Debian Codegraph @

doc/tutorial.cpp

raw
1 /*! \page tutorial A libdvdnav Tutorial
2
3 The <tt>libdvdnav</tt> library provides a powerful API allowing your
4 programs to take advantage of the sophisticated navigation features
5 on DVDs.
6
7 \subsection wherenow Tutorial sections
8
9 - For an introduction to the navigation features of DVDs look in section
10 \ref dvdnavissues . This also provides an overview of the concepts
11 required to understand DVD navigation.
12 - For a step-by step walkthrough of a simple program look in
13 section \ref firstprog .
14 - FIXME: More sections :)
15
16 */
17
18 /*! \page dvdnavissues An introduction to DVD navigation
19
20 The DVD format represents a radical departure from the traditional
21 form of video home-entertainment. Instead of just being a linear
22 programme which is watched from beginning to end like a novel
23 DVD allows the user to jump about at will (much like those
24 'Choose your own adventure' or 'Which Way' books which were
25 popular a while back).
26
27 Such features are usually referred to under the moniker
28 'interactive' by marketing people but you aren't in marketing
29 since you are reading the <tt>libdvdnav</tt> tutorial. We'll
30 assume you actually want to know precisely what DVD can do.
31
32 \subsection layout DVD logical layout
33
34 A DVD is logically structured into titles, chapters (also
35 known as 'parts'), cells and VOBUS, much like the
36 filesystem on your hard disc. The structure is heirachical.
37 A typical DVD might have the following structure:
38
39 \verbatim
40 .
41 |-- Title 1
42 | |-- Chapter 1
43 | | |-- Cell 1
44 | | | |-- VOBU 1
45 | | | |-- ...
46 | | | `-- VOBU n
47 | | |-- ...
48 | | `-- Cell n
49 | |-- ...
50 | `-- Chapter 2
51 | |-- Cell 1
52 | | |-- VOBU 1
53 | | |-- ...
54 | | `-- VOBU n
55 | |-- ...
56 | `-- Cell n
57 |-- ...
58 `-- Title m
59 |-- Chapter 1
60 | |-- Cell 1
61 | | |-- VOBU 1
62 | | |-- ...
63 | | `-- VOBU n
64 | |-- ...
65 | `-- Cell n
66 |-- ...
67 `-- Chapter 2
68 |-- Cell 1
69 | |-- VOBU 1
70 | |-- ...
71 | `-- VOBU n
72 |-- ...
73 `-- Cell n
74 \endverbatim
75
76 A DVD 'Title' is generally a logically distinct section of video. For example the main
77 feature film on a DVD might be Title 1, a behind-the-scenes documentary might be Title 2
78 and a selection of cast interviews might be Title 3. There can be up to 99 Titles on
79 any DVD.
80
81 A DVD 'Chapter' (somewhat confusingly referred to as a 'Part' in the parlence of
82 DVD authors) is generally a logical segment of a Title such as a scene in a film
83 or one interview in a set of cast interviews. There can be up to 999 Parts in
84 one Title.
85
86 A 'Cell' is a small segment of a Part. It is the smallest resolution at which
87 DVD navigation commands can act (e.g. 'Jump to Cell 3 of Part 4 of Title 2').
88 Typically one Part contains one Cell but on complex DVDs it may be useful to have
89 multiple Cells per Part.
90
91 A VOBU (<I>V</I>ideo <I>OB</I>ject <I>U</I>nit) is a small (typically a few
92 seconds) of video. It must be a self contained 'Group of Pictures' which
93 can be understood by the MPEG decoder. All seeking, jumping, etc is guaranteed
94 to occur at a VOBU boundary so that the decoder need not be restarted and that
95 the location jumped to is always the start of a valid MPEG stream. For multiple-angle
96 DVDs VOBUs for each angle can be interleaved into one Interleaved Video Unit (ILVU).
97 In this case when the player get to the end of the VOBU for angle <i>n</i> instead of
98 jumping to the next VOBU the player will move forward to the VOBU for angle <i>n</i>
99 in the next ILVU.
100
101 This is summarised in the following diagram showing how the VOBUs are actually
102 laid out on disc.
103
104 \verbatim
105 ,---------------------------. ,---------------------------.
106 | ILVU 1 | | ILVU m |
107 | ,--------. ,--------. | | ,--------. ,--------. |
108 | | VOBU 1 | ... | VOBU 1 | | ... | | VOBU m | ... | VOBU m | |
109 | |Angle 1 | |Angle n | | | |Angle 1 | |Angle n | |
110 | `--------' `--------' | | `--------' `--------' |
111 `---------------------------' `---------------------------'
112 \endverbatim
113
114 \subsection vm The DVD Virtual Machine
115
116 If the layout of the DVD were the only feature of the format the DVD
117 would only have a limited amount of interactivity, you could jump
118 around between Titles, Parts and Cells but not much else.
119
120 The feature most people associate with DVDs is its ability to
121 present the user with full-motion interactive menus. To provide
122 these features the DVD format includes a specification for a
123 DVD 'virtual machine'.
124
125 To a first order approximation x86 programs can only be run on
126 x86-based machines, PowerPC programs on PowerPC-based machines and so on.
127 Java, however, is an exception in that programs are compiled into
128 a special code which is designed for a 'Java Virtual Machine'.
129 Programmes exist which take this code and convert it into code which
130 can run on real processors.
131
132 Similarly the DVD virtual machine is a hypothetical processor
133 which has commands useful for DVD navigation (e.g. Jump to Title
134 4 or Jump to Cell 2) along with the ability to perform
135 simple arithmetic and save values in a number of special
136 variables (in processor speak, they are known as 'registers').
137
138 When a button is pressed on a DVD menu, a specified machine instruction
139 can be executed (e.g. to jump to a particular Title). Similarly
140 commands can be executed at the beginning and end of Cells and
141 Parts to, for example, return to the menu at the end of a film.
142
143 Return to the \ref tutorial.
144
145 */
146
147 /*! \page firstprog A first libdvdnav program
148
149 \section compiling Compiling a libdvdnav program
150
151 Below is a simple <tt>libdvdnav</tt> program. Type/copy it and save it
152 into the file 'dvdtest.c'.
153
154 \verbatim
155 #include <stdio.h>
156 #include <dvdnav/dvdnav.h>
157 #include <dvdnav/dvdnav_events.h>
158 #include <sys/types.h>
159
160 int main(int argc, char **argv) {
161 dvdnav_t *dvdnav;
162 int finished, len, event;
163 uint8_t buf[2050];
164
165 /* Open the DVD */
166 dvdnav_open(&dvdnav, "/dev/dvd");
167
168 fprintf(stderr, "Reading...\n");
169 finished = 0;
170 while(!finished) {
171 int result = dvdnav_get_next_block(dvdnav, buf,
172 &event, &len);
173
174 if(result == DVDNAV_STATUS_ERR) {
175 fprintf(stderr, "Error getting next block (%s)\n",
176 dvdnav_err_to_string(dvdnav));
177 exit(1);
178 }
179
180 switch(event) {
181 case DVDNAV_BLOCK_OK:
182 /* Write output to stdout */
183 fwrite(buf, len, 1, stdout);
184 break;
185 case DVDNAV_STILL_FRAME:
186 {
187 fprintf(stderr, "Skipping still frame\n");
188 dvdnav_still_skip(dvdnav);
189 }
190 break;
191 case DVDNAV_STOP:
192 {
193 finished = 1;
194 }
195 default:
196 fprintf(stderr, "Unhandled event (%i)\n", event);
197 finished = 1;
198 break;
199 }
200 }
201
202 dvdnav_close(dvdnav);
203
204 return 0;
205 }
206 \endverbatim
207
208 If you have correctly installled <tt>libdvdnav</tt>, you should have the
209 command 'dvdnav-config' in your path. If so you can compile this program
210 with
211 \verbatim
212 gcc -o dvdtest dvdtest.c `dvdnav-config --cflags --libs`
213 \endverbatim
214
215 If all goes well, this should generate the 'dvdtest' program in your current working
216 directory. You can now start saving a MPEG 2 stream directly off your DVD
217 with
218 \verbatim
219 ./dvdtest 2>error.log >out.mpeg
220 \endverbatim
221
222 If the command fails, check the error.log file for details.
223
224 \section walkthrorugh Line-by-line walk through
225
226 \verbatim
227 include <stdio.h>
228 include <dvdnav/dvdnav.h>
229 include <dvdnav/dvdnav_events.h>
230 include <sys/types.h>
231 \endverbatim
232
233 These lines include the necessary headers. Almost all <tt>libdvdnav</tt> programs
234 will only need to include the dvdnav.h and dvdnav_events.h header files from
235 the dvdnav directory.
236
237 \verbatim
238 dvdnav_open(&dvdnav, "/dev/dvd");
239 \endverbatim
240
241 The <tt>libdvdnav</tt> uses <tt>libdvdread</tt> for its DVD I/O. <tt>libdvdread</tt>
242 accesses the DVD-device directly so dvdnav_open() needs to be passed the location
243 of the DVD device. <tt>libdvdread</tt> can also open DVD images/mounted DVDs. Read
244 the <tt>libdvdread</tt> documentation for more information.
245
246 \verbatim
247 int result = dvdnav_get_next_block(dvdnav, buf,
248 &event, &len);
249 \endverbatim
250
251 Return to \ref tutorial.
252
253 */