flv: Add new crate for FLV (de)muxing

This commit is contained in:
David Wendt 2023-06-23 20:31:52 -04:00 committed by kmeisthax
parent 8f0a43f9d9
commit 5b93a9e316
7 changed files with 90 additions and 0 deletions

7
Cargo.lock generated
View File

@ -1645,6 +1645,13 @@ dependencies = [
"spin",
]
[[package]]
name = "flv-rs"
version = "0.1.0"
dependencies = [
"bitflags 2.3.2",
]
[[package]]
name = "fnv"
version = "1.0.7"

View File

@ -5,6 +5,7 @@ members = [
"core/build_playerglobal",
"desktop",
"swf",
"flv",
"web",
"web/packages/extension/safari",
"wstr",

9
flv/Cargo.toml Normal file
View File

@ -0,0 +1,9 @@
[package]
name = "flv-rs"
version = "0.1.0"
authors = ["David Wendt <dcrkid@gmail.com>"]
edition = "2021"
license = "MIT OR Apache-2.0"
[dependencies]
bitflags = "2.0.0"

14
flv/src/header.rs Normal file
View File

@ -0,0 +1,14 @@
use bitflags::bitflags;
bitflags! {
pub struct TypeFlags: u8 {
const HAS_AUDIO = 0b1000_0000;
const HAS_VIDEO = 0b0010_0000;
}
}
pub struct Header {
version: u8,
type_flags: TypeFlags,
data_offset: u32,
}

3
flv/src/lib.rs Normal file
View File

@ -0,0 +1,3 @@
mod header;
mod sound;
mod tag;

36
flv/src/sound.rs Normal file
View File

@ -0,0 +1,36 @@
#[repr(u8)]
pub enum SoundFormat {
LinearPCMPlatformEndian = 0,
Adpcm = 1,
MP3 = 2,
LinearPCMLittleEndian = 3,
Nellymoser16kHz = 4,
Nellymoser8kHz = 5,
Nellymoser = 6,
G711ALawPCM = 7,
G711MuLawPCM = 8,
Aac = 10,
Speex = 11,
MP38kHz = 14,
DeviceSpecific = 15,
}
#[repr(u8)]
pub enum SoundRate {
R5_500 = 0,
R11_000 = 1,
R22_000 = 2,
R44_000 = 3,
}
#[repr(u8)]
pub enum SoundSize {
Bits8 = 0,
Bits16 = 1,
}
#[repr(u8)]
pub enum SoundType {
Mono = 0,
Stereo = 1,
}

20
flv/src/tag.rs Normal file
View File

@ -0,0 +1,20 @@
use crate::sound::{SoundFormat, SoundRate, SoundSize, SoundType};
#[repr(u8)]
pub enum TagData<'a> {
Audio {
format: SoundFormat,
rate: SoundRate,
size: SoundSize,
sound_type: SoundType,
data: &'a [u8],
} = 8,
Video = 9,
Script = 18,
}
pub struct Tag<'a> {
timestamp: i32,
stream_id: u32, //24 bits max
data: TagData<'a>,
}