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.
24 #include "stream/stream.h"
29 typedef struct dd_priv
{
35 extern const demuxer_desc_t demuxer_desc_demuxers
;
37 demuxer_t
* new_demuxers_demuxer(demuxer_t
* vd
, demuxer_t
* ad
, demuxer_t
* sd
) {
41 ret
= talloc_zero(NULL
, struct demuxer
);
43 priv
= malloc(sizeof(dd_priv_t
));
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
;
53 ret
->stream_pts
= MP_NOPTS_VALUE
;
55 ret
->video
= vd
->video
;
56 ret
->audio
= ad
->audio
;
58 if (sd
&& sd
!= vd
&& sd
!= ad
) sd
->sub
->non_interleaved
= 1;
60 // without these, demux_demuxers_fill_buffer will never be called,
61 // but they break the demuxer-specific code in video.c
63 if (vd
) vd
->video
->demuxer
= ret
;
64 if (ad
) ad
->audio
->demuxer
= ret
;
65 if (sd
) sd
->sub
->demuxer
= ret
;
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
));
73 ret
->desc
= &demuxer_desc_demuxers
;
78 static int demux_demuxers_fill_buffer(demuxer_t
*demux
,demux_stream_t
*ds
) {
83 // HACK: make sure the subtitles get properly interleaved if with -subfile
84 if (priv
->sd
&& priv
->sd
->sub
!= ds
&&
85 priv
->sd
!= priv
->vd
&& priv
->sd
!= priv
->ad
)
86 ds_get_next_pts(priv
->sd
->sub
);
87 if(priv
->vd
&& priv
->vd
->video
== ds
)
88 return demux_fill_buffer(priv
->vd
,ds
);
89 else if(priv
->ad
&& priv
->ad
->audio
== ds
)
90 return demux_fill_buffer(priv
->ad
,ds
);
91 else if(priv
->sd
&& priv
->sd
->sub
== ds
)
92 return demux_fill_buffer(priv
->sd
,ds
);
94 mp_tmsg(MSGT_DEMUX
,MSGL_WARN
,"fill_buffer error: bad demuxer: not vd, ad or sd.\n");
98 static void demux_demuxers_seek(demuxer_t
*demuxer
,float rel_seek_secs
,float audio_delay
,int flags
) {
103 priv
->ad
->stream
->eof
= 0;
104 priv
->sd
->stream
->eof
= 0;
107 demux_seek(priv
->vd
,rel_seek_secs
,audio_delay
,flags
);
109 pos
= demuxer
->video
->pts
;
111 demux_fill_buffer(priv
->vd
, demuxer
->video
);
112 if (demuxer
->video
->first
)
113 pos
= demuxer
->video
->first
->pts
;
116 if(priv
->ad
!= priv
->vd
&& demuxer
->audio
->sh
) {
117 sh_audio_t
* sh
= demuxer
->audio
->sh
;
118 demux_seek(priv
->ad
,pos
,audio_delay
,1);
119 // In case the demuxer don't set pts
120 if(!demuxer
->audio
->pts
)
121 demuxer
->audio
->pts
= pos
-((ds_tell_pts(demuxer
->audio
)-sh
->a_in_buffer_len
)/(float)sh
->i_bps
);
124 if(priv
->sd
!= priv
->vd
)
125 demux_seek(priv
->sd
,pos
,audio_delay
,1);
129 static void demux_close_demuxers(demuxer_t
* demuxer
) {
130 dd_priv_t
* priv
= demuxer
->priv
;
134 free_demuxer(priv
->vd
);
135 if(priv
->ad
&& priv
->ad
!= priv
->vd
) {
136 // That's a hack to free the audio file stream
137 // It's ok atm but we shouldn't free that here
138 s
= priv
->ad
->stream
;
139 free_demuxer(priv
->ad
);
141 } if(priv
->sd
&& priv
->sd
!= priv
->vd
&& priv
->sd
!= priv
->ad
) {
142 s
= priv
->sd
->stream
;
143 free_demuxer(priv
->sd
);
151 static int demux_demuxers_control(demuxer_t
*demuxer
,int cmd
, void *arg
){
152 dd_priv_t
* priv
= demuxer
->priv
;
154 case DEMUXER_CTRL_GET_TIME_LENGTH
:
155 case DEMUXER_CTRL_GET_PERCENT_POS
:
156 return demux_control(priv
->vd
, cmd
, arg
);
158 return DEMUXER_CTRL_NOTIMPL
;
161 const demuxer_desc_t demuxer_desc_demuxers
= {
163 "", // Not selectable
167 DEMUXER_TYPE_DEMUXERS
,
170 demux_demuxers_fill_buffer
,
172 demux_close_demuxers
,
174 demux_demuxers_control