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

Side by Side Diff: media/base/video_frame.cc

Issue 3335014: Added FakeGlVideoDecodeEngine to exercise the IPC protocol for hardware video decoding (Closed)
Patch Set: compile man... Created 10 years, 3 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
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "media/base/video_frame.h" 5 #include "media/base/video_frame.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 8
9 namespace media { 9 namespace media {
10 10
11 static size_t GetNumberOfPlanes(VideoFrame::Format format) {
12 switch (format) {
13 case VideoFrame::RGB555:
14 case VideoFrame::RGB565:
15 case VideoFrame::RGB24:
16 case VideoFrame::RGB32:
17 case VideoFrame::RGBA:
18 case VideoFrame::ASCII:
19 return VideoFrame::kNumRGBPlanes;
20 case VideoFrame::YV12:
21 case VideoFrame::YV16:
22 return VideoFrame::kNumYUVPlanes;
23 case VideoFrame::NV12:
24 return VideoFrame::kNumNV12Planes;
25 default:
26 return 0;
27 }
28 }
29
11 // static 30 // static
12 void VideoFrame::CreateFrame(VideoFrame::Format format, 31 void VideoFrame::CreateFrame(VideoFrame::Format format,
13 size_t width, 32 size_t width,
14 size_t height, 33 size_t height,
15 base::TimeDelta timestamp, 34 base::TimeDelta timestamp,
16 base::TimeDelta duration, 35 base::TimeDelta duration,
17 scoped_refptr<VideoFrame>* frame_out) { 36 scoped_refptr<VideoFrame>* frame_out) {
18 DCHECK(width > 0 && height > 0); 37 DCHECK(width > 0 && height > 0);
19 DCHECK(width * height < 100000000); 38 DCHECK(width * height < 100000000);
20 DCHECK(frame_out); 39 DCHECK(frame_out);
(...skipping 24 matching lines...) Expand all
45 break; 64 break;
46 default: 65 default:
47 NOTREACHED(); 66 NOTREACHED();
48 alloc_worked = false; 67 alloc_worked = false;
49 break; 68 break;
50 } 69 }
51 } 70 }
52 *frame_out = alloc_worked ? frame : NULL; 71 *frame_out = alloc_worked ? frame : NULL;
53 } 72 }
54 73
74 // static
55 void VideoFrame::CreateFrameExternal(SurfaceType type, 75 void VideoFrame::CreateFrameExternal(SurfaceType type,
56 Format format, 76 Format format,
57 size_t width, 77 size_t width,
58 size_t height, 78 size_t height,
59 size_t planes, 79 size_t planes,
60 uint8* const data[kMaxPlanes], 80 uint8* const data[kMaxPlanes],
61 const int32 strides[kMaxPlanes], 81 const int32 strides[kMaxPlanes],
62 base::TimeDelta timestamp, 82 base::TimeDelta timestamp,
63 base::TimeDelta duration, 83 base::TimeDelta duration,
64 void* private_buffer, 84 void* private_buffer,
65 scoped_refptr<VideoFrame>* frame_out) { 85 scoped_refptr<VideoFrame>* frame_out) {
66 DCHECK(frame_out); 86 DCHECK(frame_out);
67 scoped_refptr<VideoFrame> frame = 87 scoped_refptr<VideoFrame> frame =
68 new VideoFrame(type, format, width, height); 88 new VideoFrame(type, format, width, height);
69 if (frame) { 89 if (frame) {
70 frame->SetTimestamp(timestamp); 90 frame->SetTimestamp(timestamp);
71 frame->SetDuration(duration); 91 frame->SetDuration(duration);
72 frame->external_memory_ = true; 92 frame->external_memory_ = true;
73 frame->planes_ = planes; 93 frame->planes_ = planes;
74 frame->private_buffer_ = private_buffer; 94 frame->private_buffer_ = private_buffer;
75 for (size_t i = 0; i < kMaxPlanes; ++i) { 95 for (size_t i = 0; i < kMaxPlanes; ++i) {
76 frame->data_[i] = data[i]; 96 frame->data_[i] = data[i];
77 frame->strides_[i] = strides[i]; 97 frame->strides_[i] = strides[i];
78 } 98 }
79 } 99 }
80 *frame_out = frame; 100 *frame_out = frame;
81 } 101 }
82 102
83 // static 103 // static
104 void VideoFrame::CreateFrameGlTexture(Format format,
105 size_t width,
106 size_t height,
107 GlTexture const textures[kMaxPlanes],
108 base::TimeDelta timestamp,
109 base::TimeDelta duration,
110 scoped_refptr<VideoFrame>* frame_out) {
111 DCHECK(frame_out);
112 scoped_refptr<VideoFrame> frame =
113 new VideoFrame(TYPE_GL_TEXTURE, format, width, height);
114 if (frame) {
115 frame->SetTimestamp(timestamp);
116 frame->SetDuration(duration);
117 frame->external_memory_ = true;
118 frame->planes_ = GetNumberOfPlanes(format);
119 for (size_t i = 0; i < kMaxPlanes; ++i) {
120 frame->gl_textures_[i] = textures[i];
121 }
122 }
123 *frame_out = frame;
124 }
125
126 // static
127 void VideoFrame::CreateFrameD3dTexture(Format format,
128 size_t width,
129 size_t height,
130 D3dTexture const textures[kMaxPlanes],
131 base::TimeDelta timestamp,
132 base::TimeDelta duration,
133 scoped_refptr<VideoFrame>* frame_out) {
134 DCHECK(frame_out);
135 scoped_refptr<VideoFrame> frame =
136 new VideoFrame(TYPE_D3D_TEXTURE, format, width, height);
137 if (frame) {
138 frame->SetTimestamp(timestamp);
139 frame->SetDuration(duration);
140 frame->external_memory_ = true;
141 frame->planes_ = GetNumberOfPlanes(format);
142 for (size_t i = 0; i < kMaxPlanes; ++i) {
143 frame->d3d_textures_[i] = textures[i];
144 }
145 }
146 *frame_out = frame;
147 }
148
149 // static
84 void VideoFrame::CreateEmptyFrame(scoped_refptr<VideoFrame>* frame_out) { 150 void VideoFrame::CreateEmptyFrame(scoped_refptr<VideoFrame>* frame_out) {
85 *frame_out = new VideoFrame(VideoFrame::TYPE_SYSTEM_MEMORY, 151 *frame_out = new VideoFrame(VideoFrame::TYPE_SYSTEM_MEMORY,
86 VideoFrame::EMPTY, 0, 0); 152 VideoFrame::EMPTY, 0, 0);
87 } 153 }
88 154
89 // static 155 // static
90 void VideoFrame::CreateBlackFrame(int width, int height, 156 void VideoFrame::CreateBlackFrame(int width, int height,
91 scoped_refptr<VideoFrame>* frame_out) { 157 scoped_refptr<VideoFrame>* frame_out) {
92 DCHECK_GT(width, 0); 158 DCHECK_GT(width, 0);
93 DCHECK_GT(height, 0); 159 DCHECK_GT(height, 0);
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
185 VideoFrame::Format format, 251 VideoFrame::Format format,
186 size_t width, 252 size_t width,
187 size_t height) { 253 size_t height) {
188 type_ = type; 254 type_ = type;
189 format_ = format; 255 format_ = format;
190 width_ = width; 256 width_ = width;
191 height_ = height; 257 height_ = height;
192 planes_ = 0; 258 planes_ = 0;
193 memset(&strides_, 0, sizeof(strides_)); 259 memset(&strides_, 0, sizeof(strides_));
194 memset(&data_, 0, sizeof(data_)); 260 memset(&data_, 0, sizeof(data_));
261 memset(&gl_textures_, 0, sizeof(gl_textures_));
262 memset(&d3d_textures_, 0, sizeof(d3d_textures_));
195 external_memory_ = false; 263 external_memory_ = false;
196 private_buffer_ = NULL; 264 private_buffer_ = NULL;
197 } 265 }
198 266
199 VideoFrame::~VideoFrame() { 267 VideoFrame::~VideoFrame() {
200 // In multi-plane allocations, only a single block of memory is allocated 268 // In multi-plane allocations, only a single block of memory is allocated
201 // on the heap, and other |data| pointers point inside the same, single block 269 // on the heap, and other |data| pointers point inside the same, single block
202 // so just delete index 0. 270 // so just delete index 0.
203 if (!external_memory_) 271 if (!external_memory_)
204 delete[] data_[0]; 272 delete[] data_[0];
205 } 273 }
206 274
207 bool VideoFrame::IsEndOfStream() const { 275 bool VideoFrame::IsEndOfStream() const {
208 return format_ == VideoFrame::EMPTY; 276 return format_ == VideoFrame::EMPTY;
209 } 277 }
210 278
211 } // namespace media 279 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698