1515#include "text.h"
1616#include "encoder.h"
1717
18- static int pipe_video_fd ;
19- static pthread_mutex_t pipe_video_mutex ;
18+ static int pipe_out_fd ;
19+ static pthread_mutex_t pipe_out_mutex ;
2020static text_t * text ;
2121static encoder_t * enc ;
2222
@@ -40,9 +40,15 @@ static void on_frame(
4040}
4141
4242static void on_encoder_output (const uint8_t * mapped , uint64_t size , uint64_t ts ) {
43- pthread_mutex_lock (& pipe_video_mutex );
44- pipe_write_buf (pipe_video_fd , mapped , size , ts );
45- pthread_mutex_unlock (& pipe_video_mutex );
43+ pthread_mutex_lock (& pipe_out_mutex );
44+ pipe_write_buf (pipe_out_fd , mapped , size , ts );
45+ pthread_mutex_unlock (& pipe_out_mutex );
46+ }
47+
48+ static void on_error () {
49+ pthread_mutex_lock (& pipe_out_mutex );
50+ pipe_write_error (pipe_out_fd , "camera driver exited" );
51+ pthread_mutex_unlock (& pipe_out_mutex );
4652}
4753
4854int main () {
@@ -51,30 +57,31 @@ int main() {
5157 return 0 ;
5258 }
5359
54- int pipe_conf_fd = atoi (getenv ("PIPE_CONF_FD" ));
55- pipe_video_fd = atoi (getenv ("PIPE_VIDEO_FD" ));
60+ int pipe_in_fd = atoi (getenv ("PIPE_CONF_FD" ));
61+ pipe_out_fd = atoi (getenv ("PIPE_VIDEO_FD" ));
5662
5763 uint8_t * buf ;
58- uint32_t n = pipe_read (pipe_conf_fd , & buf );
64+ uint32_t n = pipe_read (pipe_in_fd , & buf );
5965
6066 parameters_t params ;
6167 bool ok = parameters_unserialize (& params , & buf [1 ], n - 1 );
6268 free (buf );
6369 if (!ok ) {
64- pipe_write_error (pipe_video_fd , "parameters_unserialize(): %s" , parameters_get_error ());
70+ pipe_write_error (pipe_out_fd , "parameters_unserialize(): %s" , parameters_get_error ());
6571 return -1 ;
6672 }
6773
68- pthread_mutex_init (& pipe_video_mutex , NULL );
69- pthread_mutex_lock (& pipe_video_mutex );
74+ pthread_mutex_init (& pipe_out_mutex , NULL );
75+ pthread_mutex_lock (& pipe_out_mutex );
7076
7177 camera_t * cam ;
7278 ok = camera_create (
7379 & params ,
7480 on_frame ,
81+ on_error ,
7582 & cam );
7683 if (!ok ) {
77- pipe_write_error (pipe_video_fd , "camera_create(): %s" , camera_get_error ());
84+ pipe_write_error (pipe_out_fd , "camera_create(): %s" , camera_get_error ());
7885 return -1 ;
7986 }
8087
@@ -83,7 +90,7 @@ int main() {
8390 camera_get_stride (cam ),
8491 & text );
8592 if (!ok ) {
86- pipe_write_error (pipe_video_fd , "text_create(): %s" , text_get_error ());
93+ pipe_write_error (pipe_out_fd , "text_create(): %s" , text_get_error ());
8794 return -1 ;
8895 }
8996
@@ -94,22 +101,22 @@ int main() {
94101 on_encoder_output ,
95102 & enc );
96103 if (!ok ) {
97- pipe_write_error (pipe_video_fd , "encoder_create(): %s" , encoder_get_error ());
104+ pipe_write_error (pipe_out_fd , "encoder_create(): %s" , encoder_get_error ());
98105 return -1 ;
99106 }
100107
101108 ok = camera_start (cam );
102109 if (!ok ) {
103- pipe_write_error (pipe_video_fd , "camera_start(): %s" , camera_get_error ());
110+ pipe_write_error (pipe_out_fd , "camera_start(): %s" , camera_get_error ());
104111 return -1 ;
105112 }
106113
107- pipe_write_ready (pipe_video_fd );
108- pthread_mutex_unlock (& pipe_video_mutex );
114+ pipe_write_ready (pipe_out_fd );
115+ pthread_mutex_unlock (& pipe_out_mutex );
109116
110117 while (true) {
111118 uint8_t * buf ;
112- uint32_t n = pipe_read (pipe_conf_fd , & buf );
119+ uint32_t n = pipe_read (pipe_in_fd , & buf );
113120
114121 switch (buf [0 ]) {
115122 case 'e' :
0 commit comments