| 1 |
|
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
|
|---|
| 20 |
|
|---|
| 21 |
|
|---|
| 22 |
|
|---|
| 23 |
|
|---|
| 24 |
|
|---|
| 25 |
|
|---|
| 26 |
|
|---|
| 27 |
#ifdef HAVE_CONFIG_H |
|---|
| 28 |
# include "config.h" |
|---|
| 29 |
#endif |
|---|
| 30 |
|
|---|
| 31 |
#include <vlc_common.h> |
|---|
| 32 |
#include <vlc_demux.h> |
|---|
| 33 |
#include <vlc_interface.h> |
|---|
| 34 |
#include <vlc_charset.h> |
|---|
| 35 |
|
|---|
| 36 |
#include "playlist.h" |
|---|
| 37 |
|
|---|
| 38 |
#ifndef LONG_MAX |
|---|
| 39 |
# define LONG_MAX 2147483647L |
|---|
| 40 |
# define LONG_MIN (-LONG_MAX-1) |
|---|
| 41 |
#endif |
|---|
| 42 |
|
|---|
| 43 |
|
|---|
| 44 |
|
|---|
| 45 |
|
|---|
| 46 |
static int Demux( demux_t *p_demux); |
|---|
| 47 |
static int Control( demux_t *p_demux, int i_query, va_list args ); |
|---|
| 48 |
|
|---|
| 49 |
static int ParseLine( char *, char **, char ***, int *); |
|---|
| 50 |
|
|---|
| 51 |
|
|---|
| 52 |
|
|---|
| 53 |
|
|---|
| 54 |
int Import_DVB( vlc_object_t *p_this ) |
|---|
| 55 |
{ |
|---|
| 56 |
demux_t *p_demux = (demux_t *)p_this; |
|---|
| 57 |
const uint8_t *p_peek; |
|---|
| 58 |
int i_peek; |
|---|
| 59 |
bool b_valid = false; |
|---|
| 60 |
|
|---|
| 61 |
if( !demux_IsPathExtension( p_demux, ".conf" ) && !p_demux->b_force ) |
|---|
| 62 |
return VLC_EGENERIC; |
|---|
| 63 |
|
|---|
| 64 |
|
|---|
| 65 |
if( (i_peek = stream_Peek( p_demux->s, &p_peek, 1024 )) > 0 ) |
|---|
| 66 |
{ |
|---|
| 67 |
char psz_line[1024+1]; |
|---|
| 68 |
int i; |
|---|
| 69 |
|
|---|
| 70 |
for( i = 0; i < i_peek; i++ ) |
|---|
| 71 |
{ |
|---|
| 72 |
if( p_peek[i] == '\n' ) break; |
|---|
| 73 |
psz_line[i] = p_peek[i]; |
|---|
| 74 |
} |
|---|
| 75 |
psz_line[i] = 0; |
|---|
| 76 |
|
|---|
| 77 |
if( ParseLine( psz_line, 0, 0, 0 ) ) b_valid = true; |
|---|
| 78 |
} |
|---|
| 79 |
|
|---|
| 80 |
if( !b_valid ) return VLC_EGENERIC; |
|---|
| 81 |
|
|---|
| 82 |
msg_Dbg( p_demux, "found valid DVB conf playlist file"); |
|---|
| 83 |
p_demux->pf_control = Control; |
|---|
| 84 |
p_demux->pf_demux = Demux; |
|---|
| 85 |
|
|---|
| 86 |
return VLC_SUCCESS; |
|---|
| 87 |
} |
|---|
| 88 |
|
|---|
| 89 |
|
|---|
| 90 |
|
|---|
| 91 |
|
|---|
| 92 |
void Close_DVB( vlc_object_t *p_this ) |
|---|
| 93 |
{ |
|---|
| 94 |
VLC_UNUSED(p_this); |
|---|
| 95 |
} |
|---|
| 96 |
|
|---|
| 97 |
|
|---|
| 98 |
|
|---|
| 99 |
|
|---|
| 100 |
static int Demux( demux_t *p_demux ) |
|---|
| 101 |
{ |
|---|
| 102 |
char *psz_line; |
|---|
| 103 |
input_item_t *p_input; |
|---|
| 104 |
INIT_PLAYLIST_STUFF; |
|---|
| 105 |
|
|---|
| 106 |
while( (psz_line = stream_ReadLine( p_demux->s )) ) |
|---|
| 107 |
{ |
|---|
| 108 |
char **ppsz_options = NULL; |
|---|
| 109 |
int i, i_options = 0; |
|---|
| 110 |
char *psz_name = NULL; |
|---|
| 111 |
|
|---|
| 112 |
if( !ParseLine( psz_line, &psz_name, &ppsz_options, &i_options ) ) |
|---|
| 113 |
{ |
|---|
| 114 |
free( psz_line ); |
|---|
| 115 |
continue; |
|---|
| 116 |
} |
|---|
| 117 |
|
|---|
| 118 |
EnsureUTF8( psz_name ); |
|---|
| 119 |
|
|---|
| 120 |
p_input = input_item_NewExt( p_demux, "dvb://", psz_name, 0, NULL, -1 ); |
|---|
| 121 |
for( i = 0; i< i_options; i++ ) |
|---|
| 122 |
{ |
|---|
| 123 |
EnsureUTF8( ppsz_options[i] ); |
|---|
| 124 |
input_item_AddOption( p_input, ppsz_options[i] ); |
|---|
| 125 |
} |
|---|
| 126 |
input_item_AddSubItem( p_current_input, p_input ); |
|---|
| 127 |
vlc_gc_decref( p_input ); |
|---|
| 128 |
while( i_options-- ) free( ppsz_options[i_options] ); |
|---|
| 129 |
free( ppsz_options ); |
|---|
| 130 |
|
|---|
| 131 |
free( psz_line ); |
|---|
| 132 |
} |
|---|
| 133 |
|
|---|
| 134 |
HANDLE_PLAY_AND_RELEASE; |
|---|
| 135 |
return 0; |
|---|
| 136 |
} |
|---|
| 137 |
|
|---|
| 138 |
static const struct |
|---|
| 139 |
{ |
|---|
| 140 |
const char *psz_name; |
|---|
| 141 |
const char *psz_option; |
|---|
| 142 |
|
|---|
| 143 |
} dvb_options[] = |
|---|
| 144 |
{ |
|---|
| 145 |
{ "INVERSION_OFF", "dvb-inversion=0" }, |
|---|
| 146 |
{ "INVERSION_ON", "dvb-inversion=1" }, |
|---|
| 147 |
{ "INVERSION_AUTO", "dvb-inversion=2" }, |
|---|
| 148 |
|
|---|
| 149 |
{ "BANDWIDTH_AUTO", "dvb-bandwidth=0" }, |
|---|
| 150 |
{ "BANDWIDTH_6_MHZ", "dvb-bandwidth=6" }, |
|---|
| 151 |
{ "BANDWIDTH_7_MHZ", "dvb-bandwidth=7" }, |
|---|
| 152 |
{ "BANDWIDTH_8_MHZ", "dvb-bandwidth=8" }, |
|---|
| 153 |
|
|---|
| 154 |
{ "FEC_NONE", "dvb-fec=0" }, |
|---|
| 155 |
{ "FEC_1_2", "dvb-fec=1" }, |
|---|
| 156 |
{ "FEC_2_3", "dvb-fec=2" }, |
|---|
| 157 |
{ "FEC_3_4", "dvb-fec=3" }, |
|---|
| 158 |
{ "FEC_4_5", "dvb-fec=4" }, |
|---|
| 159 |
{ "FEC_5_6", "dvb-fec=5" }, |
|---|
| 160 |
{ "FEC_6_7", "dvb-fec=6" }, |
|---|
| 161 |
{ "FEC_7_8", "dvb-fec=7" }, |
|---|
| 162 |
{ "FEC_8_9", "dvb-fec=8" }, |
|---|
| 163 |
{ "FEC_AUTO", "dvb-fec=9" }, |
|---|
| 164 |
|
|---|
| 165 |
{ "GUARD_INTERVAL_AUTO", "dvb-guard=0" }, |
|---|
| 166 |
{ "GUARD_INTERVAL_1_4", "dvb-guard=4" }, |
|---|
| 167 |
{ "GUARD_INTERVAL_1_8", "dvb-guard=8" }, |
|---|
| 168 |
{ "GUARD_INTERVAL_1_16", "dvb-guard=16" }, |
|---|
| 169 |
{ "GUARD_INTERVAL_1_32", "dvb-guard=32" }, |
|---|
| 170 |
|
|---|
| 171 |
{ "HIERARCHY_NONE", "dvb-hierarchy=-1" }, |
|---|
| 172 |
{ "HIERARCHY_1", "dvb-hierarchy=1" }, |
|---|
| 173 |
{ "HIERARCHY_2", "dvb-hierarchy=2" }, |
|---|
| 174 |
{ "HIERARCHY_4", "dvb-hierarchy=4" }, |
|---|
| 175 |
|
|---|
| 176 |
{ "QPSK", "dvb-modulation=-1" }, |
|---|
| 177 |
{ "QAM_AUTO", "dvb-modulation=0" }, |
|---|
| 178 |
{ "QAM_16", "dvb-modulation=16" }, |
|---|
| 179 |
{ "QAM_32", "dvb-modulation=32" }, |
|---|
| 180 |
{ "QAM_64", "dvb-modulation=64" }, |
|---|
| 181 |
{ "QAM_128", "dvb-modulation=128" }, |
|---|
| 182 |
{ "QAM_256", "dvb-modulation=256" }, |
|---|
| 183 |
{ "8VSB", "dvb-modulation=8" }, |
|---|
| 184 |
{ "16VSB", "dvb-modulation=16" }, |
|---|
| 185 |
|
|---|
| 186 |
{ "TRANSMISSION_MODE_AUTO", "dvb-transmission=0" }, |
|---|
| 187 |
{ "TRANSMISSION_MODE_2K", "dvb-transmission=2" }, |
|---|
| 188 |
{ "TRANSMISSION_MODE_8K", "dvb-transmission=8" }, |
|---|
| 189 |
{ 0, 0 } |
|---|
| 190 |
|
|---|
| 191 |
}; |
|---|
| 192 |
|
|---|
| 193 |
static int ParseLine( char *psz_line, char **ppsz_name, |
|---|
| 194 |
char ***pppsz_options, int *pi_options ) |
|---|
| 195 |
{ |
|---|
| 196 |
char *psz_name = 0, *psz_parse = psz_line; |
|---|
| 197 |
int i_count = 0, i_program = 0, i_frequency = 0; |
|---|
| 198 |
bool b_valid = false; |
|---|
| 199 |
|
|---|
| 200 |
if( pppsz_options ) *pppsz_options = 0; |
|---|
| 201 |
if( pi_options ) *pi_options = 0; |
|---|
| 202 |
if( ppsz_name ) *ppsz_name = 0; |
|---|
| 203 |
|
|---|
| 204 |
|
|---|
| 205 |
while( *psz_parse == ' ' || *psz_parse == '\t' || |
|---|
| 206 |
*psz_parse == '\n' || *psz_parse == '\r' ) psz_parse++; |
|---|
| 207 |
|
|---|
| 208 |
|
|---|
| 209 |
if( *psz_parse == '#' ) return false; |
|---|
| 210 |
|
|---|
| 211 |
while( psz_parse ) |
|---|
| 212 |
{ |
|---|
| 213 |
const char *psz_option = 0; |
|---|
| 214 |
char *psz_end = strchr( psz_parse, ':' ); |
|---|
| 215 |
if( psz_end ) { *psz_end = 0; psz_end++; } |
|---|
| 216 |
|
|---|
| 217 |
if( i_count == 0 ) |
|---|
| 218 |
{ |
|---|
| 219 |
|
|---|
| 220 |
psz_name = psz_parse; |
|---|
| 221 |
} |
|---|
| 222 |
else if( i_count == 1 ) |
|---|
| 223 |
{ |
|---|
| 224 |
|
|---|
| 225 |
char *psz_end; |
|---|
| 226 |
long i_value; |
|---|
| 227 |
|
|---|
| 228 |
i_value = strtol( psz_parse, &psz_end, 10 ); |
|---|
| 229 |
if( psz_end == psz_parse || |
|---|
| 230 |
i_value == LONG_MAX || i_value == LONG_MIN ) break; |
|---|
| 231 |
|
|---|
| 232 |
i_frequency = i_value; |
|---|
| 233 |
} |
|---|
| 234 |
else |
|---|
| 235 |
{ |
|---|
| 236 |
int i; |
|---|
| 237 |
|
|---|
| 238 |
|
|---|
| 239 |
for( i = 0; dvb_options[i].psz_name; i++ ) |
|---|
| 240 |
{ |
|---|
| 241 |
if( !strcmp( psz_parse, dvb_options[i].psz_name ) ) |
|---|
| 242 |
{ |
|---|
| 243 |
psz_option = dvb_options[i].psz_option; |
|---|
| 244 |
|
|---|
| 245 |
|
|---|
| 246 |
|
|---|
| 247 |
b_valid = true; |
|---|
| 248 |
break; |
|---|
| 249 |
} |
|---|
| 250 |
} |
|---|
| 251 |
|
|---|
| 252 |
if( !psz_option ) |
|---|
| 253 |
{ |
|---|
| 254 |
|
|---|
| 255 |
char *psz_end; |
|---|
| 256 |
long i_value; |
|---|
| 257 |
|
|---|
| 258 |
i_value = strtol( psz_parse, &psz_end, 10 ); |
|---|
| 259 |
if( psz_end != psz_parse && |
|---|
| 260 |
i_value != LONG_MAX && i_value != LONG_MIN ) |
|---|
| 261 |
{ |
|---|
| 262 |
i_program = i_value; |
|---|
| 263 |
} |
|---|
| 264 |
} |
|---|
| 265 |
} |
|---|
| 266 |
|
|---|
| 267 |
if( psz_option && pppsz_options && pi_options ) |
|---|
| 268 |
{ |
|---|
| 269 |
char *psz_dup = strdup( psz_option ); |
|---|
| 270 |
if (psz_dup != NULL) |
|---|
| 271 |
INSERT_ELEM( *pppsz_options, (*pi_options), (*pi_options), |
|---|
| 272 |
psz_dup ); |
|---|
| 273 |
} |
|---|
| 274 |
|
|---|
| 275 |
psz_parse = psz_end; |
|---|
| 276 |
i_count++; |
|---|
| 277 |
} |
|---|
| 278 |
|
|---|
| 279 |
if( !b_valid && pppsz_options && pi_options ) |
|---|
| 280 |
{ |
|---|
| 281 |
|
|---|
| 282 |
while( (*pi_options)-- ) free( (*pppsz_options)[*pi_options] ); |
|---|
| 283 |
free( *pppsz_options ); |
|---|
| 284 |
*pppsz_options = 0; *pi_options = 0; |
|---|
| 285 |
} |
|---|
| 286 |
|
|---|
| 287 |
if( i_program && pppsz_options && pi_options ) |
|---|
| 288 |
{ |
|---|
| 289 |
char *psz_option; |
|---|
| 290 |
|
|---|
| 291 |
if( asprintf( &psz_option, "program=%i", i_program ) != -1 ) |
|---|
| 292 |
INSERT_ELEM( *pppsz_options, (*pi_options), (*pi_options), |
|---|
| 293 |
psz_option ); |
|---|
| 294 |
} |
|---|
| 295 |
if( i_frequency && pppsz_options && pi_options ) |
|---|
| 296 |
{ |
|---|
| 297 |
char *psz_option; |
|---|
| 298 |
|
|---|
| 299 |
if( asprintf( &psz_option, "dvb-frequency=%i", i_frequency ) != -1 ) |
|---|
| 300 |
INSERT_ELEM( *pppsz_options, (*pi_options), (*pi_options), |
|---|
| 301 |
psz_option ); |
|---|
| 302 |
} |
|---|
| 303 |
if( ppsz_name && psz_name ) *ppsz_name = strdup( psz_name ); |
|---|
| 304 |
|
|---|
| 305 |
return b_valid; |
|---|
| 306 |
} |
|---|
| 307 |
|
|---|
| 308 |
static int Control( demux_t *p_demux, int i_query, va_list args ) |
|---|
| 309 |
{ |
|---|
| 310 |
VLC_UNUSED(p_demux); VLC_UNUSED(i_query); VLC_UNUSED(args); |
|---|
| 311 |
return VLC_EGENERIC; |
|---|
| 312 |
} |
|---|