diff options
author | fischman@chromium.org <fischman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-01-18 03:29:37 +0000 |
---|---|---|
committer | fischman@chromium.org <fischman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-01-18 03:29:37 +0000 |
commit | eb5d608b4b2a345da0ae80097ecfc7e522301590 (patch) | |
tree | 4471d19b8dbc00ca48944381910955d4cd22eed3 /media | |
parent | 47c7ec8be8c6829d7973568fe453f46046c2e818 (diff) | |
download | chromium_src-eb5d608b4b2a345da0ae80097ecfc7e522301590.zip chromium_src-eb5d608b4b2a345da0ae80097ecfc7e522301590.tar.gz chromium_src-eb5d608b4b2a345da0ae80097ecfc7e522301590.tar.bz2 |
buffers.cc: replaced global TimeDelta constants with fully-inlined functions.
media_log.cc: replaced global AtomicSequenceNumber with LazyInstance.
BUG=94925
TEST=none
Review URL: http://codereview.chromium.org/9225001
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@118026 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'media')
-rw-r--r-- | media/base/buffers.cc | 8 | ||||
-rw-r--r-- | media/base/buffers.h | 10 | ||||
-rw-r--r-- | media/base/clock.cc | 2 | ||||
-rw-r--r-- | media/base/media_log.cc | 6 | ||||
-rw-r--r-- | media/base/pts_stream.cc | 12 | ||||
-rw-r--r-- | media/base/pts_stream_unittest.cc | 10 | ||||
-rw-r--r-- | media/base/seekable_buffer.cc | 6 | ||||
-rw-r--r-- | media/base/seekable_buffer.h | 4 | ||||
-rw-r--r-- | media/base/seekable_buffer_unittest.cc | 24 | ||||
-rw-r--r-- | media/filters/audio_renderer_algorithm_base.h | 2 | ||||
-rw-r--r-- | media/filters/chunk_demuxer.cc | 10 | ||||
-rw-r--r-- | media/filters/ffmpeg_audio_decoder.cc | 16 | ||||
-rw-r--r-- | media/filters/ffmpeg_demuxer.cc | 12 | ||||
-rw-r--r-- | media/filters/ffmpeg_video_decoder.cc | 4 | ||||
-rw-r--r-- | media/filters/ffmpeg_video_decoder_unittest.cc | 4 |
15 files changed, 65 insertions, 65 deletions
diff --git a/media/base/buffers.cc b/media/base/buffers.cc index 67a936e..9f59c18 100644 --- a/media/base/buffers.cc +++ b/media/base/buffers.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -6,12 +6,6 @@ namespace media { -const base::TimeDelta kNoTimestamp = - base::TimeDelta::FromMicroseconds(kint64min); - -const base::TimeDelta kInfiniteDuration = - base::TimeDelta::FromMicroseconds(kint64max); - StreamSample::StreamSample() {} StreamSample::~StreamSample() {} diff --git a/media/base/buffers.h b/media/base/buffers.h index 400eaf7..cbe89e1 100644 --- a/media/base/buffers.h +++ b/media/base/buffers.h @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -35,10 +35,14 @@ namespace media { // Indicates an invalid or missing timestamp. -MEDIA_EXPORT extern const base::TimeDelta kNoTimestamp; +MEDIA_EXPORT extern inline base::TimeDelta kNoTimestamp() { + return base::TimeDelta::FromMicroseconds(kint64min); +} // Represents an infinite stream duration. -MEDIA_EXPORT extern const base::TimeDelta kInfiniteDuration; +MEDIA_EXPORT extern inline base::TimeDelta kInfiniteDuration() { + return base::TimeDelta::FromMicroseconds(kint64max); +} class MEDIA_EXPORT StreamSample : public base::RefCountedThreadSafe<StreamSample> { diff --git a/media/base/clock.cc b/media/base/clock.cc index aaa0c13..4cdc021 100644 --- a/media/base/clock.cc +++ b/media/base/clock.cc @@ -46,7 +46,7 @@ void Clock::SetPlaybackRate(float playback_rate) { } void Clock::SetTime(const base::TimeDelta& time) { - if (time == kNoTimestamp) { + if (time == kNoTimestamp()) { NOTREACHED(); return; } diff --git a/media/base/media_log.cc b/media/base/media_log.cc index 2312942..a9fabe2 100644 --- a/media/base/media_log.cc +++ b/media/base/media_log.cc @@ -8,6 +8,7 @@ #include "base/atomic_sequence_num.h" #include "base/bind.h" +#include "base/lazy_instance.h" #include "base/logging.h" #include "base/memory/scoped_ptr.h" #include "base/values.h" @@ -16,7 +17,8 @@ namespace media { // A count of all MediaLogs created on this render process. // Used to generate unique ids. -static base::AtomicSequenceNumber media_log_count(base::LINKER_INITIALIZED); +static base::LazyInstance<base::AtomicSequenceNumber> media_log_count = + LAZY_INSTANCE_INITIALIZER; const char* MediaLog::EventTypeToString(MediaLogEvent::Type type) { switch (type) { @@ -144,7 +146,7 @@ const char* MediaLog::PipelineStatusToString(PipelineStatus status) { } MediaLog::MediaLog() { - id_ = media_log_count.GetNext(); + id_ = media_log_count.Get().GetNext(); stats_update_pending_ = false; } diff --git a/media/base/pts_stream.cc b/media/base/pts_stream.cc index 0223cdb..48cec61 100644 --- a/media/base/pts_stream.cc +++ b/media/base/pts_stream.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -31,7 +31,7 @@ void PtsStream::Flush() { void PtsStream::EnqueuePts(StreamSample* sample) { DCHECK(sample); - if (!sample->IsEndOfStream() && sample->GetTimestamp() != kNoTimestamp) { + if (!sample->IsEndOfStream() && sample->GetTimestamp() != kNoTimestamp()) { pts_heap_.Push(sample->GetTimestamp()); } } @@ -46,7 +46,7 @@ void PtsStream::UpdatePtsAndDuration(StreamSample* sample) { // situation and set the timestamp to kInvalidTimestamp. DCHECK(sample); base::TimeDelta timestamp = sample->GetTimestamp(); - if (timestamp != kNoTimestamp && + if (timestamp != kNoTimestamp() && timestamp.ToInternalValue() != 0) { current_pts_ = timestamp; // We need to clean up the timestamp we pushed onto the |pts_heap_|. @@ -56,18 +56,18 @@ void PtsStream::UpdatePtsAndDuration(StreamSample* sample) { // If the frame did not have pts, try to get the pts from the |pts_heap|. current_pts_ = pts_heap_.Top(); pts_heap_.Pop(); - } else if (current_pts_ != kNoTimestamp) { + } else if (current_pts_ != kNoTimestamp()) { // Guess assuming this frame was the same as the last frame. current_pts_ = current_pts_ + current_duration_; } else { // Now we really have no clue!!! Mark an invalid timestamp and let the // video renderer handle it (i.e., drop frame). - current_pts_ = kNoTimestamp; + current_pts_ = kNoTimestamp(); } // Fill in the duration, using the frame itself as the authoratative source. base::TimeDelta duration = sample->GetDuration(); - if (duration != kNoTimestamp && + if (duration != kNoTimestamp() && duration.ToInternalValue() != 0) { current_duration_ = duration; } else { diff --git a/media/base/pts_stream_unittest.cc b/media/base/pts_stream_unittest.cc index 22f3807..5b200b7 100644 --- a/media/base/pts_stream_unittest.cc +++ b/media/base/pts_stream_unittest.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -31,8 +31,8 @@ class PtsStreamTest : public testing::Test { TEST_F(PtsStreamTest, NoTimestamp) { // Simulate an uninitialized |video_frame| where we cannot determine a // timestamp at all. - video_frame_->SetTimestamp(kNoTimestamp); - video_frame_->SetDuration(kNoTimestamp); + video_frame_->SetTimestamp(kNoTimestamp()); + video_frame_->SetDuration(kNoTimestamp()); pts_stream_.UpdatePtsAndDuration(video_frame_); EXPECT_EQ(0, pts_stream_.current_pts().InMicroseconds()); EXPECT_EQ(40000, pts_stream_.current_duration().InMicroseconds()); @@ -48,8 +48,8 @@ TEST_F(PtsStreamTest, LastKnownTimestamp) { // Simulate an uninitialized |video_frame| where last known pts will be used // to generate a timestamp and |frame_duration| will be used to generate a // duration. - video_frame_->SetTimestamp(kNoTimestamp); - video_frame_->SetDuration(kNoTimestamp); + video_frame_->SetTimestamp(kNoTimestamp()); + video_frame_->SetDuration(kNoTimestamp()); pts_stream_.UpdatePtsAndDuration(video_frame_); EXPECT_EQ(116, pts_stream_.current_pts().InMicroseconds()); EXPECT_EQ(40000, pts_stream_.current_duration().InMicroseconds()); diff --git a/media/base/seekable_buffer.cc b/media/base/seekable_buffer.cc index 2e3180a..b9ad7a4 100644 --- a/media/base/seekable_buffer.cc +++ b/media/base/seekable_buffer.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -18,7 +18,7 @@ SeekableBuffer::SeekableBuffer(size_t backward_capacity, backward_bytes_(0), forward_capacity_(forward_capacity), forward_bytes_(0), - current_time_(kNoTimestamp) { + current_time_(kNoTimestamp()) { current_buffer_ = buffers_.begin(); } @@ -31,7 +31,7 @@ void SeekableBuffer::Clear() { current_buffer_offset_ = 0; backward_bytes_ = 0; forward_bytes_ = 0; - current_time_ = kNoTimestamp; + current_time_ = kNoTimestamp(); } size_t SeekableBuffer::Read(uint8* data, size_t size) { diff --git a/media/base/seekable_buffer.h b/media/base/seekable_buffer.h index 18dee8d..56a7ceb 100644 --- a/media/base/seekable_buffer.h +++ b/media/base/seekable_buffer.h @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -121,7 +121,7 @@ class MEDIA_EXPORT SeekableBuffer { // timestamp for the current buffer is set to 0 or the data was added with // Append(const uint*, size_t), then returns value that corresponds to the // last position in a buffer that had timestamp set. - // kNoTimestamp is returned if no buffers we read from had timestamp set. + // kNoTimestamp() is returned if no buffers we read from had timestamp set. base::TimeDelta current_time() const { return current_time_; } private: diff --git a/media/base/seekable_buffer_unittest.cc b/media/base/seekable_buffer_unittest.cc index cf87b5d..2cb547f 100644 --- a/media/base/seekable_buffer_unittest.cc +++ b/media/base/seekable_buffer_unittest.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -298,15 +298,15 @@ TEST_F(SeekableBufferTest, GetTime) { int64 expected_time; } tests[] = { // Timestamps of 0 are treated as garbage. - { 0, 1000000, 0, kNoTimestamp.ToInternalValue() }, - { 0, 4000000, 0, kNoTimestamp.ToInternalValue() }, - { 0, 8000000, 0, kNoTimestamp.ToInternalValue() }, - { 0, 1000000, 4, kNoTimestamp.ToInternalValue() }, - { 0, 4000000, 4, kNoTimestamp.ToInternalValue() }, - { 0, 8000000, 4, kNoTimestamp.ToInternalValue() }, - { 0, 1000000, kWriteSize, kNoTimestamp.ToInternalValue() }, - { 0, 4000000, kWriteSize, kNoTimestamp.ToInternalValue() }, - { 0, 8000000, kWriteSize, kNoTimestamp.ToInternalValue() }, + { 0, 1000000, 0, kNoTimestamp().ToInternalValue() }, + { 0, 4000000, 0, kNoTimestamp().ToInternalValue() }, + { 0, 8000000, 0, kNoTimestamp().ToInternalValue() }, + { 0, 1000000, 4, kNoTimestamp().ToInternalValue() }, + { 0, 4000000, 4, kNoTimestamp().ToInternalValue() }, + { 0, 8000000, 4, kNoTimestamp().ToInternalValue() }, + { 0, 1000000, kWriteSize, kNoTimestamp().ToInternalValue() }, + { 0, 4000000, kWriteSize, kNoTimestamp().ToInternalValue() }, + { 0, 8000000, kWriteSize, kNoTimestamp().ToInternalValue() }, { 5, 1000000, 0, 5 }, { 5, 4000000, 0, 5 }, { 5, 8000000, 0, 5 }, @@ -318,8 +318,8 @@ TEST_F(SeekableBufferTest, GetTime) { { 5, 8000000, kWriteSize, 8000005 }, }; - // current_time() must initially return kNoTimestamp. - EXPECT_EQ(kNoTimestamp.ToInternalValue(), + // current_time() must initially return kNoTimestamp(). + EXPECT_EQ(kNoTimestamp().ToInternalValue(), buffer_.current_time().ToInternalValue()); scoped_refptr<media::DataBuffer> buffer(new media::DataBuffer(kWriteSize)); diff --git a/media/filters/audio_renderer_algorithm_base.h b/media/filters/audio_renderer_algorithm_base.h index 2b134aa..d11dbb6 100644 --- a/media/filters/audio_renderer_algorithm_base.h +++ b/media/filters/audio_renderer_algorithm_base.h @@ -65,7 +65,7 @@ class MEDIA_EXPORT AudioRendererAlgorithmBase { // Clears |audio_buffer_|. void FlushBuffers(); - // Returns the time of the next byte in our data or kNoTimestamp if current + // Returns the time of the next byte in our data or kNoTimestamp() if current // time is unknown. base::TimeDelta GetTime(); diff --git a/media/filters/chunk_demuxer.cc b/media/filters/chunk_demuxer.cc index ba3224b..e4f1700 100644 --- a/media/filters/chunk_demuxer.cc +++ b/media/filters/chunk_demuxer.cc @@ -69,7 +69,7 @@ ChunkDemuxerStream::ChunkDemuxerStream(const AudioDecoderConfig& audio_config) : type_(AUDIO), shutdown_called_(false), received_end_of_stream_(false), - last_buffer_timestamp_(kNoTimestamp) { + last_buffer_timestamp_(kNoTimestamp()) { audio_config_.CopyFrom(audio_config); } @@ -78,7 +78,7 @@ ChunkDemuxerStream::ChunkDemuxerStream(const VideoDecoderConfig& video_config) : type_(VIDEO), shutdown_called_(false), received_end_of_stream_(false), - last_buffer_timestamp_(kNoTimestamp) { + last_buffer_timestamp_(kNoTimestamp()) { video_config_.CopyFrom(video_config); } @@ -89,14 +89,14 @@ void ChunkDemuxerStream::Flush() { base::AutoLock auto_lock(lock_); buffers_.clear(); received_end_of_stream_ = false; - last_buffer_timestamp_ = kNoTimestamp; + last_buffer_timestamp_ = kNoTimestamp(); } bool ChunkDemuxerStream::CanAddBuffers(const BufferQueue& buffers) const { base::AutoLock auto_lock(lock_); // If we haven't seen any buffers yet, then anything can be added. - if (last_buffer_timestamp_ == kNoTimestamp) + if (last_buffer_timestamp_ == kNoTimestamp()) return true; if (buffers.empty()) @@ -131,7 +131,7 @@ void ChunkDemuxerStream::AddBuffers(const BufferQueue& buffers) { } } else { base::TimeDelta current_ts = (*itr)->GetTimestamp(); - if (last_buffer_timestamp_ != kNoTimestamp) { + if (last_buffer_timestamp_ != kNoTimestamp()) { DCHECK_GT(current_ts.ToInternalValue(), last_buffer_timestamp_.ToInternalValue()); } diff --git a/media/filters/ffmpeg_audio_decoder.cc b/media/filters/ffmpeg_audio_decoder.cc index 61aa02b..1e8cc60 100644 --- a/media/filters/ffmpeg_audio_decoder.cc +++ b/media/filters/ffmpeg_audio_decoder.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -31,8 +31,8 @@ static bool IsTimestampMarkerPacket(int result, Buffer* input) { // We can get a positive result but no decoded data. This is ok because this // this can be a marker packet that only contains timestamp. return result > 0 && !input->IsEndOfStream() && - input->GetTimestamp() != kNoTimestamp && - input->GetDuration() != kNoTimestamp; + input->GetTimestamp() != kNoTimestamp() && + input->GetDuration() != kNoTimestamp(); } // Returns true if the decode result was end of stream. @@ -151,7 +151,7 @@ void FFmpegAudioDecoder::DoInitialize( void FFmpegAudioDecoder::DoFlush(const base::Closure& callback) { avcodec_flush_buffers(codec_context_); - estimated_next_timestamp_ = kNoTimestamp; + estimated_next_timestamp_ = kNoTimestamp(); callback.Run(); } @@ -171,8 +171,8 @@ void FFmpegAudioDecoder::DoDecodeBuffer(const scoped_refptr<Buffer>& input) { // FFmpeg tends to seek Ogg audio streams in the middle of nowhere, giving us // a whole bunch of AV_NOPTS_VALUE packets. Discard them until we find // something valid. Refer to http://crbug.com/49709 - if (input->GetTimestamp() == kNoTimestamp && - estimated_next_timestamp_ == kNoTimestamp && + if (input->GetTimestamp() == kNoTimestamp() && + estimated_next_timestamp_ == kNoTimestamp() && !input->IsEndOfStream()) { ReadFromDemuxerStream(); return; @@ -261,7 +261,7 @@ void FFmpegAudioDecoder::UpdateDurationAndTimestamp( output->SetDuration(duration); // Use the incoming timestamp if it's valid. - if (input->GetTimestamp() != kNoTimestamp) { + if (input->GetTimestamp() != kNoTimestamp()) { output->SetTimestamp(input->GetTimestamp()); estimated_next_timestamp_ = input->GetTimestamp() + duration; return; @@ -270,7 +270,7 @@ void FFmpegAudioDecoder::UpdateDurationAndTimestamp( // Otherwise use an estimated timestamp and attempt to update the estimation // as long as it's valid. output->SetTimestamp(estimated_next_timestamp_); - if (estimated_next_timestamp_ != kNoTimestamp) { + if (estimated_next_timestamp_ != kNoTimestamp()) { estimated_next_timestamp_ += duration; } } diff --git a/media/filters/ffmpeg_demuxer.cc b/media/filters/ffmpeg_demuxer.cc index 158f116..6e3627e 100644 --- a/media/filters/ffmpeg_demuxer.cc +++ b/media/filters/ffmpeg_demuxer.cc @@ -270,7 +270,7 @@ const VideoDecoderConfig& FFmpegDemuxerStream::video_decoder_config() { base::TimeDelta FFmpegDemuxerStream::ConvertStreamTimestamp( const AVRational& time_base, int64 timestamp) { if (timestamp == static_cast<int64>(AV_NOPTS_VALUE)) - return kNoTimestamp; + return kNoTimestamp(); return ConvertFromTimeBase(time_base, timestamp); } @@ -289,7 +289,7 @@ FFmpegDemuxer::FFmpegDemuxer(MessageLoop* message_loop, bool local_source) max_duration_(base::TimeDelta::FromMicroseconds(-1)), deferred_status_(PIPELINE_OK), first_seek_hack_(true), - start_time_(kNoTimestamp) { + start_time_(kNoTimestamp()) { DCHECK(message_loop_); } @@ -516,7 +516,7 @@ void FFmpegDemuxer::InitializeTask(DataSource* data_source, if (stream->first_dts != static_cast<int64_t>(AV_NOPTS_VALUE)) { const base::TimeDelta first_dts = ConvertFromTimeBase( stream->time_base, stream->first_dts); - if (start_time_ == kNoTimestamp || first_dts < start_time_) + if (start_time_ == kNoTimestamp() || first_dts < start_time_) start_time_ = first_dts; } } @@ -535,12 +535,12 @@ void FFmpegDemuxer::InitializeTask(DataSource* data_source, ConvertFromTimeBase(av_time_base, format_context_->duration)); } else { // The duration is unknown, in which case this is likely a live stream. - max_duration = kInfiniteDuration; + max_duration = kInfiniteDuration(); } // Some demuxers, like WAV, do not put timestamps on their frames. We // assume the the start time is 0. - if (start_time_ == kNoTimestamp) + if (start_time_ == kNoTimestamp()) start_time_ = base::TimeDelta(); // Good to go: set the duration and bitrate and notify we're done @@ -576,7 +576,7 @@ int FFmpegDemuxer::GetBitrate() { // valid duration. int64 filesize_in_bytes; if (max_duration_.InMicroseconds() <= 0 || - max_duration_ == kInfiniteDuration || + max_duration_ == kInfiniteDuration() || !GetSize(&filesize_in_bytes)) { return 0; } diff --git a/media/filters/ffmpeg_video_decoder.cc b/media/filters/ffmpeg_video_decoder.cc index c1fa54d..213c09e 100644 --- a/media/filters/ffmpeg_video_decoder.cc +++ b/media/filters/ffmpeg_video_decoder.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -418,7 +418,7 @@ scoped_refptr<VideoFrame> FFmpegVideoDecoder::AllocateVideoFrame() { size_t height = codec_context_->height; return VideoFrame::CreateFrame(format, width, height, - kNoTimestamp, kNoTimestamp); + kNoTimestamp(), kNoTimestamp()); } } // namespace media diff --git a/media/filters/ffmpeg_video_decoder_unittest.cc b/media/filters/ffmpeg_video_decoder_unittest.cc index d9c1fd4..a87bafa 100644 --- a/media/filters/ffmpeg_video_decoder_unittest.cc +++ b/media/filters/ffmpeg_video_decoder_unittest.cc @@ -491,8 +491,8 @@ TEST_F(FFmpegVideoDecoderTest, Timestamps_Estimated) { PushTimestamp(0); PushTimestamp(1000); - PushTimestamp(kNoTimestamp.InMicroseconds()); - PushTimestamp(kNoTimestamp.InMicroseconds()); + PushTimestamp(kNoTimestamp().InMicroseconds()); + PushTimestamp(kNoTimestamp().InMicroseconds()); EXPECT_EQ(0, PopTimestamp()); EXPECT_EQ(1000, PopTimestamp()); |