Skip to content

Commit 6eb110e

Browse files
StasyanychStasonych
andauthored
feat: device transport and form factor types (#203)
* Added additional fields for devices. It can be useful, for example, if there is a need in the application code to set a priority for selecting a playback device. I also added a patch that fixes an empty device GUID on macOS. * Added additional fields for devices and fixes merge request. It can be useful, for example, if there is a need in the application code to set a priority for selecting a playback device. I also added a patch that fixes an empty device GUID on macOS. * fixes merge request * fixes linux additional types * actualized branch --------- Co-authored-by: Stasonych <petrashov@1c-connect.com>
1 parent d01da57 commit 6eb110e

File tree

23 files changed

+484
-24
lines changed

23 files changed

+484
-24
lines changed

webrtc-jni/src/main/cpp/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ add_subdirectory(dependencies/jni-voithos)
5050

5151
file(GLOB SOURCES_ROOT "src/*.cpp")
5252
file(GLOB SOURCES_API "src/api/*.cpp")
53+
file(GLOB SOURCES_API_AUDIO "src/api/audio/*.cpp")
5354
file(GLOB SOURCES_MEDIA "src/media/*.cpp")
5455
file(GLOB SOURCES_MEDIA_AUDIO "src/media/audio/*.cpp")
5556
file(GLOB SOURCES_MEDIA_AUDIO_OS "src/media/audio/${SOURCE_TARGET}/*.cpp")
@@ -63,6 +64,7 @@ file(GLOB SOURCES_RTC "src/rtc/*.cpp")
6364
list(APPEND SOURCES
6465
${SOURCES_ROOT}
6566
${SOURCES_API}
67+
${SOURCES_API_AUDIO}
6668
${SOURCES_MEDIA}
6769
${SOURCES_MEDIA_AUDIO}
6870
${SOURCES_MEDIA_AUDIO_OS}

webrtc-jni/src/main/cpp/dependencies/webrtc/CMakeLists.txt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -237,14 +237,16 @@ if (PATCHES)
237237
message(STATUS "Applying ${PATCH}")
238238

239239
execute_process(
240-
COMMAND patch -p0 --forward
241-
WORKING_DIRECTORY "${WEBRTC_SRC_DIR}"
240+
COMMAND git apply
241+
WORKING_DIRECTORY "${WEBRTC_SRC}"
242242
INPUT_FILE "${PATCH}"
243243
OUTPUT_VARIABLE OUTPUT
244244
RESULT_VARIABLE RESULT)
245245

246246
if (RESULT EQUAL 0)
247247
message(STATUS "Patch applied: ${PATCH}")
248+
else()
249+
message(STATUS "Warning: Patch ${PATCH} not applied ....")
248250
endif()
249251
endforeach(PATCH)
250252
endif()
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
Subject: [PATCH] patch for mac deviceId
2+
---
3+
Index: modules/audio_device/mac/audio_device_mac.cc
4+
IDEA additional info:
5+
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
6+
<+>UTF-8
7+
===================================================================
8+
diff --git a/modules/audio_device/mac/audio_device_mac.cc b/modules/audio_device/mac/audio_device_mac.cc
9+
--- a/modules/audio_device/mac/audio_device_mac.cc (revision e4445e46a910eb407571ec0b0b8b7043562678cf)
10+
+++ b/modules/audio_device/mac/audio_device_mac.cc (date 1757498230183)
11+
@@ -834,6 +834,10 @@
12+
13+
if (guid != NULL) {
14+
memset(guid, 0, kAdmMaxGuidSize);
15+
+ AudioDeviceID deviceIds[MaxNumberDevices];
16+
+ int numberDevices = GetNumberDevices(kAudioDevicePropertyScopeOutput, deviceIds, MaxNumberDevices);
17+
+ std::string deviceId = std::to_string(deviceIds[index]);
18+
+ deviceId.copy(guid, kAdmMaxGuidSize);
19+
}
20+
21+
return GetDeviceName(kAudioDevicePropertyScopeOutput, index,
22+
@@ -853,6 +857,10 @@
23+
24+
if (guid != NULL) {
25+
memset(guid, 0, kAdmMaxGuidSize);
26+
+ AudioDeviceID deviceIds[MaxNumberDevices];
27+
+ int numberDevices = GetNumberDevices(kAudioDevicePropertyScopeInput, deviceIds, MaxNumberDevices);
28+
+ std::string deviceId = std::to_string(deviceIds[index]);
29+
+ deviceId.copy(guid, kAdmMaxGuidSize);
30+
}
31+
32+
return GetDeviceName(kAudioDevicePropertyScopeInput, index,

webrtc-jni/src/main/cpp/include/media/Device.h

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,24 @@ namespace jni
2828
{
2929
namespace avdev
3030
{
31+
/**
32+
DeviceTransport and DeviceFormFactor only for audio devices.
33+
*/
34+
enum class DeviceTransport {
35+
trUnknown,
36+
trHdmi,
37+
trUsb,
38+
trWireless,
39+
};
40+
41+
enum class DeviceFormFactor {
42+
ffUnknown,
43+
ffSpeaker,
44+
ffMicrophone,
45+
ffHeadset,
46+
ffHeadphone
47+
};
48+
3149
class Device
3250
{
3351
public:
@@ -39,13 +57,19 @@ namespace jni
3957

4058
std::string getName() const;
4159
std::string getDescriptor() const;
60+
DeviceTransport getDeviceTransport();
61+
DeviceFormFactor getDeviceFormFactor();
62+
void setDeviceTransport(DeviceTransport deviceTransport);
63+
void setDeviceFormFactor(DeviceFormFactor deviceFormFactor);
4264

4365
protected:
4466
Device(std::string name, std::string descriptor);
4567

4668
private:
4769
const std::string name;
4870
const std::string descriptor;
71+
DeviceTransport deviceTransport;
72+
DeviceFormFactor deviceFormFactor;
4973
};
5074

5175

@@ -63,6 +87,8 @@ namespace jni
6387
jmethodID ctor;
6488
jfieldID name;
6589
jfieldID descriptor;
90+
jfieldID deviceTransport;
91+
jfieldID deviceFormFactor;
6692
};
6793

6894
JavaLocalRef<jobject> toJavaDevice(JNIEnv * env, avdev::DevicePtr device);

webrtc-jni/src/main/cpp/include/media/DeviceList.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,13 @@ namespace jni
9494
return devicesSet.empty();
9595
}
9696

97+
void clearDevices()
98+
{
99+
std::unique_lock<std::mutex> mlock(mutex);
100+
devicesSet.clear();
101+
mlock.unlock();
102+
}
103+
97104
std::set<T> devices()
98105
{
99106
std::unique_lock<std::mutex> mlock(mutex);

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,19 @@ namespace jni
2727
{
2828
namespace avdev
2929
{
30+
31+
enum class AudioDeviceDirectionType {
32+
adtUnknown,
33+
adtCapture,
34+
adtRender
35+
};
36+
3037
class AudioDevice : public Device
3138
{
3239
public:
3340
AudioDevice(std::string name, std::string descriptor);
3441
virtual ~AudioDevice() {};
42+
AudioDeviceDirectionType directionType;
3543
};
3644
}
3745

@@ -46,6 +54,9 @@ namespace jni
4654
jmethodID ctor;
4755
jfieldID name;
4856
jfieldID descriptor;
57+
jfieldID deviceTransport;
58+
jfieldID deviceFormFactor;
59+
jfieldID directionType;
4960
};
5061

5162
JavaLocalRef<jobject> toJavaAudioDevice(JNIEnv * env, avdev::DevicePtr device);

webrtc-jni/src/main/cpp/include/media/audio/linux/PulseAudioDeviceManager.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,12 @@ namespace jni
5454
static void getSinkCallback(pa_context * ctx, const pa_sink_info * info, int last, void * userdata);
5555
static void newSinkCallback(pa_context * ctx, const pa_sink_info * info, int last, void * userdata);
5656

57-
void insertDevice(DeviceList<AudioDevicePtr> & devices, const char * name, const char * desc, uint32_t index, bool notify);
58-
void removeDevice(DeviceList<AudioDevicePtr> & devices, uint32_t index);
57+
void insertDevice(DeviceList<AudioDevicePtr> & devices, pa_proplist * proplist, const char * name, const char * desc, uint32_t index, bool notify, bool isCapture);
58+
void removeDevice(DeviceList<AudioDevicePtr> & devices, uint32_t index, bool isCapture);
59+
60+
void fillAdditionalTypes(AudioDevicePtr device, pa_proplist * proplist);
61+
DeviceFormFactor getActualFormFactor(std::string formFactor);
62+
DeviceTransport getActualTransport(std::string transport);
5963

6064
private:
6165
pa_threaded_mainloop * mainloop;

webrtc-jni/src/main/cpp/include/media/audio/macos/CoreAudioDeviceManager.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ namespace jni
4747
bool insertAudioDevice(const AudioDevicePtr & device, const AudioObjectPropertyScope & scope);
4848
int getChannelCount(const AudioDeviceID & deviceID, const AudioObjectPropertyScope & scope);
4949
AudioDeviceID getDefaultDeviceID(const AudioObjectPropertyScope & scope);
50+
DeviceFormFactor getActualFormFactor(const unsigned int sourceID);
51+
DeviceTransport getActualTransport(const unsigned int transportType);
52+
void fillAdditionalTypes(const AudioDeviceID & deviceID, const AudioObjectPropertyScope & scope, AudioDevicePtr device);
5053

5154
static OSStatus deviceListenerProc(AudioObjectID objectID, UInt32 numberAddresses, const AudioObjectPropertyAddress addresses[], void * clientData);
5255
};

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#ifndef JNI_WEBRTC_MEDIA_MF_AUDIO_DEVICE_MANAGER_H_
1818
#define JNI_WEBRTC_MEDIA_MF_AUDIO_DEVICE_MANAGER_H_
1919

20+
#include <initguid.h>
2021
#include "media/audio/AudioDeviceManager.h"
2122
#include "platform/windows/ComPtr.h"
2223
#include "platform/windows/ComInitializer.h"
@@ -46,7 +47,10 @@ namespace jni
4647
AudioDevicePtr createDefaultAudioDevice(const EDataFlow & dataFlow);
4748
AudioDevicePtr createAudioDevice(LPCWSTR deviceId, EDataFlow * dataFlow);
4849
bool insertAudioDevice(AudioDevicePtr device, EDataFlow dataFlow);
49-
void removeAudioDevice(DeviceList<AudioDevicePtr> & devices, std::string id);
50+
void removeAudioDevice(DeviceList<AudioDevicePtr> & devices, std::string id, EDataFlow dataFlow);
51+
DeviceFormFactor getActualFormFactor(EndpointFormFactor formFactor);
52+
DeviceTransport getActualTransport(EndpointFormFactor formFactor);
53+
void fillAdditionalTypes(AudioDevicePtr device);
5054

5155
// IMMNotificationClient implementation.
5256
STDMETHOD_(ULONG, AddRef)();

webrtc-jni/src/main/cpp/include/platform/windows/WinUtils.h

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,4 +102,34 @@ inline std::string RoleToStr(ERole role)
102102
}
103103
}
104104

105+
inline std::string FormFactorToStr(EndpointFormFactor formFactor)
106+
{
107+
switch (formFactor) {
108+
case RemoteNetworkDevice:
109+
return "RemoteNetworkDevice";
110+
case Speakers:
111+
return "Speakers";
112+
case Headphones:
113+
return "Headphones";
114+
case Microphone:
115+
return "Microphone";
116+
case Headset:
117+
return "Headset";
118+
case Handset:
119+
return "Handset";
120+
case UnknownDigitalPassthrough:
121+
return "UnknownDigitalPassthrough";
122+
case SPDIF:
123+
return "SPDIF";
124+
case DigitalAudioDisplayDevice:
125+
return "DigitalAudioDisplayDevice";
126+
case UnknownFormFactor:
127+
return "UnknownFormFactor";
128+
case EndpointFormFactor_enum_count:
129+
return "EndpointFormFactor_enum_count";
130+
default:
131+
return "Unknown Form Factor";
132+
}
133+
}
134+
105135
#endif

0 commit comments

Comments
 (0)