| Index: webrtc/api/objc/RTCOpenGLVideoRenderer.mm
|
| diff --git a/talk/app/webrtc/objc/RTCOpenGLVideoRenderer.mm b/webrtc/api/objc/RTCOpenGLVideoRenderer.mm
|
| similarity index 84%
|
| copy from talk/app/webrtc/objc/RTCOpenGLVideoRenderer.mm
|
| copy to webrtc/api/objc/RTCOpenGLVideoRenderer.mm
|
| index cfead91bcafd0eee7261af8750473649ef46e16d..56a6431ffa43c09ee947e2662bd2a49c0cba36e4 100644
|
| --- a/talk/app/webrtc/objc/RTCOpenGLVideoRenderer.mm
|
| +++ b/webrtc/api/objc/RTCOpenGLVideoRenderer.mm
|
| @@ -1,34 +1,13 @@
|
| /*
|
| - * libjingle
|
| - * Copyright 2014 Google Inc.
|
| + * Copyright 2015 The WebRTC project authors. All Rights Reserved.
|
| *
|
| - * Redistribution and use in source and binary forms, with or without
|
| - * modification, are permitted provided that the following conditions are met:
|
| - *
|
| - * 1. Redistributions of source code must retain the above copyright notice,
|
| - * this list of conditions and the following disclaimer.
|
| - * 2. Redistributions in binary form must reproduce the above copyright notice,
|
| - * this list of conditions and the following disclaimer in the documentation
|
| - * and/or other materials provided with the distribution.
|
| - * 3. The name of the author may not be used to endorse or promote products
|
| - * derived from this software without specific prior written permission.
|
| - *
|
| - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
| - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
| - * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
|
| - * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
| - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
| - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
| - * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
| - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
| - * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
| - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
| + * Use of this source code is governed by a BSD-style license
|
| + * that can be found in the LICENSE file in the root of the source
|
| + * tree. An additional intellectual property rights grant can be found
|
| + * in the file PATENTS. All contributing project authors may
|
| + * be found in the AUTHORS file in the root of the source tree.
|
| */
|
|
|
| -#if !defined(__has_feature) || !__has_feature(objc_arc)
|
| -#error "This file requires ARC support."
|
| -#endif
|
| -
|
| #import "RTCOpenGLVideoRenderer.h"
|
|
|
| #include <string.h>
|
| @@ -41,7 +20,7 @@
|
| #import <OpenGL/gl3.h>
|
| #endif
|
|
|
| -#import "RTCI420Frame.h"
|
| +#import "RTCVideoFrame.h"
|
|
|
| // TODO(tkchin): check and log openGL errors. Methods here return BOOLs in
|
| // anticipation of that happening in the future.
|
| @@ -102,7 +81,7 @@ static const char kFragmentShaderSource[] =
|
|
|
| // Compiles a shader of the given |type| with GLSL source |source| and returns
|
| // the shader handle or 0 on error.
|
| -GLuint CreateShader(GLenum type, const GLchar* source) {
|
| +GLuint CreateShader(GLenum type, const GLchar *source) {
|
| GLuint shader = glCreateShader(type);
|
| if (!shader) {
|
| return 0;
|
| @@ -164,9 +143,9 @@ static const GLsizei kNumTextures = 3 * kNumTextureSets;
|
|
|
| @implementation RTCOpenGLVideoRenderer {
|
| #if TARGET_OS_IPHONE
|
| - EAGLContext* _context;
|
| + EAGLContext *_context;
|
| #else
|
| - NSOpenGLContext* _context;
|
| + NSOpenGLContext *_context;
|
| #endif
|
| BOOL _isInitialized;
|
| NSUInteger _currentTextureSet;
|
| @@ -187,15 +166,17 @@ static const GLsizei kNumTextures = 3 * kNumTextureSets;
|
| rtc::scoped_ptr<uint8_t[]> _planeBuffer;
|
| }
|
|
|
| +@synthesize lastDrawnFrame = _lastDrawnFrame;
|
| +
|
| + (void)initialize {
|
| // Disable dithering for performance.
|
| glDisable(GL_DITHER);
|
| }
|
|
|
| #if TARGET_OS_IPHONE
|
| -- (instancetype)initWithContext:(EAGLContext*)context {
|
| +- (instancetype)initWithContext:(EAGLContext *)context {
|
| #else
|
| -- (instancetype)initWithContext:(NSOpenGLContext*)context {
|
| +- (instancetype)initWithContext:(NSOpenGLContext *)context {
|
| #endif
|
| NSAssert(context != nil, @"context cannot be nil");
|
| if (self = [super init]) {
|
| @@ -204,7 +185,7 @@ static const GLsizei kNumTextures = 3 * kNumTextureSets;
|
| return self;
|
| }
|
|
|
| -- (BOOL)drawFrame:(RTCI420Frame*)frame {
|
| +- (BOOL)drawFrame:(RTCVideoFrame *)frame {
|
| if (!_isInitialized) {
|
| return NO;
|
| }
|
| @@ -325,7 +306,7 @@ static const GLsizei kNumTextures = 3 * kNumTextureSets;
|
| return YES;
|
| }
|
|
|
| -- (BOOL)updateTextureSizesForFrame:(RTCI420Frame*)frame {
|
| +- (BOOL)updateTextureSizesForFrame:(RTCVideoFrame *)frame {
|
| if (frame.height == _lastDrawnFrame.height &&
|
| frame.width == _lastDrawnFrame.width &&
|
| frame.chromaWidth == _lastDrawnFrame.chromaWidth &&
|
| @@ -368,8 +349,9 @@ static const GLsizei kNumTextures = 3 * kNumTextureSets;
|
| GL_UNSIGNED_BYTE,
|
| 0);
|
| }
|
| - if (frame.yPitch != frame.width || frame.uPitch != frame.chromaWidth ||
|
| - frame.vPitch != frame.chromaWidth) {
|
| + if ((NSUInteger)frame.yPitch != frame.width ||
|
| + (NSUInteger)frame.uPitch != frame.chromaWidth ||
|
| + (NSUInteger)frame.vPitch != frame.chromaWidth) {
|
| _planeBuffer.reset(new uint8_t[frame.width * frame.height]);
|
| } else {
|
| _planeBuffer.reset();
|
| @@ -377,12 +359,12 @@ static const GLsizei kNumTextures = 3 * kNumTextureSets;
|
| return YES;
|
| }
|
|
|
| -- (void)uploadPlane:(const uint8_t*)plane
|
| +- (void)uploadPlane:(const uint8_t *)plane
|
| sampler:(GLint)sampler
|
| offset:(NSUInteger)offset
|
| - width:(NSUInteger)width
|
| - height:(NSUInteger)height
|
| - stride:(NSInteger)stride {
|
| + width:(size_t)width
|
| + height:(size_t)height
|
| + stride:(int32_t)stride {
|
| glActiveTexture(GL_TEXTURE0 + offset);
|
| // When setting texture sampler uniforms, the texture index is used not
|
| // the texture handle.
|
| @@ -392,8 +374,8 @@ static const GLsizei kNumTextures = 3 * kNumTextureSets;
|
| #else
|
| BOOL hasUnpackRowLength = YES;
|
| #endif
|
| - const uint8_t* uploadPlane = plane;
|
| - if (stride != width) {
|
| + const uint8_t *uploadPlane = plane;
|
| + if ((size_t)stride != width) {
|
| if (hasUnpackRowLength) {
|
| // GLES3 allows us to specify stride.
|
| glPixelStorei(GL_UNPACK_ROW_LENGTH, stride);
|
| @@ -411,8 +393,8 @@ static const GLsizei kNumTextures = 3 * kNumTextureSets;
|
| } else {
|
| // Make an unpadded copy and upload that instead. Quick profiling showed
|
| // that this is faster than uploading row by row using glTexSubImage2D.
|
| - uint8_t* unpaddedPlane = _planeBuffer.get();
|
| - for (NSUInteger y = 0; y < height; ++y) {
|
| + uint8_t *unpaddedPlane = _planeBuffer.get();
|
| + for (size_t y = 0; y < height; ++y) {
|
| memcpy(unpaddedPlane + y * width, plane + y * stride, width);
|
| }
|
| uploadPlane = unpaddedPlane;
|
| @@ -429,7 +411,7 @@ static const GLsizei kNumTextures = 3 * kNumTextureSets;
|
| uploadPlane);
|
| }
|
|
|
| -- (BOOL)updateTextureDataForFrame:(RTCI420Frame*)frame {
|
| +- (BOOL)updateTextureDataForFrame:(RTCVideoFrame *)frame {
|
| NSUInteger textureOffset = _currentTextureSet * 3;
|
| NSAssert(textureOffset + 3 <= kNumTextures, @"invalid offset");
|
|
|
| @@ -483,7 +465,7 @@ static const GLsizei kNumTextures = 3 * kNumTextureSets;
|
| // beginning at the start of the array. The last argument indicates offset
|
| // of data within |gVertices| as supplied to the vertex buffer.
|
| glVertexAttribPointer(
|
| - _position, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(GLfloat), (void*)0);
|
| + _position, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(GLfloat), (void *)0);
|
| glEnableVertexAttribArray(_position);
|
|
|
| // Read texcoord attribute from |gVertices| with size of 2 and stride of 4
|
| @@ -494,7 +476,7 @@ static const GLsizei kNumTextures = 3 * kNumTextureSets;
|
| GL_FLOAT,
|
| GL_FALSE,
|
| 4 * sizeof(GLfloat),
|
| - (void*)(2 * sizeof(GLfloat)));
|
| + (void *)(2 * sizeof(GLfloat)));
|
| glEnableVertexAttribArray(_texcoord);
|
|
|
| return YES;
|
|
|