2001-02-24 21:28:24 +01:00
|
|
|
//=================== DEMUXER v2.5 =========================
|
|
|
|
|
2001-04-23 05:42:17 +02:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2001-11-27 01:42:39 +01:00
|
|
|
#include <string.h>
|
2001-08-01 11:14:02 +02:00
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
2001-02-24 21:28:24 +01:00
|
|
|
|
2001-07-22 00:37:55 +02:00
|
|
|
#include "config.h"
|
2001-08-17 02:40:25 +02:00
|
|
|
#include "mp_msg.h"
|
2001-08-18 22:32:09 +02:00
|
|
|
#include "help_mp.h"
|
2002-02-20 17:59:25 +01:00
|
|
|
#include "../cfgparser.h"
|
2001-07-22 00:37:55 +02:00
|
|
|
|
2001-04-23 05:42:17 +02:00
|
|
|
#include "stream.h"
|
|
|
|
#include "demuxer.h"
|
2001-07-22 00:37:55 +02:00
|
|
|
#include "stheader.h"
|
2002-02-06 21:16:35 +01:00
|
|
|
#include "mf.h"
|
2001-07-22 00:37:55 +02:00
|
|
|
|
2002-03-15 16:53:11 +01:00
|
|
|
#include "../libvo/fastmemcpy.h"
|
|
|
|
|
2001-08-23 01:54:57 +02:00
|
|
|
void free_demuxer_stream(demux_stream_t *ds){
|
|
|
|
ds_free_packs(ds);
|
|
|
|
free(ds);
|
|
|
|
}
|
|
|
|
|
2001-02-24 21:28:24 +01: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;
|
2001-05-10 05:39:54 +02:00
|
|
|
ds->pts_bytes=0;
|
2001-02-24 21:28:24 +01:00
|
|
|
ds->eof=0;
|
|
|
|
ds->pos=0;
|
|
|
|
ds->dpos=0;
|
2001-05-27 02:02:12 +02:00
|
|
|
ds->pack_no=0;
|
2001-02-24 21:28:24 +01:00
|
|
|
//---------------
|
|
|
|
ds->packs=0;
|
|
|
|
ds->bytes=0;
|
|
|
|
ds->first=ds->last=NULL;
|
|
|
|
ds->id=id;
|
|
|
|
ds->demuxer=demuxer;
|
|
|
|
//----------------
|
|
|
|
ds->asf_seq=-1;
|
|
|
|
ds->asf_packet=NULL;
|
2001-10-23 15:55:49 +02:00
|
|
|
//----------------
|
|
|
|
ds->ss_mul=ds->ss_div=1;
|
2001-04-06 03:18:59 +02:00
|
|
|
//----------------
|
|
|
|
ds->sh=NULL;
|
2001-02-24 21:28:24 +01:00
|
|
|
return ds;
|
|
|
|
}
|
|
|
|
|
2001-04-21 00:35:15 +02:00
|
|
|
demuxer_t* new_demuxer(stream_t *stream,int type,int a_id,int v_id,int s_id){
|
2001-02-24 21:28:24 +01:00
|
|
|
demuxer_t *d=malloc(sizeof(demuxer_t));
|
2001-04-23 05:42:17 +02:00
|
|
|
memset(d,0,sizeof(demuxer_t));
|
2001-02-24 21:28:24 +01:00
|
|
|
d->stream=stream;
|
2001-04-23 23:25:09 +02:00
|
|
|
d->movi_start=stream->start_pos;
|
|
|
|
d->movi_end=stream->end_pos;
|
2001-08-22 18:42:37 +02:00
|
|
|
d->seekable=1;
|
2001-02-24 21:28:24 +01:00
|
|
|
d->synced=0;
|
|
|
|
d->filepos=0;
|
|
|
|
d->audio=new_demuxer_stream(d,a_id);
|
|
|
|
d->video=new_demuxer_stream(d,v_id);
|
2001-04-21 00:35:15 +02:00
|
|
|
d->sub=new_demuxer_stream(d,s_id);
|
2001-02-24 21:28:24 +01:00
|
|
|
d->type=type;
|
2001-08-12 19:28:16 +02:00
|
|
|
stream_reset(stream);
|
|
|
|
stream_seek(stream,stream->start_pos);
|
2001-02-24 21:28:24 +01:00
|
|
|
return d;
|
|
|
|
}
|
|
|
|
|
2002-03-15 16:53:11 +01:00
|
|
|
sh_audio_t *get_sh_audio(demuxer_t *demuxer, int id)
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
return demuxer->a_streams[id];
|
|
|
|
}
|
|
|
|
|
2001-07-22 00:37:55 +02:00
|
|
|
sh_audio_t* new_sh_audio(demuxer_t *demuxer,int id){
|
2002-03-15 16:53:11 +01:00
|
|
|
if(id > MAX_A_STREAMS-1 || id < 0)
|
2002-02-10 19:09:20 +01:00
|
|
|
{
|
|
|
|
mp_msg(MSGT_DEMUXER,MSGL_WARN,"Requested audio stream id overflow (%d > %d)\n",
|
|
|
|
id, MAX_A_STREAMS);
|
|
|
|
return NULL;
|
|
|
|
}
|
2001-07-22 00:37:55 +02:00
|
|
|
if(demuxer->a_streams[id]){
|
2001-08-18 22:32:09 +02:00
|
|
|
mp_msg(MSGT_DEMUXER,MSGL_WARN,MSGTR_AudioStreamRedefined,id);
|
2001-07-22 00:37:55 +02:00
|
|
|
} else {
|
2001-08-17 02:40:25 +02:00
|
|
|
mp_msg(MSGT_DEMUXER,MSGL_V,"==> Found audio stream: %d\n",id);
|
2001-07-22 00:37:55 +02:00
|
|
|
demuxer->a_streams[id]=malloc(sizeof(sh_audio_t));
|
|
|
|
memset(demuxer->a_streams[id],0,sizeof(sh_audio_t));
|
|
|
|
}
|
|
|
|
return demuxer->a_streams[id];
|
|
|
|
}
|
|
|
|
|
2001-08-23 01:54:57 +02:00
|
|
|
void free_sh_audio(sh_audio_t* sh){
|
2002-03-31 04:45:14 +02:00
|
|
|
mp_msg(MSGT_DEMUXER,MSGL_V,"DEMUXER: freeing sh_audio at %p \n",sh);
|
2001-08-23 01:54:57 +02:00
|
|
|
if(sh->wf) free(sh->wf);
|
|
|
|
free(sh);
|
|
|
|
}
|
|
|
|
|
2002-03-15 16:53:11 +01:00
|
|
|
sh_video_t *get_sh_video(demuxer_t *demuxer, int id)
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
return demuxer->v_streams[id];
|
|
|
|
}
|
|
|
|
|
2001-07-22 00:37:55 +02:00
|
|
|
sh_video_t* new_sh_video(demuxer_t *demuxer,int id){
|
2002-03-15 16:53:11 +01:00
|
|
|
if(id > MAX_V_STREAMS-1 || id < 0)
|
2002-02-10 19:09:20 +01:00
|
|
|
{
|
|
|
|
mp_msg(MSGT_DEMUXER,MSGL_WARN,"Requested video stream id overflow (%d > %d)\n",
|
|
|
|
id, MAX_V_STREAMS);
|
|
|
|
return NULL;
|
|
|
|
}
|
2001-07-22 00:37:55 +02:00
|
|
|
if(demuxer->v_streams[id]){
|
2001-08-18 22:32:09 +02:00
|
|
|
mp_msg(MSGT_DEMUXER,MSGL_WARN,MSGTR_VideoStreamRedefined,id);
|
2001-07-22 00:37:55 +02:00
|
|
|
} else {
|
2001-08-17 02:40:25 +02:00
|
|
|
mp_msg(MSGT_DEMUXER,MSGL_V,"==> Found video stream: %d\n",id);
|
2001-07-22 00:37:55 +02:00
|
|
|
demuxer->v_streams[id]=malloc(sizeof(sh_video_t));
|
|
|
|
memset(demuxer->v_streams[id],0,sizeof(sh_video_t));
|
|
|
|
}
|
|
|
|
return demuxer->v_streams[id];
|
|
|
|
}
|
|
|
|
|
2001-08-23 01:54:57 +02:00
|
|
|
void free_sh_video(sh_video_t* sh){
|
2002-03-31 04:45:14 +02:00
|
|
|
mp_msg(MSGT_DEMUXER,MSGL_V,"DEMUXER: freeing sh_video at %p \n",sh);
|
2001-08-23 14:47:23 +02:00
|
|
|
if(sh->bih) free(sh->bih);
|
2001-08-23 01:54:57 +02:00
|
|
|
free(sh);
|
|
|
|
}
|
|
|
|
|
2002-04-24 17:36:07 +02:00
|
|
|
extern void demux_close_vivo(demuxer_t *demuxer);
|
|
|
|
extern void demux_close_real(demuxer_t *demuxer);
|
|
|
|
extern void demux_close_y4m(demuxer_t *demuxer);
|
|
|
|
extern void demux_close_mf(demuxer_t* demuxer);
|
|
|
|
extern void demux_close_roq(demuxer_t* demuxer);
|
|
|
|
extern void demux_close_film(demuxer_t* demuxer);
|
|
|
|
extern void demux_close_bmp(demuxer_t* demuxer);
|
|
|
|
extern void demux_close_fli(demuxer_t* demuxer);
|
|
|
|
extern void demux_close_nuv(demuxer_t* demuxer);
|
|
|
|
|
2001-08-23 01:54:57 +02:00
|
|
|
void free_demuxer(demuxer_t *demuxer){
|
|
|
|
int i;
|
2002-03-31 04:45:14 +02:00
|
|
|
mp_msg(MSGT_DEMUXER,MSGL_V,"DEMUXER: freeing demuxer at %p \n",demuxer);
|
2002-04-24 17:36:07 +02:00
|
|
|
switch(demuxer->type) {
|
|
|
|
case DEMUXER_TYPE_VIVO:
|
|
|
|
demux_close_vivo(demuxer); break;
|
|
|
|
case DEMUXER_TYPE_REAL:
|
|
|
|
demux_close_real(demuxer); break;
|
|
|
|
case DEMUXER_TYPE_Y4M:
|
|
|
|
demux_close_y4m(demuxer); break;
|
|
|
|
case DEMUXER_TYPE_MF:
|
|
|
|
demux_close_mf(demuxer); break;
|
|
|
|
case DEMUXER_TYPE_ROQ:
|
|
|
|
demux_close_roq(demuxer); break;
|
|
|
|
case DEMUXER_TYPE_FILM:
|
|
|
|
demux_close_film(demuxer); break;
|
|
|
|
case DEMUXER_TYPE_BMP:
|
|
|
|
demux_close_bmp(demuxer); break;
|
|
|
|
case DEMUXER_TYPE_FLI:
|
|
|
|
demux_close_fli(demuxer); break;
|
|
|
|
case DEMUXER_TYPE_NUV:
|
|
|
|
demux_close_nuv(demuxer); break;
|
|
|
|
}
|
2001-08-23 01:54:57 +02:00
|
|
|
// free streams:
|
|
|
|
for(i=0;i<256;i++){
|
|
|
|
if(demuxer->a_streams[i]) free_sh_audio(demuxer->a_streams[i]);
|
|
|
|
if(demuxer->v_streams[i]) free_sh_video(demuxer->v_streams[i]);
|
|
|
|
}
|
|
|
|
//if(sh_audio) free_sh_audio(sh_audio);
|
|
|
|
//if(sh_video) free_sh_video(sh_video);
|
|
|
|
// free demuxers:
|
|
|
|
free_demuxer_stream(demuxer->audio);
|
|
|
|
free_demuxer_stream(demuxer->video);
|
2002-03-31 04:45:14 +02:00
|
|
|
free_demuxer_stream(demuxer->sub);
|
2002-02-14 14:04:35 +01:00
|
|
|
if(demuxer->info) {
|
|
|
|
for(i=0;demuxer->info[i] != NULL; i++)
|
|
|
|
free(demuxer->info[i]);
|
|
|
|
free(demuxer->info);
|
|
|
|
}
|
2001-08-23 01:54:57 +02:00
|
|
|
free(demuxer);
|
|
|
|
}
|
|
|
|
|
2001-07-22 00:37:55 +02:00
|
|
|
|
2001-04-23 05:42:17 +02:00
|
|
|
void ds_add_packet(demux_stream_t *ds,demux_packet_t* dp){
|
2001-02-24 21:28:24 +01:00
|
|
|
// demux_packet_t* dp=new_demux_packet(len);
|
|
|
|
// stream_read(stream,dp->buffer,len);
|
|
|
|
// dp->pts=pts; //(float)pts/90000.0f;
|
|
|
|
// dp->pos=pos;
|
|
|
|
// append packet to DS stream:
|
|
|
|
++ds->packs;
|
|
|
|
ds->bytes+=dp->len;
|
|
|
|
if(ds->last){
|
|
|
|
// next packet in stream
|
|
|
|
ds->last->next=dp;
|
|
|
|
ds->last=dp;
|
|
|
|
} else {
|
|
|
|
// first packet in stream
|
|
|
|
ds->first=ds->last=dp;
|
|
|
|
}
|
2001-08-17 02:40:25 +02: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",
|
2001-02-24 21:28:24 +01:00
|
|
|
(ds==ds->demuxer->audio)?"d_audio":"d_video",
|
2001-08-01 01:18:16 +02:00
|
|
|
dp->len,dp->pts,(unsigned int)dp->pos,ds->demuxer->audio->packs,ds->demuxer->video->packs);
|
2001-02-24 21:28:24 +01:00
|
|
|
}
|
|
|
|
|
2001-08-01 01:18:16 +02:00
|
|
|
void ds_read_packet(demux_stream_t *ds,stream_t *stream,int len,float pts,off_t pos,int flags){
|
2001-02-24 21:28:24 +01:00
|
|
|
demux_packet_t* dp=new_demux_packet(len);
|
|
|
|
stream_read(stream,dp->buffer,len);
|
|
|
|
dp->pts=pts; //(float)pts/90000.0f;
|
|
|
|
dp->pos=pos;
|
2001-06-04 01:37:20 +02:00
|
|
|
dp->flags=flags;
|
2001-02-24 21:28:24 +01:00
|
|
|
// append packet to DS stream:
|
|
|
|
ds_add_packet(ds,dp);
|
|
|
|
}
|
|
|
|
|
|
|
|
// return value:
|
|
|
|
// 0 = EOF or no stream found or invalid type
|
|
|
|
// 1 = successfully read a packet
|
2002-02-06 21:16:35 +01:00
|
|
|
int demux_mf_fill_buffer( demuxer_t *demux);
|
2002-02-01 06:35:16 +01:00
|
|
|
int demux_roq_fill_buffer(demuxer_t *demux);
|
2002-01-16 04:25:07 +01:00
|
|
|
int demux_film_fill_buffer(demuxer_t *demux);
|
2002-03-20 06:15:53 +01:00
|
|
|
int demux_bmp_fill_buffer(demuxer_t *demux);
|
2001-11-25 00:58:12 +01:00
|
|
|
int demux_fli_fill_buffer(demuxer_t *demux);
|
2001-02-24 21:28:24 +01:00
|
|
|
int demux_mpg_es_fill_buffer(demuxer_t *demux);
|
|
|
|
int demux_mpg_fill_buffer(demuxer_t *demux);
|
|
|
|
int demux_avi_fill_buffer(demuxer_t *demux);
|
|
|
|
int demux_avi_fill_buffer_ni(demuxer_t *demux,demux_stream_t *ds);
|
|
|
|
int demux_avi_fill_buffer_nini(demuxer_t *demux,demux_stream_t *ds);
|
|
|
|
int demux_asf_fill_buffer(demuxer_t *demux);
|
2001-10-06 13:29:18 +02:00
|
|
|
int demux_mov_fill_buffer(demuxer_t *demux,demux_stream_t* ds);
|
2001-11-04 17:57:09 +01:00
|
|
|
int demux_vivo_fill_buffer(demuxer_t *demux);
|
2001-12-27 22:24:56 +01:00
|
|
|
int demux_real_fill_buffer(demuxer_t *demuxer);
|
|
|
|
int demux_nuv_fill_buffer(demuxer_t *demux);
|
2001-11-10 00:46:06 +01:00
|
|
|
#ifdef USE_TV
|
2001-11-11 00:32:10 +01:00
|
|
|
#include "tv.h"
|
|
|
|
extern tvi_handle_t *tv_handler;
|
2001-11-16 22:30:10 +01:00
|
|
|
extern int tv_param_on;
|
|
|
|
|
2002-04-12 12:40:38 +02:00
|
|
|
extern int demux_tv_fill_buffer(demuxer_t *demux, demux_stream_t *ds, tvi_handle_t *tvh);
|
2001-11-16 22:30:10 +01:00
|
|
|
extern int demux_open_tv(demuxer_t *demuxer, tvi_handle_t *tvh);
|
2001-11-10 00:46:06 +01:00
|
|
|
#endif
|
2001-12-27 03:08:31 +01:00
|
|
|
int demux_y4m_fill_buffer(demuxer_t *demux);
|
2002-02-14 14:04:35 +01:00
|
|
|
int demux_audio_fill_buffer(demux_stream_t *ds);
|
2002-02-20 17:59:25 +01:00
|
|
|
extern int demux_demuxers_fill_buffer(demuxer_t *demux,demux_stream_t *ds);
|
2002-03-16 15:32:03 +01:00
|
|
|
extern int demux_ogg_fill_buffer(demuxer_t *d);
|
2001-02-24 21:28:24 +01:00
|
|
|
|
|
|
|
int demux_fill_buffer(demuxer_t *demux,demux_stream_t *ds){
|
|
|
|
// Note: parameter 'ds' can be NULL!
|
2001-07-22 00:37:55 +02:00
|
|
|
// printf("demux->type=%d\n",demux->type);
|
2001-02-24 21:28:24 +01:00
|
|
|
switch(demux->type){
|
2002-02-06 21:16:35 +01:00
|
|
|
case DEMUXER_TYPE_MF: return demux_mf_fill_buffer(demux);
|
2002-02-01 06:35:16 +01:00
|
|
|
case DEMUXER_TYPE_ROQ: return demux_roq_fill_buffer(demux);
|
2002-01-16 04:25:07 +01:00
|
|
|
case DEMUXER_TYPE_FILM: return demux_film_fill_buffer(demux);
|
2002-03-20 06:15:53 +01:00
|
|
|
case DEMUXER_TYPE_BMP: return demux_bmp_fill_buffer(demux);
|
2001-11-25 00:58:12 +01:00
|
|
|
case DEMUXER_TYPE_FLI: return demux_fli_fill_buffer(demux);
|
2001-02-24 21:28:24 +01:00
|
|
|
case DEMUXER_TYPE_MPEG_ES: return demux_mpg_es_fill_buffer(demux);
|
|
|
|
case DEMUXER_TYPE_MPEG_PS: return demux_mpg_fill_buffer(demux);
|
|
|
|
case DEMUXER_TYPE_AVI: return demux_avi_fill_buffer(demux);
|
|
|
|
case DEMUXER_TYPE_AVI_NI: return demux_avi_fill_buffer_ni(demux,ds);
|
|
|
|
case DEMUXER_TYPE_AVI_NINI: return demux_avi_fill_buffer_nini(demux,ds);
|
|
|
|
case DEMUXER_TYPE_ASF: return demux_asf_fill_buffer(demux);
|
2001-10-06 13:29:18 +02:00
|
|
|
case DEMUXER_TYPE_MOV: return demux_mov_fill_buffer(demux,ds);
|
2001-11-04 17:57:09 +01:00
|
|
|
case DEMUXER_TYPE_VIVO: return demux_vivo_fill_buffer(demux);
|
2001-12-26 23:57:51 +01:00
|
|
|
case DEMUXER_TYPE_REAL: return demux_real_fill_buffer(demux);
|
2001-12-27 22:24:56 +01:00
|
|
|
case DEMUXER_TYPE_NUV: return demux_nuv_fill_buffer(demux);
|
2001-11-10 00:46:06 +01:00
|
|
|
#ifdef USE_TV
|
2002-04-12 12:40:38 +02:00
|
|
|
case DEMUXER_TYPE_TV: return demux_tv_fill_buffer(demux, ds, tv_handler);
|
2001-11-10 00:46:06 +01:00
|
|
|
#endif
|
2001-12-27 03:08:31 +01:00
|
|
|
case DEMUXER_TYPE_Y4M: return demux_y4m_fill_buffer(demux);
|
2002-02-14 14:04:35 +01:00
|
|
|
case DEMUXER_TYPE_AUDIO: return demux_audio_fill_buffer(ds);
|
2002-02-20 17:59:25 +01:00
|
|
|
case DEMUXER_TYPE_DEMUXERS: return demux_demuxers_fill_buffer(demux,ds);
|
2002-03-16 15:32:03 +01:00
|
|
|
case DEMUXER_TYPE_OGG: return demux_ogg_fill_buffer(demux);
|
2001-02-24 21:28:24 +01:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// return value:
|
|
|
|
// 0 = EOF
|
|
|
|
// 1 = succesfull
|
2001-04-23 05:42:17 +02:00
|
|
|
int ds_fill_buffer(demux_stream_t *ds){
|
2001-02-24 21:28:24 +01:00
|
|
|
demuxer_t *demux=ds->demuxer;
|
|
|
|
if(ds->buffer) free(ds->buffer);
|
|
|
|
if(verbose>2){
|
2001-08-17 02:40:25 +02:00
|
|
|
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
|
2002-04-03 19:49:40 +02:00
|
|
|
if(ds==demux->sub) mp_dbg(MSGT_DEMUXER,MSGL_DBG3,"ds_fill_buffer(d_sub) called\n");else
|
2001-08-17 02:40:25 +02:00
|
|
|
mp_dbg(MSGT_DEMUXER,MSGL_DBG3,"ds_fill_buffer(unknown 0x%X) called\n",(unsigned int)ds);
|
2001-02-24 21:28:24 +01:00
|
|
|
}
|
|
|
|
while(1){
|
|
|
|
if(ds->packs){
|
|
|
|
demux_packet_t *p=ds->first;
|
|
|
|
// copy useful data:
|
|
|
|
ds->buffer=p->buffer;
|
|
|
|
ds->buffer_pos=0;
|
|
|
|
ds->buffer_size=p->len;
|
|
|
|
ds->pos=p->pos;
|
|
|
|
ds->dpos+=p->len; // !!!
|
2001-05-27 02:02:12 +02:00
|
|
|
++ds->pack_no;
|
2001-05-10 05:39:54 +02:00
|
|
|
if(p->pts){
|
|
|
|
ds->pts=p->pts;
|
|
|
|
ds->pts_bytes=0;
|
|
|
|
}
|
|
|
|
ds->pts_bytes+=p->len; // !!!
|
2001-06-04 01:37:20 +02:00
|
|
|
ds->flags=p->flags;
|
2001-02-24 21:28:24 +01:00
|
|
|
// free packet:
|
|
|
|
ds->bytes-=p->len;
|
|
|
|
ds->first=p->next;
|
|
|
|
if(!ds->first) ds->last=NULL;
|
|
|
|
free(p);
|
|
|
|
--ds->packs;
|
|
|
|
return 1; //ds->buffer_size;
|
|
|
|
}
|
|
|
|
if(demux->audio->packs>=MAX_PACKS || demux->audio->bytes>=MAX_PACK_BYTES){
|
2001-08-18 22:32:09 +02:00
|
|
|
mp_msg(MSGT_DEMUXER,MSGL_ERR,MSGTR_TooManyAudioInBuffer,demux->audio->packs,demux->audio->bytes);
|
|
|
|
mp_msg(MSGT_DEMUXER,MSGL_HINT,MSGTR_MaybeNI);
|
2001-02-24 21:28:24 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
if(demux->video->packs>=MAX_PACKS || demux->video->bytes>=MAX_PACK_BYTES){
|
2001-08-18 22:32:09 +02:00
|
|
|
mp_msg(MSGT_DEMUXER,MSGL_ERR,MSGTR_TooManyVideoInBuffer,demux->video->packs,demux->video->bytes);
|
|
|
|
mp_msg(MSGT_DEMUXER,MSGL_HINT,MSGTR_MaybeNI);
|
2001-02-24 21:28:24 +01:00
|
|
|
break;
|
|
|
|
}
|
2001-07-29 23:07:34 +02:00
|
|
|
if(!demux_fill_buffer(demux,ds)){
|
2001-08-17 02:40:25 +02:00
|
|
|
mp_dbg(MSGT_DEMUXER,MSGL_DBG2,"ds_fill_buffer()->demux_fill_buffer() failed\n");
|
2001-07-29 23:07:34 +02:00
|
|
|
break; // EOF
|
|
|
|
}
|
2001-02-24 21:28:24 +01:00
|
|
|
}
|
|
|
|
ds->buffer_pos=ds->buffer_size=0;
|
|
|
|
ds->buffer=NULL;
|
2001-08-17 02:40:25 +02:00
|
|
|
mp_msg(MSGT_DEMUXER,MSGL_V,"ds_fill_buffer: EOF reached (stream: %s) \n",ds==demux->audio?"audio":"video");
|
2001-02-24 21:28:24 +01:00
|
|
|
ds->eof=1;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2001-04-23 05:42:17 +02:00
|
|
|
int demux_read_data(demux_stream_t *ds,unsigned char* mem,int len){
|
2001-02-24 21:28:24 +01:00
|
|
|
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) memcpy(mem+bytes,&ds->buffer[ds->buffer_pos],x);
|
|
|
|
bytes+=x;len-=x;ds->buffer_pos+=x;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return bytes;
|
|
|
|
}
|
|
|
|
|
2001-05-10 05:39:54 +02:00
|
|
|
int demux_read_data_pack(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) memcpy(mem+bytes,&ds->buffer[ds->buffer_pos],x);
|
|
|
|
bytes+=x;len-=x;ds->buffer_pos+=x;
|
|
|
|
return bytes; // stop at end of package! (for correct timestamping)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return bytes;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-02-24 21:28:24 +01:00
|
|
|
void ds_free_packs(demux_stream_t *ds){
|
|
|
|
demux_packet_t *dp=ds->first;
|
|
|
|
while(dp){
|
|
|
|
demux_packet_t *dn=dp->next;
|
2002-04-03 17:40:13 +02:00
|
|
|
if(dp->buffer) free(dp->buffer);
|
2001-02-24 21:28:24 +01:00
|
|
|
free(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->buffer) free(ds->buffer);
|
|
|
|
ds->buffer=NULL;
|
|
|
|
ds->buffer_pos=ds->buffer_size;
|
2001-05-18 00:15:00 +02:00
|
|
|
ds->pts=0; ds->pts_bytes=0;
|
2001-02-24 21:28:24 +01:00
|
|
|
}
|
|
|
|
|
2001-04-23 05:42:17 +02:00
|
|
|
int ds_get_packet(demux_stream_t *ds,unsigned char **start){
|
2001-02-24 21:28:24 +01:00
|
|
|
while(1){
|
|
|
|
int len;
|
|
|
|
if(ds->buffer_pos>=ds->buffer_size){
|
|
|
|
if(!ds_fill_buffer(ds)){
|
|
|
|
// EOF
|
|
|
|
*start = NULL;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
len=ds->buffer_size-ds->buffer_pos;
|
|
|
|
*start = &ds->buffer[ds->buffer_pos];
|
|
|
|
ds->buffer_pos+=len;
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
}
|
2001-04-21 01:00:11 +02:00
|
|
|
|
2001-04-23 05:42:17 +02:00
|
|
|
int ds_get_packet_sub(demux_stream_t *ds,unsigned char **start){
|
2001-04-21 01:00:11 +02:00
|
|
|
while(1){
|
|
|
|
int len;
|
|
|
|
if(ds->buffer_pos>=ds->buffer_size){
|
|
|
|
*start = NULL;
|
|
|
|
if(!ds->packs) return -1; // no sub
|
|
|
|
if(!ds_fill_buffer(ds)) return -1; // EOF
|
|
|
|
}
|
|
|
|
len=ds->buffer_size-ds->buffer_pos;
|
|
|
|
*start = &ds->buffer[ds->buffer_pos];
|
|
|
|
ds->buffer_pos+=len;
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-07-22 00:37:55 +02:00
|
|
|
// ====================================================================
|
|
|
|
|
|
|
|
// feed-back from demuxers:
|
|
|
|
extern int num_elementary_packets100; // for MPEG-ES fileformat detection
|
|
|
|
extern int num_elementary_packets101;
|
|
|
|
extern int num_elementary_packetsPES;
|
2001-08-23 15:20:25 +02:00
|
|
|
extern int num_elementary_packets1B6;
|
2002-02-17 03:11:14 +01:00
|
|
|
extern int num_mp3audio_packets;
|
2001-07-22 00:37:55 +02:00
|
|
|
|
|
|
|
// commandline options, flags:
|
2001-08-12 19:28:16 +02:00
|
|
|
//extern int seek_to_byte;
|
2001-07-22 00:37:55 +02:00
|
|
|
extern int force_ni;
|
|
|
|
extern int pts_from_bps;
|
|
|
|
|
|
|
|
extern int audio_id;
|
|
|
|
extern int video_id;
|
|
|
|
extern int dvdsub_id;
|
|
|
|
|
|
|
|
int asf_check_header(demuxer_t *demuxer);
|
|
|
|
int read_asf_header(demuxer_t *demuxer);
|
|
|
|
demux_stream_t* demux_avi_select_stream(demuxer_t *demux,unsigned int id);
|
2001-10-02 23:45:41 +02:00
|
|
|
demuxer_t* demux_open_avi(demuxer_t* demuxer);
|
|
|
|
int mov_check_file(demuxer_t* demuxer);
|
|
|
|
int mov_read_header(demuxer_t* demuxer);
|
2001-11-25 00:58:12 +01:00
|
|
|
int demux_open_fli(demuxer_t* demuxer);
|
2002-02-06 21:16:35 +01:00
|
|
|
int demux_open_mf(demuxer_t* demuxer);
|
2002-01-16 04:25:07 +01:00
|
|
|
int demux_open_film(demuxer_t* demuxer);
|
2002-03-20 06:15:53 +01:00
|
|
|
int demux_open_bmp(demuxer_t* demuxer);
|
2002-02-01 06:35:16 +01:00
|
|
|
int demux_open_roq(demuxer_t* demuxer);
|
2001-07-22 00:37:55 +02:00
|
|
|
|
2001-11-16 22:30:10 +01:00
|
|
|
extern int vivo_check_file(demuxer_t *demuxer);
|
|
|
|
extern void demux_open_vivo(demuxer_t *demuxer);
|
2001-12-27 03:08:31 +01:00
|
|
|
extern int y4m_check_file(demuxer_t *demuxer);
|
|
|
|
extern void demux_open_y4m(demuxer_t *demuxer);
|
2002-02-01 06:35:16 +01:00
|
|
|
extern int roq_check_file(demuxer_t *demuxer);
|
2001-07-22 00:37:55 +02:00
|
|
|
|
2001-12-26 23:57:51 +01:00
|
|
|
extern int real_check_file(demuxer_t *demuxer);
|
|
|
|
extern void demux_open_real(demuxer_t *demuxer);
|
|
|
|
|
2001-12-27 22:24:56 +01:00
|
|
|
extern int nuv_check_file(demuxer_t *demuxer);
|
|
|
|
extern void demux_open_nuv(demuxer_t *demuxer);
|
2002-02-14 14:04:35 +01:00
|
|
|
extern int demux_audio_open(demuxer_t* demuxer);
|
2002-03-16 15:32:03 +01:00
|
|
|
extern int demux_ogg_open(demuxer_t* demuxer);
|
|
|
|
|
|
|
|
extern demuxer_t* init_avi_with_ogg(demuxer_t* demuxer);
|
2001-12-27 22:24:56 +01:00
|
|
|
|
2002-02-20 17:59:25 +01:00
|
|
|
|
|
|
|
static demuxer_t* demux_open_stream(stream_t *stream,int file_format,int audio_id,int video_id,int dvdsub_id){
|
2001-07-22 00:37:55 +02:00
|
|
|
|
|
|
|
//int file_format=(*file_format_ptr);
|
|
|
|
|
|
|
|
demuxer_t *demuxer=NULL;
|
|
|
|
|
|
|
|
demux_stream_t *d_audio=NULL;
|
|
|
|
demux_stream_t *d_video=NULL;
|
|
|
|
|
|
|
|
sh_audio_t *sh_audio=NULL;
|
|
|
|
sh_video_t *sh_video=NULL;
|
|
|
|
|
2001-08-23 15:20:25 +02:00
|
|
|
//printf("demux_open(%p,%d,%d,%d,%d) \n",stream,file_format,audio_id,video_id,dvdsub_id);
|
|
|
|
|
2002-02-06 21:16:35 +01:00
|
|
|
if ( mf_support )
|
|
|
|
{
|
|
|
|
mp_msg(MSGT_DEMUXER,MSGL_INFO,"forced mf.\n");
|
|
|
|
file_format=DEMUXER_TYPE_MF;
|
|
|
|
}
|
|
|
|
|
2001-11-10 00:46:06 +01:00
|
|
|
#ifdef USE_TV
|
|
|
|
//=============== Try to open as TV-input: =================
|
2001-11-23 19:51:32 +01:00
|
|
|
if((tv_param_on == 1) &&
|
|
|
|
(file_format==DEMUXER_TYPE_UNKNOWN || file_format==DEMUXER_TYPE_TV)){
|
2001-11-10 00:46:06 +01:00
|
|
|
demuxer=new_demuxer(stream,DEMUXER_TYPE_TV,audio_id,video_id,dvdsub_id);
|
2001-11-23 19:51:32 +01:00
|
|
|
mp_msg(MSGT_DEMUXER,MSGL_INFO,"Detected TV! ;-)\n");
|
|
|
|
file_format=DEMUXER_TYPE_TV;
|
2001-11-10 00:46:06 +01:00
|
|
|
}
|
|
|
|
#endif
|
2001-11-25 00:58:12 +01:00
|
|
|
|
2001-07-22 00:37:55 +02:00
|
|
|
//=============== Try to open as AVI file: =================
|
|
|
|
if(file_format==DEMUXER_TYPE_UNKNOWN || file_format==DEMUXER_TYPE_AVI){
|
|
|
|
demuxer=new_demuxer(stream,DEMUXER_TYPE_AVI,audio_id,video_id,dvdsub_id);
|
|
|
|
{ //---- RIFF header:
|
|
|
|
int id=stream_read_dword_le(demuxer->stream); // "RIFF"
|
|
|
|
if(id==mmioFOURCC('R','I','F','F')){
|
|
|
|
stream_read_dword_le(demuxer->stream); //filesize
|
|
|
|
id=stream_read_dword_le(demuxer->stream); // "AVI "
|
|
|
|
if(id==formtypeAVI){
|
2001-08-18 22:32:09 +02:00
|
|
|
mp_msg(MSGT_DEMUXER,MSGL_INFO,MSGTR_DetectedAVIfile);
|
2001-07-22 00:37:55 +02:00
|
|
|
file_format=DEMUXER_TYPE_AVI;
|
2002-02-20 17:59:25 +01:00
|
|
|
} else {
|
2002-02-11 13:11:48 +01:00
|
|
|
free_demuxer(demuxer);
|
2002-02-20 17:59:25 +01:00
|
|
|
demuxer = NULL;
|
|
|
|
}
|
2001-07-22 00:37:55 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2001-12-27 03:08:31 +01:00
|
|
|
//=============== Try to open as Y4M file: =================
|
|
|
|
if(file_format==DEMUXER_TYPE_UNKNOWN || file_format==DEMUXER_TYPE_Y4M){
|
|
|
|
demuxer=new_demuxer(stream,DEMUXER_TYPE_Y4M,audio_id,video_id,dvdsub_id);
|
|
|
|
if(y4m_check_file(demuxer)){
|
|
|
|
mp_msg(MSGT_DEMUXER,MSGL_INFO,"Detected YUV4MPEG2 file format!\n");
|
|
|
|
file_format=DEMUXER_TYPE_Y4M;
|
2002-02-20 17:59:25 +01:00
|
|
|
} else {
|
2002-02-11 13:11:48 +01:00
|
|
|
free_demuxer(demuxer);
|
2002-02-20 17:59:25 +01:00
|
|
|
demuxer = NULL;
|
|
|
|
}
|
2001-12-27 03:08:31 +01:00
|
|
|
}
|
2001-12-28 17:49:10 +01:00
|
|
|
//=============== Try to open as ASF file: =================
|
|
|
|
if(file_format==DEMUXER_TYPE_UNKNOWN || file_format==DEMUXER_TYPE_ASF){
|
|
|
|
demuxer=new_demuxer(stream,DEMUXER_TYPE_ASF,audio_id,video_id,dvdsub_id);
|
|
|
|
if(asf_check_header(demuxer)){
|
|
|
|
mp_msg(MSGT_DEMUXER,MSGL_INFO,MSGTR_DetectedASFfile);
|
|
|
|
file_format=DEMUXER_TYPE_ASF;
|
2002-02-20 17:59:25 +01:00
|
|
|
} else {
|
2002-02-11 13:11:48 +01:00
|
|
|
free_demuxer(demuxer);
|
2002-02-20 17:59:25 +01:00
|
|
|
demuxer = NULL;
|
|
|
|
}
|
2001-12-28 17:49:10 +01:00
|
|
|
}
|
2001-12-27 22:24:56 +01:00
|
|
|
//=============== Try to open as NUV file: =================
|
|
|
|
if(file_format==DEMUXER_TYPE_UNKNOWN || file_format==DEMUXER_TYPE_NUV){
|
|
|
|
demuxer=new_demuxer(stream,DEMUXER_TYPE_NUV,audio_id,video_id,dvdsub_id);
|
|
|
|
if(nuv_check_file(demuxer)){
|
|
|
|
mp_msg(MSGT_DEMUXER,MSGL_INFO,"Detected NuppelVideo file format!\n");
|
|
|
|
file_format=DEMUXER_TYPE_NUV;
|
2002-02-20 17:59:25 +01:00
|
|
|
} else {
|
2002-02-11 13:11:48 +01:00
|
|
|
free_demuxer(demuxer);
|
2002-02-20 17:59:25 +01:00
|
|
|
demuxer = NULL;
|
|
|
|
}
|
2001-12-27 22:24:56 +01:00
|
|
|
}
|
2001-11-13 22:10:51 +01:00
|
|
|
//=============== Try to open as MOV file: =================
|
|
|
|
if(file_format==DEMUXER_TYPE_UNKNOWN || file_format==DEMUXER_TYPE_MOV){
|
|
|
|
demuxer=new_demuxer(stream,DEMUXER_TYPE_MOV,audio_id,video_id,dvdsub_id);
|
|
|
|
if(mov_check_file(demuxer)){
|
|
|
|
mp_msg(MSGT_DEMUXER,MSGL_INFO,MSGTR_DetectedQTMOVfile);
|
|
|
|
file_format=DEMUXER_TYPE_MOV;
|
2002-02-20 17:59:25 +01:00
|
|
|
} else {
|
2002-02-11 13:11:48 +01:00
|
|
|
free_demuxer(demuxer);
|
2002-02-20 17:59:25 +01:00
|
|
|
demuxer = NULL;
|
|
|
|
}
|
2001-11-13 22:10:51 +01:00
|
|
|
}
|
2001-12-01 23:12:58 +01:00
|
|
|
//=============== Try to open as VIVO file: =================
|
|
|
|
if(file_format==DEMUXER_TYPE_UNKNOWN || file_format==DEMUXER_TYPE_VIVO){
|
|
|
|
demuxer=new_demuxer(stream,DEMUXER_TYPE_VIVO,audio_id,video_id,dvdsub_id);
|
|
|
|
if(vivo_check_file(demuxer)){
|
|
|
|
mp_msg(MSGT_DEMUXER,MSGL_INFO,"Detected VIVO file format!\n");
|
|
|
|
file_format=DEMUXER_TYPE_VIVO;
|
2002-02-20 17:59:25 +01:00
|
|
|
} else {
|
|
|
|
free_demuxer(demuxer);
|
|
|
|
demuxer = NULL;
|
2001-12-01 23:12:58 +01:00
|
|
|
}
|
|
|
|
}
|
2001-12-26 23:57:51 +01:00
|
|
|
//=============== Try to open as REAL file: =================
|
|
|
|
if(file_format==DEMUXER_TYPE_UNKNOWN || file_format==DEMUXER_TYPE_REAL){
|
|
|
|
demuxer=new_demuxer(stream,DEMUXER_TYPE_REAL,audio_id,video_id,dvdsub_id);
|
|
|
|
if(real_check_file(demuxer)){
|
2002-02-01 06:35:16 +01:00
|
|
|
mp_msg(MSGT_DEMUXER,MSGL_INFO,MSGTR_DetectedREALfile);
|
2001-12-26 23:57:51 +01:00
|
|
|
file_format=DEMUXER_TYPE_REAL;
|
2002-02-20 17:59:25 +01:00
|
|
|
} else {
|
2002-02-11 13:11:48 +01:00
|
|
|
free_demuxer(demuxer);
|
2002-02-20 17:59:25 +01:00
|
|
|
demuxer = NULL;
|
|
|
|
}
|
2001-12-26 23:57:51 +01:00
|
|
|
}
|
2001-12-01 23:12:58 +01:00
|
|
|
//=============== Try to open as FLI file: =================
|
|
|
|
if(file_format==DEMUXER_TYPE_UNKNOWN || file_format==DEMUXER_TYPE_FLI){
|
|
|
|
demuxer=new_demuxer(stream,DEMUXER_TYPE_FLI,audio_id,video_id,dvdsub_id);
|
|
|
|
{
|
2002-01-16 04:25:07 +01:00
|
|
|
int id;
|
|
|
|
stream_seek(demuxer->stream, 4);
|
|
|
|
id=stream_read_word_le(demuxer->stream);
|
|
|
|
// check for the FLI file magic number
|
2001-12-01 23:12:58 +01:00
|
|
|
if((id==0xAF11) || (id==0xAF12)){
|
|
|
|
mp_msg(MSGT_DEMUXER,MSGL_INFO,MSGTR_DetectedFLIfile);
|
|
|
|
file_format=DEMUXER_TYPE_FLI;
|
2002-02-20 17:59:25 +01:00
|
|
|
} else {
|
2002-02-11 13:11:48 +01:00
|
|
|
free_demuxer(demuxer);
|
2002-02-20 17:59:25 +01:00
|
|
|
demuxer = NULL;
|
|
|
|
}
|
2001-12-01 23:12:58 +01:00
|
|
|
}
|
|
|
|
}
|
2002-01-16 04:25:07 +01:00
|
|
|
//=============== Try to open as FILM file: =================
|
|
|
|
if(file_format==DEMUXER_TYPE_UNKNOWN || file_format==DEMUXER_TYPE_FILM){
|
|
|
|
demuxer=new_demuxer(stream,DEMUXER_TYPE_FILM,audio_id,video_id,dvdsub_id);
|
|
|
|
{
|
|
|
|
int signature=stream_read_fourcc(demuxer->stream);
|
|
|
|
// check for the FLI file magic number
|
|
|
|
if(signature==mmioFOURCC('F', 'I', 'L', 'M')){
|
|
|
|
mp_msg(MSGT_DEMUXER,MSGL_INFO,MSGTR_DetectedFILMfile);
|
|
|
|
file_format=DEMUXER_TYPE_FILM;
|
2002-02-20 17:59:25 +01:00
|
|
|
} else {
|
2002-02-11 13:11:48 +01:00
|
|
|
free_demuxer(demuxer);
|
2002-02-20 17:59:25 +01:00
|
|
|
demuxer = NULL;
|
|
|
|
}
|
2002-01-16 04:25:07 +01:00
|
|
|
}
|
|
|
|
}
|
2002-02-01 06:35:16 +01:00
|
|
|
//=============== Try to open as RoQ file: =================
|
|
|
|
if(file_format==DEMUXER_TYPE_UNKNOWN || file_format==DEMUXER_TYPE_ROQ){
|
|
|
|
demuxer=new_demuxer(stream,DEMUXER_TYPE_ROQ,audio_id,video_id,dvdsub_id);
|
|
|
|
if(roq_check_file(demuxer)){
|
|
|
|
mp_msg(MSGT_DEMUXER,MSGL_INFO,MSGTR_DetectedROQfile);
|
|
|
|
file_format=DEMUXER_TYPE_ROQ;
|
2002-02-20 17:59:25 +01:00
|
|
|
} else {
|
2002-02-11 13:11:48 +01:00
|
|
|
free_demuxer(demuxer);
|
2002-02-20 17:59:25 +01:00
|
|
|
demuxer = NULL;
|
|
|
|
}
|
2002-02-01 06:35:16 +01:00
|
|
|
}
|
2002-03-20 06:15:53 +01:00
|
|
|
//=============== Try to open as BMP file: =================
|
|
|
|
if(file_format==DEMUXER_TYPE_UNKNOWN || file_format==DEMUXER_TYPE_BMP){
|
|
|
|
demuxer=new_demuxer(stream,DEMUXER_TYPE_BMP,audio_id,video_id,dvdsub_id);
|
|
|
|
if(bmp_check_file(demuxer)){
|
|
|
|
mp_msg(MSGT_DEMUXER,MSGL_INFO,"BMP file\n");
|
|
|
|
file_format=DEMUXER_TYPE_BMP;
|
|
|
|
} else {
|
|
|
|
free_demuxer(demuxer);
|
|
|
|
demuxer = NULL;
|
|
|
|
}
|
|
|
|
}
|
2002-03-16 15:32:03 +01:00
|
|
|
//=============== Try to open as Ogg file: =================
|
|
|
|
if(file_format==DEMUXER_TYPE_UNKNOWN || file_format==DEMUXER_TYPE_OGG){
|
|
|
|
demuxer=new_demuxer(stream,DEMUXER_TYPE_OGG,audio_id,video_id,dvdsub_id);
|
|
|
|
if(demux_ogg_open(demuxer)){
|
|
|
|
mp_msg(MSGT_DEMUXER,MSGL_INFO,"Detected OGG format\n");
|
|
|
|
file_format=DEMUXER_TYPE_OGG;
|
|
|
|
} else {
|
|
|
|
free_demuxer(demuxer);
|
|
|
|
demuxer = NULL;
|
|
|
|
}
|
|
|
|
}
|
2001-07-22 00:37:55 +02:00
|
|
|
//=============== Try to open as MPEG-PS file: =================
|
|
|
|
if(file_format==DEMUXER_TYPE_UNKNOWN || file_format==DEMUXER_TYPE_MPEG_PS){
|
|
|
|
int pes=1;
|
2001-12-26 17:34:06 +01:00
|
|
|
int tmp;
|
2001-12-26 21:44:56 +01:00
|
|
|
off_t tmppos;
|
2001-07-22 00:37:55 +02:00
|
|
|
while(pes>=0){
|
|
|
|
demuxer=new_demuxer(stream,DEMUXER_TYPE_MPEG_PS,audio_id,video_id,dvdsub_id);
|
2001-12-26 17:34:06 +01:00
|
|
|
|
|
|
|
// try to pre-detect PES:
|
2001-12-26 21:44:56 +01:00
|
|
|
tmppos=stream_tell(demuxer->stream);
|
2001-12-26 17:34:06 +01:00
|
|
|
tmp=stream_read_dword(demuxer->stream);
|
|
|
|
if(tmp==0x1E0 || tmp==0x1C0){
|
|
|
|
tmp=stream_read_word(demuxer->stream);
|
|
|
|
if(tmp>1 && tmp<=2048) pes=0; // demuxer->synced=3; // PES...
|
|
|
|
}
|
2001-12-26 21:44:56 +01:00
|
|
|
stream_seek(demuxer->stream,tmppos);
|
2001-12-26 17:34:06 +01:00
|
|
|
|
|
|
|
if(!pes) demuxer->synced=3; // hack!
|
|
|
|
|
2001-08-23 15:20:25 +02:00
|
|
|
num_elementary_packets100=0;
|
|
|
|
num_elementary_packets101=0;
|
|
|
|
num_elementary_packets1B6=0;
|
|
|
|
num_elementary_packetsPES=0;
|
2002-02-17 03:11:14 +01:00
|
|
|
num_mp3audio_packets=0;
|
2001-08-23 15:20:25 +02:00
|
|
|
|
2001-07-22 00:37:55 +02:00
|
|
|
if(ds_fill_buffer(demuxer->video)){
|
|
|
|
if(!pes)
|
2001-08-18 22:32:09 +02:00
|
|
|
mp_msg(MSGT_DEMUXER,MSGL_INFO,MSGTR_DetectedMPEGPESfile);
|
2001-07-22 00:37:55 +02:00
|
|
|
else
|
2001-08-18 22:32:09 +02:00
|
|
|
mp_msg(MSGT_DEMUXER,MSGL_INFO,MSGTR_DetectedMPEGPSfile);
|
2001-07-22 00:37:55 +02:00
|
|
|
file_format=DEMUXER_TYPE_MPEG_PS;
|
|
|
|
} else {
|
2002-02-17 03:11:14 +01:00
|
|
|
printf("MPEG packet stats: p100: %d p101: %d PES: %d MP3: %d \n",
|
|
|
|
num_elementary_packets100,num_elementary_packets101,num_elementary_packetsPES,num_mp3audio_packets);
|
2002-04-24 01:21:19 +02:00
|
|
|
//MPEG packet stats: p100: 458 p101: 458 PES: 0 MP3: 1103 (.m2v)
|
|
|
|
if(num_mp3audio_packets>50 && num_mp3audio_packets>2*num_elementary_packets100
|
|
|
|
&& abs(num_elementary_packets100-num_elementary_packets101)>2)
|
2002-03-14 12:18:19 +01:00
|
|
|
break; // it's .MP3
|
2001-07-22 00:37:55 +02:00
|
|
|
// some hack to get meaningfull error messages to our unhappy users:
|
|
|
|
if(num_elementary_packets100>=2 && num_elementary_packets101>=2 &&
|
2001-11-13 22:38:29 +01:00
|
|
|
abs(num_elementary_packets101+8-num_elementary_packets100)<16){
|
2001-07-22 00:37:55 +02:00
|
|
|
if(num_elementary_packetsPES>=4 && num_elementary_packetsPES>=num_elementary_packets100-4){
|
|
|
|
--pes;continue; // tricky...
|
|
|
|
}
|
|
|
|
file_format=DEMUXER_TYPE_MPEG_ES; // <-- hack is here :)
|
|
|
|
} else {
|
|
|
|
if(demuxer->synced==2)
|
2001-09-26 23:35:14 +02:00
|
|
|
mp_msg(MSGT_DEMUXER,MSGL_ERR,"MPEG: " MSGTR_MissingVideoStreamBug);
|
2001-07-22 00:37:55 +02:00
|
|
|
else
|
2001-08-17 02:40:25 +02:00
|
|
|
mp_msg(MSGT_DEMUXER,MSGL_V,"Not MPEG System Stream format... (maybe Transport Stream?)\n");
|
2002-02-11 13:11:48 +01:00
|
|
|
free_demuxer(demuxer);
|
2002-02-20 17:59:25 +01:00
|
|
|
demuxer = NULL;
|
2001-07-22 00:37:55 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//=============== Try to open as MPEG-ES file: =================
|
|
|
|
if(file_format==DEMUXER_TYPE_MPEG_ES){ // little hack, see above!
|
|
|
|
demuxer=new_demuxer(stream,DEMUXER_TYPE_MPEG_ES,audio_id,video_id,dvdsub_id);
|
|
|
|
if(!ds_fill_buffer(demuxer->video)){
|
2001-08-18 22:32:09 +02:00
|
|
|
mp_msg(MSGT_DEMUXER,MSGL_ERR,MSGTR_InvalidMPEGES);
|
2001-07-22 00:37:55 +02:00
|
|
|
file_format=DEMUXER_TYPE_UNKNOWN;
|
2002-02-11 13:11:48 +01:00
|
|
|
free_demuxer(demuxer);
|
2002-02-20 17:59:25 +01:00
|
|
|
demuxer = NULL;
|
2001-07-22 00:37:55 +02:00
|
|
|
} else {
|
2001-08-18 22:32:09 +02:00
|
|
|
mp_msg(MSGT_DEMUXER,MSGL_INFO,MSGTR_DetectedMPEGESfile);
|
2001-07-22 00:37:55 +02:00
|
|
|
}
|
|
|
|
}
|
2002-02-06 21:16:35 +01:00
|
|
|
//=============== Try to open as multi file: =================
|
|
|
|
if(file_format==DEMUXER_TYPE_UNKNOWN || file_format==DEMUXER_TYPE_MF){
|
|
|
|
demuxer=new_demuxer(stream,DEMUXER_TYPE_MF,audio_id,video_id,dvdsub_id);
|
|
|
|
{
|
|
|
|
if ( mf_support )
|
|
|
|
{
|
|
|
|
file_format=DEMUXER_TYPE_MF;
|
|
|
|
mp_msg( MSGT_DEMUXER,MSGL_INFO,"[demuxer] mf support.\n" );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2002-02-14 17:09:36 +01:00
|
|
|
//=============== Try to open as audio file: =================
|
|
|
|
if(file_format==DEMUXER_TYPE_UNKNOWN || file_format==DEMUXER_TYPE_AUDIO){
|
|
|
|
demuxer=new_demuxer(stream,DEMUXER_TYPE_AUDIO,audio_id,video_id,dvdsub_id);
|
|
|
|
if(demux_audio_open(demuxer)){
|
|
|
|
mp_msg(MSGT_DEMUXER,MSGL_INFO,"Detected audio file\n");
|
|
|
|
file_format=DEMUXER_TYPE_AUDIO;
|
2002-02-20 17:59:25 +01:00
|
|
|
} else {
|
2002-02-14 17:09:36 +01:00
|
|
|
free_demuxer(demuxer);
|
2002-02-20 17:59:25 +01:00
|
|
|
demuxer = NULL;
|
|
|
|
}
|
2002-02-14 17:09:36 +01:00
|
|
|
}
|
2001-07-22 00:37:55 +02:00
|
|
|
//=============== Unknown, exiting... ===========================
|
2002-02-20 17:59:25 +01:00
|
|
|
if(file_format==DEMUXER_TYPE_UNKNOWN || demuxer == NULL){
|
2001-08-18 22:32:09 +02:00
|
|
|
mp_msg(MSGT_DEMUXER,MSGL_ERR,MSGTR_FormatNotRecognized);
|
2001-07-22 00:37:55 +02:00
|
|
|
return NULL;
|
|
|
|
// GUI_MSG( mplUnknowFileType )
|
|
|
|
}
|
|
|
|
//====== File format recognized, set up these for compatibility: =========
|
|
|
|
d_audio=demuxer->audio;
|
|
|
|
d_video=demuxer->video;
|
|
|
|
//d_dvdsub=demuxer->sub;
|
|
|
|
|
2001-08-11 22:37:33 +02:00
|
|
|
demuxer->file_format=file_format;
|
|
|
|
|
2001-07-22 00:37:55 +02:00
|
|
|
switch(file_format){
|
2002-02-06 21:16:35 +01:00
|
|
|
case DEMUXER_TYPE_MF: {
|
|
|
|
if (!demux_open_mf(demuxer)) return NULL;
|
|
|
|
break;
|
|
|
|
}
|
2001-11-25 00:58:12 +01:00
|
|
|
case DEMUXER_TYPE_FLI: {
|
|
|
|
if (!demux_open_fli(demuxer)) return NULL;
|
|
|
|
break;
|
|
|
|
}
|
2002-01-16 04:25:07 +01:00
|
|
|
case DEMUXER_TYPE_FILM: {
|
|
|
|
if (!demux_open_film(demuxer)) return NULL;
|
2002-02-01 06:35:16 +01:00
|
|
|
break;
|
|
|
|
}
|
2002-03-20 06:15:53 +01:00
|
|
|
case DEMUXER_TYPE_BMP: {
|
|
|
|
if (!demux_open_bmp(demuxer)) return NULL;
|
|
|
|
break;
|
|
|
|
}
|
2002-02-01 06:35:16 +01:00
|
|
|
case DEMUXER_TYPE_ROQ: {
|
|
|
|
if (!demux_open_roq(demuxer)) return NULL;
|
2002-01-16 04:25:07 +01:00
|
|
|
break;
|
|
|
|
}
|
2001-08-12 03:58:05 +02:00
|
|
|
case DEMUXER_TYPE_MOV: {
|
2001-10-07 23:59:49 +02:00
|
|
|
if(!mov_read_header(demuxer)) return NULL;
|
|
|
|
// sh_video=d_video->sh;if(sh_video) sh_video->ds=d_video;
|
|
|
|
// sh_audio=d_audio->sh;if(sh_audio) sh_audio->ds=d_audio;
|
2001-08-12 03:58:05 +02:00
|
|
|
break;
|
|
|
|
}
|
2001-07-22 00:37:55 +02:00
|
|
|
case DEMUXER_TYPE_AVI: {
|
2002-03-16 15:32:03 +01:00
|
|
|
sh_audio_t* sh_a;
|
|
|
|
demuxer = (demuxer_t*) demux_open_avi(demuxer);
|
2002-03-31 04:45:14 +02:00
|
|
|
if(!demuxer) return NULL; // failed to open
|
2002-03-16 15:32:03 +01:00
|
|
|
sh_a = (sh_audio_t*)demuxer->audio->sh;
|
|
|
|
if(demuxer->audio->id != -2 && sh_a && sh_a->format == 0xFFFE)
|
|
|
|
demuxer = init_avi_with_ogg(demuxer);
|
|
|
|
return demuxer;
|
2001-08-11 22:37:33 +02:00
|
|
|
// break;
|
2001-07-22 00:37:55 +02:00
|
|
|
}
|
2001-12-27 22:24:56 +01:00
|
|
|
case DEMUXER_TYPE_NUV: {
|
|
|
|
demux_open_nuv(demuxer);
|
|
|
|
break;
|
|
|
|
}
|
2001-11-04 17:57:09 +01:00
|
|
|
case DEMUXER_TYPE_VIVO: {
|
|
|
|
demux_open_vivo(demuxer);
|
|
|
|
break;
|
|
|
|
}
|
2001-12-27 03:08:31 +01:00
|
|
|
case DEMUXER_TYPE_Y4M: {
|
|
|
|
demux_open_y4m(demuxer);
|
|
|
|
break;
|
|
|
|
}
|
2001-12-26 23:57:51 +01:00
|
|
|
case DEMUXER_TYPE_REAL: {
|
|
|
|
demux_open_real(demuxer);
|
|
|
|
break;
|
|
|
|
}
|
2001-07-22 00:37:55 +02:00
|
|
|
case DEMUXER_TYPE_ASF: {
|
|
|
|
//---- ASF header:
|
|
|
|
read_asf_header(demuxer);
|
|
|
|
stream_reset(demuxer->stream);
|
|
|
|
stream_seek(demuxer->stream,demuxer->movi_start);
|
2001-08-11 22:37:33 +02:00
|
|
|
// demuxer->idx_pos=0;
|
2001-07-22 00:37:55 +02:00
|
|
|
// demuxer->endpos=avi_header.movi_end;
|
2002-02-08 17:00:14 +01:00
|
|
|
if(d_video->id != -2) {
|
|
|
|
if(!ds_fill_buffer(d_video)){
|
|
|
|
mp_msg(MSGT_DEMUXER,MSGL_WARN,"ASF: " MSGTR_MissingVideoStream);
|
|
|
|
sh_video=NULL;
|
|
|
|
//printf("ASF: missing video stream!? contact the author, it may be a bug :(\n");
|
|
|
|
//GUI_MSG( mplASFErrorMissingVideoStream )
|
|
|
|
} else {
|
|
|
|
sh_video=d_video->sh;sh_video->ds=d_video;
|
|
|
|
sh_video->fps=1000.0f; sh_video->frametime=0.001f; // 1ms
|
|
|
|
mp_msg(MSGT_DEMUXER,MSGL_INFO,"VIDEO: [%.4s] %ldx%ld %dbpp\n",
|
|
|
|
(char *)&sh_video->bih->biCompression,
|
|
|
|
sh_video->bih->biWidth,
|
|
|
|
sh_video->bih->biHeight,
|
|
|
|
sh_video->bih->biBitCount);
|
|
|
|
// sh_video->i_bps=10*asf_packetsize; // FIXME!
|
|
|
|
}
|
2001-07-22 00:37:55 +02:00
|
|
|
}
|
2002-02-08 17:00:14 +01:00
|
|
|
if(d_audio->id!=-2){
|
2001-08-17 02:40:25 +02:00
|
|
|
mp_msg(MSGT_DEMUXER,MSGL_V,"ASF: Searching for audio stream (id:%d)\n",d_audio->id);
|
2001-07-22 00:37:55 +02:00
|
|
|
if(!ds_fill_buffer(d_audio)){
|
2001-09-26 23:35:14 +02:00
|
|
|
mp_msg(MSGT_DEMUXER,MSGL_INFO,"ASF: " MSGTR_MissingAudioStream);
|
2001-07-22 00:37:55 +02:00
|
|
|
sh_audio=NULL;
|
|
|
|
} else {
|
|
|
|
sh_audio=d_audio->sh;sh_audio->ds=d_audio;
|
|
|
|
sh_audio->format=sh_audio->wf->wFormatTag;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case DEMUXER_TYPE_MPEG_ES: {
|
|
|
|
sh_audio=NULL; // ES streams has no audio channel
|
|
|
|
d_video->sh=new_sh_video(demuxer,0); // create dummy video stream header, id=0
|
|
|
|
sh_video=d_video->sh;sh_video->ds=d_video;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case DEMUXER_TYPE_MPEG_PS: {
|
|
|
|
sh_video=d_video->sh;sh_video->ds=d_video;
|
2002-01-27 21:10:28 +01:00
|
|
|
// if(demuxer->stream->type!=STREAMTYPE_VCD) demuxer->movi_start=0; // for VCD
|
2001-08-22 21:03:15 +02:00
|
|
|
|
2001-07-22 00:37:55 +02:00
|
|
|
if(audio_id!=-2) {
|
|
|
|
if(!ds_fill_buffer(d_audio)){
|
2001-09-26 23:35:14 +02:00
|
|
|
mp_msg(MSGT_DEMUXER,MSGL_INFO,"MPEG: " MSGTR_MissingAudioStream);
|
2001-07-22 00:37:55 +02:00
|
|
|
sh_audio=NULL;
|
|
|
|
} else {
|
|
|
|
sh_audio=d_audio->sh;sh_audio->ds=d_audio;
|
|
|
|
switch(d_audio->id & 0xE0){ // 1110 0000 b (high 3 bit: type low 5: id)
|
|
|
|
case 0x00: sh_audio->format=0x50;break; // mpeg
|
|
|
|
case 0xA0: sh_audio->format=0x10001;break; // dvd pcm
|
|
|
|
case 0x80: sh_audio->format=0x2000;break; // ac3
|
|
|
|
default: sh_audio=NULL; // unknown type
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2001-11-10 00:46:06 +01:00
|
|
|
#ifdef USE_TV
|
|
|
|
case DEMUXER_TYPE_TV: {
|
2001-11-11 16:45:23 +01:00
|
|
|
if (!demux_open_tv(demuxer, tv_handler))
|
|
|
|
{
|
|
|
|
tv_uninit(tv_handler);
|
|
|
|
return(NULL);
|
|
|
|
}
|
2001-11-10 00:46:06 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
#endif
|
2001-07-22 00:37:55 +02:00
|
|
|
} // switch(file_format)
|
2001-10-31 16:04:36 +01:00
|
|
|
pts_from_bps=0; // !!!
|
2001-07-22 00:37:55 +02:00
|
|
|
return demuxer;
|
|
|
|
}
|
2001-08-12 19:28:16 +02:00
|
|
|
|
2002-02-20 17:59:25 +01:00
|
|
|
static char* audio_stream = NULL;
|
|
|
|
static char* sub_stream = NULL;
|
|
|
|
static int demuxer_type = 0, audio_demuxer_type = 0, sub_demuxer_type = 0;
|
|
|
|
extern m_config_t* mconfig;
|
|
|
|
|
|
|
|
demuxer_t* demux_open(stream_t *vs,int file_format,int audio_id,int video_id,int dvdsub_id){
|
|
|
|
stream_t *as = NULL,*ss = NULL;
|
|
|
|
demuxer_t *vd,*ad = NULL,*sd = NULL;
|
|
|
|
int afmt = 0,sfmt = 0;
|
|
|
|
|
|
|
|
if(audio_stream) {
|
|
|
|
as = open_stream(audio_stream,0,&afmt);
|
|
|
|
if(!as) {
|
|
|
|
mp_msg(MSGT_DEMUXER,MSGL_ERR,"Can't open audio stream: %s\n",audio_stream);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(sub_stream) {
|
|
|
|
ss = open_stream(sub_stream,0,&sfmt);
|
|
|
|
if(!ss) {
|
|
|
|
mp_msg(MSGT_DEMUXER,MSGL_ERR,"Can't open subtitles stream: %s\n",sub_stream);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
vd = demux_open_stream(vs,demuxer_type ? demuxer_type : file_format,audio_stream ? -2 : audio_id,video_id, sub_stream ? -2 : dvdsub_id);
|
|
|
|
if(!vd)
|
|
|
|
return NULL;
|
|
|
|
if(as) {
|
|
|
|
ad = demux_open_stream(as,audio_demuxer_type ? audio_demuxer_type : afmt,audio_id,-2,-2);
|
|
|
|
if(!ad)
|
|
|
|
mp_msg(MSGT_DEMUXER,MSGL_WARN,"Failed to open audio demuxer: %s\n",audio_stream);
|
|
|
|
else if(ad->audio->sh && ((sh_audio_t*)ad->audio->sh)->format == 0x55) // MP3
|
|
|
|
m_config_set_flag(mconfig,"hr-mp3-seek",1); // Enable high res seeking
|
|
|
|
}
|
|
|
|
if(ss) {
|
|
|
|
sd = demux_open_stream(ss,sub_demuxer_type ? sub_demuxer_type : sfmt,-2,-2,dvdsub_id);
|
|
|
|
if(!sd)
|
|
|
|
mp_msg(MSGT_DEMUXER,MSGL_WARN,"Failed to open subtitles demuxer: %s\n",sub_stream);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(ad && sd)
|
|
|
|
return new_demuxers_demuxer(vd,ad,sd);
|
|
|
|
else if(ad)
|
|
|
|
return new_demuxers_demuxer(vd,ad,vd);
|
|
|
|
else if(sd)
|
|
|
|
return new_demuxers_demuxer(vd,vd,sd);
|
|
|
|
else
|
|
|
|
return vd;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-08-12 19:28:16 +02:00
|
|
|
int demux_seek_avi(demuxer_t *demuxer,float rel_seek_secs,int flags);
|
|
|
|
int demux_seek_asf(demuxer_t *demuxer,float rel_seek_secs,int flags);
|
|
|
|
int demux_seek_mpg(demuxer_t *demuxer,float rel_seek_secs,int flags);
|
2001-12-28 23:58:49 +01:00
|
|
|
int demux_seek_y4m(demuxer_t *demuxer,float rel_seek_secs,int flags);
|
2001-12-17 01:24:03 +01:00
|
|
|
int demux_seek_fli(demuxer_t *demuxer,float rel_seek_secs,int flags);
|
2002-03-17 03:59:04 +01:00
|
|
|
int demux_seek_film(demuxer_t *demuxer,float rel_seek_secs,int flags);
|
2002-02-06 21:16:35 +01:00
|
|
|
int demux_seek_mf(demuxer_t *demuxer,float rel_seek_secs,int flags);
|
2002-01-09 18:09:21 +01:00
|
|
|
int demux_seek_nuv(demuxer_t *demuxer,float rel_seek_secs,int flags);
|
2001-10-17 00:41:46 +02:00
|
|
|
void demux_seek_mov(demuxer_t *demuxer,float pts,int flags);
|
2002-03-15 16:53:11 +01:00
|
|
|
int demux_seek_real(demuxer_t *demuxer,float rel_seek_secs,int flags);
|
2002-02-14 14:04:35 +01:00
|
|
|
extern void demux_audio_seek(demuxer_t *demuxer,float rel_seek_secs,int flags);
|
2002-02-20 17:59:25 +01:00
|
|
|
extern void demux_demuxers_seek(demuxer_t *demuxer,float rel_seek_secs,int flags);
|
2002-04-21 04:38:50 +02:00
|
|
|
#ifdef HAVE_OGGVORBIS
|
2002-04-20 19:50:11 +02:00
|
|
|
extern void demux_ogg_seek(demuxer_t *demuxer,float rel_seek_secs,int flags);
|
2002-04-21 04:38:50 +02:00
|
|
|
#endif
|
2001-08-12 19:28:16 +02:00
|
|
|
|
|
|
|
int demux_seek(demuxer_t *demuxer,float rel_seek_secs,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;
|
|
|
|
|
2001-08-22 18:42:37 +02:00
|
|
|
if(!demuxer->seekable){
|
|
|
|
if(demuxer->file_format==DEMUXER_TYPE_AVI)
|
2001-09-26 23:35:14 +02:00
|
|
|
mp_msg(MSGT_SEEK,MSGL_WARN,MSGTR_CantSeekRawAVI);
|
2001-11-10 00:46:06 +01:00
|
|
|
#ifdef USE_TV
|
|
|
|
else if (demuxer->file_format==DEMUXER_TYPE_TV)
|
2002-03-15 22:38:54 +01:00
|
|
|
mp_msg(MSGT_SEEK,MSGL_WARN,"TV input isn't seekable! (probably seeking will be for changing channels ;)\n");
|
2001-11-10 00:46:06 +01:00
|
|
|
#endif
|
2001-08-22 18:42:37 +02:00
|
|
|
else
|
2001-09-26 23:35:14 +02:00
|
|
|
mp_msg(MSGT_SEEK,MSGL_WARN,MSGTR_CantSeekFile);
|
2001-08-22 18:42:37 +02:00
|
|
|
return 0;
|
|
|
|
}
|
2001-08-12 19:28:16 +02:00
|
|
|
|
|
|
|
// clear demux buffers:
|
|
|
|
if(sh_audio){ ds_free_packs(d_audio);sh_audio->a_buffer_len=0;}
|
|
|
|
ds_free_packs(d_video);
|
|
|
|
|
|
|
|
demuxer->stream->eof=0; // clear eof flag
|
2001-12-17 01:03:50 +01:00
|
|
|
demuxer->video->eof=0;
|
|
|
|
demuxer->audio->eof=0;
|
2001-08-12 19:28:16 +02:00
|
|
|
|
2002-01-17 01:32:46 +01:00
|
|
|
#if 0
|
2001-12-28 02:38:40 +01:00
|
|
|
if(sh_audio) sh_audio->timer=sh_video->timer;
|
|
|
|
#else
|
2001-08-12 19:28:16 +02:00
|
|
|
if(sh_audio) sh_audio->timer=0;
|
2002-02-08 17:00:14 +01:00
|
|
|
if(sh_video) sh_video->timer=0; // !!!!!!
|
2001-12-28 02:38:40 +01:00
|
|
|
#endif
|
2001-08-12 19:28:16 +02:00
|
|
|
|
|
|
|
switch(demuxer->file_format){
|
|
|
|
|
|
|
|
case DEMUXER_TYPE_AVI:
|
|
|
|
demux_seek_avi(demuxer,rel_seek_secs,flags); break;
|
|
|
|
|
|
|
|
case DEMUXER_TYPE_ASF:
|
|
|
|
demux_seek_asf(demuxer,rel_seek_secs,flags); break;
|
|
|
|
|
|
|
|
case DEMUXER_TYPE_MPEG_ES:
|
|
|
|
case DEMUXER_TYPE_MPEG_PS:
|
|
|
|
demux_seek_mpg(demuxer,rel_seek_secs,flags); break;
|
|
|
|
|
2001-10-17 00:41:46 +02:00
|
|
|
case DEMUXER_TYPE_MOV:
|
|
|
|
demux_seek_mov(demuxer,rel_seek_secs,flags); break;
|
|
|
|
|
2002-03-15 16:53:11 +01:00
|
|
|
case DEMUXER_TYPE_REAL:
|
|
|
|
demux_seek_real(demuxer,rel_seek_secs,flags); break;
|
|
|
|
|
2001-12-28 23:58:49 +01:00
|
|
|
case DEMUXER_TYPE_Y4M:
|
|
|
|
demux_seek_y4m(demuxer,rel_seek_secs,flags); break;
|
|
|
|
|
2002-02-07 13:07:47 +01:00
|
|
|
case DEMUXER_TYPE_MF:
|
|
|
|
demux_seek_mf(demuxer,rel_seek_secs,flags); break;
|
|
|
|
|
2001-12-17 01:24:03 +01:00
|
|
|
case DEMUXER_TYPE_FLI:
|
|
|
|
demux_seek_fli(demuxer,rel_seek_secs,flags); break;
|
2002-03-17 03:59:04 +01:00
|
|
|
case DEMUXER_TYPE_FILM:
|
|
|
|
demux_seek_film(demuxer,rel_seek_secs,flags); break;
|
2002-01-09 18:09:21 +01:00
|
|
|
case DEMUXER_TYPE_NUV:
|
|
|
|
demux_seek_nuv(demuxer,rel_seek_secs,flags); break;
|
2002-02-14 14:04:35 +01:00
|
|
|
case DEMUXER_TYPE_AUDIO:
|
|
|
|
demux_audio_seek(demuxer,rel_seek_secs,flags); break;
|
2002-02-20 17:59:25 +01:00
|
|
|
case DEMUXER_TYPE_DEMUXERS:
|
|
|
|
demux_demuxers_seek(demuxer,rel_seek_secs,flags); break;
|
2002-04-21 04:38:50 +02:00
|
|
|
#ifdef HAVE_OGGVORBIS
|
2002-04-20 19:50:11 +02:00
|
|
|
case DEMUXER_TYPE_OGG:
|
|
|
|
demux_ogg_seek(demuxer,rel_seek_secs,flags); break;
|
2002-04-21 04:38:50 +02:00
|
|
|
#endif
|
2002-01-09 18:09:21 +01:00
|
|
|
|
2001-12-17 01:24:03 +01:00
|
|
|
|
2001-08-12 19:28:16 +02:00
|
|
|
} // switch(demuxer->file_format)
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2001-11-21 17:14:14 +01:00
|
|
|
int demux_info_add(demuxer_t *demuxer, char *opt, char *param)
|
|
|
|
{
|
2002-02-14 14:04:35 +01:00
|
|
|
char **info = demuxer->info;
|
|
|
|
int n = 0;
|
2001-11-21 17:14:14 +01:00
|
|
|
|
|
|
|
|
2002-02-14 14:04:35 +01:00
|
|
|
for(n = 0; info && info[2*n] != NULL; n++)
|
|
|
|
{
|
|
|
|
if(!strcasecmp(opt,info[2*n]))
|
|
|
|
{
|
|
|
|
mp_msg(MSGT_DEMUX, MSGL_WARN, "Demuxer info %s already present\n!",opt);
|
|
|
|
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 16:43:24 +01:00
|
|
|
|
2002-02-14 14:04:35 +01:00
|
|
|
return 1;
|
2001-11-21 17:14:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
int demux_info_print(demuxer_t *demuxer)
|
|
|
|
{
|
2002-02-14 14:04:35 +01:00
|
|
|
char **info = demuxer->info;
|
|
|
|
int n;
|
2001-11-21 17:14:14 +01:00
|
|
|
|
2002-02-14 14:04:35 +01:00
|
|
|
if(!info)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
mp_msg(MSGT_DEMUX, MSGL_INFO, "Clip info: \n");
|
|
|
|
for(n = 0; info[2*n] != NULL ; n++)
|
|
|
|
mp_msg(MSGT_DEMUX, MSGL_INFO, " %s: %s\n",info[2*n],info[2*n+1]);
|
2002-01-16 04:25:07 +01:00
|
|
|
|
|
|
|
return 0;
|
2001-11-21 17:14:14 +01:00
|
|
|
}
|
2002-02-20 17:59:25 +01:00
|
|
|
|
|
|
|
char* demux_info_get(demuxer_t *demuxer, char *opt) {
|
|
|
|
int i;
|
|
|
|
char **info = demuxer->info;
|
|
|
|
|
|
|
|
for(i = 0; info && info[2*i] != NULL; i++) {
|
|
|
|
if(!strcasecmp(opt,info[2*i]))
|
|
|
|
return info[2*i+1];
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************* Options stuff **********************/
|
|
|
|
|
|
|
|
static config_t demuxer_opts[] = {
|
|
|
|
{ "audiofile", &audio_stream, CONF_TYPE_STRING, 0, 0, 0, NULL },
|
|
|
|
{ "subfile", &sub_stream, CONF_TYPE_STRING, 0, 0, 0, NULL },
|
|
|
|
{ "demuxer", &demuxer_type, CONF_TYPE_INT, CONF_RANGE, 1, DEMUXER_TYPE_MAX, NULL },
|
|
|
|
{ "audio-demuxer", &audio_demuxer_type, CONF_TYPE_INT, CONF_RANGE, 1, DEMUXER_TYPE_MAX, NULL },
|
|
|
|
{ "sub-demuxer", &sub_demuxer_type, CONF_TYPE_INT, CONF_RANGE, 1, DEMUXER_TYPE_MAX, NULL },
|
|
|
|
{ NULL, NULL, 0, 0, 0, 0, NULL}
|
|
|
|
};
|
|
|
|
|
|
|
|
void demuxer_register_options(m_config_t* cfg) {
|
|
|
|
m_config_register_options(cfg,demuxer_opts);
|
|
|
|
}
|
|
|
|
|