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
67 changes: 64 additions & 3 deletions src/608.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "ccextractor.h"
#include "608_spupng.h"
#include "cc_decoders_common.h"
#include "utility.h"

static const int rowdata[] = {11,-1,1,2,3,4,12,13,14,15,5,6,7,8,9,10};
// Relationship between the first PAC byte and the row number
Expand Down Expand Up @@ -477,7 +479,25 @@ struct eia608_screen *get_current_visible_buffer(struct s_context_cc608 *context
int write_cc_buffer(struct s_context_cc608 *context)
{
struct eia608_screen *data;
struct cc_subtitle *sub = NULL;
int wrote_something=0;
LLONG start_time;
LLONG end_time;

if(!context->sub)
{
sub =
context->sub = malloc(sizeof(struct cc_subtitle));
memset(context->sub, 0, sizeof(struct cc_subtitle));
}
else
sub = context->sub;
if (!sub)
{
mprint("No Memory Left");
return 0;
}

if (ccx_options.screens_to_process!=-1 &&
context->screenfuls_counter >= ccx_options.screens_to_process)
{
Expand All @@ -490,12 +510,49 @@ int write_cc_buffer(struct s_context_cc608 *context)
else
data = &context->buffer2;

if (context->mode == MODE_FAKE_ROLLUP_1 && // Use the actual start of data instead of last buffer change
context->ts_start_of_current_line != -1)
context->current_visible_start_ms = context->ts_start_of_current_line;

start_time = context->current_visible_start_ms;
end_time = get_visible_end() + subs_delay;

if (!data->empty)
{
if (context->mode == MODE_FAKE_ROLLUP_1 && // Use the actual start of data instead of last buffer change
context->ts_start_of_current_line != -1)
context->current_visible_start_ms = context->ts_start_of_current_line;
sub->data = (struct eia608_screen *) realloc(sub->data,sub->size + sizeof(*data));
if (!sub->data)
{
mprint("No Memory left");
return 0;
}

memcpy(((struct eia608_screen *)sub->data) + (sub->size/sizeof(*data)), data, sizeof(*data));
sub->size += sizeof(*data);
wrote_something = 1;
if(start_time < end_time)
{
int i = 0;
int nb_data = sub->size/sizeof(*data);
for(i = 0; i < nb_data; i++)
{
data = (struct eia608_screen *)sub->data + i;
data->start_time = start_time + ( ( (end_time - start_time)/nb_data ) * i );
data->end_time = start_time + ( ( (end_time - start_time)/nb_data ) * (i + 1) );
}
}
else
{
data = sub->data;
data->start_time = 0;
data->end_time = 0;
}


}
for(data = sub->data; sub->size ; sub->size -= sizeof(struct eia608_screen))
{
if(!data || !data->start_time)
break;
new_sentence=1;
switch (ccx_options.write_format)
{
Expand Down Expand Up @@ -528,7 +585,11 @@ int write_cc_buffer(struct s_context_cc608 *context)

if (ccx_options.gui_mode_reports)
write_cc_buffer_to_gui(data, context);
data = (struct eia608_screen*)sub->data + 1;
if (!sub->size)
freep(&sub->data);
}

return wrote_something;
}

Expand Down
5 changes: 4 additions & 1 deletion src/608.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ struct eia608_screen // A CC buffer
unsigned char colors[15][33];
unsigned char fonts[15][33]; // Extra char at the end for a 0
int row_used[15]; // Any data in row?
int empty; // Buffer completely empty?
int empty; // Buffer completely empty?
LLONG start_time;
LLONG end_time;
};

struct s_context_cc608
Expand All @@ -44,6 +46,7 @@ struct s_context_cc608
long bytes_processed_608; // To be written ONLY by process_608
struct ccx_s_write *out;
int have_cursor_position;
struct cc_subtitle *sub;
};

extern unsigned char *enc_buffer;
Expand Down
4 changes: 2 additions & 2 deletions src/608_sami.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,13 @@ int write_cc_buffer_as_sami(struct eia608_screen *data, struct s_context_cc608 *
{
LLONG startms, endms;
int wrote_something=0;
startms = context->current_visible_start_ms;
startms = data->start_time;

startms+=subs_delay;
if (startms<0) // Drop screens that because of subs_delay start too early
return 0;

endms = get_visible_end()+subs_delay;
endms = data->end_time;
endms--; // To prevent overlapping with next line.
sprintf ((char *) str,
"<SYNC start=%llu><P class=\"UNKNOWNCC\">\r\n",
Expand Down
4 changes: 2 additions & 2 deletions src/608_smptett.c
Original file line number Diff line number Diff line change
Expand Up @@ -102,13 +102,13 @@ int write_cc_buffer_as_smptett(struct eia608_screen *data, struct s_context_cc60
unsigned h2,m2,s2,ms2;
LLONG endms;
int wrote_something=0;
LLONG startms = context->current_visible_start_ms;
LLONG startms = data->start_time;

startms+=subs_delay;
if (startms<0) // Drop screens that because of subs_delay start too early
return 0;

endms = get_visible_end()+subs_delay;
endms = data->end_time;
endms--; // To prevent overlapping with next line.
mstotime (startms,&h1,&m1,&s1,&ms1);
mstotime (endms-1,&h2,&m2,&s2,&ms2);
Expand Down
4 changes: 2 additions & 2 deletions src/608_spupng.c
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ int
spupng_write_ccbuffer(struct spupng_t *sp, struct eia608_screen* data,
struct s_context_cc608 *context)
{
LLONG ms_start = context->current_visible_start_ms + subs_delay;
LLONG ms_start = data->start_time + subs_delay;
if (ms_start < 0)
{
dbg_print(CCX_DMT_VERBOSE, "Negative start\n");
Expand All @@ -220,7 +220,7 @@ spupng_write_ccbuffer(struct spupng_t *sp, struct eia608_screen* data,
return 0;
}

LLONG ms_end = get_visible_end() + subs_delay;
LLONG ms_end = data->end_time;

sprintf(sp->pngfile, "%s/sub%04d.png", sp->dirname, sp->fileIndex++);
if ((sp->fppng = fopen(sp->pngfile, "wb")) == NULL)
Expand Down
Loading