| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. Use of this | 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. Use of this |
| 2 // source code is governed by a BSD-style license that can be found in the | 2 // source code is governed by a BSD-style license that can be found in the |
| 3 // LICENSE file. | 3 // LICENSE file. |
| 4 | 4 |
| 5 #include "media/base/data_buffer.h" | 5 #include "media/base/data_buffer.h" |
| 6 #include "media/filters/ffmpeg_audio_decoder.h" | 6 #include "media/filters/ffmpeg_audio_decoder.h" |
| 7 #include "media/filters/ffmpeg_common.h" | 7 #include "media/filters/ffmpeg_common.h" |
| 8 #include "media/filters/ffmpeg_demuxer.h" | 8 #include "media/filters/ffmpeg_demuxer.h" |
| 9 | 9 |
| 10 namespace media { | 10 namespace media { |
| 11 | 11 |
| 12 // Size of the decoded audio buffer. | 12 // Size of the decoded audio buffer. |
| 13 const size_t FFmpegAudioDecoder::kOutputBufferSize = | 13 const size_t FFmpegAudioDecoder::kOutputBufferSize = |
| 14 AVCODEC_MAX_AUDIO_FRAME_SIZE; | 14 AVCODEC_MAX_AUDIO_FRAME_SIZE; |
| 15 | 15 |
| 16 FFmpegAudioDecoder::FFmpegAudioDecoder() | 16 FFmpegAudioDecoder::FFmpegAudioDecoder() |
| 17 : DecoderBase<AudioDecoder, Buffer>(NULL), | 17 : DecoderBase<AudioDecoder, Buffer>(NULL), |
| 18 codec_context_(NULL) { | 18 codec_context_(NULL) { |
| 19 } | 19 } |
| 20 | 20 |
| 21 FFmpegAudioDecoder::~FFmpegAudioDecoder() { | 21 FFmpegAudioDecoder::~FFmpegAudioDecoder() { |
| 22 } | 22 } |
| 23 | 23 |
| 24 // static | 24 // static |
| 25 bool FFmpegAudioDecoder::IsMediaFormatSupported(const MediaFormat& format) { | 25 bool FFmpegAudioDecoder::IsMediaFormatSupported(const MediaFormat& format) { |
| 26 int channels, sample_bits, sample_rate; | |
| 27 std::string mime_type; | 26 std::string mime_type; |
| 28 if (format.GetAsInteger(MediaFormat::kChannels, &channels) && | 27 return format.GetAsString(MediaFormat::kMimeType, &mime_type) && |
| 29 format.GetAsInteger(MediaFormat::kSampleBits, &sample_bits) && | 28 mime_type::kFFmpegAudio == mime_type; |
| 30 format.GetAsInteger(MediaFormat::kSampleRate, &sample_rate) && | |
| 31 format.GetAsString(MediaFormat::kMimeType, &mime_type) && | |
| 32 mime_type::kFFmpegAudio == mime_type) { | |
| 33 return true; | |
| 34 } | |
| 35 return false; | |
| 36 } | 29 } |
| 37 | 30 |
| 38 bool FFmpegAudioDecoder::OnInitialize(DemuxerStream* demuxer_stream) { | 31 bool FFmpegAudioDecoder::OnInitialize(DemuxerStream* demuxer_stream) { |
| 39 scoped_refptr<FFmpegDemuxerStream> ffmpeg_demuxer_stream; | 32 scoped_refptr<FFmpegDemuxerStream> ffmpeg_demuxer_stream; |
| 40 | 33 |
| 41 // Try to obtain a reference to FFmpegDemuxer. | 34 // Try to obtain a reference to FFmpegDemuxer. |
| 42 if (!demuxer_stream-> | 35 if (!demuxer_stream-> |
| 43 QueryInterface<FFmpegDemuxerStream>(&ffmpeg_demuxer_stream)) | 36 QueryInterface<FFmpegDemuxerStream>(&ffmpeg_demuxer_stream)) |
| 44 return false; | 37 return false; |
| 45 | 38 |
| 46 // Setting the media format. | 39 // Setting the media format. |
| 47 // TODO(hclam): Reuse the information provided by the demuxer for now, we may | 40 // TODO(hclam): Reuse the information provided by the demuxer for now, we may |
| 48 // need to wait until the first buffer is decoded to know the correct | 41 // need to wait until the first buffer is decoded to know the correct |
| 49 // information. | 42 // information. |
| 50 codec_context_ = ffmpeg_demuxer_stream->av_stream()->codec; | 43 codec_context_ = ffmpeg_demuxer_stream->av_stream()->codec; |
| 51 media_format_.SetAsInteger(MediaFormat::kChannels, codec_context_->channels); | 44 media_format_.SetAsInteger(MediaFormat::kChannels, codec_context_->channels); |
| 52 media_format_.SetAsInteger(MediaFormat::kSampleBits, | 45 media_format_.SetAsInteger(MediaFormat::kSampleBits, |
| 53 codec_context_->bits_per_coded_sample); | 46 av_get_bits_per_sample_format(codec_context_->sample_fmt)); |
| 54 media_format_.SetAsInteger(MediaFormat::kSampleRate, | 47 media_format_.SetAsInteger(MediaFormat::kSampleRate, |
| 55 codec_context_->sample_rate); | 48 codec_context_->sample_rate); |
| 56 media_format_.SetAsString(MediaFormat::kMimeType, | 49 media_format_.SetAsString(MediaFormat::kMimeType, |
| 57 mime_type::kUncompressedAudio); | 50 mime_type::kUncompressedAudio); |
| 58 | 51 |
| 59 // Grab the codec context from FFmpeg demuxer. | 52 // Grab the codec context from FFmpeg demuxer. |
| 60 AVCodec* codec = avcodec_find_decoder(codec_context_->codec_id); | 53 AVCodec* codec = avcodec_find_decoder(codec_context_->codec_id); |
| 61 if (!codec || avcodec_open(codec_context_, codec) < 0) { | 54 if (!codec || avcodec_open(codec_context_, codec) < 0) { |
| 62 host_->Error(PIPELINE_ERROR_DECODE); | 55 host_->Error(PIPELINE_ERROR_DECODE); |
| 63 return false; | 56 return false; |
| (...skipping 29 matching lines...) Expand all Loading... |
| 93 DataBuffer* result_buffer = new DataBuffer(); | 86 DataBuffer* result_buffer = new DataBuffer(); |
| 94 memcpy(result_buffer->GetWritableData(output_buffer_size), | 87 memcpy(result_buffer->GetWritableData(output_buffer_size), |
| 95 output_buffer, output_buffer_size); | 88 output_buffer, output_buffer_size); |
| 96 result_buffer->SetTimestamp(input->GetTimestamp()); | 89 result_buffer->SetTimestamp(input->GetTimestamp()); |
| 97 result_buffer->SetDuration(input->GetDuration()); | 90 result_buffer->SetDuration(input->GetDuration()); |
| 98 EnqueueResult(result_buffer); | 91 EnqueueResult(result_buffer); |
| 99 } | 92 } |
| 100 } | 93 } |
| 101 | 94 |
| 102 } // namespace | 95 } // namespace |
| OLD | NEW |