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

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 MakeGLContextCurrentCallback& make_context_current_cb,
299 const base::Callback<void(uint32_t, uint32_t, scoped_refptr<gl::GLImage>)>& 299 const BindGLImageCallback& 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 690 matching lines...) Expand 10 before | Expand all | Expand 10 after
1028 1031
1029 if (available_picture_ids_.empty()) 1032 if (available_picture_ids_.empty())
1030 return false; 1033 return false;
1031 1034
1032 int32_t picture_id = available_picture_ids_.back(); 1035 int32_t picture_id = available_picture_ids_.back();
1033 DCHECK(picture_info_map_.count(picture_id)); 1036 DCHECK(picture_info_map_.count(picture_id));
1034 PictureInfo* picture_info = picture_info_map_.find(picture_id)->second.get(); 1037 PictureInfo* picture_info = picture_info_map_.find(picture_id)->second.get();
1035 DCHECK(!picture_info->cv_image); 1038 DCHECK(!picture_info->cv_image);
1036 DCHECK(!picture_info->gl_image); 1039 DCHECK(!picture_info->gl_image);
1037 1040
1038 if (!make_context_current_.Run()) { 1041 if (!make_context_current_cb_.Run()) {
1039 DLOG(ERROR) << "Failed to make GL context current"; 1042 DLOG(ERROR) << "Failed to make GL context current";
1040 NotifyError(PLATFORM_FAILURE, SFT_PLATFORM_ERROR); 1043 NotifyError(PLATFORM_FAILURE, SFT_PLATFORM_ERROR);
1041 return false; 1044 return false;
1042 } 1045 }
1043 1046
1044 IOSurfaceRef surface = CVPixelBufferGetIOSurface(frame.image.get()); 1047 IOSurfaceRef surface = CVPixelBufferGetIOSurface(frame.image.get());
1045 if (gfx::GetGLImplementation() != gfx::kGLImplementationDesktopGLCoreProfile) 1048 if (gfx::GetGLImplementation() != gfx::kGLImplementationDesktopGLCoreProfile)
1046 glEnable(GL_TEXTURE_RECTANGLE_ARB); 1049 glEnable(GL_TEXTURE_RECTANGLE_ARB);
1047 gfx::ScopedTextureBinder texture_binder(GL_TEXTURE_RECTANGLE_ARB, 1050 gfx::ScopedTextureBinder texture_binder(GL_TEXTURE_RECTANGLE_ARB,
1048 picture_info->service_texture_id); 1051 picture_info->service_texture_id);
(...skipping 18 matching lines...) Expand all
1067 1070
1068 bool allow_overlay = false; 1071 bool allow_overlay = false;
1069 scoped_refptr<gl::GLImageIOSurface> gl_image( 1072 scoped_refptr<gl::GLImageIOSurface> gl_image(
1070 new gl::GLImageIOSurface(frame.coded_size, GL_BGRA_EXT)); 1073 new gl::GLImageIOSurface(frame.coded_size, GL_BGRA_EXT));
1071 if (gl_image->Initialize(surface, gfx::GenericSharedMemoryId(), 1074 if (gl_image->Initialize(surface, gfx::GenericSharedMemoryId(),
1072 gfx::BufferFormat::BGRA_8888)) { 1075 gfx::BufferFormat::BGRA_8888)) {
1073 allow_overlay = true; 1076 allow_overlay = true;
1074 } else { 1077 } else {
1075 gl_image = nullptr; 1078 gl_image = nullptr;
1076 } 1079 }
1077 bind_image_.Run(picture_info->client_texture_id, GL_TEXTURE_RECTANGLE_ARB, 1080 if (!bind_image_cb_.Run(picture_info->client_texture_id,
1078 gl_image); 1081 GL_TEXTURE_RECTANGLE_ARB, gl_image)) {
1082 DLOG(ERROR) << "Failed to bind image";
1083 NotifyError(PLATFORM_FAILURE, SFT_PLATFORM_ERROR);
1084 return false;
1085 }
1079 1086
1080 // Assign the new image(s) to the the picture info. 1087 // Assign the new image(s) to the the picture info.
1081 picture_info->gl_image = gl_image; 1088 picture_info->gl_image = gl_image;
1082 picture_info->cv_image = frame.image; 1089 picture_info->cv_image = frame.image;
1083 available_picture_ids_.pop_back(); 1090 available_picture_ids_.pop_back();
1084 1091
1085 // TODO(sandersd): Currently, the size got from 1092 // TODO(sandersd): Currently, the size got from
1086 // CMVideoFormatDescriptionGetDimensions is visible size. We pass it to 1093 // CMVideoFormatDescriptionGetDimensions is visible size. We pass it to
1087 // GpuVideoDecoder so that GpuVideoDecoder can use correct visible size in 1094 // GpuVideoDecoder so that GpuVideoDecoder can use correct visible size in
1088 // resolution changed. We should find the correct API to get the real 1095 // resolution changed. We should find the correct API to get the real
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
1145 // destructing |this|. 1152 // destructing |this|.
1146 // TODO(sandersd): Prevent the decoder from reading buffers before discarding 1153 // TODO(sandersd): Prevent the decoder from reading buffers before discarding
1147 // them. 1154 // them.
1148 for (int32_t bitstream_id : assigned_bitstream_ids_) 1155 for (int32_t bitstream_id : assigned_bitstream_ids_)
1149 client_->NotifyEndOfBitstreamBuffer(bitstream_id); 1156 client_->NotifyEndOfBitstreamBuffer(bitstream_id);
1150 assigned_bitstream_ids_.clear(); 1157 assigned_bitstream_ids_.clear();
1151 state_ = STATE_DESTROYING; 1158 state_ = STATE_DESTROYING;
1152 QueueFlush(TASK_DESTROY); 1159 QueueFlush(TASK_DESTROY);
1153 } 1160 }
1154 1161
1155 bool VTVideoDecodeAccelerator::CanDecodeOnIOThread() { 1162 bool VTVideoDecodeAccelerator::TryToSetupDecodeOnSeparateThread(
1163 const base::WeakPtr<Client>& decode_client,
1164 const scoped_refptr<base::SingleThreadTaskRunner>& decode_task_runner) {
1156 return false; 1165 return false;
1157 } 1166 }
1158 1167
1159 // static 1168 // static
1160 media::VideoDecodeAccelerator::SupportedProfiles 1169 media::VideoDecodeAccelerator::SupportedProfiles
1161 VTVideoDecodeAccelerator::GetSupportedProfiles() { 1170 VTVideoDecodeAccelerator::GetSupportedProfiles() {
1162 SupportedProfiles profiles; 1171 SupportedProfiles profiles;
1163 for (const auto& supported_profile : kSupportedProfiles) { 1172 for (const auto& supported_profile : kSupportedProfiles) {
1164 SupportedProfile profile; 1173 SupportedProfile profile;
1165 profile.profile = supported_profile; 1174 profile.profile = supported_profile;
1166 profile.min_resolution.SetSize(16, 16); 1175 profile.min_resolution.SetSize(16, 16);
1167 profile.max_resolution.SetSize(4096, 2160); 1176 profile.max_resolution.SetSize(4096, 2160);
1168 profiles.push_back(profile); 1177 profiles.push_back(profile);
1169 } 1178 }
1170 return profiles; 1179 return profiles;
1171 } 1180 }
1172 1181
1173 } // namespace content 1182 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698