summaryrefslogtreecommitdiffstats
path: root/src/plugins/symbian/openmaxal/mediarecorder/qxarecordsession.cpp
blob: ec86761e2e05e28c51be7af289873c684538e80f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
/****************************************************************************
**
** 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 Qt Mobility Components.
**
** $QT_BEGIN_LICENSE:LGPL$
** GNU Lesser General Public License Usage
** 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.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU General
** Public License version 3.0 as published by the Free Software Foundation
** and appearing in the file LICENSE.GPL included in the packaging of this
** file. Please review the following information to ensure the GNU General
** Public License version 3.0 requirements will be met:
** http://www.gnu.org/copyleft/gpl.html.
**
** Other Usage
** Alternatively, this file may be used in accordance with the terms and
** conditions contained in a signed written agreement between you and Nokia.
**
**
**
**
**
** $QT_END_LICENSE$
**
****************************************************************************/

#include <QVariant>
#include <QtCore/qdir.h>
#include <qtmedianamespace.h>
#include "qxarecordsession.h"
#include "xarecordsessionimpl.h"
#include "qxacommon.h"

/* The following declaration is required to allow QList<int> to be added to
 * QVariant
 */
Q_DECLARE_METATYPE(QList<uint>)

/* This macro checks for m_impl null pointer. If it is, emits an error signal
 * error(QMediaRecorder::ResourceError, tr("Service has not been started"));
 * and returns from function immediately with value 's'.
 */

#define RETURN_s_IF_m_impl_IS_NULL(s) \
    if (!m_impl) { \
        emit error(QMediaRecorder::ResourceError, QXARecordSession::tr("Service has not been started")); \
        SIGNAL_EMIT_TRACE1("emit error(QMediaRecorder::ResourceError, tr(\"Service has not been started\"))"); \
        return s; \
        }

/* This macro checks for m_impl null pointer. If it is, emits an error signal
 * error(QMediaRecorder::ResourceError, tr("Service has not been started"));
 * and returns from function immediately.
 */
#define RETURN_IF_m_impl_IS_NULL \
    if (!m_impl) { \
        emit error(QMediaRecorder::ResourceError, QXARecordSession::tr("Service has not been started")); \
        SIGNAL_EMIT_TRACE1("emit error(QMediaRecorder::ResourceError, tr(\"Service has not been started\"))"); \
        return; \
        }

QXARecordSession::QXARecordSession(QObject *parent)
:QObject(parent),
m_state(QMediaRecorder::StoppedState),
m_previousState(QMediaRecorder::StoppedState)
{
    QT_TRACE_FUNCTION_ENTRY;
    m_impl = NULL;
    m_impl = new XARecordSessionImpl(*this);
    if (m_impl) {
        if (m_impl->postConstruct() == KErrNone) {
            initCodecsList();
            initContainersList();
            m_containerMimeType = QString("audio/wav");
            m_audioencodersettings.setCodec("pcm");
            m_audioencodersettings.setBitRate(0);
            m_audioencodersettings.setChannelCount(-1);
            m_audioencodersettings.setEncodingMode(QtMultimediaKit::ConstantQualityEncoding);
            m_audioencodersettings.setQuality(QtMultimediaKit::NormalQuality);
            m_audioencodersettings.setSampleRate(-1);
            setEncoderSettingsToImpl();
            m_URItoImplSet = false;
            QT_TRACE1("Initialized implementation");
        }
        else {
            delete m_impl;
            m_impl = NULL;
            QT_TRACE1("Error initializing implementation");
        }
    }
    else {
        emit error(QMediaRecorder::ResourceError, tr("Unable to start Service"));
    }
    QT_TRACE_FUNCTION_EXIT;
}

QXARecordSession::~QXARecordSession()
{
    QT_TRACE_FUNCTION_ENTRY;
    delete m_impl;
    QT_TRACE_FUNCTION_EXIT;
}

QUrl QXARecordSession::outputLocation()
{
    return m_outputLocation;
}

