summaryrefslogtreecommitdiffstats
path: root/media/base
diff options
context:
space:
mode:
Diffstat (limited to 'media/base')
-rw-r--r--media/base/video_decoder_config.cc11
-rw-r--r--media/base/video_decoder_config.h14
-rw-r--r--media/base/video_frame.cc26
3 files changed, 36 insertions, 15 deletions
diff --git a/media/base/video_decoder_config.cc b/media/base/video_decoder_config.cc
index ef5e0cb..81583c1 100644
--- a/media/base/video_decoder_config.cc
+++ b/media/base/video_decoder_config.cc
@@ -10,19 +10,21 @@ namespace media {
VideoDecoderConfig::VideoDecoderConfig()
: codec_(kUnknownVideoCodec),
+ format_(VideoFrame::INVALID),
frame_rate_numerator_(0),
frame_rate_denominator_(0),
extra_data_size_(0) {
}
VideoDecoderConfig::VideoDecoderConfig(VideoCodec codec,
+ VideoFrame::Format format,
const gfx::Size& coded_size,
const gfx::Rect& visible_rect,
int frame_rate_numerator,
int frame_rate_denominator,
const uint8* extra_data,
size_t extra_data_size) {
- Initialize(codec, coded_size, visible_rect,
+ Initialize(codec, format, coded_size, visible_rect,
frame_rate_numerator, frame_rate_denominator,
extra_data, extra_data_size);
}
@@ -30,6 +32,7 @@ VideoDecoderConfig::VideoDecoderConfig(VideoCodec codec,
VideoDecoderConfig::~VideoDecoderConfig() {}
void VideoDecoderConfig::Initialize(VideoCodec codec,
+ VideoFrame::Format format,
const gfx::Size& coded_size,
const gfx::Rect& visible_rect,
int frame_rate_numerator,
@@ -39,6 +42,7 @@ void VideoDecoderConfig::Initialize(VideoCodec codec,
CHECK((extra_data_size != 0) == (extra_data != NULL));
codec_ = codec;
+ format_ = format;
coded_size_ = coded_size;
visible_rect_ = visible_rect;
frame_rate_numerator_ = frame_rate_numerator;
@@ -55,6 +59,7 @@ void VideoDecoderConfig::Initialize(VideoCodec codec,
bool VideoDecoderConfig::IsValidConfig() const {
return codec_ != kUnknownVideoCodec &&
+ format_ != VideoFrame::INVALID &&
frame_rate_numerator_ > 0 &&
frame_rate_denominator_ > 0;
}
@@ -63,6 +68,10 @@ VideoCodec VideoDecoderConfig::codec() const {
return codec_;
}
+VideoFrame::Format VideoDecoderConfig::format() const {
+ return format_;
+}
+
gfx::Size VideoDecoderConfig::coded_size() const {
return coded_size_;
}
diff --git a/media/base/video_decoder_config.h b/media/base/video_decoder_config.h
index 305bad6..44182df4 100644
--- a/media/base/video_decoder_config.h
+++ b/media/base/video_decoder_config.h
@@ -8,6 +8,7 @@
#include "base/basictypes.h"
#include "base/memory/scoped_ptr.h"
#include "media/base/media_export.h"
+#include "media/base/video_frame.h"
#include "ui/gfx/rect.h"
#include "ui/gfx/size.h"
@@ -36,7 +37,9 @@ class MEDIA_EXPORT VideoDecoderConfig {
// Constructs an initialized object. It is acceptable to pass in NULL for
// |extra_data|, otherwise the memory is copied.
- VideoDecoderConfig(VideoCodec codec, const gfx::Size& coded_size,
+ VideoDecoderConfig(VideoCodec codec,
+ VideoFrame::Format format,
+ const gfx::Size& coded_size,
const gfx::Rect& visible_rect,
int frame_rate_numerator, int frame_rate_denominator,
const uint8* extra_data, size_t extra_data_size);
@@ -44,7 +47,9 @@ class MEDIA_EXPORT VideoDecoderConfig {
~VideoDecoderConfig();
// Resets the internal state of this object.
- void Initialize(VideoCodec codec, const gfx::Size& coded_size,
+ void Initialize(VideoCodec codec,
+ VideoFrame::Format format,
+ const gfx::Size& coded_size,
const gfx::Rect& visible_rect,
int frame_rate_numerator, int frame_rate_denominator,
const uint8* extra_data, size_t extra_data_size);
@@ -55,6 +60,9 @@ class MEDIA_EXPORT VideoDecoderConfig {
VideoCodec codec() const;
+ // Video format used to determine YUV buffer sizes.
+ VideoFrame::Format format() const;
+
// Width and height of video frame immediately post-decode. Not all pixels
// in this region are valid.
gfx::Size coded_size() const;
@@ -75,6 +83,8 @@ class MEDIA_EXPORT VideoDecoderConfig {
private:
VideoCodec codec_;
+ VideoFrame::Format format_;
+
gfx::Size coded_size_;
gfx::Rect visible_rect_;
diff --git a/media/base/video_frame.cc b/media/base/video_frame.cc
index c40c58f..340ba19 100644
--- a/media/base/video_frame.cc
+++ b/media/base/video_frame.cc
@@ -75,9 +75,12 @@ scoped_refptr<VideoFrame> VideoFrame::CreateBlackFrame(int width, int height) {
// Fill the U and V planes.
uint8* u_plane = frame->data(VideoFrame::kUPlane);
uint8* v_plane = frame->data(VideoFrame::kVPlane);
- for (size_t i = 0; i < (frame->height_ / 2); ++i) {
- memset(u_plane, kBlackUV, frame->width_ / 2);
- memset(v_plane, kBlackUV, frame->width_ / 2);
+ int uv_rows = frame->rows(VideoFrame::kUPlane);
+ int u_row_bytes = frame->row_bytes(VideoFrame::kUPlane);
+ int v_row_bytes = frame->row_bytes(VideoFrame::kVPlane);
+ for (size_t i = 0; i < (size_t)uv_rows; ++i) {
+ memset(u_plane, kBlackUV, u_row_bytes);
+ memset(v_plane, kBlackUV, v_row_bytes);
u_plane += frame->stride(VideoFrame::kUPlane);
v_plane += frame->stride(VideoFrame::kVPlane);
}
@@ -115,21 +118,20 @@ void VideoFrame::AllocateYUV() {
// to avoid any potential of faulting by code that attempts to access the Y
// values of the final row, but assumes that the last row of U & V applies to
// a full two rows of Y.
- size_t alloc_height = RoundUp(height_, 2);
- size_t y_bytes_per_row = RoundUp(width_, 4);
- size_t uv_stride = RoundUp(y_bytes_per_row / 2, 4);
- size_t y_bytes = alloc_height * y_bytes_per_row;
- size_t uv_bytes = alloc_height * uv_stride;
- if (format_ == VideoFrame::YV12) {
- uv_bytes /= 2;
- }
+ size_t y_height = RoundUp(rows(VideoFrame::kYPlane), 2);
+ size_t y_stride = RoundUp(row_bytes(VideoFrame::kYPlane), 4);
+ size_t uv_stride = RoundUp(row_bytes(VideoFrame::kUPlane), 4);
+ size_t uv_height = RoundUp(rows(VideoFrame::kUPlane), 2);
+ size_t y_bytes = y_height * y_stride;
+ size_t uv_bytes = uv_height * uv_stride;
+
uint8* data = new uint8[y_bytes + (uv_bytes * 2) + kFramePadBytes];
planes_ = VideoFrame::kNumYUVPlanes;
COMPILE_ASSERT(0 == VideoFrame::kYPlane, y_plane_data_must_be_index_0);
data_[VideoFrame::kYPlane] = data;
data_[VideoFrame::kUPlane] = data + y_bytes;
data_[VideoFrame::kVPlane] = data + y_bytes + uv_bytes;
- strides_[VideoFrame::kYPlane] = y_bytes_per_row;
+ strides_[VideoFrame::kYPlane] = y_stride;
strides_[VideoFrame::kUPlane] = uv_stride;
strides_[VideoFrame::kVPlane] = uv_stride;
}