Android WebRTC Demo how to switch between front and back camera while call is active.

4,311 views
Skip to first unread message

Mohit Sharma

unread,
Dec 17, 2013, 7:20:49 PM12/17/13
to discuss...@googlegroups.com
Hi,

I am able to run android client on my Galaxy s3 device and able to connect to browser. I have a requirement to switch between front and back camera. Can anyone guide how can i do that? Initial study show me somehow i have to get reference to camera object which is created by C++ code but not able to figure out how to do it?


Thanks
Mohit

Lu, Qiang

unread,
Dec 18, 2013, 12:00:20 AM12/18/13
to discuss...@googlegroups.com

Hi mohit,

 

I think you can find how to switch camera on WebRTCDemo instead of AppRTCDemo.

You can start read code from:

toggleCamer() function in webrtc/examples/android/media_demo/src/org/webrtc/webrtcdemo/MediaEngine.java

 

For AppRTCDemo,

         You should add similar logic into it by yourself. After you switch camera, you should update your stream also.

 

BR,

Lu Qiang

--
 
---
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/groups/opt_out.

Mohit Sharma

unread,
Dec 24, 2013, 4:05:04 PM12/24/13
to discuss...@googlegroups.com

Hi,

But it seems WebRTC demo is totally different from AppRTC demo.  It seems its looking for webrtcdemo-jni which i am not able to able to generate. Can you tell me where i can generate those files.



Thanks
Mohit 
Message has been deleted

SProgrammer

unread,
Dec 24, 2013, 5:02:18 PM12/24/13
to discuss...@googlegroups.com
Hello Lu Qiang,


I dont know WebRTC, but experts in Video systems they use seamless switch called input-select adapter, where seamlessly you can switch the camera source like TV channels.


The way you referenced is not doing that because the stream has to be on, you cant stop and restart it.


Reg
/Sham

Lu, Qiang

unread,
Dec 24, 2013, 8:52:24 PM12/24/13
to discuss...@googlegroups.com

You can find how to build it in the section of “Building for Android (on Linux)

http://www.webrtc.org/reference/getting-started

Once you get it build successfully, you can find those JNI shared library on out/Debug directory. (libwebrtc-video-demo-jni.so)

Lu, Qiang

unread,
Dec 24, 2013, 9:35:27 PM12/24/13
to discuss...@googlegroups.com

Hi SProgrammer,

 

Thanks for your sharing this knowledge about “seamless switch”.

 

I am not familiar with it and will to learn it. Hopefully it can be used by WebRTC.

 

And, I just mentioned the mechanism of switch camera used on WebRTCDemoJ

 

BR,

Lu Qiang

 

From: discuss...@googlegroups.com [mailto:discuss...@googlegroups.com] On Behalf Of SProgrammer


Sent: Wednesday, December 25, 2013 6:02 AM
To: discuss...@googlegroups.com

Alexandre GOUAILLARD

unread,
Dec 25, 2013, 1:31:55 AM12/25/13
to discuss...@googlegroups.com
the webRTC demo has no network component, i.e. it is not using a peer connection, and is only here to demo the webrtc layer of the code (audio engine, video engine) separately. In other word it's a "local" demo.

appRTCDemo is a complete client with in house signaling protocol, in house signaling transport (GAE Channel API for Server to Client, XHR for client to server) and a complete p2p streaming, 1-1 solution.

webrtcDemo has just been rewritten and you can find in it some new features related to i/O that you wouldn't in appRTCDemo, including, like LQ reported, the capacity to switch cams. android-based vp8 HW encoding is almost here : http://code.google.com/p/webrtc/issues/detail?id=2575


cheers.

alex.

lanqiul...@gmail.com

unread,
Dec 31, 2013, 12:42:36 AM12/31/13
to discuss...@googlegroups.com
Hi Lu Qiang:
    according your suggestion, i try it ,but it does not work, could you share your code about this.
    thanks in advance. :)

在 2013年12月18日星期三UTC+8下午1时00分20秒,Lu, Qiang写道:

lanqiul...@gmail.com

unread,
Mar 5, 2014, 8:16:49 PM3/5/14
to discuss...@googlegroups.com
i have swich camera  on apprtcdemo

在 2013年12月25日星期三UTC+8上午5时05分04秒,Mohit Sharma写道:

Peter Lee

unread,
Jun 12, 2014, 7:30:42 AM6/12/14
to discuss...@googlegroups.com
Hi,
what's the methods you used to switch camera on the AppRTCDemo?
I have researched the WebRTC for IOS,but I cannot switch the camera,so.can I share your methods?

I think the same regardless of any platform is the principle

BR,

Peter Lee

mparis

unread,
Jul 9, 2014, 9:54:57 AM7/9/14
to discuss...@googlegroups.com
I also am interested in it.
Could you tell us how you did it in Android?

Thanks!!

Message has been deleted
Message has been deleted
Message has been deleted

Albert Devesa Triscon

unread,
Jul 14, 2014, 1:43:38 PM7/14/14
to discuss...@googlegroups.com
Someone told me a way to do it, the problem is I don't know how I have to do, maybe someone with more experience knows what the process is.
To switch the camera you can:
  • renegociate a new video stream using the peer connection API
  • switch the camera without changing the peer connection streams
