Giter VIP home page Giter VIP logo

webrtc-sdp's Introduction

webrtc-sdp

Crates.io Build Status Codecov coverage status License: MPL 2.0 dependency status

A SDP parser written in Rust specifically aimed to handle WebRTC SDP offers and answers.

Dependecies

  • Rust >= 1.60.0
  • log module
  • serde module
  • serde-derive module

Cargo installs the missing modules automatically when building webrtc-sdp for the first time.

The webrtc-sdp API

The main function is:

fn parse_sdp(sdp: &str, fail_on_warning: bool) -> Result<SdpSession, SdpParserError>

The sdp parameter is the string which will get parsed. The fail_on_warning parameter determines how to treat warnings encountered during parsing. Any problems encountered during are stored until the whole string has been parsed. Any problem during parsing falls into two catgeories:

  • Fatal error preventing further parsing or processing of the SDP
  • Warning which don't block further processing of the SDP

Warnings will be for example unknown parameters in attributes. Setting fail_on_warning to true makes most sense during development, when you want to be aware of all potential problems. In production fail_on_warning is expected to be false.

parse_sdp() returns either an SdpSession struct (code) which contains all the parsed information. Or in case a fatal error was encountered (or if fail_on_warning was set to true and any warnings were encountered) an SdpParserError (code) will be returned as a Result.

Examples

The file parser in the webrtc-sdp package gives you an easy example of how to invoke the webrtc-sdp parser.

Contributing

As the Travis CI runs are checking for code formating and clippy warnings please run the following commands locally, before submitting a Pull Request.

If you haven't clippy and Rust format installed already you add them like this:

rustup component add rustfmt-preview
rustup component add clippy

Check with clippy for warnings in the code:

cargo clippy

And format all of the code according to Rust code style convention:

cargo fmt --all

Fuzzing

Install cargo-fuzz like this:

cargo install cargo-fuzz

With rust nightly you can start fuzzing like this:

cargo fuzz run fuzz_target_parse_sdp

License

Licensed under MPL-2.0

webrtc-sdp's People

Contributors

dminor avatar docfaraday avatar eijebong avatar fuzzy-coats avatar ilyabrin avatar johni0702 avatar jwillbold avatar komi1230 avatar mnwa avatar na-g avatar nils-ohlmeier avatar se2dev avatar xaeroxe avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

webrtc-sdp's Issues

Parser error while trying to parse simple INVITE sdp.

I'm trying to parse simple INVITE sdp from client, but I got unsupported protocol, here is the sdp string:

let sdp_str = "v=0\r\n
        o=- 4232193541 678199583 IN IP4 192.168.5.33\r\n
        s=-\r\n
        c=IN IP4 192.168.5.33\r\n
        t=0 0\r\n
        m=audio 42498 RTP/AVP 96 0 8 101\r\n
        a=rtpmap:96 opus/48000/2\r\n
        a=fmtp:96 stereo=1;sprop-stereo=1;maxaveragebitrate=28000\r\n
        a=rtpmap:0 PCMU/8000\r\n
        a=rtpmap:8 PCMA/8000\r\n
        a=rtpmap:101 telephone-event/8000\r\n
        a=fmtp:101 0-15\r\n
        a=sendrecv\r\n
        a=label:1\r\n
        a=rtcp-rsize\r\n
        a=ssrc:1526903191 cname:sip:[email protected]:8080\r\n
        a=ptime:20\r\n";

And the error is:

error occured: Unsupported { error: Unsupported("unsupported protocol value: RTP/AVP"),
line: "m=audio 42498 RTP/AVP 96 0 8 101", line_number: 10 }

Makes changes to SdpBandwidthType and SdpBandwidth

The Unknown value in SdpBandwidthType should carry a String if SdpBandwidthType it is only ever used in SdpBandwidth with the unknown_type option set to the corresponding String. Then unknown_type in SdpBandwidth can be eliminated.

Alternatively, we can simplify down to one struct. Eg:

pub enum SdpBandwidth {
    As(u64),
    Ct(u64),
    Tias(u64),
    Unknown(u64, String),
}

or

pub enum SdpBandwidth {
    As {bandwidth: u64},
    Ct {bandwidth: u64},
    Tias {bandwidth: u64},
    Unknown {bandwidth: u64, bandwidth_type: String},
}

Clippy doesn't break the build

'cargo clippy' always returns 0 even if it finds problems. But travis continues as long as the return code is zero.

One option might be to use 'tee' to get the clippy output into a file and then grep through that file after the clippy run.

Support port count for media lines

A media line might have m=<media> <port>/<number of ports> <proto> <fmt> .... Currently we cannot parse the <number of ports> portion.

How to transition from Error::cause() to Error::source()

Apparently https://doc.rust-lang.org/std/error/trait.Error.html#method.cause has been deprecated in Rust 1.33.0. This results in compiler warnings for Beta right now, but soon on on Release as well.

We are suppose to replace the .cause() calls with .source() calls, but since Error::source() only got added in Rust version 1.30.0 https://doc.rust-lang.org/std/error/trait.Error.html#method.source that would mean we would have to bump the minimum Rust version to 1.30.0 only to support that transition. That looks like a pretty high price to me.

It would be nice to stay backward compatible, but still be able to pay attention to compiler warnings as errors.

Parse into Fmtp more

It looks like sipcc does some format specific parsing of the Fmtp attribute. We probably want to do as much parsing in rust as possible, which means parsing Fmtp attributes in rsdparsa.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.