Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <gst/gst.h>
- #include <stdio.h>
- #include <pthread.h>
- typedef struct _CustomData {
- GstElement *playbin; /* Our one and only element */
- GstStreamCollection *collection;
- gint n_video; /* Number of embedded video streams */
- gint n_audio; /* Number of embedded audio streams */
- gint n_text; /* Number of embedded subtitle streams */
- gint current_video; /* Currently playing video stream */
- gint current_audio; /* Currently playing audio stream */
- gint current_text; /* Currently playing subtitle stream */
- GMainLoop *main_loop; /* GLib's Main Loop */
- } CustomData;
- typedef enum {
- GST_PLAY_FLAG_VIDEO = (1 << 0), /* We want video output */
- GST_PLAY_FLAG_AUDIO = (1 << 1), /* We want audio output */
- GST_PLAY_FLAG_TEXT = (1 << 2) /* We want subtitle output */
- } GstPlayFlags;
- static CustomData *data;
- gchar *g_filename;
- gboolean isplaying;
- GMainLoop *loop;
- GstBus *bus ;
- GstMessage *msg ;
- gint flags;
- GstStateChangeReturn ret;
- gchar *uria;
- gchar *urib;
- gchar *uri1;
- void printcurrent_timestamp() {
- struct timeval te;
- gettimeofday(&te, NULL);
- long long milliseconds = te.tv_sec*1000LL + te.tv_usec/1000;
- g_print("milliseconds: %lld\n", milliseconds);
- }
- void play(gchar *uritoplay)
- {
- if (data->playbin) {
- gst_element_set_state (data->playbin, GST_STATE_NULL);
- gst_object_unref (data->playbin);
- data->playbin = NULL;
- g_free (data);
- data = g_new0 (CustomData, 1);
- }
- data->playbin = gst_element_factory_make ("playbin3", "playbin");
- if (!data->playbin) {
- g_printerr ("Not all elements could be created.\n");
- return;
- }
- g_object_set(data->playbin, "uri", uritoplay, NULL);
- g_object_get (data->playbin, "flags", &flags, NULL);
- flags |= GST_PLAY_FLAG_VIDEO;
- flags &= ~GST_PLAY_FLAG_TEXT;
- flags &= ~GST_PLAY_FLAG_AUDIO;
- g_object_set (data->playbin, "flags", flags, NULL);
- GstElement *sink;
- sink = gst_parse_bin_from_description ("kmssink plane-properties=s,zpos=3", TRUE, NULL);
- g_object_set (data->playbin, "video-sink", sink, NULL);
- gst_object_unref(sink);
- ret = gst_element_set_state (data->playbin, GST_STATE_PLAYING);
- if (ret == GST_STATE_CHANGE_FAILURE) {
- g_printerr ("Unable to set the pipeline to the playing state.\n");
- gst_object_unref (data->playbin);
- return;
- }
- }
- int main(int argc, char *argv[]) {
- int looper = 0;
- gboolean isloopa= TRUE;
- data = g_new0 (CustomData, 1);
- gst_init (NULL, NULL);
- uria = gst_filename_to_uri ("/root/FileA.mp4", NULL);
- urib = gst_filename_to_uri ("/root/FileB.mp4", NULL);
- play(uria);
- bus = gst_element_get_bus(data->playbin);
- for(;;)
- {
- looper++;
- //EVERY 10s video uri is changed and pipeline reinitialised
- if(looper==10000){
- g_print("10000!\n");
- looper=0;
- if(isloopa==TRUE) {
- isloopa= FALSE;
- play(urib);
- } else {
- isloopa= TRUE;
- play(uria);
- }
- gst_object_unref(bus);
- bus = gst_element_get_bus(data->playbin);
- }
- //BLOCKS FOR 1ms
- msg = gst_bus_timed_pop_filtered(bus, 1000000, (GstMessageType)(GST_MESSAGE_ERROR | GST_MESSAGE_EOS | GST_MESSAGE_WARNING | GST_MESSAGE_INFO));
- if(msg != NULL) {
- GError *err;
- gchar *debug_info;
- switch (GST_MESSAGE_TYPE (msg)) {
- 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");
- if(strstr(err->message, "Failed to decode frame")){
- gst_print ("1M Frame - Restart\n");
- play(uria);
- gst_message_unref (msg);
- gst_object_unref(bus);
- bus = gst_element_get_bus(data->playbin);
- }
- g_clear_error (&err);
- g_free (debug_info);
- break;
- case GST_MESSAGE_EOS:
- g_print ("End-Of-Stream reached. SEEK.\n"); printcurrent_timestamp();
- gst_message_unref (msg);
- if(gst_element_seek(data->playbin, 1.0, GST_FORMAT_TIME, GST_SEEK_FLAG_FLUSH, GST_SEEK_TYPE_SET, 0, GST_SEEK_TYPE_NONE, GST_CLOCK_TIME_NONE) ==FALSE) {
- g_print("SEEK FAILED!\n");
- }
- break;
- default:
- gst_message_unref (msg);
- break;
- }
- }
- }
- /* Free resources */
- gst_element_set_state (data->playbin, GST_STATE_NULL);
- gst_object_unref (data->playbin);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement