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

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

Issue 113598: Use av_rescale_q() for converting FFmpeg timestamps to base::TimeDelta. (Closed)
Patch Set: Tweaksd Created 11 years, 7 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
« no previous file with comments | « media/filters/ffmpeg_audio_decoder.h ('k') | media/filters/ffmpeg_demuxer.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 18 matching lines...) Expand all
29 } 29 }
30 30
31 bool FFmpegAudioDecoder::OnInitialize(DemuxerStream* demuxer_stream) { 31 bool FFmpegAudioDecoder::OnInitialize(DemuxerStream* demuxer_stream) {
32 scoped_refptr<FFmpegDemuxerStream> ffmpeg_demuxer_stream; 32 scoped_refptr<FFmpegDemuxerStream> ffmpeg_demuxer_stream;
33 33
34 // Try to obtain a reference to FFmpegDemuxer. 34 // Try to obtain a reference to FFmpegDemuxer.
35 if (!demuxer_stream-> 35 if (!demuxer_stream->
36 QueryInterface<FFmpegDemuxerStream>(&ffmpeg_demuxer_stream)) 36 QueryInterface<FFmpegDemuxerStream>(&ffmpeg_demuxer_stream))
37 return false; 37 return false;
38 38
39 // Setting the media format. 39 // Grab the AVStream's codec context and make sure we have sensible values.
40 codec_context_ = ffmpeg_demuxer_stream->av_stream()->codec;
41 DCHECK_GT(codec_context_->channels, 0);
42 DCHECK_GT(av_get_bits_per_sample_format(codec_context_->sample_fmt), 0);
43 DCHECK_GT(codec_context_->sample_rate, 0);
44
45 // Set the media format.
40 // TODO(hclam): Reuse the information provided by the demuxer for now, we may 46 // TODO(hclam): Reuse the information provided by the demuxer for now, we may
41 // need to wait until the first buffer is decoded to know the correct 47 // need to wait until the first buffer is decoded to know the correct
42 // information. 48 // information.
43 codec_context_ = ffmpeg_demuxer_stream->av_stream()->codec;
44 media_format_.SetAsInteger(MediaFormat::kChannels, codec_context_->channels); 49 media_format_.SetAsInteger(MediaFormat::kChannels, codec_context_->channels);
45 media_format_.SetAsInteger(MediaFormat::kSampleBits, 50 media_format_.SetAsInteger(MediaFormat::kSampleBits,
46 av_get_bits_per_sample_format(codec_context_->sample_fmt)); 51 av_get_bits_per_sample_format(codec_context_->sample_fmt));
47 media_format_.SetAsInteger(MediaFormat::kSampleRate, 52 media_format_.SetAsInteger(MediaFormat::kSampleRate,
48 codec_context_->sample_rate); 53 codec_context_->sample_rate);
49 media_format_.SetAsString(MediaFormat::kMimeType, 54 media_format_.SetAsString(MediaFormat::kMimeType,
50 mime_type::kUncompressedAudio); 55 mime_type::kUncompressedAudio);
51 56
52 // Grab the codec context from FFmpeg demuxer. 57 // Grab the codec context from FFmpeg demuxer.
53 AVCodec* codec = avcodec_find_decoder(codec_context_->codec_id); 58 AVCodec* codec = avcodec_find_decoder(codec_context_->codec_id);
(...skipping 29 matching lines...) Expand all
83 output_buffer_size < 0 || 88 output_buffer_size < 0 ||
84 static_cast<size_t>(output_buffer_size) > kOutputBufferSize) { 89 static_cast<size_t>(output_buffer_size) > kOutputBufferSize) {
85 host_->Error(PIPELINE_ERROR_DECODE); 90 host_->Error(PIPELINE_ERROR_DECODE);
86 } else if (result == 0) { 91 } else if (result == 0) {
87 // TODO(scherkus): does this mark EOS? Do we want to fulfill a read request 92 // TODO(scherkus): does this mark EOS? Do we want to fulfill a read request
88 // with zero size? 93 // with zero size?
89 } else { 94 } else {
90 DataBuffer* result_buffer = new DataBuffer(); 95 DataBuffer* result_buffer = new DataBuffer();
91 memcpy(result_buffer->GetWritableData(output_buffer_size), 96 memcpy(result_buffer->GetWritableData(output_buffer_size),
92 output_buffer, output_buffer_size); 97 output_buffer, output_buffer_size);
98
99 // Determine the duration if the demuxer couldn't figure it out, otherwise
100 // copy it over.
101 if (input->GetDuration().InMicroseconds() == 0) {
102 result_buffer->SetDuration(CalculateDuration(output_buffer_size));
103 } else {
104 result_buffer->SetDuration(input->GetDuration());
105 }
106
107 // Copy over the timestamp.
93 result_buffer->SetTimestamp(input->GetTimestamp()); 108 result_buffer->SetTimestamp(input->GetTimestamp());
94 result_buffer->SetDuration(input->GetDuration()); 109
95 EnqueueResult(result_buffer); 110 EnqueueResult(result_buffer);
96 } 111 }
97 } 112 }
98 113
114 base::TimeDelta FFmpegAudioDecoder::CalculateDuration(size_t size) {
115 int64 denominator = codec_context_->channels *
116 av_get_bits_per_sample_format(codec_context_->sample_fmt) / 8 *
117 codec_context_->sample_rate;
118 double microseconds = size /
119 (denominator / static_cast<double>(base::Time::kMicrosecondsPerSecond));
120 return base::TimeDelta::FromMicroseconds(static_cast<int64>(microseconds));
121 }
122
99 } // namespace 123 } // namespace
OLDNEW
« no previous file with comments | « media/filters/ffmpeg_audio_decoder.h ('k') | media/filters/ffmpeg_demuxer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698