8 #include "stream/stream.h"
12 typedef struct dd_priv
{
18 extern const demuxer_desc_t demuxer_desc_demuxers
;
20 demuxer_t
* new_demuxers_demuxer(demuxer_t
* vd
, demuxer_t
* ad
, demuxer_t
* sd
) {
24 ret
= calloc(1,sizeof(demuxer_t
));
26 priv
= malloc(sizeof(dd_priv_t
));
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
;
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
;
51 static int demux_demuxers_fill_buffer(demuxer_t
*demux
,demux_stream_t
*ds
) {
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
);
67 static void demux_demuxers_seek(demuxer_t
*demuxer
,float rel_seek_secs
,float audio_delay
,int flags
) {
72 priv
->ad
->stream
->eof
= 0;
73 priv
->sd
->stream
->eof
= 0;
76 demux_seek(priv
->vd
,rel_seek_secs
,audio_delay
,flags
);
78 pos
= demuxer
->video
->pts
;
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
;
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
);
110 } if(priv
->sd
&& priv
->sd
!= priv
->vd
&& priv
->sd
!= priv
->ad
) {
111 s
= priv
->sd
->stream
;
112 free_demuxer(priv
->sd
);
120 static int demux_demuxers_control(demuxer_t
*demuxer
,int cmd
, void *arg
){
121 dd_priv_t
* priv
= demuxer
->priv
;
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
= {
135 "", // Not selectable
139 DEMUXER_TYPE_DEMUXERS
,
142 demux_demuxers_fill_buffer
,
144 demux_close_demuxers
,
146 demux_demuxers_control