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