1
0
mirror of https://github.com/mpv-player/mpv synced 2025-01-20 06:11:10 +00:00

Use av_alloc_put_byte instead of custom protocol.

This needs less code and less hacks.


git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@26848 b3059339-0415-0410-9bf9-f77b7e298cf2
This commit is contained in:
reimar 2008-05-21 18:21:05 +00:00
parent a248cd8b68
commit 2bdedd33ed

View File

@ -32,6 +32,8 @@ extern char *info_copyright;
extern char *info_sourceform; extern char *info_sourceform;
extern char *info_comment; extern char *info_comment;
#define BIO_BUFFER_SIZE 32768
typedef struct { typedef struct {
//AVInputFormat *avif; //AVInputFormat *avif;
AVFormatContext *oc; AVFormatContext *oc;
@ -39,6 +41,7 @@ typedef struct {
int audio_streams; int audio_streams;
int video_streams; int video_streams;
int64_t last_pts; int64_t last_pts;
uint8_t buffer[BIO_BUFFER_SIZE];
} muxer_priv_t; } muxer_priv_t;
typedef struct { typedef struct {
@ -64,39 +67,15 @@ m_option_t lavfopts_conf[] = {
{NULL, NULL, 0, 0, 0, 0, NULL} {NULL, NULL, 0, 0, 0, 0, NULL}
}; };
/* This should be transmitted to mp_open() through the filename when static int mp_write(void *opaque, uint8_t *buf, int size)
* thread safety is needed but MPlayer == no threads and especially
* not multiple muxers being initialized at once so there is no
* point in the extra complexity, a static is simpler. */
static muxer_t *priv_data;
static int mp_open(URLContext *h, const char *filename, int flags)
{ {
h->priv_data= priv_data; muxer_t *muxer = opaque;
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;
return stream_write_buffer(muxer->stream, buf, size); 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) if(whence == SEEK_CUR)
{ {
off_t cur = stream_tell(muxer->stream); off_t cur = stream_tell(muxer->stream);
@ -118,16 +97,6 @@ static offset_t mp_seek(URLContext *h, offset_t pos, int whence)
} }
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) static muxer_stream_t* lavf_new_stream(muxer_t *muxer, int type)
{ {
muxer_priv_t *priv = muxer->priv; muxer_priv_t *priv = muxer->priv;
@ -321,7 +290,7 @@ static void write_trailer(muxer_t *muxer)
av_freep(&(priv->oc->streams[i])); av_freep(&(priv->oc->streams[i]));
} }
url_fclose(priv->oc->pb); av_freep(&priv->oc->pb);
av_free(priv->oc); av_free(priv->oc);
} }
@ -338,7 +307,6 @@ int muxer_init_muxer_lavf(muxer_t *muxer)
{ {
muxer_priv_t *priv; muxer_priv_t *priv;
AVOutputFormat *fmt = NULL; AVOutputFormat *fmt = NULL;
char mp_filename[256] = "menc://stream.dummy";
av_register_all(); av_register_all();
@ -404,14 +372,9 @@ int muxer_init_muxer_lavf(muxer_t *muxer)
} }
} }
register_protocol(&mp_protocol); 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_data= muxer; priv->oc->pb->is_streamed = 1;
if(url_fopen(&priv->oc->pb, mp_filename, URL_WRONLY))
{
mp_msg(MSGT_MUXER, MSGL_FATAL, "Could not open outfile.\n");
goto fail;
}
muxer->priv = (void *) priv; muxer->priv = (void *) priv;
muxer->cont_new_stream = &lavf_new_stream; muxer->cont_new_stream = &lavf_new_stream;