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 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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()); | 313 DCHECK(!make_context_current_cb_.is_null()); |
kcwu
2016/03/02 07:52:45
Remove this? It is checked in Initialize().
Pawel Osciak
2016/03/02 08:16:52
Done.
| |
315 callback_.decompressionOutputCallback = OutputThunk; | 314 callback_.decompressionOutputCallback = OutputThunk; |
316 callback_.decompressionOutputRefCon = this; | 315 callback_.decompressionOutputRefCon = this; |
317 weak_this_ = weak_this_factory_.GetWeakPtr(); | 316 weak_this_ = weak_this_factory_.GetWeakPtr(); |
318 } | 317 } |
319 | 318 |
320 VTVideoDecodeAccelerator::~VTVideoDecodeAccelerator() { | 319 VTVideoDecodeAccelerator::~VTVideoDecodeAccelerator() { |
321 DCHECK(gpu_thread_checker_.CalledOnValidThread()); | 320 DCHECK(gpu_thread_checker_.CalledOnValidThread()); |
322 } | 321 } |
323 | 322 |
324 bool VTVideoDecodeAccelerator::Initialize(const Config& config, | 323 bool VTVideoDecodeAccelerator::Initialize(const Config& config, |
325 Client* client) { | 324 Client* client) { |
326 DCHECK(gpu_thread_checker_.CalledOnValidThread()); | 325 DCHECK(gpu_thread_checker_.CalledOnValidThread()); |
327 | 326 |
327 if (make_context_current_cb_.is_null() || bind_image_cb_.is_null()) { | |
328 NOTREACHED() << "GL callbacks are required for this VDA"; | |
329 return false; | |
330 } | |
331 | |
328 if (config.is_encrypted) { | 332 if (config.is_encrypted) { |
329 NOTREACHED() << "Encrypted streams are not supported for this VDA"; | 333 NOTREACHED() << "Encrypted streams are not supported for this VDA"; |
330 return false; | 334 return false; |
331 } | 335 } |
332 | 336 |
333 client_ = client; | 337 client_ = client; |
334 | 338 |
335 if (!InitializeVideoToolbox()) | 339 if (!InitializeVideoToolbox()) |
336 return false; | 340 return false; |
337 | 341 |
(...skipping 692 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1030 | 1034 |
1031 if (available_picture_ids_.empty()) | 1035 if (available_picture_ids_.empty()) |
1032 return false; | 1036 return false; |
1033 | 1037 |
1034 int32_t picture_id = available_picture_ids_.back(); | 1038 int32_t picture_id = available_picture_ids_.back(); |
1035 DCHECK(picture_info_map_.count(picture_id)); | 1039 DCHECK(picture_info_map_.count(picture_id)); |
1036 PictureInfo* picture_info = picture_info_map_.find(picture_id)->second.get(); | 1040 PictureInfo* picture_info = picture_info_map_.find(picture_id)->second.get(); |
1037 DCHECK(!picture_info->cv_image); | 1041 DCHECK(!picture_info->cv_image); |
1038 DCHECK(!picture_info->gl_image); | 1042 DCHECK(!picture_info->gl_image); |
1039 | 1043 |
1040 if (!make_context_current_.Run()) { | 1044 if (!make_context_current_cb_.Run()) { |
1041 DLOG(ERROR) << "Failed to make GL context current"; | 1045 DLOG(ERROR) << "Failed to make GL context current"; |
1042 NotifyError(PLATFORM_FAILURE, SFT_PLATFORM_ERROR); | 1046 NotifyError(PLATFORM_FAILURE, SFT_PLATFORM_ERROR); |
1043 return false; | 1047 return false; |
1044 } | 1048 } |
1045 | 1049 |
1046 IOSurfaceRef surface = CVPixelBufferGetIOSurface(frame.image.get()); | 1050 IOSurfaceRef surface = CVPixelBufferGetIOSurface(frame.image.get()); |
1047 if (gfx::GetGLImplementation() != gfx::kGLImplementationDesktopGLCoreProfile) | 1051 if (gfx::GetGLImplementation() != gfx::kGLImplementationDesktopGLCoreProfile) |
1048 glEnable(GL_TEXTURE_RECTANGLE_ARB); | 1052 glEnable(GL_TEXTURE_RECTANGLE_ARB); |
1049 gfx::ScopedTextureBinder texture_binder(GL_TEXTURE_RECTANGLE_ARB, | 1053 gfx::ScopedTextureBinder texture_binder(GL_TEXTURE_RECTANGLE_ARB, |
1050 picture_info->service_texture_id); | 1054 picture_info->service_texture_id); |
(...skipping 18 matching lines...) Expand all Loading... | |
1069 | 1073 |
1070 bool allow_overlay = false; | 1074 bool allow_overlay = false; |
1071 scoped_refptr<gl::GLImageIOSurface> gl_image( | 1075 scoped_refptr<gl::GLImageIOSurface> gl_image( |
1072 new gl::GLImageIOSurface(frame.coded_size, GL_BGRA_EXT)); | 1076 new gl::GLImageIOSurface(frame.coded_size, GL_BGRA_EXT)); |
1073 if (gl_image->Initialize(surface, gfx::GenericSharedMemoryId(), | 1077 if (gl_image->Initialize(surface, gfx::GenericSharedMemoryId(), |
1074 gfx::BufferFormat::BGRA_8888)) { | 1078 gfx::BufferFormat::BGRA_8888)) { |
1075 allow_overlay = true; | 1079 allow_overlay = true; |
1076 } else { | 1080 } else { |
1077 gl_image = nullptr; | 1081 gl_image = nullptr; |
1078 } | 1082 } |
1079 bind_image_.Run(picture_info->client_texture_id, GL_TEXTURE_RECTANGLE_ARB, | 1083 if (!bind_image_cb_.Run(picture_info->client_texture_id, |
1080 gl_image); | 1084 GL_TEXTURE_RECTANGLE_ARB, gl_image)) { |
1085 DLOG(ERROR) << "Failed to bind image"; | |
1086 NotifyError(PLATFORM_FAILURE, SFT_PLATFORM_ERROR); | |
1087 return false; | |
1088 } | |
1081 | 1089 |
1082 // Assign the new image(s) to the the picture info. | 1090 // Assign the new image(s) to the the picture info. |
1083 picture_info->gl_image = gl_image; | 1091 picture_info->gl_image = gl_image; |
1084 picture_info->cv_image = frame.image; | 1092 picture_info->cv_image = frame.image; |
1085 available_picture_ids_.pop_back(); | 1093 available_picture_ids_.pop_back(); |
1086 | 1094 |
1087 // TODO(sandersd): Currently, the size got from | 1095 // TODO(sandersd): Currently, the size got from |
1088 // CMVideoFormatDescriptionGetDimensions is visible size. We pass it to | 1096 // CMVideoFormatDescriptionGetDimensions is visible size. We pass it to |
1089 // GpuVideoDecoder so that GpuVideoDecoder can use correct visible size in | 1097 // GpuVideoDecoder so that GpuVideoDecoder can use correct visible size in |
1090 // resolution changed. We should find the correct API to get the real | 1098 // 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... | |
1147 // destructing |this|. | 1155 // destructing |this|. |
1148 // TODO(sandersd): Prevent the decoder from reading buffers before discarding | 1156 // TODO(sandersd): Prevent the decoder from reading buffers before discarding |
1149 // them. | 1157 // them. |
1150 for (int32_t bitstream_id : assigned_bitstream_ids_) | 1158 for (int32_t bitstream_id : assigned_bitstream_ids_) |
1151 client_->NotifyEndOfBitstreamBuffer(bitstream_id); | 1159 client_->NotifyEndOfBitstreamBuffer(bitstream_id); |
1152 assigned_bitstream_ids_.clear(); | 1160 assigned_bitstream_ids_.clear(); |
1153 state_ = STATE_DESTROYING; | 1161 state_ = STATE_DESTROYING; |
1154 QueueFlush(TASK_DESTROY); | 1162 QueueFlush(TASK_DESTROY); |
1155 } | 1163 } |
1156 | 1164 |
1157 bool VTVideoDecodeAccelerator::CanDecodeOnIOThread() { | 1165 bool VTVideoDecodeAccelerator::TryInitializeDecodeOnSeparateThread( |
1166 const base::WeakPtr<Client>& decode_client, | |
1167 const scoped_refptr<base::SingleThreadTaskRunner>& decode_task_runner) { | |
1158 return false; | 1168 return false; |
1159 } | 1169 } |
1160 | 1170 |
1161 // static | 1171 // static |
1162 media::VideoDecodeAccelerator::SupportedProfiles | 1172 media::VideoDecodeAccelerator::SupportedProfiles |
1163 VTVideoDecodeAccelerator::GetSupportedProfiles() { | 1173 VTVideoDecodeAccelerator::GetSupportedProfiles() { |
1164 SupportedProfiles profiles; | 1174 SupportedProfiles profiles; |
1165 for (const auto& supported_profile : kSupportedProfiles) { | 1175 for (const auto& supported_profile : kSupportedProfiles) { |
1166 SupportedProfile profile; | 1176 SupportedProfile profile; |
1167 profile.profile = supported_profile; | 1177 profile.profile = supported_profile; |
1168 profile.min_resolution.SetSize(16, 16); | 1178 profile.min_resolution.SetSize(16, 16); |
1169 profile.max_resolution.SetSize(4096, 2160); | 1179 profile.max_resolution.SetSize(4096, 2160); |
1170 profiles.push_back(profile); | 1180 profiles.push_back(profile); |
1171 } | 1181 } |
1172 return profiles; | 1182 return profiles; |
1173 } | 1183 } |
1174 | 1184 |
1175 } // namespace content | 1185 } // namespace content |
OLD | NEW |