diff options
-rw-r--r-- | lib/rbcodec/codecs/mp3_enc.c | 37 |
1 files changed, 14 insertions, 23 deletions
diff --git a/lib/rbcodec/codecs/mp3_enc.c b/lib/rbcodec/codecs/mp3_enc.c index 8765d120e2..ebbd323b6f 100644 --- a/lib/rbcodec/codecs/mp3_enc.c +++ b/lib/rbcodec/codecs/mp3_enc.c | |||
@@ -2838,21 +2838,8 @@ static struct semaphore enc_sema IBSS_ATTR; | |||
2838 | static struct semaphore cod_sema IBSS_ATTR; | 2838 | static struct semaphore cod_sema IBSS_ATTR; |
2839 | static unsigned int enc_thread_id; | 2839 | static unsigned int enc_thread_id; |
2840 | 2840 | ||
2841 | /* Needs two extra loops to drain sb_data_buf. | 2841 | /* Needs one extra loop to drain sb_data_buf */ |
2842 | * Progress at state: | 2842 | #define DRAIN_FRAMES 1 |
2843 | * |F|F|F| | ||
2844 | *|1|2| : fill 1 | ||
2845 | * |2|1| : fill 2, get 1 | ||
2846 | * |1|2| : fill 1, get 2 | ||
2847 | * |2|1| : fill 2, get 1 | ||
2848 | * |1|2| : get 2 | ||
2849 | * |2|1| : get 1 | ||
2850 | * Loops = Fcount + 2 | ||
2851 | * | ||
2852 | * Case of Fcount==1, which would otherwise fail, never happens due to | ||
2853 | * padding frames. | ||
2854 | */ | ||
2855 | #define DRAIN_FRAMES 2 | ||
2856 | 2843 | ||
2857 | static void enc_thread(void) | 2844 | static void enc_thread(void) |
2858 | { | 2845 | { |
@@ -2894,7 +2881,7 @@ static bool enc_thread_init(void *stack, size_t stack_size) | |||
2894 | (void)stack; (void)stack_size; | 2881 | (void)stack; (void)stack_size; |
2895 | } | 2882 | } |
2896 | 2883 | ||
2897 | static inline void enc_thread_sb_data_ready(void) | 2884 | static inline void enc_thread_compress_frame(void) |
2898 | { | 2885 | { |
2899 | #ifdef MP3_ENC_COP | 2886 | #ifdef MP3_ENC_COP |
2900 | sb_data_buf_swap(); | 2887 | sb_data_buf_swap(); |
@@ -2925,7 +2912,7 @@ static inline bool wait_for_frame(void) | |||
2925 | { | 2912 | { |
2926 | /* Fill subband data buffer before getting frame from COP */ | 2913 | /* Fill subband data buffer before getting frame from COP */ |
2927 | enc_status = ENC_SB_FULL; | 2914 | enc_status = ENC_SB_FULL; |
2928 | enc_thread_sb_data_ready(); | 2915 | enc_thread_compress_frame(); |
2929 | return false; | 2916 | return false; |
2930 | } | 2917 | } |
2931 | #endif /* MP3_ENC_COP */ | 2918 | #endif /* MP3_ENC_COP */ |
@@ -2935,9 +2922,7 @@ static inline bool wait_for_frame(void) | |||
2935 | 2922 | ||
2936 | static inline size_t get_frame(uint8_t *buffer) | 2923 | static inline size_t get_frame(uint8_t *buffer) |
2937 | { | 2924 | { |
2938 | size_t size = mp3_enc_get_frame(buffer); | 2925 | return mp3_enc_get_frame(buffer); |
2939 | enc_thread_sb_data_ready(); | ||
2940 | return size; | ||
2941 | } | 2926 | } |
2942 | 2927 | ||
2943 | /* this is the codec entry point */ | 2928 | /* this is the codec entry point */ |
@@ -2971,7 +2956,7 @@ enum codec_status codec_run(void) | |||
2971 | struct enc_chunk_data *data = NULL; | 2956 | struct enc_chunk_data *data = NULL; |
2972 | 2957 | ||
2973 | /* main encoding loop */ | 2958 | /* main encoding loop */ |
2974 | while (frames_rem) | 2959 | while (1) |
2975 | { | 2960 | { |
2976 | intptr_t param; | 2961 | intptr_t param; |
2977 | enum codec_command_action action = ci->get_command(¶m); | 2962 | enum codec_command_action action = ci->get_command(¶m); |
@@ -3012,7 +2997,7 @@ enum codec_status codec_run(void) | |||
3012 | /* else Draining remaining buffered data */ | 2997 | /* else Draining remaining buffered data */ |
3013 | 2998 | ||
3014 | if (!wait_for_frame()) /* MT only */ | 2999 | if (!wait_for_frame()) /* MT only */ |
3015 | continue; | 3000 | break; |
3016 | 3001 | ||
3017 | getbuf = GETBUF_ENC; | 3002 | getbuf = GETBUF_ENC; |
3018 | case GETBUF_ENC: | 3003 | case GETBUF_ENC: |
@@ -3024,12 +3009,18 @@ enum codec_status codec_run(void) | |||
3024 | data->hdr.aux0 = first; | 3009 | data->hdr.aux0 = first; |
3025 | first = 0; | 3010 | first = 0; |
3026 | data->hdr.size = get_frame(data->data); | 3011 | data->hdr.size = get_frame(data->data); |
3027 | data->pcm_count = cfg.samp_per_frame; | ||
3028 | 3012 | ||
3013 | if (frames_rem) | ||
3014 | enc_thread_compress_frame(); /* MT only */ | ||
3015 | |||
3016 | data->pcm_count = cfg.samp_per_frame; | ||
3029 | ci->enc_encbuf_finish_buffer(); | 3017 | ci->enc_encbuf_finish_buffer(); |
3030 | 3018 | ||
3031 | getbuf = GETBUF_PCM; | 3019 | getbuf = GETBUF_PCM; |
3032 | } | 3020 | } |
3021 | |||
3022 | if (!frames_rem) | ||
3023 | break; | ||
3033 | } /* while */ | 3024 | } /* while */ |
3034 | 3025 | ||
3035 | enc_thread_stop(); /* MT only */ | 3026 | enc_thread_stop(); /* MT only */ |