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

Side by Side Diff: content/common/gpu/media/vt_video_decode_accelerator_mac.cc

Issue 1745903002: Introduce GpuVideoDecodeAcceleratorFactory. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 <algorithm> 5 #include <algorithm>
6 6
7 #include <CoreVideo/CoreVideo.h> 7 #include <CoreVideo/CoreVideo.h>
8 #include <OpenGL/CGLIOSurface.h> 8 #include <OpenGL/CGLIOSurface.h>
9 #include <OpenGL/gl.h> 9 #include <OpenGL/gl.h>
10 #include <stddef.h> 10 #include <stddef.h>
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after
288 if (lhs->pic_order_cnt != rhs->pic_order_cnt) 288 if (lhs->pic_order_cnt != rhs->pic_order_cnt)
289 return lhs->pic_order_cnt > rhs->pic_order_cnt; 289 return lhs->pic_order_cnt > rhs->pic_order_cnt;
290 // If |pic_order_cnt| is the same, fall back on using the bitstream order. 290 // If |pic_order_cnt| is the same, fall back on using the bitstream order.
291 // TODO(sandersd): Assign a sequence number in Decode() and use that instead. 291 // TODO(sandersd): Assign a sequence number in Decode() and use that instead.
292 // TODO(sandersd): Using the sequence number, ensure that frames older than 292 // TODO(sandersd): Using the sequence number, ensure that frames older than
293 // |kMaxReorderQueueSize| are ordered first, regardless of |pic_order_cnt|. 293 // |kMaxReorderQueueSize| are ordered first, regardless of |pic_order_cnt|.
294 return lhs->bitstream_id > rhs->bitstream_id; 294 return lhs->bitstream_id > rhs->bitstream_id;
295 } 295 }
296 296
297 VTVideoDecodeAccelerator::VTVideoDecodeAccelerator( 297 VTVideoDecodeAccelerator::VTVideoDecodeAccelerator(
298 const base::Callback<bool(void)>& make_context_current, 298 const gpu_vda_helpers::MakeGLContextCurrentCb& make_context_current_cb,
299 const base::Callback<void(uint32_t, uint32_t, scoped_refptr<gl::GLImage>)>& 299 const gpu_vda_helpers::BindGLImageCb& bind_image_cb)
300 bind_image) 300 : make_context_current_cb_(make_context_current_cb),
301 : make_context_current_(make_context_current), 301 bind_image_cb_(bind_image_cb),
302 bind_image_(bind_image),
303 client_(nullptr), 302 client_(nullptr),
304 state_(STATE_DECODING), 303 state_(STATE_DECODING),
305 format_(nullptr), 304 format_(nullptr),
306 session_(nullptr), 305 session_(nullptr),
307 last_sps_id_(-1), 306 last_sps_id_(-1),
308 last_pps_id_(-1), 307 last_pps_id_(-1),
309 config_changed_(false), 308 config_changed_(false),
310 missing_idr_logged_(false), 309 missing_idr_logged_(false),
311 gpu_task_runner_(base::ThreadTaskRunnerHandle::Get()), 310 gpu_task_runner_(base::ThreadTaskRunnerHandle::Get()),
312 decoder_thread_("VTDecoderThread"), 311 decoder_thread_("VTDecoderThread"),
313 weak_this_factory_(this) { 312 weak_this_factory_(this) {
314 DCHECK(!make_context_current_.is_null());
315 callback_.decompressionOutputCallback = OutputThunk; 313 callback_.decompressionOutputCallback = OutputThunk;
316 callback_.decompressionOutputRefCon = this; 314 callback_.decompressionOutputRefCon = this;
317 weak_this_ = weak_this_factory_.GetWeakPtr(); 315 weak_this_ = weak_this_factory_.GetWeakPtr();
318 } 316 }
319 317
320 VTVideoDecodeAccelerator::~VTVideoDecodeAccelerator() { 318 VTVideoDecodeAccelerator::~VTVideoDecodeAccelerator() {
321 DCHECK(gpu_thread_checker_.CalledOnValidThread()); 319 DCHECK(gpu_thread_checker_.CalledOnValidThread());
322 } 320 }
323 321
324 bool VTVideoDecodeAccelerator::Initialize(const Config& config, 322 bool VTVideoDecodeAccelerator::Initialize(const Config& config,
325 Client* client) { 323 Client* client) {
326 DCHECK(gpu_thread_checker_.CalledOnValidThread()); 324 DCHECK(gpu_thread_checker_.CalledOnValidThread());
327 325
326 if (make_context_current_cb_.is_null() || bind_image_cb_.is_null()) {
327 NOTREACHED() << "GL callbacks are required for this VDA";
328 return false;
329 }
330
328 if (config.is_encrypted) { 331 if (config.is_encrypted) {
329 NOTREACHED() << "Encrypted streams are not supported for this VDA"; 332 NOTREACHED() << "Encrypted streams are not supported for this VDA";
330 return false; 333 return false;
331 } 334 }
332 335
333 client_ = client; 336 client_ = client;
334 337
335 if (!InitializeVideoToolbox()) 338 if (!InitializeVideoToolbox())
336 return false; 339 return false;
337 340
(...skipping 692 matching lines...) Expand 10 before | Expand all | Expand 10 after
1030 1033
1031 if (available_picture_ids_.empty()) 1034 if (available_picture_ids_.empty())
1032 return false; 1035 return false;
1033 1036
1034 int32_t picture_id = available_picture_ids_.back(); 1037 int32_t picture_id = available_picture_ids_.back();
1035 DCHECK(picture_info_map_.count(picture_id)); 1038 DCHECK(picture_info_map_.count(picture_id));
1036 PictureInfo* picture_info = picture_info_map_.find(picture_id)->second.get(); 1039 PictureInfo* picture_info = picture_info_map_.find(picture_id)->second.get();
1037 DCHECK(!picture_info->cv_image); 1040 DCHECK(!picture_info->cv_image);
1038 DCHECK(!picture_info->gl_image); 1041 DCHECK(!picture_info->gl_image);
1039 1042
1040 if (!make_context_current_.Run()) { 1043 if (!make_context_current_cb_.Run()) {
1041 DLOG(ERROR) << "Failed to make GL context current"; 1044 DLOG(ERROR) << "Failed to make GL context current";
1042 NotifyError(PLATFORM_FAILURE, SFT_PLATFORM_ERROR); 1045 NotifyError(PLATFORM_FAILURE, SFT_PLATFORM_ERROR);
1043 return false; 1046 return false;
1044 } 1047 }
1045 1048
1046 IOSurfaceRef surface = CVPixelBufferGetIOSurface(frame.image.get()); 1049 IOSurfaceRef surface = CVPixelBufferGetIOSurface(frame.image.get());
1047 if (gfx::GetGLImplementation() != gfx::kGLImplementationDesktopGLCoreProfile) 1050 if (gfx::GetGLImplementation() != gfx::kGLImplementationDesktopGLCoreProfile)
1048 glEnable(GL_TEXTURE_RECTANGLE_ARB); 1051 glEnable(GL_TEXTURE_RECTANGLE_ARB);
1049 gfx::ScopedTextureBinder texture_binder(GL_TEXTURE_RECTANGLE_ARB, 1052 gfx::ScopedTextureBinder texture_binder(GL_TEXTURE_RECTANGLE_ARB,
1050 picture_info->service_texture_id); 1053 picture_info->service_texture_id);
(...skipping 18 matching lines...) Expand all
1069 1072
1070 bool allow_overlay = false; 1073 bool allow_overlay = false;
1071 scoped_refptr<gl::GLImageIOSurface> gl_image( 1074 scoped_refptr<gl::GLImageIOSurface> gl_image(
1072 new gl::GLImageIOSurface(frame.coded_size, GL_BGRA_EXT)); 1075 new gl::GLImageIOSurface(frame.coded_size, GL_BGRA_EXT));
1073 if (gl_image->Initialize(surface, gfx::GenericSharedMemoryId(), 1076 if (gl_image->Initialize(surface, gfx::GenericSharedMemoryId(),
1074 gfx::BufferFormat::BGRA_8888)) { 1077 gfx::BufferFormat::BGRA_8888)) {
1075 allow_overlay = true; 1078 allow_overlay = true;
1076 } else { 1079 } else {
1077 gl_image = nullptr; 1080 gl_image = nullptr;
1078 } 1081 }
1079 bind_image_.Run(picture_info->client_texture_id, GL_TEXTURE_RECTANGLE_ARB, 1082 if (!bind_image_cb_.Run(picture_info->client_texture_id,
1080 gl_image); 1083 GL_TEXTURE_RECTANGLE_ARB, gl_image)) {
1084 DLOG(ERROR) << "Failed to bind image";
1085 NotifyError(PLATFORM_FAILURE, SFT_PLATFORM_ERROR);
1086 return false;
1087 }
1081 1088
1082 // Assign the new image(s) to the the picture info. 1089 // Assign the new image(s) to the the picture info.
1083 picture_info->gl_image = gl_image; 1090 picture_info->gl_image = gl_image;
1084 picture_info->cv_image = frame.image; 1091 picture_info->cv_image = frame.image;
1085 available_picture_ids_.pop_back(); 1092 available_picture_ids_.pop_back();
1086 1093
1087 // TODO(sandersd): Currently, the size got from 1094 // TODO(sandersd): Currently, the size got from
1088 // CMVideoFormatDescriptionGetDimensions is visible size. We pass it to 1095 // CMVideoFormatDescriptionGetDimensions is visible size. We pass it to
1089 // GpuVideoDecoder so that GpuVideoDecoder can use correct visible size in 1096 // GpuVideoDecoder so that GpuVideoDecoder can use correct visible size in
1090 // resolution changed. We should find the correct API to get the real 1097 // resolution changed. We should find the correct API to get the real
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
1147 // destructing |this|. 1154 // destructing |this|.
1148 // TODO(sandersd): Prevent the decoder from reading buffers before discarding 1155 // TODO(sandersd): Prevent the decoder from reading buffers before discarding
1149 // them. 1156 // them.
1150 for (int32_t bitstream_id : assigned_bitstream_ids_) 1157 for (int32_t bitstream_id : assigned_bitstream_ids_)
1151 client_->NotifyEndOfBitstreamBuffer(bitstream_id); 1158 client_->NotifyEndOfBitstreamBuffer(bitstream_id);
1152 assigned_bitstream_ids_.clear(); 1159 assigned_bitstream_ids_.clear();
1153 state_ = STATE_DESTROYING; 1160 state_ = STATE_DESTROYING;
1154 QueueFlush(TASK_DESTROY); 1161 QueueFlush(TASK_DESTROY);
1155 } 1162 }
1156 1163
1157 bool VTVideoDecodeAccelerator::CanDecodeOnIOThread() { 1164 bool VTVideoDecodeAccelerator::TryInitializeDecodeOnSeparateThread(
1165 const base::WeakPtr<Client>& decode_client,
1166 const scoped_refptr<base::SingleThreadTaskRunner>& decode_task_runner) {
1158 return false; 1167 return false;
1159 } 1168 }
1160 1169
1161 // static 1170 // static
1162 media::VideoDecodeAccelerator::SupportedProfiles 1171 media::VideoDecodeAccelerator::SupportedProfiles
1163 VTVideoDecodeAccelerator::GetSupportedProfiles() { 1172 VTVideoDecodeAccelerator::GetSupportedProfiles() {
1164 SupportedProfiles profiles; 1173 SupportedProfiles profiles;
1165 for (const auto& supported_profile : kSupportedProfiles) { 1174 for (const auto& supported_profile : kSupportedProfiles) {
1166 SupportedProfile profile; 1175 SupportedProfile profile;
1167 profile.profile = supported_profile; 1176 profile.profile = supported_profile;
1168 profile.min_resolution.SetSize(16, 16); 1177 profile.min_resolution.SetSize(16, 16);
1169 profile.max_resolution.SetSize(4096, 2160); 1178 profile.max_resolution.SetSize(4096, 2160);
1170 profiles.push_back(profile); 1179 profiles.push_back(profile);
1171 } 1180 }
1172 return profiles; 1181 return profiles;
1173 } 1182 }
1174 1183
1175 } // namespace content 1184 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698