--- libavformat/rtp.c | 10 ++++---- libavformat/rtp.h | 4 ++-- libavformat/rtsp.c | 68 ++++++++++++++++++++++++++++++------------------------ 3 files changed, 45 insertions(+), 37 deletions(-)
diff --git a/libavformat/rtp.c b/libavformat/rtp.c index 2c9284b..5eb92e4 100644 --- a/libavformat/rtp.c +++ b/libavformat/rtp.c @@ -67,19 +67,19 @@ static const struct { {-1, "", AVMEDIA_TYPE_UNKNOWN, AV_CODEC_ID_NONE, -1, -1} }; -int ff_rtp_get_codec_info(AVCodecContext *codec, int payload_type) +int ff_rtp_get_codec_info(AVCodecParameters *par, int payload_type) { int i = 0; for (i = 0; rtp_payload_types[i].pt >= 0; i++) if (rtp_payload_types[i].pt == payload_type) { if (rtp_payload_types[i].codec_id != AV_CODEC_ID_NONE) { - codec->codec_type = rtp_payload_types[i].codec_type; - codec->codec_id = rtp_payload_types[i].codec_id; + par->codec_type = rtp_payload_types[i].codec_type; + par->codec_id = rtp_payload_types[i].codec_id; if (rtp_payload_types[i].audio_channels > 0) - codec->channels = rtp_payload_types[i].audio_channels; + par->channels = rtp_payload_types[i].audio_channels; if (rtp_payload_types[i].clock_rate > 0) - codec->sample_rate = rtp_payload_types[i].clock_rate; + par->sample_rate = rtp_payload_types[i].clock_rate; return 0; } } diff --git a/libavformat/rtp.h b/libavformat/rtp.h index d1bd123..01b83df 100644 --- a/libavformat/rtp.h +++ b/libavformat/rtp.h @@ -46,12 +46,12 @@ int ff_rtp_get_payload_type(AVFormatContext *fmt, AVCodecParameters *par, * information depending on the payload type; for audio codecs, the * channels and sample_rate fields are also filled. * - * @param codec The context of the codec + * @param par The codec parameters * @param payload_type The payload type (the 'PT' field in the RTP header) * @return In case of unknown payload type or dynamic payload type, a * negative value is returned; otherwise, 0 is returned */ -int ff_rtp_get_codec_info(AVCodecContext *codec, int payload_type); +int ff_rtp_get_codec_info(AVCodecParameters *par, int payload_type); /** * Return the encoding name (as defined in diff --git a/libavformat/rtsp.c b/libavformat/rtsp.c index 4beb275..2f98fe5 100644 --- a/libavformat/rtsp.c +++ b/libavformat/rtsp.c @@ -200,11 +200,11 @@ static int get_sockaddr(AVFormatContext *s, static void init_rtp_handler(RTPDynamicProtocolHandler *handler, RTSPStream *rtsp_st, AVStream *st) { - AVCodecContext *codec = st ? st->codec : NULL; + AVCodecParameters *par = st ? st->codecpar : NULL; if (!handler) return; - if (codec) - codec->codec_id = handler->codec_id; + if (par) + par->codec_id = handler->codec_id; rtsp_st->dynamic_handler = handler; if (st) st->need_parsing = handler->need_parsing; @@ -239,7 +239,7 @@ static int sdp_parse_rtpmap(AVFormatContext *s, AVStream *st, RTSPStream *rtsp_st, int payload_type, const char *p) { - AVCodecContext *codec = st->codec; + AVCodecParameters *par = st->codecpar; char buf[256]; int i; AVCodec *c; @@ -253,22 +253,22 @@ static int sdp_parse_rtpmap(AVFormatContext *s, if (payload_type < RTP_PT_PRIVATE) { /* We are in a standard case * (from http://www.iana.org/assignments/rtp-parameters). */ - codec->codec_id = ff_rtp_codec_id(buf, codec->codec_type); + par->codec_id = ff_rtp_codec_id(buf, par->codec_type); } - if (codec->codec_id == AV_CODEC_ID_NONE) { + if (par->codec_id == AV_CODEC_ID_NONE) { RTPDynamicProtocolHandler *handler = - ff_rtp_handler_find_by_name(buf, codec->codec_type); + ff_rtp_handler_find_by_name(buf, par->codec_type); init_rtp_handler(handler, rtsp_st, st); /* If no dynamic handler was found, check with the list of standard * allocated types, if such a stream for some reason happens to * use a private payload type. This isn't handled in rtpdec.c, since * the format name from the rtpmap line never is passed into rtpdec. */ if (!rtsp_st->dynamic_handler) - codec->codec_id = ff_rtp_codec_id(buf, codec->codec_type); + par->codec_id = ff_rtp_codec_id(buf, par->codec_type); } - c = avcodec_find_decoder(codec->codec_id); + c = avcodec_find_decoder(par->codec_id); if (c && c->name) c_name = c->name; else @@ -276,23 +276,23 @@ static int sdp_parse_rtpmap(AVFormatContext *s, get_word_sep(buf, sizeof(buf), "/", &p); i = atoi(buf); - switch (codec->codec_type) { + switch (par->codec_type) { case AVMEDIA_TYPE_AUDIO: av_log(s, AV_LOG_DEBUG, "audio codec set to: %s\n", c_name); - codec->sample_rate = RTSP_DEFAULT_AUDIO_SAMPLERATE; - codec->channels = RTSP_DEFAULT_NB_AUDIO_CHANNELS; + par->sample_rate = RTSP_DEFAULT_AUDIO_SAMPLERATE; + par->channels = RTSP_DEFAULT_NB_AUDIO_CHANNELS; if (i > 0) { - codec->sample_rate = i; - avpriv_set_pts_info(st, 32, 1, codec->sample_rate); + par->sample_rate = i; + avpriv_set_pts_info(st, 32, 1, par->sample_rate); get_word_sep(buf, sizeof(buf), "/", &p); i = atoi(buf); if (i > 0) - codec->channels = i; + par->channels = i; } av_log(s, AV_LOG_DEBUG, "audio samplerate set to: %i\n", - codec->sample_rate); + par->sample_rate); av_log(s, AV_LOG_DEBUG, "audio channels set to: %i\n", - codec->channels); + par->channels); break; case AVMEDIA_TYPE_VIDEO: av_log(s, AV_LOG_DEBUG, "video codec set to: %s\n", c_name); @@ -495,17 +495,17 @@ static void sdp_parse_line(AVFormatContext *s, SDPParseState *s1, return; st->id = rt->nb_rtsp_streams - 1; rtsp_st->stream_index = st->index; - st->codec->codec_type = codec_type; + st->codecpar->codec_type = codec_type; if (rtsp_st->sdp_payload_type < RTP_PT_PRIVATE) { RTPDynamicProtocolHandler *handler; /* if standard payload type, we can find the codec right now */ - ff_rtp_get_codec_info(st->codec, rtsp_st->sdp_payload_type); - if (st->codec->codec_type == AVMEDIA_TYPE_AUDIO && - st->codec->sample_rate > 0) - avpriv_set_pts_info(st, 32, 1, st->codec->sample_rate); + ff_rtp_get_codec_info(st->codecpar, rtsp_st->sdp_payload_type); + if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO && + st->codecpar->sample_rate > 0) + avpriv_set_pts_info(st, 32, 1, st->codecpar->sample_rate); /* Even static payload types may need a custom depacketizer */ handler = ff_rtp_handler_find_by_id( - rtsp_st->sdp_payload_type, st->codec->codec_type); + rtsp_st->sdp_payload_type, st->codecpar->codec_type); init_rtp_handler(handler, rtsp_st, st); finalize_rtp_handler_init(s, rtsp_st, st); } @@ -590,7 +590,7 @@ static void sdp_parse_line(AVFormatContext *s, SDPParseState *s1, } else if (av_strstart(p, "SampleRate:integer;", &p) && s->nb_streams > 0) { st = s->streams[s->nb_streams - 1]; - st->codec->sample_rate = atoi(p); + st->codecpar->sample_rate = atoi(p); } else if (av_strstart(p, "crypto:", &p) && s->nb_streams > 0) { // RFC 4568 rtsp_st = rt->rtsp_streams[rt->nb_rtsp_streams - 1]; @@ -1498,7 +1498,7 @@ int ff_rtsp_make_setup_request(AVFormatContext *s, const char *host, int port, * will return an error. Therefore, we skip those streams. */ if (rt->server_type == RTSP_SERVER_WMS && (rtsp_st->stream_index < 0 || - s->streams[rtsp_st->stream_index]->codec->codec_type == + s->streams[rtsp_st->stream_index]->codecpar->codec_type == AVMEDIA_TYPE_DATA)) continue; snprintf(transport, sizeof(transport) - 1, @@ -2356,7 +2356,7 @@ static int rtp_read_header(AVFormatContext *s) int ret, port; URLContext* in = NULL; int payload_type; - AVCodecContext codec = { 0 }; + AVCodecParameters *par = NULL; struct sockaddr_storage addr; AVIOContext pb; socklen_t addrlen = sizeof(addr); @@ -2397,13 +2397,19 @@ static int rtp_read_header(AVFormatContext *s) ffurl_close(in); in = NULL; - if (ff_rtp_get_codec_info(&codec, payload_type)) { + par = avcodec_parameters_alloc(); + if (!par) { + ret = AVERROR(ENOMEM); + goto fail; + } + + if (ff_rtp_get_codec_info(par, payload_type)) { av_log(s, AV_LOG_ERROR, "Unable to receive RTP payload type %d " "without an SDP file describing it\n", payload_type); goto fail; } - if (codec.codec_type != AVMEDIA_TYPE_DATA) { + if (par->codec_type != AVMEDIA_TYPE_DATA) { av_log(s, AV_LOG_WARNING, "Guessing on RTP content - if not received " "properly you need an SDP file " "describing it\n"); @@ -2415,10 +2421,11 @@ static int rtp_read_header(AVFormatContext *s) snprintf(sdp, sizeof(sdp), "v=0\r\nc=IN IP%d %s\r\nm=%s %d RTP/AVP %d\r\n", addr.ss_family == AF_INET ? 4 : 6, host, - codec.codec_type == AVMEDIA_TYPE_DATA ? "application" : - codec.codec_type == AVMEDIA_TYPE_VIDEO ? "video" : "audio", + par->codec_type == AVMEDIA_TYPE_DATA ? "application" : + par->codec_type == AVMEDIA_TYPE_VIDEO ? "video" : "audio", port, payload_type); av_log(s, AV_LOG_VERBOSE, "SDP:\n%s\n", sdp); + avcodec_parameters_free(&par); ffio_init_context(&pb, sdp, strlen(sdp), 0, NULL, NULL, NULL, NULL); s->pb = &pb; @@ -2433,6 +2440,7 @@ static int rtp_read_header(AVFormatContext *s) return ret; fail: + avcodec_parameters_free(&par); if (in) ffurl_close(in); ff_network_close(); -- 2.0.0 _______________________________________________ libav-devel mailing list libav-devel@libav.org https://lists.libav.org/mailman/listinfo/libav-devel