OLD | NEW |
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 #include <vector> | 13 #include <vector> |
14 | 14 |
15 #import "RTCShader+Private.h" | 15 #import "RTCShader+Private.h" |
16 #import "WebRTC/RTCVideoFrame.h" | 16 #import "WebRTC/RTCVideoFrame.h" |
17 | 17 |
| 18 #include "webrtc/base/optional.h" |
| 19 #include "webrtc/common_video/rotation.h" |
| 20 |
18 // |kNumTextures| must not exceed 8, which is the limit in OpenGLES2. Two sets | 21 // |kNumTextures| must not exceed 8, which is the limit in OpenGLES2. Two sets |
19 // of 3 textures are used here, one for each of the Y, U and V planes. Having | 22 // of 3 textures are used here, one for each of the Y, U and V planes. Having |
20 // two sets alleviates CPU blockage in the event that the GPU is asked to render | 23 // two sets alleviates CPU blockage in the event that the GPU is asked to render |
21 // to a texture that is already in use. | 24 // to a texture that is already in use. |
22 static const GLsizei kNumTextureSets = 2; | 25 static const GLsizei kNumTextureSets = 2; |
23 static const GLsizei kNumTexturesPerSet = 3; | 26 static const GLsizei kNumTexturesPerSet = 3; |
24 static const GLsizei kNumTextures = kNumTexturesPerSet * kNumTextureSets; | 27 static const GLsizei kNumTextures = kNumTexturesPerSet * kNumTextureSets; |
25 | 28 |
26 // Fragment shader converts YUV values from input textures into a final RGB | 29 // Fragment shader converts YUV values from input textures into a final RGB |
27 // pixel. The conversion formula is from http://www.fourcc.org/fccyvrgb.php. | 30 // pixel. The conversion formula is from http://www.fourcc.org/fccyvrgb.php. |
(...skipping 22 matching lines...) Expand all Loading... |
50 BOOL _hasUnpackRowLength; | 53 BOOL _hasUnpackRowLength; |
51 GLint _currentTextureSet; | 54 GLint _currentTextureSet; |
52 // Handles for OpenGL constructs. | 55 // Handles for OpenGL constructs. |
53 GLuint _textures[kNumTextures]; | 56 GLuint _textures[kNumTextures]; |
54 GLuint _i420Program; | 57 GLuint _i420Program; |
55 GLuint _vertexArray; | 58 GLuint _vertexArray; |
56 GLuint _vertexBuffer; | 59 GLuint _vertexBuffer; |
57 GLint _ySampler; | 60 GLint _ySampler; |
58 GLint _uSampler; | 61 GLint _uSampler; |
59 GLint _vSampler; | 62 GLint _vSampler; |
| 63 // Store current rotation and only upload new vertex data when rotation |
| 64 // changes. |
| 65 rtc::Optional<webrtc::VideoRotation> _currentRotation; |
60 // Used to create a non-padded plane for GPU upload when we receive padded | 66 // Used to create a non-padded plane for GPU upload when we receive padded |
61 // frames. | 67 // frames. |
62 std::vector<uint8_t> _planeBuffer; | 68 std::vector<uint8_t> _planeBuffer; |
63 } | 69 } |
64 | 70 |
65 - (instancetype)initWithContext:(GlContextType *)context { | 71 - (instancetype)initWithContext:(GlContextType *)context { |
66 if (self = [super init]) { | 72 if (self = [super init]) { |
67 #if TARGET_OS_IPHONE | 73 #if TARGET_OS_IPHONE |
68 _hasUnpackRowLength = (context.API == kEAGLRenderingAPIOpenGLES3); | 74 _hasUnpackRowLength = (context.API == kEAGLRenderingAPIOpenGLES3); |
69 #else | 75 #else |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
112 | 118 |
113 - (BOOL)drawFrame:(RTCVideoFrame*)frame { | 119 - (BOOL)drawFrame:(RTCVideoFrame*)frame { |
114 glUseProgram(_i420Program); | 120 glUseProgram(_i420Program); |
115 if (![self updateTextureDataForFrame:frame]) { | 121 if (![self updateTextureDataForFrame:frame]) { |
116 return NO; | 122 return NO; |
117 } | 123 } |
118 #if !TARGET_OS_IPHONE | 124 #if !TARGET_OS_IPHONE |
119 glBindVertexArray(_vertexArray); | 125 glBindVertexArray(_vertexArray); |
120 #endif | 126 #endif |
121 glBindBuffer(GL_ARRAY_BUFFER, _vertexBuffer); | 127 glBindBuffer(GL_ARRAY_BUFFER, _vertexBuffer); |
| 128 if (!_currentRotation || frame.rotation != *_currentRotation) { |
| 129 _currentRotation = rtc::Optional<webrtc::VideoRotation>( |
| 130 static_cast<webrtc::VideoRotation>(frame.rotation)); |
| 131 RTCSetVertexData(*_currentRotation); |
| 132 } |
122 glDrawArrays(GL_TRIANGLE_FAN, 0, 4); | 133 glDrawArrays(GL_TRIANGLE_FAN, 0, 4); |
123 | 134 |
124 return YES; | 135 return YES; |
125 } | 136 } |
126 | 137 |
127 - (void)uploadPlane:(const uint8_t *)plane | 138 - (void)uploadPlane:(const uint8_t *)plane |
128 sampler:(GLint)sampler | 139 sampler:(GLint)sampler |
129 offset:(GLint)offset | 140 offset:(GLint)offset |
130 width:(size_t)width | 141 width:(size_t)width |
131 height:(size_t)height | 142 height:(size_t)height |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
202 offset:textureOffset + 2 | 213 offset:textureOffset + 2 |
203 width:frame.chromaWidth | 214 width:frame.chromaWidth |
204 height:frame.chromaHeight | 215 height:frame.chromaHeight |
205 stride:frame.vPitch]; | 216 stride:frame.vPitch]; |
206 | 217 |
207 _currentTextureSet = (_currentTextureSet + 1) % kNumTextureSets; | 218 _currentTextureSet = (_currentTextureSet + 1) % kNumTextureSets; |
208 return YES; | 219 return YES; |
209 } | 220 } |
210 | 221 |
211 @end | 222 @end |
OLD | NEW |