2002-02-20 16:59:25 +00:00
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include "stream.h"
|
|
|
|
#include "demuxer.h"
|
|
|
|
#include "stheader.h"
|
|
|
|
|
|
|
|
typedef struct dd_priv {
|
|
|
|
demuxer_t* vd;
|
|
|
|
demuxer_t* ad;
|
|
|
|
demuxer_t* sd;
|
|
|
|
} dd_priv_t;
|
|
|
|
|
2005-08-05 19:57:47 +00:00
|
|
|
extern demuxer_desc_t demuxer_desc_demuxers;
|
2002-02-20 16:59:25 +00:00
|
|
|
|
|
|
|
demuxer_t* new_demuxers_demuxer(demuxer_t* vd, demuxer_t* ad, demuxer_t* sd) {
|
|
|
|
demuxer_t* ret;
|
|
|
|
dd_priv_t* priv;
|
|
|
|
|
|
|
|
ret = (demuxer_t*)calloc(1,sizeof(demuxer_t));
|
|
|
|
|
|
|
|
priv = (dd_priv_t*)malloc(sizeof(dd_priv_t));
|
|
|
|
priv->vd = vd;
|
|
|
|
priv->ad = ad;
|
|
|
|
priv->sd = sd;
|
|
|
|
ret->priv = priv;
|
|
|
|
|
|
|
|
ret->type = ret->file_format = DEMUXER_TYPE_DEMUXERS;
|
|
|
|
// Video is the most important :-)
|
|
|
|
ret->stream = vd->stream;
|
|
|
|
ret->seekable = vd->seekable && ad->seekable && sd->seekable;
|
|
|
|
|
|
|
|
ret->video = vd->video;
|
|
|
|
ret->audio = ad->audio;
|
|
|
|
ret->sub = sd->sub;
|
2005-08-05 19:57:47 +00:00
|
|
|
|
|
|
|
ret->desc = &demuxer_desc_demuxers;
|
|
|
|
|
2002-02-20 16:59:25 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2005-08-05 19:57:47 +00:00
|
|
|
static int demux_demuxers_fill_buffer(demuxer_t *demux,demux_stream_t *ds) {
|
2002-02-20 16:59:25 +00:00
|
|
|
dd_priv_t* priv;
|
|
|
|
|
|
|
|
priv=demux->priv;
|
|
|
|
|
|
|
|
if(ds->demuxer == priv->vd)
|
|
|
|
return demux_fill_buffer(priv->vd,ds);
|
|
|
|
else if(ds->demuxer == priv->ad)
|
|
|
|
return demux_fill_buffer(priv->ad,ds);
|
|
|
|
else if(ds->demuxer == priv->sd)
|
|
|
|
return demux_fill_buffer(priv->sd,ds);
|
|
|
|
|
|
|
|
printf("Demux demuxers fill_buffer error : bad demuxer : not vd, ad nor sd\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-08-05 19:57:47 +00:00
|
|
|
static void demux_demuxers_seek(demuxer_t *demuxer,float rel_seek_secs,int flags) {
|
2002-02-20 16:59:25 +00:00
|
|
|
dd_priv_t* priv;
|
|
|
|
float pos;
|
|
|
|
priv=demuxer->priv;
|
|
|
|
|
|
|
|
priv->ad->stream->eof = 0;
|
|
|
|
priv->sd->stream->eof = 0;
|
|
|
|
|
|
|
|
// Seek video
|
|
|
|
demux_seek(priv->vd,rel_seek_secs,flags);
|
|
|
|
// Get the new pos
|
|
|
|
pos = demuxer->video->pts;
|
|
|
|
|
|
|
|
if(priv->ad != priv->vd) {
|
|
|
|
sh_audio_t* sh = (sh_audio_t*)demuxer->audio->sh;
|
|
|
|
demux_seek(priv->ad,pos,1);
|
|
|
|
// In case the demuxer don't set pts
|
|
|
|
if(!demuxer->audio->pts)
|
|
|
|
demuxer->audio->pts = pos-((ds_tell_pts(demuxer->audio)-sh->a_in_buffer_len)/(float)sh->i_bps);
|
2002-11-02 19:52:59 +00:00
|
|
|
sh->delay = 0;
|
2002-02-20 16:59:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if(priv->sd != priv->vd)
|
|
|
|
demux_seek(priv->sd,pos,1);
|
|
|
|
|
|
|
|
}
|
2002-04-24 17:28:23 +00:00
|
|
|
|
2005-08-05 19:57:47 +00:00
|
|
|
static void demux_close_demuxers(demuxer_t* demuxer) {
|
2002-04-24 17:28:23 +00:00
|
|
|
int i;
|
|
|
|
dd_priv_t* priv = demuxer->priv;
|
2003-03-27 20:40:50 +00:00
|
|
|
stream_t *s;
|
2002-04-24 17:28:23 +00:00
|
|
|
|
|
|
|
if(priv->vd)
|
|
|
|
free_demuxer(priv->vd);
|
2003-03-27 20:40:50 +00:00
|
|
|
if(priv->ad && priv->ad != priv->vd) {
|
|
|
|
// That's a hack to free the audio file stream
|
|
|
|
// It's ok atm but we shouldn't free that here
|
|
|
|
s = priv->ad->stream;
|
2002-04-24 17:28:23 +00:00
|
|
|
free_demuxer(priv->ad);
|
2003-03-27 20:40:50 +00:00
|
|
|
free_stream(s);
|
|
|
|
} if(priv->sd && priv->sd != priv->vd && priv->sd != priv->ad) {
|
|
|
|
s = priv->sd->stream;
|
2002-04-24 17:28:23 +00:00
|
|
|
free_demuxer(priv->sd);
|
2003-03-27 20:40:50 +00:00
|
|
|
free_stream(s);
|
|
|
|
}
|
2002-04-24 17:28:23 +00:00
|
|
|
|
|
|
|
free(priv);
|
|
|
|
if(demuxer->info) {
|
|
|
|
for(i=0;demuxer->info[i] != NULL; i++)
|
|
|
|
free(demuxer->info[i]);
|
|
|
|
free(demuxer->info);
|
|
|
|
}
|
|
|
|
free(demuxer);
|
|
|
|
}
|
|
|
|
|
2005-08-05 19:57:47 +00:00
|
|
|
|
|
|
|
demuxer_desc_t demuxer_desc_demuxers = {
|
|
|
|
"Demuxers demuxer",
|
|
|
|
"", // Not selectable
|
|
|
|
"",
|
|
|
|
"?",
|
|
|
|
"internal use only",
|
|
|
|
DEMUXER_TYPE_DEMUXERS,
|
|
|
|
0, // no autodetect
|
|
|
|
NULL,
|
|
|
|
demux_demuxers_fill_buffer,
|
|
|
|
NULL,
|
|
|
|
demux_close_demuxers,
|
|
|
|
demux_demuxers_seek,
|
|
|
|
NULL
|
|
|
|
};
|