annotate DOCS/tech/general.txt @ 5793:a4165df1936d

divx audio workaround
author arpi
date Tue, 23 Apr 2002 09:26:29 +0000
parents 6ce9c6231bdd
children 4846c53f548d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
132
642d64c1cc33 translation by Gabucino
gabucino
parents:
diff changeset
1 So, I'll describe how this stuff works.
642d64c1cc33 translation by Gabucino
gabucino
parents:
diff changeset
2
642d64c1cc33 translation by Gabucino
gabucino
parents:
diff changeset
3 The main modules:
642d64c1cc33 translation by Gabucino
gabucino
parents:
diff changeset
4
5586
6ce9c6231bdd updated
arpi
parents: 5244
diff changeset
5 1. stream.c: this is the input layer, this reads the input media (file, stdin,
6ce9c6231bdd updated
arpi
parents: 5244
diff changeset
6 vcd, dvd, network etc). what it has to know: appropriate buffering by
6ce9c6231bdd updated
arpi
parents: 5244
diff changeset
7 sector, seek, skip functions, reading by bytes, or blocks with any size.
6ce9c6231bdd updated
arpi
parents: 5244
diff changeset
8 The stream_t (stream.h) structure describes the input stream, file/device.
132
642d64c1cc33 translation by Gabucino
gabucino
parents:
diff changeset
9
5586
6ce9c6231bdd updated
arpi
parents: 5244
diff changeset
10 There is a stream cache layer (cache2.c), it's a wrapper for the stream
6ce9c6231bdd updated
arpi
parents: 5244
diff changeset
11 API. It does fork(), then emulates stream driver in the parent process,
6ce9c6231bdd updated
arpi
parents: 5244
diff changeset
12 and stream user in the child process, while proxying between them using
6ce9c6231bdd updated
arpi
parents: 5244
diff changeset
13 preallocated big memory chunk for FIFO buffer.
6ce9c6231bdd updated
arpi
parents: 5244
diff changeset
14
6ce9c6231bdd updated
arpi
parents: 5244
diff changeset
15 2. demuxer.c: this does the demultiplexing (separating) of the input to
6ce9c6231bdd updated
arpi
parents: 5244
diff changeset
16 audio, video or dvdsub channels, and their reading by buffered packages.
132
642d64c1cc33 translation by Gabucino
gabucino
parents:
diff changeset
17 The demuxer.c is basically a framework, which is the same for all the
642d64c1cc33 translation by Gabucino
gabucino
parents:
diff changeset
18 input formats, and there are parsers for each of them (mpeg-es,
642d64c1cc33 translation by Gabucino
gabucino
parents:
diff changeset
19 mpeg-ps, avi, avi-ni, asf), these are in the demux_*.c files.
642d64c1cc33 translation by Gabucino
gabucino
parents:
diff changeset
20 The structure is the demuxer_t. There is only one demuxer.
642d64c1cc33 translation by Gabucino
gabucino
parents:
diff changeset
21
551
e6263c6d377a kommit, kommit
gabucino
parents: 404
diff changeset
22 2.a. demux_packet_t, that is DP.
e6263c6d377a kommit, kommit
gabucino
parents: 404
diff changeset
23 Contains one chunk (avi) or packet (asf,mpg). They are stored in memory as
5586
6ce9c6231bdd updated
arpi
parents: 5244
diff changeset
24 in linked list, cause of their different size.
551
e6263c6d377a kommit, kommit
gabucino
parents: 404
diff changeset
25
876
1f26877717f1 *** empty log message ***
gabucino
parents: 551
diff changeset
26 2.b. demuxer stream, that is DS.
1f26877717f1 *** empty log message ***
gabucino
parents: 551
diff changeset
27 Struct: demux_stream_t
5586
6ce9c6231bdd updated
arpi
parents: 5244
diff changeset
28 Every channel (a/v/s) has one. This contains the packets for the stream
876
1f26877717f1 *** empty log message ***
gabucino
parents: 551
diff changeset
29 (see 2.a). For now, there can be 3 for each demuxer :
1f26877717f1 *** empty log message ***
gabucino
parents: 551
diff changeset
30 - audio (d_audio)
1f26877717f1 *** empty log message ***
gabucino
parents: 551
diff changeset
31 - video (d_video)
1f26877717f1 *** empty log message ***
gabucino
parents: 551
diff changeset
32 - DVD subtitle (d_dvdsub)
132
642d64c1cc33 translation by Gabucino
gabucino
parents:
diff changeset
33
551
e6263c6d377a kommit, kommit
gabucino
parents: 404
diff changeset
34 2.c. stream header. There are 2 types (for now): sh_audio_t and sh_video_t
e6263c6d377a kommit, kommit
gabucino
parents: 404
diff changeset
35 This contains every parameter essential for decoding, such as input/output
e6263c6d377a kommit, kommit
gabucino
parents: 404
diff changeset
36 buffers, chosen codec, fps, etc. There are each for every stream in
e6263c6d377a kommit, kommit
gabucino
parents: 404
diff changeset
37 the file. At least one for video, if sound is present then another,
e6263c6d377a kommit, kommit
gabucino
parents: 404
diff changeset
38 but if there are more, then there'll be one structure for each.
e6263c6d377a kommit, kommit
gabucino
parents: 404
diff changeset
39 These are filled according to the header (avi/asf), or demux_mpg.c
e6263c6d377a kommit, kommit
gabucino
parents: 404
diff changeset
40 does it (mpg) if it founds a new stream. If a new stream is found,
e6263c6d377a kommit, kommit
gabucino
parents: 404
diff changeset
41 the ====> Found audio/video stream: <id> messages is displayed.
e6263c6d377a kommit, kommit
gabucino
parents: 404
diff changeset
42
e6263c6d377a kommit, kommit
gabucino
parents: 404
diff changeset
43 The chosen stream header and its demuxer are connected together
e6263c6d377a kommit, kommit
gabucino
parents: 404
diff changeset
44 (ds->sh and sh->ds) to simplify the usage. So it's enough to pass the
e6263c6d377a kommit, kommit
gabucino
parents: 404
diff changeset
45 ds or the sh, depending on the function.
e6263c6d377a kommit, kommit
gabucino
parents: 404
diff changeset
46
e6263c6d377a kommit, kommit
gabucino
parents: 404
diff changeset
47 For example: we have an asf file, 6 streams inside it, 1 audio, 5
876
1f26877717f1 *** empty log message ***
gabucino
parents: 551
diff changeset
48 video. During the reading of the header, 6 sh structs are created, 1
1f26877717f1 *** empty log message ***
gabucino
parents: 551
diff changeset
49 audio and 5 video. When it starts reading the packet, it chooses the
1f26877717f1 *** empty log message ***
gabucino
parents: 551
diff changeset
50 stream for the first found audio & video packet, and sets the sh
1f26877717f1 *** empty log message ***
gabucino
parents: 551
diff changeset
51 pointers of d_audio and d_video according to them. So later it reads
1f26877717f1 *** empty log message ***
gabucino
parents: 551
diff changeset
52 only these streams. Of course the user can force choosing a specific
1f26877717f1 *** empty log message ***
gabucino
parents: 551
diff changeset
53 stream with
551
e6263c6d377a kommit, kommit
gabucino
parents: 404
diff changeset
54 -vid and -aid switches.
e6263c6d377a kommit, kommit
gabucino
parents: 404
diff changeset
55 A good example for this is the DVD, where the english stream is not
e6263c6d377a kommit, kommit
gabucino
parents: 404
diff changeset
56 always the first, so every VOB has different language :)
e6263c6d377a kommit, kommit
gabucino
parents: 404
diff changeset
57 That's when we have to use for example the -aid 128 switch.
e6263c6d377a kommit, kommit
gabucino
parents: 404
diff changeset
58
132
642d64c1cc33 translation by Gabucino
gabucino
parents:
diff changeset
59 Now, how this reading works?
642d64c1cc33 translation by Gabucino
gabucino
parents:
diff changeset
60 - demuxer.c/demux_read_data() is called, it gets how many bytes,
642d64c1cc33 translation by Gabucino
gabucino
parents:
diff changeset
61 and where (memory address), would we like to read, and from which
642d64c1cc33 translation by Gabucino
gabucino
parents:
diff changeset
62 DS. The codecs call this.
642d64c1cc33 translation by Gabucino
gabucino
parents:
diff changeset
63 - this checks if the given DS's buffer contains something, if so, it
642d64c1cc33 translation by Gabucino
gabucino
parents:
diff changeset
64 reads from there as much as needed. If there isn't enough, it calls
642d64c1cc33 translation by Gabucino
gabucino
parents:
diff changeset
65 ds_fill_buffer(), which:
642d64c1cc33 translation by Gabucino
gabucino
parents:
diff changeset
66 - checks if the given DS has buffered packages (DP's), if so, it moves
642d64c1cc33 translation by Gabucino
gabucino
parents:
diff changeset
67 the oldest to the buffer, and reads on. If the list is empty, it
642d64c1cc33 translation by Gabucino
gabucino
parents:
diff changeset
68 calls demux_fill_buffer() :
642d64c1cc33 translation by Gabucino
gabucino
parents:
diff changeset
69 - this calls the parser for the input format, which reads the file
642d64c1cc33 translation by Gabucino
gabucino
parents:
diff changeset
70 onward, and moves the found packages to their buffers.
642d64c1cc33 translation by Gabucino
gabucino
parents:
diff changeset
71 Well it we'd like an audio package, but only a bunch of video
642d64c1cc33 translation by Gabucino
gabucino
parents:
diff changeset
72 packages are available, then sooner or later the:
642d64c1cc33 translation by Gabucino
gabucino
parents:
diff changeset
73 DEMUXER: Too many (%d in %d bytes) audio packets in the buffer
642d64c1cc33 translation by Gabucino
gabucino
parents:
diff changeset
74 error shows up.
642d64c1cc33 translation by Gabucino
gabucino
parents:
diff changeset
75
5586
6ce9c6231bdd updated
arpi
parents: 5244
diff changeset
76 2.d. video.c: this file/function handle the reading and assembling of the
6ce9c6231bdd updated
arpi
parents: 5244
diff changeset
77 video frames. each call to video_read_frame() should read and return a
6ce9c6231bdd updated
arpi
parents: 5244
diff changeset
78 single video frame, and it's duration in seconds (float).
6ce9c6231bdd updated
arpi
parents: 5244
diff changeset
79 The implementation is splitted to 2 big parts - reading from mpeg-like
6ce9c6231bdd updated
arpi
parents: 5244
diff changeset
80 streams and reading from one-frame-per-chunk files (avi, asf, mov).
6ce9c6231bdd updated
arpi
parents: 5244
diff changeset
81 Then it calculates duration, either from fixed FPS value, or from the
6ce9c6231bdd updated
arpi
parents: 5244
diff changeset
82 PTS difference between and after reading the frame.
6ce9c6231bdd updated
arpi
parents: 5244
diff changeset
83
6ce9c6231bdd updated
arpi
parents: 5244
diff changeset
84 2.e. other utility functions: there are some usefull code there, like
6ce9c6231bdd updated
arpi
parents: 5244
diff changeset
85 AVI muxer, or mp3 header parser, but leave them for now.
6ce9c6231bdd updated
arpi
parents: 5244
diff changeset
86
6ce9c6231bdd updated
arpi
parents: 5244
diff changeset
87 So everything is ok 'till now. It can be found in libmpdemux/ library.
6ce9c6231bdd updated
arpi
parents: 5244
diff changeset
88 It should compile outside of mplayer tree, you just have to implement few
6ce9c6231bdd updated
arpi
parents: 5244
diff changeset
89 simple functions, like mp_msg() to print messages, etc.
6ce9c6231bdd updated
arpi
parents: 5244
diff changeset
90 See libmpdemux/test.c for example.
6ce9c6231bdd updated
arpi
parents: 5244
diff changeset
91
6ce9c6231bdd updated
arpi
parents: 5244
diff changeset
92 See also formats.txt, for description of common media file formats and their
6ce9c6231bdd updated
arpi
parents: 5244
diff changeset
93 implementation details in libmpdemux.
132
642d64c1cc33 translation by Gabucino
gabucino
parents:
diff changeset
94
642d64c1cc33 translation by Gabucino
gabucino
parents:
diff changeset
95 Now, go on:
642d64c1cc33 translation by Gabucino
gabucino
parents:
diff changeset
96
642d64c1cc33 translation by Gabucino
gabucino
parents:
diff changeset
97 3. mplayer.c - ooh, he's the boss :)
1649
5b52297e559c typos, small fixes
arpi
parents: 1500
diff changeset
98 Its main purpose is connecting the other modules, and maintaining A/V
1500
526047bdda07 *** empty log message ***
gabucino
parents: 994
diff changeset
99 sync.
877
3e94ca839def *** empty log message ***
gabucino
parents: 876
diff changeset
100
1649
5b52297e559c typos, small fixes
arpi
parents: 1500
diff changeset
101 The given stream's actual position is in the 'timer' field of the
5b52297e559c typos, small fixes
arpi
parents: 1500
diff changeset
102 corresponding stream header (sh_audio / sh_video).
876
1f26877717f1 *** empty log message ***
gabucino
parents: 551
diff changeset
103
1f26877717f1 *** empty log message ***
gabucino
parents: 551
diff changeset
104 The structure of the playing loop :
1f26877717f1 *** empty log message ***
gabucino
parents: 551
diff changeset
105 while(not EOF) {
1f26877717f1 *** empty log message ***
gabucino
parents: 551
diff changeset
106 fill audio buffer (read & decode audio) + increase a_frame
1f26877717f1 *** empty log message ***
gabucino
parents: 551
diff changeset
107 read & decode a single video frame + increase v_frame
1f26877717f1 *** empty log message ***
gabucino
parents: 551
diff changeset
108 sleep (wait until a_frame>=v_frame)
1f26877717f1 *** empty log message ***
gabucino
parents: 551
diff changeset
109 display the frame
1f26877717f1 *** empty log message ***
gabucino
parents: 551
diff changeset
110 apply A-V PTS correction to a_frame
5586
6ce9c6231bdd updated
arpi
parents: 5244
diff changeset
111 handle events (keys,lirc etc) -> pause,seek,...
876
1f26877717f1 *** empty log message ***
gabucino
parents: 551
diff changeset
112 }
1f26877717f1 *** empty log message ***
gabucino
parents: 551
diff changeset
113
132
642d64c1cc33 translation by Gabucino
gabucino
parents:
diff changeset
114 When playing (a/v), it increases the variables by the duration of the
876
1f26877717f1 *** empty log message ***
gabucino
parents: 551
diff changeset
115 played a/v.
1f26877717f1 *** empty log message ***
gabucino
parents: 551
diff changeset
116 - with audio this is played bytes / sh_audio->o_bps
1f26877717f1 *** empty log message ***
gabucino
parents: 551
diff changeset
117 Note: i_bps = number of compressed bytes for one second of audio
1f26877717f1 *** empty log message ***
gabucino
parents: 551
diff changeset
118 o_bps = number of uncompressed bytes for one second of audio
1f26877717f1 *** empty log message ***
gabucino
parents: 551
diff changeset
119 (this is = bps*samplerate*channels)
1f26877717f1 *** empty log message ***
gabucino
parents: 551
diff changeset
120 - with video this is usually == 1.0/fps, but I have to note that
138
5f2805a2d5de even more cosmetics
gabucino
parents: 136
diff changeset
121 fps doesn't really matters at video, for example asf doesn't have that,
5f2805a2d5de even more cosmetics
gabucino
parents: 136
diff changeset
122 instead there is "duration" and it can change per frame.
132
642d64c1cc33 translation by Gabucino
gabucino
parents:
diff changeset
123 MPEG2 has "repeat_count" which delays the frame by 1-2.5 ...
642d64c1cc33 translation by Gabucino
gabucino
parents:
diff changeset
124 Maybe only AVI and MPEG1 has fixed fps.
642d64c1cc33 translation by Gabucino
gabucino
parents:
diff changeset
125
138
5f2805a2d5de even more cosmetics
gabucino
parents: 136
diff changeset
126 So everything works right until the audio and video are in perfect
132
642d64c1cc33 translation by Gabucino
gabucino
parents:
diff changeset
127 synchronity, since the audio goes, it gives the timing, and if the
642d64c1cc33 translation by Gabucino
gabucino
parents:
diff changeset
128 time of a frame passed, the next frame is displayed.
642d64c1cc33 translation by Gabucino
gabucino
parents:
diff changeset
129 But what if these two aren't synchronized in the input file?
642d64c1cc33 translation by Gabucino
gabucino
parents:
diff changeset
130 PTS correction kicks in. The input demuxers read the PTS (presentation
642d64c1cc33 translation by Gabucino
gabucino
parents:
diff changeset
131 timestamp) of the packages, and with it we can see if the streams
642d64c1cc33 translation by Gabucino
gabucino
parents:
diff changeset
132 are synchronized. Then MPlayer can correct the a_frame, within
642d64c1cc33 translation by Gabucino
gabucino
parents:
diff changeset
133 a given maximal bounder (see -mc option). The summary of the
642d64c1cc33 translation by Gabucino
gabucino
parents:
diff changeset
134 corrections can be found in c_total .
642d64c1cc33 translation by Gabucino
gabucino
parents:
diff changeset
135
642d64c1cc33 translation by Gabucino
gabucino
parents:
diff changeset
136 Of course this is not everything, several things suck.
642d64c1cc33 translation by Gabucino
gabucino
parents:
diff changeset
137 For example the soundcards delay, which has to be corrected by
876
1f26877717f1 *** empty log message ***
gabucino
parents: 551
diff changeset
138 MPlayer! The audio delay is the sum of all these:
1f26877717f1 *** empty log message ***
gabucino
parents: 551
diff changeset
139 - bytes read since the last timestamp:
1f26877717f1 *** empty log message ***
gabucino
parents: 551
diff changeset
140 t1 = d_audio->pts_bytes/sh_audio->i_bps
1f26877717f1 *** empty log message ***
gabucino
parents: 551
diff changeset
141 - if Win32/ACM then the bytes stored in audio input buffer
1f26877717f1 *** empty log message ***
gabucino
parents: 551
diff changeset
142 t2 = a_in_buffer_len/sh_audio->i_bps
1f26877717f1 *** empty log message ***
gabucino
parents: 551
diff changeset
143 - uncompressed bytes in audio out buffer
1f26877717f1 *** empty log message ***
gabucino
parents: 551
diff changeset
144 t3 = a_buffer_len/sh_audio->o_bps
1f26877717f1 *** empty log message ***
gabucino
parents: 551
diff changeset
145 - not yet played bytes stored in the soundcard's (or DMA's) buffer
1f26877717f1 *** empty log message ***
gabucino
parents: 551
diff changeset
146 t4 = get_audio_delay()/sh_audio->o_bps
1f26877717f1 *** empty log message ***
gabucino
parents: 551
diff changeset
147
1f26877717f1 *** empty log message ***
gabucino
parents: 551
diff changeset
148 From this we can calculate what PTS we need for the just played
1f26877717f1 *** empty log message ***
gabucino
parents: 551
diff changeset
149 audio, then after we compare this with the video's PTS, we have
1f26877717f1 *** empty log message ***
gabucino
parents: 551
diff changeset
150 the difference!
132
642d64c1cc33 translation by Gabucino
gabucino
parents:
diff changeset
151
642d64c1cc33 translation by Gabucino
gabucino
parents:
diff changeset
152 Life didn't get simpler with AVI. There's the "official" timing
642d64c1cc33 translation by Gabucino
gabucino
parents:
diff changeset
153 method, the BPS-based, so the header contains how many compressed
1500
526047bdda07 *** empty log message ***
gabucino
parents: 994
diff changeset
154 audio bytes or chunks belong to one second of frames.
526047bdda07 *** empty log message ***
gabucino
parents: 994
diff changeset
155 In the AVI stream header there are 2 important fields, the
526047bdda07 *** empty log message ***
gabucino
parents: 994
diff changeset
156 dwSampleSize, and dwRate/dwScale pairs:
526047bdda07 *** empty log message ***
gabucino
parents: 994
diff changeset
157 - If the dwSampleSize is 0, then it's VBR stream, so its bitrate
526047bdda07 *** empty log message ***
gabucino
parents: 994
diff changeset
158 isn't constant. It means that 1 chunk stores 1 sample, and
526047bdda07 *** empty log message ***
gabucino
parents: 994
diff changeset
159 dwRate/dwScale gives the chunks/sec value.
526047bdda07 *** empty log message ***
gabucino
parents: 994
diff changeset
160 - If the dwSampleSize is >0, then it's constant bitrate, and the
526047bdda07 *** empty log message ***
gabucino
parents: 994
diff changeset
161 time can be measured this way: time = (bytepos/dwSampleSize) /
526047bdda07 *** empty log message ***
gabucino
parents: 994
diff changeset
162 (dwRate/dwScale) (so the sample's number is divided with the
526047bdda07 *** empty log message ***
gabucino
parents: 994
diff changeset
163 samplerate). Now the audio can be handled as a stream, which can
526047bdda07 *** empty log message ***
gabucino
parents: 994
diff changeset
164 be cut to chunks, but can be one chunk also.
132
642d64c1cc33 translation by Gabucino
gabucino
parents:
diff changeset
165
1500
526047bdda07 *** empty log message ***
gabucino
parents: 994
diff changeset
166 The other method can be used only for interleaved files: from
526047bdda07 *** empty log message ***
gabucino
parents: 994
diff changeset
167 the order of the chunks, a timestamp (PTS) value can be calculated.
526047bdda07 *** empty log message ***
gabucino
parents: 994
diff changeset
168 The PTS of the video chunks are simple: chunk number * fps
526047bdda07 *** empty log message ***
gabucino
parents: 994
diff changeset
169 The audio is the same as the previous video chunk was.
526047bdda07 *** empty log message ***
gabucino
parents: 994
diff changeset
170 We have to pay attention to the so called "audio preload", that is,
526047bdda07 *** empty log message ***
gabucino
parents: 994
diff changeset
171 there is a delay between the audio and video streams. This is
526047bdda07 *** empty log message ***
gabucino
parents: 994
diff changeset
172 usually 0.5-1.0 sec, but can be totally different.
526047bdda07 *** empty log message ***
gabucino
parents: 994
diff changeset
173 The exact value was measured until now, but now the demux_avi.c
526047bdda07 *** empty log message ***
gabucino
parents: 994
diff changeset
174 handles it: at the audio chunk after the first video, it calculates
526047bdda07 *** empty log message ***
gabucino
parents: 994
diff changeset
175 the A/V difference, and take this as a measure for audio preload.
876
1f26877717f1 *** empty log message ***
gabucino
parents: 551
diff changeset
176
1f26877717f1 *** empty log message ***
gabucino
parents: 551
diff changeset
177 3.a. audio playback:
1f26877717f1 *** empty log message ***
gabucino
parents: 551
diff changeset
178 Some words on audio playback:
1f26877717f1 *** empty log message ***
gabucino
parents: 551
diff changeset
179 Not the playing is hard, but:
1f26877717f1 *** empty log message ***
gabucino
parents: 551
diff changeset
180 1. knowing when to write into the buffer, without blocking
1f26877717f1 *** empty log message ***
gabucino
parents: 551
diff changeset
181 2. knowing how much was played of what we wrote into
1f26877717f1 *** empty log message ***
gabucino
parents: 551
diff changeset
182 The first is needed for audio decoding, and to keep the buffer
1f26877717f1 *** empty log message ***
gabucino
parents: 551
diff changeset
183 full (so the audio will never skip). And the second is needed for
1f26877717f1 *** empty log message ***
gabucino
parents: 551
diff changeset
184 correct timing, because some soundcards delay even 3-7 seconds,
1f26877717f1 *** empty log message ***
gabucino
parents: 551
diff changeset
185 which can't be forgotten about.
1f26877717f1 *** empty log message ***
gabucino
parents: 551
diff changeset
186 To solve this, the OSS gives several possibilities:
1f26877717f1 *** empty log message ***
gabucino
parents: 551
diff changeset
187 - ioctl(SNDCTL_DSP_GETODELAY): tells how many unplayed bytes are in
1f26877717f1 *** empty log message ***
gabucino
parents: 551
diff changeset
188 the soundcard's buffer -> perfect for timing, but not all drivers
1f26877717f1 *** empty log message ***
gabucino
parents: 551
diff changeset
189 support it :(
1f26877717f1 *** empty log message ***
gabucino
parents: 551
diff changeset
190 - ioctl(SNDCTL_DSP_GETOSPACE): tells how much can we write into the
1f26877717f1 *** empty log message ***
gabucino
parents: 551
diff changeset
191 soundcard's buffer, without blocking. If the driver doesn't
1f26877717f1 *** empty log message ***
gabucino
parents: 551
diff changeset
192 support GETODELAY, we can use this to know how much the delay is.
1f26877717f1 *** empty log message ***
gabucino
parents: 551
diff changeset
193 - select(): should tell if we can write into the buffer without
1f26877717f1 *** empty log message ***
gabucino
parents: 551
diff changeset
194 blocking. Unfortunately it doesn't say how much we could :((
1f26877717f1 *** empty log message ***
gabucino
parents: 551
diff changeset
195 Also, doesn't/badly works with some drivers.
1f26877717f1 *** empty log message ***
gabucino
parents: 551
diff changeset
196 Only used if none of the above works.
132
642d64c1cc33 translation by Gabucino
gabucino
parents:
diff changeset
197
5586
6ce9c6231bdd updated
arpi
parents: 5244
diff changeset
198 4. Codecs. Consists of libmpcodecs/* and separate files or libs,
6ce9c6231bdd updated
arpi
parents: 5244
diff changeset
199 for example liba52, libmpeg2, xa/*, alaw.c, opendivx/*, loader, mp3lib.
1500
526047bdda07 *** empty log message ***
gabucino
parents: 994
diff changeset
200
5586
6ce9c6231bdd updated
arpi
parents: 5244
diff changeset
201 mplayer.c doesn't call them directly, but through the dec_audio.c and
1500
526047bdda07 *** empty log message ***
gabucino
parents: 994
diff changeset
202 dec_video.c files, so the mplayer.c doesn't have to know anything about
5586
6ce9c6231bdd updated
arpi
parents: 5244
diff changeset
203 the codecs.
6ce9c6231bdd updated
arpi
parents: 5244
diff changeset
204
6ce9c6231bdd updated
arpi
parents: 5244
diff changeset
205 libmpcodecs contains wrapper for every codecs, some of them include the
6ce9c6231bdd updated
arpi
parents: 5244
diff changeset
206 codec function implementation, some calls functions from other files
6ce9c6231bdd updated
arpi
parents: 5244
diff changeset
207 included with mplayer, some calls optional external libraries.
6ce9c6231bdd updated
arpi
parents: 5244
diff changeset
208 file naming convention in libmpcodecs:
6ce9c6231bdd updated
arpi
parents: 5244
diff changeset
209 ad_*.c - audio decoder (called through dec_audio.c)
6ce9c6231bdd updated
arpi
parents: 5244
diff changeset
210 vd_*.c - video decoder (called through dec_video.c)
6ce9c6231bdd updated
arpi
parents: 5244
diff changeset
211 ve_*.c - video encoder (used by mencoder)
6ce9c6231bdd updated
arpi
parents: 5244
diff changeset
212 vf_*.c - video filter (see option -vop)
132
642d64c1cc33 translation by Gabucino
gabucino
parents:
diff changeset
213
551
e6263c6d377a kommit, kommit
gabucino
parents: 404
diff changeset
214 5. libvo: this displays the frame.
e6263c6d377a kommit, kommit
gabucino
parents: 404
diff changeset
215
5586
6ce9c6231bdd updated
arpi
parents: 5244
diff changeset
216 for details on this, read libvo.txt
551
e6263c6d377a kommit, kommit
gabucino
parents: 404
diff changeset
217
986
fadb8eeff7a8 commitus interruptus
gabucino
parents: 878
diff changeset
218 6. libao2: this control audio playing
551
e6263c6d377a kommit, kommit
gabucino
parents: 404
diff changeset
219
986
fadb8eeff7a8 commitus interruptus
gabucino
parents: 878
diff changeset
220 As in libvo (see 5.) also here are some drivers, based on the same API:
fadb8eeff7a8 commitus interruptus
gabucino
parents: 878
diff changeset
221
991
dab1e9e67d8c 1 typo corrected (any more, atmos?)
gabucino
parents: 986
diff changeset
222 static int control(int cmd, int arg);
986
fadb8eeff7a8 commitus interruptus
gabucino
parents: 878
diff changeset
223 This is for reading/setting driver-specific and other special parameters.
fadb8eeff7a8 commitus interruptus
gabucino
parents: 878
diff changeset
224 Not really used for now.
fadb8eeff7a8 commitus interruptus
gabucino
parents: 878
diff changeset
225
fadb8eeff7a8 commitus interruptus
gabucino
parents: 878
diff changeset
226 static int init(int rate,int channels,int format,int flags);
fadb8eeff7a8 commitus interruptus
gabucino
parents: 878
diff changeset
227 The init of driver, opens device, sets sample rate, channels, sample format
fadb8eeff7a8 commitus interruptus
gabucino
parents: 878
diff changeset
228 parameters.
fadb8eeff7a8 commitus interruptus
gabucino
parents: 878
diff changeset
229 Sample format: usually AFMT_S16_LE or AFMT_U8, for more definitions see
fadb8eeff7a8 commitus interruptus
gabucino
parents: 878
diff changeset
230 dec_audio.c and linux/soundcards.h files!
fadb8eeff7a8 commitus interruptus
gabucino
parents: 878
diff changeset
231
fadb8eeff7a8 commitus interruptus
gabucino
parents: 878
diff changeset
232 static void uninit();
fadb8eeff7a8 commitus interruptus
gabucino
parents: 878
diff changeset
233 Guess what.
fadb8eeff7a8 commitus interruptus
gabucino
parents: 878
diff changeset
234 Ok I help: closes the device, not (yet) called when exit.
fadb8eeff7a8 commitus interruptus
gabucino
parents: 878
diff changeset
235
994
84a887d85203 huje gabu :)
atmosfear
parents: 991
diff changeset
236 static void reset();
986
fadb8eeff7a8 commitus interruptus
gabucino
parents: 878
diff changeset
237 Resets device. To be exact, it's for deleting buffers' contents,
fadb8eeff7a8 commitus interruptus
gabucino
parents: 878
diff changeset
238 so after reset() the previously received stuff won't be output.
fadb8eeff7a8 commitus interruptus
gabucino
parents: 878
diff changeset
239 (called if pause or seek)
fadb8eeff7a8 commitus interruptus
gabucino
parents: 878
diff changeset
240
fadb8eeff7a8 commitus interruptus
gabucino
parents: 878
diff changeset
241 static int get_space();
fadb8eeff7a8 commitus interruptus
gabucino
parents: 878
diff changeset
242 Returns how many bytes can be written into the audio buffer without
fadb8eeff7a8 commitus interruptus
gabucino
parents: 878
diff changeset
243 blocking (making caller process wait). If the buffer is (nearly) full,
fadb8eeff7a8 commitus interruptus
gabucino
parents: 878
diff changeset
244 has to return 0!
fadb8eeff7a8 commitus interruptus
gabucino
parents: 878
diff changeset
245 If it never gives 0, MPlayer won't work!
fadb8eeff7a8 commitus interruptus
gabucino
parents: 878
diff changeset
246
fadb8eeff7a8 commitus interruptus
gabucino
parents: 878
diff changeset
247 static int play(void* data,int len,int flags);
fadb8eeff7a8 commitus interruptus
gabucino
parents: 878
diff changeset
248 Plays a bit of audio, which is received throught the "data" memory area, with
fadb8eeff7a8 commitus interruptus
gabucino
parents: 878
diff changeset
249 a size of "len". The "flags" isn't used yet. It has to copy the data, because
fadb8eeff7a8 commitus interruptus
gabucino
parents: 878
diff changeset
250 they can be overwritten after the call is made. Doesn't really have to use
fadb8eeff7a8 commitus interruptus
gabucino
parents: 878
diff changeset
251 all the bytes, it has to give back how many have been used (copied to
fadb8eeff7a8 commitus interruptus
gabucino
parents: 878
diff changeset
252 buffer).
fadb8eeff7a8 commitus interruptus
gabucino
parents: 878
diff changeset
253
4582
9c13e907f284 applied patch from Andres Johansson
gabucino
parents: 4161
diff changeset
254 static float get_delay();
9c13e907f284 applied patch from Andres Johansson
gabucino
parents: 4161
diff changeset
255 Returns how long time it will take to play the data currently in the
9c13e907f284 applied patch from Andres Johansson
gabucino
parents: 4161
diff changeset
256 output buffer. Be exact, if possible, since the whole timing depends
9c13e907f284 applied patch from Andres Johansson
gabucino
parents: 4161
diff changeset
257 on this! In the worst case, return the maximum delay.
986
fadb8eeff7a8 commitus interruptus
gabucino
parents: 878
diff changeset
258
fadb8eeff7a8 commitus interruptus
gabucino
parents: 878
diff changeset
259 !!! Because the video is synchronized to the audio (card), it's very important
4582
9c13e907f284 applied patch from Andres Johansson
gabucino
parents: 4161
diff changeset
260 !!! that the get_space and get_delay functions are correctly implemented!
986
fadb8eeff7a8 commitus interruptus
gabucino
parents: 878
diff changeset
261
4582
9c13e907f284 applied patch from Andres Johansson
gabucino
parents: 4161
diff changeset
262 6.a audio plugins
9c13e907f284 applied patch from Andres Johansson
gabucino
parents: 4161
diff changeset
263 Audio plugins are used for processing the audio data before it
9c13e907f284 applied patch from Andres Johansson
gabucino
parents: 4161
diff changeset
264 reaches the soundcard driver. A plugin can change the following
9c13e907f284 applied patch from Andres Johansson
gabucino
parents: 4161
diff changeset
265 aspects of the audio data stream:
9c13e907f284 applied patch from Andres Johansson
gabucino
parents: 4161
diff changeset
266 1. Sample format
9c13e907f284 applied patch from Andres Johansson
gabucino
parents: 4161
diff changeset
267 2. Sample rate
9c13e907f284 applied patch from Andres Johansson
gabucino
parents: 4161
diff changeset
268 3. Number of channels
9c13e907f284 applied patch from Andres Johansson
gabucino
parents: 4161
diff changeset
269 4. The data itself (i.e. filtering and other sound effects)
9c13e907f284 applied patch from Andres Johansson
gabucino
parents: 4161
diff changeset
270 5. The delay (almost all plugins does this)
9c13e907f284 applied patch from Andres Johansson
gabucino
parents: 4161
diff changeset
271 The plugin interface is implemented as a pseudo device driver with
9c13e907f284 applied patch from Andres Johansson
gabucino
parents: 4161
diff changeset
272 the catchy name "plugin". The plugins are executed sequentially
9c13e907f284 applied patch from Andres Johansson
gabucino
parents: 4161
diff changeset
273 ordered by the "-aop list=plugin1,plugin2,..." command line switch.
9c13e907f284 applied patch from Andres Johansson
gabucino
parents: 4161
diff changeset
274 To add plugins add an entry in audio_plugin.h the makefile and
9c13e907f284 applied patch from Andres Johansson
gabucino
parents: 4161
diff changeset
275 create a source file named "pl_whatever.c". Input parameters are
9c13e907f284 applied patch from Andres Johansson
gabucino
parents: 4161
diff changeset
276 added to audio_plugin.h and to cfg-mplayer.h. A good starting point
9c13e907f284 applied patch from Andres Johansson
gabucino
parents: 4161
diff changeset
277 for writing plugins is pl_delay.c. Below is a description of what
9c13e907f284 applied patch from Andres Johansson
gabucino
parents: 4161
diff changeset
278 the functions does:
9c13e907f284 applied patch from Andres Johansson
gabucino
parents: 4161
diff changeset
279
9c13e907f284 applied patch from Andres Johansson
gabucino
parents: 4161
diff changeset
280 static int control(int cmd, int arg);
9c13e907f284 applied patch from Andres Johansson
gabucino
parents: 4161
diff changeset
281 This is for reading/setting plugin-specific and other special
9c13e907f284 applied patch from Andres Johansson
gabucino
parents: 4161
diff changeset
282 parameters and can be used for keyboard input for example. All
9c13e907f284 applied patch from Andres Johansson
gabucino
parents: 4161
diff changeset
283 plugins bust respond to cmd=AOCONTROL_PLUGIN_SET_LEN which is part
9c13e907f284 applied patch from Andres Johansson
gabucino
parents: 4161
diff changeset
284 of the initialization of the plugin. When this command is received
9c13e907f284 applied patch from Andres Johansson
gabucino
parents: 4161
diff changeset
285 the parameter pl_delay.len will contain the maximum size of data the
9c13e907f284 applied patch from Andres Johansson
gabucino
parents: 4161
diff changeset
286 plugin can produce. This can be used for calculating and allocating
9c13e907f284 applied patch from Andres Johansson
gabucino
parents: 4161
diff changeset
287 buffer space for the plugin. Before the function exits the parameter
9c13e907f284 applied patch from Andres Johansson
gabucino
parents: 4161
diff changeset
288 pl_delay.len must be set to the maximum data size the plugin can
9c13e907f284 applied patch from Andres Johansson
gabucino
parents: 4161
diff changeset
289 receive. Return CONTROL_OK for success and CONTROL_ERROR for fail,
9c13e907f284 applied patch from Andres Johansson
gabucino
parents: 4161
diff changeset
290 other control codes are found in audio_out.h.
9c13e907f284 applied patch from Andres Johansson
gabucino
parents: 4161
diff changeset
291
9c13e907f284 applied patch from Andres Johansson
gabucino
parents: 4161
diff changeset
292 static int init();
9c13e907f284 applied patch from Andres Johansson
gabucino
parents: 4161
diff changeset
293 This function is for initializing the plugin, it is called once
9c13e907f284 applied patch from Andres Johansson
gabucino
parents: 4161
diff changeset
294 before the playing is started. In this function the plugin can read
9c13e907f284 applied patch from Andres Johansson
gabucino
parents: 4161
diff changeset
295 AND write to the ao_plugin_data struct to determine and set input
9c13e907f284 applied patch from Andres Johansson
gabucino
parents: 4161
diff changeset
296 and output parameters. It is important to write to the
9c13e907f284 applied patch from Andres Johansson
gabucino
parents: 4161
diff changeset
297 ao_plugin_data.sz_mult and ao_plugin_data.delay_fix parameters if
9c13e907f284 applied patch from Andres Johansson
gabucino
parents: 4161
diff changeset
298 the plugin changes the data size or adds delay. Return 0 for fail
9c13e907f284 applied patch from Andres Johansson
gabucino
parents: 4161
diff changeset
299 and 1 for success.
9c13e907f284 applied patch from Andres Johansson
gabucino
parents: 4161
diff changeset
300
9c13e907f284 applied patch from Andres Johansson
gabucino
parents: 4161
diff changeset
301 static void uninit()
9c13e907f284 applied patch from Andres Johansson
gabucino
parents: 4161
diff changeset
302 Called before mplayer exits. Used for deallocating dynamic buffers.
9c13e907f284 applied patch from Andres Johansson
gabucino
parents: 4161
diff changeset
303
9c13e907f284 applied patch from Andres Johansson
gabucino
parents: 4161
diff changeset
304 static void reset()
9c13e907f284 applied patch from Andres Johansson
gabucino
parents: 4161
diff changeset
305 Called during reset can be used to empty buffers. Mplayer calls this
9c13e907f284 applied patch from Andres Johansson
gabucino
parents: 4161
diff changeset
306 function when pause is pressed.
9c13e907f284 applied patch from Andres Johansson
gabucino
parents: 4161
diff changeset
307
9c13e907f284 applied patch from Andres Johansson
gabucino
parents: 4161
diff changeset
308 static int play()
9c13e907f284 applied patch from Andres Johansson
gabucino
parents: 4161
diff changeset
309 Called for every block of audio data sent through the plugin. This
9c13e907f284 applied patch from Andres Johansson
gabucino
parents: 4161
diff changeset
310 function should be optimized for speed. The incoming data is found
9c13e907f284 applied patch from Andres Johansson
gabucino
parents: 4161
diff changeset
311 in ao_plugin_data.data having length ao_plugin_data.len. These two
9c13e907f284 applied patch from Andres Johansson
gabucino
parents: 4161
diff changeset
312 parameters should be changed by the plugin. Return 1 for success and
9c13e907f284 applied patch from Andres Johansson
gabucino
parents: 4161
diff changeset
313 0 for fail.
9c13e907f284 applied patch from Andres Johansson
gabucino
parents: 4161
diff changeset
314