Skip to content
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
30 changes: 27 additions & 3 deletions src/lib_ccx/ccx_encoders_webvtt.c
Original file line number Diff line number Diff line change
Expand Up @@ -230,13 +230,37 @@ void write_webvtt_header(struct encoder_ctx *context)
else
{
// Must have another newline if X-TIMESTAMP-MAP is not used
if (ccx_options.enc_cfg.line_terminator_lf == 1) // If -lf parameter is set.
// if (ccx_options.enc_cfg.line_terminator_lf == 1) // If -lf parameter is set.
// {
// write_wrapped(context->out->fh, "\n", 1);
// }
// else
// {
// write_wrapped(context->out->fh, "\r\n", 2);
// }
// Issue #1743: write default X-TIMESTAMP-MAP when timing info is unavailable
if (ccx_options.timestamp_map)
{
write_wrapped(context->out->fh, "\n", 1);
const char *default_header =
ccx_options.enc_cfg.line_terminator_lf
? "X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:0\n\n"
: "X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:0\r\n\r\n";

write_wrapped(context->out->fh,
default_header,
strlen(default_header));
}
else
{
write_wrapped(context->out->fh, "\r\n", 2);
// Must have another newline if X-TIMESTAMP-MAP is not used
if (ccx_options.enc_cfg.line_terminator_lf == 1)
{
write_wrapped(context->out->fh, "\n", 1);
}
else
{
write_wrapped(context->out->fh, "\r\n", 2);
}
}
}

Expand Down
13 changes: 12 additions & 1 deletion src/lib_ccx/output.c
Original file line number Diff line number Diff line change
Expand Up @@ -249,9 +249,20 @@ void writercwtdata(struct lib_cc_decode *ctx, const unsigned char *data, struct
LLONG currfts = ctx->timing->fts_now + ctx->timing->fts_global;
static uint16_t cbcount = 0;
static int cbempty = 0;
static unsigned char cbbuffer[0xFFFF * 3]; // TODO: use malloc
// static unsigned char cbbuffer[0xFFFF * 3]; // TODO: use malloc
static unsigned char *cbbuffer = NULL; // Dynamic allocation
static unsigned char cbheader[8 + 2];

// Allocate buffer on first use
if (cbbuffer == NULL) {
cbbuffer = (unsigned char *)malloc(0xFFFF * 3);
if (cbbuffer == NULL) {
ccx_common_logging.log_ftn("Out of memory allocating buffer in writercwtdata()\n");
return;
}
dbg_print(CCX_DMT_VERBOSE, "Allocated %zu bytes for cbbuffer in writercwtdata()\n", (size_t)(0xFFFF * 3));
}

if ((prevfts != currfts && prevfts != -1) || data == NULL || cbcount == 0xFFFF)
{
// Remove trailing empty or 608 padding caption blocks
Expand Down
Loading