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

Side by Side Diff: content/common/gpu/media/vt_video_decode_accelerator_mac.cc

Issue 1851163003: Mac h264: Use GLImageIOSurface to bind frames to textures (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 1018 matching lines...) Expand 10 before | Expand all | Expand 10 after
1029 PictureInfo* picture_info = picture_info_map_.find(picture_id)->second.get(); 1029 PictureInfo* picture_info = picture_info_map_.find(picture_id)->second.get();
1030 DCHECK(!picture_info->cv_image); 1030 DCHECK(!picture_info->cv_image);
1031 DCHECK(!picture_info->gl_image); 1031 DCHECK(!picture_info->gl_image);
1032 1032
1033 if (!make_context_current_.Run()) { 1033 if (!make_context_current_.Run()) {
1034 DLOG(ERROR) << "Failed to make GL context current"; 1034 DLOG(ERROR) << "Failed to make GL context current";
1035 NotifyError(PLATFORM_FAILURE, SFT_PLATFORM_ERROR); 1035 NotifyError(PLATFORM_FAILURE, SFT_PLATFORM_ERROR);
1036 return false; 1036 return false;
1037 } 1037 }
1038 1038
1039 IOSurfaceRef surface = CVPixelBufferGetIOSurface(frame.image.get()); 1039 IOSurfaceRef io_surface = CVPixelBufferGetIOSurface(frame.image.get());
1040
1041 scoped_refptr<gl::GLImageIOSurface> gl_image(
1042 new gl::GLImageIOSurface(frame.coded_size, GL_BGRA_EXT));
1043 if (!gl_image->Initialize(io_surface, gfx::GenericSharedMemoryId(),
1044 gfx::BufferFormat::UYVY_422)) {
1045 NOTIFY_STATUS("Failed to initialize GLImageIOSurface", PLATFORM_FAILURE,
1046 SFT_PLATFORM_ERROR);
1047 }
1048
1040 if (gfx::GetGLImplementation() != gfx::kGLImplementationDesktopGLCoreProfile) 1049 if (gfx::GetGLImplementation() != gfx::kGLImplementationDesktopGLCoreProfile)
1041 glEnable(GL_TEXTURE_RECTANGLE_ARB); 1050 glEnable(GL_TEXTURE_RECTANGLE_ARB);
1042 gfx::ScopedTextureBinder texture_binder(GL_TEXTURE_RECTANGLE_ARB, 1051 gfx::ScopedTextureBinder texture_binder(GL_TEXTURE_RECTANGLE_ARB,
1043 picture_info->service_texture_id); 1052 picture_info->service_texture_id);
1044 CGLContextObj cgl_context = 1053 bool bind_result = gl_image->BindTexImage(GL_TEXTURE_RECTANGLE_ARB);
1045 static_cast<CGLContextObj>(gfx::GLContext::GetCurrent()->GetHandle());
1046 CGLError status = CGLTexImageIOSurface2D(
1047 cgl_context, // ctx
1048 GL_TEXTURE_RECTANGLE_ARB, // target
1049 GL_RGB, // internal_format
1050 frame.coded_size.width(), // width
1051 frame.coded_size.height(), // height
1052 GL_YCBCR_422_APPLE, // format
1053 GL_UNSIGNED_SHORT_8_8_APPLE, // type
1054 surface, // io_surface
1055 0); // plane
1056 if (gfx::GetGLImplementation() != gfx::kGLImplementationDesktopGLCoreProfile) 1054 if (gfx::GetGLImplementation() != gfx::kGLImplementationDesktopGLCoreProfile)
1057 glDisable(GL_TEXTURE_RECTANGLE_ARB); 1055 glDisable(GL_TEXTURE_RECTANGLE_ARB);
1058 if (status != kCGLNoError) { 1056 if (!bind_result) {
1059 NOTIFY_STATUS("CGLTexImageIOSurface2D()", status, SFT_PLATFORM_ERROR); 1057 NOTIFY_STATUS("Failed BindTexImage on GLImageIOSurface", PLATFORM_FAILURE,
1058 SFT_PLATFORM_ERROR);
1060 return false; 1059 return false;
1061 } 1060 }
1062 1061
1063 bool allow_overlay = false;
1064 scoped_refptr<gl::GLImageIOSurface> gl_image(
1065 new gl::GLImageIOSurface(frame.coded_size, GL_BGRA_EXT));
1066 if (gl_image->Initialize(surface, gfx::GenericSharedMemoryId(),
1067 gfx::BufferFormat::BGRA_8888)) {
1068 allow_overlay = true;
1069 } else {
1070 gl_image = nullptr;
1071 }
1072 bind_image_.Run(picture_info->client_texture_id, GL_TEXTURE_RECTANGLE_ARB, 1062 bind_image_.Run(picture_info->client_texture_id, GL_TEXTURE_RECTANGLE_ARB,
1073 gl_image); 1063 gl_image);
1074 1064
1075 // Assign the new image(s) to the the picture info. 1065 // Assign the new image(s) to the the picture info.
1076 picture_info->gl_image = gl_image; 1066 picture_info->gl_image = gl_image;
1077 picture_info->cv_image = frame.image; 1067 picture_info->cv_image = frame.image;
1078 available_picture_ids_.pop_back(); 1068 available_picture_ids_.pop_back();
1079 1069
1080 // TODO(sandersd): Currently, the size got from 1070 // TODO(sandersd): Currently, the size got from
1081 // CMVideoFormatDescriptionGetDimensions is visible size. We pass it to 1071 // CMVideoFormatDescriptionGetDimensions is visible size. We pass it to
1082 // GpuVideoDecoder so that GpuVideoDecoder can use correct visible size in 1072 // GpuVideoDecoder so that GpuVideoDecoder can use correct visible size in
1083 // resolution changed. We should find the correct API to get the real 1073 // resolution changed. We should find the correct API to get the real
1084 // coded size and fix it. 1074 // coded size and fix it.
1085 client_->PictureReady(media::Picture(picture_id, frame.bitstream_id, 1075 client_->PictureReady(media::Picture(picture_id, frame.bitstream_id,
1086 gfx::Rect(frame.coded_size), 1076 gfx::Rect(frame.coded_size),
1087 allow_overlay)); 1077 true));
1088 return true; 1078 return true;
1089 } 1079 }
1090 1080
1091 void VTVideoDecodeAccelerator::NotifyError( 1081 void VTVideoDecodeAccelerator::NotifyError(
1092 Error vda_error_type, 1082 Error vda_error_type,
1093 VTVDASessionFailureType session_failure_type) { 1083 VTVDASessionFailureType session_failure_type) {
1094 DCHECK_LT(session_failure_type, SFT_MAX + 1); 1084 DCHECK_LT(session_failure_type, SFT_MAX + 1);
1095 if (!gpu_thread_checker_.CalledOnValidThread()) { 1085 if (!gpu_thread_checker_.CalledOnValidThread()) {
1096 gpu_task_runner_->PostTask(FROM_HERE, base::Bind( 1086 gpu_task_runner_->PostTask(FROM_HERE, base::Bind(
1097 &VTVideoDecodeAccelerator::NotifyError, weak_this_, vda_error_type, 1087 &VTVideoDecodeAccelerator::NotifyError, weak_this_, vda_error_type,
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
1159 SupportedProfile profile; 1149 SupportedProfile profile;
1160 profile.profile = supported_profile; 1150 profile.profile = supported_profile;
1161 profile.min_resolution.SetSize(16, 16); 1151 profile.min_resolution.SetSize(16, 16);
1162 profile.max_resolution.SetSize(4096, 2160); 1152 profile.max_resolution.SetSize(4096, 2160);
1163 profiles.push_back(profile); 1153 profiles.push_back(profile);
1164 } 1154 }
1165 return profiles; 1155 return profiles;
1166 } 1156 }
1167 1157
1168 } // namespace content 1158 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698