OLD | NEW |
---|---|
1 /* | 1 /* |
2 * libjingle | 2 * libjingle |
3 * Copyright 2015 Google Inc. | 3 * Copyright 2015 Google Inc. |
4 * | 4 * |
5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
6 * modification, are permitted provided that the following conditions are met: | 6 * modification, are permitted provided that the following conditions are met: |
7 * | 7 * |
8 * 1. Redistributions of source code must retain the above copyright notice, | 8 * 1. Redistributions of source code must retain the above copyright notice, |
9 * this list of conditions and the following disclaimer. | 9 * this list of conditions and the following disclaimer. |
10 * 2. Redistributions in binary form must reproduce the above copyright notice, | 10 * 2. Redistributions in binary form must reproduce the above copyright notice, |
(...skipping 16 matching lines...) Expand all Loading... | |
27 | 27 |
28 #import "RTCAVFoundationVideoSource+Internal.h" | 28 #import "RTCAVFoundationVideoSource+Internal.h" |
29 | 29 |
30 #import "RTCMediaConstraints+Internal.h" | 30 #import "RTCMediaConstraints+Internal.h" |
31 #import "RTCMediaSource+Internal.h" | 31 #import "RTCMediaSource+Internal.h" |
32 #import "RTCPeerConnectionFactory+Internal.h" | 32 #import "RTCPeerConnectionFactory+Internal.h" |
33 #import "RTCVideoSource+Internal.h" | 33 #import "RTCVideoSource+Internal.h" |
34 | 34 |
35 #include <memory> | 35 #include <memory> |
36 | 36 |
37 @implementation RTCAVFoundationVideoSource | 37 @implementation RTCAVFoundationVideoSource |
tkchin_webrtc
2016/04/05 16:10:27
just add the instance var here to avoid casting et
nisse-webrtc
2016/04/06 08:11:48
Thanks, I had no idea you could define instance va
tkchin_webrtc
2016/04/06 19:41:46
Yes, all objc objects are dynamically allocated.
| |
38 | 38 |
39 - (instancetype)initWithFactory:(RTCPeerConnectionFactory*)factory | 39 - (instancetype)initWithFactory:(RTCPeerConnectionFactory*)factory |
40 constraints:(RTCMediaConstraints*)constraints { | 40 constraints:(RTCMediaConstraints*)constraints { |
41 NSParameterAssert(factory); | 41 NSParameterAssert(factory); |
42 std::unique_ptr<webrtc::AVFoundationVideoCapturer> capturer; | 42 // We pass ownership of the capturer to the source, but since we own |
43 capturer.reset(new webrtc::AVFoundationVideoCapturer()); | 43 // the source, it should be ok to keep a raw pointer to the |
44 // capturer. | |
45 webrtc::AVFoundationVideoCapturer* capturer = | |
46 new webrtc::AVFoundationVideoCapturer(); | |
44 rtc::scoped_refptr<webrtc::VideoTrackSourceInterface> source = | 47 rtc::scoped_refptr<webrtc::VideoTrackSourceInterface> source = |
45 factory.nativeFactory->CreateVideoSource(capturer.release(), constraints.c onstraints); | 48 factory.nativeFactory->CreateVideoSource(capturer, |
49 constraints.constraints); | |
50 // We pass ownership of the capturer to the source, but since we own | |
51 // the source, it should be ok to keep a raw pointer to the | |
52 // capturer. | |
53 _capturer = static_cast<void*>(capturer); | |
46 return [super initWithMediaSource:source]; | 54 return [super initWithMediaSource:source]; |
47 } | 55 } |
48 | 56 |
49 - (BOOL)canUseBackCamera { | 57 - (BOOL)canUseBackCamera { |
50 return self.capturer->CanUseBackCamera(); | 58 return self.capturer->CanUseBackCamera(); |
51 } | 59 } |
52 | 60 |
53 - (BOOL)useBackCamera { | 61 - (BOOL)useBackCamera { |
54 return self.capturer->GetUseBackCamera(); | 62 return self.capturer->GetUseBackCamera(); |
55 } | 63 } |
56 | 64 |
57 - (void)setUseBackCamera:(BOOL)useBackCamera { | 65 - (void)setUseBackCamera:(BOOL)useBackCamera { |
58 self.capturer->SetUseBackCamera(useBackCamera); | 66 self.capturer->SetUseBackCamera(useBackCamera); |
59 } | 67 } |
60 | 68 |
61 - (AVCaptureSession*)captureSession { | 69 - (AVCaptureSession*)captureSession { |
62 return self.capturer->GetCaptureSession(); | 70 return self.capturer->GetCaptureSession(); |
63 } | 71 } |
64 | 72 |
65 - (webrtc::AVFoundationVideoCapturer*)capturer { | 73 - (webrtc::AVFoundationVideoCapturer*)capturer { |
66 cricket::VideoCapturer* capturer = self.videoSource->GetVideoCapturer(); | 74 return static_cast<webrtc::AVFoundationVideoCapturer*>(_capturer); |
67 // This should be safe because no one should have changed the underlying video | |
68 // source. | |
69 webrtc::AVFoundationVideoCapturer* foundationCapturer = | |
70 static_cast<webrtc::AVFoundationVideoCapturer*>(capturer); | |
71 return foundationCapturer; | |
72 } | 75 } |
73 | 76 |
74 @end | 77 @end |
OLD | NEW |