diff options
author | nsylvain@chromium.org <nsylvain@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-05-20 03:43:22 +0000 |
---|---|---|
committer | nsylvain@chromium.org <nsylvain@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-05-20 03:43:22 +0000 |
commit | a199e400093448023d4f6c555f32d230b3fb2fcd (patch) | |
tree | c037a20ac60faeef1c6273aa3b2a6c3050a717da /media | |
parent | 8edd34f129bfc61b8b5fe85767b30c7a9a32e026 (diff) | |
download | chromium_src-a199e400093448023d4f6c555f32d230b3fb2fcd.zip chromium_src-a199e400093448023d4f6c555f32d230b3fb2fcd.tar.gz chromium_src-a199e400093448023d4f6c555f32d230b3fb2fcd.tar.bz2 |
Revert change 16453 because it broke the build.
Review URL: http://codereview.chromium.org/113615
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@16459 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'media')
-rw-r--r-- | media/base/media_posix.cc | 11 | ||||
-rw-r--r-- | media/filters/ffmpeg_audio_decoder.cc | 30 | ||||
-rw-r--r-- | media/filters/ffmpeg_audio_decoder.h | 4 | ||||
-rw-r--r-- | media/filters/ffmpeg_demuxer.cc | 20 | ||||
-rw-r--r-- | media/filters/ffmpeg_demuxer.h | 10 |
5 files changed, 18 insertions, 57 deletions
diff --git a/media/base/media_posix.cc b/media/base/media_posix.cc index 94c1a89..4bddf6d 100644 --- a/media/base/media_posix.cc +++ b/media/base/media_posix.cc @@ -122,11 +122,6 @@ void av_free(void* ptr) { return av_free_ptr(ptr); } -int64_t (*av_rescale_q_ptr)(int64_t a, AVRational bq, AVRational cq) = NULL; -int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq) { - return av_rescale_q_ptr(a, bq, cq); -} - } // extern "C" @@ -245,9 +240,6 @@ bool InitializeMediaLibrary(const FilePath& module_dir) { av_free_ptr = reinterpret_cast<void (*)(void*)>( dlsym(libs[FILE_LIBAVUTIL], "av_free")); - av_rescale_q_ptr = - reinterpret_cast<int64_t (*)(int64_t, AVRational, AVRational)>( - dlsym(libs[FILE_LIBAVUTIL], "av_rescale_q")); // Check that all the symbols were loaded correctly before returning true. if (av_get_bits_per_sample_format_ptr && @@ -267,8 +259,7 @@ bool InitializeMediaLibrary(const FilePath& module_dir) { av_register_protocol_ptr && av_malloc_ptr && - av_free_ptr && - av_rescale_q_ptr) { + av_free_ptr) { return true; } diff --git a/media/filters/ffmpeg_audio_decoder.cc b/media/filters/ffmpeg_audio_decoder.cc index e44880a..77b602d 100644 --- a/media/filters/ffmpeg_audio_decoder.cc +++ b/media/filters/ffmpeg_audio_decoder.cc @@ -36,16 +36,11 @@ bool FFmpegAudioDecoder::OnInitialize(DemuxerStream* demuxer_stream) { QueryInterface<FFmpegDemuxerStream>(&ffmpeg_demuxer_stream)) return false; - // Grab the AVStream's codec context and make sure we have sensible values. - codec_context_ = ffmpeg_demuxer_stream->av_stream()->codec; - DCHECK_GT(codec_context_->channels, 0); - DCHECK_GT(av_get_bits_per_sample_format(codec_context_->sample_fmt), 0); - DCHECK_GT(codec_context_->sample_rate, 0); - - // Set the media format. + // Setting the media format. // TODO(hclam): Reuse the information provided by the demuxer for now, we may // need to wait until the first buffer is decoded to know the correct // information. + codec_context_ = ffmpeg_demuxer_stream->av_stream()->codec; media_format_.SetAsInteger(MediaFormat::kChannels, codec_context_->channels); media_format_.SetAsInteger(MediaFormat::kSampleBits, av_get_bits_per_sample_format(codec_context_->sample_fmt)); @@ -95,29 +90,10 @@ void FFmpegAudioDecoder::OnDecode(Buffer* input) { DataBuffer* result_buffer = new DataBuffer(); memcpy(result_buffer->GetWritableData(output_buffer_size), output_buffer, output_buffer_size); - - // Determine the duration if the demuxer couldn't figure it out, otherwise - // copy it over. - if (input->GetDuration().InMicroseconds() == 0) { - result_buffer->SetDuration(CalculateDuration(output_buffer_size)); - } else { - result_buffer->SetDuration(input->GetDuration()); - } - - // Copy over the timestamp. result_buffer->SetTimestamp(input->GetTimestamp()); - + result_buffer->SetDuration(input->GetDuration()); EnqueueResult(result_buffer); } } -base::TimeDelta FFmpegAudioDecoder::CalculateDuration(size_t size) { - int64 denominator = codec_context_->channels * - av_get_bits_per_sample_format(codec_context_->sample_fmt) / 8 * - codec_context_->sample_rate; - double microseconds = size / - (denominator / static_cast<double>(base::Time::kMicrosecondsPerSecond)); - return base::TimeDelta::FromMicroseconds(static_cast<int64>(microseconds)); -} - } // namespace diff --git a/media/filters/ffmpeg_audio_decoder.h b/media/filters/ffmpeg_audio_decoder.h index f30f330..ffb99f8 100644 --- a/media/filters/ffmpeg_audio_decoder.h +++ b/media/filters/ffmpeg_audio_decoder.h @@ -34,10 +34,6 @@ class FFmpegAudioDecoder : public DecoderBase<AudioDecoder, Buffer> { FFmpegAudioDecoder(); virtual ~FFmpegAudioDecoder(); - // Calculates the duration of an audio buffer based on the sample rate, - // channels and bits per sample given the size in bytes. - base::TimeDelta CalculateDuration(size_t size); - // A FFmpeg defined structure that holds decoder information, this variable // is initialized in OnInitialize(). AVCodecContext* codec_context_; diff --git a/media/filters/ffmpeg_demuxer.cc b/media/filters/ffmpeg_demuxer.cc index ab3974b..077314e 100644 --- a/media/filters/ffmpeg_demuxer.cc +++ b/media/filters/ffmpeg_demuxer.cc @@ -51,7 +51,7 @@ class AVPacketBuffer : public Buffer { FFmpegDemuxerStream::FFmpegDemuxerStream(FFmpegDemuxer* demuxer, AVStream* stream) : demuxer_(demuxer), - stream_(stream), + av_stream_(stream), discontinuous_(false) { DCHECK(demuxer_); @@ -70,8 +70,12 @@ FFmpegDemuxerStream::FFmpegDemuxerStream(FFmpegDemuxer* demuxer, break; } - // Calculate the duration. - duration_ = ConvertTimestamp(stream->duration); + // Calculate the time base and duration in microseconds. + int64 time_base_us = static_cast<int64>(av_q2d(stream->time_base) * + base::Time::kMicrosecondsPerSecond); + int64 duration_us = static_cast<int64>(time_base_us * stream->duration); + time_base_ = base::TimeDelta::FromMicroseconds(time_base_us); + duration_ = base::TimeDelta::FromMicroseconds(duration_us); } FFmpegDemuxerStream::~FFmpegDemuxerStream() { @@ -102,8 +106,8 @@ bool FFmpegDemuxerStream::HasPendingReads() { } base::TimeDelta FFmpegDemuxerStream::EnqueuePacket(AVPacket* packet) { - base::TimeDelta timestamp = ConvertTimestamp(packet->pts); - base::TimeDelta duration = ConvertTimestamp(packet->duration); + base::TimeDelta timestamp = time_base_ * packet->pts; + base::TimeDelta duration = time_base_ * packet->duration; Buffer* buffer = new AVPacketBuffer(packet, timestamp, duration); DCHECK(buffer); { @@ -162,12 +166,6 @@ bool FFmpegDemuxerStream::FulfillPendingReads() { return pending_reads; } -base::TimeDelta FFmpegDemuxerStream::ConvertTimestamp(int64 timestamp) { - AVRational time_base = { 1, base::Time::kMicrosecondsPerSecond }; - int64 microseconds = av_rescale_q(timestamp, stream_->time_base, time_base); - return base::TimeDelta::FromMicroseconds(microseconds); -} - // // FFmpegDemuxer diff --git a/media/filters/ffmpeg_demuxer.h b/media/filters/ffmpeg_demuxer.h index bd785b7..9e92cd4 100644 --- a/media/filters/ffmpeg_demuxer.h +++ b/media/filters/ffmpeg_demuxer.h @@ -70,7 +70,9 @@ class FFmpegDemuxerStream : public DemuxerStream { virtual const MediaFormat& media_format(); virtual void Read(Callback1<Buffer*>::Type* read_callback); - AVStream* av_stream() const { return stream_; } + AVStream* av_stream() { + return av_stream_; + } static const char* interface_id(); @@ -81,12 +83,10 @@ class FFmpegDemuxerStream : public DemuxerStream { // Returns true if there are still pending reads. bool FulfillPendingReads(); - // Converts an FFmpeg stream timestamp into a base::TimeDelta. - base::TimeDelta ConvertTimestamp(int64 timestamp); - FFmpegDemuxer* demuxer_; - AVStream* stream_; + AVStream* av_stream_; MediaFormat media_format_; + base::TimeDelta time_base_; base::TimeDelta duration_; bool discontinuous_; |