[MPlayer-dev-eng] [PATCH] use av_alloc_put_byte in muxer_lavf.c

Reimar Döffinger Reimar.Doeffinger at stud.uni-karlsruhe.de
Sat May 10 20:30:45 CEST 2008


Hello,
in a quick test attached patch seems to work.
Normally pb->is_streamed should be set if necessary, but it seems the only
output MPlayer supports is to file anyway and there is not really any
good way to find out if an output stream is streamed or not?

Greetings,
Reimar Döffinger
-------------- next part --------------
Index: libmpdemux/muxer_lavf.c
===================================================================
--- libmpdemux/muxer_lavf.c	(revision 26712)
+++ libmpdemux/muxer_lavf.c	(working copy)
@@ -31,6 +31,8 @@
 extern char *info_sourceform;
 extern char *info_comment;
 
+#define BIO_BUFFER_SIZE 32768
+
 typedef struct {
 	//AVInputFormat *avif;
 	AVFormatContext *oc;
@@ -38,6 +40,7 @@
 	int audio_streams;
 	int video_streams;
 	int64_t last_pts;
+	uint8_t buffer[BIO_BUFFER_SIZE];
 } muxer_priv_t;
 
 typedef struct {
@@ -61,32 +64,15 @@
 	{NULL, NULL, 0, 0, 0, 0, NULL}
 };
 
-static int mp_open(URLContext *h, const char *filename, int flags)
+static int mp_write(void *opaque, uint8_t *buf, int size)
 {
-	return 0;
-}
-
-static int mp_close(URLContext *h)
-{
-	return 0;
-}
-
-
-static int mp_read(URLContext *h, unsigned char *buf, int size)
-{
-	mp_msg(MSGT_MUXER, MSGL_WARN, "READ %d\n", size);
-	return -1;
-}
-
-static int mp_write(URLContext *h, unsigned char *buf, int size)
-{
-	muxer_t *muxer = (muxer_t*)h->priv_data;
+	muxer_t *muxer = opaque;
 	return stream_write_buffer(muxer->stream, buf, size);
 }
 
-static offset_t mp_seek(URLContext *h, offset_t pos, int whence)
+static offset_t mp_seek(void *opaque, offset_t pos, int whence)
 {
-	muxer_t *muxer = (muxer_t*)h->priv_data;
+	muxer_t *muxer = opaque;
 	if(whence == SEEK_CUR)
 	{
 		off_t cur = stream_tell(muxer->stream);
@@ -108,16 +94,6 @@
 }
 
 
-static URLProtocol mp_protocol = {
-	"menc",
-	mp_open,
-	mp_read,
-	mp_write,
-	mp_seek,
-	mp_close,
-	NULL
-};
-
 static muxer_stream_t* lavf_new_stream(muxer_t *muxer, int type)
 {
 	muxer_priv_t *priv = muxer->priv;
@@ -311,7 +287,7 @@
 		av_freep(&(priv->oc->streams[i]));
 	}
 
-	url_fclose(priv->oc->pb);
+	av_freep(&priv->oc->pb);
 
 	av_free(priv->oc);
 }
@@ -328,7 +304,6 @@
 {
 	muxer_priv_t *priv;
 	AVOutputFormat *fmt = NULL;
-	char mp_filename[256] = "menc://stream.dummy";
 
 	av_register_all();
 
@@ -386,16 +361,9 @@
             av_strlcpy(priv->oc->copyright, info_copyright, sizeof(priv->oc->copyright));
         if (info_comment)
             av_strlcpy(priv->oc->comment  , info_comment,   sizeof(priv->oc->comment  ));
-	register_protocol(&mp_protocol);
 
-	if(url_fopen(&priv->oc->pb, mp_filename, URL_WRONLY))
-	{
-		mp_msg(MSGT_MUXER, MSGL_FATAL, "Could not open outfile\n");
-		goto fail;
-        }
+	priv->oc->pb = av_alloc_put_byte(priv->buffer, BIO_BUFFER_SIZE, 1, muxer, NULL, mp_write, mp_seek);
 	
-	((URLContext*)(priv->oc->pb->opaque))->priv_data= muxer;
-	
 	muxer->priv = (void *) priv;
 	muxer->cont_new_stream = &lavf_new_stream;
 	muxer->cont_write_chunk = &write_chunk;


More information about the MPlayer-dev-eng mailing list