Skip to content

Commit

Permalink
Merge remote-tracking branch 'elb/add-teletext-module' into rust-tele…
Browse files Browse the repository at this point in the history
…text
  • Loading branch information
prateekmedia committed Aug 19, 2024
2 parents 98a85e1 + f8eb1a7 commit 0da3764
Show file tree
Hide file tree
Showing 15 changed files with 2,555 additions and 35 deletions.
6 changes: 5 additions & 1 deletion src/lib_ccx/lib_ccx.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
#include "ccx_decoders_708.h"
#include "ccx_decoders_isdb.h"

#ifndef DISABLE_RUST
extern void ccxr_init_basic_logger();
#endif

struct ccx_common_logging_t ccx_common_logging;
static struct ccx_decoders_common_settings_t *init_decoder_setting(
struct ccx_s_options *opt)
Expand Down Expand Up @@ -103,7 +107,7 @@ struct lib_ccx_ctx *init_libraries(struct ccx_s_options *opt)
ccx_common_logging.gui_ftn = &activity_library_process;

#ifndef DISABLE_RUST
ccxr_init_basic_logger(opt);
ccxr_init_basic_logger();
#endif

struct lib_ccx_ctx *ctx = malloc(sizeof(struct lib_ccx_ctx));
Expand Down
11 changes: 8 additions & 3 deletions src/lib_ccx/utility.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ int temp_debug = 0; // This is a convenience variable used to enable/disable deb
volatile sig_atomic_t change_filename_requested = 0;

#ifndef DISABLE_RUST
extern int ccxr_verify_crc32(uint8_t *buf, int len);
extern int ccxr_levenshtein_dist(const uint64_t *s1, const uint64_t *s2, unsigned s1len, unsigned s2len);
extern int ccxr_levenshtein_dist_char(const char *s1, const char *s2, unsigned s1len, unsigned s2len);
extern void ccxr_timestamp_to_srttime(uint64_t timestamp, char *buffer);
extern void ccxr_timestamp_to_vtttime(uint64_t timestamp, char *buffer);
extern void ccxr_millis_to_date(uint64_t timestamp, char *buffer, enum ccx_output_date_format date_format, char millis_separator);
Expand Down Expand Up @@ -86,7 +89,8 @@ int verify_crc32(uint8_t *buf, int len)
{
#ifndef DISABLE_RUST
return ccxr_verify_crc32(buf, len);
#endif /* ifndef DISABLE_RUST */
#endif

int i = 0;
int32_t crc = -1;
for (i = 0; i < len; i++)
Expand All @@ -99,8 +103,8 @@ int stringztoms(const char *s, struct ccx_boundary_time *bt)
#ifndef DISABLE_RUST
return ccxr_stringztoms(s, bt);
#endif
unsigned ss = 0,
mm = 0, hh = 0;

unsigned ss = 0, mm = 0, hh = 0;
int value = -1;
int colons = 0;
const char *c = s;
Expand Down Expand Up @@ -176,6 +180,7 @@ int levenshtein_dist(const uint64_t *s1, const uint64_t *s2, unsigned s1len, uns
#ifndef DISABLE_RUST
return ccxr_levenshtein_dist(s1, s2, s1len, s2len);
#endif

unsigned int x, y, v, lastdiag, olddiag;
unsigned int *column = (unsigned *)malloc((s1len + 1) * sizeof(unsigned int));
for (y = 1; y <= s1len; y++)
Expand Down
45 changes: 45 additions & 0 deletions src/rust/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions src/rust/lib_ccxr/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ derive_more = "0.99.18"
url = "2.5.2"
strum = "0.26.3"
strum_macros = "0.26.4"
crc32fast = "1.3.2"
num_enum = "0.6.1"

[features]
default = [
Expand Down
2 changes: 2 additions & 0 deletions src/rust/lib_ccxr/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
pub mod common;
pub mod hardsubx;
pub mod subtitle;
pub mod teletext;
pub mod time;
pub mod util;
97 changes: 97 additions & 0 deletions src/rust/lib_ccxr/src/subtitle.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
//! Provides types to represent different kinds of subtitle data in a unified format.
//!
//! NOTE: This module is incomplete and a lot of work is still left.
use crate::common::Language;
use crate::util::encoding::EncodedString;
use crate::util::time::Timestamp;

/// Represents the different formats in which subtitle data could be stored.
///
/// NOTE: Heavy Work in Progress.
pub enum SubtitleData {
Dvb {
/* bitmap: Bitmap, */
lang: Language,
is_eod: bool,
time_out: Timestamp,
},
Dvd {
/* bitmap: Bitmap, */
lang: Language,
},
Xds(/* XdsScreen */),
Eia608(/* Eia608Screen */),
Text(EncodedString),
Raw(Vec<u8>),
}

/// Represents a single subtitle instance on a screen with timing info.
pub struct Subtitle {
/// The subtitle data.
data: SubtitleData,

/// The start time for this subtitle.
start_time: Timestamp,

/// The end time of this subtitle.
end_time: Timestamp,

/// A flag to tell that decoder has given output.
got_output: bool,
info: Option<String>,
mode: String,
}

impl Subtitle {
/// Create a new Text Subtitle.
pub fn new_text(
string: EncodedString,
start_time: Timestamp,
end_time: Timestamp,
info: Option<String>,
mode: String,
) -> Subtitle {
Subtitle {
data: SubtitleData::Text(string),
start_time,
end_time,
got_output: true,
info,
mode,
}
}

/// Return a reference to the subtitle data.
pub fn data(&self) -> &SubtitleData {
&self.data
}

/// Return the start time of this subtitle.
pub fn start_time(&self) -> Timestamp {
self.start_time
}

/// Return the end time of this subtitle.
pub fn end_time(&self) -> Timestamp {
self.end_time
}

/// Check if decoder has given output.
pub fn got_output(&self) -> bool {
self.got_output
}

/// Update the state if decoder has given output.
pub fn set_got_output(&mut self, val: bool) {
self.got_output = val;
}

pub fn info(&self) -> Option<&str> {
self.info.as_deref()
}

pub fn mode(&self) -> &str {
&self.mode
}
}
Loading

0 comments on commit 0da3764

Please sign in to comment.