| 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 "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/sha1.h" | 10 #include "base/sha1.h" |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 67 switch (codec_id) { | 67 switch (codec_id) { |
| 68 case AV_CODEC_ID_AAC: | 68 case AV_CODEC_ID_AAC: |
| 69 return kCodecAAC; | 69 return kCodecAAC; |
| 70 case AV_CODEC_ID_MP3: | 70 case AV_CODEC_ID_MP3: |
| 71 return kCodecMP3; | 71 return kCodecMP3; |
| 72 case AV_CODEC_ID_VORBIS: | 72 case AV_CODEC_ID_VORBIS: |
| 73 return kCodecVorbis; | 73 return kCodecVorbis; |
| 74 case AV_CODEC_ID_PCM_U8: | 74 case AV_CODEC_ID_PCM_U8: |
| 75 case AV_CODEC_ID_PCM_S16LE: | 75 case AV_CODEC_ID_PCM_S16LE: |
| 76 case AV_CODEC_ID_PCM_S24LE: | 76 case AV_CODEC_ID_PCM_S24LE: |
| 77 case AV_CODEC_ID_PCM_S32LE: |
| 77 case AV_CODEC_ID_PCM_F32LE: | 78 case AV_CODEC_ID_PCM_F32LE: |
| 78 return kCodecPCM; | 79 return kCodecPCM; |
| 79 case AV_CODEC_ID_PCM_S16BE: | 80 case AV_CODEC_ID_PCM_S16BE: |
| 80 return kCodecPCM_S16BE; | 81 return kCodecPCM_S16BE; |
| 81 case AV_CODEC_ID_PCM_S24BE: | 82 case AV_CODEC_ID_PCM_S24BE: |
| 82 return kCodecPCM_S24BE; | 83 return kCodecPCM_S24BE; |
| 83 case AV_CODEC_ID_FLAC: | 84 case AV_CODEC_ID_FLAC: |
| 84 return kCodecFLAC; | 85 return kCodecFLAC; |
| 85 case AV_CODEC_ID_AMR_NB: | 86 case AV_CODEC_ID_AMR_NB: |
| 86 return kCodecAMR_NB; | 87 return kCodecAMR_NB; |
| (...skipping 23 matching lines...) Expand all Loading... |
| 110 case kCodecALAC: | 111 case kCodecALAC: |
| 111 return AV_CODEC_ID_ALAC; | 112 return AV_CODEC_ID_ALAC; |
| 112 case kCodecMP3: | 113 case kCodecMP3: |
| 113 return AV_CODEC_ID_MP3; | 114 return AV_CODEC_ID_MP3; |
| 114 case kCodecPCM: | 115 case kCodecPCM: |
| 115 switch (sample_format) { | 116 switch (sample_format) { |
| 116 case kSampleFormatU8: | 117 case kSampleFormatU8: |
| 117 return AV_CODEC_ID_PCM_U8; | 118 return AV_CODEC_ID_PCM_U8; |
| 118 case kSampleFormatS16: | 119 case kSampleFormatS16: |
| 119 return AV_CODEC_ID_PCM_S16LE; | 120 return AV_CODEC_ID_PCM_S16LE; |
| 121 case kSampleFormatS24: |
| 122 return AV_CODEC_ID_PCM_S24LE; |
| 120 case kSampleFormatS32: | 123 case kSampleFormatS32: |
| 121 return AV_CODEC_ID_PCM_S24LE; | 124 return AV_CODEC_ID_PCM_S32LE; |
| 122 case kSampleFormatF32: | 125 case kSampleFormatF32: |
| 123 return AV_CODEC_ID_PCM_F32LE; | 126 return AV_CODEC_ID_PCM_F32LE; |
| 124 default: | 127 default: |
| 125 DVLOG(1) << "Unsupported sample format: " << sample_format; | 128 DVLOG(1) << "Unsupported sample format: " << sample_format; |
| 126 } | 129 } |
| 127 break; | 130 break; |
| 128 case kCodecPCM_S16BE: | 131 case kCodecPCM_S16BE: |
| 129 return AV_CODEC_ID_PCM_S16BE; | 132 return AV_CODEC_ID_PCM_S16BE; |
| 130 case kCodecPCM_S24BE: | 133 case kCodecPCM_S24BE: |
| 131 return AV_CODEC_ID_PCM_S24BE; | 134 return AV_CODEC_ID_PCM_S24BE; |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 237 case H264PROFILE_HIGH422PROFILE: | 240 case H264PROFILE_HIGH422PROFILE: |
| 238 return FF_PROFILE_H264_HIGH_422; | 241 return FF_PROFILE_H264_HIGH_422; |
| 239 case H264PROFILE_HIGH444PREDICTIVEPROFILE: | 242 case H264PROFILE_HIGH444PREDICTIVEPROFILE: |
| 240 return FF_PROFILE_H264_HIGH_444_PREDICTIVE; | 243 return FF_PROFILE_H264_HIGH_444_PREDICTIVE; |
| 241 default: | 244 default: |
| 242 DVLOG(1) << "Unknown VideoCodecProfile: " << profile; | 245 DVLOG(1) << "Unknown VideoCodecProfile: " << profile; |
| 243 } | 246 } |
| 244 return FF_PROFILE_UNKNOWN; | 247 return FF_PROFILE_UNKNOWN; |
| 245 } | 248 } |
| 246 | 249 |
| 247 SampleFormat AVSampleFormatToSampleFormat(AVSampleFormat sample_format) { | 250 SampleFormat AVSampleFormatToSampleFormat(AVSampleFormat sample_format, |
| 251 AVCodecID codec_id) { |
| 248 switch (sample_format) { | 252 switch (sample_format) { |
| 249 case AV_SAMPLE_FMT_U8: | 253 case AV_SAMPLE_FMT_U8: |
| 250 return kSampleFormatU8; | 254 return kSampleFormatU8; |
| 251 case AV_SAMPLE_FMT_S16: | 255 case AV_SAMPLE_FMT_S16: |
| 252 return kSampleFormatS16; | 256 return kSampleFormatS16; |
| 253 case AV_SAMPLE_FMT_S32: | 257 case AV_SAMPLE_FMT_S32: |
| 254 return kSampleFormatS32; | 258 if (codec_id == AV_CODEC_ID_PCM_S24LE) |
| 259 return kSampleFormatS24; |
| 260 else |
| 261 return kSampleFormatS32; |
| 255 case AV_SAMPLE_FMT_FLT: | 262 case AV_SAMPLE_FMT_FLT: |
| 256 return kSampleFormatF32; | 263 return kSampleFormatF32; |
| 257 case AV_SAMPLE_FMT_S16P: | 264 case AV_SAMPLE_FMT_S16P: |
| 258 return kSampleFormatPlanarS16; | 265 return kSampleFormatPlanarS16; |
| 259 case AV_SAMPLE_FMT_S32P: | 266 case AV_SAMPLE_FMT_S32P: |
| 260 return kSampleFormatPlanarS32; | 267 return kSampleFormatPlanarS32; |
| 261 case AV_SAMPLE_FMT_FLTP: | 268 case AV_SAMPLE_FMT_FLTP: |
| 262 return kSampleFormatPlanarF32; | 269 return kSampleFormatPlanarF32; |
| 263 default: | 270 default: |
| 264 DVLOG(1) << "Unknown AVSampleFormat: " << sample_format; | 271 DVLOG(1) << "Unknown AVSampleFormat: " << sample_format; |
| 265 } | 272 } |
| 266 return kUnknownSampleFormat; | 273 return kUnknownSampleFormat; |
| 267 } | 274 } |
| 268 | 275 |
| 269 static AVSampleFormat SampleFormatToAVSampleFormat(SampleFormat sample_format) { | 276 static AVSampleFormat SampleFormatToAVSampleFormat(SampleFormat sample_format) { |
| 270 switch (sample_format) { | 277 switch (sample_format) { |
| 271 case kSampleFormatU8: | 278 case kSampleFormatU8: |
| 272 return AV_SAMPLE_FMT_U8; | 279 return AV_SAMPLE_FMT_U8; |
| 273 case kSampleFormatS16: | 280 case kSampleFormatS16: |
| 274 return AV_SAMPLE_FMT_S16; | 281 return AV_SAMPLE_FMT_S16; |
| 282 // pcm_s24le is treated as a codec with sample format s32 in ffmpeg |
| 283 case kSampleFormatS24: |
| 275 case kSampleFormatS32: | 284 case kSampleFormatS32: |
| 276 return AV_SAMPLE_FMT_S32; | 285 return AV_SAMPLE_FMT_S32; |
| 277 case kSampleFormatF32: | 286 case kSampleFormatF32: |
| 278 return AV_SAMPLE_FMT_FLT; | 287 return AV_SAMPLE_FMT_FLT; |
| 279 case kSampleFormatPlanarS16: | 288 case kSampleFormatPlanarS16: |
| 280 return AV_SAMPLE_FMT_S16P; | 289 return AV_SAMPLE_FMT_S16P; |
| 281 case kSampleFormatPlanarF32: | 290 case kSampleFormatPlanarF32: |
| 282 return AV_SAMPLE_FMT_FLTP; | 291 return AV_SAMPLE_FMT_FLTP; |
| 283 default: | 292 default: |
| 284 DVLOG(1) << "Unknown SampleFormat: " << sample_format; | 293 DVLOG(1) << "Unknown SampleFormat: " << sample_format; |
| 285 } | 294 } |
| 286 return AV_SAMPLE_FMT_NONE; | 295 return AV_SAMPLE_FMT_NONE; |
| 287 } | 296 } |
| 288 | 297 |
| 289 bool AVCodecContextToAudioDecoderConfig(const AVCodecContext* codec_context, | 298 bool AVCodecContextToAudioDecoderConfig(const AVCodecContext* codec_context, |
| 290 bool is_encrypted, | 299 bool is_encrypted, |
| 291 AudioDecoderConfig* config) { | 300 AudioDecoderConfig* config) { |
| 292 DCHECK_EQ(codec_context->codec_type, AVMEDIA_TYPE_AUDIO); | 301 DCHECK_EQ(codec_context->codec_type, AVMEDIA_TYPE_AUDIO); |
| 293 | 302 |
| 294 AudioCodec codec = CodecIDToAudioCodec(codec_context->codec_id); | 303 AudioCodec codec = CodecIDToAudioCodec(codec_context->codec_id); |
| 295 | 304 |
| 296 SampleFormat sample_format = | 305 SampleFormat sample_format = AVSampleFormatToSampleFormat( |
| 297 AVSampleFormatToSampleFormat(codec_context->sample_fmt); | 306 codec_context->sample_fmt, codec_context->codec_id); |
| 298 | 307 |
| 299 ChannelLayout channel_layout = ChannelLayoutToChromeChannelLayout( | 308 ChannelLayout channel_layout = ChannelLayoutToChromeChannelLayout( |
| 300 codec_context->channel_layout, codec_context->channels); | 309 codec_context->channel_layout, codec_context->channels); |
| 301 | 310 |
| 302 int sample_rate = codec_context->sample_rate; | 311 int sample_rate = codec_context->sample_rate; |
| 303 if (codec == kCodecOpus) { | 312 if (codec == kCodecOpus) { |
| 304 // |codec_context->sample_fmt| is not set by FFmpeg because Opus decoding is | 313 // |codec_context->sample_fmt| is not set by FFmpeg because Opus decoding is |
| 305 // not enabled in FFmpeg. It doesn't matter what value is set here, so long | 314 // not enabled in FFmpeg. It doesn't matter what value is set here, so long |
| 306 // as it's valid, the true sample format is selected inside the decoder. | 315 // as it's valid, the true sample format is selected inside the decoder. |
| 307 sample_format = kSampleFormatF32; | 316 sample_format = kSampleFormatF32; |
| (...skipping 373 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 681 } | 690 } |
| 682 | 691 |
| 683 int32_t HashCodecName(const char* codec_name) { | 692 int32_t HashCodecName(const char* codec_name) { |
| 684 // Use the first 32-bits from the SHA1 hash as the identifier. | 693 // Use the first 32-bits from the SHA1 hash as the identifier. |
| 685 int32_t hash; | 694 int32_t hash; |
| 686 memcpy(&hash, base::SHA1HashString(codec_name).substr(0, 4).c_str(), 4); | 695 memcpy(&hash, base::SHA1HashString(codec_name).substr(0, 4).c_str(), 4); |
| 687 return hash; | 696 return hash; |
| 688 } | 697 } |
| 689 | 698 |
| 690 } // namespace media | 699 } // namespace media |
| OLD | NEW |