diff options
author | diego <diego@b3059339-0415-0410-9bf9-f77b7e298cf2> | 2008-06-16 12:11:14 +0000 |
---|---|---|
committer | diego <diego@b3059339-0415-0410-9bf9-f77b7e298cf2> | 2008-06-16 12:11:14 +0000 |
commit | ed59b9030e33e889c038a2006ee9c9bcec44b862 (patch) | |
tree | 30dad4ac22e09f3ca3731f9569e1160d7dcfdfdc /libmpdemux/demuxer.c | |
parent | 005cf981d4a4911392ead315dcb08a98ac5571bb (diff) | |
download | mpv-ed59b9030e33e889c038a2006ee9c9bcec44b862.tar.bz2 mpv-ed59b9030e33e889c038a2006ee9c9bcec44b862.tar.xz |
cosmetics: indentation, whitespace changes
git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@27087 b3059339-0415-0410-9bf9-f77b7e298cf2
Diffstat (limited to 'libmpdemux/demuxer.c')
-rw-r--r-- | libmpdemux/demuxer.c | 1293 |
1 files changed, 645 insertions, 648 deletions
diff --git a/libmpdemux/demuxer.c b/libmpdemux/demuxer.c index 0dad426bbb..f3981b1e1f 100644 --- a/libmpdemux/demuxer.c +++ b/libmpdemux/demuxer.c @@ -79,76 +79,76 @@ extern const demuxer_desc_t demuxer_desc_nut; * libraries and demuxers requiring binary support. */ const demuxer_desc_t *const demuxer_list[] = { - &demuxer_desc_rawaudio, - &demuxer_desc_rawvideo, + &demuxer_desc_rawaudio, + &demuxer_desc_rawvideo, #ifdef USE_TV - &demuxer_desc_tv, + &demuxer_desc_tv, #endif - &demuxer_desc_mf, + &demuxer_desc_mf, #ifdef USE_LIBAVFORMAT - &demuxer_desc_lavf_preferred, + &demuxer_desc_lavf_preferred, #endif - &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, + &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, #ifdef HAVE_GIF - &demuxer_desc_gif, + &demuxer_desc_gif, #endif #ifdef HAVE_OGGVORBIS - &demuxer_desc_ogg, + &demuxer_desc_ogg, #endif #ifdef USE_WIN32DLL - &demuxer_desc_avs, + &demuxer_desc_avs, #endif - &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, - &demuxer_desc_audio, - &demuxer_desc_mpeg_ty, + &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, + &demuxer_desc_audio, + &demuxer_desc_mpeg_ty, #ifdef STREAMING_LIVE555 - &demuxer_desc_rtp, + &demuxer_desc_rtp, #endif #ifdef LIBNEMESI - &demuxer_desc_rtp_nemesi, + &demuxer_desc_rtp_nemesi, #endif #ifdef USE_LIBAVFORMAT - &demuxer_desc_lavf, + &demuxer_desc_lavf, #endif #ifdef MUSEPACK - &demuxer_desc_mpc, + &demuxer_desc_mpc, #endif #ifdef HAVE_LIBDV095 - &demuxer_desc_rawdv, + &demuxer_desc_rawdv, #endif - &demuxer_desc_aac, + &demuxer_desc_aac, #ifdef HAVE_LIBNUT - &demuxer_desc_nut, + &demuxer_desc_nut, #endif #ifdef HAVE_XMMS - &demuxer_desc_xmms, + &demuxer_desc_xmms, #endif - /* 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 + /* 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 }; void free_demuxer_stream(demux_stream_t *ds) @@ -159,29 +159,29 @@ void free_demuxer_stream(demux_stream_t *ds) 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; + 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; } @@ -193,61 +193,61 @@ demux_stream_t *new_demuxer_stream(struct demuxer_st *demuxer, int id) */ static const demuxer_desc_t *get_demuxer_desc_from_type(int file_format) { - int i; + int i; - for (i = 0; demuxer_list[i]; i++) - if (file_format == demuxer_list[i]->type) - return demuxer_list[i]; + for (i = 0; demuxer_list[i]; i++) + if (file_format == demuxer_list[i]->type) + return demuxer_list[i]; - return NULL; + return NULL; } demuxer_t *new_demuxer(stream_t *stream, int type, int a_id, int v_id, int s_id, char *filename) { - 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; - 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; + 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; + 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; } extern int dvdsub_id; 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; - mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_SUBTITLE_ID=%d\n", sid); - } - return demuxer->s_streams[id]; + 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; + mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_SUBTITLE_ID=%d\n", sid); + } + return demuxer->s_streams[id]; } void free_sh_sub(sh_sub_t *sh) @@ -264,25 +264,25 @@ void free_sh_sub(sh_sub_t *sh) 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); + 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; } if (demuxer->a_streams[id]) - mp_msg(MSGT_DEMUXER,MSGL_WARN,MSGTR_AudioStreamRedefined,id); + mp_msg(MSGT_DEMUXER, MSGL_WARN, MSGTR_AudioStreamRedefined, id); else { sh_audio_t *sh = calloc(1, sizeof(sh_audio_t)); - mp_msg(MSGT_DEMUXER,MSGL_V,MSGTR_FoundAudioStream,id); + mp_msg(MSGT_DEMUXER, MSGL_V, MSGTR_FoundAudioStream, id); demuxer->a_streams[id] = sh; sh->aid = aid; sh->ds = demuxer->audio; // set some defaults - 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; - mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_AUDIO_ID=%d\n", aid); + 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; + mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_AUDIO_ID=%d\n", aid); } return demuxer->a_streams[id]; } @@ -291,7 +291,7 @@ void free_sh_audio(demuxer_t *demuxer, int id) { sh_audio_t *sh = demuxer->a_streams[id]; demuxer->a_streams[id] = NULL; - mp_msg(MSGT_DEMUXER,MSGL_DBG2,"DEMUXER: freeing sh_audio at %p\n",sh); + mp_msg(MSGT_DEMUXER, MSGL_DBG2, "DEMUXER: freeing sh_audio at %p\n", sh); free(sh->wf); free(sh->codecdata); free(sh->lang); @@ -301,26 +301,26 @@ void free_sh_audio(demuxer_t *demuxer, int id) 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); + mp_msg(MSGT_DEMUXER, MSGL_WARN, "Requested video stream id overflow (%d > %d)\n", + id, MAX_V_STREAMS); return NULL; } if (demuxer->v_streams[id]) - mp_msg(MSGT_DEMUXER,MSGL_WARN,MSGTR_VideoStreamRedefined,id); + mp_msg(MSGT_DEMUXER, MSGL_WARN, MSGTR_VideoStreamRedefined, id); else { sh_video_t *sh = calloc(1, sizeof(sh_video_t)); - mp_msg(MSGT_DEMUXER,MSGL_V,MSGTR_FoundVideoStream,id); + mp_msg(MSGT_DEMUXER, MSGL_V, MSGTR_FoundVideoStream, id); demuxer->v_streams[id] = sh; sh->vid = vid; sh->ds = demuxer->video; - mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_VIDEO_ID=%d\n", vid); + mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_VIDEO_ID=%d\n", vid); } return demuxer->v_streams[id]; } void free_sh_video(sh_video_t *sh) { - mp_msg(MSGT_DEMUXER,MSGL_DBG2,"DEMUXER: freeing sh_video at %p\n",sh); + mp_msg(MSGT_DEMUXER, MSGL_DBG2, "DEMUXER: freeing sh_video at %p\n", sh); free(sh->bih); free(sh); } @@ -328,12 +328,12 @@ void free_sh_video(sh_video_t *sh) void free_demuxer(demuxer_t *demuxer) { int i; - mp_msg(MSGT_DEMUXER,MSGL_DBG2,"DEMUXER: freeing demuxer at %p\n",demuxer); + mp_msg(MSGT_DEMUXER, MSGL_DBG2, "DEMUXER: freeing demuxer at %p\n", demuxer); if (demuxer->desc->close) - demuxer->desc->close(demuxer); + demuxer->desc->close(demuxer); // Very ugly hack to make it behave like old implementation if (demuxer->desc->type == DEMUXER_TYPE_DEMUXERS) - goto skip_streamfree; + goto skip_streamfree; // free streams: for (i = 0; i < MAX_A_STREAMS; i++) if (demuxer->a_streams[i]) @@ -348,25 +348,25 @@ void free_demuxer(demuxer_t *demuxer) free_demuxer_stream(demuxer->audio); free_demuxer_stream(demuxer->video); free_demuxer_stream(demuxer->sub); -skip_streamfree: + skip_streamfree: if (demuxer->info) { - for (i = 0; demuxer->info[i] != NULL; i++) - free(demuxer->info[i]); - free(demuxer->info); + for (i = 0; demuxer->info[i] != NULL; i++) + free(demuxer->info[i]); + free(demuxer->info); } free(demuxer->filename); if (demuxer->chapters) { - for (i = 0; i<demuxer->num_chapters; i++) - free(demuxer->chapters[i].name); - free(demuxer->chapters); + for (i = 0; i < demuxer->num_chapters; i++) + free(demuxer->chapters[i].name); + free(demuxer->chapters); } if (demuxer->attachments) { - 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); + 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); } free(demuxer); } @@ -376,31 +376,31 @@ void ds_add_packet(demux_stream_t *ds, demux_packet_t *dp) { // append packet to DS stream: ++ds->packs; - ds->bytes+=dp->len; + ds->bytes += dp->len; if (ds->last) { - // next packet in stream - ds->last->next=dp; - ds->last=dp; + // next packet in stream + ds->last->next = dp; + ds->last = dp; } else { - // first packet in stream - ds->first=ds->last=dp; + // first packet in stream + ds->first = ds->last = dp; } - 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); + 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); } 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); + demux_packet_t *dp = new_demux_packet(len); + len = stream_read(stream, dp->buffer, len); resize_demux_packet(dp, len); dp->pts = pts; - dp->pos=pos; - dp->flags=flags; + dp->pos = pos; + dp->flags = flags; // append packet to DS stream: - ds_add_packet(ds,dp); + ds_add_packet(ds, dp); } // return value: @@ -409,8 +409,8 @@ void ds_read_packet(demux_stream_t *ds, stream_t *stream, int len, int demux_fill_buffer(demuxer_t *demux, demux_stream_t *ds) { - // Note: parameter 'ds' can be NULL! - return demux->desc->fill_buffer(demux, ds); + // Note: parameter 'ds' can be NULL! + return demux->desc->fill_buffer(demux, ds); } // return value: @@ -419,11 +419,11 @@ int demux_fill_buffer(demuxer_t *demux, demux_stream_t *ds) #define MAX_ACUMULATED_PACKETS 64 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)) { + 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) @@ -432,86 +432,86 @@ int ds_fill_buffer(demux_stream_t *ds) 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; + } + while (1) { + if (ds->packs) { + demux_packet_t *p = ds->first; #if 0 - 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; - } - } + 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; + } + } #endif - // 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 + // 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 + } } - } - 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; + 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; } 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; + 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; } /** @@ -525,56 +525,56 @@ return bytes; int demux_pattern_3(demux_stream_t *ds, unsigned char *mem, int maxlen, int *read, uint32_t pattern) { - register uint32_t head = 0xffffff00; - register uint32_t pat = pattern & 0xffffff00; - int total_len = 0; - do { - 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; - } + register uint32_t head = 0xffffff00; + register uint32_t pat = pattern & 0xffffff00; + int total_len = 0; 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; + 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; } 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; + 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; } int ds_get_packet(demux_stream_t *ds, unsigned char **start) @@ -587,13 +587,13 @@ int ds_get_packet(demux_stream_t *ds, unsigned char **start) return -1; } } - len=ds->buffer_size-ds->buffer_pos; + len = ds->buffer_size - ds->buffer_pos; *start = &ds->buffer[ds->buffer_pos]; - ds->buffer_pos+=len; + ds->buffer_pos += len; return len; } -int ds_get_packet_pts(demux_stream_t *ds,unsigned char **start, double *pts) +int ds_get_packet_pts(demux_stream_t *ds, unsigned char **start, double *pts) { int len; *pts = MP_NOPTS_VALUE; @@ -607,67 +607,67 @@ int ds_get_packet_pts(demux_stream_t *ds,unsigned char **start, double *pts) // Return pts unless this read starts from the middle of a packet if (!ds->buffer_pos) *pts = ds->current->pts; - len=ds->buffer_size-ds->buffer_pos; + len = ds->buffer_size - ds->buffer_pos; *start = &ds->buffer[ds->buffer_pos]; - ds->buffer_pos+=len; + ds->buffer_pos += len; return len; } int ds_get_packet_sub(demux_stream_t *ds, unsigned char **start) { int len; - if(ds->buffer_pos >= ds->buffer_size){ + 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; + len = ds->buffer_size - ds->buffer_pos; *start = &ds->buffer[ds->buffer_pos]; - ds->buffer_pos+=len; + ds->buffer_pos += len; return len; } double ds_get_next_pts(demux_stream_t *ds) { - 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; + 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; } - if(!demux_fill_buffer(demux,ds)) - return MP_NOPTS_VALUE; - } - return ds->first->pts; + return ds->first->pts; } // ==================================================================== void demuxer_help(void) { - 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); - } + 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); + } } @@ -681,37 +681,37 @@ void demuxer_help(void) */ int get_demuxer_type_from_name(char *demuxer_name, int *force) { - 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; - } - - // 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; + 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; + } + + // 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; + return -1; } -int extension_parsing=1; // 0=off 1=mixed (used only for unstable formats) +int extension_parsing = 1; // 0=off 1=mixed (used only for unstable formats) -int correct_pts=0; -int user_correct_pts=-1; +int correct_pts = 0; +int user_correct_pts = -1; /* NOTE : Several demuxers may be opened at the same time so @@ -730,162 +730,160 @@ static demuxer_t *demux_open_stream(stream_t *stream, int file_format, int force, int audio_id, int video_id, int dvdsub_id, char *filename) { -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 = new_demuxer(stream,demuxer_desc->type,audio_id,video_id,dvdsub_id,filename); - 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; + 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 = new_demuxer(stream, demuxer_desc->type, audio_id, video_id, dvdsub_id, filename); + if (demuxer_desc->check_file) + fformat = demuxer_desc->check_file(demuxer); + |