OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "media/ffmpeg/ffmpeg_common.h" | 5 #include "media/ffmpeg/ffmpeg_common.h" |
6 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "media/base/decoder_buffer.h" | 9 #include "media/base/decoder_buffer.h" |
10 #include "media/base/video_frame.h" | 10 #include "media/base/video_frame.h" |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
76 case CODEC_ID_FLAC: | 76 case CODEC_ID_FLAC: |
77 return kCodecFLAC; | 77 return kCodecFLAC; |
78 case CODEC_ID_AMR_NB: | 78 case CODEC_ID_AMR_NB: |
79 return kCodecAMR_NB; | 79 return kCodecAMR_NB; |
80 case CODEC_ID_AMR_WB: | 80 case CODEC_ID_AMR_WB: |
81 return kCodecAMR_WB; | 81 return kCodecAMR_WB; |
82 case CODEC_ID_GSM_MS: | 82 case CODEC_ID_GSM_MS: |
83 return kCodecGSM_MS; | 83 return kCodecGSM_MS; |
84 case CODEC_ID_PCM_MULAW: | 84 case CODEC_ID_PCM_MULAW: |
85 return kCodecPCM_MULAW; | 85 return kCodecPCM_MULAW; |
| 86 case CODEC_ID_OPUS: |
| 87 return kCodecOpus; |
86 default: | 88 default: |
87 DVLOG(1) << "Unknown audio CodecID: " << codec_id; | 89 DVLOG(1) << "Unknown audio CodecID: " << codec_id; |
88 } | 90 } |
89 return kUnknownAudioCodec; | 91 return kUnknownAudioCodec; |
90 } | 92 } |
91 | 93 |
92 static CodecID AudioCodecToCodecID(AudioCodec audio_codec, | 94 static CodecID AudioCodecToCodecID(AudioCodec audio_codec, |
93 int bits_per_channel) { | 95 int bits_per_channel) { |
94 switch (audio_codec) { | 96 switch (audio_codec) { |
95 case kCodecAAC: | 97 case kCodecAAC: |
(...skipping 21 matching lines...) Expand all Loading... |
117 case kCodecFLAC: | 119 case kCodecFLAC: |
118 return CODEC_ID_FLAC; | 120 return CODEC_ID_FLAC; |
119 case kCodecAMR_NB: | 121 case kCodecAMR_NB: |
120 return CODEC_ID_AMR_NB; | 122 return CODEC_ID_AMR_NB; |
121 case kCodecAMR_WB: | 123 case kCodecAMR_WB: |
122 return CODEC_ID_AMR_WB; | 124 return CODEC_ID_AMR_WB; |
123 case kCodecGSM_MS: | 125 case kCodecGSM_MS: |
124 return CODEC_ID_GSM_MS; | 126 return CODEC_ID_GSM_MS; |
125 case kCodecPCM_MULAW: | 127 case kCodecPCM_MULAW: |
126 return CODEC_ID_PCM_MULAW; | 128 return CODEC_ID_PCM_MULAW; |
| 129 case kCodecOpus: |
| 130 return CODEC_ID_OPUS; |
127 default: | 131 default: |
128 DVLOG(1) << "Unknown AudioCodec: " << audio_codec; | 132 DVLOG(1) << "Unknown AudioCodec: " << audio_codec; |
129 } | 133 } |
130 return CODEC_ID_NONE; | 134 return CODEC_ID_NONE; |
131 } | 135 } |
132 | 136 |
133 VideoCodec CodecIDToVideoCodec(CodecID codec_id) { | 137 VideoCodec CodecIDToVideoCodec(CodecID codec_id) { |
134 switch (codec_id) { | 138 switch (codec_id) { |
135 case CODEC_ID_VC1: | 139 case CODEC_ID_VC1: |
136 return kCodecVC1; | 140 return kCodecVC1; |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
217 } | 221 } |
218 return FF_PROFILE_UNKNOWN; | 222 return FF_PROFILE_UNKNOWN; |
219 } | 223 } |
220 | 224 |
221 void AVCodecContextToAudioDecoderConfig( | 225 void AVCodecContextToAudioDecoderConfig( |
222 const AVCodecContext* codec_context, | 226 const AVCodecContext* codec_context, |
223 AudioDecoderConfig* config) { | 227 AudioDecoderConfig* config) { |
224 DCHECK_EQ(codec_context->codec_type, AVMEDIA_TYPE_AUDIO); | 228 DCHECK_EQ(codec_context->codec_type, AVMEDIA_TYPE_AUDIO); |
225 | 229 |
226 AudioCodec codec = CodecIDToAudioCodec(codec_context->codec_id); | 230 AudioCodec codec = CodecIDToAudioCodec(codec_context->codec_id); |
227 int bytes_per_channel = av_get_bytes_per_sample(codec_context->sample_fmt); | 231 |
| 232 AVSampleFormat sample_format = codec_context->sample_fmt; |
| 233 if (codec == kCodecOpus) { |
| 234 // TODO(tomfinegan): |sample_fmt| in |codec_context| is -1... because |
| 235 // libopusdec.c isn't built into ffmpegsumo...? Maybe it's not *that* big |
| 236 // a deal since libopus will produce either float or S16 samples, and |
| 237 // OpusAudioDecoder is the only provider of Opus support. |
| 238 sample_format = AV_SAMPLE_FMT_S16; |
| 239 } |
| 240 |
| 241 int bytes_per_channel = av_get_bytes_per_sample(sample_format); |
228 ChannelLayout channel_layout = | 242 ChannelLayout channel_layout = |
229 ChannelLayoutToChromeChannelLayout(codec_context->channel_layout, | 243 ChannelLayoutToChromeChannelLayout(codec_context->channel_layout, |
230 codec_context->channels); | 244 codec_context->channels); |
231 int samples_per_second = codec_context->sample_rate; | 245 int samples_per_second = codec_context->sample_rate; |
232 | 246 |
233 config->Initialize(codec, | 247 config->Initialize(codec, |
234 bytes_per_channel << 3, | 248 bytes_per_channel << 3, |
235 channel_layout, | 249 channel_layout, |
236 samples_per_second, | 250 samples_per_second, |
237 codec_context->extradata, | 251 codec_context->extradata, |
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
421 return PIX_FMT_YUV422P; | 435 return PIX_FMT_YUV422P; |
422 case VideoFrame::YV12: | 436 case VideoFrame::YV12: |
423 return PIX_FMT_YUV420P; | 437 return PIX_FMT_YUV420P; |
424 default: | 438 default: |
425 DVLOG(1) << "Unsupported VideoFrame::Format: " << video_format; | 439 DVLOG(1) << "Unsupported VideoFrame::Format: " << video_format; |
426 } | 440 } |
427 return PIX_FMT_NONE; | 441 return PIX_FMT_NONE; |
428 } | 442 } |
429 | 443 |
430 } // namespace media | 444 } // namespace media |
OLD | NEW |