|
1 | 1 | #import <objc/runtime.h>
|
2 | 2 |
|
3 |
| -#import <WebRTC/RTCAVFoundationVideoSource.h> |
4 |
| -#import <WebRTC/RTCAudioTrack.h> |
5 |
| -#import <WebRTC/RTCVideoTrack.h> |
6 |
| -#import <WebRTC/RTCMediaConstraints.h> |
7 |
| -#import <WebRTC/RTCMediaStream.h> |
8 |
| -#import <WebRTC/RTCMediaStreamTrack.h> |
9 |
| -#import <WebRTC/RTCPeerConnectionFactory.h> |
| 3 | +#import <WebRTC/WebRTC.h> |
10 | 4 |
|
11 | 5 | #import "FlutterRTCMediaStream.h"
|
12 | 6 | #import "FlutterRTCPeerConnection.h"
|
@@ -263,22 +257,34 @@ - (void)getUserVideo:(NSDictionary *)constraints
|
263 | 257 | }
|
264 | 258 |
|
265 | 259 | if (videoDevice) {
|
266 |
| - RTCMediaConstraints* finalConstraints = [[RTCMediaConstraints alloc] initWithMandatoryConstraints:videoConstraints[@"mandatory"] optionalConstraints:nil]; |
267 |
| - RTCAVFoundationVideoSource *videoSource = [self.peerConnectionFactory avFoundationVideoSourceWithConstraints:finalConstraints]; |
268 |
| - // FIXME The effort above to find a videoDevice value which satisfies the |
269 |
| - // specified constraints was pretty much wasted. Salvage facingMode for |
270 |
| - // starters because it is kind of a common and hence important feature on |
271 |
| - // a mobile device. |
272 |
| - switch (videoDevice.position) { |
273 |
| - case AVCaptureDevicePositionBack: |
274 |
| - if (videoSource.canUseBackCamera) { |
275 |
| - videoSource.useBackCamera = YES; |
276 |
| - } |
277 |
| - break; |
278 |
| - case AVCaptureDevicePositionFront: |
279 |
| - videoSource.useBackCamera = NO; |
280 |
| - break; |
| 260 | + RTCVideoSource *videoSource = [self.peerConnectionFactory videoSource]; |
| 261 | + // FIXME: Video capturer shouldn't be local to be able to stop |
| 262 | + RTCCameraVideoCapturer *capt = [[RTCCameraVideoCapturer alloc] initWithDelegate:videoSource]; |
| 263 | + AVCaptureDeviceFormat *selectedFormat = nil; |
| 264 | + int currentDiff = INT_MAX; |
| 265 | + // TODO: use values from constraints map |
| 266 | + int targetWidth = 1280; |
| 267 | + int targetHeight = 720; |
| 268 | + for (AVCaptureDeviceFormat *format in [RTCCameraVideoCapturer supportedFormatsForDevice:videoDevice]) { |
| 269 | + CMVideoDimensions dimension = CMVideoFormatDescriptionGetDimensions(format.formatDescription); |
| 270 | + FourCharCode pixelFormat = CMFormatDescriptionGetMediaSubType(format.formatDescription); |
| 271 | + int diff = abs(targetWidth - dimension.width) + abs(targetHeight - dimension.height); |
| 272 | + if (diff < currentDiff) { |
| 273 | + selectedFormat = format; |
| 274 | + currentDiff = diff; |
| 275 | + } else if (diff == currentDiff && pixelFormat == [capt preferredOutputPixelFormat]) { |
| 276 | + selectedFormat = format; |
| 277 | + } |
| 278 | + } |
| 279 | + if (selectedFormat == nil) { |
| 280 | + NSLog(@"Capture format is nil. Fallback"); |
| 281 | + selectedFormat = [RTCCameraVideoCapturer supportedFormatsForDevice:videoDevice].firstObject; |
281 | 282 | }
|
| 283 | + [capt startCaptureWithDevice:videoDevice format:selectedFormat fps:30 completionHandler:^(NSError *error) { |
| 284 | + if (error) { |
| 285 | + NSLog(@"Start capture error: %@", [error localizedDescription]); |
| 286 | + } |
| 287 | + }]; |
282 | 288 |
|
283 | 289 | NSString *trackUUID = [[NSUUID UUID] UUIDString];
|
284 | 290 | RTCVideoTrack *videoTrack = [self.peerConnectionFactory videoTrackWithSource:videoSource trackId:trackUUID];
|
@@ -428,12 +434,7 @@ -(void)mediaStreamTrackSetEnabled:(RTCMediaStreamTrack *)track : (BOOL)enabled
|
428 | 434 | -(void)mediaStreamTrackSwitchCamera:(RTCMediaStreamTrack *)track
|
429 | 435 | {
|
430 | 436 | if (track) {
|
431 |
| - RTCVideoTrack *videoTrack = (RTCVideoTrack *)track; |
432 |
| - RTCVideoSource *source = videoTrack.source; |
433 |
| - if ([source isKindOfClass:[RTCAVFoundationVideoSource class]]) { |
434 |
| - RTCAVFoundationVideoSource *avSource = (RTCAVFoundationVideoSource *)source; |
435 |
| - avSource.useBackCamera = !avSource.useBackCamera; |
436 |
| - } |
| 437 | + //TODO(rostopira): I will handle it, if will work at least |
437 | 438 | }
|
438 | 439 | }
|
439 | 440 |
|
|
0 commit comments