1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
// Take a look at the license at the top of the repository in the LICENSE file.

// rustdoc-stripper-ignore-next
//! Traits intended for subclassing [`MediaStream`](crate::MediaStream).

use crate::subclass::prelude::*;
use crate::MediaStream;
use glib::translate::*;
use glib::Cast;

pub trait MediaStreamImpl: MediaStreamImplExt + ObjectImpl {
    fn pause(&self, media_stream: &Self::Type) {
        self.parent_pause(media_stream)
    }

    fn play(&self, media_stream: &Self::Type) -> bool {
        self.parent_play(media_stream)
    }

    fn realize(&self, media_stream: &Self::Type, surface: gdk::Surface) {
        self.parent_realize(media_stream, surface)
    }

    fn seek(&self, media_stream: &Self::Type, timestamp: i64) {
        self.parent_seek(media_stream, timestamp)
    }

    fn unrealize(&self, media_stream: &Self::Type, surface: gdk::Surface) {
        self.parent_unrealize(media_stream, surface)
    }

    fn update_audio(&self, media_stream: &Self::Type, muted: bool, volume: f64) {
        self.parent_update_audio(media_stream, muted, volume)
    }
}

pub trait MediaStreamImplExt: ObjectSubclass {
    fn parent_pause(&self, media_stream: &Self::Type);
    fn parent_play(&self, media_stream: &Self::Type) -> bool;
    fn parent_realize(&self, media_stream: &Self::Type, surface: gdk::Surface);
    fn parent_seek(&self, media_stream: &Self::Type, timestamp: i64);
    fn parent_unrealize(&self, media_stream: &Self::Type, surface: gdk::Surface);
    fn parent_update_audio(&self, media_stream: &Self::Type, muted: bool, volume: f64);
}

impl<T: MediaStreamImpl> MediaStreamImplExt for T {
    fn parent_pause(&self, media_stream: &Self::Type) {
        unsafe {
            let data = T::type_data();
            let parent_class = data.as_ref().parent_class() as *mut ffi::GtkMediaStreamClass;
            let f = (*parent_class)
                .pause
                .expect("No parent class impl for \"pause\"");
            f(media_stream
                .unsafe_cast_ref::<MediaStream>()
                .to_glib_none()
                .0)
        }
    }

    fn parent_play(&self, media_stream: &Self::Type) -> bool {
        unsafe {
            let data = T::type_data();
            let parent_class = data.as_ref().parent_class() as *mut ffi::GtkMediaStreamClass;
            if let Some(f) = (*parent_class).play {
                return from_glib(f(media_stream
                    .unsafe_cast_ref::<MediaStream>()
                    .to_glib_none()
                    .0));
            }
            false
        }
    }

    fn parent_realize(&self, media_stream: &Self::Type, surface: gdk::Surface) {
        unsafe {
            let data = T::type_data();
            let parent_class = data.as_ref().parent_class() as *mut ffi::GtkMediaStreamClass;
            let f = (*parent_class)
                .realize
                .expect("No parent class impl for \"realize\"");
            f(
                media_stream
                    .unsafe_cast_ref::<MediaStream>()
                    .to_glib_none()
                    .0,
                surface.to_glib_none().0,
            )
        }
    }

    fn parent_seek(&self, media_stream: &Self::Type, timestamp: i64) {
        unsafe {
            let data = T::type_data();
            let parent_class = data.as_ref().parent_class() as *mut ffi::GtkMediaStreamClass;
            let f = (*parent_class)
                .seek
                .expect("No parent class impl for \"realize\"");
            f(
                media_stream
                    .unsafe_cast_ref::<MediaStream>()
                    .to_glib_none()
                    .0,
                timestamp,
            )
        }
    }

    fn parent_unrealize(&self, media_stream: &Self::Type, surface: gdk::Surface) {
        unsafe {
            let data = T::type_data();
            let parent_class = data.as_ref().parent_class() as *mut ffi::GtkMediaStreamClass;
            let f = (*parent_class)
                .unrealize
                .expect("No parent class impl for \"unrealize\"");
            f(
                media_stream
                    .unsafe_cast_ref::<MediaStream>()
                    .to_glib_none()
                    .0,
                surface.to_glib_none().0,
            )
        }
    }

