Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions webrtc-jni/src/main/cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ add_subdirectory(dependencies/jni-voithos)

file(GLOB SOURCES_ROOT "src/*.cpp")
file(GLOB SOURCES_API "src/api/*.cpp")
file(GLOB SOURCES_API_AUDIO "src/api/audio/*.cpp")
file(GLOB SOURCES_MEDIA "src/media/*.cpp")
file(GLOB SOURCES_MEDIA_AUDIO "src/media/audio/*.cpp")
file(GLOB SOURCES_MEDIA_AUDIO_OS "src/media/audio/${SOURCE_TARGET}/*.cpp")
Expand All @@ -63,6 +64,7 @@ file(GLOB SOURCES_RTC "src/rtc/*.cpp")
list(APPEND SOURCES
${SOURCES_ROOT}
${SOURCES_API}
${SOURCES_API_AUDIO}
${SOURCES_MEDIA}
${SOURCES_MEDIA_AUDIO}
${SOURCES_MEDIA_AUDIO_OS}
Expand Down
6 changes: 4 additions & 2 deletions webrtc-jni/src/main/cpp/dependencies/webrtc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -237,14 +237,16 @@ if (PATCHES)
message(STATUS "Applying ${PATCH}")

execute_process(
COMMAND patch -p0 --forward
WORKING_DIRECTORY "${WEBRTC_SRC_DIR}"
COMMAND git apply
WORKING_DIRECTORY "${WEBRTC_SRC}"
INPUT_FILE "${PATCH}"
OUTPUT_VARIABLE OUTPUT
RESULT_VARIABLE RESULT)

if (RESULT EQUAL 0)
message(STATUS "Patch applied: ${PATCH}")
else()
message(STATUS "Warning: Patch ${PATCH} not applied ....")
endif()
endforeach(PATCH)
endif()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
Subject: [PATCH] patch for mac deviceId
---
Index: modules/audio_device/mac/audio_device_mac.cc
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/modules/audio_device/mac/audio_device_mac.cc b/modules/audio_device/mac/audio_device_mac.cc
--- a/modules/audio_device/mac/audio_device_mac.cc (revision e4445e46a910eb407571ec0b0b8b7043562678cf)
+++ b/modules/audio_device/mac/audio_device_mac.cc (date 1757498230183)
@@ -834,6 +834,10 @@

if (guid != NULL) {
memset(guid, 0, kAdmMaxGuidSize);
+ AudioDeviceID deviceIds[MaxNumberDevices];
+ int numberDevices = GetNumberDevices(kAudioDevicePropertyScopeOutput, deviceIds, MaxNumberDevices);
+ std::string deviceId = std::to_string(deviceIds[index]);
+ deviceId.copy(guid, kAdmMaxGuidSize);
}

return GetDeviceName(kAudioDevicePropertyScopeOutput, index,
@@ -853,6 +857,10 @@

if (guid != NULL) {
memset(guid, 0, kAdmMaxGuidSize);
+ AudioDeviceID deviceIds[MaxNumberDevices];
+ int numberDevices = GetNumberDevices(kAudioDevicePropertyScopeInput, deviceIds, MaxNumberDevices);
+ std::string deviceId = std::to_string(deviceIds[index]);
+ deviceId.copy(guid, kAdmMaxGuidSize);
}

return GetDeviceName(kAudioDevicePropertyScopeInput, index,
26 changes: 26 additions & 0 deletions webrtc-jni/src/main/cpp/include/media/Device.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,24 @@ namespace jni
{
namespace avdev
{
/**
DeviceTransport and DeviceFormFactor only for audio devices.
*/
enum class DeviceTransport {
trUnknown,
trHdmi,
trUsb,
trWireless,
};

enum class DeviceFormFactor {
ffUnknown,
ffSpeaker,
ffMicrophone,
ffHeadset,
ffHeadphone
};

class Device
{
public:
Expand All @@ -39,13 +57,19 @@ namespace jni

std::string getName() const;
std::string getDescriptor() const;
DeviceTransport getDeviceTransport();
DeviceFormFactor getDeviceFormFactor();
void setDeviceTransport(DeviceTransport deviceTransport);
void setDeviceFormFactor(DeviceFormFactor deviceFormFactor);

protected:
Device(std::string name, std::string descriptor);

private:
const std::string name;
const std::string descriptor;
DeviceTransport deviceTransport;
DeviceFormFactor deviceFormFactor;
};


Expand All @@ -63,6 +87,8 @@ namespace jni
jmethodID ctor;
jfieldID name;
jfieldID descriptor;
jfieldID deviceTransport;
jfieldID deviceFormFactor;
};

JavaLocalRef<jobject> toJavaDevice(JNIEnv * env, avdev::DevicePtr device);
Expand Down
7 changes: 7 additions & 0 deletions webrtc-jni/src/main/cpp/include/media/DeviceList.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,13 @@ namespace jni
return devicesSet.empty();
}

void clearDevices()
{
std::unique_lock<std::mutex> mlock(mutex);
devicesSet.clear();
mlock.unlock();
}

std::set<T> devices()
{
std::unique_lock<std::mutex> mlock(mutex);
Expand Down
11 changes: 11 additions & 0 deletions webrtc-jni/src/main/cpp/include/media/audio/AudioDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,19 @@ namespace jni
{
namespace avdev
{

enum class AudioDeviceDirectionType {
adtUnknown,
adtCapture,
adtRender
};

class AudioDevice : public Device
{
public:
AudioDevice(std::string name, std::string descriptor);
virtual ~AudioDevice() {};
AudioDeviceDirectionType directionType;
};
}

Expand All @@ -46,6 +54,9 @@ namespace jni
jmethodID ctor;
jfieldID name;
jfieldID descriptor;
jfieldID deviceTransport;
jfieldID deviceFormFactor;
jfieldID directionType;
};

JavaLocalRef<jobject> toJavaAudioDevice(JNIEnv * env, avdev::DevicePtr device);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,12 @@ namespace jni
static void getSinkCallback(pa_context * ctx, const pa_sink_info * info, int last, void * userdata);
static void newSinkCallback(pa_context * ctx, const pa_sink_info * info, int last, void * userdata);

void insertDevice(DeviceList<AudioDevicePtr> & devices, const char * name, const char * desc, uint32_t index, bool notify);
void removeDevice(DeviceList<AudioDevicePtr> & devices, uint32_t index);
void insertDevice(DeviceList<AudioDevicePtr> & devices, pa_proplist * proplist, const char * name, const char * desc, uint32_t index, bool notify, bool isCapture);
void removeDevice(DeviceList<AudioDevicePtr> & devices, uint32_t index, bool isCapture);

void fillAdditionalTypes(AudioDevicePtr device, pa_proplist * proplist);
DeviceFormFactor getActualFormFactor(std::string formFactor);
DeviceTransport getActualTransport(std::string transport);

private:
pa_threaded_mainloop * mainloop;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ namespace jni
bool insertAudioDevice(const AudioDevicePtr & device, const AudioObjectPropertyScope & scope);
int getChannelCount(const AudioDeviceID & deviceID, const AudioObjectPropertyScope & scope);
AudioDeviceID getDefaultDeviceID(const AudioObjectPropertyScope & scope);
DeviceFormFactor getActualFormFactor(const unsigned int sourceID);
DeviceTransport getActualTransport(const unsigned int transportType);
void fillAdditionalTypes(const AudioDeviceID & deviceID, const AudioObjectPropertyScope & scope, AudioDevicePtr device);

static OSStatus deviceListenerProc(AudioObjectID objectID, UInt32 numberAddresses, const AudioObjectPropertyAddress addresses[], void * clientData);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#ifndef JNI_WEBRTC_MEDIA_MF_AUDIO_DEVICE_MANAGER_H_
#define JNI_WEBRTC_MEDIA_MF_AUDIO_DEVICE_MANAGER_H_

#include <initguid.h>
#include "media/audio/AudioDeviceManager.h"
#include "platform/windows/ComPtr.h"
#include "platform/windows/ComInitializer.h"
Expand Down Expand Up @@ -46,7 +47,10 @@ namespace jni
AudioDevicePtr createDefaultAudioDevice(const EDataFlow & dataFlow);
AudioDevicePtr createAudioDevice(LPCWSTR deviceId, EDataFlow * dataFlow);
bool insertAudioDevice(AudioDevicePtr device, EDataFlow dataFlow);
void removeAudioDevice(DeviceList<AudioDevicePtr> & devices, std::string id);
void removeAudioDevice(DeviceList<AudioDevicePtr> & devices, std::string id, EDataFlow dataFlow);
DeviceFormFactor getActualFormFactor(EndpointFormFactor formFactor);
DeviceTransport getActualTransport(EndpointFormFactor formFactor);
void fillAdditionalTypes(AudioDevicePtr device);

// IMMNotificationClient implementation.
STDMETHOD_(ULONG, AddRef)();
Expand Down
30 changes: 30 additions & 0 deletions webrtc-jni/src/main/cpp/include/platform/windows/WinUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,4 +102,34 @@ inline std::string RoleToStr(ERole role)
}
}

inline std::string FormFactorToStr(EndpointFormFactor formFactor)
{
switch (formFactor) {
case RemoteNetworkDevice:
return "RemoteNetworkDevice";
case Speakers:
return "Speakers";
case Headphones:
return "Headphones";
case Microphone:
return "Microphone";
case Headset:
return "Headset";
case Handset:
return "Handset";
case UnknownDigitalPassthrough:
return "UnknownDigitalPassthrough";
case SPDIF:
return "SPDIF";
case DigitalAudioDisplayDevice:
return "DigitalAudioDisplayDevice";
case UnknownFormFactor:
return "UnknownFormFactor";
case EndpointFormFactor_enum_count:
return "EndpointFormFactor_enum_count";
default:
return "Unknown Form Factor";
}
}

#endif
2 changes: 2 additions & 0 deletions webrtc-jni/src/main/cpp/src/JNI_AudioDeviceModuleBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ JNIEXPORT jobject JNICALL Java_dev_onvoid_webrtc_media_audio_AudioDeviceModuleBa
for (int i = 0; i < deviceCount; ++i) {
if (audioModule->PlayoutDeviceName(i, name, guid) == 0) {
auto device = std::make_shared<jni::avdev::AudioDevice>(name, guid);
device -> directionType = jni::avdev::AudioDeviceDirectionType::adtRender;

deviceList.add(jni::AudioDevice::toJavaAudioDevice(env, device));
}
Expand All @@ -145,6 +146,7 @@ JNIEXPORT jobject JNICALL Java_dev_onvoid_webrtc_media_audio_AudioDeviceModuleBa
for (int i = 0; i < deviceCount; ++i) {
if (audioModule->RecordingDeviceName(i, name, guid) == 0) {
auto device = std::make_shared<jni::avdev::AudioDevice>(name, guid);
device -> directionType = jni::avdev::AudioDeviceDirectionType::adtCapture;

deviceList.add(jni::AudioDevice::toJavaAudioDevice(env, device));
}
Expand Down
3 changes: 3 additions & 0 deletions webrtc-jni/src/main/cpp/src/WebRTCContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@ namespace jni
JavaEnums::add<webrtc::AudioProcessing::Config::Pipeline::DownmixMethod>(env, PKG_AUDIO"AudioProcessingConfig$Pipeline$DownmixMethod");
JavaEnums::add<webrtc::AudioProcessing::Config::NoiseSuppression::Level>(env, PKG_AUDIO"AudioProcessingConfig$NoiseSuppression$Level");
JavaEnums::add<jni::RTCStats::RTCStatsType>(env, PKG"RTCStatsType");
JavaEnums::add<jni::avdev::DeviceFormFactor>(env, PKG_MEDIA"DeviceFormFactor");
JavaEnums::add<jni::avdev::DeviceTransport>(env, PKG_MEDIA"DeviceTransport");
JavaEnums::add<jni::avdev::AudioDeviceDirectionType>(env, PKG_MEDIA"AudioDeviceDirectionType");

JavaFactories::add<webrtc::AudioSourceInterface>(env, PKG_MEDIA"audio/AudioTrackSource");
JavaFactories::add<webrtc::AudioTrackInterface>(env, PKG_MEDIA"audio/AudioTrack");
Expand Down
33 changes: 32 additions & 1 deletion webrtc-jni/src/main/cpp/src/media/Device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,17 @@
#include "JavaClasses.h"
#include "JavaString.h"
#include "JNI_WebRTC.h"
#include "JavaEnums.h"

namespace jni
{
namespace avdev
{
Device::Device(std::string name, std::string descriptor) :
name(name),
descriptor(descriptor)
descriptor(descriptor),
deviceTransport(DeviceTransport::trUnknown),
deviceFormFactor(DeviceFormFactor::ffUnknown)
{
}

Expand Down Expand Up @@ -53,6 +56,26 @@ namespace jni
{
return name;
}

DeviceTransport Device::getDeviceTransport()
{
return deviceTransport;
}

DeviceFormFactor Device::getDeviceFormFactor()
{
return deviceFormFactor;
}

void Device::setDeviceTransport(DeviceTransport newDeviceTransport)
{
deviceTransport = newDeviceTransport;
}

void Device::setDeviceFormFactor(DeviceFormFactor newDeviceFormFactor)
{
deviceFormFactor = newDeviceFormFactor;
}
}

namespace Device
Expand All @@ -65,6 +88,12 @@ namespace jni
JavaString::toJava(env, device->getName()).get(),
JavaString::toJava(env, device->getDescriptor()).get());

auto deviceTransport = JavaEnums::toJava(env, device->getDeviceTransport());
env->SetObjectField(obj, javaClass->deviceTransport, deviceTransport.get());

auto deviceFormFactor = JavaEnums::toJava(env, device->getDeviceFormFactor());
env->SetObjectField(obj, javaClass->deviceFormFactor, deviceFormFactor.get());

return JavaLocalRef<jobject>(env, obj);
}

Expand All @@ -76,6 +105,8 @@ namespace jni

name = GetFieldID(env, cls, "name", STRING_SIG);
descriptor = GetFieldID(env, cls, "descriptor", STRING_SIG);
deviceTransport = GetFieldID(env, cls, "deviceTransport", "L" PKG_MEDIA "DeviceTransport;");
deviceFormFactor = GetFieldID(env, cls, "deviceFormFactor", "L" PKG_MEDIA "DeviceFormFactor;");
}
}
}
17 changes: 16 additions & 1 deletion webrtc-jni/src/main/cpp/src/media/audio/AudioDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,15 @@
#include "JavaClasses.h"
#include "JavaString.h"
#include "JNI_WebRTC.h"
#include "JavaEnums.h"

