Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEAT] Add timing module in lib_ccxr #1558

Closed
Closed
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
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,8 @@ src/rust/CMakeCache.txt
src/rust/Makefile
src/rust/cmake_install.cmake
src/rust/target/
src/rust/lib_ccxr/target/
windows/ccx_rust.lib
windows/*/debug/*
windows/*/CACHEDIR.TAG
windows/.rustc_info.json
windows/.rustc_info.json
48 changes: 48 additions & 0 deletions src/lib_ccx/ccx_common_timing.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,18 @@ int gop_rollover = 0;

struct ccx_common_timing_settings_t ccx_common_timing_settings;

#ifndef DISABLE_RUST
void ccxr_add_current_pts(struct ccx_common_timing_ctx *ctx, LLONG pts);
void ccxr_set_current_pts(struct ccx_common_timing_ctx *ctx, LLONG pts);
int ccxr_set_fts(struct ccx_common_timing_ctx *ctx);
LLONG ccxr_get_fts(struct ccx_common_timing_ctx *ctx, int current_field);
LLONG ccxr_get_fts_max(struct ccx_common_timing_ctx *ctx);
char *ccxr_print_mstime_static(LLONG mstime, char *buf);
void ccxr_print_debug_timing(struct ccx_common_timing_ctx *ctx);
void ccxr_calculate_ms_gop_time(struct gop_time_code *g);
int ccxr_gop_accepted(struct gop_time_code *g);
#endif

