Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(80)

Side by Side Diff: webkit/media/crypto/ppapi/ffmpeg_cdm_video_frame.cc

Issue 10899021: Add CDM video decoder. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address more comments. Created 8 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "webkit/media/crypto/ppapi/ffmpeg_cdm_video_frame.h"
6
7 #include "base/logging.h"
8 #include "base/memory/scoped_ptr.h"
9 #include "media/base/limits.h"
10 #include "webkit/media/crypto/ppapi/ffmpeg_cdm_video_decoder.h"
11
12
xhwang 2012/10/17 18:43:00 remove extra empty line
Tom Finegan 2012/10/17 19:55:44 Done.
13 namespace webkit_media {
14
15 namespace {
16
17 inline size_t RoundUp(size_t value, size_t alignment) {
xhwang 2012/10/17 18:43:00 Can we use "int" ?
Tom Finegan 2012/10/17 19:55:44 Done.
18 // Check that |alignment| is a power of 2.
19 DCHECK((alignment + (alignment - 1)) == (alignment | (alignment - 1)));
20 return ((value + (alignment - 1)) & ~(alignment-1));
21 }
22
23 int RowBytes(cdm::VideoFormat format,
24 cdm::VideoFrame::VideoPlane plane,
25 int width) {
26 switch (format) {
27 case cdm::kYv12:
28 case cdm::kI420:
29 if (plane == cdm::VideoFrame::kYPlane)
30 return width;
31 return RoundUp(width, 2) / 2;
32
33 default:
34 NOTREACHED() << "Unsupported video frame format: " << format;
35 return 0;
36 }
37 }
38
39 } // namespace
xhwang 2012/10/17 18:43:00 media code prefer using static to anonymous namesp
Tom Finegan 2012/10/17 19:55:44 Removed anonymous namespace, and made things stati
40
41 // static
42 FFmpegCdmVideoFrame* FFmpegCdmVideoFrame::Create(cdm::Allocator* allocator,
43 cdm::VideoFormat format,
44 const cdm::Size& size) {
45 if (!IsValidConfig(format, size)) {
46 LOG(ERROR) << "Create() invalid config.";
47 return NULL;
48 }
49
50 scoped_ptr<FFmpegCdmVideoFrame> frame(new FFmpegCdmVideoFrame(format, size));
51
52 if (!frame->AllocateYuv(allocator))
53 return NULL;
54
55 return frame.release();
56 }
57
58 FFmpegCdmVideoFrame::FFmpegCdmVideoFrame(cdm::VideoFormat format,
59 const cdm::Size& size)
60 : format_(format),
61 size_(size),
62 frame_buffer_(NULL) {
63 for (int32_t i = 0; i < cdm::VideoFrame::kMaxPlanes; ++i) {
64 plane_offsets_[i] = 0;
65 strides_[i] = 0;
66 }
67 }
68
69 FFmpegCdmVideoFrame::~FFmpegCdmVideoFrame() {
70 if (frame_buffer_)
71 frame_buffer_->Destroy();
72 }
73
74 int32_t FFmpegCdmVideoFrame::plane_offset(
75 cdm::VideoFrame::VideoPlane plane) const {
76 DCHECK(0 <= plane && plane < cdm::VideoFrame::kMaxPlanes);
77 return plane_offsets_[plane];
78 }
79
80 int32_t FFmpegCdmVideoFrame::stride(
81 cdm::VideoFrame::VideoPlane plane) const {
82 DCHECK(0 <= plane && plane < cdm::VideoFrame::kMaxPlanes);
83 return strides_[plane];
84 }
85
86 // static
87 bool FFmpegCdmVideoFrame::IsValidConfig(cdm::VideoFormat format,
xhwang 2012/10/17 18:43:00 This function is not using any class members. Make
Tom Finegan 2012/10/17 19:55:44 Can't do that-- this method is called from in this
xhwang 2012/10/17 20:23:10 Ok, did't notice it's used in another file. In tha
Tom Finegan 2012/10/17 21:32:22 I made it a static member function of FFmpegCdmVid
88 const cdm::Size& data_size) {
89 return ((format == cdm::kYv12 || format == cdm::kI420) &&
90 data_size.width > 0 && data_size.height > 0 &&
91 data_size.width <= media::limits::kMaxDimension &&
92 data_size.height <= media::limits::kMaxDimension &&
93 data_size.width * data_size.height <= media::limits::kMaxCanvas);
94 }
95
96 void FFmpegCdmVideoFrame::TransferVideoFrame(cdm::VideoFrame* target) {
ddorwin 2012/10/17 06:10:19 Should we clear this frame to invalid values so it
Tom Finegan 2012/10/17 19:55:44 There's a DCHECK on frame_buffer() in FFmpegCdmVid
97 DCHECK(frame_buffer_);
98 DCHECK(target);
99 target->set_format(format_);
100 target->set_frame_buffer(frame_buffer_);
101 frame_buffer_ = NULL;
102
103 const int kMaxPlanes = cdm::VideoFrame::kMaxPlanes;
104 for (int i = 0; i < kMaxPlanes; ++i) {
105 cdm::VideoFrame::VideoPlane plane =
106 static_cast<cdm::VideoFrame::VideoPlane>(i);
107 target->set_plane_offset(plane, plane_offsets_[i]);
108 target->set_stride(plane, strides_[i]);
109 }
110 }
111
112 bool FFmpegCdmVideoFrame::AllocateYuv(cdm::Allocator* allocator) {
113 DCHECK(allocator);
114 DCHECK(format_ == cdm::kYv12 || format_ == cdm::kI420);
115
116 // Align Y rows at least at 32 byte boundaries for safety on all platforms.
117 DVLOG(3) << "AllocateYuv() width=" << size_.width << " height="
118 << size_.height;
119 size_t y_stride = RoundUp(
120 RowBytes(format_, cdm::VideoFrame::kYPlane, size_.width),
121 kBufferAlignment);
122 size_t uv_stride = RoundUp(
123 RowBytes(format_, cdm::VideoFrame::kUPlane, size_.width),
124 kBufferAlignment);
xhwang 2012/10/17 18:43:00 So for Y, stride is RoundUp(width, kBufferAlignmen
Tom Finegan 2012/10/17 19:55:44 I think it's in case width is an odd number, which
xhwang 2012/10/17 20:23:10 Since kBufferAlignment is even, I don't think it's
Tom Finegan 2012/10/17 21:32:22 sgtm
125
126 size_t y_height = RoundUp(size_.height, kBufferAlignment);
xhwang 2012/10/17 18:43:00 What exactly is kBufferAlignment (==32 for now)? W
Tom Finegan 2012/10/17 19:55:44 Added comment from media that explains this.
127 size_t uv_height = y_height / 2;
128 size_t y_bytes = y_height * y_stride;
129 size_t uv_bytes = uv_height * uv_stride;
130
131 frame_buffer_ = allocator->Allocate(y_bytes + (uv_bytes * 2));
132 if (!frame_buffer_) {
133 LOG(ERROR) << "AllocateYuv() cdm::Allocator::Allocate failed.";
134 return false;
135 }
136
137 COMPILE_ASSERT(0 == cdm::VideoFrame::kYPlane, y_plane_data_must_be_index_0);
138 uint8_t* data = frame_buffer_->data();
139 DCHECK_EQ(0U, reinterpret_cast<uintptr_t>(data) & (kBufferAlignment - 1));
140
141 plane_offsets_[cdm::VideoFrame::kYPlane] = 0;
142
143 if (format_ == cdm::kYv12) {
144 plane_offsets_[cdm::VideoFrame::kVPlane] = y_bytes;
145 plane_offsets_[cdm::VideoFrame::kUPlane] = y_bytes + uv_bytes;
146 } else {
147 plane_offsets_[cdm::VideoFrame::kUPlane] = y_bytes;
148 plane_offsets_[cdm::VideoFrame::kVPlane] = y_bytes + uv_bytes;
149 }
150
151 strides_[cdm::VideoFrame::kYPlane] = y_stride;
152 strides_[cdm::VideoFrame::kUPlane] = uv_stride;
153 strides_[cdm::VideoFrame::kVPlane] = uv_stride;
154
155 return true;
156 }
157
158 } // namespace webkit_media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698