gst-plugins-good-1.19.1.patch 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  1. diff -Naur a/sys/osxaudio/gstosxcoreaudiocommon.c b/sys/osxaudio/gstosxcoreaudiocommon.c
  2. --- a/sys/osxaudio/gstosxcoreaudiocommon.c 2021-05-31 16:11:47.000000000 -0700
  3. +++ b/sys/osxaudio/gstosxcoreaudiocommon.c 2022-12-24 23:00:48.000000000 -0800
  4. @@ -137,15 +137,16 @@
  5. "osx ring buffer stop ioproc: %p device_id %lu",
  6. core_audio->element->io_proc, (gulong) core_audio->device_id);
  7. + // ###: why is it okay to directly remove from here but not from pause() ?
  8. + if (core_audio->io_proc_active) {
  9. + gst_core_audio_remove_render_callback (core_audio);
  10. + }
  11. +
  12. status = AudioOutputUnitStop (core_audio->audiounit);
  13. if (status) {
  14. GST_WARNING_OBJECT (core_audio->osxbuf,
  15. "AudioOutputUnitStop failed: %d", (int) status);
  16. }
  17. - // ###: why is it okay to directly remove from here but not from pause() ?
  18. - if (core_audio->io_proc_active) {
  19. - gst_core_audio_remove_render_callback (core_audio);
  20. - }
  21. return TRUE;
  22. }
  23. From 8a269018758b52c0df4035ef5989bc0c1f89a685 Mon Sep 17 00:00:00 2001
  24. From: osy <osy@turing.llc>
  25. Date: Sun, 5 Mar 2023 01:28:03 -0800
  26. Subject: [PATCH] osxaudio: detect changes to default device
  27. If the user does not specify a device and we use the default device, then
  28. register a property listener for changes to that device and re-bind the AU.
  29. ---
  30. sys/osxaudio/gstosxaudiosink.c | 4 ++
  31. sys/osxaudio/gstosxaudiosink.h | 1 +
  32. sys/osxaudio/gstosxaudiosrc.c | 4 ++
  33. sys/osxaudio/gstosxaudiosrc.h | 1 +
  34. sys/osxaudio/gstosxcoreaudio.c | 4 ++
  35. sys/osxaudio/gstosxcoreaudio.h | 1 +
  36. sys/osxaudio/gstosxcoreaudiohal.c | 82 ++++++++++++++++++++++++++
  37. sys/osxaudio/gstosxcoreaudioremoteio.c | 6 ++
  38. 8 files changed, 103 insertions(+)
  39. diff --git a/sys/osxaudio/gstosxaudiosink.c b/sys/osxaudio/gstosxaudiosink.c
  40. index 0e9608b69..2b2dcac57 100644
  41. --- a/sys/osxaudio/gstosxaudiosink.c
  42. +++ b/sys/osxaudio/gstosxaudiosink.c
  43. @@ -203,6 +203,7 @@ gst_osx_audio_sink_init (GstOsxAudioSink * sink)
  44. GST_DEBUG ("Initialising object");
  45. sink->device_id = kAudioDeviceUnknown;
  46. + sink->is_default = TRUE;
  47. sink->volume = DEFAULT_VOLUME;
  48. }
  49. @@ -216,6 +217,7 @@ gst_osx_audio_sink_set_property (GObject * object, guint prop_id,
  50. #ifndef HAVE_IOS
  51. case ARG_DEVICE:
  52. sink->device_id = g_value_get_int (value);
  53. + sink->is_default = FALSE;
  54. break;
  55. #endif
  56. case ARG_VOLUME:
  57. @@ -502,6 +504,8 @@ gst_osx_audio_sink_create_ringbuffer (GstAudioBaseSink * sink)
  58. if (ringbuffer->core_audio->device_id != osxsink->device_id)
  59. ringbuffer->core_audio->device_id = osxsink->device_id;
  60. + ringbuffer->core_audio->is_following_default = osxsink->is_default;
  61. +
  62. return GST_AUDIO_RING_BUFFER (ringbuffer);
  63. }
  64. diff --git a/sys/osxaudio/gstosxaudiosink.h b/sys/osxaudio/gstosxaudiosink.h
  65. index 2f55c4d2e..cdf9bf1f8 100644
  66. --- a/sys/osxaudio/gstosxaudiosink.h
  67. +++ b/sys/osxaudio/gstosxaudiosink.h
  68. @@ -82,6 +82,7 @@ struct _GstOsxAudioSink
  69. GstAudioBaseSink sink;
  70. AudioDeviceID device_id;
  71. + gboolean is_default;
  72. AudioUnit audiounit;
  73. double volume;
  74. diff --git a/sys/osxaudio/gstosxaudiosrc.c b/sys/osxaudio/gstosxaudiosrc.c
  75. index c3c445b47..422cfaea2 100644
  76. --- a/sys/osxaudio/gstosxaudiosrc.c
  77. +++ b/sys/osxaudio/gstosxaudiosrc.c
  78. @@ -166,6 +166,7 @@ gst_osx_audio_src_init (GstOsxAudioSrc * src)
  79. gst_base_src_set_live (GST_BASE_SRC (src), TRUE);
  80. src->device_id = kAudioDeviceUnknown;
  81. + src->is_default = TRUE;
  82. }
  83. static void
  84. @@ -177,6 +178,7 @@ gst_osx_audio_src_set_property (GObject * object, guint prop_id,
  85. switch (prop_id) {
  86. case ARG_DEVICE:
  87. src->device_id = g_value_get_int (value);
  88. + src->is_default = FALSE;
  89. break;
  90. default:
  91. G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
  92. @@ -323,6 +325,8 @@ gst_osx_audio_src_create_ringbuffer (GstAudioBaseSrc * src)
  93. if (ringbuffer->core_audio->device_id != osxsrc->device_id)
  94. ringbuffer->core_audio->device_id = osxsrc->device_id;
  95. + ringbuffer->core_audio->is_following_default = osxsrc->is_default;
  96. +
  97. return GST_AUDIO_RING_BUFFER (ringbuffer);
  98. }
  99. diff --git a/sys/osxaudio/gstosxaudiosrc.h b/sys/osxaudio/gstosxaudiosrc.h
  100. index 9d825b028..0e16331ee 100644
  101. --- a/sys/osxaudio/gstosxaudiosrc.h
  102. +++ b/sys/osxaudio/gstosxaudiosrc.h
  103. @@ -73,6 +73,7 @@ struct _GstOsxAudioSrc
  104. GstAudioBaseSrc src;
  105. AudioDeviceID device_id;
  106. + gboolean is_default;
  107. };
  108. struct _GstOsxAudioSrcClass
  109. diff --git a/sys/osxaudio/gstosxcoreaudio.c b/sys/osxaudio/gstosxcoreaudio.c
  110. index 4fae6aff3..0a994c4d4 100644
  111. --- a/sys/osxaudio/gstosxcoreaudio.c
  112. +++ b/sys/osxaudio/gstosxcoreaudio.c
  113. @@ -64,6 +64,7 @@ gst_core_audio_init (GstCoreAudio * core_audio)
  114. core_audio->is_passthrough = FALSE;
  115. core_audio->device_id = kAudioDeviceUnknown;
  116. core_audio->is_src = FALSE;
  117. + core_audio->is_following_default = FALSE;
  118. core_audio->audiounit = NULL;
  119. core_audio->cached_caps = NULL;
  120. core_audio->cached_caps_valid = FALSE;
  121. @@ -134,6 +135,9 @@ gst_core_audio_close (GstCoreAudio * core_audio)
  122. {
  123. OSStatus status;
  124. + if (!gst_core_audio_close_impl (core_audio))
  125. + return FALSE;
  126. +
  127. /* Uninitialize the AudioUnit */
  128. status = AudioUnitUninitialize (core_audio->audiounit);
  129. if (status) {
  130. diff --git a/sys/osxaudio/gstosxcoreaudio.h b/sys/osxaudio/gstosxcoreaudio.h
  131. index 8d3f91fa7..68de91e0b 100644
  132. --- a/sys/osxaudio/gstosxcoreaudio.h
  133. +++ b/sys/osxaudio/gstosxcoreaudio.h
  134. @@ -87,6 +87,7 @@ struct _GstCoreAudio
  135. gboolean is_src;
  136. gboolean is_passthrough;
  137. + gboolean is_following_default;
  138. AudioDeviceID device_id;
  139. gboolean cached_caps_valid; /* thread-safe flag */
  140. GstCaps *cached_caps;
  141. diff --git a/sys/osxaudio/gstosxcoreaudiohal.c b/sys/osxaudio/gstosxcoreaudiohal.c
  142. index 79fed0d97..dbb6b89f4 100644
  143. --- a/sys/osxaudio/gstosxcoreaudiohal.c
  144. +++ b/sys/osxaudio/gstosxcoreaudiohal.c
  145. @@ -1013,6 +1013,35 @@ _io_proc_spdif_stop (GstCoreAudio * core_audio)
  146. * Implementation *
  147. **********************/
  148. +static OSStatus
  149. +_default_device_changed_listener (AudioObjectID inObjectID,
  150. + UInt32 inNumberAddresses,
  151. + const AudioObjectPropertyAddress inAddresses[], void *inClientData)
  152. +{
  153. + OSStatus status = noErr;
  154. + guint i;
  155. + GstCoreAudio *core_audio = inClientData;
  156. + AudioObjectPropertySelector prop_selector;
  157. + AudioDeviceID default_device_id;
  158. +
  159. + prop_selector = core_audio->is_src ? kAudioHardwarePropertyDefaultInputDevice :
  160. + kAudioHardwarePropertyDefaultOutputDevice;
  161. +
  162. + for (i = 0; i < inNumberAddresses; i++) {
  163. + if (inAddresses[i].mSelector == prop_selector) {
  164. + default_device_id = _audio_system_get_default_device (!core_audio->is_src);
  165. + if (default_device_id != kAudioDeviceUnknown) {
  166. + core_audio->device_id = default_device_id;
  167. + if (!gst_core_audio_bind_device (core_audio)) {
  168. + GST_DEBUG ("Could not bind changed default device");
  169. + }
  170. + }
  171. + break;
  172. + }
  173. + }
  174. + return (status);
  175. +}
  176. +
  177. static gboolean
  178. gst_core_audio_open_impl (GstCoreAudio * core_audio)
  179. {
  180. @@ -1034,6 +1063,7 @@ gst_core_audio_open_impl (GstCoreAudio * core_audio)
  181. */
  182. ret = gst_core_audio_open_device (core_audio, kAudioUnitSubType_HALOutput,
  183. "HALOutput");
  184. +
  185. if (!ret) {
  186. GST_DEBUG ("Could not open device");
  187. goto done;
  188. @@ -1045,10 +1075,62 @@ gst_core_audio_open_impl (GstCoreAudio * core_audio)
  189. goto done;
  190. }
  191. + if (core_audio->is_following_default) {
  192. + OSStatus status;
  193. + AudioObjectPropertySelector prop_selector;
  194. +
  195. + prop_selector = core_audio->is_src ? kAudioHardwarePropertyDefaultInputDevice :
  196. + kAudioHardwarePropertyDefaultOutputDevice;
  197. + AudioObjectPropertyAddress propAddress = {
  198. + prop_selector,
  199. + kAudioObjectPropertyScopeGlobal,
  200. + kAudioObjectPropertyElementMaster
  201. + };
  202. +
  203. + /* Install the property listener */
  204. + status = AudioObjectAddPropertyListener (kAudioObjectSystemObject,
  205. + &propAddress, _default_device_changed_listener,
  206. + (void *) core_audio);
  207. + if (status != noErr) {
  208. + GST_ERROR_OBJECT (core_audio->osxbuf,
  209. + "AudioObjectAddPropertyListener failed: %d", (int) status);
  210. + ret = FALSE;
  211. + }
  212. + }
  213. +
  214. done:
  215. return ret;
  216. }
  217. +static gboolean
  218. +gst_core_audio_close_impl (GstCoreAudio * core_audio)
  219. +{
  220. + if (core_audio->is_following_default) {
  221. + OSStatus status;
  222. + AudioObjectPropertySelector prop_selector;
  223. +
  224. + prop_selector = core_audio->is_src ? kAudioHardwarePropertyDefaultInputDevice :
  225. + kAudioHardwarePropertyDefaultOutputDevice;
  226. + AudioObjectPropertyAddress propAddress = {
  227. + prop_selector,
  228. + kAudioObjectPropertyScopeGlobal,
  229. + kAudioObjectPropertyElementMaster
  230. + };
  231. +
  232. + /* Remove the property listener */
  233. + status = AudioObjectRemovePropertyListener (kAudioObjectSystemObject,
  234. + &propAddress, _default_device_changed_listener,
  235. + (void *) core_audio);
  236. + if (status != noErr) {
  237. + GST_ERROR_OBJECT (core_audio->osxbuf,
  238. + "AudioObjectRemovePropertyListener failed: %d", (int) status);
  239. + return FALSE;
  240. + }
  241. + }
  242. +
  243. + return TRUE;
  244. +}
  245. +
  246. static gboolean
  247. gst_core_audio_start_processing_impl (GstCoreAudio * core_audio)
  248. {
  249. diff --git a/sys/osxaudio/gstosxcoreaudioremoteio.c b/sys/osxaudio/gstosxcoreaudioremoteio.c
  250. index 10f5b18e4..d70910116 100644
  251. --- a/sys/osxaudio/gstosxcoreaudioremoteio.c
  252. +++ b/sys/osxaudio/gstosxcoreaudioremoteio.c
  253. @@ -29,6 +29,12 @@ gst_core_audio_open_impl (GstCoreAudio * core_audio)
  254. "RemoteIO");
  255. }
  256. +static gboolean
  257. +gst_core_audio_close_impl (GstCoreAudio * core_audio)
  258. +{
  259. + return TRUE;
  260. +}
  261. +
  262. static gboolean
  263. gst_core_audio_start_processing_impl (GstCoreAudio * core_audio)
  264. {
  265. --
  266. 2.37.1 (Apple Git-137.1)