{"id":499,"date":"2017-11-26T19:59:06","date_gmt":"2017-11-26T18:59:06","guid":{"rendered":"https:\/\/coaxion.net\/blog\/?p=499"},"modified":"2017-11-26T21:56:00","modified_gmt":"2017-11-26T20:56:00","slug":"gstreamer-rust-bindings-release-0-9","status":"publish","type":"post","link":"https:\/\/coaxion.net\/blog\/2017\/11\/gstreamer-rust-bindings-release-0-9\/","title":{"rendered":"GStreamer Rust bindings release 0.9"},"content":{"rendered":"<p>About 3 months, a <a href=\"https:\/\/gstreamer.freedesktop.org\/conference\/2017\/\" rel=\"noopener\" target=\"_blank\">GStreamer Conference<\/a> and two bug-fix releases have passed now since the <a href=\"https:\/\/coaxion.net\/blog\/2017\/08\/gstreamer-rust-bindings-release-0-8-0\/\">GStreamer Rust bindings release 0.8.0<\/a>. Today <a href=\"https:\/\/crates.io\/crates\/gstreamer\" rel=\"noopener\" target=\"_blank\">version 0.9.0<\/a> (and 0.9.1 with a small bugfix to export some forgotten types) with a couple of API improvements and lots of additions and cleanups was released. This new version depends <a href=\"http:\/\/gtk-rs.org\/blog\/2017\/11\/26\/new-release.html\" rel=\"noopener\" target=\"_blank\">on the new set of releases of the gtk-rs crates<\/a> (glib\/etc).<\/p>\n<p>The full changelog can be found <a href=\"https:\/\/github.com\/sdroege\/gstreamer-rs\/blob\/80ebc86e94468e292ae39512b13e059e69794530\/gstreamer\/CHANGELOG.md#091---2017-11-26\" rel=\"noopener\" target=\"_blank\">here<\/a>, but below is a short overview of the (in my opinion) most interesting changes.<\/p>\n<h4>Tutorials<\/h4>\n<p>The <a href=\"https:\/\/github.com\/sdroege\/gstreamer-rs\/tree\/master\/tutorials\" rel=\"noopener\" target=\"_blank\">basic tutorials 1 to 8<\/a> were ported from C to Rust by various contributors. The C versions and the corresponding explanatory text can be found <a href=\"https:\/\/gstreamer.freedesktop.org\/documentation\/tutorials\/\" rel=\"noopener\" target=\"_blank\">here<\/a>, and it should be relatively easy to follow the text together with the Rust code.<\/p>\n<p>This should make learning to use <a href=\"https:\/\/gstreamer.freedesktop.org\" rel=\"noopener\" target=\"_blank\">GStreamer<\/a> from Rust much easier, in combination with the <a href=\"https:\/\/github.com\/sdroege\/gstreamer-rs\/tree\/master\/examples\" rel=\"noopener\" target=\"_blank\">few example applications<\/a> that exist in the repository.<\/p>\n<h4>Type-safety Improvements<\/h4>\n<p>Previously querying the current playback position from a pipeline (and various other things analogous) was giving you a plain 64-bit integer, just like in C. However in Rust we can easily do better.<\/p>\n<p>The main problem with just getting an integer was that there are &#8220;special&#8221; values that have the meaning of &#8220;no value known&#8221;, specifically <em>GST_CLOCK_TIME_NONE<\/em> for values in time. In C this often causes bugs by code ignoring this special case and then doing calculations with such a value, resulting in completely wrong numbers. In the Rust bindings these are now expressed as an <em>Option<_><\/em> so that the special case has to be handled separately, and in combination with that for timed values there is a new type called <a href=\"https:\/\/sdroege.github.io\/rustdoc\/gstreamer\/gstreamer\/struct.ClockTime.html\" rel=\"noopener\" target=\"_blank\"><em>ClockTime<\/em><\/a> that is implementing all the arithmetic traits and others so you can still do normal arithmetic operations on the values, while the implementation of those operations takes care of <em>GST_CLOCK_TIME_NONE<\/em>. Also it was previously easy to get a value in bytes and add it to a value in time. Whenever multiple formats are possible, a new type called <a href=\"https:\/\/sdroege.github.io\/rustdoc\/gstreamer\/gstreamer\/enum.FormatValue.html\" rel=\"noopener\" target=\"_blank\"><em>FormatValue<\/em><\/a> is now used that combines the value itself with its format to prevent such mistakes.<\/p>\n<h4>Error Handling<\/h4>\n<p>Various operations in GStreamer can fail with a custom enum type: link pads (<a href=\"https:\/\/sdroege.github.io\/rustdoc\/gstreamer\/gstreamer\/enum.PadLinkReturn.html\" rel=\"noopener\" target=\"_blank\"><em>PadLinkReturn<\/em><\/a>), pushing a buffer (<a href=\"https:\/\/sdroege.github.io\/rustdoc\/gstreamer\/gstreamer\/enum.FlowReturn.html\" rel=\"noopener\" target=\"_blank\"><em>FlowReturn<\/em><\/a>), changing an element&#8217;s state (<a href=\"https:\/\/sdroege.github.io\/rustdoc\/gstreamer\/gstreamer\/enum.StateChangeReturn.html\" rel=\"noopener\" target=\"_blank\"><em>StateChangeReturn<\/em><\/a>). Previously handling this was not as convenient as the usual <em>Result<\/em>-based error handling in Rust. With this release, all these types provide a function <em>into_result()<\/em> that allows to convert into a <em>Result<\/em> that splits the enum into its good and bad cases, e.g. <a href=\"https:\/\/sdroege.github.io\/rustdoc\/gstreamer\/gstreamer\/enum.FlowSuccess.html\" rel=\"noopener\" target=\"_blank\"><em>FlowSuccess<\/em><\/a> and <a href=\"https:\/\/sdroege.github.io\/rustdoc\/gstreamer\/gstreamer\/enum.FlowError.html\" rel=\"noopener\" target=\"_blank\"><em>FlowError<\/em><\/a>. Based on this, the usual Rust error handling is possible, including usage of the ?-operator. Once the <a href=\"https:\/\/doc.rust-lang.org\/nightly\/std\/ops\/trait.Try.html\" rel=\"noopener\" target=\"_blank\">Try trait<\/a> is stable, it will also be possible to directly use the ?-operator on <em>FlowReturn<\/em> and the others before conversion into a <em>Result<\/em>.<\/p>\n<p>All these enums are also marked as <em>#[must_use]<\/em> now, which causes a compiler warning if code is not specifically handling them (which could mean to explicitly ignore them), making it even harder to ignore errors caused by any failures of such operations.<\/p>\n<p>In addition, all the examples and tutorials make use of the above now and many examples were ported to the <a href=\"https:\/\/crates.io\/crates\/failure\" rel=\"noopener\" target=\"_blank\">failure<\/a> crate and implement proper error handling in all situations now, for example the <a href=\"https:\/\/github.com\/sdroege\/gstreamer-rs\/blob\/ea3d08d65a9210b7f422b8719ff4189c4bb0e37a\/examples\/src\/bin\/decodebin.rs\" rel=\"noopener\" target=\"_blank\">decodebin example<\/a>.<\/p>\n<h4>Various New API<\/h4>\n<p>Apart from all of the above, a lot of new API was added. Both for writing GStreamer-based applications, and making that easier, as well as for writing GStreamer plugins in Rust. For the latter, the <a href=\"https:\/\/github.com\/sdroege\/gst-plugin-rs\/\" rel=\"noopener\" target=\"_blank\">gst-plugin-rs<\/a> repository with various crates (and plugins) was ported to the GStreamer bindings and completely rewritten, but more on that in another blog post in the next couple of days once the <a href=\"https:\/\/github.com\/sdroege\/gst-plugin-rs\/tree\/master\/gst-plugin\" rel=\"noopener\" target=\"_blank\">gst-plugin<\/a> crate is released and published on <a href=\"https:\/\/crates.io\" rel=\"noopener\" target=\"_blank\">crates.io<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>About 3 months, a GStreamer Conference and two bug-fix releases have passed now since the GStreamer Rust bindings release 0.8.0. Today version 0.9.0 (and 0.9.1 with a small bugfix to export some forgotten types) with a couple of API improvements and lots of additions and cleanups was released. This new version depends on the new &hellip; <a href=\"https:\/\/coaxion.net\/blog\/2017\/11\/gstreamer-rust-bindings-release-0-9\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">GStreamer Rust bindings release 0.9<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[3,6,5,53],"tags":[],"class_list":["post-499","post","type-post","status-publish","format-standard","hentry","category-free-software","category-gnome","category-gstreamer","category-rust"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/coaxion.net\/blog\/wp-json\/wp\/v2\/posts\/499","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/coaxion.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/coaxion.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/coaxion.net\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/coaxion.net\/blog\/wp-json\/wp\/v2\/comments?post=499"}],"version-history":[{"count":4,"href":"https:\/\/coaxion.net\/blog\/wp-json\/wp\/v2\/posts\/499\/revisions"}],"predecessor-version":[{"id":503,"href":"https:\/\/coaxion.net\/blog\/wp-json\/wp\/v2\/posts\/499\/revisions\/503"}],"wp:attachment":[{"href":"https:\/\/coaxion.net\/blog\/wp-json\/wp\/v2\/media?parent=499"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/coaxion.net\/blog\/wp-json\/wp\/v2\/categories?post=499"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/coaxion.net\/blog\/wp-json\/wp\/v2\/tags?post=499"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}