1
0
mirror of https://github.com/mpv-player/mpv synced 2024-12-26 17:12:36 +00:00

Cleanup of the muxer API, func parameters muxer & muxer_f eliminated.

patch by Andriy N. Gritsenko <andrej@lucky.net>


git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@9008 b3059339-0415-0410-9bf9-f77b7e298cf2
This commit is contained in:
arpi 2003-01-19 00:33:11 +00:00
parent 970435ce12
commit 7a7d2cdd24
4 changed files with 35 additions and 21 deletions

View File

@ -14,9 +14,10 @@
#include "muxer.h"
muxer_t* muxer_new_muxer(int type){
muxer_t *muxer_new_muxer(int type,FILE *f){
muxer_t* muxer=malloc(sizeof(muxer_t));
memset(muxer,0,sizeof(muxer_t));
muxer->file = f;
switch (type) {
case MUXER_TYPE_MPEG:
muxer_init_muxer_mpeg(muxer);

View File

@ -34,6 +34,8 @@ typedef struct {
// mpeg specific:
unsigned int gop_start; // frame number of this GOP start
size_t ipb[3]; // sizes of I/P/B frames
// muxer of that stream
struct muxer_t *muxer;
} muxer_stream_t;
typedef struct {
@ -57,17 +59,18 @@ typedef struct muxer_t{
//int num_streams;
muxer_stream_t* def_v; // default video stream (for general headers)
muxer_stream_t* streams[MUXER_MAX_STREAMS];
void (*cont_write_chunk)(struct muxer_t *,muxer_stream_t *,FILE *,size_t,unsigned int);
void (*cont_write_header)(struct muxer_t *,FILE *);
void (*cont_write_index)(struct muxer_t *,FILE *);
void (*cont_write_chunk)(muxer_stream_t *,size_t,unsigned int);
void (*cont_write_header)(struct muxer_t *);
void (*cont_write_index)(struct muxer_t *);
muxer_stream_t* (*cont_new_stream)(struct muxer_t *,int);
FILE* file;
} muxer_t;
muxer_t* muxer_new_muxer(int type);
muxer_t *muxer_new_muxer(int type,FILE *);
#define muxer_new_stream(muxer,a) muxer->cont_new_stream(muxer,a)
#define muxer_write_chunk(muxer,a,b,c,d) muxer->cont_write_chunk(muxer,a,b,c,d)
#define muxer_write_header(muxer,f) muxer->cont_write_header(muxer,f)
#define muxer_write_index(muxer,f) muxer->cont_write_index(muxer,f)
#define muxer_write_chunk(a,b,c) a->muxer->cont_write_chunk(a,b,c)
#define muxer_write_header(muxer) muxer->cont_write_header(muxer)
#define muxer_write_index(muxer) muxer->cont_write_index(muxer)
void muxer_init_muxer_avi(muxer_t *);
void muxer_init_muxer_mpeg(muxer_t *);

View File

@ -30,6 +30,7 @@ extern char *info_comment;
static muxer_stream_t* avifile_new_stream(muxer_t *muxer,int type){
muxer_stream_t* s;
if (!muxer) return NULL;
if(muxer->avih.dwStreams>=MUXER_MAX_STREAMS){
printf("Too many streams! increase MUXER_MAX_STREAMS !\n");
return NULL;
@ -42,6 +43,7 @@ static muxer_stream_t* avifile_new_stream(muxer_t *muxer,int type){
s->id=muxer->avih.dwStreams;
s->timer=0.0;
s->size=0;
s->muxer=muxer;
switch(type){
case MUXER_TYPE_VIDEO:
s->ckid=mmioFOURCC(('0'+s->id/10),('0'+(s->id%10)),'d','c');
@ -88,7 +90,8 @@ if(len>0){
}
}
static void avifile_write_chunk(muxer_t *muxer,muxer_stream_t *s, FILE *f,size_t len,unsigned int flags){
static void avifile_write_chunk(muxer_stream_t *s,size_t len,unsigned int flags){
muxer_t *muxer=s->muxer;
// add to the index:
if(muxer->idx_pos>=muxer->idx_size){
@ -97,12 +100,12 @@ static void avifile_write_chunk(muxer_t *muxer,muxer_stream_t *s, FILE *f,size_t
}
muxer->idx[muxer->idx_pos].ckid=s->ckid;
muxer->idx[muxer->idx_pos].dwFlags=flags; // keyframe?
muxer->idx[muxer->idx_pos].dwChunkOffset=ftell(f)-(muxer->movi_start-4);
muxer->idx[muxer->idx_pos].dwChunkOffset=ftell(muxer->file)-(muxer->movi_start-4);
muxer->idx[muxer->idx_pos].dwChunkLength=len;
++muxer->idx_pos;
// write out the chunk:
write_avi_chunk(f,s->ckid,len,s->buffer); /* unsigned char */
write_avi_chunk(muxer->file,s->ckid,len,s->buffer); /* unsigned char */
// alter counters:
if(s->h.dwSampleSize){
@ -135,11 +138,12 @@ static void write_avi_list(FILE *f,unsigned int id,int len){
// muxer->streams[i]->wf->cbSize
#define WFSIZE(wf) (sizeof(WAVEFORMATEX)+(((wf)->cbSize)?((wf)->cbSize-2):0))
static void avifile_write_header(muxer_t *muxer,FILE *f){
static void avifile_write_header(muxer_t *muxer){
uint32_t riff[3];
unsigned int i;
unsigned int hdrsize;
muxer_info_t info[16];
FILE *f=muxer->file;
// RIFF header:
riff[0]=mmioFOURCC('R','I','F','F');
@ -275,19 +279,19 @@ info[i].id=0;
muxer->movi_start=ftell(f);
}
static void avifile_write_index(muxer_t *muxer,FILE *f){
muxer->movi_end=ftell(f);
static void avifile_write_index(muxer_t *muxer){
muxer->movi_end=ftell(muxer->file);
if(muxer->idx && muxer->idx_pos>0){
int i;
// fixup index entries:
// for(i=0;i<muxer->idx_pos;i++) muxer->idx[i].dwChunkOffset-=muxer->movi_start-4;
// write index chunk:
for (i=0; i<muxer->idx_pos; i++) le2me_AVIINDEXENTRY((&muxer->idx[i]));
write_avi_chunk(f,ckidAVINEWINDEX,16*muxer->idx_pos,muxer->idx); /* AVIINDEXENTRY */
write_avi_chunk(muxer->file,ckidAVINEWINDEX,16*muxer->idx_pos,muxer->idx); /* AVIINDEXENTRY */
for (i=0; i<muxer->idx_pos; i++) le2me_AVIINDEXENTRY((&muxer->idx[i]));
muxer->avih.dwFlags|=AVIF_HASINDEX;
}
muxer->file_end=ftell(f);
muxer->file_end=ftell(muxer->file);
}
void muxer_init_muxer_avi(muxer_t *muxer){

View File

@ -32,6 +32,7 @@
static muxer_stream_t* mpegfile_new_stream(muxer_t *muxer,int type){
muxer_stream_t *s;
if (!muxer) return NULL;
if(muxer->avih.dwStreams>=MUXER_MAX_STREAMS){
printf("Too many streams! increase MUXER_MAX_STREAMS !\n");
return NULL;
@ -75,6 +76,7 @@ static muxer_stream_t* mpegfile_new_stream(muxer_t *muxer,int type){
s->id=muxer->avih.dwStreams;
s->timer=0.0;
s->size=0;
s->muxer=muxer;
muxer->avih.dwStreams++;
return s;
}
@ -239,10 +241,13 @@ static void set_mpeg_pts(muxer_t *muxer, muxer_stream_t *s, unsigned int pts) {
write_mpeg_ts (s->b_buffer+7, dts, 0x10);
}
static void mpegfile_write_chunk(muxer_t *muxer,muxer_stream_t *s,FILE *f,size_t len,unsigned int flags){
static void mpegfile_write_chunk(muxer_stream_t *s,size_t len,unsigned int flags){
size_t ptr=0, sz;
unsigned int pts=0;
muxer_t *muxer = s->muxer;
FILE *f;
f = muxer->file;
if (s->type == MUXER_TYPE_VIDEO) { // try to recognize frame type...
if (s->buffer[0] != 0 || s->buffer[1] != 0 || s->buffer[2] != 1 || len<6) {
printf ("Unknown block type, possibly non-MPEG stream!\n");
@ -358,13 +363,14 @@ static void mpegfile_write_chunk(muxer_t *muxer,muxer_stream_t *s,FILE *f,size_t
}
}
static void mpegfile_write_header(muxer_t *muxer,FILE *f){
static void mpegfile_write_header(muxer_t *muxer){
unsigned int i;
size_t sz = MUXER_MPEG_BLOCKSIZE-24;
unsigned char buff[12];
muxer_stream_t *s = muxer->streams[0];
uint32_t l1;
uint16_t l2;
FILE *f = muxer->file;
if (s == NULL)
return; // no streams!?
@ -407,7 +413,7 @@ static void mpegfile_write_header(muxer_t *muxer,FILE *f){
muxer->movi_end = MUXER_MPEG_BLOCKSIZE;
}
static void mpegfile_write_index(muxer_t *muxer,FILE *f){
static void mpegfile_write_index(muxer_t *muxer){
unsigned int i;
unsigned int rsr;
@ -415,9 +421,9 @@ static void mpegfile_write_index(muxer_t *muxer,FILE *f){
// finish all but one video and audio streams
rsr = muxer->sysrate; // reserve it since it's silly change it at that point
for (i = 0; i < muxer->avih.dwStreams-1; i++)
write_mpeg_block (muxer, muxer->streams[i], f, NULL, 0, 0);
write_mpeg_block (muxer, muxer->streams[i], muxer->file, NULL, 0, 0);
// end sequence: ISO-11172-End (0x1b9) and finish very last block
write_mpeg_block (muxer, muxer->streams[i], f, NULL, 0, 1);
write_mpeg_block (muxer, muxer->streams[i], muxer->file, NULL, 0, 1);
//fprintf (stderr, "PTS to SCR delay: min %u.%03u, max %u.%03u\n",
// mpeg_min_delay/90000, (mpeg_min_delay/90)%1000,
// mpeg_max_delay/90000, (mpeg_max_delay/90)%1000);