|
1 | 1 | #include "audio_decoder.h"
|
2 | 2 |
|
3 | 3 | // globals
|
4 |
| -static const AVCodec *decoder_codec = NULL; |
5 |
| -static bool_t initialized = FALSE; |
| 4 | +static const AVCodec *decoder_codecs[VOD_CODEC_ID_COUNT]; |
| 5 | + |
| 6 | +typedef struct { |
| 7 | + const char *name; |
| 8 | + uint32_t vod_codec; |
| 9 | + enum AVCodecID av_codec; |
| 10 | +} audio_codec_mapping_t; |
| 11 | + |
| 12 | +static audio_codec_mapping_t audio_codec_mapping[] = { |
| 13 | + { "aac", VOD_CODEC_ID_AAC, AV_CODEC_ID_AAC }, |
| 14 | + { "ac3", VOD_CODEC_ID_AC3, AV_CODEC_ID_AC3 }, |
| 15 | + { "eac3", VOD_CODEC_ID_EAC3, AV_CODEC_ID_EAC3 }, |
| 16 | + { "mp3", VOD_CODEC_ID_MP3, AV_CODEC_ID_MP3 }, |
| 17 | + { "dts", VOD_CODEC_ID_DTS, AV_CODEC_ID_DTS }, |
| 18 | + { "vorbis", VOD_CODEC_ID_VORBIS, AV_CODEC_ID_VORBIS }, |
| 19 | + { "opus", VOD_CODEC_ID_OPUS, AV_CODEC_ID_OPUS }, |
| 20 | + |
| 21 | + { NULL, VOD_CODEC_ID_INVALID, AV_CODEC_ID_NONE } |
| 22 | +}; |
6 | 23 |
|
7 | 24 | void
|
8 | 25 | audio_decoder_process_init(vod_log_t* log)
|
9 | 26 | {
|
| 27 | + audio_codec_mapping_t* mapping; |
| 28 | + const AVCodec* decoder_codec; |
| 29 | + |
10 | 30 | #if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(58, 18, 100)
|
11 | 31 | avcodec_register_all();
|
12 | 32 | #endif
|
13 | 33 |
|
14 |
| - decoder_codec = avcodec_find_decoder(AV_CODEC_ID_AAC); |
15 |
| - if (decoder_codec == NULL) |
| 34 | + vod_memzero(decoder_codecs, sizeof(decoder_codecs)); |
| 35 | + |
| 36 | + for (mapping = audio_codec_mapping; mapping->vod_codec != VOD_CODEC_ID_INVALID; mapping++) |
16 | 37 | {
|
17 |
| - vod_log_error(VOD_LOG_WARN, log, 0, |
18 |
| - "audio_decoder_process_init: failed to get AAC decoder, audio decoding is disabled"); |
19 |
| - return; |
20 |
| - } |
| 38 | + decoder_codec = avcodec_find_decoder(mapping->av_codec); |
| 39 | + if (decoder_codec == NULL) |
| 40 | + { |
| 41 | + vod_log_error(VOD_LOG_WARN, log, 0, |
| 42 | + "audio_decoder_process_init: failed to get %s decoder, audio decoding for this codec is disabled", mapping->name); |
| 43 | + } |
21 | 44 |
|
22 |
| - initialized = TRUE; |
| 45 | + decoder_codecs[mapping->vod_codec] = decoder_codec; |
| 46 | + } |
23 | 47 | }
|
24 | 48 |
|
25 | 49 | static vod_status_t
|
26 | 50 | audio_decoder_init_decoder(
|
27 | 51 | audio_decoder_state_t* state,
|
28 | 52 | media_info_t* media_info)
|
29 | 53 | {
|
| 54 | + const AVCodec *decoder_codec; |
30 | 55 | AVCodecContext* decoder;
|
31 | 56 | int avrc;
|
32 | 57 |
|
33 |
| - if (media_info->codec_id != VOD_CODEC_ID_AAC) |
| 58 | + decoder_codec = decoder_codecs[media_info->codec_id]; |
| 59 | + if (decoder_codec == NULL) |
34 | 60 | {
|
35 | 61 | vod_log_error(VOD_LOG_ERR, state->request_context->log, 0,
|
36 | 62 | "audio_decoder_init_decoder: codec id %uD not supported", media_info->codec_id);
|
@@ -89,13 +115,6 @@ audio_decoder_init(
|
89 | 115 | input_frame_t* cur_frame;
|
90 | 116 | vod_status_t rc;
|
91 | 117 |
|
92 |
| - if (!initialized) |
93 |
| - { |
94 |
| - vod_log_error(VOD_LOG_ERR, request_context->log, 0, |
95 |
| - "audio_decoder_init: module failed to initialize successfully"); |
96 |
| - return VOD_UNEXPECTED; |
97 |
| - } |
98 |
| - |
99 | 118 | state->request_context = request_context;
|
100 | 119 |
|
101 | 120 | // init the decoder
|
|
0 commit comments