Skip to content

Commit 8b0fb4f

Browse files
committed
Fixed camera device selection for a video track on Unix systems #30
1 parent a630f28 commit 8b0fb4f

File tree

1 file changed

+26
-4
lines changed

1 file changed

+26
-4
lines changed

webrtc-jni/src/main/cpp/src/media/video/VideoTrackDeviceSource.cpp

+26-4
Original file line numberDiff line numberDiff line change
@@ -61,18 +61,40 @@ namespace jni
6161
}
6262

6363
if (device) {
64-
const auto devGuid = device->getDescriptor();
64+
std::string devUid;
65+
const uint32_t size = webrtc::kVideoCaptureDeviceNameLength;
66+
67+
for (uint32_t i = 0; i < num; ++i) {
68+
char name[size] = { 0 };
69+
char guid[size] = { 0 };
70+
71+
int32_t ret = info->GetDeviceName(i, name, size, guid, size);
72+
73+
if (ret != 0) {
74+
RTC_LOG(WARNING) << "Get video capture device name failed";
75+
continue;
76+
}
77+
78+
if (device->getName().compare(name) == 0) {
79+
devUid = guid;
80+
break;
81+
}
82+
}
83+
84+
if (devUid.empty()) {
85+
throw new Exception("Device %s not found", device->getName().c_str());
86+
}
6587

66-
captureModule = webrtc::VideoCaptureFactory::Create(devGuid.c_str());
88+
captureModule = webrtc::VideoCaptureFactory::Create(devUid.c_str());
6789

6890
if (!captureModule) {
69-
throw new Exception("Create VideoCaptureModule for UID %s failed", devGuid.c_str());
91+
throw new Exception("Create VideoCaptureModule for UID %s failed", devUid.c_str());
7092
}
7193

7294
if (!startCapture()) {
7395
destroy();
7496

75-
throw new Exception("Start video capture for UID %s failed", devGuid.c_str());
97+
throw new Exception("Start video capture for UID %s failed", devUid.c_str());
7698
}
7799
}
78100

0 commit comments

Comments
 (0)