annotate libmpdemux/demux_demuxers.c @ 27010:ef48c2f8d4c5

Make a section out of the svgalib_helper paragraph.
author diego
date Mon, 09 Jun 2008 08:58:56 +0000
parents a0c157a99aac
children d643e4643313
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4765
d0c2c8af46b4 Demuxers demuxer support for using external audiofile (or muxed subtitles).
albeu
parents:
diff changeset
1
d0c2c8af46b4 Demuxers demuxer support for using external audiofile (or muxed subtitles).
albeu
parents:
diff changeset
2 #include "config.h"
18176
f72bc5754209 Part3 of Otvos Attila's oattila AT chello-hu mp_msg changes, with lots of modifications as usual
reynaldo
parents: 17636
diff changeset
3 #include "mp_msg.h"
f72bc5754209 Part3 of Otvos Attila's oattila AT chello-hu mp_msg changes, with lots of modifications as usual
reynaldo
parents: 17636
diff changeset
4 #include "help_mp.h"
4765
d0c2c8af46b4 Demuxers demuxer support for using external audiofile (or muxed subtitles).
albeu
parents:
diff changeset
5
d0c2c8af46b4 Demuxers demuxer support for using external audiofile (or muxed subtitles).
albeu
parents:
diff changeset
6 #include <stdlib.h>
d0c2c8af46b4 Demuxers demuxer support for using external audiofile (or muxed subtitles).
albeu
parents:
diff changeset
7 #include <stdio.h>
22605
4d81dbdf46b9 Add explicit location for headers from the stream/ directory.
diego
parents: 20071
diff changeset
8 #include "stream/stream.h"
4765
d0c2c8af46b4 Demuxers demuxer support for using external audiofile (or muxed subtitles).
albeu
parents:
diff changeset
9 #include "demuxer.h"
d0c2c8af46b4 Demuxers demuxer support for using external audiofile (or muxed subtitles).
albeu
parents:
diff changeset
10 #include "stheader.h"
d0c2c8af46b4 Demuxers demuxer support for using external audiofile (or muxed subtitles).
albeu
parents:
diff changeset
11
d0c2c8af46b4 Demuxers demuxer support for using external audiofile (or muxed subtitles).
albeu
parents:
diff changeset
12 typedef struct dd_priv {
d0c2c8af46b4 Demuxers demuxer support for using external audiofile (or muxed subtitles).
albeu
parents:
diff changeset
13 demuxer_t* vd;
d0c2c8af46b4 Demuxers demuxer support for using external audiofile (or muxed subtitles).
albeu
parents:
diff changeset
14 demuxer_t* ad;
d0c2c8af46b4 Demuxers demuxer support for using external audiofile (or muxed subtitles).
albeu
parents:
diff changeset
15 demuxer_t* sd;
d0c2c8af46b4 Demuxers demuxer support for using external audiofile (or muxed subtitles).
albeu
parents:
diff changeset
16 } dd_priv_t;
d0c2c8af46b4 Demuxers demuxer support for using external audiofile (or muxed subtitles).
albeu
parents:
diff changeset
17
25707
d4fe6e23283e Make all demuxer_desc_t const, thus moving them to .rodata
reimar
parents: 22605
diff changeset
18 extern const demuxer_desc_t demuxer_desc_demuxers;
4765
d0c2c8af46b4 Demuxers demuxer support for using external audiofile (or muxed subtitles).
albeu
parents:
diff changeset
19
d0c2c8af46b4 Demuxers demuxer support for using external audiofile (or muxed subtitles).
albeu
parents:
diff changeset
20 demuxer_t* new_demuxers_demuxer(demuxer_t* vd, demuxer_t* ad, demuxer_t* sd) {
d0c2c8af46b4 Demuxers demuxer support for using external audiofile (or muxed subtitles).
albeu
parents:
diff changeset
21 demuxer_t* ret;
d0c2c8af46b4 Demuxers demuxer support for using external audiofile (or muxed subtitles).
albeu
parents:
diff changeset
22 dd_priv_t* priv;
d0c2c8af46b4 Demuxers demuxer support for using external audiofile (or muxed subtitles).
albeu
parents:
diff changeset
23
18885
5c8acc972551 rm unnecesary casts from void* - part 4
reynaldo
parents: 18710
diff changeset
24 ret = calloc(1,sizeof(demuxer_t));
4765
d0c2c8af46b4 Demuxers demuxer support for using external audiofile (or muxed subtitles).
albeu
parents:
diff changeset
25
18885
5c8acc972551 rm unnecesary casts from void* - part 4
reynaldo
parents: 18710
diff changeset
26 priv = malloc(sizeof(dd_priv_t));
4765
d0c2c8af46b4 Demuxers demuxer support for using external audiofile (or muxed subtitles).
albeu
parents:
diff changeset
27 priv->vd = vd;
d0c2c8af46b4 Demuxers demuxer support for using external audiofile (or muxed subtitles).
albeu
parents:
diff changeset
28 priv->ad = ad;
d0c2c8af46b4 Demuxers demuxer support for using external audiofile (or muxed subtitles).
albeu
parents:
diff changeset
29 priv->sd = sd;
d0c2c8af46b4 Demuxers demuxer support for using external audiofile (or muxed subtitles).
albeu
parents:
diff changeset
30 ret->priv = priv;
d0c2c8af46b4 Demuxers demuxer support for using external audiofile (or muxed subtitles).
albeu
parents:
diff changeset
31
d0c2c8af46b4 Demuxers demuxer support for using external audiofile (or muxed subtitles).
albeu
parents:
diff changeset
32 ret->type = ret->file_format = DEMUXER_TYPE_DEMUXERS;
d0c2c8af46b4 Demuxers demuxer support for using external audiofile (or muxed subtitles).
albeu
parents:
diff changeset
33 // Video is the most important :-)
d0c2c8af46b4 Demuxers demuxer support for using external audiofile (or muxed subtitles).
albeu
parents:
diff changeset
34 ret->stream = vd->stream;
d0c2c8af46b4 Demuxers demuxer support for using external audiofile (or muxed subtitles).
albeu
parents:
diff changeset
35 ret->seekable = vd->seekable && ad->seekable && sd->seekable;
d0c2c8af46b4 Demuxers demuxer support for using external audiofile (or muxed subtitles).
albeu
parents:
diff changeset
36
d0c2c8af46b4 Demuxers demuxer support for using external audiofile (or muxed subtitles).
albeu
parents:
diff changeset
37 ret->video = vd->video;
d0c2c8af46b4 Demuxers demuxer support for using external audiofile (or muxed subtitles).
albeu
parents:
diff changeset
38 ret->audio = ad->audio;
d0c2c8af46b4 Demuxers demuxer support for using external audiofile (or muxed subtitles).
albeu
parents:
diff changeset
39 ret->sub = sd->sub;
16175
6b86089c2edd Demuxer modularization
rtognimp
parents: 9710
diff changeset
40
26817
a0c157a99aac Make internal subtitle and subtitle switching work with -audiofile
reimar
parents: 26297
diff changeset
41 // HACK?, necessary for subtitle (and audio and video when implemented) switching
a0c157a99aac Make internal subtitle and subtitle switching work with -audiofile
reimar
parents: 26297
diff changeset
42 memcpy(ret->v_streams, vd->v_streams, sizeof(ret->v_streams));
a0c157a99aac Make internal subtitle and subtitle switching work with -audiofile
reimar
parents: 26297
diff changeset
43 memcpy(ret->a_streams, ad->a_streams, sizeof(ret->a_streams));
a0c157a99aac Make internal subtitle and subtitle switching work with -audiofile
reimar
parents: 26297
diff changeset
44 memcpy(ret->s_streams, sd->s_streams, sizeof(ret->s_streams));
a0c157a99aac Make internal subtitle and subtitle switching work with -audiofile
reimar
parents: 26297
diff changeset
45
16175
6b86089c2edd Demuxer modularization
rtognimp
parents: 9710
diff changeset
46 ret->desc = &demuxer_desc_demuxers;
6b86089c2edd Demuxer modularization
rtognimp
parents: 9710
diff changeset
47
4765
d0c2c8af46b4 Demuxers demuxer support for using external audiofile (or muxed subtitles).
albeu
parents:
diff changeset
48 return ret;
d0c2c8af46b4 Demuxers demuxer support for using external audiofile (or muxed subtitles).
albeu
parents:
diff changeset
49 }
d0c2c8af46b4 Demuxers demuxer support for using external audiofile (or muxed subtitles).
albeu
parents:
diff changeset
50
16175
6b86089c2edd Demuxer modularization
rtognimp
parents: 9710
diff changeset
51 static int demux_demuxers_fill_buffer(demuxer_t *demux,demux_stream_t *ds) {
4765
d0c2c8af46b4 Demuxers demuxer support for using external audiofile (or muxed subtitles).
albeu
parents:
diff changeset
52 dd_priv_t* priv;
d0c2c8af46b4 Demuxers demuxer support for using external audiofile (or muxed subtitles).
albeu
parents:
diff changeset
53
d0c2c8af46b4 Demuxers demuxer support for using external audiofile (or muxed subtitles).
albeu
parents:
diff changeset
54 priv=demux->priv;
d0c2c8af46b4 Demuxers demuxer support for using external audiofile (or muxed subtitles).
albeu
parents:
diff changeset
55
d0c2c8af46b4 Demuxers demuxer support for using external audiofile (or muxed subtitles).
albeu
parents:
diff changeset
56 if(ds->demuxer == priv->vd)
d0c2c8af46b4 Demuxers demuxer support for using external audiofile (or muxed subtitles).
albeu
parents:
diff changeset
57 return demux_fill_buffer(priv->vd,ds);
d0c2c8af46b4 Demuxers demuxer support for using external audiofile (or muxed subtitles).
albeu
parents:
diff changeset
58 else if(ds->demuxer == priv->ad)
d0c2c8af46b4 Demuxers demuxer support for using external audiofile (or muxed subtitles).
albeu
parents:
diff changeset
59 return demux_fill_buffer(priv->ad,ds);
d0c2c8af46b4 Demuxers demuxer support for using external audiofile (or muxed subtitles).
albeu
parents:
diff changeset
60 else if(ds->demuxer == priv->sd)
d0c2c8af46b4 Demuxers demuxer support for using external audiofile (or muxed subtitles).
albeu
parents:
diff changeset
61 return demux_fill_buffer(priv->sd,ds);
d0c2c8af46b4 Demuxers demuxer support for using external audiofile (or muxed subtitles).
albeu
parents:
diff changeset
62
18176
f72bc5754209 Part3 of Otvos Attila's oattila AT chello-hu mp_msg changes, with lots of modifications as usual
reynaldo
parents: 17636
diff changeset
63 mp_msg(MSGT_DEMUX,MSGL_WARN,MSGTR_MPDEMUX_DEMUXERS_FillBufferError);
4765
d0c2c8af46b4 Demuxers demuxer support for using external audiofile (or muxed subtitles).
albeu
parents:
diff changeset
64 return 0;
d0c2c8af46b4 Demuxers demuxer support for using external audiofile (or muxed subtitles).
albeu
parents:
diff changeset
65 }
d0c2c8af46b4 Demuxers demuxer support for using external audiofile (or muxed subtitles).
albeu
parents:
diff changeset
66
17636
b849a99cdc3c Second-try commit of this patch.
corey
parents: 17569
diff changeset
67 static void demux_demuxers_seek(demuxer_t *demuxer,float rel_seek_secs,float audio_delay,int flags) {
4765
d0c2c8af46b4 Demuxers demuxer support for using external audiofile (or muxed subtitles).
albeu
parents:
diff changeset
68 dd_priv_t* priv;
d0c2c8af46b4 Demuxers demuxer support for using external audiofile (or muxed subtitles).
albeu
parents:
diff changeset
69 float pos;
d0c2c8af46b4 Demuxers demuxer support for using external audiofile (or muxed subtitles).
albeu
parents:
diff changeset
70 priv=demuxer->priv;
d0c2c8af46b4 Demuxers demuxer support for using external audiofile (or muxed subtitles).
albeu
parents:
diff changeset
71
d0c2c8af46b4 Demuxers demuxer support for using external audiofile (or muxed subtitles).
albeu
parents:
diff changeset
72 priv->ad->stream->eof = 0;
d0c2c8af46b4 Demuxers demuxer support for using external audiofile (or muxed subtitles).
albeu
parents:
diff changeset
73 priv->sd->stream->eof = 0;
d0c2c8af46b4 Demuxers demuxer support for using external audiofile (or muxed subtitles).
albeu
parents:
diff changeset
74
d0c2c8af46b4 Demuxers demuxer support for using external audiofile (or muxed subtitles).
albeu
parents:
diff changeset
75 // Seek video
17636
b849a99cdc3c Second-try commit of this patch.
corey
parents: 17569
diff changeset
76 demux_seek(priv->vd,rel_seek_secs,audio_delay,flags);
4765
d0c2c8af46b4 Demuxers demuxer support for using external audiofile (or muxed subtitles).
albeu
parents:
diff changeset
77 // Get the new pos
d0c2c8af46b4 Demuxers demuxer support for using external audiofile (or muxed subtitles).
albeu
parents:
diff changeset
78 pos = demuxer->video->pts;
20071
672123d27ae3 Fix demux_demuxers seeking if the video demuxer does not set
reimar
parents: 18958
diff changeset
79 if (!pos) {
672123d27ae3 Fix demux_demuxers seeking if the video demuxer does not set
reimar
parents: 18958
diff changeset
80 demux_fill_buffer(priv->vd, demuxer->video);
672123d27ae3 Fix demux_demuxers seeking if the video demuxer does not set
reimar
parents: 18958
diff changeset
81 if (demuxer->video->first)
672123d27ae3 Fix demux_demuxers seeking if the video demuxer does not set
reimar
parents: 18958
diff changeset
82 pos = demuxer->video->first->pts;
672123d27ae3 Fix demux_demuxers seeking if the video demuxer does not set
reimar
parents: 18958
diff changeset
83 }
4765
d0c2c8af46b4 Demuxers demuxer support for using external audiofile (or muxed subtitles).
albeu
parents:
diff changeset
84
d0c2c8af46b4 Demuxers demuxer support for using external audiofile (or muxed subtitles).
albeu
parents:
diff changeset
85 if(priv->ad != priv->vd) {
26297
e9e160b6b5ad Remove useless cast
reimar
parents: 25707
diff changeset
86 sh_audio_t* sh = demuxer->audio->sh;
17636
b849a99cdc3c Second-try commit of this patch.
corey
parents: 17569
diff changeset
87 demux_seek(priv->ad,pos,audio_delay,1);
4765
d0c2c8af46b4 Demuxers demuxer support for using external audiofile (or muxed subtitles).
albeu
parents:
diff changeset
88 // In case the demuxer don't set pts
d0c2c8af46b4 Demuxers demuxer support for using external audiofile (or muxed subtitles).
albeu
parents:
diff changeset
89 if(!demuxer->audio->pts)
d0c2c8af46b4 Demuxers demuxer support for using external audiofile (or muxed subtitles).
albeu
parents:
diff changeset
90 demuxer->audio->pts = pos-((ds_tell_pts(demuxer->audio)-sh->a_in_buffer_len)/(float)sh->i_bps);
d0c2c8af46b4 Demuxers demuxer support for using external audiofile (or muxed subtitles).
albeu
parents:
diff changeset
91 }
d0c2c8af46b4 Demuxers demuxer support for using external audiofile (or muxed subtitles).
albeu
parents:
diff changeset
92
d0c2c8af46b4 Demuxers demuxer support for using external audiofile (or muxed subtitles).
albeu
parents:
diff changeset
93 if(priv->sd != priv->vd)
17636
b849a99cdc3c Second-try commit of this patch.
corey
parents: 17569
diff changeset
94 demux_seek(priv->sd,pos,audio_delay,1);
4765
d0c2c8af46b4 Demuxers demuxer support for using external audiofile (or muxed subtitles).
albeu
parents:
diff changeset
95
d0c2c8af46b4 Demuxers demuxer support for using external audiofile (or muxed subtitles).
albeu
parents:
diff changeset
96 }
5812
f9d23c2aa6b7 Uninit added
albeu
parents: 4765
diff changeset
97
16175
6b86089c2edd Demuxer modularization
rtognimp
parents: 9710
diff changeset
98 static void demux_close_demuxers(demuxer_t* demuxer) {
5812
f9d23c2aa6b7 Uninit added
albeu
parents: 4765
diff changeset
99 dd_priv_t* priv = demuxer->priv;
9710
e3db09ae5154 Free the stream of the audio and subtitle demuxer.
albeu
parents: 8056
diff changeset
100 stream_t *s;
5812
f9d23c2aa6b7 Uninit added
albeu
parents: 4765
diff changeset
101
f9d23c2aa6b7 Uninit added
albeu
parents: 4765
diff changeset
102 if(priv->vd)
f9d23c2aa6b7 Uninit added
albeu
parents: 4765
diff changeset
103 free_demuxer(priv->vd);
9710
e3db09ae5154 Free the stream of the audio and subtitle demuxer.
albeu
parents: 8056
diff changeset
104 if(priv->ad && priv->ad != priv->vd) {
e3db09ae5154 Free the stream of the audio and subtitle demuxer.
albeu
parents: 8056
diff changeset
105 // That's a hack to free the audio file stream
e3db09ae5154 Free the stream of the audio and subtitle demuxer.
albeu
parents: 8056
diff changeset
106 // It's ok atm but we shouldn't free that here
e3db09ae5154 Free the stream of the audio and subtitle demuxer.
albeu
parents: 8056
diff changeset
107 s = priv->ad->stream;
5812
f9d23c2aa6b7 Uninit added
albeu
parents: 4765
diff changeset
108 free_demuxer(priv->ad);
9710
e3db09ae5154 Free the stream of the audio and subtitle demuxer.
albeu
parents: 8056
diff changeset
109 free_stream(s);
e3db09ae5154 Free the stream of the audio and subtitle demuxer.
albeu
parents: 8056
diff changeset
110 } if(priv->sd && priv->sd != priv->vd && priv->sd != priv->ad) {
e3db09ae5154 Free the stream of the audio and subtitle demuxer.
albeu
parents: 8056
diff changeset
111 s = priv->sd->stream;
5812
f9d23c2aa6b7 Uninit added
albeu
parents: 4765
diff changeset
112 free_demuxer(priv->sd);
9710
e3db09ae5154 Free the stream of the audio and subtitle demuxer.
albeu
parents: 8056
diff changeset
113 free_stream(s);
e3db09ae5154 Free the stream of the audio and subtitle demuxer.
albeu
parents: 8056
diff changeset
114 }
5812
f9d23c2aa6b7 Uninit added
albeu
parents: 4765
diff changeset
115
f9d23c2aa6b7 Uninit added
albeu
parents: 4765
diff changeset
116 free(priv);
f9d23c2aa6b7 Uninit added
albeu
parents: 4765
diff changeset
117 }
f9d23c2aa6b7 Uninit added
albeu
parents: 4765
diff changeset
118
16175
6b86089c2edd Demuxer modularization
rtognimp
parents: 9710
diff changeset
119
16876
9dd44ff7ec32 Provide DEMUXER_CTRL_GET_TIME_LENGTH and DEMUXER_CTRL_GET_PERCENT_POS.
reimar
parents: 16291
diff changeset
120 static int demux_demuxers_control(demuxer_t *demuxer,int cmd, void *arg){
9dd44ff7ec32 Provide DEMUXER_CTRL_GET_TIME_LENGTH and DEMUXER_CTRL_GET_PERCENT_POS.
reimar
parents: 16291
diff changeset
121 dd_priv_t* priv = demuxer->priv;
9dd44ff7ec32 Provide DEMUXER_CTRL_GET_TIME_LENGTH and DEMUXER_CTRL_GET_PERCENT_POS.
reimar
parents: 16291
diff changeset
122 switch (cmd) {
9dd44ff7ec32 Provide DEMUXER_CTRL_GET_TIME_LENGTH and DEMUXER_CTRL_GET_PERCENT_POS.
reimar
parents: 16291
diff changeset
123 case DEMUXER_CTRL_GET_TIME_LENGTH:
9dd44ff7ec32 Provide DEMUXER_CTRL_GET_TIME_LENGTH and DEMUXER_CTRL_GET_PERCENT_POS.
reimar
parents: 16291
diff changeset
124 *((double *)arg) = demuxer_get_time_length(priv->vd);
9dd44ff7ec32 Provide DEMUXER_CTRL_GET_TIME_LENGTH and DEMUXER_CTRL_GET_PERCENT_POS.
reimar
parents: 16291
diff changeset
125 return DEMUXER_CTRL_OK;
9dd44ff7ec32 Provide DEMUXER_CTRL_GET_TIME_LENGTH and DEMUXER_CTRL_GET_PERCENT_POS.
reimar
parents: 16291
diff changeset
126 case DEMUXER_CTRL_GET_PERCENT_POS:
9dd44ff7ec32 Provide DEMUXER_CTRL_GET_TIME_LENGTH and DEMUXER_CTRL_GET_PERCENT_POS.
reimar
parents: 16291
diff changeset
127 *((int *)arg) = demuxer_get_percent_pos(priv->vd);
9dd44ff7ec32 Provide DEMUXER_CTRL_GET_TIME_LENGTH and DEMUXER_CTRL_GET_PERCENT_POS.
reimar
parents: 16291
diff changeset
128 return DEMUXER_CTRL_OK;
9dd44ff7ec32 Provide DEMUXER_CTRL_GET_TIME_LENGTH and DEMUXER_CTRL_GET_PERCENT_POS.
reimar
parents: 16291
diff changeset
129 }
9dd44ff7ec32 Provide DEMUXER_CTRL_GET_TIME_LENGTH and DEMUXER_CTRL_GET_PERCENT_POS.
reimar
parents: 16291
diff changeset
130 return DEMUXER_CTRL_NOTIMPL;
9dd44ff7ec32 Provide DEMUXER_CTRL_GET_TIME_LENGTH and DEMUXER_CTRL_GET_PERCENT_POS.
reimar
parents: 16291
diff changeset
131 }
9dd44ff7ec32 Provide DEMUXER_CTRL_GET_TIME_LENGTH and DEMUXER_CTRL_GET_PERCENT_POS.
reimar
parents: 16291
diff changeset
132
25707
d4fe6e23283e Make all demuxer_desc_t const, thus moving them to .rodata
reimar
parents: 22605
diff changeset
133 const demuxer_desc_t demuxer_desc_demuxers = {
16175
6b86089c2edd Demuxer modularization
rtognimp
parents: 9710
diff changeset
134 "Demuxers demuxer",
6b86089c2edd Demuxer modularization
rtognimp
parents: 9710
diff changeset
135 "", // Not selectable
6b86089c2edd Demuxer modularization
rtognimp
parents: 9710
diff changeset
136 "",
6b86089c2edd Demuxer modularization
rtognimp
parents: 9710
diff changeset
137 "?",
6b86089c2edd Demuxer modularization
rtognimp
parents: 9710
diff changeset
138 "internal use only",
6b86089c2edd Demuxer modularization
rtognimp
parents: 9710
diff changeset
139 DEMUXER_TYPE_DEMUXERS,
6b86089c2edd Demuxer modularization
rtognimp
parents: 9710
diff changeset
140 0, // no autodetect
6b86089c2edd Demuxer modularization
rtognimp
parents: 9710
diff changeset
141 NULL,
6b86089c2edd Demuxer modularization
rtognimp
parents: 9710
diff changeset
142 demux_demuxers_fill_buffer,
6b86089c2edd Demuxer modularization
rtognimp
parents: 9710
diff changeset
143 NULL,
6b86089c2edd Demuxer modularization
rtognimp
parents: 9710
diff changeset
144 demux_close_demuxers,
6b86089c2edd Demuxer modularization
rtognimp
parents: 9710
diff changeset
145 demux_demuxers_seek,
16876
9dd44ff7ec32 Provide DEMUXER_CTRL_GET_TIME_LENGTH and DEMUXER_CTRL_GET_PERCENT_POS.
reimar
parents: 16291
diff changeset
146 demux_demuxers_control
16175
6b86089c2edd Demuxer modularization
rtognimp
parents: 9710
diff changeset
147 };