How to change camera with WebRTC on IOS device?

1,313 views
Skip to first unread message

Peter Lee

unread,
Jun 12, 2014, 5:16:42 AM6/12/14
to discuss...@googlegroups.com
Hi,everyone

I wonder how to switch camera when we are calling with WebRTC?using RTCMediaStream.
addVideoTrack/
removeVideoTrack and RTCPeerConnection.addStream/removeStream?

thanks

Zeke Chin

unread,
Jun 13, 2014, 2:01:01 PM6/13/14
to discuss...@googlegroups.com
See - [APPRTCConnectionManager appClient:didReceiveICEServers:] for an example of how a capturer/track/mediastream is set up.
The example uses the front camera - to use a different camera simply change the provided AVCaptureDevice.




--

---
You received this message because you are subscribed to the Google Groups "discuss-webrtc" group.
To unsubscribe from this group and stop receiving emails from it, send an email to discuss-webrt...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Wayne Hawkins

unread,
Jul 31, 2014, 10:50:46 AM7/31/14
to discuss...@googlegroups.com
Did you ever get this working correctly?

My current implementation allows me to swap the camera once (which also seems to result in there being a greater delay on the receiving end). 
Then, whenever I swap it again via a toggle, the app will stop running on the following line

 glTexImage2D(GL_TEXTURE_2D,      0,      RTC_PIXEL_FORMAT,     frame.width,      frame.height,       0,       RTC_PIXEL_FORMAT,     GL_UNSIGNED_BYTE,       frame.yPlane);

The log shows this:

2014-07-31 15:43:25.664 AppRTCDemo[1396:60b] PCO onRenegotiationNeeded - ignoring because AppRTC has a predefined negotiation strategy

2014-07-31 15:43:25.665 AppRTCDemo[1396:60b] PCO onRenegotiationNeeded - ignoring because AppRTC has a predefined negotiation strategy

Camera 'com.apple.avfoundation.avcapturedevice.built-in_video:0' stopped after capturing 734 frames and dropping 0%

(lldb) 

The error itself is - Thread 1:EXC_BAD_ACCESS(code=1, address.... etc


The method I use is likely the issue but here it is:
remove the localmediastream from the peerconnection
remove the localvideotrack from the localmediastream
create a new videosource in the same method mentioned by Zeke
set the localvideotrack to use the source
add the localvideotrack back to the localmediastream
add the localmediastream to the peerconnection
finally set my localvideoview.videotrack to equal the localviewtrack as well. 

Thanks 

devil 2010

unread,
Jul 16, 2020, 6:00:28 PM7/16/20
to discuss-webrtc

hi, any solution? Im stucking in switch camera then got H264 encode error
Vào lúc 21:50:46 UTC+7 ngày Thứ Năm, 31 tháng 7, 2014, bulletma...@msn.com đã viết:

John Mikelich

unread,
Aug 20, 2020, 7:33:03 PM8/20/20
to discuss-webrtc
I don't remove anything. I just switch the avcapturedevice.

Googles demo app has a good example if this.
Here's a snippet, I use ARDCaptureController from  that demo app.
Note that the tracks, streams, and peer connections are not touched.


- (void)changeCamera {

  AVCaptureDevicePosition position =

      _usingFrontCamera ? AVCaptureDevicePositionFront : AVCaptureDevicePositionBack;

  AVCaptureDevice *device = [self findDeviceForPosition:position];

  AVCaptureDeviceFormat *format = [self selectFormatForDevice:device];


  if (format == nil) {

    RTCLogError(@"No valid formats for device %@", device);

    NSAssert(NO, @"");


    return;

  }


  NSInteger fps = [self selectFpsForFormat:format];


  [_capturer startCaptureWithDevice:device format:format fps:fps];

  _capturer.captureDelegate = self;


}


Reply all
Reply to author
Forward
0 new messages