|
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 "qgstreamervideoencode_maemo.h" |
|
43 #include "qgstreamercapturesession_maemo.h" |
|
44 #include "qgstreamermediacontainercontrol_maemo.h" |
|
45 |
|
46 #include <QtCore/qdebug.h> |
|
47 |
|
48 QGstreamerVideoEncode::QGstreamerVideoEncode(QGstreamerCaptureSession *session) |
|
49 :QVideoEncoderControl(session), m_session(session) |
|
50 { |
|
51 QList<QByteArray> codecCandidates; |
|
52 codecCandidates << "video/mpeg4"; //"video/h264" << "video/xvid" << "video/mpeg4" << "video/mpeg1" << "video/mpeg2" << "video/theora"; |
|
53 |
|
54 m_elementNames["video/mpeg4"] = "dspmp4venc"; |
|
55 |
|
56 m_codecOptions["video/mpeg4"] = QStringList() << "quantizer"; |
|
57 |
|
58 foreach( const QByteArray& codecName, codecCandidates ) { |
|
59 QByteArray elementName = m_elementNames[codecName]; |
|
60 GstElementFactory *factory = gst_element_factory_find(elementName.constData()); |
|
61 if (factory) { |
|
62 m_codecs.append(codecName); |
|
63 const gchar *descr = gst_element_factory_get_description(factory); |
|
64 m_codecDescriptions.insert(codecName, QString::fromUtf8(descr)); |
|
65 |
|
66 m_streamTypes.insert(codecName, |
|
67 QGstreamerMediaContainerControl::supportedStreamTypes(factory, GST_PAD_SRC)); |
|
68 |
|
69 gst_object_unref(GST_OBJECT(factory)); |
|
70 } |
|
71 } |
|
72 |
|
73 if (!m_codecs.isEmpty()) |
|
74 m_videoSettings.setCodec(m_codecs[0]); |
|
75 } |
|
76 |
|
77 QGstreamerVideoEncode::~QGstreamerVideoEncode() |
|
78 { |
|
79 } |
|
80 |
|
81 QList<QSize> QGstreamerVideoEncode::supportedResolutions(const QVideoEncoderSettings &, bool *continuous) const |
|
82 { |
|
83 if (continuous) |
|
84 *continuous = m_session->videoInput() != 0; |
|
85 |
|
86 return m_session->videoInput() ? m_session->videoInput()->supportedResolutions() : QList<QSize>(); |
|
87 } |
|
88 |
|
89 QList< qreal > QGstreamerVideoEncode::supportedFrameRates(const QVideoEncoderSettings &, bool *continuous) const |
|
90 { |
|
91 if (continuous) |
|
92 *continuous = false; |
|
93 |
|
94 return m_session->videoInput() ? m_session->videoInput()->supportedFrameRates() : QList<qreal>(); |
|
95 } |
|
96 |
|
97 QStringList QGstreamerVideoEncode::supportedVideoCodecs() const |
|
98 { |
|
99 return m_codecs; |
|
100 } |
|
101 |
|
102 QString QGstreamerVideoEncode::videoCodecDescription(const QString &codecName) const |
|
103 { |
|
104 return m_codecDescriptions.value(codecName); |
|
105 } |
|
106 |
|
107 QStringList QGstreamerVideoEncode::supportedEncodingOptions(const QString &codec) const |
|
108 { |
|
109 return m_codecOptions.value(codec); |
|
110 } |
|
111 |
|
112 QVariant QGstreamerVideoEncode::encodingOption(const QString &codec, const QString &name) const |
|
113 { |
|
114 return m_options[codec].value(name); |
|
115 } |
|
116 |
|
117 void QGstreamerVideoEncode::setEncodingOption( |
|
118 const QString &codec, const QString &name, const QVariant &value) |
|
119 { |
|
120 m_options[codec][name] = value; |
|
121 } |
|
122 |
|
123 QVideoEncoderSettings QGstreamerVideoEncode::videoSettings() const |
|
124 { |
|
125 return m_videoSettings; |
|
126 } |
|
127 |
|
128 void QGstreamerVideoEncode::setVideoSettings(const QVideoEncoderSettings &settings) |
|
129 { |
|
130 m_videoSettings = settings; |
|
131 } |
|
132 |
|
133 GstElement *QGstreamerVideoEncode::createEncoder() |
|
134 { |
|
135 QString codec = m_videoSettings.codec(); |
|
136 |
|
137 GstElement *encoderElement = gst_element_factory_make( m_elementNames.value(codec).constData(), "video-encoder"); |
|
138 |
|
139 return encoderElement; |
|
140 } |
|
141 |
|
142 QPair<int,int> QGstreamerVideoEncode::rateAsRational() const |
|
143 { |
|
144 qreal frameRate = m_videoSettings.frameRate(); |
|
145 |
|
146 if (frameRate > 0.001) { |
|
147 //convert to rational number |
|
148 QList<int> denumCandidates; |
|
149 denumCandidates << 1 << 2 << 3 << 5 << 10 << 1001 << 1000; |
|
150 |
|
151 qreal error = 1.0; |
|
152 int num = 1; |
|
153 int denum = 1; |
|
154 |
|
155 foreach (int curDenum, denumCandidates) { |
|
156 int curNum = qRound(frameRate*curDenum); |
|
157 qreal curError = qAbs(qreal(curNum)/curDenum - frameRate); |
|
158 |
|
159 if (curError < error) { |
|
160 error = curError; |
|
161 num = curNum; |
|
162 denum = curDenum; |
|
163 } |
|
164 |
|
165 if (curError < 1e-8) |
|
166 break; |
|
167 } |
|
168 |
|
169 return QPair<int,int>(num,denum); |
|
170 } |
|
171 |
|
172 return QPair<int,int>(); |
|
173 } |
|
174 |
|
175 |
|
176 QSet<QString> QGstreamerVideoEncode::supportedStreamTypes(const QString &codecName) const |
|
177 { |
|
178 return m_streamTypes.value(codecName); |
|
179 } |