int track;
int id;
enum subtype { PICTURESUB, TEXTSUB } format;
- enum subsource { VOBSUB, SRTSUB, CCSUB } source;
+ enum subsource { VOBSUB, SRTSUB, CC608SUB, CC708SUB } source;
enum subdest { RENDERSUB, PASSTHRUSUB } dest;
char lang[1024];
char iso639_2[4];
extern hb_work_object_t hb_sync;
extern hb_work_object_t hb_decmpeg2;
-extern hb_work_object_t hb_decsub;
-extern hb_work_object_t hb_encsub;
+extern hb_work_object_t hb_decvobsub;
+extern hb_work_object_t hb_encvobsub;
+extern hb_work_object_t hb_deccc608;
extern hb_work_object_t hb_render;
extern hb_work_object_t hb_encavcodec;
extern hb_work_object_t hb_encxvid;
wb->new_sentence = 1;
wb->new_channel = 1;
wb->in_xds_mode = 0;
+
+ wb->hb_buffer = NULL;
+ wb->hb_last_buffer = NULL;
+ wb->last_pts = 0;
return 0;
}
if( wb->subline ) {
free(wb->subline);
}
+
+ if( wb->hb_buffer ) {
+ hb_buffer_close( &wb->hb_buffer );
+ }
}
memcpy( buffer->data, wb->subline, length + 1 );
//hb_log("CC %lld: %s", buffer->stop, wb->subline);
- hb_fifo_push( wb->subtitle->fifo_raw, buffer );
+ if (wb->hb_last_buffer) {
+ wb->hb_last_buffer->next = buffer;
+ } else {
+ wb->hb_buffer = buffer;
+ }
+ wb->hb_last_buffer = buffer;
XMLRPC_APPEND(wb->subline,length);
//fwrite (encoded_crlf, 1, encoded_crlf_length,wb->fh);
buffer->stop = ms_end;
memcpy( buffer->data, wb->subline, length + 1 );
- hb_fifo_push( wb->subtitle->fifo_raw, buffer );
+ if (wb->hb_last_buffer) {
+ wb->hb_last_buffer->next = buffer;
+ } else {
+ wb->hb_buffer = buffer;
+ }
+ wb->hb_last_buffer = buffer;
//fwrite (wb->subline, 1, length, wb->fh);
XMLRPC_APPEND(wb->subline,length);
void handle_end_of_data (struct s_write *wb)
{
- hb_buffer_t *buffer;
-
// We issue a EraseDisplayedMemory here so if there's any captions pending
// they get written to file.
handle_command (0x14, 0x2c, wb); // EDM
-
- /*
- * At the end of the subtitle stream HB wants an empty buffer
- */
- buffer = hb_buffer_init( 0 );
- hb_fifo_push( wb->subtitle->fifo_raw, buffer );
}
void handle_double (const unsigned char c1, const unsigned char c2, struct s_write *wb)
}
return output;
}
+
+
+struct hb_work_private_s
+{
+ hb_job_t * job;
+ struct s_write * cc608;
+};
+
+int decccInit( hb_work_object_t * w, hb_job_t * job )
+{
+ int retval = 1;
+ hb_work_private_t * pv;
+
+ pv = calloc( 1, sizeof( hb_work_private_t ) );
+ if( pv )
+ {
+ w->private_data = pv;
+
+ pv->job = job;
+
+ pv->cc608 = calloc(1, sizeof(struct s_write));
+
+ if( pv->cc608 )
+ {
+ retval = general_608_init(pv->cc608);
+ if( !retval )
+ {
+ pv->cc608->data608 = calloc(1, sizeof(struct eia608));
+ if( !pv->cc608->data608 )
+ {
+ retval = 1;
+ }
+ }
+ }
+ }
+ return retval;
+}
+
+int decccWork( hb_work_object_t * w, hb_buffer_t ** buf_in,
+ hb_buffer_t ** buf_out )
+{
+ hb_work_private_t * pv = w->private_data;
+ hb_buffer_t * in = *buf_in;
+
+ if ( in->size <= 0 )
+ {
+ /* EOF on input stream - send it downstream & say that we're done */
+ handle_end_of_data(pv->cc608);
+ /*
+ * Grab any pending buffer and output them with the EOF on the end
+ */
+ if (pv->cc608->hb_last_buffer) {
+ pv->cc608->hb_last_buffer->next = in;
+ *buf_out = pv->cc608->hb_buffer;
+ *buf_in = NULL;
+ pv->cc608->hb_buffer = NULL;
+ pv->cc608->hb_last_buffer = NULL;
+ } else {
+ *buf_out = in;
+ *buf_in = NULL;
+ }
+ return HB_WORK_DONE;
+ }
+
+ pv->cc608->last_pts = in->start;
+
+ process608(in->data, in->size, pv->cc608);
+
+ /*
+ * If there is one waiting then pass it on
+ */
+ *buf_out = pv->cc608->hb_buffer;
+ pv->cc608->hb_buffer = NULL;
+ pv->cc608->hb_last_buffer = NULL;
+
+ return HB_WORK_OK;
+}
+
+void decccClose( hb_work_object_t * w )
+{
+ hb_work_private_t * pv = w->private_data;
+ general_608_close( pv->cc608 );
+ free( pv->cc608->data608 );
+ free( pv->cc608 );
+ free( w->private_data );
+}
+
+hb_work_object_t hb_deccc608 =
+{
+ WORK_DECCC608,
+ "Closed Caption (608) decoder",
+ decccInit,
+ decccWork,
+ decccClose
+};
int new_sentence;
int new_channel;
int in_xds_mode;
- hb_subtitle_t * subtitle;
+ hb_buffer_t *hb_buffer;
+ hb_buffer_t *hb_last_buffer;
uint64_t last_pts;
};
#include "hb.h"
#include "hbffmpeg.h"
#include "mpeg2dec/mpeg2.h"
-#include "deccc608sub.h"
/* Cadence tracking */
#ifndef PIC_FLAG_REPEAT_FIRST_FIELD
int64_t last_pts;
int cadence[12];
int flag;
- struct s_write cc608; /* Closed Captions */
hb_subtitle_t * subtitle;
} hb_libmpeg2_t;
m->info = mpeg2_info( m->libmpeg2 );
m->last_pts = -1;
- /* Closed Captions init, whether needed or not */
- general_608_init( &m->cc608 );
- m->cc608.data608 = calloc(1, sizeof(struct eia608));
return m;
}
{
uint8_t cc_valid = (*cc_block & 4) >>2;
uint8_t cc_type = *cc_block & 3;
+ hb_buffer_t *cc_buf;
if( !m->job )
{
{
case 0:
// CC1 stream
- process608( cc_block+1, 2, &m->cc608 );
+ cc_buf = hb_buffer_init( 2 );
+ if( cc_buf )
+ {
+ cc_buf->start = m->last_pts;
+ memcpy( cc_buf->data, cc_block+1, 2 );
+ hb_fifo_push( m->subtitle->fifo_in, cc_buf );
+ }
break;
case 1:
// CC2 stream
/*
* Look for Closed Captions if scanning (!job) or if closed captions have been requested.
+ *
+ * Send them on to the closed caption decoder if requested and found.
*/
if( ( !m->job || m->subtitle) &&
( m->info->user_data_len != 0 &&
int capcount=(header[0] & 0x1e) / 2;
header++;
- m->cc608.last_pts = m->last_pts;
-
/*
* Add closed captions to the title if we are scanning (no job).
*
for( i = 0; i < hb_list_count( m->title->list_subtitle ); i++ )
{
subtitle = hb_list_item( m->title->list_subtitle, i);
- if( subtitle && subtitle->source == CCSUB )
+ /*
+ * Let's call them 608 subs for now even if they aren't, since they
+ * are the only types we grok.
+ */
+ if( subtitle && subtitle->source == CC608SUB )
{
found = 1;
break;
snprintf( subtitle->lang, sizeof( subtitle->lang ), "Closed Captions");
snprintf( subtitle->iso639_2, sizeof( subtitle->iso639_2 ), "und");
subtitle->format = TEXTSUB;
- subtitle->source = CCSUB;
+ subtitle->source = CC608SUB;
subtitle->dest = PASSTHRUSUB;
subtitle->type = 5;
mpeg2_close( m->libmpeg2 );
- free( m->cc608.data608 );
- general_608_close( &m->cc608 );
-
free( m );
*_m = NULL;
}
}
/*
- * If not scanning, then are we supposed to extract Closed Captions?
+ * If not scanning, then are we supposed to extract Closed Captions
+ * and send them to the decoder?
*/
if( job )
{
for( i = 0; i < hb_list_count( job->list_subtitle ); i++ )
{
subtitle = hb_list_item( job->list_subtitle, i);
- if( subtitle && subtitle->source == CCSUB )
+ if( subtitle && subtitle->source == CC608SUB )
{
pv->libmpeg2->subtitle = subtitle;
- pv->libmpeg2->cc608.subtitle = subtitle;
break;
}
}
}
- /*
- * During a scan add a Closed Caption subtitle track to the title,
- * since we may have CC. Don't bother actually trying to detect CC
- * since we'd have to go through too much of the source.
- *
- if( !job && w->title )
- {
- hb_subtitle_t * subtitle;
- int found = 0;
- int i;
-
- for( i = 0; i < hb_list_count( w->title->list_subtitle ); i++ )
- {
- subtitle = hb_list_item( w->title->list_subtitle, i);
- if( subtitle && subtitle->source == CCSUB )
- {
- found = 1;
- break;
- }
- }
-
- if( !found )
- {
- subtitle = calloc( sizeof( hb_subtitle_t ), 1 );
- subtitle->track = 0;
- subtitle->id = 0x0;
- snprintf( subtitle->lang, sizeof( subtitle->lang ), "Closed Captions");
- snprintf( subtitle->iso639_2, sizeof( subtitle->iso639_2 ), "und");
- subtitle->format = TEXTSUB;
- subtitle->source = CCSUB;
- subtitle->dest = PASSTHRUSUB;
- subtitle->type = 5;
-
- hb_list_add( w->title->list_subtitle, subtitle );
- }
- }
- */
-
return 0;
}
*/
if( pv->libmpeg2->subtitle )
{
- handle_end_of_data( &pv->libmpeg2->cc608 );
+ hb_buffer_t *buf_eof = hb_buffer_init( 0 );
+
+ if( buf_eof )
+ {
+ hb_fifo_push( pv->libmpeg2->subtitle->fifo_in, buf_eof );
+ }
}
}
free( w->private_data );
}
-hb_work_object_t hb_decsub =
+hb_work_object_t hb_decvobsub =
{
- WORK_DECSUB,
+ WORK_DECVOBSUB,
"VOBSUB decoder",
decsubInit,
decsubWork,
free( w->private_data );
}
-hb_work_object_t hb_encsub =
+hb_work_object_t hb_encvobsub =
{
- WORK_ENCSUB,
+ WORK_ENCVOBSUB,
"VOBSUB encoder",
encsubInit,
encsubWork,
hb_register( &hb_sync );
hb_register( &hb_decmpeg2 );
- hb_register( &hb_decsub );
- hb_register( &hb_encsub );
+ hb_register( &hb_decvobsub );
+ hb_register( &hb_encvobsub );
+ hb_register( &hb_deccc608 );
hb_register( &hb_render );
hb_register( &hb_encavcodec );
hb_register( &hb_encxvid );
hb_register( &hb_encx264 );
- hb_register( &hb_enctheora );
+ hb_register( &hb_enctheora );
hb_register( &hb_deca52 );
hb_register( &hb_decdca );
hb_register( &hb_decavcodec );
hb_init_real( v, u ); \
hb_register( &hb_sync ); \
hb_register( &hb_decmpeg2 ); \
-hb_register( &hb_decsub ); \
-hb_register( &hb_encsub ); \
+hb_register( &hb_decvobsub ); \
+hb_register( &hb_encvobsub ); \
+hb_register( &hb_deccc608 ); \
hb_register( &hb_render ); \
hb_register( &hb_encavcodec ); \
hb_register( &hb_encxvid ); \
hb_init_real( v, u ); \
hb_register( &hb_sync ); \
hb_register( &hb_decmpeg2 ); \
-hb_register( &hb_decsub ); \
-hb_register( &hb_encsub ); \
+hb_register( &hb_decvobsub ); \
+hb_register( &hb_encvobsub ); \
+hb_register( &hb_deccc608 ); \
hb_register( &hb_render ); \
hb_register( &hb_encavcodec ); \
hb_register( &hb_encx264 ); \
{
WORK_SYNC = 1,
WORK_DECMPEG2,
- WORK_DECSUB,
- WORK_ENCSUB,
+ WORK_DECCC608,
+ WORK_DECVOBSUB,
+ WORK_ENCVOBSUB,
WORK_RENDER,
WORK_ENCAVCODEC,
WORK_ENCXVID,
{
/* we got an end-of-stream. Feed it downstream & signal that we're done. */
hb_fifo_push( job->fifo_sync, hb_buffer_init( 0 ) );
+
+ /*
+ * Push through any subtitle EOFs in case they were not synced through.
+ */
+ for( i = 0; i < hb_list_count( job->list_subtitle ); i++)
+ {
+ subtitle = hb_list_item( job->list_subtitle, i );
+ if( subtitle->dest == PASSTHRUSUB )
+ {
+ hb_fifo_push( subtitle->fifo_out, hb_buffer_init( 0 ) );
+ }
+ }
+
pv->busy &=~ 1;
return;
}
* video (we don't know its duration). On DVDs the final frame
* is often strange and dropping it seems to be a good idea. */
hb_fifo_push( job->fifo_sync, hb_buffer_init( 0 ) );
+
+ /*
+ * Push through any subtitle EOFs in case they were not synced through.
+ */
+ for( i = 0; i < hb_list_count( job->list_subtitle ); i++)
+ {
+ subtitle = hb_list_item( job->list_subtitle, i );
+ if( subtitle->dest == PASSTHRUSUB )
+ {
+ hb_fifo_push( subtitle->fifo_out, hb_buffer_init( 0 ) );
+ }
+ }
pv->busy &=~ 1;
return;
}
/*
* Rewrite timestamps on subtitles that need it (on raw queue).
*/
- if( subtitle->source == CCSUB )
+ if( subtitle->source == CC608SUB ||
+ subtitle->source == CC708SUB )
{
/*
* Rewrite timestamps on subtitles that came from Closed Captions
*
* Bypass the sync fifo altogether.
*/
- if( sub->size == 0 )
+ if( sub->size <= 0 )
{
sub = hb_fifo_get( subtitle->fifo_raw );
hb_fifo_push( subtitle->fifo_out, sub );
{
hb_log( " * subtitle track %i, %s (id %x) %s [%s] -> %s ", subtitle->track, subtitle->lang, subtitle->id,
subtitle->format == PICTURESUB ? "Picture" : "Text",
- subtitle->source == VOBSUB ? "VOBSUB" : (subtitle->source == CCSUB ? "CC" : "SRT"),
+ subtitle->source == VOBSUB ? "VOBSUB" :
+ ((subtitle->source == CC608SUB ||
+ subtitle->source == CC708SUB) ? "CC" : "SRT"),
subtitle->dest == RENDERSUB ? "Render/Burn in" : "Pass-Through");
}
}
}
}
- if( !job->indepth_scan || job->subtitle_force ) {
+ if( (!job->indepth_scan || job->subtitle_force) &&
+ subtitle->source == VOBSUB ) {
/*
* Don't add threads for subtitles when we are scanning, unless
* looking for forced subtitles.
*/
- w = hb_get_work( WORK_DECSUB );
+ w = hb_get_work( WORK_DECVOBSUB );
+ w->fifo_in = subtitle->fifo_in;
+ w->fifo_out = subtitle->fifo_raw;
+ hb_list_add( job->list_work, w );
+ }
+
+ if( !job->indepth_scan && subtitle->source == CC608SUB )
+ {
+ w = hb_get_work( WORK_DECCC608 );
w->fifo_in = subtitle->fifo_in;
w->fifo_out = subtitle->fifo_raw;
hb_list_add( job->list_work, w );
* Passing through a subtitle picture, this will have to
* be rle encoded before muxing.
*/
- w = hb_get_work( WORK_ENCSUB );
+ w = hb_get_work( WORK_ENCVOBSUB );
w->fifo_in = subtitle->fifo_sync;
w->fifo_out = subtitle->fifo_out;
hb_list_add( job->list_work, w );