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

Reimar Döffinger Reimar.Doeffinger at stud.uni-karlsruhe.de
Mon May 12 10:44:52 CEST 2008


On Mon, May 12, 2008 at 04:11:54AM +0200, Michael Niedermayer wrote:
> > and there is not really any
> > good way to find out if an output stream is streamed or not?
> 
> try to seek ...

I wasn't paying enough attention, there actually already is everything
we need...
At least for stdout it should be enough, and that "try to seek" hack IMO
should better be done in the stream layer if necessary (it already is
done there).

Greetings,
Reimar Döffinger
-------------- next part --------------
Index: libmpdemux/muxer_lavf.c
===================================================================
--- libmpdemux/muxer_lavf.c	(revision 26730)
+++ libmpdemux/muxer_lavf.c	(working copy)
@@ -32,6 +32,8 @@
 extern char *info_sourceform;
 extern char *info_comment;
 
+#define BIO_BUFFER_SIZE 32768
+
 typedef struct {
 	//AVInputFormat *avif;
 	AVFormatContext *oc;
@@ -39,6 +41,7 @@
 	int audio_streams;
 	int video_streams;
 	int64_t last_pts;
+	uint8_t buffer[BIO_BUFFER_SIZE];
 } muxer_priv_t;
 
 typedef struct {
@@ -64,38 +67,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);
@@ -117,16 +97,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;
@@ -320,7 +290,7 @@
 		av_freep(&(priv->oc->streams[i]));
 	}
 
-	url_fclose(priv->oc->pb);
+	av_freep(&priv->oc->pb);
 
 	av_free(priv->oc);
 }
@@ -337,7 +307,6 @@
 {
 	muxer_priv_t *priv;
 	AVOutputFormat *fmt = NULL;
-	char mp_filename[256] = "menc://stream.dummy";
 
 	av_register_all();
 
@@ -403,14 +372,9 @@
             }
         }
 
-	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);
+	if ((muxer->stream->flags & STREAM_SEEK) != STREAM_SEEK)
+            priv->oc->pb->is_streamed = 1;
 	
 	muxer->priv = (void *) priv;
 	muxer->cont_new_stream = &lavf_new_stream;


More information about the MPlayer-dev-eng mailing list