manpage: Fix outdated -vo gl usage example.
[mplayer/glamo.git] / libmpdemux / demux_demuxers.c
blob531f048508f2268baee5d7e6cd8cb6ceae604bd9
1 /*
2 * This file is part of MPlayer.
4 * MPlayer is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * MPlayer is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 #include "config.h"
20 #include "mp_msg.h"
22 #include <stdlib.h>
23 #include <stdio.h>
24 #include "stream/stream.h"
25 #include "demuxer.h"
26 #include "stheader.h"
27 #include "talloc.h"
29 typedef struct dd_priv {
30 demuxer_t* vd;
31 demuxer_t* ad;
32 demuxer_t* sd;
33 } dd_priv_t;
35 extern const demuxer_desc_t demuxer_desc_demuxers;
37 demuxer_t* new_demuxers_demuxer(demuxer_t* vd, demuxer_t* ad, demuxer_t* sd) {
38 demuxer_t* ret;
39 dd_priv_t* priv;
41 ret = talloc_zero(NULL, struct demuxer);
43 priv = malloc(sizeof(dd_priv_t));
44 priv->vd = vd;
45 priv->ad = ad;
46 priv->sd = sd;
47 ret->priv = priv;
49 ret->type = ret->file_format = DEMUXER_TYPE_DEMUXERS;
50 // Video is the most important :-)
51 ret->stream = vd->stream;
52 ret->seekable = vd->seekable && ad->seekable && sd->seekable;
54 ret->video = vd->video;
55 ret->audio = ad->audio;
56 ret->sub = sd->sub;
57 if (sd && sd != vd && sd != ad) sd->sub->non_interleaved = 1;
59 // without these, demux_demuxers_fill_buffer will never be called,
60 // but they break the demuxer-specific code in video.c
61 #if 0
62 if (vd) vd->video->demuxer = ret;
63 if (ad) ad->audio->demuxer = ret;
64 if (sd) sd->sub->demuxer = ret;
65 #endif
67 // HACK?, necessary for subtitle (and audio and video when implemented) switching
68 memcpy(ret->v_streams, vd->v_streams, sizeof(ret->v_streams));
69 memcpy(ret->a_streams, ad->a_streams, sizeof(ret->a_streams));
70 memcpy(ret->s_streams, sd->s_streams, sizeof(ret->s_streams));
72 ret->desc = &demuxer_desc_demuxers;
74 return ret;
77 static int demux_demuxers_fill_buffer(demuxer_t *demux,demux_stream_t *ds) {
78 dd_priv_t* priv;
80 priv=demux->priv;
82 // HACK: make sure the subtitles get properly interleaved if with -subfile
83 if (priv->sd && priv->sd->sub != ds &&
84 priv->sd != priv->vd && priv->sd != priv->ad)
85 ds_get_next_pts(priv->sd->sub);
86 if(priv->vd && priv->vd->video == ds)
87 return demux_fill_buffer(priv->vd,ds);
88 else if(priv->ad && priv->ad->audio == ds)
89 return demux_fill_buffer(priv->ad,ds);
90 else if(priv->sd && priv->sd->sub == ds)
91 return demux_fill_buffer(priv->sd,ds);
93 mp_tmsg(MSGT_DEMUX,MSGL_WARN,"fill_buffer error: bad demuxer: not vd, ad or sd.\n");
94 return 0;
97 static void demux_demuxers_seek(demuxer_t *demuxer,float rel_seek_secs,float audio_delay,int flags) {
98 dd_priv_t* priv;
99 float pos;
100 priv=demuxer->priv;
102 priv->ad->stream->eof = 0;
103 priv->sd->stream->eof = 0;
105 // Seek video
106 demux_seek(priv->vd,rel_seek_secs,audio_delay,flags);
107 // Get the new pos
108 pos = demuxer->video->pts;
109 if (!pos) {
110 demux_fill_buffer(priv->vd, demuxer->video);
111 if (demuxer->video->first)
112 pos = demuxer->video->first->pts;
115 if(priv->ad != priv->vd) {
116 sh_audio_t* sh = demuxer->audio->sh;
117 demux_seek(priv->ad,pos,audio_delay,1);
118 // In case the demuxer don't set pts
119 if(!demuxer->audio->pts)
120 demuxer->audio->pts = pos-((ds_tell_pts(demuxer->audio)-sh->a_in_buffer_len)/(float)sh->i_bps);
123 if(priv->sd != priv->vd)
124 demux_seek(priv->sd,pos,audio_delay,1);
128 static void demux_close_demuxers(demuxer_t* demuxer) {
129 dd_priv_t* priv = demuxer->priv;
130 stream_t *s;
132 if(priv->vd)
133 free_demuxer(priv->vd);
134 if(priv->ad && priv->ad != priv->vd) {
135 // That's a hack to free the audio file stream
136 // It's ok atm but we shouldn't free that here
137 s = priv->ad->stream;
138 free_demuxer(priv->ad);
139 free_stream(s);
140 } if(priv->sd && priv->sd != priv->vd && priv->sd != priv->ad) {
141 s = priv->sd->stream;
142 free_demuxer(priv->sd);
143 free_stream(s);
146 free(priv);
150 static int demux_demuxers_control(demuxer_t *demuxer,int cmd, void *arg){
151 dd_priv_t* priv = demuxer->priv;
152 switch (cmd) {
153 case DEMUXER_CTRL_GET_TIME_LENGTH:
154 *((double *)arg) = demuxer_get_time_length(priv->vd);
155 return DEMUXER_CTRL_OK;
156 case DEMUXER_CTRL_GET_PERCENT_POS:
157 *((int *)arg) = demuxer_get_percent_pos(priv->vd);
158 return DEMUXER_CTRL_OK;
160 return DEMUXER_CTRL_NOTIMPL;
163 const demuxer_desc_t demuxer_desc_demuxers = {
164 "Demuxers demuxer",
165 "", // Not selectable
167 "?",
168 "internal use only",
169 DEMUXER_TYPE_DEMUXERS,
170 0, // no autodetect
171 NULL,
172 demux_demuxers_fill_buffer,
173 NULL,
174 demux_close_demuxers,
175 demux_demuxers_seek,
176 demux_demuxers_control