bool QXARecordSession::setOutputLocation(const QUrl &location)
{
    QT_TRACE_FUNCTION_ENTRY;

    RETURN_s_IF_m_impl_IS_NULL(false);

    // Location can be set only when recorder is in stopped state.
    if (state() != QMediaRecorder::StoppedState)
        return false;

    // Validate URL
    if (!location.isValid())
        return false;

    // If old and new locations are same, do nothing.
    QString newUrlStr = (QUrl::fromUserInput(location.toString())).toString();
    QString curUrlStr = (QUrl::fromUserInput(m_outputLocation.toString())).toString();
    if (curUrlStr.compare(newUrlStr) == KErrNone)
        return true;

    QT_TRACE2("Location:", newUrlStr);
    m_outputLocation = location;
    /* New file, so user can set new settings */
    m_previousState = QMediaRecorder::StoppedState;
    m_URItoImplSet = false;

    QT_TRACE_FUNCTION_EXIT;
    return true;
}

QMediaRecorder::State QXARecordSession::state()
{
    return m_state;
}

qint64 QXARecordSession::duration()
{
    TInt64 dur(0);

    QT_TRACE_FUNCTION_ENTRY;

    RETURN_s_IF_m_impl_IS_NULL(dur);

    m_impl->duration(dur);

    QT_TRACE_FUNCTION_EXIT;
    return (qint64)dur;
}

void QXARecordSession::applySettings()
{
    /* Settings can only be applied when the recorder is in the stopped
     * state after creation. */
    if ((state() == QMediaRecorder::StoppedState) && (m_state == m_previousState)) {
        if (m_appliedaudioencodersettings != m_audioencodersettings)
            setEncoderSettingsToImpl();
    }
    else {
        emit error(QMediaRecorder::FormatError, tr("Settings cannot be changed once recording started"));
        SIGNAL_EMIT_TRACE1("emit error(QMediaRecorder::FormatError, tr(\"Settings cannot be changed once recording started\"))");
    }
}

void QXARecordSession::record()
{
    QT_TRACE_FUNCTION_ENTRY;

    RETURN_IF_m_impl_IS_NULL;

    /* No op if object is already in recording state */
    if (state() == QMediaRecorder::RecordingState)
        return;

    /* 1. Set encoder settings here */
    if (m_appliedaudioencodersettings != m_audioencodersettings)
        RET_IF_FALSE(setEncoderSettingsToImpl());

    /* 2. Set URI to impl */
    RET_IF_FALSE(setURIToImpl());

    /* 3. Start recording...
     * If successful, setRecorderState(QMediaRecorder::RecordingState);
     * will be called from the callback cbRecordingStarted()
     */
    if (m_impl->record() != KErrNone) {
        emit error(QMediaRecorder::ResourceError, tr("Generic error"));
        SIGNAL_EMIT_TRACE1("emit error(QMediaRecorder::ResourceError, tr(\"Generic error\"))");
        }

    QT_TRACE_FUNCTION_EXIT;
}

void QXARecordSession::pause()
{
    QT_TRACE_FUNCTION_ENTRY;

    RETURN_IF_m_impl_IS_NULL;

    /* No op if object is already in paused/stopped state */
    if ((state() == QMediaRecorder::PausedState) || (state() == QMediaRecorder::StoppedState)) {
        return;
    }

    if (m_impl->pause() == KErrNone) {
        setRecorderState(QMediaRecorder::PausedState);
    }
    else {
        emit error(QMediaRecorder::ResourceError, tr("Unable to pause"));
        SIGNAL_EMIT_TRACE1("emit error(QMediaRecorder::ResourceError, tr(\"Unable to pause\"))");
    }

    QT_TRACE_FUNCTION_EXIT;
}

void QXARecordSession::stop()
{
    QT_TRACE_FUNCTION_ENTRY;

    RETURN_IF_m_impl_IS_NULL;

    /* No op if object is already in paused state */
    if (state() == QMediaRecorder::StoppedState)
        return;

    if ((m_impl->stop() == KErrNone)) {
        setRecorderState(QMediaRecorder::StoppedState);
    }
    else {
        emit error(QMediaRecorder::ResourceError, tr("Unable to stop"));
        SIGNAL_EMIT_TRACE1("emit error(QMediaRecorder::ResourceError, tr(\"Unable to stop\"))");
    }

    QT_TRACE_FUNCTION_EXIT;
}

void QXARecordSession::cbDurationChanged(TInt64 new_pos)
{
    QT_TRACE_FUNCTION_ENTRY;

    emit durationChanged((qint64)new_pos);
    SIGNAL_EMIT_TRACE1("emit durationChanged((qint64)new_pos);");

    QT_TRACE_FUNCTION_EXIT;
}

