Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changes in preparation to gstreamer integration #8

Merged
merged 6 commits into from
Jul 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
FROM mcr.microsoft.com/devcontainers/rust:0-1-bullseye
FROM mcr.microsoft.com/devcontainers/rust:latest

RUN apt-get update && \
apt-get install -y cmake llvm-dev libclang-dev clang && \
apt-get clean

RUN git clone --depth 1 -b v2.0.0 https://github.com/fraunhoferhhi/vvdec.git && \
RUN git clone --depth 1 -b v2.1.0 https://github.com/fraunhoferhhi/vvdec.git && \
cd vvdec && \
make install-release-shared install-vvdecapp=1 install-prefix=/usr && \
rm -rf vvdec
24 changes: 22 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,12 @@ impl Decoder {

pub fn decode(
&mut self,
data: &[u8],
data: impl AsRef<[u8]>,
cts: Option<u64>,
dts: Option<u64>,
is_random_access_point: bool,
) -> Result<Option<Frame>, Error> {
let data = data.as_ref();
let mut au = vvdecAccessUnit {
payload: data.as_ptr() as *mut u8,
payloadSize: data.len() as i32,
Expand Down Expand Up @@ -94,6 +95,9 @@ impl Decoder {
}
}

unsafe impl Sync for Decoder {}
unsafe impl Send for Decoder {}

pub struct Params {
params: vvdecParams,
}
Expand Down Expand Up @@ -249,6 +253,9 @@ impl Display for Frame {
}
}

unsafe impl Send for Frame {}
unsafe impl Sync for Frame {}

#[derive(Debug)]
pub struct InnerFrame {
decoder: Decoder,
Expand Down Expand Up @@ -349,7 +356,10 @@ impl Deref for Plane {
}
}

#[derive(Debug)]
unsafe impl Send for Plane {}
unsafe impl Sync for Plane {}

#[derive(Debug, Clone, Copy)]
pub enum PlaneComponent {
Y,
U,
Expand All @@ -367,6 +377,16 @@ impl PlaneComponent {
}
}

impl From<PlaneComponent> for usize {
fn from(value: PlaneComponent) -> Self {
match value {
PlaneComponent::Y => 0,
PlaneComponent::U => 1,
PlaneComponent::V => 2,
}
}
}

#[derive(Debug)]
pub struct PictureAttributes {
pub nal_type: NalType,
Expand Down
72 changes: 65 additions & 7 deletions tests/basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,7 @@ fn basic() -> Result<(), Error> {
Ok(())
}

#[test]
fn split_data() -> Result<(), Error> {
let mut decoder = Decoder::new().unwrap();

fn split_data(data: &[u8]) -> Vec<&[u8]> {
const ANNEX_B_START_CODE: &[u8] = &[0, 0, 0, 1];
let mut indices: Vec<_> = DATA
.windows(4)
Expand All @@ -52,9 +49,19 @@ fn split_data() -> Result<(), Error> {
.map(|(i, _)| i)
.collect();
indices.push(DATA.len());
for pair in indices.windows(2) {
let sub_slice = &DATA[pair[0]..pair[1]];
let _ = decoder.decode(sub_slice, Some(0), Some(0), false);

indices
.windows(2)
.map(|pair| &data[pair[0]..pair[1]])
.collect()
}

#[test]
fn test_split_data() -> Result<(), Error> {
let mut decoder = Decoder::new().unwrap();

for slice in split_data(DATA) {
let _ = decoder.decode(slice, Some(0), Some(0), false);
}

let frame1 = decoder.flush()?;
Expand All @@ -77,3 +84,54 @@ fn split_data() -> Result<(), Error> {

Ok(())
}

#[test]
fn test_decode_after_flush() -> Result<(), Error> {
let mut decoder = Decoder::new().unwrap();

let mut slices = split_data(DATA).into_iter();
let sps = slices.next().unwrap();
let pps = slices.next().unwrap();
let frame1 = slices.next().unwrap();
let frame2 = slices.next().unwrap();
let frame3 = slices.next().unwrap();

let _ = decoder.decode(sps, None, None, false);
let _ = decoder.decode(pps, None, None, false);
let _ = decoder.decode(frame1, None, None, false);
let _ = decoder.decode(frame2, None, None, false);

assert!(decoder.flush().is_ok());
assert!(decoder.flush().is_ok());
assert_eq!(decoder.flush().unwrap_err(), Error::Eof);

let _ = decoder.decode(sps, None, None, false);
let _ = decoder.decode(pps, None, None, false);
let _ = decoder.decode(frame1, None, None, false);
let _ = decoder.decode(frame2, None, None, false);
let _ = decoder.decode(frame3, None, None, false);
assert!(decoder.flush().is_ok());
assert!(decoder.flush().is_ok());
assert!(decoder.flush().is_ok());
assert_eq!(decoder.flush().unwrap_err(), Error::Eof);

Ok(())
}

#[test]
fn test_change_resolution() -> Result<(), Error> {
let mut decoder = Decoder::new().unwrap();

let _ = decoder.decode(DATA, None, None, false);
let first_frame = decoder.flush().unwrap();
assert_eq!(first_frame.width(), 320);
assert_eq!(first_frame.height(), 240);

const SECOND_DATA: &[u8] = include_bytes!("../tests/short2.vvc");
let _ = decoder.decode(SECOND_DATA, None, None, false);
let first_frame = decoder.flush().unwrap();
assert_eq!(first_frame.width(), 160);
assert_eq!(first_frame.height(), 120);

Ok(())
}
Binary file added tests/short2.vvc
Binary file not shown.
2 changes: 1 addition & 1 deletion vvdec-sys/build.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::env;
use std::path::PathBuf;

const VVDEC_VERSION: &str = "2.0.0";
const VVDEC_VERSION: &str = "2.1.0";

mod build {
use super::*;
Expand Down