Add explanatory comments to the #endif part of multiple inclusion guards.
[mplayer/greg.git] / libmpdemux / demux_demuxers.c
blob1edd1429cbe9cdab57e28a3a9fb93c70e80281f1
2 #include "config.h"
3 #include "mp_msg.h"
4 #include "help_mp.h"
6 #include <stdlib.h>
7 #include <stdio.h>
8 #include "stream/stream.h"
9 #include "demuxer.h"
10 #include "stheader.h"
12 typedef struct dd_priv {
13 demuxer_t* vd;
14 demuxer_t* ad;
15 demuxer_t* sd;
16 } dd_priv_t;
18 extern demuxer_desc_t demuxer_desc_demuxers;
20 demuxer_t* new_demuxers_demuxer(demuxer_t* vd, demuxer_t* ad, demuxer_t* sd) {
21 demuxer_t* ret;
22 dd_priv_t* priv;
24 ret = calloc(1,sizeof(demuxer_t));
26 priv = malloc(sizeof(dd_priv_t));
27 priv->vd = vd;
28 priv->ad = ad;
29 priv->sd = sd;
30 ret->priv = priv;
32 ret->type = ret->file_format = DEMUXER_TYPE_DEMUXERS;
33 // Video is the most important :-)
34 ret->stream = vd->stream;
35 ret->seekable = vd->seekable && ad->seekable && sd->seekable;
37 ret->video = vd->video;
38 ret->audio = ad->audio;
39 ret->sub = sd->sub;
41 ret->desc = &demuxer_desc_demuxers;
43 return ret;
46 static int demux_demuxers_fill_buffer(demuxer_t *demux,demux_stream_t *ds) {
47 dd_priv_t* priv;
49 priv=demux->priv;
51 if(ds->demuxer == priv->vd)
52 return demux_fill_buffer(priv->vd,ds);
53 else if(ds->demuxer == priv->ad)
54 return demux_fill_buffer(priv->ad,ds);
55 else if(ds->demuxer == priv->sd)
56 return demux_fill_buffer(priv->sd,ds);
58 mp_msg(MSGT_DEMUX,MSGL_WARN,MSGTR_MPDEMUX_DEMUXERS_FillBufferError);
59 return 0;
62 static void demux_demuxers_seek(demuxer_t *demuxer,float rel_seek_secs,float audio_delay,int flags) {
63 dd_priv_t* priv;
64 float pos;
65 priv=demuxer->priv;
67 priv->ad->stream->eof = 0;
68 priv->sd->stream->eof = 0;
70 // Seek video
71 demux_seek(priv->vd,rel_seek_secs,audio_delay,flags);
72 // Get the new pos
73 pos = demuxer->video->pts;
74 if (!pos) {
75 demux_fill_buffer(priv->vd, demuxer->video);
76 if (demuxer->video->first)
77 pos = demuxer->video->first->pts;
80 if(priv->ad != priv->vd) {
81 sh_audio_t* sh = (sh_audio_t*)demuxer->audio->sh;
82 demux_seek(priv->ad,pos,audio_delay,1);
83 // In case the demuxer don't set pts
84 if(!demuxer->audio->pts)
85 demuxer->audio->pts = pos-((ds_tell_pts(demuxer->audio)-sh->a_in_buffer_len)/(float)sh->i_bps);
88 if(priv->sd != priv->vd)
89 demux_seek(priv->sd,pos,audio_delay,1);
93 static void demux_close_demuxers(demuxer_t* demuxer) {
94 dd_priv_t* priv = demuxer->priv;
95 stream_t *s;
97 if(priv->vd)
98 free_demuxer(priv->vd);
99 if(priv->ad && priv->ad != priv->vd) {
100 // That's a hack to free the audio file stream
101 // It's ok atm but we shouldn't free that here
102 s = priv->ad->stream;
103 free_demuxer(priv->ad);
104 free_stream(s);
105 } if(priv->sd && priv->sd != priv->vd && priv->sd != priv->ad) {
106 s = priv->sd->stream;
107 free_demuxer(priv->sd);
108 free_stream(s);
111 free(priv);
115 static int demux_demuxers_control(demuxer_t *demuxer,int cmd, void *arg){
116 dd_priv_t* priv = demuxer->priv;
117 switch (cmd) {
118 case DEMUXER_CTRL_GET_TIME_LENGTH:
119 *((double *)arg) = demuxer_get_time_length(priv->vd);
120 return DEMUXER_CTRL_OK;
121 case DEMUXER_CTRL_GET_PERCENT_POS:
122 *((int *)arg) = demuxer_get_percent_pos(priv->vd);
123 return DEMUXER_CTRL_OK;
125 return DEMUXER_CTRL_NOTIMPL;
128 demuxer_desc_t demuxer_desc_demuxers = {
129 "Demuxers demuxer",
130 "", // Not selectable
132 "?",
133 "internal use only",
134 DEMUXER_TYPE_DEMUXERS,
135 0, // no autodetect
136 NULL,
137 demux_demuxers_fill_buffer,
138 NULL,
139 demux_close_demuxers,
140 demux_demuxers_seek,
141 demux_demuxers_control