wasapi: try to satisfy both mingw and msvc
[platform/upstream/gstreamer.git] / sys / wasapi / gstwasapiutil.h
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 #ifdef _MSC_VER
29 #include <initguid.h>
30 #endif
31 #include <mmdeviceapi.h>
32 #include <audioclient.h>
33
34 #include "gstaudioclient3.h"
35
36 /* Static Caps shared between source, sink, and device provider */
37 #define GST_WASAPI_STATIC_CAPS "audio/x-raw, " \
38         "format = (string) " GST_AUDIO_FORMATS_ALL ", " \
39         "layout = (string) interleaved, " \
40         "rate = " GST_AUDIO_RATE_RANGE ", " \
41         "channels = " GST_AUDIO_CHANNELS_RANGE
42
43 /* Standard error path */
44 #define HR_FAILED_AND(hr,func,and) \
45   do { \
46     if (hr != S_OK) { \
47       gchar *msg = gst_wasapi_util_hresult_to_string (hr); \
48       GST_ERROR_OBJECT (self, #func " failed: %s", msg); \
49       g_free (msg); \
50       and; \
51     } \
52   } while (0)
53
54 #define HR_FAILED_RET(hr,func,ret) HR_FAILED_AND(hr,func,return ret)
55
56 #define HR_FAILED_GOTO(hr,func,where) HR_FAILED_AND(hr,func,res = FALSE; goto where)
57
58 /* Device role enum property */
59 typedef enum
60 {
61   GST_WASAPI_DEVICE_ROLE_CONSOLE,
62   GST_WASAPI_DEVICE_ROLE_MULTIMEDIA,
63   GST_WASAPI_DEVICE_ROLE_COMMS
64 } GstWasapiDeviceRole;
65 #define GST_WASAPI_DEVICE_TYPE_ROLE (gst_wasapi_device_role_get_type())
66 GType gst_wasapi_device_role_get_type (void);
67
68 /* Utilities */
69
70 gboolean gst_wasapi_util_have_audioclient3 (void);
71
72 gint gst_wasapi_device_role_to_erole (gint role);
73
74 gint gst_wasapi_erole_to_device_role (gint erole);
75
76 gchar *gst_wasapi_util_hresult_to_string (HRESULT hr);
77
78 gboolean gst_wasapi_util_get_devices (GstElement * element, gboolean active,
79     GList ** devices);
80
81 gboolean gst_wasapi_util_get_device_client (GstElement * element,
82     gboolean capture, gint role, const wchar_t * device_strid,
83     IMMDevice ** ret_device, IAudioClient ** ret_client);
84
85 gboolean gst_wasapi_util_get_device_format (GstElement * element,
86     gint device_mode, IMMDevice * device, IAudioClient * client,
87     WAVEFORMATEX ** ret_format);
88
89 gboolean gst_wasapi_util_get_render_client (GstElement * element,
90     IAudioClient * client, IAudioRenderClient ** ret_render_client);
91
92 gboolean gst_wasapi_util_get_capture_client (GstElement * element,
93     IAudioClient * client, IAudioCaptureClient ** ret_capture_client);
94
95 gboolean gst_wasapi_util_get_clock (GstElement * element,
96     IAudioClient * client, IAudioClock ** ret_clock);
97
98 gboolean gst_wasapi_util_parse_waveformatex (WAVEFORMATEXTENSIBLE * format,
99     GstCaps * template_caps, GstCaps ** out_caps,
100     GstAudioChannelPosition ** out_positions);
101
102 void gst_wasapi_util_get_best_buffer_sizes (GstAudioRingBufferSpec * spec,
103     gboolean exclusive, REFERENCE_TIME default_period,
104     REFERENCE_TIME min_period, REFERENCE_TIME * ret_period,
105     REFERENCE_TIME * ret_buffer_duration);
106
107 gboolean gst_wasapi_util_initialize_audioclient (GstElement * element,
108     GstAudioRingBufferSpec * spec, IAudioClient * client,
109     WAVEFORMATEX * format, guint sharemode, gboolean low_latency,
110     guint * ret_devicep_frames);
111
112 gboolean gst_wasapi_util_initialize_audioclient3 (GstElement * element,
113     GstAudioRingBufferSpec * spec, IAudioClient3 * client,
114     WAVEFORMATEX * format, gboolean low_latency, guint * ret_devicep_frames);
115
116 HANDLE gst_wasapi_util_set_thread_characteristics (void);
117
118 void gst_wasapi_util_revert_thread_characteristics (HANDLE handle);
119
120 #endif /* __GST_WASAPI_UTIL_H__ */