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

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

Issue 10824141: Remove VideoDecoder::natural_size() & added VideoFrame::natural_size(). (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 4 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
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 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 #include "base/string_piece.h" 8 #include "base/string_piece.h"
9 #include "media/base/limits.h" 9 #include "media/base/limits.h"
10 #include "media/base/video_util.h" 10 #include "media/base/video_util.h"
11 #if !defined(OS_ANDROID) 11 #if !defined(OS_ANDROID)
12 #include "media/ffmpeg/ffmpeg_common.h" 12 #include "media/ffmpeg/ffmpeg_common.h"
13 #endif 13 #endif
14 14
15 #include <algorithm> 15 #include <algorithm>
16 16
17 namespace media { 17 namespace media {
18 18
19 // static 19 // static
20 scoped_refptr<VideoFrame> VideoFrame::CreateFrame( 20 scoped_refptr<VideoFrame> VideoFrame::CreateFrame(
21 VideoFrame::Format format, 21 VideoFrame::Format format,
22 size_t width, 22 size_t width,
23 size_t height, 23 size_t height,
24 const gfx::Size& natural_size,
24 base::TimeDelta timestamp) { 25 base::TimeDelta timestamp) {
25 DCHECK(IsValidConfig(format, width, height)); 26 DCHECK(IsValidConfig(format, width, height));
26 scoped_refptr<VideoFrame> frame(new VideoFrame( 27 scoped_refptr<VideoFrame> frame(new VideoFrame(
27 format, width, height, timestamp)); 28 format, width, height, natural_size, timestamp));
28 switch (format) { 29 switch (format) {
29 case VideoFrame::RGB32: 30 case VideoFrame::RGB32:
30 frame->AllocateRGB(4u); 31 frame->AllocateRGB(4u);
31 break; 32 break;
32 case VideoFrame::YV12: 33 case VideoFrame::YV12:
33 case VideoFrame::YV16: 34 case VideoFrame::YV16:
34 frame->AllocateYUV(); 35 frame->AllocateYUV();
35 break; 36 break;
36 default: 37 default:
37 LOG(FATAL) << "Unsupported frame format: " << format; 38 LOG(FATAL) << "Unsupported frame format: " << format;
(...skipping 12 matching lines...) Expand all
50 width <= limits::kMaxDimension && height <= limits::kMaxDimension && 51 width <= limits::kMaxDimension && height <= limits::kMaxDimension &&
51 width * height <= limits::kMaxCanvas); 52 width * height <= limits::kMaxCanvas);
52 } 53 }
53 54
54 // static 55 // static
55 scoped_refptr<VideoFrame> VideoFrame::WrapNativeTexture( 56 scoped_refptr<VideoFrame> VideoFrame::WrapNativeTexture(
56 uint32 texture_id, 57 uint32 texture_id,
57 uint32 texture_target, 58 uint32 texture_target,
58 size_t width, 59 size_t width,
59 size_t height, 60 size_t height,
61 const gfx::Size& natural_size,
60 base::TimeDelta timestamp, 62 base::TimeDelta timestamp,
61 const base::Closure& no_longer_needed) { 63 const base::Closure& no_longer_needed) {
62 scoped_refptr<VideoFrame> frame( 64 scoped_refptr<VideoFrame> frame(
63 new VideoFrame(NATIVE_TEXTURE, width, height, timestamp)); 65 new VideoFrame(NATIVE_TEXTURE, width, height, natural_size, timestamp));
64 frame->texture_id_ = texture_id; 66 frame->texture_id_ = texture_id;
65 frame->texture_target_ = texture_target; 67 frame->texture_target_ = texture_target;
66 frame->texture_no_longer_needed_ = no_longer_needed; 68 frame->texture_no_longer_needed_ = no_longer_needed;
67 return frame; 69 return frame;
68 } 70 }
69 71
70 // static 72 // static
71 scoped_refptr<VideoFrame> VideoFrame::CreateEmptyFrame() { 73 scoped_refptr<VideoFrame> VideoFrame::CreateEmptyFrame() {
72 return new VideoFrame( 74 return new VideoFrame(
73 VideoFrame::EMPTY, 0, 0, base::TimeDelta()); 75 VideoFrame::EMPTY, 0, 0, gfx::Size(), base::TimeDelta());
74 } 76 }
75 77
76 // static 78 // static
77 scoped_refptr<VideoFrame> VideoFrame::CreateBlackFrame(int width, int height) { 79 scoped_refptr<VideoFrame> VideoFrame::CreateBlackFrame(int width, int height) {
78 DCHECK_GT(width, 0); 80 DCHECK_GT(width, 0);
79 DCHECK_GT(height, 0); 81 DCHECK_GT(height, 0);
80 82
81 // Create our frame. 83 // Create our frame.
82 const base::TimeDelta kZero; 84 const base::TimeDelta kZero;
83 scoped_refptr<VideoFrame> frame = 85 scoped_refptr<VideoFrame> frame =
84 VideoFrame::CreateFrame(VideoFrame::YV12, width, height, kZero); 86 VideoFrame::CreateFrame(VideoFrame::YV12, width, height,
87 gfx::Size(width, height), kZero);
85 88
86 // Now set the data to YUV(0,128,128). 89 // Now set the data to YUV(0,128,128).
87 const uint8 kBlackY = 0x00; 90 const uint8 kBlackY = 0x00;
88 const uint8 kBlackUV = 0x80; 91 const uint8 kBlackUV = 0x80;
89 FillYUV(frame, kBlackY, kBlackUV, kBlackUV); 92 FillYUV(frame, kBlackY, kBlackUV, kBlackUV);
90 return frame; 93 return frame;
91 } 94 }
92 95
93 static inline size_t RoundUp(size_t value, size_t alignment) { 96 static inline size_t RoundUp(size_t value, size_t alignment) {
94 // Check that |alignment| is a power of 2. 97 // Check that |alignment| is a power of 2.
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
158 data_[VideoFrame::kUPlane] = data + y_bytes; 161 data_[VideoFrame::kUPlane] = data + y_bytes;
159 data_[VideoFrame::kVPlane] = data + y_bytes + uv_bytes; 162 data_[VideoFrame::kVPlane] = data + y_bytes + uv_bytes;
160 strides_[VideoFrame::kYPlane] = y_stride; 163 strides_[VideoFrame::kYPlane] = y_stride;
161 strides_[VideoFrame::kUPlane] = uv_stride; 164 strides_[VideoFrame::kUPlane] = uv_stride;
162 strides_[VideoFrame::kVPlane] = uv_stride; 165 strides_[VideoFrame::kVPlane] = uv_stride;
163 } 166 }
164 167
165 VideoFrame::VideoFrame(VideoFrame::Format format, 168 VideoFrame::VideoFrame(VideoFrame::Format format,
166 size_t width, 169 size_t width,
167 size_t height, 170 size_t height,
171 const gfx::Size& natural_size,
168 base::TimeDelta timestamp) 172 base::TimeDelta timestamp)
169 : format_(format), 173 : format_(format),
170 width_(width), 174 width_(width),
171 height_(height), 175 height_(height),
176 natural_size_(natural_size),
172 texture_id_(0), 177 texture_id_(0),
173 texture_target_(0), 178 texture_target_(0),
174 timestamp_(timestamp) { 179 timestamp_(timestamp) {
175 memset(&strides_, 0, sizeof(strides_)); 180 memset(&strides_, 0, sizeof(strides_));
176 memset(&data_, 0, sizeof(data_)); 181 memset(&data_, 0, sizeof(data_));
177 } 182 }
178 183
179 VideoFrame::~VideoFrame() { 184 VideoFrame::~VideoFrame() {
180 if (format_ == NATIVE_TEXTURE && !texture_no_longer_needed_.is_null()) { 185 if (format_ == NATIVE_TEXTURE && !texture_no_longer_needed_.is_null()) {
181 texture_no_longer_needed_.Run(); 186 texture_no_longer_needed_.Run();
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
290 break; 295 break;
291 for(int row = 0; row < rows(plane); row++) { 296 for(int row = 0; row < rows(plane); row++) {
292 base::MD5Update(context, base::StringPiece( 297 base::MD5Update(context, base::StringPiece(
293 reinterpret_cast<char*>(data(plane) + stride(plane) * row), 298 reinterpret_cast<char*>(data(plane) + stride(plane) * row),
294 row_bytes(plane))); 299 row_bytes(plane)));
295 } 300 }
296 } 301 }
297 } 302 }
298 303
299 } // namespace media 304 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698