From e85223d233c0e1d6beca748332b8fbaba3ebbf2d Mon Sep 17 00:00:00 2001 From: Justin McPherson Date: Thu, 15 Apr 2010 19:08:00 +1000 Subject: Create Mediaservices lib, separate from Multimedia. --- bin/syncqt | 3 +- configure | 55 +- demos/multimedia/player/player.cpp | 12 +- demos/multimedia/player/player.pro | 2 +- demos/multimedia/player/playercontrols.h | 2 +- demos/multimedia/player/videowidget.h | 2 +- mkspecs/features/qt.prf | 3 +- src/3rdparty/webkit/WebCore/WebCore.pro | 4 +- src/imports/multimedia/multimedia.cpp | 2 +- src/imports/multimedia/multimedia.pro | 2 +- src/imports/multimedia/qdeclarativeaudio.cpp | 2 +- src/imports/multimedia/qdeclarativemediabase.cpp | 8 +- src/imports/multimedia/qdeclarativemediabase_p.h | 2 +- src/imports/multimedia/qdeclarativevideo.cpp | 152 +- src/imports/multimedia/qdeclarativevideo_p.h | 2 +- .../multimedia/qmetadatacontrolmetaobject.cpp | 152 +- .../multimedia/qmetadatacontrolmetaobject_p.h | 2 +- src/multimedia/audio/audio.pri | 73 - src/multimedia/audio/qaudio.cpp | 104 -- src/multimedia/audio/qaudio.h | 71 - src/multimedia/audio/qaudio_mac.cpp | 142 -- src/multimedia/audio/qaudio_mac_p.h | 144 -- src/multimedia/audio/qaudio_symbian_p.cpp | 395 ----- src/multimedia/audio/qaudio_symbian_p.h | 156 -- src/multimedia/audio/qaudiodevicefactory.cpp | 257 ---- src/multimedia/audio/qaudiodevicefactory_p.h | 97 -- src/multimedia/audio/qaudiodeviceinfo.cpp | 400 ----- src/multimedia/audio/qaudiodeviceinfo.h | 114 -- src/multimedia/audio/qaudiodeviceinfo_alsa_p.cpp | 486 ------ src/multimedia/audio/qaudiodeviceinfo_alsa_p.h | 117 -- src/multimedia/audio/qaudiodeviceinfo_mac_p.cpp | 357 ----- src/multimedia/audio/qaudiodeviceinfo_mac_p.h | 97 -- .../audio/qaudiodeviceinfo_symbian_p.cpp | 200 --- src/multimedia/audio/qaudiodeviceinfo_symbian_p.h | 107 -- src/multimedia/audio/qaudiodeviceinfo_win32_p.cpp | 433 ------ src/multimedia/audio/qaudiodeviceinfo_win32_p.h | 112 -- src/multimedia/audio/qaudioengine.cpp | 343 ----- src/multimedia/audio/qaudioengine.h | 131 -- src/multimedia/audio/qaudioengineplugin.cpp | 54 - src/multimedia/audio/qaudioengineplugin.h | 93 -- src/multimedia/audio/qaudioformat.cpp | 407 ----- src/multimedia/audio/qaudioformat.h | 107 -- src/multimedia/audio/qaudioinput.cpp | 432 ------ src/multimedia/audio/qaudioinput.h | 111 -- src/multimedia/audio/qaudioinput_alsa_p.cpp | 706 --------- src/multimedia/audio/qaudioinput_alsa_p.h | 158 -- src/multimedia/audio/qaudioinput_mac_p.cpp | 956 ------------ src/multimedia/audio/qaudioinput_mac_p.h | 169 --- src/multimedia/audio/qaudioinput_symbian_p.cpp | 594 -------- src/multimedia/audio/qaudioinput_symbian_p.h | 188 --- src/multimedia/audio/qaudioinput_win32_p.cpp | 613 -------- src/multimedia/audio/qaudioinput_win32_p.h | 159 -- src/multimedia/audio/qaudiooutput.cpp | 411 ----- src/multimedia/audio/qaudiooutput.h | 111 -- src/multimedia/audio/qaudiooutput_alsa_p.cpp | 780 ---------- src/multimedia/audio/qaudiooutput_alsa_p.h | 166 --- src/multimedia/audio/qaudiooutput_mac_p.cpp | 712 --------- src/multimedia/audio/qaudiooutput_mac_p.h | 167 --- src/multimedia/audio/qaudiooutput_symbian_p.cpp | 697 --------- src/multimedia/audio/qaudiooutput_symbian_p.h | 210 --- src/multimedia/audio/qaudiooutput_win32_p.cpp | 606 -------- src/multimedia/audio/qaudiooutput_win32_p.h | 156 -- src/multimedia/base/base.pri | 69 - src/multimedia/base/qgraphicsvideoitem.cpp | 437 ------ src/multimedia/base/qgraphicsvideoitem.h | 112 -- .../base/qlocalmediaplaylistprovider.cpp | 196 --- src/multimedia/base/qlocalmediaplaylistprovider.h | 87 -- src/multimedia/base/qmediacontent.cpp | 242 --- src/multimedia/base/qmediacontent.h | 93 -- src/multimedia/base/qmediacontrol.cpp | 140 -- src/multimedia/base/qmediacontrol.h | 82 - src/multimedia/base/qmediacontrol_p.h | 74 - src/multimedia/base/qmediaobject.cpp | 419 ------ src/multimedia/base/qmediaobject.h | 121 -- src/multimedia/base/qmediaobject_p.h | 95 -- src/multimedia/base/qmediaplaylist.cpp | 724 --------- src/multimedia/base/qmediaplaylist.h | 147 -- src/multimedia/base/qmediaplaylist_p.h | 172 --- src/multimedia/base/qmediaplaylistcontrol.cpp | 204 --- src/multimedia/base/qmediaplaylistcontrol.h | 97 -- src/multimedia/base/qmediaplaylistioplugin.cpp | 192 --- src/multimedia/base/qmediaplaylistioplugin.h | 126 -- src/multimedia/base/qmediaplaylistnavigator.cpp | 545 ------- src/multimedia/base/qmediaplaylistnavigator.h | 116 -- src/multimedia/base/qmediaplaylistprovider.cpp | 308 ---- src/multimedia/base/qmediaplaylistprovider.h | 114 -- src/multimedia/base/qmediaplaylistprovider_p.h | 75 - src/multimedia/base/qmediapluginloader.cpp | 135 -- src/multimedia/base/qmediapluginloader_p.h | 92 -- src/multimedia/base/qmediaresource.cpp | 399 ----- src/multimedia/base/qmediaresource.h | 134 -- src/multimedia/base/qmediaservice.cpp | 140 -- src/multimedia/base/qmediaservice.h | 90 -- src/multimedia/base/qmediaservice_p.h | 75 - src/multimedia/base/qmediaserviceprovider.cpp | 738 --------- src/multimedia/base/qmediaserviceprovider.h | 174 --- src/multimedia/base/qmediaserviceproviderplugin.h | 125 -- src/multimedia/base/qmediatimerange.cpp | 708 --------- src/multimedia/base/qmediatimerange.h | 135 -- src/multimedia/base/qmetadatacontrol.cpp | 185 --- src/multimedia/base/qmetadatacontrol.h | 92 -- src/multimedia/base/qpaintervideosurface.cpp | 1565 -------------------- src/multimedia/base/qpaintervideosurface_mac.mm | 283 ---- src/multimedia/base/qpaintervideosurface_mac_p.h | 100 -- src/multimedia/base/qpaintervideosurface_p.h | 178 --- src/multimedia/base/qtmedianamespace.h | 194 --- src/multimedia/base/qtmedianamespace.qdoc | 214 --- src/multimedia/base/qvideodevicecontrol.cpp | 155 -- src/multimedia/base/qvideodevicecontrol.h | 90 -- src/multimedia/base/qvideooutputcontrol.cpp | 135 -- src/multimedia/base/qvideooutputcontrol.h | 91 -- src/multimedia/base/qvideorenderercontrol.cpp | 124 -- src/multimedia/base/qvideorenderercontrol.h | 77 - src/multimedia/base/qvideowidget.cpp | 944 ------------ src/multimedia/base/qvideowidget.h | 131 -- src/multimedia/base/qvideowidget_p.h | 271 ---- src/multimedia/base/qvideowidgetcontrol.cpp | 235 --- src/multimedia/base/qvideowidgetcontrol.h | 105 -- src/multimedia/base/qvideowindowcontrol.cpp | 275 ---- src/multimedia/base/qvideowindowcontrol.h | 111 -- src/multimedia/effects/effects.pri | 26 - src/multimedia/effects/qsoundeffect.cpp | 207 --- src/multimedia/effects/qsoundeffect_p.h | 109 -- src/multimedia/effects/qsoundeffect_pulse_p.cpp | 499 ------- src/multimedia/effects/qsoundeffect_pulse_p.h | 137 -- src/multimedia/effects/qsoundeffect_qmedia_p.cpp | 132 -- src/multimedia/effects/qsoundeffect_qmedia_p.h | 103 -- src/multimedia/effects/qsoundeffect_qsound_p.cpp | 131 -- src/multimedia/effects/qsoundeffect_qsound_p.h | 102 -- src/multimedia/effects/wavedecoder_p.cpp | 151 -- src/multimedia/effects/wavedecoder_p.h | 133 -- src/multimedia/mediaservices/base/base.pri | 69 + .../mediaservices/base/qgraphicsvideoitem.cpp | 437 ++++++ .../mediaservices/base/qgraphicsvideoitem.h | 112 ++ .../base/qlocalmediaplaylistprovider.cpp | 196 +++ .../base/qlocalmediaplaylistprovider.h | 87 ++ .../mediaservices/base/qmediacontent.cpp | 242 +++ src/multimedia/mediaservices/base/qmediacontent.h | 93 ++ .../mediaservices/base/qmediacontrol.cpp | 140 ++ src/multimedia/mediaservices/base/qmediacontrol.h | 82 + .../mediaservices/base/qmediacontrol_p.h | 74 + src/multimedia/mediaservices/base/qmediaobject.cpp | 419 ++++++ src/multimedia/mediaservices/base/qmediaobject.h | 121 ++ src/multimedia/mediaservices/base/qmediaobject_p.h | 95 ++ .../mediaservices/base/qmediaplaylist.cpp | 724 +++++++++ src/multimedia/mediaservices/base/qmediaplaylist.h | 147 ++ .../mediaservices/base/qmediaplaylist_p.h | 172 +++ .../mediaservices/base/qmediaplaylistcontrol.cpp | 204 +++ .../mediaservices/base/qmediaplaylistcontrol.h | 97 ++ .../mediaservices/base/qmediaplaylistioplugin.cpp | 192 +++ .../mediaservices/base/qmediaplaylistioplugin.h | 126 ++ .../mediaservices/base/qmediaplaylistnavigator.cpp | 545 +++++++ .../mediaservices/base/qmediaplaylistnavigator.h | 116 ++ .../mediaservices/base/qmediaplaylistprovider.cpp | 308 ++++ .../mediaservices/base/qmediaplaylistprovider.h | 114 ++ .../mediaservices/base/qmediaplaylistprovider_p.h | 75 + .../mediaservices/base/qmediapluginloader.cpp | 135 ++ .../mediaservices/base/qmediapluginloader_p.h | 92 ++ .../mediaservices/base/qmediaresource.cpp | 399 +++++ src/multimedia/mediaservices/base/qmediaresource.h | 134 ++ .../mediaservices/base/qmediaservice.cpp | 140 ++ src/multimedia/mediaservices/base/qmediaservice.h | 90 ++ .../mediaservices/base/qmediaservice_p.h | 75 + .../mediaservices/base/qmediaserviceprovider.cpp | 738 +++++++++ .../mediaservices/base/qmediaserviceprovider.h | 174 +++ .../base/qmediaserviceproviderplugin.h | 125 ++ .../mediaservices/base/qmediatimerange.cpp | 708 +++++++++ .../mediaservices/base/qmediatimerange.h | 135 ++ .../mediaservices/base/qmetadatacontrol.cpp | 185 +++ .../mediaservices/base/qmetadatacontrol.h | 92 ++ .../mediaservices/base/qpaintervideosurface.cpp | 1565 ++++++++++++++++++++ .../mediaservices/base/qpaintervideosurface_mac.mm | 283 ++++ .../base/qpaintervideosurface_mac_p.h | 100 ++ .../mediaservices/base/qpaintervideosurface_p.h | 178 +++ .../mediaservices/base/qtmedianamespace.h | 194 +++ .../mediaservices/base/qtmedianamespace.qdoc | 214 +++ .../mediaservices/base/qvideodevicecontrol.cpp | 155 ++ .../mediaservices/base/qvideodevicecontrol.h | 90 ++ .../mediaservices/base/qvideooutputcontrol.cpp | 135 ++ .../mediaservices/base/qvideooutputcontrol.h | 91 ++ .../mediaservices/base/qvideorenderercontrol.cpp | 124 ++ .../mediaservices/base/qvideorenderercontrol.h | 77 + src/multimedia/mediaservices/base/qvideowidget.cpp | 944 ++++++++++++ src/multimedia/mediaservices/base/qvideowidget.h | 131 ++ src/multimedia/mediaservices/base/qvideowidget_p.h | 271 ++++ .../mediaservices/base/qvideowidgetcontrol.cpp | 235 +++ .../mediaservices/base/qvideowidgetcontrol.h | 105 ++ .../mediaservices/base/qvideowindowcontrol.cpp | 275 ++++ .../mediaservices/base/qvideowindowcontrol.h | 111 ++ src/multimedia/mediaservices/effects/effects.pri | 26 + .../mediaservices/effects/qsoundeffect.cpp | 207 +++ .../mediaservices/effects/qsoundeffect_p.h | 109 ++ .../mediaservices/effects/qsoundeffect_pulse_p.cpp | 499 +++++++ .../mediaservices/effects/qsoundeffect_pulse_p.h | 137 ++ .../effects/qsoundeffect_qmedia_p.cpp | 132 ++ .../mediaservices/effects/qsoundeffect_qmedia_p.h | 103 ++ .../effects/qsoundeffect_qsound_p.cpp | 131 ++ .../mediaservices/effects/qsoundeffect_qsound_p.h | 102 ++ .../mediaservices/effects/wavedecoder_p.cpp | 151 ++ .../mediaservices/effects/wavedecoder_p.h | 133 ++ src/multimedia/mediaservices/mediaservices.pro | 16 + src/multimedia/mediaservices/playback/playback.pri | 11 + .../mediaservices/playback/qmediaplayer.cpp | 982 ++++++++++++ .../mediaservices/playback/qmediaplayer.h | 203 +++ .../mediaservices/playback/qmediaplayercontrol.cpp | 378 +++++ .../mediaservices/playback/qmediaplayercontrol.h | 131 ++ src/multimedia/multimedia.pro | 19 +- src/multimedia/multimedia/audio/audio.pri | 73 + src/multimedia/multimedia/audio/qaudio.cpp | 104 ++ src/multimedia/multimedia/audio/qaudio.h | 71 + src/multimedia/multimedia/audio/qaudio_mac.cpp | 142 ++ src/multimedia/multimedia/audio/qaudio_mac_p.h | 144 ++ .../multimedia/audio/qaudio_symbian_p.cpp | 395 +++++ src/multimedia/multimedia/audio/qaudio_symbian_p.h | 156 ++ .../multimedia/audio/qaudiodevicefactory.cpp | 257 ++++ .../multimedia/audio/qaudiodevicefactory_p.h | 97 ++ .../multimedia/audio/qaudiodeviceinfo.cpp | 400 +++++ src/multimedia/multimedia/audio/qaudiodeviceinfo.h | 114 ++ .../multimedia/audio/qaudiodeviceinfo_alsa_p.cpp | 486 ++++++ .../multimedia/audio/qaudiodeviceinfo_alsa_p.h | 117 ++ .../multimedia/audio/qaudiodeviceinfo_mac_p.cpp | 357 +++++ .../multimedia/audio/qaudiodeviceinfo_mac_p.h | 97 ++ .../audio/qaudiodeviceinfo_symbian_p.cpp | 200 +++ .../multimedia/audio/qaudiodeviceinfo_symbian_p.h | 107 ++ .../multimedia/audio/qaudiodeviceinfo_win32_p.cpp | 433 ++++++ .../multimedia/audio/qaudiodeviceinfo_win32_p.h | 112 ++ src/multimedia/multimedia/audio/qaudioengine.cpp | 343 +++++ src/multimedia/multimedia/audio/qaudioengine.h | 131 ++ .../multimedia/audio/qaudioengineplugin.cpp | 54 + .../multimedia/audio/qaudioengineplugin.h | 93 ++ src/multimedia/multimedia/audio/qaudioformat.cpp | 407 +++++ src/multimedia/multimedia/audio/qaudioformat.h | 107 ++ src/multimedia/multimedia/audio/qaudioinput.cpp | 432 ++++++ src/multimedia/multimedia/audio/qaudioinput.h | 111 ++ .../multimedia/audio/qaudioinput_alsa_p.cpp | 706 +++++++++ .../multimedia/audio/qaudioinput_alsa_p.h | 158 ++ .../multimedia/audio/qaudioinput_mac_p.cpp | 956 ++++++++++++ .../multimedia/audio/qaudioinput_mac_p.h | 169 +++ .../multimedia/audio/qaudioinput_symbian_p.cpp | 594 ++++++++ .../multimedia/audio/qaudioinput_symbian_p.h | 188 +++ .../multimedia/audio/qaudioinput_win32_p.cpp | 613 ++++++++ .../multimedia/audio/qaudioinput_win32_p.h | 159 ++ src/multimedia/multimedia/audio/qaudiooutput.cpp | 411 +++++ src/multimedia/multimedia/audio/qaudiooutput.h | 111 ++ .../multimedia/audio/qaudiooutput_alsa_p.cpp | 780 ++++++++++ .../multimedia/audio/qaudiooutput_alsa_p.h | 166 +++ .../multimedia/audio/qaudiooutput_mac_p.cpp | 712 +++++++++ .../multimedia/audio/qaudiooutput_mac_p.h | 167 +++ .../multimedia/audio/qaudiooutput_symbian_p.cpp | 697 +++++++++ .../multimedia/audio/qaudiooutput_symbian_p.h | 210 +++ .../multimedia/audio/qaudiooutput_win32_p.cpp | 606 ++++++++ .../multimedia/audio/qaudiooutput_win32_p.h | 156 ++ src/multimedia/multimedia/multimedia.pro | 14 + .../multimedia/video/qabstractvideobuffer.cpp | 200 +++ .../multimedia/video/qabstractvideobuffer.h | 106 ++ .../multimedia/video/qabstractvideobuffer_p.h | 73 + .../multimedia/video/qabstractvideosurface.cpp | 283 ++++ .../multimedia/video/qabstractvideosurface.h | 110 ++ .../multimedia/video/qabstractvideosurface_p.h | 78 + .../multimedia/video/qimagevideobuffer.cpp | 106 ++ .../multimedia/video/qimagevideobuffer_p.h | 79 + .../multimedia/video/qmemoryvideobuffer.cpp | 129 ++ .../multimedia/video/qmemoryvideobuffer_p.h | 83 ++ src/multimedia/multimedia/video/qvideoframe.cpp | 741 +++++++++ src/multimedia/multimedia/video/qvideoframe.h | 169 +++ .../multimedia/video/qvideosurfaceformat.cpp | 704 +++++++++ .../multimedia/video/qvideosurfaceformat.h | 147 ++ src/multimedia/multimedia/video/video.pri | 21 + src/multimedia/playback/playback.pri | 11 - src/multimedia/playback/qmediaplayer.cpp | 982 ------------ src/multimedia/playback/qmediaplayer.h | 203 --- src/multimedia/playback/qmediaplayercontrol.cpp | 378 ----- src/multimedia/playback/qmediaplayercontrol.h | 131 -- src/multimedia/video/qabstractvideobuffer.cpp | 200 --- src/multimedia/video/qabstractvideobuffer.h | 106 -- src/multimedia/video/qabstractvideobuffer_p.h | 73 - src/multimedia/video/qabstractvideosurface.cpp | 283 ---- src/multimedia/video/qabstractvideosurface.h | 110 -- src/multimedia/video/qabstractvideosurface_p.h | 78 - src/multimedia/video/qimagevideobuffer.cpp | 106 -- src/multimedia/video/qimagevideobuffer_p.h | 79 - src/multimedia/video/qmemoryvideobuffer.cpp | 129 -- src/multimedia/video/qmemoryvideobuffer_p.h | 83 -- src/multimedia/video/qvideoframe.cpp | 741 --------- src/multimedia/video/qvideoframe.h | 169 --- src/multimedia/video/qvideosurfaceformat.cpp | 704 --------- src/multimedia/video/qvideosurfaceformat.h | 147 -- src/multimedia/video/video.pri | 21 - .../mediaservices/directshow/directshow.pro | 4 +- .../mediaplayer/directshowaudioendpointcontrol.h | 2 +- .../mediaplayer/directshowmetadatacontrol.cpp | 116 +- .../mediaplayer/directshowmetadatacontrol.h | 8 +- .../directshow/mediaplayer/directshowpinenum.cpp | 2 +- .../mediaplayer/directshowplayercontrol.h | 4 +- .../mediaplayer/directshowplayerservice.cpp | 2 +- .../mediaplayer/directshowplayerservice.h | 8 +- .../mediaplayer/directshowvideooutputcontrol.h | 2 +- .../mediaplayer/directshowvideorenderercontrol.h | 2 +- .../mediaplayer/mediasamplevideobuffer.h | 2 +- .../mediaplayer/vmr9videowindowcontrol.h | 2 +- src/plugins/mediaservices/gstreamer/gstreamer.pro | 4 +- .../mediaplayer/qgstreamermetadataprovider.cpp | 108 +- .../mediaplayer/qgstreamermetadataprovider.h | 8 +- .../mediaplayer/qgstreamerplayercontrol.h | 4 +- .../mediaplayer/qgstreamerplayersession.cpp | 8 +- .../mediaplayer/qgstreamerplayersession.h | 6 +- .../gstreamer/qgstreamerserviceplugin.cpp | 2 +- .../gstreamer/qgstreamerserviceplugin.h | 2 +- .../gstreamer/qgstreamervideoinputdevicecontrol.h | 2 +- .../gstreamer/qgstreamervideooutputcontrol.h | 2 +- .../gstreamer/qgstreamervideooverlay.h | 2 +- .../gstreamer/qgstreamervideorenderer.h | 2 +- .../gstreamer/qgstreamervideowidget.h | 2 +- src/plugins/mediaservices/mediaservices.pro | 2 +- .../qt7/mediaplayer/qt7playercontrol.h | 4 +- .../qt7/mediaplayer/qt7playercontrol.mm | 2 +- .../qt7/mediaplayer/qt7playermetadata.h | 10 +- .../qt7/mediaplayer/qt7playermetadata.mm | 20 +- .../qt7/mediaplayer/qt7playerservice.h | 2 +- .../qt7/mediaplayer/qt7playerservice.mm | 4 +- .../qt7/mediaplayer/qt7playersession.h | 4 +- .../qt7/mediaplayer/qt7playersession.mm | 2 +- src/plugins/mediaservices/qt7/qt7.pro | 4 +- src/plugins/mediaservices/qt7/qt7movieviewoutput.h | 4 +- .../mediaservices/qt7/qt7movieviewrenderer.h | 4 +- src/plugins/mediaservices/qt7/qt7serviceplugin.h | 2 +- src/plugins/mediaservices/qt7/qt7serviceplugin.mm | 2 +- .../mediaservices/qt7/qt7videooutputcontrol.h | 10 +- src/src.pro | 8 +- tests/auto/auto.pro | 1 + tests/auto/mediaservices.pro | 19 + tests/auto/multimedia.pro | 16 +- tests/auto/qdeclarativeaudio/qdeclarativeaudio.pro | 2 +- tests/auto/qdeclarativevideo/qdeclarativevideo.pro | 2 +- .../auto/qgraphicsvideoitem/qgraphicsvideoitem.pro | 4 +- tests/auto/qmediacontent/qmediacontent.pro | 2 +- tests/auto/qmediaobject/qmediaobject.pro | 2 +- tests/auto/qmediaplayer/qmediaplayer.pro | 2 +- tests/auto/qmediaplaylist/qmediaplaylist.pro | 2 +- .../qmediaplaylistnavigator.pro | 2 +- .../auto/qmediapluginloader/qmediapluginloader.pro | 2 +- tests/auto/qmediaresource/qmediaresource.pro | 2 +- tests/auto/qmediaservice/qmediaservice.pro | 2 +- .../qmediaserviceprovider.pro | 2 +- tests/auto/qmediatimerange/qmediatimerange.pro | 2 +- tests/auto/qsoundeffect/qsoundeffect.pro | 2 +- tests/auto/qvideowidget/qvideowidget.pro | 2 +- tools/configure/configureapp.cpp | 42 +- 348 files changed, 33560 insertions(+), 33496 deletions(-) delete mode 100644 src/multimedia/audio/audio.pri delete mode 100644 src/multimedia/audio/qaudio.cpp delete mode 100644 src/multimedia/audio/qaudio.h delete mode 100644 src/multimedia/audio/qaudio_mac.cpp delete mode 100644 src/multimedia/audio/qaudio_mac_p.h delete mode 100644 src/multimedia/audio/qaudio_symbian_p.cpp delete mode 100644 src/multimedia/audio/qaudio_symbian_p.h delete mode 100644 src/multimedia/audio/qaudiodevicefactory.cpp delete mode 100644 src/multimedia/audio/qaudiodevicefactory_p.h delete mode 100644 src/multimedia/audio/qaudiodeviceinfo.cpp delete mode 100644 src/multimedia/audio/qaudiodeviceinfo.h delete mode 100644 src/multimedia/audio/qaudiodeviceinfo_alsa_p.cpp delete mode 100644 src/multimedia/audio/qaudiodeviceinfo_alsa_p.h delete mode 100644 src/multimedia/audio/qaudiodeviceinfo_mac_p.cpp delete mode 100644 src/multimedia/audio/qaudiodeviceinfo_mac_p.h delete mode 100644 src/multimedia/audio/qaudiodeviceinfo_symbian_p.cpp delete mode 100644 src/multimedia/audio/qaudiodeviceinfo_symbian_p.h delete mode 100644 src/multimedia/audio/qaudiodeviceinfo_win32_p.cpp delete mode 100644 src/multimedia/audio/qaudiodeviceinfo_win32_p.h delete mode 100644 src/multimedia/audio/qaudioengine.cpp delete mode 100644 src/multimedia/audio/qaudioengine.h delete mode 100644 src/multimedia/audio/qaudioengineplugin.cpp delete mode 100644 src/multimedia/audio/qaudioengineplugin.h delete mode 100644 src/multimedia/audio/qaudioformat.cpp delete mode 100644 src/multimedia/audio/qaudioformat.h delete mode 100644 src/multimedia/audio/qaudioinput.cpp delete mode 100644 src/multimedia/audio/qaudioinput.h delete mode 100644 src/multimedia/audio/qaudioinput_alsa_p.cpp delete mode 100644 src/multimedia/audio/qaudioinput_alsa_p.h delete mode 100644 src/multimedia/audio/qaudioinput_mac_p.cpp delete mode 100644 src/multimedia/audio/qaudioinput_mac_p.h delete mode 100644 src/multimedia/audio/qaudioinput_symbian_p.cpp delete mode 100644 src/multimedia/audio/qaudioinput_symbian_p.h delete mode 100644 src/multimedia/audio/qaudioinput_win32_p.cpp delete mode 100644 src/multimedia/audio/qaudioinput_win32_p.h delete mode 100644 src/multimedia/audio/qaudiooutput.cpp delete mode 100644 src/multimedia/audio/qaudiooutput.h delete mode 100644 src/multimedia/audio/qaudiooutput_alsa_p.cpp delete mode 100644 src/multimedia/audio/qaudiooutput_alsa_p.h delete mode 100644 src/multimedia/audio/qaudiooutput_mac_p.cpp delete mode 100644 src/multimedia/audio/qaudiooutput_mac_p.h delete mode 100644 src/multimedia/audio/qaudiooutput_symbian_p.cpp delete mode 100644 src/multimedia/audio/qaudiooutput_symbian_p.h delete mode 100644 src/multimedia/audio/qaudiooutput_win32_p.cpp delete mode 100644 src/multimedia/audio/qaudiooutput_win32_p.h delete mode 100644 src/multimedia/base/base.pri delete mode 100644 src/multimedia/base/qgraphicsvideoitem.cpp delete mode 100644 src/multimedia/base/qgraphicsvideoitem.h delete mode 100644 src/multimedia/base/qlocalmediaplaylistprovider.cpp delete mode 100644 src/multimedia/base/qlocalmediaplaylistprovider.h delete mode 100644 src/multimedia/base/qmediacontent.cpp delete mode 100644 src/multimedia/base/qmediacontent.h delete mode 100644 src/multimedia/base/qmediacontrol.cpp delete mode 100644 src/multimedia/base/qmediacontrol.h delete mode 100644 src/multimedia/base/qmediacontrol_p.h delete mode 100644 src/multimedia/base/qmediaobject.cpp delete mode 100644 src/multimedia/base/qmediaobject.h delete mode 100644 src/multimedia/base/qmediaobject_p.h delete mode 100644 src/multimedia/base/qmediaplaylist.cpp delete mode 100644 src/multimedia/base/qmediaplaylist.h delete mode 100644 src/multimedia/base/qmediaplaylist_p.h delete mode 100644 src/multimedia/base/qmediaplaylistcontrol.cpp delete mode 100644 src/multimedia/base/qmediaplaylistcontrol.h delete mode 100644 src/multimedia/base/qmediaplaylistioplugin.cpp delete mode 100644 src/multimedia/base/qmediaplaylistioplugin.h delete mode 100644 src/multimedia/base/qmediaplaylistnavigator.cpp delete mode 100644 src/multimedia/base/qmediaplaylistnavigator.h delete mode 100644 src/multimedia/base/qmediaplaylistprovider.cpp delete mode 100644 src/multimedia/base/qmediaplaylistprovider.h delete mode 100644 src/multimedia/base/qmediaplaylistprovider_p.h delete mode 100644 src/multimedia/base/qmediapluginloader.cpp delete mode 100644 src/multimedia/base/qmediapluginloader_p.h delete mode 100644 src/multimedia/base/qmediaresource.cpp delete mode 100644 src/multimedia/base/qmediaresource.h delete mode 100644 src/multimedia/base/qmediaservice.cpp delete mode 100644 src/multimedia/base/qmediaservice.h delete mode 100644 src/multimedia/base/qmediaservice_p.h delete mode 100644 src/multimedia/base/qmediaserviceprovider.cpp delete mode 100644 src/multimedia/base/qmediaserviceprovider.h delete mode 100644 src/multimedia/base/qmediaserviceproviderplugin.h delete mode 100644 src/multimedia/base/qmediatimerange.cpp delete mode 100644 src/multimedia/base/qmediatimerange.h delete mode 100644 src/multimedia/base/qmetadatacontrol.cpp delete mode 100644 src/multimedia/base/qmetadatacontrol.h delete mode 100644 src/multimedia/base/qpaintervideosurface.cpp delete mode 100644 src/multimedia/base/qpaintervideosurface_mac.mm delete mode 100644 src/multimedia/base/qpaintervideosurface_mac_p.h delete mode 100644 src/multimedia/base/qpaintervideosurface_p.h delete mode 100644 src/multimedia/base/qtmedianamespace.h delete mode 100644 src/multimedia/base/qtmedianamespace.qdoc delete mode 100644 src/multimedia/base/qvideodevicecontrol.cpp delete mode 100644 src/multimedia/base/qvideodevicecontrol.h delete mode 100644 src/multimedia/base/qvideooutputcontrol.cpp delete mode 100644 src/multimedia/base/qvideooutputcontrol.h delete mode 100644 src/multimedia/base/qvideorenderercontrol.cpp delete mode 100644 src/multimedia/base/qvideorenderercontrol.h delete mode 100644 src/multimedia/base/qvideowidget.cpp delete mode 100644 src/multimedia/base/qvideowidget.h delete mode 100644 src/multimedia/base/qvideowidget_p.h delete mode 100644 src/multimedia/base/qvideowidgetcontrol.cpp delete mode 100644 src/multimedia/base/qvideowidgetcontrol.h delete mode 100644 src/multimedia/base/qvideowindowcontrol.cpp delete mode 100644 src/multimedia/base/qvideowindowcontrol.h delete mode 100644 src/multimedia/effects/effects.pri delete mode 100644 src/multimedia/effects/qsoundeffect.cpp delete mode 100644 src/multimedia/effects/qsoundeffect_p.h delete mode 100644 src/multimedia/effects/qsoundeffect_pulse_p.cpp delete mode 100644 src/multimedia/effects/qsoundeffect_pulse_p.h delete mode 100644 src/multimedia/effects/qsoundeffect_qmedia_p.cpp delete mode 100644 src/multimedia/effects/qsoundeffect_qmedia_p.h delete mode 100644 src/multimedia/effects/qsoundeffect_qsound_p.cpp delete mode 100644 src/multimedia/effects/qsoundeffect_qsound_p.h delete mode 100644 src/multimedia/effects/wavedecoder_p.cpp delete mode 100644 src/multimedia/effects/wavedecoder_p.h create mode 100644 src/multimedia/mediaservices/base/base.pri create mode 100644 src/multimedia/mediaservices/base/qgraphicsvideoitem.cpp create mode 100644 src/multimedia/mediaservices/base/qgraphicsvideoitem.h create mode 100644 src/multimedia/mediaservices/base/qlocalmediaplaylistprovider.cpp create mode 100644 src/multimedia/mediaservices/base/qlocalmediaplaylistprovider.h create mode 100644 src/multimedia/mediaservices/base/qmediacontent.cpp create mode 100644 src/multimedia/mediaservices/base/qmediacontent.h create mode 100644 src/multimedia/mediaservices/base/qmediacontrol.cpp create mode 100644 src/multimedia/mediaservices/base/qmediacontrol.h create mode 100644 src/multimedia/mediaservices/base/qmediacontrol_p.h create mode 100644 src/multimedia/mediaservices/base/qmediaobject.cpp create mode 100644 src/multimedia/mediaservices/base/qmediaobject.h create mode 100644 src/multimedia/mediaservices/base/qmediaobject_p.h create mode 100644 src/multimedia/mediaservices/base/qmediaplaylist.cpp create mode 100644 src/multimedia/mediaservices/base/qmediaplaylist.h create mode 100644 src/multimedia/mediaservices/base/qmediaplaylist_p.h create mode 100644 src/multimedia/mediaservices/base/qmediaplaylistcontrol.cpp create mode 100644 src/multimedia/mediaservices/base/qmediaplaylistcontrol.h create mode 100644 src/multimedia/mediaservices/base/qmediaplaylistioplugin.cpp create mode 100644 src/multimedia/mediaservices/base/qmediaplaylistioplugin.h create mode 100644 src/multimedia/mediaservices/base/qmediaplaylistnavigator.cpp create mode 100644 src/multimedia/mediaservices/base/qmediaplaylistnavigator.h create mode 100644 src/multimedia/mediaservices/base/qmediaplaylistprovider.cpp create mode 100644 src/multimedia/mediaservices/base/qmediaplaylistprovider.h create mode 100644 src/multimedia/mediaservices/base/qmediaplaylistprovider_p.h create mode 100644 src/multimedia/mediaservices/base/qmediapluginloader.cpp create mode 100644 src/multimedia/mediaservices/base/qmediapluginloader_p.h create mode 100644 src/multimedia/mediaservices/base/qmediaresource.cpp create mode 100644 src/multimedia/mediaservices/base/qmediaresource.h create mode 100644 src/multimedia/mediaservices/base/qmediaservice.cpp create mode 100644 src/multimedia/mediaservices/base/qmediaservice.h create mode 100644 src/multimedia/mediaservices/base/qmediaservice_p.h create mode 100644 src/multimedia/mediaservices/base/qmediaserviceprovider.cpp create mode 100644 src/multimedia/mediaservices/base/qmediaserviceprovider.h create mode 100644 src/multimedia/mediaservices/base/qmediaserviceproviderplugin.h create mode 100644 src/multimedia/mediaservices/base/qmediatimerange.cpp create mode 100644 src/multimedia/mediaservices/base/qmediatimerange.h create mode 100644 src/multimedia/mediaservices/base/qmetadatacontrol.cpp create mode 100644 src/multimedia/mediaservices/base/qmetadatacontrol.h create mode 100644 src/multimedia/mediaservices/base/qpaintervideosurface.cpp create mode 100644 src/multimedia/mediaservices/base/qpaintervideosurface_mac.mm create mode 100644 src/multimedia/mediaservices/base/qpaintervideosurface_mac_p.h create mode 100644 src/multimedia/mediaservices/base/qpaintervideosurface_p.h create mode 100644 src/multimedia/mediaservices/base/qtmedianamespace.h create mode 100644 src/multimedia/mediaservices/base/qtmedianamespace.qdoc create mode 100644 src/multimedia/mediaservices/base/qvideodevicecontrol.cpp create mode 100644 src/multimedia/mediaservices/base/qvideodevicecontrol.h create mode 100644 src/multimedia/mediaservices/base/qvideooutputcontrol.cpp create mode 100644 src/multimedia/mediaservices/base/qvideooutputcontrol.h create mode 100644 src/multimedia/mediaservices/base/qvideorenderercontrol.cpp create mode 100644 src/multimedia/mediaservices/base/qvideorenderercontrol.h create mode 100644 src/multimedia/mediaservices/base/qvideowidget.cpp create mode 100644 src/multimedia/mediaservices/base/qvideowidget.h create mode 100644 src/multimedia/mediaservices/base/qvideowidget_p.h create mode 100644 src/multimedia/mediaservices/base/qvideowidgetcontrol.cpp create mode 100644 src/multimedia/mediaservices/base/qvideowidgetcontrol.h create mode 100644 src/multimedia/mediaservices/base/qvideowindowcontrol.cpp create mode 100644 src/multimedia/mediaservices/base/qvideowindowcontrol.h create mode 100644 src/multimedia/mediaservices/effects/effects.pri create mode 100644 src/multimedia/mediaservices/effects/qsoundeffect.cpp create mode 100644 src/multimedia/mediaservices/effects/qsoundeffect_p.h create mode 100644 src/multimedia/mediaservices/effects/qsoundeffect_pulse_p.cpp create mode 100644 src/multimedia/mediaservices/effects/qsoundeffect_pulse_p.h create mode 100644 src/multimedia/mediaservices/effects/qsoundeffect_qmedia_p.cpp create mode 100644 src/multimedia/mediaservices/effects/qsoundeffect_qmedia_p.h create mode 100644 src/multimedia/mediaservices/effects/qsoundeffect_qsound_p.cpp create mode 100644 src/multimedia/mediaservices/effects/qsoundeffect_qsound_p.h create mode 100644 src/multimedia/mediaservices/effects/wavedecoder_p.cpp create mode 100644 src/multimedia/mediaservices/effects/wavedecoder_p.h create mode 100644 src/multimedia/mediaservices/mediaservices.pro create mode 100644 src/multimedia/mediaservices/playback/playback.pri create mode 100644 src/multimedia/mediaservices/playback/qmediaplayer.cpp create mode 100644 src/multimedia/mediaservices/playback/qmediaplayer.h create mode 100644 src/multimedia/mediaservices/playback/qmediaplayercontrol.cpp create mode 100644 src/multimedia/mediaservices/playback/qmediaplayercontrol.h create mode 100644 src/multimedia/multimedia/audio/audio.pri create mode 100644 src/multimedia/multimedia/audio/qaudio.cpp create mode 100644 src/multimedia/multimedia/audio/qaudio.h create mode 100644 src/multimedia/multimedia/audio/qaudio_mac.cpp create mode 100644 src/multimedia/multimedia/audio/qaudio_mac_p.h create mode 100644 src/multimedia/multimedia/audio/qaudio_symbian_p.cpp create mode 100644 src/multimedia/multimedia/audio/qaudio_symbian_p.h create mode 100644 src/multimedia/multimedia/audio/qaudiodevicefactory.cpp create mode 100644 src/multimedia/multimedia/audio/qaudiodevicefactory_p.h create mode 100644 src/multimedia/multimedia/audio/qaudiodeviceinfo.cpp create mode 100644 src/multimedia/multimedia/audio/qaudiodeviceinfo.h create mode 100644 src/multimedia/multimedia/audio/qaudiodeviceinfo_alsa_p.cpp create mode 100644 src/multimedia/multimedia/audio/qaudiodeviceinfo_alsa_p.h create mode 100644 src/multimedia/multimedia/audio/qaudiodeviceinfo_mac_p.cpp create mode 100644 src/multimedia/multimedia/audio/qaudiodeviceinfo_mac_p.h create mode 100644 src/multimedia/multimedia/audio/qaudiodeviceinfo_symbian_p.cpp create mode 100644 src/multimedia/multimedia/audio/qaudiodeviceinfo_symbian_p.h create mode 100644 src/multimedia/multimedia/audio/qaudiodeviceinfo_win32_p.cpp create mode 100644 src/multimedia/multimedia/audio/qaudiodeviceinfo_win32_p.h create mode 100644 src/multimedia/multimedia/audio/qaudioengine.cpp create mode 100644 src/multimedia/multimedia/audio/qaudioengine.h create mode 100644 src/multimedia/multimedia/audio/qaudioengineplugin.cpp create mode 100644 src/multimedia/multimedia/audio/qaudioengineplugin.h create mode 100644 src/multimedia/multimedia/audio/qaudioformat.cpp create mode 100644 src/multimedia/multimedia/audio/qaudioformat.h create mode 100644 src/multimedia/multimedia/audio/qaudioinput.cpp create mode 100644 src/multimedia/multimedia/audio/qaudioinput.h create mode 100644 src/multimedia/multimedia/audio/qaudioinput_alsa_p.cpp create mode 100644 src/multimedia/multimedia/audio/qaudioinput_alsa_p.h create mode 100644 src/multimedia/multimedia/audio/qaudioinput_mac_p.cpp create mode 100644 src/multimedia/multimedia/audio/qaudioinput_mac_p.h create mode 100644 src/multimedia/multimedia/audio/qaudioinput_symbian_p.cpp create mode 100644 src/multimedia/multimedia/audio/qaudioinput_symbian_p.h create mode 100644 src/multimedia/multimedia/audio/qaudioinput_win32_p.cpp create mode 100644 src/multimedia/multimedia/audio/qaudioinput_win32_p.h create mode 100644 src/multimedia/multimedia/audio/qaudiooutput.cpp create mode 100644 src/multimedia/multimedia/audio/qaudiooutput.h create mode 100644 src/multimedia/multimedia/audio/qaudiooutput_alsa_p.cpp create mode 100644 src/multimedia/multimedia/audio/qaudiooutput_alsa_p.h create mode 100644 src/multimedia/multimedia/audio/qaudiooutput_mac_p.cpp create mode 100644 src/multimedia/multimedia/audio/qaudiooutput_mac_p.h create mode 100644 src/multimedia/multimedia/audio/qaudiooutput_symbian_p.cpp create mode 100644 src/multimedia/multimedia/audio/qaudiooutput_symbian_p.h create mode 100644 src/multimedia/multimedia/audio/qaudiooutput_win32_p.cpp create mode 100644 src/multimedia/multimedia/audio/qaudiooutput_win32_p.h create mode 100644 src/multimedia/multimedia/multimedia.pro create mode 100644 src/multimedia/multimedia/video/qabstractvideobuffer.cpp create mode 100644 src/multimedia/multimedia/video/qabstractvideobuffer.h create mode 100644 src/multimedia/multimedia/video/qabstractvideobuffer_p.h create mode 100644 src/multimedia/multimedia/video/qabstractvideosurface.cpp create mode 100644 src/multimedia/multimedia/video/qabstractvideosurface.h create mode 100644 src/multimedia/multimedia/video/qabstractvideosurface_p.h create mode 100644 src/multimedia/multimedia/video/qimagevideobuffer.cpp create mode 100644 src/multimedia/multimedia/video/qimagevideobuffer_p.h create mode 100644 src/multimedia/multimedia/video/qmemoryvideobuffer.cpp create mode 100644 src/multimedia/multimedia/video/qmemoryvideobuffer_p.h create mode 100644 src/multimedia/multimedia/video/qvideoframe.cpp create mode 100644 src/multimedia/multimedia/video/qvideoframe.h create mode 100644 src/multimedia/multimedia/video/qvideosurfaceformat.cpp create mode 100644 src/multimedia/multimedia/video/qvideosurfaceformat.h create mode 100644 src/multimedia/multimedia/video/video.pri delete mode 100644 src/multimedia/playback/playback.pri delete mode 100644 src/multimedia/playback/qmediaplayer.cpp delete mode 100644 src/multimedia/playback/qmediaplayer.h delete mode 100644 src/multimedia/playback/qmediaplayercontrol.cpp delete mode 100644 src/multimedia/playback/qmediaplayercontrol.h delete mode 100644 src/multimedia/video/qabstractvideobuffer.cpp delete mode 100644 src/multimedia/video/qabstractvideobuffer.h delete mode 100644 src/multimedia/video/qabstractvideobuffer_p.h delete mode 100644 src/multimedia/video/qabstractvideosurface.cpp delete mode 100644 src/multimedia/video/qabstractvideosurface.h delete mode 100644 src/multimedia/video/qabstractvideosurface_p.h delete mode 100644 src/multimedia/video/qimagevideobuffer.cpp delete mode 100644 src/multimedia/video/qimagevideobuffer_p.h delete mode 100644 src/multimedia/video/qmemoryvideobuffer.cpp delete mode 100644 src/multimedia/video/qmemoryvideobuffer_p.h delete mode 100644 src/multimedia/video/qvideoframe.cpp delete mode 100644 src/multimedia/video/qvideoframe.h delete mode 100644 src/multimedia/video/qvideosurfaceformat.cpp delete mode 100644 src/multimedia/video/qvideosurfaceformat.h delete mode 100644 src/multimedia/video/video.pri create mode 100644 tests/auto/mediaservices.pro diff --git a/bin/syncqt b/bin/syncqt index 71f2eab..9fe0009 100755 --- a/bin/syncqt +++ b/bin/syncqt @@ -50,7 +50,8 @@ my %modules = ( # path to module name map "QtDBus" => "$basedir/src/dbus", "QtWebKit" => "$basedir/src/3rdparty/webkit/WebCore", "phonon" => "$basedir/src/phonon", - "QtMultimedia" => "$basedir/src/multimedia", + "QtMultimedia" => "$basedir/src/multimedia/multimedia", + "QtMediaservices" => "$basedir/src/multimedia/mediaservices", ); my %moduleheaders = ( # restrict the module headers to those found in relative path "QtWebKit" => "../WebKit/qt/Api", diff --git a/configure b/configure index 5478d06..11b33f6 100755 --- a/configure +++ b/configure @@ -682,7 +682,8 @@ CFG_RELEASE_QMAKE=no CFG_PHONON=auto CFG_PHONON_BACKEND=yes CFG_MULTIMEDIA=auto -CFG_MEDIASERVICE=auto +CFG_MEDIASERVICES=auto +CFG_MEDIA_BACKEND=auto CFG_AUDIO_BACKEND=auto CFG_SVG=auto CFG_DECLARATIVE=auto @@ -937,7 +938,7 @@ while [ "$#" -gt 0 ]; do VAL=no ;; #Qt style yes options - -incremental|-qvfb|-profile|-shared|-static|-sm|-xinerama|-xshape|-xsync|-xinput|-reduce-exports|-pch|-separate-debug-info|-stl|-freetype|-xcursor|-xfixes|-xrandr|-xrender|-mitshm|-fontconfig|-xkb|-nis|-qdbus|-dbus|-dbus-linked|-glib|-gstreamer|-gtkstyle|-cups|-iconv|-largefile|-h|-help|-v|-verbose|-debug|-release|-fast|-accessibility|-confirm-license|-gnumake|-framework|-qt3support|-debug-and-release|-exceptions|-cocoa|-carbon|-universal|-prefix-install|-silent|-armfpa|-optimized-qmake|-dwarf2|-reduce-relocations|-sse|-openssl|-openssl-linked|-ptmalloc|-xmlpatterns|-phonon|-phonon-backend|-multimedia|-mediaservice|-audio-backend|-svg|-declarative|-webkit|-javascript-jit|-script|-scripttools|-rpath|-force-pkg-config|-s60|-usedeffiles) + -incremental|-qvfb|-profile|-shared|-static|-sm|-xinerama|-xshape|-xsync|-xinput|-reduce-exports|-pch|-separate-debug-info|-stl|-freetype|-xcursor|-xfixes|-xrandr|-xrender|-mitshm|-fontconfig|-xkb|-nis|-qdbus|-dbus|-dbus-linked|-glib|-gstreamer|-gtkstyle|-cups|-iconv|-largefile|-h|-help|-v|-verbose|-debug|-release|-fast|-accessibility|-confirm-license|-gnumake|-framework|-qt3support|-debug-and-release|-exceptions|-cocoa|-carbon|-universal|-prefix-install|-silent|-armfpa|-optimized-qmake|-dwarf2|-reduce-relocations|-sse|-openssl|-openssl-linked|-ptmalloc|-xmlpatterns|-phonon|-phonon-backend|-multimedia|-mediaservices|-media-backend|-audio-backend|-svg|-declarative|-webkit|-javascript-jit|-script|-scripttools|-rpath|-force-pkg-config|-s60|-usedeffiles) VAR=`echo $1 | sed "s,^-\(.*\),\1,"` VAL=yes ;; @@ -2153,9 +2154,16 @@ while [ "$#" -gt 0 ]; do UNKNOWN_OPT=yes fi ;; - mediaservice) + mediaservices) if [ "$VAL" = "yes" ] || [ "$VAL" = "no" ]; then - CFG_MEDIASERVICE="$VAL" + CFG_MEDIASERVICES="$VAL" + else + UNKNOWN_OPT=yes + fi + ;; + media-backend) + if [ "$VAL" = "yes" ] || [ "$VAL" = "no" ]; then + CFG_MEDIA_BACKEND="$VAL" else UNKNOWN_OPT=yes fi @@ -3390,8 +3398,9 @@ Usage: $relconf [-h] [-prefix ] [-prefix-install] [-bindir ] [-libdir [-no-separate-debug-info] [-no-mmx] [-no-3dnow] [-no-sse] [-no-sse2] [-qtnamespace ] [-qtlibinfix ] [-separate-debug-info] [-armfpa] [-no-optimized-qmake] [-optimized-qmake] [-no-xmlpatterns] [-xmlpatterns] - [-no-multimedia] [-multimedia] [-no-phonon] [-phonon] [-no-phonon-backend] [-phonon-backend] - [-no-mediaservice] [-mediaservice] [-no-audio-backend] [-audio-backend] + [-no-multimedia] [-multimedia] [-no-mediaservices] [-mediaservices] + [-no-phonon] [-phonon] [-no-phonon-backend] [-phonon-backend] + [-no-media-backend] [-medias-backend] [-no-audio-backend] [-audio-backend] [-no-openssl] [-openssl] [-openssl-linked] [-no-gtkstyle] [-gtkstyle] [-no-svg] [-svg] [-no-webkit] [-webkit] [-no-javascript-jit] [-javascript-jit] [-no-script] [-script] [-no-scripttools] [-scripttools] [-no-declarative] [-declarative] @@ -3532,12 +3541,15 @@ fi -no-multimedia ..... Do not build the QtMultimedia module. + -multimedia ........ Build the QtMultimedia module. - -no-mediaservice.... Do not build platform mediaservice plugin. - + -mediaservice ...... Build the platform mediaservice plugin. - -no-audio-backend .. Do not build the platform audio backend into QtMultimedia. + -audio-backend ..... Build the platform audio backend into QtMultimedia if available. + -no-mediaservices... Do not build the QtMediaservices module. + + -mediaservices...... Build the QtMediaservices module. + + -no-media-backend... Do not build platform mediaservices plugin. + + -media-backend..... Build the platform mediaservices plugin. + -no-phonon ......... Do not build the Phonon module. + -phonon ............ Build the Phonon module. Phonon is built if a decent C++ compiler is used. @@ -5176,16 +5188,16 @@ if [ "$PLATFORM_X11" = "yes" -o "$PLATFORM_QWS" = "yes" ]; then fi if [ "$CFG_GUI" = "no" ]; then - if [ "$CFG_MEDIASERVICE" = "auto" ]; then - CFG_MEDIASERVICE=no + if [ "$CFG_MEDIA_BACKEND" = "auto" ]; then + CFG_MEDIA_BACKEND=no fi - if [ "$CFG_MEDIASERVICE" != "no" ]; then - echo "Mediaservice enabled, but GUI disabled." - echo " You might need to either enable the GUI or disable Mediaservice" + if [ "$CFG_MEDIA_BACKEND" != "no" ]; then + echo "Medias backend enabled, but GUI disabled." + echo " You might need to either enable the GUI or disable the media backend" exit 1 fi - elif [ "$CFG_MEDIASERVICE" = "auto" ]; then - CFG_MEDIASERVICE=yes + elif [ "$CFG_MEDIA_BACKEND" = "auto" ]; then + CFG_MEDIA_BACKEND=yes fi # Auto-detect GStreamer support (needed for both Phonon & QtMultimedia) @@ -6820,8 +6832,14 @@ if [ "$CFG_MULTIMEDIA" = "no" ]; then QCONFIG_FLAGS="$QCONFIG_FLAGS QT_NO_MULTIMEDIA" else QT_CONFIG="$QT_CONFIG multimedia" - if [ "$CFG_MEDIASERVICE" = "yes" ]; then - QT_CONFIG="$QT_CONFIG mediaservice" +fi + +if [ "$CFG_MEDIASERVICES" = "no" ]; then + QCONFIG_FLAGS="$QCONFIG_FLAGS QT_NO_MEDIASERVICES" +else + QT_CONFIG="$QT_CONFIG mediaservices" + if [ "$CFG_MEDIA_BACKEND" = "yes" ]; then + QT_CONFIG="$QT_CONFIG media-backend" fi fi @@ -7782,6 +7800,7 @@ echo "QtScriptTools module ... $CFG_SCRIPTTOOLS" echo "QtXmlPatterns module ... $CFG_XMLPATTERNS" echo "Phonon module .......... $CFG_PHONON" echo "Multimedia module ...... $CFG_MULTIMEDIA" +echo "Mediaservices module ... $CFG_MEDIASERVICES" echo "SVG module ............. $CFG_SVG" echo "WebKit module .......... $CFG_WEBKIT" if [ "$CFG_WEBKIT" = "yes" ]; then diff --git a/demos/multimedia/player/player.cpp b/demos/multimedia/player/player.cpp index af30a97..20341bc 100644 --- a/demos/multimedia/player/player.cpp +++ b/demos/multimedia/player/player.cpp @@ -45,8 +45,8 @@ #include "playlistmodel.h" #include "videowidget.h" -#include -#include +#include +#include #include @@ -204,14 +204,14 @@ void Player::positionChanged(qint64 progress) void Player::metaDataChanged() { - //qDebug() << "update metadata" << player->metaData(QtMultimedia::Title).toString(); + //qDebug() << "update metadata" << player->metaData(QtMediaservices::Title).toString(); if (player->isMetaDataAvailable()) { setTrackInfo(QString("%1 - %2") - .arg(player->metaData(QtMultimedia::AlbumArtist).toString()) - .arg(player->metaData(QtMultimedia::Title).toString())); + .arg(player->metaData(QtMediaservices::AlbumArtist).toString()) + .arg(player->metaData(QtMediaservices::Title).toString())); if (coverLabel) { - QUrl url = player->metaData(QtMultimedia::CoverArtUrlLarge).value(); + QUrl url = player->metaData(QtMediaservices::CoverArtUrlLarge).value(); coverLabel->setPixmap(!url.isEmpty() ? QPixmap(url.toString()) diff --git a/demos/multimedia/player/player.pro b/demos/multimedia/player/player.pro index dc731e4..fb93416 100644 --- a/demos/multimedia/player/player.pro +++ b/demos/multimedia/player/player.pro @@ -1,7 +1,7 @@ TEMPLATE = app TARGET = player -QT += gui multimedia +QT += gui mediaservices HEADERS = \ diff --git a/demos/multimedia/player/playercontrols.h b/demos/multimedia/player/playercontrols.h index 99894ff..0b0b0e6 100644 --- a/demos/multimedia/player/playercontrols.h +++ b/demos/multimedia/player/playercontrols.h @@ -42,7 +42,7 @@ #ifndef PLAYERCONTROLS_H #define PLAYERCONTROLS_H -#include +#include #include diff --git a/demos/multimedia/player/videowidget.h b/demos/multimedia/player/videowidget.h index 543e1e0..0251bfe 100644 --- a/demos/multimedia/player/videowidget.h +++ b/demos/multimedia/player/videowidget.h @@ -41,7 +41,7 @@ #ifndef VIDEOWIDGET_H #define VIDEOWIDGET_H -#include +#include QT_BEGIN_HEADER diff --git a/mkspecs/features/qt.prf b/mkspecs/features/qt.prf index 62cce62..ff4e986 100644 --- a/mkspecs/features/qt.prf +++ b/mkspecs/features/qt.prf @@ -36,7 +36,7 @@ INCLUDEPATH = $$QMAKE_INCDIR_QT $$INCLUDEPATH #prepending prevents us from picki win32:INCLUDEPATH += $$QMAKE_INCDIR_QT/ActiveQt # As order does matter for static libs, we reorder the QT variable here -TMPLIBS = declarative webkit phonon multimedia dbus testlib script scripttools svg qt3support sql xmlpatterns xml egl opengl openvg gui network core +TMPLIBS = declarative webkit phonon mediaservices multimedia dbus testlib script scripttools svg qt3support sql xmlpatterns xml egl opengl openvg gui network core for(QTLIB, $$list($$TMPLIBS)) { contains(QT, $$QTLIB): QT_ORDERED += $$QTLIB } @@ -175,6 +175,7 @@ for(QTLIB, $$list($$lower($$unique(QT)))) { } } else:isEqual(QTLIB, declarative):qlib = QtDeclarative else:isEqual(QTLIB, multimedia):qlib = QtMultimedia + else:isEqual(QTLIB, mediaservices):qlib = QtMediaservices else:message("Unknown QT: $$QTLIB"):qlib = !isEmpty(qlib) { target_qt:isEqual(TARGET, qlib) { diff --git a/src/3rdparty/webkit/WebCore/WebCore.pro b/src/3rdparty/webkit/WebCore/WebCore.pro index bdb3f83..22c39b6 100644 --- a/src/3rdparty/webkit/WebCore/WebCore.pro +++ b/src/3rdparty/webkit/WebCore/WebCore.pro @@ -142,7 +142,7 @@ addJavaScriptCoreLib(../JavaScriptCore) DEFINES -= ENABLE_VIDEO=0 DEFINES += ENABLE_VIDEO=1 } - !lessThan(QT_MINOR_VERSION, 7):contains(QT_CONFIG, multimedia) { + !lessThan(QT_MINOR_VERSION, 7):contains(QT_CONFIG, mediaservices) { DEFINES -= ENABLE_VIDEO=0 DEFINES += ENABLE_VIDEO=1 } @@ -2370,7 +2370,7 @@ contains(DEFINES, ENABLE_VIDEO=1) { HEADERS += platform/graphics/qt/MediaPlayerPrivateQt.h SOURCES += platform/graphics/qt/MediaPlayerPrivateQt.cpp - tobe|!tobe: QT += multimedia + tobe|!tobe: QT += mediaservices } else { HEADERS += \ platform/graphics/qt/MediaPlayerPrivatePhonon.h diff --git a/src/imports/multimedia/multimedia.cpp b/src/imports/multimedia/multimedia.cpp index a2e74f4..46ceb34 100644 --- a/src/imports/multimedia/multimedia.cpp +++ b/src/imports/multimedia/multimedia.cpp @@ -41,7 +41,7 @@ #include #include -#include +#include #include "qdeclarativevideo_p.h" #include "qdeclarativeaudio_p.h" diff --git a/src/imports/multimedia/multimedia.pro b/src/imports/multimedia/multimedia.pro index 92f7ec4..c1933a3 100644 --- a/src/imports/multimedia/multimedia.pro +++ b/src/imports/multimedia/multimedia.pro @@ -2,7 +2,7 @@ TARGET = multimedia TARGETPATH = Qt/multimedia include(../qimportbase.pri) -QT += multimedia declarative +QT += mediaservices declarative HEADERS += \ qdeclarativeaudio_p.h \ diff --git a/src/imports/multimedia/qdeclarativeaudio.cpp b/src/imports/multimedia/qdeclarativeaudio.cpp index 8d2dc61..4e75099 100644 --- a/src/imports/multimedia/qdeclarativeaudio.cpp +++ b/src/imports/multimedia/qdeclarativeaudio.cpp @@ -41,7 +41,7 @@ #include "qdeclarativeaudio_p.h" -#include +#include QT_BEGIN_NAMESPACE diff --git a/src/imports/multimedia/qdeclarativemediabase.cpp b/src/imports/multimedia/qdeclarativemediabase.cpp index bbd5901..5ed602a 100644 --- a/src/imports/multimedia/qdeclarativemediabase.cpp +++ b/src/imports/multimedia/qdeclarativemediabase.cpp @@ -44,10 +44,10 @@ #include #include -#include -#include -#include -#include +#include +#include +#include +#include #include "qmetadatacontrolmetaobject_p.h" diff --git a/src/imports/multimedia/qdeclarativemediabase_p.h b/src/imports/multimedia/qdeclarativemediabase_p.h index 7d262e0..e5115de 100644 --- a/src/imports/multimedia/qdeclarativemediabase_p.h +++ b/src/imports/multimedia/qdeclarativemediabase_p.h @@ -54,7 +54,7 @@ // #include -#include +#include QT_BEGIN_HEADER diff --git a/src/imports/multimedia/qdeclarativevideo.cpp b/src/imports/multimedia/qdeclarativevideo.cpp index bf112be..734bd96 100644 --- a/src/imports/multimedia/qdeclarativevideo.cpp +++ b/src/imports/multimedia/qdeclarativevideo.cpp @@ -41,11 +41,11 @@ #include "qdeclarativevideo_p.h" -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include QT_BEGIN_NAMESPACE @@ -435,7 +435,7 @@ QT_END_NAMESPACE This property holds the tile of the media. - \sa {QtMultimedia::Title} + \sa {QtMediaservices::Title} */ /*! @@ -443,7 +443,7 @@ QT_END_NAMESPACE This property holds the sub-title of the media. - \sa {QtMultimedia::SubTitle} + \sa {QtMediaservices::SubTitle} */ /*! @@ -451,7 +451,7 @@ QT_END_NAMESPACE This property holds the author of the media. - \sa {QtMultimedia::Author} + \sa {QtMediaservices::Author} */ /*! @@ -459,7 +459,7 @@ QT_END_NAMESPACE This property holds a user comment about the media. - \sa {QtMultimedia::Comment} + \sa {QtMediaservices::Comment} */ /*! @@ -467,7 +467,7 @@ QT_END_NAMESPACE This property holds a description of the media. - \sa {QtMultimedia::Description} + \sa {QtMediaservices::Description} */ /*! @@ -475,7 +475,7 @@ QT_END_NAMESPACE This property holds the category of the media - \sa {QtMultimedia::Category} + \sa {QtMediaservices::Category} */ /*! @@ -483,7 +483,7 @@ QT_END_NAMESPACE This property holds the genre of the media. - \sa {QtMultimedia::Genre} + \sa {QtMediaservices::Genre} */ /*! @@ -491,7 +491,7 @@ QT_END_NAMESPACE This property holds the year of release of the media. - \sa {QtMultimedia::Year} + \sa {QtMediaservices::Year} */ /*! @@ -499,7 +499,7 @@ QT_END_NAMESPACE This property holds the date of the media. - \sa {QtMultimedia::Date} + \sa {QtMediaservices::Date} */ /*! @@ -507,7 +507,7 @@ QT_END_NAMESPACE This property holds a user rating of the media in the range of 0 to 100. - \sa {QtMultimedia::UserRating} + \sa {QtMediaservices::UserRating} */ /*! @@ -515,7 +515,7 @@ QT_END_NAMESPACE This property holds a list of keywords describing the media. - \sa {QtMultimedia::Keywords} + \sa {QtMediaservices::Keywords} */ /*! @@ -523,7 +523,7 @@ QT_END_NAMESPACE This property holds the language of the media, as an ISO 639-2 code. - \sa {QtMultimedia::Language} + \sa {QtMediaservices::Language} */ /*! @@ -531,7 +531,7 @@ QT_END_NAMESPACE This property holds the publisher of the media. - \sa {QtMultimedia::Publisher} + \sa {QtMediaservices::Publisher} */ /*! @@ -539,7 +539,7 @@ QT_END_NAMESPACE This property holds the media's copyright notice. - \sa {QtMultimedia::Copyright} + \sa {QtMediaservices::Copyright} */ /*! @@ -547,7 +547,7 @@ QT_END_NAMESPACE This property holds the parental rating of the media. - \sa {QtMultimedia::ParentalRating} + \sa {QtMediaservices::ParentalRating} */ /*! @@ -556,7 +556,7 @@ QT_END_NAMESPACE This property holds the name of the rating organisation responsible for the parental rating of the media. - \sa {QtMultimedia::RatingOrganisation} + \sa {QtMediaservices::RatingOrganisation} */ /*! @@ -564,7 +564,7 @@ QT_END_NAMESPACE This property property holds the size of the media in bytes. - \sa {QtMultimedia::Size} + \sa {QtMediaservices::Size} */ /*! @@ -572,7 +572,7 @@ QT_END_NAMESPACE This property holds the type of the media. - \sa {QtMultimedia::MediaType} + \sa {QtMediaservices::MediaType} */ /*! @@ -581,7 +581,7 @@ QT_END_NAMESPACE This property holds the bit rate of the media's audio stream ni bits per second. - \sa {QtMultimedia::AudioBitRate} + \sa {QtMediaservices::AudioBitRate} */ /*! @@ -589,7 +589,7 @@ QT_END_NAMESPACE This property holds the encoding of the media audio stream. - \sa {QtMultimedia::AudioCodec} + \sa {QtMediaservices::AudioCodec} */ /*! @@ -597,7 +597,7 @@ QT_END_NAMESPACE This property holds the average volume level of the media. - \sa {QtMultimedia::AverageLevel} + \sa {QtMediaservices::AverageLevel} */ /*! @@ -605,7 +605,7 @@ QT_END_NAMESPACE This property holds the number of channels in the media's audio stream. - \sa {QtMultimedia::ChannelCount} + \sa {QtMediaservices::ChannelCount} */ /*! @@ -613,7 +613,7 @@ QT_END_NAMESPACE This property holds the peak volume of media's audio stream. - \sa {QtMultimedia::PeakValue} + \sa {QtMediaservices::PeakValue} */ /*! @@ -621,7 +621,7 @@ QT_END_NAMESPACE This property holds the sample rate of the media's audio stream in hertz. - \sa {QtMultimedia::SampleRate} + \sa {QtMediaservices::SampleRate} */ /*! @@ -629,7 +629,7 @@ QT_END_NAMESPACE This property holds the title of the album the media belongs to. - \sa {QtMultimedia::AlbumTitle} + \sa {QtMediaservices::AlbumTitle} */ /*! @@ -638,7 +638,7 @@ QT_END_NAMESPACE This property holds the name of the principal artist of the album the media belongs to. - \sa {QtMultimedia::AlbumArtist} + \sa {QtMediaservices::AlbumArtist} */ /*! @@ -646,7 +646,7 @@ QT_END_NAMESPACE This property holds the names of artists contributing to the media. - \sa {QtMultimedia::ContributingArtist} + \sa {QtMediaservices::ContributingArtist} */ /*! @@ -654,7 +654,7 @@ QT_END_NAMESPACE This property holds the composer of the media. - \sa {QtMultimedia::Composer} + \sa {QtMediaservices::Composer} */ /*! @@ -662,7 +662,7 @@ QT_END_NAMESPACE This property holds the conductor of the media. - \sa {QtMultimedia::Conductor} + \sa {QtMediaservices::Conductor} */ /*! @@ -670,7 +670,7 @@ QT_END_NAMESPACE This property holds the lyrics to the media. - \sa {QtMultimedia::Lyrics} + \sa {QtMediaservices::Lyrics} */ /*! @@ -678,7 +678,7 @@ QT_END_NAMESPACE This property holds the mood of the media. - \sa {QtMultimedia::Mood} + \sa {QtMediaservices::Mood} */ /*! @@ -686,7 +686,7 @@ QT_END_NAMESPACE This property holds the track number of the media. - \sa {QtMultimedia::TrackNumber} + \sa {QtMediaservices::TrackNumber} */ /*! @@ -694,7 +694,7 @@ QT_END_NAMESPACE This property holds the number of track on the album containing the media. - \sa {QtMultimedia::TrackNumber} + \sa {QtMediaservices::TrackNumber} */ /*! @@ -702,7 +702,7 @@ QT_END_NAMESPACE This property holds the URL of a small cover art image. - \sa {QtMultimedia::CoverArtUrlSmall} + \sa {QtMediaservices::CoverArtUrlSmall} */ /*! @@ -710,7 +710,7 @@ QT_END_NAMESPACE This property holds the URL of a large cover art image. - \sa {QtMultimedia::CoverArtUrlLarge} + \sa {QtMediaservices::CoverArtUrlLarge} */ /*! @@ -718,7 +718,7 @@ QT_END_NAMESPACE This property holds the dimension of an image or video. - \sa {QtMultimedia::Resolution} + \sa {QtMediaservices::Resolution} */ /*! @@ -726,7 +726,7 @@ QT_END_NAMESPACE This property holds the pixel aspect ratio of an image or video. - \sa {QtMultimedia::PixelAspectRatio} + \sa {QtMediaservices::PixelAspectRatio} */ /*! @@ -734,7 +734,7 @@ QT_END_NAMESPACE This property holds the frame rate of the media's video stream. - \sa {QtMultimedia::VideoFrameRate} + \sa {QtMediaservices::VideoFrameRate} */ /*! @@ -743,7 +743,7 @@ QT_END_NAMESPACE This property holds the bit rate of the media's video stream in bits per second. - \sa {QtMultimedia::VideoBitRate} + \sa {QtMediaservices::VideoBitRate} */ /*! @@ -751,7 +751,7 @@ QT_END_NAMESPACE This property holds the encoding of the media's video stream. - \sa {QtMultimedia::VideoCodec} + \sa {QtMediaservices::VideoCodec} */ /*! @@ -759,7 +759,7 @@ QT_END_NAMESPACE This property holds the URL of a poster image. - \sa {QtMultimedia::PosterUrl} + \sa {QtMediaservices::PosterUrl} */ /*! @@ -767,7 +767,7 @@ QT_END_NAMESPACE This property holds the chapter number of the media. - \sa {QtMultimedia::ChapterNumber} + \sa {QtMediaservices::ChapterNumber} */ /*! @@ -775,7 +775,7 @@ QT_END_NAMESPACE This property holds the director of the media. - \sa {QtMultimedia::Director} + \sa {QtMediaservices::Director} */ /*! @@ -783,7 +783,7 @@ QT_END_NAMESPACE This property holds the lead performer in the media. - \sa {QtMultimedia::LeadPerformer} + \sa {QtMediaservices::LeadPerformer} */ /*! @@ -791,7 +791,7 @@ QT_END_NAMESPACE This property holds the writer of the media. - \sa {QtMultimedia::Writer} + \sa {QtMediaservices::Writer} */ // The remaining properties are related to photos, and are technically @@ -801,157 +801,157 @@ QT_END_NAMESPACE /*! \qmlproperty variant Video::cameraManufacturer - \sa {QtMultimedia::CameraManufacturer} + \sa {QtMediaservices::CameraManufacturer} */ /*! \qmlproperty variant Video::cameraModel - \sa {QtMultimedia::CameraModel} + \sa {QtMediaservices::CameraModel} */ /*! \qmlproperty variant Video::event - \sa {QtMultimedia::Event} + \sa {QtMediaservices::Event} */ /*! \qmlproperty variant Video::subject - \sa {QtMultimedia::Subject} + \sa {QtMediaservices::Subject} */ /*! \qmlproperty variant Video::orientation - \sa {QtMultimedia::Orientation} + \sa {QtMediaservices::Orientation} */ /*! \qmlproperty variant Video::exposureTime - \sa {QtMultimedia::ExposureTime} + \sa {QtMediaservices::ExposureTime} */ /*! \qmlproperty variant Video::fNumber - \sa {QtMultimedia::FNumber} + \sa {QtMediaservices::FNumber} */ /*! \qmlproperty variant Video::exposureProgram - \sa {QtMultimedia::ExposureProgram} + \sa {QtMediaservices::ExposureProgram} */ /*! \qmlproperty variant Video::isoSpeedRatings - \sa {QtMultimedia::ISOSpeedRatings} + \sa {QtMediaservices::ISOSpeedRatings} */ /*! \qmlproperty variant Video::exposureBiasValue - \sa {QtMultimedia::ExposureBiasValue} + \sa {QtMediaservices::ExposureBiasValue} */ /*! \qmlproperty variant Video::dateTimeDigitized - \sa {QtMultimedia::DateTimeDigitized} + \sa {QtMediaservices::DateTimeDigitized} */ /*! \qmlproperty variant Video::subjectDistance - \sa {QtMultimedia::SubjectDistance} + \sa {QtMediaservices::SubjectDistance} */ /*! \qmlproperty variant Video::meteringMode - \sa {QtMultimedia::MeteringMode} + \sa {QtMediaservices::MeteringMode} */ /*! \qmlproperty variant Video::lightSource - \sa {QtMultimedia::LightSource} + \sa {QtMediaservices::LightSource} */ /*! \qmlproperty variant Video::flash - \sa {QtMultimedia::Flash} + \sa {QtMediaservices::Flash} */ /*! \qmlproperty variant Video::focalLength - \sa {QtMultimedia::FocalLength} + \sa {QtMediaservices::FocalLength} */ /*! \qmlproperty variant Video::exposureMode - \sa {QtMultimedia::ExposureMode} + \sa {QtMediaservices::ExposureMode} */ /*! \qmlproperty variant Video::whiteBalance - \sa {QtMultimedia::WhiteBalance} + \sa {QtMediaservices::WhiteBalance} */ /*! \qmlproperty variant Video::DigitalZoomRatio - \sa {QtMultimedia::DigitalZoomRatio} + \sa {QtMediaservices::DigitalZoomRatio} */ /*! \qmlproperty variant Video::focalLengthIn35mmFilm - \sa {QtMultimedia::FocalLengthIn35mmFile} + \sa {QtMediaservices::FocalLengthIn35mmFile} */ /*! \qmlproperty variant Video::sceneCaptureType - \sa {QtMultimedia::SceneCaptureType} + \sa {QtMediaservices::SceneCaptureType} */ /*! \qmlproperty variant Video::gainControl - \sa {QtMultimedia::GainControl} + \sa {QtMediaservices::GainControl} */ /*! \qmlproperty variant Video::contrast - \sa {QtMultimedia::contrast} + \sa {QtMediaservices::contrast} */ /*! \qmlproperty variant Video::saturation - \sa {QtMultimedia::Saturation} + \sa {QtMediaservices::Saturation} */ /*! \qmlproperty variant Video::sharpness - \sa {QtMultimedia::Sharpness} + \sa {QtMediaservices::Sharpness} */ /*! \qmlproperty variant Video::deviceSettingDescription - \sa {QtMultimedia::DeviceSettingDescription} + \sa {QtMediaservices::DeviceSettingDescription} */ #endif diff --git a/src/imports/multimedia/qdeclarativevideo_p.h b/src/imports/multimedia/qdeclarativevideo_p.h index 29e1090..99882ac 100644 --- a/src/imports/multimedia/qdeclarativevideo_p.h +++ b/src/imports/multimedia/qdeclarativevideo_p.h @@ -55,7 +55,7 @@ #include "qdeclarativemediabase_p.h" -#include +#include #include #include diff --git a/src/imports/multimedia/qmetadatacontrolmetaobject.cpp b/src/imports/multimedia/qmetadatacontrolmetaobject.cpp index e90cbd6..2f45b50 100644 --- a/src/imports/multimedia/qmetadatacontrolmetaobject.cpp +++ b/src/imports/multimedia/qmetadatacontrolmetaobject.cpp @@ -40,7 +40,7 @@ ****************************************************************************/ #include "qmetadatacontrolmetaobject_p.h" -#include +#include QT_BEGIN_NAMESPACE @@ -106,101 +106,101 @@ namespace { struct MetaDataKey { - QtMultimedia::MetaData key; + QtMediaservices::MetaData key; const char *name; }; const MetaDataKey qt_metaDataKeys[] = { - { QtMultimedia::Title, "title" }, - { QtMultimedia::SubTitle, "subTitle" }, - { QtMultimedia::Author, "author" }, - { QtMultimedia::Comment, "comment" }, - { QtMultimedia::Description, "description" }, - { QtMultimedia::Category, "category" }, - { QtMultimedia::Genre, "genre" }, - { QtMultimedia::Year, "year" }, - { QtMultimedia::Date, "date" }, - { QtMultimedia::UserRating, "userRating" }, - { QtMultimedia::Keywords, "keywords" }, - { QtMultimedia::Language, "language" }, - { QtMultimedia::Publisher, "publisher" }, - { QtMultimedia::Copyright, "copyright" }, - { QtMultimedia::ParentalRating, "parentalRating" }, - { QtMultimedia::RatingOrganisation, "ratingOrganisation" }, + { QtMediaservices::Title, "title" }, + { QtMediaservices::SubTitle, "subTitle" }, + { QtMediaservices::Author, "author" }, + { QtMediaservices::Comment, "comment" }, + { QtMediaservices::Description, "description" }, + { QtMediaservices::Category, "category" }, + { QtMediaservices::Genre, "genre" }, + { QtMediaservices::Year, "year" }, + { QtMediaservices::Date, "date" }, + { QtMediaservices::UserRating, "userRating" }, + { QtMediaservices::Keywords, "keywords" }, + { QtMediaservices::Language, "language" }, + { QtMediaservices::Publisher, "publisher" }, + { QtMediaservices::Copyright, "copyright" }, + { QtMediaservices::ParentalRating, "parentalRating" }, + { QtMediaservices::RatingOrganisation, "ratingOrganisation" }, // Media - { QtMultimedia::Size, "size" }, - { QtMultimedia::MediaType, "mediaType" }, -// { QtMultimedia::Duration, "duration" }, + { QtMediaservices::Size, "size" }, + { QtMediaservices::MediaType, "mediaType" }, +// { QtMediaservices::Duration, "duration" }, // Audio - { QtMultimedia::AudioBitRate, "audioBitRate" }, - { QtMultimedia::AudioCodec, "audioCodec" }, - { QtMultimedia::AverageLevel, "averageLevel" }, - { QtMultimedia::ChannelCount, "channelCount" }, - { QtMultimedia::PeakValue, "peakValue" }, - { QtMultimedia::SampleRate, "sampleRate" }, + { QtMediaservices::AudioBitRate, "audioBitRate" }, + { QtMediaservices::AudioCodec, "audioCodec" }, + { QtMediaservices::AverageLevel, "averageLevel" }, + { QtMediaservices::ChannelCount, "channelCount" }, + { QtMediaservices::PeakValue, "peakValue" }, + { QtMediaservices::SampleRate, "sampleRate" }, // Music - { QtMultimedia::AlbumTitle, "albumTitle" }, - { QtMultimedia::AlbumArtist, "albumArtist" }, - { QtMultimedia::ContributingArtist, "contributingArtist" }, - { QtMultimedia::Composer, "composer" }, - { QtMultimedia::Conductor, "conductor" }, - { QtMultimedia::Lyrics, "lyrics" }, - { QtMultimedia::Mood, "mood" }, - { QtMultimedia::TrackNumber, "trackNumber" }, - { QtMultimedia::TrackCount, "trackCount" }, - - { QtMultimedia::CoverArtUrlSmall, "coverArtUrlSmall" }, - { QtMultimedia::CoverArtUrlLarge, "coverArtUrlLarge" }, + { QtMediaservices::AlbumTitle, "albumTitle" }, + { QtMediaservices::AlbumArtist, "albumArtist" }, + { QtMediaservices::ContributingArtist, "contributingArtist" }, + { QtMediaservices::Composer, "composer" }, + { QtMediaservices::Conductor, "conductor" }, + { QtMediaservices::Lyrics, "lyrics" }, + { QtMediaservices::Mood, "mood" }, + { QtMediaservices::TrackNumber, "trackNumber" }, + { QtMediaservices::TrackCount, "trackCount" }, + + { QtMediaservices::CoverArtUrlSmall, "coverArtUrlSmall" }, + { QtMediaservices::CoverArtUrlLarge, "coverArtUrlLarge" }, // Image/Video - { QtMultimedia::Resolution, "resolution" }, - { QtMultimedia::PixelAspectRatio, "pixelAspectRatio" }, + { QtMediaservices::Resolution, "resolution" }, + { QtMediaservices::PixelAspectRatio, "pixelAspectRatio" }, // Video - { QtMultimedia::VideoFrameRate, "videoFrameRate" }, - { QtMultimedia::VideoBitRate, "videoBitRate" }, - { QtMultimedia::VideoCodec, "videoCodec" }, + { QtMediaservices::VideoFrameRate, "videoFrameRate" }, + { QtMediaservices::VideoBitRate, "videoBitRate" }, + { QtMediaservices::VideoCodec, "videoCodec" }, - { QtMultimedia::PosterUrl, "posterUrl" }, + { QtMediaservices::PosterUrl, "posterUrl" }, // Movie - { QtMultimedia::ChapterNumber, "chapterNumber" }, - { QtMultimedia::Director, "director" }, - { QtMultimedia::LeadPerformer, "leadPerformer" }, - { QtMultimedia::Writer, "writer" }, + { QtMediaservices::ChapterNumber, "chapterNumber" }, + { QtMediaservices::Director, "director" }, + { QtMediaservices::LeadPerformer, "leadPerformer" }, + { QtMediaservices::Writer, "writer" }, // Photos - { QtMultimedia::CameraManufacturer, "cameraManufacturer" }, - { QtMultimedia::CameraModel, "cameraModel" }, - { QtMultimedia::Event, "event" }, - { QtMultimedia::Subject, "subject" }, - { QtMultimedia::Orientation, "orientation" }, - { QtMultimedia::ExposureTime, "exposureTime" }, - { QtMultimedia::FNumber, "fNumber" }, - { QtMultimedia::ExposureProgram, "exposureProgram" }, - { QtMultimedia::ISOSpeedRatings, "isoSpeedRatings" }, - { QtMultimedia::ExposureBiasValue, "exposureBiasValue" }, - { QtMultimedia::DateTimeOriginal, "dateTimeOriginal" }, - { QtMultimedia::DateTimeDigitized, "dateTimeDigitized" }, - { QtMultimedia::SubjectDistance, "subjectDistance" }, - { QtMultimedia::MeteringMode, "meteringMode" }, - { QtMultimedia::LightSource, "lightSource" }, - { QtMultimedia::Flash, "flash" }, - { QtMultimedia::FocalLength, "focalLength" }, - { QtMultimedia::ExposureMode, "exposureMode" }, - { QtMultimedia::WhiteBalance, "whiteBalance" }, - { QtMultimedia::DigitalZoomRatio, "digitalZoomRatio" }, - { QtMultimedia::FocalLengthIn35mmFilm, "focalLengthIn35mmFilm" }, - { QtMultimedia::SceneCaptureType, "sceneCaptureType" }, - { QtMultimedia::GainControl, "gainControl" }, - { QtMultimedia::Contrast, "contrast" }, - { QtMultimedia::Saturation, "saturation" }, - { QtMultimedia::Sharpness, "sharpness" }, - { QtMultimedia::DeviceSettingDescription, "deviceSettingDescription" } + { QtMediaservices::CameraManufacturer, "cameraManufacturer" }, + { QtMediaservices::CameraModel, "cameraModel" }, + { QtMediaservices::Event, "event" }, + { QtMediaservices::Subject, "subject" }, + { QtMediaservices::Orientation, "orientation" }, + { QtMediaservices::ExposureTime, "exposureTime" }, + { QtMediaservices::FNumber, "fNumber" }, + { QtMediaservices::ExposureProgram, "exposureProgram" }, + { QtMediaservices::ISOSpeedRatings, "isoSpeedRatings" }, + { QtMediaservices::ExposureBiasValue, "exposureBiasValue" }, + { QtMediaservices::DateTimeOriginal, "dateTimeOriginal" }, + { QtMediaservices::DateTimeDigitized, "dateTimeDigitized" }, + { QtMediaservices::SubjectDistance, "subjectDistance" }, + { QtMediaservices::MeteringMode, "meteringMode" }, + { QtMediaservices::LightSource, "lightSource" }, + { QtMediaservices::Flash, "flash" }, + { QtMediaservices::FocalLength, "focalLength" }, + { QtMediaservices::ExposureMode, "exposureMode" }, + { QtMediaservices::WhiteBalance, "whiteBalance" }, + { QtMediaservices::DigitalZoomRatio, "digitalZoomRatio" }, + { QtMediaservices::FocalLengthIn35mmFilm, "focalLengthIn35mmFilm" }, + { QtMediaservices::SceneCaptureType, "sceneCaptureType" }, + { QtMediaservices::GainControl, "gainControl" }, + { QtMediaservices::Contrast, "contrast" }, + { QtMediaservices::Saturation, "saturation" }, + { QtMediaservices::Sharpness, "sharpness" }, + { QtMediaservices::DeviceSettingDescription, "deviceSettingDescription" } }; class QMetaDataControlObject : public QObject diff --git a/src/imports/multimedia/qmetadatacontrolmetaobject_p.h b/src/imports/multimedia/qmetadatacontrolmetaobject_p.h index c381f2d..128eaa4 100644 --- a/src/imports/multimedia/qmetadatacontrolmetaobject_p.h +++ b/src/imports/multimedia/qmetadatacontrolmetaobject_p.h @@ -54,7 +54,7 @@ // #include -#include +#include #include diff --git a/src/multimedia/audio/audio.pri b/src/multimedia/audio/audio.pri deleted file mode 100644 index ae28a26..0000000 --- a/src/multimedia/audio/audio.pri +++ /dev/null @@ -1,73 +0,0 @@ -HEADERS += $$PWD/qaudio.h \ - $$PWD/qaudioformat.h \ - $$PWD/qaudioinput.h \ - $$PWD/qaudiooutput.h \ - $$PWD/qaudiodeviceinfo.h \ - $$PWD/qaudioengineplugin.h \ - $$PWD/qaudioengine.h \ - $$PWD/qaudiodevicefactory_p.h - - -SOURCES += $$PWD/qaudio.cpp \ - $$PWD/qaudioformat.cpp \ - $$PWD/qaudiodeviceinfo.cpp \ - $$PWD/qaudiooutput.cpp \ - $$PWD/qaudioinput.cpp \ - $$PWD/qaudioengineplugin.cpp \ - $$PWD/qaudioengine.cpp \ - $$PWD/qaudiodevicefactory.cpp - -contains(QT_CONFIG, audio-backend) { - -mac { - HEADERS += $$PWD/qaudioinput_mac_p.h \ - $$PWD/qaudiooutput_mac_p.h \ - $$PWD/qaudiodeviceinfo_mac_p.h \ - $$PWD/qaudio_mac_p.h - - SOURCES += $$PWD/qaudiodeviceinfo_mac_p.cpp \ - $$PWD/qaudiooutput_mac_p.cpp \ - $$PWD/qaudioinput_mac_p.cpp \ - $$PWD/qaudio_mac.cpp - - LIBS += -framework ApplicationServices -framework CoreAudio -framework AudioUnit -framework AudioToolbox - -} else:win32 { - - HEADERS += $$PWD/qaudioinput_win32_p.h $$PWD/qaudiooutput_win32_p.h $$PWD/qaudiodeviceinfo_win32_p.h - SOURCES += $$PWD/qaudiodeviceinfo_win32_p.cpp \ - $$PWD/qaudiooutput_win32_p.cpp \ - $$PWD/qaudioinput_win32_p.cpp - !wince*:LIBS += -lwinmm - wince*:LIBS += -lcoredll - -} else:symbian { - INCLUDEPATH += /epoc32/include/mmf/common - INCLUDEPATH += /epoc32/include/mmf/server - - HEADERS += $$PWD/qaudio_symbian_p.h \ - $$PWD/qaudiodeviceinfo_symbian_p.h \ - $$PWD/qaudioinput_symbian_p.h \ - $$PWD/qaudiooutput_symbian_p.h - - SOURCES += $$PWD/qaudio_symbian_p.cpp \ - $$PWD/qaudiodeviceinfo_symbian_p.cpp \ - $$PWD/qaudioinput_symbian_p.cpp \ - $$PWD/qaudiooutput_symbian_p.cpp - - LIBS += -lmmfdevsound -} else:unix { - unix:contains(QT_CONFIG, alsa) { - linux-*|freebsd-*|openbsd-*:{ - DEFINES += HAS_ALSA - HEADERS += $$PWD/qaudiooutput_alsa_p.h $$PWD/qaudioinput_alsa_p.h $$PWD/qaudiodeviceinfo_alsa_p.h - SOURCES += $$PWD/qaudiodeviceinfo_alsa_p.cpp \ - $$PWD/qaudiooutput_alsa_p.cpp \ - $$PWD/qaudioinput_alsa_p.cpp - LIBS_PRIVATE += -lasound - } - } -} -} else { - DEFINES += QT_NO_AUDIO_BACKEND -} diff --git a/src/multimedia/audio/qaudio.cpp b/src/multimedia/audio/qaudio.cpp deleted file mode 100644 index e0f24ce..0000000 --- a/src/multimedia/audio/qaudio.cpp +++ /dev/null @@ -1,104 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtMultimedia module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - - -#include - - -QT_BEGIN_NAMESPACE - -namespace QAudio -{ - -class RegisterMetaTypes -{ -public: - RegisterMetaTypes() - { - qRegisterMetaType(); - qRegisterMetaType(); - qRegisterMetaType(); - } - -} _register; - -} - -/*! - \namespace QAudio - \brief The QAudio namespace contains enums used by the audio classes. - \inmodule QtMultimedia - \ingroup multimedia - \since 4.6 -*/ - -/*! - \enum QAudio::Error - - \value NoError No errors have occurred - \value OpenError An error opening the audio device - \value IOError An error occurred during read/write of audio device - \value UnderrunError Audio data is not being fed to the audio device at a fast enough rate - \value FatalError A non-recoverable error has occurred, the audio device is not usable at this time. -*/ - -/*! - \enum QAudio::State - - \value ActiveState Audio data is being processed, this state is set after start() is called - and while audio data is available to be processed. - \value SuspendedState The audio device is in a suspended state, this state will only be entered - after suspend() is called. - \value StoppedState The audio device is closed, not processing any audio data - \value IdleState The QIODevice passed in has no data and audio system's buffer is empty, this state - is set after start() is called and while no audio data is available to be processed. -*/ - -/*! - \enum QAudio::Mode - - \value AudioOutput audio output device - \value AudioInput audio input device -*/ - - -QT_END_NAMESPACE - diff --git a/src/multimedia/audio/qaudio.h b/src/multimedia/audio/qaudio.h deleted file mode 100644 index 9ca1dff..0000000 --- a/src/multimedia/audio/qaudio.h +++ /dev/null @@ -1,71 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtMultimedia module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - - -#ifndef QAUDIO_H -#define QAUDIO_H - - -#include -#include - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Multimedia) - -namespace QAudio -{ - enum Error { NoError, OpenError, IOError, UnderrunError, FatalError }; - enum State { ActiveState, SuspendedState, StoppedState, IdleState }; - enum Mode { AudioInput, AudioOutput }; -} - -QT_END_NAMESPACE - -QT_END_HEADER - -Q_DECLARE_METATYPE(QAudio::Error) -Q_DECLARE_METATYPE(QAudio::State) -Q_DECLARE_METATYPE(QAudio::Mode) - -#endif // QAUDIO_H diff --git a/src/multimedia/audio/qaudio_mac.cpp b/src/multimedia/audio/qaudio_mac.cpp deleted file mode 100644 index 14fee8b..0000000 --- a/src/multimedia/audio/qaudio_mac.cpp +++ /dev/null @@ -1,142 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtMultimedia module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - - -#include "qaudio_mac_p.h" - -QT_BEGIN_NAMESPACE - -// Debugging -QDebug operator<<(QDebug dbg, const QAudioFormat& audioFormat) -{ - dbg.nospace() << "QAudioFormat(" << - audioFormat.frequency() << "," << - audioFormat.channels() << "," << - audioFormat.sampleSize()<< "," << - audioFormat.codec() << "," << - audioFormat.byteOrder() << "," << - audioFormat.sampleType() << ")"; - - return dbg.space(); -} - - -// Conversion -QAudioFormat toQAudioFormat(AudioStreamBasicDescription const& sf) -{ - QAudioFormat audioFormat; - - audioFormat.setFrequency(sf.mSampleRate); - audioFormat.setChannels(sf.mChannelsPerFrame); - audioFormat.setSampleSize(sf.mBitsPerChannel); - audioFormat.setCodec(QString::fromLatin1("audio/pcm")); - audioFormat.setByteOrder(sf.mFormatFlags & kLinearPCMFormatFlagIsBigEndian != 0 ? QAudioFormat::BigEndian : QAudioFormat::LittleEndian); - QAudioFormat::SampleType type = QAudioFormat::UnSignedInt; - if ((sf.mFormatFlags & kLinearPCMFormatFlagIsSignedInteger) != 0) - type = QAudioFormat::SignedInt; - else if ((sf.mFormatFlags & kLinearPCMFormatFlagIsFloat) != 0) - type = QAudioFormat::Float; - audioFormat.setSampleType(type); - - return audioFormat; -} - -AudioStreamBasicDescription toAudioStreamBasicDescription(QAudioFormat const& audioFormat) -{ - AudioStreamBasicDescription sf; - - sf.mFormatFlags = kAudioFormatFlagIsPacked; - sf.mSampleRate = audioFormat.frequency(); - sf.mFramesPerPacket = 1; - sf.mChannelsPerFrame = audioFormat.channels(); - sf.mBitsPerChannel = audioFormat.sampleSize(); - sf.mBytesPerFrame = sf.mChannelsPerFrame * (sf.mBitsPerChannel / 8); - sf.mBytesPerPacket = sf.mFramesPerPacket * sf.mBytesPerFrame; - sf.mFormatID = kAudioFormatLinearPCM; - - switch (audioFormat.sampleType()) { - case QAudioFormat::SignedInt: sf.mFormatFlags |= kAudioFormatFlagIsSignedInteger; break; - case QAudioFormat::UnSignedInt: /* default */ break; - case QAudioFormat::Float: sf.mFormatFlags |= kAudioFormatFlagIsFloat; break; - case QAudioFormat::Unknown: default: break; - } - - return sf; -} - -// QAudioRingBuffer -QAudioRingBuffer::QAudioRingBuffer(int bufferSize): - m_bufferSize(bufferSize) -{ - m_buffer = new char[m_bufferSize]; - reset(); -} - -QAudioRingBuffer::~QAudioRingBuffer() -{ - delete m_buffer; -} - -int QAudioRingBuffer::used() const -{ - return m_bufferUsed; -} - -int QAudioRingBuffer::free() const -{ - return m_bufferSize - m_bufferUsed; -} - -int QAudioRingBuffer::size() const -{ - return m_bufferSize; -} - -void QAudioRingBuffer::reset() -{ - m_readPos = 0; - m_writePos = 0; - m_bufferUsed = 0; -} - -QT_END_NAMESPACE - - diff --git a/src/multimedia/audio/qaudio_mac_p.h b/src/multimedia/audio/qaudio_mac_p.h deleted file mode 100644 index 4e7d688..0000000 --- a/src/multimedia/audio/qaudio_mac_p.h +++ /dev/null @@ -1,144 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtMultimedia module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -// -// W A R N I N G -// ------------- -// -// This file is not part of the Qt API. It exists for the convenience -// of other Qt classes. This header file may change from version to -// version without notice, or even be removed. -// -// We mean it. -// - - -#ifndef QAUDIO_MAC_P_H -#define QAUDIO_MAC_P_H - -#include - -#include -#include - -#include - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Multimedia) - - -extern QDebug operator<<(QDebug dbg, const QAudioFormat& audioFormat); - -extern QAudioFormat toQAudioFormat(const AudioStreamBasicDescription& streamFormat); -extern AudioStreamBasicDescription toAudioStreamBasicDescription(QAudioFormat const& audioFormat); - -class QAudioRingBuffer -{ -public: - typedef QPair Region; - - QAudioRingBuffer(int bufferSize); - ~QAudioRingBuffer(); - - Region acquireReadRegion(int size) - { - const int used = m_bufferUsed.fetchAndAddAcquire(0); - - if (used > 0) { - const int readSize = qMin(size, qMin(m_bufferSize - m_readPos, used)); - - return readSize > 0 ? Region(m_buffer + m_readPos, readSize) : Region(0, 0); - } - - return Region(0, 0); - } - - void releaseReadRegion(Region const& region) - { - m_readPos = (m_readPos + region.second) % m_bufferSize; - - m_bufferUsed.fetchAndAddRelease(-region.second); - } - - Region acquireWriteRegion(int size) - { - const int free = m_bufferSize - m_bufferUsed.fetchAndAddAcquire(0); - - if (free > 0) { - const int writeSize = qMin(size, qMin(m_bufferSize - m_writePos, free)); - - return writeSize > 0 ? Region(m_buffer + m_writePos, writeSize) : Region(0, 0); - } - - return Region(0, 0); - } - - void releaseWriteRegion(Region const& region) - { - m_writePos = (m_writePos + region.second) % m_bufferSize; - - m_bufferUsed.fetchAndAddRelease(region.second); - } - - int used() const; - int free() const; - int size() const; - - void reset(); - -private: - int m_bufferSize; - int m_readPos; - int m_writePos; - char* m_buffer; - QAtomicInt m_bufferUsed; -}; - -QT_END_NAMESPACE - -QT_END_HEADER - -#endif // QAUDIO_MAC_P_H - - diff --git a/src/multimedia/audio/qaudio_symbian_p.cpp b/src/multimedia/audio/qaudio_symbian_p.cpp deleted file mode 100644 index 58e3745..0000000 --- a/src/multimedia/audio/qaudio_symbian_p.cpp +++ /dev/null @@ -1,395 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtMultimedia module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qaudio_symbian_p.h" -#include - -QT_BEGIN_NAMESPACE - -namespace SymbianAudio { - -DevSoundCapabilities::DevSoundCapabilities(CMMFDevSound &devsound, - QAudio::Mode mode) -{ - QT_TRAP_THROWING(constructL(devsound, mode)); -} - -DevSoundCapabilities::~DevSoundCapabilities() -{ - m_fourCC.Close(); -} - -void DevSoundCapabilities::constructL(CMMFDevSound &devsound, - QAudio::Mode mode) -{ - m_caps = devsound.Capabilities(); - - TMMFPrioritySettings settings; - - switch (mode) { - case QAudio::AudioOutput: - settings.iState = EMMFStatePlaying; - devsound.GetSupportedInputDataTypesL(m_fourCC, settings); - break; - - case QAudio::AudioInput: - settings.iState = EMMFStateRecording; - devsound.GetSupportedInputDataTypesL(m_fourCC, settings); - break; - - default: - Q_ASSERT_X(false, Q_FUNC_INFO, "Invalid mode"); - } -} - -namespace Utils { - -//----------------------------------------------------------------------------- -// Static data -//----------------------------------------------------------------------------- - -// Sample rate / frequency - -typedef TMMFSampleRate SampleRateNative; -typedef int SampleRateQt; - -const int SampleRateCount = 12; - -const SampleRateNative SampleRateListNative[SampleRateCount] = { - EMMFSampleRate8000Hz - , EMMFSampleRate11025Hz - , EMMFSampleRate12000Hz - , EMMFSampleRate16000Hz - , EMMFSampleRate22050Hz - , EMMFSampleRate24000Hz - , EMMFSampleRate32000Hz - , EMMFSampleRate44100Hz - , EMMFSampleRate48000Hz - , EMMFSampleRate64000Hz - , EMMFSampleRate88200Hz - , EMMFSampleRate96000Hz -}; - -const SampleRateQt SampleRateListQt[SampleRateCount] = { - 8000 - , 11025 - , 12000 - , 16000 - , 22050 - , 24000 - , 32000 - , 44100 - , 48000 - , 64000 - , 88200 - , 96000 -}; - -// Channels - -typedef TMMFMonoStereo ChannelsNative; -typedef int ChannelsQt; - -const int ChannelsCount = 2; - -const ChannelsNative ChannelsListNative[ChannelsCount] = { - EMMFMono - , EMMFStereo -}; - -const ChannelsQt ChannelsListQt[ChannelsCount] = { - 1 - , 2 -}; - -// Encoding - -const int EncodingCount = 6; - -const TUint32 EncodingFourCC[EncodingCount] = { - KMMFFourCCCodePCM8 // 0 - , KMMFFourCCCodePCMU8 // 1 - , KMMFFourCCCodePCM16 // 2 - , KMMFFourCCCodePCMU16 // 3 - , KMMFFourCCCodePCM16B // 4 - , KMMFFourCCCodePCMU16B // 5 -}; - -// The characterised DevSound API specification states that the iEncoding -// field in TMMFCapabilities is ignored, and that the FourCC should be used -// to specify the PCM encoding. -// See "SGL.GT0287.102 Multimedia DevSound Baseline Compatibility.doc" in the -// mm_info/mm_docs repository. -const TMMFSoundEncoding EncodingNative[EncodingCount] = { - EMMFSoundEncoding16BitPCM // 0 - , EMMFSoundEncoding16BitPCM // 1 - , EMMFSoundEncoding16BitPCM // 2 - , EMMFSoundEncoding16BitPCM // 3 - , EMMFSoundEncoding16BitPCM // 4 - , EMMFSoundEncoding16BitPCM // 5 -}; - - -const int EncodingSampleSize[EncodingCount] = { - 8 // 0 - , 8 // 1 - , 16 // 2 - , 16 // 3 - , 16 // 4 - , 16 // 5 -}; - -const QAudioFormat::Endian EncodingByteOrder[EncodingCount] = { - QAudioFormat::LittleEndian // 0 - , QAudioFormat::LittleEndian // 1 - , QAudioFormat::LittleEndian // 2 - , QAudioFormat::LittleEndian // 3 - , QAudioFormat::BigEndian // 4 - , QAudioFormat::BigEndian // 5 -}; - -const QAudioFormat::SampleType EncodingSampleType[EncodingCount] = { - QAudioFormat::SignedInt // 0 - , QAudioFormat::UnSignedInt // 1 - , QAudioFormat::SignedInt // 2 - , QAudioFormat::UnSignedInt // 3 - , QAudioFormat::SignedInt // 4 - , QAudioFormat::UnSignedInt // 5 -}; - - -//----------------------------------------------------------------------------- -// Private functions -//----------------------------------------------------------------------------- - -// Helper functions for implementing parameter conversions - -template -bool findValue(const Input *inputArray, int length, Input input, int &index) { - bool result = false; - for (int i=0; !result && i -bool convertValue(const Input *inputArray, const Output *outputArray, - int length, Input input, Output &output) { - int index; - const bool result = findValue(inputArray, length, input, index); - if (result) - output = outputArray[index]; - return result; -} - -/** - * Macro which is used to generate the implementation of the conversion - * functions. The implementation is just a wrapper around the templated - * convertValue function, e.g. - * - * CONVERSION_FUNCTION_IMPL(SampleRate, Qt, Native) - * - * expands to - * - * bool SampleRateQtToNative(int input, TMMFSampleRate &output) { - * return convertValue - * (SampleRateListQt, SampleRateListNative, SampleRateCount, - * input, output); - * } - */ -#define CONVERSION_FUNCTION_IMPL(FieldLc, Field, Input, Output) \ -bool FieldLc##Input##To##Output(Field##Input input, Field##Output &output) { \ - return convertValue(Field##List##Input, \ - Field##List##Output, Field##Count, input, output); \ -} - -//----------------------------------------------------------------------------- -// Local helper functions -//----------------------------------------------------------------------------- - -CONVERSION_FUNCTION_IMPL(sampleRate, SampleRate, Qt, Native) -CONVERSION_FUNCTION_IMPL(sampleRate, SampleRate, Native, Qt) -CONVERSION_FUNCTION_IMPL(channels, Channels, Qt, Native) -CONVERSION_FUNCTION_IMPL(channels, Channels, Native, Qt) - -bool sampleInfoQtToNative(int inputSampleSize, - QAudioFormat::Endian inputByteOrder, - QAudioFormat::SampleType inputSampleType, - TUint32 &outputFourCC, - TMMFSoundEncoding &outputEncoding) { - - bool found = false; - - for (int i=0; i &frequencies, - QList &channels, - QList &sampleSizes, - QList &byteOrders, - QList &sampleTypes) { - - frequencies.clear(); - sampleSizes.clear(); - byteOrders.clear(); - sampleTypes.clear(); - channels.clear(); - - for (int i=0; i -#include -#include -#include - -QT_BEGIN_NAMESPACE - -namespace SymbianAudio { - -/** - * Default values used by audio input and output classes, when underlying - * DevSound instance has not yet been created. - */ - -const int DefaultBufferSize = 4096; // bytes -const int DefaultNotifyInterval = 1000; // ms - -/** - * Enumeration used to track state of internal DevSound instances. - * Values are translated to the corresponding QAudio::State values by - * SymbianAudio::Utils::stateNativeToQt. - */ -enum State { - ClosedState - , InitializingState - , ActiveState - , IdleState - , SuspendedState -}; - -/* - * Helper class for querying DevSound codec / format support - */ -class DevSoundCapabilities { -public: - DevSoundCapabilities(CMMFDevSound &devsound, QAudio::Mode mode); - ~DevSoundCapabilities(); - - const RArray& fourCC() const { return m_fourCC; } - const TMMFCapabilities& caps() const { return m_caps; } - -private: - void constructL(CMMFDevSound &devsound, QAudio::Mode mode); - -private: - RArray m_fourCC; - TMMFCapabilities m_caps; -}; - -namespace Utils { - -/** - * Convert native audio capabilities to QAudio lists. - */ -void capabilitiesNativeToQt(const DevSoundCapabilities &caps, - QList &frequencies, - QList &channels, - QList &sampleSizes, - QList &byteOrders, - QList &sampleTypes); - -/** - * Check whether format is supported. - */ -bool isFormatSupported(const QAudioFormat &format, - const DevSoundCapabilities &caps); - -/** - * Convert QAudioFormat to native format types. - * - * Note that, despite the name, DevSound uses TMMFCapabilities to specify - * single formats as well as capabilities. - * - * Note that this function does not modify outputFormat.iBufferSize. - */ -bool formatQtToNative(const QAudioFormat &inputFormat, - TUint32 &outputFourCC, - TMMFCapabilities &outputFormat); - -/** - * Convert internal states to QAudio states. - */ -QAudio::State stateNativeToQt(State nativeState, - QAudio::State initializingState); - -/** - * Convert data length to number of samples. - */ -qint64 bytesToSamples(const QAudioFormat &format, qint64 length); - -/** - * Convert number of samples to data length. - */ -qint64 samplesToBytes(const QAudioFormat &format, qint64 samples); - -} // namespace Utils -} // namespace SymbianAudio - -QT_END_NAMESPACE - -#endif diff --git a/src/multimedia/audio/qaudiodevicefactory.cpp b/src/multimedia/audio/qaudiodevicefactory.cpp deleted file mode 100644 index 4f45110..0000000 --- a/src/multimedia/audio/qaudiodevicefactory.cpp +++ /dev/null @@ -1,257 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtMultimedia module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include -#include -#include -#include -#include "qaudiodevicefactory_p.h" - -#ifndef QT_NO_AUDIO_BACKEND -#if defined(Q_OS_WIN) -#include "qaudiodeviceinfo_win32_p.h" -#include "qaudiooutput_win32_p.h" -#include "qaudioinput_win32_p.h" -#elif defined(Q_OS_MAC) -#include "qaudiodeviceinfo_mac_p.h" -#include "qaudiooutput_mac_p.h" -#include "qaudioinput_mac_p.h" -#elif defined(HAS_ALSA) -#include "qaudiodeviceinfo_alsa_p.h" -#include "qaudiooutput_alsa_p.h" -#include "qaudioinput_alsa_p.h" -#elif defined(Q_OS_SYMBIAN) -#include "qaudiodeviceinfo_symbian_p.h" -#include "qaudiooutput_symbian_p.h" -#include "qaudioinput_symbian_p.h" -#endif -#endif - -QT_BEGIN_NAMESPACE - -Q_GLOBAL_STATIC_WITH_ARGS(QFactoryLoader, loader, - (QAudioEngineFactoryInterface_iid, QLatin1String("/audio"), Qt::CaseInsensitive)) - - -class QNullDeviceInfo : public QAbstractAudioDeviceInfo -{ -public: - QAudioFormat preferredFormat() const { qWarning()<<"using null deviceinfo, none available"; return QAudioFormat(); } - bool isFormatSupported(const QAudioFormat& ) const { return false; } - QAudioFormat nearestFormat(const QAudioFormat& ) const { return QAudioFormat(); } - QString deviceName() const { return QString(); } - QStringList codecList() { return QStringList(); } - QList frequencyList() { return QList(); } - QList channelsList() { return QList(); } - QList sampleSizeList() { return QList(); } - QList byteOrderList() { return QList(); } - QList sampleTypeList() { return QList(); } -}; - -class QNullInputDevice : public QAbstractAudioInput -{ -public: - QIODevice* start(QIODevice* ) { qWarning()<<"using null input device, none available"; return 0; } - void stop() {} - void reset() {} - void suspend() {} - void resume() {} - int bytesReady() const { return 0; } - int periodSize() const { return 0; } - void setBufferSize(int ) {} - int bufferSize() const { return 0; } - void setNotifyInterval(int ) {} - int notifyInterval() const { return 0; } - qint64 processedUSecs() const { return 0; } - qint64 elapsedUSecs() const { return 0; } - QAudio::Error error() const { return QAudio::OpenError; } - QAudio::State state() const { return QAudio::StoppedState; } - QAudioFormat format() const { return QAudioFormat(); } -}; - -class QNullOutputDevice : public QAbstractAudioOutput -{ -public: - QIODevice* start(QIODevice* ) { qWarning()<<"using null output device, none available"; return 0; } - void stop() {} - void reset() {} - void suspend() {} - void resume() {} - int bytesFree() const { return 0; } - int periodSize() const { return 0; } - void setBufferSize(int ) {} - int bufferSize() const { return 0; } - void setNotifyInterval(int ) {} - int notifyInterval() const { return 0; } - qint64 processedUSecs() const { return 0; } - qint64 elapsedUSecs() const { return 0; } - QAudio::Error error() const { return QAudio::OpenError; } - QAudio::State state() const { return QAudio::StoppedState; } - QAudioFormat format() const { return QAudioFormat(); } -}; - -QList QAudioDeviceFactory::availableDevices(QAudio::Mode mode) -{ - QList devices; -#ifndef QT_NO_AUDIO_BACKEND -#if (defined(Q_OS_WIN) || defined(Q_OS_MAC) || defined(HAS_ALSA) || defined(Q_OS_SYMBIAN)) - foreach (const QByteArray &handle, QAudioDeviceInfoInternal::availableDevices(mode)) - devices << QAudioDeviceInfo(QLatin1String("builtin"), handle, mode); -#endif -#endif - QFactoryLoader* l = loader(); - - foreach (QString const& key, l->keys()) { - QAudioEngineFactoryInterface* plugin = qobject_cast(l->instance(key)); - if (plugin) { - foreach (QByteArray const& handle, plugin->availableDevices(mode)) - devices << QAudioDeviceInfo(key, handle, mode); - } - - delete plugin; - } - - return devices; -} - -QAudioDeviceInfo QAudioDeviceFactory::defaultInputDevice() -{ - QAudioEngineFactoryInterface* plugin = qobject_cast(loader()->instance(QLatin1String("default"))); - - if (plugin) { - QList list = plugin->availableDevices(QAudio::AudioInput); - if (list.size() > 0) - return QAudioDeviceInfo(QLatin1String("default"), list.at(0), QAudio::AudioInput); - } -#ifndef QT_NO_AUDIO_BACKEND -#if (defined(Q_OS_WIN) || defined(Q_OS_MAC) || defined(HAS_ALSA) || defined(Q_OS_SYMBIAN)) - return QAudioDeviceInfo(QLatin1String("builtin"), QAudioDeviceInfoInternal::defaultInputDevice(), QAudio::AudioInput); -#endif -#endif - return QAudioDeviceInfo(); -} - -QAudioDeviceInfo QAudioDeviceFactory::defaultOutputDevice() -{ - QAudioEngineFactoryInterface* plugin = qobject_cast(loader()->instance(QLatin1String("default"))); - - if (plugin) { - QList list = plugin->availableDevices(QAudio::AudioOutput); - if (list.size() > 0) - return QAudioDeviceInfo(QLatin1String("default"), list.at(0), QAudio::AudioOutput); - } -#ifndef QT_NO_AUDIO_BACKEND -#if (defined(Q_OS_WIN) || defined(Q_OS_MAC) || defined(HAS_ALSA) || defined(Q_OS_SYMBIAN)) - return QAudioDeviceInfo(QLatin1String("builtin"), QAudioDeviceInfoInternal::defaultOutputDevice(), QAudio::AudioOutput); -#endif -#endif - return QAudioDeviceInfo(); -} - -QAbstractAudioDeviceInfo* QAudioDeviceFactory::audioDeviceInfo(const QString &realm, const QByteArray &handle, QAudio::Mode mode) -{ - QAbstractAudioDeviceInfo *rc = 0; - -#ifndef QT_NO_AUDIO_BACKEND -#if (defined(Q_OS_WIN) || defined(Q_OS_MAC) || defined(HAS_ALSA) || defined(Q_OS_SYMBIAN)) - if (realm == QLatin1String("builtin")) - return new QAudioDeviceInfoInternal(handle, mode); -#endif -#endif - QAudioEngineFactoryInterface* plugin = - qobject_cast(loader()->instance(realm)); - - if (plugin) - rc = plugin->createDeviceInfo(handle, mode); - - return rc == 0 ? new QNullDeviceInfo() : rc; -} - -QAbstractAudioInput* QAudioDeviceFactory::createDefaultInputDevice(QAudioFormat const &format) -{ - return createInputDevice(defaultInputDevice(), format); -} - -QAbstractAudioOutput* QAudioDeviceFactory::createDefaultOutputDevice(QAudioFormat const &format) -{ - return createOutputDevice(defaultOutputDevice(), format); -} - -QAbstractAudioInput* QAudioDeviceFactory::createInputDevice(QAudioDeviceInfo const& deviceInfo, QAudioFormat const &format) -{ - if (deviceInfo.isNull()) - return new QNullInputDevice(); -#ifndef QT_NO_AUDIO_BACKEND -#if (defined(Q_OS_WIN) || defined(Q_OS_MAC) || defined(HAS_ALSA) || defined(Q_OS_SYMBIAN)) - if (deviceInfo.realm() == QLatin1String("builtin")) - return new QAudioInputPrivate(deviceInfo.handle(), format); -#endif -#endif - QAudioEngineFactoryInterface* plugin = - qobject_cast(loader()->instance(deviceInfo.realm())); - - if (plugin) - return plugin->createInput(deviceInfo.handle(), format); - - return new QNullInputDevice(); -} - -QAbstractAudioOutput* QAudioDeviceFactory::createOutputDevice(QAudioDeviceInfo const& deviceInfo, QAudioFormat const &format) -{ - if (deviceInfo.isNull()) - return new QNullOutputDevice(); -#ifndef QT_NO_AUDIO_BACKEND -#if (defined(Q_OS_WIN) || defined(Q_OS_MAC) || defined(HAS_ALSA) || defined(Q_OS_SYMBIAN)) - if (deviceInfo.realm() == QLatin1String("builtin")) - return new QAudioOutputPrivate(deviceInfo.handle(), format); -#endif -#endif - QAudioEngineFactoryInterface* plugin = - qobject_cast(loader()->instance(deviceInfo.realm())); - - if (plugin) - return plugin->createOutput(deviceInfo.handle(), format); - - return new QNullOutputDevice(); -} - -QT_END_NAMESPACE - diff --git a/src/multimedia/audio/qaudiodevicefactory_p.h b/src/multimedia/audio/qaudiodevicefactory_p.h deleted file mode 100644 index 8ee8b05..0000000 --- a/src/multimedia/audio/qaudiodevicefactory_p.h +++ /dev/null @@ -1,97 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtMultimedia module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -// -// W A R N I N G -// ------------- -// -// This file is not part of the Qt API. It exists for the convenience -// of other Qt classes. This header file may change from version to -// version without notice, or even be removed. -// -// We mean it. -// - -#ifndef QAUDIODEVICEFACTORY_P_H -#define QAUDIODEVICEFACTORY_P_H - -#include -#include -#include - -#include - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Multimedia) - -class QAbstractAudioInput; -class QAbstractAudioOutput; -class QAbstractAudioDeviceInfo; - -class QAudioDeviceFactory -{ -public: - static QList availableDevices(QAudio::Mode mode); - - static QAudioDeviceInfo defaultInputDevice(); - static QAudioDeviceInfo defaultOutputDevice(); - - static QAbstractAudioDeviceInfo* audioDeviceInfo(const QString &realm, const QByteArray &handle, QAudio::Mode mode); - - static QAbstractAudioInput* createDefaultInputDevice(QAudioFormat const &format); - static QAbstractAudioOutput* createDefaultOutputDevice(QAudioFormat const &format); - - static QAbstractAudioInput* createInputDevice(QAudioDeviceInfo const &device, QAudioFormat const &format); - static QAbstractAudioOutput* createOutputDevice(QAudioDeviceInfo const &device, QAudioFormat const &format); - - static QAbstractAudioInput* createNullInput(); - static QAbstractAudioOutput* createNullOutput(); -}; - -QT_END_NAMESPACE - -QT_END_HEADER - -#endif // QAUDIODEVICEFACTORY_P_H - diff --git a/src/multimedia/audio/qaudiodeviceinfo.cpp b/src/multimedia/audio/qaudiodeviceinfo.cpp deleted file mode 100644 index ff04b4e..0000000 --- a/src/multimedia/audio/qaudiodeviceinfo.cpp +++ /dev/null @@ -1,400 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtMultimedia module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qaudiodevicefactory_p.h" -#include -#include - - -QT_BEGIN_NAMESPACE - -class QAudioDeviceInfoPrivate : public QSharedData -{ -public: - QAudioDeviceInfoPrivate():info(0) {} - QAudioDeviceInfoPrivate(const QString &r, const QByteArray &h, QAudio::Mode m): - realm(r), handle(h), mode(m) - { - info = QAudioDeviceFactory::audioDeviceInfo(realm, handle, mode); - } - - QAudioDeviceInfoPrivate(const QAudioDeviceInfoPrivate &other): - QSharedData(other), - realm(other.realm), handle(other.handle), mode(other.mode) - { - info = QAudioDeviceFactory::audioDeviceInfo(realm, handle, mode); - } - - QAudioDeviceInfoPrivate& operator=(const QAudioDeviceInfoPrivate &other) - { - delete info; - - realm = other.realm; - handle = other.handle; - mode = other.mode; - info = QAudioDeviceFactory::audioDeviceInfo(realm, handle, mode); - return *this; - } - - ~QAudioDeviceInfoPrivate() - { - delete info; - } - - QString realm; - QByteArray handle; - QAudio::Mode mode; - QAbstractAudioDeviceInfo* info; -}; - - -/*! - \class QAudioDeviceInfo - \brief The QAudioDeviceInfo class provides an interface to query audio devices and their functionality. - \inmodule QtMultimedia - \ingroup multimedia - - \since 4.6 - - QAudioDeviceInfo lets you query for audio devices--such as sound - cards and USB headsets--that are currently available on the system. - The audio devices available are dependent on the platform or audio plugins installed. - - You can also query each device for the formats it supports. A - format in this context is a set consisting of a specific byte - order, channel, codec, frequency, sample rate, and sample type. A - format is represented by the QAudioFormat class. - - The values supported by the the device for each of these - parameters can be fetched with - supportedByteOrders(), supportedChannelCounts(), supportedCodecs(), - supportedSampleRates(), supportedSampleSizes(), and - supportedSampleTypes(). The combinations supported are dependent on the platform, - audio plugins installed and the audio device capabilities. If you need a specific format, you can check if - the device supports it with isFormatSupported(), or fetch a - supported format that is as close as possible to the format with - nearestFormat(). For instance: - - \snippet doc/src/snippets/audio/main.cpp 1 - \dots 8 - \snippet doc/src/snippets/audio/main.cpp 2 - - A QAudioDeviceInfo is used by Qt to construct - classes that communicate with the device--such as - QAudioInput, and QAudioOutput. The static - functions defaultInputDevice(), defaultOutputDevice(), and - availableDevices() let you get a list of all available - devices. Devices are fetch according to the value of mode - this is specified by the QAudio::Mode enum. - The QAudioDeviceInfo returned are only valid for the QAudio::Mode. - - For instance: - - \code - foreach(const QAudioDeviceInfo &deviceInfo, QAudioDeviceInfo::availableDevices(QAudio::AudioOutput)) - qDebug() << "Device name: " << deviceInfo.deviceName(); - \endcode - - In this code sample, we loop through all devices that are able to output - sound, i.e., play an audio stream in a supported format. For each device we - find, we simply print the deviceName(). - - \sa QAudioOutput, QAudioInput -*/ - -/*! - Constructs an empty QAudioDeviceInfo object. -*/ - -QAudioDeviceInfo::QAudioDeviceInfo(): - d(new QAudioDeviceInfoPrivate) -{ -} - -/*! - Constructs a copy of \a other. -*/ - -QAudioDeviceInfo::QAudioDeviceInfo(const QAudioDeviceInfo& other): - d(other.d) -{ -} - -/*! - Destroy this audio device info. -*/ - -QAudioDeviceInfo::~QAudioDeviceInfo() -{ -} - -/*! - Sets the QAudioDeviceInfo object to be equal to \a other. -*/ - -QAudioDeviceInfo& QAudioDeviceInfo::operator=(const QAudioDeviceInfo &other) -{ - d = other.d; - return *this; -} - -/*! - Returns whether this QAudioDeviceInfo object holds a device definition. -*/ - -bool QAudioDeviceInfo::isNull() const -{ - return d->info == 0; -} - -/*! - Returns human readable name of audio device. - - Device names vary depending on platform/audio plugin being used. - - They are a unique string identifiers for the audio device. - - eg. default, Intel, U0x46d0x9a4 -*/ - -QString QAudioDeviceInfo::deviceName() const -{ - return isNull() ? QString() : d->info->deviceName(); -} - -/*! - Returns true if \a settings are supported by the audio device of this QAudioDeviceInfo. -*/ - -bool QAudioDeviceInfo::isFormatSupported(const QAudioFormat &settings) const -{ - return isNull() ? false : d->info->isFormatSupported(settings); -} - -/*! - Returns QAudioFormat of default settings. - - These settings are provided by the platform/audio plugin being used. - - They also are dependent on the QAudio::Mode being used. - - A typical audio system would provide something like: - \list - \o Input settings: 8000Hz mono 8 bit. - \o Output settings: 44100Hz stereo 16 bit little endian. - \endlist -*/ - -QAudioFormat QAudioDeviceInfo::preferredFormat() const -{ - return isNull() ? QAudioFormat() : d->info->preferredFormat(); -} - -/*! - Returns closest QAudioFormat to \a settings that system audio supports. - - These settings are provided by the platform/audio plugin being used. - - They also are dependent on the QAudio::Mode being used. -*/ - -QAudioFormat QAudioDeviceInfo::nearestFormat(const QAudioFormat &settings) const -{ - return isNull() ? QAudioFormat() : d->info->nearestFormat(settings); -} - -/*! - Returns a list of supported codecs. - - All platform and plugin implementations should provide support for: - - "audio/pcm" - Linear PCM - - For writing plugins to support additional codecs refer to: - - http://www.iana.org/assignments/media-types/audio/ -*/ - -QStringList QAudioDeviceInfo::supportedCodecs() const -{ - return isNull() ? QStringList() : d->info->codecList(); -} - -/*! - Returns a list of supported sample rates. - - \since 4.7 -*/ - -QList QAudioDeviceInfo::supportedSampleRates() const -{ - return supportedFrequencies(); -} - -/*! - \obsolete - - Use supportedSampleRates() instead. -*/ - -QList QAudioDeviceInfo::supportedFrequencies() const -{ - return isNull() ? QList() : d->info->frequencyList(); -} - -/*! - Returns a list of supported channel counts. - - \since 4.7 -*/ - -QList QAudioDeviceInfo::supportedChannelCounts() const -{ - return supportedChannels(); -} - -/*! - \obsolete - - Use supportedChannelCount() instead. -*/ - -QList QAudioDeviceInfo::supportedChannels() const -{ - return isNull() ? QList() : d->info->channelsList(); -} - -/*! - Returns a list of supported sample sizes. -*/ - -QList QAudioDeviceInfo::supportedSampleSizes() const -{ - return isNull() ? QList() : d->info->sampleSizeList(); -} - -/*! - Returns a list of supported byte orders. -*/ - -QList QAudioDeviceInfo::supportedByteOrders() const -{ - return isNull() ? QList() : d->info->byteOrderList(); -} - -/*! - Returns a list of supported sample types. -*/ - -QList QAudioDeviceInfo::supportedSampleTypes() const -{ - return isNull() ? QList() : d->info->sampleTypeList(); -} - -/*! - Returns the name of the default input audio device. - All platform and audio plugin implementations provide a default audio device to use. -*/ - -QAudioDeviceInfo QAudioDeviceInfo::defaultInputDevice() -{ - return QAudioDeviceFactory::defaultInputDevice(); -} - -/*! - Returns the name of the default output audio device. - All platform and audio plugin implementations provide a default audio device to use. -*/ - -QAudioDeviceInfo QAudioDeviceInfo::defaultOutputDevice() -{ - return QAudioDeviceFactory::defaultOutputDevice(); -} - -/*! - Returns a list of audio devices that support \a mode. -*/ - -QList QAudioDeviceInfo::availableDevices(QAudio::Mode mode) -{ - return QAudioDeviceFactory::availableDevices(mode); -} - - -/*! - \internal -*/ - -QAudioDeviceInfo::QAudioDeviceInfo(const QString &realm, const QByteArray &handle, QAudio::Mode mode): - d(new QAudioDeviceInfoPrivate(realm, handle, mode)) -{ -} - -/*! - \internal -*/ - -QString QAudioDeviceInfo::realm() const -{ - return d->realm; -} - -/*! - \internal -*/ - -QByteArray QAudioDeviceInfo::handle() const -{ - return d->handle; -} - - -/*! - \internal -*/ - -QAudio::Mode QAudioDeviceInfo::mode() const -{ - return d->mode; -} - -QT_END_NAMESPACE - diff --git a/src/multimedia/audio/qaudiodeviceinfo.h b/src/multimedia/audio/qaudiodeviceinfo.h deleted file mode 100644 index 1cc0731..0000000 --- a/src/multimedia/audio/qaudiodeviceinfo.h +++ /dev/null @@ -1,114 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtMultimedia module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - - -#ifndef QAUDIODEVICEINFO_H -#define QAUDIODEVICEINFO_H - -#include -#include -#include -#include -#include -#include - -#include -#include - - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Multimedia) - -class QAudioDeviceFactory; - -class QAudioDeviceInfoPrivate; -class Q_MULTIMEDIA_EXPORT QAudioDeviceInfo -{ - friend class QAudioDeviceFactory; - -public: - QAudioDeviceInfo(); - QAudioDeviceInfo(const QAudioDeviceInfo& other); - ~QAudioDeviceInfo(); - - QAudioDeviceInfo& operator=(const QAudioDeviceInfo& other); - - bool isNull() const; - - QString deviceName() const; - - bool isFormatSupported(const QAudioFormat &format) const; - QAudioFormat preferredFormat() const; - QAudioFormat nearestFormat(const QAudioFormat &format) const; - - QStringList supportedCodecs() const; - QList supportedFrequencies() const; - QList supportedSampleRates() const; - QList supportedChannels() const; - QList supportedChannelCounts() const; - QList supportedSampleSizes() const; - QList supportedByteOrders() const; - QList supportedSampleTypes() const; - - static QAudioDeviceInfo defaultInputDevice(); - static QAudioDeviceInfo defaultOutputDevice(); - - static QList availableDevices(QAudio::Mode mode); - -private: - QAudioDeviceInfo(const QString &realm, const QByteArray &handle, QAudio::Mode mode); - QString realm() const; - QByteArray handle() const; - QAudio::Mode mode() const; - - QSharedDataPointer d; -}; - -QT_END_NAMESPACE - -QT_END_HEADER - -Q_DECLARE_METATYPE(QAudioDeviceInfo) - -#endif // QAUDIODEVICEINFO_H diff --git a/src/multimedia/audio/qaudiodeviceinfo_alsa_p.cpp b/src/multimedia/audio/qaudiodeviceinfo_alsa_p.cpp deleted file mode 100644 index 36270a7..0000000 --- a/src/multimedia/audio/qaudiodeviceinfo_alsa_p.cpp +++ /dev/null @@ -1,486 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtMultimedia module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -// -// W A R N I N G -// ------------- -// -// This file is not part of the Qt API. It exists for the convenience -// of other Qt classes. This header file may change from version to -// version without notice, or even be removed. -// -// We mean it. -// - -#include "qaudiodeviceinfo_alsa_p.h" - -#include - -QT_BEGIN_NAMESPACE - -QAudioDeviceInfoInternal::QAudioDeviceInfoInternal(QByteArray dev, QAudio::Mode mode) -{ - handle = 0; - - device = QLatin1String(dev); - this->mode = mode; -} - -QAudioDeviceInfoInternal::~QAudioDeviceInfoInternal() -{ - close(); -} - -bool QAudioDeviceInfoInternal::isFormatSupported(const QAudioFormat& format) const -{ - return testSettings(format); -} - -QAudioFormat QAudioDeviceInfoInternal::preferredFormat() const -{ - QAudioFormat nearest; - if(mode == QAudio::AudioOutput) { - nearest.setFrequency(44100); - nearest.setChannels(2); - nearest.setByteOrder(QAudioFormat::LittleEndian); - nearest.setSampleType(QAudioFormat::SignedInt); - nearest.setSampleSize(16); - nearest.setCodec(QLatin1String("audio/pcm")); - } else { - nearest.setFrequency(8000); - nearest.setChannels(1); - nearest.setSampleType(QAudioFormat::UnSignedInt); - nearest.setSampleSize(8); - nearest.setCodec(QLatin1String("audio/pcm")); - if(!testSettings(nearest)) { - nearest.setChannels(2); - nearest.setSampleSize(16); - nearest.setSampleType(QAudioFormat::SignedInt); - } - } - return nearest; -} - -QAudioFormat QAudioDeviceInfoInternal::nearestFormat(const QAudioFormat& format) const -{ - if(testSettings(format)) - return format; - else - return preferredFormat(); -} - -QString QAudioDeviceInfoInternal::deviceName() const -{ - return device; -} - -QStringList QAudioDeviceInfoInternal::codecList() -{ - updateLists(); - return codecz; -} - -QList QAudioDeviceInfoInternal::frequencyList() -{ - updateLists(); - return freqz; -} - -QList QAudioDeviceInfoInternal::channelsList() -{ - updateLists(); - return channelz; -} - -QList QAudioDeviceInfoInternal::sampleSizeList() -{ - updateLists(); - return sizez; -} - -QList QAudioDeviceInfoInternal::byteOrderList() -{ - updateLists(); - return byteOrderz; -} - -QList QAudioDeviceInfoInternal::sampleTypeList() -{ - updateLists(); - return typez; -} - -bool QAudioDeviceInfoInternal::open() -{ - int err = 0; - QString dev = device; - QList devices = availableDevices(mode); - - if(dev.compare(QLatin1String("default")) == 0) { -#if(SND_LIB_MAJOR == 1 && SND_LIB_MINOR == 0 && SND_LIB_SUBMINOR >= 14) - dev = QLatin1String(devices.first().constData()); -#else - dev = QLatin1String("hw:0,0"); -#endif - } else { -#if(SND_LIB_MAJOR == 1 && SND_LIB_MINOR == 0 && SND_LIB_SUBMINOR >= 14) - dev = device; -#else - int idx = 0; - char *name; - - QString shortName = device.mid(device.indexOf(QLatin1String("="),0)+1); - - while(snd_card_get_name(idx,&name) == 0) { - if(dev.contains(QLatin1String(name))) - break; - idx++; - } - dev = QString(QLatin1String("hw:%1,0")).arg(idx); -#endif - } - if(mode == QAudio::AudioOutput) { - err=snd_pcm_open( &handle,dev.toLocal8Bit().constData(),SND_PCM_STREAM_PLAYBACK,0); - } else { - err=snd_pcm_open( &handle,dev.toLocal8Bit().constData(),SND_PCM_STREAM_CAPTURE,0); - } - if(err < 0) { - handle = 0; - return false; - } - return true; -} - -void QAudioDeviceInfoInternal::close() -{ - if(handle) - snd_pcm_close(handle); - handle = 0; -} - -bool QAudioDeviceInfoInternal::testSettings(const QAudioFormat& format) const -{ - // Set nearest to closest settings that do work. - // See if what is in settings will work (return value). - int err = 0; - snd_pcm_t* handle; - snd_pcm_hw_params_t *params; - QString dev = device; - - QList devices = QAudioDeviceInfoInternal::availableDevices(QAudio::AudioOutput); - - if(dev.compare(QLatin1String("default")) == 0) { -#if(SND_LIB_MAJOR == 1 && SND_LIB_MINOR == 0 && SND_LIB_SUBMINOR >= 14) - dev = QLatin1String(devices.first().constData()); -#else - dev = QLatin1String("hw:0,0"); -#endif - } else { -#if(SND_LIB_MAJOR == 1 && SND_LIB_MINOR == 0 && SND_LIB_SUBMINOR >= 14) - dev = device; -#else - int idx = 0; - char *name; - - QString shortName = device.mid(device.indexOf(QLatin1String("="),0)+1); - - while(snd_card_get_name(idx,&name) == 0) { - if(shortName.compare(QLatin1String(name)) == 0) - break; - idx++; - } - dev = QString(QLatin1String("hw:%1,0")).arg(idx); -#endif - } - if(mode == QAudio::AudioOutput) { - err=snd_pcm_open( &handle,dev.toLocal8Bit().constData(),SND_PCM_STREAM_PLAYBACK,0); - } else { - err=snd_pcm_open( &handle,dev.toLocal8Bit().constData(),SND_PCM_STREAM_CAPTURE,0); - } - if(err < 0) { - handle = 0; - return false; - } - - bool testChannel = false; - bool testCodec = false; - bool testFreq = false; - bool testType = false; - bool testSize = false; - - int dir = 0; - - snd_pcm_nonblock( handle, 0 ); - snd_pcm_hw_params_alloca( ¶ms ); - snd_pcm_hw_params_any( handle, params ); - - // set the values! - snd_pcm_hw_params_set_channels(handle,params,format.channels()); - snd_pcm_hw_params_set_rate(handle,params,format.frequency(),dir); - switch(format.sampleSize()) { - case 8: - if(format.sampleType() == QAudioFormat::SignedInt) - snd_pcm_hw_params_set_format(handle,params,SND_PCM_FORMAT_S8); - else if(format.sampleType() == QAudioFormat::UnSignedInt) - snd_pcm_hw_params_set_format(handle,params,SND_PCM_FORMAT_U8); - break; - case 16: - if(format.sampleType() == QAudioFormat::SignedInt) { - if(format.byteOrder() == QAudioFormat::LittleEndian) - snd_pcm_hw_params_set_format(handle,params,SND_PCM_FORMAT_S16_LE); - else if(format.byteOrder() == QAudioFormat::BigEndian) - snd_pcm_hw_params_set_format(handle,params,SND_PCM_FORMAT_S16_BE); - } else if(format.sampleType() == QAudioFormat::UnSignedInt) { - if(format.byteOrder() == QAudioFormat::LittleEndian) - snd_pcm_hw_params_set_format(handle,params,SND_PCM_FORMAT_U16_LE); - else if(format.byteOrder() == QAudioFormat::BigEndian) - snd_pcm_hw_params_set_format(handle,params,SND_PCM_FORMAT_U16_BE); - } - break; - case 32: - if(format.sampleType() == QAudioFormat::SignedInt) { - if(format.byteOrder() == QAudioFormat::LittleEndian) - snd_pcm_hw_params_set_format(handle,params,SND_PCM_FORMAT_S32_LE); - else if(format.byteOrder() == QAudioFormat::BigEndian) - snd_pcm_hw_params_set_format(handle,params,SND_PCM_FORMAT_S32_BE); - } else if(format.sampleType() == QAudioFormat::UnSignedInt) { - if(format.byteOrder() == QAudioFormat::LittleEndian) - snd_pcm_hw_params_set_format(handle,params,SND_PCM_FORMAT_U32_LE); - else if(format.byteOrder() == QAudioFormat::BigEndian) - snd_pcm_hw_params_set_format(handle,params,SND_PCM_FORMAT_U32_BE); - } - } - - // For now, just accept only audio/pcm codec - if(!format.codec().startsWith(QLatin1String("audio/pcm"))) { - err=-1; - } else - testCodec = true; - - if(err>=0 && format.channels() != -1) { - err = snd_pcm_hw_params_test_channels(handle,params,format.channels()); - if(err>=0) - err = snd_pcm_hw_params_set_channels(handle,params,format.channels()); - if(err>=0) - testChannel = true; - } - - if(err>=0 && format.frequency() != -1) { - err = snd_pcm_hw_params_test_rate(handle,params,format.frequency(),0); - if(err>=0) - err = snd_pcm_hw_params_set_rate(handle,params,format.frequency(),dir); - if(err>=0) - testFreq = true; - } - - if((err>=0 && format.sampleSize() != -1) && - (format.sampleType() != QAudioFormat::Unknown)) { - switch(format.sampleSize()) { - case 8: - if(format.sampleType() == QAudioFormat::SignedInt) - err = snd_pcm_hw_params_set_format(handle,params,SND_PCM_FORMAT_S8); - else if(format.sampleType() == QAudioFormat::UnSignedInt) - err = snd_pcm_hw_params_set_format(handle,params,SND_PCM_FORMAT_U8); - break; - case 16: - if(format.sampleType() == QAudioFormat::SignedInt) { - if(format.byteOrder() == QAudioFormat::LittleEndian) - err = snd_pcm_hw_params_set_format(handle,params,SND_PCM_FORMAT_S16_LE); - else if(format.byteOrder() == QAudioFormat::BigEndian) - err = snd_pcm_hw_params_set_format(handle,params,SND_PCM_FORMAT_S16_BE); - } else if(format.sampleType() == QAudioFormat::UnSignedInt) { - if(format.byteOrder() == QAudioFormat::LittleEndian) - err = snd_pcm_hw_params_set_format(handle,params,SND_PCM_FORMAT_U16_LE); - else if(format.byteOrder() == QAudioFormat::BigEndian) - err = snd_pcm_hw_params_set_format(handle,params,SND_PCM_FORMAT_U16_BE); - } - break; - case 32: - if(format.sampleType() == QAudioFormat::SignedInt) { - if(format.byteOrder() == QAudioFormat::LittleEndian) - err = snd_pcm_hw_params_set_format(handle,params,SND_PCM_FORMAT_S32_LE); - else if(format.byteOrder() == QAudioFormat::BigEndian) - err = snd_pcm_hw_params_set_format(handle,params,SND_PCM_FORMAT_S32_BE); - } else if(format.sampleType() == QAudioFormat::UnSignedInt) { - if(format.byteOrder() == QAudioFormat::LittleEndian) - err = snd_pcm_hw_params_set_format(handle,params,SND_PCM_FORMAT_U32_LE); - else if(format.byteOrder() == QAudioFormat::BigEndian) - err = snd_pcm_hw_params_set_format(handle,params,SND_PCM_FORMAT_U32_BE); - } - } - if(err>=0) { - testSize = true; - testType = true; - } - } - if(err>=0) - err = snd_pcm_hw_params(handle, params); - - if(err == 0) { - // settings work - // close() - if(handle) - snd_pcm_close(handle); - return true; - } - if(handle) - snd_pcm_close(handle); - - return false; -} - -void QAudioDeviceInfoInternal::updateLists() -{ - // redo all lists based on current settings - freqz.clear(); - channelz.clear(); - sizez.clear(); - byteOrderz.clear(); - typez.clear(); - codecz.clear(); - - if(!handle) - open(); - - if(!handle) - return; - - for(int i=0; i<(int)MAX_SAMPLE_RATES; i++) { - //if(snd_pcm_hw_params_test_rate(handle, params, SAMPLE_RATES[i], dir) == 0) - freqz.append(SAMPLE_RATES[i]); - } - channelz.append(1); - channelz.append(2); - sizez.append(8); - sizez.append(16); - sizez.append(32); - byteOrderz.append(QAudioFormat::LittleEndian); - byteOrderz.append(QAudioFormat::BigEndian); - typez.append(QAudioFormat::SignedInt); - typez.append(QAudioFormat::UnSignedInt); - typez.append(QAudioFormat::Float); - codecz.append(QLatin1String("audio/pcm")); - close(); -} - -QList QAudioDeviceInfoInternal::availableDevices(QAudio::Mode mode) -{ - QList allDevices; - QList devices; - QByteArray filter; - -#if(SND_LIB_MAJOR == 1 && SND_LIB_MINOR == 0 && SND_LIB_SUBMINOR >= 14) - // Create a list of all current audio devices that support mode - void **hints, **n; - char *name, *descr, *io; - - if(snd_device_name_hint(-1, "pcm", &hints) < 0) { - qWarning() << "no alsa devices available"; - return devices; - } - n = hints; - - if(mode == QAudio::AudioInput) { - filter = "Input"; - } else { - filter = "Output"; - } - - while (*n != NULL) { - name = snd_device_name_get_hint(*n, "NAME"); - descr = snd_device_name_get_hint(*n, "DESC"); - io = snd_device_name_get_hint(*n, "IOID"); - if((name != NULL) && (descr != NULL) && ((io == NULL) || (io == filter))) { - QString deviceName = QLatin1String(name); - QString deviceDescription = QLatin1String(descr); - allDevices.append(deviceName.toLocal8Bit().constData()); - if(deviceDescription.contains(QLatin1String("Default Audio Device"))) - devices.append(deviceName.toLocal8Bit().constData()); - } - if(name != NULL) - free(name); - if(descr != NULL) - free(descr); - if(io != NULL) - free(io); - ++n; - } - snd_device_name_free_hint(hints); - - if(devices.size() > 0) { - devices.append("default"); - } -#else - int idx = 0; - char* name; - - while(snd_card_get_name(idx,&name) == 0) { - devices.append(name); - idx++; - } - if (idx > 0) - devices.append("default"); -#endif - if (devices.size() == 0 && allDevices.size() > 0) - return allDevices; - - return devices; -} - -QByteArray QAudioDeviceInfoInternal::defaultInputDevice() -{ - QList devices = availableDevices(QAudio::AudioInput); - if(devices.size() == 0) - return QByteArray(); - - return devices.first(); -} - -QByteArray QAudioDeviceInfoInternal::defaultOutputDevice() -{ - QList devices = availableDevices(QAudio::AudioOutput); - if(devices.size() == 0) - return QByteArray(); - - return devices.first(); -} - -QT_END_NAMESPACE diff --git a/src/multimedia/audio/qaudiodeviceinfo_alsa_p.h b/src/multimedia/audio/qaudiodeviceinfo_alsa_p.h deleted file mode 100644 index 6f9a459..0000000 --- a/src/multimedia/audio/qaudiodeviceinfo_alsa_p.h +++ /dev/null @@ -1,117 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtMultimedia module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -// -// W A R N I N G -// ------------- -// -// This file is not part of the Qt API. It exists for the convenience -// of other Qt classes. This header file may change from version to -// version without notice, or even be removed. -// -// We mean it. -// - - -#ifndef QAUDIODEVICEINFOALSA_H -#define QAUDIODEVICEINFOALSA_H - -#include - -#include -#include -#include -#include - -#include -#include -#include - -QT_BEGIN_NAMESPACE - -const unsigned int MAX_SAMPLE_RATES = 5; -const unsigned int SAMPLE_RATES[] = - { 8000, 11025, 22050, 44100, 48000 }; - -class QAudioDeviceInfoInternal : public QAbstractAudioDeviceInfo -{ - Q_OBJECT -public: - QAudioDeviceInfoInternal(QByteArray dev,QAudio::Mode mode); - ~QAudioDeviceInfoInternal(); - - bool testSettings(const QAudioFormat& format) const; - void updateLists(); - QAudioFormat preferredFormat() const; - bool isFormatSupported(const QAudioFormat& format) const; - QAudioFormat nearestFormat(const QAudioFormat& format) const; - QString deviceName() const; - QStringList codecList(); - QList frequencyList(); - QList channelsList(); - QList sampleSizeList(); - QList byteOrderList(); - QList sampleTypeList(); - static QByteArray defaultInputDevice(); - static QByteArray defaultOutputDevice(); - static QList availableDevices(QAudio::Mode); - -private: - bool open(); - void close(); - - QString device; - QAudio::Mode mode; - QAudioFormat nearest; - QList freqz; - QList channelz; - QList sizez; - QList byteOrderz; - QStringList codecz; - QList typez; - snd_pcm_t* handle; - snd_pcm_hw_params_t *params; -}; - -QT_END_NAMESPACE - -#endif - diff --git a/src/multimedia/audio/qaudiodeviceinfo_mac_p.cpp b/src/multimedia/audio/qaudiodeviceinfo_mac_p.cpp deleted file mode 100644 index ecd03e5..0000000 --- a/src/multimedia/audio/qaudiodeviceinfo_mac_p.cpp +++ /dev/null @@ -1,357 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtMultimedia module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -// -// W A R N I N G -// ------------- -// -// This file is not part of the Qt API. It exists for the convenience -// of other Qt classes. This header file may change from version to -// version without notice, or even be removed. -// -// We mean it. -// - -#include -#include -#include -#include -#include -#include - -#include -#include "qaudio_mac_p.h" -#include "qaudiodeviceinfo_mac_p.h" - - - -QT_BEGIN_NAMESPACE - - -QAudioDeviceInfoInternal::QAudioDeviceInfoInternal(QByteArray const& handle, QAudio::Mode) -{ - QDataStream ds(handle); - quint32 did, tm; - - ds >> did >> tm >> name; - deviceId = AudioDeviceID(did); - mode = QAudio::Mode(tm); -} - -bool QAudioDeviceInfoInternal::isFormatSupported(const QAudioFormat& format) const -{ - return format.codec() == QString::fromLatin1("audio/pcm"); -} - -QAudioFormat QAudioDeviceInfoInternal::preferredFormat() const -{ - QAudioFormat rc; - - UInt32 propSize = 0; - - if (AudioDeviceGetPropertyInfo(deviceId, - 0, - mode == QAudio::AudioInput, - kAudioDevicePropertyStreams, - &propSize, - 0) == noErr) { - - const int sc = propSize / sizeof(AudioStreamID); - - if (sc > 0) { - AudioStreamID* streams = new AudioStreamID[sc]; - - if (AudioDeviceGetProperty(deviceId, - 0, - mode == QAudio::AudioInput, - kAudioDevicePropertyStreams, - &propSize, - streams) == noErr) { - - for (int i = 0; i < sc; ++i) { - if (AudioStreamGetPropertyInfo(streams[i], - 0, - kAudioStreamPropertyPhysicalFormat, - &propSize, - 0) == noErr) { - - AudioStreamBasicDescription sf; - - if (AudioStreamGetProperty(streams[i], - 0, - kAudioStreamPropertyPhysicalFormat, - &propSize, - &sf) == noErr) { - rc = toQAudioFormat(sf); - break; - } - } - } - } - - delete streams; - } - } - - return rc; -} - -QAudioFormat QAudioDeviceInfoInternal::nearestFormat(const QAudioFormat& format) const -{ - QAudioFormat rc(format); - QAudioFormat target = preferredFormat(); - - if (!format.codec().isEmpty() && format.codec() != QString::fromLatin1("audio/pcm")) - return QAudioFormat(); - - rc.setCodec(QString::fromLatin1("audio/pcm")); - - if (rc.frequency() != target.frequency()) - rc.setFrequency(target.frequency()); - if (rc.channels() != target.channels()) - rc.setChannels(target.channels()); - if (rc.sampleSize() != target.sampleSize()) - rc.setSampleSize(target.sampleSize()); - if (rc.byteOrder() != target.byteOrder()) - rc.setByteOrder(target.byteOrder()); - if (rc.sampleType() != target.sampleType()) - rc.setSampleType(target.sampleType()); - - return rc; -} - -QString QAudioDeviceInfoInternal::deviceName() const -{ - return name; -} - -QStringList QAudioDeviceInfoInternal::codecList() -{ - return QStringList() << QString::fromLatin1("audio/pcm"); -} - -QList QAudioDeviceInfoInternal::frequencyList() -{ - QSet rc; - - // Add some common frequencies - rc << 8000 << 11025 << 22050 << 44100; - - // - UInt32 propSize = 0; - - if (AudioDeviceGetPropertyInfo(deviceId, - 0, - mode == QAudio::AudioInput, - kAudioDevicePropertyAvailableNominalSampleRates, - &propSize, - 0) == noErr) { - - const int pc = propSize / sizeof(AudioValueRange); - - if (pc > 0) { - AudioValueRange* vr = new AudioValueRange[pc]; - - if (AudioDeviceGetProperty(deviceId, - 0, - mode == QAudio::AudioInput, - kAudioDevicePropertyAvailableNominalSampleRates, - &propSize, - vr) == noErr) { - - for (int i = 0; i < pc; ++i) - rc << vr[i].mMaximum; - } - - delete vr; - } - } - - return rc.toList(); -} - -QList QAudioDeviceInfoInternal::channelsList() -{ - QList rc; - - // Can mix down to 1 channel - rc << 1; - - UInt32 propSize = 0; - int channels = 0; - - if (AudioDeviceGetPropertyInfo(deviceId, - 0, - mode == QAudio::AudioInput, - kAudioDevicePropertyStreamConfiguration, - &propSize, - 0) == noErr) { - - AudioBufferList* audioBufferList = static_cast(qMalloc(propSize)); - - if (audioBufferList != 0) { - if (AudioDeviceGetProperty(deviceId, - 0, - mode == QAudio::AudioInput, - kAudioDevicePropertyStreamConfiguration, - &propSize, - audioBufferList) == noErr) { - - for (int i = 0; i < int(audioBufferList->mNumberBuffers); ++i) { - channels += audioBufferList->mBuffers[i].mNumberChannels; - rc << channels; - } - } - - qFree(audioBufferList); - } - } - - return rc; -} - -QList QAudioDeviceInfoInternal::sampleSizeList() -{ - return QList() << 8 << 16 << 24 << 32 << 64; -} - -QList QAudioDeviceInfoInternal::byteOrderList() -{ - return QList() << QAudioFormat::LittleEndian << QAudioFormat::BigEndian; -} - -QList QAudioDeviceInfoInternal::sampleTypeList() -{ - return QList() << QAudioFormat::SignedInt << QAudioFormat::UnSignedInt << QAudioFormat::Float; -} - -static QByteArray get_device_info(AudioDeviceID audioDevice, QAudio::Mode mode) -{ - UInt32 size; - QByteArray device; - QDataStream ds(&device, QIODevice::WriteOnly); - AudioStreamBasicDescription sf; - CFStringRef name; - Boolean isInput = mode == QAudio::AudioInput; - - // Id - ds << quint32(audioDevice); - - // Mode - size = sizeof(AudioStreamBasicDescription); - if (AudioDeviceGetProperty(audioDevice, 0, isInput, kAudioDevicePropertyStreamFormat, - &size, &sf) != noErr) { - return QByteArray(); - } - ds << quint32(mode); - - // Name - size = sizeof(CFStringRef); - if (AudioDeviceGetProperty(audioDevice, 0, isInput, kAudioObjectPropertyName, - &size, &name) != noErr) { - qWarning() << "QAudioDeviceInfo: Unable to find device name"; - } - ds << QCFString::toQString(name); - - CFRelease(name); - - return device; -} - -QByteArray QAudioDeviceInfoInternal::defaultInputDevice() -{ - AudioDeviceID audioDevice; - UInt32 size = sizeof(audioDevice); - - if (AudioHardwareGetProperty(kAudioHardwarePropertyDefaultInputDevice, &size, - &audioDevice) != noErr) { - qWarning() << "QAudioDeviceInfo: Unable to find default input device"; - return QByteArray(); - } - - return get_device_info(audioDevice, QAudio::AudioInput); -} - -QByteArray QAudioDeviceInfoInternal::defaultOutputDevice() -{ - AudioDeviceID audioDevice; - UInt32 size = sizeof(audioDevice); - - if (AudioHardwareGetProperty(kAudioHardwarePropertyDefaultOutputDevice, &size, - &audioDevice) != noErr) { - qWarning() << "QAudioDeviceInfo: Unable to find default output device"; - return QByteArray(); - } - - return get_device_info(audioDevice, QAudio::AudioOutput); -} - -QList QAudioDeviceInfoInternal::availableDevices(QAudio::Mode mode) -{ - QList devices; - - UInt32 propSize = 0; - - if (AudioHardwareGetPropertyInfo(kAudioHardwarePropertyDevices, &propSize, 0) == noErr) { - - const int dc = propSize / sizeof(AudioDeviceID); - - if (dc > 0) { - AudioDeviceID* audioDevices = new AudioDeviceID[dc]; - - if (AudioHardwareGetProperty(kAudioHardwarePropertyDevices, &propSize, audioDevices) == noErr) { - for (int i = 0; i < dc; ++i) { - QByteArray info = get_device_info(audioDevices[i], mode); - if (!info.isNull()) - devices << info; - } - } - - delete audioDevices; - } - } - - return devices; -} - - -QT_END_NAMESPACE - diff --git a/src/multimedia/audio/qaudiodeviceinfo_mac_p.h b/src/multimedia/audio/qaudiodeviceinfo_mac_p.h deleted file mode 100644 index e234384..0000000 --- a/src/multimedia/audio/qaudiodeviceinfo_mac_p.h +++ /dev/null @@ -1,97 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtMultimedia module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -// -// W A R N I N G -// ------------- -// -// This file is not part of the Qt API. It exists for the convenience -// of other Qt classes. This header file may change from version to -// version without notice, or even be removed. -// -// We mean it. -// - - -#ifndef QDEVICEINFO_MAC_P_H -#define QDEVICEINFO_MAC_P_H - -#include - -#include - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -class QAudioDeviceInfoInternal : public QAbstractAudioDeviceInfo -{ -public: - AudioDeviceID deviceId; - QString name; - QAudio::Mode mode; - - QAudioDeviceInfoInternal(QByteArray const& handle, QAudio::Mode mode); - - bool isFormatSupported(const QAudioFormat& format) const; - QAudioFormat preferredFormat() const; - QAudioFormat nearestFormat(const QAudioFormat& format) const; - - QString deviceName() const; - - QStringList codecList(); - QList frequencyList(); - QList channelsList(); - QList sampleSizeList(); - QList byteOrderList(); - QList sampleTypeList(); - - static QByteArray defaultInputDevice(); - static QByteArray defaultOutputDevice(); - - static QList availableDevices(QAudio::Mode mode); -}; - -QT_END_NAMESPACE - -QT_END_HEADER - -#endif // QDEVICEINFO_MAC_P_H diff --git a/src/multimedia/audio/qaudiodeviceinfo_symbian_p.cpp b/src/multimedia/audio/qaudiodeviceinfo_symbian_p.cpp deleted file mode 100644 index 36284d3..0000000 --- a/src/multimedia/audio/qaudiodeviceinfo_symbian_p.cpp +++ /dev/null @@ -1,200 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtMultimedia module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qaudiodeviceinfo_symbian_p.h" -#include "qaudio_symbian_p.h" - -QT_BEGIN_NAMESPACE - -QAudioDeviceInfoInternal::QAudioDeviceInfoInternal(QByteArray device, - QAudio::Mode mode) - : m_deviceName(QLatin1String(device)) - , m_mode(mode) - , m_updated(false) -{ - QT_TRAP_THROWING(m_devsound.reset(CMMFDevSound::NewL())); -} - -QAudioDeviceInfoInternal::~QAudioDeviceInfoInternal() -{ - -} - -QAudioFormat QAudioDeviceInfoInternal::preferredFormat() const -{ - QAudioFormat format; - switch (m_mode) { - case QAudio::AudioOutput: - format.setFrequency(44100); - format.setChannels(2); - format.setSampleSize(16); - format.setByteOrder(QAudioFormat::LittleEndian); - format.setSampleType(QAudioFormat::SignedInt); - format.setCodec(QLatin1String("audio/pcm")); - break; - - case QAudio::AudioInput: - format.setFrequency(8000); - format.setChannels(1); - format.setSampleSize(16); - format.setByteOrder(QAudioFormat::LittleEndian); - format.setSampleType(QAudioFormat::SignedInt); - format.setCodec(QLatin1String("audio/pcm")); - break; - - default: - Q_ASSERT_X(false, Q_FUNC_INFO, "Invalid mode"); - } - - if (!isFormatSupported(format)) { - if (m_frequencies.size()) - format.setFrequency(m_frequencies[0]); - if (m_channels.size()) - format.setChannels(m_channels[0]); - if (m_sampleSizes.size()) - format.setSampleSize(m_sampleSizes[0]); - if (m_byteOrders.size()) - format.setByteOrder(m_byteOrders[0]); - if (m_sampleTypes.size()) - format.setSampleType(m_sampleTypes[0]); - } - - return format; -} - -bool QAudioDeviceInfoInternal::isFormatSupported( - const QAudioFormat &format) const -{ - getSupportedFormats(); - const bool supported = - m_codecs.contains(format.codec()) - && m_frequencies.contains(format.frequency()) - && m_channels.contains(format.channels()) - && m_sampleSizes.contains(format.sampleSize()) - && m_byteOrders.contains(format.byteOrder()) - && m_sampleTypes.contains(format.sampleType()); - - return supported; -} - -QAudioFormat QAudioDeviceInfoInternal::nearestFormat(const QAudioFormat &format) const -{ - if (isFormatSupported(format)) - return format; - else - return preferredFormat(); -} - -QString QAudioDeviceInfoInternal::deviceName() const -{ - return m_deviceName; -} - -QStringList QAudioDeviceInfoInternal::codecList() -{ - getSupportedFormats(); - return m_codecs; -} - -QList QAudioDeviceInfoInternal::frequencyList() -{ - getSupportedFormats(); - return m_frequencies; -} - -QList QAudioDeviceInfoInternal::channelsList() -{ - getSupportedFormats(); - return m_channels; -} - -QList QAudioDeviceInfoInternal::sampleSizeList() -{ - getSupportedFormats(); - return m_sampleSizes; -} - -QList QAudioDeviceInfoInternal::byteOrderList() -{ - getSupportedFormats(); - return m_byteOrders; -} - -QList QAudioDeviceInfoInternal::sampleTypeList() -{ - getSupportedFormats(); - return m_sampleTypes; -} - -QByteArray QAudioDeviceInfoInternal::defaultInputDevice() -{ - return QByteArray("default"); -} - -QByteArray QAudioDeviceInfoInternal::defaultOutputDevice() -{ - return QByteArray("default"); -} - -QList QAudioDeviceInfoInternal::availableDevices(QAudio::Mode) -{ - QList result; - result += QByteArray("default"); - return result; -} - -void QAudioDeviceInfoInternal::getSupportedFormats() const -{ - if (!m_updated) { - QScopedPointer caps( - new SymbianAudio::DevSoundCapabilities(*m_devsound, m_mode)); - - SymbianAudio::Utils::capabilitiesNativeToQt(*caps, - m_frequencies, m_channels, m_sampleSizes, - m_byteOrders, m_sampleTypes); - - m_codecs.append(QLatin1String("audio/pcm")); - - m_updated = true; - } -} - -QT_END_NAMESPACE diff --git a/src/multimedia/audio/qaudiodeviceinfo_symbian_p.h b/src/multimedia/audio/qaudiodeviceinfo_symbian_p.h deleted file mode 100644 index 89e539f..0000000 --- a/src/multimedia/audio/qaudiodeviceinfo_symbian_p.h +++ /dev/null @@ -1,107 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtMultimedia module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -// -// W A R N I N G -// ------------- -// -// This file is not part of the Qt API. It exists for the convenience -// of other Qt classes. This header file may change from version to -// version without notice, or even be removed. -// -// We mean it. -// - -#ifndef QAUDIODEVICEINFO_SYMBIAN_P_H -#define QAUDIODEVICEINFO_SYMBIAN_P_H - -#include -#include - -QT_BEGIN_NAMESPACE - -class QAudioDeviceInfoInternal - : public QAbstractAudioDeviceInfo -{ - Q_OBJECT - -public: - QAudioDeviceInfoInternal(QByteArray device, QAudio::Mode mode); - ~QAudioDeviceInfoInternal(); - - // QAbstractAudioDeviceInfo - QAudioFormat preferredFormat() const; - bool isFormatSupported(const QAudioFormat &format) const; - QAudioFormat nearestFormat(const QAudioFormat &format) const; - QString deviceName() const; - QStringList codecList(); - QList frequencyList(); - QList channelsList(); - QList sampleSizeList(); - QList byteOrderList(); - QList sampleTypeList(); - static QByteArray defaultInputDevice(); - static QByteArray defaultOutputDevice(); - static QList availableDevices(QAudio::Mode); - -private: - void getSupportedFormats() const; - -private: - QScopedPointer m_devsound; - - QString m_deviceName; - QAudio::Mode m_mode; - - // Mutable to allow lazy initialization when called from const-qualified - // public functions (isFormatSupported, nearestFormat) - mutable bool m_updated; - mutable QStringList m_codecs; - mutable QList m_frequencies; - mutable QList m_channels; - mutable QList m_sampleSizes; - mutable QList m_byteOrders; - mutable QList m_sampleTypes; -}; - -QT_END_NAMESPACE - -#endif diff --git a/src/multimedia/audio/qaudiodeviceinfo_win32_p.cpp b/src/multimedia/audio/qaudiodeviceinfo_win32_p.cpp deleted file mode 100644 index aee0807..0000000 --- a/src/multimedia/audio/qaudiodeviceinfo_win32_p.cpp +++ /dev/null @@ -1,433 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtMultimedia module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -// -// W A R N I N G -// ------------- -// -// This file is not part of the Qt API. It exists for the convenience -// of other Qt classes. This header file may change from version to -// version without notice, or even be removed. -// -// We mean it. -// - - -#include -#include -#include "qaudiodeviceinfo_win32_p.h" - -QT_BEGIN_NAMESPACE - -// For mingw toolchain mmsystem.h only defines half the defines, so add if needed. -#ifndef WAVE_FORMAT_44M08 -#define WAVE_FORMAT_44M08 0x00000100 -#define WAVE_FORMAT_44S08 0x00000200 -#define WAVE_FORMAT_44M16 0x00000400 -#define WAVE_FORMAT_44S16 0x00000800 -#define WAVE_FORMAT_48M08 0x00001000 -#define WAVE_FORMAT_48S08 0x00002000 -#define WAVE_FORMAT_48M16 0x00004000 -#define WAVE_FORMAT_48S16 0x00008000 -#define WAVE_FORMAT_96M08 0x00010000 -#define WAVE_FORMAT_96S08 0x00020000 -#define WAVE_FORMAT_96M16 0x00040000 -#define WAVE_FORMAT_96S16 0x00080000 -#endif - - -QAudioDeviceInfoInternal::QAudioDeviceInfoInternal(QByteArray dev, QAudio::Mode mode) -{ - device = QLatin1String(dev); - this->mode = mode; - - updateLists(); -} - -QAudioDeviceInfoInternal::~QAudioDeviceInfoInternal() -{ - close(); -} - -bool QAudioDeviceInfoInternal::isFormatSupported(const QAudioFormat& format) const -{ - return testSettings(format); -} - -QAudioFormat QAudioDeviceInfoInternal::preferredFormat() const -{ - QAudioFormat nearest; - if(mode == QAudio::AudioOutput) { - nearest.setFrequency(44100); - nearest.setChannelCount(2); - nearest.setByteOrder(QAudioFormat::LittleEndian); - nearest.setSampleType(QAudioFormat::SignedInt); - nearest.setSampleSize(16); - nearest.setCodec(QLatin1String("audio/pcm")); - } else { - nearest.setFrequency(11025); - nearest.setChannelCount(1); - nearest.setByteOrder(QAudioFormat::LittleEndian); - nearest.setSampleType(QAudioFormat::SignedInt); - nearest.setSampleSize(8); - nearest.setCodec(QLatin1String("audio/pcm")); - } - return nearest; -} - -QAudioFormat QAudioDeviceInfoInternal::nearestFormat(const QAudioFormat& format) const -{ - if(testSettings(format)) - return format; - else - return preferredFormat(); -} - -QString QAudioDeviceInfoInternal::deviceName() const -{ - return device; -} - -QStringList QAudioDeviceInfoInternal::codecList() -{ - updateLists(); - return codecz; -} - -QList QAudioDeviceInfoInternal::frequencyList() -{ - updateLists(); - return freqz; -} - -QList QAudioDeviceInfoInternal::channelsList() -{ - updateLists(); - return channelz; -} - -QList QAudioDeviceInfoInternal::sampleSizeList() -{ - updateLists(); - return sizez; -} - -QList QAudioDeviceInfoInternal::byteOrderList() -{ - updateLists(); - return byteOrderz; -} - -QList QAudioDeviceInfoInternal::sampleTypeList() -{ - updateLists(); - return typez; -} - - -bool QAudioDeviceInfoInternal::open() -{ - return true; -} - -void QAudioDeviceInfoInternal::close() -{ -} - -bool QAudioDeviceInfoInternal::testSettings(const QAudioFormat& format) const -{ - // Set nearest to closest settings that do work. - // See if what is in settings will work (return value). - - bool failed = false; - bool match = false; - - // check codec - for( int i = 0; i < codecz.count(); i++) { - if (format.codec() == codecz.at(i)) - match = true; - } - if (!match) failed = true; - - // check channel - match = false; - if (!failed) { - for( int i = 0; i < channelz.count(); i++) { - if (format.channels() == channelz.at(i)) { - match = true; - break; - } - } - } - if (!match) failed = true; - - // check frequency - match = false; - if (!failed) { - for( int i = 0; i < freqz.count(); i++) { - if (format.frequency() == freqz.at(i)) { - match = true; - break; - } - } - } - - // check sample size - match = false; - if (!failed) { - for( int i = 0; i < sizez.count(); i++) { - if (format.sampleSize() == sizez.at(i)) { - match = true; - break; - } - } - } - - // check byte order - match = false; - if (!failed) { - for( int i = 0; i < byteOrderz.count(); i++) { - if (format.byteOrder() == byteOrderz.at(i)) { - match = true; - break; - } - } - } - - // check sample type - match = false; - if (!failed) { - for( int i = 0; i < typez.count(); i++) { - if (format.sampleType() == typez.at(i)) { - match = true; - break; - } - } - } - - if(!failed) { - // settings work - return true; - } - return false; -} - -void QAudioDeviceInfoInternal::updateLists() -{ - // redo all lists based on current settings - bool base = false; - bool match = false; - DWORD fmt = NULL; - QString tmp; - - if(device.compare(QLatin1String("default")) == 0) - base = true; - - if(mode == QAudio::AudioOutput) { - WAVEOUTCAPS woc; - unsigned long iNumDevs,i; - iNumDevs = waveOutGetNumDevs(); - for(i=0;i 0) - freqz.prepend(8000); -} - -QList QAudioDeviceInfoInternal::availableDevices(QAudio::Mode mode) -{ - Q_UNUSED(mode) - - QList devices; - - if(mode == QAudio::AudioOutput) { - WAVEOUTCAPS woc; - unsigned long iNumDevs,i; - iNumDevs = waveOutGetNumDevs(); - for(i=0;i 0) - devices.append("default"); - - return devices; -} - -QByteArray QAudioDeviceInfoInternal::defaultOutputDevice() -{ - return QByteArray("default"); -} - -QByteArray QAudioDeviceInfoInternal::defaultInputDevice() -{ - return QByteArray("default"); -} - -QT_END_NAMESPACE diff --git a/src/multimedia/audio/qaudiodeviceinfo_win32_p.h b/src/multimedia/audio/qaudiodeviceinfo_win32_p.h deleted file mode 100644 index cb6dd91..0000000 --- a/src/multimedia/audio/qaudiodeviceinfo_win32_p.h +++ /dev/null @@ -1,112 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtMultimedia module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -// -// W A R N I N G -// ------------- -// -// This file is not part of the Qt API. It exists for the convenience -// of other Qt classes. This header file may change from version to -// version without notice, or even be removed. -// -// We mean it. -// - - -#ifndef QAUDIODEVICEINFOWIN_H -#define QAUDIODEVICEINFOWIN_H - -#include -#include -#include -#include - -#include -#include - - -QT_BEGIN_NAMESPACE - -const unsigned int MAX_SAMPLE_RATES = 5; -const unsigned int SAMPLE_RATES[] = { 8000, 11025, 22050, 44100, 48000 }; - -class QAudioDeviceInfoInternal : public QAbstractAudioDeviceInfo -{ - Q_OBJECT - -public: - QAudioDeviceInfoInternal(QByteArray dev,QAudio::Mode mode); - ~QAudioDeviceInfoInternal(); - - bool open(); - void close(); - - bool testSettings(const QAudioFormat& format) const; - void updateLists(); - QAudioFormat preferredFormat() const; - bool isFormatSupported(const QAudioFormat& format) const; - QAudioFormat nearestFormat(const QAudioFormat& format) const; - QString deviceName() const; - QStringList codecList(); - QList frequencyList(); - QList channelsList(); - QList sampleSizeList(); - QList byteOrderList(); - QList sampleTypeList(); - static QByteArray defaultInputDevice(); - static QByteArray defaultOutputDevice(); - static QList availableDevices(QAudio::Mode); - -private: - QAudio::Mode mode; - QString device; - QAudioFormat nearest; - QList freqz; - QList channelz; - QList sizez; - QList byteOrderz; - QStringList codecz; - QList typez; -}; - -QT_END_NAMESPACE - -#endif diff --git a/src/multimedia/audio/qaudioengine.cpp b/src/multimedia/audio/qaudioengine.cpp deleted file mode 100644 index 7f1f5d3..0000000 --- a/src/multimedia/audio/qaudioengine.cpp +++ /dev/null @@ -1,343 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtMultimedia module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include - -QT_BEGIN_NAMESPACE - -/*! - \class QAbstractAudioDeviceInfo - \brief The QAbstractAudioDeviceInfo class provides access for QAudioDeviceInfo to access the audio - device provided by the plugin. - \internal - - \ingroup multimedia - - This class implements the audio functionality for - QAudioDeviceInfo, i.e., QAudioDeviceInfo keeps a - QAbstractAudioDeviceInfo and routes function calls to it. For a - description of the functionality that QAbstractAudioDeviceInfo - implements, you can read the class and functions documentation of - QAudioDeviceInfo. - - \sa QAudioDeviceInfo -*/ - -/*! - \fn virtual QAudioFormat QAbstractAudioDeviceInfo::preferredFormat() const - Returns the nearest settings. -*/ - -/*! - \fn virtual bool QAbstractAudioDeviceInfo::isFormatSupported(const QAudioFormat& format) const - Returns true if \a format is available from audio device. -*/ - -/*! - \fn virtual QAudioFormat QAbstractAudioDeviceInfo::nearestFormat(const QAudioFormat& format) const - Returns the nearest settings \a format. -*/ - -/*! - \fn virtual QString QAbstractAudioDeviceInfo::deviceName() const - Returns the audio device name. -*/ - -/*! - \fn virtual QStringList QAbstractAudioDeviceInfo::codecList() - Returns the list of currently available codecs. -*/ - -/*! - \fn virtual QList QAbstractAudioDeviceInfo::frequencyList() - Returns the list of currently available frequencies. -*/ - -/*! - \fn virtual QList QAbstractAudioDeviceInfo::channelsList() - Returns the list of currently available channels. -*/ - -/*! - \fn virtual QList QAbstractAudioDeviceInfo::sampleSizeList() - Returns the list of currently available sample sizes. -*/ - -/*! - \fn virtual QList QAbstractAudioDeviceInfo::byteOrderList() - Returns the list of currently available byte orders. -*/ - -/*! - \fn virtual QList QAbstractAudioDeviceInfo::sampleTypeList() - Returns the list of currently available sample types. -*/ - -/*! - \class QAbstractAudioOutput - \brief The QAbstractAudioOutput class provides access for QAudioOutput to access the audio - device provided by the plugin. - \internal - - \ingroup multimedia - - QAbstractAudioOutput implements audio functionality for - QAudioOutput, i.e., QAudioOutput routes function calls to - QAbstractAudioOutput. For a description of the functionality that - is implemented, see the QAudioOutput class and function - descriptions. - - \sa QAudioOutput -*/ - -/*! - \fn virtual QIODevice* QAbstractAudioOutput::start(QIODevice* device) - Uses the \a device as the QIODevice to transfer data. If \a device is null then the class - creates an internal QIODevice. Returns a pointer to the QIODevice being used to handle - the data transfer. This QIODevice can be used to write() audio data directly. Passing a - QIODevice allows the data to be transfered without any extra code. -*/ - -/*! - \fn virtual void QAbstractAudioOutput::stop() - Stops the audio output. -*/ - -/*! - \fn virtual void QAbstractAudioOutput::reset() - Drops all audio data in the buffers, resets buffers to zero. -*/ - -/*! - \fn virtual void QAbstractAudioOutput::suspend() - Stops processing audio data, preserving buffered audio data. -*/ - -/*! - \fn virtual void QAbstractAudioOutput::resume() - Resumes processing audio data after a suspend() -*/ - -/*! - \fn virtual int QAbstractAudioOutput::bytesFree() const - Returns the free space available in bytes in the audio buffer. -*/ - -/*! - \fn virtual int QAbstractAudioOutput::periodSize() const - Returns the period size in bytes. -*/ - -/*! - \fn virtual void QAbstractAudioOutput::setBufferSize(int value) - Sets the audio buffer size to \a value in bytes. -*/ - -/*! - \fn virtual int QAbstractAudioOutput::bufferSize() const - Returns the audio buffer size in bytes. -*/ - -/*! - \fn virtual void QAbstractAudioOutput::setNotifyInterval(int ms) - Sets the interval for notify() signal to be emitted. This is based on the \a ms - of audio data processed not on actual real-time. The resolution of the timer - is platform specific. -*/ - -/*! - \fn virtual int QAbstractAudioOutput::notifyInterval() const - Returns the notify interval in milliseconds. -*/ - -/*! - \fn virtual qint64 QAbstractAudioOutput::processedUSecs() const - Returns the amount of audio data processed since start() was called in milliseconds. -*/ - -/*! - \fn virtual qint64 QAbstractAudioOutput::elapsedUSecs() const - Returns the milliseconds since start() was called, including time in Idle and suspend states. -*/ - -/*! - \fn virtual QAudio::Error QAbstractAudioOutput::error() const - Returns the error state. -*/ - -/*! - \fn virtual QAudio::State QAbstractAudioOutput::state() const - Returns the state of audio processing. -*/ - -/*! - \fn virtual QAudioFormat QAbstractAudioOutput::format() const - Returns the QAudioFormat being used. -*/ - -/*! - \fn QAbstractAudioOutput::stateChanged(QAudio::State state) - This signal is emitted when the device \a state has changed. -*/ - -/*! - \fn QAbstractAudioOutput::notify() - This signal is emitted when x ms of audio data has been processed - the interval set by setNotifyInterval(x). -*/ - - -/*! - \class QAbstractAudioInput - \brief The QAbstractAudioInput class provides access for QAudioInput to access the audio - device provided by the plugin. - \internal - - \ingroup multimedia - - QAudioDeviceInput keeps an instance of QAbstractAudioInput and - routes calls to functions of the same name to QAbstractAudioInput. - This means that it is QAbstractAudioInput that implements the - audio functionality. For a description of the functionality, see - the QAudioInput class description. - - \sa QAudioInput -*/ - -/*! - \fn virtual QIODevice* QAbstractAudioInput::start(QIODevice* device) - Uses the \a device as the QIODevice to transfer data. If \a device is null - then the class creates an internal QIODevice. Returns a pointer to the - QIODevice being used to handle the data transfer. This QIODevice can be used to - read() audio data directly. Passing a QIODevice allows the data to be transfered - without any extra code. -*/ - -/*! - \fn virtual void QAbstractAudioInput::stop() - Stops the audio input. -*/ - -/*! - \fn virtual void QAbstractAudioInput::reset() - Drops all audio data in the buffers, resets buffers to zero. -*/ - -/*! - \fn virtual void QAbstractAudioInput::suspend() - Stops processing audio data, preserving buffered audio data. -*/ - -/*! - \fn virtual void QAbstractAudioInput::resume() - Resumes processing audio data after a suspend(). -*/ - -/*! - \fn virtual int QAbstractAudioInput::bytesReady() const - Returns the amount of audio data available to read in bytes. -*/ - -/*! - \fn virtual int QAbstractAudioInput::periodSize() const - Returns the period size in bytes. -*/ - -/*! - \fn virtual void QAbstractAudioInput::setBufferSize(int value) - Sets the audio buffer size to \a value in milliseconds. -*/ - -/*! - \fn virtual int QAbstractAudioInput::bufferSize() const - Returns the audio buffer size in milliseconds. -*/ - -/*! - \fn virtual void QAbstractAudioInput::setNotifyInterval(int ms) - Sets the interval for notify() signal to be emitted. This is based - on the \a ms of audio data processed not on actual real-time. - The resolution of the timer is platform specific. -*/ - -/*! - \fn virtual int QAbstractAudioInput::notifyInterval() const - Returns the notify interval in milliseconds. -*/ - -/*! - \fn virtual qint64 QAbstractAudioInput::processedUSecs() const - Returns the amount of audio data processed since start() was called in milliseconds. -*/ - -/*! - \fn virtual qint64 QAbstractAudioInput::elapsedUSecs() const - Returns the milliseconds since start() was called, including time in Idle and suspend states. -*/ - -/*! - \fn virtual QAudio::Error QAbstractAudioInput::error() const - Returns the error state. -*/ - -/*! - \fn virtual QAudio::State QAbstractAudioInput::state() const - Returns the state of audio processing. -*/ - -/*! - \fn virtual QAudioFormat QAbstractAudioInput::format() const - Returns the QAudioFormat being used -*/ - -/*! - \fn QAbstractAudioInput::stateChanged(QAudio::State state) - This signal is emitted when the device \a state has changed. -*/ - -/*! - \fn QAbstractAudioInput::notify() - This signal is emitted when x ms of audio data has been processed - the interval set by setNotifyInterval(x). -*/ - - -QT_END_NAMESPACE diff --git a/src/multimedia/audio/qaudioengine.h b/src/multimedia/audio/qaudioengine.h deleted file mode 100644 index df9d09d..0000000 --- a/src/multimedia/audio/qaudioengine.h +++ /dev/null @@ -1,131 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtMultimedia module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QAUDIOENGINE_H -#define QAUDIOENGINE_H - -#include -#include -#include -#include - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Multimedia) - -class Q_MULTIMEDIA_EXPORT QAbstractAudioDeviceInfo : public QObject -{ - Q_OBJECT - -public: - virtual QAudioFormat preferredFormat() const = 0; - virtual bool isFormatSupported(const QAudioFormat &format) const = 0; - virtual QAudioFormat nearestFormat(const QAudioFormat &format) const = 0; - virtual QString deviceName() const = 0; - virtual QStringList codecList() = 0; - virtual QList frequencyList() = 0; - virtual QList channelsList() = 0; - virtual QList sampleSizeList() = 0; - virtual QList byteOrderList() = 0; - virtual QList sampleTypeList() = 0; -}; - -class Q_MULTIMEDIA_EXPORT QAbstractAudioOutput : public QObject -{ - Q_OBJECT - -public: - virtual QIODevice* start(QIODevice* device) = 0; - virtual void stop() = 0; - virtual void reset() = 0; - virtual void suspend() = 0; - virtual void resume() = 0; - virtual int bytesFree() const = 0; - virtual int periodSize() const = 0; - virtual void setBufferSize(int value) = 0; - virtual int bufferSize() const = 0; - virtual void setNotifyInterval(int milliSeconds) = 0; - virtual int notifyInterval() const = 0; - virtual qint64 processedUSecs() const = 0; - virtual qint64 elapsedUSecs() const = 0; - virtual QAudio::Error error() const = 0; - virtual QAudio::State state() const = 0; - virtual QAudioFormat format() const = 0; - -Q_SIGNALS: - void stateChanged(QAudio::State); - void notify(); -}; - -class Q_MULTIMEDIA_EXPORT QAbstractAudioInput : public QObject -{ - Q_OBJECT - -public: - virtual QIODevice* start(QIODevice* device) = 0; - virtual void stop() = 0; - virtual void reset() = 0; - virtual void suspend() = 0; - virtual void resume() = 0; - virtual int bytesReady() const = 0; - virtual int periodSize() const = 0; - virtual void setBufferSize(int value) = 0; - virtual int bufferSize() const = 0; - virtual void setNotifyInterval(int milliSeconds) = 0; - virtual int notifyInterval() const = 0; - virtual qint64 processedUSecs() const = 0; - virtual qint64 elapsedUSecs() const = 0; - virtual QAudio::Error error() const = 0; - virtual QAudio::State state() const = 0; - virtual QAudioFormat format() const = 0; - -Q_SIGNALS: - void stateChanged(QAudio::State); - void notify(); -}; - -QT_END_NAMESPACE - -QT_END_HEADER - -#endif // QAUDIOENGINE_H diff --git a/src/multimedia/audio/qaudioengineplugin.cpp b/src/multimedia/audio/qaudioengineplugin.cpp deleted file mode 100644 index 82324b5..0000000 --- a/src/multimedia/audio/qaudioengineplugin.cpp +++ /dev/null @@ -1,54 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtMultimedia module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - - -#include - -QT_BEGIN_NAMESPACE - -QAudioEnginePlugin::QAudioEnginePlugin(QObject* parent) : - QObject(parent) -{} - -QAudioEnginePlugin::~QAudioEnginePlugin() -{} - -QT_END_NAMESPACE diff --git a/src/multimedia/audio/qaudioengineplugin.h b/src/multimedia/audio/qaudioengineplugin.h deleted file mode 100644 index 2322d2a..0000000 --- a/src/multimedia/audio/qaudioengineplugin.h +++ /dev/null @@ -1,93 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtMultimedia module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - - -#ifndef QAUDIOENGINEPLUGIN_H -#define QAUDIOENGINEPLUGIN_H - -#include -#include -#include - -#include -#include -#include - - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Multimedia) - -struct Q_MULTIMEDIA_EXPORT QAudioEngineFactoryInterface : public QFactoryInterface -{ - virtual QList availableDevices(QAudio::Mode) const = 0; - virtual QAbstractAudioInput* createInput(const QByteArray& device, const QAudioFormat& format = QAudioFormat()) = 0; - virtual QAbstractAudioOutput* createOutput(const QByteArray& device, const QAudioFormat& format = QAudioFormat()) = 0; - virtual QAbstractAudioDeviceInfo* createDeviceInfo(const QByteArray& device, QAudio::Mode mode) = 0; -}; - -#define QAudioEngineFactoryInterface_iid \ - "com.nokia.qt.QAudioEngineFactoryInterface" -Q_DECLARE_INTERFACE(QAudioEngineFactoryInterface, QAudioEngineFactoryInterface_iid) - -class Q_MULTIMEDIA_EXPORT QAudioEnginePlugin : public QObject, public QAudioEngineFactoryInterface -{ - Q_OBJECT - Q_INTERFACES(QAudioEngineFactoryInterface:QFactoryInterface) - -public: - QAudioEnginePlugin(QObject *parent = 0); - ~QAudioEnginePlugin(); - - virtual QStringList keys() const = 0; - virtual QList availableDevices(QAudio::Mode) const = 0; - virtual QAbstractAudioInput* createInput(const QByteArray& device, const QAudioFormat& format = QAudioFormat()) = 0; - virtual QAbstractAudioOutput* createOutput(const QByteArray& device, const QAudioFormat& format = QAudioFormat()) = 0; - virtual QAbstractAudioDeviceInfo* createDeviceInfo(const QByteArray& device, QAudio::Mode mode) = 0; -}; - -QT_END_NAMESPACE - -QT_END_HEADER - -#endif // QAUDIOENGINEPLUGIN_H diff --git a/src/multimedia/audio/qaudioformat.cpp b/src/multimedia/audio/qaudioformat.cpp deleted file mode 100644 index 86d72f6..0000000 --- a/src/multimedia/audio/qaudioformat.cpp +++ /dev/null @@ -1,407 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtMultimedia module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ -#include -#include - - -QT_BEGIN_NAMESPACE - - -class QAudioFormatPrivate : public QSharedData -{ -public: - QAudioFormatPrivate() - { - frequency = -1; - channels = -1; - sampleSize = -1; - byteOrder = QAudioFormat::Endian(QSysInfo::ByteOrder); - sampleType = QAudioFormat::Unknown; - } - - QAudioFormatPrivate(const QAudioFormatPrivate &other): - QSharedData(other), - codec(other.codec), - byteOrder(other.byteOrder), - sampleType(other.sampleType), - frequency(other.frequency), - channels(other.channels), - sampleSize(other.sampleSize) - { - } - - QAudioFormatPrivate& operator=(const QAudioFormatPrivate &other) - { - codec = other.codec; - byteOrder = other.byteOrder; - sampleType = other.sampleType; - frequency = other.frequency; - channels = other.channels; - sampleSize = other.sampleSize; - - return *this; - } - - QString codec; - QAudioFormat::Endian byteOrder; - QAudioFormat::SampleType sampleType; - int frequency; - int channels; - int sampleSize; -}; - -/*! - \class QAudioFormat - \brief The QAudioFormat class stores audio parameter information. - - \inmodule QtMultimedia - \ingroup multimedia - \since 4.6 - - An audio format specifies how data in an audio stream is arranged, - i.e, how the stream is to be interpreted. The encoding itself is - specified by the codec() used for the stream. - - In addition to the encoding, QAudioFormat contains other - parameters that further specify how the audio data is arranged. - These are the frequency, the number of channels, the sample size, - the sample type, and the byte order. The following table describes - these in more detail. - - \table - \header - \o Parameter - \o Description - \row - \o Sample Rate - \o Samples per second of audio data in Hertz. - \row - \o Number of channels - \o The number of audio channels (typically one for mono - or two for stereo) - \row - \o Sample size - \o How much data is stored in each sample (typically 8 - or 16 bits) - \row - \o Sample type - \o Numerical representation of sample (typically signed integer, - unsigned integer or float) - \row - \o Byte order - \o Byte ordering of sample (typically little endian, big endian) - \endtable - - You can obtain audio formats compatible with the audio device used - through functions in QAudioDeviceInfo. This class also lets you - query available parameter values for a device, so that you can set - the parameters yourself. See the QAudioDeviceInfo class - description for details. You need to know the format of the audio - streams you wish to play. Qt does not set up formats for you. -*/ - -/*! - Construct a new audio format. - - Values are initialized as follows: - \list - \o sampleRate() = -1 - \o channelCount() = -1 - \o sampleSize() = -1 - \o byteOrder() = QAudioFormat::Endian(QSysInfo::ByteOrder) - \o sampleType() = QAudioFormat::Unknown - \c codec() = "" - \endlist -*/ - -QAudioFormat::QAudioFormat(): - d(new QAudioFormatPrivate) -{ -} - -/*! - Construct a new audio format using \a other. -*/ - -QAudioFormat::QAudioFormat(const QAudioFormat &other): - d(other.d) -{ -} - -/*! - Destroy this audio format. -*/ - -QAudioFormat::~QAudioFormat() -{ -} - -/*! - Assigns \a other to this QAudioFormat implementation. -*/ - -QAudioFormat& QAudioFormat::operator=(const QAudioFormat &other) -{ - d = other.d; - return *this; -} - -/*! - Returns true if this QAudioFormat is equal to the \a other - QAudioFormat; otherwise returns false. - - All elements of QAudioFormat are used for the comparison. -*/ - -bool QAudioFormat::operator==(const QAudioFormat &other) const -{ - return d->frequency == other.d->frequency && - d->channels == other.d->channels && - d->sampleSize == other.d->sampleSize && - d->byteOrder == other.d->byteOrder && - d->codec == other.d->codec && - d->sampleType == other.d->sampleType; -} - -/*! - Returns true if this QAudioFormat is not equal to the \a other - QAudioFormat; otherwise returns false. - - All elements of QAudioFormat are used for the comparison. -*/ - -bool QAudioFormat::operator!=(const QAudioFormat& other) const -{ - return !(*this == other); -} - -/*! - Returns true if all of the parameters are valid. -*/ - -bool QAudioFormat::isValid() const -{ - return d->frequency != -1 && d->channels != -1 && d->sampleSize != -1 && - d->sampleType != QAudioFormat::Unknown && !d->codec.isEmpty(); -} - -/*! - Sets the sample rate to \a samplerate Hertz. - - \since 4.7 -*/ - -void QAudioFormat::setSampleRate(int samplerate) -{ - d->frequency = samplerate; -} - -/*! - \obsolete - - Use setSampleRate() instead. -*/ - -void QAudioFormat::setFrequency(int frequency) -{ - d->frequency = frequency; -} - -/*! - Returns the current sample rate in Hertz. - - \since 4.7 -*/ - -int QAudioFormat::sampleRate() const -{ - return d->frequency; -} - -/*! - \obsolete - - Use sampleRate() instead. -*/ - -int QAudioFormat::frequency() const -{ - return d->frequency; -} - -/*! - Sets the channel count to \a channels. - - \since 4.7 -*/ - -void QAudioFormat::setChannelCount(int channels) -{ - d->channels = channels; -} - -/*! - \obsolete - - Use setChannelCount() instead. -*/ - -void QAudioFormat::setChannels(int channels) -{ - d->channels = channels; -} - -/*! - Returns the current channel count value. - - \since 4.7 -*/ - -int QAudioFormat::channelCount() const -{ - return d->channels; -} - -/*! - \obsolete - - Use channelCount() instead. -*/ - -int QAudioFormat::channels() const -{ - return d->channels; -} - -/*! - Sets the sample size to the \a sampleSize specified. -*/ - -void QAudioFormat::setSampleSize(int sampleSize) -{ - d->sampleSize = sampleSize; -} - -/*! - Returns the current sample size value. -*/ - -int QAudioFormat::sampleSize() const -{ - return d->sampleSize; -} - -/*! - Sets the codec to \a codec. - - \sa QAudioDeviceInfo::supportedCodecs() -*/ - -void QAudioFormat::setCodec(const QString &codec) -{ - d->codec = codec; -} - -/*! - Returns the current codec value. - - \sa QAudioDeviceInfo::supportedCodecs() -*/ - -QString QAudioFormat::codec() const -{ - return d->codec; -} - -/*! - Sets the byteOrder to \a byteOrder. -*/ - -void QAudioFormat::setByteOrder(QAudioFormat::Endian byteOrder) -{ - d->byteOrder = byteOrder; -} - -/*! - Returns the current byteOrder value. -*/ - -QAudioFormat::Endian QAudioFormat::byteOrder() const -{ - return d->byteOrder; -} - -/*! - Sets the sampleType to \a sampleType. -*/ - -void QAudioFormat::setSampleType(QAudioFormat::SampleType sampleType) -{ - d->sampleType = sampleType; -} - -/*! - Returns the current SampleType value. -*/ - -QAudioFormat::SampleType QAudioFormat::sampleType() const -{ - return d->sampleType; -} - -/*! - \enum QAudioFormat::SampleType - - \value Unknown Not Set - \value SignedInt samples are signed integers - \value UnSignedInt samples are unsigned intergers - \value Float samples are floats -*/ - -/*! - \enum QAudioFormat::Endian - - \value BigEndian samples are big endian byte order - \value LittleEndian samples are little endian byte order -*/ - -QT_END_NAMESPACE - diff --git a/src/multimedia/audio/qaudioformat.h b/src/multimedia/audio/qaudioformat.h deleted file mode 100644 index 6c835b7..0000000 --- a/src/multimedia/audio/qaudioformat.h +++ /dev/null @@ -1,107 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtMultimedia module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - - -#ifndef QAUDIOFORMAT_H -#define QAUDIOFORMAT_H - -#include -#include -#include - - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Multimedia) - - -class QAudioFormatPrivate; - -class Q_MULTIMEDIA_EXPORT QAudioFormat -{ -public: - enum SampleType { Unknown, SignedInt, UnSignedInt, Float }; - enum Endian { BigEndian = QSysInfo::BigEndian, LittleEndian = QSysInfo::LittleEndian }; - - QAudioFormat(); - QAudioFormat(const QAudioFormat &other); - ~QAudioFormat(); - - QAudioFormat& operator=(const QAudioFormat &other); - bool operator==(const QAudioFormat &other) const; - bool operator!=(const QAudioFormat &other) const; - - bool isValid() const; - - void setFrequency(int frequency); - int frequency() const; - void setSampleRate(int sampleRate); - int sampleRate() const; - - void setChannels(int channels); - int channels() const; - void setChannelCount(int channelCount); - int channelCount() const; - - void setSampleSize(int sampleSize); - int sampleSize() const; - - void setCodec(const QString &codec); - QString codec() const; - - void setByteOrder(QAudioFormat::Endian byteOrder); - QAudioFormat::Endian byteOrder() const; - - void setSampleType(QAudioFormat::SampleType sampleType); - QAudioFormat::SampleType sampleType() const; - -private: - QSharedDataPointer d; -}; - - -QT_END_NAMESPACE - -QT_END_HEADER - -#endif // QAUDIOFORMAT_H diff --git a/src/multimedia/audio/qaudioinput.cpp b/src/multimedia/audio/qaudioinput.cpp deleted file mode 100644 index c99e870..0000000 --- a/src/multimedia/audio/qaudioinput.cpp +++ /dev/null @@ -1,432 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtMultimedia module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - - -#include -#include -#include -#include - -#include "qaudiodevicefactory_p.h" - -QT_BEGIN_NAMESPACE - -/*! - \class QAudioInput - \brief The QAudioInput class provides an interface for receiving audio data from an audio input device. - - \inmodule QtMultimedia - \ingroup multimedia - \since 4.6 - - You can construct an audio input with the system's - \l{QAudioDeviceInfo::defaultInputDevice()}{default audio input - device}. It is also possible to create QAudioInput with a - specific QAudioDeviceInfo. When you create the audio input, you - should also send in the QAudioFormat to be used for the recording - (see the QAudioFormat class description for details). - - To record to a file: - - QAudioInput lets you record audio with an audio input device. The - default constructor of this class will use the systems default - audio device, but you can also specify a QAudioDeviceInfo for a - specific device. You also need to pass in the QAudioFormat in - which you wish to record. - - Starting up the QAudioInput is simply a matter of calling start() - with a QIODevice opened for writing. For instance, to record to a - file, you can: - - \code - QFile outputFile; // class member. - QAudioInput* audio; // class member. - \endcode - - \code - { - outputFile.setFileName("/tmp/test.raw"); - outputFile.open( QIODevice::WriteOnly | QIODevice::Truncate ); - - QAudioFormat format; - // set up the format you want, eg. - format.setFrequency(8000); - format.setChannels(1); - format.setSampleSize(8); - format.setCodec("audio/pcm"); - format.setByteOrder(QAudioFormat::LittleEndian); - format.setSampleType(QAudioFormat::UnSignedInt); - - QAudioDeviceInfo info = QAudioDeviceInfo::defaultInputDevice(); - if (!info.isFormatSupported(format)) { - qWarning()<<"default format not supported try to use nearest"; - format = info.nearestFormat(format); - } - - audio = new QAudioInput(format, this); - QTimer::singleShot(3000, this, SLOT(stopRecording())); - audio->start(&outputFile); - // Records audio for 3000ms - } - \endcode - - This will start recording if the format specified is supported by - the input device (you can check this with - QAudioDeviceInfo::isFormatSupported(). In case there are any - snags, use the error() function to check what went wrong. We stop - recording in the \c stopRecording() slot. - - \code - void stopRecording() - { - audio->stop(); - outputFile->close(); - delete audio; - } - \endcode - - At any point in time, QAudioInput will be in one of four states: - active, suspended, stopped, or idle. These states are specified by - the QAudio::State enum. You can request a state change directly through - suspend(), resume(), stop(), reset(), and start(). The current - state is reported by state(). QAudioOutput will also signal you - when the state changes (stateChanged()). - - QAudioInput provides several ways of measuring the time that has - passed since the start() of the recording. The \c processedUSecs() - function returns the length of the stream in microseconds written, - i.e., it leaves out the times the audio input was suspended or idle. - The elapsedUSecs() function returns the time elapsed since start() was called regardless of - which states the QAudioInput has been in. - - If an error should occur, you can fetch its reason with error(). - The possible error reasons are described by the QAudio::Error - enum. The QAudioInput will enter the \l{QAudio::}{StoppedState} when - an error is encountered. Connect to the stateChanged() signal to - handle the error: - - \snippet doc/src/snippets/audio/main.cpp 0 - - \sa QAudioOutput, QAudioDeviceInfo - - \section1 Symbian Platform Security Requirements - - On Symbian, processes which use this class must have the - \c UserEnvironment platform security capability. If the client - process lacks this capability, calls to either overload of start() - will fail. - This failure is indicated by the QAudioInput object setting - its error() value to \l{QAudio::OpenError} and then emitting a - \l{stateChanged()}{stateChanged}(\l{QAudio::StoppedState}) signal. - - Platform security capabilities are added via the - \l{qmake-variable-reference.html#target-capability}{TARGET.CAPABILITY} - qmake variable. -*/ - -/*! - Construct a new audio input and attach it to \a parent. - The default audio input device is used with the output - \a format parameters. -*/ - -QAudioInput::QAudioInput(const QAudioFormat &format, QObject *parent): - QObject(parent) -{ - d = QAudioDeviceFactory::createDefaultInputDevice(format); - connect(d, SIGNAL(notify()), SIGNAL(notify())); - connect(d, SIGNAL(stateChanged(QAudio::State)), SIGNAL(stateChanged(QAudio::State))); -} - -/*! - Construct a new audio input and attach it to \a parent. - The device referenced by \a audioDevice is used with the input - \a format parameters. -*/ - -QAudioInput::QAudioInput(const QAudioDeviceInfo &audioDevice, const QAudioFormat &format, QObject *parent): - QObject(parent) -{ - d = QAudioDeviceFactory::createInputDevice(audioDevice, format); - connect(d, SIGNAL(notify()), SIGNAL(notify())); - connect(d, SIGNAL(stateChanged(QAudio::State)), SIGNAL(stateChanged(QAudio::State))); -} - -/*! - Destroy this audio input. -*/ - -QAudioInput::~QAudioInput() -{ - delete d; -} - -/*! - Uses the \a device as the QIODevice to transfer data. - Passing a QIODevice allows the data to be transfered without any extra code. - All that is required is to open the QIODevice. - - If able to successfully get audio data from the systems audio device the - state() is set to either QAudio::ActiveState or QAudio::IdleState, - error() is set to QAudio::NoError and the stateChanged() signal is emitted. - - If a problem occurs during this process the error() is set to QAudio::OpenError, - state() is set to QAudio::StoppedState and stateChanged() signal is emitted. - - \sa {Symbian Platform Security Requirements} - - \sa QIODevice -*/ - -void QAudioInput::start(QIODevice* device) -{ - d->start(device); -} - -/*! - Returns a pointer to the QIODevice being used to handle the data - transfer. This QIODevice can be used to read() audio data - directly. - - If able to access the systems audio device the state() is set to - QAudio::IdleState, error() is set to QAudio::NoError - and the stateChanged() signal is emitted. - - If a problem occurs during this process the error() is set to QAudio::OpenError, - state() is set to QAudio::StoppedState and stateChanged() signal is emitted. - - \sa {Symbian Platform Security Requirements} - - \sa QIODevice -*/ - -QIODevice* QAudioInput::start() -{ - return d->start(0); -} - -/*! - Returns the QAudioFormat being used. -*/ - -QAudioFormat QAudioInput::format() const -{ - return d->format(); -} - -/*! - Stops the audio input, detaching from the system resource. - - Sets error() to QAudio::NoError, state() to QAudio::StoppedState and - emit stateChanged() signal. -*/ - -void QAudioInput::stop() -{ - d->stop(); -} - -/*! - Drops all audio data in the buffers, resets buffers to zero. -*/ - -void QAudioInput::reset() -{ - d->reset(); -} - -/*! - Stops processing audio data, preserving buffered audio data. - - Sets error() to QAudio::NoError, state() to QAudio::SuspendedState and - emit stateChanged() signal. -*/ - -void QAudioInput::suspend() -{ - d->suspend(); -} - -/*! - Resumes processing audio data after a suspend(). - - Sets error() to QAudio::NoError. - Sets state() to QAudio::ActiveState if you previously called start(QIODevice*). - Sets state() to QAudio::IdleState if you previously called start(). - emits stateChanged() signal. -*/ - -void QAudioInput::resume() -{ - d->resume(); -} - -/*! - Sets the audio buffer size to \a value milliseconds. - - Note: This function can be called anytime before start(), calls to this - are ignored after start(). It should not be assumed that the buffer size - set is the actual buffer size used, calling bufferSize() anytime after start() - will return the actual buffer size being used. - -*/ - -void QAudioInput::setBufferSize(int value) -{ - d->setBufferSize(value); -} - -/*! - Returns the audio buffer size in milliseconds. - - If called before start(), returns platform default value. - If called before start() but setBufferSize() was called prior, returns value set by setBufferSize(). - If called after start(), returns the actual buffer size being used. This may not be what was set previously - by setBufferSize(). - -*/ - -int QAudioInput::bufferSize() const -{ - return d->bufferSize(); -} - -/*! - Returns the amount of audio data available to read in bytes. - - NOTE: returned value is only valid while in QAudio::ActiveState or QAudio::IdleState - state, otherwise returns zero. -*/ - -int QAudioInput::bytesReady() const -{ - /* - -If not ActiveState|IdleState, return 0 - -return amount of audio data available to read - */ - return d->bytesReady(); -} - -/*! - Returns the period size in bytes. - - Note: This is the recommended read size in bytes. -*/ - -int QAudioInput::periodSize() const -{ - return d->periodSize(); -} - -/*! - Sets the interval for notify() signal to be emitted. - This is based on the \a ms of audio data processed - not on actual real-time. - The minimum resolution of the timer is platform specific and values - should be checked with notifyInterval() to confirm actual value - being used. -*/ - -void QAudioInput::setNotifyInterval(int ms) -{ - d->setNotifyInterval(ms); -} - -/*! - Returns the notify interval in milliseconds. -*/ - -int QAudioInput::notifyInterval() const -{ - return d->notifyInterval(); -} - -/*! - Returns the amount of audio data processed since start() - was called in microseconds. -*/ - -qint64 QAudioInput::processedUSecs() const -{ - return d->processedUSecs(); -} - -/*! - Returns the microseconds since start() was called, including time in Idle and - Suspend states. -*/ - -qint64 QAudioInput::elapsedUSecs() const -{ - return d->elapsedUSecs(); -} - -/*! - Returns the error state. -*/ - -QAudio::Error QAudioInput::error() const -{ - return d->error(); -} - -/*! - Returns the state of audio processing. -*/ - -QAudio::State QAudioInput::state() const -{ - return d->state(); -} - -/*! - \fn QAudioInput::stateChanged(QAudio::State state) - This signal is emitted when the device \a state has changed. -*/ - -/*! - \fn QAudioInput::notify() - This signal is emitted when x ms of audio data has been processed - the interval set by setNotifyInterval(x). -*/ - -QT_END_NAMESPACE - diff --git a/src/multimedia/audio/qaudioinput.h b/src/multimedia/audio/qaudioinput.h deleted file mode 100644 index 5be9b5a..0000000 --- a/src/multimedia/audio/qaudioinput.h +++ /dev/null @@ -1,111 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtMultimedia module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - - -#ifndef QAUDIOINPUT_H -#define QAUDIOINPUT_H - -#include -#include - -#include -#include -#include - - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Multimedia) - - -class QAbstractAudioInput; - -class Q_MULTIMEDIA_EXPORT QAudioInput : public QObject -{ - Q_OBJECT - -public: - explicit QAudioInput(const QAudioFormat &format = QAudioFormat(), QObject *parent = 0); - explicit QAudioInput(const QAudioDeviceInfo &audioDeviceInfo, const QAudioFormat &format = QAudioFormat(), QObject *parent = 0); - ~QAudioInput(); - - QAudioFormat format() const; - - void start(QIODevice *device); - QIODevice* start(); - - void stop(); - void reset(); - void suspend(); - void resume(); - - void setBufferSize(int bytes); - int bufferSize() const; - - int bytesReady() const; - int periodSize() const; - - void setNotifyInterval(int milliSeconds); - int notifyInterval() const; - - qint64 processedUSecs() const; - qint64 elapsedUSecs() const; - - QAudio::Error error() const; - QAudio::State state() const; - -Q_SIGNALS: - void stateChanged(QAudio::State); - void notify(); - -private: - Q_DISABLE_COPY(QAudioInput) - - QAbstractAudioInput* d; -}; - -QT_END_NAMESPACE - -QT_END_HEADER - -#endif // QAUDIOINPUT_H diff --git a/src/multimedia/audio/qaudioinput_alsa_p.cpp b/src/multimedia/audio/qaudioinput_alsa_p.cpp deleted file mode 100644 index 6b15008..0000000 --- a/src/multimedia/audio/qaudioinput_alsa_p.cpp +++ /dev/null @@ -1,706 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtMultimedia module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -// -// W A R N I N G -// ------------- -// -// This file is not part of the Qt API. It exists for the convenience -// of other Qt classes. This header file may change from version to -// version without notice, or even be removed. -// -// We mean it. -// - -#include -#include "qaudioinput_alsa_p.h" -#include "qaudiodeviceinfo_alsa_p.h" - -QT_BEGIN_NAMESPACE - -//#define DEBUG_AUDIO 1 - -static const int minimumIntervalTime = 50; - -QAudioInputPrivate::QAudioInputPrivate(const QByteArray &device, const QAudioFormat& audioFormat): - settings(audioFormat) -{ - bytesAvailable = 0; - handle = 0; - ahandler = 0; - access = SND_PCM_ACCESS_RW_INTERLEAVED; - pcmformat = SND_PCM_FORMAT_S16; - buffer_size = 0; - period_size = 0; - buffer_time = 100000; - period_time = 20000; - totalTimeValue = 0; - intervalTime = 1000; - audioBuffer = 0; - errorState = QAudio::NoError; - deviceState = QAudio::StoppedState; - audioSource = 0; - pullMode = true; - resuming = false; - - m_device = device; - - timer = new QTimer(this); - connect(timer,SIGNAL(timeout()),SLOT(userFeed())); -} - -QAudioInputPrivate::~QAudioInputPrivate() -{ - close(); - disconnect(timer, SIGNAL(timeout())); - QCoreApplication::processEvents(); - delete timer; -} - -QAudio::Error QAudioInputPrivate::error() const -{ - return errorState; -} - -QAudio::State QAudioInputPrivate::state() const -{ - return deviceState; -} - - -QAudioFormat QAudioInputPrivate::format() const -{ - return settings; -} - -int QAudioInputPrivate::xrun_recovery(int err) -{ - int count = 0; - bool reset = false; - - if(err == -EPIPE) { - errorState = QAudio::UnderrunError; - err = snd_pcm_prepare(handle); - if(err < 0) - reset = true; - else { - bytesAvailable = bytesReady(); - if (bytesAvailable <= 0) - reset = true; - } - - } else if((err == -ESTRPIPE)||(err == -EIO)) { - errorState = QAudio::IOError; - while((err = snd_pcm_resume(handle)) == -EAGAIN){ - usleep(100); - count++; - if(count > 5) { - reset = true; - break; - } - } - if(err < 0) { - err = snd_pcm_prepare(handle); - if(err < 0) - reset = true; - } - } - if(reset) { - close(); - open(); - snd_pcm_prepare(handle); - return 0; - } - return err; -} - -int QAudioInputPrivate::setFormat() -{ - snd_pcm_format_t format = SND_PCM_FORMAT_S16; - - if(settings.sampleSize() == 8) { - format = SND_PCM_FORMAT_U8; - } else if(settings.sampleSize() == 16) { - if(settings.sampleType() == QAudioFormat::SignedInt) { - if(settings.byteOrder() == QAudioFormat::LittleEndian) - format = SND_PCM_FORMAT_S16_LE; - else - format = SND_PCM_FORMAT_S16_BE; - } else if(settings.sampleType() == QAudioFormat::UnSignedInt) { - if(settings.byteOrder() == QAudioFormat::LittleEndian) - format = SND_PCM_FORMAT_U16_LE; - else - format = SND_PCM_FORMAT_U16_BE; - } - } else if(settings.sampleSize() == 24) { - if(settings.sampleType() == QAudioFormat::SignedInt) { - if(settings.byteOrder() == QAudioFormat::LittleEndian) - format = SND_PCM_FORMAT_S24_LE; - else - format = SND_PCM_FORMAT_S24_BE; - } else if(settings.sampleType() == QAudioFormat::UnSignedInt) { - if(settings.byteOrder() == QAudioFormat::LittleEndian) - format = SND_PCM_FORMAT_U24_LE; - else - format = SND_PCM_FORMAT_U24_BE; - } - } else if(settings.sampleSize() == 32) { - if(settings.sampleType() == QAudioFormat::SignedInt) { - if(settings.byteOrder() == QAudioFormat::LittleEndian) - format = SND_PCM_FORMAT_S32_LE; - else - format = SND_PCM_FORMAT_S32_BE; - } else if(settings.sampleType() == QAudioFormat::UnSignedInt) { - if(settings.byteOrder() == QAudioFormat::LittleEndian) - format = SND_PCM_FORMAT_U32_LE; - else - format = SND_PCM_FORMAT_U32_BE; - } else if(settings.sampleType() == QAudioFormat::Float) { - if(settings.byteOrder() == QAudioFormat::LittleEndian) - format = SND_PCM_FORMAT_FLOAT_LE; - else - format = SND_PCM_FORMAT_FLOAT_BE; - } - } else if(settings.sampleSize() == 64) { - if(settings.byteOrder() == QAudioFormat::LittleEndian) - format = SND_PCM_FORMAT_FLOAT64_LE; - else - format = SND_PCM_FORMAT_FLOAT64_BE; - } - - return snd_pcm_hw_params_set_format( handle, hwparams, format); -} - -QIODevice* QAudioInputPrivate::start(QIODevice* device) -{ - if(deviceState != QAudio::StoppedState) - close(); - - if(!pullMode && audioSource) { - delete audioSource; - } - - if(device) { - //set to pull mode - pullMode = true; - audioSource = device; - deviceState = QAudio::ActiveState; - } else { - //set to push mode - pullMode = false; - deviceState = QAudio::IdleState; - audioSource = new InputPrivate(this); - audioSource->open(QIODevice::ReadOnly | QIODevice::Unbuffered); - } - - if( !open() ) - return 0; - - emit stateChanged(deviceState); - - return audioSource; -} - -void QAudioInputPrivate::stop() -{ - if(deviceState == QAudio::StoppedState) - return; - - deviceState = QAudio::StoppedState; - - close(); - emit stateChanged(deviceState); -} - -bool QAudioInputPrivate::open() -{ -#ifdef DEBUG_AUDIO - QTime now(QTime::currentTime()); - qDebug()< devices = QAudioDeviceInfoInternal::availableDevices(QAudio::AudioInput); - if(dev.compare(QLatin1String("default")) == 0) { -#if(SND_LIB_MAJOR == 1 && SND_LIB_MINOR == 0 && SND_LIB_SUBMINOR >= 14) - dev = QLatin1String(devices.first()); -#else - dev = QLatin1String("hw:0,0"); -#endif - } else { -#if(SND_LIB_MAJOR == 1 && SND_LIB_MINOR == 0 && SND_LIB_SUBMINOR >= 14) - dev = QLatin1String(m_device); -#else - int idx = 0; - char *name; - - QString shortName = QLatin1String(m_device.mid(m_device.indexOf('=',0)+1).constData()); - - while(snd_card_get_name(idx,&name) == 0) { - if(qstrncmp(shortName.toLocal8Bit().constData(),name,shortName.length()) == 0) - break; - idx++; - } - dev = QString(QLatin1String("hw:%1,0")).arg(idx); -#endif - } - - // Step 1: try and open the device - while((count < 5) && (err < 0)) { - err=snd_pcm_open(&handle,dev.toLocal8Bit().constData(),SND_PCM_STREAM_CAPTURE,0); - if(err < 0) - count++; - } - if (( err < 0)||(handle == 0)) { - errorState = QAudio::OpenError; - deviceState = QAudio::StoppedState; - emit stateChanged(deviceState); - return false; - } - snd_pcm_nonblock( handle, 0 ); - - // Step 2: Set the desired HW parameters. - snd_pcm_hw_params_alloca( &hwparams ); - - bool fatal = false; - QString errMessage; - unsigned int chunks = 8; - - err = snd_pcm_hw_params_any( handle, hwparams ); - if ( err < 0 ) { - fatal = true; - errMessage = QString::fromLatin1("QAudioInput: snd_pcm_hw_params_any: err = %1").arg(err); - } - if ( !fatal ) { - err = snd_pcm_hw_params_set_rate_resample( handle, hwparams, 1 ); - if ( err < 0 ) { - fatal = true; - errMessage = QString::fromLatin1("QAudioInput: snd_pcm_hw_params_set_rate_resample: err = %1").arg(err); - } - } - if ( !fatal ) { - err = snd_pcm_hw_params_set_access( handle, hwparams, access ); - if ( err < 0 ) { - fatal = true; - errMessage = QString::fromLatin1("QAudioInput: snd_pcm_hw_params_set_access: err = %1").arg(err); - } - } - if ( !fatal ) { - err = setFormat(); - if ( err < 0 ) { - fatal = true; - errMessage = QString::fromLatin1("QAudioInput: snd_pcm_hw_params_set_format: err = %1").arg(err); - } - } - if ( !fatal ) { - err = snd_pcm_hw_params_set_channels( handle, hwparams, (unsigned int)settings.channels() ); - if ( err < 0 ) { - fatal = true; - errMessage = QString::fromLatin1("QAudioInput: snd_pcm_hw_params_set_channels: err = %1").arg(err); - } - } - if ( !fatal ) { - err = snd_pcm_hw_params_set_rate_near( handle, hwparams, &freakuency, 0 ); - if ( err < 0 ) { - fatal = true; - errMessage = QString::fromLatin1("QAudioInput: snd_pcm_hw_params_set_rate_near: err = %1").arg(err); - } - } - if ( !fatal ) { - err = snd_pcm_hw_params_set_buffer_time_near(handle, hwparams, &buffer_time, &dir); - if ( err < 0 ) { - fatal = true; - errMessage = QString::fromLatin1("QAudioInput: snd_pcm_hw_params_set_buffer_time_near: err = %1").arg(err); - } - } - if ( !fatal ) { - err = snd_pcm_hw_params_set_period_time_near(handle, hwparams, &period_time, &dir); - if ( err < 0 ) { - fatal = true; - errMessage = QString::fromLatin1("QAudioInput: snd_pcm_hw_params_set_period_time_near: err = %1").arg(err); - } - } - if ( !fatal ) { - err = snd_pcm_hw_params_set_periods_near(handle, hwparams, &chunks, &dir); - if ( err < 0 ) { - fatal = true; - errMessage = QString::fromLatin1("QAudioInput: snd_pcm_hw_params_set_periods_near: err = %1").arg(err); - } - } - if ( !fatal ) { - err = snd_pcm_hw_params(handle, hwparams); - if ( err < 0 ) { - fatal = true; - errMessage = QString::fromLatin1("QAudioInput: snd_pcm_hw_params: err = %1").arg(err); - } - } - if( err < 0) { - qWarning()<start(period_time*chunks/2000); - - errorState = QAudio::NoError; - - totalTimeValue = 0; - - return true; -} - -void QAudioInputPrivate::close() -{ - timer->stop(); - - if ( handle ) { - snd_pcm_drop( handle ); - snd_pcm_close( handle ); - handle = 0; - delete [] audioBuffer; - audioBuffer=0; - } -} - -int QAudioInputPrivate::bytesReady() const -{ - if(resuming) - return period_size; - - if(deviceState != QAudio::ActiveState && deviceState != QAudio::IdleState) - return 0; - int frames = snd_pcm_avail_update(handle); - if (frames < 0) return frames; - if((int)frames > (int)buffer_frames) - frames = buffer_frames; - - return snd_pcm_frames_to_bytes(handle, frames); -} - -qint64 QAudioInputPrivate::read(char* data, qint64 len) -{ - Q_UNUSED(len) - - // Read in some audio data and write it to QIODevice, pull mode - if ( !handle ) - return 0; - - bytesAvailable = bytesReady(); - - if (bytesAvailable < 0) { - // bytesAvailable as negative is error code, try to recover from it. - xrun_recovery(bytesAvailable); - bytesAvailable = bytesReady(); - if (bytesAvailable < 0) { - // recovery failed must stop and set error. - close(); - errorState = QAudio::IOError; - deviceState = QAudio::StoppedState; - emit stateChanged(deviceState); - return 0; - } - } - - int count=0, err = 0; - while(count < 5) { - int chunks = bytesAvailable/period_size; - int frames = chunks*period_frames; - if(frames > (int)buffer_frames) - frames = buffer_frames; - int readFrames = snd_pcm_readi(handle, audioBuffer, frames); - if (readFrames >= 0) { - err = snd_pcm_frames_to_bytes(handle, readFrames); -#ifdef DEBUG_AUDIO - qDebug()< 0) { - // got some send it onward -#ifdef DEBUG_AUDIO - qDebug()<<"frames to write to QIODevice = "<< - snd_pcm_bytes_to_frames( handle, (int)err )<<" ("<write(audioBuffer,err); - if(l < 0) { - close(); - errorState = QAudio::IOError; - deviceState = QAudio::StoppedState; - emit stateChanged(deviceState); - } else if(l == 0) { - if (deviceState != QAudio::IdleState) { - errorState = QAudio::NoError; - deviceState = QAudio::IdleState; - emit stateChanged(deviceState); - } - } else { - totalTimeValue += err; - resuming = false; - if (deviceState != QAudio::ActiveState) { - errorState = QAudio::NoError; - deviceState = QAudio::ActiveState; - emit stateChanged(deviceState); - } - } - return l; - - } else { - memcpy(data,audioBuffer,err); - totalTimeValue += err; - resuming = false; - if (deviceState != QAudio::ActiveState) { - errorState = QAudio::NoError; - deviceState = QAudio::ActiveState; - emit stateChanged(deviceState); - } - return err; - } - } - return 0; -} - -void QAudioInputPrivate::resume() -{ - if(deviceState == QAudio::SuspendedState) { - int err = 0; - - if(handle) { - err = snd_pcm_prepare( handle ); - if(err < 0) - xrun_recovery(err); - - err = snd_pcm_start(handle); - if(err < 0) - xrun_recovery(err); - - bytesAvailable = buffer_size; - } - resuming = true; - deviceState = QAudio::ActiveState; - int chunks = buffer_size/period_size; - timer->start(period_time*chunks/2000); - emit stateChanged(deviceState); - } -} - -void QAudioInputPrivate::setBufferSize(int value) -{ - buffer_size = value; -} - -int QAudioInputPrivate::bufferSize() const -{ - return buffer_size; -} - -int QAudioInputPrivate::periodSize() const -{ - return period_size; -} - -void QAudioInputPrivate::setNotifyInterval(int ms) -{ - if(ms >= minimumIntervalTime) - intervalTime = ms; - else - intervalTime = minimumIntervalTime; -} - -int QAudioInputPrivate::notifyInterval() const -{ - return intervalTime; -} - -qint64 QAudioInputPrivate::processedUSecs() const -{ - qint64 result = qint64(1000000) * totalTimeValue / - (settings.channels()*(settings.sampleSize()/8)) / - settings.frequency(); - - return result; -} - -void QAudioInputPrivate::suspend() -{ - if(deviceState == QAudio::ActiveState||resuming) { - timer->stop(); - deviceState = QAudio::SuspendedState; - emit stateChanged(deviceState); - } -} - -void QAudioInputPrivate::userFeed() -{ - if(deviceState == QAudio::StoppedState || deviceState == QAudio::SuspendedState) - return; -#ifdef DEBUG_AUDIO - QTime now(QTime::currentTime()); - qDebug()<(audioSource); - a->trigger(); - } - bytesAvailable = bytesReady(); - - if(deviceState != QAudio::ActiveState) - return true; - - if((timeStamp.elapsed() + elapsedTimeOffset) > intervalTime) { - emit notify(); - elapsedTimeOffset = timeStamp.elapsed() + elapsedTimeOffset - intervalTime; - timeStamp.restart(); - } - return true; -} - -qint64 QAudioInputPrivate::elapsedUSecs() const -{ - if (deviceState == QAudio::StoppedState) - return 0; - - return clockStamp.elapsed()*1000; -} - -void QAudioInputPrivate::reset() -{ - if(handle) - snd_pcm_reset(handle); -} - -void QAudioInputPrivate::drain() -{ - if(handle) - snd_pcm_drain(handle); -} - -InputPrivate::InputPrivate(QAudioInputPrivate* audio) -{ - audioDevice = qobject_cast(audio); -} - -InputPrivate::~InputPrivate() -{ -} - -qint64 InputPrivate::readData( char* data, qint64 len) -{ - return audioDevice->read(data,len); -} - -qint64 InputPrivate::writeData(const char* data, qint64 len) -{ - Q_UNUSED(data) - Q_UNUSED(len) - return 0; -} - -void InputPrivate::trigger() -{ - emit readyRead(); -} - -QT_END_NAMESPACE diff --git a/src/multimedia/audio/qaudioinput_alsa_p.h b/src/multimedia/audio/qaudioinput_alsa_p.h deleted file mode 100644 index c907019..0000000 --- a/src/multimedia/audio/qaudioinput_alsa_p.h +++ /dev/null @@ -1,158 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtMultimedia module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -// -// W A R N I N G -// ------------- -// -// This file is not part of the Qt API. It exists for the convenience -// of other Qt classes. This header file may change from version to -// version without notice, or even be removed. -// -// We mean it. -// - - -#ifndef QAUDIOINPUTALSA_H -#define QAUDIOINPUTALSA_H - -#include - -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include - -QT_BEGIN_NAMESPACE - -class InputPrivate; - -class QAudioInputPrivate : public QAbstractAudioInput -{ - Q_OBJECT -public: - QAudioInputPrivate(const QByteArray &device, const QAudioFormat& audioFormat); - ~QAudioInputPrivate(); - - qint64 read(char* data, qint64 len); - - QIODevice* start(QIODevice* device = 0); - void stop(); - void reset(); - void suspend(); - void resume(); - int bytesReady() const; - int periodSize() const; - void setBufferSize(int value); - int bufferSize() const; - void setNotifyInterval(int milliSeconds); - int notifyInterval() const; - qint64 processedUSecs() const; - qint64 elapsedUSecs() const; - QAudio::Error error() const; - QAudio::State state() const; - QAudioFormat format() const; - bool resuming; - snd_pcm_t* handle; - qint64 totalTimeValue; - QIODevice* audioSource; - QAudioFormat settings; - QAudio::Error errorState; - QAudio::State deviceState; - -private slots: - void userFeed(); - bool deviceReady(); - -private: - int xrun_recovery(int err); - int setFormat(); - bool open(); - void close(); - void drain(); - - QTimer* timer; - QElapsedTimer timeStamp; - QElapsedTimer clockStamp; - qint64 elapsedTimeOffset; - int intervalTime; - char* audioBuffer; - int bytesAvailable; - QByteArray m_device; - bool pullMode; - int buffer_size; - int period_size; - unsigned int buffer_time; - unsigned int period_time; - snd_pcm_uframes_t buffer_frames; - snd_pcm_uframes_t period_frames; - snd_async_handler_t* ahandler; - snd_pcm_access_t access; - snd_pcm_format_t pcmformat; - snd_timestamp_t* timestamp; - snd_pcm_hw_params_t *hwparams; -}; - -class InputPrivate : public QIODevice -{ - Q_OBJECT -public: - InputPrivate(QAudioInputPrivate* audio); - ~InputPrivate(); - - qint64 readData( char* data, qint64 len); - qint64 writeData(const char* data, qint64 len); - - void trigger(); -private: - QAudioInputPrivate *audioDevice; -}; - -QT_END_NAMESPACE - -#endif diff --git a/src/multimedia/audio/qaudioinput_mac_p.cpp b/src/multimedia/audio/qaudioinput_mac_p.cpp deleted file mode 100644 index cb65f6e..0000000 --- a/src/multimedia/audio/qaudioinput_mac_p.cpp +++ /dev/null @@ -1,956 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtMultimedia module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -// -// W A R N I N G -// ------------- -// -// This file is not part of the Qt API. It exists for the convenience -// of other Qt classes. This header file may change from version to -// version without notice, or even be removed. -// -// We mean it. -// - -#include -#include -#include - -#include - -#include "qaudio_mac_p.h" -#include "qaudioinput_mac_p.h" -#include "qaudiodeviceinfo_mac_p.h" - -QT_BEGIN_NAMESPACE - - -namespace QtMultimediaInternal -{ - -static const int default_buffer_size = 4 * 1024; - -class QAudioBufferList -{ -public: - QAudioBufferList(AudioStreamBasicDescription const& streamFormat): - owner(false), - sf(streamFormat) - { - const bool isInterleaved = (sf.mFormatFlags & kAudioFormatFlagIsNonInterleaved) == 0; - const int numberOfBuffers = isInterleaved ? 1 : sf.mChannelsPerFrame; - - dataSize = 0; - - bfs = reinterpret_cast(qMalloc(sizeof(AudioBufferList) + - (sizeof(AudioBuffer) * numberOfBuffers))); - - bfs->mNumberBuffers = numberOfBuffers; - for (int i = 0; i < numberOfBuffers; ++i) { - bfs->mBuffers[i].mNumberChannels = isInterleaved ? numberOfBuffers : 1; - bfs->mBuffers[i].mDataByteSize = 0; - bfs->mBuffers[i].mData = 0; - } - } - - QAudioBufferList(AudioStreamBasicDescription const& streamFormat, char* buffer, int bufferSize): - owner(false), - sf(streamFormat), - bfs(0) - { - dataSize = bufferSize; - - bfs = reinterpret_cast(qMalloc(sizeof(AudioBufferList) + sizeof(AudioBuffer))); - - bfs->mNumberBuffers = 1; - bfs->mBuffers[0].mNumberChannels = 1; - bfs->mBuffers[0].mDataByteSize = dataSize; - bfs->mBuffers[0].mData = buffer; - } - - QAudioBufferList(AudioStreamBasicDescription const& streamFormat, int framesToBuffer): - owner(true), - sf(streamFormat), - bfs(0) - { - const bool isInterleaved = (sf.mFormatFlags & kAudioFormatFlagIsNonInterleaved) == 0; - const int numberOfBuffers = isInterleaved ? 1 : sf.mChannelsPerFrame; - - dataSize = framesToBuffer * sf.mBytesPerFrame; - - bfs = reinterpret_cast(qMalloc(sizeof(AudioBufferList) + - (sizeof(AudioBuffer) * numberOfBuffers))); - bfs->mNumberBuffers = numberOfBuffers; - for (int i = 0; i < numberOfBuffers; ++i) { - bfs->mBuffers[i].mNumberChannels = isInterleaved ? numberOfBuffers : 1; - bfs->mBuffers[i].mDataByteSize = dataSize; - bfs->mBuffers[i].mData = qMalloc(dataSize); - } - } - - ~QAudioBufferList() - { - if (owner) { - for (UInt32 i = 0; i < bfs->mNumberBuffers; ++i) - qFree(bfs->mBuffers[i].mData); - } - - qFree(bfs); - } - - AudioBufferList* audioBufferList() const - { - return bfs; - } - - char* data(int buffer = 0) const - { - return static_cast(bfs->mBuffers[buffer].mData); - } - - qint64 bufferSize(int buffer = 0) const - { - return bfs->mBuffers[buffer].mDataByteSize; - } - - int frameCount(int buffer = 0) const - { - return bfs->mBuffers[buffer].mDataByteSize / sf.mBytesPerFrame; - } - - int packetCount(int buffer = 0) const - { - return bfs->mBuffers[buffer].mDataByteSize / sf.mBytesPerPacket; - } - - int packetSize() const - { - return sf.mBytesPerPacket; - } - - void reset() - { - for (UInt32 i = 0; i < bfs->mNumberBuffers; ++i) { - bfs->mBuffers[i].mDataByteSize = dataSize; - bfs->mBuffers[i].mData = 0; - } - } - -private: - bool owner; - int dataSize; - AudioStreamBasicDescription sf; - AudioBufferList* bfs; -}; - -class QAudioPacketFeeder -{ -public: - QAudioPacketFeeder(QAudioBufferList* abl): - audioBufferList(abl) - { - totalPackets = audioBufferList->packetCount(); - position = 0; - } - - bool feed(AudioBufferList& dst, UInt32& packetCount) - { - if (position == totalPackets) { - dst.mBuffers[0].mDataByteSize = 0; - packetCount = 0; - return false; - } - - if (totalPackets - position < packetCount) - packetCount = totalPackets - position; - - dst.mBuffers[0].mDataByteSize = packetCount * audioBufferList->packetSize(); - dst.mBuffers[0].mData = audioBufferList->data() + (position * audioBufferList->packetSize()); - - position += packetCount; - - return true; - } - -private: - UInt32 totalPackets; - UInt32 position; - QAudioBufferList* audioBufferList; -}; - -class QAudioInputBuffer : public QObject -{ - Q_OBJECT - -public: - QAudioInputBuffer(int bufferSize, - int maxPeriodSize, - AudioStreamBasicDescription const& inputFormat, - AudioStreamBasicDescription const& outputFormat, - QObject* parent): - QObject(parent), - m_deviceError(false), - m_audioConverter(0), - m_inputFormat(inputFormat), - m_outputFormat(outputFormat) - { - m_maxPeriodSize = maxPeriodSize; - m_periodTime = m_maxPeriodSize / m_outputFormat.mBytesPerFrame * 1000 / m_outputFormat.mSampleRate; - m_buffer = new QAudioRingBuffer(bufferSize + (bufferSize % maxPeriodSize == 0 ? 0 : maxPeriodSize - (bufferSize % maxPeriodSize))); - m_inputBufferList = new QAudioBufferList(m_inputFormat); - - m_flushTimer = new QTimer(this); - connect(m_flushTimer, SIGNAL(timeout()), SLOT(flushBuffer())); - - if (toQAudioFormat(inputFormat) != toQAudioFormat(outputFormat)) { - if (AudioConverterNew(&m_inputFormat, &m_outputFormat, &m_audioConverter) != noErr) { - qWarning() << "QAudioInput: Unable to create an Audio Converter"; - m_audioConverter = 0; - } - } - } - - ~QAudioInputBuffer() - { - delete m_buffer; - } - - qint64 renderFromDevice(AudioUnit audioUnit, - AudioUnitRenderActionFlags* ioActionFlags, - const AudioTimeStamp* inTimeStamp, - UInt32 inBusNumber, - UInt32 inNumberFrames) - { - const bool wasEmpty = m_buffer->used() == 0; - - OSStatus err; - qint64 framesRendered = 0; - - m_inputBufferList->reset(); - err = AudioUnitRender(audioUnit, - ioActionFlags, - inTimeStamp, - inBusNumber, - inNumberFrames, - m_inputBufferList->audioBufferList()); - - if (m_audioConverter != 0) { - QAudioPacketFeeder feeder(m_inputBufferList); - - bool wecan = true; - int copied = 0; - - const int available = m_buffer->free(); - - while (err == noErr && wecan) { - QAudioRingBuffer::Region region = m_buffer->acquireWriteRegion(available); - - if (region.second > 0) { - AudioBufferList output; - output.mNumberBuffers = 1; - output.mBuffers[0].mNumberChannels = 1; - output.mBuffers[0].mDataByteSize = region.second; - output.mBuffers[0].mData = region.first; - - UInt32 packetSize = region.second / m_outputFormat.mBytesPerPacket; - err = AudioConverterFillComplexBuffer(m_audioConverter, - converterCallback, - &feeder, - &packetSize, - &output, - 0); - - region.second = output.mBuffers[0].mDataByteSize; - copied += region.second; - - m_buffer->releaseWriteRegion(region); - } - else - wecan = false; - } - - framesRendered += copied / m_outputFormat.mBytesPerFrame; - } - else { - const int available = m_inputBufferList->bufferSize(); - bool wecan = true; - int copied = 0; - - while (wecan && copied < available) { - QAudioRingBuffer::Region region = m_buffer->acquireWriteRegion(available - copied); - - if (region.second > 0) { - memcpy(region.first, m_inputBufferList->data() + copied, region.second); - copied += region.second; - } - else - wecan = false; - - m_buffer->releaseWriteRegion(region); - } - - framesRendered = copied / m_outputFormat.mBytesPerFrame; - } - - if (wasEmpty && framesRendered > 0) - emit readyRead(); - - return framesRendered; - } - - qint64 readBytes(char* data, qint64 len) - { - bool wecan = true; - qint64 bytesCopied = 0; - - len -= len % m_maxPeriodSize; - while (wecan && bytesCopied < len) { - QAudioRingBuffer::Region region = m_buffer->acquireReadRegion(len - bytesCopied); - - if (region.second > 0) { - memcpy(data + bytesCopied, region.first, region.second); - bytesCopied += region.second; - } - else - wecan = false; - - m_buffer->releaseReadRegion(region); - } - - return bytesCopied; - } - - void setFlushDevice(QIODevice* device) - { - if (m_device != device) - m_device = device; - } - - void startFlushTimer() - { - if (m_device != 0) { - m_flushTimer->start((m_buffer->size() - (m_maxPeriodSize * 2)) / m_maxPeriodSize * m_periodTime); - } - } - - void stopFlushTimer() - { - m_flushTimer->stop(); - } - - void flush(bool all = false) - { - if (m_device == 0) - return; - - const int used = m_buffer->used(); - const int readSize = all ? used : used - (used % m_maxPeriodSize); - - if (readSize > 0) { - bool wecan = true; - int flushed = 0; - - while (!m_deviceError && wecan && flushed < readSize) { - QAudioRingBuffer::Region region = m_buffer->acquireReadRegion(readSize - flushed); - - if (region.second > 0) { - int bytesWritten = m_device->write(region.first, region.second); - if (bytesWritten < 0) { - stopFlushTimer(); - m_deviceError = true; - } - else { - region.second = bytesWritten; - flushed += bytesWritten; - wecan = bytesWritten != 0; - } - } - else - wecan = false; - - m_buffer->releaseReadRegion(region); - } - } - } - - void reset() - { - m_buffer->reset(); - m_deviceError = false; - } - - int available() const - { - return m_buffer->free(); - } - - int used() const - { - return m_buffer->used(); - } - -signals: - void readyRead(); - -private slots: - void flushBuffer() - { - flush(); - } - -private: - bool m_deviceError; - int m_maxPeriodSize; - int m_periodTime; - QIODevice* m_device; - QTimer* m_flushTimer; - QAudioRingBuffer* m_buffer; - QAudioBufferList* m_inputBufferList; - AudioConverterRef m_audioConverter; - AudioStreamBasicDescription m_inputFormat; - AudioStreamBasicDescription m_outputFormat; - - const static OSStatus as_empty = 'qtem'; - - // Converter callback - static OSStatus converterCallback(AudioConverterRef inAudioConverter, - UInt32* ioNumberDataPackets, - AudioBufferList* ioData, - AudioStreamPacketDescription** outDataPacketDescription, - void* inUserData) - { - Q_UNUSED(inAudioConverter); - Q_UNUSED(outDataPacketDescription); - - QAudioPacketFeeder* feeder = static_cast(inUserData); - - if (!feeder->feed(*ioData, *ioNumberDataPackets)) - return as_empty; - - return noErr; - } -}; - - -class MacInputDevice : public QIODevice -{ - Q_OBJECT - -public: - MacInputDevice(QAudioInputBuffer* audioBuffer, QObject* parent): - QIODevice(parent), - m_audioBuffer(audioBuffer) - { - open(QIODevice::ReadOnly | QIODevice::Unbuffered); - connect(m_audioBuffer, SIGNAL(readyRead()), SIGNAL(readyRead())); - } - - qint64 readData(char* data, qint64 len) - { - return m_audioBuffer->readBytes(data, len); - } - - qint64 writeData(const char* data, qint64 len) - { - Q_UNUSED(data); - Q_UNUSED(len); - - return 0; - } - - bool isSequential() const - { - return true; - } - -private: - QAudioInputBuffer* m_audioBuffer; -}; - -} - - -QAudioInputPrivate::QAudioInputPrivate(const QByteArray& device, QAudioFormat const& format): - audioFormat(format) -{ - QDataStream ds(device); - quint32 did, mode; - - ds >> did >> mode; - - if (QAudio::Mode(mode) == QAudio::AudioOutput) - errorCode = QAudio::OpenError; - else { - audioDeviceInfo = new QAudioDeviceInfoInternal(device, QAudio::AudioInput); - isOpen = false; - audioDeviceId = AudioDeviceID(did); - audioUnit = 0; - startTime = 0; - totalFrames = 0; - audioBuffer = 0; - internalBufferSize = QtMultimediaInternal::default_buffer_size; - clockFrequency = AudioGetHostClockFrequency() / 1000; - errorCode = QAudio::NoError; - stateCode = QAudio::StoppedState; - - intervalTimer = new QTimer(this); - intervalTimer->setInterval(1000); - connect(intervalTimer, SIGNAL(timeout()), SIGNAL(notify())); - } -} - -QAudioInputPrivate::~QAudioInputPrivate() -{ - close(); - delete audioDeviceInfo; -} - -bool QAudioInputPrivate::open() -{ - UInt32 size = 0; - - if (isOpen) - return true; - - ComponentDescription cd; - cd.componentType = kAudioUnitType_Output; - cd.componentSubType = kAudioUnitSubType_HALOutput; - cd.componentManufacturer = kAudioUnitManufacturer_Apple; - cd.componentFlags = 0; - cd.componentFlagsMask = 0; - - // Open - Component cp = FindNextComponent(NULL, &cd); - if (cp == 0) { - qWarning() << "QAudioInput: Failed to find HAL Output component"; - return false; - } - - if (OpenAComponent(cp, &audioUnit) != noErr) { - qWarning() << "QAudioInput: Unable to Open Output Component"; - return false; - } - - // Set mode - // switch to input mode - UInt32 enable = 1; - if (AudioUnitSetProperty(audioUnit, - kAudioOutputUnitProperty_EnableIO, - kAudioUnitScope_Input, - 1, - &enable, - sizeof(enable)) != noErr) { - qWarning() << "QAudioInput: Unable to switch to input mode (Enable Input)"; - return false; - } - - enable = 0; - if (AudioUnitSetProperty(audioUnit, - kAudioOutputUnitProperty_EnableIO, - kAudioUnitScope_Output, - 0, - &enable, - sizeof(enable)) != noErr) { - qWarning() << "QAudioInput: Unable to switch to input mode (Disable output)"; - return false; - } - - // register callback - AURenderCallbackStruct cb; - cb.inputProc = inputCallback; - cb.inputProcRefCon = this; - - if (AudioUnitSetProperty(audioUnit, - kAudioOutputUnitProperty_SetInputCallback, - kAudioUnitScope_Global, - 0, - &cb, - sizeof(cb)) != noErr) { - qWarning() << "QAudioInput: Failed to set AudioUnit callback"; - return false; - } - - // Set Audio Device - if (AudioUnitSetProperty(audioUnit, - kAudioOutputUnitProperty_CurrentDevice, - kAudioUnitScope_Global, - 0, - &audioDeviceId, - sizeof(audioDeviceId)) != noErr) { - qWarning() << "QAudioInput: Unable to use configured device"; - return false; - } - - // Set format - // Wanted - streamFormat = toAudioStreamBasicDescription(audioFormat); - - // Required on unit - if (audioFormat == audioDeviceInfo->preferredFormat()) { - deviceFormat = streamFormat; - AudioUnitSetProperty(audioUnit, - kAudioUnitProperty_StreamFormat, - kAudioUnitScope_Output, - 1, - &deviceFormat, - sizeof(deviceFormat)); - } - else { - size = sizeof(deviceFormat); - if (AudioUnitGetProperty(audioUnit, - kAudioUnitProperty_StreamFormat, - kAudioUnitScope_Input, - 1, - &deviceFormat, - &size) != noErr) { - qWarning() << "QAudioInput: Unable to retrieve device format"; - return false; - } - - if (AudioUnitSetProperty(audioUnit, - kAudioUnitProperty_StreamFormat, - kAudioUnitScope_Output, - 1, - &deviceFormat, - sizeof(deviceFormat)) != noErr) { - qWarning() << "QAudioInput: Unable to set device format"; - return false; - } - } - - // Setup buffers - UInt32 numberOfFrames; - size = sizeof(UInt32); - if (AudioUnitGetProperty(audioUnit, - kAudioDevicePropertyBufferFrameSize, - kAudioUnitScope_Global, - 0, - &numberOfFrames, - &size) != noErr) { - qWarning() << "QAudioInput: Failed to get audio period size"; - return false; - } - - // Allocate buffer - periodSizeBytes = numberOfFrames * streamFormat.mBytesPerFrame; - - if (internalBufferSize < periodSizeBytes * 2) - internalBufferSize = periodSizeBytes * 2; - else - internalBufferSize -= internalBufferSize % streamFormat.mBytesPerFrame; - - audioBuffer = new QtMultimediaInternal::QAudioInputBuffer(internalBufferSize, - periodSizeBytes, - deviceFormat, - streamFormat, - this); - - audioIO = new QtMultimediaInternal::MacInputDevice(audioBuffer, this); - - // Init - if (AudioUnitInitialize(audioUnit) != noErr) { - qWarning() << "QAudioInput: Failed to initialize AudioUnit"; - return false; - } - - isOpen = true; - - return isOpen; -} - -void QAudioInputPrivate::close() -{ - if (audioUnit != 0) { - AudioOutputUnitStop(audioUnit); - AudioUnitUninitialize(audioUnit); - CloseComponent(audioUnit); - } - - delete audioBuffer; -} - -QAudioFormat QAudioInputPrivate::format() const -{ - return audioFormat; -} - -QIODevice* QAudioInputPrivate::start(QIODevice* device) -{ - QIODevice* op = device; - - if (!audioFormat.isValid() || !open()) { - stateCode = QAudio::StoppedState; - errorCode = QAudio::OpenError; - return audioIO; - } - - reset(); - audioBuffer->reset(); - audioBuffer->setFlushDevice(op); - - if (op == 0) - op = audioIO; - - // Start - startTime = AudioGetCurrentHostTime(); - totalFrames = 0; - - audioThreadStart(); - - stateCode = QAudio::ActiveState; - errorCode = QAudio::NoError; - emit stateChanged(stateCode); - - return op; -} - -void QAudioInputPrivate::stop() -{ - QMutexLocker lock(&mutex); - if (stateCode != QAudio::StoppedState) { - audioThreadStop(); - audioBuffer->flush(true); - - errorCode = QAudio::NoError; - stateCode = QAudio::StoppedState; - QMetaObject::invokeMethod(this, "stateChanged", Qt::QueuedConnection, Q_ARG(QAudio::State, stateCode)); - } -} - -void QAudioInputPrivate::reset() -{ - QMutexLocker lock(&mutex); - if (stateCode != QAudio::StoppedState) { - audioThreadStop(); - - errorCode = QAudio::NoError; - stateCode = QAudio::StoppedState; - QMetaObject::invokeMethod(this, "stateChanged", Qt::QueuedConnection, Q_ARG(QAudio::State, stateCode)); - } -} - -void QAudioInputPrivate::suspend() -{ - QMutexLocker lock(&mutex); - if (stateCode == QAudio::ActiveState || stateCode == QAudio::IdleState) { - audioThreadStop(); - - errorCode = QAudio::NoError; - stateCode = QAudio::SuspendedState; - QMetaObject::invokeMethod(this, "stateChanged", Qt::QueuedConnection, Q_ARG(QAudio::State, stateCode)); - } -} - -void QAudioInputPrivate::resume() -{ - QMutexLocker lock(&mutex); - if (stateCode == QAudio::SuspendedState) { - audioThreadStart(); - - errorCode = QAudio::NoError; - stateCode = QAudio::ActiveState; - QMetaObject::invokeMethod(this, "stateChanged", Qt::QueuedConnection, Q_ARG(QAudio::State, stateCode)); - } -} - -int QAudioInputPrivate::bytesReady() const -{ - return audioBuffer->used(); -} - -int QAudioInputPrivate::periodSize() const -{ - return periodSizeBytes; -} - -void QAudioInputPrivate::setBufferSize(int bs) -{ - internalBufferSize = bs; -} - -int QAudioInputPrivate::bufferSize() const -{ - return internalBufferSize; -} - -void QAudioInputPrivate::setNotifyInterval(int milliSeconds) -{ - if (intervalTimer->interval() == milliSeconds) - return; - - if (milliSeconds <= 0) - milliSeconds = 0; - - intervalTimer->setInterval(milliSeconds); -} - -int QAudioInputPrivate::notifyInterval() const -{ - return intervalTimer->interval(); -} - -qint64 QAudioInputPrivate::processedUSecs() const -{ - return totalFrames * 1000000 / audioFormat.frequency(); -} - -qint64 QAudioInputPrivate::elapsedUSecs() const -{ - if (stateCode == QAudio::StoppedState) - return 0; - - return (AudioGetCurrentHostTime() - startTime) / (clockFrequency / 1000); -} - -QAudio::Error QAudioInputPrivate::error() const -{ - return errorCode; -} - -QAudio::State QAudioInputPrivate::state() const -{ - return stateCode; -} - -void QAudioInputPrivate::audioThreadStop() -{ - stopTimers(); - if (audioThreadState.testAndSetAcquire(Running, Stopped)) - threadFinished.wait(&mutex); -} - -void QAudioInputPrivate::audioThreadStart() -{ - startTimers(); - audioThreadState = Running; - AudioOutputUnitStart(audioUnit); -} - -void QAudioInputPrivate::audioDeviceStop() -{ - AudioOutputUnitStop(audioUnit); - audioThreadState = Stopped; - threadFinished.wakeOne(); -} - -void QAudioInputPrivate::audioDeviceFull() -{ - QMutexLocker lock(&mutex); - if (stateCode == QAudio::ActiveState) { - audioDeviceStop(); - - errorCode = QAudio::UnderrunError; - stateCode = QAudio::IdleState; - QMetaObject::invokeMethod(this, "deviceStopped", Qt::QueuedConnection); - } -} - -void QAudioInputPrivate::audioDeviceError() -{ - QMutexLocker lock(&mutex); - if (stateCode == QAudio::ActiveState) { - audioDeviceStop(); - - errorCode = QAudio::IOError; - stateCode = QAudio::StoppedState; - QMetaObject::invokeMethod(this, "deviceStopped", Qt::QueuedConnection); - } -} - -void QAudioInputPrivate::startTimers() -{ - audioBuffer->startFlushTimer(); - if (intervalTimer->interval() > 0) - intervalTimer->start(); -} - -void QAudioInputPrivate::stopTimers() -{ - audioBuffer->stopFlushTimer(); - intervalTimer->stop(); -} - -void QAudioInputPrivate::deviceStopped() -{ - stopTimers(); - emit stateChanged(stateCode); -} - -// Input callback -OSStatus QAudioInputPrivate::inputCallback(void* inRefCon, - AudioUnitRenderActionFlags* ioActionFlags, - const AudioTimeStamp* inTimeStamp, - UInt32 inBusNumber, - UInt32 inNumberFrames, - AudioBufferList* ioData) -{ - Q_UNUSED(ioData); - - QAudioInputPrivate* d = static_cast(inRefCon); - - const int threadState = d->audioThreadState.fetchAndAddAcquire(0); - if (threadState == Stopped) - d->audioDeviceStop(); - else { - qint64 framesWritten; - - framesWritten = d->audioBuffer->renderFromDevice(d->audioUnit, - ioActionFlags, - inTimeStamp, - inBusNumber, - inNumberFrames); - - if (framesWritten > 0) - d->totalFrames += framesWritten; - else if (framesWritten == 0) - d->audioDeviceFull(); - else if (framesWritten < 0) - d->audioDeviceError(); - } - - return noErr; -} - - -QT_END_NAMESPACE - -#include "qaudioinput_mac_p.moc" - diff --git a/src/multimedia/audio/qaudioinput_mac_p.h b/src/multimedia/audio/qaudioinput_mac_p.h deleted file mode 100644 index 7aa4168..0000000 --- a/src/multimedia/audio/qaudioinput_mac_p.h +++ /dev/null @@ -1,169 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtMultimedia module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -// -// W A R N I N G -// ------------- -// -// This file is not part of the Qt API. It exists for the convenience -// of other Qt classes. This header file may change from version to -// version without notice, or even be removed. -// -// We mean it. -// - - -#ifndef QAUDIOINPUT_MAC_P_H -#define QAUDIOINPUT_MAC_P_H - -#include -#include -#include -#include - -#include -#include -#include -#include - -#include -#include -#include - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -class QTimer; -class QIODevice; -class QAbstractAudioDeviceInfo; - -namespace QtMultimediaInternal -{ -class QAudioInputBuffer; -} - -class QAudioInputPrivate : public QAbstractAudioInput -{ - Q_OBJECT - -public: - bool isOpen; - int periodSizeBytes; - int internalBufferSize; - qint64 totalFrames; - QAudioFormat audioFormat; - QIODevice* audioIO; - AudioUnit audioUnit; - AudioDeviceID audioDeviceId; - Float64 clockFrequency; - UInt64 startTime; - QAudio::Error errorCode; - QAudio::State stateCode; - QtMultimediaInternal::QAudioInputBuffer* audioBuffer; - QMutex mutex; - QWaitCondition threadFinished; - QAtomicInt audioThreadState; - QTimer* intervalTimer; - AudioStreamBasicDescription streamFormat; - AudioStreamBasicDescription deviceFormat; - QAbstractAudioDeviceInfo *audioDeviceInfo; - - QAudioInputPrivate(const QByteArray& device, QAudioFormat const& format); - ~QAudioInputPrivate(); - - bool open(); - void close(); - - QAudioFormat format() const; - - QIODevice* start(QIODevice* device); - void stop(); - void reset(); - void suspend(); - void resume(); - void idle(); - - int bytesReady() const; - int periodSize() const; - - void setBufferSize(int value); - int bufferSize() const; - - void setNotifyInterval(int milliSeconds); - int notifyInterval() const; - - qint64 processedUSecs() const; - qint64 elapsedUSecs() const; - - QAudio::Error error() const; - QAudio::State state() const; - - void audioThreadStart(); - void audioThreadStop(); - - void audioDeviceStop(); - void audioDeviceFull(); - void audioDeviceError(); - - void startTimers(); - void stopTimers(); - -private slots: - void deviceStopped(); - -private: - enum { Running, Stopped }; - - // Input callback - static OSStatus inputCallback(void* inRefCon, - AudioUnitRenderActionFlags* ioActionFlags, - const AudioTimeStamp* inTimeStamp, - UInt32 inBusNumber, - UInt32 inNumberFrames, - AudioBufferList* ioData); -}; - -QT_END_NAMESPACE - -QT_END_HEADER - -#endif // QAUDIOINPUT_MAC_P_H diff --git a/src/multimedia/audio/qaudioinput_symbian_p.cpp b/src/multimedia/audio/qaudioinput_symbian_p.cpp deleted file mode 100644 index 52daa88..0000000 --- a/src/multimedia/audio/qaudioinput_symbian_p.cpp +++ /dev/null @@ -1,594 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtMultimedia module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qaudioinput_symbian_p.h" - -QT_BEGIN_NAMESPACE - -//----------------------------------------------------------------------------- -// Constants -//----------------------------------------------------------------------------- - -const int PushInterval = 50; // ms - - -//----------------------------------------------------------------------------- -// Private class -//----------------------------------------------------------------------------- - -SymbianAudioInputPrivate::SymbianAudioInputPrivate( - QAudioInputPrivate *audioDevice) - : m_audioDevice(audioDevice) -{ - -} - -SymbianAudioInputPrivate::~SymbianAudioInputPrivate() -{ - -} - -qint64 SymbianAudioInputPrivate::readData(char *data, qint64 len) -{ - qint64 totalRead = 0; - - if (m_audioDevice->state() == QAudio::ActiveState || - m_audioDevice->state() == QAudio::IdleState) { - - while (totalRead < len) { - const qint64 read = m_audioDevice->read(data + totalRead, - len - totalRead); - if (read > 0) - totalRead += read; - else - break; - } - } - - return totalRead; -} - -qint64 SymbianAudioInputPrivate::writeData(const char *data, qint64 len) -{ - Q_UNUSED(data) - Q_UNUSED(len) - return 0; -} - -void SymbianAudioInputPrivate::dataReady() -{ - emit readyRead(); -} - - -//----------------------------------------------------------------------------- -// Public functions -//----------------------------------------------------------------------------- - -QAudioInputPrivate::QAudioInputPrivate(const QByteArray &device, - const QAudioFormat &format) - : m_device(device) - , m_format(format) - , m_clientBufferSize(SymbianAudio::DefaultBufferSize) - , m_notifyInterval(SymbianAudio::DefaultNotifyInterval) - , m_notifyTimer(new QTimer(this)) - , m_error(QAudio::NoError) - , m_internalState(SymbianAudio::ClosedState) - , m_externalState(QAudio::StoppedState) - , m_pullMode(false) - , m_sink(0) - , m_pullTimer(new QTimer(this)) - , m_devSoundBuffer(0) - , m_devSoundBufferSize(0) - , m_totalBytesReady(0) - , m_devSoundBufferPos(0) - , m_totalSamplesRecorded(0) -{ - connect(m_notifyTimer.data(), SIGNAL(timeout()), this, SIGNAL(notify())); - - SymbianAudio::Utils::formatQtToNative(m_format, m_nativeFourCC, - m_nativeFormat); - - m_pullTimer->setInterval(PushInterval); - connect(m_pullTimer.data(), SIGNAL(timeout()), this, SLOT(pullData())); -} - -QAudioInputPrivate::~QAudioInputPrivate() -{ - close(); -} - -QIODevice* QAudioInputPrivate::start(QIODevice *device) -{ - stop(); - - open(); - if (SymbianAudio::ClosedState != m_internalState) { - if (device) { - m_pullMode = true; - m_sink = device; - } else { - m_sink = new SymbianAudioInputPrivate(this); - m_sink->open(QIODevice::ReadOnly | QIODevice::Unbuffered); - } - - m_elapsed.restart(); - } - - return m_sink; -} - -void QAudioInputPrivate::stop() -{ - close(); -} - -void QAudioInputPrivate::reset() -{ - m_totalSamplesRecorded += getSamplesRecorded(); - m_devSound->Stop(); - startRecording(); -} - -void QAudioInputPrivate::suspend() -{ - if (SymbianAudio::ActiveState == m_internalState - || SymbianAudio::IdleState == m_internalState) { - m_notifyTimer->stop(); - m_pullTimer->stop(); - m_devSound->Pause(); - const qint64 samplesRecorded = getSamplesRecorded(); - m_totalSamplesRecorded += samplesRecorded; - - if (m_devSoundBuffer) { - m_devSoundBufferQ.append(m_devSoundBuffer); - m_devSoundBuffer = 0; - } - - setState(SymbianAudio::SuspendedState); - } -} - -void QAudioInputPrivate::resume() -{ - if (SymbianAudio::SuspendedState == m_internalState) - startDataTransfer(); -} - -int QAudioInputPrivate::bytesReady() const -{ - Q_ASSERT(m_devSoundBufferPos <= m_totalBytesReady); - return m_totalBytesReady - m_devSoundBufferPos; -} - -int QAudioInputPrivate::periodSize() const -{ - return bufferSize(); -} - -void QAudioInputPrivate::setBufferSize(int value) -{ - // Note that DevSound does not allow its client to specify the buffer size. - // This functionality is available via custom interfaces, but since these - // cannot be guaranteed to work across all DevSound implementations, we - // do not use them here. - // In order to comply with the expected bevahiour of QAudioInput, we store - // the value and return it from bufferSize(), but the underlying DevSound - // buffer size remains unchanged. - if (value > 0) - m_clientBufferSize = value; -} - -int QAudioInputPrivate::bufferSize() const -{ - return m_devSoundBufferSize ? m_devSoundBufferSize : m_clientBufferSize; -} - -void QAudioInputPrivate::setNotifyInterval(int ms) -{ - if (ms > 0) { - const int oldNotifyInterval = m_notifyInterval; - m_notifyInterval = ms; - if (m_notifyTimer->isActive() && ms != oldNotifyInterval) - m_notifyTimer->start(m_notifyInterval); - } -} - -int QAudioInputPrivate::notifyInterval() const -{ - return m_notifyInterval; -} - -qint64 QAudioInputPrivate::processedUSecs() const -{ - int samplesPlayed = 0; - if (m_devSound && SymbianAudio::SuspendedState != m_internalState) - samplesPlayed = getSamplesRecorded(); - - // Protect against division by zero - Q_ASSERT_X(m_format.frequency() > 0, Q_FUNC_INFO, "Invalid frequency"); - - const qint64 result = qint64(1000000) * - (samplesPlayed + m_totalSamplesRecorded) - / m_format.frequency(); - - return result; -} - -qint64 QAudioInputPrivate::elapsedUSecs() const -{ - const qint64 result = (QAudio::StoppedState == state()) ? - 0 : m_elapsed.elapsed() * 1000; - return result; -} - -QAudio::Error QAudioInputPrivate::error() const -{ - return m_error; -} - -QAudio::State QAudioInputPrivate::state() const -{ - return m_externalState; -} - -QAudioFormat QAudioInputPrivate::format() const -{ - return m_format; -} - -//----------------------------------------------------------------------------- -// MDevSoundObserver implementation -//----------------------------------------------------------------------------- - -void QAudioInputPrivate::InitializeComplete(TInt aError) -{ - Q_ASSERT_X(SymbianAudio::InitializingState == m_internalState, - Q_FUNC_INFO, "Invalid state"); - - if (KErrNone == aError) - startRecording(); -} - -void QAudioInputPrivate::ToneFinished(TInt aError) -{ - Q_UNUSED(aError) - // This class doesn't use DevSound's tone playback functions, so should - // never receive this callback. - Q_ASSERT_X(false, Q_FUNC_INFO, "Unexpected callback"); -} - -void QAudioInputPrivate::BufferToBeFilled(CMMFBuffer *aBuffer) -{ - Q_UNUSED(aBuffer) - // This class doesn't use DevSound in play mode, so should never receive - // this callback. - Q_ASSERT_X(false, Q_FUNC_INFO, "Unexpected callback"); -} - -void QAudioInputPrivate::PlayError(TInt aError) -{ - Q_UNUSED(aError) - // This class doesn't use DevSound in play mode, so should never receive - // this callback. - Q_ASSERT_X(false, Q_FUNC_INFO, "Unexpected callback"); -} - -void QAudioInputPrivate::BufferToBeEmptied(CMMFBuffer *aBuffer) -{ - // Following receipt of this callback, DevSound should not provide another - // buffer until we have returned the current one. - Q_ASSERT_X(!m_devSoundBuffer, Q_FUNC_INFO, "Buffer already held"); - - CMMFDataBuffer *const buffer = static_cast(aBuffer); - - if (!m_devSoundBufferSize) - m_devSoundBufferSize = buffer->Data().MaxLength(); - - m_totalBytesReady += buffer->Data().Length(); - - if (SymbianAudio::SuspendedState == m_internalState) { - m_devSoundBufferQ.append(buffer); - } else { - // Will be returned to DevSound by bufferEmptied(). - m_devSoundBuffer = buffer; - m_devSoundBufferPos = 0; - - if (bytesReady() && !m_pullMode) - pushData(); - } -} - -void QAudioInputPrivate::RecordError(TInt aError) -{ - Q_UNUSED(aError) - setError(QAudio::IOError); -} - -void QAudioInputPrivate::ConvertError(TInt aError) -{ - Q_UNUSED(aError) - // This class doesn't use DevSound's format conversion functions, so - // should never receive this callback. - Q_ASSERT_X(false, Q_FUNC_INFO, "Unexpected callback"); -} - -void QAudioInputPrivate::DeviceMessage(TUid aMessageType, const TDesC8 &aMsg) -{ - Q_UNUSED(aMessageType) - Q_UNUSED(aMsg) - // Ignore this callback. -} - -//----------------------------------------------------------------------------- -// Private functions -//----------------------------------------------------------------------------- - -void QAudioInputPrivate::open() -{ - Q_ASSERT_X(SymbianAudio::ClosedState == m_internalState, - Q_FUNC_INFO, "DevSound already opened"); - - QT_TRAP_THROWING( m_devSound.reset(CMMFDevSound::NewL()) ) - - QScopedPointer caps( - new SymbianAudio::DevSoundCapabilities(*m_devSound, QAudio::AudioInput)); - - int err = SymbianAudio::Utils::isFormatSupported(m_format, *caps) ? - KErrNone : KErrNotSupported; - - if (KErrNone == err) { - setState(SymbianAudio::InitializingState); - TRAP(err, m_devSound->InitializeL(*this, m_nativeFourCC, - EMMFStateRecording)); - } - - if (KErrNone != err) { - setError(QAudio::OpenError); - m_devSound.reset(); - } -} - -void QAudioInputPrivate::startRecording() -{ - const int samplesRecorded = m_devSound->SamplesRecorded(); - Q_ASSERT(samplesRecorded == 0); - - TRAPD(err, startDevSoundL()); - if (KErrNone == err) { - startDataTransfer(); - } else { - setError(QAudio::OpenError); - close(); - } -} - -void QAudioInputPrivate::startDevSoundL() -{ - TMMFCapabilities nativeFormat = m_devSound->Config(); - m_nativeFormat.iBufferSize = nativeFormat.iBufferSize; - m_devSound->SetConfigL(m_nativeFormat); - m_devSound->RecordInitL(); -} - -void QAudioInputPrivate::startDataTransfer() -{ - m_notifyTimer->start(m_notifyInterval); - - if (m_pullMode) - m_pullTimer->start(); - - if (bytesReady()) { - setState(SymbianAudio::ActiveState); - if (!m_pullMode) - pushData(); - } else { - if (SymbianAudio::SuspendedState == m_internalState) - setState(SymbianAudio::ActiveState); - else - setState(SymbianAudio::IdleState); - } -} - -CMMFDataBuffer* QAudioInputPrivate::currentBuffer() const -{ - CMMFDataBuffer *result = m_devSoundBuffer; - if (!result && !m_devSoundBufferQ.empty()) - result = m_devSoundBufferQ.front(); - return result; -} - -void QAudioInputPrivate::pushData() -{ - Q_ASSERT_X(bytesReady(), Q_FUNC_INFO, "No data available"); - Q_ASSERT_X(!m_pullMode, Q_FUNC_INFO, "pushData called when in pull mode"); - qobject_cast(m_sink)->dataReady(); -} - -qint64 QAudioInputPrivate::read(char *data, qint64 len) -{ - // SymbianAudioInputPrivate is ready to read data - - Q_ASSERT_X(!m_pullMode, Q_FUNC_INFO, - "read called when in pull mode"); - - qint64 bytesRead = 0; - - CMMFDataBuffer *buffer = 0; - while ((buffer = currentBuffer()) && (bytesRead < len)) { - if (SymbianAudio::IdleState == m_internalState) - setState(SymbianAudio::ActiveState); - - TDesC8 &inputBuffer = buffer->Data(); - - const qint64 inputBytes = bytesReady(); - const qint64 outputBytes = len - bytesRead; - const qint64 copyBytes = outputBytes < inputBytes ? - outputBytes : inputBytes; - - memcpy(data, inputBuffer.Ptr() + m_devSoundBufferPos, copyBytes); - - m_devSoundBufferPos += copyBytes; - data += copyBytes; - bytesRead += copyBytes; - - if (!bytesReady()) - bufferEmptied(); - } - - return bytesRead; -} - -void QAudioInputPrivate::pullData() -{ - Q_ASSERT_X(m_pullMode, Q_FUNC_INFO, - "pullData called when in push mode"); - - CMMFDataBuffer *buffer = 0; - while (buffer = currentBuffer()) { - if (SymbianAudio::IdleState == m_internalState) - setState(SymbianAudio::ActiveState); - - TDesC8 &inputBuffer = buffer->Data(); - - const qint64 inputBytes = bytesReady(); - const qint64 bytesPushed = m_sink->write( - (char*)inputBuffer.Ptr() + m_devSoundBufferPos, inputBytes); - - m_devSoundBufferPos += bytesPushed; - - if (!bytesReady()) - bufferEmptied(); - - if (!bytesPushed) - break; - } -} - -void QAudioInputPrivate::bufferEmptied() -{ - m_devSoundBufferPos = 0; - - if (m_devSoundBuffer) { - m_totalBytesReady -= m_devSoundBuffer->Data().Length(); - m_devSoundBuffer = 0; - m_devSound->RecordData(); - } else { - Q_ASSERT(!m_devSoundBufferQ.empty()); - m_totalBytesReady -= m_devSoundBufferQ.front()->Data().Length(); - m_devSoundBufferQ.erase(m_devSoundBufferQ.begin()); - - // If the queue has been emptied, resume transfer from the hardware - if (m_devSoundBufferQ.empty()) - m_devSound->RecordInitL(); - } - - Q_ASSERT(m_totalBytesReady >= 0); -} - -void QAudioInputPrivate::close() -{ - m_notifyTimer->stop(); - m_pullTimer->stop(); - - m_error = QAudio::NoError; - - if (m_devSound) - m_devSound->Stop(); - m_devSound.reset(); - m_devSoundBuffer = 0; - m_devSoundBufferSize = 0; - m_totalBytesReady = 0; - - if (!m_pullMode) // m_sink is owned - delete m_sink; - m_pullMode = false; - m_sink = 0; - - m_devSoundBufferQ.clear(); - m_devSoundBufferPos = 0; - m_totalSamplesRecorded = 0; - - setState(SymbianAudio::ClosedState); -} - -qint64 QAudioInputPrivate::getSamplesRecorded() const -{ - qint64 result = 0; - if (m_devSound) - result = qint64(m_devSound->SamplesRecorded()); - return result; -} - -void QAudioInputPrivate::setError(QAudio::Error error) -{ - m_error = error; - - // Although no state transition actually occurs here, a stateChanged event - // must be emitted to inform the client that the call to start() was - // unsuccessful. - if (QAudio::OpenError == error) - emit stateChanged(QAudio::StoppedState); - - // Close the DevSound instance. This causes a transition to StoppedState. - // This must be done asynchronously in case the current function was called - // from a DevSound event handler, in which case deleting the DevSound - // instance may cause an exception. - QMetaObject::invokeMethod(this, "close", Qt::QueuedConnection); -} - -void QAudioInputPrivate::setState(SymbianAudio::State newInternalState) -{ - const QAudio::State oldExternalState = m_externalState; - m_internalState = newInternalState; - m_externalState = SymbianAudio::Utils::stateNativeToQt( - m_internalState, initializingState()); - - if (m_externalState != oldExternalState) - emit stateChanged(m_externalState); -} - -QAudio::State QAudioInputPrivate::initializingState() const -{ - return QAudio::IdleState; -} - -QT_END_NAMESPACE diff --git a/src/multimedia/audio/qaudioinput_symbian_p.h b/src/multimedia/audio/qaudioinput_symbian_p.h deleted file mode 100644 index ca3ccf7..0000000 --- a/src/multimedia/audio/qaudioinput_symbian_p.h +++ /dev/null @@ -1,188 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtMultimedia module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -// -// W A R N I N G -// ------------- -// -// This file is not part of the Qt API. It exists for the convenience -// of other Qt classes. This header file may change from version to -// version without notice, or even be removed. -// -// We mean it. -// - -#ifndef QAUDIOINPUT_SYMBIAN_P_H -#define QAUDIOINPUT_SYMBIAN_P_H - -#include -#include -#include -#include -#include "qaudio_symbian_p.h" - -QT_BEGIN_NAMESPACE - -class QAudioInputPrivate; - -class SymbianAudioInputPrivate : public QIODevice -{ - friend class QAudioInputPrivate; - Q_OBJECT -public: - SymbianAudioInputPrivate(QAudioInputPrivate *audio); - ~SymbianAudioInputPrivate(); - - qint64 readData(char *data, qint64 len); - qint64 writeData(const char *data, qint64 len); - - void dataReady(); - -private: - QAudioInputPrivate *const m_audioDevice; -}; - -class QAudioInputPrivate - : public QAbstractAudioInput - , public MDevSoundObserver -{ - friend class SymbianAudioInputPrivate; - Q_OBJECT -public: - QAudioInputPrivate(const QByteArray &device, - const QAudioFormat &audioFormat); - ~QAudioInputPrivate(); - - // QAbstractAudioInput - QIODevice* start(QIODevice *device = 0); - void stop(); - void reset(); - void suspend(); - void resume(); - int bytesReady() const; - int periodSize() const; - void setBufferSize(int value); - int bufferSize() const; - void setNotifyInterval(int milliSeconds); - int notifyInterval() const; - qint64 processedUSecs() const; - qint64 elapsedUSecs() const; - QAudio::Error error() const; - QAudio::State state() const; - QAudioFormat format() const; - - // MDevSoundObserver - void InitializeComplete(TInt aError); - void ToneFinished(TInt aError); - void BufferToBeFilled(CMMFBuffer *aBuffer); - void PlayError(TInt aError); - void BufferToBeEmptied(CMMFBuffer *aBuffer); - void RecordError(TInt aError); - void ConvertError(TInt aError); - void DeviceMessage(TUid aMessageType, const TDesC8 &aMsg); - -private slots: - void pullData(); - -private: - void open(); - void startRecording(); - void startDevSoundL(); - void startDataTransfer(); - CMMFDataBuffer* currentBuffer() const; - void pushData(); - qint64 read(char *data, qint64 len); - void bufferEmptied(); - Q_INVOKABLE void close(); - - qint64 getSamplesRecorded() const; - - void setError(QAudio::Error error); - void setState(SymbianAudio::State state); - - QAudio::State initializingState() const; - -private: - const QByteArray m_device; - const QAudioFormat m_format; - - int m_clientBufferSize; - int m_notifyInterval; - QScopedPointer m_notifyTimer; - QTime m_elapsed; - QAudio::Error m_error; - - SymbianAudio::State m_internalState; - QAudio::State m_externalState; - - bool m_pullMode; - QIODevice *m_sink; - - QScopedPointer m_pullTimer; - - QScopedPointer m_devSound; - TUint32 m_nativeFourCC; - TMMFCapabilities m_nativeFormat; - - // Latest buffer provided by DevSound, to be empied of data. - CMMFDataBuffer *m_devSoundBuffer; - - int m_devSoundBufferSize; - - // Total amount of data in buffers provided by DevSound - int m_totalBytesReady; - - // Queue of buffers returned after call to CMMFDevSound::Pause(). - QList m_devSoundBufferQ; - - // Current read position within m_devSoundBuffer - qint64 m_devSoundBufferPos; - - // Samples recorded up to the last call to suspend(). It is necessary - // to cache this because suspend() is implemented using - // CMMFDevSound::Stop(), which resets DevSound's SamplesRecorded() counter. - quint32 m_totalSamplesRecorded; - -}; - -QT_END_NAMESPACE - -#endif diff --git a/src/multimedia/audio/qaudioinput_win32_p.cpp b/src/multimedia/audio/qaudioinput_win32_p.cpp deleted file mode 100644 index b5d673e..0000000 --- a/src/multimedia/audio/qaudioinput_win32_p.cpp +++ /dev/null @@ -1,613 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtMultimedia module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -// -// W A R N I N G -// ------------- -// -// This file is not part of the Qt API. It exists for the convenience -// of other Qt classes. This header file may change from version to -// version without notice, or even be removed. -// -// We mean it. -// - - -#include "qaudioinput_win32_p.h" - -QT_BEGIN_NAMESPACE - -//#define DEBUG_AUDIO 1 - -static const int minimumIntervalTime = 50; - -QAudioInputPrivate::QAudioInputPrivate(const QByteArray &device, const QAudioFormat& audioFormat): - settings(audioFormat) -{ - bytesAvailable = 0; - buffer_size = 0; - period_size = 0; - m_device = device; - totalTimeValue = 0; - intervalTime = 1000; - errorState = QAudio::NoError; - deviceState = QAudio::StoppedState; - audioSource = 0; - pullMode = true; - resuming = false; - finished = false; - - connect(this,SIGNAL(processMore()),SLOT(deviceReady())); - - InitializeCriticalSection(&waveInCriticalSection); -} - -QAudioInputPrivate::~QAudioInputPrivate() -{ - stop(); - DeleteCriticalSection(&waveInCriticalSection); -} - -void QT_WIN_CALLBACK QAudioInputPrivate::waveInProc( HWAVEIN hWaveIn, UINT uMsg, - DWORD dwInstance, DWORD dwParam1, DWORD dwParam2 ) -{ - Q_UNUSED(dwParam1) - Q_UNUSED(dwParam2) - Q_UNUSED(hWaveIn) - - QAudioInputPrivate* qAudio; - qAudio = (QAudioInputPrivate*)(dwInstance); - if(!qAudio) - return; - - switch(uMsg) { - case WIM_OPEN: - break; - case WIM_DATA: - EnterCriticalSection(&qAudio->waveInCriticalSection); - if(qAudio->waveFreeBlockCount > 0) - qAudio->waveFreeBlockCount--; - qAudio->feedback(); - LeaveCriticalSection(&qAudio->waveInCriticalSection); - break; - case WIM_CLOSE: - EnterCriticalSection(&qAudio->waveInCriticalSection); - qAudio->finished = true; - LeaveCriticalSection(&qAudio->waveInCriticalSection); - break; - default: - return; - } -} - -WAVEHDR* QAudioInputPrivate::allocateBlocks(int size, int count) -{ - int i; - unsigned char* buffer; - WAVEHDR* blocks; - DWORD totalBufferSize = (size + sizeof(WAVEHDR))*count; - - if((buffer=(unsigned char*)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY, - totalBufferSize)) == 0) { - qWarning("QAudioInput: Memory allocation error"); - return 0; - } - blocks = (WAVEHDR*)buffer; - buffer += sizeof(WAVEHDR)*count; - for(i = 0; i < count; i++) { - blocks[i].dwBufferLength = size; - blocks[i].lpData = (LPSTR)buffer; - blocks[i].dwBytesRecorded=0; - blocks[i].dwUser = 0L; - blocks[i].dwFlags = 0L; - blocks[i].dwLoops = 0L; - result = waveInPrepareHeader(hWaveIn,&blocks[i], sizeof(WAVEHDR)); - if(result != MMSYSERR_NOERROR) { - qWarning("QAudioInput: Can't prepare block %d",i); - return 0; - } - buffer += size; - } - return blocks; -} - -void QAudioInputPrivate::freeBlocks(WAVEHDR* blockArray) -{ - WAVEHDR* blocks = blockArray; - - int count = buffer_size/period_size; - - for(int i = 0; i < count; i++) { - waveInUnprepareHeader(hWaveIn,&blocks[i], sizeof(WAVEHDR)); - blocks+=sizeof(WAVEHDR); - } - HeapFree(GetProcessHeap(), 0, blockArray); -} - -QAudio::Error QAudioInputPrivate::error() const -{ - return errorState; -} - -QAudio::State QAudioInputPrivate::state() const -{ - return deviceState; -} - -QAudioFormat QAudioInputPrivate::format() const -{ - return settings; -} - -QIODevice* QAudioInputPrivate::start(QIODevice* device) -{ - if(deviceState != QAudio::StoppedState) - close(); - - if(!pullMode && audioSource) { - delete audioSource; - } - - if(device) { - //set to pull mode - pullMode = true; - audioSource = device; - deviceState = QAudio::ActiveState; - } else { - //set to push mode - pullMode = false; - deviceState = QAudio::IdleState; - audioSource = new InputPrivate(this); - audioSource->open(QIODevice::ReadOnly | QIODevice::Unbuffered); - } - - if( !open() ) - return 0; - - emit stateChanged(deviceState); - - return audioSource; -} - -void QAudioInputPrivate::stop() -{ - if(deviceState == QAudio::StoppedState) - return; - - close(); - emit stateChanged(deviceState); -} - -bool QAudioInputPrivate::open() -{ -#ifdef DEBUG_AUDIO - QTime now(QTime::currentTime()); - qDebug()<> 3) * wfx.nChannels; - wfx.nAvgBytesPerSec = wfx.nBlockAlign * wfx.nSamplesPerSec; - - UINT_PTR devId = WAVE_MAPPER; - - WAVEINCAPS wic; - unsigned long iNumDevs,ii; - iNumDevs = waveInGetNumDevs(); - for(ii=0;ii 0 && waveBlocks[header].dwFlags & WHDR_DONE) { - if(pullMode) { - l = audioSource->write(waveBlocks[header].lpData, - waveBlocks[header].dwBytesRecorded); -#ifdef DEBUG_AUDIO - qDebug()<<"IN: "<= buffer_size/period_size) - header = 0; - p+=l; - - EnterCriticalSection(&waveInCriticalSection); - if(!pullMode) { - if(l+period_size > len && waveFreeBlockCount == buffer_size/period_size) - done = true; - } else { - if(waveFreeBlockCount == buffer_size/period_size) - done = true; - } - LeaveCriticalSection(&waveInCriticalSection); - - written+=l; - } -#ifdef DEBUG_AUDIO - qDebug()<<"read in len="<= minimumIntervalTime) - intervalTime = ms; - else - intervalTime = minimumIntervalTime; -} - -int QAudioInputPrivate::notifyInterval() const -{ - return intervalTime; -} - -qint64 QAudioInputPrivate::processedUSecs() const -{ - if (deviceState == QAudio::StoppedState) - return 0; - qint64 result = qint64(1000000) * totalTimeValue / - (settings.channels()*(settings.sampleSize()/8)) / - settings.frequency(); - - return result; -} - -void QAudioInputPrivate::suspend() -{ - if(deviceState == QAudio::ActiveState) { - waveInReset(hWaveIn); - deviceState = QAudio::SuspendedState; - emit stateChanged(deviceState); - } -} - -void QAudioInputPrivate::feedback() -{ -#ifdef DEBUG_AUDIO - QTime now(QTime::currentTime()); - qDebug()<(audioSource); - a->trigger(); - } - - if((timeStamp.elapsed() + elapsedTimeOffset) > intervalTime) { - emit notify(); - elapsedTimeOffset = timeStamp.elapsed() + elapsedTimeOffset - intervalTime; - timeStamp.restart(); - } - return true; -} - -qint64 QAudioInputPrivate::elapsedUSecs() const -{ - if (deviceState == QAudio::StoppedState) - return 0; - - return timeStampOpened.elapsed()*1000; -} - -void QAudioInputPrivate::reset() -{ - close(); -} - -InputPrivate::InputPrivate(QAudioInputPrivate* audio) -{ - audioDevice = qobject_cast(audio); -} - -InputPrivate::~InputPrivate() {} - -qint64 InputPrivate::readData( char* data, qint64 len) -{ - // push mode, user read() called - if(audioDevice->deviceState != QAudio::ActiveState && - audioDevice->deviceState != QAudio::IdleState) - return 0; - // Read in some audio data - return audioDevice->read(data,len); -} - -qint64 InputPrivate::writeData(const char* data, qint64 len) -{ - Q_UNUSED(data) - Q_UNUSED(len) - - emit readyRead(); - return 0; -} - -void InputPrivate::trigger() -{ - emit readyRead(); -} - -QT_END_NAMESPACE diff --git a/src/multimedia/audio/qaudioinput_win32_p.h b/src/multimedia/audio/qaudioinput_win32_p.h deleted file mode 100644 index 66c2535..0000000 --- a/src/multimedia/audio/qaudioinput_win32_p.h +++ /dev/null @@ -1,159 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtMultimedia module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -// -// W A R N I N G -// ------------- -// -// This file is not part of the Qt API. It exists for the convenience -// of other Qt classes. This header file may change from version to -// version without notice, or even be removed. -// -// We mean it. -// - -#ifndef QAUDIOINPUTWIN_H -#define QAUDIOINPUTWIN_H - -#include -#include - -#include -#include -#include -#include -#include -#include - -#include -#include -#include - - -QT_BEGIN_NAMESPACE - -class QAudioInputPrivate : public QAbstractAudioInput -{ - Q_OBJECT -public: - QAudioInputPrivate(const QByteArray &device, const QAudioFormat& audioFormat); - ~QAudioInputPrivate(); - - qint64 read(char* data, qint64 len); - - QAudioFormat format() const; - QIODevice* start(QIODevice* device = 0); - void stop(); - void reset(); - void suspend(); - void resume(); - int bytesReady() const; - int periodSize() const; - void setBufferSize(int value); - int bufferSize() const; - void setNotifyInterval(int milliSeconds); - int notifyInterval() const; - qint64 processedUSecs() const; - qint64 elapsedUSecs() const; - QAudio::Error error() const; - QAudio::State state() const; - - QIODevice* audioSource; - QAudioFormat settings; - QAudio::Error errorState; - QAudio::State deviceState; - -private: - qint32 buffer_size; - qint32 period_size; - qint32 header; - QByteArray m_device; - int bytesAvailable; - int intervalTime; - QTime timeStamp; - qint64 elapsedTimeOffset; - QTime timeStampOpened; - qint64 totalTimeValue; - bool pullMode; - bool resuming; - WAVEFORMATEX wfx; - HWAVEIN hWaveIn; - MMRESULT result; - WAVEHDR* waveBlocks; - volatile bool finished; - volatile int waveFreeBlockCount; - int waveCurrentBlock; - - CRITICAL_SECTION waveInCriticalSection; - static void QT_WIN_CALLBACK waveInProc( HWAVEIN hWaveIn, UINT uMsg, - DWORD dwInstance, DWORD dwParam1, DWORD dwParam2 ); - - WAVEHDR* allocateBlocks(int size, int count); - void freeBlocks(WAVEHDR* blockArray); - bool open(); - void close(); - -private slots: - void feedback(); - bool deviceReady(); - -signals: - void processMore(); -}; - -class InputPrivate : public QIODevice -{ - Q_OBJECT -public: - InputPrivate(QAudioInputPrivate* audio); - ~InputPrivate(); - - qint64 readData( char* data, qint64 len); - qint64 writeData(const char* data, qint64 len); - - void trigger(); -private: - QAudioInputPrivate *audioDevice; -}; - -QT_END_NAMESPACE - -#endif diff --git a/src/multimedia/audio/qaudiooutput.cpp b/src/multimedia/audio/qaudiooutput.cpp deleted file mode 100644 index b0b5244..0000000 --- a/src/multimedia/audio/qaudiooutput.cpp +++ /dev/null @@ -1,411 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtMultimedia module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - - -#include -#include -#include -#include - -#include "qaudiodevicefactory_p.h" - - -QT_BEGIN_NAMESPACE - -/*! - \class QAudioOutput - \brief The QAudioOutput class provides an interface for sending audio data to an audio output device. - - \inmodule QtMultimedia - \ingroup multimedia - \since 4.6 - - You can construct an audio output with the system's - \l{QAudioDeviceInfo::defaultOutputDevice()}{default audio output - device}. It is also possible to create QAudioOutput with a - specific QAudioDeviceInfo. When you create the audio output, you - should also send in the QAudioFormat to be used for the playback - (see the QAudioFormat class description for details). - - To play a file: - - Starting to play an audio stream is simply a matter of calling - start() with a QIODevice. QAudioOutput will then fetch the data it - needs from the io device. So playing back an audio file is as - simple as: - - \code - QFile inputFile; // class member. - QAudioOutput* audio; // class member. - \endcode - - \code - inputFile.setFileName("/tmp/test.raw"); - inputFile.open(QIODevice::ReadOnly); - - QAudioFormat format; - // Set up the format, eg. - format.setFrequency(8000); - format.setChannels(1); - format.setSampleSize(8); - format.setCodec("audio/pcm"); - format.setByteOrder(QAudioFormat::LittleEndian); - format.setSampleType(QAudioFormat::UnSignedInt); - - QAudioDeviceInfo info(QAudioDeviceInfo::defaultOutputDevice()); - if (!info.isFormatSupported(format)) { - qWarning()<<"raw audio format not supported by backend, cannot play audio."; - return; - } - - audio = new QAudioOutput(format, this); - connect(audio,SIGNAL(stateChanged(QAudio::State)),SLOT(finishedPlaying(QAudio::State))); - audio->start(&inputFile); - - \endcode - - The file will start playing assuming that the audio system and - output device support it. If you run out of luck, check what's - up with the error() function. - - After the file has finished playing, we need to stop the device: - - \code - void finishedPlaying(QAudio::State state) - { - if(state == QAudio::IdleState) { - audio->stop(); - inputFile.close(); - delete audio; - } - } - \endcode - - At any given time, the QAudioOutput will be in one of four states: - active, suspended, stopped, or idle. These states are described - by the QAudio::State enum. - State changes are reported through the stateChanged() signal. You - can use this signal to, for instance, update the GUI of the - application; the mundane example here being changing the state of - a \c { play/pause } button. You request a state change directly - with suspend(), stop(), reset(), resume(), and start(). - - While the stream is playing, you can set a notify interval in - milliseconds with setNotifyInterval(). This interval specifies the - time between two emissions of the notify() signal. This is - relative to the position in the stream, i.e., if the QAudioOutput - is in the SuspendedState or the IdleState, the notify() signal is - not emitted. A typical use-case would be to update a - \l{QSlider}{slider} that allows seeking in the stream. - If you want the time since playback started regardless of which - states the audio output has been in, elapsedUSecs() is the function for you. - - If an error occurs, you can fetch the \l{QAudio::Error}{error - type} with the error() function. Please see the QAudio::Error enum - for a description of the possible errors that are reported. When - an error is encountered, the state changes to QAudio::StoppedState. - You can check for errors by connecting to the stateChanged() - signal: - - \snippet doc/src/snippets/audio/main.cpp 3 - - \sa QAudioInput, QAudioDeviceInfo -*/ - -/*! - Construct a new audio output and attach it to \a parent. - The default audio output device is used with the output - \a format parameters. -*/ - -QAudioOutput::QAudioOutput(const QAudioFormat &format, QObject *parent): - QObject(parent) -{ - d = QAudioDeviceFactory::createDefaultOutputDevice(format); - connect(d, SIGNAL(notify()), SIGNAL(notify())); - connect(d, SIGNAL(stateChanged(QAudio::State)), SIGNAL(stateChanged(QAudio::State))); -} - -/*! - Construct a new audio output and attach it to \a parent. - The device referenced by \a audioDevice is used with the output - \a format parameters. -*/ - -QAudioOutput::QAudioOutput(const QAudioDeviceInfo &audioDevice, const QAudioFormat &format, QObject *parent): - QObject(parent) -{ - d = QAudioDeviceFactory::createOutputDevice(audioDevice, format); - connect(d, SIGNAL(notify()), SIGNAL(notify())); - connect(d, SIGNAL(stateChanged(QAudio::State)), SIGNAL(stateChanged(QAudio::State))); -} - -/*! - Destroys this audio output. -*/ - -QAudioOutput::~QAudioOutput() -{ - delete d; -} - -/*! - Returns the QAudioFormat being used. - -*/ - -QAudioFormat QAudioOutput::format() const -{ - return d->format(); -} - -/*! - Uses the \a device as the QIODevice to transfer data. - Passing a QIODevice allows the data to be transfered without any extra code. - All that is required is to open the QIODevice. - - If able to successfully output audio data to the systems audio device the - state() is set to QAudio::ActiveState, error() is set to QAudio::NoError - and the stateChanged() signal is emitted. - - If a problem occurs during this process the error() is set to QAudio::OpenError, - state() is set to QAudio::StoppedState and stateChanged() signal is emitted. - - \sa QIODevice -*/ - -void QAudioOutput::start(QIODevice* device) -{ - d->start(device); -} - -/*! - Returns a pointer to the QIODevice being used to handle the data - transfer. This QIODevice can be used to write() audio data directly. - - If able to access the systems audio device the state() is set to - QAudio::IdleState, error() is set to QAudio::NoError - and the stateChanged() signal is emitted. - - If a problem occurs during this process the error() is set to QAudio::OpenError, - state() is set to QAudio::StoppedState and stateChanged() signal is emitted. - - \sa QIODevice -*/ - -QIODevice* QAudioOutput::start() -{ - return d->start(0); -} - -/*! - Stops the audio output, detaching from the system resource. - - Sets error() to QAudio::NoError, state() to QAudio::StoppedState and - emit stateChanged() signal. -*/ - -void QAudioOutput::stop() -{ - d->stop(); -} - -/*! - Drops all audio data in the buffers, resets buffers to zero. -*/ - -void QAudioOutput::reset() -{ - d->reset(); -} - -/*! - Stops processing audio data, preserving buffered audio data. - - Sets error() to QAudio::NoError, state() to QAudio::SuspendedState and - emit stateChanged() signal. -*/ - -void QAudioOutput::suspend() -{ - d->suspend(); -} - -/*! - Resumes processing audio data after a suspend(). - - Sets error() to QAudio::NoError. - Sets state() to QAudio::ActiveState if you previously called start(QIODevice*). - Sets state() to QAudio::IdleState if you previously called start(). - emits stateChanged() signal. -*/ - -void QAudioOutput::resume() -{ - d->resume(); -} - -/*! - Returns the free space available in bytes in the audio buffer. - - NOTE: returned value is only valid while in QAudio::ActiveState or QAudio::IdleState - state, otherwise returns zero. -*/ - -int QAudioOutput::bytesFree() const -{ - return d->bytesFree(); -} - -/*! - Returns the period size in bytes. - - Note: This is the recommended write size in bytes. -*/ - -int QAudioOutput::periodSize() const -{ - return d->periodSize(); -} - -/*! - Sets the audio buffer size to \a value in bytes. - - Note: This function can be called anytime before start(), calls to this - are ignored after start(). It should not be assumed that the buffer size - set is the actual buffer size used, calling bufferSize() anytime after start() - will return the actual buffer size being used. -*/ - -void QAudioOutput::setBufferSize(int value) -{ - d->setBufferSize(value); -} - -/*! - Returns the audio buffer size in bytes. - - If called before start(), returns platform default value. - If called before start() but setBufferSize() was called prior, returns value set by setBufferSize(). - If called after start(), returns the actual buffer size being used. This may not be what was set previously - by setBufferSize(). - -*/ - -int QAudioOutput::bufferSize() const -{ - return d->bufferSize(); -} - -/*! - Sets the interval for notify() signal to be emitted. - This is based on the \a ms of audio data processed - not on actual real-time. - The minimum resolution of the timer is platform specific and values - should be checked with notifyInterval() to confirm actual value - being used. -*/ - -void QAudioOutput::setNotifyInterval(int ms) -{ - d->setNotifyInterval(ms); -} - -/*! - Returns the notify interval in milliseconds. -*/ - -int QAudioOutput::notifyInterval() const -{ - return d->notifyInterval(); -} - -/*! - Returns the amount of audio data processed since start() - was called in microseconds. -*/ - -qint64 QAudioOutput::processedUSecs() const -{ - return d->processedUSecs(); -} - -/*! - Returns the microseconds since start() was called, including time in Idle and - Suspend states. -*/ - -qint64 QAudioOutput::elapsedUSecs() const -{ - return d->elapsedUSecs(); -} - -/*! - Returns the error state. -*/ - -QAudio::Error QAudioOutput::error() const -{ - return d->error(); -} - -/*! - Returns the state of audio processing. -*/ - -QAudio::State QAudioOutput::state() const -{ - return d->state(); -} - -/*! - \fn QAudioOutput::stateChanged(QAudio::State state) - This signal is emitted when the device \a state has changed. - This is the current state of the audio output. -*/ - -/*! - \fn QAudioOutput::notify() - This signal is emitted when x ms of audio data has been processed - the interval set by setNotifyInterval(x). -*/ - -QT_END_NAMESPACE diff --git a/src/multimedia/audio/qaudiooutput.h b/src/multimedia/audio/qaudiooutput.h deleted file mode 100644 index 0f45b1b..0000000 --- a/src/multimedia/audio/qaudiooutput.h +++ /dev/null @@ -1,111 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtMultimedia module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - - -#ifndef QAUDIOOUTPUT_H -#define QAUDIOOUTPUT_H - -#include -#include - -#include -#include -#include - - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Multimedia) - - -class QAbstractAudioOutput; - -class Q_MULTIMEDIA_EXPORT QAudioOutput : public QObject -{ - Q_OBJECT - -public: - explicit QAudioOutput(const QAudioFormat &format = QAudioFormat(), QObject *parent = 0); - explicit QAudioOutput(const QAudioDeviceInfo &audioDeviceInfo, const QAudioFormat &format = QAudioFormat(), QObject *parent = 0); - ~QAudioOutput(); - - QAudioFormat format() const; - - void start(QIODevice *device); - QIODevice* start(); - - void stop(); - void reset(); - void suspend(); - void resume(); - - void setBufferSize(int bytes); - int bufferSize() const; - - int bytesFree() const; - int periodSize() const; - - void setNotifyInterval(int milliSeconds); - int notifyInterval() const; - - qint64 processedUSecs() const; - qint64 elapsedUSecs() const; - - QAudio::Error error() const; - QAudio::State state() const; - -Q_SIGNALS: - void stateChanged(QAudio::State); - void notify(); - -private: - Q_DISABLE_COPY(QAudioOutput) - - QAbstractAudioOutput* d; -}; - -QT_END_NAMESPACE - -QT_END_HEADER - -#endif // QAUDIOOUTPUT_H diff --git a/src/multimedia/audio/qaudiooutput_alsa_p.cpp b/src/multimedia/audio/qaudiooutput_alsa_p.cpp deleted file mode 100644 index cf3726b..0000000 --- a/src/multimedia/audio/qaudiooutput_alsa_p.cpp +++ /dev/null @@ -1,780 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtMultimedia module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -// -// W A R N I N G -// ------------- -// -// This file is not part of the Qt API. It exists for the convenience -// of other Qt classes. This header file may change from version to -// version without notice, or even be removed. -// -// We mean it. -// - -#include -#include "qaudiooutput_alsa_p.h" -#include "qaudiodeviceinfo_alsa_p.h" - -QT_BEGIN_NAMESPACE - -//#define DEBUG_AUDIO 1 - -static const int minimumIntervalTime = 50; - -QAudioOutputPrivate::QAudioOutputPrivate(const QByteArray &device, const QAudioFormat& audioFormat): - settings(audioFormat) -{ - bytesAvailable = 0; - handle = 0; - ahandler = 0; - access = SND_PCM_ACCESS_RW_INTERLEAVED; - pcmformat = SND_PCM_FORMAT_S16; - buffer_frames = 0; - period_frames = 0; - buffer_size = 0; - period_size = 0; - buffer_time = 100000; - period_time = 20000; - totalTimeValue = 0; - intervalTime = 1000; - audioBuffer = 0; - errorState = QAudio::NoError; - deviceState = QAudio::StoppedState; - audioSource = 0; - pullMode = true; - resuming = false; - opened = false; - - QStringList list1 = QString(QLatin1String(device)).split(QLatin1String(":")); - m_device = QByteArray(list1.at(0).toLocal8Bit().constData()); - - timer = new QTimer(this); - connect(timer,SIGNAL(timeout()),SLOT(userFeed())); -} - -QAudioOutputPrivate::~QAudioOutputPrivate() -{ - close(); - disconnect(timer, SIGNAL(timeout())); - QCoreApplication::processEvents(); - delete timer; -} - -QAudio::Error QAudioOutputPrivate::error() const -{ - return errorState; -} - -QAudio::State QAudioOutputPrivate::state() const -{ - return deviceState; -} - -void QAudioOutputPrivate::async_callback(snd_async_handler_t *ahandler) -{ - QAudioOutputPrivate* audioOut; - - audioOut = static_cast - (snd_async_handler_get_callback_private(ahandler)); - - if((audioOut->deviceState==QAudio::ActiveState)||(audioOut->resuming)) - audioOut->feedback(); -} - -int QAudioOutputPrivate::xrun_recovery(int err) -{ - int count = 0; - bool reset = false; - - if(err == -EPIPE) { - errorState = QAudio::UnderrunError; - err = snd_pcm_prepare(handle); - if(err < 0) - reset = true; - - } else if((err == -ESTRPIPE)||(err == -EIO)) { - errorState = QAudio::IOError; - while((err = snd_pcm_resume(handle)) == -EAGAIN){ - usleep(100); - count++; - if(count > 5) { - reset = true; - break; - } - } - if(err < 0) { - err = snd_pcm_prepare(handle); - if(err < 0) - reset = true; - } - } - if(reset) { - close(); - open(); - snd_pcm_prepare(handle); - return 0; - } - return err; -} - -int QAudioOutputPrivate::setFormat() -{ - snd_pcm_format_t pcmformat = SND_PCM_FORMAT_S16; - - if(settings.sampleSize() == 8) { - pcmformat = SND_PCM_FORMAT_U8; - - } else if(settings.sampleSize() == 16) { - if(settings.sampleType() == QAudioFormat::SignedInt) { - if(settings.byteOrder() == QAudioFormat::LittleEndian) - pcmformat = SND_PCM_FORMAT_S16_LE; - else - pcmformat = SND_PCM_FORMAT_S16_BE; - } else if(settings.sampleType() == QAudioFormat::UnSignedInt) { - if(settings.byteOrder() == QAudioFormat::LittleEndian) - pcmformat = SND_PCM_FORMAT_U16_LE; - else - pcmformat = SND_PCM_FORMAT_U16_BE; - } - } else if(settings.sampleSize() == 24) { - if(settings.sampleType() == QAudioFormat::SignedInt) { - if(settings.byteOrder() == QAudioFormat::LittleEndian) - pcmformat = SND_PCM_FORMAT_S24_LE; - else - pcmformat = SND_PCM_FORMAT_S24_BE; - } else if(settings.sampleType() == QAudioFormat::UnSignedInt) { - if(settings.byteOrder() == QAudioFormat::LittleEndian) - pcmformat = SND_PCM_FORMAT_U24_LE; - else - pcmformat = SND_PCM_FORMAT_U24_BE; - } - } else if(settings.sampleSize() == 32) { - if(settings.sampleType() == QAudioFormat::SignedInt) { - if(settings.byteOrder() == QAudioFormat::LittleEndian) - pcmformat = SND_PCM_FORMAT_S32_LE; - else - pcmformat = SND_PCM_FORMAT_S32_BE; - } else if(settings.sampleType() == QAudioFormat::UnSignedInt) { - if(settings.byteOrder() == QAudioFormat::LittleEndian) - pcmformat = SND_PCM_FORMAT_U32_LE; - else - pcmformat = SND_PCM_FORMAT_U32_BE; - } else if(settings.sampleType() == QAudioFormat::Float) { - if(settings.byteOrder() == QAudioFormat::LittleEndian) - pcmformat = SND_PCM_FORMAT_FLOAT_LE; - else - pcmformat = SND_PCM_FORMAT_FLOAT_BE; - } - } else if(settings.sampleSize() == 64) { - if(settings.byteOrder() == QAudioFormat::LittleEndian) - pcmformat = SND_PCM_FORMAT_FLOAT64_LE; - else - pcmformat = SND_PCM_FORMAT_FLOAT64_BE; - } - - return snd_pcm_hw_params_set_format( handle, hwparams, pcmformat); -} - -QIODevice* QAudioOutputPrivate::start(QIODevice* device) -{ - if(deviceState != QAudio::StoppedState) - deviceState = QAudio::StoppedState; - - errorState = QAudio::NoError; - - // Handle change of mode - if(audioSource && pullMode && !device) { - // pull -> push - close(); - audioSource = 0; - } else if(audioSource && !pullMode && device) { - // push -> pull - close(); - delete audioSource; - audioSource = 0; - } - - if(device) { - //set to pull mode - pullMode = true; - audioSource = device; - deviceState = QAudio::ActiveState; - } else { - //set to push mode - if(!audioSource) { - audioSource = new OutputPrivate(this); - audioSource->open(QIODevice::WriteOnly|QIODevice::Unbuffered); - } - pullMode = false; - deviceState = QAudio::IdleState; - } - - open(); - - emit stateChanged(deviceState); - - return audioSource; -} - -void QAudioOutputPrivate::stop() -{ - if(deviceState == QAudio::StoppedState) - return; - errorState = QAudio::NoError; - deviceState = QAudio::StoppedState; - close(); - emit stateChanged(deviceState); -} - -bool QAudioOutputPrivate::open() -{ - if(opened) - return true; - -#ifdef DEBUG_AUDIO - QTime now(QTime::currentTime()); - qDebug()< devices = QAudioDeviceInfoInternal::availableDevices(QAudio::AudioOutput); - if(dev.compare(QLatin1String("default")) == 0) { -#if(SND_LIB_MAJOR == 1 && SND_LIB_MINOR == 0 && SND_LIB_SUBMINOR >= 14) - dev = QLatin1String(devices.first().constData()); -#else - dev = QLatin1String("hw:0,0"); -#endif - } else { -#if(SND_LIB_MAJOR == 1 && SND_LIB_MINOR == 0 && SND_LIB_SUBMINOR >= 14) - dev = QLatin1String(m_device); -#else - int idx = 0; - char *name; - - QString shortName = QLatin1String(m_device.mid(m_device.indexOf('=',0)+1).constData()); - - while(snd_card_get_name(idx,&name) == 0) { - if(qstrncmp(shortName.toLocal8Bit().constData(),name,shortName.length()) == 0) - break; - idx++; - } - dev = QString(QLatin1String("hw:%1,0")).arg(idx); -#endif - } - - // Step 1: try and open the device - while((count < 5) && (err < 0)) { - err=snd_pcm_open(&handle,dev.toLocal8Bit().constData(),SND_PCM_STREAM_PLAYBACK,0); - if(err < 0) - count++; - } - if (( err < 0)||(handle == 0)) { - errorState = QAudio::OpenError; - deviceState = QAudio::StoppedState; - return false; - } - snd_pcm_nonblock( handle, 0 ); - - // Step 2: Set the desired HW parameters. - snd_pcm_hw_params_alloca( &hwparams ); - - bool fatal = false; - QString errMessage; - unsigned int chunks = 8; - - err = snd_pcm_hw_params_any( handle, hwparams ); - if ( err < 0 ) { - fatal = true; - errMessage = QString::fromLatin1("QAudioOutput: snd_pcm_hw_params_any: err = %1").arg(err); - } - if ( !fatal ) { - err = snd_pcm_hw_params_set_rate_resample( handle, hwparams, 1 ); - if ( err < 0 ) { - fatal = true; - errMessage = QString::fromLatin1("QAudioOutput: snd_pcm_hw_params_set_rate_resample: err = %1").arg(err); - } - } - if ( !fatal ) { - err = snd_pcm_hw_params_set_access( handle, hwparams, access ); - if ( err < 0 ) { - fatal = true; - errMessage = QString::fromLatin1("QAudioOutput: snd_pcm_hw_params_set_access: err = %1").arg(err); - } - } - if ( !fatal ) { - err = setFormat(); - if ( err < 0 ) { - fatal = true; - errMessage = QString::fromLatin1("QAudioOutput: snd_pcm_hw_params_set_format: err = %1").arg(err); - } - } - if ( !fatal ) { - err = snd_pcm_hw_params_set_channels( handle, hwparams, (unsigned int)settings.channels() ); - if ( err < 0 ) { - fatal = true; - errMessage = QString::fromLatin1("QAudioOutput: snd_pcm_hw_params_set_channels: err = %1").arg(err); - } - } - if ( !fatal ) { - err = snd_pcm_hw_params_set_rate_near( handle, hwparams, &freakuency, 0 ); - if ( err < 0 ) { - fatal = true; - errMessage = QString::fromLatin1("QAudioOutput: snd_pcm_hw_params_set_rate_near: err = %1").arg(err); - } - } - if ( !fatal ) { - unsigned int maxBufferTime = 0; - unsigned int minBufferTime = 0; - unsigned int maxPeriodTime = 0; - unsigned int minPeriodTime = 0; - - err = snd_pcm_hw_params_get_buffer_time_max(hwparams, &maxBufferTime, &dir); - if ( err >= 0) - err = snd_pcm_hw_params_get_buffer_time_min(hwparams, &minBufferTime, &dir); - if ( err >= 0) - err = snd_pcm_hw_params_get_period_time_max(hwparams, &maxPeriodTime, &dir); - if ( err >= 0) - err = snd_pcm_hw_params_get_period_time_min(hwparams, &minPeriodTime, &dir); - - if ( err < 0 ) { - fatal = true; - errMessage = QString::fromLatin1("QAudioOutput: buffer/period min and max: err = %1").arg(err); - } else { - if (maxBufferTime < buffer_time || buffer_time < minBufferTime || maxPeriodTime < period_time || minPeriodTime > period_time) { -#ifdef DEBUG_AUDIO - qDebug()<<"defaults out of range"; - qDebug()<<"pmin="<start(period_time/1000); - - clockStamp.restart(); - timeStamp.restart(); - elapsedTimeOffset = 0; - errorState = QAudio::NoError; - totalTimeValue = 0; - opened = true; - - return true; -} - -void QAudioOutputPrivate::close() -{ - timer->stop(); - - if ( handle ) { - snd_pcm_drain( handle ); - snd_pcm_close( handle ); - handle = 0; - delete [] audioBuffer; - audioBuffer=0; - } - if(!pullMode && audioSource) { - delete audioSource; - audioSource = 0; - } - opened = false; -} - -int QAudioOutputPrivate::bytesFree() const -{ - if(resuming) - return period_size; - - if(deviceState != QAudio::ActiveState && deviceState != QAudio::IdleState) - return 0; - int frames = snd_pcm_avail_update(handle); - if((int)frames > (int)buffer_frames) - frames = buffer_frames; - - return snd_pcm_frames_to_bytes(handle, frames); -} - -qint64 QAudioOutputPrivate::write( const char *data, qint64 len ) -{ - // Write out some audio data - if ( !handle ) - return 0; -#ifdef DEBUG_AUDIO - qDebug()<<"frames to write out = "<< - snd_pcm_bytes_to_frames( handle, (int)len )<<" ("< 0) { - totalTimeValue += err; - resuming = false; - errorState = QAudio::NoError; - if (deviceState != QAudio::ActiveState) { - deviceState = QAudio::ActiveState; - emit stateChanged(deviceState); - } - return snd_pcm_frames_to_bytes( handle, err ); - } else - err = xrun_recovery(err); - - if(err < 0) { - close(); - errorState = QAudio::FatalError; - deviceState = QAudio::StoppedState; - emit stateChanged(deviceState); - } - return 0; -} - -int QAudioOutputPrivate::periodSize() const -{ - return period_size; -} - -void QAudioOutputPrivate::setBufferSize(int value) -{ - if(deviceState == QAudio::StoppedState) - buffer_size = value; -} - -int QAudioOutputPrivate::bufferSize() const -{ - return buffer_size; -} - -void QAudioOutputPrivate::setNotifyInterval(int ms) -{ - if(ms >= minimumIntervalTime) - intervalTime = ms; - else - intervalTime = minimumIntervalTime; -} - -int QAudioOutputPrivate::notifyInterval() const -{ - return intervalTime; -} - -qint64 QAudioOutputPrivate::processedUSecs() const -{ - return qint64(1000000) * totalTimeValue / settings.frequency(); -} - -void QAudioOutputPrivate::resume() -{ - if(deviceState == QAudio::SuspendedState) { - int err = 0; - - if(handle) { - err = snd_pcm_prepare( handle ); - if(err < 0) - xrun_recovery(err); - - err = snd_pcm_start(handle); - if(err < 0) - xrun_recovery(err); - - bytesAvailable = (int)snd_pcm_frames_to_bytes(handle, buffer_frames); - } - resuming = true; - - deviceState = QAudio::ActiveState; - - errorState = QAudio::NoError; - timer->start(period_time/1000); - emit stateChanged(deviceState); - } -} - -QAudioFormat QAudioOutputPrivate::format() const -{ - return settings; -} - -void QAudioOutputPrivate::suspend() -{ - if(deviceState == QAudio::ActiveState || deviceState == QAudio::IdleState || resuming) { - timer->stop(); - deviceState = QAudio::SuspendedState; - errorState = QAudio::NoError; - emit stateChanged(deviceState); - } -} - -void QAudioOutputPrivate::userFeed() -{ - if(deviceState == QAudio::StoppedState || deviceState == QAudio::SuspendedState) - return; -#ifdef DEBUG_AUDIO - QTime now(QTime::currentTime()); - qDebug()<acquireReadRegion((maxFrames - framesRead) * m_bytesPerFrame); - - if (region.second > 0) { - region.second -= region.second % m_bytesPerFrame; - memcpy(data + (framesRead * m_bytesPerFrame), region.first, region.second); - framesRead += region.second / m_bytesPerFrame; - } - else - wecan = false; - - m_buffer->releaseReadRegion(region); - } - - if (framesRead == 0 && m_deviceError) - framesRead = -1; - - return framesRead; - } - - qint64 writeBytes(const char* data, qint64 maxSize) - { - bool wecan = true; - qint64 bytesWritten = 0; - - maxSize -= maxSize % m_bytesPerFrame; - while (wecan && bytesWritten < maxSize) { - QAudioRingBuffer::Region region = m_buffer->acquireWriteRegion(maxSize - bytesWritten); - - if (region.second > 0) { - memcpy(region.first, data + bytesWritten, region.second); - bytesWritten += region.second; - } - else - wecan = false; - - m_buffer->releaseWriteRegion(region); - } - - if (bytesWritten > 0) - emit readyRead(); - - return bytesWritten; - } - - int available() const - { - return m_buffer->free(); - } - - void reset() - { - m_buffer->reset(); - m_deviceError = false; - } - - void setPrefetchDevice(QIODevice* device) - { - if (m_device != device) { - m_device = device; - if (m_device != 0) - fillBuffer(); - } - } - - void startFillTimer() - { - if (m_device != 0) - m_fillTimer->start(m_buffer->size() / 2 / m_maxPeriodSize * m_periodTime); - } - - void stopFillTimer() - { - m_fillTimer->stop(); - } - -signals: - void readyRead(); - -private slots: - void fillBuffer() - { - const int free = m_buffer->free(); - const int writeSize = free - (free % m_maxPeriodSize); - - if (writeSize > 0) { - bool wecan = true; - int filled = 0; - - while (!m_deviceError && wecan && filled < writeSize) { - QAudioRingBuffer::Region region = m_buffer->acquireWriteRegion(writeSize - filled); - - if (region.second > 0) { - region.second = m_device->read(region.first, region.second); - if (region.second > 0) - filled += region.second; - else if (region.second == 0) - wecan = false; - else if (region.second < 0) { - m_fillTimer->stop(); - region.second = 0; - m_deviceError = true; - } - } - else - wecan = false; - - m_buffer->releaseWriteRegion(region); - } - - if (filled > 0) - emit readyRead(); - } - } - -private: - bool m_deviceError; - int m_maxPeriodSize; - int m_bytesPerFrame; - int m_periodTime; - QIODevice* m_device; - QTimer* m_fillTimer; - QAudioRingBuffer* m_buffer; -}; - - -} - -class MacOutputDevice : public QIODevice -{ - Q_OBJECT - -public: - MacOutputDevice(QtMultimediaInternal::QAudioOutputBuffer* audioBuffer, QObject* parent): - QIODevice(parent), - m_audioBuffer(audioBuffer) - { - open(QIODevice::WriteOnly | QIODevice::Unbuffered); - } - - qint64 readData(char* data, qint64 len) - { - Q_UNUSED(data); - Q_UNUSED(len); - - return 0; - } - - qint64 writeData(const char* data, qint64 len) - { - return m_audioBuffer->writeBytes(data, len); - } - - bool isSequential() const - { - return true; - } - -private: - QtMultimediaInternal::QAudioOutputBuffer* m_audioBuffer; -}; - - -QAudioOutputPrivate::QAudioOutputPrivate(const QByteArray& device, const QAudioFormat& format): - audioFormat(format) -{ - QDataStream ds(device); - quint32 did, mode; - - ds >> did >> mode; - - if (QAudio::Mode(mode) == QAudio::AudioInput) - errorCode = QAudio::OpenError; - else { - isOpen = false; - audioDeviceId = AudioDeviceID(did); - audioUnit = 0; - audioIO = 0; - startTime = 0; - totalFrames = 0; - audioBuffer = 0; - internalBufferSize = QtMultimediaInternal::default_buffer_size; - clockFrequency = AudioGetHostClockFrequency() / 1000; - errorCode = QAudio::NoError; - stateCode = QAudio::StoppedState; - audioThreadState = Stopped; - - intervalTimer = new QTimer(this); - intervalTimer->setInterval(1000); - connect(intervalTimer, SIGNAL(timeout()), SIGNAL(notify())); - } -} - -QAudioOutputPrivate::~QAudioOutputPrivate() -{ - close(); -} - -bool QAudioOutputPrivate::open() -{ - if (errorCode != QAudio::NoError) - return false; - - if (isOpen) - return true; - - ComponentDescription cd; - cd.componentType = kAudioUnitType_Output; - cd.componentSubType = kAudioUnitSubType_HALOutput; - cd.componentManufacturer = kAudioUnitManufacturer_Apple; - cd.componentFlags = 0; - cd.componentFlagsMask = 0; - - // Open - Component cp = FindNextComponent(NULL, &cd); - if (cp == 0) { - qWarning() << "QAudioOutput: Failed to find HAL Output component"; - return false; - } - - if (OpenAComponent(cp, &audioUnit) != noErr) { - qWarning() << "QAudioOutput: Unable to Open Output Component"; - return false; - } - - // register callback - AURenderCallbackStruct cb; - cb.inputProc = renderCallback; - cb.inputProcRefCon = this; - - if (AudioUnitSetProperty(audioUnit, - kAudioUnitProperty_SetRenderCallback, - kAudioUnitScope_Global, - 0, - &cb, - sizeof(cb)) != noErr) { - qWarning() << "QAudioOutput: Failed to set AudioUnit callback"; - return false; - } - - // Set Audio Device - if (AudioUnitSetProperty(audioUnit, - kAudioOutputUnitProperty_CurrentDevice, - kAudioUnitScope_Global, - 0, - &audioDeviceId, - sizeof(audioDeviceId)) != noErr) { - qWarning() << "QAudioOutput: Unable to use configured device"; - return false; - } - - // Set stream format - streamFormat = toAudioStreamBasicDescription(audioFormat); - - UInt32 size = sizeof(deviceFormat); - if (AudioUnitGetProperty(audioUnit, - kAudioUnitProperty_StreamFormat, - kAudioUnitScope_Input, - 0, - &deviceFormat, - &size) != noErr) { - qWarning() << "QAudioOutput: Unable to retrieve device format"; - return false; - } - - if (AudioUnitSetProperty(audioUnit, - kAudioUnitProperty_StreamFormat, - kAudioUnitScope_Input, - 0, - &streamFormat, - sizeof(streamFormat)) != noErr) { - qWarning() << "QAudioOutput: Unable to Set Stream information"; - return false; - } - - // Allocate buffer - UInt32 numberOfFrames = 0; - size = sizeof(UInt32); - if (AudioUnitGetProperty(audioUnit, - kAudioDevicePropertyBufferFrameSize, - kAudioUnitScope_Global, - 0, - &numberOfFrames, - &size) != noErr) { - qWarning() << "QAudioInput: Failed to get audio period size"; - return false; - } - - periodSizeBytes = (numberOfFrames * streamFormat.mSampleRate / deviceFormat.mSampleRate) * - streamFormat.mBytesPerFrame; - if (internalBufferSize < periodSizeBytes * 2) - internalBufferSize = periodSizeBytes * 2; - else - internalBufferSize -= internalBufferSize % streamFormat.mBytesPerFrame; - - audioBuffer = new QtMultimediaInternal::QAudioOutputBuffer(internalBufferSize, periodSizeBytes, audioFormat); - connect(audioBuffer, SIGNAL(readyRead()), SLOT(inputReady())); // Pull - - audioIO = new MacOutputDevice(audioBuffer, this); - - // Init - if (AudioUnitInitialize(audioUnit)) { - qWarning() << "QAudioOutput: Failed to initialize AudioUnit"; - return false; - } - - isOpen = true; - - return true; -} - -void QAudioOutputPrivate::close() -{ - if (audioUnit != 0) { - AudioOutputUnitStop(audioUnit); - AudioUnitUninitialize(audioUnit); - CloseComponent(audioUnit); - } - - delete audioBuffer; -} - -QAudioFormat QAudioOutputPrivate::format() const -{ - return audioFormat; -} - -QIODevice* QAudioOutputPrivate::start(QIODevice* device) -{ - QIODevice* op = device; - - if (!audioFormat.isValid() || !open()) { - stateCode = QAudio::StoppedState; - errorCode = QAudio::OpenError; - return audioIO; - } - - reset(); - audioBuffer->reset(); - audioBuffer->setPrefetchDevice(op); - - if (op == 0) { - op = audioIO; - stateCode = QAudio::IdleState; - } - else - stateCode = QAudio::ActiveState; - - // Start - errorCode = QAudio::NoError; - totalFrames = 0; - startTime = AudioGetCurrentHostTime(); - - if (stateCode == QAudio::ActiveState) - audioThreadStart(); - - emit stateChanged(stateCode); - - return op; -} - -void QAudioOutputPrivate::stop() -{ - QMutexLocker lock(&mutex); - if (stateCode != QAudio::StoppedState) { - audioThreadDrain(); - - stateCode = QAudio::StoppedState; - errorCode = QAudio::NoError; - QMetaObject::invokeMethod(this, "stateChanged", Qt::QueuedConnection, Q_ARG(QAudio::State, stateCode)); - } -} - -void QAudioOutputPrivate::reset() -{ - QMutexLocker lock(&mutex); - if (stateCode != QAudio::StoppedState) { - audioThreadStop(); - - stateCode = QAudio::StoppedState; - errorCode = QAudio::NoError; - QMetaObject::invokeMethod(this, "stateChanged", Qt::QueuedConnection, Q_ARG(QAudio::State, stateCode)); - } -} - -void QAudioOutputPrivate::suspend() -{ - QMutexLocker lock(&mutex); - if (stateCode == QAudio::ActiveState || stateCode == QAudio::IdleState) { - audioThreadStop(); - - stateCode = QAudio::SuspendedState; - errorCode = QAudio::NoError; - QMetaObject::invokeMethod(this, "stateChanged", Qt::QueuedConnection, Q_ARG(QAudio::State, stateCode)); - } -} - -void QAudioOutputPrivate::resume() -{ - QMutexLocker lock(&mutex); - if (stateCode == QAudio::SuspendedState) { - audioThreadStart(); - - stateCode = QAudio::ActiveState; - errorCode = QAudio::NoError; - QMetaObject::invokeMethod(this, "stateChanged", Qt::QueuedConnection, Q_ARG(QAudio::State, stateCode)); - } -} - -int QAudioOutputPrivate::bytesFree() const -{ - return audioBuffer->available(); -} - -int QAudioOutputPrivate::periodSize() const -{ - return periodSizeBytes; -} - -void QAudioOutputPrivate::setBufferSize(int bs) -{ - if (stateCode == QAudio::StoppedState) - internalBufferSize = bs; -} - -int QAudioOutputPrivate::bufferSize() const -{ - return internalBufferSize; -} - -void QAudioOutputPrivate::setNotifyInterval(int milliSeconds) -{ - if (intervalTimer->interval() == milliSeconds) - return; - - if (milliSeconds <= 0) - milliSeconds = 0; - - intervalTimer->setInterval(milliSeconds); -} - -int QAudioOutputPrivate::notifyInterval() const -{ - return intervalTimer->interval(); -} - -qint64 QAudioOutputPrivate::processedUSecs() const -{ - return totalFrames * 1000000 / audioFormat.frequency(); -} - -qint64 QAudioOutputPrivate::elapsedUSecs() const -{ - if (stateCode == QAudio::StoppedState) - return 0; - - return (AudioGetCurrentHostTime() - startTime) / (clockFrequency / 1000); -} - -QAudio::Error QAudioOutputPrivate::error() const -{ - return errorCode; -} - -QAudio::State QAudioOutputPrivate::state() const -{ - return stateCode; -} - -void QAudioOutputPrivate::audioThreadStart() -{ - startTimers(); - audioThreadState = Running; - AudioOutputUnitStart(audioUnit); -} - -void QAudioOutputPrivate::audioThreadStop() -{ - stopTimers(); - if (audioThreadState.testAndSetAcquire(Running, Stopped)) - threadFinished.wait(&mutex); -} - -void QAudioOutputPrivate::audioThreadDrain() -{ - stopTimers(); - if (audioThreadState.testAndSetAcquire(Running, Draining)) - threadFinished.wait(&mutex); -} - -void QAudioOutputPrivate::audioDeviceStop() -{ - AudioOutputUnitStop(audioUnit); - audioThreadState = Stopped; - threadFinished.wakeOne(); -} - -void QAudioOutputPrivate::audioDeviceIdle() -{ - QMutexLocker lock(&mutex); - if (stateCode == QAudio::ActiveState) { - audioDeviceStop(); - - errorCode = QAudio::UnderrunError; - stateCode = QAudio::IdleState; - QMetaObject::invokeMethod(this, "deviceStopped", Qt::QueuedConnection); - } -} - -void QAudioOutputPrivate::audioDeviceError() -{ - QMutexLocker lock(&mutex); - if (stateCode == QAudio::ActiveState) { - audioDeviceStop(); - - errorCode = QAudio::IOError; - stateCode = QAudio::StoppedState; - QMetaObject::invokeMethod(this, "deviceStopped", Qt::QueuedConnection); - } -} - -void QAudioOutputPrivate::startTimers() -{ - audioBuffer->startFillTimer(); - if (intervalTimer->interval() > 0) - intervalTimer->start(); -} - -void QAudioOutputPrivate::stopTimers() -{ - audioBuffer->stopFillTimer(); - intervalTimer->stop(); -} - - -void QAudioOutputPrivate::deviceStopped() -{ - intervalTimer->stop(); - emit stateChanged(stateCode); -} - -void QAudioOutputPrivate::inputReady() -{ - QMutexLocker lock(&mutex); - if (stateCode == QAudio::IdleState) { - audioThreadStart(); - - stateCode = QAudio::ActiveState; - errorCode = QAudio::NoError; - - QMetaObject::invokeMethod(this, "stateChanged", Qt::QueuedConnection, Q_ARG(QAudio::State, stateCode)); - } -} - - -OSStatus QAudioOutputPrivate::renderCallback(void* inRefCon, - AudioUnitRenderActionFlags* ioActionFlags, - const AudioTimeStamp* inTimeStamp, - UInt32 inBusNumber, - UInt32 inNumberFrames, - AudioBufferList* ioData) -{ - Q_UNUSED(ioActionFlags) - Q_UNUSED(inTimeStamp) - Q_UNUSED(inBusNumber) - Q_UNUSED(inNumberFrames) - - QAudioOutputPrivate* d = static_cast(inRefCon); - - const int threadState = d->audioThreadState.fetchAndAddAcquire(0); - if (threadState == Stopped) { - ioData->mBuffers[0].mDataByteSize = 0; - d->audioDeviceStop(); - } - else { - const UInt32 bytesPerFrame = d->streamFormat.mBytesPerFrame; - qint64 framesRead; - - framesRead = d->audioBuffer->readFrames((char*)ioData->mBuffers[0].mData, - ioData->mBuffers[0].mDataByteSize / bytesPerFrame); - - if (framesRead > 0) { - ioData->mBuffers[0].mDataByteSize = framesRead * bytesPerFrame; - d->totalFrames += framesRead; - } - else { - ioData->mBuffers[0].mDataByteSize = 0; - if (framesRead == 0) { - if (threadState == Draining) - d->audioDeviceStop(); - else - d->audioDeviceIdle(); - } - else - d->audioDeviceError(); - } - } - - return noErr; -} - - -QT_END_NAMESPACE - -#include "qaudiooutput_mac_p.moc" - diff --git a/src/multimedia/audio/qaudiooutput_mac_p.h b/src/multimedia/audio/qaudiooutput_mac_p.h deleted file mode 100644 index 752905c..0000000 --- a/src/multimedia/audio/qaudiooutput_mac_p.h +++ /dev/null @@ -1,167 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtMultimedia module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -// -// W A R N I N G -// ------------- -// -// This file is not part of the Qt API. It exists for the convenience -// of other Qt classes. This header file may change from version to -// version without notice, or even be removed. -// -// We mean it. -// - -#ifndef QAUDIOOUTPUT_MAC_P_H -#define QAUDIOOUTPUT_MAC_P_H - -#include -#include -#include -#include - -#include -#include -#include -#include -#include - -#include -#include -#include - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -class QIODevice; - -namespace QtMultimediaInternal -{ -class QAudioOutputBuffer; -} - -class QAudioOutputPrivate : public QAbstractAudioOutput -{ - Q_OBJECT - -public: - bool isOpen; - int internalBufferSize; - int periodSizeBytes; - qint64 totalFrames; - QAudioFormat audioFormat; - QIODevice* audioIO; - AudioDeviceID audioDeviceId; - AudioUnit audioUnit; - Float64 clockFrequency; - UInt64 startTime; - AudioStreamBasicDescription deviceFormat; - AudioStreamBasicDescription streamFormat; - QtMultimediaInternal::QAudioOutputBuffer* audioBuffer; - QAtomicInt audioThreadState; - QWaitCondition threadFinished; - QMutex mutex; - QTimer* intervalTimer; - - QAudio::Error errorCode; - QAudio::State stateCode; - - QAudioOutputPrivate(const QByteArray& device, const QAudioFormat& format); - ~QAudioOutputPrivate(); - - bool open(); - void close(); - - QAudioFormat format() const; - - QIODevice* start(QIODevice* device); - void stop(); - void reset(); - void suspend(); - void resume(); - - int bytesFree() const; - int periodSize() const; - - void setBufferSize(int value); - int bufferSize() const; - - void setNotifyInterval(int milliSeconds); - int notifyInterval() const; - - qint64 processedUSecs() const; - qint64 elapsedUSecs() const; - - QAudio::Error error() const; - QAudio::State state() const; - - void audioThreadStart(); - void audioThreadStop(); - void audioThreadDrain(); - - void audioDeviceStop(); - void audioDeviceIdle(); - void audioDeviceError(); - - void startTimers(); - void stopTimers(); - -private slots: - void deviceStopped(); - void inputReady(); - -private: - enum { Running, Draining, Stopped }; - - static OSStatus renderCallback(void* inRefCon, - AudioUnitRenderActionFlags* ioActionFlags, - const AudioTimeStamp* inTimeStamp, - UInt32 inBusNumber, - UInt32 inNumberFrames, - AudioBufferList* ioData); -}; - -QT_END_NAMESPACE - -QT_END_HEADER - -#endif diff --git a/src/multimedia/audio/qaudiooutput_symbian_p.cpp b/src/multimedia/audio/qaudiooutput_symbian_p.cpp deleted file mode 100644 index 3f8e933..0000000 --- a/src/multimedia/audio/qaudiooutput_symbian_p.cpp +++ /dev/null @@ -1,697 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtMultimedia module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qaudiooutput_symbian_p.h" - -QT_BEGIN_NAMESPACE - -//----------------------------------------------------------------------------- -// Constants -//----------------------------------------------------------------------------- - -const int UnderflowTimerInterval = 50; // ms - - -//----------------------------------------------------------------------------- -// Private class -//----------------------------------------------------------------------------- - -SymbianAudioOutputPrivate::SymbianAudioOutputPrivate( - QAudioOutputPrivate *audioDevice) - : m_audioDevice(audioDevice) -{ - -} - -SymbianAudioOutputPrivate::~SymbianAudioOutputPrivate() -{ - -} - -qint64 SymbianAudioOutputPrivate::readData(char *data, qint64 len) -{ - Q_UNUSED(data) - Q_UNUSED(len) - return 0; -} - -qint64 SymbianAudioOutputPrivate::writeData(const char *data, qint64 len) -{ - qint64 totalWritten = 0; - - if (m_audioDevice->state() == QAudio::ActiveState || - m_audioDevice->state() == QAudio::IdleState) { - - while (totalWritten < len) { - const qint64 written = m_audioDevice->pushData(data + totalWritten, - len - totalWritten); - if (written > 0) - totalWritten += written; - else - break; - } - } - - return totalWritten; -} - - -//----------------------------------------------------------------------------- -// Public functions -//----------------------------------------------------------------------------- - -QAudioOutputPrivate::QAudioOutputPrivate(const QByteArray &device, - const QAudioFormat &format) - : m_device(device) - , m_format(format) - , m_clientBufferSize(SymbianAudio::DefaultBufferSize) - , m_notifyInterval(SymbianAudio::DefaultNotifyInterval) - , m_notifyTimer(new QTimer(this)) - , m_error(QAudio::NoError) - , m_internalState(SymbianAudio::ClosedState) - , m_externalState(QAudio::StoppedState) - , m_pullMode(false) - , m_source(0) - , m_devSoundBuffer(0) - , m_devSoundBufferSize(0) - , m_bytesWritten(0) - , m_pushDataReady(false) - , m_bytesPadding(0) - , m_underflow(false) - , m_lastBuffer(false) - , m_underflowTimer(new QTimer(this)) - , m_samplesPlayed(0) - , m_totalSamplesPlayed(0) -{ - connect(m_notifyTimer.data(), SIGNAL(timeout()), this, SIGNAL(notify())); - - SymbianAudio::Utils::formatQtToNative(m_format, m_nativeFourCC, - m_nativeFormat); - - m_underflowTimer->setInterval(UnderflowTimerInterval); - connect(m_underflowTimer.data(), SIGNAL(timeout()), this, - SLOT(underflowTimerExpired())); -} - -QAudioOutputPrivate::~QAudioOutputPrivate() -{ - close(); -} - -QIODevice* QAudioOutputPrivate::start(QIODevice *device) -{ - stop(); - - // We have to set these before the call to open() because of the - // logic in initializingState() - if (device) { - m_pullMode = true; - m_source = device; - } - - open(); - - if (SymbianAudio::ClosedState != m_internalState) { - if (device) { - connect(m_source, SIGNAL(readyRead()), this, SLOT(dataReady())); - } else { - m_source = new SymbianAudioOutputPrivate(this); - m_source->open(QIODevice::WriteOnly | QIODevice::Unbuffered); - } - - m_elapsed.restart(); - } - - return m_source; -} - -void QAudioOutputPrivate::stop() -{ - close(); -} - -void QAudioOutputPrivate::reset() -{ - m_totalSamplesPlayed += getSamplesPlayed(); - m_devSound->Stop(); - m_bytesPadding = 0; - startPlayback(); -} - -void QAudioOutputPrivate::suspend() -{ - if (SymbianAudio::ActiveState == m_internalState - || SymbianAudio::IdleState == m_internalState) { - m_notifyTimer->stop(); - m_underflowTimer->stop(); - - const qint64 samplesWritten = SymbianAudio::Utils::bytesToSamples( - m_format, m_bytesWritten); - - const qint64 samplesPlayed = getSamplesPlayed(); - - m_bytesWritten = 0; - - // CMMFDevSound::Pause() is not guaranteed to work correctly in all - // implementations, for play-mode DevSound sessions. We therefore - // have to implement suspend() by calling CMMFDevSound::Stop(). - // Because this causes buffered data to be dropped, we replace the - // lost data with silence following a call to resume(), in order to - // ensure that processedUSecs() returns the correct value. - m_devSound->Stop(); - m_totalSamplesPlayed += samplesPlayed; - - // Calculate the amount of data dropped - const qint64 paddingSamples = samplesWritten - samplesPlayed; - m_bytesPadding = SymbianAudio::Utils::samplesToBytes(m_format, - paddingSamples); - - setState(SymbianAudio::SuspendedState); - } -} - -void QAudioOutputPrivate::resume() -{ - if (SymbianAudio::SuspendedState == m_internalState) - startPlayback(); -} - -int QAudioOutputPrivate::bytesFree() const -{ - int result = 0; - if (m_devSoundBuffer) { - const TDes8 &outputBuffer = m_devSoundBuffer->Data(); - result = outputBuffer.MaxLength() - outputBuffer.Length(); - } - return result; -} - -int QAudioOutputPrivate::periodSize() const -{ - return bufferSize(); -} - -void QAudioOutputPrivate::setBufferSize(int value) -{ - // Note that DevSound does not allow its client to specify the buffer size. - // This functionality is available via custom interfaces, but since these - // cannot be guaranteed to work across all DevSound implementations, we - // do not use them here. - // In order to comply with the expected bevahiour of QAudioOutput, we store - // the value and return it from bufferSize(), but the underlying DevSound - // buffer size remains unchanged. - if (value > 0) - m_clientBufferSize = value; -} - -int QAudioOutputPrivate::bufferSize() const -{ - return m_devSoundBufferSize ? m_devSoundBufferSize : m_clientBufferSize; -} - -void QAudioOutputPrivate::setNotifyInterval(int ms) -{ - if (ms > 0) { - const int oldNotifyInterval = m_notifyInterval; - m_notifyInterval = ms; - if (m_notifyTimer->isActive() && ms != oldNotifyInterval) - m_notifyTimer->start(m_notifyInterval); - } -} - -int QAudioOutputPrivate::notifyInterval() const -{ - return m_notifyInterval; -} - -qint64 QAudioOutputPrivate::processedUSecs() const -{ - int samplesPlayed = 0; - if (m_devSound && SymbianAudio::SuspendedState != m_internalState) - samplesPlayed = getSamplesPlayed(); - - // Protect against division by zero - Q_ASSERT_X(m_format.frequency() > 0, Q_FUNC_INFO, "Invalid frequency"); - - const qint64 result = qint64(1000000) * - (samplesPlayed + m_totalSamplesPlayed) - / m_format.frequency(); - - return result; -} - -qint64 QAudioOutputPrivate::elapsedUSecs() const -{ - const qint64 result = (QAudio::StoppedState == state()) ? - 0 : m_elapsed.elapsed() * 1000; - return result; -} - -QAudio::Error QAudioOutputPrivate::error() const -{ - return m_error; -} - -QAudio::State QAudioOutputPrivate::state() const -{ - return m_externalState; -} - -QAudioFormat QAudioOutputPrivate::format() const -{ - return m_format; -} - -//----------------------------------------------------------------------------- -// MDevSoundObserver implementation -//----------------------------------------------------------------------------- - -void QAudioOutputPrivate::InitializeComplete(TInt aError) -{ - Q_ASSERT_X(SymbianAudio::InitializingState == m_internalState, - Q_FUNC_INFO, "Invalid state"); - - if (KErrNone == aError) - startPlayback(); -} - -void QAudioOutputPrivate::ToneFinished(TInt aError) -{ - Q_UNUSED(aError) - // This class doesn't use DevSound's tone playback functions, so should - // never receive this callback. - Q_ASSERT_X(false, Q_FUNC_INFO, "Unexpected callback"); -} - -void QAudioOutputPrivate::BufferToBeFilled(CMMFBuffer *aBuffer) -{ - // Following receipt of this callback, DevSound should not provide another - // buffer until we have returned the current one. - Q_ASSERT_X(!m_devSoundBuffer, Q_FUNC_INFO, "Buffer already held"); - - // Will be returned to DevSound by bufferFilled(). - m_devSoundBuffer = static_cast(aBuffer); - - if (!m_devSoundBufferSize) - m_devSoundBufferSize = m_devSoundBuffer->Data().MaxLength(); - - writePaddingData(); - - if (m_pullMode && isDataReady() && !m_bytesPadding) - pullData(); -} - -void QAudioOutputPrivate::PlayError(TInt aError) -{ - switch (aError) { - case KErrUnderflow: - m_underflow = true; - if (m_pullMode && !m_lastBuffer) - setError(QAudio::UnderrunError); - else - setState(SymbianAudio::IdleState); - break; - default: - setError(QAudio::IOError); - break; - } -} - -void QAudioOutputPrivate::BufferToBeEmptied(CMMFBuffer *aBuffer) -{ - Q_UNUSED(aBuffer) - // This class doesn't use DevSound in record mode, so should never receive - // this callback. - Q_ASSERT_X(false, Q_FUNC_INFO, "Unexpected callback"); -} - -void QAudioOutputPrivate::RecordError(TInt aError) -{ - Q_UNUSED(aError) - // This class doesn't use DevSound in record mode, so should never receive - // this callback. - Q_ASSERT_X(false, Q_FUNC_INFO, "Unexpected callback"); -} - -void QAudioOutputPrivate::ConvertError(TInt aError) -{ - Q_UNUSED(aError) - // This class doesn't use DevSound's format conversion functions, so - // should never receive this callback. - Q_ASSERT_X(false, Q_FUNC_INFO, "Unexpected callback"); -} - -void QAudioOutputPrivate::DeviceMessage(TUid aMessageType, const TDesC8 &aMsg) -{ - Q_UNUSED(aMessageType) - Q_UNUSED(aMsg) - // Ignore this callback. -} - -//----------------------------------------------------------------------------- -// Private functions -//----------------------------------------------------------------------------- - -void QAudioOutputPrivate::dataReady() -{ - // Client-provided QIODevice has data ready to read. - - Q_ASSERT_X(m_source->bytesAvailable(), Q_FUNC_INFO, - "readyRead signal received, but no data available"); - - if (!m_bytesPadding) - pullData(); -} - -void QAudioOutputPrivate::underflowTimerExpired() -{ - const TInt samplesPlayed = getSamplesPlayed(); - if (m_samplesPlayed && (samplesPlayed == m_samplesPlayed)) { - setError(QAudio::UnderrunError); - } else { - m_samplesPlayed = samplesPlayed; - m_underflowTimer->start(); - } -} - -void QAudioOutputPrivate::open() -{ - Q_ASSERT_X(SymbianAudio::ClosedState == m_internalState, - Q_FUNC_INFO, "DevSound already opened"); - - QT_TRAP_THROWING( m_devSound.reset(CMMFDevSound::NewL()) ) - - QScopedPointer caps( - new SymbianAudio::DevSoundCapabilities(*m_devSound, - QAudio::AudioOutput)); - - int err = SymbianAudio::Utils::isFormatSupported(m_format, *caps) ? - KErrNone : KErrNotSupported; - - if (KErrNone == err) { - setState(SymbianAudio::InitializingState); - TRAP(err, m_devSound->InitializeL(*this, m_nativeFourCC, - EMMFStatePlaying)); - } - - if (KErrNone != err) { - setError(QAudio::OpenError); - m_devSound.reset(); - } -} - -void QAudioOutputPrivate::startPlayback() -{ - TRAPD(err, startDevSoundL()); - if (KErrNone == err) { - if (isDataReady()) - setState(SymbianAudio::ActiveState); - else - setState(SymbianAudio::IdleState); - - m_notifyTimer->start(m_notifyInterval); - m_underflow = false; - - Q_ASSERT(m_devSound->SamplesPlayed() == 0); - - writePaddingData(); - - if (m_pullMode && m_source->bytesAvailable() && !m_bytesPadding) - dataReady(); - } else { - setError(QAudio::OpenError); - close(); - } -} - -void QAudioOutputPrivate::startDevSoundL() -{ - TMMFCapabilities nativeFormat = m_devSound->Config(); - m_nativeFormat.iBufferSize = nativeFormat.iBufferSize; - m_devSound->SetConfigL(m_nativeFormat); - m_devSound->PlayInitL(); -} - -void QAudioOutputPrivate::writePaddingData() -{ - // See comments in suspend() - - while (m_devSoundBuffer && m_bytesPadding) { - if (SymbianAudio::IdleState == m_internalState) - setState(SymbianAudio::ActiveState); - - TDes8 &outputBuffer = m_devSoundBuffer->Data(); - const qint64 outputBytes = bytesFree(); - const qint64 paddingBytes = outputBytes < m_bytesPadding ? - outputBytes : m_bytesPadding; - unsigned char *ptr = const_cast(outputBuffer.Ptr()); - Mem::FillZ(ptr, paddingBytes); - outputBuffer.SetLength(outputBuffer.Length() + paddingBytes); - m_bytesPadding -= paddingBytes; - - if (m_pullMode && m_source->atEnd()) - lastBufferFilled(); - if (paddingBytes == outputBytes) - bufferFilled(); - } -} - -qint64 QAudioOutputPrivate::pushData(const char *data, qint64 len) -{ - // Data has been written to SymbianAudioOutputPrivate - - Q_ASSERT_X(!m_pullMode, Q_FUNC_INFO, - "pushData called when in pull mode"); - - const unsigned char *const inputPtr = - reinterpret_cast(data); - qint64 bytesWritten = 0; - - if (SymbianAudio::IdleState == m_internalState) - setState(SymbianAudio::ActiveState); - - while (m_devSoundBuffer && (bytesWritten < len)) { - // writePaddingData() is called from BufferToBeFilled(), so we should - // never have any padding data left at this point. - Q_ASSERT_X(0 == m_bytesPadding, Q_FUNC_INFO, - "Padding bytes remaining in pushData"); - - TDes8 &outputBuffer = m_devSoundBuffer->Data(); - - const qint64 outputBytes = bytesFree(); - const qint64 inputBytes = len - bytesWritten; - const qint64 copyBytes = outputBytes < inputBytes ? - outputBytes : inputBytes; - - outputBuffer.Append(inputPtr + bytesWritten, copyBytes); - bytesWritten += copyBytes; - - bufferFilled(); - } - - m_pushDataReady = (bytesWritten < len); - - // If DevSound is still initializing (m_internalState == InitializingState), - // we cannot transition m_internalState to ActiveState, but we must emit - // an (external) state change from IdleState to ActiveState. The following - // call triggers this signal. - setState(m_internalState); - - return bytesWritten; -} - -void QAudioOutputPrivate::pullData() -{ - Q_ASSERT_X(m_pullMode, Q_FUNC_INFO, - "pullData called when in push mode"); - - if (m_bytesPadding) - m_bytesPadding = 1; - - // writePaddingData() is called by BufferToBeFilled() before pullData(), - // so we should never have any padding data left at this point. - Q_ASSERT_X(0 == m_bytesPadding, Q_FUNC_INFO, - "Padding bytes remaining in pullData"); - - qint64 inputBytes = m_source->bytesAvailable(); - while (m_devSoundBuffer && inputBytes) { - if (SymbianAudio::IdleState == m_internalState) - setState(SymbianAudio::ActiveState); - - TDes8 &outputBuffer = m_devSoundBuffer->Data(); - - const qint64 outputBytes = bytesFree(); - const qint64 copyBytes = outputBytes < inputBytes ? - outputBytes : inputBytes; - - char *outputPtr = (char*)(outputBuffer.Ptr() + outputBuffer.Length()); - const qint64 bytesCopied = m_source->read(outputPtr, copyBytes); - Q_ASSERT(bytesCopied == copyBytes); - outputBuffer.SetLength(outputBuffer.Length() + bytesCopied); - inputBytes -= bytesCopied; - - if (m_source->atEnd()) - lastBufferFilled(); - else if (copyBytes == outputBytes) - bufferFilled(); - } -} - -void QAudioOutputPrivate::bufferFilled() -{ - Q_ASSERT_X(m_devSoundBuffer, Q_FUNC_INFO, "No buffer to return"); - - const TDes8 &outputBuffer = m_devSoundBuffer->Data(); - m_bytesWritten += outputBuffer.Length(); - - m_devSoundBuffer = 0; - - m_samplesPlayed = getSamplesPlayed(); - m_underflowTimer->start(); - - if (QAudio::UnderrunError == m_error) - m_error = QAudio::NoError; - - m_devSound->PlayData(); -} - -void QAudioOutputPrivate::lastBufferFilled() -{ - Q_ASSERT_X(m_devSoundBuffer, Q_FUNC_INFO, "No buffer to fill"); - Q_ASSERT_X(!m_lastBuffer, Q_FUNC_INFO, "Last buffer already sent"); - m_lastBuffer = true; - m_devSoundBuffer->SetLastBuffer(ETrue); - bufferFilled(); -} - -void QAudioOutputPrivate::close() -{ - m_notifyTimer->stop(); - m_underflowTimer->stop(); - - m_error = QAudio::NoError; - - if (m_devSound) - m_devSound->Stop(); - m_devSound.reset(); - m_devSoundBuffer = 0; - m_devSoundBufferSize = 0; - - if (!m_pullMode) // m_source is owned - delete m_source; - m_pullMode = false; - m_source = 0; - - m_bytesWritten = 0; - m_pushDataReady = false; - m_bytesPadding = 0; - m_underflow = false; - m_lastBuffer = false; - m_samplesPlayed = 0; - m_totalSamplesPlayed = 0; - - setState(SymbianAudio::ClosedState); -} - -qint64 QAudioOutputPrivate::getSamplesPlayed() const -{ - qint64 result = 0; - if (m_devSound) { - const qint64 samplesWritten = SymbianAudio::Utils::bytesToSamples( - m_format, m_bytesWritten); - - if (m_underflow) { - result = samplesWritten; - } else { - // This is necessary because some DevSound implementations report - // that they have played more data than has actually been provided to them - // by the client. - const qint64 devSoundSamplesPlayed(m_devSound->SamplesPlayed()); - result = qMin(devSoundSamplesPlayed, samplesWritten); - } - } - return result; -} - -void QAudioOutputPrivate::setError(QAudio::Error error) -{ - m_error = error; - - // Although no state transition actually occurs here, a stateChanged event - // must be emitted to inform the client that the call to start() was - // unsuccessful. - if (QAudio::OpenError == error) - emit stateChanged(QAudio::StoppedState); - - if (QAudio::UnderrunError == error) - setState(SymbianAudio::IdleState); - else - // Close the DevSound instance. This causes a transition to - // StoppedState. This must be done asynchronously in case the - // current function was called from a DevSound event handler, in which - // case deleting the DevSound instance may cause an exception. - QMetaObject::invokeMethod(this, "close", Qt::QueuedConnection); -} - -void QAudioOutputPrivate::setState(SymbianAudio::State newInternalState) -{ - const QAudio::State oldExternalState = m_externalState; - m_internalState = newInternalState; - m_externalState = SymbianAudio::Utils::stateNativeToQt( - m_internalState, initializingState()); - - if (m_externalState != oldExternalState) - emit stateChanged(m_externalState); -} - -bool QAudioOutputPrivate::isDataReady() const -{ - return (m_source && m_source->bytesAvailable()) - || m_bytesPadding - || m_pushDataReady; -} - -QAudio::State QAudioOutputPrivate::initializingState() const -{ - return isDataReady() ? QAudio::ActiveState : QAudio::IdleState; -} - -QT_END_NAMESPACE diff --git a/src/multimedia/audio/qaudiooutput_symbian_p.h b/src/multimedia/audio/qaudiooutput_symbian_p.h deleted file mode 100644 index 00ccb24..0000000 --- a/src/multimedia/audio/qaudiooutput_symbian_p.h +++ /dev/null @@ -1,210 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtMultimedia module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -// -// W A R N I N G -// ------------- -// -// This file is not part of the Qt API. It exists for the convenience -// of other Qt classes. This header file may change from version to -// version without notice, or even be removed. -// -// We mean it. -// - -#ifndef QAUDIOOUTPUT_SYMBIAN_P_H -#define QAUDIOOUTPUT_SYMBIAN_P_H - -#include -#include -#include -#include -#include "qaudio_symbian_p.h" - -QT_BEGIN_NAMESPACE - -class QAudioOutputPrivate; - -class SymbianAudioOutputPrivate : public QIODevice -{ - friend class QAudioOutputPrivate; - Q_OBJECT -public: - SymbianAudioOutputPrivate(QAudioOutputPrivate *audio); - ~SymbianAudioOutputPrivate(); - - qint64 readData(char *data, qint64 len); - qint64 writeData(const char *data, qint64 len); - -private: - QAudioOutputPrivate *const m_audioDevice; -}; - -class QAudioOutputPrivate - : public QAbstractAudioOutput - , public MDevSoundObserver -{ - friend class SymbianAudioOutputPrivate; - Q_OBJECT -public: - QAudioOutputPrivate(const QByteArray &device, - const QAudioFormat &audioFormat); - ~QAudioOutputPrivate(); - - // QAbstractAudioOutput - QIODevice* start(QIODevice *device = 0); - void stop(); - void reset(); - void suspend(); - void resume(); - int bytesFree() const; - int periodSize() const; - void setBufferSize(int value); - int bufferSize() const; - void setNotifyInterval(int milliSeconds); - int notifyInterval() const; - qint64 processedUSecs() const; - qint64 elapsedUSecs() const; - QAudio::Error error() const; - QAudio::State state() const; - QAudioFormat format() const; - - // MDevSoundObserver - void InitializeComplete(TInt aError); - void ToneFinished(TInt aError); - void BufferToBeFilled(CMMFBuffer *aBuffer); - void PlayError(TInt aError); - void BufferToBeEmptied(CMMFBuffer *aBuffer); - void RecordError(TInt aError); - void ConvertError(TInt aError); - void DeviceMessage(TUid aMessageType, const TDesC8 &aMsg); - -private slots: - void dataReady(); - void underflowTimerExpired(); - -private: - void open(); - void startPlayback(); - void startDevSoundL(); - void writePaddingData(); - qint64 pushData(const char *data, qint64 len); - void pullData(); - void bufferFilled(); - void lastBufferFilled(); - Q_INVOKABLE void close(); - - qint64 getSamplesPlayed() const; - - void setError(QAudio::Error error); - void setState(SymbianAudio::State state); - - bool isDataReady() const; - QAudio::State initializingState() const; - -private: - const QByteArray m_device; - const QAudioFormat m_format; - - int m_clientBufferSize; - int m_notifyInterval; - QScopedPointer m_notifyTimer; - QTime m_elapsed; - QAudio::Error m_error; - - SymbianAudio::State m_internalState; - QAudio::State m_externalState; - - bool m_pullMode; - QIODevice *m_source; - - QScopedPointer m_devSound; - TUint32 m_nativeFourCC; - TMMFCapabilities m_nativeFormat; - - // Buffer provided by DevSound, to be filled with data. - CMMFDataBuffer *m_devSoundBuffer; - - int m_devSoundBufferSize; - - // Number of bytes transferred from QIODevice to QAudioOutput. It is - // necessary to count this because data is dropped when suspend() is - // called. The difference between the position reported by DevSound and - // this value allows us to calculate m_bytesPadding; - quint32 m_bytesWritten; - - // True if client has provided data while the audio subsystem was not - // ready to consume it. - bool m_pushDataReady; - - // Number of zero bytes which will be written when client calls resume(). - quint32 m_bytesPadding; - - // True if PlayError(KErrUnderflow) has been called. - bool m_underflow; - - // True if a buffer marked with the "last buffer" flag has been provided - // to DevSound. - bool m_lastBuffer; - - // Some DevSound implementations ignore all underflow errors raised by the - // audio driver, unless the last buffer flag has been set by the client. - // In push-mode playback, this flag will never be set, so the underflow - // error will never be reported. In order to work around this, a timer - // is used, which gets reset every time the client provides more data. If - // the timer expires, an underflow error is raised by this object. - QScopedPointer m_underflowTimer; - - // Result of previous call to CMMFDevSound::SamplesPlayed(). This value is - // used to determine whether, when m_underflowTimer expires, an - // underflow error has actually occurred. - quint32 m_samplesPlayed; - - // Samples played up to the last call to suspend(). It is necessary - // to cache this because suspend() is implemented using - // CMMFDevSound::Stop(), which resets DevSound's SamplesPlayed() counter. - quint32 m_totalSamplesPlayed; - -}; - -QT_END_NAMESPACE - -#endif diff --git a/src/multimedia/audio/qaudiooutput_win32_p.cpp b/src/multimedia/audio/qaudiooutput_win32_p.cpp deleted file mode 100644 index 13bce58..0000000 --- a/src/multimedia/audio/qaudiooutput_win32_p.cpp +++ /dev/null @@ -1,606 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtMultimedia module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -// -// W A R N I N G -// ------------- -// -// This file is not part of the Qt API. It exists for the convenience -// of other Qt classes. This header file may change from version to -// version without notice, or even be removed. -// -// We mean it. -// - -#include "qaudiooutput_win32_p.h" - -//#define DEBUG_AUDIO 1 - -QT_BEGIN_NAMESPACE - -static const int minimumIntervalTime = 50; - -QAudioOutputPrivate::QAudioOutputPrivate(const QByteArray &device, const QAudioFormat& audioFormat): - settings(audioFormat) -{ - bytesAvailable = 0; - buffer_size = 0; - period_size = 0; - m_device = device; - totalTimeValue = 0; - intervalTime = 1000; - audioBuffer = 0; - errorState = QAudio::NoError; - deviceState = QAudio::StoppedState; - audioSource = 0; - pullMode = true; - finished = false; - InitializeCriticalSection(&waveOutCriticalSection); -} - -QAudioOutputPrivate::~QAudioOutputPrivate() -{ - EnterCriticalSection(&waveOutCriticalSection); - finished = true; - LeaveCriticalSection(&waveOutCriticalSection); - - close(); - DeleteCriticalSection(&waveOutCriticalSection); -} - -void CALLBACK QAudioOutputPrivate::waveOutProc( HWAVEOUT hWaveOut, UINT uMsg, - DWORD dwInstance, DWORD dwParam1, DWORD dwParam2 ) -{ - Q_UNUSED(dwParam1) - Q_UNUSED(dwParam2) - Q_UNUSED(hWaveOut) - - QAudioOutputPrivate* qAudio; - qAudio = (QAudioOutputPrivate*)(dwInstance); - if(!qAudio) - return; - - switch(uMsg) { - case WOM_OPEN: - qAudio->feedback(); - break; - case WOM_CLOSE: - return; - case WOM_DONE: - EnterCriticalSection(&qAudio->waveOutCriticalSection); - if(qAudio->finished || qAudio->buffer_size == 0 || qAudio->period_size == 0) { - LeaveCriticalSection(&qAudio->waveOutCriticalSection); - return; - } - qAudio->waveFreeBlockCount++; - if(qAudio->waveFreeBlockCount >= qAudio->buffer_size/qAudio->period_size) - qAudio->waveFreeBlockCount = qAudio->buffer_size/qAudio->period_size; - qAudio->feedback(); - LeaveCriticalSection(&qAudio->waveOutCriticalSection); - break; - default: - return; - } -} - -WAVEHDR* QAudioOutputPrivate::allocateBlocks(int size, int count) -{ - int i; - unsigned char* buffer; - WAVEHDR* blocks; - DWORD totalBufferSize = (size + sizeof(WAVEHDR))*count; - - if((buffer=(unsigned char*)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY, - totalBufferSize)) == 0) { - qWarning("QAudioOutput: Memory allocation error"); - return 0; - } - blocks = (WAVEHDR*)buffer; - buffer += sizeof(WAVEHDR)*count; - for(i = 0; i < count; i++) { - blocks[i].dwBufferLength = size; - blocks[i].lpData = (LPSTR)buffer; - buffer += size; - } - return blocks; -} - -void QAudioOutputPrivate::freeBlocks(WAVEHDR* blockArray) -{ - WAVEHDR* blocks = blockArray; - - int count = buffer_size/period_size; - - for(int i = 0; i < count; i++) { - waveOutUnprepareHeader(hWaveOut,&blocks[i], sizeof(WAVEHDR)); - blocks+=sizeof(WAVEHDR); - } - HeapFree(GetProcessHeap(), 0, blockArray); -} - -QAudioFormat QAudioOutputPrivate::format() const -{ - return settings; -} - -QIODevice* QAudioOutputPrivate::start(QIODevice* device) -{ - if(deviceState != QAudio::StoppedState) - close(); - - if(!pullMode && audioSource) { - delete audioSource; - } - - if(device) { - //set to pull mode - pullMode = true; - audioSource = device; - deviceState = QAudio::ActiveState; - } else { - //set to push mode - pullMode = false; - audioSource = new OutputPrivate(this); - audioSource->open(QIODevice::WriteOnly|QIODevice::Unbuffered); - deviceState = QAudio::IdleState; - } - - if( !open() ) - return 0; - - emit stateChanged(deviceState); - - return audioSource; -} - -void QAudioOutputPrivate::stop() -{ - if(deviceState == QAudio::StoppedState) - return; - close(); - if(!pullMode && audioSource) { - delete audioSource; - audioSource = 0; - } - emit stateChanged(deviceState); -} - -bool QAudioOutputPrivate::open() -{ -#ifdef DEBUG_AUDIO - QTime now(QTime::currentTime()); - qDebug()<= 8000 && settings.frequency() <= 48000)) { - errorState = QAudio::OpenError; - deviceState = QAudio::StoppedState; - emit stateChanged(deviceState); - qWarning("QAudioOutput: open error, frequency out of range."); - return false; - } - if(buffer_size == 0) { - // Default buffer size, 200ms, default period size is 40ms - buffer_size = settings.frequency()*settings.channels()*(settings.sampleSize()/8)*0.2; - period_size = buffer_size/5; - } else { - period_size = buffer_size/5; - } - waveBlocks = allocateBlocks(period_size, buffer_size/period_size); - - EnterCriticalSection(&waveOutCriticalSection); - waveFreeBlockCount = buffer_size/period_size; - LeaveCriticalSection(&waveOutCriticalSection); - - waveCurrentBlock = 0; - - if(audioBuffer == 0) - audioBuffer = new char[buffer_size]; - - timeStamp.restart(); - elapsedTimeOffset = 0; - - wfx.nSamplesPerSec = settings.frequency(); - wfx.wBitsPerSample = settings.sampleSize(); - wfx.nChannels = settings.channels(); - wfx.cbSize = 0; - - wfx.wFormatTag = WAVE_FORMAT_PCM; - wfx.nBlockAlign = (wfx.wBitsPerSample >> 3) * wfx.nChannels; - wfx.nAvgBytesPerSec = wfx.nBlockAlign * wfx.nSamplesPerSec; - - UINT_PTR devId = WAVE_MAPPER; - - WAVEOUTCAPS woc; - unsigned long iNumDevs,ii; - iNumDevs = waveOutGetNumDevs(); - for(ii=0;ii= minimumIntervalTime) - intervalTime = ms; - else - intervalTime = minimumIntervalTime; -} - -int QAudioOutputPrivate::notifyInterval() const -{ - return intervalTime; -} - -qint64 QAudioOutputPrivate::processedUSecs() const -{ - if (deviceState == QAudio::StoppedState) - return 0; - qint64 result = qint64(1000000) * totalTimeValue / - (settings.channels()*(settings.sampleSize()/8)) / - settings.frequency(); - - return result; -} - -qint64 QAudioOutputPrivate::write( const char *data, qint64 len ) -{ - // Write out some audio data - if (deviceState != QAudio::ActiveState && deviceState != QAudio::IdleState) - return 0; - - char* p = (char*)data; - int l = (int)len; - - WAVEHDR* current; - int remain; - current = &waveBlocks[waveCurrentBlock]; - while(l > 0) { - EnterCriticalSection(&waveOutCriticalSection); - if(waveFreeBlockCount==0) { - LeaveCriticalSection(&waveOutCriticalSection); - break; - } - LeaveCriticalSection(&waveOutCriticalSection); - - if(current->dwFlags & WHDR_PREPARED) - waveOutUnprepareHeader(hWaveOut, current, sizeof(WAVEHDR)); - - if(l < period_size) - remain = l; - else - remain = period_size; - memcpy(current->lpData, p, remain); - - l -= remain; - p += remain; - current->dwBufferLength = remain; - waveOutPrepareHeader(hWaveOut, current, sizeof(WAVEHDR)); - waveOutWrite(hWaveOut, current, sizeof(WAVEHDR)); - - EnterCriticalSection(&waveOutCriticalSection); - waveFreeBlockCount--; - LeaveCriticalSection(&waveOutCriticalSection); -#ifdef DEBUG_AUDIO - EnterCriticalSection(&waveOutCriticalSection); - qDebug("write out l=%d, waveFreeBlockCount=%d", - current->dwBufferLength,waveFreeBlockCount); - LeaveCriticalSection(&waveOutCriticalSection); -#endif - totalTimeValue += current->dwBufferLength; - waveCurrentBlock++; - waveCurrentBlock %= buffer_size/period_size; - current = &waveBlocks[waveCurrentBlock]; - current->dwUser = 0; - errorState = QAudio::NoError; - if (deviceState != QAudio::ActiveState) { - deviceState = QAudio::ActiveState; - emit stateChanged(deviceState); - } - } - return (len-l); -} - -void QAudioOutputPrivate::resume() -{ - if(deviceState == QAudio::SuspendedState) { - deviceState = QAudio::ActiveState; - errorState = QAudio::NoError; - waveOutRestart(hWaveOut); - QTimer::singleShot(10, this, SLOT(feedback())); - emit stateChanged(deviceState); - } -} - -void QAudioOutputPrivate::suspend() -{ - if(deviceState == QAudio::ActiveState || deviceState == QAudio::IdleState) { - int delay = (buffer_size-bytesFree())*1000/(settings.frequency() - *settings.channels()*(settings.sampleSize()/8)); - waveOutPause(hWaveOut); - Sleep(delay+10); - deviceState = QAudio::SuspendedState; - errorState = QAudio::NoError; - emit stateChanged(deviceState); - } -} - -void QAudioOutputPrivate::feedback() -{ -#ifdef DEBUG_AUDIO - QTime now(QTime::currentTime()); - qDebug()<= period_size) - QMetaObject::invokeMethod(this, "deviceReady", Qt::QueuedConnection); - } -} - -bool QAudioOutputPrivate::deviceReady() -{ - if(deviceState == QAudio::StoppedState) - return false; - - if(pullMode) { - int chunks = bytesAvailable/period_size; -#ifdef DEBUG_AUDIO - qDebug()<<"deviceReady() avail="< intervalTime ) { - emit notify(); - elapsedTimeOffset = timeStamp.elapsed() + elapsedTimeOffset - intervalTime; - timeStamp.restart(); - } - return true; - } - - if(startup) - waveOutPause(hWaveOut); - int input = period_size*chunks; - int l = audioSource->read(audioBuffer,input); - if(l > 0) { - int out= write(audioBuffer,l); - if(out > 0) { - if (deviceState != QAudio::ActiveState) { - deviceState = QAudio::ActiveState; - emit stateChanged(deviceState); - } - } - if ( out < l) { - // Didnt write all data - audioSource->seek(audioSource->pos()-(l-out)); - } - if(startup) - waveOutRestart(hWaveOut); - } else if(l == 0) { - bytesAvailable = bytesFree(); - - int check = 0; - EnterCriticalSection(&waveOutCriticalSection); - check = waveFreeBlockCount; - LeaveCriticalSection(&waveOutCriticalSection); - if(check == buffer_size/period_size) { - errorState = QAudio::UnderrunError; - if (deviceState != QAudio::IdleState) { - deviceState = QAudio::IdleState; - emit stateChanged(deviceState); - } - } - - } else if(l < 0) { - bytesAvailable = bytesFree(); - errorState = QAudio::IOError; - } - } else { - int buffered; - EnterCriticalSection(&waveOutCriticalSection); - buffered = waveFreeBlockCount; - LeaveCriticalSection(&waveOutCriticalSection); - errorState = QAudio::UnderrunError; - if (buffered >= buffer_size/period_size && deviceState == QAudio::ActiveState) { - deviceState = QAudio::IdleState; - emit stateChanged(deviceState); - } - } - if(deviceState != QAudio::ActiveState && deviceState != QAudio::IdleState) - return true; - - if((timeStamp.elapsed() + elapsedTimeOffset) > intervalTime) { - emit notify(); - elapsedTimeOffset = timeStamp.elapsed() + elapsedTimeOffset - intervalTime; - timeStamp.restart(); - } - - return true; -} - -qint64 QAudioOutputPrivate::elapsedUSecs() const -{ - if (deviceState == QAudio::StoppedState) - return 0; - - return timeStampOpened.elapsed()*1000; -} - -QAudio::Error QAudioOutputPrivate::error() const -{ - return errorState; -} - -QAudio::State QAudioOutputPrivate::state() const -{ - return deviceState; -} - -void QAudioOutputPrivate::reset() -{ - close(); -} - -OutputPrivate::OutputPrivate(QAudioOutputPrivate* audio) -{ - audioDevice = qobject_cast(audio); -} - -OutputPrivate::~OutputPrivate() {} - -qint64 OutputPrivate::readData( char* data, qint64 len) -{ - Q_UNUSED(data) - Q_UNUSED(len) - - return 0; -} - -qint64 OutputPrivate::writeData(const char* data, qint64 len) -{ - int retry = 0; - qint64 written = 0; - - if((audioDevice->deviceState == QAudio::ActiveState) - ||(audioDevice->deviceState == QAudio::IdleState)) { - qint64 l = len; - while(written < l) { - int chunk = audioDevice->write(data+written,(l-written)); - if(chunk <= 0) - retry++; - else - written+=chunk; - - if(retry > 10) - return written; - } - audioDevice->deviceState = QAudio::ActiveState; - } - return written; -} - -QT_END_NAMESPACE diff --git a/src/multimedia/audio/qaudiooutput_win32_p.h b/src/multimedia/audio/qaudiooutput_win32_p.h deleted file mode 100644 index 68a40f7..0000000 --- a/src/multimedia/audio/qaudiooutput_win32_p.h +++ /dev/null @@ -1,156 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtMultimedia module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -// -// W A R N I N G -// ------------- -// -// This file is not part of the Qt API. It exists for the convenience -// of other Qt classes. This header file may change from version to -// version without notice, or even be removed. -// -// We mean it. -// - -#ifndef QAUDIOOUTPUTWIN_H -#define QAUDIOOUTPUTWIN_H - -#include -#include - -#include -#include -#include -#include -#include - -#include -#include -#include - - -QT_BEGIN_NAMESPACE - -class QAudioOutputPrivate : public QAbstractAudioOutput -{ - Q_OBJECT -public: - QAudioOutputPrivate(const QByteArray &device, const QAudioFormat& audioFormat); - ~QAudioOutputPrivate(); - - qint64 write( const char *data, qint64 len ); - - QAudioFormat format() const; - QIODevice* start(QIODevice* device = 0); - void stop(); - void reset(); - void suspend(); - void resume(); - int bytesFree() const; - int periodSize() const; - void setBufferSize(int value); - int bufferSize() const; - void setNotifyInterval(int milliSeconds); - int notifyInterval() const; - qint64 processedUSecs() const; - qint64 elapsedUSecs() const; - QAudio::Error error() const; - QAudio::State state() const; - - QIODevice* audioSource; - QAudioFormat settings; - QAudio::Error errorState; - QAudio::State deviceState; - -private slots: - void feedback(); - bool deviceReady(); - -private: - QByteArray m_device; - bool resuming; - int bytesAvailable; - QTime timeStamp; - qint64 elapsedTimeOffset; - QTime timeStampOpened; - qint32 buffer_size; - qint32 period_size; - qint64 totalTimeValue; - bool pullMode; - int intervalTime; - static void QT_WIN_CALLBACK waveOutProc( HWAVEOUT hWaveOut, UINT uMsg, - DWORD dwInstance, DWORD dwParam1, DWORD dwParam2 ); - - CRITICAL_SECTION waveOutCriticalSection; - - WAVEHDR* allocateBlocks(int size, int count); - void freeBlocks(WAVEHDR* blockArray); - bool open(); - void close(); - - WAVEFORMATEX wfx; - HWAVEOUT hWaveOut; - MMRESULT result; - WAVEHDR header; - WAVEHDR* waveBlocks; - volatile bool finished; - volatile int waveFreeBlockCount; - int waveCurrentBlock; - char* audioBuffer; -}; - -class OutputPrivate : public QIODevice -{ - Q_OBJECT -public: - OutputPrivate(QAudioOutputPrivate* audio); - ~OutputPrivate(); - - qint64 readData( char* data, qint64 len); - qint64 writeData(const char* data, qint64 len); - -private: - QAudioOutputPrivate *audioDevice; -}; - -QT_END_NAMESPACE - -#endif diff --git a/src/multimedia/base/base.pri b/src/multimedia/base/base.pri deleted file mode 100644 index 49eca49..0000000 --- a/src/multimedia/base/base.pri +++ /dev/null @@ -1,69 +0,0 @@ - -QT += network -contains(QT_CONFIG, opengl):QT += opengl - -HEADERS += \ - $$PWD/qmediaresource.h \ - $$PWD/qmediacontent.h \ - $$PWD/qmediaobject.h \ - $$PWD/qmediaobject_p.h \ - $$PWD/qmediapluginloader_p.h \ - $$PWD/qmediaservice.h \ - $$PWD/qmediaservice_p.h \ - $$PWD/qmediaserviceprovider.h \ - $$PWD/qmediaserviceproviderplugin.h \ - $$PWD/qmediacontrol.h \ - $$PWD/qmediacontrol_p.h \ - $$PWD/qmetadatacontrol.h \ - $$PWD/qvideooutputcontrol.h \ - $$PWD/qvideowindowcontrol.h \ - $$PWD/qvideorenderercontrol.h \ - $$PWD/qvideodevicecontrol.h \ - $$PWD/qvideowidgetcontrol.h \ - $$PWD/qvideowidget.h \ - $$PWD/qvideowidget_p.h \ - $$PWD/qgraphicsvideoitem.h \ - $$PWD/qmediaplaylistcontrol.h \ - $$PWD/qmediaplaylist.h \ - $$PWD/qmediaplaylist_p.h \ - $$PWD/qmediaplaylistprovider.h \ - $$PWD/qmediaplaylistprovider_p.h \ - $$PWD/qmediaplaylistioplugin.h \ - $$PWD/qlocalmediaplaylistprovider.h \ - $$PWD/qmediaplaylistnavigator.h \ - $$PWD/qpaintervideosurface_p.h \ - $$PWD/qmediatimerange.h \ - $$PWD/qtmedianamespace.h - -SOURCES += \ - $$PWD/qmediaresource.cpp \ - $$PWD/qmediacontent.cpp \ - $$PWD/qmediaobject.cpp \ - $$PWD/qmediapluginloader.cpp \ - $$PWD/qmediaservice.cpp \ - $$PWD/qmediaserviceprovider.cpp \ - $$PWD/qmediacontrol.cpp \ - $$PWD/qmetadatacontrol.cpp \ - $$PWD/qvideooutputcontrol.cpp \ - $$PWD/qvideowindowcontrol.cpp \ - $$PWD/qvideorenderercontrol.cpp \ - $$PWD/qvideodevicecontrol.cpp \ - $$PWD/qvideowidgetcontrol.cpp \ - $$PWD/qvideowidget.cpp \ - $$PWD/qgraphicsvideoitem.cpp \ - $$PWD/qmediaplaylistcontrol.cpp \ - $$PWD/qmediaplaylist.cpp \ - $$PWD/qmediaplaylistprovider.cpp \ - $$PWD/qmediaplaylistioplugin.cpp \ - $$PWD/qlocalmediaplaylistprovider.cpp \ - $$PWD/qmediaplaylistnavigator.cpp \ - $$PWD/qpaintervideosurface.cpp \ - $$PWD/qmediatimerange.cpp - -mac { - HEADERS += $$PWD/qpaintervideosurface_mac_p.h - OBJECTIVE_SOURCES += $$PWD/qpaintervideosurface_mac.mm - - LIBS += -framework AppKit -framework QuartzCore -framework QTKit - -} diff --git a/src/multimedia/base/qgraphicsvideoitem.cpp b/src/multimedia/base/qgraphicsvideoitem.cpp deleted file mode 100644 index f903eb7..0000000 --- a/src/multimedia/base/qgraphicsvideoitem.cpp +++ /dev/null @@ -1,437 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtMultimedia module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include - -#include -#include -#include -#include -#include -#include - -#if !defined(QT_NO_OPENGL) && !defined(QT_OPENGL_ES_1_CL) && !defined(QT_OPENGL_ES_1) -#include -#endif - -QT_BEGIN_NAMESPACE - - -class QGraphicsVideoItemPrivate -{ -public: - QGraphicsVideoItemPrivate() - : q_ptr(0) - , surface(0) - , mediaObject(0) - , service(0) - , outputControl(0) - , rendererControl(0) - , aspectRatioMode(Qt::KeepAspectRatio) - , updatePaintDevice(true) - , rect(0.0, 0.0, 320, 240) - { - } - - QGraphicsVideoItem *q_ptr; - - QPainterVideoSurface *surface; - QMediaObject *mediaObject; - QMediaService *service; - QVideoOutputControl *outputControl; - QVideoRendererControl *rendererControl; - Qt::AspectRatioMode aspectRatioMode; - bool updatePaintDevice; - QRectF rect; - QRectF boundingRect; - QRectF sourceRect; - QSizeF nativeSize; - - void clearService(); - void updateRects(); - - void _q_present(); - void _q_formatChanged(const QVideoSurfaceFormat &format); - void _q_serviceDestroyed(); - void _q_mediaObjectDestroyed(); -}; - -void QGraphicsVideoItemPrivate::clearService() -{ - if (outputControl) { - outputControl->setOutput(QVideoOutputControl::NoOutput); - outputControl = 0; - } - if (rendererControl) { - surface->stop(); - rendererControl->setSurface(0); - rendererControl = 0; - } - if (service) { - QObject::disconnect(service, SIGNAL(destroyed()), q_ptr, SLOT(_q_serviceDestroyed())); - service = 0; - } -} - -void QGraphicsVideoItemPrivate::updateRects() -{ - q_ptr->prepareGeometryChange(); - - if (nativeSize.isEmpty()) { - boundingRect = QRectF(); - } else if (aspectRatioMode == Qt::IgnoreAspectRatio) { - boundingRect = rect; - sourceRect = QRectF(0, 0, 1, 1); - } else if (aspectRatioMode == Qt::KeepAspectRatio) { - QSizeF size = nativeSize; - size.scale(rect.size(), Qt::KeepAspectRatio); - - boundingRect = QRectF(0, 0, size.width(), size.height()); - boundingRect.moveCenter(rect.center()); - - sourceRect = QRectF(0, 0, 1, 1); - } else if (aspectRatioMode == Qt::KeepAspectRatioByExpanding) { - boundingRect = rect; - - QSizeF size = rect.size(); - size.scale(nativeSize, Qt::KeepAspectRatio); - - sourceRect = QRectF( - 0, 0, size.width() / nativeSize.width(), size.height() / nativeSize.height()); - sourceRect.moveCenter(QPointF(0.5, 0.5)); - } -} - -void QGraphicsVideoItemPrivate::_q_present() -{ - if (q_ptr->isObscured()) { - q_ptr->update(boundingRect); - surface->setReady(true); - } else { - q_ptr->update(boundingRect); - } -} - -void QGraphicsVideoItemPrivate::_q_formatChanged(const QVideoSurfaceFormat &format) -{ - nativeSize = format.sizeHint(); - - updateRects(); - - emit q_ptr->nativeSizeChanged(nativeSize); -} - -void QGraphicsVideoItemPrivate::_q_serviceDestroyed() -{ - rendererControl = 0; - outputControl = 0; - service = 0; - - surface->stop(); -} - -void QGraphicsVideoItemPrivate::_q_mediaObjectDestroyed() -{ - mediaObject = 0; - - clearService(); -} - -/*! - \class QGraphicsVideoItem - \brief The QGraphicsVideoItem class provides a graphics item which display video produced by a QMediaObject. - - \since 4.7 - - \ingroup multimedia - - Attaching a QGraphicsVideoItem to a QMediaObject allows it to display - the video or image output of that media object. A QGraphicsVideoItem - is attached to a media object by passing a pointer to the QMediaObject - to the setMediaObject() function. - - \code - player = new QMediaPlayer(this); - - QGraphicsVideoItem *item = new QGraphicsVideoItem; - item->setMediaObject(player); - graphicsView->scence()->addItem(item); - graphicsView->show(); - - player->setMedia(video); - player->play(); - \endcode - - \bold {Note}: Only a single display output can be attached to a media - object at one time. - - \sa QMediaObject, QMediaPlayer, QVideoWidget -*/ - -/*! - Constructs a graphics item that displays video. - - The \a parent is passed to QGraphicsItem. -*/ -QGraphicsVideoItem::QGraphicsVideoItem(QGraphicsItem *parent) - : QGraphicsObject(parent) - , d_ptr(new QGraphicsVideoItemPrivate) -{ - d_ptr->q_ptr = this; - d_ptr->surface = new QPainterVideoSurface; - - connect(d_ptr->surface, SIGNAL(frameChanged()), this, SLOT(_q_present())); - connect(d_ptr->surface, SIGNAL(surfaceFormatChanged(QVideoSurfaceFormat)), - this, SLOT(_q_formatChanged(QVideoSurfaceFormat))); -} - -/*! - Destroys a video graphics item. -*/ -QGraphicsVideoItem::~QGraphicsVideoItem() -{ - if (d_ptr->outputControl) - d_ptr->outputControl->setOutput(QVideoOutputControl::NoOutput); - - if (d_ptr->rendererControl) - d_ptr->rendererControl->setSurface(0); - - delete d_ptr->surface; - delete d_ptr; -} - -/*! - \property QGraphicsVideoItem::mediaObject - \brief the media object which provides the video displayed by a graphics - item. -*/ - -QMediaObject *QGraphicsVideoItem::mediaObject() const -{ - return d_func()->mediaObject; -} - -void QGraphicsVideoItem::setMediaObject(QMediaObject *object) -{ - Q_D(QGraphicsVideoItem); - - if (object == d->mediaObject) - return; - - d->clearService(); - - if (d->mediaObject) { - disconnect(d->mediaObject, SIGNAL(destroyed()), this, SLOT(_q_mediaObjectDestroyed())); - d->mediaObject->unbind(this); - } - - d->mediaObject = object; - - if (d->mediaObject) { - d->mediaObject->bind(this); - - connect(d->mediaObject, SIGNAL(destroyed()), this, SLOT(_q_mediaObjectDestroyed())); - - d->service = d->mediaObject->service(); - - if (d->service) { - connect(d->service, SIGNAL(destroyed()), this, SLOT(_q_serviceDestroyed())); - - d->outputControl = qobject_cast( - d->service->control(QVideoOutputControl_iid)); - d->rendererControl = qobject_cast( - d->service->control(QVideoRendererControl_iid)); - - if (d->outputControl != 0 && d->rendererControl != 0) { - d->rendererControl->setSurface(d->surface); - - if (isVisible()) - d->outputControl->setOutput(QVideoOutputControl::RendererOutput); - } - } - } -} - -/*! - \property QGraphicsVideoItem::aspectRatioMode - \brief how a video is scaled to fit the graphics item's size. -*/ - -Qt::AspectRatioMode QGraphicsVideoItem::aspectRatioMode() const -{ - return d_func()->aspectRatioMode; -} - -void QGraphicsVideoItem::setAspectRatioMode(Qt::AspectRatioMode mode) -{ - Q_D(QGraphicsVideoItem); - - d->aspectRatioMode = mode; - d->updateRects(); -} - -/*! - \property QGraphicsVideoItem::offset - \brief the video item's offset. - - QGraphicsVideoItem will draw video using the offset for its top left - corner. -*/ - -QPointF QGraphicsVideoItem::offset() const -{ - return d_func()->rect.topLeft(); -} - -void QGraphicsVideoItem::setOffset(const QPointF &offset) -{ - Q_D(QGraphicsVideoItem); - - d->rect.moveTo(offset); - d->updateRects(); -} - -/*! - \property QGraphicsVideoItem::size - \brief the video item's size. - - QGraphicsVideoItem will draw video scaled to fit size according to its - fillMode. -*/ - -QSizeF QGraphicsVideoItem::size() const -{ - return d_func()->rect.size(); -} - -void QGraphicsVideoItem::setSize(const QSizeF &size) -{ - Q_D(QGraphicsVideoItem); - - d->rect.setSize(size.isValid() ? size : QSizeF(0, 0)); - d->updateRects(); -} - -/*! - \property QGraphicsVideoItem::nativeSize - \brief the native size of the video. -*/ - -QSizeF QGraphicsVideoItem::nativeSize() const -{ - return d_func()->nativeSize; -} - -/*! - \fn QGraphicsVideoItem::nativeSizeChanged(const QSizeF &size) - - Signals that the native \a size of the video has changed. -*/ - -/*! - \reimp -*/ -QRectF QGraphicsVideoItem::boundingRect() const -{ - return d_func()->boundingRect; -} - -/*! - \reimp -*/ -void QGraphicsVideoItem::paint( - QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) -{ - Q_D(QGraphicsVideoItem); - - Q_UNUSED(option); - Q_UNUSED(widget); - - if (d->surface && d->surface->isActive()) { - d->surface->paint(painter, d->boundingRect, d->sourceRect); - d->surface->setReady(true); -#if !defined(QT_NO_OPENGL) && !defined(QT_OPENGL_ES_1_CL) && !defined(QT_OPENGL_ES_1) - } else if (d->updatePaintDevice && (painter->paintEngine()->type() == QPaintEngine::OpenGL - || painter->paintEngine()->type() == QPaintEngine::OpenGL2)) { - d->updatePaintDevice = false; - - d->surface->setGLContext(const_cast(QGLContext::currentContext())); - if (d->surface->supportedShaderTypes() & QPainterVideoSurface::GlslShader) { - d->surface->setShaderType(QPainterVideoSurface::GlslShader); - } else { - d->surface->setShaderType(QPainterVideoSurface::FragmentProgramShader); - } -#endif - } -} - -/*! - \reimp - - \internal -*/ -QVariant QGraphicsVideoItem::itemChange(GraphicsItemChange change, const QVariant &value) -{ - return QGraphicsObject::itemChange(change, value); -} - -/*! - \reimp - - \internal -*/ -bool QGraphicsVideoItem::event(QEvent *event) -{ - return QGraphicsObject::event(event); -} - -/*! - \reimp - - \internal -*/ -bool QGraphicsVideoItem::sceneEvent(QEvent *event) -{ - return QGraphicsObject::sceneEvent(event); -} - -QT_END_NAMESPACE -#include "moc_qgraphicsvideoitem.cpp" diff --git a/src/multimedia/base/qgraphicsvideoitem.h b/src/multimedia/base/qgraphicsvideoitem.h deleted file mode 100644 index e6f0d81..0000000 --- a/src/multimedia/base/qgraphicsvideoitem.h +++ /dev/null @@ -1,112 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtMultimedia module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QGRAPHICSVIDEOITEM_H -#define QGRAPHICSVIDEOITEM_H - -#include - -#include - - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Multimedia) - -class QVideoSurfaceFormat; - -class QGraphicsVideoItemPrivate; -class Q_MULTIMEDIA_EXPORT QGraphicsVideoItem : public QGraphicsObject -{ - Q_OBJECT - Q_PROPERTY(QMediaObject* mediaObject READ mediaObject WRITE setMediaObject) - Q_PROPERTY(Qt::AspectRatioMode aspectRatioMode READ aspectRatioMode WRITE setAspectRatioMode) - Q_PROPERTY(QPointF offset READ offset WRITE setOffset) - Q_PROPERTY(QSizeF size READ size WRITE setSize) - Q_PROPERTY(QSizeF nativeSize READ nativeSize NOTIFY nativeSizeChanged) -public: - QGraphicsVideoItem(QGraphicsItem *parent = 0); - ~QGraphicsVideoItem(); - - QMediaObject *mediaObject() const; - void setMediaObject(QMediaObject *object); - - Qt::AspectRatioMode aspectRatioMode() const; - void setAspectRatioMode(Qt::AspectRatioMode mode); - - QPointF offset() const; - void setOffset(const QPointF &offset); - - QSizeF size() const; - void setSize(const QSizeF &size); - - QSizeF nativeSize() const; - - QRectF boundingRect() const; - - void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0); - -Q_SIGNALS: - void nativeSizeChanged(const QSizeF &size); - -protected: - bool event(QEvent *event); - bool sceneEvent(QEvent *event); - - QVariant itemChange(GraphicsItemChange change, const QVariant &value); - - QGraphicsVideoItemPrivate *d_ptr; - -private: - Q_DECLARE_PRIVATE(QGraphicsVideoItem) - Q_PRIVATE_SLOT(d_func(), void _q_present()) - Q_PRIVATE_SLOT(d_func(), void _q_formatChanged(const QVideoSurfaceFormat &)) - Q_PRIVATE_SLOT(d_func(), void _q_serviceDestroyed()) - Q_PRIVATE_SLOT(d_func(), void _q_mediaObjectDestroyed()) -}; - -QT_END_NAMESPACE - -QT_END_HEADER - -#endif diff --git a/src/multimedia/base/qlocalmediaplaylistprovider.cpp b/src/multimedia/base/qlocalmediaplaylistprovider.cpp deleted file mode 100644 index 40ff1fc..0000000 --- a/src/multimedia/base/qlocalmediaplaylistprovider.cpp +++ /dev/null @@ -1,196 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtMultimedia module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include -#include "qmediaplaylistprovider_p.h" -#include - - -QT_BEGIN_NAMESPACE - -class QLocalMediaPlaylistProviderPrivate: public QMediaPlaylistProviderPrivate -{ -public: - QList resources; -}; - -QLocalMediaPlaylistProvider::QLocalMediaPlaylistProvider(QObject *parent) - :QMediaPlaylistProvider(*new QLocalMediaPlaylistProviderPrivate, parent) -{ -} - -QLocalMediaPlaylistProvider::~QLocalMediaPlaylistProvider() -{ -} - -bool QLocalMediaPlaylistProvider::isReadOnly() const -{ - return false; -} - -int QLocalMediaPlaylistProvider::mediaCount() const -{ - return d_func()->resources.size(); -} - -QMediaContent QLocalMediaPlaylistProvider::media(int pos) const -{ - return d_func()->resources.value(pos); -} - -bool QLocalMediaPlaylistProvider::addMedia(const QMediaContent &content) -{ - Q_D(QLocalMediaPlaylistProvider); - - int pos = d->resources.count(); - - emit mediaAboutToBeInserted(pos, pos); - d->resources.append(content); - emit mediaInserted(pos, pos); - - return true; -} - -bool QLocalMediaPlaylistProvider::addMedia(const QList &items) -{ - Q_D(QLocalMediaPlaylistProvider); - - if (items.isEmpty()) - return true; - - int pos = d->resources.count(); - int end = pos+items.count()-1; - - emit mediaAboutToBeInserted(pos, end); - d->resources.append(items); - emit mediaInserted(pos, end); - - return true; -} - - -bool QLocalMediaPlaylistProvider::insertMedia(int pos, const QMediaContent &content) -{ - Q_D(QLocalMediaPlaylistProvider); - - emit mediaAboutToBeInserted(pos, pos); - d->resources.insert(pos, content); - emit mediaInserted(pos,pos); - - return true; -} - -bool QLocalMediaPlaylistProvider::insertMedia(int pos, const QList &items) -{ - Q_D(QLocalMediaPlaylistProvider); - - if (items.isEmpty()) - return true; - - const int last = pos+items.count()-1; - - emit mediaAboutToBeInserted(pos, last); - for (int i=0; iresources.insert(pos+i, items.at(i)); - emit mediaInserted(pos, last); - - return true; -} - -bool QLocalMediaPlaylistProvider::removeMedia(int fromPos, int toPos) -{ - Q_D(QLocalMediaPlaylistProvider); - - Q_ASSERT(fromPos >= 0); - Q_ASSERT(fromPos <= toPos); - Q_ASSERT(toPos < mediaCount()); - - emit mediaAboutToBeRemoved(fromPos, toPos); - d->resources.erase(d->resources.begin()+fromPos, d->resources.begin()+toPos+1); - emit mediaRemoved(fromPos, toPos); - - return true; -} - -bool QLocalMediaPlaylistProvider::removeMedia(int pos) -{ - Q_D(QLocalMediaPlaylistProvider); - - emit mediaAboutToBeRemoved(pos, pos); - d->resources.removeAt(pos); - emit mediaRemoved(pos, pos); - - return true; -} - -bool QLocalMediaPlaylistProvider::clear() -{ - Q_D(QLocalMediaPlaylistProvider); - if (!d->resources.isEmpty()) { - int lastPos = mediaCount()-1; - emit mediaAboutToBeRemoved(0, lastPos); - d->resources.clear(); - emit mediaRemoved(0, lastPos); - } - - return true; -} - -void QLocalMediaPlaylistProvider::shuffle() -{ - Q_D(QLocalMediaPlaylistProvider); - if (!d->resources.isEmpty()) { - QList resources; - - while (!d->resources.isEmpty()) { - resources.append(d->resources.takeAt(qrand() % d->resources.size())); - } - - d->resources = resources; - emit mediaChanged(0, mediaCount()-1); - } - -} - -#include "moc_qlocalmediaplaylistprovider.cpp" - -QT_END_NAMESPACE - diff --git a/src/multimedia/base/qlocalmediaplaylistprovider.h b/src/multimedia/base/qlocalmediaplaylistprovider.h deleted file mode 100644 index db8deb1..0000000 --- a/src/multimedia/base/qlocalmediaplaylistprovider.h +++ /dev/null @@ -1,87 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtMultimedia module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QLOCALMEDIAPAYLISTPROVIDER_H -#define QLOCALMEDIAPAYLISTPROVIDER_H - -#include - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Multimedia) - - -class QLocalMediaPlaylistProviderPrivate; -class Q_MULTIMEDIA_EXPORT QLocalMediaPlaylistProvider : public QMediaPlaylistProvider -{ - Q_OBJECT - -public: - QLocalMediaPlaylistProvider(QObject *parent=0); - virtual ~QLocalMediaPlaylistProvider(); - - virtual int mediaCount() const; - virtual QMediaContent media(int pos) const; - - virtual bool isReadOnly() const; - - virtual bool addMedia(const QMediaContent &content); - virtual bool addMedia(const QList &items); - virtual bool insertMedia(int pos, const QMediaContent &content); - virtual bool insertMedia(int pos, const QList &items); - virtual bool removeMedia(int pos); - virtual bool removeMedia(int start, int end); - virtual bool clear(); - -public Q_SLOTS: - virtual void shuffle(); - -private: - Q_DECLARE_PRIVATE(QLocalMediaPlaylistProvider) -}; - -QT_END_NAMESPACE - -QT_END_HEADER - -#endif // QLOCALMEDIAPAYLISTSOURCE_H diff --git a/src/multimedia/base/qmediacontent.cpp b/src/multimedia/base/qmediacontent.cpp deleted file mode 100644 index b6bf56b..0000000 --- a/src/multimedia/base/qmediacontent.cpp +++ /dev/null @@ -1,242 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtMultimedia module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include -#include - -#include - - -QT_BEGIN_NAMESPACE - - -class QMediaContentPrivate : public QSharedData -{ -public: - QMediaContentPrivate() {} - QMediaContentPrivate(const QMediaResourceList &r): - resources(r) {} - - QMediaContentPrivate(const QMediaContentPrivate &other): - QSharedData(other), - resources(other.resources) - {} - - bool operator==(const QMediaContentPrivate &other) const - { - return resources == other.resources; - } - - QMediaResourceList resources; - -private: - QMediaContentPrivate& operator=(const QMediaContentPrivate &other); -}; - - -/*! - \class QMediaContent - \preliminary - \brief The QMediaContent class provides access to the resources relating to a media content. - \since 4.7 - - \ingroup multimedia - - QMediaContent is used within the multimedia framework as the logical handle - to media content. A QMediaContent object is composed of one or more - \l {QMediaResource}s where each resource provides the URL and format - information of a different encoding of the content. - - A non-null QMediaContent will always have a primary or canonical reference to - the content available through the canonicalUrl() or canonicalResource() - methods, any additional resources are optional. -*/ - - -/*! - Constructs a null QMediaContent. -*/ - -QMediaContent::QMediaContent() -{ -} - -/*! - Constructs a media content with \a url providing a reference to the content. -*/ - -QMediaContent::QMediaContent(const QUrl &url): - d(new QMediaContentPrivate) -{ - d->resources << QMediaResource(url); -} - -/*! - Constructs a media content with \a request providing a reference to the content. - - This constructor can be used to reference media content via network protocols such as HTTP. - This may include additional information required to obtain the resource, such as Cookies or HTTP headers. -*/ - -QMediaContent::QMediaContent(const QNetworkRequest &request): - d(new QMediaContentPrivate) -{ - d->resources << QMediaResource(request); -} - -/*! - Constructs a media content with \a resource providing a reference to the content. -*/ - -QMediaContent::QMediaContent(const QMediaResource &resource): - d(new QMediaContentPrivate) -{ - d->resources << resource; -} - -/*! - Constructs a media content with \a resources providing a reference to the content. -*/ - -QMediaContent::QMediaContent(const QMediaResourceList &resources): - d(new QMediaContentPrivate(resources)) -{ -} - -/*! - Constructs a copy of the media content \a other. -*/ - -QMediaContent::QMediaContent(const QMediaContent &other): - d(other.d) -{ -} - -/*! - Destroys the media content object. -*/ - -QMediaContent::~QMediaContent() -{ -} - -/*! - Assigns the value of \a other to this media content. -*/ - -QMediaContent& QMediaContent::operator=(const QMediaContent &other) -{ - d = other.d; - return *this; -} - -/*! - Returns true if \a other is equivalent to this media content; false otherwise. -*/ - -bool QMediaContent::operator==(const QMediaContent &other) const -{ - return (d.constData() == 0 && other.d.constData() == 0) || - (d.constData() != 0 && other.d.constData() != 0 && - *d.constData() == *other.d.constData()); -} - -/*! - Returns true if \a other is not equivalent to this media content; false otherwise. -*/ - -bool QMediaContent::operator!=(const QMediaContent &other) const -{ - return !(*this == other); -} - -/*! - Returns true if this media content is null (uninitialized); false otherwise. -*/ - -bool QMediaContent::isNull() const -{ - return d.constData() == 0; -} - -/*! - Returns a QUrl that represents that canonical resource for this media content. -*/ - -QUrl QMediaContent::canonicalUrl() const -{ - return canonicalResource().url(); -} - -/*! - Returns a QNetworkRequest that represents that canonical resource for this media content. -*/ - -QNetworkRequest QMediaContent::canonicalRequest() const -{ - return canonicalResource().request(); -} - -/*! - Returns a QMediaResource that represents that canonical resource for this media content. -*/ - -QMediaResource QMediaContent::canonicalResource() const -{ - return d.constData() != 0 - ? d->resources.value(0) - : QMediaResource(); -} - -/*! - Returns a list of alternative resources for this media content. The first item in this list - is always the canonical resource. -*/ - -QMediaResourceList QMediaContent::resources() const -{ - return d.constData() != 0 - ? d->resources - : QMediaResourceList(); -} - -QT_END_NAMESPACE - diff --git a/src/multimedia/base/qmediacontent.h b/src/multimedia/base/qmediacontent.h deleted file mode 100644 index 5a279c1..0000000 --- a/src/multimedia/base/qmediacontent.h +++ /dev/null @@ -1,93 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtMultimedia module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QMEDIACONTENT_H -#define QMEDIACONTENT_H - -#include -#include - -#include -#include - - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Multimedia) - -class QMediaContentPrivate; -class Q_MULTIMEDIA_EXPORT QMediaContent -{ -public: - QMediaContent(); - QMediaContent(const QUrl &contentUrl); - QMediaContent(const QNetworkRequest &contentRequest); - QMediaContent(const QMediaResource &contentResource); - QMediaContent(const QMediaResourceList &resources); - QMediaContent(const QMediaContent &other); - ~QMediaContent(); - - QMediaContent& operator=(const QMediaContent &other); - - bool operator==(const QMediaContent &other) const; - bool operator!=(const QMediaContent &other) const; - - bool isNull() const; - - QUrl canonicalUrl() const; - QNetworkRequest canonicalRequest() const; - QMediaResource canonicalResource() const; - - QMediaResourceList resources() const; - -private: - QSharedDataPointer d; -}; - -QT_END_NAMESPACE - -Q_DECLARE_METATYPE(QMediaContent) - -QT_END_HEADER - -#endif // QMEDIACONTENT_H diff --git a/src/multimedia/base/qmediacontrol.cpp b/src/multimedia/base/qmediacontrol.cpp deleted file mode 100644 index b84c49e..0000000 --- a/src/multimedia/base/qmediacontrol.cpp +++ /dev/null @@ -1,140 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtMultimedia module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include -#include - -#include -#include "qmediacontrol_p.h" - - - -QT_BEGIN_NAMESPACE - -/*! - \class QMediaControl - \ingroup multimedia-serv - \since 4.7 - - \preliminary - \brief The QMediaControl class provides a base interface for media service controls. - - Media controls provide an interface to individual features provided by a media service. Most - services implement a principal control which exposes the core functionality of the service and - a number optional controls which expose any additional functionality. - - A pointer to a control implemented by a media service can be obtained using the - \l {QMediaService::control()}{control()} member of QMediaService. If the service doesn't - implement a control it will instead return a null pointer. - - \code - QMediaPlayerControl *control = qobject_cast( - service->control("com.nokia.Qt.QMediaPlayerControl/1.0")); - \endcode - - Alternatively if the IId of the control has been declared using Q_MEDIA_DECLARE_CONTROL - the template version of QMediaService::control() can be used to request the service without - explicitly passing the IId. - - \code - QMediaPlayerControl *control = service->control(); - \endcode - - Most application code will not interface directly with a media service's controls, instead the - QMediaObject which owns the service acts as an intermeditary between one or more controls and - the application. - - \sa QMediaService, QMediaObject -*/ - -/*! - \macro Q_MEDIA_DECLARE_CONTROL(Class, IId) - \relates QMediaControl - - The Q_MEDIA_DECLARE_CONTROL macro declares an \a IId for a \a Class that inherits from - QMediaControl. - - Declaring an IId for a QMediaControl allows an instance of that control to be requested from - QMediaService::control() without explicitly passing the IId. - - \code - QMediaPlayerControl *control = service->control(); - \endcode - - \sa QMediaService::control() -*/ - -/*! - Destroys a media control. -*/ - -QMediaControl::~QMediaControl() -{ - delete d_ptr; -} - -/*! - Constructs a media control with the given \a parent. -*/ - -QMediaControl::QMediaControl(QObject *parent) - : QObject(parent) - , d_ptr(new QMediaControlPrivate) -{ - d_ptr->q_ptr = this; -} - -/*! - \internal -*/ - -QMediaControl::QMediaControl(QMediaControlPrivate &dd, QObject *parent) - : QObject(parent) - , d_ptr(&dd) - -{ - d_ptr->q_ptr = this; -} - -#include "moc_qmediacontrol.cpp" - -QT_END_NAMESPACE - diff --git a/src/multimedia/base/qmediacontrol.h b/src/multimedia/base/qmediacontrol.h deleted file mode 100644 index 8ed9fe8..0000000 --- a/src/multimedia/base/qmediacontrol.h +++ /dev/null @@ -1,82 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtMultimedia module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QABSTRACTMEDIACONTROL_H -#define QABSTRACTMEDIACONTROL_H - -#include -#include -#include - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Multimedia) - -class QMediaControlPrivate; -class Q_MULTIMEDIA_EXPORT QMediaControl : public QObject -{ - Q_OBJECT - -public: - ~QMediaControl(); - -protected: - QMediaControl(QObject *parent = 0); - QMediaControl(QMediaControlPrivate &dd, QObject *parent = 0); - - QMediaControlPrivate *d_ptr; - -private: - Q_DECLARE_PRIVATE(QMediaControl) -}; - -template const char *qmediacontrol_iid() { return 0; } - -#define Q_MEDIA_DECLARE_CONTROL(Class, IId) \ - template <> inline const char *qmediacontrol_iid() { return IId; } - -QT_END_NAMESPACE - -QT_END_HEADER - -#endif // QABSTRACTMEDIACONTROL_H diff --git a/src/multimedia/base/qmediacontrol_p.h b/src/multimedia/base/qmediacontrol_p.h deleted file mode 100644 index 4d00f11..0000000 --- a/src/multimedia/base/qmediacontrol_p.h +++ /dev/null @@ -1,74 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtMultimedia module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QABSTRACTMEDIACONTROL_P_H -#define QABSTRACTMEDIACONTROL_P_H - -// -// W A R N I N G -// ------------- -// -// This file is not part of the Qt API. It exists purely as an -// implementation detail. This header file may change from version to -// version without notice, or even be removed. -// -// We mean it. -// - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -class QMediaControl; - -class QMediaControlPrivate -{ -public: - virtual ~QMediaControlPrivate() {} - - QMediaControl *q_ptr; -}; - -QT_END_NAMESPACE - -QT_END_HEADER - -#endif diff --git a/src/multimedia/base/qmediaobject.cpp b/src/multimedia/base/qmediaobject.cpp deleted file mode 100644 index 0422718..0000000 --- a/src/multimedia/base/qmediaobject.cpp +++ /dev/null @@ -1,419 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtMultimedia module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include - -#include "qmediaobject_p.h" - -#include -#include - - -QT_BEGIN_NAMESPACE - -void QMediaObjectPrivate::_q_notify() -{ - Q_Q(QMediaObject); - - const QMetaObject* m = q->metaObject(); - - foreach (int pi, notifyProperties) { - QMetaProperty p = m->property(pi); - p.notifySignal().invoke( - q, QGenericArgument(QMetaType::typeName(p.userType()), p.read(q).data())); - } -} - - -/*! - \class QMediaObject - \preliminary - \brief The QMediaObject class provides a common base for multimedia objects. - \since 4.7 - - \ingroup multimedia - - QMediaObject derived classes provide access to the functionality of a - QMediaService. Each media object hosts a QMediaService and uses the - QMediaControl interfaces implemented by the service to implement its - API. Most media objects when constructed will request a new - QMediaService instance from a QMediaServiceProvider, but some like - QMediaRecorder will share a service with another object. - - QMediaObject itself provides an API for accessing a media service's \l {metaData()}{meta-data} and a means of connecting other media objects, - and peripheral classes like QVideoWidget and QMediaPlaylist. - - \sa QMediaService, QMediaControl -*/ - -/*! - Destroys a media object. -*/ - -QMediaObject::~QMediaObject() -{ - delete d_ptr; -} - -/*! - Returns the service availability error state. -*/ - -QtMultimedia::AvailabilityError QMediaObject::availabilityError() const -{ - return QtMultimedia::ServiceMissingError; -} - -/*! - Returns true if the service is available for use. -*/ - -bool QMediaObject::isAvailable() const -{ - return false; -} - -/*! - Returns the media service that provides the functionality of a multimedia object. -*/ - -QMediaService* QMediaObject::service() const -{ - return d_func()->service; -} - -int QMediaObject::notifyInterval() const -{ - return d_func()->notifyTimer->interval(); -} - -void QMediaObject::setNotifyInterval(int milliSeconds) -{ - Q_D(QMediaObject); - - if (d->notifyTimer->interval() != milliSeconds) { - d->notifyTimer->setInterval(milliSeconds); - - emit notifyIntervalChanged(milliSeconds); - } -} - -/*! - \internal -*/ -void QMediaObject::bind(QObject*) -{ -} - -/*! - \internal -*/ -void QMediaObject::unbind(QObject*) -{ -} - - -/*! - Constructs a media object which uses the functionality provided by a media \a service. - - The \a parent is passed to QObject. - - This class is meant as a base class for Multimedia objects so this - constructor is protected. -*/ - -QMediaObject::QMediaObject(QObject *parent, QMediaService *service): - QObject(parent), - d_ptr(new QMediaObjectPrivate) - -{ - Q_D(QMediaObject); - - d->q_ptr = this; - - d->notifyTimer = new QTimer(this); - d->notifyTimer->setInterval(1000); - connect(d->notifyTimer, SIGNAL(timeout()), SLOT(_q_notify())); - - d->service = service; - - setupMetaData(); -} - -/*! - \internal -*/ - -QMediaObject::QMediaObject(QMediaObjectPrivate &dd, QObject *parent, - QMediaService *service): - QObject(parent), - d_ptr(&dd) -{ - Q_D(QMediaObject); - d->q_ptr = this; - - d->notifyTimer = new QTimer(this); - d->notifyTimer->setInterval(1000); - connect(d->notifyTimer, SIGNAL(timeout()), SLOT(_q_notify())); - - d->service = service; - - setupMetaData(); -} - -/*! - Watch the property \a name. The property's notify signal will be emitted - once every notifyInterval milliseconds. - - \sa notifyInterval -*/ - -void QMediaObject::addPropertyWatch(QByteArray const &name) -{ - Q_D(QMediaObject); - - const QMetaObject* m = metaObject(); - - int index = m->indexOfProperty(name.constData()); - - if (index != -1 && m->property(index).hasNotifySignal()) { - d->notifyProperties.insert(index); - - if (!d->notifyTimer->isActive()) - d->notifyTimer->start(); - } -} - -/*! - Remove property \a name from the list of properties whose changes are - regularly signaled. - - \sa notifyInterval -*/ - -void QMediaObject::removePropertyWatch(QByteArray const &name) -{ - Q_D(QMediaObject); - - int index = metaObject()->indexOfProperty(name.constData()); - - if (index != -1) { - d->notifyProperties.remove(index); - - if (d->notifyProperties.isEmpty()) - d->notifyTimer->stop(); - } -} - -/*! - \property QMediaObject::notifyInterval - - The interval at which notifiable properties will update. - - The interval is expressed in milliseconds, the default value is 1000. - - \sa addPropertyWatch(), removePropertyWatch() -*/ - -/*! - \fn void QMediaObject::notifyIntervalChanged(int milliseconds) - - Signal a change in the notify interval period to \a milliseconds. -*/ - -/*! - \property QMediaObject::metaDataAvailable - \brief whether access to a media object's meta-data is available. - - If this is true there is meta-data available, otherwise there is no meta-data available. -*/ - -bool QMediaObject::isMetaDataAvailable() const -{ - Q_D(const QMediaObject); - - return d->metaDataControl - ? d->metaDataControl->isMetaDataAvailable() - : false; -} - -/*! - \fn QMediaObject::metaDataAvailableChanged(bool available) - - Signals that the \a available state of a media object's meta-data has changed. -*/ - -/*! - \property QMediaObject::metaDataWritable - \brief whether a media object's meta-data is writable. - - If this is true the meta-data is writable, otherwise the meta-data is read-only. -*/ - -bool QMediaObject::isMetaDataWritable() const -{ - Q_D(const QMediaObject); - - return d->metaDataControl - ? d->metaDataControl->isWritable() - : false; -} - -/*! - \fn QMediaObject::metaDataWritableChanged(bool writable) - - Signals that the \a writable state of a media object's meta-data has changed. -*/ - -/*! - Returns the value associated with a meta-data \a key. -*/ -QVariant QMediaObject::metaData(QtMultimedia::MetaData key) const -{ - Q_D(const QMediaObject); - - return d->metaDataControl - ? d->metaDataControl->metaData(key) - : QVariant(); -} - -/*! - Sets a \a value for a meta-data \a key. -*/ -void QMediaObject::setMetaData(QtMultimedia::MetaData key, const QVariant &value) -{ - Q_D(QMediaObject); - - if (d->metaDataControl) - d->metaDataControl->setMetaData(key, value); -} - -/*! - Returns a list of keys there is meta-data available for. -*/ -QList QMediaObject::availableMetaData() const -{ - Q_D(const QMediaObject); - - return d->metaDataControl - ? d->metaDataControl->availableMetaData() - : QList(); -} - -/*! - \fn QMediaObject::metaDataChanged() - - Signals that a media object's meta-data has changed. -*/ - -/*! - Returns the value associated with a meta-data \a key. - - The naming and type of extended meta-data is not standardized, so the values and meaning - of keys may vary between backends. -*/ -QVariant QMediaObject::extendedMetaData(const QString &key) const -{ - Q_D(const QMediaObject); - - return d->metaDataControl - ? d->metaDataControl->extendedMetaData(key) - : QVariant(); -} - -/*! - Sets a \a value for a meta-data \a key. - - The naming and type of extended meta-data is not standardized, so the values and meaning - of keys may vary between backends. -*/ -void QMediaObject::setExtendedMetaData(const QString &key, const QVariant &value) -{ - Q_D(QMediaObject); - - if (d->metaDataControl) - d->metaDataControl->setExtendedMetaData(key, value); -} - -/*! - Returns a list of keys there is extended meta-data available for. -*/ -QStringList QMediaObject::availableExtendedMetaData() const -{ - Q_D(const QMediaObject); - - return d->metaDataControl - ? d->metaDataControl->availableExtendedMetaData() - : QStringList(); -} - - -void QMediaObject::setupMetaData() -{ - Q_D(QMediaObject); - - if (d->service != 0) { - d->metaDataControl = - qobject_cast(d->service->control(QMetaDataControl_iid)); - - if (d->metaDataControl) { - connect(d->metaDataControl, SIGNAL(metaDataChanged()), SIGNAL(metaDataChanged())); - connect(d->metaDataControl, - SIGNAL(metaDataAvailableChanged(bool)), - SIGNAL(metaDataAvailableChanged(bool))); - connect(d->metaDataControl, - SIGNAL(writableChanged(bool)), - SIGNAL(metaDataWritableChanged(bool))); - } - } -} - -/*! - \fn QMediaObject::availabilityChanged(bool available) - - Signal emitted when the availability state has changed to \a available -*/ - - -#include "moc_qmediaobject.cpp" - -QT_END_NAMESPACE - diff --git a/src/multimedia/base/qmediaobject.h b/src/multimedia/base/qmediaobject.h deleted file mode 100644 index d09b1af..0000000 --- a/src/multimedia/base/qmediaobject.h +++ /dev/null @@ -1,121 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtMultimedia module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QABSTRACTMEDIAOBJECT_H -#define QABSTRACTMEDIAOBJECT_H - -#include -#include - -#include - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Multimedia) - -class QMediaService; - -class QMediaObjectPrivate; -class Q_MULTIMEDIA_EXPORT QMediaObject : public QObject -{ - Q_OBJECT - Q_PROPERTY(int notifyInterval READ notifyInterval WRITE setNotifyInterval NOTIFY notifyIntervalChanged) - Q_PROPERTY(bool metaDataAvailable READ isMetaDataAvailable NOTIFY metaDataAvailableChanged) - Q_PROPERTY(bool metaDataWritable READ isMetaDataWritable NOTIFY metaDataWritableChanged) - -public: - ~QMediaObject(); - - virtual bool isAvailable() const; - virtual QtMultimedia::AvailabilityError availabilityError() const; - - virtual QMediaService* service() const; - - int notifyInterval() const; - void setNotifyInterval(int milliSeconds); - - virtual void bind(QObject*); - virtual void unbind(QObject*); - - bool isMetaDataAvailable() const; - bool isMetaDataWritable() const; - - QVariant metaData(QtMultimedia::MetaData key) const; - void setMetaData(QtMultimedia::MetaData key, const QVariant &value); - QList availableMetaData() const; - - QVariant extendedMetaData(const QString &key) const; - void setExtendedMetaData(const QString &key, const QVariant &value); - QStringList availableExtendedMetaData() const; - -Q_SIGNALS: - void notifyIntervalChanged(int milliSeconds); - - void metaDataAvailableChanged(bool available); - void metaDataWritableChanged(bool writable); - void metaDataChanged(); - - void availabilityChanged(bool available); - -protected: - QMediaObject(QObject *parent, QMediaService *service); - QMediaObject(QMediaObjectPrivate &dd, QObject *parent, QMediaService *service); - - void addPropertyWatch(QByteArray const &name); - void removePropertyWatch(QByteArray const &name); - - QMediaObjectPrivate *d_ptr; - -private: - void setupMetaData(); - - Q_DECLARE_PRIVATE(QMediaObject) - Q_PRIVATE_SLOT(d_func(), void _q_notify()) -}; - -QT_END_NAMESPACE - -QT_END_HEADER - - -#endif // QABSTRACTMEDIAOBJECT_H diff --git a/src/multimedia/base/qmediaobject_p.h b/src/multimedia/base/qmediaobject_p.h deleted file mode 100644 index ec2f75a..0000000 --- a/src/multimedia/base/qmediaobject_p.h +++ /dev/null @@ -1,95 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtMultimedia module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QABSTRACTMEDIAOBJECT_P_H -#define QABSTRACTMEDIAOBJECT_P_H - -// -// W A R N I N G -// ------------- -// -// This file is not part of the Qt API. It exists purely as an -// implementation detail. This header file may change from version to -// version without notice, or even be removed. -// -// We mean it. -// - -#include -#include -#include - -#include - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -class QMetaDataControl; - -#define Q_DECLARE_NON_CONST_PUBLIC(Class) \ - inline Class* q_func() { return static_cast(q_ptr); } \ - friend class Class; - - -class QMediaObjectPrivate -{ - Q_DECLARE_PUBLIC(QMediaObject) - -public: - QMediaObjectPrivate():metaDataControl(0), notifyTimer(0) {} - virtual ~QMediaObjectPrivate() {} - - void _q_notify(); - - QMediaService *service; - QMetaDataControl *metaDataControl; - QTimer* notifyTimer; - QSet notifyProperties; - - QMediaObject *q_ptr; -}; - -QT_END_NAMESPACE - -QT_END_HEADER - -#endif diff --git a/src/multimedia/base/qmediaplaylist.cpp b/src/multimedia/base/qmediaplaylist.cpp deleted file mode 100644 index b3f3dd3..0000000 --- a/src/multimedia/base/qmediaplaylist.cpp +++ /dev/null @@ -1,724 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtMultimedia module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include -#include -#include -#include -#include - -#include -#include "qmediaplaylist_p.h" -#include -#include -#include -#include -#include -#include - -#include "qmediapluginloader_p.h" - - -QT_BEGIN_NAMESPACE - -Q_GLOBAL_STATIC_WITH_ARGS(QMediaPluginLoader, playlistIOLoader, - (QMediaPlaylistIOInterface_iid, QLatin1String("/playlistformats"), Qt::CaseInsensitive)) - - -/*! - \class QMediaPlaylist - \ingroup multimedia - \since 4.7 - - \preliminary - \brief The QMediaPlaylist class provides a list of media content to play. - - QMediaPlaylist is intended to be used with other media objects, - like QMediaPlayer or QMediaImageViewer. - QMediaPlaylist allows to access the service intrinsic playlist functionality - if available, otherwise it provides the the local memory playlist implementation. - -\code - player = new QMediaPlayer; - - playlist = new QMediaPlaylist; - playlist->setMediaObject(player); - playlist->append(QUrl("http://example.com/movie1.mp4")); - playlist->append(QUrl("http://example.com/movie2.mp4")); - playlist->append(QUrl("http://example.com/movie3.mp4")); - - playlist->setCurrentIndex(1); - - player->play(); -\endcode - - Depending on playlist source implementation, - most of playlist modifcation operations can be asynchronous. - - \sa QMediaContent -*/ - - -/*! - \enum QMediaPlaylist::PlaybackMode - - The QMediaPlaylist::PlaybackMode describes the order items in playlist are played. - - \value CurrentItemOnce The current item is played only once. - - \value CurrentItemInLoop The current item is played in the loop. - - \value Linear Playback starts from the first to the last items and stops. - next item is a null item when the last one is currently playing. - - \value Loop Playback continues from the first item after the last one finished playing. - - \value Random Play items in random order. -*/ - - - -/*! - Create a new playlist object for with the given \a parent. -*/ - -QMediaPlaylist::QMediaPlaylist(QObject *parent) - : QObject(parent) - , d_ptr(new QMediaPlaylistPrivate) -{ - Q_D(QMediaPlaylist); - - d->q_ptr = this; - d->localPlaylistControl = new QLocalMediaPlaylistControl(this); - - setMediaObject(0); -} - -/*! - Destroys the playlist. - */ - -QMediaPlaylist::~QMediaPlaylist() -{ - Q_D(QMediaPlaylist); - - if (d->mediaObject) - d->mediaObject->unbind(this); - - delete d_ptr; -} - -/*! - Returns the QMediaObject that is being used to play the contents of this playlist. -*/ - -QMediaObject *QMediaPlaylist::mediaObject() const -{ - return d_func()->mediaObject; -} - -/*! - If \a mediaObject is null or doesn't have an intrinsic playlist, - internal local memory playlist source will be created. -*/ -void QMediaPlaylist::setMediaObject(QMediaObject *mediaObject) -{ - Q_D(QMediaPlaylist); - - if (mediaObject && mediaObject == d->mediaObject) - return; - - QMediaService *service = mediaObject - ? mediaObject->service() : 0; - - QMediaPlaylistControl *newControl = 0; - - if (service) - newControl = qobject_cast(service->control(QMediaPlaylistControl_iid)); - - if (!newControl) - newControl = d->localPlaylistControl; - - if (d->control != newControl) { - int oldSize = 0; - if (d->control) { - QMediaPlaylistProvider *playlist = d->control->playlistProvider(); - oldSize = playlist->mediaCount(); - disconnect(playlist, SIGNAL(loadFailed(QMediaPlaylist::Error,QString)), - this, SLOT(_q_loadFailed(QMediaPlaylist::Error,QString))); - - disconnect(playlist, SIGNAL(mediaChanged(int,int)), this, SIGNAL(mediaChanged(int,int))); - disconnect(playlist, SIGNAL(mediaAboutToBeInserted(int,int)), this, SIGNAL(mediaAboutToBeInserted(int,int))); - disconnect(playlist, SIGNAL(mediaInserted(int,int)), this, SIGNAL(mediaInserted(int,int))); - disconnect(playlist, SIGNAL(mediaAboutToBeRemoved(int,int)), this, SIGNAL(mediaAboutToBeRemoved(int,int))); - disconnect(playlist, SIGNAL(mediaRemoved(int,int)), this, SIGNAL(mediaRemoved(int,int))); - - disconnect(playlist, SIGNAL(loaded()), this, SIGNAL(loaded())); - - disconnect(d->control, SIGNAL(playbackModeChanged(QMediaPlaylist::PlaybackMode)), - this, SIGNAL(playbackModeChanged(QMediaPlaylist::PlaybackMode))); - disconnect(d->control, SIGNAL(currentIndexChanged(int)), - this, SIGNAL(currentIndexChanged(int))); - disconnect(d->control, SIGNAL(currentMediaChanged(QMediaContent)), - this, SIGNAL(currentMediaChanged(QMediaContent))); - } - - d->control = newControl; - QMediaPlaylistProvider *playlist = d->control->playlistProvider(); - connect(playlist, SIGNAL(loadFailed(QMediaPlaylist::Error,QString)), - this, SLOT(_q_loadFailed(QMediaPlaylist::Error,QString))); - - connect(playlist, SIGNAL(mediaChanged(int,int)), this, SIGNAL(mediaChanged(int,int))); - connect(playlist, SIGNAL(mediaAboutToBeInserted(int,int)), this, SIGNAL(mediaAboutToBeInserted(int,int))); - connect(playlist, SIGNAL(mediaInserted(int,int)), this, SIGNAL(mediaInserted(int,int))); - connect(playlist, SIGNAL(mediaAboutToBeRemoved(int,int)), this, SIGNAL(mediaAboutToBeRemoved(int,int))); - connect(playlist, SIGNAL(mediaRemoved(int,int)), this, SIGNAL(mediaRemoved(int,int))); - - connect(playlist, SIGNAL(loaded()), this, SIGNAL(loaded())); - - connect(d->control, SIGNAL(playbackModeChanged(QMediaPlaylist::PlaybackMode)), - this, SIGNAL(playbackModeChanged(QMediaPlaylist::PlaybackMode))); - connect(d->control, SIGNAL(currentIndexChanged(int)), - this, SIGNAL(currentIndexChanged(int))); - connect(d->control, SIGNAL(currentMediaChanged(QMediaContent)), - this, SIGNAL(currentMediaChanged(QMediaContent))); - - if (oldSize) - emit mediaRemoved(0, oldSize-1); - - if (playlist->mediaCount()) { - emit mediaAboutToBeInserted(0,playlist->mediaCount()-1); - emit mediaInserted(0,playlist->mediaCount()-1); - } - } - - if (d->mediaObject) - d->mediaObject->unbind(this); - - d->mediaObject = mediaObject; - if (d->mediaObject) - d->mediaObject->bind(this); -} - -/*! - \property QMediaPlaylist::playbackMode - - This property defines the order, items in playlist are played. - - \sa QMediaPlaylist::PlaybackMode -*/ - -QMediaPlaylist::PlaybackMode QMediaPlaylist::playbackMode() const -{ - return d_func()->control->playbackMode(); -} - -void QMediaPlaylist::setPlaybackMode(QMediaPlaylist::PlaybackMode mode) -{ - Q_D(QMediaPlaylist); - d->control->setPlaybackMode(mode); -} - -/*! - Returns position of the current media source in the playlist. -*/ -int QMediaPlaylist::currentIndex() const -{ - return d_func()->control->currentIndex(); -} - -/*! - Returns the current media content. -*/ - -QMediaContent QMediaPlaylist::currentMedia() const -{ - return d_func()->playlist()->media(currentIndex()); -} - -/*! - Returns the index of item, which were current after calling next() - \a steps times. - - Returned value depends on the size of playlist, current position - and playback mode. - - \sa QMediaPlaylist::playbackMode -*/ -int QMediaPlaylist::nextIndex(int steps) const -{ - return d_func()->control->nextIndex(steps); -} - -/*! - Returns the index of item, which were current after calling previous() - \a steps times. - - \sa QMediaPlaylist::playbackMode -*/ - -int QMediaPlaylist::previousIndex(int steps) const -{ - return d_func()->control->previousIndex(steps); -} - - -/*! - Returns the number of items in the playlist. - - \sa isEmpty() - */ -int QMediaPlaylist::mediaCount() const -{ - return d_func()->playlist()->mediaCount(); -} - -/*! - Returns true if the playlist contains no items; otherwise returns false. - \sa mediaCount() - */ -bool QMediaPlaylist::isEmpty() const -{ - return mediaCount() == 0; -} - -/*! - Returns true if the playlist can be modified; otherwise returns false. - \sa mediaCount() - */ -bool QMediaPlaylist::isReadOnly() const -{ - return d_func()->playlist()->isReadOnly(); -} - -/*! - Returns the media content at \a index in the playlist. -*/ - -QMediaContent QMediaPlaylist::media(int index) const -{ - return d_func()->playlist()->media(index); -} - -/*! - Append the media \a content to the playlist. - - Returns true if the operation is successfull, other wise return false. - */ -bool QMediaPlaylist::addMedia(const QMediaContent &content) -{ - return d_func()->control->playlistProvider()->addMedia(content); -} - -/*! - Append multiple media content \a items to the playlist. - - Returns true if the operation is successfull, other wise return false. - */ -bool QMediaPlaylist::addMedia(const QList &items) -{ - return d_func()->control->playlistProvider()->addMedia(items); -} - -/*! - Insert the media \a content to the playlist at position \a pos. - - Returns true if the operation is successful, otherwise false. -*/ - -bool QMediaPlaylist::insertMedia(int pos, const QMediaContent &content) -{ - return d_func()->playlist()->insertMedia(pos, content); -} - -/*! - Insert multiple media content \a items to the playlist at position \a pos. - - Returns true if the operation is successful, otherwise false. -*/ - -bool QMediaPlaylist::insertMedia(int pos, const QList &items) -{ - return d_func()->playlist()->insertMedia(pos, items); -} - -/*! - Remove the item from the playlist at position \a pos. - - Returns true if the operation is successfull, other wise return false. - */ -bool QMediaPlaylist::removeMedia(int pos) -{ - Q_D(QMediaPlaylist); - return d->playlist()->removeMedia(pos); -} - -/*! - Remove the items from the playlist from position \a start to \a end inclusive. - - Returns true if the operation is successfull, other wise return false. - */ -bool QMediaPlaylist::removeMedia(int start, int end) -{ - Q_D(QMediaPlaylist); - return d->playlist()->removeMedia(start, end); -} - -/*! - Remove all the items from the playlist. - - Returns true if the operation is successfull, other wise return false. - */ -bool QMediaPlaylist::clear() -{ - Q_D(QMediaPlaylist); - return d->playlist()->clear(); -} - -bool QMediaPlaylistPrivate::readItems(QMediaPlaylistReader *reader) -{ - while (!reader->atEnd()) - playlist()->addMedia(reader->readItem()); - - return true; -} - -bool QMediaPlaylistPrivate::writeItems(QMediaPlaylistWriter *writer) -{ - for (int i=0; imediaCount(); i++) { - if (!writer->writeItem(playlist()->media(i))) - return false; - } - writer->close(); - return true; -} - -/*! - Load playlist from \a location. If \a format is specified, it is used, - otherwise format is guessed from location name and data. - - New items are appended to playlist. - - QMediaPlaylist::loaded() signal is emited if playlist was loaded succesfully, - otherwise the playlist emits loadFailed(). -*/ -void QMediaPlaylist::load(const QUrl &location, const char *format) -{ - Q_D(QMediaPlaylist); - - d->error = NoError; - d->errorString.clear(); - - if (d->playlist()->load(location,format)) - return; - - if (isReadOnly()) { - d->error = AccessDeniedError; - d->errorString = tr("Could not add items to read only playlist."); - emit loadFailed(); - return; - } - - foreach (QString const& key, playlistIOLoader()->keys()) { - QMediaPlaylistIOInterface* plugin = qobject_cast(playlistIOLoader()->instance(key)); - if (plugin && plugin->canRead(location,format)) { - QMediaPlaylistReader *reader = plugin->createReader(location,QByteArray(format)); - if (reader && d->readItems(reader)) { - delete reader; - emit loaded(); - return; - } - delete reader; - } - } - - d->error = FormatNotSupportedError; - d->errorString = tr("Playlist format is not supported"); - emit loadFailed(); - - return; -} - -/*! - Load playlist from QIODevice \a device. If \a format is specified, it is used, - otherwise format is guessed from device data. - - New items are appended to playlist. - - QMediaPlaylist::loaded() signal is emited if playlist was loaded succesfully, - otherwise the playlist emits loadFailed(). -*/ -void QMediaPlaylist::load(QIODevice * device, const char *format) -{ - Q_D(QMediaPlaylist); - - d->error = NoError; - d->errorString.clear(); - - if (d->playlist()->load(device,format)) - return; - - if (isReadOnly()) { - d->error = AccessDeniedError; - d->errorString = tr("Could not add items to read only playlist."); - emit loadFailed(); - return; - } - - foreach (QString const& key, playlistIOLoader()->keys()) { - QMediaPlaylistIOInterface* plugin = qobject_cast(playlistIOLoader()->instance(key)); - if (plugin && plugin->canRead(device,format)) { - QMediaPlaylistReader *reader = plugin->createReader(device,QByteArray(format)); - if (reader && d->readItems(reader)) { - delete reader; - emit loaded(); - return; - } - delete reader; - } - } - - d->error = FormatNotSupportedError; - d->errorString = tr("Playlist format is not supported"); - emit loadFailed(); - - return; -} - -/*! - Save playlist to \a location. If \a format is specified, it is used, - otherwise format is guessed from location name. - - Returns true if playlist was saved succesfully, otherwise returns false. - */ -bool QMediaPlaylist::save(const QUrl &location, const char *format) -{ - Q_D(QMediaPlaylist); - - d->error = NoError; - d->errorString.clear(); - - if (d->playlist()->save(location,format)) - return true; - - QFile file(location.toLocalFile()); - - if (!file.open(QIODevice::WriteOnly | QIODevice::Truncate)) { - d->error = AccessDeniedError; - d->errorString = tr("The file could not be accessed."); - return false; - } - - return save(&file, format); -} - -/*! - Save playlist to QIODevice \a device using format \a format. - - Returns true if playlist was saved succesfully, otherwise returns false. -*/ -bool QMediaPlaylist::save(QIODevice * device, const char *format) -{ - Q_D(QMediaPlaylist); - - d->error = NoError; - d->errorString.clear(); - - if (d->playlist()->save(device,format)) - return true; - - foreach (QString const& key, playlistIOLoader()->keys()) { - QMediaPlaylistIOInterface* plugin = qobject_cast(playlistIOLoader()->instance(key)); - if (plugin && plugin->canWrite(device,format)) { - QMediaPlaylistWriter *writer = plugin->createWriter(device,QByteArray(format)); - if (writer && d->writeItems(writer)) { - delete writer; - return true; - } - delete writer; - } - } - - d->error = FormatNotSupportedError; - d->errorString = tr("Playlist format is not supported."); - - return false; -} - -/*! - Returns the last error condition. -*/ -QMediaPlaylist::Error QMediaPlaylist::error() const -{ - return d_func()->error; -} - -/*! - Returns the string describing the last error condition. -*/ -QString QMediaPlaylist::errorString() const -{ - return d_func()->errorString; -} - -/*! - Shuffle items in the playlist. -*/ -void QMediaPlaylist::shuffle() -{ - d_func()->playlist()->shuffle(); -} - - -/*! - Advance to the next media content in playlist. -*/ -void QMediaPlaylist::next() -{ - d_func()->control->next(); -} - -/*! - Return to the previous media content in playlist. -*/ -void QMediaPlaylist::previous() -{ - d_func()->control->previous(); -} - -/*! - Activate media content from playlist at position \a playlistPosition. -*/ - -void QMediaPlaylist::setCurrentIndex(int playlistPosition) -{ - d_func()->control->setCurrentIndex(playlistPosition); -} - -/*! - \fn void QMediaPlaylist::mediaInserted(int start, int end) - - This signal is emitted after media has been inserted into the playlist. - The new items are those between \a start and \a end inclusive. - */ - -/*! - \fn void QMediaPlaylist::mediaRemoved(int start, int end) - - This signal is emitted after media has been removed from the playlist. - The removed items are those between \a start and \a end inclusive. - */ - -/*! - \fn void QMediaPlaylist::mediaChanged(int start, int end) - - This signal is emitted after media has been changed in the playlist - between \a start and \a end positions inclusive. - */ - -/*! - \fn void QMediaPlaylist::currentIndexChanged(int position) - - Signal emitted when playlist position changed to \a position. -*/ - -/*! - \fn void QMediaPlaylist::playbackModeChanged(QMediaPlaylist::PlaybackMode mode) - - Signal emitted when playback mode changed to \a mode. -*/ - -/*! - \fn void QMediaPlaylist::mediaAboutToBeInserted(int start, int end) - - Signal emitted when item to be inserted at \a start and ending at \a end. -*/ - -/*! - \fn void QMediaPlaylist::mediaAboutToBeRemoved(int start, int end) - - Signal emitted when item to de deleted ar \a start and ending at \a end. -*/ - -/*! - \fn void QMediaPlaylist::currentMediaChanged(const QMediaContent &content) - - Signal emitted when current media changes to \a content. -*/ - -/*! - \property QMediaPlaylist::currentIndex - \brief Current position. -*/ - -/*! - \property QMediaPlaylist::currentMedia - \brief Current media content. -*/ - -/*! - \fn QMediaPlaylist::loaded() - - Signal emitted when playlist finished loading. -*/ - -/*! - \fn QMediaPlaylist::loadFailed() - - Signal emitted if failed to load playlist. -*/ - -/*! - \enum QMediaPlaylist::Error - - This enum describes the QMediaPlaylist error codes. - - \value NoError No errors. - \value FormatError Format error. - \value FormatNotSupportedError Format not supported. - \value NetworkError Network error. - \value AccessDeniedError Access denied error. -*/ - -QT_END_NAMESPACE - -#include "moc_qmediaplaylist.cpp" -#include "moc_qmediaplaylist_p.cpp" diff --git a/src/multimedia/base/qmediaplaylist.h b/src/multimedia/base/qmediaplaylist.h deleted file mode 100644 index 494cf11..0000000 --- a/src/multimedia/base/qmediaplaylist.h +++ /dev/null @@ -1,147 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtMultimedia module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QMEDIAPLAYLIST_H -#define QMEDIAPLAYLIST_H - -#include - -#include -#include - - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Multimedia) - -class QMediaPlaylistProvider; - -class QMediaPlaylistPrivate; -class Q_MULTIMEDIA_EXPORT QMediaPlaylist : public QObject -{ - Q_OBJECT - Q_PROPERTY(QMediaPlaylist::PlaybackMode playbackMode READ playbackMode WRITE setPlaybackMode NOTIFY playbackModeChanged) - Q_PROPERTY(QMediaContent currentMedia READ currentMedia NOTIFY currentMediaChanged) - Q_PROPERTY(int currentIndex READ currentIndex WRITE setCurrentIndex NOTIFY currentIndexChanged) - Q_ENUMS(PlaybackMode Error) - -public: - enum PlaybackMode { CurrentItemOnce, CurrentItemInLoop, Linear, Loop, Random }; - enum Error { NoError, FormatError, FormatNotSupportedError, NetworkError, AccessDeniedError }; - - QMediaPlaylist(QObject *parent = 0); - virtual ~QMediaPlaylist(); - - QMediaObject *mediaObject() const; - void setMediaObject(QMediaObject *object); - - PlaybackMode playbackMode() const; - void setPlaybackMode(PlaybackMode mode); - - int currentIndex() const; - QMediaContent currentMedia() const; - - int nextIndex(int steps = 1) const; - int previousIndex(int steps = 1) const; - - QMediaContent media(int index) const; - - int mediaCount() const; - bool isEmpty() const; - bool isReadOnly() const; - - bool addMedia(const QMediaContent &content); - bool addMedia(const QList &items); - bool insertMedia(int index, const QMediaContent &content); - bool insertMedia(int index, const QList &items); - bool removeMedia(int pos); - bool removeMedia(int start, int end); - bool clear(); - - void load(const QUrl &location, const char *format = 0); - void load(QIODevice * device, const char *format = 0); - - bool save(const QUrl &location, const char *format = 0); - bool save(QIODevice * device, const char *format); - - Error error() const; - QString errorString() const; - -public Q_SLOTS: - void shuffle(); - - void next(); - void previous(); - - void setCurrentIndex(int index); - -Q_SIGNALS: - void currentIndexChanged(int index); - void playbackModeChanged(QMediaPlaylist::PlaybackMode mode); - void currentMediaChanged(const QMediaContent&); - - void mediaAboutToBeInserted(int start, int end); - void mediaInserted(int start, int end); - void mediaAboutToBeRemoved(int start, int end); - void mediaRemoved(int start, int end); - void mediaChanged(int start, int end); - - void loaded(); - void loadFailed(); - -protected: - QMediaPlaylistPrivate *d_ptr; - -private: - Q_DECLARE_PRIVATE(QMediaPlaylist) - Q_PRIVATE_SLOT(d_func(), void _q_loadFailed(QMediaPlaylist::Error, const QString &)) -}; - -QT_END_NAMESPACE - -Q_DECLARE_METATYPE(QMediaPlaylist::PlaybackMode) -Q_DECLARE_METATYPE(QMediaPlaylist::Error) - -QT_END_HEADER - -#endif // QMEDIAPLAYLIST_H diff --git a/src/multimedia/base/qmediaplaylist_p.h b/src/multimedia/base/qmediaplaylist_p.h deleted file mode 100644 index da529b7..0000000 --- a/src/multimedia/base/qmediaplaylist_p.h +++ /dev/null @@ -1,172 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtMultimedia module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QMEDIAPLAYLIST_P_H -#define QMEDIAPLAYLIST_P_H - -// -// W A R N I N G -// ------------- -// -// This file is not part of the Qt API. It exists purely as an -// implementation detail. This header file may change from version to -// version without notice, or even be removed. -// -// We mean it. -// - -#include -#include -#include -#include -#include -#include "qmediaobject_p.h" - -#include - -#ifdef Q_MOC_RUN -# pragma Q_MOC_EXPAND_MACROS -#endif - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -class QMediaPlaylistControl; -class QMediaPlaylistProvider; -class QMediaPlaylistReader; -class QMediaPlaylistWriter; -class QMediaPlayerControl; - -class QMediaPlaylistPrivate -{ - Q_DECLARE_PUBLIC(QMediaPlaylist) -public: - QMediaPlaylistPrivate() - :mediaObject(0), - control(0), - localPlaylistControl(0), - error(QMediaPlaylist::NoError) - { - } - - virtual ~QMediaPlaylistPrivate() {} - - void _q_loadFailed(QMediaPlaylist::Error error, const QString &errorString) - { - this->error = error; - this->errorString = errorString; - - emit q_ptr->loadFailed(); - } - - void _q_mediaObjectDeleted() - { - Q_Q(QMediaPlaylist); - mediaObject = 0; - if (control != localPlaylistControl) - control = 0; - q->setMediaObject(0); - } - - QMediaObject *mediaObject; - - QMediaPlaylistControl *control; - QMediaPlaylistProvider *playlist() const { return control->playlistProvider(); } - - QMediaPlaylistControl *localPlaylistControl; - - bool readItems(QMediaPlaylistReader *reader); - bool writeItems(QMediaPlaylistWriter *writer); - - QMediaPlaylist::Error error; - QString errorString; - - QMediaPlaylist *q_ptr; -}; - - -class QLocalMediaPlaylistControl : public QMediaPlaylistControl -{ - Q_OBJECT -public: - QLocalMediaPlaylistControl(QObject *parent) - :QMediaPlaylistControl(parent) - { - QMediaPlaylistProvider *playlist = new QLocalMediaPlaylistProvider(this); - m_navigator = new QMediaPlaylistNavigator(playlist,this); - m_navigator->setPlaybackMode(QMediaPlaylist::Linear); - - connect(m_navigator, SIGNAL(currentIndexChanged(int)), SIGNAL(currentIndexChanged(int))); - connect(m_navigator, SIGNAL(activated(QMediaContent)), SIGNAL(currentMediaChanged(QMediaContent))); - } - - virtual ~QLocalMediaPlaylistControl() {}; - - QMediaPlaylistProvider* playlistProvider() const { return m_navigator->playlist(); } - bool setPlaylistProvider(QMediaPlaylistProvider *mediaPlaylist) - { - m_navigator->setPlaylist(mediaPlaylist); - emit playlistProviderChanged(); - return true; - } - - int currentIndex() const { return m_navigator->currentIndex(); } - void setCurrentIndex(int position) { m_navigator->jump(position); } - int nextIndex(int steps) const { return m_navigator->nextIndex(steps); } - int previousIndex(int steps) const { return m_navigator->previousIndex(steps); } - - void next() { m_navigator->next(); } - void previous() { m_navigator->previous(); } - - QMediaPlaylist::PlaybackMode playbackMode() const { return m_navigator->playbackMode(); } - void setPlaybackMode(QMediaPlaylist::PlaybackMode mode) { m_navigator->setPlaybackMode(mode); } - -private: - QMediaPlaylistNavigator *m_navigator; -}; - - -QT_END_NAMESPACE - -QT_END_HEADER - -#endif // QMEDIAPLAYLIST_P_H diff --git a/src/multimedia/base/qmediaplaylistcontrol.cpp b/src/multimedia/base/qmediaplaylistcontrol.cpp deleted file mode 100644 index ba3d224..0000000 --- a/src/multimedia/base/qmediaplaylistcontrol.cpp +++ /dev/null @@ -1,204 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtMultimedia module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - - -#include -#include "qmediacontrol_p.h" - - -QT_BEGIN_NAMESPACE - -/*! - \class QMediaPlaylistControl - \ingroup multimedia-serv - \since 4.7 - - \preliminary - \brief The QMediaPlaylistControl class provides access to the playlist functionality of a - QMediaService. - - If a QMediaService contains an internal playlist it will implement QMediaPlaylistControl. This - control provides access to the contents of the \l {playlistProvider()}{playlist}, as well as the - \l {currentIndex()}{position} of the current media, and a means of navigating to the - \l {next()}{next} and \l {previous()}{previous} media. - - The functionality provided by the control is exposed to application code through the - QMediaPlaylist class. - - The interface name of QMediaPlaylistControl is \c com.nokia.Qt.QMediaPlaylistControl/1.0 as - defined in QMediaPlaylistControl_iid. - - \sa QMediaService::control(), QMediaPlayer -*/ - -/*! - \macro QMediaPlaylistControl_iid - - \c com.nokia.Qt.QMediaPlaylistControl/1.0 - - Defines the interface name of the QMediaPlaylistControl class. - - \relates QMediaPlaylistControl -*/ - -/*! - Create a new playlist control object with the given \a parent. -*/ -QMediaPlaylistControl::QMediaPlaylistControl(QObject *parent): - QMediaControl(*new QMediaControlPrivate, parent) -{ -} - -/*! - Destroys the playlist control. -*/ -QMediaPlaylistControl::~QMediaPlaylistControl() -{ -} - - -/*! - \fn QMediaPlaylistControl::playlistProvider() const - - Returns the playlist used by this media player. -*/ - -/*! - \fn QMediaPlaylistControl::setPlaylistProvider(QMediaPlaylistProvider *playlist) - - Set the playlist of this media player to \a playlist. - - In many cases it is possible just to use the playlist - constructed by player, but sometimes replacing the whole - playlist allows to avoid copyting of all the items bettween playlists. - - Returns true if player can use this passed playlist; otherwise returns false. - -*/ - -/*! - \fn QMediaPlaylistControl::currentIndex() const - - Returns position of the current media source in the playlist. -*/ - -/*! - \fn QMediaPlaylistControl::setCurrentIndex(int position) - - Jump to the item at the given \a position. -*/ - -/*! - \fn QMediaPlaylistControl::nextIndex(int step) const - - Returns the index of item, which were current after calling next() - \a step times. - - Returned value depends on the size of playlist, current position - and playback mode. - - \sa QMediaPlaylist::playbackMode -*/ - -/*! - \fn QMediaPlaylistControl::previousIndex(int step) const - - Returns the index of item, which were current after calling previous() - \a step times. - - \sa QMediaPlaylist::playbackMode -*/ - -/*! - \fn QMediaPlaylistControl::next() - - Moves to the next item in playlist. -*/ - -/*! - \fn QMediaPlaylistControl::previous() - - Returns to the previous item in playlist. -*/ - -/*! - \fn QMediaPlaylistControl::playbackMode() const - - Returns the playlist navigation mode. - - \sa QMediaPlaylist::PlaybackMode -*/ - -/*! - \fn QMediaPlaylistControl::setPlaybackMode(QMediaPlaylist::PlaybackMode mode) - - Sets the playback \a mode. - - \sa QMediaPlaylist::PlaybackMode -*/ - -/*! - \fn QMediaPlaylistControl::playlistProviderChanged() - - Signal emited when the playlist provider has changed. -*/ - -/*! - \fn QMediaPlaylistControl::currentIndexChanged(int position) - - Signal emited when the playlist \a position is changed. -*/ - -/*! - \fn QMediaPlaylistControl::playbackModeChanged(QMediaPlaylist::PlaybackMode mode) - - Signal emited when the playback \a mode is changed. -*/ - -/*! - \fn QMediaPlaylistControl::currentMediaChanged(const QMediaContent& content) - - Signal emitted when current media changes to \a content. -*/ - -#include "moc_qmediaplaylistcontrol.cpp" -QT_END_NAMESPACE - diff --git a/src/multimedia/base/qmediaplaylistcontrol.h b/src/multimedia/base/qmediaplaylistcontrol.h deleted file mode 100644 index 228ee19..0000000 --- a/src/multimedia/base/qmediaplaylistcontrol.h +++ /dev/null @@ -1,97 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtMultimedia module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - - -#ifndef QMEDIAPLAYLISTCONTROL_H -#define QMEDIAPLAYLISTCONTROL_H - -#include -#include - - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Multimedia) - - -class QMediaPlaylistProvider; - -class Q_MULTIMEDIA_EXPORT QMediaPlaylistControl : public QMediaControl -{ - Q_OBJECT - -public: - virtual ~QMediaPlaylistControl(); - - virtual QMediaPlaylistProvider* playlistProvider() const = 0; - virtual bool setPlaylistProvider(QMediaPlaylistProvider *playlist) = 0; - - virtual int currentIndex() const = 0; - virtual void setCurrentIndex(int position) = 0; - virtual int nextIndex(int steps) const = 0; - virtual int previousIndex(int steps) const = 0; - - virtual void next() = 0; - virtual void previous() = 0; - - virtual QMediaPlaylist::PlaybackMode playbackMode() const = 0; - virtual void setPlaybackMode(QMediaPlaylist::PlaybackMode mode) = 0; - -Q_SIGNALS: - void playlistProviderChanged(); - void currentIndexChanged(int position); - void currentMediaChanged(const QMediaContent&); - void playbackModeChanged(QMediaPlaylist::PlaybackMode mode); - -protected: - QMediaPlaylistControl(QObject* parent = 0); -}; - -#define QMediaPlaylistControl_iid "com.nokia.Qt.QMediaPlaylistControl/1.0" -Q_MEDIA_DECLARE_CONTROL(QMediaPlaylistControl, QMediaPlaylistControl_iid) - -QT_END_NAMESPACE - -QT_END_HEADER - -#endif // QMEDIAPLAYLISTCONTROL_H diff --git a/src/multimedia/base/qmediaplaylistioplugin.cpp b/src/multimedia/base/qmediaplaylistioplugin.cpp deleted file mode 100644 index 48fd721..0000000 --- a/src/multimedia/base/qmediaplaylistioplugin.cpp +++ /dev/null @@ -1,192 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtMultimedia module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include - -QT_BEGIN_NAMESPACE - -/*! - \class QMediaPlaylistReader - \preliminary - \since 4.7 - \brief The QMediaPlaylistReader class provides an interface for reading a playlist file. - - \sa QMediaPlaylistIOPlugin -*/ - -/*! - Destroys a media playlist reader. -*/ -QMediaPlaylistReader::~QMediaPlaylistReader() -{ -} - -/*! - \fn QMediaPlaylistReader::atEnd() const - - Identifies if a playlist reader has reached the end of its input. - - Returns true if the reader has reached the end; and false otherwise. -*/ - -/*! - \fn QMediaPlaylistReader::readItem() - - Reads an item of media from a playlist file. - - Returns the read media, or a null QMediaContent if no more media is available. -*/ - -/*! - \fn QMediaPlaylistReader::close() - - Closes a playlist reader's input device. -*/ - -/*! - \class QMediaPlaylistWriter - \preliminary - \since 4.7 - \brief The QMediaPlaylistWriter class provides an interface for writing a playlist file. - - \sa QMediaPlaylistIOPlugin -*/ - -/*! - Destroys a media playlist writer. -*/ -QMediaPlaylistWriter::~QMediaPlaylistWriter() -{ -} - -/*! - \fn QMediaPlaylistWriter::writeItem(const QMediaContent &media) - - Writes an item of \a media to a playlist file. - - Returns true if the media was written succesfully; and false otherwise. -*/ - -/*! - \fn QMediaPlaylistWriter::close() - - Finalizes the writing of a playlist and closes the output device. -*/ - -/*! - \class QMediaPlaylistIOPlugin - \since 4.7 - \brief The QMediaPlaylistIOPlugin class provides an interface for media playlist I/O plug-ins. -*/ - -/*! - Constructs a media playlist I/O plug-in with the given \a parent. -*/ -QMediaPlaylistIOPlugin::QMediaPlaylistIOPlugin(QObject *parent) - :QObject(parent) -{ -} - -/*! - Destroys a media playlist I/O plug-in. -*/ -QMediaPlaylistIOPlugin::~QMediaPlaylistIOPlugin() -{ -} - -/*! - \fn QMediaPlaylistIOPlugin::canRead(QIODevice *device, const QByteArray &format) const - - Identifies if plug-in can read \a format data from an I/O \a device. - - Returns true if the data can be read; and false otherwise. -*/ - -/*! - \fn QMediaPlaylistIOPlugin::canRead(const QUrl& location, const QByteArray &format) const - - Identifies if a plug-in can read \a format data from a URL \a location. - - Returns true if the data can be read; and false otherwise. -*/ - -/*! - \fn QMediaPlaylistIOPlugin::canWrite(QIODevice *device, const QByteArray &format) const - - Identifies if a plug-in can write \a format data to an I/O \a device. - - Returns true if the data can be written; and false otherwise. -*/ - -/*! - \fn QMediaPlaylistIOPlugin::keys() const - - Returns a list of format keys supported by a plug-in. -*/ - -/*! - \fn QMediaPlaylistIOPlugin::createReader(QIODevice *device, const QByteArray &format) - - Returns a new QMediaPlaylistReader which reads \a format data from an I/O \a device. - - If the device is invalid or the format is unsupported this will return a null pointer. -*/ - -/*! - \fn QMediaPlaylistIOPlugin::createReader(const QUrl& location, const QByteArray &format) - - Returns a new QMediaPlaylistReader which reads \a format data from a URL \a location. - - If the location or the format is unsupported this will return a null pointer. -*/ - -/*! - \fn QMediaPlaylistIOPlugin::createWriter(QIODevice *device, const QByteArray &format) - - Returns a new QMediaPlaylistWriter which writes \a format data to an I/O \a device. - - If the device is invalid or the format is unsupported this will return a null pointer. -*/ - -QT_END_NAMESPACE - -#include "moc_qmediaplaylistioplugin.cpp" - diff --git a/src/multimedia/base/qmediaplaylistioplugin.h b/src/multimedia/base/qmediaplaylistioplugin.h deleted file mode 100644 index e55298d..0000000 --- a/src/multimedia/base/qmediaplaylistioplugin.h +++ /dev/null @@ -1,126 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtMultimedia module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QMEDIAPLAYLISTIOPLUGIN_H -#define QMEDIAPLAYLISTIOPLUGIN_H - -#include -#include -#include - -#include - - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Multimedia) - - -class QString; -class QUrl; -class QByteArray; -class QIODevice; -class QStringList; - -class Q_MULTIMEDIA_EXPORT QMediaPlaylistReader -{ -public: - virtual ~QMediaPlaylistReader(); - - virtual bool atEnd() const = 0; - virtual QMediaContent readItem() = 0; - virtual void close() = 0; -}; - -class Q_MULTIMEDIA_EXPORT QMediaPlaylistWriter -{ -public: - virtual ~QMediaPlaylistWriter(); - - virtual bool writeItem(const QMediaContent &content) = 0; - virtual void close() = 0; -}; - -struct Q_MULTIMEDIA_EXPORT QMediaPlaylistIOInterface : public QFactoryInterface -{ - virtual bool canRead(QIODevice *device, const QByteArray &format = QByteArray() ) const = 0; - virtual bool canRead(const QUrl& location, const QByteArray &format = QByteArray()) const = 0; - - virtual bool canWrite(QIODevice *device, const QByteArray &format) const = 0; - - virtual QMediaPlaylistReader *createReader(QIODevice *device, const QByteArray &format = QByteArray()) = 0; - virtual QMediaPlaylistReader *createReader(const QUrl& location, const QByteArray &format = QByteArray()) = 0; - - virtual QMediaPlaylistWriter *createWriter(QIODevice *device, const QByteArray &format) = 0; -}; - -#define QMediaPlaylistIOInterface_iid "com.nokia.Qt.QMediaPlaylistIOInterface" -Q_DECLARE_INTERFACE(QMediaPlaylistIOInterface, QMediaPlaylistIOInterface_iid); - -class Q_MULTIMEDIA_EXPORT QMediaPlaylistIOPlugin : public QObject, public QMediaPlaylistIOInterface -{ - Q_OBJECT - Q_INTERFACES(QMediaPlaylistIOInterface:QFactoryInterface) - -public: - explicit QMediaPlaylistIOPlugin(QObject *parent = 0); - virtual ~QMediaPlaylistIOPlugin(); - - virtual bool canRead(QIODevice *device, const QByteArray &format = QByteArray() ) const = 0; - virtual bool canRead(const QUrl& location, const QByteArray &format = QByteArray()) const = 0; - - virtual bool canWrite(QIODevice *device, const QByteArray &format) const = 0; - - virtual QStringList keys() const = 0; - - virtual QMediaPlaylistReader *createReader(QIODevice *device, const QByteArray &format = QByteArray()) = 0; - virtual QMediaPlaylistReader *createReader(const QUrl& location, const QByteArray &format = QByteArray()) = 0; - - virtual QMediaPlaylistWriter *createWriter(QIODevice *device, const QByteArray &format) = 0; -}; - -QT_END_NAMESPACE - -QT_END_HEADER - -#endif // QMEDIAPLAYLISTIOPLUGIN_H diff --git a/src/multimedia/base/qmediaplaylistnavigator.cpp b/src/multimedia/base/qmediaplaylistnavigator.cpp deleted file mode 100644 index 0c52c71..0000000 --- a/src/multimedia/base/qmediaplaylistnavigator.cpp +++ /dev/null @@ -1,545 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtMultimedia module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include -#include -#include -#include "qmediaobject_p.h" - -#include - -QT_BEGIN_NAMESPACE - -class QMediaPlaylistNullProvider : public QMediaPlaylistProvider -{ -public: - QMediaPlaylistNullProvider() :QMediaPlaylistProvider() {} - virtual ~QMediaPlaylistNullProvider() {} - virtual int mediaCount() const {return 0;} - virtual QMediaContent media(int) const { return QMediaContent(); } -}; - -Q_GLOBAL_STATIC(QMediaPlaylistNullProvider, _q_nullMediaPlaylist) - -class QMediaPlaylistNavigatorPrivate -{ - Q_DECLARE_NON_CONST_PUBLIC(QMediaPlaylistNavigator) -public: - QMediaPlaylistNavigatorPrivate() - :playlist(0), - currentPos(-1), - lastValidPos(-1), - playbackMode(QMediaPlaylist::Linear), - randomPositionsOffset(-1) - { - } - - QMediaPlaylistProvider *playlist; - int currentPos; - int lastValidPos; //to be used with CurrentItemOnce playback mode - QMediaPlaylist::PlaybackMode playbackMode; - QMediaContent currentItem; - - mutable QList randomModePositions; - mutable int randomPositionsOffset; - - int nextItemPos(int steps = 1) const; - int previousItemPos(int steps = 1) const; - - void _q_mediaInserted(int start, int end); - void _q_mediaRemoved(int start, int end); - void _q_mediaChanged(int start, int end); - - QMediaPlaylistNavigator *q_ptr; -}; - - -int QMediaPlaylistNavigatorPrivate::nextItemPos(int steps) const -{ - if (playlist->mediaCount() == 0) - return -1; - - if (steps == 0) - return currentPos; - - switch (playbackMode) { - case QMediaPlaylist::CurrentItemOnce: - return /*currentPos == -1 ? lastValidPos :*/ -1; - case QMediaPlaylist::CurrentItemInLoop: - return currentPos; - case QMediaPlaylist::Linear: - { - int nextPos = currentPos+steps; - return nextPos < playlist->mediaCount() ? nextPos : -1; - } - case QMediaPlaylist::Loop: - return (currentPos+steps) % playlist->mediaCount(); - case QMediaPlaylist::Random: - { - //TODO: limit the history size - - if (randomPositionsOffset == -1) { - randomModePositions.clear(); - randomModePositions.append(currentPos); - randomPositionsOffset = 0; - } - - while (randomModePositions.size() < randomPositionsOffset+steps+1) - randomModePositions.append(-1); - int res = randomModePositions[randomPositionsOffset+steps]; - if (res<0 || res >= playlist->mediaCount()) { - res = qrand() % playlist->mediaCount(); - randomModePositions[randomPositionsOffset+steps] = res; - } - - return res; - } - } - - return -1; -} - -int QMediaPlaylistNavigatorPrivate::previousItemPos(int steps) const -{ - if (playlist->mediaCount() == 0) - return -1; - - if (steps == 0) - return currentPos; - - switch (playbackMode) { - case QMediaPlaylist::CurrentItemOnce: - return /*currentPos == -1 ? lastValidPos :*/ -1; - case QMediaPlaylist::CurrentItemInLoop: - return currentPos; - case QMediaPlaylist::Linear: - { - int prevPos = currentPos == -1 ? playlist->mediaCount() - steps : currentPos - steps; - return prevPos>=0 ? prevPos : -1; - } - case QMediaPlaylist::Loop: - { - int prevPos = currentPos - steps; - while (prevPos<0) - prevPos += playlist->mediaCount(); - return prevPos; - } - case QMediaPlaylist::Random: - { - //TODO: limit the history size - - if (randomPositionsOffset == -1) { - randomModePositions.clear(); - randomModePositions.append(currentPos); - randomPositionsOffset = 0; - } - - while (randomPositionsOffset-steps < 0) { - randomModePositions.prepend(-1); - randomPositionsOffset++; - } - - int res = randomModePositions[randomPositionsOffset-steps]; - if (res<0 || res >= playlist->mediaCount()) { - res = qrand() % playlist->mediaCount(); - randomModePositions[randomPositionsOffset-steps] = res; - } - - return res; - } - } - - return -1; -} - -/*! - \class QMediaPlaylistNavigator - \preliminary - \since 4.7 - \brief The QMediaPlaylistNavigator class provides navigation for a media playlist. - - \sa QMediaPlaylist, QMediaPlaylistProvider -*/ - - -/*! - Constructs a media playlist navigator for a \a playlist. - - The \a parent is passed to QObject. - */ -QMediaPlaylistNavigator::QMediaPlaylistNavigator(QMediaPlaylistProvider *playlist, QObject *parent) - : QObject(parent) - , d_ptr(new QMediaPlaylistNavigatorPrivate) -{ - d_ptr->q_ptr = this; - - setPlaylist(playlist ? playlist : _q_nullMediaPlaylist()); -} - -/*! - Destroys a media playlist navigator. - */ - -QMediaPlaylistNavigator::~QMediaPlaylistNavigator() -{ - delete d_ptr; -} - - -/*! \property QMediaPlaylistNavigator::playbackMode - Contains the playback mode. - */ -QMediaPlaylist::PlaybackMode QMediaPlaylistNavigator::playbackMode() const -{ - return d_func()->playbackMode; -} - -/*! - Sets the playback \a mode. - */ -void QMediaPlaylistNavigator::setPlaybackMode(QMediaPlaylist::PlaybackMode mode) -{ - Q_D(QMediaPlaylistNavigator); - if (d->playbackMode == mode) - return; - - if (mode == QMediaPlaylist::Random) { - d->randomPositionsOffset = 0; - d->randomModePositions.append(d->currentPos); - } else if (d->playbackMode == QMediaPlaylist::Random) { - d->randomPositionsOffset = -1; - d->randomModePositions.clear(); - } - - d->playbackMode = mode; - - emit playbackModeChanged(mode); - emit surroundingItemsChanged(); -} - -/*! - Returns the playlist being navigated. -*/ - -QMediaPlaylistProvider *QMediaPlaylistNavigator::playlist() const -{ - return d_func()->playlist; -} - -/*! - Sets the \a playlist to navigate. -*/ -void QMediaPlaylistNavigator::setPlaylist(QMediaPlaylistProvider *playlist) -{ - Q_D(QMediaPlaylistNavigator); - - if (d->playlist == playlist) - return; - - if (d->playlist) { - d->playlist->disconnect(this); - } - - if (playlist) { - d->playlist = playlist; - } else { - //assign to shared readonly null playlist - d->playlist = _q_nullMediaPlaylist(); - } - - connect(d->playlist, SIGNAL(mediaInserted(int,int)), SLOT(_q_mediaInserted(int,int))); - connect(d->playlist, SIGNAL(mediaRemoved(int,int)), SLOT(_q_mediaRemoved(int,int))); - connect(d->playlist, SIGNAL(mediaChanged(int,int)), SLOT(_q_mediaChanged(int,int))); - - d->randomPositionsOffset = -1; - d->randomModePositions.clear(); - - if (d->currentPos != -1) { - d->currentPos = -1; - emit currentIndexChanged(-1); - } - - if (!d->currentItem.isNull()) { - d->currentItem = QMediaContent(); - emit activated(d->currentItem); //stop playback - } -} - -/*! \property QMediaPlaylistNavigator::currentItem - - Contains the media at the current position in the playlist. - - \sa currentIndex() -*/ - -QMediaContent QMediaPlaylistNavigator::currentItem() const -{ - return itemAt(d_func()->currentPos); -} - -/*! \fn QMediaContent QMediaPlaylistNavigator::nextItem(int steps) const - - Returns the media that is \a steps positions ahead of the current - position in the playlist. - - \sa nextIndex() -*/ -QMediaContent QMediaPlaylistNavigator::nextItem(int steps) const -{ - return itemAt(nextIndex(steps)); -} - -/*! - Returns the media that is \a steps positions behind the current - position in the playlist. - - \sa previousIndex() - */ -QMediaContent QMediaPlaylistNavigator::previousItem(int steps) const -{ - return itemAt(previousIndex(steps)); -} - -/*! - Returns the media at a \a position in the playlist. - */ -QMediaContent QMediaPlaylistNavigator::itemAt(int position) const -{ - return d_func()->playlist->media(position); -} - -/*! \property QMediaPlaylistNavigator::currentIndex - - Contains the position of the current media. - - If no media is current, the property contains -1. - - \sa nextIndex(), previousIndex() -*/ - -int QMediaPlaylistNavigator::currentIndex() const -{ - return d_func()->currentPos; -} - -/*! - Returns a position \a steps ahead of the current position - accounting for the playbackMode(). - - If the position is beyond the end of the playlist, this value - returned is -1. - - \sa currentIndex(), previousIndex(), playbackMode() -*/ - -int QMediaPlaylistNavigator::nextIndex(int steps) const -{ - return d_func()->nextItemPos(steps); -} - -/*! - - Returns a position \a steps behind the current position accounting - for the playbackMode(). - - If the position is prior to the beginning of the playlist this will - return -1. - - \sa currentIndex(), nextIndex(), playbackMode() -*/ -int QMediaPlaylistNavigator::previousIndex(int steps) const -{ - return d_func()->previousItemPos(steps); -} - -/*! - Advances to the next item in the playlist. - - \sa previous(), jump(), playbackMode() - */ -void QMediaPlaylistNavigator::next() -{ - Q_D(QMediaPlaylistNavigator); - - int nextPos = d->nextItemPos(); - - if ( playbackMode() == QMediaPlaylist::Random ) - d->randomPositionsOffset++; - - jump(nextPos); -} - -/*! - Returns to the previous item in the playlist, - - \sa next(), jump(), playbackMode() - */ -void QMediaPlaylistNavigator::previous() -{ - Q_D(QMediaPlaylistNavigator); - - int prevPos = d->previousItemPos(); - if ( playbackMode() == QMediaPlaylist::Random ) - d->randomPositionsOffset--; - - jump(prevPos); -} - -/*! - Jumps to a new \a position in the playlist. - */ -void QMediaPlaylistNavigator::jump(int position) -{ - Q_D(QMediaPlaylistNavigator); - - if (position<-1 || position>=d->playlist->mediaCount()) { - qWarning() << "QMediaPlaylistNavigator: Jump outside playlist range"; - position = -1; - } - - if (position != -1) - d->lastValidPos = position; - - if (playbackMode() == QMediaPlaylist::Random) { - if (d->randomModePositions[d->randomPositionsOffset] != position) { - d->randomModePositions.clear(); - d->randomModePositions.append(position); - d->randomPositionsOffset = 0; - } - } - - if (position != -1) - d->currentItem = d->playlist->media(position); - else - d->currentItem = QMediaContent(); - - if (position != d->currentPos) { - d->currentPos = position; - emit currentIndexChanged(d->currentPos); - emit surroundingItemsChanged(); - } - - emit activated(d->currentItem); -} - -/*! - \internal -*/ -void QMediaPlaylistNavigatorPrivate::_q_mediaInserted(int start, int end) -{ - Q_Q(QMediaPlaylistNavigator); - - if (currentPos >= start) { - currentPos = end-start+1; - q->jump(currentPos); - } - - //TODO: check if they really changed - emit q->surroundingItemsChanged(); -} - -/*! - \internal -*/ -void QMediaPlaylistNavigatorPrivate::_q_mediaRemoved(int start, int end) -{ - Q_Q(QMediaPlaylistNavigator); - - if (currentPos > end) { - currentPos = currentPos - end-start+1; - q->jump(currentPos); - } else if (currentPos >= start) { - //current item was removed - currentPos = qMin(start, playlist->mediaCount()-1); - q->jump(currentPos); - } - - //TODO: check if they really changed - emit q->surroundingItemsChanged(); -} - -/*! - \internal -*/ -void QMediaPlaylistNavigatorPrivate::_q_mediaChanged(int start, int end) -{ - Q_Q(QMediaPlaylistNavigator); - - if (currentPos >= start && currentPos<=end) { - QMediaContent src = playlist->media(currentPos); - if (src != currentItem) { - currentItem = src; - emit q->activated(src); - } - } - - //TODO: check if they really changed - emit q->surroundingItemsChanged(); -} - -/*! - \fn QMediaPlaylistNavigator::activated(const QMediaContent &media) - - Signals that the current \a media has changed. -*/ - -/*! - \fn QMediaPlaylistNavigator::currentIndexChanged(int position) - - Signals the \a position of the current media has changed. -*/ - -/*! - \fn QMediaPlaylistNavigator::playbackModeChanged(QMediaPlaylist::PlaybackMode mode) - - Signals that the playback \a mode has changed. -*/ - -/*! - \fn QMediaPlaylistNavigator::surroundingItemsChanged() - - Signals that media immediately surrounding the current position has changed. -*/ - -#include "moc_qmediaplaylistnavigator.cpp" - -QT_END_NAMESPACE - diff --git a/src/multimedia/base/qmediaplaylistnavigator.h b/src/multimedia/base/qmediaplaylistnavigator.h deleted file mode 100644 index 73789af..0000000 --- a/src/multimedia/base/qmediaplaylistnavigator.h +++ /dev/null @@ -1,116 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtMultimedia module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QMEDIAPLAYLISTNAVIGATOR_H -#define QMEDIAPLAYLISTNAVIGATOR_H - -#include - -#include -#include - - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Multimedia) - - -class QMediaPlaylistNavigatorPrivate; -class Q_MULTIMEDIA_EXPORT QMediaPlaylistNavigator : public QObject -{ - Q_OBJECT - Q_PROPERTY(QMediaPlaylist::PlaybackMode playbackMode READ playbackMode WRITE setPlaybackMode NOTIFY playbackModeChanged) - Q_PROPERTY(int currentIndex READ currentIndex WRITE jump NOTIFY currentIndexChanged) - Q_PROPERTY(QMediaContent currentItem READ currentItem NOTIFY currentItemChanged) - -public: - QMediaPlaylistNavigator(QMediaPlaylistProvider *playlist, QObject *parent = 0); - virtual ~QMediaPlaylistNavigator(); - - QMediaPlaylistProvider *playlist() const; - void setPlaylist(QMediaPlaylistProvider *playlist); - - QMediaPlaylist::PlaybackMode playbackMode() const; - - QMediaContent currentItem() const; - QMediaContent nextItem(int steps = 1) const; - QMediaContent previousItem(int steps = 1) const; - - QMediaContent itemAt(int position) const; - - int currentIndex() const; - int nextIndex(int steps = 1) const; - int previousIndex(int steps = 1) const; - -public Q_SLOTS: - void next(); - void previous(); - - void jump(int); - - void setPlaybackMode(QMediaPlaylist::PlaybackMode mode); - -Q_SIGNALS: - void activated(const QMediaContent &content); - void currentIndexChanged(int); - void playbackModeChanged(QMediaPlaylist::PlaybackMode mode); - - void surroundingItemsChanged(); - -protected: - QMediaPlaylistNavigatorPrivate *d_ptr; - -private: - Q_DISABLE_COPY(QMediaPlaylistNavigator) - Q_DECLARE_PRIVATE(QMediaPlaylistNavigator) - - Q_PRIVATE_SLOT(d_func(), void _q_mediaInserted(int start, int end)) - Q_PRIVATE_SLOT(d_func(), void _q_mediaRemoved(int start, int end)) - Q_PRIVATE_SLOT(d_func(), void _q_mediaChanged(int start, int end)) -}; - -QT_END_NAMESPACE - -QT_END_HEADER - -#endif // QMEDIAPLAYLISTNAVIGATOR_H diff --git a/src/multimedia/base/qmediaplaylistprovider.cpp b/src/multimedia/base/qmediaplaylistprovider.cpp deleted file mode 100644 index 942f155..0000000 --- a/src/multimedia/base/qmediaplaylistprovider.cpp +++ /dev/null @@ -1,308 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtMultimedia module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include - -#include -#include "qmediaplaylistprovider_p.h" - - -QT_BEGIN_NAMESPACE - -/*! - \class QMediaPlaylistProvider - \preliminary - \since 4.7 - \brief The QMediaPlaylistProvider class provides an abstract list of media. - - \sa QMediaPlaylist -*/ - -/*! - Constructs a playlist provider with the given \a parent. -*/ -QMediaPlaylistProvider::QMediaPlaylistProvider(QObject *parent) - :QObject(parent), d_ptr(new QMediaPlaylistProviderPrivate) -{ -} - -/*! - \internal -*/ -QMediaPlaylistProvider::QMediaPlaylistProvider(QMediaPlaylistProviderPrivate &dd, QObject *parent) - :QObject(parent), d_ptr(&dd) -{ -} - -/*! - Destroys a playlist provider. -*/ -QMediaPlaylistProvider::~QMediaPlaylistProvider() -{ - delete d_ptr; -} - -/*! - \fn QMediaPlaylistProvider::mediaCount() const; - - Returns the size of playlist. -*/ - -/*! - \fn QMediaPlaylistProvider::media(int index) const; - - Returns the media at \a index in the playlist. - - If the index is invalid this will return a null media content. -*/ - - -/*! - Loads a playlist from from a URL \a location. If no playlist \a format is specified the loader - will inspect the URL or probe the headers to guess the format. - - New items are appended to playlist. - - Returns true if the provider supports the format and loading from the locations URL protocol, - otherwise this will return false. -*/ -bool QMediaPlaylistProvider::load(const QUrl &location, const char *format) -{ - Q_UNUSED(location); - Q_UNUSED(format); - return false; -} - -/*! - Loads a playlist from from an I/O \a device. If no playlist \a format is specified the loader - will probe the headers to guess the format. - - New items are appended to playlist. - - Returns true if the provider supports the format and loading from an I/O device, otherwise this - will return false. -*/ -bool QMediaPlaylistProvider::load(QIODevice * device, const char *format) -{ - Q_UNUSED(device); - Q_UNUSED(format); - return false; -} - -/*! - Saves the contents of a playlist to a URL \a location. If no playlist \a format is specified - the writer will inspect the URL to guess the format. - - Returns true if the playlist was saved succesfully; and false otherwise. - */ -bool QMediaPlaylistProvider::save(const QUrl &location, const char *format) -{ - Q_UNUSED(location); - Q_UNUSED(format); - return false; -} - -/*! - Saves the contents of a playlist to an I/O \a device in the specified \a format. - - Returns true if the playlist was saved succesfully; and false otherwise. -*/ -bool QMediaPlaylistProvider::save(QIODevice * device, const char *format) -{ - Q_UNUSED(device); - Q_UNUSED(format); - return false; -} - -/*! - Returns true if a playlist is read-only; otherwise returns false. -*/ -bool QMediaPlaylistProvider::isReadOnly() const -{ - return true; -} - -/*! - Append \a media to a playlist. - - Returns true if the media was appended; and false otherwise. -*/ -bool QMediaPlaylistProvider::addMedia(const QMediaContent &media) -{ - Q_UNUSED(media); - return false; -} - -/*! - Append multiple media \a items to a playlist. - - Returns true if the media items were appended; and false otherwise. -*/ -bool QMediaPlaylistProvider::addMedia(const QList &items) -{ - foreach(const QMediaContent &item, items) { - if (!addMedia(item)) - return false; - } - - return true; -} - -/*! - Inserts \a media into a playlist at \a position. - - Returns true if the media was inserted; and false otherwise. -*/ -bool QMediaPlaylistProvider::insertMedia(int position, const QMediaContent &media) -{ - Q_UNUSED(position); - Q_UNUSED(media); - return false; -} - -/*! - Inserts multiple media \a items into a playlist at \a position. - - Returns true if the media \a items were inserted; and false otherwise. -*/ -bool QMediaPlaylistProvider::insertMedia(int position, const QList &items) -{ - for (int i=0; i - -#include -#include - - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Multimedia) - -class QString; - - -class QMediaPlaylistProviderPrivate; -class Q_MULTIMEDIA_EXPORT QMediaPlaylistProvider : public QObject -{ - Q_OBJECT - -public: - QMediaPlaylistProvider(QObject *parent=0); - virtual ~QMediaPlaylistProvider(); - - virtual bool load(const QUrl &location, const char *format = 0); - virtual bool load(QIODevice * device, const char *format = 0); - virtual bool save(const QUrl &location, const char *format = 0); - virtual bool save(QIODevice * device, const char *format); - - virtual int mediaCount() const = 0; - virtual QMediaContent media(int index) const = 0; - - virtual bool isReadOnly() const; - - virtual bool addMedia(const QMediaContent &content); - virtual bool addMedia(const QList &contentList); - virtual bool insertMedia(int index, const QMediaContent &content); - virtual bool insertMedia(int index, const QList &content); - virtual bool removeMedia(int pos); - virtual bool removeMedia(int start, int end); - virtual bool clear(); - -public Q_SLOTS: - virtual void shuffle(); - -Q_SIGNALS: - void mediaAboutToBeInserted(int start, int end); - void mediaInserted(int start, int end); - - void mediaAboutToBeRemoved(int start, int end); - void mediaRemoved(int start, int end); - - void mediaChanged(int start, int end); - - void loaded(); - void loadFailed(QMediaPlaylist::Error, const QString& errorMessage); - -protected: - QMediaPlaylistProviderPrivate *d_ptr; - QMediaPlaylistProvider(QMediaPlaylistProviderPrivate &dd, QObject *parent); - -private: - Q_DECLARE_PRIVATE(QMediaPlaylistProvider) -}; - -QT_END_NAMESPACE - -QT_END_HEADER - -#endif // QMEDIAPLAYLISTPROVIDER_H diff --git a/src/multimedia/base/qmediaplaylistprovider_p.h b/src/multimedia/base/qmediaplaylistprovider_p.h deleted file mode 100644 index aaf6deb..0000000 --- a/src/multimedia/base/qmediaplaylistprovider_p.h +++ /dev/null @@ -1,75 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtMultimedia module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QMEDIAPLAYLISTPROVIDER_P_H -#define QMEDIAPLAYLISTPROVIDER_P_H - -// -// W A R N I N G -// ------------- -// -// This file is not part of the Qt API. It exists purely as an -// implementation detail. This header file may change from version to -// version without notice, or even be removed. -// -// We mean it. -// - -#include - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -class QMediaPlaylistProviderPrivate -{ -public: - QMediaPlaylistProviderPrivate() - {} - virtual ~QMediaPlaylistProviderPrivate() - {} -}; - -QT_END_NAMESPACE - -QT_END_HEADER - -#endif // QMEDIAPLAYLISTSOURCE_P_H diff --git a/src/multimedia/base/qmediapluginloader.cpp b/src/multimedia/base/qmediapluginloader.cpp deleted file mode 100644 index eaf6218..0000000 --- a/src/multimedia/base/qmediapluginloader.cpp +++ /dev/null @@ -1,135 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtMultimedia module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qmediapluginloader_p.h" -#include -#include -#include -#include - -#include - - -QT_BEGIN_NAMESPACE - - -typedef QMap ObjectListMap; -Q_GLOBAL_STATIC(ObjectListMap, staticMediaPlugins); - -QMediaPluginLoader::QMediaPluginLoader(const char *iid, const QString &location, Qt::CaseSensitivity): - m_iid(iid) -{ - m_location = location + QLatin1String("/"); - load(); -} - -QStringList QMediaPluginLoader::keys() const -{ - return m_instances.keys(); -} - -QObject* QMediaPluginLoader::instance(QString const &key) -{ - return m_instances.value(key); -} - -QList QMediaPluginLoader::instances(QString const &key) -{ - return m_instances.values(key); -} - -//to be used for testing purposes only -void QMediaPluginLoader::setStaticPlugins(const QString &location, const QObjectList& objects) -{ - staticMediaPlugins()->insert(location + QLatin1String("/"), objects); -} - -void QMediaPluginLoader::load() -{ - if (!m_instances.isEmpty()) - return; - - if (staticMediaPlugins() && staticMediaPlugins()->contains(m_location)) { - foreach(QObject *o, staticMediaPlugins()->value(m_location)) { - if (o != 0 && o->qt_metacast(m_iid) != 0) { - QFactoryInterface* p = qobject_cast(o); - if (p != 0) { - foreach (QString const &key, p->keys()) - m_instances.insertMulti(key, o); - } - } - } - } else { -#ifndef QT_NO_LIBRARY - QStringList paths = QCoreApplication::libraryPaths(); - - foreach (QString const &path, paths) { - QString pluginPathName(path + m_location); - QDir pluginDir(pluginPathName); - - if (!pluginDir.exists()) - continue; - - foreach (QString pluginLib, pluginDir.entryList(QDir::Files)) { - QPluginLoader loader(pluginPathName + pluginLib); - - QObject *o = loader.instance(); - if (o != 0 && o->qt_metacast(m_iid) != 0) { - QFactoryInterface* p = qobject_cast(o); - if (p != 0) { - foreach (QString const &key, p->keys()) - m_instances.insertMulti(key, o); - } - - continue; - } else { - qWarning() << "QMediaPluginLoader: Failed to load plugin: " << pluginLib << loader.errorString(); - } - delete o; - loader.unload(); - } - } -#endif - } -} - -QT_END_NAMESPACE - diff --git a/src/multimedia/base/qmediapluginloader_p.h b/src/multimedia/base/qmediapluginloader_p.h deleted file mode 100644 index 351d2f1..0000000 --- a/src/multimedia/base/qmediapluginloader_p.h +++ /dev/null @@ -1,92 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtMultimedia module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QMEDIAPLUGINLOADER_H -#define QMEDIAPLUGINLOADER_H - -// -// W A R N I N G -// ------------- -// -// This file is not part of the Qt API. It exists purely as an -// implementation detail. This header file may change from version to -// version without notice, or even be removed. -// -// We mean it. -// - -#include -#include -#include - - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -class QMediaServiceProviderPlugin; - -class Q_AUTOTEST_EXPORT QMediaPluginLoader -{ -public: - QMediaPluginLoader(const char *iid, - const QString &suffix = QString(), - Qt::CaseSensitivity = Qt::CaseSensitive); - - QStringList keys() const; - QObject* instance(QString const &key); - QList instances(QString const &key); - - static void setStaticPlugins(const QString &location, const QObjectList& objects); - -private: - void load(); - - QByteArray m_iid; - QString m_location; - QMap m_instances; -}; - -QT_END_NAMESPACE - -QT_END_HEADER - -#endif // QMEDIAPLUGINLOADER_H diff --git a/src/multimedia/base/qmediaresource.cpp b/src/multimedia/base/qmediaresource.cpp deleted file mode 100644 index 646d9a7..0000000 --- a/src/multimedia/base/qmediaresource.cpp +++ /dev/null @@ -1,399 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtMultimedia module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include -#include -#include - -#include - - -QT_BEGIN_NAMESPACE - -/*! - \class QMediaResource - \preliminary - \since 4.7 - \brief The QMediaResource class provides a description of a media resource. - \ingroup multimedia - - A media resource is composed of a \l {url()}{URL} containing the - location of the resource and a set of properties that describe the - format of the resource. The properties provide a means to assess a - resource without first attempting to load it, and in situations where - media be represented by multiple alternative representations provide a - means to select the appropriate resource. - - Media made available by a remote services can often be available in - multiple encodings or quality levels, this allows a client to select - an appropriate resource based on considerations such as codecs supported, - network bandwidth, and display constraints. QMediaResource includes - information such as the \l {mimeType()}{MIME type}, \l {audioCodec()}{audio} - and \l {videoCodec()}{video} codecs, \l {audioBitRate()}{audio} and - \l {videoBitRate()}{video} bit rates, and \l {resolution()}{resolution} - so these constraints and others can be evaluated. - - The only mandatory property of a QMediaResource is the url(). - - \sa QMediaContent -*/ - -/*! - \typedef QMediaResourceList - - Synonym for \c QList -*/ - -/*! - Constructs a null media resource. -*/ -QMediaResource::QMediaResource() -{ -} - -/*! - Constructs a media resource with the given \a mimeType from a \a url. -*/ -QMediaResource::QMediaResource(const QUrl &url, const QString &mimeType) -{ - values.insert(Url, url); - values.insert(MimeType, mimeType); -} - -/*! - Constructs a media resource with the given \a mimeType from a network \a request. -*/ -QMediaResource::QMediaResource(const QNetworkRequest &request, const QString &mimeType) -{ - values.insert(Request, QVariant::fromValue(request)); - values.insert(Url, request.url()); - values.insert(MimeType, mimeType); -} - -/*! - Constructs a copy of a media resource \a other. -*/ -QMediaResource::QMediaResource(const QMediaResource &other) - : values(other.values) -{ -} - -/*! - Assigns the value of \a other to a media resource. -*/ -QMediaResource &QMediaResource::operator =(const QMediaResource &other) -{ - values = other.values; - - return *this; -} - -/*! - Destroys a media resource. -*/ -QMediaResource::~QMediaResource() -{ -} - - -/*! - Compares a media resource to \a other. - - Returns true if the resources are identical, and false otherwise. -*/ -bool QMediaResource::operator ==(const QMediaResource &other) const -{ - return values == other.values; -} - -/*! - Compares a media resource to \a other. - - Returns true if they are different, and false otherwise. -*/ -bool QMediaResource::operator !=(const QMediaResource &other) const -{ - return values != other.values; -} - -/*! - Identifies if a media resource is null. - - Returns true if the resource is null, and false otherwise. -*/ -bool QMediaResource::isNull() const -{ - return values.isEmpty(); -} - -/*! - Returns the URL of a media resource. -*/ -QUrl QMediaResource::url() const -{ - return qvariant_cast(values.value(Url)); -} - -/*! - Returns the network request associated with this media resource. -*/ -QNetworkRequest QMediaResource::request() const -{ - if(values.contains(Request)) - return qvariant_cast(values.value(Request)); - - return QNetworkRequest(url()); -} - -/*! - Returns the MIME type of a media resource. - - This may be null if the MIME type is unknown. -*/ -QString QMediaResource::mimeType() const -{ - return qvariant_cast(values.value(MimeType)); -} - -/*! - Returns the language of a media resource as an ISO 639-2 code. - - This may be null if the language is unknown. -*/ -QString QMediaResource::language() const -{ - return qvariant_cast(values.value(Language)); -} - -/*! - Sets the \a language of a media resource. -*/ -void QMediaResource::setLanguage(const QString &language) -{ - if (!language.isNull()) - values.insert(Language, language); - else - values.remove(Language); -} - -/*! - Returns the audio codec of a media resource. - - This may be null if the media resource does not contain an audio stream, or the codec is - unknown. -*/ -QString QMediaResource::audioCodec() const -{ - return qvariant_cast(values.value(AudioCodec)); -} - -/*! - Sets the audio \a codec of a media resource. -*/ -void QMediaResource::setAudioCodec(const QString &codec) -{ - if (!codec.isNull()) - values.insert(AudioCodec, codec); - else - values.remove(AudioCodec); -} - -/*! - Returns the video codec of a media resource. - - This may be null if the media resource does not contain a video stream, or the codec is - unknonwn. -*/ -QString QMediaResource::videoCodec() const -{ - return qvariant_cast(values.value(VideoCodec)); -} - -/*! - Sets the video \a codec of media resource. -*/ -void QMediaResource::setVideoCodec(const QString &codec) -{ - if (!codec.isNull()) - values.insert(VideoCodec, codec); - else - values.remove(VideoCodec); -} - -/*! - Returns the size in bytes of a media resource. - - This may be zero if the size is unknown. -*/ -qint64 QMediaResource::dataSize() const -{ - return qvariant_cast(values.value(DataSize)); -} - -/*! - Sets the \a size in bytes of a media resource. -*/ -void QMediaResource::setDataSize(const qint64 size) -{ - if (size != 0) - values.insert(DataSize, size); - else - values.remove(DataSize); -} - -/*! - Returns the bit rate in bits per second of a media resource's audio stream. - - This may be zero if the bit rate is unknown, or the resource contains no audio stream. -*/ -int QMediaResource::audioBitRate() const -{ - return values.value(AudioBitRate).toInt(); -} - -/*! - Sets the bit \a rate in bits per second of a media resource's video stream. -*/ -void QMediaResource::setAudioBitRate(int rate) -{ - if (rate != 0) - values.insert(AudioBitRate, rate); - else - values.remove(AudioBitRate); -} - -/*! - Returns the audio sample rate of a media resource. - - This may be zero if the sample size is unknown, or the resource contains no audio stream. -*/ -int QMediaResource::sampleRate() const -{ - return qvariant_cast(values.value(SampleRate)); -} - -/*! - Sets the audio \a sampleRate of a media resource. -*/ -void QMediaResource::setSampleRate(int sampleRate) -{ - if (sampleRate != 0) - values.insert(SampleRate, sampleRate); - else - values.remove(SampleRate); -} - -/*! - Returns the number of audio channels in a media resource. - - This may be zero if the sample size is unknown, or the resource contains no audio stream. -*/ -int QMediaResource::channelCount() const -{ - return qvariant_cast(values.value(ChannelCount)); -} - -/*! - Sets the number of audio \a channels in a media resource. -*/ -void QMediaResource::setChannelCount(int channels) -{ - if (channels != 0) - values.insert(ChannelCount, channels); - else - values.remove(ChannelCount); -} - -/*! - Returns the bit rate in bits per second of a media resource's video stream. - - This may be zero if the bit rate is unknown, or the resource contains no video stream. -*/ -int QMediaResource::videoBitRate() const -{ - return values.value(VideoBitRate).toInt(); -} - -/*! - Sets the bit \a rate in bits per second of a media resource's video stream. -*/ -void QMediaResource::setVideoBitRate(int rate) -{ - if (rate != 0) - values.insert(VideoBitRate, rate); - else - values.remove(VideoBitRate); -} - -/*! - Returns the resolution in pixels of a media resource. - - This may be null is the resolution is unknown, or the resource contains no pixel data (i.e. the - resource is an audio stream. -*/ -QSize QMediaResource::resolution() const -{ - return qvariant_cast(values.value(Resolution)); -} - -/*! - Sets the \a resolution in pixels of a media resource. -*/ -void QMediaResource::setResolution(const QSize &resolution) -{ - if (resolution.width() != -1 || resolution.height() != -1) - values.insert(Resolution, resolution); - else - values.remove(Resolution); -} - -/*! - Sets the \a width and \a height in pixels of a media resource. -*/ -void QMediaResource::setResolution(int width, int height) -{ - if (width != -1 || height != -1) - values.insert(Resolution, QSize(width, height)); - else - values.remove(Resolution); -} -QT_END_NAMESPACE - diff --git a/src/multimedia/base/qmediaresource.h b/src/multimedia/base/qmediaresource.h deleted file mode 100644 index a535bbd..0000000 --- a/src/multimedia/base/qmediaresource.h +++ /dev/null @@ -1,134 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtMultimedia module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QMEDIARESOURCE_H -#define QMEDIARESOURCE_H - -#include -#include -#include - - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Multimedia) - - -class Q_MULTIMEDIA_EXPORT QMediaResource -{ -public: - QMediaResource(); - QMediaResource(const QUrl &url, const QString &mimeType = QString()); - QMediaResource(const QNetworkRequest &request, const QString &mimeType = QString()); - QMediaResource(const QMediaResource &other); - QMediaResource &operator =(const QMediaResource &other); - ~QMediaResource(); - - bool isNull() const; - - bool operator ==(const QMediaResource &other) const; - bool operator !=(const QMediaResource &other) const; - - QUrl url() const; - QNetworkRequest request() const; - QString mimeType() const; - - QString language() const; - void setLanguage(const QString &language); - - QString audioCodec() const; - void setAudioCodec(const QString &codec); - - QString videoCodec() const; - void setVideoCodec(const QString &codec); - - qint64 dataSize() const; - void setDataSize(const qint64 size); - - int audioBitRate() const; - void setAudioBitRate(int rate); - - int sampleRate() const; - void setSampleRate(int frequency); - - int channelCount() const; - void setChannelCount(int channels); - - int videoBitRate() const; - void setVideoBitRate(int rate); - - QSize resolution() const; - void setResolution(const QSize &resolution); - void setResolution(int width, int height); - - -private: - enum Property - { - Url, - Request, - MimeType, - Language, - AudioCodec, - VideoCodec, - DataSize, - AudioBitRate, - VideoBitRate, - SampleRate, - ChannelCount, - Resolution - }; - QMap values; -}; - -typedef QList QMediaResourceList; - -QT_END_NAMESPACE - -Q_DECLARE_METATYPE(QMediaResource) -Q_DECLARE_METATYPE(QMediaResourceList) - -QT_END_HEADER - - -#endif diff --git a/src/multimedia/base/qmediaservice.cpp b/src/multimedia/base/qmediaservice.cpp deleted file mode 100644 index d9e980b..0000000 --- a/src/multimedia/base/qmediaservice.cpp +++ /dev/null @@ -1,140 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtMultimedia module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include - -#include -#include "qmediaservice_p.h" - - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Multimedia) - -/*! - \class QMediaService - \brief The QMediaService class provides a common base class for media - service implementations. - \ingroup multimedia-serv - \preliminary - \since 4.7 - - Media services provide implementations of the functionality promised - by media objects, and allow multiple providers to implement a QMediaObject. - - To provide the functionality of a QMediaObject media services implement - QMediaControl interfaces. Services typically implement one core media - control which provides the core feature of a media object, and some - number of additional controls which provide either optional features of - the media object, or features of a secondary media object or peripheral - object. - - A pointer to media service's QMediaControl implementation can be - obtained by passing the control's interface name to the control() function. - - \code - QMediaPlayerControl *control = qobject_cast( - service->control("com.nokia.Qt.QMediaPlayerControl/1.0")); - \endcode - - Media objects can use services loaded dynamically from plug-ins or - implemented statically within an applications. Plug-in based services - should also implement the QMediaServiceProviderPlugin interface. Static - services should implement the QMediaServiceProvider interface. - - \sa QMediaObject, QMediaControl, QMediaServiceProvider, QMediaServiceProviderPlugin -*/ - -/*! - Construct a media service with the given \a parent. This class is meant as a - base class for Multimedia services so this constructor is protected. -*/ - -QMediaService::QMediaService(QObject *parent) - : QObject(parent) - , d_ptr(new QMediaServicePrivate) -{ - d_ptr->q_ptr = this; -} - -/*! - \internal -*/ -QMediaService::QMediaService(QMediaServicePrivate &dd, QObject *parent) - : QObject(parent) - , d_ptr(&dd) -{ - d_ptr->q_ptr = this; -} - -/*! - Destroys a media service. -*/ - -QMediaService::~QMediaService() -{ - delete d_ptr; -} - -/*! - \fn QMediaService::control(const char *interface) const - - Returns a pointer to the media control implementing \a interface. - - If the service does not implement the control a null pointer is returned instead. -*/ - -/*! - \fn QMediaService::control() const - - Returns a pointer to the media control of type T implemented by a media service. - - If the service does not implment the control a null pointer is returned instead. -*/ - -#include "moc_qmediaservice.cpp" - -QT_END_NAMESPACE - -QT_END_HEADER - diff --git a/src/multimedia/base/qmediaservice.h b/src/multimedia/base/qmediaservice.h deleted file mode 100644 index c53a15f..0000000 --- a/src/multimedia/base/qmediaservice.h +++ /dev/null @@ -1,90 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtMultimedia module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QABSTRACTMEDIASERVICE_H -#define QABSTRACTMEDIASERVICE_H - -#include -#include - -#include - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Multimedia) - -class QMediaServicePrivate; -class Q_MULTIMEDIA_EXPORT QMediaService : public QObject -{ - Q_OBJECT - -public: - ~QMediaService(); - - virtual QMediaControl* control(const char *name) const = 0; - -#ifndef QT_NO_MEMBER_TEMPLATES - template inline T control() const { - if (QObject *object = control(qmediacontrol_iid())) { - return qobject_cast(object); - } - return 0; - } -#endif - -protected: - QMediaService(QObject* parent); - QMediaService(QMediaServicePrivate &dd, QObject *parent); - - QMediaServicePrivate *d_ptr; - -private: - Q_DECLARE_PRIVATE(QMediaService) -}; - -QT_END_NAMESPACE - -QT_END_HEADER - -#endif // QABSTRACTMEDIASERVICE_H - diff --git a/src/multimedia/base/qmediaservice_p.h b/src/multimedia/base/qmediaservice_p.h deleted file mode 100644 index 7dbcd8a..0000000 --- a/src/multimedia/base/qmediaservice_p.h +++ /dev/null @@ -1,75 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtMultimedia module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QABSTRACTMEDIASERVICE_P_H -#define QABSTRACTMEDIASERVICE_P_H - -// -// W A R N I N G -// ------------- -// -// This file is not part of the Qt API. It exists purely as an -// implementation detail. This header file may change from version to -// version without notice, or even be removed. -// -// We mean it. -// - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -class QAudioDeviceControl; - -class QMediaServicePrivate -{ -public: - QMediaServicePrivate(): q_ptr(0) {} - virtual ~QMediaServicePrivate() {} - - QMediaService *q_ptr; -}; - -QT_END_NAMESPACE - -QT_END_HEADER - -#endif diff --git a/src/multimedia/base/qmediaserviceprovider.cpp b/src/multimedia/base/qmediaserviceprovider.cpp deleted file mode 100644 index b089b39..0000000 --- a/src/multimedia/base/qmediaserviceprovider.cpp +++ /dev/null @@ -1,738 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtMultimedia module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include -#include - -#include -#include -#include -#include "qmediapluginloader_p.h" -#include - -QT_BEGIN_NAMESPACE - -class QMediaServiceProviderHintPrivate : public QSharedData -{ -public: - QMediaServiceProviderHintPrivate(QMediaServiceProviderHint::Type type) - :type(type), features(0) - { - } - - QMediaServiceProviderHintPrivate(const QMediaServiceProviderHintPrivate &other) - :QSharedData(other), - type(other.type), - device(other.device), - mimeType(other.mimeType), - codecs(other.codecs), - features(other.features) - { - } - - ~QMediaServiceProviderHintPrivate() - { - } - - QMediaServiceProviderHint::Type type; - QByteArray device; - QString mimeType; - QStringList codecs; - QMediaServiceProviderHint::Features features; -}; - -/*! - \class QMediaServiceProviderHint - \preliminary - \since 4.7 - \brief The QMediaServiceProviderHint class describes what is required of a QMediaService. - - \ingroup multimedia-serv - - The QMediaServiceProvider class uses hints to select an appropriate media service. -*/ - -/*! - \enum QMediaServiceProviderHint::Feature - - Enumerates features a media service may provide. - - \value LowLatencyPlayback - The service is expected to play simple audio formats, - but playback should start without significant delay. - Such playback service can be used for beeps, ringtones, etc. - - \value RecordingSupport - The service provides audio or video recording functions. - - \value StreamPlayback - The service is capable of playing QIODevice based streams. -*/ - -/*! - \enum QMediaServiceProviderHint::Type - - Enumerates the possible types of media service provider hint. - - \value Null En empty hint, use the default service. - \value ContentType Select media service most suitable for certain content type. - \value Device Select media service which supports certain device. - \value SupportedFeatures Select media service supporting the set of optional features. -*/ - - -/*! - Constructs an empty media service provider hint. -*/ -QMediaServiceProviderHint::QMediaServiceProviderHint() - :d(new QMediaServiceProviderHintPrivate(Null)) -{ -} - -/*! - Constructs a ContentType media service provider hint. - - This type of hint describes a service that is able to play content of a specific MIME \a type - encoded with one or more of the listed \a codecs. -*/ -QMediaServiceProviderHint::QMediaServiceProviderHint(const QString &type, const QStringList& codecs) - :d(new QMediaServiceProviderHintPrivate(ContentType)) -{ - d->mimeType = type; - d->codecs = codecs; -} - -/*! - Constructs a Device media service provider hint. - - This type of hint describes a media service that utilizes a specific \a device. -*/ -QMediaServiceProviderHint::QMediaServiceProviderHint(const QByteArray &device) - :d(new QMediaServiceProviderHintPrivate(Device)) -{ - d->device = device; -} - -/*! - Constructs a SupportedFeatures media service provider hint. - - This type of hint describes a service which supports a specific set of \a features. -*/ -QMediaServiceProviderHint::QMediaServiceProviderHint(QMediaServiceProviderHint::Features features) - :d(new QMediaServiceProviderHintPrivate(SupportedFeatures)) -{ - d->features = features; -} - -/*! - Constructs a copy of the media service provider hint \a other. -*/ -QMediaServiceProviderHint::QMediaServiceProviderHint(const QMediaServiceProviderHint &other) - :d(other.d) -{ -} - -/*! - Destroys a media service provider hint. -*/ -QMediaServiceProviderHint::~QMediaServiceProviderHint() -{ -} - -/*! - Assigns the value \a other to a media service provider hint. -*/ -QMediaServiceProviderHint& QMediaServiceProviderHint::operator=(const QMediaServiceProviderHint &other) -{ - d = other.d; - return *this; -} - -/*! - Identifies if \a other is of equal value to a media service provider hint. - - Returns true if the hints are equal, and false if they are not. -*/ -bool QMediaServiceProviderHint::operator == (const QMediaServiceProviderHint &other) const -{ - return (d == other.d) || - (d->type == other.d->type && - d->device == other.d->device && - d->mimeType == other.d->mimeType && - d->codecs == other.d->codecs && - d->features == other.d->features); -} - -/*! - Identifies if \a other is not of equal value to a media service provider hint. - - Returns true if the hints are not equal, and false if they are. -*/ -bool QMediaServiceProviderHint::operator != (const QMediaServiceProviderHint &other) const -{ - return !(*this == other); -} - -/*! - Returns true if a media service provider is null. -*/ -bool QMediaServiceProviderHint::isNull() const -{ - return d->type == Null; -} - -/*! - Returns the type of a media service provider hint. -*/ -QMediaServiceProviderHint::Type QMediaServiceProviderHint::type() const -{ - return d->type; -} - -/*! - Returns the mime type of the media a service is expected to be able play. -*/ -QString QMediaServiceProviderHint::mimeType() const -{ - return d->mimeType; -} - -/*! - Returns a list of codes a media service is expected to be able to decode. -*/ -QStringList QMediaServiceProviderHint::codecs() const -{ - return d->codecs; -} - -/*! - Returns the name of a device a media service is expected to utilize. -*/ -QByteArray QMediaServiceProviderHint::device() const -{ - return d->device; -} - -/*! - Returns a set of features a media service is expected to provide. -*/ -QMediaServiceProviderHint::Features QMediaServiceProviderHint::features() const -{ - return d->features; -} - - -Q_GLOBAL_STATIC_WITH_ARGS(QMediaPluginLoader, loader, - (QMediaServiceProviderFactoryInterface_iid, QLatin1String("/mediaservices"), Qt::CaseInsensitive)) - - -class QPluginServiceProvider : public QMediaServiceProvider -{ - QMap pluginMap; - -public: - QMediaService* requestService(const QByteArray &type, const QMediaServiceProviderHint &hint) - { - QString key(QString::fromLatin1(type.constData(),type.length())); - - QListplugins; - foreach (QObject *obj, loader()->instances(key)) { - QMediaServiceProviderPlugin *plugin = - qobject_cast(obj); - if (plugin) - plugins << plugin; - } - - if (!plugins.isEmpty()) { - QMediaServiceProviderPlugin *plugin = 0; - - switch (hint.type()) { - case QMediaServiceProviderHint::Null: - plugin = plugins[0]; - //special case for media player, if low latency was not asked, - //prefer services not offering it, since they are likely to support - //more formats - if (type == QByteArray(Q_MEDIASERVICE_MEDIAPLAYER)) { - foreach (QMediaServiceProviderPlugin *currentPlugin, plugins) { - QMediaServiceFeaturesInterface *iface = - qobject_cast(currentPlugin); - - if (!iface || !(iface->supportedFeatures(type) & - QMediaServiceProviderHint::LowLatencyPlayback)) { - plugin = currentPlugin; - break; - } - - } - } - break; - case QMediaServiceProviderHint::SupportedFeatures: - plugin = plugins[0]; - foreach (QMediaServiceProviderPlugin *currentPlugin, plugins) { - QMediaServiceFeaturesInterface *iface = - qobject_cast(currentPlugin); - - if (iface) { - if ((iface->supportedFeatures(type) & hint.features()) == hint.features()) { - plugin = currentPlugin; - break; - } - } - } - break; - case QMediaServiceProviderHint::Device: { - foreach (QMediaServiceProviderPlugin *currentPlugin, plugins) { - QMediaServiceSupportedDevicesInterface *iface = - qobject_cast(currentPlugin); - - if (!iface) { - // the plugin may support the device, - // but this choice still can be overridden - plugin = currentPlugin; - } else { - if (iface->devices(type).contains(hint.device())) { - plugin = currentPlugin; - break; - } - } - } - } - break; - case QMediaServiceProviderHint::ContentType: { - QtMultimedia::SupportEstimate estimate = QtMultimedia::NotSupported; - foreach (QMediaServiceProviderPlugin *currentPlugin, plugins) { - QtMultimedia::SupportEstimate currentEstimate = QtMultimedia::MaybeSupported; - QMediaServiceSupportedFormatsInterface *iface = - qobject_cast(currentPlugin); - - if (iface) - currentEstimate = iface->hasSupport(hint.mimeType(), hint.codecs()); - - if (currentEstimate > estimate) { - estimate = currentEstimate; - plugin = currentPlugin; - - if (currentEstimate == QtMultimedia::PreferredService) - break; - } - } - } - break; - } - - if (plugin != 0) { - QMediaService *service = plugin->create(key); - if (service != 0) - pluginMap.insert(service, plugin); - - return service; - } - } - - qWarning() << "defaultServiceProvider::requestService(): no service found for -" << key; - return 0; - } - - void releaseService(QMediaService *service) - { - if (service != 0) { - QMediaServiceProviderPlugin *plugin = pluginMap.take(service); - - if (plugin != 0) - plugin->release(service); - } - } - - QtMultimedia::SupportEstimate hasSupport(const QByteArray &serviceType, - const QString &mimeType, - const QStringList& codecs, - int flags) const - { - QList instances = loader()->instances( - QString::fromLatin1(serviceType.constData(),serviceType.length())); - - if (instances.isEmpty()) - return QtMultimedia::NotSupported; - - bool allServicesProvideInterface = true; - QtMultimedia::SupportEstimate supportEstimate = QtMultimedia::NotSupported; - - foreach(QObject *obj, instances) { - QMediaServiceSupportedFormatsInterface *iface = - qobject_cast(obj); - - - if (flags) { - QMediaServiceFeaturesInterface *iface = - qobject_cast(obj); - - if (iface) { - QMediaServiceProviderHint::Features features = iface->supportedFeatures(serviceType); - - //if low latency playback was asked, skip services known - //not to provide low latency playback - if ((flags & QMediaPlayer::LowLatency) && - !(features & QMediaServiceProviderHint::LowLatencyPlayback)) - continue; - - //the same for QIODevice based streams support - if ((flags & QMediaPlayer::StreamPlayback) && - !(features & QMediaServiceProviderHint::StreamPlayback)) - continue; - } - } - - if (iface) - supportEstimate = qMax(supportEstimate, iface->hasSupport(mimeType, codecs)); - else - allServicesProvideInterface = false; - } - - //don't return PreferredService - supportEstimate = qMin(supportEstimate, QtMultimedia::ProbablySupported); - - //Return NotSupported only if no services are available of serviceType - //or all the services returned NotSupported, otherwise return at least MaybeSupported - if (!allServicesProvideInterface) - supportEstimate = qMax(QtMultimedia::MaybeSupported, supportEstimate); - - return supportEstimate; - } - - QStringList supportedMimeTypes(const QByteArray &serviceType, int flags) const - { - QList instances = loader()->instances( - QString::fromLatin1(serviceType.constData(),serviceType.length())); - - QStringList supportedTypes; - - foreach(QObject *obj, instances) { - QMediaServiceSupportedFormatsInterface *iface = - qobject_cast(obj); - - - if (flags & QMediaPlayer::LowLatency) { - QMediaServiceFeaturesInterface *iface = - qobject_cast(obj); - - if (iface) { - QMediaServiceProviderHint::Features features = iface->supportedFeatures(serviceType); - - // If low latency playback was asked for, skip MIME types from services known - // not to provide low latency playback - if ((flags & QMediaPlayer::LowLatency) && - !(features & QMediaServiceProviderHint::LowLatencyPlayback)) - continue; - - //the same for QIODevice based streams support - if ((flags & QMediaPlayer::StreamPlayback) && - !(features & QMediaServiceProviderHint::StreamPlayback)) - continue; - } - } - - if (iface) { - supportedTypes << iface->supportedMimeTypes(); - } - } - - // Multiple services may support the same MIME type - supportedTypes.removeDuplicates(); - - return supportedTypes; - } - - QList devices(const QByteArray &serviceType) const - { - QList res; - - foreach(QObject *obj, loader()->instances( - QString::fromLatin1(serviceType.constData(),serviceType.length()))) { - QMediaServiceSupportedDevicesInterface *iface = - qobject_cast(obj); - - if (iface) { - res.append(iface->devices(serviceType)); - } - } - - return res; - } - - QString deviceDescription(const QByteArray &serviceType, const QByteArray &device) - { - foreach(QObject *obj, loader()->instances( - QString::fromLatin1(serviceType.constData(),serviceType.length()))) { - QMediaServiceSupportedDevicesInterface *iface = - qobject_cast(obj); - - if (iface) { - if (iface->devices(serviceType).contains(device)) - return iface->deviceDescription(serviceType, device); - } - } - - return QString(); - } -}; - -Q_GLOBAL_STATIC(QPluginServiceProvider, pluginProvider); - -/*! - \class QMediaServiceProvider - \preliminary - \since 4.7 - \brief The QMediaServiceProvider class provides an abstract allocator for media services. -*/ - -/*! - \fn QMediaServiceProvider::requestService(const QByteArray &type, const QMediaServiceProviderHint &hint) - - Requests an instance of a \a type service which best matches the given \a hint. - - Returns a pointer to the requested service, or a null pointer if there is no suitable service. - - The returned service must be released with releaseService when it is finished with. -*/ - -/*! - \fn QMediaServiceProvider::releaseService(QMediaService *service) - - Releases a media \a service requested with requestService(). -*/ - -/*! - \fn QtMultimedia::SupportEstimate QMediaServiceProvider::hasSupport(const QByteArray &serviceType, const QString &mimeType, const QStringList& codecs, int flags) const - - Returns how confident a media service provider is that is can provide a \a serviceType - service that is able to play media of a specific \a mimeType that is encoded using the listed - \a codecs while adhearing to constraints identified in \a flags. -*/ -QtMultimedia::SupportEstimate QMediaServiceProvider::hasSupport(const QByteArray &serviceType, - const QString &mimeType, - const QStringList& codecs, - int flags) const -{ - Q_UNUSED(serviceType); - Q_UNUSED(mimeType); - Q_UNUSED(codecs); - Q_UNUSED(flags); - - return QtMultimedia::MaybeSupported; -} - -/*! - \fn QStringList QMediaServiceProvider::supportedMimeTypes(const QByteArray &serviceType, int flags) const - - Returns a list of MIME types supported by the service provider for the specified \a serviceType. - - The resultant list is restricted to MIME types which can be supported given the constraints in \a flags. -*/ -QStringList QMediaServiceProvider::supportedMimeTypes(const QByteArray &serviceType, int flags) const -{ - Q_UNUSED(serviceType); - Q_UNUSED(flags); - - return QStringList(); -} - -/*! - Returns the list of devices related to \a service type. -*/ -QList QMediaServiceProvider::devices(const QByteArray &service) const -{ - Q_UNUSED(service); - return QList(); -} - -/*! - Returns the description of \a device related to \a serviceType, - suitable to be displayed to user. -*/ -QString QMediaServiceProvider::deviceDescription(const QByteArray &serviceType, const QByteArray &device) -{ - Q_UNUSED(serviceType); - Q_UNUSED(device); - return QString(); -} - - -#ifdef QT_BUILD_INTERNAL - -static QMediaServiceProvider *qt_defaultMediaServiceProvider = 0; - -/*! - Sets a media service \a provider as the default. - - \internal -*/ -void QMediaServiceProvider::setDefaultServiceProvider(QMediaServiceProvider *provider) -{ - qt_defaultMediaServiceProvider = provider; -} - -#endif - -/*! - Returns a default provider of media services. -*/ -QMediaServiceProvider *QMediaServiceProvider::defaultServiceProvider() -{ -#ifdef QT_BUILD_INTERNAL - return qt_defaultMediaServiceProvider != 0 - ? qt_defaultMediaServiceProvider - : static_cast(pluginProvider()); -#else - return pluginProvider(); -#endif -} - -/*! - \class QMediaServiceProviderPlugin - \preliminary - \since 4.7 - \brief The QMediaServiceProviderPlugin class interface provides an interface for QMediaService - plug-ins. - - A media service provider plug-in may implement one or more of - QMediaServiceSupportedFormatsInterface, QMediaServiceSupportedDevicesInterface, - and QMediaServiceFeaturesInterface to identify the features it supports. -*/ - -/*! - \fn QMediaServiceProviderPlugin::keys() const - - Returns a list of keys for media services a plug-in can create. -*/ - -/*! - \fn QMediaServiceProviderPlugin::create(const QString &key) - - Constructs a new instance of the QMediaService identified by \a key. - - The QMediaService returned must be destroyed with release(). -*/ - -/*! - \fn QMediaServiceProviderPlugin::release(QMediaService *service) - - Destroys a media \a service constructed with create(). -*/ - - -/*! - \class QMediaServiceSupportedFormatsInterface - \brief The QMediaServiceSupportedFormatsInterface class interface - identifies if a media service plug-in supports a media format. - \since 4.7 - - A QMediaServiceProviderPlugin may implement this interface. -*/ - -/*! - \fn QMediaServiceSupportedFormatsInterface::~QMediaServiceSupportedFormatsInterface() - - Destroys a media service supported formats interface. -*/ - -/*! - \fn QMediaServiceSupportedFormatsInterface::hasSupport(const QString &mimeType, const QStringList& codecs) const - - Returns the level of support a media service plug-in has for a \a mimeType and set of \a codecs. -*/ - -/*! - \fn QMediaServiceSupportedFormatsInterface::supportedMimeTypes() const - - Returns a list of MIME types supported by the media service plug-in. -*/ - -/*! - \class QMediaServiceSupportedDevicesInterface - \brief The QMediaServiceSupportedDevicesInterface class interface - identifies the devices supported by a media service plug-in. - \since 4.7 - - A QMediaServiceProviderPlugin may implement this interface. -*/ - -/*! - \fn QMediaServiceSupportedDevicesInterface::~QMediaServiceSupportedDevicesInterface() - - Destroys a media service supported devices interface. -*/ - -/*! - \fn QMediaServiceSupportedDevicesInterface::devices(const QByteArray &service) const - - Returns a list of devices supported by a plug-in \a service. -*/ - -/*! - \fn QMediaServiceSupportedDevicesInterface::deviceDescription(const QByteArray &service, const QByteArray &device) - - Returns a description of a \a device supported by a plug-in \a service. -*/ - -/*! - \class QMediaServiceFeaturesInterface - \brief The QMediaServiceFeaturesInterface class interface identifies - features supported by a media service plug-in. - \since 4.7 - - A QMediaServiceProviderPlugin may implement this interface. -*/ - -/*! - \fn QMediaServiceFeaturesInterface::~QMediaServiceFeaturesInterface() - - Destroys a media service features interface. -*/ -/*! - \fn QMediaServiceFeaturesInterface::supportedFeatures(const QByteArray &service) const - - Returns a set of features supported by a plug-in \a service. -*/ - -QT_END_NAMESPACE - -#include "moc_qmediaserviceprovider.cpp" -#include "moc_qmediaserviceproviderplugin.cpp" diff --git a/src/multimedia/base/qmediaserviceprovider.h b/src/multimedia/base/qmediaserviceprovider.h deleted file mode 100644 index 6e31493..0000000 --- a/src/multimedia/base/qmediaserviceprovider.h +++ /dev/null @@ -1,174 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtMultimedia module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QMEDIASERVICEPROVIDER_H -#define QMEDIASERVICEPROVIDER_H - -#include -#include - -#include - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Multimedia) - - -class QMediaService; - -class QMediaServiceProviderHintPrivate; -class Q_MULTIMEDIA_EXPORT QMediaServiceProviderHint -{ -public: - enum Type { Null, ContentType, Device, SupportedFeatures }; - - enum Feature { - LowLatencyPlayback = 0x01, - RecordingSupport = 0x02, - StreamPlayback = 0x04 - }; - Q_DECLARE_FLAGS(Features, Feature) - - QMediaServiceProviderHint(); - QMediaServiceProviderHint(const QString &mimeType, const QStringList& codecs); - QMediaServiceProviderHint(const QByteArray &device); - QMediaServiceProviderHint(Features features); - QMediaServiceProviderHint(const QMediaServiceProviderHint &other); - ~QMediaServiceProviderHint(); - - QMediaServiceProviderHint& operator=(const QMediaServiceProviderHint &other); - - bool operator == (const QMediaServiceProviderHint &other) const; - bool operator != (const QMediaServiceProviderHint &other) const; - - bool isNull() const; - - Type type() const; - - QString mimeType() const; - QStringList codecs() const; - - QByteArray device() const; - - Features features() const; - - //to be extended, if necessary - -private: - QSharedDataPointer d; -}; - -class Q_MULTIMEDIA_EXPORT QMediaServiceProvider : public QObject -{ - Q_OBJECT - -public: - virtual QMediaService* requestService(const QByteArray &type, const QMediaServiceProviderHint &hint = QMediaServiceProviderHint()) = 0; - virtual void releaseService(QMediaService *service) = 0; - - virtual QtMultimedia::SupportEstimate hasSupport(const QByteArray &serviceType, - const QString &mimeType, - const QStringList& codecs, - int flags = 0) const; - virtual QStringList supportedMimeTypes(const QByteArray &serviceType, int flags = 0) const; - - virtual QList devices(const QByteArray &serviceType) const; - virtual QString deviceDescription(const QByteArray &serviceType, const QByteArray &device); - - static QMediaServiceProvider* defaultServiceProvider(); - -#ifdef QT_BUILD_INTERNAL - static void setDefaultServiceProvider(QMediaServiceProvider *provider); -#endif -}; - -/*! - Service with support for media playback - Required Controls: QMediaPlayerControl - Optional Controls: QMediaPlaylistControl, QAudioDeviceControl - Video Output Controls (used by QWideoWidget and QGraphicsVideoItem): - Required: QVideoOutputControl - Optional: QVideoWindowControl, QVideoRendererControl, QVideoWidgetControl -*/ -#define Q_MEDIASERVICE_MEDIAPLAYER "com.nokia.qt.mediaplayer" - -/*! - Service with support for recording from audio sources - Required Controls: QAudioDeviceControl - Recording Controls (QMediaRecorder): - Required: QMediaRecorderControl - Recommended: QAudioEncoderControl - Optional: QMediaContainerControl -*/ -#define Q_MEDIASERVICE_AUDIOSOURCE "com.nokia.qt.audiosource" - -/*! - Service with support for camera use. - Required Controls: QCameraControl - Optional Controls: QCameraExposureControl, QCameraFocusControl, QImageProcessingControl - Still Capture Controls: QImageCaptureControl - Recording Controls (QMediaRecorder): - Required: QMediaRecorderControl - Recommended: QAudioEncoderControl, QVideoEncoderControl, QMediaContainerControl - Viewfinder Video Output Controls (used by QWideoWidget and QGraphicsVideoItem): - Required: QVideoOutputControl - Optional: QVideoWindowControl, QVideoRendererControl, QVideoWidgetControl -*/ -#define Q_MEDIASERVICE_CAMERA "com.nokia.qt.camera" - -/*! - Service with support for radio tuning. - Required Controls: QRadioTunerControl - Recording Controls (Optional, used by QMediaRecorder): - Required: QMediaRecorderControl - Recommended: QAudioEncoderControl - Optional: QMediaContainerControl -*/ -#define Q_MEDIASERVICE_RADIO "com.nokia.qt.radio" - - -QT_END_NAMESPACE - -QT_END_HEADER - -#endif // QMEDIASERVICEPROVIDER_H diff --git a/src/multimedia/base/qmediaserviceproviderplugin.h b/src/multimedia/base/qmediaserviceproviderplugin.h deleted file mode 100644 index b1e728b..0000000 --- a/src/multimedia/base/qmediaserviceproviderplugin.h +++ /dev/null @@ -1,125 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtMultimedia module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QMEDIASERVICEPROVIDERPLUGIN_H -#define QMEDIASERVICEPROVIDERPLUGIN_H - -#include -#include -#include - -#include - -#ifdef Q_MOC_RUN -# pragma Q_MOC_EXPAND_MACROS -#endif - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Multimedia) - -class QMediaService; - - -struct Q_MULTIMEDIA_EXPORT QMediaServiceProviderFactoryInterface : public QFactoryInterface -{ - virtual QStringList keys() const = 0; - virtual QMediaService* create(QString const& key) = 0; - virtual void release(QMediaService *service) = 0; -}; - -#define QMediaServiceProviderFactoryInterface_iid \ - "com.nokia.Qt.QMediaServiceProviderFactoryInterface/1.0" -Q_DECLARE_INTERFACE(QMediaServiceProviderFactoryInterface, QMediaServiceProviderFactoryInterface_iid) - - -struct Q_MULTIMEDIA_EXPORT QMediaServiceSupportedFormatsInterface -{ - virtual ~QMediaServiceSupportedFormatsInterface() {} - virtual QtMultimedia::SupportEstimate hasSupport(const QString &mimeType, const QStringList& codecs) const = 0; - virtual QStringList supportedMimeTypes() const = 0; -}; - -#define QMediaServiceSupportedFormatsInterface_iid \ - "com.nokia.Qt.QMediaServiceSupportedFormatsInterface/1.0" -Q_DECLARE_INTERFACE(QMediaServiceSupportedFormatsInterface, QMediaServiceSupportedFormatsInterface_iid) - - -struct Q_MULTIMEDIA_EXPORT QMediaServiceSupportedDevicesInterface -{ - virtual ~QMediaServiceSupportedDevicesInterface() {} - virtual QList devices(const QByteArray &service) const = 0; - virtual QString deviceDescription(const QByteArray &service, const QByteArray &device) = 0; -}; - -#define QMediaServiceSupportedDevicesInterface_iid \ - "com.nokia.Qt.QMediaServiceSupportedDevicesInterface/1.0" -Q_DECLARE_INTERFACE(QMediaServiceSupportedDevicesInterface, QMediaServiceSupportedDevicesInterface_iid) - - -struct Q_MULTIMEDIA_EXPORT QMediaServiceFeaturesInterface -{ - virtual ~QMediaServiceFeaturesInterface() {} - virtual QMediaServiceProviderHint::Features supportedFeatures(const QByteArray &service) const = 0; -}; - -#define QMediaServiceFeaturesInterface_iid \ - "com.nokia.Qt.QMediaServiceFeaturesInterface/1.0" -Q_DECLARE_INTERFACE(QMediaServiceFeaturesInterface, QMediaServiceFeaturesInterface_iid) - -class Q_MULTIMEDIA_EXPORT QMediaServiceProviderPlugin : public QObject, public QMediaServiceProviderFactoryInterface -{ - Q_OBJECT - Q_INTERFACES(QMediaServiceProviderFactoryInterface:QFactoryInterface) - -public: - virtual QStringList keys() const = 0; - virtual QMediaService* create(const QString& key) = 0; - virtual void release(QMediaService *service) = 0; -}; - -QT_END_NAMESPACE - -QT_END_HEADER - -#endif // QMEDIASERVICEPROVIDERPLUGIN_H diff --git a/src/multimedia/base/qmediatimerange.cpp b/src/multimedia/base/qmediatimerange.cpp deleted file mode 100644 index e1cea7e..0000000 --- a/src/multimedia/base/qmediatimerange.cpp +++ /dev/null @@ -1,708 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtMultimedia module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include - - -QT_BEGIN_NAMESPACE - -/*! - \class QMediaTimeInterval - \brief The QMediaTimeInterval class represents a time interval with integer precision. - \ingroup multimedia - \since 4.7 - - An interval is specified by an inclusive start() and end() time. - These must be set in the constructor, as this is an immutable class. - The specific units of time represented by the class have not been defined - - it is suitable for any times which can be represented by a signed 64 bit integer. - - The isNormal() method determines if a time interval is normal - (a normal time interval has start() <= end()). An abnormal interval can be converted - in to a normal interval by calling the normalized() method. - - The contains() method determines if a specified time lies within - the time interval. - - The translated() method returns a time interval which has been translated - forwards or backwards through time by a specified offset. - - \sa QMediaTimeRange -*/ - -/*! - \fn QMediaTimeInterval::QMediaTimeInterval() - - Constructs an empty interval. -*/ -QMediaTimeInterval::QMediaTimeInterval() - : s(0) - , e(0) -{ - -} - -/*! - \fn QMediaTimeInterval::QMediaTimeInterval(qint64 start, qint64 end) - - Constructs an interval with the specified \a start and \a end times. -*/ -QMediaTimeInterval::QMediaTimeInterval(qint64 start, qint64 end) - : s(start) - , e(end) -{ - -} - -/*! - \fn QMediaTimeInterval::QMediaTimeInterval(const QMediaTimeInterval &other) - - Constructs an interval by taking a copy of \a other. -*/ -QMediaTimeInterval::QMediaTimeInterval(const QMediaTimeInterval &other) - : s(other.s) - , e(other.e) -{ - -} - -/*! - \fn QMediaTimeInterval::start() const - - Returns the start time of the interval. - - \sa end() -*/ -qint64 QMediaTimeInterval::start() const -{ - return s; -} - -/*! - \fn QMediaTimeInterval::end() const - - Returns the end time of the interval. - - \sa start() -*/ -qint64 QMediaTimeInterval::end() const -{ - return e; -} - -/*! - \fn QMediaTimeInterval::contains(qint64 time) const - - Returns true if the time interval contains the specified \a time. - That is, start() <= time <= end(). -*/ -bool QMediaTimeInterval::contains(qint64 time) const -{ - return isNormal() ? (s <= time && time <= e) - : (e <= time && time <= s); -} - -/*! - \fn QMediaTimeInterval::isNormal() const - - Returns true if this time interval is normal. - A normal time interval has start() <= end(). - - \sa normalized() -*/ -bool QMediaTimeInterval::isNormal() const -{ - return s <= e; -} - -/*! - \fn QMediaTimeInterval::normalized() const - - Returns a normalized version of this interval. - - If the start() time of the interval is greater than the end() time, - then the returned interval has the start and end times swapped. -*/ -QMediaTimeInterval QMediaTimeInterval::normalized() const -{ - if(s > e) - return QMediaTimeInterval(e, s); - - return *this; -} - -/*! - \fn QMediaTimeInterval::translated(qint64 offset) const - - Returns a copy of this time interval, translated by a value of \a offset. - An interval can be moved forward through time with a positive offset, or backward - through time with a negative offset. -*/ -QMediaTimeInterval QMediaTimeInterval::translated(qint64 offset) const -{ - return QMediaTimeInterval(s + offset, e + offset); -} - -/*! - \fn operator==(const QMediaTimeInterval &a, const QMediaTimeInterval &b) - \relates QMediaTimeRange - - Returns true if \a a is exactly equal to \a b. -*/ -bool operator==(const QMediaTimeInterval &a, const QMediaTimeInterval &b) -{ - return a.start() == b.start() && a.end() == b.end(); -} - -/*! - \fn operator!=(const QMediaTimeInterval &a, const QMediaTimeInterval &b) - \relates QMediaTimeRange - - Returns true if \a a is not exactly equal to \a b. -*/ -bool operator!=(const QMediaTimeInterval &a, const QMediaTimeInterval &b) -{ - return a.start() != b.start() || a.end() != b.end(); -} - -class QMediaTimeRangePrivate : public QSharedData -{ -public: - - QMediaTimeRangePrivate(); - QMediaTimeRangePrivate(const QMediaTimeRangePrivate &other); - QMediaTimeRangePrivate(const QMediaTimeInterval &interval); - - QList intervals; - - void addInterval(const QMediaTimeInterval &interval); - void removeInterval(const QMediaTimeInterval &interval); -}; - -QMediaTimeRangePrivate::QMediaTimeRangePrivate() - : QSharedData() -{ - -} - -QMediaTimeRangePrivate::QMediaTimeRangePrivate(const QMediaTimeRangePrivate &other) - : QSharedData() - , intervals(other.intervals) -{ - -} - -QMediaTimeRangePrivate::QMediaTimeRangePrivate(const QMediaTimeInterval &interval) - : QSharedData() -{ - if(interval.isNormal()) - intervals << interval; -} - -void QMediaTimeRangePrivate::addInterval(const QMediaTimeInterval &interval) -{ - // Handle normalized intervals only - if(!interval.isNormal()) - return; - - // Find a place to insert the interval - int i; - for (i = 0; i < intervals.count(); i++) { - // Insert before this element - if(interval.s < intervals[i].s) { - intervals.insert(i, interval); - break; - } - } - - // Interval needs to be added to the end of the list - if (i == intervals.count()) - intervals.append(interval); - - // Do we need to correct the element before us? - if(i > 0 && intervals[i - 1].e >= interval.s - 1) - i--; - - // Merge trailing ranges - while (i < intervals.count() - 1 - && intervals[i].e >= intervals[i + 1].s - 1) { - intervals[i].e = qMax(intervals[i].e, intervals[i + 1].e); - intervals.removeAt(i + 1); - } -} - -void QMediaTimeRangePrivate::removeInterval(const QMediaTimeInterval &interval) -{ - // Handle normalized intervals only - if(!interval.isNormal()) - return; - - for (int i = 0; i < intervals.count(); i++) { - QMediaTimeInterval r = intervals[i]; - - if (r.e < interval.s) { - // Before the removal interval - continue; - } else if (interval.e < r.s) { - // After the removal interval - stop here - break; - } else if (r.s < interval.s && interval.e < r.e) { - // Split case - a single range has a chunk removed - intervals[i].e = interval.s -1; - addInterval(QMediaTimeInterval(interval.e + 1, r.e)); - break; - } else if (r.s < interval.s) { - // Trimming Tail Case - intervals[i].e = interval.s - 1; - } else if (interval.e < r.e) { - // Trimming Head Case - we can stop after this - intervals[i].s = interval.e + 1; - break; - } else { - // Complete coverage case - intervals.removeAt(i); - --i; - } - } -} - -/*! - \class QMediaTimeRange - \brief The QMediaTimeRange class represents a set of zero or more disjoint - time intervals. - \ingroup multimedia - \since 4.7 - - \reentrant - - The earliestTime(), latestTime(), intervals() and isEmpty() - methods are used to get information about the current time range. - - The addInterval(), removeInterval() and clear() methods are used to modify - the current time range. - - When adding or removing intervals from the time range, existing intervals - within the range may be expanded, trimmed, deleted, merged or split to ensure - that all intervals within the time range remain distinct and disjoint. As a - consequence, all intervals added or removed from a time range must be - \l{QMediaTimeInterval::isNormal()}{normal}. - - \sa QMediaTimeInterval -*/ - -/*! - \fn QMediaTimeRange::QMediaTimeRange() - - Constructs an empty time range. -*/ -QMediaTimeRange::QMediaTimeRange() - : d(new QMediaTimeRangePrivate) -{ - -} - -/*! - \fn QMediaTimeRange::QMediaTimeRange(qint64 start, qint64 end) - - Constructs a time range that contains an initial interval from - \a start to \a end inclusive. - - If the interval is not \l{QMediaTimeInterval::isNormal()}{normal}, - the resulting time range will be empty. - - \sa addInterval() -*/ -QMediaTimeRange::QMediaTimeRange(qint64 start, qint64 end) - : d(new QMediaTimeRangePrivate(QMediaTimeInterval(start, end))) -{ - -} - -/*! - \fn QMediaTimeRange::QMediaTimeRange(const QMediaTimeInterval &interval) - - Constructs a time range that contains an intitial interval, \a interval. - - If \a interval is not \l{QMediaTimeInterval::isNormal()}{normal}, - the resulting time range will be empty. - - \sa addInterval() -*/ -QMediaTimeRange::QMediaTimeRange(const QMediaTimeInterval &interval) - : d(new QMediaTimeRangePrivate(interval)) -{ - -} - -/*! - \fn QMediaTimeRange::QMediaTimeRange(const QMediaTimeRange &range) - - Constructs a time range by copying another time \a range. -*/ -QMediaTimeRange::QMediaTimeRange(const QMediaTimeRange &range) - : d(range.d) -{ - -} - -/*! - \fn QMediaTimeRange::~QMediaTimeRange() - - Destructor. -*/ -QMediaTimeRange::~QMediaTimeRange() -{ - -} - -/*! - \fn QMediaTimeRange::operator=(const QMediaTimeRange &other) - - Takes a copy of the \a other time range and returns itself. -*/ -QMediaTimeRange &QMediaTimeRange::operator=(const QMediaTimeRange &other) -{ - d = other.d; - return *this; -} - -/*! - \fn QMediaTimeRange::operator=(const QMediaTimeInterval &interval) - - Sets the time range to a single continuous interval, \a interval. -*/ -QMediaTimeRange &QMediaTimeRange::operator=(const QMediaTimeInterval &interval) -{ - d = new QMediaTimeRangePrivate(interval); - return *this; -} - -/*! - \fn QMediaTimeRange::earliestTime() const - - Returns the earliest time within the time range. - - For empty time ranges, this value is equal to zero. - - \sa latestTime() -*/ -qint64 QMediaTimeRange::earliestTime() const -{ - if (!d->intervals.isEmpty()) - return d->intervals[0].s; - - return 0; -} - -/*! - \fn QMediaTimeRange::latestTime() const - - Returns the latest time within the time range. - - For empty time ranges, this value is equal to zero. - - \sa earliestTime() -*/ -qint64 QMediaTimeRange::latestTime() const -{ - if (!d->intervals.isEmpty()) - return d->intervals[d->intervals.count() - 1].e; - - return 0; -} - -/*! - \fn QMediaTimeRange::addInterval(qint64 start, qint64 end) - \overload - - Adds the interval specified by \a start and \a end - to the time range. - - \sa addInterval() -*/ -void QMediaTimeRange::addInterval(qint64 start, qint64 end) -{ - d->addInterval(QMediaTimeInterval(start, end)); -} - -/*! - \fn QMediaTimeRange::addInterval(const QMediaTimeInterval &interval) - - Adds the specified \a interval to the time range. - - Adding intervals which are not \l{QMediaTimeInterval::isNormal()}{normal} - is invalid, and will be ignored. - - If the specified interval is adjacent to, or overlaps existing - intervals within the time range, these intervals will be merged. - - This operation takes \l{linear time} - - \sa removeInterval() -*/ -void QMediaTimeRange::addInterval(const QMediaTimeInterval &interval) -{ - d->addInterval(interval); -} - -/*! - \fn QMediaTimeRange::addTimeRange(const QMediaTimeRange &range) - - Adds each of the intervals in \a range to this time range. - - Equivalent to calling addInterval() for each interval in \a range. -*/ -void QMediaTimeRange::addTimeRange(const QMediaTimeRange &range) -{ - foreach(const QMediaTimeInterval &i, range.intervals()) { - d->addInterval(i); - } -} - -/*! - \fn QMediaTimeRange::removeInterval(qint64 start, qint64 end) - \overload - - Removes the interval specified by \a start and \a end - from the time range. - - \sa removeInterval() -*/ -void QMediaTimeRange::removeInterval(qint64 start, qint64 end) -{ - d->removeInterval(QMediaTimeInterval(start, end)); -} - -/*! - \fn QMediaTimeRange::removeInterval(const QMediaTimeInterval &interval) - - Removes the specified \a interval from the time range. - - Removing intervals which are not \l{QMediaTimeInterval::isNormal()}{normal} - is invalid, and will be ignored. - - Intervals within the time range will be trimmed, split or deleted - such that no intervals within the time range include any part of the - target interval. - - This operation takes \l{linear time} - - \sa addInterval() -*/ -void QMediaTimeRange::removeInterval(const QMediaTimeInterval &interval) -{ - d->removeInterval(interval); -} - -/*! - \fn QMediaTimeRange::removeTimeRange(const QMediaTimeRange &range) - - Removes each of the intervals in \a range from this time range. - - Equivalent to calling removeInterval() for each interval in \a range. -*/ -void QMediaTimeRange::removeTimeRange(const QMediaTimeRange &range) -{ - foreach(const QMediaTimeInterval &i, range.intervals()) { - d->removeInterval(i); - } -} - -/*! - \fn QMediaTimeRange::operator+=(const QMediaTimeRange &other) - - Adds each interval in \a other to the time range and returns the result. -*/ -QMediaTimeRange& QMediaTimeRange::operator+=(const QMediaTimeRange &other) -{ - addTimeRange(other); - return *this; -} - -/*! - \fn QMediaTimeRange::operator+=(const QMediaTimeInterval &interval) - - Adds the specified \a interval to the time range and returns the result. -*/ -QMediaTimeRange& QMediaTimeRange::operator+=(const QMediaTimeInterval &interval) -{ - addInterval(interval); - return *this; -} - -/*! - \fn QMediaTimeRange::operator-=(const QMediaTimeRange &other) - - Removes each interval in \a other from the time range and returns the result. -*/ -QMediaTimeRange& QMediaTimeRange::operator-=(const QMediaTimeRange &other) -{ - removeTimeRange(other); - return *this; -} - -/*! - \fn QMediaTimeRange::operator-=(const QMediaTimeInterval &interval) - - Removes the specified \a interval from the time range and returns the result. -*/ -QMediaTimeRange& QMediaTimeRange::operator-=(const QMediaTimeInterval &interval) -{ - removeInterval(interval); - return *this; -} - -/*! - \fn QMediaTimeRange::clear() - - Removes all intervals from the time range. - - \sa removeInterval() -*/ -void QMediaTimeRange::clear() -{ - d->intervals.clear(); -} - -/*! - \fn QMediaTimeRange::intervals() const - - Returns the list of intervals covered by this time range. -*/ -QList QMediaTimeRange::intervals() const -{ - return d->intervals; -} - -/*! - \fn QMediaTimeRange::isEmpty() const - - Returns true if there are no intervals within the time range. - - \sa intervals() -*/ -bool QMediaTimeRange::isEmpty() const -{ - return d->intervals.isEmpty(); -} - -/*! - \fn QMediaTimeRange::isContinuous() const - - Returns true if the time range consists of a continuous interval. - That is, there is one or fewer disjoint intervals within the time range. -*/ -bool QMediaTimeRange::isContinuous() const -{ - return (d->intervals.count() <= 1); -} - -/*! - \fn QMediaTimeRange::contains(qint64 time) const - - Returns true if the specified \a time lies within the time range. -*/ -bool QMediaTimeRange::contains(qint64 time) const -{ - for (int i = 0; i < d->intervals.count(); i++) { - if (d->intervals[i].contains(time)) - return true; - - if (time < d->intervals[i].s) - break; - } - - return false; -} - -/*! - \fn operator==(const QMediaTimeRange &a, const QMediaTimeRange &b) - \relates QMediaTimeRange - - Returns true if all intervals in \a a are present in \a b. -*/ -bool operator==(const QMediaTimeRange &a, const QMediaTimeRange &b) -{ - if (a.intervals().count() != b.intervals().count()) - return false; - - for (int i = 0; i < a.intervals().count(); i++) - { - if(a.intervals()[i] != b.intervals()[i]) - return false; - } - - return true; -} - -/*! - \fn operator!=(const QMediaTimeRange &a, const QMediaTimeRange &b) - \relates QMediaTimeRange - - Returns true if one or more intervals in \a a are not present in \a b. -*/ -bool operator!=(const QMediaTimeRange &a, const QMediaTimeRange &b) -{ - return !(a == b); -} - -/*! - \fn operator+(const QMediaTimeRange &r1, const QMediaTimeRange &r2) - - Returns a time range containing the union between \a r1 and \a r2. - */ -QMediaTimeRange operator+(const QMediaTimeRange &r1, const QMediaTimeRange &r2) -{ - return (QMediaTimeRange(r1) += r2); -} - -/*! - \fn operator-(const QMediaTimeRange &r1, const QMediaTimeRange &r2) - - Returns a time range containing \a r2 subtracted from \a r1. - */ -QMediaTimeRange operator-(const QMediaTimeRange &r1, const QMediaTimeRange &r2) -{ - return (QMediaTimeRange(r1) -= r2); -} - -QT_END_NAMESPACE - diff --git a/src/multimedia/base/qmediatimerange.h b/src/multimedia/base/qmediatimerange.h deleted file mode 100644 index a65629e..0000000 --- a/src/multimedia/base/qmediatimerange.h +++ /dev/null @@ -1,135 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtMultimedia module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QMEDIATIMERANGE_H -#define QMEDIATIMERANGE_H - -#include -#include - - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Multimedia) - -class QMediaTimeRangePrivate; - -class Q_MULTIMEDIA_EXPORT QMediaTimeInterval -{ -public: - QMediaTimeInterval(); - QMediaTimeInterval(qint64 start, qint64 end); - QMediaTimeInterval(const QMediaTimeInterval&); - - qint64 start() const; - qint64 end() const; - - bool contains(qint64 time) const; - - bool isNormal() const; - QMediaTimeInterval normalized() const; - QMediaTimeInterval translated(qint64 offset) const; - -private: - friend class QMediaTimeRangePrivate; - friend class QMediaTimeRange; - - qint64 s; - qint64 e; -}; - -Q_MULTIMEDIA_EXPORT bool operator==(const QMediaTimeInterval&, const QMediaTimeInterval&); -Q_MULTIMEDIA_EXPORT bool operator!=(const QMediaTimeInterval&, const QMediaTimeInterval&); - -class Q_MULTIMEDIA_EXPORT QMediaTimeRange -{ -public: - - QMediaTimeRange(); - QMediaTimeRange(qint64 start, qint64 end); - QMediaTimeRange(const QMediaTimeInterval&); - QMediaTimeRange(const QMediaTimeRange &range); - ~QMediaTimeRange(); - - QMediaTimeRange &operator=(const QMediaTimeRange&); - QMediaTimeRange &operator=(const QMediaTimeInterval&); - - qint64 earliestTime() const; - qint64 latestTime() const; - - QList intervals() const; - bool isEmpty() const; - bool isContinuous() const; - - bool contains(qint64 time) const; - - void addInterval(qint64 start, qint64 end); - void addInterval(const QMediaTimeInterval &interval); - void addTimeRange(const QMediaTimeRange&); - - void removeInterval(qint64 start, qint64 end); - void removeInterval(const QMediaTimeInterval &interval); - void removeTimeRange(const QMediaTimeRange&); - - QMediaTimeRange& operator+=(const QMediaTimeRange&); - QMediaTimeRange& operator+=(const QMediaTimeInterval&); - QMediaTimeRange& operator-=(const QMediaTimeRange&); - QMediaTimeRange& operator-=(const QMediaTimeInterval&); - - void clear(); - -private: - QSharedDataPointer d; -}; - -Q_MULTIMEDIA_EXPORT bool operator==(const QMediaTimeRange&, const QMediaTimeRange&); -Q_MULTIMEDIA_EXPORT bool operator!=(const QMediaTimeRange&, const QMediaTimeRange&); -Q_MULTIMEDIA_EXPORT QMediaTimeRange operator+(const QMediaTimeRange&, const QMediaTimeRange&); -Q_MULTIMEDIA_EXPORT QMediaTimeRange operator-(const QMediaTimeRange&, const QMediaTimeRange&); - - -QT_END_NAMESPACE - -QT_END_HEADER - -#endif // QMEDIATIMERANGE_H diff --git a/src/multimedia/base/qmetadatacontrol.cpp b/src/multimedia/base/qmetadatacontrol.cpp deleted file mode 100644 index 28a82ec..0000000 --- a/src/multimedia/base/qmetadatacontrol.cpp +++ /dev/null @@ -1,185 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtMultimedia module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include -#include "qmediacontrol_p.h" - - -QT_BEGIN_NAMESPACE - - -/*! - \class QMetaDataControl - \ingroup multimedia-serv - \since 4.7 - \preliminary - \brief The QMetaDataControl class provides access to the meta-data of a - QMediaService's media. - - If a QMediaService can provide read or write access to the meta-data of - its current media it will implement QMetaDataControl. This control - provides functions for both retrieving and setting meta-data values. - Meta-data may be addressed by the well defined keys in the - QtMultimedia::MetaData enumeration using the metaData() functions, or by - string keys using the extendedMetaData() functions. - - The functionality provided by this control is exposed to application - code by the meta-data members of QMediaObject, and so meta-data access - is potentially available in any of the media object classes. Any media - service may implement QMetaDataControl. - - The interface name of QMetaDataControl is \c com.nokia.Qt.QMetaDataControl/1.0 as - defined in QMetaDataControl_iid. - - \sa QMediaService::control(), QMediaObject -*/ - -/*! - \macro QMetaDataControl_iid - - \c com.nokia.Qt.QMetaDataControl/1.0 - - Defines the interface name of the QMetaDataControl class. - - \relates QMetaDataControl -*/ - -/*! - Construct a QMetaDataControl with \a parent. This class is meant as a base class - for service specific meta data providers so this constructor is protected. -*/ - -QMetaDataControl::QMetaDataControl(QObject *parent): - QMediaControl(*new QMediaControlPrivate, parent) -{ -} - -/*! - Destroy the meta-data object. -*/ - -QMetaDataControl::~QMetaDataControl() -{ -} - -/*! - \fn bool QMetaDataControl::isMetaDataAvailable() const - - Identifies if meta-data is available from a media service. - - Returns true if the meta-data is available and false otherwise. -*/ - -/*! - \fn bool QMetaDataControl::isWritable() const - - Identifies if a media service's meta-data can be edited. - - Returns true if the meta-data is writable and false otherwise. -*/ - -/*! - \fn QVariant QMetaDataControl::metaData(QtMultimedia::MetaData key) const - - Returns the meta-data for the given \a key. -*/ - -/*! - \fn void QMetaDataControl::setMetaData(QtMultimedia::MetaData key, const QVariant &value) - - Sets the \a value of the meta-data element with the given \a key. -*/ - -/*! - \fn QMetaDataControl::availableMetaData() const - - Returns a list of keys there is meta-data available for. -*/ - -/*! - \fn QMetaDataControl::extendedMetaData(const QString &key) const - - Returns the metaData for an abitrary string \a key. - - The valid selection of keys for extended meta-data is determined by the provider and the meaning - and type may differ between providers. -*/ - -/*! - \fn QMetaDataControl::setExtendedMetaData(const QString &key, const QVariant &value) - - Change the value of the meta-data element with an abitrary string \a key to \a value. - - The valid selection of keys for extended meta-data is determined by the provider and the meaning - and type may differ between providers. -*/ - -/*! - \fn QMetaDataControl::availableExtendedMetaData() const - - Returns a list of keys there is extended meta-data available for. -*/ - - -/*! - \fn void QMetaDataControl::metaDataChanged() - - Signal the changes of meta-data. -*/ - -/*! - \fn void QMetaDataControl::metaDataAvailableChanged(bool available) - - Signal the availability of meta-data has changed, \a available will - be true if the multimedia object has meta-data. -*/ - -/*! - \fn void QMetaDataControl::writableChanged(bool writable) - - Signal a change in the writable status of meta-data, \a writable will be - true if meta-data elements can be added or adjusted. -*/ - -#include "moc_qmetadatacontrol.cpp" - -QT_END_NAMESPACE - diff --git a/src/multimedia/base/qmetadatacontrol.h b/src/multimedia/base/qmetadatacontrol.h deleted file mode 100644 index 8e18c16..0000000 --- a/src/multimedia/base/qmetadatacontrol.h +++ /dev/null @@ -1,92 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtMultimedia module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QMETADATACONTROL_H -#define QMETADATACONTROL_H - -#include -#include -#include - - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Multimedia) - -class Q_MULTIMEDIA_EXPORT QMetaDataControl : public QMediaControl -{ - Q_OBJECT - -public: - ~QMetaDataControl(); - - virtual bool isWritable() const = 0; - virtual bool isMetaDataAvailable() const = 0; - - virtual QVariant metaData(QtMultimedia::MetaData key) const = 0; - virtual void setMetaData(QtMultimedia::MetaData key, const QVariant &value) = 0; - virtual QList availableMetaData() const = 0; - - virtual QVariant extendedMetaData(const QString &key) const = 0; - virtual void setExtendedMetaData(const QString &key, const QVariant &value) = 0; - virtual QStringList availableExtendedMetaData() const = 0; - -Q_SIGNALS: - void metaDataChanged(); - - void writableChanged(bool writable); - void metaDataAvailableChanged(bool available); - -protected: - QMetaDataControl(QObject *parent = 0); -}; - -#define QMetaDataControl_iid "com.nokia.Qt.QMetaDataControl/1.0" -Q_MEDIA_DECLARE_CONTROL(QMetaDataControl, QMetaDataControl_iid) - -QT_END_NAMESPACE - -QT_END_HEADER - - -#endif // QMETADATAPROVIDER_H diff --git a/src/multimedia/base/qpaintervideosurface.cpp b/src/multimedia/base/qpaintervideosurface.cpp deleted file mode 100644 index 2fe941b..0000000 --- a/src/multimedia/base/qpaintervideosurface.cpp +++ /dev/null @@ -1,1565 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtMultimedia module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qpaintervideosurface_p.h" -#include "qpaintervideosurface_mac_p.h" - -#include - -#include -#include -#include - -#if !defined(QT_NO_OPENGL) && !defined(QT_OPENGL_ES_1_CL) && !defined(QT_OPENGL_ES_1) -#include -#endif - -#include - - -QT_BEGIN_NAMESPACE - -QVideoSurfacePainter::~QVideoSurfacePainter() -{ -} - -class QVideoSurfaceRasterPainter : public QVideoSurfacePainter -{ -public: - QVideoSurfaceRasterPainter(); - - QList supportedPixelFormats( - QAbstractVideoBuffer::HandleType handleType) const; - - bool isFormatSupported( - const QVideoSurfaceFormat &format, QVideoSurfaceFormat *similar) const; - - QAbstractVideoSurface::Error start(const QVideoSurfaceFormat &format); - void stop(); - - QAbstractVideoSurface::Error setCurrentFrame(const QVideoFrame &frame); - - QAbstractVideoSurface::Error paint( - const QRectF &target, QPainter *painter, const QRectF &source); - - void updateColors(int brightness, int contrast, int hue, int saturation); - -private: - QList m_imagePixelFormats; - QVideoFrame m_frame; - QSize m_imageSize; - QImage::Format m_imageFormat; - QVideoSurfaceFormat::Direction m_scanLineDirection; -}; - -QVideoSurfaceRasterPainter::QVideoSurfaceRasterPainter() - : m_imageFormat(QImage::Format_Invalid) - , m_scanLineDirection(QVideoSurfaceFormat::TopToBottom) -{ - m_imagePixelFormats - << QVideoFrame::Format_RGB32 -#ifndef QT_OPENGL_ES // The raster formats should be a subset of the GL formats. - << QVideoFrame::Format_RGB24 -#endif - << QVideoFrame::Format_ARGB32 - << QVideoFrame::Format_RGB565; -} - -QList QVideoSurfaceRasterPainter::supportedPixelFormats( - QAbstractVideoBuffer::HandleType handleType) const -{ - return handleType == QAbstractVideoBuffer::NoHandle - ? m_imagePixelFormats - : QList(); -} - -bool QVideoSurfaceRasterPainter::isFormatSupported( - const QVideoSurfaceFormat &format, QVideoSurfaceFormat *) const -{ - return format.handleType() == QAbstractVideoBuffer::NoHandle - && m_imagePixelFormats.contains(format.pixelFormat()) - && !format.frameSize().isEmpty(); -} - -QAbstractVideoSurface::Error QVideoSurfaceRasterPainter::start(const QVideoSurfaceFormat &format) -{ - m_frame = QVideoFrame(); - m_imageFormat = QVideoFrame::imageFormatFromPixelFormat(format.pixelFormat()); - m_imageSize = format.frameSize(); - m_scanLineDirection = format.scanLineDirection(); - - return format.handleType() == QAbstractVideoBuffer::NoHandle - && m_imageFormat != QImage::Format_Invalid - && !m_imageSize.isEmpty() - ? QAbstractVideoSurface::NoError - : QAbstractVideoSurface::UnsupportedFormatError; -} - -void QVideoSurfaceRasterPainter::stop() -{ - m_frame = QVideoFrame(); -} - -QAbstractVideoSurface::Error QVideoSurfaceRasterPainter::setCurrentFrame(const QVideoFrame &frame) -{ - m_frame = frame; - - return QAbstractVideoSurface::NoError; -} - -QAbstractVideoSurface::Error QVideoSurfaceRasterPainter::paint( - const QRectF &target, QPainter *painter, const QRectF &source) -{ - if (m_frame.map(QAbstractVideoBuffer::ReadOnly)) { - QImage image( - m_frame.bits(), - m_imageSize.width(), - m_imageSize.height(), - m_frame.bytesPerLine(), - m_imageFormat); - - if (m_scanLineDirection == QVideoSurfaceFormat::BottomToTop) { - const QTransform oldTransform = painter->transform(); - - painter->scale(1, -1); - painter->translate(0, -target.bottom()); - painter->drawImage( - QRectF(target.x(), 0, target.width(), target.height()), image, source); - painter->setTransform(oldTransform); - } else { - painter->drawImage(target, image, source); - } - - m_frame.unmap(); - } else if (m_frame.isValid()) { - return QAbstractVideoSurface::IncorrectFormatError; - } else { - painter->fillRect(target, Qt::black); - } - return QAbstractVideoSurface::NoError; -} - -void QVideoSurfaceRasterPainter::updateColors(int, int, int, int) -{ -} - -#if !defined(QT_NO_OPENGL) && !defined(QT_OPENGL_ES_1_CL) && !defined(QT_OPENGL_ES_1) - -#ifndef Q_WS_MAC -# ifndef APIENTRYP -# ifdef APIENTRY -# define APIENTRYP APIENTRY * -# else -# define APIENTRY -# define APIENTRYP * -# endif -# endif -#else -# define APIENTRY -# define APIENTRYP * -#endif - -#ifndef GL_TEXTURE0 -# define GL_TEXTURE0 0x84C0 -# define GL_TEXTURE1 0x84C1 -# define GL_TEXTURE2 0x84C2 -#endif -#ifndef GL_PROGRAM_ERROR_STRING_ARB -# define GL_PROGRAM_ERROR_STRING_ARB 0x8874 -#endif - -#ifndef GL_UNSIGNED_SHORT_5_6_5 -# define GL_UNSIGNED_SHORT_5_6_5 33635 -#endif - -class QVideoSurfaceGLPainter : public QVideoSurfacePainter -{ -public: - QVideoSurfaceGLPainter(QGLContext *context); - ~QVideoSurfaceGLPainter(); - QList supportedPixelFormats( - QAbstractVideoBuffer::HandleType handleType) const; - - bool isFormatSupported( - const QVideoSurfaceFormat &format, QVideoSurfaceFormat *similar) const; - - QAbstractVideoSurface::Error setCurrentFrame(const QVideoFrame &frame); - - void updateColors(int brightness, int contrast, int hue, int saturation); - -protected: - void initRgbTextureInfo(GLenum internalFormat, GLuint format, GLenum type, const QSize &size); - void initYuv420PTextureInfo(const QSize &size); - void initYv12TextureInfo(const QSize &size); - -#ifndef QT_OPENGL_ES - typedef void (APIENTRY *_glActiveTexture) (GLenum); - _glActiveTexture glActiveTexture; -#endif - - QList m_imagePixelFormats; - QList m_glPixelFormats; - QMatrix4x4 m_colorMatrix; - QVideoFrame m_frame; - - QGLContext *m_context; - QAbstractVideoBuffer::HandleType m_handleType; - QVideoSurfaceFormat::Direction m_scanLineDirection; - GLenum m_textureFormat; - GLuint m_textureInternalFormat; - GLenum m_textureType; - int m_textureCount; - GLuint m_textureIds[3]; - int m_textureWidths[3]; - int m_textureHeights[3]; - int m_textureOffsets[3]; - bool m_yuv; -}; - -QVideoSurfaceGLPainter::QVideoSurfaceGLPainter(QGLContext *context) - : m_context(context) - , m_handleType(QAbstractVideoBuffer::NoHandle) - , m_scanLineDirection(QVideoSurfaceFormat::TopToBottom) - , m_textureFormat(0) - , m_textureInternalFormat(0) - , m_textureType(0) - , m_textureCount(0) - , m_yuv(false) -{ -#ifndef QT_OPENGL_ES - glActiveTexture = (_glActiveTexture)m_context->getProcAddress(QLatin1String("glActiveTexture")); -#endif -} - -QVideoSurfaceGLPainter::~QVideoSurfaceGLPainter() -{ -} - -QList QVideoSurfaceGLPainter::supportedPixelFormats( - QAbstractVideoBuffer::HandleType handleType) const -{ - switch (handleType) { - case QAbstractVideoBuffer::NoHandle: - return m_imagePixelFormats; - case QAbstractVideoBuffer::GLTextureHandle: - return m_glPixelFormats; - default: - return QList(); - } -} - -bool QVideoSurfaceGLPainter::isFormatSupported( - const QVideoSurfaceFormat &format, QVideoSurfaceFormat *) const -{ - if (format.frameSize().isEmpty()) { - return false; - } else { - switch (format.handleType()) { - case QAbstractVideoBuffer::NoHandle: - return m_imagePixelFormats.contains(format.pixelFormat()); - case QAbstractVideoBuffer::GLTextureHandle: - return m_glPixelFormats.contains(format.pixelFormat()); - default: - return false; - } - } -} - -QAbstractVideoSurface::Error QVideoSurfaceGLPainter::setCurrentFrame(const QVideoFrame &frame) -{ - m_frame = frame; - - if (m_handleType == QAbstractVideoBuffer::GLTextureHandle) { - m_textureIds[0] = frame.handle().toInt(); - } else if (m_frame.map(QAbstractVideoBuffer::ReadOnly)) { - m_context->makeCurrent(); - - for (int i = 0; i < m_textureCount; ++i) { - glBindTexture(GL_TEXTURE_2D, m_textureIds[i]); - glTexImage2D( - GL_TEXTURE_2D, - 0, - m_textureInternalFormat, - m_textureWidths[i], - m_textureHeights[i], - 0, - m_textureFormat, - m_textureType, - m_frame.bits() + m_textureOffsets[i]); - glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); - glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); - glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); - } - m_frame.unmap(); - } else if (m_frame.isValid()) { - return QAbstractVideoSurface::IncorrectFormatError; - } - - return QAbstractVideoSurface::NoError; -} - -void QVideoSurfaceGLPainter::updateColors(int brightness, int contrast, int hue, int saturation) -{ - const qreal b = brightness / 200.0; - const qreal c = contrast / 100.0 + 1.0; - const qreal h = hue / 100.0; - const qreal s = saturation / 100.0 + 1.0; - - const qreal cosH = qCos(M_PI * h); - const qreal sinH = qSin(M_PI * h); - - const qreal h11 = 0.787 * cosH - 0.213 * sinH + 0.213; - const qreal h21 = -0.213 * cosH + 0.143 * sinH + 0.213; - const qreal h31 = -0.213 * cosH - 0.787 * sinH + 0.213; - - const qreal h12 = -0.715 * cosH - 0.715 * sinH + 0.715; - const qreal h22 = 0.285 * cosH + 0.140 * sinH + 0.715; - const qreal h32 = -0.715 * cosH + 0.715 * sinH + 0.715; - - const qreal h13 = -0.072 * cosH + 0.928 * sinH + 0.072; - const qreal h23 = -0.072 * cosH - 0.283 * sinH + 0.072; - const qreal h33 = 0.928 * cosH + 0.072 * sinH + 0.072; - - const qreal sr = (1.0 - s) * 0.3086; - const qreal sg = (1.0 - s) * 0.6094; - const qreal sb = (1.0 - s) * 0.0820; - - const qreal sr_s = sr + s; - const qreal sg_s = sg + s; - const qreal sb_s = sr + s; - - const float m4 = (s + sr + sg + sb) * (0.5 - 0.5 * c + b); - - m_colorMatrix(0, 0) = c * (sr_s * h11 + sg * h21 + sb * h31); - m_colorMatrix(0, 1) = c * (sr_s * h12 + sg * h22 + sb * h32); - m_colorMatrix(0, 2) = c * (sr_s * h13 + sg * h23 + sb * h33); - m_colorMatrix(0, 3) = m4; - - m_colorMatrix(1, 0) = c * (sr * h11 + sg_s * h21 + sb * h31); - m_colorMatrix(1, 1) = c * (sr * h12 + sg_s * h22 + sb * h32); - m_colorMatrix(1, 2) = c * (sr * h13 + sg_s * h23 + sb * h33); - m_colorMatrix(1, 3) = m4; - - m_colorMatrix(2, 0) = c * (sr * h11 + sg * h21 + sb_s * h31); - m_colorMatrix(2, 1) = c * (sr * h12 + sg * h22 + sb_s * h32); - m_colorMatrix(2, 2) = c * (sr * h13 + sg * h23 + sb_s * h33); - m_colorMatrix(2, 3) = m4; - - m_colorMatrix(3, 0) = 0.0; - m_colorMatrix(3, 1) = 0.0; - m_colorMatrix(3, 2) = 0.0; - m_colorMatrix(3, 3) = 1.0; - - if (m_yuv) { - m_colorMatrix = m_colorMatrix * QMatrix4x4( - 1.0, 0.000, 1.140, -0.5700, - 1.0, -0.394, -0.581, 0.4875, - 1.0, 2.028, 0.000, -1.0140, - 0.0, 0.000, 0.000, 1.0000); - } -} - -void QVideoSurfaceGLPainter::initRgbTextureInfo( - GLenum internalFormat, GLuint format, GLenum type, const QSize &size) -{ - m_yuv = false; - m_textureInternalFormat = internalFormat; - m_textureFormat = format; - m_textureType = type; - m_textureCount = 1; - m_textureWidths[0] = size.width(); - m_textureHeights[0] = size.height(); - m_textureOffsets[0] = 0; -} - -void QVideoSurfaceGLPainter::initYuv420PTextureInfo(const QSize &size) -{ - int w = (size.width() + 3) & ~3; - int w2 = (size.width()/2 + 3) & ~3; - - m_yuv = true; - m_textureInternalFormat = GL_LUMINANCE; - m_textureFormat = GL_LUMINANCE; - m_textureType = GL_UNSIGNED_BYTE; - m_textureCount = 3; - m_textureWidths[0] = size.width(); - m_textureHeights[0] = size.height(); - m_textureOffsets[0] = 0; - m_textureWidths[1] = size.width() / 2; - m_textureHeights[1] = size.height() / 2; - m_textureOffsets[1] = w * size.height(); - m_textureWidths[2] = size.width() / 2; - m_textureHeights[2] = size.height() / 2; - m_textureOffsets[2] = w * size.height() + w2 * (size.height() / 2); -} - -void QVideoSurfaceGLPainter::initYv12TextureInfo(const QSize &size) -{ - int w = (size.width() + 3) & ~3; - int w2 = (size.width()/2 + 3) & ~3; - - m_yuv = true; - m_textureInternalFormat = GL_LUMINANCE; - m_textureFormat = GL_LUMINANCE; - m_textureType = GL_UNSIGNED_BYTE; - m_textureCount = 3; - m_textureWidths[0] = size.width(); - m_textureHeights[0] = size.height(); - m_textureOffsets[0] = 0; - m_textureWidths[1] = size.width() / 2; - m_textureHeights[1] = size.height() / 2; - m_textureOffsets[1] = w * size.height() + w2 * (size.height() / 2); - m_textureWidths[2] = size.width() / 2; - m_textureHeights[2] = size.height() / 2; - m_textureOffsets[2] = w * size.height(); -} - -#ifndef QT_OPENGL_ES - -# ifndef GL_FRAGMENT_PROGRAM_ARB -# define GL_FRAGMENT_PROGRAM_ARB 0x8804 -# define GL_PROGRAM_FORMAT_ASCII_ARB 0x8875 -# endif - -// Paints an RGB32 frame -static const char *qt_arbfp_xrgbShaderProgram = - "!!ARBfp1.0\n" - "PARAM matrix[4] = { program.local[0..2]," - "{ 0.0, 0.0, 0.0, 1.0 } };\n" - "TEMP xrgb;\n" - "TEX xrgb.xyz, fragment.texcoord[0], texture[0], 2D;\n" - "MOV xrgb.w, matrix[3].w;\n" - "DP4 result.color.x, xrgb.zyxw, matrix[0];\n" - "DP4 result.color.y, xrgb.zyxw, matrix[1];\n" - "DP4 result.color.z, xrgb.zyxw, matrix[2];\n" - "END"; - -// Paints an ARGB frame. -static const char *qt_arbfp_argbShaderProgram = - "!!ARBfp1.0\n" - "PARAM matrix[4] = { program.local[0..2]," - "{ 0.0, 0.0, 0.0, 1.0 } };\n" - "TEMP argb;\n" - "TEX argb, fragment.texcoord[0], texture[0], 2D;\n" - "MOV argb.w, matrix[3].w;\n" - "DP4 result.color.x, argb.zyxw, matrix[0];\n" - "DP4 result.color.y, argb.zyxw, matrix[1];\n" - "DP4 result.color.z, argb.zyxw, matrix[2];\n" - "TEX result.color.w, fragment.texcoord[0], texture, 2D;\n" - "END"; - -// Paints an RGB(A) frame. -static const char *qt_arbfp_rgbShaderProgram = - "!!ARBfp1.0\n" - "PARAM matrix[4] = { program.local[0..2]," - "{ 0.0, 0.0, 0.0, 1.0 } };\n" - "TEMP rgb;\n" - "TEX rgb, fragment.texcoord[0], texture[0], 2D;\n" - "MOV rgb.w, matrix[3].w;\n" - "DP4 result.color.x, rgb, matrix[0];\n" - "DP4 result.color.y, rgb, matrix[1];\n" - "DP4 result.color.z, rgb, matrix[2];\n" - "TEX result.color.w, fragment.texcoord[0], texture, 2D;\n" - "END"; - -// Paints a YUV420P or YV12 frame. -static const char *qt_arbfp_yuvPlanarShaderProgram = - "!!ARBfp1.0\n" - "PARAM matrix[4] = { program.local[0..2]," - "{ 0.0, 0.0, 0.0, 1.0 } };\n" - "TEMP yuv;\n" - "TEX yuv.x, fragment.texcoord[0], texture[0], 2D;\n" - "TEX yuv.y, fragment.texcoord[0], texture[1], 2D;\n" - "TEX yuv.z, fragment.texcoord[0], texture[2], 2D;\n" - "MOV yuv.w, matrix[3].w;\n" - "DP4 result.color.x, yuv, matrix[0];\n" - "DP4 result.color.y, yuv, matrix[1];\n" - "DP4 result.color.z, yuv, matrix[2];\n" - "END"; - -// Paints a YUV444 frame. -static const char *qt_arbfp_xyuvShaderProgram = - "!!ARBfp1.0\n" - "PARAM matrix[4] = { program.local[0..2]," - "{ 0.0, 0.0, 0.0, 1.0 } };\n" - "TEMP ayuv;\n" - "TEX ayuv, fragment.texcoord[0], texture[0], 2D;\n" - "MOV ayuv.x, matrix[3].w;\n" - "DP4 result.color.x, ayuv.yzwx, matrix[0];\n" - "DP4 result.color.y, ayuv.yzwx, matrix[1];\n" - "DP4 result.color.z, ayuv.yzwx, matrix[2];\n" - "END"; - -// Paints a AYUV444 frame. -static const char *qt_arbfp_ayuvShaderProgram = - "!!ARBfp1.0\n" - "PARAM matrix[4] = { program.local[0..2]," - "{ 0.0, 0.0, 0.0, 1.0 } };\n" - "TEMP ayuv;\n" - "TEX ayuv, fragment.texcoord[0], texture[0], 2D;\n" - "MOV ayuv.x, matrix[3].w;\n" - "DP4 result.color.x, ayuv.yzwx, matrix[0];\n" - "DP4 result.color.y, ayuv.yzwx, matrix[1];\n" - "DP4 result.color.z, ayuv.yzwx, matrix[2];\n" - "TEX result.color.w, fragment.texcoord[0], texture, 2D;\n" - "END"; - -class QVideoSurfaceArbFpPainter : public QVideoSurfaceGLPainter -{ -public: - QVideoSurfaceArbFpPainter(QGLContext *context); - - QAbstractVideoSurface::Error start(const QVideoSurfaceFormat &format); - void stop(); - - QAbstractVideoSurface::Error paint( - const QRectF &target, QPainter *painter, const QRectF &source); - -private: - typedef void (APIENTRY *_glProgramStringARB) (GLenum, GLenum, GLsizei, const GLvoid *); - typedef void (APIENTRY *_glBindProgramARB) (GLenum, GLuint); - typedef void (APIENTRY *_glDeleteProgramsARB) (GLsizei, const GLuint *); - typedef void (APIENTRY *_glGenProgramsARB) (GLsizei, GLuint *); - typedef void (APIENTRY *_glProgramLocalParameter4fARB) ( - GLenum, GLuint, GLfloat, GLfloat, GLfloat, GLfloat); - typedef void (APIENTRY *_glActiveTexture) (GLenum); - - _glProgramStringARB glProgramStringARB; - _glBindProgramARB glBindProgramARB; - _glDeleteProgramsARB glDeleteProgramsARB; - _glGenProgramsARB glGenProgramsARB; - _glProgramLocalParameter4fARB glProgramLocalParameter4fARB; - - GLuint m_programId; - QSize m_frameSize; -}; - -QVideoSurfaceArbFpPainter::QVideoSurfaceArbFpPainter(QGLContext *context) - : QVideoSurfaceGLPainter(context) - , m_programId(0) -{ - glProgramStringARB = (_glProgramStringARB) m_context->getProcAddress( - QLatin1String("glProgramStringARB")); - glBindProgramARB = (_glBindProgramARB) m_context->getProcAddress( - QLatin1String("glBindProgramARB")); - glDeleteProgramsARB = (_glDeleteProgramsARB) m_context->getProcAddress( - QLatin1String("glDeleteProgramsARB")); - glGenProgramsARB = (_glGenProgramsARB) m_context->getProcAddress( - QLatin1String("glGenProgramsARB")); - glProgramLocalParameter4fARB = (_glProgramLocalParameter4fARB) m_context->getProcAddress( - QLatin1String("glProgramLocalParameter4fARB")); - - m_imagePixelFormats - << QVideoFrame::Format_RGB32 - << QVideoFrame::Format_BGR32 - << QVideoFrame::Format_ARGB32 - << QVideoFrame::Format_RGB24 - << QVideoFrame::Format_BGR24 - << QVideoFrame::Format_RGB565 - << QVideoFrame::Format_AYUV444 - << QVideoFrame::Format_YUV444 - << QVideoFrame::Format_YV12 - << QVideoFrame::Format_YUV420P; - m_glPixelFormats - << QVideoFrame::Format_RGB32 - << QVideoFrame::Format_ARGB32; -} - -QAbstractVideoSurface::Error QVideoSurfaceArbFpPainter::start(const QVideoSurfaceFormat &format) -{ - Q_ASSERT(m_textureCount == 0); - - QAbstractVideoSurface::Error error = QAbstractVideoSurface::NoError; - - m_context->makeCurrent(); - - const char *program = 0; - - if (format.handleType() == QAbstractVideoBuffer::NoHandle) { - switch (format.pixelFormat()) { - case QVideoFrame::Format_RGB32: - initRgbTextureInfo(GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE, format.frameSize()); - program = qt_arbfp_xrgbShaderProgram; - break; - case QVideoFrame::Format_BGR32: - initRgbTextureInfo(GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE, format.frameSize()); - program = qt_arbfp_rgbShaderProgram; - break; - case QVideoFrame::Format_ARGB32: - initRgbTextureInfo(GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE, format.frameSize()); - program = qt_arbfp_argbShaderProgram; - break; - case QVideoFrame::Format_RGB24: - initRgbTextureInfo(GL_RGB8, GL_RGBA, GL_UNSIGNED_BYTE, format.frameSize()); - program = qt_arbfp_rgbShaderProgram; - break; - case QVideoFrame::Format_BGR24: - initRgbTextureInfo(GL_RGB8, GL_RGBA, GL_UNSIGNED_BYTE, format.frameSize()); - program = qt_arbfp_xrgbShaderProgram; - break; - case QVideoFrame::Format_RGB565: - initRgbTextureInfo(GL_RGB, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, format.frameSize()); - program = qt_arbfp_rgbShaderProgram; - break; - case QVideoFrame::Format_YUV444: - initRgbTextureInfo(GL_RGB, GL_RGB, GL_UNSIGNED_BYTE, format.frameSize()); - program = qt_arbfp_xyuvShaderProgram; - m_yuv = true; - break; - case QVideoFrame::Format_AYUV444: - initRgbTextureInfo(GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE, format.frameSize()); - program = qt_arbfp_ayuvShaderProgram; - m_yuv = true; - break; - case QVideoFrame::Format_YV12: - initYv12TextureInfo(format.frameSize()); - program = qt_arbfp_yuvPlanarShaderProgram; - break; - case QVideoFrame::Format_YUV420P: - initYuv420PTextureInfo(format.frameSize()); - program = qt_arbfp_yuvPlanarShaderProgram; - break; - default: - break; - } - } else if (format.handleType() == QAbstractVideoBuffer::GLTextureHandle) { - switch (format.pixelFormat()) { - case QVideoFrame::Format_RGB32: - case QVideoFrame::Format_ARGB32: - m_yuv = false; - m_textureCount = 1; - program = qt_arbfp_rgbShaderProgram; - break; - default: - break; - } - } - - if (!program) { - error = QAbstractVideoSurface::UnsupportedFormatError; - } else { - glGenProgramsARB(1, &m_programId); - - GLenum glError = glGetError(); - if (glError != GL_NO_ERROR) { - qWarning("QPainterVideoSurface: ARBfb Shader allocation error %x", int(glError)); - m_textureCount = 0; - m_programId = 0; - - error = QAbstractVideoSurface::ResourceError; - } else { - glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, m_programId); - glProgramStringARB( - GL_FRAGMENT_PROGRAM_ARB, - GL_PROGRAM_FORMAT_ASCII_ARB, - qstrlen(program), - reinterpret_cast(program)); - - if ((glError = glGetError()) != GL_NO_ERROR) { - const GLubyte* errorString = glGetString(GL_PROGRAM_ERROR_STRING_ARB); - - qWarning("QPainterVideoSurface: ARBfp Shader compile error %x, %s", - int(glError), - reinterpret_cast(errorString)); - glDeleteProgramsARB(1, &m_programId); - - m_textureCount = 0; - m_programId = 0; - - error = QAbstractVideoSurface::ResourceError; - } else { - m_handleType = format.handleType(); - m_scanLineDirection = format.scanLineDirection(); - m_frameSize = format.frameSize(); - - if (m_handleType == QAbstractVideoBuffer::NoHandle) - glGenTextures(m_textureCount, m_textureIds); - } - } - } - - return error; -} - -void QVideoSurfaceArbFpPainter::stop() -{ - m_context->makeCurrent(); - - if (m_handleType != QAbstractVideoBuffer::GLTextureHandle) - glDeleteTextures(m_textureCount, m_textureIds); - glDeleteProgramsARB(1, &m_programId); - - m_textureCount = 0; - m_programId = 0; - m_handleType = QAbstractVideoBuffer::NoHandle; -} - -QAbstractVideoSurface::Error QVideoSurfaceArbFpPainter::paint( - const QRectF &target, QPainter *painter, const QRectF &source) -{ - if (m_frame.isValid()) { - bool stencilTestEnabled = glIsEnabled(GL_STENCIL_TEST); - bool scissorTestEnabled = glIsEnabled(GL_SCISSOR_TEST); - - painter->beginNativePainting(); - - if (stencilTestEnabled) - glEnable(GL_STENCIL_TEST); - if (scissorTestEnabled) - glEnable(GL_SCISSOR_TEST); - - const float txLeft = source.left() / m_frameSize.width(); - const float txRight = source.right() / m_frameSize.width(); - const float txTop = m_scanLineDirection == QVideoSurfaceFormat::TopToBottom - ? source.top() / m_frameSize.height() - : source.bottom() / m_frameSize.height(); - const float txBottom = m_scanLineDirection == QVideoSurfaceFormat::TopToBottom - ? source.bottom() / m_frameSize.height() - : source.top() / m_frameSize.height(); - - - const float tx_array[] = - { - txLeft , txBottom, - txRight, txBottom, - txLeft , txTop, - txRight, txTop - }; - const float v_array[] = - { - float(target.left()) , float(target.bottom() + 1), - float(target.right() + 1), float(target.bottom() + 1), - float(target.left()) , float(target.top()), - float(target.right() + 1), float(target.top()) - }; - - glEnable(GL_FRAGMENT_PROGRAM_ARB); - glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, m_programId); - - glProgramLocalParameter4fARB( - GL_FRAGMENT_PROGRAM_ARB, - 0, - m_colorMatrix(0, 0), - m_colorMatrix(0, 1), - m_colorMatrix(0, 2), - m_colorMatrix(0, 3)); - glProgramLocalParameter4fARB( - GL_FRAGMENT_PROGRAM_ARB, - 1, - m_colorMatrix(1, 0), - m_colorMatrix(1, 1), - m_colorMatrix(1, 2), - m_colorMatrix(1, 3)); - glProgramLocalParameter4fARB( - GL_FRAGMENT_PROGRAM_ARB, - 2, - m_colorMatrix(2, 0), - m_colorMatrix(2, 1), - m_colorMatrix(2, 2), - m_colorMatrix(2, 3)); - - glActiveTexture(GL_TEXTURE0); - glBindTexture(GL_TEXTURE_2D, m_textureIds[0]); - - if (m_textureCount == 3) { - glActiveTexture(GL_TEXTURE1); - glBindTexture(GL_TEXTURE_2D, m_textureIds[1]); - glActiveTexture(GL_TEXTURE2); - glBindTexture(GL_TEXTURE_2D, m_textureIds[2]); - glActiveTexture(GL_TEXTURE0); - } - - glVertexPointer(2, GL_FLOAT, 0, v_array); - glTexCoordPointer(2, GL_FLOAT, 0, tx_array); - - glEnableClientState(GL_VERTEX_ARRAY); - glEnableClientState(GL_TEXTURE_COORD_ARRAY); - - glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); - - glDisableClientState(GL_TEXTURE_COORD_ARRAY); - glDisableClientState(GL_VERTEX_ARRAY); - glDisable(GL_FRAGMENT_PROGRAM_ARB); - - painter->endNativePainting(); - } - return QAbstractVideoSurface::NoError; -} - -#endif - -static const char *qt_glsl_vertexShaderProgram = - "attribute highp vec4 vertexCoordArray;\n" - "attribute highp vec2 textureCoordArray;\n" - "uniform highp mat4 positionMatrix;\n" - "varying highp vec2 textureCoord;\n" - "void main(void)\n" - "{\n" - " gl_Position = positionMatrix * vertexCoordArray;\n" - " textureCoord = textureCoordArray;\n" - "}\n"; - -// Paints an RGB32 frame -static const char *qt_glsl_xrgbShaderProgram = - "uniform sampler2D texRgb;\n" - "uniform mediump mat4 colorMatrix;\n" - "varying highp vec2 textureCoord;\n" - "void main(void)\n" - "{\n" - " highp vec4 color = vec4(texture2D(texRgb, textureCoord.st).bgr, 1.0);\n" - " gl_FragColor = colorMatrix * color;\n" - "}\n"; - -// Paints an ARGB frame. -static const char *qt_glsl_argbShaderProgram = - "uniform sampler2D texRgb;\n" - "uniform mediump mat4 colorMatrix;\n" - "varying highp vec2 textureCoord;\n" - "void main(void)\n" - "{\n" - " highp vec4 color = vec4(texture2D(texRgb, textureCoord.st).bgr, 1.0);\n" - " color = colorMatrix * color;\n" - " gl_FragColor = vec4(color.rgb, texture2D(texRgb, textureCoord.st).a);\n" - "}\n"; - -// Paints an RGB(A) frame. -static const char *qt_glsl_rgbShaderProgram = - "uniform sampler2D texRgb;\n" - "uniform mediump mat4 colorMatrix;\n" - "varying highp vec2 textureCoord;\n" - "void main(void)\n" - "{\n" - " highp vec4 color = vec4(texture2D(texRgb, textureCoord.st).rgb, 1.0);\n" - " color = colorMatrix * color;\n" - " gl_FragColor = vec4(color.rgb, texture2D(texRgb, textureCoord.st).a);\n" - "}\n"; - -// Paints a YUV420P or YV12 frame. -static const char *qt_glsl_yuvPlanarShaderProgram = - "uniform sampler2D texY;\n" - "uniform sampler2D texU;\n" - "uniform sampler2D texV;\n" - "uniform mediump mat4 colorMatrix;\n" - "varying highp vec2 textureCoord;\n" - "void main(void)\n" - "{\n" - " highp vec4 color = vec4(\n" - " texture2D(texY, textureCoord.st).r,\n" - " texture2D(texU, textureCoord.st).r,\n" - " texture2D(texV, textureCoord.st).r,\n" - " 1.0);\n" - " gl_FragColor = colorMatrix * color;\n" - "}\n"; - -// Paints a YUV444 frame. -static const char *qt_glsl_xyuvShaderProgram = - "uniform sampler2D texRgb;\n" - "uniform mediump mat4 colorMatrix;\n" - "varying highp vec2 textureCoord;\n" - "void main(void)\n" - "{\n" - " highp vec4 color = vec4(texture2D(texRgb, textureCoord.st).gba, 1.0);\n" - " gl_FragColor = colorMatrix * color;\n" - "}\n"; - -// Paints a AYUV444 frame. -static const char *qt_glsl_ayuvShaderProgram = - "uniform sampler2D texRgb;\n" - "uniform mediump mat4 colorMatrix;\n" - "varying highp vec2 textureCoord;\n" - "void main(void)\n" - "{\n" - " highp vec4 color = vec4(texture2D(texRgb, textureCoord.st).gba, 1.0);\n" - " color = colorMatrix * color;\n" - " gl_FragColor = vec4(color.rgb, texture2D(texRgb, textureCoord.st).r);\n" - "}\n"; - -class QVideoSurfaceGlslPainter : public QVideoSurfaceGLPainter -{ -public: - QVideoSurfaceGlslPainter(QGLContext *context); - - QAbstractVideoSurface::Error start(const QVideoSurfaceFormat &format); - void stop(); - - QAbstractVideoSurface::Error paint( - const QRectF &target, QPainter *painter, const QRectF &source); - -private: - QGLShaderProgram m_program; - QSize m_frameSize; -}; - -QVideoSurfaceGlslPainter::QVideoSurfaceGlslPainter(QGLContext *context) - : QVideoSurfaceGLPainter(context) - , m_program(context) -{ - m_imagePixelFormats - << QVideoFrame::Format_RGB32 - << QVideoFrame::Format_BGR32 - << QVideoFrame::Format_ARGB32 -#ifndef QT_OPENGL_ES - << QVideoFrame::Format_RGB24 - << QVideoFrame::Format_BGR24 -#endif - << QVideoFrame::Format_RGB565 - << QVideoFrame::Format_YUV444 - << QVideoFrame::Format_AYUV444 - << QVideoFrame::Format_YV12 - << QVideoFrame::Format_YUV420P; - m_glPixelFormats - << QVideoFrame::Format_RGB32 - << QVideoFrame::Format_ARGB32; -} - -QAbstractVideoSurface::Error QVideoSurfaceGlslPainter::start(const QVideoSurfaceFormat &format) -{ - Q_ASSERT(m_textureCount == 0); - - QAbstractVideoSurface::Error error = QAbstractVideoSurface::NoError; - - m_context->makeCurrent(); - - const char *fragmentProgram = 0; - - if (format.handleType() == QAbstractVideoBuffer::NoHandle) { - switch (format.pixelFormat()) { - case QVideoFrame::Format_RGB32: - initRgbTextureInfo(GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE, format.frameSize()); - fragmentProgram = qt_glsl_xrgbShaderProgram; - break; - case QVideoFrame::Format_BGR32: - initRgbTextureInfo(GL_RGB, GL_RGBA, GL_UNSIGNED_BYTE, format.frameSize()); - fragmentProgram = qt_glsl_rgbShaderProgram; - break; - case QVideoFrame::Format_ARGB32: - initRgbTextureInfo(GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE, format.frameSize()); - fragmentProgram = qt_glsl_argbShaderProgram; - break; -#ifndef QT_OPENGL_ES - case QVideoFrame::Format_RGB24: - initRgbTextureInfo(GL_RGB8, GL_RGB, GL_UNSIGNED_BYTE, format.frameSize()); - fragmentProgram = qt_glsl_rgbShaderProgram; - break; - case QVideoFrame::Format_BGR24: - initRgbTextureInfo(GL_RGB8, GL_RGB, GL_UNSIGNED_BYTE, format.frameSize()); - fragmentProgram = qt_glsl_argbShaderProgram; - break; -#endif - case QVideoFrame::Format_RGB565: - initRgbTextureInfo(GL_RGB, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, format.frameSize()); - fragmentProgram = qt_glsl_rgbShaderProgram; - break; - case QVideoFrame::Format_YUV444: - initRgbTextureInfo(GL_RGB, GL_RGB, GL_UNSIGNED_BYTE, format.frameSize()); - fragmentProgram = qt_glsl_xyuvShaderProgram; - m_yuv = true; - break; - case QVideoFrame::Format_AYUV444: - initRgbTextureInfo(GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE, format.frameSize()); - fragmentProgram = qt_glsl_ayuvShaderProgram; - m_yuv = true; - break; - case QVideoFrame::Format_YV12: - initYv12TextureInfo(format.frameSize()); - fragmentProgram = qt_glsl_yuvPlanarShaderProgram; - break; - case QVideoFrame::Format_YUV420P: - initYuv420PTextureInfo(format.frameSize()); - fragmentProgram = qt_glsl_yuvPlanarShaderProgram; - break; - default: - break; - } - } else if (format.handleType() == QAbstractVideoBuffer::GLTextureHandle) { - switch (format.pixelFormat()) { - case QVideoFrame::Format_RGB32: - case QVideoFrame::Format_ARGB32: - m_yuv = false; - m_textureCount = 1; - fragmentProgram = qt_glsl_rgbShaderProgram; - break; - default: - break; - } - } - - if (!fragmentProgram) { - error = QAbstractVideoSurface::UnsupportedFormatError; - } else if (!m_program.addShaderFromSourceCode(QGLShader::Vertex, qt_glsl_vertexShaderProgram)) { - qWarning("QPainterVideoSurface: Vertex shader compile error %s", - qPrintable(m_program.log())); - error = QAbstractVideoSurface::ResourceError; - } else if (!m_program.addShaderFromSourceCode(QGLShader::Fragment, fragmentProgram)) { - qWarning("QPainterVideoSurface: Shader compile error %s", qPrintable(m_program.log())); - error = QAbstractVideoSurface::ResourceError; - m_program.removeAllShaders(); - } else if(!m_program.link()) { - qWarning("QPainterVideoSurface: Shader link error %s", qPrintable(m_program.log())); - m_program.removeAllShaders(); - error = QAbstractVideoSurface::ResourceError; - } else { - m_handleType = format.handleType(); - m_scanLineDirection = format.scanLineDirection(); - m_frameSize = format.frameSize(); - - if (m_handleType == QAbstractVideoBuffer::NoHandle) - glGenTextures(m_textureCount, m_textureIds); - } - - return error; -} - -void QVideoSurfaceGlslPainter::stop() -{ - m_context->makeCurrent(); - - if (m_handleType != QAbstractVideoBuffer::GLTextureHandle) - glDeleteTextures(m_textureCount, m_textureIds); - m_program.removeAllShaders(); - - m_textureCount = 0; - m_handleType = QAbstractVideoBuffer::NoHandle; -} - -QAbstractVideoSurface::Error QVideoSurfaceGlslPainter::paint( - const QRectF &target, QPainter *painter, const QRectF &source) -{ - if (m_frame.isValid()) { - bool stencilTestEnabled = glIsEnabled(GL_STENCIL_TEST); - bool scissorTestEnabled = glIsEnabled(GL_SCISSOR_TEST); - - painter->beginNativePainting(); - - if (stencilTestEnabled) - glEnable(GL_STENCIL_TEST); - if (scissorTestEnabled) - glEnable(GL_SCISSOR_TEST); - - const int width = QGLContext::currentContext()->device()->width(); - const int height = QGLContext::currentContext()->device()->height(); - - const QTransform transform = painter->deviceTransform(); - - const GLfloat wfactor = 2.0 / width; - const GLfloat hfactor = -2.0 / height; - - const GLfloat positionMatrix[4][4] = - { - { - /*(0,0)*/ GLfloat(wfactor * transform.m11() - transform.m13()), - /*(0,1)*/ GLfloat(hfactor * transform.m12() + transform.m13()), - /*(0,2)*/ 0.0, - /*(0,3)*/ GLfloat(transform.m13()) - }, { - /*(1,0)*/ GLfloat(wfactor * transform.m21() - transform.m23()), - /*(1,1)*/ GLfloat(hfactor * transform.m22() + transform.m23()), - /*(1,2)*/ 0.0, - /*(1,3)*/ GLfloat(transform.m23()) - }, { - /*(2,0)*/ 0.0, - /*(2,1)*/ 0.0, - /*(2,2)*/ -1.0, - /*(2,3)*/ 0.0 - }, { - /*(3,0)*/ GLfloat(wfactor * transform.dx() - transform.m33()), - /*(3,1)*/ GLfloat(hfactor * transform.dy() + transform.m33()), - /*(3,2)*/ 0.0, - /*(3,3)*/ GLfloat(transform.m33()) - } - }; - - const GLfloat vertexCoordArray[] = - { - GLfloat(target.left()) , GLfloat(target.bottom() + 1), - GLfloat(target.right() + 1), GLfloat(target.bottom() + 1), - GLfloat(target.left()) , GLfloat(target.top()), - GLfloat(target.right() + 1), GLfloat(target.top()) - }; - - const GLfloat txLeft = source.left() / m_frameSize.width(); - const GLfloat txRight = source.right() / m_frameSize.width(); - const GLfloat txTop = m_scanLineDirection == QVideoSurfaceFormat::TopToBottom - ? source.top() / m_frameSize.height() - : source.bottom() / m_frameSize.height(); - const GLfloat txBottom = m_scanLineDirection == QVideoSurfaceFormat::TopToBottom - ? source.bottom() / m_frameSize.height() - : source.top() / m_frameSize.height(); - - const GLfloat textureCoordArray[] = - { - txLeft , txBottom, - txRight, txBottom, - txLeft , txTop, - txRight, txTop - }; - - m_program.bind(); - - m_program.enableAttributeArray("vertexCoordArray"); - m_program.enableAttributeArray("textureCoordArray"); - m_program.setAttributeArray("vertexCoordArray", vertexCoordArray, 2); - m_program.setAttributeArray("textureCoordArray", textureCoordArray, 2); - m_program.setUniformValue("positionMatrix", positionMatrix); - - if (m_textureCount == 3) { - glActiveTexture(GL_TEXTURE0); - glBindTexture(GL_TEXTURE_2D, m_textureIds[0]); - glActiveTexture(GL_TEXTURE1); - glBindTexture(GL_TEXTURE_2D, m_textureIds[1]); - glActiveTexture(GL_TEXTURE2); - glBindTexture(GL_TEXTURE_2D, m_textureIds[2]); - glActiveTexture(GL_TEXTURE0); - - m_program.setUniformValue("texY", GLint(0)); - m_program.setUniformValue("texU", GLint(1)); - m_program.setUniformValue("texV", GLint(2)); - } else { - glActiveTexture(GL_TEXTURE0); - glBindTexture(GL_TEXTURE_2D, m_textureIds[0]); - - m_program.setUniformValue("texRgb", GLint(0)); - } - m_program.setUniformValue("colorMatrix", m_colorMatrix); - - glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); - - m_program.release(); - - painter->endNativePainting(); - } - return QAbstractVideoSurface::NoError; -} - -#endif - -/*! - \class QPainterVideoSurface - \internal -*/ - -/*! -*/ -QPainterVideoSurface::QPainterVideoSurface(QObject *parent) - : QAbstractVideoSurface(parent) - , m_painter(0) -#if !defined(QT_NO_OPENGL) && !defined(QT_OPENGL_ES_1_CL) && !defined(QT_OPENGL_ES_1) - , m_glContext(0) - , m_shaderTypes(NoShaders) - , m_shaderType(NoShaders) -#endif - , m_brightness(0) - , m_contrast(0) - , m_hue(0) - , m_saturation(0) - , m_pixelFormat(QVideoFrame::Format_Invalid) - , m_colorsDirty(true) - , m_ready(false) -{ -} - -/*! -*/ -QPainterVideoSurface::~QPainterVideoSurface() -{ - if (isActive()) - m_painter->stop(); - - delete m_painter; -} - -/*! -*/ -QList QPainterVideoSurface::supportedPixelFormats( - QAbstractVideoBuffer::HandleType handleType) const -{ - if (!m_painter) - const_cast(this)->createPainter(); - - return m_painter->supportedPixelFormats(handleType); -} - -/*! -*/ -bool QPainterVideoSurface::isFormatSupported( - const QVideoSurfaceFormat &format, QVideoSurfaceFormat *similar) const -{ - if (!m_painter) - const_cast(this)->createPainter(); - - return m_painter->isFormatSupported(format, similar); -} - -/*! -*/ -bool QPainterVideoSurface::start(const QVideoSurfaceFormat &format) -{ - if (isActive()) - m_painter->stop(); - - if (!m_painter) - createPainter(); - - if (format.frameSize().isEmpty()) { - setError(UnsupportedFormatError); - } else { - QAbstractVideoSurface::Error error = m_painter->start(format); - - if (error != QAbstractVideoSurface::NoError) { - setError(error); - } else { - m_pixelFormat = format.pixelFormat(); - m_frameSize = format.frameSize(); - m_sourceRect = format.viewport(); - m_colorsDirty = true; - m_ready = true; - - return QAbstractVideoSurface::start(format); - } - } - - QAbstractVideoSurface::stop(); - - return false; -} - -/*! -*/ -void QPainterVideoSurface::stop() -{ - if (isActive()) { - m_painter->stop(); - m_ready = false; - - QAbstractVideoSurface::stop(); - } -} - -/*! -*/ -bool QPainterVideoSurface::present(const QVideoFrame &frame) -{ - if (!m_ready) { - if (!isActive()) - setError(StoppedError); - } else if (frame.isValid() - && (frame.pixelFormat() != m_pixelFormat || frame.size() != m_frameSize)) { - setError(IncorrectFormatError); - - stop(); - } else { - QAbstractVideoSurface::Error error = m_painter->setCurrentFrame(frame); - - if (error != QAbstractVideoSurface::NoError) { - setError(error); - - stop(); - } else { - m_ready = false; - - emit frameChanged(); - - return true; - } - } - return false; -} - -/*! -*/ -int QPainterVideoSurface::brightness() const -{ - return m_brightness; -} - -/*! -*/ -void QPainterVideoSurface::setBrightness(int brightness) -{ - m_brightness = brightness; - - m_colorsDirty = true; -} - -/*! -*/ -int QPainterVideoSurface::contrast() const -{ - return m_contrast; -} - -/*! -*/ -void QPainterVideoSurface::setContrast(int contrast) -{ - m_contrast = contrast; - - m_colorsDirty = true; -} - -/*! -*/ -int QPainterVideoSurface::hue() const -{ - return m_hue; -} - -/*! -*/ -void QPainterVideoSurface::setHue(int hue) -{ - m_hue = hue; - - m_colorsDirty = true; -} - -/*! -*/ -int QPainterVideoSurface::saturation() const -{ - return m_saturation; -} - -/*! -*/ -void QPainterVideoSurface::setSaturation(int saturation) -{ - m_saturation = saturation; - - m_colorsDirty = true; -} - -/*! -*/ -bool QPainterVideoSurface::isReady() const -{ - return m_ready; -} - -/*! -*/ -void QPainterVideoSurface::setReady(bool ready) -{ - m_ready = ready; -} - -/*! -*/ -void QPainterVideoSurface::paint(QPainter *painter, const QRectF &target, const QRectF &source) -{ - if (!isActive()) { - painter->fillRect(target, QBrush(Qt::black)); - } else { - if (m_colorsDirty) { - m_painter->updateColors(m_brightness, m_contrast, m_hue, m_saturation); - m_colorsDirty = false; - } - - const QRectF sourceRect( - m_sourceRect.x() + m_sourceRect.width() * source.x(), - m_sourceRect.y() + m_sourceRect.height() * source.y(), - m_sourceRect.width() * source.width(), - m_sourceRect.height() * source.height()); - - QAbstractVideoSurface::Error error = m_painter->paint(target, painter, sourceRect); - - if (error != QAbstractVideoSurface::NoError) { - setError(error); - - stop(); - } - } -} - -/*! - \fn QPainterVideoSurface::frameChanged() -*/ - -#if !defined(QT_NO_OPENGL) && !defined(QT_OPENGL_ES_1_CL) && !defined(QT_OPENGL_ES_1) - -/*! -*/ -const QGLContext *QPainterVideoSurface::glContext() const -{ - return m_glContext; -} - -/*! -*/ -void QPainterVideoSurface::setGLContext(QGLContext *context) -{ - if (m_glContext == context) - return; - - m_glContext = context; - - m_shaderTypes = NoShaders; - - if (m_glContext) { - m_glContext->makeCurrent(); - - const QByteArray extensions(reinterpret_cast(glGetString(GL_EXTENSIONS))); -#ifndef QT_OPENGL_ES - - if (extensions.contains("ARB_fragment_program")) - m_shaderTypes |= FragmentProgramShader; -#endif - - if (QGLShaderProgram::hasOpenGLShaderPrograms(m_glContext) - && extensions.contains("ARB_shader_objects")) - m_shaderTypes |= GlslShader; - } - - ShaderType type = (m_shaderType & m_shaderTypes) - ? m_shaderType - : NoShaders; - - if (type != m_shaderType || type != NoShaders) { - m_shaderType = type; - - if (isActive()) { - m_painter->stop(); - delete m_painter; - m_painter = 0; - m_ready = false; - - setError(ResourceError); - QAbstractVideoSurface::stop(); - } - emit supportedFormatsChanged(); - } -} - -/*! - \enum QPainterVideoSurface::ShaderType - - \value NoShaders - \value FragmentProgramShader - \value HlslShader -*/ - -/*! - \typedef QPainterVideoSurface::ShaderTypes -*/ - -/*! -*/ -QPainterVideoSurface::ShaderTypes QPainterVideoSurface::supportedShaderTypes() const -{ - return m_shaderTypes; -} - -/*! -*/ -QPainterVideoSurface::ShaderType QPainterVideoSurface::shaderType() const -{ - return m_shaderType; -} - -/*! -*/ -void QPainterVideoSurface::setShaderType(ShaderType type) -{ - if (!(type & m_shaderTypes)) - type = NoShaders; - - if (type != m_shaderType) { - m_shaderType = type; - - if (isActive()) { - m_painter->stop(); - delete m_painter; - m_painter = 0; - m_ready = false; - - setError(ResourceError); - QAbstractVideoSurface::stop(); - } else { - delete m_painter; - m_painter = 0; - } - emit supportedFormatsChanged(); - } -} - -#endif - -void QPainterVideoSurface::createPainter() -{ - Q_ASSERT(!m_painter); - -#ifdef Q_WS_MAC - if (m_glContext) - m_glContext->makeCurrent(); - - m_painter = new QVideoSurfaceCoreGraphicsPainter(m_glContext != 0); - return; -#endif - -#if !defined(QT_NO_OPENGL) && !defined(QT_OPENGL_ES_1_CL) && !defined(QT_OPENGL_ES_1) - switch (m_shaderType) { -#ifndef QT_OPENGL_ES - case FragmentProgramShader: - Q_ASSERT(m_glContext); - m_glContext->makeCurrent(); - m_painter = new QVideoSurfaceArbFpPainter(m_glContext); - break; -#endif - case GlslShader: - Q_ASSERT(m_glContext); - m_glContext->makeCurrent(); - m_painter = new QVideoSurfaceGlslPainter(m_glContext); - break; - default: - m_painter = new QVideoSurfaceRasterPainter; - break; - } -#else - m_painter = new QVideoSurfaceRasterPainter; -#endif -} - -QT_END_NAMESPACE - -#include "moc_qpaintervideosurface_p.cpp" - - diff --git a/src/multimedia/base/qpaintervideosurface_mac.mm b/src/multimedia/base/qpaintervideosurface_mac.mm deleted file mode 100644 index 1154f86..0000000 --- a/src/multimedia/base/qpaintervideosurface_mac.mm +++ /dev/null @@ -1,283 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtMultimedia module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qpaintervideosurface_mac_p.h" - -#include - -#include - -#include -#include -#include - -#include - -#include -#include -#include - -QT_BEGIN_NAMESPACE - -extern CGContextRef qt_mac_cg_context(const QPaintDevice *pdev); //qpaintdevice_mac.cpp - -QVideoSurfaceCoreGraphicsPainter::QVideoSurfaceCoreGraphicsPainter(bool glSupported) - : ciContext(0) - , m_imageFormat(QImage::Format_Invalid) - , m_scanLineDirection(QVideoSurfaceFormat::TopToBottom) -{ - //qDebug() << "QVideoSurfaceCoreGraphicsPainter, GL supported:" << glSupported; - ciContext = 0; - m_imagePixelFormats - << QVideoFrame::Format_RGB32; - - m_supportedHandles - << QAbstractVideoBuffer::NoHandle - << QAbstractVideoBuffer::CoreImageHandle; - - if (glSupported) - m_supportedHandles << QAbstractVideoBuffer::GLTextureHandle; -} - -QVideoSurfaceCoreGraphicsPainter::~QVideoSurfaceCoreGraphicsPainter() -{ - [(CIContext*)ciContext release]; -} - -QList QVideoSurfaceCoreGraphicsPainter::supportedPixelFormats( - QAbstractVideoBuffer::HandleType handleType) const -{ - return m_supportedHandles.contains(handleType) - ? m_imagePixelFormats - : QList(); -} - -bool QVideoSurfaceCoreGraphicsPainter::isFormatSupported( - const QVideoSurfaceFormat &format, QVideoSurfaceFormat *) const -{ - return m_supportedHandles.contains(format.handleType()) - && m_imagePixelFormats.contains(format.pixelFormat()) - && !format.frameSize().isEmpty(); -} - -QAbstractVideoSurface::Error QVideoSurfaceCoreGraphicsPainter::start(const QVideoSurfaceFormat &format) -{ - m_frame = QVideoFrame(); - m_imageFormat = QVideoFrame::imageFormatFromPixelFormat(format.pixelFormat()); - m_imageSize = format.frameSize(); - m_scanLineDirection = format.scanLineDirection(); - - return m_supportedHandles.contains(format.handleType()) - && m_imageFormat != QImage::Format_Invalid - && !m_imageSize.isEmpty() - ? QAbstractVideoSurface::NoError - : QAbstractVideoSurface::UnsupportedFormatError; -} - -void QVideoSurfaceCoreGraphicsPainter::stop() -{ - m_frame = QVideoFrame(); -} - -QAbstractVideoSurface::Error QVideoSurfaceCoreGraphicsPainter::setCurrentFrame(const QVideoFrame &frame) -{ - m_frame = frame; - - return QAbstractVideoSurface::NoError; -} - -QAbstractVideoSurface::Error QVideoSurfaceCoreGraphicsPainter::paint( - const QRectF &target, QPainter *painter, const QRectF &source) -{ - if (m_frame.handleType() == QAbstractVideoBuffer::CoreImageHandle) { - if (painter->paintEngine()->type() == QPaintEngine::CoreGraphics ) { - - CIImage *img = (CIImage*)(m_frame.handle().value()); - - if (img) { - CGContextRef cgContext = qt_mac_cg_context(painter->device()); - - if (cgContext) { - painter->beginNativePainting(); - - CGRect sRect = CGRectMake(source.x(), source.y(), source.width(), source.height()); - CGRect dRect = CGRectMake(target.x(), target.y(), target.width(), target.height()); - - NSBitmapImageRep *bitmap = [[NSBitmapImageRep alloc] initWithCIImage:img]; - - if (m_scanLineDirection == QVideoSurfaceFormat::TopToBottom) { - CGContextSaveGState( cgContext ); - CGContextTranslateCTM(cgContext, 0, dRect.origin.y + CGRectGetMaxY(dRect)); - CGContextScaleCTM(cgContext, 1, -1); - -#if (MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_4) - if (QSysInfo::MacintoshVersion > QSysInfo::MV_10_4) { - CGContextDrawImage(cgContext, dRect, [bitmap CGImage]); - } -#endif - - CGContextRestoreGState(cgContext); - } else { -#if (MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_4) - if (QSysInfo::MacintoshVersion > QSysInfo::MV_10_4) { - CGContextDrawImage(cgContext, dRect, [bitmap CGImage]); - } -#endif - } - - [bitmap release]; - - painter->endNativePainting(); - - return QAbstractVideoSurface::NoError; - } - } - } else if (painter->paintEngine()->type() == QPaintEngine::OpenGL2 || - painter->paintEngine()->type() == QPaintEngine::OpenGL) { - CIImage *img = (CIImage*)(m_frame.handle().value()); - - if (img) { - CGLContextObj cglContext = CGLGetCurrentContext(); - - if (cglContext) { - - if (!ciContext) { - CGLContextObj cglContext = CGLGetCurrentContext(); - NSOpenGLPixelFormat *nsglPixelFormat = [NSOpenGLView defaultPixelFormat]; - CGLPixelFormatObj cglPixelFormat = static_cast([nsglPixelFormat CGLPixelFormatObj]); - - ciContext = [CIContext contextWithCGLContext:cglContext - pixelFormat:cglPixelFormat - options:nil]; - - [(CIContext*)ciContext retain]; - } - - CGRect sRect = CGRectMake(source.x(), source.y(), source.width(), source.height()); - CGRect dRect = m_scanLineDirection == QVideoSurfaceFormat::TopToBottom ? - CGRectMake(target.x(), target.y()+target.height(), target.width(), -target.height()) : - CGRectMake(target.x(), target.y(), target.width(), target.height()); - - - painter->beginNativePainting(); - - [(CIContext*)ciContext drawImage:img inRect:dRect fromRect:sRect]; - - painter->endNativePainting(); - - return QAbstractVideoSurface::NoError; - } - } - } - } - - if (m_frame.handleType() == QAbstractVideoBuffer::GLTextureHandle && - (painter->paintEngine()->type() == QPaintEngine::OpenGL2 || - painter->paintEngine()->type() == QPaintEngine::OpenGL)) { - - painter->beginNativePainting(); - GLuint texture = m_frame.handle().toUInt(); - - glDisable(GL_CULL_FACE); - glEnable(GL_TEXTURE_2D); - - glBindTexture(GL_TEXTURE_2D, texture); - glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); - glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - - const float txLeft = source.left() / m_frame.width(); - const float txRight = source.right() / m_frame.width(); - const float txTop = m_scanLineDirection == QVideoSurfaceFormat::TopToBottom - ? source.top() / m_frame.height() - : source.bottom() / m_frame.height(); - const float txBottom = m_scanLineDirection == QVideoSurfaceFormat::TopToBottom - ? source.bottom() / m_frame.height() - : source.top() / m_frame.height(); - - glBegin(GL_QUADS); - QRectF rect = target; - glTexCoord2f(txLeft, txBottom); - glVertex2f(rect.topLeft().x(), rect.topLeft().y()); - glTexCoord2f(txRight, txBottom); - glVertex2f(rect.topRight().x() + 1, rect.topRight().y()); - glTexCoord2f(txRight, txTop); - glVertex2f(rect.bottomRight().x() + 1, rect.bottomRight().y() + 1); - glTexCoord2f(txLeft, txTop); - glVertex2f(rect.bottomLeft().x(), rect.bottomLeft().y() + 1); - glEnd(); - painter->endNativePainting(); - - return QAbstractVideoSurface::NoError; - } - - //fallback case, software rendering - if (m_frame.map(QAbstractVideoBuffer::ReadOnly)) { - QImage image( - m_frame.bits(), - m_imageSize.width(), - m_imageSize.height(), - m_frame.bytesPerLine(), - m_imageFormat); - - if (m_scanLineDirection == QVideoSurfaceFormat::BottomToTop) { - const QTransform oldTransform = painter->transform(); - - painter->scale(1, -1); - painter->translate(0, -target.bottom()); - painter->drawImage( - QRectF(target.x(), 0, target.width(), target.height()), image, source); - painter->setTransform(oldTransform); - } else { - painter->drawImage(target, image, source); - } - - m_frame.unmap(); - } else { - painter->fillRect(target, Qt::black); - } - return QAbstractVideoSurface::NoError; -} - -void QVideoSurfaceCoreGraphicsPainter::updateColors(int, int, int, int) -{ -} - -QT_END_NAMESPACE diff --git a/src/multimedia/base/qpaintervideosurface_mac_p.h b/src/multimedia/base/qpaintervideosurface_mac_p.h deleted file mode 100644 index 64442ed..0000000 --- a/src/multimedia/base/qpaintervideosurface_mac_p.h +++ /dev/null @@ -1,100 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtMultimedia module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QPAINTERVIDEOSURFACE_MAC_P_H -#define QPAINTERVIDEOSURFACE_MAC_P_H - -// -// W A R N I N G -// ------------- -// -// This file is not part of the Qt API. It exists purely as an -// implementation detail. This header file may change from version to -// version without notice, or even be removed. -// -// We mean it. -// - -#include "qpaintervideosurface_p.h" -#include -#include - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -class QVideoSurfaceCoreGraphicsPainter : public QVideoSurfacePainter -{ -public: - QVideoSurfaceCoreGraphicsPainter(bool glSupported); - ~QVideoSurfaceCoreGraphicsPainter(); - - QList supportedPixelFormats( - QAbstractVideoBuffer::HandleType handleType) const; - - bool isFormatSupported( - const QVideoSurfaceFormat &format, QVideoSurfaceFormat *similar) const; - - QAbstractVideoSurface::Error start(const QVideoSurfaceFormat &format); - void stop(); - - QAbstractVideoSurface::Error setCurrentFrame(const QVideoFrame &frame); - - QAbstractVideoSurface::Error paint( - const QRectF &target, QPainter *painter, const QRectF &source); - - void updateColors(int brightness, int contrast, int hue, int saturation); - -private: - void* ciContext; - QList m_imagePixelFormats; - QVideoFrame m_frame; - QSize m_imageSize; - QImage::Format m_imageFormat; - QVector m_supportedHandles; - QVideoSurfaceFormat::Direction m_scanLineDirection; -}; - -QT_END_NAMESPACE - -QT_END_HEADER - -#endif diff --git a/src/multimedia/base/qpaintervideosurface_p.h b/src/multimedia/base/qpaintervideosurface_p.h deleted file mode 100644 index caba3ba..0000000 --- a/src/multimedia/base/qpaintervideosurface_p.h +++ /dev/null @@ -1,178 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtMultimedia module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QPAINTERVIDEOSURFACE_P_H -#define QPAINTERVIDEOSURFACE_P_H - -// -// W A R N I N G -// ------------- -// -// This file is not part of the Qt API. It exists purely as an -// implementation detail. This header file may change from version to -// version without notice, or even be removed. -// -// We mean it. -// - -#include -#include -#include -#include -#include -#include - - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -class QGLContext; - -class QVideoSurfacePainter -{ -public: - virtual ~QVideoSurfacePainter(); - - virtual QList supportedPixelFormats( - QAbstractVideoBuffer::HandleType handleType) const = 0; - - virtual bool isFormatSupported( - const QVideoSurfaceFormat &format, QVideoSurfaceFormat *similar) const = 0; - - virtual QAbstractVideoSurface::Error start(const QVideoSurfaceFormat &format) = 0; - virtual void stop() = 0; - - virtual QAbstractVideoSurface::Error setCurrentFrame(const QVideoFrame &frame) = 0; - - virtual QAbstractVideoSurface::Error paint( - const QRectF &target, QPainter *painter, const QRectF &source) = 0; - - virtual void updateColors(int brightness, int contrast, int hue, int saturation) = 0; -}; - -class Q_MULTIMEDIA_EXPORT QPainterVideoSurface : public QAbstractVideoSurface -{ - Q_OBJECT -public: - explicit QPainterVideoSurface(QObject *parent = 0); - ~QPainterVideoSurface(); - - QList supportedPixelFormats( - QAbstractVideoBuffer::HandleType handleType = QAbstractVideoBuffer::NoHandle) const; - - bool isFormatSupported( - const QVideoSurfaceFormat &format, QVideoSurfaceFormat *similar = 0) const; - - bool start(const QVideoSurfaceFormat &format); - void stop(); - - bool present(const QVideoFrame &frame); - - int brightness() const; - void setBrightness(int brightness); - - int contrast() const; - void setContrast(int contrast); - - int hue() const; - void setHue(int hue); - - int saturation() const; - void setSaturation(int saturation); - - bool isReady() const; - void setReady(bool ready); - - void paint(QPainter *painter, const QRectF &target, const QRectF &source = QRectF(0, 0, 1, 1)); - -#if !defined(QT_NO_OPENGL) && !defined(QT_OPENGL_ES_1_CL) && !defined(QT_OPENGL_ES_1) - const QGLContext *glContext() const; - void setGLContext(QGLContext *context); - - enum ShaderType - { - NoShaders = 0x00, - FragmentProgramShader = 0x01, - GlslShader = 0x02 - }; - - Q_DECLARE_FLAGS(ShaderTypes, ShaderType) - - ShaderTypes supportedShaderTypes() const; - - ShaderType shaderType() const; - void setShaderType(ShaderType type); -#endif - -Q_SIGNALS: - void frameChanged(); - -private: - void createPainter(); - - QVideoSurfacePainter *m_painter; -#if !defined(QT_NO_OPENGL) && !defined(QT_OPENGL_ES_1_CL) && !defined(QT_OPENGL_ES_1) - QGLContext *m_glContext; - ShaderTypes m_shaderTypes; - ShaderType m_shaderType; -#endif - int m_brightness; - int m_contrast; - int m_hue; - int m_saturation; - - QVideoFrame::PixelFormat m_pixelFormat; - QSize m_frameSize; - QRect m_sourceRect; - bool m_colorsDirty; - bool m_ready; -}; - -#if !defined(QT_NO_OPENGL) && !defined(QT_OPENGL_ES_1_CL) && !defined(QT_OPENGL_ES_1) -Q_DECLARE_OPERATORS_FOR_FLAGS(QPainterVideoSurface::ShaderTypes) -#endif - -QT_END_NAMESPACE - -QT_END_HEADER - -#endif diff --git a/src/multimedia/base/qtmedianamespace.h b/src/multimedia/base/qtmedianamespace.h deleted file mode 100644 index 1e04da8..0000000 --- a/src/multimedia/base/qtmedianamespace.h +++ /dev/null @@ -1,194 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtMultimedia module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QTMEDIANAMESPACE_H -#define QTMEDIANAMESPACE_H - -#include -#include - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Multimedia) - -namespace QtMultimedia -{ - enum MetaData - { - // Common - Title, - SubTitle, - Author, - Comment, - Description, - Category, - Genre, - Year, - Date, - UserRating, - Keywords, - Language, - Publisher, - Copyright, - ParentalRating, - RatingOrganisation, - - // Media - Size, - MediaType, - Duration, - - // Audio - AudioBitRate, - AudioCodec, - AverageLevel, - ChannelCount, - PeakValue, - SampleRate, - - // Music - AlbumTitle, - AlbumArtist, - ContributingArtist, - Composer, - Conductor, - Lyrics, - Mood, - TrackNumber, - TrackCount, - - CoverArtUrlSmall, - CoverArtUrlLarge, - - // Image/Video - Resolution, - PixelAspectRatio, - - // Video - VideoFrameRate, - VideoBitRate, - VideoCodec, - - PosterUrl, - - // Movie - ChapterNumber, - Director, - LeadPerformer, - Writer, - - // Photos - CameraManufacturer, - CameraModel, - Event, - Subject, - Orientation, - ExposureTime, - FNumber, - ExposureProgram, - ISOSpeedRatings, - ExposureBiasValue, - DateTimeOriginal, - DateTimeDigitized, - SubjectDistance, - MeteringMode, - LightSource, - Flash, - FocalLength, - ExposureMode, - WhiteBalance, - DigitalZoomRatio, - FocalLengthIn35mmFilm, - SceneCaptureType, - GainControl, - Contrast, - Saturation, - Sharpness, - DeviceSettingDescription, - - PosterImage, - CoverArtImage, - ThumbnailImage - - }; - - enum SupportEstimate - { - NotSupported, - MaybeSupported, - ProbablySupported, - PreferredService - }; - - enum EncodingQuality - { - VeryLowQuality, - LowQuality, - NormalQuality, - HighQuality, - VeryHighQuality - }; - - enum EncodingMode - { - ConstantQualityEncoding, - ConstantBitRateEncoding, - AverageBitRateEncoding, - TwoPassEncoding - }; - - enum AvailabilityError - { - NoError, - ServiceMissingError, - BusyError, - ResourceError - }; - -} - -QT_END_NAMESPACE - -QT_END_HEADER - -#endif diff --git a/src/multimedia/base/qtmedianamespace.qdoc b/src/multimedia/base/qtmedianamespace.qdoc deleted file mode 100644 index 277b1a5..0000000 --- a/src/multimedia/base/qtmedianamespace.qdoc +++ /dev/null @@ -1,214 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtMultimedia module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -/*! - \namespace QtMultimedia - \ingroup multimedia - - \brief The QtMultimedia namespace contains miscellaneous identifiers used - throughout the Qt Multimedia library. -*/ - -/*! - \enum QtMultimedia::MetaData - - This enum provides identifiers for meta-data attributes. - - Common attributes - \value Title The title of the media. QString. - \value SubTitle The sub-title of the media. QString. - \value Author The authors of the media. QStringList. - \value Comment A user comment about the media. QString. - \value Description A description of the media. QString - \value Category The category of the media. QStringList. - \value Genre The genre of the media. QStringList. - \value Year The year of release of the media. int. - \value Date The date of the media. QDate. - \value UserRating A user rating of the media. int [0..100]. - \value Keywords A list of keywords describing the media. QStringList. - \value Language The language of media, as an ISO 639-2 code. - - \value Publisher The publisher of the media. QString. - \value Copyright The media's copyright notice. QString. - \value ParentalRating The parental rating of the media. QString. - \value RatingOrganisation The organisation responsible for the parental rating of the media. - QString. - - Media attributes - \value Size The size in bytes of the media. qint64 - \value MediaType The type of the media (audio, video, etc). QString. - \value Duration The duration in millseconds of the media. qint64. - - Audio attributes - \value AudioBitRate The bit rate of the media's audio stream in bits per second. int. - \value AudioCodec The codec of the media's audio stream. QString. - \value AverageLevel The average volume level of the media. int. - \value ChannelCount The number of channels in the media's audio stream. int. - \value PeakValue The peak volume of the media's audio stream. int - \value SampleRate The sample rate of the media's audio stream in hertz. int - - Music attributes - \value AlbumTitle The title of the album the media belongs to. QString. - \value AlbumArtist The principal artist of the album the media belongs to. QString. - \value ContributingArtist The artists contributing to the media. QStringList. - \value Composer The composer of the media. QStringList. - \value Conductor The conductor of the media. QString. - \value Lyrics The lyrics to the media. QString. - \value Mood The mood of the media. QString. - \value TrackNumber The track number of the media. int. - \value TrackCount The number of tracks on the album containing the media. int. - - \value CoverArtUrlSmall The URL of a small cover art image. QUrl. - \value CoverArtUrlLarge The URL of a large cover art image. QUrl. - \value CoverArtImage An embedded cover art image. QImage. - - Image and video attributes - \value Resolution The dimensions of an image or video. QSize. - \value PixelAspectRatio The pixel aspect ratio of an image or video. QSize. - - Video attributes - \value VideoFrameRate The frame rate of the media's video stream. qreal. - \value VideoBitRate The bit rate of the media's video stream in bits per second. int. - \value VideoCodec The codec of the media's video stream. QString. - - \value PosterUrl The URL of a poster image. QUrl. - \value PosterImage An embedded poster image. QImage. - - Movie attributes - \value ChapterNumber The chapter number of the media. int. - \value Director The director of the media. QString. - \value LeadPerformer The lead performer in the media. QStringList. - \value Writer The writer of the media. QStringList. - - Photo attributes. - \value CameraManufacturer The manufacturer of the camera used to capture the media. QString. - \value CameraModel The model of the camera used to capture the media. QString. - \value Event The event during which the media was captured. QString. - \value Subject The subject of the media. QString. - \value Orientation Orientation of image. - \value ExposureTime Exposure time, given in seconds. - \value FNumber The F Number. - \value ExposureProgram - The class of the program used by the camera to set exposure when the picture is taken. - \value ISOSpeedRatings - Indicates the ISO Speed and ISO Latitude of the camera or input device as specified in ISO 12232. - \value ExposureBiasValue - The exposure bias. - The unit is the APEX (Additive System of Photographic Exposure) setting. - \value DateTimeOriginal The date and time when the original image data was generated. - \value DateTimeDigitized The date and time when the image was stored as digital data. - \value SubjectDistance The distance to the subject, given in meters. - \value MeteringMode The metering mode. - \value LightSource - The kind of light source. - \value Flash - Status of flash when the image was shot. - \value FocalLength - The actual focal length of the lens, in mm. - \value ExposureMode - Indicates the exposure mode set when the image was shot. - \value WhiteBalance - Indicates the white balance mode set when the image was shot. - \value DigitalZoomRatio - Indicates the digital zoom ratio when the image was shot. - \value FocalLengthIn35mmFilm - Indicates the equivalent focal length assuming a 35mm film camera, in mm. - \value SceneCaptureType - Indicates the type of scene that was shot. - It can also be used to record the mode in which the image was shot. - \value GainControl - Indicates the degree of overall image gain adjustment. - \value Contrast - Indicates the direction of contrast processing applied by the camera when the image was shot. - \value Saturation - Indicates the direction of saturation processing applied by the camera when the image was shot. - \value Sharpness - Indicates the direction of sharpness processing applied by the camera when the image was shot. - \value DeviceSettingDescription - Exif tag, indicates information on the picture-taking conditions of a particular camera model. QString - - \value ThumbnailImage An embedded thumbnail image. QImage. -*/ - -/*! - \enum QtMultimedia::SupportEstimate - - Enumerates the levels of support a media service provider may have for a feature. - - \value NotSupported The feature is not supported. - \value MaybeSupported The feature may be supported. - \value ProbablySupported The feature is probably supported. - \value PreferredService The service is the preferred provider of a service. -*/ - -/*! - \enum QtMultimedia::EncodingQuality - - Enumerates quality encoding levels. - - \value VeryLowQuality - \value LowQuality - \value NormalQuality - \value HighQuality - \value VeryHighQuality -*/ - -/*! - \enum QtMultimedia::EncodingMode - - Enumerates encoding modes. - - \value ConstantQualityEncoding - \value ConstantBitRateEncoding - \value AverageBitRateEncoding - \value TwoPassEncoding -*/ - -/*! - \enum QtMultimedia::AvailabilityError - - Enumerates Service status errors. - - \value NoError - \value ServiceMissingError - \value ResourceError - \value BusyError -*/ diff --git a/src/multimedia/base/qvideodevicecontrol.cpp b/src/multimedia/base/qvideodevicecontrol.cpp deleted file mode 100644 index c0fe9a8..0000000 --- a/src/multimedia/base/qvideodevicecontrol.cpp +++ /dev/null @@ -1,155 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtMultimedia module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include - - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -/*! - \class QVideoDeviceControl - \preliminary - \since 4.7 - \brief The QVideoDeviceControl class provides an video device selector media control. - \ingroup multimedia-serv - - The QVideoDeviceControl class provides descriptions of the video devices - available on a system and allows one to be selected as the endpoint of - a media service. - - The interface name of QVideoDeviceControl is \c com.nokia.Qt.VideoDeviceControl as - defined in QVideoDeviceControl_iid. -*/ - -/*! - \macro QVideoDeviceControl_iid - - \c com.nokia.Qt.VideoDeviceControl - - Defines the interface name of the QVideoDeviceControl class. - - \relates QVideoDeviceControl -*/ - -/*! - Constructs a video device control with the given \a parent. -*/ -QVideoDeviceControl::QVideoDeviceControl(QObject *parent) - :QMediaControl(parent) -{ -} - -/*! - Destroys a video device control. -*/ -QVideoDeviceControl::~QVideoDeviceControl() -{ -} - -/*! - \fn QVideoDeviceControl::deviceCount() const - - Returns the number of available video devices; -*/ - -/*! - \fn QVideoDeviceControl::deviceName(int index) const - - Returns the name of the video device at \a index. -*/ - -/*! - \fn QVideoDeviceControl::deviceDescription(int index) const - - Returns a description of the video device at \a index. -*/ - -/*! - \fn QVideoDeviceControl::deviceIcon(int index) const - - Returns an icon for the video device at \a index. -*/ - -/*! - \fn QVideoDeviceControl::defaultDevice() const - - Returns the index of the default video device. -*/ - -/*! - \fn QVideoDeviceControl::selectedDevice() const - - Returns the index of the selected video device. -*/ - -/*! - \fn QVideoDeviceControl::setSelectedDevice(int index) - - Sets the selected video device \a index. -*/ - -/*! - \fn QVideoDeviceControl::devicesChanged() - - Signals that the list of available video devices has changed. -*/ - -/*! - \fn QVideoDeviceControl::selectedDeviceChanged(int index) - - Signals that the selected video device \a index has changed. -*/ - -/*! - \fn QVideoDeviceControl::selectedDeviceChanged(const QString &name) - - Signals that the selected video device \a name has changed. -*/ - -QT_END_NAMESPACE - -QT_END_HEADER - -#include "moc_qvideodevicecontrol.cpp" - - diff --git a/src/multimedia/base/qvideodevicecontrol.h b/src/multimedia/base/qvideodevicecontrol.h deleted file mode 100644 index ce99fd1..0000000 --- a/src/multimedia/base/qvideodevicecontrol.h +++ /dev/null @@ -1,90 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtMultimedia module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QVIDEODEVICECONTROL_H -#define QVIDEODEVICECONTROL_H - -#include - - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Multimedia) - -class Q_MULTIMEDIA_EXPORT QVideoDeviceControl : public QMediaControl -{ - Q_OBJECT - -public: - virtual ~QVideoDeviceControl(); - - virtual int deviceCount() const = 0; - - virtual QString deviceName(int index) const = 0; - virtual QString deviceDescription(int index) const = 0; - virtual QIcon deviceIcon(int index) const = 0; - - virtual int defaultDevice() const = 0; - virtual int selectedDevice() const = 0; - -public Q_SLOTS: - virtual void setSelectedDevice(int index) = 0; - -Q_SIGNALS: - void selectedDeviceChanged(int index); - void selectedDeviceChanged(const QString &deviceName); - void devicesChanged(); - -protected: - QVideoDeviceControl(QObject *parent = 0); -}; - -#define QVideoDeviceControl_iid "com.nokia.Qt.QVideoDeviceControl/1.0" -Q_MEDIA_DECLARE_CONTROL(QVideoDeviceControl, QVideoDeviceControl_iid) - - -QT_END_NAMESPACE - -QT_END_HEADER - -#endif // QVIDEODEVICECONTROL_H diff --git a/src/multimedia/base/qvideooutputcontrol.cpp b/src/multimedia/base/qvideooutputcontrol.cpp deleted file mode 100644 index 58f1527..0000000 --- a/src/multimedia/base/qvideooutputcontrol.cpp +++ /dev/null @@ -1,135 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtMultimedia module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include - - -QT_BEGIN_NAMESPACE - -/*! - \class QVideoOutputControl - \preliminary - \since 4.7 - \brief The QVideoOutputControl class provides a means of selecting the - active video output control. - - \ingroup multimedia-serv - - There are multiple controls which a QMediaService may use to output - video ony one of which may be active at one time, QVideoOutputControl - is the means by which this active control is selected. - - The possible output controls are QVideoRendererControl, - QVideoWindowControl, and QVideoWidgetControl. - - The interface name of QVideoOutputControl is \c com.nokia.Qt.QVideoOutputControl/1.0 as - defined in QVideoOutputControl_iid. - - \sa QMediaService::control(), QVideoWidget, QVideoRendererControl, - QVideoWindowControl, QVideoWidgetControl -*/ - -/*! - \macro QVideoOutputControl_iid - - \c com.nokia.Qt.QVideoOutputControl/1.0 - - Defines the interface name of the QVideoOutputControl class. - - \relates QVideoOutputControl -*/ - -/*! - \enum QVideoOutputControl::Output - - Identifies the possible render targets of a video output. - - \value NoOutput Video is not rendered. - \value WindowOutput Video is rendered to the target of a QVideoWindowControl. - \value RendererOutput Video is rendered to the target of a QVideoRendererControl. - \value WidgetOutput Video is rendered to a QWidget provided by QVideoWidgetControl. - \value UserOutput Start value for user defined video targets. - \value MaxUserOutput End value for user defined video targets. -*/ - -/*! - Constructs a new video output control with the given \a parent. -*/ -QVideoOutputControl::QVideoOutputControl(QObject *parent) - : QMediaControl(parent) -{ -} - -/*! - Destroys a video output control. -*/ -QVideoOutputControl::~QVideoOutputControl() -{ -} - -/*! - \fn QList QVideoOutputControl::availableOutputs() const - - Returns a list of available video output targets. -*/ - -/*! - \fn QVideoOutputControl::output() const - - Returns the current video output target. -*/ - -/*! - \fn QVideoOutputControl::setOutput(Output output) - - Sets the current video \a output target. -*/ - -/*! - \fn QVideoOutputControl::availableOutputsChanged(const QList &outputs) - - Signals that available set of video \a outputs has changed. -*/ - -#include "moc_qvideooutputcontrol.cpp" - -QT_END_NAMESPACE - diff --git a/src/multimedia/base/qvideooutputcontrol.h b/src/multimedia/base/qvideooutputcontrol.h deleted file mode 100644 index 805da58..0000000 --- a/src/multimedia/base/qvideooutputcontrol.h +++ /dev/null @@ -1,91 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtMultimedia module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QVIDEOOUTPUTCONTROL_H -#define QVIDEOOUTPUTCONTROL_H - -#include - - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Multimedia) - - -class Q_MULTIMEDIA_EXPORT QVideoOutputControl : public QMediaControl -{ - Q_OBJECT - -public: - enum Output - { - NoOutput, - WindowOutput, - RendererOutput, - WidgetOutput, - UserOutput = 100, - MaxUserOutput = 1000 - }; - - ~QVideoOutputControl(); - - virtual QList availableOutputs() const = 0; - - virtual Output output() const = 0; - virtual void setOutput(Output output) = 0; - -Q_SIGNALS: - void availableOutputsChanged(const QList &outputs); - -protected: - QVideoOutputControl(QObject *parent = 0); -}; - -#define QVideoOutputControl_iid "com.nokia.Qt.QVideoOutputControl/1.0" -Q_MEDIA_DECLARE_CONTROL(QVideoOutputControl, QVideoOutputControl_iid) - -QT_END_NAMESPACE - -QT_END_HEADER - -#endif diff --git a/src/multimedia/base/qvideorenderercontrol.cpp b/src/multimedia/base/qvideorenderercontrol.cpp deleted file mode 100644 index a34ef9b..0000000 --- a/src/multimedia/base/qvideorenderercontrol.cpp +++ /dev/null @@ -1,124 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtMultimedia module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include - -#include "qmediacontrol_p.h" - - -QT_BEGIN_NAMESPACE - -/*! - \class QVideoRendererControl - \preliminary - \since 4.7 - \brief The QVideoRendererControl class provides a control for rendering - to a video surface. - - \ingroup multimedia-serv - - Using the surface() property of QVideoRendererControl a QAbstractVideoSurface - may be set as the video render target of a QMediaService. - - \code - QVideoRendererControl *rendererControl = mediaService->control(); - rendererControl->setSurface(myVideoSurface); - \endcode - - QVideoRendererControl is one of number of possible video output controls, - in order to receive video it must be made the active video output - control by setting the output property of QVideoOutputControl to - \l {QVideoOutputControl::RendererOutput}{RendererOutput}. Consequently any - QMediaService that implements QVideoRendererControl must also implement - QVideoOutputControl. - - \code - QVideoOutputControl *outputControl = mediaService->control(); - outputControl->setOutput(QVideoOutputControl::RendererOutput); - \endcode - - The interface name of QVideoRendererControl is \c com.nokia.Qt.QVideoRendererControl/1.0 as - defined in QVideoRendererControl_iid. - - \sa QMediaService::control(), QVideoOutputControl, QVideoWidget -*/ - -/*! - \macro QVideoRendererControl_iid - - \c com.nokia.Qt.QVideoRendererControl/1.0 - - Defines the interface name of the QVideoRendererControl class. - - \relates QVideoRendererControl -*/ - -/*! - Constructs a new video renderer media end point with the given \a parent. -*/ -QVideoRendererControl::QVideoRendererControl(QObject *parent) - : QMediaControl(parent) -{ -} - -/*! - Destroys a video renderer media end point. -*/ -QVideoRendererControl::~QVideoRendererControl() -{ -} - -/*! - \fn QVideoRendererControl::surface() const - - Returns the surface a video producer renders to. -*/ - -/*! - \fn QVideoRendererControl::setSurface(QAbstractVideoSurface *surface) - - Sets the \a surface a video producer renders to. -*/ - -#include "moc_qvideorenderercontrol.cpp" - -QT_END_NAMESPACE - diff --git a/src/multimedia/base/qvideorenderercontrol.h b/src/multimedia/base/qvideorenderercontrol.h deleted file mode 100644 index f5ba83e..0000000 --- a/src/multimedia/base/qvideorenderercontrol.h +++ /dev/null @@ -1,77 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtMultimedia module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QVIDEORENDERERCONTROL_H -#define QVIDEORENDERERCONTROL_H - -#include - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Multimedia) - - -class QAbstractVideoSurface; - -class Q_MULTIMEDIA_EXPORT QVideoRendererControl : public QMediaControl -{ - Q_OBJECT - -public: - ~QVideoRendererControl(); - - virtual QAbstractVideoSurface *surface() const = 0; - virtual void setSurface(QAbstractVideoSurface *surface) = 0; - -protected: - QVideoRendererControl(QObject *parent = 0); -}; - -#define QVideoRendererControl_iid "com.nokia.Qt.QVideoRendererControl/1.0" -Q_MEDIA_DECLARE_CONTROL(QVideoRendererControl, QVideoRendererControl_iid) - -QT_END_NAMESPACE - -QT_END_HEADER - -#endif // QVIDEORENDERERCONTROL_H diff --git a/src/multimedia/base/qvideowidget.cpp b/src/multimedia/base/qvideowidget.cpp deleted file mode 100644 index b791abd..0000000 --- a/src/multimedia/base/qvideowidget.cpp +++ /dev/null @@ -1,944 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtMultimedia module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qvideowidget_p.h" - -#include -#include -#include -#include -#include - -#include "qpaintervideosurface_p.h" -#include -#include -#include - -#include -#include -#include -#include -#include - - -QT_BEGIN_NAMESPACE - -QVideoWidgetControlBackend::QVideoWidgetControlBackend( - QVideoWidgetControl *control, QWidget *widget) - : m_widgetControl(control) -{ - connect(control, SIGNAL(brightnessChanged(int)), widget, SLOT(_q_brightnessChanged(int))); - connect(control, SIGNAL(contrastChanged(int)), widget, SLOT(_q_contrastChanged(int))); - connect(control, SIGNAL(hueChanged(int)), widget, SLOT(_q_hueChanged(int))); - connect(control, SIGNAL(saturationChanged(int)), widget, SLOT(_q_saturationChanged(int))); - connect(control, SIGNAL(fullScreenChanged(bool)), widget, SLOT(_q_fullScreenChanged(bool))); - - QBoxLayout *layout = new QVBoxLayout; - layout->setMargin(0); - layout->setSpacing(0); - layout->addWidget(control->videoWidget()); - - widget->setLayout(layout); -} - -void QVideoWidgetControlBackend::setBrightness(int brightness) -{ - m_widgetControl->setBrightness(brightness); -} - -void QVideoWidgetControlBackend::setContrast(int contrast) -{ - m_widgetControl->setContrast(contrast); -} - -void QVideoWidgetControlBackend::setHue(int hue) -{ - m_widgetControl->setHue(hue); -} - -void QVideoWidgetControlBackend::setSaturation(int saturation) -{ - m_widgetControl->setSaturation(saturation); -} - -void QVideoWidgetControlBackend::setFullScreen(bool fullScreen) -{ - m_widgetControl->setFullScreen(fullScreen); -} - - -Qt::AspectRatioMode QVideoWidgetControlBackend::aspectRatioMode() const -{ - return m_widgetControl->aspectRatioMode(); -} - -void QVideoWidgetControlBackend::setAspectRatioMode(Qt::AspectRatioMode mode) -{ - m_widgetControl->setAspectRatioMode(mode); -} - -QRendererVideoWidgetBackend::QRendererVideoWidgetBackend( - QVideoRendererControl *control, QWidget *widget) - : m_rendererControl(control) - , m_widget(widget) - , m_surface(new QPainterVideoSurface) - , m_aspectRatioMode(Qt::KeepAspectRatio) - , m_updatePaintDevice(true) -{ - connect(this, SIGNAL(brightnessChanged(int)), m_widget, SLOT(_q_brightnessChanged(int))); - connect(this, SIGNAL(contrastChanged(int)), m_widget, SLOT(_q_contrastChanged(int))); - connect(this, SIGNAL(hueChanged(int)), m_widget, SLOT(_q_hueChanged(int))); - connect(this, SIGNAL(saturationChanged(int)), m_widget, SLOT(_q_saturationChanged(int))); - connect(m_surface, SIGNAL(frameChanged()), this, SLOT(frameChanged())); - connect(m_surface, SIGNAL(surfaceFormatChanged(QVideoSurfaceFormat)), - this, SLOT(formatChanged(QVideoSurfaceFormat))); - - m_rendererControl->setSurface(m_surface); -} - -QRendererVideoWidgetBackend::~QRendererVideoWidgetBackend() -{ - delete m_surface; -} - -void QRendererVideoWidgetBackend::clearSurface() -{ - m_rendererControl->setSurface(0); -} - -void QRendererVideoWidgetBackend::setBrightness(int brightness) -{ - m_surface->setBrightness(brightness); - - emit brightnessChanged(brightness); -} - -void QRendererVideoWidgetBackend::setContrast(int contrast) -{ - m_surface->setContrast(contrast); - - emit contrastChanged(contrast); -} - -void QRendererVideoWidgetBackend::setHue(int hue) -{ - m_surface->setHue(hue); - - emit hueChanged(hue); -} - -void QRendererVideoWidgetBackend::setSaturation(int saturation) -{ - m_surface->setSaturation(saturation); - - emit saturationChanged(saturation); -} - -Qt::AspectRatioMode QRendererVideoWidgetBackend::aspectRatioMode() const -{ - return m_aspectRatioMode; -} - -void QRendererVideoWidgetBackend::setAspectRatioMode(Qt::AspectRatioMode mode) -{ - m_aspectRatioMode = mode; - - m_widget->updateGeometry(); -} - -void QRendererVideoWidgetBackend::setFullScreen(bool) -{ -} - -QSize QRendererVideoWidgetBackend::sizeHint() const -{ - return m_surface->surfaceFormat().sizeHint(); -} - -void QRendererVideoWidgetBackend::showEvent() -{ -} - -void QRendererVideoWidgetBackend::hideEvent(QHideEvent *) -{ -#if !defined(QT_NO_OPENGL) && !defined(QT_OPENGL_ES_1_CL) && !defined(QT_OPENGL_ES_1) - m_updatePaintDevice = true; - m_surface->setGLContext(0); -#endif -} - -void QRendererVideoWidgetBackend::resizeEvent(QResizeEvent *) -{ - updateRects(); -} - -void QRendererVideoWidgetBackend::moveEvent(QMoveEvent *) -{ -} - -void QRendererVideoWidgetBackend::paintEvent(QPaintEvent *event) -{ - QPainter painter(m_widget); - - if (m_widget->testAttribute(Qt::WA_OpaquePaintEvent)) { - QRegion borderRegion = event->region(); - borderRegion = borderRegion.subtracted(m_boundingRect); - - QBrush brush = m_widget->palette().window(); - - QVector rects = borderRegion.rects(); - for (QVector::iterator it = rects.begin(), end = rects.end(); it != end; ++it) { - painter.fillRect(*it, brush); - } - } - - if (m_surface->isActive() && m_boundingRect.intersects(event->rect())) { - m_surface->paint(&painter, m_boundingRect, m_sourceRect); - - m_surface->setReady(true); - } else { - #if !defined(QT_NO_OPENGL) && !defined(QT_OPENGL_ES_1_CL) && !defined(QT_OPENGL_ES_1) - if (m_updatePaintDevice && (painter.paintEngine()->type() == QPaintEngine::OpenGL - || painter.paintEngine()->type() == QPaintEngine::OpenGL2)) { - m_updatePaintDevice = false; - - m_surface->setGLContext(const_cast(QGLContext::currentContext())); - if (m_surface->supportedShaderTypes() & QPainterVideoSurface::GlslShader) { - m_surface->setShaderType(QPainterVideoSurface::GlslShader); - } else { - m_surface->setShaderType(QPainterVideoSurface::FragmentProgramShader); - } - } -#endif - } - -} - -void QRendererVideoWidgetBackend::formatChanged(const QVideoSurfaceFormat &format) -{ - m_nativeSize = format.sizeHint(); - - updateRects(); - - m_widget->updateGeometry(); - m_widget->update(); -} - -void QRendererVideoWidgetBackend::frameChanged() -{ - m_widget->update(m_boundingRect); -} - -void QRendererVideoWidgetBackend::updateRects() -{ - QRect rect = m_widget->rect(); - - if (m_nativeSize.isEmpty()) { - m_boundingRect = QRect(); - } else if (m_aspectRatioMode == Qt::IgnoreAspectRatio) { - m_boundingRect = rect; - m_sourceRect = QRectF(0, 0, 1, 1); - } else if (m_aspectRatioMode == Qt::KeepAspectRatio) { - QSize size = m_nativeSize; - size.scale(rect.size(), Qt::KeepAspectRatio); - - m_boundingRect = QRect(0, 0, size.width(), size.height()); - m_boundingRect.moveCenter(rect.center()); - - m_sourceRect = QRectF(0, 0, 1, 1); - } else if (m_aspectRatioMode == Qt::KeepAspectRatioByExpanding) { - m_boundingRect = rect; - - QSizeF size = rect.size(); - size.scale(m_nativeSize, Qt::KeepAspectRatio); - - m_sourceRect = QRectF( - 0, 0, size.width() / m_nativeSize.width(), size.height() / m_nativeSize.height()); - m_sourceRect.moveCenter(QPointF(0.5, 0.5)); - } -} - -QWindowVideoWidgetBackend::QWindowVideoWidgetBackend(QVideoWindowControl *control, QWidget *widget) - : m_windowControl(control) - , m_widget(widget) - , m_aspectRatioMode(Qt::KeepAspectRatio) -{ - connect(control, SIGNAL(brightnessChanged(int)), m_widget, SLOT(_q_brightnessChanged(int))); - connect(control, SIGNAL(contrastChanged(int)), m_widget, SLOT(_q_contrastChanged(int))); - connect(control, SIGNAL(hueChanged(int)), m_widget, SLOT(_q_hueChanged(int))); - connect(control, SIGNAL(saturationChanged(int)), m_widget, SLOT(_q_saturationChanged(int))); - connect(control, SIGNAL(fullScreenChanged(bool)), m_widget, SLOT(_q_fullScreenChanged(bool))); - connect(control, SIGNAL(nativeSizeChanged()), m_widget, SLOT(_q_dimensionsChanged())); -} - -QWindowVideoWidgetBackend::~QWindowVideoWidgetBackend() -{ -} - -void QWindowVideoWidgetBackend::setBrightness(int brightness) -{ - m_windowControl->setBrightness(brightness); -} - -void QWindowVideoWidgetBackend::setContrast(int contrast) -{ - m_windowControl->setContrast(contrast); -} - -void QWindowVideoWidgetBackend::setHue(int hue) -{ - m_windowControl->setHue(hue); -} - -void QWindowVideoWidgetBackend::setSaturation(int saturation) -{ - m_windowControl->setSaturation(saturation); -} - -void QWindowVideoWidgetBackend::setFullScreen(bool fullScreen) -{ - m_windowControl->setFullScreen(fullScreen); -} - -Qt::AspectRatioMode QWindowVideoWidgetBackend::aspectRatioMode() const -{ - return m_windowControl->aspectRatioMode(); -} - -void QWindowVideoWidgetBackend::setAspectRatioMode(Qt::AspectRatioMode mode) -{ - m_windowControl->setAspectRatioMode(mode); -} - -QSize QWindowVideoWidgetBackend::sizeHint() const -{ - return m_windowControl->nativeSize(); -} - -void QWindowVideoWidgetBackend::showEvent() -{ - m_windowControl->setWinId(m_widget->winId()); - - m_windowControl->setDisplayRect(m_widget->rect()); -} - -void QWindowVideoWidgetBackend::hideEvent(QHideEvent *) -{ -} - -void QWindowVideoWidgetBackend::moveEvent(QMoveEvent *) -{ - m_windowControl->setDisplayRect(m_widget->rect()); -} - -void QWindowVideoWidgetBackend::resizeEvent(QResizeEvent *) -{ - m_windowControl->setDisplayRect(m_widget->rect()); -} - -void QWindowVideoWidgetBackend::paintEvent(QPaintEvent *event) -{ - if (m_widget->testAttribute(Qt::WA_OpaquePaintEvent)) { - QPainter painter(m_widget); - - painter.fillRect(event->rect(), m_widget->palette().window()); - } - - m_windowControl->repaint(); - - event->accept(); -} - -void QVideoWidgetPrivate::setCurrentControl(QVideoWidgetControlInterface *control) -{ - if (currentControl != control) { - currentControl = control; - - currentControl->setBrightness(brightness); - currentControl->setContrast(contrast); - currentControl->setHue(hue); - currentControl->setSaturation(saturation); - currentControl->setAspectRatioMode(aspectRatioMode); - } -} - -void QVideoWidgetPrivate::show() -{ - if (outputControl) { - if (widgetBackend != 0) { - setCurrentControl(widgetBackend); - outputControl->setOutput(QVideoOutputControl::WidgetOutput); - } else if (windowBackend != 0 && (q_func()->window() == 0 - || !q_func()->window()->testAttribute(Qt::WA_DontShowOnScreen))) { - windowBackend->showEvent(); - currentBackend = windowBackend; - setCurrentControl(windowBackend); - outputControl->setOutput(QVideoOutputControl::WindowOutput); - } else if (rendererBackend != 0) { - rendererBackend->showEvent(); - currentBackend = rendererBackend; - setCurrentControl(rendererBackend); - outputControl->setOutput(QVideoOutputControl::RendererOutput); - } else { - outputControl->setOutput(QVideoOutputControl::NoOutput); - } - } -} - -void QVideoWidgetPrivate::clearService() -{ - if (service) { - QObject::disconnect(service, SIGNAL(destroyed()), q_func(), SLOT(_q_serviceDestroyed())); - - if (outputControl) - outputControl->setOutput(QVideoOutputControl::NoOutput); - - if (widgetBackend) { - QLayout *layout = q_func()->layout(); - - for (QLayoutItem *item = layout->takeAt(0); item; item = layout->takeAt(0)) { - item->widget()->setParent(0); - delete item; - } - delete layout; - - delete widgetBackend; - widgetBackend = 0; - } - - delete windowBackend; - windowBackend = 0; - - if (rendererBackend) { - rendererBackend->clearSurface(); - - delete rendererBackend; - rendererBackend = 0; - } - - currentBackend = 0; - currentControl = 0; - outputControl = 0; - service = 0; - } -} - -void QVideoWidgetPrivate::_q_serviceDestroyed() -{ - if (widgetBackend) { - delete q_func()->layout(); - - delete widgetBackend; - widgetBackend = 0; - } - - delete windowBackend; - windowBackend = 0; - - delete rendererBackend; - rendererBackend = 0; - - currentControl = 0; - currentBackend = 0; - outputControl = 0; - service = 0; -} - -void QVideoWidgetPrivate::_q_mediaObjectDestroyed() -{ - mediaObject = 0; - clearService(); -} - -void QVideoWidgetPrivate::_q_brightnessChanged(int b) -{ - if (b != brightness) - emit q_func()->brightnessChanged(brightness = b); -} - -void QVideoWidgetPrivate::_q_contrastChanged(int c) -{ - if (c != contrast) - emit q_func()->contrastChanged(contrast = c); -} - -void QVideoWidgetPrivate::_q_hueChanged(int h) -{ - if (h != hue) - emit q_func()->hueChanged(hue = h); -} - -void QVideoWidgetPrivate::_q_saturationChanged(int s) -{ - if (s != saturation) - emit q_func()->saturationChanged(saturation = s); -} - - -void QVideoWidgetPrivate::_q_fullScreenChanged(bool fullScreen) -{ - if (!fullScreen && q_func()->isFullScreen()) - q_func()->showNormal(); -} - -void QVideoWidgetPrivate::_q_dimensionsChanged() -{ - q_func()->updateGeometry(); - q_func()->update(); -} - -/*! - \class QVideoWidget - \preliminary - \since 4.7 - \brief The QVideoWidget class provides a widget which presents video - produced by a media object. - \ingroup multimedia - - Attaching a QVideoWidget to a QMediaObject allows it to display the - video or image output of that media object. A QVideoWidget is attached - to media object by passing a pointer to the QMediaObject in its - constructor, and detached by destroying the QVideoWidget. - - \code - player = new QMediaPlayer; - - widget = new QVideoWidget(player); - widget->show(); - - player->setMedia(QUrl("http://example.com/movie.mp4")); - player->play(); - \endcode - - \bold {Note}: Only a single display output can be attached to a media - object at one time. - - \sa QMediaObject, QMediaPlayer, QGraphicsVideoItem -*/ - -/*! - Constructs a new video widget. - - The \a parent is passed to QWidget. -*/ -QVideoWidget::QVideoWidget(QWidget *parent) - : QWidget(parent, 0) - , d_ptr(new QVideoWidgetPrivate) -{ - d_ptr->q_ptr = this; -} - -/*! - Destroys a video widget. -*/ -QVideoWidget::~QVideoWidget() -{ - setMediaObject(0); - delete d_ptr; -} - -/*! - \property QVideoWidget::mediaObject - \brief the media object which provides the video displayed by a widget. -*/ - -QMediaObject *QVideoWidget::mediaObject() const -{ - return d_func()->mediaObject; -} - -void QVideoWidget::setMediaObject(QMediaObject *object) -{ - Q_D(QVideoWidget); - - if (object == d->mediaObject) - return; - - if (d->mediaObject) { - disconnect(d->mediaObject, SIGNAL(destroyed()), this, SLOT(_q_mediaObjectDestroyed())); - d->mediaObject->unbind(this); - } - - d->clearService(); - - d->mediaObject = object; - - if (d->mediaObject) { - d->service = d->mediaObject->service(); - - connect(d->mediaObject, SIGNAL(destroyed()), this, SLOT(_q_mediaObjectDestroyed())); - d->mediaObject->bind(this); - } - - if (d->service) { - connect(d->service, SIGNAL(destroyed()), SLOT(_q_serviceDestroyed())); - - d->outputControl = qobject_cast( - d->service->control(QVideoOutputControl_iid)); - - QVideoWidgetControl *widgetControl = qobject_cast( - d->service->control(QVideoWidgetControl_iid)); - - if (widgetControl != 0) { - d->widgetBackend = new QVideoWidgetControlBackend(widgetControl, this); - } else { - QVideoWindowControl *windowControl = qobject_cast( - d->service->control(QVideoWindowControl_iid)); - - if (windowControl != 0) - d->windowBackend = new QWindowVideoWidgetBackend(windowControl, this); - - QVideoRendererControl *rendererControl = qobject_cast( - d->service->control(QVideoRendererControl_iid)); - - if (rendererControl != 0) - d->rendererBackend = new QRendererVideoWidgetBackend(rendererControl, this); - } - - if (isVisible()) - d->show(); - } -} - -/*! - \property QVideoWidget::aspectRatioMode - \brief how video is scaled with respect to its aspect ratio. -*/ - -Qt::AspectRatioMode QVideoWidget::aspectRatioMode() const -{ - return d_func()->aspectRatioMode; -} - -void QVideoWidget::setAspectRatioMode(Qt::AspectRatioMode mode) -{ - Q_D(QVideoWidget); - - if (d->currentControl) { - d->currentControl->setAspectRatioMode(mode); - d->aspectRatioMode = d->currentControl->aspectRatioMode(); - } else { - d->aspectRatioMode = mode; - } -} - -/*! - \property QVideoWidget::fullScreen - \brief whether video display is confined to a window or is fullScreen. -*/ - -void QVideoWidget::setFullScreen(bool fullScreen) -{ - Q_D(QVideoWidget); - - if (fullScreen) { - Qt::WindowFlags flags = windowFlags(); - - d->nonFullScreenFlags = flags & (Qt::Window | Qt::SubWindow); - flags |= Qt::Window; - flags &= ~Qt::SubWindow; - setWindowFlags(flags); - - showFullScreen(); - } else { - showNormal(); - } -} - -/*! - \fn QVideoWidget::fullScreenChanged(bool fullScreen) - - Signals that the \a fullScreen mode of a video widget has changed. - - \sa fullScreen -*/ - -/*! - \property QVideoWidget::brightness - \brief an adjustment to the brightness of displayed video. - - Valid brightness values range between -100 and 100, the default is 0. -*/ - -int QVideoWidget::brightness() const -{ - return d_func()->brightness; -} - -void QVideoWidget::setBrightness(int brightness) -{ - Q_D(QVideoWidget); - - int boundedBrightness = qBound(-100, brightness, 100); - - if (d->currentControl) - d->currentControl->setBrightness(boundedBrightness); - else if (d->brightness != boundedBrightness) - emit brightnessChanged(d->brightness = boundedBrightness); -} - -/*! - \fn QVideoWidget::brightnessChanged(int brightness) - - Signals that a video widgets's \a brightness adjustment has changed. - - \sa brightness -*/ - -/*! - \property QVideoWidget::contrast - \brief an adjustment to the contrast of displayed video. - - Valid contrast values range between -100 and 100, the default is 0. - -*/ - -int QVideoWidget::contrast() const -{ - return d_func()->contrast; -} - -void QVideoWidget::setContrast(int contrast) -{ - Q_D(QVideoWidget); - - int boundedContrast = qBound(-100, contrast, 100); - - if (d->currentControl) - d->currentControl->setContrast(boundedContrast); - else if (d->contrast != boundedContrast) - emit contrastChanged(d->contrast = boundedContrast); -} - -/*! - \fn QVideoWidget::contrastChanged(int contrast) - - Signals that a video widgets's \a contrast adjustment has changed. - - \sa contrast -*/ - -/*! - \property QVideoWidget::hue - \brief an adjustment to the hue of displayed video. - - Valid hue values range between -100 and 100, the default is 0. -*/ - -int QVideoWidget::hue() const -{ - return d_func()->hue; -} - -void QVideoWidget::setHue(int hue) -{ - Q_D(QVideoWidget); - - int boundedHue = qBound(-100, hue, 100); - - if (d->currentControl) - d->currentControl->setHue(boundedHue); - else if (d->hue != boundedHue) - emit hueChanged(d->hue = boundedHue); -} - -/*! - \fn QVideoWidget::hueChanged(int hue) - - Signals that a video widgets's \a hue has changed. - - \sa hue -*/ - -/*! - \property QVideoWidget::saturation - \brief an adjustment to the saturation of displayed video. - - Valid saturation values range between -100 and 100, the default is 0. -*/ - -int QVideoWidget::saturation() const -{ - return d_func()->saturation; -} - -void QVideoWidget::setSaturation(int saturation) -{ - Q_D(QVideoWidget); - - int boundedSaturation = qBound(-100, saturation, 100); - - if (d->currentControl) - d->currentControl->setSaturation(boundedSaturation); - else if (d->saturation != boundedSaturation) - emit saturationChanged(d->saturation = boundedSaturation); - -} - -/*! - \fn QVideoWidget::saturationChanged(int saturation) - - Signals that a video widgets's \a saturation has changed. - - \sa saturation -*/ - -/*! - Returns the size hint for the current back end, - if there is one, or else the size hint from QWidget. - */ -QSize QVideoWidget::sizeHint() const -{ - Q_D(const QVideoWidget); - - if (d->currentBackend) - return d->currentBackend->sizeHint(); - else - return QWidget::sizeHint(); - - -} - -/*! - \reimp - \internal - */ -bool QVideoWidget::event(QEvent *event) -{ - Q_D(QVideoWidget); - - if (event->type() == QEvent::WindowStateChange) { - Qt::WindowFlags flags = windowFlags(); - - if (windowState() & Qt::WindowFullScreen) { - if (d->currentControl) - d->currentControl->setFullScreen(true); - - if (!d->wasFullScreen) - emit fullScreenChanged(d->wasFullScreen = true); - } else { - if (d->currentControl) - d->currentControl->setFullScreen(false); - - if (d->wasFullScreen) { - flags &= ~(Qt::Window | Qt::SubWindow); //clear the flags... - flags |= d->nonFullScreenFlags; //then we reset the flags (window and subwindow) - setWindowFlags(flags); - - emit fullScreenChanged(d->wasFullScreen = false); - } - } - } - return QWidget::event(event); -} - -/*! - Handles the show \a event. - */ -void QVideoWidget::showEvent(QShowEvent *event) -{ - Q_D(QVideoWidget); - - QWidget::showEvent(event); - - d->show(); - -} - -/*! - - Handles the hide \a event. -*/ -void QVideoWidget::hideEvent(QHideEvent *event) -{ - Q_D(QVideoWidget); - - if (d->currentBackend) - d->currentBackend->hideEvent(event); - - QWidget::hideEvent(event); -} - -/*! - Handles the resize \a event. - */ -void QVideoWidget::resizeEvent(QResizeEvent *event) -{ - Q_D(QVideoWidget); - - QWidget::resizeEvent(event); - - if (d->currentBackend) - d->currentBackend->resizeEvent(event); -} - -/*! - Handles the move \a event. - */ -void QVideoWidget::moveEvent(QMoveEvent *event) -{ - Q_D(QVideoWidget); - - if (d->currentBackend) - d->currentBackend->moveEvent(event); -} - -/*! - Handles the paint \a event. - */ -void QVideoWidget::paintEvent(QPaintEvent *event) -{ - Q_D(QVideoWidget); - - if (d->currentBackend) { - d->currentBackend->paintEvent(event); - } else if (testAttribute(Qt::WA_OpaquePaintEvent)) { - QPainter painter(this); - - painter.fillRect(event->rect(), palette().window()); - } -} - -#include "moc_qvideowidget.cpp" -#include "moc_qvideowidget_p.cpp" - -QT_END_NAMESPACE - diff --git a/src/multimedia/base/qvideowidget.h b/src/multimedia/base/qvideowidget.h deleted file mode 100644 index 4b24bcb..0000000 --- a/src/multimedia/base/qvideowidget.h +++ /dev/null @@ -1,131 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtMultimedia module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QVIDEOWIDGET_H -#define QVIDEOWIDGET_H - -#include - - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Multimedia) - - -class QMediaObject; - -class QVideoWidgetPrivate; -class Q_MULTIMEDIA_EXPORT QVideoWidget : public QWidget -{ - Q_OBJECT - Q_PROPERTY(QMediaObject* mediaObject READ mediaObject WRITE setMediaObject) - Q_PROPERTY(bool fullScreen READ isFullScreen WRITE setFullScreen NOTIFY fullScreenChanged) - Q_PROPERTY(Qt::AspectRatioMode aspectRatioMode READ aspectRatioMode WRITE setAspectRatioMode NOTIFY aspectRatioModeChanged) - Q_PROPERTY(int brightness READ brightness WRITE setBrightness NOTIFY brightnessChanged) - Q_PROPERTY(int contrast READ contrast WRITE setContrast NOTIFY contrastChanged) - Q_PROPERTY(int hue READ hue WRITE setHue NOTIFY hueChanged) - Q_PROPERTY(int saturation READ saturation WRITE setSaturation NOTIFY saturationChanged) - -public: - QVideoWidget(QWidget *parent = 0); - ~QVideoWidget(); - - QMediaObject *mediaObject() const; - void setMediaObject(QMediaObject *object); - -#ifdef Q_QDOC - bool isFullScreen() const; -#endif - - Qt::AspectRatioMode aspectRatioMode() const; - - int brightness() const; - int contrast() const; - int hue() const; - int saturation() const; - - QSize sizeHint() const; - -public Q_SLOTS: - void setFullScreen(bool fullScreen); - void setAspectRatioMode(Qt::AspectRatioMode mode); - void setBrightness(int brightness); - void setContrast(int contrast); - void setHue(int hue); - void setSaturation(int saturation); - -Q_SIGNALS: - void fullScreenChanged(bool fullScreen); - void brightnessChanged(int brightness); - void contrastChanged(int contrast); - void hueChanged(int hue); - void saturationChanged(int saturation); - -protected: - bool event(QEvent *event); - void showEvent(QShowEvent *event); - void hideEvent(QHideEvent *event); - void resizeEvent(QResizeEvent *event); - void moveEvent(QMoveEvent *event); - void paintEvent(QPaintEvent *event); - -protected: - QVideoWidgetPrivate *d_ptr; - -private: - Q_DECLARE_PRIVATE(QVideoWidget) - Q_PRIVATE_SLOT(d_func(), void _q_serviceDestroyed()) - Q_PRIVATE_SLOT(d_func(), void _q_mediaObjectDestroyed()) - Q_PRIVATE_SLOT(d_func(), void _q_brightnessChanged(int)) - Q_PRIVATE_SLOT(d_func(), void _q_contrastChanged(int)) - Q_PRIVATE_SLOT(d_func(), void _q_hueChanged(int)) - Q_PRIVATE_SLOT(d_func(), void _q_saturationChanged(int)) - Q_PRIVATE_SLOT(d_func(), void _q_fullScreenChanged(bool)) - Q_PRIVATE_SLOT(d_func(), void _q_dimensionsChanged()); -}; - -QT_END_NAMESPACE - -QT_END_HEADER - -#endif diff --git a/src/multimedia/base/qvideowidget_p.h b/src/multimedia/base/qvideowidget_p.h deleted file mode 100644 index 44fd1cd..0000000 --- a/src/multimedia/base/qvideowidget_p.h +++ /dev/null @@ -1,271 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtMultimedia module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QVIDEOWIDGET_P_H -#define QVIDEOWIDGET_P_H - -// -// W A R N I N G -// ------------- -// -// This file is not part of the Qt API. It exists purely as an -// implementation detail. This header file may change from version to -// version without notice, or even be removed. -// -// We mean it. -// - -#include - -#ifndef QT_NO_OPENGL -#include -#endif - -#include "qpaintervideosurface_p.h" - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - - -class QVideoWidgetControlInterface -{ -public: - virtual ~QVideoWidgetControlInterface() {} - - virtual void setBrightness(int brightness) = 0; - virtual void setContrast(int contrast) = 0; - virtual void setHue(int hue) = 0; - virtual void setSaturation(int saturation) = 0; - - virtual void setFullScreen(bool fullScreen) = 0; - - virtual Qt::AspectRatioMode aspectRatioMode() const = 0; - virtual void setAspectRatioMode(Qt::AspectRatioMode mode) = 0; -}; - -class QVideoWidgetBackend : public QObject, public QVideoWidgetControlInterface -{ - Q_OBJECT - -public: - virtual QSize sizeHint() const = 0; - - virtual void showEvent() = 0; - virtual void hideEvent(QHideEvent *event) = 0; - virtual void resizeEvent(QResizeEvent *event) = 0; - virtual void moveEvent(QMoveEvent *event) = 0; - virtual void paintEvent(QPaintEvent *event) = 0; -}; - -class QVideoWidgetControl; - -class QVideoWidgetControlBackend : public QObject, public QVideoWidgetControlInterface -{ - Q_OBJECT -public: - QVideoWidgetControlBackend(QVideoWidgetControl *control, QWidget *widget); - - void setBrightness(int brightness); - void setContrast(int contrast); - void setHue(int hue); - void setSaturation(int saturation); - - void setFullScreen(bool fullScreen); - - Qt::AspectRatioMode aspectRatioMode() const; - void setAspectRatioMode(Qt::AspectRatioMode mode); - -private: - QVideoWidgetControl *m_widgetControl; -}; - - -class QVideoRendererControl; - -class QRendererVideoWidgetBackend : public QVideoWidgetBackend -{ - Q_OBJECT -public: - QRendererVideoWidgetBackend(QVideoRendererControl *control, QWidget *widget); - ~QRendererVideoWidgetBackend(); - - void clearSurface(); - - void setBrightness(int brightness); - void setContrast(int contrast); - void setHue(int hue); - void setSaturation(int saturation); - - void setFullScreen(bool fullScreen); - - Qt::AspectRatioMode aspectRatioMode() const; - void setAspectRatioMode(Qt::AspectRatioMode mode); - - QSize sizeHint() const; - - void showEvent(); - void hideEvent(QHideEvent *event); - void resizeEvent(QResizeEvent *event); - void moveEvent(QMoveEvent *event); - void paintEvent(QPaintEvent *event); - -Q_SIGNALS: - void fullScreenChanged(bool fullScreen); - void brightnessChanged(int brightness); - void contrastChanged(int contrast); - void hueChanged(int hue); - void saturationChanged(int saturation); - -private Q_SLOTS: - void formatChanged(const QVideoSurfaceFormat &format); - void frameChanged(); - -private: - void updateRects(); - - QVideoRendererControl *m_rendererControl; - QWidget *m_widget; - QPainterVideoSurface *m_surface; - Qt::AspectRatioMode m_aspectRatioMode; - QRect m_boundingRect; - QRectF m_sourceRect; - QSize m_nativeSize; - bool m_updatePaintDevice; -}; - -class QVideoWindowControl; - -class QWindowVideoWidgetBackend : public QVideoWidgetBackend -{ - Q_OBJECT -public: - QWindowVideoWidgetBackend(QVideoWindowControl *control, QWidget *widget); - ~QWindowVideoWidgetBackend(); - - void setBrightness(int brightness); - void setContrast(int contrast); - void setHue(int hue); - void setSaturation(int saturation); - - void setFullScreen(bool fullScreen); - - Qt::AspectRatioMode aspectRatioMode() const; - void setAspectRatioMode(Qt::AspectRatioMode mode); - - QSize sizeHint() const; - - void showEvent(); - void hideEvent(QHideEvent *event); - void resizeEvent(QResizeEvent *event); - void moveEvent(QMoveEvent *event); - void paintEvent(QPaintEvent *event); - -private: - QVideoWindowControl *m_windowControl; - QWidget *m_widget; - Qt::AspectRatioMode m_aspectRatioMode; - QSize m_pixelAspectRatio; -}; - -class QMediaService; -class QVideoOutputControl; - -class QVideoWidgetPrivate -{ - Q_DECLARE_PUBLIC(QVideoWidget) -public: - QVideoWidgetPrivate() - : q_ptr(0) - , mediaObject(0) - , service(0) - , outputControl(0) - , widgetBackend(0) - , windowBackend(0) - , rendererBackend(0) - , currentControl(0) - , currentBackend(0) - , brightness(0) - , contrast(0) - , hue(0) - , saturation(0) - , aspectRatioMode(Qt::KeepAspectRatio) - , nonFullScreenFlags(0) - , wasFullScreen(false) - { - } - - QVideoWidget *q_ptr; - QMediaObject *mediaObject; - QMediaService *service; - QVideoOutputControl *outputControl; - QVideoWidgetControlBackend *widgetBackend; - QWindowVideoWidgetBackend *windowBackend; - QRendererVideoWidgetBackend *rendererBackend; - QVideoWidgetControlInterface *currentControl; - QVideoWidgetBackend *currentBackend; - int brightness; - int contrast; - int hue; - int saturation; - Qt::AspectRatioMode aspectRatioMode; - Qt::WindowFlags nonFullScreenFlags; - bool wasFullScreen; - - void setCurrentControl(QVideoWidgetControlInterface *control); - void show(); - void clearService(); - - void _q_serviceDestroyed(); - void _q_mediaObjectDestroyed(); - void _q_brightnessChanged(int brightness); - void _q_contrastChanged(int contrast); - void _q_hueChanged(int hue); - void _q_saturationChanged(int saturation); - void _q_fullScreenChanged(bool fullScreen); - void _q_dimensionsChanged(); -}; - -QT_END_NAMESPACE - -QT_END_HEADER - -#endif diff --git a/src/multimedia/base/qvideowidgetcontrol.cpp b/src/multimedia/base/qvideowidgetcontrol.cpp deleted file mode 100644 index e8957dc..0000000 --- a/src/multimedia/base/qvideowidgetcontrol.cpp +++ /dev/null @@ -1,235 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtMultimedia module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include -#include "qmediacontrol_p.h" - - -QT_BEGIN_NAMESPACE - -/*! - \class QVideoWidgetControl - \preliminary - \since 4.7 - \brief The QVideoWidgetControl class provides a media control which - implements a video widget. - - \ingroup multimedia-serv - - The videoWidget() property of QVideoWidgetControl provides a pointer to - a video widget implemented by the control's media service. This widget - is owned by the media service and so care should be taken not to delete it. - - \code - QVideoWidgetControl *widgetControl = mediaService->control(); - - layout->addWidget(widgetControl->widget()); - \endcode - - QVideoWidgetControl is one of number of possible video output controls, - in order to receive video it must be made the active video output - control by setting the output property of QVideoOutputControl to \l {QVideoOutputControl::WidgetOutput}{WidgetOutput}. Consequently any - QMediaService that implements QVideoWidgetControl must also implement - QVideoOutputControl. - - The interface name of QVideoWidgetControl is \c com.nokia.Qt.QVideoWidgetControl/1.0 as - defined in QVideoWidgetControl_iid. - - \sa QMediaService::control(), QVideoOutputControl, QVideoWidget -*/ - -/*! - \macro QVideoWidgetControl_iid - - \c com.nokia.Qt.QVideoWidgetControl/1.0 - - Defines the interface name of the QVideoWidgetControl class. - - \relates QVideoWidgetControl -*/ - -/*! - Constructs a new video widget control with the given \a parent. -*/ -QVideoWidgetControl::QVideoWidgetControl(QObject *parent) - :QMediaControl(parent) -{ -} - -/*! - Destroys a video widget control. -*/ -QVideoWidgetControl::~QVideoWidgetControl() -{ -} - -/*! - \fn QVideoWidgetControl::isFullScreen() const - - Returns true if the video is shown using the complete screen. -*/ - -/*! - \fn QVideoWidgetControl::setFullScreen(bool fullScreen) - - Sets whether a video widget is in \a fullScreen mode. -*/ - -/*! - \fn QVideoWidgetControl::fullScreenChanged(bool fullScreen) - - Signals that the \a fullScreen state of a video widget has changed. -*/ - -/*! - \fn QVideoWidgetControl::aspectRatioMode() const - - Returns how video is scaled to fit the widget with respect to its aspect ratio. -*/ - -/*! - \fn QVideoWidgetControl::setAspectRatioMode(Qt::AspectRatioMode mode) - - Sets the aspect ratio \a mode which determines how video is scaled to the fit the widget with - respect to its aspect ratio. -*/ - -/*! - \fn QVideoWidgetControl::brightness() const - - Returns the brightness adjustment applied to a video. - - Valid brightness values range between -100 and 100, the default is 0. -*/ - -/*! - \fn QVideoWidgetControl::setBrightness(int brightness) - - Sets a \a brightness adjustment for a video. - - Valid brightness values range between -100 and 100, the default is 0. -*/ - -/*! - \fn QVideoWidgetControl::brightnessChanged(int brightness) - - Signals that a video widget's \a brightness adjustment has changed. -*/ - -/*! - \fn QVideoWidgetControl::contrast() const - - Returns the contrast adjustment applied to a video. - - Valid contrast values range between -100 and 100, the default is 0. -*/ - -/*! - \fn QVideoWidgetControl::setContrast(int contrast) - - Sets the contrast adjustment for a video widget to \a contrast. - - Valid contrast values range between -100 and 100, the default is 0. -*/ - - -/*! - \fn QVideoWidgetControl::contrastChanged(int contrast) - - Signals that a video widget's \a contrast adjustment has changed. -*/ - -/*! - \fn QVideoWidgetControl::hue() const - - Returns the hue adjustment applied to a video widget. - - Value hue values range between -100 and 100, the default is 0. -*/ - -/*! - \fn QVideoWidgetControl::setHue(int hue) - - Sets a \a hue adjustment for a video widget. - - Valid hue values range between -100 and 100, the default is 0. -*/ - - -/*! - \fn QVideoWidgetControl::hueChanged(int hue) - - Signals that a video widget's \a hue adjustment has changed. -*/ - -/*! - \fn QVideoWidgetControl::saturation() const - - Returns the saturation adjustment applied to a video widget. - - Value saturation values range between -100 and 100, the default is 0. -*/ - - -/*! - \fn QVideoWidgetControl::setSaturation(int saturation) - - Sets a \a saturation adjustment for a video widget. - - Valid saturation values range between -100 and 100, the default is 0. -*/ - -/*! - \fn QVideoWidgetControl::saturationChanged(int saturation) - - Signals that a video widget's \a saturation adjustment has changed. -*/ - -/*! - \fn QVideoWidgetControl::videoWidget() - - Returns the QWidget. -*/ - -#include "moc_qvideowidgetcontrol.cpp" - -QT_END_NAMESPACE - diff --git a/src/multimedia/base/qvideowidgetcontrol.h b/src/multimedia/base/qvideowidgetcontrol.h deleted file mode 100644 index 4c0a6c6..0000000 --- a/src/multimedia/base/qvideowidgetcontrol.h +++ /dev/null @@ -1,105 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtMultimedia module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QVIDEOWIDGETCONTROL_H -#define QVIDEOWIDGETCONTROL_H - -#include - -#include -#include - - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Multimedia) - - -class QVideoWidgetControlPrivate; - -class Q_MULTIMEDIA_EXPORT QVideoWidgetControl : public QMediaControl -{ - Q_OBJECT - -public: - virtual ~QVideoWidgetControl(); - - virtual QWidget *videoWidget() = 0; - - virtual Qt::AspectRatioMode aspectRatioMode() const = 0; - virtual void setAspectRatioMode(Qt::AspectRatioMode mode) = 0; - - virtual bool isFullScreen() const = 0; - virtual void setFullScreen(bool fullScreen) = 0; - - virtual int brightness() const = 0; - virtual void setBrightness(int brightness) = 0; - - virtual int contrast() const = 0; - virtual void setContrast(int contrast) = 0; - - virtual int hue() const = 0; - virtual void setHue(int hue) = 0; - - virtual int saturation() const = 0; - virtual void setSaturation(int saturation) = 0; - -Q_SIGNALS: - void fullScreenChanged(bool fullScreen); - void brightnessChanged(int brightness); - void contrastChanged(int contrast); - void hueChanged(int hue); - void saturationChanged(int saturation); - -protected: - QVideoWidgetControl(QObject *parent = 0); -}; - -#define QVideoWidgetControl_iid "com.nokia.Qt.QVideoWidgetControl/1.0" -Q_MEDIA_DECLARE_CONTROL(QVideoWidgetControl, QVideoWidgetControl_iid) - -QT_END_NAMESPACE - -QT_END_HEADER - -#endif diff --git a/src/multimedia/base/qvideowindowcontrol.cpp b/src/multimedia/base/qvideowindowcontrol.cpp deleted file mode 100644 index c74a0d5..0000000 --- a/src/multimedia/base/qvideowindowcontrol.cpp +++ /dev/null @@ -1,275 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtMultimedia module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include - - -QT_BEGIN_NAMESPACE - -/*! - \class QVideoWindowControl - \preliminary - \since 4.7 - \ingroup multimedia-serv - \brief The QVideoWindowControl class provides a media control for rendering video to a window. - - - The winId() property QVideoWindowControl allows a platform specific - window ID to be set as the video render target of a QMediaService. The - displayRect() property is used to set the region of the window the - video should be rendered to, and the aspectRatioMode() property - indicates how the video should be scaled to fit the displayRect(). - - \code - QVideoWindowControl *windowControl = mediaService->control(); - windowControl->setWinId(widget->winId()); - windowControl->setDisplayRect(widget->rect()); - windowControl->setAspectRatioMode(Qt::KeepAspectRatio); - \endcode - - QVideoWindowControl is one of number of possible video output controls, - in order to receive video it must be made the active video output - control by setting the output property of QVideoOutputControl to \l {QVideoOutputControl::WindowOutput}{WindowOutput}. - Consequently any QMediaService that implements QVideoWindowControl must - also implement QVideoOutputControl. - - \code - QVideoOutputControl *outputControl = mediaService->control(); - outputControl->setOutput(QVideoOutputControl::WindowOutput); - \endcode - - The interface name of QVideoWindowControl is \c com.nokia.Qt.QVideoWindowControl/1.0 as - defined in QVideoWindowControl_iid. - - \sa QMediaService::control(), QVideoOutputControl, QVideoWidget -*/ - -/*! - \macro QVideoWindowControl_iid - - \c com.nokia.Qt.QVideoWindowControl/1.0 - - Defines the interface name of the QVideoWindowControl class. - - \relates QVideoWindowControl -*/ - -/*! - Constructs a new video window control with the given \a parent. -*/ -QVideoWindowControl::QVideoWindowControl(QObject *parent) - : QMediaControl(parent) -{ -} - -/*! - Destroys a video window control. -*/ -QVideoWindowControl::~QVideoWindowControl() -{ -} - -/*! - \fn QVideoWindowControl::winId() const - - Returns the ID of the window a video overlay end point renders to. -*/ - -/*! - \fn QVideoWindowControl::setWinId(WId id) - - Sets the \a id of the window a video overlay end point renders to. -*/ - -/*! - \fn QVideoWindowControl::displayRect() const - Returns the sub-rect of a window where video is displayed. -*/ - -/*! - \fn QVideoWindowControl::setDisplayRect(const QRect &rect) - Sets the sub-\a rect of a window where video is displayed. -*/ - -/*! - \fn QVideoWindowControl::isFullScreen() const - - Identifies if a video overlay is a fullScreen overlay. - - Returns true if the video overlay is fullScreen, and false otherwise. -*/ - -/*! - \fn QVideoWindowControl::setFullScreen(bool fullScreen) - - Sets whether a video overlay is a \a fullScreen overlay. -*/ - -/*! - \fn QVideoWindowControl::fullScreenChanged(bool fullScreen) - - Signals that the \a fullScreen state of a video overlay has changed. -*/ - -/*! - \fn QVideoWindowControl::repaint() - - Repaints the last frame. -*/ - -/*! - \fn QVideoWindowControl::nativeSize() const - - Returns a suggested size for the video display based on the resolution and aspect ratio of the - video. -*/ - -/*! - \fn QVideoWindowControl::nativeSizeChanged() - - Signals that the native dimensions of the video have changed. -*/ - - -/*! - \fn QVideoWindowControl::aspectRatioMode() const - - Returns how video is scaled to fit the display region with respect to its aspect ratio. -*/ - -/*! - \fn QVideoWindowControl::setAspectRatioMode(Qt::AspectRatioMode mode) - - Sets the aspect ratio \a mode which determines how video is scaled to the fit the display region - with respect to its aspect ratio. -*/ - -/*! - \fn QVideoWindowControl::brightness() const - - Returns the brightness adjustment applied to a video overlay. - - Valid brightness values range between -100 and 100, the default is 0. -*/ - -/*! - \fn QVideoWindowControl::setBrightness(int brightness) - - Sets a \a brightness adjustment for a video overlay. - - Valid brightness values range between -100 and 100, the default is 0. -*/ - -/*! - \fn QVideoWindowControl::brightnessChanged(int brightness) - - Signals that a video overlay's \a brightness adjustment has changed. -*/ - -/*! - \fn QVideoWindowControl::contrast() const - - Returns the contrast adjustment applied to a video overlay. - - Valid contrast values range between -100 and 100, the default is 0. -*/ - -/*! - \fn QVideoWindowControl::setContrast(int contrast) - - Sets the \a contrast adjustment for a video overlay. - - Valid contrast values range between -100 and 100, the default is 0. -*/ - -/*! - \fn QVideoWindowControl::contrastChanged(int contrast) - - Signals that a video overlay's \a contrast adjustment has changed. -*/ - -/*! - \fn QVideoWindowControl::hue() const - - Returns the hue adjustment applied to a video overlay. - - Value hue values range between -100 and 100, the default is 0. -*/ - -/*! - \fn QVideoWindowControl::setHue(int hue) - - Sets a \a hue adjustment for a video overlay. - - Valid hue values range between -100 and 100, the default is 0. -*/ - -/*! - \fn QVideoWindowControl::hueChanged(int hue) - - Signals that a video overlay's \a hue adjustment has changed. -*/ - -/*! - \fn QVideoWindowControl::saturation() const - - Returns the saturation adjustment applied to a video overlay. - - Value saturation values range between -100 and 100, the default is 0. -*/ - -/*! - \fn QVideoWindowControl::setSaturation(int saturation) - Sets a \a saturation adjustment for a video overlay. - - Valid saturation values range between -100 and 100, the default is 0. -*/ - -/*! - \fn QVideoWindowControl::saturationChanged(int saturation) - - Signals that a video overlay's \a saturation adjustment has changed. -*/ - -#include "moc_qvideowindowcontrol.cpp" - -QT_END_NAMESPACE - diff --git a/src/multimedia/base/qvideowindowcontrol.h b/src/multimedia/base/qvideowindowcontrol.h deleted file mode 100644 index 53f7b0e..0000000 --- a/src/multimedia/base/qvideowindowcontrol.h +++ /dev/null @@ -1,111 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtMultimedia module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QVIDEOWINDOWCONTROL_H -#define QVIDEOWINDOWCONTROL_H - -#include - -#include -#include - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Multimedia) - - -class Q_MULTIMEDIA_EXPORT QVideoWindowControl : public QMediaControl -{ - Q_OBJECT - -public: - ~QVideoWindowControl(); - - virtual WId winId() const = 0; - virtual void setWinId(WId id) = 0; - - virtual QRect displayRect() const = 0; - virtual void setDisplayRect(const QRect &rect) = 0; - - virtual bool isFullScreen() const = 0; - virtual void setFullScreen(bool fullScreen) = 0; - - virtual void repaint() = 0; - - virtual QSize nativeSize() const = 0; - - virtual Qt::AspectRatioMode aspectRatioMode() const = 0; - virtual void setAspectRatioMode(Qt::AspectRatioMode mode) = 0; - - virtual int brightness() const = 0; - virtual void setBrightness(int brightness) = 0; - - virtual int contrast() const = 0; - virtual void setContrast(int contrast) = 0; - - virtual int hue() const = 0; - virtual void setHue(int hue) = 0; - - virtual int saturation() const = 0; - virtual void setSaturation(int saturation) = 0; - -Q_SIGNALS: - void fullScreenChanged(bool fullScreen); - void brightnessChanged(int brightness); - void contrastChanged(int contrast); - void hueChanged(int hue); - void saturationChanged(int saturation); - void nativeSizeChanged(); - -protected: - QVideoWindowControl(QObject *parent = 0); -}; - -#define QVideoWindowControl_iid "com.nokia.Qt.QVideoWindowControl/1.0" -Q_MEDIA_DECLARE_CONTROL(QVideoWindowControl, QVideoWindowControl_iid) - -QT_END_NAMESPACE - -QT_END_HEADER - -#endif diff --git a/src/multimedia/effects/effects.pri b/src/multimedia/effects/effects.pri deleted file mode 100644 index 6307255..0000000 --- a/src/multimedia/effects/effects.pri +++ /dev/null @@ -1,26 +0,0 @@ - - -unix:!mac { - contains(QT_CONFIG, pulseaudio) { - DEFINES += QT_MULTIMEDIA_PULSEAUDIO - HEADERS += $$PWD/qsoundeffect_pulse_p.h - SOURCES += $$PWD/qsoundeffect_pulse_p.cpp - QMAKE_CXXFLAGS += $$QT_CFLAGS_PULSEAUDIO - LIBS += $$QT_LIBS_PULSEAUDIO - } else { - DEFINES += QT_MULTIMEDIA_QMEDIAPLAYER - HEADERS += $$PWD/qsoundeffect_qmedia_p.h - SOURCES += $$PWD/qsoundeffect_qmedia_p.cpp - } -} else { - HEADERS += $$PWD/qsoundeffect_qsound_p.h - SOURCES += $$PWD/qsoundeffect_qsound_p.cpp -} - -HEADERS += \ - $$PWD/qsoundeffect_p.h \ - $$PWD/wavedecoder_p.h - -SOURCES += \ - $$PWD/qsoundeffect.cpp \ - $$PWD/wavedecoder_p.cpp diff --git a/src/multimedia/effects/qsoundeffect.cpp b/src/multimedia/effects/qsoundeffect.cpp deleted file mode 100644 index 8a38103..0000000 --- a/src/multimedia/effects/qsoundeffect.cpp +++ /dev/null @@ -1,207 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtMultimedia module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qsoundeffect_p.h" - -#if defined(QT_MULTIMEDIA_PULSEAUDIO) -#include "qsoundeffect_pulse_p.h" -#elif(QT_MULTIMEDIA_QMEDIAPLAYER) -#include "qsoundeffect_qmedia_p.h" -#else -#include "qsoundeffect_qsound_p.h" -#endif - -QT_BEGIN_NAMESPACE - -/*! - \qmlclass SoundEffect QSoundEffect - \since 4.7 - \brief The SoundEffect element provides a way to play sound effects in qml. - - This element is part of the \bold{Qt.multimedia 4.7} module. - - The following example plays a wav file on mouse click. - - \qml - import Qt 4.6 - import Qt.multimedia 4.7 - - Item { - SoundEffect { - id: playSound - source: "test.wav" - } - MouseArea { - id: playArea - anchors.fill: parent - onPressed: { - playSound.play() - } - } - } - \endqml -*/ - -/*! - \qmlproperty QUrl SoundEffect::source - - This property provides a way to control the sound to play. -*/ - -/*! - \qmlproperty int SoundEffect::loops - - This property provides a way to control the number of times to repeat the sound on each play(). -*/ - -/*! - \qmlproperty int SoundEffect::volume - - This property provides a way to control the volume for playback. -*/ - -/*! - \qmlproperty bool SoundEffect::muted - - This property provides a way to control muting. -*/ - -/*! - \qmlsignal SoundEffect::sourceChanged() - - This handler is called when the source has changed. -*/ - -/*! - \qmlsignal SoundEffect::loopsChanged() - - This handler is called when the number of loops has changes. -*/ - -/*! - \qmlsignal SoundEffect::volumeChanged() - - This handler is called when the volume has changed. -*/ - -/*! - \qmlsignal SoundEffect::mutedChanged() - - This handler is called when the mute state has changed. -*/ - - -QSoundEffect::QSoundEffect(QObject *parent) : - QObject(parent) -{ - d = new QSoundEffectPrivate(this); - connect(d, SIGNAL(volumeChanged()), SIGNAL(volumeChanged())); - connect(d, SIGNAL(mutedChanged()), SIGNAL(mutedChanged())); -} - -QSoundEffect::~QSoundEffect() -{ - d->deleteLater(); -} - -QUrl QSoundEffect::source() const -{ - return d->source(); -} - -void QSoundEffect::setSource(const QUrl &url) -{ - if (d->source() == url) - return; - - d->setSource(url); - - emit sourceChanged(); -} - -int QSoundEffect::loops() const -{ - return d->loopCount(); -} - -void QSoundEffect::setLoops(int loopCount) -{ - if (d->loopCount() == loopCount) - return; - - d->setLoopCount(loopCount); - emit loopsChanged(); -} - -int QSoundEffect::volume() const -{ - return d->volume(); -} - -void QSoundEffect::setVolume(int volume) -{ - if (d->volume() == volume) - return; - - d->setVolume(volume); - emit volumeChanged(); -} - -bool QSoundEffect::isMuted() const -{ - return d->isMuted(); -} - -void QSoundEffect::setMuted(bool muted) -{ - if (d->isMuted() == muted) - return; - - d->setMuted(muted); - emit mutedChanged(); -} - -void QSoundEffect::play() -{ - d->play(); -} - -QT_END_NAMESPACE diff --git a/src/multimedia/effects/qsoundeffect_p.h b/src/multimedia/effects/qsoundeffect_p.h deleted file mode 100644 index 05207a0..0000000 --- a/src/multimedia/effects/qsoundeffect_p.h +++ /dev/null @@ -1,109 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtMultimedia module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QSOUNDEFFECT_H -#define QSOUNDEFFECT_H - -// -// W A R N I N G -// ------------- -// -// This file is not part of the Qt API. It exists purely as an -// implementation detail. This header file may change from version to -// version without notice, or even be removed. -// -// We mean it. -// - - -#include -#include - - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -class QSoundEffectPrivate; -class Q_MULTIMEDIA_EXPORT QSoundEffect : public QObject -{ - Q_OBJECT - Q_PROPERTY(QUrl source READ source WRITE setSource NOTIFY sourceChanged) - Q_PROPERTY(int loops READ loops WRITE setLoops NOTIFY loopsChanged) - Q_PROPERTY(int volume READ volume WRITE setVolume NOTIFY volumeChanged) - Q_PROPERTY(bool muted READ isMuted WRITE setMuted NOTIFY mutedChanged) - -public: - explicit QSoundEffect(QObject *parent = 0); - ~QSoundEffect(); - - QUrl source() const; - void setSource(const QUrl &url); - - int loops() const; - void setLoops(int loopCount); - - int volume() const; - void setVolume(int volume); - - bool isMuted() const; - void setMuted(bool muted); - -Q_SIGNALS: - void sourceChanged(); - void loopsChanged(); - void volumeChanged(); - void mutedChanged(); - -public Q_SLOTS: - void play(); - -private: - Q_DISABLE_COPY(QSoundEffect) - QSoundEffectPrivate* d; -}; - -QT_END_NAMESPACE - -QT_END_HEADER - - -#endif // QSOUNDEFFECT_H diff --git a/src/multimedia/effects/qsoundeffect_pulse_p.cpp b/src/multimedia/effects/qsoundeffect_pulse_p.cpp deleted file mode 100644 index e379259..0000000 --- a/src/multimedia/effects/qsoundeffect_pulse_p.cpp +++ /dev/null @@ -1,499 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtMultimedia module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -// -// W A R N I N G -// ------------- -// -// This file is not part of the Qt API. It exists purely as an -// implementation detail. This header file may change from version to -// version without notice, or even be removed. -// -// We mean it. -// - -#include -#include -#include -#include - -#include "wavedecoder_p.h" - -#include "qsoundeffect_pulse_p.h" - -#if defined(Q_WS_MAEMO_5) -#include -#endif - -#include - -// Less than ideal -#define PA_SCACHE_ENTRY_SIZE_MAX (1024*1024*16) - -QT_BEGIN_NAMESPACE - -namespace -{ -inline pa_sample_spec audioFormatToSampleSpec(const QAudioFormat &format) -{ - pa_sample_spec spec; - - spec.rate = format.frequency(); - spec.channels = format.channels(); - - if (format.sampleSize() == 8) - spec.format = PA_SAMPLE_U8; - else if (format.sampleSize() == 16) { - switch (format.byteOrder()) { - case QAudioFormat::BigEndian: spec.format = PA_SAMPLE_S16BE; break; - case QAudioFormat::LittleEndian: spec.format = PA_SAMPLE_S16LE; break; - } - } - else if (format.sampleSize() == 32) { - switch (format.byteOrder()) { - case QAudioFormat::BigEndian: spec.format = PA_SAMPLE_S32BE; break; - case QAudioFormat::LittleEndian: spec.format = PA_SAMPLE_S32LE; break; - } - } - - return spec; -} - -class PulseDaemon -{ -public: - PulseDaemon():m_prepared(false) - { - prepare(); - } - - ~PulseDaemon() - { - if (m_prepared) - release(); - } - - inline void lock() - { - pa_threaded_mainloop_lock(m_mainLoop); - } - - inline void unlock() - { - pa_threaded_mainloop_unlock(m_mainLoop); - } - - inline pa_context *context() const - { - return m_context; - } - - int volume() - { - return m_vol; - } - -private: - void prepare() - { - m_vol = 100; - - m_mainLoop = pa_threaded_mainloop_new(); - if (m_mainLoop == 0) { - qWarning("PulseAudioService: unable to create pulseaudio mainloop"); - return; - } - - if (pa_threaded_mainloop_start(m_mainLoop) != 0) { - qWarning("PulseAudioService: unable to start pulseaudio mainloop"); - pa_threaded_mainloop_free(m_mainLoop); - return; - } - - m_mainLoopApi = pa_threaded_mainloop_get_api(m_mainLoop); - - lock(); - m_context = pa_context_new(m_mainLoopApi, QString(QLatin1String("QtPulseAudio:%1")).arg(::getpid()).toAscii().constData()); - -#if defined(Q_WS_MAEMO_5) - pa_context_set_state_callback(m_context, context_state_callback, this); -#endif - if (m_context == 0) { - qWarning("PulseAudioService: Unable to create new pulseaudio context"); - pa_threaded_mainloop_free(m_mainLoop); - return; - } - - if (pa_context_connect(m_context, NULL, (pa_context_flags_t)0, NULL) < 0) { - qWarning("PulseAudioService: pa_context_connect() failed"); - pa_context_unref(m_context); - pa_threaded_mainloop_free(m_mainLoop); - return; - } - unlock(); - - m_prepared = true; - } - - void release() - { - if (!m_prepared) return; - pa_threaded_mainloop_stop(m_mainLoop); - pa_threaded_mainloop_free(m_mainLoop); - m_prepared = false; - } - -#if defined(Q_WS_MAEMO_5) - static void context_state_callback(pa_context *c, void *userdata) - { - PulseDaemon *self = reinterpret_cast(userdata); - switch (pa_context_get_state(c)) { - case PA_CONTEXT_CONNECTING: - case PA_CONTEXT_AUTHORIZING: - case PA_CONTEXT_SETTING_NAME: - break; - case PA_CONTEXT_READY: - pa_ext_stream_restore_set_subscribe_cb(c, &stream_restore_monitor_callback, self); - pa_ext_stream_restore_subscribe(c, 1, NULL, self); - break; - default: - break; - } - } - static void stream_restore_monitor_callback(pa_context *c, void *userdata) - { - PulseDaemon *self = reinterpret_cast(userdata); - pa_ext_stream_restore2_read(c, &stream_restore_info_callback, self); - } - static void stream_restore_info_callback(pa_context *c, const pa_ext_stream_restore2_info *info, - int eol, void *userdata) - { - Q_UNUSED(c) - - PulseDaemon *self = reinterpret_cast(userdata); - - if (!eol) { - if (QString(info->name).startsWith(QLatin1String("sink-input-by-media-role:x-maemo"))) { - const unsigned str_length = 256; - char str[str_length]; - pa_cvolume_snprint(str, str_length, &info->volume); - self->m_vol = QString(str).replace(" ","").replace("%","").mid(2).toInt(); - } - } - } -#endif - - int m_vol; - bool m_prepared; - pa_context *m_context; - pa_threaded_mainloop *m_mainLoop; - pa_mainloop_api *m_mainLoopApi; -}; -} - -Q_GLOBAL_STATIC(PulseDaemon, daemon) - - -QSoundEffectPrivate::QSoundEffectPrivate(QObject* parent): - QObject(parent), - m_retry(false), - m_muted(false), - m_playQueued(false), - m_sampleLoaded(false), - m_volume(100), - m_duration(0), - m_dataUploaded(0), - m_loopCount(1), - m_runningCount(0), - m_reply(0), - m_stream(0), - m_networkAccessManager(0) -{ -} - -QSoundEffectPrivate::~QSoundEffectPrivate() -{ - m_reply->deleteLater(); - unloadSample(); -} - -QUrl QSoundEffectPrivate::source() const -{ - return m_source; -} - -void QSoundEffectPrivate::setSource(const QUrl &url) -{ - if (url.isEmpty()) { - m_source = QUrl(); - unloadSample(); - return; - } - - m_source = url; - - if (m_networkAccessManager == 0) - m_networkAccessManager = new QNetworkAccessManager(this); - - m_stream = m_networkAccessManager->get(QNetworkRequest(m_source)); - - unloadSample(); - loadSample(); -} - -int QSoundEffectPrivate::loopCount() const -{ - return m_loopCount; -} - -void QSoundEffectPrivate::setLoopCount(int loopCount) -{ - m_loopCount = loopCount; -} - -int QSoundEffectPrivate::volume() const -{ - return m_volume; -} - -void QSoundEffectPrivate::setVolume(int volume) -{ - m_volume = volume; -} - -bool QSoundEffectPrivate::isMuted() const -{ - return m_muted; -} - -void QSoundEffectPrivate::setMuted(bool muted) -{ - m_muted = muted; -} - -void QSoundEffectPrivate::play() -{ - if (m_retry) { - m_retry = false; - setSource(m_source); - return; - } - - if (!m_sampleLoaded) { - m_playQueued = true; - return; - } - - m_runningCount += m_loopCount; - - playSample(); -} - -void QSoundEffectPrivate::decoderReady() -{ - if (m_waveDecoder->size() >= PA_SCACHE_ENTRY_SIZE_MAX) { - m_waveDecoder->deleteLater(); - qWarning("QSoundEffect(pulseaudio): Attempting to load to large a sample"); - return; - } - - if (m_name.isNull()) - m_name = QString(QLatin1String("QtPulseSample-%1-%2")).arg(::getpid()).arg(quintptr(this)).toUtf8(); - - pa_sample_spec spec = audioFormatToSampleSpec(m_waveDecoder->audioFormat()); - - daemon()->lock(); - pa_stream *stream = pa_stream_new(daemon()->context(), m_name.constData(), &spec, 0); - pa_stream_set_state_callback(stream, stream_state_callback, this); - pa_stream_set_write_callback(stream, stream_write_callback, this); - pa_stream_connect_upload(stream, (size_t)m_waveDecoder->size()); - m_pulseStream = stream; - daemon()->unlock(); -} - -void QSoundEffectPrivate::decoderError() -{ - qWarning("QSoundEffect(pulseaudio): Error decoding source"); -} - -void QSoundEffectPrivate::checkPlayTime() -{ - int elapsed = m_playbackTime.elapsed(); - - if (elapsed < m_duration) - startTimer(m_duration - elapsed); -} - -void QSoundEffectPrivate::loadSample() -{ - m_sampleLoaded = false; - m_dataUploaded = 0; - m_waveDecoder = new WaveDecoder(m_stream); - connect(m_waveDecoder, SIGNAL(formatKnown()), SLOT(decoderReady())); - connect(m_waveDecoder, SIGNAL(invalidFormat()), SLOT(decoderError())); -} - -void QSoundEffectPrivate::unloadSample() -{ - if (!m_sampleLoaded) - return; - - daemon()->lock(); - pa_context_remove_sample(daemon()->context(), m_name.constData(), NULL, NULL); - daemon()->unlock(); - - m_duration = 0; - m_dataUploaded = 0; - m_sampleLoaded = false; -} - -void QSoundEffectPrivate::uploadSample() -{ - daemon()->lock(); - - size_t bufferSize = qMin(pa_stream_writable_size(m_pulseStream), - size_t(m_waveDecoder->bytesAvailable())); - char buffer[bufferSize]; - - size_t len = 0; - while (len < (m_waveDecoder->size())) { - qint64 read = m_waveDecoder->read(buffer, qMin((int)bufferSize, - (int)(m_waveDecoder->size()-len))); - if (read > 0) { - if (pa_stream_write(m_pulseStream, buffer, size_t(read), 0, 0, PA_SEEK_RELATIVE) == 0) - len += size_t(read); - else - break; - } - } - - m_dataUploaded += len; - pa_stream_set_write_callback(m_pulseStream, NULL, NULL); - - if (m_waveDecoder->size() == m_dataUploaded) { - int err = pa_stream_finish_upload(m_pulseStream); - if(err != 0) { - qWarning("pa_stream_finish_upload() err=%d",err); - pa_stream_disconnect(m_pulseStream); - m_retry = true; - m_playQueued = false; - QMetaObject::invokeMethod(this, "play"); - daemon()->unlock(); - return; - } - m_duration = m_waveDecoder->duration(); - m_waveDecoder->deleteLater(); - m_stream->deleteLater(); - m_sampleLoaded = true; - if (m_playQueued) { - m_playQueued = false; - QMetaObject::invokeMethod(this, "play"); - } - } - daemon()->unlock(); -} - -void QSoundEffectPrivate::playSample() -{ - pa_volume_t volume = PA_VOLUME_NORM; - - daemon()->lock(); -#ifdef Q_WS_MAEMO_5 - volume = PA_VOLUME_NORM / 100 * ((daemon()->volume() + m_volume) / 2); -#endif - pa_operation_unref( - pa_context_play_sample(daemon()->context(), - m_name.constData(), - 0, - volume, - play_callback, - this) - ); - daemon()->unlock(); - - m_playbackTime.start(); -} - -void QSoundEffectPrivate::timerEvent(QTimerEvent *event) -{ - if (m_runningCount > 0) - playSample(); - - killTimer(event->timerId()); -} - -void QSoundEffectPrivate::stream_write_callback(pa_stream *s, size_t length, void *userdata) -{ - Q_UNUSED(length); - - QSoundEffectPrivate *self = reinterpret_cast(userdata); - - QMetaObject::invokeMethod(self, "uploadSample", Qt::QueuedConnection); -} - -void QSoundEffectPrivate::stream_state_callback(pa_stream *s, void *userdata) -{ - switch (pa_stream_get_state(s)) { - case PA_STREAM_CREATING: - case PA_STREAM_READY: - case PA_STREAM_TERMINATED: - break; - - case PA_STREAM_FAILED: - default: - qWarning("QSoundEffect(pulseaudio): Error in pulse audio stream"); - break; - } -} - -void QSoundEffectPrivate::play_callback(pa_context *c, int success, void *userdata) -{ - Q_UNUSED(c); - - QSoundEffectPrivate *self = reinterpret_cast(userdata); - - if (success == 1) { - self->m_runningCount--; - QMetaObject::invokeMethod(self, "checkPlayTime", Qt::QueuedConnection); - } -} - -QT_END_NAMESPACE diff --git a/src/multimedia/effects/qsoundeffect_pulse_p.h b/src/multimedia/effects/qsoundeffect_pulse_p.h deleted file mode 100644 index aff729c..0000000 --- a/src/multimedia/effects/qsoundeffect_pulse_p.h +++ /dev/null @@ -1,137 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtMultimedia module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QSOUNDEFFECT_PULSE_H -#define QSOUNDEFFECT_PULSE_H - -// -// W A R N I N G -// ------------- -// -// This file is not part of the Qt API. It exists purely as an -// implementation detail. This header file may change from version to -// version without notice, or even be removed. -// -// We mean it. -// - - -#include "qsoundeffect_p.h" - -#include -#include -#include -#include - - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -class QNetworkReply; -class QNetworkAccessManager; -class WaveDecoder; - -class QSoundEffectPrivate : public QObject -{ - Q_OBJECT -public: - explicit QSoundEffectPrivate(QObject* parent); - ~QSoundEffectPrivate(); - - QUrl source() const; - void setSource(const QUrl &url); - int loopCount() const; - void setLoopCount(int loopCount); - int volume() const; - void setVolume(int volume); - bool isMuted() const; - void setMuted(bool muted); - -public Q_SLOTS: - void play(); - -Q_SIGNALS: - void volumeChanged(); - void mutedChanged(); - -private Q_SLOTS: - void decoderReady(); - void decoderError(); - void checkPlayTime(); - void uploadSample(); - -private: - void loadSample(); - void unloadSample(); - void playSample(); - - void timerEvent(QTimerEvent *event); - - static void stream_write_callback(pa_stream *s, size_t length, void *userdata); - static void stream_state_callback(pa_stream *s, void *userdata); - static void play_callback(pa_context *c, int success, void *userdata); - - pa_stream *m_pulseStream; - - bool m_retry; - bool m_muted; - bool m_playQueued; - bool m_sampleLoaded; - int m_volume; - int m_duration; - int m_dataUploaded; - int m_loopCount; - int m_runningCount; - QUrl m_source; - QTime m_playbackTime; - QByteArray m_name; - QNetworkReply *m_reply; - WaveDecoder *m_waveDecoder; - QIODevice *m_stream; - QNetworkAccessManager *m_networkAccessManager; -}; - -QT_END_NAMESPACE - -QT_END_HEADER - -#endif // QSOUNDEFFECT_PULSE_H diff --git a/src/multimedia/effects/qsoundeffect_qmedia_p.cpp b/src/multimedia/effects/qsoundeffect_qmedia_p.cpp deleted file mode 100644 index 36c36dd..0000000 --- a/src/multimedia/effects/qsoundeffect_qmedia_p.cpp +++ /dev/null @@ -1,132 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtMultimedia module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -// -// W A R N I N G -// ------------- -// -// This file is not part of the Qt API. It exists purely as an -// implementation detail. This header file may change from version to -// version without notice, or even be removed. -// -// We mean it. -// - -#include "qsoundeffect_qmedia_p.h" - -#include - -#include -#include - - -QT_BEGIN_NAMESPACE - -QSoundEffectPrivate::QSoundEffectPrivate(QObject* parent): - QObject(parent), - m_loopCount(1), - m_runningCount(0), - m_player(0) -{ - m_player = new QMediaPlayer(this, QMediaPlayer::LowLatency); - connect(m_player, SIGNAL(stateChanged(QMediaPlayer::State)), SLOT(stateChanged(QMediaPlayer::State))); -} - -QSoundEffectPrivate::~QSoundEffectPrivate() -{ -} - -QUrl QSoundEffectPrivate::source() const -{ - return m_player->media().canonicalUrl(); -} - -void QSoundEffectPrivate::setSource(const QUrl &url) -{ - m_player->setMedia(url); -} - -int QSoundEffectPrivate::loopCount() const -{ - return m_loopCount; -} - -void QSoundEffectPrivate::setLoopCount(int loopCount) -{ - m_loopCount = loopCount; -} - -int QSoundEffectPrivate::volume() const -{ - return m_player->volume(); -} - -void QSoundEffectPrivate::setVolume(int volume) -{ - m_player->setVolume(volume); -} - -bool QSoundEffectPrivate::isMuted() const -{ - return m_player->isMuted(); -} - -void QSoundEffectPrivate::setMuted(bool muted) -{ - m_player->setMuted(muted); -} - -void QSoundEffectPrivate::play() -{ - m_runningCount += m_loopCount; - m_player->play(); -} - -void QSoundEffectPrivate::stateChanged(QMediaPlayer::State state) -{ - if (state == QMediaPlayer::StoppedState) { - if (--m_runningCount > 0) - m_player->play(); - } -} - -QT_END_NAMESPACE - diff --git a/src/multimedia/effects/qsoundeffect_qmedia_p.h b/src/multimedia/effects/qsoundeffect_qmedia_p.h deleted file mode 100644 index 6ad9d79..0000000 --- a/src/multimedia/effects/qsoundeffect_qmedia_p.h +++ /dev/null @@ -1,103 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtMultimedia module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QSOUNDEFFECT_QMEDIA_H -#define QSOUNDEFFECT_QMEDIA_H - -// -// W A R N I N G -// ------------- -// -// This file is not part of the Qt API. It exists purely as an -// implementation detail. This header file may change from version to -// version without notice, or even be removed. -// -// We mean it. -// - - -#include -#include -#include - - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - - -class QSoundEffectPrivate : public QObject -{ - Q_OBJECT -public: - explicit QSoundEffectPrivate(QObject* parent); - ~QSoundEffectPrivate(); - - QUrl source() const; - void setSource(const QUrl &url); - int loopCount() const; - void setLoopCount(int loopCount); - int volume() const; - void setVolume(int volume); - bool isMuted() const; - void setMuted(bool muted); - -public Q_SLOTS: - void play(); - -Q_SIGNALS: - void volumeChanged(); - void mutedChanged(); - -private Q_SLOTS: - void stateChanged(QMediaPlayer::State); - -private: - int m_loopCount; - int m_runningCount; - QMediaPlayer *m_player; -}; - -QT_END_NAMESPACE - -QT_END_HEADER - -#endif // QSOUNDEFFECT_QMEDIA_H diff --git a/src/multimedia/effects/qsoundeffect_qsound_p.cpp b/src/multimedia/effects/qsoundeffect_qsound_p.cpp deleted file mode 100644 index ff30f67..0000000 --- a/src/multimedia/effects/qsoundeffect_qsound_p.cpp +++ /dev/null @@ -1,131 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtMultimedia module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -// -// W A R N I N G -// ------------- -// -// This file is not part of the Qt API. It exists purely as an -// implementation detail. This header file may change from version to -// version without notice, or even be removed. -// -// We mean it. -// - -#include "qsoundeffect_qsound_p.h" - -#include -#include - - -QT_BEGIN_NAMESPACE - -QSoundEffectPrivate::QSoundEffectPrivate(QObject* parent): - QObject(parent), - m_muted(false), - m_loopCount(1), - m_volume(100), - m_sound(0) -{ -} - -QSoundEffectPrivate::~QSoundEffectPrivate() -{ -} - -QUrl QSoundEffectPrivate::source() const -{ - return m_source; -} - -void QSoundEffectPrivate::setSource(const QUrl &url) -{ - if (url.isEmpty() || url.scheme() != QLatin1String("file")) { - m_source = QUrl(); - return; - } - - if (m_sound != 0) - delete m_sound; - - m_source = url; - m_sound = new QSound(m_source.toLocalFile(), this); - m_sound->setLoops(m_loopCount); -} - -int QSoundEffectPrivate::loopCount() const -{ - return m_loopCount; -} - -void QSoundEffectPrivate::setLoopCount(int lc) -{ - m_loopCount = lc; - if (m_sound) - m_sound->setLoops(lc); -} - -int QSoundEffectPrivate::volume() const -{ - return m_volume; -} - -void QSoundEffectPrivate::setVolume(int v) -{ - m_volume = v; -} - -bool QSoundEffectPrivate::isMuted() const -{ - return m_muted; -} - -void QSoundEffectPrivate::setMuted(bool muted) -{ - m_muted = muted; -} - -void QSoundEffectPrivate::play() -{ - m_sound->play(); -} - -QT_END_NAMESPACE diff --git a/src/multimedia/effects/qsoundeffect_qsound_p.h b/src/multimedia/effects/qsoundeffect_qsound_p.h deleted file mode 100644 index 6fb3cfa..0000000 --- a/src/multimedia/effects/qsoundeffect_qsound_p.h +++ /dev/null @@ -1,102 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtMultimedia module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QSOUNDEFFECT_QSOUND_H -#define QSOUNDEFFECT_QSOUND_H - -// -// W A R N I N G -// ------------- -// -// This file is not part of the Qt API. It exists purely as an -// implementation detail. This header file may change from version to -// version without notice, or even be removed. -// -// We mean it. -// - - -#include -#include - - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -class QSound; - -class QSoundEffectPrivate : public QObject -{ - Q_OBJECT -public: - explicit QSoundEffectPrivate(QObject* parent); - ~QSoundEffectPrivate(); - - QUrl source() const; - void setSource(const QUrl &url); - int loopCount() const; - void setLoopCount(int loopCount); - int volume() const; - void setVolume(int volume); - bool isMuted() const; - void setMuted(bool muted); - -public Q_SLOTS: - void play(); - -Q_SIGNALS: - void volumeChanged(); - void mutedChanged(); - -private: - bool m_muted; - int m_loopCount; - int m_volume; - QSound *m_sound; - QUrl m_source; -}; - -QT_END_NAMESPACE - -QT_END_HEADER - -#endif // QSOUNDEFFECT_QSOUND_H diff --git a/src/multimedia/effects/wavedecoder_p.cpp b/src/multimedia/effects/wavedecoder_p.cpp deleted file mode 100644 index b534ded..0000000 --- a/src/multimedia/effects/wavedecoder_p.cpp +++ /dev/null @@ -1,151 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtMultimedia module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "wavedecoder_p.h" - -#include -#include - -QT_BEGIN_NAMESPACE - -WaveDecoder::WaveDecoder(QIODevice *s, QObject *parent): - QIODevice(parent), - haveFormat(false), - dataSize(0), - remaining(0), - source(s) -{ - open(QIODevice::ReadOnly | QIODevice::Unbuffered); - - if (source->bytesAvailable() >= qint64(sizeof(CombinedHeader) + sizeof(DATAHeader) + sizeof(quint16))) - QTimer::singleShot(0, this, SLOT(handleData())); - else - connect(source, SIGNAL(readyRead()), SLOT(handleData())); -} - -WaveDecoder::~WaveDecoder() -{ -} - -QAudioFormat WaveDecoder::audioFormat() const -{ - return format; -} - -int WaveDecoder::duration() const -{ - return size() * 1000 / (format.sampleSize() / 8) / format.channels() / format.frequency(); -} - -qint64 WaveDecoder::size() const -{ - return haveFormat ? dataSize : 0; -} - -bool WaveDecoder::isSequential() const -{ - return source->isSequential(); -} - -qint64 WaveDecoder::bytesAvailable() const -{ - return haveFormat ? source->bytesAvailable() : 0; -} - -qint64 WaveDecoder::readData(char *data, qint64 maxlen) -{ - return haveFormat ? source->read(data, maxlen) : 0; -} - -qint64 WaveDecoder::writeData(const char *data, qint64 len) -{ - Q_UNUSED(data); - Q_UNUSED(len); - - return -1; -} - -void WaveDecoder::handleData() -{ - if (source->bytesAvailable() < qint64(sizeof(CombinedHeader) + sizeof(DATAHeader) + sizeof(quint16))) - return; - - source->disconnect(SIGNAL(readyRead()), this, SLOT(handleData())); - source->read((char*)&header, sizeof(CombinedHeader)); - - if (qstrncmp(header.riff.descriptor.id, "RIFF", 4) != 0 || - qstrncmp(header.riff.type, "WAVE", 4) != 0 || - qstrncmp(header.wave.descriptor.id, "fmt ", 4) != 0 || - (header.wave.audioFormat != 0 && header.wave.audioFormat != 1)) { - - emit invalidFormat(); - } - else { - DATAHeader dataHeader; - - if (qFromLittleEndian(header.wave.descriptor.size) > sizeof(WAVEHeader)) { - // Extended data available - quint16 extraFormatBytes; - source->peek((char*)&extraFormatBytes, sizeof(quint16)); - extraFormatBytes = qFromLittleEndian(extraFormatBytes); - source->read(sizeof(quint16) + extraFormatBytes); // dump it all - } - - source->read((char*)&dataHeader, sizeof(DATAHeader)); - - int bps = qFromLittleEndian(header.wave.bitsPerSample); - - format.setCodec(QLatin1String("audio/pcm")); - format.setSampleType(bps == 8 ? QAudioFormat::UnSignedInt : QAudioFormat::SignedInt); - format.setByteOrder(QAudioFormat::LittleEndian); - format.setFrequency(qFromLittleEndian(header.wave.sampleRate)); - format.setSampleSize(bps); - format.setChannels(qFromLittleEndian(header.wave.numChannels)); - - dataSize = qFromLittleEndian(dataHeader.descriptor.size); - - haveFormat = true; - connect(source, SIGNAL(readyRead()), SIGNAL(readyRead())); - emit formatKnown(); - } -} - -QT_END_NAMESPACE diff --git a/src/multimedia/effects/wavedecoder_p.h b/src/multimedia/effects/wavedecoder_p.h deleted file mode 100644 index c1892bb..0000000 --- a/src/multimedia/effects/wavedecoder_p.h +++ /dev/null @@ -1,133 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtMultimedia module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef WAVEDECODER_H -#define WAVEDECODER_H - -// -// W A R N I N G -// ------------- -// -// This file is not part of the Qt API. It exists for the convenience -// of other Qt classes. This header file may change from version to -// version without notice, or even be removed. -// -// We mean it. -// - -#include -#include - - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - - -class WaveDecoder : public QIODevice -{ - Q_OBJECT - -public: - explicit WaveDecoder(QIODevice *source, QObject *parent = 0); - ~WaveDecoder(); - - QAudioFormat audioFormat() const; - int duration() const; - - qint64 size() const; - bool isSequential() const; - qint64 bytesAvailable() const; - -Q_SIGNALS: - void formatKnown(); - void invalidFormat(); - -private Q_SLOTS: - void handleData(); - -private: - qint64 readData(char *data, qint64 maxlen); - qint64 writeData(const char *data, qint64 len); - - struct chunk - { - char id[4]; - quint32 size; - }; - struct RIFFHeader - { - chunk descriptor; - char type[4]; - }; - struct WAVEHeader - { - chunk descriptor; - quint16 audioFormat; - quint16 numChannels; - quint32 sampleRate; - quint32 byteRate; - quint16 blockAlign; - quint16 bitsPerSample; - }; - struct DATAHeader - { - chunk descriptor; - }; - struct CombinedHeader - { - RIFFHeader riff; - WAVEHeader wave; - }; - - bool haveFormat; - qint64 dataSize; - qint64 remaining; - QAudioFormat format; - QIODevice *source; - CombinedHeader header; -}; - -QT_END_NAMESPACE - -QT_END_HEADER - -#endif // WAVEDECODER_H diff --git a/src/multimedia/mediaservices/base/base.pri b/src/multimedia/mediaservices/base/base.pri new file mode 100644 index 0000000..49eca49 --- /dev/null +++ b/src/multimedia/mediaservices/base/base.pri @@ -0,0 +1,69 @@ + +QT += network +contains(QT_CONFIG, opengl):QT += opengl + +HEADERS += \ + $$PWD/qmediaresource.h \ + $$PWD/qmediacontent.h \ + $$PWD/qmediaobject.h \ + $$PWD/qmediaobject_p.h \ + $$PWD/qmediapluginloader_p.h \ + $$PWD/qmediaservice.h \ + $$PWD/qmediaservice_p.h \ + $$PWD/qmediaserviceprovider.h \ + $$PWD/qmediaserviceproviderplugin.h \ + $$PWD/qmediacontrol.h \ + $$PWD/qmediacontrol_p.h \ + $$PWD/qmetadatacontrol.h \ + $$PWD/qvideooutputcontrol.h \ + $$PWD/qvideowindowcontrol.h \ + $$PWD/qvideorenderercontrol.h \ + $$PWD/qvideodevicecontrol.h \ + $$PWD/qvideowidgetcontrol.h \ + $$PWD/qvideowidget.h \ + $$PWD/qvideowidget_p.h \ + $$PWD/qgraphicsvideoitem.h \ + $$PWD/qmediaplaylistcontrol.h \ + $$PWD/qmediaplaylist.h \ + $$PWD/qmediaplaylist_p.h \ + $$PWD/qmediaplaylistprovider.h \ + $$PWD/qmediaplaylistprovider_p.h \ + $$PWD/qmediaplaylistioplugin.h \ + $$PWD/qlocalmediaplaylistprovider.h \ + $$PWD/qmediaplaylistnavigator.h \ + $$PWD/qpaintervideosurface_p.h \ + $$PWD/qmediatimerange.h \ + $$PWD/qtmedianamespace.h + +SOURCES += \ + $$PWD/qmediaresource.cpp \ + $$PWD/qmediacontent.cpp \ + $$PWD/qmediaobject.cpp \ + $$PWD/qmediapluginloader.cpp \ + $$PWD/qmediaservice.cpp \ + $$PWD/qmediaserviceprovider.cpp \ + $$PWD/qmediacontrol.cpp \ + $$PWD/qmetadatacontrol.cpp \ + $$PWD/qvideooutputcontrol.cpp \ + $$PWD/qvideowindowcontrol.cpp \ + $$PWD/qvideorenderercontrol.cpp \ + $$PWD/qvideodevicecontrol.cpp \ + $$PWD/qvideowidgetcontrol.cpp \ + $$PWD/qvideowidget.cpp \ + $$PWD/qgraphicsvideoitem.cpp \ + $$PWD/qmediaplaylistcontrol.cpp \ + $$PWD/qmediaplaylist.cpp \ + $$PWD/qmediaplaylistprovider.cpp \ + $$PWD/qmediaplaylistioplugin.cpp \ + $$PWD/qlocalmediaplaylistprovider.cpp \ + $$PWD/qmediaplaylistnavigator.cpp \ + $$PWD/qpaintervideosurface.cpp \ + $$PWD/qmediatimerange.cpp + +mac { + HEADERS += $$PWD/qpaintervideosurface_mac_p.h + OBJECTIVE_SOURCES += $$PWD/qpaintervideosurface_mac.mm + + LIBS += -framework AppKit -framework QuartzCore -framework QTKit + +} diff --git a/src/multimedia/mediaservices/base/qgraphicsvideoitem.cpp b/src/multimedia/mediaservices/base/qgraphicsvideoitem.cpp new file mode 100644 index 0000000..05070f8 --- /dev/null +++ b/src/multimedia/mediaservices/base/qgraphicsvideoitem.cpp @@ -0,0 +1,437 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtMediaservies module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include + +#include +#include +#include +#include +#include +#include + +#if !defined(QT_NO_OPENGL) && !defined(QT_OPENGL_ES_1_CL) && !defined(QT_OPENGL_ES_1) +#include +#endif + +QT_BEGIN_NAMESPACE + + +class QGraphicsVideoItemPrivate +{ +public: + QGraphicsVideoItemPrivate() + : q_ptr(0) + , surface(0) + , mediaObject(0) + , service(0) + , outputControl(0) + , rendererControl(0) + , aspectRatioMode(Qt::KeepAspectRatio) + , updatePaintDevice(true) + , rect(0.0, 0.0, 320, 240) + { + } + + QGraphicsVideoItem *q_ptr; + + QPainterVideoSurface *surface; + QMediaObject *mediaObject; + QMediaService *service; + QVideoOutputControl *outputControl; + QVideoRendererControl *rendererControl; + Qt::AspectRatioMode aspectRatioMode; + bool updatePaintDevice; + QRectF rect; + QRectF boundingRect; + QRectF sourceRect; + QSizeF nativeSize; + + void clearService(); + void updateRects(); + + void _q_present(); + void _q_formatChanged(const QVideoSurfaceFormat &format); + void _q_serviceDestroyed(); + void _q_mediaObjectDestroyed(); +}; + +void QGraphicsVideoItemPrivate::clearService() +{ + if (outputControl) { + outputControl->setOutput(QVideoOutputControl::NoOutput); + outputControl = 0; + } + if (rendererControl) { + surface->stop(); + rendererControl->setSurface(0); + rendererControl = 0; + } + if (service) { + QObject::disconnect(service, SIGNAL(destroyed()), q_ptr, SLOT(_q_serviceDestroyed())); + service = 0; + } +} + +void QGraphicsVideoItemPrivate::updateRects() +{ + q_ptr->prepareGeometryChange(); + + if (nativeSize.isEmpty()) { + boundingRect = QRectF(); + } else if (aspectRatioMode == Qt::IgnoreAspectRatio) { + boundingRect = rect; + sourceRect = QRectF(0, 0, 1, 1); + } else if (aspectRatioMode == Qt::KeepAspectRatio) { + QSizeF size = nativeSize; + size.scale(rect.size(), Qt::KeepAspectRatio); + + boundingRect = QRectF(0, 0, size.width(), size.height()); + boundingRect.moveCenter(rect.center()); + + sourceRect = QRectF(0, 0, 1, 1); + } else if (aspectRatioMode == Qt::KeepAspectRatioByExpanding) { + boundingRect = rect; + + QSizeF size = rect.size(); + size.scale(nativeSize, Qt::KeepAspectRatio); + + sourceRect = QRectF( + 0, 0, size.width() / nativeSize.width(), size.height() / nativeSize.height()); + sourceRect.moveCenter(QPointF(0.5, 0.5)); + } +} + +void QGraphicsVideoItemPrivate::_q_present() +{ + if (q_ptr->isObscured()) { + q_ptr->update(boundingRect); + surface->setReady(true); + } else { + q_ptr->update(boundingRect); + } +} + +void QGraphicsVideoItemPrivate::_q_formatChanged(const QVideoSurfaceFormat &format) +{ + nativeSize = format.sizeHint(); + + updateRects(); + + emit q_ptr->nativeSizeChanged(nativeSize); +} + +void QGraphicsVideoItemPrivate::_q_serviceDestroyed() +{ + rendererControl = 0; + outputControl = 0; + service = 0; + + surface->stop(); +} + +void QGraphicsVideoItemPrivate::_q_mediaObjectDestroyed() +{ + mediaObject = 0; + + clearService(); +} + +/*! + \class QGraphicsVideoItem + \brief The QGraphicsVideoItem class provides a graphics item which display video produced by a QMediaObject. + + \since 4.7 + + \ingroup multimedia + + Attaching a QGraphicsVideoItem to a QMediaObject allows it to display + the video or image output of that media object. A QGraphicsVideoItem + is attached to a media object by passing a pointer to the QMediaObject + to the setMediaObject() function. + + \code + player = new QMediaPlayer(this); + + QGraphicsVideoItem *item = new QGraphicsVideoItem; + item->setMediaObject(player); + graphicsView->scence()->addItem(item); + graphicsView->show(); + + player->setMedia(video); + player->play(); + \endcode + + \bold {Note}: Only a single display output can be attached to a media + object at one time. + + \sa QMediaObject, QMediaPlayer, QVideoWidget +*/ + +/*! + Constructs a graphics item that displays video. + + The \a parent is passed to QGraphicsItem. +*/ +QGraphicsVideoItem::QGraphicsVideoItem(QGraphicsItem *parent) + : QGraphicsObject(parent) + , d_ptr(new QGraphicsVideoItemPrivate) +{ + d_ptr->q_ptr = this; + d_ptr->surface = new QPainterVideoSurface; + + connect(d_ptr->surface, SIGNAL(frameChanged()), this, SLOT(_q_present())); + connect(d_ptr->surface, SIGNAL(surfaceFormatChanged(QVideoSurfaceFormat)), + this, SLOT(_q_formatChanged(QVideoSurfaceFormat))); +} + +/*! + Destroys a video graphics item. +*/ +QGraphicsVideoItem::~QGraphicsVideoItem() +{ + if (d_ptr->outputControl) + d_ptr->outputControl->setOutput(QVideoOutputControl::NoOutput); + + if (d_ptr->rendererControl) + d_ptr->rendererControl->setSurface(0); + + delete d_ptr->surface; + delete d_ptr; +} + +/*! + \property QGraphicsVideoItem::mediaObject + \brief the media object which provides the video displayed by a graphics + item. +*/ + +QMediaObject *QGraphicsVideoItem::mediaObject() const +{ + return d_func()->mediaObject; +} + +void QGraphicsVideoItem::setMediaObject(QMediaObject *object) +{ + Q_D(QGraphicsVideoItem); + + if (object == d->mediaObject) + return; + + d->clearService(); + + if (d->mediaObject) { + disconnect(d->mediaObject, SIGNAL(destroyed()), this, SLOT(_q_mediaObjectDestroyed())); + d->mediaObject->unbind(this); + } + + d->mediaObject = object; + + if (d->mediaObject) { + d->mediaObject->bind(this); + + connect(d->mediaObject, SIGNAL(destroyed()), this, SLOT(_q_mediaObjectDestroyed())); + + d->service = d->mediaObject->service(); + + if (d->service) { + connect(d->service, SIGNAL(destroyed()), this, SLOT(_q_serviceDestroyed())); + + d->outputControl = qobject_cast( + d->service->control(QVideoOutputControl_iid)); + d->rendererControl = qobject_cast( + d->service->control(QVideoRendererControl_iid)); + + if (d->outputControl != 0 && d->rendererControl != 0) { + d->rendererControl->setSurface(d->surface); + + if (isVisible()) + d->outputControl->setOutput(QVideoOutputControl::RendererOutput); + } + } + } +} + +/*! + \property QGraphicsVideoItem::aspectRatioMode + \brief how a video is scaled to fit the graphics item's size. +*/ + +Qt::AspectRatioMode QGraphicsVideoItem::aspectRatioMode() const +{ + return d_func()->aspectRatioMode; +} + +void QGraphicsVideoItem::setAspectRatioMode(Qt::AspectRatioMode mode) +{ + Q_D(QGraphicsVideoItem); + + d->aspectRatioMode = mode; + d->updateRects(); +} + +/*! + \property QGraphicsVideoItem::offset + \brief the video item's offset. + + QGraphicsVideoItem will draw video using the offset for its top left + corner. +*/ + +QPointF QGraphicsVideoItem::offset() const +{ + return d_func()->rect.topLeft(); +} + +void QGraphicsVideoItem::setOffset(const QPointF &offset) +{ + Q_D(QGraphicsVideoItem); + + d->rect.moveTo(offset); + d->updateRects(); +} + +/*! + \property QGraphicsVideoItem::size + \brief the video item's size. + + QGraphicsVideoItem will draw video scaled to fit size according to its + fillMode. +*/ + +QSizeF QGraphicsVideoItem::size() const +{ + return d_func()->rect.size(); +} + +void QGraphicsVideoItem::setSize(const QSizeF &size) +{ + Q_D(QGraphicsVideoItem); + + d->rect.setSize(size.isValid() ? size : QSizeF(0, 0)); + d->updateRects(); +} + +/*! + \property QGraphicsVideoItem::nativeSize + \brief the native size of the video. +*/ + +QSizeF QGraphicsVideoItem::nativeSize() const +{ + return d_func()->nativeSize; +} + +/*! + \fn QGraphicsVideoItem::nativeSizeChanged(const QSizeF &size) + + Signals that the native \a size of the video has changed. +*/ + +/*! + \reimp +*/ +QRectF QGraphicsVideoItem::boundingRect() const +{ + return d_func()->boundingRect; +} + +/*! + \reimp +*/ +void QGraphicsVideoItem::paint( + QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) +{ + Q_D(QGraphicsVideoItem); + + Q_UNUSED(option); + Q_UNUSED(widget); + + if (d->surface && d->surface->isActive()) { + d->surface->paint(painter, d->boundingRect, d->sourceRect); + d->surface->setReady(true); +#if !defined(QT_NO_OPENGL) && !defined(QT_OPENGL_ES_1_CL) && !defined(QT_OPENGL_ES_1) + } else if (d->updatePaintDevice && (painter->paintEngine()->type() == QPaintEngine::OpenGL + || painter->paintEngine()->type() == QPaintEngine::OpenGL2)) { + d->updatePaintDevice = false; + + d->surface->setGLContext(const_cast(QGLContext::currentContext())); + if (d->surface->supportedShaderTypes() & QPainterVideoSurface::GlslShader) { + d->surface->setShaderType(QPainterVideoSurface::GlslShader); + } else { + d->surface->setShaderType(QPainterVideoSurface::FragmentProgramShader); + } +#endif + } +} + +/*! + \reimp + + \internal +*/ +QVariant QGraphicsVideoItem::itemChange(GraphicsItemChange change, const QVariant &value) +{ + return QGraphicsObject::itemChange(change, value); +} + +/*! + \reimp + + \internal +*/ +bool QGraphicsVideoItem::event(QEvent *event) +{ + return QGraphicsObject::event(event); +} + +/*! + \reimp + + \internal +*/ +bool QGraphicsVideoItem::sceneEvent(QEvent *event) +{ + return QGraphicsObject::sceneEvent(event); +} + +QT_END_NAMESPACE +#include "moc_qgraphicsvideoitem.cpp" diff --git a/src/multimedia/mediaservices/base/qgraphicsvideoitem.h b/src/multimedia/mediaservices/base/qgraphicsvideoitem.h new file mode 100644 index 0000000..c0d8f7a --- /dev/null +++ b/src/multimedia/mediaservices/base/qgraphicsvideoitem.h @@ -0,0 +1,112 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtMediaservices module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QGRAPHICSVIDEOITEM_H +#define QGRAPHICSVIDEOITEM_H + +#include + +#include + + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Multimedia) + +class QVideoSurfaceFormat; + +class QGraphicsVideoItemPrivate; +class Q_MULTIMEDIA_EXPORT QGraphicsVideoItem : public QGraphicsObject +{ + Q_OBJECT + Q_PROPERTY(QMediaObject* mediaObject READ mediaObject WRITE setMediaObject) + Q_PROPERTY(Qt::AspectRatioMode aspectRatioMode READ aspectRatioMode WRITE setAspectRatioMode) + Q_PROPERTY(QPointF offset READ offset WRITE setOffset) + Q_PROPERTY(QSizeF size READ size WRITE setSize) + Q_PROPERTY(QSizeF nativeSize READ nativeSize NOTIFY nativeSizeChanged) +public: + QGraphicsVideoItem(QGraphicsItem *parent = 0); + ~QGraphicsVideoItem(); + + QMediaObject *mediaObject() const; + void setMediaObject(QMediaObject *object); + + Qt::AspectRatioMode aspectRatioMode() const; + void setAspectRatioMode(Qt::AspectRatioMode mode); + + QPointF offset() const; + void setOffset(const QPointF &offset); + + QSizeF size() const; + void setSize(const QSizeF &size); + + QSizeF nativeSize() const; + + QRectF boundingRect() const; + + void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0); + +Q_SIGNALS: + void nativeSizeChanged(const QSizeF &size); + +protected: + bool event(QEvent *event); + bool sceneEvent(QEvent *event); + + QVariant itemChange(GraphicsItemChange change, const QVariant &value); + + QGraphicsVideoItemPrivate *d_ptr; + +private: + Q_DECLARE_PRIVATE(QGraphicsVideoItem) + Q_PRIVATE_SLOT(d_func(), void _q_present()) + Q_PRIVATE_SLOT(d_func(), void _q_formatChanged(const QVideoSurfaceFormat &)) + Q_PRIVATE_SLOT(d_func(), void _q_serviceDestroyed()) + Q_PRIVATE_SLOT(d_func(), void _q_mediaObjectDestroyed()) +}; + +QT_END_NAMESPACE + +QT_END_HEADER + +#endif diff --git a/src/multimedia/mediaservices/base/qlocalmediaplaylistprovider.cpp b/src/multimedia/mediaservices/base/qlocalmediaplaylistprovider.cpp new file mode 100644 index 0000000..818b285 --- /dev/null +++ b/src/multimedia/mediaservices/base/qlocalmediaplaylistprovider.cpp @@ -0,0 +1,196 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtMediaservices module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include "qmediaplaylistprovider_p.h" +#include + + +QT_BEGIN_NAMESPACE + +class QLocalMediaPlaylistProviderPrivate: public QMediaPlaylistProviderPrivate +{ +public: + QList resources; +}; + +QLocalMediaPlaylistProvider::QLocalMediaPlaylistProvider(QObject *parent) + :QMediaPlaylistProvider(*new QLocalMediaPlaylistProviderPrivate, parent) +{ +} + +QLocalMediaPlaylistProvider::~QLocalMediaPlaylistProvider() +{ +} + +bool QLocalMediaPlaylistProvider::isReadOnly() const +{ + return false; +} + +int QLocalMediaPlaylistProvider::mediaCount() const +{ + return d_func()->resources.size(); +} + +QMediaContent QLocalMediaPlaylistProvider::media(int pos) const +{ + return d_func()->resources.value(pos); +} + +bool QLocalMediaPlaylistProvider::addMedia(const QMediaContent &content) +{ + Q_D(QLocalMediaPlaylistProvider); + + int pos = d->resources.count(); + + emit mediaAboutToBeInserted(pos, pos); + d->resources.append(content); + emit mediaInserted(pos, pos); + + return true; +} + +bool QLocalMediaPlaylistProvider::addMedia(const QList &items) +{ + Q_D(QLocalMediaPlaylistProvider); + + if (items.isEmpty()) + return true; + + int pos = d->resources.count(); + int end = pos+items.count()-1; + + emit mediaAboutToBeInserted(pos, end); + d->resources.append(items); + emit mediaInserted(pos, end); + + return true; +} + + +bool QLocalMediaPlaylistProvider::insertMedia(int pos, const QMediaContent &content) +{ + Q_D(QLocalMediaPlaylistProvider); + + emit mediaAboutToBeInserted(pos, pos); + d->resources.insert(pos, content); + emit mediaInserted(pos,pos); + + return true; +} + +bool QLocalMediaPlaylistProvider::insertMedia(int pos, const QList &items) +{ + Q_D(QLocalMediaPlaylistProvider); + + if (items.isEmpty()) + return true; + + const int last = pos+items.count()-1; + + emit mediaAboutToBeInserted(pos, last); + for (int i=0; iresources.insert(pos+i, items.at(i)); + emit mediaInserted(pos, last); + + return true; +} + +bool QLocalMediaPlaylistProvider::removeMedia(int fromPos, int toPos) +{ + Q_D(QLocalMediaPlaylistProvider); + + Q_ASSERT(fromPos >= 0); + Q_ASSERT(fromPos <= toPos); + Q_ASSERT(toPos < mediaCount()); + + emit mediaAboutToBeRemoved(fromPos, toPos); + d->resources.erase(d->resources.begin()+fromPos, d->resources.begin()+toPos+1); + emit mediaRemoved(fromPos, toPos); + + return true; +} + +bool QLocalMediaPlaylistProvider::removeMedia(int pos) +{ + Q_D(QLocalMediaPlaylistProvider); + + emit mediaAboutToBeRemoved(pos, pos); + d->resources.removeAt(pos); + emit mediaRemoved(pos, pos); + + return true; +} + +bool QLocalMediaPlaylistProvider::clear() +{ + Q_D(QLocalMediaPlaylistProvider); + if (!d->resources.isEmpty()) { + int lastPos = mediaCount()-1; + emit mediaAboutToBeRemoved(0, lastPos); + d->resources.clear(); + emit mediaRemoved(0, lastPos); + } + + return true; +} + +void QLocalMediaPlaylistProvider::shuffle() +{ + Q_D(QLocalMediaPlaylistProvider); + if (!d->resources.isEmpty()) { + QList resources; + + while (!d->resources.isEmpty()) { + resources.append(d->resources.takeAt(qrand() % d->resources.size())); + } + + d->resources = resources; + emit mediaChanged(0, mediaCount()-1); + } + +} + +#include "moc_qlocalmediaplaylistprovider.cpp" + +QT_END_NAMESPACE + diff --git a/src/multimedia/mediaservices/base/qlocalmediaplaylistprovider.h b/src/multimedia/mediaservices/base/qlocalmediaplaylistprovider.h new file mode 100644 index 0000000..73ff82d --- /dev/null +++ b/src/multimedia/mediaservices/base/qlocalmediaplaylistprovider.h @@ -0,0 +1,87 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtMediaservices module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QLOCALMEDIAPAYLISTPROVIDER_H +#define QLOCALMEDIAPAYLISTPROVIDER_H + +#include + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Multimedia) + + +class QLocalMediaPlaylistProviderPrivate; +class Q_MULTIMEDIA_EXPORT QLocalMediaPlaylistProvider : public QMediaPlaylistProvider +{ + Q_OBJECT + +public: + QLocalMediaPlaylistProvider(QObject *parent=0); + virtual ~QLocalMediaPlaylistProvider(); + + virtual int mediaCount() const; + virtual QMediaContent media(int pos) const; + + virtual bool isReadOnly() const; + + virtual bool addMedia(const QMediaContent &content); + virtual bool addMedia(const QList &items); + virtual bool insertMedia(int pos, const QMediaContent &content); + virtual bool insertMedia(int pos, const QList &items); + virtual bool removeMedia(int pos); + virtual bool removeMedia(int start, int end); + virtual bool clear(); + +public Q_SLOTS: + virtual void shuffle(); + +private: + Q_DECLARE_PRIVATE(QLocalMediaPlaylistProvider) +}; + +QT_END_NAMESPACE + +QT_END_HEADER + +#endif // QLOCALMEDIAPAYLISTSOURCE_H diff --git a/src/multimedia/mediaservices/base/qmediacontent.cpp b/src/multimedia/mediaservices/base/qmediacontent.cpp new file mode 100644 index 0000000..f89e901 --- /dev/null +++ b/src/multimedia/mediaservices/base/qmediacontent.cpp @@ -0,0 +1,242 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtMediaservices module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include + +#include + + +QT_BEGIN_NAMESPACE + + +class QMediaContentPrivate : public QSharedData +{ +public: + QMediaContentPrivate() {} + QMediaContentPrivate(const QMediaResourceList &r): + resources(r) {} + + QMediaContentPrivate(const QMediaContentPrivate &other): + QSharedData(other), + resources(other.resources) + {} + + bool operator==(const QMediaContentPrivate &other) const + { + return resources == other.resources; + } + + QMediaResourceList resources; + +private: + QMediaContentPrivate& operator=(const QMediaContentPrivate &other); +}; + + +/*! + \class QMediaContent + \preliminary + \brief The QMediaContent class provides access to the resources relating to a media content. + \since 4.7 + + \ingroup multimedia + + QMediaContent is used within the multimedia framework as the logical handle + to media content. A QMediaContent object is composed of one or more + \l {QMediaResource}s where each resource provides the URL and format + information of a different encoding of the content. + + A non-null QMediaContent will always have a primary or canonical reference to + the content available through the canonicalUrl() or canonicalResource() + methods, any additional resources are optional. +*/ + + +/*! + Constructs a null QMediaContent. +*/ + +QMediaContent::QMediaContent() +{ +} + +/*! + Constructs a media content with \a url providing a reference to the content. +*/ + +QMediaContent::QMediaContent(const QUrl &url): + d(new QMediaContentPrivate) +{ + d->resources << QMediaResource(url); +} + +/*! + Constructs a media content with \a request providing a reference to the content. + + This constructor can be used to reference media content via network protocols such as HTTP. + This may include additional information required to obtain the resource, such as Cookies or HTTP headers. +*/ + +QMediaContent::QMediaContent(const QNetworkRequest &request): + d(new QMediaContentPrivate) +{ + d->resources << QMediaResource(request); +} + +/*! + Constructs a media content with \a resource providing a reference to the content. +*/ + +QMediaContent::QMediaContent(const QMediaResource &resource): + d(new QMediaContentPrivate) +{ + d->resources << resource; +} + +/*! + Constructs a media content with \a resources providing a reference to the content. +*/ + +QMediaContent::QMediaContent(const QMediaResourceList &resources): + d(new QMediaContentPrivate(resources)) +{ +} + +/*! + Constructs a copy of the media content \a other. +*/ + +QMediaContent::QMediaContent(const QMediaContent &other): + d(other.d) +{ +} + +/*! + Destroys the media content object. +*/ + +QMediaContent::~QMediaContent() +{ +} + +/*! + Assigns the value of \a other to this media content. +*/ + +QMediaContent& QMediaContent::operator=(const QMediaContent &other) +{ + d = other.d; + return *this; +} + +/*! + Returns true if \a other is equivalent to this media content; false otherwise. +*/ + +bool QMediaContent::operator==(const QMediaContent &other) const +{ + return (d.constData() == 0 && other.d.constData() == 0) || + (d.constData() != 0 && other.d.constData() != 0 && + *d.constData() == *other.d.constData()); +} + +/*! + Returns true if \a other is not equivalent to this media content; false otherwise. +*/ + +bool QMediaContent::operator!=(const QMediaContent &other) const +{ + return !(*this == other); +} + +/*! + Returns true if this media content is null (uninitialized); false otherwise. +*/ + +bool QMediaContent::isNull() const +{ + return d.constData() == 0; +} + +/*! + Returns a QUrl that represents that canonical resource for this media content. +*/ + +QUrl QMediaContent::canonicalUrl() const +{ + return canonicalResource().url(); +} + +/*! + Returns a QNetworkRequest that represents that canonical resource for this media content. +*/ + +QNetworkRequest QMediaContent::canonicalRequest() const +{ + return canonicalResource().request(); +} + +/*! + Returns a QMediaResource that represents that canonical resource for this media content. +*/ + +QMediaResource QMediaContent::canonicalResource() const +{ + return d.constData() != 0 + ? d->resources.value(0) + : QMediaResource(); +} + +/*! + Returns a list of alternative resources for this media content. The first item in this list + is always the canonical resource. +*/ + +QMediaResourceList QMediaContent::resources() const +{ + return d.constData() != 0 + ? d->resources + : QMediaResourceList(); +} + +QT_END_NAMESPACE + diff --git a/src/multimedia/mediaservices/base/qmediacontent.h b/src/multimedia/mediaservices/base/qmediacontent.h new file mode 100644 index 0000000..20f0525 --- /dev/null +++ b/src/multimedia/mediaservices/base/qmediacontent.h @@ -0,0 +1,93 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtMediaservices module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QMEDIACONTENT_H +#define QMEDIACONTENT_H + +#include +#include + +#include +#include + + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Multimedia) + +class QMediaContentPrivate; +class Q_MULTIMEDIA_EXPORT QMediaContent +{ +public: + QMediaContent(); + QMediaContent(const QUrl &contentUrl); + QMediaContent(const QNetworkRequest &contentRequest); + QMediaContent(const QMediaResource &contentResource); + QMediaContent(const QMediaResourceList &resources); + QMediaContent(const QMediaContent &other); + ~QMediaContent(); + + QMediaContent& operator=(const QMediaContent &other); + + bool operator==(const QMediaContent &other) const; + bool operator!=(const QMediaContent &other) const; + + bool isNull() const; + + QUrl canonicalUrl() const; + QNetworkRequest canonicalRequest() const; + QMediaResource canonicalResource() const; + + QMediaResourceList resources() const; + +private: + QSharedDataPointer d; +}; + +QT_END_NAMESPACE + +Q_DECLARE_METATYPE(QMediaContent) + +QT_END_HEADER + +#endif // QMEDIACONTENT_H diff --git a/src/multimedia/mediaservices/base/qmediacontrol.cpp b/src/multimedia/mediaservices/base/qmediacontrol.cpp new file mode 100644 index 0000000..98db9fe --- /dev/null +++ b/src/multimedia/mediaservices/base/qmediacontrol.cpp @@ -0,0 +1,140 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtMediaservices module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include + +#include +#include + + + +QT_BEGIN_NAMESPACE + +/*! + \class QMediaControl + \ingroup multimedia-serv + \since 4.7 + + \preliminary + \brief The QMediaControl class provides a base interface for media service controls. + + Media controls provide an interface to individual features provided by a media service. Most + services implement a principal control which exposes the core functionality of the service and + a number optional controls which expose any additional functionality. + + A pointer to a control implemented by a media service can be obtained using the + \l {QMediaService::control()}{control()} member of QMediaService. If the service doesn't + implement a control it will instead return a null pointer. + + \code + QMediaPlayerControl *control = qobject_cast( + service->control("com.nokia.Qt.QMediaPlayerControl/1.0")); + \endcode + + Alternatively if the IId of the control has been declared using Q_MEDIA_DECLARE_CONTROL + the template version of QMediaService::control() can be used to request the service without + explicitly passing the IId. + + \code + QMediaPlayerControl *control = service->control(); + \endcode + + Most application code will not interface directly with a media service's controls, instead the + QMediaObject which owns the service acts as an intermeditary between one or more controls and + the application. + + \sa QMediaService, QMediaObject +*/ + +/*! + \macro Q_MEDIA_DECLARE_CONTROL(Class, IId) + \relates QMediaControl + + The Q_MEDIA_DECLARE_CONTROL macro declares an \a IId for a \a Class that inherits from + QMediaControl. + + Declaring an IId for a QMediaControl allows an instance of that control to be requested from + QMediaService::control() without explicitly passing the IId. + + \code + QMediaPlayerControl *control = service->control(); + \endcode + + \sa QMediaService::control() +*/ + +/*! + Destroys a media control. +*/ + +QMediaControl::~QMediaControl() +{ + delete d_ptr; +} + +/*! + Constructs a media control with the given \a parent. +*/ + +QMediaControl::QMediaControl(QObject *parent) + : QObject(parent) + , d_ptr(new QMediaControlPrivate) +{ + d_ptr->q_ptr = this; +} + +/*! + \internal +*/ + +QMediaControl::QMediaControl(QMediaControlPrivate &dd, QObject *parent) + : QObject(parent) + , d_ptr(&dd) + +{ + d_ptr->q_ptr = this; +} + +#include "moc_qmediacontrol.cpp" + +QT_END_NAMESPACE + diff --git a/src/multimedia/mediaservices/base/qmediacontrol.h b/src/multimedia/mediaservices/base/qmediacontrol.h new file mode 100644 index 0000000..be5d95d --- /dev/null +++ b/src/multimedia/mediaservices/base/qmediacontrol.h @@ -0,0 +1,82 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtMediaservices module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QABSTRACTMEDIACONTROL_H +#define QABSTRACTMEDIACONTROL_H + +#include +#include +#include + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Multimedia) + +class QMediaControlPrivate; +class Q_MULTIMEDIA_EXPORT QMediaControl : public QObject +{ + Q_OBJECT + +public: + ~QMediaControl(); + +protected: + QMediaControl(QObject *parent = 0); + QMediaControl(QMediaControlPrivate &dd, QObject *parent = 0); + + QMediaControlPrivate *d_ptr; + +private: + Q_DECLARE_PRIVATE(QMediaControl) +}; + +template const char *qmediacontrol_iid() { return 0; } + +#define Q_MEDIA_DECLARE_CONTROL(Class, IId) \ + template <> inline const char *qmediacontrol_iid() { return IId; } + +QT_END_NAMESPACE + +QT_END_HEADER + +#endif // QABSTRACTMEDIACONTROL_H diff --git a/src/multimedia/mediaservices/base/qmediacontrol_p.h b/src/multimedia/mediaservices/base/qmediacontrol_p.h new file mode 100644 index 0000000..ad7e947 --- /dev/null +++ b/src/multimedia/mediaservices/base/qmediacontrol_p.h @@ -0,0 +1,74 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtMediaservices module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QABSTRACTMEDIACONTROL_P_H +#define QABSTRACTMEDIACONTROL_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +class QMediaControl; + +class QMediaControlPrivate +{ +public: + virtual ~QMediaControlPrivate() {} + + QMediaControl *q_ptr; +}; + +QT_END_NAMESPACE + +QT_END_HEADER + +#endif diff --git a/src/multimedia/mediaservices/base/qmediaobject.cpp b/src/multimedia/mediaservices/base/qmediaobject.cpp new file mode 100644 index 0000000..3d92b12 --- /dev/null +++ b/src/multimedia/mediaservices/base/qmediaobject.cpp @@ -0,0 +1,419 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtMediaservics module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include + +#include "qmediaobject_p.h" + +#include +#include + + +QT_BEGIN_NAMESPACE + +void QMediaObjectPrivate::_q_notify() +{ + Q_Q(QMediaObject); + + const QMetaObject* m = q->metaObject(); + + foreach (int pi, notifyProperties) { + QMetaProperty p = m->property(pi); + p.notifySignal().invoke( + q, QGenericArgument(QMetaType::typeName(p.userType()), p.read(q).data())); + } +} + + +/*! + \class QMediaObject + \preliminary + \brief The QMediaObject class provides a common base for multimedia objects. + \since 4.7 + + \ingroup multimedia + + QMediaObject derived classes provide access to the functionality of a + QMediaService. Each media object hosts a QMediaService and uses the + QMediaControl interfaces implemented by the service to implement its + API. Most media objects when constructed will request a new + QMediaService instance from a QMediaServiceProvider, but some like + QMediaRecorder will share a service with another object. + + QMediaObject itself provides an API for accessing a media service's \l {metaData()}{meta-data} and a means of connecting other media objects, + and peripheral classes like QVideoWidget and QMediaPlaylist. + + \sa QMediaService, QMediaControl +*/ + +/*! + Destroys a media object. +*/ + +QMediaObject::~QMediaObject() +{ + delete d_ptr; +} + +/*! + Returns the service availability error state. +*/ + +QtMediaservices::AvailabilityError QMediaObject::availabilityError() const +{ + return QtMediaservices::ServiceMissingError; +} + +/*! + Returns true if the service is available for use. +*/ + +bool QMediaObject::isAvailable() const +{ + return false; +} + +/*! + Returns the media service that provides the functionality of a multimedia object. +*/ + +QMediaService* QMediaObject::service() const +{ + return d_func()->service; +} + +int QMediaObject::notifyInterval() const +{ + return d_func()->notifyTimer->interval(); +} + +void QMediaObject::setNotifyInterval(int milliSeconds) +{ + Q_D(QMediaObject); + + if (d->notifyTimer->interval() != milliSeconds) { + d->notifyTimer->setInterval(milliSeconds); + + emit notifyIntervalChanged(milliSeconds); + } +} + +/*! + \internal +*/ +void QMediaObject::bind(QObject*) +{ +} + +/*! + \internal +*/ +void QMediaObject::unbind(QObject*) +{ +} + + +/*! + Constructs a media object which uses the functionality provided by a media \a service. + + The \a parent is passed to QObject. + + This class is meant as a base class for Multimedia objects so this + constructor is protected. +*/ + +QMediaObject::QMediaObject(QObject *parent, QMediaService *service): + QObject(parent), + d_ptr(new QMediaObjectPrivate) + +{ + Q_D(QMediaObject); + + d->q_ptr = this; + + d->notifyTimer = new QTimer(this); + d->notifyTimer->setInterval(1000); + connect(d->notifyTimer, SIGNAL(timeout()), SLOT(_q_notify())); + + d->service = service; + + setupMetaData(); +} + +/*! + \internal +*/ + +QMediaObject::QMediaObject(QMediaObjectPrivate &dd, QObject *parent, + QMediaService *service): + QObject(parent), + d_ptr(&dd) +{ + Q_D(QMediaObject); + d->q_ptr = this; + + d->notifyTimer = new QTimer(this); + d->notifyTimer->setInterval(1000); + connect(d->notifyTimer, SIGNAL(timeout()), SLOT(_q_notify())); + + d->service = service; + + setupMetaData(); +} + +/*! + Watch the property \a name. The property's notify signal will be emitted + once every notifyInterval milliseconds. + + \sa notifyInterval +*/ + +void QMediaObject::addPropertyWatch(QByteArray const &name) +{ + Q_D(QMediaObject); + + const QMetaObject* m = metaObject(); + + int index = m->indexOfProperty(name.constData()); + + if (index != -1 && m->property(index).hasNotifySignal()) { + d->notifyProperties.insert(index); + + if (!d->notifyTimer->isActive()) + d->notifyTimer->start(); + } +} + +/*! + Remove property \a name from the list of properties whose changes are + regularly signaled. + + \sa notifyInterval +*/ + +void QMediaObject::removePropertyWatch(QByteArray const &name) +{ + Q_D(QMediaObject); + + int index = metaObject()->indexOfProperty(name.constData()); + + if (index != -1) { + d->notifyProperties.remove(index); + + if (d->notifyProperties.isEmpty()) + d->notifyTimer->stop(); + } +} + +/*! + \property QMediaObject::notifyInterval + + The interval at which notifiable properties will update. + + The interval is expressed in milliseconds, the default value is 1000. + + \sa addPropertyWatch(), removePropertyWatch() +*/ + +/*! + \fn void QMediaObject::notifyIntervalChanged(int milliseconds) + + Signal a change in the notify interval period to \a milliseconds. +*/ + +/*! + \property QMediaObject::metaDataAvailable + \brief whether access to a media object's meta-data is available. + + If this is true there is meta-data available, otherwise there is no meta-data available. +*/ + +bool QMediaObject::isMetaDataAvailable() const +{ + Q_D(const QMediaObject); + + return d->metaDataControl + ? d->metaDataControl->isMetaDataAvailable() + : false; +} + +/*! + \fn QMediaObject::metaDataAvailableChanged(bool available) + + Signals that the \a available state of a media object's meta-data has changed. +*/ + +/*! + \property QMediaObject::metaDataWritable + \brief whether a media object's meta-data is writable. + + If this is true the meta-data is writable, otherwise the meta-data is read-only. +*/ + +bool QMediaObject::isMetaDataWritable() const +{ + Q_D(const QMediaObject); + + return d->metaDataControl + ? d->metaDataControl->isWritable() + : false; +} + +/*! + \fn QMediaObject::metaDataWritableChanged(bool writable) + + Signals that the \a writable state of a media object's meta-data has changed. +*/ + +/*! + Returns the value associated with a meta-data \a key. +*/ +QVariant QMediaObject::metaData(QtMediaservices::MetaData key) const +{ + Q_D(const QMediaObject); + + return d->metaDataControl + ? d->metaDataControl->metaData(key) + : QVariant(); +} + +/*! + Sets a \a value for a meta-data \a key. +*/ +void QMediaObject::setMetaData(QtMediaservices::MetaData key, const QVariant &value) +{ + Q_D(QMediaObject); + + if (d->metaDataControl) + d->metaDataControl->setMetaData(key, value); +} + +/*! + Returns a list of keys there is meta-data available for. +*/ +QList QMediaObject::availableMetaData() const +{ + Q_D(const QMediaObject); + + return d->metaDataControl + ? d->metaDataControl->availableMetaData() + : QList(); +} + +/*! + \fn QMediaObject::metaDataChanged() + + Signals that a media object's meta-data has changed. +*/ + +/*! + Returns the value associated with a meta-data \a key. + + The naming and type of extended meta-data is not standardized, so the values and meaning + of keys may vary between backends. +*/ +QVariant QMediaObject::extendedMetaData(const QString &key) const +{ + Q_D(const QMediaObject); + + return d->metaDataControl + ? d->metaDataControl->extendedMetaData(key) + : QVariant(); +} + +/*! + Sets a \a value for a meta-data \a key. + + The naming and type of extended meta-data is not standardized, so the values and meaning + of keys may vary between backends. +*/ +void QMediaObject::setExtendedMetaData(const QString &key, const QVariant &value) +{ + Q_D(QMediaObject); + + if (d->metaDataControl) + d->metaDataControl->setExtendedMetaData(key, value); +} + +/*! + Returns a list of keys there is extended meta-data available for. +*/ +QStringList QMediaObject::availableExtendedMetaData() const +{ + Q_D(const QMediaObject); + + return d->metaDataControl + ? d->metaDataControl->availableExtendedMetaData() + : QStringList(); +} + + +void QMediaObject::setupMetaData() +{ + Q_D(QMediaObject); + + if (d->service != 0) { + d->metaDataControl = + qobject_cast(d->service->control(QMetaDataControl_iid)); + + if (d->metaDataControl) { + connect(d->metaDataControl, SIGNAL(metaDataChanged()), SIGNAL(metaDataChanged())); + connect(d->metaDataControl, + SIGNAL(metaDataAvailableChanged(bool)), + SIGNAL(metaDataAvailableChanged(bool))); + connect(d->metaDataControl, + SIGNAL(writableChanged(bool)), + SIGNAL(metaDataWritableChanged(bool))); + } + } +} + +/*! + \fn QMediaObject::availabilityChanged(bool available) + + Signal emitted when the availability state has changed to \a available +*/ + + +#include "moc_qmediaobject.cpp" + +QT_END_NAMESPACE + diff --git a/src/multimedia/mediaservices/base/qmediaobject.h b/src/multimedia/mediaservices/base/qmediaobject.h new file mode 100644 index 0000000..461e056 --- /dev/null +++ b/src/multimedia/mediaservices/base/qmediaobject.h @@ -0,0 +1,121 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtMediaservices module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QABSTRACTMEDIAOBJECT_H +#define QABSTRACTMEDIAOBJECT_H + +#include +#include + +#include + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Multimedia) + +class QMediaService; + +class QMediaObjectPrivate; +class Q_MULTIMEDIA_EXPORT QMediaObject : public QObject +{ + Q_OBJECT + Q_PROPERTY(int notifyInterval READ notifyInterval WRITE setNotifyInterval NOTIFY notifyIntervalChanged) + Q_PROPERTY(bool metaDataAvailable READ isMetaDataAvailable NOTIFY metaDataAvailableChanged) + Q_PROPERTY(bool metaDataWritable READ isMetaDataWritable NOTIFY metaDataWritableChanged) + +public: + ~QMediaObject(); + + virtual bool isAvailable() const; + virtual QtMediaservices::AvailabilityError availabilityError() const; + + virtual QMediaService* service() const; + + int notifyInterval() const; + void setNotifyInterval(int milliSeconds); + + virtual void bind(QObject*); + virtual void unbind(QObject*); + + bool isMetaDataAvailable() const; + bool isMetaDataWritable() const; + + QVariant metaData(QtMediaservices::MetaData key) const; + void setMetaData(QtMediaservices::MetaData key, const QVariant &value); + QList availableMetaData() const; + + QVariant extendedMetaData(const QString &key) const; + void setExtendedMetaData(const QString &key, const QVariant &value); + QStringList availableExtendedMetaData() const; + +Q_SIGNALS: + void notifyIntervalChanged(int milliSeconds); + + void metaDataAvailableChanged(bool available); + void metaDataWritableChanged(bool writable); + void metaDataChanged(); + + void availabilityChanged(bool available); + +protected: + QMediaObject(QObject *parent, QMediaService *service); + QMediaObject(QMediaObjectPrivate &dd, QObject *parent, QMediaService *service); + + void addPropertyWatch(QByteArray const &name); + void removePropertyWatch(QByteArray const &name); + + QMediaObjectPrivate *d_ptr; + +private: + void setupMetaData(); + + Q_DECLARE_PRIVATE(QMediaObject) + Q_PRIVATE_SLOT(d_func(), void _q_notify()) +}; + +QT_END_NAMESPACE + +QT_END_HEADER + + +#endif // QABSTRACTMEDIAOBJECT_H diff --git a/src/multimedia/mediaservices/base/qmediaobject_p.h b/src/multimedia/mediaservices/base/qmediaobject_p.h new file mode 100644 index 0000000..4589f03 --- /dev/null +++ b/src/multimedia/mediaservices/base/qmediaobject_p.h @@ -0,0 +1,95 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtMediaservices module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QABSTRACTMEDIAOBJECT_P_H +#define QABSTRACTMEDIAOBJECT_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include +#include +#include + +#include + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +class QMetaDataControl; + +#define Q_DECLARE_NON_CONST_PUBLIC(Class) \ + inline Class* q_func() { return static_cast(q_ptr); } \ + friend class Class; + + +class QMediaObjectPrivate +{ + Q_DECLARE_PUBLIC(QMediaObject) + +public: + QMediaObjectPrivate():metaDataControl(0), notifyTimer(0) {} + virtual ~QMediaObjectPrivate() {} + + void _q_notify(); + + QMediaService *service; + QMetaDataControl *metaDataControl; + QTimer* notifyTimer; + QSet notifyProperties; + + QMediaObject *q_ptr; +}; + +QT_END_NAMESPACE + +QT_END_HEADER + +#endif diff --git a/src/multimedia/mediaservices/base/qmediaplaylist.cpp b/src/multimedia/mediaservices/base/qmediaplaylist.cpp new file mode 100644 index 0000000..174a8ac --- /dev/null +++ b/src/multimedia/mediaservices/base/qmediaplaylist.cpp @@ -0,0 +1,724 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtMediaservices module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include +#include +#include +#include + +#include +#include "qmediaplaylist_p.h" +#include +#include +#include +#include +#include +#include + +#include "qmediapluginloader_p.h" + + +QT_BEGIN_NAMESPACE + +Q_GLOBAL_STATIC_WITH_ARGS(QMediaPluginLoader, playlistIOLoader, + (QMediaPlaylistIOInterface_iid, QLatin1String("/playlistformats"), Qt::CaseInsensitive)) + + +/*! + \class QMediaPlaylist + \ingroup multimedia + \since 4.7 + + \preliminary + \brief The QMediaPlaylist class provides a list of media content to play. + + QMediaPlaylist is intended to be used with other media objects, + like QMediaPlayer or QMediaImageViewer. + QMediaPlaylist allows to access the service intrinsic playlist functionality + if available, otherwise it provides the the local memory playlist implementation. + +\code + player = new QMediaPlayer; + + playlist = new QMediaPlaylist; + playlist->setMediaObject(player); + playlist->append(QUrl("http://example.com/movie1.mp4")); + playlist->append(QUrl("http://example.com/movie2.mp4")); + playlist->append(QUrl("http://example.com/movie3.mp4")); + + playlist->setCurrentIndex(1); + + player->play(); +\endcode + + Depending on playlist source implementation, + most of playlist modifcation operations can be asynchronous. + + \sa QMediaContent +*/ + + +/*! + \enum QMediaPlaylist::PlaybackMode + + The QMediaPlaylist::PlaybackMode describes the order items in playlist are played. + + \value CurrentItemOnce The current item is played only once. + + \value CurrentItemInLoop The current item is played in the loop. + + \value Linear Playback starts from the first to the last items and stops. + next item is a null item when the last one is currently playing. + + \value Loop Playback continues from the first item after the last one finished playing. + + \value Random Play items in random order. +*/ + + + +/*! + Create a new playlist object for with the given \a parent. +*/ + +QMediaPlaylist::QMediaPlaylist(QObject *parent) + : QObject(parent) + , d_ptr(new QMediaPlaylistPrivate) +{ + Q_D(QMediaPlaylist); + + d->q_ptr = this; + d->localPlaylistControl = new QLocalMediaPlaylistControl(this); + + setMediaObject(0); +} + +/*! + Destroys the playlist. + */ + +QMediaPlaylist::~QMediaPlaylist() +{ + Q_D(QMediaPlaylist); + + if (d->mediaObject) + d->mediaObject->unbind(this); + + delete d_ptr; +} + +/*! + Returns the QMediaObject that is being used to play the contents of this playlist. +*/ + +QMediaObject *QMediaPlaylist::mediaObject() const +{ + return d_func()->mediaObject; +} + +/*! + If \a mediaObject is null or doesn't have an intrinsic playlist, + internal local memory playlist source will be created. +*/ +void QMediaPlaylist::setMediaObject(QMediaObject *mediaObject) +{ + Q_D(QMediaPlaylist); + + if (mediaObject && mediaObject == d->mediaObject) + return; + + QMediaService *service = mediaObject + ? mediaObject->service() : 0; + + QMediaPlaylistControl *newControl = 0; + + if (service) + newControl = qobject_cast(service->control(QMediaPlaylistControl_iid)); + + if (!newControl) + newControl = d->localPlaylistControl; + + if (d->control != newControl) { + int oldSize = 0; + if (d->control) { + QMediaPlaylistProvider *playlist = d->control->playlistProvider(); + oldSize = playlist->mediaCount(); + disconnect(playlist, SIGNAL(loadFailed(QMediaPlaylist::Error,QString)), + this, SLOT(_q_loadFailed(QMediaPlaylist::Error,QString))); + + disconnect(playlist, SIGNAL(mediaChanged(int,int)), this, SIGNAL(mediaChanged(int,int))); + disconnect(playlist, SIGNAL(mediaAboutToBeInserted(int,int)), this, SIGNAL(mediaAboutToBeInserted(int,int))); + disconnect(playlist, SIGNAL(mediaInserted(int,int)), this, SIGNAL(mediaInserted(int,int))); + disconnect(playlist, SIGNAL(mediaAboutToBeRemoved(int,int)), this, SIGNAL(mediaAboutToBeRemoved(int,int))); + disconnect(playlist, SIGNAL(mediaRemoved(int,int)), this, SIGNAL(mediaRemoved(int,int))); + + disconnect(playlist, SIGNAL(loaded()), this, SIGNAL(loaded())); + + disconnect(d->control, SIGNAL(playbackModeChanged(QMediaPlaylist::PlaybackMode)), + this, SIGNAL(playbackModeChanged(QMediaPlaylist::PlaybackMode))); + disconnect(d->control, SIGNAL(currentIndexChanged(int)), + this, SIGNAL(currentIndexChanged(int))); + disconnect(d->control, SIGNAL(currentMediaChanged(QMediaContent)), + this, SIGNAL(currentMediaChanged(QMediaContent))); + } + + d->control = newControl; + QMediaPlaylistProvider *playlist = d->control->playlistProvider(); + connect(playlist, SIGNAL(loadFailed(QMediaPlaylist::Error,QString)), + this, SLOT(_q_loadFailed(QMediaPlaylist::Error,QString))); + + connect(playlist, SIGNAL(mediaChanged(int,int)), this, SIGNAL(mediaChanged(int,int))); + connect(playlist, SIGNAL(mediaAboutToBeInserted(int,int)), this, SIGNAL(mediaAboutToBeInserted(int,int))); + connect(playlist, SIGNAL(mediaInserted(int,int)), this, SIGNAL(mediaInserted(int,int))); + connect(playlist, SIGNAL(mediaAboutToBeRemoved(int,int)), this, SIGNAL(mediaAboutToBeRemoved(int,int))); + connect(playlist, SIGNAL(mediaRemoved(int,int)), this, SIGNAL(mediaRemoved(int,int))); + + connect(playlist, SIGNAL(loaded()), this, SIGNAL(loaded())); + + connect(d->control, SIGNAL(playbackModeChanged(QMediaPlaylist::PlaybackMode)), + this, SIGNAL(playbackModeChanged(QMediaPlaylist::PlaybackMode))); + connect(d->control, SIGNAL(currentIndexChanged(int)), + this, SIGNAL(currentIndexChanged(int))); + connect(d->control, SIGNAL(currentMediaChanged(QMediaContent)), + this, SIGNAL(currentMediaChanged(QMediaContent))); + + if (oldSize) + emit mediaRemoved(0, oldSize-1); + + if (playlist->mediaCount()) { + emit mediaAboutToBeInserted(0,playlist->mediaCount()-1); + emit mediaInserted(0,playlist->mediaCount()-1); + } + } + + if (d->mediaObject) + d->mediaObject->unbind(this); + + d->mediaObject = mediaObject; + if (d->mediaObject) + d->mediaObject->bind(this); +} + +/*! + \property QMediaPlaylist::playbackMode + + This property defines the order, items in playlist are played. + + \sa QMediaPlaylist::PlaybackMode +*/ + +QMediaPlaylist::PlaybackMode QMediaPlaylist::playbackMode() const +{ + return d_func()->control->playbackMode(); +} + +void QMediaPlaylist::setPlaybackMode(QMediaPlaylist::PlaybackMode mode) +{ + Q_D(QMediaPlaylist); + d->control->setPlaybackMode(mode); +} + +/*! + Returns position of the current media source in the playlist. +*/ +int QMediaPlaylist::currentIndex() const +{ + return d_func()->control->currentIndex(); +} + +/*! + Returns the current media content. +*/ + +QMediaContent QMediaPlaylist::currentMedia() const +{ + return d_func()->playlist()->media(currentIndex()); +} + +/*! + Returns the index of item, which were current after calling next() + \a steps times. + + Returned value depends on the size of playlist, current position + and playback mode. + + \sa QMediaPlaylist::playbackMode +*/ +int QMediaPlaylist::nextIndex(int steps) const +{ + return d_func()->control->nextIndex(steps); +} + +/*! + Returns the index of item, which were current after calling previous() + \a steps times. + + \sa QMediaPlaylist::playbackMode +*/ + +int QMediaPlaylist::previousIndex(int steps) const +{ + return d_func()->control->previousIndex(steps); +} + + +/*! + Returns the number of items in the playlist. + + \sa isEmpty() + */ +int QMediaPlaylist::mediaCount() const +{ + return d_func()->playlist()->mediaCount(); +} + +/*! + Returns true if the playlist contains no items; otherwise returns false. + \sa mediaCount() + */ +bool QMediaPlaylist::isEmpty() const +{ + return mediaCount() == 0; +} + +/*! + Returns true if the playlist can be modified; otherwise returns false. + \sa mediaCount() + */ +bool QMediaPlaylist::isReadOnly() const +{ + return d_func()->playlist()->isReadOnly(); +} + +/*! + Returns the media content at \a index in the playlist. +*/ + +QMediaContent QMediaPlaylist::media(int index) const +{ + return d_func()->playlist()->media(index); +} + +/*! + Append the media \a content to the playlist. + + Returns true if the operation is successfull, other wise return false. + */ +bool QMediaPlaylist::addMedia(const QMediaContent &content) +{ + return d_func()->control->playlistProvider()->addMedia(content); +} + +/*! + Append multiple media content \a items to the playlist. + + Returns true if the operation is successfull, other wise return false. + */ +bool QMediaPlaylist::addMedia(const QList &items) +{ + return d_func()->control->playlistProvider()->addMedia(items); +} + +/*! + Insert the media \a content to the playlist at position \a pos. + + Returns true if the operation is successful, otherwise false. +*/ + +bool QMediaPlaylist::insertMedia(int pos, const QMediaContent &content) +{ + return d_func()->playlist()->insertMedia(pos, content); +} + +/*! + Insert multiple media content \a items to the playlist at position \a pos. + + Returns true if the operation is successful, otherwise false. +*/ + +bool QMediaPlaylist::insertMedia(int pos, const QList &items) +{ + return d_func()->playlist()->insertMedia(pos, items); +} + +/*! + Remove the item from the playlist at position \a pos. + + Returns true if the operation is successfull, other wise return false. + */ +bool QMediaPlaylist::removeMedia(int pos) +{ + Q_D(QMediaPlaylist); + return d->playlist()->removeMedia(pos); +} + +/*! + Remove the items from the playlist from position \a start to \a end inclusive. + + Returns true if the operation is successfull, other wise return false. + */ +bool QMediaPlaylist::removeMedia(int start, int end) +{ + Q_D(QMediaPlaylist); + return d->playlist()->removeMedia(start, end); +} + +/*! + Remove all the items from the playlist. + + Returns true if the operation is successfull, other wise return false. + */ +bool QMediaPlaylist::clear() +{ + Q_D(QMediaPlaylist); + return d->playlist()->clear(); +} + +bool QMediaPlaylistPrivate::readItems(QMediaPlaylistReader *reader) +{ + while (!reader->atEnd()) + playlist()->addMedia(reader->readItem()); + + return true; +} + +bool QMediaPlaylistPrivate::writeItems(QMediaPlaylistWriter *writer) +{ + for (int i=0; imediaCount(); i++) { + if (!writer->writeItem(playlist()->media(i))) + return false; + } + writer->close(); + return true; +} + +/*! + Load playlist from \a location. If \a format is specified, it is used, + otherwise format is guessed from location name and data. + + New items are appended to playlist. + + QMediaPlaylist::loaded() signal is emited if playlist was loaded succesfully, + otherwise the playlist emits loadFailed(). +*/ +void QMediaPlaylist::load(const QUrl &location, const char *format) +{ + Q_D(QMediaPlaylist); + + d->error = NoError; + d->errorString.clear(); + + if (d->playlist()->load(location,format)) + return; + + if (isReadOnly()) { + d->error = AccessDeniedError; + d->errorString = tr("Could not add items to read only playlist."); + emit loadFailed(); + return; + } + + foreach (QString const& key, playlistIOLoader()->keys()) { + QMediaPlaylistIOInterface* plugin = qobject_cast(playlistIOLoader()->instance(key)); + if (plugin && plugin->canRead(location,format)) { + QMediaPlaylistReader *reader = plugin->createReader(location,QByteArray(format)); + if (reader && d->readItems(reader)) { + delete reader; + emit loaded(); + return; + } + delete reader; + } + } + + d->error = FormatNotSupportedError; + d->errorString = tr("Playlist format is not supported"); + emit loadFailed(); + + return; +} + +/*! + Load playlist from QIODevice \a device. If \a format is specified, it is used, + otherwise format is guessed from device data. + + New items are appended to playlist. + + QMediaPlaylist::loaded() signal is emited if playlist was loaded succesfully, + otherwise the playlist emits loadFailed(). +*/ +void QMediaPlaylist::load(QIODevice * device, const char *format) +{ + Q_D(QMediaPlaylist); + + d->error = NoError; + d->errorString.clear(); + + if (d->playlist()->load(device,format)) + return; + + if (isReadOnly()) { + d->error = AccessDeniedError; + d->errorString = tr("Could not add items to read only playlist."); + emit loadFailed(); + return; + } + + foreach (QString const& key, playlistIOLoader()->keys()) { + QMediaPlaylistIOInterface* plugin = qobject_cast(playlistIOLoader()->instance(key)); + if (plugin && plugin->canRead(device,format)) { + QMediaPlaylistReader *reader = plugin->createReader(device,QByteArray(format)); + if (reader && d->readItems(reader)) { + delete reader; + emit loaded(); + return; + } + delete reader; + } + } + + d->error = FormatNotSupportedError; + d->errorString = tr("Playlist format is not supported"); + emit loadFailed(); + + return; +} + +/*! + Save playlist to \a location. If \a format is specified, it is used, + otherwise format is guessed from location name. + + Returns true if playlist was saved succesfully, otherwise returns false. + */ +bool QMediaPlaylist::save(const QUrl &location, const char *format) +{ + Q_D(QMediaPlaylist); + + d->error = NoError; + d->errorString.clear(); + + if (d->playlist()->save(location,format)) + return true; + + QFile file(location.toLocalFile()); + + if (!file.open(QIODevice::WriteOnly | QIODevice::Truncate)) { + d->error = AccessDeniedError; + d->errorString = tr("The file could not be accessed."); + return false; + } + + return save(&file, format); +} + +/*! + Save playlist to QIODevice \a device using format \a format. + + Returns true if playlist was saved succesfully, otherwise returns false. +*/ +bool QMediaPlaylist::save(QIODevice * device, const char *format) +{ + Q_D(QMediaPlaylist); + + d->error = NoError; + d->errorString.clear(); + + if (d->playlist()->save(device,format)) + return true; + + foreach (QString const& key, playlistIOLoader()->keys()) { + QMediaPlaylistIOInterface* plugin = qobject_cast(playlistIOLoader()->instance(key)); + if (plugin && plugin->canWrite(device,format)) { + QMediaPlaylistWriter *writer = plugin->createWriter(device,QByteArray(format)); + if (writer && d->writeItems(writer)) { + delete writer; + return true; + } + delete writer; + } + } + + d->error = FormatNotSupportedError; + d->errorString = tr("Playlist format is not supported."); + + return false; +} + +/*! + Returns the last error condition. +*/ +QMediaPlaylist::Error QMediaPlaylist::error() const +{ + return d_func()->error; +} + +/*! + Returns the string describing the last error condition. +*/ +QString QMediaPlaylist::errorString() const +{ + return d_func()->errorString; +} + +/*! + Shuffle items in the playlist. +*/ +void QMediaPlaylist::shuffle() +{ + d_func()->playlist()->shuffle(); +} + + +/*! + Advance to the next media content in playlist. +*/ +void QMediaPlaylist::next() +{ + d_func()->control->next(); +} + +/*! + Return to the previous media content in playlist. +*/ +void QMediaPlaylist::previous() +{ + d_func()->control->previous(); +} + +/*! + Activate media content from playlist at position \a playlistPosition. +*/ + +void QMediaPlaylist::setCurrentIndex(int playlistPosition) +{ + d_func()->control->setCurrentIndex(playlistPosition); +} + +/*! + \fn void QMediaPlaylist::mediaInserted(int start, int end) + + This signal is emitted after media has been inserted into the playlist. + The new items are those between \a start and \a end inclusive. + */ + +/*! + \fn void QMediaPlaylist::mediaRemoved(int start, int end) + + This signal is emitted after media has been removed from the playlist. + The removed items are those between \a start and \a end inclusive. + */ + +/*! + \fn void QMediaPlaylist::mediaChanged(int start, int end) + + This signal is emitted after media has been changed in the playlist + between \a start and \a end positions inclusive. + */ + +/*! + \fn void QMediaPlaylist::currentIndexChanged(int position) + + Signal emitted when playlist position changed to \a position. +*/ + +/*! + \fn void QMediaPlaylist::playbackModeChanged(QMediaPlaylist::PlaybackMode mode) + + Signal emitted when playback mode changed to \a mode. +*/ + +/*! + \fn void QMediaPlaylist::mediaAboutToBeInserted(int start, int end) + + Signal emitted when item to be inserted at \a start and ending at \a end. +*/ + +/*! + \fn void QMediaPlaylist::mediaAboutToBeRemoved(int start, int end) + + Signal emitted when item to de deleted ar \a start and ending at \a end. +*/ + +/*! + \fn void QMediaPlaylist::currentMediaChanged(const QMediaContent &content) + + Signal emitted when current media changes to \a content. +*/ + +/*! + \property QMediaPlaylist::currentIndex + \brief Current position. +*/ + +/*! + \property QMediaPlaylist::currentMedia + \brief Current media content. +*/ + +/*! + \fn QMediaPlaylist::loaded() + + Signal emitted when playlist finished loading. +*/ + +/*! + \fn QMediaPlaylist::loadFailed() + + Signal emitted if failed to load playlist. +*/ + +/*! + \enum QMediaPlaylist::Error + + This enum describes the QMediaPlaylist error codes. + + \value NoError No errors. + \value FormatError Format error. + \value FormatNotSupportedError Format not supported. + \value NetworkError Network error. + \value AccessDeniedError Access denied error. +*/ + +QT_END_NAMESPACE + +#include "moc_qmediaplaylist.cpp" +#include "moc_qmediaplaylist_p.cpp" diff --git a/src/multimedia/mediaservices/base/qmediaplaylist.h b/src/multimedia/mediaservices/base/qmediaplaylist.h new file mode 100644 index 0000000..132b58c --- /dev/null +++ b/src/multimedia/mediaservices/base/qmediaplaylist.h @@ -0,0 +1,147 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtMediaservices module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QMEDIAPLAYLIST_H +#define QMEDIAPLAYLIST_H + +#include + +#include +#include + + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Multimedia) + +class QMediaPlaylistProvider; + +class QMediaPlaylistPrivate; +class Q_MULTIMEDIA_EXPORT QMediaPlaylist : public QObject +{ + Q_OBJECT + Q_PROPERTY(QMediaPlaylist::PlaybackMode playbackMode READ playbackMode WRITE setPlaybackMode NOTIFY playbackModeChanged) + Q_PROPERTY(QMediaContent currentMedia READ currentMedia NOTIFY currentMediaChanged) + Q_PROPERTY(int currentIndex READ currentIndex WRITE setCurrentIndex NOTIFY currentIndexChanged) + Q_ENUMS(PlaybackMode Error) + +public: + enum PlaybackMode { CurrentItemOnce, CurrentItemInLoop, Linear, Loop, Random }; + enum Error { NoError, FormatError, FormatNotSupportedError, NetworkError, AccessDeniedError }; + + QMediaPlaylist(QObject *parent = 0); + virtual ~QMediaPlaylist(); + + QMediaObject *mediaObject() const; + void setMediaObject(QMediaObject *object); + + PlaybackMode playbackMode() const; + void setPlaybackMode(PlaybackMode mode); + + int currentIndex() const; + QMediaContent currentMedia() const; + + int nextIndex(int steps = 1) const; + int previousIndex(int steps = 1) const; + + QMediaContent media(int index) const; + + int mediaCount() const; + bool isEmpty() const; + bool isReadOnly() const; + + bool addMedia(const QMediaContent &content); + bool addMedia(const QList &items); + bool insertMedia(int index, const QMediaContent &content); + bool insertMedia(int index, const QList &items); + bool removeMedia(int pos); + bool removeMedia(int start, int end); + bool clear(); + + void load(const QUrl &location, const char *format = 0); + void load(QIODevice * device, const char *format = 0); + + bool save(const QUrl &location, const char *format = 0); + bool save(QIODevice * device, const char *format); + + Error error() const; + QString errorString() const; + +public Q_SLOTS: + void shuffle(); + + void next(); + void previous(); + + void setCurrentIndex(int index); + +Q_SIGNALS: + void currentIndexChanged(int index); + void playbackModeChanged(QMediaPlaylist::PlaybackMode mode); + void currentMediaChanged(const QMediaContent&); + + void mediaAboutToBeInserted(int start, int end); + void mediaInserted(int start, int end); + void mediaAboutToBeRemoved(int start, int end); + void mediaRemoved(int start, int end); + void mediaChanged(int start, int end); + + void loaded(); + void loadFailed(); + +protected: + QMediaPlaylistPrivate *d_ptr; + +private: + Q_DECLARE_PRIVATE(QMediaPlaylist) + Q_PRIVATE_SLOT(d_func(), void _q_loadFailed(QMediaPlaylist::Error, const QString &)) +}; + +QT_END_NAMESPACE + +Q_DECLARE_METATYPE(QMediaPlaylist::PlaybackMode) +Q_DECLARE_METATYPE(QMediaPlaylist::Error) + +QT_END_HEADER + +#endif // QMEDIAPLAYLIST_H diff --git a/src/multimedia/mediaservices/base/qmediaplaylist_p.h b/src/multimedia/mediaservices/base/qmediaplaylist_p.h new file mode 100644 index 0000000..57c2723 --- /dev/null +++ b/src/multimedia/mediaservices/base/qmediaplaylist_p.h @@ -0,0 +1,172 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtMediaservices module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QMEDIAPLAYLIST_P_H +#define QMEDIAPLAYLIST_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include +#include +#include +#include +#include +#include "qmediaobject_p.h" + +#include + +#ifdef Q_MOC_RUN +# pragma Q_MOC_EXPAND_MACROS +#endif + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +class QMediaPlaylistControl; +class QMediaPlaylistProvider; +class QMediaPlaylistReader; +class QMediaPlaylistWriter; +class QMediaPlayerControl; + +class QMediaPlaylistPrivate +{ + Q_DECLARE_PUBLIC(QMediaPlaylist) +public: + QMediaPlaylistPrivate() + :mediaObject(0), + control(0), + localPlaylistControl(0), + error(QMediaPlaylist::NoError) + { + } + + virtual ~QMediaPlaylistPrivate() {} + + void _q_loadFailed(QMediaPlaylist::Error error, const QString &errorString) + { + this->error = error; + this->errorString = errorString; + + emit q_ptr->loadFailed(); + } + + void _q_mediaObjectDeleted() + { + Q_Q(QMediaPlaylist); + mediaObject = 0; + if (control != localPlaylistControl) + control = 0; + q->setMediaObject(0); + } + + QMediaObject *mediaObject; + + QMediaPlaylistControl *control; + QMediaPlaylistProvider *playlist() const { return control->playlistProvider(); } + + QMediaPlaylistControl *localPlaylistControl; + + bool readItems(QMediaPlaylistReader *reader); + bool writeItems(QMediaPlaylistWriter *writer); + + QMediaPlaylist::Error error; + QString errorString; + + QMediaPlaylist *q_ptr; +}; + + +class QLocalMediaPlaylistControl : public QMediaPlaylistControl +{ + Q_OBJECT +public: + QLocalMediaPlaylistControl(QObject *parent) + :QMediaPlaylistControl(parent) + { + QMediaPlaylistProvider *playlist = new QLocalMediaPlaylistProvider(this); + m_navigator = new QMediaPlaylistNavigator(playlist,this); + m_navigator->setPlaybackMode(QMediaPlaylist::Linear); + + connect(m_navigator, SIGNAL(currentIndexChanged(int)), SIGNAL(currentIndexChanged(int))); + connect(m_navigator, SIGNAL(activated(QMediaContent)), SIGNAL(currentMediaChanged(QMediaContent))); + } + + virtual ~QLocalMediaPlaylistControl() {}; + + QMediaPlaylistProvider* playlistProvider() const { return m_navigator->playlist(); } + bool setPlaylistProvider(QMediaPlaylistProvider *mediaPlaylist) + { + m_navigator->setPlaylist(mediaPlaylist); + emit playlistProviderChanged(); + return true; + } + + int currentIndex() const { return m_navigator->currentIndex(); } + void setCurrentIndex(int position) { m_navigator->jump(position); } + int nextIndex(int steps) const { return m_navigator->nextIndex(steps); } + int previousIndex(int steps) const { return m_navigator->previousIndex(steps); } + + void next() { m_navigator->next(); } + void previous() { m_navigator->previous(); } + + QMediaPlaylist::PlaybackMode playbackMode() const { return m_navigator->playbackMode(); } + void setPlaybackMode(QMediaPlaylist::PlaybackMode mode) { m_navigator->setPlaybackMode(mode); } + +private: + QMediaPlaylistNavigator *m_navigator; +}; + + +QT_END_NAMESPACE + +QT_END_HEADER + +#endif // QMEDIAPLAYLIST_P_H diff --git a/src/multimedia/mediaservices/base/qmediaplaylistcontrol.cpp b/src/multimedia/mediaservices/base/qmediaplaylistcontrol.cpp new file mode 100644 index 0000000..6f3b2fe --- /dev/null +++ b/src/multimedia/mediaservices/base/qmediaplaylistcontrol.cpp @@ -0,0 +1,204 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtMediaservices module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + + +#include +#include "qmediacontrol_p.h" + + +QT_BEGIN_NAMESPACE + +/*! + \class QMediaPlaylistControl + \ingroup multimedia-serv + \since 4.7 + + \preliminary + \brief The QMediaPlaylistControl class provides access to the playlist functionality of a + QMediaService. + + If a QMediaService contains an internal playlist it will implement QMediaPlaylistControl. This + control provides access to the contents of the \l {playlistProvider()}{playlist}, as well as the + \l {currentIndex()}{position} of the current media, and a means of navigating to the + \l {next()}{next} and \l {previous()}{previous} media. + + The functionality provided by the control is exposed to application code through the + QMediaPlaylist class. + + The interface name of QMediaPlaylistControl is \c com.nokia.Qt.QMediaPlaylistControl/1.0 as + defined in QMediaPlaylistControl_iid. + + \sa QMediaService::control(), QMediaPlayer +*/ + +/*! + \macro QMediaPlaylistControl_iid + + \c com.nokia.Qt.QMediaPlaylistControl/1.0 + + Defines the interface name of the QMediaPlaylistControl class. + + \relates QMediaPlaylistControl +*/ + +/*! + Create a new playlist control object with the given \a parent. +*/ +QMediaPlaylistControl::QMediaPlaylistControl(QObject *parent): + QMediaControl(*new QMediaControlPrivate, parent) +{ +} + +/*! + Destroys the playlist control. +*/ +QMediaPlaylistControl::~QMediaPlaylistControl() +{ +} + + +/*! + \fn QMediaPlaylistControl::playlistProvider() const + + Returns the playlist used by this media player. +*/ + +/*! + \fn QMediaPlaylistControl::setPlaylistProvider(QMediaPlaylistProvider *playlist) + + Set the playlist of this media player to \a playlist. + + In many cases it is possible just to use the playlist + constructed by player, but sometimes replacing the whole + playlist allows to avoid copyting of all the items bettween playlists. + + Returns true if player can use this passed playlist; otherwise returns false. + +*/ + +/*! + \fn QMediaPlaylistControl::currentIndex() const + + Returns position of the current media source in the playlist. +*/ + +/*! + \fn QMediaPlaylistControl::setCurrentIndex(int position) + + Jump to the item at the given \a position. +*/ + +/*! + \fn QMediaPlaylistControl::nextIndex(int step) const + + Returns the index of item, which were current after calling next() + \a step times. + + Returned value depends on the size of playlist, current position + and playback mode. + + \sa QMediaPlaylist::playbackMode +*/ + +/*! + \fn QMediaPlaylistControl::previousIndex(int step) const + + Returns the index of item, which were current after calling previous() + \a step times. + + \sa QMediaPlaylist::playbackMode +*/ + +/*! + \fn QMediaPlaylistControl::next() + + Moves to the next item in playlist. +*/ + +/*! + \fn QMediaPlaylistControl::previous() + + Returns to the previous item in playlist. +*/ + +/*! + \fn QMediaPlaylistControl::playbackMode() const + + Returns the playlist navigation mode. + + \sa QMediaPlaylist::PlaybackMode +*/ + +/*! + \fn QMediaPlaylistControl::setPlaybackMode(QMediaPlaylist::PlaybackMode mode) + + Sets the playback \a mode. + + \sa QMediaPlaylist::PlaybackMode +*/ + +/*! + \fn QMediaPlaylistControl::playlistProviderChanged() + + Signal emited when the playlist provider has changed. +*/ + +/*! + \fn QMediaPlaylistControl::currentIndexChanged(int position) + + Signal emited when the playlist \a position is changed. +*/ + +/*! + \fn QMediaPlaylistControl::playbackModeChanged(QMediaPlaylist::PlaybackMode mode) + + Signal emited when the playback \a mode is changed. +*/ + +/*! + \fn QMediaPlaylistControl::currentMediaChanged(const QMediaContent& content) + + Signal emitted when current media changes to \a content. +*/ + +#include "moc_qmediaplaylistcontrol.cpp" +QT_END_NAMESPACE + diff --git a/src/multimedia/mediaservices/base/qmediaplaylistcontrol.h b/src/multimedia/mediaservices/base/qmediaplaylistcontrol.h new file mode 100644 index 0000000..cf489e3 --- /dev/null +++ b/src/multimedia/mediaservices/base/qmediaplaylistcontrol.h @@ -0,0 +1,97 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtMediaservices module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + + +#ifndef QMEDIAPLAYLISTCONTROL_H +#define QMEDIAPLAYLISTCONTROL_H + +#include +#include + + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Multimedia) + + +class QMediaPlaylistProvider; + +class Q_MULTIMEDIA_EXPORT QMediaPlaylistControl : public QMediaControl +{ + Q_OBJECT + +public: + virtual ~QMediaPlaylistControl(); + + virtual QMediaPlaylistProvider* playlistProvider() const = 0; + virtual bool setPlaylistProvider(QMediaPlaylistProvider *playlist) = 0; + + virtual int currentIndex() const = 0; + virtual void setCurrentIndex(int position) = 0; + virtual int nextIndex(int steps) const = 0; + virtual int previousIndex(int steps) const = 0; + + virtual void next() = 0; + virtual void previous() = 0; + + virtual QMediaPlaylist::PlaybackMode playbackMode() const = 0; + virtual void setPlaybackMode(QMediaPlaylist::PlaybackMode mode) = 0; + +Q_SIGNALS: + void playlistProviderChanged(); + void currentIndexChanged(int position); + void currentMediaChanged(const QMediaContent&); + void playbackModeChanged(QMediaPlaylist::PlaybackMode mode); + +protected: + QMediaPlaylistControl(QObject* parent = 0); +}; + +#define QMediaPlaylistControl_iid "com.nokia.Qt.QMediaPlaylistControl/1.0" +Q_MEDIA_DECLARE_CONTROL(QMediaPlaylistControl, QMediaPlaylistControl_iid) + +QT_END_NAMESPACE + +QT_END_HEADER + +#endif // QMEDIAPLAYLISTCONTROL_H diff --git a/src/multimedia/mediaservices/base/qmediaplaylistioplugin.cpp b/src/multimedia/mediaservices/base/qmediaplaylistioplugin.cpp new file mode 100644 index 0000000..ba5dc81 --- /dev/null +++ b/src/multimedia/mediaservices/base/qmediaplaylistioplugin.cpp @@ -0,0 +1,192 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtMediaservices module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include + +QT_BEGIN_NAMESPACE + +/*! + \class QMediaPlaylistReader + \preliminary + \since 4.7 + \brief The QMediaPlaylistReader class provides an interface for reading a playlist file. + + \sa QMediaPlaylistIOPlugin +*/ + +/*! + Destroys a media playlist reader. +*/ +QMediaPlaylistReader::~QMediaPlaylistReader() +{ +} + +/*! + \fn QMediaPlaylistReader::atEnd() const + + Identifies if a playlist reader has reached the end of its input. + + Returns true if the reader has reached the end; and false otherwise. +*/ + +/*! + \fn QMediaPlaylistReader::readItem() + + Reads an item of media from a playlist file. + + Returns the read media, or a null QMediaContent if no more media is available. +*/ + +/*! + \fn QMediaPlaylistReader::close() + + Closes a playlist reader's input device. +*/ + +/*! + \class QMediaPlaylistWriter + \preliminary + \since 4.7 + \brief The QMediaPlaylistWriter class provides an interface for writing a playlist file. + + \sa QMediaPlaylistIOPlugin +*/ + +/*! + Destroys a media playlist writer. +*/ +QMediaPlaylistWriter::~QMediaPlaylistWriter() +{ +} + +/*! + \fn QMediaPlaylistWriter::writeItem(const QMediaContent &media) + + Writes an item of \a media to a playlist file. + + Returns true if the media was written succesfully; and false otherwise. +*/ + +/*! + \fn QMediaPlaylistWriter::close() + + Finalizes the writing of a playlist and closes the output device. +*/ + +/*! + \class QMediaPlaylistIOPlugin + \since 4.7 + \brief The QMediaPlaylistIOPlugin class provides an interface for media playlist I/O plug-ins. +*/ + +/*! + Constructs a media playlist I/O plug-in with the given \a parent. +*/ +QMediaPlaylistIOPlugin::QMediaPlaylistIOPlugin(QObject *parent) + :QObject(parent) +{ +} + +/*! + Destroys a media playlist I/O plug-in. +*/ +QMediaPlaylistIOPlugin::~QMediaPlaylistIOPlugin() +{ +} + +/*! + \fn QMediaPlaylistIOPlugin::canRead(QIODevice *device, const QByteArray &format) const + + Identifies if plug-in can read \a format data from an I/O \a device. + + Returns true if the data can be read; and false otherwise. +*/ + +/*! + \fn QMediaPlaylistIOPlugin::canRead(const QUrl& location, const QByteArray &format) const + + Identifies if a plug-in can read \a format data from a URL \a location. + + Returns true if the data can be read; and false otherwise. +*/ + +/*! + \fn QMediaPlaylistIOPlugin::canWrite(QIODevice *device, const QByteArray &format) const + + Identifies if a plug-in can write \a format data to an I/O \a device. + + Returns true if the data can be written; and false otherwise. +*/ + +/*! + \fn QMediaPlaylistIOPlugin::keys() const + + Returns a list of format keys supported by a plug-in. +*/ + +/*! + \fn QMediaPlaylistIOPlugin::createReader(QIODevice *device, const QByteArray &format) + + Returns a new QMediaPlaylistReader which reads \a format data from an I/O \a device. + + If the device is invalid or the format is unsupported this will return a null pointer. +*/ + +/*! + \fn QMediaPlaylistIOPlugin::createReader(const QUrl& location, const QByteArray &format) + + Returns a new QMediaPlaylistReader which reads \a format data from a URL \a location. + + If the location or the format is unsupported this will return a null pointer. +*/ + +/*! + \fn QMediaPlaylistIOPlugin::createWriter(QIODevice *device, const QByteArray &format) + + Returns a new QMediaPlaylistWriter which writes \a format data to an I/O \a device. + + If the device is invalid or the format is unsupported this will return a null pointer. +*/ + +QT_END_NAMESPACE + +#include "moc_qmediaplaylistioplugin.cpp" + diff --git a/src/multimedia/mediaservices/base/qmediaplaylistioplugin.h b/src/multimedia/mediaservices/base/qmediaplaylistioplugin.h new file mode 100644 index 0000000..6bc0418 --- /dev/null +++ b/src/multimedia/mediaservices/base/qmediaplaylistioplugin.h @@ -0,0 +1,126 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtMediaservices module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QMEDIAPLAYLISTIOPLUGIN_H +#define QMEDIAPLAYLISTIOPLUGIN_H + +#include +#include +#include + +#include + + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Multimedia) + + +class QString; +class QUrl; +class QByteArray; +class QIODevice; +class QStringList; + +class Q_MULTIMEDIA_EXPORT QMediaPlaylistReader +{ +public: + virtual ~QMediaPlaylistReader(); + + virtual bool atEnd() const = 0; + virtual QMediaContent readItem() = 0; + virtual void close() = 0; +}; + +class Q_MULTIMEDIA_EXPORT QMediaPlaylistWriter +{ +public: + virtual ~QMediaPlaylistWriter(); + + virtual bool writeItem(const QMediaContent &content) = 0; + virtual void close() = 0; +}; + +struct Q_MULTIMEDIA_EXPORT QMediaPlaylistIOInterface : public QFactoryInterface +{ + virtual bool canRead(QIODevice *device, const QByteArray &format = QByteArray() ) const = 0; + virtual bool canRead(const QUrl& location, const QByteArray &format = QByteArray()) const = 0; + + virtual bool canWrite(QIODevice *device, const QByteArray &format) const = 0; + + virtual QMediaPlaylistReader *createReader(QIODevice *device, const QByteArray &format = QByteArray()) = 0; + virtual QMediaPlaylistReader *createReader(const QUrl& location, const QByteArray &format = QByteArray()) = 0; + + virtual QMediaPlaylistWriter *createWriter(QIODevice *device, const QByteArray &format) = 0; +}; + +#define QMediaPlaylistIOInterface_iid "com.nokia.Qt.QMediaPlaylistIOInterface" +Q_DECLARE_INTERFACE(QMediaPlaylistIOInterface, QMediaPlaylistIOInterface_iid); + +class Q_MULTIMEDIA_EXPORT QMediaPlaylistIOPlugin : public QObject, public QMediaPlaylistIOInterface +{ + Q_OBJECT + Q_INTERFACES(QMediaPlaylistIOInterface:QFactoryInterface) + +public: + explicit QMediaPlaylistIOPlugin(QObject *parent = 0); + virtual ~QMediaPlaylistIOPlugin(); + + virtual bool canRead(QIODevice *device, const QByteArray &format = QByteArray() ) const = 0; + virtual bool canRead(const QUrl& location, const QByteArray &format = QByteArray()) const = 0; + + virtual bool canWrite(QIODevice *device, const QByteArray &format) const = 0; + + virtual QStringList keys() const = 0; + + virtual QMediaPlaylistReader *createReader(QIODevice *device, const QByteArray &format = QByteArray()) = 0; + virtual QMediaPlaylistReader *createReader(const QUrl& location, const QByteArray &format = QByteArray()) = 0; + + virtual QMediaPlaylistWriter *createWriter(QIODevice *device, const QByteArray &format) = 0; +}; + +QT_END_NAMESPACE + +QT_END_HEADER + +#endif // QMEDIAPLAYLISTIOPLUGIN_H diff --git a/src/multimedia/mediaservices/base/qmediaplaylistnavigator.cpp b/src/multimedia/mediaservices/base/qmediaplaylistnavigator.cpp new file mode 100644 index 0000000..134ae77 --- /dev/null +++ b/src/multimedia/mediaservices/base/qmediaplaylistnavigator.cpp @@ -0,0 +1,545 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtMediaservices module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include +#include +#include "qmediaobject_p.h" + +#include + +QT_BEGIN_NAMESPACE + +class QMediaPlaylistNullProvider : public QMediaPlaylistProvider +{ +public: + QMediaPlaylistNullProvider() :QMediaPlaylistProvider() {} + virtual ~QMediaPlaylistNullProvider() {} + virtual int mediaCount() const {return 0;} + virtual QMediaContent media(int) const { return QMediaContent(); } +}; + +Q_GLOBAL_STATIC(QMediaPlaylistNullProvider, _q_nullMediaPlaylist) + +class QMediaPlaylistNavigatorPrivate +{ + Q_DECLARE_NON_CONST_PUBLIC(QMediaPlaylistNavigator) +public: + QMediaPlaylistNavigatorPrivate() + :playlist(0), + currentPos(-1), + lastValidPos(-1), + playbackMode(QMediaPlaylist::Linear), + randomPositionsOffset(-1) + { + } + + QMediaPlaylistProvider *playlist; + int currentPos; + int lastValidPos; //to be used with CurrentItemOnce playback mode + QMediaPlaylist::PlaybackMode playbackMode; + QMediaContent currentItem; + + mutable QList randomModePositions; + mutable int randomPositionsOffset; + + int nextItemPos(int steps = 1) const; + int previousItemPos(int steps = 1) const; + + void _q_mediaInserted(int start, int end); + void _q_mediaRemoved(int start, int end); + void _q_mediaChanged(int start, int end); + + QMediaPlaylistNavigator *q_ptr; +}; + + +int QMediaPlaylistNavigatorPrivate::nextItemPos(int steps) const +{ + if (playlist->mediaCount() == 0) + return -1; + + if (steps == 0) + return currentPos; + + switch (playbackMode) { + case QMediaPlaylist::CurrentItemOnce: + return /*currentPos == -1 ? lastValidPos :*/ -1; + case QMediaPlaylist::CurrentItemInLoop: + return currentPos; + case QMediaPlaylist::Linear: + { + int nextPos = currentPos+steps; + return nextPos < playlist->mediaCount() ? nextPos : -1; + } + case QMediaPlaylist::Loop: + return (currentPos+steps) % playlist->mediaCount(); + case QMediaPlaylist::Random: + { + //TODO: limit the history size + + if (randomPositionsOffset == -1) { + randomModePositions.clear(); + randomModePositions.append(currentPos); + randomPositionsOffset = 0; + } + + while (randomModePositions.size() < randomPositionsOffset+steps+1) + randomModePositions.append(-1); + int res = randomModePositions[randomPositionsOffset+steps]; + if (res<0 || res >= playlist->mediaCount()) { + res = qrand() % playlist->mediaCount(); + randomModePositions[randomPositionsOffset+steps] = res; + } + + return res; + } + } + + return -1; +} + +int QMediaPlaylistNavigatorPrivate::previousItemPos(int steps) const +{ + if (playlist->mediaCount() == 0) + return -1; + + if (steps == 0) + return currentPos; + + switch (playbackMode) { + case QMediaPlaylist::CurrentItemOnce: + return /*currentPos == -1 ? lastValidPos :*/ -1; + case QMediaPlaylist::CurrentItemInLoop: + return currentPos; + case QMediaPlaylist::Linear: + { + int prevPos = currentPos == -1 ? playlist->mediaCount() - steps : currentPos - steps; + return prevPos>=0 ? prevPos : -1; + } + case QMediaPlaylist::Loop: + { + int prevPos = currentPos - steps; + while (prevPos<0) + prevPos += playlist->mediaCount(); + return prevPos; + } + case QMediaPlaylist::Random: + { + //TODO: limit the history size + + if (randomPositionsOffset == -1) { + randomModePositions.clear(); + randomModePositions.append(currentPos); + randomPositionsOffset = 0; + } + + while (randomPositionsOffset-steps < 0) { + randomModePositions.prepend(-1); + randomPositionsOffset++; + } + + int res = randomModePositions[randomPositionsOffset-steps]; + if (res<0 || res >= playlist->mediaCount()) { + res = qrand() % playlist->mediaCount(); + randomModePositions[randomPositionsOffset-steps] = res; + } + + return res; + } + } + + return -1; +} + +/*! + \class QMediaPlaylistNavigator + \preliminary + \since 4.7 + \brief The QMediaPlaylistNavigator class provides navigation for a media playlist. + + \sa QMediaPlaylist, QMediaPlaylistProvider +*/ + + +/*! + Constructs a media playlist navigator for a \a playlist. + + The \a parent is passed to QObject. + */ +QMediaPlaylistNavigator::QMediaPlaylistNavigator(QMediaPlaylistProvider *playlist, QObject *parent) + : QObject(parent) + , d_ptr(new QMediaPlaylistNavigatorPrivate) +{ + d_ptr->q_ptr = this; + + setPlaylist(playlist ? playlist : _q_nullMediaPlaylist()); +} + +/*! + Destroys a media playlist navigator. + */ + +QMediaPlaylistNavigator::~QMediaPlaylistNavigator() +{ + delete d_ptr; +} + + +/*! \property QMediaPlaylistNavigator::playbackMode + Contains the playback mode. + */ +QMediaPlaylist::PlaybackMode QMediaPlaylistNavigator::playbackMode() const +{ + return d_func()->playbackMode; +} + +/*! + Sets the playback \a mode. + */ +void QMediaPlaylistNavigator::setPlaybackMode(QMediaPlaylist::PlaybackMode mode) +{ + Q_D(QMediaPlaylistNavigator); + if (d->playbackMode == mode) + return; + + if (mode == QMediaPlaylist::Random) { + d->randomPositionsOffset = 0; + d->randomModePositions.append(d->currentPos); + } else if (d->playbackMode == QMediaPlaylist::Random) { + d->randomPositionsOffset = -1; + d->randomModePositions.clear(); + } + + d->playbackMode = mode; + + emit playbackModeChanged(mode); + emit surroundingItemsChanged(); +} + +/*! + Returns the playlist being navigated. +*/ + +QMediaPlaylistProvider *QMediaPlaylistNavigator::playlist() const +{ + return d_func()->playlist; +} + +/*! + Sets the \a playlist to navigate. +*/ +void QMediaPlaylistNavigator::setPlaylist(QMediaPlaylistProvider *playlist) +{ + Q_D(QMediaPlaylistNavigator); + + if (d->playlist == playlist) + return; + + if (d->playlist) { + d->playlist->disconnect(this); + } + + if (playlist) { + d->playlist = playlist; + } else { + //assign to shared readonly null playlist + d->playlist = _q_nullMediaPlaylist(); + } + + connect(d->playlist, SIGNAL(mediaInserted(int,int)), SLOT(_q_mediaInserted(int,int))); + connect(d->playlist, SIGNAL(mediaRemoved(int,int)), SLOT(_q_mediaRemoved(int,int))); + connect(d->playlist, SIGNAL(mediaChanged(int,int)), SLOT(_q_mediaChanged(int,int))); + + d->randomPositionsOffset = -1; + d->randomModePositions.clear(); + + if (d->currentPos != -1) { + d->currentPos = -1; + emit currentIndexChanged(-1); + } + + if (!d->currentItem.isNull()) { + d->currentItem = QMediaContent(); + emit activated(d->currentItem); //stop playback + } +} + +/*! \property QMediaPlaylistNavigator::currentItem + + Contains the media at the current position in the playlist. + + \sa currentIndex() +*/ + +QMediaContent QMediaPlaylistNavigator::currentItem() const +{ + return itemAt(d_func()->currentPos); +} + +/*! \fn QMediaContent QMediaPlaylistNavigator::nextItem(int steps) const + + Returns the media that is \a steps positions ahead of the current + position in the playlist. + + \sa nextIndex() +*/ +QMediaContent QMediaPlaylistNavigator::nextItem(int steps) const +{ + return itemAt(nextIndex(steps)); +} + +/*! + Returns the media that is \a steps positions behind the current + position in the playlist. + + \sa previousIndex() + */ +QMediaContent QMediaPlaylistNavigator::previousItem(int steps) const +{ + return itemAt(previousIndex(steps)); +} + +/*! + Returns the media at a \a position in the playlist. + */ +QMediaContent QMediaPlaylistNavigator::itemAt(int position) const +{ + return d_func()->playlist->media(position); +} + +/*! \property QMediaPlaylistNavigator::currentIndex + + Contains the position of the current media. + + If no media is current, the property contains -1. + + \sa nextIndex(), previousIndex() +*/ + +int QMediaPlaylistNavigator::currentIndex() const +{ + return d_func()->currentPos; +} + +/*! + Returns a position \a steps ahead of the current position + accounting for the playbackMode(). + + If the position is beyond the end of the playlist, this value + returned is -1. + + \sa currentIndex(), previousIndex(), playbackMode() +*/ + +int QMediaPlaylistNavigator::nextIndex(int steps) const +{ + return d_func()->nextItemPos(steps); +} + +/*! + + Returns a position \a steps behind the current position accounting + for the playbackMode(). + + If the position is prior to the beginning of the playlist this will + return -1. + + \sa currentIndex(), nextIndex(), playbackMode() +*/ +int QMediaPlaylistNavigator::previousIndex(int steps) const +{ + return d_func()->previousItemPos(steps); +} + +/*! + Advances to the next item in the playlist. + + \sa previous(), jump(), playbackMode() + */ +void QMediaPlaylistNavigator::next() +{ + Q_D(QMediaPlaylistNavigator); + + int nextPos = d->nextItemPos(); + + if ( playbackMode() == QMediaPlaylist::Random ) + d->randomPositionsOffset++; + + jump(nextPos); +} + +/*! + Returns to the previous item in the playlist, + + \sa next(), jump(), playbackMode() + */ +void QMediaPlaylistNavigator::previous() +{ + Q_D(QMediaPlaylistNavigator); + + int prevPos = d->previousItemPos(); + if ( playbackMode() == QMediaPlaylist::Random ) + d->randomPositionsOffset--; + + jump(prevPos); +} + +/*! + Jumps to a new \a position in the playlist. + */ +void QMediaPlaylistNavigator::jump(int position) +{ + Q_D(QMediaPlaylistNavigator); + + if (position<-1 || position>=d->playlist->mediaCount()) { + qWarning() << "QMediaPlaylistNavigator: Jump outside playlist range"; + position = -1; + } + + if (position != -1) + d->lastValidPos = position; + + if (playbackMode() == QMediaPlaylist::Random) { + if (d->randomModePositions[d->randomPositionsOffset] != position) { + d->randomModePositions.clear(); + d->randomModePositions.append(position); + d->randomPositionsOffset = 0; + } + } + + if (position != -1) + d->currentItem = d->playlist->media(position); + else + d->currentItem = QMediaContent(); + + if (position != d->currentPos) { + d->currentPos = position; + emit currentIndexChanged(d->currentPos); + emit surroundingItemsChanged(); + } + + emit activated(d->currentItem); +} + +/*! + \internal +*/ +void QMediaPlaylistNavigatorPrivate::_q_mediaInserted(int start, int end) +{ + Q_Q(QMediaPlaylistNavigator); + + if (currentPos >= start) { + currentPos = end-start+1; + q->jump(currentPos); + } + + //TODO: check if they really changed + emit q->surroundingItemsChanged(); +} + +/*! + \internal +*/ +void QMediaPlaylistNavigatorPrivate::_q_mediaRemoved(int start, int end) +{ + Q_Q(QMediaPlaylistNavigator); + + if (currentPos > end) { + currentPos = currentPos - end-start+1; + q->jump(currentPos); + } else if (currentPos >= start) { + //current item was removed + currentPos = qMin(start, playlist->mediaCount()-1); + q->jump(currentPos); + } + + //TODO: check if they really changed + emit q->surroundingItemsChanged(); +} + +/*! + \internal +*/ +void QMediaPlaylistNavigatorPrivate::_q_mediaChanged(int start, int end) +{ + Q_Q(QMediaPlaylistNavigator); + + if (currentPos >= start && currentPos<=end) { + QMediaContent src = playlist->media(currentPos); + if (src != currentItem) { + currentItem = src; + emit q->activated(src); + } + } + + //TODO: check if they really changed + emit q->surroundingItemsChanged(); +} + +/*! + \fn QMediaPlaylistNavigator::activated(const QMediaContent &media) + + Signals that the current \a media has changed. +*/ + +/*! + \fn QMediaPlaylistNavigator::currentIndexChanged(int position) + + Signals the \a position of the current media has changed. +*/ + +/*! + \fn QMediaPlaylistNavigator::playbackModeChanged(QMediaPlaylist::PlaybackMode mode) + + Signals that the playback \a mode has changed. +*/ + +/*! + \fn QMediaPlaylistNavigator::surroundingItemsChanged() + + Signals that media immediately surrounding the current position has changed. +*/ + +#include "moc_qmediaplaylistnavigator.cpp" + +QT_END_NAMESPACE + diff --git a/src/multimedia/mediaservices/base/qmediaplaylistnavigator.h b/src/multimedia/mediaservices/base/qmediaplaylistnavigator.h new file mode 100644 index 0000000..b6d3d96 --- /dev/null +++ b/src/multimedia/mediaservices/base/qmediaplaylistnavigator.h @@ -0,0 +1,116 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtMediaservices module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QMEDIAPLAYLISTNAVIGATOR_H +#define QMEDIAPLAYLISTNAVIGATOR_H + +#include + +#include +#include + + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Multimedia) + + +class QMediaPlaylistNavigatorPrivate; +class Q_MULTIMEDIA_EXPORT QMediaPlaylistNavigator : public QObject +{ + Q_OBJECT + Q_PROPERTY(QMediaPlaylist::PlaybackMode playbackMode READ playbackMode WRITE setPlaybackMode NOTIFY playbackModeChanged) + Q_PROPERTY(int currentIndex READ currentIndex WRITE jump NOTIFY currentIndexChanged) + Q_PROPERTY(QMediaContent currentItem READ currentItem NOTIFY currentItemChanged) + +public: + QMediaPlaylistNavigator(QMediaPlaylistProvider *playlist, QObject *parent = 0); + virtual ~QMediaPlaylistNavigator(); + + QMediaPlaylistProvider *playlist() const; + void setPlaylist(QMediaPlaylistProvider *playlist); + + QMediaPlaylist::PlaybackMode playbackMode() const; + + QMediaContent currentItem() const; + QMediaContent nextItem(int steps = 1) const; + QMediaContent previousItem(int steps = 1) const; + + QMediaContent itemAt(int position) const; + + int currentIndex() const; + int nextIndex(int steps = 1) const; + int previousIndex(int steps = 1) const; + +public Q_SLOTS: + void next(); + void previous(); + + void jump(int); + + void setPlaybackMode(QMediaPlaylist::PlaybackMode mode); + +Q_SIGNALS: + void activated(const QMediaContent &content); + void currentIndexChanged(int); + void playbackModeChanged(QMediaPlaylist::PlaybackMode mode); + + void surroundingItemsChanged(); + +protected: + QMediaPlaylistNavigatorPrivate *d_ptr; + +private: + Q_DISABLE_COPY(QMediaPlaylistNavigator) + Q_DECLARE_PRIVATE(QMediaPlaylistNavigator) + + Q_PRIVATE_SLOT(d_func(), void _q_mediaInserted(int start, int end)) + Q_PRIVATE_SLOT(d_func(), void _q_mediaRemoved(int start, int end)) + Q_PRIVATE_SLOT(d_func(), void _q_mediaChanged(int start, int end)) +}; + +QT_END_NAMESPACE + +QT_END_HEADER + +#endif // QMEDIAPLAYLISTNAVIGATOR_H diff --git a/src/multimedia/mediaservices/base/qmediaplaylistprovider.cpp b/src/multimedia/mediaservices/base/qmediaplaylistprovider.cpp new file mode 100644 index 0000000..c546899 --- /dev/null +++ b/src/multimedia/mediaservices/base/qmediaplaylistprovider.cpp @@ -0,0 +1,308 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtMediaservices module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include + +#include +#include "qmediaplaylistprovider_p.h" + + +QT_BEGIN_NAMESPACE + +/*! + \class QMediaPlaylistProvider + \preliminary + \since 4.7 + \brief The QMediaPlaylistProvider class provides an abstract list of media. + + \sa QMediaPlaylist +*/ + +/*! + Constructs a playlist provider with the given \a parent. +*/ +QMediaPlaylistProvider::QMediaPlaylistProvider(QObject *parent) + :QObject(parent), d_ptr(new QMediaPlaylistProviderPrivate) +{ +} + +/*! + \internal +*/ +QMediaPlaylistProvider::QMediaPlaylistProvider(QMediaPlaylistProviderPrivate &dd, QObject *parent) + :QObject(parent), d_ptr(&dd) +{ +} + +/*! + Destroys a playlist provider. +*/ +QMediaPlaylistProvider::~QMediaPlaylistProvider() +{ + delete d_ptr; +} + +/*! + \fn QMediaPlaylistProvider::mediaCount() const; + + Returns the size of playlist. +*/ + +/*! + \fn QMediaPlaylistProvider::media(int index) const; + + Returns the media at \a index in the playlist. + + If the index is invalid this will return a null media content. +*/ + + +/*! + Loads a playlist from from a URL \a location. If no playlist \a format is specified the loader + will inspect the URL or probe the headers to guess the format. + + New items are appended to playlist. + + Returns true if the provider supports the format and loading from the locations URL protocol, + otherwise this will return false. +*/ +bool QMediaPlaylistProvider::load(const QUrl &location, const char *format) +{ + Q_UNUSED(location); + Q_UNUSED(format); + return false; +} + +/*! + Loads a playlist from from an I/O \a device. If no playlist \a format is specified the loader + will probe the headers to guess the format. + + New items are appended to playlist. + + Returns true if the provider supports the format and loading from an I/O device, otherwise this + will return false. +*/ +bool QMediaPlaylistProvider::load(QIODevice * device, const char *format) +{ + Q_UNUSED(device); + Q_UNUSED(format); + return false; +} + +/*! + Saves the contents of a playlist to a URL \a location. If no playlist \a format is specified + the writer will inspect the URL to guess the format. + + Returns true if the playlist was saved succesfully; and false otherwise. + */ +bool QMediaPlaylistProvider::save(const QUrl &location, const char *format) +{ + Q_UNUSED(location); + Q_UNUSED(format); + return false; +} + +/*! + Saves the contents of a playlist to an I/O \a device in the specified \a format. + + Returns true if the playlist was saved succesfully; and false otherwise. +*/ +bool QMediaPlaylistProvider::save(QIODevice * device, const char *format) +{ + Q_UNUSED(device); + Q_UNUSED(format); + return false; +} + +/*! + Returns true if a playlist is read-only; otherwise returns false. +*/ +bool QMediaPlaylistProvider::isReadOnly() const +{ + return true; +} + +/*! + Append \a media to a playlist. + + Returns true if the media was appended; and false otherwise. +*/ +bool QMediaPlaylistProvider::addMedia(const QMediaContent &media) +{ + Q_UNUSED(media); + return false; +} + +/*! + Append multiple media \a items to a playlist. + + Returns true if the media items were appended; and false otherwise. +*/ +bool QMediaPlaylistProvider::addMedia(const QList &items) +{ + foreach(const QMediaContent &item, items) { + if (!addMedia(item)) + return false; + } + + return true; +} + +/*! + Inserts \a media into a playlist at \a position. + + Returns true if the media was inserted; and false otherwise. +*/ +bool QMediaPlaylistProvider::insertMedia(int position, const QMediaContent &media) +{ + Q_UNUSED(position); + Q_UNUSED(media); + return false; +} + +/*! + Inserts multiple media \a items into a playlist at \a position. + + Returns true if the media \a items were inserted; and false otherwise. +*/ +bool QMediaPlaylistProvider::insertMedia(int position, const QList &items) +{ + for (int i=0; i + +#include +#include + + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Multimedia) + +class QString; + + +class QMediaPlaylistProviderPrivate; +class Q_MULTIMEDIA_EXPORT QMediaPlaylistProvider : public QObject +{ + Q_OBJECT + +public: + QMediaPlaylistProvider(QObject *parent=0); + virtual ~QMediaPlaylistProvider(); + + virtual bool load(const QUrl &location, const char *format = 0); + virtual bool load(QIODevice * device, const char *format = 0); + virtual bool save(const QUrl &location, const char *format = 0); + virtual bool save(QIODevice * device, const char *format); + + virtual int mediaCount() const = 0; + virtual QMediaContent media(int index) const = 0; + + virtual bool isReadOnly() const; + + virtual bool addMedia(const QMediaContent &content); + virtual bool addMedia(const QList &contentList); + virtual bool insertMedia(int index, const QMediaContent &content); + virtual bool insertMedia(int index, const QList &content); + virtual bool removeMedia(int pos); + virtual bool removeMedia(int start, int end); + virtual bool clear(); + +public Q_SLOTS: + virtual void shuffle(); + +Q_SIGNALS: + void mediaAboutToBeInserted(int start, int end); + void mediaInserted(int start, int end); + + void mediaAboutToBeRemoved(int start, int end); + void mediaRemoved(int start, int end); + + void mediaChanged(int start, int end); + + void loaded(); + void loadFailed(QMediaPlaylist::Error, const QString& errorMessage); + +protected: + QMediaPlaylistProviderPrivate *d_ptr; + QMediaPlaylistProvider(QMediaPlaylistProviderPrivate &dd, QObject *parent); + +private: + Q_DECLARE_PRIVATE(QMediaPlaylistProvider) +}; + +QT_END_NAMESPACE + +QT_END_HEADER + +#endif // QMEDIAPLAYLISTPROVIDER_H diff --git a/src/multimedia/mediaservices/base/qmediaplaylistprovider_p.h b/src/multimedia/mediaservices/base/qmediaplaylistprovider_p.h new file mode 100644 index 0000000..03f72ac --- /dev/null +++ b/src/multimedia/mediaservices/base/qmediaplaylistprovider_p.h @@ -0,0 +1,75 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtMediaservices module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QMEDIAPLAYLISTPROVIDER_P_H +#define QMEDIAPLAYLISTPROVIDER_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +class QMediaPlaylistProviderPrivate +{ +public: + QMediaPlaylistProviderPrivate() + {} + virtual ~QMediaPlaylistProviderPrivate() + {} +}; + +QT_END_NAMESPACE + +QT_END_HEADER + +#endif // QMEDIAPLAYLISTSOURCE_P_H diff --git a/src/multimedia/mediaservices/base/qmediapluginloader.cpp b/src/multimedia/mediaservices/base/qmediapluginloader.cpp new file mode 100644 index 0000000..a1975ab --- /dev/null +++ b/src/multimedia/mediaservices/base/qmediapluginloader.cpp @@ -0,0 +1,135 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtMediaservices module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qmediapluginloader_p.h" +#include +#include +#include +#include + +#include + + +QT_BEGIN_NAMESPACE + + +typedef QMap ObjectListMap; +Q_GLOBAL_STATIC(ObjectListMap, staticMediaPlugins); + +QMediaPluginLoader::QMediaPluginLoader(const char *iid, const QString &location, Qt::CaseSensitivity): + m_iid(iid) +{ + m_location = location + QLatin1String("/"); + load(); +} + +QStringList QMediaPluginLoader::keys() const +{ + return m_instances.keys(); +} + +QObject* QMediaPluginLoader::instance(QString const &key) +{ + return m_instances.value(key); +} + +QList QMediaPluginLoader::instances(QString const &key) +{ + return m_instances.values(key); +} + +//to be used for testing purposes only +void QMediaPluginLoader::setStaticPlugins(const QString &location, const QObjectList& objects) +{ + staticMediaPlugins()->insert(location + QLatin1String("/"), objects); +} + +void QMediaPluginLoader::load() +{ + if (!m_instances.isEmpty()) + return; + + if (staticMediaPlugins() && staticMediaPlugins()->contains(m_location)) { + foreach(QObject *o, staticMediaPlugins()->value(m_location)) { + if (o != 0 && o->qt_metacast(m_iid) != 0) { + QFactoryInterface* p = qobject_cast(o); + if (p != 0) { + foreach (QString const &key, p->keys()) + m_instances.insertMulti(key, o); + } + } + } + } else { +#ifndef QT_NO_LIBRARY + QStringList paths = QCoreApplication::libraryPaths(); + + foreach (QString const &path, paths) { + QString pluginPathName(path + m_location); + QDir pluginDir(pluginPathName); + + if (!pluginDir.exists()) + continue; + + foreach (QString pluginLib, pluginDir.entryList(QDir::Files)) { + QPluginLoader loader(pluginPathName + pluginLib); + + QObject *o = loader.instance(); + if (o != 0 && o->qt_metacast(m_iid) != 0) { + QFactoryInterface* p = qobject_cast(o); + if (p != 0) { + foreach (QString const &key, p->keys()) + m_instances.insertMulti(key, o); + } + + continue; + } else { + qWarning() << "QMediaPluginLoader: Failed to load plugin: " << pluginLib << loader.errorString(); + } + delete o; + loader.unload(); + } + } +#endif + } +} + +QT_END_NAMESPACE + diff --git a/src/multimedia/mediaservices/base/qmediapluginloader_p.h b/src/multimedia/mediaservices/base/qmediapluginloader_p.h new file mode 100644 index 0000000..194f6ee --- /dev/null +++ b/src/multimedia/mediaservices/base/qmediapluginloader_p.h @@ -0,0 +1,92 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtMediaservices module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QMEDIAPLUGINLOADER_H +#define QMEDIAPLUGINLOADER_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include +#include +#include + + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +class QMediaServiceProviderPlugin; + +class Q_AUTOTEST_EXPORT QMediaPluginLoader +{ +public: + QMediaPluginLoader(const char *iid, + const QString &suffix = QString(), + Qt::CaseSensitivity = Qt::CaseSensitive); + + QStringList keys() const; + QObject* instance(QString const &key); + QList instances(QString const &key); + + static void setStaticPlugins(const QString &location, const QObjectList& objects); + +private: + void load(); + + QByteArray m_iid; + QString m_location; + QMap m_instances; +}; + +QT_END_NAMESPACE + +QT_END_HEADER + +#endif // QMEDIAPLUGINLOADER_H diff --git a/src/multimedia/mediaservices/base/qmediaresource.cpp b/src/multimedia/mediaservices/base/qmediaresource.cpp new file mode 100644 index 0000000..9577092 --- /dev/null +++ b/src/multimedia/mediaservices/base/qmediaresource.cpp @@ -0,0 +1,399 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtMediaservices module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include +#include + +#include + + +QT_BEGIN_NAMESPACE + +/*! + \class QMediaResource + \preliminary + \since 4.7 + \brief The QMediaResource class provides a description of a media resource. + \ingroup multimedia + + A media resource is composed of a \l {url()}{URL} containing the + location of the resource and a set of properties that describe the + format of the resource. The properties provide a means to assess a + resource without first attempting to load it, and in situations where + media be represented by multiple alternative representations provide a + means to select the appropriate resource. + + Media made available by a remote services can often be available in + multiple encodings or quality levels, this allows a client to select + an appropriate resource based on considerations such as codecs supported, + network bandwidth, and display constraints. QMediaResource includes + information such as the \l {mimeType()}{MIME type}, \l {audioCodec()}{audio} + and \l {videoCodec()}{video} codecs, \l {audioBitRate()}{audio} and + \l {videoBitRate()}{video} bit rates, and \l {resolution()}{resolution} + so these constraints and others can be evaluated. + + The only mandatory property of a QMediaResource is the url(). + + \sa QMediaContent +*/ + +/*! + \typedef QMediaResourceList + + Synonym for \c QList +*/ + +/*! + Constructs a null media resource. +*/ +QMediaResource::QMediaResource() +{ +} + +/*! + Constructs a media resource with the given \a mimeType from a \a url. +*/ +QMediaResource::QMediaResource(const QUrl &url, const QString &mimeType) +{ + values.insert(Url, url); + values.insert(MimeType, mimeType); +} + +/*! + Constructs a media resource with the given \a mimeType from a network \a request. +*/ +QMediaResource::QMediaResource(const QNetworkRequest &request, const QString &mimeType) +{ + values.insert(Request, QVariant::fromValue(request)); + values.insert(Url, request.url()); + values.insert(MimeType, mimeType); +} + +/*! + Constructs a copy of a media resource \a other. +*/ +QMediaResource::QMediaResource(const QMediaResource &other) + : values(other.values) +{ +} + +/*! + Assigns the value of \a other to a media resource. +*/ +QMediaResource &QMediaResource::operator =(const QMediaResource &other) +{ + values = other.values; + + return *this; +} + +/*! + Destroys a media resource. +*/ +QMediaResource::~QMediaResource() +{ +} + + +/*! + Compares a media resource to \a other. + + Returns true if the resources are identical, and false otherwise. +*/ +bool QMediaResource::operator ==(const QMediaResource &other) const +{ + return values == other.values; +} + +/*! + Compares a media resource to \a other. + + Returns true if they are different, and false otherwise. +*/ +bool QMediaResource::operator !=(const QMediaResource &other) const +{ + return values != other.values; +} + +/*! + Identifies if a media resource is null. + + Returns true if the resource is null, and false otherwise. +*/ +bool QMediaResource::isNull() const +{ + return values.isEmpty(); +} + +/*! + Returns the URL of a media resource. +*/ +QUrl QMediaResource::url() const +{ + return qvariant_cast(values.value(Url)); +} + +/*! + Returns the network request associated with this media resource. +*/ +QNetworkRequest QMediaResource::request() const +{ + if(values.contains(Request)) + return qvariant_cast(values.value(Request)); + + return QNetworkRequest(url()); +} + +/*! + Returns the MIME type of a media resource. + + This may be null if the MIME type is unknown. +*/ +QString QMediaResource::mimeType() const +{ + return qvariant_cast(values.value(MimeType)); +} + +/*! + Returns the language of a media resource as an ISO 639-2 code. + + This may be null if the language is unknown. +*/ +QString QMediaResource::language() const +{ + return qvariant_cast(values.value(Language)); +} + +/*! + Sets the \a language of a media resource. +*/ +void QMediaResource::setLanguage(const QString &language) +{ + if (!language.isNull()) + values.insert(Language, language); + else + values.remove(Language); +} + +/*! + Returns the audio codec of a media resource. + + This may be null if the media resource does not contain an audio stream, or the codec is + unknown. +*/ +QString QMediaResource::audioCodec() const +{ + return qvariant_cast(values.value(AudioCodec)); +} + +/*! + Sets the audio \a codec of a media resource. +*/ +void QMediaResource::setAudioCodec(const QString &codec) +{ + if (!codec.isNull()) + values.insert(AudioCodec, codec); + else + values.remove(AudioCodec); +} + +/*! + Returns the video codec of a media resource. + + This may be null if the media resource does not contain a video stream, or the codec is + unknonwn. +*/ +QString QMediaResource::videoCodec() const +{ + return qvariant_cast(values.value(VideoCodec)); +} + +/*! + Sets the video \a codec of media resource. +*/ +void QMediaResource::setVideoCodec(const QString &codec) +{ + if (!codec.isNull()) + values.insert(VideoCodec, codec); + else + values.remove(VideoCodec); +} + +/*! + Returns the size in bytes of a media resource. + + This may be zero if the size is unknown. +*/ +qint64 QMediaResource::dataSize() const +{ + return qvariant_cast(values.value(DataSize)); +} + +/*! + Sets the \a size in bytes of a media resource. +*/ +void QMediaResource::setDataSize(const qint64 size) +{ + if (size != 0) + values.insert(DataSize, size); + else + values.remove(DataSize); +} + +/*! + Returns the bit rate in bits per second of a media resource's audio stream. + + This may be zero if the bit rate is unknown, or the resource contains no audio stream. +*/ +int QMediaResource::audioBitRate() const +{ + return values.value(AudioBitRate).toInt(); +} + +/*! + Sets the bit \a rate in bits per second of a media resource's video stream. +*/ +void QMediaResource::setAudioBitRate(int rate) +{ + if (rate != 0) + values.insert(AudioBitRate, rate); + else + values.remove(AudioBitRate); +} + +/*! + Returns the audio sample rate of a media resource. + + This may be zero if the sample size is unknown, or the resource contains no audio stream. +*/ +int QMediaResource::sampleRate() const +{ + return qvariant_cast(values.value(SampleRate)); +} + +/*! + Sets the audio \a sampleRate of a media resource. +*/ +void QMediaResource::setSampleRate(int sampleRate) +{ + if (sampleRate != 0) + values.insert(SampleRate, sampleRate); + else + values.remove(SampleRate); +} + +/*! + Returns the number of audio channels in a media resource. + + This may be zero if the sample size is unknown, or the resource contains no audio stream. +*/ +int QMediaResource::channelCount() const +{ + return qvariant_cast(values.value(ChannelCount)); +} + +/*! + Sets the number of audio \a channels in a media resource. +*/ +void QMediaResource::setChannelCount(int channels) +{ + if (channels != 0) + values.insert(ChannelCount, channels); + else + values.remove(ChannelCount); +} + +/*! + Returns the bit rate in bits per second of a media resource's video stream. + + This may be zero if the bit rate is unknown, or the resource contains no video stream. +*/ +int QMediaResource::videoBitRate() const +{ + return values.value(VideoBitRate).toInt(); +} + +/*! + Sets the bit \a rate in bits per second of a media resource's video stream. +*/ +void QMediaResource::setVideoBitRate(int rate) +{ + if (rate != 0) + values.insert(VideoBitRate, rate); + else + values.remove(VideoBitRate); +} + +/*! + Returns the resolution in pixels of a media resource. + + This may be null is the resolution is unknown, or the resource contains no pixel data (i.e. the + resource is an audio stream. +*/ +QSize QMediaResource::resolution() const +{ + return qvariant_cast(values.value(Resolution)); +} + +/*! + Sets the \a resolution in pixels of a media resource. +*/ +void QMediaResource::setResolution(const QSize &resolution) +{ + if (resolution.width() != -1 || resolution.height() != -1) + values.insert(Resolution, resolution); + else + values.remove(Resolution); +} + +/*! + Sets the \a width and \a height in pixels of a media resource. +*/ +void QMediaResource::setResolution(int width, int height) +{ + if (width != -1 || height != -1) + values.insert(Resolution, QSize(width, height)); + else + values.remove(Resolution); +} +QT_END_NAMESPACE + diff --git a/src/multimedia/mediaservices/base/qmediaresource.h b/src/multimedia/mediaservices/base/qmediaresource.h new file mode 100644 index 0000000..69078cc --- /dev/null +++ b/src/multimedia/mediaservices/base/qmediaresource.h @@ -0,0 +1,134 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtMediaservices module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QMEDIARESOURCE_H +#define QMEDIARESOURCE_H + +#include +#include +#include + + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Multimedia) + + +class Q_MULTIMEDIA_EXPORT QMediaResource +{ +public: + QMediaResource(); + QMediaResource(const QUrl &url, const QString &mimeType = QString()); + QMediaResource(const QNetworkRequest &request, const QString &mimeType = QString()); + QMediaResource(const QMediaResource &other); + QMediaResource &operator =(const QMediaResource &other); + ~QMediaResource(); + + bool isNull() const; + + bool operator ==(const QMediaResource &other) const; + bool operator !=(const QMediaResource &other) const; + + QUrl url() const; + QNetworkRequest request() const; + QString mimeType() const; + + QString language() const; + void setLanguage(const QString &language); + + QString audioCodec() const; + void setAudioCodec(const QString &codec); + + QString videoCodec() const; + void setVideoCodec(const QString &codec); + + qint64 dataSize() const; + void setDataSize(const qint64 size); + + int audioBitRate() const; + void setAudioBitRate(int rate); + + int sampleRate() const; + void setSampleRate(int frequency); + + int channelCount() const; + void setChannelCount(int channels); + + int videoBitRate() const; + void setVideoBitRate(int rate); + + QSize resolution() const; + void setResolution(const QSize &resolution); + void setResolution(int width, int height); + + +private: + enum Property + { + Url, + Request, + MimeType, + Language, + AudioCodec, + VideoCodec, + DataSize, + AudioBitRate, + VideoBitRate, + SampleRate, + ChannelCount, + Resolution + }; + QMap values; +}; + +typedef QList QMediaResourceList; + +QT_END_NAMESPACE + +Q_DECLARE_METATYPE(QMediaResource) +Q_DECLARE_METATYPE(QMediaResourceList) + +QT_END_HEADER + + +#endif diff --git a/src/multimedia/mediaservices/base/qmediaservice.cpp b/src/multimedia/mediaservices/base/qmediaservice.cpp new file mode 100644 index 0000000..5d522dc --- /dev/null +++ b/src/multimedia/mediaservices/base/qmediaservice.cpp @@ -0,0 +1,140 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtMediaservices module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include + +#include +#include "qmediaservice_p.h" + + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Multimedia) + +/*! + \class QMediaService + \brief The QMediaService class provides a common base class for media + service implementations. + \ingroup multimedia-serv + \preliminary + \since 4.7 + + Media services provide implementations of the functionality promised + by media objects, and allow multiple providers to implement a QMediaObject. + + To provide the functionality of a QMediaObject media services implement + QMediaControl interfaces. Services typically implement one core media + control which provides the core feature of a media object, and some + number of additional controls which provide either optional features of + the media object, or features of a secondary media object or peripheral + object. + + A pointer to media service's QMediaControl implementation can be + obtained by passing the control's interface name to the control() function. + + \code + QMediaPlayerControl *control = qobject_cast( + service->control("com.nokia.Qt.QMediaPlayerControl/1.0")); + \endcode + + Media objects can use services loaded dynamically from plug-ins or + implemented statically within an applications. Plug-in based services + should also implement the QMediaServiceProviderPlugin interface. Static + services should implement the QMediaServiceProvider interface. + + \sa QMediaObject, QMediaControl, QMediaServiceProvider, QMediaServiceProviderPlugin +*/ + +/*! + Construct a media service with the given \a parent. This class is meant as a + base class for Multimedia services so this constructor is protected. +*/ + +QMediaService::QMediaService(QObject *parent) + : QObject(parent) + , d_ptr(new QMediaServicePrivate) +{ + d_ptr->q_ptr = this; +} + +/*! + \internal +*/ +QMediaService::QMediaService(QMediaServicePrivate &dd, QObject *parent) + : QObject(parent) + , d_ptr(&dd) +{ + d_ptr->q_ptr = this; +} + +/*! + Destroys a media service. +*/ + +QMediaService::~QMediaService() +{ + delete d_ptr; +} + +/*! + \fn QMediaService::control(const char *interface) const + + Returns a pointer to the media control implementing \a interface. + + If the service does not implement the control a null pointer is returned instead. +*/ + +/*! + \fn QMediaService::control() const + + Returns a pointer to the media control of type T implemented by a media service. + + If the service does not implment the control a null pointer is returned instead. +*/ + +#include "moc_qmediaservice.cpp" + +QT_END_NAMESPACE + +QT_END_HEADER + diff --git a/src/multimedia/mediaservices/base/qmediaservice.h b/src/multimedia/mediaservices/base/qmediaservice.h new file mode 100644 index 0000000..060019b --- /dev/null +++ b/src/multimedia/mediaservices/base/qmediaservice.h @@ -0,0 +1,90 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtMediaservices module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QABSTRACTMEDIASERVICE_H +#define QABSTRACTMEDIASERVICE_H + +#include +#include + +#include + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Multimedia) + +class QMediaServicePrivate; +class Q_MULTIMEDIA_EXPORT QMediaService : public QObject +{ + Q_OBJECT + +public: + ~QMediaService(); + + virtual QMediaControl* control(const char *name) const = 0; + +#ifndef QT_NO_MEMBER_TEMPLATES + template inline T control() const { + if (QObject *object = control(qmediacontrol_iid())) { + return qobject_cast(object); + } + return 0; + } +#endif + +protected: + QMediaService(QObject* parent); + QMediaService(QMediaServicePrivate &dd, QObject *parent); + + QMediaServicePrivate *d_ptr; + +private: + Q_DECLARE_PRIVATE(QMediaService) +}; + +QT_END_NAMESPACE + +QT_END_HEADER + +#endif // QABSTRACTMEDIASERVICE_H + diff --git a/src/multimedia/mediaservices/base/qmediaservice_p.h b/src/multimedia/mediaservices/base/qmediaservice_p.h new file mode 100644 index 0000000..e60e669 --- /dev/null +++ b/src/multimedia/mediaservices/base/qmediaservice_p.h @@ -0,0 +1,75 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtMediaservices module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QABSTRACTMEDIASERVICE_P_H +#define QABSTRACTMEDIASERVICE_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +class QAudioDeviceControl; + +class QMediaServicePrivate +{ +public: + QMediaServicePrivate(): q_ptr(0) {} + virtual ~QMediaServicePrivate() {} + + QMediaService *q_ptr; +}; + +QT_END_NAMESPACE + +QT_END_HEADER + +#endif diff --git a/src/multimedia/mediaservices/base/qmediaserviceprovider.cpp b/src/multimedia/mediaservices/base/qmediaserviceprovider.cpp new file mode 100644 index 0000000..48d245d --- /dev/null +++ b/src/multimedia/mediaservices/base/qmediaserviceprovider.cpp @@ -0,0 +1,738 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtMediaservices module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include + +#include +#include +#include +#include "qmediapluginloader_p.h" +#include + +QT_BEGIN_NAMESPACE + +class QMediaServiceProviderHintPrivate : public QSharedData +{ +public: + QMediaServiceProviderHintPrivate(QMediaServiceProviderHint::Type type) + :type(type), features(0) + { + } + + QMediaServiceProviderHintPrivate(const QMediaServiceProviderHintPrivate &other) + :QSharedData(other), + type(other.type), + device(other.device), + mimeType(other.mimeType), + codecs(other.codecs), + features(other.features) + { + } + + ~QMediaServiceProviderHintPrivate() + { + } + + QMediaServiceProviderHint::Type type; + QByteArray device; + QString mimeType; + QStringList codecs; + QMediaServiceProviderHint::Features features; +}; + +/*! + \class QMediaServiceProviderHint + \preliminary + \since 4.7 + \brief The QMediaServiceProviderHint class describes what is required of a QMediaService. + + \ingroup multimedia-serv + + The QMediaServiceProvider class uses hints to select an appropriate media service. +*/ + +/*! + \enum QMediaServiceProviderHint::Feature + + Enumerates features a media service may provide. + + \value LowLatencyPlayback + The service is expected to play simple audio formats, + but playback should start without significant delay. + Such playback service can be used for beeps, ringtones, etc. + + \value RecordingSupport + The service provides audio or video recording functions. + + \value StreamPlayback + The service is capable of playing QIODevice based streams. +*/ + +/*! + \enum QMediaServiceProviderHint::Type + + Enumerates the possible types of media service provider hint. + + \value Null En empty hint, use the default service. + \value ContentType Select media service most suitable for certain content type. + \value Device Select media service which supports certain device. + \value SupportedFeatures Select media service supporting the set of optional features. +*/ + + +/*! + Constructs an empty media service provider hint. +*/ +QMediaServiceProviderHint::QMediaServiceProviderHint() + :d(new QMediaServiceProviderHintPrivate(Null)) +{ +} + +/*! + Constructs a ContentType media service provider hint. + + This type of hint describes a service that is able to play content of a specific MIME \a type + encoded with one or more of the listed \a codecs. +*/ +QMediaServiceProviderHint::QMediaServiceProviderHint(const QString &type, const QStringList& codecs) + :d(new QMediaServiceProviderHintPrivate(ContentType)) +{ + d->mimeType = type; + d->codecs = codecs; +} + +/*! + Constructs a Device media service provider hint. + + This type of hint describes a media service that utilizes a specific \a device. +*/ +QMediaServiceProviderHint::QMediaServiceProviderHint(const QByteArray &device) + :d(new QMediaServiceProviderHintPrivate(Device)) +{ + d->device = device; +} + +/*! + Constructs a SupportedFeatures media service provider hint. + + This type of hint describes a service which supports a specific set of \a features. +*/ +QMediaServiceProviderHint::QMediaServiceProviderHint(QMediaServiceProviderHint::Features features) + :d(new QMediaServiceProviderHintPrivate(SupportedFeatures)) +{ + d->features = features; +} + +/*! + Constructs a copy of the media service provider hint \a other. +*/ +QMediaServiceProviderHint::QMediaServiceProviderHint(const QMediaServiceProviderHint &other) + :d(other.d) +{ +} + +/*! + Destroys a media service provider hint. +*/ +QMediaServiceProviderHint::~QMediaServiceProviderHint() +{ +} + +/*! + Assigns the value \a other to a media service provider hint. +*/ +QMediaServiceProviderHint& QMediaServiceProviderHint::operator=(const QMediaServiceProviderHint &other) +{ + d = other.d; + return *this; +} + +/*! + Identifies if \a other is of equal value to a media service provider hint. + + Returns true if the hints are equal, and false if they are not. +*/ +bool QMediaServiceProviderHint::operator == (const QMediaServiceProviderHint &other) const +{ + return (d == other.d) || + (d->type == other.d->type && + d->device == other.d->device && + d->mimeType == other.d->mimeType && + d->codecs == other.d->codecs && + d->features == other.d->features); +} + +/*! + Identifies if \a other is not of equal value to a media service provider hint. + + Returns true if the hints are not equal, and false if they are. +*/ +bool QMediaServiceProviderHint::operator != (const QMediaServiceProviderHint &other) const +{ + return !(*this == other); +} + +/*! + Returns true if a media service provider is null. +*/ +bool QMediaServiceProviderHint::isNull() const +{ + return d->type == Null; +} + +/*! + Returns the type of a media service provider hint. +*/ +QMediaServiceProviderHint::Type QMediaServiceProviderHint::type() const +{ + return d->type; +} + +/*! + Returns the mime type of the media a service is expected to be able play. +*/ +QString QMediaServiceProviderHint::mimeType() const +{ + return d->mimeType; +} + +/*! + Returns a list of codes a media service is expected to be able to decode. +*/ +QStringList QMediaServiceProviderHint::codecs() const +{ + return d->codecs; +} + +/*! + Returns the name of a device a media service is expected to utilize. +*/ +QByteArray QMediaServiceProviderHint::device() const +{ + return d->device; +} + +/*! + Returns a set of features a media service is expected to provide. +*/ +QMediaServiceProviderHint::Features QMediaServiceProviderHint::features() const +{ + return d->features; +} + + +Q_GLOBAL_STATIC_WITH_ARGS(QMediaPluginLoader, loader, + (QMediaServiceProviderFactoryInterface_iid, QLatin1String("/mediaservices"), Qt::CaseInsensitive)) + + +class QPluginServiceProvider : public QMediaServiceProvider +{ + QMap pluginMap; + +public: + QMediaService* requestService(const QByteArray &type, const QMediaServiceProviderHint &hint) + { + QString key(QString::fromLatin1(type.constData(),type.length())); + + QListplugins; + foreach (QObject *obj, loader()->instances(key)) { + QMediaServiceProviderPlugin *plugin = + qobject_cast(obj); + if (plugin) + plugins << plugin; + } + + if (!plugins.isEmpty()) { + QMediaServiceProviderPlugin *plugin = 0; + + switch (hint.type()) { + case QMediaServiceProviderHint::Null: + plugin = plugins[0]; + //special case for media player, if low latency was not asked, + //prefer services not offering it, since they are likely to support + //more formats + if (type == QByteArray(Q_MEDIASERVICE_MEDIAPLAYER)) { + foreach (QMediaServiceProviderPlugin *currentPlugin, plugins) { + QMediaServiceFeaturesInterface *iface = + qobject_cast(currentPlugin); + + if (!iface || !(iface->supportedFeatures(type) & + QMediaServiceProviderHint::LowLatencyPlayback)) { + plugin = currentPlugin; + break; + } + + } + } + break; + case QMediaServiceProviderHint::SupportedFeatures: + plugin = plugins[0]; + foreach (QMediaServiceProviderPlugin *currentPlugin, plugins) { + QMediaServiceFeaturesInterface *iface = + qobject_cast(currentPlugin); + + if (iface) { + if ((iface->supportedFeatures(type) & hint.features()) == hint.features()) { + plugin = currentPlugin; + break; + } + } + } + break; + case QMediaServiceProviderHint::Device: { + foreach (QMediaServiceProviderPlugin *currentPlugin, plugins) { + QMediaServiceSupportedDevicesInterface *iface = + qobject_cast(currentPlugin); + + if (!iface) { + // the plugin may support the device, + // but this choice still can be overridden + plugin = currentPlugin; + } else { + if (iface->devices(type).contains(hint.device())) { + plugin = currentPlugin; + break; + } + } + } + } + break; + case QMediaServiceProviderHint::ContentType: { + QtMediaservices::SupportEstimate estimate = QtMediaservices::NotSupported; + foreach (QMediaServiceProviderPlugin *currentPlugin, plugins) { + QtMediaservices::SupportEstimate currentEstimate = QtMediaservices::MaybeSupported; + QMediaServiceSupportedFormatsInterface *iface = + qobject_cast(currentPlugin); + + if (iface) + currentEstimate = iface->hasSupport(hint.mimeType(), hint.codecs()); + + if (currentEstimate > estimate) { + estimate = currentEstimate; + plugin = currentPlugin; + + if (currentEstimate == QtMediaservices::PreferredService) + break; + } + } + } + break; + } + + if (plugin != 0) { + QMediaService *service = plugin->create(key); + if (service != 0) + pluginMap.insert(service, plugin); + + return service; + } + } + + qWarning() << "defaultServiceProvider::requestService(): no service found for -" << key; + return 0; + } + + void releaseService(QMediaService *service) + { + if (service != 0) { + QMediaServiceProviderPlugin *plugin = pluginMap.take(service); + + if (plugin != 0) + plugin->release(service); + } + } + + QtMediaservices::SupportEstimate hasSupport(const QByteArray &serviceType, + const QString &mimeType, + const QStringList& codecs, + int flags) const + { + QList instances = loader()->instances( + QString::fromLatin1(serviceType.constData(),serviceType.length())); + + if (instances.isEmpty()) + return QtMediaservices::NotSupported; + + bool allServicesProvideInterface = true; + QtMediaservices::SupportEstimate supportEstimate = QtMediaservices::NotSupported; + + foreach(QObject *obj, instances) { + QMediaServiceSupportedFormatsInterface *iface = + qobject_cast(obj); + + + if (flags) { + QMediaServiceFeaturesInterface *iface = + qobject_cast(obj); + + if (iface) { + QMediaServiceProviderHint::Features features = iface->supportedFeatures(serviceType); + + //if low latency playback was asked, skip services known + //not to provide low latency playback + if ((flags & QMediaPlayer::LowLatency) && + !(features & QMediaServiceProviderHint::LowLatencyPlayback)) + continue; + + //the same for QIODevice based streams support + if ((flags & QMediaPlayer::StreamPlayback) && + !(features & QMediaServiceProviderHint::StreamPlayback)) + continue; + } + } + + if (iface) + supportEstimate = qMax(supportEstimate, iface->hasSupport(mimeType, codecs)); + else + allServicesProvideInterface = false; + } + + //don't return PreferredService + supportEstimate = qMin(supportEstimate, QtMediaservices::ProbablySupported); + + //Return NotSupported only if no services are available of serviceType + //or all the services returned NotSupported, otherwise return at least MaybeSupported + if (!allServicesProvideInterface) + supportEstimate = qMax(QtMediaservices::MaybeSupported, supportEstimate); + + return supportEstimate; + } + + QStringList supportedMimeTypes(const QByteArray &serviceType, int flags) const + { + QList instances = loader()->instances( + QString::fromLatin1(serviceType.constData(),serviceType.length())); + + QStringList supportedTypes; + + foreach(QObject *obj, instances) { + QMediaServiceSupportedFormatsInterface *iface = + qobject_cast(obj); + + + if (flags & QMediaPlayer::LowLatency) { + QMediaServiceFeaturesInterface *iface = + qobject_cast(obj); + + if (iface) { + QMediaServiceProviderHint::Features features = iface->supportedFeatures(serviceType); + + // If low latency playback was asked for, skip MIME types from services known + // not to provide low latency playback + if ((flags & QMediaPlayer::LowLatency) && + !(features & QMediaServiceProviderHint::LowLatencyPlayback)) + continue; + + //the same for QIODevice based streams support + if ((flags & QMediaPlayer::StreamPlayback) && + !(features & QMediaServiceProviderHint::StreamPlayback)) + continue; + } + } + + if (iface) { + supportedTypes << iface->supportedMimeTypes(); + } + } + + // Multiple services may support the same MIME type + supportedTypes.removeDuplicates(); + + return supportedTypes; + } + + QList devices(const QByteArray &serviceType) const + { + QList res; + + foreach(QObject *obj, loader()->instances( + QString::fromLatin1(serviceType.constData(),serviceType.length()))) { + QMediaServiceSupportedDevicesInterface *iface = + qobject_cast(obj); + + if (iface) { + res.append(iface->devices(serviceType)); + } + } + + return res; + } + + QString deviceDescription(const QByteArray &serviceType, const QByteArray &device) + { + foreach(QObject *obj, loader()->instances( + QString::fromLatin1(serviceType.constData(),serviceType.length()))) { + QMediaServiceSupportedDevicesInterface *iface = + qobject_cast(obj); + + if (iface) { + if (iface->devices(serviceType).contains(device)) + return iface->deviceDescription(serviceType, device); + } + } + + return QString(); + } +}; + +Q_GLOBAL_STATIC(QPluginServiceProvider, pluginProvider); + +/*! + \class QMediaServiceProvider + \preliminary + \since 4.7 + \brief The QMediaServiceProvider class provides an abstract allocator for media services. +*/ + +/*! + \fn QMediaServiceProvider::requestService(const QByteArray &type, const QMediaServiceProviderHint &hint) + + Requests an instance of a \a type service which best matches the given \a hint. + + Returns a pointer to the requested service, or a null pointer if there is no suitable service. + + The returned service must be released with releaseService when it is finished with. +*/ + +/*! + \fn QMediaServiceProvider::releaseService(QMediaService *service) + + Releases a media \a service requested with requestService(). +*/ + +/*! + \fn QtMediaservices::SupportEstimate QMediaServiceProvider::hasSupport(const QByteArray &serviceType, const QString &mimeType, const QStringList& codecs, int flags) const + + Returns how confident a media service provider is that is can provide a \a serviceType + service that is able to play media of a specific \a mimeType that is encoded using the listed + \a codecs while adhearing to constraints identified in \a flags. +*/ +QtMediaservices::SupportEstimate QMediaServiceProvider::hasSupport(const QByteArray &serviceType, + const QString &mimeType, + const QStringList& codecs, + int flags) const +{ + Q_UNUSED(serviceType); + Q_UNUSED(mimeType); + Q_UNUSED(codecs); + Q_UNUSED(flags); + + return QtMediaservices::MaybeSupported; +} + +/*! + \fn QStringList QMediaServiceProvider::supportedMimeTypes(const QByteArray &serviceType, int flags) const + + Returns a list of MIME types supported by the service provider for the specified \a serviceType. + + The resultant list is restricted to MIME types which can be supported given the constraints in \a flags. +*/ +QStringList QMediaServiceProvider::supportedMimeTypes(const QByteArray &serviceType, int flags) const +{ + Q_UNUSED(serviceType); + Q_UNUSED(flags); + + return QStringList(); +} + +/*! + Returns the list of devices related to \a service type. +*/ +QList QMediaServiceProvider::devices(const QByteArray &service) const +{ + Q_UNUSED(service); + return QList(); +} + +/*! + Returns the description of \a device related to \a serviceType, + suitable to be displayed to user. +*/ +QString QMediaServiceProvider::deviceDescription(const QByteArray &serviceType, const QByteArray &device) +{ + Q_UNUSED(serviceType); + Q_UNUSED(device); + return QString(); +} + + +#ifdef QT_BUILD_INTERNAL + +static QMediaServiceProvider *qt_defaultMediaServiceProvider = 0; + +/*! + Sets a media service \a provider as the default. + + \internal +*/ +void QMediaServiceProvider::setDefaultServiceProvider(QMediaServiceProvider *provider) +{ + qt_defaultMediaServiceProvider = provider; +} + +#endif + +/*! + Returns a default provider of media services. +*/ +QMediaServiceProvider *QMediaServiceProvider::defaultServiceProvider() +{ +#ifdef QT_BUILD_INTERNAL + return qt_defaultMediaServiceProvider != 0 + ? qt_defaultMediaServiceProvider + : static_cast(pluginProvider()); +#else + return pluginProvider(); +#endif +} + +/*! + \class QMediaServiceProviderPlugin + \preliminary + \since 4.7 + \brief The QMediaServiceProviderPlugin class interface provides an interface for QMediaService + plug-ins. + + A media service provider plug-in may implement one or more of + QMediaServiceSupportedFormatsInterface, QMediaServiceSupportedDevicesInterface, + and QMediaServiceFeaturesInterface to identify the features it supports. +*/ + +/*! + \fn QMediaServiceProviderPlugin::keys() const + + Returns a list of keys for media services a plug-in can create. +*/ + +/*! + \fn QMediaServiceProviderPlugin::create(const QString &key) + + Constructs a new instance of the QMediaService identified by \a key. + + The QMediaService returned must be destroyed with release(). +*/ + +/*! + \fn QMediaServiceProviderPlugin::release(QMediaService *service) + + Destroys a media \a service constructed with create(). +*/ + + +/*! + \class QMediaServiceSupportedFormatsInterface + \brief The QMediaServiceSupportedFormatsInterface class interface + identifies if a media service plug-in supports a media format. + \since 4.7 + + A QMediaServiceProviderPlugin may implement this interface. +*/ + +/*! + \fn QMediaServiceSupportedFormatsInterface::~QMediaServiceSupportedFormatsInterface() + + Destroys a media service supported formats interface. +*/ + +/*! + \fn QMediaServiceSupportedFormatsInterface::hasSupport(const QString &mimeType, const QStringList& codecs) const + + Returns the level of support a media service plug-in has for a \a mimeType and set of \a codecs. +*/ + +/*! + \fn QMediaServiceSupportedFormatsInterface::supportedMimeTypes() const + + Returns a list of MIME types supported by the media service plug-in. +*/ + +/*! + \class QMediaServiceSupportedDevicesInterface + \brief The QMediaServiceSupportedDevicesInterface class interface + identifies the devices supported by a media service plug-in. + \since 4.7 + + A QMediaServiceProviderPlugin may implement this interface. +*/ + +/*! + \fn QMediaServiceSupportedDevicesInterface::~QMediaServiceSupportedDevicesInterface() + + Destroys a media service supported devices interface. +*/ + +/*! + \fn QMediaServiceSupportedDevicesInterface::devices(const QByteArray &service) const + + Returns a list of devices supported by a plug-in \a service. +*/ + +/*! + \fn QMediaServiceSupportedDevicesInterface::deviceDescription(const QByteArray &service, const QByteArray &device) + + Returns a description of a \a device supported by a plug-in \a service. +*/ + +/*! + \class QMediaServiceFeaturesInterface + \brief The QMediaServiceFeaturesInterface class interface identifies + features supported by a media service plug-in. + \since 4.7 + + A QMediaServiceProviderPlugin may implement this interface. +*/ + +/*! + \fn QMediaServiceFeaturesInterface::~QMediaServiceFeaturesInterface() + + Destroys a media service features interface. +*/ +/*! + \fn QMediaServiceFeaturesInterface::supportedFeatures(const QByteArray &service) const + + Returns a set of features supported by a plug-in \a service. +*/ + +QT_END_NAMESPACE + +#include "moc_qmediaserviceprovider.cpp" +#include "moc_qmediaserviceproviderplugin.cpp" diff --git a/src/multimedia/mediaservices/base/qmediaserviceprovider.h b/src/multimedia/mediaservices/base/qmediaserviceprovider.h new file mode 100644 index 0000000..45021c7 --- /dev/null +++ b/src/multimedia/mediaservices/base/qmediaserviceprovider.h @@ -0,0 +1,174 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtMediaservices module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QMEDIASERVICEPROVIDER_H +#define QMEDIASERVICEPROVIDER_H + +#include +#include + +#include + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Multimedia) + + +class QMediaService; + +class QMediaServiceProviderHintPrivate; +class Q_MULTIMEDIA_EXPORT QMediaServiceProviderHint +{ +public: + enum Type { Null, ContentType, Device, SupportedFeatures }; + + enum Feature { + LowLatencyPlayback = 0x01, + RecordingSupport = 0x02, + StreamPlayback = 0x04 + }; + Q_DECLARE_FLAGS(Features, Feature) + + QMediaServiceProviderHint(); + QMediaServiceProviderHint(const QString &mimeType, const QStringList& codecs); + QMediaServiceProviderHint(const QByteArray &device); + QMediaServiceProviderHint(Features features); + QMediaServiceProviderHint(const QMediaServiceProviderHint &other); + ~QMediaServiceProviderHint(); + + QMediaServiceProviderHint& operator=(const QMediaServiceProviderHint &other); + + bool operator == (const QMediaServiceProviderHint &other) const; + bool operator != (const QMediaServiceProviderHint &other) const; + + bool isNull() const; + + Type type() const; + + QString mimeType() const; + QStringList codecs() const; + + QByteArray device() const; + + Features features() const; + + //to be extended, if necessary + +private: + QSharedDataPointer d; +}; + +class Q_MULTIMEDIA_EXPORT QMediaServiceProvider : public QObject +{ + Q_OBJECT + +public: + virtual QMediaService* requestService(const QByteArray &type, const QMediaServiceProviderHint &hint = QMediaServiceProviderHint()) = 0; + virtual void releaseService(QMediaService *service) = 0; + + virtual QtMediaservices::SupportEstimate hasSupport(const QByteArray &serviceType, + const QString &mimeType, + const QStringList& codecs, + int flags = 0) const; + virtual QStringList supportedMimeTypes(const QByteArray &serviceType, int flags = 0) const; + + virtual QList devices(const QByteArray &serviceType) const; + virtual QString deviceDescription(const QByteArray &serviceType, const QByteArray &device); + + static QMediaServiceProvider* defaultServiceProvider(); + +#ifdef QT_BUILD_INTERNAL + static void setDefaultServiceProvider(QMediaServiceProvider *provider); +#endif +}; + +/*! + Service with support for media playback + Required Controls: QMediaPlayerControl + Optional Controls: QMediaPlaylistControl, QAudioDeviceControl + Video Output Controls (used by QWideoWidget and QGraphicsVideoItem): + Required: QVideoOutputControl + Optional: QVideoWindowControl, QVideoRendererControl, QVideoWidgetControl +*/ +#define Q_MEDIASERVICE_MEDIAPLAYER "com.nokia.qt.mediaplayer" + +/*! + Service with support for recording from audio sources + Required Controls: QAudioDeviceControl + Recording Controls (QMediaRecorder): + Required: QMediaRecorderControl + Recommended: QAudioEncoderControl + Optional: QMediaContainerControl +*/ +#define Q_MEDIASERVICE_AUDIOSOURCE "com.nokia.qt.audiosource" + +/*! + Service with support for camera use. + Required Controls: QCameraControl + Optional Controls: QCameraExposureControl, QCameraFocusControl, QImageProcessingControl + Still Capture Controls: QImageCaptureControl + Recording Controls (QMediaRecorder): + Required: QMediaRecorderControl + Recommended: QAudioEncoderControl, QVideoEncoderControl, QMediaContainerControl + Viewfinder Video Output Controls (used by QWideoWidget and QGraphicsVideoItem): + Required: QVideoOutputControl + Optional: QVideoWindowControl, QVideoRendererControl, QVideoWidgetControl +*/ +#define Q_MEDIASERVICE_CAMERA "com.nokia.qt.camera" + +/*! + Service with support for radio tuning. + Required Controls: QRadioTunerControl + Recording Controls (Optional, used by QMediaRecorder): + Required: QMediaRecorderControl + Recommended: QAudioEncoderControl + Optional: QMediaContainerControl +*/ +#define Q_MEDIASERVICE_RADIO "com.nokia.qt.radio" + + +QT_END_NAMESPACE + +QT_END_HEADER + +#endif // QMEDIASERVICEPROVIDER_H diff --git a/src/multimedia/mediaservices/base/qmediaserviceproviderplugin.h b/src/multimedia/mediaservices/base/qmediaserviceproviderplugin.h new file mode 100644 index 0000000..bc41845 --- /dev/null +++ b/src/multimedia/mediaservices/base/qmediaserviceproviderplugin.h @@ -0,0 +1,125 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtMediaservices module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QMEDIASERVICEPROVIDERPLUGIN_H +#define QMEDIASERVICEPROVIDERPLUGIN_H + +#include +#include +#include + +#include + +#ifdef Q_MOC_RUN +# pragma Q_MOC_EXPAND_MACROS +#endif + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Multimedia) + +class QMediaService; + + +struct Q_MULTIMEDIA_EXPORT QMediaServiceProviderFactoryInterface : public QFactoryInterface +{ + virtual QStringList keys() const = 0; + virtual QMediaService* create(QString const& key) = 0; + virtual void release(QMediaService *service) = 0; +}; + +#define QMediaServiceProviderFactoryInterface_iid \ + "com.nokia.Qt.QMediaServiceProviderFactoryInterface/1.0" +Q_DECLARE_INTERFACE(QMediaServiceProviderFactoryInterface, QMediaServiceProviderFactoryInterface_iid) + + +struct Q_MULTIMEDIA_EXPORT QMediaServiceSupportedFormatsInterface +{ + virtual ~QMediaServiceSupportedFormatsInterface() {} + virtual QtMediaservices::SupportEstimate hasSupport(const QString &mimeType, const QStringList& codecs) const = 0; + virtual QStringList supportedMimeTypes() const = 0; +}; + +#define QMediaServiceSupportedFormatsInterface_iid \ + "com.nokia.Qt.QMediaServiceSupportedFormatsInterface/1.0" +Q_DECLARE_INTERFACE(QMediaServiceSupportedFormatsInterface, QMediaServiceSupportedFormatsInterface_iid) + + +struct Q_MULTIMEDIA_EXPORT QMediaServiceSupportedDevicesInterface +{ + virtual ~QMediaServiceSupportedDevicesInterface() {} + virtual QList devices(const QByteArray &service) const = 0; + virtual QString deviceDescription(const QByteArray &service, const QByteArray &device) = 0; +}; + +#define QMediaServiceSupportedDevicesInterface_iid \ + "com.nokia.Qt.QMediaServiceSupportedDevicesInterface/1.0" +Q_DECLARE_INTERFACE(QMediaServiceSupportedDevicesInterface, QMediaServiceSupportedDevicesInterface_iid) + + +struct Q_MULTIMEDIA_EXPORT QMediaServiceFeaturesInterface +{ + virtual ~QMediaServiceFeaturesInterface() {} + virtual QMediaServiceProviderHint::Features supportedFeatures(const QByteArray &service) const = 0; +}; + +#define QMediaServiceFeaturesInterface_iid \ + "com.nokia.Qt.QMediaServiceFeaturesInterface/1.0" +Q_DECLARE_INTERFACE(QMediaServiceFeaturesInterface, QMediaServiceFeaturesInterface_iid) + +class Q_MULTIMEDIA_EXPORT QMediaServiceProviderPlugin : public QObject, public QMediaServiceProviderFactoryInterface +{ + Q_OBJECT + Q_INTERFACES(QMediaServiceProviderFactoryInterface:QFactoryInterface) + +public: + virtual QStringList keys() const = 0; + virtual QMediaService* create(const QString& key) = 0; + virtual void release(QMediaService *service) = 0; +}; + +QT_END_NAMESPACE + +QT_END_HEADER + +#endif // QMEDIASERVICEPROVIDERPLUGIN_H diff --git a/src/multimedia/mediaservices/base/qmediatimerange.cpp b/src/multimedia/mediaservices/base/qmediatimerange.cpp new file mode 100644 index 0000000..74f54dd --- /dev/null +++ b/src/multimedia/mediaservices/base/qmediatimerange.cpp @@ -0,0 +1,708 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtMediaservices module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include + + +QT_BEGIN_NAMESPACE + +/*! + \class QMediaTimeInterval + \brief The QMediaTimeInterval class represents a time interval with integer precision. + \ingroup multimedia + \since 4.7 + + An interval is specified by an inclusive start() and end() time. + These must be set in the constructor, as this is an immutable class. + The specific units of time represented by the class have not been defined - + it is suitable for any times which can be represented by a signed 64 bit integer. + + The isNormal() method determines if a time interval is normal + (a normal time interval has start() <= end()). An abnormal interval can be converted + in to a normal interval by calling the normalized() method. + + The contains() method determines if a specified time lies within + the time interval. + + The translated() method returns a time interval which has been translated + forwards or backwards through time by a specified offset. + + \sa QMediaTimeRange +*/ + +/*! + \fn QMediaTimeInterval::QMediaTimeInterval() + + Constructs an empty interval. +*/ +QMediaTimeInterval::QMediaTimeInterval() + : s(0) + , e(0) +{ + +} + +/*! + \fn QMediaTimeInterval::QMediaTimeInterval(qint64 start, qint64 end) + + Constructs an interval with the specified \a start and \a end times. +*/ +QMediaTimeInterval::QMediaTimeInterval(qint64 start, qint64 end) + : s(start) + , e(end) +{ + +} + +/*! + \fn QMediaTimeInterval::QMediaTimeInterval(const QMediaTimeInterval &other) + + Constructs an interval by taking a copy of \a other. +*/ +QMediaTimeInterval::QMediaTimeInterval(const QMediaTimeInterval &other) + : s(other.s) + , e(other.e) +{ + +} + +/*! + \fn QMediaTimeInterval::start() const + + Returns the start time of the interval. + + \sa end() +*/ +qint64 QMediaTimeInterval::start() const +{ + return s; +} + +/*! + \fn QMediaTimeInterval::end() const + + Returns the end time of the interval. + + \sa start() +*/ +qint64 QMediaTimeInterval::end() const +{ + return e; +} + +/*! + \fn QMediaTimeInterval::contains(qint64 time) const + + Returns true if the time interval contains the specified \a time. + That is, start() <= time <= end(). +*/ +bool QMediaTimeInterval::contains(qint64 time) const +{ + return isNormal() ? (s <= time && time <= e) + : (e <= time && time <= s); +} + +/*! + \fn QMediaTimeInterval::isNormal() const + + Returns true if this time interval is normal. + A normal time interval has start() <= end(). + + \sa normalized() +*/ +bool QMediaTimeInterval::isNormal() const +{ + return s <= e; +} + +/*! + \fn QMediaTimeInterval::normalized() const + + Returns a normalized version of this interval. + + If the start() time of the interval is greater than the end() time, + then the returned interval has the start and end times swapped. +*/ +QMediaTimeInterval QMediaTimeInterval::normalized() const +{ + if(s > e) + return QMediaTimeInterval(e, s); + + return *this; +} + +/*! + \fn QMediaTimeInterval::translated(qint64 offset) const + + Returns a copy of this time interval, translated by a value of \a offset. + An interval can be moved forward through time with a positive offset, or backward + through time with a negative offset. +*/ +QMediaTimeInterval QMediaTimeInterval::translated(qint64 offset) const +{ + return QMediaTimeInterval(s + offset, e + offset); +} + +/*! + \fn operator==(const QMediaTimeInterval &a, const QMediaTimeInterval &b) + \relates QMediaTimeRange + + Returns true if \a a is exactly equal to \a b. +*/ +bool operator==(const QMediaTimeInterval &a, const QMediaTimeInterval &b) +{ + return a.start() == b.start() && a.end() == b.end(); +} + +/*! + \fn operator!=(const QMediaTimeInterval &a, const QMediaTimeInterval &b) + \relates QMediaTimeRange + + Returns true if \a a is not exactly equal to \a b. +*/ +bool operator!=(const QMediaTimeInterval &a, const QMediaTimeInterval &b) +{ + return a.start() != b.start() || a.end() != b.end(); +} + +class QMediaTimeRangePrivate : public QSharedData +{ +public: + + QMediaTimeRangePrivate(); + QMediaTimeRangePrivate(const QMediaTimeRangePrivate &other); + QMediaTimeRangePrivate(const QMediaTimeInterval &interval); + + QList intervals; + + void addInterval(const QMediaTimeInterval &interval); + void removeInterval(const QMediaTimeInterval &interval); +}; + +QMediaTimeRangePrivate::QMediaTimeRangePrivate() + : QSharedData() +{ + +} + +QMediaTimeRangePrivate::QMediaTimeRangePrivate(const QMediaTimeRangePrivate &other) + : QSharedData() + , intervals(other.intervals) +{ + +} + +QMediaTimeRangePrivate::QMediaTimeRangePrivate(const QMediaTimeInterval &interval) + : QSharedData() +{ + if(interval.isNormal()) + intervals << interval; +} + +void QMediaTimeRangePrivate::addInterval(const QMediaTimeInterval &interval) +{ + // Handle normalized intervals only + if(!interval.isNormal()) + return; + + // Find a place to insert the interval + int i; + for (i = 0; i < intervals.count(); i++) { + // Insert before this element + if(interval.s < intervals[i].s) { + intervals.insert(i, interval); + break; + } + } + + // Interval needs to be added to the end of the list + if (i == intervals.count()) + intervals.append(interval); + + // Do we need to correct the element before us? + if(i > 0 && intervals[i - 1].e >= interval.s - 1) + i--; + + // Merge trailing ranges + while (i < intervals.count() - 1 + && intervals[i].e >= intervals[i + 1].s - 1) { + intervals[i].e = qMax(intervals[i].e, intervals[i + 1].e); + intervals.removeAt(i + 1); + } +} + +void QMediaTimeRangePrivate::removeInterval(const QMediaTimeInterval &interval) +{ + // Handle normalized intervals only + if(!interval.isNormal()) + return; + + for (int i = 0; i < intervals.count(); i++) { + QMediaTimeInterval r = intervals[i]; + + if (r.e < interval.s) { + // Before the removal interval + continue; + } else if (interval.e < r.s) { + // After the removal interval - stop here + break; + } else if (r.s < interval.s && interval.e < r.e) { + // Split case - a single range has a chunk removed + intervals[i].e = interval.s -1; + addInterval(QMediaTimeInterval(interval.e + 1, r.e)); + break; + } else if (r.s < interval.s) { + // Trimming Tail Case + intervals[i].e = interval.s - 1; + } else if (interval.e < r.e) { + // Trimming Head Case - we can stop after this + intervals[i].s = interval.e + 1; + break; + } else { + // Complete coverage case + intervals.removeAt(i); + --i; + } + } +} + +/*! + \class QMediaTimeRange + \brief The QMediaTimeRange class represents a set of zero or more disjoint + time intervals. + \ingroup multimedia + \since 4.7 + + \reentrant + + The earliestTime(), latestTime(), intervals() and isEmpty() + methods are used to get information about the current time range. + + The addInterval(), removeInterval() and clear() methods are used to modify + the current time range. + + When adding or removing intervals from the time range, existing intervals + within the range may be expanded, trimmed, deleted, merged or split to ensure + that all intervals within the time range remain distinct and disjoint. As a + consequence, all intervals added or removed from a time range must be + \l{QMediaTimeInterval::isNormal()}{normal}. + + \sa QMediaTimeInterval +*/ + +/*! + \fn QMediaTimeRange::QMediaTimeRange() + + Constructs an empty time range. +*/ +QMediaTimeRange::QMediaTimeRange() + : d(new QMediaTimeRangePrivate) +{ + +} + +/*! + \fn QMediaTimeRange::QMediaTimeRange(qint64 start, qint64 end) + + Constructs a time range that contains an initial interval from + \a start to \a end inclusive. + + If the interval is not \l{QMediaTimeInterval::isNormal()}{normal}, + the resulting time range will be empty. + + \sa addInterval() +*/ +QMediaTimeRange::QMediaTimeRange(qint64 start, qint64 end) + : d(new QMediaTimeRangePrivate(QMediaTimeInterval(start, end))) +{ + +} + +/*! + \fn QMediaTimeRange::QMediaTimeRange(const QMediaTimeInterval &interval) + + Constructs a time range that contains an intitial interval, \a interval. + + If \a interval is not \l{QMediaTimeInterval::isNormal()}{normal}, + the resulting time range will be empty. + + \sa addInterval() +*/ +QMediaTimeRange::QMediaTimeRange(const QMediaTimeInterval &interval) + : d(new QMediaTimeRangePrivate(interval)) +{ + +} + +/*! + \fn QMediaTimeRange::QMediaTimeRange(const QMediaTimeRange &range) + + Constructs a time range by copying another time \a range. +*/ +QMediaTimeRange::QMediaTimeRange(const QMediaTimeRange &range) + : d(range.d) +{ + +} + +/*! + \fn QMediaTimeRange::~QMediaTimeRange() + + Destructor. +*/ +QMediaTimeRange::~QMediaTimeRange() +{ + +} + +/*! + \fn QMediaTimeRange::operator=(const QMediaTimeRange &other) + + Takes a copy of the \a other time range and returns itself. +*/ +QMediaTimeRange &QMediaTimeRange::operator=(const QMediaTimeRange &other) +{ + d = other.d; + return *this; +} + +/*! + \fn QMediaTimeRange::operator=(const QMediaTimeInterval &interval) + + Sets the time range to a single continuous interval, \a interval. +*/ +QMediaTimeRange &QMediaTimeRange::operator=(const QMediaTimeInterval &interval) +{ + d = new QMediaTimeRangePrivate(interval); + return *this; +} + +/*! + \fn QMediaTimeRange::earliestTime() const + + Returns the earliest time within the time range. + + For empty time ranges, this value is equal to zero. + + \sa latestTime() +*/ +qint64 QMediaTimeRange::earliestTime() const +{ + if (!d->intervals.isEmpty()) + return d->intervals[0].s; + + return 0; +} + +/*! + \fn QMediaTimeRange::latestTime() const + + Returns the latest time within the time range. + + For empty time ranges, this value is equal to zero. + + \sa earliestTime() +*/ +qint64 QMediaTimeRange::latestTime() const +{ + if (!d->intervals.isEmpty()) + return d->intervals[d->intervals.count() - 1].e; + + return 0; +} + +/*! + \fn QMediaTimeRange::addInterval(qint64 start, qint64 end) + \overload + + Adds the interval specified by \a start and \a end + to the time range. + + \sa addInterval() +*/ +void QMediaTimeRange::addInterval(qint64 start, qint64 end) +{ + d->addInterval(QMediaTimeInterval(start, end)); +} + +/*! + \fn QMediaTimeRange::addInterval(const QMediaTimeInterval &interval) + + Adds the specified \a interval to the time range. + + Adding intervals which are not \l{QMediaTimeInterval::isNormal()}{normal} + is invalid, and will be ignored. + + If the specified interval is adjacent to, or overlaps existing + intervals within the time range, these intervals will be merged. + + This operation takes \l{linear time} + + \sa removeInterval() +*/ +void QMediaTimeRange::addInterval(const QMediaTimeInterval &interval) +{ + d->addInterval(interval); +} + +/*! + \fn QMediaTimeRange::addTimeRange(const QMediaTimeRange &range) + + Adds each of the intervals in \a range to this time range. + + Equivalent to calling addInterval() for each interval in \a range. +*/ +void QMediaTimeRange::addTimeRange(const QMediaTimeRange &range) +{ + foreach(const QMediaTimeInterval &i, range.intervals()) { + d->addInterval(i); + } +} + +/*! + \fn QMediaTimeRange::removeInterval(qint64 start, qint64 end) + \overload + + Removes the interval specified by \a start and \a end + from the time range. + + \sa removeInterval() +*/ +void QMediaTimeRange::removeInterval(qint64 start, qint64 end) +{ + d->removeInterval(QMediaTimeInterval(start, end)); +} + +/*! + \fn QMediaTimeRange::removeInterval(const QMediaTimeInterval &interval) + + Removes the specified \a interval from the time range. + + Removing intervals which are not \l{QMediaTimeInterval::isNormal()}{normal} + is invalid, and will be ignored. + + Intervals within the time range will be trimmed, split or deleted + such that no intervals within the time range include any part of the + target interval. + + This operation takes \l{linear time} + + \sa addInterval() +*/ +void QMediaTimeRange::removeInterval(const QMediaTimeInterval &interval) +{ + d->removeInterval(interval); +} + +/*! + \fn QMediaTimeRange::removeTimeRange(const QMediaTimeRange &range) + + Removes each of the intervals in \a range from this time range. + + Equivalent to calling removeInterval() for each interval in \a range. +*/ +void QMediaTimeRange::removeTimeRange(const QMediaTimeRange &range) +{ + foreach(const QMediaTimeInterval &i, range.intervals()) { + d->removeInterval(i); + } +} + +/*! + \fn QMediaTimeRange::operator+=(const QMediaTimeRange &other) + + Adds each interval in \a other to the time range and returns the result. +*/ +QMediaTimeRange& QMediaTimeRange::operator+=(const QMediaTimeRange &other) +{ + addTimeRange(other); + return *this; +} + +/*! + \fn QMediaTimeRange::operator+=(const QMediaTimeInterval &interval) + + Adds the specified \a interval to the time range and returns the result. +*/ +QMediaTimeRange& QMediaTimeRange::operator+=(const QMediaTimeInterval &interval) +{ + addInterval(interval); + return *this; +} + +/*! + \fn QMediaTimeRange::operator-=(const QMediaTimeRange &other) + + Removes each interval in \a other from the time range and returns the result. +*/ +QMediaTimeRange& QMediaTimeRange::operator-=(const QMediaTimeRange &other) +{ + removeTimeRange(other); + return *this; +} + +/*! + \fn QMediaTimeRange::operator-=(const QMediaTimeInterval &interval) + + Removes the specified \a interval from the time range and returns the result. +*/ +QMediaTimeRange& QMediaTimeRange::operator-=(const QMediaTimeInterval &interval) +{ + removeInterval(interval); + return *this; +} + +/*! + \fn QMediaTimeRange::clear() + + Removes all intervals from the time range. + + \sa removeInterval() +*/ +void QMediaTimeRange::clear() +{ + d->intervals.clear(); +} + +/*! + \fn QMediaTimeRange::intervals() const + + Returns the list of intervals covered by this time range. +*/ +QList QMediaTimeRange::intervals() const +{ + return d->intervals; +} + +/*! + \fn QMediaTimeRange::isEmpty() const + + Returns true if there are no intervals within the time range. + + \sa intervals() +*/ +bool QMediaTimeRange::isEmpty() const +{ + return d->intervals.isEmpty(); +} + +/*! + \fn QMediaTimeRange::isContinuous() const + + Returns true if the time range consists of a continuous interval. + That is, there is one or fewer disjoint intervals within the time range. +*/ +bool QMediaTimeRange::isContinuous() const +{ + return (d->intervals.count() <= 1); +} + +/*! + \fn QMediaTimeRange::contains(qint64 time) const + + Returns true if the specified \a time lies within the time range. +*/ +bool QMediaTimeRange::contains(qint64 time) const +{ + for (int i = 0; i < d->intervals.count(); i++) { + if (d->intervals[i].contains(time)) + return true; + + if (time < d->intervals[i].s) + break; + } + + return false; +} + +/*! + \fn operator==(const QMediaTimeRange &a, const QMediaTimeRange &b) + \relates QMediaTimeRange + + Returns true if all intervals in \a a are present in \a b. +*/ +bool operator==(const QMediaTimeRange &a, const QMediaTimeRange &b) +{ + if (a.intervals().count() != b.intervals().count()) + return false; + + for (int i = 0; i < a.intervals().count(); i++) + { + if(a.intervals()[i] != b.intervals()[i]) + return false; + } + + return true; +} + +/*! + \fn operator!=(const QMediaTimeRange &a, const QMediaTimeRange &b) + \relates QMediaTimeRange + + Returns true if one or more intervals in \a a are not present in \a b. +*/ +bool operator!=(const QMediaTimeRange &a, const QMediaTimeRange &b) +{ + return !(a == b); +} + +/*! + \fn operator+(const QMediaTimeRange &r1, const QMediaTimeRange &r2) + + Returns a time range containing the union between \a r1 and \a r2. + */ +QMediaTimeRange operator+(const QMediaTimeRange &r1, const QMediaTimeRange &r2) +{ + return (QMediaTimeRange(r1) += r2); +} + +/*! + \fn operator-(const QMediaTimeRange &r1, const QMediaTimeRange &r2) + + Returns a time range containing \a r2 subtracted from \a r1. + */ +QMediaTimeRange operator-(const QMediaTimeRange &r1, const QMediaTimeRange &r2) +{ + return (QMediaTimeRange(r1) -= r2); +} + +QT_END_NAMESPACE + diff --git a/src/multimedia/mediaservices/base/qmediatimerange.h b/src/multimedia/mediaservices/base/qmediatimerange.h new file mode 100644 index 0000000..94beaad --- /dev/null +++ b/src/multimedia/mediaservices/base/qmediatimerange.h @@ -0,0 +1,135 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtMediaservices module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QMEDIATIMERANGE_H +#define QMEDIATIMERANGE_H + +#include +#include + + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Multimedia) + +class QMediaTimeRangePrivate; + +class Q_MULTIMEDIA_EXPORT QMediaTimeInterval +{ +public: + QMediaTimeInterval(); + QMediaTimeInterval(qint64 start, qint64 end); + QMediaTimeInterval(const QMediaTimeInterval&); + + qint64 start() const; + qint64 end() const; + + bool contains(qint64 time) const; + + bool isNormal() const; + QMediaTimeInterval normalized() const; + QMediaTimeInterval translated(qint64 offset) const; + +private: + friend class QMediaTimeRangePrivate; + friend class QMediaTimeRange; + + qint64 s; + qint64 e; +}; + +Q_MULTIMEDIA_EXPORT bool operator==(const QMediaTimeInterval&, const QMediaTimeInterval&); +Q_MULTIMEDIA_EXPORT bool operator!=(const QMediaTimeInterval&, const QMediaTimeInterval&); + +class Q_MULTIMEDIA_EXPORT QMediaTimeRange +{ +public: + + QMediaTimeRange(); + QMediaTimeRange(qint64 start, qint64 end); + QMediaTimeRange(const QMediaTimeInterval&); + QMediaTimeRange(const QMediaTimeRange &range); + ~QMediaTimeRange(); + + QMediaTimeRange &operator=(const QMediaTimeRange&); + QMediaTimeRange &operator=(const QMediaTimeInterval&); + + qint64 earliestTime() const; + qint64 latestTime() const; + + QList intervals() const; + bool isEmpty() const; + bool isContinuous() const; + + bool contains(qint64 time) const; + + void addInterval(qint64 start, qint64 end); + void addInterval(const QMediaTimeInterval &interval); + void addTimeRange(const QMediaTimeRange&); + + void removeInterval(qint64 start, qint64 end); + void removeInterval(const QMediaTimeInterval &interval); + void removeTimeRange(const QMediaTimeRange&); + + QMediaTimeRange& operator+=(const QMediaTimeRange&); + QMediaTimeRange& operator+=(const QMediaTimeInterval&); + QMediaTimeRange& operator-=(const QMediaTimeRange&); + QMediaTimeRange& operator-=(const QMediaTimeInterval&); + + void clear(); + +private: + QSharedDataPointer d; +}; + +Q_MULTIMEDIA_EXPORT bool operator==(const QMediaTimeRange&, const QMediaTimeRange&); +Q_MULTIMEDIA_EXPORT bool operator!=(const QMediaTimeRange&, const QMediaTimeRange&); +Q_MULTIMEDIA_EXPORT QMediaTimeRange operator+(const QMediaTimeRange&, const QMediaTimeRange&); +Q_MULTIMEDIA_EXPORT QMediaTimeRange operator-(const QMediaTimeRange&, const QMediaTimeRange&); + + +QT_END_NAMESPACE + +QT_END_HEADER + +#endif // QMEDIATIMERANGE_H diff --git a/src/multimedia/mediaservices/base/qmetadatacontrol.cpp b/src/multimedia/mediaservices/base/qmetadatacontrol.cpp new file mode 100644 index 0000000..32be987 --- /dev/null +++ b/src/multimedia/mediaservices/base/qmetadatacontrol.cpp @@ -0,0 +1,185 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtMediaservices module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include "qmediacontrol_p.h" + + +QT_BEGIN_NAMESPACE + + +/*! + \class QMetaDataControl + \ingroup multimedia-serv + \since 4.7 + \preliminary + \brief The QMetaDataControl class provides access to the meta-data of a + QMediaService's media. + + If a QMediaService can provide read or write access to the meta-data of + its current media it will implement QMetaDataControl. This control + provides functions for both retrieving and setting meta-data values. + Meta-data may be addressed by the well defined keys in the + QtMediaservices::MetaData enumeration using the metaData() functions, or by + string keys using the extendedMetaData() functions. + + The functionality provided by this control is exposed to application + code by the meta-data members of QMediaObject, and so meta-data access + is potentially available in any of the media object classes. Any media + service may implement QMetaDataControl. + + The interface name of QMetaDataControl is \c com.nokia.Qt.QMetaDataControl/1.0 as + defined in QMetaDataControl_iid. + + \sa QMediaService::control(), QMediaObject +*/ + +/*! + \macro QMetaDataControl_iid + + \c com.nokia.Qt.QMetaDataControl/1.0 + + Defines the interface name of the QMetaDataControl class. + + \relates QMetaDataControl +*/ + +/*! + Construct a QMetaDataControl with \a parent. This class is meant as a base class + for service specific meta data providers so this constructor is protected. +*/ + +QMetaDataControl::QMetaDataControl(QObject *parent): + QMediaControl(*new QMediaControlPrivate, parent) +{ +} + +/*! + Destroy the meta-data object. +*/ + +QMetaDataControl::~QMetaDataControl() +{ +} + +/*! + \fn bool QMetaDataControl::isMetaDataAvailable() const + + Identifies if meta-data is available from a media service. + + Returns true if the meta-data is available and false otherwise. +*/ + +/*! + \fn bool QMetaDataControl::isWritable() const + + Identifies if a media service's meta-data can be edited. + + Returns true if the meta-data is writable and false otherwise. +*/ + +/*! + \fn QVariant QMetaDataControl::metaData(QtMediaservices::MetaData key) const + + Returns the meta-data for the given \a key. +*/ + +/*! + \fn void QMetaDataControl::setMetaData(QtMediaservices::MetaData key, const QVariant &value) + + Sets the \a value of the meta-data element with the given \a key. +*/ + +/*! + \fn QMetaDataControl::availableMetaData() const + + Returns a list of keys there is meta-data available for. +*/ + +/*! + \fn QMetaDataControl::extendedMetaData(const QString &key) const + + Returns the metaData for an abitrary string \a key. + + The valid selection of keys for extended meta-data is determined by the provider and the meaning + and type may differ between providers. +*/ + +/*! + \fn QMetaDataControl::setExtendedMetaData(const QString &key, const QVariant &value) + + Change the value of the meta-data element with an abitrary string \a key to \a value. + + The valid selection of keys for extended meta-data is determined by the provider and the meaning + and type may differ between providers. +*/ + +/*! + \fn QMetaDataControl::availableExtendedMetaData() const + + Returns a list of keys there is extended meta-data available for. +*/ + + +/*! + \fn void QMetaDataControl::metaDataChanged() + + Signal the changes of meta-data. +*/ + +/*! + \fn void QMetaDataControl::metaDataAvailableChanged(bool available) + + Signal the availability of meta-data has changed, \a available will + be true if the multimedia object has meta-data. +*/ + +/*! + \fn void QMetaDataControl::writableChanged(bool writable) + + Signal a change in the writable status of meta-data, \a writable will be + true if meta-data elements can be added or adjusted. +*/ + +#include "moc_qmetadatacontrol.cpp" + +QT_END_NAMESPACE + diff --git a/src/multimedia/mediaservices/base/qmetadatacontrol.h b/src/multimedia/mediaservices/base/qmetadatacontrol.h new file mode 100644 index 0000000..cf4a0d3 --- /dev/null +++ b/src/multimedia/mediaservices/base/qmetadatacontrol.h @@ -0,0 +1,92 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtMediaservices module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QMETADATACONTROL_H +#define QMETADATACONTROL_H + +#include +#include +#include + + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Multimedia) + +class Q_MULTIMEDIA_EXPORT QMetaDataControl : public QMediaControl +{ + Q_OBJECT + +public: + ~QMetaDataControl(); + + virtual bool isWritable() const = 0; + virtual bool isMetaDataAvailable() const = 0; + + virtual QVariant metaData(QtMediaservices::MetaData key) const = 0; + virtual void setMetaData(QtMediaservices::MetaData key, const QVariant &value) = 0; + virtual QList availableMetaData() const = 0; + + virtual QVariant extendedMetaData(const QString &key) const = 0; + virtual void setExtendedMetaData(const QString &key, const QVariant &value) = 0; + virtual QStringList availableExtendedMetaData() const = 0; + +Q_SIGNALS: + void metaDataChanged(); + + void writableChanged(bool writable); + void metaDataAvailableChanged(bool available); + +protected: + QMetaDataControl(QObject *parent = 0); +}; + +#define QMetaDataControl_iid "com.nokia.Qt.QMetaDataControl/1.0" +Q_MEDIA_DECLARE_CONTROL(QMetaDataControl, QMetaDataControl_iid) + +QT_END_NAMESPACE + +QT_END_HEADER + + +#endif // QMETADATAPROVIDER_H diff --git a/src/multimedia/mediaservices/base/qpaintervideosurface.cpp b/src/multimedia/mediaservices/base/qpaintervideosurface.cpp new file mode 100644 index 0000000..b3e0dd5 --- /dev/null +++ b/src/multimedia/mediaservices/base/qpaintervideosurface.cpp @@ -0,0 +1,1565 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtMediaservices module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qpaintervideosurface_p.h" +#include "qpaintervideosurface_mac_p.h" + +#include + +#include +#include +#include + +#if !defined(QT_NO_OPENGL) && !defined(QT_OPENGL_ES_1_CL) && !defined(QT_OPENGL_ES_1) +#include +#endif + +#include + + +QT_BEGIN_NAMESPACE + +QVideoSurfacePainter::~QVideoSurfacePainter() +{ +} + +class QVideoSurfaceRasterPainter : public QVideoSurfacePainter +{ +public: + QVideoSurfaceRasterPainter(); + + QList supportedPixelFormats( + QAbstractVideoBuffer::HandleType handleType) const; + + bool isFormatSupported( + const QVideoSurfaceFormat &format, QVideoSurfaceFormat *similar) const; + + QAbstractVideoSurface::Error start(const QVideoSurfaceFormat &format); + void stop(); + + QAbstractVideoSurface::Error setCurrentFrame(const QVideoFrame &frame); + + QAbstractVideoSurface::Error paint( + const QRectF &target, QPainter *painter, const QRectF &source); + + void updateColors(int brightness, int contrast, int hue, int saturation); + +private: + QList m_imagePixelFormats; + QVideoFrame m_frame; + QSize m_imageSize; + QImage::Format m_imageFormat; + QVideoSurfaceFormat::Direction m_scanLineDirection; +}; + +QVideoSurfaceRasterPainter::QVideoSurfaceRasterPainter() + : m_imageFormat(QImage::Format_Invalid) + , m_scanLineDirection(QVideoSurfaceFormat::TopToBottom) +{ + m_imagePixelFormats + << QVideoFrame::Format_RGB32 +#ifndef QT_OPENGL_ES // The raster formats should be a subset of the GL formats. + << QVideoFrame::Format_RGB24 +#endif + << QVideoFrame::Format_ARGB32 + << QVideoFrame::Format_RGB565; +} + +QList QVideoSurfaceRasterPainter::supportedPixelFormats( + QAbstractVideoBuffer::HandleType handleType) const +{ + return handleType == QAbstractVideoBuffer::NoHandle + ? m_imagePixelFormats + : QList(); +} + +bool QVideoSurfaceRasterPainter::isFormatSupported( + const QVideoSurfaceFormat &format, QVideoSurfaceFormat *) const +{ + return format.handleType() == QAbstractVideoBuffer::NoHandle + && m_imagePixelFormats.contains(format.pixelFormat()) + && !format.frameSize().isEmpty(); +} + +QAbstractVideoSurface::Error QVideoSurfaceRasterPainter::start(const QVideoSurfaceFormat &format) +{ + m_frame = QVideoFrame(); + m_imageFormat = QVideoFrame::imageFormatFromPixelFormat(format.pixelFormat()); + m_imageSize = format.frameSize(); + m_scanLineDirection = format.scanLineDirection(); + + return format.handleType() == QAbstractVideoBuffer::NoHandle + && m_imageFormat != QImage::Format_Invalid + && !m_imageSize.isEmpty() + ? QAbstractVideoSurface::NoError + : QAbstractVideoSurface::UnsupportedFormatError; +} + +void QVideoSurfaceRasterPainter::stop() +{ + m_frame = QVideoFrame(); +} + +QAbstractVideoSurface::Error QVideoSurfaceRasterPainter::setCurrentFrame(const QVideoFrame &frame) +{ + m_frame = frame; + + return QAbstractVideoSurface::NoError; +} + +QAbstractVideoSurface::Error QVideoSurfaceRasterPainter::paint( + const QRectF &target, QPainter *painter, const QRectF &source) +{ + if (m_frame.map(QAbstractVideoBuffer::ReadOnly)) { + QImage image( + m_frame.bits(), + m_imageSize.width(), + m_imageSize.height(), + m_frame.bytesPerLine(), + m_imageFormat); + + if (m_scanLineDirection == QVideoSurfaceFormat::BottomToTop) { + const QTransform oldTransform = painter->transform(); + + painter->scale(1, -1); + painter->translate(0, -target.bottom()); + painter->drawImage( + QRectF(target.x(), 0, target.width(), target.height()), image, source); + painter->setTransform(oldTransform); + } else { + painter->drawImage(target, image, source); + } + + m_frame.unmap(); + } else if (m_frame.isValid()) { + return QAbstractVideoSurface::IncorrectFormatError; + } else { + painter->fillRect(target, Qt::black); + } + return QAbstractVideoSurface::NoError; +} + +void QVideoSurfaceRasterPainter::updateColors(int, int, int, int) +{ +} + +#if !defined(QT_NO_OPENGL) && !defined(QT_OPENGL_ES_1_CL) && !defined(QT_OPENGL_ES_1) + +#ifndef Q_WS_MAC +# ifndef APIENTRYP +# ifdef APIENTRY +# define APIENTRYP APIENTRY * +# else +# define APIENTRY +# define APIENTRYP * +# endif +# endif +#else +# define APIENTRY +# define APIENTRYP * +#endif + +#ifndef GL_TEXTURE0 +# define GL_TEXTURE0 0x84C0 +# define GL_TEXTURE1 0x84C1 +# define GL_TEXTURE2 0x84C2 +#endif +#ifndef GL_PROGRAM_ERROR_STRING_ARB +# define GL_PROGRAM_ERROR_STRING_ARB 0x8874 +#endif + +#ifndef GL_UNSIGNED_SHORT_5_6_5 +# define GL_UNSIGNED_SHORT_5_6_5 33635 +#endif + +class QVideoSurfaceGLPainter : public QVideoSurfacePainter +{ +public: + QVideoSurfaceGLPainter(QGLContext *context); + ~QVideoSurfaceGLPainter(); + QList supportedPixelFormats( + QAbstractVideoBuffer::HandleType handleType) const; + + bool isFormatSupported( + const QVideoSurfaceFormat &format, QVideoSurfaceFormat *similar) const; + + QAbstractVideoSurface::Error setCurrentFrame(const QVideoFrame &frame); + + void updateColors(int brightness, int contrast, int hue, int saturation); + +protected: + void initRgbTextureInfo(GLenum internalFormat, GLuint format, GLenum type, const QSize &size); + void initYuv420PTextureInfo(const QSize &size); + void initYv12TextureInfo(const QSize &size); + +#ifndef QT_OPENGL_ES + typedef void (APIENTRY *_glActiveTexture) (GLenum); + _glActiveTexture glActiveTexture; +#endif + + QList m_imagePixelFormats; + QList m_glPixelFormats; + QMatrix4x4 m_colorMatrix; + QVideoFrame m_frame; + + QGLContext *m_context; + QAbstractVideoBuffer::HandleType m_handleType; + QVideoSurfaceFormat::Direction m_scanLineDirection; + GLenum m_textureFormat; + GLuint m_textureInternalFormat; + GLenum m_textureType; + int m_textureCount; + GLuint m_textureIds[3]; + int m_textureWidths[3]; + int m_textureHeights[3]; + int m_textureOffsets[3]; + bool m_yuv; +}; + +QVideoSurfaceGLPainter::QVideoSurfaceGLPainter(QGLContext *context) + : m_context(context) + , m_handleType(QAbstractVideoBuffer::NoHandle) + , m_scanLineDirection(QVideoSurfaceFormat::TopToBottom) + , m_textureFormat(0) + , m_textureInternalFormat(0) + , m_textureType(0) + , m_textureCount(0) + , m_yuv(false) +{ +#ifndef QT_OPENGL_ES + glActiveTexture = (_glActiveTexture)m_context->getProcAddress(QLatin1String("glActiveTexture")); +#endif +} + +QVideoSurfaceGLPainter::~QVideoSurfaceGLPainter() +{ +} + +QList QVideoSurfaceGLPainter::supportedPixelFormats( + QAbstractVideoBuffer::HandleType handleType) const +{ + switch (handleType) { + case QAbstractVideoBuffer::NoHandle: + return m_imagePixelFormats; + case QAbstractVideoBuffer::GLTextureHandle: + return m_glPixelFormats; + default: + return QList(); + } +} + +bool QVideoSurfaceGLPainter::isFormatSupported( + const QVideoSurfaceFormat &format, QVideoSurfaceFormat *) const +{ + if (format.frameSize().isEmpty()) { + return false; + } else { + switch (format.handleType()) { + case QAbstractVideoBuffer::NoHandle: + return m_imagePixelFormats.contains(format.pixelFormat()); + case QAbstractVideoBuffer::GLTextureHandle: + return m_glPixelFormats.contains(format.pixelFormat()); + default: + return false; + } + } +} + +QAbstractVideoSurface::Error QVideoSurfaceGLPainter::setCurrentFrame(const QVideoFrame &frame) +{ + m_frame = frame; + + if (m_handleType == QAbstractVideoBuffer::GLTextureHandle) { + m_textureIds[0] = frame.handle().toInt(); + } else if (m_frame.map(QAbstractVideoBuffer::ReadOnly)) { + m_context->makeCurrent(); + + for (int i = 0; i < m_textureCount; ++i) { + glBindTexture(GL_TEXTURE_2D, m_textureIds[i]); + glTexImage2D( + GL_TEXTURE_2D, + 0, + m_textureInternalFormat, + m_textureWidths[i], + m_textureHeights[i], + 0, + m_textureFormat, + m_textureType, + m_frame.bits() + m_textureOffsets[i]); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); + } + m_frame.unmap(); + } else if (m_frame.isValid()) { + return QAbstractVideoSurface::IncorrectFormatError; + } + + return QAbstractVideoSurface::NoError; +} + +void QVideoSurfaceGLPainter::updateColors(int brightness, int contrast, int hue, int saturation) +{ + const qreal b = brightness / 200.0; + const qreal c = contrast / 100.0 + 1.0; + const qreal h = hue / 100.0; + const qreal s = saturation / 100.0 + 1.0; + + const qreal cosH = qCos(M_PI * h); + const qreal sinH = qSin(M_PI * h); + + const qreal h11 = 0.787 * cosH - 0.213 * sinH + 0.213; + const qreal h21 = -0.213 * cosH + 0.143 * sinH + 0.213; + const qreal h31 = -0.213 * cosH - 0.787 * sinH + 0.213; + + const qreal h12 = -0.715 * cosH - 0.715 * sinH + 0.715; + const qreal h22 = 0.285 * cosH + 0.140 * sinH + 0.715; + const qreal h32 = -0.715 * cosH + 0.715 * sinH + 0.715; + + const qreal h13 = -0.072 * cosH + 0.928 * sinH + 0.072; + const qreal h23 = -0.072 * cosH - 0.283 * sinH + 0.072; + const qreal h33 = 0.928 * cosH + 0.072 * sinH + 0.072; + + const qreal sr = (1.0 - s) * 0.3086; + const qreal sg = (1.0 - s) * 0.6094; + const qreal sb = (1.0 - s) * 0.0820; + + const qreal sr_s = sr + s; + const qreal sg_s = sg + s; + const qreal sb_s = sr + s; + + const float m4 = (s + sr + sg + sb) * (0.5 - 0.5 * c + b); + + m_colorMatrix(0, 0) = c * (sr_s * h11 + sg * h21 + sb * h31); + m_colorMatrix(0, 1) = c * (sr_s * h12 + sg * h22 + sb * h32); + m_colorMatrix(0, 2) = c * (sr_s * h13 + sg * h23 + sb * h33); + m_colorMatrix(0, 3) = m4; + + m_colorMatrix(1, 0) = c * (sr * h11 + sg_s * h21 + sb * h31); + m_colorMatrix(1, 1) = c * (sr * h12 + sg_s * h22 + sb * h32); + m_colorMatrix(1, 2) = c * (sr * h13 + sg_s * h23 + sb * h33); + m_colorMatrix(1, 3) = m4; + + m_colorMatrix(2, 0) = c * (sr * h11 + sg * h21 + sb_s * h31); + m_colorMatrix(2, 1) = c * (sr * h12 + sg * h22 + sb_s * h32); + m_colorMatrix(2, 2) = c * (sr * h13 + sg * h23 + sb_s * h33); + m_colorMatrix(2, 3) = m4; + + m_colorMatrix(3, 0) = 0.0; + m_colorMatrix(3, 1) = 0.0; + m_colorMatrix(3, 2) = 0.0; + m_colorMatrix(3, 3) = 1.0; + + if (m_yuv) { + m_colorMatrix = m_colorMatrix * QMatrix4x4( + 1.0, 0.000, 1.140, -0.5700, + 1.0, -0.394, -0.581, 0.4875, + 1.0, 2.028, 0.000, -1.0140, + 0.0, 0.000, 0.000, 1.0000); + } +} + +void QVideoSurfaceGLPainter::initRgbTextureInfo( + GLenum internalFormat, GLuint format, GLenum type, const QSize &size) +{ + m_yuv = false; + m_textureInternalFormat = internalFormat; + m_textureFormat = format; + m_textureType = type; + m_textureCount = 1; + m_textureWidths[0] = size.width(); + m_textureHeights[0] = size.height(); + m_textureOffsets[0] = 0; +} + +void QVideoSurfaceGLPainter::initYuv420PTextureInfo(const QSize &size) +{ + int w = (size.width() + 3) & ~3; + int w2 = (size.width()/2 + 3) & ~3; + + m_yuv = true; + m_textureInternalFormat = GL_LUMINANCE; + m_textureFormat = GL_LUMINANCE; + m_textureType = GL_UNSIGNED_BYTE; + m_textureCount = 3; + m_textureWidths[0] = size.width(); + m_textureHeights[0] = size.height(); + m_textureOffsets[0] = 0; + m_textureWidths[1] = size.width() / 2; + m_textureHeights[1] = size.height() / 2; + m_textureOffsets[1] = w * size.height(); + m_textureWidths[2] = size.width() / 2; + m_textureHeights[2] = size.height() / 2; + m_textureOffsets[2] = w * size.height() + w2 * (size.height() / 2); +} + +void QVideoSurfaceGLPainter::initYv12TextureInfo(const QSize &size) +{ + int w = (size.width() + 3) & ~3; + int w2 = (size.width()/2 + 3) & ~3; + + m_yuv = true; + m_textureInternalFormat = GL_LUMINANCE; + m_textureFormat = GL_LUMINANCE; + m_textureType = GL_UNSIGNED_BYTE; + m_textureCount = 3; + m_textureWidths[0] = size.width(); + m_textureHeights[0] = size.height(); + m_textureOffsets[0] = 0; + m_textureWidths[1] = size.width() / 2; + m_textureHeights[1] = size.height() / 2; + m_textureOffsets[1] = w * size.height() + w2 * (size.height() / 2); + m_textureWidths[2] = size.width() / 2; + m_textureHeights[2] = size.height() / 2; + m_textureOffsets[2] = w * size.height(); +} + +#ifndef QT_OPENGL_ES + +# ifndef GL_FRAGMENT_PROGRAM_ARB +# define GL_FRAGMENT_PROGRAM_ARB 0x8804 +# define GL_PROGRAM_FORMAT_ASCII_ARB 0x8875 +# endif + +// Paints an RGB32 frame +static const char *qt_arbfp_xrgbShaderProgram = + "!!ARBfp1.0\n" + "PARAM matrix[4] = { program.local[0..2]," + "{ 0.0, 0.0, 0.0, 1.0 } };\n" + "TEMP xrgb;\n" + "TEX xrgb.xyz, fragment.texcoord[0], texture[0], 2D;\n" + "MOV xrgb.w, matrix[3].w;\n" + "DP4 result.color.x, xrgb.zyxw, matrix[0];\n" + "DP4 result.color.y, xrgb.zyxw, matrix[1];\n" + "DP4 result.color.z, xrgb.zyxw, matrix[2];\n" + "END"; + +// Paints an ARGB frame. +static const char *qt_arbfp_argbShaderProgram = + "!!ARBfp1.0\n" + "PARAM matrix[4] = { program.local[0..2]," + "{ 0.0, 0.0, 0.0, 1.0 } };\n" + "TEMP argb;\n" + "TEX argb, fragment.texcoord[0], texture[0], 2D;\n" + "MOV argb.w, matrix[3].w;\n" + "DP4 result.color.x, argb.zyxw, matrix[0];\n" + "DP4 result.color.y, argb.zyxw, matrix[1];\n" + "DP4 result.color.z, argb.zyxw, matrix[2];\n" + "TEX result.color.w, fragment.texcoord[0], texture, 2D;\n" + "END"; + +// Paints an RGB(A) frame. +static const char *qt_arbfp_rgbShaderProgram = + "!!ARBfp1.0\n" + "PARAM matrix[4] = { program.local[0..2]," + "{ 0.0, 0.0, 0.0, 1.0 } };\n" + "TEMP rgb;\n" + "TEX rgb, fragment.texcoord[0], texture[0], 2D;\n" + "MOV rgb.w, matrix[3].w;\n" + "DP4 result.color.x, rgb, matrix[0];\n" + "DP4 result.color.y, rgb, matrix[1];\n" + "DP4 result.color.z, rgb, matrix[2];\n" + "TEX result.color.w, fragment.texcoord[0], texture, 2D;\n" + "END"; + +// Paints a YUV420P or YV12 frame. +static const char *qt_arbfp_yuvPlanarShaderProgram = + "!!ARBfp1.0\n" + "PARAM matrix[4] = { program.local[0..2]," + "{ 0.0, 0.0, 0.0, 1.0 } };\n" + "TEMP yuv;\n" + "TEX yuv.x, fragment.texcoord[0], texture[0], 2D;\n" + "TEX yuv.y, fragment.texcoord[0], texture[1], 2D;\n" + "TEX yuv.z, fragment.texcoord[0], texture[2], 2D;\n" + "MOV yuv.w, matrix[3].w;\n" + "DP4 result.color.x, yuv, matrix[0];\n" + "DP4 result.color.y, yuv, matrix[1];\n" + "DP4 result.color.z, yuv, matrix[2];\n" + "END"; + +// Paints a YUV444 frame. +static const char *qt_arbfp_xyuvShaderProgram = + "!!ARBfp1.0\n" + "PARAM matrix[4] = { program.local[0..2]," + "{ 0.0, 0.0, 0.0, 1.0 } };\n" + "TEMP ayuv;\n" + "TEX ayuv, fragment.texcoord[0], texture[0], 2D;\n" + "MOV ayuv.x, matrix[3].w;\n" + "DP4 result.color.x, ayuv.yzwx, matrix[0];\n" + "DP4 result.color.y, ayuv.yzwx, matrix[1];\n" + "DP4 result.color.z, ayuv.yzwx, matrix[2];\n" + "END"; + +// Paints a AYUV444 frame. +static const char *qt_arbfp_ayuvShaderProgram = + "!!ARBfp1.0\n" + "PARAM matrix[4] = { program.local[0..2]," + "{ 0.0, 0.0, 0.0, 1.0 } };\n" + "TEMP ayuv;\n" + "TEX ayuv, fragment.texcoord[0], texture[0], 2D;\n" + "MOV ayuv.x, matrix[3].w;\n" + "DP4 result.color.x, ayuv.yzwx, matrix[0];\n" + "DP4 result.color.y, ayuv.yzwx, matrix[1];\n" + "DP4 result.color.z, ayuv.yzwx, matrix[2];\n" + "TEX result.color.w, fragment.texcoord[0], texture, 2D;\n" + "END"; + +class QVideoSurfaceArbFpPainter : public QVideoSurfaceGLPainter +{ +public: + QVideoSurfaceArbFpPainter(QGLContext *context); + + QAbstractVideoSurface::Error start(const QVideoSurfaceFormat &format); + void stop(); + + QAbstractVideoSurface::Error paint( + const QRectF &target, QPainter *painter, const QRectF &source); + +private: + typedef void (APIENTRY *_glProgramStringARB) (GLenum, GLenum, GLsizei, const GLvoid *); + typedef void (APIENTRY *_glBindProgramARB) (GLenum, GLuint); + typedef void (APIENTRY *_glDeleteProgramsARB) (GLsizei, const GLuint *); + typedef void (APIENTRY *_glGenProgramsARB) (GLsizei, GLuint *); + typedef void (APIENTRY *_glProgramLocalParameter4fARB) ( + GLenum, GLuint, GLfloat, GLfloat, GLfloat, GLfloat); + typedef void (APIENTRY *_glActiveTexture) (GLenum); + + _glProgramStringARB glProgramStringARB; + _glBindProgramARB glBindProgramARB; + _glDeleteProgramsARB glDeleteProgramsARB; + _glGenProgramsARB glGenProgramsARB; + _glProgramLocalParameter4fARB glProgramLocalParameter4fARB; + + GLuint m_programId; + QSize m_frameSize; +}; + +QVideoSurfaceArbFpPainter::QVideoSurfaceArbFpPainter(QGLContext *context) + : QVideoSurfaceGLPainter(context) + , m_programId(0) +{ + glProgramStringARB = (_glProgramStringARB) m_context->getProcAddress( + QLatin1String("glProgramStringARB")); + glBindProgramARB = (_glBindProgramARB) m_context->getProcAddress( + QLatin1String("glBindProgramARB")); + glDeleteProgramsARB = (_glDeleteProgramsARB) m_context->getProcAddress( + QLatin1String("glDeleteProgramsARB")); + glGenProgramsARB = (_glGenProgramsARB) m_context->getProcAddress( + QLatin1String("glGenProgramsARB")); + glProgramLocalParameter4fARB = (_glProgramLocalParameter4fARB) m_context->getProcAddress( + QLatin1String("glProgramLocalParameter4fARB")); + + m_imagePixelFormats + << QVideoFrame::Format_RGB32 + << QVideoFrame::Format_BGR32 + << QVideoFrame::Format_ARGB32 + << QVideoFrame::Format_RGB24 + << QVideoFrame::Format_BGR24 + << QVideoFrame::Format_RGB565 + << QVideoFrame::Format_AYUV444 + << QVideoFrame::Format_YUV444 + << QVideoFrame::Format_YV12 + << QVideoFrame::Format_YUV420P; + m_glPixelFormats + << QVideoFrame::Format_RGB32 + << QVideoFrame::Format_ARGB32; +} + +QAbstractVideoSurface::Error QVideoSurfaceArbFpPainter::start(const QVideoSurfaceFormat &format) +{ + Q_ASSERT(m_textureCount == 0); + + QAbstractVideoSurface::Error error = QAbstractVideoSurface::NoError; + + m_context->makeCurrent(); + + const char *program = 0; + + if (format.handleType() == QAbstractVideoBuffer::NoHandle) { + switch (format.pixelFormat()) { + case QVideoFrame::Format_RGB32: + initRgbTextureInfo(GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE, format.frameSize()); + program = qt_arbfp_xrgbShaderProgram; + break; + case QVideoFrame::Format_BGR32: + initRgbTextureInfo(GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE, format.frameSize()); + program = qt_arbfp_rgbShaderProgram; + break; + case QVideoFrame::Format_ARGB32: + initRgbTextureInfo(GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE, format.frameSize()); + program = qt_arbfp_argbShaderProgram; + break; + case QVideoFrame::Format_RGB24: + initRgbTextureInfo(GL_RGB8, GL_RGBA, GL_UNSIGNED_BYTE, format.frameSize()); + program = qt_arbfp_rgbShaderProgram; + break; + case QVideoFrame::Format_BGR24: + initRgbTextureInfo(GL_RGB8, GL_RGBA, GL_UNSIGNED_BYTE, format.frameSize()); + program = qt_arbfp_xrgbShaderProgram; + break; + case QVideoFrame::Format_RGB565: + initRgbTextureInfo(GL_RGB, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, format.frameSize()); + program = qt_arbfp_rgbShaderProgram; + break; + case QVideoFrame::Format_YUV444: + initRgbTextureInfo(GL_RGB, GL_RGB, GL_UNSIGNED_BYTE, format.frameSize()); + program = qt_arbfp_xyuvShaderProgram; + m_yuv = true; + break; + case QVideoFrame::Format_AYUV444: + initRgbTextureInfo(GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE, format.frameSize()); + program = qt_arbfp_ayuvShaderProgram; + m_yuv = true; + break; + case QVideoFrame::Format_YV12: + initYv12TextureInfo(format.frameSize()); + program = qt_arbfp_yuvPlanarShaderProgram; + break; + case QVideoFrame::Format_YUV420P: + initYuv420PTextureInfo(format.frameSize()); + program = qt_arbfp_yuvPlanarShaderProgram; + break; + default: + break; + } + } else if (format.handleType() == QAbstractVideoBuffer::GLTextureHandle) { + switch (format.pixelFormat()) { + case QVideoFrame::Format_RGB32: + case QVideoFrame::Format_ARGB32: + m_yuv = false; + m_textureCount = 1; + program = qt_arbfp_rgbShaderProgram; + break; + default: + break; + } + } + + if (!program) { + error = QAbstractVideoSurface::UnsupportedFormatError; + } else { + glGenProgramsARB(1, &m_programId); + + GLenum glError = glGetError(); + if (glError != GL_NO_ERROR) { + qWarning("QPainterVideoSurface: ARBfb Shader allocation error %x", int(glError)); + m_textureCount = 0; + m_programId = 0; + + error = QAbstractVideoSurface::ResourceError; + } else { + glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, m_programId); + glProgramStringARB( + GL_FRAGMENT_PROGRAM_ARB, + GL_PROGRAM_FORMAT_ASCII_ARB, + qstrlen(program), + reinterpret_cast(program)); + + if ((glError = glGetError()) != GL_NO_ERROR) { + const GLubyte* errorString = glGetString(GL_PROGRAM_ERROR_STRING_ARB); + + qWarning("QPainterVideoSurface: ARBfp Shader compile error %x, %s", + int(glError), + reinterpret_cast(errorString)); + glDeleteProgramsARB(1, &m_programId); + + m_textureCount = 0; + m_programId = 0; + + error = QAbstractVideoSurface::ResourceError; + } else { + m_handleType = format.handleType(); + m_scanLineDirection = format.scanLineDirection(); + m_frameSize = format.frameSize(); + + if (m_handleType == QAbstractVideoBuffer::NoHandle) + glGenTextures(m_textureCount, m_textureIds); + } + } + } + + return error; +} + +void QVideoSurfaceArbFpPainter::stop() +{ + m_context->makeCurrent(); + + if (m_handleType != QAbstractVideoBuffer::GLTextureHandle) + glDeleteTextures(m_textureCount, m_textureIds); + glDeleteProgramsARB(1, &m_programId); + + m_textureCount = 0; + m_programId = 0; + m_handleType = QAbstractVideoBuffer::NoHandle; +} + +QAbstractVideoSurface::Error QVideoSurfaceArbFpPainter::paint( + const QRectF &target, QPainter *painter, const QRectF &source) +{ + if (m_frame.isValid()) { + bool stencilTestEnabled = glIsEnabled(GL_STENCIL_TEST); + bool scissorTestEnabled = glIsEnabled(GL_SCISSOR_TEST); + + painter->beginNativePainting(); + + if (stencilTestEnabled) + glEnable(GL_STENCIL_TEST); + if (scissorTestEnabled) + glEnable(GL_SCISSOR_TEST); + + const float txLeft = source.left() / m_frameSize.width(); + const float txRight = source.right() / m_frameSize.width(); + const float txTop = m_scanLineDirection == QVideoSurfaceFormat::TopToBottom + ? source.top() / m_frameSize.height() + : source.bottom() / m_frameSize.height(); + const float txBottom = m_scanLineDirection == QVideoSurfaceFormat::TopToBottom + ? source.bottom() / m_frameSize.height() + : source.top() / m_frameSize.height(); + + + const float tx_array[] = + { + txLeft , txBottom, + txRight, txBottom, + txLeft , txTop, + txRight, txTop + }; + const float v_array[] = + { + float(target.left()) , float(target.bottom() + 1), + float(target.right() + 1), float(target.bottom() + 1), + float(target.left()) , float(target.top()), + float(target.right() + 1), float(target.top()) + }; + + glEnable(GL_FRAGMENT_PROGRAM_ARB); + glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, m_programId); + + glProgramLocalParameter4fARB( + GL_FRAGMENT_PROGRAM_ARB, + 0, + m_colorMatrix(0, 0), + m_colorMatrix(0, 1), + m_colorMatrix(0, 2), + m_colorMatrix(0, 3)); + glProgramLocalParameter4fARB( + GL_FRAGMENT_PROGRAM_ARB, + 1, + m_colorMatrix(1, 0), + m_colorMatrix(1, 1), + m_colorMatrix(1, 2), + m_colorMatrix(1, 3)); + glProgramLocalParameter4fARB( + GL_FRAGMENT_PROGRAM_ARB, + 2, + m_colorMatrix(2, 0), + m_colorMatrix(2, 1), + m_colorMatrix(2, 2), + m_colorMatrix(2, 3)); + + glActiveTexture(GL_TEXTURE0); + glBindTexture(GL_TEXTURE_2D, m_textureIds[0]); + + if (m_textureCount == 3) { + glActiveTexture(GL_TEXTURE1); + glBindTexture(GL_TEXTURE_2D, m_textureIds[1]); + glActiveTexture(GL_TEXTURE2); + glBindTexture(GL_TEXTURE_2D, m_textureIds[2]); + glActiveTexture(GL_TEXTURE0); + } + + glVertexPointer(2, GL_FLOAT, 0, v_array); + glTexCoordPointer(2, GL_FLOAT, 0, tx_array); + + glEnableClientState(GL_VERTEX_ARRAY); + glEnableClientState(GL_TEXTURE_COORD_ARRAY); + + glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); + + glDisableClientState(GL_TEXTURE_COORD_ARRAY); + glDisableClientState(GL_VERTEX_ARRAY); + glDisable(GL_FRAGMENT_PROGRAM_ARB); + + painter->endNativePainting(); + } + return QAbstractVideoSurface::NoError; +} + +#endif + +static const char *qt_glsl_vertexShaderProgram = + "attribute highp vec4 vertexCoordArray;\n" + "attribute highp vec2 textureCoordArray;\n" + "uniform highp mat4 positionMatrix;\n" + "varying highp vec2 textureCoord;\n" + "void main(void)\n" + "{\n" + " gl_Position = positionMatrix * vertexCoordArray;\n" + " textureCoord = textureCoordArray;\n" + "}\n"; + +// Paints an RGB32 frame +static const char *qt_glsl_xrgbShaderProgram = + "uniform sampler2D texRgb;\n" + "uniform mediump mat4 colorMatrix;\n" + "varying highp vec2 textureCoord;\n" + "void main(void)\n" + "{\n" + " highp vec4 color = vec4(texture2D(texRgb, textureCoord.st).bgr, 1.0);\n" + " gl_FragColor = colorMatrix * color;\n" + "}\n"; + +// Paints an ARGB frame. +static const char *qt_glsl_argbShaderProgram = + "uniform sampler2D texRgb;\n" + "uniform mediump mat4 colorMatrix;\n" + "varying highp vec2 textureCoord;\n" + "void main(void)\n" + "{\n" + " highp vec4 color = vec4(texture2D(texRgb, textureCoord.st).bgr, 1.0);\n" + " color = colorMatrix * color;\n" + " gl_FragColor = vec4(color.rgb, texture2D(texRgb, textureCoord.st).a);\n" + "}\n"; + +// Paints an RGB(A) frame. +static const char *qt_glsl_rgbShaderProgram = + "uniform sampler2D texRgb;\n" + "uniform mediump mat4 colorMatrix;\n" + "varying highp vec2 textureCoord;\n" + "void main(void)\n" + "{\n" + " highp vec4 color = vec4(texture2D(texRgb, textureCoord.st).rgb, 1.0);\n" + " color = colorMatrix * color;\n" + " gl_FragColor = vec4(color.rgb, texture2D(texRgb, textureCoord.st).a);\n" + "}\n"; + +// Paints a YUV420P or YV12 frame. +static const char *qt_glsl_yuvPlanarShaderProgram = + "uniform sampler2D texY;\n" + "uniform sampler2D texU;\n" + "uniform sampler2D texV;\n" + "uniform mediump mat4 colorMatrix;\n" + "varying highp vec2 textureCoord;\n" + "void main(void)\n" + "{\n" + " highp vec4 color = vec4(\n" + " texture2D(texY, textureCoord.st).r,\n" + " texture2D(texU, textureCoord.st).r,\n" + " texture2D(texV, textureCoord.st).r,\n" + " 1.0);\n" + " gl_FragColor = colorMatrix * color;\n" + "}\n"; + +// Paints a YUV444 frame. +static const char *qt_glsl_xyuvShaderProgram = + "uniform sampler2D texRgb;\n" + "uniform mediump mat4 colorMatrix;\n" + "varying highp vec2 textureCoord;\n" + "void main(void)\n" + "{\n" + " highp vec4 color = vec4(texture2D(texRgb, textureCoord.st).gba, 1.0);\n" + " gl_FragColor = colorMatrix * color;\n" + "}\n"; + +// Paints a AYUV444 frame. +static const char *qt_glsl_ayuvShaderProgram = + "uniform sampler2D texRgb;\n" + "uniform mediump mat4 colorMatrix;\n" + "varying highp vec2 textureCoord;\n" + "void main(void)\n" + "{\n" + " highp vec4 color = vec4(texture2D(texRgb, textureCoord.st).gba, 1.0);\n" + " color = colorMatrix * color;\n" + " gl_FragColor = vec4(color.rgb, texture2D(texRgb, textureCoord.st).r);\n" + "}\n"; + +class QVideoSurfaceGlslPainter : public QVideoSurfaceGLPainter +{ +public: + QVideoSurfaceGlslPainter(QGLContext *context); + + QAbstractVideoSurface::Error start(const QVideoSurfaceFormat &format); + void stop(); + + QAbstractVideoSurface::Error paint( + const QRectF &target, QPainter *painter, const QRectF &source); + +private: + QGLShaderProgram m_program; + QSize m_frameSize; +}; + +QVideoSurfaceGlslPainter::QVideoSurfaceGlslPainter(QGLContext *context) + : QVideoSurfaceGLPainter(context) + , m_program(context) +{ + m_imagePixelFormats + << QVideoFrame::Format_RGB32 + << QVideoFrame::Format_BGR32 + << QVideoFrame::Format_ARGB32 +#ifndef QT_OPENGL_ES + << QVideoFrame::Format_RGB24 + << QVideoFrame::Format_BGR24 +#endif + << QVideoFrame::Format_RGB565 + << QVideoFrame::Format_YUV444 + << QVideoFrame::Format_AYUV444 + << QVideoFrame::Format_YV12 + << QVideoFrame::Format_YUV420P; + m_glPixelFormats + << QVideoFrame::Format_RGB32 + << QVideoFrame::Format_ARGB32; +} + +QAbstractVideoSurface::Error QVideoSurfaceGlslPainter::start(const QVideoSurfaceFormat &format) +{ + Q_ASSERT(m_textureCount == 0); + + QAbstractVideoSurface::Error error = QAbstractVideoSurface::NoError; + + m_context->makeCurrent(); + + const char *fragmentProgram = 0; + + if (format.handleType() == QAbstractVideoBuffer::NoHandle) { + switch (format.pixelFormat()) { + case QVideoFrame::Format_RGB32: + initRgbTextureInfo(GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE, format.frameSize()); + fragmentProgram = qt_glsl_xrgbShaderProgram; + break; + case QVideoFrame::Format_BGR32: + initRgbTextureInfo(GL_RGB, GL_RGBA, GL_UNSIGNED_BYTE, format.frameSize()); + fragmentProgram = qt_glsl_rgbShaderProgram; + break; + case QVideoFrame::Format_ARGB32: + initRgbTextureInfo(GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE, format.frameSize()); + fragmentProgram = qt_glsl_argbShaderProgram; + break; +#ifndef QT_OPENGL_ES + case QVideoFrame::Format_RGB24: + initRgbTextureInfo(GL_RGB8, GL_RGB, GL_UNSIGNED_BYTE, format.frameSize()); + fragmentProgram = qt_glsl_rgbShaderProgram; + break; + case QVideoFrame::Format_BGR24: + initRgbTextureInfo(GL_RGB8, GL_RGB, GL_UNSIGNED_BYTE, format.frameSize()); + fragmentProgram = qt_glsl_argbShaderProgram; + break; +#endif + case QVideoFrame::Format_RGB565: + initRgbTextureInfo(GL_RGB, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, format.frameSize()); + fragmentProgram = qt_glsl_rgbShaderProgram; + break; + case QVideoFrame::Format_YUV444: + initRgbTextureInfo(GL_RGB, GL_RGB, GL_UNSIGNED_BYTE, format.frameSize()); + fragmentProgram = qt_glsl_xyuvShaderProgram; + m_yuv = true; + break; + case QVideoFrame::Format_AYUV444: + initRgbTextureInfo(GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE, format.frameSize()); + fragmentProgram = qt_glsl_ayuvShaderProgram; + m_yuv = true; + break; + case QVideoFrame::Format_YV12: + initYv12TextureInfo(format.frameSize()); + fragmentProgram = qt_glsl_yuvPlanarShaderProgram; + break; + case QVideoFrame::Format_YUV420P: + initYuv420PTextureInfo(format.frameSize()); + fragmentProgram = qt_glsl_yuvPlanarShaderProgram; + break; + default: + break; + } + } else if (format.handleType() == QAbstractVideoBuffer::GLTextureHandle) { + switch (format.pixelFormat()) { + case QVideoFrame::Format_RGB32: + case QVideoFrame::Format_ARGB32: + m_yuv = false; + m_textureCount = 1; + fragmentProgram = qt_glsl_rgbShaderProgram; + break; + default: + break; + } + } + + if (!fragmentProgram) { + error = QAbstractVideoSurface::UnsupportedFormatError; + } else if (!m_program.addShaderFromSourceCode(QGLShader::Vertex, qt_glsl_vertexShaderProgram)) { + qWarning("QPainterVideoSurface: Vertex shader compile error %s", + qPrintable(m_program.log())); + error = QAbstractVideoSurface::ResourceError; + } else if (!m_program.addShaderFromSourceCode(QGLShader::Fragment, fragmentProgram)) { + qWarning("QPainterVideoSurface: Shader compile error %s", qPrintable(m_program.log())); + error = QAbstractVideoSurface::ResourceError; + m_program.removeAllShaders(); + } else if(!m_program.link()) { + qWarning("QPainterVideoSurface: Shader link error %s", qPrintable(m_program.log())); + m_program.removeAllShaders(); + error = QAbstractVideoSurface::ResourceError; + } else { + m_handleType = format.handleType(); + m_scanLineDirection = format.scanLineDirection(); + m_frameSize = format.frameSize(); + + if (m_handleType == QAbstractVideoBuffer::NoHandle) + glGenTextures(m_textureCount, m_textureIds); + } + + return error; +} + +void QVideoSurfaceGlslPainter::stop() +{ + m_context->makeCurrent(); + + if (m_handleType != QAbstractVideoBuffer::GLTextureHandle) + glDeleteTextures(m_textureCount, m_textureIds); + m_program.removeAllShaders(); + + m_textureCount = 0; + m_handleType = QAbstractVideoBuffer::NoHandle; +} + +QAbstractVideoSurface::Error QVideoSurfaceGlslPainter::paint( + const QRectF &target, QPainter *painter, const QRectF &source) +{ + if (m_frame.isValid()) { + bool stencilTestEnabled = glIsEnabled(GL_STENCIL_TEST); + bool scissorTestEnabled = glIsEnabled(GL_SCISSOR_TEST); + + painter->beginNativePainting(); + + if (stencilTestEnabled) + glEnable(GL_STENCIL_TEST); + if (scissorTestEnabled) + glEnable(GL_SCISSOR_TEST); + + const int width = QGLContext::currentContext()->device()->width(); + const int height = QGLContext::currentContext()->device()->height(); + + const QTransform transform = painter->deviceTransform(); + + const GLfloat wfactor = 2.0 / width; + const GLfloat hfactor = -2.0 / height; + + const GLfloat positionMatrix[4][4] = + { + { + /*(0,0)*/ GLfloat(wfactor * transform.m11() - transform.m13()), + /*(0,1)*/ GLfloat(hfactor * transform.m12() + transform.m13()), + /*(0,2)*/ 0.0, + /*(0,3)*/ GLfloat(transform.m13()) + }, { + /*(1,0)*/ GLfloat(wfactor * transform.m21() - transform.m23()), + /*(1,1)*/ GLfloat(hfactor * transform.m22() + transform.m23()), + /*(1,2)*/ 0.0, + /*(1,3)*/ GLfloat(transform.m23()) + }, { + /*(2,0)*/ 0.0, + /*(2,1)*/ 0.0, + /*(2,2)*/ -1.0, + /*(2,3)*/ 0.0 + }, { + /*(3,0)*/ GLfloat(wfactor * transform.dx() - transform.m33()), + /*(3,1)*/ GLfloat(hfactor * transform.dy() + transform.m33()), + /*(3,2)*/ 0.0, + /*(3,3)*/ GLfloat(transform.m33()) + } + }; + + const GLfloat vertexCoordArray[] = + { + GLfloat(target.left()) , GLfloat(target.bottom() + 1), + GLfloat(target.right() + 1), GLfloat(target.bottom() + 1), + GLfloat(target.left()) , GLfloat(target.top()), + GLfloat(target.right() + 1), GLfloat(target.top()) + }; + + const GLfloat txLeft = source.left() / m_frameSize.width(); + const GLfloat txRight = source.right() / m_frameSize.width(); + const GLfloat txTop = m_scanLineDirection == QVideoSurfaceFormat::TopToBottom + ? source.top() / m_frameSize.height() + : source.bottom() / m_frameSize.height(); + const GLfloat txBottom = m_scanLineDirection == QVideoSurfaceFormat::TopToBottom + ? source.bottom() / m_frameSize.height() + : source.top() / m_frameSize.height(); + + const GLfloat textureCoordArray[] = + { + txLeft , txBottom, + txRight, txBottom, + txLeft , txTop, + txRight, txTop + }; + + m_program.bind(); + + m_program.enableAttributeArray("vertexCoordArray"); + m_program.enableAttributeArray("textureCoordArray"); + m_program.setAttributeArray("vertexCoordArray", vertexCoordArray, 2); + m_program.setAttributeArray("textureCoordArray", textureCoordArray, 2); + m_program.setUniformValue("positionMatrix", positionMatrix); + + if (m_textureCount == 3) { + glActiveTexture(GL_TEXTURE0); + glBindTexture(GL_TEXTURE_2D, m_textureIds[0]); + glActiveTexture(GL_TEXTURE1); + glBindTexture(GL_TEXTURE_2D, m_textureIds[1]); + glActiveTexture(GL_TEXTURE2); + glBindTexture(GL_TEXTURE_2D, m_textureIds[2]); + glActiveTexture(GL_TEXTURE0); + + m_program.setUniformValue("texY", GLint(0)); + m_program.setUniformValue("texU", GLint(1)); + m_program.setUniformValue("texV", GLint(2)); + } else { + glActiveTexture(GL_TEXTURE0); + glBindTexture(GL_TEXTURE_2D, m_textureIds[0]); + + m_program.setUniformValue("texRgb", GLint(0)); + } + m_program.setUniformValue("colorMatrix", m_colorMatrix); + + glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); + + m_program.release(); + + painter->endNativePainting(); + } + return QAbstractVideoSurface::NoError; +} + +#endif + +/*! + \class QPainterVideoSurface + \internal +*/ + +/*! +*/ +QPainterVideoSurface::QPainterVideoSurface(QObject *parent) + : QAbstractVideoSurface(parent) + , m_painter(0) +#if !defined(QT_NO_OPENGL) && !defined(QT_OPENGL_ES_1_CL) && !defined(QT_OPENGL_ES_1) + , m_glContext(0) + , m_shaderTypes(NoShaders) + , m_shaderType(NoShaders) +#endif + , m_brightness(0) + , m_contrast(0) + , m_hue(0) + , m_saturation(0) + , m_pixelFormat(QVideoFrame::Format_Invalid) + , m_colorsDirty(true) + , m_ready(false) +{ +} + +/*! +*/ +QPainterVideoSurface::~QPainterVideoSurface() +{ + if (isActive()) + m_painter->stop(); + + delete m_painter; +} + +/*! +*/ +QList QPainterVideoSurface::supportedPixelFormats( + QAbstractVideoBuffer::HandleType handleType) const +{ + if (!m_painter) + const_cast(this)->createPainter(); + + return m_painter->supportedPixelFormats(handleType); +} + +/*! +*/ +bool QPainterVideoSurface::isFormatSupported( + const QVideoSurfaceFormat &format, QVideoSurfaceFormat *similar) const +{ + if (!m_painter) + const_cast(this)->createPainter(); + + return m_painter->isFormatSupported(format, similar); +} + +/*! +*/ +bool QPainterVideoSurface::start(const QVideoSurfaceFormat &format) +{ + if (isActive()) + m_painter->stop(); + + if (!m_painter) + createPainter(); + + if (format.frameSize().isEmpty()) { + setError(UnsupportedFormatError); + } else { + QAbstractVideoSurface::Error error = m_painter->start(format); + + if (error != QAbstractVideoSurface::NoError) { + setError(error); + } else { + m_pixelFormat = format.pixelFormat(); + m_frameSize = format.frameSize(); + m_sourceRect = format.viewport(); + m_colorsDirty = true; + m_ready = true; + + return QAbstractVideoSurface::start(format); + } + } + + QAbstractVideoSurface::stop(); + + return false; +} + +/*! +*/ +void QPainterVideoSurface::stop() +{ + if (isActive()) { + m_painter->stop(); + m_ready = false; + + QAbstractVideoSurface::stop(); + } +} + +/*! +*/ +bool QPainterVideoSurface::present(const QVideoFrame &frame) +{ + if (!m_ready) { + if (!isActive()) + setError(StoppedError); + } else if (frame.isValid() + && (frame.pixelFormat() != m_pixelFormat || frame.size() != m_frameSize)) { + setError(IncorrectFormatError); + + stop(); + } else { + QAbstractVideoSurface::Error error = m_painter->setCurrentFrame(frame); + + if (error != QAbstractVideoSurface::NoError) { + setError(error); + + stop(); + } else { + m_ready = false; + + emit frameChanged(); + + return true; + } + } + return false; +} + +/*! +*/ +int QPainterVideoSurface::brightness() const +{ + return m_brightness; +} + +/*! +*/ +void QPainterVideoSurface::setBrightness(int brightness) +{ + m_brightness = brightness; + + m_colorsDirty = true; +} + +/*! +*/ +int QPainterVideoSurface::contrast() const +{ + return m_contrast; +} + +/*! +*/ +void QPainterVideoSurface::setContrast(int contrast) +{ + m_contrast = contrast; + + m_colorsDirty = true; +} + +/*! +*/ +int QPainterVideoSurface::hue() const +{ + return m_hue; +} + +/*! +*/ +void QPainterVideoSurface::setHue(int hue) +{ + m_hue = hue; + + m_colorsDirty = true; +} + +/*! +*/ +int QPainterVideoSurface::saturation() const +{ + return m_saturation; +} + +/*! +*/ +void QPainterVideoSurface::setSaturation(int saturation) +{ + m_saturation = saturation; + + m_colorsDirty = true; +} + +/*! +*/ +bool QPainterVideoSurface::isReady() const +{ + return m_ready; +} + +/*! +*/ +void QPainterVideoSurface::setReady(bool ready) +{ + m_ready = ready; +} + +/*! +*/ +void QPainterVideoSurface::paint(QPainter *painter, const QRectF &target, const QRectF &source) +{ + if (!isActive()) { + painter->fillRect(target, QBrush(Qt::black)); + } else { + if (m_colorsDirty) { + m_painter->updateColors(m_brightness, m_contrast, m_hue, m_saturation); + m_colorsDirty = false; + } + + const QRectF sourceRect( + m_sourceRect.x() + m_sourceRect.width() * source.x(), + m_sourceRect.y() + m_sourceRect.height() * source.y(), + m_sourceRect.width() * source.width(), + m_sourceRect.height() * source.height()); + + QAbstractVideoSurface::Error error = m_painter->paint(target, painter, sourceRect); + + if (error != QAbstractVideoSurface::NoError) { + setError(error); + + stop(); + } + } +} + +/*! + \fn QPainterVideoSurface::frameChanged() +*/ + +#if !defined(QT_NO_OPENGL) && !defined(QT_OPENGL_ES_1_CL) && !defined(QT_OPENGL_ES_1) + +/*! +*/ +const QGLContext *QPainterVideoSurface::glContext() const +{ + return m_glContext; +} + +/*! +*/ +void QPainterVideoSurface::setGLContext(QGLContext *context) +{ + if (m_glContext == context) + return; + + m_glContext = context; + + m_shaderTypes = NoShaders; + + if (m_glContext) { + m_glContext->makeCurrent(); + + const QByteArray extensions(reinterpret_cast(glGetString(GL_EXTENSIONS))); +#ifndef QT_OPENGL_ES + + if (extensions.contains("ARB_fragment_program")) + m_shaderTypes |= FragmentProgramShader; +#endif + + if (QGLShaderProgram::hasOpenGLShaderPrograms(m_glContext) + && extensions.contains("ARB_shader_objects")) + m_shaderTypes |= GlslShader; + } + + ShaderType type = (m_shaderType & m_shaderTypes) + ? m_shaderType + : NoShaders; + + if (type != m_shaderType || type != NoShaders) { + m_shaderType = type; + + if (isActive()) { + m_painter->stop(); + delete m_painter; + m_painter = 0; + m_ready = false; + + setError(ResourceError); + QAbstractVideoSurface::stop(); + } + emit supportedFormatsChanged(); + } +} + +/*! + \enum QPainterVideoSurface::ShaderType + + \value NoShaders + \value FragmentProgramShader + \value HlslShader +*/ + +/*! + \typedef QPainterVideoSurface::ShaderTypes +*/ + +/*! +*/ +QPainterVideoSurface::ShaderTypes QPainterVideoSurface::supportedShaderTypes() const +{ + return m_shaderTypes; +} + +/*! +*/ +QPainterVideoSurface::ShaderType QPainterVideoSurface::shaderType() const +{ + return m_shaderType; +} + +/*! +*/ +void QPainterVideoSurface::setShaderType(ShaderType type) +{ + if (!(type & m_shaderTypes)) + type = NoShaders; + + if (type != m_shaderType) { + m_shaderType = type; + + if (isActive()) { + m_painter->stop(); + delete m_painter; + m_painter = 0; + m_ready = false; + + setError(ResourceError); + QAbstractVideoSurface::stop(); + } else { + delete m_painter; + m_painter = 0; + } + emit supportedFormatsChanged(); + } +} + +#endif + +void QPainterVideoSurface::createPainter() +{ + Q_ASSERT(!m_painter); + +#ifdef Q_WS_MAC + if (m_glContext) + m_glContext->makeCurrent(); + + m_painter = new QVideoSurfaceCoreGraphicsPainter(m_glContext != 0); + return; +#endif + +#if !defined(QT_NO_OPENGL) && !defined(QT_OPENGL_ES_1_CL) && !defined(QT_OPENGL_ES_1) + switch (m_shaderType) { +#ifndef QT_OPENGL_ES + case FragmentProgramShader: + Q_ASSERT(m_glContext); + m_glContext->makeCurrent(); + m_painter = new QVideoSurfaceArbFpPainter(m_glContext); + break; +#endif + case GlslShader: + Q_ASSERT(m_glContext); + m_glContext->makeCurrent(); + m_painter = new QVideoSurfaceGlslPainter(m_glContext); + break; + default: + m_painter = new QVideoSurfaceRasterPainter; + break; + } +#else + m_painter = new QVideoSurfaceRasterPainter; +#endif +} + +QT_END_NAMESPACE + +#include "moc_qpaintervideosurface_p.cpp" + + diff --git a/src/multimedia/mediaservices/base/qpaintervideosurface_mac.mm b/src/multimedia/mediaservices/base/qpaintervideosurface_mac.mm new file mode 100644 index 0000000..1154f86 --- /dev/null +++ b/src/multimedia/mediaservices/base/qpaintervideosurface_mac.mm @@ -0,0 +1,283 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtMultimedia module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qpaintervideosurface_mac_p.h" + +#include + +#include + +#include +#include +#include + +#include + +#include +#include +#include + +QT_BEGIN_NAMESPACE + +extern CGContextRef qt_mac_cg_context(const QPaintDevice *pdev); //qpaintdevice_mac.cpp + +QVideoSurfaceCoreGraphicsPainter::QVideoSurfaceCoreGraphicsPainter(bool glSupported) + : ciContext(0) + , m_imageFormat(QImage::Format_Invalid) + , m_scanLineDirection(QVideoSurfaceFormat::TopToBottom) +{ + //qDebug() << "QVideoSurfaceCoreGraphicsPainter, GL supported:" << glSupported; + ciContext = 0; + m_imagePixelFormats + << QVideoFrame::Format_RGB32; + + m_supportedHandles + << QAbstractVideoBuffer::NoHandle + << QAbstractVideoBuffer::CoreImageHandle; + + if (glSupported) + m_supportedHandles << QAbstractVideoBuffer::GLTextureHandle; +} + +QVideoSurfaceCoreGraphicsPainter::~QVideoSurfaceCoreGraphicsPainter() +{ + [(CIContext*)ciContext release]; +} + +QList QVideoSurfaceCoreGraphicsPainter::supportedPixelFormats( + QAbstractVideoBuffer::HandleType handleType) const +{ + return m_supportedHandles.contains(handleType) + ? m_imagePixelFormats + : QList(); +} + +bool QVideoSurfaceCoreGraphicsPainter::isFormatSupported( + const QVideoSurfaceFormat &format, QVideoSurfaceFormat *) const +{ + return m_supportedHandles.contains(format.handleType()) + && m_imagePixelFormats.contains(format.pixelFormat()) + && !format.frameSize().isEmpty(); +} + +QAbstractVideoSurface::Error QVideoSurfaceCoreGraphicsPainter::start(const QVideoSurfaceFormat &format) +{ + m_frame = QVideoFrame(); + m_imageFormat = QVideoFrame::imageFormatFromPixelFormat(format.pixelFormat()); + m_imageSize = format.frameSize(); + m_scanLineDirection = format.scanLineDirection(); + + return m_supportedHandles.contains(format.handleType()) + && m_imageFormat != QImage::Format_Invalid + && !m_imageSize.isEmpty() + ? QAbstractVideoSurface::NoError + : QAbstractVideoSurface::UnsupportedFormatError; +} + +void QVideoSurfaceCoreGraphicsPainter::stop() +{ + m_frame = QVideoFrame(); +} + +QAbstractVideoSurface::Error QVideoSurfaceCoreGraphicsPainter::setCurrentFrame(const QVideoFrame &frame) +{ + m_frame = frame; + + return QAbstractVideoSurface::NoError; +} + +QAbstractVideoSurface::Error QVideoSurfaceCoreGraphicsPainter::paint( + const QRectF &target, QPainter *painter, const QRectF &source) +{ + if (m_frame.handleType() == QAbstractVideoBuffer::CoreImageHandle) { + if (painter->paintEngine()->type() == QPaintEngine::CoreGraphics ) { + + CIImage *img = (CIImage*)(m_frame.handle().value()); + + if (img) { + CGContextRef cgContext = qt_mac_cg_context(painter->device()); + + if (cgContext) { + painter->beginNativePainting(); + + CGRect sRect = CGRectMake(source.x(), source.y(), source.width(), source.height()); + CGRect dRect = CGRectMake(target.x(), target.y(), target.width(), target.height()); + + NSBitmapImageRep *bitmap = [[NSBitmapImageRep alloc] initWithCIImage:img]; + + if (m_scanLineDirection == QVideoSurfaceFormat::TopToBottom) { + CGContextSaveGState( cgContext ); + CGContextTranslateCTM(cgContext, 0, dRect.origin.y + CGRectGetMaxY(dRect)); + CGContextScaleCTM(cgContext, 1, -1); + +#if (MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_4) + if (QSysInfo::MacintoshVersion > QSysInfo::MV_10_4) { + CGContextDrawImage(cgContext, dRect, [bitmap CGImage]); + } +#endif + + CGContextRestoreGState(cgContext); + } else { +#if (MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_4) + if (QSysInfo::MacintoshVersion > QSysInfo::MV_10_4) { + CGContextDrawImage(cgContext, dRect, [bitmap CGImage]); + } +#endif + } + + [bitmap release]; + + painter->endNativePainting(); + + return QAbstractVideoSurface::NoError; + } + } + } else if (painter->paintEngine()->type() == QPaintEngine::OpenGL2 || + painter->paintEngine()->type() == QPaintEngine::OpenGL) { + CIImage *img = (CIImage*)(m_frame.handle().value()); + + if (img) { + CGLContextObj cglContext = CGLGetCurrentContext(); + + if (cglContext) { + + if (!ciContext) { + CGLContextObj cglContext = CGLGetCurrentContext(); + NSOpenGLPixelFormat *nsglPixelFormat = [NSOpenGLView defaultPixelFormat]; + CGLPixelFormatObj cglPixelFormat = static_cast([nsglPixelFormat CGLPixelFormatObj]); + + ciContext = [CIContext contextWithCGLContext:cglContext + pixelFormat:cglPixelFormat + options:nil]; + + [(CIContext*)ciContext retain]; + } + + CGRect sRect = CGRectMake(source.x(), source.y(), source.width(), source.height()); + CGRect dRect = m_scanLineDirection == QVideoSurfaceFormat::TopToBottom ? + CGRectMake(target.x(), target.y()+target.height(), target.width(), -target.height()) : + CGRectMake(target.x(), target.y(), target.width(), target.height()); + + + painter->beginNativePainting(); + + [(CIContext*)ciContext drawImage:img inRect:dRect fromRect:sRect]; + + painter->endNativePainting(); + + return QAbstractVideoSurface::NoError; + } + } + } + } + + if (m_frame.handleType() == QAbstractVideoBuffer::GLTextureHandle && + (painter->paintEngine()->type() == QPaintEngine::OpenGL2 || + painter->paintEngine()->type() == QPaintEngine::OpenGL)) { + + painter->beginNativePainting(); + GLuint texture = m_frame.handle().toUInt(); + + glDisable(GL_CULL_FACE); + glEnable(GL_TEXTURE_2D); + + glBindTexture(GL_TEXTURE_2D, texture); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + + const float txLeft = source.left() / m_frame.width(); + const float txRight = source.right() / m_frame.width(); + const float txTop = m_scanLineDirection == QVideoSurfaceFormat::TopToBottom + ? source.top() / m_frame.height() + : source.bottom() / m_frame.height(); + const float txBottom = m_scanLineDirection == QVideoSurfaceFormat::TopToBottom + ? source.bottom() / m_frame.height() + : source.top() / m_frame.height(); + + glBegin(GL_QUADS); + QRectF rect = target; + glTexCoord2f(txLeft, txBottom); + glVertex2f(rect.topLeft().x(), rect.topLeft().y()); + glTexCoord2f(txRight, txBottom); + glVertex2f(rect.topRight().x() + 1, rect.topRight().y()); + glTexCoord2f(txRight, txTop); + glVertex2f(rect.bottomRight().x() + 1, rect.bottomRight().y() + 1); + glTexCoord2f(txLeft, txTop); + glVertex2f(rect.bottomLeft().x(), rect.bottomLeft().y() + 1); + glEnd(); + painter->endNativePainting(); + + return QAbstractVideoSurface::NoError; + } + + //fallback case, software rendering + if (m_frame.map(QAbstractVideoBuffer::ReadOnly)) { + QImage image( + m_frame.bits(), + m_imageSize.width(), + m_imageSize.height(), + m_frame.bytesPerLine(), + m_imageFormat); + + if (m_scanLineDirection == QVideoSurfaceFormat::BottomToTop) { + const QTransform oldTransform = painter->transform(); + + painter->scale(1, -1); + painter->translate(0, -target.bottom()); + painter->drawImage( + QRectF(target.x(), 0, target.width(), target.height()), image, source); + painter->setTransform(oldTransform); + } else { + painter->drawImage(target, image, source); + } + + m_frame.unmap(); + } else { + painter->fillRect(target, Qt::black); + } + return QAbstractVideoSurface::NoError; +} + +void QVideoSurfaceCoreGraphicsPainter::updateColors(int, int, int, int) +{ +} + +QT_END_NAMESPACE diff --git a/src/multimedia/mediaservices/base/qpaintervideosurface_mac_p.h b/src/multimedia/mediaservices/base/qpaintervideosurface_mac_p.h new file mode 100644 index 0000000..13c22c2 --- /dev/null +++ b/src/multimedia/mediaservices/base/qpaintervideosurface_mac_p.h @@ -0,0 +1,100 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtMediaservices module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QPAINTERVIDEOSURFACE_MAC_P_H +#define QPAINTERVIDEOSURFACE_MAC_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include "qpaintervideosurface_p.h" +#include +#include + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +class QVideoSurfaceCoreGraphicsPainter : public QVideoSurfacePainter +{ +public: + QVideoSurfaceCoreGraphicsPainter(bool glSupported); + ~QVideoSurfaceCoreGraphicsPainter(); + + QList supportedPixelFormats( + QAbstractVideoBuffer::HandleType handleType) const; + + bool isFormatSupported( + const QVideoSurfaceFormat &format, QVideoSurfaceFormat *similar) const; + + QAbstractVideoSurface::Error start(const QVideoSurfaceFormat &format); + void stop(); + + QAbstractVideoSurface::Error setCurrentFrame(const QVideoFrame &frame); + + QAbstractVideoSurface::Error paint( + const QRectF &target, QPainter *painter, const QRectF &source); + + void updateColors(int brightness, int contrast, int hue, int saturation); + +private: + void* ciContext; + QList m_imagePixelFormats; + QVideoFrame m_frame; + QSize m_imageSize; + QImage::Format m_imageFormat; + QVector m_supportedHandles; + QVideoSurfaceFormat::Direction m_scanLineDirection; +}; + +QT_END_NAMESPACE + +QT_END_HEADER + +#endif diff --git a/src/multimedia/mediaservices/base/qpaintervideosurface_p.h b/src/multimedia/mediaservices/base/qpaintervideosurface_p.h new file mode 100644 index 0000000..de9c24a --- /dev/null +++ b/src/multimedia/mediaservices/base/qpaintervideosurface_p.h @@ -0,0 +1,178 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtMediaservices module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QPAINTERVIDEOSURFACE_P_H +#define QPAINTERVIDEOSURFACE_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include +#include +#include +#include +#include +#include + + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +class QGLContext; + +class QVideoSurfacePainter +{ +public: + virtual ~QVideoSurfacePainter(); + + virtual QList supportedPixelFormats( + QAbstractVideoBuffer::HandleType handleType) const = 0; + + virtual bool isFormatSupported( + const QVideoSurfaceFormat &format, QVideoSurfaceFormat *similar) const = 0; + + virtual QAbstractVideoSurface::Error start(const QVideoSurfaceFormat &format) = 0; + virtual void stop() = 0; + + virtual QAbstractVideoSurface::Error setCurrentFrame(const QVideoFrame &frame) = 0; + + virtual QAbstractVideoSurface::Error paint( + const QRectF &target, QPainter *painter, const QRectF &source) = 0; + + virtual void updateColors(int brightness, int contrast, int hue, int saturation) = 0; +}; + +class Q_MULTIMEDIA_EXPORT QPainterVideoSurface : public QAbstractVideoSurface +{ + Q_OBJECT +public: + explicit QPainterVideoSurface(QObject *parent = 0); + ~QPainterVideoSurface(); + + QList supportedPixelFormats( + QAbstractVideoBuffer::HandleType handleType = QAbstractVideoBuffer::NoHandle) const; + + bool isFormatSupported( + const QVideoSurfaceFormat &format, QVideoSurfaceFormat *similar = 0) const; + + bool start(const QVideoSurfaceFormat &format); + void stop(); + + bool present(const QVideoFrame &frame); + + int brightness() const; + void setBrightness(int brightness); + + int contrast() const; + void setContrast(int contrast); + + int hue() const; + void setHue(int hue); + + int saturation() const; + void setSaturation(int saturation); + + bool isReady() const; + void setReady(bool ready); + + void paint(QPainter *painter, const QRectF &target, const QRectF &source = QRectF(0, 0, 1, 1)); + +#if !defined(QT_NO_OPENGL) && !defined(QT_OPENGL_ES_1_CL) && !defined(QT_OPENGL_ES_1) + const QGLContext *glContext() const; + void setGLContext(QGLContext *context); + + enum ShaderType + { + NoShaders = 0x00, + FragmentProgramShader = 0x01, + GlslShader = 0x02 + }; + + Q_DECLARE_FLAGS(ShaderTypes, ShaderType) + + ShaderTypes supportedShaderTypes() const; + + ShaderType shaderType() const; + void setShaderType(ShaderType type); +#endif + +Q_SIGNALS: + void frameChanged(); + +private: + void createPainter(); + + QVideoSurfacePainter *m_painter; +#if !defined(QT_NO_OPENGL) && !defined(QT_OPENGL_ES_1_CL) && !defined(QT_OPENGL_ES_1) + QGLContext *m_glContext; + ShaderTypes m_shaderTypes; + ShaderType m_shaderType; +#endif + int m_brightness; + int m_contrast; + int m_hue; + int m_saturation; + + QVideoFrame::PixelFormat m_pixelFormat; + QSize m_frameSize; + QRect m_sourceRect; + bool m_colorsDirty; + bool m_ready; +}; + +#if !defined(QT_NO_OPENGL) && !defined(QT_OPENGL_ES_1_CL) && !defined(QT_OPENGL_ES_1) +Q_DECLARE_OPERATORS_FOR_FLAGS(QPainterVideoSurface::ShaderTypes) +#endif + +QT_END_NAMESPACE + +QT_END_HEADER + +#endif diff --git a/src/multimedia/mediaservices/base/qtmedianamespace.h b/src/multimedia/mediaservices/base/qtmedianamespace.h new file mode 100644 index 0000000..7db7aa8 --- /dev/null +++ b/src/multimedia/mediaservices/base/qtmedianamespace.h @@ -0,0 +1,194 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtMediaservices module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QTMEDIANAMESPACE_H +#define QTMEDIANAMESPACE_H + +#include +#include + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Multimedia) + +namespace QtMediaservices +{ + enum MetaData + { + // Common + Title, + SubTitle, + Author, + Comment, + Description, + Category, + Genre, + Year, + Date, + UserRating, + Keywords, + Language, + Publisher, + Copyright, + ParentalRating, + RatingOrganisation, + + // Media + Size, + MediaType, + Duration, + + // Audio + AudioBitRate, + AudioCodec, + AverageLevel, + ChannelCount, + PeakValue, + SampleRate, + + // Music + AlbumTitle, + AlbumArtist, + ContributingArtist, + Composer, + Conductor, + Lyrics, + Mood, + TrackNumber, + TrackCount, + + CoverArtUrlSmall, + CoverArtUrlLarge, + + // Image/Video + Resolution, + PixelAspectRatio, + + // Video + VideoFrameRate, + VideoBitRate, + VideoCodec, + + PosterUrl, + + // Movie + ChapterNumber, + Director, + LeadPerformer, + Writer, + + // Photos + CameraManufacturer, + CameraModel, + Event, + Subject, + Orientation, + ExposureTime, + FNumber, + ExposureProgram, + ISOSpeedRatings, + ExposureBiasValue, + DateTimeOriginal, + DateTimeDigitized, + SubjectDistance, + MeteringMode, + LightSource, + Flash, + FocalLength, + ExposureMode, + WhiteBalance, + DigitalZoomRatio, + FocalLengthIn35mmFilm, + SceneCaptureType, + GainControl, + Contrast, + Saturation, + Sharpness, + DeviceSettingDescription, + + PosterImage, + CoverArtImage, + ThumbnailImage + + }; + + enum SupportEstimate + { + NotSupported, + MaybeSupported, + ProbablySupported, + PreferredService + }; + + enum EncodingQuality + { + VeryLowQuality, + LowQuality, + NormalQuality, + HighQuality, + VeryHighQuality + }; + + enum EncodingMode + { + ConstantQualityEncoding, + ConstantBitRateEncoding, + AverageBitRateEncoding, + TwoPassEncoding + }; + + enum AvailabilityError + { + NoError, + ServiceMissingError, + BusyError, + ResourceError + }; + +} + +QT_END_NAMESPACE + +QT_END_HEADER + +#endif diff --git a/src/multimedia/mediaservices/base/qtmedianamespace.qdoc b/src/multimedia/mediaservices/base/qtmedianamespace.qdoc new file mode 100644 index 0000000..277b1a5 --- /dev/null +++ b/src/multimedia/mediaservices/base/qtmedianamespace.qdoc @@ -0,0 +1,214 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtMultimedia module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +/*! + \namespace QtMultimedia + \ingroup multimedia + + \brief The QtMultimedia namespace contains miscellaneous identifiers used + throughout the Qt Multimedia library. +*/ + +/*! + \enum QtMultimedia::MetaData + + This enum provides identifiers for meta-data attributes. + + Common attributes + \value Title The title of the media. QString. + \value SubTitle The sub-title of the media. QString. + \value Author The authors of the media. QStringList. + \value Comment A user comment about the media. QString. + \value Description A description of the media. QString + \value Category The category of the media. QStringList. + \value Genre The genre of the media. QStringList. + \value Year The year of release of the media. int. + \value Date The date of the media. QDate. + \value UserRating A user rating of the media. int [0..100]. + \value Keywords A list of keywords describing the media. QStringList. + \value Language The language of media, as an ISO 639-2 code. + + \value Publisher The publisher of the media. QString. + \value Copyright The media's copyright notice. QString. + \value ParentalRating The parental rating of the media. QString. + \value RatingOrganisation The organisation responsible for the parental rating of the media. + QString. + + Media attributes + \value Size The size in bytes of the media. qint64 + \value MediaType The type of the media (audio, video, etc). QString. + \value Duration The duration in millseconds of the media. qint64. + + Audio attributes + \value AudioBitRate The bit rate of the media's audio stream in bits per second. int. + \value AudioCodec The codec of the media's audio stream. QString. + \value AverageLevel The average volume level of the media. int. + \value ChannelCount The number of channels in the media's audio stream. int. + \value PeakValue The peak volume of the media's audio stream. int + \value SampleRate The sample rate of the media's audio stream in hertz. int + + Music attributes + \value AlbumTitle The title of the album the media belongs to. QString. + \value AlbumArtist The principal artist of the album the media belongs to. QString. + \value ContributingArtist The artists contributing to the media. QStringList. + \value Composer The composer of the media. QStringList. + \value Conductor The conductor of the media. QString. + \value Lyrics The lyrics to the media. QString. + \value Mood The mood of the media. QString. + \value TrackNumber The track number of the media. int. + \value TrackCount The number of tracks on the album containing the media. int. + + \value CoverArtUrlSmall The URL of a small cover art image. QUrl. + \value CoverArtUrlLarge The URL of a large cover art image. QUrl. + \value CoverArtImage An embedded cover art image. QImage. + + Image and video attributes + \value Resolution The dimensions of an image or video. QSize. + \value PixelAspectRatio The pixel aspect ratio of an image or video. QSize. + + Video attributes + \value VideoFrameRate The frame rate of the media's video stream. qreal. + \value VideoBitRate The bit rate of the media's video stream in bits per second. int. + \value VideoCodec The codec of the media's video stream. QString. + + \value PosterUrl The URL of a poster image. QUrl. + \value PosterImage An embedded poster image. QImage. + + Movie attributes + \value ChapterNumber The chapter number of the media. int. + \value Director The director of the media. QString. + \value LeadPerformer The lead performer in the media. QStringList. + \value Writer The writer of the media. QStringList. + + Photo attributes. + \value CameraManufacturer The manufacturer of the camera used to capture the media. QString. + \value CameraModel The model of the camera used to capture the media. QString. + \value Event The event during which the media was captured. QString. + \value Subject The subject of the media. QString. + \value Orientation Orientation of image. + \value ExposureTime Exposure time, given in seconds. + \value FNumber The F Number. + \value ExposureProgram + The class of the program used by the camera to set exposure when the picture is taken. + \value ISOSpeedRatings + Indicates the ISO Speed and ISO Latitude of the camera or input device as specified in ISO 12232. + \value ExposureBiasValue + The exposure bias. + The unit is the APEX (Additive System of Photographic Exposure) setting. + \value DateTimeOriginal The date and time when the original image data was generated. + \value DateTimeDigitized The date and time when the image was stored as digital data. + \value SubjectDistance The distance to the subject, given in meters. + \value MeteringMode The metering mode. + \value LightSource + The kind of light source. + \value Flash + Status of flash when the image was shot. + \value FocalLength + The actual focal length of the lens, in mm. + \value ExposureMode + Indicates the exposure mode set when the image was shot. + \value WhiteBalance + Indicates the white balance mode set when the image was shot. + \value DigitalZoomRatio + Indicates the digital zoom ratio when the image was shot. + \value FocalLengthIn35mmFilm + Indicates the equivalent focal length assuming a 35mm film camera, in mm. + \value SceneCaptureType + Indicates the type of scene that was shot. + It can also be used to record the mode in which the image was shot. + \value GainControl + Indicates the degree of overall image gain adjustment. + \value Contrast + Indicates the direction of contrast processing applied by the camera when the image was shot. + \value Saturation + Indicates the direction of saturation processing applied by the camera when the image was shot. + \value Sharpness + Indicates the direction of sharpness processing applied by the camera when the image was shot. + \value DeviceSettingDescription + Exif tag, indicates information on the picture-taking conditions of a particular camera model. QString + + \value ThumbnailImage An embedded thumbnail image. QImage. +*/ + +/*! + \enum QtMultimedia::SupportEstimate + + Enumerates the levels of support a media service provider may have for a feature. + + \value NotSupported The feature is not supported. + \value MaybeSupported The feature may be supported. + \value ProbablySupported The feature is probably supported. + \value PreferredService The service is the preferred provider of a service. +*/ + +/*! + \enum QtMultimedia::EncodingQuality + + Enumerates quality encoding levels. + + \value VeryLowQuality + \value LowQuality + \value NormalQuality + \value HighQuality + \value VeryHighQuality +*/ + +/*! + \enum QtMultimedia::EncodingMode + + Enumerates encoding modes. + + \value ConstantQualityEncoding + \value ConstantBitRateEncoding + \value AverageBitRateEncoding + \value TwoPassEncoding +*/ + +/*! + \enum QtMultimedia::AvailabilityError + + Enumerates Service status errors. + + \value NoError + \value ServiceMissingError + \value ResourceError + \value BusyError +*/ diff --git a/src/multimedia/mediaservices/base/qvideodevicecontrol.cpp b/src/multimedia/mediaservices/base/qvideodevicecontrol.cpp new file mode 100644 index 0000000..128cee9 --- /dev/null +++ b/src/multimedia/mediaservices/base/qvideodevicecontrol.cpp @@ -0,0 +1,155 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtMediaservices module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include + + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +/*! + \class QVideoDeviceControl + \preliminary + \since 4.7 + \brief The QVideoDeviceControl class provides an video device selector media control. + \ingroup multimedia-serv + + The QVideoDeviceControl class provides descriptions of the video devices + available on a system and allows one to be selected as the endpoint of + a media service. + + The interface name of QVideoDeviceControl is \c com.nokia.Qt.VideoDeviceControl as + defined in QVideoDeviceControl_iid. +*/ + +/*! + \macro QVideoDeviceControl_iid + + \c com.nokia.Qt.VideoDeviceControl + + Defines the interface name of the QVideoDeviceControl class. + + \relates QVideoDeviceControl +*/ + +/*! + Constructs a video device control with the given \a parent. +*/ +QVideoDeviceControl::QVideoDeviceControl(QObject *parent) + :QMediaControl(parent) +{ +} + +/*! + Destroys a video device control. +*/ +QVideoDeviceControl::~QVideoDeviceControl() +{ +} + +/*! + \fn QVideoDeviceControl::deviceCount() const + + Returns the number of available video devices; +*/ + +/*! + \fn QVideoDeviceControl::deviceName(int index) const + + Returns the name of the video device at \a index. +*/ + +/*! + \fn QVideoDeviceControl::deviceDescription(int index) const + + Returns a description of the video device at \a index. +*/ + +/*! + \fn QVideoDeviceControl::deviceIcon(int index) const + + Returns an icon for the video device at \a index. +*/ + +/*! + \fn QVideoDeviceControl::defaultDevice() const + + Returns the index of the default video device. +*/ + +/*! + \fn QVideoDeviceControl::selectedDevice() const + + Returns the index of the selected video device. +*/ + +/*! + \fn QVideoDeviceControl::setSelectedDevice(int index) + + Sets the selected video device \a index. +*/ + +/*! + \fn QVideoDeviceControl::devicesChanged() + + Signals that the list of available video devices has changed. +*/ + +/*! + \fn QVideoDeviceControl::selectedDeviceChanged(int index) + + Signals that the selected video device \a index has changed. +*/ + +/*! + \fn QVideoDeviceControl::selectedDeviceChanged(const QString &name) + + Signals that the selected video device \a name has changed. +*/ + +QT_END_NAMESPACE + +QT_END_HEADER + +#include "moc_qvideodevicecontrol.cpp" + + diff --git a/src/multimedia/mediaservices/base/qvideodevicecontrol.h b/src/multimedia/mediaservices/base/qvideodevicecontrol.h new file mode 100644 index 0000000..df1d4fa --- /dev/null +++ b/src/multimedia/mediaservices/base/qvideodevicecontrol.h @@ -0,0 +1,90 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtMediaservices module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QVIDEODEVICECONTROL_H +#define QVIDEODEVICECONTROL_H + +#include + + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Multimedia) + +class Q_MULTIMEDIA_EXPORT QVideoDeviceControl : public QMediaControl +{ + Q_OBJECT + +public: + virtual ~QVideoDeviceControl(); + + virtual int deviceCount() const = 0; + + virtual QString deviceName(int index) const = 0; + virtual QString deviceDescription(int index) const = 0; + virtual QIcon deviceIcon(int index) const = 0; + + virtual int defaultDevice() const = 0; + virtual int selectedDevice() const = 0; + +public Q_SLOTS: + virtual void setSelectedDevice(int index) = 0; + +Q_SIGNALS: + void selectedDeviceChanged(int index); + void selectedDeviceChanged(const QString &deviceName); + void devicesChanged(); + +protected: + QVideoDeviceControl(QObject *parent = 0); +}; + +#define QVideoDeviceControl_iid "com.nokia.Qt.QVideoDeviceControl/1.0" +Q_MEDIA_DECLARE_CONTROL(QVideoDeviceControl, QVideoDeviceControl_iid) + + +QT_END_NAMESPACE + +QT_END_HEADER + +#endif // QVIDEODEVICECONTROL_H diff --git a/src/multimedia/mediaservices/base/qvideooutputcontrol.cpp b/src/multimedia/mediaservices/base/qvideooutputcontrol.cpp new file mode 100644 index 0000000..7d7ed4b --- /dev/null +++ b/src/multimedia/mediaservices/base/qvideooutputcontrol.cpp @@ -0,0 +1,135 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtMediaservices module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include + + +QT_BEGIN_NAMESPACE + +/*! + \class QVideoOutputControl + \preliminary + \since 4.7 + \brief The QVideoOutputControl class provides a means of selecting the + active video output control. + + \ingroup multimedia-serv + + There are multiple controls which a QMediaService may use to output + video ony one of which may be active at one time, QVideoOutputControl + is the means by which this active control is selected. + + The possible output controls are QVideoRendererControl, + QVideoWindowControl, and QVideoWidgetControl. + + The interface name of QVideoOutputControl is \c com.nokia.Qt.QVideoOutputControl/1.0 as + defined in QVideoOutputControl_iid. + + \sa QMediaService::control(), QVideoWidget, QVideoRendererControl, + QVideoWindowControl, QVideoWidgetControl +*/ + +/*! + \macro QVideoOutputControl_iid + + \c com.nokia.Qt.QVideoOutputControl/1.0 + + Defines the interface name of the QVideoOutputControl class. + + \relates QVideoOutputControl +*/ + +/*! + \enum QVideoOutputControl::Output + + Identifies the possible render targets of a video output. + + \value NoOutput Video is not rendered. + \value WindowOutput Video is rendered to the target of a QVideoWindowControl. + \value RendererOutput Video is rendered to the target of a QVideoRendererControl. + \value WidgetOutput Video is rendered to a QWidget provided by QVideoWidgetControl. + \value UserOutput Start value for user defined video targets. + \value MaxUserOutput End value for user defined video targets. +*/ + +/*! + Constructs a new video output control with the given \a parent. +*/ +QVideoOutputControl::QVideoOutputControl(QObject *parent) + : QMediaControl(parent) +{ +} + +/*! + Destroys a video output control. +*/ +QVideoOutputControl::~QVideoOutputControl() +{ +} + +/*! + \fn QList QVideoOutputControl::availableOutputs() const + + Returns a list of available video output targets. +*/ + +/*! + \fn QVideoOutputControl::output() const + + Returns the current video output target. +*/ + +/*! + \fn QVideoOutputControl::setOutput(Output output) + + Sets the current video \a output target. +*/ + +/*! + \fn QVideoOutputControl::availableOutputsChanged(const QList &outputs) + + Signals that available set of video \a outputs has changed. +*/ + +#include "moc_qvideooutputcontrol.cpp" + +QT_END_NAMESPACE + diff --git a/src/multimedia/mediaservices/base/qvideooutputcontrol.h b/src/multimedia/mediaservices/base/qvideooutputcontrol.h new file mode 100644 index 0000000..05bc164 --- /dev/null +++ b/src/multimedia/mediaservices/base/qvideooutputcontrol.h @@ -0,0 +1,91 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtMediaservices module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QVIDEOOUTPUTCONTROL_H +#define QVIDEOOUTPUTCONTROL_H + +#include + + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Multimedia) + + +class Q_MULTIMEDIA_EXPORT QVideoOutputControl : public QMediaControl +{ + Q_OBJECT + +public: + enum Output + { + NoOutput, + WindowOutput, + RendererOutput, + WidgetOutput, + UserOutput = 100, + MaxUserOutput = 1000 + }; + + ~QVideoOutputControl(); + + virtual QList availableOutputs() const = 0; + + virtual Output output() const = 0; + virtual void setOutput(Output output) = 0; + +Q_SIGNALS: + void availableOutputsChanged(const QList &outputs); + +protected: + QVideoOutputControl(QObject *parent = 0); +}; + +#define QVideoOutputControl_iid "com.nokia.Qt.QVideoOutputControl/1.0" +Q_MEDIA_DECLARE_CONTROL(QVideoOutputControl, QVideoOutputControl_iid) + +QT_END_NAMESPACE + +QT_END_HEADER + +#endif diff --git a/src/multimedia/mediaservices/base/qvideorenderercontrol.cpp b/src/multimedia/mediaservices/base/qvideorenderercontrol.cpp new file mode 100644 index 0000000..bd7c78d --- /dev/null +++ b/src/multimedia/mediaservices/base/qvideorenderercontrol.cpp @@ -0,0 +1,124 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtMediaservices module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include + +#include "qmediacontrol_p.h" + + +QT_BEGIN_NAMESPACE + +/*! + \class QVideoRendererControl + \preliminary + \since 4.7 + \brief The QVideoRendererControl class provides a control for rendering + to a video surface. + + \ingroup multimedia-serv + + Using the surface() property of QVideoRendererControl a QAbstractVideoSurface + may be set as the video render target of a QMediaService. + + \code + QVideoRendererControl *rendererControl = mediaService->control(); + rendererControl->setSurface(myVideoSurface); + \endcode + + QVideoRendererControl is one of number of possible video output controls, + in order to receive video it must be made the active video output + control by setting the output property of QVideoOutputControl to + \l {QVideoOutputControl::RendererOutput}{RendererOutput}. Consequently any + QMediaService that implements QVideoRendererControl must also implement + QVideoOutputControl. + + \code + QVideoOutputControl *outputControl = mediaService->control(); + outputControl->setOutput(QVideoOutputControl::RendererOutput); + \endcode + + The interface name of QVideoRendererControl is \c com.nokia.Qt.QVideoRendererControl/1.0 as + defined in QVideoRendererControl_iid. + + \sa QMediaService::control(), QVideoOutputControl, QVideoWidget +*/ + +/*! + \macro QVideoRendererControl_iid + + \c com.nokia.Qt.QVideoRendererControl/1.0 + + Defines the interface name of the QVideoRendererControl class. + + \relates QVideoRendererControl +*/ + +/*! + Constructs a new video renderer media end point with the given \a parent. +*/ +QVideoRendererControl::QVideoRendererControl(QObject *parent) + : QMediaControl(parent) +{ +} + +/*! + Destroys a video renderer media end point. +*/ +QVideoRendererControl::~QVideoRendererControl() +{ +} + +/*! + \fn QVideoRendererControl::surface() const + + Returns the surface a video producer renders to. +*/ + +/*! + \fn QVideoRendererControl::setSurface(QAbstractVideoSurface *surface) + + Sets the \a surface a video producer renders to. +*/ + +#include "moc_qvideorenderercontrol.cpp" + +QT_END_NAMESPACE + diff --git a/src/multimedia/mediaservices/base/qvideorenderercontrol.h b/src/multimedia/mediaservices/base/qvideorenderercontrol.h new file mode 100644 index 0000000..fd130ac --- /dev/null +++ b/src/multimedia/mediaservices/base/qvideorenderercontrol.h @@ -0,0 +1,77 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtMediaservices module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QVIDEORENDERERCONTROL_H +#define QVIDEORENDERERCONTROL_H + +#include + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Multimedia) + + +class QAbstractVideoSurface; + +class Q_MULTIMEDIA_EXPORT QVideoRendererControl : public QMediaControl +{ + Q_OBJECT + +public: + ~QVideoRendererControl(); + + virtual QAbstractVideoSurface *surface() const = 0; + virtual void setSurface(QAbstractVideoSurface *surface) = 0; + +protected: + QVideoRendererControl(QObject *parent = 0); +}; + +#define QVideoRendererControl_iid "com.nokia.Qt.QVideoRendererControl/1.0" +Q_MEDIA_DECLARE_CONTROL(QVideoRendererControl, QVideoRendererControl_iid) + +QT_END_NAMESPACE + +QT_END_HEADER + +#endif // QVIDEORENDERERCONTROL_H diff --git a/src/multimedia/mediaservices/base/qvideowidget.cpp b/src/multimedia/mediaservices/base/qvideowidget.cpp new file mode 100644 index 0000000..52291b0 --- /dev/null +++ b/src/multimedia/mediaservices/base/qvideowidget.cpp @@ -0,0 +1,944 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtMediaservices module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qvideowidget_p.h" + +#include +#include +#include +#include +#include + +#include "qpaintervideosurface_p.h" +#include +#include +#include + +#include +#include +#include +#include +#include + + +QT_BEGIN_NAMESPACE + +QVideoWidgetControlBackend::QVideoWidgetControlBackend( + QVideoWidgetControl *control, QWidget *widget) + : m_widgetControl(control) +{ + connect(control, SIGNAL(brightnessChanged(int)), widget, SLOT(_q_brightnessChanged(int))); + connect(control, SIGNAL(contrastChanged(int)), widget, SLOT(_q_contrastChanged(int))); + connect(control, SIGNAL(hueChanged(int)), widget, SLOT(_q_hueChanged(int))); + connect(control, SIGNAL(saturationChanged(int)), widget, SLOT(_q_saturationChanged(int))); + connect(control, SIGNAL(fullScreenChanged(bool)), widget, SLOT(_q_fullScreenChanged(bool))); + + QBoxLayout *layout = new QVBoxLayout; + layout->setMargin(0); + layout->setSpacing(0); + layout->addWidget(control->videoWidget()); + + widget->setLayout(layout); +} + +void QVideoWidgetControlBackend::setBrightness(int brightness) +{ + m_widgetControl->setBrightness(brightness); +} + +void QVideoWidgetControlBackend::setContrast(int contrast) +{ + m_widgetControl->setContrast(contrast); +} + +void QVideoWidgetControlBackend::setHue(int hue) +{ + m_widgetControl->setHue(hue); +} + +void QVideoWidgetControlBackend::setSaturation(int saturation) +{ + m_widgetControl->setSaturation(saturation); +} + +void QVideoWidgetControlBackend::setFullScreen(bool fullScreen) +{ + m_widgetControl->setFullScreen(fullScreen); +} + + +Qt::AspectRatioMode QVideoWidgetControlBackend::aspectRatioMode() const +{ + return m_widgetControl->aspectRatioMode(); +} + +void QVideoWidgetControlBackend::setAspectRatioMode(Qt::AspectRatioMode mode) +{ + m_widgetControl->setAspectRatioMode(mode); +} + +QRendererVideoWidgetBackend::QRendererVideoWidgetBackend( + QVideoRendererControl *control, QWidget *widget) + : m_rendererControl(control) + , m_widget(widget) + , m_surface(new QPainterVideoSurface) + , m_aspectRatioMode(Qt::KeepAspectRatio) + , m_updatePaintDevice(true) +{ + connect(this, SIGNAL(brightnessChanged(int)), m_widget, SLOT(_q_brightnessChanged(int))); + connect(this, SIGNAL(contrastChanged(int)), m_widget, SLOT(_q_contrastChanged(int))); + connect(this, SIGNAL(hueChanged(int)), m_widget, SLOT(_q_hueChanged(int))); + connect(this, SIGNAL(saturationChanged(int)), m_widget, SLOT(_q_saturationChanged(int))); + connect(m_surface, SIGNAL(frameChanged()), this, SLOT(frameChanged())); + connect(m_surface, SIGNAL(surfaceFormatChanged(QVideoSurfaceFormat)), + this, SLOT(formatChanged(QVideoSurfaceFormat))); + + m_rendererControl->setSurface(m_surface); +} + +QRendererVideoWidgetBackend::~QRendererVideoWidgetBackend() +{ + delete m_surface; +} + +void QRendererVideoWidgetBackend::clearSurface() +{ + m_rendererControl->setSurface(0); +} + +void QRendererVideoWidgetBackend::setBrightness(int brightness) +{ + m_surface->setBrightness(brightness); + + emit brightnessChanged(brightness); +} + +void QRendererVideoWidgetBackend::setContrast(int contrast) +{ + m_surface->setContrast(contrast); + + emit contrastChanged(contrast); +} + +void QRendererVideoWidgetBackend::setHue(int hue) +{ + m_surface->setHue(hue); + + emit hueChanged(hue); +} + +void QRendererVideoWidgetBackend::setSaturation(int saturation) +{ + m_surface->setSaturation(saturation); + + emit saturationChanged(saturation); +} + +Qt::AspectRatioMode QRendererVideoWidgetBackend::aspectRatioMode() const +{ + return m_aspectRatioMode; +} + +void QRendererVideoWidgetBackend::setAspectRatioMode(Qt::AspectRatioMode mode) +{ + m_aspectRatioMode = mode; + + m_widget->updateGeometry(); +} + +void QRendererVideoWidgetBackend::setFullScreen(bool) +{ +} + +QSize QRendererVideoWidgetBackend::sizeHint() const +{ + return m_surface->surfaceFormat().sizeHint(); +} + +void QRendererVideoWidgetBackend::showEvent() +{ +} + +void QRendererVideoWidgetBackend::hideEvent(QHideEvent *) +{ +#if !defined(QT_NO_OPENGL) && !defined(QT_OPENGL_ES_1_CL) && !defined(QT_OPENGL_ES_1) + m_updatePaintDevice = true; + m_surface->setGLContext(0); +#endif +} + +void QRendererVideoWidgetBackend::resizeEvent(QResizeEvent *) +{ + updateRects(); +} + +void QRendererVideoWidgetBackend::moveEvent(QMoveEvent *) +{ +} + +void QRendererVideoWidgetBackend::paintEvent(QPaintEvent *event) +{ + QPainter painter(m_widget); + + if (m_widget->testAttribute(Qt::WA_OpaquePaintEvent)) { + QRegion borderRegion = event->region(); + borderRegion = borderRegion.subtracted(m_boundingRect); + + QBrush brush = m_widget->palette().window(); + + QVector rects = borderRegion.rects(); + for (QVector::iterator it = rects.begin(), end = rects.end(); it != end; ++it) { + painter.fillRect(*it, brush); + } + } + + if (m_surface->isActive() && m_boundingRect.intersects(event->rect())) { + m_surface->paint(&painter, m_boundingRect, m_sourceRect); + + m_surface->setReady(true); + } else { + #if !defined(QT_NO_OPENGL) && !defined(QT_OPENGL_ES_1_CL) && !defined(QT_OPENGL_ES_1) + if (m_updatePaintDevice && (painter.paintEngine()->type() == QPaintEngine::OpenGL + || painter.paintEngine()->type() == QPaintEngine::OpenGL2)) { + m_updatePaintDevice = false; + + m_surface->setGLContext(const_cast(QGLContext::currentContext())); + if (m_surface->supportedShaderTypes() & QPainterVideoSurface::GlslShader) { + m_surface->setShaderType(QPainterVideoSurface::GlslShader); + } else { + m_surface->setShaderType(QPainterVideoSurface::FragmentProgramShader); + } + } +#endif + } + +} + +void QRendererVideoWidgetBackend::formatChanged(const QVideoSurfaceFormat &format) +{ + m_nativeSize = format.sizeHint(); + + updateRects(); + + m_widget->updateGeometry(); + m_widget->update(); +} + +void QRendererVideoWidgetBackend::frameChanged() +{ + m_widget->update(m_boundingRect); +} + +void QRendererVideoWidgetBackend::updateRects() +{ + QRect rect = m_widget->rect(); + + if (m_nativeSize.isEmpty()) { + m_boundingRect = QRect(); + } else if (m_aspectRatioMode == Qt::IgnoreAspectRatio) { + m_boundingRect = rect; + m_sourceRect = QRectF(0, 0, 1, 1); + } else if (m_aspectRatioMode == Qt::KeepAspectRatio) { + QSize size = m_nativeSize; + size.scale(rect.size(), Qt::KeepAspectRatio); + + m_boundingRect = QRect(0, 0, size.width(), size.height()); + m_boundingRect.moveCenter(rect.center()); + + m_sourceRect = QRectF(0, 0, 1, 1); + } else if (m_aspectRatioMode == Qt::KeepAspectRatioByExpanding) { + m_boundingRect = rect; + + QSizeF size = rect.size(); + size.scale(m_nativeSize, Qt::KeepAspectRatio); + + m_sourceRect = QRectF( + 0, 0, size.width() / m_nativeSize.width(), size.height() / m_nativeSize.height()); + m_sourceRect.moveCenter(QPointF(0.5, 0.5)); + } +} + +QWindowVideoWidgetBackend::QWindowVideoWidgetBackend(QVideoWindowControl *control, QWidget *widget) + : m_windowControl(control) + , m_widget(widget) + , m_aspectRatioMode(Qt::KeepAspectRatio) +{ + connect(control, SIGNAL(brightnessChanged(int)), m_widget, SLOT(_q_brightnessChanged(int))); + connect(control, SIGNAL(contrastChanged(int)), m_widget, SLOT(_q_contrastChanged(int))); + connect(control, SIGNAL(hueChanged(int)), m_widget, SLOT(_q_hueChanged(int))); + connect(control, SIGNAL(saturationChanged(int)), m_widget, SLOT(_q_saturationChanged(int))); + connect(control, SIGNAL(fullScreenChanged(bool)), m_widget, SLOT(_q_fullScreenChanged(bool))); + connect(control, SIGNAL(nativeSizeChanged()), m_widget, SLOT(_q_dimensionsChanged())); +} + +QWindowVideoWidgetBackend::~QWindowVideoWidgetBackend() +{ +} + +void QWindowVideoWidgetBackend::setBrightness(int brightness) +{ + m_windowControl->setBrightness(brightness); +} + +void QWindowVideoWidgetBackend::setContrast(int contrast) +{ + m_windowControl->setContrast(contrast); +} + +void QWindowVideoWidgetBackend::setHue(int hue) +{ + m_windowControl->setHue(hue); +} + +void QWindowVideoWidgetBackend::setSaturation(int saturation) +{ + m_windowControl->setSaturation(saturation); +} + +void QWindowVideoWidgetBackend::setFullScreen(bool fullScreen) +{ + m_windowControl->setFullScreen(fullScreen); +} + +Qt::AspectRatioMode QWindowVideoWidgetBackend::aspectRatioMode() const +{ + return m_windowControl->aspectRatioMode(); +} + +void QWindowVideoWidgetBackend::setAspectRatioMode(Qt::AspectRatioMode mode) +{ + m_windowControl->setAspectRatioMode(mode); +} + +QSize QWindowVideoWidgetBackend::sizeHint() const +{ + return m_windowControl->nativeSize(); +} + +void QWindowVideoWidgetBackend::showEvent() +{ + m_windowControl->setWinId(m_widget->winId()); + + m_windowControl->setDisplayRect(m_widget->rect()); +} + +void QWindowVideoWidgetBackend::hideEvent(QHideEvent *) +{ +} + +void QWindowVideoWidgetBackend::moveEvent(QMoveEvent *) +{ + m_windowControl->setDisplayRect(m_widget->rect()); +} + +void QWindowVideoWidgetBackend::resizeEvent(QResizeEvent *) +{ + m_windowControl->setDisplayRect(m_widget->rect()); +} + +void QWindowVideoWidgetBackend::paintEvent(QPaintEvent *event) +{ + if (m_widget->testAttribute(Qt::WA_OpaquePaintEvent)) { + QPainter painter(m_widget); + + painter.fillRect(event->rect(), m_widget->palette().window()); + } + + m_windowControl->repaint(); + + event->accept(); +} + +void QVideoWidgetPrivate::setCurrentControl(QVideoWidgetControlInterface *control) +{ + if (currentControl != control) { + currentControl = control; + + currentControl->setBrightness(brightness); + currentControl->setContrast(contrast); + currentControl->setHue(hue); + currentControl->setSaturation(saturation); + currentControl->setAspectRatioMode(aspectRatioMode); + } +} + +void QVideoWidgetPrivate::show() +{ + if (outputControl) { + if (widgetBackend != 0) { + setCurrentControl(widgetBackend); + outputControl->setOutput(QVideoOutputControl::WidgetOutput); + } else if (windowBackend != 0 && (q_func()->window() == 0 + || !q_func()->window()->testAttribute(Qt::WA_DontShowOnScreen))) { + windowBackend->showEvent(); + currentBackend = windowBackend; + setCurrentControl(windowBackend); + outputControl->setOutput(QVideoOutputControl::WindowOutput); + } else if (rendererBackend != 0) { + rendererBackend->showEvent(); + currentBackend = rendererBackend; + setCurrentControl(rendererBackend); + outputControl->setOutput(QVideoOutputControl::RendererOutput); + } else { + outputControl->setOutput(QVideoOutputControl::NoOutput); + } + } +} + +void QVideoWidgetPrivate::clearService() +{ + if (service) { + QObject::disconnect(service, SIGNAL(destroyed()), q_func(), SLOT(_q_serviceDestroyed())); + + if (outputControl) + outputControl->setOutput(QVideoOutputControl::NoOutput); + + if (widgetBackend) { + QLayout *layout = q_func()->layout(); + + for (QLayoutItem *item = layout->takeAt(0); item; item = layout->takeAt(0)) { + item->widget()->setParent(0); + delete item; + } + delete layout; + + delete widgetBackend; + widgetBackend = 0; + } + + delete windowBackend; + windowBackend = 0; + + if (rendererBackend) { + rendererBackend->clearSurface(); + + delete rendererBackend; + rendererBackend = 0; + } + + currentBackend = 0; + currentControl = 0; + outputControl = 0; + service = 0; + } +} + +void QVideoWidgetPrivate::_q_serviceDestroyed() +{ + if (widgetBackend) { + delete q_func()->layout(); + + delete widgetBackend; + widgetBackend = 0; + } + + delete windowBackend; + windowBackend = 0; + + delete rendererBackend; + rendererBackend = 0; + + currentControl = 0; + currentBackend = 0; + outputControl = 0; + service = 0; +} + +void QVideoWidgetPrivate::_q_mediaObjectDestroyed() +{ + mediaObject = 0; + clearService(); +} + +void QVideoWidgetPrivate::_q_brightnessChanged(int b) +{ + if (b != brightness) + emit q_func()->brightnessChanged(brightness = b); +} + +void QVideoWidgetPrivate::_q_contrastChanged(int c) +{ + if (c != contrast) + emit q_func()->contrastChanged(contrast = c); +} + +void QVideoWidgetPrivate::_q_hueChanged(int h) +{ + if (h != hue) + emit q_func()->hueChanged(hue = h); +} + +void QVideoWidgetPrivate::_q_saturationChanged(int s) +{ + if (s != saturation) + emit q_func()->saturationChanged(saturation = s); +} + + +void QVideoWidgetPrivate::_q_fullScreenChanged(bool fullScreen) +{ + if (!fullScreen && q_func()->isFullScreen()) + q_func()->showNormal(); +} + +void QVideoWidgetPrivate::_q_dimensionsChanged() +{ + q_func()->updateGeometry(); + q_func()->update(); +} + +/*! + \class QVideoWidget + \preliminary + \since 4.7 + \brief The QVideoWidget class provides a widget which presents video + produced by a media object. + \ingroup multimedia + + Attaching a QVideoWidget to a QMediaObject allows it to display the + video or image output of that media object. A QVideoWidget is attached + to media object by passing a pointer to the QMediaObject in its + constructor, and detached by destroying the QVideoWidget. + + \code + player = new QMediaPlayer; + + widget = new QVideoWidget(player); + widget->show(); + + player->setMedia(QUrl("http://example.com/movie.mp4")); + player->play(); + \endcode + + \bold {Note}: Only a single display output can be attached to a media + object at one time. + + \sa QMediaObject, QMediaPlayer, QGraphicsVideoItem +*/ + +/*! + Constructs a new video widget. + + The \a parent is passed to QWidget. +*/ +QVideoWidget::QVideoWidget(QWidget *parent) + : QWidget(parent, 0) + , d_ptr(new QVideoWidgetPrivate) +{ + d_ptr->q_ptr = this; +} + +/*! + Destroys a video widget. +*/ +QVideoWidget::~QVideoWidget() +{ + setMediaObject(0); + delete d_ptr; +} + +/*! + \property QVideoWidget::mediaObject + \brief the media object which provides the video displayed by a widget. +*/ + +QMediaObject *QVideoWidget::mediaObject() const +{ + return d_func()->mediaObject; +} + +void QVideoWidget::setMediaObject(QMediaObject *object) +{ + Q_D(QVideoWidget); + + if (object == d->mediaObject) + return; + + if (d->mediaObject) { + disconnect(d->mediaObject, SIGNAL(destroyed()), this, SLOT(_q_mediaObjectDestroyed())); + d->mediaObject->unbind(this); + } + + d->clearService(); + + d->mediaObject = object; + + if (d->mediaObject) { + d->service = d->mediaObject->service(); + + connect(d->mediaObject, SIGNAL(destroyed()), this, SLOT(_q_mediaObjectDestroyed())); + d->mediaObject->bind(this); + } + + if (d->service) { + connect(d->service, SIGNAL(destroyed()), SLOT(_q_serviceDestroyed())); + + d->outputControl = qobject_cast( + d->service->control(QVideoOutputControl_iid)); + + QVideoWidgetControl *widgetControl = qobject_cast( + d->service->control(QVideoWidgetControl_iid)); + + if (widgetControl != 0) { + d->widgetBackend = new QVideoWidgetControlBackend(widgetControl, this); + } else { + QVideoWindowControl *windowControl = qobject_cast( + d->service->control(QVideoWindowControl_iid)); + + if (windowControl != 0) + d->windowBackend = new QWindowVideoWidgetBackend(windowControl, this); + + QVideoRendererControl *rendererControl = qobject_cast( + d->service->control(QVideoRendererControl_iid)); + + if (rendererControl != 0) + d->rendererBackend = new QRendererVideoWidgetBackend(rendererControl, this); + } + + if (isVisible()) + d->show(); + } +} + +/*! + \property QVideoWidget::aspectRatioMode + \brief how video is scaled with respect to its aspect ratio. +*/ + +Qt::AspectRatioMode QVideoWidget::aspectRatioMode() const +{ + return d_func()->aspectRatioMode; +} + +void QVideoWidget::setAspectRatioMode(Qt::AspectRatioMode mode) +{ + Q_D(QVideoWidget); + + if (d->currentControl) { + d->currentControl->setAspectRatioMode(mode); + d->aspectRatioMode = d->currentControl->aspectRatioMode(); + } else { + d->aspectRatioMode = mode; + } +} + +/*! + \property QVideoWidget::fullScreen + \brief whether video display is confined to a window or is fullScreen. +*/ + +void QVideoWidget::setFullScreen(bool fullScreen) +{ + Q_D(QVideoWidget); + + if (fullScreen) { + Qt::WindowFlags flags = windowFlags(); + + d->nonFullScreenFlags = flags & (Qt::Window | Qt::SubWindow); + flags |= Qt::Window; + flags &= ~Qt::SubWindow; + setWindowFlags(flags); + + showFullScreen(); + } else { + showNormal(); + } +} + +/*! + \fn QVideoWidget::fullScreenChanged(bool fullScreen) + + Signals that the \a fullScreen mode of a video widget has changed. + + \sa fullScreen +*/ + +/*! + \property QVideoWidget::brightness + \brief an adjustment to the brightness of displayed video. + + Valid brightness values range between -100 and 100, the default is 0. +*/ + +int QVideoWidget::brightness() const +{ + return d_func()->brightness; +} + +void QVideoWidget::setBrightness(int brightness) +{ + Q_D(QVideoWidget); + + int boundedBrightness = qBound(-100, brightness, 100); + + if (d->currentControl) + d->currentControl->setBrightness(boundedBrightness); + else if (d->brightness != boundedBrightness) + emit brightnessChanged(d->brightness = boundedBrightness); +} + +/*! + \fn QVideoWidget::brightnessChanged(int brightness) + + Signals that a video widgets's \a brightness adjustment has changed. + + \sa brightness +*/ + +/*! + \property QVideoWidget::contrast + \brief an adjustment to the contrast of displayed video. + + Valid contrast values range between -100 and 100, the default is 0. + +*/ + +int QVideoWidget::contrast() const +{ + return d_func()->contrast; +} + +void QVideoWidget::setContrast(int contrast) +{ + Q_D(QVideoWidget); + + int boundedContrast = qBound(-100, contrast, 100); + + if (d->currentControl) + d->currentControl->setContrast(boundedContrast); + else if (d->contrast != boundedContrast) + emit contrastChanged(d->contrast = boundedContrast); +} + +/*! + \fn QVideoWidget::contrastChanged(int contrast) + + Signals that a video widgets's \a contrast adjustment has changed. + + \sa contrast +*/ + +/*! + \property QVideoWidget::hue + \brief an adjustment to the hue of displayed video. + + Valid hue values range between -100 and 100, the default is 0. +*/ + +int QVideoWidget::hue() const +{ + return d_func()->hue; +} + +void QVideoWidget::setHue(int hue) +{ + Q_D(QVideoWidget); + + int boundedHue = qBound(-100, hue, 100); + + if (d->currentControl) + d->currentControl->setHue(boundedHue); + else if (d->hue != boundedHue) + emit hueChanged(d->hue = boundedHue); +} + +/*! + \fn QVideoWidget::hueChanged(int hue) + + Signals that a video widgets's \a hue has changed. + + \sa hue +*/ + +/*! + \property QVideoWidget::saturation + \brief an adjustment to the saturation of displayed video. + + Valid saturation values range between -100 and 100, the default is 0. +*/ + +int QVideoWidget::saturation() const +{ + return d_func()->saturation; +} + +void QVideoWidget::setSaturation(int saturation) +{ + Q_D(QVideoWidget); + + int boundedSaturation = qBound(-100, saturation, 100); + + if (d->currentControl) + d->currentControl->setSaturation(boundedSaturation); + else if (d->saturation != boundedSaturation) + emit saturationChanged(d->saturation = boundedSaturation); + +} + +/*! + \fn QVideoWidget::saturationChanged(int saturation) + + Signals that a video widgets's \a saturation has changed. + + \sa saturation +*/ + +/*! + Returns the size hint for the current back end, + if there is one, or else the size hint from QWidget. + */ +QSize QVideoWidget::sizeHint() const +{ + Q_D(const QVideoWidget); + + if (d->currentBackend) + return d->currentBackend->sizeHint(); + else + return QWidget::sizeHint(); + + +} + +/*! + \reimp + \internal + */ +bool QVideoWidget::event(QEvent *event) +{ + Q_D(QVideoWidget); + + if (event->type() == QEvent::WindowStateChange) { + Qt::WindowFlags flags = windowFlags(); + + if (windowState() & Qt::WindowFullScreen) { + if (d->currentControl) + d->currentControl->setFullScreen(true); + + if (!d->wasFullScreen) + emit fullScreenChanged(d->wasFullScreen = true); + } else { + if (d->currentControl) + d->currentControl->setFullScreen(false); + + if (d->wasFullScreen) { + flags &= ~(Qt::Window | Qt::SubWindow); //clear the flags... + flags |= d->nonFullScreenFlags; //then we reset the flags (window and subwindow) + setWindowFlags(flags); + + emit fullScreenChanged(d->wasFullScreen = false); + } + } + } + return QWidget::event(event); +} + +/*! + Handles the show \a event. + */ +void QVideoWidget::showEvent(QShowEvent *event) +{ + Q_D(QVideoWidget); + + QWidget::showEvent(event); + + d->show(); + +} + +/*! + + Handles the hide \a event. +*/ +void QVideoWidget::hideEvent(QHideEvent *event) +{ + Q_D(QVideoWidget); + + if (d->currentBackend) + d->currentBackend->hideEvent(event); + + QWidget::hideEvent(event); +} + +/*! + Handles the resize \a event. + */ +void QVideoWidget::resizeEvent(QResizeEvent *event) +{ + Q_D(QVideoWidget); + + QWidget::resizeEvent(event); + + if (d->currentBackend) + d->currentBackend->resizeEvent(event); +} + +/*! + Handles the move \a event. + */ +void QVideoWidget::moveEvent(QMoveEvent *event) +{ + Q_D(QVideoWidget); + + if (d->currentBackend) + d->currentBackend->moveEvent(event); +} + +/*! + Handles the paint \a event. + */ +void QVideoWidget::paintEvent(QPaintEvent *event) +{ + Q_D(QVideoWidget); + + if (d->currentBackend) { + d->currentBackend->paintEvent(event); + } else if (testAttribute(Qt::WA_OpaquePaintEvent)) { + QPainter painter(this); + + painter.fillRect(event->rect(), palette().window()); + } +} + +#include "moc_qvideowidget.cpp" +#include "moc_qvideowidget_p.cpp" + +QT_END_NAMESPACE + diff --git a/src/multimedia/mediaservices/base/qvideowidget.h b/src/multimedia/mediaservices/base/qvideowidget.h new file mode 100644 index 0000000..080e19c --- /dev/null +++ b/src/multimedia/mediaservices/base/qvideowidget.h @@ -0,0 +1,131 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtMediaservices module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QVIDEOWIDGET_H +#define QVIDEOWIDGET_H + +#include + + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Multimedia) + + +class QMediaObject; + +class QVideoWidgetPrivate; +class Q_MULTIMEDIA_EXPORT QVideoWidget : public QWidget +{ + Q_OBJECT + Q_PROPERTY(QMediaObject* mediaObject READ mediaObject WRITE setMediaObject) + Q_PROPERTY(bool fullScreen READ isFullScreen WRITE setFullScreen NOTIFY fullScreenChanged) + Q_PROPERTY(Qt::AspectRatioMode aspectRatioMode READ aspectRatioMode WRITE setAspectRatioMode NOTIFY aspectRatioModeChanged) + Q_PROPERTY(int brightness READ brightness WRITE setBrightness NOTIFY brightnessChanged) + Q_PROPERTY(int contrast READ contrast WRITE setContrast NOTIFY contrastChanged) + Q_PROPERTY(int hue READ hue WRITE setHue NOTIFY hueChanged) + Q_PROPERTY(int saturation READ saturation WRITE setSaturation NOTIFY saturationChanged) + +public: + QVideoWidget(QWidget *parent = 0); + ~QVideoWidget(); + + QMediaObject *mediaObject() const; + void setMediaObject(QMediaObject *object); + +#ifdef Q_QDOC + bool isFullScreen() const; +#endif + + Qt::AspectRatioMode aspectRatioMode() const; + + int brightness() const; + int contrast() const; + int hue() const; + int saturation() const; + + QSize sizeHint() const; + +public Q_SLOTS: + void setFullScreen(bool fullScreen); + void setAspectRatioMode(Qt::AspectRatioMode mode); + void setBrightness(int brightness); + void setContrast(int contrast); + void setHue(int hue); + void setSaturation(int saturation); + +Q_SIGNALS: + void fullScreenChanged(bool fullScreen); + void brightnessChanged(int brightness); + void contrastChanged(int contrast); + void hueChanged(int hue); + void saturationChanged(int saturation); + +protected: + bool event(QEvent *event); + void showEvent(QShowEvent *event); + void hideEvent(QHideEvent *event); + void resizeEvent(QResizeEvent *event); + void moveEvent(QMoveEvent *event); + void paintEvent(QPaintEvent *event); + +protected: + QVideoWidgetPrivate *d_ptr; + +private: + Q_DECLARE_PRIVATE(QVideoWidget) + Q_PRIVATE_SLOT(d_func(), void _q_serviceDestroyed()) + Q_PRIVATE_SLOT(d_func(), void _q_mediaObjectDestroyed()) + Q_PRIVATE_SLOT(d_func(), void _q_brightnessChanged(int)) + Q_PRIVATE_SLOT(d_func(), void _q_contrastChanged(int)) + Q_PRIVATE_SLOT(d_func(), void _q_hueChanged(int)) + Q_PRIVATE_SLOT(d_func(), void _q_saturationChanged(int)) + Q_PRIVATE_SLOT(d_func(), void _q_fullScreenChanged(bool)) + Q_PRIVATE_SLOT(d_func(), void _q_dimensionsChanged()); +}; + +QT_END_NAMESPACE + +QT_END_HEADER + +#endif diff --git a/src/multimedia/mediaservices/base/qvideowidget_p.h b/src/multimedia/mediaservices/base/qvideowidget_p.h new file mode 100644 index 0000000..4f67117 --- /dev/null +++ b/src/multimedia/mediaservices/base/qvideowidget_p.h @@ -0,0 +1,271 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtMediaservices module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QVIDEOWIDGET_P_H +#define QVIDEOWIDGET_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include + +#ifndef QT_NO_OPENGL +#include +#endif + +#include "qpaintervideosurface_p.h" + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + + +class QVideoWidgetControlInterface +{ +public: + virtual ~QVideoWidgetControlInterface() {} + + virtual void setBrightness(int brightness) = 0; + virtual void setContrast(int contrast) = 0; + virtual void setHue(int hue) = 0; + virtual void setSaturation(int saturation) = 0; + + virtual void setFullScreen(bool fullScreen) = 0; + + virtual Qt::AspectRatioMode aspectRatioMode() const = 0; + virtual void setAspectRatioMode(Qt::AspectRatioMode mode) = 0; +}; + +class QVideoWidgetBackend : public QObject, public QVideoWidgetControlInterface +{ + Q_OBJECT + +public: + virtual QSize sizeHint() const = 0; + + virtual void showEvent() = 0; + virtual void hideEvent(QHideEvent *event) = 0; + virtual void resizeEvent(QResizeEvent *event) = 0; + virtual void moveEvent(QMoveEvent *event) = 0; + virtual void paintEvent(QPaintEvent *event) = 0; +}; + +class QVideoWidgetControl; + +class QVideoWidgetControlBackend : public QObject, public QVideoWidgetControlInterface +{ + Q_OBJECT +public: + QVideoWidgetControlBackend(QVideoWidgetControl *control, QWidget *widget); + + void setBrightness(int brightness); + void setContrast(int contrast); + void setHue(int hue); + void setSaturation(int saturation); + + void setFullScreen(bool fullScreen); + + Qt::AspectRatioMode aspectRatioMode() const; + void setAspectRatioMode(Qt::AspectRatioMode mode); + +private: + QVideoWidgetControl *m_widgetControl; +}; + + +class QVideoRendererControl; + +class QRendererVideoWidgetBackend : public QVideoWidgetBackend +{ + Q_OBJECT +public: + QRendererVideoWidgetBackend(QVideoRendererControl *control, QWidget *widget); + ~QRendererVideoWidgetBackend(); + + void clearSurface(); + + void setBrightness(int brightness); + void setContrast(int contrast); + void setHue(int hue); + void setSaturation(int saturation); + + void setFullScreen(bool fullScreen); + + Qt::AspectRatioMode aspectRatioMode() const; + void setAspectRatioMode(Qt::AspectRatioMode mode); + + QSize sizeHint() const; + + void showEvent(); + void hideEvent(QHideEvent *event); + void resizeEvent(QResizeEvent *event); + void moveEvent(QMoveEvent *event); + void paintEvent(QPaintEvent *event); + +Q_SIGNALS: + void fullScreenChanged(bool fullScreen); + void brightnessChanged(int brightness); + void contrastChanged(int contrast); + void hueChanged(int hue); + void saturationChanged(int saturation); + +private Q_SLOTS: + void formatChanged(const QVideoSurfaceFormat &format); + void frameChanged(); + +private: + void updateRects(); + + QVideoRendererControl *m_rendererControl; + QWidget *m_widget; + QPainterVideoSurface *m_surface; + Qt::AspectRatioMode m_aspectRatioMode; + QRect m_boundingRect; + QRectF m_sourceRect; + QSize m_nativeSize; + bool m_updatePaintDevice; +}; + +class QVideoWindowControl; + +class QWindowVideoWidgetBackend : public QVideoWidgetBackend +{ + Q_OBJECT +public: + QWindowVideoWidgetBackend(QVideoWindowControl *control, QWidget *widget); + ~QWindowVideoWidgetBackend(); + + void setBrightness(int brightness); + void setContrast(int contrast); + void setHue(int hue); + void setSaturation(int saturation); + + void setFullScreen(bool fullScreen); + + Qt::AspectRatioMode aspectRatioMode() const; + void setAspectRatioMode(Qt::AspectRatioMode mode); + + QSize sizeHint() const; + + void showEvent(); + void hideEvent(QHideEvent *event); + void resizeEvent(QResizeEvent *event); + void moveEvent(QMoveEvent *event); + void paintEvent(QPaintEvent *event); + +private: + QVideoWindowControl *m_windowControl; + QWidget *m_widget; + Qt::AspectRatioMode m_aspectRatioMode; + QSize m_pixelAspectRatio; +}; + +class QMediaService; +class QVideoOutputControl; + +class QVideoWidgetPrivate +{ + Q_DECLARE_PUBLIC(QVideoWidget) +public: + QVideoWidgetPrivate() + : q_ptr(0) + , mediaObject(0) + , service(0) + , outputControl(0) + , widgetBackend(0) + , windowBackend(0) + , rendererBackend(0) + , currentControl(0) + , currentBackend(0) + , brightness(0) + , contrast(0) + , hue(0) + , saturation(0) + , aspectRatioMode(Qt::KeepAspectRatio) + , nonFullScreenFlags(0) + , wasFullScreen(false) + { + } + + QVideoWidget *q_ptr; + QMediaObject *mediaObject; + QMediaService *service; + QVideoOutputControl *outputControl; + QVideoWidgetControlBackend *widgetBackend; + QWindowVideoWidgetBackend *windowBackend; + QRendererVideoWidgetBackend *rendererBackend; + QVideoWidgetControlInterface *currentControl; + QVideoWidgetBackend *currentBackend; + int brightness; + int contrast; + int hue; + int saturation; + Qt::AspectRatioMode aspectRatioMode; + Qt::WindowFlags nonFullScreenFlags; + bool wasFullScreen; + + void setCurrentControl(QVideoWidgetControlInterface *control); + void show(); + void clearService(); + + void _q_serviceDestroyed(); + void _q_mediaObjectDestroyed(); + void _q_brightnessChanged(int brightness); + void _q_contrastChanged(int contrast); + void _q_hueChanged(int hue); + void _q_saturationChanged(int saturation); + void _q_fullScreenChanged(bool fullScreen); + void _q_dimensionsChanged(); +}; + +QT_END_NAMESPACE + +QT_END_HEADER + +#endif diff --git a/src/multimedia/mediaservices/base/qvideowidgetcontrol.cpp b/src/multimedia/mediaservices/base/qvideowidgetcontrol.cpp new file mode 100644 index 0000000..1cc7eaf --- /dev/null +++ b/src/multimedia/mediaservices/base/qvideowidgetcontrol.cpp @@ -0,0 +1,235 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtMediaservices module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include "qmediacontrol_p.h" + + +QT_BEGIN_NAMESPACE + +/*! + \class QVideoWidgetControl + \preliminary + \since 4.7 + \brief The QVideoWidgetControl class provides a media control which + implements a video widget. + + \ingroup multimedia-serv + + The videoWidget() property of QVideoWidgetControl provides a pointer to + a video widget implemented by the control's media service. This widget + is owned by the media service and so care should be taken not to delete it. + + \code + QVideoWidgetControl *widgetControl = mediaService->control(); + + layout->addWidget(widgetControl->widget()); + \endcode + + QVideoWidgetControl is one of number of possible video output controls, + in order to receive video it must be made the active video output + control by setting the output property of QVideoOutputControl to \l {QVideoOutputControl::WidgetOutput}{WidgetOutput}. Consequently any + QMediaService that implements QVideoWidgetControl must also implement + QVideoOutputControl. + + The interface name of QVideoWidgetControl is \c com.nokia.Qt.QVideoWidgetControl/1.0 as + defined in QVideoWidgetControl_iid. + + \sa QMediaService::control(), QVideoOutputControl, QVideoWidget +*/ + +/*! + \macro QVideoWidgetControl_iid + + \c com.nokia.Qt.QVideoWidgetControl/1.0 + + Defines the interface name of the QVideoWidgetControl class. + + \relates QVideoWidgetControl +*/ + +/*! + Constructs a new video widget control with the given \a parent. +*/ +QVideoWidgetControl::QVideoWidgetControl(QObject *parent) + :QMediaControl(parent) +{ +} + +/*! + Destroys a video widget control. +*/ +QVideoWidgetControl::~QVideoWidgetControl() +{ +} + +/*! + \fn QVideoWidgetControl::isFullScreen() const + + Returns true if the video is shown using the complete screen. +*/ + +/*! + \fn QVideoWidgetControl::setFullScreen(bool fullScreen) + + Sets whether a video widget is in \a fullScreen mode. +*/ + +/*! + \fn QVideoWidgetControl::fullScreenChanged(bool fullScreen) + + Signals that the \a fullScreen state of a video widget has changed. +*/ + +/*! + \fn QVideoWidgetControl::aspectRatioMode() const + + Returns how video is scaled to fit the widget with respect to its aspect ratio. +*/ + +/*! + \fn QVideoWidgetControl::setAspectRatioMode(Qt::AspectRatioMode mode) + + Sets the aspect ratio \a mode which determines how video is scaled to the fit the widget with + respect to its aspect ratio. +*/ + +/*! + \fn QVideoWidgetControl::brightness() const + + Returns the brightness adjustment applied to a video. + + Valid brightness values range between -100 and 100, the default is 0. +*/ + +/*! + \fn QVideoWidgetControl::setBrightness(int brightness) + + Sets a \a brightness adjustment for a video. + + Valid brightness values range between -100 and 100, the default is 0. +*/ + +/*! + \fn QVideoWidgetControl::brightnessChanged(int brightness) + + Signals that a video widget's \a brightness adjustment has changed. +*/ + +/*! + \fn QVideoWidgetControl::contrast() const + + Returns the contrast adjustment applied to a video. + + Valid contrast values range between -100 and 100, the default is 0. +*/ + +/*! + \fn QVideoWidgetControl::setContrast(int contrast) + + Sets the contrast adjustment for a video widget to \a contrast. + + Valid contrast values range between -100 and 100, the default is 0. +*/ + + +/*! + \fn QVideoWidgetControl::contrastChanged(int contrast) + + Signals that a video widget's \a contrast adjustment has changed. +*/ + +/*! + \fn QVideoWidgetControl::hue() const + + Returns the hue adjustment applied to a video widget. + + Value hue values range between -100 and 100, the default is 0. +*/ + +/*! + \fn QVideoWidgetControl::setHue(int hue) + + Sets a \a hue adjustment for a video widget. + + Valid hue values range between -100 and 100, the default is 0. +*/ + + +/*! + \fn QVideoWidgetControl::hueChanged(int hue) + + Signals that a video widget's \a hue adjustment has changed. +*/ + +/*! + \fn QVideoWidgetControl::saturation() const + + Returns the saturation adjustment applied to a video widget. + + Value saturation values range between -100 and 100, the default is 0. +*/ + + +/*! + \fn QVideoWidgetControl::setSaturation(int saturation) + + Sets a \a saturation adjustment for a video widget. + + Valid saturation values range between -100 and 100, the default is 0. +*/ + +/*! + \fn QVideoWidgetControl::saturationChanged(int saturation) + + Signals that a video widget's \a saturation adjustment has changed. +*/ + +/*! + \fn QVideoWidgetControl::videoWidget() + + Returns the QWidget. +*/ + +#include "moc_qvideowidgetcontrol.cpp" + +QT_END_NAMESPACE + diff --git a/src/multimedia/mediaservices/base/qvideowidgetcontrol.h b/src/multimedia/mediaservices/base/qvideowidgetcontrol.h new file mode 100644 index 0000000..a8105ac --- /dev/null +++ b/src/multimedia/mediaservices/base/qvideowidgetcontrol.h @@ -0,0 +1,105 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtMediaservices module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QVIDEOWIDGETCONTROL_H +#define QVIDEOWIDGETCONTROL_H + +#include + +#include +#include + + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Multimedia) + + +class QVideoWidgetControlPrivate; + +class Q_MULTIMEDIA_EXPORT QVideoWidgetControl : public QMediaControl +{ + Q_OBJECT + +public: + virtual ~QVideoWidgetControl(); + + virtual QWidget *videoWidget() = 0; + + virtual Qt::AspectRatioMode aspectRatioMode() const = 0; + virtual void setAspectRatioMode(Qt::AspectRatioMode mode) = 0; + + virtual bool isFullScreen() const = 0; + virtual void setFullScreen(bool fullScreen) = 0; + + virtual int brightness() const = 0; + virtual void setBrightness(int brightness) = 0; + + virtual int contrast() const = 0; + virtual void setContrast(int contrast) = 0; + + virtual int hue() const = 0; + virtual void setHue(int hue) = 0; + + virtual int saturation() const = 0; + virtual void setSaturation(int saturation) = 0; + +Q_SIGNALS: + void fullScreenChanged(bool fullScreen); + void brightnessChanged(int brightness); + void contrastChanged(int contrast); + void hueChanged(int hue); + void saturationChanged(int saturation); + +protected: + QVideoWidgetControl(QObject *parent = 0); +}; + +#define QVideoWidgetControl_iid "com.nokia.Qt.QVideoWidgetControl/1.0" +Q_MEDIA_DECLARE_CONTROL(QVideoWidgetControl, QVideoWidgetControl_iid) + +QT_END_NAMESPACE + +QT_END_HEADER + +#endif diff --git a/src/multimedia/mediaservices/base/qvideowindowcontrol.cpp b/src/multimedia/mediaservices/base/qvideowindowcontrol.cpp new file mode 100644 index 0000000..f73b187 --- /dev/null +++ b/src/multimedia/mediaservices/base/qvideowindowcontrol.cpp @@ -0,0 +1,275 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtMediaservices module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include + + +QT_BEGIN_NAMESPACE + +/*! + \class QVideoWindowControl + \preliminary + \since 4.7 + \ingroup multimedia-serv + \brief The QVideoWindowControl class provides a media control for rendering video to a window. + + + The winId() property QVideoWindowControl allows a platform specific + window ID to be set as the video render target of a QMediaService. The + displayRect() property is used to set the region of the window the + video should be rendered to, and the aspectRatioMode() property + indicates how the video should be scaled to fit the displayRect(). + + \code + QVideoWindowControl *windowControl = mediaService->control(); + windowControl->setWinId(widget->winId()); + windowControl->setDisplayRect(widget->rect()); + windowControl->setAspectRatioMode(Qt::KeepAspectRatio); + \endcode + + QVideoWindowControl is one of number of possible video output controls, + in order to receive video it must be made the active video output + control by setting the output property of QVideoOutputControl to \l {QVideoOutputControl::WindowOutput}{WindowOutput}. + Consequently any QMediaService that implements QVideoWindowControl must + also implement QVideoOutputControl. + + \code + QVideoOutputControl *outputControl = mediaService->control(); + outputControl->setOutput(QVideoOutputControl::WindowOutput); + \endcode + + The interface name of QVideoWindowControl is \c com.nokia.Qt.QVideoWindowControl/1.0 as + defined in QVideoWindowControl_iid. + + \sa QMediaService::control(), QVideoOutputControl, QVideoWidget +*/ + +/*! + \macro QVideoWindowControl_iid + + \c com.nokia.Qt.QVideoWindowControl/1.0 + + Defines the interface name of the QVideoWindowControl class. + + \relates QVideoWindowControl +*/ + +/*! + Constructs a new video window control with the given \a parent. +*/ +QVideoWindowControl::QVideoWindowControl(QObject *parent) + : QMediaControl(parent) +{ +} + +/*! + Destroys a video window control. +*/ +QVideoWindowControl::~QVideoWindowControl() +{ +} + +/*! + \fn QVideoWindowControl::winId() const + + Returns the ID of the window a video overlay end point renders to. +*/ + +/*! + \fn QVideoWindowControl::setWinId(WId id) + + Sets the \a id of the window a video overlay end point renders to. +*/ + +/*! + \fn QVideoWindowControl::displayRect() const + Returns the sub-rect of a window where video is displayed. +*/ + +/*! + \fn QVideoWindowControl::setDisplayRect(const QRect &rect) + Sets the sub-\a rect of a window where video is displayed. +*/ + +/*! + \fn QVideoWindowControl::isFullScreen() const + + Identifies if a video overlay is a fullScreen overlay. + + Returns true if the video overlay is fullScreen, and false otherwise. +*/ + +/*! + \fn QVideoWindowControl::setFullScreen(bool fullScreen) + + Sets whether a video overlay is a \a fullScreen overlay. +*/ + +/*! + \fn QVideoWindowControl::fullScreenChanged(bool fullScreen) + + Signals that the \a fullScreen state of a video overlay has changed. +*/ + +/*! + \fn QVideoWindowControl::repaint() + + Repaints the last frame. +*/ + +/*! + \fn QVideoWindowControl::nativeSize() const + + Returns a suggested size for the video display based on the resolution and aspect ratio of the + video. +*/ + +/*! + \fn QVideoWindowControl::nativeSizeChanged() + + Signals that the native dimensions of the video have changed. +*/ + + +/*! + \fn QVideoWindowControl::aspectRatioMode() const + + Returns how video is scaled to fit the display region with respect to its aspect ratio. +*/ + +/*! + \fn QVideoWindowControl::setAspectRatioMode(Qt::AspectRatioMode mode) + + Sets the aspect ratio \a mode which determines how video is scaled to the fit the display region + with respect to its aspect ratio. +*/ + +/*! + \fn QVideoWindowControl::brightness() const + + Returns the brightness adjustment applied to a video overlay. + + Valid brightness values range between -100 and 100, the default is 0. +*/ + +/*! + \fn QVideoWindowControl::setBrightness(int brightness) + + Sets a \a brightness adjustment for a video overlay. + + Valid brightness values range between -100 and 100, the default is 0. +*/ + +/*! + \fn QVideoWindowControl::brightnessChanged(int brightness) + + Signals that a video overlay's \a brightness adjustment has changed. +*/ + +/*! + \fn QVideoWindowControl::contrast() const + + Returns the contrast adjustment applied to a video overlay. + + Valid contrast values range between -100 and 100, the default is 0. +*/ + +/*! + \fn QVideoWindowControl::setContrast(int contrast) + + Sets the \a contrast adjustment for a video overlay. + + Valid contrast values range between -100 and 100, the default is 0. +*/ + +/*! + \fn QVideoWindowControl::contrastChanged(int contrast) + + Signals that a video overlay's \a contrast adjustment has changed. +*/ + +/*! + \fn QVideoWindowControl::hue() const + + Returns the hue adjustment applied to a video overlay. + + Value hue values range between -100 and 100, the default is 0. +*/ + +/*! + \fn QVideoWindowControl::setHue(int hue) + + Sets a \a hue adjustment for a video overlay. + + Valid hue values range between -100 and 100, the default is 0. +*/ + +/*! + \fn QVideoWindowControl::hueChanged(int hue) + + Signals that a video overlay's \a hue adjustment has changed. +*/ + +/*! + \fn QVideoWindowControl::saturation() const + + Returns the saturation adjustment applied to a video overlay. + + Value saturation values range between -100 and 100, the default is 0. +*/ + +/*! + \fn QVideoWindowControl::setSaturation(int saturation) + Sets a \a saturation adjustment for a video overlay. + + Valid saturation values range between -100 and 100, the default is 0. +*/ + +/*! + \fn QVideoWindowControl::saturationChanged(int saturation) + + Signals that a video overlay's \a saturation adjustment has changed. +*/ + +#include "moc_qvideowindowcontrol.cpp" + +QT_END_NAMESPACE + diff --git a/src/multimedia/mediaservices/base/qvideowindowcontrol.h b/src/multimedia/mediaservices/base/qvideowindowcontrol.h new file mode 100644 index 0000000..0fabce9 --- /dev/null +++ b/src/multimedia/mediaservices/base/qvideowindowcontrol.h @@ -0,0 +1,111 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtMediaservices module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QVIDEOWINDOWCONTROL_H +#define QVIDEOWINDOWCONTROL_H + +#include + +#include +#include + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Multimedia) + + +class Q_MULTIMEDIA_EXPORT QVideoWindowControl : public QMediaControl +{ + Q_OBJECT + +public: + ~QVideoWindowControl(); + + virtual WId winId() const = 0; + virtual void setWinId(WId id) = 0; + + virtual QRect displayRect() const = 0; + virtual void setDisplayRect(const QRect &rect) = 0; + + virtual bool isFullScreen() const = 0; + virtual void setFullScreen(bool fullScreen) = 0; + + virtual void repaint() = 0; + + virtual QSize nativeSize() const = 0; + + virtual Qt::AspectRatioMode aspectRatioMode() const = 0; + virtual void setAspectRatioMode(Qt::AspectRatioMode mode) = 0; + + virtual int brightness() const = 0; + virtual void setBrightness(int brightness) = 0; + + virtual int contrast() const = 0; + virtual void setContrast(int contrast) = 0; + + virtual int hue() const = 0; + virtual void setHue(int hue) = 0; + + virtual int saturation() const = 0; + virtual void setSaturation(int saturation) = 0; + +Q_SIGNALS: + void fullScreenChanged(bool fullScreen); + void brightnessChanged(int brightness); + void contrastChanged(int contrast); + void hueChanged(int hue); + void saturationChanged(int saturation); + void nativeSizeChanged(); + +protected: + QVideoWindowControl(QObject *parent = 0); +}; + +#define QVideoWindowControl_iid "com.nokia.Qt.QVideoWindowControl/1.0" +Q_MEDIA_DECLARE_CONTROL(QVideoWindowControl, QVideoWindowControl_iid) + +QT_END_NAMESPACE + +QT_END_HEADER + +#endif diff --git a/src/multimedia/mediaservices/effects/effects.pri b/src/multimedia/mediaservices/effects/effects.pri new file mode 100644 index 0000000..6307255 --- /dev/null +++ b/src/multimedia/mediaservices/effects/effects.pri @@ -0,0 +1,26 @@ + + +unix:!mac { + contains(QT_CONFIG, pulseaudio) { + DEFINES += QT_MULTIMEDIA_PULSEAUDIO + HEADERS += $$PWD/qsoundeffect_pulse_p.h + SOURCES += $$PWD/qsoundeffect_pulse_p.cpp + QMAKE_CXXFLAGS += $$QT_CFLAGS_PULSEAUDIO + LIBS += $$QT_LIBS_PULSEAUDIO + } else { + DEFINES += QT_MULTIMEDIA_QMEDIAPLAYER + HEADERS += $$PWD/qsoundeffect_qmedia_p.h + SOURCES += $$PWD/qsoundeffect_qmedia_p.cpp + } +} else { + HEADERS += $$PWD/qsoundeffect_qsound_p.h + SOURCES += $$PWD/qsoundeffect_qsound_p.cpp +} + +HEADERS += \ + $$PWD/qsoundeffect_p.h \ + $$PWD/wavedecoder_p.h + +SOURCES += \ + $$PWD/qsoundeffect.cpp \ + $$PWD/wavedecoder_p.cpp diff --git a/src/multimedia/mediaservices/effects/qsoundeffect.cpp b/src/multimedia/mediaservices/effects/qsoundeffect.cpp new file mode 100644 index 0000000..8a38103 --- /dev/null +++ b/src/multimedia/mediaservices/effects/qsoundeffect.cpp @@ -0,0 +1,207 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtMultimedia module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qsoundeffect_p.h" + +#if defined(QT_MULTIMEDIA_PULSEAUDIO) +#include "qsoundeffect_pulse_p.h" +#elif(QT_MULTIMEDIA_QMEDIAPLAYER) +#include "qsoundeffect_qmedia_p.h" +#else +#include "qsoundeffect_qsound_p.h" +#endif + +QT_BEGIN_NAMESPACE + +/*! + \qmlclass SoundEffect QSoundEffect + \since 4.7 + \brief The SoundEffect element provides a way to play sound effects in qml. + + This element is part of the \bold{Qt.multimedia 4.7} module. + + The following example plays a wav file on mouse click. + + \qml + import Qt 4.6 + import Qt.multimedia 4.7 + + Item { + SoundEffect { + id: playSound + source: "test.wav" + } + MouseArea { + id: playArea + anchors.fill: parent + onPressed: { + playSound.play() + } + } + } + \endqml +*/ + +/*! + \qmlproperty QUrl SoundEffect::source + + This property provides a way to control the sound to play. +*/ + +/*! + \qmlproperty int SoundEffect::loops + + This property provides a way to control the number of times to repeat the sound on each play(). +*/ + +/*! + \qmlproperty int SoundEffect::volume + + This property provides a way to control the volume for playback. +*/ + +/*! + \qmlproperty bool SoundEffect::muted + + This property provides a way to control muting. +*/ + +/*! + \qmlsignal SoundEffect::sourceChanged() + + This handler is called when the source has changed. +*/ + +/*! + \qmlsignal SoundEffect::loopsChanged() + + This handler is called when the number of loops has changes. +*/ + +/*! + \qmlsignal SoundEffect::volumeChanged() + + This handler is called when the volume has changed. +*/ + +/*! + \qmlsignal SoundEffect::mutedChanged() + + This handler is called when the mute state has changed. +*/ + + +QSoundEffect::QSoundEffect(QObject *parent) : + QObject(parent) +{ + d = new QSoundEffectPrivate(this); + connect(d, SIGNAL(volumeChanged()), SIGNAL(volumeChanged())); + connect(d, SIGNAL(mutedChanged()), SIGNAL(mutedChanged())); +} + +QSoundEffect::~QSoundEffect() +{ + d->deleteLater(); +} + +QUrl QSoundEffect::source() const +{ + return d->source(); +} + +void QSoundEffect::setSource(const QUrl &url) +{ + if (d->source() == url) + return; + + d->setSource(url); + + emit sourceChanged(); +} + +int QSoundEffect::loops() const +{ + return d->loopCount(); +} + +void QSoundEffect::setLoops(int loopCount) +{ + if (d->loopCount() == loopCount) + return; + + d->setLoopCount(loopCount); + emit loopsChanged(); +} + +int QSoundEffect::volume() const +{ + return d->volume(); +} + +void QSoundEffect::setVolume(int volume) +{ + if (d->volume() == volume) + return; + + d->setVolume(volume); + emit volumeChanged(); +} + +bool QSoundEffect::isMuted() const +{ + return d->isMuted(); +} + +void QSoundEffect::setMuted(bool muted) +{ + if (d->isMuted() == muted) + return; + + d->setMuted(muted); + emit mutedChanged(); +} + +void QSoundEffect::play() +{ + d->play(); +} + +QT_END_NAMESPACE diff --git a/src/multimedia/mediaservices/effects/qsoundeffect_p.h b/src/multimedia/mediaservices/effects/qsoundeffect_p.h new file mode 100644 index 0000000..8c8985a --- /dev/null +++ b/src/multimedia/mediaservices/effects/qsoundeffect_p.h @@ -0,0 +1,109 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtMediaservices module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QSOUNDEFFECT_H +#define QSOUNDEFFECT_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + + +#include +#include + + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +class QSoundEffectPrivate; +class Q_MULTIMEDIA_EXPORT QSoundEffect : public QObject +{ + Q_OBJECT + Q_PROPERTY(QUrl source READ source WRITE setSource NOTIFY sourceChanged) + Q_PROPERTY(int loops READ loops WRITE setLoops NOTIFY loopsChanged) + Q_PROPERTY(int volume READ volume WRITE setVolume NOTIFY volumeChanged) + Q_PROPERTY(bool muted READ isMuted WRITE setMuted NOTIFY mutedChanged) + +public: + explicit QSoundEffect(QObject *parent = 0); + ~QSoundEffect(); + + QUrl source() const; + void setSource(const QUrl &url); + + int loops() const; + void setLoops(int loopCount); + + int volume() const; + void setVolume(int volume); + + bool isMuted() const; + void setMuted(bool muted); + +Q_SIGNALS: + void sourceChanged(); + void loopsChanged(); + void volumeChanged(); + void mutedChanged(); + +public Q_SLOTS: + void play(); + +private: + Q_DISABLE_COPY(QSoundEffect) + QSoundEffectPrivate* d; +}; + +QT_END_NAMESPACE + +QT_END_HEADER + + +#endif // QSOUNDEFFECT_H diff --git a/src/multimedia/mediaservices/effects/qsoundeffect_pulse_p.cpp b/src/multimedia/mediaservices/effects/qsoundeffect_pulse_p.cpp new file mode 100644 index 0000000..e834280 --- /dev/null +++ b/src/multimedia/mediaservices/effects/qsoundeffect_pulse_p.cpp @@ -0,0 +1,499 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtMediaservices module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include +#include +#include +#include + +#include "wavedecoder_p.h" + +#include "qsoundeffect_pulse_p.h" + +#if defined(Q_WS_MAEMO_5) +#include +#endif + +#include + +// Less than ideal +#define PA_SCACHE_ENTRY_SIZE_MAX (1024*1024*16) + +QT_BEGIN_NAMESPACE + +namespace +{ +inline pa_sample_spec audioFormatToSampleSpec(const QAudioFormat &format) +{ + pa_sample_spec spec; + + spec.rate = format.frequency(); + spec.channels = format.channels(); + + if (format.sampleSize() == 8) + spec.format = PA_SAMPLE_U8; + else if (format.sampleSize() == 16) { + switch (format.byteOrder()) { + case QAudioFormat::BigEndian: spec.format = PA_SAMPLE_S16BE; break; + case QAudioFormat::LittleEndian: spec.format = PA_SAMPLE_S16LE; break; + } + } + else if (format.sampleSize() == 32) { + switch (format.byteOrder()) { + case QAudioFormat::BigEndian: spec.format = PA_SAMPLE_S32BE; break; + case QAudioFormat::LittleEndian: spec.format = PA_SAMPLE_S32LE; break; + } + } + + return spec; +} + +class PulseDaemon +{ +public: + PulseDaemon():m_prepared(false) + { + prepare(); + } + + ~PulseDaemon() + { + if (m_prepared) + release(); + } + + inline void lock() + { + pa_threaded_mainloop_lock(m_mainLoop); + } + + inline void unlock() + { + pa_threaded_mainloop_unlock(m_mainLoop); + } + + inline pa_context *context() const + { + return m_context; + } + + int volume() + { + return m_vol; + } + +private: + void prepare() + { + m_vol = 100; + + m_mainLoop = pa_threaded_mainloop_new(); + if (m_mainLoop == 0) { + qWarning("PulseAudioService: unable to create pulseaudio mainloop"); + return; + } + + if (pa_threaded_mainloop_start(m_mainLoop) != 0) { + qWarning("PulseAudioService: unable to start pulseaudio mainloop"); + pa_threaded_mainloop_free(m_mainLoop); + return; + } + + m_mainLoopApi = pa_threaded_mainloop_get_api(m_mainLoop); + + lock(); + m_context = pa_context_new(m_mainLoopApi, QString(QLatin1String("QtPulseAudio:%1")).arg(::getpid()).toAscii().constData()); + +#if defined(Q_WS_MAEMO_5) + pa_context_set_state_callback(m_context, context_state_callback, this); +#endif + if (m_context == 0) { + qWarning("PulseAudioService: Unable to create new pulseaudio context"); + pa_threaded_mainloop_free(m_mainLoop); + return; + } + + if (pa_context_connect(m_context, NULL, (pa_context_flags_t)0, NULL) < 0) { + qWarning("PulseAudioService: pa_context_connect() failed"); + pa_context_unref(m_context); + pa_threaded_mainloop_free(m_mainLoop); + return; + } + unlock(); + + m_prepared = true; + } + + void release() + { + if (!m_prepared) return; + pa_threaded_mainloop_stop(m_mainLoop); + pa_threaded_mainloop_free(m_mainLoop); + m_prepared = false; + } + +#if defined(Q_WS_MAEMO_5) + static void context_state_callback(pa_context *c, void *userdata) + { + PulseDaemon *self = reinterpret_cast(userdata); + switch (pa_context_get_state(c)) { + case PA_CONTEXT_CONNECTING: + case PA_CONTEXT_AUTHORIZING: + case PA_CONTEXT_SETTING_NAME: + break; + case PA_CONTEXT_READY: + pa_ext_stream_restore_set_subscribe_cb(c, &stream_restore_monitor_callback, self); + pa_ext_stream_restore_subscribe(c, 1, NULL, self); + break; + default: + break; + } + } + static void stream_restore_monitor_callback(pa_context *c, void *userdata) + { + PulseDaemon *self = reinterpret_cast(userdata); + pa_ext_stream_restore2_read(c, &stream_restore_info_callback, self); + } + static void stream_restore_info_callback(pa_context *c, const pa_ext_stream_restore2_info *info, + int eol, void *userdata) + { + Q_UNUSED(c) + + PulseDaemon *self = reinterpret_cast(userdata); + + if (!eol) { + if (QString(info->name).startsWith(QLatin1String("sink-input-by-media-role:x-maemo"))) { + const unsigned str_length = 256; + char str[str_length]; + pa_cvolume_snprint(str, str_length, &info->volume); + self->m_vol = QString(str).replace(" ","").replace("%","").mid(2).toInt(); + } + } + } +#endif + + int m_vol; + bool m_prepared; + pa_context *m_context; + pa_threaded_mainloop *m_mainLoop; + pa_mainloop_api *m_mainLoopApi; +}; +} + +Q_GLOBAL_STATIC(PulseDaemon, daemon) + + +QSoundEffectPrivate::QSoundEffectPrivate(QObject* parent): + QObject(parent), + m_retry(false), + m_muted(false), + m_playQueued(false), + m_sampleLoaded(false), + m_volume(100), + m_duration(0), + m_dataUploaded(0), + m_loopCount(1), + m_runningCount(0), + m_reply(0), + m_stream(0), + m_networkAccessManager(0) +{ +} + +QSoundEffectPrivate::~QSoundEffectPrivate() +{ + m_reply->deleteLater(); + unloadSample(); +} + +QUrl QSoundEffectPrivate::source() const +{ + return m_source; +} + +void QSoundEffectPrivate::setSource(const QUrl &url) +{ + if (url.isEmpty()) { + m_source = QUrl(); + unloadSample(); + return; + } + + m_source = url; + + if (m_networkAccessManager == 0) + m_networkAccessManager = new QNetworkAccessManager(this); + + m_stream = m_networkAccessManager->get(QNetworkRequest(m_source)); + + unloadSample(); + loadSample(); +} + +int QSoundEffectPrivate::loopCount() const +{ + return m_loopCount; +} + +void QSoundEffectPrivate::setLoopCount(int loopCount) +{ + m_loopCount = loopCount; +} + +int QSoundEffectPrivate::volume() const +{ + return m_volume; +} + +void QSoundEffectPrivate::setVolume(int volume) +{ + m_volume = volume; +} + +bool QSoundEffectPrivate::isMuted() const +{ + return m_muted; +} + +void QSoundEffectPrivate::setMuted(bool muted) +{ + m_muted = muted; +} + +void QSoundEffectPrivate::play() +{ + if (m_retry) { + m_retry = false; + setSource(m_source); + return; + } + + if (!m_sampleLoaded) { + m_playQueued = true; + return; + } + + m_runningCount += m_loopCount; + + playSample(); +} + +void QSoundEffectPrivate::decoderReady() +{ + if (m_waveDecoder->size() >= PA_SCACHE_ENTRY_SIZE_MAX) { + m_waveDecoder->deleteLater(); + qWarning("QSoundEffect(pulseaudio): Attempting to load to large a sample"); + return; + } + + if (m_name.isNull()) + m_name = QString(QLatin1String("QtPulseSample-%1-%2")).arg(::getpid()).arg(quintptr(this)).toUtf8(); + + pa_sample_spec spec = audioFormatToSampleSpec(m_waveDecoder->audioFormat()); + + daemon()->lock(); + pa_stream *stream = pa_stream_new(daemon()->context(), m_name.constData(), &spec, 0); + pa_stream_set_state_callback(stream, stream_state_callback, this); + pa_stream_set_write_callback(stream, stream_write_callback, this); + pa_stream_connect_upload(stream, (size_t)m_waveDecoder->size()); + m_pulseStream = stream; + daemon()->unlock(); +} + +void QSoundEffectPrivate::decoderError() +{ + qWarning("QSoundEffect(pulseaudio): Error decoding source"); +} + +void QSoundEffectPrivate::checkPlayTime() +{ + int elapsed = m_playbackTime.elapsed(); + + if (elapsed < m_duration) + startTimer(m_duration - elapsed); +} + +void QSoundEffectPrivate::loadSample() +{ + m_sampleLoaded = false; + m_dataUploaded = 0; + m_waveDecoder = new WaveDecoder(m_stream); + connect(m_waveDecoder, SIGNAL(formatKnown()), SLOT(decoderReady())); + connect(m_waveDecoder, SIGNAL(invalidFormat()), SLOT(decoderError())); +} + +void QSoundEffectPrivate::unloadSample() +{ + if (!m_sampleLoaded) + return; + + daemon()->lock(); + pa_context_remove_sample(daemon()->context(), m_name.constData(), NULL, NULL); + daemon()->unlock(); + + m_duration = 0; + m_dataUploaded = 0; + m_sampleLoaded = false; +} + +void QSoundEffectPrivate::uploadSample() +{ + daemon()->lock(); + + size_t bufferSize = qMin(pa_stream_writable_size(m_pulseStream), + size_t(m_waveDecoder->bytesAvailable())); + char buffer[bufferSize]; + + size_t len = 0; + while (len < (m_waveDecoder->size())) { + qint64 read = m_waveDecoder->read(buffer, qMin((int)bufferSize, + (int)(m_waveDecoder->size()-len))); + if (read > 0) { + if (pa_stream_write(m_pulseStream, buffer, size_t(read), 0, 0, PA_SEEK_RELATIVE) == 0) + len += size_t(read); + else + break; + } + } + + m_dataUploaded += len; + pa_stream_set_write_callback(m_pulseStream, NULL, NULL); + + if (m_waveDecoder->size() == m_dataUploaded) { + int err = pa_stream_finish_upload(m_pulseStream); + if(err != 0) { + qWarning("pa_stream_finish_upload() err=%d",err); + pa_stream_disconnect(m_pulseStream); + m_retry = true; + m_playQueued = false; + QMetaObject::invokeMethod(this, "play"); + daemon()->unlock(); + return; + } + m_duration = m_waveDecoder->duration(); + m_waveDecoder->deleteLater(); + m_stream->deleteLater(); + m_sampleLoaded = true; + if (m_playQueued) { + m_playQueued = false; + QMetaObject::invokeMethod(this, "play"); + } + } + daemon()->unlock(); +} + +void QSoundEffectPrivate::playSample() +{ + pa_volume_t volume = PA_VOLUME_NORM; + + daemon()->lock(); +#ifdef Q_WS_MAEMO_5 + volume = PA_VOLUME_NORM / 100 * ((daemon()->volume() + m_volume) / 2); +#endif + pa_operation_unref( + pa_context_play_sample(daemon()->context(), + m_name.constData(), + 0, + volume, + play_callback, + this) + ); + daemon()->unlock(); + + m_playbackTime.start(); +} + +void QSoundEffectPrivate::timerEvent(QTimerEvent *event) +{ + if (m_runningCount > 0) + playSample(); + + killTimer(event->timerId()); +} + +void QSoundEffectPrivate::stream_write_callback(pa_stream *s, size_t length, void *userdata) +{ + Q_UNUSED(length); + + QSoundEffectPrivate *self = reinterpret_cast(userdata); + + QMetaObject::invokeMethod(self, "uploadSample", Qt::QueuedConnection); +} + +void QSoundEffectPrivate::stream_state_callback(pa_stream *s, void *userdata) +{ + switch (pa_stream_get_state(s)) { + case PA_STREAM_CREATING: + case PA_STREAM_READY: + case PA_STREAM_TERMINATED: + break; + + case PA_STREAM_FAILED: + default: + qWarning("QSoundEffect(pulseaudio): Error in pulse audio stream"); + break; + } +} + +void QSoundEffectPrivate::play_callback(pa_context *c, int success, void *userdata) +{ + Q_UNUSED(c); + + QSoundEffectPrivate *self = reinterpret_cast(userdata); + + if (success == 1) { + self->m_runningCount--; + QMetaObject::invokeMethod(self, "checkPlayTime", Qt::QueuedConnection); + } +} + +QT_END_NAMESPACE diff --git a/src/multimedia/mediaservices/effects/qsoundeffect_pulse_p.h b/src/multimedia/mediaservices/effects/qsoundeffect_pulse_p.h new file mode 100644 index 0000000..ef6bff1 --- /dev/null +++ b/src/multimedia/mediaservices/effects/qsoundeffect_pulse_p.h @@ -0,0 +1,137 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtMediaservices module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QSOUNDEFFECT_PULSE_H +#define QSOUNDEFFECT_PULSE_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + + +#include "qsoundeffect_p.h" + +#include +#include +#include +#include + + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +class QNetworkReply; +class QNetworkAccessManager; +class WaveDecoder; + +class QSoundEffectPrivate : public QObject +{ + Q_OBJECT +public: + explicit QSoundEffectPrivate(QObject* parent); + ~QSoundEffectPrivate(); + + QUrl source() const; + void setSource(const QUrl &url); + int loopCount() const; + void setLoopCount(int loopCount); + int volume() const; + void setVolume(int volume); + bool isMuted() const; + void setMuted(bool muted); + +public Q_SLOTS: + void play(); + +Q_SIGNALS: + void volumeChanged(); + void mutedChanged(); + +private Q_SLOTS: + void decoderReady(); + void decoderError(); + void checkPlayTime(); + void uploadSample(); + +private: + void loadSample(); + void unloadSample(); + void playSample(); + + void timerEvent(QTimerEvent *event); + + static void stream_write_callback(pa_stream *s, size_t length, void *userdata); + static void stream_state_callback(pa_stream *s, void *userdata); + static void play_callback(pa_context *c, int success, void *userdata); + + pa_stream *m_pulseStream; + + bool m_retry; + bool m_muted; + bool m_playQueued; + bool m_sampleLoaded; + int m_volume; + int m_duration; + int m_dataUploaded; + int m_loopCount; + int m_runningCount; + QUrl m_source; + QTime m_playbackTime; + QByteArray m_name; + QNetworkReply *m_reply; + WaveDecoder *m_waveDecoder; + QIODevice *m_stream; + QNetworkAccessManager *m_networkAccessManager; +}; + +QT_END_NAMESPACE + +QT_END_HEADER + +#endif // QSOUNDEFFECT_PULSE_H diff --git a/src/multimedia/mediaservices/effects/qsoundeffect_qmedia_p.cpp b/src/multimedia/mediaservices/effects/qsoundeffect_qmedia_p.cpp new file mode 100644 index 0000000..8cc2675 --- /dev/null +++ b/src/multimedia/mediaservices/effects/qsoundeffect_qmedia_p.cpp @@ -0,0 +1,132 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtMediaservices module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include "qsoundeffect_qmedia_p.h" + +#include + +#include +#include + + +QT_BEGIN_NAMESPACE + +QSoundEffectPrivate::QSoundEffectPrivate(QObject* parent): + QObject(parent), + m_loopCount(1), + m_runningCount(0), + m_player(0) +{ + m_player = new QMediaPlayer(this, QMediaPlayer::LowLatency); + connect(m_player, SIGNAL(stateChanged(QMediaPlayer::State)), SLOT(stateChanged(QMediaPlayer::State))); +} + +QSoundEffectPrivate::~QSoundEffectPrivate() +{ +} + +QUrl QSoundEffectPrivate::source() const +{ + return m_player->media().canonicalUrl(); +} + +void QSoundEffectPrivate::setSource(const QUrl &url) +{ + m_player->setMedia(url); +} + +int QSoundEffectPrivate::loopCount() const +{ + return m_loopCount; +} + +void QSoundEffectPrivate::setLoopCount(int loopCount) +{ + m_loopCount = loopCount; +} + +int QSoundEffectPrivate::volume() const +{ + return m_player->volume(); +} + +void QSoundEffectPrivate::setVolume(int volume) +{ + m_player->setVolume(volume); +} + +bool QSoundEffectPrivate::isMuted() const +{ + return m_player->isMuted(); +} + +void QSoundEffectPrivate::setMuted(bool muted) +{ + m_player->setMuted(muted); +} + +void QSoundEffectPrivate::play() +{ + m_runningCount += m_loopCount; + m_player->play(); +} + +void QSoundEffectPrivate::stateChanged(QMediaPlayer::State state) +{ + if (state == QMediaPlayer::StoppedState) { + if (--m_runningCount > 0) + m_player->play(); + } +} + +QT_END_NAMESPACE + diff --git a/src/multimedia/mediaservices/effects/qsoundeffect_qmedia_p.h b/src/multimedia/mediaservices/effects/qsoundeffect_qmedia_p.h new file mode 100644 index 0000000..5abdcad --- /dev/null +++ b/src/multimedia/mediaservices/effects/qsoundeffect_qmedia_p.h @@ -0,0 +1,103 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtMediaservices module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QSOUNDEFFECT_QMEDIA_H +#define QSOUNDEFFECT_QMEDIA_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + + +#include +#include +#include + + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + + +class QSoundEffectPrivate : public QObject +{ + Q_OBJECT +public: + explicit QSoundEffectPrivate(QObject* parent); + ~QSoundEffectPrivate(); + + QUrl source() const; + void setSource(const QUrl &url); + int loopCount() const; + void setLoopCount(int loopCount); + int volume() const; + void setVolume(int volume); + bool isMuted() const; + void setMuted(bool muted); + +public Q_SLOTS: + void play(); + +Q_SIGNALS: + void volumeChanged(); + void mutedChanged(); + +private Q_SLOTS: + void stateChanged(QMediaPlayer::State); + +private: + int m_loopCount; + int m_runningCount; + QMediaPlayer *m_player; +}; + +QT_END_NAMESPACE + +QT_END_HEADER + +#endif // QSOUNDEFFECT_QMEDIA_H diff --git a/src/multimedia/mediaservices/effects/qsoundeffect_qsound_p.cpp b/src/multimedia/mediaservices/effects/qsoundeffect_qsound_p.cpp new file mode 100644 index 0000000..7746f0c --- /dev/null +++ b/src/multimedia/mediaservices/effects/qsoundeffect_qsound_p.cpp @@ -0,0 +1,131 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtMediaservices module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include "qsoundeffect_qsound_p.h" + +#include +#include + + +QT_BEGIN_NAMESPACE + +QSoundEffectPrivate::QSoundEffectPrivate(QObject* parent): + QObject(parent), + m_muted(false), + m_loopCount(1), + m_volume(100), + m_sound(0) +{ +} + +QSoundEffectPrivate::~QSoundEffectPrivate() +{ +} + +QUrl QSoundEffectPrivate::source() const +{ + return m_source; +} + +void QSoundEffectPrivate::setSource(const QUrl &url) +{ + if (url.isEmpty() || url.scheme() != QLatin1String("file")) { + m_source = QUrl(); + return; + } + + if (m_sound != 0) + delete m_sound; + + m_source = url; + m_sound = new QSound(m_source.toLocalFile(), this); + m_sound->setLoops(m_loopCount); +} + +int QSoundEffectPrivate::loopCount() const +{ + return m_loopCount; +} + +void QSoundEffectPrivate::setLoopCount(int lc) +{ + m_loopCount = lc; + if (m_sound) + m_sound->setLoops(lc); +} + +int QSoundEffectPrivate::volume() const +{ + return m_volume; +} + +void QSoundEffectPrivate::setVolume(int v) +{ + m_volume = v; +} + +bool QSoundEffectPrivate::isMuted() const +{ + return m_muted; +} + +void QSoundEffectPrivate::setMuted(bool muted) +{ + m_muted = muted; +} + +void QSoundEffectPrivate::play() +{ + m_sound->play(); +} + +QT_END_NAMESPACE diff --git a/src/multimedia/mediaservices/effects/qsoundeffect_qsound_p.h b/src/multimedia/mediaservices/effects/qsoundeffect_qsound_p.h new file mode 100644 index 0000000..133e6ec --- /dev/null +++ b/src/multimedia/mediaservices/effects/qsoundeffect_qsound_p.h @@ -0,0 +1,102 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtMediaservices module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QSOUNDEFFECT_QSOUND_H +#define QSOUNDEFFECT_QSOUND_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + + +#include +#include + + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +class QSound; + +class QSoundEffectPrivate : public QObject +{ + Q_OBJECT +public: + explicit QSoundEffectPrivate(QObject* parent); + ~QSoundEffectPrivate(); + + QUrl source() const; + void setSource(const QUrl &url); + int loopCount() const; + void setLoopCount(int loopCount); + int volume() const; + void setVolume(int volume); + bool isMuted() const; + void setMuted(bool muted); + +public Q_SLOTS: + void play(); + +Q_SIGNALS: + void volumeChanged(); + void mutedChanged(); + +private: + bool m_muted; + int m_loopCount; + int m_volume; + QSound *m_sound; + QUrl m_source; +}; + +QT_END_NAMESPACE + +QT_END_HEADER + +#endif // QSOUNDEFFECT_QSOUND_H diff --git a/src/multimedia/mediaservices/effects/wavedecoder_p.cpp b/src/multimedia/mediaservices/effects/wavedecoder_p.cpp new file mode 100644 index 0000000..2208461 --- /dev/null +++ b/src/multimedia/mediaservices/effects/wavedecoder_p.cpp @@ -0,0 +1,151 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtMediaservices module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "wavedecoder_p.h" + +#include +#include + +QT_BEGIN_NAMESPACE + +WaveDecoder::WaveDecoder(QIODevice *s, QObject *parent): + QIODevice(parent), + haveFormat(false), + dataSize(0), + remaining(0), + source(s) +{ + open(QIODevice::ReadOnly | QIODevice::Unbuffered); + + if (source->bytesAvailable() >= qint64(sizeof(CombinedHeader) + sizeof(DATAHeader) + sizeof(quint16))) + QTimer::singleShot(0, this, SLOT(handleData())); + else + connect(source, SIGNAL(readyRead()), SLOT(handleData())); +} + +WaveDecoder::~WaveDecoder() +{ +} + +QAudioFormat WaveDecoder::audioFormat() const +{ + return format; +} + +int WaveDecoder::duration() const +{ + return size() * 1000 / (format.sampleSize() / 8) / format.channels() / format.frequency(); +} + +qint64 WaveDecoder::size() const +{ + return haveFormat ? dataSize : 0; +} + +bool WaveDecoder::isSequential() const +{ + return source->isSequential(); +} + +qint64 WaveDecoder::bytesAvailable() const +{ + return haveFormat ? source->bytesAvailable() : 0; +} + +qint64 WaveDecoder::readData(char *data, qint64 maxlen) +{ + return haveFormat ? source->read(data, maxlen) : 0; +} + +qint64 WaveDecoder::writeData(const char *data, qint64 len) +{ + Q_UNUSED(data); + Q_UNUSED(len); + + return -1; +} + +void WaveDecoder::handleData() +{ + if (source->bytesAvailable() < qint64(sizeof(CombinedHeader) + sizeof(DATAHeader) + sizeof(quint16))) + return; + + source->disconnect(SIGNAL(readyRead()), this, SLOT(handleData())); + source->read((char*)&header, sizeof(CombinedHeader)); + + if (qstrncmp(header.riff.descriptor.id, "RIFF", 4) != 0 || + qstrncmp(header.riff.type, "WAVE", 4) != 0 || + qstrncmp(header.wave.descriptor.id, "fmt ", 4) != 0 || + (header.wave.audioFormat != 0 && header.wave.audioFormat != 1)) { + + emit invalidFormat(); + } + else { + DATAHeader dataHeader; + + if (qFromLittleEndian(header.wave.descriptor.size) > sizeof(WAVEHeader)) { + // Extended data available + quint16 extraFormatBytes; + source->peek((char*)&extraFormatBytes, sizeof(quint16)); + extraFormatBytes = qFromLittleEndian(extraFormatBytes); + source->read(sizeof(quint16) + extraFormatBytes); // dump it all + } + + source->read((char*)&dataHeader, sizeof(DATAHeader)); + + int bps = qFromLittleEndian(header.wave.bitsPerSample); + + format.setCodec(QLatin1String("audio/pcm")); + format.setSampleType(bps == 8 ? QAudioFormat::UnSignedInt : QAudioFormat::SignedInt); + format.setByteOrder(QAudioFormat::LittleEndian); + format.setFrequency(qFromLittleEndian(header.wave.sampleRate)); + format.setSampleSize(bps); + format.setChannels(qFromLittleEndian(header.wave.numChannels)); + + dataSize = qFromLittleEndian(dataHeader.descriptor.size); + + haveFormat = true; + connect(source, SIGNAL(readyRead()), SIGNAL(readyRead())); + emit formatKnown(); + } +} + +QT_END_NAMESPACE diff --git a/src/multimedia/mediaservices/effects/wavedecoder_p.h b/src/multimedia/mediaservices/effects/wavedecoder_p.h new file mode 100644 index 0000000..bb22907 --- /dev/null +++ b/src/multimedia/mediaservices/effects/wavedecoder_p.h @@ -0,0 +1,133 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtMediaservices module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef WAVEDECODER_H +#define WAVEDECODER_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists for the convenience +// of other Qt classes. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include +#include + + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + + +class WaveDecoder : public QIODevice +{ + Q_OBJECT + +public: + explicit WaveDecoder(QIODevice *source, QObject *parent = 0); + ~WaveDecoder(); + + QAudioFormat audioFormat() const; + int duration() const; + + qint64 size() const; + bool isSequential() const; + qint64 bytesAvailable() const; + +Q_SIGNALS: + void formatKnown(); + void invalidFormat(); + +private Q_SLOTS: + void handleData(); + +private: + qint64 readData(char *data, qint64 maxlen); + qint64 writeData(const char *data, qint64 len); + + struct chunk + { + char id[4]; + quint32 size; + }; + struct RIFFHeader + { + chunk descriptor; + char type[4]; + }; + struct WAVEHeader + { + chunk descriptor; + quint16 audioFormat; + quint16 numChannels; + quint32 sampleRate; + quint32 byteRate; + quint16 blockAlign; + quint16 bitsPerSample; + }; + struct DATAHeader + { + chunk descriptor; + }; + struct CombinedHeader + { + RIFFHeader riff; + WAVEHeader wave; + }; + + bool haveFormat; + qint64 dataSize; + qint64 remaining; + QAudioFormat format; + QIODevice *source; + CombinedHeader header; +}; + +QT_END_NAMESPACE + +QT_END_HEADER + +#endif // WAVEDECODER_H diff --git a/src/multimedia/mediaservices/mediaservices.pro b/src/multimedia/mediaservices/mediaservices.pro new file mode 100644 index 0000000..908f60a --- /dev/null +++ b/src/multimedia/mediaservices/mediaservices.pro @@ -0,0 +1,16 @@ +TARGET = QtMediaservices +QPRO_PWD = $$PWD +QT = core gui multimedia + +DEFINES += QT_BUILD_MEDIASERVICES_LIB QT_NO_USING_NAMESPACE + +unix:QMAKE_PKGCONFIG_REQUIRES = QtCore QtGui QtMultimedia + +include(../../qbase.pri) + +include(base/base.pri) +include(playback/playback.pri) +include(effects/effects.pri) + +symbian: TARGET.UID3 = 0x2001E631 + diff --git a/src/multimedia/mediaservices/playback/playback.pri b/src/multimedia/mediaservices/playback/playback.pri new file mode 100644 index 0000000..09a81c9 --- /dev/null +++ b/src/multimedia/mediaservices/playback/playback.pri @@ -0,0 +1,11 @@ + +HEADERS += \ + $$PWD/qmediaplayer.h \ + $$PWD/qmediaplayercontrol.h + +SOURCES += \ + $$PWD/qmediaplayer.cpp \ + $$PWD/qmediaplayercontrol.cpp + + + diff --git a/src/multimedia/mediaservices/playback/qmediaplayer.cpp b/src/multimedia/mediaservices/playback/qmediaplayer.cpp new file mode 100644 index 0000000..676a6eb --- /dev/null +++ b/src/multimedia/mediaservices/playback/qmediaplayer.cpp @@ -0,0 +1,982 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtMediaservices module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include +#include +#include +#include + +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +//#define DEBUG_PLAYER_STATE + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Multimedia) + +/*! + \class QMediaPlayer + \brief The QMediaPlayer class allows the playing of a media source. + \ingroup multimedia + \since 4.7 + \preliminary + + The QMediaPlayer class is a high level media playback class. It can be used + to playback such content as songs, movies and internet radio. The content + to playback is specified as a QMediaContent, which can be thought of as a + main or canonical URL with addition information attached. When provided + with a QMediaContent playback may be able to commence. + + \code + player = new QMediaPlayer; + connect(player, SIGNAL(positionChanged(qint64)), this, SLOT(positionChanged(qint64))); + player->setMedia(QUrl::fromLocalFile("/Users/me/Music/coolsong.mp3")); + player->setVolume(50); + player->play(); + \endcode + + QVideoWidget can be used with QMediaPlayer for video rendering and QMediaPlaylist + for accessing playlist functionality. + + \code + player = new QMediaPlayer; + + playlist = new QMediaPlaylist; + playlist->setMediaObject(player); + playlist->append(QUrl("http://example.com/movie1.mp4")); + playlist->append(QUrl("http://example.com/movie2.mp4")); + + widget = new QVideoWidget; + widget->setMediaObject(player); + widget->show(); + + player->play(); + \endcode + + \sa QMediaObject, QMediaService, QVideoWidget, QMediaPlaylist +*/ + +namespace +{ +class MediaPlayerRegisterMetaTypes +{ +public: + MediaPlayerRegisterMetaTypes() + { + qRegisterMetaType(); + qRegisterMetaType(); + qRegisterMetaType(); + } +} _registerPlayerMetaTypes; +} + +class QMediaPlayerPrivate : public QMediaObjectPrivate +{ + Q_DECLARE_NON_CONST_PUBLIC(QMediaPlayer) + +public: + QMediaPlayerPrivate() + : provider(0) + , control(0) + , playlistControl(0) + , state(QMediaPlayer::StoppedState) + , error(QMediaPlayer::NoError) + , filterStates(false) + , playlist(0) + {} + + QMediaServiceProvider *provider; + QMediaPlayerControl* control; + QMediaPlaylistControl* playlistControl; + QMediaPlayer::State state; + QMediaPlayer::Error error; + QString errorString; + bool filterStates; + + QMediaPlaylist *playlist; + QPointer videoWidget; + QPointer videoItem; + + void _q_stateChanged(QMediaPlayer::State state); + void _q_mediaStatusChanged(QMediaPlayer::MediaStatus status); + void _q_error(int error, const QString &errorString); + void _q_updateMedia(const QMediaContent&); + void _q_playlistDestroyed(); +}; + +#define ENUM_NAME(c,e,v) (c::staticMetaObject.enumerator(c::staticMetaObject.indexOfEnumerator(e)).valueToKey((v))) + +void QMediaPlayerPrivate::_q_stateChanged(QMediaPlayer::State ps) +{ + Q_Q(QMediaPlayer); + +#ifdef DEBUG_PLAYER_STATE + qDebug() << "State changed:" << ENUM_NAME(QMediaPlayer, "State", ps) << (filterStates ? "(filtered)" : ""); +#endif + + if (filterStates) + return; + + if (playlist + && !playlistControl //service should do this itself + && ps != state && ps == QMediaPlayer::StoppedState + && control->mediaStatus() == QMediaPlayer::EndOfMedia) { + playlist->next(); + ps = control->state(); + } + + if (ps != state) { + state = ps; + + if (ps == QMediaPlayer::PlayingState) + q->addPropertyWatch("position"); + else + q->removePropertyWatch("position"); + + emit q->stateChanged(ps); + } +} + +void QMediaPlayerPrivate::_q_mediaStatusChanged(QMediaPlayer::MediaStatus status) +{ + Q_Q(QMediaPlayer); + +#ifdef DEBUG_PLAYER_STATE + qDebug() << "MediaStatus changed:" << ENUM_NAME(QMediaPlayer, "MediaStatus", status); +#endif + + switch (status) { + case QMediaPlayer::StalledMedia: + case QMediaPlayer::BufferingMedia: + q->addPropertyWatch("bufferStatus"); + emit q->mediaStatusChanged(status); + break; + default: + q->removePropertyWatch("bufferStatus"); + emit q->mediaStatusChanged(status); + break; + } + +} + +void QMediaPlayerPrivate::_q_error(int error, const QString &errorString) +{ + Q_Q(QMediaPlayer); + + this->error = QMediaPlayer::Error(error); + this->errorString = errorString; + + emit q->error(this->error); +} + +void QMediaPlayerPrivate::_q_updateMedia(const QMediaContent &media) +{ + const QMediaPlayer::State currentState = state; + + filterStates = true; + control->setMedia(media, 0); + + if (!media.isNull()) { + switch (currentState) { + case QMediaPlayer::PlayingState: + control->play(); + break; + case QMediaPlayer::PausedState: + control->pause(); + break; + default: + break; + } + } + filterStates = false; + + state = control->state(); + + if (state != currentState) { +#ifdef DEBUG_PLAYER_STATE + qDebug() << "State changed:" << ENUM_NAME(QMediaPlayer, "State", state); +#endif + emit q_func()->stateChanged(state); + } +} + +void QMediaPlayerPrivate::_q_playlistDestroyed() +{ + playlist = 0; + + control->setMedia(QMediaContent(), 0); +} + +static QMediaService *playerService(QMediaPlayer::Flags flags, QMediaServiceProvider *provider) +{ + if (flags) { + QMediaServiceProviderHint::Features features = 0; + if (flags & QMediaPlayer::LowLatency) + features |= QMediaServiceProviderHint::LowLatencyPlayback; + + if (flags & QMediaPlayer::StreamPlayback) + features |= QMediaServiceProviderHint::StreamPlayback; + + return provider->requestService(Q_MEDIASERVICE_MEDIAPLAYER, + QMediaServiceProviderHint(features)); + } else + return provider->requestService(Q_MEDIASERVICE_MEDIAPLAYER); +} + + +/*! + Construct a QMediaPlayer that uses the playback service from \a provider, + parented to \a parent and with \a flags. + + If a playback service is not specified the system default will be used. +*/ + +QMediaPlayer::QMediaPlayer(QObject *parent, QMediaPlayer::Flags flags, QMediaServiceProvider *provider): + QMediaObject(*new QMediaPlayerPrivate, + parent, + playerService(flags,provider)) +{ + Q_D(QMediaPlayer); + + d->provider = provider; + + if (d->service == 0) { + d->error = ServiceMissingError; + } else { + d->control = qobject_cast(d->service->control(QMediaPlayerControl_iid)); + d->playlistControl = qobject_cast(d->service->control(QMediaPlaylistControl_iid)); + if (d->control != 0) { + connect(d->control, SIGNAL(mediaChanged(QMediaContent)), SIGNAL(mediaChanged(QMediaContent))); + connect(d->control, SIGNAL(stateChanged(QMediaPlayer::State)), SLOT(_q_stateChanged(QMediaPlayer::State))); + connect(d->control, SIGNAL(mediaStatusChanged(QMediaPlayer::MediaStatus)), + SLOT(_q_mediaStatusChanged(QMediaPlayer::MediaStatus))); + connect(d->control, SIGNAL(error(int,QString)), SLOT(_q_error(int,QString))); + + connect(d->control, SIGNAL(durationChanged(qint64)), SIGNAL(durationChanged(qint64))); + connect(d->control, SIGNAL(positionChanged(qint64)), SIGNAL(positionChanged(qint64))); + connect(d->control, SIGNAL(audioAvailableChanged(bool)), SIGNAL(audioAvailableChanged(bool))); + connect(d->control, SIGNAL(videoAvailableChanged(bool)), SIGNAL(videoAvailableChanged(bool))); + connect(d->control, SIGNAL(volumeChanged(int)), SIGNAL(volumeChanged(int))); + connect(d->control, SIGNAL(mutedChanged(bool)), SIGNAL(mutedChanged(bool))); + connect(d->control, SIGNAL(seekableChanged(bool)), SIGNAL(seekableChanged(bool))); + connect(d->control, SIGNAL(playbackRateChanged(qreal)), SIGNAL(playbackRateChanged(qreal))); + + if (d->control->state() == PlayingState) + addPropertyWatch("position"); + + if (d->control->mediaStatus() == StalledMedia || d->control->mediaStatus() == BufferingMedia) + addPropertyWatch("bufferStatus"); + } + } +} + + +/*! + Destroys the player object. +*/ + +QMediaPlayer::~QMediaPlayer() +{ + Q_D(QMediaPlayer); + + d->provider->releaseService(d->service); +} + +QMediaContent QMediaPlayer::media() const +{ + Q_D(const QMediaPlayer); + + if (d->control != 0) + return d->control->media(); + + return QMediaContent(); +} + +/*! + Returns the stream source of media data. + + This is only valid if a stream was passed to setMedia(). + + \sa setMedia() +*/ + +const QIODevice *QMediaPlayer::mediaStream() const +{ + Q_D(const QMediaPlayer); + + if (d->control != 0) + return d->control->mediaStream(); + + return 0; +} + +QMediaPlayer::State QMediaPlayer::state() const +{ + return d_func()->state; +} + +QMediaPlayer::MediaStatus QMediaPlayer::mediaStatus() const +{ + Q_D(const QMediaPlayer); + + if (d->control != 0) + return d->control->mediaStatus(); + + return QMediaPlayer::UnknownMediaStatus; +} + +qint64 QMediaPlayer::duration() const +{ + Q_D(const QMediaPlayer); + + if (d->control != 0) + return d->control->duration(); + + return -1; +} + +qint64 QMediaPlayer::position() const +{ + Q_D(const QMediaPlayer); + + if (d->control != 0) + return d->control->position(); + + return 0; +} + +int QMediaPlayer::volume() const +{ + Q_D(const QMediaPlayer); + + if (d->control != 0) + return d->control->volume(); + + return 0; +} + +bool QMediaPlayer::isMuted() const +{ + Q_D(const QMediaPlayer); + + if (d->control != 0) + return d->control->isMuted(); + + return false; +} + +int QMediaPlayer::bufferStatus() const +{ + Q_D(const QMediaPlayer); + + if (d->control != 0) + return d->control->bufferStatus(); + + return 0; +} + +bool QMediaPlayer::isAudioAvailable() const +{ + Q_D(const QMediaPlayer); + + if (d->control != 0) + return d->control->isAudioAvailable(); + + return false; +} + +bool QMediaPlayer::isVideoAvailable() const +{ + Q_D(const QMediaPlayer); + + if (d->control != 0) + return d->control->isVideoAvailable(); + + return false; +} + +bool QMediaPlayer::isSeekable() const +{ + Q_D(const QMediaPlayer); + + if (d->control != 0) + return d->control->isSeekable(); + + return false; +} + +qreal QMediaPlayer::playbackRate() const +{ + Q_D(const QMediaPlayer); + + if (d->control != 0) + return d->control->playbackRate(); + + return 0.0; +} + +/*! + Returns the current error state. +*/ + +QMediaPlayer::Error QMediaPlayer::error() const +{ + return d_func()->error; +} + +QString QMediaPlayer::errorString() const +{ + return d_func()->errorString; +} + +//public Q_SLOTS: +/*! + Start or resume playing the current source. +*/ + +void QMediaPlayer::play() +{ + Q_D(QMediaPlayer); + + if (d->control == 0) { + QMetaObject::invokeMethod(this, "_q_error", Qt::QueuedConnection); + Q_ARG(int, QMediaPlayer::ServiceMissingError), + Q_ARG(QString, tr("The QMediaPlayer object does not have a valid service")); + return; + } + + //if playlist control is available, the service should advance itself + if (d->playlist && !d->playlistControl && d->playlist->currentIndex() == -1 && !d->playlist->isEmpty()) + d->playlist->setCurrentIndex(0); + + // Reset error conditions + d->error = NoError; + d->errorString = QString(); + + d->control->play(); +} + +/*! + Pause playing the current source. +*/ + +void QMediaPlayer::pause() +{ + Q_D(QMediaPlayer); + + if (d->control != 0) + d->control->pause(); +} + +/*! + Stop playing, and reset the play position to the beginning. +*/ + +void QMediaPlayer::stop() +{ + Q_D(QMediaPlayer); + + if (d->control != 0) + d->control->stop(); +} + +void QMediaPlayer::setPosition(qint64 position) +{ + Q_D(QMediaPlayer); + + if (d->control == 0 || !isSeekable()) + return; + + d->control->setPosition(qBound(qint64(0), duration(), position)); +} + +void QMediaPlayer::setVolume(int v) +{ + Q_D(QMediaPlayer); + + if (d->control == 0) + return; + + int clamped = qBound(0, v, 100); + if (clamped == volume()) + return; + + d->control->setVolume(clamped); +} + +void QMediaPlayer::setMuted(bool muted) +{ + Q_D(QMediaPlayer); + + if (d->control == 0 || muted == isMuted()) + return; + + d->control->setMuted(muted); +} + +void QMediaPlayer::setPlaybackRate(qreal rate) +{ + Q_D(QMediaPlayer); + + if (d->control != 0) + d->control->setPlaybackRate(rate); +} + +/*! + Sets the current \a media source. + + If a \a stream is supplied; media data will be read from it instead of resolving the media + source. In this case the media source may still be used to resolve additional information + about the media such as mime type. + + Setting the media to a null QMediaContent will cause the player to discard all + information relating to the current media source and to cease all I/O operations related + to that media. +*/ + +void QMediaPlayer::setMedia(const QMediaContent &media, QIODevice *stream) +{ + Q_D(QMediaPlayer); + + if (d->control != 0) + d_func()->control->setMedia(media, stream); +} + +/*! + \internal +*/ + +void QMediaPlayer::bind(QObject *obj) +{ + Q_D(QMediaPlayer); + + if (d->control != 0) { + QMediaPlaylist *playlist = qobject_cast(obj); + + if (playlist) { + if (d->playlist) + d->playlist->setMediaObject(0); + + d->playlist = playlist; + connect(d->playlist, SIGNAL(currentMediaChanged(QMediaContent)), + this, SLOT(_q_updateMedia(QMediaContent))); + connect(d->playlist, SIGNAL(destroyed()), this, SLOT(_q_playlistDestroyed())); + + setMedia(playlist->currentMedia()); + + return; + } + + QVideoWidget *videoWidget = qobject_cast(obj); + QGraphicsVideoItem *videoItem = qobject_cast(obj); + + if (videoWidget || videoItem) { + //detach the current video output + if (d->videoWidget) { + d->videoWidget->setMediaObject(0); + d->videoWidget = 0; + } + + if (d->videoItem) { + d->videoItem->setMediaObject(0); + d->videoItem = 0; + } + } + + if (videoWidget) + d->videoWidget = videoWidget; + + if (videoItem) + d->videoItem = videoItem; + } +} + +/*! + \internal +*/ + +void QMediaPlayer::unbind(QObject *obj) +{ + Q_D(QMediaPlayer); + + if (obj == d->videoWidget) { + d->videoWidget = 0; + } else if (obj == d->videoItem) { + d->videoItem = 0; + } else if (obj == d->playlist) { + disconnect(d->playlist, SIGNAL(currentMediaChanged(QMediaContent)), + this, SLOT(_q_updateMedia(QMediaContent))); + disconnect(d->playlist, SIGNAL(destroyed()), this, SLOT(_q_playlistDestroyed())); + d->playlist = 0; + setMedia(QMediaContent()); + } +} + +/*! + Returns the level of support a media player has for a \a mimeType and a set of \a codecs. + + The \a flags argument allows additional requirements such as performance indicators to be + specified. +*/ +QtMediaservices::SupportEstimate QMediaPlayer::hasSupport(const QString &mimeType, + const QStringList& codecs, + Flags flags) +{ + return QMediaServiceProvider::defaultServiceProvider()->hasSupport(QByteArray(Q_MEDIASERVICE_MEDIAPLAYER), + mimeType, + codecs, + flags); +} + +/*! + Returns a list of MIME types supported by the media player. + + The \a flags argument causes the resultant list to be restricted to MIME types which can be supported + given additional requirements, such as performance indicators. +*/ +QStringList QMediaPlayer::supportedMimeTypes(Flags flags) +{ + return QMediaServiceProvider::defaultServiceProvider()->supportedMimeTypes(QByteArray(Q_MEDIASERVICE_MEDIAPLAYER), + flags); +} + + +// Enums +/*! + \enum QMediaPlayer::State + + Defines the current state of a media player. + + \value PlayingState The media player is currently playing content. + \value PausedState The media player has paused playback, playback of the current track will + resume from the position the player was paused at. + \value StoppedState The media player is not playing content, playback will begin from the start + of the current track. +*/ + +/*! + \enum QMediaPlayer::MediaStatus + + Defines the status of a media player's current media. + + \value UnknownMediaStatus The status of the media cannot be determined. + \value NoMedia The is no current media. The player is in the StoppedState. + \value LoadingMedia The current media is being loaded. The player may be in any state. + \value LoadedMedia The current media has been loaded. The player is in the StoppedState. + \value StalledMedia Playback of the current media has stalled due to insufficient buffering or + some other temporary interruption. The player is in the PlayingState or PausedState. + \value BufferingMedia The player is buffering data but has enough data buffered for playback to + continue for the immediate future. The player is in the PlayingState or PausedState. + \value BufferedMedia The player has fully buffered the current media. The player is in the + PlayingState or PausedState. + \value EndOfMedia Playback has reached the end of the current media. The player is in the + StoppedState. + \value InvalidMedia The current media cannot be played. The player is in the StoppedState. +*/ + +/*! + \enum QMediaPlayer::Error + + Defines a media player error condition. + + \value NoError No error has occurred. + \value ResourceError A media resource couldn't be resolved. + \value FormatError The format of a media resource isn't (fully) supported. Playback may still + be possible, but without an audio or video component. + \value NetworkError A network error occurred. + \value AccessDeniedError There are not the appropriate permissions to play a media resource. + \value ServiceMissingError A valid playback service was not found, playback cannot proceed. +*/ + +// Signals +/*! + \fn QMediaPlayer::error(QMediaPlayer::Error error) + + Signals that an \a error condition has occurred. + + \sa errorString() +*/ + +/*! + \fn void QMediaPlayer::stateChanged(State state) + + Signal the \a state of the Player object has changed. +*/ + +/*! + \fn QMediaPlayer::mediaStatusChanged(QMediaPlayer::MediaStatus status) + + Signals that the \a status of the current media has changed. + + \sa mediaStatus() +*/ + +/*! + \fn void QMediaPlayer::mediaChanged(const QMediaContent &media); + + Signals that the current playing content will be obtained from \a media. + + \sa media() +*/ + +/*! + \fn void QMediaPlayer::playbackRateChanged(qreal rate); + + Signals the playbackRate has changed to \a rate. +*/ + +/*! + \fn void QMediaPlayer::seekableChanged(bool seekable); + + Signals the \a seekable status of the player object has changed. +*/ + +// Properties +/*! + \property QMediaPlayer::state + \brief the media player's playback state. + + By default this property is QMediaPlayer::Stopped + + \sa mediaStatus(), play(), pause(), stop() +*/ + +/*! + \property QMediaPlayer::error + \brief a string describing the last error condition. + + \sa error() +*/ + +/*! + \property QMediaPlayer::media + \brief the active media source being used by the player object. + + The player object will use the QMediaContent for selection of the content to + be played. + + By default this property has a null QMediaContent. + + Setting this property to a null QMediaContent will cause the player to discard all + information relating to the current media source and to cease all I/O operations related + to that media. + + \sa QMediaContent +*/ + +/*! + \property QMediaPlayer::mediaStatus + \brief the status of the current media stream. + + The stream status describes how the playback of the current stream is + progressing. + + By default this property is QMediaPlayer::NoMedia + + \sa state +*/ + +/*! + \property QMediaPlayer::duration + \brief the duration of the current media. + + The value is the total playback time in milliseconds of the current media. + The value may change across the life time of the QMediaPlayer object and + may not be available when initial playback begins, connect to the + durationChanged() signal to receive status notifications. +*/ + +/*! + \property QMediaPlayer::position + \brief the playback position of the current media. + + The value is the current playback position, expressed in milliseconds since + the beginning of the media. Periodically changes in the position will be + indicated with the signal positionChanged(), the interval between updates + can be set with QMediaObject's method setNotifyInterval(). +*/ + +/*! + \property QMediaPlayer::volume + \brief the current playback volume. + + The playback volume is a linear in effect and the value can range from 0 - + 100, values outside this range will be clamped. +*/ + +/*! + \property QMediaPlayer::muted + \brief the muted state of the current media. + + The value will be true if the playback volume is muted; otherwise false. +*/ + +/*! + \property QMediaPlayer::bufferStatus + \brief the percentage of the temporary buffer filled before playback begins. + + When the player object is buffering; this property holds the percentage of + the temporary buffer that is filled. The buffer will need to reach 100% + filled before playback can resume, at which time the MediaStatus will be + BufferedMedia. + + \sa mediaStatus() +*/ + +/*! + \property QMediaPlayer::audioAvailable + \brief the audio availabilty status for the current media. + + As the life time of QMediaPlayer can be longer than the playback of one + QMediaContent, this property may change over time, the + audioAvailableChanged signal can be used to monitor it's status. +*/ + +/*! + \property QMediaPlayer::videoAvailable + \brief the video availability status for the current media. + + If available, the QVideoWidget class can be used to view the video. As the + life time of QMediaPlayer can be longer than the playback of one + QMediaContent, this property may change over time, the + videoAvailableChanged signal can be used to monitor it's status. + + \sa QVideoWidget, QMediaContent +*/ + +/*! + \property QMediaPlayer::seekable + \brief the seek-able status of the current media + + If seeking is supported this property will be true; false otherwise. The + status of this property may change across the life time of the QMediaPlayer + object, use the seekableChanged signal to monitor changes. +*/ + +/*! + \property QMediaPlayer::playbackRate + \brief the playback rate of the current media. + + This value is a multiplier applied to the media's standard play rate. By + default this value is 1.0, indicating that the media is playing at the + standard pace. Values higher than 1.0 will increase the rate of play. + Values less than zero can be set and indicate the media will rewind at the + multiplier of the standard pace. + + Not all playback services support change of the playback rate. It is + framework defined as to the status and quality of audio and video + while fast forwarding or rewinding. +*/ + +/*! + \fn void QMediaPlayer::durationChanged(qint64 duration) + + Signal the duration of the content has changed to \a duration, expressed in milliseconds. +*/ + +/*! + \fn void QMediaPlayer::positionChanged(qint64 position) + + Signal the position of the content has changed to \a position, expressed in + milliseconds. +*/ + +/*! + \fn void QMediaPlayer::volumeChanged(int volume) + + Signal the playback volume has changed to \a volume. +*/ + +/*! + \fn void QMediaPlayer::mutedChanged(bool muted) + + Signal the mute state has changed to \a muted. +*/ + +/*! + \fn void QMediaPlayer::audioAvailableChanged(bool available) + + Signals the availability of audio content has changed to \a available. +*/ + +/*! + \fn void QMediaPlayer::videoAvailableChanged(bool videoAvailable) + + Signal the availability of visual content has changed to \a videoAvailable. +*/ + +/*! + \fn void QMediaPlayer::bufferStatusChanged(int percentFilled) + + Signal the amount of the local buffer filled as a percentage by \a percentFilled. +*/ + +/*! + \enum QMediaPlayer::Flag + + \value LowLatency + The player is expected to be used with simple audio formats, + but playback should start without significant delay. + Such playback service can be used for beeps, ringtones, etc. + + \value StreamPlayback + The player is expected to play QIODevice based streams. + If passed to QMediaPlayer constructor, the service supporting + streams playback will be choosen. +*/ + +QT_END_NAMESPACE + +QT_END_HEADER + +#include "moc_qmediaplayer.cpp" diff --git a/src/multimedia/mediaservices/playback/qmediaplayer.h b/src/multimedia/mediaservices/playback/qmediaplayer.h new file mode 100644 index 0000000..2b4c443 --- /dev/null +++ b/src/multimedia/mediaservices/playback/qmediaplayer.h @@ -0,0 +1,203 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtMediaservices module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QMEDIAPLAYER_H +#define QMEDIAPLAYER_H + +#include +#include +#include + + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Multimedia) + + +class QMediaPlaylist; + +class QMediaPlayerPrivate; +class Q_MULTIMEDIA_EXPORT QMediaPlayer : public QMediaObject +{ + Q_OBJECT + Q_PROPERTY(QMediaContent media READ media WRITE setMedia NOTIFY mediaChanged) + Q_PROPERTY(qint64 duration READ duration NOTIFY durationChanged) + Q_PROPERTY(qint64 position READ position WRITE setPosition NOTIFY positionChanged) + Q_PROPERTY(int volume READ volume WRITE setVolume NOTIFY volumeChanged) + Q_PROPERTY(bool muted READ isMuted WRITE setMuted NOTIFY mutedChanged) + Q_PROPERTY(int bufferStatus READ bufferStatus NOTIFY bufferStatusChanged) + Q_PROPERTY(bool audioAvailable READ isAudioAvailable NOTIFY audioAvailableChanged) + Q_PROPERTY(bool videoAvailable READ isVideoAvailable NOTIFY videoAvailableChanged) + Q_PROPERTY(bool seekable READ isSeekable NOTIFY seekableChanged) + Q_PROPERTY(qreal playbackRate READ playbackRate WRITE setPlaybackRate NOTIFY playbackRateChanged) + Q_PROPERTY(State state READ state NOTIFY stateChanged) + Q_PROPERTY(MediaStatus mediaStatus READ mediaStatus NOTIFY mediaStatusChanged) + Q_PROPERTY(QString error READ errorString) + Q_ENUMS(State) + Q_ENUMS(MediaStatus) + +public: + enum State + { + StoppedState, + PlayingState, + PausedState + }; + + enum MediaStatus + { + UnknownMediaStatus, + NoMedia, + LoadingMedia, + LoadedMedia, + StalledMedia, + BufferingMedia, + BufferedMedia, + EndOfMedia, + InvalidMedia + }; + + enum Flag + { + LowLatency = 0x01, + StreamPlayback = 0x02 + }; + Q_DECLARE_FLAGS(Flags, Flag) + + enum Error + { + NoError, + ResourceError, + FormatError, + NetworkError, + AccessDeniedError, + ServiceMissingError + }; + + QMediaPlayer(QObject *parent = 0, Flags flags = 0, QMediaServiceProvider *provider = QMediaServiceProvider::defaultServiceProvider()); + ~QMediaPlayer(); + + static QtMediaservices::SupportEstimate hasSupport(const QString &mimeType, + const QStringList& codecs = QStringList(), + Flags flags = 0); + static QStringList supportedMimeTypes(Flags flags = 0); + + QMediaContent media() const; + const QIODevice *mediaStream() const; + + State state() const; + MediaStatus mediaStatus() const; + + qint64 duration() const; + qint64 position() const; + + int volume() const; + bool isMuted() const; + bool isAudioAvailable() const; + bool isVideoAvailable() const; + + int bufferStatus() const; + + bool isSeekable() const; + qreal playbackRate() const; + + Error error() const; + QString errorString() const; + +public Q_SLOTS: + void play(); + void pause(); + void stop(); + + void setPosition(qint64 position); + void setVolume(int volume); + void setMuted(bool muted); + + void setPlaybackRate(qreal rate); + + void setMedia(const QMediaContent &media, QIODevice *stream = 0); + +Q_SIGNALS: + void mediaChanged(const QMediaContent &media); + + void stateChanged(QMediaPlayer::State newState); + void mediaStatusChanged(QMediaPlayer::MediaStatus status); + + void durationChanged(qint64 duration); + void positionChanged(qint64 position); + + void volumeChanged(int volume); + void mutedChanged(bool muted); + void audioAvailableChanged(bool audioAvailable); + void videoAvailableChanged(bool videoAvailable); + + void bufferStatusChanged(int percentFilled); + + void seekableChanged(bool seekable); + void playbackRateChanged(qreal rate); + + void error(QMediaPlayer::Error error); + +public: + virtual void bind(QObject*); + virtual void unbind(QObject*); + +private: + Q_DISABLE_COPY(QMediaPlayer) + Q_DECLARE_PRIVATE(QMediaPlayer) + Q_PRIVATE_SLOT(d_func(), void _q_stateChanged(QMediaPlayer::State)) + Q_PRIVATE_SLOT(d_func(), void _q_mediaStatusChanged(QMediaPlayer::MediaStatus)) + Q_PRIVATE_SLOT(d_func(), void _q_error(int, const QString &)) + Q_PRIVATE_SLOT(d_func(), void _q_updateMedia(const QMediaContent&)) + Q_PRIVATE_SLOT(d_func(), void _q_playlistDestroyed()) +}; + +QT_END_NAMESPACE + +Q_DECLARE_METATYPE(QMediaPlayer::State) +Q_DECLARE_METATYPE(QMediaPlayer::MediaStatus) +Q_DECLARE_METATYPE(QMediaPlayer::Error) + +QT_END_HEADER + +#endif // QMEDIAPLAYER_H diff --git a/src/multimedia/mediaservices/playback/qmediaplayercontrol.cpp b/src/multimedia/mediaservices/playback/qmediaplayercontrol.cpp new file mode 100644 index 0000000..3b63d93 --- /dev/null +++ b/src/multimedia/mediaservices/playback/qmediaplayercontrol.cpp @@ -0,0 +1,378 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtMediaservices module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include +#include + + +QT_BEGIN_NAMESPACE + + +/*! + \class QMediaPlayerControl + \ingroup multimedia-serv + \since 4.7 + \preliminary + \brief The QMediaPlayerControl class provides access to the media playing + functionality of a QMediaService. + + If a QMediaService can play media is will implement QMediaPlayerControl. + This control provides a means to set the \l {setMedia()}{media} to play, + \l {play()}{start}, \l {pause()} {pause} and \l {stop()}{stop} playback, + \l {setPosition()}{seek}, and control the \l {setVolume()}{volume}. + It also provides feedback on the \l {duration()}{duration} of the media, + the current \l {position()}{position}, and \l {bufferStatus()}{buffering} + progress. + + The functionality provided by this control is exposed to application + code through the QMediaPlayer class. + + The interface name of QMediaPlayerControl is \c com.nokia.Qt.QMediaPlayerControl/1.0 as + defined in QMediaPlayerControl_iid. + + \sa QMediaService::control(), QMediaPlayer +*/ + +/*! + \macro QMediaPlayerControl_iid + + \c com.nokia.Qt.QMediaPlayerControl/1.0 + + Defines the interface name of the QMediaPlayerControl class. + + \relates QMediaPlayerControl +*/ + +/*! + Destroys a media player control. +*/ +QMediaPlayerControl::~QMediaPlayerControl() +{ +} + +/*! + Constructs a new media player control with the given \a parent. +*/ +QMediaPlayerControl::QMediaPlayerControl(QObject *parent): + QMediaControl(*new QMediaControlPrivate, parent) +{ +} + +/*! + \fn QMediaPlayerControl::state() const + + Returns the state of a player control. +*/ + +/*! + \fn QMediaPlayerControl::stateChanged(QMediaPlayer::State state) + + Signals that the \a state of a player control has changed. + + \sa state() +*/ + +/*! + \fn QMediaPlayerControl::mediaStatus() const + + Returns the status of the current media. +*/ + +/*! + \fn QMediaPlayerControl::mediaStatusChanged(QMediaPlayer::MediaStatus status) + + Signals that the \a status of the current media has changed. + + \sa mediaStatus() +*/ + + +/*! + \fn QMediaPlayerControl::duration() const + + Returns the duration of the current media in milliseconds. +*/ + +/*! + \fn QMediaPlayerControl::durationChanged(qint64 duration) + + Signals that the \a duration of the current media has changed. + + \sa duration() +*/ + +/*! + \fn QMediaPlayerControl::position() const + + Returns the current playback position in milliseconds. +*/ + +/*! + \fn QMediaPlayerControl::setPosition(qint64 position) + + Sets the playback \a position of the current media. This will initiate a seek and it may take + some time for playback to reach the position set. +*/ + +/*! + \fn QMediaPlayerControl::positionChanged(qint64 position) + + Signals the playback \a position has changed. + + This is only emitted in when there has been a discontinous change in the playback postion, such + as a seek or the position being reset. + + \sa position() +*/ + +/*! + \fn QMediaPlayerControl::volume() const + + Returns the audio volume of a player control. +*/ + +/*! + \fn QMediaPlayerControl::setVolume(int volume) + + Sets the audio \a volume of a player control. +*/ + +/*! + \fn QMediaPlayerControl::volumeChanged(int volume) + + Signals the audio \a volume of a player control has changed. + + \sa volume() +*/ + +/*! + \fn QMediaPlayerControl::isMuted() const + + Returns the mute state of a player control. +*/ + +/*! + \fn QMediaPlayerControl::setMuted(bool mute) + + Sets the \a mute state of a player control. +*/ + +/*! + \fn QMediaPlayerControl::mutedChanged(bool mute) + + Signals a change in the \a mute status of a player control. + + \sa isMuted() +*/ + +/*! + \fn QMediaPlayerControl::bufferStatus() const + + Returns the buffering progress of the current media. Progress is measured in the percentage + of the buffer filled. +*/ + +/*! + \fn QMediaPlayerControl::bufferStatusChanged(int progress) + + Signals that buffering \a progress has changed. + + \sa bufferStatus() +*/ + +/*! + \fn QMediaPlayerControl::isAudioAvailable() const + + Identifies if there is audio output available for the current media. + + Returns true if audio output is available and false otherwise. +*/ + +/*! + \fn QMediaPlayerControl::audioAvailableChanged(bool audio) + + Signals that there has been a change in the availability of \a audio output. + + \sa isAudioAvailable() +*/ + +/*! + \fn QMediaPlayerControl::isVideoAvailable() const + + Identifies if there is video output available for the current media. + + Returns true if video output is available and false otherwise. +*/ + +/*! + \fn QMediaPlayerControl::videoAvailableChanged(bool video) + + Signals that there has been a change in the availability of \a video output. + + \sa isVideoAvailable() +*/ + +/*! + \fn QMediaPlayerControl::isSeekable() const + + Identifies if the current media is seekable. + + Returns true if it possible to seek within the current media, and false otherwise. +*/ + +/*! + \fn QMediaPlayerControl::seekableChanged(bool seekable) + + Signals that the \a seekable state of a player control has changed. + + \sa isSeekable() +*/ + +/*! + \fn QMediaPlayerControl::availablePlaybackRanges() const + + Returns a range of times in milliseconds that can be played back. + + Usually for local files this is a continuous interval equal to [0..duration()] + or an empty time range if seeking is not supported, but for network sources + it refers to the buffered parts of the media. +*/ + +/*! + \fn QMediaPlayerControl::availablePlaybackRangesChanged(const QMediaTimeRange &ranges) + + Signals that the available media playback \a ranges have changed. + + \sa QMediaPlayerControl::availablePlaybackRanges() +*/ + +/*! + \fn qreal QMediaPlayerControl::playbackRate() const + + Returns the rate of playback. +*/ + +/*! + \fn QMediaPlayerControl::setPlaybackRate(qreal rate) + + Sets the \a rate of playback. +*/ + +/*! + \fn QMediaPlayerControl::media() const + + Returns the current media source. +*/ + +/*! + \fn QMediaPlayerControl::mediaStream() const + + Returns the current media stream. This is only a valid if a stream was passed to setMedia(). + + \sa setMedia() +*/ + +/*! + \fn QMediaPlayerControl::setMedia(const QMediaContent &media, QIODevice *stream) + + Sets the current \a media source. If a \a stream is supplied; data will be read from that + instead of attempting to resolve the media source. The media source may still be used to + supply media information such as mime type. + + Setting the media to a null QMediaContent will cause the control to discard all + information relating to the current media source and to cease all I/O operations related + to that media. +*/ + +/*! + \fn QMediaPlayerControl::mediaChanged(const QMediaContent& content) + + Signals that the current media \a content has changed. +*/ + +/*! + \fn QMediaPlayerControl::play() + + Starts playback of the current media. + + If successful the player control will immediately enter the \l {QMediaPlayer::PlayingState} + {playing} state. + + \sa state() +*/ + +/*! + \fn QMediaPlayerControl::pause() + + Pauses playback of the current media. + + If sucessful the player control will immediately enter the \l {QMediaPlayer::PausedState} + {paused} state. + + \sa state(), play(), stop() +*/ + +/*! + \fn QMediaPlayerControl::stop() + + Stops playback of the current media. + + If succesful the player control will immediately enter the \l {QMediaPlayer::StoppedState} + {stopped} state. +*/ + +/*! + \fn QMediaPlayerControl::error(int error, const QString &errorString) + + Signals that an \a error has occurred. The \a errorString provides a more detailed explanation. +*/ + +/*! + \fn QMediaPlayerControl::playbackRateChanged(qreal rate) + + Signal emitted when playback rate changes to \a rate. +*/ + +QT_END_NAMESPACE + +#include "moc_qmediaplayercontrol.cpp" + diff --git a/src/multimedia/mediaservices/playback/qmediaplayercontrol.h b/src/multimedia/mediaservices/playback/qmediaplayercontrol.h new file mode 100644 index 0000000..be10713 --- /dev/null +++ b/src/multimedia/mediaservices/playback/qmediaplayercontrol.h @@ -0,0 +1,131 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtMediaservices module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QMEDIAPLAYERCONTROL_H +#define QMEDIAPLAYERCONTROL_H + +#include + +#include +#include +#include + + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Multimedia) + + +class QMediaPlaylist; + +class Q_MULTIMEDIA_EXPORT QMediaPlayerControl : public QMediaControl +{ + Q_OBJECT + +public: + ~QMediaPlayerControl(); + + virtual QMediaPlayer::State state() const = 0; + + virtual QMediaPlayer::MediaStatus mediaStatus() const = 0; + + virtual qint64 duration() const = 0; + + virtual qint64 position() const = 0; + virtual void setPosition(qint64 position) = 0; + + virtual int volume() const = 0; + virtual void setVolume(int volume) = 0; + + virtual bool isMuted() const = 0; + virtual void setMuted(bool muted) = 0; + + virtual int bufferStatus() const = 0; + + virtual bool isAudioAvailable() const = 0; + virtual bool isVideoAvailable() const = 0; + + virtual bool isSeekable() const = 0; + + virtual QMediaTimeRange availablePlaybackRanges() const = 0; + + virtual qreal playbackRate() const = 0; + virtual void setPlaybackRate(qreal rate) = 0; + + virtual QMediaContent media() const = 0; + virtual const QIODevice *mediaStream() const = 0; + virtual void setMedia(const QMediaContent &media, QIODevice *stream) = 0; + + virtual void play() = 0; + virtual void pause() = 0; + virtual void stop() = 0; + +Q_SIGNALS: + void mediaChanged(const QMediaContent& content); + void durationChanged(qint64 duration); + void positionChanged(qint64 position); + void stateChanged(QMediaPlayer::State newState); + void mediaStatusChanged(QMediaPlayer::MediaStatus status); + void volumeChanged(int volume); + void mutedChanged(bool muted); + void audioAvailableChanged(bool audioAvailable); + void videoAvailableChanged(bool videoAvailable); + void bufferStatusChanged(int percentFilled); + void seekableChanged(bool); + void availablePlaybackRangesChanged(const QMediaTimeRange&); + void playbackRateChanged(qreal rate); + void error(int error, const QString &errorString); + +protected: + QMediaPlayerControl(QObject* parent = 0); +}; + +#define QMediaPlayerControl_iid "com.nokia.Qt.QMediaPlayerControl/1.0" +Q_MEDIA_DECLARE_CONTROL(QMediaPlayerControl, QMediaPlayerControl_iid) + +QT_END_NAMESPACE + +QT_END_HEADER + +#endif // QMEDIAPLAYERCONTROL_H + diff --git a/src/multimedia/multimedia.pro b/src/multimedia/multimedia.pro index 500aff7..8cdcb38 100644 --- a/src/multimedia/multimedia.pro +++ b/src/multimedia/multimedia.pro @@ -1,17 +1,8 @@ -TARGET = QtMultimedia -QPRO_PWD = $$PWD -QT = core gui +TEMPLATE = subdirs -DEFINES += QT_BUILD_MULTIMEDIA_LIB QT_NO_USING_NAMESPACE +contains(QT_CONFIG, multimedia) { + SUBDIRS += multimedia -unix:QMAKE_PKGCONFIG_REQUIRES = QtCore QtGui + contains(QT_CONFIG, mediaservices):SUBDIRS += mediaservices +} -include(../qbase.pri) - -include(audio/audio.pri) -include(video/video.pri) -include(base/base.pri) -include(playback/playback.pri) -include(effects/effects.pri) - -symbian: TARGET.UID3 = 0x2001E627 diff --git a/src/multimedia/multimedia/audio/audio.pri b/src/multimedia/multimedia/audio/audio.pri new file mode 100644 index 0000000..ae28a26 --- /dev/null +++ b/src/multimedia/multimedia/audio/audio.pri @@ -0,0 +1,73 @@ +HEADERS += $$PWD/qaudio.h \ + $$PWD/qaudioformat.h \ + $$PWD/qaudioinput.h \ + $$PWD/qaudiooutput.h \ + $$PWD/qaudiodeviceinfo.h \ + $$PWD/qaudioengineplugin.h \ + $$PWD/qaudioengine.h \ + $$PWD/qaudiodevicefactory_p.h + + +SOURCES += $$PWD/qaudio.cpp \ + $$PWD/qaudioformat.cpp \ + $$PWD/qaudiodeviceinfo.cpp \ + $$PWD/qaudiooutput.cpp \ + $$PWD/qaudioinput.cpp \ + $$PWD/qaudioengineplugin.cpp \ + $$PWD/qaudioengine.cpp \ + $$PWD/qaudiodevicefactory.cpp + +contains(QT_CONFIG, audio-backend) { + +mac { + HEADERS += $$PWD/qaudioinput_mac_p.h \ + $$PWD/qaudiooutput_mac_p.h \ + $$PWD/qaudiodeviceinfo_mac_p.h \ + $$PWD/qaudio_mac_p.h + + SOURCES += $$PWD/qaudiodeviceinfo_mac_p.cpp \ + $$PWD/qaudiooutput_mac_p.cpp \ + $$PWD/qaudioinput_mac_p.cpp \ + $$PWD/qaudio_mac.cpp + + LIBS += -framework ApplicationServices -framework CoreAudio -framework AudioUnit -framework AudioToolbox + +} else:win32 { + + HEADERS += $$PWD/qaudioinput_win32_p.h $$PWD/qaudiooutput_win32_p.h $$PWD/qaudiodeviceinfo_win32_p.h + SOURCES += $$PWD/qaudiodeviceinfo_win32_p.cpp \ + $$PWD/qaudiooutput_win32_p.cpp \ + $$PWD/qaudioinput_win32_p.cpp + !wince*:LIBS += -lwinmm + wince*:LIBS += -lcoredll + +} else:symbian { + INCLUDEPATH += /epoc32/include/mmf/common + INCLUDEPATH += /epoc32/include/mmf/server + + HEADERS += $$PWD/qaudio_symbian_p.h \ + $$PWD/qaudiodeviceinfo_symbian_p.h \ + $$PWD/qaudioinput_symbian_p.h \ + $$PWD/qaudiooutput_symbian_p.h + + SOURCES += $$PWD/qaudio_symbian_p.cpp \ + $$PWD/qaudiodeviceinfo_symbian_p.cpp \ + $$PWD/qaudioinput_symbian_p.cpp \ + $$PWD/qaudiooutput_symbian_p.cpp + + LIBS += -lmmfdevsound +} else:unix { + unix:contains(QT_CONFIG, alsa) { + linux-*|freebsd-*|openbsd-*:{ + DEFINES += HAS_ALSA + HEADERS += $$PWD/qaudiooutput_alsa_p.h $$PWD/qaudioinput_alsa_p.h $$PWD/qaudiodeviceinfo_alsa_p.h + SOURCES += $$PWD/qaudiodeviceinfo_alsa_p.cpp \ + $$PWD/qaudiooutput_alsa_p.cpp \ + $$PWD/qaudioinput_alsa_p.cpp + LIBS_PRIVATE += -lasound + } + } +} +} else { + DEFINES += QT_NO_AUDIO_BACKEND +} diff --git a/src/multimedia/multimedia/audio/qaudio.cpp b/src/multimedia/multimedia/audio/qaudio.cpp new file mode 100644 index 0000000..e0f24ce --- /dev/null +++ b/src/multimedia/multimedia/audio/qaudio.cpp @@ -0,0 +1,104 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtMultimedia module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + + +#include + + +QT_BEGIN_NAMESPACE + +namespace QAudio +{ + +class RegisterMetaTypes +{ +public: + RegisterMetaTypes() + { + qRegisterMetaType(); + qRegisterMetaType(); + qRegisterMetaType(); + } + +} _register; + +} + +/*! + \namespace QAudio + \brief The QAudio namespace contains enums used by the audio classes. + \inmodule QtMultimedia + \ingroup multimedia + \since 4.6 +*/ + +/*! + \enum QAudio::Error + + \value NoError No errors have occurred + \value OpenError An error opening the audio device + \value IOError An error occurred during read/write of audio device + \value UnderrunError Audio data is not being fed to the audio device at a fast enough rate + \value FatalError A non-recoverable error has occurred, the audio device is not usable at this time. +*/ + +/*! + \enum QAudio::State + + \value ActiveState Audio data is being processed, this state is set after start() is called + and while audio data is available to be processed. + \value SuspendedState The audio device is in a suspended state, this state will only be entered + after suspend() is called. + \value StoppedState The audio device is closed, not processing any audio data + \value IdleState The QIODevice passed in has no data and audio system's buffer is empty, this state + is set after start() is called and while no audio data is available to be processed. +*/ + +/*! + \enum QAudio::Mode + + \value AudioOutput audio output device + \value AudioInput audio input device +*/ + + +QT_END_NAMESPACE + diff --git a/src/multimedia/multimedia/audio/qaudio.h b/src/multimedia/multimedia/audio/qaudio.h new file mode 100644 index 0000000..9ca1dff --- /dev/null +++ b/src/multimedia/multimedia/audio/qaudio.h @@ -0,0 +1,71 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtMultimedia module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + + +#ifndef QAUDIO_H +#define QAUDIO_H + + +#include +#include + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Multimedia) + +namespace QAudio +{ + enum Error { NoError, OpenError, IOError, UnderrunError, FatalError }; + enum State { ActiveState, SuspendedState, StoppedState, IdleState }; + enum Mode { AudioInput, AudioOutput }; +} + +QT_END_NAMESPACE + +QT_END_HEADER + +Q_DECLARE_METATYPE(QAudio::Error) +Q_DECLARE_METATYPE(QAudio::State) +Q_DECLARE_METATYPE(QAudio::Mode) + +#endif // QAUDIO_H diff --git a/src/multimedia/multimedia/audio/qaudio_mac.cpp b/src/multimedia/multimedia/audio/qaudio_mac.cpp new file mode 100644 index 0000000..14fee8b --- /dev/null +++ b/src/multimedia/multimedia/audio/qaudio_mac.cpp @@ -0,0 +1,142 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtMultimedia module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + + +#include "qaudio_mac_p.h" + +QT_BEGIN_NAMESPACE + +// Debugging +QDebug operator<<(QDebug dbg, const QAudioFormat& audioFormat) +{ + dbg.nospace() << "QAudioFormat(" << + audioFormat.frequency() << "," << + audioFormat.channels() << "," << + audioFormat.sampleSize()<< "," << + audioFormat.codec() << "," << + audioFormat.byteOrder() << "," << + audioFormat.sampleType() << ")"; + + return dbg.space(); +} + + +// Conversion +QAudioFormat toQAudioFormat(AudioStreamBasicDescription const& sf) +{ + QAudioFormat audioFormat; + + audioFormat.setFrequency(sf.mSampleRate); + audioFormat.setChannels(sf.mChannelsPerFrame); + audioFormat.setSampleSize(sf.mBitsPerChannel); + audioFormat.setCodec(QString::fromLatin1("audio/pcm")); + audioFormat.setByteOrder(sf.mFormatFlags & kLinearPCMFormatFlagIsBigEndian != 0 ? QAudioFormat::BigEndian : QAudioFormat::LittleEndian); + QAudioFormat::SampleType type = QAudioFormat::UnSignedInt; + if ((sf.mFormatFlags & kLinearPCMFormatFlagIsSignedInteger) != 0) + type = QAudioFormat::SignedInt; + else if ((sf.mFormatFlags & kLinearPCMFormatFlagIsFloat) != 0) + type = QAudioFormat::Float; + audioFormat.setSampleType(type); + + return audioFormat; +} + +AudioStreamBasicDescription toAudioStreamBasicDescription(QAudioFormat const& audioFormat) +{ + AudioStreamBasicDescription sf; + + sf.mFormatFlags = kAudioFormatFlagIsPacked; + sf.mSampleRate = audioFormat.frequency(); + sf.mFramesPerPacket = 1; + sf.mChannelsPerFrame = audioFormat.channels(); + sf.mBitsPerChannel = audioFormat.sampleSize(); + sf.mBytesPerFrame = sf.mChannelsPerFrame * (sf.mBitsPerChannel / 8); + sf.mBytesPerPacket = sf.mFramesPerPacket * sf.mBytesPerFrame; + sf.mFormatID = kAudioFormatLinearPCM; + + switch (audioFormat.sampleType()) { + case QAudioFormat::SignedInt: sf.mFormatFlags |= kAudioFormatFlagIsSignedInteger; break; + case QAudioFormat::UnSignedInt: /* default */ break; + case QAudioFormat::Float: sf.mFormatFlags |= kAudioFormatFlagIsFloat; break; + case QAudioFormat::Unknown: default: break; + } + + return sf; +} + +// QAudioRingBuffer +QAudioRingBuffer::QAudioRingBuffer(int bufferSize): + m_bufferSize(bufferSize) +{ + m_buffer = new char[m_bufferSize]; + reset(); +} + +QAudioRingBuffer::~QAudioRingBuffer() +{ + delete m_buffer; +} + +int QAudioRingBuffer::used() const +{ + return m_bufferUsed; +} + +int QAudioRingBuffer::free() const +{ + return m_bufferSize - m_bufferUsed; +} + +int QAudioRingBuffer::size() const +{ + return m_bufferSize; +} + +void QAudioRingBuffer::reset() +{ + m_readPos = 0; + m_writePos = 0; + m_bufferUsed = 0; +} + +QT_END_NAMESPACE + + diff --git a/src/multimedia/multimedia/audio/qaudio_mac_p.h b/src/multimedia/multimedia/audio/qaudio_mac_p.h new file mode 100644 index 0000000..4e7d688 --- /dev/null +++ b/src/multimedia/multimedia/audio/qaudio_mac_p.h @@ -0,0 +1,144 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtMultimedia module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists for the convenience +// of other Qt classes. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + + +#ifndef QAUDIO_MAC_P_H +#define QAUDIO_MAC_P_H + +#include + +#include +#include + +#include + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Multimedia) + + +extern QDebug operator<<(QDebug dbg, const QAudioFormat& audioFormat); + +extern QAudioFormat toQAudioFormat(const AudioStreamBasicDescription& streamFormat); +extern AudioStreamBasicDescription toAudioStreamBasicDescription(QAudioFormat const& audioFormat); + +class QAudioRingBuffer +{ +public: + typedef QPair Region; + + QAudioRingBuffer(int bufferSize); + ~QAudioRingBuffer(); + + Region acquireReadRegion(int size) + { + const int used = m_bufferUsed.fetchAndAddAcquire(0); + + if (used > 0) { + const int readSize = qMin(size, qMin(m_bufferSize - m_readPos, used)); + + return readSize > 0 ? Region(m_buffer + m_readPos, readSize) : Region(0, 0); + } + + return Region(0, 0); + } + + void releaseReadRegion(Region const& region) + { + m_readPos = (m_readPos + region.second) % m_bufferSize; + + m_bufferUsed.fetchAndAddRelease(-region.second); + } + + Region acquireWriteRegion(int size) + { + const int free = m_bufferSize - m_bufferUsed.fetchAndAddAcquire(0); + + if (free > 0) { + const int writeSize = qMin(size, qMin(m_bufferSize - m_writePos, free)); + + return writeSize > 0 ? Region(m_buffer + m_writePos, writeSize) : Region(0, 0); + } + + return Region(0, 0); + } + + void releaseWriteRegion(Region const& region) + { + m_writePos = (m_writePos + region.second) % m_bufferSize; + + m_bufferUsed.fetchAndAddRelease(region.second); + } + + int used() const; + int free() const; + int size() const; + + void reset(); + +private: + int m_bufferSize; + int m_readPos; + int m_writePos; + char* m_buffer; + QAtomicInt m_bufferUsed; +}; + +QT_END_NAMESPACE + +QT_END_HEADER + +#endif // QAUDIO_MAC_P_H + + diff --git a/src/multimedia/multimedia/audio/qaudio_symbian_p.cpp b/src/multimedia/multimedia/audio/qaudio_symbian_p.cpp new file mode 100644 index 0000000..58e3745 --- /dev/null +++ b/src/multimedia/multimedia/audio/qaudio_symbian_p.cpp @@ -0,0 +1,395 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtMultimedia module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qaudio_symbian_p.h" +#include + +QT_BEGIN_NAMESPACE + +namespace SymbianAudio { + +DevSoundCapabilities::DevSoundCapabilities(CMMFDevSound &devsound, + QAudio::Mode mode) +{ + QT_TRAP_THROWING(constructL(devsound, mode)); +} + +DevSoundCapabilities::~DevSoundCapabilities() +{ + m_fourCC.Close(); +} + +void DevSoundCapabilities::constructL(CMMFDevSound &devsound, + QAudio::Mode mode) +{ + m_caps = devsound.Capabilities(); + + TMMFPrioritySettings settings; + + switch (mode) { + case QAudio::AudioOutput: + settings.iState = EMMFStatePlaying; + devsound.GetSupportedInputDataTypesL(m_fourCC, settings); + break; + + case QAudio::AudioInput: + settings.iState = EMMFStateRecording; + devsound.GetSupportedInputDataTypesL(m_fourCC, settings); + break; + + default: + Q_ASSERT_X(false, Q_FUNC_INFO, "Invalid mode"); + } +} + +namespace Utils { + +//----------------------------------------------------------------------------- +// Static data +//----------------------------------------------------------------------------- + +// Sample rate / frequency + +typedef TMMFSampleRate SampleRateNative; +typedef int SampleRateQt; + +const int SampleRateCount = 12; + +const SampleRateNative SampleRateListNative[SampleRateCount] = { + EMMFSampleRate8000Hz + , EMMFSampleRate11025Hz + , EMMFSampleRate12000Hz + , EMMFSampleRate16000Hz + , EMMFSampleRate22050Hz + , EMMFSampleRate24000Hz + , EMMFSampleRate32000Hz + , EMMFSampleRate44100Hz + , EMMFSampleRate48000Hz + , EMMFSampleRate64000Hz + , EMMFSampleRate88200Hz + , EMMFSampleRate96000Hz +}; + +const SampleRateQt SampleRateListQt[SampleRateCount] = { + 8000 + , 11025 + , 12000 + , 16000 + , 22050 + , 24000 + , 32000 + , 44100 + , 48000 + , 64000 + , 88200 + , 96000 +}; + +// Channels + +typedef TMMFMonoStereo ChannelsNative; +typedef int ChannelsQt; + +const int ChannelsCount = 2; + +const ChannelsNative ChannelsListNative[ChannelsCount] = { + EMMFMono + , EMMFStereo +}; + +const ChannelsQt ChannelsListQt[ChannelsCount] = { + 1 + , 2 +}; + +// Encoding + +const int EncodingCount = 6; + +const TUint32 EncodingFourCC[EncodingCount] = { + KMMFFourCCCodePCM8 // 0 + , KMMFFourCCCodePCMU8 // 1 + , KMMFFourCCCodePCM16 // 2 + , KMMFFourCCCodePCMU16 // 3 + , KMMFFourCCCodePCM16B // 4 + , KMMFFourCCCodePCMU16B // 5 +}; + +// The characterised DevSound API specification states that the iEncoding +// field in TMMFCapabilities is ignored, and that the FourCC should be used +// to specify the PCM encoding. +// See "SGL.GT0287.102 Multimedia DevSound Baseline Compatibility.doc" in the +// mm_info/mm_docs repository. +const TMMFSoundEncoding EncodingNative[EncodingCount] = { + EMMFSoundEncoding16BitPCM // 0 + , EMMFSoundEncoding16BitPCM // 1 + , EMMFSoundEncoding16BitPCM // 2 + , EMMFSoundEncoding16BitPCM // 3 + , EMMFSoundEncoding16BitPCM // 4 + , EMMFSoundEncoding16BitPCM // 5 +}; + + +const int EncodingSampleSize[EncodingCount] = { + 8 // 0 + , 8 // 1 + , 16 // 2 + , 16 // 3 + , 16 // 4 + , 16 // 5 +}; + +const QAudioFormat::Endian EncodingByteOrder[EncodingCount] = { + QAudioFormat::LittleEndian // 0 + , QAudioFormat::LittleEndian // 1 + , QAudioFormat::LittleEndian // 2 + , QAudioFormat::LittleEndian // 3 + , QAudioFormat::BigEndian // 4 + , QAudioFormat::BigEndian // 5 +}; + +const QAudioFormat::SampleType EncodingSampleType[EncodingCount] = { + QAudioFormat::SignedInt // 0 + , QAudioFormat::UnSignedInt // 1 + , QAudioFormat::SignedInt // 2 + , QAudioFormat::UnSignedInt // 3 + , QAudioFormat::SignedInt // 4 + , QAudioFormat::UnSignedInt // 5 +}; + + +//----------------------------------------------------------------------------- +// Private functions +//----------------------------------------------------------------------------- + +// Helper functions for implementing parameter conversions + +template +bool findValue(const Input *inputArray, int length, Input input, int &index) { + bool result = false; + for (int i=0; !result && i +bool convertValue(const Input *inputArray, const Output *outputArray, + int length, Input input, Output &output) { + int index; + const bool result = findValue(inputArray, length, input, index); + if (result) + output = outputArray[index]; + return result; +} + +/** + * Macro which is used to generate the implementation of the conversion + * functions. The implementation is just a wrapper around the templated + * convertValue function, e.g. + * + * CONVERSION_FUNCTION_IMPL(SampleRate, Qt, Native) + * + * expands to + * + * bool SampleRateQtToNative(int input, TMMFSampleRate &output) { + * return convertValue + * (SampleRateListQt, SampleRateListNative, SampleRateCount, + * input, output); + * } + */ +#define CONVERSION_FUNCTION_IMPL(FieldLc, Field, Input, Output) \ +bool FieldLc##Input##To##Output(Field##Input input, Field##Output &output) { \ + return convertValue(Field##List##Input, \ + Field##List##Output, Field##Count, input, output); \ +} + +//----------------------------------------------------------------------------- +// Local helper functions +//----------------------------------------------------------------------------- + +CONVERSION_FUNCTION_IMPL(sampleRate, SampleRate, Qt, Native) +CONVERSION_FUNCTION_IMPL(sampleRate, SampleRate, Native, Qt) +CONVERSION_FUNCTION_IMPL(channels, Channels, Qt, Native) +CONVERSION_FUNCTION_IMPL(channels, Channels, Native, Qt) + +bool sampleInfoQtToNative(int inputSampleSize, + QAudioFormat::Endian inputByteOrder, + QAudioFormat::SampleType inputSampleType, + TUint32 &outputFourCC, + TMMFSoundEncoding &outputEncoding) { + + bool found = false; + + for (int i=0; i &frequencies, + QList &channels, + QList &sampleSizes, + QList &byteOrders, + QList &sampleTypes) { + + frequencies.clear(); + sampleSizes.clear(); + byteOrders.clear(); + sampleTypes.clear(); + channels.clear(); + + for (int i=0; i +#include +#include +#include + +QT_BEGIN_NAMESPACE + +namespace SymbianAudio { + +/** + * Default values used by audio input and output classes, when underlying + * DevSound instance has not yet been created. + */ + +const int DefaultBufferSize = 4096; // bytes +const int DefaultNotifyInterval = 1000; // ms + +/** + * Enumeration used to track state of internal DevSound instances. + * Values are translated to the corresponding QAudio::State values by + * SymbianAudio::Utils::stateNativeToQt. + */ +enum State { + ClosedState + , InitializingState + , ActiveState + , IdleState + , SuspendedState +}; + +/* + * Helper class for querying DevSound codec / format support + */ +class DevSoundCapabilities { +public: + DevSoundCapabilities(CMMFDevSound &devsound, QAudio::Mode mode); + ~DevSoundCapabilities(); + + const RArray& fourCC() const { return m_fourCC; } + const TMMFCapabilities& caps() const { return m_caps; } + +private: + void constructL(CMMFDevSound &devsound, QAudio::Mode mode); + +private: + RArray m_fourCC; + TMMFCapabilities m_caps; +}; + +namespace Utils { + +/** + * Convert native audio capabilities to QAudio lists. + */ +void capabilitiesNativeToQt(const DevSoundCapabilities &caps, + QList &frequencies, + QList &channels, + QList &sampleSizes, + QList &byteOrders, + QList &sampleTypes); + +/** + * Check whether format is supported. + */ +bool isFormatSupported(const QAudioFormat &format, + const DevSoundCapabilities &caps); + +/** + * Convert QAudioFormat to native format types. + * + * Note that, despite the name, DevSound uses TMMFCapabilities to specify + * single formats as well as capabilities. + * + * Note that this function does not modify outputFormat.iBufferSize. + */ +bool formatQtToNative(const QAudioFormat &inputFormat, + TUint32 &outputFourCC, + TMMFCapabilities &outputFormat); + +/** + * Convert internal states to QAudio states. + */ +QAudio::State stateNativeToQt(State nativeState, + QAudio::State initializingState); + +/** + * Convert data length to number of samples. + */ +qint64 bytesToSamples(const QAudioFormat &format, qint64 length); + +/** + * Convert number of samples to data length. + */ +qint64 samplesToBytes(const QAudioFormat &format, qint64 samples); + +} // namespace Utils +} // namespace SymbianAudio + +QT_END_NAMESPACE + +#endif diff --git a/src/multimedia/multimedia/audio/qaudiodevicefactory.cpp b/src/multimedia/multimedia/audio/qaudiodevicefactory.cpp new file mode 100644 index 0000000..4f45110 --- /dev/null +++ b/src/multimedia/multimedia/audio/qaudiodevicefactory.cpp @@ -0,0 +1,257 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtMultimedia module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include +#include +#include +#include "qaudiodevicefactory_p.h" + +#ifndef QT_NO_AUDIO_BACKEND +#if defined(Q_OS_WIN) +#include "qaudiodeviceinfo_win32_p.h" +#include "qaudiooutput_win32_p.h" +#include "qaudioinput_win32_p.h" +#elif defined(Q_OS_MAC) +#include "qaudiodeviceinfo_mac_p.h" +#include "qaudiooutput_mac_p.h" +#include "qaudioinput_mac_p.h" +#elif defined(HAS_ALSA) +#include "qaudiodeviceinfo_alsa_p.h" +#include "qaudiooutput_alsa_p.h" +#include "qaudioinput_alsa_p.h" +#elif defined(Q_OS_SYMBIAN) +#include "qaudiodeviceinfo_symbian_p.h" +#include "qaudiooutput_symbian_p.h" +#include "qaudioinput_symbian_p.h" +#endif +#endif + +QT_BEGIN_NAMESPACE + +Q_GLOBAL_STATIC_WITH_ARGS(QFactoryLoader, loader, + (QAudioEngineFactoryInterface_iid, QLatin1String("/audio"), Qt::CaseInsensitive)) + + +class QNullDeviceInfo : public QAbstractAudioDeviceInfo +{ +public: + QAudioFormat preferredFormat() const { qWarning()<<"using null deviceinfo, none available"; return QAudioFormat(); } + bool isFormatSupported(const QAudioFormat& ) const { return false; } + QAudioFormat nearestFormat(const QAudioFormat& ) const { return QAudioFormat(); } + QString deviceName() const { return QString(); } + QStringList codecList() { return QStringList(); } + QList frequencyList() { return QList(); } + QList channelsList() { return QList(); } + QList sampleSizeList() { return QList(); } + QList byteOrderList() { return QList(); } + QList sampleTypeList() { return QList(); } +}; + +class QNullInputDevice : public QAbstractAudioInput +{ +public: + QIODevice* start(QIODevice* ) { qWarning()<<"using null input device, none available"; return 0; } + void stop() {} + void reset() {} + void suspend() {} + void resume() {} + int bytesReady() const { return 0; } + int periodSize() const { return 0; } + void setBufferSize(int ) {} + int bufferSize() const { return 0; } + void setNotifyInterval(int ) {} + int notifyInterval() const { return 0; } + qint64 processedUSecs() const { return 0; } + qint64 elapsedUSecs() const { return 0; } + QAudio::Error error() const { return QAudio::OpenError; } + QAudio::State state() const { return QAudio::StoppedState; } + QAudioFormat format() const { return QAudioFormat(); } +}; + +class QNullOutputDevice : public QAbstractAudioOutput +{ +public: + QIODevice* start(QIODevice* ) { qWarning()<<"using null output device, none available"; return 0; } + void stop() {} + void reset() {} + void suspend() {} + void resume() {} + int bytesFree() const { return 0; } + int periodSize() const { return 0; } + void setBufferSize(int ) {} + int bufferSize() const { return 0; } + void setNotifyInterval(int ) {} + int notifyInterval() const { return 0; } + qint64 processedUSecs() const { return 0; } + qint64 elapsedUSecs() const { return 0; } + QAudio::Error error() const { return QAudio::OpenError; } + QAudio::State state() const { return QAudio::StoppedState; } + QAudioFormat format() const { return QAudioFormat(); } +}; + +QList QAudioDeviceFactory::availableDevices(QAudio::Mode mode) +{ + QList devices; +#ifndef QT_NO_AUDIO_BACKEND +#if (defined(Q_OS_WIN) || defined(Q_OS_MAC) || defined(HAS_ALSA) || defined(Q_OS_SYMBIAN)) + foreach (const QByteArray &handle, QAudioDeviceInfoInternal::availableDevices(mode)) + devices << QAudioDeviceInfo(QLatin1String("builtin"), handle, mode); +#endif +#endif + QFactoryLoader* l = loader(); + + foreach (QString const& key, l->keys()) { + QAudioEngineFactoryInterface* plugin = qobject_cast(l->instance(key)); + if (plugin) { + foreach (QByteArray const& handle, plugin->availableDevices(mode)) + devices << QAudioDeviceInfo(key, handle, mode); + } + + delete plugin; + } + + return devices; +} + +QAudioDeviceInfo QAudioDeviceFactory::defaultInputDevice() +{ + QAudioEngineFactoryInterface* plugin = qobject_cast(loader()->instance(QLatin1String("default"))); + + if (plugin) { + QList list = plugin->availableDevices(QAudio::AudioInput); + if (list.size() > 0) + return QAudioDeviceInfo(QLatin1String("default"), list.at(0), QAudio::AudioInput); + } +#ifndef QT_NO_AUDIO_BACKEND +#if (defined(Q_OS_WIN) || defined(Q_OS_MAC) || defined(HAS_ALSA) || defined(Q_OS_SYMBIAN)) + return QAudioDeviceInfo(QLatin1String("builtin"), QAudioDeviceInfoInternal::defaultInputDevice(), QAudio::AudioInput); +#endif +#endif + return QAudioDeviceInfo(); +} + +QAudioDeviceInfo QAudioDeviceFactory::defaultOutputDevice() +{ + QAudioEngineFactoryInterface* plugin = qobject_cast(loader()->instance(QLatin1String("default"))); + + if (plugin) { + QList list = plugin->availableDevices(QAudio::AudioOutput); + if (list.size() > 0) + return QAudioDeviceInfo(QLatin1String("default"), list.at(0), QAudio::AudioOutput); + } +#ifndef QT_NO_AUDIO_BACKEND +#if (defined(Q_OS_WIN) || defined(Q_OS_MAC) || defined(HAS_ALSA) || defined(Q_OS_SYMBIAN)) + return QAudioDeviceInfo(QLatin1String("builtin"), QAudioDeviceInfoInternal::defaultOutputDevice(), QAudio::AudioOutput); +#endif +#endif + return QAudioDeviceInfo(); +} + +QAbstractAudioDeviceInfo* QAudioDeviceFactory::audioDeviceInfo(const QString &realm, const QByteArray &handle, QAudio::Mode mode) +{ + QAbstractAudioDeviceInfo *rc = 0; + +#ifndef QT_NO_AUDIO_BACKEND +#if (defined(Q_OS_WIN) || defined(Q_OS_MAC) || defined(HAS_ALSA) || defined(Q_OS_SYMBIAN)) + if (realm == QLatin1String("builtin")) + return new QAudioDeviceInfoInternal(handle, mode); +#endif +#endif + QAudioEngineFactoryInterface* plugin = + qobject_cast(loader()->instance(realm)); + + if (plugin) + rc = plugin->createDeviceInfo(handle, mode); + + return rc == 0 ? new QNullDeviceInfo() : rc; +} + +QAbstractAudioInput* QAudioDeviceFactory::createDefaultInputDevice(QAudioFormat const &format) +{ + return createInputDevice(defaultInputDevice(), format); +} + +QAbstractAudioOutput* QAudioDeviceFactory::createDefaultOutputDevice(QAudioFormat const &format) +{ + return createOutputDevice(defaultOutputDevice(), format); +} + +QAbstractAudioInput* QAudioDeviceFactory::createInputDevice(QAudioDeviceInfo const& deviceInfo, QAudioFormat const &format) +{ + if (deviceInfo.isNull()) + return new QNullInputDevice(); +#ifndef QT_NO_AUDIO_BACKEND +#if (defined(Q_OS_WIN) || defined(Q_OS_MAC) || defined(HAS_ALSA) || defined(Q_OS_SYMBIAN)) + if (deviceInfo.realm() == QLatin1String("builtin")) + return new QAudioInputPrivate(deviceInfo.handle(), format); +#endif +#endif + QAudioEngineFactoryInterface* plugin = + qobject_cast(loader()->instance(deviceInfo.realm())); + + if (plugin) + return plugin->createInput(deviceInfo.handle(), format); + + return new QNullInputDevice(); +} + +QAbstractAudioOutput* QAudioDeviceFactory::createOutputDevice(QAudioDeviceInfo const& deviceInfo, QAudioFormat const &format) +{ + if (deviceInfo.isNull()) + return new QNullOutputDevice(); +#ifndef QT_NO_AUDIO_BACKEND +#if (defined(Q_OS_WIN) || defined(Q_OS_MAC) || defined(HAS_ALSA) || defined(Q_OS_SYMBIAN)) + if (deviceInfo.realm() == QLatin1String("builtin")) + return new QAudioOutputPrivate(deviceInfo.handle(), format); +#endif +#endif + QAudioEngineFactoryInterface* plugin = + qobject_cast(loader()->instance(deviceInfo.realm())); + + if (plugin) + return plugin->createOutput(deviceInfo.handle(), format); + + return new QNullOutputDevice(); +} + +QT_END_NAMESPACE + diff --git a/src/multimedia/multimedia/audio/qaudiodevicefactory_p.h b/src/multimedia/multimedia/audio/qaudiodevicefactory_p.h new file mode 100644 index 0000000..8ee8b05 --- /dev/null +++ b/src/multimedia/multimedia/audio/qaudiodevicefactory_p.h @@ -0,0 +1,97 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtMultimedia module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists for the convenience +// of other Qt classes. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#ifndef QAUDIODEVICEFACTORY_P_H +#define QAUDIODEVICEFACTORY_P_H + +#include +#include +#include + +#include + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Multimedia) + +class QAbstractAudioInput; +class QAbstractAudioOutput; +class QAbstractAudioDeviceInfo; + +class QAudioDeviceFactory +{ +public: + static QList availableDevices(QAudio::Mode mode); + + static QAudioDeviceInfo defaultInputDevice(); + static QAudioDeviceInfo defaultOutputDevice(); + + static QAbstractAudioDeviceInfo* audioDeviceInfo(const QString &realm, const QByteArray &handle, QAudio::Mode mode); + + static QAbstractAudioInput* createDefaultInputDevice(QAudioFormat const &format); + static QAbstractAudioOutput* createDefaultOutputDevice(QAudioFormat const &format); + + static QAbstractAudioInput* createInputDevice(QAudioDeviceInfo const &device, QAudioFormat const &format); + static QAbstractAudioOutput* createOutputDevice(QAudioDeviceInfo const &device, QAudioFormat const &format); + + static QAbstractAudioInput* createNullInput(); + static QAbstractAudioOutput* createNullOutput(); +}; + +QT_END_NAMESPACE + +QT_END_HEADER + +#endif // QAUDIODEVICEFACTORY_P_H + diff --git a/src/multimedia/multimedia/audio/qaudiodeviceinfo.cpp b/src/multimedia/multimedia/audio/qaudiodeviceinfo.cpp new file mode 100644 index 0000000..ff04b4e --- /dev/null +++ b/src/multimedia/multimedia/audio/qaudiodeviceinfo.cpp @@ -0,0 +1,400 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtMultimedia module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qaudiodevicefactory_p.h" +#include +#include + + +QT_BEGIN_NAMESPACE + +class QAudioDeviceInfoPrivate : public QSharedData +{ +public: + QAudioDeviceInfoPrivate():info(0) {} + QAudioDeviceInfoPrivate(const QString &r, const QByteArray &h, QAudio::Mode m): + realm(r), handle(h), mode(m) + { + info = QAudioDeviceFactory::audioDeviceInfo(realm, handle, mode); + } + + QAudioDeviceInfoPrivate(const QAudioDeviceInfoPrivate &other): + QSharedData(other), + realm(other.realm), handle(other.handle), mode(other.mode) + { + info = QAudioDeviceFactory::audioDeviceInfo(realm, handle, mode); + } + + QAudioDeviceInfoPrivate& operator=(const QAudioDeviceInfoPrivate &other) + { + delete info; + + realm = other.realm; + handle = other.handle; + mode = other.mode; + info = QAudioDeviceFactory::audioDeviceInfo(realm, handle, mode); + return *this; + } + + ~QAudioDeviceInfoPrivate() + { + delete info; + } + + QString realm; + QByteArray handle; + QAudio::Mode mode; + QAbstractAudioDeviceInfo* info; +}; + + +/*! + \class QAudioDeviceInfo + \brief The QAudioDeviceInfo class provides an interface to query audio devices and their functionality. + \inmodule QtMultimedia + \ingroup multimedia + + \since 4.6 + + QAudioDeviceInfo lets you query for audio devices--such as sound + cards and USB headsets--that are currently available on the system. + The audio devices available are dependent on the platform or audio plugins installed. + + You can also query each device for the formats it supports. A + format in this context is a set consisting of a specific byte + order, channel, codec, frequency, sample rate, and sample type. A + format is represented by the QAudioFormat class. + + The values supported by the the device for each of these + parameters can be fetched with + supportedByteOrders(), supportedChannelCounts(), supportedCodecs(), + supportedSampleRates(), supportedSampleSizes(), and + supportedSampleTypes(). The combinations supported are dependent on the platform, + audio plugins installed and the audio device capabilities. If you need a specific format, you can check if + the device supports it with isFormatSupported(), or fetch a + supported format that is as close as possible to the format with + nearestFormat(). For instance: + + \snippet doc/src/snippets/audio/main.cpp 1 + \dots 8 + \snippet doc/src/snippets/audio/main.cpp 2 + + A QAudioDeviceInfo is used by Qt to construct + classes that communicate with the device--such as + QAudioInput, and QAudioOutput. The static + functions defaultInputDevice(), defaultOutputDevice(), and + availableDevices() let you get a list of all available + devices. Devices are fetch according to the value of mode + this is specified by the QAudio::Mode enum. + The QAudioDeviceInfo returned are only valid for the QAudio::Mode. + + For instance: + + \code + foreach(const QAudioDeviceInfo &deviceInfo, QAudioDeviceInfo::availableDevices(QAudio::AudioOutput)) + qDebug() << "Device name: " << deviceInfo.deviceName(); + \endcode + + In this code sample, we loop through all devices that are able to output + sound, i.e., play an audio stream in a supported format. For each device we + find, we simply print the deviceName(). + + \sa QAudioOutput, QAudioInput +*/ + +/*! + Constructs an empty QAudioDeviceInfo object. +*/ + +QAudioDeviceInfo::QAudioDeviceInfo(): + d(new QAudioDeviceInfoPrivate) +{ +} + +/*! + Constructs a copy of \a other. +*/ + +QAudioDeviceInfo::QAudioDeviceInfo(const QAudioDeviceInfo& other): + d(other.d) +{ +} + +/*! + Destroy this audio device info. +*/ + +QAudioDeviceInfo::~QAudioDeviceInfo() +{ +} + +/*! + Sets the QAudioDeviceInfo object to be equal to \a other. +*/ + +QAudioDeviceInfo& QAudioDeviceInfo::operator=(const QAudioDeviceInfo &other) +{ + d = other.d; + return *this; +} + +/*! + Returns whether this QAudioDeviceInfo object holds a device definition. +*/ + +bool QAudioDeviceInfo::isNull() const +{ + return d->info == 0; +} + +/*! + Returns human readable name of audio device. + + Device names vary depending on platform/audio plugin being used. + + They are a unique string identifiers for the audio device. + + eg. default, Intel, U0x46d0x9a4 +*/ + +QString QAudioDeviceInfo::deviceName() const +{ + return isNull() ? QString() : d->info->deviceName(); +} + +/*! + Returns true if \a settings are supported by the audio device of this QAudioDeviceInfo. +*/ + +bool QAudioDeviceInfo::isFormatSupported(const QAudioFormat &settings) const +{ + return isNull() ? false : d->info->isFormatSupported(settings); +} + +/*! + Returns QAudioFormat of default settings. + + These settings are provided by the platform/audio plugin being used. + + They also are dependent on the QAudio::Mode being used. + + A typical audio system would provide something like: + \list + \o Input settings: 8000Hz mono 8 bit. + \o Output settings: 44100Hz stereo 16 bit little endian. + \endlist +*/ + +QAudioFormat QAudioDeviceInfo::preferredFormat() const +{ + return isNull() ? QAudioFormat() : d->info->preferredFormat(); +} + +/*! + Returns closest QAudioFormat to \a settings that system audio supports. + + These settings are provided by the platform/audio plugin being used. + + They also are dependent on the QAudio::Mode being used. +*/ + +QAudioFormat QAudioDeviceInfo::nearestFormat(const QAudioFormat &settings) const +{ + return isNull() ? QAudioFormat() : d->info->nearestFormat(settings); +} + +/*! + Returns a list of supported codecs. + + All platform and plugin implementations should provide support for: + + "audio/pcm" - Linear PCM + + For writing plugins to support additional codecs refer to: + + http://www.iana.org/assignments/media-types/audio/ +*/ + +QStringList QAudioDeviceInfo::supportedCodecs() const +{ + return isNull() ? QStringList() : d->info->codecList(); +} + +/*! + Returns a list of supported sample rates. + + \since 4.7 +*/ + +QList QAudioDeviceInfo::supportedSampleRates() const +{ + return supportedFrequencies(); +} + +/*! + \obsolete + + Use supportedSampleRates() instead. +*/ + +QList QAudioDeviceInfo::supportedFrequencies() const +{ + return isNull() ? QList() : d->info->frequencyList(); +} + +/*! + Returns a list of supported channel counts. + + \since 4.7 +*/ + +QList QAudioDeviceInfo::supportedChannelCounts() const +{ + return supportedChannels(); +} + +/*! + \obsolete + + Use supportedChannelCount() instead. +*/ + +QList QAudioDeviceInfo::supportedChannels() const +{ + return isNull() ? QList() : d->info->channelsList(); +} + +/*! + Returns a list of supported sample sizes. +*/ + +QList QAudioDeviceInfo::supportedSampleSizes() const +{ + return isNull() ? QList() : d->info->sampleSizeList(); +} + +/*! + Returns a list of supported byte orders. +*/ + +QList QAudioDeviceInfo::supportedByteOrders() const +{ + return isNull() ? QList() : d->info->byteOrderList(); +} + +/*! + Returns a list of supported sample types. +*/ + +QList QAudioDeviceInfo::supportedSampleTypes() const +{ + return isNull() ? QList() : d->info->sampleTypeList(); +} + +/*! + Returns the name of the default input audio device. + All platform and audio plugin implementations provide a default audio device to use. +*/ + +QAudioDeviceInfo QAudioDeviceInfo::defaultInputDevice() +{ + return QAudioDeviceFactory::defaultInputDevice(); +} + +/*! + Returns the name of the default output audio device. + All platform and audio plugin implementations provide a default audio device to use. +*/ + +QAudioDeviceInfo QAudioDeviceInfo::defaultOutputDevice() +{ + return QAudioDeviceFactory::defaultOutputDevice(); +} + +/*! + Returns a list of audio devices that support \a mode. +*/ + +QList QAudioDeviceInfo::availableDevices(QAudio::Mode mode) +{ + return QAudioDeviceFactory::availableDevices(mode); +} + + +/*! + \internal +*/ + +QAudioDeviceInfo::QAudioDeviceInfo(const QString &realm, const QByteArray &handle, QAudio::Mode mode): + d(new QAudioDeviceInfoPrivate(realm, handle, mode)) +{ +} + +/*! + \internal +*/ + +QString QAudioDeviceInfo::realm() const +{ + return d->realm; +} + +/*! + \internal +*/ + +QByteArray QAudioDeviceInfo::handle() const +{ + return d->handle; +} + + +/*! + \internal +*/ + +QAudio::Mode QAudioDeviceInfo::mode() const +{ + return d->mode; +} + +QT_END_NAMESPACE + diff --git a/src/multimedia/multimedia/audio/qaudiodeviceinfo.h b/src/multimedia/multimedia/audio/qaudiodeviceinfo.h new file mode 100644 index 0000000..1cc0731 --- /dev/null +++ b/src/multimedia/multimedia/audio/qaudiodeviceinfo.h @@ -0,0 +1,114 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtMultimedia module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + + +#ifndef QAUDIODEVICEINFO_H +#define QAUDIODEVICEINFO_H + +#include +#include +#include +#include +#include +#include + +#include +#include + + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Multimedia) + +class QAudioDeviceFactory; + +class QAudioDeviceInfoPrivate; +class Q_MULTIMEDIA_EXPORT QAudioDeviceInfo +{ + friend class QAudioDeviceFactory; + +public: + QAudioDeviceInfo(); + QAudioDeviceInfo(const QAudioDeviceInfo& other); + ~QAudioDeviceInfo(); + + QAudioDeviceInfo& operator=(const QAudioDeviceInfo& other); + + bool isNull() const; + + QString deviceName() const; + + bool isFormatSupported(const QAudioFormat &format) const; + QAudioFormat preferredFormat() const; + QAudioFormat nearestFormat(const QAudioFormat &format) const; + + QStringList supportedCodecs() const; + QList supportedFrequencies() const; + QList supportedSampleRates() const; + QList supportedChannels() const; + QList supportedChannelCounts() const; + QList supportedSampleSizes() const; + QList supportedByteOrders() const; + QList supportedSampleTypes() const; + + static QAudioDeviceInfo defaultInputDevice(); + static QAudioDeviceInfo defaultOutputDevice(); + + static QList availableDevices(QAudio::Mode mode); + +private: + QAudioDeviceInfo(const QString &realm, const QByteArray &handle, QAudio::Mode mode); + QString realm() const; + QByteArray handle() const; + QAudio::Mode mode() const; + + QSharedDataPointer d; +}; + +QT_END_NAMESPACE + +QT_END_HEADER + +Q_DECLARE_METATYPE(QAudioDeviceInfo) + +#endif // QAUDIODEVICEINFO_H diff --git a/src/multimedia/multimedia/audio/qaudiodeviceinfo_alsa_p.cpp b/src/multimedia/multimedia/audio/qaudiodeviceinfo_alsa_p.cpp new file mode 100644 index 0000000..36270a7 --- /dev/null +++ b/src/multimedia/multimedia/audio/qaudiodeviceinfo_alsa_p.cpp @@ -0,0 +1,486 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtMultimedia module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists for the convenience +// of other Qt classes. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include "qaudiodeviceinfo_alsa_p.h" + +#include + +QT_BEGIN_NAMESPACE + +QAudioDeviceInfoInternal::QAudioDeviceInfoInternal(QByteArray dev, QAudio::Mode mode) +{ + handle = 0; + + device = QLatin1String(dev); + this->mode = mode; +} + +QAudioDeviceInfoInternal::~QAudioDeviceInfoInternal() +{ + close(); +} + +bool QAudioDeviceInfoInternal::isFormatSupported(const QAudioFormat& format) const +{ + return testSettings(format); +} + +QAudioFormat QAudioDeviceInfoInternal::preferredFormat() const +{ + QAudioFormat nearest; + if(mode == QAudio::AudioOutput) { + nearest.setFrequency(44100); + nearest.setChannels(2); + nearest.setByteOrder(QAudioFormat::LittleEndian); + nearest.setSampleType(QAudioFormat::SignedInt); + nearest.setSampleSize(16); + nearest.setCodec(QLatin1String("audio/pcm")); + } else { + nearest.setFrequency(8000); + nearest.setChannels(1); + nearest.setSampleType(QAudioFormat::UnSignedInt); + nearest.setSampleSize(8); + nearest.setCodec(QLatin1String("audio/pcm")); + if(!testSettings(nearest)) { + nearest.setChannels(2); + nearest.setSampleSize(16); + nearest.setSampleType(QAudioFormat::SignedInt); + } + } + return nearest; +} + +QAudioFormat QAudioDeviceInfoInternal::nearestFormat(const QAudioFormat& format) const +{ + if(testSettings(format)) + return format; + else + return preferredFormat(); +} + +QString QAudioDeviceInfoInternal::deviceName() const +{ + return device; +} + +QStringList QAudioDeviceInfoInternal::codecList() +{ + updateLists(); + return codecz; +} + +QList QAudioDeviceInfoInternal::frequencyList() +{ + updateLists(); + return freqz; +} + +QList QAudioDeviceInfoInternal::channelsList() +{ + updateLists(); + return channelz; +} + +QList QAudioDeviceInfoInternal::sampleSizeList() +{ + updateLists(); + return sizez; +} + +QList QAudioDeviceInfoInternal::byteOrderList() +{ + updateLists(); + return byteOrderz; +} + +QList QAudioDeviceInfoInternal::sampleTypeList() +{ + updateLists(); + return typez; +} + +bool QAudioDeviceInfoInternal::open() +{ + int err = 0; + QString dev = device; + QList devices = availableDevices(mode); + + if(dev.compare(QLatin1String("default")) == 0) { +#if(SND_LIB_MAJOR == 1 && SND_LIB_MINOR == 0 && SND_LIB_SUBMINOR >= 14) + dev = QLatin1String(devices.first().constData()); +#else + dev = QLatin1String("hw:0,0"); +#endif + } else { +#if(SND_LIB_MAJOR == 1 && SND_LIB_MINOR == 0 && SND_LIB_SUBMINOR >= 14) + dev = device; +#else + int idx = 0; + char *name; + + QString shortName = device.mid(device.indexOf(QLatin1String("="),0)+1); + + while(snd_card_get_name(idx,&name) == 0) { + if(dev.contains(QLatin1String(name))) + break; + idx++; + } + dev = QString(QLatin1String("hw:%1,0")).arg(idx); +#endif + } + if(mode == QAudio::AudioOutput) { + err=snd_pcm_open( &handle,dev.toLocal8Bit().constData(),SND_PCM_STREAM_PLAYBACK,0); + } else { + err=snd_pcm_open( &handle,dev.toLocal8Bit().constData(),SND_PCM_STREAM_CAPTURE,0); + } + if(err < 0) { + handle = 0; + return false; + } + return true; +} + +void QAudioDeviceInfoInternal::close() +{ + if(handle) + snd_pcm_close(handle); + handle = 0; +} + +bool QAudioDeviceInfoInternal::testSettings(const QAudioFormat& format) const +{ + // Set nearest to closest settings that do work. + // See if what is in settings will work (return value). + int err = 0; + snd_pcm_t* handle; + snd_pcm_hw_params_t *params; + QString dev = device; + + QList devices = QAudioDeviceInfoInternal::availableDevices(QAudio::AudioOutput); + + if(dev.compare(QLatin1String("default")) == 0) { +#if(SND_LIB_MAJOR == 1 && SND_LIB_MINOR == 0 && SND_LIB_SUBMINOR >= 14) + dev = QLatin1String(devices.first().constData()); +#else + dev = QLatin1String("hw:0,0"); +#endif + } else { +#if(SND_LIB_MAJOR == 1 && SND_LIB_MINOR == 0 && SND_LIB_SUBMINOR >= 14) + dev = device; +#else + int idx = 0; + char *name; + + QString shortName = device.mid(device.indexOf(QLatin1String("="),0)+1); + + while(snd_card_get_name(idx,&name) == 0) { + if(shortName.compare(QLatin1String(name)) == 0) + break; + idx++; + } + dev = QString(QLatin1String("hw:%1,0")).arg(idx); +#endif + } + if(mode == QAudio::AudioOutput) { + err=snd_pcm_open( &handle,dev.toLocal8Bit().constData(),SND_PCM_STREAM_PLAYBACK,0); + } else { + err=snd_pcm_open( &handle,dev.toLocal8Bit().constData(),SND_PCM_STREAM_CAPTURE,0); + } + if(err < 0) { + handle = 0; + return false; + } + + bool testChannel = false; + bool testCodec = false; + bool testFreq = false; + bool testType = false; + bool testSize = false; + + int dir = 0; + + snd_pcm_nonblock( handle, 0 ); + snd_pcm_hw_params_alloca( ¶ms ); + snd_pcm_hw_params_any( handle, params ); + + // set the values! + snd_pcm_hw_params_set_channels(handle,params,format.channels()); + snd_pcm_hw_params_set_rate(handle,params,format.frequency(),dir); + switch(format.sampleSize()) { + case 8: + if(format.sampleType() == QAudioFormat::SignedInt) + snd_pcm_hw_params_set_format(handle,params,SND_PCM_FORMAT_S8); + else if(format.sampleType() == QAudioFormat::UnSignedInt) + snd_pcm_hw_params_set_format(handle,params,SND_PCM_FORMAT_U8); + break; + case 16: + if(format.sampleType() == QAudioFormat::SignedInt) { + if(format.byteOrder() == QAudioFormat::LittleEndian) + snd_pcm_hw_params_set_format(handle,params,SND_PCM_FORMAT_S16_LE); + else if(format.byteOrder() == QAudioFormat::BigEndian) + snd_pcm_hw_params_set_format(handle,params,SND_PCM_FORMAT_S16_BE); + } else if(format.sampleType() == QAudioFormat::UnSignedInt) { + if(format.byteOrder() == QAudioFormat::LittleEndian) + snd_pcm_hw_params_set_format(handle,params,SND_PCM_FORMAT_U16_LE); + else if(format.byteOrder() == QAudioFormat::BigEndian) + snd_pcm_hw_params_set_format(handle,params,SND_PCM_FORMAT_U16_BE); + } + break; + case 32: + if(format.sampleType() == QAudioFormat::SignedInt) { + if(format.byteOrder() == QAudioFormat::LittleEndian) + snd_pcm_hw_params_set_format(handle,params,SND_PCM_FORMAT_S32_LE); + else if(format.byteOrder() == QAudioFormat::BigEndian) + snd_pcm_hw_params_set_format(handle,params,SND_PCM_FORMAT_S32_BE); + } else if(format.sampleType() == QAudioFormat::UnSignedInt) { + if(format.byteOrder() == QAudioFormat::LittleEndian) + snd_pcm_hw_params_set_format(handle,params,SND_PCM_FORMAT_U32_LE); + else if(format.byteOrder() == QAudioFormat::BigEndian) + snd_pcm_hw_params_set_format(handle,params,SND_PCM_FORMAT_U32_BE); + } + } + + // For now, just accept only audio/pcm codec + if(!format.codec().startsWith(QLatin1String("audio/pcm"))) { + err=-1; + } else + testCodec = true; + + if(err>=0 && format.channels() != -1) { + err = snd_pcm_hw_params_test_channels(handle,params,format.channels()); + if(err>=0) + err = snd_pcm_hw_params_set_channels(handle,params,format.channels()); + if(err>=0) + testChannel = true; + } + + if(err>=0 && format.frequency() != -1) { + err = snd_pcm_hw_params_test_rate(handle,params,format.frequency(),0); + if(err>=0) + err = snd_pcm_hw_params_set_rate(handle,params,format.frequency(),dir); + if(err>=0) + testFreq = true; + } + + if((err>=0 && format.sampleSize() != -1) && + (format.sampleType() != QAudioFormat::Unknown)) { + switch(format.sampleSize()) { + case 8: + if(format.sampleType() == QAudioFormat::SignedInt) + err = snd_pcm_hw_params_set_format(handle,params,SND_PCM_FORMAT_S8); + else if(format.sampleType() == QAudioFormat::UnSignedInt) + err = snd_pcm_hw_params_set_format(handle,params,SND_PCM_FORMAT_U8); + break; + case 16: + if(format.sampleType() == QAudioFormat::SignedInt) { + if(format.byteOrder() == QAudioFormat::LittleEndian) + err = snd_pcm_hw_params_set_format(handle,params,SND_PCM_FORMAT_S16_LE); + else if(format.byteOrder() == QAudioFormat::BigEndian) + err = snd_pcm_hw_params_set_format(handle,params,SND_PCM_FORMAT_S16_BE); + } else if(format.sampleType() == QAudioFormat::UnSignedInt) { + if(format.byteOrder() == QAudioFormat::LittleEndian) + err = snd_pcm_hw_params_set_format(handle,params,SND_PCM_FORMAT_U16_LE); + else if(format.byteOrder() == QAudioFormat::BigEndian) + err = snd_pcm_hw_params_set_format(handle,params,SND_PCM_FORMAT_U16_BE); + } + break; + case 32: + if(format.sampleType() == QAudioFormat::SignedInt) { + if(format.byteOrder() == QAudioFormat::LittleEndian) + err = snd_pcm_hw_params_set_format(handle,params,SND_PCM_FORMAT_S32_LE); + else if(format.byteOrder() == QAudioFormat::BigEndian) + err = snd_pcm_hw_params_set_format(handle,params,SND_PCM_FORMAT_S32_BE); + } else if(format.sampleType() == QAudioFormat::UnSignedInt) { + if(format.byteOrder() == QAudioFormat::LittleEndian) + err = snd_pcm_hw_params_set_format(handle,params,SND_PCM_FORMAT_U32_LE); + else if(format.byteOrder() == QAudioFormat::BigEndian) + err = snd_pcm_hw_params_set_format(handle,params,SND_PCM_FORMAT_U32_BE); + } + } + if(err>=0) { + testSize = true; + testType = true; + } + } + if(err>=0) + err = snd_pcm_hw_params(handle, params); + + if(err == 0) { + // settings work + // close() + if(handle) + snd_pcm_close(handle); + return true; + } + if(handle) + snd_pcm_close(handle); + + return false; +} + +void QAudioDeviceInfoInternal::updateLists() +{ + // redo all lists based on current settings + freqz.clear(); + channelz.clear(); + sizez.clear(); + byteOrderz.clear(); + typez.clear(); + codecz.clear(); + + if(!handle) + open(); + + if(!handle) + return; + + for(int i=0; i<(int)MAX_SAMPLE_RATES; i++) { + //if(snd_pcm_hw_params_test_rate(handle, params, SAMPLE_RATES[i], dir) == 0) + freqz.append(SAMPLE_RATES[i]); + } + channelz.append(1); + channelz.append(2); + sizez.append(8); + sizez.append(16); + sizez.append(32); + byteOrderz.append(QAudioFormat::LittleEndian); + byteOrderz.append(QAudioFormat::BigEndian); + typez.append(QAudioFormat::SignedInt); + typez.append(QAudioFormat::UnSignedInt); + typez.append(QAudioFormat::Float); + codecz.append(QLatin1String("audio/pcm")); + close(); +} + +QList QAudioDeviceInfoInternal::availableDevices(QAudio::Mode mode) +{ + QList allDevices; + QList devices; + QByteArray filter; + +#if(SND_LIB_MAJOR == 1 && SND_LIB_MINOR == 0 && SND_LIB_SUBMINOR >= 14) + // Create a list of all current audio devices that support mode + void **hints, **n; + char *name, *descr, *io; + + if(snd_device_name_hint(-1, "pcm", &hints) < 0) { + qWarning() << "no alsa devices available"; + return devices; + } + n = hints; + + if(mode == QAudio::AudioInput) { + filter = "Input"; + } else { + filter = "Output"; + } + + while (*n != NULL) { + name = snd_device_name_get_hint(*n, "NAME"); + descr = snd_device_name_get_hint(*n, "DESC"); + io = snd_device_name_get_hint(*n, "IOID"); + if((name != NULL) && (descr != NULL) && ((io == NULL) || (io == filter))) { + QString deviceName = QLatin1String(name); + QString deviceDescription = QLatin1String(descr); + allDevices.append(deviceName.toLocal8Bit().constData()); + if(deviceDescription.contains(QLatin1String("Default Audio Device"))) + devices.append(deviceName.toLocal8Bit().constData()); + } + if(name != NULL) + free(name); + if(descr != NULL) + free(descr); + if(io != NULL) + free(io); + ++n; + } + snd_device_name_free_hint(hints); + + if(devices.size() > 0) { + devices.append("default"); + } +#else + int idx = 0; + char* name; + + while(snd_card_get_name(idx,&name) == 0) { + devices.append(name); + idx++; + } + if (idx > 0) + devices.append("default"); +#endif + if (devices.size() == 0 && allDevices.size() > 0) + return allDevices; + + return devices; +} + +QByteArray QAudioDeviceInfoInternal::defaultInputDevice() +{ + QList devices = availableDevices(QAudio::AudioInput); + if(devices.size() == 0) + return QByteArray(); + + return devices.first(); +} + +QByteArray QAudioDeviceInfoInternal::defaultOutputDevice() +{ + QList devices = availableDevices(QAudio::AudioOutput); + if(devices.size() == 0) + return QByteArray(); + + return devices.first(); +} + +QT_END_NAMESPACE diff --git a/src/multimedia/multimedia/audio/qaudiodeviceinfo_alsa_p.h b/src/multimedia/multimedia/audio/qaudiodeviceinfo_alsa_p.h new file mode 100644 index 0000000..6f9a459 --- /dev/null +++ b/src/multimedia/multimedia/audio/qaudiodeviceinfo_alsa_p.h @@ -0,0 +1,117 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtMultimedia module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists for the convenience +// of other Qt classes. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + + +#ifndef QAUDIODEVICEINFOALSA_H +#define QAUDIODEVICEINFOALSA_H + +#include + +#include +#include +#include +#include + +#include +#include +#include + +QT_BEGIN_NAMESPACE + +const unsigned int MAX_SAMPLE_RATES = 5; +const unsigned int SAMPLE_RATES[] = + { 8000, 11025, 22050, 44100, 48000 }; + +class QAudioDeviceInfoInternal : public QAbstractAudioDeviceInfo +{ + Q_OBJECT +public: + QAudioDeviceInfoInternal(QByteArray dev,QAudio::Mode mode); + ~QAudioDeviceInfoInternal(); + + bool testSettings(const QAudioFormat& format) const; + void updateLists(); + QAudioFormat preferredFormat() const; + bool isFormatSupported(const QAudioFormat& format) const; + QAudioFormat nearestFormat(const QAudioFormat& format) const; + QString deviceName() const; + QStringList codecList(); + QList frequencyList(); + QList channelsList(); + QList sampleSizeList(); + QList byteOrderList(); + QList sampleTypeList(); + static QByteArray defaultInputDevice(); + static QByteArray defaultOutputDevice(); + static QList availableDevices(QAudio::Mode); + +private: + bool open(); + void close(); + + QString device; + QAudio::Mode mode; + QAudioFormat nearest; + QList freqz; + QList channelz; + QList sizez; + QList byteOrderz; + QStringList codecz; + QList typez; + snd_pcm_t* handle; + snd_pcm_hw_params_t *params; +}; + +QT_END_NAMESPACE + +#endif + diff --git a/src/multimedia/multimedia/audio/qaudiodeviceinfo_mac_p.cpp b/src/multimedia/multimedia/audio/qaudiodeviceinfo_mac_p.cpp new file mode 100644 index 0000000..ecd03e5 --- /dev/null +++ b/src/multimedia/multimedia/audio/qaudiodeviceinfo_mac_p.cpp @@ -0,0 +1,357 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtMultimedia module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists for the convenience +// of other Qt classes. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include +#include +#include +#include +#include +#include + +#include +#include "qaudio_mac_p.h" +#include "qaudiodeviceinfo_mac_p.h" + + + +QT_BEGIN_NAMESPACE + + +QAudioDeviceInfoInternal::QAudioDeviceInfoInternal(QByteArray const& handle, QAudio::Mode) +{ + QDataStream ds(handle); + quint32 did, tm; + + ds >> did >> tm >> name; + deviceId = AudioDeviceID(did); + mode = QAudio::Mode(tm); +} + +bool QAudioDeviceInfoInternal::isFormatSupported(const QAudioFormat& format) const +{ + return format.codec() == QString::fromLatin1("audio/pcm"); +} + +QAudioFormat QAudioDeviceInfoInternal::preferredFormat() const +{ + QAudioFormat rc; + + UInt32 propSize = 0; + + if (AudioDeviceGetPropertyInfo(deviceId, + 0, + mode == QAudio::AudioInput, + kAudioDevicePropertyStreams, + &propSize, + 0) == noErr) { + + const int sc = propSize / sizeof(AudioStreamID); + + if (sc > 0) { + AudioStreamID* streams = new AudioStreamID[sc]; + + if (AudioDeviceGetProperty(deviceId, + 0, + mode == QAudio::AudioInput, + kAudioDevicePropertyStreams, + &propSize, + streams) == noErr) { + + for (int i = 0; i < sc; ++i) { + if (AudioStreamGetPropertyInfo(streams[i], + 0, + kAudioStreamPropertyPhysicalFormat, + &propSize, + 0) == noErr) { + + AudioStreamBasicDescription sf; + + if (AudioStreamGetProperty(streams[i], + 0, + kAudioStreamPropertyPhysicalFormat, + &propSize, + &sf) == noErr) { + rc = toQAudioFormat(sf); + break; + } + } + } + } + + delete streams; + } + } + + return rc; +} + +QAudioFormat QAudioDeviceInfoInternal::nearestFormat(const QAudioFormat& format) const +{ + QAudioFormat rc(format); + QAudioFormat target = preferredFormat(); + + if (!format.codec().isEmpty() && format.codec() != QString::fromLatin1("audio/pcm")) + return QAudioFormat(); + + rc.setCodec(QString::fromLatin1("audio/pcm")); + + if (rc.frequency() != target.frequency()) + rc.setFrequency(target.frequency()); + if (rc.channels() != target.channels()) + rc.setChannels(target.channels()); + if (rc.sampleSize() != target.sampleSize()) + rc.setSampleSize(target.sampleSize()); + if (rc.byteOrder() != target.byteOrder()) + rc.setByteOrder(target.byteOrder()); + if (rc.sampleType() != target.sampleType()) + rc.setSampleType(target.sampleType()); + + return rc; +} + +QString QAudioDeviceInfoInternal::deviceName() const +{ + return name; +} + +QStringList QAudioDeviceInfoInternal::codecList() +{ + return QStringList() << QString::fromLatin1("audio/pcm"); +} + +QList QAudioDeviceInfoInternal::frequencyList() +{ + QSet rc; + + // Add some common frequencies + rc << 8000 << 11025 << 22050 << 44100; + + // + UInt32 propSize = 0; + + if (AudioDeviceGetPropertyInfo(deviceId, + 0, + mode == QAudio::AudioInput, + kAudioDevicePropertyAvailableNominalSampleRates, + &propSize, + 0) == noErr) { + + const int pc = propSize / sizeof(AudioValueRange); + + if (pc > 0) { + AudioValueRange* vr = new AudioValueRange[pc]; + + if (AudioDeviceGetProperty(deviceId, + 0, + mode == QAudio::AudioInput, + kAudioDevicePropertyAvailableNominalSampleRates, + &propSize, + vr) == noErr) { + + for (int i = 0; i < pc; ++i) + rc << vr[i].mMaximum; + } + + delete vr; + } + } + + return rc.toList(); +} + +QList QAudioDeviceInfoInternal::channelsList() +{ + QList rc; + + // Can mix down to 1 channel + rc << 1; + + UInt32 propSize = 0; + int channels = 0; + + if (AudioDeviceGetPropertyInfo(deviceId, + 0, + mode == QAudio::AudioInput, + kAudioDevicePropertyStreamConfiguration, + &propSize, + 0) == noErr) { + + AudioBufferList* audioBufferList = static_cast(qMalloc(propSize)); + + if (audioBufferList != 0) { + if (AudioDeviceGetProperty(deviceId, + 0, + mode == QAudio::AudioInput, + kAudioDevicePropertyStreamConfiguration, + &propSize, + audioBufferList) == noErr) { + + for (int i = 0; i < int(audioBufferList->mNumberBuffers); ++i) { + channels += audioBufferList->mBuffers[i].mNumberChannels; + rc << channels; + } + } + + qFree(audioBufferList); + } + } + + return rc; +} + +QList QAudioDeviceInfoInternal::sampleSizeList() +{ + return QList() << 8 << 16 << 24 << 32 << 64; +} + +QList QAudioDeviceInfoInternal::byteOrderList() +{ + return QList() << QAudioFormat::LittleEndian << QAudioFormat::BigEndian; +} + +QList QAudioDeviceInfoInternal::sampleTypeList() +{ + return QList() << QAudioFormat::SignedInt << QAudioFormat::UnSignedInt << QAudioFormat::Float; +} + +static QByteArray get_device_info(AudioDeviceID audioDevice, QAudio::Mode mode) +{ + UInt32 size; + QByteArray device; + QDataStream ds(&device, QIODevice::WriteOnly); + AudioStreamBasicDescription sf; + CFStringRef name; + Boolean isInput = mode == QAudio::AudioInput; + + // Id + ds << quint32(audioDevice); + + // Mode + size = sizeof(AudioStreamBasicDescription); + if (AudioDeviceGetProperty(audioDevice, 0, isInput, kAudioDevicePropertyStreamFormat, + &size, &sf) != noErr) { + return QByteArray(); + } + ds << quint32(mode); + + // Name + size = sizeof(CFStringRef); + if (AudioDeviceGetProperty(audioDevice, 0, isInput, kAudioObjectPropertyName, + &size, &name) != noErr) { + qWarning() << "QAudioDeviceInfo: Unable to find device name"; + } + ds << QCFString::toQString(name); + + CFRelease(name); + + return device; +} + +QByteArray QAudioDeviceInfoInternal::defaultInputDevice() +{ + AudioDeviceID audioDevice; + UInt32 size = sizeof(audioDevice); + + if (AudioHardwareGetProperty(kAudioHardwarePropertyDefaultInputDevice, &size, + &audioDevice) != noErr) { + qWarning() << "QAudioDeviceInfo: Unable to find default input device"; + return QByteArray(); + } + + return get_device_info(audioDevice, QAudio::AudioInput); +} + +QByteArray QAudioDeviceInfoInternal::defaultOutputDevice() +{ + AudioDeviceID audioDevice; + UInt32 size = sizeof(audioDevice); + + if (AudioHardwareGetProperty(kAudioHardwarePropertyDefaultOutputDevice, &size, + &audioDevice) != noErr) { + qWarning() << "QAudioDeviceInfo: Unable to find default output device"; + return QByteArray(); + } + + return get_device_info(audioDevice, QAudio::AudioOutput); +} + +QList QAudioDeviceInfoInternal::availableDevices(QAudio::Mode mode) +{ + QList devices; + + UInt32 propSize = 0; + + if (AudioHardwareGetPropertyInfo(kAudioHardwarePropertyDevices, &propSize, 0) == noErr) { + + const int dc = propSize / sizeof(AudioDeviceID); + + if (dc > 0) { + AudioDeviceID* audioDevices = new AudioDeviceID[dc]; + + if (AudioHardwareGetProperty(kAudioHardwarePropertyDevices, &propSize, audioDevices) == noErr) { + for (int i = 0; i < dc; ++i) { + QByteArray info = get_device_info(audioDevices[i], mode); + if (!info.isNull()) + devices << info; + } + } + + delete audioDevices; + } + } + + return devices; +} + + +QT_END_NAMESPACE + diff --git a/src/multimedia/multimedia/audio/qaudiodeviceinfo_mac_p.h b/src/multimedia/multimedia/audio/qaudiodeviceinfo_mac_p.h new file mode 100644 index 0000000..e234384 --- /dev/null +++ b/src/multimedia/multimedia/audio/qaudiodeviceinfo_mac_p.h @@ -0,0 +1,97 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtMultimedia module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists for the convenience +// of other Qt classes. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + + +#ifndef QDEVICEINFO_MAC_P_H +#define QDEVICEINFO_MAC_P_H + +#include + +#include + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +class QAudioDeviceInfoInternal : public QAbstractAudioDeviceInfo +{ +public: + AudioDeviceID deviceId; + QString name; + QAudio::Mode mode; + + QAudioDeviceInfoInternal(QByteArray const& handle, QAudio::Mode mode); + + bool isFormatSupported(const QAudioFormat& format) const; + QAudioFormat preferredFormat() const; + QAudioFormat nearestFormat(const QAudioFormat& format) const; + + QString deviceName() const; + + QStringList codecList(); + QList frequencyList(); + QList channelsList(); + QList sampleSizeList(); + QList byteOrderList(); + QList sampleTypeList(); + + static QByteArray defaultInputDevice(); + static QByteArray defaultOutputDevice(); + + static QList availableDevices(QAudio::Mode mode); +}; + +QT_END_NAMESPACE + +QT_END_HEADER + +#endif // QDEVICEINFO_MAC_P_H diff --git a/src/multimedia/multimedia/audio/qaudiodeviceinfo_symbian_p.cpp b/src/multimedia/multimedia/audio/qaudiodeviceinfo_symbian_p.cpp new file mode 100644 index 0000000..36284d3 --- /dev/null +++ b/src/multimedia/multimedia/audio/qaudiodeviceinfo_symbian_p.cpp @@ -0,0 +1,200 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtMultimedia module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qaudiodeviceinfo_symbian_p.h" +#include "qaudio_symbian_p.h" + +QT_BEGIN_NAMESPACE + +QAudioDeviceInfoInternal::QAudioDeviceInfoInternal(QByteArray device, + QAudio::Mode mode) + : m_deviceName(QLatin1String(device)) + , m_mode(mode) + , m_updated(false) +{ + QT_TRAP_THROWING(m_devsound.reset(CMMFDevSound::NewL())); +} + +QAudioDeviceInfoInternal::~QAudioDeviceInfoInternal() +{ + +} + +QAudioFormat QAudioDeviceInfoInternal::preferredFormat() const +{ + QAudioFormat format; + switch (m_mode) { + case QAudio::AudioOutput: + format.setFrequency(44100); + format.setChannels(2); + format.setSampleSize(16); + format.setByteOrder(QAudioFormat::LittleEndian); + format.setSampleType(QAudioFormat::SignedInt); + format.setCodec(QLatin1String("audio/pcm")); + break; + + case QAudio::AudioInput: + format.setFrequency(8000); + format.setChannels(1); + format.setSampleSize(16); + format.setByteOrder(QAudioFormat::LittleEndian); + format.setSampleType(QAudioFormat::SignedInt); + format.setCodec(QLatin1String("audio/pcm")); + break; + + default: + Q_ASSERT_X(false, Q_FUNC_INFO, "Invalid mode"); + } + + if (!isFormatSupported(format)) { + if (m_frequencies.size()) + format.setFrequency(m_frequencies[0]); + if (m_channels.size()) + format.setChannels(m_channels[0]); + if (m_sampleSizes.size()) + format.setSampleSize(m_sampleSizes[0]); + if (m_byteOrders.size()) + format.setByteOrder(m_byteOrders[0]); + if (m_sampleTypes.size()) + format.setSampleType(m_sampleTypes[0]); + } + + return format; +} + +bool QAudioDeviceInfoInternal::isFormatSupported( + const QAudioFormat &format) const +{ + getSupportedFormats(); + const bool supported = + m_codecs.contains(format.codec()) + && m_frequencies.contains(format.frequency()) + && m_channels.contains(format.channels()) + && m_sampleSizes.contains(format.sampleSize()) + && m_byteOrders.contains(format.byteOrder()) + && m_sampleTypes.contains(format.sampleType()); + + return supported; +} + +QAudioFormat QAudioDeviceInfoInternal::nearestFormat(const QAudioFormat &format) const +{ + if (isFormatSupported(format)) + return format; + else + return preferredFormat(); +} + +QString QAudioDeviceInfoInternal::deviceName() const +{ + return m_deviceName; +} + +QStringList QAudioDeviceInfoInternal::codecList() +{ + getSupportedFormats(); + return m_codecs; +} + +QList QAudioDeviceInfoInternal::frequencyList() +{ + getSupportedFormats(); + return m_frequencies; +} + +QList QAudioDeviceInfoInternal::channelsList() +{ + getSupportedFormats(); + return m_channels; +} + +QList QAudioDeviceInfoInternal::sampleSizeList() +{ + getSupportedFormats(); + return m_sampleSizes; +} + +QList QAudioDeviceInfoInternal::byteOrderList() +{ + getSupportedFormats(); + return m_byteOrders; +} + +QList QAudioDeviceInfoInternal::sampleTypeList() +{ + getSupportedFormats(); + return m_sampleTypes; +} + +QByteArray QAudioDeviceInfoInternal::defaultInputDevice() +{ + return QByteArray("default"); +} + +QByteArray QAudioDeviceInfoInternal::defaultOutputDevice() +{ + return QByteArray("default"); +} + +QList QAudioDeviceInfoInternal::availableDevices(QAudio::Mode) +{ + QList result; + result += QByteArray("default"); + return result; +} + +void QAudioDeviceInfoInternal::getSupportedFormats() const +{ + if (!m_updated) { + QScopedPointer caps( + new SymbianAudio::DevSoundCapabilities(*m_devsound, m_mode)); + + SymbianAudio::Utils::capabilitiesNativeToQt(*caps, + m_frequencies, m_channels, m_sampleSizes, + m_byteOrders, m_sampleTypes); + + m_codecs.append(QLatin1String("audio/pcm")); + + m_updated = true; + } +} + +QT_END_NAMESPACE diff --git a/src/multimedia/multimedia/audio/qaudiodeviceinfo_symbian_p.h b/src/multimedia/multimedia/audio/qaudiodeviceinfo_symbian_p.h new file mode 100644 index 0000000..89e539f --- /dev/null +++ b/src/multimedia/multimedia/audio/qaudiodeviceinfo_symbian_p.h @@ -0,0 +1,107 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtMultimedia module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists for the convenience +// of other Qt classes. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#ifndef QAUDIODEVICEINFO_SYMBIAN_P_H +#define QAUDIODEVICEINFO_SYMBIAN_P_H + +#include +#include + +QT_BEGIN_NAMESPACE + +class QAudioDeviceInfoInternal + : public QAbstractAudioDeviceInfo +{ + Q_OBJECT + +public: + QAudioDeviceInfoInternal(QByteArray device, QAudio::Mode mode); + ~QAudioDeviceInfoInternal(); + + // QAbstractAudioDeviceInfo + QAudioFormat preferredFormat() const; + bool isFormatSupported(const QAudioFormat &format) const; + QAudioFormat nearestFormat(const QAudioFormat &format) const; + QString deviceName() const; + QStringList codecList(); + QList frequencyList(); + QList channelsList(); + QList sampleSizeList(); + QList byteOrderList(); + QList sampleTypeList(); + static QByteArray defaultInputDevice(); + static QByteArray defaultOutputDevice(); + static QList availableDevices(QAudio::Mode); + +private: + void getSupportedFormats() const; + +private: + QScopedPointer m_devsound; + + QString m_deviceName; + QAudio::Mode m_mode; + + // Mutable to allow lazy initialization when called from const-qualified + // public functions (isFormatSupported, nearestFormat) + mutable bool m_updated; + mutable QStringList m_codecs; + mutable QList m_frequencies; + mutable QList m_channels; + mutable QList m_sampleSizes; + mutable QList m_byteOrders; + mutable QList m_sampleTypes; +}; + +QT_END_NAMESPACE + +#endif diff --git a/src/multimedia/multimedia/audio/qaudiodeviceinfo_win32_p.cpp b/src/multimedia/multimedia/audio/qaudiodeviceinfo_win32_p.cpp new file mode 100644 index 0000000..aee0807 --- /dev/null +++ b/src/multimedia/multimedia/audio/qaudiodeviceinfo_win32_p.cpp @@ -0,0 +1,433 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtMultimedia module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists for the convenience +// of other Qt classes. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + + +#include +#include +#include "qaudiodeviceinfo_win32_p.h" + +QT_BEGIN_NAMESPACE + +// For mingw toolchain mmsystem.h only defines half the defines, so add if needed. +#ifndef WAVE_FORMAT_44M08 +#define WAVE_FORMAT_44M08 0x00000100 +#define WAVE_FORMAT_44S08 0x00000200 +#define WAVE_FORMAT_44M16 0x00000400 +#define WAVE_FORMAT_44S16 0x00000800 +#define WAVE_FORMAT_48M08 0x00001000 +#define WAVE_FORMAT_48S08 0x00002000 +#define WAVE_FORMAT_48M16 0x00004000 +#define WAVE_FORMAT_48S16 0x00008000 +#define WAVE_FORMAT_96M08 0x00010000 +#define WAVE_FORMAT_96S08 0x00020000 +#define WAVE_FORMAT_96M16 0x00040000 +#define WAVE_FORMAT_96S16 0x00080000 +#endif + + +QAudioDeviceInfoInternal::QAudioDeviceInfoInternal(QByteArray dev, QAudio::Mode mode) +{ + device = QLatin1String(dev); + this->mode = mode; + + updateLists(); +} + +QAudioDeviceInfoInternal::~QAudioDeviceInfoInternal() +{ + close(); +} + +bool QAudioDeviceInfoInternal::isFormatSupported(const QAudioFormat& format) const +{ + return testSettings(format); +} + +QAudioFormat QAudioDeviceInfoInternal::preferredFormat() const +{ + QAudioFormat nearest; + if(mode == QAudio::AudioOutput) { + nearest.setFrequency(44100); + nearest.setChannelCount(2); + nearest.setByteOrder(QAudioFormat::LittleEndian); + nearest.setSampleType(QAudioFormat::SignedInt); + nearest.setSampleSize(16); + nearest.setCodec(QLatin1String("audio/pcm")); + } else { + nearest.setFrequency(11025); + nearest.setChannelCount(1); + nearest.setByteOrder(QAudioFormat::LittleEndian); + nearest.setSampleType(QAudioFormat::SignedInt); + nearest.setSampleSize(8); + nearest.setCodec(QLatin1String("audio/pcm")); + } + return nearest; +} + +QAudioFormat QAudioDeviceInfoInternal::nearestFormat(const QAudioFormat& format) const +{ + if(testSettings(format)) + return format; + else + return preferredFormat(); +} + +QString QAudioDeviceInfoInternal::deviceName() const +{ + return device; +} + +QStringList QAudioDeviceInfoInternal::codecList() +{ + updateLists(); + return codecz; +} + +QList QAudioDeviceInfoInternal::frequencyList() +{ + updateLists(); + return freqz; +} + +QList QAudioDeviceInfoInternal::channelsList() +{ + updateLists(); + return channelz; +} + +QList QAudioDeviceInfoInternal::sampleSizeList() +{ + updateLists(); + return sizez; +} + +QList QAudioDeviceInfoInternal::byteOrderList() +{ + updateLists(); + return byteOrderz; +} + +QList QAudioDeviceInfoInternal::sampleTypeList() +{ + updateLists(); + return typez; +} + + +bool QAudioDeviceInfoInternal::open() +{ + return true; +} + +void QAudioDeviceInfoInternal::close() +{ +} + +bool QAudioDeviceInfoInternal::testSettings(const QAudioFormat& format) const +{ + // Set nearest to closest settings that do work. + // See if what is in settings will work (return value). + + bool failed = false; + bool match = false; + + // check codec + for( int i = 0; i < codecz.count(); i++) { + if (format.codec() == codecz.at(i)) + match = true; + } + if (!match) failed = true; + + // check channel + match = false; + if (!failed) { + for( int i = 0; i < channelz.count(); i++) { + if (format.channels() == channelz.at(i)) { + match = true; + break; + } + } + } + if (!match) failed = true; + + // check frequency + match = false; + if (!failed) { + for( int i = 0; i < freqz.count(); i++) { + if (format.frequency() == freqz.at(i)) { + match = true; + break; + } + } + } + + // check sample size + match = false; + if (!failed) { + for( int i = 0; i < sizez.count(); i++) { + if (format.sampleSize() == sizez.at(i)) { + match = true; + break; + } + } + } + + // check byte order + match = false; + if (!failed) { + for( int i = 0; i < byteOrderz.count(); i++) { + if (format.byteOrder() == byteOrderz.at(i)) { + match = true; + break; + } + } + } + + // check sample type + match = false; + if (!failed) { + for( int i = 0; i < typez.count(); i++) { + if (format.sampleType() == typez.at(i)) { + match = true; + break; + } + } + } + + if(!failed) { + // settings work + return true; + } + return false; +} + +void QAudioDeviceInfoInternal::updateLists() +{ + // redo all lists based on current settings + bool base = false; + bool match = false; + DWORD fmt = NULL; + QString tmp; + + if(device.compare(QLatin1String("default")) == 0) + base = true; + + if(mode == QAudio::AudioOutput) { + WAVEOUTCAPS woc; + unsigned long iNumDevs,i; + iNumDevs = waveOutGetNumDevs(); + for(i=0;i 0) + freqz.prepend(8000); +} + +QList QAudioDeviceInfoInternal::availableDevices(QAudio::Mode mode) +{ + Q_UNUSED(mode) + + QList devices; + + if(mode == QAudio::AudioOutput) { + WAVEOUTCAPS woc; + unsigned long iNumDevs,i; + iNumDevs = waveOutGetNumDevs(); + for(i=0;i 0) + devices.append("default"); + + return devices; +} + +QByteArray QAudioDeviceInfoInternal::defaultOutputDevice() +{ + return QByteArray("default"); +} + +QByteArray QAudioDeviceInfoInternal::defaultInputDevice() +{ + return QByteArray("default"); +} + +QT_END_NAMESPACE diff --git a/src/multimedia/multimedia/audio/qaudiodeviceinfo_win32_p.h b/src/multimedia/multimedia/audio/qaudiodeviceinfo_win32_p.h new file mode 100644 index 0000000..cb6dd91 --- /dev/null +++ b/src/multimedia/multimedia/audio/qaudiodeviceinfo_win32_p.h @@ -0,0 +1,112 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtMultimedia module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists for the convenience +// of other Qt classes. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + + +#ifndef QAUDIODEVICEINFOWIN_H +#define QAUDIODEVICEINFOWIN_H + +#include +#include +#include +#include + +#include +#include + + +QT_BEGIN_NAMESPACE + +const unsigned int MAX_SAMPLE_RATES = 5; +const unsigned int SAMPLE_RATES[] = { 8000, 11025, 22050, 44100, 48000 }; + +class QAudioDeviceInfoInternal : public QAbstractAudioDeviceInfo +{ + Q_OBJECT + +public: + QAudioDeviceInfoInternal(QByteArray dev,QAudio::Mode mode); + ~QAudioDeviceInfoInternal(); + + bool open(); + void close(); + + bool testSettings(const QAudioFormat& format) const; + void updateLists(); + QAudioFormat preferredFormat() const; + bool isFormatSupported(const QAudioFormat& format) const; + QAudioFormat nearestFormat(const QAudioFormat& format) const; + QString deviceName() const; + QStringList codecList(); + QList frequencyList(); + QList channelsList(); + QList sampleSizeList(); + QList byteOrderList(); + QList sampleTypeList(); + static QByteArray defaultInputDevice(); + static QByteArray defaultOutputDevice(); + static QList availableDevices(QAudio::Mode); + +private: + QAudio::Mode mode; + QString device; + QAudioFormat nearest; + QList freqz; + QList channelz; + QList sizez; + QList byteOrderz; + QStringList codecz; + QList typez; +}; + +QT_END_NAMESPACE + +#endif diff --git a/src/multimedia/multimedia/audio/qaudioengine.cpp b/src/multimedia/multimedia/audio/qaudioengine.cpp new file mode 100644 index 0000000..7f1f5d3 --- /dev/null +++ b/src/multimedia/multimedia/audio/qaudioengine.cpp @@ -0,0 +1,343 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtMultimedia module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include + +QT_BEGIN_NAMESPACE + +/*! + \class QAbstractAudioDeviceInfo + \brief The QAbstractAudioDeviceInfo class provides access for QAudioDeviceInfo to access the audio + device provided by the plugin. + \internal + + \ingroup multimedia + + This class implements the audio functionality for + QAudioDeviceInfo, i.e., QAudioDeviceInfo keeps a + QAbstractAudioDeviceInfo and routes function calls to it. For a + description of the functionality that QAbstractAudioDeviceInfo + implements, you can read the class and functions documentation of + QAudioDeviceInfo. + + \sa QAudioDeviceInfo +*/ + +/*! + \fn virtual QAudioFormat QAbstractAudioDeviceInfo::preferredFormat() const + Returns the nearest settings. +*/ + +/*! + \fn virtual bool QAbstractAudioDeviceInfo::isFormatSupported(const QAudioFormat& format) const + Returns true if \a format is available from audio device. +*/ + +/*! + \fn virtual QAudioFormat QAbstractAudioDeviceInfo::nearestFormat(const QAudioFormat& format) const + Returns the nearest settings \a format. +*/ + +/*! + \fn virtual QString QAbstractAudioDeviceInfo::deviceName() const + Returns the audio device name. +*/ + +/*! + \fn virtual QStringList QAbstractAudioDeviceInfo::codecList() + Returns the list of currently available codecs. +*/ + +/*! + \fn virtual QList QAbstractAudioDeviceInfo::frequencyList() + Returns the list of currently available frequencies. +*/ + +/*! + \fn virtual QList QAbstractAudioDeviceInfo::channelsList() + Returns the list of currently available channels. +*/ + +/*! + \fn virtual QList QAbstractAudioDeviceInfo::sampleSizeList() + Returns the list of currently available sample sizes. +*/ + +/*! + \fn virtual QList QAbstractAudioDeviceInfo::byteOrderList() + Returns the list of currently available byte orders. +*/ + +/*! + \fn virtual QList QAbstractAudioDeviceInfo::sampleTypeList() + Returns the list of currently available sample types. +*/ + +/*! + \class QAbstractAudioOutput + \brief The QAbstractAudioOutput class provides access for QAudioOutput to access the audio + device provided by the plugin. + \internal + + \ingroup multimedia + + QAbstractAudioOutput implements audio functionality for + QAudioOutput, i.e., QAudioOutput routes function calls to + QAbstractAudioOutput. For a description of the functionality that + is implemented, see the QAudioOutput class and function + descriptions. + + \sa QAudioOutput +*/ + +/*! + \fn virtual QIODevice* QAbstractAudioOutput::start(QIODevice* device) + Uses the \a device as the QIODevice to transfer data. If \a device is null then the class + creates an internal QIODevice. Returns a pointer to the QIODevice being used to handle + the data transfer. This QIODevice can be used to write() audio data directly. Passing a + QIODevice allows the data to be transfered without any extra code. +*/ + +/*! + \fn virtual void QAbstractAudioOutput::stop() + Stops the audio output. +*/ + +/*! + \fn virtual void QAbstractAudioOutput::reset() + Drops all audio data in the buffers, resets buffers to zero. +*/ + +/*! + \fn virtual void QAbstractAudioOutput::suspend() + Stops processing audio data, preserving buffered audio data. +*/ + +/*! + \fn virtual void QAbstractAudioOutput::resume() + Resumes processing audio data after a suspend() +*/ + +/*! + \fn virtual int QAbstractAudioOutput::bytesFree() const + Returns the free space available in bytes in the audio buffer. +*/ + +/*! + \fn virtual int QAbstractAudioOutput::periodSize() const + Returns the period size in bytes. +*/ + +/*! + \fn virtual void QAbstractAudioOutput::setBufferSize(int value) + Sets the audio buffer size to \a value in bytes. +*/ + +/*! + \fn virtual int QAbstractAudioOutput::bufferSize() const + Returns the audio buffer size in bytes. +*/ + +/*! + \fn virtual void QAbstractAudioOutput::setNotifyInterval(int ms) + Sets the interval for notify() signal to be emitted. This is based on the \a ms + of audio data processed not on actual real-time. The resolution of the timer + is platform specific. +*/ + +/*! + \fn virtual int QAbstractAudioOutput::notifyInterval() const + Returns the notify interval in milliseconds. +*/ + +/*! + \fn virtual qint64 QAbstractAudioOutput::processedUSecs() const + Returns the amount of audio data processed since start() was called in milliseconds. +*/ + +/*! + \fn virtual qint64 QAbstractAudioOutput::elapsedUSecs() const + Returns the milliseconds since start() was called, including time in Idle and suspend states. +*/ + +/*! + \fn virtual QAudio::Error QAbstractAudioOutput::error() const + Returns the error state. +*/ + +/*! + \fn virtual QAudio::State QAbstractAudioOutput::state() const + Returns the state of audio processing. +*/ + +/*! + \fn virtual QAudioFormat QAbstractAudioOutput::format() const + Returns the QAudioFormat being used. +*/ + +/*! + \fn QAbstractAudioOutput::stateChanged(QAudio::State state) + This signal is emitted when the device \a state has changed. +*/ + +/*! + \fn QAbstractAudioOutput::notify() + This signal is emitted when x ms of audio data has been processed + the interval set by setNotifyInterval(x). +*/ + + +/*! + \class QAbstractAudioInput + \brief The QAbstractAudioInput class provides access for QAudioInput to access the audio + device provided by the plugin. + \internal + + \ingroup multimedia + + QAudioDeviceInput keeps an instance of QAbstractAudioInput and + routes calls to functions of the same name to QAbstractAudioInput. + This means that it is QAbstractAudioInput that implements the + audio functionality. For a description of the functionality, see + the QAudioInput class description. + + \sa QAudioInput +*/ + +/*! + \fn virtual QIODevice* QAbstractAudioInput::start(QIODevice* device) + Uses the \a device as the QIODevice to transfer data. If \a device is null + then the class creates an internal QIODevice. Returns a pointer to the + QIODevice being used to handle the data transfer. This QIODevice can be used to + read() audio data directly. Passing a QIODevice allows the data to be transfered + without any extra code. +*/ + +/*! + \fn virtual void QAbstractAudioInput::stop() + Stops the audio input. +*/ + +/*! + \fn virtual void QAbstractAudioInput::reset() + Drops all audio data in the buffers, resets buffers to zero. +*/ + +/*! + \fn virtual void QAbstractAudioInput::suspend() + Stops processing audio data, preserving buffered audio data. +*/ + +/*! + \fn virtual void QAbstractAudioInput::resume() + Resumes processing audio data after a suspend(). +*/ + +/*! + \fn virtual int QAbstractAudioInput::bytesReady() const + Returns the amount of audio data available to read in bytes. +*/ + +/*! + \fn virtual int QAbstractAudioInput::periodSize() const + Returns the period size in bytes. +*/ + +/*! + \fn virtual void QAbstractAudioInput::setBufferSize(int value) + Sets the audio buffer size to \a value in milliseconds. +*/ + +/*! + \fn virtual int QAbstractAudioInput::bufferSize() const + Returns the audio buffer size in milliseconds. +*/ + +/*! + \fn virtual void QAbstractAudioInput::setNotifyInterval(int ms) + Sets the interval for notify() signal to be emitted. This is based + on the \a ms of audio data processed not on actual real-time. + The resolution of the timer is platform specific. +*/ + +/*! + \fn virtual int QAbstractAudioInput::notifyInterval() const + Returns the notify interval in milliseconds. +*/ + +/*! + \fn virtual qint64 QAbstractAudioInput::processedUSecs() const + Returns the amount of audio data processed since start() was called in milliseconds. +*/ + +/*! + \fn virtual qint64 QAbstractAudioInput::elapsedUSecs() const + Returns the milliseconds since start() was called, including time in Idle and suspend states. +*/ + +/*! + \fn virtual QAudio::Error QAbstractAudioInput::error() const + Returns the error state. +*/ + +/*! + \fn virtual QAudio::State QAbstractAudioInput::state() const + Returns the state of audio processing. +*/ + +/*! + \fn virtual QAudioFormat QAbstractAudioInput::format() const + Returns the QAudioFormat being used +*/ + +/*! + \fn QAbstractAudioInput::stateChanged(QAudio::State state) + This signal is emitted when the device \a state has changed. +*/ + +/*! + \fn QAbstractAudioInput::notify() + This signal is emitted when x ms of audio data has been processed + the interval set by setNotifyInterval(x). +*/ + + +QT_END_NAMESPACE diff --git a/src/multimedia/multimedia/audio/qaudioengine.h b/src/multimedia/multimedia/audio/qaudioengine.h new file mode 100644 index 0000000..df9d09d --- /dev/null +++ b/src/multimedia/multimedia/audio/qaudioengine.h @@ -0,0 +1,131 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtMultimedia module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QAUDIOENGINE_H +#define QAUDIOENGINE_H + +#include +#include +#include +#include + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Multimedia) + +class Q_MULTIMEDIA_EXPORT QAbstractAudioDeviceInfo : public QObject +{ + Q_OBJECT + +public: + virtual QAudioFormat preferredFormat() const = 0; + virtual bool isFormatSupported(const QAudioFormat &format) const = 0; + virtual QAudioFormat nearestFormat(const QAudioFormat &format) const = 0; + virtual QString deviceName() const = 0; + virtual QStringList codecList() = 0; + virtual QList frequencyList() = 0; + virtual QList channelsList() = 0; + virtual QList sampleSizeList() = 0; + virtual QList byteOrderList() = 0; + virtual QList sampleTypeList() = 0; +}; + +class Q_MULTIMEDIA_EXPORT QAbstractAudioOutput : public QObject +{ + Q_OBJECT + +public: + virtual QIODevice* start(QIODevice* device) = 0; + virtual void stop() = 0; + virtual void reset() = 0; + virtual void suspend() = 0; + virtual void resume() = 0; + virtual int bytesFree() const = 0; + virtual int periodSize() const = 0; + virtual void setBufferSize(int value) = 0; + virtual int bufferSize() const = 0; + virtual void setNotifyInterval(int milliSeconds) = 0; + virtual int notifyInterval() const = 0; + virtual qint64 processedUSecs() const = 0; + virtual qint64 elapsedUSecs() const = 0; + virtual QAudio::Error error() const = 0; + virtual QAudio::State state() const = 0; + virtual QAudioFormat format() const = 0; + +Q_SIGNALS: + void stateChanged(QAudio::State); + void notify(); +}; + +class Q_MULTIMEDIA_EXPORT QAbstractAudioInput : public QObject +{ + Q_OBJECT + +public: + virtual QIODevice* start(QIODevice* device) = 0; + virtual void stop() = 0; + virtual void reset() = 0; + virtual void suspend() = 0; + virtual void resume() = 0; + virtual int bytesReady() const = 0; + virtual int periodSize() const = 0; + virtual void setBufferSize(int value) = 0; + virtual int bufferSize() const = 0; + virtual void setNotifyInterval(int milliSeconds) = 0; + virtual int notifyInterval() const = 0; + virtual qint64 processedUSecs() const = 0; + virtual qint64 elapsedUSecs() const = 0; + virtual QAudio::Error error() const = 0; + virtual QAudio::State state() const = 0; + virtual QAudioFormat format() const = 0; + +Q_SIGNALS: + void stateChanged(QAudio::State); + void notify(); +}; + +QT_END_NAMESPACE + +QT_END_HEADER + +#endif // QAUDIOENGINE_H diff --git a/src/multimedia/multimedia/audio/qaudioengineplugin.cpp b/src/multimedia/multimedia/audio/qaudioengineplugin.cpp new file mode 100644 index 0000000..82324b5 --- /dev/null +++ b/src/multimedia/multimedia/audio/qaudioengineplugin.cpp @@ -0,0 +1,54 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtMultimedia module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + + +#include + +QT_BEGIN_NAMESPACE + +QAudioEnginePlugin::QAudioEnginePlugin(QObject* parent) : + QObject(parent) +{} + +QAudioEnginePlugin::~QAudioEnginePlugin() +{} + +QT_END_NAMESPACE diff --git a/src/multimedia/multimedia/audio/qaudioengineplugin.h b/src/multimedia/multimedia/audio/qaudioengineplugin.h new file mode 100644 index 0000000..2322d2a --- /dev/null +++ b/src/multimedia/multimedia/audio/qaudioengineplugin.h @@ -0,0 +1,93 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtMultimedia module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + + +#ifndef QAUDIOENGINEPLUGIN_H +#define QAUDIOENGINEPLUGIN_H + +#include +#include +#include + +#include +#include +#include + + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Multimedia) + +struct Q_MULTIMEDIA_EXPORT QAudioEngineFactoryInterface : public QFactoryInterface +{ + virtual QList availableDevices(QAudio::Mode) const = 0; + virtual QAbstractAudioInput* createInput(const QByteArray& device, const QAudioFormat& format = QAudioFormat()) = 0; + virtual QAbstractAudioOutput* createOutput(const QByteArray& device, const QAudioFormat& format = QAudioFormat()) = 0; + virtual QAbstractAudioDeviceInfo* createDeviceInfo(const QByteArray& device, QAudio::Mode mode) = 0; +}; + +#define QAudioEngineFactoryInterface_iid \ + "com.nokia.qt.QAudioEngineFactoryInterface" +Q_DECLARE_INTERFACE(QAudioEngineFactoryInterface, QAudioEngineFactoryInterface_iid) + +class Q_MULTIMEDIA_EXPORT QAudioEnginePlugin : public QObject, public QAudioEngineFactoryInterface +{ + Q_OBJECT + Q_INTERFACES(QAudioEngineFactoryInterface:QFactoryInterface) + +public: + QAudioEnginePlugin(QObject *parent = 0); + ~QAudioEnginePlugin(); + + virtual QStringList keys() const = 0; + virtual QList availableDevices(QAudio::Mode) const = 0; + virtual QAbstractAudioInput* createInput(const QByteArray& device, const QAudioFormat& format = QAudioFormat()) = 0; + virtual QAbstractAudioOutput* createOutput(const QByteArray& device, const QAudioFormat& format = QAudioFormat()) = 0; + virtual QAbstractAudioDeviceInfo* createDeviceInfo(const QByteArray& device, QAudio::Mode mode) = 0; +}; + +QT_END_NAMESPACE + +QT_END_HEADER + +#endif // QAUDIOENGINEPLUGIN_H diff --git a/src/multimedia/multimedia/audio/qaudioformat.cpp b/src/multimedia/multimedia/audio/qaudioformat.cpp new file mode 100644 index 0000000..86d72f6 --- /dev/null +++ b/src/multimedia/multimedia/audio/qaudioformat.cpp @@ -0,0 +1,407 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtMultimedia module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include +#include + + +QT_BEGIN_NAMESPACE + + +class QAudioFormatPrivate : public QSharedData +{ +public: + QAudioFormatPrivate() + { + frequency = -1; + channels = -1; + sampleSize = -1; + byteOrder = QAudioFormat::Endian(QSysInfo::ByteOrder); + sampleType = QAudioFormat::Unknown; + } + + QAudioFormatPrivate(const QAudioFormatPrivate &other): + QSharedData(other), + codec(other.codec), + byteOrder(other.byteOrder), + sampleType(other.sampleType), + frequency(other.frequency), + channels(other.channels), + sampleSize(other.sampleSize) + { + } + + QAudioFormatPrivate& operator=(const QAudioFormatPrivate &other) + { + codec = other.codec; + byteOrder = other.byteOrder; + sampleType = other.sampleType; + frequency = other.frequency; + channels = other.channels; + sampleSize = other.sampleSize; + + return *this; + } + + QString codec; + QAudioFormat::Endian byteOrder; + QAudioFormat::SampleType sampleType; + int frequency; + int channels; + int sampleSize; +}; + +/*! + \class QAudioFormat + \brief The QAudioFormat class stores audio parameter information. + + \inmodule QtMultimedia + \ingroup multimedia + \since 4.6 + + An audio format specifies how data in an audio stream is arranged, + i.e, how the stream is to be interpreted. The encoding itself is + specified by the codec() used for the stream. + + In addition to the encoding, QAudioFormat contains other + parameters that further specify how the audio data is arranged. + These are the frequency, the number of channels, the sample size, + the sample type, and the byte order. The following table describes + these in more detail. + + \table + \header + \o Parameter + \o Description + \row + \o Sample Rate + \o Samples per second of audio data in Hertz. + \row + \o Number of channels + \o The number of audio channels (typically one for mono + or two for stereo) + \row + \o Sample size + \o How much data is stored in each sample (typically 8 + or 16 bits) + \row + \o Sample type + \o Numerical representation of sample (typically signed integer, + unsigned integer or float) + \row + \o Byte order + \o Byte ordering of sample (typically little endian, big endian) + \endtable + + You can obtain audio formats compatible with the audio device used + through functions in QAudioDeviceInfo. This class also lets you + query available parameter values for a device, so that you can set + the parameters yourself. See the QAudioDeviceInfo class + description for details. You need to know the format of the audio + streams you wish to play. Qt does not set up formats for you. +*/ + +/*! + Construct a new audio format. + + Values are initialized as follows: + \list + \o sampleRate() = -1 + \o channelCount() = -1 + \o sampleSize() = -1 + \o byteOrder() = QAudioFormat::Endian(QSysInfo::ByteOrder) + \o sampleType() = QAudioFormat::Unknown + \c codec() = "" + \endlist +*/ + +QAudioFormat::QAudioFormat(): + d(new QAudioFormatPrivate) +{ +} + +/*! + Construct a new audio format using \a other. +*/ + +QAudioFormat::QAudioFormat(const QAudioFormat &other): + d(other.d) +{ +} + +/*! + Destroy this audio format. +*/ + +QAudioFormat::~QAudioFormat() +{ +} + +/*! + Assigns \a other to this QAudioFormat implementation. +*/ + +QAudioFormat& QAudioFormat::operator=(const QAudioFormat &other) +{ + d = other.d; + return *this; +} + +/*! + Returns true if this QAudioFormat is equal to the \a other + QAudioFormat; otherwise returns false. + + All elements of QAudioFormat are used for the comparison. +*/ + +bool QAudioFormat::operator==(const QAudioFormat &other) const +{ + return d->frequency == other.d->frequency && + d->channels == other.d->channels && + d->sampleSize == other.d->sampleSize && + d->byteOrder == other.d->byteOrder && + d->codec == other.d->codec && + d->sampleType == other.d->sampleType; +} + +/*! + Returns true if this QAudioFormat is not equal to the \a other + QAudioFormat; otherwise returns false. + + All elements of QAudioFormat are used for the comparison. +*/ + +bool QAudioFormat::operator!=(const QAudioFormat& other) const +{ + return !(*this == other); +} + +/*! + Returns true if all of the parameters are valid. +*/ + +bool QAudioFormat::isValid() const +{ + return d->frequency != -1 && d->channels != -1 && d->sampleSize != -1 && + d->sampleType != QAudioFormat::Unknown && !d->codec.isEmpty(); +} + +/*! + Sets the sample rate to \a samplerate Hertz. + + \since 4.7 +*/ + +void QAudioFormat::setSampleRate(int samplerate) +{ + d->frequency = samplerate; +} + +/*! + \obsolete + + Use setSampleRate() instead. +*/ + +void QAudioFormat::setFrequency(int frequency) +{ + d->frequency = frequency; +} + +/*! + Returns the current sample rate in Hertz. + + \since 4.7 +*/ + +int QAudioFormat::sampleRate() const +{ + return d->frequency; +} + +/*! + \obsolete + + Use sampleRate() instead. +*/ + +int QAudioFormat::frequency() const +{ + return d->frequency; +} + +/*! + Sets the channel count to \a channels. + + \since 4.7 +*/ + +void QAudioFormat::setChannelCount(int channels) +{ + d->channels = channels; +} + +/*! + \obsolete + + Use setChannelCount() instead. +*/ + +void QAudioFormat::setChannels(int channels) +{ + d->channels = channels; +} + +/*! + Returns the current channel count value. + + \since 4.7 +*/ + +int QAudioFormat::channelCount() const +{ + return d->channels; +} + +/*! + \obsolete + + Use channelCount() instead. +*/ + +int QAudioFormat::channels() const +{ + return d->channels; +} + +/*! + Sets the sample size to the \a sampleSize specified. +*/ + +void QAudioFormat::setSampleSize(int sampleSize) +{ + d->sampleSize = sampleSize; +} + +/*! + Returns the current sample size value. +*/ + +int QAudioFormat::sampleSize() const +{ + return d->sampleSize; +} + +/*! + Sets the codec to \a codec. + + \sa QAudioDeviceInfo::supportedCodecs() +*/ + +void QAudioFormat::setCodec(const QString &codec) +{ + d->codec = codec; +} + +/*! + Returns the current codec value. + + \sa QAudioDeviceInfo::supportedCodecs() +*/ + +QString QAudioFormat::codec() const +{ + return d->codec; +} + +/*! + Sets the byteOrder to \a byteOrder. +*/ + +void QAudioFormat::setByteOrder(QAudioFormat::Endian byteOrder) +{ + d->byteOrder = byteOrder; +} + +/*! + Returns the current byteOrder value. +*/ + +QAudioFormat::Endian QAudioFormat::byteOrder() const +{ + return d->byteOrder; +} + +/*! + Sets the sampleType to \a sampleType. +*/ + +void QAudioFormat::setSampleType(QAudioFormat::SampleType sampleType) +{ + d->sampleType = sampleType; +} + +/*! + Returns the current SampleType value. +*/ + +QAudioFormat::SampleType QAudioFormat::sampleType() const +{ + return d->sampleType; +} + +/*! + \enum QAudioFormat::SampleType + + \value Unknown Not Set + \value SignedInt samples are signed integers + \value UnSignedInt samples are unsigned intergers + \value Float samples are floats +*/ + +/*! + \enum QAudioFormat::Endian + + \value BigEndian samples are big endian byte order + \value LittleEndian samples are little endian byte order +*/ + +QT_END_NAMESPACE + diff --git a/src/multimedia/multimedia/audio/qaudioformat.h b/src/multimedia/multimedia/audio/qaudioformat.h new file mode 100644 index 0000000..6c835b7 --- /dev/null +++ b/src/multimedia/multimedia/audio/qaudioformat.h @@ -0,0 +1,107 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtMultimedia module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + + +#ifndef QAUDIOFORMAT_H +#define QAUDIOFORMAT_H + +#include +#include +#include + + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Multimedia) + + +class QAudioFormatPrivate; + +class Q_MULTIMEDIA_EXPORT QAudioFormat +{ +public: + enum SampleType { Unknown, SignedInt, UnSignedInt, Float }; + enum Endian { BigEndian = QSysInfo::BigEndian, LittleEndian = QSysInfo::LittleEndian }; + + QAudioFormat(); + QAudioFormat(const QAudioFormat &other); + ~QAudioFormat(); + + QAudioFormat& operator=(const QAudioFormat &other); + bool operator==(const QAudioFormat &other) const; + bool operator!=(const QAudioFormat &other) const; + + bool isValid() const; + + void setFrequency(int frequency); + int frequency() const; + void setSampleRate(int sampleRate); + int sampleRate() const; + + void setChannels(int channels); + int channels() const; + void setChannelCount(int channelCount); + int channelCount() const; + + void setSampleSize(int sampleSize); + int sampleSize() const; + + void setCodec(const QString &codec); + QString codec() const; + + void setByteOrder(QAudioFormat::Endian byteOrder); + QAudioFormat::Endian byteOrder() const; + + void setSampleType(QAudioFormat::SampleType sampleType); + QAudioFormat::SampleType sampleType() const; + +private: + QSharedDataPointer d; +}; + + +QT_END_NAMESPACE + +QT_END_HEADER + +#endif // QAUDIOFORMAT_H diff --git a/src/multimedia/multimedia/audio/qaudioinput.cpp b/src/multimedia/multimedia/audio/qaudioinput.cpp new file mode 100644 index 0000000..c99e870 --- /dev/null +++ b/src/multimedia/multimedia/audio/qaudioinput.cpp @@ -0,0 +1,432 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtMultimedia module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + + +#include +#include +#include +#include + +#include "qaudiodevicefactory_p.h" + +QT_BEGIN_NAMESPACE + +/*! + \class QAudioInput + \brief The QAudioInput class provides an interface for receiving audio data from an audio input device. + + \inmodule QtMultimedia + \ingroup multimedia + \since 4.6 + + You can construct an audio input with the system's + \l{QAudioDeviceInfo::defaultInputDevice()}{default audio input + device}. It is also possible to create QAudioInput with a + specific QAudioDeviceInfo. When you create the audio input, you + should also send in the QAudioFormat to be used for the recording + (see the QAudioFormat class description for details). + + To record to a file: + + QAudioInput lets you record audio with an audio input device. The + default constructor of this class will use the systems default + audio device, but you can also specify a QAudioDeviceInfo for a + specific device. You also need to pass in the QAudioFormat in + which you wish to record. + + Starting up the QAudioInput is simply a matter of calling start() + with a QIODevice opened for writing. For instance, to record to a + file, you can: + + \code + QFile outputFile; // class member. + QAudioInput* audio; // class member. + \endcode + + \code + { + outputFile.setFileName("/tmp/test.raw"); + outputFile.open( QIODevice::WriteOnly | QIODevice::Truncate ); + + QAudioFormat format; + // set up the format you want, eg. + format.setFrequency(8000); + format.setChannels(1); + format.setSampleSize(8); + format.setCodec("audio/pcm"); + format.setByteOrder(QAudioFormat::LittleEndian); + format.setSampleType(QAudioFormat::UnSignedInt); + + QAudioDeviceInfo info = QAudioDeviceInfo::defaultInputDevice(); + if (!info.isFormatSupported(format)) { + qWarning()<<"default format not supported try to use nearest"; + format = info.nearestFormat(format); + } + + audio = new QAudioInput(format, this); + QTimer::singleShot(3000, this, SLOT(stopRecording())); + audio->start(&outputFile); + // Records audio for 3000ms + } + \endcode + + This will start recording if the format specified is supported by + the input device (you can check this with + QAudioDeviceInfo::isFormatSupported(). In case there are any + snags, use the error() function to check what went wrong. We stop + recording in the \c stopRecording() slot. + + \code + void stopRecording() + { + audio->stop(); + outputFile->close(); + delete audio; + } + \endcode + + At any point in time, QAudioInput will be in one of four states: + active, suspended, stopped, or idle. These states are specified by + the QAudio::State enum. You can request a state change directly through + suspend(), resume(), stop(), reset(), and start(). The current + state is reported by state(). QAudioOutput will also signal you + when the state changes (stateChanged()). + + QAudioInput provides several ways of measuring the time that has + passed since the start() of the recording. The \c processedUSecs() + function returns the length of the stream in microseconds written, + i.e., it leaves out the times the audio input was suspended or idle. + The elapsedUSecs() function returns the time elapsed since start() was called regardless of + which states the QAudioInput has been in. + + If an error should occur, you can fetch its reason with error(). + The possible error reasons are described by the QAudio::Error + enum. The QAudioInput will enter the \l{QAudio::}{StoppedState} when + an error is encountered. Connect to the stateChanged() signal to + handle the error: + + \snippet doc/src/snippets/audio/main.cpp 0 + + \sa QAudioOutput, QAudioDeviceInfo + + \section1 Symbian Platform Security Requirements + + On Symbian, processes which use this class must have the + \c UserEnvironment platform security capability. If the client + process lacks this capability, calls to either overload of start() + will fail. + This failure is indicated by the QAudioInput object setting + its error() value to \l{QAudio::OpenError} and then emitting a + \l{stateChanged()}{stateChanged}(\l{QAudio::StoppedState}) signal. + + Platform security capabilities are added via the + \l{qmake-variable-reference.html#target-capability}{TARGET.CAPABILITY} + qmake variable. +*/ + +/*! + Construct a new audio input and attach it to \a parent. + The default audio input device is used with the output + \a format parameters. +*/ + +QAudioInput::QAudioInput(const QAudioFormat &format, QObject *parent): + QObject(parent) +{ + d = QAudioDeviceFactory::createDefaultInputDevice(format); + connect(d, SIGNAL(notify()), SIGNAL(notify())); + connect(d, SIGNAL(stateChanged(QAudio::State)), SIGNAL(stateChanged(QAudio::State))); +} + +/*! + Construct a new audio input and attach it to \a parent. + The device referenced by \a audioDevice is used with the input + \a format parameters. +*/ + +QAudioInput::QAudioInput(const QAudioDeviceInfo &audioDevice, const QAudioFormat &format, QObject *parent): + QObject(parent) +{ + d = QAudioDeviceFactory::createInputDevice(audioDevice, format); + connect(d, SIGNAL(notify()), SIGNAL(notify())); + connect(d, SIGNAL(stateChanged(QAudio::State)), SIGNAL(stateChanged(QAudio::State))); +} + +/*! + Destroy this audio input. +*/ + +QAudioInput::~QAudioInput() +{ + delete d; +} + +/*! + Uses the \a device as the QIODevice to transfer data. + Passing a QIODevice allows the data to be transfered without any extra code. + All that is required is to open the QIODevice. + + If able to successfully get audio data from the systems audio device the + state() is set to either QAudio::ActiveState or QAudio::IdleState, + error() is set to QAudio::NoError and the stateChanged() signal is emitted. + + If a problem occurs during this process the error() is set to QAudio::OpenError, + state() is set to QAudio::StoppedState and stateChanged() signal is emitted. + + \sa {Symbian Platform Security Requirements} + + \sa QIODevice +*/ + +void QAudioInput::start(QIODevice* device) +{ + d->start(device); +} + +/*! + Returns a pointer to the QIODevice being used to handle the data + transfer. This QIODevice can be used to read() audio data + directly. + + If able to access the systems audio device the state() is set to + QAudio::IdleState, error() is set to QAudio::NoError + and the stateChanged() signal is emitted. + + If a problem occurs during this process the error() is set to QAudio::OpenError, + state() is set to QAudio::StoppedState and stateChanged() signal is emitted. + + \sa {Symbian Platform Security Requirements} + + \sa QIODevice +*/ + +QIODevice* QAudioInput::start() +{ + return d->start(0); +} + +/*! + Returns the QAudioFormat being used. +*/ + +QAudioFormat QAudioInput::format() const +{ + return d->format(); +} + +/*! + Stops the audio input, detaching from the system resource. + + Sets error() to QAudio::NoError, state() to QAudio::StoppedState and + emit stateChanged() signal. +*/ + +void QAudioInput::stop() +{ + d->stop(); +} + +/*! + Drops all audio data in the buffers, resets buffers to zero. +*/ + +void QAudioInput::reset() +{ + d->reset(); +} + +/*! + Stops processing audio data, preserving buffered audio data. + + Sets error() to QAudio::NoError, state() to QAudio::SuspendedState and + emit stateChanged() signal. +*/ + +void QAudioInput::suspend() +{ + d->suspend(); +} + +/*! + Resumes processing audio data after a suspend(). + + Sets error() to QAudio::NoError. + Sets state() to QAudio::ActiveState if you previously called start(QIODevice*). + Sets state() to QAudio::IdleState if you previously called start(). + emits stateChanged() signal. +*/ + +void QAudioInput::resume() +{ + d->resume(); +} + +/*! + Sets the audio buffer size to \a value milliseconds. + + Note: This function can be called anytime before start(), calls to this + are ignored after start(). It should not be assumed that the buffer size + set is the actual buffer size used, calling bufferSize() anytime after start() + will return the actual buffer size being used. + +*/ + +void QAudioInput::setBufferSize(int value) +{ + d->setBufferSize(value); +} + +/*! + Returns the audio buffer size in milliseconds. + + If called before start(), returns platform default value. + If called before start() but setBufferSize() was called prior, returns value set by setBufferSize(). + If called after start(), returns the actual buffer size being used. This may not be what was set previously + by setBufferSize(). + +*/ + +int QAudioInput::bufferSize() const +{ + return d->bufferSize(); +} + +/*! + Returns the amount of audio data available to read in bytes. + + NOTE: returned value is only valid while in QAudio::ActiveState or QAudio::IdleState + state, otherwise returns zero. +*/ + +int QAudioInput::bytesReady() const +{ + /* + -If not ActiveState|IdleState, return 0 + -return amount of audio data available to read + */ + return d->bytesReady(); +} + +/*! + Returns the period size in bytes. + + Note: This is the recommended read size in bytes. +*/ + +int QAudioInput::periodSize() const +{ + return d->periodSize(); +} + +/*! + Sets the interval for notify() signal to be emitted. + This is based on the \a ms of audio data processed + not on actual real-time. + The minimum resolution of the timer is platform specific and values + should be checked with notifyInterval() to confirm actual value + being used. +*/ + +void QAudioInput::setNotifyInterval(int ms) +{ + d->setNotifyInterval(ms); +} + +/*! + Returns the notify interval in milliseconds. +*/ + +int QAudioInput::notifyInterval() const +{ + return d->notifyInterval(); +} + +/*! + Returns the amount of audio data processed since start() + was called in microseconds. +*/ + +qint64 QAudioInput::processedUSecs() const +{ + return d->processedUSecs(); +} + +/*! + Returns the microseconds since start() was called, including time in Idle and + Suspend states. +*/ + +qint64 QAudioInput::elapsedUSecs() const +{ + return d->elapsedUSecs(); +} + +/*! + Returns the error state. +*/ + +QAudio::Error QAudioInput::error() const +{ + return d->error(); +} + +/*! + Returns the state of audio processing. +*/ + +QAudio::State QAudioInput::state() const +{ + return d->state(); +} + +/*! + \fn QAudioInput::stateChanged(QAudio::State state) + This signal is emitted when the device \a state has changed. +*/ + +/*! + \fn QAudioInput::notify() + This signal is emitted when x ms of audio data has been processed + the interval set by setNotifyInterval(x). +*/ + +QT_END_NAMESPACE + diff --git a/src/multimedia/multimedia/audio/qaudioinput.h b/src/multimedia/multimedia/audio/qaudioinput.h new file mode 100644 index 0000000..5be9b5a --- /dev/null +++ b/src/multimedia/multimedia/audio/qaudioinput.h @@ -0,0 +1,111 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtMultimedia module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + + +#ifndef QAUDIOINPUT_H +#define QAUDIOINPUT_H + +#include +#include + +#include +#include +#include + + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Multimedia) + + +class QAbstractAudioInput; + +class Q_MULTIMEDIA_EXPORT QAudioInput : public QObject +{ + Q_OBJECT + +public: + explicit QAudioInput(const QAudioFormat &format = QAudioFormat(), QObject *parent = 0); + explicit QAudioInput(const QAudioDeviceInfo &audioDeviceInfo, const QAudioFormat &format = QAudioFormat(), QObject *parent = 0); + ~QAudioInput(); + + QAudioFormat format() const; + + void start(QIODevice *device); + QIODevice* start(); + + void stop(); + void reset(); + void suspend(); + void resume(); + + void setBufferSize(int bytes); + int bufferSize() const; + + int bytesReady() const; + int periodSize() const; + + void setNotifyInterval(int milliSeconds); + int notifyInterval() const; + + qint64 processedUSecs() const; + qint64 elapsedUSecs() const; + + QAudio::Error error() const; + QAudio::State state() const; + +Q_SIGNALS: + void stateChanged(QAudio::State); + void notify(); + +private: + Q_DISABLE_COPY(QAudioInput) + + QAbstractAudioInput* d; +}; + +QT_END_NAMESPACE + +QT_END_HEADER + +#endif // QAUDIOINPUT_H diff --git a/src/multimedia/multimedia/audio/qaudioinput_alsa_p.cpp b/src/multimedia/multimedia/audio/qaudioinput_alsa_p.cpp new file mode 100644 index 0000000..6b15008 --- /dev/null +++ b/src/multimedia/multimedia/audio/qaudioinput_alsa_p.cpp @@ -0,0 +1,706 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtMultimedia module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists for the convenience +// of other Qt classes. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include +#include "qaudioinput_alsa_p.h" +#include "qaudiodeviceinfo_alsa_p.h" + +QT_BEGIN_NAMESPACE + +//#define DEBUG_AUDIO 1 + +static const int minimumIntervalTime = 50; + +QAudioInputPrivate::QAudioInputPrivate(const QByteArray &device, const QAudioFormat& audioFormat): + settings(audioFormat) +{ + bytesAvailable = 0; + handle = 0; + ahandler = 0; + access = SND_PCM_ACCESS_RW_INTERLEAVED; + pcmformat = SND_PCM_FORMAT_S16; + buffer_size = 0; + period_size = 0; + buffer_time = 100000; + period_time = 20000; + totalTimeValue = 0; + intervalTime = 1000; + audioBuffer = 0; + errorState = QAudio::NoError; + deviceState = QAudio::StoppedState; + audioSource = 0; + pullMode = true; + resuming = false; + + m_device = device; + + timer = new QTimer(this); + connect(timer,SIGNAL(timeout()),SLOT(userFeed())); +} + +QAudioInputPrivate::~QAudioInputPrivate() +{ + close(); + disconnect(timer, SIGNAL(timeout())); + QCoreApplication::processEvents(); + delete timer; +} + +QAudio::Error QAudioInputPrivate::error() const +{ + return errorState; +} + +QAudio::State QAudioInputPrivate::state() const +{ + return deviceState; +} + + +QAudioFormat QAudioInputPrivate::format() const +{ + return settings; +} + +int QAudioInputPrivate::xrun_recovery(int err) +{ + int count = 0; + bool reset = false; + + if(err == -EPIPE) { + errorState = QAudio::UnderrunError; + err = snd_pcm_prepare(handle); + if(err < 0) + reset = true; + else { + bytesAvailable = bytesReady(); + if (bytesAvailable <= 0) + reset = true; + } + + } else if((err == -ESTRPIPE)||(err == -EIO)) { + errorState = QAudio::IOError; + while((err = snd_pcm_resume(handle)) == -EAGAIN){ + usleep(100); + count++; + if(count > 5) { + reset = true; + break; + } + } + if(err < 0) { + err = snd_pcm_prepare(handle); + if(err < 0) + reset = true; + } + } + if(reset) { + close(); + open(); + snd_pcm_prepare(handle); + return 0; + } + return err; +} + +int QAudioInputPrivate::setFormat() +{ + snd_pcm_format_t format = SND_PCM_FORMAT_S16; + + if(settings.sampleSize() == 8) { + format = SND_PCM_FORMAT_U8; + } else if(settings.sampleSize() == 16) { + if(settings.sampleType() == QAudioFormat::SignedInt) { + if(settings.byteOrder() == QAudioFormat::LittleEndian) + format = SND_PCM_FORMAT_S16_LE; + else + format = SND_PCM_FORMAT_S16_BE; + } else if(settings.sampleType() == QAudioFormat::UnSignedInt) { + if(settings.byteOrder() == QAudioFormat::LittleEndian) + format = SND_PCM_FORMAT_U16_LE; + else + format = SND_PCM_FORMAT_U16_BE; + } + } else if(settings.sampleSize() == 24) { + if(settings.sampleType() == QAudioFormat::SignedInt) { + if(settings.byteOrder() == QAudioFormat::LittleEndian) + format = SND_PCM_FORMAT_S24_LE; + else + format = SND_PCM_FORMAT_S24_BE; + } else if(settings.sampleType() == QAudioFormat::UnSignedInt) { + if(settings.byteOrder() == QAudioFormat::LittleEndian) + format = SND_PCM_FORMAT_U24_LE; + else + format = SND_PCM_FORMAT_U24_BE; + } + } else if(settings.sampleSize() == 32) { + if(settings.sampleType() == QAudioFormat::SignedInt) { + if(settings.byteOrder() == QAudioFormat::LittleEndian) + format = SND_PCM_FORMAT_S32_LE; + else + format = SND_PCM_FORMAT_S32_BE; + } else if(settings.sampleType() == QAudioFormat::UnSignedInt) { + if(settings.byteOrder() == QAudioFormat::LittleEndian) + format = SND_PCM_FORMAT_U32_LE; + else + format = SND_PCM_FORMAT_U32_BE; + } else if(settings.sampleType() == QAudioFormat::Float) { + if(settings.byteOrder() == QAudioFormat::LittleEndian) + format = SND_PCM_FORMAT_FLOAT_LE; + else + format = SND_PCM_FORMAT_FLOAT_BE; + } + } else if(settings.sampleSize() == 64) { + if(settings.byteOrder() == QAudioFormat::LittleEndian) + format = SND_PCM_FORMAT_FLOAT64_LE; + else + format = SND_PCM_FORMAT_FLOAT64_BE; + } + + return snd_pcm_hw_params_set_format( handle, hwparams, format); +} + +QIODevice* QAudioInputPrivate::start(QIODevice* device) +{ + if(deviceState != QAudio::StoppedState) + close(); + + if(!pullMode && audioSource) { + delete audioSource; + } + + if(device) { + //set to pull mode + pullMode = true; + audioSource = device; + deviceState = QAudio::ActiveState; + } else { + //set to push mode + pullMode = false; + deviceState = QAudio::IdleState; + audioSource = new InputPrivate(this); + audioSource->open(QIODevice::ReadOnly | QIODevice::Unbuffered); + } + + if( !open() ) + return 0; + + emit stateChanged(deviceState); + + return audioSource; +} + +void QAudioInputPrivate::stop() +{ + if(deviceState == QAudio::StoppedState) + return; + + deviceState = QAudio::StoppedState; + + close(); + emit stateChanged(deviceState); +} + +bool QAudioInputPrivate::open() +{ +#ifdef DEBUG_AUDIO + QTime now(QTime::currentTime()); + qDebug()< devices = QAudioDeviceInfoInternal::availableDevices(QAudio::AudioInput); + if(dev.compare(QLatin1String("default")) == 0) { +#if(SND_LIB_MAJOR == 1 && SND_LIB_MINOR == 0 && SND_LIB_SUBMINOR >= 14) + dev = QLatin1String(devices.first()); +#else + dev = QLatin1String("hw:0,0"); +#endif + } else { +#if(SND_LIB_MAJOR == 1 && SND_LIB_MINOR == 0 && SND_LIB_SUBMINOR >= 14) + dev = QLatin1String(m_device); +#else + int idx = 0; + char *name; + + QString shortName = QLatin1String(m_device.mid(m_device.indexOf('=',0)+1).constData()); + + while(snd_card_get_name(idx,&name) == 0) { + if(qstrncmp(shortName.toLocal8Bit().constData(),name,shortName.length()) == 0) + break; + idx++; + } + dev = QString(QLatin1String("hw:%1,0")).arg(idx); +#endif + } + + // Step 1: try and open the device + while((count < 5) && (err < 0)) { + err=snd_pcm_open(&handle,dev.toLocal8Bit().constData(),SND_PCM_STREAM_CAPTURE,0); + if(err < 0) + count++; + } + if (( err < 0)||(handle == 0)) { + errorState = QAudio::OpenError; + deviceState = QAudio::StoppedState; + emit stateChanged(deviceState); + return false; + } + snd_pcm_nonblock( handle, 0 ); + + // Step 2: Set the desired HW parameters. + snd_pcm_hw_params_alloca( &hwparams ); + + bool fatal = false; + QString errMessage; + unsigned int chunks = 8; + + err = snd_pcm_hw_params_any( handle, hwparams ); + if ( err < 0 ) { + fatal = true; + errMessage = QString::fromLatin1("QAudioInput: snd_pcm_hw_params_any: err = %1").arg(err); + } + if ( !fatal ) { + err = snd_pcm_hw_params_set_rate_resample( handle, hwparams, 1 ); + if ( err < 0 ) { + fatal = true; + errMessage = QString::fromLatin1("QAudioInput: snd_pcm_hw_params_set_rate_resample: err = %1").arg(err); + } + } + if ( !fatal ) { + err = snd_pcm_hw_params_set_access( handle, hwparams, access ); + if ( err < 0 ) { + fatal = true; + errMessage = QString::fromLatin1("QAudioInput: snd_pcm_hw_params_set_access: err = %1").arg(err); + } + } + if ( !fatal ) { + err = setFormat(); + if ( err < 0 ) { + fatal = true; + errMessage = QString::fromLatin1("QAudioInput: snd_pcm_hw_params_set_format: err = %1").arg(err); + } + } + if ( !fatal ) { + err = snd_pcm_hw_params_set_channels( handle, hwparams, (unsigned int)settings.channels() ); + if ( err < 0 ) { + fatal = true; + errMessage = QString::fromLatin1("QAudioInput: snd_pcm_hw_params_set_channels: err = %1").arg(err); + } + } + if ( !fatal ) { + err = snd_pcm_hw_params_set_rate_near( handle, hwparams, &freakuency, 0 ); + if ( err < 0 ) { + fatal = true; + errMessage = QString::fromLatin1("QAudioInput: snd_pcm_hw_params_set_rate_near: err = %1").arg(err); + } + } + if ( !fatal ) { + err = snd_pcm_hw_params_set_buffer_time_near(handle, hwparams, &buffer_time, &dir); + if ( err < 0 ) { + fatal = true; + errMessage = QString::fromLatin1("QAudioInput: snd_pcm_hw_params_set_buffer_time_near: err = %1").arg(err); + } + } + if ( !fatal ) { + err = snd_pcm_hw_params_set_period_time_near(handle, hwparams, &period_time, &dir); + if ( err < 0 ) { + fatal = true; + errMessage = QString::fromLatin1("QAudioInput: snd_pcm_hw_params_set_period_time_near: err = %1").arg(err); + } + } + if ( !fatal ) { + err = snd_pcm_hw_params_set_periods_near(handle, hwparams, &chunks, &dir); + if ( err < 0 ) { + fatal = true; + errMessage = QString::fromLatin1("QAudioInput: snd_pcm_hw_params_set_periods_near: err = %1").arg(err); + } + } + if ( !fatal ) { + err = snd_pcm_hw_params(handle, hwparams); + if ( err < 0 ) { + fatal = true; + errMessage = QString::fromLatin1("QAudioInput: snd_pcm_hw_params: err = %1").arg(err); + } + } + if( err < 0) { + qWarning()<start(period_time*chunks/2000); + + errorState = QAudio::NoError; + + totalTimeValue = 0; + + return true; +} + +void QAudioInputPrivate::close() +{ + timer->stop(); + + if ( handle ) { + snd_pcm_drop( handle ); + snd_pcm_close( handle ); + handle = 0; + delete [] audioBuffer; + audioBuffer=0; + } +} + +int QAudioInputPrivate::bytesReady() const +{ + if(resuming) + return period_size; + + if(deviceState != QAudio::ActiveState && deviceState != QAudio::IdleState) + return 0; + int frames = snd_pcm_avail_update(handle); + if (frames < 0) return frames; + if((int)frames > (int)buffer_frames) + frames = buffer_frames; + + return snd_pcm_frames_to_bytes(handle, frames); +} + +qint64 QAudioInputPrivate::read(char* data, qint64 len) +{ + Q_UNUSED(len) + + // Read in some audio data and write it to QIODevice, pull mode + if ( !handle ) + return 0; + + bytesAvailable = bytesReady(); + + if (bytesAvailable < 0) { + // bytesAvailable as negative is error code, try to recover from it. + xrun_recovery(bytesAvailable); + bytesAvailable = bytesReady(); + if (bytesAvailable < 0) { + // recovery failed must stop and set error. + close(); + errorState = QAudio::IOError; + deviceState = QAudio::StoppedState; + emit stateChanged(deviceState); + return 0; + } + } + + int count=0, err = 0; + while(count < 5) { + int chunks = bytesAvailable/period_size; + int frames = chunks*period_frames; + if(frames > (int)buffer_frames) + frames = buffer_frames; + int readFrames = snd_pcm_readi(handle, audioBuffer, frames); + if (readFrames >= 0) { + err = snd_pcm_frames_to_bytes(handle, readFrames); +#ifdef DEBUG_AUDIO + qDebug()< 0) { + // got some send it onward +#ifdef DEBUG_AUDIO + qDebug()<<"frames to write to QIODevice = "<< + snd_pcm_bytes_to_frames( handle, (int)err )<<" ("<write(audioBuffer,err); + if(l < 0) { + close(); + errorState = QAudio::IOError; + deviceState = QAudio::StoppedState; + emit stateChanged(deviceState); + } else if(l == 0) { + if (deviceState != QAudio::IdleState) { + errorState = QAudio::NoError; + deviceState = QAudio::IdleState; + emit stateChanged(deviceState); + } + } else { + totalTimeValue += err; + resuming = false; + if (deviceState != QAudio::ActiveState) { + errorState = QAudio::NoError; + deviceState = QAudio::ActiveState; + emit stateChanged(deviceState); + } + } + return l; + + } else { + memcpy(data,audioBuffer,err); + totalTimeValue += err; + resuming = false; + if (deviceState != QAudio::ActiveState) { + errorState = QAudio::NoError; + deviceState = QAudio::ActiveState; + emit stateChanged(deviceState); + } + return err; + } + } + return 0; +} + +void QAudioInputPrivate::resume() +{ + if(deviceState == QAudio::SuspendedState) { + int err = 0; + + if(handle) { + err = snd_pcm_prepare( handle ); + if(err < 0) + xrun_recovery(err); + + err = snd_pcm_start(handle); + if(err < 0) + xrun_recovery(err); + + bytesAvailable = buffer_size; + } + resuming = true; + deviceState = QAudio::ActiveState; + int chunks = buffer_size/period_size; + timer->start(period_time*chunks/2000); + emit stateChanged(deviceState); + } +} + +void QAudioInputPrivate::setBufferSize(int value) +{ + buffer_size = value; +} + +int QAudioInputPrivate::bufferSize() const +{ + return buffer_size; +} + +int QAudioInputPrivate::periodSize() const +{ + return period_size; +} + +void QAudioInputPrivate::setNotifyInterval(int ms) +{ + if(ms >= minimumIntervalTime) + intervalTime = ms; + else + intervalTime = minimumIntervalTime; +} + +int QAudioInputPrivate::notifyInterval() const +{ + return intervalTime; +} + +qint64 QAudioInputPrivate::processedUSecs() const +{ + qint64 result = qint64(1000000) * totalTimeValue / + (settings.channels()*(settings.sampleSize()/8)) / + settings.frequency(); + + return result; +} + +void QAudioInputPrivate::suspend() +{ + if(deviceState == QAudio::ActiveState||resuming) { + timer->stop(); + deviceState = QAudio::SuspendedState; + emit stateChanged(deviceState); + } +} + +void QAudioInputPrivate::userFeed() +{ + if(deviceState == QAudio::StoppedState || deviceState == QAudio::SuspendedState) + return; +#ifdef DEBUG_AUDIO + QTime now(QTime::currentTime()); + qDebug()<(audioSource); + a->trigger(); + } + bytesAvailable = bytesReady(); + + if(deviceState != QAudio::ActiveState) + return true; + + if((timeStamp.elapsed() + elapsedTimeOffset) > intervalTime) { + emit notify(); + elapsedTimeOffset = timeStamp.elapsed() + elapsedTimeOffset - intervalTime; + timeStamp.restart(); + } + return true; +} + +qint64 QAudioInputPrivate::elapsedUSecs() const +{ + if (deviceState == QAudio::StoppedState) + return 0; + + return clockStamp.elapsed()*1000; +} + +void QAudioInputPrivate::reset() +{ + if(handle) + snd_pcm_reset(handle); +} + +void QAudioInputPrivate::drain() +{ + if(handle) + snd_pcm_drain(handle); +} + +InputPrivate::InputPrivate(QAudioInputPrivate* audio) +{ + audioDevice = qobject_cast(audio); +} + +InputPrivate::~InputPrivate() +{ +} + +qint64 InputPrivate::readData( char* data, qint64 len) +{ + return audioDevice->read(data,len); +} + +qint64 InputPrivate::writeData(const char* data, qint64 len) +{ + Q_UNUSED(data) + Q_UNUSED(len) + return 0; +} + +void InputPrivate::trigger() +{ + emit readyRead(); +} + +QT_END_NAMESPACE diff --git a/src/multimedia/multimedia/audio/qaudioinput_alsa_p.h b/src/multimedia/multimedia/audio/qaudioinput_alsa_p.h new file mode 100644 index 0000000..c907019 --- /dev/null +++ b/src/multimedia/multimedia/audio/qaudioinput_alsa_p.h @@ -0,0 +1,158 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtMultimedia module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists for the convenience +// of other Qt classes. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + + +#ifndef QAUDIOINPUTALSA_H +#define QAUDIOINPUTALSA_H + +#include + +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +QT_BEGIN_NAMESPACE + +class InputPrivate; + +class QAudioInputPrivate : public QAbstractAudioInput +{ + Q_OBJECT +public: + QAudioInputPrivate(const QByteArray &device, const QAudioFormat& audioFormat); + ~QAudioInputPrivate(); + + qint64 read(char* data, qint64 len); + + QIODevice* start(QIODevice* device = 0); + void stop(); + void reset(); + void suspend(); + void resume(); + int bytesReady() const; + int periodSize() const; + void setBufferSize(int value); + int bufferSize() const; + void setNotifyInterval(int milliSeconds); + int notifyInterval() const; + qint64 processedUSecs() const; + qint64 elapsedUSecs() const; + QAudio::Error error() const; + QAudio::State state() const; + QAudioFormat format() const; + bool resuming; + snd_pcm_t* handle; + qint64 totalTimeValue; + QIODevice* audioSource; + QAudioFormat settings; + QAudio::Error errorState; + QAudio::State deviceState; + +private slots: + void userFeed(); + bool deviceReady(); + +private: + int xrun_recovery(int err); + int setFormat(); + bool open(); + void close(); + void drain(); + + QTimer* timer; + QElapsedTimer timeStamp; + QElapsedTimer clockStamp; + qint64 elapsedTimeOffset; + int intervalTime; + char* audioBuffer; + int bytesAvailable; + QByteArray m_device; + bool pullMode; + int buffer_size; + int period_size; + unsigned int buffer_time; + unsigned int period_time; + snd_pcm_uframes_t buffer_frames; + snd_pcm_uframes_t period_frames; + snd_async_handler_t* ahandler; + snd_pcm_access_t access; + snd_pcm_format_t pcmformat; + snd_timestamp_t* timestamp; + snd_pcm_hw_params_t *hwparams; +}; + +class InputPrivate : public QIODevice +{ + Q_OBJECT +public: + InputPrivate(QAudioInputPrivate* audio); + ~InputPrivate(); + + qint64 readData( char* data, qint64 len); + qint64 writeData(const char* data, qint64 len); + + void trigger(); +private: + QAudioInputPrivate *audioDevice; +}; + +QT_END_NAMESPACE + +#endif diff --git a/src/multimedia/multimedia/audio/qaudioinput_mac_p.cpp b/src/multimedia/multimedia/audio/qaudioinput_mac_p.cpp new file mode 100644 index 0000000..cb65f6e --- /dev/null +++ b/src/multimedia/multimedia/audio/qaudioinput_mac_p.cpp @@ -0,0 +1,956 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtMultimedia module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists for the convenience +// of other Qt classes. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include +#include +#include + +#include + +#include "qaudio_mac_p.h" +#include "qaudioinput_mac_p.h" +#include "qaudiodeviceinfo_mac_p.h" + +QT_BEGIN_NAMESPACE + + +namespace QtMultimediaInternal +{ + +static const int default_buffer_size = 4 * 1024; + +class QAudioBufferList +{ +public: + QAudioBufferList(AudioStreamBasicDescription const& streamFormat): + owner(false), + sf(streamFormat) + { + const bool isInterleaved = (sf.mFormatFlags & kAudioFormatFlagIsNonInterleaved) == 0; + const int numberOfBuffers = isInterleaved ? 1 : sf.mChannelsPerFrame; + + dataSize = 0; + + bfs = reinterpret_cast(qMalloc(sizeof(AudioBufferList) + + (sizeof(AudioBuffer) * numberOfBuffers))); + + bfs->mNumberBuffers = numberOfBuffers; + for (int i = 0; i < numberOfBuffers; ++i) { + bfs->mBuffers[i].mNumberChannels = isInterleaved ? numberOfBuffers : 1; + bfs->mBuffers[i].mDataByteSize = 0; + bfs->mBuffers[i].mData = 0; + } + } + + QAudioBufferList(AudioStreamBasicDescription const& streamFormat, char* buffer, int bufferSize): + owner(false), + sf(streamFormat), + bfs(0) + { + dataSize = bufferSize; + + bfs = reinterpret_cast(qMalloc(sizeof(AudioBufferList) + sizeof(AudioBuffer))); + + bfs->mNumberBuffers = 1; + bfs->mBuffers[0].mNumberChannels = 1; + bfs->mBuffers[0].mDataByteSize = dataSize; + bfs->mBuffers[0].mData = buffer; + } + + QAudioBufferList(AudioStreamBasicDescription const& streamFormat, int framesToBuffer): + owner(true), + sf(streamFormat), + bfs(0) + { + const bool isInterleaved = (sf.mFormatFlags & kAudioFormatFlagIsNonInterleaved) == 0; + const int numberOfBuffers = isInterleaved ? 1 : sf.mChannelsPerFrame; + + dataSize = framesToBuffer * sf.mBytesPerFrame; + + bfs = reinterpret_cast(qMalloc(sizeof(AudioBufferList) + + (sizeof(AudioBuffer) * numberOfBuffers))); + bfs->mNumberBuffers = numberOfBuffers; + for (int i = 0; i < numberOfBuffers; ++i) { + bfs->mBuffers[i].mNumberChannels = isInterleaved ? numberOfBuffers : 1; + bfs->mBuffers[i].mDataByteSize = dataSize; + bfs->mBuffers[i].mData = qMalloc(dataSize); + } + } + + ~QAudioBufferList() + { + if (owner) { + for (UInt32 i = 0; i < bfs->mNumberBuffers; ++i) + qFree(bfs->mBuffers[i].mData); + } + + qFree(bfs); + } + + AudioBufferList* audioBufferList() const + { + return bfs; + } + + char* data(int buffer = 0) const + { + return static_cast(bfs->mBuffers[buffer].mData); + } + + qint64 bufferSize(int buffer = 0) const + { + return bfs->mBuffers[buffer].mDataByteSize; + } + + int frameCount(int buffer = 0) const + { + return bfs->mBuffers[buffer].mDataByteSize / sf.mBytesPerFrame; + } + + int packetCount(int buffer = 0) const + { + return bfs->mBuffers[buffer].mDataByteSize / sf.mBytesPerPacket; + } + + int packetSize() const + { + return sf.mBytesPerPacket; + } + + void reset() + { + for (UInt32 i = 0; i < bfs->mNumberBuffers; ++i) { + bfs->mBuffers[i].mDataByteSize = dataSize; + bfs->mBuffers[i].mData = 0; + } + } + +private: + bool owner; + int dataSize; + AudioStreamBasicDescription sf; + AudioBufferList* bfs; +}; + +class QAudioPacketFeeder +{ +public: + QAudioPacketFeeder(QAudioBufferList* abl): + audioBufferList(abl) + { + totalPackets = audioBufferList->packetCount(); + position = 0; + } + + bool feed(AudioBufferList& dst, UInt32& packetCount) + { + if (position == totalPackets) { + dst.mBuffers[0].mDataByteSize = 0; + packetCount = 0; + return false; + } + + if (totalPackets - position < packetCount) + packetCount = totalPackets - position; + + dst.mBuffers[0].mDataByteSize = packetCount * audioBufferList->packetSize(); + dst.mBuffers[0].mData = audioBufferList->data() + (position * audioBufferList->packetSize()); + + position += packetCount; + + return true; + } + +private: + UInt32 totalPackets; + UInt32 position; + QAudioBufferList* audioBufferList; +}; + +class QAudioInputBuffer : public QObject +{ + Q_OBJECT + +public: + QAudioInputBuffer(int bufferSize, + int maxPeriodSize, + AudioStreamBasicDescription const& inputFormat, + AudioStreamBasicDescription const& outputFormat, + QObject* parent): + QObject(parent), + m_deviceError(false), + m_audioConverter(0), + m_inputFormat(inputFormat), + m_outputFormat(outputFormat) + { + m_maxPeriodSize = maxPeriodSize; + m_periodTime = m_maxPeriodSize / m_outputFormat.mBytesPerFrame * 1000 / m_outputFormat.mSampleRate; + m_buffer = new QAudioRingBuffer(bufferSize + (bufferSize % maxPeriodSize == 0 ? 0 : maxPeriodSize - (bufferSize % maxPeriodSize))); + m_inputBufferList = new QAudioBufferList(m_inputFormat); + + m_flushTimer = new QTimer(this); + connect(m_flushTimer, SIGNAL(timeout()), SLOT(flushBuffer())); + + if (toQAudioFormat(inputFormat) != toQAudioFormat(outputFormat)) { + if (AudioConverterNew(&m_inputFormat, &m_outputFormat, &m_audioConverter) != noErr) { + qWarning() << "QAudioInput: Unable to create an Audio Converter"; + m_audioConverter = 0; + } + } + } + + ~QAudioInputBuffer() + { + delete m_buffer; + } + + qint64 renderFromDevice(AudioUnit audioUnit, + AudioUnitRenderActionFlags* ioActionFlags, + const AudioTimeStamp* inTimeStamp, + UInt32 inBusNumber, + UInt32 inNumberFrames) + { + const bool wasEmpty = m_buffer->used() == 0; + + OSStatus err; + qint64 framesRendered = 0; + + m_inputBufferList->reset(); + err = AudioUnitRender(audioUnit, + ioActionFlags, + inTimeStamp, + inBusNumber, + inNumberFrames, + m_inputBufferList->audioBufferList()); + + if (m_audioConverter != 0) { + QAudioPacketFeeder feeder(m_inputBufferList); + + bool wecan = true; + int copied = 0; + + const int available = m_buffer->free(); + + while (err == noErr && wecan) { + QAudioRingBuffer::Region region = m_buffer->acquireWriteRegion(available); + + if (region.second > 0) { + AudioBufferList output; + output.mNumberBuffers = 1; + output.mBuffers[0].mNumberChannels = 1; + output.mBuffers[0].mDataByteSize = region.second; + output.mBuffers[0].mData = region.first; + + UInt32 packetSize = region.second / m_outputFormat.mBytesPerPacket; + err = AudioConverterFillComplexBuffer(m_audioConverter, + converterCallback, + &feeder, + &packetSize, + &output, + 0); + + region.second = output.mBuffers[0].mDataByteSize; + copied += region.second; + + m_buffer->releaseWriteRegion(region); + } + else + wecan = false; + } + + framesRendered += copied / m_outputFormat.mBytesPerFrame; + } + else { + const int available = m_inputBufferList->bufferSize(); + bool wecan = true; + int copied = 0; + + while (wecan && copied < available) { + QAudioRingBuffer::Region region = m_buffer->acquireWriteRegion(available - copied); + + if (region.second > 0) { + memcpy(region.first, m_inputBufferList->data() + copied, region.second); + copied += region.second; + } + else + wecan = false; + + m_buffer->releaseWriteRegion(region); + } + + framesRendered = copied / m_outputFormat.mBytesPerFrame; + } + + if (wasEmpty && framesRendered > 0) + emit readyRead(); + + return framesRendered; + } + + qint64 readBytes(char* data, qint64 len) + { + bool wecan = true; + qint64 bytesCopied = 0; + + len -= len % m_maxPeriodSize; + while (wecan && bytesCopied < len) { + QAudioRingBuffer::Region region = m_buffer->acquireReadRegion(len - bytesCopied); + + if (region.second > 0) { + memcpy(data + bytesCopied, region.first, region.second); + bytesCopied += region.second; + } + else + wecan = false; + + m_buffer->releaseReadRegion(region); + } + + return bytesCopied; + } + + void setFlushDevice(QIODevice* device) + { + if (m_device != device) + m_device = device; + } + + void startFlushTimer() + { + if (m_device != 0) { + m_flushTimer->start((m_buffer->size() - (m_maxPeriodSize * 2)) / m_maxPeriodSize * m_periodTime); + } + } + + void stopFlushTimer() + { + m_flushTimer->stop(); + } + + void flush(bool all = false) + { + if (m_device == 0) + return; + + const int used = m_buffer->used(); + const int readSize = all ? used : used - (used % m_maxPeriodSize); + + if (readSize > 0) { + bool wecan = true; + int flushed = 0; + + while (!m_deviceError && wecan && flushed < readSize) { + QAudioRingBuffer::Region region = m_buffer->acquireReadRegion(readSize - flushed); + + if (region.second > 0) { + int bytesWritten = m_device->write(region.first, region.second); + if (bytesWritten < 0) { + stopFlushTimer(); + m_deviceError = true; + } + else { + region.second = bytesWritten; + flushed += bytesWritten; + wecan = bytesWritten != 0; + } + } + else + wecan = false; + + m_buffer->releaseReadRegion(region); + } + } + } + + void reset() + { + m_buffer->reset(); + m_deviceError = false; + } + + int available() const + { + return m_buffer->free(); + } + + int used() const + { + return m_buffer->used(); + } + +signals: + void readyRead(); + +private slots: + void flushBuffer() + { + flush(); + } + +private: + bool m_deviceError; + int m_maxPeriodSize; + int m_periodTime; + QIODevice* m_device; + QTimer* m_flushTimer; + QAudioRingBuffer* m_buffer; + QAudioBufferList* m_inputBufferList; + AudioConverterRef m_audioConverter; + AudioStreamBasicDescription m_inputFormat; + AudioStreamBasicDescription m_outputFormat; + + const static OSStatus as_empty = 'qtem'; + + // Converter callback + static OSStatus converterCallback(AudioConverterRef inAudioConverter, + UInt32* ioNumberDataPackets, + AudioBufferList* ioData, + AudioStreamPacketDescription** outDataPacketDescription, + void* inUserData) + { + Q_UNUSED(inAudioConverter); + Q_UNUSED(outDataPacketDescription); + + QAudioPacketFeeder* feeder = static_cast(inUserData); + + if (!feeder->feed(*ioData, *ioNumberDataPackets)) + return as_empty; + + return noErr; + } +}; + + +class MacInputDevice : public QIODevice +{ + Q_OBJECT + +public: + MacInputDevice(QAudioInputBuffer* audioBuffer, QObject* parent): + QIODevice(parent), + m_audioBuffer(audioBuffer) + { + open(QIODevice::ReadOnly | QIODevice::Unbuffered); + connect(m_audioBuffer, SIGNAL(readyRead()), SIGNAL(readyRead())); + } + + qint64 readData(char* data, qint64 len) + { + return m_audioBuffer->readBytes(data, len); + } + + qint64 writeData(const char* data, qint64 len) + { + Q_UNUSED(data); + Q_UNUSED(len); + + return 0; + } + + bool isSequential() const + { + return true; + } + +private: + QAudioInputBuffer* m_audioBuffer; +}; + +} + + +QAudioInputPrivate::QAudioInputPrivate(const QByteArray& device, QAudioFormat const& format): + audioFormat(format) +{ + QDataStream ds(device); + quint32 did, mode; + + ds >> did >> mode; + + if (QAudio::Mode(mode) == QAudio::AudioOutput) + errorCode = QAudio::OpenError; + else { + audioDeviceInfo = new QAudioDeviceInfoInternal(device, QAudio::AudioInput); + isOpen = false; + audioDeviceId = AudioDeviceID(did); + audioUnit = 0; + startTime = 0; + totalFrames = 0; + audioBuffer = 0; + internalBufferSize = QtMultimediaInternal::default_buffer_size; + clockFrequency = AudioGetHostClockFrequency() / 1000; + errorCode = QAudio::NoError; + stateCode = QAudio::StoppedState; + + intervalTimer = new QTimer(this); + intervalTimer->setInterval(1000); + connect(intervalTimer, SIGNAL(timeout()), SIGNAL(notify())); + } +} + +QAudioInputPrivate::~QAudioInputPrivate() +{ + close(); + delete audioDeviceInfo; +} + +bool QAudioInputPrivate::open() +{ + UInt32 size = 0; + + if (isOpen) + return true; + + ComponentDescription cd; + cd.componentType = kAudioUnitType_Output; + cd.componentSubType = kAudioUnitSubType_HALOutput; + cd.componentManufacturer = kAudioUnitManufacturer_Apple; + cd.componentFlags = 0; + cd.componentFlagsMask = 0; + + // Open + Component cp = FindNextComponent(NULL, &cd); + if (cp == 0) { + qWarning() << "QAudioInput: Failed to find HAL Output component"; + return false; + } + + if (OpenAComponent(cp, &audioUnit) != noErr) { + qWarning() << "QAudioInput: Unable to Open Output Component"; + return false; + } + + // Set mode + // switch to input mode + UInt32 enable = 1; + if (AudioUnitSetProperty(audioUnit, + kAudioOutputUnitProperty_EnableIO, + kAudioUnitScope_Input, + 1, + &enable, + sizeof(enable)) != noErr) { + qWarning() << "QAudioInput: Unable to switch to input mode (Enable Input)"; + return false; + } + + enable = 0; + if (AudioUnitSetProperty(audioUnit, + kAudioOutputUnitProperty_EnableIO, + kAudioUnitScope_Output, + 0, + &enable, + sizeof(enable)) != noErr) { + qWarning() << "QAudioInput: Unable to switch to input mode (Disable output)"; + return false; + } + + // register callback + AURenderCallbackStruct cb; + cb.inputProc = inputCallback; + cb.inputProcRefCon = this; + + if (AudioUnitSetProperty(audioUnit, + kAudioOutputUnitProperty_SetInputCallback, + kAudioUnitScope_Global, + 0, + &cb, + sizeof(cb)) != noErr) { + qWarning() << "QAudioInput: Failed to set AudioUnit callback"; + return false; + } + + // Set Audio Device + if (AudioUnitSetProperty(audioUnit, + kAudioOutputUnitProperty_CurrentDevice, + kAudioUnitScope_Global, + 0, + &audioDeviceId, + sizeof(audioDeviceId)) != noErr) { + qWarning() << "QAudioInput: Unable to use configured device"; + return false; + } + + // Set format + // Wanted + streamFormat = toAudioStreamBasicDescription(audioFormat); + + // Required on unit + if (audioFormat == audioDeviceInfo->preferredFormat()) { + deviceFormat = streamFormat; + AudioUnitSetProperty(audioUnit, + kAudioUnitProperty_StreamFormat, + kAudioUnitScope_Output, + 1, + &deviceFormat, + sizeof(deviceFormat)); + } + else { + size = sizeof(deviceFormat); + if (AudioUnitGetProperty(audioUnit, + kAudioUnitProperty_StreamFormat, + kAudioUnitScope_Input, + 1, + &deviceFormat, + &size) != noErr) { + qWarning() << "QAudioInput: Unable to retrieve device format"; + return false; + } + + if (AudioUnitSetProperty(audioUnit, + kAudioUnitProperty_StreamFormat, + kAudioUnitScope_Output, + 1, + &deviceFormat, + sizeof(deviceFormat)) != noErr) { + qWarning() << "QAudioInput: Unable to set device format"; + return false; + } + } + + // Setup buffers + UInt32 numberOfFrames; + size = sizeof(UInt32); + if (AudioUnitGetProperty(audioUnit, + kAudioDevicePropertyBufferFrameSize, + kAudioUnitScope_Global, + 0, + &numberOfFrames, + &size) != noErr) { + qWarning() << "QAudioInput: Failed to get audio period size"; + return false; + } + + // Allocate buffer + periodSizeBytes = numberOfFrames * streamFormat.mBytesPerFrame; + + if (internalBufferSize < periodSizeBytes * 2) + internalBufferSize = periodSizeBytes * 2; + else + internalBufferSize -= internalBufferSize % streamFormat.mBytesPerFrame; + + audioBuffer = new QtMultimediaInternal::QAudioInputBuffer(internalBufferSize, + periodSizeBytes, + deviceFormat, + streamFormat, + this); + + audioIO = new QtMultimediaInternal::MacInputDevice(audioBuffer, this); + + // Init + if (AudioUnitInitialize(audioUnit) != noErr) { + qWarning() << "QAudioInput: Failed to initialize AudioUnit"; + return false; + } + + isOpen = true; + + return isOpen; +} + +void QAudioInputPrivate::close() +{ + if (audioUnit != 0) { + AudioOutputUnitStop(audioUnit); + AudioUnitUninitialize(audioUnit); + CloseComponent(audioUnit); + } + + delete audioBuffer; +} + +QAudioFormat QAudioInputPrivate::format() const +{ + return audioFormat; +} + +QIODevice* QAudioInputPrivate::start(QIODevice* device) +{ + QIODevice* op = device; + + if (!audioFormat.isValid() || !open()) { + stateCode = QAudio::StoppedState; + errorCode = QAudio::OpenError; + return audioIO; + } + + reset(); + audioBuffer->reset(); + audioBuffer->setFlushDevice(op); + + if (op == 0) + op = audioIO; + + // Start + startTime = AudioGetCurrentHostTime(); + totalFrames = 0; + + audioThreadStart(); + + stateCode = QAudio::ActiveState; + errorCode = QAudio::NoError; + emit stateChanged(stateCode); + + return op; +} + +void QAudioInputPrivate::stop() +{ + QMutexLocker lock(&mutex); + if (stateCode != QAudio::StoppedState) { + audioThreadStop(); + audioBuffer->flush(true); + + errorCode = QAudio::NoError; + stateCode = QAudio::StoppedState; + QMetaObject::invokeMethod(this, "stateChanged", Qt::QueuedConnection, Q_ARG(QAudio::State, stateCode)); + } +} + +void QAudioInputPrivate::reset() +{ + QMutexLocker lock(&mutex); + if (stateCode != QAudio::StoppedState) { + audioThreadStop(); + + errorCode = QAudio::NoError; + stateCode = QAudio::StoppedState; + QMetaObject::invokeMethod(this, "stateChanged", Qt::QueuedConnection, Q_ARG(QAudio::State, stateCode)); + } +} + +void QAudioInputPrivate::suspend() +{ + QMutexLocker lock(&mutex); + if (stateCode == QAudio::ActiveState || stateCode == QAudio::IdleState) { + audioThreadStop(); + + errorCode = QAudio::NoError; + stateCode = QAudio::SuspendedState; + QMetaObject::invokeMethod(this, "stateChanged", Qt::QueuedConnection, Q_ARG(QAudio::State, stateCode)); + } +} + +void QAudioInputPrivate::resume() +{ + QMutexLocker lock(&mutex); + if (stateCode == QAudio::SuspendedState) { + audioThreadStart(); + + errorCode = QAudio::NoError; + stateCode = QAudio::ActiveState; + QMetaObject::invokeMethod(this, "stateChanged", Qt::QueuedConnection, Q_ARG(QAudio::State, stateCode)); + } +} + +int QAudioInputPrivate::bytesReady() const +{ + return audioBuffer->used(); +} + +int QAudioInputPrivate::periodSize() const +{ + return periodSizeBytes; +} + +void QAudioInputPrivate::setBufferSize(int bs) +{ + internalBufferSize = bs; +} + +int QAudioInputPrivate::bufferSize() const +{ + return internalBufferSize; +} + +void QAudioInputPrivate::setNotifyInterval(int milliSeconds) +{ + if (intervalTimer->interval() == milliSeconds) + return; + + if (milliSeconds <= 0) + milliSeconds = 0; + + intervalTimer->setInterval(milliSeconds); +} + +int QAudioInputPrivate::notifyInterval() const +{ + return intervalTimer->interval(); +} + +qint64 QAudioInputPrivate::processedUSecs() const +{ + return totalFrames * 1000000 / audioFormat.frequency(); +} + +qint64 QAudioInputPrivate::elapsedUSecs() const +{ + if (stateCode == QAudio::StoppedState) + return 0; + + return (AudioGetCurrentHostTime() - startTime) / (clockFrequency / 1000); +} + +QAudio::Error QAudioInputPrivate::error() const +{ + return errorCode; +} + +QAudio::State QAudioInputPrivate::state() const +{ + return stateCode; +} + +void QAudioInputPrivate::audioThreadStop() +{ + stopTimers(); + if (audioThreadState.testAndSetAcquire(Running, Stopped)) + threadFinished.wait(&mutex); +} + +void QAudioInputPrivate::audioThreadStart() +{ + startTimers(); + audioThreadState = Running; + AudioOutputUnitStart(audioUnit); +} + +void QAudioInputPrivate::audioDeviceStop() +{ + AudioOutputUnitStop(audioUnit); + audioThreadState = Stopped; + threadFinished.wakeOne(); +} + +void QAudioInputPrivate::audioDeviceFull() +{ + QMutexLocker lock(&mutex); + if (stateCode == QAudio::ActiveState) { + audioDeviceStop(); + + errorCode = QAudio::UnderrunError; + stateCode = QAudio::IdleState; + QMetaObject::invokeMethod(this, "deviceStopped", Qt::QueuedConnection); + } +} + +void QAudioInputPrivate::audioDeviceError() +{ + QMutexLocker lock(&mutex); + if (stateCode == QAudio::ActiveState) { + audioDeviceStop(); + + errorCode = QAudio::IOError; + stateCode = QAudio::StoppedState; + QMetaObject::invokeMethod(this, "deviceStopped", Qt::QueuedConnection); + } +} + +void QAudioInputPrivate::startTimers() +{ + audioBuffer->startFlushTimer(); + if (intervalTimer->interval() > 0) + intervalTimer->start(); +} + +void QAudioInputPrivate::stopTimers() +{ + audioBuffer->stopFlushTimer(); + intervalTimer->stop(); +} + +void QAudioInputPrivate::deviceStopped() +{ + stopTimers(); + emit stateChanged(stateCode); +} + +// Input callback +OSStatus QAudioInputPrivate::inputCallback(void* inRefCon, + AudioUnitRenderActionFlags* ioActionFlags, + const AudioTimeStamp* inTimeStamp, + UInt32 inBusNumber, + UInt32 inNumberFrames, + AudioBufferList* ioData) +{ + Q_UNUSED(ioData); + + QAudioInputPrivate* d = static_cast(inRefCon); + + const int threadState = d->audioThreadState.fetchAndAddAcquire(0); + if (threadState == Stopped) + d->audioDeviceStop(); + else { + qint64 framesWritten; + + framesWritten = d->audioBuffer->renderFromDevice(d->audioUnit, + ioActionFlags, + inTimeStamp, + inBusNumber, + inNumberFrames); + + if (framesWritten > 0) + d->totalFrames += framesWritten; + else if (framesWritten == 0) + d->audioDeviceFull(); + else if (framesWritten < 0) + d->audioDeviceError(); + } + + return noErr; +} + + +QT_END_NAMESPACE + +#include "qaudioinput_mac_p.moc" + diff --git a/src/multimedia/multimedia/audio/qaudioinput_mac_p.h b/src/multimedia/multimedia/audio/qaudioinput_mac_p.h new file mode 100644 index 0000000..7aa4168 --- /dev/null +++ b/src/multimedia/multimedia/audio/qaudioinput_mac_p.h @@ -0,0 +1,169 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtMultimedia module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists for the convenience +// of other Qt classes. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + + +#ifndef QAUDIOINPUT_MAC_P_H +#define QAUDIOINPUT_MAC_P_H + +#include +#include +#include +#include + +#include +#include +#include +#include + +#include +#include +#include + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +class QTimer; +class QIODevice; +class QAbstractAudioDeviceInfo; + +namespace QtMultimediaInternal +{ +class QAudioInputBuffer; +} + +class QAudioInputPrivate : public QAbstractAudioInput +{ + Q_OBJECT + +public: + bool isOpen; + int periodSizeBytes; + int internalBufferSize; + qint64 totalFrames; + QAudioFormat audioFormat; + QIODevice* audioIO; + AudioUnit audioUnit; + AudioDeviceID audioDeviceId; + Float64 clockFrequency; + UInt64 startTime; + QAudio::Error errorCode; + QAudio::State stateCode; + QtMultimediaInternal::QAudioInputBuffer* audioBuffer; + QMutex mutex; + QWaitCondition threadFinished; + QAtomicInt audioThreadState; + QTimer* intervalTimer; + AudioStreamBasicDescription streamFormat; + AudioStreamBasicDescription deviceFormat; + QAbstractAudioDeviceInfo *audioDeviceInfo; + + QAudioInputPrivate(const QByteArray& device, QAudioFormat const& format); + ~QAudioInputPrivate(); + + bool open(); + void close(); + + QAudioFormat format() const; + + QIODevice* start(QIODevice* device); + void stop(); + void reset(); + void suspend(); + void resume(); + void idle(); + + int bytesReady() const; + int periodSize() const; + + void setBufferSize(int value); + int bufferSize() const; + + void setNotifyInterval(int milliSeconds); + int notifyInterval() const; + + qint64 processedUSecs() const; + qint64 elapsedUSecs() const; + + QAudio::Error error() const; + QAudio::State state() const; + + void audioThreadStart(); + void audioThreadStop(); + + void audioDeviceStop(); + void audioDeviceFull(); + void audioDeviceError(); + + void startTimers(); + void stopTimers(); + +private slots: + void deviceStopped(); + +private: + enum { Running, Stopped }; + + // Input callback + static OSStatus inputCallback(void* inRefCon, + AudioUnitRenderActionFlags* ioActionFlags, + const AudioTimeStamp* inTimeStamp, + UInt32 inBusNumber, + UInt32 inNumberFrames, + AudioBufferList* ioData); +}; + +QT_END_NAMESPACE + +QT_END_HEADER + +#endif // QAUDIOINPUT_MAC_P_H diff --git a/src/multimedia/multimedia/audio/qaudioinput_symbian_p.cpp b/src/multimedia/multimedia/audio/qaudioinput_symbian_p.cpp new file mode 100644 index 0000000..52daa88 --- /dev/null +++ b/src/multimedia/multimedia/audio/qaudioinput_symbian_p.cpp @@ -0,0 +1,594 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtMultimedia module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qaudioinput_symbian_p.h" + +QT_BEGIN_NAMESPACE + +//----------------------------------------------------------------------------- +// Constants +//----------------------------------------------------------------------------- + +const int PushInterval = 50; // ms + + +//----------------------------------------------------------------------------- +// Private class +//----------------------------------------------------------------------------- + +SymbianAudioInputPrivate::SymbianAudioInputPrivate( + QAudioInputPrivate *audioDevice) + : m_audioDevice(audioDevice) +{ + +} + +SymbianAudioInputPrivate::~SymbianAudioInputPrivate() +{ + +} + +qint64 SymbianAudioInputPrivate::readData(char *data, qint64 len) +{ + qint64 totalRead = 0; + + if (m_audioDevice->state() == QAudio::ActiveState || + m_audioDevice->state() == QAudio::IdleState) { + + while (totalRead < len) { + const qint64 read = m_audioDevice->read(data + totalRead, + len - totalRead); + if (read > 0) + totalRead += read; + else + break; + } + } + + return totalRead; +} + +qint64 SymbianAudioInputPrivate::writeData(const char *data, qint64 len) +{ + Q_UNUSED(data) + Q_UNUSED(len) + return 0; +} + +void SymbianAudioInputPrivate::dataReady() +{ + emit readyRead(); +} + + +//----------------------------------------------------------------------------- +// Public functions +//----------------------------------------------------------------------------- + +QAudioInputPrivate::QAudioInputPrivate(const QByteArray &device, + const QAudioFormat &format) + : m_device(device) + , m_format(format) + , m_clientBufferSize(SymbianAudio::DefaultBufferSize) + , m_notifyInterval(SymbianAudio::DefaultNotifyInterval) + , m_notifyTimer(new QTimer(this)) + , m_error(QAudio::NoError) + , m_internalState(SymbianAudio::ClosedState) + , m_externalState(QAudio::StoppedState) + , m_pullMode(false) + , m_sink(0) + , m_pullTimer(new QTimer(this)) + , m_devSoundBuffer(0) + , m_devSoundBufferSize(0) + , m_totalBytesReady(0) + , m_devSoundBufferPos(0) + , m_totalSamplesRecorded(0) +{ + connect(m_notifyTimer.data(), SIGNAL(timeout()), this, SIGNAL(notify())); + + SymbianAudio::Utils::formatQtToNative(m_format, m_nativeFourCC, + m_nativeFormat); + + m_pullTimer->setInterval(PushInterval); + connect(m_pullTimer.data(), SIGNAL(timeout()), this, SLOT(pullData())); +} + +QAudioInputPrivate::~QAudioInputPrivate() +{ + close(); +} + +QIODevice* QAudioInputPrivate::start(QIODevice *device) +{ + stop(); + + open(); + if (SymbianAudio::ClosedState != m_internalState) { + if (device) { + m_pullMode = true; + m_sink = device; + } else { + m_sink = new SymbianAudioInputPrivate(this); + m_sink->open(QIODevice::ReadOnly | QIODevice::Unbuffered); + } + + m_elapsed.restart(); + } + + return m_sink; +} + +void QAudioInputPrivate::stop() +{ + close(); +} + +void QAudioInputPrivate::reset() +{ + m_totalSamplesRecorded += getSamplesRecorded(); + m_devSound->Stop(); + startRecording(); +} + +void QAudioInputPrivate::suspend() +{ + if (SymbianAudio::ActiveState == m_internalState + || SymbianAudio::IdleState == m_internalState) { + m_notifyTimer->stop(); + m_pullTimer->stop(); + m_devSound->Pause(); + const qint64 samplesRecorded = getSamplesRecorded(); + m_totalSamplesRecorded += samplesRecorded; + + if (m_devSoundBuffer) { + m_devSoundBufferQ.append(m_devSoundBuffer); + m_devSoundBuffer = 0; + } + + setState(SymbianAudio::SuspendedState); + } +} + +void QAudioInputPrivate::resume() +{ + if (SymbianAudio::SuspendedState == m_internalState) + startDataTransfer(); +} + +int QAudioInputPrivate::bytesReady() const +{ + Q_ASSERT(m_devSoundBufferPos <= m_totalBytesReady); + return m_totalBytesReady - m_devSoundBufferPos; +} + +int QAudioInputPrivate::periodSize() const +{ + return bufferSize(); +} + +void QAudioInputPrivate::setBufferSize(int value) +{ + // Note that DevSound does not allow its client to specify the buffer size. + // This functionality is available via custom interfaces, but since these + // cannot be guaranteed to work across all DevSound implementations, we + // do not use them here. + // In order to comply with the expected bevahiour of QAudioInput, we store + // the value and return it from bufferSize(), but the underlying DevSound + // buffer size remains unchanged. + if (value > 0) + m_clientBufferSize = value; +} + +int QAudioInputPrivate::bufferSize() const +{ + return m_devSoundBufferSize ? m_devSoundBufferSize : m_clientBufferSize; +} + +void QAudioInputPrivate::setNotifyInterval(int ms) +{ + if (ms > 0) { + const int oldNotifyInterval = m_notifyInterval; + m_notifyInterval = ms; + if (m_notifyTimer->isActive() && ms != oldNotifyInterval) + m_notifyTimer->start(m_notifyInterval); + } +} + +int QAudioInputPrivate::notifyInterval() const +{ + return m_notifyInterval; +} + +qint64 QAudioInputPrivate::processedUSecs() const +{ + int samplesPlayed = 0; + if (m_devSound && SymbianAudio::SuspendedState != m_internalState) + samplesPlayed = getSamplesRecorded(); + + // Protect against division by zero + Q_ASSERT_X(m_format.frequency() > 0, Q_FUNC_INFO, "Invalid frequency"); + + const qint64 result = qint64(1000000) * + (samplesPlayed + m_totalSamplesRecorded) + / m_format.frequency(); + + return result; +} + +qint64 QAudioInputPrivate::elapsedUSecs() const +{ + const qint64 result = (QAudio::StoppedState == state()) ? + 0 : m_elapsed.elapsed() * 1000; + return result; +} + +QAudio::Error QAudioInputPrivate::error() const +{ + return m_error; +} + +QAudio::State QAudioInputPrivate::state() const +{ + return m_externalState; +} + +QAudioFormat QAudioInputPrivate::format() const +{ + return m_format; +} + +//----------------------------------------------------------------------------- +// MDevSoundObserver implementation +//----------------------------------------------------------------------------- + +void QAudioInputPrivate::InitializeComplete(TInt aError) +{ + Q_ASSERT_X(SymbianAudio::InitializingState == m_internalState, + Q_FUNC_INFO, "Invalid state"); + + if (KErrNone == aError) + startRecording(); +} + +void QAudioInputPrivate::ToneFinished(TInt aError) +{ + Q_UNUSED(aError) + // This class doesn't use DevSound's tone playback functions, so should + // never receive this callback. + Q_ASSERT_X(false, Q_FUNC_INFO, "Unexpected callback"); +} + +void QAudioInputPrivate::BufferToBeFilled(CMMFBuffer *aBuffer) +{ + Q_UNUSED(aBuffer) + // This class doesn't use DevSound in play mode, so should never receive + // this callback. + Q_ASSERT_X(false, Q_FUNC_INFO, "Unexpected callback"); +} + +void QAudioInputPrivate::PlayError(TInt aError) +{ + Q_UNUSED(aError) + // This class doesn't use DevSound in play mode, so should never receive + // this callback. + Q_ASSERT_X(false, Q_FUNC_INFO, "Unexpected callback"); +} + +void QAudioInputPrivate::BufferToBeEmptied(CMMFBuffer *aBuffer) +{ + // Following receipt of this callback, DevSound should not provide another + // buffer until we have returned the current one. + Q_ASSERT_X(!m_devSoundBuffer, Q_FUNC_INFO, "Buffer already held"); + + CMMFDataBuffer *const buffer = static_cast(aBuffer); + + if (!m_devSoundBufferSize) + m_devSoundBufferSize = buffer->Data().MaxLength(); + + m_totalBytesReady += buffer->Data().Length(); + + if (SymbianAudio::SuspendedState == m_internalState) { + m_devSoundBufferQ.append(buffer); + } else { + // Will be returned to DevSound by bufferEmptied(). + m_devSoundBuffer = buffer; + m_devSoundBufferPos = 0; + + if (bytesReady() && !m_pullMode) + pushData(); + } +} + +void QAudioInputPrivate::RecordError(TInt aError) +{ + Q_UNUSED(aError) + setError(QAudio::IOError); +} + +void QAudioInputPrivate::ConvertError(TInt aError) +{ + Q_UNUSED(aError) + // This class doesn't use DevSound's format conversion functions, so + // should never receive this callback. + Q_ASSERT_X(false, Q_FUNC_INFO, "Unexpected callback"); +} + +void QAudioInputPrivate::DeviceMessage(TUid aMessageType, const TDesC8 &aMsg) +{ + Q_UNUSED(aMessageType) + Q_UNUSED(aMsg) + // Ignore this callback. +} + +//----------------------------------------------------------------------------- +// Private functions +//----------------------------------------------------------------------------- + +void QAudioInputPrivate::open() +{ + Q_ASSERT_X(SymbianAudio::ClosedState == m_internalState, + Q_FUNC_INFO, "DevSound already opened"); + + QT_TRAP_THROWING( m_devSound.reset(CMMFDevSound::NewL()) ) + + QScopedPointer caps( + new SymbianAudio::DevSoundCapabilities(*m_devSound, QAudio::AudioInput)); + + int err = SymbianAudio::Utils::isFormatSupported(m_format, *caps) ? + KErrNone : KErrNotSupported; + + if (KErrNone == err) { + setState(SymbianAudio::InitializingState); + TRAP(err, m_devSound->InitializeL(*this, m_nativeFourCC, + EMMFStateRecording)); + } + + if (KErrNone != err) { + setError(QAudio::OpenError); + m_devSound.reset(); + } +} + +void QAudioInputPrivate::startRecording() +{ + const int samplesRecorded = m_devSound->SamplesRecorded(); + Q_ASSERT(samplesRecorded == 0); + + TRAPD(err, startDevSoundL()); + if (KErrNone == err) { + startDataTransfer(); + } else { + setError(QAudio::OpenError); + close(); + } +} + +void QAudioInputPrivate::startDevSoundL() +{ + TMMFCapabilities nativeFormat = m_devSound->Config(); + m_nativeFormat.iBufferSize = nativeFormat.iBufferSize; + m_devSound->SetConfigL(m_nativeFormat); + m_devSound->RecordInitL(); +} + +void QAudioInputPrivate::startDataTransfer() +{ + m_notifyTimer->start(m_notifyInterval); + + if (m_pullMode) + m_pullTimer->start(); + + if (bytesReady()) { + setState(SymbianAudio::ActiveState); + if (!m_pullMode) + pushData(); + } else { + if (SymbianAudio::SuspendedState == m_internalState) + setState(SymbianAudio::ActiveState); + else + setState(SymbianAudio::IdleState); + } +} + +CMMFDataBuffer* QAudioInputPrivate::currentBuffer() const +{ + CMMFDataBuffer *result = m_devSoundBuffer; + if (!result && !m_devSoundBufferQ.empty()) + result = m_devSoundBufferQ.front(); + return result; +} + +void QAudioInputPrivate::pushData() +{ + Q_ASSERT_X(bytesReady(), Q_FUNC_INFO, "No data available"); + Q_ASSERT_X(!m_pullMode, Q_FUNC_INFO, "pushData called when in pull mode"); + qobject_cast(m_sink)->dataReady(); +} + +qint64 QAudioInputPrivate::read(char *data, qint64 len) +{ + // SymbianAudioInputPrivate is ready to read data + + Q_ASSERT_X(!m_pullMode, Q_FUNC_INFO, + "read called when in pull mode"); + + qint64 bytesRead = 0; + + CMMFDataBuffer *buffer = 0; + while ((buffer = currentBuffer()) && (bytesRead < len)) { + if (SymbianAudio::IdleState == m_internalState) + setState(SymbianAudio::ActiveState); + + TDesC8 &inputBuffer = buffer->Data(); + + const qint64 inputBytes = bytesReady(); + const qint64 outputBytes = len - bytesRead; + const qint64 copyBytes = outputBytes < inputBytes ? + outputBytes : inputBytes; + + memcpy(data, inputBuffer.Ptr() + m_devSoundBufferPos, copyBytes); + + m_devSoundBufferPos += copyBytes; + data += copyBytes; + bytesRead += copyBytes; + + if (!bytesReady()) + bufferEmptied(); + } + + return bytesRead; +} + +void QAudioInputPrivate::pullData() +{ + Q_ASSERT_X(m_pullMode, Q_FUNC_INFO, + "pullData called when in push mode"); + + CMMFDataBuffer *buffer = 0; + while (buffer = currentBuffer()) { + if (SymbianAudio::IdleState == m_internalState) + setState(SymbianAudio::ActiveState); + + TDesC8 &inputBuffer = buffer->Data(); + + const qint64 inputBytes = bytesReady(); + const qint64 bytesPushed = m_sink->write( + (char*)inputBuffer.Ptr() + m_devSoundBufferPos, inputBytes); + + m_devSoundBufferPos += bytesPushed; + + if (!bytesReady()) + bufferEmptied(); + + if (!bytesPushed) + break; + } +} + +void QAudioInputPrivate::bufferEmptied() +{ + m_devSoundBufferPos = 0; + + if (m_devSoundBuffer) { + m_totalBytesReady -= m_devSoundBuffer->Data().Length(); + m_devSoundBuffer = 0; + m_devSound->RecordData(); + } else { + Q_ASSERT(!m_devSoundBufferQ.empty()); + m_totalBytesReady -= m_devSoundBufferQ.front()->Data().Length(); + m_devSoundBufferQ.erase(m_devSoundBufferQ.begin()); + + // If the queue has been emptied, resume transfer from the hardware + if (m_devSoundBufferQ.empty()) + m_devSound->RecordInitL(); + } + + Q_ASSERT(m_totalBytesReady >= 0); +} + +void QAudioInputPrivate::close() +{ + m_notifyTimer->stop(); + m_pullTimer->stop(); + + m_error = QAudio::NoError; + + if (m_devSound) + m_devSound->Stop(); + m_devSound.reset(); + m_devSoundBuffer = 0; + m_devSoundBufferSize = 0; + m_totalBytesReady = 0; + + if (!m_pullMode) // m_sink is owned + delete m_sink; + m_pullMode = false; + m_sink = 0; + + m_devSoundBufferQ.clear(); + m_devSoundBufferPos = 0; + m_totalSamplesRecorded = 0; + + setState(SymbianAudio::ClosedState); +} + +qint64 QAudioInputPrivate::getSamplesRecorded() const +{ + qint64 result = 0; + if (m_devSound) + result = qint64(m_devSound->SamplesRecorded()); + return result; +} + +void QAudioInputPrivate::setError(QAudio::Error error) +{ + m_error = error; + + // Although no state transition actually occurs here, a stateChanged event + // must be emitted to inform the client that the call to start() was + // unsuccessful. + if (QAudio::OpenError == error) + emit stateChanged(QAudio::StoppedState); + + // Close the DevSound instance. This causes a transition to StoppedState. + // This must be done asynchronously in case the current function was called + // from a DevSound event handler, in which case deleting the DevSound + // instance may cause an exception. + QMetaObject::invokeMethod(this, "close", Qt::QueuedConnection); +} + +void QAudioInputPrivate::setState(SymbianAudio::State newInternalState) +{ + const QAudio::State oldExternalState = m_externalState; + m_internalState = newInternalState; + m_externalState = SymbianAudio::Utils::stateNativeToQt( + m_internalState, initializingState()); + + if (m_externalState != oldExternalState) + emit stateChanged(m_externalState); +} + +QAudio::State QAudioInputPrivate::initializingState() const +{ + return QAudio::IdleState; +} + +QT_END_NAMESPACE diff --git a/src/multimedia/multimedia/audio/qaudioinput_symbian_p.h b/src/multimedia/multimedia/audio/qaudioinput_symbian_p.h new file mode 100644 index 0000000..ca3ccf7 --- /dev/null +++ b/src/multimedia/multimedia/audio/qaudioinput_symbian_p.h @@ -0,0 +1,188 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtMultimedia module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists for the convenience +// of other Qt classes. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#ifndef QAUDIOINPUT_SYMBIAN_P_H +#define QAUDIOINPUT_SYMBIAN_P_H + +#include +#include +#include +#include +#include "qaudio_symbian_p.h" + +QT_BEGIN_NAMESPACE + +class QAudioInputPrivate; + +class SymbianAudioInputPrivate : public QIODevice +{ + friend class QAudioInputPrivate; + Q_OBJECT +public: + SymbianAudioInputPrivate(QAudioInputPrivate *audio); + ~SymbianAudioInputPrivate(); + + qint64 readData(char *data, qint64 len); + qint64 writeData(const char *data, qint64 len); + + void dataReady(); + +private: + QAudioInputPrivate *const m_audioDevice; +}; + +class QAudioInputPrivate + : public QAbstractAudioInput + , public MDevSoundObserver +{ + friend class SymbianAudioInputPrivate; + Q_OBJECT +public: + QAudioInputPrivate(const QByteArray &device, + const QAudioFormat &audioFormat); + ~QAudioInputPrivate(); + + // QAbstractAudioInput + QIODevice* start(QIODevice *device = 0); + void stop(); + void reset(); + void suspend(); + void resume(); + int bytesReady() const; + int periodSize() const; + void setBufferSize(int value); + int bufferSize() const; + void setNotifyInterval(int milliSeconds); + int notifyInterval() const; + qint64 processedUSecs() const; + qint64 elapsedUSecs() const; + QAudio::Error error() const; + QAudio::State state() const; + QAudioFormat format() const; + + // MDevSoundObserver + void InitializeComplete(TInt aError); + void ToneFinished(TInt aError); + void BufferToBeFilled(CMMFBuffer *aBuffer); + void PlayError(TInt aError); + void BufferToBeEmptied(CMMFBuffer *aBuffer); + void RecordError(TInt aError); + void ConvertError(TInt aError); + void DeviceMessage(TUid aMessageType, const TDesC8 &aMsg); + +private slots: + void pullData(); + +private: + void open(); + void startRecording(); + void startDevSoundL(); + void startDataTransfer(); + CMMFDataBuffer* currentBuffer() const; + void pushData(); + qint64 read(char *data, qint64 len); + void bufferEmptied(); + Q_INVOKABLE void close(); + + qint64 getSamplesRecorded() const; + + void setError(QAudio::Error error); + void setState(SymbianAudio::State state); + + QAudio::State initializingState() const; + +private: + const QByteArray m_device; + const QAudioFormat m_format; + + int m_clientBufferSize; + int m_notifyInterval; + QScopedPointer m_notifyTimer; + QTime m_elapsed; + QAudio::Error m_error; + + SymbianAudio::State m_internalState; + QAudio::State m_externalState; + + bool m_pullMode; + QIODevice *m_sink; + + QScopedPointer m_pullTimer; + + QScopedPointer m_devSound; + TUint32 m_nativeFourCC; + TMMFCapabilities m_nativeFormat; + + // Latest buffer provided by DevSound, to be empied of data. + CMMFDataBuffer *m_devSoundBuffer; + + int m_devSoundBufferSize; + + // Total amount of data in buffers provided by DevSound + int m_totalBytesReady; + + // Queue of buffers returned after call to CMMFDevSound::Pause(). + QList m_devSoundBufferQ; + + // Current read position within m_devSoundBuffer + qint64 m_devSoundBufferPos; + + // Samples recorded up to the last call to suspend(). It is necessary + // to cache this because suspend() is implemented using + // CMMFDevSound::Stop(), which resets DevSound's SamplesRecorded() counter. + quint32 m_totalSamplesRecorded; + +}; + +QT_END_NAMESPACE + +#endif diff --git a/src/multimedia/multimedia/audio/qaudioinput_win32_p.cpp b/src/multimedia/multimedia/audio/qaudioinput_win32_p.cpp new file mode 100644 index 0000000..b5d673e --- /dev/null +++ b/src/multimedia/multimedia/audio/qaudioinput_win32_p.cpp @@ -0,0 +1,613 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtMultimedia module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists for the convenience +// of other Qt classes. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + + +#include "qaudioinput_win32_p.h" + +QT_BEGIN_NAMESPACE + +//#define DEBUG_AUDIO 1 + +static const int minimumIntervalTime = 50; + +QAudioInputPrivate::QAudioInputPrivate(const QByteArray &device, const QAudioFormat& audioFormat): + settings(audioFormat) +{ + bytesAvailable = 0; + buffer_size = 0; + period_size = 0; + m_device = device; + totalTimeValue = 0; + intervalTime = 1000; + errorState = QAudio::NoError; + deviceState = QAudio::StoppedState; + audioSource = 0; + pullMode = true; + resuming = false; + finished = false; + + connect(this,SIGNAL(processMore()),SLOT(deviceReady())); + + InitializeCriticalSection(&waveInCriticalSection); +} + +QAudioInputPrivate::~QAudioInputPrivate() +{ + stop(); + DeleteCriticalSection(&waveInCriticalSection); +} + +void QT_WIN_CALLBACK QAudioInputPrivate::waveInProc( HWAVEIN hWaveIn, UINT uMsg, + DWORD dwInstance, DWORD dwParam1, DWORD dwParam2 ) +{ + Q_UNUSED(dwParam1) + Q_UNUSED(dwParam2) + Q_UNUSED(hWaveIn) + + QAudioInputPrivate* qAudio; + qAudio = (QAudioInputPrivate*)(dwInstance); + if(!qAudio) + return; + + switch(uMsg) { + case WIM_OPEN: + break; + case WIM_DATA: + EnterCriticalSection(&qAudio->waveInCriticalSection); + if(qAudio->waveFreeBlockCount > 0) + qAudio->waveFreeBlockCount--; + qAudio->feedback(); + LeaveCriticalSection(&qAudio->waveInCriticalSection); + break; + case WIM_CLOSE: + EnterCriticalSection(&qAudio->waveInCriticalSection); + qAudio->finished = true; + LeaveCriticalSection(&qAudio->waveInCriticalSection); + break; + default: + return; + } +} + +WAVEHDR* QAudioInputPrivate::allocateBlocks(int size, int count) +{ + int i; + unsigned char* buffer; + WAVEHDR* blocks; + DWORD totalBufferSize = (size + sizeof(WAVEHDR))*count; + + if((buffer=(unsigned char*)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY, + totalBufferSize)) == 0) { + qWarning("QAudioInput: Memory allocation error"); + return 0; + } + blocks = (WAVEHDR*)buffer; + buffer += sizeof(WAVEHDR)*count; + for(i = 0; i < count; i++) { + blocks[i].dwBufferLength = size; + blocks[i].lpData = (LPSTR)buffer; + blocks[i].dwBytesRecorded=0; + blocks[i].dwUser = 0L; + blocks[i].dwFlags = 0L; + blocks[i].dwLoops = 0L; + result = waveInPrepareHeader(hWaveIn,&blocks[i], sizeof(WAVEHDR)); + if(result != MMSYSERR_NOERROR) { + qWarning("QAudioInput: Can't prepare block %d",i); + return 0; + } + buffer += size; + } + return blocks; +} + +void QAudioInputPrivate::freeBlocks(WAVEHDR* blockArray) +{ + WAVEHDR* blocks = blockArray; + + int count = buffer_size/period_size; + + for(int i = 0; i < count; i++) { + waveInUnprepareHeader(hWaveIn,&blocks[i], sizeof(WAVEHDR)); + blocks+=sizeof(WAVEHDR); + } + HeapFree(GetProcessHeap(), 0, blockArray); +} + +QAudio::Error QAudioInputPrivate::error() const +{ + return errorState; +} + +QAudio::State QAudioInputPrivate::state() const +{ + return deviceState; +} + +QAudioFormat QAudioInputPrivate::format() const +{ + return settings; +} + +QIODevice* QAudioInputPrivate::start(QIODevice* device) +{ + if(deviceState != QAudio::StoppedState) + close(); + + if(!pullMode && audioSource) { + delete audioSource; + } + + if(device) { + //set to pull mode + pullMode = true; + audioSource = device; + deviceState = QAudio::ActiveState; + } else { + //set to push mode + pullMode = false; + deviceState = QAudio::IdleState; + audioSource = new InputPrivate(this); + audioSource->open(QIODevice::ReadOnly | QIODevice::Unbuffered); + } + + if( !open() ) + return 0; + + emit stateChanged(deviceState); + + return audioSource; +} + +void QAudioInputPrivate::stop() +{ + if(deviceState == QAudio::StoppedState) + return; + + close(); + emit stateChanged(deviceState); +} + +bool QAudioInputPrivate::open() +{ +#ifdef DEBUG_AUDIO + QTime now(QTime::currentTime()); + qDebug()<> 3) * wfx.nChannels; + wfx.nAvgBytesPerSec = wfx.nBlockAlign * wfx.nSamplesPerSec; + + UINT_PTR devId = WAVE_MAPPER; + + WAVEINCAPS wic; + unsigned long iNumDevs,ii; + iNumDevs = waveInGetNumDevs(); + for(ii=0;ii 0 && waveBlocks[header].dwFlags & WHDR_DONE) { + if(pullMode) { + l = audioSource->write(waveBlocks[header].lpData, + waveBlocks[header].dwBytesRecorded); +#ifdef DEBUG_AUDIO + qDebug()<<"IN: "<= buffer_size/period_size) + header = 0; + p+=l; + + EnterCriticalSection(&waveInCriticalSection); + if(!pullMode) { + if(l+period_size > len && waveFreeBlockCount == buffer_size/period_size) + done = true; + } else { + if(waveFreeBlockCount == buffer_size/period_size) + done = true; + } + LeaveCriticalSection(&waveInCriticalSection); + + written+=l; + } +#ifdef DEBUG_AUDIO + qDebug()<<"read in len="<= minimumIntervalTime) + intervalTime = ms; + else + intervalTime = minimumIntervalTime; +} + +int QAudioInputPrivate::notifyInterval() const +{ + return intervalTime; +} + +qint64 QAudioInputPrivate::processedUSecs() const +{ + if (deviceState == QAudio::StoppedState) + return 0; + qint64 result = qint64(1000000) * totalTimeValue / + (settings.channels()*(settings.sampleSize()/8)) / + settings.frequency(); + + return result; +} + +void QAudioInputPrivate::suspend() +{ + if(deviceState == QAudio::ActiveState) { + waveInReset(hWaveIn); + deviceState = QAudio::SuspendedState; + emit stateChanged(deviceState); + } +} + +void QAudioInputPrivate::feedback() +{ +#ifdef DEBUG_AUDIO + QTime now(QTime::currentTime()); + qDebug()<(audioSource); + a->trigger(); + } + + if((timeStamp.elapsed() + elapsedTimeOffset) > intervalTime) { + emit notify(); + elapsedTimeOffset = timeStamp.elapsed() + elapsedTimeOffset - intervalTime; + timeStamp.restart(); + } + return true; +} + +qint64 QAudioInputPrivate::elapsedUSecs() const +{ + if (deviceState == QAudio::StoppedState) + return 0; + + return timeStampOpened.elapsed()*1000; +} + +void QAudioInputPrivate::reset() +{ + close(); +} + +InputPrivate::InputPrivate(QAudioInputPrivate* audio) +{ + audioDevice = qobject_cast(audio); +} + +InputPrivate::~InputPrivate() {} + +qint64 InputPrivate::readData( char* data, qint64 len) +{ + // push mode, user read() called + if(audioDevice->deviceState != QAudio::ActiveState && + audioDevice->deviceState != QAudio::IdleState) + return 0; + // Read in some audio data + return audioDevice->read(data,len); +} + +qint64 InputPrivate::writeData(const char* data, qint64 len) +{ + Q_UNUSED(data) + Q_UNUSED(len) + + emit readyRead(); + return 0; +} + +void InputPrivate::trigger() +{ + emit readyRead(); +} + +QT_END_NAMESPACE diff --git a/src/multimedia/multimedia/audio/qaudioinput_win32_p.h b/src/multimedia/multimedia/audio/qaudioinput_win32_p.h new file mode 100644 index 0000000..66c2535 --- /dev/null +++ b/src/multimedia/multimedia/audio/qaudioinput_win32_p.h @@ -0,0 +1,159 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtMultimedia module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists for the convenience +// of other Qt classes. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#ifndef QAUDIOINPUTWIN_H +#define QAUDIOINPUTWIN_H + +#include +#include + +#include +#include +#include +#include +#include +#include + +#include +#include +#include + + +QT_BEGIN_NAMESPACE + +class QAudioInputPrivate : public QAbstractAudioInput +{ + Q_OBJECT +public: + QAudioInputPrivate(const QByteArray &device, const QAudioFormat& audioFormat); + ~QAudioInputPrivate(); + + qint64 read(char* data, qint64 len); + + QAudioFormat format() const; + QIODevice* start(QIODevice* device = 0); + void stop(); + void reset(); + void suspend(); + void resume(); + int bytesReady() const; + int periodSize() const; + void setBufferSize(int value); + int bufferSize() const; + void setNotifyInterval(int milliSeconds); + int notifyInterval() const; + qint64 processedUSecs() const; + qint64 elapsedUSecs() const; + QAudio::Error error() const; + QAudio::State state() const; + + QIODevice* audioSource; + QAudioFormat settings; + QAudio::Error errorState; + QAudio::State deviceState; + +private: + qint32 buffer_size; + qint32 period_size; + qint32 header; + QByteArray m_device; + int bytesAvailable; + int intervalTime; + QTime timeStamp; + qint64 elapsedTimeOffset; + QTime timeStampOpened; + qint64 totalTimeValue; + bool pullMode; + bool resuming; + WAVEFORMATEX wfx; + HWAVEIN hWaveIn; + MMRESULT result; + WAVEHDR* waveBlocks; + volatile bool finished; + volatile int waveFreeBlockCount; + int waveCurrentBlock; + + CRITICAL_SECTION waveInCriticalSection; + static void QT_WIN_CALLBACK waveInProc( HWAVEIN hWaveIn, UINT uMsg, + DWORD dwInstance, DWORD dwParam1, DWORD dwParam2 ); + + WAVEHDR* allocateBlocks(int size, int count); + void freeBlocks(WAVEHDR* blockArray); + bool open(); + void close(); + +private slots: + void feedback(); + bool deviceReady(); + +signals: + void processMore(); +}; + +class InputPrivate : public QIODevice +{ + Q_OBJECT +public: + InputPrivate(QAudioInputPrivate* audio); + ~InputPrivate(); + + qint64 readData( char* data, qint64 len); + qint64 writeData(const char* data, qint64 len); + + void trigger(); +private: + QAudioInputPrivate *audioDevice; +}; + +QT_END_NAMESPACE + +#endif diff --git a/src/multimedia/multimedia/audio/qaudiooutput.cpp b/src/multimedia/multimedia/audio/qaudiooutput.cpp new file mode 100644 index 0000000..b0b5244 --- /dev/null +++ b/src/multimedia/multimedia/audio/qaudiooutput.cpp @@ -0,0 +1,411 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtMultimedia module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + + +#include +#include +#include +#include + +#include "qaudiodevicefactory_p.h" + + +QT_BEGIN_NAMESPACE + +/*! + \class QAudioOutput + \brief The QAudioOutput class provides an interface for sending audio data to an audio output device. + + \inmodule QtMultimedia + \ingroup multimedia + \since 4.6 + + You can construct an audio output with the system's + \l{QAudioDeviceInfo::defaultOutputDevice()}{default audio output + device}. It is also possible to create QAudioOutput with a + specific QAudioDeviceInfo. When you create the audio output, you + should also send in the QAudioFormat to be used for the playback + (see the QAudioFormat class description for details). + + To play a file: + + Starting to play an audio stream is simply a matter of calling + start() with a QIODevice. QAudioOutput will then fetch the data it + needs from the io device. So playing back an audio file is as + simple as: + + \code + QFile inputFile; // class member. + QAudioOutput* audio; // class member. + \endcode + + \code + inputFile.setFileName("/tmp/test.raw"); + inputFile.open(QIODevice::ReadOnly); + + QAudioFormat format; + // Set up the format, eg. + format.setFrequency(8000); + format.setChannels(1); + format.setSampleSize(8); + format.setCodec("audio/pcm"); + format.setByteOrder(QAudioFormat::LittleEndian); + format.setSampleType(QAudioFormat::UnSignedInt); + + QAudioDeviceInfo info(QAudioDeviceInfo::defaultOutputDevice()); + if (!info.isFormatSupported(format)) { + qWarning()<<"raw audio format not supported by backend, cannot play audio."; + return; + } + + audio = new QAudioOutput(format, this); + connect(audio,SIGNAL(stateChanged(QAudio::State)),SLOT(finishedPlaying(QAudio::State))); + audio->start(&inputFile); + + \endcode + + The file will start playing assuming that the audio system and + output device support it. If you run out of luck, check what's + up with the error() function. + + After the file has finished playing, we need to stop the device: + + \code + void finishedPlaying(QAudio::State state) + { + if(state == QAudio::IdleState) { + audio->stop(); + inputFile.close(); + delete audio; + } + } + \endcode + + At any given time, the QAudioOutput will be in one of four states: + active, suspended, stopped, or idle. These states are described + by the QAudio::State enum. + State changes are reported through the stateChanged() signal. You + can use this signal to, for instance, update the GUI of the + application; the mundane example here being changing the state of + a \c { play/pause } button. You request a state change directly + with suspend(), stop(), reset(), resume(), and start(). + + While the stream is playing, you can set a notify interval in + milliseconds with setNotifyInterval(). This interval specifies the + time between two emissions of the notify() signal. This is + relative to the position in the stream, i.e., if the QAudioOutput + is in the SuspendedState or the IdleState, the notify() signal is + not emitted. A typical use-case would be to update a + \l{QSlider}{slider} that allows seeking in the stream. + If you want the time since playback started regardless of which + states the audio output has been in, elapsedUSecs() is the function for you. + + If an error occurs, you can fetch the \l{QAudio::Error}{error + type} with the error() function. Please see the QAudio::Error enum + for a description of the possible errors that are reported. When + an error is encountered, the state changes to QAudio::StoppedState. + You can check for errors by connecting to the stateChanged() + signal: + + \snippet doc/src/snippets/audio/main.cpp 3 + + \sa QAudioInput, QAudioDeviceInfo +*/ + +/*! + Construct a new audio output and attach it to \a parent. + The default audio output device is used with the output + \a format parameters. +*/ + +QAudioOutput::QAudioOutput(const QAudioFormat &format, QObject *parent): + QObject(parent) +{ + d = QAudioDeviceFactory::createDefaultOutputDevice(format); + connect(d, SIGNAL(notify()), SIGNAL(notify())); + connect(d, SIGNAL(stateChanged(QAudio::State)), SIGNAL(stateChanged(QAudio::State))); +} + +/*! + Construct a new audio output and attach it to \a parent. + The device referenced by \a audioDevice is used with the output + \a format parameters. +*/ + +QAudioOutput::QAudioOutput(const QAudioDeviceInfo &audioDevice, const QAudioFormat &format, QObject *parent): + QObject(parent) +{ + d = QAudioDeviceFactory::createOutputDevice(audioDevice, format); + connect(d, SIGNAL(notify()), SIGNAL(notify())); + connect(d, SIGNAL(stateChanged(QAudio::State)), SIGNAL(stateChanged(QAudio::State))); +} + +/*! + Destroys this audio output. +*/ + +QAudioOutput::~QAudioOutput() +{ + delete d; +} + +/*! + Returns the QAudioFormat being used. + +*/ + +QAudioFormat QAudioOutput::format() const +{ + return d->format(); +} + +/*! + Uses the \a device as the QIODevice to transfer data. + Passing a QIODevice allows the data to be transfered without any extra code. + All that is required is to open the QIODevice. + + If able to successfully output audio data to the systems audio device the + state() is set to QAudio::ActiveState, error() is set to QAudio::NoError + and the stateChanged() signal is emitted. + + If a problem occurs during this process the error() is set to QAudio::OpenError, + state() is set to QAudio::StoppedState and stateChanged() signal is emitted. + + \sa QIODevice +*/ + +void QAudioOutput::start(QIODevice* device) +{ + d->start(device); +} + +/*! + Returns a pointer to the QIODevice being used to handle the data + transfer. This QIODevice can be used to write() audio data directly. + + If able to access the systems audio device the state() is set to + QAudio::IdleState, error() is set to QAudio::NoError + and the stateChanged() signal is emitted. + + If a problem occurs during this process the error() is set to QAudio::OpenError, + state() is set to QAudio::StoppedState and stateChanged() signal is emitted. + + \sa QIODevice +*/ + +QIODevice* QAudioOutput::start() +{ + return d->start(0); +} + +/*! + Stops the audio output, detaching from the system resource. + + Sets error() to QAudio::NoError, state() to QAudio::StoppedState and + emit stateChanged() signal. +*/ + +void QAudioOutput::stop() +{ + d->stop(); +} + +/*! + Drops all audio data in the buffers, resets buffers to zero. +*/ + +void QAudioOutput::reset() +{ + d->reset(); +} + +/*! + Stops processing audio data, preserving buffered audio data. + + Sets error() to QAudio::NoError, state() to QAudio::SuspendedState and + emit stateChanged() signal. +*/ + +void QAudioOutput::suspend() +{ + d->suspend(); +} + +/*! + Resumes processing audio data after a suspend(). + + Sets error() to QAudio::NoError. + Sets state() to QAudio::ActiveState if you previously called start(QIODevice*). + Sets state() to QAudio::IdleState if you previously called start(). + emits stateChanged() signal. +*/ + +void QAudioOutput::resume() +{ + d->resume(); +} + +/*! + Returns the free space available in bytes in the audio buffer. + + NOTE: returned value is only valid while in QAudio::ActiveState or QAudio::IdleState + state, otherwise returns zero. +*/ + +int QAudioOutput::bytesFree() const +{ + return d->bytesFree(); +} + +/*! + Returns the period size in bytes. + + Note: This is the recommended write size in bytes. +*/ + +int QAudioOutput::periodSize() const +{ + return d->periodSize(); +} + +/*! + Sets the audio buffer size to \a value in bytes. + + Note: This function can be called anytime before start(), calls to this + are ignored after start(). It should not be assumed that the buffer size + set is the actual buffer size used, calling bufferSize() anytime after start() + will return the actual buffer size being used. +*/ + +void QAudioOutput::setBufferSize(int value) +{ + d->setBufferSize(value); +} + +/*! + Returns the audio buffer size in bytes. + + If called before start(), returns platform default value. + If called before start() but setBufferSize() was called prior, returns value set by setBufferSize(). + If called after start(), returns the actual buffer size being used. This may not be what was set previously + by setBufferSize(). + +*/ + +int QAudioOutput::bufferSize() const +{ + return d->bufferSize(); +} + +/*! + Sets the interval for notify() signal to be emitted. + This is based on the \a ms of audio data processed + not on actual real-time. + The minimum resolution of the timer is platform specific and values + should be checked with notifyInterval() to confirm actual value + being used. +*/ + +void QAudioOutput::setNotifyInterval(int ms) +{ + d->setNotifyInterval(ms); +} + +/*! + Returns the notify interval in milliseconds. +*/ + +int QAudioOutput::notifyInterval() const +{ + return d->notifyInterval(); +} + +/*! + Returns the amount of audio data processed since start() + was called in microseconds. +*/ + +qint64 QAudioOutput::processedUSecs() const +{ + return d->processedUSecs(); +} + +/*! + Returns the microseconds since start() was called, including time in Idle and + Suspend states. +*/ + +qint64 QAudioOutput::elapsedUSecs() const +{ + return d->elapsedUSecs(); +} + +/*! + Returns the error state. +*/ + +QAudio::Error QAudioOutput::error() const +{ + return d->error(); +} + +/*! + Returns the state of audio processing. +*/ + +QAudio::State QAudioOutput::state() const +{ + return d->state(); +} + +/*! + \fn QAudioOutput::stateChanged(QAudio::State state) + This signal is emitted when the device \a state has changed. + This is the current state of the audio output. +*/ + +/*! + \fn QAudioOutput::notify() + This signal is emitted when x ms of audio data has been processed + the interval set by setNotifyInterval(x). +*/ + +QT_END_NAMESPACE diff --git a/src/multimedia/multimedia/audio/qaudiooutput.h b/src/multimedia/multimedia/audio/qaudiooutput.h new file mode 100644 index 0000000..0f45b1b --- /dev/null +++ b/src/multimedia/multimedia/audio/qaudiooutput.h @@ -0,0 +1,111 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtMultimedia module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + + +#ifndef QAUDIOOUTPUT_H +#define QAUDIOOUTPUT_H + +#include +#include + +#include +#include +#include + + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Multimedia) + + +class QAbstractAudioOutput; + +class Q_MULTIMEDIA_EXPORT QAudioOutput : public QObject +{ + Q_OBJECT + +public: + explicit QAudioOutput(const QAudioFormat &format = QAudioFormat(), QObject *parent = 0); + explicit QAudioOutput(const QAudioDeviceInfo &audioDeviceInfo, const QAudioFormat &format = QAudioFormat(), QObject *parent = 0); + ~QAudioOutput(); + + QAudioFormat format() const; + + void start(QIODevice *device); + QIODevice* start(); + + void stop(); + void reset(); + void suspend(); + void resume(); + + void setBufferSize(int bytes); + int bufferSize() const; + + int bytesFree() const; + int periodSize() const; + + void setNotifyInterval(int milliSeconds); + int notifyInterval() const; + + qint64 processedUSecs() const; + qint64 elapsedUSecs() const; + + QAudio::Error error() const; + QAudio::State state() const; + +Q_SIGNALS: + void stateChanged(QAudio::State); + void notify(); + +private: + Q_DISABLE_COPY(QAudioOutput) + + QAbstractAudioOutput* d; +}; + +QT_END_NAMESPACE + +QT_END_HEADER + +#endif // QAUDIOOUTPUT_H diff --git a/src/multimedia/multimedia/audio/qaudiooutput_alsa_p.cpp b/src/multimedia/multimedia/audio/qaudiooutput_alsa_p.cpp new file mode 100644 index 0000000..cf3726b --- /dev/null +++ b/src/multimedia/multimedia/audio/qaudiooutput_alsa_p.cpp @@ -0,0 +1,780 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtMultimedia module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists for the convenience +// of other Qt classes. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include +#include "qaudiooutput_alsa_p.h" +#include "qaudiodeviceinfo_alsa_p.h" + +QT_BEGIN_NAMESPACE + +//#define DEBUG_AUDIO 1 + +static const int minimumIntervalTime = 50; + +QAudioOutputPrivate::QAudioOutputPrivate(const QByteArray &device, const QAudioFormat& audioFormat): + settings(audioFormat) +{ + bytesAvailable = 0; + handle = 0; + ahandler = 0; + access = SND_PCM_ACCESS_RW_INTERLEAVED; + pcmformat = SND_PCM_FORMAT_S16; + buffer_frames = 0; + period_frames = 0; + buffer_size = 0; + period_size = 0; + buffer_time = 100000; + period_time = 20000; + totalTimeValue = 0; + intervalTime = 1000; + audioBuffer = 0; + errorState = QAudio::NoError; + deviceState = QAudio::StoppedState; + audioSource = 0; + pullMode = true; + resuming = false; + opened = false; + + QStringList list1 = QString(QLatin1String(device)).split(QLatin1String(":")); + m_device = QByteArray(list1.at(0).toLocal8Bit().constData()); + + timer = new QTimer(this); + connect(timer,SIGNAL(timeout()),SLOT(userFeed())); +} + +QAudioOutputPrivate::~QAudioOutputPrivate() +{ + close(); + disconnect(timer, SIGNAL(timeout())); + QCoreApplication::processEvents(); + delete timer; +} + +QAudio::Error QAudioOutputPrivate::error() const +{ + return errorState; +} + +QAudio::State QAudioOutputPrivate::state() const +{ + return deviceState; +} + +void QAudioOutputPrivate::async_callback(snd_async_handler_t *ahandler) +{ + QAudioOutputPrivate* audioOut; + + audioOut = static_cast + (snd_async_handler_get_callback_private(ahandler)); + + if((audioOut->deviceState==QAudio::ActiveState)||(audioOut->resuming)) + audioOut->feedback(); +} + +int QAudioOutputPrivate::xrun_recovery(int err) +{ + int count = 0; + bool reset = false; + + if(err == -EPIPE) { + errorState = QAudio::UnderrunError; + err = snd_pcm_prepare(handle); + if(err < 0) + reset = true; + + } else if((err == -ESTRPIPE)||(err == -EIO)) { + errorState = QAudio::IOError; + while((err = snd_pcm_resume(handle)) == -EAGAIN){ + usleep(100); + count++; + if(count > 5) { + reset = true; + break; + } + } + if(err < 0) { + err = snd_pcm_prepare(handle); + if(err < 0) + reset = true; + } + } + if(reset) { + close(); + open(); + snd_pcm_prepare(handle); + return 0; + } + return err; +} + +int QAudioOutputPrivate::setFormat() +{ + snd_pcm_format_t pcmformat = SND_PCM_FORMAT_S16; + + if(settings.sampleSize() == 8) { + pcmformat = SND_PCM_FORMAT_U8; + + } else if(settings.sampleSize() == 16) { + if(settings.sampleType() == QAudioFormat::SignedInt) { + if(settings.byteOrder() == QAudioFormat::LittleEndian) + pcmformat = SND_PCM_FORMAT_S16_LE; + else + pcmformat = SND_PCM_FORMAT_S16_BE; + } else if(settings.sampleType() == QAudioFormat::UnSignedInt) { + if(settings.byteOrder() == QAudioFormat::LittleEndian) + pcmformat = SND_PCM_FORMAT_U16_LE; + else + pcmformat = SND_PCM_FORMAT_U16_BE; + } + } else if(settings.sampleSize() == 24) { + if(settings.sampleType() == QAudioFormat::SignedInt) { + if(settings.byteOrder() == QAudioFormat::LittleEndian) + pcmformat = SND_PCM_FORMAT_S24_LE; + else + pcmformat = SND_PCM_FORMAT_S24_BE; + } else if(settings.sampleType() == QAudioFormat::UnSignedInt) { + if(settings.byteOrder() == QAudioFormat::LittleEndian) + pcmformat = SND_PCM_FORMAT_U24_LE; + else + pcmformat = SND_PCM_FORMAT_U24_BE; + } + } else if(settings.sampleSize() == 32) { + if(settings.sampleType() == QAudioFormat::SignedInt) { + if(settings.byteOrder() == QAudioFormat::LittleEndian) + pcmformat = SND_PCM_FORMAT_S32_LE; + else + pcmformat = SND_PCM_FORMAT_S32_BE; + } else if(settings.sampleType() == QAudioFormat::UnSignedInt) { + if(settings.byteOrder() == QAudioFormat::LittleEndian) + pcmformat = SND_PCM_FORMAT_U32_LE; + else + pcmformat = SND_PCM_FORMAT_U32_BE; + } else if(settings.sampleType() == QAudioFormat::Float) { + if(settings.byteOrder() == QAudioFormat::LittleEndian) + pcmformat = SND_PCM_FORMAT_FLOAT_LE; + else + pcmformat = SND_PCM_FORMAT_FLOAT_BE; + } + } else if(settings.sampleSize() == 64) { + if(settings.byteOrder() == QAudioFormat::LittleEndian) + pcmformat = SND_PCM_FORMAT_FLOAT64_LE; + else + pcmformat = SND_PCM_FORMAT_FLOAT64_BE; + } + + return snd_pcm_hw_params_set_format( handle, hwparams, pcmformat); +} + +QIODevice* QAudioOutputPrivate::start(QIODevice* device) +{ + if(deviceState != QAudio::StoppedState) + deviceState = QAudio::StoppedState; + + errorState = QAudio::NoError; + + // Handle change of mode + if(audioSource && pullMode && !device) { + // pull -> push + close(); + audioSource = 0; + } else if(audioSource && !pullMode && device) { + // push -> pull + close(); + delete audioSource; + audioSource = 0; + } + + if(device) { + //set to pull mode + pullMode = true; + audioSource = device; + deviceState = QAudio::ActiveState; + } else { + //set to push mode + if(!audioSource) { + audioSource = new OutputPrivate(this); + audioSource->open(QIODevice::WriteOnly|QIODevice::Unbuffered); + } + pullMode = false; + deviceState = QAudio::IdleState; + } + + open(); + + emit stateChanged(deviceState); + + return audioSource; +} + +void QAudioOutputPrivate::stop() +{ + if(deviceState == QAudio::StoppedState) + return; + errorState = QAudio::NoError; + deviceState = QAudio::StoppedState; + close(); + emit stateChanged(deviceState); +} + +bool QAudioOutputPrivate::open() +{ + if(opened) + return true; + +#ifdef DEBUG_AUDIO + QTime now(QTime::currentTime()); + qDebug()< devices = QAudioDeviceInfoInternal::availableDevices(QAudio::AudioOutput); + if(dev.compare(QLatin1String("default")) == 0) { +#if(SND_LIB_MAJOR == 1 && SND_LIB_MINOR == 0 && SND_LIB_SUBMINOR >= 14) + dev = QLatin1String(devices.first().constData()); +#else + dev = QLatin1String("hw:0,0"); +#endif + } else { +#if(SND_LIB_MAJOR == 1 && SND_LIB_MINOR == 0 && SND_LIB_SUBMINOR >= 14) + dev = QLatin1String(m_device); +#else + int idx = 0; + char *name; + + QString shortName = QLatin1String(m_device.mid(m_device.indexOf('=',0)+1).constData()); + + while(snd_card_get_name(idx,&name) == 0) { + if(qstrncmp(shortName.toLocal8Bit().constData(),name,shortName.length()) == 0) + break; + idx++; + } + dev = QString(QLatin1String("hw:%1,0")).arg(idx); +#endif + } + + // Step 1: try and open the device + while((count < 5) && (err < 0)) { + err=snd_pcm_open(&handle,dev.toLocal8Bit().constData(),SND_PCM_STREAM_PLAYBACK,0); + if(err < 0) + count++; + } + if (( err < 0)||(handle == 0)) { + errorState = QAudio::OpenError; + deviceState = QAudio::StoppedState; + return false; + } + snd_pcm_nonblock( handle, 0 ); + + // Step 2: Set the desired HW parameters. + snd_pcm_hw_params_alloca( &hwparams ); + + bool fatal = false; + QString errMessage; + unsigned int chunks = 8; + + err = snd_pcm_hw_params_any( handle, hwparams ); + if ( err < 0 ) { + fatal = true; + errMessage = QString::fromLatin1("QAudioOutput: snd_pcm_hw_params_any: err = %1").arg(err); + } + if ( !fatal ) { + err = snd_pcm_hw_params_set_rate_resample( handle, hwparams, 1 ); + if ( err < 0 ) { + fatal = true; + errMessage = QString::fromLatin1("QAudioOutput: snd_pcm_hw_params_set_rate_resample: err = %1").arg(err); + } + } + if ( !fatal ) { + err = snd_pcm_hw_params_set_access( handle, hwparams, access ); + if ( err < 0 ) { + fatal = true; + errMessage = QString::fromLatin1("QAudioOutput: snd_pcm_hw_params_set_access: err = %1").arg(err); + } + } + if ( !fatal ) { + err = setFormat(); + if ( err < 0 ) { + fatal = true; + errMessage = QString::fromLatin1("QAudioOutput: snd_pcm_hw_params_set_format: err = %1").arg(err); + } + } + if ( !fatal ) { + err = snd_pcm_hw_params_set_channels( handle, hwparams, (unsigned int)settings.channels() ); + if ( err < 0 ) { + fatal = true; + errMessage = QString::fromLatin1("QAudioOutput: snd_pcm_hw_params_set_channels: err = %1").arg(err); + } + } + if ( !fatal ) { + err = snd_pcm_hw_params_set_rate_near( handle, hwparams, &freakuency, 0 ); + if ( err < 0 ) { + fatal = true; + errMessage = QString::fromLatin1("QAudioOutput: snd_pcm_hw_params_set_rate_near: err = %1").arg(err); + } + } + if ( !fatal ) { + unsigned int maxBufferTime = 0; + unsigned int minBufferTime = 0; + unsigned int maxPeriodTime = 0; + unsigned int minPeriodTime = 0; + + err = snd_pcm_hw_params_get_buffer_time_max(hwparams, &maxBufferTime, &dir); + if ( err >= 0) + err = snd_pcm_hw_params_get_buffer_time_min(hwparams, &minBufferTime, &dir); + if ( err >= 0) + err = snd_pcm_hw_params_get_period_time_max(hwparams, &maxPeriodTime, &dir); + if ( err >= 0) + err = snd_pcm_hw_params_get_period_time_min(hwparams, &minPeriodTime, &dir); + + if ( err < 0 ) { + fatal = true; + errMessage = QString::fromLatin1("QAudioOutput: buffer/period min and max: err = %1").arg(err); + } else { + if (maxBufferTime < buffer_time || buffer_time < minBufferTime || maxPeriodTime < period_time || minPeriodTime > period_time) { +#ifdef DEBUG_AUDIO + qDebug()<<"defaults out of range"; + qDebug()<<"pmin="<start(period_time/1000); + + clockStamp.restart(); + timeStamp.restart(); + elapsedTimeOffset = 0; + errorState = QAudio::NoError; + totalTimeValue = 0; + opened = true; + + return true; +} + +void QAudioOutputPrivate::close() +{ + timer->stop(); + + if ( handle ) { + snd_pcm_drain( handle ); + snd_pcm_close( handle ); + handle = 0; + delete [] audioBuffer; + audioBuffer=0; + } + if(!pullMode && audioSource) { + delete audioSource; + audioSource = 0; + } + opened = false; +} + +int QAudioOutputPrivate::bytesFree() const +{ + if(resuming) + return period_size; + + if(deviceState != QAudio::ActiveState && deviceState != QAudio::IdleState) + return 0; + int frames = snd_pcm_avail_update(handle); + if((int)frames > (int)buffer_frames) + frames = buffer_frames; + + return snd_pcm_frames_to_bytes(handle, frames); +} + +qint64 QAudioOutputPrivate::write( const char *data, qint64 len ) +{ + // Write out some audio data + if ( !handle ) + return 0; +#ifdef DEBUG_AUDIO + qDebug()<<"frames to write out = "<< + snd_pcm_bytes_to_frames( handle, (int)len )<<" ("< 0) { + totalTimeValue += err; + resuming = false; + errorState = QAudio::NoError; + if (deviceState != QAudio::ActiveState) { + deviceState = QAudio::ActiveState; + emit stateChanged(deviceState); + } + return snd_pcm_frames_to_bytes( handle, err ); + } else + err = xrun_recovery(err); + + if(err < 0) { + close(); + errorState = QAudio::FatalError; + deviceState = QAudio::StoppedState; + emit stateChanged(deviceState); + } + return 0; +} + +int QAudioOutputPrivate::periodSize() const +{ + return period_size; +} + +void QAudioOutputPrivate::setBufferSize(int value) +{ + if(deviceState == QAudio::StoppedState) + buffer_size = value; +} + +int QAudioOutputPrivate::bufferSize() const +{ + return buffer_size; +} + +void QAudioOutputPrivate::setNotifyInterval(int ms) +{ + if(ms >= minimumIntervalTime) + intervalTime = ms; + else + intervalTime = minimumIntervalTime; +} + +int QAudioOutputPrivate::notifyInterval() const +{ + return intervalTime; +} + +qint64 QAudioOutputPrivate::processedUSecs() const +{ + return qint64(1000000) * totalTimeValue / settings.frequency(); +} + +void QAudioOutputPrivate::resume() +{ + if(deviceState == QAudio::SuspendedState) { + int err = 0; + + if(handle) { + err = snd_pcm_prepare( handle ); + if(err < 0) + xrun_recovery(err); + + err = snd_pcm_start(handle); + if(err < 0) + xrun_recovery(err); + + bytesAvailable = (int)snd_pcm_frames_to_bytes(handle, buffer_frames); + } + resuming = true; + + deviceState = QAudio::ActiveState; + + errorState = QAudio::NoError; + timer->start(period_time/1000); + emit stateChanged(deviceState); + } +} + +QAudioFormat QAudioOutputPrivate::format() const +{ + return settings; +} + +void QAudioOutputPrivate::suspend() +{ + if(deviceState == QAudio::ActiveState || deviceState == QAudio::IdleState || resuming) { + timer->stop(); + deviceState = QAudio::SuspendedState; + errorState = QAudio::NoError; + emit stateChanged(deviceState); + } +} + +void QAudioOutputPrivate::userFeed() +{ + if(deviceState == QAudio::StoppedState || deviceState == QAudio::SuspendedState) + return; +#ifdef DEBUG_AUDIO + QTime now(QTime::currentTime()); + qDebug()<acquireReadRegion((maxFrames - framesRead) * m_bytesPerFrame); + + if (region.second > 0) { + region.second -= region.second % m_bytesPerFrame; + memcpy(data + (framesRead * m_bytesPerFrame), region.first, region.second); + framesRead += region.second / m_bytesPerFrame; + } + else + wecan = false; + + m_buffer->releaseReadRegion(region); + } + + if (framesRead == 0 && m_deviceError) + framesRead = -1; + + return framesRead; + } + + qint64 writeBytes(const char* data, qint64 maxSize) + { + bool wecan = true; + qint64 bytesWritten = 0; + + maxSize -= maxSize % m_bytesPerFrame; + while (wecan && bytesWritten < maxSize) { + QAudioRingBuffer::Region region = m_buffer->acquireWriteRegion(maxSize - bytesWritten); + + if (region.second > 0) { + memcpy(region.first, data + bytesWritten, region.second); + bytesWritten += region.second; + } + else + wecan = false; + + m_buffer->releaseWriteRegion(region); + } + + if (bytesWritten > 0) + emit readyRead(); + + return bytesWritten; + } + + int available() const + { + return m_buffer->free(); + } + + void reset() + { + m_buffer->reset(); + m_deviceError = false; + } + + void setPrefetchDevice(QIODevice* device) + { + if (m_device != device) { + m_device = device; + if (m_device != 0) + fillBuffer(); + } + } + + void startFillTimer() + { + if (m_device != 0) + m_fillTimer->start(m_buffer->size() / 2 / m_maxPeriodSize * m_periodTime); + } + + void stopFillTimer() + { + m_fillTimer->stop(); + } + +signals: + void readyRead(); + +private slots: + void fillBuffer() + { + const int free = m_buffer->free(); + const int writeSize = free - (free % m_maxPeriodSize); + + if (writeSize > 0) { + bool wecan = true; + int filled = 0; + + while (!m_deviceError && wecan && filled < writeSize) { + QAudioRingBuffer::Region region = m_buffer->acquireWriteRegion(writeSize - filled); + + if (region.second > 0) { + region.second = m_device->read(region.first, region.second); + if (region.second > 0) + filled += region.second; + else if (region.second == 0) + wecan = false; + else if (region.second < 0) { + m_fillTimer->stop(); + region.second = 0; + m_deviceError = true; + } + } + else + wecan = false; + + m_buffer->releaseWriteRegion(region); + } + + if (filled > 0) + emit readyRead(); + } + } + +private: + bool m_deviceError; + int m_maxPeriodSize; + int m_bytesPerFrame; + int m_periodTime; + QIODevice* m_device; + QTimer* m_fillTimer; + QAudioRingBuffer* m_buffer; +}; + + +} + +class MacOutputDevice : public QIODevice +{ + Q_OBJECT + +public: + MacOutputDevice(QtMultimediaInternal::QAudioOutputBuffer* audioBuffer, QObject* parent): + QIODevice(parent), + m_audioBuffer(audioBuffer) + { + open(QIODevice::WriteOnly | QIODevice::Unbuffered); + } + + qint64 readData(char* data, qint64 len) + { + Q_UNUSED(data); + Q_UNUSED(len); + + return 0; + } + + qint64 writeData(const char* data, qint64 len) + { + return m_audioBuffer->writeBytes(data, len); + } + + bool isSequential() const + { + return true; + } + +private: + QtMultimediaInternal::QAudioOutputBuffer* m_audioBuffer; +}; + + +QAudioOutputPrivate::QAudioOutputPrivate(const QByteArray& device, const QAudioFormat& format): + audioFormat(format) +{ + QDataStream ds(device); + quint32 did, mode; + + ds >> did >> mode; + + if (QAudio::Mode(mode) == QAudio::AudioInput) + errorCode = QAudio::OpenError; + else { + isOpen = false; + audioDeviceId = AudioDeviceID(did); + audioUnit = 0; + audioIO = 0; + startTime = 0; + totalFrames = 0; + audioBuffer = 0; + internalBufferSize = QtMultimediaInternal::default_buffer_size; + clockFrequency = AudioGetHostClockFrequency() / 1000; + errorCode = QAudio::NoError; + stateCode = QAudio::StoppedState; + audioThreadState = Stopped; + + intervalTimer = new QTimer(this); + intervalTimer->setInterval(1000); + connect(intervalTimer, SIGNAL(timeout()), SIGNAL(notify())); + } +} + +QAudioOutputPrivate::~QAudioOutputPrivate() +{ + close(); +} + +bool QAudioOutputPrivate::open() +{ + if (errorCode != QAudio::NoError) + return false; + + if (isOpen) + return true; + + ComponentDescription cd; + cd.componentType = kAudioUnitType_Output; + cd.componentSubType = kAudioUnitSubType_HALOutput; + cd.componentManufacturer = kAudioUnitManufacturer_Apple; + cd.componentFlags = 0; + cd.componentFlagsMask = 0; + + // Open + Component cp = FindNextComponent(NULL, &cd); + if (cp == 0) { + qWarning() << "QAudioOutput: Failed to find HAL Output component"; + return false; + } + + if (OpenAComponent(cp, &audioUnit) != noErr) { + qWarning() << "QAudioOutput: Unable to Open Output Component"; + return false; + } + + // register callback + AURenderCallbackStruct cb; + cb.inputProc = renderCallback; + cb.inputProcRefCon = this; + + if (AudioUnitSetProperty(audioUnit, + kAudioUnitProperty_SetRenderCallback, + kAudioUnitScope_Global, + 0, + &cb, + sizeof(cb)) != noErr) { + qWarning() << "QAudioOutput: Failed to set AudioUnit callback"; + return false; + } + + // Set Audio Device + if (AudioUnitSetProperty(audioUnit, + kAudioOutputUnitProperty_CurrentDevice, + kAudioUnitScope_Global, + 0, + &audioDeviceId, + sizeof(audioDeviceId)) != noErr) { + qWarning() << "QAudioOutput: Unable to use configured device"; + return false; + } + + // Set stream format + streamFormat = toAudioStreamBasicDescription(audioFormat); + + UInt32 size = sizeof(deviceFormat); + if (AudioUnitGetProperty(audioUnit, + kAudioUnitProperty_StreamFormat, + kAudioUnitScope_Input, + 0, + &deviceFormat, + &size) != noErr) { + qWarning() << "QAudioOutput: Unable to retrieve device format"; + return false; + } + + if (AudioUnitSetProperty(audioUnit, + kAudioUnitProperty_StreamFormat, + kAudioUnitScope_Input, + 0, + &streamFormat, + sizeof(streamFormat)) != noErr) { + qWarning() << "QAudioOutput: Unable to Set Stream information"; + return false; + } + + // Allocate buffer + UInt32 numberOfFrames = 0; + size = sizeof(UInt32); + if (AudioUnitGetProperty(audioUnit, + kAudioDevicePropertyBufferFrameSize, + kAudioUnitScope_Global, + 0, + &numberOfFrames, + &size) != noErr) { + qWarning() << "QAudioInput: Failed to get audio period size"; + return false; + } + + periodSizeBytes = (numberOfFrames * streamFormat.mSampleRate / deviceFormat.mSampleRate) * + streamFormat.mBytesPerFrame; + if (internalBufferSize < periodSizeBytes * 2) + internalBufferSize = periodSizeBytes * 2; + else + internalBufferSize -= internalBufferSize % streamFormat.mBytesPerFrame; + + audioBuffer = new QtMultimediaInternal::QAudioOutputBuffer(internalBufferSize, periodSizeBytes, audioFormat); + connect(audioBuffer, SIGNAL(readyRead()), SLOT(inputReady())); // Pull + + audioIO = new MacOutputDevice(audioBuffer, this); + + // Init + if (AudioUnitInitialize(audioUnit)) { + qWarning() << "QAudioOutput: Failed to initialize AudioUnit"; + return false; + } + + isOpen = true; + + return true; +} + +void QAudioOutputPrivate::close() +{ + if (audioUnit != 0) { + AudioOutputUnitStop(audioUnit); + AudioUnitUninitialize(audioUnit); + CloseComponent(audioUnit); + } + + delete audioBuffer; +} + +QAudioFormat QAudioOutputPrivate::format() const +{ + return audioFormat; +} + +QIODevice* QAudioOutputPrivate::start(QIODevice* device) +{ + QIODevice* op = device; + + if (!audioFormat.isValid() || !open()) { + stateCode = QAudio::StoppedState; + errorCode = QAudio::OpenError; + return audioIO; + } + + reset(); + audioBuffer->reset(); + audioBuffer->setPrefetchDevice(op); + + if (op == 0) { + op = audioIO; + stateCode = QAudio::IdleState; + } + else + stateCode = QAudio::ActiveState; + + // Start + errorCode = QAudio::NoError; + totalFrames = 0; + startTime = AudioGetCurrentHostTime(); + + if (stateCode == QAudio::ActiveState) + audioThreadStart(); + + emit stateChanged(stateCode); + + return op; +} + +void QAudioOutputPrivate::stop() +{ + QMutexLocker lock(&mutex); + if (stateCode != QAudio::StoppedState) { + audioThreadDrain(); + + stateCode = QAudio::StoppedState; + errorCode = QAudio::NoError; + QMetaObject::invokeMethod(this, "stateChanged", Qt::QueuedConnection, Q_ARG(QAudio::State, stateCode)); + } +} + +void QAudioOutputPrivate::reset() +{ + QMutexLocker lock(&mutex); + if (stateCode != QAudio::StoppedState) { + audioThreadStop(); + + stateCode = QAudio::StoppedState; + errorCode = QAudio::NoError; + QMetaObject::invokeMethod(this, "stateChanged", Qt::QueuedConnection, Q_ARG(QAudio::State, stateCode)); + } +} + +void QAudioOutputPrivate::suspend() +{ + QMutexLocker lock(&mutex); + if (stateCode == QAudio::ActiveState || stateCode == QAudio::IdleState) { + audioThreadStop(); + + stateCode = QAudio::SuspendedState; + errorCode = QAudio::NoError; + QMetaObject::invokeMethod(this, "stateChanged", Qt::QueuedConnection, Q_ARG(QAudio::State, stateCode)); + } +} + +void QAudioOutputPrivate::resume() +{ + QMutexLocker lock(&mutex); + if (stateCode == QAudio::SuspendedState) { + audioThreadStart(); + + stateCode = QAudio::ActiveState; + errorCode = QAudio::NoError; + QMetaObject::invokeMethod(this, "stateChanged", Qt::QueuedConnection, Q_ARG(QAudio::State, stateCode)); + } +} + +int QAudioOutputPrivate::bytesFree() const +{ + return audioBuffer->available(); +} + +int QAudioOutputPrivate::periodSize() const +{ + return periodSizeBytes; +} + +void QAudioOutputPrivate::setBufferSize(int bs) +{ + if (stateCode == QAudio::StoppedState) + internalBufferSize = bs; +} + +int QAudioOutputPrivate::bufferSize() const +{ + return internalBufferSize; +} + +void QAudioOutputPrivate::setNotifyInterval(int milliSeconds) +{ + if (intervalTimer->interval() == milliSeconds) + return; + + if (milliSeconds <= 0) + milliSeconds = 0; + + intervalTimer->setInterval(milliSeconds); +} + +int QAudioOutputPrivate::notifyInterval() const +{ + return intervalTimer->interval(); +} + +qint64 QAudioOutputPrivate::processedUSecs() const +{ + return totalFrames * 1000000 / audioFormat.frequency(); +} + +qint64 QAudioOutputPrivate::elapsedUSecs() const +{ + if (stateCode == QAudio::StoppedState) + return 0; + + return (AudioGetCurrentHostTime() - startTime) / (clockFrequency / 1000); +} + +QAudio::Error QAudioOutputPrivate::error() const +{ + return errorCode; +} + +QAudio::State QAudioOutputPrivate::state() const +{ + return stateCode; +} + +void QAudioOutputPrivate::audioThreadStart() +{ + startTimers(); + audioThreadState = Running; + AudioOutputUnitStart(audioUnit); +} + +void QAudioOutputPrivate::audioThreadStop() +{ + stopTimers(); + if (audioThreadState.testAndSetAcquire(Running, Stopped)) + threadFinished.wait(&mutex); +} + +void QAudioOutputPrivate::audioThreadDrain() +{ + stopTimers(); + if (audioThreadState.testAndSetAcquire(Running, Draining)) + threadFinished.wait(&mutex); +} + +void QAudioOutputPrivate::audioDeviceStop() +{ + AudioOutputUnitStop(audioUnit); + audioThreadState = Stopped; + threadFinished.wakeOne(); +} + +void QAudioOutputPrivate::audioDeviceIdle() +{ + QMutexLocker lock(&mutex); + if (stateCode == QAudio::ActiveState) { + audioDeviceStop(); + + errorCode = QAudio::UnderrunError; + stateCode = QAudio::IdleState; + QMetaObject::invokeMethod(this, "deviceStopped", Qt::QueuedConnection); + } +} + +void QAudioOutputPrivate::audioDeviceError() +{ + QMutexLocker lock(&mutex); + if (stateCode == QAudio::ActiveState) { + audioDeviceStop(); + + errorCode = QAudio::IOError; + stateCode = QAudio::StoppedState; + QMetaObject::invokeMethod(this, "deviceStopped", Qt::QueuedConnection); + } +} + +void QAudioOutputPrivate::startTimers() +{ + audioBuffer->startFillTimer(); + if (intervalTimer->interval() > 0) + intervalTimer->start(); +} + +void QAudioOutputPrivate::stopTimers() +{ + audioBuffer->stopFillTimer(); + intervalTimer->stop(); +} + + +void QAudioOutputPrivate::deviceStopped() +{ + intervalTimer->stop(); + emit stateChanged(stateCode); +} + +void QAudioOutputPrivate::inputReady() +{ + QMutexLocker lock(&mutex); + if (stateCode == QAudio::IdleState) { + audioThreadStart(); + + stateCode = QAudio::ActiveState; + errorCode = QAudio::NoError; + + QMetaObject::invokeMethod(this, "stateChanged", Qt::QueuedConnection, Q_ARG(QAudio::State, stateCode)); + } +} + + +OSStatus QAudioOutputPrivate::renderCallback(void* inRefCon, + AudioUnitRenderActionFlags* ioActionFlags, + const AudioTimeStamp* inTimeStamp, + UInt32 inBusNumber, + UInt32 inNumberFrames, + AudioBufferList* ioData) +{ + Q_UNUSED(ioActionFlags) + Q_UNUSED(inTimeStamp) + Q_UNUSED(inBusNumber) + Q_UNUSED(inNumberFrames) + + QAudioOutputPrivate* d = static_cast(inRefCon); + + const int threadState = d->audioThreadState.fetchAndAddAcquire(0); + if (threadState == Stopped) { + ioData->mBuffers[0].mDataByteSize = 0; + d->audioDeviceStop(); + } + else { + const UInt32 bytesPerFrame = d->streamFormat.mBytesPerFrame; + qint64 framesRead; + + framesRead = d->audioBuffer->readFrames((char*)ioData->mBuffers[0].mData, + ioData->mBuffers[0].mDataByteSize / bytesPerFrame); + + if (framesRead > 0) { + ioData->mBuffers[0].mDataByteSize = framesRead * bytesPerFrame; + d->totalFrames += framesRead; + } + else { + ioData->mBuffers[0].mDataByteSize = 0; + if (framesRead == 0) { + if (threadState == Draining) + d->audioDeviceStop(); + else + d->audioDeviceIdle(); + } + else + d->audioDeviceError(); + } + } + + return noErr; +} + + +QT_END_NAMESPACE + +#include "qaudiooutput_mac_p.moc" + diff --git a/src/multimedia/multimedia/audio/qaudiooutput_mac_p.h b/src/multimedia/multimedia/audio/qaudiooutput_mac_p.h new file mode 100644 index 0000000..752905c --- /dev/null +++ b/src/multimedia/multimedia/audio/qaudiooutput_mac_p.h @@ -0,0 +1,167 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtMultimedia module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists for the convenience +// of other Qt classes. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#ifndef QAUDIOOUTPUT_MAC_P_H +#define QAUDIOOUTPUT_MAC_P_H + +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#include +#include +#include + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +class QIODevice; + +namespace QtMultimediaInternal +{ +class QAudioOutputBuffer; +} + +class QAudioOutputPrivate : public QAbstractAudioOutput +{ + Q_OBJECT + +public: + bool isOpen; + int internalBufferSize; + int periodSizeBytes; + qint64 totalFrames; + QAudioFormat audioFormat; + QIODevice* audioIO; + AudioDeviceID audioDeviceId; + AudioUnit audioUnit; + Float64 clockFrequency; + UInt64 startTime; + AudioStreamBasicDescription deviceFormat; + AudioStreamBasicDescription streamFormat; + QtMultimediaInternal::QAudioOutputBuffer* audioBuffer; + QAtomicInt audioThreadState; + QWaitCondition threadFinished; + QMutex mutex; + QTimer* intervalTimer; + + QAudio::Error errorCode; + QAudio::State stateCode; + + QAudioOutputPrivate(const QByteArray& device, const QAudioFormat& format); + ~QAudioOutputPrivate(); + + bool open(); + void close(); + + QAudioFormat format() const; + + QIODevice* start(QIODevice* device); + void stop(); + void reset(); + void suspend(); + void resume(); + + int bytesFree() const; + int periodSize() const; + + void setBufferSize(int value); + int bufferSize() const; + + void setNotifyInterval(int milliSeconds); + int notifyInterval() const; + + qint64 processedUSecs() const; + qint64 elapsedUSecs() const; + + QAudio::Error error() const; + QAudio::State state() const; + + void audioThreadStart(); + void audioThreadStop(); + void audioThreadDrain(); + + void audioDeviceStop(); + void audioDeviceIdle(); + void audioDeviceError(); + + void startTimers(); + void stopTimers(); + +private slots: + void deviceStopped(); + void inputReady(); + +private: + enum { Running, Draining, Stopped }; + + static OSStatus renderCallback(void* inRefCon, + AudioUnitRenderActionFlags* ioActionFlags, + const AudioTimeStamp* inTimeStamp, + UInt32 inBusNumber, + UInt32 inNumberFrames, + AudioBufferList* ioData); +}; + +QT_END_NAMESPACE + +QT_END_HEADER + +#endif diff --git a/src/multimedia/multimedia/audio/qaudiooutput_symbian_p.cpp b/src/multimedia/multimedia/audio/qaudiooutput_symbian_p.cpp new file mode 100644 index 0000000..3f8e933 --- /dev/null +++ b/src/multimedia/multimedia/audio/qaudiooutput_symbian_p.cpp @@ -0,0 +1,697 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtMultimedia module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qaudiooutput_symbian_p.h" + +QT_BEGIN_NAMESPACE + +//----------------------------------------------------------------------------- +// Constants +//----------------------------------------------------------------------------- + +const int UnderflowTimerInterval = 50; // ms + + +//----------------------------------------------------------------------------- +// Private class +//----------------------------------------------------------------------------- + +SymbianAudioOutputPrivate::SymbianAudioOutputPrivate( + QAudioOutputPrivate *audioDevice) + : m_audioDevice(audioDevice) +{ + +} + +SymbianAudioOutputPrivate::~SymbianAudioOutputPrivate() +{ + +} + +qint64 SymbianAudioOutputPrivate::readData(char *data, qint64 len) +{ + Q_UNUSED(data) + Q_UNUSED(len) + return 0; +} + +qint64 SymbianAudioOutputPrivate::writeData(const char *data, qint64 len) +{ + qint64 totalWritten = 0; + + if (m_audioDevice->state() == QAudio::ActiveState || + m_audioDevice->state() == QAudio::IdleState) { + + while (totalWritten < len) { + const qint64 written = m_audioDevice->pushData(data + totalWritten, + len - totalWritten); + if (written > 0) + totalWritten += written; + else + break; + } + } + + return totalWritten; +} + + +//----------------------------------------------------------------------------- +// Public functions +//----------------------------------------------------------------------------- + +QAudioOutputPrivate::QAudioOutputPrivate(const QByteArray &device, + const QAudioFormat &format) + : m_device(device) + , m_format(format) + , m_clientBufferSize(SymbianAudio::DefaultBufferSize) + , m_notifyInterval(SymbianAudio::DefaultNotifyInterval) + , m_notifyTimer(new QTimer(this)) + , m_error(QAudio::NoError) + , m_internalState(SymbianAudio::ClosedState) + , m_externalState(QAudio::StoppedState) + , m_pullMode(false) + , m_source(0) + , m_devSoundBuffer(0) + , m_devSoundBufferSize(0) + , m_bytesWritten(0) + , m_pushDataReady(false) + , m_bytesPadding(0) + , m_underflow(false) + , m_lastBuffer(false) + , m_underflowTimer(new QTimer(this)) + , m_samplesPlayed(0) + , m_totalSamplesPlayed(0) +{ + connect(m_notifyTimer.data(), SIGNAL(timeout()), this, SIGNAL(notify())); + + SymbianAudio::Utils::formatQtToNative(m_format, m_nativeFourCC, + m_nativeFormat); + + m_underflowTimer->setInterval(UnderflowTimerInterval); + connect(m_underflowTimer.data(), SIGNAL(timeout()), this, + SLOT(underflowTimerExpired())); +} + +QAudioOutputPrivate::~QAudioOutputPrivate() +{ + close(); +} + +QIODevice* QAudioOutputPrivate::start(QIODevice *device) +{ + stop(); + + // We have to set these before the call to open() because of the + // logic in initializingState() + if (device) { + m_pullMode = true; + m_source = device; + } + + open(); + + if (SymbianAudio::ClosedState != m_internalState) { + if (device) { + connect(m_source, SIGNAL(readyRead()), this, SLOT(dataReady())); + } else { + m_source = new SymbianAudioOutputPrivate(this); + m_source->open(QIODevice::WriteOnly | QIODevice::Unbuffered); + } + + m_elapsed.restart(); + } + + return m_source; +} + +void QAudioOutputPrivate::stop() +{ + close(); +} + +void QAudioOutputPrivate::reset() +{ + m_totalSamplesPlayed += getSamplesPlayed(); + m_devSound->Stop(); + m_bytesPadding = 0; + startPlayback(); +} + +void QAudioOutputPrivate::suspend() +{ + if (SymbianAudio::ActiveState == m_internalState + || SymbianAudio::IdleState == m_internalState) { + m_notifyTimer->stop(); + m_underflowTimer->stop(); + + const qint64 samplesWritten = SymbianAudio::Utils::bytesToSamples( + m_format, m_bytesWritten); + + const qint64 samplesPlayed = getSamplesPlayed(); + + m_bytesWritten = 0; + + // CMMFDevSound::Pause() is not guaranteed to work correctly in all + // implementations, for play-mode DevSound sessions. We therefore + // have to implement suspend() by calling CMMFDevSound::Stop(). + // Because this causes buffered data to be dropped, we replace the + // lost data with silence following a call to resume(), in order to + // ensure that processedUSecs() returns the correct value. + m_devSound->Stop(); + m_totalSamplesPlayed += samplesPlayed; + + // Calculate the amount of data dropped + const qint64 paddingSamples = samplesWritten - samplesPlayed; + m_bytesPadding = SymbianAudio::Utils::samplesToBytes(m_format, + paddingSamples); + + setState(SymbianAudio::SuspendedState); + } +} + +void QAudioOutputPrivate::resume() +{ + if (SymbianAudio::SuspendedState == m_internalState) + startPlayback(); +} + +int QAudioOutputPrivate::bytesFree() const +{ + int result = 0; + if (m_devSoundBuffer) { + const TDes8 &outputBuffer = m_devSoundBuffer->Data(); + result = outputBuffer.MaxLength() - outputBuffer.Length(); + } + return result; +} + +int QAudioOutputPrivate::periodSize() const +{ + return bufferSize(); +} + +void QAudioOutputPrivate::setBufferSize(int value) +{ + // Note that DevSound does not allow its client to specify the buffer size. + // This functionality is available via custom interfaces, but since these + // cannot be guaranteed to work across all DevSound implementations, we + // do not use them here. + // In order to comply with the expected bevahiour of QAudioOutput, we store + // the value and return it from bufferSize(), but the underlying DevSound + // buffer size remains unchanged. + if (value > 0) + m_clientBufferSize = value; +} + +int QAudioOutputPrivate::bufferSize() const +{ + return m_devSoundBufferSize ? m_devSoundBufferSize : m_clientBufferSize; +} + +void QAudioOutputPrivate::setNotifyInterval(int ms) +{ + if (ms > 0) { + const int oldNotifyInterval = m_notifyInterval; + m_notifyInterval = ms; + if (m_notifyTimer->isActive() && ms != oldNotifyInterval) + m_notifyTimer->start(m_notifyInterval); + } +} + +int QAudioOutputPrivate::notifyInterval() const +{ + return m_notifyInterval; +} + +qint64 QAudioOutputPrivate::processedUSecs() const +{ + int samplesPlayed = 0; + if (m_devSound && SymbianAudio::SuspendedState != m_internalState) + samplesPlayed = getSamplesPlayed(); + + // Protect against division by zero + Q_ASSERT_X(m_format.frequency() > 0, Q_FUNC_INFO, "Invalid frequency"); + + const qint64 result = qint64(1000000) * + (samplesPlayed + m_totalSamplesPlayed) + / m_format.frequency(); + + return result; +} + +qint64 QAudioOutputPrivate::elapsedUSecs() const +{ + const qint64 result = (QAudio::StoppedState == state()) ? + 0 : m_elapsed.elapsed() * 1000; + return result; +} + +QAudio::Error QAudioOutputPrivate::error() const +{ + return m_error; +} + +QAudio::State QAudioOutputPrivate::state() const +{ + return m_externalState; +} + +QAudioFormat QAudioOutputPrivate::format() const +{ + return m_format; +} + +//----------------------------------------------------------------------------- +// MDevSoundObserver implementation +//----------------------------------------------------------------------------- + +void QAudioOutputPrivate::InitializeComplete(TInt aError) +{ + Q_ASSERT_X(SymbianAudio::InitializingState == m_internalState, + Q_FUNC_INFO, "Invalid state"); + + if (KErrNone == aError) + startPlayback(); +} + +void QAudioOutputPrivate::ToneFinished(TInt aError) +{ + Q_UNUSED(aError) + // This class doesn't use DevSound's tone playback functions, so should + // never receive this callback. + Q_ASSERT_X(false, Q_FUNC_INFO, "Unexpected callback"); +} + +void QAudioOutputPrivate::BufferToBeFilled(CMMFBuffer *aBuffer) +{ + // Following receipt of this callback, DevSound should not provide another + // buffer until we have returned the current one. + Q_ASSERT_X(!m_devSoundBuffer, Q_FUNC_INFO, "Buffer already held"); + + // Will be returned to DevSound by bufferFilled(). + m_devSoundBuffer = static_cast(aBuffer); + + if (!m_devSoundBufferSize) + m_devSoundBufferSize = m_devSoundBuffer->Data().MaxLength(); + + writePaddingData(); + + if (m_pullMode && isDataReady() && !m_bytesPadding) + pullData(); +} + +void QAudioOutputPrivate::PlayError(TInt aError) +{ + switch (aError) { + case KErrUnderflow: + m_underflow = true; + if (m_pullMode && !m_lastBuffer) + setError(QAudio::UnderrunError); + else + setState(SymbianAudio::IdleState); + break; + default: + setError(QAudio::IOError); + break; + } +} + +void QAudioOutputPrivate::BufferToBeEmptied(CMMFBuffer *aBuffer) +{ + Q_UNUSED(aBuffer) + // This class doesn't use DevSound in record mode, so should never receive + // this callback. + Q_ASSERT_X(false, Q_FUNC_INFO, "Unexpected callback"); +} + +void QAudioOutputPrivate::RecordError(TInt aError) +{ + Q_UNUSED(aError) + // This class doesn't use DevSound in record mode, so should never receive + // this callback. + Q_ASSERT_X(false, Q_FUNC_INFO, "Unexpected callback"); +} + +void QAudioOutputPrivate::ConvertError(TInt aError) +{ + Q_UNUSED(aError) + // This class doesn't use DevSound's format conversion functions, so + // should never receive this callback. + Q_ASSERT_X(false, Q_FUNC_INFO, "Unexpected callback"); +} + +void QAudioOutputPrivate::DeviceMessage(TUid aMessageType, const TDesC8 &aMsg) +{ + Q_UNUSED(aMessageType) + Q_UNUSED(aMsg) + // Ignore this callback. +} + +//----------------------------------------------------------------------------- +// Private functions +//----------------------------------------------------------------------------- + +void QAudioOutputPrivate::dataReady() +{ + // Client-provided QIODevice has data ready to read. + + Q_ASSERT_X(m_source->bytesAvailable(), Q_FUNC_INFO, + "readyRead signal received, but no data available"); + + if (!m_bytesPadding) + pullData(); +} + +void QAudioOutputPrivate::underflowTimerExpired() +{ + const TInt samplesPlayed = getSamplesPlayed(); + if (m_samplesPlayed && (samplesPlayed == m_samplesPlayed)) { + setError(QAudio::UnderrunError); + } else { + m_samplesPlayed = samplesPlayed; + m_underflowTimer->start(); + } +} + +void QAudioOutputPrivate::open() +{ + Q_ASSERT_X(SymbianAudio::ClosedState == m_internalState, + Q_FUNC_INFO, "DevSound already opened"); + + QT_TRAP_THROWING( m_devSound.reset(CMMFDevSound::NewL()) ) + + QScopedPointer caps( + new SymbianAudio::DevSoundCapabilities(*m_devSound, + QAudio::AudioOutput)); + + int err = SymbianAudio::Utils::isFormatSupported(m_format, *caps) ? + KErrNone : KErrNotSupported; + + if (KErrNone == err) { + setState(SymbianAudio::InitializingState); + TRAP(err, m_devSound->InitializeL(*this, m_nativeFourCC, + EMMFStatePlaying)); + } + + if (KErrNone != err) { + setError(QAudio::OpenError); + m_devSound.reset(); + } +} + +void QAudioOutputPrivate::startPlayback() +{ + TRAPD(err, startDevSoundL()); + if (KErrNone == err) { + if (isDataReady()) + setState(SymbianAudio::ActiveState); + else + setState(SymbianAudio::IdleState); + + m_notifyTimer->start(m_notifyInterval); + m_underflow = false; + + Q_ASSERT(m_devSound->SamplesPlayed() == 0); + + writePaddingData(); + + if (m_pullMode && m_source->bytesAvailable() && !m_bytesPadding) + dataReady(); + } else { + setError(QAudio::OpenError); + close(); + } +} + +void QAudioOutputPrivate::startDevSoundL() +{ + TMMFCapabilities nativeFormat = m_devSound->Config(); + m_nativeFormat.iBufferSize = nativeFormat.iBufferSize; + m_devSound->SetConfigL(m_nativeFormat); + m_devSound->PlayInitL(); +} + +void QAudioOutputPrivate::writePaddingData() +{ + // See comments in suspend() + + while (m_devSoundBuffer && m_bytesPadding) { + if (SymbianAudio::IdleState == m_internalState) + setState(SymbianAudio::ActiveState); + + TDes8 &outputBuffer = m_devSoundBuffer->Data(); + const qint64 outputBytes = bytesFree(); + const qint64 paddingBytes = outputBytes < m_bytesPadding ? + outputBytes : m_bytesPadding; + unsigned char *ptr = const_cast(outputBuffer.Ptr()); + Mem::FillZ(ptr, paddingBytes); + outputBuffer.SetLength(outputBuffer.Length() + paddingBytes); + m_bytesPadding -= paddingBytes; + + if (m_pullMode && m_source->atEnd()) + lastBufferFilled(); + if (paddingBytes == outputBytes) + bufferFilled(); + } +} + +qint64 QAudioOutputPrivate::pushData(const char *data, qint64 len) +{ + // Data has been written to SymbianAudioOutputPrivate + + Q_ASSERT_X(!m_pullMode, Q_FUNC_INFO, + "pushData called when in pull mode"); + + const unsigned char *const inputPtr = + reinterpret_cast(data); + qint64 bytesWritten = 0; + + if (SymbianAudio::IdleState == m_internalState) + setState(SymbianAudio::ActiveState); + + while (m_devSoundBuffer && (bytesWritten < len)) { + // writePaddingData() is called from BufferToBeFilled(), so we should + // never have any padding data left at this point. + Q_ASSERT_X(0 == m_bytesPadding, Q_FUNC_INFO, + "Padding bytes remaining in pushData"); + + TDes8 &outputBuffer = m_devSoundBuffer->Data(); + + const qint64 outputBytes = bytesFree(); + const qint64 inputBytes = len - bytesWritten; + const qint64 copyBytes = outputBytes < inputBytes ? + outputBytes : inputBytes; + + outputBuffer.Append(inputPtr + bytesWritten, copyBytes); + bytesWritten += copyBytes; + + bufferFilled(); + } + + m_pushDataReady = (bytesWritten < len); + + // If DevSound is still initializing (m_internalState == InitializingState), + // we cannot transition m_internalState to ActiveState, but we must emit + // an (external) state change from IdleState to ActiveState. The following + // call triggers this signal. + setState(m_internalState); + + return bytesWritten; +} + +void QAudioOutputPrivate::pullData() +{ + Q_ASSERT_X(m_pullMode, Q_FUNC_INFO, + "pullData called when in push mode"); + + if (m_bytesPadding) + m_bytesPadding = 1; + + // writePaddingData() is called by BufferToBeFilled() before pullData(), + // so we should never have any padding data left at this point. + Q_ASSERT_X(0 == m_bytesPadding, Q_FUNC_INFO, + "Padding bytes remaining in pullData"); + + qint64 inputBytes = m_source->bytesAvailable(); + while (m_devSoundBuffer && inputBytes) { + if (SymbianAudio::IdleState == m_internalState) + setState(SymbianAudio::ActiveState); + + TDes8 &outputBuffer = m_devSoundBuffer->Data(); + + const qint64 outputBytes = bytesFree(); + const qint64 copyBytes = outputBytes < inputBytes ? + outputBytes : inputBytes; + + char *outputPtr = (char*)(outputBuffer.Ptr() + outputBuffer.Length()); + const qint64 bytesCopied = m_source->read(outputPtr, copyBytes); + Q_ASSERT(bytesCopied == copyBytes); + outputBuffer.SetLength(outputBuffer.Length() + bytesCopied); + inputBytes -= bytesCopied; + + if (m_source->atEnd()) + lastBufferFilled(); + else if (copyBytes == outputBytes) + bufferFilled(); + } +} + +void QAudioOutputPrivate::bufferFilled() +{ + Q_ASSERT_X(m_devSoundBuffer, Q_FUNC_INFO, "No buffer to return"); + + const TDes8 &outputBuffer = m_devSoundBuffer->Data(); + m_bytesWritten += outputBuffer.Length(); + + m_devSoundBuffer = 0; + + m_samplesPlayed = getSamplesPlayed(); + m_underflowTimer->start(); + + if (QAudio::UnderrunError == m_error) + m_error = QAudio::NoError; + + m_devSound->PlayData(); +} + +void QAudioOutputPrivate::lastBufferFilled() +{ + Q_ASSERT_X(m_devSoundBuffer, Q_FUNC_INFO, "No buffer to fill"); + Q_ASSERT_X(!m_lastBuffer, Q_FUNC_INFO, "Last buffer already sent"); + m_lastBuffer = true; + m_devSoundBuffer->SetLastBuffer(ETrue); + bufferFilled(); +} + +void QAudioOutputPrivate::close() +{ + m_notifyTimer->stop(); + m_underflowTimer->stop(); + + m_error = QAudio::NoError; + + if (m_devSound) + m_devSound->Stop(); + m_devSound.reset(); + m_devSoundBuffer = 0; + m_devSoundBufferSize = 0; + + if (!m_pullMode) // m_source is owned + delete m_source; + m_pullMode = false; + m_source = 0; + + m_bytesWritten = 0; + m_pushDataReady = false; + m_bytesPadding = 0; + m_underflow = false; + m_lastBuffer = false; + m_samplesPlayed = 0; + m_totalSamplesPlayed = 0; + + setState(SymbianAudio::ClosedState); +} + +qint64 QAudioOutputPrivate::getSamplesPlayed() const +{ + qint64 result = 0; + if (m_devSound) { + const qint64 samplesWritten = SymbianAudio::Utils::bytesToSamples( + m_format, m_bytesWritten); + + if (m_underflow) { + result = samplesWritten; + } else { + // This is necessary because some DevSound implementations report + // that they have played more data than has actually been provided to them + // by the client. + const qint64 devSoundSamplesPlayed(m_devSound->SamplesPlayed()); + result = qMin(devSoundSamplesPlayed, samplesWritten); + } + } + return result; +} + +void QAudioOutputPrivate::setError(QAudio::Error error) +{ + m_error = error; + + // Although no state transition actually occurs here, a stateChanged event + // must be emitted to inform the client that the call to start() was + // unsuccessful. + if (QAudio::OpenError == error) + emit stateChanged(QAudio::StoppedState); + + if (QAudio::UnderrunError == error) + setState(SymbianAudio::IdleState); + else + // Close the DevSound instance. This causes a transition to + // StoppedState. This must be done asynchronously in case the + // current function was called from a DevSound event handler, in which + // case deleting the DevSound instance may cause an exception. + QMetaObject::invokeMethod(this, "close", Qt::QueuedConnection); +} + +void QAudioOutputPrivate::setState(SymbianAudio::State newInternalState) +{ + const QAudio::State oldExternalState = m_externalState; + m_internalState = newInternalState; + m_externalState = SymbianAudio::Utils::stateNativeToQt( + m_internalState, initializingState()); + + if (m_externalState != oldExternalState) + emit stateChanged(m_externalState); +} + +bool QAudioOutputPrivate::isDataReady() const +{ + return (m_source && m_source->bytesAvailable()) + || m_bytesPadding + || m_pushDataReady; +} + +QAudio::State QAudioOutputPrivate::initializingState() const +{ + return isDataReady() ? QAudio::ActiveState : QAudio::IdleState; +} + +QT_END_NAMESPACE diff --git a/src/multimedia/multimedia/audio/qaudiooutput_symbian_p.h b/src/multimedia/multimedia/audio/qaudiooutput_symbian_p.h new file mode 100644 index 0000000..00ccb24 --- /dev/null +++ b/src/multimedia/multimedia/audio/qaudiooutput_symbian_p.h @@ -0,0 +1,210 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtMultimedia module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists for the convenience +// of other Qt classes. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#ifndef QAUDIOOUTPUT_SYMBIAN_P_H +#define QAUDIOOUTPUT_SYMBIAN_P_H + +#include +#include +#include +#include +#include "qaudio_symbian_p.h" + +QT_BEGIN_NAMESPACE + +class QAudioOutputPrivate; + +class SymbianAudioOutputPrivate : public QIODevice +{ + friend class QAudioOutputPrivate; + Q_OBJECT +public: + SymbianAudioOutputPrivate(QAudioOutputPrivate *audio); + ~SymbianAudioOutputPrivate(); + + qint64 readData(char *data, qint64 len); + qint64 writeData(const char *data, qint64 len); + +private: + QAudioOutputPrivate *const m_audioDevice; +}; + +class QAudioOutputPrivate + : public QAbstractAudioOutput + , public MDevSoundObserver +{ + friend class SymbianAudioOutputPrivate; + Q_OBJECT +public: + QAudioOutputPrivate(const QByteArray &device, + const QAudioFormat &audioFormat); + ~QAudioOutputPrivate(); + + // QAbstractAudioOutput + QIODevice* start(QIODevice *device = 0); + void stop(); + void reset(); + void suspend(); + void resume(); + int bytesFree() const; + int periodSize() const; + void setBufferSize(int value); + int bufferSize() const; + void setNotifyInterval(int milliSeconds); + int notifyInterval() const; + qint64 processedUSecs() const; + qint64 elapsedUSecs() const; + QAudio::Error error() const; + QAudio::State state() const; + QAudioFormat format() const; + + // MDevSoundObserver + void InitializeComplete(TInt aError); + void ToneFinished(TInt aError); + void BufferToBeFilled(CMMFBuffer *aBuffer); + void PlayError(TInt aError); + void BufferToBeEmptied(CMMFBuffer *aBuffer); + void RecordError(TInt aError); + void ConvertError(TInt aError); + void DeviceMessage(TUid aMessageType, const TDesC8 &aMsg); + +private slots: + void dataReady(); + void underflowTimerExpired(); + +private: + void open(); + void startPlayback(); + void startDevSoundL(); + void writePaddingData(); + qint64 pushData(const char *data, qint64 len); + void pullData(); + void bufferFilled(); + void lastBufferFilled(); + Q_INVOKABLE void close(); + + qint64 getSamplesPlayed() const; + + void setError(QAudio::Error error); + void setState(SymbianAudio::State state); + + bool isDataReady() const; + QAudio::State initializingState() const; + +private: + const QByteArray m_device; + const QAudioFormat m_format; + + int m_clientBufferSize; + int m_notifyInterval; + QScopedPointer m_notifyTimer; + QTime m_elapsed; + QAudio::Error m_error; + + SymbianAudio::State m_internalState; + QAudio::State m_externalState; + + bool m_pullMode; + QIODevice *m_source; + + QScopedPointer m_devSound; + TUint32 m_nativeFourCC; + TMMFCapabilities m_nativeFormat; + + // Buffer provided by DevSound, to be filled with data. + CMMFDataBuffer *m_devSoundBuffer; + + int m_devSoundBufferSize; + + // Number of bytes transferred from QIODevice to QAudioOutput. It is + // necessary to count this because data is dropped when suspend() is + // called. The difference between the position reported by DevSound and + // this value allows us to calculate m_bytesPadding; + quint32 m_bytesWritten; + + // True if client has provided data while the audio subsystem was not + // ready to consume it. + bool m_pushDataReady; + + // Number of zero bytes which will be written when client calls resume(). + quint32 m_bytesPadding; + + // True if PlayError(KErrUnderflow) has been called. + bool m_underflow; + + // True if a buffer marked with the "last buffer" flag has been provided + // to DevSound. + bool m_lastBuffer; + + // Some DevSound implementations ignore all underflow errors raised by the + // audio driver, unless the last buffer flag has been set by the client. + // In push-mode playback, this flag will never be set, so the underflow + // error will never be reported. In order to work around this, a timer + // is used, which gets reset every time the client provides more data. If + // the timer expires, an underflow error is raised by this object. + QScopedPointer m_underflowTimer; + + // Result of previous call to CMMFDevSound::SamplesPlayed(). This value is + // used to determine whether, when m_underflowTimer expires, an + // underflow error has actually occurred. + quint32 m_samplesPlayed; + + // Samples played up to the last call to suspend(). It is necessary + // to cache this because suspend() is implemented using + // CMMFDevSound::Stop(), which resets DevSound's SamplesPlayed() counter. + quint32 m_totalSamplesPlayed; + +}; + +QT_END_NAMESPACE + +#endif diff --git a/src/multimedia/multimedia/audio/qaudiooutput_win32_p.cpp b/src/multimedia/multimedia/audio/qaudiooutput_win32_p.cpp new file mode 100644 index 0000000..13bce58 --- /dev/null +++ b/src/multimedia/multimedia/audio/qaudiooutput_win32_p.cpp @@ -0,0 +1,606 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtMultimedia module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists for the convenience +// of other Qt classes. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include "qaudiooutput_win32_p.h" + +//#define DEBUG_AUDIO 1 + +QT_BEGIN_NAMESPACE + +static const int minimumIntervalTime = 50; + +QAudioOutputPrivate::QAudioOutputPrivate(const QByteArray &device, const QAudioFormat& audioFormat): + settings(audioFormat) +{ + bytesAvailable = 0; + buffer_size = 0; + period_size = 0; + m_device = device; + totalTimeValue = 0; + intervalTime = 1000; + audioBuffer = 0; + errorState = QAudio::NoError; + deviceState = QAudio::StoppedState; + audioSource = 0; + pullMode = true; + finished = false; + InitializeCriticalSection(&waveOutCriticalSection); +} + +QAudioOutputPrivate::~QAudioOutputPrivate() +{ + EnterCriticalSection(&waveOutCriticalSection); + finished = true; + LeaveCriticalSection(&waveOutCriticalSection); + + close(); + DeleteCriticalSection(&waveOutCriticalSection); +} + +void CALLBACK QAudioOutputPrivate::waveOutProc( HWAVEOUT hWaveOut, UINT uMsg, + DWORD dwInstance, DWORD dwParam1, DWORD dwParam2 ) +{ + Q_UNUSED(dwParam1) + Q_UNUSED(dwParam2) + Q_UNUSED(hWaveOut) + + QAudioOutputPrivate* qAudio; + qAudio = (QAudioOutputPrivate*)(dwInstance); + if(!qAudio) + return; + + switch(uMsg) { + case WOM_OPEN: + qAudio->feedback(); + break; + case WOM_CLOSE: + return; + case WOM_DONE: + EnterCriticalSection(&qAudio->waveOutCriticalSection); + if(qAudio->finished || qAudio->buffer_size == 0 || qAudio->period_size == 0) { + LeaveCriticalSection(&qAudio->waveOutCriticalSection); + return; + } + qAudio->waveFreeBlockCount++; + if(qAudio->waveFreeBlockCount >= qAudio->buffer_size/qAudio->period_size) + qAudio->waveFreeBlockCount = qAudio->buffer_size/qAudio->period_size; + qAudio->feedback(); + LeaveCriticalSection(&qAudio->waveOutCriticalSection); + break; + default: + return; + } +} + +WAVEHDR* QAudioOutputPrivate::allocateBlocks(int size, int count) +{ + int i; + unsigned char* buffer; + WAVEHDR* blocks; + DWORD totalBufferSize = (size + sizeof(WAVEHDR))*count; + + if((buffer=(unsigned char*)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY, + totalBufferSize)) == 0) { + qWarning("QAudioOutput: Memory allocation error"); + return 0; + } + blocks = (WAVEHDR*)buffer; + buffer += sizeof(WAVEHDR)*count; + for(i = 0; i < count; i++) { + blocks[i].dwBufferLength = size; + blocks[i].lpData = (LPSTR)buffer; + buffer += size; + } + return blocks; +} + +void QAudioOutputPrivate::freeBlocks(WAVEHDR* blockArray) +{ + WAVEHDR* blocks = blockArray; + + int count = buffer_size/period_size; + + for(int i = 0; i < count; i++) { + waveOutUnprepareHeader(hWaveOut,&blocks[i], sizeof(WAVEHDR)); + blocks+=sizeof(WAVEHDR); + } + HeapFree(GetProcessHeap(), 0, blockArray); +} + +QAudioFormat QAudioOutputPrivate::format() const +{ + return settings; +} + +QIODevice* QAudioOutputPrivate::start(QIODevice* device) +{ + if(deviceState != QAudio::StoppedState) + close(); + + if(!pullMode && audioSource) { + delete audioSource; + } + + if(device) { + //set to pull mode + pullMode = true; + audioSource = device; + deviceState = QAudio::ActiveState; + } else { + //set to push mode + pullMode = false; + audioSource = new OutputPrivate(this); + audioSource->open(QIODevice::WriteOnly|QIODevice::Unbuffered); + deviceState = QAudio::IdleState; + } + + if( !open() ) + return 0; + + emit stateChanged(deviceState); + + return audioSource; +} + +void QAudioOutputPrivate::stop() +{ + if(deviceState == QAudio::StoppedState) + return; + close(); + if(!pullMode && audioSource) { + delete audioSource; + audioSource = 0; + } + emit stateChanged(deviceState); +} + +bool QAudioOutputPrivate::open() +{ +#ifdef DEBUG_AUDIO + QTime now(QTime::currentTime()); + qDebug()<= 8000 && settings.frequency() <= 48000)) { + errorState = QAudio::OpenError; + deviceState = QAudio::StoppedState; + emit stateChanged(deviceState); + qWarning("QAudioOutput: open error, frequency out of range."); + return false; + } + if(buffer_size == 0) { + // Default buffer size, 200ms, default period size is 40ms + buffer_size = settings.frequency()*settings.channels()*(settings.sampleSize()/8)*0.2; + period_size = buffer_size/5; + } else { + period_size = buffer_size/5; + } + waveBlocks = allocateBlocks(period_size, buffer_size/period_size); + + EnterCriticalSection(&waveOutCriticalSection); + waveFreeBlockCount = buffer_size/period_size; + LeaveCriticalSection(&waveOutCriticalSection); + + waveCurrentBlock = 0; + + if(audioBuffer == 0) + audioBuffer = new char[buffer_size]; + + timeStamp.restart(); + elapsedTimeOffset = 0; + + wfx.nSamplesPerSec = settings.frequency(); + wfx.wBitsPerSample = settings.sampleSize(); + wfx.nChannels = settings.channels(); + wfx.cbSize = 0; + + wfx.wFormatTag = WAVE_FORMAT_PCM; + wfx.nBlockAlign = (wfx.wBitsPerSample >> 3) * wfx.nChannels; + wfx.nAvgBytesPerSec = wfx.nBlockAlign * wfx.nSamplesPerSec; + + UINT_PTR devId = WAVE_MAPPER; + + WAVEOUTCAPS woc; + unsigned long iNumDevs,ii; + iNumDevs = waveOutGetNumDevs(); + for(ii=0;ii= minimumIntervalTime) + intervalTime = ms; + else + intervalTime = minimumIntervalTime; +} + +int QAudioOutputPrivate::notifyInterval() const +{ + return intervalTime; +} + +qint64 QAudioOutputPrivate::processedUSecs() const +{ + if (deviceState == QAudio::StoppedState) + return 0; + qint64 result = qint64(1000000) * totalTimeValue / + (settings.channels()*(settings.sampleSize()/8)) / + settings.frequency(); + + return result; +} + +qint64 QAudioOutputPrivate::write( const char *data, qint64 len ) +{ + // Write out some audio data + if (deviceState != QAudio::ActiveState && deviceState != QAudio::IdleState) + return 0; + + char* p = (char*)data; + int l = (int)len; + + WAVEHDR* current; + int remain; + current = &waveBlocks[waveCurrentBlock]; + while(l > 0) { + EnterCriticalSection(&waveOutCriticalSection); + if(waveFreeBlockCount==0) { + LeaveCriticalSection(&waveOutCriticalSection); + break; + } + LeaveCriticalSection(&waveOutCriticalSection); + + if(current->dwFlags & WHDR_PREPARED) + waveOutUnprepareHeader(hWaveOut, current, sizeof(WAVEHDR)); + + if(l < period_size) + remain = l; + else + remain = period_size; + memcpy(current->lpData, p, remain); + + l -= remain; + p += remain; + current->dwBufferLength = remain; + waveOutPrepareHeader(hWaveOut, current, sizeof(WAVEHDR)); + waveOutWrite(hWaveOut, current, sizeof(WAVEHDR)); + + EnterCriticalSection(&waveOutCriticalSection); + waveFreeBlockCount--; + LeaveCriticalSection(&waveOutCriticalSection); +#ifdef DEBUG_AUDIO + EnterCriticalSection(&waveOutCriticalSection); + qDebug("write out l=%d, waveFreeBlockCount=%d", + current->dwBufferLength,waveFreeBlockCount); + LeaveCriticalSection(&waveOutCriticalSection); +#endif + totalTimeValue += current->dwBufferLength; + waveCurrentBlock++; + waveCurrentBlock %= buffer_size/period_size; + current = &waveBlocks[waveCurrentBlock]; + current->dwUser = 0; + errorState = QAudio::NoError; + if (deviceState != QAudio::ActiveState) { + deviceState = QAudio::ActiveState; + emit stateChanged(deviceState); + } + } + return (len-l); +} + +void QAudioOutputPrivate::resume() +{ + if(deviceState == QAudio::SuspendedState) { + deviceState = QAudio::ActiveState; + errorState = QAudio::NoError; + waveOutRestart(hWaveOut); + QTimer::singleShot(10, this, SLOT(feedback())); + emit stateChanged(deviceState); + } +} + +void QAudioOutputPrivate::suspend() +{ + if(deviceState == QAudio::ActiveState || deviceState == QAudio::IdleState) { + int delay = (buffer_size-bytesFree())*1000/(settings.frequency() + *settings.channels()*(settings.sampleSize()/8)); + waveOutPause(hWaveOut); + Sleep(delay+10); + deviceState = QAudio::SuspendedState; + errorState = QAudio::NoError; + emit stateChanged(deviceState); + } +} + +void QAudioOutputPrivate::feedback() +{ +#ifdef DEBUG_AUDIO + QTime now(QTime::currentTime()); + qDebug()<= period_size) + QMetaObject::invokeMethod(this, "deviceReady", Qt::QueuedConnection); + } +} + +bool QAudioOutputPrivate::deviceReady() +{ + if(deviceState == QAudio::StoppedState) + return false; + + if(pullMode) { + int chunks = bytesAvailable/period_size; +#ifdef DEBUG_AUDIO + qDebug()<<"deviceReady() avail="< intervalTime ) { + emit notify(); + elapsedTimeOffset = timeStamp.elapsed() + elapsedTimeOffset - intervalTime; + timeStamp.restart(); + } + return true; + } + + if(startup) + waveOutPause(hWaveOut); + int input = period_size*chunks; + int l = audioSource->read(audioBuffer,input); + if(l > 0) { + int out= write(audioBuffer,l); + if(out > 0) { + if (deviceState != QAudio::ActiveState) { + deviceState = QAudio::ActiveState; + emit stateChanged(deviceState); + } + } + if ( out < l) { + // Didnt write all data + audioSource->seek(audioSource->pos()-(l-out)); + } + if(startup) + waveOutRestart(hWaveOut); + } else if(l == 0) { + bytesAvailable = bytesFree(); + + int check = 0; + EnterCriticalSection(&waveOutCriticalSection); + check = waveFreeBlockCount; + LeaveCriticalSection(&waveOutCriticalSection); + if(check == buffer_size/period_size) { + errorState = QAudio::UnderrunError; + if (deviceState != QAudio::IdleState) { + deviceState = QAudio::IdleState; + emit stateChanged(deviceState); + } + } + + } else if(l < 0) { + bytesAvailable = bytesFree(); + errorState = QAudio::IOError; + } + } else { + int buffered; + EnterCriticalSection(&waveOutCriticalSection); + buffered = waveFreeBlockCount; + LeaveCriticalSection(&waveOutCriticalSection); + errorState = QAudio::UnderrunError; + if (buffered >= buffer_size/period_size && deviceState == QAudio::ActiveState) { + deviceState = QAudio::IdleState; + emit stateChanged(deviceState); + } + } + if(deviceState != QAudio::ActiveState && deviceState != QAudio::IdleState) + return true; + + if((timeStamp.elapsed() + elapsedTimeOffset) > intervalTime) { + emit notify(); + elapsedTimeOffset = timeStamp.elapsed() + elapsedTimeOffset - intervalTime; + timeStamp.restart(); + } + + return true; +} + +qint64 QAudioOutputPrivate::elapsedUSecs() const +{ + if (deviceState == QAudio::StoppedState) + return 0; + + return timeStampOpened.elapsed()*1000; +} + +QAudio::Error QAudioOutputPrivate::error() const +{ + return errorState; +} + +QAudio::State QAudioOutputPrivate::state() const +{ + return deviceState; +} + +void QAudioOutputPrivate::reset() +{ + close(); +} + +OutputPrivate::OutputPrivate(QAudioOutputPrivate* audio) +{ + audioDevice = qobject_cast(audio); +} + +OutputPrivate::~OutputPrivate() {} + +qint64 OutputPrivate::readData( char* data, qint64 len) +{ + Q_UNUSED(data) + Q_UNUSED(len) + + return 0; +} + +qint64 OutputPrivate::writeData(const char* data, qint64 len) +{ + int retry = 0; + qint64 written = 0; + + if((audioDevice->deviceState == QAudio::ActiveState) + ||(audioDevice->deviceState == QAudio::IdleState)) { + qint64 l = len; + while(written < l) { + int chunk = audioDevice->write(data+written,(l-written)); + if(chunk <= 0) + retry++; + else + written+=chunk; + + if(retry > 10) + return written; + } + audioDevice->deviceState = QAudio::ActiveState; + } + return written; +} + +QT_END_NAMESPACE diff --git a/src/multimedia/multimedia/audio/qaudiooutput_win32_p.h b/src/multimedia/multimedia/audio/qaudiooutput_win32_p.h new file mode 100644 index 0000000..68a40f7 --- /dev/null +++ b/src/multimedia/multimedia/audio/qaudiooutput_win32_p.h @@ -0,0 +1,156 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtMultimedia module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists for the convenience +// of other Qt classes. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#ifndef QAUDIOOUTPUTWIN_H +#define QAUDIOOUTPUTWIN_H + +#include +#include + +#include +#include +#include +#include +#include + +#include +#include +#include + + +QT_BEGIN_NAMESPACE + +class QAudioOutputPrivate : public QAbstractAudioOutput +{ + Q_OBJECT +public: + QAudioOutputPrivate(const QByteArray &device, const QAudioFormat& audioFormat); + ~QAudioOutputPrivate(); + + qint64 write( const char *data, qint64 len ); + + QAudioFormat format() const; + QIODevice* start(QIODevice* device = 0); + void stop(); + void reset(); + void suspend(); + void resume(); + int bytesFree() const; + int periodSize() const; + void setBufferSize(int value); + int bufferSize() const; + void setNotifyInterval(int milliSeconds); + int notifyInterval() const; + qint64 processedUSecs() const; + qint64 elapsedUSecs() const; + QAudio::Error error() const; + QAudio::State state() const; + + QIODevice* audioSource; + QAudioFormat settings; + QAudio::Error errorState; + QAudio::State deviceState; + +private slots: + void feedback(); + bool deviceReady(); + +private: + QByteArray m_device; + bool resuming; + int bytesAvailable; + QTime timeStamp; + qint64 elapsedTimeOffset; + QTime timeStampOpened; + qint32 buffer_size; + qint32 period_size; + qint64 totalTimeValue; + bool pullMode; + int intervalTime; + static void QT_WIN_CALLBACK waveOutProc( HWAVEOUT hWaveOut, UINT uMsg, + DWORD dwInstance, DWORD dwParam1, DWORD dwParam2 ); + + CRITICAL_SECTION waveOutCriticalSection; + + WAVEHDR* allocateBlocks(int size, int count); + void freeBlocks(WAVEHDR* blockArray); + bool open(); + void close(); + + WAVEFORMATEX wfx; + HWAVEOUT hWaveOut; + MMRESULT result; + WAVEHDR header; + WAVEHDR* waveBlocks; + volatile bool finished; + volatile int waveFreeBlockCount; + int waveCurrentBlock; + char* audioBuffer; +}; + +class OutputPrivate : public QIODevice +{ + Q_OBJECT +public: + OutputPrivate(QAudioOutputPrivate* audio); + ~OutputPrivate(); + + qint64 readData( char* data, qint64 len); + qint64 writeData(const char* data, qint64 len); + +private: + QAudioOutputPrivate *audioDevice; +}; + +QT_END_NAMESPACE + +#endif diff --git a/src/multimedia/multimedia/multimedia.pro b/src/multimedia/multimedia/multimedia.pro new file mode 100644 index 0000000..8d130bd --- /dev/null +++ b/src/multimedia/multimedia/multimedia.pro @@ -0,0 +1,14 @@ +TARGET = QtMultimedia +QPRO_PWD = $$PWD +QT = core gui + +DEFINES += QT_BUILD_MULTIMEDIA_LIB QT_NO_USING_NAMESPACE + +unix:QMAKE_PKGCONFIG_REQUIRES = QtCore QtGui + +include(../../qbase.pri) + +include(audio/audio.pri) +include(video/video.pri) + +symbian: TARGET.UID3 = 0x2001E627 diff --git a/src/multimedia/multimedia/video/qabstractvideobuffer.cpp b/src/multimedia/multimedia/video/qabstractvideobuffer.cpp new file mode 100644 index 0000000..e9d30d0 --- /dev/null +++ b/src/multimedia/multimedia/video/qabstractvideobuffer.cpp @@ -0,0 +1,200 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtMultimedia module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qabstractvideobuffer_p.h" + +#include + +QT_BEGIN_NAMESPACE + +/*! + \class QAbstractVideoBuffer + \brief The QAbstractVideoBuffer class is an abstraction for video data. + \since 4.6 + + The QVideoFrame class makes use of a QAbstractVideoBuffer internally to reference a buffer of + video data. Creating a subclass of QAbstractVideoBuffer will allow you to construct video + frames from preallocated or static buffers. + + The contents of a buffer can be accessed by mapping the buffer to memory using the map() + function which returns a pointer to memory containing the contents of the the video buffer. + The memory returned by map() is released by calling the unmap() function. + + The handle() of a buffer may also be used to manipulate it's contents using type specific APIs. + The type of a buffer's handle is given by the handleType() function. + + \sa QVideoFrame +*/ + +/*! + \enum QAbstractVideoBuffer::HandleType + + Identifies the type of a video buffers handle. + + \value NoHandle The buffer has no handle, its data can only be accessed by mapping the buffer. + \value GLTextureHandle The handle of the buffer is an OpenGL texture ID. + \value XvShmImageHandle The handle contains pointer to shared memory XVideo image. + \value CoreImageHandle The handle contains pointer to Mac OS X CIImage. + \value UserHandle Start value for user defined handle types. + + \sa handleType() +*/ + +/*! + \enum QAbstractVideoBuffer::MapMode + + Enumerates how a video buffer's data is mapped to memory. + + \value NotMapped The video buffer has is not mapped to memory. + \value ReadOnly The mapped memory is populated with data from the video buffer when mapped, but + the content of the mapped memory may be discarded when unmapped. + \value WriteOnly The mapped memory in unitialized when mapped, and the content will be used to + populate the video buffer when unmapped. + \value ReadWrite The mapped memory is populated with data from the video buffer, and the + video buffer is repopulated with the content of the mapped memory. + + \sa mapMode(), map() +*/ + +/*! + Constructs an abstract video buffer of the given \a type. +*/ + +QAbstractVideoBuffer::QAbstractVideoBuffer(HandleType type) + : d_ptr(new QAbstractVideoBufferPrivate) +{ + Q_D(QAbstractVideoBuffer); + + d->handleType = type; +} + +/*! + \internal +*/ + +QAbstractVideoBuffer::QAbstractVideoBuffer(QAbstractVideoBufferPrivate &dd, HandleType type) + : d_ptr(&dd) +{ + Q_D(QAbstractVideoBuffer); + + d->handleType = type; +} + +/*! + Destroys an abstract video buffer. +*/ + +QAbstractVideoBuffer::~QAbstractVideoBuffer() +{ + delete d_ptr; +} + +/*! + Returns the type of a video buffer's handle. + + \sa handle() +*/ + +QAbstractVideoBuffer::HandleType QAbstractVideoBuffer::handleType() const +{ + return d_func()->handleType; +} + +/*! + \fn QAbstractVideoBuffer::mapMode() const + + Returns the mode a video buffer is mapped in. + + \sa map() +*/ + +/*! + \fn QAbstractVideoBuffer::map(MapMode mode, int *numBytes, int *bytesPerLine) + + Maps the contents of a video buffer to memory. + + The map \a mode indicates whether the contents of the mapped memory should be read from and/or + written to the buffer. If the map mode includes the QAbstractVideoBuffer::ReadOnly flag the + mapped memory will be populated with the content of the video buffer when mapped. If the map + mode includes the QAbstractVideoBuffer::WriteOnly flag the content of the mapped memory will be + persisted in the buffer when unmapped. + + When access to the data is no longer needed be sure to call the unmap() function to release the + mapped memory. + + Returns a pointer to the mapped memory region, or a null pointer if the mapping failed. The + size in bytes of the mapped memory region is returned in \a numBytes, and the line stride in \a + bytesPerLine. + + When access to the data is no longer needed be sure to unmap() the buffer. + + \note Writing to memory that is mapped as read-only is undefined, and may result in changes + to shared data. + + \sa unmap(), mapMode() +*/ + +/*! + \fn QAbstractVideoBuffer::unmap() + + Releases the memory mapped by the map() function + + If the \l {QAbstractVideoBuffer::MapMode}{MapMode} included the QAbstractVideoBuffer::WriteOnly + flag this will persist the current content of the mapped memory to the video frame. + + \sa map() +*/ + +/*! + Returns a type specific handle to the data buffer. + + The type of the handle is given by handleType() function. + + \sa handleType() +*/ + +QVariant QAbstractVideoBuffer::handle() const +{ + return QVariant(); +} + + +QT_END_NAMESPACE diff --git a/src/multimedia/multimedia/video/qabstractvideobuffer.h b/src/multimedia/multimedia/video/qabstractvideobuffer.h new file mode 100644 index 0000000..a8389db --- /dev/null +++ b/src/multimedia/multimedia/video/qabstractvideobuffer.h @@ -0,0 +1,106 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtMultimedia module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QABSTRACTVIDEOBUFFER_H +#define QABSTRACTVIDEOBUFFER_H + +#include + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Multimedia) + +class QVariant; + +class QAbstractVideoBufferPrivate; + +class Q_MULTIMEDIA_EXPORT QAbstractVideoBuffer +{ +public: + enum HandleType + { + NoHandle, + GLTextureHandle, + XvShmImageHandle, + CoreImageHandle, + UserHandle = 1000 + }; + + enum MapMode + { + NotMapped = 0x00, + ReadOnly = 0x01, + WriteOnly = 0x02, + ReadWrite = ReadOnly | WriteOnly + }; + + QAbstractVideoBuffer(HandleType type); + virtual ~QAbstractVideoBuffer(); + + HandleType handleType() const; + + virtual MapMode mapMode() const = 0; + + virtual uchar *map(MapMode mode, int *numBytes, int *bytesPerLine) = 0; + virtual void unmap() = 0; + + virtual QVariant handle() const; + +protected: + QAbstractVideoBuffer(QAbstractVideoBufferPrivate &dd, HandleType type); + + QAbstractVideoBufferPrivate *d_ptr; + +private: + Q_DECLARE_PRIVATE(QAbstractVideoBuffer) + Q_DISABLE_COPY(QAbstractVideoBuffer) +}; + +QT_END_NAMESPACE + +Q_DECLARE_METATYPE(QAbstractVideoBuffer::HandleType) +Q_DECLARE_METATYPE(QAbstractVideoBuffer::MapMode) + +QT_END_HEADER + +#endif diff --git a/src/multimedia/multimedia/video/qabstractvideobuffer_p.h b/src/multimedia/multimedia/video/qabstractvideobuffer_p.h new file mode 100644 index 0000000..c72f303 --- /dev/null +++ b/src/multimedia/multimedia/video/qabstractvideobuffer_p.h @@ -0,0 +1,73 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtMultimedia module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QABSTRACTVIDEOBUFFER_P_H +#define QABSTRACTVIDEOBUFFER_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include +#include + +QT_BEGIN_NAMESPACE + +class QAbstractVideoBufferPrivate +{ +public: + QAbstractVideoBufferPrivate() + : handleType(QAbstractVideoBuffer::NoHandle) + {} + + QAbstractVideoBuffer::HandleType handleType; +}; + +QT_END_NAMESPACE + +#endif diff --git a/src/multimedia/multimedia/video/qabstractvideosurface.cpp b/src/multimedia/multimedia/video/qabstractvideosurface.cpp new file mode 100644 index 0000000..3dabb6b --- /dev/null +++ b/src/multimedia/multimedia/video/qabstractvideosurface.cpp @@ -0,0 +1,283 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtMultimedia module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qabstractvideosurface_p.h" + +QT_BEGIN_NAMESPACE + +/*! + \class QAbstractVideoSurface + \brief The QAbstractVideoSurface class is a base class for video presentation surfaces. + \since 4.6 + + The QAbstractVideoSurface class defines the standard interface that video producers use to + inter-operate with video presentation surfaces. It is not supposed to be instantiated directly. + Instead, you should subclass it to create new video surfaces. + + A video surface presents a continuous stream of identically formatted frames, where the format + of each frame is compatible with a stream format supplied when starting a presentation. + + A list of pixel formats a surface can present is given by the supportedPixelFormats() function, + and the isFormatSupported() function will test if a video surface format is supported. If a + format is not supported the nearestFormat() function may be able to suggest a similar format. + For example if a surface supports fixed set of resolutions it may suggest the smallest + supported resolution that contains the proposed resolution. + + The start() function takes a supported format and enables a video surface. Once started a + surface will begin displaying the frames it receives in the present() function. Surfaces may + hold a reference to the buffer of a presented video frame until a new frame is presented or + streaming is stopped. The stop() function will disable a surface and a release any video + buffers it holds references to. +*/ + +/*! + \enum QAbstractVideoSurface::Error + This enum describes the errors that may be returned by the error() function. + + \value NoError No error occurred. + \value UnsupportedFormatError A video format was not supported. + \value IncorrectFormatError A video frame was not compatible with the format of the surface. + \value StoppedError The surface has not been started. + \value ResourceError The surface could not allocate some resource. +*/ + +/*! + Constructs a video surface with the given \a parent. +*/ + +QAbstractVideoSurface::QAbstractVideoSurface(QObject *parent) + : QObject(*new QAbstractVideoSurfacePrivate, parent) +{ +} + +/*! + \internal +*/ + +QAbstractVideoSurface::QAbstractVideoSurface(QAbstractVideoSurfacePrivate &dd, QObject *parent) + : QObject(dd, parent) +{ +} + +/*! + Destroys a video surface. +*/ + +QAbstractVideoSurface::~QAbstractVideoSurface() +{ +} + +/*! + \fn QAbstractVideoSurface::supportedPixelFormats(QAbstractVideoBuffer::HandleType type) const + + Returns a list of pixel formats a video surface can present for a given handle \a type. + + The pixel formats returned for the QAbstractVideoBuffer::NoHandle type are valid for any buffer + that can be mapped in read-only mode. + + Types that are first in the list can be assumed to be faster to render. +*/ + +/*! + Tests a video surface \a format to determine if a surface can accept it. + + Returns true if the format is supported by the surface, and false otherwise. +*/ + +bool QAbstractVideoSurface::isFormatSupported(const QVideoSurfaceFormat &format) const +{ + return supportedPixelFormats(format.handleType()).contains(format.pixelFormat()); +} + +/*! + Returns a supported video surface format that is similar to \a format. + + A similar surface format is one that has the same \l {QVideoSurfaceFormat::pixelFormat()}{pixel + format} and \l {QVideoSurfaceFormat::handleType()}{handle type} but differs in some of the other + properties. For example if there are restrictions on the \l {QVideoSurfaceFormat::frameSize()} + {frame sizes} a video surface can accept it may suggest a format with a larger frame size and + a \l {QVideoSurfaceFormat::viewport()}{viewport} the size of the original frame size. + + If the format is already supported it will be returned unchanged, or if there is no similar + supported format an invalid format will be returned. +*/ + +QVideoSurfaceFormat QAbstractVideoSurface::nearestFormat(const QVideoSurfaceFormat &format) const +{ + return isFormatSupported(format) + ? format + : QVideoSurfaceFormat(); +} + +/*! + \fn QAbstractVideoSurface::supportedFormatsChanged() + + Signals that the set of formats supported by a video surface has changed. + + \sa supportedPixelFormats(), isFormatSupported() +*/ + +/*! + Returns the format of a video surface. +*/ + +QVideoSurfaceFormat QAbstractVideoSurface::surfaceFormat() const +{ + return d_func()->format; +} + +/*! + \fn QAbstractVideoSurface::surfaceFormatChanged(const QVideoSurfaceFormat &format) + + Signals that the configured \a format of a video surface has changed. + + \sa surfaceFormat(), start() +*/ + +/*! + Starts a video surface presenting \a format frames. + + Returns true if the surface was started, and false if an error occurred. + + \sa isActive(), stop() +*/ + +bool QAbstractVideoSurface::start(const QVideoSurfaceFormat &format) +{ + Q_D(QAbstractVideoSurface); + + bool wasActive = d->active; + + d->active = true; + d->format = format; + d->error = NoError; + + emit surfaceFormatChanged(d->format); + + if (!wasActive) + emit activeChanged(true); + + return true; +} + +/*! + Stops a video surface presenting frames and releases any resources acquired in start(). + + \sa isActive(), start() +*/ + +void QAbstractVideoSurface::stop() +{ + Q_D(QAbstractVideoSurface); + + if (d->active) { + d->format = QVideoSurfaceFormat(); + d->active = false; + + emit activeChanged(false); + emit surfaceFormatChanged(d->format); + } +} + +/*! + Indicates whether a video surface has been started. + + Returns true if the surface has been started, and false otherwise. +*/ + +bool QAbstractVideoSurface::isActive() const +{ + return d_func()->active; +} + +/*! + \fn QAbstractVideoSurface::activeChanged(bool active) + + Signals that the \a active state of a video surface has changed. + + \sa isActive(), start(), stop() +*/ + +/*! + \fn QAbstractVideoSurface::present(const QVideoFrame &frame) + + Presents a video \a frame. + + Returns true if the frame was presented, and false if an error occurred. + + Not all surfaces will block until the presentation of a frame has completed. Calling present() + on a non-blocking surface may fail if called before the presentation of a previous frame has + completed. In such cases the surface may not return to a ready state until it's had an + opportunity to process events. + + If present() fails for any other reason the surface will immediately enter the stopped state + and an error() value will be set. + + A video surface must be in the started state for present() to succeed, and the format of the + video frame must be compatible with the current video surface format. + + \sa error() +*/ + +/*! + Returns the last error that occurred. + + If a surface fails to start(), or stops unexpectedly this function can be called to discover + what error occurred. +*/ + +QAbstractVideoSurface::Error QAbstractVideoSurface::error() const +{ + return d_func()->error; +} + +/*! + Sets the value of error() to \a error. +*/ + +void QAbstractVideoSurface::setError(Error error) +{ + Q_D(QAbstractVideoSurface); + + d->error = error; +} + +QT_END_NAMESPACE diff --git a/src/multimedia/multimedia/video/qabstractvideosurface.h b/src/multimedia/multimedia/video/qabstractvideosurface.h new file mode 100644 index 0000000..f2cae17 --- /dev/null +++ b/src/multimedia/multimedia/video/qabstractvideosurface.h @@ -0,0 +1,110 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtMultimedia module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QABSTRACTVIDEOSURFACE_H +#define QABSTRACTVIDEOSURFACE_H + +#include +#include + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Multimedia) + +class QRectF; +class QVideoSurfaceFormat; + +class QAbstractVideoSurfacePrivate; + +class Q_MULTIMEDIA_EXPORT QAbstractVideoSurface : public QObject +{ + Q_OBJECT + +public: + enum Error + { + NoError, + UnsupportedFormatError, + IncorrectFormatError, + StoppedError, + ResourceError + }; + + explicit QAbstractVideoSurface(QObject *parent = 0); + ~QAbstractVideoSurface(); + + virtual QList supportedPixelFormats( + QAbstractVideoBuffer::HandleType handleType = QAbstractVideoBuffer::NoHandle) const = 0; + virtual bool isFormatSupported(const QVideoSurfaceFormat &format) const; + virtual QVideoSurfaceFormat nearestFormat(const QVideoSurfaceFormat &format) const; + + QVideoSurfaceFormat surfaceFormat() const; + + virtual bool start(const QVideoSurfaceFormat &format); + virtual void stop(); + + bool isActive() const; + + virtual bool present(const QVideoFrame &frame) = 0; + + Error error() const; + +Q_SIGNALS: + void activeChanged(bool active); + void surfaceFormatChanged(const QVideoSurfaceFormat &format); + void supportedFormatsChanged(); + +protected: + QAbstractVideoSurface(QAbstractVideoSurfacePrivate &dd, QObject *parent); + + void setError(Error error); + +private: + Q_DECLARE_PRIVATE(QAbstractVideoSurface) +}; + +QT_END_NAMESPACE + +QT_END_HEADER + +#endif diff --git a/src/multimedia/multimedia/video/qabstractvideosurface_p.h b/src/multimedia/multimedia/video/qabstractvideosurface_p.h new file mode 100644 index 0000000..42df112 --- /dev/null +++ b/src/multimedia/multimedia/video/qabstractvideosurface_p.h @@ -0,0 +1,78 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtMultimedia module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QABSTRACTVIDEOSURFACE_P_H +#define QABSTRACTVIDEOSURFACE_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include +#include +#include + +QT_BEGIN_NAMESPACE + +class QAbstractVideoSurfacePrivate : public QObjectPrivate +{ +public: + QAbstractVideoSurfacePrivate() + : error(QAbstractVideoSurface::NoError) + , active(false) + { + } + + mutable QAbstractVideoSurface::Error error; + QVideoSurfaceFormat format; + bool active; +}; + +QT_END_NAMESPACE + +#endif diff --git a/src/multimedia/multimedia/video/qimagevideobuffer.cpp b/src/multimedia/multimedia/video/qimagevideobuffer.cpp new file mode 100644 index 0000000..e3e1585 --- /dev/null +++ b/src/multimedia/multimedia/video/qimagevideobuffer.cpp @@ -0,0 +1,106 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtMultimedia module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qimagevideobuffer_p.h" + +#include + +#include +#include + +QT_BEGIN_NAMESPACE + +class QImageVideoBufferPrivate : public QAbstractVideoBufferPrivate +{ +public: + QImageVideoBufferPrivate() + : mapMode(QAbstractVideoBuffer::NotMapped) + { + } + + QAbstractVideoBuffer::MapMode mapMode; + QImage image; +}; + +QImageVideoBuffer::QImageVideoBuffer(const QImage &image) + : QAbstractVideoBuffer(*new QImageVideoBufferPrivate, NoHandle) +{ + Q_D(QImageVideoBuffer); + + d->image = image; +} + +QImageVideoBuffer::~QImageVideoBuffer() +{ +} + +QAbstractVideoBuffer::MapMode QImageVideoBuffer::mapMode() const +{ + return d_func()->mapMode; +} + +uchar *QImageVideoBuffer::map(MapMode mode, int *numBytes, int *bytesPerLine) +{ + Q_D(QImageVideoBuffer); + + if (d->mapMode == NotMapped && d->image.bits() && mode != NotMapped) { + d->mapMode = mode; + + if (numBytes) + *numBytes = d->image.byteCount(); + + if (bytesPerLine) + *bytesPerLine = d->image.bytesPerLine(); + + return d->image.bits(); + } else { + return 0; + } +} + +void QImageVideoBuffer::unmap() +{ + Q_D(QImageVideoBuffer); + + d->mapMode = NotMapped; +} + +QT_END_NAMESPACE diff --git a/src/multimedia/multimedia/video/qimagevideobuffer_p.h b/src/multimedia/multimedia/video/qimagevideobuffer_p.h new file mode 100644 index 0000000..82075d7 --- /dev/null +++ b/src/multimedia/multimedia/video/qimagevideobuffer_p.h @@ -0,0 +1,79 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtMultimedia module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QIMAGEVIDEOBUFFER_P_H +#define QIMAGEVIDEOBUFFER_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include + +QT_BEGIN_NAMESPACE + +class QImage; + +class QImageVideoBufferPrivate; + +class Q_MULTIMEDIA_EXPORT QImageVideoBuffer : public QAbstractVideoBuffer +{ + Q_DECLARE_PRIVATE(QImageVideoBuffer) +public: + QImageVideoBuffer(const QImage &image); + ~QImageVideoBuffer(); + + MapMode mapMode() const; + + uchar *map(MapMode mode, int *numBytes, int *bytesPerLine); + void unmap(); +}; + +QT_END_NAMESPACE + +#endif diff --git a/src/multimedia/multimedia/video/qmemoryvideobuffer.cpp b/src/multimedia/multimedia/video/qmemoryvideobuffer.cpp new file mode 100644 index 0000000..2e892b7 --- /dev/null +++ b/src/multimedia/multimedia/video/qmemoryvideobuffer.cpp @@ -0,0 +1,129 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtMultimedia module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qmemoryvideobuffer_p.h" + +#include +#include + +QT_BEGIN_NAMESPACE + +class QMemoryVideoBufferPrivate : public QAbstractVideoBufferPrivate +{ +public: + QMemoryVideoBufferPrivate() + : bytesPerLine(0) + , mapMode(QAbstractVideoBuffer::NotMapped) + { + } + + int bytesPerLine; + QAbstractVideoBuffer::MapMode mapMode; + QByteArray data; +}; + +/*! + \class QMemoryVideoBuffer + \brief The QMemoryVideoBuffer class provides a system memory allocated video data buffer. + \internal + + QMemoryVideoBuffer is the default video buffer for allocating system memory. It may be used to + allocate memory for a QVideoFrame without implementing your own QAbstractVideoBuffer. +*/ + +/*! + Constructs a video buffer with an image stride of \a bytesPerLine from a byte \a array. +*/ +QMemoryVideoBuffer::QMemoryVideoBuffer(const QByteArray &array, int bytesPerLine) + : QAbstractVideoBuffer(*new QMemoryVideoBufferPrivate, NoHandle) +{ + Q_D(QMemoryVideoBuffer); + + d->data = array; + d->bytesPerLine = bytesPerLine; +} + +/*! + Destroys a system memory allocated video buffer. +*/ +QMemoryVideoBuffer::~QMemoryVideoBuffer() +{ +} + +/*! + \reimp +*/ +QAbstractVideoBuffer::MapMode QMemoryVideoBuffer::mapMode() const +{ + return d_func()->mapMode; +} + +/*! + \reimp +*/ +uchar *QMemoryVideoBuffer::map(MapMode mode, int *numBytes, int *bytesPerLine) +{ + Q_D(QMemoryVideoBuffer); + + if (d->mapMode == NotMapped && d->data.data() && mode != NotMapped) { + d->mapMode = mode; + + if (numBytes) + *numBytes = d->data.size(); + + if (bytesPerLine) + *bytesPerLine = d->bytesPerLine; + + return reinterpret_cast(d->data.data()); + } else { + return 0; + } +} + +/*! + \reimp +*/ +void QMemoryVideoBuffer::unmap() +{ + d_func()->mapMode = NotMapped; +} + +QT_END_NAMESPACE diff --git a/src/multimedia/multimedia/video/qmemoryvideobuffer_p.h b/src/multimedia/multimedia/video/qmemoryvideobuffer_p.h new file mode 100644 index 0000000..c66cf93 --- /dev/null +++ b/src/multimedia/multimedia/video/qmemoryvideobuffer_p.h @@ -0,0 +1,83 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtMultimedia module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QMEMORYVIDEOBUFFER_P_H +#define QMEMORYVIDEOBUFFER_P_H + +#include + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Multimedia) + +class QMemoryVideoBufferPrivate; + +class Q_MULTIMEDIA_EXPORT QMemoryVideoBuffer : public QAbstractVideoBuffer +{ + Q_DECLARE_PRIVATE(QMemoryVideoBuffer) +public: + QMemoryVideoBuffer(const QByteArray &data, int bytesPerLine); + ~QMemoryVideoBuffer(); + + MapMode mapMode() const; + + uchar *map(MapMode mode, int *numBytes, int *bytesPerLine); + void unmap(); +}; + +QT_END_NAMESPACE + +QT_END_HEADER + +#endif diff --git a/src/multimedia/multimedia/video/qvideoframe.cpp b/src/multimedia/multimedia/video/qvideoframe.cpp new file mode 100644 index 0000000..2d66d9e --- /dev/null +++ b/src/multimedia/multimedia/video/qvideoframe.cpp @@ -0,0 +1,741 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtMultimedia module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qvideoframe.h" + +#include +#include + +#include +#include +#include +#include +#include + +QT_BEGIN_NAMESPACE + +class QVideoFramePrivate : public QSharedData +{ +public: + QVideoFramePrivate() + : startTime(-1) + , endTime(-1) + , data(0) + , mappedBytes(0) + , bytesPerLine(0) + , pixelFormat(QVideoFrame::Format_Invalid) + , fieldType(QVideoFrame::ProgressiveFrame) + , buffer(0) + { + } + + QVideoFramePrivate(const QSize &size, QVideoFrame::PixelFormat format) + : size(size) + , startTime(-1) + , endTime(-1) + , data(0) + , mappedBytes(0) + , bytesPerLine(0) + , pixelFormat(format) + , fieldType(QVideoFrame::ProgressiveFrame) + , buffer(0) + { + } + + ~QVideoFramePrivate() + { + delete buffer; + } + + QSize size; + qint64 startTime; + qint64 endTime; + uchar *data; + int mappedBytes; + int bytesPerLine; + QVideoFrame::PixelFormat pixelFormat; + QVideoFrame::FieldType fieldType; + QAbstractVideoBuffer *buffer; + +private: + Q_DISABLE_COPY(QVideoFramePrivate) +}; + +/*! + \class QVideoFrame + \brief The QVideoFrame class provides a representation of a frame of video data. + \since 4.6 + + A QVideoFrame encapsulates the data of a video frame, and information about the frame. + + The contents of a video frame can be mapped to memory using the map() function. While + mapped the video data can accessed using the bits() function which returns a pointer to a + buffer, the total size of which is given by the mappedBytes(), and the size of each line is given + by bytesPerLine(). The return value of the handle() function may be used to access frame data + using the internal buffer's native APIs. + + The video data in a QVideoFrame is encapsulated in a QAbstractVideoBuffer. A QVideoFrame + may be constructed from any buffer type by subclassing the QAbstractVideoBuffer class. + + \note QVideoFrame is explicitly shared, any change made to video frame will also apply to any + copies. +*/ + +/*! + \enum QVideoFrame::PixelFormat + + Enumerates video data types. + + \value Format_Invalid + The frame is invalid. + + \value Format_ARGB32 + The frame is stored using a 32-bit ARGB format (0xAARRGGBB). This is equivalent to + QImage::Format_ARGB32. + + \value Format_ARGB32_Premultiplied + The frame stored using a premultiplied 32-bit ARGB format (0xAARRGGBB). This is equivalent + to QImage::Format_ARGB32_Premultiplied. + + \value Format_RGB32 + The frame stored using a 32-bit RGB format (0xffRRGGBB). This is equivalent to + QImage::Format_RGB32 + + \value Format_RGB24 + The frame is stored using a 24-bit RGB format (8-8-8). This is equivalent to + QImage::Format_RGB888 + + \value Format_RGB565 + The frame is stored using a 16-bit RGB format (5-6-5). This is equivalent to + QImage::Format_RGB16. + + \value Format_RGB555 + The frame is stored using a 16-bit RGB format (5-5-5). This is equivalent to + QImage::Format_RGB555. + + \value Format_ARGB8565_Premultiplied + The frame is stored using a 24-bit premultiplied ARGB format (8-6-6-5). + + \value Format_BGRA32 + The frame is stored using a 32-bit ARGB format (0xBBGGRRAA). + + \value Format_BGRA32_Premultiplied + The frame is stored using a premultiplied 32bit BGRA format. + + \value Format_BGR32 + The frame is stored using a 32-bit BGR format (0xBBGGRRff). + + \value Format_BGR24 + The frame is stored using a 24-bit BGR format (0xBBGGRR). + + \value Format_BGR565 + The frame is stored using a 16-bit BGR format (5-6-5). + + \value Format_BGR555 + The frame is stored using a 16-bit BGR format (5-5-5). + + \value Format_BGRA5658_Premultiplied + The frame is stored using a 24-bit premultiplied BGRA format (5-6-5-8). + + \value Format_AYUV444 + The frame is stored using a packed 32-bit AYUV format (0xAAYYUUVV). + + \value Format_AYUV444_Premultiplied + The frame is stored using a packed premultiplied 32-bit AYUV format (0xAAYYUUVV). + + \value Format_YUV444 + The frame is stored using a 24-bit packed YUV format (8-8-8). + + \value Format_YUV420P + The frame is stored using an 8-bit per component planar YUV format with the U and V planes + horizontally and vertically sub-sampled, i.e. the height and width of the U and V planes are + half that of the Y plane. + + \value Format_YV12 + The frame is stored using an 8-bit per component planar YVU format with the V and U planes + horizontally and vertically sub-sampled, i.e. the height and width of the V and U planes are + half that of the Y plane. + + \value Format_UYVY + The frame is stored using an 8-bit per component packed YUV format with the U and V planes + horizontally sub-sampled (U-Y-V-Y), i.e. two horizontally adjacent pixels are stored as a 32-bit + macropixel which has a Y value for each pixel and common U and V values. + + \value Format_YUYV + The frame is stored using an 8-bit per component packed YUV format with the U and V planes + horizontally sub-sampled (Y-U-Y-V), i.e. two horizontally adjacent pixels are stored as a 32-bit + macropixel which has a Y value for each pixel and common U and V values. + + \value Format_NV12 + The frame is stored using an 8-bit per component semi-planar YUV format with a Y plane (Y) + followed by a horizontally and vertically sub-sampled, packed UV plane (U-V). + + \value Format_NV21 + The frame is stored using an 8-bit per component semi-planar YUV format with a Y plane (Y) + followed by a horizontally and vertically sub-sampled, packed VU plane (V-U). + + \value Format_IMC1 + The frame is stored using an 8-bit per component planar YUV format with the U and V planes + horizontally and vertically sub-sampled. This is similar to the Format_YUV420P type, except + that the bytes per line of the U and V planes are padded out to the same stride as the Y plane. + + \value Format_IMC2 + The frame is stored using an 8-bit per component planar YUV format with the U and V planes + horizontally and vertically sub-sampled. This is similar to the Format_YUV420P type, except + that the lines of the U and V planes are interleaved, i.e. each line of U data is followed by a + line of V data creating a single line of the same stride as the Y data. + + \value Format_IMC3 + The frame is stored using an 8-bit per component planar YVU format with the V and U planes + horizontally and vertically sub-sampled. This is similar to the Format_YV12 type, except that + the bytes per line of the V and U planes are padded out to the same stride as the Y plane. + + \value Format_IMC4 + The frame is stored using an 8-bit per component planar YVU format with the V and U planes + horizontally and vertically sub-sampled. This is similar to the Format_YV12 type, except that + the lines of the V and U planes are interleaved, i.e. each line of V data is followed by a line + of U data creating a single line of the same stride as the Y data. + + \value Format_Y8 + The frame is stored using an 8-bit greyscale format. + + \value Format_Y16 + The frame is stored using a 16-bit linear greyscale format. Little endian. + + \value Format_User + Start value for user defined pixel formats. +*/ + +/*! + \enum QVideoFrame::FieldType + + Specifies the field an interlaced video frame belongs to. + + \value ProgressiveFrame The frame is not interlaced. + \value TopField The frame contains a top field. + \value BottomField The frame contains a bottom field. + \value InterlacedFrame The frame contains a merged top and bottom field. +*/ + +/*! + Constructs a null video frame. +*/ + +QVideoFrame::QVideoFrame() + : d(new QVideoFramePrivate) +{ +} + +/*! + Constructs a video frame from a \a buffer of the given pixel \a format and \a size in pixels. + + \note This doesn't increment the reference count of the video buffer. +*/ + +QVideoFrame::QVideoFrame( + QAbstractVideoBuffer *buffer, const QSize &size, PixelFormat format) + : d(new QVideoFramePrivate(size, format)) +{ + d->buffer = buffer; +} + +/*! + Constructs a video frame of the given pixel \a format and \a size in pixels. + + The \a bytesPerLine (stride) is the length of each scan line in bytes, and \a bytes is the total + number of bytes that must be allocated for the frame. +*/ + +QVideoFrame::QVideoFrame(int bytes, const QSize &size, int bytesPerLine, PixelFormat format) + : d(new QVideoFramePrivate(size, format)) +{ + if (bytes > 0) { + QByteArray data; + data.resize(bytes); + + // Check the memory was successfully allocated. + if (!data.isEmpty()) + d->buffer = new QMemoryVideoBuffer(data, bytesPerLine); + } +} + +/*! + Constructs a video frame from an \a image. + + \note This will construct an invalid video frame if there is no frame type equivalent to the + image format. + + \sa pixelFormatFromImageFormat() +*/ + +QVideoFrame::QVideoFrame(const QImage &image) + : d(new QVideoFramePrivate( + image.size(), pixelFormatFromImageFormat(image.format()))) +{ + if (d->pixelFormat != Format_Invalid) + d->buffer = new QImageVideoBuffer(image); +} + +/*! + Constructs a copy of \a other. +*/ + +QVideoFrame::QVideoFrame(const QVideoFrame &other) + : d(other.d) +{ +} + +/*! + Assigns the contents of \a other to a video frame. +*/ + +QVideoFrame &QVideoFrame::operator =(const QVideoFrame &other) +{ + d = other.d; + + return *this; +} + +/*! + Destroys a video frame. +*/ + +QVideoFrame::~QVideoFrame() +{ +} + +/*! + Identifies whether a video frame is valid. + + An invalid frame has no video buffer associated with it. + + Returns true if the frame is valid, and false if it is not. +*/ + +bool QVideoFrame::isValid() const +{ + return d->buffer != 0; +} + +/*! + Returns the color format of a video frame. +*/ + +QVideoFrame::PixelFormat QVideoFrame::pixelFormat() const +{ + return d->pixelFormat; +} + +/*! + Returns the type of a video frame's handle. +*/ + +QAbstractVideoBuffer::HandleType QVideoFrame::handleType() const +{ + return d->buffer ? d->buffer->handleType() : QAbstractVideoBuffer::NoHandle; +} + +/*! + Returns the size of a video frame. +*/ + +QSize QVideoFrame::size() const +{ + return d->size; +} + +/*! + Returns the width of a video frame. +*/ + +int QVideoFrame::width() const +{ + return d->size.width(); +} + +/*! + Returns the height of a video frame. +*/ + +int QVideoFrame::height() const +{ + return d->size.height(); +} + +/*! + Returns the field an interlaced video frame belongs to. + + If the video is not interlaced this will return WholeFrame. +*/ + +QVideoFrame::FieldType QVideoFrame::fieldType() const +{ + return d->fieldType; +} + +/*! + Sets the \a field an interlaced video frame belongs to. +*/ + +void QVideoFrame::setFieldType(QVideoFrame::FieldType field) +{ + d->fieldType = field; +} + +/*! + Identifies if a video frame's contents are currently mapped to system memory. + + This is a convenience function which checks that the \l {QAbstractVideoBuffer::MapMode}{MapMode} + of the frame is not equal to QAbstractVideoBuffer::NotMapped. + + Returns true if the contents of the video frame are mapped to system memory, and false + otherwise. + + \sa mapMode() QAbstractVideoBuffer::MapMode +*/ + +bool QVideoFrame::isMapped() const +{ + return d->buffer != 0 && d->buffer->mapMode() != QAbstractVideoBuffer::NotMapped; +} + +/*! + Identifies if the mapped contents of a video frame will be persisted when the frame is unmapped. + + This is a convenience function which checks if the \l {QAbstractVideoBuffer::MapMode}{MapMode} + contains the QAbstractVideoBuffer::WriteOnly flag. + + Returns true if the video frame will be updated when unmapped, and false otherwise. + + \note The result of altering the data of a frame that is mapped in read-only mode is undefined. + Depending on the buffer implementation the changes may be persisted, or worse alter a shared + buffer. + + \sa mapMode(), QAbstractVideoBuffer::MapMode +*/ + +bool QVideoFrame::isWritable() const +{ + return d->buffer != 0 && (d->buffer->mapMode() & QAbstractVideoBuffer::WriteOnly); +} + +/*! + Identifies if the mapped contents of a video frame were read from the frame when it was mapped. + + This is a convenience function which checks if the \l {QAbstractVideoBuffer::MapMode}{MapMode} + contains the QAbstractVideoBuffer::WriteOnly flag. + + Returns true if the contents of the mapped memory were read from the video frame, and false + otherwise. + + \sa mapMode(), QAbstractVideoBuffer::MapMode +*/ + +bool QVideoFrame::isReadable() const +{ + return d->buffer != 0 && (d->buffer->mapMode() & QAbstractVideoBuffer::ReadOnly); +} + +/*! + Returns the mode a video frame was mapped to system memory in. + + \sa map(), QAbstractVideoBuffer::MapMode +*/ + +QAbstractVideoBuffer::MapMode QVideoFrame::mapMode() const +{ + return d->buffer != 0 ? d->buffer->mapMode() : QAbstractVideoBuffer::NotMapped; +} + +/*! + Maps the contents of a video frame to memory. + + The map \a mode indicates whether the contents of the mapped memory should be read from and/or + written to the frame. If the map mode includes the QAbstractVideoBuffer::ReadOnly flag the + mapped memory will be populated with the content of the video frame when mapped. If the map + mode inclues the QAbstractVideoBuffer::WriteOnly flag the content of the mapped memory will be + persisted in the frame when unmapped. + + While mapped the contents of a video frame can be accessed directly through the pointer returned + by the bits() function. + + When access to the data is no longer needed be sure to call the unmap() function to release the + mapped memory. + + Returns true if the buffer was mapped to memory in the given \a mode and false otherwise. + + \sa unmap(), mapMode(), bits() +*/ + +bool QVideoFrame::map(QAbstractVideoBuffer::MapMode mode) +{ + if (d->buffer != 0 && d->data == 0) { + Q_ASSERT(d->bytesPerLine == 0); + Q_ASSERT(d->mappedBytes == 0); + + d->data = d->buffer->map(mode, &d->mappedBytes, &d->bytesPerLine); + + return d->data != 0; + } + + return false; +} + +/*! + Releases the memory mapped by the map() function. + + If the \l {QAbstractVideoBuffer::MapMode}{MapMode} included the QAbstractVideoBuffer::WriteOnly + flag this will persist the current content of the mapped memory to the video frame. + + \sa map() +*/ + +void QVideoFrame::unmap() +{ + if (d->data != 0) { + d->mappedBytes = 0; + d->bytesPerLine = 0; + d->data = 0; + + d->buffer->unmap(); + } +} + +/*! + Returns the number of bytes in a scan line. + + \note This is the bytes per line of the first plane only. The bytes per line of subsequent + planes should be calculated as per the frame type. + + This value is only valid while the frame data is \l {map()}{mapped}. + + \sa bits(), map(), mappedBytes() +*/ + +int QVideoFrame::bytesPerLine() const +{ + return d->bytesPerLine; +} + +/*! + Returns a pointer to the start of the frame data buffer. + + This value is only valid while the frame data is \l {map()}{mapped}. + + \sa map(), mappedBytes(), bytesPerLine() +*/ + +uchar *QVideoFrame::bits() +{ + return d->data; +} + +/*! + Returns a pointer to the start of the frame data buffer. + + This value is only valid while the frame data is \l {map()}{mapped}. + + \sa map(), mappedBytes(), bytesPerLine() +*/ + +const uchar *QVideoFrame::bits() const +{ + return d->data; +} + +/*! + Returns the number of bytes occupied by the mapped frame data. + + This value is only valid while the frame data is \l {map()}{mapped}. + + \sa map() +*/ + +int QVideoFrame::mappedBytes() const +{ + return d->mappedBytes; +} + +/*! + Returns a type specific handle to a video frame's buffer. + + For an OpenGL texture this would be the texture ID. + + \sa QAbstractVideoBuffer::handle() +*/ + +QVariant QVideoFrame::handle() const +{ + return d->buffer != 0 ? d->buffer->handle() : QVariant(); +} + +/*! + Returns the presentation time when the frame should be displayed. +*/ + +qint64 QVideoFrame::startTime() const +{ + return d->startTime; +} + +/*! + Sets the presentation \a time when the frame should be displayed. +*/ + +void QVideoFrame::setStartTime(qint64 time) +{ + d->startTime = time; +} + +/*! + Returns the presentation time when a frame should stop being displayed. +*/ + +qint64 QVideoFrame::endTime() const +{ + return d->endTime; +} + +/*! + Sets the presentation \a time when a frame should stop being displayed. +*/ + +void QVideoFrame::setEndTime(qint64 time) +{ + d->endTime = time; +} + +/*! + Returns an video pixel format equivalent to an image \a format. If there is no equivalent + format QVideoFrame::InvalidType is returned instead. +*/ + +QVideoFrame::PixelFormat QVideoFrame::pixelFormatFromImageFormat(QImage::Format format) +{ + switch (format) { + case QImage::Format_Invalid: + case QImage::Format_Mono: + case QImage::Format_MonoLSB: + case QImage::Format_Indexed8: + return Format_Invalid; + case QImage::Format_RGB32: + return Format_RGB32; + case QImage::Format_ARGB32: + return Format_ARGB32; + case QImage::Format_ARGB32_Premultiplied: + return Format_ARGB32_Premultiplied; + case QImage::Format_RGB16: + return Format_RGB565; + case QImage::Format_ARGB8565_Premultiplied: + case QImage::Format_RGB666: + case QImage::Format_ARGB6666_Premultiplied: + return Format_Invalid; + case QImage::Format_RGB555: + return Format_RGB555; + case QImage::Format_ARGB8555_Premultiplied: + return Format_Invalid; + case QImage::Format_RGB888: + return Format_RGB24; + case QImage::Format_RGB444: + case QImage::Format_ARGB4444_Premultiplied: + return Format_Invalid; + case QImage::NImageFormats: + return Format_Invalid; + } + return Format_Invalid; +} + +/*! + Returns an image format equivalent to a video frame pixel \a format. If there is no equivalent + format QImage::Format_Invalid is returned instead. +*/ + +QImage::Format QVideoFrame::imageFormatFromPixelFormat(PixelFormat format) +{ + switch (format) { + case Format_Invalid: + return QImage::Format_Invalid; + case Format_ARGB32: + return QImage::Format_ARGB32; + case Format_ARGB32_Premultiplied: + return QImage::Format_ARGB32_Premultiplied; + case Format_RGB32: + return QImage::Format_RGB32; + case Format_RGB24: + return QImage::Format_RGB888; + case Format_RGB565: + return QImage::Format_RGB16; + case Format_RGB555: + return QImage::Format_RGB555; + case Format_ARGB8565_Premultiplied: + return QImage::Format_ARGB8565_Premultiplied; + case Format_BGRA32: + case Format_BGRA32_Premultiplied: + case Format_BGR32: + case Format_BGR24: + return QImage::Format_Invalid; + case Format_BGR565: + case Format_BGR555: + case Format_BGRA5658_Premultiplied: + case Format_AYUV444: + case Format_AYUV444_Premultiplied: + case Format_YUV444: + case Format_YUV420P: + case Format_YV12: + case Format_UYVY: + case Format_YUYV: + case Format_NV12: + case Format_NV21: + case Format_IMC1: + case Format_IMC2: + case Format_IMC3: + case Format_IMC4: + case Format_Y8: + case Format_Y16: + return QImage::Format_Invalid; + case Format_User: + return QImage::Format_Invalid; + } + return QImage::Format_Invalid; +} + +QT_END_NAMESPACE + diff --git a/src/multimedia/multimedia/video/qvideoframe.h b/src/multimedia/multimedia/video/qvideoframe.h new file mode 100644 index 0000000..668a738 --- /dev/null +++ b/src/multimedia/multimedia/video/qvideoframe.h @@ -0,0 +1,169 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtMultimedia module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QVIDEOFRAME_H +#define QVIDEOFRAME_H + +#include +#include +#include +#include + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Multimedia) + +class QSize; +class QVariant; + +class QVideoFramePrivate; + +class Q_MULTIMEDIA_EXPORT QVideoFrame +{ +public: + enum FieldType + { + ProgressiveFrame, + TopField, + BottomField, + InterlacedFrame + }; + + enum PixelFormat + { + Format_Invalid, + Format_ARGB32, + Format_ARGB32_Premultiplied, + Format_RGB32, + Format_RGB24, + Format_RGB565, + Format_RGB555, + Format_ARGB8565_Premultiplied, + Format_BGRA32, + Format_BGRA32_Premultiplied, + Format_BGR32, + Format_BGR24, + Format_BGR565, + Format_BGR555, + Format_BGRA5658_Premultiplied, + + Format_AYUV444, + Format_AYUV444_Premultiplied, + Format_YUV444, + Format_YUV420P, + Format_YV12, + Format_UYVY, + Format_YUYV, + Format_NV12, + Format_NV21, + Format_IMC1, + Format_IMC2, + Format_IMC3, + Format_IMC4, + Format_Y8, + Format_Y16, + + Format_User = 1000 + }; + + QVideoFrame(); + QVideoFrame(QAbstractVideoBuffer *buffer, const QSize &size, PixelFormat format); + QVideoFrame(int bytes, const QSize &size, int bytesPerLine, PixelFormat format); + QVideoFrame(const QImage &image); + QVideoFrame(const QVideoFrame &other); + ~QVideoFrame(); + + QVideoFrame &operator =(const QVideoFrame &other); + + bool isValid() const; + + PixelFormat pixelFormat() const; + + QAbstractVideoBuffer::HandleType handleType() const; + + QSize size() const; + int width() const; + int height() const; + + FieldType fieldType() const; + void setFieldType(FieldType); + + bool isMapped() const; + bool isReadable() const; + bool isWritable() const; + + QAbstractVideoBuffer::MapMode mapMode() const; + + bool map(QAbstractVideoBuffer::MapMode mode); + void unmap(); + + int bytesPerLine() const; + + uchar *bits(); + const uchar *bits() const; + int mappedBytes() const; + + QVariant handle() const; + + qint64 startTime() const; + void setStartTime(qint64 time); + + qint64 endTime() const; + void setEndTime(qint64 time); + + static PixelFormat pixelFormatFromImageFormat(QImage::Format format); + static QImage::Format imageFormatFromPixelFormat(PixelFormat format); + +private: + QExplicitlySharedDataPointer d; +}; + +QT_END_NAMESPACE + +Q_DECLARE_METATYPE(QVideoFrame::FieldType) +Q_DECLARE_METATYPE(QVideoFrame::PixelFormat) + +QT_END_HEADER + +#endif + diff --git a/src/multimedia/multimedia/video/qvideosurfaceformat.cpp b/src/multimedia/multimedia/video/qvideosurfaceformat.cpp new file mode 100644 index 0000000..1fc13a6 --- /dev/null +++ b/src/multimedia/multimedia/video/qvideosurfaceformat.cpp @@ -0,0 +1,704 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtMultimedia module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qvideosurfaceformat.h" + +#include +#include +#include +#include +#include + +QT_BEGIN_NAMESPACE + +class QVideoSurfaceFormatPrivate : public QSharedData +{ +public: + QVideoSurfaceFormatPrivate() + : pixelFormat(QVideoFrame::Format_Invalid) + , handleType(QAbstractVideoBuffer::NoHandle) + , scanLineDirection(QVideoSurfaceFormat::TopToBottom) + , pixelAspectRatio(1, 1) + , ycbcrColorSpace(QVideoSurfaceFormat::YCbCr_Undefined) + , frameRate(0.0) + { + } + + QVideoSurfaceFormatPrivate( + const QSize &size, + QVideoFrame::PixelFormat format, + QAbstractVideoBuffer::HandleType type) + : pixelFormat(format) + , handleType(type) + , scanLineDirection(QVideoSurfaceFormat::TopToBottom) + , frameSize(size) + , pixelAspectRatio(1, 1) + , ycbcrColorSpace(QVideoSurfaceFormat::YCbCr_Undefined) + , viewport(QPoint(0, 0), size) + , frameRate(0.0) + { + } + + QVideoSurfaceFormatPrivate(const QVideoSurfaceFormatPrivate &other) + : QSharedData(other) + , pixelFormat(other.pixelFormat) + , handleType(other.handleType) + , scanLineDirection(other.scanLineDirection) + , frameSize(other.frameSize) + , pixelAspectRatio(other.pixelAspectRatio) + , ycbcrColorSpace(other.ycbcrColorSpace) + , viewport(other.viewport) + , frameRate(other.frameRate) + , propertyNames(other.propertyNames) + , propertyValues(other.propertyValues) + { + } + + bool operator ==(const QVideoSurfaceFormatPrivate &other) const + { + if (pixelFormat == other.pixelFormat + && handleType == other.handleType + && scanLineDirection == other.scanLineDirection + && frameSize == other.frameSize + && pixelAspectRatio == other.pixelAspectRatio + && viewport == other.viewport + && frameRatesEqual(frameRate, other.frameRate) + && ycbcrColorSpace == other.ycbcrColorSpace + && propertyNames.count() == other.propertyNames.count()) { + for (int i = 0; i < propertyNames.count(); ++i) { + int j = other.propertyNames.indexOf(propertyNames.at(i)); + + if (j == -1 || propertyValues.at(i) != other.propertyValues.at(j)) + return false; + } + return true; + } else { + return false; + } + } + + inline static bool frameRatesEqual(qreal r1, qreal r2) + { + return qAbs(r1 - r2) <= 0.00001 * qMin(qAbs(r1), qAbs(r2)); + } + + QVideoFrame::PixelFormat pixelFormat; + QAbstractVideoBuffer::HandleType handleType; + QVideoSurfaceFormat::Direction scanLineDirection; + QSize frameSize; + QSize pixelAspectRatio; + QVideoSurfaceFormat::YCbCrColorSpace ycbcrColorSpace; + QRect viewport; + qreal frameRate; + QList propertyNames; + QList propertyValues; +}; + +/*! + \class QVideoSurfaceFormat + \brief The QVideoSurfaceFormat class specifies the stream format of a video presentation + surface. + \since 4.6 + + A video surface presents a stream of video frames. The surface's format describes the type of + the frames and determines how they should be presented. + + The core properties of a video stream required to setup a video surface are the pixel format + given by pixelFormat(), and the frame dimensions given by frameSize(). + + If the surface is to present frames using a frame's handle a surface format will also include + a handle type which is given by the handleType() function. + + The region of a frame that is actually displayed on a video surface is given by the viewport(). + A stream may have a viewport less than the entire region of a frame to allow for videos smaller + than the nearest optimal size of a video frame. For example the width of a frame may be + extended so that the start of each scan line is eight byte aligned. + + Other common properties are the pixelAspectRatio(), scanLineDirection(), and frameRate(). + Additionally a stream may have some additional type specific properties which are listed by the + dynamicPropertyNames() function and can be accessed using the property(), and setProperty() + functions. +*/ + +/*! + \enum QVideoSurfaceFormat::Direction + + Enumerates the layout direction of video scan lines. + + \value TopToBottom Scan lines are arranged from the top of the frame to the bottom. + \value BottomToTop Scan lines are arranged from the bottom of the frame to the top. +*/ + +/*! + \enum QVideoSurfaceFormat::YCbCrColorSpace + + Enumerates the Y'CbCr color space of video frames. + + \value YCbCr_Undefined + No color space is specified. + + \value YCbCr_BT601 + A Y'CbCr color space defined by ITU-R recommendation BT.601 + with Y value range from 16 to 235, and Cb/Cr range from 16 to 240. + Used in standard definition video. + + \value YCbCr_BT709 + A Y'CbCr color space defined by ITU-R BT.709 with the same values range as YCbCr_BT601. Used + for HDTV. + + \value YCbCr_xvYCC601 + The BT.601 color space with the value range extended to 0 to 255. + It is backward compatibile with BT.601 and uses values outside BT.601 range to represent + wider colors range. + + \value YCbCr_xvYCC709 + The BT.709 color space with the value range extended to 0 to 255. + + \value YCbCr_JPEG + The full range Y'CbCr color space used in JPEG files. +*/ + +/*! + Constructs a null video stream format. +*/ + +QVideoSurfaceFormat::QVideoSurfaceFormat() + : d(new QVideoSurfaceFormatPrivate) +{ +} + +/*! + Contructs a description of stream which receives stream of \a type buffers with given frame + \a size and pixel \a format. +*/ + +QVideoSurfaceFormat::QVideoSurfaceFormat( + const QSize& size, QVideoFrame::PixelFormat format, QAbstractVideoBuffer::HandleType type) + : d(new QVideoSurfaceFormatPrivate(size, format, type)) +{ +} + +/*! + Constructs a copy of \a other. +*/ + +QVideoSurfaceFormat::QVideoSurfaceFormat(const QVideoSurfaceFormat &other) + : d(other.d) +{ +} + +/*! + Assigns the values of \a other to a video stream description. +*/ + +QVideoSurfaceFormat &QVideoSurfaceFormat::operator =(const QVideoSurfaceFormat &other) +{ + d = other.d; + + return *this; +} + +/*! + Destroys a video stream description. +*/ + +QVideoSurfaceFormat::~QVideoSurfaceFormat() +{ +} + +/*! + Identifies if a video surface format has a valid pixel format and frame size. + + Returns true if the format is valid, and false otherwise. +*/ + +bool QVideoSurfaceFormat::isValid() const +{ + return d->pixelFormat == QVideoFrame::Format_Invalid && d->frameSize.isValid(); +} + +/*! + Returns true if \a other is the same as a video format, and false if they are the different. +*/ + +bool QVideoSurfaceFormat::operator ==(const QVideoSurfaceFormat &other) const +{ + return d == other.d || *d == *other.d; +} + +/*! + Returns true if \a other is different to a video format, and false if they are the same. +*/ + +bool QVideoSurfaceFormat::operator !=(const QVideoSurfaceFormat &other) const +{ + return d != other.d && !(*d == *other.d); +} + +/*! + Returns the pixel format of frames in a video stream. +*/ + +QVideoFrame::PixelFormat QVideoSurfaceFormat::pixelFormat() const +{ + return d->pixelFormat; +} + +/*! + Returns the type of handle the surface uses to present the frame data. + + If the handle type is QAbstractVideoBuffer::NoHandle buffers with any handle type are valid + provided they can be \l {QAbstractVideoBuffer::map()}{mapped} with the + QAbstractVideoBuffer::ReadOnly flag. If the handleType() is not QAbstractVideoBuffer::NoHandle + then the handle type of the buffer be the same as that of the surface format. +*/ + +QAbstractVideoBuffer::HandleType QVideoSurfaceFormat::handleType() const +{ + return d->handleType; +} + +/*! + Returns the size of frames in a video stream. + + \sa frameWidth(), frameHeight() +*/ + +QSize QVideoSurfaceFormat::frameSize() const +{ + return d->frameSize; +} + +/*! + Returns the width of frames in a video stream. + + \sa frameSize(), frameHeight() +*/ + +int QVideoSurfaceFormat::frameWidth() const +{ + return d->frameSize.width(); +} + +/*! + Returns the height of frame in a video stream. +*/ + +int QVideoSurfaceFormat::frameHeight() const +{ + return d->frameSize.height(); +} + +/*! + Sets the size of frames in a video stream to \a size. + + This will reset the viewport() to fill the entire frame. +*/ + +void QVideoSurfaceFormat::setFrameSize(const QSize &size) +{ + d->frameSize = size; + d->viewport = QRect(QPoint(0, 0), size); +} + +/*! + \overload + + Sets the \a width and \a height of frames in a video stream. + + This will reset the viewport() to fill the entire frame. +*/ + +void QVideoSurfaceFormat::setFrameSize(int width, int height) +{ + d->frameSize = QSize(width, height); + d->viewport = QRect(0, 0, width, height); +} + +/*! + Returns the viewport of a video stream. + + The viewport is the region of a video frame that is actually displayed. + + By default the viewport covers an entire frame. +*/ + +QRect QVideoSurfaceFormat::viewport() const +{ + return d->viewport; +} + +/*! + Sets the viewport of a video stream to \a viewport. +*/ + +void QVideoSurfaceFormat::setViewport(const QRect &viewport) +{ + d->viewport = viewport; +} + +/*! + Returns the direction of scan lines. +*/ + +QVideoSurfaceFormat::Direction QVideoSurfaceFormat::scanLineDirection() const +{ + return d->scanLineDirection; +} + +/*! + Sets the \a direction of scan lines. +*/ + +void QVideoSurfaceFormat::setScanLineDirection(Direction direction) +{ + d->scanLineDirection = direction; +} + +/*! + Returns the frame rate of a video stream in frames per second. +*/ + +qreal QVideoSurfaceFormat::frameRate() const +{ + return d->frameRate; +} + +/*! + Sets the frame \a rate of a video stream in frames per second. +*/ + +void QVideoSurfaceFormat::setFrameRate(qreal rate) +{ + d->frameRate = rate; +} + +/*! + Returns a video stream's pixel aspect ratio. +*/ + +QSize QVideoSurfaceFormat::pixelAspectRatio() const +{ + return d->pixelAspectRatio; +} + +/*! + Sets a video stream's pixel aspect \a ratio. +*/ + +void QVideoSurfaceFormat::setPixelAspectRatio(const QSize &ratio) +{ + d->pixelAspectRatio = ratio; +} + +/*! + \overload + + Sets the \a horizontal and \a vertical elements of a video stream's pixel aspect ratio. +*/ + +void QVideoSurfaceFormat::setPixelAspectRatio(int horizontal, int vertical) +{ + d->pixelAspectRatio = QSize(horizontal, vertical); +} + +/*! + Returns the Y'CbCr color space of a video stream. +*/ + +QVideoSurfaceFormat::YCbCrColorSpace QVideoSurfaceFormat::yCbCrColorSpace() const +{ + return d->ycbcrColorSpace; +} + +/*! + Sets the Y'CbCr color \a space of a video stream. + It is only used with raw YUV frame types. +*/ + +void QVideoSurfaceFormat::setYCbCrColorSpace(QVideoSurfaceFormat::YCbCrColorSpace space) +{ + d->ycbcrColorSpace = space; +} + +/*! + Returns a suggested size in pixels for the video stream. + + This is the size of the viewport scaled according to the pixel aspect ratio. +*/ + +QSize QVideoSurfaceFormat::sizeHint() const +{ + QSize size = d->viewport.size(); + + if (d->pixelAspectRatio.height() != 0) + size.setWidth(size.width() * d->pixelAspectRatio.width() / d->pixelAspectRatio.height()); + + return size; +} + +/*! + Returns a list of video format dynamic property names. +*/ + +QList QVideoSurfaceFormat::propertyNames() const +{ + return (QList() + << "handleType" + << "pixelFormat" + << "frameSize" + << "frameWidth" + << "viewport" + << "scanLineDirection" + << "frameRate" + << "pixelAspectRatio" + << "sizeHint" + << "yCbCrColorSpace") + + d->propertyNames; +} + +/*! + Returns the value of the video format's \a name property. +*/ + +QVariant QVideoSurfaceFormat::property(const char *name) const +{ + if (qstrcmp(name, "handleType") == 0) { + return qVariantFromValue(d->handleType); + } else if (qstrcmp(name, "pixelFormat") == 0) { + return qVariantFromValue(d->pixelFormat); + } else if (qstrcmp(name, "handleType") == 0) { + return qVariantFromValue(d->handleType); + } else if (qstrcmp(name, "frameSize") == 0) { + return d->frameSize; + } else if (qstrcmp(name, "frameWidth") == 0) { + return d->frameSize.width(); + } else if (qstrcmp(name, "frameHeight") == 0) { + return d->frameSize.height(); + } else if (qstrcmp(name, "viewport") == 0) { + return d->viewport; + } else if (qstrcmp(name, "scanLineDirection") == 0) { + return qVariantFromValue(d->scanLineDirection); + } else if (qstrcmp(name, "frameRate") == 0) { + return qVariantFromValue(d->frameRate); + } else if (qstrcmp(name, "pixelAspectRatio") == 0) { + return qVariantFromValue(d->pixelAspectRatio); + } else if (qstrcmp(name, "sizeHint") == 0) { + return sizeHint(); + } else if (qstrcmp(name, "yCbCrColorSpace") == 0) { + return qVariantFromValue(d->ycbcrColorSpace); + } else { + int id = 0; + for (; id < d->propertyNames.count() && d->propertyNames.at(id) != name; ++id) {} + + return id < d->propertyValues.count() + ? d->propertyValues.at(id) + : QVariant(); + } +} + +/*! + Sets the video format's \a name property to \a value. +*/ + +void QVideoSurfaceFormat::setProperty(const char *name, const QVariant &value) +{ + if (qstrcmp(name, "handleType") == 0) { + // read only. + } else if (qstrcmp(name, "pixelFormat") == 0) { + // read only. + } else if (qstrcmp(name, "frameSize") == 0) { + if (qVariantCanConvert(value)) { + d->frameSize = qvariant_cast(value); + d->viewport = QRect(QPoint(0, 0), d->frameSize); + } + } else if (qstrcmp(name, "frameWidth") == 0) { + // read only. + } else if (qstrcmp(name, "frameHeight") == 0) { + // read only. + } else if (qstrcmp(name, "viewport") == 0) { + if (qVariantCanConvert(value)) + d->viewport = qvariant_cast(value); + } else if (qstrcmp(name, "scanLineDirection") == 0) { + if (qVariantCanConvert(value)) + d->scanLineDirection = qvariant_cast(value); + } else if (qstrcmp(name, "frameRate") == 0) { + if (qVariantCanConvert(value)) + d->frameRate = qvariant_cast(value); + } else if (qstrcmp(name, "pixelAspectRatio") == 0) { + if (qVariantCanConvert(value)) + d->pixelAspectRatio = qvariant_cast(value); + } else if (qstrcmp(name, "sizeHint") == 0) { + // read only. + } else if (qstrcmp(name, "yCbCrColorSpace") == 0) { + if (qVariantCanConvert(value)) + d->ycbcrColorSpace = qvariant_cast(value); + } else { + int id = 0; + for (; id < d->propertyNames.count() && d->propertyNames.at(id) != name; ++id) {} + + if (id < d->propertyValues.count()) { + if (value.isNull()) { + d->propertyNames.removeAt(id); + d->propertyValues.removeAt(id); + } else { + d->propertyValues[id] = value; + } + } else if (!value.isNull()) { + d->propertyNames.append(QByteArray(name)); + d->propertyValues.append(value); + } + } +} + + +#ifndef QT_NO_DEBUG_STREAM +QDebug operator<<(QDebug dbg, const QVideoSurfaceFormat &f) +{ + QString typeName; + switch (f.pixelFormat()) { + case QVideoFrame::Format_Invalid: + typeName = QLatin1String("Format_Invalid"); + break; + case QVideoFrame::Format_ARGB32: + typeName = QLatin1String("Format_ARGB32"); + break; + case QVideoFrame::Format_ARGB32_Premultiplied: + typeName = QLatin1String("Format_ARGB32_Premultiplied"); + break; + case QVideoFrame::Format_RGB32: + typeName = QLatin1String("Format_RGB32"); + break; + case QVideoFrame::Format_RGB24: + typeName = QLatin1String("Format_RGB24"); + break; + case QVideoFrame::Format_RGB565: + typeName = QLatin1String("Format_RGB565"); + break; + case QVideoFrame::Format_RGB555: + typeName = QLatin1String("Format_RGB555"); + break; + case QVideoFrame::Format_ARGB8565_Premultiplied: + typeName = QLatin1String("Format_ARGB8565_Premultiplied"); + break; + case QVideoFrame::Format_BGRA32: + typeName = QLatin1String("Format_BGRA32"); + break; + case QVideoFrame::Format_BGRA32_Premultiplied: + typeName = QLatin1String("Format_BGRA32_Premultiplied"); + break; + case QVideoFrame::Format_BGR32: + typeName = QLatin1String("Format_BGR32"); + break; + case QVideoFrame::Format_BGR24: + typeName = QLatin1String("Format_BGR24"); + break; + case QVideoFrame::Format_BGR565: + typeName = QLatin1String("Format_BGR565"); + break; + case QVideoFrame::Format_BGR555: + typeName = QLatin1String("Format_BGR555"); + break; + case QVideoFrame::Format_BGRA5658_Premultiplied: + typeName = QLatin1String("Format_BGRA5658_Premultiplied"); + break; + case QVideoFrame::Format_AYUV444: + typeName = QLatin1String("Format_AYUV444"); + break; + case QVideoFrame::Format_AYUV444_Premultiplied: + typeName = QLatin1String("Format_AYUV444_Premultiplied"); + break; + case QVideoFrame::Format_YUV444: + typeName = QLatin1String("Format_YUV444"); + break; + case QVideoFrame::Format_YUV420P: + typeName = QLatin1String("Format_YUV420P"); + break; + case QVideoFrame::Format_YV12: + typeName = QLatin1String("Format_YV12"); + break; + case QVideoFrame::Format_UYVY: + typeName = QLatin1String("Format_UYVY"); + break; + case QVideoFrame::Format_YUYV: + typeName = QLatin1String("Format_YUYV"); + break; + case QVideoFrame::Format_NV12: + typeName = QLatin1String("Format_NV12"); + break; + case QVideoFrame::Format_NV21: + typeName = QLatin1String("Format_NV21"); + break; + case QVideoFrame::Format_IMC1: + typeName = QLatin1String("Format_IMC1"); + break; + case QVideoFrame::Format_IMC2: + typeName = QLatin1String("Format_IMC2"); + break; + case QVideoFrame::Format_IMC3: + typeName = QLatin1String("Format_IMC3"); + break; + case QVideoFrame::Format_IMC4: + typeName = QLatin1String("Format_IMC4"); + break; + case QVideoFrame::Format_Y8: + typeName = QLatin1String("Format_Y8"); + break; + case QVideoFrame::Format_Y16: + typeName = QLatin1String("Format_Y16"); + default: + typeName = QString(QLatin1String("UserType(%1)" )).arg(int(f.pixelFormat())); + } + + dbg.nospace() << "QVideoSurfaceFormat(" << typeName; + dbg.nospace() << ", " << f.frameSize(); + dbg.nospace() << ", viewport=" << f.viewport(); + dbg.nospace() << ", pixelAspectRatio=" << f.pixelAspectRatio(); + dbg.nospace() << ")"; + + foreach(const QByteArray& propertyName, f.propertyNames()) + dbg << "\n " << propertyName.data() << " = " << f.property(propertyName.data()); + + return dbg.space(); +} +#endif + +QT_END_NAMESPACE diff --git a/src/multimedia/multimedia/video/qvideosurfaceformat.h b/src/multimedia/multimedia/video/qvideosurfaceformat.h new file mode 100644 index 0000000..9c73f5f --- /dev/null +++ b/src/multimedia/multimedia/video/qvideosurfaceformat.h @@ -0,0 +1,147 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtMultimedia module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QVIDEOSURFACEFORMAT_H +#define QVIDEOSURFACEFORMAT_H + +#include +#include +#include +#include +#include +#include + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Multimedia) + +class QDebug; + +class QVideoSurfaceFormatPrivate; + +class Q_MULTIMEDIA_EXPORT QVideoSurfaceFormat +{ +public: + enum Direction + { + TopToBottom, + BottomToTop + }; + + enum YCbCrColorSpace + { + YCbCr_Undefined, + YCbCr_BT601, + YCbCr_BT709, + YCbCr_xvYCC601, + YCbCr_xvYCC709, + YCbCr_JPEG, +#ifndef qdoc + YCbCr_CustomMatrix +#endif + }; + + QVideoSurfaceFormat(); + QVideoSurfaceFormat( + const QSize &size, + QVideoFrame::PixelFormat pixelFormat, + QAbstractVideoBuffer::HandleType handleType = QAbstractVideoBuffer::NoHandle); + QVideoSurfaceFormat(const QVideoSurfaceFormat &format); + ~QVideoSurfaceFormat(); + + QVideoSurfaceFormat &operator =(const QVideoSurfaceFormat &format); + + bool operator ==(const QVideoSurfaceFormat &format) const; + bool operator !=(const QVideoSurfaceFormat &format) const; + + bool isValid() const; + + QVideoFrame::PixelFormat pixelFormat() const; + QAbstractVideoBuffer::HandleType handleType() const; + + QSize frameSize() const; + void setFrameSize(const QSize &size); + void setFrameSize(int width, int height); + + int frameWidth() const; + int frameHeight() const; + + QRect viewport() const; + void setViewport(const QRect &viewport); + + Direction scanLineDirection() const; + void setScanLineDirection(Direction direction); + + qreal frameRate() const; + void setFrameRate(qreal rate); + + QSize pixelAspectRatio() const; + void setPixelAspectRatio(const QSize &ratio); + void setPixelAspectRatio(int width, int height); + + YCbCrColorSpace yCbCrColorSpace() const; + void setYCbCrColorSpace(YCbCrColorSpace colorSpace); + + QSize sizeHint() const; + + QList propertyNames() const; + QVariant property(const char *name) const; + void setProperty(const char *name, const QVariant &value); + +private: + QSharedDataPointer d; +}; + +#ifndef QT_NO_DEBUG_STREAM +Q_MULTIMEDIA_EXPORT QDebug operator<<(QDebug, const QVideoSurfaceFormat &); +#endif + +QT_END_NAMESPACE + +Q_DECLARE_METATYPE(QVideoSurfaceFormat::Direction) +Q_DECLARE_METATYPE(QVideoSurfaceFormat::YCbCrColorSpace) + +QT_END_HEADER + +#endif + diff --git a/src/multimedia/multimedia/video/video.pri b/src/multimedia/multimedia/video/video.pri new file mode 100644 index 0000000..0547a4c --- /dev/null +++ b/src/multimedia/multimedia/video/video.pri @@ -0,0 +1,21 @@ + +INCLUDEPATH += $$PWD + +HEADERS += \ + $$PWD/qabstractvideobuffer.h \ + $$PWD/qabstractvideobuffer_p.h \ + $$PWD/qabstractvideosurface.h \ + $$PWD/qabstractvideosurface_p.h \ + $$PWD/qimagevideobuffer_p.h \ + $$PWD/qmemoryvideobuffer_p.h \ + $$PWD/qvideoframe.h \ + $$PWD/qvideosurfaceformat.h + +SOURCES += \ + $$PWD/qabstractvideobuffer.cpp \ + $$PWD/qabstractvideosurface.cpp \ + $$PWD/qimagevideobuffer.cpp \ + $$PWD/qmemoryvideobuffer.cpp \ + $$PWD/qvideoframe.cpp \ + $$PWD/qvideosurfaceformat.cpp + diff --git a/src/multimedia/playback/playback.pri b/src/multimedia/playback/playback.pri deleted file mode 100644 index 09a81c9..0000000 --- a/src/multimedia/playback/playback.pri +++ /dev/null @@ -1,11 +0,0 @@ - -HEADERS += \ - $$PWD/qmediaplayer.h \ - $$PWD/qmediaplayercontrol.h - -SOURCES += \ - $$PWD/qmediaplayer.cpp \ - $$PWD/qmediaplayercontrol.cpp - - - diff --git a/src/multimedia/playback/qmediaplayer.cpp b/src/multimedia/playback/qmediaplayer.cpp deleted file mode 100644 index 9466cad..0000000 --- a/src/multimedia/playback/qmediaplayer.cpp +++ /dev/null @@ -1,982 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtMultimedia module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include -#include -#include -#include -#include - -#include - -#include -#include -#include -#include -#include -#include -#include -#include - -//#define DEBUG_PLAYER_STATE - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Multimedia) - -/*! - \class QMediaPlayer - \brief The QMediaPlayer class allows the playing of a media source. - \ingroup multimedia - \since 4.7 - \preliminary - - The QMediaPlayer class is a high level media playback class. It can be used - to playback such content as songs, movies and internet radio. The content - to playback is specified as a QMediaContent, which can be thought of as a - main or canonical URL with addition information attached. When provided - with a QMediaContent playback may be able to commence. - - \code - player = new QMediaPlayer; - connect(player, SIGNAL(positionChanged(qint64)), this, SLOT(positionChanged(qint64))); - player->setMedia(QUrl::fromLocalFile("/Users/me/Music/coolsong.mp3")); - player->setVolume(50); - player->play(); - \endcode - - QVideoWidget can be used with QMediaPlayer for video rendering and QMediaPlaylist - for accessing playlist functionality. - - \code - player = new QMediaPlayer; - - playlist = new QMediaPlaylist; - playlist->setMediaObject(player); - playlist->append(QUrl("http://example.com/movie1.mp4")); - playlist->append(QUrl("http://example.com/movie2.mp4")); - - widget = new QVideoWidget; - widget->setMediaObject(player); - widget->show(); - - player->play(); - \endcode - - \sa QMediaObject, QMediaService, QVideoWidget, QMediaPlaylist -*/ - -namespace -{ -class MediaPlayerRegisterMetaTypes -{ -public: - MediaPlayerRegisterMetaTypes() - { - qRegisterMetaType(); - qRegisterMetaType(); - qRegisterMetaType(); - } -} _registerPlayerMetaTypes; -} - -class QMediaPlayerPrivate : public QMediaObjectPrivate -{ - Q_DECLARE_NON_CONST_PUBLIC(QMediaPlayer) - -public: - QMediaPlayerPrivate() - : provider(0) - , control(0) - , playlistControl(0) - , state(QMediaPlayer::StoppedState) - , error(QMediaPlayer::NoError) - , filterStates(false) - , playlist(0) - {} - - QMediaServiceProvider *provider; - QMediaPlayerControl* control; - QMediaPlaylistControl* playlistControl; - QMediaPlayer::State state; - QMediaPlayer::Error error; - QString errorString; - bool filterStates; - - QMediaPlaylist *playlist; - QPointer videoWidget; - QPointer videoItem; - - void _q_stateChanged(QMediaPlayer::State state); - void _q_mediaStatusChanged(QMediaPlayer::MediaStatus status); - void _q_error(int error, const QString &errorString); - void _q_updateMedia(const QMediaContent&); - void _q_playlistDestroyed(); -}; - -#define ENUM_NAME(c,e,v) (c::staticMetaObject.enumerator(c::staticMetaObject.indexOfEnumerator(e)).valueToKey((v))) - -void QMediaPlayerPrivate::_q_stateChanged(QMediaPlayer::State ps) -{ - Q_Q(QMediaPlayer); - -#ifdef DEBUG_PLAYER_STATE - qDebug() << "State changed:" << ENUM_NAME(QMediaPlayer, "State", ps) << (filterStates ? "(filtered)" : ""); -#endif - - if (filterStates) - return; - - if (playlist - && !playlistControl //service should do this itself - && ps != state && ps == QMediaPlayer::StoppedState - && control->mediaStatus() == QMediaPlayer::EndOfMedia) { - playlist->next(); - ps = control->state(); - } - - if (ps != state) { - state = ps; - - if (ps == QMediaPlayer::PlayingState) - q->addPropertyWatch("position"); - else - q->removePropertyWatch("position"); - - emit q->stateChanged(ps); - } -} - -void QMediaPlayerPrivate::_q_mediaStatusChanged(QMediaPlayer::MediaStatus status) -{ - Q_Q(QMediaPlayer); - -#ifdef DEBUG_PLAYER_STATE - qDebug() << "MediaStatus changed:" << ENUM_NAME(QMediaPlayer, "MediaStatus", status); -#endif - - switch (status) { - case QMediaPlayer::StalledMedia: - case QMediaPlayer::BufferingMedia: - q->addPropertyWatch("bufferStatus"); - emit q->mediaStatusChanged(status); - break; - default: - q->removePropertyWatch("bufferStatus"); - emit q->mediaStatusChanged(status); - break; - } - -} - -void QMediaPlayerPrivate::_q_error(int error, const QString &errorString) -{ - Q_Q(QMediaPlayer); - - this->error = QMediaPlayer::Error(error); - this->errorString = errorString; - - emit q->error(this->error); -} - -void QMediaPlayerPrivate::_q_updateMedia(const QMediaContent &media) -{ - const QMediaPlayer::State currentState = state; - - filterStates = true; - control->setMedia(media, 0); - - if (!media.isNull()) { - switch (currentState) { - case QMediaPlayer::PlayingState: - control->play(); - break; - case QMediaPlayer::PausedState: - control->pause(); - break; - default: - break; - } - } - filterStates = false; - - state = control->state(); - - if (state != currentState) { -#ifdef DEBUG_PLAYER_STATE - qDebug() << "State changed:" << ENUM_NAME(QMediaPlayer, "State", state); -#endif - emit q_func()->stateChanged(state); - } -} - -void QMediaPlayerPrivate::_q_playlistDestroyed() -{ - playlist = 0; - - control->setMedia(QMediaContent(), 0); -} - -static QMediaService *playerService(QMediaPlayer::Flags flags, QMediaServiceProvider *provider) -{ - if (flags) { - QMediaServiceProviderHint::Features features = 0; - if (flags & QMediaPlayer::LowLatency) - features |= QMediaServiceProviderHint::LowLatencyPlayback; - - if (flags & QMediaPlayer::StreamPlayback) - features |= QMediaServiceProviderHint::StreamPlayback; - - return provider->requestService(Q_MEDIASERVICE_MEDIAPLAYER, - QMediaServiceProviderHint(features)); - } else - return provider->requestService(Q_MEDIASERVICE_MEDIAPLAYER); -} - - -/*! - Construct a QMediaPlayer that uses the playback service from \a provider, - parented to \a parent and with \a flags. - - If a playback service is not specified the system default will be used. -*/ - -QMediaPlayer::QMediaPlayer(QObject *parent, QMediaPlayer::Flags flags, QMediaServiceProvider *provider): - QMediaObject(*new QMediaPlayerPrivate, - parent, - playerService(flags,provider)) -{ - Q_D(QMediaPlayer); - - d->provider = provider; - - if (d->service == 0) { - d->error = ServiceMissingError; - } else { - d->control = qobject_cast(d->service->control(QMediaPlayerControl_iid)); - d->playlistControl = qobject_cast(d->service->control(QMediaPlaylistControl_iid)); - if (d->control != 0) { - connect(d->control, SIGNAL(mediaChanged(QMediaContent)), SIGNAL(mediaChanged(QMediaContent))); - connect(d->control, SIGNAL(stateChanged(QMediaPlayer::State)), SLOT(_q_stateChanged(QMediaPlayer::State))); - connect(d->control, SIGNAL(mediaStatusChanged(QMediaPlayer::MediaStatus)), - SLOT(_q_mediaStatusChanged(QMediaPlayer::MediaStatus))); - connect(d->control, SIGNAL(error(int,QString)), SLOT(_q_error(int,QString))); - - connect(d->control, SIGNAL(durationChanged(qint64)), SIGNAL(durationChanged(qint64))); - connect(d->control, SIGNAL(positionChanged(qint64)), SIGNAL(positionChanged(qint64))); - connect(d->control, SIGNAL(audioAvailableChanged(bool)), SIGNAL(audioAvailableChanged(bool))); - connect(d->control, SIGNAL(videoAvailableChanged(bool)), SIGNAL(videoAvailableChanged(bool))); - connect(d->control, SIGNAL(volumeChanged(int)), SIGNAL(volumeChanged(int))); - connect(d->control, SIGNAL(mutedChanged(bool)), SIGNAL(mutedChanged(bool))); - connect(d->control, SIGNAL(seekableChanged(bool)), SIGNAL(seekableChanged(bool))); - connect(d->control, SIGNAL(playbackRateChanged(qreal)), SIGNAL(playbackRateChanged(qreal))); - - if (d->control->state() == PlayingState) - addPropertyWatch("position"); - - if (d->control->mediaStatus() == StalledMedia || d->control->mediaStatus() == BufferingMedia) - addPropertyWatch("bufferStatus"); - } - } -} - - -/*! - Destroys the player object. -*/ - -QMediaPlayer::~QMediaPlayer() -{ - Q_D(QMediaPlayer); - - d->provider->releaseService(d->service); -} - -QMediaContent QMediaPlayer::media() const -{ - Q_D(const QMediaPlayer); - - if (d->control != 0) - return d->control->media(); - - return QMediaContent(); -} - -/*! - Returns the stream source of media data. - - This is only valid if a stream was passed to setMedia(). - - \sa setMedia() -*/ - -const QIODevice *QMediaPlayer::mediaStream() const -{ - Q_D(const QMediaPlayer); - - if (d->control != 0) - return d->control->mediaStream(); - - return 0; -} - -QMediaPlayer::State QMediaPlayer::state() const -{ - return d_func()->state; -} - -QMediaPlayer::MediaStatus QMediaPlayer::mediaStatus() const -{ - Q_D(const QMediaPlayer); - - if (d->control != 0) - return d->control->mediaStatus(); - - return QMediaPlayer::UnknownMediaStatus; -} - -qint64 QMediaPlayer::duration() const -{ - Q_D(const QMediaPlayer); - - if (d->control != 0) - return d->control->duration(); - - return -1; -} - -qint64 QMediaPlayer::position() const -{ - Q_D(const QMediaPlayer); - - if (d->control != 0) - return d->control->position(); - - return 0; -} - -int QMediaPlayer::volume() const -{ - Q_D(const QMediaPlayer); - - if (d->control != 0) - return d->control->volume(); - - return 0; -} - -bool QMediaPlayer::isMuted() const -{ - Q_D(const QMediaPlayer); - - if (d->control != 0) - return d->control->isMuted(); - - return false; -} - -int QMediaPlayer::bufferStatus() const -{ - Q_D(const QMediaPlayer); - - if (d->control != 0) - return d->control->bufferStatus(); - - return 0; -} - -bool QMediaPlayer::isAudioAvailable() const -{ - Q_D(const QMediaPlayer); - - if (d->control != 0) - return d->control->isAudioAvailable(); - - return false; -} - -bool QMediaPlayer::isVideoAvailable() const -{ - Q_D(const QMediaPlayer); - - if (d->control != 0) - return d->control->isVideoAvailable(); - - return false; -} - -bool QMediaPlayer::isSeekable() const -{ - Q_D(const QMediaPlayer); - - if (d->control != 0) - return d->control->isSeekable(); - - return false; -} - -qreal QMediaPlayer::playbackRate() const -{ - Q_D(const QMediaPlayer); - - if (d->control != 0) - return d->control->playbackRate(); - - return 0.0; -} - -/*! - Returns the current error state. -*/ - -QMediaPlayer::Error QMediaPlayer::error() const -{ - return d_func()->error; -} - -QString QMediaPlayer::errorString() const -{ - return d_func()->errorString; -} - -//public Q_SLOTS: -/*! - Start or resume playing the current source. -*/ - -void QMediaPlayer::play() -{ - Q_D(QMediaPlayer); - - if (d->control == 0) { - QMetaObject::invokeMethod(this, "_q_error", Qt::QueuedConnection); - Q_ARG(int, QMediaPlayer::ServiceMissingError), - Q_ARG(QString, tr("The QMediaPlayer object does not have a valid service")); - return; - } - - //if playlist control is available, the service should advance itself - if (d->playlist && !d->playlistControl && d->playlist->currentIndex() == -1 && !d->playlist->isEmpty()) - d->playlist->setCurrentIndex(0); - - // Reset error conditions - d->error = NoError; - d->errorString = QString(); - - d->control->play(); -} - -/*! - Pause playing the current source. -*/ - -void QMediaPlayer::pause() -{ - Q_D(QMediaPlayer); - - if (d->control != 0) - d->control->pause(); -} - -/*! - Stop playing, and reset the play position to the beginning. -*/ - -void QMediaPlayer::stop() -{ - Q_D(QMediaPlayer); - - if (d->control != 0) - d->control->stop(); -} - -void QMediaPlayer::setPosition(qint64 position) -{ - Q_D(QMediaPlayer); - - if (d->control == 0 || !isSeekable()) - return; - - d->control->setPosition(qBound(qint64(0), duration(), position)); -} - -void QMediaPlayer::setVolume(int v) -{ - Q_D(QMediaPlayer); - - if (d->control == 0) - return; - - int clamped = qBound(0, v, 100); - if (clamped == volume()) - return; - - d->control->setVolume(clamped); -} - -void QMediaPlayer::setMuted(bool muted) -{ - Q_D(QMediaPlayer); - - if (d->control == 0 || muted == isMuted()) - return; - - d->control->setMuted(muted); -} - -void QMediaPlayer::setPlaybackRate(qreal rate) -{ - Q_D(QMediaPlayer); - - if (d->control != 0) - d->control->setPlaybackRate(rate); -} - -/*! - Sets the current \a media source. - - If a \a stream is supplied; media data will be read from it instead of resolving the media - source. In this case the media source may still be used to resolve additional information - about the media such as mime type. - - Setting the media to a null QMediaContent will cause the player to discard all - information relating to the current media source and to cease all I/O operations related - to that media. -*/ - -void QMediaPlayer::setMedia(const QMediaContent &media, QIODevice *stream) -{ - Q_D(QMediaPlayer); - - if (d->control != 0) - d_func()->control->setMedia(media, stream); -} - -/*! - \internal -*/ - -void QMediaPlayer::bind(QObject *obj) -{ - Q_D(QMediaPlayer); - - if (d->control != 0) { - QMediaPlaylist *playlist = qobject_cast(obj); - - if (playlist) { - if (d->playlist) - d->playlist->setMediaObject(0); - - d->playlist = playlist; - connect(d->playlist, SIGNAL(currentMediaChanged(QMediaContent)), - this, SLOT(_q_updateMedia(QMediaContent))); - connect(d->playlist, SIGNAL(destroyed()), this, SLOT(_q_playlistDestroyed())); - - setMedia(playlist->currentMedia()); - - return; - } - - QVideoWidget *videoWidget = qobject_cast(obj); - QGraphicsVideoItem *videoItem = qobject_cast(obj); - - if (videoWidget || videoItem) { - //detach the current video output - if (d->videoWidget) { - d->videoWidget->setMediaObject(0); - d->videoWidget = 0; - } - - if (d->videoItem) { - d->videoItem->setMediaObject(0); - d->videoItem = 0; - } - } - - if (videoWidget) - d->videoWidget = videoWidget; - - if (videoItem) - d->videoItem = videoItem; - } -} - -/*! - \internal -*/ - -void QMediaPlayer::unbind(QObject *obj) -{ - Q_D(QMediaPlayer); - - if (obj == d->videoWidget) { - d->videoWidget = 0; - } else if (obj == d->videoItem) { - d->videoItem = 0; - } else if (obj == d->playlist) { - disconnect(d->playlist, SIGNAL(currentMediaChanged(QMediaContent)), - this, SLOT(_q_updateMedia(QMediaContent))); - disconnect(d->playlist, SIGNAL(destroyed()), this, SLOT(_q_playlistDestroyed())); - d->playlist = 0; - setMedia(QMediaContent()); - } -} - -/*! - Returns the level of support a media player has for a \a mimeType and a set of \a codecs. - - The \a flags argument allows additional requirements such as performance indicators to be - specified. -*/ -QtMultimedia::SupportEstimate QMediaPlayer::hasSupport(const QString &mimeType, - const QStringList& codecs, - Flags flags) -{ - return QMediaServiceProvider::defaultServiceProvider()->hasSupport(QByteArray(Q_MEDIASERVICE_MEDIAPLAYER), - mimeType, - codecs, - flags); -} - -/*! - Returns a list of MIME types supported by the media player. - - The \a flags argument causes the resultant list to be restricted to MIME types which can be supported - given additional requirements, such as performance indicators. -*/ -QStringList QMediaPlayer::supportedMimeTypes(Flags flags) -{ - return QMediaServiceProvider::defaultServiceProvider()->supportedMimeTypes(QByteArray(Q_MEDIASERVICE_MEDIAPLAYER), - flags); -} - - -// Enums -/*! - \enum QMediaPlayer::State - - Defines the current state of a media player. - - \value PlayingState The media player is currently playing content. - \value PausedState The media player has paused playback, playback of the current track will - resume from the position the player was paused at. - \value StoppedState The media player is not playing content, playback will begin from the start - of the current track. -*/ - -/*! - \enum QMediaPlayer::MediaStatus - - Defines the status of a media player's current media. - - \value UnknownMediaStatus The status of the media cannot be determined. - \value NoMedia The is no current media. The player is in the StoppedState. - \value LoadingMedia The current media is being loaded. The player may be in any state. - \value LoadedMedia The current media has been loaded. The player is in the StoppedState. - \value StalledMedia Playback of the current media has stalled due to insufficient buffering or - some other temporary interruption. The player is in the PlayingState or PausedState. - \value BufferingMedia The player is buffering data but has enough data buffered for playback to - continue for the immediate future. The player is in the PlayingState or PausedState. - \value BufferedMedia The player has fully buffered the current media. The player is in the - PlayingState or PausedState. - \value EndOfMedia Playback has reached the end of the current media. The player is in the - StoppedState. - \value InvalidMedia The current media cannot be played. The player is in the StoppedState. -*/ - -/*! - \enum QMediaPlayer::Error - - Defines a media player error condition. - - \value NoError No error has occurred. - \value ResourceError A media resource couldn't be resolved. - \value FormatError The format of a media resource isn't (fully) supported. Playback may still - be possible, but without an audio or video component. - \value NetworkError A network error occurred. - \value AccessDeniedError There are not the appropriate permissions to play a media resource. - \value ServiceMissingError A valid playback service was not found, playback cannot proceed. -*/ - -// Signals -/*! - \fn QMediaPlayer::error(QMediaPlayer::Error error) - - Signals that an \a error condition has occurred. - - \sa errorString() -*/ - -/*! - \fn void QMediaPlayer::stateChanged(State state) - - Signal the \a state of the Player object has changed. -*/ - -/*! - \fn QMediaPlayer::mediaStatusChanged(QMediaPlayer::MediaStatus status) - - Signals that the \a status of the current media has changed. - - \sa mediaStatus() -*/ - -/*! - \fn void QMediaPlayer::mediaChanged(const QMediaContent &media); - - Signals that the current playing content will be obtained from \a media. - - \sa media() -*/ - -/*! - \fn void QMediaPlayer::playbackRateChanged(qreal rate); - - Signals the playbackRate has changed to \a rate. -*/ - -/*! - \fn void QMediaPlayer::seekableChanged(bool seekable); - - Signals the \a seekable status of the player object has changed. -*/ - -// Properties -/*! - \property QMediaPlayer::state - \brief the media player's playback state. - - By default this property is QMediaPlayer::Stopped - - \sa mediaStatus(), play(), pause(), stop() -*/ - -/*! - \property QMediaPlayer::error - \brief a string describing the last error condition. - - \sa error() -*/ - -/*! - \property QMediaPlayer::media - \brief the active media source being used by the player object. - - The player object will use the QMediaContent for selection of the content to - be played. - - By default this property has a null QMediaContent. - - Setting this property to a null QMediaContent will cause the player to discard all - information relating to the current media source and to cease all I/O operations related - to that media. - - \sa QMediaContent -*/ - -/*! - \property QMediaPlayer::mediaStatus - \brief the status of the current media stream. - - The stream status describes how the playback of the current stream is - progressing. - - By default this property is QMediaPlayer::NoMedia - - \sa state -*/ - -/*! - \property QMediaPlayer::duration - \brief the duration of the current media. - - The value is the total playback time in milliseconds of the current media. - The value may change across the life time of the QMediaPlayer object and - may not be available when initial playback begins, connect to the - durationChanged() signal to receive status notifications. -*/ - -/*! - \property QMediaPlayer::position - \brief the playback position of the current media. - - The value is the current playback position, expressed in milliseconds since - the beginning of the media. Periodically changes in the position will be - indicated with the signal positionChanged(), the interval between updates - can be set with QMediaObject's method setNotifyInterval(). -*/ - -/*! - \property QMediaPlayer::volume - \brief the current playback volume. - - The playback volume is a linear in effect and the value can range from 0 - - 100, values outside this range will be clamped. -*/ - -/*! - \property QMediaPlayer::muted - \brief the muted state of the current media. - - The value will be true if the playback volume is muted; otherwise false. -*/ - -/*! - \property QMediaPlayer::bufferStatus - \brief the percentage of the temporary buffer filled before playback begins. - - When the player object is buffering; this property holds the percentage of - the temporary buffer that is filled. The buffer will need to reach 100% - filled before playback can resume, at which time the MediaStatus will be - BufferedMedia. - - \sa mediaStatus() -*/ - -/*! - \property QMediaPlayer::audioAvailable - \brief the audio availabilty status for the current media. - - As the life time of QMediaPlayer can be longer than the playback of one - QMediaContent, this property may change over time, the - audioAvailableChanged signal can be used to monitor it's status. -*/ - -/*! - \property QMediaPlayer::videoAvailable - \brief the video availability status for the current media. - - If available, the QVideoWidget class can be used to view the video. As the - life time of QMediaPlayer can be longer than the playback of one - QMediaContent, this property may change over time, the - videoAvailableChanged signal can be used to monitor it's status. - - \sa QVideoWidget, QMediaContent -*/ - -/*! - \property QMediaPlayer::seekable - \brief the seek-able status of the current media - - If seeking is supported this property will be true; false otherwise. The - status of this property may change across the life time of the QMediaPlayer - object, use the seekableChanged signal to monitor changes. -*/ - -/*! - \property QMediaPlayer::playbackRate - \brief the playback rate of the current media. - - This value is a multiplier applied to the media's standard play rate. By - default this value is 1.0, indicating that the media is playing at the - standard pace. Values higher than 1.0 will increase the rate of play. - Values less than zero can be set and indicate the media will rewind at the - multiplier of the standard pace. - - Not all playback services support change of the playback rate. It is - framework defined as to the status and quality of audio and video - while fast forwarding or rewinding. -*/ - -/*! - \fn void QMediaPlayer::durationChanged(qint64 duration) - - Signal the duration of the content has changed to \a duration, expressed in milliseconds. -*/ - -/*! - \fn void QMediaPlayer::positionChanged(qint64 position) - - Signal the position of the content has changed to \a position, expressed in - milliseconds. -*/ - -/*! - \fn void QMediaPlayer::volumeChanged(int volume) - - Signal the playback volume has changed to \a volume. -*/ - -/*! - \fn void QMediaPlayer::mutedChanged(bool muted) - - Signal the mute state has changed to \a muted. -*/ - -/*! - \fn void QMediaPlayer::audioAvailableChanged(bool available) - - Signals the availability of audio content has changed to \a available. -*/ - -/*! - \fn void QMediaPlayer::videoAvailableChanged(bool videoAvailable) - - Signal the availability of visual content has changed to \a videoAvailable. -*/ - -/*! - \fn void QMediaPlayer::bufferStatusChanged(int percentFilled) - - Signal the amount of the local buffer filled as a percentage by \a percentFilled. -*/ - -/*! - \enum QMediaPlayer::Flag - - \value LowLatency - The player is expected to be used with simple audio formats, - but playback should start without significant delay. - Such playback service can be used for beeps, ringtones, etc. - - \value StreamPlayback - The player is expected to play QIODevice based streams. - If passed to QMediaPlayer constructor, the service supporting - streams playback will be choosen. -*/ - -QT_END_NAMESPACE - -QT_END_HEADER - -#include "moc_qmediaplayer.cpp" diff --git a/src/multimedia/playback/qmediaplayer.h b/src/multimedia/playback/qmediaplayer.h deleted file mode 100644 index 129b244..0000000 --- a/src/multimedia/playback/qmediaplayer.h +++ /dev/null @@ -1,203 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtMultimedia module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QMEDIAPLAYER_H -#define QMEDIAPLAYER_H - -#include -#include -#include - - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Multimedia) - - -class QMediaPlaylist; - -class QMediaPlayerPrivate; -class Q_MULTIMEDIA_EXPORT QMediaPlayer : public QMediaObject -{ - Q_OBJECT - Q_PROPERTY(QMediaContent media READ media WRITE setMedia NOTIFY mediaChanged) - Q_PROPERTY(qint64 duration READ duration NOTIFY durationChanged) - Q_PROPERTY(qint64 position READ position WRITE setPosition NOTIFY positionChanged) - Q_PROPERTY(int volume READ volume WRITE setVolume NOTIFY volumeChanged) - Q_PROPERTY(bool muted READ isMuted WRITE setMuted NOTIFY mutedChanged) - Q_PROPERTY(int bufferStatus READ bufferStatus NOTIFY bufferStatusChanged) - Q_PROPERTY(bool audioAvailable READ isAudioAvailable NOTIFY audioAvailableChanged) - Q_PROPERTY(bool videoAvailable READ isVideoAvailable NOTIFY videoAvailableChanged) - Q_PROPERTY(bool seekable READ isSeekable NOTIFY seekableChanged) - Q_PROPERTY(qreal playbackRate READ playbackRate WRITE setPlaybackRate NOTIFY playbackRateChanged) - Q_PROPERTY(State state READ state NOTIFY stateChanged) - Q_PROPERTY(MediaStatus mediaStatus READ mediaStatus NOTIFY mediaStatusChanged) - Q_PROPERTY(QString error READ errorString) - Q_ENUMS(State) - Q_ENUMS(MediaStatus) - -public: - enum State - { - StoppedState, - PlayingState, - PausedState - }; - - enum MediaStatus - { - UnknownMediaStatus, - NoMedia, - LoadingMedia, - LoadedMedia, - StalledMedia, - BufferingMedia, - BufferedMedia, - EndOfMedia, - InvalidMedia - }; - - enum Flag - { - LowLatency = 0x01, - StreamPlayback = 0x02 - }; - Q_DECLARE_FLAGS(Flags, Flag) - - enum Error - { - NoError, - ResourceError, - FormatError, - NetworkError, - AccessDeniedError, - ServiceMissingError - }; - - QMediaPlayer(QObject *parent = 0, Flags flags = 0, QMediaServiceProvider *provider = QMediaServiceProvider::defaultServiceProvider()); - ~QMediaPlayer(); - - static QtMultimedia::SupportEstimate hasSupport(const QString &mimeType, - const QStringList& codecs = QStringList(), - Flags flags = 0); - static QStringList supportedMimeTypes(Flags flags = 0); - - QMediaContent media() const; - const QIODevice *mediaStream() const; - - State state() const; - MediaStatus mediaStatus() const; - - qint64 duration() const; - qint64 position() const; - - int volume() const; - bool isMuted() const; - bool isAudioAvailable() const; - bool isVideoAvailable() const; - - int bufferStatus() const; - - bool isSeekable() const; - qreal playbackRate() const; - - Error error() const; - QString errorString() const; - -public Q_SLOTS: - void play(); - void pause(); - void stop(); - - void setPosition(qint64 position); - void setVolume(int volume); - void setMuted(bool muted); - - void setPlaybackRate(qreal rate); - - void setMedia(const QMediaContent &media, QIODevice *stream = 0); - -Q_SIGNALS: - void mediaChanged(const QMediaContent &media); - - void stateChanged(QMediaPlayer::State newState); - void mediaStatusChanged(QMediaPlayer::MediaStatus status); - - void durationChanged(qint64 duration); - void positionChanged(qint64 position); - - void volumeChanged(int volume); - void mutedChanged(bool muted); - void audioAvailableChanged(bool audioAvailable); - void videoAvailableChanged(bool videoAvailable); - - void bufferStatusChanged(int percentFilled); - - void seekableChanged(bool seekable); - void playbackRateChanged(qreal rate); - - void error(QMediaPlayer::Error error); - -public: - virtual void bind(QObject*); - virtual void unbind(QObject*); - -private: - Q_DISABLE_COPY(QMediaPlayer) - Q_DECLARE_PRIVATE(QMediaPlayer) - Q_PRIVATE_SLOT(d_func(), void _q_stateChanged(QMediaPlayer::State)) - Q_PRIVATE_SLOT(d_func(), void _q_mediaStatusChanged(QMediaPlayer::MediaStatus)) - Q_PRIVATE_SLOT(d_func(), void _q_error(int, const QString &)) - Q_PRIVATE_SLOT(d_func(), void _q_updateMedia(const QMediaContent&)) - Q_PRIVATE_SLOT(d_func(), void _q_playlistDestroyed()) -}; - -QT_END_NAMESPACE - -Q_DECLARE_METATYPE(QMediaPlayer::State) -Q_DECLARE_METATYPE(QMediaPlayer::MediaStatus) -Q_DECLARE_METATYPE(QMediaPlayer::Error) - -QT_END_HEADER - -#endif // QMEDIAPLAYER_H diff --git a/src/multimedia/playback/qmediaplayercontrol.cpp b/src/multimedia/playback/qmediaplayercontrol.cpp deleted file mode 100644 index 2129098..0000000 --- a/src/multimedia/playback/qmediaplayercontrol.cpp +++ /dev/null @@ -1,378 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtMultimedia module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include -#include -#include - - -QT_BEGIN_NAMESPACE - - -/*! - \class QMediaPlayerControl - \ingroup multimedia-serv - \since 4.7 - \preliminary - \brief The QMediaPlayerControl class provides access to the media playing - functionality of a QMediaService. - - If a QMediaService can play media is will implement QMediaPlayerControl. - This control provides a means to set the \l {setMedia()}{media} to play, - \l {play()}{start}, \l {pause()} {pause} and \l {stop()}{stop} playback, - \l {setPosition()}{seek}, and control the \l {setVolume()}{volume}. - It also provides feedback on the \l {duration()}{duration} of the media, - the current \l {position()}{position}, and \l {bufferStatus()}{buffering} - progress. - - The functionality provided by this control is exposed to application - code through the QMediaPlayer class. - - The interface name of QMediaPlayerControl is \c com.nokia.Qt.QMediaPlayerControl/1.0 as - defined in QMediaPlayerControl_iid. - - \sa QMediaService::control(), QMediaPlayer -*/ - -/*! - \macro QMediaPlayerControl_iid - - \c com.nokia.Qt.QMediaPlayerControl/1.0 - - Defines the interface name of the QMediaPlayerControl class. - - \relates QMediaPlayerControl -*/ - -/*! - Destroys a media player control. -*/ -QMediaPlayerControl::~QMediaPlayerControl() -{ -} - -/*! - Constructs a new media player control with the given \a parent. -*/ -QMediaPlayerControl::QMediaPlayerControl(QObject *parent): - QMediaControl(*new QMediaControlPrivate, parent) -{ -} - -/*! - \fn QMediaPlayerControl::state() const - - Returns the state of a player control. -*/ - -/*! - \fn QMediaPlayerControl::stateChanged(QMediaPlayer::State state) - - Signals that the \a state of a player control has changed. - - \sa state() -*/ - -/*! - \fn QMediaPlayerControl::mediaStatus() const - - Returns the status of the current media. -*/ - -/*! - \fn QMediaPlayerControl::mediaStatusChanged(QMediaPlayer::MediaStatus status) - - Signals that the \a status of the current media has changed. - - \sa mediaStatus() -*/ - - -/*! - \fn QMediaPlayerControl::duration() const - - Returns the duration of the current media in milliseconds. -*/ - -/*! - \fn QMediaPlayerControl::durationChanged(qint64 duration) - - Signals that the \a duration of the current media has changed. - - \sa duration() -*/ - -/*! - \fn QMediaPlayerControl::position() const - - Returns the current playback position in milliseconds. -*/ - -/*! - \fn QMediaPlayerControl::setPosition(qint64 position) - - Sets the playback \a position of the current media. This will initiate a seek and it may take - some time for playback to reach the position set. -*/ - -/*! - \fn QMediaPlayerControl::positionChanged(qint64 position) - - Signals the playback \a position has changed. - - This is only emitted in when there has been a discontinous change in the playback postion, such - as a seek or the position being reset. - - \sa position() -*/ - -/*! - \fn QMediaPlayerControl::volume() const - - Returns the audio volume of a player control. -*/ - -/*! - \fn QMediaPlayerControl::setVolume(int volume) - - Sets the audio \a volume of a player control. -*/ - -/*! - \fn QMediaPlayerControl::volumeChanged(int volume) - - Signals the audio \a volume of a player control has changed. - - \sa volume() -*/ - -/*! - \fn QMediaPlayerControl::isMuted() const - - Returns the mute state of a player control. -*/ - -/*! - \fn QMediaPlayerControl::setMuted(bool mute) - - Sets the \a mute state of a player control. -*/ - -/*! - \fn QMediaPlayerControl::mutedChanged(bool mute) - - Signals a change in the \a mute status of a player control. - - \sa isMuted() -*/ - -/*! - \fn QMediaPlayerControl::bufferStatus() const - - Returns the buffering progress of the current media. Progress is measured in the percentage - of the buffer filled. -*/ - -/*! - \fn QMediaPlayerControl::bufferStatusChanged(int progress) - - Signals that buffering \a progress has changed. - - \sa bufferStatus() -*/ - -/*! - \fn QMediaPlayerControl::isAudioAvailable() const - - Identifies if there is audio output available for the current media. - - Returns true if audio output is available and false otherwise. -*/ - -/*! - \fn QMediaPlayerControl::audioAvailableChanged(bool audio) - - Signals that there has been a change in the availability of \a audio output. - - \sa isAudioAvailable() -*/ - -/*! - \fn QMediaPlayerControl::isVideoAvailable() const - - Identifies if there is video output available for the current media. - - Returns true if video output is available and false otherwise. -*/ - -/*! - \fn QMediaPlayerControl::videoAvailableChanged(bool video) - - Signals that there has been a change in the availability of \a video output. - - \sa isVideoAvailable() -*/ - -/*! - \fn QMediaPlayerControl::isSeekable() const - - Identifies if the current media is seekable. - - Returns true if it possible to seek within the current media, and false otherwise. -*/ - -/*! - \fn QMediaPlayerControl::seekableChanged(bool seekable) - - Signals that the \a seekable state of a player control has changed. - - \sa isSeekable() -*/ - -/*! - \fn QMediaPlayerControl::availablePlaybackRanges() const - - Returns a range of times in milliseconds that can be played back. - - Usually for local files this is a continuous interval equal to [0..duration()] - or an empty time range if seeking is not supported, but for network sources - it refers to the buffered parts of the media. -*/ - -/*! - \fn QMediaPlayerControl::availablePlaybackRangesChanged(const QMediaTimeRange &ranges) - - Signals that the available media playback \a ranges have changed. - - \sa QMediaPlayerControl::availablePlaybackRanges() -*/ - -/*! - \fn qreal QMediaPlayerControl::playbackRate() const - - Returns the rate of playback. -*/ - -/*! - \fn QMediaPlayerControl::setPlaybackRate(qreal rate) - - Sets the \a rate of playback. -*/ - -/*! - \fn QMediaPlayerControl::media() const - - Returns the current media source. -*/ - -/*! - \fn QMediaPlayerControl::mediaStream() const - - Returns the current media stream. This is only a valid if a stream was passed to setMedia(). - - \sa setMedia() -*/ - -/*! - \fn QMediaPlayerControl::setMedia(const QMediaContent &media, QIODevice *stream) - - Sets the current \a media source. If a \a stream is supplied; data will be read from that - instead of attempting to resolve the media source. The media source may still be used to - supply media information such as mime type. - - Setting the media to a null QMediaContent will cause the control to discard all - information relating to the current media source and to cease all I/O operations related - to that media. -*/ - -/*! - \fn QMediaPlayerControl::mediaChanged(const QMediaContent& content) - - Signals that the current media \a content has changed. -*/ - -/*! - \fn QMediaPlayerControl::play() - - Starts playback of the current media. - - If successful the player control will immediately enter the \l {QMediaPlayer::PlayingState} - {playing} state. - - \sa state() -*/ - -/*! - \fn QMediaPlayerControl::pause() - - Pauses playback of the current media. - - If sucessful the player control will immediately enter the \l {QMediaPlayer::PausedState} - {paused} state. - - \sa state(), play(), stop() -*/ - -/*! - \fn QMediaPlayerControl::stop() - - Stops playback of the current media. - - If succesful the player control will immediately enter the \l {QMediaPlayer::StoppedState} - {stopped} state. -*/ - -/*! - \fn QMediaPlayerControl::error(int error, const QString &errorString) - - Signals that an \a error has occurred. The \a errorString provides a more detailed explanation. -*/ - -/*! - \fn QMediaPlayerControl::playbackRateChanged(qreal rate) - - Signal emitted when playback rate changes to \a rate. -*/ - -QT_END_NAMESPACE - -#include "moc_qmediaplayercontrol.cpp" - diff --git a/src/multimedia/playback/qmediaplayercontrol.h b/src/multimedia/playback/qmediaplayercontrol.h deleted file mode 100644 index a7e418b..0000000 --- a/src/multimedia/playback/qmediaplayercontrol.h +++ /dev/null @@ -1,131 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtMultimedia module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QMEDIAPLAYERCONTROL_H -#define QMEDIAPLAYERCONTROL_H - -#include - -#include -#include -#include - - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Multimedia) - - -class QMediaPlaylist; - -class Q_MULTIMEDIA_EXPORT QMediaPlayerControl : public QMediaControl -{ - Q_OBJECT - -public: - ~QMediaPlayerControl(); - - virtual QMediaPlayer::State state() const = 0; - - virtual QMediaPlayer::MediaStatus mediaStatus() const = 0; - - virtual qint64 duration() const = 0; - - virtual qint64 position() const = 0; - virtual void setPosition(qint64 position) = 0; - - virtual int volume() const = 0; - virtual void setVolume(int volume) = 0; - - virtual bool isMuted() const = 0; - virtual void setMuted(bool muted) = 0; - - virtual int bufferStatus() const = 0; - - virtual bool isAudioAvailable() const = 0; - virtual bool isVideoAvailable() const = 0; - - virtual bool isSeekable() const = 0; - - virtual QMediaTimeRange availablePlaybackRanges() const = 0; - - virtual qreal playbackRate() const = 0; - virtual void setPlaybackRate(qreal rate) = 0; - - virtual QMediaContent media() const = 0; - virtual const QIODevice *mediaStream() const = 0; - virtual void setMedia(const QMediaContent &media, QIODevice *stream) = 0; - - virtual void play() = 0; - virtual void pause() = 0; - virtual void stop() = 0; - -Q_SIGNALS: - void mediaChanged(const QMediaContent& content); - void durationChanged(qint64 duration); - void positionChanged(qint64 position); - void stateChanged(QMediaPlayer::State newState); - void mediaStatusChanged(QMediaPlayer::MediaStatus status); - void volumeChanged(int volume); - void mutedChanged(bool muted); - void audioAvailableChanged(bool audioAvailable); - void videoAvailableChanged(bool videoAvailable); - void bufferStatusChanged(int percentFilled); - void seekableChanged(bool); - void availablePlaybackRangesChanged(const QMediaTimeRange&); - void playbackRateChanged(qreal rate); - void error(int error, const QString &errorString); - -protected: - QMediaPlayerControl(QObject* parent = 0); -}; - -#define QMediaPlayerControl_iid "com.nokia.Qt.QMediaPlayerControl/1.0" -Q_MEDIA_DECLARE_CONTROL(QMediaPlayerControl, QMediaPlayerControl_iid) - -QT_END_NAMESPACE - -QT_END_HEADER - -#endif // QMEDIAPLAYERCONTROL_H - diff --git a/src/multimedia/video/qabstractvideobuffer.cpp b/src/multimedia/video/qabstractvideobuffer.cpp deleted file mode 100644 index e9d30d0..0000000 --- a/src/multimedia/video/qabstractvideobuffer.cpp +++ /dev/null @@ -1,200 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtMultimedia module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qabstractvideobuffer_p.h" - -#include - -QT_BEGIN_NAMESPACE - -/*! - \class QAbstractVideoBuffer - \brief The QAbstractVideoBuffer class is an abstraction for video data. - \since 4.6 - - The QVideoFrame class makes use of a QAbstractVideoBuffer internally to reference a buffer of - video data. Creating a subclass of QAbstractVideoBuffer will allow you to construct video - frames from preallocated or static buffers. - - The contents of a buffer can be accessed by mapping the buffer to memory using the map() - function which returns a pointer to memory containing the contents of the the video buffer. - The memory returned by map() is released by calling the unmap() function. - - The handle() of a buffer may also be used to manipulate it's contents using type specific APIs. - The type of a buffer's handle is given by the handleType() function. - - \sa QVideoFrame -*/ - -/*! - \enum QAbstractVideoBuffer::HandleType - - Identifies the type of a video buffers handle. - - \value NoHandle The buffer has no handle, its data can only be accessed by mapping the buffer. - \value GLTextureHandle The handle of the buffer is an OpenGL texture ID. - \value XvShmImageHandle The handle contains pointer to shared memory XVideo image. - \value CoreImageHandle The handle contains pointer to Mac OS X CIImage. - \value UserHandle Start value for user defined handle types. - - \sa handleType() -*/ - -/*! - \enum QAbstractVideoBuffer::MapMode - - Enumerates how a video buffer's data is mapped to memory. - - \value NotMapped The video buffer has is not mapped to memory. - \value ReadOnly The mapped memory is populated with data from the video buffer when mapped, but - the content of the mapped memory may be discarded when unmapped. - \value WriteOnly The mapped memory in unitialized when mapped, and the content will be used to - populate the video buffer when unmapped. - \value ReadWrite The mapped memory is populated with data from the video buffer, and the - video buffer is repopulated with the content of the mapped memory. - - \sa mapMode(), map() -*/ - -/*! - Constructs an abstract video buffer of the given \a type. -*/ - -QAbstractVideoBuffer::QAbstractVideoBuffer(HandleType type) - : d_ptr(new QAbstractVideoBufferPrivate) -{ - Q_D(QAbstractVideoBuffer); - - d->handleType = type; -} - -/*! - \internal -*/ - -QAbstractVideoBuffer::QAbstractVideoBuffer(QAbstractVideoBufferPrivate &dd, HandleType type) - : d_ptr(&dd) -{ - Q_D(QAbstractVideoBuffer); - - d->handleType = type; -} - -/*! - Destroys an abstract video buffer. -*/ - -QAbstractVideoBuffer::~QAbstractVideoBuffer() -{ - delete d_ptr; -} - -/*! - Returns the type of a video buffer's handle. - - \sa handle() -*/ - -QAbstractVideoBuffer::HandleType QAbstractVideoBuffer::handleType() const -{ - return d_func()->handleType; -} - -/*! - \fn QAbstractVideoBuffer::mapMode() const - - Returns the mode a video buffer is mapped in. - - \sa map() -*/ - -/*! - \fn QAbstractVideoBuffer::map(MapMode mode, int *numBytes, int *bytesPerLine) - - Maps the contents of a video buffer to memory. - - The map \a mode indicates whether the contents of the mapped memory should be read from and/or - written to the buffer. If the map mode includes the QAbstractVideoBuffer::ReadOnly flag the - mapped memory will be populated with the content of the video buffer when mapped. If the map - mode includes the QAbstractVideoBuffer::WriteOnly flag the content of the mapped memory will be - persisted in the buffer when unmapped. - - When access to the data is no longer needed be sure to call the unmap() function to release the - mapped memory. - - Returns a pointer to the mapped memory region, or a null pointer if the mapping failed. The - size in bytes of the mapped memory region is returned in \a numBytes, and the line stride in \a - bytesPerLine. - - When access to the data is no longer needed be sure to unmap() the buffer. - - \note Writing to memory that is mapped as read-only is undefined, and may result in changes - to shared data. - - \sa unmap(), mapMode() -*/ - -/*! - \fn QAbstractVideoBuffer::unmap() - - Releases the memory mapped by the map() function - - If the \l {QAbstractVideoBuffer::MapMode}{MapMode} included the QAbstractVideoBuffer::WriteOnly - flag this will persist the current content of the mapped memory to the video frame. - - \sa map() -*/ - -/*! - Returns a type specific handle to the data buffer. - - The type of the handle is given by handleType() function. - - \sa handleType() -*/ - -QVariant QAbstractVideoBuffer::handle() const -{ - return QVariant(); -} - - -QT_END_NAMESPACE diff --git a/src/multimedia/video/qabstractvideobuffer.h b/src/multimedia/video/qabstractvideobuffer.h deleted file mode 100644 index a8389db..0000000 --- a/src/multimedia/video/qabstractvideobuffer.h +++ /dev/null @@ -1,106 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtMultimedia module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QABSTRACTVIDEOBUFFER_H -#define QABSTRACTVIDEOBUFFER_H - -#include - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Multimedia) - -class QVariant; - -class QAbstractVideoBufferPrivate; - -class Q_MULTIMEDIA_EXPORT QAbstractVideoBuffer -{ -public: - enum HandleType - { - NoHandle, - GLTextureHandle, - XvShmImageHandle, - CoreImageHandle, - UserHandle = 1000 - }; - - enum MapMode - { - NotMapped = 0x00, - ReadOnly = 0x01, - WriteOnly = 0x02, - ReadWrite = ReadOnly | WriteOnly - }; - - QAbstractVideoBuffer(HandleType type); - virtual ~QAbstractVideoBuffer(); - - HandleType handleType() const; - - virtual MapMode mapMode() const = 0; - - virtual uchar *map(MapMode mode, int *numBytes, int *bytesPerLine) = 0; - virtual void unmap() = 0; - - virtual QVariant handle() const; - -protected: - QAbstractVideoBuffer(QAbstractVideoBufferPrivate &dd, HandleType type); - - QAbstractVideoBufferPrivate *d_ptr; - -private: - Q_DECLARE_PRIVATE(QAbstractVideoBuffer) - Q_DISABLE_COPY(QAbstractVideoBuffer) -}; - -QT_END_NAMESPACE - -Q_DECLARE_METATYPE(QAbstractVideoBuffer::HandleType) -Q_DECLARE_METATYPE(QAbstractVideoBuffer::MapMode) - -QT_END_HEADER - -#endif diff --git a/src/multimedia/video/qabstractvideobuffer_p.h b/src/multimedia/video/qabstractvideobuffer_p.h deleted file mode 100644 index c72f303..0000000 --- a/src/multimedia/video/qabstractvideobuffer_p.h +++ /dev/null @@ -1,73 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtMultimedia module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QABSTRACTVIDEOBUFFER_P_H -#define QABSTRACTVIDEOBUFFER_P_H - -// -// W A R N I N G -// ------------- -// -// This file is not part of the Qt API. It exists purely as an -// implementation detail. This header file may change from version to -// version without notice, or even be removed. -// -// We mean it. -// - -#include -#include - -QT_BEGIN_NAMESPACE - -class QAbstractVideoBufferPrivate -{ -public: - QAbstractVideoBufferPrivate() - : handleType(QAbstractVideoBuffer::NoHandle) - {} - - QAbstractVideoBuffer::HandleType handleType; -}; - -QT_END_NAMESPACE - -#endif diff --git a/src/multimedia/video/qabstractvideosurface.cpp b/src/multimedia/video/qabstractvideosurface.cpp deleted file mode 100644 index 3dabb6b..0000000 --- a/src/multimedia/video/qabstractvideosurface.cpp +++ /dev/null @@ -1,283 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtMultimedia module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qabstractvideosurface_p.h" - -QT_BEGIN_NAMESPACE - -/*! - \class QAbstractVideoSurface - \brief The QAbstractVideoSurface class is a base class for video presentation surfaces. - \since 4.6 - - The QAbstractVideoSurface class defines the standard interface that video producers use to - inter-operate with video presentation surfaces. It is not supposed to be instantiated directly. - Instead, you should subclass it to create new video surfaces. - - A video surface presents a continuous stream of identically formatted frames, where the format - of each frame is compatible with a stream format supplied when starting a presentation. - - A list of pixel formats a surface can present is given by the supportedPixelFormats() function, - and the isFormatSupported() function will test if a video surface format is supported. If a - format is not supported the nearestFormat() function may be able to suggest a similar format. - For example if a surface supports fixed set of resolutions it may suggest the smallest - supported resolution that contains the proposed resolution. - - The start() function takes a supported format and enables a video surface. Once started a - surface will begin displaying the frames it receives in the present() function. Surfaces may - hold a reference to the buffer of a presented video frame until a new frame is presented or - streaming is stopped. The stop() function will disable a surface and a release any video - buffers it holds references to. -*/ - -/*! - \enum QAbstractVideoSurface::Error - This enum describes the errors that may be returned by the error() function. - - \value NoError No error occurred. - \value UnsupportedFormatError A video format was not supported. - \value IncorrectFormatError A video frame was not compatible with the format of the surface. - \value StoppedError The surface has not been started. - \value ResourceError The surface could not allocate some resource. -*/ - -/*! - Constructs a video surface with the given \a parent. -*/ - -QAbstractVideoSurface::QAbstractVideoSurface(QObject *parent) - : QObject(*new QAbstractVideoSurfacePrivate, parent) -{ -} - -/*! - \internal -*/ - -QAbstractVideoSurface::QAbstractVideoSurface(QAbstractVideoSurfacePrivate &dd, QObject *parent) - : QObject(dd, parent) -{ -} - -/*! - Destroys a video surface. -*/ - -QAbstractVideoSurface::~QAbstractVideoSurface() -{ -} - -/*! - \fn QAbstractVideoSurface::supportedPixelFormats(QAbstractVideoBuffer::HandleType type) const - - Returns a list of pixel formats a video surface can present for a given handle \a type. - - The pixel formats returned for the QAbstractVideoBuffer::NoHandle type are valid for any buffer - that can be mapped in read-only mode. - - Types that are first in the list can be assumed to be faster to render. -*/ - -/*! - Tests a video surface \a format to determine if a surface can accept it. - - Returns true if the format is supported by the surface, and false otherwise. -*/ - -bool QAbstractVideoSurface::isFormatSupported(const QVideoSurfaceFormat &format) const -{ - return supportedPixelFormats(format.handleType()).contains(format.pixelFormat()); -} - -/*! - Returns a supported video surface format that is similar to \a format. - - A similar surface format is one that has the same \l {QVideoSurfaceFormat::pixelFormat()}{pixel - format} and \l {QVideoSurfaceFormat::handleType()}{handle type} but differs in some of the other - properties. For example if there are restrictions on the \l {QVideoSurfaceFormat::frameSize()} - {frame sizes} a video surface can accept it may suggest a format with a larger frame size and - a \l {QVideoSurfaceFormat::viewport()}{viewport} the size of the original frame size. - - If the format is already supported it will be returned unchanged, or if there is no similar - supported format an invalid format will be returned. -*/ - -QVideoSurfaceFormat QAbstractVideoSurface::nearestFormat(const QVideoSurfaceFormat &format) const -{ - return isFormatSupported(format) - ? format - : QVideoSurfaceFormat(); -} - -/*! - \fn QAbstractVideoSurface::supportedFormatsChanged() - - Signals that the set of formats supported by a video surface has changed. - - \sa supportedPixelFormats(), isFormatSupported() -*/ - -/*! - Returns the format of a video surface. -*/ - -QVideoSurfaceFormat QAbstractVideoSurface::surfaceFormat() const -{ - return d_func()->format; -} - -/*! - \fn QAbstractVideoSurface::surfaceFormatChanged(const QVideoSurfaceFormat &format) - - Signals that the configured \a format of a video surface has changed. - - \sa surfaceFormat(), start() -*/ - -/*! - Starts a video surface presenting \a format frames. - - Returns true if the surface was started, and false if an error occurred. - - \sa isActive(), stop() -*/ - -bool QAbstractVideoSurface::start(const QVideoSurfaceFormat &format) -{ - Q_D(QAbstractVideoSurface); - - bool wasActive = d->active; - - d->active = true; - d->format = format; - d->error = NoError; - - emit surfaceFormatChanged(d->format); - - if (!wasActive) - emit activeChanged(true); - - return true; -} - -/*! - Stops a video surface presenting frames and releases any resources acquired in start(). - - \sa isActive(), start() -*/ - -void QAbstractVideoSurface::stop() -{ - Q_D(QAbstractVideoSurface); - - if (d->active) { - d->format = QVideoSurfaceFormat(); - d->active = false; - - emit activeChanged(false); - emit surfaceFormatChanged(d->format); - } -} - -/*! - Indicates whether a video surface has been started. - - Returns true if the surface has been started, and false otherwise. -*/ - -bool QAbstractVideoSurface::isActive() const -{ - return d_func()->active; -} - -/*! - \fn QAbstractVideoSurface::activeChanged(bool active) - - Signals that the \a active state of a video surface has changed. - - \sa isActive(), start(), stop() -*/ - -/*! - \fn QAbstractVideoSurface::present(const QVideoFrame &frame) - - Presents a video \a frame. - - Returns true if the frame was presented, and false if an error occurred. - - Not all surfaces will block until the presentation of a frame has completed. Calling present() - on a non-blocking surface may fail if called before the presentation of a previous frame has - completed. In such cases the surface may not return to a ready state until it's had an - opportunity to process events. - - If present() fails for any other reason the surface will immediately enter the stopped state - and an error() value will be set. - - A video surface must be in the started state for present() to succeed, and the format of the - video frame must be compatible with the current video surface format. - - \sa error() -*/ - -/*! - Returns the last error that occurred. - - If a surface fails to start(), or stops unexpectedly this function can be called to discover - what error occurred. -*/ - -QAbstractVideoSurface::Error QAbstractVideoSurface::error() const -{ - return d_func()->error; -} - -/*! - Sets the value of error() to \a error. -*/ - -void QAbstractVideoSurface::setError(Error error) -{ - Q_D(QAbstractVideoSurface); - - d->error = error; -} - -QT_END_NAMESPACE diff --git a/src/multimedia/video/qabstractvideosurface.h b/src/multimedia/video/qabstractvideosurface.h deleted file mode 100644 index f2cae17..0000000 --- a/src/multimedia/video/qabstractvideosurface.h +++ /dev/null @@ -1,110 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtMultimedia module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QABSTRACTVIDEOSURFACE_H -#define QABSTRACTVIDEOSURFACE_H - -#include -#include - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Multimedia) - -class QRectF; -class QVideoSurfaceFormat; - -class QAbstractVideoSurfacePrivate; - -class Q_MULTIMEDIA_EXPORT QAbstractVideoSurface : public QObject -{ - Q_OBJECT - -public: - enum Error - { - NoError, - UnsupportedFormatError, - IncorrectFormatError, - StoppedError, - ResourceError - }; - - explicit QAbstractVideoSurface(QObject *parent = 0); - ~QAbstractVideoSurface(); - - virtual QList supportedPixelFormats( - QAbstractVideoBuffer::HandleType handleType = QAbstractVideoBuffer::NoHandle) const = 0; - virtual bool isFormatSupported(const QVideoSurfaceFormat &format) const; - virtual QVideoSurfaceFormat nearestFormat(const QVideoSurfaceFormat &format) const; - - QVideoSurfaceFormat surfaceFormat() const; - - virtual bool start(const QVideoSurfaceFormat &format); - virtual void stop(); - - bool isActive() const; - - virtual bool present(const QVideoFrame &frame) = 0; - - Error error() const; - -Q_SIGNALS: - void activeChanged(bool active); - void surfaceFormatChanged(const QVideoSurfaceFormat &format); - void supportedFormatsChanged(); - -protected: - QAbstractVideoSurface(QAbstractVideoSurfacePrivate &dd, QObject *parent); - - void setError(Error error); - -private: - Q_DECLARE_PRIVATE(QAbstractVideoSurface) -}; - -QT_END_NAMESPACE - -QT_END_HEADER - -#endif diff --git a/src/multimedia/video/qabstractvideosurface_p.h b/src/multimedia/video/qabstractvideosurface_p.h deleted file mode 100644 index 42df112..0000000 --- a/src/multimedia/video/qabstractvideosurface_p.h +++ /dev/null @@ -1,78 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtMultimedia module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QABSTRACTVIDEOSURFACE_P_H -#define QABSTRACTVIDEOSURFACE_P_H - -// -// W A R N I N G -// ------------- -// -// This file is not part of the Qt API. It exists purely as an -// implementation detail. This header file may change from version to -// version without notice, or even be removed. -// -// We mean it. -// - -#include -#include -#include - -QT_BEGIN_NAMESPACE - -class QAbstractVideoSurfacePrivate : public QObjectPrivate -{ -public: - QAbstractVideoSurfacePrivate() - : error(QAbstractVideoSurface::NoError) - , active(false) - { - } - - mutable QAbstractVideoSurface::Error error; - QVideoSurfaceFormat format; - bool active; -}; - -QT_END_NAMESPACE - -#endif diff --git a/src/multimedia/video/qimagevideobuffer.cpp b/src/multimedia/video/qimagevideobuffer.cpp deleted file mode 100644 index e3e1585..0000000 --- a/src/multimedia/video/qimagevideobuffer.cpp +++ /dev/null @@ -1,106 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtMultimedia module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qimagevideobuffer_p.h" - -#include - -#include -#include - -QT_BEGIN_NAMESPACE - -class QImageVideoBufferPrivate : public QAbstractVideoBufferPrivate -{ -public: - QImageVideoBufferPrivate() - : mapMode(QAbstractVideoBuffer::NotMapped) - { - } - - QAbstractVideoBuffer::MapMode mapMode; - QImage image; -}; - -QImageVideoBuffer::QImageVideoBuffer(const QImage &image) - : QAbstractVideoBuffer(*new QImageVideoBufferPrivate, NoHandle) -{ - Q_D(QImageVideoBuffer); - - d->image = image; -} - -QImageVideoBuffer::~QImageVideoBuffer() -{ -} - -QAbstractVideoBuffer::MapMode QImageVideoBuffer::mapMode() const -{ - return d_func()->mapMode; -} - -uchar *QImageVideoBuffer::map(MapMode mode, int *numBytes, int *bytesPerLine) -{ - Q_D(QImageVideoBuffer); - - if (d->mapMode == NotMapped && d->image.bits() && mode != NotMapped) { - d->mapMode = mode; - - if (numBytes) - *numBytes = d->image.byteCount(); - - if (bytesPerLine) - *bytesPerLine = d->image.bytesPerLine(); - - return d->image.bits(); - } else { - return 0; - } -} - -void QImageVideoBuffer::unmap() -{ - Q_D(QImageVideoBuffer); - - d->mapMode = NotMapped; -} - -QT_END_NAMESPACE diff --git a/src/multimedia/video/qimagevideobuffer_p.h b/src/multimedia/video/qimagevideobuffer_p.h deleted file mode 100644 index 82075d7..0000000 --- a/src/multimedia/video/qimagevideobuffer_p.h +++ /dev/null @@ -1,79 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtMultimedia module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QIMAGEVIDEOBUFFER_P_H -#define QIMAGEVIDEOBUFFER_P_H - -// -// W A R N I N G -// ------------- -// -// This file is not part of the Qt API. It exists purely as an -// implementation detail. This header file may change from version to -// version without notice, or even be removed. -// -// We mean it. -// - -#include - -QT_BEGIN_NAMESPACE - -class QImage; - -class QImageVideoBufferPrivate; - -class Q_MULTIMEDIA_EXPORT QImageVideoBuffer : public QAbstractVideoBuffer -{ - Q_DECLARE_PRIVATE(QImageVideoBuffer) -public: - QImageVideoBuffer(const QImage &image); - ~QImageVideoBuffer(); - - MapMode mapMode() const; - - uchar *map(MapMode mode, int *numBytes, int *bytesPerLine); - void unmap(); -}; - -QT_END_NAMESPACE - -#endif diff --git a/src/multimedia/video/qmemoryvideobuffer.cpp b/src/multimedia/video/qmemoryvideobuffer.cpp deleted file mode 100644 index 2e892b7..0000000 --- a/src/multimedia/video/qmemoryvideobuffer.cpp +++ /dev/null @@ -1,129 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtMultimedia module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qmemoryvideobuffer_p.h" - -#include -#include - -QT_BEGIN_NAMESPACE - -class QMemoryVideoBufferPrivate : public QAbstractVideoBufferPrivate -{ -public: - QMemoryVideoBufferPrivate() - : bytesPerLine(0) - , mapMode(QAbstractVideoBuffer::NotMapped) - { - } - - int bytesPerLine; - QAbstractVideoBuffer::MapMode mapMode; - QByteArray data; -}; - -/*! - \class QMemoryVideoBuffer - \brief The QMemoryVideoBuffer class provides a system memory allocated video data buffer. - \internal - - QMemoryVideoBuffer is the default video buffer for allocating system memory. It may be used to - allocate memory for a QVideoFrame without implementing your own QAbstractVideoBuffer. -*/ - -/*! - Constructs a video buffer with an image stride of \a bytesPerLine from a byte \a array. -*/ -QMemoryVideoBuffer::QMemoryVideoBuffer(const QByteArray &array, int bytesPerLine) - : QAbstractVideoBuffer(*new QMemoryVideoBufferPrivate, NoHandle) -{ - Q_D(QMemoryVideoBuffer); - - d->data = array; - d->bytesPerLine = bytesPerLine; -} - -/*! - Destroys a system memory allocated video buffer. -*/ -QMemoryVideoBuffer::~QMemoryVideoBuffer() -{ -} - -/*! - \reimp -*/ -QAbstractVideoBuffer::MapMode QMemoryVideoBuffer::mapMode() const -{ - return d_func()->mapMode; -} - -/*! - \reimp -*/ -uchar *QMemoryVideoBuffer::map(MapMode mode, int *numBytes, int *bytesPerLine) -{ - Q_D(QMemoryVideoBuffer); - - if (d->mapMode == NotMapped && d->data.data() && mode != NotMapped) { - d->mapMode = mode; - - if (numBytes) - *numBytes = d->data.size(); - - if (bytesPerLine) - *bytesPerLine = d->bytesPerLine; - - return reinterpret_cast(d->data.data()); - } else { - return 0; - } -} - -/*! - \reimp -*/ -void QMemoryVideoBuffer::unmap() -{ - d_func()->mapMode = NotMapped; -} - -QT_END_NAMESPACE diff --git a/src/multimedia/video/qmemoryvideobuffer_p.h b/src/multimedia/video/qmemoryvideobuffer_p.h deleted file mode 100644 index c66cf93..0000000 --- a/src/multimedia/video/qmemoryvideobuffer_p.h +++ /dev/null @@ -1,83 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtMultimedia module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QMEMORYVIDEOBUFFER_P_H -#define QMEMORYVIDEOBUFFER_P_H - -#include - -// -// W A R N I N G -// ------------- -// -// This file is not part of the Qt API. It exists purely as an -// implementation detail. This header file may change from version to -// version without notice, or even be removed. -// -// We mean it. -// - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Multimedia) - -class QMemoryVideoBufferPrivate; - -class Q_MULTIMEDIA_EXPORT QMemoryVideoBuffer : public QAbstractVideoBuffer -{ - Q_DECLARE_PRIVATE(QMemoryVideoBuffer) -public: - QMemoryVideoBuffer(const QByteArray &data, int bytesPerLine); - ~QMemoryVideoBuffer(); - - MapMode mapMode() const; - - uchar *map(MapMode mode, int *numBytes, int *bytesPerLine); - void unmap(); -}; - -QT_END_NAMESPACE - -QT_END_HEADER - -#endif diff --git a/src/multimedia/video/qvideoframe.cpp b/src/multimedia/video/qvideoframe.cpp deleted file mode 100644 index 2d66d9e..0000000 --- a/src/multimedia/video/qvideoframe.cpp +++ /dev/null @@ -1,741 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtMultimedia module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qvideoframe.h" - -#include -#include - -#include -#include -#include -#include -#include - -QT_BEGIN_NAMESPACE - -class QVideoFramePrivate : public QSharedData -{ -public: - QVideoFramePrivate() - : startTime(-1) - , endTime(-1) - , data(0) - , mappedBytes(0) - , bytesPerLine(0) - , pixelFormat(QVideoFrame::Format_Invalid) - , fieldType(QVideoFrame::ProgressiveFrame) - , buffer(0) - { - } - - QVideoFramePrivate(const QSize &size, QVideoFrame::PixelFormat format) - : size(size) - , startTime(-1) - , endTime(-1) - , data(0) - , mappedBytes(0) - , bytesPerLine(0) - , pixelFormat(format) - , fieldType(QVideoFrame::ProgressiveFrame) - , buffer(0) - { - } - - ~QVideoFramePrivate() - { - delete buffer; - } - - QSize size; - qint64 startTime; - qint64 endTime; - uchar *data; - int mappedBytes; - int bytesPerLine; - QVideoFrame::PixelFormat pixelFormat; - QVideoFrame::FieldType fieldType; - QAbstractVideoBuffer *buffer; - -private: - Q_DISABLE_COPY(QVideoFramePrivate) -}; - -/*! - \class QVideoFrame - \brief The QVideoFrame class provides a representation of a frame of video data. - \since 4.6 - - A QVideoFrame encapsulates the data of a video frame, and information about the frame. - - The contents of a video frame can be mapped to memory using the map() function. While - mapped the video data can accessed using the bits() function which returns a pointer to a - buffer, the total size of which is given by the mappedBytes(), and the size of each line is given - by bytesPerLine(). The return value of the handle() function may be used to access frame data - using the internal buffer's native APIs. - - The video data in a QVideoFrame is encapsulated in a QAbstractVideoBuffer. A QVideoFrame - may be constructed from any buffer type by subclassing the QAbstractVideoBuffer class. - - \note QVideoFrame is explicitly shared, any change made to video frame will also apply to any - copies. -*/ - -/*! - \enum QVideoFrame::PixelFormat - - Enumerates video data types. - - \value Format_Invalid - The frame is invalid. - - \value Format_ARGB32 - The frame is stored using a 32-bit ARGB format (0xAARRGGBB). This is equivalent to - QImage::Format_ARGB32. - - \value Format_ARGB32_Premultiplied - The frame stored using a premultiplied 32-bit ARGB format (0xAARRGGBB). This is equivalent - to QImage::Format_ARGB32_Premultiplied. - - \value Format_RGB32 - The frame stored using a 32-bit RGB format (0xffRRGGBB). This is equivalent to - QImage::Format_RGB32 - - \value Format_RGB24 - The frame is stored using a 24-bit RGB format (8-8-8). This is equivalent to - QImage::Format_RGB888 - - \value Format_RGB565 - The frame is stored using a 16-bit RGB format (5-6-5). This is equivalent to - QImage::Format_RGB16. - - \value Format_RGB555 - The frame is stored using a 16-bit RGB format (5-5-5). This is equivalent to - QImage::Format_RGB555. - - \value Format_ARGB8565_Premultiplied - The frame is stored using a 24-bit premultiplied ARGB format (8-6-6-5). - - \value Format_BGRA32 - The frame is stored using a 32-bit ARGB format (0xBBGGRRAA). - - \value Format_BGRA32_Premultiplied - The frame is stored using a premultiplied 32bit BGRA format. - - \value Format_BGR32 - The frame is stored using a 32-bit BGR format (0xBBGGRRff). - - \value Format_BGR24 - The frame is stored using a 24-bit BGR format (0xBBGGRR). - - \value Format_BGR565 - The frame is stored using a 16-bit BGR format (5-6-5). - - \value Format_BGR555 - The frame is stored using a 16-bit BGR format (5-5-5). - - \value Format_BGRA5658_Premultiplied - The frame is stored using a 24-bit premultiplied BGRA format (5-6-5-8). - - \value Format_AYUV444 - The frame is stored using a packed 32-bit AYUV format (0xAAYYUUVV). - - \value Format_AYUV444_Premultiplied - The frame is stored using a packed premultiplied 32-bit AYUV format (0xAAYYUUVV). - - \value Format_YUV444 - The frame is stored using a 24-bit packed YUV format (8-8-8). - - \value Format_YUV420P - The frame is stored using an 8-bit per component planar YUV format with the U and V planes - horizontally and vertically sub-sampled, i.e. the height and width of the U and V planes are - half that of the Y plane. - - \value Format_YV12 - The frame is stored using an 8-bit per component planar YVU format with the V and U planes - horizontally and vertically sub-sampled, i.e. the height and width of the V and U planes are - half that of the Y plane. - - \value Format_UYVY - The frame is stored using an 8-bit per component packed YUV format with the U and V planes - horizontally sub-sampled (U-Y-V-Y), i.e. two horizontally adjacent pixels are stored as a 32-bit - macropixel which has a Y value for each pixel and common U and V values. - - \value Format_YUYV - The frame is stored using an 8-bit per component packed YUV format with the U and V planes - horizontally sub-sampled (Y-U-Y-V), i.e. two horizontally adjacent pixels are stored as a 32-bit - macropixel which has a Y value for each pixel and common U and V values. - - \value Format_NV12 - The frame is stored using an 8-bit per component semi-planar YUV format with a Y plane (Y) - followed by a horizontally and vertically sub-sampled, packed UV plane (U-V). - - \value Format_NV21 - The frame is stored using an 8-bit per component semi-planar YUV format with a Y plane (Y) - followed by a horizontally and vertically sub-sampled, packed VU plane (V-U). - - \value Format_IMC1 - The frame is stored using an 8-bit per component planar YUV format with the U and V planes - horizontally and vertically sub-sampled. This is similar to the Format_YUV420P type, except - that the bytes per line of the U and V planes are padded out to the same stride as the Y plane. - - \value Format_IMC2 - The frame is stored using an 8-bit per component planar YUV format with the U and V planes - horizontally and vertically sub-sampled. This is similar to the Format_YUV420P type, except - that the lines of the U and V planes are interleaved, i.e. each line of U data is followed by a - line of V data creating a single line of the same stride as the Y data. - - \value Format_IMC3 - The frame is stored using an 8-bit per component planar YVU format with the V and U planes - horizontally and vertically sub-sampled. This is similar to the Format_YV12 type, except that - the bytes per line of the V and U planes are padded out to the same stride as the Y plane. - - \value Format_IMC4 - The frame is stored using an 8-bit per component planar YVU format with the V and U planes - horizontally and vertically sub-sampled. This is similar to the Format_YV12 type, except that - the lines of the V and U planes are interleaved, i.e. each line of V data is followed by a line - of U data creating a single line of the same stride as the Y data. - - \value Format_Y8 - The frame is stored using an 8-bit greyscale format. - - \value Format_Y16 - The frame is stored using a 16-bit linear greyscale format. Little endian. - - \value Format_User - Start value for user defined pixel formats. -*/ - -/*! - \enum QVideoFrame::FieldType - - Specifies the field an interlaced video frame belongs to. - - \value ProgressiveFrame The frame is not interlaced. - \value TopField The frame contains a top field. - \value BottomField The frame contains a bottom field. - \value InterlacedFrame The frame contains a merged top and bottom field. -*/ - -/*! - Constructs a null video frame. -*/ - -QVideoFrame::QVideoFrame() - : d(new QVideoFramePrivate) -{ -} - -/*! - Constructs a video frame from a \a buffer of the given pixel \a format and \a size in pixels. - - \note This doesn't increment the reference count of the video buffer. -*/ - -QVideoFrame::QVideoFrame( - QAbstractVideoBuffer *buffer, const QSize &size, PixelFormat format) - : d(new QVideoFramePrivate(size, format)) -{ - d->buffer = buffer; -} - -/*! - Constructs a video frame of the given pixel \a format and \a size in pixels. - - The \a bytesPerLine (stride) is the length of each scan line in bytes, and \a bytes is the total - number of bytes that must be allocated for the frame. -*/ - -QVideoFrame::QVideoFrame(int bytes, const QSize &size, int bytesPerLine, PixelFormat format) - : d(new QVideoFramePrivate(size, format)) -{ - if (bytes > 0) { - QByteArray data; - data.resize(bytes); - - // Check the memory was successfully allocated. - if (!data.isEmpty()) - d->buffer = new QMemoryVideoBuffer(data, bytesPerLine); - } -} - -/*! - Constructs a video frame from an \a image. - - \note This will construct an invalid video frame if there is no frame type equivalent to the - image format. - - \sa pixelFormatFromImageFormat() -*/ - -QVideoFrame::QVideoFrame(const QImage &image) - : d(new QVideoFramePrivate( - image.size(), pixelFormatFromImageFormat(image.format()))) -{ - if (d->pixelFormat != Format_Invalid) - d->buffer = new QImageVideoBuffer(image); -} - -/*! - Constructs a copy of \a other. -*/ - -QVideoFrame::QVideoFrame(const QVideoFrame &other) - : d(other.d) -{ -} - -/*! - Assigns the contents of \a other to a video frame. -*/ - -QVideoFrame &QVideoFrame::operator =(const QVideoFrame &other) -{ - d = other.d; - - return *this; -} - -/*! - Destroys a video frame. -*/ - -QVideoFrame::~QVideoFrame() -{ -} - -/*! - Identifies whether a video frame is valid. - - An invalid frame has no video buffer associated with it. - - Returns true if the frame is valid, and false if it is not. -*/ - -bool QVideoFrame::isValid() const -{ - return d->buffer != 0; -} - -/*! - Returns the color format of a video frame. -*/ - -QVideoFrame::PixelFormat QVideoFrame::pixelFormat() const -{ - return d->pixelFormat; -} - -/*! - Returns the type of a video frame's handle. -*/ - -QAbstractVideoBuffer::HandleType QVideoFrame::handleType() const -{ - return d->buffer ? d->buffer->handleType() : QAbstractVideoBuffer::NoHandle; -} - -/*! - Returns the size of a video frame. -*/ - -QSize QVideoFrame::size() const -{ - return d->size; -} - -/*! - Returns the width of a video frame. -*/ - -int QVideoFrame::width() const -{ - return d->size.width(); -} - -/*! - Returns the height of a video frame. -*/ - -int QVideoFrame::height() const -{ - return d->size.height(); -} - -/*! - Returns the field an interlaced video frame belongs to. - - If the video is not interlaced this will return WholeFrame. -*/ - -QVideoFrame::FieldType QVideoFrame::fieldType() const -{ - return d->fieldType; -} - -/*! - Sets the \a field an interlaced video frame belongs to. -*/ - -void QVideoFrame::setFieldType(QVideoFrame::FieldType field) -{ - d->fieldType = field; -} - -/*! - Identifies if a video frame's contents are currently mapped to system memory. - - This is a convenience function which checks that the \l {QAbstractVideoBuffer::MapMode}{MapMode} - of the frame is not equal to QAbstractVideoBuffer::NotMapped. - - Returns true if the contents of the video frame are mapped to system memory, and false - otherwise. - - \sa mapMode() QAbstractVideoBuffer::MapMode -*/ - -bool QVideoFrame::isMapped() const -{ - return d->buffer != 0 && d->buffer->mapMode() != QAbstractVideoBuffer::NotMapped; -} - -/*! - Identifies if the mapped contents of a video frame will be persisted when the frame is unmapped. - - This is a convenience function which checks if the \l {QAbstractVideoBuffer::MapMode}{MapMode} - contains the QAbstractVideoBuffer::WriteOnly flag. - - Returns true if the video frame will be updated when unmapped, and false otherwise. - - \note The result of altering the data of a frame that is mapped in read-only mode is undefined. - Depending on the buffer implementation the changes may be persisted, or worse alter a shared - buffer. - - \sa mapMode(), QAbstractVideoBuffer::MapMode -*/ - -bool QVideoFrame::isWritable() const -{ - return d->buffer != 0 && (d->buffer->mapMode() & QAbstractVideoBuffer::WriteOnly); -} - -/*! - Identifies if the mapped contents of a video frame were read from the frame when it was mapped. - - This is a convenience function which checks if the \l {QAbstractVideoBuffer::MapMode}{MapMode} - contains the QAbstractVideoBuffer::WriteOnly flag. - - Returns true if the contents of the mapped memory were read from the video frame, and false - otherwise. - - \sa mapMode(), QAbstractVideoBuffer::MapMode -*/ - -bool QVideoFrame::isReadable() const -{ - return d->buffer != 0 && (d->buffer->mapMode() & QAbstractVideoBuffer::ReadOnly); -} - -/*! - Returns the mode a video frame was mapped to system memory in. - - \sa map(), QAbstractVideoBuffer::MapMode -*/ - -QAbstractVideoBuffer::MapMode QVideoFrame::mapMode() const -{ - return d->buffer != 0 ? d->buffer->mapMode() : QAbstractVideoBuffer::NotMapped; -} - -/*! - Maps the contents of a video frame to memory. - - The map \a mode indicates whether the contents of the mapped memory should be read from and/or - written to the frame. If the map mode includes the QAbstractVideoBuffer::ReadOnly flag the - mapped memory will be populated with the content of the video frame when mapped. If the map - mode inclues the QAbstractVideoBuffer::WriteOnly flag the content of the mapped memory will be - persisted in the frame when unmapped. - - While mapped the contents of a video frame can be accessed directly through the pointer returned - by the bits() function. - - When access to the data is no longer needed be sure to call the unmap() function to release the - mapped memory. - - Returns true if the buffer was mapped to memory in the given \a mode and false otherwise. - - \sa unmap(), mapMode(), bits() -*/ - -bool QVideoFrame::map(QAbstractVideoBuffer::MapMode mode) -{ - if (d->buffer != 0 && d->data == 0) { - Q_ASSERT(d->bytesPerLine == 0); - Q_ASSERT(d->mappedBytes == 0); - - d->data = d->buffer->map(mode, &d->mappedBytes, &d->bytesPerLine); - - return d->data != 0; - } - - return false; -} - -/*! - Releases the memory mapped by the map() function. - - If the \l {QAbstractVideoBuffer::MapMode}{MapMode} included the QAbstractVideoBuffer::WriteOnly - flag this will persist the current content of the mapped memory to the video frame. - - \sa map() -*/ - -void QVideoFrame::unmap() -{ - if (d->data != 0) { - d->mappedBytes = 0; - d->bytesPerLine = 0; - d->data = 0; - - d->buffer->unmap(); - } -} - -/*! - Returns the number of bytes in a scan line. - - \note This is the bytes per line of the first plane only. The bytes per line of subsequent - planes should be calculated as per the frame type. - - This value is only valid while the frame data is \l {map()}{mapped}. - - \sa bits(), map(), mappedBytes() -*/ - -int QVideoFrame::bytesPerLine() const -{ - return d->bytesPerLine; -} - -/*! - Returns a pointer to the start of the frame data buffer. - - This value is only valid while the frame data is \l {map()}{mapped}. - - \sa map(), mappedBytes(), bytesPerLine() -*/ - -uchar *QVideoFrame::bits() -{ - return d->data; -} - -/*! - Returns a pointer to the start of the frame data buffer. - - This value is only valid while the frame data is \l {map()}{mapped}. - - \sa map(), mappedBytes(), bytesPerLine() -*/ - -const uchar *QVideoFrame::bits() const -{ - return d->data; -} - -/*! - Returns the number of bytes occupied by the mapped frame data. - - This value is only valid while the frame data is \l {map()}{mapped}. - - \sa map() -*/ - -int QVideoFrame::mappedBytes() const -{ - return d->mappedBytes; -} - -/*! - Returns a type specific handle to a video frame's buffer. - - For an OpenGL texture this would be the texture ID. - - \sa QAbstractVideoBuffer::handle() -*/ - -QVariant QVideoFrame::handle() const -{ - return d->buffer != 0 ? d->buffer->handle() : QVariant(); -} - -/*! - Returns the presentation time when the frame should be displayed. -*/ - -qint64 QVideoFrame::startTime() const -{ - return d->startTime; -} - -/*! - Sets the presentation \a time when the frame should be displayed. -*/ - -void QVideoFrame::setStartTime(qint64 time) -{ - d->startTime = time; -} - -/*! - Returns the presentation time when a frame should stop being displayed. -*/ - -qint64 QVideoFrame::endTime() const -{ - return d->endTime; -} - -/*! - Sets the presentation \a time when a frame should stop being displayed. -*/ - -void QVideoFrame::setEndTime(qint64 time) -{ - d->endTime = time; -} - -/*! - Returns an video pixel format equivalent to an image \a format. If there is no equivalent - format QVideoFrame::InvalidType is returned instead. -*/ - -QVideoFrame::PixelFormat QVideoFrame::pixelFormatFromImageFormat(QImage::Format format) -{ - switch (format) { - case QImage::Format_Invalid: - case QImage::Format_Mono: - case QImage::Format_MonoLSB: - case QImage::Format_Indexed8: - return Format_Invalid; - case QImage::Format_RGB32: - return Format_RGB32; - case QImage::Format_ARGB32: - return Format_ARGB32; - case QImage::Format_ARGB32_Premultiplied: - return Format_ARGB32_Premultiplied; - case QImage::Format_RGB16: - return Format_RGB565; - case QImage::Format_ARGB8565_Premultiplied: - case QImage::Format_RGB666: - case QImage::Format_ARGB6666_Premultiplied: - return Format_Invalid; - case QImage::Format_RGB555: - return Format_RGB555; - case QImage::Format_ARGB8555_Premultiplied: - return Format_Invalid; - case QImage::Format_RGB888: - return Format_RGB24; - case QImage::Format_RGB444: - case QImage::Format_ARGB4444_Premultiplied: - return Format_Invalid; - case QImage::NImageFormats: - return Format_Invalid; - } - return Format_Invalid; -} - -/*! - Returns an image format equivalent to a video frame pixel \a format. If there is no equivalent - format QImage::Format_Invalid is returned instead. -*/ - -QImage::Format QVideoFrame::imageFormatFromPixelFormat(PixelFormat format) -{ - switch (format) { - case Format_Invalid: - return QImage::Format_Invalid; - case Format_ARGB32: - return QImage::Format_ARGB32; - case Format_ARGB32_Premultiplied: - return QImage::Format_ARGB32_Premultiplied; - case Format_RGB32: - return QImage::Format_RGB32; - case Format_RGB24: - return QImage::Format_RGB888; - case Format_RGB565: - return QImage::Format_RGB16; - case Format_RGB555: - return QImage::Format_RGB555; - case Format_ARGB8565_Premultiplied: - return QImage::Format_ARGB8565_Premultiplied; - case Format_BGRA32: - case Format_BGRA32_Premultiplied: - case Format_BGR32: - case Format_BGR24: - return QImage::Format_Invalid; - case Format_BGR565: - case Format_BGR555: - case Format_BGRA5658_Premultiplied: - case Format_AYUV444: - case Format_AYUV444_Premultiplied: - case Format_YUV444: - case Format_YUV420P: - case Format_YV12: - case Format_UYVY: - case Format_YUYV: - case Format_NV12: - case Format_NV21: - case Format_IMC1: - case Format_IMC2: - case Format_IMC3: - case Format_IMC4: - case Format_Y8: - case Format_Y16: - return QImage::Format_Invalid; - case Format_User: - return QImage::Format_Invalid; - } - return QImage::Format_Invalid; -} - -QT_END_NAMESPACE - diff --git a/src/multimedia/video/qvideoframe.h b/src/multimedia/video/qvideoframe.h deleted file mode 100644 index 668a738..0000000 --- a/src/multimedia/video/qvideoframe.h +++ /dev/null @@ -1,169 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtMultimedia module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QVIDEOFRAME_H -#define QVIDEOFRAME_H - -#include -#include -#include -#include - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Multimedia) - -class QSize; -class QVariant; - -class QVideoFramePrivate; - -class Q_MULTIMEDIA_EXPORT QVideoFrame -{ -public: - enum FieldType - { - ProgressiveFrame, - TopField, - BottomField, - InterlacedFrame - }; - - enum PixelFormat - { - Format_Invalid, - Format_ARGB32, - Format_ARGB32_Premultiplied, - Format_RGB32, - Format_RGB24, - Format_RGB565, - Format_RGB555, - Format_ARGB8565_Premultiplied, - Format_BGRA32, - Format_BGRA32_Premultiplied, - Format_BGR32, - Format_BGR24, - Format_BGR565, - Format_BGR555, - Format_BGRA5658_Premultiplied, - - Format_AYUV444, - Format_AYUV444_Premultiplied, - Format_YUV444, - Format_YUV420P, - Format_YV12, - Format_UYVY, - Format_YUYV, - Format_NV12, - Format_NV21, - Format_IMC1, - Format_IMC2, - Format_IMC3, - Format_IMC4, - Format_Y8, - Format_Y16, - - Format_User = 1000 - }; - - QVideoFrame(); - QVideoFrame(QAbstractVideoBuffer *buffer, const QSize &size, PixelFormat format); - QVideoFrame(int bytes, const QSize &size, int bytesPerLine, PixelFormat format); - QVideoFrame(const QImage &image); - QVideoFrame(const QVideoFrame &other); - ~QVideoFrame(); - - QVideoFrame &operator =(const QVideoFrame &other); - - bool isValid() const; - - PixelFormat pixelFormat() const; - - QAbstractVideoBuffer::HandleType handleType() const; - - QSize size() const; - int width() const; - int height() const; - - FieldType fieldType() const; - void setFieldType(FieldType); - - bool isMapped() const; - bool isReadable() const; - bool isWritable() const; - - QAbstractVideoBuffer::MapMode mapMode() const; - - bool map(QAbstractVideoBuffer::MapMode mode); - void unmap(); - - int bytesPerLine() const; - - uchar *bits(); - const uchar *bits() const; - int mappedBytes() const; - - QVariant handle() const; - - qint64 startTime() const; - void setStartTime(qint64 time); - - qint64 endTime() const; - void setEndTime(qint64 time); - - static PixelFormat pixelFormatFromImageFormat(QImage::Format format); - static QImage::Format imageFormatFromPixelFormat(PixelFormat format); - -private: - QExplicitlySharedDataPointer d; -}; - -QT_END_NAMESPACE - -Q_DECLARE_METATYPE(QVideoFrame::FieldType) -Q_DECLARE_METATYPE(QVideoFrame::PixelFormat) - -QT_END_HEADER - -#endif - diff --git a/src/multimedia/video/qvideosurfaceformat.cpp b/src/multimedia/video/qvideosurfaceformat.cpp deleted file mode 100644 index 1fc13a6..0000000 --- a/src/multimedia/video/qvideosurfaceformat.cpp +++ /dev/null @@ -1,704 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtMultimedia module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qvideosurfaceformat.h" - -#include -#include -#include -#include -#include - -QT_BEGIN_NAMESPACE - -class QVideoSurfaceFormatPrivate : public QSharedData -{ -public: - QVideoSurfaceFormatPrivate() - : pixelFormat(QVideoFrame::Format_Invalid) - , handleType(QAbstractVideoBuffer::NoHandle) - , scanLineDirection(QVideoSurfaceFormat::TopToBottom) - , pixelAspectRatio(1, 1) - , ycbcrColorSpace(QVideoSurfaceFormat::YCbCr_Undefined) - , frameRate(0.0) - { - } - - QVideoSurfaceFormatPrivate( - const QSize &size, - QVideoFrame::PixelFormat format, - QAbstractVideoBuffer::HandleType type) - : pixelFormat(format) - , handleType(type) - , scanLineDirection(QVideoSurfaceFormat::TopToBottom) - , frameSize(size) - , pixelAspectRatio(1, 1) - , ycbcrColorSpace(QVideoSurfaceFormat::YCbCr_Undefined) - , viewport(QPoint(0, 0), size) - , frameRate(0.0) - { - } - - QVideoSurfaceFormatPrivate(const QVideoSurfaceFormatPrivate &other) - : QSharedData(other) - , pixelFormat(other.pixelFormat) - , handleType(other.handleType) - , scanLineDirection(other.scanLineDirection) - , frameSize(other.frameSize) - , pixelAspectRatio(other.pixelAspectRatio) - , ycbcrColorSpace(other.ycbcrColorSpace) - , viewport(other.viewport) - , frameRate(other.frameRate) - , propertyNames(other.propertyNames) - , propertyValues(other.propertyValues) - { - } - - bool operator ==(const QVideoSurfaceFormatPrivate &other) const - { - if (pixelFormat == other.pixelFormat - && handleType == other.handleType - && scanLineDirection == other.scanLineDirection - && frameSize == other.frameSize - && pixelAspectRatio == other.pixelAspectRatio - && viewport == other.viewport - && frameRatesEqual(frameRate, other.frameRate) - && ycbcrColorSpace == other.ycbcrColorSpace - && propertyNames.count() == other.propertyNames.count()) { - for (int i = 0; i < propertyNames.count(); ++i) { - int j = other.propertyNames.indexOf(propertyNames.at(i)); - - if (j == -1 || propertyValues.at(i) != other.propertyValues.at(j)) - return false; - } - return true; - } else { - return false; - } - } - - inline static bool frameRatesEqual(qreal r1, qreal r2) - { - return qAbs(r1 - r2) <= 0.00001 * qMin(qAbs(r1), qAbs(r2)); - } - - QVideoFrame::PixelFormat pixelFormat; - QAbstractVideoBuffer::HandleType handleType; - QVideoSurfaceFormat::Direction scanLineDirection; - QSize frameSize; - QSize pixelAspectRatio; - QVideoSurfaceFormat::YCbCrColorSpace ycbcrColorSpace; - QRect viewport; - qreal frameRate; - QList propertyNames; - QList propertyValues; -}; - -/*! - \class QVideoSurfaceFormat - \brief The QVideoSurfaceFormat class specifies the stream format of a video presentation - surface. - \since 4.6 - - A video surface presents a stream of video frames. The surface's format describes the type of - the frames and determines how they should be presented. - - The core properties of a video stream required to setup a video surface are the pixel format - given by pixelFormat(), and the frame dimensions given by frameSize(). - - If the surface is to present frames using a frame's handle a surface format will also include - a handle type which is given by the handleType() function. - - The region of a frame that is actually displayed on a video surface is given by the viewport(). - A stream may have a viewport less than the entire region of a frame to allow for videos smaller - than the nearest optimal size of a video frame. For example the width of a frame may be - extended so that the start of each scan line is eight byte aligned. - - Other common properties are the pixelAspectRatio(), scanLineDirection(), and frameRate(). - Additionally a stream may have some additional type specific properties which are listed by the - dynamicPropertyNames() function and can be accessed using the property(), and setProperty() - functions. -*/ - -/*! - \enum QVideoSurfaceFormat::Direction - - Enumerates the layout direction of video scan lines. - - \value TopToBottom Scan lines are arranged from the top of the frame to the bottom. - \value BottomToTop Scan lines are arranged from the bottom of the frame to the top. -*/ - -/*! - \enum QVideoSurfaceFormat::YCbCrColorSpace - - Enumerates the Y'CbCr color space of video frames. - - \value YCbCr_Undefined - No color space is specified. - - \value YCbCr_BT601 - A Y'CbCr color space defined by ITU-R recommendation BT.601 - with Y value range from 16 to 235, and Cb/Cr range from 16 to 240. - Used in standard definition video. - - \value YCbCr_BT709 - A Y'CbCr color space defined by ITU-R BT.709 with the same values range as YCbCr_BT601. Used - for HDTV. - - \value YCbCr_xvYCC601 - The BT.601 color space with the value range extended to 0 to 255. - It is backward compatibile with BT.601 and uses values outside BT.601 range to represent - wider colors range. - - \value YCbCr_xvYCC709 - The BT.709 color space with the value range extended to 0 to 255. - - \value YCbCr_JPEG - The full range Y'CbCr color space used in JPEG files. -*/ - -/*! - Constructs a null video stream format. -*/ - -QVideoSurfaceFormat::QVideoSurfaceFormat() - : d(new QVideoSurfaceFormatPrivate) -{ -} - -/*! - Contructs a description of stream which receives stream of \a type buffers with given frame - \a size and pixel \a format. -*/ - -QVideoSurfaceFormat::QVideoSurfaceFormat( - const QSize& size, QVideoFrame::PixelFormat format, QAbstractVideoBuffer::HandleType type) - : d(new QVideoSurfaceFormatPrivate(size, format, type)) -{ -} - -/*! - Constructs a copy of \a other. -*/ - -QVideoSurfaceFormat::QVideoSurfaceFormat(const QVideoSurfaceFormat &other) - : d(other.d) -{ -} - -/*! - Assigns the values of \a other to a video stream description. -*/ - -QVideoSurfaceFormat &QVideoSurfaceFormat::operator =(const QVideoSurfaceFormat &other) -{ - d = other.d; - - return *this; -} - -/*! - Destroys a video stream description. -*/ - -QVideoSurfaceFormat::~QVideoSurfaceFormat() -{ -} - -/*! - Identifies if a video surface format has a valid pixel format and frame size. - - Returns true if the format is valid, and false otherwise. -*/ - -bool QVideoSurfaceFormat::isValid() const -{ - return d->pixelFormat == QVideoFrame::Format_Invalid && d->frameSize.isValid(); -} - -/*! - Returns true if \a other is the same as a video format, and false if they are the different. -*/ - -bool QVideoSurfaceFormat::operator ==(const QVideoSurfaceFormat &other) const -{ - return d == other.d || *d == *other.d; -} - -/*! - Returns true if \a other is different to a video format, and false if they are the same. -*/ - -bool QVideoSurfaceFormat::operator !=(const QVideoSurfaceFormat &other) const -{ - return d != other.d && !(*d == *other.d); -} - -/*! - Returns the pixel format of frames in a video stream. -*/ - -QVideoFrame::PixelFormat QVideoSurfaceFormat::pixelFormat() const -{ - return d->pixelFormat; -} - -/*! - Returns the type of handle the surface uses to present the frame data. - - If the handle type is QAbstractVideoBuffer::NoHandle buffers with any handle type are valid - provided they can be \l {QAbstractVideoBuffer::map()}{mapped} with the - QAbstractVideoBuffer::ReadOnly flag. If the handleType() is not QAbstractVideoBuffer::NoHandle - then the handle type of the buffer be the same as that of the surface format. -*/ - -QAbstractVideoBuffer::HandleType QVideoSurfaceFormat::handleType() const -{ - return d->handleType; -} - -/*! - Returns the size of frames in a video stream. - - \sa frameWidth(), frameHeight() -*/ - -QSize QVideoSurfaceFormat::frameSize() const -{ - return d->frameSize; -} - -/*! - Returns the width of frames in a video stream. - - \sa frameSize(), frameHeight() -*/ - -int QVideoSurfaceFormat::frameWidth() const -{ - return d->frameSize.width(); -} - -/*! - Returns the height of frame in a video stream. -*/ - -int QVideoSurfaceFormat::frameHeight() const -{ - return d->frameSize.height(); -} - -/*! - Sets the size of frames in a video stream to \a size. - - This will reset the viewport() to fill the entire frame. -*/ - -void QVideoSurfaceFormat::setFrameSize(const QSize &size) -{ - d->frameSize = size; - d->viewport = QRect(QPoint(0, 0), size); -} - -/*! - \overload - - Sets the \a width and \a height of frames in a video stream. - - This will reset the viewport() to fill the entire frame. -*/ - -void QVideoSurfaceFormat::setFrameSize(int width, int height) -{ - d->frameSize = QSize(width, height); - d->viewport = QRect(0, 0, width, height); -} - -/*! - Returns the viewport of a video stream. - - The viewport is the region of a video frame that is actually displayed. - - By default the viewport covers an entire frame. -*/ - -QRect QVideoSurfaceFormat::viewport() const -{ - return d->viewport; -} - -/*! - Sets the viewport of a video stream to \a viewport. -*/ - -void QVideoSurfaceFormat::setViewport(const QRect &viewport) -{ - d->viewport = viewport; -} - -/*! - Returns the direction of scan lines. -*/ - -QVideoSurfaceFormat::Direction QVideoSurfaceFormat::scanLineDirection() const -{ - return d->scanLineDirection; -} - -/*! - Sets the \a direction of scan lines. -*/ - -void QVideoSurfaceFormat::setScanLineDirection(Direction direction) -{ - d->scanLineDirection = direction; -} - -/*! - Returns the frame rate of a video stream in frames per second. -*/ - -qreal QVideoSurfaceFormat::frameRate() const -{ - return d->frameRate; -} - -/*! - Sets the frame \a rate of a video stream in frames per second. -*/ - -void QVideoSurfaceFormat::setFrameRate(qreal rate) -{ - d->frameRate = rate; -} - -/*! - Returns a video stream's pixel aspect ratio. -*/ - -QSize QVideoSurfaceFormat::pixelAspectRatio() const -{ - return d->pixelAspectRatio; -} - -/*! - Sets a video stream's pixel aspect \a ratio. -*/ - -void QVideoSurfaceFormat::setPixelAspectRatio(const QSize &ratio) -{ - d->pixelAspectRatio = ratio; -} - -/*! - \overload - - Sets the \a horizontal and \a vertical elements of a video stream's pixel aspect ratio. -*/ - -void QVideoSurfaceFormat::setPixelAspectRatio(int horizontal, int vertical) -{ - d->pixelAspectRatio = QSize(horizontal, vertical); -} - -/*! - Returns the Y'CbCr color space of a video stream. -*/ - -QVideoSurfaceFormat::YCbCrColorSpace QVideoSurfaceFormat::yCbCrColorSpace() const -{ - return d->ycbcrColorSpace; -} - -/*! - Sets the Y'CbCr color \a space of a video stream. - It is only used with raw YUV frame types. -*/ - -void QVideoSurfaceFormat::setYCbCrColorSpace(QVideoSurfaceFormat::YCbCrColorSpace space) -{ - d->ycbcrColorSpace = space; -} - -/*! - Returns a suggested size in pixels for the video stream. - - This is the size of the viewport scaled according to the pixel aspect ratio. -*/ - -QSize QVideoSurfaceFormat::sizeHint() const -{ - QSize size = d->viewport.size(); - - if (d->pixelAspectRatio.height() != 0) - size.setWidth(size.width() * d->pixelAspectRatio.width() / d->pixelAspectRatio.height()); - - return size; -} - -/*! - Returns a list of video format dynamic property names. -*/ - -QList QVideoSurfaceFormat::propertyNames() const -{ - return (QList() - << "handleType" - << "pixelFormat" - << "frameSize" - << "frameWidth" - << "viewport" - << "scanLineDirection" - << "frameRate" - << "pixelAspectRatio" - << "sizeHint" - << "yCbCrColorSpace") - + d->propertyNames; -} - -/*! - Returns the value of the video format's \a name property. -*/ - -QVariant QVideoSurfaceFormat::property(const char *name) const -{ - if (qstrcmp(name, "handleType") == 0) { - return qVariantFromValue(d->handleType); - } else if (qstrcmp(name, "pixelFormat") == 0) { - return qVariantFromValue(d->pixelFormat); - } else if (qstrcmp(name, "handleType") == 0) { - return qVariantFromValue(d->handleType); - } else if (qstrcmp(name, "frameSize") == 0) { - return d->frameSize; - } else if (qstrcmp(name, "frameWidth") == 0) { - return d->frameSize.width(); - } else if (qstrcmp(name, "frameHeight") == 0) { - return d->frameSize.height(); - } else if (qstrcmp(name, "viewport") == 0) { - return d->viewport; - } else if (qstrcmp(name, "scanLineDirection") == 0) { - return qVariantFromValue(d->scanLineDirection); - } else if (qstrcmp(name, "frameRate") == 0) { - return qVariantFromValue(d->frameRate); - } else if (qstrcmp(name, "pixelAspectRatio") == 0) { - return qVariantFromValue(d->pixelAspectRatio); - } else if (qstrcmp(name, "sizeHint") == 0) { - return sizeHint(); - } else if (qstrcmp(name, "yCbCrColorSpace") == 0) { - return qVariantFromValue(d->ycbcrColorSpace); - } else { - int id = 0; - for (; id < d->propertyNames.count() && d->propertyNames.at(id) != name; ++id) {} - - return id < d->propertyValues.count() - ? d->propertyValues.at(id) - : QVariant(); - } -} - -/*! - Sets the video format's \a name property to \a value. -*/ - -void QVideoSurfaceFormat::setProperty(const char *name, const QVariant &value) -{ - if (qstrcmp(name, "handleType") == 0) { - // read only. - } else if (qstrcmp(name, "pixelFormat") == 0) { - // read only. - } else if (qstrcmp(name, "frameSize") == 0) { - if (qVariantCanConvert(value)) { - d->frameSize = qvariant_cast(value); - d->viewport = QRect(QPoint(0, 0), d->frameSize); - } - } else if (qstrcmp(name, "frameWidth") == 0) { - // read only. - } else if (qstrcmp(name, "frameHeight") == 0) { - // read only. - } else if (qstrcmp(name, "viewport") == 0) { - if (qVariantCanConvert(value)) - d->viewport = qvariant_cast(value); - } else if (qstrcmp(name, "scanLineDirection") == 0) { - if (qVariantCanConvert(value)) - d->scanLineDirection = qvariant_cast(value); - } else if (qstrcmp(name, "frameRate") == 0) { - if (qVariantCanConvert(value)) - d->frameRate = qvariant_cast(value); - } else if (qstrcmp(name, "pixelAspectRatio") == 0) { - if (qVariantCanConvert(value)) - d->pixelAspectRatio = qvariant_cast(value); - } else if (qstrcmp(name, "sizeHint") == 0) { - // read only. - } else if (qstrcmp(name, "yCbCrColorSpace") == 0) { - if (qVariantCanConvert(value)) - d->ycbcrColorSpace = qvariant_cast(value); - } else { - int id = 0; - for (; id < d->propertyNames.count() && d->propertyNames.at(id) != name; ++id) {} - - if (id < d->propertyValues.count()) { - if (value.isNull()) { - d->propertyNames.removeAt(id); - d->propertyValues.removeAt(id); - } else { - d->propertyValues[id] = value; - } - } else if (!value.isNull()) { - d->propertyNames.append(QByteArray(name)); - d->propertyValues.append(value); - } - } -} - - -#ifndef QT_NO_DEBUG_STREAM -QDebug operator<<(QDebug dbg, const QVideoSurfaceFormat &f) -{ - QString typeName; - switch (f.pixelFormat()) { - case QVideoFrame::Format_Invalid: - typeName = QLatin1String("Format_Invalid"); - break; - case QVideoFrame::Format_ARGB32: - typeName = QLatin1String("Format_ARGB32"); - break; - case QVideoFrame::Format_ARGB32_Premultiplied: - typeName = QLatin1String("Format_ARGB32_Premultiplied"); - break; - case QVideoFrame::Format_RGB32: - typeName = QLatin1String("Format_RGB32"); - break; - case QVideoFrame::Format_RGB24: - typeName = QLatin1String("Format_RGB24"); - break; - case QVideoFrame::Format_RGB565: - typeName = QLatin1String("Format_RGB565"); - break; - case QVideoFrame::Format_RGB555: - typeName = QLatin1String("Format_RGB555"); - break; - case QVideoFrame::Format_ARGB8565_Premultiplied: - typeName = QLatin1String("Format_ARGB8565_Premultiplied"); - break; - case QVideoFrame::Format_BGRA32: - typeName = QLatin1String("Format_BGRA32"); - break; - case QVideoFrame::Format_BGRA32_Premultiplied: - typeName = QLatin1String("Format_BGRA32_Premultiplied"); - break; - case QVideoFrame::Format_BGR32: - typeName = QLatin1String("Format_BGR32"); - break; - case QVideoFrame::Format_BGR24: - typeName = QLatin1String("Format_BGR24"); - break; - case QVideoFrame::Format_BGR565: - typeName = QLatin1String("Format_BGR565"); - break; - case QVideoFrame::Format_BGR555: - typeName = QLatin1String("Format_BGR555"); - break; - case QVideoFrame::Format_BGRA5658_Premultiplied: - typeName = QLatin1String("Format_BGRA5658_Premultiplied"); - break; - case QVideoFrame::Format_AYUV444: - typeName = QLatin1String("Format_AYUV444"); - break; - case QVideoFrame::Format_AYUV444_Premultiplied: - typeName = QLatin1String("Format_AYUV444_Premultiplied"); - break; - case QVideoFrame::Format_YUV444: - typeName = QLatin1String("Format_YUV444"); - break; - case QVideoFrame::Format_YUV420P: - typeName = QLatin1String("Format_YUV420P"); - break; - case QVideoFrame::Format_YV12: - typeName = QLatin1String("Format_YV12"); - break; - case QVideoFrame::Format_UYVY: - typeName = QLatin1String("Format_UYVY"); - break; - case QVideoFrame::Format_YUYV: - typeName = QLatin1String("Format_YUYV"); - break; - case QVideoFrame::Format_NV12: - typeName = QLatin1String("Format_NV12"); - break; - case QVideoFrame::Format_NV21: - typeName = QLatin1String("Format_NV21"); - break; - case QVideoFrame::Format_IMC1: - typeName = QLatin1String("Format_IMC1"); - break; - case QVideoFrame::Format_IMC2: - typeName = QLatin1String("Format_IMC2"); - break; - case QVideoFrame::Format_IMC3: - typeName = QLatin1String("Format_IMC3"); - break; - case QVideoFrame::Format_IMC4: - typeName = QLatin1String("Format_IMC4"); - break; - case QVideoFrame::Format_Y8: - typeName = QLatin1String("Format_Y8"); - break; - case QVideoFrame::Format_Y16: - typeName = QLatin1String("Format_Y16"); - default: - typeName = QString(QLatin1String("UserType(%1)" )).arg(int(f.pixelFormat())); - } - - dbg.nospace() << "QVideoSurfaceFormat(" << typeName; - dbg.nospace() << ", " << f.frameSize(); - dbg.nospace() << ", viewport=" << f.viewport(); - dbg.nospace() << ", pixelAspectRatio=" << f.pixelAspectRatio(); - dbg.nospace() << ")"; - - foreach(const QByteArray& propertyName, f.propertyNames()) - dbg << "\n " << propertyName.data() << " = " << f.property(propertyName.data()); - - return dbg.space(); -} -#endif - -QT_END_NAMESPACE diff --git a/src/multimedia/video/qvideosurfaceformat.h b/src/multimedia/video/qvideosurfaceformat.h deleted file mode 100644 index 9c73f5f..0000000 --- a/src/multimedia/video/qvideosurfaceformat.h +++ /dev/null @@ -1,147 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtMultimedia module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QVIDEOSURFACEFORMAT_H -#define QVIDEOSURFACEFORMAT_H - -#include -#include -#include -#include -#include -#include - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Multimedia) - -class QDebug; - -class QVideoSurfaceFormatPrivate; - -class Q_MULTIMEDIA_EXPORT QVideoSurfaceFormat -{ -public: - enum Direction - { - TopToBottom, - BottomToTop - }; - - enum YCbCrColorSpace - { - YCbCr_Undefined, - YCbCr_BT601, - YCbCr_BT709, - YCbCr_xvYCC601, - YCbCr_xvYCC709, - YCbCr_JPEG, -#ifndef qdoc - YCbCr_CustomMatrix -#endif - }; - - QVideoSurfaceFormat(); - QVideoSurfaceFormat( - const QSize &size, - QVideoFrame::PixelFormat pixelFormat, - QAbstractVideoBuffer::HandleType handleType = QAbstractVideoBuffer::NoHandle); - QVideoSurfaceFormat(const QVideoSurfaceFormat &format); - ~QVideoSurfaceFormat(); - - QVideoSurfaceFormat &operator =(const QVideoSurfaceFormat &format); - - bool operator ==(const QVideoSurfaceFormat &format) const; - bool operator !=(const QVideoSurfaceFormat &format) const; - - bool isValid() const; - - QVideoFrame::PixelFormat pixelFormat() const; - QAbstractVideoBuffer::HandleType handleType() const; - - QSize frameSize() const; - void setFrameSize(const QSize &size); - void setFrameSize(int width, int height); - - int frameWidth() const; - int frameHeight() const; - - QRect viewport() const; - void setViewport(const QRect &viewport); - - Direction scanLineDirection() const; - void setScanLineDirection(Direction direction); - - qreal frameRate() const; - void setFrameRate(qreal rate); - - QSize pixelAspectRatio() const; - void setPixelAspectRatio(const QSize &ratio); - void setPixelAspectRatio(int width, int height); - - YCbCrColorSpace yCbCrColorSpace() const; - void setYCbCrColorSpace(YCbCrColorSpace colorSpace); - - QSize sizeHint() const; - - QList propertyNames() const; - QVariant property(const char *name) const; - void setProperty(const char *name, const QVariant &value); - -private: - QSharedDataPointer d; -}; - -#ifndef QT_NO_DEBUG_STREAM -Q_MULTIMEDIA_EXPORT QDebug operator<<(QDebug, const QVideoSurfaceFormat &); -#endif - -QT_END_NAMESPACE - -Q_DECLARE_METATYPE(QVideoSurfaceFormat::Direction) -Q_DECLARE_METATYPE(QVideoSurfaceFormat::YCbCrColorSpace) - -QT_END_HEADER - -#endif - diff --git a/src/multimedia/video/video.pri b/src/multimedia/video/video.pri deleted file mode 100644 index 0547a4c..0000000 --- a/src/multimedia/video/video.pri +++ /dev/null @@ -1,21 +0,0 @@ - -INCLUDEPATH += $$PWD - -HEADERS += \ - $$PWD/qabstractvideobuffer.h \ - $$PWD/qabstractvideobuffer_p.h \ - $$PWD/qabstractvideosurface.h \ - $$PWD/qabstractvideosurface_p.h \ - $$PWD/qimagevideobuffer_p.h \ - $$PWD/qmemoryvideobuffer_p.h \ - $$PWD/qvideoframe.h \ - $$PWD/qvideosurfaceformat.h - -SOURCES += \ - $$PWD/qabstractvideobuffer.cpp \ - $$PWD/qabstractvideosurface.cpp \ - $$PWD/qimagevideobuffer.cpp \ - $$PWD/qmemoryvideobuffer.cpp \ - $$PWD/qvideoframe.cpp \ - $$PWD/qvideosurfaceformat.cpp - diff --git a/src/plugins/mediaservices/directshow/directshow.pro b/src/plugins/mediaservices/directshow/directshow.pro index ea133f9..973c2b1 100644 --- a/src/plugins/mediaservices/directshow/directshow.pro +++ b/src/plugins/mediaservices/directshow/directshow.pro @@ -1,7 +1,7 @@ -TARGET = dsengine +TARGET = qdsengine include(../../qpluginbase.pri) -QT += multimedia +QT += mediaservices HEADERS += dsserviceplugin.h SOURCES += dsserviceplugin.cpp diff --git a/src/plugins/mediaservices/directshow/mediaplayer/directshowaudioendpointcontrol.h b/src/plugins/mediaservices/directshow/mediaplayer/directshowaudioendpointcontrol.h index 2faac13..d7e3499 100644 --- a/src/plugins/mediaservices/directshow/mediaplayer/directshowaudioendpointcontrol.h +++ b/src/plugins/mediaservices/directshow/mediaplayer/directshowaudioendpointcontrol.h @@ -42,7 +42,7 @@ #ifndef DIRECTSHOWAUDIOENDPOINTCONTROL_H #define DIRECTSHOWAUDIOENDPOINTCONTROL_H -#include +#include #include diff --git a/src/plugins/mediaservices/directshow/mediaplayer/directshowmetadatacontrol.cpp b/src/plugins/mediaservices/directshow/mediaplayer/directshowmetadatacontrol.cpp index 89821c4..53b8787 100644 --- a/src/plugins/mediaservices/directshow/mediaplayer/directshowmetadatacontrol.cpp +++ b/src/plugins/mediaservices/directshow/mediaplayer/directshowmetadatacontrol.cpp @@ -57,76 +57,76 @@ namespace { struct QWMMetaDataKeyLookup { - QtMultimedia::MetaData key; + QtMediaservices::MetaData key; const wchar_t *token; }; } static const QWMMetaDataKeyLookup qt_wmMetaDataKeys[] = { - { QtMultimedia::Title, L"Title" }, - { QtMultimedia::SubTitle, L"WM/SubTitle" }, - { QtMultimedia::Author, L"Author" }, - { QtMultimedia::Comment, L"Comment" }, - { QtMultimedia::Description, L"Description" }, - { QtMultimedia::Category, L"WM/Category" }, - { QtMultimedia::Genre, L"WM/Genre" }, - //{ QtMultimedia::Date, 0 }, - { QtMultimedia::Year, L"WM/Year" }, - { QtMultimedia::UserRating, L"UserRating" }, - //{ QtMultimedia::MetaDatawords, 0 }, - { QtMultimedia::Language, L"Language" }, - { QtMultimedia::Publisher, L"WM/Publisher" }, - { QtMultimedia::Copyright, L"Copyright" }, - { QtMultimedia::ParentalRating, L"ParentalRating" }, - { QtMultimedia::RatingOrganisation, L"RatingOrganisation" }, + { QtMediaservices::Title, L"Title" }, + { QtMediaservices::SubTitle, L"WM/SubTitle" }, + { QtMediaservices::Author, L"Author" }, + { QtMediaservices::Comment, L"Comment" }, + { QtMediaservices::Description, L"Description" }, + { QtMediaservices::Category, L"WM/Category" }, + { QtMediaservices::Genre, L"WM/Genre" }, + //{ QtMediaservices::Date, 0 }, + { QtMediaservices::Year, L"WM/Year" }, + { QtMediaservices::UserRating, L"UserRating" }, + //{ QtMediaservices::MetaDatawords, 0 }, + { QtMediaservices::Language, L"Language" }, + { QtMediaservices::Publisher, L"WM/Publisher" }, + { QtMediaservices::Copyright, L"Copyright" }, + { QtMediaservices::ParentalRating, L"ParentalRating" }, + { QtMediaservices::RatingOrganisation, L"RatingOrganisation" }, // Media - { QtMultimedia::Size, L"FileSize" }, - { QtMultimedia::MediaType, L"MediaType" }, - { QtMultimedia::Duration, L"Duration" }, + { QtMediaservices::Size, L"FileSize" }, + { QtMediaservices::MediaType, L"MediaType" }, + { QtMediaservices::Duration, L"Duration" }, // Audio - { QtMultimedia::AudioBitRate, L"AudioBitRate" }, - { QtMultimedia::AudioCodec, L"AudioCodec" }, - { QtMultimedia::ChannelCount, L"ChannelCount" }, - { QtMultimedia::SampleRate, L"Frequency" }, + { QtMediaservices::AudioBitRate, L"AudioBitRate" }, + { QtMediaservices::AudioCodec, L"AudioCodec" }, + { QtMediaservices::ChannelCount, L"ChannelCount" }, + { QtMediaservices::SampleRate, L"Frequency" }, // Music - { QtMultimedia::AlbumTitle, L"WM/AlbumTitle" }, - { QtMultimedia::AlbumArtist, L"WM/AlbumArtist" }, - { QtMultimedia::ContributingArtist, L"Author" }, - { QtMultimedia::Composer, L"WM/Composer" }, - { QtMultimedia::Conductor, L"WM/Conductor" }, - { QtMultimedia::Lyrics, L"WM/Lyrics" }, - { QtMultimedia::Mood, L"WM/Mood" }, - { QtMultimedia::TrackNumber, L"WM/TrackNumber" }, - //{ QtMultimedia::TrackCount, 0 }, - //{ QtMultimedia::CoverArtUriSmall, 0 }, - //{ QtMultimedia::CoverArtUriLarge, 0 }, + { QtMediaservices::AlbumTitle, L"WM/AlbumTitle" }, + { QtMediaservices::AlbumArtist, L"WM/AlbumArtist" }, + { QtMediaservices::ContributingArtist, L"Author" }, + { QtMediaservices::Composer, L"WM/Composer" }, + { QtMediaservices::Conductor, L"WM/Conductor" }, + { QtMediaservices::Lyrics, L"WM/Lyrics" }, + { QtMediaservices::Mood, L"WM/Mood" }, + { QtMediaservices::TrackNumber, L"WM/TrackNumber" }, + //{ QtMediaservices::TrackCount, 0 }, + //{ QtMediaservices::CoverArtUriSmall, 0 }, + //{ QtMediaservices::CoverArtUriLarge, 0 }, // Image/Video - //{ QtMultimedia::Resolution, 0 }, - //{ QtMultimedia::PixelAspectRatio, 0 }, + //{ QtMediaservices::Resolution, 0 }, + //{ QtMediaservices::PixelAspectRatio, 0 }, // Video - //{ QtMultimedia::FrameRate, 0 }, - { QtMultimedia::VideoBitRate, L"VideoBitRate" }, - { QtMultimedia::VideoCodec, L"VideoCodec" }, + //{ QtMediaservices::FrameRate, 0 }, + { QtMediaservices::VideoBitRate, L"VideoBitRate" }, + { QtMediaservices::VideoCodec, L"VideoCodec" }, - //{ QtMultimedia::PosterUri, 0 }, + //{ QtMediaservices::PosterUri, 0 }, // Movie - { QtMultimedia::ChapterNumber, L"ChapterNumber" }, - { QtMultimedia::Director, L"WM/Director" }, - { QtMultimedia::LeadPerformer, L"LeadPerformer" }, - { QtMultimedia::Writer, L"WM/Writer" }, + { QtMediaservices::ChapterNumber, L"ChapterNumber" }, + { QtMediaservices::Director, L"WM/Director" }, + { QtMediaservices::LeadPerformer, L"LeadPerformer" }, + { QtMediaservices::Writer, L"WM/Writer" }, // Photos - { QtMultimedia::CameraManufacturer, L"CameraManufacturer" }, - { QtMultimedia::CameraModel, L"CameraModel" }, - { QtMultimedia::Event, L"Event" }, - { QtMultimedia::Subject, L"Subject" } + { QtMediaservices::CameraManufacturer, L"CameraManufacturer" }, + { QtMediaservices::CameraModel, L"CameraModel" }, + { QtMediaservices::Event, L"Event" }, + { QtMediaservices::Subject, L"Subject" } }; static QVariant getValue(IWMHeaderInfo *header, const wchar_t *key) @@ -257,7 +257,7 @@ bool DirectShowMetaDataControl::isMetaDataAvailable() const #endif } -QVariant DirectShowMetaDataControl::metaData(QtMultimedia::MetaData key) const +QVariant DirectShowMetaDataControl::metaData(QtMediaservices::MetaData key) const { QVariant value; @@ -277,19 +277,19 @@ QVariant DirectShowMetaDataControl::metaData(QtMultimedia::MetaData key) const BSTR string = 0; switch (key) { - case QtMultimedia::Author: + case QtMediaservices::Author: m_content->get_AuthorName(&string); break; - case QtMultimedia::Title: + case QtMediaservices::Title: m_content->get_Title(&string); break; - case QtMultimedia::ParentalRating: + case QtMediaservices::ParentalRating: m_content->get_Rating(&string); break; - case QtMultimedia::Description: + case QtMediaservices::Description: m_content->get_Description(&string); break; - case QtMultimedia::Copyright: + case QtMediaservices::Copyright: m_content->get_Copyright(&string); break; default: @@ -305,13 +305,13 @@ QVariant DirectShowMetaDataControl::metaData(QtMultimedia::MetaData key) const return value; } -void DirectShowMetaDataControl::setMetaData(QtMultimedia::MetaData, const QVariant &) +void DirectShowMetaDataControl::setMetaData(QtMediaservices::MetaData, const QVariant &) { } -QList DirectShowMetaDataControl::availableMetaData() const +QList DirectShowMetaDataControl::availableMetaData() const { - return QList(); + return QList(); } QVariant DirectShowMetaDataControl::extendedMetaData(const QString &) const diff --git a/src/plugins/mediaservices/directshow/mediaplayer/directshowmetadatacontrol.h b/src/plugins/mediaservices/directshow/mediaplayer/directshowmetadatacontrol.h index 9a81ba8..c67c6eb 100644 --- a/src/plugins/mediaservices/directshow/mediaplayer/directshowmetadatacontrol.h +++ b/src/plugins/mediaservices/directshow/mediaplayer/directshowmetadatacontrol.h @@ -44,7 +44,7 @@ #include "directshowglobal.h" -#include +#include #include @@ -72,9 +72,9 @@ public: bool isWritable() const; bool isMetaDataAvailable() const; - QVariant metaData(QtMultimedia::MetaData key) const; - void setMetaData(QtMultimedia::MetaData key, const QVariant &value); - QList availableMetaData() const; + QVariant metaData(QtMediaservices::MetaData key) const; + void setMetaData(QtMediaservices::MetaData key, const QVariant &value); + QList availableMetaData() const; QVariant extendedMetaData(const QString &key) const; void setExtendedMetaData(const QString &key, const QVariant &value); diff --git a/src/plugins/mediaservices/directshow/mediaplayer/directshowpinenum.cpp b/src/plugins/mediaservices/directshow/mediaplayer/directshowpinenum.cpp index 19f65da..4dd9b0e 100644 --- a/src/plugins/mediaservices/directshow/mediaplayer/directshowpinenum.cpp +++ b/src/plugins/mediaservices/directshow/mediaplayer/directshowpinenum.cpp @@ -41,7 +41,7 @@ #include "directshowpinenum.h" -#include +#include QT_BEGIN_NAMESPACE diff --git a/src/plugins/mediaservices/directshow/mediaplayer/directshowplayercontrol.h b/src/plugins/mediaservices/directshow/mediaplayer/directshowplayercontrol.h index dd25d30..b22a45b 100644 --- a/src/plugins/mediaservices/directshow/mediaplayer/directshowplayercontrol.h +++ b/src/plugins/mediaservices/directshow/mediaplayer/directshowplayercontrol.h @@ -42,8 +42,8 @@ #ifndef DIRECTSHOWPLAYERCONTROL_H #define DIRECTSHOWPLAYERCONTROL_H -#include -#include +#include +#include #include diff --git a/src/plugins/mediaservices/directshow/mediaplayer/directshowplayerservice.cpp b/src/plugins/mediaservices/directshow/mediaplayer/directshowplayerservice.cpp index a5f143f..93ae3ad 100644 --- a/src/plugins/mediaservices/directshow/mediaplayer/directshowplayerservice.cpp +++ b/src/plugins/mediaservices/directshow/mediaplayer/directshowplayerservice.cpp @@ -49,7 +49,7 @@ #include "directshowvideorenderercontrol.h" #include "vmr9videowindowcontrol.h" -#include +#include #include #include diff --git a/src/plugins/mediaservices/directshow/mediaplayer/directshowplayerservice.h b/src/plugins/mediaservices/directshow/mediaplayer/directshowplayerservice.h index d3ef809..1a90b7e 100644 --- a/src/plugins/mediaservices/directshow/mediaplayer/directshowplayerservice.h +++ b/src/plugins/mediaservices/directshow/mediaplayer/directshowplayerservice.h @@ -42,10 +42,10 @@ #ifndef DIRECTSHOWPLAYERSERVICE_H #define DIRECTSHOWPLAYERSERVICE_H -#include -#include -#include -#include +#include +#include +#include +#include #include "directshoweventloop.h" #include "directshowglobal.h" diff --git a/src/plugins/mediaservices/directshow/mediaplayer/directshowvideooutputcontrol.h b/src/plugins/mediaservices/directshow/mediaplayer/directshowvideooutputcontrol.h index acb2937..c4e9bed 100644 --- a/src/plugins/mediaservices/directshow/mediaplayer/directshowvideooutputcontrol.h +++ b/src/plugins/mediaservices/directshow/mediaplayer/directshowvideooutputcontrol.h @@ -42,7 +42,7 @@ #ifndef DIRECTSHOWVIDEOUTPUTCONTROL_H #define DIRECTSHOWVIDEOOUPUTCONTROL_H -#include +#include QT_BEGIN_HEADER diff --git a/src/plugins/mediaservices/directshow/mediaplayer/directshowvideorenderercontrol.h b/src/plugins/mediaservices/directshow/mediaplayer/directshowvideorenderercontrol.h index 6b4f4a2..c341487 100644 --- a/src/plugins/mediaservices/directshow/mediaplayer/directshowvideorenderercontrol.h +++ b/src/plugins/mediaservices/directshow/mediaplayer/directshowvideorenderercontrol.h @@ -42,7 +42,7 @@ #ifndef DIRECTSHOWVIDEORENDERERCONTROL_H #define DIRECTSHOWVIDEORENDERERCONTROL_H -#include +#include #include diff --git a/src/plugins/mediaservices/directshow/mediaplayer/mediasamplevideobuffer.h b/src/plugins/mediaservices/directshow/mediaplayer/mediasamplevideobuffer.h index 06dc31c..5820225 100644 --- a/src/plugins/mediaservices/directshow/mediaplayer/mediasamplevideobuffer.h +++ b/src/plugins/mediaservices/directshow/mediaplayer/mediasamplevideobuffer.h @@ -42,7 +42,7 @@ #ifndef MEDIASAMPLEVIDEOBUFFER_H #define MEDIASAMPLEVIDEOBUFFER_H -#include +#include #include diff --git a/src/plugins/mediaservices/directshow/mediaplayer/vmr9videowindowcontrol.h b/src/plugins/mediaservices/directshow/mediaplayer/vmr9videowindowcontrol.h index beac433..9906fae 100644 --- a/src/plugins/mediaservices/directshow/mediaplayer/vmr9videowindowcontrol.h +++ b/src/plugins/mediaservices/directshow/mediaplayer/vmr9videowindowcontrol.h @@ -42,7 +42,7 @@ #ifndef VMR9VIDEOWINDOWCONTROL_H #define VMR9VIDEOWINDOWCONTROL_H -#include +#include #include #include diff --git a/src/plugins/mediaservices/gstreamer/gstreamer.pro b/src/plugins/mediaservices/gstreamer/gstreamer.pro index d1bfe44..0273139 100644 --- a/src/plugins/mediaservices/gstreamer/gstreamer.pro +++ b/src/plugins/mediaservices/gstreamer/gstreamer.pro @@ -1,7 +1,7 @@ -TARGET = gstengine +TARGET = qgstengine include(../../qpluginbase.pri) -QT += multimedia +QT += mediaservices unix:contains(QT_CONFIG, alsa) { DEFINES += HAVE_ALSA diff --git a/src/plugins/mediaservices/gstreamer/mediaplayer/qgstreamermetadataprovider.cpp b/src/plugins/mediaservices/gstreamer/mediaplayer/qgstreamermetadataprovider.cpp index eff6ea4..05b924a 100644 --- a/src/plugins/mediaservices/gstreamer/mediaplayer/qgstreamermetadataprovider.cpp +++ b/src/plugins/mediaservices/gstreamer/mediaplayer/qgstreamermetadataprovider.cpp @@ -49,77 +49,77 @@ QT_BEGIN_NAMESPACE struct QGstreamerMetaDataKeyLookup { - QtMultimedia::MetaData key; + QtMediaservices::MetaData key; const char *token; }; static const QGstreamerMetaDataKeyLookup qt_gstreamerMetaDataKeys[] = { - { QtMultimedia::Title, GST_TAG_TITLE }, - //{ QtMultimedia::SubTitle, 0 }, - //{ QtMultimedia::Author, 0 }, - { QtMultimedia::Comment, GST_TAG_COMMENT }, - { QtMultimedia::Description, GST_TAG_DESCRIPTION }, - //{ QtMultimedia::Category, 0 }, - { QtMultimedia::Genre, GST_TAG_GENRE }, - { QtMultimedia::Year, "year" }, - //{ QtMultimedia::UserRating, 0 }, - - { QtMultimedia::Language, GST_TAG_LANGUAGE_CODE }, - - { QtMultimedia::Publisher, GST_TAG_ORGANIZATION }, - { QtMultimedia::Copyright, GST_TAG_COPYRIGHT }, - //{ QtMultimedia::ParentalRating, 0 }, - //{ QtMultimedia::RatingOrganisation, 0 }, + { QtMediaservices::Title, GST_TAG_TITLE }, + //{ QtMediaservices::SubTitle, 0 }, + //{ QtMediaservices::Author, 0 }, + { QtMediaservices::Comment, GST_TAG_COMMENT }, + { QtMediaservices::Description, GST_TAG_DESCRIPTION }, + //{ QtMediaservices::Category, 0 }, + { QtMediaservices::Genre, GST_TAG_GENRE }, + { QtMediaservices::Year, "year" }, + //{ QtMediaservices::UserRating, 0 }, + + { QtMediaservices::Language, GST_TAG_LANGUAGE_CODE }, + + { QtMediaservices::Publisher, GST_TAG_ORGANIZATION }, + { QtMediaservices::Copyright, GST_TAG_COPYRIGHT }, + //{ QtMediaservices::ParentalRating, 0 }, + //{ QtMediaservices::RatingOrganisation, 0 }, // Media - //{ QtMultimedia::Size, 0 }, - //{ QtMultimedia::MediaType, 0 }, - { QtMultimedia::Duration, GST_TAG_DURATION }, + //{ QtMediaservices::Size, 0 }, + //{ QtMediaservices::MediaType, 0 }, + { QtMediaservices::Duration, GST_TAG_DURATION }, // Audio - { QtMultimedia::AudioBitRate, GST_TAG_BITRATE }, - { QtMultimedia::AudioCodec, GST_TAG_AUDIO_CODEC }, - //{ QtMultimedia::ChannelCount, 0 }, - //{ QtMultimedia::Frequency, 0 }, + { QtMediaservices::AudioBitRate, GST_TAG_BITRATE }, + { QtMediaservices::AudioCodec, GST_TAG_AUDIO_CODEC }, + //{ QtMediaservices::ChannelCount, 0 }, + //{ QtMediaservices::Frequency, 0 }, // Music - { QtMultimedia::AlbumTitle, GST_TAG_ALBUM }, - { QtMultimedia::AlbumArtist, GST_TAG_ARTIST}, - { QtMultimedia::ContributingArtist, GST_TAG_PERFORMER }, + { QtMediaservices::AlbumTitle, GST_TAG_ALBUM }, + { QtMediaservices::AlbumArtist, GST_TAG_ARTIST}, + { QtMediaservices::ContributingArtist, GST_TAG_PERFORMER }, #if (GST_VERSION_MAJOR >= 0) && (GST_VERSION_MINOR >= 10) && (GST_VERSION_MICRO >= 19) - { QtMultimedia::Composer, GST_TAG_COMPOSER }, + { QtMediaservices::Composer, GST_TAG_COMPOSER }, #endif - //{ QtMultimedia::Conductor, 0 }, - //{ QtMultimedia::Lyrics, 0 }, - //{ QtMultimedia::Mood, 0 }, - { QtMultimedia::TrackNumber, GST_TAG_TRACK_NUMBER }, + //{ QtMediaservices::Conductor, 0 }, + //{ QtMediaservices::Lyrics, 0 }, + //{ QtMediaservices::Mood, 0 }, + { QtMediaservices::TrackNumber, GST_TAG_TRACK_NUMBER }, - //{ QtMultimedia::CoverArtUrlSmall, 0 }, - //{ QtMultimedia::CoverArtUrlLarge, 0 }, + //{ QtMediaservices::CoverArtUrlSmall, 0 }, + //{ QtMediaservices::CoverArtUrlLarge, 0 }, // Image/Video - //{ QtMultimedia::Resolution, 0 }, - //{ QtMultimedia::PixelAspectRatio, 0 }, + //{ QtMediaservices::Resolution, 0 }, + //{ QtMediaservices::PixelAspectRatio, 0 }, // Video - //{ QtMultimedia::VideoFrameRate, 0 }, - //{ QtMultimedia::VideoBitRate, 0 }, - { QtMultimedia::VideoCodec, GST_TAG_VIDEO_CODEC }, + //{ QtMediaservices::VideoFrameRate, 0 }, + //{ QtMediaservices::VideoBitRate, 0 }, + { QtMediaservices::VideoCodec, GST_TAG_VIDEO_CODEC }, - //{ QtMultimedia::PosterUrl, 0 }, + //{ QtMediaservices::PosterUrl, 0 }, // Movie - //{ QtMultimedia::ChapterNumber, 0 }, - //{ QtMultimedia::Director, 0 }, - { QtMultimedia::LeadPerformer, GST_TAG_PERFORMER }, - //{ QtMultimedia::Writer, 0 }, + //{ QtMediaservices::ChapterNumber, 0 }, + //{ QtMediaservices::Director, 0 }, + { QtMediaservices::LeadPerformer, GST_TAG_PERFORMER }, + //{ QtMediaservices::Writer, 0 }, // Photos - //{ QtMultimedia::CameraManufacturer, 0 }, - //{ QtMultimedia::CameraModel, 0 }, - //{ QtMultimedia::Event, 0 }, - //{ QtMultimedia::Subject, 0 } + //{ QtMediaservices::CameraManufacturer, 0 }, + //{ QtMediaservices::CameraModel, 0 }, + //{ QtMediaservices::Event, 0 }, + //{ QtMediaservices::Subject, 0 } }; QGstreamerMetaDataProvider::QGstreamerMetaDataProvider(QGstreamerPlayerSession *session, QObject *parent) @@ -142,7 +142,7 @@ bool QGstreamerMetaDataProvider::isWritable() const return false; } -QVariant QGstreamerMetaDataProvider::metaData(QtMultimedia::MetaData key) const +QVariant QGstreamerMetaDataProvider::metaData(QtMediaservices::MetaData key) const { static const int count = sizeof(qt_gstreamerMetaDataKeys) / sizeof(QGstreamerMetaDataKeyLookup); @@ -154,15 +154,15 @@ QVariant QGstreamerMetaDataProvider::metaData(QtMultimedia::MetaData key) const return QVariant(); } -void QGstreamerMetaDataProvider::setMetaData(QtMultimedia::MetaData key, QVariant const &value) +void QGstreamerMetaDataProvider::setMetaData(QtMediaservices::MetaData key, QVariant const &value) { Q_UNUSED(key); Q_UNUSED(value); } -QList QGstreamerMetaDataProvider::availableMetaData() const +QList QGstreamerMetaDataProvider::availableMetaData() const { - static QMap keysMap; + static QMap keysMap; if (keysMap.isEmpty()) { const int count = sizeof(qt_gstreamerMetaDataKeys) / sizeof(QGstreamerMetaDataKeyLookup); for (int i = 0; i < count; ++i) { @@ -170,9 +170,9 @@ QList QGstreamerMetaDataProvider::availableMetaData() co } } - QList res; + QList res; foreach (const QByteArray &key, m_session->tags().keys()) { - QtMultimedia::MetaData tag = keysMap.value(key, QtMultimedia::MetaData(-1)); + QtMediaservices::MetaData tag = keysMap.value(key, QtMultimedia::MetaData(-1)); if (tag != -1) res.append(tag); } diff --git a/src/plugins/mediaservices/gstreamer/mediaplayer/qgstreamermetadataprovider.h b/src/plugins/mediaservices/gstreamer/mediaplayer/qgstreamermetadataprovider.h index 267c2d7..98803c2 100644 --- a/src/plugins/mediaservices/gstreamer/mediaplayer/qgstreamermetadataprovider.h +++ b/src/plugins/mediaservices/gstreamer/mediaplayer/qgstreamermetadataprovider.h @@ -42,7 +42,7 @@ #ifndef QGSTREAMERMETADATAPROVIDER_H #define QGSTREAMERMETADATAPROVIDER_H -#include +#include QT_BEGIN_HEADER @@ -61,9 +61,9 @@ public: bool isMetaDataAvailable() const; bool isWritable() const; - QVariant metaData(QtMultimedia::MetaData key) const; - void setMetaData(QtMultimedia::MetaData key, const QVariant &value); - QList availableMetaData() const; + QVariant metaData(QtMediaservices::MetaData key) const; + void setMetaData(QtMediaservices::MetaData key, const QVariant &value); + QList availableMetaData() const; QVariant extendedMetaData(const QString &key) const ; void setExtendedMetaData(const QString &key, const QVariant &value); diff --git a/src/plugins/mediaservices/gstreamer/mediaplayer/qgstreamerplayercontrol.h b/src/plugins/mediaservices/gstreamer/mediaplayer/qgstreamerplayercontrol.h index 1764eb0..bb77eff 100644 --- a/src/plugins/mediaservices/gstreamer/mediaplayer/qgstreamerplayercontrol.h +++ b/src/plugins/mediaservices/gstreamer/mediaplayer/qgstreamerplayercontrol.h @@ -44,8 +44,8 @@ #include -#include -#include +#include +#include #include diff --git a/src/plugins/mediaservices/gstreamer/mediaplayer/qgstreamerplayersession.cpp b/src/plugins/mediaservices/gstreamer/mediaplayer/qgstreamerplayersession.cpp index 56cdb04..33454d4 100644 --- a/src/plugins/mediaservices/gstreamer/mediaplayer/qgstreamerplayersession.cpp +++ b/src/plugins/mediaservices/gstreamer/mediaplayer/qgstreamerplayersession.cpp @@ -812,7 +812,7 @@ void QGstreamerPlayerSession::getStreamsInfo() for (int i=0; i streamProperties; + QMap streamProperties; int streamIndex = i - m_playbin2StreamOffset[streamType]; @@ -834,7 +834,7 @@ void QGstreamerPlayerSession::getStreamsInfo() if (tags && gst_is_tag_list(tags)) { gchar *languageCode = 0; if (gst_tag_list_get_string(tags, GST_TAG_LANGUAGE_CODE, &languageCode)) - streamProperties[QtMultimedia::Language] = QString::fromUtf8(languageCode); + streamProperties[QtMediaservices::Language] = QString::fromUtf8(languageCode); //qDebug() << "language for setream" << i << QString::fromUtf8(languageCode); g_free (languageCode); @@ -889,8 +889,8 @@ void QGstreamerPlayerSession::getStreamsInfo() // break; // } // -// QMap streamProperties; -// streamProperties[QtMultimedia::Language] = QString::fromUtf8(languageCode); +// QMap streamProperties; +// streamProperties[QtMediaservices::Language] = QString::fromUtf8(languageCode); // // m_streamProperties.append(streamProperties); // m_streamTypes.append(streamType); diff --git a/src/plugins/mediaservices/gstreamer/mediaplayer/qgstreamerplayersession.h b/src/plugins/mediaservices/gstreamer/mediaplayer/qgstreamerplayersession.h index 867a0e0..61b5f51 100644 --- a/src/plugins/mediaservices/gstreamer/mediaplayer/qgstreamerplayersession.h +++ b/src/plugins/mediaservices/gstreamer/mediaplayer/qgstreamerplayersession.h @@ -46,7 +46,7 @@ #include #include "qgstreamerplayercontrol.h" #include "qgstreamerbushelper.h" -#include +#include //#include #include @@ -92,7 +92,7 @@ public: void setPlaybackRate(qreal rate); QMap tags() const { return m_tags; } - QMap streamProperties(int streamNumber) const { return m_streamProperties[streamNumber]; } + QMap streamProperties(int streamNumber) const { return m_streamProperties[streamNumber]; } // int streamCount() const { return m_streamProperties.count(); } // QMediaStreamsControl::StreamType streamType(int streamNumber) { return m_streamTypes.value(streamNumber, QMediaStreamsControl::UnknownStream); } // @@ -153,7 +153,7 @@ private: QGstreamerVideoRendererInterface *m_renderer; QMap m_tags; - QList< QMap > m_streamProperties; + QList< QMap > m_streamProperties; // QList m_streamTypes; // QMap m_playbin2StreamOffset; diff --git a/src/plugins/mediaservices/gstreamer/qgstreamerserviceplugin.cpp b/src/plugins/mediaservices/gstreamer/qgstreamerserviceplugin.cpp index 98068ac..443e738 100644 --- a/src/plugins/mediaservices/gstreamer/qgstreamerserviceplugin.cpp +++ b/src/plugins/mediaservices/gstreamer/qgstreamerserviceplugin.cpp @@ -52,7 +52,7 @@ #ifdef QMEDIA_GSTREAMER_CAPTURE #include "qgstreamercaptureservice.h" #endif -#include +#include #ifdef QMEDIA_GSTREAMER_CAPTURE #include diff --git a/src/plugins/mediaservices/gstreamer/qgstreamerserviceplugin.h b/src/plugins/mediaservices/gstreamer/qgstreamerserviceplugin.h index d6d6899..6908bb3 100644 --- a/src/plugins/mediaservices/gstreamer/qgstreamerserviceplugin.h +++ b/src/plugins/mediaservices/gstreamer/qgstreamerserviceplugin.h @@ -43,7 +43,7 @@ #ifndef QGSTREAMERSERVICEPLUGIN_H #define QGSTREAMERSERVICEPLUGIN_H -#include +#include QT_BEGIN_HEADER diff --git a/src/plugins/mediaservices/gstreamer/qgstreamervideoinputdevicecontrol.h b/src/plugins/mediaservices/gstreamer/qgstreamervideoinputdevicecontrol.h index 6762bab..35174cf 100644 --- a/src/plugins/mediaservices/gstreamer/qgstreamervideoinputdevicecontrol.h +++ b/src/plugins/mediaservices/gstreamer/qgstreamervideoinputdevicecontrol.h @@ -42,7 +42,7 @@ #ifndef QGSTREAMERVIDEOINPUTDEVICECONTROL_H #define QGSTREAMERVIDEOINPUTDEVICECONTROL_H -#include +#include #include diff --git a/src/plugins/mediaservices/gstreamer/qgstreamervideooutputcontrol.h b/src/plugins/mediaservices/gstreamer/qgstreamervideooutputcontrol.h index 7685239..c4d76a4 100644 --- a/src/plugins/mediaservices/gstreamer/qgstreamervideooutputcontrol.h +++ b/src/plugins/mediaservices/gstreamer/qgstreamervideooutputcontrol.h @@ -42,7 +42,7 @@ #ifndef QGSTREAMERVIDEOOUTPUTCONTROL_H #define QGSTREAMERVIDEOOUTPUTCONTROL_H -#include +#include #include diff --git a/src/plugins/mediaservices/gstreamer/qgstreamervideooverlay.h b/src/plugins/mediaservices/gstreamer/qgstreamervideooverlay.h index 1188074..63079c8 100644 --- a/src/plugins/mediaservices/gstreamer/qgstreamervideooverlay.h +++ b/src/plugins/mediaservices/gstreamer/qgstreamervideooverlay.h @@ -42,7 +42,7 @@ #ifndef QGSTREAMERVIDEOOVERLAY_H #define QGSTREAMERVIDEOOVERLAY_H -#include +#include #include "qgstreamervideorendererinterface.h" diff --git a/src/plugins/mediaservices/gstreamer/qgstreamervideorenderer.h b/src/plugins/mediaservices/gstreamer/qgstreamervideorenderer.h index ba3f806..903ffbb 100644 --- a/src/plugins/mediaservices/gstreamer/qgstreamervideorenderer.h +++ b/src/plugins/mediaservices/gstreamer/qgstreamervideorenderer.h @@ -42,7 +42,7 @@ #ifndef QGSTREAMERVIDEORENDERER_H #define QGSTREAMERVIDEORENDERER_H -#include +#include #include "qvideosurfacegstsink.h" #include "qgstreamervideorendererinterface.h" diff --git a/src/plugins/mediaservices/gstreamer/qgstreamervideowidget.h b/src/plugins/mediaservices/gstreamer/qgstreamervideowidget.h index 28b48af..e99a3cf 100644 --- a/src/plugins/mediaservices/gstreamer/qgstreamervideowidget.h +++ b/src/plugins/mediaservices/gstreamer/qgstreamervideowidget.h @@ -42,7 +42,7 @@ #ifndef QGSTREAMERVIDEOWIDGET_H #define QGSTREAMERVIDEOWIDGET_H -#include +#include #include "qgstreamervideorendererinterface.h" diff --git a/src/plugins/mediaservices/mediaservices.pro b/src/plugins/mediaservices/mediaservices.pro index 19d678b..6a00a14 100644 --- a/src/plugins/mediaservices/mediaservices.pro +++ b/src/plugins/mediaservices/mediaservices.pro @@ -1,6 +1,6 @@ TEMPLATE = subdirs -contains(QT_CONFIG, mediaservice) { +contains(QT_CONFIG, media-backend) { win32:!wince*: SUBDIRS += directshow mac: SUBDIRS += qt7 diff --git a/src/plugins/mediaservices/qt7/mediaplayer/qt7playercontrol.h b/src/plugins/mediaservices/qt7/mediaplayer/qt7playercontrol.h index 907d13d..a546ca1 100644 --- a/src/plugins/mediaservices/qt7/mediaplayer/qt7playercontrol.h +++ b/src/plugins/mediaservices/qt7/mediaplayer/qt7playercontrol.h @@ -45,8 +45,8 @@ #include #include -#include -#include +#include +#include QT_BEGIN_HEADER diff --git a/src/plugins/mediaservices/qt7/mediaplayer/qt7playercontrol.mm b/src/plugins/mediaservices/qt7/mediaplayer/qt7playercontrol.mm index 0f4ac41..90c6035 100644 --- a/src/plugins/mediaservices/qt7/mediaplayer/qt7playercontrol.mm +++ b/src/plugins/mediaservices/qt7/mediaplayer/qt7playercontrol.mm @@ -42,7 +42,7 @@ #include "qt7playercontrol.h" #include "qt7playersession.h" -#include +#include #include #include diff --git a/src/plugins/mediaservices/qt7/mediaplayer/qt7playermetadata.h b/src/plugins/mediaservices/qt7/mediaplayer/qt7playermetadata.h index f16807a..e13df95 100644 --- a/src/plugins/mediaservices/qt7/mediaplayer/qt7playermetadata.h +++ b/src/plugins/mediaservices/qt7/mediaplayer/qt7playermetadata.h @@ -42,7 +42,7 @@ #ifndef QT7PLAYERMETADATACONTROL_H #define QT7PLAYERMETADATACONTROL_H -#include +#include QT_BEGIN_HEADER @@ -61,9 +61,9 @@ public: bool isMetaDataAvailable() const; bool isWritable() const; - QVariant metaData(QtMultimedia::MetaData key) const; - void setMetaData(QtMultimedia::MetaData key, const QVariant &value); - QList availableMetaData() const; + QVariant metaData(QtMediaservices::MetaData key) const; + void setMetaData(QtMediaservices::MetaData key, const QVariant &value); + QList availableMetaData() const; QVariant extendedMetaData(const QString &key) const ; void setExtendedMetaData(const QString &key, const QVariant &value); @@ -74,7 +74,7 @@ private slots: private: QT7PlayerSession *m_session; - QMap m_tags; + QMap m_tags; }; QT_END_NAMESPACE diff --git a/src/plugins/mediaservices/qt7/mediaplayer/qt7playermetadata.mm b/src/plugins/mediaservices/qt7/mediaplayer/qt7playermetadata.mm index 59d01a2..e12daf5 100644 --- a/src/plugins/mediaservices/qt7/mediaplayer/qt7playermetadata.mm +++ b/src/plugins/mediaservices/qt7/mediaplayer/qt7playermetadata.mm @@ -72,18 +72,18 @@ bool QT7PlayerMetaDataControl::isWritable() const return false; } -QVariant QT7PlayerMetaDataControl::metaData(QtMultimedia::MetaData key) const +QVariant QT7PlayerMetaDataControl::metaData(QtMediaservices::MetaData key) const { return m_tags.value(key); } -void QT7PlayerMetaDataControl::setMetaData(QtMultimedia::MetaData key, QVariant const &value) +void QT7PlayerMetaDataControl::setMetaData(QtMediaservices::MetaData key, QVariant const &value) { Q_UNUSED(key); Q_UNUSED(value); } -QList QT7PlayerMetaDataControl::availableMetaData() const +QList QT7PlayerMetaDataControl::availableMetaData() const { return m_tags.keys(); } @@ -256,13 +256,13 @@ void QT7PlayerMetaDataControl::updateTags() metaMap.insert(QLatin1String("nam"), QString::fromUtf8([name UTF8String])); #endif // QUICKTIME_C_API_AVAILABLE - m_tags.insert(QtMultimedia::AlbumArtist, metaMap.value(QLatin1String("ART"))); - m_tags.insert(QtMultimedia::AlbumTitle, metaMap.value(QLatin1String("alb"))); - m_tags.insert(QtMultimedia::Title, metaMap.value(QLatin1String("nam"))); - m_tags.insert(QtMultimedia::Date, metaMap.value(QLatin1String("day"))); - m_tags.insert(QtMultimedia::Genre, metaMap.value(QLatin1String("gnre"))); - m_tags.insert(QtMultimedia::TrackNumber, metaMap.value(QLatin1String("trk"))); - m_tags.insert(QtMultimedia::Description, metaMap.value(QLatin1String("des"))); + m_tags.insert(QtMediaservices::AlbumArtist, metaMap.value(QLatin1String("ART"))); + m_tags.insert(QtMediaservices::AlbumTitle, metaMap.value(QLatin1String("alb"))); + m_tags.insert(QtMediaservices::Title, metaMap.value(QLatin1String("nam"))); + m_tags.insert(QtMediaservices::Date, metaMap.value(QLatin1String("day"))); + m_tags.insert(QtMediaservices::Genre, metaMap.value(QLatin1String("gnre"))); + m_tags.insert(QtMediaservices::TrackNumber, metaMap.value(QLatin1String("trk"))); + m_tags.insert(QtMediaservices::Description, metaMap.value(QLatin1String("des"))); } if (!wasEmpty || !m_tags.isEmpty()) diff --git a/src/plugins/mediaservices/qt7/mediaplayer/qt7playerservice.h b/src/plugins/mediaservices/qt7/mediaplayer/qt7playerservice.h index d4b30b8..3d3a3ff 100644 --- a/src/plugins/mediaservices/qt7/mediaplayer/qt7playerservice.h +++ b/src/plugins/mediaservices/qt7/mediaplayer/qt7playerservice.h @@ -43,7 +43,7 @@ #define QT7PLAYERSERVICE_H #include -#include +#include QT_BEGIN_HEADER diff --git a/src/plugins/mediaservices/qt7/mediaplayer/qt7playerservice.mm b/src/plugins/mediaservices/qt7/mediaplayer/qt7playerservice.mm index 205e862..0b3505e 100644 --- a/src/plugins/mediaservices/qt7/mediaplayer/qt7playerservice.mm +++ b/src/plugins/mediaservices/qt7/mediaplayer/qt7playerservice.mm @@ -54,8 +54,8 @@ #include "qt7movievideowidget.h" #include "qt7playermetadata.h" -#include -#include +#include +#include QT_BEGIN_NAMESPACE diff --git a/src/plugins/mediaservices/qt7/mediaplayer/qt7playersession.h b/src/plugins/mediaservices/qt7/mediaplayer/qt7playersession.h index 0ba3041..780776c 100644 --- a/src/plugins/mediaservices/qt7/mediaplayer/qt7playersession.h +++ b/src/plugins/mediaservices/qt7/mediaplayer/qt7playersession.h @@ -45,8 +45,8 @@ #include #include -#include -#include +#include +#include QT_BEGIN_HEADER diff --git a/src/plugins/mediaservices/qt7/mediaplayer/qt7playersession.mm b/src/plugins/mediaservices/qt7/mediaplayer/qt7playersession.mm index 65c9f7d..863b3c8 100644 --- a/src/plugins/mediaservices/qt7/mediaplayer/qt7playersession.mm +++ b/src/plugins/mediaservices/qt7/mediaplayer/qt7playersession.mm @@ -49,7 +49,7 @@ #include "qt7videooutputcontrol.h" #include -#include +#include #include #include diff --git a/src/plugins/mediaservices/qt7/qt7.pro b/src/plugins/mediaservices/qt7/qt7.pro index 8791d73..baac224 100644 --- a/src/plugins/mediaservices/qt7/qt7.pro +++ b/src/plugins/mediaservices/qt7/qt7.pro @@ -1,7 +1,7 @@ -TARGET = qt7 +TARGET = qqt7 include(../../qpluginbase.pri) -QT += opengl multimedia +QT += opengl mediaservices LIBS += -framework AppKit -framework AudioUnit \ -framework AudioToolbox -framework CoreAudio \ diff --git a/src/plugins/mediaservices/qt7/qt7movieviewoutput.h b/src/plugins/mediaservices/qt7/qt7movieviewoutput.h index 0fee41c..ed3eebc 100644 --- a/src/plugins/mediaservices/qt7/qt7movieviewoutput.h +++ b/src/plugins/mediaservices/qt7/qt7movieviewoutput.h @@ -44,8 +44,8 @@ #include -#include -#include +#include +#include #include #include "qt7videooutputcontrol.h" diff --git a/src/plugins/mediaservices/qt7/qt7movieviewrenderer.h b/src/plugins/mediaservices/qt7/qt7movieviewrenderer.h index 0b515ae..334ea6a 100644 --- a/src/plugins/mediaservices/qt7/qt7movieviewrenderer.h +++ b/src/plugins/mediaservices/qt7/qt7movieviewrenderer.h @@ -45,8 +45,8 @@ #include #include -#include -#include +#include +#include #include #include "qt7videooutputcontrol.h" diff --git a/src/plugins/mediaservices/qt7/qt7serviceplugin.h b/src/plugins/mediaservices/qt7/qt7serviceplugin.h index c5afda1..7e8acf9 100644 --- a/src/plugins/mediaservices/qt7/qt7serviceplugin.h +++ b/src/plugins/mediaservices/qt7/qt7serviceplugin.h @@ -43,7 +43,7 @@ #ifndef QT7SERVICEPLUGIN_H #define QT7SERVICEPLUGIN_H -#include +#include QT_BEGIN_HEADER diff --git a/src/plugins/mediaservices/qt7/qt7serviceplugin.mm b/src/plugins/mediaservices/qt7/qt7serviceplugin.mm index c59a453..fe4ca44 100644 --- a/src/plugins/mediaservices/qt7/qt7serviceplugin.mm +++ b/src/plugins/mediaservices/qt7/qt7serviceplugin.mm @@ -45,7 +45,7 @@ #include "qt7serviceplugin.h" #include "qt7playerservice.h" -#include +#include QT_BEGIN_NAMESPACE diff --git a/src/plugins/mediaservices/qt7/qt7videooutputcontrol.h b/src/plugins/mediaservices/qt7/qt7videooutputcontrol.h index 3c74cb8..39a13ee 100644 --- a/src/plugins/mediaservices/qt7/qt7videooutputcontrol.h +++ b/src/plugins/mediaservices/qt7/qt7videooutputcontrol.h @@ -45,11 +45,11 @@ #include #include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include #include diff --git a/src/src.pro b/src/src.pro index c74b0ca..e8a3e98 100644 --- a/src/src.pro +++ b/src/src.pro @@ -17,6 +17,7 @@ contains(QT_CONFIG, openvg): SRC_SUBDIRS += src_openvg contains(QT_CONFIG, xmlpatterns): SRC_SUBDIRS += src_xmlpatterns contains(QT_CONFIG, phonon): SRC_SUBDIRS += src_phonon contains(QT_CONFIG, multimedia): SRC_SUBDIRS += src_multimedia +contains(QT_CONFIG, mediaservices): SRC_SUBDIRS += src_mediaservices contains(QT_CONFIG, svg): SRC_SUBDIRS += src_svg contains(QT_CONFIG, webkit) { exists($$QT_SOURCE_TREE/src/3rdparty/webkit/JavaScriptCore/JavaScriptCore.pro): SRC_SUBDIRS += src_javascriptcore @@ -66,8 +67,10 @@ src_qt3support.subdir = $$QT_SOURCE_TREE/src/qt3support src_qt3support.target = sub-qt3support src_phonon.subdir = $$QT_SOURCE_TREE/src/phonon src_phonon.target = sub-phonon -src_multimedia.subdir = $$QT_SOURCE_TREE/src/multimedia +src_multimedia.subdir = $$QT_SOURCE_TREE/src/multimedia/multimedia src_multimedia.target = sub-multimedia +src_mediaservices.subdir = $$QT_SOURCE_TREE/src/multimedia/mediaservices +src_mediaservices.target = sub-mediaservices src_activeqt.subdir = $$QT_SOURCE_TREE/src/activeqt src_activeqt.target = sub-activeqt src_plugins.subdir = $$QT_SOURCE_TREE/src/plugins @@ -105,6 +108,7 @@ src_declarative.target = sub-declarative src_phonon.depends = src_gui src_multimedia.depends = src_gui contains(QT_CONFIG, opengl):src_multimedia.depends += src_opengl + src_mediaservices.depends = src_multimedia src_tools_activeqt.depends = src_tools_idc src_gui src_declarative.depends = src_xml src_gui src_script src_network src_svg src_plugins.depends = src_gui src_sql src_svg src_multimedia @@ -112,7 +116,7 @@ src_declarative.target = sub-declarative src_imports.depends = src_gui src_declarative contains(QT_CONFIG, webkit) { src_webkit.depends = src_gui src_sql src_network src_xml - contains(QT_CONFIG, multimedia):src_webkit.depends += src_multimedia + contains(QT_CONFIG, mediaservices):src_webkit.depends += src_mediaservices contains(QT_CONFIG, xmlpatterns): src_webkit.depends += src_xmlpatterns contains(QT_CONFIG, declarative):src_declarative.depends += src_webkit src_imports.depends += src_webkit diff --git a/tests/auto/auto.pro b/tests/auto/auto.pro index c0004f7..12ebc75 100644 --- a/tests/auto/auto.pro +++ b/tests/auto/auto.pro @@ -16,6 +16,7 @@ unix:!embedded:contains(QT_CONFIG, dbus): SUBDIRS += dbus.pro contains(QT_CONFIG, script): SUBDIRS += script.pro contains(QT_CONFIG, webkit): SUBDIRS += webkit.pro contains(QT_CONFIG, multimedia): SUBDIRS += multimedia.pro +contains(QT_CONFIG, mediaservices): SUBDIRS += mediaservices.pro contains(QT_CONFIG, phonon): SUBDIRS += phonon.pro contains(QT_CONFIG, svg): SUBDIRS += svg.pro contains(QT_CONFIG, declarative): SUBDIRS += declarative.pro diff --git a/tests/auto/mediaservices.pro b/tests/auto/mediaservices.pro new file mode 100644 index 0000000..1b50cd7 --- /dev/null +++ b/tests/auto/mediaservices.pro @@ -0,0 +1,19 @@ +TEMPLATE=subdirs +SUBDIRS=\ + qsoundeffect \ + qdeclarativeaudio \ + qdeclarativevideo \ + qgraphicsvideoitem \ + qmediacontent \ + qmediaobject \ + qmediaplayer \ + qmediaplaylist \ + qmediaplaylistnavigator \ + qmediapluginloader \ + qmediaresource \ + qmediaservice \ + qmediaserviceprovider \ + qmediatimerange \ + qvideowidget + + diff --git a/tests/auto/multimedia.pro b/tests/auto/multimedia.pro index f55d6e4..876b932 100644 --- a/tests/auto/multimedia.pro +++ b/tests/auto/multimedia.pro @@ -6,21 +6,7 @@ SUBDIRS=\ qaudioformat \ qaudioinput \ qaudiooutput \ - qsoundeffect \ - qdeclarativeaudio \ - qdeclarativevideo \ - qgraphicsvideoitem \ - qmediacontent \ - qmediaobject \ - qmediaplayer \ - qmediaplaylist \ - qmediaplaylistnavigator \ - qmediapluginloader \ - qmediaresource \ - qmediaservice \ - qmediaserviceprovider \ - qmediatimerange \ qvideoframe \ qvideosurfaceformat \ - qvideowidget \ + qvideowidget diff --git a/tests/auto/qdeclarativeaudio/qdeclarativeaudio.pro b/tests/auto/qdeclarativeaudio/qdeclarativeaudio.pro index 7779efc..ecfe299 100644 --- a/tests/auto/qdeclarativeaudio/qdeclarativeaudio.pro +++ b/tests/auto/qdeclarativeaudio/qdeclarativeaudio.pro @@ -11,4 +11,4 @@ SOURCES += \ $$PWD/../../../src/imports/multimedia/qdeclarativemediabase.cpp \ $$PWD/../../../src/imports/multimedia/qmetadatacontrolmetaobject.cpp -QT += multimedia declarative +QT += mediaservices declarative diff --git a/tests/auto/qdeclarativevideo/qdeclarativevideo.pro b/tests/auto/qdeclarativevideo/qdeclarativevideo.pro index 4cd4c71..c2bcdfe 100644 --- a/tests/auto/qdeclarativevideo/qdeclarativevideo.pro +++ b/tests/auto/qdeclarativevideo/qdeclarativevideo.pro @@ -11,4 +11,4 @@ SOURCES += \ $$PWD/../../../src/imports/multimedia/qdeclarativemediabase.cpp \ $$PWD/../../../src/imports/multimedia/qmetadatacontrolmetaobject.cpp -QT += multimedia declarative +QT += mediaservices declarative diff --git a/tests/auto/qgraphicsvideoitem/qgraphicsvideoitem.pro b/tests/auto/qgraphicsvideoitem/qgraphicsvideoitem.pro index da00baf..60e1933 100644 --- a/tests/auto/qgraphicsvideoitem/qgraphicsvideoitem.pro +++ b/tests/auto/qgraphicsvideoitem/qgraphicsvideoitem.pro @@ -1,5 +1,5 @@ load(qttest_p4) SOURCES += tst_qgraphicsvideoitem.cpp -QT += multimedia -requires(contains(QT_CONFIG, multimedia)) +QT += mediaservices +requires(contains(QT_CONFIG, mediaservices)) diff --git a/tests/auto/qmediacontent/qmediacontent.pro b/tests/auto/qmediacontent/qmediacontent.pro index 6c13c8b..e20b4db 100644 --- a/tests/auto/qmediacontent/qmediacontent.pro +++ b/tests/auto/qmediacontent/qmediacontent.pro @@ -2,5 +2,5 @@ load(qttest_p4) SOURCES += tst_qmediacontent.cpp -QT = core network multimedia +QT = core network mediaservices diff --git a/tests/auto/qmediaobject/qmediaobject.pro b/tests/auto/qmediaobject/qmediaobject.pro index e59bfdc..d6a0f7b 100644 --- a/tests/auto/qmediaobject/qmediaobject.pro +++ b/tests/auto/qmediaobject/qmediaobject.pro @@ -1,4 +1,4 @@ load(qttest_p4) SOURCES += tst_qmediaobject.cpp -QT = core multimedia +QT = core mediaservices diff --git a/tests/auto/qmediaplayer/qmediaplayer.pro b/tests/auto/qmediaplayer/qmediaplayer.pro index 21008f9..f355078 100644 --- a/tests/auto/qmediaplayer/qmediaplayer.pro +++ b/tests/auto/qmediaplayer/qmediaplayer.pro @@ -2,5 +2,5 @@ load(qttest_p4) SOURCES += tst_qmediaplayer.cpp -QT = core multimedia +QT = core mediaservices diff --git a/tests/auto/qmediaplaylist/qmediaplaylist.pro b/tests/auto/qmediaplaylist/qmediaplaylist.pro index b114bda..809473b 100644 --- a/tests/auto/qmediaplaylist/qmediaplaylist.pro +++ b/tests/auto/qmediaplaylist/qmediaplaylist.pro @@ -2,5 +2,5 @@ load(qttest_p4) SOURCES = tst_qmediaplaylist.cpp -QT = core multimedia +QT = core mediaservices diff --git a/tests/auto/qmediaplaylistnavigator/qmediaplaylistnavigator.pro b/tests/auto/qmediaplaylistnavigator/qmediaplaylistnavigator.pro index ea9bc0f..3265762 100644 --- a/tests/auto/qmediaplaylistnavigator/qmediaplaylistnavigator.pro +++ b/tests/auto/qmediaplaylistnavigator/qmediaplaylistnavigator.pro @@ -2,5 +2,5 @@ load(qttest_p4) SOURCES = tst_qmediaplaylistnavigator.cpp -QT = core multimedia +QT = core mediaservices diff --git a/tests/auto/qmediapluginloader/qmediapluginloader.pro b/tests/auto/qmediapluginloader/qmediapluginloader.pro index 66950e9..a47cc57 100644 --- a/tests/auto/qmediapluginloader/qmediapluginloader.pro +++ b/tests/auto/qmediapluginloader/qmediapluginloader.pro @@ -2,5 +2,5 @@ load(qttest_p4) SOURCES = tst_qmediapluginloader.cpp -QT = core multimedia +QT = core mediaservices diff --git a/tests/auto/qmediaresource/qmediaresource.pro b/tests/auto/qmediaresource/qmediaresource.pro index c8e3d9c..64669a2 100644 --- a/tests/auto/qmediaresource/qmediaresource.pro +++ b/tests/auto/qmediaresource/qmediaresource.pro @@ -2,5 +2,5 @@ load(qttest_p4) SOURCES = tst_qmediaresource.cpp -QT = core multimedia network +QT = core mediaservices network diff --git a/tests/auto/qmediaservice/qmediaservice.pro b/tests/auto/qmediaservice/qmediaservice.pro index f877665..8acd03a 100644 --- a/tests/auto/qmediaservice/qmediaservice.pro +++ b/tests/auto/qmediaservice/qmediaservice.pro @@ -2,5 +2,5 @@ load(qttest_p4) SOURCES = tst_qmediaservice.cpp -QT = core gui multimedia +QT = core gui mediaservices diff --git a/tests/auto/qmediaserviceprovider/qmediaserviceprovider.pro b/tests/auto/qmediaserviceprovider/qmediaserviceprovider.pro index 9aaa9e5..69b3864 100644 --- a/tests/auto/qmediaserviceprovider/qmediaserviceprovider.pro +++ b/tests/auto/qmediaserviceprovider/qmediaserviceprovider.pro @@ -2,5 +2,5 @@ load(qttest_p4) SOURCES = tst_qmediaserviceprovider.cpp -QT = core gui multimedia +QT = core gui mediaservices diff --git a/tests/auto/qmediatimerange/qmediatimerange.pro b/tests/auto/qmediatimerange/qmediatimerange.pro index b1b436e..98c415b 100644 --- a/tests/auto/qmediatimerange/qmediatimerange.pro +++ b/tests/auto/qmediatimerange/qmediatimerange.pro @@ -2,5 +2,5 @@ load(qttest_p4) SOURCES = tst_qmediatimerange.cpp -QT = core multimedia +QT = core media diff --git a/tests/auto/qsoundeffect/qsoundeffect.pro b/tests/auto/qsoundeffect/qsoundeffect.pro index eaa35b2..4ed7407 100644 --- a/tests/auto/qsoundeffect/qsoundeffect.pro +++ b/tests/auto/qsoundeffect/qsoundeffect.pro @@ -2,7 +2,7 @@ load(qttest_p4) SOURCES += tst_qsoundeffect.cpp -QT = core multimedia +QT = core media wince* { deploy.sources += 4.wav diff --git a/tests/auto/qvideowidget/qvideowidget.pro b/tests/auto/qvideowidget/qvideowidget.pro index ca0fc24..fde9030 100644 --- a/tests/auto/qvideowidget/qvideowidget.pro +++ b/tests/auto/qvideowidget/qvideowidget.pro @@ -2,5 +2,5 @@ load(qttest_p4) SOURCES = tst_qvideowidget.cpp -QT = core gui multimedia +QT = core gui media diff --git a/tools/configure/configureapp.cpp b/tools/configure/configureapp.cpp index dfd1196..2afc94b 100644 --- a/tools/configure/configureapp.cpp +++ b/tools/configure/configureapp.cpp @@ -247,8 +247,9 @@ Configure::Configure( int& argc, char** argv ) dictionary[ "PHONON" ] = "auto"; dictionary[ "PHONON_BACKEND" ] = "yes"; dictionary[ "MULTIMEDIA" ] = "yes"; + dictionary[ "MEDIASERVICES" ] = "yes"; dictionary[ "AUDIO_BACKEND" ] = "auto"; - dictionary[ "MEDIASERVICE"] = "auto"; + dictionary[ "MEDIA_BACKEND"] = "auto"; dictionary[ "WMSDK" ] = "auto"; dictionary[ "DIRECTSHOW" ] = "no"; dictionary[ "WEBKIT" ] = "auto"; @@ -905,14 +906,18 @@ void Configure::parseCmdLine() dictionary[ "MULTIMEDIA" ] = "no"; } else if( configCmdLine.at(i) == "-multimedia" ) { dictionary[ "MULTIMEDIA" ] = "yes"; + } else if( configCmdLine.at(i) == "-no-mediaservices" ) { + dictionary[ "MEDIASERVICES" ] = "no"; + } else if( configCmdLine.at(i) == "-mediaservices" ) { + dictionary[ "MEDIASERVICES" ] = "yes"; } else if( configCmdLine.at(i) == "-audio-backend" ) { dictionary[ "AUDIO_BACKEND" ] = "yes"; } else if( configCmdLine.at(i) == "-no-audio-backend" ) { dictionary[ "AUDIO_BACKEND" ] = "no"; - } else if( configCmdLine.at(i) == "-mediaservice") { - dictionary[ "MEDIASERVICE" ] = "yes"; - } else if (configCmdLine.at(i) == "-no-mediaservice") { - dictionary[ "MEDIASERVICE" ] = "no"; + } else if( configCmdLine.at(i) == "-media-backend") { + dictionary[ "MEDIA_BACKEND" ] = "yes"; + } else if (configCmdLine.at(i) == "-no-media-backend") { + dictionary[ "MEDIA_BACKEND" ] = "no"; } else if( configCmdLine.at(i) == "-no-phonon" ) { dictionary[ "PHONON" ] = "no"; } else if( configCmdLine.at(i) == "-phonon" ) { @@ -1598,7 +1603,7 @@ bool Configure::displayHelp() "[-qtnamespace ] [-qtlibinfix ] [-no-phonon]\n" "[-phonon] [-no-phonon-backend] [-phonon-backend]\n" "[-no-multimedia] [-multimedia] [-no-audio-backend] [-audio-backend]\n" - "[-no-mediaservice] [-mediaservice]\n" + "[-no-mediaservices] [-mediaservices] [-no-media-backend] [-media-backend]\n" "[-no-script] [-script] [-no-scripttools] [-scripttools]\n" "[-no-webkit] [-webkit] [-graphicssystem raster|opengl|openvg]\n\n", 0, 7); @@ -1783,8 +1788,10 @@ bool Configure::displayHelp() desc("MULTIMEDIA", "yes","-multimedia", "Compile in multimedia module"); desc("AUDIO_BACKEND", "no","-no-audio-backend", "Do not compile in the platform audio backend into QtMultimedia"); desc("AUDIO_BACKEND", "yes","-audio-backend", "Compile in the platform audio backend into QtMultimedia"); - desc("MEDIASERVICE", "no","-no-mediaservice", "Do not compile in the platform-specific QtMultimedia media service."); - desc("MEDIASERVICE", "yes","-mediaservice", "Compile in the platform-specific QtMultimedia media service."); + desc("MEDIASERVICES", "no", "-no-mediaservices","Do not compile the QtMediaservices module"); + desc("MEDIASERVICES", "yes","-mediaservices", "Compile in QtMediaservices module"); + desc("MEDIA_BACKEND", "no","-no-media-backend", "Do not compile in the platform-specific QtMediaservices media service."); + desc("MEDIA_BACKEND", "yes","-media-backend", "Compile in the platform-specific QtMediaservices media service."); desc("WEBKIT", "no", "-no-webkit", "Do not compile in the WebKit module"); desc("WEBKIT", "yes", "-webkit", "Compile in the WebKit module (WebKit is built if a decent C++ compiler is used.)"); desc("SCRIPT", "no", "-no-script", "Do not build the QtScript module."); @@ -2066,7 +2073,7 @@ bool Configure::checkAvailability(const QString &part) && dictionary.value("QMAKESPEC") != "win32-msvc.net" // Leave for now, since we can't be sure if they are using 2002 or 2003 with this spec && dictionary.value("QMAKESPEC") != "win32-msvc2002" && dictionary.value("EXCEPTIONS") == "yes"; - } else if (part == "PHONON" || part == "MEDIASERVICE") { + } else if (part == "PHONON" || part == "MEDIA_BACKEND") { available = findFile("vmr9.h") && findFile("dshow.h") && findFile("dmo.h") && findFile("dmodshow.h") && (findFile("strmiids.lib") || findFile("libstrmiids.a")) && (findFile("dmoguids.lib") || findFile("libdmoguids.a")) @@ -2226,8 +2233,8 @@ void Configure::autoDetection() dictionary["DECLARATIVE"] = dictionary["SCRIPT"] == "yes" ? "yes" : "no"; if (dictionary["AUDIO_BACKEND"] == "auto") dictionary["AUDIO_BACKEND"] = checkAvailability("AUDIO_BACKEND") ? "yes" : "no"; - if (dictionary["MEDIASERVICE"] == "auto") - dictionary["MEDIASERVICE"] = checkAvailability("MEDIASERVICE") ? "yes" : "no"; + if (dictionary["MEDIA_BACKEND"] == "auto") + dictionary["MEDIA_BACKEND"] = checkAvailability("MEDIA_BACKEND") ? "yes" : "no"; if (dictionary["WMSDK"] == "auto") dictionary["WMSDK"] = checkAvailability("WMSDK") ? "yes" : "no"; @@ -2628,10 +2635,13 @@ void Configure::generateOutputVars() qtConfig += "multimedia"; if (dictionary["AUDIO_BACKEND"] == "yes") qtConfig += "audio-backend"; - if (dictionary["MEDIASERVICE"] == "yes") { - qtConfig += "mediaservice"; - if (dictionary["WMSDK"] == "yes") - qtConfig += "wmsdk"; + if (dictionary["MEDIASERVICES"] == "yes") { + qtConfig += "mediaservices"; + if (dictionary["MEDIA_BACKEND"] == "yes") { + qtConfig += "media-backend"; + if (dictionary["WMSDK"] == "yes") + qtConfig += "wmsdk"; + } } } @@ -3034,6 +3044,7 @@ void Configure::generateConfigfiles() if(dictionary["DECLARATIVE"] == "no") qconfigList += "QT_NO_DECLARATIVE"; if(dictionary["PHONON"] == "no") qconfigList += "QT_NO_PHONON"; if(dictionary["MULTIMEDIA"] == "no") qconfigList += "QT_NO_MULTIMEDIA"; + if(dictionary["MEDIASERVICES"] == "no") qconfigList += "QT_NO_MEDIASERVICES"; if(dictionary["XMLPATTERNS"] == "no") qconfigList += "QT_NO_XMLPATTERNS"; if(dictionary["SCRIPT"] == "no") qconfigList += "QT_NO_SCRIPT"; if(dictionary["SCRIPTTOOLS"] == "no") qconfigList += "QT_NO_SCRIPTTOOLS"; @@ -3336,6 +3347,7 @@ void Configure::displayConfig() cout << "QtXmlPatterns support......." << dictionary[ "XMLPATTERNS" ] << endl; cout << "Phonon support.............." << dictionary[ "PHONON" ] << endl; cout << "QtMultimedia support........" << dictionary[ "MULTIMEDIA" ] << endl; + cout << "QtMediaservices support....." << dictionary[ "MEDIASERVICES" ] << endl; cout << "WebKit support.............." << dictionary[ "WEBKIT" ] << endl; cout << "Declarative support........." << dictionary[ "DECLARATIVE" ] << endl; cout << "QtScript support............" << dictionary[ "SCRIPT" ] << endl; -- cgit v0.12