Beispiel #1
0
void  VideoImpl::_updateRate()
{
  // Check different things.
  if (_pipeline == NULL)
  {
    qWarning() << "Cannot set rate: no pipeline!" << endl;
    return;
  }

  if (!_seekEnabled)
  {
    qWarning() << "Cannot set rate: seek not working" << endl;
    return;
  }

  if (!_isMovieReady())
  {
    qWarning() << "Movie is not yet ready to play, cannot seek yet." << endl;
  }

  // Obtain the current position, needed for the seek event.
  gint64 position;
  if (!gst_element_query_position (_pipeline, GST_FORMAT_TIME, &position)) {
    qWarning() << "Unable to retrieve current position." << endl;
    return;
  }

  // Create the seek event.
  GstEvent *seekEvent;
  if (_rate > 0.0) {
    // Rate is positive (playing the video in normal direction)
    // Set new rate as a first argument. Provide position 0 so that we go to 0:00
    seekEvent = gst_event_new_seek (_rate, GST_FORMAT_TIME, GstSeekFlags( GST_SEEK_FLAG_FLUSH | GST_SEEK_FLAG_ACCURATE ),
        GST_SEEK_TYPE_SET, position, GST_SEEK_TYPE_NONE, 0); // Go to 0:00
  } else {
    // Rate is negative
    // Set new rate as a first arguemnt. Provide the position we were already at.
    seekEvent = gst_event_new_seek (_rate, GST_FORMAT_TIME, GstSeekFlags( GST_SEEK_FLAG_FLUSH | GST_SEEK_FLAG_ACCURATE ),
        GST_SEEK_TYPE_SET, 0, GST_SEEK_TYPE_SET, position);
  }

  // If we have not done so, obtain the sink through which we will send the seek events.
  if (_appsink0 == NULL) {
    g_object_get (_pipeline, "video-sink", &_appsink0, NULL);
  }

  // Send the event.
  if (!gst_element_send_event (_appsink0, seekEvent)) {
    qWarning() << "Cannot perform seek event" << endl;
  }

  qDebug() << "Current rate: " << _rate << "." << endl;
}
Beispiel #2
0
void  MediaImpl::_updateRate()
{
    if (_pipeline == NULL)
    {
        qDebug() << "Cannot set rate: no pipeline!" << endl;
        return;
    }

    if (!_seekEnabled)
    {
        qDebug() << "Cannot set rate: seek not working" << endl;
        return;
    }

    if (!_isMovieReady())
    {
        qDebug() << "Movie is not yet ready to play, cannot seek yet." << endl;
    }

    gint64 position;
    GstEvent *seekEvent;

    /* Obtain the current position, needed for the seek event */
    if (!gst_element_query_position (_pipeline, GST_FORMAT_TIME, &position)) {
        g_printerr ("Unable to retrieve current position.\n");
        return;
    }

    /* Create the seek event */
    if (_rate > 0) {
        seekEvent = gst_event_new_seek (_rate, GST_FORMAT_TIME, GstSeekFlags( GST_SEEK_FLAG_FLUSH | GST_SEEK_FLAG_ACCURATE ),
                                        GST_SEEK_TYPE_SET, position, GST_SEEK_TYPE_NONE, 0);
    } else {
        seekEvent = gst_event_new_seek (_rate, GST_FORMAT_TIME, GstSeekFlags( GST_SEEK_FLAG_FLUSH | GST_SEEK_FLAG_ACCURATE ),
                                        GST_SEEK_TYPE_SET, 0, GST_SEEK_TYPE_SET, position);
    }

    if (_appsink0 == NULL) {
        /* If we have not done so, obtain the sink through which we will send the seek events */
        g_object_get (_pipeline, "video-sink", &_appsink0, NULL);
    }

    /* Send the event */
    gst_element_send_event (_appsink0, seekEvent);

    g_print ("Current rate: %g\n", _rate);
}
Beispiel #3
0
void MediaImpl::_checkMessages()
{
    if (_bus != NULL)
    {
        // Get message.
        GstMessage *msg = gst_bus_timed_pop_filtered(
                              _bus, 0,
                              (GstMessageType) (GST_MESSAGE_STATE_CHANGED | GST_MESSAGE_ERROR | GST_MESSAGE_EOS | GST_MESSAGE_ASYNC_DONE));

        if (msg != NULL)
        {
            GError *err;
            gchar *debug_info;

            switch (GST_MESSAGE_TYPE (msg))
            {
            // Error ////////////////////////////////////////////////
            case GST_MESSAGE_ERROR:
                gst_message_parse_error(msg, &err, &debug_info);
                g_printerr("Error received from element %s: %s\n",
                           GST_OBJECT_NAME (msg->src), err->message);
                g_printerr("Debugging information: %s\n",
                           debug_info ? debug_info : "none");
                g_clear_error(&err);
                g_free(debug_info);

                if (!_isSharedMemorySource)
                {
                    _terminate = true;
                }
                else
                {
                    _attached = false;
                    gst_element_set_state (_pipeline, GST_STATE_PAUSED);
                    gst_element_set_state (_pipeline, GST_STATE_NULL);
                    gst_element_set_state (_pipeline, GST_STATE_READY);
                }
//        _finish();
                break;

            // End-of-stream ////////////////////////////////////////
            case GST_MESSAGE_EOS:
                // Automatically loop back.
                g_print("End-Of-Stream reached.\n");
                resetMovie();
//        _terminate = true;
//        _finish();
                break;

            // Pipeline has prerolled/ready to play ///////////////
            case GST_MESSAGE_ASYNC_DONE:
                if (!_isMovieReady())
                {
                    // Check if seeking is allowed.
                    gint64 start, end;
                    GstQuery *query = gst_query_new_seeking (GST_FORMAT_TIME);
                    if (gst_element_query (_pipeline, query))
                    {
                        gst_query_parse_seeking (query, NULL, (gboolean*)&_seekEnabled, &start, &end);
                        if (_seekEnabled)
                        {
                            g_print ("Seeking is ENABLED from %" GST_TIME_FORMAT " to %" GST_TIME_FORMAT "\n",
                                     GST_TIME_ARGS (start), GST_TIME_ARGS (end));

                        }
                        else
                        {
                            g_print ("Seeking is DISABLED for this stream.\n");
                        }
                    }
                    else
                    {
                        g_printerr ("Seeking query failed.");
                    }

                    gst_query_unref (query);

                    // Movie is ready!
                    _setMovieReady(true);
                }

                break;

            case GST_MESSAGE_STATE_CHANGED:
                // We are only interested in state-changed messages from the pipeline.
                if (GST_MESSAGE_SRC (msg) == GST_OBJECT (_pipeline))
                {
                    GstState oldState, newState, pendingState;
                    gst_message_parse_state_changed(msg, &oldState, &newState,
                                                    &pendingState);
                    g_print("Pipeline state for movie %s changed from %s to %s:\n",
                            _uri.toUtf8().constData(),
                            gst_element_state_get_name(oldState),
                            gst_element_state_get_name(newState));
                }
                break;

            default:
                // We should not reach here.
                g_printerr("Unexpected message received.\n");
                break;
            }
            gst_message_unref(msg);
        }
    }
}
Beispiel #4
0
void VideoImpl::_checkMessages()
{
  if (_bus != NULL)
  {
    // Get message.
    GstMessage *msg = gst_bus_timed_pop_filtered(
                        _bus, 0,
                        (GstMessageType) (GST_MESSAGE_STATE_CHANGED | GST_MESSAGE_ERROR | GST_MESSAGE_EOS | GST_MESSAGE_ASYNC_DONE));

    if (msg != NULL)
    {
      GError *err;
      gchar *debug_info;

      switch (GST_MESSAGE_TYPE (msg))
      {
      // Error ////////////////////////////////////////////////
      case GST_MESSAGE_ERROR:
        gst_message_parse_error(msg, &err, &debug_info);
        qWarning() << "Error received from element " << GST_OBJECT_NAME (msg->src) << ": " << err->message << endl;
        qDebug() << "Debugging information: " << (debug_info ? debug_info : "none") << "." << endl;
        g_clear_error(&err);
        g_free(debug_info);

        if (!isLive())
        {
          _terminate = true;
        }
        else
        {
          gst_element_set_state (_pipeline, GST_STATE_PAUSED);
          gst_element_set_state (_pipeline, GST_STATE_NULL);
          gst_element_set_state (_pipeline, GST_STATE_READY);
        }
//        _finish();
        break;

      // End-of-stream ////////////////////////////////////////
      case GST_MESSAGE_EOS:
        // Automatically loop back.
        resetMovie();
//        _terminate = true;
//        _finish();
        break;

      // Pipeline has prerolled/ready to play ///////////////
      case GST_MESSAGE_ASYNC_DONE:
        if (!_isMovieReady())
        {
          // Check if seeking is allowed.
          gint64 start, end;
          GstQuery *query = gst_query_new_seeking (GST_FORMAT_TIME);
          if (gst_element_query (_pipeline, query))
          {
            gst_query_parse_seeking (query, NULL, (gboolean*)&_seekEnabled, &start, &end);
            if (_seekEnabled)
            {
#ifdef VIDEO_IMPL_VERBOSE
              qDebug() << "Seeking is ENABLED from " << start << " to " << end << "." << endl;
#endif
            }
            else
            {
              qDebug() << "Seeking is DISABLED for this stream." << endl;
            }
          }
          else
          {
            qWarning() << "Seeking query failed." << endl;
          }

          gst_query_unref (query);

          // Movie is ready!
#ifdef VIDEO_IMPL_VERBOSE
          qDebug() << "Preroll done: movie is ready." << endl;
#endif // ifdef
          _setMovieReady(true);
        }

        break;

      case GST_MESSAGE_STATE_CHANGED:
        // We are only interested in state-changed messages from the pipeline.
        if (GST_MESSAGE_SRC (msg) == GST_OBJECT (_pipeline))
        {
          GstState oldState, newState, pendingState;
          gst_message_parse_state_changed(msg, &oldState, &newState, &pendingState);
#ifdef VIDEO_IMPL_VERBOSE
          qDebug() << "Pipeline state for movie " << _uri
                   << " changed from " << gst_element_state_get_name(oldState)
                   << " to " << gst_element_state_get_name(newState) << endl;
#endif
        }
        break;

      default:
        // We should not reach here.
        qWarning() << "Unexpected message received." << endl;
        break;
      }
      gst_message_unref(msg);
    }
  }
}