@@ -52,6 +52,8 @@ static const char *smptett_header = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>
5252
5353static const char * webvtt_header = "WEBVTT\r\n\r\n" ;
5454
55+ static const char * simple_xml_header = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n<captions>\r\n" ;
56+
5557void find_limit_characters (unsigned char * line , int * first_non_blank , int * last_non_blank , int max_len )
5658{
5759 * last_non_blank = -1 ;
@@ -329,6 +331,19 @@ int write_subtitle_file_footer(struct encoder_ctx *ctx,struct ccx_s_write *out)
329331 case CCX_OF_SPUPNG :
330332 write_spumux_footer (out );
331333 break ;
334+ case CCX_OF_SIMPLE_XML :
335+ sprintf ((char * ) str ,"</captions>\n" );
336+ if (ctx -> encoding != CCX_ENC_UNICODE )
337+ {
338+ dbg_print (CCX_DMT_DECODER_608 , "\r%s\n" , str );
339+ }
340+ used = encode_line (ctx , ctx -> buffer ,(unsigned char * ) str );
341+ ret = write (out -> fh , ctx -> buffer , used );
342+ if (ret != used )
343+ {
344+ mprint ("WARNING: loss of data\n" );
345+ }
346+ break ;
332347 default : // Nothing to do, no footer on this format
333348 break ;
334349 }
@@ -445,13 +460,67 @@ static int write_subtitle_file_header(struct encoder_ctx *ctx, struct ccx_s_writ
445460 ret = write_bom (ctx , out );
446461 if (ret < 0 )
447462 return -1 ;
463+ case CCX_OF_SIMPLE_XML : // No header. Fall thru
464+ ret = write_bom (ctx , out );
465+ if (ret < 0 )
466+ return -1 ;
467+ REQUEST_BUFFER_CAPACITY (ctx ,strlen (simple_xml_header )* 3 );
468+ used = encode_line (ctx , ctx -> buffer ,(unsigned char * ) simple_xml_header );
469+ ret = write (out -> fh , ctx -> buffer , used );
470+ if (ret < used )
471+ {
472+ mprint ("WARNING: Unable to write complete Buffer \n" );
473+ return -1 ;
474+ }
448475 default :
449476 break ;
450477 }
451478
452479 return ret ;
453480}
454481
482+ int write_cc_subtitle_as_simplexml (struct cc_subtitle * sub , struct encoder_ctx * context )
483+ {
484+ int length ;
485+ int ret = 0 ;
486+ char * str ;
487+ char * save_str ;
488+ struct cc_subtitle * osub = sub ;
489+ struct cc_subtitle * lsub = sub ;
490+
491+ while (sub )
492+ {
493+ str = sub -> data ;
494+
495+ str = strtok_r (str , "\r\n" , & save_str );
496+ do
497+ {
498+ length = get_str_basic (context -> subline , str , context -> trim_subs , sub -> enc_type , context -> encoding , strlen (str ));
499+ if (length <= 0 )
500+ {
501+ continue ;
502+ }
503+ ret = write (context -> out -> fh , context -> encoded_crlf , context -> encoded_crlf_length );
504+ if (ret < context -> encoded_crlf_length )
505+ {
506+ mprint ("Warning:Loss of data\n" );
507+ }
508+
509+ } while (str = strtok_r (NULL , "\r\n" , & save_str ) );
510+
511+ freep (& sub -> data );
512+ lsub = sub ;
513+ sub = sub -> next ;
514+ }
515+ while (lsub != osub )
516+ {
517+ sub = lsub -> prev ;
518+ freep (& lsub );
519+ lsub = sub ;
520+ }
521+
522+ }
523+
455524int write_cc_subtitle_as_transcript (struct cc_subtitle * sub , struct encoder_ctx * context )
456525{
457526 int length ;
@@ -573,6 +642,30 @@ int write_cc_subtitle_as_transcript(struct cc_subtitle *sub, struct encoder_ctx
573642 return ret ;
574643}
575644
645+ void write_cc_line_as_simplexml (struct eia608_screen * data , struct encoder_ctx * context , int line_number )
646+ {
647+ int ret ;
648+ int length = 0 ;
649+ char * cap = "<caption>" ;
650+ char * cap1 = "</caption>" ;
651+ if (context -> sentence_cap )
652+ {
653+ capitalize (context , line_number , data );
654+ correct_case (line_number , data );
655+ }
656+ length = get_str_basic (context -> subline , data -> characters [line_number ],
657+ context -> trim_subs , CCX_ENC_ASCII , context -> encoding , CCX_DECODER_608_SCREEN_WIDTH );
658+
659+ ret = write (context -> out -> fh , cap , strlen (cap ));
660+ ret = write (context -> out -> fh , context -> subline , length );
661+ if (ret < length )
662+ {
663+ mprint ("Warning:Loss of data\n" );
664+ }
665+ ret = write (context -> out -> fh , cap1 , strlen (cap1 ));
666+ ret = write (context -> out -> fh , context -> encoded_crlf , context -> encoded_crlf_length );
667+
668+ }
576669//TODO Convert CC line to TEXT format and remove this function
577670void write_cc_line_as_transcript2 (struct eia608_screen * data , struct encoder_ctx * context , int line_number )
578671{
@@ -680,6 +773,21 @@ void write_cc_line_as_transcript2(struct eia608_screen *data, struct encoder_ctx
680773 // fprintf (wb->fh,encoded_crlf);
681774}
682775
776+ int write_cc_buffer_as_simplexml (struct eia608_screen * data , struct encoder_ctx * context )
777+ {
778+ int wrote_something = 0 ;
779+
780+ for (int i = 0 ;i < 15 ;i ++ )
781+ {
782+ if (data -> row_used [i ])
783+ {
784+ write_cc_line_as_simplexml (data , context , i );
785+ }
786+ wrote_something = 1 ;
787+ }
788+ return wrote_something ;
789+ }
790+
683791int write_cc_buffer_as_transcript2 (struct eia608_screen * data , struct encoder_ctx * context )
684792{
685793 int wrote_something = 0 ;
@@ -696,6 +804,17 @@ int write_cc_buffer_as_transcript2(struct eia608_screen *data, struct encoder_ct
696804 dbg_print (CCX_DMT_DECODER_608 , "- - - - - - - - - - - -\r\n" );
697805 return wrote_something ;
698806}
807+
808+ //Dummy Function for support DVB in simple xml
809+ int write_cc_bitmap_as_simplexml (struct cc_subtitle * sub , struct encoder_ctx * context )
810+ {
811+ int ret = 0 ;
812+
813+ sub -> nb_data = 0 ;
814+ freep (& sub -> data );
815+ return ret ;
816+ }
817+
699818int write_cc_bitmap_as_transcript (struct cc_subtitle * sub , struct encoder_ctx * context )
700819{
701820 int ret = 0 ;
@@ -1248,6 +1367,9 @@ int encode_sub(struct encoder_ctx *context, struct cc_subtitle *sub)
12481367 case CCX_OF_SPUPNG :
12491368 wrote_something = write_cc_buffer_as_spupng (data , context );
12501369 break ;
1370+ case CCX_OF_SIMPLE_XML :
1371+ wrote_something = write_cc_buffer_as_simplexml (data , context );
1372+ break ;
12511373 default :
12521374 break ;
12531375 }
@@ -1289,6 +1411,9 @@ int encode_sub(struct encoder_ctx *context, struct cc_subtitle *sub)
12891411 case CCX_OF_SPUPNG :
12901412 wrote_something = write_cc_bitmap_as_spupng (sub , context );
12911413 break ;
1414+ case CCX_OF_SIMPLE_XML :
1415+ wrote_something = write_cc_bitmap_as_simplexml (sub , context );
1416+ break ;
12921417 default :
12931418 break ;
12941419 }
@@ -1337,6 +1462,9 @@ int encode_sub(struct encoder_ctx *context, struct cc_subtitle *sub)
13371462 case CCX_OF_SPUPNG :
13381463 wrote_something = write_cc_subtitle_as_spupng (sub , context );
13391464 break ;
1465+ case CCX_OF_SIMPLE_XML :
1466+ wrote_something = write_cc_subtitle_as_simplexml (sub , context );
1467+ break ;
13401468 default :
13411469 break ;
13421470 }
0 commit comments