diff options
Diffstat (limited to 'apps/codec_thread.c')
-rw-r--r-- | apps/codec_thread.c | 59 |
1 files changed, 52 insertions, 7 deletions
diff --git a/apps/codec_thread.c b/apps/codec_thread.c index 54bc28e19a..1a0b0b255c 100644 --- a/apps/codec_thread.c +++ b/apps/codec_thread.c | |||
@@ -249,7 +249,7 @@ static void codec_pcmbuf_insert_callback( | |||
249 | return; /* No input remains and DSP purged */ | 249 | return; /* No input remains and DSP purged */ |
250 | } | 250 | } |
251 | } | 251 | } |
252 | } | 252 | } |
253 | } | 253 | } |
254 | 254 | ||
255 | /* helper function, not a callback */ | 255 | /* helper function, not a callback */ |
@@ -365,10 +365,14 @@ static enum codec_command_action | |||
365 | 365 | ||
366 | queue_peek(&codec_queue, &ev); /* Find out what it is */ | 366 | queue_peek(&codec_queue, &ev); /* Find out what it is */ |
367 | 367 | ||
368 | long id = ev.id; | 368 | intptr_t id = ev.id; |
369 | 369 | ||
370 | switch (id) | 370 | switch (id) |
371 | { | 371 | { |
372 | case Q_NULL: | ||
373 | LOGFQUEUE("codec < Q_NULL"); | ||
374 | break; | ||
375 | |||
372 | case Q_CODEC_RUN: /* Already running */ | 376 | case Q_CODEC_RUN: /* Already running */ |
373 | LOGFQUEUE("codec < Q_CODEC_RUN"); | 377 | LOGFQUEUE("codec < Q_CODEC_RUN"); |
374 | break; | 378 | break; |
@@ -388,8 +392,25 @@ static enum codec_command_action | |||
388 | break; | 392 | break; |
389 | 393 | ||
390 | case Q_CODEC_STOP: /* Must only return 0 in main loop */ | 394 | case Q_CODEC_STOP: /* Must only return 0 in main loop */ |
391 | LOGFQUEUE("codec < Q_CODEC_STOP"); | 395 | LOGFQUEUE("codec < Q_CODEC_STOP: %ld", ev.data); |
392 | dsp_configure(ci.dsp, DSP_FLUSH, 0); /* Discontinuity */ | 396 | #ifdef HAVE_RECORDING |
397 | if (type_is_encoder(codec_type)) | ||
398 | { | ||
399 | /* Stream finish request (soft stop)? */ | ||
400 | if (ev.data && param) | ||
401 | { | ||
402 | /* ev.data is pointer to size */ | ||
403 | *param = ev.data; | ||
404 | action = CODEC_ACTION_STREAM_FINISH; | ||
405 | break; | ||
406 | } | ||
407 | } | ||
408 | else | ||
409 | #endif /* HAVE_RECORDING */ | ||
410 | { | ||
411 | dsp_configure(ci.dsp, DSP_FLUSH, 0); /* Discontinuity */ | ||
412 | } | ||
413 | |||
393 | return CODEC_ACTION_HALT; /* Leave in queue */ | 414 | return CODEC_ACTION_HALT; /* Leave in queue */ |
394 | 415 | ||
395 | default: /* This is in error in this context. */ | 416 | default: /* This is in error in this context. */ |
@@ -459,7 +480,8 @@ static void load_codec(const struct codec_load_info *ev_data) | |||
459 | } | 480 | } |
460 | } | 481 | } |
461 | 482 | ||
462 | if (status >= 0) | 483 | /* Types must agree */ |
484 | if (status >= 0 && encoder == !!codec_get_enc_callback()) | ||
463 | { | 485 | { |
464 | codec_type = data.afmt; | 486 | codec_type = data.afmt; |
465 | codec_queue_ack(Q_CODEC_LOAD); | 487 | codec_queue_ack(Q_CODEC_LOAD); |
@@ -558,7 +580,7 @@ static void NORETURN_ATTR codec_thread(void) | |||
558 | { | 580 | { |
559 | struct queue_event ev; | 581 | struct queue_event ev; |
560 | 582 | ||
561 | while (1) | 583 | while (1) |
562 | { | 584 | { |
563 | cancel_cpu_boost(); | 585 | cancel_cpu_boost(); |
564 | 586 | ||
@@ -685,10 +707,33 @@ bool codec_pause(void) | |||
685 | void codec_stop(void) | 707 | void codec_stop(void) |
686 | { | 708 | { |
687 | /* Wait until it's in the main loop */ | 709 | /* Wait until it's in the main loop */ |
688 | LOGFQUEUE("audio >| codec Q_CODEC_STOP"); | 710 | LOGFQUEUE("audio >| codec Q_CODEC_STOP: 0"); |
689 | while (codec_queue_send(Q_CODEC_STOP, 0) != Q_NULL); | 711 | while (codec_queue_send(Q_CODEC_STOP, 0) != Q_NULL); |
690 | } | 712 | } |
691 | 713 | ||
714 | #ifdef HAVE_RECORDING | ||
715 | /* Tells codec to take final encoding step and then exit - | ||
716 | Returns minimum buffer size required or 0 if complete */ | ||
717 | size_t codec_finish_stream(void) | ||
718 | { | ||
719 | size_t size = 0; | ||
720 | |||
721 | LOGFQUEUE("audio >| codec Q_CODEC_STOP: &size"); | ||
722 | if (codec_queue_send(Q_CODEC_STOP, (intptr_t)&size) != Q_NULL) | ||
723 | { | ||
724 | /* Sync to keep size in scope and get response */ | ||
725 | LOGFQUEUE("audio >| codec Q_NULL"); | ||
726 | codec_queue_send(Q_NULL, 0); | ||
727 | |||
728 | if (size == 0) | ||
729 | codec_stop(); /* Replied with 0 size */ | ||
730 | } | ||
731 | /* else thread running in the main loop */ | ||
732 | |||
733 | return size; | ||
734 | } | ||
735 | #endif /* HAVE_RECORDING */ | ||
736 | |||
692 | /* Call the codec's exit routine and close all references */ | 737 | /* Call the codec's exit routine and close all references */ |
693 | void codec_unload(void) | 738 | void codec_unload(void) |
694 | { | 739 | { |