void QXARecordSession::cbAvailableAudioInputsChanged()
{
    QT_TRACE_FUNCTION_ENTRY;

    emit availableAudioInputsChanged();
    SIGNAL_EMIT_TRACE1("emit availableAudioInputsChanged();");

    QT_TRACE_FUNCTION_EXIT;
}

void QXARecordSession::cbRecordingStarted()
{
    QT_TRACE_FUNCTION_ENTRY;

    setRecorderState(QMediaRecorder::RecordingState);

    QT_TRACE_FUNCTION_EXIT;
}

void QXARecordSession::cbRecordingStopped()
{
    QT_TRACE_FUNCTION_ENTRY;

    emit error(QMediaRecorder::ResourceError, tr("Resources Unavailable"));
    SIGNAL_EMIT_TRACE1("emit error(QMediaRecorder::ResourceError, tr(\"Resources Unavailable\"))");
    setRecorderState(QMediaRecorder::StoppedState);
    /* Set record state to Stopped */
    if (m_impl)
        m_impl->stop();

    QT_TRACE_FUNCTION_EXIT;
}

/* For QAudioEndpointSelector begin */
QList<QString> QXARecordSession::availableEndpoints()
{
    QT_TRACE_FUNCTION_ENTRY;

    QList<QString> strList;

    RETURN_s_IF_m_impl_IS_NULL(strList);

    QString str;
    RArray<TPtrC> names;
    m_impl->getAudioInputDeviceNames(names);
    for (TInt index = 0; index < names.Count(); index++) {
        str = QString((QChar*)names[index].Ptr(), names[index].Length());
        strList.append(str);
    }

    QT_TRACE_FUNCTION_EXIT;
    return strList;
}

QString QXARecordSession::endpointDescription(const QString &name)
{
    /* From AL we get only device name */
    return name;
}

QString QXARecordSession::defaultEndpoint()
{
    QT_TRACE_FUNCTION_ENTRY;

    QString str;

    RETURN_s_IF_m_impl_IS_NULL(str);

    TPtrC name;
    if(m_impl->defaultAudioInputDevice(name) == KErrNone)
        str = QString((QChar*)name.Ptr(), name.Length());

    QT_TRACE_FUNCTION_EXIT;
    return str;
}

QString QXARecordSession::activeEndpoint()
{
    QT_TRACE_FUNCTION_ENTRY;

    QString str;

    RETURN_s_IF_m_impl_IS_NULL(str);

    TPtrC name;
    if(m_impl->activeAudioInputDevice(name) == KErrNone)
        str = QString((QChar*)name.Ptr(), name.Length());

    QT_TRACE_FUNCTION_EXIT;
    return str;
}

void QXARecordSession::setActiveEndpoint(const QString &name)
{
    QT_TRACE_FUNCTION_ENTRY;

    RETURN_IF_m_impl_IS_NULL;

    if (name.isNull() || name.isEmpty())
        return;

    TPtrC16 tempPtr(reinterpret_cast<const TUint16*>(name.utf16()));
    if (m_impl->setAudioInputDevice(tempPtr) == true) {
        emit activeEndpointChanged(name);
        SIGNAL_EMIT_TRACE1("emit activeEndpointChanged(name)");
    }
    else {
        emit error(QMediaRecorder::ResourceError, tr("Invalid endpoint"));
        SIGNAL_EMIT_TRACE1("emit error(QMediaRecorder::ResourceError, tr(\"Invalid endpoint\"))");
        }

    QT_TRACE_FUNCTION_EXIT;
}
/* For QAudioEndpointSelector end */

/* For QAudioEncoderControl begin */
QStringList QXARecordSession::supportedAudioCodecs()
{
    return m_codecs;
}

QString QXARecordSession::codecDescription(const QString &codecName)
{
    if (m_codecs.contains(codecName))
        return QString(codecName);
    return QString();
}

QList<int> QXARecordSession::supportedSampleRates(
            const QAudioEncoderSettings &settings,
            bool *continuous)
{
    QT_TRACE_FUNCTION_ENTRY;

    QList<int> srList;

    RETURN_s_IF_m_impl_IS_NULL(srList);

    QString selectedCodec = settings.codec();
    if (selectedCodec.isNull() || selectedCodec.isEmpty())
        selectedCodec = QString("pcm");

    if (m_codecs.indexOf(selectedCodec) >= 0) {
        RArray<TInt32> sampleRates;
        TBool isContinuous;
        TPtrC16 tempPtr(reinterpret_cast<const TUint16*>(selectedCodec.utf16()));
        if (m_impl->getSampleRates(tempPtr, sampleRates, isContinuous) == KErrNone) {
            for (TInt index = 0; index < sampleRates.Count(); index++)
                srList.append(sampleRates[index]);
            sampleRates.Close();
            if (continuous)
                {
                *continuous = false;
                if (isContinuous == true)
                    *continuous = true;
                }
        }
    }

    QT_TRACE_FUNCTION_EXIT;
    return srList;
}

