|
1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
4 ** All rights reserved. |
|
5 ** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 ** |
|
7 ** This file is part of the Qt Mobility Components. |
|
8 ** |
|
9 ** $QT_BEGIN_LICENSE:LGPL$ |
|
10 ** No Commercial Usage |
|
11 ** This file contains pre-release code and may not be distributed. |
|
12 ** You may use this file in accordance with the terms and conditions |
|
13 ** contained in the Technology Preview License Agreement accompanying |
|
14 ** this package. |
|
15 ** |
|
16 ** GNU Lesser General Public License Usage |
|
17 ** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 ** General Public License version 2.1 as published by the Free Software |
|
19 ** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 ** packaging of this file. Please review the following information to |
|
21 ** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 ** |
|
24 ** In addition, as a special exception, Nokia gives you certain additional |
|
25 ** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 ** |
|
28 ** If you have questions regarding the use of this file, please contact |
|
29 ** Nokia at qt-info@nokia.com. |
|
30 ** |
|
31 ** |
|
32 ** |
|
33 ** |
|
34 ** |
|
35 ** |
|
36 ** |
|
37 ** |
|
38 ** $QT_END_LICENSE$ |
|
39 ** |
|
40 ****************************************************************************/ |
|
41 |
|
42 #include <QtTest/QtTest> |
|
43 #include <QDebug> |
|
44 #include <qmediaobject.h> |
|
45 #include <qmediacontrol.h> |
|
46 #include <qmediaservice.h> |
|
47 #include <qmediarecordercontrol.h> |
|
48 #include <qmediarecorder.h> |
|
49 #include <qaudioendpointselector.h> |
|
50 #include <qaudioencodercontrol.h> |
|
51 #include <qmediacontainercontrol.h> |
|
52 #include <QtMultimedia/qaudioformat.h> |
|
53 #include <qaudiocapturesource.h> |
|
54 |
|
55 #define QTRY_COMPARE(a,e) \ |
|
56 for (int _i = 0; _i < 5000; _i += 100) { \ |
|
57 if ((a) == (e)) break; \ |
|
58 QTest::qWait(100); \ |
|
59 } \ |
|
60 QCOMPARE(a, e) |
|
61 |
|
62 #define QTRY_VERIFY(a) \ |
|
63 for (int _i = 0; _i < 5000; _i += 100) { \ |
|
64 if (a) break; \ |
|
65 QTest::qWait(100); \ |
|
66 } \ |
|
67 QVERIFY(a) |
|
68 |
|
69 QTM_USE_NAMESPACE |
|
70 class tst_QMediaRecorder: public QObject |
|
71 { |
|
72 Q_OBJECT |
|
73 |
|
74 public slots: |
|
75 void initTestCase(); |
|
76 void cleanupTestCase(); |
|
77 |
|
78 private slots: |
|
79 void testAudioSink(); |
|
80 void testAudioRecord(); |
|
81 void testAudioEndPointSelector(); |
|
82 void testAudioEncoderControl(); |
|
83 void testMediaFormatsControl(); |
|
84 // void testDefaultAudioEncodingSettings(); |
|
85 |
|
86 private: |
|
87 |
|
88 QAudioEncoderControl *audioEncoder; |
|
89 QAudioEndpointSelector *audioEndpoint; |
|
90 QMediaRecorder *audiocapture; |
|
91 QAudioCaptureSource *captureSource; |
|
92 }; |
|
93 |
|
94 void tst_QMediaRecorder::initTestCase() |
|
95 { |
|
96 qRegisterMetaType<QtMobility::QMediaRecorder::State>("QMediaRecorder::State"); |
|
97 qRegisterMetaType<QtMobility::QMediaRecorder::Error>("QMediaRecorder::Error"); |
|
98 |
|
99 captureSource = new QAudioCaptureSource; |
|
100 audiocapture = new QMediaRecorder(captureSource); |
|
101 |
|
102 audioEndpoint = qobject_cast<QAudioEndpointSelector*>(audiocapture->service()->control(QAudioEndpointSelector_iid)); |
|
103 audioEncoder = qobject_cast<QAudioEncoderControl*>(audiocapture->service()->control(QAudioEncoderControl_iid)); |
|
104 } |
|
105 |
|
106 void tst_QMediaRecorder::cleanupTestCase() |
|
107 { |
|
108 delete audiocapture; |
|
109 delete captureSource; |
|
110 } |
|
111 |
|
112 void tst_QMediaRecorder::testAudioSink() |
|
113 { |
|
114 audiocapture->setOutputLocation(QUrl("test.tmp")); |
|
115 QUrl s = audiocapture->outputLocation(); |
|
116 QCOMPARE(s.toString(), QString("test.tmp")); |
|
117 } |
|
118 |
|
119 void tst_QMediaRecorder::testAudioRecord() |
|
120 { |
|
121 } |
|
122 |
|
123 void tst_QMediaRecorder::testAudioEndPointSelector() |
|
124 { |
|
125 QSignalSpy audioSignal(audioEndpoint,SIGNAL(activeEndpointChanged(QString))); |
|
126 QVERIFY(audioEndpoint->availableEndpoints().count() == 1); |
|
127 QVERIFY(audioEndpoint->defaultEndpoint().compare("MMF") == 0); |
|
128 audioEndpoint->setActiveEndpoint("device2"); |
|
129 QVERIFY(audioEndpoint->activeEndpoint().compare("device2") == 0); |
|
130 QVERIFY(audioSignal.count() == 1); |
|
131 QVERIFY(audioEndpoint->endpointDescription("device2").compare("") == 0); |
|
132 } |
|
133 |
|
134 void tst_QMediaRecorder::testAudioEncoderControl() |
|
135 { |
|
136 QStringList codecs = audiocapture->supportedAudioCodecs(); |
|
137 QVERIFY(codecs.count() == 1); |
|
138 QVERIFY(audiocapture->audioCodecDescription("audio/wav") == "WAV Write Format"); |
|
139 QStringList options = audioEncoder->supportedEncodingOptions("audio/wav"); |
|
140 QCOMPARE(options.count(), 0); |
|
141 QVERIFY(audioEncoder->encodingOption("audio/wav","bitrate").toInt() == -1); |
|
142 audioEncoder->setEncodingOption("audio/wav", "bitrate", QString("vbr")); |
|
143 QCOMPARE(audioEncoder->encodingOption("audio/wav","bitrate").toInt(), -1); |
|
144 QCOMPARE(audiocapture->supportedAudioSampleRates(), QList<int>() << 44100); |
|
145 } |
|
146 |
|
147 void tst_QMediaRecorder::testMediaFormatsControl() |
|
148 { |
|
149 //audioocontainer types |
|
150 QCOMPARE(audiocapture->supportedContainers(), QStringList() << "audio/wav" << "audio/pcm"); |
|
151 QCOMPARE(audiocapture->containerDescription("audio/pcm"), QString("WAV file format")); |
|
152 QCOMPARE(audiocapture->containerDescription("audio/x-wav"), QString("RAW file format")); |
|
153 } |
|
154 |
|
155 /* |
|
156 void tst_QMediaRecorder::testDefaultAudioEncodingSettings() |
|
157 { |
|
158 QAudioEncoderSettings audioSettings = audiocapture->audioSettings(); |
|
159 QCOMPARE(audioSettings.codec(), QString("AMR")); |
|
160 QString format = audiocapture->containerMimeType(); |
|
161 QCOMPARE(format, QString("audio/amr")); |
|
162 /* QCOMPARE(audioSettings.bitRate(), 128*1024); |
|
163 QCOMPARE(audioSettings.sampleRate(), -1); |
|
164 QCOMPARE(audioSettings.quality(), QtMedia::NormalQuality); |
|
165 QCOMPARE(audioSettings.channelCount(), -1); |
|
166 |
|
167 QCOMPARE(audioSettings.encodingMode(), QtMedia::ConstantQualityEncoding); |
|
168 |
|
169 }*/ |
|
170 |
|
171 |
|
172 QTEST_MAIN(tst_QMediaRecorder) |
|
173 |
|
174 #include "tst_qmediarecorder_s60.moc" |