diff options
author | vrk@google.com <vrk@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-09-16 00:20:20 +0000 |
---|---|---|
committer | vrk@google.com <vrk@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-09-16 00:20:20 +0000 |
commit | e4d9491934ef4bb70aeac5c92cbe76e0399e7367 (patch) | |
tree | 743748d7cc4708e501fb09cfe1e7805b1f1e3dce /media | |
parent | a1d41ed5a126c9426f986930fb420e0c9c3f7faa (diff) | |
download | chromium_src-e4d9491934ef4bb70aeac5c92cbe76e0399e7367.zip chromium_src-e4d9491934ef4bb70aeac5c92cbe76e0399e7367.tar.gz chromium_src-e4d9491934ef4bb70aeac5c92cbe76e0399e7367.tar.bz2 |
Revert 101418 - Fix aspect ratio and clarify video frame dimensions
BUG=18941,94861
TEST=video-aspect-ratio.html
Review URL: http://codereview.chromium.org/7864009
TBR=vrk@google.com
Review URL: http://codereview.chromium.org/7919006
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@101420 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'media')
25 files changed, 206 insertions, 196 deletions
diff --git a/media/base/composite_filter.cc b/media/base/composite_filter.cc index d58bfec..a84bf21 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) 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; + 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(); private: CompositeFilter* parent_; @@ -526,9 +526,9 @@ void CompositeFilter::FilterHostImpl::SetBufferedBytes(int64 buffered_bytes) { host_->SetBufferedBytes(buffered_bytes); } -void CompositeFilter::FilterHostImpl::SetNaturalVideoSize( - const gfx::Size& size) { - host_->SetNaturalVideoSize(size); +void CompositeFilter::FilterHostImpl::SetVideoSize(size_t width, + size_t height) { + host_->SetVideoSize(width, height); } void CompositeFilter::FilterHostImpl::SetStreaming(bool streaming) { diff --git a/media/base/composite_filter.h b/media/base/composite_filter.h index ad070bc..8e1ec4a 100644 --- a/media/base/composite_filter.h +++ b/media/base/composite_filter.h @@ -27,16 +27,15 @@ class MEDIA_EXPORT CompositeFilter : public Filter { bool AddFilter(scoped_refptr<Filter> filter); // media::Filter methods. - 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; + 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(); protected: virtual ~CompositeFilter(); diff --git a/media/base/filter_host.h b/media/base/filter_host.h index d6977b6..510e333 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 natural size of the video output in pixel units. - virtual void SetNaturalVideoSize(const gfx::Size& size) = 0; + // Sets the size of the video output in pixel units. + virtual void SetVideoSize(size_t width, size_t height) = 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 dba2efa..180739d 100644 --- a/media/base/filters.h +++ b/media/base/filters.h @@ -35,7 +35,6 @@ #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 { @@ -181,14 +180,15 @@ class MEDIA_EXPORT VideoDecoder : public Filter { consume_video_frame_callback_ = callback; } - // Returns the natural width and height of decoded video in pixels. + // Returns the 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 gfx::Size natural_size() = 0; + virtual int width() = 0; + virtual int height() = 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 9b9cd7c..2464de8 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_METHOD1(SetNaturalVideoSize, void(const gfx::Size& size)); + MOCK_METHOD2(SetVideoSize, void(size_t width, size_t height)); 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 901361c..e215186 100644 --- a/media/base/mock_filters.h +++ b/media/base/mock_filters.h @@ -184,7 +184,8 @@ class MockVideoDecoder : public VideoDecoder { FilterCallback* callback, StatisticsCallback* stats_callback)); MOCK_METHOD1(ProduceVideoFrame, void(scoped_refptr<VideoFrame>)); - MOCK_METHOD0(natural_size, gfx::Size()); + MOCK_METHOD0(width, int()); + MOCK_METHOD0(height, int()); void VideoFrameReadyForTest(scoped_refptr<VideoFrame> frame) { VideoDecoder::VideoFrameReady(frame); diff --git a/media/base/pipeline.h b/media/base/pipeline.h index 1945010..3e1f919 100644 --- a/media/base/pipeline.h +++ b/media/base/pipeline.h @@ -147,10 +147,9 @@ 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 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; + // 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; // 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 263441c..0d3c1dd 100644 --- a/media/base/pipeline_impl.cc +++ b/media/base/pipeline_impl.cc @@ -310,10 +310,12 @@ int64 PipelineImpl::GetTotalBytes() const { return total_bytes_; } -void PipelineImpl::GetNaturalVideoSize(gfx::Size* out_size) const { - CHECK(out_size); +void PipelineImpl::GetVideoSize(size_t* width_out, size_t* height_out) const { + CHECK(width_out); + CHECK(height_out); base::AutoLock auto_lock(lock_); - *out_size = natural_size_; + *width_out = video_width_; + *height_out = video_height_; } bool PipelineImpl::IsStreaming() const { @@ -369,7 +371,8 @@ void PipelineImpl::ResetState() { streaming_ = false; loaded_ = false; total_bytes_ = 0; - natural_size_.SetSize(0, 0); + video_width_ = 0; + video_height_ = 0; volume_ = 1.0f; preload_ = AUTO; playback_rate_ = 0.0f; @@ -533,13 +536,13 @@ void PipelineImpl::SetBufferedBytes(int64 buffered_bytes) { buffered_bytes_ = buffered_bytes; } -void PipelineImpl::SetNaturalVideoSize(const gfx::Size& size) { +void PipelineImpl::SetVideoSize(size_t width, size_t height) { DCHECK(IsRunning()); - media_log_->AddEvent(media_log_->CreateVideoSizeSetEvent( - size.width(), size.height())); + media_log_->AddEvent(media_log_->CreateVideoSizeSetEvent(width, height)); base::AutoLock auto_lock(lock_); - natural_size_ = size; + video_width_ = width; + video_height_ = height; } void PipelineImpl::SetStreaming(bool streaming) { diff --git a/media/base/pipeline_impl.h b/media/base/pipeline_impl.h index d792347..bb88272 100644 --- a/media/base/pipeline_impl.h +++ b/media/base/pipeline_impl.h @@ -25,7 +25,6 @@ #include "media/base/demuxer.h" #include "media/base/filter_host.h" #include "media/base/pipeline.h" -#include "ui/gfx/size.h" namespace media { @@ -102,32 +101,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) OVERRIDE; + const PipelineStatusCB& network_callback); virtual bool Start(FilterCollection* filter_collection, const std::string& uri, - const PipelineStatusCB& start_callback) OVERRIDE; - virtual void Stop(const PipelineStatusCB& stop_callback) OVERRIDE; + const PipelineStatusCB& start_callback); + virtual void Stop(const PipelineStatusCB& stop_callback); virtual void Seek(base::TimeDelta time, - 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; + 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; void SetClockForTesting(Clock* clock); @@ -191,22 +190,22 @@ class MEDIA_EXPORT PipelineImpl : public Pipeline, public FilterHost { State FindNextState(State current); // FilterHost implementation. - 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; + 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(); // Callback executed by filters upon completing initialization. void OnFilterInitialize(); @@ -372,8 +371,9 @@ class MEDIA_EXPORT PipelineImpl : public Pipeline, public FilterHost { // Total size of the media. Set by filters. int64 total_bytes_; - // Video's natural width and height. Set by filters. - gfx::Size natural_size_; + // Video width and height. Set by filters. + size_t video_width_; + size_t video_height_; // 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 ccb43d0..66b430a 100644 --- a/media/base/pipeline_impl_unittest.cc +++ b/media/base/pipeline_impl_unittest.cc @@ -308,10 +308,11 @@ TEST_F(PipelineImplTest, NotStarted) { EXPECT_EQ(0, pipeline_->GetTotalBytes()); // Should always get set to zero. - gfx::Size size(1, 1); - pipeline_->GetNaturalVideoSize(&size); - EXPECT_EQ(0, size.width()); - EXPECT_EQ(0, size.height()); + size_t width = 1u; + size_t height = 1u; + pipeline_->GetVideoSize(&width, &height); + EXPECT_EQ(0u, width); + EXPECT_EQ(0u, height); } TEST_F(PipelineImplTest, NeverInitializes) { diff --git a/media/base/video_decoder_config.cc b/media/base/video_decoder_config.cc index 52104cb..0d3ae76 100644 --- a/media/base/video_decoder_config.cc +++ b/media/base/video_decoder_config.cc @@ -9,17 +9,19 @@ namespace media { VideoDecoderConfig::VideoDecoderConfig(VideoCodec codec, - const gfx::Size& coded_size, - const gfx::Rect& visible_rect, - const gfx::Size& natural_size, + int width, + int height, + int surface_width, + int surface_height, int frame_rate_numerator, int frame_rate_denominator, const uint8* extra_data, size_t extra_data_size) : codec_(codec), - coded_size_(coded_size), - visible_rect_(visible_rect), - natural_size_(natural_size), + width_(width), + height_(height), + surface_width_(surface_width), + surface_height_(surface_height), frame_rate_numerator_(frame_rate_numerator), frame_rate_denominator_(frame_rate_denominator), extra_data_size_(extra_data_size) { @@ -36,16 +38,20 @@ VideoCodec VideoDecoderConfig::codec() const { return codec_; } -gfx::Size VideoDecoderConfig::coded_size() const { - return coded_size_; +int VideoDecoderConfig::width() const { + return width_; } -gfx::Rect VideoDecoderConfig::visible_rect() const { - return visible_rect_; +int VideoDecoderConfig::height() const { + return height_; } -gfx::Size VideoDecoderConfig::natural_size() const { - return natural_size_; +int VideoDecoderConfig::surface_width() const { + return surface_width_; +} + +int VideoDecoderConfig::surface_height() const { + return surface_height_; } int VideoDecoderConfig::frame_rate_numerator() const { diff --git a/media/base/video_decoder_config.h b/media/base/video_decoder_config.h index fcfd3e7..360451a 100644 --- a/media/base/video_decoder_config.h +++ b/media/base/video_decoder_config.h @@ -8,8 +8,6 @@ #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 { @@ -30,17 +28,17 @@ enum VideoCodec { class MEDIA_EXPORT VideoDecoderConfig { public: - VideoDecoderConfig(VideoCodec codec, const gfx::Size& coded_size, - const gfx::Rect& visible_rect, - const gfx::Size& natural_size, + VideoDecoderConfig(VideoCodec codec, int width, int height, + int surface_width, int surface_height, int frame_rate_numerator, int frame_rate_denominator, const uint8* extra_data, size_t extra_data_size); ~VideoDecoderConfig(); VideoCodec codec() const; - gfx::Size coded_size() const; - gfx::Rect visible_rect() const; - gfx::Size natural_size() const; + int width() const; + int height() const; + int surface_width() const; + int surface_height() const; int frame_rate_numerator() const; int frame_rate_denominator() const; uint8* extra_data() const; @@ -49,16 +47,13 @@ class MEDIA_EXPORT VideoDecoderConfig { private: VideoCodec codec_; - // Width and height of video frame immediately post-decode. Not all pixels - // in this region are valid. - gfx::Size coded_size_; + // Container's concept of width and height of this video. + int width_; + int 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_; + // Width and height of the display surface for this video. + int surface_width_; + int surface_height_; // Frame rate in seconds expressed as a fraction. // TODO(scherkus): fairly certain decoders don't require frame rates. diff --git a/media/ffmpeg/ffmpeg_common.cc b/media/ffmpeg/ffmpeg_common.cc index e0e40f3..65ab9bb 100644 --- a/media/ffmpeg/ffmpeg_common.cc +++ b/media/ffmpeg/ffmpeg_common.cc @@ -187,11 +187,11 @@ bool GetStreamByteCountOverRange(AVStream* stream, return true; } -int GetNaturalHeight(AVStream* stream) { +int GetSurfaceHeight(AVStream* stream) { return stream->codec->height; } -int GetNaturalWidth(AVStream* stream) { +int GetSurfaceWidth(AVStream* stream) { double aspect_ratio; if (stream->sample_aspect_ratio.num) diff --git a/media/ffmpeg/ffmpeg_common.h b/media/ffmpeg/ffmpeg_common.h index 6f04e07..dec47df 100644 --- a/media/ffmpeg/ffmpeg_common.h +++ b/media/ffmpeg/ffmpeg_common.h @@ -105,10 +105,10 @@ MEDIA_EXPORT bool GetStreamByteCountOverRange(AVStream* stream, base::TimeDelta* range_start, base::TimeDelta* range_end); -// Calculates the natural width and height of the video using the video's +// Calculates the width and height of the video surface using the video's // encoded dimensions and sample_aspect_ratio. -int GetNaturalHeight(AVStream* stream); -int GetNaturalWidth(AVStream* stream); +int GetSurfaceHeight(AVStream* stream); +int GetSurfaceWidth(AVStream* stream); // Closes & destroys all AVStreams in the context and then closes & // destroys the AVFormatContext. diff --git a/media/filters/ffmpeg_video_decoder.cc b/media/filters/ffmpeg_video_decoder.cc index 9bc9bea..4920a17 100644 --- a/media/filters/ffmpeg_video_decoder.cc +++ b/media/filters/ffmpeg_video_decoder.cc @@ -17,7 +17,6 @@ #include "media/ffmpeg/ffmpeg_common.h" #include "media/video/ffmpeg_video_decode_engine.h" #include "media/video/video_decode_context.h" -#include "ui/gfx/rect.h" namespace media { @@ -70,25 +69,23 @@ void FFmpegVideoDecoder::Initialize(DemuxerStream* demuxer_stream, pts_stream_.Initialize(GetFrameDuration(av_stream)); - gfx::Size coded_size( - av_stream->codec->coded_width, av_stream->codec->coded_height); - // TODO(vrk): This assumes decoded frame data starts at (0, 0), which is true - // for now, but may not always be true forever. Fix this in the future. - gfx::Rect visible_rect( - av_stream->codec->width, av_stream->codec->height); - gfx::Size natural_size( - GetNaturalWidth(av_stream), GetNaturalHeight(av_stream)); - - if (natural_size.width() > Limits::kMaxDimension || - natural_size.height() > Limits::kMaxDimension || - natural_size.GetArea() > Limits::kMaxCanvas) { + int width = av_stream->codec->coded_width; + int height = av_stream->codec->coded_height; + + int surface_width = GetSurfaceWidth(av_stream); + int surface_height = GetSurfaceHeight(av_stream); + + if (surface_width > Limits::kMaxDimension || + surface_height > Limits::kMaxDimension || + (surface_width * surface_height) > Limits::kMaxCanvas) { VideoCodecInfo info = {0}; OnInitializeComplete(info); return; } VideoDecoderConfig config(CodecIDToVideoCodec(av_stream->codec->codec_id), - coded_size, visible_rect, natural_size, + width, height, + surface_width, surface_height, av_stream->r_frame_rate.num, av_stream->r_frame_rate.den, av_stream->codec->extradata, @@ -342,9 +339,14 @@ void FFmpegVideoDecoder::ProduceVideoSample( this)); } -gfx::Size FFmpegVideoDecoder::natural_size() { +int FFmpegVideoDecoder::width() { + DCHECK(info_.success); + return info_.surface_width; +} + +int FFmpegVideoDecoder::height() { DCHECK(info_.success); - return info_.natural_size; + return info_.surface_height; } void FFmpegVideoDecoder::FlushBuffers() { diff --git a/media/filters/ffmpeg_video_decoder.h b/media/filters/ffmpeg_video_decoder.h index 1be28fe..7458ff7 100644 --- a/media/filters/ffmpeg_video_decoder.h +++ b/media/filters/ffmpeg_video_decoder.h @@ -39,7 +39,8 @@ class MEDIA_EXPORT FFmpegVideoDecoder StatisticsCallback* stats_callback) OVERRIDE; virtual void ProduceVideoFrame( scoped_refptr<VideoFrame> video_frame) OVERRIDE; - virtual gfx::Size natural_size() OVERRIDE; + virtual int width() OVERRIDE; + virtual int height() OVERRIDE; private: // VideoDecodeEngine::EventHandler interface. diff --git a/media/filters/ffmpeg_video_decoder_unittest.cc b/media/filters/ffmpeg_video_decoder_unittest.cc index 3b5a3e6..9501518 100644 --- a/media/filters/ffmpeg_video_decoder_unittest.cc +++ b/media/filters/ffmpeg_video_decoder_unittest.cc @@ -33,9 +33,8 @@ using ::testing::Invoke; namespace media { -static const gfx::Size kCodedSize(1280, 720); -static const gfx::Rect kVisibleRect(1280, 720); -static const gfx::Size kNaturalSize(1280, 720); +static const int kWidth = 1280; +static const int kHeight = 720; // Holds timestamp and duration data needed for properly enqueuing a frame. struct TimeTuple { @@ -98,7 +97,8 @@ class DecoderPrivateMock : public FFmpegVideoDecoder { ACTION_P2(EngineInitialize, engine, success) { engine->event_handler_ = arg1; engine->info_.success = success; - engine->info_.natural_size = kNaturalSize; + engine->info_.surface_width = kWidth; + engine->info_.surface_height = kHeight; engine->event_handler_->OnInitializeComplete(engine->info_); } @@ -143,13 +143,11 @@ class FFmpegVideoDecoderTest : public testing::Test { memset(&codec_, 0, sizeof(codec_)); memset(&yuv_frame_, 0, sizeof(yuv_frame_)); base::TimeDelta zero; - video_frame_ = VideoFrame::CreateFrame(VideoFrame::YV12, - kVisibleRect.width(), - kVisibleRect.height(), + video_frame_ = VideoFrame::CreateFrame(VideoFrame::YV12, kWidth, kHeight, zero, zero); stream_.codec = &codec_context_; - codec_context_.width = kVisibleRect.width(); - codec_context_.height = kVisibleRect.height(); + codec_context_.width = kWidth; + codec_context_.height = kHeight; codec_context_.codec_id = CODEC_ID_H264; stream_.r_frame_rate.num = 1; stream_.r_frame_rate.den = 1; @@ -245,7 +243,8 @@ TEST_F(FFmpegVideoDecoderTest, Initialize_Successful) { // Test that the uncompressed video surface matches the dimensions // specified by FFmpeg. - EXPECT_EQ(kNaturalSize, decoder_->natural_size()); + EXPECT_EQ(kWidth, decoder_->width()); + EXPECT_EQ(kHeight, decoder_->height()); } TEST_F(FFmpegVideoDecoderTest, OnError) { diff --git a/media/filters/video_renderer_base.cc b/media/filters/video_renderer_base.cc index c7d37811..b40ec67 100644 --- a/media/filters/video_renderer_base.cc +++ b/media/filters/video_renderer_base.cc @@ -148,7 +148,7 @@ void VideoRendererBase::Initialize(VideoDecoder* decoder, base::Unretained(this))); // Notify the pipeline of the video dimensions. - host()->SetNaturalVideoSize(decoder_->natural_size()); + host()->SetVideoSize(decoder_->width(), decoder_->height()); // Initialize the subclass. // TODO(scherkus): do we trust subclasses not to do something silly while diff --git a/media/filters/video_renderer_base_unittest.cc b/media/filters/video_renderer_base_unittest.cc index b43c805..ccef901 100644 --- a/media/filters/video_renderer_base_unittest.cc +++ b/media/filters/video_renderer_base_unittest.cc @@ -58,7 +58,8 @@ class VideoRendererBaseTest : public ::testing::Test { EXPECT_CALL(*decoder_, ProduceVideoFrame(_)) .WillRepeatedly(Invoke(this, &VideoRendererBaseTest::EnqueueCallback)); - EXPECT_CALL(*decoder_, natural_size()).WillRepeatedly(Return(kNaturalSize)); + EXPECT_CALL(*decoder_, width()).WillRepeatedly(Return(kWidth)); + EXPECT_CALL(*decoder_, height()).WillRepeatedly(Return(kHeight)); EXPECT_CALL(stats_callback_object_, OnStatistics(_)) .Times(AnyNumber()); @@ -91,7 +92,7 @@ class VideoRendererBaseTest : public ::testing::Test { InSequence s; // We expect the video size to be set. - EXPECT_CALL(host_, SetNaturalVideoSize(kNaturalSize)); + EXPECT_CALL(host_, SetVideoSize(kWidth, kHeight)); // Then our subclass will be asked to initialize. EXPECT_CALL(*renderer_, OnInitialize(_)) @@ -147,8 +148,7 @@ class VideoRendererBaseTest : public ::testing::Test { void CreateFrame(int64 timestamp, int64 duration) { const base::TimeDelta kZero; scoped_refptr<VideoFrame> frame = - VideoFrame::CreateFrame(VideoFrame::RGB32, kNaturalSize.width(), - kNaturalSize.height(), + VideoFrame::CreateFrame(VideoFrame::RGB32, kWidth, kHeight, base::TimeDelta::FromMicroseconds(timestamp), base::TimeDelta::FromMicroseconds(duration)); decoder_->VideoFrameReadyForTest(frame); @@ -162,7 +162,8 @@ class VideoRendererBaseTest : public ::testing::Test { } protected: - static const gfx::Size kNaturalSize; + static const size_t kWidth; + static const size_t kHeight; static const int64 kDuration; StatisticsCallback* NewStatisticsCallback() { @@ -195,7 +196,8 @@ class VideoRendererBaseTest : public ::testing::Test { DISALLOW_COPY_AND_ASSIGN(VideoRendererBaseTest); }; -const gfx::Size VideoRendererBaseTest::kNaturalSize(16u, 16u); +const size_t VideoRendererBaseTest::kWidth = 16u; +const size_t VideoRendererBaseTest::kHeight = 16u; const int64 VideoRendererBaseTest::kDuration = 10; // Test initialization where the subclass failed for some reason. @@ -203,7 +205,7 @@ TEST_F(VideoRendererBaseTest, Initialize_Failed) { InSequence s; // We expect the video size to be set. - EXPECT_CALL(host_, SetNaturalVideoSize(kNaturalSize)); + EXPECT_CALL(host_, SetVideoSize(kWidth, kHeight)); // Our subclass will fail when asked to initialize. EXPECT_CALL(*renderer_, OnInitialize(_)) diff --git a/media/tools/player_wtl/wtl_renderer.cc b/media/tools/player_wtl/wtl_renderer.cc index c5d9fd3..baec88e 100644 --- a/media/tools/player_wtl/wtl_renderer.cc +++ b/media/tools/player_wtl/wtl_renderer.cc @@ -13,8 +13,7 @@ WtlVideoRenderer::WtlVideoRenderer(WtlVideoWindow* window) WtlVideoRenderer::~WtlVideoRenderer() {} bool WtlVideoRenderer::OnInitialize(media::VideoDecoder* decoder) { - window_->SetSize( - decoder->natural_size().width(), decoder->natural_size().height()); + window_->SetSize(decoder->width(), decoder->height()); return true; } diff --git a/media/tools/player_x11/gl_video_renderer.cc b/media/tools/player_x11/gl_video_renderer.cc index 6c6cda4..b58b4df 100644 --- a/media/tools/player_x11/gl_video_renderer.cc +++ b/media/tools/player_x11/gl_video_renderer.cc @@ -128,8 +128,7 @@ bool GlVideoRenderer::OnInitialize(media::VideoDecoder* decoder) { LOG(INFO) << "Initializing GL Renderer..."; // Resize the window to fit that of the video. - XResizeWindow(display_, window_, decoder->natural_size().width(), - decoder->natural_size().height()); + XResizeWindow(display_, window_, decoder->width(), decoder->height()); gl_context_ = InitGLContext(display_, window_); if (!gl_context_) diff --git a/media/tools/player_x11/x11_video_renderer.cc b/media/tools/player_x11/x11_video_renderer.cc index a06f6b8..055e54b 100644 --- a/media/tools/player_x11/x11_video_renderer.cc +++ b/media/tools/player_x11/x11_video_renderer.cc @@ -94,8 +94,8 @@ bool X11VideoRenderer::OnInitialize(media::VideoDecoder* decoder) { LOG(INFO) << "Initializing X11 Renderer..."; // Resize the window to fit that of the video. - int width = decoder->natural_size().width(); - int height = decoder->natural_size().height(); + int width = decoder->width(); + int height = decoder->height(); XResizeWindow(display_, window_, width, height); // Allocate an XImage for caching RGB result. diff --git a/media/video/ffmpeg_video_decode_engine.cc b/media/video/ffmpeg_video_decode_engine.cc index 65edc2f..ced1b60 100644 --- a/media/video/ffmpeg_video_decode_engine.cc +++ b/media/video/ffmpeg_video_decode_engine.cc @@ -61,8 +61,8 @@ void FFmpegVideoDecodeEngine::Initialize( codec_context_->pix_fmt = PIX_FMT_YUV420P; codec_context_->codec_type = AVMEDIA_TYPE_VIDEO; codec_context_->codec_id = VideoCodecToCodecID(config.codec()); - codec_context_->coded_width = config.coded_size().width(); - codec_context_->coded_height = config.coded_size().height(); + codec_context_->coded_width = config.width(); + codec_context_->coded_height = config.height(); frame_rate_numerator_ = config.frame_rate_numerator(); frame_rate_denominator_ = config.frame_rate_denominator(); @@ -104,7 +104,8 @@ void FFmpegVideoDecodeEngine::Initialize( av_frame_.reset(avcodec_alloc_frame()); VideoCodecInfo info; info.success = false; - info.natural_size = config.natural_size(); + info.surface_width = config.surface_width(); + info.surface_height = config.surface_height(); // If we do not have enough buffers, we will report error too. frame_queue_available_.clear(); @@ -113,8 +114,8 @@ void FFmpegVideoDecodeEngine::Initialize( for (size_t i = 0; i < Limits::kMaxVideoFrames; ++i) { scoped_refptr<VideoFrame> video_frame = VideoFrame::CreateFrame(VideoFrame::YV12, - config.visible_rect().width(), - config.visible_rect().height(), + config.surface_width(), + config.surface_height(), kNoTimestamp, kNoTimestamp); frame_queue_available_.push_back(video_frame); diff --git a/media/video/ffmpeg_video_decode_engine_unittest.cc b/media/video/ffmpeg_video_decode_engine_unittest.cc index e8238ff..0368e63 100644 --- a/media/video/ffmpeg_video_decode_engine_unittest.cc +++ b/media/video/ffmpeg_video_decode_engine_unittest.cc @@ -23,9 +23,10 @@ using ::testing::StrictMock; namespace media { -static const gfx::Size kCodedSize(320, 240); -static const gfx::Rect kVisibleRect(320, 240); -static const gfx::Size kNaturalSize(522, 288); +static const size_t kWidth = 320; +static const size_t kHeight = 240; +static const size_t kSurfaceWidth = 522; +static const size_t kSurfaceHeight = 288; static const AVRational kFrameRate = { 100, 1 }; ACTION_P2(DemuxComplete, engine, buffer) { @@ -37,12 +38,12 @@ class FFmpegVideoDecodeEngineTest public VideoDecodeEngine::EventHandler { public: FFmpegVideoDecodeEngineTest() - : config_(kCodecVP8, kCodedSize, kVisibleRect, kNaturalSize, + : config_(kCodecVP8, kWidth, kHeight, kSurfaceWidth, kSurfaceHeight, kFrameRate.num, kFrameRate.den, NULL, 0) { CHECK(FFmpegGlue::GetInstance()); // Setup FFmpeg structures. - frame_buffer_.reset(new uint8[kCodedSize.GetArea()]); + frame_buffer_.reset(new uint8[kWidth * kHeight]); test_engine_.reset(new FFmpegVideoDecodeEngine()); @@ -104,13 +105,10 @@ class FFmpegVideoDecodeEngineTest CallProduceVideoFrame(); CallProduceVideoFrame(); - size_t expected_width = static_cast<size_t>(kVisibleRect.width()); - size_t expected_height = static_cast<size_t>(kVisibleRect.height()); - - EXPECT_EQ(expected_width, video_frame_a->width()); - EXPECT_EQ(expected_height, video_frame_a->height()); - EXPECT_EQ(expected_width, video_frame_b->width()); - EXPECT_EQ(expected_height, video_frame_b->height()); + EXPECT_EQ(kSurfaceWidth, video_frame_a->width()); + EXPECT_EQ(kSurfaceHeight, video_frame_a->height()); + EXPECT_EQ(kSurfaceWidth, video_frame_b->width()); + EXPECT_EQ(kSurfaceHeight, video_frame_b->height()); } // VideoDecodeEngine::EventHandler implementation. @@ -127,9 +125,11 @@ class FFmpegVideoDecodeEngineTest MOCK_METHOD0(OnError, void()); void CallProduceVideoFrame() { - test_engine_->ProduceVideoFrame(VideoFrame::CreateFrame( - VideoFrame::YV12, kVisibleRect.width(), kVisibleRect.height(), - kNoTimestamp, kNoTimestamp)); + test_engine_->ProduceVideoFrame(VideoFrame::CreateFrame(VideoFrame::YV12, + kWidth, + kHeight, + kNoTimestamp, + kNoTimestamp)); } protected: @@ -149,8 +149,9 @@ TEST_F(FFmpegVideoDecodeEngineTest, Initialize_Normal) { } TEST_F(FFmpegVideoDecodeEngineTest, Initialize_FindDecoderFails) { - VideoDecoderConfig config(kUnknown, kCodedSize, kVisibleRect, kNaturalSize, - kFrameRate.num, kFrameRate.den, NULL, 0); + VideoDecoderConfig config(kUnknown, kWidth, kHeight, kSurfaceWidth, + kSurfaceHeight, kFrameRate.num, kFrameRate.den, + NULL, 0); // Test avcodec_find_decoder() returning NULL. VideoCodecInfo info; EXPECT_CALL(*this, OnInitializeComplete(_)) @@ -161,8 +162,8 @@ TEST_F(FFmpegVideoDecodeEngineTest, Initialize_FindDecoderFails) { TEST_F(FFmpegVideoDecodeEngineTest, Initialize_OpenDecoderFails) { // Specify Theora w/o extra data so that avcodec_open() fails. - VideoDecoderConfig config(kCodecTheora, kCodedSize, kVisibleRect, - kNaturalSize, kFrameRate.num, kFrameRate.den, + VideoDecoderConfig config(kCodecTheora, kWidth, kHeight, kSurfaceWidth, + kSurfaceHeight, kFrameRate.num, kFrameRate.den, NULL, 0); VideoCodecInfo info; EXPECT_CALL(*this, OnInitializeComplete(_)) diff --git a/media/video/video_decode_engine.h b/media/video/video_decode_engine.h index 4ec7cf5..6171232 100644 --- a/media/video/video_decode_engine.h +++ b/media/video/video_decode_engine.h @@ -10,7 +10,6 @@ #include "media/base/media_export.h" #include "media/base/video_decoder_config.h" #include "media/base/video_frame.h" -#include "ui/gfx/size.h" class MessageLoop; @@ -25,8 +24,11 @@ struct VideoCodecInfo { // Other parameter is only meaningful when this is true. bool success; - // Natural dimensions of video. May be different from coded and visible sizes. - gfx::Size natural_size; + // Can be different with container's value. + uint32 surface_width; + + // Can be different with container's value. + uint32 surface_height; }; class MEDIA_EXPORT VideoDecodeEngine { |