namespace jni
{
namespace avdev
{
AudioDevice::AudioDevice(std::string name, std::string descriptor) :
Device(name, descriptor)
Device(name, descriptor),
directionType(AudioDeviceDirectionType::adtUnknown)
{
}
}
Expand All @@ -40,6 +42,16 @@ namespace jni
JavaString::toJava(env, device->getName()).get(),
JavaString::toJava(env, device->getDescriptor()).get());

auto deviceTransport = JavaEnums::toJava(env, device->getDeviceTransport());
env->SetObjectField(obj, javaClass->deviceTransport, deviceTransport.get());

auto deviceFormFactor = JavaEnums::toJava(env, device->getDeviceFormFactor());
env->SetObjectField(obj, javaClass->deviceFormFactor, deviceFormFactor.get());

auto audioDevice = dynamic_cast<jni::avdev::AudioDevice *>(device.get());
auto directionType = JavaEnums::toJava(env, audioDevice->directionType);
env->SetObjectField(obj, javaClass->directionType, directionType.get());

return JavaLocalRef<jobject>(env, obj);
}

Expand All @@ -51,6 +63,9 @@ namespace jni

name = GetFieldID(env, cls, "name", STRING_SIG);
descriptor = GetFieldID(env, cls, "descriptor", STRING_SIG);
directionType = GetFieldID(env, cls, "directionType", "L" PKG_MEDIA "AudioDeviceDirectionType;");
deviceTransport = GetFieldID(env, cls, "deviceTransport", "L" PKG_MEDIA "DeviceTransport;");
deviceFormFactor = GetFieldID(env, cls, "deviceFormFactor", "L" PKG_MEDIA "DeviceFormFactor;");
}
}
}
Loading