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
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
use ffi::*;
use util::*;
use error::Error;
use std::os::raw;
use reference::Reference;

unsafe impl Send for GstMessage {}
unsafe impl Send for GstTagList {}
unsafe impl Send for Message {}

pub type MessagePrivate = *mut GstMessage;


unsafe fn gst_message_ref(msg: *mut GstMessage) -> *mut GstMessage{
	gst_mini_object_ref(mem::transmute(msg)) as *mut GstMessage
}

pub enum Message{
    Unknown(MessagePrivate),
    Eos(MessagePrivate),
    Error(MessagePrivate),
    ErrorParsed{msg: MessagePrivate, error: Error, debug: String},
    Warning(MessagePrivate),
    WarningParsed{msg: MessagePrivate, error: Error, debug: String},
    Info(MessagePrivate),
    InfoParsed{msg: MessagePrivate, error: Error, debug: String},
    Tag(MessagePrivate),
    TagParsed{msg: MessagePrivate, tags: *mut GstTagList},
    Buffering(MessagePrivate),
    BufferingParsed{msg: MessagePrivate, pct: i32},
    StateChanged(MessagePrivate),
    StateChangedParsed{msg: MessagePrivate, old: GstState, new: GstState, pending: GstState},
    StateDirty(MessagePrivate),
    StepDone(MessagePrivate),
    ClockProvide(MessagePrivate),
    ClockLost(MessagePrivate),
    NewClock(MessagePrivate),
    StructureChange(MessagePrivate),
    StreamStatus(MessagePrivate),
    Application(MessagePrivate),
    Element(MessagePrivate),
    SegmentStart(MessagePrivate),
    SegmentDone(MessagePrivate),
    DurationChanged(MessagePrivate),
    Latency(MessagePrivate),
    AsyncStart(MessagePrivate),
    AsyncDone(MessagePrivate),
    RequestState(MessagePrivate),
    StepStart(MessagePrivate),
    Qos(MessagePrivate),
    Progress(MessagePrivate),
    Toc(MessagePrivate),
    ResetTime(MessagePrivate),
    StreamStart(MessagePrivate),
    NeedContext(MessagePrivate),
    HaveContext(MessagePrivate),
    Extended(MessagePrivate),
    DeviceAdded(MessagePrivate),
    DeviceRemoved(MessagePrivate),
    Any(MessagePrivate),
}

impl Drop for Message{
    fn drop(&mut self){
        unsafe{
            gst_mini_object_unref(self.gst_message() as *mut GstMiniObject);
        }
    }
}

impl Message{
    pub unsafe fn new(gst_message: *const GstMessage) -> Option<Message>{
        if gst_message != ptr::null(){
            let gst_message = gst_mini_object_ref(gst_message as *mut GstMiniObject) as *mut GstMessage;
            match (*gst_message)._type{
                 GST_MESSAGE_UNKNOWN => Some(Message::Unknown(gst_message)),
                 GST_MESSAGE_EOS => Some(Message::Eos(gst_message)),
                 GST_MESSAGE_ERROR => Some(Message::Error(gst_message)),
                 GST_MESSAGE_WARNING => Some(Message::Warning(gst_message)),
                 GST_MESSAGE_INFO => Some(Message::Info(gst_message)),
                 GST_MESSAGE_TAG => Some(Message::Tag(gst_message)),
                 GST_MESSAGE_BUFFERING => Some(Message::Buffering(gst_message)),
                 GST_MESSAGE_STATE_CHANGED => Some(Message::StateChanged(gst_message)),
                 GST_MESSAGE_STATE_DIRTY => Some(Message::StateDirty(gst_message)),
                 GST_MESSAGE_STEP_DONE => Some(Message::StepDone(gst_message)),
                 GST_MESSAGE_CLOCK_PROVIDE => Some(Message::ClockProvide(gst_message)),
                 GST_MESSAGE_CLOCK_LOST => Some(Message::ClockLost(gst_message)),
                 GST_MESSAGE_NEW_CLOCK => Some(Message::NewClock(gst_message)),
                 GST_MESSAGE_STRUCTURE_CHANGE => Some(Message::StructureChange(gst_message)),
                 GST_MESSAGE_STREAM_STATUS => Some(Message::StreamStatus(gst_message)),
                 GST_MESSAGE_APPLICATION => Some(Message::Application(gst_message)),
                 GST_MESSAGE_ELEMENT => Some(Message::Element(gst_message)),
                 GST_MESSAGE_SEGMENT_START => Some(Message::SegmentStart(gst_message)),
                 GST_MESSAGE_SEGMENT_DONE => Some(Message::SegmentDone(gst_message)),
                 GST_MESSAGE_DURATION_CHANGED => Some(Message::DurationChanged(gst_message)),
                 GST_MESSAGE_LATENCY => Some(Message::Latency(gst_message)),
                 GST_MESSAGE_ASYNC_START => Some(Message::AsyncStart(gst_message)),
                 GST_MESSAGE_ASYNC_DONE => Some(Message::AsyncDone(gst_message)),
                 GST_MESSAGE_REQUEST_STATE => Some(Message::RequestState(gst_message)),
                 GST_MESSAGE_STEP_START => Some(Message::StepStart(gst_message)),
                 GST_MESSAGE_QOS => Some(Message::Qos(gst_message)),
                 GST_MESSAGE_PROGRESS => Some(Message::Progress(gst_message)),
                 GST_MESSAGE_TOC => Some(Message::Toc(gst_message)),
                 GST_MESSAGE_RESET_TIME => Some(Message::ResetTime(gst_message)),
                 GST_MESSAGE_STREAM_START => Some(Message::StreamStart(gst_message)),
                 GST_MESSAGE_NEED_CONTEXT => Some(Message::NeedContext(gst_message)),
                 GST_MESSAGE_HAVE_CONTEXT => Some(Message::HaveContext(gst_message)),
                 GST_MESSAGE_EXTENDED => Some(Message::Extended(gst_message)),
                 GST_MESSAGE_DEVICE_ADDED => Some(Message::DeviceAdded(gst_message)),
                 GST_MESSAGE_DEVICE_REMOVED => Some(Message::DeviceRemoved(gst_message)),
                 GST_MESSAGE_ANY => Some(Message::Any(gst_message)),
                 _ => None
            }
        }else{
            None
        }
    }

