sbTranscodeProfile.cpp
Go to the documentation of this file.
1 /* vim: set sw=2 :miv */
2 /*
3 //
4 // BEGIN SONGBIRD GPL
5 //
6 // This file is part of the Songbird web player.
7 //
8 // Copyright(c) 2005-2009 POTI, Inc.
9 // http://songbirdnest.com
10 //
11 // This file may be licensed under the terms of of the
12 // GNU General Public License Version 2 (the "GPL").
13 //
14 // Software distributed under the License is distributed
15 // on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either
16 // express or implied. See the GPL for the specific language
17 // governing rights and limitations.
18 //
19 // You should have received a copy of the GPL along with this
20 // program. If not, go to http://www.gnu.org/licenses/gpl.html
21 // or write to the Free Software Foundation, Inc.,
22 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
23 //
24 // END SONGBIRD GPL
25 //
26 */
27 
28 #include "sbTranscodeProfile.h"
29 
30 /* Implementation file */
34 
36  mPriority(0),
37  mType(sbITranscodeProfile::TRANSCODE_TYPE_UNKNOWN)
38 {
39  /* member initializers and constructor code */
40 }
41 
42 sbTranscodeProfile::~sbTranscodeProfile()
43 {
44  /* destructor code */
45 }
46 
47 NS_IMETHODIMP
48 sbTranscodeProfile::GetId(nsAString & aId)
49 {
50  aId = mId;
51  return NS_OK;
52 }
53 
54 NS_IMETHODIMP
55 sbTranscodeProfile::SetId(nsAString const & aId)
56 {
57  mId = aId;
58  return NS_OK;
59 }
60 
61 NS_IMETHODIMP
62 sbTranscodeProfile::GetPriority(PRUint32 *aPriority)
63 {
64  NS_ENSURE_ARG_POINTER(aPriority);
65  *aPriority = mPriority;
66  return NS_OK;
67 }
68 
69 NS_IMETHODIMP
70 sbTranscodeProfile::SetPriority(PRUint32 aPriority)
71 {
72  mPriority = aPriority;
73  // set a default point for sbITranscodeEncoderProfile::getPriority
74  mPriorityMap[0.5] = aPriority;
75  return NS_OK;
76 }
77 
78 NS_IMETHODIMP
79 sbTranscodeProfile::GetDescription(nsAString & aDescription)
80 {
81  aDescription = mDescription;
82  return NS_OK;
83 }
84 
85 NS_IMETHODIMP
86 sbTranscodeProfile::SetDescription(nsAString const & aDescription)
87 {
88  mDescription = aDescription;
89  return NS_OK;
90 }
91 
92 NS_IMETHODIMP
93 sbTranscodeProfile::GetType(PRUint32 *aType)
94 {
95  NS_ENSURE_ARG_POINTER(aType);
96 
97  *aType = mType;
98  return NS_OK;
99 }
100 
101 NS_IMETHODIMP
102 sbTranscodeProfile::SetType(PRUint32 aType)
103 {
104  mType = aType;
105  return NS_OK;
106 }
107 
108 NS_IMETHODIMP
109 sbTranscodeProfile::GetContainerFormat(nsAString & aContainerFormat)
110 {
111  aContainerFormat = mContainerFormat;
112  return NS_OK;
113 }
114 
115 NS_IMETHODIMP
116 sbTranscodeProfile::SetContainerFormat(nsAString const & aContainerFormat)
117 {
118  mContainerFormat = aContainerFormat;
119  return NS_OK;
120 }
121 
122 NS_IMETHODIMP
123 sbTranscodeProfile::GetFileExtension(nsACString & aFileExtension)
124 {
125  aFileExtension = mFileExtension;
126  return NS_OK;
127 }
128 
129 NS_IMETHODIMP
130 sbTranscodeProfile::SetFileExtension(nsACString const & aFileExtension)
131 {
132  mFileExtension = aFileExtension;
133  return NS_OK;
134 }
135 
136 NS_IMETHODIMP
137 sbTranscodeProfile::GetAudioCodec(nsAString & aAudioCodec)
138 {
139  aAudioCodec = mAudioCodec;
140  return NS_OK;
141 }
142 
143 NS_IMETHODIMP
144 sbTranscodeProfile::SetAudioCodec(nsAString const & aAudioCodec)
145 {
146  mAudioCodec = aAudioCodec;
147  return NS_OK;
148 }
149 
150 NS_IMETHODIMP
151 sbTranscodeProfile::GetVideoCodec(nsAString & aVideoCodec)
152 {
153  aVideoCodec = mVideoCodec;
154  return NS_OK;
155 }
156 
157 NS_IMETHODIMP
158 sbTranscodeProfile::SetVideoCodec(nsAString const & aVideoCodec)
159 {
160  mVideoCodec = aVideoCodec;
161  return NS_OK;
162 }
163 
164 NS_IMETHODIMP
165 sbTranscodeProfile::GetAudioProperties(nsIArray * *aAudioProperties)
166 {
167  NS_ENSURE_ARG_POINTER(aAudioProperties);
168 
169  NS_IF_ADDREF(*aAudioProperties = mAudioProperties);
170  return NS_OK;
171 }
172 
173 NS_IMETHODIMP
174 sbTranscodeProfile::SetAudioProperties(nsIArray * aAudioProperties)
175 {
176  mAudioProperties = aAudioProperties;
177  return NS_OK;
178 }
179 
180 NS_IMETHODIMP
181 sbTranscodeProfile::GetVideoProperties(nsIArray * *aVideoProperties)
182 {
183  NS_ENSURE_ARG_POINTER(aVideoProperties);
184 
185  NS_IF_ADDREF(*aVideoProperties = mVideoProperties);
186  return NS_OK;
187 }
188 
189 NS_IMETHODIMP
190 sbTranscodeProfile::SetVideoProperties(nsIArray * aVideoProperties)
191 {
192  mVideoProperties = aVideoProperties;
193  return NS_OK;
194 }
195 
196 NS_IMETHODIMP
197 sbTranscodeProfile::GetContainerProperties(nsIArray * *aContainerProperties)
198 {
199  NS_ENSURE_ARG_POINTER(aContainerProperties);
200 
201  NS_IF_ADDREF(*aContainerProperties = mContainerProperties);
202  return NS_OK;
203 }
204 
205 NS_IMETHODIMP
206 sbTranscodeProfile::SetContainerProperties(nsIArray * aContainerProperties)
207 {
208  mContainerProperties = aContainerProperties;
209  return NS_OK;
210 }
211 
212 NS_IMETHODIMP
213 sbTranscodeProfile::GetAudioAttributes(nsIArray * *aAudioAttributes)
214 {
215  NS_ENSURE_ARG_POINTER(aAudioAttributes);
216 
217  NS_IF_ADDREF(*aAudioAttributes = mAudioAttributes);
218  return NS_OK;
219 }
220 
221 NS_IMETHODIMP
222 sbTranscodeProfile::SetAudioAttributes(nsIArray * aAudioAttributes)
223 {
224  mAudioAttributes = aAudioAttributes;
225  return NS_OK;
226 }
227 
228 NS_IMETHODIMP
229 sbTranscodeProfile::GetVideoAttributes(nsIArray * *aVideoAttributes)
230 {
231  NS_ENSURE_ARG_POINTER(aVideoAttributes);
232 
233  NS_IF_ADDREF(*aVideoAttributes = mVideoAttributes);
234  return NS_OK;
235 }
236 
237 NS_IMETHODIMP
238 sbTranscodeProfile::SetVideoAttributes(nsIArray * aVideoAttributes)
239 {
240  mVideoAttributes = aVideoAttributes;
241  return NS_OK;
242 }
243 
244 NS_IMETHODIMP
245 sbTranscodeProfile::GetContainerAttributes(nsIArray * *aContainerAttributes)
246 {
247  NS_ENSURE_ARG_POINTER(aContainerAttributes);
248 
249  NS_IF_ADDREF(*aContainerAttributes = mContainerAttributes);
250  return NS_OK;
251 }
252 
253 NS_IMETHODIMP
254 sbTranscodeProfile::SetContainerAttributes(nsIArray * aContainerAttributes)
255 {
256  mContainerAttributes = aContainerAttributes;
257  return NS_OK;
258 }
259 
260 /***** nsITranscodeEncoderProfile implementation *****/
261 template<typename T>
262 T getInterpolatedQuality(std::map<double, T> &aMap, double aQuality)
263 {
264  typename std::map<double, T>::const_iterator end = aMap.end(),
265  lower,
266  upper = aMap.upper_bound(aQuality);
267 
268  if (aMap.empty()) {
269  // completely missing :(
270  return 0;
271  }
272 
273  if (upper == aMap.begin()) {
274  // the first point is larger than desired; just return that
275  return upper->second;
276  }
277 
278  lower = upper;
279  --lower;
280  if (upper == end) {
281  // nothing is greater than desired quality, select the highest we have
282  return lower->second;
283  }
284 
285  double scale = (aQuality - lower->first) / (upper->first - lower->first);
286  T difference = (T)(scale * (upper->second - lower->second));
287  return lower->second + difference;
288 }
289 
290 /* PRInt32 getEncoderProfilePriority (in double aQuality); */
291 NS_IMETHODIMP
292 sbTranscodeProfile::GetEncoderProfilePriority(double aQuality,
293  PRUint32 *_retval)
294 {
295  NS_ENSURE_ARG_POINTER(_retval);
296  *_retval = getInterpolatedQuality(mPriorityMap, aQuality);
297  return NS_OK;
298 }
299 
300 /* double getAudioBitrate (in double aQuality); */
301 NS_IMETHODIMP
302 sbTranscodeProfile::GetAudioBitrate(double aQuality, double *_retval)
303 {
304  NS_ENSURE_ARG_POINTER(_retval);
305  *_retval = getInterpolatedQuality(mAudioBitrateMap, aQuality);
306  return NS_OK;
307 }
308 
309 /* double getVideoBitsPerPixel (in double aQuality); */
310 NS_IMETHODIMP
311 sbTranscodeProfile::GetVideoBitsPerPixel(double aQuality, double *_retval)
312 {
313  NS_ENSURE_ARG_POINTER(_retval);
314  *_retval = getInterpolatedQuality(mVideoBPPMap, aQuality);
315  return NS_OK;
316 }
317 
318 /***** nsITranscodeEncoderProfile helpers *****/
319 nsresult
320 sbTranscodeProfile::AddPriority(double aQuality, PRUint32 aPriority)
321 {
322  NS_ENSURE_ARG_RANGE(aQuality, 0, 1);
323  mPriorityMap[aQuality] = aPriority;
324  return NS_OK;
325 }
326 
327 nsresult
328 sbTranscodeProfile::AddAudioBitrate(double aQuality, double aBitrate)
329 {
330  NS_ENSURE_ARG_RANGE(aQuality, 0, 1);
331  mAudioBitrateMap[aQuality] = aBitrate;
332  return NS_OK;
333 }
334 
335 nsresult
336 sbTranscodeProfile::AddVideoBPP(double aQuality, double aBPP)
337 {
338  NS_ENSURE_ARG_RANGE(aQuality, 0, 1);
339  mVideoBPPMap[aQuality] = aBPP;
340  return NS_OK;
341 }
return NS_OK
NS_IMPL_THREADSAFE_ISUPPORTS2(sbTranscodeProfile, sbITranscodeProfile, sbITranscodeEncoderProfile) sbTranscodeProfile
An object defining a transcoding profile.
nsresult AddVideoBPP(double aQuality, double aBPP)
nsresult AddAudioBitrate(double aQuality, double aBitrate)
T getInterpolatedQuality(std::map< double, T > &aMap, double aQuality)
nsresult AddPriority(double aQuality, PRUint32 aPriority)