sdp_message.rs 22.1 KB
Newer Older
1 2 3 4 5 6 7 8
// Copyright (C) 2018 Sebastian Dröge <sebastian@centricular.com>
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

9
use std::ffi::CStr;
10 11 12
use std::mem;
use std::ptr;

13
use ffi;
14
use glib::translate::*;
15
use glib_ffi;
16
use gobject_ffi;
17
use gst;
18 19
use gst::MiniObject;

20 21 22 23 24 25 26 27
use sdp_attribute::SDPAttribute;
use sdp_bandwidth::SDPBandwidth;
use sdp_connection::SDPConnection;
use sdp_key::SDPKey;
use sdp_media::SDPMedia;
use sdp_origin::SDPOrigin;
use sdp_time::SDPTime;
use sdp_zone::SDPZone;
28

29 30 31
#[cfg(any(feature = "v1_8_1", feature = "dox"))]
use MIKEYMessage;

32 33 34 35 36 37 38 39 40
glib_wrapper! {
    pub struct SDPMessage(Boxed<ffi::GstSDPMessage>);

    match fn {
        copy => |ptr| gobject_ffi::g_boxed_copy(ffi::gst_sdp_message_get_type(), ptr as *mut _) as *mut ffi::GstSDPMessage,
        free => |ptr| gobject_ffi::g_boxed_free(ffi::gst_sdp_message_get_type(), ptr as *mut _),
        get_type => || ffi::gst_sdp_message_get_type(),
    }
}
Sebastian Dröge's avatar
Sebastian Dröge committed
41 42 43 44 45

impl SDPMessage {
    pub fn new() -> SDPMessage {
        assert_initialized_main_thread!();
        unsafe {
46 47
            let mut msg = mem::zeroed();
            ffi::gst_sdp_message_new(&mut msg);
Sebastian Dröge's avatar
Sebastian Dröge committed
48 49 50
            from_glib_full(msg)
        }
    }
51

52 53 54 55 56
    pub fn add_attribute<'a, P: Into<Option<&'a str>>>(
        &mut self,
        key: &str,
        value: P,
    ) -> Result<(), ()> {
57
        let result = unsafe {
58
            ffi::gst_sdp_message_add_attribute(
59 60 61
                self.to_glib_none_mut().0,
                key.to_glib_none().0,
                value.into().to_glib_none().0,
62
            )
63 64
        };
        match result {
65
            ffi::GST_SDP_OK => Ok(()),
66 67 68 69
            _ => Err(()),
        }
    }

70
    pub fn add_email(&mut self, email: &str) -> Result<(), ()> {
71
        let result = unsafe {
72
            ffi::gst_sdp_message_add_email(self.to_glib_none_mut().0, email.to_glib_none().0)
73 74
        };
        match result {
75
            ffi::GST_SDP_OK => Ok(()),
76 77 78 79
            _ => Err(()),
        }
    }

80
    pub fn add_media(&mut self, media: SDPMedia) -> Result<(), ()> {
81
        let result = unsafe {
82
            ffi::gst_sdp_message_add_media(
83 84
                self.to_glib_none_mut().0,
                media.to_glib_full() as *mut ffi::GstSDPMedia,
85
            )
86 87 88
        };
        mem::forget(media);
        match result {
89
            ffi::GST_SDP_OK => Ok(()),
90 91 92 93
            _ => Err(()),
        }
    }

94
    pub fn add_phone(&mut self, phone: &str) -> Result<(), ()> {
95
        let result = unsafe {
96
            ffi::gst_sdp_message_add_phone(self.to_glib_none_mut().0, phone.to_glib_none().0)
97 98
        };
        match result {
99
            ffi::GST_SDP_OK => Ok(()),
100 101 102 103
            _ => Err(()),
        }
    }

104
    pub fn add_time(&mut self, start: &str, stop: &str, repeat: &[&str]) -> Result<(), ()> {
105
        let result = unsafe {
106
            ffi::gst_sdp_message_add_time(
107 108 109 110
                self.to_glib_none_mut().0,
                start.to_glib_none().0,
                stop.to_glib_none().0,
                repeat.to_glib_none().0,
111
            )
112 113
        };
        match result {
114
            ffi::GST_SDP_OK => Ok(()),
115 116 117 118
            _ => Err(()),
        }
    }

119
    pub fn add_zone(&mut self, adj_time: &str, typed_time: &str) -> Result<(), ()> {
120
        let result = unsafe {
121
            ffi::gst_sdp_message_add_zone(
122 123 124
                self.to_glib_none_mut().0,
                adj_time.to_glib_none().0,
                typed_time.to_glib_none().0,
125
            )
126 127
        };
        match result {
128
            ffi::GST_SDP_OK => Ok(()),
129 130 131 132 133
            _ => Err(()),
        }
    }

    pub fn as_text(&self) -> Option<String> {
134
        unsafe { from_glib_full(ffi::gst_sdp_message_as_text(self.to_glib_none().0)) }
135 136 137
    }

    pub fn attributes_len(&self) -> u32 {
138
        unsafe { ffi::gst_sdp_message_attributes_len(self.to_glib_none().0) }
139 140
    }

141
    pub fn attributes_to_caps(&self, caps: &mut gst::CapsRef) -> Result<(), ()> {
142
        let result = unsafe {
143
            ffi::gst_sdp_message_attributes_to_caps(self.to_glib_none().0, caps.as_mut_ptr())
144 145
        };
        match result {
146
            ffi::GST_SDP_OK => Ok(()),
147 148 149 150 151
            _ => Err(()),
        }
    }

    pub fn bandwidths_len(&self) -> u32 {
152
        unsafe { ffi::gst_sdp_message_bandwidths_len(self.to_glib_none().0) }
153 154
    }

155
    pub fn dump(&self) -> Result<(), ()> {
156
        let result = unsafe { ffi::gst_sdp_message_dump(self.to_glib_none().0) };
157
        match result {
158
            ffi::GST_SDP_OK => Ok(()),
159 160 161 162 163
            _ => Err(()),
        }
    }

    pub fn emails_len(&self) -> u32 {
164
        unsafe { ffi::gst_sdp_message_emails_len(self.to_glib_none().0) }
165 166
    }

167
    pub fn get_attribute(&self, idx: u32) -> Option<&SDPAttribute> {
168
        unsafe {
169 170 171 172 173 174
            let ptr = ffi::gst_sdp_message_get_attribute(self.to_glib_none().0, idx);
            if ptr.is_null() {
                None
            } else {
                Some(&*(ptr as *mut SDPAttribute))
            }
175 176 177
        }
    }

178
    pub fn get_attribute_val(&self, key: &str) -> Option<&str> {
179
        unsafe {
180 181
            let ptr =
                ffi::gst_sdp_message_get_attribute_val(self.to_glib_none().0, key.to_glib_none().0);
182 183 184 185 186 187 188 189 190
            if ptr.is_null() {
                None
            } else {
                let result = CStr::from_ptr(ptr).to_str();
                match result {
                    Ok(attr) => Some(attr),
                    Err(_) => None,
                }
            }
191 192 193
        }
    }

194
    pub fn get_attribute_val_n(&self, key: &str, nth: u32) -> Option<&str> {
195
        unsafe {
196 197 198 199 200
            let ptr = ffi::gst_sdp_message_get_attribute_val_n(
                self.to_glib_none().0,
                key.to_glib_none().0,
                nth,
            );
201 202 203 204 205 206 207 208 209
            if ptr.is_null() {
                None
            } else {
                let result = CStr::from_ptr(ptr).to_str();
                match result {
                    Ok(attr) => Some(attr),
                    Err(_) => None,
                }
            }
210 211 212
        }
    }

213
    pub fn get_bandwidth(&self, idx: u32) -> Option<&SDPBandwidth> {
214
        unsafe {
215 216 217 218 219 220
            let ptr = ffi::gst_sdp_message_get_bandwidth(self.to_glib_none().0, idx);
            if ptr.is_null() {
                None
            } else {
                Some(&*(ptr as *mut SDPBandwidth))
            }
221 222 223
        }
    }

224
    pub fn get_connection(&self) -> Option<&SDPConnection> {
225
        unsafe {
226 227 228 229 230 231
            let ptr = ffi::gst_sdp_message_get_connection(self.to_glib_none().0);
            if ptr.is_null() {
                None
            } else {
                Some(&*(ptr as *mut SDPConnection))
            }
232 233 234
        }
    }

235
    pub fn get_email(&self, idx: u32) -> Option<&str> {
236
        unsafe {
237 238 239 240 241 242 243 244 245 246
            let ptr = ffi::gst_sdp_message_get_email(self.to_glib_none().0, idx);
            if ptr.is_null() {
                None
            } else {
                let result = CStr::from_ptr(ptr).to_str();
                match result {
                    Ok(attr) => Some(attr),
                    Err(_) => None,
                }
            }
247 248 249
        }
    }

250
    pub fn get_information(&self) -> Option<&str> {
251
        unsafe {
252 253 254 255 256 257 258 259 260 261
            let ptr = ffi::gst_sdp_message_get_information(self.to_glib_none().0);
            if ptr.is_null() {
                None
            } else {
                let result = CStr::from_ptr(ptr).to_str();
                match result {
                    Ok(attr) => Some(attr),
                    Err(_) => None,
                }
            }
262 263 264
        }
    }

265
    pub fn get_key(&self) -> Option<&SDPKey> {
266
        unsafe {
267 268 269 270 271 272
            let ptr = ffi::gst_sdp_message_get_key(self.to_glib_none().0);
            if ptr.is_null() {
                None
            } else {
                Some(&*(ptr as *mut SDPKey))
            }
273 274 275
        }
    }

276
    pub fn get_media(&self, idx: u32) -> Option<&SDPMedia> {
277
        unsafe {
278 279 280 281 282 283
            let ptr = ffi::gst_sdp_message_get_media(self.to_glib_none().0, idx);
            if ptr.is_null() {
                None
            } else {
                Some(&*(ptr as *mut SDPMedia))
            }
284 285 286
        }
    }

287
    pub fn get_origin(&self) -> Option<&SDPOrigin> {
288
        unsafe {
289 290 291 292 293 294
            let ptr = ffi::gst_sdp_message_get_origin(self.to_glib_none().0);
            if ptr.is_null() {
                None
            } else {
                Some(&*(ptr as *mut SDPOrigin))
            }
295 296 297
        }
    }

298
    pub fn get_phone(&self, idx: u32) -> Option<&str> {
299
        unsafe {
300 301 302 303 304 305 306 307 308 309
            let ptr = ffi::gst_sdp_message_get_phone(self.to_glib_none().0, idx);
            if ptr.is_null() {
                None
            } else {
                let result = CStr::from_ptr(ptr).to_str();
                match result {
                    Ok(attr) => Some(attr),
                    Err(_) => None,
                }
            }
310 311 312
        }
    }

313
    pub fn get_session_name(&self) -> Option<&str> {
314
        unsafe {
315 316 317 318 319 320 321 322 323 324
            let ptr = ffi::gst_sdp_message_get_session_name(self.to_glib_none().0);
            if ptr.is_null() {
                None
            } else {
                let result = CStr::from_ptr(ptr).to_str();
                match result {
                    Ok(attr) => Some(attr),
                    Err(_) => None,
                }
            }
325 326 327
        }
    }

328
    pub fn get_time(&self, idx: u32) -> Option<&SDPTime> {
329
        unsafe {
330 331 332 333 334 335
            let ptr = ffi::gst_sdp_message_get_time(self.to_glib_none().0, idx);
            if ptr.is_null() {
                None
            } else {
                Some(&*(ptr as *mut SDPTime))
            }
336 337 338
        }
    }

339
    pub fn get_uri(&self) -> Option<&str> {
340
        unsafe {
341 342 343 344 345 346 347 348 349 350
            let ptr = ffi::gst_sdp_message_get_uri(self.to_glib_none().0);
            if ptr.is_null() {
                None
            } else {
                let result = CStr::from_ptr(ptr).to_str();
                match result {
                    Ok(attr) => Some(attr),
                    Err(_) => None,
                }
            }
351 352 353
        }
    }

354
    pub fn get_version(&self) -> Option<&str> {
355
        unsafe {
356 357 358 359 360 361 362 363 364 365
            let ptr = ffi::gst_sdp_message_get_version(self.to_glib_none().0);
            if ptr.is_null() {
                None
            } else {
                let result = CStr::from_ptr(ptr).to_str();
                match result {
                    Ok(attr) => Some(attr),
                    Err(_) => None,
                }
            }
366 367 368
        }
    }

369
    pub fn get_zone(&self, idx: u32) -> Option<&SDPZone> {
370
        unsafe {
371 372 373 374 375 376
            let ptr = ffi::gst_sdp_message_get_zone(self.to_glib_none().0, idx);
            if ptr.is_null() {
                None
            } else {
                Some(&*(ptr as *mut SDPZone))
            }
377 378 379
        }
    }

380
    pub fn insert_attribute(&mut self, idx: i32, mut attr: SDPAttribute) -> Result<(), ()> {
381
        let result = unsafe {
382
            ffi::gst_sdp_message_insert_attribute(self.to_glib_none_mut().0, idx, &mut attr.0)
383 384 385
        };
        mem::forget(attr);
        match result {
386
            ffi::GST_SDP_OK => Ok(()),
387 388 389 390
            _ => Err(()),
        }
    }

391
    pub fn insert_bandwidth(&mut self, idx: i32, mut bw: SDPBandwidth) -> Result<(), ()> {
392
        let result = unsafe {
393
            ffi::gst_sdp_message_insert_bandwidth(self.to_glib_none_mut().0, idx, &mut bw.0)
394 395 396
        };
        mem::forget(bw);
        match result {
397
            ffi::GST_SDP_OK => Ok(()),
398 399 400 401
            _ => Err(()),
        }
    }

402
    pub fn insert_email(&mut self, idx: i32, email: &str) -> Result<(), ()> {
403
        let result = unsafe {
404
            ffi::gst_sdp_message_insert_email(
405 406 407
                self.to_glib_none_mut().0,
                idx,
                email.to_glib_none().0,
408
            )
409 410
        };
        match result {
411
            ffi::GST_SDP_OK => Ok(()),
412 413 414 415
            _ => Err(()),
        }
    }

416
    pub fn insert_phone(&mut self, idx: i32, phone: &str) -> Result<(), ()> {
417
        let result = unsafe {
418
            ffi::gst_sdp_message_insert_phone(
419 420 421
                self.to_glib_none_mut().0,
                idx,
                phone.to_glib_none().0,
422
            )
423 424
        };
        match result {
425
            ffi::GST_SDP_OK => Ok(()),
426 427 428 429
            _ => Err(()),
        }
    }

430
    pub fn insert_time(&mut self, idx: i32, mut time: SDPTime) -> Result<(), ()> {
431
        let result = unsafe {
432
            ffi::gst_sdp_message_insert_time(self.to_glib_none_mut().0, idx, &mut time.0)
433 434 435
        };
        mem::forget(time);
        match result {
436
            ffi::GST_SDP_OK => Ok(()),
437 438 439 440
            _ => Err(()),
        }
    }

441
    pub fn insert_zone(&mut self, idx: i32, mut zone: SDPZone) -> Result<(), ()> {
442
        let result = unsafe {
443
            ffi::gst_sdp_message_insert_zone(self.to_glib_none_mut().0, idx, &mut zone.0)
444
        };
445
        mem::forget(zone);
446
        match result {
447
            ffi::GST_SDP_OK => Ok(()),
448 449 450 451 452
            _ => Err(()),
        }
    }

    pub fn medias_len(&self) -> u32 {
453
        unsafe { ffi::gst_sdp_message_medias_len(self.to_glib_none().0) }
454 455 456
    }

    #[cfg(any(feature = "v1_8_1", feature = "dox"))]
457 458 459 460 461 462 463 464
    pub fn parse_keymgmt(&self) -> Result<MIKEYMessage, ()> {
        unsafe {
            let mut mikey = ptr::null_mut();
            let result = ffi::gst_sdp_message_parse_keymgmt(self.to_glib_none().0, &mut mikey);
            match result {
                ffi::GST_SDP_OK => Ok(from_glib_full(mikey)),
                _ => Err(()),
            }
465 466 467 468
        }
    }

    pub fn phones_len(&self) -> u32 {
469
        unsafe { ffi::gst_sdp_message_phones_len(self.to_glib_none().0) }
470 471
    }

472
    pub fn remove_attribute(&mut self, idx: u32) -> Result<(), ()> {
473 474
        let result =
            unsafe { ffi::gst_sdp_message_remove_attribute(self.to_glib_none_mut().0, idx) };
475
        match result {
476
            ffi::GST_SDP_OK => Ok(()),
477 478 479 480
            _ => Err(()),
        }
    }

481
    pub fn remove_bandwidth(&mut self, idx: u32) -> Result<(), ()> {
482 483
        let result =
            unsafe { ffi::gst_sdp_message_remove_bandwidth(self.to_glib_none_mut().0, idx) };
484
        match result {
485
            ffi::GST_SDP_OK => Ok(()),
486 487 488 489
            _ => Err(()),
        }
    }

490
    pub fn remove_email(&mut self, idx: u32) -> Result<(), ()> {
491
        let result = unsafe { ffi::gst_sdp_message_remove_email(self.to_glib_none_mut().0, idx) };
492
        match result {
493
            ffi::GST_SDP_OK => Ok(()),
494 495 496 497
            _ => Err(()),
        }
    }

498
    pub fn remove_phone(&mut self, idx: u32) -> Result<(), ()> {
499
        let result = unsafe { ffi::gst_sdp_message_remove_phone(self.to_glib_none_mut().0, idx) };
500
        match result {
501
            ffi::GST_SDP_OK => Ok(()),
502 503 504 505
            _ => Err(()),
        }
    }

506
    pub fn remove_time(&mut self, idx: u32) -> Result<(), ()> {
507
        let result = unsafe { ffi::gst_sdp_message_remove_time(self.to_glib_none_mut().0, idx) };
508
        match result {
509
            ffi::GST_SDP_OK => Ok(()),
510 511 512 513
            _ => Err(()),
        }
    }

514
    pub fn remove_zone(&mut self, idx: u32) -> Result<(), ()> {
515
        let result = unsafe { ffi::gst_sdp_message_remove_zone(self.to_glib_none_mut().0, idx) };
516
        match result {
517
            ffi::GST_SDP_OK => Ok(()),
518 519 520 521
            _ => Err(()),
        }
    }

522
    pub fn replace_attribute(&mut self, idx: u32, mut attr: SDPAttribute) -> Result<(), ()> {
523
        let result = unsafe {
524
            ffi::gst_sdp_message_replace_attribute(self.to_glib_none_mut().0, idx, &mut attr.0)
525 526 527
        };
        mem::forget(attr);
        match result {
528
            ffi::GST_SDP_OK => Ok(()),
529 530 531 532
            _ => Err(()),
        }
    }

533
    pub fn replace_bandwidth(&mut self, idx: u32, mut bw: SDPBandwidth) -> Result<(), ()> {
534
        let result = unsafe {
535
            ffi::gst_sdp_message_replace_bandwidth(self.to_glib_none_mut().0, idx, &mut bw.0)
536 537 538
        };
        mem::forget(bw);
        match result {
539
            ffi::GST_SDP_OK => Ok(()),
540 541 542 543
            _ => Err(()),
        }
    }

544
    pub fn replace_email(&mut self, idx: u32, email: &str) -> Result<(), ()> {
545
        let result = unsafe {
546
            ffi::gst_sdp_message_replace_email(
547 548 549
                self.to_glib_none_mut().0,
                idx,
                email.to_glib_none().0,
550
            )
551 552
        };
        match result {
553
            ffi::GST_SDP_OK => Ok(()),
554 555 556 557
            _ => Err(()),
        }
    }

558
    pub fn replace_phone(&mut self, idx: u32, phone: &str) -> Result<(), ()> {
559
        let result = unsafe {
560
            ffi::gst_sdp_message_replace_phone(
561 562 563
                self.to_glib_none_mut().0,
                idx,
                phone.to_glib_none().0,
564
            )
565 566
        };
        match result {
567
            ffi::GST_SDP_OK => Ok(()),
568 569 570 571
            _ => Err(()),
        }
    }

572
    pub fn replace_time(&mut self, idx: u32, mut time: SDPTime) -> Result<(), ()> {
573
        let result = unsafe {
574
            ffi::gst_sdp_message_replace_time(self.to_glib_none_mut().0, idx, &mut time.0)
575 576 577
        };
        mem::forget(time);
        match result {
578
            ffi::GST_SDP_OK => Ok(()),
579 580 581 582
            _ => Err(()),
        }
    }

583
    pub fn replace_zone(&mut self, idx: u32, mut zone: SDPZone) -> Result<(), ()> {
584
        let result = unsafe {
585
            ffi::gst_sdp_message_replace_zone(self.to_glib_none_mut().0, idx, &mut zone.0)
586 587 588
        };
        mem::forget(zone);
        match result {
589
            ffi::GST_SDP_OK => Ok(()),
590 591 592 593
            _ => Err(()),
        }
    }

594 595 596 597 598 599 600 601
    pub fn set_connection(
        &mut self,
        nettype: &str,
        addrtype: &str,
        address: &str,
        ttl: u32,
        addr_number: u32,
    ) -> Result<(), ()> {
602
        let result = unsafe {
603
            ffi::gst_sdp_message_set_connection(
604 605 606 607 608 609
                self.to_glib_none_mut().0,
                nettype.to_glib_none().0,
                addrtype.to_glib_none().0,
                address.to_glib_none().0,
                ttl,
                addr_number,
610
            )
611 612
        };
        match result {
613
            ffi::GST_SDP_OK => Ok(()),
614 615 616 617
            _ => Err(()),
        }
    }

618
    pub fn set_information(&mut self, information: &str) -> Result<(), ()> {
619
        let result = unsafe {
620
            ffi::gst_sdp_message_set_information(
621 622
                self.to_glib_none_mut().0,
                information.to_glib_none().0,
623
            )
624 625
        };
        match result {
626
            ffi::GST_SDP_OK => Ok(()),
627 628 629 630
            _ => Err(()),
        }
    }

631
    pub fn set_key(&mut self, type_: &str, data: &str) -> Result<(), ()> {
632
        let result = unsafe {
633
            ffi::gst_sdp_message_set_key(
634 635 636
                self.to_glib_none_mut().0,
                type_.to_glib_none().0,
                data.to_glib_none().0,
637
            )
638 639
        };
        match result {
640
            ffi::GST_SDP_OK => Ok(()),
641 642 643 644
            _ => Err(()),
        }
    }

645 646 647 648 649 650 651 652 653
    pub fn set_origin(
        &mut self,
        username: &str,
        sess_id: &str,
        sess_version: &str,
        nettype: &str,
        addrtype: &str,
        addr: &str,
    ) -> Result<(), ()> {
654
        let result = unsafe {
655
            ffi::gst_sdp_message_set_origin(
656 657 658 659 660 661 662
                self.to_glib_none_mut().0,
                username.to_glib_none().0,
                sess_id.to_glib_none().0,
                sess_version.to_glib_none().0,
                nettype.to_glib_none().0,
                addrtype.to_glib_none().0,
                addr.to_glib_none().0,
663
            )
664 665
        };
        match result {
666
            ffi::GST_SDP_OK => Ok(()),
667 668 669 670
            _ => Err(()),
        }
    }

671
    pub fn set_session_name(&mut self, session_name: &str) -> Result<(), ()> {
672
        let result = unsafe {
673
            ffi::gst_sdp_message_set_session_name(
674 675
                self.to_glib_none_mut().0,
                session_name.to_glib_none().0,
676
            )
677 678
        };
        match result {
679
            ffi::GST_SDP_OK => Ok(()),
680 681 682 683
            _ => Err(()),
        }
    }

684
    pub fn set_uri(&mut self, uri: &str) -> Result<(), ()> {
685
        let result = unsafe {
686
            ffi::gst_sdp_message_set_uri(self.to_glib_none_mut().0, uri.to_glib_none().0)
687 688
        };
        match result {
689
            ffi::GST_SDP_OK => Ok(()),
690 691 692 693
            _ => Err(()),
        }
    }

694
    pub fn set_version(&mut self, version: &str) -> Result<(), ()> {
695
        let result = unsafe {
696
            ffi::gst_sdp_message_set_version(self.to_glib_none_mut().0, version.to_glib_none().0)
697 698
        };
        match result {
699
            ffi::GST_SDP_OK => Ok(()),
700 701 702 703 704
            _ => Err(()),
        }
    }