    fn parent_update_audio(&self, media_stream: &Self::Type, muted: bool, volume: f64) {
        unsafe {
            let data = T::type_data();
            let parent_class = data.as_ref().parent_class() as *mut ffi::GtkMediaStreamClass;
            let f = (*parent_class)
                .update_audio
                .expect("No parent class impl for \"update_audio\"");
            f(
                media_stream
                    .unsafe_cast_ref::<MediaStream>()
                    .to_glib_none()
                    .0,
                muted.into_glib(),
                volume,
            )
        }
    }
}

unsafe impl<T: MediaStreamImpl> IsSubclassable<T> for MediaStream {
    fn class_init(class: &mut glib::Class<Self>) {
        Self::parent_class_init::<T>(class);

        assert!(
            crate::rt::is_initialized(),
            "GTK has to be initialized first"
        );

        let klass = class.as_mut();
        klass.pause = Some(media_stream_pause::<T>);
        klass.play = Some(media_stream_play::<T>);
        klass.realize = Some(media_stream_realize::<T>);
        klass.seek = Some(media_stream_seek::<T>);
        klass.unrealize = Some(media_stream_unrealize::<T>);
        klass.update_audio = Some(media_stream_update_audio::<T>);
    }
}

unsafe extern "C" fn media_stream_pause<T: MediaStreamImpl>(ptr: *mut ffi::GtkMediaStream) {
    let instance = &*(ptr as *mut T::Instance);
    let imp = instance.impl_();
    let wrap: Borrowed<MediaStream> = from_glib_borrow(ptr);

    imp.pause(wrap.unsafe_cast_ref())
}

unsafe extern "C" fn media_stream_play<T: MediaStreamImpl>(
    ptr: *mut ffi::GtkMediaStream,
) -> glib::ffi::gboolean {
    let instance = &*(ptr as *mut T::Instance);
    let imp = instance.impl_();
    let wrap: Borrowed<MediaStream> = from_glib_borrow(ptr);

    imp.play(wrap.unsafe_cast_ref()).into_glib()
}

unsafe extern "C" fn media_stream_realize<T: MediaStreamImpl>(
    ptr: *mut ffi::GtkMediaStream,
    surface: *mut gdk::ffi::GdkSurface,
) {
    let instance = &*(ptr as *mut T::Instance);
    let imp = instance.impl_();
    let wrap: Borrowed<MediaStream> = from_glib_borrow(ptr);

    imp.realize(wrap.unsafe_cast_ref(), from_glib_none(surface))
}

unsafe extern "C" fn media_stream_seek<T: MediaStreamImpl>(
    ptr: *mut ffi::GtkMediaStream,
    timestamp: i64,
) {
    let instance = &*(ptr as *mut T::Instance);
    let imp = instance.impl_();
    let wrap: Borrowed<MediaStream> = from_glib_borrow(ptr);

    imp.seek(wrap.unsafe_cast_ref(), timestamp)
}

unsafe extern "C" fn media_stream_unrealize<T: MediaStreamImpl>(
    ptr: *mut ffi::GtkMediaStream,
    surface: *mut gdk::ffi::GdkSurface,
) {
    let instance = &*(ptr as *mut T::Instance);
    let imp = instance.impl_();
    let wrap: Borrowed<MediaStream> = from_glib_borrow(ptr);

    imp.unrealize(wrap.unsafe_cast_ref(), from_glib_none(surface))
}

unsafe extern "C" fn media_stream_update_audio<T: MediaStreamImpl>(
    ptr: *mut ffi::GtkMediaStream,
    muted: glib::ffi::gboolean,
    volume: f64,
) {
    let instance = &*(ptr as *mut T::Instance);
    let imp = instance.impl_();
    let wrap: Borrowed<MediaStream> = from_glib_borrow(ptr);

    imp.update_audio(wrap.unsafe_cast_ref(), from_glib(muted), volume)
}