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