    pub unsafe fn new_eos(src: *mut GstObject) -> Option<Message>{
        Message::new(gst_message_new_eos(src))
    }

    pub unsafe fn new_error(src: *mut GstObject, error: *mut GError, debug: &str) -> Option<Message>{
        let cdebug = CString::new(debug).unwrap();
        Message::new(gst_message_new_error(src,error,mem::transmute(cdebug.as_ptr())))
    }

    pub unsafe fn new_warning(src: *mut GstObject, error: *mut GError, debug: &str) -> Option<Message>{
        let cdebug = CString::new(debug).unwrap();
        Message::new(gst_message_new_warning(src,error,mem::transmute(cdebug.as_ptr())))
    }

    pub unsafe fn new_info(src: *mut GstObject, error: *mut GError, debug: &str) -> Option<Message>{
		let cdebug = CString::new(debug).unwrap();
        Message::new(gst_message_new_info(src,error,mem::transmute(cdebug.as_ptr())))
    }

    pub unsafe fn new_tag(src: *mut GstObject, tag_list: *mut GstTagList) -> Option<Message>{
        Message::new(gst_message_new_tag(src,tag_list))
    }

    pub unsafe fn new_buffering(src: *mut GstObject, pct: i32) -> Option<Message>{
        Message::new(gst_message_new_buffering(src,pct))
    }

    pub unsafe fn new_state_changed(src: *mut GstObject, old_state: GstState, new_state: GstState, pending: GstState) -> Option<Message>{
        Message::new(gst_message_new_state_changed(src,old_state,new_state,pending))
    }

    pub unsafe fn new_state_dirty(src: *mut GstObject) -> Option<Message>{
        Message::new(gst_message_new_state_dirty(src))
    }

    pub unsafe fn new_step_done(src: *mut GstObject, format: GstFormat,
                         amount: u64, rate: f64,
                         flush: bool, intermediate: bool,
                         duration: u64, eos: bool) -> Option<Message>{
        Message::new(gst_message_new_step_done(src,format,amount,rate,flush as i32,intermediate as i32,duration,eos as i32))
    }

    pub unsafe fn new_clock_provide(src: *mut GstObject, clock: *mut GstClock, ready: bool) -> Option<Message>{
        Message::new(gst_message_new_clock_provide(src,clock,ready as i32))
    }

    pub unsafe fn new_clock_lost(src: *mut GstObject, clock: *mut GstClock) -> Option<Message>{
        Message::new(gst_message_new_clock_lost(src,clock))
    }

