aboutsummaryrefslogtreecommitdiffstats
path: root/nihav-duck/src
diff options
context:
space:
mode:
authorKostya Shishkov <kostya.shishkov@gmail.com>2021-11-02 18:20:06 +0100
committerKostya Shishkov <kostya.shishkov@gmail.com>2021-11-02 18:20:06 +0100
commit92d9fb6993d2d3f6f7a016ee6796a98e6e989f21 (patch)
treefc62601617c3ec10e18c5a39940225abe0d2da4d /nihav-duck/src
parentbc23de6bedc2e151caea241b073a65d30f62c134 (diff)
downloadnihav-92d9fb6993d2d3f6f7a016ee6796a98e6e989f21.tar.gz
Flash support
Diffstat (limited to 'nihav-duck/src')
-rw-r--r--nihav-duck/src/codecs/mod.rs4
-rw-r--r--nihav-duck/src/codecs/vp56.rs2
-rw-r--r--nihav-duck/src/codecs/vp6.rs26
-rw-r--r--nihav-duck/src/codecs/vp6enc/mod.rs18
4 files changed, 37 insertions, 13 deletions
diff --git a/nihav-duck/src/codecs/mod.rs b/nihav-duck/src/codecs/mod.rs
index 38c25d0..6086150 100644
--- a/nihav-duck/src/codecs/mod.rs
+++ b/nihav-duck/src/codecs/mod.rs
@@ -99,6 +99,8 @@ const DUCK_CODECS: &[DecoderInfo] = &[
#[cfg(feature="decoder_vp6")]
DecoderInfo { name: "vp6", get_decoder: vp6::get_decoder_vp6 },
#[cfg(feature="decoder_vp6")]
+ DecoderInfo { name: "vp6f", get_decoder: vp6::get_decoder_vp6f },
+#[cfg(feature="decoder_vp6")]
DecoderInfo { name: "vp6a", get_decoder: vp6::get_decoder_vp6_alpha },
#[cfg(feature="decoder_vp7")]
DecoderInfo { name: "vp7", get_decoder: vp7::get_decoder },
@@ -129,6 +131,8 @@ mod vp6enc;
const DUCK_ENCODERS: &[EncoderInfo] = &[
#[cfg(feature="encoder_vp6")]
EncoderInfo { name: "vp6", get_encoder: vp6enc::get_encoder },
+#[cfg(feature="encoder_vp6")]
+ EncoderInfo { name: "vp6f", get_encoder: vp6enc::get_encoder_flv },
];
/// Registers all available encoders provided by this crate.
diff --git a/nihav-duck/src/codecs/vp56.rs b/nihav-duck/src/codecs/vp56.rs
index 807756a..01e8171 100644
--- a/nihav-duck/src/codecs/vp56.rs
+++ b/nihav-duck/src/codecs/vp56.rs
@@ -486,7 +486,7 @@ impl VP56Decoder {
let hdr = br.parse_header(&mut bc)?;
validate!((hdr.offset as usize) < aoffset); //XXX: take alpha 3 byte offset into account?
- if hdr.mb_w != 0 {
+ if hdr.mb_w != 0 && (usize::from(hdr.mb_w) != self.mb_w || usize::from(hdr.mb_h) != self.mb_h) {
self.set_dimensions((hdr.mb_w as usize) * 16, (hdr.mb_h as usize) * 16);
}
let fmt = if !self.has_alpha {
diff --git a/nihav-duck/src/codecs/vp6.rs b/nihav-duck/src/codecs/vp6.rs
index 15bd832..6d97189 100644
--- a/nihav-duck/src/codecs/vp6.rs
+++ b/nihav-duck/src/codecs/vp6.rs
@@ -478,15 +478,17 @@ struct VP6Decoder {
info: NACodecInfoRef,
br: VP6BR,
has_alpha: bool,
+ flipped: bool,
}
impl VP6Decoder {
- fn new(has_alpha: bool) -> Self {
+ fn new(flipped: bool, has_alpha: bool) -> Self {
Self {
- dec: VP56Decoder::new(6, has_alpha, true),
+ dec: VP56Decoder::new(6, has_alpha, flipped),
info: NACodecInfoRef::default(),
br: VP6BR::new(),
has_alpha,
+ flipped,
}
}
}
@@ -499,7 +501,15 @@ impl NADecoder for VP6Decoder {
} else {
VP_YUVA420_FORMAT
};
- let myvinfo = NAVideoInfo::new(vinfo.get_width(), vinfo.get_height(), false, fmt);
+ let mut width = vinfo.get_width();
+ let mut height = vinfo.get_height();
+ if let (false, Some(edta)) = (self.flipped, info.get_extradata()) {
+ if (width & 0xF) == 0 && (height & 0xF) == 0 {
+ width -= usize::from(edta[0] >> 4);
+ height -= usize::from(edta[0] & 0xF);
+ }
+ }
+ let myvinfo = NAVideoInfo::new(width, height, self.flipped, fmt);
let myinfo = NACodecTypeInfo::Video(myvinfo);
self.info = NACodecInfo::new_ref(info.get_name(), myinfo, info.get_extradata()).into_ref();
self.dec.init(supp, myvinfo)?;
@@ -530,11 +540,15 @@ impl NAOptionHandler for VP6Decoder {
}
pub fn get_decoder_vp6() -> Box<dyn NADecoder + Send> {
- Box::new(VP6Decoder::new(false))
+ Box::new(VP6Decoder::new(true, false))
+}
+
+pub fn get_decoder_vp6f() -> Box<dyn NADecoder + Send> {
+ Box::new(VP6Decoder::new(false, false))
}
pub fn get_decoder_vp6_alpha() -> Box<dyn NADecoder + Send> {
- Box::new(VP6Decoder::new(true))
+ Box::new(VP6Decoder::new(false, true))
}
#[cfg(test)]
@@ -605,6 +619,6 @@ mod test {
[0xd3801a96, 0x1b5384ff, 0x422b228c, 0x9c4582c4],
[0x8ddb0dfe, 0x302eb1ed, 0x10e64e22, 0x5a5a62b9],
[0x79338328, 0x06113781, 0x8b116d18, 0xde56707e],
- [0x671fa1b3, 0x0b3e41e9, 0xeb3a494c, 0xcdd24b1b]]));
+ [0xdb58433b, 0x1de4ce67, 0x15fcbcee, 0x1df9de61]]));
}
}
diff --git a/nihav-duck/src/codecs/vp6enc/mod.rs b/nihav-duck/src/codecs/vp6enc/mod.rs
index 7959ae0..9388fd2 100644
--- a/nihav-duck/src/codecs/vp6enc/mod.rs
+++ b/nihav-duck/src/codecs/vp6enc/mod.rs
@@ -172,6 +172,7 @@ struct VP6Encoder {
fenc: FrameEncoder,
ratectl: RateControl,
+ flipped: bool,
huffman: bool,
version: u8,
@@ -191,7 +192,7 @@ struct VP6Encoder {
}
impl VP6Encoder {
- fn new() -> Self {
+ fn new(flipped: bool) -> Self {
let vt = alloc_video_buffer(NAVideoInfo::new(24, 24, false, VP_YUVA420_FORMAT), 4).unwrap();
let mc_buf = vt.get_vbuf().unwrap();
Self {
@@ -207,6 +208,7 @@ impl VP6Encoder {
ratectl: RateControl::new(),
mc_buf,
+ flipped,
huffman: false,
version: VERSION_VP60,
@@ -633,12 +635,12 @@ impl NAEncoder for VP6Encoder {
match encinfo.format {
NACodecTypeInfo::None => {
let mut ofmt = EncodeParameters::default();
- ofmt.format = NACodecTypeInfo::Video(NAVideoInfo::new(0, 0, true, YUV420_FORMAT));
+ ofmt.format = NACodecTypeInfo::Video(NAVideoInfo::new(0, 0, self.flipped, YUV420_FORMAT));
Ok(ofmt)
},
NACodecTypeInfo::Audio(_) => Err(EncoderError::FormatError),
NACodecTypeInfo::Video(vinfo) => {
- let outinfo = NAVideoInfo::new((vinfo.width + 3) & !3, (vinfo.height + 3) & !3, true, YUV420_FORMAT);
+ let outinfo = NAVideoInfo::new((vinfo.width + 3) & !3, (vinfo.height + 3) & !3, self.flipped, YUV420_FORMAT);
let mut ofmt = *encinfo;
ofmt.format = NACodecTypeInfo::Video(outinfo);
Ok(ofmt)
@@ -660,8 +662,8 @@ impl NAEncoder for VP6Encoder {
return Err(EncoderError::FormatError);
}
- let out_info = NAVideoInfo::new(vinfo.width, vinfo.height, true, vinfo.format);
- let info = NACodecInfo::new("vp6", NACodecTypeInfo::Video(out_info), None);
+ let out_info = NAVideoInfo::new(vinfo.width, vinfo.height, self.flipped, vinfo.format);
+ let info = NACodecInfo::new(if self.flipped { "vp6" } else { "vp6f" }, NACodecTypeInfo::Video(out_info), None);
let mut stream = NAStream::new(StreamType::Video, stream_id, info, encinfo.tb_num, encinfo.tb_den, 0);
stream.set_num(stream_id as usize);
let stream = stream.into_ref();
@@ -854,7 +856,11 @@ impl NAOptionHandler for VP6Encoder {
}
pub fn get_encoder() -> Box<dyn NAEncoder + Send> {
- Box::new(VP6Encoder::new())
+ Box::new(VP6Encoder::new(true))
+}
+
+pub fn get_encoder_flv() -> Box<dyn NAEncoder + Send> {
+ Box::new(VP6Encoder::new(false))
}
#[cfg(test)]