void
AlertTonePreview::gstSignalHandler (
    GstBus              *bus,
    GstMessage          *msg,
    AlertTonePreview    *atp)
{
    Q_UNUSED (bus);

    if (GST_MESSAGE_TYPE (msg) == GST_MESSAGE_ERROR)
    {
        GError *err = NULL;
        char *debug = NULL;

        gst_message_parse_error (msg, &err, &debug);
        SYS_WARNING ("\nfrom '%s'\ntype '%s'\n'error '%s'\ndebug '%s'",
                     GST_MESSAGE_SRC_NAME (msg), GST_MESSAGE_TYPE_NAME (msg),
                     (err && err->message) ? err->message : "Unknown error",
                     debug ? debug : "empty");

        g_error_free(err);
        g_free(debug);
    }
    else if (GST_MESSAGE_TYPE (msg) == GST_MESSAGE_EOS)
        atp->rewind ();
}
Exemplo n.º 2
0
static void
bus_call (GstBus     *bus,
          GstMessage *msg,
          gpointer    data)
{
  GMainLoop *loop = (GMainLoop *) data;
  char sender[181] = {0};
  int rc = 0;
  if (!strcmp("motions",GST_MESSAGE_SRC_NAME(msg)))
{
	count_det++;
	//rc = Base64Encode("006$rpi001$ceslab$Detected", sender, BUFFFERLEN);
	//send(global_socket,sender,181,NULL);
	printf("Detection: %d\n",count_det);
	//gst_element_set_state (pipeline, GST_STATE_NULL);
  	//gst_object_unref (pipeline);
  //gst_element_set_state (pipeline, GST_STATE_NULL);
  //gst_object_unref (pipeline);
}
  if (count_det == 5)
{
	rc = Base64Encode("006$rpi001$ceslab$Detected", sender, BUFFFERLEN);
        send(global_socket,sender,181,NULL);
        //printf("%d\n",count_det);
	gst_object_unref (bus);
        gst_element_set_state (pipeline, GST_STATE_NULL);
        gst_object_unref (pipeline);
	//count_det=0;
	//printf("video_send_gathering_done: %d\n", video_send_gathering_done);
	//printf("text_gathering_done: %d\n", text_gathering_done);
	//printf("detect_done: %d\n", detect_done);
}
  //return TRUE;
}
Exemplo n.º 3
0
gboolean bus_callback(GstBus* sender, GstMessage* message, void* data)
{
  gPlay* gplay = reinterpret_cast<gPlay*> (data);
  
  switch (GST_MESSAGE_TYPE (message)) {
    case GST_MESSAGE_STATE_CHANGED:
    {
      GstState newState;
      gst_message_parse_state_changed(message, NULL, &newState, NULL);
      
      std::string message_name(GST_MESSAGE_SRC_NAME(message));//TODO: Avoid this copy using glib
      
      if (message_name.compare("playbin") == 0){
	gplay->on_state_changed(newState);
      }
    }
      break;
      
    case GST_MESSAGE_TAG:
    {
      GstTagList* tag_list = 0;
      gst_message_parse_tag(message, &tag_list);
      Track t;
      track_from_tag(tag_list, &t);
      gplay->on_tag_found(t);
      gst_tag_list_free(tag_list);
    }
      break;
      
    case GST_MESSAGE_EOS:
      gplay->on_eos();
      break;
      
    case GST_MESSAGE_STREAM_STATUS:
      GstStreamStatusType message_type;
      gst_message_parse_stream_status(message, &message_type, NULL);
      g_print("Stream status: %d\n", message_type);
      break;
      
    default:
      g_print("Message from %s: %s\n", GST_MESSAGE_SRC_NAME(message), gst_message_type_get_name(GST_MESSAGE_TYPE(message)));
      break;
  }
  
  //TODO: Should I dispose message?
  return true;
}
Exemplo n.º 4
0
static gboolean
message_handler (GstBus * bus, GstMessage * message, gpointer user_data)
{

    switch (GST_MESSAGE_TYPE (message)) {
#ifdef ASYNC_VERSION
    case GST_MESSAGE_ELEMENT: {
        const GstStructure *str;

        str = gst_message_get_structure (message);

        if (gst_structure_has_name (str, "GstBinForwarded")) {
            GstMessage *orig;

            /* unwrap the element message */
            gst_structure_get (str, "message", GST_TYPE_MESSAGE, &orig, NULL);
            g_assert (orig);

            switch (GST_MESSAGE_TYPE (orig)) {
            case GST_MESSAGE_ASYNC_DONE:
                g_print ("ASYNC done %s\n", GST_MESSAGE_SRC_NAME (orig));
                if (GST_MESSAGE_SRC (orig) == GST_OBJECT_CAST (play_bin)) {
                    g_print
                    ("prerolled, starting synchronized playback and recording\n");
                    /* returns ASYNC because the sink linked to the live source is not
                     * prerolled */
                    if (gst_element_set_state (pipeline,
                                               GST_STATE_PLAYING) != GST_STATE_CHANGE_ASYNC) {
                        g_warning ("State change failed");
                    }
                }
                break;
            default:
                break;
            }
        }
        break;
    }
#endif
    case GST_MESSAGE_EOS:
        g_print ("EOS\n");
        g_main_loop_quit (loop);
        break;
    case GST_MESSAGE_ERROR: {
        GError *err = NULL;

        gst_message_parse_error (message, &err, NULL);
        g_print ("error: %s\n", err->message);
        g_clear_error (&err);

        g_main_loop_quit (loop);
        break;
    }
    default:
        break;
    }

    return TRUE;
}
Exemplo n.º 5
0
static gboolean
gst_bus_message (GstBus * bus, GstMessage * message, void *unused)
{
    (void)bus;
    (void)unused;

    DEBUGF("    [gst] got BUS message %s\n",
        gst_message_type_get_name (GST_MESSAGE_TYPE (message)));

    switch (GST_MESSAGE_TYPE (message)) {
        case GST_MESSAGE_ERROR:
        {
        GError *err;
        gchar *debug;
        gst_message_parse_error (message, &err, &debug);

        DEBUGF("[gst] Received error: Src: %s, msg: %s\n", GST_MESSAGE_SRC_NAME(message), err->message);

        g_error_free (err);
        g_free (debug);
        }

        g_main_loop_quit (pcm_loop);
        break;
        case GST_MESSAGE_EOS:
        gst_element_set_state (GST_ELEMENT(gst_pipeline), GST_STATE_NULL);
        break;
    case GST_MESSAGE_STATE_CHANGED:
    {
        GstState old_state, new_state;

        gst_message_parse_state_changed (message, &old_state, &new_state, NULL);
        DEBUGF("[gst] Element %s changed state from %s to %s.\n",
            GST_MESSAGE_SRC_NAME(message),
            gst_element_state_get_name (old_state),
            gst_element_state_get_name (new_state));
        break;
        }
        default:
        break;
    }

    return TRUE;
}
Exemplo n.º 6
0
static gboolean bus_callback(GstBus *bus, GstMessage *message, gpointer *ptr)
{
	gst_app_t *app = (gst_app_t*)ptr;

	switch(GST_MESSAGE_TYPE(message)){

		case GST_MESSAGE_ERROR:{
					       gchar *debug;
					       GError *err;

					       gst_message_parse_error(message, &err, &debug);
					       g_print("Error %s\n", err->message);
					       g_error_free(err);
					       g_free(debug);
					       g_main_loop_quit(app->loop);
				       }
				       break;

		case GST_MESSAGE_WARNING:{
						 gchar *debug;
						 GError *err;
						 gchar *name;

						 gst_message_parse_warning(message, &err, &debug);
						 g_print("Warning %s\nDebug %s\n", err->message, debug);

						 name = (gchar *)GST_MESSAGE_SRC_NAME(message);

						 g_print("Name of src %s\n", name ? name : "nil");
						 g_error_free(err);
						 g_free(debug);
					 }
					 break;

		case GST_MESSAGE_EOS:
					 g_print("End of stream\n");
					 g_main_loop_quit(app->loop);
					 break;

		case GST_MESSAGE_STATE_CHANGED:
					 break;

		default:
//					 g_print("got message %s\n", \
							 gst_message_type_get_name (GST_MESSAGE_TYPE (message)));
					 break;
	}

	return TRUE;
}
Exemplo n.º 7
0
GstBusSyncReply GstPipeliner::on_gst_error(GstMessage* msg) {
  if (GST_MESSAGE_TYPE(msg) != GST_MESSAGE_ERROR) return GST_BUS_PASS;
  gchar* debug = nullptr;
  GError* error = nullptr;
  gst_message_parse_error(msg, &error, &debug);
  g_free(debug);
  g_warning("GStreamer error: %s (element %s)", error->message, GST_MESSAGE_SRC_NAME(msg));
  On_scope_exit {
    if (error) g_error_free(error);
  };
  // on-error-gsource
  GSourceWrapper* gsrc =
      static_cast<GSourceWrapper*>(g_object_get_data(G_OBJECT(msg->src), "on-error-gsource"));
  if (nullptr != gsrc) {
    // removing command in order to get it invoked once
    g_object_set_data(G_OBJECT(msg->src), "on-error-gsource", nullptr);
    gsrc->attach(main_loop_->get_main_context());
  }
  if (on_error_cb_) on_error_cb_(GST_MESSAGE_SRC(msg), error);
  return GST_BUS_DROP;
}
Exemplo n.º 8
0
void media_bus_message(GstBus     *bus,
                              GstMessage *message,
                              gpointer    user_data) {
  switch (GST_MESSAGE_TYPE (message)) {
  case GST_MESSAGE_ERROR: {
    GError *err = NULL;
    gchar *dbg = NULL;
    gst_message_parse_error(message, &err, &dbg);
    if (err) {
      g_error("RTSP Pipeline ERROR: %s", err->message);
      g_error_free(err);
    }
    if (dbg) {
      g_message("Debug details: %s", dbg);
      g_free(dbg);
    }
    break;
  }
    /*
  case GST_MESSAGE_STATE_CHANGED:
  case GST_MESSAGE_STREAM_STATUS:
  case GST_MESSAGE_TAG:
  case GST_MESSAGE_NEW_CLOCK: {
    // Ignore
    break;
  }
    */
  default: {
    const GstStructure* mstruct = gst_message_get_structure(message);
    char* struct_info =
      mstruct ? gst_structure_to_string(mstruct) : g_strdup("no-struct");
    g_message("RTSP bus Message '%s' from '%s': %s",
              GST_MESSAGE_TYPE_NAME(message),
              GST_MESSAGE_SRC_NAME(message),
              struct_info);
    g_free(struct_info);
    break;
  }
  }
}
Exemplo n.º 9
0
bool ofGstUtils::gstHandleMessage(GstBus * bus, GstMessage * msg){
	if(appsink && appsink->on_message(msg)) return true;

		ofLogVerbose("ofGstUtils") << "gstHandleMessage(): got " << GST_MESSAGE_TYPE_NAME(msg)
			<< " message from " << GST_MESSAGE_SRC_NAME(msg);

	switch (GST_MESSAGE_TYPE (msg)) {

		case GST_MESSAGE_BUFFERING:
			gint pctBuffered;
			gst_message_parse_buffering(msg,&pctBuffered);
			ofLogVerbose("ofGstUtils") << "gstHandleMessage(): buffering " << pctBuffered;
			/*if(pctBuffered<100){
				gst_element_set_state (gstPipeline, GST_STATE_PAUSED);
			}else if(!bPaused){
				gst_element_set_state (gstPipeline, GST_STATE_PLAYING);
			}*/
		break;

#if GST_VERSION_MAJOR==0
		case GST_MESSAGE_DURATION:{
			GstFormat format=GST_FORMAT_TIME;
			gst_element_query_duration(gstPipeline,&format,&durationNanos);
		}break;
#else
		case GST_MESSAGE_DURATION_CHANGED:
			gst_element_query_duration(gstPipeline,GST_FORMAT_TIME,&durationNanos);
			break;

#endif

		case GST_MESSAGE_STATE_CHANGED:{
			GstState oldstate, newstate, pendstate;
			gst_message_parse_state_changed(msg, &oldstate, &newstate, &pendstate);
			if(isStream && newstate==GST_STATE_PAUSED && !bPlaying ){
				bLoaded = true;
				bPlaying = true;
				if(!bPaused){
					ofLogVerbose("ofGstUtils") << "gstHandleMessage(): setting stream pipeline to play";
					play();
				}
			}

			ofLogVerbose("ofGstUtils") << "gstHandleMessage(): " << GST_MESSAGE_SRC_NAME(msg) << " state changed from "
					<< getName(oldstate) << " to " << getName(newstate) << " (" + getName(pendstate) << ")";
		}break;

		case GST_MESSAGE_ASYNC_DONE:
			ofLogVerbose("ofGstUtils") << "gstHandleMessage(): async done";
		break;

		case GST_MESSAGE_ERROR: {
			GError *err;
			gchar *debug;
			gst_message_parse_error(msg, &err, &debug);

			ofLogVerbose("ofGstUtils") << "gstHandleMessage(): embedded video playback halted for plugin, module "
				<< gst_element_get_name(GST_MESSAGE_SRC (msg)) << "  reported: " << err->message;

			g_error_free(err);
			g_free(debug);

			gst_element_set_state(GST_ELEMENT(gstPipeline), GST_STATE_NULL);

		}break;

			case GST_MESSAGE_EOS:
				ofLogVerbose("ofGstUtils") << "gstHandleMessage(): end of the stream";
				bIsMovieDone = true;


			if(appsink && !isAppSink) appsink->on_eos();

			switch(loopMode){

				case OF_LOOP_NORMAL:{
					GstFormat format = GST_FORMAT_TIME;
					GstSeekFlags flags = (GstSeekFlags) (GST_SEEK_FLAG_FLUSH |GST_SEEK_FLAG_KEY_UNIT);
					gint64 pos;
#if GST_VERSION_MAJOR==0
					gst_element_query_position(GST_ELEMENT(gstPipeline),&format,&pos);
#else
					gst_element_query_position(GST_ELEMENT(gstPipeline),format,&pos);
#endif
					if(!gst_element_seek(GST_ELEMENT(gstPipeline),
										speed,
										format,
										flags,
										GST_SEEK_TYPE_SET,
										0,
										GST_SEEK_TYPE_SET,
										durationNanos)) {
						ofLogWarning("ofGstUtils") << "gstHandleMessage(): unable to seek";
					}
				}break;

				case OF_LOOP_PALINDROME:{
					GstFormat format = GST_FORMAT_TIME;
					GstSeekFlags flags = (GstSeekFlags) (GST_SEEK_FLAG_FLUSH |GST_SEEK_FLAG_KEY_UNIT);
					gint64 pos;
#if GST_VERSION_MAJOR==0
					gst_element_query_position(GST_ELEMENT(gstPipeline),&format,&pos);
#else
					gst_element_query_position(GST_ELEMENT(gstPipeline),format,&pos);
#endif
					float loopSpeed;
					if(pos>0)
						loopSpeed=-speed;
					else
						loopSpeed=speed;
					if(!gst_element_seek(GST_ELEMENT(gstPipeline),
										loopSpeed,
										GST_FORMAT_UNDEFINED,
										flags,
										GST_SEEK_TYPE_NONE,
										0,
										GST_SEEK_TYPE_NONE,
										0)) {
						ofLogWarning("ofGstUtils") << "gstHandleMessage(): unable to seek";
					}
				}break;

				default:
				break;
			}

		break;

		default:
			ofLogVerbose("ofGstUtils") << "gstHandleMessage(): unhandled message from " << GST_MESSAGE_SRC_NAME(msg);
		break;
	}
	return true;
}
Exemplo n.º 10
0
bool ofGstUtils::gstHandleMessage(GstBus * bus, GstMessage * msg){
	if(appsink && appsink->on_message(msg)) return true;

		/*ofLogVerbose("ofGstUtils") << "gstHandleMessage(): got " << GST_MESSAGE_TYPE_NAME(msg)
			<< " message from " << GST_MESSAGE_SRC_NAME(msg);*/

	switch (GST_MESSAGE_TYPE (msg)) {

		case GST_MESSAGE_BUFFERING:
			gint pctBuffered;
			gst_message_parse_buffering(msg,&pctBuffered);
			ofLogVerbose("ofGstUtils") << "gstHandleMessage(): buffering " << pctBuffered;
			if(pctBuffered<100){
				gst_element_set_state (gstPipeline, GST_STATE_PAUSED);
			}else if(!bPaused){
				gst_element_set_state (gstPipeline, GST_STATE_PLAYING);
			}
		break;

#if GST_VERSION_MAJOR==0
		case GST_MESSAGE_DURATION:{
			GstFormat format=GST_FORMAT_TIME;
			gst_element_query_duration(gstPipeline,&format,&durationNanos);
		}break;
#else
		case GST_MESSAGE_DURATION_CHANGED:
			gst_element_query_duration(gstPipeline,GST_FORMAT_TIME,&durationNanos);
			break;

#endif

		case GST_MESSAGE_STATE_CHANGED:{
			GstState oldstate, newstate, pendstate;
			gst_message_parse_state_changed(msg, &oldstate, &newstate, &pendstate);
			if(isStream && newstate==GST_STATE_PAUSED && !bPlaying ){
				bLoaded = true;
				bPlaying = true;
				if(!bPaused){
					//ofLogVerbose("ofGstUtils") << "gstHandleMessage(): setting stream pipeline to play";
					play();
				}
			}

			/*ofLogVerbose("ofGstUtils") << "gstHandleMessage(): " << GST_MESSAGE_SRC_NAME(msg) << " state changed from "
					<< getName(oldstate) << " to " << getName(newstate) << " (" + getName(pendstate) << ")";*/
		}break;

		case GST_MESSAGE_ASYNC_DONE:
			ofLogVerbose("ofGstUtils") << "gstHandleMessage(): async done";
		break;

		case GST_MESSAGE_ERROR: {
			GError *err;
			gchar *debug;
			gst_message_parse_error(msg, &err, &debug);
			gchar * name = gst_element_get_name(GST_MESSAGE_SRC (msg));

			ofLogError("ofGstUtils") << "gstHandleMessage(): embedded video playback halted for plugin, module "
				<< name << "  reported: " << err->message;

			g_free(name);
			g_error_free(err);
			g_free(debug);

			gst_element_set_state(GST_ELEMENT(gstPipeline), GST_STATE_NULL);

		}break;

		case GST_MESSAGE_EOS:{
			ofLogVerbose("ofGstUtils") << "gstHandleMessage(): end of the stream";
			bool isClosing = closing;
			eos_cb();

			if(isClosing){
				busWatchID = 0;
				return false;
			}

			switch(loopMode){

				case OF_LOOP_NORMAL:{
					GstFormat format = GST_FORMAT_TIME;
					GstSeekFlags flags = (GstSeekFlags) (GST_SEEK_FLAG_FLUSH | GST_SEEK_FLAG_KEY_UNIT);
					if(speed>0){
						if(!gst_element_seek(GST_ELEMENT(gstPipeline),
											speed,
											format,
											flags,
											GST_SEEK_TYPE_SET,
											0,
											GST_SEEK_TYPE_SET,
											-1)) {
							ofLogWarning("ofGstUtils") << "gstHandleMessage(): unable to seek";
						}
					}else if(speed<0){
						if(!gst_element_seek(GST_ELEMENT(gstPipeline),speed, 	format,
								flags,
								GST_SEEK_TYPE_SET,
								0,
								GST_SEEK_TYPE_SET,
								durationNanos-1000000)) {
							ofLogWarning("ofGstUtils") << "gstHandleMessage(): unable to seek";
						}
					}
				}break;

				case OF_LOOP_PALINDROME:{
					GstFormat format = GST_FORMAT_TIME;
					GstSeekFlags flags = (GstSeekFlags) (GST_SEEK_FLAG_FLUSH |GST_SEEK_FLAG_KEY_UNIT);
					gint64 pos;
					#if GST_VERSION_MAJOR==0
						gst_element_query_position(GST_ELEMENT(gstPipeline),&format,&pos);
					#else
						gst_element_query_position(GST_ELEMENT(gstPipeline),format,&pos);
					#endif
					float loopSpeed;
					if(pos>0)
						loopSpeed=-speed;
					else
						loopSpeed=speed;
					if(!gst_element_seek(GST_ELEMENT(gstPipeline),
										loopSpeed,
										GST_FORMAT_UNDEFINED,
										flags,
										GST_SEEK_TYPE_NONE,
										0,
										GST_SEEK_TYPE_NONE,
										0)) {
						ofLogWarning("ofGstUtils") << "gstHandleMessage(): unable to seek";
					}
				}break;

				default:
				break;
			}

		}break;
		case GST_MESSAGE_LATENCY:
			gst_bin_recalculate_latency (GST_BIN (getPipeline()));
			break;
		case GST_MESSAGE_REQUEST_STATE:	{
			GstState state;
			gchar *name = gst_object_get_path_string (GST_MESSAGE_SRC (msg));

			gst_message_parse_request_state (msg, &state);
			gst_element_set_state (getPipeline(), state);

			g_free (name);
			break;
		}
		case GST_MESSAGE_HAVE_CONTEXT:{
			GstContext *context;
			const gchar *context_type;
			gchar *context_str;

			gst_message_parse_have_context (msg, &context);

			context_type = gst_context_get_context_type (context);
			context_str = gst_structure_to_string (gst_context_get_structure (context));
			ofLogNotice("ofGstUtils","Got context from element '%s': %s=%s\n",
				GST_ELEMENT_NAME (GST_MESSAGE_SRC (msg)), context_type,
				context_str);
			g_free (context_str);
			gst_context_unref (context);
			break;
		}
		default:
			ofLogVerbose("ofGstUtils") << "gstHandleMessage(): unhandled message from " << GST_MESSAGE_SRC_NAME(msg);
		break;
	}

	return true;
}
Exemplo n.º 11
0
void ofGstUtils::gstHandleMessage(){
	GstBus *bus = gst_pipeline_get_bus(GST_PIPELINE(gstPipeline));
	while(gst_bus_have_pending(bus)) {
		GstMessage* msg = gst_bus_pop(bus);
		if(appsink && appsink->on_message(msg)) continue;

		ofLogVerbose() << "GStreamer: Got " << GST_MESSAGE_TYPE_NAME(msg) << " message from " << GST_MESSAGE_SRC_NAME(msg);

		switch (GST_MESSAGE_TYPE (msg)) {

			case GST_MESSAGE_BUFFERING:
				gint pctBuffered;
				gst_message_parse_buffering(msg,&pctBuffered);
				ofLog(OF_LOG_VERBOSE,"GStreamer: buffering %i\%", pctBuffered);
				/*if(pctBuffered<100){
					gst_element_set_state (gstPipeline, GST_STATE_PAUSED);
				}else if(!bPaused){
					gst_element_set_state (gstPipeline, GST_STATE_PLAYING);
				}*/
			break;

			case GST_MESSAGE_DURATION:{
				GstFormat format=GST_FORMAT_TIME;
				gst_element_query_duration(gstPipeline,&format,&durationNanos);
			}break;

			case GST_MESSAGE_STATE_CHANGED:{
				GstState oldstate, newstate, pendstate;
				gst_message_parse_state_changed(msg, &oldstate, &newstate, &pendstate);
				if(isStream && newstate==GST_STATE_PAUSED && !bPlaying ){
					bLoaded = true;
					bPlaying = true;
					if(!bPaused){
						cout << "setting stream pipeline to play " << endl;
						play();
					}
				}
				ofLogVerbose() << "GStreamer: " << GST_MESSAGE_SRC_NAME(msg) << " state changed from " << getName(oldstate) + " to " + getName(newstate) + " (" + getName(pendstate) + ")";
			}break;

			case GST_MESSAGE_ASYNC_DONE:
				ofLog(OF_LOG_VERBOSE,"GStreamer: async done");
			break;

			case GST_MESSAGE_ERROR: {
				GError *err;
				gchar *debug;
				gst_message_parse_error(msg, &err, &debug);

				ofLog(OF_LOG_ERROR, "GStreamer Plugin: Embedded video playback halted; module %s reported: %s",
					  gst_element_get_name(GST_MESSAGE_SRC (msg)), err->message);

				g_error_free(err);
				g_free(debug);

				gst_element_set_state(GST_ELEMENT(gstPipeline), GST_STATE_NULL);

			}break;

			case GST_MESSAGE_EOS:
				ofLog(OF_LOG_VERBOSE,"GStreamer: end of the stream.");
				bIsMovieDone = true;
				
				if(appsink && !isAppSink) appsink->on_eos();

				switch(loopMode){

					case OF_LOOP_NORMAL:{
						GstFormat format = GST_FORMAT_TIME;
						GstSeekFlags flags = (GstSeekFlags) (GST_SEEK_FLAG_FLUSH |GST_SEEK_FLAG_KEY_UNIT);
						gint64 pos;
						gst_element_query_position(GST_ELEMENT(gstPipeline),&format,&pos);

						if(!gst_element_seek(GST_ELEMENT(gstPipeline),
											speed,
											format,
											flags,
											GST_SEEK_TYPE_SET,
											0,
											GST_SEEK_TYPE_SET,
											durationNanos)) {
							ofLog(OF_LOG_WARNING,"GStreamer: unable to seek");
						}
					}break;

					case OF_LOOP_PALINDROME:{
						GstFormat format = GST_FORMAT_TIME;
						GstSeekFlags flags = (GstSeekFlags) (GST_SEEK_FLAG_FLUSH |GST_SEEK_FLAG_KEY_UNIT);
						gint64 pos;
						gst_element_query_position(GST_ELEMENT(gstPipeline),&format,&pos);
						float loopSpeed;
						if(pos>0)
							loopSpeed=-speed;
						else
							loopSpeed=speed;
						if(!gst_element_seek(GST_ELEMENT(gstPipeline),
											loopSpeed,
											GST_FORMAT_UNDEFINED,
											flags,
											GST_SEEK_TYPE_NONE,
											0,
											GST_SEEK_TYPE_NONE,
											0)) {
							ofLog(OF_LOG_WARNING,"GStreamer: unable to seek");
						}
					}break;

					default:
					break;
				}

			break;

			default:
				ofLogVerbose() << "GStreamer: unhandled message from " << GST_MESSAGE_SRC_NAME(msg);
			break;
		}
		gst_message_unref(msg);
	}

	gst_object_unref(GST_OBJECT(bus));
}
Exemplo n.º 12
0
CAMLprim value ocaml_gstreamer_message_source_name(value _msg)
{
  CAMLparam1(_msg);
  GstMessage *msg = Message_val(_msg);
  CAMLreturn(caml_copy_string(GST_MESSAGE_SRC_NAME(msg)));
}
Exemplo n.º 13
0
/**
 * gst_bus_timed_pop_filtered:
 * @bus: a #GstBus to pop from
 * @timeout: a timeout in nanoseconds, or GST_CLOCK_TIME_NONE to wait forever
 * @types: message types to take into account, GST_MESSAGE_ANY for any type
 *
 * Get a message from the bus whose type matches the message type mask @types,
 * waiting up to the specified timeout (and discarding any messages that do not
 * match the mask provided).
 *
 * If @timeout is 0, this function behaves like gst_bus_pop_filtered(). If
 * @timeout is #GST_CLOCK_TIME_NONE, this function will block forever until a
 * matching message was posted on the bus.
 *
 * Returns: (transfer full) (nullable): a #GstMessage matching the
 *     filter in @types, or %NULL if no matching message was found on
 *     the bus until the timeout expired. The message is taken from
 *     the bus and needs to be unreffed with gst_message_unref() after
 *     usage.
 *
 * MT safe.
 */
