Skip to content

Commit 702e58c

Browse files
committed
Audio/video device (Windows) handling consistent with the internal API
1 parent 6550c3c commit 702e58c

21 files changed

+253
-731
lines changed

webrtc-jni/src/main/cpp/dependencies/jni-voithos/src/JavaUtils.cpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,14 @@ bool ExceptionCheck(JNIEnv * env)
3535

3636
void ThrowCxxJavaException(JNIEnv * env)
3737
{
38+
std::exception_ptr eptr = std::current_exception();
39+
40+
if (!eptr) {
41+
return;
42+
}
43+
3844
try {
39-
std::rethrow_exception(std::current_exception());
45+
std::rethrow_exception(eptr);
4046
}
4147
catch (const jni::JavaWrappedException & e) {
4248
env->Throw(e.exception().get());
@@ -48,12 +54,7 @@ void ThrowCxxJavaException(JNIEnv * env)
4854
env->Throw(jni::JavaError(env, e.what()));
4955
}
5056
catch (...) {
51-
try {
52-
std::rethrow_exception(std::current_exception());
53-
}
54-
catch (const std::exception & e) {
55-
env->Throw(jni::JavaError(env, e.what()));
56-
}
57+
env->Throw(jni::JavaError(env, "Unhandled Exception"));
5758
}
5859
}
5960

webrtc-jni/src/main/cpp/include/media/audio/windows/WasapiAudioDeviceManager.h

Lines changed: 0 additions & 64 deletions
This file was deleted.