    pub unsafe fn new_new_clock(src: *mut GstObject, clock: *mut GstClock) -> Option<Message>{
        Message::new(gst_message_new_new_clock(src,clock))
    }

    pub unsafe fn new_application(src: *mut GstObject, structure: *mut GstStructure) -> Option<Message>{
        Message::new(gst_message_new_application(src,structure))
    }

    pub unsafe fn new_element(src: *mut GstObject, structure: *mut GstStructure) -> Option<Message>{
        Message::new(gst_message_new_element(src,structure))
    }

    pub unsafe fn new_custom(ty: GstMessageType, src: *mut GstObject, structure: *mut GstStructure) -> Option<Message>{
        Message::new(gst_message_new_custom(ty,src,structure))
    }

	#[allow(unused_variables)]
    pub unsafe fn gst_message(&self) -> *const GstMessage{
        match *self{
            Message::Unknown(msg) => msg,
            Message::Eos(msg) => msg,
            Message::Error(msg) => msg,
            Message::ErrorParsed{msg, ref error, ref debug} => msg,
            Message::Warning(msg) => msg,
            Message::WarningParsed{msg, ref error, ref debug} => msg,
            Message::Info(msg) => msg,
            Message::InfoParsed{msg, ref error, ref debug} => msg,
            Message::Tag(msg) => msg,
            Message::TagParsed{msg, ref tags} => msg,
            Message::Buffering(msg) => msg,
            Message::BufferingParsed{msg, ref pct} => msg,
            Message::StateChanged(msg) => msg,
            Message::StateChangedParsed{msg, ref old, ref new, ref pending} => msg,
            Message::StateDirty(msg) => msg,
            Message::StepDone(msg) => msg,
            Message::ClockProvide(msg) => msg,
            Message::ClockLost(msg) => msg,
            Message::NewClock(msg) => msg,
            Message::StructureChange(msg) => msg,
            Message::StreamStatus(msg) => msg,
            Message::Application(msg) => msg,
            Message::Element(msg) => msg,
            Message::SegmentStart(msg) => msg,
            Message::SegmentDone(msg) => msg,
            Message::DurationChanged(msg) => msg,
            Message::Latency(msg) => msg,
            Message::AsyncStart(msg) => msg,
            Message::AsyncDone(msg) => msg,
            Message::RequestState(msg) => msg,
            Message::StepStart(msg) => msg,
            Message::Qos(msg) => msg,
            Message::Progress(msg) => msg,
            Message::Toc(msg) => msg,
            Message::ResetTime(msg) => msg,
            Message::StreamStart(msg) => msg,
            Message::NeedContext(msg) => msg,
            Message::HaveContext(msg) => msg,
            Message::Extended(msg) => msg,
            Message::DeviceAdded(msg) => msg,
            Message::DeviceRemoved(msg) => msg,
            Message::Any(msg) => msg,
        }
    }

	#[allow(unused_variables)]
    pub unsafe fn gst_message_mut(&mut self) -> *mut GstMessage{
        match *self{
            Message::Unknown(msg) => msg,
            Message::Eos(msg) => msg,
            Message::Error(msg) => msg,
            Message::ErrorParsed{msg, ref error, ref debug} => msg,
            Message::Warning(msg) => msg,
            Message::WarningParsed{msg, ref error, ref debug} => msg,
            Message::Info(msg) => msg,
            Message::InfoParsed{msg, ref error, ref debug} => msg,
            Message::Tag(msg) => msg,
            Message::TagParsed{msg, ref tags} => msg,
            Message::Buffering(msg) => msg,
            Message::BufferingParsed{msg, ref pct} => msg,
            Message::StateChanged(msg) => msg,
            Message::StateChangedParsed{msg, ref old, ref new, ref pending} => msg,
            Message::StateDirty(msg) => msg,
            Message::StepDone(msg) => msg,
            Message::ClockProvide(msg) => msg,
            Message::ClockLost(msg) => msg,
            Message::NewClock(msg) => msg,
            Message::StructureChange(msg) => msg,
            Message::StreamStatus(msg) => msg,
            Message::Application(msg) => msg,
            Message::Element(msg) => msg,
            Message::SegmentStart(msg) => msg,
            Message::SegmentDone(msg) => msg,
            Message::DurationChanged(msg) => msg,
            Message::Latency(msg) => msg,
            Message::AsyncStart(msg) => msg,
            Message::AsyncDone(msg) => msg,
            Message::RequestState(msg) => msg,
            Message::StepStart(msg) => msg,
            Message::Qos(msg) => msg,
            Message::Progress(msg) => msg,
            Message::Toc(msg) => msg,
            Message::ResetTime(msg) => msg,
            Message::StreamStart(msg) => msg,
            Message::NeedContext(msg) => msg,
            Message::HaveContext(msg) => msg,
            Message::Extended(msg) => msg,
            Message::DeviceAdded(msg) => msg,
            Message::DeviceRemoved(msg) => msg,
            Message::Any(msg) => msg,
        }
    }