void ccx_common_timing_init(LLONG *file_position, int no_sync)
{
ccx_common_timing_settings.disable_sync_check = 0;
Expand Down Expand Up @@ -73,11 +85,19 @@ struct ccx_common_timing_ctx *init_timing_ctx(struct ccx_common_timing_settings_

void add_current_pts(struct ccx_common_timing_ctx *ctx, LLONG pts)
{
#ifndef DISABLE_RUST
return ccxr_add_current_pts(ctx, pts);
#endif

set_current_pts(ctx, ctx->current_pts + pts);
}

void set_current_pts(struct ccx_common_timing_ctx *ctx, LLONG pts)
{
#ifndef DISABLE_RUST
return ccxr_set_current_pts(ctx, pts);
#endif

LLONG prev_pts = ctx->current_pts;
ctx->current_pts = pts;
if (ctx->pts_set == 0)
Expand All @@ -95,6 +115,10 @@ void set_current_pts(struct ccx_common_timing_ctx *ctx, LLONG pts)

int set_fts(struct ccx_common_timing_ctx *ctx)
{
#ifndef DISABLE_RUST
return ccxr_set_fts(ctx);
#endif

int pts_jump = 0;

// ES don't have PTS unless GOP timing is used
Expand Down Expand Up @@ -266,6 +290,10 @@ int set_fts(struct ccx_common_timing_ctx *ctx)

LLONG get_fts(struct ccx_common_timing_ctx *ctx, int current_field)
{
#ifndef DISABLE_RUST
return ccxr_get_fts(ctx, current_field);
#endif

LLONG fts;

switch (current_field)
Expand All @@ -290,6 +318,10 @@ LLONG get_fts(struct ccx_common_timing_ctx *ctx, int current_field)

LLONG get_fts_max(struct ccx_common_timing_ctx *ctx)
{
#ifndef DISABLE_RUST
return ccxr_get_fts_max(ctx);
#endif

// This returns the maximum FTS that belonged to a frame. Caption block
// counters are not applicable.
return ctx->fts_max + ctx->fts_global;
Expand Down Expand Up @@ -322,13 +354,21 @@ size_t print_mstime_buff(LLONG mstime, char *fmt, char *buf)
char *print_mstime_static(LLONG mstime)
{
static char buf[15]; // 14 should be long enough
#ifndef DISABLE_RUST
return ccxr_print_mstime_static(mstime, buf);
#endif

print_mstime_buff(mstime, "%02u:%02u:%02u:%03u", buf);
return buf;
}

/* Helper function for to display debug timing info. */
void print_debug_timing(struct ccx_common_timing_ctx *ctx)
{
#ifndef DISABLE_RUST
return ccxr_print_debug_timing(ctx);
#endif

// Avoid wrong "Calc. difference" and "Asynchronous by" numbers
// for uninitialized min_pts
LLONG tempmin_pts = (ctx->min_pts == 0x01FFFFFFFFLL ? ctx->sync_pts : ctx->min_pts);
Expand All @@ -355,6 +395,10 @@ void print_debug_timing(struct ccx_common_timing_ctx *ctx)

void calculate_ms_gop_time(struct gop_time_code *g)
{
#ifndef DISABLE_RUST
return ccxr_calculate_ms_gop_time(g);
#endif

int seconds = (g->time_code_hours * 3600) + (g->time_code_minutes * 60) + g->time_code_seconds;
g->ms = (LLONG)(1000 * (seconds + g->time_code_pictures / current_fps));
if (gop_rollover)
Expand All @@ -363,6 +407,10 @@ void calculate_ms_gop_time(struct gop_time_code *g)

int gop_accepted(struct gop_time_code *g)
{
#ifndef DISABLE_RUST
return ccxr_gop_accepted(g);
#endif

if (!((g->time_code_hours <= 23) && (g->time_code_minutes <= 59) && (g->time_code_seconds <= 59) && (g->time_code_pictures <= 59)))
return 0;

Expand Down
8 changes: 8 additions & 0 deletions 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 @@ -100,6 +104,10 @@ struct lib_ccx_ctx *init_libraries(struct ccx_s_options *opt)
ccx_common_logging.log_ftn = &mprint;
ccx_common_logging.gui_ftn = &activity_library_process;

#ifndef DISABLE_RUST
ccxr_init_basic_logger();
#endif

struct lib_ccx_ctx *ctx = malloc(sizeof(struct lib_ccx_ctx));
if (!ctx)
ccx_common_logging.fatal_ftn(EXIT_NOT_ENOUGH_MEMORY, "init_libraries: Not enough memory allocating lib_ccx_ctx context.");
Expand Down
33 changes: 33 additions & 0 deletions src/lib_ccx/utility.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@
int temp_debug = 0; // This is a convenience variable used to enable/disable debug on variable conditions. Find references to understand.
volatile sig_atomic_t change_filename_requested = 0;

#ifndef DISABLE_RUST
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);
extern int ccxr_stringztoms(const char *s, struct ccx_boundary_time *bt);
#endif

static uint32_t crc32_table[] = {
0x00000000, 0x04c11db7, 0x09823b6e, 0x0d4326d9,
0x130476dc, 0x17c56b6b, 0x1a864db2, 0x1e475005,
Expand Down Expand Up @@ -86,6 +93,10 @@ int verify_crc32(uint8_t *buf, int len)

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;
int value = -1;
int colons = 0;
Expand Down Expand Up @@ -130,6 +141,10 @@ int stringztoms(const char *s, struct ccx_boundary_time *bt)
}
void timestamp_to_srttime(uint64_t timestamp, char *buffer)
{
#ifndef DISABLE_RUST
return ccxr_timestamp_to_srttime(timestamp, buffer);
#endif

uint64_t p = timestamp;
uint8_t h = (uint8_t)(p / 3600000);
uint8_t m = (uint8_t)(p / 60000 - 60 * h);
Expand All @@ -139,6 +154,10 @@ void timestamp_to_srttime(uint64_t timestamp, char *buffer)
}
void timestamp_to_vtttime(uint64_t timestamp, char *buffer)
{
#ifndef DISABLE_RUST
return ccxr_timestamp_to_vtttime(timestamp, buffer);
#endif

uint64_t p = timestamp;
uint8_t h = (uint8_t)(p / 3600000);
uint8_t m = (uint8_t)(p / 60000 - 60 * h);
Expand Down Expand Up @@ -193,6 +212,20 @@ int levenshtein_dist_char(const char *s1, const char *s2, unsigned s1len, unsign

void millis_to_date(uint64_t timestamp, char *buffer, enum ccx_output_date_format date_format, char millis_separator)
{
#ifndef DISABLE_RUST
switch (date_format)
{
case ODF_NONE:
case ODF_HHMMSS:
case ODF_HHMMSSMS:
case ODF_SECONDS:
case ODF_DATE:
return ccxr_millis_to_date(timestamp, buffer, date_format, millis_separator);
default:
fatal(CCX_COMMON_EXIT_BUG_BUG, "Invalid value for date_format in millis_to_date()\n");
}
#endif

time_t secs;
unsigned int millis;
char c_temp[80];
Expand Down
Loading
Loading