Android, getting camera working from native side ( C++ ).

323 views
Skip to first unread message

Miguel del Amor

unread,
Jan 17, 2018, 4:19:55 AM1/17/18
to discuss-webrtc
Hello all,


I've an application that uses WebRTC stack directly from native side (C++) in Android, integrated with Qt Framework ( just in case it's interesting to know this ). Please, anyone can direct me on how to get the Android camera working without using java?


For other platforms I'm using to get the devices this helper I've created; based on how I've seen WebRTC working:

powah::DeviceManager::VideoDevices powah::DeviceManager::_getDevices()
{
    powah
::DeviceManager::VideoDevices devices;


    std
::unique_ptr<webrtc::VideoCaptureModule::DeviceInfo> info(
                webrtc
::VideoCaptureFactory::CreateDeviceInfo(0));
   
if (!info) return devices;


   
int num_devices = info->NumberOfDevices();
   
for (int i = 0; i < num_devices; ++i) {
       
const uint32_t kSize = 256;
       
char name[kSize] = {0};
       
char id[kSize] = {0};
       
if (info->GetDeviceName(i, name, kSize, id, kSize) != -1)
       
{
            powah
::VideoDevice * device = new powah::VideoDevice();
            device
->setName(name);
            device
->setId(id);


            int32_t numberCapabilities
= info->NumberOfCapabilities(id);
           
for (int j = 0; j < numberCapabilities; j++)
           
{
                webrtc
::VideoCaptureCapability capability;
               
if (info->GetCapability(id, j, capability) < 0) continue;


               
// Check FPS
               
if ((capability.maxFPS > powah::MAX_FPS)
                       
|| (capability.maxFPS < powah::MIN_FPS)) continue;


               
// Check Resolution
               
if ((capability.width > powah::MAX_WIDTH)
                       
|| (capability.height > powah::MAX_HEIGHT)) continue;


                std
::stringstream nameSt;
                nameSt
<< capability.width << "x" << capability.height;
                std
::string name = nameSt.str();
               
for (const powah::Capability & cap : m_predefinedCapabilities)
               
{
                   
if ((cap.width() == capability.width) &&
                           
(cap.height() == capability.height))
                   
{
                        name
= cap.name();
                       
break;
                   
}
               
}
                device
->addCapability(capability, name);
           
}


            powah
::VideoDevice::Capabilities capabilities = device->capabilities();
            powah
::VideoDevice::Capabilities::iterator it = capabilities.end();
            device
->setCurrentCapability((*--it));


            devices
.push_back(device);
       
}
   
}


   
return devices;
}


But for Android list no devices as the method CreateDeviceInfo  (webrtc\modules\video_capture\video_capture_factory.cc) returns nullptr while Android:

VideoCaptureModule::DeviceInfo* VideoCaptureFactory::CreateDeviceInfo(
   
const int32_t id) {
#if defined(ANDROID)
 
return nullptr;
#else
 
return videocapturemodule::VideoCaptureImpl::CreateDeviceInfo(id);
#endif
}




Thanks in advance, regards.

Miguel del Amor

unread,
Jan 18, 2018, 9:25:42 AM1/18/18
to discuss-webrtc


I've been able of doing this, if someone is looking for same, it's a question of adding the stuff that's here (in Android folder): https://chromium.googlesource.com/external/webrtc/stable/webrtc/+/master/modules/video_capture/

And obviously having everything up and running with this inclusion and then remove the android defined part on video_capture_factory.cc.


Not sure if this is adequate, but it's works :). If someone knows a better way of doing this, please tell me!
Reply all
Reply to author
Forward
0 new messages