iOS render: Handle frame rotation in OpenGL
This CL handles frame rotation by updating the OpenGL vertex data in
RTCOpenGLVideoRenderer, instead of calling the expensive
libyuv::I420Rotate that will rotate the actual memory. Also, we can
handle rotated native frames instead of falling back to
NativeToI420Buffer.
Review-Url: https://codereview.webrtc.org/2176623002
Cr-Commit-Position: refs/heads/master@{#13715}
diff --git a/webrtc/sdk/objc/Framework/Classes/RTCNativeNV12Shader.mm b/webrtc/sdk/objc/Framework/Classes/RTCNativeNV12Shader.mm
index cc97943..75a575b 100644
--- a/webrtc/sdk/objc/Framework/Classes/RTCNativeNV12Shader.mm
+++ b/webrtc/sdk/objc/Framework/Classes/RTCNativeNV12Shader.mm
@@ -20,6 +20,8 @@
#import "WebRTC/RTCVideoFrame.h"
#include "webrtc/base/checks.h"
+#include "webrtc/base/optional.h"
+#include "webrtc/common_video/rotation.h"
static const char kNV12FragmentShaderSource[] =
SHADER_VERSION
@@ -46,6 +48,9 @@
GLint _ySampler;
GLint _uvSampler;
CVOpenGLESTextureCacheRef _textureCache;
+ // Store current rotation and only upload new vertex data when rotation
+ // changes.
+ rtc::Optional<webrtc::VideoRotation> _currentRotation;
}
- (instancetype)initWithContext:(GlContextType *)context {
@@ -149,6 +154,11 @@
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glBindBuffer(GL_ARRAY_BUFFER, _vertexBuffer);
+ if (!_currentRotation || frame.rotation != *_currentRotation) {
+ _currentRotation = rtc::Optional<webrtc::VideoRotation>(
+ static_cast<webrtc::VideoRotation>(frame.rotation));
+ RTCSetVertexData(*_currentRotation);
+ }
glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
CFRelease(chromaTexture);