X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=libavformat%2Frtpdec_asf.c;h=597f29fae3338f47463692411676eca38177d6d0;hb=f890677d05bc4e8b494a73373ab4cc19791bf884;hp=8c4969111c114dd913b1d3161ae6229d95bf4d13;hpb=a2704c9712ad35cc22e7e0d8a79b581c07fa383b;p=ffmpeg diff --git a/libavformat/rtpdec_asf.c b/libavformat/rtpdec_asf.c index 8c4969111c1..597f29fae33 100644 --- a/libavformat/rtpdec_asf.c +++ b/libavformat/rtpdec_asf.c @@ -2,20 +2,20 @@ * Microsoft RTP/ASF support. * Copyright (c) 2008 Ronald S. Bultje * - * This file is part of FFmpeg. + * This file is part of Libav. * - * FFmpeg is free software; you can redistribute it and/or + * Libav is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * - * FFmpeg is distributed in the hope that it will be useful, + * Libav is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public - * License along with FFmpeg; if not, write to the Free Software + * License along with Libav; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ @@ -33,6 +33,7 @@ #include "rtsp.h" #include "asf.h" #include "avio_internal.h" +#include "internal.h" /** * From MSDN 2.2.1.4, we learn that ASF data packets over RTP should not @@ -98,8 +99,12 @@ int ff_wms_parse_sdp_a_line(AVFormatContext *s, const char *p) if (av_strstart(p, "pgmpu:data:application/vnd.ms.wms-hdr.asfv1;base64,", &p)) { AVIOContext pb; RTSPState *rt = s->priv_data; + AVDictionary *opts = NULL; int len = strlen(p) * 6 / 8; char *buf = av_mallocz(len); + + if (!buf) + return AVERROR(ENOMEM); av_base64_decode(buf, p, len); if (rtp_asf_fix_header(buf, len) < 0) @@ -107,13 +112,22 @@ int ff_wms_parse_sdp_a_line(AVFormatContext *s, const char *p) "Failed to fix invalid RTSP-MS/ASF min_pktsize\n"); init_packetizer(&pb, buf, len); if (rt->asf_ctx) { - av_close_input_stream(rt->asf_ctx); - rt->asf_ctx = NULL; + avformat_close_input(&rt->asf_ctx); + } + rt->asf_ctx = avformat_alloc_context(); + if (!rt->asf_ctx) { + av_free(buf); + return AVERROR(ENOMEM); } - ret = av_open_input_stream(&rt->asf_ctx, &pb, "", &ff_asf_demuxer, NULL); - if (ret < 0) + rt->asf_ctx->pb = &pb; + av_dict_set(&opts, "no_resync_search", "1", 0); + ret = avformat_open_input(&rt->asf_ctx, "", &ff_asf_demuxer, &opts); + av_dict_free(&opts); + if (ret < 0) { + av_free(buf); return ret; - av_metadata_copy(&s->metadata, rt->asf_ctx->metadata, 0); + } + av_dict_copy(&s->metadata, rt->asf_ctx->metadata, 0); rt->asf_pb_pos = avio_tell(&pb); av_free(buf); rt->asf_ctx->pb = NULL; @@ -124,6 +138,8 @@ int ff_wms_parse_sdp_a_line(AVFormatContext *s, const char *p) static int asfrtp_parse_sdp_line(AVFormatContext *s, int stream_index, PayloadContext *asf, const char *line) { + if (stream_index < 0) + return 0; if (av_strstart(line, "stream:", &line)) { RTSPState *rt = s->priv_data; @@ -136,9 +152,11 @@ static int asfrtp_parse_sdp_line(AVFormatContext *s, int stream_index, if (s->streams[stream_index]->id == rt->asf_ctx->streams[i]->id) { *s->streams[stream_index]->codec = *rt->asf_ctx->streams[i]->codec; + s->streams[stream_index]->need_parsing = + rt->asf_ctx->streams[i]->need_parsing; rt->asf_ctx->streams[i]->codec->extradata_size = 0; rt->asf_ctx->streams[i]->codec->extradata = NULL; - av_set_pts_info(s->streams[stream_index], 32, 1, 1000); + avpriv_set_pts_info(s->streams[stream_index], 32, 1, 1000); } } } @@ -160,7 +178,8 @@ struct PayloadContext { static int asfrtp_parse_packet(AVFormatContext *s, PayloadContext *asf, AVStream *st, AVPacket *pkt, uint32_t *timestamp, - const uint8_t *buf, int len, int flags) + const uint8_t *buf, int len, uint16_t seq, + int flags) { AVIOContext *pb = &asf->pb; int res, mflags, len_off; @@ -183,15 +202,13 @@ static int asfrtp_parse_packet(AVFormatContext *s, PayloadContext *asf, int start_off = avio_tell(pb); mflags = avio_r8(pb); - if (mflags & 0x80) - flags |= RTP_FLAG_KEY; len_off = avio_rb24(pb); if (mflags & 0x20) /**< relative timestamp */ - avio_seek(pb, 4, SEEK_CUR); + avio_skip(pb, 4); if (mflags & 0x10) /**< has duration */ - avio_seek(pb, 4, SEEK_CUR); + avio_skip(pb, 4); if (mflags & 0x8) /**< has location ID */ - avio_seek(pb, 4, SEEK_CUR); + avio_skip(pb, 4); off = avio_tell(pb); if (!(mflags & 0x40)) { @@ -202,22 +219,19 @@ static int asfrtp_parse_packet(AVFormatContext *s, PayloadContext *asf, * multiple RTP packets. */ if (asf->pktbuf && len_off != avio_tell(asf->pktbuf)) { - uint8_t *p; - url_close_dyn_buf(asf->pktbuf, &p); - asf->pktbuf = NULL; - av_free(p); + ffio_free_dyn_buf(&asf->pktbuf); } if (!len_off && !asf->pktbuf && - (res = url_open_dyn_buf(&asf->pktbuf)) < 0) + (res = avio_open_dyn_buf(&asf->pktbuf)) < 0) return res; if (!asf->pktbuf) return AVERROR(EIO); avio_write(asf->pktbuf, buf + off, len - off); - avio_seek(pb, len - off, SEEK_CUR); + avio_skip(pb, len - off); if (!(flags & RTP_FLAG_MARKER)) return -1; - out_len = url_close_dyn_buf(asf->pktbuf, &asf->buf); + out_len = avio_close_dyn_buf(asf->pktbuf, &asf->buf); asf->pktbuf = NULL; } else { /** @@ -231,10 +245,13 @@ static int asfrtp_parse_packet(AVFormatContext *s, PayloadContext *asf, int cur_len = start_off + len_off - off; int prev_len = out_len; out_len += cur_len; - asf->buf = av_realloc(asf->buf, out_len); + if (FFMIN(cur_len, len - off) < 0) + return -1; + if ((res = av_reallocp(&asf->buf, out_len)) < 0) + return res; memcpy(asf->buf + prev_len, buf + off, FFMIN(cur_len, len - off)); - avio_seek(pb, cur_len, SEEK_CUR); + avio_skip(pb, cur_len); } } @@ -247,7 +264,7 @@ static int asfrtp_parse_packet(AVFormatContext *s, PayloadContext *asf, for (;;) { int i; - res = av_read_packet(rt->asf_ctx, pkt); + res = ff_read_packet(rt->asf_ctx, pkt); rt->asf_pb_pos = avio_tell(pb); if (res != 0) break; @@ -263,31 +280,20 @@ static int asfrtp_parse_packet(AVFormatContext *s, PayloadContext *asf, return res == 1 ? -1 : res; } -static PayloadContext *asfrtp_new_context(void) +static void asfrtp_close_context(PayloadContext *asf) { - return av_mallocz(sizeof(PayloadContext)); -} - -static void asfrtp_free_context(PayloadContext *asf) -{ - if (asf->pktbuf) { - uint8_t *p = NULL; - url_close_dyn_buf(asf->pktbuf, &p); - asf->pktbuf = NULL; - av_free(p); - } + ffio_free_dyn_buf(&asf->pktbuf); av_freep(&asf->buf); - av_free(asf); } #define RTP_ASF_HANDLER(n, s, t) \ RTPDynamicProtocolHandler ff_ms_rtp_ ## n ## _handler = { \ .enc_name = s, \ .codec_type = t, \ - .codec_id = CODEC_ID_NONE, \ + .codec_id = AV_CODEC_ID_NONE, \ + .priv_data_size = sizeof(PayloadContext), \ .parse_sdp_a_line = asfrtp_parse_sdp_line, \ - .open = asfrtp_new_context, \ - .close = asfrtp_free_context, \ + .close = asfrtp_close_context, \ .parse_packet = asfrtp_parse_packet, \ }