Debian Codegraph @

gstreamer/src/audioclock.ccg

raw
1 /* gstreamermm - a C++ wrapper for gstreamer
2 *
3 * Copyright 2008-2016 The gstreamermm Development Team
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free
17 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 */
19
20 #include <gst/audio/gstaudioclock.h>
21
22 _PINCLUDE(gstreamermm/private/systemclock_p.h)
23
24 // TODO: remove this check after we require at least gstreamer 1.12
25 #if GST_VERSION_MINOR < 12
26 #define GSTMM_AUDIO_CLOCK_CAST(obj) GST_CLOCK(obj)
27 #else
28 #define GSTMM_AUDIO_CLOCK_CAST(obj) GST_AUDIO_CLOCK(obj)
29 #endif
30
31 namespace
32 {
33
34 extern "C"
35 {
36
37 static GstClockTime AudioClock_GetTime_gstreamermm_callback(GstClock* clock, void* data)
38 {
39 Gst::AudioClock::SlotGetTime* the_slot = static_cast<Gst::AudioClock::SlotGetTime*>(data);
40
41 try
42 {
43 return (*the_slot)(Glib::wrap(clock, true));
44 }
45 catch(...)
46 {
47 Glib::exception_handlers_invoke();
48 }
49
50 return 0; // arbitrary value
51 }
52
53 } // extern "C"
54
55 } // anonymous namespace
56
57 namespace Gst
58 {
59
60 AudioClock::AudioClock(const Glib::ustring& name, const SlotGetTime& time_slot)
61 : _CONSTRUCT("name", (name.empty() ? static_cast<char*>(0) : name.c_str()))
62 {
63 // The slot is dynamically allocated because it is called each time the time
64 // is gotten.
65 m_slot.reset(new SlotGetTime(time_slot));
66
67 // The following lines are taken verbatim from gst_audio_clock_new() after
68 // the call to g_object_new() because it seems that bug #545782 will not be
69 // accepted.
70 gobj()->func = &AudioClock_GetTime_gstreamermm_callback;
71 gobj()->user_data = m_slot.get();
72 }
73
74 Gst::ClockTime AudioClock::adjust(Gst::ClockTime time)
75 {
76 return static_cast<Gst::ClockTime>(gst_audio_clock_adjust(GSTMM_AUDIO_CLOCK_CAST(gobj()), static_cast<GstClockTime>(time)));
77 }
78
79 Gst::ClockTime AudioClock::get_time() const
80 {
81 return static_cast<Gst::ClockTime>(gst_audio_clock_get_time(GSTMM_AUDIO_CLOCK_CAST(gobj())));
82 }
83
84 void AudioClock::invalidate()
85 {
86 gst_audio_clock_invalidate(GSTMM_AUDIO_CLOCK_CAST(gobj()));
87 }
88
89 } //namespace Gst