1 /*****************************************************************************
3 *****************************************************************************
4 * Copyright (C) 2007 Laurent Aimar
5 * $Id: csa.h 20134 2007-05-16 14:30:27Z jpsaman $
7 * Authors: Laurent Aimar <fenrir@via.ecp.fr>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22 *****************************************************************************/
27 /* CC have a maximum rate of 9600 bit/s (per field?) */
28 #define CC_MAX_DATA_SIZE (2 * 3*600)
31 /* Which channel are present */
32 vlc_bool_t pb_present[4];
35 * byte[x+0]: field (0/1)
36 * byte[x+1]: cc data 1
37 * byte[x+2]: cc data 2
40 uint8_t p_data[CC_MAX_DATA_SIZE];
43 static inline int cc_Channel( int i_field, const uint8_t p_data[2] )
45 const uint8_t d = p_data[0] & 0x7f;
46 if( i_field != 0 && i_field != 1 )
52 /* unknown(middle of a command) or not cc channel */
55 static inline void cc_Init( cc_data_t *c )
59 for( i = 0; i < 4; i++ )
60 c-> pb_present[i] = VLC_FALSE;
63 static inline void cc_Exit( cc_data_t *c )
67 static inline void cc_Flush( cc_data_t *c )
71 static inline void cc_Extract( cc_data_t *c, const uint8_t *p_src, int i_src )
73 static const uint8_t p_cc_ga94[4] = { 0x47, 0x41, 0x39, 0x34 };
74 //static const uint8_t p_afd_start[4] = { 0x44, 0x54, 0x47, 0x31 };
81 * u1 process_cc_data_flag
82 * u1 additional_data_flag
84 * u8 reserved(1111 1111)
86 * u5 marker bit(1111 1)
91 * u8 marker bit(1111 1111)
92 * if additional_data_flag
99 if( !memcmp( p_cc_ga94, p_src, 4 ) && i_src >= 5+1+1+1 && p_src[4] == 0x03 )
101 /* Extract CC from DVB/ATSC TS */
102 const uint8_t *cc = &p_src[5];
103 const int i_count_cc = cc[0]&0x1f;
106 if( !(cc[0]&0x40) ) // process flag
108 if( i_src < 5 + 1+1 + i_count_cc*3 + 1) // broken packet
110 if( i_count_cc <= 0 ) // no cc present
112 if( cc[2+i_count_cc * 3] != 0xff ) // marker absent
116 for( i = 0; i < i_count_cc; i++, cc += 3 )
118 int i_field = cc[0] & 0x03;
120 if( ( cc[0] & 0xfc ) != 0xfc )
122 if( i_field != 0 && i_field != 1 )
124 if( c->i_data + 3 > CC_MAX_DATA_SIZE )
127 i_channel = cc_Channel( i_field, &cc[1] );
128 if( i_channel >= 0 && i_channel < 4 )
129 c->pb_present[i_channel] = VLC_TRUE;
131 c->p_data[c->i_data++] = i_field;
132 c->p_data[c->i_data++] = cc[1];
133 c->p_data[c->i_data++] = cc[2];
138 /* TODO DVD CC, ... */