[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:33:57 CEST 2008


Hello,
On Sat, May 10, 2008 at 08:30:45PM +0200, Reimar Döffinger wrote:
> 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?

Sorry, this one is against SVN.

Greetings,
Reimar Döffinger
-------------- next part --------------
Index: libmpdemux/muxer_lavf.c
===================================================================
--- libmpdemux/muxer_lavf.c	(revision 26722)
+++ 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,38 +64,15 @@
 	{NULL, NULL, 0, 0, 0, 0, NULL}
 };
 
-static muxer_t *priv_data; // This should be transmitted to mp_open() through the filename
-                           // when thread saftey is needed but mplayer == no threads and
-                           // especially not multiple muxers being inited at once so theres
-                           // no point in the extra complexity, a static is simpler.
-
-static int mp_open(URLContext *h, const char *filename, int flags)
+static int mp_write(void *opaque, uint8_t *buf, int size)
 {
-        h->priv_data= priv_data;
-	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);
@@ -114,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;
@@ -317,7 +287,7 @@
 		av_freep(&(priv->oc->streams[i]));
 	}
 
-	url_fclose(priv->oc->pb);
+	av_freep(&priv->oc->pb);
 
 	av_free(priv->oc);
 }
@@ -334,7 +304,6 @@
 {
 	muxer_priv_t *priv;
 	AVOutputFormat *fmt = NULL;
-	char mp_filename[256] = "menc://stream.dummy";
 
 	av_register_all();
 
@@ -392,14 +361,8 @@
             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);
 
-        priv_data= muxer;
-	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);
 	
 	muxer->priv = (void *) priv;
 	muxer->cont_new_stream = &lavf_new_stream;


More information about the MPlayer-dev-eng mailing list