10000 fix imports, some starting point, builds without errors but doesn't w… · CodeStrings/flutter-webrtc@8804b01 · GitHub
[go: up one dir, main page]

Skip to content

Commit 8804b01

Browse files
committed
fix imports, some starting point, builds without errors but doesn't work at all
1 parent 4318cef commit 8804b01

File tree

1 file changed

+29
-28
lines changed

1 file changed

+29
-28
lines changed

ios/Classes/FlutterRTCMediaStream.m

Lines changed: 29 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
11
#import <objc/runtime.h>
22

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>
104

115
#import "FlutterRTCMediaStream.h"
126
#import "FlutterRTCPeerConnection.h"
@@ -263,22 +257,34 @@ - (void)getUserVideo:(NSDictionary *)constraints
263257
}
264258

265259
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;
281282
}
283+
[capt startCaptureWithDevice:videoDevice format:selectedFormat fps:30 completionHandler:^(NSError *error) {
284+
if (error) {
285+
NSLog(@"Start capture error: %@", [error localizedDescription]);
286+
}
287+
}];
282288

283289
NSString *trackUUID = [[NSUUID UUID] UUIDString];
284290
RTCVideoTrack *videoTrack = [self.peerConnectionFactory videoTrackWithSource:videoSource trackId:trackUUID];
@@ -428,12 +434,7 @@ -(void)mediaStreamTrackSetEnabled:(RTCMediaStreamTrack *)track : (BOOL)enabled
428434
-(void)mediaStreamTrackSwitchCamera:(RTCMediaStreamTrack *)track
429435
{
430436
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
437438
}
438439
}
439440

0 commit comments

Comments
 (0)
0