Skip to content
Merged
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
2 changes: 1 addition & 1 deletion src/lib_ccx/activity.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ void activity_progress (int percentage, int cur_min, int cur_sec)
mprint ("\rStreaming | %02d:%02d", cur_min, cur_sec);
else
mprint ("\r%3d%% | %02d:%02d",percentage, cur_min, cur_sec);
if (ccx_options.pes_header_to_stdout) //For PES Header dumping
if (ccx_options.pes_header_to_stdout || ccx_options.dvb_debug_traces_to_stdout) //For PES Header dumping and DVB debug traces
{
printf("\n");
}
Expand Down
1 change: 1 addition & 0 deletions src/lib_ccx/ccx_common_option.h
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ struct ccx_s_options // Options from user parameters
LLONG subs_delay; // ms to delay (or advance) subs
int cc_to_stdout; // If this is set to 1, the stdout will be flushed when data was written to the screen during a process_608 call.
int pes_header_to_stdout; //If this is set to 1, the PES Header will be printed to console (debugging purposes)
int dvb_debug_traces_to_stdout; // If 1, DVB subtitle debug traces will be outputted to console
int multiprogram;
int out_interval;
#ifdef WITH_LIBCURL
Expand Down
1 change: 1 addition & 0 deletions src/lib_ccx/ccx_decoders_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ void dinit_cc_decode(struct lib_cc_decode **ctx)
ccx_decoder_608_dinit_library(&lctx->context_cc608_field_1);
ccx_decoder_608_dinit_library(&lctx->context_cc608_field_2);
dinit_timing_ctx(&lctx->timing);
freep(&lctx->prev);
freep(ctx);
}

Expand Down
3 changes: 3 additions & 0 deletions src/lib_ccx/ccx_decoders_structs.h
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,9 @@ struct lib_cc_decode
struct ccx_decoder_vbi_ctx *vbi_decoder;

int (*writedata)(const unsigned char *data, int length, void *private_data, struct cc_subtitle *sub);

//dvb subtitle related
struct lib_cc_decode *prev;
};

#endif
3 changes: 2 additions & 1 deletion src/lib_ccx/ccx_encoders_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -892,7 +892,8 @@ void dinit_encoder(struct encoder_ctx **arg, LLONG current_fts)
freep(&ctx->subline);
freep(&ctx->buffer);
ctx->capacity = 0;
freep(arg);
freep(&ctx->prev);
freep(arg);
}

struct encoder_ctx *init_encoder(struct encoder_cfg *opt)
Expand Down
4 changes: 4 additions & 0 deletions src/lib_ccx/ccx_encoders_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,10 @@ struct encoder_ctx
LLONG sbs_time_from; // Used by the split-by-sentence code to know when the current block starts...
LLONG sbs_time_trim; // ... and ends
size_t sbs_capacity;

//for dvb subs
struct encoder_ctx* prev;
int write_previous;
};

#define INITIAL_ENC_BUFFER_CAPACITY 2048
Expand Down
16 changes: 1 addition & 15 deletions src/lib_ccx/ccx_encoders_srt.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,23 +91,9 @@ int write_cc_bitmap_as_srt(struct cc_subtitle *sub, struct encoder_ctx *context)
int i = 0;
char *str;

//if (context->prev_start != -1 && (sub->flags & SUB_EOD_MARKER))
//{
// ms_start = context->prev_start;
// ms_end = sub->start_time;
//}
//else if ( !(sub->flags & SUB_EOD_MARKER))
//{
// ms_start = sub->start_time;
// ms_end = sub->end_time;
//}
//else if (context->prev_start == -1 && (sub->flags & SUB_EOD_MARKER))
//{
// ms_start = 1;
// ms_end = sub->start_time;
//}
ms_start = sub->start_time;
ms_end = sub->end_time;

if(sub->nb_data == 0 )
return 0;

