diff options
author | scherkus@chromium.org <scherkus@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-12-07 18:54:17 +0000 |
---|---|---|
committer | scherkus@chromium.org <scherkus@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-12-07 18:54:17 +0000 |
commit | b3e1bc055de885a92f7f148f9136bf1570581518 (patch) | |
tree | f8369389ccc2ac3127ee4eb29340c99210a7deb8 /media | |
parent | 9ce7cb4c378d6ac673abfd8c136960424f8308bb (diff) | |
download | chromium_src-b3e1bc055de885a92f7f148f9136bf1570581518.zip chromium_src-b3e1bc055de885a92f7f148f9136bf1570581518.tar.gz chromium_src-b3e1bc055de885a92f7f148f9136bf1570581518.tar.bz2 |
Replace media::Limits struct with media::limits namespace and update documentation.
Review URL: http://codereview.chromium.org/8786013
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@113425 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'media')
-rw-r--r-- | media/audio/audio_parameters.cc | 8 | ||||
-rw-r--r-- | media/audio/win/audio_output_win_unittest.cc | 2 | ||||
-rw-r--r-- | media/base/audio_decoder_config.cc | 4 | ||||
-rw-r--r-- | media/base/buffers.cc | 5 | ||||
-rw-r--r-- | media/base/buffers.h | 3 | ||||
-rw-r--r-- | media/base/limits.h | 44 | ||||
-rw-r--r-- | media/base/video_decoder_config.cc | 6 | ||||
-rw-r--r-- | media/filters/ffmpeg_demuxer.cc | 27 | ||||
-rw-r--r-- | media/filters/video_renderer_base.cc | 6 |
9 files changed, 59 insertions, 46 deletions
diff --git a/media/audio/audio_parameters.cc b/media/audio/audio_parameters.cc index 45c98d9..4395481 100644 --- a/media/audio/audio_parameters.cc +++ b/media/audio/audio_parameters.cc @@ -28,12 +28,12 @@ AudioParameters::AudioParameters(Format format, ChannelLayout channel_layout, bool AudioParameters::IsValid() const { return (format >= 0) && (format < AUDIO_LAST_FORMAT) && - (channels > 0) && (channels <= media::Limits::kMaxChannels) && - (sample_rate > 0) && (sample_rate <= media::Limits::kMaxSampleRate) && + (channels > 0) && (channels <= media::limits::kMaxChannels) && + (sample_rate > 0) && (sample_rate <= media::limits::kMaxSampleRate) && (bits_per_sample > 0) && - (bits_per_sample <= media::Limits::kMaxBitsPerSample) && + (bits_per_sample <= media::limits::kMaxBitsPerSample) && (samples_per_packet > 0) && - (samples_per_packet <= media::Limits::kMaxSamplesPerPacket); + (samples_per_packet <= media::limits::kMaxSamplesPerPacket); } int AudioParameters::GetPacketSize() const { diff --git a/media/audio/win/audio_output_win_unittest.cc b/media/audio/win/audio_output_win_unittest.cc index bc01e73..71c0d0c 100644 --- a/media/audio/win/audio_output_win_unittest.cc +++ b/media/audio/win/audio_output_win_unittest.cc @@ -262,7 +262,7 @@ TEST(WinAudioTest, SanityOnMakeParams) { AudioParameters(fmt, CHANNEL_LAYOUT_MONO, 8000, 16, 0))); EXPECT_TRUE(NULL == audio_man->MakeAudioOutputStream( AudioParameters(fmt, CHANNEL_LAYOUT_MONO, 8000, 16, - media::Limits::kMaxSamplesPerPacket + 1))); + media::limits::kMaxSamplesPerPacket + 1))); } // Test that it can be opened and closed. diff --git a/media/base/audio_decoder_config.cc b/media/base/audio_decoder_config.cc index 243c4c5..ece264b 100644 --- a/media/base/audio_decoder_config.cc +++ b/media/base/audio_decoder_config.cc @@ -100,9 +100,9 @@ bool AudioDecoderConfig::IsValidConfig() const { return codec_ != kUnknownAudioCodec && channel_layout_ != CHANNEL_LAYOUT_UNSUPPORTED && bits_per_channel_ > 0 && - bits_per_channel_ <= Limits::kMaxBitsPerSample && + bits_per_channel_ <= limits::kMaxBitsPerSample && samples_per_second_ > 0 && - samples_per_second_ <= Limits::kMaxSampleRate; + samples_per_second_ <= limits::kMaxSampleRate; } AudioCodec AudioDecoderConfig::codec() const { diff --git a/media/base/buffers.cc b/media/base/buffers.cc index ab66b9a..67a936e 100644 --- a/media/base/buffers.cc +++ b/media/base/buffers.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 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. @@ -9,6 +9,9 @@ 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 82f2402..400eaf7 100644 --- a/media/base/buffers.h +++ b/media/base/buffers.h @@ -37,6 +37,9 @@ namespace media { // Indicates an invalid or missing timestamp. MEDIA_EXPORT extern const base::TimeDelta kNoTimestamp; +// Represents an infinite stream duration. +MEDIA_EXPORT extern const base::TimeDelta kInfiniteDuration; + class MEDIA_EXPORT StreamSample : public base::RefCountedThreadSafe<StreamSample> { public: diff --git a/media/base/limits.h b/media/base/limits.h index 93522d2..2f5b801 100644 --- a/media/base/limits.h +++ b/media/base/limits.h @@ -11,29 +11,35 @@ namespace media { -struct Limits { - // For video. - static const int kMaxDimension = (1 << 15) - 1; // 32767 - static const int kMaxCanvas = (1 << (14 * 2)); // 16384 x 16384 +namespace limits { + +enum { + // Maximum possible dimension (width or height) for any video. + kMaxDimension = (1 << 15) - 1, // 32767 + + // Maximum possible canvas size (width multiplied by height) for any video. + kMaxCanvas = (1 << (14 * 2)), // 16384 x 16384 // Total number of video frames which are populating in the pipeline. - static const size_t kMaxVideoFrames = 4; - - // Following limits are used by AudioParameters::IsValid(). - // The 192 Khz constant is the frequency of quicktime lossless audio codec. - // MP4 is limited to 96 Khz, and mp3 is limited to 48 Khz. - // OGG vorbis was initially limited to 96 Khz, but recent tools are unlimited. - // 192 Khz is also the limit on most PC audio hardware. - static const int kMaxSampleRate = 192000; - static const int kMinSampleRate = 8000; - static const int kMaxChannels = 32; - static const int kMaxBitsPerSample = 64; - static const int kMaxSamplesPerPacket = kMaxSampleRate; - - // Maximum possible time. - static const int64 kMaxTimeInMicroseconds = kint64max; + kMaxVideoFrames = 4, + + // The following limits are used by AudioParameters::IsValid(). + // + // A few notes on sample rates of common formats: + // - AAC files are limited to 96 kHz. + // - MP3 files are limited to 48 kHz. + // - Vorbis used to be limited to 96 KHz, but no longer has that + // restriction. + // - Most PC audio hardware is limited to 192 KHz. + kMaxSampleRate = 192000, + kMinSampleRate = 8000, + kMaxChannels = 32, + kMaxBitsPerSample = 64, + kMaxSamplesPerPacket = kMaxSampleRate, }; +} // namespace limits + } // namespace media #endif // MEDIA_BASE_LIMITS_H_ diff --git a/media/base/video_decoder_config.cc b/media/base/video_decoder_config.cc index 304dd61..ee334d3 100644 --- a/media/base/video_decoder_config.cc +++ b/media/base/video_decoder_config.cc @@ -120,9 +120,9 @@ bool VideoDecoderConfig::IsValidConfig() const { frame_rate_denominator_ > 0 && aspect_ratio_numerator_ > 0 && aspect_ratio_denominator_ > 0 && - natural_size_.width() <= Limits::kMaxDimension && - natural_size_.height() <= Limits::kMaxDimension && - natural_size_.GetArea() <= Limits::kMaxCanvas; + natural_size_.width() <= limits::kMaxDimension && + natural_size_.height() <= limits::kMaxDimension && + natural_size_.GetArea() <= limits::kMaxCanvas; } VideoCodec VideoDecoderConfig::codec() const { diff --git a/media/filters/ffmpeg_demuxer.cc b/media/filters/ffmpeg_demuxer.cc index e33bada..c1a056c 100644 --- a/media/filters/ffmpeg_demuxer.cc +++ b/media/filters/ffmpeg_demuxer.cc @@ -519,10 +519,8 @@ void FFmpegDemuxer::InitializeTask(DataSource* data_source, std::max(max_duration, ConvertFromTimeBase(av_time_base, format_context_->duration)); } else { - // The duration is not a valid value. Assume that this is a live stream - // and set duration to the maximum int64 number to represent infinity. - max_duration = base::TimeDelta::FromMicroseconds( - Limits::kMaxTimeInMicroseconds); + // The duration is unknown, in which case this is likely a live stream. + max_duration = kInfiniteDuration; } // Some demuxers, like WAV, do not put timestamps on their frames. We @@ -559,17 +557,20 @@ int FFmpegDemuxer::GetBitrate() { if (bitrate > 0) return bitrate; - // If there isn't a bitrate set in the container or streams, but there is a - // valid duration, approximate the bitrate using the duration. - if (max_duration_.InMilliseconds() > 0 && - max_duration_.InMicroseconds() < Limits::kMaxTimeInMicroseconds) { - int64 filesize_in_bytes; - if (GetSize(&filesize_in_bytes)) - return 8000 * filesize_in_bytes / max_duration_.InMilliseconds(); + // See if we can approximate the bitrate as long as we have a filesize and + // valid duration. + int64 filesize_in_bytes; + if (max_duration_.InMicroseconds() <= 0 || + max_duration_ == kInfiniteDuration || + !GetSize(&filesize_in_bytes)) { + return 0; } - // Bitrate could not be determined. - return 0; + // Do math in floating point as we'd overflow an int64 if the filesize was + // larger than ~1073GB. + double bytes = filesize_in_bytes; + double duration = max_duration_.InMicroseconds(); + return bytes * 8000000.0 / duration; } bool FFmpegDemuxer::IsLocalSource() { diff --git a/media/filters/video_renderer_base.cc b/media/filters/video_renderer_base.cc index 5162229..4cd7775 100644 --- a/media/filters/video_renderer_base.cc +++ b/media/filters/video_renderer_base.cc @@ -377,7 +377,7 @@ void VideoRendererBase::FrameReady(scoped_refptr<VideoFrame> frame) { // This one's a keeper! Place it in the ready queue. frames_queue_ready_.push_back(frame); DCHECK_LE(frames_queue_ready_.size(), - static_cast<size_t>(Limits::kMaxVideoFrames)); + static_cast<size_t>(limits::kMaxVideoFrames)); frame_available_.Signal(); PipelineStatistics statistics; @@ -388,7 +388,7 @@ void VideoRendererBase::FrameReady(scoped_refptr<VideoFrame> frame) { // purposes: // 1) Prerolling while paused // 2) Keeps decoding going if video rendering thread starts falling behind - if (frames_queue_ready_.size() < Limits::kMaxVideoFrames && + if (frames_queue_ready_.size() < limits::kMaxVideoFrames && !frame->IsEndOfStream()) { AttemptRead_Locked(); return; @@ -420,7 +420,7 @@ void VideoRendererBase::AttemptRead_Locked() { lock_.AssertAcquired(); DCHECK_NE(kEnded, state_); - if (pending_read_ || frames_queue_ready_.size() == Limits::kMaxVideoFrames) { + if (pending_read_ || frames_queue_ready_.size() == limits::kMaxVideoFrames) { return; } |