GstMessage *
gst_bus_timed_pop_filtered (GstBus * bus, GstClockTime timeout,
    GstMessageType types)
{
  GstMessage *message;
  GTimeVal now, then;
  gboolean first_round = TRUE;
  GstClockTime elapsed = 0;

  g_return_val_if_fail (GST_IS_BUS (bus), NULL);
  g_return_val_if_fail (types != 0, NULL);
  g_return_val_if_fail (timeout == 0 || bus->priv->poll != NULL, NULL);

  g_mutex_lock (&bus->priv->queue_lock);

  while (TRUE) {
    gint ret;

    GST_LOG_OBJECT (bus, "have %d messages",
        gst_atomic_queue_length (bus->priv->queue));

    while ((message = gst_atomic_queue_pop (bus->priv->queue))) {
      if (bus->priv->poll)
        gst_poll_read_control (bus->priv->poll);

      GST_DEBUG_OBJECT (bus, "got message %p, %s from %s, type mask is %u",
          message, GST_MESSAGE_TYPE_NAME (message),
          GST_MESSAGE_SRC_NAME (message), (guint) types);
      if ((GST_MESSAGE_TYPE (message) & types) != 0) {
        /* Extra check to ensure extended types don't get matched unless
         * asked for */
        if ((!GST_MESSAGE_TYPE_IS_EXTENDED (message))
            || (types & GST_MESSAGE_EXTENDED)) {
          /* exit the loop, we have a message */
          goto beach;
        }
      }

      GST_DEBUG_OBJECT (bus, "discarding message, does not match mask");
      gst_message_unref (message);
      message = NULL;
    }

    /* no need to wait, exit loop */
    if (timeout == 0)
      break;

    else if (timeout != GST_CLOCK_TIME_NONE) {
      if (first_round) {
        g_get_current_time (&then);
        first_round = FALSE;
      } else {
        g_get_current_time (&now);

        elapsed = GST_TIMEVAL_TO_TIME (now) - GST_TIMEVAL_TO_TIME (then);

        if (elapsed > timeout)
          break;
      }
    }

    /* only here in timeout case */
    g_assert (bus->priv->poll);
    g_mutex_unlock (&bus->priv->queue_lock);
    ret = gst_poll_wait (bus->priv->poll, timeout - elapsed);
    g_mutex_lock (&bus->priv->queue_lock);

    if (ret == 0) {
      GST_INFO_OBJECT (bus, "timed out, breaking loop");
      break;
    } else {
      GST_INFO_OBJECT (bus, "we got woken up, recheck for message");
    }
  }

beach:

  g_mutex_unlock (&bus->priv->queue_lock);

  return message;
}
Exemplo n.º 14
0
GstBusSyncReply GstPipeliner::bus_sync_handler(GstBus* /*bus*/,
                                               GstMessage* msg,
                                               gpointer user_data) {
  GstPipeliner* context = static_cast<GstPipeliner*>(user_data);
  auto res = GST_BUS_PASS;
  if (GST_BUS_DROP == context->on_gst_error(msg))
    return GST_BUS_DROP;
  else {
    if (context->on_msg_sync_cb_) {
      if (GST_BUS_DROP == context->on_msg_sync_cb_(msg)) return GST_BUS_DROP;
    }
  }

  // if (GST_MESSAGE_TYPE(msg) == GST_MESSAGE_QOS) {
  //   GstFormat format;
  //   guint64 processed;
  //   guint64 dropped;
  //   gst_message_parse_qos_stats(msg, &format, &processed, &dropped);
  //   // g_print ("QOS from %s, format %d, processed %lu dropped %lu\n",
  //   //  G_OBJECT_TYPE_NAME(G_OBJECT (msg->src)),
  //   //  format,
  //   //  processed,
  //   //  dropped);
  // }

  if (GST_MESSAGE_TYPE(msg) == GST_MESSAGE_ERROR) {
    gchar* debug = nullptr;
    GError* error = nullptr;
    gst_message_parse_error(msg, &error, &debug);
    g_free(debug);
    g_warning("GStreamer error: %s (element %s)", error->message, GST_MESSAGE_SRC_NAME(msg));
    g_error_free(error);
    res = GST_BUS_DROP;
  }

  // if (GST_MESSAGE_TYPE(msg) == GST_MESSAGE_EOS) {
  //   if (context->on_eos_cb_)
  //     context->on_eos_cb_();
  //   return GST_BUS_DROP;
  // }

  // FIXME:
  // const GstStructure *gstruct = gst_message_get_structure (msg);
  // if (nullptr != gstruct) {
  //   if (gst_structure_has_name(gstruct, "prepare-xwindow-id")) {
  //     guintptr *window_handle =
  //         (guintptr *) g_object_get_data(G_OBJECT(msg->src),
  //                                        "window-handle");
  //     if (window_handle != nullptr) {
  //       gst_x_overlay_set_window_handle(GST_X_OVERLAY(msg->src),
  //                                       *window_handle);
  //     }
  //   }
  // }

  // if (GST_MESSAGE_TYPE(msg) == GST_MESSAGE_TAG) {
  //   // GstTagList *tags = nullptr;
  //   // gst_message_parse_tag (msg, &tags);
  //   // g_print ("Got tags from element %s:\n", GST_OBJECT_NAME (msg->src));
  //   // gst_tag_list_foreach (tags, print_one_tag, nullptr);
  //   // g_print ("\n");
  //   // gst_tag_list_free (tags);
  // }

  return res;
}
Exemplo n.º 15
0
void Player::messageReceived(GstMessage *message)
{

                switch (GST_MESSAGE_TYPE (message)) {
                case GST_STATE_CHANGE_FAILURE: {
                    qDebug() << Q_FUNC_INFO <<": Gstreamer error:"<< p->error;
                }
                case GST_MESSAGE_ERROR: {
                        if ( p->error == "")
                        {
                            GError *err;
                            gchar *debug;
                            gst_message_parse_error (message, &err, &debug);
                            p->error = "Error #"+QString::number(err->code)+" in module "+QString::number(err->domain)+"\n"+QString::fromUtf8(err->message);
                            if(err->domain != GST_STREAM_ERROR && err->code != GST_STREAM_ERROR_FAILED) {
                                    p->error += "\nMay be you should install more of gstreamer plugins";
                                    lastError = QString::fromUtf8(err->message);
                            }
                            qDebug() << Q_FUNC_INFO <<": Gstreamer error:"<< p->error;
                            g_error_free (err);
                            g_free (debug);
                            Q_EMIT error();
                        }
                        break;
                }
                case GST_MESSAGE_EOS:{
                    qDebug() << Q_FUNC_INFO <<":"<<parentWidget()->objectName()<<" End of track reached";
                    Q_EMIT finish();
                    break;
                }
                case GST_MESSAGE_STATE_CHANGED: {
                    GstState old_state, new_state;
                    gst_message_parse_state_changed (message, &old_state, &new_state, NULL);
                    switch(new_state){
                    case GST_STATE_PAUSED:
                    case GST_STATE_NULL:
                        rms_l=rms_r=0;
                        rmsout_l=rmsout_r=0;
                    default:
                            break;
                    }
                    break;
                  }

                case GST_MESSAGE_ELEMENT:{
                        const GstStructure *s = gst_message_get_structure (message);
                        const gchar *src_name=GST_MESSAGE_SRC_NAME (message);

                        if (strcmp (src_name, "levelintern") == 0) {
                            gint channels;
                            gdouble peak_dB;
                            gdouble rms;
                            gint i;

#ifdef GST_API_VERSION_1
                            const GValue *array_val;
                            GValueArray *peak_arr;


                            array_val = gst_structure_get_value (s, "peak");
                            peak_arr = (GValueArray *) g_value_get_boxed (array_val);
                            channels = peak_arr->n_values;

                            for (i = 0; i < channels; ++i) {
                              peak_dB = g_value_get_double (peak_arr->values+i);
#else
                             const GValue *list;
                             const GValue *value;

                             list = gst_structure_get_value (s, "peak");
                             channels = gst_value_list_get_size (list);

                             for (i = 0; i < channels; ++i) {
                                 list = gst_structure_get_value (s, "peak");
                                 value = gst_value_list_get_value (list, i);
                                 peak_dB = g_value_get_double (value);
#endif
                              /* converting from dB to normal gives us a value between 0.0 and 1.0 */
                              rms = pow (10, peak_dB / 20);
                              if (i==0)
                                  rms_l=rms;
                              else
                                  rms_r=rms;
                            }
                        }
                        if (strcmp (src_name, "levelout") == 0) {
                            gint channels;
                            gdouble peak_dB;
                            gdouble rms;
                            gint i;

#ifdef GST_API_VERSION_1
                            const GValue *array_val;
                            GValueArray *peak_arr;


                            array_val = gst_structure_get_value (s, "peak");
                            peak_arr = (GValueArray *) g_value_get_boxed (array_val);
                            channels = peak_arr->n_values;

                            for (i = 0; i < channels; ++i) {
                              peak_dB = g_value_get_double (peak_arr->values+i);
#else
                             const GValue *list;
                             const GValue *value;

                             list = gst_structure_get_value (s, "peak");
                             channels = gst_value_list_get_size (list);

                             for (i = 0; i < channels; ++i) {
                                 list = gst_structure_get_value (s, "peak");
                                 value = gst_value_list_get_value (list, i);
                                 peak_dB = g_value_get_double (value);
#endif

                              /* converting from dB to normal gives us a value between 0.0 and 1.0 */
                              rms = pow (10, peak_dB / 20);
                              if (i==0)
                                  rmsout_l=rms;
                              else
                                  rmsout_r=rms;

                            }

                        }

                    }
                        break;
                default:
                        break;
                }

}
Exemplo n.º 16
0
/**
 * gst_bus_timed_pop_filtered:
 * @bus: a #GstBus to pop from
 * @timeout: a timeout in nanoseconds, or GST_CLOCK_TIME_NONE to wait forever
 * @types: message types to take into account, GST_MESSAGE_ANY for any type
 *
 * Get a message from the bus whose type matches the message type mask @types,
 * waiting up to the specified timeout (and discarding any messages that do not
 * match the mask provided).
 *
 * If @timeout is 0, this function behaves like gst_bus_pop_filtered(). If
 * @timeout is #GST_CLOCK_TIME_NONE, this function will block forever until a
 * matching message was posted on the bus.
 *
 * Returns: (transfer full) (nullable): a #GstMessage matching the
 *     filter in @types, or %NULL if no matching message was found on
 *     the bus until the timeout expired. The message is taken from
 *     the bus and needs to be unreffed with gst_message_unref() after
 *     usage.
 *
 * MT safe.
 */
GstMessage *
gst_bus_timed_pop_filtered (GstBus * bus, GstClockTime timeout,
    GstMessageType types)
{
  GstMessage *message;
  GTimeVal now, then;
  gboolean first_round = TRUE;
  GstClockTime elapsed = 0;

  g_return_val_if_fail (GST_IS_BUS (bus), NULL);
  g_return_val_if_fail (types != 0, NULL);
  g_return_val_if_fail (timeout == 0 || bus->priv->poll != NULL, NULL);

  g_mutex_lock (&bus->priv->queue_lock);

  while (TRUE) {
    gint ret;

    GST_LOG_OBJECT (bus, "have %d messages",
        gst_atomic_queue_length (bus->priv->queue));

    while ((message = gst_atomic_queue_pop (bus->priv->queue))) {
      if (bus->priv->poll) {
        while (!gst_poll_read_control (bus->priv->poll)) {
          if (errno == EWOULDBLOCK) {
            /* Retry, this can happen if pushing to the queue has finished,
             * popping here succeeded but writing control did not finish
             * before we got to this line. */
            /* Give other threads the chance to do something */
            g_thread_yield ();
            continue;
          } else {
            /* This is a real error and means that either the bus is in an
             * inconsistent state, or the GstPoll is invalid. GstPoll already
             * prints a critical warning about this, no need to do that again
             * ourselves */
            break;
          }
        }
      }

      GST_DEBUG_OBJECT (bus, "got message %p, %s from %s, type mask is %u",
          message, GST_MESSAGE_TYPE_NAME (message),
          GST_MESSAGE_SRC_NAME (message), (guint) types);
      if ((GST_MESSAGE_TYPE (message) & types) != 0) {
        /* Extra check to ensure extended types don't get matched unless
         * asked for */
        if ((!GST_MESSAGE_TYPE_IS_EXTENDED (message))
            || (types & GST_MESSAGE_EXTENDED)) {
          /* exit the loop, we have a message */
          goto beach;
        }
      }

      GST_DEBUG_OBJECT (bus, "discarding message, does not match mask");
      gst_message_unref (message);
      message = NULL;
    }

    /* no need to wait, exit loop */
    if (timeout == 0)
      break;

    else if (timeout != GST_CLOCK_TIME_NONE) {
      if (first_round) {
        g_get_current_time (&then);
        first_round = FALSE;
      } else {
        g_get_current_time (&now);

        elapsed = GST_TIMEVAL_TO_TIME (now) - GST_TIMEVAL_TO_TIME (then);

        if (elapsed > timeout)
          break;
      }
    }

    /* only here in timeout case */
    g_assert (bus->priv->poll);
    g_mutex_unlock (&bus->priv->queue_lock);
    ret = gst_poll_wait (bus->priv->poll, timeout - elapsed);
    g_mutex_lock (&bus->priv->queue_lock);

    if (ret == 0) {
      GST_INFO_OBJECT (bus, "timed out, breaking loop");
      break;
    } else {
      GST_INFO_OBJECT (bus, "we got woken up, recheck for message");
    }
  }

beach:

  g_mutex_unlock (&bus->priv->queue_lock);

  return message;
}
Exemplo n.º 17
0
bool ofxGstRTPServer::on_message(GstMessage * msg){
	// read messages from the pipeline like dropped packages
	switch (GST_MESSAGE_TYPE (msg)) {
	case GST_MESSAGE_ELEMENT:{
		GstObject * messageSrc = GST_MESSAGE_SRC(msg);
		ofLogVerbose(LOG_NAME) << "Got " << GST_MESSAGE_TYPE_NAME(msg) << " message from " << GST_MESSAGE_SRC_NAME(msg);
		ofLogVerbose(LOG_NAME) << "Message source type: " << G_OBJECT_CLASS_NAME(G_OBJECT_GET_CLASS(messageSrc));
		ofLogVerbose(LOG_NAME) << "With structure name: " << gst_structure_get_name(gst_message_get_structure(msg));
		ofLogVerbose(LOG_NAME) << gst_structure_to_string(gst_message_get_structure(msg));
		return true;
	}
	case GST_MESSAGE_QOS:{
		GstObject * messageSrc = GST_MESSAGE_SRC(msg);
		ofLogVerbose(LOG_NAME) << "Got " << GST_MESSAGE_TYPE_NAME(msg) << " message from " << GST_MESSAGE_SRC_NAME(msg);
		ofLogVerbose(LOG_NAME) << "Message source type: " << G_OBJECT_CLASS_NAME(G_OBJECT_GET_CLASS(messageSrc));

		GstFormat format;
		guint64 processed;
		guint64 dropped;
		gst_message_parse_qos_stats(msg,&format,&processed,&dropped);
		ofLogVerbose(LOG_NAME) << "format " << gst_format_get_name(format) << " processed " << processed << " dropped " << dropped;

		gint64 jitter;
		gdouble proportion;
		gint quality;
		gst_message_parse_qos_values(msg,&jitter,&proportion,&quality);
		ofLogVerbose(LOG_NAME) << "jitter " << jitter << " proportion " << proportion << " quality " << quality;

		gboolean live;
		guint64 running_time;
		guint64 stream_time;
		guint64 timestamp;
		guint64 duration;
		gst_message_parse_qos(msg,&live,&running_time,&stream_time,&timestamp,&duration);
		ofLogVerbose(LOG_NAME) << "live stream " << live << " runninng_time " << running_time << " stream_time " << stream_time << " timestamp " << timestamp << " duration " << duration;

		return true;
	}
	default:
		//ofLogVerbose(LOG_NAME) << "Got " << GST_MESSAGE_TYPE_NAME(msg) << " message from " << GST_MESSAGE_SRC_NAME(msg);
		return false;
	}
}