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

Side by Side Diff: cc/resources/video_resource_updater.cc

Issue 178133005: Audit/fix use of media::VideoFrame::coded_size() (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: d4e1a5bd Uhh yeah. Created 6 years, 9 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "cc/resources/video_resource_updater.h" 5 #include "cc/resources/video_resource_updater.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "cc/output/gl_renderer.h" 8 #include "cc/output/gl_renderer.h"
9 #include "cc/resources/resource_provider.h" 9 #include "cc/resources/resource_provider.h"
10 #include "gpu/GLES2/gl2extchromium.h" 10 #include "gpu/GLES2/gl2extchromium.h"
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 78
79 // Unacceptable inputs. ¯\(°_o)/¯ 79 // Unacceptable inputs. ¯\(°_o)/¯
80 case media::VideoFrame::UNKNOWN: 80 case media::VideoFrame::UNKNOWN:
81 case media::VideoFrame::HISTOGRAM_MAX: 81 case media::VideoFrame::HISTOGRAM_MAX:
82 case media::VideoFrame::I420: 82 case media::VideoFrame::I420:
83 break; 83 break;
84 } 84 }
85 return false; 85 return false;
86 } 86 }
87 87
88 // For frames that we receive in software format, determine the dimensions of
89 // each plane in the frame.
90 static gfx::Size SoftwarePlaneDimension(
91 media::VideoFrame::Format input_frame_format,
92 const gfx::Size& coded_size,
93 ResourceFormat output_resource_format,
94 int plane_index) {
95 if (output_resource_format == kYUVResourceFormat) {
danakj 2014/02/28 16:55:34 Can you keep this method, and just have it call Vi
96 if (plane_index == media::VideoFrame::kYPlane ||
97 plane_index == media::VideoFrame::kAPlane)
98 return coded_size;
99
100 switch (input_frame_format) {
101 case media::VideoFrame::YV12:
102 case media::VideoFrame::YV12A:
103 case media::VideoFrame::YV12J:
104 return gfx::ToFlooredSize(gfx::ScaleSize(coded_size, 0.5f, 0.5f));
105 case media::VideoFrame::YV16:
106 return gfx::ToFlooredSize(gfx::ScaleSize(coded_size, 0.5f, 1.f));
107
108 case media::VideoFrame::UNKNOWN:
109 case media::VideoFrame::I420:
110 case media::VideoFrame::NATIVE_TEXTURE:
111 case media::VideoFrame::HISTOGRAM_MAX:
112 #if defined(VIDEO_HOLE)
113 case media::VideoFrame::HOLE:
114 #endif // defined(VIDEO_HOLE)
115 NOTREACHED();
116 }
117 }
118
119 DCHECK_EQ(output_resource_format, kRGBResourceFormat);
120 return coded_size;
121 }
122
123 VideoFrameExternalResources VideoResourceUpdater::CreateForSoftwarePlanes( 88 VideoFrameExternalResources VideoResourceUpdater::CreateForSoftwarePlanes(
124 const scoped_refptr<media::VideoFrame>& video_frame) { 89 const scoped_refptr<media::VideoFrame>& video_frame) {
125 media::VideoFrame::Format input_frame_format = video_frame->format(); 90 media::VideoFrame::Format input_frame_format = video_frame->format();
126 91
127 #if defined(VIDEO_HOLE) 92 #if defined(VIDEO_HOLE)
128 if (input_frame_format == media::VideoFrame::HOLE) { 93 if (input_frame_format == media::VideoFrame::HOLE) {
129 VideoFrameExternalResources external_resources; 94 VideoFrameExternalResources external_resources;
130 external_resources.type = VideoFrameExternalResources::HOLE; 95 external_resources.type = VideoFrameExternalResources::HOLE;
131 return external_resources; 96 return external_resources;
132 } 97 }
133 #endif // defined(VIDEO_HOLE) 98 #endif // defined(VIDEO_HOLE)
134 99
135 // Only YUV software video frames are supported. 100 // Only YUV software video frames are supported.
136 DCHECK(input_frame_format == media::VideoFrame::YV12 || 101 DCHECK(input_frame_format == media::VideoFrame::YV12 ||
137 input_frame_format == media::VideoFrame::YV12A || 102 input_frame_format == media::VideoFrame::YV12A ||
138 input_frame_format == media::VideoFrame::YV12J || 103 input_frame_format == media::VideoFrame::YV12J ||
139 input_frame_format == media::VideoFrame::YV16); 104 input_frame_format == media::VideoFrame::YV16);
140 if (input_frame_format != media::VideoFrame::YV12 && 105 if (input_frame_format != media::VideoFrame::YV12 &&
141 input_frame_format != media::VideoFrame::YV12A && 106 input_frame_format != media::VideoFrame::YV12A &&
142 input_frame_format != media::VideoFrame::YV12J && 107 input_frame_format != media::VideoFrame::YV12J &&
143 input_frame_format != media::VideoFrame::YV16) 108 input_frame_format != media::VideoFrame::YV16)
144 return VideoFrameExternalResources(); 109 return VideoFrameExternalResources();
145 110
146 bool software_compositor = context_provider_ == NULL; 111 bool software_compositor = context_provider_ == NULL;
147 112
148 ResourceFormat output_resource_format = kYUVResourceFormat; 113 ResourceFormat output_resource_format = kYUVResourceFormat;
149 size_t output_plane_count = 114 size_t output_plane_count = media::VideoFrame::NumPlanes(input_frame_format);
150 (input_frame_format == media::VideoFrame::YV12A) ? 4 : 3;
151 115
152 // TODO(skaslev): If we're in software compositing mode, we do the YUV -> RGB 116 // TODO(skaslev): If we're in software compositing mode, we do the YUV -> RGB
153 // conversion here. That involves an extra copy of each frame to a bitmap. 117 // conversion here. That involves an extra copy of each frame to a bitmap.
154 // Obviously, this is suboptimal and should be addressed once ubercompositor 118 // Obviously, this is suboptimal and should be addressed once ubercompositor
155 // starts shaping up. 119 // starts shaping up.
156 if (software_compositor) { 120 if (software_compositor) {
157 output_resource_format = kRGBResourceFormat; 121 output_resource_format = kRGBResourceFormat;
158 output_plane_count = 1; 122 output_plane_count = 1;
159 } 123 }
160 124
161 int max_resource_size = resource_provider_->max_texture_size(); 125 int max_resource_size = resource_provider_->max_texture_size();
162 gfx::Size coded_frame_size = video_frame->coded_size();
163
164 std::vector<PlaneResource> plane_resources; 126 std::vector<PlaneResource> plane_resources;
165 bool allocation_success = true; 127 bool allocation_success = true;
166 128
167 for (size_t i = 0; i < output_plane_count; ++i) { 129 for (size_t i = 0; i < output_plane_count; ++i) {
168 gfx::Size output_plane_resource_size = 130 gfx::Size output_plane_resource_size = video_frame->coded_size();
169 SoftwarePlaneDimension(input_frame_format, 131 if (output_resource_format == kYUVResourceFormat) {
170 coded_frame_size, 132 output_plane_resource_size = media::VideoFrame::PlaneSize(
171 output_resource_format, 133 video_frame->format(), i, video_frame->coded_size());
172 i); 134 } else {
135 DCHECK_EQ(output_resource_format, kRGBResourceFormat);
136 }
173 if (output_plane_resource_size.IsEmpty() || 137 if (output_plane_resource_size.IsEmpty() ||
174 output_plane_resource_size.width() > max_resource_size || 138 output_plane_resource_size.width() > max_resource_size ||
175 output_plane_resource_size.height() > max_resource_size) { 139 output_plane_resource_size.height() > max_resource_size) {
176 allocation_success = false; 140 allocation_success = false;
177 break; 141 break;
178 } 142 }
179 143
180 ResourceProvider::ResourceId resource_id = 0; 144 ResourceProvider::ResourceId resource_id = 0;
181 gpu::Mailbox mailbox; 145 gpu::Mailbox mailbox;
182 146
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
385 } 349 }
386 350
387 PlaneResource recycled_resource(data.resource_id, 351 PlaneResource recycled_resource(data.resource_id,
388 data.resource_size, 352 data.resource_size,
389 data.resource_format, 353 data.resource_format,
390 data.mailbox); 354 data.mailbox);
391 updater->recycled_resources_.push_back(recycled_resource); 355 updater->recycled_resources_.push_back(recycled_resource);
392 } 356 }
393 357
394 } // namespace cc 358 } // namespace cc
OLDNEW
« no previous file with comments | « cc/layers/video_layer_impl.cc ('k') | content/common/gpu/media/android_video_encode_accelerator.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698