@@ -115,7 +115,7 @@ static uint32_t parse_codec(const char *name) {
115115static int process_message (struct fma_client * client ,
116116 const struct fma_frame_pool * pool , uint8_t * pool_map ,
117117 FILE * output , uint64_t * frames , bool * packet_ack ,
118- bool * eos ) {
118+ bool * eos , bool * poll_done ) {
119119 struct fma_message message ;
120120 if (fma_client_receive (client , & message ) < 0 )
121121 return -1 ;
@@ -140,6 +140,8 @@ static int process_message(struct fma_client *client,
140140 * packet_ack = true;
141141 } else if (message .type == FMA_MSG_OUTPUT_EOS ) {
142142 * eos = true;
143+ } else if (message .type == FMA_MSG_POLL_DONE ) {
144+ * poll_done = true;
143145 } else if (message .type == FMA_MSG_ERROR ) {
144146 fprintf (stderr , "daemon: %.*s\n" , (int )message .payload_size ,
145147 message .payload ? (char * )message .payload : "error" );
@@ -242,6 +244,7 @@ int main(int argc, char **argv) {
242244 for (size_t i = 0 ; i < unit_count ; ++ i ) {
243245 int64_t pts_us = (int64_t )(i * UINT64_C (1000000 ) / fps );
244246 bool packet_ack = false;
247+ bool poll_done = false;
245248 if (fma_client_queue_packet (& client , input + units [i ].offset ,
246249 units [i ].size , pts_us , 0 ) < 0 ) {
247250 perror ("decode" );
@@ -251,17 +254,28 @@ int main(int argc, char **argv) {
251254 input_bytes += units [i ].size ;
252255 while (!packet_ack &&
253256 process_message (& client , & pool , pool_map , output , & frames ,
254- & packet_ack , & eos ) == 0 ) {}
257+ & packet_ack , & eos , & poll_done ) == 0 ) {}
255258 if (!packet_ack ) {
256259 perror ("decode" );
257260 failed = true;
258261 break ;
259262 }
260263 }
264+ if (!failed && fma_client_poll_output (& client , 0 ) == 0 ) {
265+ bool packet_ack = false;
266+ bool poll_done = false;
267+ while (!poll_done &&
268+ process_message (& client , & pool , pool_map , output , & frames ,
269+ & packet_ack , & eos , & poll_done ) == 0 ) {}
270+ if (!poll_done )
271+ failed = true;
272+ }
261273 if (!failed && fma_client_drain (& client ) == 0 ) {
262274 bool packet_ack = false;
275+ bool poll_done = false;
263276 while (!eos && process_message (& client , & pool , pool_map , output ,
264- & frames , & packet_ack , & eos ) == 0 ) {}
277+ & frames , & packet_ack , & eos ,
278+ & poll_done ) == 0 ) {}
265279 }
266280 if (!eos )
267281 failed = true;
0 commit comments