OLD | NEW |
1 /* | 1 /* |
2 * libjingle | 2 * Copyright 2015 The WebRTC project authors. All Rights Reserved. |
3 * Copyright 2014 Google Inc. | |
4 * | 3 * |
5 * Redistribution and use in source and binary forms, with or without | 4 * Use of this source code is governed by a BSD-style license |
6 * modification, are permitted provided that the following conditions are met: | 5 * that can be found in the LICENSE file in the root of the source |
7 * | 6 * tree. An additional intellectual property rights grant can be found |
8 * 1. Redistributions of source code must retain the above copyright notice, | 7 * in the file PATENTS. All contributing project authors may |
9 * this list of conditions and the following disclaimer. | 8 * be found in the AUTHORS file in the root of the source tree. |
10 * 2. Redistributions in binary form must reproduce the above copyright notice, | |
11 * this list of conditions and the following disclaimer in the documentation | |
12 * and/or other materials provided with the distribution. | |
13 * 3. The name of the author may not be used to endorse or promote products | |
14 * derived from this software without specific prior written permission. | |
15 * | |
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED | |
17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF | |
18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO | |
19 * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
20 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | |
21 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; | |
22 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, | |
23 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR | |
24 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF | |
25 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
26 */ | 9 */ |
27 | 10 |
28 #if !defined(__has_feature) || !__has_feature(objc_arc) | |
29 #error "This file requires ARC support." | |
30 #endif | |
31 | |
32 #import "RTCNSGLVideoView.h" | 11 #import "RTCNSGLVideoView.h" |
33 | 12 |
34 #import <CoreVideo/CVDisplayLink.h> | 13 #import <CoreVideo/CVDisplayLink.h> |
35 #import <OpenGL/gl3.h> | 14 #import <OpenGL/gl3.h> |
36 #import "RTCI420Frame.h" | 15 #import "RTCI420Frame.h" |
37 #import "RTCOpenGLVideoRenderer.h" | 16 #import "RTCOpenGLVideoRenderer.h" |
38 | 17 |
39 @interface RTCNSGLVideoView () | 18 @interface RTCNSGLVideoView () |
40 // |i420Frame| is set when we receive a frame from a worker thread and is read | 19 // |i420Frame| is set when we receive a frame from a worker thread and is read |
41 // from the display link callback so atomicity is required. | 20 // from the display link callback so atomicity is required. |
42 @property(atomic, strong) RTCI420Frame* i420Frame; | 21 @property(atomic, strong) RTCI420Frame *i420Frame; |
43 @property(atomic, strong) RTCOpenGLVideoRenderer* glRenderer; | 22 @property(atomic, strong) RTCOpenGLVideoRenderer *glRenderer; |
44 - (void)drawFrame; | 23 - (void)drawFrame; |
45 @end | 24 @end |
46 | 25 |
47 static CVReturn OnDisplayLinkFired(CVDisplayLinkRef displayLink, | 26 static CVReturn OnDisplayLinkFired(CVDisplayLinkRef displayLink, |
48 const CVTimeStamp* now, | 27 const CVTimeStamp* now, |
49 const CVTimeStamp* outputTime, | 28 const CVTimeStamp* outputTime, |
50 CVOptionFlags flagsIn, | 29 CVOptionFlags flagsIn, |
51 CVOptionFlags* flagsOut, | 30 CVOptionFlags* flagsOut, |
52 void* displayLinkContext) { | 31 void* displayLinkContext) { |
53 RTCNSGLVideoView* view = (__bridge RTCNSGLVideoView*)displayLinkContext; | 32 RTCNSGLVideoView* view = (__bridge RTCNSGLVideoView*)displayLinkContext; |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
102 | 81 |
103 #pragma mark - RTCVideoRenderer | 82 #pragma mark - RTCVideoRenderer |
104 | 83 |
105 // These methods may be called on non-main thread. | 84 // These methods may be called on non-main thread. |
106 - (void)setSize:(CGSize)size { | 85 - (void)setSize:(CGSize)size { |
107 dispatch_async(dispatch_get_main_queue(), ^{ | 86 dispatch_async(dispatch_get_main_queue(), ^{ |
108 [self.delegate videoView:self didChangeVideoSize:size]; | 87 [self.delegate videoView:self didChangeVideoSize:size]; |
109 }); | 88 }); |
110 } | 89 } |
111 | 90 |
112 - (void)renderFrame:(RTCI420Frame*)frame { | 91 - (void)renderFrame:(RTCI420Frame *)frame { |
113 self.i420Frame = frame; | 92 self.i420Frame = frame; |
114 } | 93 } |
115 | 94 |
116 #pragma mark - Private | 95 #pragma mark - Private |
117 | 96 |
118 - (void)drawFrame { | 97 - (void)drawFrame { |
119 RTCI420Frame* i420Frame = self.i420Frame; | 98 RTCI420Frame* i420Frame = self.i420Frame; |
120 if (self.glRenderer.lastDrawnFrame != i420Frame) { | 99 if (self.glRenderer.lastDrawnFrame != i420Frame) { |
121 // This method may be called from CVDisplayLink callback which isn't on the | 100 // This method may be called from CVDisplayLink callback which isn't on the |
122 // main thread so we have to lock the GL context before drawing. | 101 // main thread so we have to lock the GL context before drawing. |
(...skipping 26 matching lines...) Expand all Loading... |
149 | 128 |
150 - (void)teardownDisplayLink { | 129 - (void)teardownDisplayLink { |
151 if (!_displayLink) { | 130 if (!_displayLink) { |
152 return; | 131 return; |
153 } | 132 } |
154 CVDisplayLinkRelease(_displayLink); | 133 CVDisplayLinkRelease(_displayLink); |
155 _displayLink = NULL; | 134 _displayLink = NULL; |
156 } | 135 } |
157 | 136 |
158 @end | 137 @end |
OLD | NEW |