vlc | branch: master | Francois Cartegnie <fcvlc...@free.fr> | Wed Nov 16 20:54:30 2016 +0100| [2b7a60de8ec91870390c92d5609a82c2405fa905] | committer: Francois Cartegnie
codec: cc: allow to pass format directly and strip unwanted headers > http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=2b7a60de8ec91870390c92d5609a82c2405fa905 --- modules/codec/cc.h | 121 +++++++++++++++++++++------------------ modules/codec/libmpeg2.c | 4 +- modules/packetizer/hxxx_common.c | 2 +- modules/packetizer/mpegvideo.c | 2 +- modules/packetizer/vc1.c | 2 +- 5 files changed, 69 insertions(+), 62 deletions(-) diff --git a/modules/codec/cc.h b/modules/codec/cc.h index f9c6170..6f8b6c4 100644 --- a/modules/codec/cc.h +++ b/modules/codec/cc.h @@ -96,64 +96,9 @@ static inline void cc_AppendData( cc_data_t *c, uint8_t cc_preamble, const uint8 c->p_data[c->i_data++] = cc[1]; } -static inline void cc_Extract( cc_data_t *c, bool b_top_field_first, const uint8_t *p_src, int i_src ) +static inline void cc_Extract( cc_data_t *c, enum cc_payload_type_e i_payload_type, + bool b_top_field_first, const uint8_t *p_src, int i_src ) { - static const uint8_t p_cc_ga94[4] = { 0x47, 0x41, 0x39, 0x34 }; - static const uint8_t p_cc_dvd[4] = { 0x43, 0x43, 0x01, 0xf8 }; /* ascii 'CC', type_code, cc_block_size */ - static const uint8_t p_cc_replaytv4a[2] = { 0xbb, 0x02 };/* RTV4K, BB02xxxxCC02 */ - static const uint8_t p_cc_replaytv4b[2] = { 0xcc, 0x02 };/* see DVR-ClosedCaption in samples */ - static const uint8_t p_cc_replaytv5a[2] = { 0x99, 0x02 };/* RTV5K, 9902xxxxAA02 */ - static const uint8_t p_cc_replaytv5b[2] = { 0xaa, 0x02 };/* see DVR-ClosedCaption in samples */ - static const uint8_t p_cc_scte20[2] = { 0x03, 0x81 }; /* user_data_type_code, SCTE 20 */ - static const uint8_t p_cc_scte20_old[2] = { 0x03, 0x01 };/* user_data_type_code, old, Note 1 */ - - if( i_src < 4 ) - return; - - int i_payload_type; - if( !memcmp( p_cc_ga94, p_src, 4 ) && i_src >= 5+1+1+1 && p_src[4] == 0x03 ) - { - /* CC from DVB/ATSC TS */ - i_payload_type = CC_PAYLOAD_GA94; - i_src -= 5; - p_src += 5; - } - else if( !memcmp( p_cc_dvd, p_src, 4 ) && i_src > 4+1 ) - { - i_payload_type = CC_PAYLOAD_DVD; - } - else if( i_src >= 2+2 + 2+2 && - ( ( !memcmp( p_cc_replaytv4a, &p_src[0], 2 ) && !memcmp( p_cc_replaytv4b, &p_src[4], 2 ) ) || - ( !memcmp( p_cc_replaytv5a, &p_src[0], 2 ) && !memcmp( p_cc_replaytv5b, &p_src[4], 2 ) ) ) ) - { - i_payload_type = CC_PAYLOAD_REPLAYTV; - } - else if( ( !memcmp( p_cc_scte20, p_src, 2 ) || - !memcmp( p_cc_scte20_old, p_src, 2 ) ) && i_src > 2 ) - { - i_payload_type = CC_PAYLOAD_SCTE20; - } - else if (p_src[0] == 0x03 && p_src[1] == i_src - 2) /* DIRECTV */ - { - i_payload_type = CC_PAYLOAD_GA94; - i_src -= 2; - p_src += 2; - } - else - { -#if 0 -#define V(x) ( ( x < 0x20 || x >= 0x7f ) ? '?' : x ) - fprintf( stderr, "-------------- unknown user data " ); - for( int i = 0; i < i_src; i++ ) - fprintf( stderr, "%2.2x ", p_src[i] ); - for( int i = 0; i < i_src; i++ ) - fprintf( stderr, "%c ", V(p_src[i]) ); - fprintf( stderr, "\n" ); -#undef V -#endif - return; - } - if( c->i_payload_type != CC_PAYLOAD_NONE && c->i_payload_type != i_payload_type ) { c->i_payload_other_count++; @@ -312,5 +257,67 @@ static inline void cc_Extract( cc_data_t *c, bool b_top_field_first, const uint8 } } + +static inline void cc_ProbeAndExtract( cc_data_t *c, bool b_top_field_first, const uint8_t *p_src, int i_src ) +{ + static const uint8_t p_cc_ga94[4] = { 0x47, 0x41, 0x39, 0x34 }; + static const uint8_t p_cc_dvd[4] = { 0x43, 0x43, 0x01, 0xf8 }; /* ascii 'CC', type_code, cc_block_size */ + static const uint8_t p_cc_replaytv4a[2] = { 0xbb, 0x02 };/* RTV4K, BB02xxxxCC02 */ + static const uint8_t p_cc_replaytv4b[2] = { 0xcc, 0x02 };/* see DVR-ClosedCaption in samples */ + static const uint8_t p_cc_replaytv5a[2] = { 0x99, 0x02 };/* RTV5K, 9902xxxxAA02 */ + static const uint8_t p_cc_replaytv5b[2] = { 0xaa, 0x02 };/* see DVR-ClosedCaption in samples */ + static const uint8_t p_cc_scte20[2] = { 0x03, 0x81 }; /* user_data_type_code, SCTE 20 */ + static const uint8_t p_cc_scte20_old[2] = { 0x03, 0x01 };/* user_data_type_code, old, Note 1 */ + + if( i_src < 4 ) + return; + + enum cc_payload_type_e i_payload_type; + if( !memcmp( p_cc_ga94, p_src, 4 ) && i_src >= 5+1+1+1 && p_src[4] == 0x03 ) + { + /* CC from DVB/ATSC TS */ + i_payload_type = CC_PAYLOAD_GA94; + i_src -= 5; + p_src += 5; + } + else if( !memcmp( p_cc_dvd, p_src, 4 ) && i_src > 4+1 ) + { + i_payload_type = CC_PAYLOAD_DVD; + } + else if( i_src >= 2+2 + 2+2 && + ( ( !memcmp( p_cc_replaytv4a, &p_src[0], 2 ) && !memcmp( p_cc_replaytv4b, &p_src[4], 2 ) ) || + ( !memcmp( p_cc_replaytv5a, &p_src[0], 2 ) && !memcmp( p_cc_replaytv5b, &p_src[4], 2 ) ) ) ) + { + i_payload_type = CC_PAYLOAD_REPLAYTV; + } + else if( ( !memcmp( p_cc_scte20, p_src, 2 ) || + !memcmp( p_cc_scte20_old, p_src, 2 ) ) && i_src > 2 ) + { + i_payload_type = CC_PAYLOAD_SCTE20; + } + else if (p_src[0] == 0x03 && p_src[1] == i_src - 2) /* DIRECTV */ + { + i_payload_type = CC_PAYLOAD_GA94; + i_src -= 2; + p_src += 2; + } + else + { +#if 0 +#define V(x) ( ( x < 0x20 || x >= 0x7f ) ? '?' : x ) + fprintf( stderr, "-------------- unknown user data " ); + for( int i = 0; i < i_src; i++ ) + fprintf( stderr, "%2.2x ", p_src[i] ); + for( int i = 0; i < i_src; i++ ) + fprintf( stderr, "%c ", V(p_src[i]) ); + fprintf( stderr, "\n" ); +#undef V +#endif + return; + } + + cc_Extract( c, i_payload_type, b_top_field_first, p_src, i_src ); +} + #endif /* _CC_H */ diff --git a/modules/codec/libmpeg2.c b/modules/codec/libmpeg2.c index f70ff3a..ef994d4 100644 --- a/modules/codec/libmpeg2.c +++ b/modules/codec/libmpeg2.c @@ -442,14 +442,14 @@ static picture_t *DecodeBlock( decoder_t *p_dec, block_t **pp_block ) if( p_sys->i_gop_user_data > 2 ) { /* We now have picture info for any cached user_data out of the gop */ - cc_Extract( &p_sys->cc, b_top_field_first, + cc_ProbeAndExtract( &p_sys->cc, b_top_field_first, &p_sys->p_gop_user_data[0], p_sys->i_gop_user_data ); p_sys->i_gop_user_data = 0; } /* Extract the CC from the user_data of the picture */ if( p_info->user_data_len > 2 ) - cc_Extract( &p_sys->cc, b_top_field_first, + cc_ProbeAndExtract( &p_sys->cc, b_top_field_first, &p_info->user_data[0], p_info->user_data_len ); } } diff --git a/modules/packetizer/hxxx_common.c b/modules/packetizer/hxxx_common.c index 137330e..0c5845a 100644 --- a/modules/packetizer/hxxx_common.c +++ b/modules/packetizer/hxxx_common.c @@ -68,7 +68,7 @@ void cc_storage_reset( cc_storage_t *p_ccs ) void cc_storage_append( cc_storage_t *p_ccs, bool b_top_field_first, const uint8_t *p_buf, size_t i_buf ) { - cc_Extract( &p_ccs->next, b_top_field_first, p_buf, i_buf ); + cc_ProbeAndExtract( &p_ccs->next, b_top_field_first, p_buf, i_buf ); } void cc_storage_commit( cc_storage_t *p_ccs, block_t *p_pic ) diff --git a/modules/packetizer/mpegvideo.c b/modules/packetizer/mpegvideo.c index 22f6e86..fc205d7 100644 --- a/modules/packetizer/mpegvideo.c +++ b/modules/packetizer/mpegvideo.c @@ -702,7 +702,7 @@ static block_t *ParseMPEGBlock( decoder_t *p_dec, block_t *p_frag ) } else if( p_frag->p_buffer[3] == 0xb2 && p_frag->i_buffer > 4 ) { - cc_Extract( &p_sys->cc, p_sys->i_top_field_first, + cc_ProbeAndExtract( &p_sys->cc, p_sys->i_top_field_first, &p_frag->p_buffer[4], p_frag->i_buffer - 4 ); } else if( p_frag->p_buffer[3] == 0x00 ) diff --git a/modules/packetizer/vc1.c b/modules/packetizer/vc1.c index e15b25f..51849dc 100644 --- a/modules/packetizer/vc1.c +++ b/modules/packetizer/vc1.c @@ -717,7 +717,7 @@ static block_t *ParseIDU( decoder_t *p_dec, bool *pb_ts_used, block_t *p_frag ) if( i_data >= sizeof(p_DVB1_user_identifier) && !memcmp( p_data, p_DVB1_user_identifier, sizeof(p_DVB1_user_identifier) ) ) { - cc_Extract( &p_sys->cc_next, true, p_data, i_data ); + cc_ProbeAndExtract( &p_sys->cc_next, true, p_data, i_data ); } free( p_data ); _______________________________________________ vlc-commits mailing list vlc-commits@videolan.org https://mailman.videolan.org/listinfo/vlc-commits