27 #include <sbIGStreamerService.h>
30 #include <nsIInterfaceRequestorUtils.h>
31 #include <nsIRunnable.h>
32 #include <nsServiceManagerUtils.h>
33 #include <nsThreadUtils.h>
36 #include <sbIMediacoreError.h>
45 static PRLogModuleInfo* gGStreamerPipeline = PR_NewLogModule(
"sbGStreamerPipeline");
46 #define LOG(args) PR_LOG(gGStreamerPipeline, PR_LOG_WARNING, args)
47 #define TRACE(args) PR_LOG(gGStreamerPipeline, PR_LOG_DEBUG, args)
61 sbIMediacoreEventTarget)
66 sbGStreamerPipeline::sbGStreamerPipeline() :
71 TRACE((
"sbGStreamerPipeline[0x%.8x] - Constructed",
this));
78 TRACE((
"sbGStreamerPipeline[0x%.8x] - Destructed",
this));
83 nsAutoMonitor::DestroyMonitor(
mMonitor);
90 TRACE((
"sbGStreamerPipeline[0x%.8x] - Initialise",
this));
96 if (!NS_IsMainThread()) {
97 nsCOMPtr<sbIGStreamerService>
service =
101 nsCOMPtr<sbIGStreamerService>
service =
103 NS_ENSURE_SUCCESS(rv, rv);
106 mMonitor = nsAutoMonitor::NewMonitor(
"sbGStreamerPipeline::mMonitor");
107 NS_ENSURE_TRUE(
mMonitor, NS_ERROR_OUT_OF_MEMORY);
115 return NS_ERROR_NOT_IMPLEMENTED;
121 TRACE((
"sbGStreamerPipeline[0x%.8x] - SetupPipeline",
this));
126 NS_ENSURE_SUCCESS (rv, rv);
131 GstBus *bus = gst_element_get_bus(
mPipeline);
135 g_object_set(
mPipeline,
"auto-flush-bus", FALSE, NULL);
140 static_cast<sbGStreamerMessageHandler*>(
this));
142 gst_object_unref(bus);
153 TRACE((
"sbGStreamerPipeline[0x%.8x] - DestroyPipeline",
this));
156 GstElement *pipeline = NULL;
160 pipeline = (GstElement *)gst_object_ref (
mPipeline);
164 gst_element_set_state(pipeline, GST_STATE_NULL);
165 gst_object_unref (pipeline);
166 TRACE((
"sbGStreamerPipeline[0x%.8x] - DestroyPipeline NULL state.",
this));
174 NS_ENSURE_SUCCESS (rv, rv);
177 TRACE((
"sbGStreamerPipeline[0x%.8x] - DestroyPipeline unref",
this));
194 sbGStreamerPipeline::PlayPipeline()
196 TRACE((
"sbGStreamerPipeline[0x%.8x] - PlayPipeline",
this));
197 GstElement *pipeline = NULL;
203 NS_ENSURE_SUCCESS (rv, rv);
205 pipeline = (GstElement *)gst_object_ref (
mPipeline);
208 gst_element_set_state(pipeline, GST_STATE_PLAYING);
209 gst_object_unref (pipeline);
215 sbGStreamerPipeline::PausePipeline()
217 TRACE((
"sbGStreamerPipeline[0x%.8x] - PausePipeline",
this));
218 GstElement *pipeline = NULL;
224 NS_ENSURE_SUCCESS (rv, rv);
226 pipeline = (GstElement *)gst_object_ref (
mPipeline);
229 gst_element_set_state(pipeline, GST_STATE_PAUSED);
230 gst_object_unref (pipeline);
236 sbGStreamerPipeline::StopPipeline()
238 TRACE((
"sbGStreamerPipeline[0x%.8x] - StopPipeline",
this));
239 GstElement *pipeline = NULL;
244 pipeline = (GstElement *)gst_object_ref (
mPipeline);
248 gst_element_set_state(pipeline, GST_STATE_NULL);
249 gst_object_unref (pipeline);
252 NS_ENSURE_SUCCESS (rv, rv);
273 GstMessageType msg_type;
274 msg_type = GST_MESSAGE_TYPE(message);
277 case GST_MESSAGE_ERROR:
280 case GST_MESSAGE_WARNING:
283 case GST_MESSAGE_STATE_CHANGED:
286 case GST_MESSAGE_EOS:
290 LOG((
"Got message: %s", gst_message_type_get_name(msg_type)));
297 GError *gerror = NULL;
299 nsString errormessage;
300 nsCOMPtr<sbIMediacoreError> error;
303 gst_message_parse_error(message, &gerror, &debug);
305 LOG((
"Error message: %s [%s]", GST_STR_NULL (gerror->message),
306 GST_STR_NULL (debug)));
310 op, getter_AddRefs(error));
311 NS_ENSURE_SUCCESS(rv, );
315 g_error_free (gerror);
319 NS_ENSURE_SUCCESS (rv, );
324 GError *error = NULL;
327 gst_message_parse_warning(message, &error, &debug);
329 LOG((
"Warning message: %s [%s]", GST_STR_NULL (error->message),
330 GST_STR_NULL (debug)));
332 g_warning (
"%s [%s]", GST_STR_NULL (error->message), GST_STR_NULL (debug));
334 g_error_free (error);
340 TRACE((
"sbGStreamerPipeline[0x%.8x] - HandleEOSMessage",
this));
342 nsresult rv = StopPipeline();
343 NS_ENSURE_SUCCESS (rv, );
357 if (GST_IS_PIPELINE (message->src))
359 GstState oldstate, newstate, pendingstate;
360 gst_message_parse_state_changed (message,
361 &oldstate, &newstate, &pendingstate);
363 gchar *srcname = gst_object_get_name(message->src);
364 LOG((
"state-changed: %s changed state from %s to %s", srcname,
365 gst_element_state_get_name (oldstate),
366 gst_element_state_get_name (newstate)));
369 if (oldstate == GST_STATE_PAUSED && newstate == GST_STATE_PLAYING)
374 else if (oldstate == GST_STATE_PLAYING && newstate == GST_STATE_PAUSED)
381 if (pendingstate == GST_STATE_VOID_PENDING) {
382 if (newstate == GST_STATE_PLAYING)
384 else if (newstate == GST_STATE_PAUSED)
386 else if (newstate == GST_STATE_NULL)
396 nsCOMPtr<sbIMediacoreEvent>
event;
401 getter_AddRefs(event));
402 NS_ENSURE_SUCCESS(rv, );
404 rv = DispatchEvent(event, PR_TRUE, nsnull);
405 NS_ENSURE_SUCCESS(rv, );
411 PRIntervalTime
now = PR_IntervalNow();
412 PRIntervalTime interval;
419 PRInt64 realnow = (PRInt64)now + ((PRInt64)1<<32);
426 return mTimeRunning + PR_IntervalToMilliseconds (interval) * GST_MSECOND;
438 NS_ERROR_NULL_POINTER;
446 NS_ERROR_NULL_POINTER;
454 NS_ERROR_NULL_POINTER;
GStreamer::pipelineOp_t GetPipelineOp()
nsAutoPtr< sbBaseMediacoreEventTarget > mBaseEventTarget
GstClockTime mTimeRunning
virtual void HandleBufferingMessage(GstMessage *message)
GstClockTime GetRunningTime()
virtual void HandleErrorMessage(GstMessage *message)
NS_IMPL_THREADSAFE_RELEASE(sbRequestItem)
#define SBGSTREAMERSERVICE_CONTRACTID
NS_IMPL_THREADSAFE_ADDREF(sbRequestItem)
virtual void HandleWarningMessage(GstMessage *message)
const sbCreateProxiedComponent do_ProxiedGetService(const nsCID &aCID, nsresult *error=0)
virtual nsresult BuildPipeline()
void DispatchMediacoreEvent(unsigned long type, nsIVariant *aData=NULL, sbIMediacoreError *aError=NULL)
virtual void HandleEOSMessage(GstMessage *message)
virtual void HandleStateChangeMessage(GstMessage *message)
GStreamer::pipelineOp_t mPipelineOp
virtual void HandleMessage(GstMessage *message)
virtual ~sbGStreamerPipeline()
nsString mResourceDisplayName
virtual nsresult SetupPipeline()
void SetPipelineOp(GStreamer::pipelineOp_t aPipelineOp)
PRIntervalTime mTimeStarted
NS_INTERFACE_MAP_END NS_IMPL_CI_INTERFACE_GETTER1(CDatabaseQuery, sbIDatabaseQuery) CDatabaseQuery
virtual nsresult OnDestroyPipeline(GstElement *pipeline)
virtual nsresult DestroyPipeline()
NS_IMPL_QUERY_INTERFACE2_CI(sbGStreamerPipeline, sbIMediacoreEventTarget, nsIClassInfo) NS_IMPL_CI_INTERFACE_GETTER1(sbGStreamerPipeline
virtual PRBool HandleSynchronousMessage(GstMessage *message)
_updateTextAndScrollDataForFrame aData
virtual void HandleTagMessage(GstMessage *message)