    pub fn ty(&self) -> GstMessageType{
        unsafe{
            (*self.gst_message())._type
        }
    }

    pub fn type_name(&self) -> String{
        unsafe{
            from_c_str!(gst_message_type_get_name(self.ty())).to_string()
        }
    }

    pub fn seqnum(&self) -> u32{
        unsafe{
            gst_message_get_seqnum(mem::transmute(self.gst_message()))
        }
    }

    pub fn set_seqnum(&mut self, seqnum: u32){
        unsafe{
            gst_message_set_seqnum(self.gst_message_mut(),seqnum)
        }
    }

    pub fn timestamp(&self) -> u64{
        unsafe{
            (*self.gst_message()).timestamp
        }
    }

    pub unsafe fn src(&self) -> *mut GstObject{
        (*self.gst_message()).src
    }

    pub fn src_name(&self) -> String{
        unsafe{
            from_c_str!(mem::transmute((*self.src()).name)).to_string()
        }
    }

    pub unsafe fn structure(&self) -> *const GstStructure{
        gst_message_get_structure(mem::transmute(self.gst_message()))
    }

    pub fn make_writable(&self) -> Option<Message>{
        unsafe{
            Message::new(gst_mini_object_make_writable(self.gst_message() as *mut GstMiniObject) as *mut GstMessage)
        }
    }

    pub fn is_writable(&self) -> bool{
        unsafe{
            gst_mini_object_is_writable(self.gst_message() as *mut GstMiniObject) == 1
        }
    }

    pub fn parse(&self) -> Message{
        unsafe{
			let ret = Message::new(gst_mini_object_copy(self.gst_message() as *mut GstMiniObject) as *const GstMessage).unwrap();
            match ret{
                Message::Error(message) => {
                    let mut error: *mut GError = ptr::null_mut();
                    let mut debug: *mut raw::c_char = ptr::null_mut();
                    gst_message_parse_error(message,&mut error,&mut debug);
                    let str_error = from_c_str!(mem::transmute(debug)).to_string();
                    g_free(mem::transmute(debug));
                    let message = gst_message_ref(message);
                    Message::ErrorParsed{msg: message, error: Error::new_from_g_error(error), debug: str_error}
                }
                Message::Warning(message) => {
                    let mut error: *mut GError = ptr::null_mut();
                    let mut debug: *mut raw::c_char = ptr::null_mut();
                    gst_message_parse_warning(message,&mut error,&mut debug);
                    let str_error = from_c_str!(mem::transmute(debug)).to_string();
                    g_free(mem::transmute(debug));
                    let message = gst_message_ref(message);
                    Message::WarningParsed{msg: message, error: Error::new_from_g_error(error), debug: str_error}
                }
                Message::Info(message) => {
                    let mut error: *mut GError = ptr::null_mut();
                    let mut debug: *mut raw::c_char = ptr::null_mut();
                    gst_message_parse_info(message,&mut error,&mut debug);
                    let str_error = from_c_str!(mem::transmute(debug)).to_string();
                    g_free(mem::transmute(debug));
                    let message = gst_message_ref(message);
                    Message::InfoParsed{msg: message, error: Error::new_from_g_error(error), debug: str_error}
                }
                Message::Tag(message) => {
                    let mut tags: *mut GstTagList = ptr::null_mut();
                    gst_message_parse_tag(message,&mut tags);
                    let message = gst_message_ref(message);
                    Message::TagParsed{msg: message, tags: tags}
                }
                Message::Buffering(message) => {
                    let mut pct: i32 = 0;
                    let message = gst_message_ref(message);
                    gst_message_parse_buffering(message,&mut pct);
                    Message::BufferingParsed{msg: message, pct: pct}
                }
                Message::StateChanged(message) => {
                    let mut old: GstState = GST_STATE_NULL;
                    let mut new: GstState = GST_STATE_NULL;
                    let mut pending: GstState = GST_STATE_NULL;
                    gst_message_parse_state_changed(message,&mut old,&mut new,&mut pending);
                    let message = gst_message_ref(message);
                    Message::StateChangedParsed{msg: message, old: old, new: new, pending: pending}
                }
                _ => {
                    ret
                }
                /*
                Message::StateDirty(message) => message,
                Message::StepDone(message) => message,
                Message::ClockProvide(message) => message,
                Message::ClockLost(message) => message,
                Message::NewClock(message) => message,
                Message::StructureChange(message) => message,
                Message::StreamStatus(message) => message,
                Message::Application(message) => message,
                Message::Element(message) => message,
                Message::SegmentStart(message) => message,
                Message::SegmentDone(message) => message,
                Message::DurationChanged(message) => message,
                Message::Latency(message) => message,
                Message::AsyncStart(message) => message,
                Message::AsyncDone(message) => message,
                Message::RequestState(message) => message,
                Message::StepStart(message) => message,
                Message::Qos(message) => message,
                Message::Progress(message) => message,
                Message::Toc(message) => message,
                Message::ResetTime(message) => message,
                Message::StreamStart(message) => message,
                Message::NeedContext(message) => message,
                Message::HaveContext(message) => message,
                Message::Extended(message) => message,
                Message::DeviceAdded(message) => message,
                Message::DeviceRemoved(message) => message,
                Message::Any(message) => message,*/
            }
        }
    }
}


