Remove the grayscale and 4:2:2 RTjpeg code, it is neither used nor is there
[mplayer/glamo.git] / libmpdemux / demux_demuxers.c
bloba5f87e601bda69f69855600a0bd0662cb5057b09
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 const 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 // HACK?, necessary for subtitle (and audio and video when implemented) switching
42 memcpy(ret->v_streams, vd->v_streams, sizeof(ret->v_streams));
43 memcpy(ret->a_streams, ad->a_streams, sizeof(ret->a_streams));
44 memcpy(ret->s_streams, sd->s_streams, sizeof(ret->s_streams));
46 ret->desc = &demuxer_desc_demuxers;
48 return ret;
51 static int demux_demuxers_fill_buffer(demuxer_t *demux,demux_stream_t *ds) {
52 dd_priv_t* priv;
54 priv=demux->priv;
56 if(ds->demuxer == priv->vd)
57 return demux_fill_buffer(priv->vd,ds);
58 else if(ds->demuxer == priv->ad)
59 return demux_fill_buffer(priv->ad,ds);
60 else if(ds->demuxer == priv->sd)
61 return demux_fill_buffer(priv->sd,ds);
63 mp_msg(MSGT_DEMUX,MSGL_WARN,MSGTR_MPDEMUX_DEMUXERS_FillBufferError);
64 return 0;
67 static void demux_demuxers_seek(demuxer_t *demuxer,float rel_seek_secs,float audio_delay,int flags) {
68 dd_priv_t* priv;
69 float pos;
70 priv=demuxer->priv;
72 priv->ad->stream->eof = 0;
73 priv->sd->stream->eof = 0;
75 // Seek video
76 demux_seek(priv->vd,rel_seek_secs,audio_delay,flags);
77 // Get the new pos
78 pos = demuxer->video->pts;
79 if (!pos) {
80 demux_fill_buffer(priv->vd, demuxer->video);
81 if (demuxer->video->first)
82 pos = demuxer->video->first->pts;
85 if(priv->ad != priv->vd) {
86 sh_audio_t* sh = demuxer->audio->sh;
87 demux_seek(priv->ad,pos,audio_delay,1);
88 // In case the demuxer don't set pts
89 if(!demuxer->audio->pts)
90 demuxer->audio->pts = pos-((ds_tell_pts(demuxer->audio)-sh->a_in_buffer_len)/(float)sh->i_bps);
93 if(priv->sd != priv->vd)
94 demux_seek(priv->sd,pos,audio_delay,1);
98 static void demux_close_demuxers(demuxer_t* demuxer) {
99 dd_priv_t* priv = demuxer->priv;
100 stream_t *s;
102 if(priv->vd)
103 free_demuxer(priv->vd);
104 if(priv->ad && priv->ad != priv->vd) {
105 // That's a hack to free the audio file stream
106 // It's ok atm but we shouldn't free that here
107 s = priv->ad->stream;
108 free_demuxer(priv->ad);
109 free_stream(s);
110 } if(priv->sd && priv->sd != priv->vd && priv->sd != priv->ad) {
111 s = priv->sd->stream;
112 free_demuxer(priv->sd);
113 free_stream(s);
116 free(priv);
120 static int demux_demuxers_control(demuxer_t *demuxer,int cmd, void *arg){
121 dd_priv_t* priv = demuxer->priv;
122 switch (cmd) {
123 case DEMUXER_CTRL_GET_TIME_LENGTH:
124 *((double *)arg) = demuxer_get_time_length(priv->vd);
125 return DEMUXER_CTRL_OK;
126 case DEMUXER_CTRL_GET_PERCENT_POS:
127 *((int *)arg) = demuxer_get_percent_pos(priv->vd);
128 return DEMUXER_CTRL_OK;
130 return DEMUXER_CTRL_NOTIMPL;
133 const demuxer_desc_t demuxer_desc_demuxers = {
134 "Demuxers demuxer",
135 "", // Not selectable
137 "?",
138 "internal use only",
139 DEMUXER_TYPE_DEMUXERS,
140 0, // no autodetect
141 NULL,
142 demux_demuxers_fill_buffer,
143 NULL,
144 demux_close_demuxers,
145 demux_demuxers_seek,
146 demux_demuxers_control