Skip to content
Open
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
1 change: 0 additions & 1 deletion src/lib_ccx/ccx_decoders_vbi.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,4 @@ struct ccx_decoder_vbi_ctx
};


int decode_vbi(struct lib_cc_decode *dec_ctx, uint8_t field, unsigned char *buffer, size_t len, struct cc_subtitle *sub);
#endif
6 changes: 6 additions & 0 deletions src/lib_ccx/es_functions.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,14 @@ static int read_pic_data(struct bitstream *esstream);
/* Process a mpeg-2 data stream with "length" bytes in buffer "data".
* The number of processed bytes is returned.
* Defined in ISO/IEC 13818-2 6.2 */
#ifndef DISABLE_RUST
size_t ccxr_process_m2v(struct encoder_ctx *enc_ctx, struct lib_cc_decode *dec_ctx, unsigned char *data, size_t length, struct cc_subtitle *sub);
#endif
size_t process_m2v(struct encoder_ctx *enc_ctx, struct lib_cc_decode *dec_ctx, unsigned char *data, size_t length, struct cc_subtitle *sub)
{
#ifndef DISABLE_RUST
return ccxr_process_m2v(enc_ctx, dec_ctx, data, length, sub);
#endif
if (length < 8) // Need to look ahead 8 bytes
return length;

Expand Down
2 changes: 2 additions & 0 deletions src/lib_ccx/lib_ccx.h
Original file line number Diff line number Diff line change
Expand Up @@ -329,4 +329,6 @@ int process_non_multiprogram_general_loop(struct lib_ccx_ctx* ctx,
int ret,
int *caps);
void segment_output_file(struct lib_ccx_ctx *ctx, struct lib_cc_decode *dec_ctx);
int decode_vbi(struct lib_cc_decode *dec_ctx, uint8_t field, unsigned char *buffer, size_t len, struct cc_subtitle *sub);

#endif
5 changes: 5 additions & 0 deletions src/rust/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ fn main() {
"version",
"set_binary_mode",
"net_send_header", // shall be removed after NET
"process_hdcc",
"anchor_hdcc",
"store_hdcc",
"do_cb",
"decode_vbi",
"write_spumux_footer",
"write_spumux_header",
]);
Expand Down
25 changes: 25 additions & 0 deletions src/rust/lib_ccxr/src/activity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ use crate::common::Options;

pub trait ActivityExt {
fn activity_report_version(&mut self);
fn activity_video_info(
&mut self,
hor_size: u32,
vert_size: u32,
aspect_ratio: &str,
framerate: &str,
);
}
impl ActivityExt for Options {
fn activity_report_version(&mut self) {
Expand All @@ -15,4 +22,22 @@ impl ActivityExt for Options {
stderr.flush().unwrap();
}
}
fn activity_video_info(
&mut self,
hor_size: u32,
vert_size: u32,
aspect_ratio: &str,
framerate: &str,
) {
if self.gui_mode_reports {
let mut stderr = io::stderr();
writeln!(
stderr,
"###VIDEOINFO#{}#{}#{}#{}",
hor_size, vert_size, aspect_ratio, framerate
)
.unwrap();
stderr.flush().unwrap();
}
}
}
131 changes: 130 additions & 1 deletion src/rust/lib_ccxr/src/common/bitstream.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use crate::fatal;
use crate::util::log::ExitCause;
use crate::util::log::{debug, DebugMessageFlag};
use thiserror::Error;

#[derive(Debug, Error)]
Expand All @@ -23,7 +24,12 @@ pub struct BitStreamRust<'a> {
pub _i_pos: usize,
pub _i_bpos: u8,
}

