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

Side by Side Diff: webrtc/sdk/objc/Framework/Classes/RTCNativeNV12Shader.mm

Issue 2695203004: Clean up RTCVideoFrame (Closed)
Patch Set: Fix memory leak. Add ObjC rotation enum. Add space in pointer types. Created 3 years, 10 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
OLDNEW
1 /* 1 /*
2 * Copyright 2016 The WebRTC project authors. All Rights Reserved. 2 * Copyright 2016 The WebRTC project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
11 #import "RTCShader.h" 11 #import "RTCShader.h"
12 12
13 // Native CVPixelBufferRef rendering is only supported on iPhone because it 13 // Native CVPixelBufferRef rendering is only supported on iPhone because it
14 // depends on CVOpenGLESTextureCacheCreate. 14 // depends on CVOpenGLESTextureCacheCreate.
15 #if TARGET_OS_IPHONE 15 #if TARGET_OS_IPHONE
16 16
17 #import <CoreVideo/CVOpenGLESTextureCache.h> 17 #import <CoreVideo/CVOpenGLESTextureCache.h>
18 18
19 #import "RTCShader+Private.h" 19 #import "RTCShader+Private.h"
20 #import "WebRTC/RTCVideoFrame.h" 20 #import "WebRTC/RTCVideoFrame.h"
21 21
22 #include "webrtc/api/video/video_rotation.h"
23 #include "webrtc/base/checks.h" 22 #include "webrtc/base/checks.h"
24 #include "webrtc/base/optional.h" 23 #include "webrtc/base/optional.h"
25 24
26 static const char kNV12FragmentShaderSource[] = 25 static const char kNV12FragmentShaderSource[] =
27 SHADER_VERSION 26 SHADER_VERSION
28 "precision mediump float;" 27 "precision mediump float;"
29 FRAGMENT_SHADER_IN " vec2 v_texcoord;\n" 28 FRAGMENT_SHADER_IN " vec2 v_texcoord;\n"
30 "uniform lowp sampler2D s_textureY;\n" 29 "uniform lowp sampler2D s_textureY;\n"
31 "uniform lowp sampler2D s_textureUV;\n" 30 "uniform lowp sampler2D s_textureUV;\n"
32 FRAGMENT_SHADER_OUT 31 FRAGMENT_SHADER_OUT
(...skipping 10 matching lines...) Expand all
43 " }\n"; 42 " }\n";
44 43
45 @implementation RTCNativeNV12Shader { 44 @implementation RTCNativeNV12Shader {
46 GLuint _vertexBuffer; 45 GLuint _vertexBuffer;
47 GLuint _nv12Program; 46 GLuint _nv12Program;
48 GLint _ySampler; 47 GLint _ySampler;
49 GLint _uvSampler; 48 GLint _uvSampler;
50 CVOpenGLESTextureCacheRef _textureCache; 49 CVOpenGLESTextureCacheRef _textureCache;
51 // Store current rotation and only upload new vertex data when rotation 50 // Store current rotation and only upload new vertex data when rotation
52 // changes. 51 // changes.
53 rtc::Optional<webrtc::VideoRotation> _currentRotation; 52 rtc::Optional<RTCVideoRotation> _currentRotation;
54 } 53 }
55 54
56 - (instancetype)initWithContext:(GlContextType *)context { 55 - (instancetype)initWithContext:(GlContextType *)context {
57 if (self = [super init]) { 56 if (self = [super init]) {
58 if (![self setupNV12Program] || ![self setupTextureCacheWithContext:context] || 57 if (![self setupNV12Program] || ![self setupTextureCacheWithContext:context] ||
59 !RTCSetupVerticesForProgram(_nv12Program, &_vertexBuffer, nullptr)) { 58 !RTCSetupVerticesForProgram(_nv12Program, &_vertexBuffer, nullptr)) {
60 self = nil; 59 self = nil;
61 } 60 }
62 } 61 }
63 return self; 62 return self;
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
148 RTC_CHECK_EQ(static_cast<GLenum>(GL_TEXTURE_2D), 147 RTC_CHECK_EQ(static_cast<GLenum>(GL_TEXTURE_2D),
149 CVOpenGLESTextureGetTarget(chromaTexture)); 148 CVOpenGLESTextureGetTarget(chromaTexture));
150 glBindTexture(GL_TEXTURE_2D, CVOpenGLESTextureGetName(chromaTexture)); 149 glBindTexture(GL_TEXTURE_2D, CVOpenGLESTextureGetName(chromaTexture));
151 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); 150 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
152 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 151 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
153 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); 152 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
154 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); 153 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
155 154
156 glBindBuffer(GL_ARRAY_BUFFER, _vertexBuffer); 155 glBindBuffer(GL_ARRAY_BUFFER, _vertexBuffer);
157 if (!_currentRotation || frame.rotation != *_currentRotation) { 156 if (!_currentRotation || frame.rotation != *_currentRotation) {
158 _currentRotation = rtc::Optional<webrtc::VideoRotation>( 157 _currentRotation = rtc::Optional<RTCVideoRotation>(frame.rotation);
159 static_cast<webrtc::VideoRotation>(frame.rotation));
160 RTCSetVertexData(*_currentRotation); 158 RTCSetVertexData(*_currentRotation);
161 } 159 }
162 glDrawArrays(GL_TRIANGLE_FAN, 0, 4); 160 glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
163 161
164 CFRelease(chromaTexture); 162 CFRelease(chromaTexture);
165 CFRelease(lumaTexture); 163 CFRelease(lumaTexture);
166 164
167 return YES; 165 return YES;
168 } 166 }
169 167
170 @end 168 @end
171 #endif // TARGET_OS_IPHONE 169 #endif // TARGET_OS_IPHONE
OLDNEW
« no previous file with comments | « webrtc/sdk/objc/Framework/Classes/RTCI420Shader.mm ('k') | webrtc/sdk/objc/Framework/Classes/RTCOpenGLVideoRenderer.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698