2009-05-08 21:51:13 +00:00
|
|
|
/*
|
|
|
|
* This file is part of MPlayer.
|
|
|
|
*
|
|
|
|
* MPlayer is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* MPlayer is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with MPlayer; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*/
|
2002-02-20 16:59:25 +00:00
|
|
|
|
|
|
|
#include "config.h"
|
2006-04-22 05:12:10 +00:00
|
|
|
#include "mp_msg.h"
|
2002-02-20 16:59:25 +00:00
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
2007-03-15 18:36:36 +00:00
|
|
|
#include "stream/stream.h"
|
2002-02-20 16:59:25 +00:00
|
|
|
#include "demuxer.h"
|
|
|
|
#include "stheader.h"
|
2009-03-16 03:11:22 +00:00
|
|
|
#include "talloc.h"
|
2002-02-20 16:59:25 +00:00
|
|
|
|
|
|
|
typedef struct dd_priv {
|
|
|
|
demuxer_t* vd;
|
|
|
|
demuxer_t* ad;
|
|
|
|
demuxer_t* sd;
|
|
|
|
} dd_priv_t;
|
|
|
|
|
2008-01-13 16:00:39 +00:00
|
|
|
extern const 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;
|
|
|
|
|
2009-03-16 03:11:22 +00:00
|
|
|
ret = talloc_zero(NULL, struct demuxer);
|
2009-07-06 23:26:13 +00:00
|
|
|
|
2006-07-03 13:21:54 +00:00
|
|
|
priv = malloc(sizeof(dd_priv_t));
|
2002-02-20 16:59:25 +00:00
|
|
|
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;
|
2010-11-08 00:02:21 +00:00
|
|
|
ret->stream_pts = MP_NOPTS_VALUE;
|
2009-07-06 23:26:13 +00:00
|
|
|
|
2002-02-20 16:59:25 +00:00
|
|
|
ret->video = vd->video;
|
|
|
|
ret->audio = ad->audio;
|
|
|
|
ret->sub = sd->sub;
|
2009-11-01 09:48:34 +00:00
|
|
|
if (sd && sd != vd && sd != ad) sd->sub->non_interleaved = 1;
|
|
|
|
|
|
|
|
// without these, demux_demuxers_fill_buffer will never be called,
|
|
|
|
// but they break the demuxer-specific code in video.c
|
|
|
|
#if 0
|
2009-09-01 14:51:49 +00:00
|
|
|
if (vd) vd->video->demuxer = ret;
|
|
|
|
if (ad) ad->audio->demuxer = ret;
|
|
|
|
if (sd) sd->sub->demuxer = ret;
|
2005-08-05 19:57:47 +00:00
|
|
|
|
2008-05-21 18:45:30 +00:00
|
|
|
// HACK?, necessary for subtitle (and audio and video when implemented) switching
|
|
|
|
memcpy(ret->v_streams, vd->v_streams, sizeof(ret->v_streams));
|
|
|
|
memcpy(ret->a_streams, ad->a_streams, sizeof(ret->a_streams));
|
|
|
|
memcpy(ret->s_streams, sd->s_streams, sizeof(ret->s_streams));
|
2010-11-08 00:38:51 +00:00
|
|
|
#endif
|
2008-05-21 18:45:30 +00:00
|
|
|
|
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;
|
|
|
|
|
2009-09-01 15:00:49 +00:00
|
|
|
// HACK: make sure the subtitles get properly interleaved if with -subfile
|
|
|
|
if (priv->sd && priv->sd->sub != ds &&
|
|
|
|
priv->sd != priv->vd && priv->sd != priv->ad)
|
|
|
|
ds_get_next_pts(priv->sd->sub);
|
2009-09-01 14:51:49 +00:00
|
|
|
if(priv->vd && priv->vd->video == ds)
|
2002-02-20 16:59:25 +00:00
|
|
|
return demux_fill_buffer(priv->vd,ds);
|
2009-09-01 14:51:49 +00:00
|
|
|
else if(priv->ad && priv->ad->audio == ds)
|
2002-02-20 16:59:25 +00:00
|
|
|
return demux_fill_buffer(priv->ad,ds);
|
2009-09-01 14:51:49 +00:00
|
|
|
else if(priv->sd && priv->sd->sub == ds)
|
2002-02-20 16:59:25 +00:00
|
|
|
return demux_fill_buffer(priv->sd,ds);
|
2009-07-06 23:26:13 +00:00
|
|
|
|
2009-07-06 22:15:02 +00:00
|
|
|
mp_tmsg(MSGT_DEMUX,MSGL_WARN,"fill_buffer error: bad demuxer: not vd, ad or sd.\n");
|
2002-02-20 16:59:25 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-02-17 01:57:41 +00:00
|
|
|
static void demux_demuxers_seek(demuxer_t *demuxer,float rel_seek_secs,float audio_delay,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
|
2006-02-17 01:57:41 +00:00
|
|
|
demux_seek(priv->vd,rel_seek_secs,audio_delay,flags);
|
2002-02-20 16:59:25 +00:00
|
|
|
// Get the new pos
|
|
|
|
pos = demuxer->video->pts;
|
2011-10-23 00:22:32 +00:00
|
|
|
if (pos == MP_NOPTS_VALUE) {
|
2006-10-05 21:28:55 +00:00
|
|
|
demux_fill_buffer(priv->vd, demuxer->video);
|
|
|
|
if (demuxer->video->first)
|
|
|
|
pos = demuxer->video->first->pts;
|
|
|
|
}
|
2002-02-20 16:59:25 +00:00
|
|
|
|
2010-12-11 19:32:23 +00:00
|
|
|
if(priv->ad != priv->vd && demuxer->audio->sh) {
|
2008-04-05 14:07:05 +00:00
|
|
|
sh_audio_t* sh = demuxer->audio->sh;
|
2006-02-17 01:57:41 +00:00
|
|
|
demux_seek(priv->ad,pos,audio_delay,1);
|
2002-02-20 16:59:25 +00:00
|
|
|
// 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);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(priv->sd != priv->vd)
|
2006-02-17 01:57:41 +00:00
|
|
|
demux_seek(priv->sd,pos,audio_delay,1);
|
2002-02-20 16:59:25 +00:00
|
|
|
|
|
|
|
}
|
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
|
|
|
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);
|
|
|
|
}
|
2009-07-06 23:26:13 +00:00
|
|
|
|
2005-08-05 19:57:47 +00:00
|
|
|
|
2005-10-30 09:13:32 +00:00
|
|
|
static int demux_demuxers_control(demuxer_t *demuxer,int cmd, void *arg){
|
|
|
|
dd_priv_t* priv = demuxer->priv;
|
|
|
|
switch (cmd) {
|
|
|
|
case DEMUXER_CTRL_GET_TIME_LENGTH:
|
|
|
|
case DEMUXER_CTRL_GET_PERCENT_POS:
|
2010-11-07 22:54:32 +00:00
|
|
|
return demux_control(priv->vd, cmd, arg);
|
2005-10-30 09:13:32 +00:00
|
|
|
}
|
|
|
|
return DEMUXER_CTRL_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
2008-01-13 16:00:39 +00:00
|
|
|
const demuxer_desc_t demuxer_desc_demuxers = {
|
2005-08-05 19:57:47 +00:00
|
|
|
"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,
|
2005-10-30 09:13:32 +00:00
|
|
|
demux_demuxers_control
|
2005-08-05 19:57:47 +00:00
|
|
|
};
|