diff options
author | scherkus@chromium.org <scherkus@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-05-14 20:35:35 +0000 |
---|---|---|
committer | scherkus@chromium.org <scherkus@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-05-14 20:35:35 +0000 |
commit | 629b32899929cc043154ee54a4bf6364eccf5ce6 (patch) | |
tree | 77fb9a472f5b8302d20b836b21992e7e753968bb /media | |
parent | 77d7aeebd314325c40d602bdaffe9342e3f4e29e (diff) | |
download | chromium_src-629b32899929cc043154ee54a4bf6364eccf5ce6.zip chromium_src-629b32899929cc043154ee54a4bf6364eccf5ce6.tar.gz chromium_src-629b32899929cc043154ee54a4bf6364eccf5ce6.tar.bz2 |
Add a private opaque pointer option to VideoFrame.
This will allow using types such as EGLImageKHR for decoding and rendering.
Patch by wjia@google.com:
http://codereview.chromium.org/2008005/show
BUG=none
TEST=compiles
Review URL: http://codereview.chromium.org/2137001
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@47307 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'media')
-rw-r--r-- | media/base/video_frame.cc | 30 | ||||
-rw-r--r-- | media/base/video_frame.h | 23 | ||||
-rw-r--r-- | media/base/video_frame_unittest.cc | 22 |
3 files changed, 70 insertions, 5 deletions
diff --git a/media/base/video_frame.cc b/media/base/video_frame.cc index 0b8239c..9d81804 100644 --- a/media/base/video_frame.cc +++ b/media/base/video_frame.cc @@ -18,7 +18,7 @@ void VideoFrame::CreateFrame(VideoFrame::Format format, DCHECK(frame_out); bool alloc_worked = false; scoped_refptr<VideoFrame> frame = - new VideoFrame(format, width, height); + new VideoFrame(VideoFrame::TYPE_SYSTEM_MEMORY, format, width, height); if (frame) { frame->SetTimestamp(timestamp); frame->SetDuration(duration); @@ -49,7 +49,8 @@ void VideoFrame::CreateFrame(VideoFrame::Format format, // static void VideoFrame::CreateEmptyFrame(scoped_refptr<VideoFrame>* frame_out) { - *frame_out = new VideoFrame(VideoFrame::EMPTY, 0, 0); + *frame_out = new VideoFrame(VideoFrame::TYPE_SYSTEM_MEMORY, + VideoFrame::EMPTY, 0, 0); } // static @@ -90,6 +91,26 @@ void VideoFrame::CreateBlackFrame(int width, int height, *frame_out = frame; } +// static +void VideoFrame::CreatePrivateFrame(VideoFrame::BufferType type, + VideoFrame::Format format, + size_t width, + size_t height, + base::TimeDelta timestamp, + base::TimeDelta duration, + void* private_buffer, + scoped_refptr<VideoFrame>* frame_out) { + DCHECK(frame_out); + scoped_refptr<VideoFrame> frame = + new VideoFrame(type, format, width, height); + if (frame) { + frame->SetTimestamp(timestamp); + frame->SetDuration(duration); + frame->private_buffer_ = private_buffer; + } + *frame_out = frame; +} + static inline size_t RoundUp(size_t value, size_t alignment) { // Check that |alignment| is a power of 2. DCHECK((alignment + (alignment - 1)) == (alignment | (alignment - 1))); @@ -145,15 +166,18 @@ bool VideoFrame::AllocateYUV() { return false; } -VideoFrame::VideoFrame(VideoFrame::Format format, +VideoFrame::VideoFrame(VideoFrame::BufferType type, + VideoFrame::Format format, size_t width, size_t height) { + type_ = type; format_ = format; width_ = width; height_ = height; planes_ = 0; memset(&strides_, 0, sizeof(strides_)); memset(&data_, 0, sizeof(data_)); + private_buffer_ = NULL; } VideoFrame::~VideoFrame() { diff --git a/media/base/video_frame.h b/media/base/video_frame.h index e5cb8ba..77563a9 100644 --- a/media/base/video_frame.h +++ b/media/base/video_frame.h @@ -61,7 +61,17 @@ class VideoFrame : public StreamSample { static void CreateBlackFrame(int width, int height, scoped_refptr<VideoFrame>* frame_out); - virtual BufferType type() const { return TYPE_SYSTEM_MEMORY; } + // Creates a new frame of |type| with given parameters. + static void CreatePrivateFrame(VideoFrame::BufferType type, + VideoFrame::Format format, + size_t width, + size_t height, + base::TimeDelta timestamp, + base::TimeDelta duration, + void* private_buffer, + scoped_refptr<VideoFrame>* frame_out); + + virtual BufferType type() const { return type_; } Format format() const { return format_; } @@ -77,12 +87,15 @@ class VideoFrame : public StreamSample { // VideoFrame object and must not be freed by the caller. uint8* data(size_t plane) const { return data_[plane]; } + void* private_buffer() const { return private_buffer_; } + // StreamSample interface. virtual bool IsEndOfStream() const; protected: // Clients must use the static CreateFrame() method to create a new frame. - VideoFrame(Format format, + VideoFrame(BufferType type, + Format format, size_t video_width, size_t video_height); @@ -95,6 +108,9 @@ class VideoFrame : public StreamSample { // Frame format. Format format_; + // Buffer type. + BufferType type_; + // Width and height of surface. size_t width_; size_t height_; @@ -111,6 +127,9 @@ class VideoFrame : public StreamSample { // Array of data pointers to each plane. uint8* data_[kMaxPlanes]; + // Private buffer pointer, can be used for EGLImage. + void* private_buffer_; + DISALLOW_COPY_AND_ASSIGN(VideoFrame); }; diff --git a/media/base/video_frame_unittest.cc b/media/base/video_frame_unittest.cc index 27e15dc..caa5675 100644 --- a/media/base/video_frame_unittest.cc +++ b/media/base/video_frame_unittest.cc @@ -119,6 +119,8 @@ TEST(VideoFrame, CreateFrame) { EXPECT_FALSE(frame->IsDiscontinuous()); // Test VideoFrame implementation. + EXPECT_EQ(media::VideoFrame::TYPE_SYSTEM_MEMORY, frame->type()); + EXPECT_EQ(media::VideoFrame::YV12, frame->format()); { SCOPED_TRACE(""); InitializeYV12Frame(frame, 0.0f); @@ -173,4 +175,24 @@ TEST(VideoFrame, CreateBlackFrame) { } } +TEST(VideoFrame, CreatePrivateFrame) { + void* private_buffer = NULL; + const base::TimeDelta kTimestampA = base::TimeDelta::FromMicroseconds(1337); + const base::TimeDelta kDurationA = base::TimeDelta::FromMicroseconds(1667); + + // Create an EGL Frame. + scoped_refptr<media::VideoFrame> frame; + VideoFrame::CreatePrivateFrame(media::VideoFrame::TYPE_EGL_IMAGE, + media::VideoFrame::RGBA, 0, 0, + kTimestampA, kDurationA, + private_buffer, &frame); + ASSERT_TRUE(frame); + + // Test |frame| properties. + EXPECT_EQ(media::VideoFrame::TYPE_EGL_IMAGE, frame->type()); + EXPECT_EQ(media::VideoFrame::RGBA, frame->format()); + EXPECT_EQ(private_buffer, frame->private_buffer()); + EXPECT_EQ(NULL, frame->data(VideoFrame::kYPlane)); +} + } // namespace media |