QAudioEncoderSettings QXARecordSession::audioSettings()
{
    return m_appliedaudioencodersettings;
}

void QXARecordSession::setAudioSettings(const QAudioEncoderSettings &settings)
{
    /* Settings can only be set when the recorder is in the stopped
     * state after creation. */
    if ((state() == QMediaRecorder::StoppedState) && (m_state == m_previousState)) {
        /* Validate and ignore rest of the settings */
        m_audioencodersettings = settings;
    }
    else {
        emit error(QMediaRecorder::FormatError, tr("Settings cannot be changed once recording started"));
        SIGNAL_EMIT_TRACE1("emit error(QMediaRecorder::FormatError, tr(\"Settings cannot be changed once recording started\"))");
    }
}

QStringList QXARecordSession::supportedEncodingOptions(const QString &codec)
{
    QT_TRACE_FUNCTION_ENTRY;
    Q_UNUSED(codec);
    QStringList options;
    if ((codec.compare("aac") == 0) ||
            (codec.compare("amr") == 0))
        {
        options << "bitrate" << "quality";
        }


    QT_TRACE_FUNCTION_EXIT;
    return options;
}

QVariant QXARecordSession::encodingOption(const QString &codec, const QString &name)
{
    QT_TRACE_FUNCTION_ENTRY;

    QVariant encodingOption;
    QMap<QString, QVariant> map;
    RETURN_s_IF_m_impl_IS_NULL(encodingOption);

    if (name.compare("bitrate") == 0) {
        TPtrC16 tempPtr(reinterpret_cast<const TUint16*>(codec.utf16()));
        QList<uint> bitrateList;
        RArray<TUint32> bitrates;
        TBool continuous;
        if (m_impl->getBitrates(tempPtr, bitrates, continuous) == KErrNone) {
            for (TInt index = 0; index < bitrates.Count(); index++)
                bitrateList.append(bitrates[index]);
            bitrates.Close();
        }
        encodingOption.setValue(bitrateList);
        map.insert("continuous", QVariant(continuous));
        map.insert("bitrates", encodingOption);
    }

    QT_TRACE_FUNCTION_EXIT;
    return map;
}

void QXARecordSession::setEncodingOption(
                                    const QString &codec,
                                    const QString &name,
                                    const QVariant &value)
{
    /*
     * Currently nothing can be set via this function.
     * Bitrate is set via QAudioEncoderSettings::setBitrate().
     */
    Q_UNUSED(codec);
    Q_UNUSED(name);
    Q_UNUSED(value);
}
/* For QAudioEncoderControl end */

QStringList QXARecordSession::supportedContainers()
{
    return m_containers;
}

QString QXARecordSession::containerMimeType()
{
    return m_containerMimeType;
}

void QXARecordSession::setContainerMimeType(const QString &formatMimeType)
{
    if (formatMimeType.isNull() || formatMimeType.isEmpty())
        return;
    else if (m_containers.indexOf(formatMimeType) >= 0 )
        m_containerMimeType = formatMimeType;
    else {
        emit error(QMediaRecorder::FormatError, tr("Invalid container"));
        SIGNAL_EMIT_TRACE1("emit error(QMediaRecorder::FormatError, tr(\"Invalid container\"))");
        }
}

QString QXARecordSession::containerDescription(const QString &formatMimeType)
{
    int index = m_containers.indexOf(formatMimeType);
    if (index >= 0) {
        return m_containersDesc.at(index);
        }
    else {
        emit error(QMediaRecorder::FormatError, tr("Invalid container"));
        SIGNAL_EMIT_TRACE1("emit error(QMediaRecorder::FormatError, tr(\"Invalid container\"))");
    }
    return QString();
}

void QXARecordSession::setRecorderState(QMediaRecorder::State state)
{
    if (state != m_state) {
        m_previousState = m_state;
        m_state = state;
        emit stateChanged(m_state);
        SIGNAL_EMIT_TRACE1("emit stateChanged(m_state);");
    }
}

