Refractor video magic bytes into BinaryData
This commit is contained in:
3 files changed
+87
-31
No files matched your search
+29
-1
@@ -174,7 +174,35 @@ fn bc_modern_msg<'a, 'b, 'c>(
|
||||
// message).
|
||||
context.in_bin_mode.insert(header.msg_id);
|
||||
|
||||
binary = Some(payload);
|
||||
let magic = &payload.as_slice()[..4];
|
||||
trace!("Magic is: {:x?}", &magic);
|
||||
binary = match magic {
|
||||
MAGIC_VIDEO_INFO => {
|
||||
trace!("Video info magic type");
|
||||
Some(BinaryData::InfoData(payload))
|
||||
},
|
||||
MAGIC_AAC => {
|
||||
trace!("AAC magic type");
|
||||
Some(BinaryData::AudioData(payload))
|
||||
},
|
||||
MAGIC_ADPCM => {
|
||||
trace!("ADPCM magic type");
|
||||
Some(BinaryData::AudioData(payload))
|
||||
},
|
||||
MAGIC_IFRAME => {
|
||||
trace!("IFrame magic type");
|
||||
Some(BinaryData::VideoData(payload))
|
||||
},
|
||||
MAGIC_PFRAME => {
|
||||
trace!("PFrame magic type");
|
||||
Some(BinaryData::VideoData(payload))
|
||||
}
|
||||
_ => {
|
||||
trace!("Unknown magic type"); // When large video is chunked it goes here
|
||||
Some(BinaryData::Unknown(payload))
|
||||
}
|
||||
};
|
||||
|
||||
buf = buf_after;
|
||||
} else {
|
||||
// Seriously, Nom, what even is this
|
||||
|
||||
+49
-1
@@ -22,10 +22,58 @@ pub enum BcBody {
|
||||
ModernMsg(ModernMsg),
|
||||
}
|
||||
|
||||
pub const MAGIC_VIDEO_INFO: &[u8] = &[0x31, 0x30, 0x30, 0x31];
|
||||
pub const MAGIC_AAC: &[u8] = &[0x30, 0x35, 0x77, 0x62];
|
||||
pub const MAGIC_ADPCM: &[u8] = &[0x30, 0x31, 0x77, 0x62];
|
||||
pub const MAGIC_IFRAME: &[u8] = &[0x30, 0x30, 0x64, 0x63];
|
||||
pub const MAGIC_PFRAME: &[u8] = &[0x30, 0x31, 0x64, 0x63];
|
||||
|
||||
#[derive(Debug, PartialEq, Eq)]
|
||||
pub enum BinaryData {
|
||||
VideoData(Vec<u8>),
|
||||
AudioData(Vec<u8>),
|
||||
InfoData(Vec<u8>),
|
||||
Unknown(Vec<u8>),
|
||||
}
|
||||
|
||||
impl std::convert::AsRef<[u8]> for BinaryData {
|
||||
fn as_ref(&self) -> &[u8] {
|
||||
let binary = match self {
|
||||
BinaryData::VideoData(binary) => binary,
|
||||
BinaryData::AudioData(binary) => binary,
|
||||
BinaryData::InfoData(binary) => binary,
|
||||
BinaryData::Unknown(binary) => binary,
|
||||
};
|
||||
binary.as_slice()
|
||||
}
|
||||
}
|
||||
|
||||
impl BinaryData {
|
||||
pub fn len(&self) -> usize {
|
||||
let binary = match self {
|
||||
BinaryData::VideoData(binary) => binary,
|
||||
BinaryData::AudioData(binary) => binary,
|
||||
BinaryData::InfoData(binary) => binary,
|
||||
BinaryData::Unknown(binary) => binary,
|
||||
};
|
||||
binary.len()
|
||||
}
|
||||
|
||||
pub fn as_slice(&self) -> &[u8] {
|
||||
let binary = match self {
|
||||
BinaryData::VideoData(binary) => binary,
|
||||
BinaryData::AudioData(binary) => binary,
|
||||
BinaryData::InfoData(binary) => binary,
|
||||
BinaryData::Unknown(binary) => binary,
|
||||
};
|
||||
binary.as_slice()
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Default, PartialEq, Eq)]
|
||||
pub struct ModernMsg {
|
||||
pub xml: Option<BcXml>,
|
||||
pub binary: Option<Vec<u8>>,
|
||||
pub binary: Option<BinaryData>,
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq, Eq)]
|
||||
|
||||
+9
-29
@@ -269,11 +269,6 @@ impl BcCamera {
|
||||
|
||||
sub_video.send(start_video)?;
|
||||
|
||||
const MAGIC_HEADER: &[u8] = &[0x31, 0x30, 0x30, 0x31];
|
||||
const MAGIC_AAC: &[u8] = &[0x30, 0x35, 0x77, 0x62];
|
||||
const MAGIC_ADPCM: &[u8] = &[0x30, 0x31, 0x77, 0x62];
|
||||
const MAGIC_IFRAME: &[u8] = &[0x30, 0x30, 0x64, 0x63];
|
||||
const MAGIC_PFRAME: &[u8] = &[0x30, 0x31, 0x64, 0x63];
|
||||
|
||||
loop {
|
||||
trace!("Getting video message...");
|
||||
@@ -284,34 +279,19 @@ impl BcCamera {
|
||||
}) = msg.body
|
||||
{
|
||||
trace!("Got {} bytes of video data", binary.len());
|
||||
let magic = &binary.as_slice()[..4];
|
||||
trace!("Magic is: {:x?}", &magic);
|
||||
match magic {
|
||||
MAGIC_HEADER => {
|
||||
trace!("Header magic type");
|
||||
();
|
||||
match binary {
|
||||
BinaryData::VideoData(binary) => {
|
||||
data_out.write_all(binary.as_slice())?
|
||||
},
|
||||
MAGIC_AAC => {
|
||||
trace!("AAC magic type");
|
||||
//data_out.write_all(&binary.as_slice()[4..])?;
|
||||
BinaryData::AudioData(binary) => {
|
||||
()
|
||||
},
|
||||
MAGIC_ADPCM => {
|
||||
trace!("ADPCM magic type");
|
||||
();
|
||||
BinaryData::InfoData(binary) => {
|
||||
()
|
||||
},
|
||||
MAGIC_IFRAME => {
|
||||
trace!("IFrame magic type");
|
||||
data_out.write_all(binary.as_slice())?;
|
||||
BinaryData::Unknown(binary) => {
|
||||
data_out.write_all(binary.as_slice())?
|
||||
},
|
||||
MAGIC_PFRAME => {
|
||||
trace!("PFrame magic type");
|
||||
data_out.write_all(binary.as_slice())?;
|
||||
}
|
||||
_ => {
|
||||
trace!("Unknown magic type"); // When large video is chunked it goes here
|
||||
data_out.write_all(binary.as_slice())?;
|
||||
();
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
Reference in new issue
Block a user