    pub fn times_len(&self) -> u32 {
705
        unsafe { ffi::gst_sdp_message_times_len(self.to_glib_none().0) }
706 707 708
    }

    pub fn zones_len(&self) -> u32 {
709
        unsafe { ffi::gst_sdp_message_zones_len(self.to_glib_none().0) }
710 711
    }

712
    pub fn as_uri(&self, scheme: &str) -> Option<String> {
713 714
        assert_initialized_main_thread!();
        unsafe {
715 716
            from_glib_full(ffi::gst_sdp_message_as_uri(
                scheme.to_glib_none().0,
717
                self.to_glib_none().0,
718
            ))
719 720 721
        }
    }

722
    pub fn parse_buffer(data: &[u8]) -> Result<Self, ()> {
723 724 725
        assert_initialized_main_thread!();
        unsafe {
            let size = data.len() as u32;
726 727
            let mut msg = mem::zeroed();
            ffi::gst_sdp_message_new(&mut msg);
728
            let result = ffi::gst_sdp_message_parse_buffer(data.to_glib_none().0, size, msg);
729
            match result {
730
                ffi::GST_SDP_OK => Ok(from_glib_full(msg)),
731 732 733
                _ => {
                    glib_ffi::g_free(msg as *mut _);
                    Err(())
734
                }
735 736 737 738
            }
        }
    }

739
    pub fn parse_uri(uri: &str) -> Result<Self, ()> {
740 741
        assert_initialized_main_thread!();
        unsafe {
742 743
            let mut msg = mem::zeroed();
            ffi::gst_sdp_message_new(&mut msg);
744
            let result = ffi::gst_sdp_message_parse_uri(uri.to_glib_none().0, msg);
745
            match result {
746
                ffi::GST_SDP_OK => Ok(from_glib_full(msg)),
747 748 749
                _ => {
                    glib_ffi::g_free(msg as *mut _);
                    Err(())
750
                }
751 752 753
            }
        }
    }
Sebastian Dröge's avatar
Sebastian Dröge committed
754
}
755

756 757 758 759 760 761
impl Default for SDPMessage {
    fn default() -> Self {
        Self::new()
    }
}

762
unsafe impl Send for SDPMessage {}