webrtc-jni/src/main/cpp/include/media/audio/windows/MFAudioDeviceManager.h renamed to webrtc-jni/src/main/cpp/include/media/audio/windows/WindowsAudioDeviceManager.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@ namespace jni
2626
{
2727
namespace avdev
2828
{
29-
class MFAudioDeviceManager : public AudioDeviceManager, IMMNotificationClient
29+
class WindowsAudioDeviceManager : public AudioDeviceManager, IMMNotificationClient
3030
{
3131
public:
32-
MFAudioDeviceManager();
33-
~MFAudioDeviceManager();
32+
WindowsAudioDeviceManager();
33+
~WindowsAudioDeviceManager();
3434

3535
std::set<AudioDevicePtr> getAudioCaptureDevices() override;
3636
std::set<AudioDevicePtr> getAudioPlaybackDevices() override;

webrtc-jni/src/main/cpp/include/media/video/VideoDevice.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,14 @@ namespace jni
2828
namespace avdev
2929
{
3030
class VideoDevice : public Device
31-
{
31+
{
3232
public:
3333
VideoDevice(std::string name, std::string descriptor);
3434
virtual ~VideoDevice() {};
3535
};
36+
37+
38+
using VideoDevicePtr = std::shared_ptr<VideoDevice>;
3639
}
3740

3841
namespace VideoDevice
@@ -48,7 +51,7 @@ namespace jni
4851
jfieldID descriptor;
4952
};
5053

51-
JavaLocalRef<jobject> toJavaVideoDevice(JNIEnv * env, avdev::DevicePtr device);
54+
JavaLocalRef<jobject> toJavaVideoDevice(JNIEnv * env, const avdev::VideoDevice & device);
5255
avdev::VideoDevice toNativeVideoDevice(JNIEnv * env, const JavaRef<jobject> & javaType);
5356
}
5457
}

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
#include "modules/video_capture/video_capture.h"
2727
#include "modules/video_capture/video_capture_defines.h"
2828

29+
#include "media/video/VideoDevice.h"
30+
2931
namespace jni
3032
{
3133
class VideoTrackDeviceSource : public webrtc::VideoTrackSource, public rtc::VideoSinkInterface<webrtc::VideoFrame>
@@ -34,7 +36,7 @@ namespace jni
3436
VideoTrackDeviceSource();
3537
~VideoTrackDeviceSource();
3638

37-
void setDeviceUid(const std::string & deviceUid);
39+
void setVideoDevice(const avdev::VideoDevicePtr & device);
3840
void setVideoCaptureCapability(const webrtc::VideoCaptureCapability & capability);
3941

4042
void start();
@@ -56,7 +58,7 @@ namespace jni
5658
void destroy();
5759

5860
private:
59-
std::string deviceUid;
61+
avdev::VideoDevicePtr device;
6062
webrtc::VideoCaptureCapability capability;
6163

6264
rtc::scoped_refptr<webrtc::VideoCaptureModule> captureModule;

webrtc-jni/src/main/cpp/include/media/video/windows/MFVideoDeviceManager.h renamed to webrtc-jni/src/main/cpp/include/media/video/windows/WindowsVideoDeviceManager.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@ namespace jni
2424
{
2525
namespace avdev
2626
{
27-
class MFVideoDeviceManager : public VideoDeviceManager, WinHotplugNotifier
27+
class WindowsVideoDeviceManager : public VideoDeviceManager, WinHotplugNotifier
2828
{
2929
public:
30-
MFVideoDeviceManager();
31-
~MFVideoDeviceManager() = default;
30+
WindowsVideoDeviceManager();
31+
~WindowsVideoDeviceManager() = default;
3232

3333
std::set<VideoDevicePtr> getVideoCaptureDevices() override;
3434
std::set<VideoCaptureCapability> getVideoCaptureCapabilities(const VideoDevice & device) override;

webrtc-jni/src/main/cpp/src/JNI_AudioDeviceModule.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,6 @@ JNIEXPORT void JNICALL Java_dev_onvoid_webrtc_media_audio_AudioDeviceModule_setR
151151
jni::JavaObject obj(env, jni::JavaLocalRef<jobject>(env, device));
152152

153153
const auto javaClass = jni::JavaClasses::get<jni::AudioDevice::JavaAudioDeviceClass>(env);
154-
const std::string devName = jni::JavaString::toNative(env, obj.getString(javaClass->name));
155154
const std::string devGuid = jni::JavaString::toNative(env, obj.getString(javaClass->descriptor));
156155

157156
uint16_t index = 0;
@@ -162,9 +161,6 @@ JNIEXPORT void JNICALL Java_dev_onvoid_webrtc_media_audio_AudioDeviceModule_setR
162161

163162
for (int i = 0; i < deviceCount; ++i) {
164163
if ((audioModule->RecordingDeviceName(i, name, guid) == 0) && devGuid == std::string(guid)) {
165-
printf("selected audio device: %s - %s\n", name, guid);
166-
fflush(NULL);
167-
168164
index = i;
169165
break;
170166
}

webrtc-jni/src/main/cpp/src/JNI_MediaDevices.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ JNIEXPORT jobject JNICALL Java_dev_onvoid_webrtc_media_MediaDevices_getVideoCapt
117117
jni::JavaArrayList deviceList(env, devices.size());
118118

119119
for (const auto & device : devices) {
120-
deviceList.add(jni::VideoDevice::toJavaVideoDevice(env, device));
120+
deviceList.add(jni::VideoDevice::toJavaVideoDevice(env, *device.get()));
121121
}
122122

123123
return deviceList.listObject().release();

webrtc-jni/src/main/cpp/src/JNI_VideoCapture.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ JNIEXPORT void JNICALL Java_dev_onvoid_webrtc_media_video_VideoCapture_setVideoC
3434
jni::VideoCapture * videoSource = GetHandle<jni::VideoCapture>(env, caller);
3535
CHECK_HANDLE(videoSource);
3636

37-
const auto javaClass = jni::JavaClasses::get<jni::VideoDevice::JavaVideoDeviceClass>(env);
3837
const auto dev = jni::VideoDevice::toNativeVideoDevice(env, jni::JavaLocalRef<jobject>(env, device));
3938

4039
videoSource->setDevice(std::make_shared<jni::avdev::VideoDevice>(dev.getName(), dev.getDescriptor()));

webrtc-jni/src/main/cpp/src/JNI_VideoDeviceSource.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,9 @@ JNIEXPORT void JNICALL Java_dev_onvoid_webrtc_media_video_VideoDeviceSource_setV
3434
jni::VideoTrackDeviceSource * videoSource = GetHandle<jni::VideoTrackDeviceSource>(env, caller);
3535
CHECK_HANDLE(videoSource);
3636

37-
jni::JavaObject obj(env, jni::JavaLocalRef<jobject>(env, device));
37+
const auto dev = jni::VideoDevice::toNativeVideoDevice(env, jni::JavaLocalRef<jobject>(env, device));
3838

39-
const auto javaClass = jni::JavaClasses::get<jni::VideoDevice::JavaVideoDeviceClass>(env);
40-
const std::string guid = jni::JavaString::toNative(env, obj.getString(javaClass->descriptor));
41-
42-
videoSource->setDeviceUid(guid);
39+
videoSource->setVideoDevice(std::make_shared<jni::avdev::VideoDevice>(dev.getName(), dev.getDescriptor()));
4340
}
4441

4542
JNIEXPORT void JNICALL Java_dev_onvoid_webrtc_media_video_VideoDeviceSource_setVideoCaptureCapability

webrtc-jni/src/main/cpp/src/WebRTCContext.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@
3030

3131
#ifdef _WIN32
3232
#include <windows.h>
33-
#include "media/audio/windows/MFAudioDeviceManager.h"
34-
#include "media/video/windows/MFVideoDeviceManager.h"
33+
#include "media/audio/windows/WindowsAudioDeviceManager.h"
34+
#include "media/video/windows/WindowsVideoDeviceManager.h"
3535
#endif
3636
#ifdef __linux__
3737
#include "media/audio/linux/PulseAudioDeviceManager.h"
@@ -123,8 +123,8 @@ namespace jni
123123
void WebRTCContext::initDeviceManagers()
124124
{
125125
#ifdef _WIN32
126-
audioDevManager = std::make_unique<avdev::MFAudioDeviceManager>();
127-
videoDevManager = std::make_unique<avdev::MFVideoDeviceManager>();
126+
audioDevManager = std::make_unique<avdev::WindowsAudioDeviceManager>();
127+
videoDevManager = std::make_unique<avdev::WindowsVideoDeviceManager>();
128128
#endif
129129
#ifdef __linux__
130130
audioDevManager = std::make_unique<avdev::PulseAudioDeviceManager>();

webrtc-jni/src/main/cpp/src/media/DeviceChangeListener.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ namespace jni
3939
jdevice = AudioDevice::toJavaAudioDevice(env, device);
4040
}
4141
else if (dynamic_cast<jni::avdev::VideoDevice *>(device.get())) {
42-
jdevice = VideoDevice::toJavaVideoDevice(env, device);
42+
const auto dev = dynamic_cast<jni::avdev::VideoDevice*>(device.get());
43+
jdevice = VideoDevice::toJavaVideoDevice(env, *dev);
4344
}
4445

4546
if (jdevice) {
@@ -56,7 +57,8 @@ namespace jni
5657
jdevice = AudioDevice::toJavaAudioDevice(env, device);
5758
}
5859
else if (dynamic_cast<jni::avdev::VideoDevice *>(device.get())) {
59-
jdevice = VideoDevice::toJavaVideoDevice(env, device);
60+
const auto dev = dynamic_cast<jni::avdev::VideoDevice *>(device.get());
61+
jdevice = VideoDevice::toJavaVideoDevice(env, *dev);
6062
}
6163

6264
if (jdevice) {

0 commit comments

Comments
 (0)