void QXARecordSession::initCodecsList()
{
    QT_TRACE_FUNCTION_ENTRY;

    RETURN_IF_m_impl_IS_NULL;

    m_codecs.clear();

    const RArray<TPtrC>& names = m_impl->getAudioEncoderNames();
    QString str;

    for (TInt index = 0; index < names.Count(); index++) {
        str = QString((QChar*)names[index].Ptr(), names[index].Length());
        m_codecs.append(str);
    }
    QT_TRACE_FUNCTION_EXIT;
}

void QXARecordSession::initContainersList()
{
    QT_TRACE_FUNCTION_ENTRY;

    RETURN_IF_m_impl_IS_NULL;

    m_containers.clear();
    m_containersDesc.clear();

    const RArray<TPtrC>& names = m_impl->getContainerNames();
    const RArray<TPtrC>& descs = m_impl->getContainerDescs();
    QString str;

    for (TInt32 index = 0; index < names.Count(); index++) {
        str = QString((QChar*)names[index].Ptr(), names[index].Length());
        m_containers.append(str);
        str = QString((QChar*)descs[index].Ptr(), descs[index].Length());
        m_containersDesc.append(str);
    }
    QT_TRACE_FUNCTION_EXIT;
}

bool QXARecordSession::setEncoderSettingsToImpl()
{
    QT_TRACE_FUNCTION_ENTRY;

    RETURN_s_IF_m_impl_IS_NULL(false);

    m_impl->resetEncoderAttributes();

    /* m_containerMimeType is alredy validated in ::setContainerMimeType() */
    QString tempStr = m_containerMimeType;
    TPtrC16 tempPtr(reinterpret_cast<const TUint16 *>(tempStr.utf16()));
    m_impl->setContainerType(tempPtr);

    /* vaidate and assign codec */
    if (m_audioencodersettings.codec().isNull() || m_audioencodersettings.codec().isEmpty()) {
        m_audioencodersettings.setCodec(m_appliedaudioencodersettings.codec());
    }
    tempStr = m_audioencodersettings.codec();
    if (m_codecs.indexOf(tempStr) >= 0) {
        tempPtr.Set(reinterpret_cast<const TUint16*>(tempStr.utf16()));
        /* We already did validation above, so function always returns true */
        m_impl->setCodec(tempPtr);
    }
    else {
        QT_TRACE2("Codec selected is :", m_audioencodersettings.codec());
        emit error(QMediaRecorder::FormatError, tr("Invalid codec"));
        SIGNAL_EMIT_TRACE1("emit error(QMediaRecorder::FormatError, tr(\"Invalid codec\"));");
        return false;
    }

    /* Validate and set bitrate only if encoding mode is other than quality encoding and container type is not wav*/
    if ((m_audioencodersettings.encodingMode() != QtMultimediaKit::ConstantQualityEncoding) &&
        (m_containerMimeType.compare("audio/wav") != 0)) {
            m_impl->setBitRate(m_audioencodersettings.bitRate());
            m_audioencodersettings.setBitRate(m_impl->getBitRate());
    }

    if (m_audioencodersettings.channelCount() == -1) {
        m_impl->setOptimalChannelCount();
    }
    else {
        m_impl->setChannels(m_audioencodersettings.channelCount());
        m_audioencodersettings.setChannelCount(m_impl->getChannels());
    }

    switch (m_audioencodersettings.encodingMode()) {
    case QtMultimediaKit::ConstantQualityEncoding: {
            switch (m_audioencodersettings.quality()) {
            case QtMultimediaKit::VeryLowQuality:
                m_impl->setVeryLowQuality();
                m_audioencodersettings.setBitRate(m_impl->getBitRate());
                break;
            case QtMultimediaKit::LowQuality:
                m_impl->setLowQuality();
                m_audioencodersettings.setBitRate(m_impl->getBitRate());
                break;
            case QtMultimediaKit::NormalQuality:
                m_impl->setNormalQuality();
                m_audioencodersettings.setBitRate(m_impl->getBitRate());
                break;
            case QtMultimediaKit::HighQuality:
                m_impl->setHighQuality();
                m_audioencodersettings.setBitRate(m_impl->getBitRate());
                break;
            case QtMultimediaKit::VeryHighQuality:
                m_impl->setVeryHighQuality();
                m_audioencodersettings.setBitRate(m_impl->getBitRate());
                break;
            default:
                break;
            }; /* end of switch (m_audioencodersettings.quality())*/
        }
        break;
    case QtMultimediaKit::ConstantBitRateEncoding: {
            TInt32 status = m_impl->setCBRMode();
            if (status == KErrNotSupported) {
                emit error(QMediaRecorder::FormatError, tr("Invalid encoding mode setting"));
                SIGNAL_EMIT_TRACE1("emit error(QMediaRecorder::FormatError, tr(\"Invalid encoding mode setting\"));");
                return false;
            }
            else if (status != KErrNone) {
                emit error(QMediaRecorder::ResourceError, tr("Internal error"));
                SIGNAL_EMIT_TRACE1("emit error(QMediaRecorder::ResourceError, tr(\"Internal error\"));");
                return false;
            }
        }
        break;
    case QtMultimediaKit::AverageBitRateEncoding: {
            TInt32 status = m_impl->setVBRMode();
            if (status == KErrNotSupported) {
                emit error(QMediaRecorder::FormatError, tr("Invalid encoding mode setting"));
                SIGNAL_EMIT_TRACE1("emit error(QMediaRecorder::FormatError, tr(\"Invalid encoding mode setting\"));");
                return false;
            }
            else if (status != KErrNone) {
                emit error(QMediaRecorder::ResourceError, tr("Internal error"));
                SIGNAL_EMIT_TRACE1("emit error(QMediaRecorder::ResourceError, tr(\"Internal error\"));");
                return false;
            }
        }
        break;
    case QtMultimediaKit::TwoPassEncoding:
        // fall through
    default: {
            emit error(QMediaRecorder::FormatError, tr("Invalid encoding mode setting"));
            SIGNAL_EMIT_TRACE1("emit error(QMediaRecorder::FormatError, tr(\"Invalid encoding mode setting\"));");
            return false;
        }
    }; /* switch (m_audioencodersettings.encodingMode()) */

    if (m_audioencodersettings.sampleRate() == -1) {
        m_impl->setOptimalSampleRate();
    }
    else {
        m_impl->setSampleRate(m_audioencodersettings.sampleRate());
        m_audioencodersettings.setSampleRate(m_impl->getSampleRate());
    }
    m_appliedaudioencodersettings = m_audioencodersettings;

    QT_TRACE_FUNCTION_EXIT;
    return true;
}