impl ::Transfer<GstMessage> for Message{
    unsafe fn transfer(mut self) ->  *mut GstMessage{
        let message = self.gst_message_mut();
		mem::forget(self);
        message
    }
}

impl Reference for Message{
    fn reference(&self) -> Message{
        unsafe{
			Message::new(self.gst_message()).unwrap()
		}
    }
}
/*pub trait MessageT{
    unsafe fn gst_message(&self) -> *mut GstMessage;

    fn class_ty() -> GstMessageType;

    fn from_gst_msg(gst_message: *mut GstMessage) -> Option<Self>;

    fn make_writable(&self) -> Option<Self>;

    fn ty(&self) -> GstMessageType{
        unsafe{
            (*self.gst_message())._type
        }
    }

    fn type_name(&self) -> String{
        unsafe{
            from_c_str!(gst_message_type_get_name(self.ty())).to_string()
        }
    }

    fn seqnum(&self) -> u32{
        unsafe{
            gst_message_get_seqnum(self.gst_message())
        }
    }

    fn set_seqnum(&mut self, seqnum: u32){
        unsafe{
            gst_message_set_seqnum(self.gst_message(),seqnum)
        }
    }

    fn timestamp(&self) -> u64{
        unsafe{
            (*self.gst_message()).timestamp
        }
    }

    unsafe fn src(&self) -> *mut GstObject{
        (*self.gst_message()).src
    }

    fn src_name(&self) -> String{
        unsafe{
            from_c_str!(mem::transmute((*self.src()).name)).to_string()
        }
    }

    unsafe fn structure(&self) -> *const GstStructure{
        gst_message_get_structure(self.gst_message())
    }

    fn is_writable(&self) -> bool{
        unsafe{
            gst_mini_object_is_writable(self.gst_message() as *mut GstMiniObject) == 1
        }
    }
}

pub struct Unknown(MessagePrivate);
pub struct Eos(MessagePrivate);
pub struct Error(MessagePrivate);
pub struct Warning(MessagePrivate);
pub struct Info(MessagePrivate);
pub struct Tag(MessagePrivate);
pub struct Buffering(MessagePrivate);
pub struct StateChanged(MessagePrivate);
pub struct StateDirty(MessagePrivate);
pub struct StepDone(MessagePrivate);
pub struct ClockProvide(MessagePrivate);
pub struct ClockLost(MessagePrivate);
pub struct NewClock(MessagePrivate);
pub struct StructureChange(MessagePrivate);
pub struct StreamStatus(MessagePrivate);
pub struct Application(MessagePrivate);
pub struct Element(MessagePrivate);
pub struct SegmentStart(MessagePrivate);
pub struct SegmentDone(MessagePrivate);
pub struct DurationChanged(MessagePrivate);
pub struct Latency(MessagePrivate);
pub struct AsyncStart(MessagePrivate);
pub struct AsyncDone(MessagePrivate);
pub struct RequestState(MessagePrivate);
pub struct StepStart(MessagePrivate);
pub struct Qos(MessagePrivate);
pub struct Progress(MessagePrivate);
pub struct Toc(MessagePrivate);
pub struct ResetTime(MessagePrivate);
pub struct StreamStart(MessagePrivate);
pub struct NeedContext(MessagePrivate);
pub struct HaveContext(MessagePrivate);
pub struct Extended(MessagePrivate);
pub struct DeviceAdded(MessagePrivate);
pub struct DeviceRemoved(MessagePrivate);
pub struct Any(MessagePrivate);


macro_rules! msg_impl(
  ($t: ident, $msg_t: expr) => (
    impl MessageT for $t {
        unsafe fn gst_message(&self) -> *mut GstMessage{
            self.0.message.0
        }

        fn class_ty() -> GstMessageType{
            $msg_t
        }

        fn from_gst_msg(gst_message: *mut GstMessage) -> Option<$t>{
            if gst_message != ptr::null_mut(){
                unsafe{
                    let gst_message = gst_mini_object_ref(gst_message as *mut GstMiniObject) as *mut GstMessage;
                    if (*gst_message)._type == $msg_t{
                        Some($t(gst_message))
                    }else{
                        None
                    }
                }
            }else{
                None
            }
        }

        fn make_writable(&self) -> Option<$t>{
            unsafe{
                MessageT::from_gst_msg(gst_mini_object_make_writable(self.gst_message() as *mut GstMiniObject) as *mut GstMessage)
            }
        }
    }
  )
);

msg_impl!(Unknown,GST_MESSAGE_UNKNOWN);
msg_impl!(Eos,GST_MESSAGE_EOS);
msg_impl!(Error,GST_MESSAGE_ERROR);
msg_impl!(Warning,GST_MESSAGE_WARNING);
msg_impl!(Info,GST_MESSAGE_INFO);
msg_impl!(Tag,GST_MESSAGE_TAG);
msg_impl!(Buffering,GST_MESSAGE_BUFFERING);
msg_impl!(StateChanged,GST_MESSAGE_STATE_CHANGED);
msg_impl!(StateDirty,GST_MESSAGE_STATE_DIRTY);
msg_impl!(StepDone,GST_MESSAGE_STEP_DONE);
msg_impl!(ClockProvide,GST_MESSAGE_CLOCK_PROVIDE);
msg_impl!(ClockLost,GST_MESSAGE_CLOCK_LOST);
msg_impl!(NewClock,GST_MESSAGE_NEW_CLOCK);
msg_impl!(StructureChange,GST_MESSAGE_STRUCTURE_CHANGE);
msg_impl!(StreamStatus,GST_MESSAGE_STREAM_STATUS);
msg_impl!(Application,GST_MESSAGE_APPLICATION);
msg_impl!(Element,GST_MESSAGE_ELEMENT);
msg_impl!(SegmentStart,GST_MESSAGE_SEGMENT_START);
msg_impl!(SegmentDone,GST_MESSAGE_SEGMENT_DONE);
msg_impl!(DurationChanged,GST_MESSAGE_DURATION_CHANGED);
msg_impl!(Latency,GST_MESSAGE_LATENCY);
msg_impl!(AsyncStart,GST_MESSAGE_ASYNC_START);
msg_impl!(AsyncDone,GST_MESSAGE_ASYNC_DONE);
msg_impl!(RequestState,GST_MESSAGE_REQUEST_STATE);
msg_impl!(StepStart,GST_MESSAGE_STEP_START);
msg_impl!(Qos,GST_MESSAGE_QOS);
msg_impl!(Progress,GST_MESSAGE_PROGRESS);
msg_impl!(Toc,GST_MESSAGE_TOC);
msg_impl!(ResetTime,GST_MESSAGE_RESET_TIME);
msg_impl!(StreamStart,GST_MESSAGE_STREAM_START);
msg_impl!(NeedContext,GST_MESSAGE_NEED_CONTEXT);
msg_impl!(HaveContext,GST_MESSAGE_HAVE_CONTEXT);
msg_impl!(Extended,GST_MESSAGE_EXTENDED);
msg_impl!(DeviceAdded,GST_MESSAGE_DEVICE_ADDED);
msg_impl!(DeviceRemoved,GST_MESSAGE_DEVICE_REMOVED);
msg_impl!(Any,GST_MESSAGE_ANY);

impl Eos{
    pub fn new(src: *mut GstObject) -> Option<Eos>{
        unsafe{
            MessageT::from_gst_msg(gst_message_new_eos(src))
        }
    }
}*/