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

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

Issue 3032030: Implement accurate seeking by decoding audio/video until we reach our desired timestamp. (Closed)
Patch Set: Fixes Created 10 years, 5 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/audio_renderer_base.cc ('k') | media/filters/video_renderer_base.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) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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/filters/ffmpeg_audio_decoder.h" 5 #include "media/filters/ffmpeg_audio_decoder.h"
6 6
7 #include "media/base/callback.h" 7 #include "media/base/callback.h"
8 #include "media/base/data_buffer.h" 8 #include "media/base/data_buffer.h"
9 #include "media/base/limits.h" 9 #include "media/base/limits.h"
10 #include "media/ffmpeg/ffmpeg_common.h" 10 #include "media/ffmpeg/ffmpeg_common.h"
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
148 *reinterpret_cast<int32*>(p) = sample; 148 *reinterpret_cast<int32*>(p) = sample;
149 } 149 }
150 #endif 150 #endif
151 static void ConvertAudioF32ToS32(void* buffer, int buffer_size) { 151 static void ConvertAudioF32ToS32(void* buffer, int buffer_size) {
152 for (int i = 0; i < buffer_size / 4; ++i) { 152 for (int i = 0; i < buffer_size / 4; ++i) {
153 FloatToIntSaturate(reinterpret_cast<float*>(buffer) + i); 153 FloatToIntSaturate(reinterpret_cast<float*>(buffer) + i);
154 } 154 }
155 } 155 }
156 156
157 void FFmpegAudioDecoder::DoDecode(Buffer* input) { 157 void FFmpegAudioDecoder::DoDecode(Buffer* input) {
158 // FFmpeg tends to seek Ogg audio streams in the middle of nowhere, giving us
159 // a whole bunch of AV_NOPTS_VALUE packets. Discard them until we find
160 // something valid.
161 // TODO(hclam): remove this once fixing the issue in FFmpeg.
162 if (input->GetTimestamp() == StreamSample::kInvalidTimestamp &&
163 estimated_next_timestamp_ == StreamSample::kInvalidTimestamp &&
164 !input->IsEndOfStream()) {
165 DecoderBase<AudioDecoder, Buffer>::OnDecodeComplete();
166 return;
167 }
168
158 // Due to FFmpeg API changes we no longer have const read-only pointers. 169 // Due to FFmpeg API changes we no longer have const read-only pointers.
159 AVPacket packet; 170 AVPacket packet;
160 av_init_packet(&packet); 171 av_init_packet(&packet);
161 packet.data = const_cast<uint8*>(input->GetData()); 172 packet.data = const_cast<uint8*>(input->GetData());
162 packet.size = input->GetDataSize(); 173 packet.size = input->GetDataSize();
163 174
164 int16_t* output_buffer = reinterpret_cast<int16_t*>(output_buffer_.get()); 175 int16_t* output_buffer = reinterpret_cast<int16_t*>(output_buffer_.get());
165 int output_buffer_size = kOutputBufferSize; 176 int output_buffer_size = kOutputBufferSize;
166 int result = avcodec_decode_audio3(codec_context_, 177 int result = avcodec_decode_audio3(codec_context_,
167 output_buffer, 178 output_buffer,
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
245 base::TimeDelta FFmpegAudioDecoder::CalculateDuration(size_t size) { 256 base::TimeDelta FFmpegAudioDecoder::CalculateDuration(size_t size) {
246 int64 denominator = codec_context_->channels * 257 int64 denominator = codec_context_->channels *
247 av_get_bits_per_sample_format(codec_context_->sample_fmt) / 8 * 258 av_get_bits_per_sample_format(codec_context_->sample_fmt) / 8 *
248 codec_context_->sample_rate; 259 codec_context_->sample_rate;
249 double microseconds = size / 260 double microseconds = size /
250 (denominator / static_cast<double>(base::Time::kMicrosecondsPerSecond)); 261 (denominator / static_cast<double>(base::Time::kMicrosecondsPerSecond));
251 return base::TimeDelta::FromMicroseconds(static_cast<int64>(microseconds)); 262 return base::TimeDelta::FromMicroseconds(static_cast<int64>(microseconds));
252 } 263 }
253 264
254 } // namespace 265 } // namespace
OLDNEW
« no previous file with comments | « media/filters/audio_renderer_base.cc ('k') | media/filters/video_renderer_base.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698