source: trunk/doc/src/frameworks-technologies/phonon.qdoc@ 846

Last change on this file since 846 was 846, checked in by Dmitry A. Kuminov, 14 years ago

trunk: Merged in qt 4.7.2 sources from branches/vendor/nokia/qt.

  • Property svn:eol-style set to native
File size: 21.0 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4** All rights reserved.
5** Contact: Nokia Corporation ([email protected])
6**
7** This file is part of the documentation of the Qt Toolkit.
8**
9** $QT_BEGIN_LICENSE:FDL$
10** Commercial Usage
11** Licensees holding valid Qt Commercial licenses may use this file in
12** accordance with the Qt Commercial License Agreement provided with the
13** Software or, alternatively, in accordance with the terms contained in a
14** written agreement between you and Nokia.
15**
16** GNU Free Documentation License
17** Alternatively, this file may be used under the terms of the GNU Free
18** Documentation License version 1.3 as published by the Free Software
19** Foundation and appearing in the file included in the packaging of this
20** file.
21**
22** If you have questions regarding the use of this file, please contact
23** Nokia at [email protected].
24** $QT_END_LICENSE$
25**
26****************************************************************************/
27
28/*!
29 \page phonon-overview.html
30 \title Phonon multimedia framework
31 \brief Using the Phonon multimedia framework in Qt.
32 \ingroup technology-apis
33 \ingroup best-practices
34
35 \tableofcontents
36
37 \target Phonon Overview
38 \section1 Introduction
39
40 Qt uses the Phonon multimedia framework to provide functionality
41 for playback of the most common multimedia formats. The media can
42 be read from files or streamed over a network, using a QURL to a
43 file.
44
45 In this overview, we take a look at the main concepts of Phonon.
46 We also explain the architecture, examine the
47 core API classes, and show examples on how to use the classes
48 provided.
49
50 \section1 Architecture
51
52 Phonon has three basic concepts: media objects, sinks, and paths.
53 A media object manages a media source, for instance, a music file;
54 it provides simple playback control, such as starting, stopping,
55 and pausing the playback. A sink outputs the media from Phonon,
56 e.g., by rendering video on a widget, or by sending audio to a
57 sound card. Paths are used to connect Phonon objects, i.e., a
58 media object and a sink, in a graph - called a media graph in
59 Phonon.
60
61 As an example, we show a media graph for an audio stream:
62
63 \image conceptaudio.png
64
65 The playback is started and managed by the media object, which
66 send the media stream to any sinks connected to it by a path. The
67 sink then plays the stream back, usually though a sound card.
68
69 \omit Not sure if this goes here, or anywhere...
70 All nodes in the graph are synchronized by the framework,
71 meaning that if more than one sink is connected to the same
72 media object, the framework will handle the synchronization
73 between the sinks; this happens for instance when a media
74 source containing video with sound is played back. More on
75 this later.
76 \endomit
77
78 \section2 Media Objects
79
80 The media object, an instance of the \l{Phonon::}{MediaObject}
81 class, lets you start, pause, and stop the playback of a media
82 stream, i.e., it provided basic control over the playback. You may
83 think of the object as a simple media player.
84
85 The media data is provided by a media source, which is
86 kept by the media object. The media source is a separate
87 object - an instance of \l{Phonon::}{MediaSource} - in Phonon, and
88 not part of the graph itself. The source will supply the media
89 object with raw data. The data can be read from files and streamed
90 over a network. The contents of the source will be interpreted by
91 the media object.
92
93 A media object is always instantiated with the default constructor
94 and then supplied with a media source. Concrete code examples are
95 given later in this overview.
96
97 As a complement to the media object, Phonon also provides
98 \l{Phonon::}{MediaController}, which provides control over
99 features that are optional for a given media. For instance, for
100 chapters, menus, and titles of a VOB (DVD) file will be features
101 managed by a \l{Phonon::}{MediaController}.
102
103 \section2 Sinks
104
105 A sink is a node that can output media from the graph, i.e., it
106 does not send its output to other nodes. A sink is usually a
107 rendering device.
108
109 The input of sinks in a Phonon media graph comes from a
110 \l{Phonon::}{MediaObject}, though it might have been processed
111 through other nodes on the way.
112
113 While the \l{Phonon::}{MediaObject} controls the playback, the
114 sink has basic controls for manipulation of the media. With an
115 audio sink, for instance, you can control the volume and mute the
116 sound, i.e., it represents a virtual audio device. Another example
117 is the \l{Phonon::}{VideoWidget}, which can render video on a
118 QWidget and alter the brightness, hue, and scaling of the video.
119
120 As an example we give an image of a graph used for playing back a
121 video file with sound.
122
123 \image conceptvideo.png
124
125 \section2 Processors
126
127 Phonon does not allow manipulation of media streams directly,
128 i.e., one cannot alter a media stream's bytes programmatically
129 after they have been given to a media object. We have other nodes
130 to help with this: processors, which are placed in the graph on
131 the path somewhere between the media object and its sinks. In
132 Phonon, processors are of the \l{Phonon::}{Effect} class.
133
134 When inserted into the rendering process, the processor will
135 alter the media stream, and will be active as long as it is part
136 of the graph. To stop, it needs to be removed.
137
138 \omit \image conceptprocessor.png \endomit
139
140 The \c {Effect}s may also have controls that affect how the media
141 stream is manipulated. A processor applying a depth effect to
142 audio, for instance, can have a value controlling the amount of
143 depth. An \c Effect can be configured at any point in time.
144
145 \section1 Playback
146
147 In some common cases, it is not necessary to build a graph
148 yourself.
149
150 Phonon has convenience functions for building common graphs. For
151 playing an audio file, you can use the
152 \l{Phonon::}{createPlayer()} function. This will set up the
153 necessary graph and return the media object node; the sound can
154 then be started by calling its \l{Phonon::MediaObject::}{play()}
155 function.
156
157 \snippet snippets/phonon.cpp 0
158
159 We have a similar solution for playing video files, the
160 \l{Phonon::}{VideoPlayer}.
161
162 \snippet snippets/phonon.cpp 1
163
164 The VideoPlayer is a widget onto which the video will be drawn.
165
166 The \c .pro file for a project needs the following line to be added:
167
168 \snippet doc/src/snippets/code/doc_src_phonon.qdoc 0
169
170 Phonon comes with several widgets that provide functionality
171 commonly associated with multimedia players - notably SeekSlider
172 for controlling the position of the stream, VolumeSlider for
173 controlling sound volume, and EffectWidget for controlling the
174 parameters of an effect. You can learn about them in the API
175 documentation.
176
177 \section1 Building Graphs
178
179 If you need more freedom than the convenience functions described
180 in the previous section offers you, you can build the graphs
181 yourself. We will now take a look at how some common graphs are
182 built. Starting a graph up is a matter of calling the
183 \l{Phonon::MediaObject::}{play()} function of the media object.
184
185 If the media source contains several types of media, for instance, a
186 stream with both video and audio, the graph will contain two
187 output nodes: one for the video and one for the audio.
188
189 We will now look at the code required to build the graphs discussed
190 previously in the \l{Architecture} section.
191
192 \section2 Audio
193
194 When playing back audio, you create the media object and connect
195 it to an audio output node - a node that inherits from
196 AbstractAudioOutput. Currently, AudioOutput, which outputs audio
197 to the sound card, is provided.
198
199 The code to create the graph is straight forward:
200
201 \snippet snippets/phonon.cpp 2
202
203 Notice that the type of media an input source has is resolved by
204 Phonon, so you need not be concerned with this. If a source
205 contains multiple media formats, this is also handled
206 automatically.
207
208 The media object is always created using the default constructor
209 since it handles all multimedia formats.
210
211 The setting of a Category, Phonon::MusicCategory in this case,
212 does not affect the actual playback; the category can be used by
213 KDE to control the playback through, for instance, the control
214 panel.
215
216 \omit Not sure about this
217 Users of KDE can often also choose to send sound with the
218 CommunicationCategory, e.g., given to VoIP, to their headset,
219 while sound with MusicCategory is sent to the sound card.
220 \endomit
221
222 The AudioOutput class outputs the audio media to a sound card,
223 that is, one of the audio devices of the operating system. An
224 audio device can be a sound card or a intermediate technology,
225 such as \c DirectShow on windows. A default device will be chosen
226 if one is not set with \l{Phonon::AudioOutput::}{setOutputDevice()}.
227
228 The AudioOutput node will work with all audio formats supported by
229 the back end, so you don't need to know what format a specific
230 media source has.
231
232 For a an extensive example of audio playback, see the \l{Music
233 Player Example}{Phonon Music Player}.
234
235 \section3 Audio Effects
236
237 Since a media stream cannot be manipulated directly, the backend
238 can produce nodes that can process the media streams. These nodes
239 are inserted into the graph between a media object and an output
240 node.
241
242 Nodes that process media streams inherit from the Effect class.
243 The effects available depends on the underlying system. Most of
244 these effects will be supported by Phonon. See the \l{Querying
245 Backends for Support} section for information on how to resolve
246 the available effects on a particular system.
247
248 We will now continue the example from above using the Path
249 variable \c path to add an effect. The code is again trivial:
250
251 \snippet snippets/phonon.cpp 3
252
253 Here we simply take the first available effect on the system.
254
255 The effect will start immediately after being inserted into the
256 graph if the media object is playing. To stop it, you have to
257 detach it again using \l{Phonon::Path::}{removeEffect()} of the Path.
258
259 \section2 Video
260
261 For playing video, VideoWidget is provided. This class functions
262 both as a node in the graph and as a widget upon which it draws
263 the video stream. The widget will automatically choose an available
264 device for playing the video, which is usually a technology
265 between the Qt application and the graphics card, such as \c
266 DirectShow on Windows.
267
268 The video widget does not play the audio (if any) in the media
269 stream. If you want to play the audio as well, you will need
270 an AudioOutput node. You create and connect it to the graph as
271 shown in the previous section.
272
273 The code for creating this graph is given below, after which
274 one can play the video with \l{Phonon::MediaObject::}{play()}.
275
276 \snippet snippets/phonon.cpp 4
277
278 The VideoWidget does not need to be set to a Category, it is
279 automatically classified to \l{Phonon::}{VideoCategory}, we only
280 need to assure that the audio is also classified in the same
281 category.
282
283 The media object will split files with different media content
284 into separate streams before sending them off to other nodes in
285 the graph. It is the media object that determines the type of
286 content appropriate for nodes that connect to it.
287
288 \omit This section is from the future
289
290 \section2 Multiple Audio Sources and Graph Outputs
291
292 In this section, we take a look at a graph that contains multiple
293 audio sources in addition to video. We have a video camera with
294 some embarrassing home footage from last weekend's party, a
295 microphone with which we intend to add commentary, and an audio
296 music file to set the correct mood. It would be an advantage to
297 write the graph output to a file for later viewing, but since this
298 is not yet supported by Qt backends, we will play it back
299 directly.
300
301 <image of party graph>
302
303 <code>
304
305 <code walkthrough>
306
307 \endomit
308
309 \section1 Backends
310
311 The multimedia functionality is not implemented by Phonon itself,
312 but by a back end - often also referred to as an engine. This
313 includes connecting to, managing, and driving the underlying
314 hardware or intermediate technology. For the programmer, this
315 implies that the media nodes, e.g., media objects, processors, and
316 sinks, are produced by the back end. Also, it is responsible for
317 building the graph, i.e., connecting the nodes.
318
319 The backends of Qt use the media systems DirectShow (which
320 requires DirectX) on Windows, QuickTime on Mac, and GStreamer on
321 Linux. The functionality provided on the different platforms are
322 dependent on these underlying systems and may vary somewhat, e.g.,
323 in the media formats supported.
324
325 Backends expose information about the underlying system. It can
326 tell which media formats are supported, e.g., \c AVI, \c mp3, or
327 \c OGG.
328
329 A user can often add support for new formats and filters to the
330 underlying system, by, for instance, installing the DivX codex. We
331 can therefore not give an exact overview of which formats are
332 available with the Qt backends.
333
334 \omit Not sure I want a separate section for this
335 \section2 Communication with the Backends
336
337 We cooperate with backends through static functions in the
338 Phonon namespace. We have already seen some of these functions
339 in code examples. Their two main responsibilities are creating
340 graph nodes and supplying information about the capabilities
341 of the various nodes. The nodes uses the backend internally
342 when created, so it is only connecting them in the graph that
343 you need to use the backend directly.
344
345 The main functions for graph building are:
346
347 \list
348 \o createPath(): This function creates a path between to
349 nodes, which it takes as arguments.
350 \o
351 \endlist
352
353 For more detailed information, please consult the API
354 documentation.
355
356 \endomit
357
358 \section2 Querying Backends for Support
359
360 As mentioned, Phonon depends on the backend to provide its
361 functionality. Depending on the individual backend, full support
362 of the API may not be in place. Applications therefore need to
363 check with the backend if functionality they require is
364 implemented. In this section, we take look at how this is done.
365
366 The backend provides the
367 \l{Phonon::BackendCapabilities::}{availableMimeTypes()} and
368 \l{Phonon::BackendCapabilities::}{isMimeTypeAvailable()} functions
369 to query which MIME types the backend can produce nodes for. The
370 types are listed as strings, which for any type is equal for any
371 backend or platform.
372
373 The backend will emit a signal -
374 \l{Phonon::BackendCapabilities::}{Notifier::capabilitiesChanged()}
375 - if its abilities have changed. If the available audio devices
376 have changed, the
377 \l{Phonon::BackendCapabilities::}{Notifier::availableAudioOutputDevicesChanged()}
378 signal is emitted instead.
379
380 To query the actual audio devices possible, we have the
381 \l{Phonon::BackendCapabilities::}{availableAudioOutputDevices()} as
382 mentioned in the \l{#Sinks}{Sinks} section. To query information
383 about the individual devices, you can examine its \c name(); this
384 string is dependent on the operating system, and the Qt backends
385 does not analyze the devices further.
386
387 The sink for playback of video does not have a selection of
388 devices. For convenience, the \l{Phonon::}{VideoWidget} is both a
389 node in the graph and a widget on which the video output is
390 rendered. To query the various video formats available, use
391 \l{Phonon::BackendCapabilities::}{isMimeTypeAvailable()}. To add
392 it to a path, you can use the Phonon::createPath() as usual. After
393 creating a media object, it is also possible to call its
394 \l{Phonon::MediaObject::}{hasVideo()} function.
395
396 See also the \l{Capabilities Example}.
397
398 \section1 Installing Phonon
399
400 When running the Qt configure script, you will be notified whether
401 Phonon support is available on your system. As mentioned
402 previously, to use develop and run Phonon applications, you also
403 need to link to a backend, which provides the multimedia
404 functionality.
405
406 Note that Phonon applications will compile and run without a
407 working backend, but will, of course, not work as expected.
408
409 The following sections explains requirements for each backend.
410
411 \section2 Windows
412
413 On Windows, building Phonon requires DirectX and DirectShow
414 version 9 or higher. You'll need additional SDKs you can download
415 from Microsoft.
416
417 \section3 Windows XP and later Windows versions
418
419 If you develop for Windows XP and up, you should download the Windows SDK
420 \l{http://www.microsoft.com/downloads/details.aspx?FamilyID=e6e1c3df-a74f-4207-8586-711ebe331cdc&amp;DisplayLang=en}{here}.
421 Before building Qt, just call the script: \c {C:\Program Files\Microsoft SDKs\Windows\v6.1\Bin\setenv.cmd}
422
423 \note Visual C++ 2008 already contains the Windows SDK and doesn't
424 need that package and has already the environment set up for a
425 smooth compilation of phonon.
426
427 \section3 Earlier Windows versions than Windows XP
428
429 If you want to support previous Windows versions, you should download and install the Platform SDK. You find it
430 \l{http://www.microsoft.com/downloads/details.aspx?FamilyId=0BAF2B35-C656-4969-ACE8-E4C0C0716ADB&amp;displaylang=en}{here}.
431
432 \note The platform SDK provided with Visual C++ is not
433 complete and
434 you'll need this one to have DirectShow 9.0 support. You can download the DirectX SDK
435 \l{http://www.microsoft.com/downloads/details.aspx?familyid=09F7578C-24AA-4E0A-BF91-5FEC24C8C7BF&amp;displaylang=en}{here}.
436
437 \section3 Setting up the environment
438
439 Once the SDKs are installed, please make sure to set your
440 environment variables LIB and INCLUDE correctly. The paths to the
441 include and lib directory of the SDKs should appear first.
442 Typically, to setup your environment, you would execute the
443 following script:
444
445 \code
446 Set DXSDK_DIR=C:\Program Files\Microsoft DirectX SDK (February 2007)
447 %DXSDK_DIR%\utilities\bin\dx_setenv.cmd
448 C:\program files\Microsoft Platform SDK\setenv.cmd
449 \endcode
450
451 If your environment is setup correctly, executing configure.exe on
452 your Qt installation should automatically activate Phonon.
453
454 \warning The MinGW version of Qt does not support building the
455 Qt backend.
456
457 \section2 Linux
458
459 The Qt backend on Linux uses GStreamer (minimum version is 0.10),
460 which must be installed on the system. At a minimum, you need the
461 GStreamer library and base plugins, which provides support for \c
462 .ogg files. The package names may vary between Linux
463 distributions; on Mandriva, they have the following names:
464
465 \table
466 \header
467 \o Package
468 \o Description
469 \row
470 \o libgstreamer0.10_0.10
471 \o The GStreamer base library.
472 \row
473 \o libgstreamer0.10_0.10-devel
474 \o Contains files for developing applications with
475 GStreamer.
476 \row
477 \o libgstreamer-plugins-base0.10
478 \o Contains the basic plugins for audio and video
479 playback, and will enable support for \c ogg files.
480 \row
481 \o libgstreamer-plugins-base0.10-devel
482 \o Makes it possible to develop applications using the
483 base plugins.
484 \endtable
485
486 \omit Should go in troubleshooting (in for example README)
487 alsasink backend for GStreamer
488 \table
489 \header
490 \o Variable
491 \o Description
492 \row
493 \o PHONON_GST_AUDIOSINK
494 \o Sets the audio sink to be used. Possible values are
495 ... alsasink.
496 \row
497 \o PHONON_GSTREAMER_DRIVER
498 \o Sets the driver for GStreamer. This driver will
499 usually be configured automatically when
500 installing.
501 \row
502 \o PHONON_GST_VIDEOWIDGET
503 \o This variable can be set to the name of a widget to
504 use as the video widget??
505 \row
506 \o PHONON_GST_DEBUG
507 \o Phonon will give debug information while running if
508 this variable is set to a number between 1 and 3.
509 \row
510 \o PHONON_TESTURL
511 \o ...
512 \endtable
513 \endomit
514
515 \section2 Mac OS X
516
517 On Mac OS X, Qt uses QuickTime for its backend. The minimum
518 supported version is 7.0.
519
520 \section1 Deploying Phonon Applications on Windows and Mac OS X
521
522 On Windows and Mac OS X, the Qt backend makes use of the
523 \l{QtOpenGL Module}{QtOpenGL} module. You therefore need to deploy
524 the QtOpenGL shared library. If this is not what you want, it is
525 possible to configure Qt without OpenGL support. In that case, you
526 need to run \c configure with the \c -no-opengl option.
527*/
528
Note: See TracBrowser for help on using the repository browser.