OLD | NEW |
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 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
279 if (lhs->pic_order_cnt != rhs->pic_order_cnt) | 279 if (lhs->pic_order_cnt != rhs->pic_order_cnt) |
280 return lhs->pic_order_cnt > rhs->pic_order_cnt; | 280 return lhs->pic_order_cnt > rhs->pic_order_cnt; |
281 // If |pic_order_cnt| is the same, fall back on using the bitstream order. | 281 // If |pic_order_cnt| is the same, fall back on using the bitstream order. |
282 // TODO(sandersd): Assign a sequence number in Decode() and use that instead. | 282 // TODO(sandersd): Assign a sequence number in Decode() and use that instead. |
283 // TODO(sandersd): Using the sequence number, ensure that frames older than | 283 // TODO(sandersd): Using the sequence number, ensure that frames older than |
284 // |kMaxReorderQueueSize| are ordered first, regardless of |pic_order_cnt|. | 284 // |kMaxReorderQueueSize| are ordered first, regardless of |pic_order_cnt|. |
285 return lhs->bitstream_id > rhs->bitstream_id; | 285 return lhs->bitstream_id > rhs->bitstream_id; |
286 } | 286 } |
287 | 287 |
288 VTVideoDecodeAccelerator::VTVideoDecodeAccelerator( | 288 VTVideoDecodeAccelerator::VTVideoDecodeAccelerator( |
289 const MakeContextCurrentCallback& make_context_current, | 289 const MakeGLContextCurrentCallback& make_context_current_cb, |
290 const BindImageCallback& bind_image) | 290 const BindGLImageCallback& bind_image_cb) |
291 : make_context_current_(make_context_current), | 291 : make_context_current_cb_(make_context_current_cb), |
292 bind_image_(bind_image), | 292 bind_image_cb_(bind_image_cb), |
293 client_(nullptr), | 293 client_(nullptr), |
294 state_(STATE_DECODING), | 294 state_(STATE_DECODING), |
295 format_(nullptr), | 295 format_(nullptr), |
296 session_(nullptr), | 296 session_(nullptr), |
297 last_sps_id_(-1), | 297 last_sps_id_(-1), |
298 last_pps_id_(-1), | 298 last_pps_id_(-1), |
299 config_changed_(false), | 299 config_changed_(false), |
300 missing_idr_logged_(false), | 300 missing_idr_logged_(false), |
301 gpu_task_runner_(base::ThreadTaskRunnerHandle::Get()), | 301 gpu_task_runner_(base::ThreadTaskRunnerHandle::Get()), |
302 decoder_thread_("VTDecoderThread"), | 302 decoder_thread_("VTDecoderThread"), |
303 weak_this_factory_(this) { | 303 weak_this_factory_(this) { |
304 DCHECK(!make_context_current_.is_null()); | |
305 callback_.decompressionOutputCallback = OutputThunk; | 304 callback_.decompressionOutputCallback = OutputThunk; |
306 callback_.decompressionOutputRefCon = this; | 305 callback_.decompressionOutputRefCon = this; |
307 weak_this_ = weak_this_factory_.GetWeakPtr(); | 306 weak_this_ = weak_this_factory_.GetWeakPtr(); |
308 } | 307 } |
309 | 308 |
310 VTVideoDecodeAccelerator::~VTVideoDecodeAccelerator() { | 309 VTVideoDecodeAccelerator::~VTVideoDecodeAccelerator() { |
311 DCHECK(gpu_thread_checker_.CalledOnValidThread()); | 310 DCHECK(gpu_thread_checker_.CalledOnValidThread()); |
312 } | 311 } |
313 | 312 |
314 bool VTVideoDecodeAccelerator::Initialize(const Config& config, | 313 bool VTVideoDecodeAccelerator::Initialize(const Config& config, |
315 Client* client) { | 314 Client* client) { |
316 DCHECK(gpu_thread_checker_.CalledOnValidThread()); | 315 DCHECK(gpu_thread_checker_.CalledOnValidThread()); |
317 | 316 |
| 317 if (make_context_current_cb_.is_null() || bind_image_cb_.is_null()) { |
| 318 NOTREACHED() << "GL callbacks are required for this VDA"; |
| 319 return false; |
| 320 } |
| 321 |
318 if (config.is_encrypted) { | 322 if (config.is_encrypted) { |
319 NOTREACHED() << "Encrypted streams are not supported for this VDA"; | 323 NOTREACHED() << "Encrypted streams are not supported for this VDA"; |
320 return false; | 324 return false; |
321 } | 325 } |
322 | 326 |
323 client_ = client; | 327 client_ = client; |
324 | 328 |
325 if (!InitializeVideoToolbox()) | 329 if (!InitializeVideoToolbox()) |
326 return false; | 330 return false; |
327 | 331 |
(...skipping 692 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1020 | 1024 |
1021 if (available_picture_ids_.empty()) | 1025 if (available_picture_ids_.empty()) |
1022 return false; | 1026 return false; |
1023 | 1027 |
1024 int32_t picture_id = available_picture_ids_.back(); | 1028 int32_t picture_id = available_picture_ids_.back(); |
1025 DCHECK(picture_info_map_.count(picture_id)); | 1029 DCHECK(picture_info_map_.count(picture_id)); |
1026 PictureInfo* picture_info = picture_info_map_.find(picture_id)->second.get(); | 1030 PictureInfo* picture_info = picture_info_map_.find(picture_id)->second.get(); |
1027 DCHECK(!picture_info->cv_image); | 1031 DCHECK(!picture_info->cv_image); |
1028 DCHECK(!picture_info->gl_image); | 1032 DCHECK(!picture_info->gl_image); |
1029 | 1033 |
1030 if (!make_context_current_.Run()) { | 1034 if (!make_context_current_cb_.Run()) { |
1031 DLOG(ERROR) << "Failed to make GL context current"; | 1035 DLOG(ERROR) << "Failed to make GL context current"; |
1032 NotifyError(PLATFORM_FAILURE, SFT_PLATFORM_ERROR); | 1036 NotifyError(PLATFORM_FAILURE, SFT_PLATFORM_ERROR); |
1033 return false; | 1037 return false; |
1034 } | 1038 } |
1035 | 1039 |
1036 IOSurfaceRef io_surface = CVPixelBufferGetIOSurface(frame.image.get()); | 1040 IOSurfaceRef io_surface = CVPixelBufferGetIOSurface(frame.image.get()); |
1037 | 1041 |
1038 scoped_refptr<gl::GLImageIOSurface> gl_image( | 1042 scoped_refptr<gl::GLImageIOSurface> gl_image( |
1039 new gl::GLImageIOSurface(frame.coded_size, GL_BGRA_EXT)); | 1043 new gl::GLImageIOSurface(frame.coded_size, GL_BGRA_EXT)); |
1040 if (!gl_image->Initialize(io_surface, gfx::GenericSharedMemoryId(), | 1044 if (!gl_image->Initialize(io_surface, gfx::GenericSharedMemoryId(), |
1041 gfx::BufferFormat::YUV_420_BIPLANAR)) { | 1045 gfx::BufferFormat::YUV_420_BIPLANAR)) { |
1042 NOTIFY_STATUS("Failed to initialize GLImageIOSurface", PLATFORM_FAILURE, | 1046 NOTIFY_STATUS("Failed to initialize GLImageIOSurface", PLATFORM_FAILURE, |
1043 SFT_PLATFORM_ERROR); | 1047 SFT_PLATFORM_ERROR); |
1044 } | 1048 } |
1045 | 1049 |
1046 bind_image_.Run(picture_info->client_texture_id, GL_TEXTURE_RECTANGLE_ARB, | 1050 if (!bind_image_cb_.Run(picture_info->client_texture_id, |
1047 gl_image, false); | 1051 GL_TEXTURE_RECTANGLE_ARB, gl_image, false)) { |
| 1052 DLOG(ERROR) << "Failed to bind image"; |
| 1053 NotifyError(PLATFORM_FAILURE, SFT_PLATFORM_ERROR); |
| 1054 return false; |
| 1055 } |
1048 | 1056 |
1049 // Assign the new image(s) to the the picture info. | 1057 // Assign the new image(s) to the the picture info. |
1050 picture_info->gl_image = gl_image; | 1058 picture_info->gl_image = gl_image; |
1051 picture_info->cv_image = frame.image; | 1059 picture_info->cv_image = frame.image; |
1052 available_picture_ids_.pop_back(); | 1060 available_picture_ids_.pop_back(); |
1053 | 1061 |
1054 // TODO(sandersd): Currently, the size got from | 1062 // TODO(sandersd): Currently, the size got from |
1055 // CMVideoFormatDescriptionGetDimensions is visible size. We pass it to | 1063 // CMVideoFormatDescriptionGetDimensions is visible size. We pass it to |
1056 // GpuVideoDecoder so that GpuVideoDecoder can use correct visible size in | 1064 // GpuVideoDecoder so that GpuVideoDecoder can use correct visible size in |
1057 // resolution changed. We should find the correct API to get the real | 1065 // resolution changed. We should find the correct API to get the real |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1114 // destructing |this|. | 1122 // destructing |this|. |
1115 // TODO(sandersd): Prevent the decoder from reading buffers before discarding | 1123 // TODO(sandersd): Prevent the decoder from reading buffers before discarding |
1116 // them. | 1124 // them. |
1117 for (int32_t bitstream_id : assigned_bitstream_ids_) | 1125 for (int32_t bitstream_id : assigned_bitstream_ids_) |
1118 client_->NotifyEndOfBitstreamBuffer(bitstream_id); | 1126 client_->NotifyEndOfBitstreamBuffer(bitstream_id); |
1119 assigned_bitstream_ids_.clear(); | 1127 assigned_bitstream_ids_.clear(); |
1120 state_ = STATE_DESTROYING; | 1128 state_ = STATE_DESTROYING; |
1121 QueueFlush(TASK_DESTROY); | 1129 QueueFlush(TASK_DESTROY); |
1122 } | 1130 } |
1123 | 1131 |
1124 bool VTVideoDecodeAccelerator::CanDecodeOnIOThread() { | 1132 bool VTVideoDecodeAccelerator::TryToSetupDecodeOnSeparateThread( |
| 1133 const base::WeakPtr<Client>& decode_client, |
| 1134 const scoped_refptr<base::SingleThreadTaskRunner>& decode_task_runner) { |
1125 return false; | 1135 return false; |
1126 } | 1136 } |
1127 | 1137 |
1128 // static | 1138 // static |
1129 media::VideoDecodeAccelerator::SupportedProfiles | 1139 media::VideoDecodeAccelerator::SupportedProfiles |
1130 VTVideoDecodeAccelerator::GetSupportedProfiles() { | 1140 VTVideoDecodeAccelerator::GetSupportedProfiles() { |
1131 SupportedProfiles profiles; | 1141 SupportedProfiles profiles; |
1132 for (const auto& supported_profile : kSupportedProfiles) { | 1142 for (const auto& supported_profile : kSupportedProfiles) { |
1133 SupportedProfile profile; | 1143 SupportedProfile profile; |
1134 profile.profile = supported_profile; | 1144 profile.profile = supported_profile; |
1135 profile.min_resolution.SetSize(16, 16); | 1145 profile.min_resolution.SetSize(16, 16); |
1136 profile.max_resolution.SetSize(4096, 2160); | 1146 profile.max_resolution.SetSize(4096, 2160); |
1137 profiles.push_back(profile); | 1147 profiles.push_back(profile); |
1138 } | 1148 } |
1139 return profiles; | 1149 return profiles; |
1140 } | 1150 } |
1141 | 1151 |
1142 } // namespace content | 1152 } // namespace content |
OLD | NEW |