comparison libmpdemux/demux_lavf.c @ 25471:5075d5ff1da8

Get rid of URLProtocol mess (especially problematic since it made use of a non-constant global variable) and use ByteIOContext directly.
author reimar
date Sat, 22 Dec 2007 16:22:54 +0000
parents bb7c65f2a289
children ace1b77375bd
comparison
equal deleted inserted replaced
25470:e71edb23a650 25471:5075d5ff1da8
58 {"analyzeduration", &(opt_analyzeduration), CONF_TYPE_INT, CONF_RANGE, 0, INT_MAX, NULL}, 58 {"analyzeduration", &(opt_analyzeduration), CONF_TYPE_INT, CONF_RANGE, 0, INT_MAX, NULL},
59 {"cryptokey", &(opt_cryptokey), CONF_TYPE_STRING, 0, 0, 0, NULL}, 59 {"cryptokey", &(opt_cryptokey), CONF_TYPE_STRING, 0, 0, 0, NULL},
60 {NULL, NULL, 0, 0, 0, 0, NULL} 60 {NULL, NULL, 0, 0, 0, 0, NULL}
61 }; 61 };
62 62
63 #define BIO_BUFFER_SIZE 32768
63 64
64 typedef struct lavf_priv_t{ 65 typedef struct lavf_priv_t{
65 AVInputFormat *avif; 66 AVInputFormat *avif;
66 AVFormatContext *avfc; 67 AVFormatContext *avfc;
67 ByteIOContext *pb; 68 ByteIOContext *pb;
69 uint8_t buffer[BIO_BUFFER_SIZE];
68 int audio_streams; 70 int audio_streams;
69 int video_streams; 71 int video_streams;
70 int sub_streams; 72 int sub_streams;
71 int64_t last_pts; 73 int64_t last_pts;
72 int astreams[MAX_A_STREAMS]; 74 int astreams[MAX_A_STREAMS];
124 { 0, 0 }, 126 { 0, 0 },
125 }; 127 };
126 128
127 const struct AVCodecTag *mp_bmp_taglists[] = {codec_bmp_tags, mp_bmp_tags, 0}; 129 const struct AVCodecTag *mp_bmp_taglists[] = {codec_bmp_tags, mp_bmp_tags, 0};
128 130
129 static int mp_open(URLContext *h, const char *filename, int flags){ 131 static int mp_read(void *opaque, uint8_t *buf, int size) {
130 return 0; 132 stream_t *stream = opaque;
131 }
132
133 static int mp_read(URLContext *h, unsigned char *buf, int size){
134 stream_t *stream = (stream_t*)h->priv_data;
135 int ret; 133 int ret;
136 134
137 if(stream_eof(stream)) //needed? 135 if(stream_eof(stream)) //needed?
138 return -1; 136 return -1;
139 ret=stream_read(stream, buf, size); 137 ret=stream_read(stream, buf, size);
140 138
141 mp_msg(MSGT_HEADER,MSGL_DBG2,"%d=mp_read(%p, %p, %d), eof:%d\n", ret, h, buf, size, stream->eof); 139 mp_msg(MSGT_HEADER,MSGL_DBG2,"%d=mp_read(%p, %p, %d), eof:%d\n", ret, stream, buf, size, stream->eof);
142 return ret; 140 return ret;
143 } 141 }
144 142
145 static int mp_write(URLContext *h, unsigned char *buf, int size){ 143 static offset_t mp_seek(void *opaque, offset_t pos, int whence) {
146 return -1; 144 stream_t *stream = opaque;
147 } 145 mp_msg(MSGT_HEADER,MSGL_DBG2,"mp_seek(%p, %d, %d)\n", stream, (int)pos, whence);
148
149 static offset_t mp_seek(URLContext *h, offset_t pos, int whence){
150 stream_t *stream = (stream_t*)h->priv_data;
151
152 mp_msg(MSGT_HEADER,MSGL_DBG2,"mp_seek(%p, %d, %d)\n", h, (int)pos, whence);
153 if(whence == SEEK_CUR) 146 if(whence == SEEK_CUR)
154 pos +=stream_tell(stream); 147 pos +=stream_tell(stream);
155 else if(whence == SEEK_END && stream->end_pos > 0) 148 else if(whence == SEEK_END && stream->end_pos > 0)
156 pos += stream->end_pos; 149 pos += stream->end_pos;
157 else if(whence == SEEK_SET) 150 else if(whence == SEEK_SET)
168 if(stream_seek(stream, pos)==0) 161 if(stream_seek(stream, pos)==0)
169 return -1; 162 return -1;
170 163
171 return pos - stream->start_pos; 164 return pos - stream->start_pos;
172 } 165 }
173
174 static int mp_close(URLContext *h){
175 return 0;
176 }
177
178 static URLProtocol mp_protocol = {
179 "mp",
180 mp_open,
181 mp_read,
182 mp_write,
183 mp_seek,
184 mp_close,
185 };
186 166
187 static void list_formats(void) { 167 static void list_formats(void) {
188 AVInputFormat *fmt; 168 AVInputFormat *fmt;
189 mp_msg(MSGT_DEMUX, MSGL_INFO, "Available lavf input formats:\n"); 169 mp_msg(MSGT_DEMUX, MSGL_INFO, "Available lavf input formats:\n");
190 for (fmt = first_iformat; fmt; fmt = fmt->next) 170 for (fmt = first_iformat; fmt; fmt = fmt->next)
441 421
442 memset(&ap, 0, sizeof(AVFormatParameters)); 422 memset(&ap, 0, sizeof(AVFormatParameters));
443 423
444 stream_seek(demuxer->stream, 0); 424 stream_seek(demuxer->stream, 0);
445 425
446 register_protocol(&mp_protocol);
447
448 avfc = av_alloc_format_context(); 426 avfc = av_alloc_format_context();
449 427
450 if (opt_cryptokey) 428 if (opt_cryptokey)
451 parse_cryptokey(avfc, opt_cryptokey); 429 parse_cryptokey(avfc, opt_cryptokey);
452 if (correct_pts) 430 if (correct_pts)
467 if(demuxer->stream->url) 445 if(demuxer->stream->url)
468 strncpy(mp_filename + 3, demuxer->stream->url, sizeof(mp_filename)-3); 446 strncpy(mp_filename + 3, demuxer->stream->url, sizeof(mp_filename)-3);
469 else 447 else
470 strncpy(mp_filename + 3, "foobar.dummy", sizeof(mp_filename)-3); 448 strncpy(mp_filename + 3, "foobar.dummy", sizeof(mp_filename)-3);
471 449
472 url_fopen(&priv->pb, mp_filename, URL_RDONLY); 450 priv->pb = alloc_put_byte(priv->buffer, BIO_BUFFER_SIZE, 0,
451 demuxer->stream, mp_read, NULL, mp_seek);
473 452
474 ((URLContext*)(priv->pb->opaque))->priv_data= demuxer->stream;
475
476 if(av_open_input_stream(&avfc, priv->pb, mp_filename, priv->avif, &ap)<0){ 453 if(av_open_input_stream(&avfc, priv->pb, mp_filename, priv->avif, &ap)<0){
477 mp_msg(MSGT_HEADER,MSGL_ERR,"LAVF_header: av_open_input_stream() failed\n"); 454 mp_msg(MSGT_HEADER,MSGL_ERR,"LAVF_header: av_open_input_stream() failed\n");
478 return NULL; 455 return NULL;
479 } 456 }
480 457
785 lavf_priv_t* priv = demuxer->priv; 762 lavf_priv_t* priv = demuxer->priv;
786 if (priv){ 763 if (priv){
787 if(priv->avfc) 764 if(priv->avfc)
788 { 765 {
789 av_freep(&priv->avfc->key); 766 av_freep(&priv->avfc->key);
790 av_close_input_file(priv->avfc); priv->avfc= NULL; 767 av_close_input_stream(priv->avfc);
791 } 768 }
769 av_freep(&priv->pb);
792 free(priv); demuxer->priv= NULL; 770 free(priv); demuxer->priv= NULL;
793 } 771 }
794 } 772 }
795 773
796 774