*** gstrtspsrc.c 2011-01-06 11:38:56.000000000 +0000 --- gstrtspsrc_redirect.c 2011-02-28 16:20:23.000000000 +0000 *************** *** 4364,4370 **** --- 4364,4376 ---- if (code != NULL) *code = int_code; else if (int_code != GST_RTSP_STS_OK) + goto error_response; + // Do we need to force a loading of the new address ? + if (int_code == GST_RTSP_STS_MULTIPLE_CHOICES) + { + GST_INFO("goto error_response MULTIPLE CHOICES"); goto error_response; + } return res; *************** *** 4383,4388 **** --- 4389,4431 ---- GST_ELEMENT_ERROR (src, RESOURCE, NOT_FOUND, (NULL), ("%s", response->type_data.response.reason)); break; + case GST_RTSP_STS_MULTIPLE_CHOICES: + { + /* similar to MOVED_PERMANENTLY or MOVE_TEMPORARILY except we don't want to change the uri yet, just store it */ + gchar *new_location; + GstRTSPLowerTrans transports; + + GST_DEBUG_OBJECT (src, "got redirection"); + GST_INFO("got redirection"); + /* if we don't have a Location Header, we must error */ + if (gst_rtsp_message_get_header (response, GST_RTSP_HDR_LOCATION, + &new_location, 0) < 0) + { + GST_INFO("Ooops no Location Header"); + } + + GST_INFO("Source Address %p", src); + src->addr = g_strdup (new_location); + GST_INFO("Redirect to [ %s ]", src->addr); + + /* save current transports */ + if (src->conninfo.url) + transports = src->conninfo.url->transports; + else + transports = GST_RTSP_LOWER_TRANS_UNKNOWN; + + gst_rtspsrc_uri_set_uri (GST_URI_HANDLER (src), new_location); + + /* set old transports */ + if (src->conninfo.url && transports != GST_RTSP_LOWER_TRANS_UNKNOWN) + src->conninfo.url->transports = transports; + + src->need_redirect = TRUE; + src->state = GST_RTSP_STATE_INIT; + res = GST_RTSP_OK; + } + break; + case GST_RTSP_STS_MOVED_PERMANENTLY: case GST_RTSP_STS_MOVE_TEMPORARILY: { *************** *** 4873,4878 **** --- 4916,4926 ---- switch (code) { case GST_RTSP_STS_OK: break; + case GST_RTSP_STS_MULTIPLE_CHOICES : + GST_INFO("GST_RTSP_STS_MULTIPLE_CHOICES in %s", __FUNCTION__ ); + goto multi_choices; + break; + case GST_RTSP_STS_UNSUPPORTED_TRANSPORT: gst_rtsp_message_unset (&request); gst_rtsp_message_unset (&response); *************** *** 5058,5063 **** --- 5106,5116 ---- gst_rtsp_message_unset (&response); return FALSE; } + //New return, act as if nothing is wrong it will be handled in the gst_rtspsrc_open fn + multi_choices: + { + return FALSE; + } } static gboolean *************** *** 5408,5413 **** --- 5461,5468 ---- { gboolean res; + retry: + src->methods = GST_RTSP_SETUP | GST_RTSP_PLAY | GST_RTSP_PAUSE | GST_RTSP_TEARDOWN; *************** *** 5436,5441 **** --- 5491,5520 ---- { GST_WARNING_OBJECT (src, "can't setup streaming from sdp"); GST_RTSP_STATE_UNLOCK (src); + if ( src->need_redirect ) + { + //Lets emit a message to the playbin..... + GstStructure *messageStruct; + GstMessage *message; + + gchar * uri = g_strdup (src->addr); + + messageStruct = gst_structure_new ("redirect_message", + "uri", G_TYPE_STRING, uri, + NULL); + + message = gst_message_new_element (GST_OBJECT (src), messageStruct); + gst_element_post_message (GST_ELEMENT(src), message); + + printf("Going to redirect to [ %s ]\n", uri); + + gst_rtspsrc_close(src); + //We are being asked to redirect. + gst_rtspsrc_uri_set_uri (GST_URI_HANDLER (src), + src->addr); + goto retry; + + } return FALSE; } }