X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=libavformat%2Frtpdec_asf.c;h=483b196d6208e251ca54368dea3154434f1a584b;hb=f7de52354fe15ba7cae141b44ffdd01e560f0e47;hp=d63d705b418a28db21a461d2f0ec805445549735;hpb=bcc4cb4681aaf04bff1d10eee1eb24ae5ba7fb82;p=ffmpeg diff --git a/libavformat/rtpdec_asf.c b/libavformat/rtpdec_asf.c index d63d705b418..483b196d620 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 */ @@ -29,9 +29,11 @@ #include "libavutil/avstring.h" #include "libavutil/intreadwrite.h" #include "rtp.h" -#include "rtpdec_asf.h" +#include "rtpdec_formats.h" #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 @@ -72,7 +74,7 @@ static int rtp_asf_fix_header(uint8_t *buf, int len) } /** - * The following code is basically a buffered ByteIOContext, + * The following code is basically a buffered AVIOContext, * with the added benefit of returning -EAGAIN (instead of 0) * on packet boundaries, such that the ASF demuxer can return * safely and resume business at the next packet. @@ -82,9 +84,9 @@ static int packetizer_read(void *opaque, uint8_t *buf, int buf_size) return AVERROR(EAGAIN); } -static void init_packetizer(ByteIOContext *pb, uint8_t *buf, int len) +static void init_packetizer(AVIOContext *pb, uint8_t *buf, int len) { - init_put_byte(pb, buf, len, 0, NULL, packetizer_read, NULL, NULL); + ffio_init_context(pb, buf, len, 0, NULL, packetizer_read, NULL, NULL); /* this "fills" the buffer with its current content */ pb->pos = len; @@ -95,7 +97,7 @@ int ff_wms_parse_sdp_a_line(AVFormatContext *s, const char *p) { int ret = 0; if (av_strstart(p, "pgmpu:data:application/vnd.ms.wms-hdr.asfv1;base64,", &p)) { - ByteIOContext pb; + AVIOContext pb; RTSPState *rt = s->priv_data; int len = strlen(p) * 6 / 8; char *buf = av_mallocz(len); @@ -106,13 +108,16 @@ 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); } - ret = av_open_input_stream(&rt->asf_ctx, &pb, "", &asf_demuxer, NULL); + if (!(rt->asf_ctx = avformat_alloc_context())) + return AVERROR(ENOMEM); + rt->asf_ctx->pb = &pb; + ret = avformat_open_input(&rt->asf_ctx, "", &ff_asf_demuxer, NULL); if (ret < 0) return ret; - rt->asf_pb_pos = url_ftell(&pb); + 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; } @@ -136,7 +141,7 @@ static int asfrtp_parse_sdp_line(AVFormatContext *s, int stream_index, *rt->asf_ctx->streams[i]->codec; 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); } } } @@ -146,7 +151,7 @@ static int asfrtp_parse_sdp_line(AVFormatContext *s, int stream_index, } struct PayloadContext { - ByteIOContext *pktbuf, pb; + AVIOContext *pktbuf, pb; uint8_t *buf; }; @@ -160,7 +165,7 @@ static int asfrtp_parse_packet(AVFormatContext *s, PayloadContext *asf, uint32_t *timestamp, const uint8_t *buf, int len, int flags) { - ByteIOContext *pb = &asf->pb; + AVIOContext *pb = &asf->pb; int res, mflags, len_off; RTSPState *rt = s->priv_data; @@ -175,63 +180,71 @@ static int asfrtp_parse_packet(AVFormatContext *s, PayloadContext *asf, av_freep(&asf->buf); - init_put_byte(pb, buf, len, 0, NULL, NULL, NULL, NULL); - - while (url_ftell(pb) + 4 < len) { - int start_off = url_ftell(pb); - - mflags = get_byte(pb); - if (mflags & 0x80) - flags |= RTP_FLAG_KEY; - len_off = get_be24(pb); - if (mflags & 0x20) /**< relative timestamp */ - url_fskip(pb, 4); - if (mflags & 0x10) /**< has duration */ - url_fskip(pb, 4); - if (mflags & 0x8) /**< has location ID */ - url_fskip(pb, 4); - off = url_ftell(pb); - - if (!(mflags & 0x40)) { - /** - * If 0x40 is not set, the len_off field specifies an offset of this - * packet's payload data in the complete (reassembled) ASF packet. - * This is used to spread one ASF packet over multiple RTP packets. - */ - if (asf->pktbuf && len_off != url_ftell(asf->pktbuf)) { - uint8_t *p; - url_close_dyn_buf(asf->pktbuf, &p); + ffio_init_context(pb, buf, len, 0, NULL, NULL, NULL, NULL); + + while (avio_tell(pb) + 4 < len) { + 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_skip(pb, 4); + if (mflags & 0x10) /**< has duration */ + avio_skip(pb, 4); + if (mflags & 0x8) /**< has location ID */ + avio_skip(pb, 4); + off = avio_tell(pb); + + if (!(mflags & 0x40)) { + /** + * If 0x40 is not set, the len_off field specifies an offset + * of this packet's payload data in the complete (reassembled) + * ASF packet. This is used to spread one ASF packet over + * multiple RTP packets. + */ + if (asf->pktbuf && len_off != avio_tell(asf->pktbuf)) { + uint8_t *p; + avio_close_dyn_buf(asf->pktbuf, &p); + asf->pktbuf = NULL; + av_free(p); + } + if (!len_off && !asf->pktbuf && + (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_skip(pb, len - off); + if (!(flags & RTP_FLAG_MARKER)) + return -1; + out_len = avio_close_dyn_buf(asf->pktbuf, &asf->buf); asf->pktbuf = NULL; - av_free(p); + } else { + /** + * If 0x40 is set, the len_off field specifies the length of + * the next ASF packet that can be read from this payload + * data alone. This is commonly the same as the payload size, + * but could be less in case of packet splitting (i.e. + * multiple ASF packets in one RTP packet). + */ + + int cur_len = start_off + len_off - off; + int prev_len = out_len; + void *newmem; + out_len += cur_len; + if (FFMIN(cur_len, len - off) < 0) + return -1; + newmem = av_realloc(asf->buf, out_len); + if (!newmem) + return -1; + asf->buf = newmem; + memcpy(asf->buf + prev_len, buf + off, + FFMIN(cur_len, len - off)); + avio_skip(pb, cur_len); } - if (!len_off && !asf->pktbuf && - (res = url_open_dyn_buf(&asf->pktbuf)) < 0) - return res; - if (!asf->pktbuf) - return AVERROR(EIO); - - put_buffer(asf->pktbuf, buf + off, len - off); - url_fskip(pb, len - off); - if (!(flags & RTP_FLAG_MARKER)) - return -1; - out_len = url_close_dyn_buf(asf->pktbuf, &asf->buf); - asf->pktbuf = NULL; - } else { - /** - * If 0x40 is set, the len_off field specifies the length of the - * next ASF packet that can be read from this payload data alone. - * This is commonly the same as the payload size, but could be - * less in case of packet splitting (i.e. multiple ASF packets in - * one RTP packet). - */ - - 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); - memcpy(asf->buf + prev_len, buf + off, cur_len); - url_fskip(pb, cur_len); - } } init_packetizer(pb, asf->buf, out_len); @@ -244,7 +257,7 @@ static int asfrtp_parse_packet(AVFormatContext *s, PayloadContext *asf, int i; res = av_read_packet(rt->asf_ctx, pkt); - rt->asf_pb_pos = url_ftell(pb); + rt->asf_pb_pos = avio_tell(pb); if (res != 0) break; for (i = 0; i < s->nb_streams; i++) { @@ -268,7 +281,7 @@ static void asfrtp_free_context(PayloadContext *asf) { if (asf->pktbuf) { uint8_t *p = NULL; - url_close_dyn_buf(asf->pktbuf, &p); + avio_close_dyn_buf(asf->pktbuf, &p); asf->pktbuf = NULL; av_free(p); } @@ -282,10 +295,10 @@ RTPDynamicProtocolHandler ff_ms_rtp_ ## n ## _handler = { \ .codec_type = t, \ .codec_id = CODEC_ID_NONE, \ .parse_sdp_a_line = asfrtp_parse_sdp_line, \ - .open = asfrtp_new_context, \ - .close = asfrtp_free_context, \ + .alloc = asfrtp_new_context, \ + .free = asfrtp_free_context, \ .parse_packet = asfrtp_parse_packet, \ -}; +} RTP_ASF_HANDLER(asf_pfv, "x-asf-pf", AVMEDIA_TYPE_VIDEO); RTP_ASF_HANDLER(asf_pfa, "x-asf-pf", AVMEDIA_TYPE_AUDIO);