summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--content/renderer/media/capture_video_decoder.cc14
-rw-r--r--content/renderer/media/capture_video_decoder.h3
-rw-r--r--content/renderer/media/rtc_video_decoder.cc43
-rw-r--r--content/renderer/media/rtc_video_decoder.h6
-rw-r--r--content/renderer/media/rtc_video_decoder_unittest.cc11
-rw-r--r--media/base/composite_filter.cc38
-rw-r--r--media/base/composite_filter.h19
-rw-r--r--media/base/filter_host.h4
-rw-r--r--media/base/filters.h6
-rw-r--r--media/base/mock_filter_host.h2
-rw-r--r--media/base/mock_filters.h3
-rw-r--r--media/base/pipeline.h7
-rw-r--r--media/base/pipeline_impl.cc19
-rw-r--r--media/base/pipeline_impl.h84
-rw-r--r--media/base/pipeline_impl_unittest.cc10
-rw-r--r--media/base/video_decoder_config.cc30
-rw-r--r--media/base/video_decoder_config.h29
-rw-r--r--media/ffmpeg/ffmpeg_common.cc4
-rw-r--r--media/ffmpeg/ffmpeg_common.h6
-rw-r--r--media/filters/ffmpeg_video_decoder.cc34
-rw-r--r--media/filters/ffmpeg_video_decoder.h3
-rw-r--r--media/filters/ffmpeg_video_decoder_unittest.cc19
-rw-r--r--media/filters/video_renderer_base.cc2
-rw-r--r--media/filters/video_renderer_base_unittest.cc16
-rw-r--r--media/media.gyp2
-rw-r--r--media/tools/player_wtl/wtl_renderer.cc3
-rw-r--r--media/tools/player_x11/gl_video_renderer.cc3
-rw-r--r--media/tools/player_x11/x11_video_renderer.cc4
-rw-r--r--media/video/ffmpeg_video_decode_engine.cc11
-rw-r--r--media/video/ffmpeg_video_decode_engine_unittest.cc39
-rw-r--r--media/video/video_decode_engine.h8
-rw-r--r--webkit/glue/media/video_renderer_impl.cc12
-rw-r--r--webkit/glue/media/video_renderer_impl.h4
-rw-r--r--webkit/glue/webmediaplayer_impl.cc6
34 files changed, 250 insertions, 254 deletions
diff --git a/content/renderer/media/capture_video_decoder.cc b/content/renderer/media/capture_video_decoder.cc
index 0ceb1ac..74652f3 100644
--- a/content/renderer/media/capture_video_decoder.cc
+++ b/content/renderer/media/capture_video_decoder.cc
@@ -50,12 +50,8 @@ void CaptureVideoDecoder::ProduceVideoFrame(
&CaptureVideoDecoder::ProduceVideoFrameOnDecoderThread, video_frame));
}
-int CaptureVideoDecoder::width() {
- return capability_.width;
-}
-
-int CaptureVideoDecoder::height() {
- return capability_.height;
+gfx::Size CaptureVideoDecoder::natural_size() {
+ return gfx::Size(capability_.width, capability_.height);
}
void CaptureVideoDecoder::Play(media::FilterCallback* callback) {
@@ -223,7 +219,8 @@ void CaptureVideoDecoder::OnBufferReadyOnDecoderThread(
if (buf->width != capability_.width || buf->height != capability_.height) {
capability_.width = buf->width;
capability_.height = buf->height;
- host()->SetVideoSize(capability_.width, capability_.height);
+ host()->SetNaturalVideoSize(
+ gfx::Size(capability_.width, capability_.height));
}
// Check if there's a size change.
@@ -242,6 +239,9 @@ void CaptureVideoDecoder::OnBufferReadyOnDecoderThread(
uint8* buffer = buf->memory_pointer;
+ // Assume YV12 format.
+ // TODO(vrk): This DCHECK fails in content_unittests ... it should not!
+ // DCHECK(capability_.raw_type == media::VideoFrame::YV12);
int y_width = capability_.width;
int y_height = capability_.height;
int uv_width = capability_.width / 2;
diff --git a/content/renderer/media/capture_video_decoder.h b/content/renderer/media/capture_video_decoder.h
index 0f8b585..ef2ffad 100644
--- a/content/renderer/media/capture_video_decoder.h
+++ b/content/renderer/media/capture_video_decoder.h
@@ -44,8 +44,7 @@ class CaptureVideoDecoder
media::StatisticsCallback* stat_callback) OVERRIDE;
virtual void ProduceVideoFrame(
scoped_refptr<media::VideoFrame> video_frame) OVERRIDE;
- virtual int width() OVERRIDE;
- virtual int height() OVERRIDE;
+ virtual gfx::Size natural_size() OVERRIDE;
// VideoCapture::EventHandler implementation.
virtual void OnStarted(media::VideoCapture* capture) OVERRIDE;
diff --git a/content/renderer/media/rtc_video_decoder.cc b/content/renderer/media/rtc_video_decoder.cc
index 56ec6d1..4722f96 100644
--- a/content/renderer/media/rtc_video_decoder.cc
+++ b/content/renderer/media/rtc_video_decoder.cc
@@ -33,8 +33,7 @@ using media::VideoFrame;
RTCVideoDecoder::RTCVideoDecoder(MessageLoop* message_loop,
const std::string& url)
: message_loop_(message_loop),
- width_(176),
- height_(144),
+ visible_size_(176, 144),
url_(url),
state_(kUnInitialized) {
}
@@ -127,9 +126,10 @@ void RTCVideoDecoder::Seek(base::TimeDelta time, const FilterStatusCB& cb) {
state_ = kSeeking;
// Create output buffer pool and pass the frames to renderer
- // so that the renderer can complete the seeking
+ // so that the renderer can complete the seeking.
for (size_t i = 0; i < Limits::kMaxVideoFrames; ++i) {
- VideoFrameReady(VideoFrame::CreateBlackFrame(width_, height_));
+ VideoFrameReady(VideoFrame::CreateBlackFrame(
+ visible_size_.width(), visible_size_.height()));
}
state_ = kNormal;
@@ -151,19 +151,16 @@ void RTCVideoDecoder::ProduceVideoFrame(
frame_queue_available_.push_back(video_frame);
}
-int RTCVideoDecoder::width() {
- return width_;
-}
-
-int RTCVideoDecoder::height() {
- return height_;
+gfx::Size RTCVideoDecoder::natural_size() {
+ // TODO(vrk): Return natural size when aspect ratio support is implemented.
+ return visible_size_;
}
bool RTCVideoDecoder::SetSize(int width, int height, int reserved) {
- width_ = width;
- height_ = height;
+ visible_size_.SetSize(width, height);
- host()->SetVideoSize(width_, height_);
+ // TODO(vrk): Provide natural size when aspect ratio support is implemented.
+ host()->SetNaturalVideoSize(visible_size_);
return true;
}
@@ -173,7 +170,7 @@ bool RTCVideoDecoder::RenderFrame(const cricket::VideoFrame* frame) {
if (state_ != kNormal)
return true;
- // This is called from another thread
+ // This is called from another thread.
scoped_refptr<VideoFrame> video_frame;
{
base::AutoLock auto_lock(lock_);
@@ -184,16 +181,24 @@ bool RTCVideoDecoder::RenderFrame(const cricket::VideoFrame* frame) {
frame_queue_available_.pop_front();
}
- // Check if there's a size change
- if (video_frame->width() != width_ || video_frame->height() != height_) {
- // Allocate new buffer based on the new size
+ // Check if there's a size change.
+ // TODO(vrk): Remove casts when media::VideoFrame is updated with gfx::Sizes
+ // for width/height.
+ if (video_frame->width() != static_cast<size_t>(visible_size_.width()) ||
+ video_frame->height() != static_cast<size_t>(visible_size_.height())) {
+ // Allocate new buffer based on the new size.
video_frame = VideoFrame::CreateFrame(VideoFrame::YV12,
- width_,
- height_,
+ visible_size_.width(),
+ visible_size_.height(),
kNoTimestamp,
kNoTimestamp);
}
+ // Only YV12 frames are supported.
+ DCHECK(video_frame->format() == VideoFrame::YV12);
+ // Aspect ratio unsupported; DCHECK when there are non-square pixels.
+ DCHECK(frame->GetPixelWidth() == 1);
+ DCHECK(frame->GetPixelHeight() == 1);
video_frame->SetTimestamp(host()->GetTime());
video_frame->SetDuration(base::TimeDelta::FromMilliseconds(30));
diff --git a/content/renderer/media/rtc_video_decoder.h b/content/renderer/media/rtc_video_decoder.h
index 82b78fc..d3b4196 100644
--- a/content/renderer/media/rtc_video_decoder.h
+++ b/content/renderer/media/rtc_video_decoder.h
@@ -42,8 +42,7 @@ class RTCVideoDecoder
media::StatisticsCallback* stat_callback) OVERRIDE;
virtual void ProduceVideoFrame(
scoped_refptr<media::VideoFrame> video_frame) OVERRIDE;
- virtual int width() OVERRIDE;
- virtual int height() OVERRIDE;
+ virtual gfx::Size natural_size() OVERRIDE;
// cricket::VideoRenderer implementation
virtual bool SetSize(int width, int height, int reserved) OVERRIDE;
@@ -65,8 +64,7 @@ class RTCVideoDecoder
};
MessageLoop* message_loop_;
- size_t width_;
- size_t height_;
+ gfx::Size visible_size_;
std::string url_;
DecoderState state_;
std::deque<scoped_refptr<media::VideoFrame> > frame_queue_available_;
diff --git a/content/renderer/media/rtc_video_decoder_unittest.cc b/content/renderer/media/rtc_video_decoder_unittest.cc
index 14a3b22..ce434fd 100644
--- a/content/renderer/media/rtc_video_decoder_unittest.cc
+++ b/content/renderer/media/rtc_video_decoder_unittest.cc
@@ -161,8 +161,8 @@ TEST_F(RTCVideoDecoderTest, Initialize_Successful) {
// Test that the output media format is an uncompressed video surface that
// matches the dimensions specified by RTC.
- EXPECT_EQ(kWidth, decoder_->width());
- EXPECT_EQ(kHeight, decoder_->height());
+ EXPECT_EQ(kWidth, decoder_->natural_size().width());
+ EXPECT_EQ(kHeight, decoder_->natural_size().height());
}
TEST_F(RTCVideoDecoderTest, DoSeek) {
@@ -216,15 +216,16 @@ TEST_F(RTCVideoDecoderTest, DoSetSize) {
int new_width = kWidth * 2;
int new_height = kHeight * 2;
+ gfx::Size new_natural_size(new_width, new_height);
int new_reserved = 0;
EXPECT_CALL(host_,
- SetVideoSize(new_width, new_height)).WillRepeatedly(Return());
+ SetNaturalVideoSize(new_natural_size)).WillRepeatedly(Return());
decoder_->SetSize(new_width, new_height, new_reserved);
- EXPECT_EQ(new_width, decoder_->width());
- EXPECT_EQ(new_height, decoder_->height());
+ EXPECT_EQ(new_width, decoder_->natural_size().width());
+ EXPECT_EQ(new_height, decoder_->natural_size().height());
message_loop_.RunAllPending();
}
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.
diff --git a/media/ffmpeg/ffmpeg_common.cc b/media/ffmpeg/ffmpeg_common.cc
index 65ab9bb..e0e40f3 100644
--- a/media/ffmpeg/ffmpeg_common.cc
+++ b/media/ffmpeg/ffmpeg_common.cc
@@ -187,11 +187,11 @@ bool GetStreamByteCountOverRange(AVStream* stream,
return true;
}
-int GetSurfaceHeight(AVStream* stream) {
+int GetNaturalHeight(AVStream* stream) {
return stream->codec->height;
}
-int GetSurfaceWidth(AVStream* stream) {
+int GetNaturalWidth(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 dec47df..6f04e07 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 width and height of the video surface using the video's
+// Calculates the natural width and height of the video using the video's
// encoded dimensions and sample_aspect_ratio.
-int GetSurfaceHeight(AVStream* stream);
-int GetSurfaceWidth(AVStream* stream);
+int GetNaturalHeight(AVStream* stream);
+int GetNaturalWidth(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 70ef517..61a8771 100644
--- a/media/filters/ffmpeg_video_decoder.cc
+++ b/media/filters/ffmpeg_video_decoder.cc
@@ -18,6 +18,7 @@
#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,23 +71,25 @@ void FFmpegVideoDecoder::Initialize(DemuxerStream* demuxer_stream,
pts_stream_.Initialize(GetFrameDuration(av_stream));
- 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) {
+ 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) {
VideoCodecInfo info = {0};
OnInitializeComplete(info);
return;
}
VideoDecoderConfig config(CodecIDToVideoCodec(av_stream->codec->codec_id),
- width, height,
- surface_width, surface_height,
+ coded_size, visible_rect, natural_size,
av_stream->r_frame_rate.num,
av_stream->r_frame_rate.den,
av_stream->codec->extradata,
@@ -340,14 +343,9 @@ void FFmpegVideoDecoder::ProduceVideoSample(
this));
}
-int FFmpegVideoDecoder::width() {
- DCHECK(info_.success);
- return info_.surface_width;
-}
-
-int FFmpegVideoDecoder::height() {
+gfx::Size FFmpegVideoDecoder::natural_size() {
DCHECK(info_.success);
- return info_.surface_height;
+ return info_.natural_size;
}
void FFmpegVideoDecoder::FlushBuffers() {
diff --git a/media/filters/ffmpeg_video_decoder.h b/media/filters/ffmpeg_video_decoder.h
index edca948..a09ab5d 100644
--- a/media/filters/ffmpeg_video_decoder.h
+++ b/media/filters/ffmpeg_video_decoder.h
@@ -38,8 +38,7 @@ class MEDIA_EXPORT FFmpegVideoDecoder
StatisticsCallback* stats_callback) OVERRIDE;
virtual void ProduceVideoFrame(
scoped_refptr<VideoFrame> video_frame) OVERRIDE;
- virtual int width() OVERRIDE;
- virtual int height() OVERRIDE;
+ virtual gfx::Size natural_size() OVERRIDE;
private:
// VideoDecodeEngine::EventHandler interface.
diff --git a/media/filters/ffmpeg_video_decoder_unittest.cc b/media/filters/ffmpeg_video_decoder_unittest.cc
index 460dcb4..e5b9eeb 100644
--- a/media/filters/ffmpeg_video_decoder_unittest.cc
+++ b/media/filters/ffmpeg_video_decoder_unittest.cc
@@ -34,8 +34,9 @@ using ::testing::Invoke;
namespace media {
-static const int kWidth = 1280;
-static const int kHeight = 720;
+static const gfx::Size kCodedSize(1280, 720);
+static const gfx::Rect kVisibleRect(1280, 720);
+static const gfx::Size kNaturalSize(1280, 720);
// Holds timestamp and duration data needed for properly enqueuing a frame.
struct TimeTuple {
@@ -98,8 +99,7 @@ class DecoderPrivateMock : public FFmpegVideoDecoder {
ACTION_P2(EngineInitialize, engine, success) {
engine->event_handler_ = arg1;
engine->info_.success = success;
- engine->info_.surface_width = kWidth;
- engine->info_.surface_height = kHeight;
+ engine->info_.natural_size = kNaturalSize;
engine->event_handler_->OnInitializeComplete(engine->info_);
}
@@ -144,11 +144,13 @@ 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, kWidth, kHeight,
+ video_frame_ = VideoFrame::CreateFrame(VideoFrame::YV12,
+ kVisibleRect.width(),
+ kVisibleRect.height(),
zero, zero);
stream_.codec = &codec_context_;
- codec_context_.width = kWidth;
- codec_context_.height = kHeight;
+ codec_context_.width = kVisibleRect.width();
+ codec_context_.height = kVisibleRect.height();
codec_context_.codec_id = CODEC_ID_H264;
stream_.r_frame_rate.num = 1;
stream_.r_frame_rate.den = 1;
@@ -244,8 +246,7 @@ TEST_F(FFmpegVideoDecoderTest, Initialize_Successful) {
// Test that the uncompressed video surface matches the dimensions
// specified by FFmpeg.
- EXPECT_EQ(kWidth, decoder_->width());
- EXPECT_EQ(kHeight, decoder_->height());
+ EXPECT_EQ(kNaturalSize, decoder_->natural_size());
}
TEST_F(FFmpegVideoDecoderTest, OnError) {
diff --git a/media/filters/video_renderer_base.cc b/media/filters/video_renderer_base.cc
index b40ec67..c7d37811 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()->SetVideoSize(decoder_->width(), decoder_->height());
+ host()->SetNaturalVideoSize(decoder_->natural_size());
// 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 ccef901..b43c805 100644
--- a/media/filters/video_renderer_base_unittest.cc
+++ b/media/filters/video_renderer_base_unittest.cc
@@ -58,8 +58,7 @@ class VideoRendererBaseTest : public ::testing::Test {
EXPECT_CALL(*decoder_, ProduceVideoFrame(_))
.WillRepeatedly(Invoke(this, &VideoRendererBaseTest::EnqueueCallback));
- EXPECT_CALL(*decoder_, width()).WillRepeatedly(Return(kWidth));
- EXPECT_CALL(*decoder_, height()).WillRepeatedly(Return(kHeight));
+ EXPECT_CALL(*decoder_, natural_size()).WillRepeatedly(Return(kNaturalSize));
EXPECT_CALL(stats_callback_object_, OnStatistics(_))
.Times(AnyNumber());
@@ -92,7 +91,7 @@ class VideoRendererBaseTest : public ::testing::Test {
InSequence s;
// We expect the video size to be set.
- EXPECT_CALL(host_, SetVideoSize(kWidth, kHeight));
+ EXPECT_CALL(host_, SetNaturalVideoSize(kNaturalSize));
// Then our subclass will be asked to initialize.
EXPECT_CALL(*renderer_, OnInitialize(_))
@@ -148,7 +147,8 @@ class VideoRendererBaseTest : public ::testing::Test {
void CreateFrame(int64 timestamp, int64 duration) {
const base::TimeDelta kZero;
scoped_refptr<VideoFrame> frame =
- VideoFrame::CreateFrame(VideoFrame::RGB32, kWidth, kHeight,
+ VideoFrame::CreateFrame(VideoFrame::RGB32, kNaturalSize.width(),
+ kNaturalSize.height(),
base::TimeDelta::FromMicroseconds(timestamp),
base::TimeDelta::FromMicroseconds(duration));
decoder_->VideoFrameReadyForTest(frame);
@@ -162,8 +162,7 @@ class VideoRendererBaseTest : public ::testing::Test {
}
protected:
- static const size_t kWidth;
- static const size_t kHeight;
+ static const gfx::Size kNaturalSize;
static const int64 kDuration;
StatisticsCallback* NewStatisticsCallback() {
@@ -196,8 +195,7 @@ class VideoRendererBaseTest : public ::testing::Test {
DISALLOW_COPY_AND_ASSIGN(VideoRendererBaseTest);
};
-const size_t VideoRendererBaseTest::kWidth = 16u;
-const size_t VideoRendererBaseTest::kHeight = 16u;
+const gfx::Size VideoRendererBaseTest::kNaturalSize(16u, 16u);
const int64 VideoRendererBaseTest::kDuration = 10;
// Test initialization where the subclass failed for some reason.
@@ -205,7 +203,7 @@ TEST_F(VideoRendererBaseTest, Initialize_Failed) {
InSequence s;
// We expect the video size to be set.
- EXPECT_CALL(host_, SetVideoSize(kWidth, kHeight));
+ EXPECT_CALL(host_, SetNaturalVideoSize(kNaturalSize));
// Our subclass will fail when asked to initialize.
EXPECT_CALL(*renderer_, OnInitialize(_))
diff --git a/media/media.gyp b/media/media.gyp
index a0d4dab..603f5a0 100644
--- a/media/media.gyp
+++ b/media/media.gyp
@@ -534,6 +534,7 @@
'../testing/gmock.gyp:gmock',
'../testing/gtest.gyp:gtest',
'../third_party/ffmpeg/ffmpeg.gyp:ffmpeg',
+ '../ui/ui.gyp:ui',
],
'sources': [
'audio/audio_input_controller_unittest.cc',
@@ -691,6 +692,7 @@
'yuv_convert',
'../base/base.gyp:base',
'../base/third_party/dynamic_annotations/dynamic_annotations.gyp:dynamic_annotations',
+ '../ui/ui.gyp:ui',
],
'include_dirs': [
'<(DEPTH)/third_party/wtl/include',
diff --git a/media/tools/player_wtl/wtl_renderer.cc b/media/tools/player_wtl/wtl_renderer.cc
index baec88e..c5d9fd3 100644
--- a/media/tools/player_wtl/wtl_renderer.cc
+++ b/media/tools/player_wtl/wtl_renderer.cc
@@ -13,7 +13,8 @@ WtlVideoRenderer::WtlVideoRenderer(WtlVideoWindow* window)
WtlVideoRenderer::~WtlVideoRenderer() {}
bool WtlVideoRenderer::OnInitialize(media::VideoDecoder* decoder) {
- window_->SetSize(decoder->width(), decoder->height());
+ window_->SetSize(
+ decoder->natural_size().width(), decoder->natural_size().height());
return true;
}
diff --git a/media/tools/player_x11/gl_video_renderer.cc b/media/tools/player_x11/gl_video_renderer.cc
index b58b4df..6c6cda4 100644
--- a/media/tools/player_x11/gl_video_renderer.cc
+++ b/media/tools/player_x11/gl_video_renderer.cc
@@ -128,7 +128,8 @@ bool GlVideoRenderer::OnInitialize(media::VideoDecoder* decoder) {
LOG(INFO) << "Initializing GL Renderer...";
// Resize the window to fit that of the video.
- XResizeWindow(display_, window_, decoder->width(), decoder->height());
+ XResizeWindow(display_, window_, decoder->natural_size().width(),
+ decoder->natural_size().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 055e54b..a06f6b8 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->width();
- int height = decoder->height();
+ int width = decoder->natural_size().width();
+ int height = decoder->natural_size().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 ced1b60..65edc2f 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.width();
- codec_context_->coded_height = config.height();
+ codec_context_->coded_width = config.coded_size().width();
+ codec_context_->coded_height = config.coded_size().height();
frame_rate_numerator_ = config.frame_rate_numerator();
frame_rate_denominator_ = config.frame_rate_denominator();
@@ -104,8 +104,7 @@ void FFmpegVideoDecodeEngine::Initialize(
av_frame_.reset(avcodec_alloc_frame());
VideoCodecInfo info;
info.success = false;
- info.surface_width = config.surface_width();
- info.surface_height = config.surface_height();
+ info.natural_size = config.natural_size();
// If we do not have enough buffers, we will report error too.
frame_queue_available_.clear();
@@ -114,8 +113,8 @@ void FFmpegVideoDecodeEngine::Initialize(
for (size_t i = 0; i < Limits::kMaxVideoFrames; ++i) {
scoped_refptr<VideoFrame> video_frame =
VideoFrame::CreateFrame(VideoFrame::YV12,
- config.surface_width(),
- config.surface_height(),
+ config.visible_rect().width(),
+ config.visible_rect().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 0368e63..e8238ff 100644
--- a/media/video/ffmpeg_video_decode_engine_unittest.cc
+++ b/media/video/ffmpeg_video_decode_engine_unittest.cc
@@ -23,10 +23,9 @@ using ::testing::StrictMock;
namespace media {
-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 gfx::Size kCodedSize(320, 240);
+static const gfx::Rect kVisibleRect(320, 240);
+static const gfx::Size kNaturalSize(522, 288);
static const AVRational kFrameRate = { 100, 1 };
ACTION_P2(DemuxComplete, engine, buffer) {
@@ -38,12 +37,12 @@ class FFmpegVideoDecodeEngineTest
public VideoDecodeEngine::EventHandler {
public:
FFmpegVideoDecodeEngineTest()
- : config_(kCodecVP8, kWidth, kHeight, kSurfaceWidth, kSurfaceHeight,
+ : config_(kCodecVP8, kCodedSize, kVisibleRect, kNaturalSize,
kFrameRate.num, kFrameRate.den, NULL, 0) {
CHECK(FFmpegGlue::GetInstance());
// Setup FFmpeg structures.
- frame_buffer_.reset(new uint8[kWidth * kHeight]);
+ frame_buffer_.reset(new uint8[kCodedSize.GetArea()]);
test_engine_.reset(new FFmpegVideoDecodeEngine());
@@ -105,10 +104,13 @@ class FFmpegVideoDecodeEngineTest
CallProduceVideoFrame();
CallProduceVideoFrame();
- 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());
+ 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());
}
// VideoDecodeEngine::EventHandler implementation.
@@ -125,11 +127,9 @@ class FFmpegVideoDecodeEngineTest
MOCK_METHOD0(OnError, void());
void CallProduceVideoFrame() {
- test_engine_->ProduceVideoFrame(VideoFrame::CreateFrame(VideoFrame::YV12,
- kWidth,
- kHeight,
- kNoTimestamp,
- kNoTimestamp));
+ test_engine_->ProduceVideoFrame(VideoFrame::CreateFrame(
+ VideoFrame::YV12, kVisibleRect.width(), kVisibleRect.height(),
+ kNoTimestamp, kNoTimestamp));
}
protected:
@@ -149,9 +149,8 @@ TEST_F(FFmpegVideoDecodeEngineTest, Initialize_Normal) {
}
TEST_F(FFmpegVideoDecodeEngineTest, Initialize_FindDecoderFails) {
- VideoDecoderConfig config(kUnknown, kWidth, kHeight, kSurfaceWidth,
- kSurfaceHeight, kFrameRate.num, kFrameRate.den,
- NULL, 0);
+ VideoDecoderConfig config(kUnknown, kCodedSize, kVisibleRect, kNaturalSize,
+ kFrameRate.num, kFrameRate.den, NULL, 0);
// Test avcodec_find_decoder() returning NULL.
VideoCodecInfo info;
EXPECT_CALL(*this, OnInitializeComplete(_))
@@ -162,8 +161,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, kWidth, kHeight, kSurfaceWidth,
- kSurfaceHeight, kFrameRate.num, kFrameRate.den,
+ VideoDecoderConfig config(kCodecTheora, kCodedSize, kVisibleRect,
+ kNaturalSize, 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 6171232..4ec7cf5 100644
--- a/media/video/video_decode_engine.h
+++ b/media/video/video_decode_engine.h
@@ -10,6 +10,7 @@
#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;
@@ -24,11 +25,8 @@ struct VideoCodecInfo {
// Other parameter is only meaningful when this is true.
bool success;
- // Can be different with container's value.
- uint32 surface_width;
-
- // Can be different with container's value.
- uint32 surface_height;
+ // Natural dimensions of video. May be different from coded and visible sizes.
+ gfx::Size natural_size;
};
class MEDIA_EXPORT VideoDecodeEngine {
diff --git a/webkit/glue/media/video_renderer_impl.cc b/webkit/glue/media/video_renderer_impl.cc
index 70dbe7a9a..4532935 100644
--- a/webkit/glue/media/video_renderer_impl.cc
+++ b/webkit/glue/media/video_renderer_impl.cc
@@ -21,9 +21,9 @@ VideoRendererImpl::VideoRendererImpl(bool pts_logging)
VideoRendererImpl::~VideoRendererImpl() {}
bool VideoRendererImpl::OnInitialize(media::VideoDecoder* decoder) {
- video_size_.SetSize(decoder->width(), decoder->height());
+ natural_size_ = decoder->natural_size();
bitmap_.setConfig(SkBitmap::kARGB_8888_Config,
- decoder->width(), decoder->height());
+ natural_size_.width(), natural_size_.height());
bitmap_.allocPixels();
bitmap_.eraseRGB(0x00, 0x00, 0x00);
bitmap_.setIsVolatile(true);
@@ -162,12 +162,12 @@ void VideoRendererImpl::SlowPaint(media::VideoFrame* video_frame,
SkMatrix matrix;
matrix.setTranslate(static_cast<SkScalar>(dest_rect.x()),
static_cast<SkScalar>(dest_rect.y()));
- if (dest_rect.width() != video_size_.width() ||
- dest_rect.height() != video_size_.height()) {
+ if (dest_rect.width() != natural_size_.width() ||
+ dest_rect.height() != natural_size_.height()) {
matrix.preScale(SkIntToScalar(dest_rect.width()) /
- SkIntToScalar(video_size_.width()),
+ SkIntToScalar(natural_size_.width()),
SkIntToScalar(dest_rect.height()) /
- SkIntToScalar(video_size_.height()));
+ SkIntToScalar(natural_size_.height()));
}
SkPaint paint;
paint.setFlags(SkPaint::kFilterBitmap_Flag);
diff --git a/webkit/glue/media/video_renderer_impl.h b/webkit/glue/media/video_renderer_impl.h
index 71977d0..aedadf2 100644
--- a/webkit/glue/media/video_renderer_impl.h
+++ b/webkit/glue/media/video_renderer_impl.h
@@ -68,8 +68,8 @@ class VideoRendererImpl : public WebVideoRenderer {
media::VideoFrame* last_converted_frame_;
base::TimeDelta last_converted_timestamp_;
- // The size of the video.
- gfx::Size video_size_;
+ // The natural size of the video.
+ gfx::Size natural_size_;
// Whether we're logging video presentation timestamps (PTS).
bool pts_logging_;
diff --git a/webkit/glue/webmediaplayer_impl.cc b/webkit/glue/webmediaplayer_impl.cc
index 300eeac..e77ed36 100644
--- a/webkit/glue/webmediaplayer_impl.cc
+++ b/webkit/glue/webmediaplayer_impl.cc
@@ -400,9 +400,9 @@ bool WebMediaPlayerImpl::hasAudio() const {
WebKit::WebSize WebMediaPlayerImpl::naturalSize() const {
DCHECK(MessageLoop::current() == main_loop_);
- size_t width, height;
- pipeline_->GetVideoSize(&width, &height);
- return WebKit::WebSize(width, height);
+ gfx::Size size;
+ pipeline_->GetNaturalVideoSize(&size);
+ return WebKit::WebSize(size);
}
bool WebMediaPlayerImpl::paused() const {