OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
(...skipping 23 matching lines...) Expand all Loading... |
34 } | 34 } |
35 | 35 |
36 ~AutoPulseLock() { | 36 ~AutoPulseLock() { |
37 LATE(pa_threaded_mainloop_unlock)(pa_mainloop_); | 37 LATE(pa_threaded_mainloop_unlock)(pa_mainloop_); |
38 } | 38 } |
39 | 39 |
40 private: | 40 private: |
41 pa_threaded_mainloop* const pa_mainloop_; | 41 pa_threaded_mainloop* const pa_mainloop_; |
42 }; | 42 }; |
43 | 43 |
44 AudioMixerManagerLinuxPulse::AudioMixerManagerLinuxPulse(const int32_t id) : | 44 AudioMixerManagerLinuxPulse::AudioMixerManagerLinuxPulse(const int32_t id) |
45 _id(id), | 45 : _id(id), |
46 _paOutputDeviceIndex(-1), | 46 _paOutputDeviceIndex(-1), |
47 _paInputDeviceIndex(-1), | 47 _paInputDeviceIndex(-1), |
48 _paPlayStream(NULL), | 48 _paPlayStream(nullptr), |
49 _paRecStream(NULL), | 49 _paRecStream(nullptr), |
50 _paMainloop(NULL), | 50 _paMainloop(nullptr), |
51 _paContext(NULL), | 51 _paContext(nullptr), |
52 _paVolume(0), | 52 _paVolume(0), |
53 _paMute(0), | 53 _paMute(0), |
54 _paVolSteps(0), | 54 _paVolSteps(0), |
55 _paSpeakerMute(false), | 55 _paSpeakerMute(false), |
56 _paSpeakerVolume(PA_VOLUME_NORM), | 56 _paSpeakerVolume(PA_VOLUME_NORM), |
57 _paChannels(0), | 57 _paChannels(0), |
58 _paObjectsSet(false) | 58 _paObjectsSet(false) { |
59 { | 59 WEBRTC_TRACE(kTraceMemory, kTraceAudioDevice, _id, "%s constructed", |
60 WEBRTC_TRACE(kTraceMemory, kTraceAudioDevice, _id, | 60 __FUNCTION__); |
61 "%s constructed", __FUNCTION__); | |
62 } | 61 } |
63 | 62 |
64 AudioMixerManagerLinuxPulse::~AudioMixerManagerLinuxPulse() | 63 AudioMixerManagerLinuxPulse::~AudioMixerManagerLinuxPulse() |
65 { | 64 { |
66 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | 65 RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
67 WEBRTC_TRACE(kTraceMemory, kTraceAudioDevice, _id, | 66 WEBRTC_TRACE(kTraceMemory, kTraceAudioDevice, _id, |
68 "%s destructed", __FUNCTION__); | 67 "%s destructed", __FUNCTION__); |
69 | 68 |
70 Close(); | 69 Close(); |
71 } | 70 } |
(...skipping 29 matching lines...) Expand all Loading... |
101 | 100 |
102 int32_t AudioMixerManagerLinuxPulse::Close() | 101 int32_t AudioMixerManagerLinuxPulse::Close() |
103 { | 102 { |
104 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | 103 RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
105 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, "%s", | 104 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, "%s", |
106 __FUNCTION__); | 105 __FUNCTION__); |
107 | 106 |
108 CloseSpeaker(); | 107 CloseSpeaker(); |
109 CloseMicrophone(); | 108 CloseMicrophone(); |
110 | 109 |
111 _paMainloop = NULL; | 110 _paMainloop = nullptr; |
112 _paContext = NULL; | 111 _paContext = nullptr; |
113 _paObjectsSet = false; | 112 _paObjectsSet = false; |
114 | 113 |
115 return 0; | 114 return 0; |
116 | 115 |
117 } | 116 } |
118 | 117 |
119 int32_t AudioMixerManagerLinuxPulse::CloseSpeaker() | 118 int32_t AudioMixerManagerLinuxPulse::CloseSpeaker() |
120 { | 119 { |
121 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | 120 RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
122 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, "%s", | 121 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, "%s", |
123 __FUNCTION__); | 122 __FUNCTION__); |
124 | 123 |
125 // Reset the index to -1 | 124 // Reset the index to -1 |
126 _paOutputDeviceIndex = -1; | 125 _paOutputDeviceIndex = -1; |
127 _paPlayStream = NULL; | 126 _paPlayStream = nullptr; |
128 | 127 |
129 return 0; | 128 return 0; |
130 } | 129 } |
131 | 130 |
132 int32_t AudioMixerManagerLinuxPulse::CloseMicrophone() | 131 int32_t AudioMixerManagerLinuxPulse::CloseMicrophone() |
133 { | 132 { |
134 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | 133 RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
135 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, "%s", | 134 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, "%s", |
136 __FUNCTION__); | 135 __FUNCTION__); |
137 | 136 |
138 // Reset the index to -1 | 137 // Reset the index to -1 |
139 _paInputDeviceIndex = -1; | 138 _paInputDeviceIndex = -1; |
140 _paRecStream = NULL; | 139 _paRecStream = nullptr; |
141 | 140 |
142 return 0; | 141 return 0; |
143 } | 142 } |
144 | 143 |
145 int32_t AudioMixerManagerLinuxPulse::SetPlayStream(pa_stream* playStream) | 144 int32_t AudioMixerManagerLinuxPulse::SetPlayStream(pa_stream* playStream) |
146 { | 145 { |
147 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | 146 RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
148 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, | 147 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, |
149 "AudioMixerManagerLinuxPulse::SetPlayStream(playStream)"); | 148 "AudioMixerManagerLinuxPulse::SetPlayStream(playStream)"); |
150 | 149 |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
264 { | 263 { |
265 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, | 264 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, |
266 " could not get sample specification"); | 265 " could not get sample specification"); |
267 return -1; | 266 return -1; |
268 } | 267 } |
269 | 268 |
270 // Set the same volume for all channels | 269 // Set the same volume for all channels |
271 pa_cvolume cVolumes; | 270 pa_cvolume cVolumes; |
272 LATE(pa_cvolume_set)(&cVolumes, spec->channels, volume); | 271 LATE(pa_cvolume_set)(&cVolumes, spec->channels, volume); |
273 | 272 |
274 pa_operation* paOperation = NULL; | 273 pa_operation* paOperation = nullptr; |
275 paOperation = LATE(pa_context_set_sink_input_volume)( | 274 paOperation = LATE(pa_context_set_sink_input_volume)( |
276 _paContext, | 275 _paContext, LATE(pa_stream_get_index)(_paPlayStream), &cVolumes, |
277 LATE(pa_stream_get_index)(_paPlayStream), | 276 PaSetVolumeCallback, nullptr); |
278 &cVolumes, | |
279 PaSetVolumeCallback, NULL); | |
280 if (!paOperation) | 277 if (!paOperation) |
281 { | 278 { |
282 setFailed = true; | 279 setFailed = true; |
283 } | 280 } |
284 | 281 |
285 // Don't need to wait for the completion | 282 // Don't need to wait for the completion |
286 LATE(pa_operation_unref)(paOperation); | 283 LATE(pa_operation_unref)(paOperation); |
287 } else | 284 } else |
288 { | 285 { |
289 // We have not created a stream or it's not connected to the sink | 286 // We have not created a stream or it's not connected to the sink |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
440 } | 437 } |
441 | 438 |
442 bool setFailed(false); | 439 bool setFailed(false); |
443 | 440 |
444 if (_paPlayStream && (LATE(pa_stream_get_state)(_paPlayStream) | 441 if (_paPlayStream && (LATE(pa_stream_get_state)(_paPlayStream) |
445 != PA_STREAM_UNCONNECTED)) | 442 != PA_STREAM_UNCONNECTED)) |
446 { | 443 { |
447 // We can only really mute if we have a connected stream | 444 // We can only really mute if we have a connected stream |
448 AutoPulseLock auto_lock(_paMainloop); | 445 AutoPulseLock auto_lock(_paMainloop); |
449 | 446 |
450 pa_operation* paOperation = NULL; | 447 pa_operation* paOperation = nullptr; |
451 paOperation = LATE(pa_context_set_sink_input_mute)( | 448 paOperation = LATE(pa_context_set_sink_input_mute)( |
452 _paContext, | 449 _paContext, LATE(pa_stream_get_index)(_paPlayStream), (int)enable, |
453 LATE(pa_stream_get_index)(_paPlayStream), | 450 PaSetVolumeCallback, nullptr); |
454 (int) enable, | |
455 PaSetVolumeCallback, | |
456 NULL); | |
457 if (!paOperation) | 451 if (!paOperation) |
458 { | 452 { |
459 setFailed = true; | 453 setFailed = true; |
460 } | 454 } |
461 | 455 |
462 // Don't need to wait for the completion | 456 // Don't need to wait for the completion |
463 LATE(pa_operation_unref)(paOperation); | 457 LATE(pa_operation_unref)(paOperation); |
464 } else | 458 } else |
465 { | 459 { |
466 // We have not created a stream or it's not connected to the sink | 460 // We have not created a stream or it's not connected to the sink |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
560 | 554 |
561 // Get the actual stream device index if we have a connected stream | 555 // Get the actual stream device index if we have a connected stream |
562 // The device used by the stream can be changed | 556 // The device used by the stream can be changed |
563 // during the call | 557 // during the call |
564 if (_paRecStream && (LATE(pa_stream_get_state)(_paRecStream) | 558 if (_paRecStream && (LATE(pa_stream_get_state)(_paRecStream) |
565 != PA_STREAM_UNCONNECTED)) | 559 != PA_STREAM_UNCONNECTED)) |
566 { | 560 { |
567 deviceIndex = LATE(pa_stream_get_device_index)(_paRecStream); | 561 deviceIndex = LATE(pa_stream_get_device_index)(_paRecStream); |
568 } | 562 } |
569 | 563 |
570 pa_operation* paOperation = NULL; | 564 pa_operation* paOperation = nullptr; |
571 | 565 |
572 // Get info for this source | 566 // Get info for this source |
573 // We want to know if the actual device can record in stereo | 567 // We want to know if the actual device can record in stereo |
574 paOperation = LATE(pa_context_get_source_info_by_index)( | 568 paOperation = LATE(pa_context_get_source_info_by_index)( |
575 _paContext, deviceIndex, | 569 _paContext, deviceIndex, |
576 PaSourceInfoCallback, | 570 PaSourceInfoCallback, |
577 (void*) this); | 571 (void*) this); |
578 | 572 |
579 WaitForOperationCompletion(paOperation); | 573 WaitForOperationCompletion(paOperation); |
580 | 574 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
612 enable); | 606 enable); |
613 | 607 |
614 if (_paInputDeviceIndex == -1) | 608 if (_paInputDeviceIndex == -1) |
615 { | 609 { |
616 WEBRTC_TRACE(kTraceWarning, kTraceAudioDevice, _id, | 610 WEBRTC_TRACE(kTraceWarning, kTraceAudioDevice, _id, |
617 " input device index has not been set"); | 611 " input device index has not been set"); |
618 return -1; | 612 return -1; |
619 } | 613 } |
620 | 614 |
621 bool setFailed(false); | 615 bool setFailed(false); |
622 pa_operation* paOperation = NULL; | 616 pa_operation* paOperation = nullptr; |
623 | 617 |
624 uint32_t deviceIndex = (uint32_t) _paInputDeviceIndex; | 618 uint32_t deviceIndex = (uint32_t) _paInputDeviceIndex; |
625 | 619 |
626 AutoPulseLock auto_lock(_paMainloop); | 620 AutoPulseLock auto_lock(_paMainloop); |
627 | 621 |
628 // Get the actual stream device index if we have a connected stream | 622 // Get the actual stream device index if we have a connected stream |
629 // The device used by the stream can be changed | 623 // The device used by the stream can be changed |
630 // during the call | 624 // during the call |
631 if (_paRecStream && (LATE(pa_stream_get_state)(_paRecStream) | 625 if (_paRecStream && (LATE(pa_stream_get_state)(_paRecStream) |
632 != PA_STREAM_UNCONNECTED)) | 626 != PA_STREAM_UNCONNECTED)) |
633 { | 627 { |
634 deviceIndex = LATE(pa_stream_get_device_index)(_paRecStream); | 628 deviceIndex = LATE(pa_stream_get_device_index)(_paRecStream); |
635 } | 629 } |
636 | 630 |
637 // Set mute switch for the source | 631 // Set mute switch for the source |
638 paOperation = LATE(pa_context_set_source_mute_by_index)( | 632 paOperation = LATE(pa_context_set_source_mute_by_index)( |
639 _paContext, deviceIndex, | 633 _paContext, deviceIndex, enable, PaSetVolumeCallback, nullptr); |
640 enable, | |
641 PaSetVolumeCallback, NULL); | |
642 | 634 |
643 if (!paOperation) | 635 if (!paOperation) |
644 { | 636 { |
645 setFailed = true; | 637 setFailed = true; |
646 } | 638 } |
647 | 639 |
648 // Don't need to wait for this to complete. | 640 // Don't need to wait for this to complete. |
649 LATE(pa_operation_unref)(paOperation); | 641 LATE(pa_operation_unref)(paOperation); |
650 | 642 |
651 if (setFailed) | 643 if (setFailed) |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
807 // Get the actual stream device index if we have a connected stream | 799 // Get the actual stream device index if we have a connected stream |
808 // The device used by the stream can be changed | 800 // The device used by the stream can be changed |
809 // during the call | 801 // during the call |
810 if (_paRecStream && (LATE(pa_stream_get_state)(_paRecStream) | 802 if (_paRecStream && (LATE(pa_stream_get_state)(_paRecStream) |
811 != PA_STREAM_UNCONNECTED)) | 803 != PA_STREAM_UNCONNECTED)) |
812 { | 804 { |
813 deviceIndex = LATE(pa_stream_get_device_index)(_paRecStream); | 805 deviceIndex = LATE(pa_stream_get_device_index)(_paRecStream); |
814 } | 806 } |
815 | 807 |
816 bool setFailed(false); | 808 bool setFailed(false); |
817 pa_operation* paOperation = NULL; | 809 pa_operation* paOperation = nullptr; |
818 | 810 |
819 // Get the number of channels for this source | 811 // Get the number of channels for this source |
820 paOperation | 812 paOperation |
821 = LATE(pa_context_get_source_info_by_index)(_paContext, deviceIndex, | 813 = LATE(pa_context_get_source_info_by_index)(_paContext, deviceIndex, |
822 PaSourceInfoCallback, | 814 PaSourceInfoCallback, |
823 (void*) this); | 815 (void*) this); |
824 | 816 |
825 WaitForOperationCompletion(paOperation); | 817 WaitForOperationCompletion(paOperation); |
826 | 818 |
827 uint8_t channels = _paChannels; | 819 uint8_t channels = _paChannels; |
828 pa_cvolume cVolumes; | 820 pa_cvolume cVolumes; |
829 LATE(pa_cvolume_set)(&cVolumes, channels, volume); | 821 LATE(pa_cvolume_set)(&cVolumes, channels, volume); |
830 | 822 |
831 // Set the volume for the source | 823 // Set the volume for the source |
832 paOperation | 824 paOperation = LATE(pa_context_set_source_volume_by_index)( |
833 = LATE(pa_context_set_source_volume_by_index)(_paContext, deviceIndex, | 825 _paContext, deviceIndex, &cVolumes, PaSetVolumeCallback, nullptr); |
834 &cVolumes, | |
835 PaSetVolumeCallback, | |
836 NULL); | |
837 | 826 |
838 if (!paOperation) | 827 if (!paOperation) |
839 { | 828 { |
840 setFailed = true; | 829 setFailed = true; |
841 } | 830 } |
842 | 831 |
843 // Don't need to wait for this to complete. | 832 // Don't need to wait for this to complete. |
844 LATE(pa_operation_unref)(paOperation); | 833 LATE(pa_operation_unref)(paOperation); |
845 | 834 |
846 if (setFailed) | 835 if (setFailed) |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
945 | 934 |
946 // Get the actual stream device index if we have a connected stream | 935 // Get the actual stream device index if we have a connected stream |
947 // The device used by the stream can be changed | 936 // The device used by the stream can be changed |
948 // during the call | 937 // during the call |
949 if (_paRecStream && (LATE(pa_stream_get_state)(_paRecStream) | 938 if (_paRecStream && (LATE(pa_stream_get_state)(_paRecStream) |
950 != PA_STREAM_UNCONNECTED)) | 939 != PA_STREAM_UNCONNECTED)) |
951 { | 940 { |
952 deviceIndex = LATE(pa_stream_get_device_index)(_paRecStream); | 941 deviceIndex = LATE(pa_stream_get_device_index)(_paRecStream); |
953 } | 942 } |
954 | 943 |
955 pa_operation* paOperation = NULL; | 944 pa_operation* paOperation = nullptr; |
956 | 945 |
957 // Get info for this source | 946 // Get info for this source |
958 paOperation | 947 paOperation |
959 = LATE(pa_context_get_source_info_by_index)(_paContext, deviceIndex, | 948 = LATE(pa_context_get_source_info_by_index)(_paContext, deviceIndex, |
960 PaSourceInfoCallback, | 949 PaSourceInfoCallback, |
961 (void*) this); | 950 (void*) this); |
962 | 951 |
963 WaitForOperationCompletion(paOperation); | 952 WaitForOperationCompletion(paOperation); |
964 | 953 |
965 stepSize = static_cast<uint16_t> ((PA_VOLUME_NORM + 1) / _paVolSteps); | 954 stepSize = static_cast<uint16_t> ((PA_VOLUME_NORM + 1) / _paVolSteps); |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1106 { | 1095 { |
1107 while (LATE(pa_operation_get_state)(paOperation) == PA_OPERATION_RUNNING) | 1096 while (LATE(pa_operation_get_state)(paOperation) == PA_OPERATION_RUNNING) |
1108 { | 1097 { |
1109 LATE(pa_threaded_mainloop_wait)(_paMainloop); | 1098 LATE(pa_threaded_mainloop_wait)(_paMainloop); |
1110 } | 1099 } |
1111 | 1100 |
1112 LATE(pa_operation_unref)(paOperation); | 1101 LATE(pa_operation_unref)(paOperation); |
1113 } | 1102 } |
1114 | 1103 |
1115 bool AudioMixerManagerLinuxPulse::GetSinkInputInfo() const { | 1104 bool AudioMixerManagerLinuxPulse::GetSinkInputInfo() const { |
1116 pa_operation* paOperation = NULL; | 1105 pa_operation* paOperation = nullptr; |
1117 | 1106 |
1118 AutoPulseLock auto_lock(_paMainloop); | 1107 AutoPulseLock auto_lock(_paMainloop); |
1119 // Get info for this stream (sink input). | 1108 // Get info for this stream (sink input). |
1120 paOperation = LATE(pa_context_get_sink_input_info)( | 1109 paOperation = LATE(pa_context_get_sink_input_info)( |
1121 _paContext, | 1110 _paContext, |
1122 LATE(pa_stream_get_index)(_paPlayStream), | 1111 LATE(pa_stream_get_index)(_paPlayStream), |
1123 PaSinkInputInfoCallback, | 1112 PaSinkInputInfoCallback, |
1124 (void*) this); | 1113 (void*) this); |
1125 | 1114 |
1126 WaitForOperationCompletion(paOperation); | 1115 WaitForOperationCompletion(paOperation); |
1127 return true; | 1116 return true; |
1128 } | 1117 } |
1129 | 1118 |
1130 bool AudioMixerManagerLinuxPulse::GetSinkInfoByIndex( | 1119 bool AudioMixerManagerLinuxPulse::GetSinkInfoByIndex( |
1131 int device_index) const { | 1120 int device_index) const { |
1132 pa_operation* paOperation = NULL; | 1121 pa_operation* paOperation = nullptr; |
1133 | 1122 |
1134 AutoPulseLock auto_lock(_paMainloop); | 1123 AutoPulseLock auto_lock(_paMainloop); |
1135 paOperation = LATE(pa_context_get_sink_info_by_index)(_paContext, | 1124 paOperation = LATE(pa_context_get_sink_info_by_index)(_paContext, |
1136 device_index, PaSinkInfoCallback, (void*) this); | 1125 device_index, PaSinkInfoCallback, (void*) this); |
1137 | 1126 |
1138 WaitForOperationCompletion(paOperation); | 1127 WaitForOperationCompletion(paOperation); |
1139 return true; | 1128 return true; |
1140 } | 1129 } |
1141 | 1130 |
1142 bool AudioMixerManagerLinuxPulse::GetSourceInfoByIndex( | 1131 bool AudioMixerManagerLinuxPulse::GetSourceInfoByIndex( |
1143 int device_index) const { | 1132 int device_index) const { |
1144 pa_operation* paOperation = NULL; | 1133 pa_operation* paOperation = nullptr; |
1145 | 1134 |
1146 AutoPulseLock auto_lock(_paMainloop); | 1135 AutoPulseLock auto_lock(_paMainloop); |
1147 paOperation = LATE(pa_context_get_source_info_by_index)( | 1136 paOperation = LATE(pa_context_get_source_info_by_index)( |
1148 _paContext, device_index, PaSourceInfoCallback, (void*) this); | 1137 _paContext, device_index, PaSourceInfoCallback, (void*) this); |
1149 | 1138 |
1150 WaitForOperationCompletion(paOperation); | 1139 WaitForOperationCompletion(paOperation); |
1151 return true; | 1140 return true; |
1152 } | 1141 } |
1153 | 1142 |
1154 } | 1143 } |
OLD | NEW |