[MPlayer-dev-eng] [PATCH] set is_streamed correctly in lavf URLContext
Reimar Döffinger
Reimar.Doeffinger at stud.uni-karlsruhe.de
Sat Dec 15 17:35:19 CET 2007
On Sat, Dec 15, 2007 at 05:33:05PM +0100, Reimar Döffinger wrote:
> On Sat, Dec 15, 2007 at 04:30:10PM +0100, Reimar Döffinger wrote:
> > I know it looks a bit hackish by modifying the file name.
> > A different way I just realized is of course having two different
> > protocols (only differing in the open function I guess).
> > Any opinions or better suggestions?
>
> Actually this seems much better to me, it gets rid of the whole
> URLProtocol mess.
> The only problem is, it leaks memory since I could not find a function
> to just free the AVFormatContext, the currently used function can not
> be used since it wants to use url_fclose, which is only valid for
> URLProtocol stuff (I sent a mail about this to ffmpeg-dev)...
...
-------------- next part --------------
Index: libmpdemux/demux_lavf.c
===================================================================
--- libmpdemux/demux_lavf.c (revision 25408)
+++ libmpdemux/demux_lavf.c (working copy)
@@ -60,11 +60,13 @@
{NULL, NULL, 0, 0, 0, 0, NULL}
};
+#define BIO_BUFFER_SIZE 32768
typedef struct lavf_priv_t{
AVInputFormat *avif;
AVFormatContext *avfc;
- ByteIOContext *pb;
+ ByteIOContext pb;
+ uint8_t buffer[BIO_BUFFER_SIZE];
int audio_streams;
int video_streams;
int sub_streams;
@@ -126,30 +128,19 @@
const struct AVCodecTag *mp_bmp_taglists[] = {codec_bmp_tags, mp_bmp_tags, 0};
-static int mp_open(URLContext *h, const char *filename, int flags){
- return 0;
-}
-
-static int mp_read(URLContext *h, unsigned char *buf, int size){
- stream_t *stream = (stream_t*)h->priv_data;
+static int mp_read(stream_t *stream, unsigned char *buf, int size){
int ret;
if(stream_eof(stream)) //needed?
return -1;
ret=stream_read(stream, buf, size);
- mp_msg(MSGT_HEADER,MSGL_DBG2,"%d=mp_read(%p, %p, %d), eof:%d\n", ret, h, buf, size, stream->eof);
+ mp_msg(MSGT_HEADER,MSGL_DBG2,"%d=mp_read(%p, %p, %d), eof:%d\n", ret, stream, buf, size, stream->eof);
return ret;
}
-static int mp_write(URLContext *h, unsigned char *buf, int size){
- return -1;
-}
-
-static offset_t mp_seek(URLContext *h, offset_t pos, int whence){
- stream_t *stream = (stream_t*)h->priv_data;
-
- mp_msg(MSGT_HEADER,MSGL_DBG2,"mp_seek(%p, %d, %d)\n", h, (int)pos, whence);
+static offset_t mp_seek(stream_t *stream, offset_t pos, int whence){
+ mp_msg(MSGT_HEADER,MSGL_DBG2,"mp_seek(%p, %d, %d)\n", stream, (int)pos, whence);
if(whence == SEEK_CUR)
pos +=stream_tell(stream);
else if(whence == SEEK_END && stream->end_pos > 0)
@@ -171,19 +162,6 @@
return pos - stream->start_pos;
}
-static int mp_close(URLContext *h){
- return 0;
-}
-
-static URLProtocol mp_protocol = {
- "mp",
- mp_open,
- mp_read,
- mp_write,
- mp_seek,
- mp_close,
-};
-
static void list_formats(void) {
AVInputFormat *fmt;
mp_msg(MSGT_DEMUX, MSGL_INFO, "Available lavf input formats:\n");
@@ -443,8 +421,6 @@
stream_seek(demuxer->stream, 0);
- register_protocol(&mp_protocol);
-
avfc = av_alloc_format_context();
if (opt_cryptokey)
@@ -469,11 +445,11 @@
else
strncpy(mp_filename + 3, "foobar.dummy", sizeof(mp_filename)-3);
- url_fopen(&priv->pb, mp_filename, URL_RDONLY);
+ init_put_byte(&priv->pb, priv->buffer, BIO_BUFFER_SIZE, 0, demuxer->stream,
+ mp_read, NULL, mp_seek);
+ priv->pb.is_streamed = !demuxer->stream->end_pos;
- ((URLContext*)(priv->pb->opaque))->priv_data= demuxer->stream;
-
- if(av_open_input_stream(&avfc, priv->pb, mp_filename, priv->avif, &ap)<0){
+ if(av_open_input_stream(&avfc, &priv->pb, mp_filename, priv->avif, &ap)<0){
mp_msg(MSGT_HEADER,MSGL_ERR,"LAVF_header: av_open_input_stream() failed\n");
return NULL;
}
@@ -787,7 +773,6 @@
if(priv->avfc)
{
av_freep(&priv->avfc->key);
- av_close_input_file(priv->avfc); priv->avfc= NULL;
}
free(priv); demuxer->priv= NULL;
}
More information about the MPlayer-dev-eng
mailing list