tests: Add integration tests for full tag parsing
This commit is contained in:
parent
e50ee7c139
commit
4d829768a1
|
@ -105,8 +105,8 @@ impl<'a> Value<'a> {
|
||||||
/// otherwise identical.
|
/// otherwise identical.
|
||||||
#[derive(PartialEq, Debug)]
|
#[derive(PartialEq, Debug)]
|
||||||
pub struct Variable<'a> {
|
pub struct Variable<'a> {
|
||||||
name: &'a [u8],
|
pub name: &'a [u8],
|
||||||
data: Value<'a>,
|
pub data: Value<'a>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> Variable<'a> {
|
impl<'a> Variable<'a> {
|
||||||
|
@ -119,7 +119,7 @@ impl<'a> Variable<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(PartialEq, Debug)]
|
#[derive(PartialEq, Debug)]
|
||||||
pub struct ScriptData<'a>(Vec<Variable<'a>>);
|
pub struct ScriptData<'a>(pub Vec<Variable<'a>>);
|
||||||
|
|
||||||
impl<'a> ScriptData<'a> {
|
impl<'a> ScriptData<'a> {
|
||||||
/// Parse a script data structure.
|
/// Parse a script data structure.
|
||||||
|
|
|
@ -111,11 +111,11 @@ pub enum AudioDataType<'a> {
|
||||||
|
|
||||||
#[derive(PartialEq, Eq, Debug)]
|
#[derive(PartialEq, Eq, Debug)]
|
||||||
pub struct AudioData<'a> {
|
pub struct AudioData<'a> {
|
||||||
format: SoundFormat,
|
pub format: SoundFormat,
|
||||||
rate: SoundRate,
|
pub rate: SoundRate,
|
||||||
size: SoundSize,
|
pub size: SoundSize,
|
||||||
sound_type: SoundType,
|
pub sound_type: SoundType,
|
||||||
data: AudioDataType<'a>,
|
pub data: AudioDataType<'a>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> AudioData<'a> {
|
impl<'a> AudioData<'a> {
|
||||||
|
|
|
@ -4,12 +4,14 @@ use crate::sound::AudioData;
|
||||||
use crate::video::VideoData;
|
use crate::video::VideoData;
|
||||||
|
|
||||||
#[repr(u8)]
|
#[repr(u8)]
|
||||||
|
#[derive(PartialEq, Debug)]
|
||||||
pub enum TagData<'a> {
|
pub enum TagData<'a> {
|
||||||
Audio(AudioData<'a>) = 8,
|
Audio(AudioData<'a>) = 8,
|
||||||
Video(VideoData<'a>) = 9,
|
Video(VideoData<'a>) = 9,
|
||||||
Script(ScriptData<'a>) = 18,
|
Script(ScriptData<'a>) = 18,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(PartialEq, Debug)]
|
||||||
pub struct Tag<'a> {
|
pub struct Tag<'a> {
|
||||||
timestamp: i32,
|
timestamp: i32,
|
||||||
stream_id: u32, //24 bits max
|
stream_id: u32, //24 bits max
|
||||||
|
@ -50,3 +52,85 @@ impl<'a> Tag<'a> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use crate::reader::FlvReader;
|
||||||
|
use crate::script::{ScriptData, Value, Variable};
|
||||||
|
use crate::sound::{AudioData, AudioDataType, SoundFormat, SoundRate, SoundSize, SoundType};
|
||||||
|
use crate::tag::{Tag, TagData};
|
||||||
|
use crate::video::{CodecId, FrameType, VideoData, VideoPacket};
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn read_tag_sounddata() {
|
||||||
|
let data = [
|
||||||
|
0x08, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x50, 0x00, 0xFB, 0x12, 0x34,
|
||||||
|
0x56, 0x78,
|
||||||
|
];
|
||||||
|
let mut reader = FlvReader::from_source(&data);
|
||||||
|
|
||||||
|
assert_eq!(
|
||||||
|
Tag::parse(&mut reader),
|
||||||
|
Some(Tag {
|
||||||
|
timestamp: 0,
|
||||||
|
stream_id: 0x5000,
|
||||||
|
data: TagData::Audio(AudioData {
|
||||||
|
format: SoundFormat::Speex,
|
||||||
|
rate: SoundRate::R44_000,
|
||||||
|
size: SoundSize::Bits16,
|
||||||
|
sound_type: SoundType::Stereo,
|
||||||
|
data: AudioDataType::Raw(&[0x12, 0x34, 0x56, 0x78])
|
||||||
|
})
|
||||||
|
})
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn read_tag_videodata() {
|
||||||
|
let data = [
|
||||||
|
0x09, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x50, 0x00, 0x21, 0x12, 0x34,
|
||||||
|
0x56, 0x78,
|
||||||
|
];
|
||||||
|
let mut reader = FlvReader::from_source(&data);
|
||||||
|
|
||||||
|
assert_eq!(
|
||||||
|
Tag::parse(&mut reader),
|
||||||
|
Some(Tag {
|
||||||
|
timestamp: 0,
|
||||||
|
stream_id: 0x5000,
|
||||||
|
data: TagData::Video(VideoData {
|
||||||
|
frame_type: FrameType::Keyframe,
|
||||||
|
codec_id: CodecId::SorensonH263,
|
||||||
|
data: VideoPacket::Data(&[0x12, 0x34, 0x56, 0x78])
|
||||||
|
})
|
||||||
|
})
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn read_tag_scriptdata() {
|
||||||
|
let data = [
|
||||||
|
0x12, 0x00, 0x00, 0x0E, 0x00, 0x00, 0x00, 0x00, 0x00, 0x50, 0x00, 0x00, 0x03, 0x01,
|
||||||
|
0x02, 0x03, 0x06, 0x00, 0x03, 0x01, 0x02, 0x03, 0x05, 0x00, 0x00, 0x09,
|
||||||
|
];
|
||||||
|
let mut reader = FlvReader::from_source(&data);
|
||||||
|
|
||||||
|
assert_eq!(
|
||||||
|
Tag::parse(&mut reader),
|
||||||
|
Some(Tag {
|
||||||
|
timestamp: 0,
|
||||||
|
stream_id: 0x5000,
|
||||||
|
data: TagData::Script(ScriptData(vec![
|
||||||
|
Variable {
|
||||||
|
name: &[0x01, 0x02, 0x03],
|
||||||
|
data: Value::Undefined
|
||||||
|
},
|
||||||
|
Variable {
|
||||||
|
name: &[0x01, 0x02, 0x03],
|
||||||
|
data: Value::Null
|
||||||
|
}
|
||||||
|
]))
|
||||||
|
})
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -86,9 +86,9 @@ pub enum VideoPacket<'a> {
|
||||||
|
|
||||||
#[derive(PartialEq, Eq, Debug)]
|
#[derive(PartialEq, Eq, Debug)]
|
||||||
pub struct VideoData<'a> {
|
pub struct VideoData<'a> {
|
||||||
frame_type: FrameType,
|
pub frame_type: FrameType,
|
||||||
codec_id: CodecId,
|
pub codec_id: CodecId,
|
||||||
data: VideoPacket<'a>,
|
pub data: VideoPacket<'a>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> VideoData<'a> {
|
impl<'a> VideoData<'a> {
|
||||||
|
|
Loading…
Reference in New Issue