Expand Down
29 changes: 26 additions & 3 deletions src/lib_ccx/dvb_subtitle_decoder.c
Original file line number Diff line number Diff line change
Expand Up @@ -1561,7 +1561,7 @@ static int write_dvb_sub(struct lib_cc_decode *dec_ctx, struct cc_subtitle *sub)
*
* @return -1 on error
*/
int dvbsub_decode(struct lib_cc_decode *dec_ctx, const unsigned char *buf, int buf_size, struct cc_subtitle *sub)
int dvbsub_decode(struct encoder_ctx *enc_ctx, struct lib_cc_decode *dec_ctx, const unsigned char *buf, int buf_size, struct cc_subtitle *sub)
{
DVBSubContext *ctx = (DVBSubContext *) dec_ctx->private_data;
const uint8_t *p, *p_end;
Expand Down Expand Up @@ -1601,6 +1601,13 @@ int dvbsub_decode(struct lib_cc_decode *dec_ctx, const unsigned char *buf, int b
if (page_id == ctx->composition_id || page_id == ctx->ancillary_id
|| ctx->composition_id == -1 || ctx->ancillary_id == -1)
{
if (ccx_options.dvb_debug_traces_to_stdout)
{
//debug traces
printf("DVBSUB - PTS: %d, ", dec_ctx->timing->current_pts);
printf("FTS: %d, ", dec_ctx->timing->fts_now);
printf("SEGMENT TYPE : %d \n", segment_type);
}
switch (segment_type)
{
case DVBSUB_PAGE_SEGMENT:
Expand All @@ -1625,8 +1632,24 @@ int dvbsub_decode(struct lib_cc_decode *dec_ctx, const unsigned char *buf, int b
dvbsub_parse_display_definition_segment(ctx, p,
segment_length);
break;
case DVBSUB_DISPLAY_SEGMENT:
write_dvb_sub(dec_ctx, sub);
case DVBSUB_DISPLAY_SEGMENT: //when we get a display segment, we save the current page
if (enc_ctx->write_previous) //this condition is used for the first subtitle - write_previous will be 0 first so we don't encode a non-existing previous sub
{
sub->prev->end_time = (dec_ctx->timing->current_pts - dec_ctx->timing->min_pts) / (MPEG_CLOCK_FREQ / 1000); //we set the end time of the previous sub the current pts
encode_sub(enc_ctx->prev, sub->prev); //we encode it
enc_ctx->srt_counter = enc_ctx->prev->srt_counter; //for dvb subs we need to update the current srt counter because we always encode the previous subtitle (and the counter is increased for the previous context)
sub->prev->got_output = 0;
freep(sub->prev); //we free it to avoid memory leak
enc_ctx->write_previous = 0;

}
memcpy(enc_ctx->prev, enc_ctx, sizeof(struct encoder_ctx)); //we save the current encoder context
sub->prev = malloc(sizeof(struct cc_subtitle)); //we allocate space for the previous subtitle of the current subtitle
memcpy(sub->prev, sub, sizeof(struct cc_subtitle)); //we save the current subtitle
memcpy(dec_ctx->prev, dec_ctx, sizeof(struct lib_cc_decode)); //we save the current decoder context
sub->prev->start_time = (dec_ctx->timing->current_pts - dec_ctx->timing->min_pts) / (MPEG_CLOCK_FREQ / 1000); //we set the start time of the previous sub the current pts
write_dvb_sub(dec_ctx->prev, sub->prev); //we write the current dvb sub to update decoder context
enc_ctx->write_previous = 1; //we update our boolean value so next time the program reaches this block of code, it encodes the previous sub
got_segment |= 16;
break;
default:
Expand Down
2 changes: 1 addition & 1 deletion src/lib_ccx/dvb_subtitle_decoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ int dvbsub_close_decoder(void **dvb_ctx);
*
* @return -1 on error
*/
int dvbsub_decode(struct lib_cc_decode *dec_ctx, const unsigned char *buf, int buf_size, struct cc_subtitle *sub);
int dvbsub_decode(struct encoder_ctx *enc_ctx, struct lib_cc_decode *dec_ctx, const unsigned char *buf, int buf_size, struct cc_subtitle *sub);

/**
* @func parse_dvb_description
Expand Down
5 changes: 3 additions & 2 deletions src/lib_ccx/general_loop.c
Original file line number Diff line number Diff line change
Expand Up @@ -645,7 +645,7 @@ int process_data(struct encoder_ctx *enc_ctx, struct lib_cc_decode *dec_ctx, str
}
else if(data_node->bufferdatatype == CCX_DVB_SUBTITLE)
{
dvbsub_decode(dec_ctx, data_node->buffer + 2, data_node->len - 2, dec_sub);
dvbsub_decode(enc_ctx, dec_ctx, data_node->buffer + 2, data_node->len - 2, dec_sub);
set_fts(dec_ctx->timing);
got = data_node->len;
}
Expand Down Expand Up @@ -751,7 +751,7 @@ int process_data(struct encoder_ctx *enc_ctx, struct lib_cc_decode *dec_ctx, str
}
}

if (dec_sub->got_output)
if (data_node->bufferdatatype != CCX_DVB_SUBTITLE && dec_sub->got_output)
{
encode_sub(enc_ctx, dec_sub);
dec_sub->got_output = 0;
Expand Down Expand Up @@ -872,6 +872,7 @@ void general_loop(struct lib_ccx_ctx *ctx)
enc_ctx = update_encoder_list_cinfo(ctx, cinfo);
dec_ctx = update_decoder_list_cinfo(ctx, cinfo);
dec_ctx->dtvcc->encoder = (void *)enc_ctx; //WARN: otherwise cea-708 will not work

if (enc_ctx)
enc_ctx->timing = dec_ctx->timing;

Expand Down
16 changes: 16 additions & 0 deletions src/lib_ccx/lib_ccx.c
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ struct lib_ccx_ctx* init_libraries(struct ccx_s_options *opt)

ctx->cc_to_stdout = opt->cc_to_stdout;
ctx->pes_header_to_stdout = opt->pes_header_to_stdout;
ctx->dvb_debug_traces_to_stdout = opt->dvb_debug_traces_to_stdout;

ctx->hauppauge_mode = opt->hauppauge_mode;
ctx->live_stream = opt->live_stream;
Expand Down Expand Up @@ -318,6 +319,13 @@ struct lib_cc_decode *update_decoder_list_cinfo(struct lib_ccx_ctx *ctx, struct
fatal(EXIT_NOT_ENOUGH_MEMORY, "update_decoder_list_cinfo: Not enough memory allocating dec_ctx ((multiprogram == true)\n");
list_add_tail( &(dec_ctx->list), &(ctx->dec_ctx_head) );
}
if (cinfo)
{
if (cinfo->codec == CCX_CODEC_DVB)
{
dec_ctx->prev = malloc(sizeof(struct lib_cc_decode));
}
}
return dec_ctx;
}

Expand Down Expand Up @@ -406,6 +414,14 @@ struct encoder_ctx *update_encoder_list_cinfo(struct lib_ccx_ctx *ctx, struct ca
freep(&ccx_options.enc_cfg.output_filename);
}
freep(&extension);
if (cinfo)
{
if (cinfo->codec == CCX_CODEC_DVB)
{
enc_ctx->write_previous = 0;
enc_ctx->prev = malloc(sizeof(struct encoder_ctx));
}
}
return enc_ctx;
}

Expand Down
1 change: 1 addition & 0 deletions src/lib_ccx/lib_ccx.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ struct lib_ccx_ctx

int cc_to_stdout; // If 1, captions go to stdout instead of file
int pes_header_to_stdout; //If 1, PES Header data will be outputted to console
int dvb_debug_traces_to_stdout; // If 1, DVB subtitle debug traces will be outputted to console

LLONG subs_delay; // ms to delay (or advance) subs

Expand Down
5 changes: 5 additions & 0 deletions src/lib_ccx/params.c
Original file line number Diff line number Diff line change
Expand Up @@ -1650,6 +1650,11 @@ int parse_parameters (struct ccx_s_options *opt, int argc, char *argv[])
opt->pes_header_to_stdout = 1;
continue;
}
if (strcmp(argv[i], "-debugdvbsub") == 0)
{
opt->dvb_debug_traces_to_stdout = 1;
continue;
}
if (strcmp (argv[i],"-quiet")==0)
{
opt->messages_target=0;
Expand Down