sbGStreamerTranscodeDeviceConfigurator.h
Go to the documentation of this file.
1 /* vim: set sw=2 */
2 /*
3  *=BEGIN SONGBIRD GPL
4  *
5  * This file is part of the Songbird web player.
6  *
7  * Copyright(c) 2005-2009 POTI, Inc.
8  * http://www.songbirdnest.com
9  *
10  * This file may be licensed under the terms of of the
11  * GNU General Public License Version 2 (the ``GPL'').
12  *
13  * Software distributed under the License is distributed
14  * on an ``AS IS'' basis, WITHOUT WARRANTY OF ANY KIND, either
15  * express or implied. See the GPL for the specific language
16  * governing rights and limitations.
17  *
18  * You should have received a copy of the GPL along with this
19  * program. If not, go to http://www.gnu.org/licenses/gpl.html
20  * or write to the Free Software Foundation, Inc.,
21  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22  *
23  *=END SONGBIRD GPL
24  */
25 
26 #ifndef _SB_GSTREAMER_TRANSCODE_DEVICE_CONFIGURATOR_H_
27 #define _SB_GSTREAMER_TRANSCODE_DEVICE_CONFIGURATOR_H_
28 
29 // {8D5D04F8-2060-4e82-A25B-C7D67A6B5292}
30 #define SB_GSTREAMER_TRANSCODE_DEVICE_CONFIGURATOR_CID \
31  { 0x8d5d04f8, 0x2060, 0x4e82, \
32  { 0xa2, 0x5b, 0xc7, 0xd6, 0x7a, 0x6b, 0x52, 0x92 } }
33 
34 #define SB_GSTREAMER_TRANSCODE_DEVICE_CONFIGURATOR_CONTRACTID \
35  "@songbirdnest.com/Songbird/Mediacore/Transcode/Configurator/Device/GStreamer;1"
36 #define SB_GSTREAMER_TRANSCODE_DEVICE_CONFIGURATOR_CLASSNAME \
37  "GStreamerTranscodeDeviceConfigurator"
38 
40 
41 #include <sbITranscodingConfigurator.h>
42 #include <sbPIGstTranscodingConfigurator.h>
43 
44 #include <nsCOMPtr.h>
45 #include <nsDataHashtable.h>
46 
47 #include <sbFraction.h>
48 
49 class nsIArray;
50 class nsIWritablePropertyBag;
51 
52 class sbIDevice;
54 class sbIVideoFormatType;
55 
60 {
61 public:
63  NS_DECL_SBIDEVICETRANSCODINGCONFIGURATOR
64  NS_DECL_SBPIGSTTRANSCODINGCONFIGURATOR
65 
66  // forward most of sbITranscodingConfigurator to the base class
67  #define FORWARD_TO_BASE(METHOD, PROTO, ARGS) \
68  NS_IMETHOD METHOD PROTO { return sbTranscodingConfigurator::METHOD(ARGS); }
69 
70  FORWARD_TO_BASE(GetInputUri, (nsIURI ** aUri), aUri)
71  FORWARD_TO_BASE(SetInputUri, (nsIURI * aUri), aUri)
72  FORWARD_TO_BASE(GetInputFormat, (sbIMediaFormat * *aInputFormat), aInputFormat)
73  FORWARD_TO_BASE(SetInputFormat, (sbIMediaFormat * aInputFormat), aInputFormat)
74  FORWARD_TO_BASE(GetLastError, (sbITranscodeError * *aLastError), aLastError)
75  FORWARD_TO_BASE(GetMuxer, (nsAString & aMuxer), aMuxer)
76  FORWARD_TO_BASE(GetUseMuxer, (PRBool *aUseMuxer), aUseMuxer)
77  FORWARD_TO_BASE(GetFileExtension, (nsACString & aFileExtension), aFileExtension)
78  FORWARD_TO_BASE(GetVideoEncoder, (nsAString & aVideoEncoder), aVideoEncoder)
79  FORWARD_TO_BASE(GetUseVideoEncoder, (PRBool *aUseVideoEncoder), aUseVideoEncoder)
80  FORWARD_TO_BASE(GetVideoFormat, (sbIMediaFormatVideo * *aVideoFormat), aVideoFormat)
81  FORWARD_TO_BASE(GetAudioEncoder, (nsAString & aAudioEncoder), aAudioEncoder)
82  FORWARD_TO_BASE(GetUseAudioEncoder, (PRBool *aUseAudioEncoder), aUseAudioEncoder)
83  FORWARD_TO_BASE(GetAudioFormat, (sbIMediaFormatAudio * *aAudioFormat), aAudioFormat)
84  FORWARD_TO_BASE(GetVideoEncoderProperties, (nsIPropertyBag * *aVideoEncoderProperties), aVideoEncoderProperties)
85  FORWARD_TO_BASE(GetAudioEncoderProperties, (nsIPropertyBag * *aAudioEncoderProperties), aAudioEncoderProperties)
86 
87  #undef FORWARD_TO_BASE
88 
89  /*
90  * re-implement determineOutputType() and configurate() to have the
91  * configuration logic specific to gstreamer-based configuration for devices
92  */
93  NS_IMETHOD DetermineOutputType();
94  NS_IMETHOD Configurate();
95  /* Implement GetAvailableProfiles to return only appropriate profiles. */
96  NS_IMETHOD GetAvailableProfiles(nsIArray **aProfiles);
97 
99 
100 protected:
102 
106  struct Dimensions {
107  PRInt32 width;
108  PRInt32 height;
109  Dimensions() : width(PR_INT32_MIN), height(PR_INT32_MIN) {}
110  Dimensions(PRInt32 w, PRInt32 h) : width(w), height(h) {}
111  };
112 
123 
129  nsresult SelectQuality();
130 
141  nsresult SelectProfile();
142 
149  nsresult SetAudioProperties();
150 
158  nsresult DetermineOutputDimensions();
159 
166  static Dimensions GetMaximumFit(const Dimensions& aInput,
167  const Dimensions& aMaximum);
168 
178  nsresult DetermineOutputVideoBitrate();
179 
186  nsresult SetVideoProperties();
187 
194  nsresult CopyPropertiesIntoBag(nsIArray * aSrcProps,
195  nsIWritablePropertyBag * aDstBag,
196  PRBool aIsVideo);
197 
198 protected:
203  nsCString muxer;
204  nsCString audioEncoder;
205  nsCString videoEncoder;
206  };
207  nsDataHashtable<nsISupportsHashKey, EncoderProfileData> mElementNames;
208 
212  double mQuality;
216  nsCOMPtr<sbIDevice> mDevice;
221  nsCOMPtr<nsIArray> mAvailableProfiles;
225  nsCOMPtr<sbITranscodeEncoderProfile> mSelectedProfile;
230  nsCOMPtr<sbIVideoFormatType> mSelectedFormat;
231 
235  PRInt32 mVideoBitrate;
236 
241 
246 
251 };
252 
253 #endif // _SB_GSTREAMER_TRANSCODE_DEVICE_CONFIGURATOR_H_
NS_IMETHOD GetVideoFormat(sbIMediaFormatVideo **aVideoFormat)
NS_IMETHOD SetInputFormat(sbIMediaFormat *aInputFormat)
nsDataHashtable< nsISupportsHashKey, EncoderProfileData > mElementNames
NS_IMETHOD GetVideoEncoderProperties(nsIPropertyBag **aVideoEncoderProperties)
NS_IMETHOD GetInputFormat(sbIMediaFormat **aInputFormat)
NS_IMETHOD GetLastError(sbITranscodeError **aLastError)
#define FORWARD_TO_BASE(METHOD, PROTO, ARGS)
nsCOMPtr< sbITranscodeEncoderProfile > mSelectedProfile
nsresult CopyPropertiesIntoBag(nsIArray *aSrcProps, nsIWritablePropertyBag *aDstBag, PRBool aIsVideo)
NS_IMETHOD GetFileExtension(nsACString &aFileExtension)
NS_IMETHOD GetAudioFormat(sbIMediaFormatAudio **aAudioFormat)
static Dimensions GetMaximumFit(const Dimensions &aInput, const Dimensions &aMaximum)
NS_IMETHOD GetAudioEncoderProperties(nsIPropertyBag **aAudioEncoderProperties)
nsresult EnsureProfileAvailable(sbITranscodeEncoderProfile *aProfile)