This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Gstreamer File Stream repetition problem



Hello,

I am trying to play a video file repeatedly using Gstreamer, when the file reaches End Of Stream. My video file just gets played only for a single time. I want it to repeat again. 

I try closing the file and reopening it again when END OF FILE condition is satisfied. I have attached that portion of code with this post. But, this method doesn't help me out.

The Pipeline is in PLAYING STATE and my terminal window is stable with the Dynamic Pads created. But the video playing window gets struck with the last frame of the video file. Repetition doesn't happen! 

 int repeat= 0;

    if (feof(l_pVideoFD))
                                        {
                                                if(fclose(l_pVideoFD) == 0)
                                                {
                                                        repeat++;
                                                        printf(" REPEATING %d\n",repeat);
                                                        l_pVideoFD = fopen("sample.mpg","r");

                                                }
                                        }

Kindly support me with regards to this issue.

Thanks in Advance!

Shylesh S.

  • Hello,

    If I understand you right you could try this approach.

    When receive EOS, seek to the beginning of the stream. This way you could restarts playback.

    You could try to implement this in gboolean bus_callback ()

    Something like:
    case GST_MESSAGE_EOS:
    /* restart playback if at end */
    if (!gst_element_seek(play,
    1.0, GST_FORMAT_TIME, GST_SEEK_FLAG_FLUSH,
    GST_SEEK_TYPE_SET, 0,
    GST_SEEK_TYPE_NONE, GST_CLOCK_TIME_NONE)) {
    g_print("Seek failed!\n");
    }

    You could also check this function:

    developer.gnome.org/.../glib-The-Main-Event-Loop.html

    BR
    Margarita
  • Hello Margarita,
    The first argument of this call is a GstElement. What element am I supposed to mention over there? I just tried giving GstElement *PipeLine in it.


    Once my file plays completely, it just hits GST_WARNING case in the bus call. I don't find it getting into GST_MESSAGE_EOS. So, I used gst_element_seek() in GST_WARNING case. I see that the file gets repeated improperly. Only the first time playback has audio working. Repeating portion looks like fast forwarded version with no audio heard.

    Kindly help me,
    Shylesh S.

  • Hello,

    In this example playbin is play element.

    BR
    Margarita
  • Hello,
    I have edited my previous reply. Do Check again.

    BR,
    Shylesh S.

  • Hello,

    Did you try to implement gst_element_seek in GST_MESSAGE_EOS?

    Shylesh S said:
    Repeating portion looks like fast forwarded version with no audio heard.

    You could check the debug log, I have suspicious that the audio device can not be open because it is in use.

    You could try when EOS is received to move the pipeline to NULL state and then back to PLAYING but you make sure that all the elements are receive the EOS.

    But if you move it in NULL state it has not allocated any runtime resources . If this not work for you, you could try to move it in READY -> PLAYING.

    In worst case you could  destroy the pipeline and create it again at the EOS event.

    BR
    Margarita

  • Hello Margarita,

    Yeah, I tried implementing it at EOS case. But the control doesn't go to EOS case. So, I couldn't check the behavior of that implementation.

    The problem in my case is that I don't find my bus call hitting the EOS case. Am I supposed to change or add something else to get notified about EOS in the bus call?

    Thanks!

    Shylesh S.

  • Hello,

    Do you mean that you can not get GST_MESSAGE_EOS for end of streaming on bus?
    If yes, you could try send EOS event directly to the pipeline from your application

    gst_element_send_event(pipeline, gst_event_new_eos());

    BR
    Margarita
  • Hello,
    I just implemented this. It gets into EOS case. But the call fails. I get " SEEK FAILED" error!

    What causes gst_element_seek() fail??

    Kindly help me out.



    BR,
    Shylesh S.

  • Hello,

    You could check here:
    gstreamer.freedesktop.org/.../section-eventsseek.html

    Could you post the seek function on your side?

    What is the pipeline ?

    Could you try to send seek when the pipeline is in PAUSE STATE?

    BR
    Margarita
  • Hello Margarita,

    I see that my APPSRC stream type is GST_APP_STREAM_TYPE_STREAM, which doesn't support seeking. I get to know my AppSrc stream type using "gst_app_src_get_stream_type ()".
    So, I tried setting my stream type manually using "gst_app_src_set_stream_type ()". But, I get some problems like, buffer Injection failure.

    I had also tried setting SYNC Property of kmssink as FALSE, to check if my repetition is proper. When I do this, I see that the stream gets repeated with an increased play back speed than the usual speed. And, the Audio is not heard.

    Kindly guide me through this!

    Regards,
    Shylesh S.

  • Hello,

    Since I know appsrc does not support seek.

    Have you tried to move the pipeline in NULL state(check my above suggestion)?

    The sync property should be set as true. If the sync=false, means that the sink ignores the timestamps on buffers and
    the clock, and just displays the frame as soon as it receive.

    Regarding the audio could you check about errors or warnings in the debug log.


    BR
    Margarita
  • Hello,
    This is my Pipeline:
    PipeLine = (GstPipeline*)gst_pipeline_new("VideoPlayerPipeline");

    Do you mean to manually move the pipeline to NULL once End Of File is reached?
    How is that going to solve the repetition issue?

    BR,
    Shylesh S.
  • Hello,

    I mean the full pipeline that you are using.

    Did you set he sync=true? If yes, is this resolve your problem with fast playing?

    BR
    Margarita
  • Hello Margarita,

    This is what I do with my VideoSink:

    Access2Player->AudioSink    = gst_element_factory_make("alsasink","AudoSink");

    Access2Player->VideoSink   = gst_element_factory_make("kmssink", "VideoSink");

    g_object_set (Access2Player->VideoSink, "connector", 16, NULL);

    g_object_set (Access2Player->VideoSink, "sync", 0, NULL);

    g_object_set (Access2Player->AudioSink, "sync", 0, NULL);


    When I do this, I do not get any warnings and disturbance. In my previous posts, I had told you that I set only the sync property of VideoSink as FALSE. Now when I set the sync property of AudioSink also as FALSE, I see that Audio is also is being played (Repeated). But there is a slight synchronization problem between the video and audio. 


    I do know that the sync property mustn't be set to FALSE. Just for an observation I have done this and I've observed the above behavior.


    The default sync properties of both Audio/Video Sink are TRUE. So, when I run with the sync property as TRUE, I get warning print in the GST_MESSAGE_WARNING bus call case. And also the video doesn't repeat properly.

    case GST_MESSAGE_WARNING:

                                   printf("GST_MESSAGE_WARNING\n");

                                   gchar *debug;

                                   gst_message_parse_warning (Message, &error, &debug);

                                   printf("%s\n", error->message);

     

    Error that I get:

    GSTREAMER PC ELEMENTS LINKED SUCCESSFULY
    Video thread created
    going to add pad
    g sig conn succ
    loop starting..
    Start Dynamic Pad
    The decoder's video pad is linked to video decoder's sink pad
    Start Dynamic Pad
    The decoder's audio pad is linked to the audio decoder's sink pad
    GST_MESSAGE_WARNING
    A lot of buffers are being dropped.
    GST_MESSAGE_WARNING
    A lot of buffers are being dropped.
    GST_MESSAGE_WARNING
    A lot of buffers are being dropped.


    I keep getting these GST_MESSAGE_WARNING prints continuously.

    Kindly help me out.

    Regards,

    Shylesh S.

  • Hello,

    Could you try to add queue elements in your pipeline?

    You could set these properties for queue element max-size-buffers=xx max-size-time=xx max-size-bytes=xx.

    BR
    Margarita
  • Hello Margarita,

    I have already included QUEUE element for both Audio and Video.

    Now I have tried setting properties for them as follows,

    g_object_set (Access2Player->VideoQueue, "max-size-bytes", 90000, NULL);
    g_object_set (Access2Player->VideoQueue, "max-size-time", 10000000000, NULL);

    I see no improvement in the playback.

    Kindly help!

    Regards,

    Shylesh S.

  • Hello,

    Mostly " GST_MESSAGE_WARNING A lot of buffers are being dropped" means not all frames are decode display in time.
    You could try to check are the frames are dropped by decoder or some other element in you pipeline.

    BR
    Margarita