#[macro_export]
macro_rules! dbg_es {
($($args:expr),*) => {
debug!(msg_type = DebugMessageFlag::VERBOSE; "{}", format!($($args),*))
};
}
impl<'a> BitStreamRust<'a> {
/// Create a new bitstream. Empty data is allowed (bits_left = 0).
pub fn new(data: &'a [u8]) -> Result<Self, BitstreamError> {
Expand Down Expand Up @@ -333,6 +339,129 @@ impl<'a> BitStreamRust<'a> {

res
}
// Return the next startcode or sequence_error_code if not enough
// data was left in the bitstream. Also set esstream->bitsleft.
// The bitstream pointer shall be moved to the begin of the start
// code if found, or to the position where a search would continue
// would more data be made available.
// This function discards all data until the start code is
// found
pub fn search_start_code(&mut self) -> Result<u8, BitstreamError> {
self.make_byte_aligned()?;

// Keep a negative esstream->bitsleft, but correct it.
if self.bits_left <= 0 {
dbg_es!("search_start_code: bitsleft <= 0");
self.bits_left -= 8 * 4;
return Ok(0xB4);
}

let mut tpos = self.pos;

// Scan for 0x000001xx in header
loop {
// Find next 0x00 byte
let remaining_data = &self.data[tpos..];
if let Some(zero_offset) = remaining_data.iter().position(|&b| b == 0x00) {
tpos += zero_offset;
} else {
// We don't even have the starting 0x00
tpos = self.data.len();
self.bits_left = -8 * 4;
break;
}

if tpos + 3 >= self.data.len() {
// Not enough bytes left to check for 0x000001??
self.bits_left = 8 * (self.data.len() as i64 - (tpos + 4) as i64);
break;
} else if self.data[tpos + 1] == 0x00 && self.data[tpos + 2] == 0x01 {
// Found 0x000001??
self.bits_left = 8 * (self.data.len() as i64 - (tpos + 4) as i64);
break;
}
// Keep searching
tpos += 1;
}

self.pos = tpos;
if self.bits_left < 0 {
dbg_es!("search_start_code: bitsleft <= 0");
Ok(0xB4)
} else {
dbg_es!("search_start_code: Found {:02X}", self.data[tpos + 3]);
Ok(self.data[tpos + 3])
}
}

// Return the next startcode or sequence_error_code if not enough
// data was left in the bitstream. Also set esstream->bitsleft.
// The bitstream pointer shall be moved to the begin of the start
// code if found, or to the position where a search would continue
// would more data be made available.
// Only NULL bytes before the start code are discarded, if a non
// NULL byte is encountered esstream->error is set to TRUE and the
// function returns sequence_error_code with the pointer set after
// that byte.
pub fn next_start_code(&mut self) -> Result<u8, BitstreamError> {
if self.error || self.bits_left < 0 {
return Ok(0xB4);
}

self.make_byte_aligned()?;

// Only start looking if there is enough data. Adjust bitsleft.
if self.bits_left < 4 * 8 {
dbg_es!("next_start_code: bitsleft {} < 32", self.bits_left);
self.bits_left -= 8 * 4;
return Ok(0xB4);
}

let mut tmp: u8;
while (self.bitstream_get_num(4, false)? & 0x00FFFFFF) != 0x00010000 // LSB 0x000001??
&& self.bits_left > 0
{
tmp = self.bitstream_get_num(1, true)? as u8;
if tmp != 0 {
dbg_es!("next_start_code: Non zero stuffing");
self.error = true;
return Ok(0xB4);
}
}

if self.bits_left < 8 {
self.bits_left -= 8;
dbg_es!("next_start_code: bitsleft <= 0");
Ok(0xB4)
} else {
dbg_es!("next_start_code: Found {:02X}", self.data[self.pos + 3]);

if self.data[self.pos + 3] == 0xB4 {
dbg_es!("B4: assume bitstream syntax error!");
self.error = true;
}

Ok(self.data[self.pos + 3])
}
}
pub fn init_bitstream(&mut self, start: usize, end: usize) -> Result<(), BitstreamError> {
if start > end || end > self.data.len() {
return Err(BitstreamError::InsufficientData);
}

self.pos = start;
self.bpos = 8;
self.bits_left = (end - start) as i64 * 8;
self.error = false;
self._i_pos = 0;
self._i_bpos = 0;

if self.bits_left < 0 {
return Err(BitstreamError::NegativeLength);
}

Ok(())
}
}
#[cfg(test)]
mod tests {
Expand Down
12 changes: 6 additions & 6 deletions src/rust/lib_ccxr/src/time/units.rs
Original file line number Diff line number Diff line change
Expand Up @@ -537,12 +537,12 @@ impl FrameCount {
/// [`Timestamp`] instead of the other format.
#[derive(Copy, Clone, Debug)]
pub struct GopTimeCode {
drop_frame: bool,
time_code_hours: u8,
time_code_minutes: u8,
time_code_seconds: u8,
time_code_pictures: u8,
timestamp: Timestamp,
pub drop_frame: bool,
pub time_code_hours: u8,
pub time_code_minutes: u8,
pub time_code_seconds: u8,
pub time_code_pictures: u8,
pub timestamp: Timestamp,
}

impl GopTimeCode {
Expand Down
Loading
Loading