Skip to content

Commit 98cec31

Browse files
authored
Rust updates:- Update documentation (#1374)
* Fix warning * Update documentation * Fix typo * fmt
1 parent 46b145a commit 98cec31

File tree

9 files changed

+631
-427
lines changed

9 files changed

+631
-427
lines changed

src/lib_ccx/ccx_decoders_common.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -195,16 +195,16 @@ int do_cb(struct lib_cc_decode *ctx, unsigned char *cc_block, struct cc_subtitle
195195
timeok = 0;
196196
ctx->processed_enough = 1;
197197
}
198-
char temp[4];
199-
temp[0] = cc_valid;
200-
temp[1] = cc_type;
201-
temp[2] = cc_block[1];
202-
temp[3] = cc_block[2];
203198
if (timeok)
204199
{
205200
if (ctx->write_format != CCX_OF_RCWT)
206201
{
207202
#ifndef ENABLE_RUST
203+
char temp[4];
204+
temp[0] = cc_valid;
205+
temp[1] = cc_type;
206+
temp[2] = cc_block[1];
207+
temp[3] = cc_block[2];
208208
dtvcc_process_data(ctx->dtvcc, (const unsigned char *)temp);
209209
#endif
210210
}

src/rust/src/decoder/commands.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! Different code sets as defined in CEA-708-E
22
//!
3-
//! Refer section 7.1 CEA-708-E
3+
//! Refer section 7.1 CEA-708-E.
44
//! Different code sets are:
55
//!
66
//! | Name | Description | Space |

src/rust/src/decoder/mod.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! CEA 708 decoder
22
//!
3-
//! This module provides a CEA 708 decoder as defined by ANSI/CTA-708-E R-2018
3+
//! Provides a CEA 708 decoder as defined by ANSI/CTA-708-E R-2018
44
55
mod commands;
66
mod output;
@@ -20,7 +20,7 @@ const CCX_DTVCC_SCREENGRID_COLUMNS: u8 = 210;
2020
const CCX_DTVCC_MAX_ROWS: u8 = 15;
2121
const CCX_DTVCC_MAX_COLUMNS: u8 = 32 * 2;
2222

23-
/// Stores the context required for processing 708 data
23+
/// Context required for processing 708 data
2424
pub struct Dtvcc<'a> {
2525
pub is_active: bool,
2626
pub active_services_count: u8,
@@ -60,7 +60,7 @@ impl<'a> Dtvcc<'a> {
6060
timing,
6161
}
6262
}
63-
/// Process cc data to generate dtvcc packet
63+
/// Process cc data and add it to the dtvcc packet
6464
pub fn process_cc_data(&mut self, cc_valid: u8, cc_type: u8, data1: u8, data2: u8) {
6565
if !self.is_active && !self.report_enabled {
6666
return;
@@ -86,6 +86,7 @@ impl<'a> Dtvcc<'a> {
8686
max_len *= 2;
8787
}
8888

89+
// If packet is complete then process the packet
8990
if self.packet_length >= max_len {
9091
self.process_current_packet(max_len);
9192
}
@@ -109,6 +110,7 @@ impl<'a> Dtvcc<'a> {
109110
),
110111
}
111112
}
113+
/// Add data to the packet
112114
pub fn add_data_to_packet(&mut self, data1: u8, data2: u8) {
113115
self.packet[self.packet_length as usize] = data1;
114116
self.packet_length += 1;
@@ -126,6 +128,8 @@ impl<'a> Dtvcc<'a> {
126128
return;
127129
}
128130

131+
// Check if current sequence is correct
132+
// Sequence number is a 2 bit rolling sequence from (0-3)
129133
if self.last_sequence != CCX_DTVCC_NO_LAST_SEQUENCE
130134
&& (self.last_sequence + 1) % 4 != seq as i32
131135
{
@@ -189,6 +193,10 @@ impl<'a> Dtvcc<'a> {
189193
}
190194
}
191195

196+
/// A single character symbol
197+
///
198+
/// sym stores the symbol
199+
/// init is used to know if the symbol is initialized
192200
impl dtvcc_symbol {
193201
/// Create a new symbol
194202
pub fn new(sym: u16) -> Self {

src/rust/src/decoder/output.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//! Utilty functions to write captions
2+
13
#[cfg(windows)]
24
use std::os::windows::io::{FromRawHandle, IntoRawHandle, RawHandle};
35
use std::{
@@ -23,6 +25,7 @@ pub struct Writer<'a> {
2325
}
2426

2527
impl<'a> Writer<'a> {
28+
/// Create a new writer context
2629
pub fn new(
2730
cea_708_counter: &'a mut u32,
2831
subs_delay: LLONG,
@@ -43,6 +46,11 @@ impl<'a> Writer<'a> {
4346
no_bom,
4447
}
4548
}
49+
/// Write subtitles to the file
50+
///
51+
/// File must already exist
52+
/// On Unix Platforms, uses the raw fd from context to access the file
53+
/// On Windows Platforms, uses the raw handle from context to access the file
4654
pub fn write_to_file(&mut self, buf: &[u8]) -> Result<(), String> {
4755
#[cfg(unix)]
4856
{
@@ -60,6 +68,10 @@ impl<'a> Writer<'a> {
6068
}
6169
}
6270

71+
/// Write the symbol to the provided buffer
72+
///
73+
/// If symbol is 8-bit, then it's written to the buffer
74+
/// If symbol is 16-bit, then two 8-bit symbols are written to the buffer
6375
pub fn write_char(sym: &dtvcc_symbol, buf: &mut Vec<u8>) {
6476
if sym.sym >> 8 != 0 {
6577
buf.push((sym.sym >> 8) as u8);
@@ -69,6 +81,12 @@ pub fn write_char(sym: &dtvcc_symbol, buf: &mut Vec<u8>) {
6981
}
7082
}
7183

84+
/// Convert from CEA-708 color representation to hex code
85+
///
86+
/// Two bits are specified for each red, green, and blue color value which defines the
87+
/// intensity of each individual color component.
88+
///
89+
/// Refer section 8.8 CEA-708-E
7290
pub fn color_to_hex(color: u8) -> (u8, u8, u8) {
7391
let red = color >> 4;
7492
let green = (color >> 2) & 0x3;

0 commit comments

Comments
 (0)