comparison libmpdemux/demux_lavf.c @ 24757:cc80a9169d90

Add -lavfdopts cryptokey
author reimar
date Sun, 14 Oct 2007 12:11:28 +0000
parents f6cf2c01315d
children fbf46414bb48
comparison
equal deleted inserted replaced
24756:4858c996a5c9 24757:cc80a9169d90
47 47
48 extern char *audio_lang; 48 extern char *audio_lang;
49 static unsigned int opt_probesize = 0; 49 static unsigned int opt_probesize = 0;
50 static unsigned int opt_analyzeduration = 0; 50 static unsigned int opt_analyzeduration = 0;
51 static char *opt_format; 51 static char *opt_format;
52 static char *opt_cryptokey;
52 53
53 m_option_t lavfdopts_conf[] = { 54 m_option_t lavfdopts_conf[] = {
54 {"probesize", &(opt_probesize), CONF_TYPE_INT, CONF_RANGE, 32, INT_MAX, NULL}, 55 {"probesize", &(opt_probesize), CONF_TYPE_INT, CONF_RANGE, 32, INT_MAX, NULL},
55 {"format", &(opt_format), CONF_TYPE_STRING, 0, 0, 0, NULL}, 56 {"format", &(opt_format), CONF_TYPE_STRING, 0, 0, 0, NULL},
56 {"analyzeduration", &(opt_analyzeduration), CONF_TYPE_INT, CONF_RANGE, 0, INT_MAX, NULL}, 57 {"analyzeduration", &(opt_analyzeduration), CONF_TYPE_INT, CONF_RANGE, 0, INT_MAX, NULL},
58 {"cryptokey", &(opt_cryptokey), CONF_TYPE_STRING, 0, 0, 0, NULL},
57 {NULL, NULL, 0, 0, 0, 0, NULL} 59 {NULL, NULL, 0, 0, 0, 0, NULL}
58 }; 60 };
59 61
60 62
61 typedef struct lavf_priv_t{ 63 typedef struct lavf_priv_t{
248 } 250 }
249 } 251 }
250 return 0; 252 return 0;
251 } 253 }
252 254
255 static uint8_t char2int(char c) {
256 if (c >= '0' && c <= '9') return c - '0';
257 if (c >= 'a' && c <= 'f') return c - 'a' + 10;
258 if (c >= 'A' && c <= 'F') return c - 'A' + 10;
259 return 0;
260 }
261
262 static void parse_cryptokey(AVFormatContext *avfc, const char *str) {
263 int len = strlen(str) / 2;
264 uint8_t *key = av_mallocz(len);
265 int i;
266 avfc->keylen = len;
267 avfc->key = key;
268 for (i = 0; i < len; i++, str += 2)
269 *key++ = (char2int(str[0]) << 4) | char2int(str[1]);
270 }
271
253 static demuxer_t* demux_open_lavf(demuxer_t *demuxer){ 272 static demuxer_t* demux_open_lavf(demuxer_t *demuxer){
254 AVFormatContext *avfc; 273 AVFormatContext *avfc;
255 AVFormatParameters ap; 274 AVFormatParameters ap;
256 const AVOption *opt; 275 const AVOption *opt;
257 lavf_priv_t *priv= demuxer->priv; 276 lavf_priv_t *priv= demuxer->priv;
264 283
265 register_protocol(&mp_protocol); 284 register_protocol(&mp_protocol);
266 285
267 avfc = av_alloc_format_context(); 286 avfc = av_alloc_format_context();
268 287
288 if (opt_cryptokey)
289 parse_cryptokey(avfc, opt_cryptokey);
269 if (correct_pts) 290 if (correct_pts)
270 avfc->flags |= AVFMT_FLAG_GENPTS; 291 avfc->flags |= AVFMT_FLAG_GENPTS;
271 if (index_mode == 0) 292 if (index_mode == 0)
272 avfc->flags |= AVFMT_FLAG_IGNIDX; 293 avfc->flags |= AVFMT_FLAG_IGNIDX;
273 294
666 { 687 {
667 lavf_priv_t* priv = demuxer->priv; 688 lavf_priv_t* priv = demuxer->priv;
668 if (priv){ 689 if (priv){
669 if(priv->avfc) 690 if(priv->avfc)
670 { 691 {
692 av_freep(&priv->avfc->key);
671 av_close_input_file(priv->avfc); priv->avfc= NULL; 693 av_close_input_file(priv->avfc); priv->avfc= NULL;
672 } 694 }
673 free(priv); demuxer->priv= NULL; 695 free(priv); demuxer->priv= NULL;
674 } 696 }
675 } 697 }