-static int rtsp_read_play(AVFormatContext *s)
-{
- RTSPState *rt = s->priv_data;
- RTSPMessageHeader reply1, *reply = &reply1;
- int i;
- char cmd[1024];
-
- av_log(s, AV_LOG_DEBUG, "hello state=%d\n", rt->state);
- rt->nb_byes = 0;
-
- if (!(rt->server_type == RTSP_SERVER_REAL && rt->need_subscription)) {
- if (rt->state == RTSP_STATE_PAUSED) {
- cmd[0] = 0;
- } else {
- snprintf(cmd, sizeof(cmd),
- "Range: npt=%0.3f-\r\n",
- (double)rt->seek_timestamp / AV_TIME_BASE);
- }
- ff_rtsp_send_cmd(s, "PLAY", rt->control_uri, cmd, reply, NULL);
- if (reply->status_code != RTSP_STATUS_OK) {
- return -1;
- }
- if (rt->transport == RTSP_TRANSPORT_RTP) {
- for (i = 0; i < rt->nb_rtsp_streams; i++) {
- RTSPStream *rtsp_st = rt->rtsp_streams[i];
- RTPDemuxContext *rtpctx = rtsp_st->transport_priv;
- AVStream *st = NULL;
- if (!rtpctx)
- continue;
- if (rtsp_st->stream_index >= 0)
- st = s->streams[rtsp_st->stream_index];
- ff_rtp_reset_packet_queue(rtpctx);
- if (reply->range_start != AV_NOPTS_VALUE) {
- rtpctx->last_rtcp_ntp_time = AV_NOPTS_VALUE;
- rtpctx->first_rtcp_ntp_time = AV_NOPTS_VALUE;
- if (st)
- rtpctx->range_start_offset =
- av_rescale_q(reply->range_start, AV_TIME_BASE_Q,
- st->time_base);
- }
- }
- }
- }
- rt->state = RTSP_STATE_STREAMING;
- return 0;
-}
-
-static int rtsp_setup_input_streams(AVFormatContext *s, RTSPMessageHeader *reply)
-{
- RTSPState *rt = s->priv_data;
- char cmd[1024];
- unsigned char *content = NULL;
- int ret;
-
- /* describe the stream */
- snprintf(cmd, sizeof(cmd),
- "Accept: application/sdp\r\n");
- if (rt->server_type == RTSP_SERVER_REAL) {
- /**
- * The Require: attribute is needed for proper streaming from
- * Realmedia servers.
- */
- av_strlcat(cmd,
- "Require: com.real.retain-entity-for-setup\r\n",
- sizeof(cmd));
- }
- ff_rtsp_send_cmd(s, "DESCRIBE", rt->control_uri, cmd, reply, &content);
- if (!content)
- return AVERROR_INVALIDDATA;
- if (reply->status_code != RTSP_STATUS_OK) {
- av_freep(&content);
- return AVERROR_INVALIDDATA;
- }
-
- av_log(s, AV_LOG_VERBOSE, "SDP:\n%s\n", content);
- /* now we got the SDP description, we parse it */
- ret = sdp_parse(s, (const char *)content);
- av_freep(&content);
- if (ret < 0)
- return AVERROR_INVALIDDATA;
-
- return 0;
-}
-
-static int rtsp_setup_output_streams(AVFormatContext *s, const char *addr)
-{
- RTSPState *rt = s->priv_data;
- RTSPMessageHeader reply1, *reply = &reply1;
- int i;
- char *sdp;
- AVFormatContext sdp_ctx, *ctx_array[1];
-
- rt->start_time = av_gettime();
-
- /* Announce the stream */
- sdp = av_mallocz(SDP_MAX_SIZE);
- if (sdp == NULL)
- return AVERROR(ENOMEM);
- /* We create the SDP based on the RTSP AVFormatContext where we
- * aren't allowed to change the filename field. (We create the SDP
- * based on the RTSP context since the contexts for the RTP streams
- * don't exist yet.) In order to specify a custom URL with the actual
- * peer IP instead of the originally specified hostname, we create
- * a temporary copy of the AVFormatContext, where the custom URL is set.
- *
- * FIXME: Create the SDP without copying the AVFormatContext.
- * This either requires setting up the RTP stream AVFormatContexts
- * already here (complicating things immensely) or getting a more
- * flexible SDP creation interface.
- */
- sdp_ctx = *s;
- ff_url_join(sdp_ctx.filename, sizeof(sdp_ctx.filename),
- "rtsp", NULL, addr, -1, NULL);
- ctx_array[0] = &sdp_ctx;
- if (avf_sdp_create(ctx_array, 1, sdp, SDP_MAX_SIZE)) {
- av_free(sdp);
- return AVERROR_INVALIDDATA;
- }
- av_log(s, AV_LOG_VERBOSE, "SDP:\n%s\n", sdp);
- ff_rtsp_send_cmd_with_content(s, "ANNOUNCE", rt->control_uri,
- "Content-Type: application/sdp\r\n",
- reply, NULL, sdp, strlen(sdp));
- av_free(sdp);
- if (reply->status_code != RTSP_STATUS_OK)
- return AVERROR_INVALIDDATA;
-
- /* Set up the RTSPStreams for each AVStream */
- for (i = 0; i < s->nb_streams; i++) {
- RTSPStream *rtsp_st;
- AVStream *st = s->streams[i];
-
- rtsp_st = av_mallocz(sizeof(RTSPStream));
- if (!rtsp_st)
- return AVERROR(ENOMEM);
- dynarray_add(&rt->rtsp_streams, &rt->nb_rtsp_streams, rtsp_st);
-
- st->priv_data = rtsp_st;
- rtsp_st->stream_index = i;
-
- av_strlcpy(rtsp_st->control_url, rt->control_uri, sizeof(rtsp_st->control_url));
- /* Note, this must match the relative uri set in the sdp content */
- av_strlcatf(rtsp_st->control_url, sizeof(rtsp_st->control_url),
- "/streamid=%d", i);
- }
-
- return 0;
-}
-