henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1 | /* |
| 2 | * libjingle |
| 3 | * Copyright 2013, Google Inc. |
| 4 | * |
| 5 | * Redistribution and use in source and binary forms, with or without |
| 6 | * modification, are permitted provided that the following conditions are met: |
| 7 | * |
| 8 | * 1. Redistributions of source code must retain the above copyright notice, |
| 9 | * this list of conditions and the following disclaimer. |
| 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 | */ |
| 27 | |
| 28 | #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 29 | #error "This file requires ARC support." |
| 30 | #endif |
| 31 | |
fischman@webrtc.org | c693a2a | 2014-03-24 18:56:37 +0000 | [diff] [blame] | 32 | #import "RTCVideoRenderer+Internal.h" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 33 | |
| 34 | #if TARGET_OS_IPHONE |
tkchin@webrtc.org | 1732a59 | 2014-05-19 23:26:01 +0000 | [diff] [blame^] | 35 | #import "RTCEAGLVideoView+Internal.h" |
| 36 | #endif |
| 37 | #import "RTCI420Frame+Internal.h" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 38 | |
tkchin@webrtc.org | 1732a59 | 2014-05-19 23:26:01 +0000 | [diff] [blame^] | 39 | namespace webrtc { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 40 | |
tkchin@webrtc.org | 1732a59 | 2014-05-19 23:26:01 +0000 | [diff] [blame^] | 41 | class RTCVideoRendererAdapter : public VideoRendererInterface { |
henrike@webrtc.org | d3d6bce | 2014-03-10 20:41:22 +0000 | [diff] [blame] | 42 | public: |
tkchin@webrtc.org | 1732a59 | 2014-05-19 23:26:01 +0000 | [diff] [blame^] | 43 | RTCVideoRendererAdapter(RTCVideoRenderer* renderer) { _renderer = renderer; } |
henrike@webrtc.org | d3d6bce | 2014-03-10 20:41:22 +0000 | [diff] [blame] | 44 | |
tkchin@webrtc.org | 1732a59 | 2014-05-19 23:26:01 +0000 | [diff] [blame^] | 45 | virtual void SetSize(int width, int height) OVERRIDE { |
| 46 | [_renderer.delegate renderer:_renderer |
| 47 | didSetSize:CGSizeMake(width, height)]; |
| 48 | } |
henrike@webrtc.org | d3d6bce | 2014-03-10 20:41:22 +0000 | [diff] [blame] | 49 | |
tkchin@webrtc.org | 1732a59 | 2014-05-19 23:26:01 +0000 | [diff] [blame^] | 50 | virtual void RenderFrame(const cricket::VideoFrame* frame) OVERRIDE { |
| 51 | if (!_renderer.delegate) { |
| 52 | return; |
| 53 | } |
| 54 | RTCI420Frame* i420Frame = [[RTCI420Frame alloc] initWithVideoFrame:frame]; |
| 55 | [_renderer.delegate renderer:_renderer didReceiveFrame:i420Frame]; |
henrike@webrtc.org | d3d6bce | 2014-03-10 20:41:22 +0000 | [diff] [blame] | 56 | } |
| 57 | |
| 58 | private: |
tkchin@webrtc.org | 1732a59 | 2014-05-19 23:26:01 +0000 | [diff] [blame^] | 59 | __weak RTCVideoRenderer* _renderer; |
henrike@webrtc.org | d3d6bce | 2014-03-10 20:41:22 +0000 | [diff] [blame] | 60 | }; |
tkchin@webrtc.org | 1732a59 | 2014-05-19 23:26:01 +0000 | [diff] [blame^] | 61 | } |
henrike@webrtc.org | d3d6bce | 2014-03-10 20:41:22 +0000 | [diff] [blame] | 62 | |
| 63 | @implementation RTCVideoRenderer { |
tkchin@webrtc.org | 1732a59 | 2014-05-19 23:26:01 +0000 | [diff] [blame^] | 64 | talk_base::scoped_ptr<webrtc::RTCVideoRendererAdapter> _adapter; |
| 65 | #if TARGET_OS_IPHONE |
| 66 | RTCEAGLVideoView* _videoView; |
| 67 | #endif |
henrike@webrtc.org | d3d6bce | 2014-03-10 20:41:22 +0000 | [diff] [blame] | 68 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 69 | |
tkchin@webrtc.org | 1732a59 | 2014-05-19 23:26:01 +0000 | [diff] [blame^] | 70 | - (instancetype)initWithDelegate:(id<RTCVideoRendererDelegate>)delegate { |
| 71 | if (self = [super init]) { |
henrike@webrtc.org | d3d6bce | 2014-03-10 20:41:22 +0000 | [diff] [blame] | 72 | _delegate = delegate; |
tkchin@webrtc.org | 1732a59 | 2014-05-19 23:26:01 +0000 | [diff] [blame^] | 73 | _adapter.reset(new webrtc::RTCVideoRendererAdapter(self)); |
henrike@webrtc.org | d3d6bce | 2014-03-10 20:41:22 +0000 | [diff] [blame] | 74 | } |
| 75 | return self; |
| 76 | } |
tkchin@webrtc.org | 1732a59 | 2014-05-19 23:26:01 +0000 | [diff] [blame^] | 77 | |
| 78 | #if TARGET_OS_IPHONE |
| 79 | // TODO(tkchin): remove shim for deprecated method. |
| 80 | - (instancetype)initWithView:(UIView*)view { |
| 81 | if (self = [super init]) { |
| 82 | _videoView = [[RTCEAGLVideoView alloc] initWithFrame:view.bounds]; |
| 83 | _videoView.autoresizingMask = |
| 84 | UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth; |
| 85 | _videoView.translatesAutoresizingMaskIntoConstraints = YES; |
| 86 | [view addSubview:_videoView]; |
| 87 | self.delegate = _videoView; |
| 88 | _adapter.reset(new webrtc::RTCVideoRendererAdapter(self)); |
| 89 | } |
| 90 | return self; |
henrike@webrtc.org | d3d6bce | 2014-03-10 20:41:22 +0000 | [diff] [blame] | 91 | } |
tkchin@webrtc.org | 1732a59 | 2014-05-19 23:26:01 +0000 | [diff] [blame^] | 92 | #endif |
henrike@webrtc.org | d3d6bce | 2014-03-10 20:41:22 +0000 | [diff] [blame] | 93 | |
| 94 | @end |
tkchin@webrtc.org | 1732a59 | 2014-05-19 23:26:01 +0000 | [diff] [blame^] | 95 | |
henrike@webrtc.org | d3d6bce | 2014-03-10 20:41:22 +0000 | [diff] [blame] | 96 | @implementation RTCVideoRenderer (Internal) |
henrike@webrtc.org | d3d6bce | 2014-03-10 20:41:22 +0000 | [diff] [blame] | 97 | |
tkchin@webrtc.org | 1732a59 | 2014-05-19 23:26:01 +0000 | [diff] [blame^] | 98 | - (webrtc::VideoRendererInterface*)videoRenderer { |
| 99 | return _adapter.get(); |
| 100 | } |
| 101 | |
| 102 | @end |