2001-02-24 20:28:24 +00:00
|
|
|
//=================== DEMUXER v2.5 =========================
|
|
|
|
|
2001-04-23 03:42:17 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2001-11-27 00:42:39 +00:00
|
|
|
#include <string.h>
|
2001-08-01 09:14:02 +00:00
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
2001-02-24 20:28:24 +00:00
|
|
|
|
2001-07-21 22:37:55 +00:00
|
|
|
#include "config.h"
|
2008-04-16 01:23:38 +00:00
|
|
|
#include "options.h"
|
2001-08-17 00:40:25 +00:00
|
|
|
#include "mp_msg.h"
|
2001-08-18 20:32:09 +00:00
|
|
|
#include "help_mp.h"
|
2005-11-18 14:39:25 +00:00
|
|
|
#include "m_config.h"
|
2001-07-21 22:37:55 +00:00
|
|
|
|
2005-12-17 10:46:48 +00:00
|
|
|
#include "libvo/fastmemcpy.h"
|
|
|
|
|
2007-03-15 18:36:36 +00:00
|
|
|
#include "stream/stream.h"
|
2001-04-23 03:42:17 +00:00
|
|
|
#include "demuxer.h"
|
2001-07-21 22:37:55 +00:00
|
|
|
#include "stheader.h"
|
2002-02-06 20:16:35 +00:00
|
|
|
#include "mf.h"
|
2001-07-21 22:37:55 +00:00
|
|
|
|
2005-11-18 14:39:25 +00:00
|
|
|
#include "libaf/af_format.h"
|
2002-03-15 15:53:11 +00:00
|
|
|
|
2008-01-11 21:45:15 +00:00
|
|
|
#ifdef USE_ASS
|
|
|
|
#include "libass/ass.h"
|
|
|
|
#include "libass/ass_mp.h"
|
|
|
|
#endif
|
|
|
|
|
2007-02-05 23:46:08 +00:00
|
|
|
extern void resync_video_stream(sh_video_t *sh_video);
|
2005-10-30 09:19:05 +00:00
|
|
|
extern void resync_audio_stream(sh_audio_t *sh_audio);
|
2005-08-05 19:57:47 +00:00
|
|
|
|
|
|
|
// Demuxer list
|
2008-01-13 16:00:39 +00:00
|
|
|
extern const demuxer_desc_t demuxer_desc_rawaudio;
|
|
|
|
extern const demuxer_desc_t demuxer_desc_rawvideo;
|
|
|
|
extern const demuxer_desc_t demuxer_desc_tv;
|
|
|
|
extern const demuxer_desc_t demuxer_desc_mf;
|
|
|
|
extern const demuxer_desc_t demuxer_desc_avi;
|
|
|
|
extern const demuxer_desc_t demuxer_desc_y4m;
|
|
|
|
extern const demuxer_desc_t demuxer_desc_asf;
|
|
|
|
extern const demuxer_desc_t demuxer_desc_nuv;
|
|
|
|
extern const demuxer_desc_t demuxer_desc_real;
|
|
|
|
extern const demuxer_desc_t demuxer_desc_smjpeg;
|
|
|
|
extern const demuxer_desc_t demuxer_desc_matroska;
|
|
|
|
extern const demuxer_desc_t demuxer_desc_realaudio;
|
|
|
|
extern const demuxer_desc_t demuxer_desc_vqf;
|
|
|
|
extern const demuxer_desc_t demuxer_desc_mov;
|
|
|
|
extern const demuxer_desc_t demuxer_desc_vivo;
|
|
|
|
extern const demuxer_desc_t demuxer_desc_fli;
|
|
|
|
extern const demuxer_desc_t demuxer_desc_film;
|
|
|
|
extern const demuxer_desc_t demuxer_desc_roq;
|
|
|
|
extern const demuxer_desc_t demuxer_desc_gif;
|
|
|
|
extern const demuxer_desc_t demuxer_desc_ogg;
|
|
|
|
extern const demuxer_desc_t demuxer_desc_avs;
|
|
|
|
extern const demuxer_desc_t demuxer_desc_pva;
|
|
|
|
extern const demuxer_desc_t demuxer_desc_nsv;
|
|
|
|
extern const demuxer_desc_t demuxer_desc_mpeg_ts;
|
|
|
|
extern const demuxer_desc_t demuxer_desc_lmlm4;
|
|
|
|
extern const demuxer_desc_t demuxer_desc_mpeg_ps;
|
|
|
|
extern const demuxer_desc_t demuxer_desc_mpeg_pes;
|
|
|
|
extern const demuxer_desc_t demuxer_desc_mpeg_es;
|
|
|
|
extern const demuxer_desc_t demuxer_desc_mpeg_gxf;
|
|
|
|
extern const demuxer_desc_t demuxer_desc_mpeg4_es;
|
|
|
|
extern const demuxer_desc_t demuxer_desc_h264_es;
|
|
|
|
extern const demuxer_desc_t demuxer_desc_rawdv;
|
|
|
|
extern const demuxer_desc_t demuxer_desc_mpc;
|
|
|
|
extern const demuxer_desc_t demuxer_desc_audio;
|
|
|
|
extern const demuxer_desc_t demuxer_desc_xmms;
|
|
|
|
extern const demuxer_desc_t demuxer_desc_mpeg_ty;
|
|
|
|
extern const demuxer_desc_t demuxer_desc_rtp;
|
|
|
|
extern const demuxer_desc_t demuxer_desc_rtp_nemesi;
|
|
|
|
extern const demuxer_desc_t demuxer_desc_lavf;
|
|
|
|
extern const demuxer_desc_t demuxer_desc_lavf_preferred;
|
|
|
|
extern const demuxer_desc_t demuxer_desc_aac;
|
|
|
|
extern const demuxer_desc_t demuxer_desc_nut;
|
2005-08-05 19:57:47 +00:00
|
|
|
|
2008-01-28 16:03:22 +00:00
|
|
|
/* Please do not add any new demuxers here. If you want to implement a new
|
2008-01-28 22:09:21 +00:00
|
|
|
* demuxer, add it to libavformat, except for wrappers around external
|
|
|
|
* libraries and demuxers requiring binary support. */
|
2008-01-28 16:03:22 +00:00
|
|
|
|
2008-04-12 15:51:08 +00:00
|
|
|
const demuxer_desc_t *const demuxer_list[] = {
|
|
|
|
&demuxer_desc_rawaudio,
|
|
|
|
&demuxer_desc_rawvideo,
|
2005-08-05 19:57:47 +00:00
|
|
|
#ifdef USE_TV
|
2008-04-12 15:51:08 +00:00
|
|
|
&demuxer_desc_tv,
|
2005-08-05 19:57:47 +00:00
|
|
|
#endif
|
2008-04-12 15:51:08 +00:00
|
|
|
&demuxer_desc_mf,
|
2007-04-26 15:10:07 +00:00
|
|
|
#ifdef USE_LIBAVFORMAT
|
2008-04-12 15:51:08 +00:00
|
|
|
&demuxer_desc_lavf_preferred,
|
2007-04-22 20:32:15 +00:00
|
|
|
#endif
|
2008-04-12 15:51:08 +00:00
|
|
|
&demuxer_desc_avi,
|
|
|
|
&demuxer_desc_y4m,
|
|
|
|
&demuxer_desc_asf,
|
|
|
|
&demuxer_desc_nsv,
|
|
|
|
&demuxer_desc_nuv,
|
|
|
|
&demuxer_desc_real,
|
|
|
|
&demuxer_desc_smjpeg,
|
|
|
|
&demuxer_desc_matroska,
|
|
|
|
&demuxer_desc_realaudio,
|
|
|
|
&demuxer_desc_vqf,
|
|
|
|
&demuxer_desc_mov,
|
|
|
|
&demuxer_desc_vivo,
|
|
|
|
&demuxer_desc_fli,
|
|
|
|
&demuxer_desc_film,
|
|
|
|
&demuxer_desc_roq,
|
2005-08-05 19:57:47 +00:00
|
|
|
#ifdef HAVE_GIF
|
2008-04-12 15:51:08 +00:00
|
|
|
&demuxer_desc_gif,
|
2005-08-05 19:57:47 +00:00
|
|
|
#endif
|
|
|
|
#ifdef HAVE_OGGVORBIS
|
2008-04-12 15:51:08 +00:00
|
|
|
&demuxer_desc_ogg,
|
2005-08-05 19:57:47 +00:00
|
|
|
#endif
|
|
|
|
#ifdef USE_WIN32DLL
|
2008-04-12 15:51:08 +00:00
|
|
|
&demuxer_desc_avs,
|
2005-08-05 19:57:47 +00:00
|
|
|
#endif
|
2008-04-12 15:51:08 +00:00
|
|
|
&demuxer_desc_pva,
|
|
|
|
&demuxer_desc_mpeg_ts,
|
|
|
|
&demuxer_desc_lmlm4,
|
|
|
|
&demuxer_desc_mpeg_ps,
|
|
|
|
&demuxer_desc_mpeg_pes,
|
|
|
|
&demuxer_desc_mpeg_es,
|
|
|
|
&demuxer_desc_mpeg_gxf,
|
|
|
|
&demuxer_desc_mpeg4_es,
|
|
|
|
&demuxer_desc_h264_es,
|
2006-12-28 23:44:38 +00:00
|
|
|
#ifdef MUSEPACK
|
2008-04-12 15:51:08 +00:00
|
|
|
&demuxer_desc_mpc,
|
2006-12-28 23:44:38 +00:00
|
|
|
#endif
|
2008-04-12 15:51:08 +00:00
|
|
|
&demuxer_desc_audio,
|
|
|
|
&demuxer_desc_mpeg_ty,
|
2007-12-04 13:05:25 +00:00
|
|
|
#ifdef STREAMING_LIVE555
|
2008-04-12 15:51:08 +00:00
|
|
|
&demuxer_desc_rtp,
|
2005-08-05 19:57:47 +00:00
|
|
|
#endif
|
2007-12-04 13:05:25 +00:00
|
|
|
#ifdef LIBNEMESI
|
2008-04-12 15:51:08 +00:00
|
|
|
&demuxer_desc_rtp_nemesi,
|
2007-12-04 13:05:25 +00:00
|
|
|
#endif
|
2007-04-26 15:10:07 +00:00
|
|
|
#ifdef USE_LIBAVFORMAT
|
2008-04-12 15:51:08 +00:00
|
|
|
&demuxer_desc_lavf,
|
2006-07-04 21:26:41 +00:00
|
|
|
#endif
|
|
|
|
#ifdef HAVE_LIBDV095
|
2008-04-12 15:51:08 +00:00
|
|
|
&demuxer_desc_rawdv,
|
2005-08-05 19:57:47 +00:00
|
|
|
#endif
|
2008-04-12 15:51:08 +00:00
|
|
|
&demuxer_desc_aac,
|
2006-09-17 09:32:28 +00:00
|
|
|
#ifdef HAVE_LIBNUT
|
2008-04-12 15:51:08 +00:00
|
|
|
&demuxer_desc_nut,
|
2006-09-17 09:32:28 +00:00
|
|
|
#endif
|
2006-07-04 21:26:41 +00:00
|
|
|
#ifdef HAVE_XMMS
|
2008-04-12 15:51:08 +00:00
|
|
|
&demuxer_desc_xmms,
|
2006-07-04 21:26:41 +00:00
|
|
|
#endif
|
2008-04-12 15:51:08 +00:00
|
|
|
/* Please do not add any new demuxers here. If you want to implement a new
|
|
|
|
* demuxer, add it to libavformat, except for wrappers around external
|
|
|
|
* libraries and demuxers requiring binary support. */
|
|
|
|
NULL
|
2005-08-05 19:57:47 +00:00
|
|
|
};
|
|
|
|
|
2008-04-12 15:51:08 +00:00
|
|
|
void free_demuxer_stream(demux_stream_t *ds)
|
|
|
|
{
|
2001-08-22 23:54:57 +00:00
|
|
|
ds_free_packs(ds);
|
|
|
|
free(ds);
|
|
|
|
}
|
|
|
|
|
2008-04-12 15:51:08 +00:00
|
|
|
demux_stream_t *new_demuxer_stream(struct demuxer_st *demuxer, int id)
|
|
|
|
{
|
|
|
|
demux_stream_t *ds = malloc(sizeof(demux_stream_t));
|
|
|
|
ds->buffer_pos = ds->buffer_size = 0;
|
|
|
|
ds->buffer = NULL;
|
|
|
|
ds->pts = 0;
|
|
|
|
ds->pts_bytes = 0;
|
|
|
|
ds->eof = 0;
|
|
|
|
ds->pos = 0;
|
|
|
|
ds->dpos = 0;
|
|
|
|
ds->pack_no = 0;
|
|
|
|
|
|
|
|
ds->packs = 0;
|
|
|
|
ds->bytes = 0;
|
|
|
|
ds->first = ds->last = ds->current = NULL;
|
|
|
|
ds->id = id;
|
|
|
|
ds->demuxer = demuxer;
|
|
|
|
|
|
|
|
ds->asf_seq = -1;
|
|
|
|
ds->asf_packet = NULL;
|
|
|
|
|
|
|
|
ds->ss_mul = ds->ss_div = 0;
|
|
|
|
|
|
|
|
ds->sh = NULL;
|
|
|
|
return ds;
|
2001-02-24 20:28:24 +00:00
|
|
|
}
|
|
|
|
|
2005-08-05 19:57:47 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get demuxer description structure for a given demuxer type
|
|
|
|
*
|
|
|
|
* @param file_format type of the demuxer
|
|
|
|
* @return structure for the demuxer, NULL if not found
|
|
|
|
*/
|
2008-04-12 15:51:08 +00:00
|
|
|
static const demuxer_desc_t *get_demuxer_desc_from_type(int file_format)
|
2005-08-05 19:57:47 +00:00
|
|
|
{
|
2008-04-12 15:51:08 +00:00
|
|
|
int i;
|
2005-08-05 19:57:47 +00:00
|
|
|
|
2008-04-12 15:51:08 +00:00
|
|
|
for (i = 0; demuxer_list[i]; i++)
|
|
|
|
if (file_format == demuxer_list[i]->type)
|
|
|
|
return demuxer_list[i];
|
2005-08-05 19:57:47 +00:00
|
|
|
|
2008-04-12 15:51:08 +00:00
|
|
|
return NULL;
|
2005-08-05 19:57:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-04-16 01:23:38 +00:00
|
|
|
demuxer_t *new_demuxer(struct MPOpts *opts, stream_t *stream, int type,
|
|
|
|
int a_id, int v_id, int s_id, char *filename)
|
2008-04-12 15:51:08 +00:00
|
|
|
{
|
|
|
|
demuxer_t *d = malloc(sizeof(demuxer_t));
|
|
|
|
memset(d, 0, sizeof(demuxer_t));
|
|
|
|
d->stream = stream;
|
|
|
|
d->stream_pts = MP_NOPTS_VALUE;
|
|
|
|
d->reference_clock = MP_NOPTS_VALUE;
|
|
|
|
d->movi_start = stream->start_pos;
|
|
|
|
d->movi_end = stream->end_pos;
|
|
|
|
d->seekable = 1;
|
|
|
|
d->synced = 0;
|
|
|
|
d->filepos = 0;
|
|
|
|
d->audio = new_demuxer_stream(d, a_id);
|
|
|
|
d->video = new_demuxer_stream(d, v_id);
|
|
|
|
d->sub = new_demuxer_stream(d, s_id);
|
|
|
|
d->type = type;
|
2008-04-16 01:23:38 +00:00
|
|
|
d->opts = opts;
|
2008-04-12 15:51:08 +00:00
|
|
|
if (type)
|
|
|
|
if (!(d->desc = get_demuxer_desc_from_type(type)))
|
|
|
|
mp_msg(MSGT_DEMUXER, MSGL_ERR,
|
|
|
|
"BUG! Invalid demuxer type in new_demuxer(), "
|
|
|
|
"big troubles ahead.");
|
|
|
|
if (filename) // Filename hack for avs_check_file
|
|
|
|
d->filename = strdup(filename);
|
|
|
|
stream_reset(stream);
|
|
|
|
stream_seek(stream, stream->start_pos);
|
|
|
|
return d;
|
2001-02-24 20:28:24 +00:00
|
|
|
}
|
|
|
|
|
2007-08-09 10:26:00 +00:00
|
|
|
extern int dvdsub_id;
|
|
|
|
|
2008-04-12 15:51:08 +00:00
|
|
|
sh_sub_t *new_sh_sub_sid(demuxer_t *demuxer, int id, int sid)
|
|
|
|
{
|
|
|
|
if (id > MAX_S_STREAMS - 1 || id < 0) {
|
|
|
|
mp_msg(MSGT_DEMUXER, MSGL_WARN,
|
|
|
|
"Requested sub stream id overflow (%d > %d)\n", id,
|
|
|
|
MAX_S_STREAMS);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
if (demuxer->s_streams[id])
|
|
|
|
mp_msg(MSGT_DEMUXER, MSGL_WARN, "Sub stream %i redefined\n", id);
|
|
|
|
else {
|
|
|
|
sh_sub_t *sh = calloc(1, sizeof(sh_sub_t));
|
|
|
|
demuxer->s_streams[id] = sh;
|
|
|
|
sh->sid = sid;
|
2008-04-16 01:23:38 +00:00
|
|
|
sh->opts = demuxer->opts;
|
2008-04-12 15:51:08 +00:00
|
|
|
mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_SUBTITLE_ID=%d\n", sid);
|
|
|
|
}
|
|
|
|
return demuxer->s_streams[id];
|
2006-11-13 16:15:23 +00:00
|
|
|
}
|
|
|
|
|
2008-04-12 15:51:08 +00:00
|
|
|
void free_sh_sub(sh_sub_t *sh)
|
|
|
|
{
|
2007-06-23 17:39:27 +00:00
|
|
|
mp_msg(MSGT_DEMUXER, MSGL_DBG2, "DEMUXER: freeing sh_sub at %p\n", sh);
|
2008-02-29 17:25:41 +00:00
|
|
|
free(sh->extradata);
|
2008-01-13 13:37:19 +00:00
|
|
|
#ifdef USE_ASS
|
2008-04-12 15:51:08 +00:00
|
|
|
if (sh->ass_track)
|
|
|
|
ass_free_track(sh->ass_track);
|
2008-01-13 13:37:19 +00:00
|
|
|
#endif
|
2008-02-29 17:25:33 +00:00
|
|
|
free(sh->lang);
|
2007-06-23 17:39:27 +00:00
|
|
|
free(sh);
|
|
|
|
}
|
|
|
|
|
2008-04-12 15:51:08 +00:00
|
|
|
sh_audio_t *new_sh_audio_aid(demuxer_t *demuxer, int id, int aid)
|
|
|
|
{
|
|
|
|
if (id > MAX_A_STREAMS - 1 || id < 0) {
|
|
|
|
mp_msg(MSGT_DEMUXER, MSGL_WARN,
|
|
|
|
"Requested audio stream id overflow (%d > %d)\n", id,
|
|
|
|
MAX_A_STREAMS);
|
|
|
|
return NULL;
|
2002-02-10 18:09:20 +00:00
|
|
|
}
|
2008-04-12 15:51:08 +00:00
|
|
|
if (demuxer->a_streams[id]) {
|
|
|
|
mp_msg(MSGT_DEMUXER, MSGL_WARN, MSGTR_AudioStreamRedefined, id);
|
2001-07-21 22:37:55 +00:00
|
|
|
} else {
|
2004-09-16 19:51:13 +00:00
|
|
|
sh_audio_t *sh;
|
2008-04-12 15:51:08 +00:00
|
|
|
mp_msg(MSGT_DEMUXER, MSGL_V, MSGTR_FoundAudioStream, id);
|
|
|
|
demuxer->a_streams[id] = calloc(1, sizeof(sh_audio_t));
|
2004-09-16 19:51:13 +00:00
|
|
|
sh = demuxer->a_streams[id];
|
|
|
|
// set some defaults
|
2008-04-12 15:51:08 +00:00
|
|
|
sh->samplesize = 2;
|
|
|
|
sh->sample_format = AF_FORMAT_S16_NE;
|
|
|
|
sh->audio_out_minsize = 8192; /* default size, maybe not enough for Win32/ACM */
|
|
|
|
sh->pts = MP_NOPTS_VALUE;
|
2008-04-16 01:23:38 +00:00
|
|
|
sh->opts = demuxer->opts;
|
2008-04-12 15:51:08 +00:00
|
|
|
mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_AUDIO_ID=%d\n", aid);
|
2001-07-21 22:37:55 +00:00
|
|
|
}
|
2008-04-12 15:51:08 +00:00
|
|
|
((sh_audio_t *) demuxer->a_streams[id])->aid = aid;
|
2001-07-21 22:37:55 +00:00
|
|
|
return demuxer->a_streams[id];
|
|
|
|
}
|
|
|
|
|
2008-04-12 15:51:08 +00:00
|
|
|
void free_sh_audio(demuxer_t *demuxer, int id)
|
|
|
|
{
|
2006-06-14 14:05:59 +00:00
|
|
|
sh_audio_t *sh = demuxer->a_streams[id];
|
|
|
|
demuxer->a_streams[id] = NULL;
|
2008-04-12 15:51:08 +00:00
|
|
|
mp_msg(MSGT_DEMUXER, MSGL_DBG2, "DEMUXER: freeing sh_audio at %p\n", sh);
|
2008-02-29 17:25:41 +00:00
|
|
|
free(sh->wf);
|
|
|
|
free(sh->codecdata);
|
2008-02-29 17:25:33 +00:00
|
|
|
free(sh->lang);
|
2001-08-22 23:54:57 +00:00
|
|
|
free(sh);
|
|
|
|
}
|
|
|
|
|
2008-04-12 15:51:08 +00:00
|
|
|
sh_video_t *new_sh_video_vid(demuxer_t *demuxer, int id, int vid)
|
|
|
|
{
|
|
|
|
if (id > MAX_V_STREAMS - 1 || id < 0) {
|
|
|
|
mp_msg(MSGT_DEMUXER, MSGL_WARN,
|
|
|
|
"Requested video stream id overflow (%d > %d)\n", id,
|
|
|
|
MAX_V_STREAMS);
|
|
|
|
return NULL;
|
2002-02-10 18:09:20 +00:00
|
|
|
}
|
2008-04-12 15:51:08 +00:00
|
|
|
if (demuxer->v_streams[id])
|
|
|
|
mp_msg(MSGT_DEMUXER, MSGL_WARN, MSGTR_VideoStreamRedefined, id);
|
|
|
|
else {
|
|
|
|
mp_msg(MSGT_DEMUXER, MSGL_V, MSGTR_FoundVideoStream, id);
|
2008-04-16 01:23:38 +00:00
|
|
|
sh_video_t *sh = calloc(1, sizeof *sh);
|
|
|
|
demuxer->v_streams[id] = sh;
|
|
|
|
sh->opts = demuxer->opts;
|
2008-04-12 15:51:08 +00:00
|
|
|
mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_VIDEO_ID=%d\n", vid);
|
2001-07-21 22:37:55 +00:00
|
|
|
}
|
2008-04-12 15:51:08 +00:00
|
|
|
((sh_video_t *) demuxer->v_streams[id])->vid = vid;
|
2001-07-21 22:37:55 +00:00
|
|
|
return demuxer->v_streams[id];
|
|
|
|
}
|
|
|
|
|
2008-04-12 15:51:08 +00:00
|
|
|
void free_sh_video(sh_video_t *sh)
|
|
|
|
{
|
|
|
|
mp_msg(MSGT_DEMUXER, MSGL_DBG2, "DEMUXER: freeing sh_video at %p\n", sh);
|
2008-02-29 17:25:41 +00:00
|
|
|
free(sh->bih);
|
2001-08-22 23:54:57 +00:00
|
|
|
free(sh);
|
|
|
|
}
|
|
|
|
|
2008-04-12 15:51:08 +00:00
|
|
|
void free_demuxer(demuxer_t *demuxer)
|
|
|
|
{
|
2001-08-22 23:54:57 +00:00
|
|
|
int i;
|
2008-04-12 15:51:08 +00:00
|
|
|
mp_msg(MSGT_DEMUXER, MSGL_DBG2, "DEMUXER: freeing demuxer at %p\n",
|
|
|
|
demuxer);
|
|
|
|
if (demuxer->desc->close)
|
|
|
|
demuxer->desc->close(demuxer);
|
2005-08-05 19:57:47 +00:00
|
|
|
// Very ugly hack to make it behave like old implementation
|
|
|
|
if (demuxer->desc->type == DEMUXER_TYPE_DEMUXERS)
|
2008-04-12 15:51:08 +00:00
|
|
|
goto skip_streamfree;
|
2001-08-22 23:54:57 +00:00
|
|
|
// free streams:
|
2008-04-12 15:51:08 +00:00
|
|
|
for (i = 0; i < MAX_A_STREAMS; i++)
|
|
|
|
if (demuxer->a_streams[i])
|
|
|
|
free_sh_audio(demuxer, i);
|
|
|
|
for (i = 0; i < MAX_V_STREAMS; i++)
|
|
|
|
if (demuxer->v_streams[i])
|
|
|
|
free_sh_video(demuxer->v_streams[i]);
|
|
|
|
for (i = 0; i < MAX_S_STREAMS; i++)
|
|
|
|
if (demuxer->s_streams[i])
|
|
|
|
free_sh_sub(demuxer->s_streams[i]);
|
2001-08-22 23:54:57 +00:00
|
|
|
// free demuxers:
|
|
|
|
free_demuxer_stream(demuxer->audio);
|
|
|
|
free_demuxer_stream(demuxer->video);
|
2002-03-31 02:45:14 +00:00
|
|
|
free_demuxer_stream(demuxer->sub);
|
2008-04-12 15:51:08 +00:00
|
|
|
skip_streamfree:
|
|
|
|
if (demuxer->info) {
|
|
|
|
for (i = 0; demuxer->info[i] != NULL; i++)
|
|
|
|
free(demuxer->info[i]);
|
|
|
|
free(demuxer->info);
|
2002-02-14 13:04:35 +00:00
|
|
|
}
|
2008-02-29 17:25:41 +00:00
|
|
|
free(demuxer->filename);
|
2006-08-06 18:55:34 +00:00
|
|
|
if (demuxer->chapters) {
|
2008-04-12 15:51:08 +00:00
|
|
|
for (i = 0; i < demuxer->num_chapters; i++)
|
|
|
|
free(demuxer->chapters[i].name);
|
|
|
|
free(demuxer->chapters);
|
2006-08-06 18:55:34 +00:00
|
|
|
}
|
2008-01-12 01:12:36 +00:00
|
|
|
if (demuxer->attachments) {
|
2008-04-12 15:51:08 +00:00
|
|
|
for (i = 0; i < demuxer->num_attachments; i++) {
|
|
|
|
free(demuxer->attachments[i].name);
|
|
|
|
free(demuxer->attachments[i].type);
|
|
|
|
free(demuxer->attachments[i].data);
|
|
|
|
}
|
|
|
|
free(demuxer->attachments);
|
2008-01-12 01:12:36 +00:00
|
|
|
}
|
2001-08-22 23:54:57 +00:00
|
|
|
free(demuxer);
|
|
|
|
}
|
|
|
|
|
2001-07-21 22:37:55 +00:00
|
|
|
|
2008-04-12 15:51:08 +00:00
|
|
|
void ds_add_packet(demux_stream_t *ds, demux_packet_t *dp)
|
|
|
|
{
|
2001-02-24 20:28:24 +00:00
|
|
|
// append packet to DS stream:
|
|
|
|
++ds->packs;
|
2008-04-12 15:51:08 +00:00
|
|
|
ds->bytes += dp->len;
|
|
|
|
if (ds->last) {
|
|
|
|
// next packet in stream
|
|
|
|
ds->last->next = dp;
|
|
|
|
ds->last = dp;
|
2001-02-24 20:28:24 +00:00
|
|
|
} else {
|
2008-04-12 15:51:08 +00:00
|
|
|
// first packet in stream
|
|
|
|
ds->first = ds->last = dp;
|
2001-02-24 20:28:24 +00:00
|
|
|
}
|
2008-04-12 15:51:08 +00:00
|
|
|
mp_dbg(MSGT_DEMUXER, MSGL_DBG2,
|
|
|
|
"DEMUX: Append packet to %s, len=%d pts=%5.3f pos=%u [packs: A=%d V=%d]\n",
|
|
|
|
(ds == ds->demuxer->audio) ? "d_audio" : "d_video", dp->len,
|
|
|
|
dp->pts, (unsigned int) dp->pos, ds->demuxer->audio->packs,
|
|
|
|
ds->demuxer->video->packs);
|
2001-02-24 20:28:24 +00:00
|
|
|
}
|
|
|
|
|
2008-04-12 15:51:08 +00:00
|
|
|
void ds_read_packet(demux_stream_t *ds, stream_t *stream, int len,
|
|
|
|
double pts, off_t pos, int flags)
|
|
|
|
{
|
|
|
|
demux_packet_t *dp = new_demux_packet(len);
|
|
|
|
len = stream_read(stream, dp->buffer, len);
|
2003-09-20 12:50:25 +00:00
|
|
|
resize_demux_packet(dp, len);
|
2008-04-12 15:51:08 +00:00
|
|
|
dp->pts = pts;
|
|
|
|
dp->pos = pos;
|
|
|
|
dp->flags = flags;
|
2001-02-24 20:28:24 +00:00
|
|
|
// append packet to DS stream:
|
2008-04-12 15:51:08 +00:00
|
|
|
ds_add_packet(ds, dp);
|
2001-02-24 20:28:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// return value:
|
|
|
|
// 0 = EOF or no stream found or invalid type
|
|
|
|
// 1 = successfully read a packet
|
|
|
|
|
2008-04-12 15:51:08 +00:00
|
|
|
int demux_fill_buffer(demuxer_t *demux, demux_stream_t *ds)
|
|
|
|
{
|
|
|
|
// Note: parameter 'ds' can be NULL!
|
|
|
|
return demux->desc->fill_buffer(demux, ds);
|
2001-02-24 20:28:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// return value:
|
|
|
|
// 0 = EOF
|
2007-12-01 13:35:25 +00:00
|
|
|
// 1 = successful
|
2008-02-23 10:31:44 +00:00
|
|
|
#define MAX_ACUMULATED_PACKETS 64
|
2008-04-12 15:51:08 +00:00
|
|
|
int ds_fill_buffer(demux_stream_t *ds)
|
|
|
|
{
|
|
|
|
demuxer_t *demux = ds->demuxer;
|
|
|
|
if (ds->current)
|
|
|
|
free_demux_packet(ds->current);
|
|
|
|
ds->current = NULL;
|
|
|
|
if (mp_msg_test(MSGT_DEMUXER, MSGL_DBG3)) {
|
|
|
|
if (ds == demux->audio)
|
|
|
|
mp_dbg(MSGT_DEMUXER, MSGL_DBG3,
|
|
|
|
"ds_fill_buffer(d_audio) called\n");
|
|
|
|
else if (ds == demux->video)
|
|
|
|
mp_dbg(MSGT_DEMUXER, MSGL_DBG3,
|
|
|
|
"ds_fill_buffer(d_video) called\n");
|
|
|
|
else if (ds == demux->sub)
|
|
|
|
mp_dbg(MSGT_DEMUXER, MSGL_DBG3, "ds_fill_buffer(d_sub) called\n");
|
|
|
|
else
|
|
|
|
mp_dbg(MSGT_DEMUXER, MSGL_DBG3,
|
|
|
|
"ds_fill_buffer(unknown 0x%X) called\n", (unsigned int) ds);
|
|
|
|
}
|
|
|
|
while (1) {
|
|
|
|
if (ds->packs) {
|
|
|
|
demux_packet_t *p = ds->first;
|
2008-02-25 22:29:45 +00:00
|
|
|
#if 0
|
2008-04-12 15:51:08 +00:00
|
|
|
if (demux->reference_clock != MP_NOPTS_VALUE) {
|
|
|
|
if ((p->pts != MP_NOPTS_VALUE)
|
|
|
|
&& (p->pts > demux->reference_clock)
|
|
|
|
&& (ds->packs < MAX_ACUMULATED_PACKETS)) {
|
|
|
|
if (demux_fill_buffer(demux, ds))
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
2008-02-25 22:29:45 +00:00
|
|
|
#endif
|
2008-04-12 15:51:08 +00:00
|
|
|
// copy useful data:
|
|
|
|
ds->buffer = p->buffer;
|
|
|
|
ds->buffer_pos = 0;
|
|
|
|
ds->buffer_size = p->len;
|
|
|
|
ds->pos = p->pos;
|
|
|
|
ds->dpos += p->len; // !!!
|
|
|
|
++ds->pack_no;
|
|
|
|
if (p->pts != MP_NOPTS_VALUE) {
|
|
|
|
ds->pts = p->pts;
|
|
|
|
ds->pts_bytes = 0;
|
|
|
|
}
|
|
|
|
ds->pts_bytes += p->len; // !!!
|
|
|
|
if (p->stream_pts != MP_NOPTS_VALUE)
|
|
|
|
demux->stream_pts = p->stream_pts;
|
|
|
|
ds->flags = p->flags;
|
|
|
|
// unlink packet:
|
|
|
|
ds->bytes -= p->len;
|
|
|
|
ds->current = p;
|
|
|
|
ds->first = p->next;
|
|
|
|
if (!ds->first)
|
|
|
|
ds->last = NULL;
|
|
|
|
--ds->packs;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
if (demux->audio->packs >= MAX_PACKS
|
|
|
|
|| demux->audio->bytes >= MAX_PACK_BYTES) {
|
|
|
|
mp_msg(MSGT_DEMUXER, MSGL_ERR, MSGTR_TooManyAudioInBuffer,
|
|
|
|
demux->audio->packs, demux->audio->bytes);
|
|
|
|
mp_msg(MSGT_DEMUXER, MSGL_HINT, MSGTR_MaybeNI);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (demux->video->packs >= MAX_PACKS
|
|
|
|
|| demux->video->bytes >= MAX_PACK_BYTES) {
|
|
|
|
mp_msg(MSGT_DEMUXER, MSGL_ERR, MSGTR_TooManyVideoInBuffer,
|
|
|
|
demux->video->packs, demux->video->bytes);
|
|
|
|
mp_msg(MSGT_DEMUXER, MSGL_HINT, MSGTR_MaybeNI);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (!demux_fill_buffer(demux, ds)) {
|
|
|
|
mp_dbg(MSGT_DEMUXER, MSGL_DBG2,
|
|
|
|
"ds_fill_buffer()->demux_fill_buffer() failed\n");
|
|
|
|
break; // EOF
|
|
|
|
}
|
2001-07-29 21:07:34 +00:00
|
|
|
}
|
2008-04-12 15:51:08 +00:00
|
|
|
ds->buffer_pos = ds->buffer_size = 0;
|
|
|
|
ds->buffer = NULL;
|
|
|
|
mp_msg(MSGT_DEMUXER, MSGL_V,
|
|
|
|
"ds_fill_buffer: EOF reached (stream: %s) \n",
|
|
|
|
ds == demux->audio ? "audio" : "video");
|
|
|
|
ds->eof = 1;
|
|
|
|
return 0;
|
2001-02-24 20:28:24 +00:00
|
|
|
}
|
|
|
|
|
2008-04-12 15:51:08 +00:00
|
|
|
int demux_read_data(demux_stream_t *ds, unsigned char *mem, int len)
|
|
|
|
{
|
|
|
|
int x;
|
|
|
|
int bytes = 0;
|
|
|
|
while (len > 0) {
|
|
|
|
x = ds->buffer_size - ds->buffer_pos;
|
|
|
|
if (x == 0) {
|
|
|
|
if (!ds_fill_buffer(ds))
|
|
|
|
return bytes;
|
|
|
|
} else {
|
|
|
|
if (x > len)
|
|
|
|
x = len;
|
|
|
|
if (mem)
|
|
|
|
fast_memcpy(mem + bytes, &ds->buffer[ds->buffer_pos], x);
|
|
|
|
bytes += x;
|
|
|
|
len -= x;
|
|
|
|
ds->buffer_pos += x;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return bytes;
|
2001-02-24 20:28:24 +00:00
|
|
|
}
|
|
|
|
|
2006-01-17 20:04:49 +00:00
|
|
|
/**
|
|
|
|
* \brief read data until the given 3-byte pattern is encountered, up to maxlen
|
|
|
|
* \param mem memory to read data into, may be NULL to discard data
|
|
|
|
* \param maxlen maximum number of bytes to read
|
|
|
|
* \param read number of bytes actually read
|
|
|
|
* \param pattern pattern to search for (lowest 8 bits are ignored)
|
|
|
|
* \return whether pattern was found
|
|
|
|
*/
|
|
|
|
int demux_pattern_3(demux_stream_t *ds, unsigned char *mem, int maxlen,
|
2008-04-12 15:51:08 +00:00
|
|
|
int *read, uint32_t pattern)
|
|
|
|
{
|
|
|
|
register uint32_t head = 0xffffff00;
|
|
|
|
register uint32_t pat = pattern & 0xffffff00;
|
|
|
|
int total_len = 0;
|
2006-01-17 20:04:49 +00:00
|
|
|
do {
|
2008-04-12 15:51:08 +00:00
|
|
|
register unsigned char *ds_buf = &ds->buffer[ds->buffer_size];
|
|
|
|
int len = ds->buffer_size - ds->buffer_pos;
|
|
|
|
register long pos = -len;
|
|
|
|
if (unlikely(pos >= 0)) { // buffer is empty
|
|
|
|
ds_fill_buffer(ds);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
do {
|
|
|
|
head |= ds_buf[pos];
|
|
|
|
head <<= 8;
|
|
|
|
} while (++pos && head != pat);
|
|
|
|
len += pos;
|
|
|
|
if (total_len + len > maxlen)
|
|
|
|
len = maxlen - total_len;
|
|
|
|
len = demux_read_data(ds, mem ? &mem[total_len] : NULL, len);
|
|
|
|
total_len += len;
|
|
|
|
} while ((head != pat || total_len < 3) && total_len < maxlen && !ds->eof);
|
|
|
|
if (read)
|
|
|
|
*read = total_len;
|
|
|
|
return total_len >= 3 && head == pat;
|
2006-01-17 20:04:49 +00:00
|
|
|
}
|
2001-05-10 03:39:54 +00:00
|
|
|
|
2008-04-12 15:51:08 +00:00
|
|
|
void ds_free_packs(demux_stream_t *ds)
|
|
|
|
{
|
|
|
|
demux_packet_t *dp = ds->first;
|
|
|
|
while (dp) {
|
|
|
|
demux_packet_t *dn = dp->next;
|
|
|
|
free_demux_packet(dp);
|
|
|
|
dp = dn;
|
|
|
|
}
|
|
|
|
if (ds->asf_packet) {
|
|
|
|
// free unfinished .asf fragments:
|
|
|
|
free(ds->asf_packet->buffer);
|
|
|
|
free(ds->asf_packet);
|
|
|
|
ds->asf_packet = NULL;
|
|
|
|
}
|
|
|
|
ds->first = ds->last = NULL;
|
|
|
|
ds->packs = 0; // !!!!!
|
|
|
|
ds->bytes = 0;
|
|
|
|
if (ds->current)
|
|
|
|
free_demux_packet(ds->current);
|
|
|
|
ds->current = NULL;
|
|
|
|
ds->buffer = NULL;
|
|
|
|
ds->buffer_pos = ds->buffer_size;
|
|
|
|
ds->pts = 0;
|
|
|
|
ds->pts_bytes = 0;
|
2001-02-24 20:28:24 +00:00
|
|
|
}
|
|
|
|
|
2008-04-12 15:51:08 +00:00
|
|
|
int ds_get_packet(demux_stream_t *ds, unsigned char **start)
|
|
|
|
{
|
2007-10-25 19:21:24 +00:00
|
|
|
int len;
|
2008-04-12 15:51:08 +00:00
|
|
|
if (ds->buffer_pos >= ds->buffer_size) {
|
|
|
|
if (!ds_fill_buffer(ds)) {
|
2001-02-24 20:28:24 +00:00
|
|
|
// EOF
|
|
|
|
*start = NULL;
|
|
|
|
return -1;
|
2008-04-12 15:51:08 +00:00
|
|
|
}
|
2001-02-24 20:28:24 +00:00
|
|
|
}
|
2008-04-12 15:51:08 +00:00
|
|
|
len = ds->buffer_size - ds->buffer_pos;
|
2007-10-25 19:21:24 +00:00
|
|
|
*start = &ds->buffer[ds->buffer_pos];
|
2008-04-12 15:51:08 +00:00
|
|
|
ds->buffer_pos += len;
|
2007-10-25 19:21:24 +00:00
|
|
|
return len;
|
2001-02-24 20:28:24 +00:00
|
|
|
}
|
2001-04-20 23:00:11 +00:00
|
|
|
|
2008-04-12 15:51:08 +00:00
|
|
|
int ds_get_packet_pts(demux_stream_t *ds, unsigned char **start, double *pts)
|
2006-04-24 10:58:40 +00:00
|
|
|
{
|
|
|
|
int len;
|
|
|
|
*pts = MP_NOPTS_VALUE;
|
2008-04-12 15:51:08 +00:00
|
|
|
if (ds->buffer_pos >= ds->buffer_size) {
|
|
|
|
if (!ds_fill_buffer(ds)) {
|
2006-04-24 10:58:40 +00:00
|
|
|
// EOF
|
|
|
|
*start = NULL;
|
|
|
|
return -1;
|
2008-04-12 15:51:08 +00:00
|
|
|
}
|
2006-04-24 10:58:40 +00:00
|
|
|
}
|
2006-07-06 06:58:17 +00:00
|
|
|
// Return pts unless this read starts from the middle of a packet
|
2008-02-12 10:48:42 +00:00
|
|
|
if (!ds->buffer_pos)
|
2008-04-12 15:51:08 +00:00
|
|
|
*pts = ds->current->pts;
|
|
|
|
len = ds->buffer_size - ds->buffer_pos;
|
2006-04-24 10:58:40 +00:00
|
|
|
*start = &ds->buffer[ds->buffer_pos];
|
2008-04-12 15:51:08 +00:00
|
|
|
ds->buffer_pos += len;
|
2006-04-24 10:58:40 +00:00
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
2008-04-12 15:51:08 +00:00
|
|
|
int ds_get_packet_sub(demux_stream_t *ds, unsigned char **start)
|
|
|
|
{
|
2007-10-25 19:21:24 +00:00
|
|
|
int len;
|
2008-04-12 15:51:08 +00:00
|
|
|
if (ds->buffer_pos >= ds->buffer_size) {
|
|
|
|
*start = NULL;
|
|
|
|
if (!ds->packs)
|
|
|
|
return -1; // no sub
|
|
|
|
if (!ds_fill_buffer(ds))
|
|
|
|
return -1; // EOF
|
2001-04-20 23:00:11 +00:00
|
|
|
}
|
2008-04-12 15:51:08 +00:00
|
|
|
len = ds->buffer_size - ds->buffer_pos;
|
2007-10-25 19:21:24 +00:00
|
|
|
*start = &ds->buffer[ds->buffer_pos];
|
2008-04-12 15:51:08 +00:00
|
|
|
ds->buffer_pos += len;
|
2007-10-25 19:21:24 +00:00
|
|
|
return len;
|
2001-04-20 23:00:11 +00:00
|
|
|
}
|
|
|
|
|
2006-04-27 11:13:21 +00:00
|
|
|
double ds_get_next_pts(demux_stream_t *ds)
|
|
|
|
{
|
2008-04-12 15:51:08 +00:00
|
|
|
demuxer_t *demux = ds->demuxer;
|
|
|
|
while (!ds->first) {
|
|
|
|
if (demux->audio->packs >= MAX_PACKS
|
|
|
|
|| demux->audio->bytes >= MAX_PACK_BYTES) {
|
|
|
|
mp_msg(MSGT_DEMUXER, MSGL_ERR, MSGTR_TooManyAudioInBuffer,
|
|
|
|
demux->audio->packs, demux->audio->bytes);
|
|
|
|
mp_msg(MSGT_DEMUXER, MSGL_HINT, MSGTR_MaybeNI);
|
|
|
|
return MP_NOPTS_VALUE;
|
|
|
|
}
|
|
|
|
if (demux->video->packs >= MAX_PACKS
|
|
|
|
|| demux->video->bytes >= MAX_PACK_BYTES) {
|
|
|
|
mp_msg(MSGT_DEMUXER, MSGL_ERR, MSGTR_TooManyVideoInBuffer,
|
|
|
|
demux->video->packs, demux->video->bytes);
|
|
|
|
mp_msg(MSGT_DEMUXER, MSGL_HINT, MSGTR_MaybeNI);
|
|
|
|
return MP_NOPTS_VALUE;
|
|
|
|
}
|
|
|
|
if (!demux_fill_buffer(demux, ds))
|
|
|
|
return MP_NOPTS_VALUE;
|
2002-05-02 10:25:48 +00:00
|
|
|
}
|
2008-04-12 15:51:08 +00:00
|
|
|
return ds->first->pts;
|
2002-05-02 10:25:48 +00:00
|
|
|
}
|
|
|
|
|
2001-07-21 22:37:55 +00:00
|
|
|
// ====================================================================
|
|
|
|
|
2005-08-05 19:57:47 +00:00
|
|
|
void demuxer_help(void)
|
|
|
|
{
|
2008-04-12 15:51:08 +00:00
|
|
|
int i;
|
|
|
|
|
|
|
|
mp_msg(MSGT_DEMUXER, MSGL_INFO, "Available demuxers:\n");
|
|
|
|
mp_msg(MSGT_DEMUXER, MSGL_INFO, " demuxer: type info: (comment)\n");
|
|
|
|
mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_DEMUXERS\n");
|
|
|
|
for (i = 0; demuxer_list[i]; i++) {
|
|
|
|
if (demuxer_list[i]->type > DEMUXER_TYPE_MAX) // Don't display special demuxers
|
|
|
|
continue;
|
|
|
|
if (demuxer_list[i]->comment && strlen(demuxer_list[i]->comment))
|
|
|
|
mp_msg(MSGT_DEMUXER, MSGL_INFO, "%10s %2d %s (%s)\n",
|
|
|
|
demuxer_list[i]->name, demuxer_list[i]->type,
|
|
|
|
demuxer_list[i]->info, demuxer_list[i]->comment);
|
|
|
|
else
|
|
|
|
mp_msg(MSGT_DEMUXER, MSGL_INFO, "%10s %2d %s\n",
|
|
|
|
demuxer_list[i]->name, demuxer_list[i]->type,
|
|
|
|
demuxer_list[i]->info);
|
|
|
|
}
|
2005-08-05 19:57:47 +00:00
|
|
|
}
|
2005-02-13 13:39:19 +00:00
|
|
|
|
2002-03-16 14:32:03 +00:00
|
|
|
|
2005-08-05 19:57:47 +00:00
|
|
|
/**
|
|
|
|
* Get demuxer type for a given demuxer name
|
|
|
|
*
|
|
|
|
* @param demuxer_name string with demuxer name of demuxer number
|
2005-08-30 23:56:24 +00:00
|
|
|
* @param force will be set if demuxer should be forced.
|
|
|
|
* May be NULL.
|
2005-08-05 19:57:47 +00:00
|
|
|
* @return DEMUXER_TYPE_xxx, -1 if error or not found
|
|
|
|
*/
|
2005-08-30 23:56:24 +00:00
|
|
|
int get_demuxer_type_from_name(char *demuxer_name, int *force)
|
2005-08-05 19:57:47 +00:00
|
|
|
{
|
2008-04-12 15:51:08 +00:00
|
|
|
int i;
|
|
|
|
long type_int;
|
|
|
|
char *endptr;
|
|
|
|
|
|
|
|
if (!demuxer_name || !demuxer_name[0])
|
|
|
|
return DEMUXER_TYPE_UNKNOWN;
|
|
|
|
if (force)
|
|
|
|
*force = demuxer_name[0] == '+';
|
|
|
|
if (demuxer_name[0] == '+')
|
|
|
|
demuxer_name = &demuxer_name[1];
|
|
|
|
for (i = 0; demuxer_list[i]; i++) {
|
|
|
|
if (demuxer_list[i]->type > DEMUXER_TYPE_MAX) // Can't select special demuxers from commandline
|
|
|
|
continue;
|
|
|
|
if (strcmp(demuxer_name, demuxer_list[i]->name) == 0)
|
|
|
|
return demuxer_list[i]->type;
|
|
|
|
}
|
2005-08-05 19:57:47 +00:00
|
|
|
|
2008-04-12 15:51:08 +00:00
|
|
|
// No match found, try to parse name as an integer (demuxer number)
|
|
|
|
type_int = strtol(demuxer_name, &endptr, 0);
|
|
|
|
if (*endptr) // Conversion failed
|
|
|
|
return -1;
|
|
|
|
if ((type_int > 0) && (type_int <= DEMUXER_TYPE_MAX))
|
|
|
|
return (int) type_int;
|
|
|
|
|
|
|
|
return -1;
|
2005-08-05 19:57:47 +00:00
|
|
|
}
|
2001-12-27 21:24:56 +00:00
|
|
|
|
2008-04-12 15:51:08 +00:00
|
|
|
int extension_parsing = 1; // 0=off 1=mixed (used only for unstable formats)
|
2002-02-20 16:59:25 +00:00
|
|
|
|
2003-03-30 17:12:11 +00:00
|
|
|
/*
|
|
|
|
NOTE : Several demuxers may be opened at the same time so
|
|
|
|
demuxers should NEVER rely on an external var to enable them
|
2007-12-01 13:35:25 +00:00
|
|
|
self. If a demuxer can't do any auto-detection it should only use
|
|
|
|
file_format. The user can explicitly set file_format with the -demuxer
|
2003-03-30 17:12:11 +00:00
|
|
|
option so there is really no need for another extra var.
|
2007-12-01 13:35:25 +00:00
|
|
|
For convenience an option can be added to set file_format directly
|
2003-03-30 17:12:11 +00:00
|
|
|
to the right type (ex: rawaudio,rawvideo).
|
2007-12-01 13:35:25 +00:00
|
|
|
Also the stream can override the file_format so a demuxer which rely
|
2003-03-30 17:12:11 +00:00
|
|
|
on a special stream type can set file_format at the stream level
|
|
|
|
(ex: tv,mf).
|
|
|
|
*/
|
|
|
|
|
2008-04-16 01:23:38 +00:00
|
|
|
static demuxer_t *demux_open_stream(struct MPOpts *opts, stream_t *stream,
|
|
|
|
int file_format, int force, int audio_id,
|
|
|
|
int video_id, int dvdsub_id,
|
|
|
|
char *filename)
|
2008-04-12 15:51:08 +00:00
|
|
|
{
|
|
|
|
demuxer_t *demuxer = NULL;
|
|
|
|
|
|
|
|
sh_video_t *sh_video = NULL;
|
|
|
|
|
|
|
|
const demuxer_desc_t *demuxer_desc;
|
|
|
|
int fformat = 0;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
// If somebody requested a demuxer check it
|
|
|
|
if (file_format) {
|
|
|
|
if ((demuxer_desc = get_demuxer_desc_from_type(file_format))) {
|
|
|
|
demuxer =
|
2008-04-16 01:23:38 +00:00
|
|
|
new_demuxer(opts, stream, demuxer_desc->type, audio_id,
|
|
|
|
video_id, dvdsub_id, filename);
|
2008-04-12 15:51:08 +00:00
|
|
|
if (demuxer_desc->check_file)
|
|
|
|
fformat = demuxer_desc->check_file(demuxer);
|
|
|
|
if (force || !demuxer_desc->check_file)
|
|
|
|
fformat = demuxer_desc->type;
|
|
|
|
if (fformat != 0) {
|
|
|
|
if (fformat == demuxer_desc->type) {
|
|
|
|
demuxer_t *demux2 = demuxer;
|
|
|
|
// Move messages to demuxer detection code?
|
|
|
|
mp_msg(MSGT_DEMUXER, MSGL_INFO,
|
|
|
|
MSGTR_Detected_XXX_FileFormat,
|
|
|
|
demuxer_desc->shortdesc);
|
|
|
|
file_format = fformat;
|
|
|
|
if (!demuxer->desc->open
|
|
|
|
|| (demux2 = demuxer->desc->open(demuxer))) {
|
|
|
|
demuxer = demux2;
|
|
|
|
goto dmx_open;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// Format changed after check, recurse
|
|
|
|
free_demuxer(demuxer);
|
2008-04-16 01:23:38 +00:00
|
|
|
return demux_open_stream(opts, stream, fformat, force,
|
|
|
|
audio_id, video_id, dvdsub_id,
|
|
|
|
filename);
|
2008-04-12 15:51:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
// Check failed for forced demuxer, quit
|
|
|
|
free_demuxer(demuxer);
|
|
|
|
return NULL;
|
2005-08-05 19:57:47 +00:00
|
|
|
}
|
2006-10-20 19:36:59 +00:00
|
|
|
}
|
2008-04-12 15:51:08 +00:00
|
|
|
// Test demuxers with safe file checks
|
|
|
|
for (i = 0; (demuxer_desc = demuxer_list[i]); i++) {
|
|
|
|
if (demuxer_desc->safe_check) {
|
|
|
|
demuxer =
|
2008-04-16 01:23:38 +00:00
|
|
|
new_demuxer(opts, stream, demuxer_desc->type, audio_id,
|
|
|
|
video_id, dvdsub_id, filename);
|
2008-04-12 15:51:08 +00:00
|
|
|
if ((fformat = demuxer_desc->check_file(demuxer)) != 0) {
|
|
|
|
if (fformat == demuxer_desc->type) {
|
|
|
|
demuxer_t *demux2 = demuxer;
|
|
|
|
mp_msg(MSGT_DEMUXER, MSGL_INFO,
|
|
|
|
MSGTR_Detected_XXX_FileFormat,
|
|
|
|
demuxer_desc->shortdesc);
|
|
|
|
file_format = fformat;
|
|
|
|
if (!demuxer->desc->open
|
|
|
|
|| (demux2 = demuxer->desc->open(demuxer))) {
|
|
|
|
demuxer = demux2;
|
|
|
|
goto dmx_open;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (fformat == DEMUXER_TYPE_PLAYLIST)
|
|
|
|
return demuxer; // handled in mplayer.c
|
|
|
|
// Format changed after check, recurse
|
|
|
|
free_demuxer(demuxer);
|
|
|
|
demuxer =
|
2008-04-16 01:23:38 +00:00
|
|
|
demux_open_stream(opts, stream, fformat, force,
|
|
|
|
audio_id, video_id, dvdsub_id,
|
|
|
|
filename);
|
2008-04-12 15:51:08 +00:00
|
|
|
if (demuxer)
|
|
|
|
return demuxer; // done!
|
|
|
|
file_format = DEMUXER_TYPE_UNKNOWN;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
free_demuxer(demuxer);
|
|
|
|
demuxer = NULL;
|
2006-10-19 18:20:12 +00:00
|
|
|
}
|
|
|
|
}
|
2003-01-19 00:21:54 +00:00
|
|
|
|
2008-04-12 15:51:08 +00:00
|
|
|
// If no forced demuxer perform file extension based detection
|
|
|
|
// Ok. We're over the stable detectable fileformats, the next ones are
|
|
|
|
// a bit fuzzy. So by default (extension_parsing==1) try extension-based
|
|
|
|
// detection first:
|
|
|
|
if (file_format == DEMUXER_TYPE_UNKNOWN && filename
|
|
|
|
&& extension_parsing == 1) {
|
|
|
|
file_format = demuxer_type_by_filename(filename);
|
|
|
|
if (file_format != DEMUXER_TYPE_UNKNOWN) {
|
|
|
|
// we like recursion :)
|
2008-04-16 01:23:38 +00:00
|
|
|
demuxer = demux_open_stream(opts, stream, file_format, force,
|
|
|
|
audio_id, video_id, dvdsub_id,
|
|
|
|
filename);
|
2008-04-12 15:51:08 +00:00
|
|
|
if (demuxer)
|
|
|
|
return demuxer; // done!
|
|
|
|
file_format = DEMUXER_TYPE_UNKNOWN; // continue fuzzy guessing...
|
|
|
|
mp_msg(MSGT_DEMUXER, MSGL_V,
|
|
|
|
"demuxer: continue fuzzy content-based format guessing...\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Try detection for all other demuxers
|
|
|
|
for (i = 0; (demuxer_desc = demuxer_list[i]); i++) {
|
|
|
|
if (!demuxer_desc->safe_check && demuxer_desc->check_file) {
|
|
|
|
demuxer =
|
2008-04-16 01:23:38 +00:00
|
|
|
new_demuxer(opts, stream, demuxer_desc->type, audio_id,
|
|
|
|
video_id, dvdsub_id, filename);
|
2008-04-12 15:51:08 +00:00
|
|
|
if ((fformat = demuxer_desc->check_file(demuxer)) != 0) {
|
|
|
|
if (fformat == demuxer_desc->type) {
|
|
|
|
demuxer_t *demux2 = demuxer;
|
|
|
|
mp_msg(MSGT_DEMUXER, MSGL_INFO,
|
|
|
|
MSGTR_Detected_XXX_FileFormat,
|
|
|
|
demuxer_desc->shortdesc);
|
|
|
|
file_format = fformat;
|
|
|
|
if (!demuxer->desc->open
|
|
|
|
|| (demux2 = demuxer->desc->open(demuxer))) {
|
|
|
|
demuxer = demux2;
|
|
|
|
goto dmx_open;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (fformat == DEMUXER_TYPE_PLAYLIST)
|
|
|
|
return demuxer; // handled in mplayer.c
|
|
|
|
// Format changed after check, recurse
|
|
|
|
free_demuxer(demuxer);
|
|
|
|
demuxer =
|
2008-04-16 01:23:38 +00:00
|
|
|
demux_open_stream(opts, stream, fformat, force,
|
|
|
|
audio_id, video_id, dvdsub_id,
|
|
|
|
filename);
|
2008-04-12 15:51:08 +00:00
|
|
|
if (demuxer)
|
|
|
|
return demuxer; // done!
|
|
|
|
file_format = DEMUXER_TYPE_UNKNOWN;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
free_demuxer(demuxer);
|
|
|
|
demuxer = NULL;
|
2006-10-19 18:20:12 +00:00
|
|
|
}
|
|
|
|
}
|
2001-12-26 16:34:06 +00:00
|
|
|
|
2008-04-12 15:51:08 +00:00
|
|
|
return NULL;
|
|
|
|
//====== File format recognized, set up these for compatibility: =========
|
|
|
|
dmx_open:
|
|
|
|
|
|
|
|
demuxer->file_format = file_format;
|
|
|
|
|
|
|
|
if ((sh_video = demuxer->video->sh) && sh_video->bih) {
|
|
|
|
int biComp = le2me_32(sh_video->bih->biCompression);
|
|
|
|
mp_msg(MSGT_DEMUX, MSGL_INFO,
|
|
|
|
"VIDEO: [%.4s] %dx%d %dbpp %5.3f fps %5.1f kbps (%4.1f kbyte/s)\n",
|
|
|
|
(char *) &biComp, sh_video->bih->biWidth,
|
|
|
|
sh_video->bih->biHeight, sh_video->bih->biBitCount,
|
|
|
|
sh_video->fps, sh_video->i_bps * 0.008f,
|
|
|
|
sh_video->i_bps / 1024.0f);
|
|
|
|
}
|
2008-01-11 21:45:15 +00:00
|
|
|
#ifdef USE_ASS
|
2008-04-12 15:51:08 +00:00
|
|
|
if (ass_enabled && ass_library) {
|
|
|
|
for (i = 0; i < MAX_S_STREAMS; ++i) {
|
|
|
|
sh_sub_t *sh = demuxer->s_streams[i];
|
|
|
|
if (sh && sh->type == 'a') {
|
|
|
|
sh->ass_track = ass_new_track(ass_library);
|
|
|
|
if (sh->ass_track && sh->extradata)
|
|
|
|
ass_process_codec_private(sh->ass_track, sh->extradata,
|
|
|
|
sh->extradata_len);
|
|
|
|
} else if (sh && sh->type != 'v')
|
|
|
|
sh->ass_track = ass_default_track(ass_library);
|
|
|
|
}
|
|
|
|
}
|
2008-01-11 21:45:15 +00:00
|
|
|
#endif
|
2008-04-12 15:51:08 +00:00
|
|
|
return demuxer;
|
2001-07-21 22:37:55 +00:00
|
|
|
}
|
2001-08-12 17:28:16 +00:00
|
|
|
|
2008-04-12 15:51:08 +00:00
|
|
|
char *audio_stream = NULL;
|
|
|
|
char *sub_stream = NULL;
|
2003-03-27 20:38:14 +00:00
|
|
|
int audio_stream_cache = 0;
|
2002-10-23 17:21:01 +00:00
|
|
|
|
2008-04-12 15:51:08 +00:00
|
|
|
char *demuxer_name = NULL; // parameter from -demuxer
|
2005-08-05 19:57:47 +00:00
|
|
|
char *audio_demuxer_name = NULL; // parameter from -audio-demuxer
|
2008-04-12 15:51:08 +00:00
|
|
|
char *sub_demuxer_name = NULL; // parameter from -sub-demuxer
|
2005-08-05 19:57:47 +00:00
|
|
|
|
2002-10-23 17:21:01 +00:00
|
|
|
extern int hr_mp3_seek;
|
2002-02-20 16:59:25 +00:00
|
|
|
|
2004-07-16 20:31:17 +00:00
|
|
|
extern float stream_cache_min_percent;
|
2005-07-31 00:26:07 +00:00
|
|
|
extern float stream_cache_seek_min_percent;
|
2004-07-16 20:31:17 +00:00
|
|
|
|
2008-04-16 01:23:38 +00:00
|
|
|
demuxer_t *demux_open(struct MPOpts *opts, stream_t *vs, int file_format,
|
|
|
|
int audio_id, int video_id, int dvdsub_id,
|
|
|
|
char *filename)
|
2008-04-12 15:51:08 +00:00
|
|
|
{
|
|
|
|
stream_t *as = NULL, *ss = NULL;
|
|
|
|
demuxer_t *vd, *ad = NULL, *sd = NULL;
|
|
|
|
demuxer_t *res;
|
|
|
|
int afmt = DEMUXER_TYPE_UNKNOWN, sfmt = DEMUXER_TYPE_UNKNOWN;
|
|
|
|
int demuxer_type;
|
|
|
|
int audio_demuxer_type = 0, sub_demuxer_type = 0;
|
|
|
|
int demuxer_force = 0, audio_demuxer_force = 0, sub_demuxer_force = 0;
|
|
|
|
|
|
|
|
if ((demuxer_type =
|
|
|
|
get_demuxer_type_from_name(demuxer_name, &demuxer_force)) < 0) {
|
|
|
|
mp_msg(MSGT_DEMUXER, MSGL_ERR, "-demuxer %s does not exist.\n",
|
|
|
|
demuxer_name);
|
2002-02-20 16:59:25 +00:00
|
|
|
}
|
2008-04-12 15:51:08 +00:00
|
|
|
if ((audio_demuxer_type =
|
|
|
|
get_demuxer_type_from_name(audio_demuxer_name,
|
|
|
|
&audio_demuxer_force)) < 0) {
|
|
|
|
mp_msg(MSGT_DEMUXER, MSGL_ERR, "-audio-demuxer %s does not exist.\n",
|
|
|
|
audio_demuxer_name);
|
2003-03-27 20:38:14 +00:00
|
|
|
}
|
2008-04-12 15:51:08 +00:00
|
|
|
if ((sub_demuxer_type =
|
|
|
|
get_demuxer_type_from_name(sub_demuxer_name,
|
|
|
|
&sub_demuxer_force)) < 0) {
|
|
|
|
mp_msg(MSGT_DEMUXER, MSGL_ERR, "-sub-demuxer %s does not exist.\n",
|
|
|
|
sub_demuxer_name);
|
2002-02-20 16:59:25 +00:00
|
|
|
}
|
2008-04-12 15:51:08 +00:00
|
|
|
|
|
|
|
if (audio_stream) {
|
|
|
|
as = open_stream(audio_stream, 0, &afmt);
|
|
|
|
if (!as) {
|
|
|
|
mp_msg(MSGT_DEMUXER, MSGL_ERR, MSGTR_CannotOpenAudioStream,
|
|
|
|
audio_stream);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
if (audio_stream_cache) {
|
|
|
|
if (!stream_enable_cache
|
|
|
|
(as, audio_stream_cache * 1024,
|
|
|
|
audio_stream_cache * 1024 * (stream_cache_min_percent /
|
|
|
|
100.0),
|
|
|
|
audio_stream_cache * 1024 * (stream_cache_seek_min_percent /
|
|
|
|
100.0))) {
|
|
|
|
free_stream(as);
|
|
|
|
mp_msg(MSGT_DEMUXER, MSGL_ERR,
|
|
|
|
"Can't enable audio stream cache\n");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
2003-03-27 20:38:14 +00:00
|
|
|
}
|
2008-04-12 15:51:08 +00:00
|
|
|
if (sub_stream) {
|
|
|
|
ss = open_stream(sub_stream, 0, &sfmt);
|
|
|
|
if (!ss) {
|
|
|
|
mp_msg(MSGT_DEMUXER, MSGL_ERR, MSGTR_CannotOpenSubtitlesStream,
|
|
|
|
sub_stream);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-04-16 01:23:38 +00:00
|
|
|
vd = demux_open_stream(opts, vs, demuxer_type ? demuxer_type : file_format,
|
2008-04-12 15:51:08 +00:00
|
|
|
demuxer_force, audio_stream ? -2 : audio_id,
|
|
|
|
video_id, sub_stream ? -2 : dvdsub_id, filename);
|
|
|
|
if (!vd) {
|
|
|
|
if (as)
|
|
|
|
free_stream(as);
|
|
|
|
if (ss)
|
|
|
|
free_stream(ss);
|
|
|
|
return NULL;
|
2003-03-27 20:38:14 +00:00
|
|
|
}
|
2008-04-12 15:51:08 +00:00
|
|
|
if (as) {
|
2008-04-16 01:23:38 +00:00
|
|
|
ad = demux_open_stream(opts, as,
|
2008-04-12 15:51:08 +00:00
|
|
|
audio_demuxer_type ? audio_demuxer_type : afmt,
|
|
|
|
audio_demuxer_force, audio_id, -2, -2,
|
|
|
|
audio_stream);
|
|
|
|
if (!ad) {
|
|
|
|
mp_msg(MSGT_DEMUXER, MSGL_WARN, MSGTR_OpeningAudioDemuxerFailed,
|
|
|
|
audio_stream);
|
|
|
|
free_stream(as);
|
|
|
|
} else if (ad->audio->sh
|
|
|
|
&& ((sh_audio_t *) ad->audio->sh)->format == 0x55) // MP3
|
|
|
|
hr_mp3_seek = 1; // Enable high res seeking
|
|
|
|
}
|
|
|
|
if (ss) {
|
2008-04-16 01:23:38 +00:00
|
|
|
sd = demux_open_stream(opts, ss,
|
|
|
|
sub_demuxer_type ? sub_demuxer_type : sfmt,
|
2008-04-12 15:51:08 +00:00
|
|
|
sub_demuxer_force, -2, -2, dvdsub_id,
|
|
|
|
sub_stream);
|
|
|
|
if (!sd) {
|
|
|
|
mp_msg(MSGT_DEMUXER, MSGL_WARN,
|
|
|
|
MSGTR_OpeningSubtitlesDemuxerFailed, sub_stream);
|
|
|
|
free_stream(ss);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ad && sd)
|
|
|
|
res = new_demuxers_demuxer(vd, ad, sd);
|
|
|
|
else if (ad)
|
|
|
|
res = new_demuxers_demuxer(vd, ad, vd);
|
|
|
|
else if (sd)
|
|
|
|
res = new_demuxers_demuxer(vd, vd, sd);
|
|
|
|
else
|
|
|
|
res = vd;
|
|
|
|
|
2008-04-16 04:11:12 +00:00
|
|
|
opts->correct_pts = opts->user_correct_pts;
|
|
|
|
if (opts->correct_pts < 0)
|
|
|
|
opts->correct_pts =
|
2008-04-12 15:51:08 +00:00
|
|
|
demux_control(res, DEMUXER_CTRL_CORRECT_PTS,
|
|
|
|
NULL) == DEMUXER_CTRL_OK;
|
|
|
|
return res;
|
2002-02-20 16:59:25 +00:00
|
|
|
}
|
|
|
|
|
2001-08-12 17:28:16 +00:00
|
|
|
|
2008-04-12 15:51:08 +00:00
|
|
|
int demux_seek(demuxer_t *demuxer, float rel_seek_secs, float audio_delay,
|
|
|
|
int flags)
|
|
|
|
{
|
|
|
|
demux_stream_t *d_audio = demuxer->audio;
|
|
|
|
demux_stream_t *d_video = demuxer->video;
|
|
|
|
sh_audio_t *sh_audio = d_audio->sh;
|
|
|
|
sh_video_t *sh_video = d_video->sh;
|
2006-11-12 17:19:56 +00:00
|
|
|
double tmp = 0;
|
2006-11-07 22:54:28 +00:00
|
|
|
double pts;
|
2001-08-12 17:28:16 +00:00
|
|
|
|
2008-04-12 15:51:08 +00:00
|
|
|
if (!demuxer->seekable) {
|
|
|
|
if (demuxer->file_format == DEMUXER_TYPE_AVI)
|
|
|
|
mp_msg(MSGT_SEEK, MSGL_WARN, MSGTR_CantSeekRawAVI);
|
2001-11-09 23:46:06 +00:00
|
|
|
#ifdef USE_TV
|
2008-04-12 15:51:08 +00:00
|
|
|
else if (demuxer->file_format == DEMUXER_TYPE_TV)
|
|
|
|
mp_msg(MSGT_SEEK, MSGL_WARN, MSGTR_TVInputNotSeekable);
|
2001-11-09 23:46:06 +00:00
|
|
|
#endif
|
2008-04-12 15:51:08 +00:00
|
|
|
else
|
|
|
|
mp_msg(MSGT_SEEK, MSGL_WARN, MSGTR_CantSeekFile);
|
|
|
|
return 0;
|
|
|
|
}
|
2001-08-12 17:28:16 +00:00
|
|
|
// clear demux buffers:
|
2008-04-12 15:51:08 +00:00
|
|
|
if (sh_audio) {
|
|
|
|
ds_free_packs(d_audio);
|
|
|
|
sh_audio->a_buffer_len = 0;
|
|
|
|
}
|
2001-08-12 17:28:16 +00:00
|
|
|
ds_free_packs(d_video);
|
2007-10-04 02:35:34 +00:00
|
|
|
ds_free_packs(demuxer->sub);
|
2001-08-12 17:28:16 +00:00
|
|
|
|
2008-04-12 15:51:08 +00:00
|
|
|
demuxer->stream->eof = 0;
|
|
|
|
demuxer->video->eof = 0;
|
|
|
|
demuxer->audio->eof = 0;
|
2001-08-12 17:28:16 +00:00
|
|
|
|
2008-04-12 15:51:08 +00:00
|
|
|
if (sh_video)
|
|
|
|
sh_video->timer = 0; // !!!!!!
|
|
|
|
|
|
|
|
if (flags & SEEK_ABSOLUTE)
|
|
|
|
pts = 0.0f;
|
2006-11-07 22:54:28 +00:00
|
|
|
else {
|
2008-04-12 15:51:08 +00:00
|
|
|
if (demuxer->stream_pts == MP_NOPTS_VALUE)
|
|
|
|
goto dmx_seek;
|
|
|
|
pts = demuxer->stream_pts;
|
2006-11-07 22:54:28 +00:00
|
|
|
}
|
|
|
|
|
2008-04-12 15:51:08 +00:00
|
|
|
if (flags & SEEK_FACTOR) {
|
|
|
|
if (stream_control(demuxer->stream, STREAM_CTRL_GET_TIME_LENGTH, &tmp)
|
|
|
|
== STREAM_UNSUPPORTED)
|
|
|
|
goto dmx_seek;
|
|
|
|
pts += tmp * rel_seek_secs;
|
2006-11-07 22:54:28 +00:00
|
|
|
} else
|
2008-04-12 15:51:08 +00:00
|
|
|
pts += rel_seek_secs;
|
2006-11-07 22:54:28 +00:00
|
|
|
|
2008-04-12 15:51:08 +00:00
|
|
|
if (stream_control(demuxer->stream, STREAM_CTRL_SEEK_TO_TIME, &pts) !=
|
|
|
|
STREAM_UNSUPPORTED) {
|
|
|
|
demux_control(demuxer, DEMUXER_CTRL_RESYNC, NULL);
|
|
|
|
return 1;
|
2006-11-07 22:54:28 +00:00
|
|
|
}
|
|
|
|
|
2008-04-12 15:51:08 +00:00
|
|
|
dmx_seek:
|
|
|
|
if (demuxer->desc->seek)
|
|
|
|
demuxer->desc->seek(demuxer, rel_seek_secs, audio_delay, flags);
|
2001-08-12 17:28:16 +00:00
|
|
|
|
2008-04-12 15:51:08 +00:00
|
|
|
if (sh_audio)
|
|
|
|
resync_audio_stream(sh_audio);
|
2005-10-30 09:19:05 +00:00
|
|
|
|
2008-04-12 15:51:08 +00:00
|
|
|
return 1;
|
2001-08-12 17:28:16 +00:00
|
|
|
}
|
|
|
|
|
2006-07-13 05:03:43 +00:00
|
|
|
int demux_info_add(demuxer_t *demuxer, const char *opt, const char *param)
|
2001-11-21 16:14:14 +00:00
|
|
|
{
|
2002-02-14 13:04:35 +00:00
|
|
|
char **info = demuxer->info;
|
|
|
|
int n = 0;
|
2001-11-21 16:14:14 +00:00
|
|
|
|
|
|
|
|
2008-04-12 15:51:08 +00:00
|
|
|
for (n = 0; info && info[2 * n] != NULL; n++) {
|
|
|
|
if (!strcasecmp(opt, info[2 * n])) {
|
|
|
|
mp_msg(MSGT_DEMUX, MSGL_INFO, MSGTR_DemuxerInfoChanged, opt,
|
|
|
|
param);
|
|
|
|
free(info[2 * n + 1]);
|
|
|
|
info[2 * n + 1] = strdup(param);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
info = demuxer->info =
|
|
|
|
(char **) realloc(info, (2 * (n + 2)) * sizeof(char *));
|
|
|
|
info[2 * n] = strdup(opt);
|
|
|
|
info[2 * n + 1] = strdup(param);
|
|
|
|
memset(&info[2 * (n + 1)], 0, 2 * sizeof(char *));
|
2001-11-22 15:43:24 +00:00
|
|
|
|
2002-02-14 13:04:35 +00:00
|
|
|
return 1;
|
2001-11-21 16:14:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int demux_info_print(demuxer_t *demuxer)
|
|
|
|
{
|
2002-02-14 13:04:35 +00:00
|
|
|
char **info = demuxer->info;
|
|
|
|
int n;
|
2001-11-21 16:14:14 +00:00
|
|
|
|
2008-04-12 15:51:08 +00:00
|
|
|
if (!info)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
mp_msg(MSGT_DEMUX, MSGL_INFO, MSGTR_ClipInfo);
|
|
|
|
for (n = 0; info[2 * n] != NULL; n++) {
|
|
|
|
mp_msg(MSGT_DEMUX, MSGL_INFO, " %s: %s\n", info[2 * n],
|
|
|
|
info[2 * n + 1]);
|
|
|
|
mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_CLIP_INFO_NAME%d=%s\n", n,
|
|
|
|
info[2 * n]);
|
|
|
|
mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_CLIP_INFO_VALUE%d=%s\n", n,
|
|
|
|
info[2 * n + 1]);
|
2005-06-20 23:07:35 +00:00
|
|
|
}
|
2006-04-24 07:20:34 +00:00
|
|
|
mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_CLIP_INFO_N=%d\n", n);
|
2002-01-16 03:25:07 +00:00
|
|
|
|
|
|
|
return 0;
|
2001-11-21 16:14:14 +00:00
|
|
|
}
|
2002-02-20 16:59:25 +00:00
|
|
|
|
2008-04-12 15:51:08 +00:00
|
|
|
char *demux_info_get(demuxer_t *demuxer, const char *opt)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
char **info = demuxer->info;
|
2002-02-20 16:59:25 +00:00
|
|
|
|
2008-04-12 15:51:08 +00:00
|
|
|
for (i = 0; info && info[2 * i] != NULL; i++) {
|
|
|
|
if (!strcasecmp(opt, info[2 * i]))
|
|
|
|
return info[2 * i + 1];
|
|
|
|
}
|
2002-02-20 16:59:25 +00:00
|
|
|
|
2008-04-12 15:51:08 +00:00
|
|
|
return NULL;
|
2002-02-20 16:59:25 +00:00
|
|
|
}
|
|
|
|
|
2008-04-12 15:51:08 +00:00
|
|
|
int demux_control(demuxer_t *demuxer, int cmd, void *arg)
|
|
|
|
{
|
2005-08-05 19:57:47 +00:00
|
|
|
|
|
|
|
if (demuxer->desc->control)
|
2008-04-12 15:51:08 +00:00
|
|
|
return demuxer->desc->control(demuxer, cmd, arg);
|
2005-08-05 19:57:47 +00:00
|
|
|
|
|
|
|
return DEMUXER_CTRL_NOTIMPL;
|
2002-11-16 03:42:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2008-04-12 15:51:08 +00:00
|
|
|
double demuxer_get_time_length(demuxer_t *demuxer)
|
|
|
|
{
|
2005-09-02 08:32:32 +00:00
|
|
|
double get_time_ans;
|
2005-01-15 16:11:45 +00:00
|
|
|
sh_video_t *sh_video = demuxer->video->sh;
|
2005-11-06 14:14:53 +00:00
|
|
|
sh_audio_t *sh_audio = demuxer->audio->sh;
|
2005-01-15 16:11:45 +00:00
|
|
|
// <= 0 means DEMUXER_CTRL_NOTIMPL or DEMUXER_CTRL_DONTKNOW
|
2008-04-12 15:51:08 +00:00
|
|
|
if (demux_control
|
|
|
|
(demuxer, DEMUXER_CTRL_GET_TIME_LENGTH, (void *) &get_time_ans) <= 0) {
|
|
|
|
if (sh_video && sh_video->i_bps && sh_audio && sh_audio->i_bps)
|
|
|
|
get_time_ans =
|
|
|
|
(double) (demuxer->movi_end -
|
|
|
|
demuxer->movi_start) / (sh_video->i_bps +
|
|
|
|
sh_audio->i_bps);
|
|
|
|
else if (sh_video && sh_video->i_bps)
|
|
|
|
get_time_ans =
|
|
|
|
(double) (demuxer->movi_end -
|
|
|
|
demuxer->movi_start) / sh_video->i_bps;
|
|
|
|
else if (sh_audio && sh_audio->i_bps)
|
|
|
|
get_time_ans =
|
|
|
|
(double) (demuxer->movi_end -
|
|
|
|
demuxer->movi_start) / sh_audio->i_bps;
|
|
|
|
else
|
|
|
|
get_time_ans = 0;
|
2002-11-16 03:42:14 +00:00
|
|
|
}
|
|
|
|
return get_time_ans;
|
|
|
|
}
|
|
|
|
|
2006-11-07 22:55:49 +00:00
|
|
|
/**
|
|
|
|
* \brief demuxer_get_current_time() returns the time of the current play in three possible ways:
|
|
|
|
* either when the stream reader satisfies STREAM_CTRL_GET_CURRENT_TIME (e.g. dvd)
|
|
|
|
* or using sh_video->pts when the former method fails
|
|
|
|
* 0 otherwise
|
|
|
|
* \return the current play time
|
|
|
|
*/
|
2008-04-12 15:51:08 +00:00
|
|
|
int demuxer_get_current_time(demuxer_t *demuxer)
|
|
|
|
{
|
2006-11-07 22:55:49 +00:00
|
|
|
double get_time_ans = 0;
|
|
|
|
sh_video_t *sh_video = demuxer->video->sh;
|
2008-04-12 15:51:08 +00:00
|
|
|
if (demuxer->stream_pts != MP_NOPTS_VALUE)
|
2006-12-31 11:09:53 +00:00
|
|
|
get_time_ans = demuxer->stream_pts;
|
2008-04-12 15:51:08 +00:00
|
|
|
else if (sh_video)
|
|
|
|
get_time_ans = sh_video->pts;
|
2006-11-07 22:55:49 +00:00
|
|
|
return (int) get_time_ans;
|
|
|
|
}
|
|
|
|
|
2008-04-12 15:51:08 +00:00
|
|
|
int demuxer_get_percent_pos(demuxer_t *demuxer)
|
|
|
|
{
|
2004-12-21 12:25:59 +00:00
|
|
|
int ans = 0;
|
|
|
|
int res = demux_control(demuxer, DEMUXER_CTRL_GET_PERCENT_POS, &ans);
|
|
|
|
int len = (demuxer->movi_end - demuxer->movi_start) / 100;
|
2005-01-15 16:11:45 +00:00
|
|
|
if (res <= 0) {
|
2008-04-12 15:51:08 +00:00
|
|
|
if (len > 0)
|
|
|
|
ans = (demuxer->filepos - demuxer->movi_start) / len;
|
|
|
|
else
|
|
|
|
ans = 0;
|
2005-01-15 16:11:45 +00:00
|
|
|
}
|
2008-04-12 15:51:08 +00:00
|
|
|
if (ans < 0)
|
|
|
|
ans = 0;
|
|
|
|
if (ans > 100)
|
|
|
|
ans = 100;
|
2002-11-16 03:42:14 +00:00
|
|
|
return ans;
|
|
|
|
}
|
|
|
|
|
2008-04-12 15:51:08 +00:00
|
|
|
int demuxer_switch_audio(demuxer_t *demuxer, int index)
|
|
|
|
{
|
2005-04-28 14:43:19 +00:00
|
|
|
int res = demux_control(demuxer, DEMUXER_CTRL_SWITCH_AUDIO, &index);
|
|
|
|
if (res == DEMUXER_CTRL_NOTIMPL)
|
2008-04-12 15:51:08 +00:00
|
|
|
index = demuxer->audio->id;
|
2008-02-29 17:25:48 +00:00
|
|
|
if (demuxer->audio->id >= 0)
|
2008-04-12 15:51:08 +00:00
|
|
|
demuxer->audio->sh = demuxer->a_streams[demuxer->audio->id];
|
2008-02-29 17:25:48 +00:00
|
|
|
else
|
2008-04-12 15:51:08 +00:00
|
|
|
demuxer->audio->sh = NULL;
|
2005-04-28 14:43:19 +00:00
|
|
|
return index;
|
2005-04-03 14:08:28 +00:00
|
|
|
}
|
2006-08-06 18:55:34 +00:00
|
|
|
|
2008-04-12 15:51:08 +00:00
|
|
|
int demuxer_switch_video(demuxer_t *demuxer, int index)
|
|
|
|
{
|
2006-11-16 21:23:06 +00:00
|
|
|
int res = demux_control(demuxer, DEMUXER_CTRL_SWITCH_VIDEO, &index);
|
|
|
|
if (res == DEMUXER_CTRL_NOTIMPL)
|
2008-04-12 15:51:08 +00:00
|
|
|
index = demuxer->video->id;
|
2008-02-29 17:25:48 +00:00
|
|
|
if (demuxer->video->id >= 0)
|
2008-04-12 15:51:08 +00:00
|
|
|
demuxer->video->sh = demuxer->v_streams[demuxer->video->id];
|
2008-02-29 17:25:48 +00:00
|
|
|
else
|
2008-04-12 15:51:08 +00:00
|
|
|
demuxer->video->sh = NULL;
|
2006-11-16 21:23:06 +00:00
|
|
|
return index;
|
|
|
|
}
|
|
|
|
|
2008-04-12 15:51:08 +00:00
|
|
|
int demuxer_add_attachment(demuxer_t *demuxer, const char *name,
|
|
|
|
const char *type, const void *data, size_t size)
|
|
|
|
{
|
2008-01-12 01:12:36 +00:00
|
|
|
if (!(demuxer->num_attachments & 31))
|
2008-04-12 15:51:08 +00:00
|
|
|
demuxer->attachments = realloc(demuxer->attachments,
|
|
|
|
(demuxer->num_attachments + 32) * sizeof(demux_attachment_t));
|
2008-01-12 01:12:36 +00:00
|
|
|
|
|
|
|
demuxer->attachments[demuxer->num_attachments].name = strdup(name);
|
|
|
|
demuxer->attachments[demuxer->num_attachments].type = strdup(type);
|
|
|
|
demuxer->attachments[demuxer->num_attachments].data = malloc(size);
|
|
|
|
memcpy(demuxer->attachments[demuxer->num_attachments].data, data, size);
|
|
|
|
demuxer->attachments[demuxer->num_attachments].data_size = size;
|
|
|
|
|
2008-04-12 15:51:08 +00:00
|
|
|
return demuxer->num_attachments++;
|
2008-01-12 01:12:36 +00:00
|
|
|
}
|
|
|
|
|
2008-04-12 15:51:08 +00:00
|
|
|
int demuxer_add_chapter(demuxer_t *demuxer, const char *name, uint64_t start,
|
|
|
|
uint64_t end)
|
|
|
|
{
|
2006-08-06 18:55:34 +00:00
|
|
|
if (demuxer->chapters == NULL)
|
2008-04-12 15:51:08 +00:00
|
|
|
demuxer->chapters = malloc(32 * sizeof(*demuxer->chapters));
|
2006-08-06 18:55:34 +00:00
|
|
|
else if (!(demuxer->num_chapters % 32))
|
2008-04-12 15:51:08 +00:00
|
|
|
demuxer->chapters = realloc(demuxer->chapters,
|
|
|
|
(demuxer->num_chapters + 32) * sizeof(*demuxer->chapters));
|
2006-08-06 18:55:34 +00:00
|
|
|
|
|
|
|
demuxer->chapters[demuxer->num_chapters].start = start;
|
|
|
|
demuxer->chapters[demuxer->num_chapters].end = end;
|
|
|
|
demuxer->chapters[demuxer->num_chapters].name = strdup(name);
|
|
|
|
|
2008-04-12 15:51:08 +00:00
|
|
|
return demuxer->num_chapters++;
|
2006-08-06 18:55:34 +00:00
|
|
|
}
|
|
|
|
|
2006-08-18 16:48:22 +00:00
|
|
|
/**
|
2008-04-12 15:51:08 +00:00
|
|
|
* \brief demuxer_seek_chapter() seeks to a chapter in two possible ways:
|
2006-08-18 16:48:22 +00:00
|
|
|
* either using the demuxer->chapters structure set by the demuxer
|
|
|
|
* or asking help to the stream layer (e.g. dvd)
|
2006-08-18 19:03:59 +00:00
|
|
|
* \param chapter - chapter number wished - 0-based
|
2006-08-18 16:48:22 +00:00
|
|
|
* \param mode 0: relative to current main pts, 1: absolute
|
|
|
|
* \param seek_pts set by the function to the pts to seek to (if demuxer->chapters is set)
|
2006-08-21 19:19:00 +00:00
|
|
|
* \param num_chapters number of chapters present (set by this function is param is not null)
|
|
|
|
* \param chapter_name name of chapter found (set by this function is param is not null)
|
2006-08-18 16:48:22 +00:00
|
|
|
* \return -1 on error, current chapter if successful
|
|
|
|
*/
|
|
|
|
|
2008-04-12 15:51:08 +00:00
|
|
|
int demuxer_seek_chapter(demuxer_t *demuxer, int chapter, int mode,
|
|
|
|
float *seek_pts, int *num_chapters,
|
|
|
|
char **chapter_name)
|
|
|
|
{
|
2006-08-18 16:48:22 +00:00
|
|
|
int ris;
|
|
|
|
int current, total;
|
|
|
|
sh_video_t *sh_video = demuxer->video->sh;
|
|
|
|
sh_audio_t *sh_audio = demuxer->audio->sh;
|
|
|
|
|
|
|
|
if (!demuxer->num_chapters || !demuxer->chapters) {
|
2008-04-12 15:51:08 +00:00
|
|
|
if (!mode) {
|
|
|
|
ris = stream_control(demuxer->stream,
|
|
|
|
STREAM_CTRL_GET_CURRENT_CHAPTER, ¤t);
|
|
|
|
if (ris == STREAM_UNSUPPORTED)
|
|
|
|
return -1;
|
2006-08-18 19:03:31 +00:00
|
|
|
chapter += current;
|
|
|
|
}
|
|
|
|
|
2008-04-12 15:51:08 +00:00
|
|
|
if (demuxer->video->sh)
|
2006-08-18 16:48:22 +00:00
|
|
|
ds_free_packs(demuxer->video);
|
|
|
|
|
2008-04-12 15:51:08 +00:00
|
|
|
if (demuxer->audio->sh)
|
2006-08-18 16:48:22 +00:00
|
|
|
ds_free_packs(demuxer->audio);
|
|
|
|
|
2008-04-12 15:51:08 +00:00
|
|
|
if (demuxer->sub->id >= 0)
|
2006-08-18 16:48:22 +00:00
|
|
|
ds_free_packs(demuxer->sub);
|
|
|
|
|
2008-04-12 15:51:08 +00:00
|
|
|
ris =
|
|
|
|
stream_control(demuxer->stream, STREAM_CTRL_SEEK_TO_CHAPTER,
|
|
|
|
&chapter);
|
|
|
|
if (ris != STREAM_UNSUPPORTED)
|
2006-11-11 11:53:32 +00:00
|
|
|
demux_control(demuxer, DEMUXER_CTRL_RESYNC, NULL);
|
2008-04-12 15:51:08 +00:00
|
|
|
if (sh_video) {
|
2006-08-18 16:48:22 +00:00
|
|
|
ds_fill_buffer(demuxer->video);
|
|
|
|
resync_video_stream(sh_video);
|
|
|
|
}
|
|
|
|
|
2008-04-12 15:51:08 +00:00
|
|
|
if (sh_audio) {
|
2006-08-18 16:48:22 +00:00
|
|
|
ds_fill_buffer(demuxer->audio);
|
|
|
|
resync_audio_stream(sh_audio);
|
|
|
|
}
|
2008-04-12 15:51:08 +00:00
|
|
|
//exit status may be ok, but main() doesn't have to seek itself
|
|
|
|
// (because e.g. dvds depend on sectors, not on pts)
|
2006-08-18 16:48:22 +00:00
|
|
|
*seek_pts = -1.0;
|
2006-08-21 19:19:00 +00:00
|
|
|
|
2008-04-12 15:51:08 +00:00
|
|
|
if (num_chapters) {
|
|
|
|
if (stream_control(demuxer->stream, STREAM_CTRL_GET_NUM_CHAPTERS,
|
|
|
|
num_chapters) == STREAM_UNSUPPORTED)
|
2006-08-21 19:19:00 +00:00
|
|
|
*num_chapters = 0;
|
|
|
|
}
|
|
|
|
|
2008-04-12 15:51:08 +00:00
|
|
|
if (chapter_name) {
|
2006-08-21 19:19:00 +00:00
|
|
|
*chapter_name = NULL;
|
2007-12-10 14:43:09 +00:00
|
|
|
if (num_chapters && *num_chapters) {
|
|
|
|
char *tmp = malloc(16);
|
|
|
|
if (tmp) {
|
|
|
|
sprintf(tmp, " of %3d", *num_chapters);
|
|
|
|
*chapter_name = tmp;
|
|
|
|
}
|
2006-08-21 19:19:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-04-12 15:51:08 +00:00
|
|
|
return ris != STREAM_UNSUPPORTED ? chapter : -1;
|
|
|
|
} else { // chapters structure is set in the demuxer
|
2006-08-18 16:48:22 +00:00
|
|
|
total = demuxer->num_chapters;
|
|
|
|
|
2008-04-12 15:51:08 +00:00
|
|
|
if (mode == 1) //absolute seeking
|
2006-08-18 16:48:22 +00:00
|
|
|
current = chapter;
|
2008-04-12 15:51:08 +00:00
|
|
|
else { //relative seeking
|
2006-08-18 16:48:22 +00:00
|
|
|
uint64_t now;
|
2008-04-12 15:51:08 +00:00
|
|
|
now =
|
|
|
|
(sh_video ? sh_video->pts : (sh_audio ? sh_audio->pts : 0.)) *
|
|
|
|
1000 + .5;
|
2006-08-18 16:48:22 +00:00
|
|
|
|
|
|
|
for (current = total - 1; current >= 0; --current) {
|
2008-04-12 15:51:08 +00:00
|
|
|
demux_chapter_t *chapter = demuxer->chapters + current;
|
2006-08-18 16:48:22 +00:00
|
|
|
if (chapter->start <= now)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
current += chapter;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (current >= total)
|
2008-04-12 15:51:08 +00:00
|
|
|
return -1;
|
|
|
|
if (current < 0)
|
|
|
|
current = 0;
|
2006-08-18 16:48:22 +00:00
|
|
|
|
|
|
|
*seek_pts = demuxer->chapters[current].start / 1000.0;
|
|
|
|
|
2008-04-12 15:51:08 +00:00
|
|
|
if (num_chapters)
|
2006-08-21 19:19:00 +00:00
|
|
|
*num_chapters = demuxer->num_chapters;
|
|
|
|
|
2008-04-12 15:51:08 +00:00
|
|
|
if (chapter_name) {
|
|
|
|
if (demuxer->chapters[current].name)
|
2006-08-21 19:52:11 +00:00
|
|
|
*chapter_name = strdup(demuxer->chapters[current].name);
|
2008-04-12 15:51:08 +00:00
|
|
|
else
|
|
|
|
*chapter_name = NULL;
|
2006-08-21 19:52:11 +00:00
|
|
|
}
|
2006-08-21 19:19:00 +00:00
|
|
|
|
2006-08-18 16:48:22 +00:00
|
|
|
return current;
|
|
|
|
}
|
|
|
|
}
|
2007-12-13 12:51:05 +00:00
|
|
|
|
2008-04-12 15:51:08 +00:00
|
|
|
int demuxer_get_current_chapter(demuxer_t *demuxer)
|
|
|
|
{
|
2007-12-13 12:51:05 +00:00
|
|
|
int chapter = -1;
|
|
|
|
if (!demuxer->num_chapters || !demuxer->chapters) {
|
|
|
|
if (stream_control(demuxer->stream, STREAM_CTRL_GET_CURRENT_CHAPTER,
|
|
|
|
&chapter) == STREAM_UNSUPPORTED)
|
|
|
|
chapter = -1;
|
2008-04-12 15:51:08 +00:00
|
|
|
} else {
|
2007-12-13 12:51:05 +00:00
|
|
|
sh_video_t *sh_video = demuxer->video->sh;
|
|
|
|
sh_audio_t *sh_audio = demuxer->audio->sh;
|
|
|
|
uint64_t now;
|
2008-04-12 15:51:08 +00:00
|
|
|
now =
|
|
|
|
(sh_video ? sh_video->pts : (sh_audio ? sh_audio->pts : 0)) *
|
|
|
|
1000 + 0.5;
|
2007-12-13 12:51:05 +00:00
|
|
|
for (chapter = demuxer->num_chapters - 1; chapter >= 0; --chapter) {
|
|
|
|
if (demuxer->chapters[chapter].start <= now)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return chapter;
|
|
|
|
}
|
|
|
|
|
2008-04-12 15:51:08 +00:00
|
|
|
char *demuxer_chapter_name(demuxer_t *demuxer, int chapter)
|
|
|
|
{
|
2007-12-13 12:51:05 +00:00
|
|
|
if (demuxer->num_chapters && demuxer->chapters) {
|
2008-04-12 15:51:08 +00:00
|
|
|
if (chapter >= 0 && chapter < demuxer->num_chapters
|
|
|
|
&& demuxer->chapters[chapter].name)
|
2007-12-13 12:51:05 +00:00
|
|
|
return strdup(demuxer->chapters[chapter].name);
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2008-04-12 15:51:08 +00:00
|
|
|
char *demuxer_chapter_display_name(demuxer_t *demuxer, int chapter)
|
|
|
|
{
|
2007-12-13 12:51:05 +00:00
|
|
|
char *chapter_name = demuxer_chapter_name(demuxer, chapter);
|
|
|
|
if (chapter_name) {
|
|
|
|
char *tmp = malloc(strlen(chapter_name) + 14);
|
|
|
|
snprintf(tmp, 63, "(%d) %s", chapter + 1, chapter_name);
|
2008-04-12 15:51:08 +00:00
|
|
|
free(chapter_name);
|
2007-12-13 12:51:05 +00:00
|
|
|
return tmp;
|
2008-04-12 15:51:08 +00:00
|
|
|
} else {
|
2007-12-13 12:51:05 +00:00
|
|
|
int chapter_num = demuxer_chapter_count(demuxer);
|
|
|
|
char tmp[30];
|
|
|
|
if (chapter_num <= 0)
|
|
|
|
sprintf(tmp, "(%d)", chapter + 1);
|
|
|
|
else
|
|
|
|
sprintf(tmp, "(%d) of %d", chapter + 1, chapter_num);
|
|
|
|
return strdup(tmp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-04-12 15:51:08 +00:00
|
|
|
float demuxer_chapter_time(demuxer_t *demuxer, int chapter, float *end)
|
|
|
|
{
|
2007-12-13 12:51:05 +00:00
|
|
|
if (demuxer->num_chapters && demuxer->chapters && chapter >= 0
|
2008-04-12 15:51:08 +00:00
|
|
|
&& chapter < demuxer->num_chapters) {
|
2007-12-13 12:51:05 +00:00
|
|
|
if (end)
|
|
|
|
*end = demuxer->chapters[chapter].end / 1000.0;
|
|
|
|
return demuxer->chapters[chapter].start / 1000.0;
|
|
|
|
}
|
|
|
|
return -1.0;
|
|
|
|
}
|
|
|
|
|
2008-04-12 15:51:08 +00:00
|
|
|
int demuxer_chapter_count(demuxer_t *demuxer)
|
|
|
|
{
|
2007-12-13 12:51:05 +00:00
|
|
|
if (!demuxer->num_chapters || !demuxer->chapters) {
|
|
|
|
int num_chapters = 0;
|
|
|
|
if (stream_control(demuxer->stream, STREAM_CTRL_GET_NUM_CHAPTERS,
|
|
|
|
&num_chapters) == STREAM_UNSUPPORTED)
|
|
|
|
num_chapters = 0;
|
|
|
|
return num_chapters;
|
2008-04-12 15:51:08 +00:00
|
|
|
} else
|
2007-12-13 12:51:05 +00:00
|
|
|
return demuxer->num_chapters;
|
|
|
|
}
|
|
|
|
|
2008-04-12 15:51:08 +00:00
|
|
|
int demuxer_angles_count(demuxer_t *demuxer)
|
|
|
|
{
|
|
|
|
int ris, angles = -1;
|
2008-01-05 14:28:57 +00:00
|
|
|
|
|
|
|
ris = stream_control(demuxer->stream, STREAM_CTRL_GET_NUM_ANGLES, &angles);
|
2008-04-12 15:51:08 +00:00
|
|
|
if (ris == STREAM_UNSUPPORTED)
|
|
|
|
return -1;
|
2008-01-05 14:28:57 +00:00
|
|
|
return angles;
|
|
|
|
}
|
|
|
|
|
2008-04-12 15:51:08 +00:00
|
|
|
int demuxer_get_current_angle(demuxer_t *demuxer)
|
|
|
|
{
|
|
|
|
int ris, curr_angle = -1;
|
2008-01-05 14:28:57 +00:00
|
|
|
ris = stream_control(demuxer->stream, STREAM_CTRL_GET_ANGLE, &curr_angle);
|
2008-04-12 15:51:08 +00:00
|
|
|
if (ris == STREAM_UNSUPPORTED)
|
|
|
|
return -1;
|
2008-01-05 14:28:57 +00:00
|
|
|
return curr_angle;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-04-12 15:51:08 +00:00
|
|
|
int demuxer_set_angle(demuxer_t *demuxer, int angle)
|
|
|
|
{
|
|
|
|
int ris, angles = -1;
|
2008-01-05 14:28:57 +00:00
|
|
|
sh_video_t *sh_video = demuxer->video->sh;
|
|
|
|
sh_audio_t *sh_audio = demuxer->audio->sh;
|
|
|
|
|
|
|
|
angles = demuxer_angles_count(demuxer);
|
2008-04-12 15:51:08 +00:00
|
|
|
if ((angles < 1) || (angle > angles))
|
|
|
|
return -1;
|
2008-01-05 14:28:57 +00:00
|
|
|
|
2008-04-12 15:51:08 +00:00
|
|
|
if (demuxer->video->sh)
|
2008-01-05 14:28:57 +00:00
|
|
|
ds_free_packs(demuxer->video);
|
|
|
|
|
2008-04-12 15:51:08 +00:00
|
|
|
if (demuxer->audio->sh)
|
2008-01-05 14:28:57 +00:00
|
|
|
ds_free_packs(demuxer->audio);
|
|
|
|
|
2008-04-12 15:51:08 +00:00
|
|
|
if (demuxer->sub->id >= 0)
|
2008-01-05 14:28:57 +00:00
|
|
|
ds_free_packs(demuxer->sub);
|
|
|
|
|
|
|
|
ris = stream_control(demuxer->stream, STREAM_CTRL_SET_ANGLE, &angle);
|
2008-04-12 15:51:08 +00:00
|
|
|
if (ris == STREAM_UNSUPPORTED)
|
|
|
|
return -1;
|
2008-01-05 14:28:57 +00:00
|
|
|
|
|
|
|
demux_control(demuxer, DEMUXER_CTRL_RESYNC, NULL);
|
2008-04-12 15:51:08 +00:00
|
|
|
if (sh_video) {
|
2008-01-05 14:28:57 +00:00
|
|
|
ds_fill_buffer(demuxer->video);
|
|
|
|
resync_video_stream(sh_video);
|
|
|
|
}
|
|
|
|
|
2008-04-12 15:51:08 +00:00
|
|
|
if (sh_audio) {
|
2008-01-05 14:28:57 +00:00
|
|
|
ds_fill_buffer(demuxer->audio);
|
|
|
|
resync_audio_stream(sh_audio);
|
|
|
|
}
|
|
|
|
|
|
|
|
return angle;
|
|
|
|
}
|
2008-02-29 17:25:43 +00:00
|
|
|
|
2008-04-12 15:51:08 +00:00
|
|
|
int demuxer_audio_track_by_lang(demuxer_t *d, char *lang)
|
2008-02-29 17:25:43 +00:00
|
|
|
{
|
|
|
|
int i, len;
|
|
|
|
lang += strspn(lang, ",");
|
2008-04-12 15:51:08 +00:00
|
|
|
while ((len = strcspn(lang, ",")) > 0) {
|
|
|
|
for (i = 0; i < MAX_A_STREAMS; ++i) {
|
|
|
|
sh_audio_t *sh = d->a_streams[i];
|
2008-02-29 17:25:43 +00:00
|
|
|
if (sh && sh->lang && strncmp(sh->lang, lang, len) == 0)
|
|
|
|
return sh->aid;
|
|
|
|
}
|
|
|
|
lang += len;
|
|
|
|
lang += strspn(lang, ",");
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2008-04-12 15:51:08 +00:00
|
|
|
int demuxer_sub_track_by_lang(demuxer_t *d, char *lang)
|
2008-02-29 17:25:43 +00:00
|
|
|
{
|
|
|
|
int i, len;
|
|
|
|
lang += strspn(lang, ",");
|
2008-04-12 15:51:08 +00:00
|
|
|
while ((len = strcspn(lang, ",")) > 0) {
|
|
|
|
for (i = 0; i < MAX_S_STREAMS; ++i) {
|
|
|
|
sh_sub_t *sh = d->s_streams[i];
|
2008-02-29 17:25:43 +00:00
|
|
|
if (sh && sh->lang && strncmp(sh->lang, lang, len) == 0)
|
|
|
|
return sh->sid;
|
|
|
|
}
|
|
|
|
lang += len;
|
|
|
|
lang += strspn(lang, ",");
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
2008-03-30 16:55:46 +00:00
|
|
|
|
2008-04-12 15:51:08 +00:00
|
|
|
int demuxer_default_audio_track(demuxer_t *d)
|
2008-03-30 16:55:46 +00:00
|
|
|
{
|
|
|
|
int i;
|
2008-04-12 15:51:08 +00:00
|
|
|
for (i = 0; i < MAX_A_STREAMS; ++i) {
|
|
|
|
sh_audio_t *sh = d->a_streams[i];
|
2008-03-30 16:55:46 +00:00
|
|
|
if (sh && sh->default_track)
|
|
|
|
return sh->aid;
|
|
|
|
}
|
2008-04-12 15:51:08 +00:00
|
|
|
for (i = 0; i < MAX_A_STREAMS; ++i) {
|
|
|
|
sh_audio_t *sh = d->a_streams[i];
|
2008-03-30 16:55:46 +00:00
|
|
|
if (sh)
|
|
|
|
return sh->aid;
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2008-04-12 15:51:08 +00:00
|
|
|
int demuxer_default_sub_track(demuxer_t *d)
|
2008-03-30 16:55:46 +00:00
|
|
|
{
|
|
|
|
int i;
|
2008-04-12 15:51:08 +00:00
|
|
|
for (i = 0; i < MAX_S_STREAMS; ++i) {
|
|
|
|
sh_sub_t *sh = d->s_streams[i];
|
2008-03-30 16:55:46 +00:00
|
|
|
if (sh && sh->default_track)
|
|
|
|
return sh->sid;
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|