Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(180)

Side by Side Diff: media/filters/ffmpeg_audio_decoder.cc

Issue 125027: Fixing bug that 8bit PCM stream is gabbled... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
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 {
(...skipping 24 matching lines...) Expand all
35 return false; 35 return false;
36 } 36 }
37 AVStream* av_stream = av_stream_provider->GetAVStream(); 37 AVStream* av_stream = av_stream_provider->GetAVStream();
38 38
39 // Grab the AVStream's codec context and make sure we have sensible values. 39 // Grab the AVStream's codec context and make sure we have sensible values.
40 codec_context_ = av_stream->codec; 40 codec_context_ = av_stream->codec;
41 DCHECK_GT(codec_context_->channels, 0); 41 DCHECK_GT(codec_context_->channels, 0);
42 DCHECK_GT(av_get_bits_per_sample_format(codec_context_->sample_fmt), 0); 42 DCHECK_GT(av_get_bits_per_sample_format(codec_context_->sample_fmt), 0);
43 DCHECK_GT(codec_context_->sample_rate, 0); 43 DCHECK_GT(codec_context_->sample_rate, 0);
44 44
45 // Set the media format. 45 // Grab the codec context from FFmpeg demuxer.
46 AVCodec* codec = avcodec_find_decoder(codec_context_->codec_id);
47 if (!codec || avcodec_open(codec_context_, codec) < 0) {
48 host_->Error(PIPELINE_ERROR_DECODE);
49 return false;
50 }
51
52 // When calling avcodec_find_decoder(), |codec_context_| might be altered by
53 // the decoder to give more accurate values of the output format of the
54 // decoder. So set the media format after a decoder is allocated.
46 // TODO(hclam): Reuse the information provided by the demuxer for now, we may 55 // TODO(hclam): Reuse the information provided by the demuxer for now, we may
47 // need to wait until the first buffer is decoded to know the correct 56 // need to wait until the first buffer is decoded to know the correct
48 // information. 57 // information.
49 media_format_.SetAsInteger(MediaFormat::kChannels, codec_context_->channels); 58 media_format_.SetAsInteger(MediaFormat::kChannels, codec_context_->channels);
50 media_format_.SetAsInteger(MediaFormat::kSampleBits, 59 media_format_.SetAsInteger(MediaFormat::kSampleBits,
51 av_get_bits_per_sample_format(codec_context_->sample_fmt)); 60 av_get_bits_per_sample_format(codec_context_->sample_fmt));
52 media_format_.SetAsInteger(MediaFormat::kSampleRate, 61 media_format_.SetAsInteger(MediaFormat::kSampleRate,
53 codec_context_->sample_rate); 62 codec_context_->sample_rate);
54 media_format_.SetAsString(MediaFormat::kMimeType, 63 media_format_.SetAsString(MediaFormat::kMimeType,
55 mime_type::kUncompressedAudio); 64 mime_type::kUncompressedAudio);
56 65
57 // Grab the codec context from FFmpeg demuxer.
58 AVCodec* codec = avcodec_find_decoder(codec_context_->codec_id);
59 if (!codec || avcodec_open(codec_context_, codec) < 0) {
60 host_->Error(PIPELINE_ERROR_DECODE);
61 return false;
62 }
63
64 // Prepare the output buffer. 66 // Prepare the output buffer.
65 output_buffer_.reset(static_cast<uint8*>(av_malloc(kOutputBufferSize))); 67 output_buffer_.reset(static_cast<uint8*>(av_malloc(kOutputBufferSize)));
66 if (!output_buffer_.get()) { 68 if (!output_buffer_.get()) {
67 host_->Error(PIPELINE_ERROR_OUT_OF_MEMORY); 69 host_->Error(PIPELINE_ERROR_OUT_OF_MEMORY);
68 return false; 70 return false;
69 } 71 }
70 return true; 72 return true;
71 } 73 }
72 74
73 void FFmpegAudioDecoder::OnStop() { 75 void FFmpegAudioDecoder::OnStop() {
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 base::TimeDelta FFmpegAudioDecoder::CalculateDuration(size_t size) { 140 base::TimeDelta FFmpegAudioDecoder::CalculateDuration(size_t size) {
139 int64 denominator = codec_context_->channels * 141 int64 denominator = codec_context_->channels *
140 av_get_bits_per_sample_format(codec_context_->sample_fmt) / 8 * 142 av_get_bits_per_sample_format(codec_context_->sample_fmt) / 8 *
141 codec_context_->sample_rate; 143 codec_context_->sample_rate;
142 double microseconds = size / 144 double microseconds = size /
143 (denominator / static_cast<double>(base::Time::kMicrosecondsPerSecond)); 145 (denominator / static_cast<double>(base::Time::kMicrosecondsPerSecond));
144 return base::TimeDelta::FromMicroseconds(static_cast<int64>(microseconds)); 146 return base::TimeDelta::FromMicroseconds(static_cast<int64>(microseconds));
145 } 147 }
146 148
147 } // namespace 149 } // namespace
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698