Skip to content

Commit e6b85da

Browse files
committed
Fix writing frame end with multiline captions
1 parent cb48bee commit e6b85da

2 files changed

Lines changed: 46 additions & 14 deletions

File tree

src/lib_ccx/ccx_encoders_transcript.c

Lines changed: 38 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ int write_cc_subtitle_as_transcript(struct cc_subtitle *sub, struct encoder_ctx
134134

135135
str = sub->data;
136136

137+
int wrote_something = 0;
137138
str = strtok_r(str, "\r\n", &save_str);
138139
do
139140
{
@@ -143,6 +144,15 @@ int write_cc_subtitle_as_transcript(struct cc_subtitle *sub, struct encoder_ctx
143144
continue;
144145
}
145146

147+
if (wrote_something)
148+
{
149+
ret = write(context->out->fh, context->encoded_crlf, context->encoded_crlf_length);
150+
if (ret < context->encoded_crlf_length)
151+
{
152+
mprint("Warning:Loss of data\n");
153+
}
154+
}
155+
146156
if (context->transcript_settings->showStartTime)
147157
{
148158
char buf[80];
@@ -200,14 +210,16 @@ int write_cc_subtitle_as_transcript(struct cc_subtitle *sub, struct encoder_ctx
200210
mprint("Warning:Loss of data\n");
201211
}
202212

203-
ret = write(context->out->fh, context->encoded_end_frame, context->encoded_end_frame_length);
204-
if (ret < context->encoded_end_frame_length)
205-
{
206-
mprint("Warning:Loss of data\n");
207-
}
213+
wrote_something = 1;
208214

209215
} while ((str = strtok_r(NULL, "\r\n", &save_str)));
210216

217+
ret = write(context->out->fh, context->encoded_end_frame, context->encoded_end_frame_length);
218+
if (ret < context->encoded_end_frame_length)
219+
{
220+
mprint("Warning:Loss of data\n");
221+
}
222+
211223
freep(&sub->data);
212224
lsub = sub;
213225
sub = sub->next;
@@ -321,29 +333,43 @@ void write_cc_line_as_transcript2(struct eia608_screen *data, struct encoder_ctx
321333
{
322334
mprint("Warning:Loss of data\n");
323335
}
324-
325-
ret = write(context->out->fh, context->encoded_end_frame, context->encoded_end_frame_length);
326-
if (ret < context->encoded_end_frame_length)
327-
{
328-
mprint("Warning:Loss of data\n");
329-
}
330336
}
331337
// fprintf (wb->fh,encoded_crlf);
332338
}
333339

334340
int write_cc_buffer_as_transcript2(struct eia608_screen *data, struct encoder_ctx *context)
335341
{
342+
int ret;
336343
int wrote_something = 0;
337344
dbg_print(CCX_DMT_DECODER_608, "\n- - - TRANSCRIPT caption - - -\n");
338345

339346
for (int i = 0; i < 15; i++)
340347
{
341348
if (data->row_used[i])
342349
{
350+
if (wrote_something)
351+
{
352+
ret = write(context->out->fh, context->encoded_crlf, context->encoded_crlf_length);
353+
if (ret < context->encoded_crlf_length)
354+
{
355+
mprint("Warning:Loss of data\n");
356+
}
357+
}
358+
343359
write_cc_line_as_transcript2(data, context, i);
360+
wrote_something = 1;
361+
}
362+
}
363+
364+
if (wrote_something)
365+
{
366+
ret = write(context->out->fh, context->encoded_end_frame, context->encoded_end_frame_length);
367+
if (ret < context->encoded_end_frame_length)
368+
{
369+
mprint("Warning:Loss of data\n");
344370
}
345-
wrote_something = 1;
346371
}
372+
347373
dbg_print(CCX_DMT_DECODER_608, "- - - - - - - - - - - -\r\n");
348374
return wrote_something;
349375
}

src/rust/src/decoder/tv_screen.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -330,8 +330,13 @@ impl dtvcc_tv_screen {
330330
let time_show = get_time_str(self.time_ms_show);
331331
let time_hide = get_time_str(self.time_ms_hide);
332332

333+
let mut wrote_something = false;
333334
for row_index in 0..CCX_DTVCC_SCREENGRID_ROWS as usize {
334335
if !self.is_row_empty(row_index) {
336+
if wrote_something {
337+
writer.write_to_file(b"\r\n")?;
338+
}
339+
335340
let mut buf = String::new();
336341

337342
if is_true(writer.transcript_settings.showStartTime) {
@@ -350,10 +355,11 @@ impl dtvcc_tv_screen {
350355
}
351356
writer.write_to_file(buf.as_bytes())?;
352357
self.write_row(writer, row_index, false)?;
353-
let end_frame = writer.end_frame.clone();
354-
writer.write_to_file(&end_frame)?;
358+
wrote_something = true;
355359
}
356360
}
361+
let end_frame = writer.end_frame.clone();
362+
writer.write_to_file(&end_frame)?;
357363
Ok(())
358364
}
359365

0 commit comments

Comments
 (0)