Skip to content
Snippets Groups Projects
Commit ee0cb67f authored by Ronald S. Bultje's avatar Ronald S. Bultje
Browse files

Factorize out common code for opening of the RTP parsing context between

SDP and RTSP into a new function. See discussion on ML in "[PATCH] rtsp
cleanup part 1: remove duplicate code" thread.

Originally committed as revision 15297 to svn://svn.ffmpeg.org/ffmpeg/trunk
parent e09d7eef
No related branches found
No related tags found
No related merge requests found
...@@ -868,6 +868,30 @@ static void rtsp_close_streams(RTSPState *rt) ...@@ -868,6 +868,30 @@ static void rtsp_close_streams(RTSPState *rt)
av_free(rt->rtsp_streams); av_free(rt->rtsp_streams);
} }
static int
rtsp_open_transport_ctx(AVFormatContext *s, RTSPStream *rtsp_st)
{
AVStream *st = NULL;
/* open the RTP context */
if (rtsp_st->stream_index >= 0)
st = s->streams[rtsp_st->stream_index];
if (!st)
s->ctx_flags |= AVFMTCTX_NOHEADER;
rtsp_st->rtp_ctx = rtp_parse_open(s, st, rtsp_st->rtp_handle, rtsp_st->sdp_payload_type, &rtsp_st->rtp_payload_data);
if (!rtsp_st->rtp_ctx) {
return AVERROR(ENOMEM);
} else {
if(rtsp_st->dynamic_handler) {
rtsp_st->rtp_ctx->dynamic_protocol_context= rtsp_st->dynamic_protocol_context;
rtsp_st->rtp_ctx->parse_packet= rtsp_st->dynamic_handler->parse_packet;
}
}
return 0;
}
/** /**
* @returns 0 on success, <0 on error, 1 if protocol is unavailable. * @returns 0 on success, <0 on error, 1 if protocol is unavailable.
*/ */
...@@ -878,7 +902,6 @@ make_setup_request (AVFormatContext *s, const char *host, int port, ...@@ -878,7 +902,6 @@ make_setup_request (AVFormatContext *s, const char *host, int port,
RTSPState *rt = s->priv_data; RTSPState *rt = s->priv_data;
int j, i, err; int j, i, err;
RTSPStream *rtsp_st; RTSPStream *rtsp_st;
AVStream *st;
RTSPHeader reply1, *reply = &reply1; RTSPHeader reply1, *reply = &reply1;
char cmd[2048]; char cmd[2048];
const char *trans_pref; const char *trans_pref;
...@@ -1016,23 +1039,9 @@ make_setup_request (AVFormatContext *s, const char *host, int port, ...@@ -1016,23 +1039,9 @@ make_setup_request (AVFormatContext *s, const char *host, int port,
} }
break; break;
} }
/* open the RTP context */
st = NULL;
if (rtsp_st->stream_index >= 0)
st = s->streams[rtsp_st->stream_index];
if (!st)
s->ctx_flags |= AVFMTCTX_NOHEADER;
rtsp_st->rtp_ctx = rtp_parse_open(s, st, rtsp_st->rtp_handle, rtsp_st->sdp_payload_type, &rtsp_st->rtp_payload_data);
if (!rtsp_st->rtp_ctx) { if ((err = rtsp_open_transport_ctx(s, rtsp_st)))
err = AVERROR(ENOMEM);
goto fail; goto fail;
} else {
if(rtsp_st->dynamic_handler) {
rtsp_st->rtp_ctx->dynamic_protocol_context= rtsp_st->dynamic_protocol_context;
rtsp_st->rtp_ctx->parse_packet= rtsp_st->dynamic_handler->parse_packet;
}
}
} }
if (rt->server_type == RTSP_SERVER_RDT) if (rt->server_type == RTSP_SERVER_RDT)
...@@ -1509,7 +1518,6 @@ static int sdp_read_header(AVFormatContext *s, ...@@ -1509,7 +1518,6 @@ static int sdp_read_header(AVFormatContext *s,
int size, i, err; int size, i, err;
char *content; char *content;
char url[1024]; char url[1024];
AVStream *st;
/* read the whole sdp file */ /* read the whole sdp file */
/* XXX: better loading */ /* XXX: better loading */
...@@ -1537,22 +1545,8 @@ static int sdp_read_header(AVFormatContext *s, ...@@ -1537,22 +1545,8 @@ static int sdp_read_header(AVFormatContext *s,
err = AVERROR_INVALIDDATA; err = AVERROR_INVALIDDATA;
goto fail; goto fail;
} }
/* open the RTP context */ if ((err = rtsp_open_transport_ctx(s, rtsp_st)))
st = NULL;
if (rtsp_st->stream_index >= 0)
st = s->streams[rtsp_st->stream_index];
if (!st)
s->ctx_flags |= AVFMTCTX_NOHEADER;
rtsp_st->rtp_ctx = rtp_parse_open(s, st, rtsp_st->rtp_handle, rtsp_st->sdp_payload_type, &rtsp_st->rtp_payload_data);
if (!rtsp_st->rtp_ctx) {
err = AVERROR(ENOMEM);
goto fail; goto fail;
} else {
if(rtsp_st->dynamic_handler) {
rtsp_st->rtp_ctx->dynamic_protocol_context= rtsp_st->dynamic_protocol_context;
rtsp_st->rtp_ctx->parse_packet= rtsp_st->dynamic_handler->parse_packet;
}
}
} }
return 0; return 0;
fail: fail:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment