17 #include "sbIGStreamerService.h"
20 #include "nsThreadUtils.h"
29 sbGStreamerMediaContainer::GetMimeType(nsACString & aMimeType)
35 rv = AcquireMimeType_Priv();
36 NS_ENSURE_SUCCESS(rv, rv);
39 NS_ENSURE_TRUE(!mMimeType.IsEmpty(), NS_ERROR_NOT_AVAILABLE);
40 aMimeType.Assign(mMimeType);
48 sbGStreamerMediaContainer::GetPath(nsACString &
aPath)
57 sbGStreamerMediaContainer::SetPath(
const nsACString & aPath)
60 if (mPath.Equals(aPath)) {
69 gst_caps_unref(mCaps);
86 gst_caps_unref(mCaps);
92 gst_object_unref (mPipeline);
101 g_main_loop_unref (mLoop);
129 nsCOMPtr<sbIGStreamerService> gstreamer;
130 if (!NS_IsMainThread()) {
136 NS_ENSURE_SUCCESS(rv, rv);
140 mLoop = g_main_loop_new (NULL, FALSE);
141 NS_ENSURE_TRUE(mLoop, NS_ERROR_FAILURE);
144 mPipeline = GST_PIPELINE (gst_pipeline_new (
"pipe"));
145 NS_ENSURE_TRUE(mPipeline, NS_ERROR_FAILURE);
148 mFilesrc = gst_element_factory_make (
"filesrc",
"source");
149 NS_ENSURE_TRUE(mFilesrc, NS_ERROR_FAILURE);
151 mTypefind = gst_element_factory_make (
"typefind",
"decoder");
152 NS_ENSURE_TRUE(mTypefind, NS_ERROR_FAILURE);
154 mSink = gst_element_factory_make (
"fakesink",
"sink");
155 NS_ENSURE_TRUE(mSink, NS_ERROR_FAILURE);
157 g_signal_connect (mTypefind,
"have-type", G_CALLBACK(OnHaveType_Priv),
this);
166 gst_element_link_many (
178 sbGStreamerMediaContainer::AcquireMimeType_Priv()
180 NS_ENSURE_TRUE(!mPath.IsEmpty(), NS_ERROR_NOT_INITIALIZED);
188 NS_ENSURE_STATE(mPipeline);
189 GstBus * bus = gst_pipeline_get_bus (GST_PIPELINE (mPipeline));
190 gst_bus_add_watch_full (
198 NS_ENSURE_STATE(mFilesrc);
199 g_object_set (G_OBJECT (mFilesrc),
"location", mPath.get(), NULL);
202 NS_ENSURE_STATE(mLoop);
203 gst_element_set_state (GST_ELEMENT (mPipeline), GST_STATE_PAUSED);
204 g_main_loop_run (mLoop);
209 NS_ENSURE_SUCCESS(rv,rv);
213 gst_bus_add_watch_full (
219 gst_object_unref (bus);
222 GstStateChangeReturn mode =
223 gst_element_set_state (GST_ELEMENT (mPipeline), GST_STATE_NULL);
224 if (mode == GST_STATE_CHANGE_ASYNC) {
225 g_main_loop_run (mLoop);
229 NS_ENSURE_TRUE(!mMimeType.IsEmpty(), NS_ERROR_NOT_AVAILABLE);
237 sbGStreamerMediaContainer::OnHaveType_Priv (
238 GstElement * typefind,
243 NS_ENSURE_TRUE(user_data,);
248 self->mCaps = gst_caps_ref(caps);
254 sbGStreamerMediaContainer::OnBusMessage_Priv (
259 NS_ENSURE_TRUE(data, FALSE);
263 switch (GST_MESSAGE_TYPE (message))
265 case GST_MESSAGE_STATE_CHANGED:
270 gst_message_parse_state_changed (message, &from, &to, &goal);
272 GstObject * who = GST_MESSAGE_SRC (message);
273 if (who == GST_OBJECT (
self->mPipeline))
275 gboolean
done = (goal == GST_STATE_VOID_PENDING || to == GST_STATE_NULL);
281 case GST_MESSAGE_ERROR:
286 gst_message_parse_error(message, &err, &debug);
295 case GST_MESSAGE_EOS:
312 sbGStreamerMediaContainer::OnMainLoopDone_Priv (
315 NS_ENSURE_TRUE(user_data, FALSE);
318 g_main_loop_quit (
self->mLoop);
325 sbGStreamerMediaContainer::OnPrerollDone_Priv (
328 g_idle_add (OnMainLoopDone_Priv, user_data);
338 return ssbGStreamerMediaContainer;
#define SBGSTREAMERSERVICE_CONTRACTID
const sbCreateProxiedComponent do_ProxiedGetService(const nsCID &aCID, nsresult *error=0)