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 33 /* Static Caps shared between source, sink, and device provider */ 34 #define GST_WASAPI_STATIC_CAPS "audio/x-raw, " \ 35 "format = (string) " GST_AUDIO_FORMATS_ALL ", " \ 36 "layout = (string) interleaved, " \ 37 "rate = " GST_AUDIO_RATE_RANGE ", " \ 38 "channels = " GST_AUDIO_CHANNELS_RANGE 39 40 /* Standard error path */ 41 #define HR_FAILED_AND(hr,func,and) \ 42 G_STMT_START { \ 43 if (FAILED (hr)) { \ 44 gchar *msg = gst_wasapi_util_hresult_to_string (hr); \ 45 GST_ERROR_OBJECT (self, #func " failed (%x): %s", (guint) hr, msg); \ 46 g_free (msg); \ 47 and; \ 48 } \ 49 } G_STMT_END 50 51 #define HR_FAILED_RET(hr,func,ret) HR_FAILED_AND(hr,func,return ret) 52 53 #define HR_FAILED_GOTO(hr,func,where) HR_FAILED_AND(hr,func,res = FALSE; goto where) 54 55 #define HR_FAILED_ELEMENT_ERROR_AND(hr,func,el,and) \ 56 G_STMT_START { \ 57 if (FAILED (hr)) { \ 58 gchar *msg = gst_wasapi_util_hresult_to_string (hr); \ 59 GST_ERROR_OBJECT (el, #func " failed (%x): %s", (guint) hr, msg); \ 60 if (GST_IS_AUDIO_SRC (el)) \ 61 GST_ELEMENT_ERROR(el, RESOURCE, READ, \ 62 (#func " failed (%x): %s", (guint) hr, msg), (NULL)); \ 63 else \ 64 GST_ELEMENT_ERROR(el, RESOURCE, WRITE, \ 65 (#func " failed (%x): %s", (guint) hr, msg), (NULL)); \ 66 g_free (msg); \ 67 and; \ 68 } \ 69 } G_STMT_END 70 71 #define HR_FAILED_ELEMENT_ERROR_RET(hr,func,el,ret) \ 72 HR_FAILED_ELEMENT_ERROR_AND(hr,func,el,return ret) 73 74 75 /* Device role enum property */ 76 typedef enum 77 { 78 GST_WASAPI_DEVICE_ROLE_CONSOLE, 79 GST_WASAPI_DEVICE_ROLE_MULTIMEDIA, 80 GST_WASAPI_DEVICE_ROLE_COMMS 81 } GstWasapiDeviceRole; 82 #define GST_WASAPI_DEVICE_TYPE_ROLE (gst_wasapi_device_role_get_type()) 83 GType gst_wasapi_device_role_get_type (void); 84 85 /* Utilities */ 86 87 gboolean gst_wasapi_util_have_audioclient3 (void); 88 89 gint gst_wasapi_device_role_to_erole (gint role); 90 91 gint gst_wasapi_erole_to_device_role (gint erole); 92 93 gchar *gst_wasapi_util_hresult_to_string (HRESULT hr); 94 95 gboolean gst_wasapi_util_get_devices (GstObject * element, gboolean active, 96 GList ** devices); 97 98 gboolean gst_wasapi_util_get_device_client (GstElement * element, 99 gint data_flow, gint role, const wchar_t * device_strid, 100 IMMDevice ** ret_device, IAudioClient ** ret_client); 101 102 gboolean gst_wasapi_util_get_device_format (GstElement * element, 103 gint device_mode, IMMDevice * device, IAudioClient * client, 104 WAVEFORMATEX ** ret_format); 105 106 gboolean gst_wasapi_util_get_render_client (GstElement * element, 107 IAudioClient * client, IAudioRenderClient ** ret_render_client); 108 109 gboolean gst_wasapi_util_get_capture_client (GstElement * element, 110 IAudioClient * client, IAudioCaptureClient ** ret_capture_client); 111 112 gboolean gst_wasapi_util_get_clock (GstElement * element, 113 IAudioClient * client, IAudioClock ** ret_clock); 114 115 gboolean gst_wasapi_util_parse_waveformatex (WAVEFORMATEXTENSIBLE * format, 116 GstCaps * template_caps, GstCaps ** out_caps, 117 GstAudioChannelPosition ** out_positions); 118 119 void gst_wasapi_util_get_best_buffer_sizes (GstAudioRingBufferSpec * spec, 120 gboolean exclusive, REFERENCE_TIME default_period, 121 REFERENCE_TIME min_period, REFERENCE_TIME * ret_period, 122 REFERENCE_TIME * ret_buffer_duration); 123 124 gboolean gst_wasapi_util_initialize_audioclient (GstElement * element, 125 GstAudioRingBufferSpec * spec, IAudioClient * client, 126 WAVEFORMATEX * format, guint sharemode, gboolean low_latency, 127 gboolean loopback, guint * ret_devicep_frames); 128 129 gboolean gst_wasapi_util_initialize_audioclient3 (GstElement * element, 130 GstAudioRingBufferSpec * spec, IAudioClient3 * client, 131 WAVEFORMATEX * format, gboolean low_latency, gboolean loopback, 132 guint * ret_devicep_frames); 133 134 #endif /* __GST_WASAPI_UTIL_H__ */ 135