video: Add software video crate, moved VideoDecoder to it

This commit is contained in:
= 2022-08-26 00:30:07 +02:00 committed by Mike Welsh
parent 91ae384682
commit 7c839ef8ae
10 changed files with 63 additions and 34 deletions

11
Cargo.lock generated
View File

@ -3082,6 +3082,7 @@ dependencies = [
"ruffle_macros",
"ruffle_render",
"ruffle_video",
"ruffle_video_software",
"ruffle_wstr",
"serde",
"serde_json",
@ -3228,6 +3229,16 @@ dependencies = [
"thiserror",
]
[[package]]
name = "ruffle_video_software"
version = "0.1.0"
dependencies = [
"generational-arena",
"ruffle_video",
"swf",
"thiserror",
]
[[package]]
name = "ruffle_web"
version = "0.1.0"

View File

@ -17,6 +17,7 @@ members = [
"render/webgl",
"video",
"video/software",
"tests",
"tests/input-format",

View File

@ -17,6 +17,7 @@ log = "0.4"
minimp3 = { version = "0.5.1", optional = true }
ruffle_render = { path = "../render" }
ruffle_video = { path = "../video" }
ruffle_video_software = { path = "../video/software" }
ruffle_macros = { path = "macros" }
ruffle_wstr = { path = "../wstr" }
swf = { path = "../swf" }

View File

@ -1,9 +1,9 @@
use crate::backend::video::software::VideoDecoder;
use h263_rs::parser::H263Reader;
use h263_rs::{DecoderOption, H263State, PictureTypeCode};
use h263_rs_yuv::bt601::yuv420_to_rgba;
use ruffle_video::error::Error;
use ruffle_video::frame::{DecodedFrame, EncodedFrame, FrameDependency};
use ruffle_video_software::decoder::VideoDecoder;
#[derive(thiserror::Error, Debug)]
pub enum H263Error {

View File

@ -1,8 +1,8 @@
// This module is heavily based on flashsv.rs from NihAV,
// written by Kostya Shishkov, with permission.
use crate::backend::video::software::VideoDecoder;
use ruffle_video::error::Error;
use ruffle_video_software::decoder::VideoDecoder;
use flate2::Decompress;
use ruffle_video::frame::{DecodedFrame, EncodedFrame, FrameDependency};

View File

@ -1,5 +1,5 @@
use crate::backend::video::software::VideoDecoder;
use ruffle_video::error::Error;
use ruffle_video_software::decoder::VideoDecoder;
use h263_rs_yuv::bt601::yuv420_to_rgba;

View File

@ -5,8 +5,9 @@ use ruffle_render::backend::RenderBackend;
use ruffle_render::bitmap::{Bitmap, BitmapFormat, BitmapHandle, BitmapInfo};
use ruffle_video::backend::VideoBackend;
use ruffle_video::error::Error;
use ruffle_video::frame::{DecodedFrame, EncodedFrame, FrameDependency};
use ruffle_video::frame::{EncodedFrame, FrameDependency};
use ruffle_video::VideoStreamHandle;
use ruffle_video_software::decoder::VideoDecoder;
use swf::{VideoCodec, VideoDeblocking};
pub mod decoders;
@ -125,33 +126,3 @@ impl VideoStream {
}
}
}
/// Trait for video decoders.
/// This should be implemented for each video codec.
trait VideoDecoder {
/// Preload a frame.
///
/// No decoding is intended to happen at this point in time. Instead, the
/// video data should be inspected to determine inter-frame dependencies
/// between this and any previous frames in the stream.
///
/// Frames should be preloaded in the order that they are recieved.
///
/// Any dependencies listed here are inherent to the video bitstream. The
/// containing video stream is also permitted to introduce additional
/// interframe dependencies.
fn preload_frame(&mut self, encoded_frame: EncodedFrame<'_>) -> Result<FrameDependency, Error>;
/// Decode a frame of a given video stream.
///
/// This function is provided the external index of the frame, the codec
/// used to decode the data, and what codec to decode it with. The codec
/// provided here must match the one used to register the video stream.
///
/// Frames may be decoded in any order that does not violate the frame
/// dependencies declared by the output of `preload_video_stream_frame`.
///
/// The decoded frame should be returned. An `Error` can be returned if
/// a drawable bitmap can not be produced.
fn decode_frame(&mut self, encoded_frame: EncodedFrame<'_>) -> Result<DecodedFrame, Error>;
}

12
video/software/Cargo.toml Normal file
View File

@ -0,0 +1,12 @@
[package]
name = "ruffle_video_software"
version = "0.1.0"
authors = ["Ruffle LLC <ruffle@ruffle.rs>"]
edition = "2021"
license = "MIT OR Apache-2.0"
[dependencies]
ruffle_video = { path = ".." }
swf = { path = "../../swf" }
generational-arena = "0.2.8"
thiserror = "1.0"

View File

@ -0,0 +1,32 @@
use ruffle_video::error::Error;
use ruffle_video::frame::{DecodedFrame, EncodedFrame, FrameDependency};
/// Trait for video decoders.
/// This should be implemented for each video codec.
pub trait VideoDecoder {
/// Preload a frame.
///
/// No decoding is intended to happen at this point in time. Instead, the
/// video data should be inspected to determine inter-frame dependencies
/// between this and any previous frames in the stream.
///
/// Frames should be preloaded in the order that they are recieved.
///
/// Any dependencies listed here are inherent to the video bitstream. The
/// containing video stream is also permitted to introduce additional
/// interframe dependencies.
fn preload_frame(&mut self, encoded_frame: EncodedFrame<'_>) -> Result<FrameDependency, Error>;
/// Decode a frame of a given video stream.
///
/// This function is provided the external index of the frame, the codec
/// used to decode the data, and what codec to decode it with. The codec
/// provided here must match the one used to register the video stream.
///
/// Frames may be decoded in any order that does not violate the frame
/// dependencies declared by the output of `preload_video_stream_frame`.
///
/// The decoded frame should be returned. An `Error` can be returned if
/// a drawable bitmap can not be produced.
fn decode_frame(&mut self, encoded_frame: EncodedFrame<'_>) -> Result<DecodedFrame, Error>;
}

View File

@ -0,0 +1 @@
pub mod decoder;