Both approaches are working and both approaches required to extend a little bit the code/API provided by Google. The easiest path is the second one along these lines: Java => C++ => Java.
Java => C++
    ------------------
    > org/webrtc/VideoCapturer.java
        ++ void switchCamera(int cameraId, CameraInfo cameraInfo) ==> native call
        ++ private static native void nativeSwitchCamera(long nativeVideoCapturer, int cameraId)

    C++
    ------
    > talk/app/webrtc/java/jni/peerconnection_jni.cc
        ++ JOW(void, VideoCapturer_nativeSwitchCamera)(JNIEnv* jni, jclass, jlong pointer, jint camera_id) {
        ++ (reinterpret_cast<cricket::VideoCapturer*>(pointer))->SwitchCamera(camera_id);
        ++ }
    > webrtc/modules/video_capture/include/video_capture.h
        ++ virtual void SwitchCamera(int cameraId) = 0;
    > talk/media/base/videocapturer.h
        ++ virtual void SwitchCamera(int camera_id){};
    > talk/media/webrtc/webrtcvideocapturer.h
        ++ virtual void SwitchCamera(int camera_id);
    > webrtc/modules/video_capture/android/video_capture_android.h
        ++ virtual void SwitchCamera(int cameraId);
    > talk/media/webrtc/webrtcvideocapturer.cc
        ++ void WebRtcVideoCapturer::SetCaptureRotation(int rotation) {
        ++   ...
        ++   module_->SetCaptureRotation(lRotation);
        ++}

    C++ => Java
    ------------------
    > webrtc/modules/video_capture/android/video_capture_android.cc
        ++void VideoCaptureAndroid::SwitchCamera(int cameraId) {
        ++  ...
        ++  jmethodID cid = env->GetMethodID(g_java_capturer_class, "switchCamera", "(I)V");
        ++  if (cid != NULL) {
        ++    env->CallVoidMethod(_jCapturer, cid, cameraId);
        ++  }
        ++}

    Java
    ------
    > org/webrtc/videoengine/VideoCaptureAndroid.java
        ++ private synchronized void switchCamera(int id) {
        ++ if (camera != null) {
        ++  stopCapture();
        ++}
        ++ ...
        ++  startCapture(captureWidth, captureHeight, captureMinMfps, captureMaxMfps);
        ++}

I don’t really know the steps I have to do but what I thought was, do I have to modify all this files and then build the libraries again?



El dimecres 9 de juliol de 2014 15:54:57 UTC+2, mparis va escriure:

kapil kumar

unread,
Dec 30, 2014, 5:37:43 AM12/30/14
to discuss...@googlegroups.com
Hi all,
Even i was thinking the same, and feel both points mentioned by you.
-But when we renegotiate , session has to be re-established and getUserMedia will be invoked again. which i dont want, as its irritating as a user.
-Handle in native application( e.g chrome), like apprtcdemo, i implemented the way to switchcamera through platform API.
So when user press some button, i will switch to other camera. 
My only worry is , is it according to spec ? like without showing getUserMedia dialog again, switching the camera ?

Please correct me if my understanding is wrong :)
TIA
...

Alexandre GOUAILLARD

unread,
Jan 5, 2015, 7:40:14 PM1/5/15
to discuss...@googlegroups.com
you can call GUM once only for each camera, which will generate two (local) streams. As long as you don;t call stop() on the streams, those streams are around, wether you use them (e.g. display locally in a <video> element, or as a source in a peerconnection), or not.

your switching between streams in your peer connection, as many time as you want, is not a problem at all

Note that renegotiation has nothing to do with GUM, it's just for Peerconnection. Practically, you don;t have to all GUM again for switching camera, if the first thing you did was to capture both of them:

- call GUM => get front camera in stream1
- call GUM => get back camera in stream2
- create a peer connection, add stream1, negotiation (create offer, setlocaldescription, ......)
change your mind,
- remove stream1, add stream2, renegotiate <----- *NO GUM*
change your mind n times
- remove streamX, add streamY, renegotiate, n times <------ *NO GUM*


--

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



--
Alex. Gouaillard, PhD, PhD, MBA
------------------------------------------------------------------------------------
CTO - Temasys Communications, S'pore / Mountain View
President - CoSMo Software, Cambridge, MA
------------------------------------------------------------------------------------

Ming Wu

unread,
Jan 9, 2015, 10:57:08 AM1/9/15
to discuss...@googlegroups.com, mohitsh...@gmail.com
Hi Mohit,

Do you have solved the problem that changing camera while clients is connecting in WebRTC for Android Demo? If you have found the way to solve the problem, could you tell me, because I run into the trouble too.
I am looking forward your replay, thanks!

在 2013年12月18日星期三 UTC+8上午8:20:49,Mohit Sharma写道:

Albert

unread,
Jan 10, 2015, 9:32:49 AM1/10/15
to discuss...@googlegroups.com, mohitsh...@gmail.com
Hi Ming Wu,
in the Android example you can find  how to switch between front and back camera while in a call in a PeerConnection level (no need to modify the API code). I leave you the link with the revision and its implementation: https://code.google.com/p/webrtc/source/detail?r=7553

Hope this helps you,
Albert

El divendres, 9 gener de 2015 16:57:08 UTC+1, Ming Wu va escriure:

RTC.Blacker

unread,
Jan 11, 2015, 11:20:06 PM1/11/15
to discuss...@googlegroups.com, mohitsh...@gmail.com
Albert. +1.

it is OK in latest apprtcdemo version.

Ming Wu

unread,
Jan 12, 2015, 10:09:12 AM1/12/15
to discuss...@googlegroups.com, mohitsh...@gmail.com
Hei Albert

Thank you very much for your help! The link you gave me  is so valuable! I solve the problem which have haunted me more than a month. Appreciate you once again!

在 2015年1月10日星期六 UTC+8下午10:32:49,Albert写道:
Reply all
Reply to author
Forward
0 new messages