sbGStreamerMediacoreUtils.h
Go to the documentation of this file.
1 /*
2 //
3 // BEGIN SONGBIRD GPL
4 //
5 // This file is part of the Songbird web player.
6 //
7 // Copyright(c) 2005-2008 POTI, Inc.
8 // http://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 
27 #ifndef _SB_GSTREAMERMEDIACOREUTILS_H_
28 #define _SB_GSTREAMERMEDIACOREUTILS_H_
29 
30 #include <nsCOMPtr.h>
31 #include <nsCOMArray.h>
32 #include <nsStringGlue.h>
33 #include <nsIDOMEventListener.h>
34 #include <nsIDOMWindow.h>
35 #include <nsITimer.h>
36 #include <nsComponentManagerUtils.h>
37 #include <nsIStringBundle.h>
38 #include <nsIVariant.h>
39 #include <nsIPropertyBag.h>
40 #include <nsIProperty.h>
41 #include <nsIWritablePropertyBag2.h>
42 
43 #include <sbIPropertyArray.h>
44 #include <sbMediacoreError.h>
45 #include <sbMemoryUtils.h>
46 
47 #include <gst/gst.h>
48 
49 SB_AUTO_CLASS(sbGstCaps, GstCaps*, !!mValue, gst_caps_unref(mValue), mValue = NULL);
50 
51 /* Custom GStreamer tag names. Must match those used in the various gstreamer
52  muxers/taggers we have.
53  */
54 #define SB_GST_TAG_GRACENOTE_TAGID "gracenote-tagid"
55 #define SB_GST_TAG_GRACENOTE_EXTENDED_DATA "gracenote-extdata"
56 
57 /*
58  Simple enum of possible primary pipeline operations. This is used
59  by sbGStreamerPipeline and derived classes as well as
60  GetMediacoreErrorFromGstError. It helps determine which error message
61  should be constructed based on the primary operation being performed.
62 
63  This type is defined in the GStreamer namespace to avoid clashing with
64  other types.
65  */
66 namespace GStreamer {
67 
68 typedef enum {
69  OP_UNKNOWN = 0, /* unknown: default behavior */
70  OP_INSPECTING, /* inspecting (eg. scanning for metadata) */
71  OP_PLAYING, /* playing: playing back a file for the user */
72  OP_STREAMING, /* streaming: acting as server during streaming */
73  OP_TRANSCODING /* transcoding: transcoding a media file to another format */
74 } pipelineOp_t;
75 
76 } /*namespace GStreamer*/
77 
78 
79 /* Apply all the properties from 'props' to element.
80  If any property cannot be set (the type is incompatible, or the element
81  does not have such a property), this will return an error.
82 
83  Type compatibility: numerical types MUST match exactly (e.g. if the
84  GObject property contains an unsigned 32 bit int, then the property in
85  the property bag must also be an unsigned 32 bit int.
86 
87  Strings MAY be either nsString or nsCString.
88 
89  Enum values (for the GObject properties) MUST be 32 bit unsigned integers
90  in the nsIVariant; they'll be converted as appropriate.
91 
92  Current limitations: only 32 bit or 64 bit (signed or unsigned) integers,
93  floats, doubles, booleans, strings (AString and ACString), and enums
94  are supported.
95  */
96 nsresult ApplyPropertyBagToElement(GstElement *element, nsIPropertyBag *props);
97 
98 GstTagList *ConvertPropertyArrayToTagList(sbIPropertyArray *properties);
99 
100 nsresult ConvertTagListToPropertyArray(GstTagList *taglist,
101  sbIPropertyArray **aPropertyArray);
102 
104 public:
106  virtual void HandleMessage(GstMessage *message) = 0;
107  virtual PRBool HandleSynchronousMessage(GstMessage *message) = 0;
108 };
109 GstBusSyncReply SyncToAsyncDispatcher(GstBus* bus, GstMessage* message,
110  gpointer data);
111 
112 /* Get a mediacore error from the gstreamer error. The error string may include
113  a reference to a filename or URI; if so the string aResource will be used
114 
115  \param aResource the URI string points to the file that has error.
116  Will be unescaped in the processing.
117  \param aPipelineOp Optional pipeline primary operation to pick the error
118  message that is most representative. Pass
119  GStreamer::OP_UNKNOWN for the default behavior.
120  */
121 nsresult GetMediacoreErrorFromGstError(GError *gerror, nsString aResource,
122  GStreamer::pipelineOp_t aPipelineOp,
123  sbIMediacoreError **_retval);
124 
133 const char *
134 FindMatchingElementName(const char *srcCapsString, const char *typeName);
135 
139 const char *
140 FindMatchingElementName(GstCaps *srcCaps, const char *typeName);
141 
142 /* Register any the custom tags we need to use */
143 void
145 
146 /* Get the mime type string to use for a given GStreamer caps type */
147 nsresult
148 GetMimeTypeForCaps (GstCaps *aCaps, nsACString &aMimeType);
149 
155 };
156 
157 /* Get a GstCaps object (possibly incomplete) for a given mime type string */
158 GstCaps *
159 GetCapsForMimeType (const nsACString &aMimeType, enum sbGstCapsMapType);
160 
161 /* Copy fields from aStructure to aPropertyBag. If aFieldList is supplied,
162  it shall have aFieldCount field names and any fields so named shall be
163  copied to a property of the same name. Missing fields will be skipped
164  without error. If aFieldList is not present, all fields in aStructure
165  shall be copied. */
166 nsresult
167 SetPropertiesFromGstStructure(nsIWritablePropertyBag2 * aPropertyBag,
168  const GstStructure * aStructure,
169  const gchar * const aFieldList[] = NULL,
170  PRUint32 aFieldCount = 0);
171 
172 /* Copy aValue to aPropertyBag using aFieldName. */
173 nsresult
174 SetPropertyFromGValue(nsIWritablePropertyBag2 * aPropertyBag,
175  const nsAString & aProperty,
176  const GValue * aValue);
177 
178 /* Return the real pad, skipping ghosts. The return object is add ref'd */
179 GstPad *
180 GetRealPad (GstPad *pad);
181 
182 #endif // _SB_GSTREAMERMEDIACOREUTILS_H_
183 
Songbird Mediacore Error Definition.
onPageChanged aValue
Definition: FeedWriter.js:1395
GstTagList * ConvertPropertyArrayToTagList(sbIPropertyArray *properties)
nsresult SetPropertiesFromGstStructure(nsIWritablePropertyBag2 *aPropertyBag, const GstStructure *aStructure, const gchar *const aFieldList[]=NULL, PRUint32 aFieldCount=0)
GstCaps * GetCapsForMimeType(const nsACString &aMimeType, enum sbGstCapsMapType)
nsresult SetPropertyFromGValue(nsIWritablePropertyBag2 *aPropertyBag, const nsAString &aProperty, const GValue *aValue)
GstBusSyncReply SyncToAsyncDispatcher(GstBus *bus, GstMessage *message, gpointer data)
nsresult GetMediacoreErrorFromGstError(GError *gerror, nsString aResource, GStreamer::pipelineOp_t aPipelineOp, sbIMediacoreError **_retval)
const char * FindMatchingElementName(const char *srcCapsString, const char *typeName)
GstPad * GetRealPad(GstPad *pad)
SB_AUTO_CLASS(sbGstCaps, GstCaps *,!!mValue, gst_caps_unref(mValue), mValue=NULL)
GstMessage * message
nsresult ApplyPropertyBagToElement(GstElement *element, nsIPropertyBag *props)
virtual void HandleMessage(GstMessage *message)=0
void RegisterCustomTags()
observe data
Definition: FeedWriter.js:1329
An interface to carry around arrays of nsIProperty instances. Users of this interface should only QI ...
nsresult ConvertTagListToPropertyArray(GstTagList *taglist, sbIPropertyArray **aPropertyArray)
virtual PRBool HandleSynchronousMessage(GstMessage *message)=0
nsresult GetMimeTypeForCaps(GstCaps *aCaps, nsACString &aMimeType)