Как повторить воспроизведение интернет радио, если радио отключалось на время?

Я хочу воспроизводить музыку с помощью gstreamer. И подключаюсь к интернет радио. Сначала воспроизводит, но если я отключу интернет радио на стороне сервера, и включу через какое то время, то поток не будет воспроизводиться.

static int init_new_gst (  ) {

    gst.pipeline = gst_pipeline_new ( "radio" );
    gst.source = gst_element_factory_make ( "souphttpsrc", NULL );
    gst.demuxer = gst_element_factory_make ( "decodebin", NULL );
    gst.decoder = gst_element_factory_make ( "audioconvert", NULL );
    gst.volume = gst_element_factory_make ( "volume", NULL );
    gst.conv = gst_element_factory_make ( "audioconvert", NULL );
    gst.sink = gst_element_factory_make ( "autoaudiosink", NULL );

    gst_bin_add_many ( GST_BIN ( gst.pipeline ),
            gst.source,
            gst.demuxer,
            gst.decoder,
            gst.volume,
            gst.conv,
            gst.sink,
            NULL
            );

    gst_element_link ( gst.source, gst.demuxer );
    gst_element_link_many ( gst.decoder, gst.volume, gst.conv, gst.sink, NULL );
    g_signal_connect ( gst.demuxer, "pad-added", G_CALLBACK ( gst_demuxer_pad_added_cb ), NULL );

    g_object_set ( gst.source, "location", "http://localhost:8000/stream", NULL );
    g_object_set ( gst.source, "iradio-mode", TRUE, NULL );
    g_object_set ( gst.source, "retries", -1, NULL );
    //g_object_set ( gst.source, "location", "http://radio.abcmusic.kz/ladushkishop", NULL );
    g_object_set ( gst.volume, "volume", 1.0, NULL );

    int ret = gst_element_set_state ( gst.pipeline, GST_STATE_PLAYING );
    if ( ret == GST_STATE_CHANGE_NO_PREROLL ) {
        gst.is_live = TRUE;
    } else {
        gst.is_live = FALSE;
    }

    GstMessage *msg;
    gst.bus = gst_pipeline_get_bus ( GST_PIPELINE ( gst.pipeline ) );
    gst_bus_add_signal_watch ( gst.bus );
    g_signal_connect ( gst.bus, "message", G_CALLBACK ( cb_message ), NULL );
    msg = gst_bus_poll ( gst.bus, GST_MESSAGE_ERROR, 0 );
    if ( msg ) {
        GError *error = NULL;
        gst_message_parse_error ( msg, &error, NULL );
        g_print ( "error: %s\n", error->message );
        g_error_free ( error );
        gst_message_unref ( msg );
    }
    return gst.is_live;
}

static gboolean func_handle ( gpointer data ) {

    GstState state, pending;
    gst_element_get_state ( gst.pipeline, &state, &pending, 1 );

    switch ( state ) {
        case GST_STATE_VOID_PENDING: printf ( "0\n" ); break;
        case GST_STATE_NULL: printf ( "1\n" ); break;
        case GST_STATE_READY:{ 
                        printf ( "2\n" ); 
                    g_object_set ( gst.source, "location", "http://localhost:8000/stream", NULL );
                        int ret = gst_element_set_state ( gst.pipeline, GST_STATE_PLAYING ); 
                    if ( ret == GST_STATE_CHANGE_NO_PREROLL ) {
                        printf ( "live true\n" );
                        gst.is_live = TRUE;
                    } else if ( ret == GST_STATE_CHANGE_FAILURE ) {
                        printf ( "live failure\n" );
                    } else if ( ret == GST_STATE_CHANGE_SUCCESS ) {
                        printf ( "live success\n" );
                    } else if ( ret == GST_STATE_CHANGE_ASYNC ) {
                        printf ( "live async\n" );
                    } else {
                        printf ( "live false\n" );
                        gst.is_live = FALSE;
                    }
                     }
                    break;
        case GST_STATE_PAUSED: {
                    printf ( "3\n" ); 
                    g_object_set ( gst.source, "location", "http://localhost:8000/stream", NULL );
                        int ret = gst_element_set_state ( gst.pipeline, GST_STATE_PLAYING ); 
                    if ( ret == GST_STATE_CHANGE_NO_PREROLL ) {
                        printf ( "live true\n" );
                        gst.is_live = TRUE;
                    } else {
                        printf ( "live false\n" );
                        gst.is_live = FALSE;
                    }
                    break;
                       }
        case GST_STATE_PLAYING: printf ( "4\n" ); break;
    }

    return TRUE;
}

выводит следующий текст

eos
2
live async
type error
error: from souphttpsrc0 File Not Found
type error
error: from souphttpsrc0 Internal data stream error.
type error
error: from typefind Stream doesn't contain enough data.
2
live async
2
live async


Ответы (0 шт):