From 76a175b8e94e201f1035a32fb09fbeb79ba4eae0 Mon Sep 17 00:00:00 2001 From: xd009642 Date: Thu, 22 Apr 2021 11:35:22 +0400 Subject: [PATCH] Add missing open_with implementations Add open_with for `Decoder` and `encoder::Subtitle` --- src/codec/decoder/decoder.rs | 14 ++++++++++++++ src/codec/encoder/subtitle.rs | 14 ++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/src/codec/decoder/decoder.rs b/src/codec/decoder/decoder.rs index 6990ab71..4ae8a820 100644 --- a/src/codec/decoder/decoder.rs +++ b/src/codec/decoder/decoder.rs @@ -31,6 +31,20 @@ impl Decoder { } } + pub fn open_with(mut self, options: Dictionary) -> Result { + unsafe { + let mut opts = options.disown(); + let res = avcodec_open2(self.as_mut_ptr(), ptr::null(), &mut opts); + + Dictionary::own(opts); + + match res { + 0 => Ok(Opened(self)), + e => Err(Error::from(e)), + } + } + } + pub fn open_as_with( mut self, codec: D, diff --git a/src/codec/encoder/subtitle.rs b/src/codec/encoder/subtitle.rs index 0bbb346c..05f5d001 100644 --- a/src/codec/encoder/subtitle.rs +++ b/src/codec/encoder/subtitle.rs @@ -33,6 +33,20 @@ impl Subtitle { } } + pub fn open_with(mut self, options: Dictionary) -> Result { + unsafe { + let mut opts = options.disown(); + let res = avcodec_open2(self.as_mut_ptr(), ptr::null(), &mut opts); + + Dictionary::own(opts); + + match res { + 0 => Ok(Encoder(self)), + e => Err(Error::from(e)), + } + } + } + pub fn open_as_with( mut self, codec: E,