diff options
author | vrk@google.com <vrk@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-09-19 20:18:33 +0000 |
---|---|---|
committer | vrk@google.com <vrk@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-09-19 20:18:33 +0000 |
commit | 2975fa5391dfd5c57def10929408d814c4acaf6d (patch) | |
tree | 32e17ca77ac82b2adf3e36b23f3f7b7918b6b509 /media/base | |
parent | ef03e1ded45fe5dff2b3a783b1be554b5064dfea (diff) | |
download | chromium_src-2975fa5391dfd5c57def10929408d814c4acaf6d.zip chromium_src-2975fa5391dfd5c57def10929408d814c4acaf6d.tar.gz chromium_src-2975fa5391dfd5c57def10929408d814c4acaf6d.tar.bz2 |
Reland r101418: Fix aspect ratio and clarify video frame dimensions
Fixes shared build errors for windows and linux.
BUG=18941,94861
TEST=shared builds compile
TBR=acolwell
Review URL: http://codereview.chromium.org/7932005
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@101808 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'media/base')
-rw-r--r-- | media/base/composite_filter.cc | 38 | ||||
-rw-r--r-- | media/base/composite_filter.h | 19 | ||||
-rw-r--r-- | media/base/filter_host.h | 4 | ||||
-rw-r--r-- | media/base/filters.h | 6 | ||||
-rw-r--r-- | media/base/mock_filter_host.h | 2 | ||||
-rw-r--r-- | media/base/mock_filters.h | 3 | ||||
-rw-r--r-- | media/base/pipeline.h | 7 | ||||
-rw-r--r-- | media/base/pipeline_impl.cc | 19 | ||||
-rw-r--r-- | media/base/pipeline_impl.h | 84 | ||||
-rw-r--r-- | media/base/pipeline_impl_unittest.cc | 10 | ||||
-rw-r--r-- | media/base/video_decoder_config.cc | 30 | ||||
-rw-r--r-- | media/base/video_decoder_config.h | 29 |
12 files changed, 124 insertions, 127 deletions
diff --git a/media/base/composite_filter.cc b/media/base/composite_filter.cc index a84bf21..d58bfec 100644 --- a/media/base/composite_filter.cc +++ b/media/base/composite_filter.cc @@ -18,22 +18,22 @@ class CompositeFilter::FilterHostImpl : public FilterHost { FilterHost* host(); // media::FilterHost methods. - virtual void SetError(PipelineStatus error); - virtual base::TimeDelta GetTime() const; - virtual base::TimeDelta GetDuration() const; - virtual void SetTime(base::TimeDelta time); - virtual void SetDuration(base::TimeDelta duration); - virtual void SetBufferedTime(base::TimeDelta buffered_time); - virtual void SetTotalBytes(int64 total_bytes); - virtual void SetBufferedBytes(int64 buffered_bytes); - virtual void SetVideoSize(size_t width, size_t height); - virtual void SetStreaming(bool streaming); - virtual void NotifyEnded(); - virtual void SetLoaded(bool loaded); - virtual void SetNetworkActivity(bool network_activity); - virtual void DisableAudioRenderer(); - virtual void SetCurrentReadPosition(int64 offset); - virtual int64 GetCurrentReadPosition(); + virtual void SetError(PipelineStatus error) OVERRIDE; + virtual base::TimeDelta GetTime() const OVERRIDE; + virtual base::TimeDelta GetDuration() const OVERRIDE; + virtual void SetTime(base::TimeDelta time) OVERRIDE; + virtual void SetDuration(base::TimeDelta duration) OVERRIDE; + virtual void SetBufferedTime(base::TimeDelta buffered_time) OVERRIDE; + virtual void SetTotalBytes(int64 total_bytes) OVERRIDE; + virtual void SetBufferedBytes(int64 buffered_bytes) OVERRIDE; + virtual void SetNaturalVideoSize(const gfx::Size& size) OVERRIDE; + virtual void SetStreaming(bool streaming) OVERRIDE; + virtual void NotifyEnded() OVERRIDE; + virtual void SetLoaded(bool loaded) OVERRIDE; + virtual void SetNetworkActivity(bool network_activity) OVERRIDE; + virtual void DisableAudioRenderer() OVERRIDE; + virtual void SetCurrentReadPosition(int64 offset) OVERRIDE; + virtual int64 GetCurrentReadPosition() OVERRIDE; private: CompositeFilter* parent_; @@ -526,9 +526,9 @@ void CompositeFilter::FilterHostImpl::SetBufferedBytes(int64 buffered_bytes) { host_->SetBufferedBytes(buffered_bytes); } -void CompositeFilter::FilterHostImpl::SetVideoSize(size_t width, - size_t height) { - host_->SetVideoSize(width, height); +void CompositeFilter::FilterHostImpl::SetNaturalVideoSize( + const gfx::Size& size) { + host_->SetNaturalVideoSize(size); } void CompositeFilter::FilterHostImpl::SetStreaming(bool streaming) { diff --git a/media/base/composite_filter.h b/media/base/composite_filter.h index 8e1ec4a..ad070bc 100644 --- a/media/base/composite_filter.h +++ b/media/base/composite_filter.h @@ -27,15 +27,16 @@ class MEDIA_EXPORT CompositeFilter : public Filter { bool AddFilter(scoped_refptr<Filter> filter); // media::Filter methods. - virtual void set_host(FilterHost* host); - virtual FilterHost* host(); - virtual void Play(FilterCallback* play_callback); - virtual void Pause(FilterCallback* pause_callback); - virtual void Flush(FilterCallback* flush_callback); - virtual void Stop(FilterCallback* stop_callback); - virtual void SetPlaybackRate(float playback_rate); - virtual void Seek(base::TimeDelta time, const FilterStatusCB& seek_cb); - virtual void OnAudioRendererDisabled(); + virtual void set_host(FilterHost* host) OVERRIDE; + virtual FilterHost* host() OVERRIDE; + virtual void Play(FilterCallback* play_callback) OVERRIDE; + virtual void Pause(FilterCallback* pause_callback) OVERRIDE; + virtual void Flush(FilterCallback* flush_callback) OVERRIDE; + virtual void Stop(FilterCallback* stop_callback) OVERRIDE; + virtual void SetPlaybackRate(float playback_rate) OVERRIDE; + virtual void Seek( + base::TimeDelta time, const FilterStatusCB& seek_cb) OVERRIDE; + virtual void OnAudioRendererDisabled() OVERRIDE; protected: virtual ~CompositeFilter(); diff --git a/media/base/filter_host.h b/media/base/filter_host.h index 510e333..d6977b6 100644 --- a/media/base/filter_host.h +++ b/media/base/filter_host.h @@ -53,8 +53,8 @@ class MEDIA_EXPORT FilterHost { // be played. virtual void SetBufferedBytes(int64 buffered_bytes) = 0; - // Sets the size of the video output in pixel units. - virtual void SetVideoSize(size_t width, size_t height) = 0; + // Sets the natural size of the video output in pixel units. + virtual void SetNaturalVideoSize(const gfx::Size& size) = 0; // Sets the flag to indicate that we are doing streaming. virtual void SetStreaming(bool streaming) = 0; diff --git a/media/base/filters.h b/media/base/filters.h index faafa4e..a379a58 100644 --- a/media/base/filters.h +++ b/media/base/filters.h @@ -35,6 +35,7 @@ #include "media/base/media_export.h" #include "media/base/pipeline_status.h" #include "media/base/video_frame.h" +#include "ui/gfx/size.h" namespace media { @@ -180,15 +181,14 @@ class MEDIA_EXPORT VideoDecoder : public Filter { consume_video_frame_callback_ = callback; } - // Returns the width and height of decoded video in pixels. + // Returns the natural width and height of decoded video in pixels. // // Clients should NOT rely on these values to remain constant. Instead, use // the width/height from decoded video frames themselves. // // TODO(scherkus): why not rely on prerolling and decoding a single frame to // get dimensions? - virtual int width() = 0; - virtual int height() = 0; + virtual gfx::Size natural_size() = 0; protected: // Executes the permanent callback to pass off decoded video. diff --git a/media/base/mock_filter_host.h b/media/base/mock_filter_host.h index 2464de8..9b9cd7c 100644 --- a/media/base/mock_filter_host.h +++ b/media/base/mock_filter_host.h @@ -32,7 +32,7 @@ class MockFilterHost : public FilterHost { MOCK_METHOD1(SetBufferedTime, void(base::TimeDelta buffered_time)); MOCK_METHOD1(SetTotalBytes, void(int64 total_bytes)); MOCK_METHOD1(SetBufferedBytes, void(int64 buffered_bytes)); - MOCK_METHOD2(SetVideoSize, void(size_t width, size_t height)); + MOCK_METHOD1(SetNaturalVideoSize, void(const gfx::Size& size)); MOCK_METHOD1(SetStreaming, void(bool streamed)); MOCK_METHOD1(SetLoaded, void(bool loaded)); MOCK_METHOD1(SetNetworkActivity, void(bool network_activity)); diff --git a/media/base/mock_filters.h b/media/base/mock_filters.h index 8abcbd3..a836f0b 100644 --- a/media/base/mock_filters.h +++ b/media/base/mock_filters.h @@ -184,8 +184,7 @@ class MockVideoDecoder : public VideoDecoder { FilterCallback* callback, StatisticsCallback* stats_callback)); MOCK_METHOD1(ProduceVideoFrame, void(scoped_refptr<VideoFrame>)); - MOCK_METHOD0(width, int()); - MOCK_METHOD0(height, int()); + MOCK_METHOD0(natural_size, gfx::Size()); void VideoFrameReadyForTest(scoped_refptr<VideoFrame> frame) { VideoDecoder::VideoFrameReady(frame); diff --git a/media/base/pipeline.h b/media/base/pipeline.h index 3e1f919..1945010 100644 --- a/media/base/pipeline.h +++ b/media/base/pipeline.h @@ -147,9 +147,10 @@ class MEDIA_EXPORT Pipeline : public base::RefCountedThreadSafe<Pipeline> { // determined or can not be determined, this value is 0. virtual int64 GetTotalBytes() const = 0; - // Gets the size of the video output in pixel units. If there is no video - // or the video has not been rendered yet, the width and height will be 0. - virtual void GetVideoSize(size_t* width_out, size_t* height_out) const = 0; + // Gets the natural size of the video output in pixel units. If there is no + // video or the video has not been rendered yet, the width and height will + // be 0. + virtual void GetNaturalVideoSize(gfx::Size* out_size) const = 0; // If this method returns true, that means the data source is a streaming // data source. Seeking may not be possible. diff --git a/media/base/pipeline_impl.cc b/media/base/pipeline_impl.cc index 0d3c1dd..263441c 100644 --- a/media/base/pipeline_impl.cc +++ b/media/base/pipeline_impl.cc @@ -310,12 +310,10 @@ int64 PipelineImpl::GetTotalBytes() const { return total_bytes_; } -void PipelineImpl::GetVideoSize(size_t* width_out, size_t* height_out) const { - CHECK(width_out); - CHECK(height_out); +void PipelineImpl::GetNaturalVideoSize(gfx::Size* out_size) const { + CHECK(out_size); base::AutoLock auto_lock(lock_); - *width_out = video_width_; - *height_out = video_height_; + *out_size = natural_size_; } bool PipelineImpl::IsStreaming() const { @@ -371,8 +369,7 @@ void PipelineImpl::ResetState() { streaming_ = false; loaded_ = false; total_bytes_ = 0; - video_width_ = 0; - video_height_ = 0; + natural_size_.SetSize(0, 0); volume_ = 1.0f; preload_ = AUTO; playback_rate_ = 0.0f; @@ -536,13 +533,13 @@ void PipelineImpl::SetBufferedBytes(int64 buffered_bytes) { buffered_bytes_ = buffered_bytes; } -void PipelineImpl::SetVideoSize(size_t width, size_t height) { +void PipelineImpl::SetNaturalVideoSize(const gfx::Size& size) { DCHECK(IsRunning()); - media_log_->AddEvent(media_log_->CreateVideoSizeSetEvent(width, height)); + media_log_->AddEvent(media_log_->CreateVideoSizeSetEvent( + size.width(), size.height())); base::AutoLock auto_lock(lock_); - video_width_ = width; - video_height_ = height; + natural_size_ = size; } void PipelineImpl::SetStreaming(bool streaming) { diff --git a/media/base/pipeline_impl.h b/media/base/pipeline_impl.h index bb88272..d792347 100644 --- a/media/base/pipeline_impl.h +++ b/media/base/pipeline_impl.h @@ -25,6 +25,7 @@ #include "media/base/demuxer.h" #include "media/base/filter_host.h" #include "media/base/pipeline.h" +#include "ui/gfx/size.h" namespace media { @@ -101,32 +102,32 @@ class MEDIA_EXPORT PipelineImpl : public Pipeline, public FilterHost { // Pipeline implementation. virtual void Init(const PipelineStatusCB& ended_callback, const PipelineStatusCB& error_callback, - const PipelineStatusCB& network_callback); + const PipelineStatusCB& network_callback) OVERRIDE; virtual bool Start(FilterCollection* filter_collection, const std::string& uri, - const PipelineStatusCB& start_callback); - virtual void Stop(const PipelineStatusCB& stop_callback); + const PipelineStatusCB& start_callback) OVERRIDE; + virtual void Stop(const PipelineStatusCB& stop_callback) OVERRIDE; virtual void Seek(base::TimeDelta time, - const PipelineStatusCB& seek_callback); - virtual bool IsRunning() const; - virtual bool IsInitialized() const; - virtual bool IsNetworkActive() const; - virtual bool HasAudio() const; - virtual bool HasVideo() const; - virtual float GetPlaybackRate() const; - virtual void SetPlaybackRate(float playback_rate); - virtual float GetVolume() const; - virtual void SetVolume(float volume); - virtual void SetPreload(Preload preload); - virtual base::TimeDelta GetCurrentTime() const; - virtual base::TimeDelta GetBufferedTime(); - virtual base::TimeDelta GetMediaDuration() const; - virtual int64 GetBufferedBytes() const; - virtual int64 GetTotalBytes() const; - virtual void GetVideoSize(size_t* width_out, size_t* height_out) const; - virtual bool IsStreaming() const; - virtual bool IsLoaded() const; - virtual PipelineStatistics GetStatistics() const; + const PipelineStatusCB& seek_callback) OVERRIDE; + virtual bool IsRunning() const OVERRIDE; + virtual bool IsInitialized() const OVERRIDE; + virtual bool IsNetworkActive() const OVERRIDE; + virtual bool HasAudio() const OVERRIDE; + virtual bool HasVideo() const OVERRIDE; + virtual float GetPlaybackRate() const OVERRIDE; + virtual void SetPlaybackRate(float playback_rate) OVERRIDE; + virtual float GetVolume() const OVERRIDE; + virtual void SetVolume(float volume) OVERRIDE; + virtual void SetPreload(Preload preload) OVERRIDE; + virtual base::TimeDelta GetCurrentTime() const OVERRIDE; + virtual base::TimeDelta GetBufferedTime() OVERRIDE; + virtual base::TimeDelta GetMediaDuration() const OVERRIDE; + virtual int64 GetBufferedBytes() const OVERRIDE; + virtual int64 GetTotalBytes() const OVERRIDE; + virtual void GetNaturalVideoSize(gfx::Size* out_size) const OVERRIDE; + virtual bool IsStreaming() const OVERRIDE; + virtual bool IsLoaded() const OVERRIDE; + virtual PipelineStatistics GetStatistics() const OVERRIDE; void SetClockForTesting(Clock* clock); @@ -190,22 +191,22 @@ class MEDIA_EXPORT PipelineImpl : public Pipeline, public FilterHost { State FindNextState(State current); // FilterHost implementation. - virtual void SetError(PipelineStatus error); - virtual base::TimeDelta GetTime() const; - virtual base::TimeDelta GetDuration() const; - virtual void SetTime(base::TimeDelta time); - virtual void SetDuration(base::TimeDelta duration); - virtual void SetBufferedTime(base::TimeDelta buffered_time); - virtual void SetTotalBytes(int64 total_bytes); - virtual void SetBufferedBytes(int64 buffered_bytes); - virtual void SetVideoSize(size_t width, size_t height); - virtual void SetStreaming(bool streamed); - virtual void SetLoaded(bool loaded); - virtual void SetNetworkActivity(bool network_activity); - virtual void NotifyEnded(); - virtual void DisableAudioRenderer(); - virtual void SetCurrentReadPosition(int64 offset); - virtual int64 GetCurrentReadPosition(); + virtual void SetError(PipelineStatus error) OVERRIDE; + virtual base::TimeDelta GetTime() const OVERRIDE; + virtual base::TimeDelta GetDuration() const OVERRIDE; + virtual void SetTime(base::TimeDelta time) OVERRIDE; + virtual void SetDuration(base::TimeDelta duration) OVERRIDE; + virtual void SetBufferedTime(base::TimeDelta buffered_time) OVERRIDE; + virtual void SetTotalBytes(int64 total_bytes) OVERRIDE; + virtual void SetBufferedBytes(int64 buffered_bytes) OVERRIDE; + virtual void SetNaturalVideoSize(const gfx::Size& size) OVERRIDE; + virtual void SetStreaming(bool streamed) OVERRIDE; + virtual void SetLoaded(bool loaded) OVERRIDE; + virtual void SetNetworkActivity(bool network_activity) OVERRIDE; + virtual void NotifyEnded() OVERRIDE; + virtual void DisableAudioRenderer() OVERRIDE; + virtual void SetCurrentReadPosition(int64 offset) OVERRIDE; + virtual int64 GetCurrentReadPosition() OVERRIDE; // Callback executed by filters upon completing initialization. void OnFilterInitialize(); @@ -371,9 +372,8 @@ class MEDIA_EXPORT PipelineImpl : public Pipeline, public FilterHost { // Total size of the media. Set by filters. int64 total_bytes_; - // Video width and height. Set by filters. - size_t video_width_; - size_t video_height_; + // Video's natural width and height. Set by filters. + gfx::Size natural_size_; // Sets by the filters to indicate whether the data source is a streaming // source. diff --git a/media/base/pipeline_impl_unittest.cc b/media/base/pipeline_impl_unittest.cc index 66b430a..c1cd68d 100644 --- a/media/base/pipeline_impl_unittest.cc +++ b/media/base/pipeline_impl_unittest.cc @@ -15,6 +15,7 @@ #include "media/base/mock_callback.h" #include "media/base/mock_filters.h" #include "testing/gtest/include/gtest/gtest.h" +#include "ui/gfx/size.h" using ::testing::_; using ::testing::DeleteArg; @@ -308,11 +309,10 @@ TEST_F(PipelineImplTest, NotStarted) { EXPECT_EQ(0, pipeline_->GetTotalBytes()); // Should always get set to zero. - size_t width = 1u; - size_t height = 1u; - pipeline_->GetVideoSize(&width, &height); - EXPECT_EQ(0u, width); - EXPECT_EQ(0u, height); + gfx::Size size(1, 1); + pipeline_->GetNaturalVideoSize(&size); + EXPECT_EQ(0, size.width()); + EXPECT_EQ(0, size.height()); } TEST_F(PipelineImplTest, NeverInitializes) { diff --git a/media/base/video_decoder_config.cc b/media/base/video_decoder_config.cc index 0d3ae76..52104cb 100644 --- a/media/base/video_decoder_config.cc +++ b/media/base/video_decoder_config.cc @@ -9,19 +9,17 @@ namespace media { VideoDecoderConfig::VideoDecoderConfig(VideoCodec codec, - int width, - int height, - int surface_width, - int surface_height, + const gfx::Size& coded_size, + const gfx::Rect& visible_rect, + const gfx::Size& natural_size, int frame_rate_numerator, int frame_rate_denominator, const uint8* extra_data, size_t extra_data_size) : codec_(codec), - width_(width), - height_(height), - surface_width_(surface_width), - surface_height_(surface_height), + coded_size_(coded_size), + visible_rect_(visible_rect), + natural_size_(natural_size), frame_rate_numerator_(frame_rate_numerator), frame_rate_denominator_(frame_rate_denominator), extra_data_size_(extra_data_size) { @@ -38,20 +36,16 @@ VideoCodec VideoDecoderConfig::codec() const { return codec_; } -int VideoDecoderConfig::width() const { - return width_; +gfx::Size VideoDecoderConfig::coded_size() const { + return coded_size_; } -int VideoDecoderConfig::height() const { - return height_; +gfx::Rect VideoDecoderConfig::visible_rect() const { + return visible_rect_; } -int VideoDecoderConfig::surface_width() const { - return surface_width_; -} - -int VideoDecoderConfig::surface_height() const { - return surface_height_; +gfx::Size VideoDecoderConfig::natural_size() const { + return natural_size_; } int VideoDecoderConfig::frame_rate_numerator() const { diff --git a/media/base/video_decoder_config.h b/media/base/video_decoder_config.h index 360451a..fcfd3e7 100644 --- a/media/base/video_decoder_config.h +++ b/media/base/video_decoder_config.h @@ -8,6 +8,8 @@ #include "base/basictypes.h" #include "base/memory/scoped_ptr.h" #include "media/base/media_export.h" +#include "ui/gfx/rect.h" +#include "ui/gfx/size.h" namespace media { @@ -28,17 +30,17 @@ enum VideoCodec { class MEDIA_EXPORT VideoDecoderConfig { public: - VideoDecoderConfig(VideoCodec codec, int width, int height, - int surface_width, int surface_height, + VideoDecoderConfig(VideoCodec codec, const gfx::Size& coded_size, + const gfx::Rect& visible_rect, + const gfx::Size& natural_size, int frame_rate_numerator, int frame_rate_denominator, const uint8* extra_data, size_t extra_data_size); ~VideoDecoderConfig(); VideoCodec codec() const; - int width() const; - int height() const; - int surface_width() const; - int surface_height() const; + gfx::Size coded_size() const; + gfx::Rect visible_rect() const; + gfx::Size natural_size() const; int frame_rate_numerator() const; int frame_rate_denominator() const; uint8* extra_data() const; @@ -47,13 +49,16 @@ class MEDIA_EXPORT VideoDecoderConfig { private: VideoCodec codec_; - // Container's concept of width and height of this video. - int width_; - int height_; + // Width and height of video frame immediately post-decode. Not all pixels + // in this region are valid. + gfx::Size coded_size_; - // Width and height of the display surface for this video. - int surface_width_; - int surface_height_; + // Region of |coded_size_| that is visible. + gfx::Rect visible_rect_; + + // Natural width and height of the video, i.e. the visible dimensions + // after aspect ratio is applied. + gfx::Size natural_size_; // Frame rate in seconds expressed as a fraction. // TODO(scherkus): fairly certain decoders don't require frame rates. |