codec/encoder: set the medium if it's unknown

This commit is contained in:
meh 2015-10-01 23:34:59 +02:00
parent 4cc4ba3579
commit e7cd9fd94f

View File

@ -8,30 +8,63 @@ use super::{video, audio, subtitle};
pub struct Encoder(pub Context); pub struct Encoder(pub Context);
impl Encoder { impl Encoder {
pub fn video(self) -> Result<video::Video, Error> { pub fn video(mut self) -> Result<video::Video, Error> {
if self.medium() == media::Type::Video { match self.medium() {
Ok(video::Video(self)) media::Type::Unknown => {
} unsafe {
else { (*self.as_mut_ptr()).codec_type = media::Type::Video.into();
Err(Error::InvalidData) }
Ok(video::Video(self))
}
media::Type::Video => {
Ok(video::Video(self))
}
_ => {
Err(Error::InvalidData)
}
} }
} }
pub fn audio(self) -> Result<audio::Audio, Error> { pub fn audio(mut self) -> Result<audio::Audio, Error> {
if self.medium() == media::Type::Audio { match self.medium() {
Ok(audio::Audio(self)) media::Type::Unknown => {
} unsafe {
else { (*self.as_mut_ptr()).codec_type = media::Type::Audio.into();
Err(Error::InvalidData) }
Ok(audio::Audio(self))
}
media::Type::Audio => {
Ok(audio::Audio(self))
}
_ => {
Err(Error::InvalidData)
}
} }
} }
pub fn subtitle(self) -> Result<subtitle::Subtitle, Error> { pub fn subtitle(mut self) -> Result<subtitle::Subtitle, Error> {
if self.medium() == media::Type::Subtitle { match self.medium() {
Ok(subtitle::Subtitle(self)) media::Type::Unknown => {
} unsafe {
else { (*self.as_mut_ptr()).codec_type = media::Type::Subtitle.into();
Err(Error::InvalidData) }
Ok(subtitle::Subtitle(self))
}
media::Type::Subtitle => {
Ok(subtitle::Subtitle(self))
}
_ => {
Err(Error::InvalidData)
}
} }
} }