39 ** |
39 ** |
40 ****************************************************************************/ |
40 ****************************************************************************/ |
41 |
41 |
42 #include "qgstreameraudioencode.h" |
42 #include "qgstreameraudioencode.h" |
43 #include "qgstreamercapturesession.h" |
43 #include "qgstreamercapturesession.h" |
|
44 #include "qgstreamermediacontainercontrol.h" |
44 |
45 |
45 #include <QtCore/qdebug.h> |
46 #include <QtCore/qdebug.h> |
46 |
47 |
47 #include <math.h> |
48 #include <math.h> |
48 |
49 |
49 QGstreamerAudioEncode::QGstreamerAudioEncode(QObject *parent) |
50 QGstreamerAudioEncode::QGstreamerAudioEncode(QObject *parent) |
50 :QAudioEncoderControl(parent) |
51 :QAudioEncoderControl(parent) |
51 { |
52 { |
52 QList<QByteArray> codecCandidates; |
53 QList<QByteArray> codecCandidates; |
53 codecCandidates << "audio/mpeg" << "audio/vorbis" << "audio/speex" << "audio/GSM"; |
54 codecCandidates << "audio/mpeg" << "audio/vorbis" << "audio/speex" << "audio/GSM" |
54 |
55 << "audio/PCM" << "audio/AMR" << "audio/AMR-WB"; |
55 m_elementNames["audio/mpeg"] = "lame"; |
56 |
|
57 m_elementNames["audio/mpeg"] = "lamemp3enc"; |
56 m_elementNames["audio/vorbis"] = "vorbisenc"; |
58 m_elementNames["audio/vorbis"] = "vorbisenc"; |
57 m_elementNames["audio/speex"] = "speexenc"; |
59 m_elementNames["audio/speex"] = "speexenc"; |
58 m_elementNames["audio/GSM"] = "gsmenc"; |
60 m_elementNames["audio/GSM"] = "gsmenc"; |
|
61 m_elementNames["audio/PCM"] = "audioresample"; |
|
62 m_elementNames["audio/AMR"] = "amrnbenc"; |
|
63 m_elementNames["audio/AMR-WB"] = "amrwbenc"; |
|
64 |
59 |
65 |
60 m_codecOptions["audio/vorbis"] = QStringList() << "min-bitrate" << "max-bitrate"; |
66 m_codecOptions["audio/vorbis"] = QStringList() << "min-bitrate" << "max-bitrate"; |
61 m_codecOptions["audio/mpeg"] = QStringList() << "mode"; |
67 m_codecOptions["audio/mpeg"] = QStringList() << "mode"; |
62 m_codecOptions["audio/speex"] = QStringList() << "mode" << "vbr" << "vad" << "dtx"; |
68 m_codecOptions["audio/speex"] = QStringList() << "mode" << "vbr" << "vad" << "dtx"; |
63 m_codecOptions["audio/GSM"] = QStringList(); |
69 m_codecOptions["audio/GSM"] = QStringList(); |
|
70 m_codecOptions["audio/PCM"] = QStringList(); |
|
71 m_codecOptions["audio/AMR"] = QStringList(); |
|
72 m_codecOptions["audio/AMR-WB"] = QStringList(); |
64 |
73 |
65 foreach( const QByteArray& codecName, codecCandidates ) { |
74 foreach( const QByteArray& codecName, codecCandidates ) { |
66 QByteArray elementName = m_elementNames[codecName]; |
75 QByteArray elementName = m_elementNames[codecName]; |
67 GstElementFactory *factory = gst_element_factory_find(elementName.constData()); |
76 GstElementFactory *factory = gst_element_factory_find(elementName.constData()); |
68 |
77 |
69 if (factory) { |
78 if (factory) { |
70 m_codecs.append(codecName); |
79 m_codecs.append(codecName); |
71 const gchar *descr = gst_element_factory_get_description(factory); |
80 const gchar *descr = gst_element_factory_get_description(factory); |
72 m_codecDescriptions.insert(codecName, QString::fromUtf8(descr)); |
81 |
|
82 if (codecName == QByteArray("audio/PCM")) |
|
83 m_codecDescriptions.insert(codecName, tr("Raw PCM audio")); |
|
84 else |
|
85 m_codecDescriptions.insert(codecName, QString::fromUtf8(descr)); |
|
86 |
|
87 m_streamTypes.insert(codecName, |
|
88 QGstreamerMediaContainerControl::supportedStreamTypes(factory, GST_PAD_SRC)); |
73 |
89 |
74 gst_object_unref(GST_OBJECT(factory)); |
90 gst_object_unref(GST_OBJECT(factory)); |
75 } |
91 } |
76 } |
92 } |
77 |
93 |
78 if (!m_codecs.isEmpty()) |
94 //if (!m_codecs.isEmpty()) |
79 m_audioSettings.setCodec(m_codecs[0]); |
95 // m_audioSettings.setCodec(m_codecs[0]); |
80 } |
96 } |
81 |
97 |
82 QGstreamerAudioEncode::~QGstreamerAudioEncode() |
98 QGstreamerAudioEncode::~QGstreamerAudioEncode() |
83 { |
99 { |
84 } |
100 } |
183 0.7, //High |
199 0.7, //High |
184 1.0 //VeryHigh |
200 1.0 //VeryHigh |
185 }; |
201 }; |
186 g_object_set(G_OBJECT(encoderElement), "quality", qualityTable[qualityValue], NULL); |
202 g_object_set(G_OBJECT(encoderElement), "quality", qualityTable[qualityValue], NULL); |
187 } else if (codec == QLatin1String("audio/mpeg")) { |
203 } else if (codec == QLatin1String("audio/mpeg")) { |
188 int presets[] = { |
204 g_object_set(G_OBJECT(encoderElement), "target", 0, NULL); //constant quality mode |
189 1006, //VeryLow - Medium |
205 qreal quality[] = { |
190 1006, //Low - Medium |
206 1, //VeryLow |
191 1001, //Normal - Standard |
207 3, //Low |
192 1002, //High - Extreme |
208 5, //Normal |
193 1003 //VeryHigh - Insane |
209 7, //High |
194 }; |
210 9 //VeryHigh |
195 |
211 }; |
196 g_object_set(G_OBJECT(encoderElement), "preset", presets[qualityValue], NULL); |
212 g_object_set(G_OBJECT(encoderElement), "quality", quality[qualityValue], NULL); |
197 } else if (codec == QLatin1String("audio/speex")) { |
213 } else if (codec == QLatin1String("audio/speex")) { |
198 //0-10 range with default 8 |
214 //0-10 range with default 8 |
199 double qualityTable[] = { |
215 double qualityTable[] = { |
200 2, //VeryLow |
216 2, //VeryLow |
201 5, //Low |
217 5, //Low |
202 8, //Normal |
218 8, //Normal |
203 9, //High |
219 9, //High |
204 10 //VeryHigh |
220 10 //VeryHigh |
205 }; |
221 }; |
206 g_object_set(G_OBJECT(encoderElement), "quality", qualityTable[qualityValue], NULL); |
222 g_object_set(G_OBJECT(encoderElement), "quality", qualityTable[qualityValue], NULL); |
|
223 } else if (codec.startsWith("audio/AMR")) { |
|
224 int band[] = { |
|
225 0, //VeryLow |
|
226 2, //Low |
|
227 4, //Normal |
|
228 6, //High |
|
229 7 //VeryHigh |
|
230 }; |
|
231 |
|
232 g_object_set(G_OBJECT(encoderElement), "band-mode", band[qualityValue], NULL); |
207 } |
233 } |
208 } else { |
234 } else { |
209 int bitrate = m_audioSettings.bitRate(); |
235 int bitrate = m_audioSettings.bitRate(); |
210 if (bitrate > 0) { |
236 if (bitrate > 0) { |
|
237 if (codec == QLatin1String("audio/mpeg")) { |
|
238 g_object_set(G_OBJECT(encoderElement), "target", 1, NULL); //constant bitrate mode |
|
239 } |
211 g_object_set(G_OBJECT(encoderElement), "bitrate", bitrate, NULL); |
240 g_object_set(G_OBJECT(encoderElement), "bitrate", bitrate, NULL); |
212 } |
241 } |
213 } |
242 } |
214 |
243 |
215 QMap<QString, QVariant> options = m_options.value(codec); |
244 QMap<QString, QVariant> options = m_options.value(codec); |