diff options
author | acolwell@chromium.org <acolwell@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-01-09 23:52:25 +0000 |
---|---|---|
committer | acolwell@chromium.org <acolwell@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-01-09 23:52:25 +0000 |
commit | a830cd58ac3f146a797553abf6533b8fd3a5399d (patch) | |
tree | 4158d599f32e75956931c4b1badabfd3485391cb /media/base | |
parent | 91e0e293fdf8be438d14b8ca25537fe3785aa3bf (diff) | |
download | chromium_src-a830cd58ac3f146a797553abf6533b8fd3a5399d.zip chromium_src-a830cd58ac3f146a797553abf6533b8fd3a5399d.tar.gz chromium_src-a830cd58ac3f146a797553abf6533b8fd3a5399d.tar.bz2 |
Move WebM specific code from ChunkDemuxer to WebMStreamParser.
Created StreamParser interface to allow ChunkDemuxer to support formats other than WebM.
BUG=108329
TEST=Existing ChunkDemuxer unittests
Review URL: http://codereview.chromium.org/9018019
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@116957 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'media/base')
-rw-r--r-- | media/base/audio_decoder_config.cc | 45 | ||||
-rw-r--r-- | media/base/audio_decoder_config.h | 8 | ||||
-rw-r--r-- | media/base/stream_parser.cc | 17 | ||||
-rw-r--r-- | media/base/stream_parser.h | 85 | ||||
-rw-r--r-- | media/base/video_decoder_config.cc | 38 | ||||
-rw-r--r-- | media/base/video_decoder_config.h | 8 |
6 files changed, 172 insertions, 29 deletions
diff --git a/media/base/audio_decoder_config.cc b/media/base/audio_decoder_config.cc index ece264b..38e0136 100644 --- a/media/base/audio_decoder_config.cc +++ b/media/base/audio_decoder_config.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. @@ -25,7 +25,7 @@ AudioDecoderConfig::AudioDecoderConfig(AudioCodec codec, const uint8* extra_data, size_t extra_data_size) { Initialize(codec, bits_per_channel, channel_layout, samples_per_second, - extra_data, extra_data_size); + extra_data, extra_data_size, true); } // Helper enum used only for histogramming samples-per-second. Put @@ -63,21 +63,26 @@ void AudioDecoderConfig::Initialize(AudioCodec codec, ChannelLayout channel_layout, int samples_per_second, const uint8* extra_data, - size_t extra_data_size) { + size_t extra_data_size, + bool record_stats) { CHECK((extra_data_size != 0) == (extra_data != NULL)); - UMA_HISTOGRAM_ENUMERATION("Media.AudioCodec", codec, kAudioCodecMax + 1); - // Fake enum histogram to get exact integral buckets. Expect to never see - // any values over 32 and even that is huge. - UMA_HISTOGRAM_ENUMERATION("Media.AudioBitsPerChannel", bits_per_channel, 40); - UMA_HISTOGRAM_ENUMERATION( - "Media.AudioChannelLayout", channel_layout, CHANNEL_LAYOUT_MAX); - AudioSamplesPerSecond asps = AsAudioSamplesPerSecond(samples_per_second); - if (asps != kUnexpected) { - UMA_HISTOGRAM_ENUMERATION("Media.AudioSamplesPerSecond", asps, kUnexpected); - } else { - UMA_HISTOGRAM_COUNTS( - "Media.AudioSamplesPerSecondUnexpected", samples_per_second); + if (record_stats) { + UMA_HISTOGRAM_ENUMERATION("Media.AudioCodec", codec, kAudioCodecMax + 1); + // Fake enum histogram to get exact integral buckets. Expect to never see + // any values over 32 and even that is huge. + UMA_HISTOGRAM_ENUMERATION("Media.AudioBitsPerChannel", bits_per_channel, + 40); + UMA_HISTOGRAM_ENUMERATION( + "Media.AudioChannelLayout", channel_layout, CHANNEL_LAYOUT_MAX); + AudioSamplesPerSecond asps = AsAudioSamplesPerSecond(samples_per_second); + if (asps != kUnexpected) { + UMA_HISTOGRAM_ENUMERATION("Media.AudioSamplesPerSecond", asps, + kUnexpected); + } else { + UMA_HISTOGRAM_COUNTS( + "Media.AudioSamplesPerSecondUnexpected", samples_per_second); + } } codec_ = codec; @@ -105,6 +110,16 @@ bool AudioDecoderConfig::IsValidConfig() const { samples_per_second_ <= limits::kMaxSampleRate; } +void AudioDecoderConfig::CopyFrom(const AudioDecoderConfig& audio_config) { + Initialize(audio_config.codec(), + audio_config.bits_per_channel(), + audio_config.channel_layout(), + audio_config.samples_per_second(), + audio_config.extra_data(), + audio_config.extra_data_size(), + false); +} + AudioCodec AudioDecoderConfig::codec() const { return codec_; } diff --git a/media/base/audio_decoder_config.h b/media/base/audio_decoder_config.h index 168a941..90f51c1 100644 --- a/media/base/audio_decoder_config.h +++ b/media/base/audio_decoder_config.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. @@ -52,7 +52,11 @@ class MEDIA_EXPORT AudioDecoderConfig { // Resets the internal state of this object. void Initialize(AudioCodec codec, int bits_per_channel, ChannelLayout channel_layout, int samples_per_second, - const uint8* extra_data, size_t extra_data_size); + const uint8* extra_data, size_t extra_data_size, + bool record_stats); + + // Deep copies |audio_config|. + void CopyFrom(const AudioDecoderConfig& audio_config); // Returns true if this object has appropriate configuration values, false // otherwise. diff --git a/media/base/stream_parser.cc b/media/base/stream_parser.cc new file mode 100644 index 0000000..255cc6f --- /dev/null +++ b/media/base/stream_parser.cc @@ -0,0 +1,17 @@ +// 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. + +#include "media/base/stream_parser.h" + +namespace media { + +StreamParserHost::StreamParserHost() {} + +StreamParserHost::~StreamParserHost() {} + +StreamParser::StreamParser() {} + +StreamParser::~StreamParser() {} + +} // namespace media diff --git a/media/base/stream_parser.h b/media/base/stream_parser.h new file mode 100644 index 0000000..71baf130 --- /dev/null +++ b/media/base/stream_parser.h @@ -0,0 +1,85 @@ +// 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. + +#ifndef MEDIA_BASE_STREAM_PARSER_H_ +#define MEDIA_BASE_STREAM_PARSER_H_ + +#include <deque> + +#include "base/callback_forward.h" +#include "base/memory/ref_counted.h" +#include "base/time.h" + +namespace media { + +class AudioDecoderConfig; +class Buffer; +class VideoDecoderConfig; + +// Provides callback methods for StreamParser to report information +// about the media stream. +class StreamParserHost { + public: + typedef std::deque<scoped_refptr<Buffer> > BufferQueue; + + StreamParserHost(); + virtual ~StreamParserHost(); + + // A new audio decoder configuration was encountered. All audio buffers + // after this call will be associated with this configuration. + virtual bool OnNewAudioConfig(const AudioDecoderConfig& config) = 0; + + // A new video decoder configuration was encountered. All video buffers + // after this call will be associated with this configuration. + virtual bool OnNewVideoConfig(const VideoDecoderConfig& config) = 0; + + // New audio buffers have been received. + virtual bool OnAudioBuffers(const BufferQueue& buffers) = 0; + + // New video buffers have been received. + virtual bool OnVideoBuffers(const BufferQueue& buffers) = 0; + + private: + DISALLOW_COPY_AND_ASSIGN(StreamParserHost); +}; + +// Abstract interface for parsing media byte streams. +class StreamParser { + public: + StreamParser(); + virtual ~StreamParser(); + + // Indicates completion of parser initialization. + // First parameter - Indicates initialization success. Set to true if + // initialization was successful. False if an error + // occurred. + // Second parameter - Indicates the stream duration. Only contains a valid + // value if the first parameter is true. + typedef base::Callback<void(bool, base::TimeDelta)> InitCB; + + // Initialize the parser with necessary callbacks. Must be called before any + // data is passed to Parse(). |init_cb| will be called once enough data has + // been parsed to determine the initial stream configurations, presentation + // start time, and duration. + virtual void Init(const InitCB& init_cb, StreamParserHost* host) = 0; + + // Called when a seek occurs. This flushes the current parser state + // and puts the parser in a state where it can receive data for the new seek + // point. + virtual void Flush() = 0; + + // Called when there is new data to parse. + // + // Returns < 0 if the parse fails. + // Returns 0 if more data is needed. + // Returning > 0 indicates success & the number of bytes parsed. + virtual int Parse(const uint8* buf, int size) = 0; + + private: + DISALLOW_COPY_AND_ASSIGN(StreamParser); +}; + +} // namespace media + +#endif // MEDIA_BASE_STREAM_PARSER_H_ diff --git a/media/base/video_decoder_config.cc b/media/base/video_decoder_config.cc index 07bf9a5..4966dfb 100644 --- a/media/base/video_decoder_config.cc +++ b/media/base/video_decoder_config.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. @@ -37,7 +37,7 @@ VideoDecoderConfig::VideoDecoderConfig(VideoCodec codec, Initialize(codec, profile, format, coded_size, visible_rect, frame_rate_numerator, frame_rate_denominator, aspect_ratio_numerator, aspect_ratio_denominator, - extra_data, extra_data_size); + extra_data, extra_data_size, true); } VideoDecoderConfig::~VideoDecoderConfig() {} @@ -74,16 +74,19 @@ void VideoDecoderConfig::Initialize(VideoCodec codec, int aspect_ratio_numerator, int aspect_ratio_denominator, const uint8* extra_data, - size_t extra_data_size) { + size_t extra_data_size, + bool record_stats) { CHECK((extra_data_size != 0) == (extra_data != NULL)); - UMA_HISTOGRAM_ENUMERATION("Media.VideoCodec", codec, kVideoCodecMax + 1); - UMA_HISTOGRAM_ENUMERATION("Media.VideoCodecProfile", profile, - VIDEO_CODEC_PROFILE_MAX + 1); - UMA_HISTOGRAM_COUNTS_10000("Media.VideoCodedWidth", coded_size.width()); - UmaHistogramAspectRatio("Media.VideoCodedAspectRatio", coded_size); - UMA_HISTOGRAM_COUNTS_10000("Media.VideoVisibleWidth", visible_rect.width()); - UmaHistogramAspectRatio("Media.VideoVisibleAspectRatio", visible_rect); + if (record_stats) { + UMA_HISTOGRAM_ENUMERATION("Media.VideoCodec", codec, kVideoCodecMax + 1); + UMA_HISTOGRAM_ENUMERATION("Media.VideoCodecProfile", profile, + VIDEO_CODEC_PROFILE_MAX + 1); + UMA_HISTOGRAM_COUNTS_10000("Media.VideoCodedWidth", coded_size.width()); + UmaHistogramAspectRatio("Media.VideoCodedAspectRatio", coded_size); + UMA_HISTOGRAM_COUNTS_10000("Media.VideoVisibleWidth", visible_rect.width()); + UmaHistogramAspectRatio("Media.VideoVisibleAspectRatio", visible_rect); + } codec_ = codec; profile_ = profile; @@ -120,6 +123,21 @@ void VideoDecoderConfig::Initialize(VideoCodec codec, natural_size_.SetSize(width & ~1, height); } +void VideoDecoderConfig::CopyFrom(const VideoDecoderConfig& video_config) { + Initialize(video_config.codec(), + video_config.profile(), + video_config.format(), + video_config.coded_size(), + video_config.visible_rect(), + video_config.frame_rate_numerator(), + video_config.frame_rate_denominator(), + video_config.aspect_ratio_numerator(), + video_config.aspect_ratio_denominator(), + video_config.extra_data(), + video_config.extra_data_size(), + false); +} + bool VideoDecoderConfig::IsValidConfig() const { return codec_ != kUnknownVideoCodec && format_ != VideoFrame::INVALID && diff --git a/media/base/video_decoder_config.h b/media/base/video_decoder_config.h index 28b1106..96dd677 100644 --- a/media/base/video_decoder_config.h +++ b/media/base/video_decoder_config.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. @@ -82,7 +82,11 @@ class MEDIA_EXPORT VideoDecoderConfig { const gfx::Rect& visible_rect, int frame_rate_numerator, int frame_rate_denominator, int aspect_ratio_numerator, int aspect_ratio_denominator, - const uint8* extra_data, size_t extra_data_size); + const uint8* extra_data, size_t extra_data_size, + bool record_stats); + + // Deep copies |video_config|. + void CopyFrom(const VideoDecoderConfig& video_config); // Returns true if this object has appropriate configuration values, false // otherwise. |