93b166e4d555352c740194fb5c0a89fdf7e1c7a8
[platform/upstream/gstreamer.git] / sys / wasapi / gstwasapisrc.c
1 /*
2  * Copyright (C) 2008 Ole André Vadla Ravnås <ole.andre.ravnas@tandberg.com>
3  * Copyright (C) 2018 Centricular Ltd.
4  *   Author: Nirbheek Chauhan <nirbheek@centricular.com>
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Library General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Library General Public License for more details.
15  *
16  * You should have received a copy of the GNU Library General Public
17  * License along with this library; if not, write to the
18  * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
19  * Boston, MA 02110-1301, USA.
20  */
21
22 /**
23  * SECTION:element-wasapisrc
24  * @title: wasapisrc
25  *
26  * Provides audio capture from the Windows Audio Session API available with
27  * Vista and newer.
28  *
29  * ## Example pipelines
30  * |[
31  * gst-launch-1.0 -v wasapisrc ! fakesink
32  * ]| Capture from the default audio device and render to fakesink.
33  *
34  */
35 #ifdef HAVE_CONFIG_H
36 #  include <config.h>
37 #endif
38
39 #include "gstwasapisrc.h"
40
41 #include <avrt.h>
42
43 GST_DEBUG_CATEGORY_STATIC (gst_wasapi_src_debug);
44 #define GST_CAT_DEFAULT gst_wasapi_src_debug
45
46 static GstStaticPadTemplate src_template = GST_STATIC_PAD_TEMPLATE ("src",
47     GST_PAD_SRC,
48     GST_PAD_ALWAYS,
49     GST_STATIC_CAPS (GST_WASAPI_STATIC_CAPS));
50
51 #define DEFAULT_ROLE          GST_WASAPI_DEVICE_ROLE_CONSOLE
52 #define DEFAULT_EXCLUSIVE     FALSE
53 #define DEFAULT_LOW_LATENCY   FALSE
54
55 enum
56 {
57   PROP_0,
58   PROP_ROLE,
59   PROP_DEVICE,
60   PROP_EXCLUSIVE,
61   PROP_LOW_LATENCY
62 };
63
64 static void gst_wasapi_src_dispose (GObject * object);
65 static void gst_wasapi_src_finalize (GObject * object);
66 static void gst_wasapi_src_set_property (GObject * object, guint prop_id,
67     const GValue * value, GParamSpec * pspec);
68 static void gst_wasapi_src_get_property (GObject * object, guint prop_id,
69     GValue * value, GParamSpec * pspec);
70
71 static GstCaps *gst_wasapi_src_get_caps (GstBaseSrc * bsrc, GstCaps * filter);
72
73 static gboolean gst_wasapi_src_open (GstAudioSrc * asrc);
74 static gboolean gst_wasapi_src_close (GstAudioSrc * asrc);
75 static gboolean gst_wasapi_src_prepare (GstAudioSrc * asrc,
76     GstAudioRingBufferSpec * spec);
77 static gboolean gst_wasapi_src_unprepare (GstAudioSrc * asrc);
78 static guint gst_wasapi_src_read (GstAudioSrc * asrc, gpointer data,
79     guint length, GstClockTime * timestamp);
80 static guint gst_wasapi_src_delay (GstAudioSrc * asrc);
81 static void gst_wasapi_src_reset (GstAudioSrc * asrc);
82
83 static GstClockTime gst_wasapi_src_get_time (GstClock * clock,
84     gpointer user_data);
85
86 #define gst_wasapi_src_parent_class parent_class
87 G_DEFINE_TYPE (GstWasapiSrc, gst_wasapi_src, GST_TYPE_AUDIO_SRC);
88
89 static void
90 gst_wasapi_src_class_init (GstWasapiSrcClass * klass)
91 {
92   GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
93   GstElementClass *gstelement_class = GST_ELEMENT_CLASS (klass);
94   GstBaseSrcClass *gstbasesrc_class = GST_BASE_SRC_CLASS (klass);
95   GstAudioSrcClass *gstaudiosrc_class = GST_AUDIO_SRC_CLASS (klass);
96
97   gobject_class->dispose = gst_wasapi_src_dispose;
98   gobject_class->finalize = gst_wasapi_src_finalize;
99   gobject_class->set_property = gst_wasapi_src_set_property;
100   gobject_class->get_property = gst_wasapi_src_get_property;
101
102   g_object_class_install_property (gobject_class,
103       PROP_ROLE,
104       g_param_spec_enum ("role", "Role",
105           "Role of the device: communications, multimedia, etc",
106           GST_WASAPI_DEVICE_TYPE_ROLE, DEFAULT_ROLE, G_PARAM_READWRITE |
107           G_PARAM_STATIC_STRINGS | GST_PARAM_MUTABLE_READY));
108
109   g_object_class_install_property (gobject_class,
110       PROP_DEVICE,
111       g_param_spec_string ("device", "Device",
112           "WASAPI playback device as a GUID string",
113           NULL, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
114
115   g_object_class_install_property (gobject_class,
116       PROP_EXCLUSIVE,
117       g_param_spec_boolean ("exclusive", "Exclusive mode",
118           "Open the device in exclusive mode",
119           DEFAULT_EXCLUSIVE, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
120
121   g_object_class_install_property (gobject_class,
122       PROP_LOW_LATENCY,
123       g_param_spec_boolean ("low-latency", "Low latency",
124           "Optimize all settings for lowest latency",
125           DEFAULT_LOW_LATENCY, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
126
127   gst_element_class_add_static_pad_template (gstelement_class, &src_template);
128   gst_element_class_set_static_metadata (gstelement_class, "WasapiSrc",
129       "Source/Audio",
130       "Stream audio from an audio capture device through WASAPI",
131       "Ole André Vadla Ravnås <ole.andre.ravnas@tandberg.com>");
132
133   gstbasesrc_class->get_caps = GST_DEBUG_FUNCPTR (gst_wasapi_src_get_caps);
134
135   gstaudiosrc_class->open = GST_DEBUG_FUNCPTR (gst_wasapi_src_open);
136   gstaudiosrc_class->close = GST_DEBUG_FUNCPTR (gst_wasapi_src_close);
137   gstaudiosrc_class->read = GST_DEBUG_FUNCPTR (gst_wasapi_src_read);
138   gstaudiosrc_class->prepare = GST_DEBUG_FUNCPTR (gst_wasapi_src_prepare);
139   gstaudiosrc_class->unprepare = GST_DEBUG_FUNCPTR (gst_wasapi_src_unprepare);
140   gstaudiosrc_class->delay = GST_DEBUG_FUNCPTR (gst_wasapi_src_delay);
141   gstaudiosrc_class->reset = GST_DEBUG_FUNCPTR (gst_wasapi_src_reset);
142
143   GST_DEBUG_CATEGORY_INIT (gst_wasapi_src_debug, "wasapisrc",
144       0, "Windows audio session API source");
145 }
146
147 static void
148 gst_wasapi_src_init (GstWasapiSrc * self)
149 {
150   /* override with a custom clock */
151   if (GST_AUDIO_BASE_SRC (self)->clock)
152     gst_object_unref (GST_AUDIO_BASE_SRC (self)->clock);
153
154   GST_AUDIO_BASE_SRC (self)->clock = gst_audio_clock_new ("GstWasapiSrcClock",
155       gst_wasapi_src_get_time, gst_object_ref (self),
156       (GDestroyNotify) gst_object_unref);
157
158   self->event_handle = CreateEvent (NULL, FALSE, FALSE, NULL);
159
160   CoInitialize (NULL);
161 }
162
163 static void
164 gst_wasapi_src_dispose (GObject * object)
165 {
166   GstWasapiSrc *self = GST_WASAPI_SRC (object);
167
168   if (self->event_handle != NULL) {
169     CloseHandle (self->event_handle);
170     self->event_handle = NULL;
171   }
172
173   if (self->client_clock != NULL) {
174     IUnknown_Release (self->client_clock);
175     self->client_clock = NULL;
176   }
177
178   if (self->client != NULL) {
179     IUnknown_Release (self->client);
180     self->client = NULL;
181   }
182
183   if (self->capture_client != NULL) {
184     IUnknown_Release (self->capture_client);
185     self->capture_client = NULL;
186   }
187
188   G_OBJECT_CLASS (parent_class)->dispose (object);
189 }
190
191 static void
192 gst_wasapi_src_finalize (GObject * object)
193 {
194   GstWasapiSrc *self = GST_WASAPI_SRC (object);
195
196   g_clear_pointer (&self->mix_format, CoTaskMemFree);
197
198   CoUninitialize ();
199
200   g_clear_pointer (&self->cached_caps, gst_caps_unref);
201   g_clear_pointer (&self->positions, g_free);
202   g_clear_pointer (&self->device_strid, g_free);
203
204   G_OBJECT_CLASS (parent_class)->finalize (object);
205 }
206
207 static void
208 gst_wasapi_src_set_property (GObject * object, guint prop_id,
209     const GValue * value, GParamSpec * pspec)
210 {
211   GstWasapiSrc *self = GST_WASAPI_SRC (object);
212
213   switch (prop_id) {
214     case PROP_ROLE:
215       self->role = gst_wasapi_device_role_to_erole (g_value_get_enum (value));
216       break;
217     case PROP_DEVICE:
218     {
219       const gchar *device = g_value_get_string (value);
220       g_free (self->device_strid);
221       self->device_strid =
222           device ? g_utf8_to_utf16 (device, -1, NULL, NULL, NULL) : NULL;
223       break;
224     }
225     case PROP_EXCLUSIVE:
226       self->sharemode = g_value_get_boolean (value)
227           ? AUDCLNT_SHAREMODE_EXCLUSIVE : AUDCLNT_SHAREMODE_SHARED;
228       break;
229     case PROP_LOW_LATENCY:
230       self->low_latency = g_value_get_boolean (value);
231       break;
232     default:
233       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
234       break;
235   }
236 }
237
238 static void
239 gst_wasapi_src_get_property (GObject * object, guint prop_id,
240     GValue * value, GParamSpec * pspec)
241 {
242   GstWasapiSrc *self = GST_WASAPI_SRC (object);
243
244   switch (prop_id) {
245     case PROP_ROLE:
246       g_value_set_enum (value, gst_wasapi_erole_to_device_role (self->role));
247       break;
248     case PROP_DEVICE:
249       g_value_take_string (value, self->device_strid ?
250           g_utf16_to_utf8 (self->device_strid, -1, NULL, NULL, NULL) : NULL);
251       break;
252     case PROP_EXCLUSIVE:
253       g_value_set_boolean (value,
254           self->sharemode == AUDCLNT_SHAREMODE_EXCLUSIVE);
255       break;
256     case PROP_LOW_LATENCY:
257       g_value_set_boolean (value, self->low_latency);
258       break;
259     default:
260       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
261       break;
262   }
263 }
264
265 static GstCaps *
266 gst_wasapi_src_get_caps (GstBaseSrc * bsrc, GstCaps * filter)
267 {
268   GstWasapiSrc *self = GST_WASAPI_SRC (bsrc);
269   WAVEFORMATEX *format = NULL;
270   GstCaps *caps = NULL;
271
272   GST_DEBUG_OBJECT (self, "entering get caps");
273
274   if (self->cached_caps) {
275     caps = gst_caps_ref (self->cached_caps);
276   } else {
277     GstCaps *template_caps;
278     gboolean ret;
279
280     template_caps = gst_pad_get_pad_template_caps (bsrc->srcpad);
281
282     if (!self->client)
283       gst_wasapi_src_open (GST_AUDIO_SRC (bsrc));
284
285     ret = gst_wasapi_util_get_device_format (GST_ELEMENT (self),
286         self->sharemode, self->device, self->client, &format);
287     if (!ret) {
288       GST_ELEMENT_ERROR (self, STREAM, FORMAT, (NULL),
289           ("failed to detect format"));
290       goto out;
291     }
292
293     gst_wasapi_util_parse_waveformatex ((WAVEFORMATEXTENSIBLE *) format,
294         template_caps, &caps, &self->positions);
295     if (caps == NULL) {
296       GST_ELEMENT_ERROR (self, STREAM, FORMAT, (NULL), ("unknown format"));
297       goto out;
298     }
299
300     {
301       gchar *pos_str = gst_audio_channel_positions_to_string (self->positions,
302           format->nChannels);
303       GST_INFO_OBJECT (self, "positions are: %s", pos_str);
304       g_free (pos_str);
305     }
306
307     self->mix_format = format;
308     gst_caps_replace (&self->cached_caps, caps);
309     gst_caps_unref (template_caps);
310   }
311
312   if (filter) {
313     GstCaps *filtered =
314         gst_caps_intersect_full (filter, caps, GST_CAPS_INTERSECT_FIRST);
315     gst_caps_unref (caps);
316     caps = filtered;
317   }
318
319   GST_DEBUG_OBJECT (self, "returning caps %" GST_PTR_FORMAT, caps);
320
321 out:
322   return caps;
323 }
324
325 static gboolean
326 gst_wasapi_src_open (GstAudioSrc * asrc)
327 {
328   GstWasapiSrc *self = GST_WASAPI_SRC (asrc);
329   gboolean res = FALSE;
330   IAudioClient *client = NULL;
331   IMMDevice *device = NULL;
332
333   if (self->client)
334     return TRUE;
335
336   /* FIXME: Switching the default device does not switch the stream to it,
337    * even if the old device was unplugged. We need to handle this somehow.
338    * For example, perhaps we should automatically switch to the new device if
339    * the default device is changed and a device isn't explicitly selected. */
340   if (!gst_wasapi_util_get_device_client (GST_ELEMENT (self), TRUE,
341           self->role, self->device_strid, &device, &client)) {
342     if (!self->device_strid)
343       GST_ELEMENT_ERROR (self, RESOURCE, OPEN_READ, (NULL),
344           ("Failed to get default device"));
345     else
346       GST_ELEMENT_ERROR (self, RESOURCE, OPEN_READ, (NULL),
347           ("Failed to open device %S", self->device_strid));
348     goto beach;
349   }
350
351   self->client = client;
352   self->device = device;
353   res = TRUE;
354
355 beach:
356
357   return res;
358 }
359
360 static gboolean
361 gst_wasapi_src_close (GstAudioSrc * asrc)
362 {
363   GstWasapiSrc *self = GST_WASAPI_SRC (asrc);
364
365   if (self->device != NULL) {
366     IUnknown_Release (self->device);
367     self->device = NULL;
368   }
369
370   if (self->client != NULL) {
371     IUnknown_Release (self->client);
372     self->client = NULL;
373   }
374
375   return TRUE;
376 }
377
378 static gboolean
379 gst_wasapi_src_prepare (GstAudioSrc * asrc, GstAudioRingBufferSpec * spec)
380 {
381   GstWasapiSrc *self = GST_WASAPI_SRC (asrc);
382   gboolean res = FALSE;
383   REFERENCE_TIME latency_rt;
384   guint bpf, rate, devicep_frames, buffer_frames;
385   HRESULT hr;
386
387   if (self->sharemode == AUDCLNT_SHAREMODE_SHARED &&
388       gst_wasapi_util_have_audioclient3 ()) {
389     if (!gst_wasapi_util_initialize_audioclient3 (GST_ELEMENT (self), spec,
390             (IAudioClient3 *) self->client, self->mix_format, self->low_latency,
391             &devicep_frames))
392       goto beach;
393   } else {
394     if (!gst_wasapi_util_initialize_audioclient (GST_ELEMENT (self), spec,
395             self->client, self->mix_format, self->sharemode, self->low_latency,
396             &devicep_frames))
397       goto beach;
398   }
399
400   bpf = GST_AUDIO_INFO_BPF (&spec->info);
401   rate = GST_AUDIO_INFO_RATE (&spec->info);
402
403   /* Total size in frames of the allocated buffer that we will read from */
404   hr = IAudioClient_GetBufferSize (self->client, &buffer_frames);
405   HR_FAILED_GOTO (hr, IAudioClient::GetBufferSize, beach);
406
407   GST_INFO_OBJECT (self, "buffer size is %i frames, device period is %i "
408       "frames, bpf is %i bytes, rate is %i Hz", buffer_frames,
409       devicep_frames, bpf, rate);
410
411   /* Actual latency-time/buffer-time will be different now */
412   spec->segsize = devicep_frames * bpf;
413
414   /* We need a minimum of 2 segments to ensure glitch-free playback */
415   spec->segtotal = MAX (self->buffer_frame_count * bpf / spec->segsize, 2);
416
417   GST_INFO_OBJECT (self, "segsize is %i, segtotal is %i", spec->segsize,
418       spec->segtotal);
419
420   /* Get WASAPI latency for logging */
421   hr = IAudioClient_GetStreamLatency (self->client, &latency_rt);
422   HR_FAILED_GOTO (hr, IAudioClient::GetStreamLatency, beach);
423
424   GST_INFO_OBJECT (self, "wasapi stream latency: %" G_GINT64_FORMAT " (%"
425       G_GINT64_FORMAT " ms)", latency_rt, latency_rt / 10000);
426
427   /* Set the event handler which will trigger reads */
428   hr = IAudioClient_SetEventHandle (self->client, self->event_handle);
429   HR_FAILED_GOTO (hr, IAudioClient::SetEventHandle, beach);
430
431   /* Get the clock and the clock freq */
432   if (!gst_wasapi_util_get_clock (GST_ELEMENT (self), self->client,
433           &self->client_clock))
434     goto beach;
435
436   hr = IAudioClock_GetFrequency (self->client_clock, &self->client_clock_freq);
437   HR_FAILED_GOTO (hr, IAudioClock::GetFrequency, beach);
438
439   /* Get capture source client and start it up */
440   if (!gst_wasapi_util_get_capture_client (GST_ELEMENT (self), self->client,
441           &self->capture_client)) {
442     goto beach;
443   }
444
445   hr = IAudioClient_Start (self->client);
446   HR_FAILED_GOTO (hr, IAudioClock::Start, beach);
447
448   gst_audio_ring_buffer_set_channel_positions (GST_AUDIO_BASE_SRC
449       (self)->ringbuffer, self->positions);
450
451   /* Increase the thread priority to reduce glitches */
452   self->thread_priority_handle = gst_wasapi_util_set_thread_characteristics ();
453
454   res = TRUE;
455 beach:
456   /* unprepare() is not called if prepare() fails, but we want it to be, so call
457    * it manually when needed */
458   if (!res)
459     gst_wasapi_src_unprepare (asrc);
460
461   return res;
462 }
463
464 static gboolean
465 gst_wasapi_src_unprepare (GstAudioSrc * asrc)
466 {
467   GstWasapiSrc *self = GST_WASAPI_SRC (asrc);
468
469   if (self->sharemode == AUDCLNT_SHAREMODE_EXCLUSIVE)
470     CoUninitialize ();
471
472   if (self->thread_priority_handle != NULL) {
473     gst_wasapi_util_revert_thread_characteristics
474         (self->thread_priority_handle);
475     self->thread_priority_handle = NULL;
476   }
477
478   if (self->client != NULL) {
479     IAudioClient_Stop (self->client);
480   }
481
482   if (self->capture_client != NULL) {
483     IUnknown_Release (self->capture_client);
484     self->capture_client = NULL;
485   }
486
487   if (self->client_clock != NULL) {
488     IUnknown_Release (self->client_clock);
489     self->client_clock = NULL;
490   }
491
492   self->client_clock_freq = 0;
493
494   return TRUE;
495 }
496
497 static guint
498 gst_wasapi_src_read (GstAudioSrc * asrc, gpointer data, guint length,
499     GstClockTime * timestamp)
500 {
501   GstWasapiSrc *self = GST_WASAPI_SRC (asrc);
502   HRESULT hr;
503   gint16 *from = NULL;
504   guint wanted = length;
505   DWORD flags;
506
507   while (wanted > 0) {
508     guint have_frames, n_frames, want_frames, read_len;
509
510     /* Wait for data to become available */
511     WaitForSingleObject (self->event_handle, INFINITE);
512
513     hr = IAudioCaptureClient_GetBuffer (self->capture_client,
514         (BYTE **) & from, &have_frames, &flags, NULL, NULL);
515     if (hr != S_OK) {
516       gchar *msg = gst_wasapi_util_hresult_to_string (hr);
517       if (hr == AUDCLNT_S_BUFFER_EMPTY)
518         GST_WARNING_OBJECT (self, "IAudioCaptureClient::GetBuffer failed: %s"
519             ", retrying", msg);
520       else
521         GST_ERROR_OBJECT (self, "IAudioCaptureClient::GetBuffer failed: %s",
522             msg);
523       g_free (msg);
524       length = 0;
525       goto beach;
526     }
527
528     if (flags != 0)
529       GST_INFO_OBJECT (self, "buffer flags=%#08x", (guint) flags);
530
531     /* XXX: How do we handle AUDCLNT_BUFFERFLAGS_SILENT? We're supposed to write
532      * out silence when that flag is set? See:
533      * https://msdn.microsoft.com/en-us/library/windows/desktop/dd370800(v=vs.85).aspx */
534
535     if (flags & AUDCLNT_BUFFERFLAGS_DATA_DISCONTINUITY)
536       GST_WARNING_OBJECT (self, "WASAPI reported glitch in buffer");
537
538     want_frames = wanted / self->mix_format->nBlockAlign;
539
540     /* If GetBuffer is returning more frames than we can handle, all we can do is
541      * hope that this is temporary and that things will settle down later. */
542     if (G_UNLIKELY (have_frames > want_frames))
543       GST_WARNING_OBJECT (self, "captured too many frames: have %i, want %i",
544           have_frames, want_frames);
545
546     /* Only copy data that will fit into the allocated buffer of size @length */
547     n_frames = MIN (have_frames, want_frames);
548     read_len = n_frames * self->mix_format->nBlockAlign;
549
550     {
551       guint bpf = self->mix_format->nBlockAlign;
552       GST_DEBUG_OBJECT (self, "have: %i (%i bytes), can read: %i (%i bytes), "
553           "will read: %i (%i bytes)", have_frames, have_frames * bpf,
554           want_frames, wanted, n_frames, read_len);
555     }
556
557     memcpy (data, from, read_len);
558     wanted -= read_len;
559
560     /* Always release all captured buffers if we've captured any at all */
561     hr = IAudioCaptureClient_ReleaseBuffer (self->capture_client, have_frames);
562     HR_FAILED_AND (hr, IAudioClock::ReleaseBuffer, goto beach);
563   }
564
565
566 beach:
567
568   return length;
569 }
570
571 static guint
572 gst_wasapi_src_delay (GstAudioSrc * asrc)
573 {
574   GstWasapiSrc *self = GST_WASAPI_SRC (asrc);
575   guint delay = 0;
576   HRESULT hr;
577
578   hr = IAudioClient_GetCurrentPadding (self->client, &delay);
579   HR_FAILED_RET (hr, IAudioClock::GetCurrentPadding, 0);
580
581   return delay;
582 }
583
584 static void
585 gst_wasapi_src_reset (GstAudioSrc * asrc)
586 {
587   GstWasapiSrc *self = GST_WASAPI_SRC (asrc);
588   HRESULT hr;
589
590   if (!self->client)
591     return;
592
593   hr = IAudioClient_Stop (self->client);
594   HR_FAILED_RET (hr, IAudioClock::Stop,);
595
596   hr = IAudioClient_Reset (self->client);
597   HR_FAILED_RET (hr, IAudioClock::Reset,);
598 }
599
600 static GstClockTime
601 gst_wasapi_src_get_time (GstClock * clock, gpointer user_data)
602 {
603   GstWasapiSrc *self = GST_WASAPI_SRC (user_data);
604   HRESULT hr;
605   guint64 devpos;
606   GstClockTime result;
607
608   if (G_UNLIKELY (self->client_clock == NULL))
609     return GST_CLOCK_TIME_NONE;
610
611   hr = IAudioClock_GetPosition (self->client_clock, &devpos, NULL);
612   HR_FAILED_RET (hr, IAudioClock::GetPosition, GST_CLOCK_TIME_NONE);
613
614   result = gst_util_uint64_scale_int (devpos, GST_SECOND,
615       self->client_clock_freq);
616
617   /*
618      GST_DEBUG_OBJECT (self, "devpos = %" G_GUINT64_FORMAT
619      " frequency = %" G_GUINT64_FORMAT
620      " result = %" G_GUINT64_FORMAT " ms",
621      devpos, self->client_clock_freq, GST_TIME_AS_MSECONDS (result));
622    */
623
624   return result;
625 }