1 /* 2 * Copyright (C) 2008 Ole André Vadla Ravnås <ole.andre.ravnas@tandberg.com> 3 * 4 * This library is free software; you can redistribute it and/or 5 * modify it under the terms of the GNU Library General Public 6 * License as published by the Free Software Foundation; either 7 * version 2 of the License, or (at your option) any later version. 8 * 9 * This library is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 * Library General Public License for more details. 13 * 14 * You should have received a copy of the GNU Library General Public 15 * License along with this library; if not, write to the 16 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, 17 * Boston, MA 02110-1301, USA. 18 */ 19 20 #ifndef __GST_WASAPI_UTIL_H__ 21 #define __GST_WASAPI_UTIL_H__ 22 23 #include <gst/gst.h> 24 #include <gst/audio/audio.h> 25 #include <gst/audio/gstaudiosrc.h> 26 #include <gst/audio/gstaudiosink.h> 27 28 #include <mmdeviceapi.h> 29 #include <audioclient.h> 30 31 #include "gstaudioclient3.h" 32 #include "gstmmdeviceenumerator.h" 33 34 /* Static Caps shared between source, sink, and device provider */ 35 #define GST_WASAPI_STATIC_CAPS "audio/x-raw, " \ 36 "format = (string) " GST_AUDIO_FORMATS_ALL ", " \ 37 "layout = (string) interleaved, " \ 38 "rate = " GST_AUDIO_RATE_RANGE ", " \ 39 "channels = " GST_AUDIO_CHANNELS_RANGE 40 41 /* Standard error path */ 42 #define HR_FAILED_AND(hr,func,and) \ 43 G_STMT_START { \ 44 if (FAILED (hr)) { \ 45 gchar *msg = gst_wasapi_util_hresult_to_string (hr); \ 46 GST_ERROR_OBJECT (self, #func " failed (%x): %s", (guint) hr, msg); \ 47 g_free (msg); \ 48 and; \ 49 } \ 50 } G_STMT_END 51 52 #define HR_FAILED_RET(hr,func,ret) HR_FAILED_AND(hr,func,return ret) 53 54 #define HR_FAILED_GOTO(hr,func,where) HR_FAILED_AND(hr,func,res = FALSE; goto where) 55 56 #define HR_FAILED_ELEMENT_ERROR_AND(hr,func,el,and) \ 57 G_STMT_START { \ 58 if (FAILED (hr)) { \ 59 gchar *msg = gst_wasapi_util_hresult_to_string (hr); \ 60 GST_ERROR_OBJECT (el, #func " failed (%x): %s", (guint) hr, msg); \ 61 if (GST_IS_AUDIO_SRC (el)) \ 62 GST_ELEMENT_ERROR(el, RESOURCE, READ, \ 63 (#func " failed (%x): %s", (guint) hr, msg), (NULL)); \ 64 else \ 65 GST_ELEMENT_ERROR(el, RESOURCE, WRITE, \ 66 (#func " failed (%x): %s", (guint) hr, msg), (NULL)); \ 67 g_free (msg); \ 68 and; \ 69 } \ 70 } G_STMT_END 71 72 #define HR_FAILED_ELEMENT_ERROR_RET(hr,func,el,ret) \ 73 HR_FAILED_ELEMENT_ERROR_AND(hr,func,el,return ret) 74 75 76 /* Device role enum property */ 77 typedef enum 78 { 79 GST_WASAPI_DEVICE_ROLE_CONSOLE, 80 GST_WASAPI_DEVICE_ROLE_MULTIMEDIA, 81 GST_WASAPI_DEVICE_ROLE_COMMS 82 } GstWasapiDeviceRole; 83 #define GST_WASAPI_DEVICE_TYPE_ROLE (gst_wasapi_device_role_get_type()) 84 GType gst_wasapi_device_role_get_type (void); 85 86 /* Utilities */ 87 88 gboolean gst_wasapi_util_have_audioclient3 (void); 89 90 gint gst_wasapi_device_role_to_erole (gint role); 91 92 gint gst_wasapi_erole_to_device_role (gint erole); 93 94 gchar *gst_wasapi_util_hresult_to_string (HRESULT hr); 95 96 gboolean gst_wasapi_util_get_devices (GstMMDeviceEnumerator * enumerator, 97 gboolean active, 98 GList ** devices); 99 100 gboolean gst_wasapi_util_get_device (GstMMDeviceEnumerator * enumerator, 101 gint data_flow, gint role, const wchar_t * device_strid, 102 IMMDevice ** ret_device); 103 104 gboolean gst_wasapi_util_get_audio_client (GstElement * self, 105 IMMDevice * device, IAudioClient ** ret_client); 106 107 gboolean gst_wasapi_util_get_device_format (GstElement * element, 108 gint device_mode, IMMDevice * device, IAudioClient * client, 109 WAVEFORMATEX ** ret_format); 110 111 gboolean gst_wasapi_util_get_render_client (GstElement * element, 112 IAudioClient * client, IAudioRenderClient ** ret_render_client); 113 114 gboolean gst_wasapi_util_get_capture_client (GstElement * element, 115 IAudioClient * client, IAudioCaptureClient ** ret_capture_client); 116 117 gboolean gst_wasapi_util_get_clock (GstElement * element, 118 IAudioClient * client, IAudioClock ** ret_clock); 119 120 gboolean gst_wasapi_util_parse_waveformatex (WAVEFORMATEXTENSIBLE * format, 121 GstCaps * template_caps, GstCaps ** out_caps, 122 GstAudioChannelPosition ** out_positions); 123 124 void gst_wasapi_util_get_best_buffer_sizes (GstAudioRingBufferSpec * spec, 125 gboolean exclusive, REFERENCE_TIME default_period, 126 REFERENCE_TIME min_period, REFERENCE_TIME * ret_period, 127 REFERENCE_TIME * ret_buffer_duration); 128 129 gboolean gst_wasapi_util_initialize_audioclient (GstElement * element, 130 GstAudioRingBufferSpec * spec, IAudioClient * client, 131 WAVEFORMATEX * format, guint sharemode, gboolean low_latency, 132 gboolean loopback, guint * ret_devicep_frames); 133 134 gboolean gst_wasapi_util_initialize_audioclient3 (GstElement * element, 135 GstAudioRingBufferSpec * spec, IAudioClient3 * client, 136 WAVEFORMATEX * format, gboolean low_latency, gboolean loopback, 137 guint * ret_devicep_frames); 138 139 #endif /* __GST_WASAPI_UTIL_H__ */ 140