bool QXARecordSession::setURIToImpl()
{
    QT_TRACE_FUNCTION_ENTRY;
    if (m_URItoImplSet)
        return true;

    /* If m_outputLocation is null, set a default location */
    if (m_outputLocation.isEmpty()) {
        QDir outputDir(QDir::rootPath());

        int lastImage = 0;
        int fileCount = 0;
        foreach(QString fileName, outputDir.entryList(QStringList() << "recordclip_*")) {
            int imgNumber = fileName.mid(5, fileName.size() - 9).toInt();
            lastImage = qMax(lastImage, imgNumber);
            if (outputDir.exists(fileName))
                fileCount += 1;
        }
        lastImage += fileCount;
        m_outputLocation = QUrl(QDir::toNativeSeparators(outputDir.canonicalPath() + QString("/recordclip_%1").arg(lastImage + 1, 4, 10, QLatin1Char('0'))));
    }

    QString newUrlStr = (QUrl::fromUserInput(m_outputLocation.toString())).toString();
    // append file prefix if required
    if (newUrlStr.lastIndexOf('.') == -1) {
        QString fileExtension;
        if ((m_containerMimeType.compare("audio/wav")) == KErrNone) {
            fileExtension = QString(".wav");
        }
        else if ((m_containerMimeType.compare("audio/amr")) == KErrNone) {
            fileExtension = QString(".amr");
        }
        else if ((m_containerMimeType.compare("audio/mpeg")) == KErrNone) {
            fileExtension = QString(".mp4");
        }
        newUrlStr.append(fileExtension);
    }

    QT_TRACE2("Filename selected is :", newUrlStr);
    TPtrC16 tempPtr(reinterpret_cast<const TUint16 *>(newUrlStr.utf16()));
    if (m_impl->setURI(tempPtr) != 0) {
        emit error(QMediaRecorder::ResourceError, tr("Generic error"));
        SIGNAL_EMIT_TRACE1("emit error(QMediaRecorder::ResourceError, tr(\"Generic error\"))");
        return false;
    }
    m_URItoImplSet = true;
    m_outputLocation = QUrl(newUrlStr);
    QT_TRACE_FUNCTION_EXIT;
    return true;
}