0
|
1 |
// Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
2 |
// All rights reserved.
|
|
3 |
// This component and the accompanying materials are made available
|
|
4 |
// under the terms of "Eclipse Public License v1.0"
|
|
5 |
// which accompanies this distribution, and is available
|
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
7 |
//
|
|
8 |
// Initial Contributors:
|
|
9 |
// Nokia Corporation - initial contribution.
|
|
10 |
//
|
|
11 |
// Contributors:
|
|
12 |
//
|
|
13 |
// Description:
|
|
14 |
//
|
|
15 |
|
|
16 |
/**
|
|
17 |
@file
|
|
18 |
@internalComponent
|
|
19 |
*/
|
|
20 |
|
|
21 |
#include <mdf/mdfpuconfig.h>
|
|
22 |
#include <mmf/server/taskconfig.h>
|
|
23 |
#include <omxprocessingunit.h>
|
|
24 |
|
|
25 |
#include "vorbisencoderprocessingunit.h"
|
|
26 |
#include "vorbisencoderinputport.h"
|
|
27 |
#include "vorbisencoderoutputport.h"
|
|
28 |
|
|
29 |
const TInt KVorbisEncoderInputPortIndex = 0;
|
|
30 |
const TInt KVorbisEncoderOutputPortIndex = 1;
|
|
31 |
|
|
32 |
_LIT8(KVorbisEncoderILComponentName,"OMX.SYMBIAN.AUDIO.ENCODER.VORBIS");
|
|
33 |
|
|
34 |
// for the derivation of these constants see
|
|
35 |
// http://en.wikipedia.org/wiki/Vorbis
|
|
36 |
const TInt KVorbisQualityMinus1 = 4500;
|
|
37 |
const TInt KVorbisQuality0 = 6000;
|
|
38 |
const TInt KVorbisQuality1 = 80000;
|
|
39 |
const TInt KVorbisQuality2 = 96000;
|
|
40 |
const TInt KVorbisQuality3 = 110000;
|
|
41 |
const TInt KVorbisQuality4 = 128000;
|
|
42 |
const TInt KVorbisQuality5 = 160000;
|
|
43 |
const TInt KVorbisQuality6 = 192000;
|
|
44 |
const TInt KVorbisQuality7 = 224000;
|
|
45 |
const TInt KVorbisQuality8 = 256000;
|
|
46 |
const TInt KVorbisQuality9 = 320000;
|
|
47 |
const TInt KVorbisQuality10 = 500000;
|
|
48 |
|
|
49 |
CVorbisEncoderProcessingUnit::CVorbisEncoderProcessingUnit()
|
|
50 |
: iVorbisEncoderInputPort(NULL),
|
|
51 |
iVorbisEncoderOutputPort(NULL)
|
|
52 |
{
|
|
53 |
|
|
54 |
// input defaults (EPCM16)
|
|
55 |
iInputBitsPerSample = 16;
|
|
56 |
iNumInputType = OMX_NumericalDataSigned;
|
|
57 |
|
|
58 |
// no output defaults (EVorbis)
|
|
59 |
}
|
|
60 |
|
|
61 |
CVorbisEncoderProcessingUnit* CVorbisEncoderProcessingUnit::NewL()
|
|
62 |
{
|
|
63 |
CVorbisEncoderProcessingUnit* self = new (ELeave) CVorbisEncoderProcessingUnit;
|
|
64 |
CleanupStack::PushL(self);
|
|
65 |
self->ConstructL();
|
|
66 |
CleanupStack::Pop(self);
|
|
67 |
return self;
|
|
68 |
}
|
|
69 |
|
|
70 |
void CVorbisEncoderProcessingUnit::ConstructL()
|
|
71 |
{
|
|
72 |
// setup supported bit rates array
|
|
73 |
iSupportedBitRates.Reset();
|
|
74 |
iSupportedBitRates.AppendL(KVorbisQualityMinus1);
|
|
75 |
iSupportedBitRates.AppendL(KVorbisQuality0);
|
|
76 |
iSupportedBitRates.AppendL(KVorbisQuality1);
|
|
77 |
iSupportedBitRates.AppendL(KVorbisQuality2);
|
|
78 |
iSupportedBitRates.AppendL(KVorbisQuality3);
|
|
79 |
iSupportedBitRates.AppendL(KVorbisQuality4);
|
|
80 |
iSupportedBitRates.AppendL(KVorbisQuality5);
|
|
81 |
iSupportedBitRates.AppendL(KVorbisQuality6);
|
|
82 |
iSupportedBitRates.AppendL(KVorbisQuality7);
|
|
83 |
iSupportedBitRates.AppendL(KVorbisQuality8);
|
|
84 |
iSupportedBitRates.AppendL(KVorbisQuality9);
|
|
85 |
iSupportedBitRates.AppendL(KVorbisQuality10);
|
|
86 |
}
|
|
87 |
|
|
88 |
CVorbisEncoderProcessingUnit::~CVorbisEncoderProcessingUnit()
|
|
89 |
{
|
|
90 |
iSupportedBitRates.Reset();
|
|
91 |
iSupportedBitRates.Close();
|
|
92 |
delete iVorbisEncoderOutputPort;
|
|
93 |
delete iVorbisEncoderInputPort;
|
|
94 |
}
|
|
95 |
|
|
96 |
TInt CVorbisEncoderProcessingUnit::Create(const MMdfProcessingUnitObserver& aProcessingUnitObserver)
|
|
97 |
{
|
|
98 |
TRAPD(err, CreateL(aProcessingUnitObserver));
|
|
99 |
return err;
|
|
100 |
}
|
|
101 |
|
|
102 |
|
|
103 |
void CVorbisEncoderProcessingUnit::CreateL(const MMdfProcessingUnitObserver& aProcessingUnitObserver)
|
|
104 |
{
|
|
105 |
COmxProcessingUnit::ConstructL(KVorbisEncoderILComponentName, aProcessingUnitObserver);
|
|
106 |
iVorbisEncoderInputPort = CVorbisEncoderInputPort::NewL(KVorbisEncoderInputPortIndex, this);
|
|
107 |
iVorbisEncoderOutputPort = CVorbisEncoderOutputPort::NewL(KVorbisEncoderOutputPortIndex, this);
|
|
108 |
User::LeaveIfError(AddInputPort(iVorbisEncoderInputPort));
|
|
109 |
User::LeaveIfError(AddOutputPort(iVorbisEncoderOutputPort));
|
|
110 |
}
|
|
111 |
|
|
112 |
|
|
113 |
|
|
114 |
|
|
115 |
TInt CVorbisEncoderProcessingUnit::CreateCustomInterface(TUid aInterfaceId)
|
|
116 |
{
|
|
117 |
if (aInterfaceId == KUidCustomInterfaceDevSoundBitRate)
|
|
118 |
{
|
|
119 |
// There is no work to create this interface, so just return no error
|
|
120 |
return KErrNone;
|
|
121 |
}
|
|
122 |
else
|
|
123 |
{
|
|
124 |
return KErrNotSupported;
|
|
125 |
}
|
|
126 |
}
|
|
127 |
|
|
128 |
TAny* CVorbisEncoderProcessingUnit::CustomInterface(TUid aInterfaceId)
|
|
129 |
{
|
|
130 |
// The vorbis encoder requires the custom interface for bitrates
|
|
131 |
if (aInterfaceId == KUidCustomInterfaceDevSoundBitRate)
|
|
132 |
{
|
|
133 |
return static_cast<MMMFDevSoundCustomInterfaceBitRate*> (this);
|
|
134 |
}
|
|
135 |
else
|
|
136 |
{
|
|
137 |
return NULL;
|
|
138 |
}
|
|
139 |
}
|
|
140 |
|
|
141 |
/**
|
|
142 |
Gets the bit rates that are supported by DevSound in its current configuration.
|
|
143 |
|
|
144 |
@param aSupportedBitRates
|
|
145 |
The supported bit rates, in bits per second, shall be appended to this array. Note that
|
|
146 |
the array shall be reset by this method.
|
|
147 |
*/
|
|
148 |
void CVorbisEncoderProcessingUnit::GetSupportedBitRatesL(RArray<TInt>& aSupportedBitRates)
|
|
149 |
{
|
|
150 |
aSupportedBitRates.Reset();
|
|
151 |
TInt c = iSupportedBitRates.Count();
|
|
152 |
for(TInt i = 0; i < c; i++)
|
|
153 |
{
|
|
154 |
aSupportedBitRates.AppendL(iSupportedBitRates[i]);
|
|
155 |
}
|
|
156 |
}
|
|
157 |
|
|
158 |
TInt CVorbisEncoderProcessingUnit::BitRateL()
|
|
159 |
{
|
|
160 |
return iVorbisEncoderOutputPort->BitRate();
|
|
161 |
}
|
|
162 |
|
|
163 |
void CVorbisEncoderProcessingUnit::SetBitRateL(TInt aBitRate)
|
|
164 |
{
|
|
165 |
// We can't strictly set the bit rate outside of calling
|
|
166 |
// MopConfigure() on the output port.
|
|
167 |
// However if we own the port we can call its SetBitRateL() method
|
|
168 |
// which is not part of MMdfOutputPort.
|
|
169 |
|
|
170 |
// set the bitrate to the nearest available, rounding down
|
|
171 |
TInt c = iSupportedBitRates.Count();
|
|
172 |
for(TInt i = c-1; i >= 0; i--)
|
|
173 |
{
|
|
174 |
if(aBitRate >= iSupportedBitRates[i])
|
|
175 |
{
|
|
176 |
iVorbisEncoderOutputPort->SetBitRate(iSupportedBitRates[i]);
|
|
177 |
return;
|
|
178 |
}
|
|
179 |
}
|
|
180 |
User::Leave(KErrNotSupported);
|
|
181 |
}
|
|
182 |
|
|
183 |
// end
|
|
184 |
|
|
185 |
|
|
186 |
|