Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
QtAudioDeviceManager.java
Go to the documentation of this file.
1// Copyright (C) 2021 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4package org.qtproject.qt.android.multimedia;
5
6import java.util.ArrayList;
7import java.util.Arrays;
8import java.util.Comparator;
9import java.util.HashMap;
10import java.util.List;
11import java.util.concurrent.CountDownLatch;
12import java.util.concurrent.atomic.AtomicInteger;
13import android.content.Context;
14import android.media.AudioDeviceCallback;
15import android.media.AudioDeviceInfo;
16import android.media.AudioFormat;
17import android.media.AudioManager;
18import android.media.AudioRecord;
19import android.media.AudioTrack;
20import android.media.MediaRecorder;
21import android.os.Build;
22import android.os.Handler;
23import android.os.HandlerThread;
24import android.util.Log;
25
26import org.qtproject.qt.android.UsedFromNativeCode;
27
28class QtAudioDeviceManager
29{
30 private static final String TAG = "QtAudioDeviceManager";
31
32 static private AudioManager m_audioManager = null;
33 static private final AudioDevicesReceiver m_audioDevicesReceiver = new AudioDevicesReceiver();
34 static private HandlerThread m_handlerThread = null;
35 static private Handler m_handler = null;
36 static private AudioRecord m_recorder = null;
37 static private AudioTrack m_streamPlayer = null;
38 static private Thread m_streamingThread = null;
39 static private boolean m_isStreaming = false;
40 static private boolean m_useSpeaker = false;
41 static private final int m_sampleRate = 8000;
42 static private final int m_channels = AudioFormat.CHANNEL_CONFIGURATION_MONO;
43 static private final int m_audioFormat = AudioFormat.ENCODING_PCM_16BIT;
44 static private final int m_bufferSize = AudioRecord.getMinBufferSize(m_sampleRate, m_channels, m_audioFormat);
45 static private int m_currentOutputId = -1;
46 static private AtomicInteger m_scoCounter = new AtomicInteger();
47 static private AtomicInteger m_communicationDeviceCounter = new AtomicInteger();
48 static private AtomicInteger m_speakerphoneCounter = new AtomicInteger();
49 static private int m_currentCommunicationDeviceId = -1;
50
51 // Holds the pointer to the QAndroidAudioDevices instance.
52 //
53 // This is always assigned with callbacks registered, from a
54 // C++ thread. Assignment only happens when QAndroidAudioDevices
55 // is constructed. It is always cleared from the Handler thread, using
56 // blocking job from the C++ thread.
57 static private long m_qAudioDevicesNativePtr = 0;
58
59 static native void onAudioInputDevicesUpdated(long qAudioDeviceNativePtr);
60 static native void onAudioOutputDevicesUpdated(long qAudioDeviceNativePtr);
61
62 static private void updateDeviceList() {
63 assert(m_handler.getLooper().isCurrentThread());
64 // Make sure we never get a callback when we are unregistered.
65 assert(m_qAudioDevicesNativePtr != 0);
66
67 if (m_currentOutputId != -1)
68 prepareAudioOutput(m_currentOutputId);
69 onAudioInputDevicesUpdated(m_qAudioDevicesNativePtr);
70 onAudioOutputDevicesUpdated(m_qAudioDevicesNativePtr);
71 }
72
73 private static class AudioDevicesReceiver extends AudioDeviceCallback {
75 public void onAudioDevicesAdded(AudioDeviceInfo[] addedDevices) {
76 assert(m_handler.getLooper().isCurrentThread());
77 updateDeviceList();
78 }
79
81 public void onAudioDevicesRemoved(AudioDeviceInfo[] removedDevices) {
82 assert(m_handler.getLooper().isCurrentThread());
83 updateDeviceList();
84 }
85 }
86
87 @UsedFromNativeCode
88 static void qAndroidAudioDevicesConstructed(long nativePtr)
89 {
90 assert(nativePtr != 0);
91 assert(m_handlerThread == null);
92 m_qAudioDevicesNativePtr = nativePtr;
93 m_handlerThread = new HandlerThread("QtAudioDeviceCallbacks");
94 m_handlerThread.start();
95 m_handler = new Handler(m_handlerThread.getLooper());
96 m_audioManager.registerAudioDeviceCallback(m_audioDevicesReceiver, m_handler);
97 }
98
99 @UsedFromNativeCode
100 static void qAndroidAudioDevicesDestroyed()
101 {
102 assert(!m_handler.getLooper().isCurrentThread());
103
104 // Perform cleanup on the same thread that we receive callbacks, then wait for cleanup job
105 // to finish. No need for locks.
106 final CountDownLatch latch = new CountDownLatch(1);
107 final boolean postSuccess = m_handler.post(() -> {
108 m_audioManager.unregisterAudioDeviceCallback(m_audioDevicesReceiver);
109 assert(m_qAudioDevicesNativePtr != 0);
110 m_qAudioDevicesNativePtr = 0;
111 latch.countDown(); // Signal that the task is done
112 });
113
114 if (!postSuccess) {
115 Log.w(
116 TAG,
117 "Unable to post cleanup job to corresponding thread during " +
118 "QAndroidAudioDevices cleanup.");
119 return;
120 }
121
122 try {
123 latch.await();
124 } catch (Exception e) {
125 Log.w(
126 TAG,
127 "Unable to wait for cleanup job to finish on corresponding thread during" +
128 "QAndroidAudioDevices cleanup.");
129 }
130
131 m_handlerThread.quitSafely();
132 m_handlerThread = null;
133 m_handler = null;
134 }
135
136 static void setContext(Context context)
137 {
138 m_audioManager = (AudioManager)context.getSystemService(Context.AUDIO_SERVICE);
139 }
140
141 static AudioDeviceInfo[] getAudioOutputDevices()
142 {
143 return getAudioDevices(AudioManager.GET_DEVICES_OUTPUTS);
144 }
145
146 static AudioDeviceInfo[] getAudioInputDevices()
147 {
148 return getAudioDevices(AudioManager.GET_DEVICES_INPUTS);
149 }
150
151 @UsedFromNativeCode
152 static AudioDeviceInfo getAudioInputDeviceInfo(int id)
153 {
154 final AudioDeviceInfo[] audioDevices = m_audioManager.getDevices(AudioManager.GET_DEVICES_INPUTS);
155
156 for (AudioDeviceInfo deviceInfo : audioDevices) {
157 if (deviceInfo.getId() == id)
158 return deviceInfo;
159 }
160
161 return null;
162 }
163
164 @UsedFromNativeCode
165 static int getDefaultSampleRate()
166 {
167 String sampleRate = m_audioManager.getProperty(AudioManager.PROPERTY_OUTPUT_SAMPLE_RATE);
168 return Integer.parseInt(sampleRate);
169 }
170
171 @UsedFromNativeCode
172 static boolean isBluetoothDevice(AudioDeviceInfo deviceInfo)
173 {
174 return isBluetoothDeviceType(deviceInfo.getType());
175 }
176
177 @UsedFromNativeCode
178 static boolean isBluetoothDeviceId(int id)
179 {
180 if (m_audioManager == null)
181 return false;
182
183 for (AudioDeviceInfo deviceInfo : m_audioManager.getDevices(AudioManager.GET_DEVICES_ALL)) {
184 if (deviceInfo.getId() == id)
185 return isBluetoothDevice(deviceInfo);
186 }
187 return false;
188 }
189
190 @UsedFromNativeCode
191 static boolean prepareAudioInput(int id)
192 {
193 final AudioDeviceInfo[] audioDevices =
194 m_audioManager.getDevices(AudioManager.GET_DEVICES_INPUTS);
195 for (AudioDeviceInfo deviceInfo : audioDevices) {
196 if (deviceInfo.getId() == id) {
197 if (isBluetoothDevice(deviceInfo))
198 return prepareAudioDevice(deviceInfo, AudioManager.MODE_NORMAL);
199 switch (deviceInfo.getType())
200 {
201 case AudioDeviceInfo.TYPE_WIRED_HEADSET:
202 case AudioDeviceInfo.TYPE_USB_HEADSET:
203 case AudioDeviceInfo.TYPE_BUILTIN_MIC:
204 return prepareAudioDevice(deviceInfo, AudioManager.MODE_NORMAL);
205 default:
206 return true;
207 }
208 }
209 }
210 return false;
211 }
212
213 private static boolean isBluetoothDeviceType(int type)
214 {
215 return Arrays.stream(bluetoothTypes).anyMatch(t -> t == type);
216 }
217
218 private static void setInputMuted(boolean mute)
219 {
220 // This method mutes the microphone across the entire platform
221 m_audioManager.setMicrophoneMute(mute);
222 }
223
224 private static boolean isMicrophoneMute()
225 {
226 return m_audioManager.isMicrophoneMute();
227 }
228
229 private static String audioDeviceTypeToString(int type)
230 {
231 // API <= 23 types
232 switch (type)
233 {
234 case AudioDeviceInfo.TYPE_AUX_LINE:
235 return "AUX Line";
236 case AudioDeviceInfo.TYPE_BUILTIN_EARPIECE:
237 return "Built in earpiece";
238 case AudioDeviceInfo.TYPE_BUILTIN_MIC:
239 return "Built in microphone";
240 case AudioDeviceInfo.TYPE_BUILTIN_SPEAKER:
241 return "Built in speaker";
242 case AudioDeviceInfo.TYPE_DOCK:
243 return "Dock";
244 case AudioDeviceInfo.TYPE_FM:
245 return "FM";
246 case AudioDeviceInfo.TYPE_FM_TUNER:
247 return "FM TUNER";
248 case AudioDeviceInfo.TYPE_HDMI:
249 return "HDMI";
250 case AudioDeviceInfo.TYPE_HDMI_ARC:
251 return "HDMI ARC";
252 case AudioDeviceInfo.TYPE_IP:
253 return "IP";
254 case AudioDeviceInfo.TYPE_LINE_ANALOG:
255 return "Line analog";
256 case AudioDeviceInfo.TYPE_LINE_DIGITAL:
257 return "Line digital";
258 case AudioDeviceInfo.TYPE_TV_TUNER:
259 return "TV tuner";
260 case AudioDeviceInfo.TYPE_USB_ACCESSORY:
261 return "USB accessory";
262 case AudioDeviceInfo.TYPE_USB_DEVICE:
263 return "USB device";
264 case AudioDeviceInfo.TYPE_WIRED_HEADPHONES:
265 return "Wired headphones";
266 case AudioDeviceInfo.TYPE_WIRED_HEADSET:
267 return "Wired headset";
268 }
269
270 if (isBluetoothDeviceType(type))
271 return "Bluetooth";
272
273 // API 24
274 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
275 if (type == AudioDeviceInfo.TYPE_BUS)
276 return "Bus";
277 }
278
279 return "Unknown-Type";
280
281 }
282
283 private static boolean isDeviceTypeSupported(int type)
284 {
285 return audioDeviceTypeToString(type)
286 != audioDeviceTypeToString(AudioDeviceInfo.TYPE_UNKNOWN);
287 }
288
289 private static final HashMap<Integer, Integer> priorityMap = new HashMap<Integer, Integer>() {{
290 put(AudioDeviceInfo.TYPE_WIRED_HEADSET, 1);
291 put(AudioDeviceInfo.TYPE_WIRED_HEADPHONES, 1);
292 put(AudioDeviceInfo.TYPE_USB_DEVICE, 1);
293 // Keep SCO below the other Bluetooth types
294 put(AudioDeviceInfo.TYPE_BLUETOOTH_SCO, 3);
295 put(AudioDeviceInfo.TYPE_BUILTIN_SPEAKER, 4);
296 }};
297 private static final int BLUETOOTH_PRIORITY = 2;
298 private static final int DEFAULT_PRIORITY = 5;
299
300 private static int getDevicePriority(int type) {
301 Integer priority = priorityMap.get(type);
302 if (priority != null)
303 return priority;
304
305 if (isBluetoothDeviceType(type))
306 return BLUETOOTH_PRIORITY;
307
308 return DEFAULT_PRIORITY;
309 }
310
311 private static void sortAudioDevices(AudioDeviceInfo[] devices) {
312 Comparator<AudioDeviceInfo> deviceTypeComparator = new Comparator<AudioDeviceInfo>() {
313 @Override
314 public int compare(AudioDeviceInfo device1, AudioDeviceInfo device2) {
315 return getDevicePriority(device1.getType()) - getDevicePriority(device2.getType());
316 }
317 };
318
319 Arrays.sort(devices, deviceTypeComparator);
320 }
321
322 private static AudioDeviceInfo[] getAudioDevices(int type)
323 {
324 ArrayList<AudioDeviceInfo> filteredDevices = new ArrayList<>();
325
326 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
327 boolean builtInMicAdded = false;
328 boolean bluetoothDeviceAdded = false;
329 AudioDeviceInfo[] audioDevices = m_audioManager.getDevices(type);
330 sortAudioDevices(audioDevices);
331
332 for (AudioDeviceInfo deviceInfo : audioDevices) {
333 if (!isDeviceTypeSupported(deviceInfo.getType()))
334 continue;
335
336 String deviceType = audioDeviceTypeToString(deviceInfo.getType());
337 if (deviceType.equals(audioDeviceTypeToString(AudioDeviceInfo.TYPE_BUILTIN_MIC))) {
338 if (builtInMicAdded) {
339 // Built in mic already added. Second built in mic is CAMCORDER, but there
340 // is no reliable way of selecting it. AudioSource.MIC usually means the
341 // primary mic. AudioSource.CAMCORDER source might mean the secondary mic,
342 // but there's no guarantee. It depends e.g. on the physical placement
343 // of the mics. That's why we will not add built in microphone twice.
344 // Should we?
345 continue;
346 }
347 builtInMicAdded = true;
348 } else if (isBluetoothDevice(deviceInfo)) {
349 if (bluetoothDeviceAdded) {
350 // Bluetooth device already added. Second device is just a different
351 // technology profille (like A2DP or SCO). We should not add the same
352 // device twice. Should we?
353 continue;
354 }
355 bluetoothDeviceAdded = true;
356 }
357
358 filteredDevices.add(deviceInfo);
359 }
360 }
361
362 return filteredDevices.toArray(new AudioDeviceInfo[filteredDevices.size()]);
363 }
364
365 final private static int [] bluetoothTypes = createBluetoothTypes();
366
367 private static int[] createBluetoothTypes()
368 {
369 ArrayList<Integer> types = new ArrayList<>(Arrays.asList(
370 AudioDeviceInfo.TYPE_BLUETOOTH_A2DP,
371 AudioDeviceInfo.TYPE_BLUETOOTH_SCO));
372 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
373 types.add(AudioDeviceInfo.TYPE_BLE_HEADSET);
374 types.add(AudioDeviceInfo.TYPE_BLE_SPEAKER);
375 }
376 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU)
377 types.add(AudioDeviceInfo.TYPE_BLE_BROADCAST);
378 return types.stream().mapToInt(Integer::intValue).toArray();
379 }
380
381 final private static int [] wiredTypes = {
382 AudioDeviceInfo.TYPE_WIRED_HEADSET,
383 AudioDeviceInfo.TYPE_WIRED_HEADPHONES
384 };
385
386 private static boolean containsAnyOfType(AudioDeviceInfo[] devices, int[]... types) {
387
388 return Arrays.stream(devices)
389 .anyMatch(device -> Arrays.stream(types)
390 .flatMapToInt(Arrays::stream)
391 .anyMatch(type -> device.getType() == type));
392 }
393
394 private static int getCorrectModeIfContainsAnyOfType(AudioDeviceInfo[] devices, int[]... types) {
395 return containsAnyOfType(devices, types) ?
396 AudioManager.MODE_IN_COMMUNICATION : AudioManager.MODE_NORMAL;
397 }
398
399 private static int getModeForWired(AudioDeviceInfo[] audioDevices)
400 {
401 return getCorrectModeIfContainsAnyOfType(audioDevices, bluetoothTypes);
402 }
403
404 private static int getModeForBluetooth(AudioDeviceInfo[] audioDevices)
405 {
406 return getCorrectModeIfContainsAnyOfType(audioDevices, wiredTypes);
407 }
408
409 private static int getModeForSpeaker(AudioDeviceInfo[] audioDevices)
410 {
411 return getCorrectModeIfContainsAnyOfType(audioDevices, bluetoothTypes, wiredTypes);
412 }
413
414 private static boolean prepareAudioOutput(int id)
415 {
416 final AudioDeviceInfo[] audioDevices =
417 m_audioManager.getDevices(AudioManager.GET_DEVICES_OUTPUTS);
418 for (AudioDeviceInfo deviceInfo : audioDevices) {
419 if (deviceInfo.getId() == id) {
420 if (isBluetoothDevice(deviceInfo))
421 return prepareAudioDevice(deviceInfo, getModeForBluetooth(audioDevices));
422 switch (deviceInfo.getType())
423 {
424 case AudioDeviceInfo.TYPE_BUILTIN_SPEAKER:
425 return prepareAudioDevice(deviceInfo, getModeForSpeaker(audioDevices));
426 case AudioDeviceInfo.TYPE_WIRED_HEADSET:
427 case AudioDeviceInfo.TYPE_WIRED_HEADPHONES:
428 return prepareAudioDevice(deviceInfo, getModeForWired(audioDevices));
429 case AudioDeviceInfo.TYPE_BUILTIN_EARPIECE:
430 // It doesn't work when WIRED HEADPHONES are connected
431 // Earpiece has the lowest priority and setWiredHeadsetOn(boolean)
432 // method to force it is deprecated
433 Log.w(TAG, "Built in Earpiece may not work when "
434 + "Wired Headphones are connected");
435 return prepareAudioDevice(deviceInfo, AudioManager.MODE_IN_CALL);
436 case AudioDeviceInfo.TYPE_HDMI:
437 case AudioDeviceInfo.TYPE_HDMI_ARC:
438 case AudioDeviceInfo.TYPE_HDMI_EARC:
439 return prepareAudioDevice(deviceInfo, AudioManager.MODE_NORMAL);
440 default:
441 return false;
442 }
443 }
444 }
445 return false;
446 }
447
452 private static AudioDeviceInfo getValidCommunicationDevice(AudioDeviceInfo device) {
453 if (device.isSink())
454 return device;
455
456 if (isBluetoothDevice(device)) {
457 // For Bluetooth sources, get output device with the same type and address
458 List<AudioDeviceInfo> communicationDevices = m_audioManager.getAvailableCommunicationDevices();
459 for (AudioDeviceInfo communicationDevice : communicationDevices) {
460 boolean isSameType = communicationDevice.getType() == device.getType();
461 boolean isSameAddress = communicationDevice.getAddress().equals(device.getAddress());
462 if (isSameType && isSameAddress)
463 return communicationDevice;
464 }
465
466 Log.w(TAG, "No matching bluetooth output device found for " + device);
467 }
468
469 return null;
470 }
471
472 private static boolean deviceIsCurrentCommunicationDevice(AudioDeviceInfo device) {
473 if (m_currentCommunicationDeviceId == -1 || device == null) {
474 return false;
475 }
476
477 return m_currentCommunicationDeviceId == device.getId();
478 }
479
480 @UsedFromNativeCode
481 static void releaseAudioDevice(int id) {
482 final AudioDeviceInfo[] devices = m_audioManager.getDevices(AudioManager.GET_DEVICES_ALL);
484 if (device.getId() == id)
485 releaseAudioDevice(device);
486 }
487 }
488
492 private static void releaseAudioDevice(AudioDeviceInfo deviceInfo) {
493 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
494 // If device was used as the communication device, it should be cleared
495 AudioDeviceInfo communicationDevice = getValidCommunicationDevice(deviceInfo);
496 if (!deviceIsCurrentCommunicationDevice(communicationDevice))
497 return;
498
499 if (m_communicationDeviceCounter.decrementAndGet() == 0) {
500 m_audioManager.clearCommunicationDevice();
501 m_currentCommunicationDeviceId = -1;
502 }
503 } else if (isBluetoothDevice(deviceInfo) && m_audioManager.isBluetoothScoOn()
504 && m_scoCounter.decrementAndGet() == 0) {
505 m_audioManager.stopBluetoothSco();
506 m_audioManager.setBluetoothScoOn(false);
507 } else if (deviceInfo.getType() == AudioDeviceInfo.TYPE_BUILTIN_SPEAKER
508 && m_speakerphoneCounter.decrementAndGet() == 0) {
509 m_audioManager.setSpeakerphoneOn(false);
510 }
511 }
512
513 private static boolean prepareAudioDevice(AudioDeviceInfo deviceInfo, int mode)
514 {
515 if (deviceInfo == null)
516 return false;
517
518 m_audioManager.setMode(mode);
519
520 boolean isSink = deviceInfo.isSink();
521 if (isSink)
522 m_currentOutputId = deviceInfo.getId();
523
524 boolean isBluetoothDevice = isBluetoothDevice(deviceInfo);
525 boolean isBluetoothSource = isBluetoothDevice && !isSink;
526 boolean isCommunicationMode = (mode == AudioManager.MODE_IN_CALL
527 || mode == AudioManager.MODE_IN_COMMUNICATION);
528
529 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
530 if (!isBluetoothSource && !isCommunicationMode)
531 return true;
532
533 // For communication modes and Bluetooth sources, it's required to set a communication device
534 AudioDeviceInfo communicationDevice = getValidCommunicationDevice(deviceInfo);
535 if (communicationDevice == null) {
536 Log.w(TAG, "No suitable communication device to set to enable communication via "
537 + deviceInfo.getId());
538 return false;
539 }
540
541 if (deviceIsCurrentCommunicationDevice(communicationDevice)) {
542 m_communicationDeviceCounter.incrementAndGet();
543 return true;
544 } else if (m_audioManager.setCommunicationDevice(communicationDevice)) {
545 // NOTE: Keep track of communication devices we set, as it takes time for it to be
546 // fully operational.
547 // TODO: Other applications can set a different communication device, in which case
548 // we should probably register a listener and clear our tracking when the
549 // communication device unexpectedly changes
550 m_currentCommunicationDeviceId = communicationDevice.getId();
551 m_communicationDeviceCounter.set(1);
552 return true;
553 }
554
555 return false;
556 }
557
558 boolean isSpeakerphoneDevice = deviceInfo.getType() == AudioDeviceInfo.TYPE_BUILTIN_SPEAKER;
559
560 if (isBluetoothSource && m_scoCounter.getAndIncrement() == 0) {
561 m_audioManager.startBluetoothSco();
562 m_audioManager.setBluetoothScoOn(true);
563 } else if (isSpeakerphoneDevice
564 && m_speakerphoneCounter.getAndIncrement() == 0) {
565 // TODO: Check if setting speakerphone is actually required for anything, it's not
566 // recommended in Android docs.
567 m_audioManager.setSpeakerphoneOn(true);
568 }
569
570 return true;
571 }
572
573 private static void streamSound()
574 {
575 byte data[] = new byte[m_bufferSize];
576 while (m_isStreaming) {
577 m_recorder.read(data, 0, m_bufferSize);
578 m_streamPlayer.play();
579 m_streamPlayer.write(data, 0, m_bufferSize);
580 m_streamPlayer.stop();
581 }
582 }
583
584 private static void startSoundStreaming(int inputId, int outputId)
585 {
586 if (m_isStreaming)
587 stopSoundStreaming();
588
589 m_recorder = new AudioRecord(MediaRecorder.AudioSource.DEFAULT, m_sampleRate, m_channels,
590 m_audioFormat, m_bufferSize);
591 m_streamPlayer = new AudioTrack(AudioManager.STREAM_MUSIC, m_sampleRate, m_channels,
592 m_audioFormat, m_bufferSize, AudioTrack.MODE_STREAM);
593
594 final AudioDeviceInfo[] devices = m_audioManager.getDevices(AudioManager.GET_DEVICES_ALL);
595 for (AudioDeviceInfo deviceInfo : devices) {
596 if (deviceInfo.getId() == outputId) {
597 m_streamPlayer.setPreferredDevice(deviceInfo);
598 } else if (deviceInfo.getId() == inputId) {
599 m_recorder.setPreferredDevice(deviceInfo);
600 }
601 }
602
603 m_recorder.startRecording();
604 m_isStreaming = true;
605
606 m_streamingThread = new Thread(new Runnable() {
607 @Override
608 public void run() {
609 streamSound();
610 }
611 });
612
613 m_streamingThread.start();
614 }
615
616 private static void stopSoundStreaming()
617 {
618 if (!m_isStreaming)
619 return;
620
621 m_isStreaming = false;
622 try {
623 m_streamingThread.join();
624 m_streamingThread = null;
625 } catch (InterruptedException e) {
626 e.printStackTrace();
627 }
628 m_recorder.stop();
629 m_recorder.release();
630 m_streamPlayer.release();
631 m_streamPlayer = null;
632 m_recorder = null;
633 }
634}
void AudioDeviceInfo()
[Audio callback capture setup peak meter]
Definition audio.cpp:278
IOBluetoothDevice * device
QPainter Context
int compare(const FunctionNode *f1, const FunctionNode *f2)
Napi::String String
Definition qnapi_p.h:70
QTCONCURRENT_RUN_NODISCARD auto run(QThreadPool *pool, Function &&f, Args &&...args)
#define assert
EGLDeviceEXT * devices
GLsizei GLenum GLenum * types
GLenum type
GLenum mode
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
[0]
GLdouble GLdouble t
Definition qopenglext.h:243
@ Handler
manager put(request, myData, this, [this](QRestReply &reply) { if(reply.isSuccess()) })
[5]