X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=libavformat%2Fmovenchint.c;h=5ef90f154ad420f8d1c3871036407f2ff6c47129;hb=681ed0009905a088aae2a5caf2308d89aaa80562;hp=fbc7faace6546badd05e70f6fb0c0997c5b34c03;hpb=77eb5504d3b3e1047900382350e0bc5e0bfb16b5;p=ffmpeg diff --git a/libavformat/movenchint.c b/libavformat/movenchint.c index fbc7faace65..5ef90f154ad 100644 --- a/libavformat/movenchint.c +++ b/libavformat/movenchint.c @@ -2,20 +2,20 @@ * MOV, 3GP, MP4 muxer RTP hinting * Copyright (c) 2010 Martin Storsjo * - * 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 */ @@ -23,6 +23,8 @@ #include "libavutil/intreadwrite.h" #include "internal.h" #include "rtpenc_chain.h" +#include "avio_internal.h" +#include "rtp.h" int ff_mov_init_hinting(AVFormatContext *s, int index, int src_index) { @@ -35,15 +37,15 @@ int ff_mov_init_hinting(AVFormatContext *s, int index, int src_index) track->tag = MKTAG('r','t','p',' '); track->src_track = src_index; - track->enc = avcodec_alloc_context(); + track->enc = avcodec_alloc_context3(NULL); if (!track->enc) goto fail; track->enc->codec_type = AVMEDIA_TYPE_DATA; track->enc->codec_tag = track->tag; - track->rtp_ctx = ff_rtp_chain_mux_open(s, src_st, NULL, - RTP_MAX_PACKET_SIZE); - if (!track->rtp_ctx) + ret = ff_rtp_chain_mux_open(&track->rtp_ctx, s, src_st, NULL, + RTP_MAX_PACKET_SIZE); + if (ret < 0) goto fail; /* Copy the RTP AVStream timebase back to the hint AVStream */ @@ -94,11 +96,12 @@ static void sample_queue_free(HintSampleQueue *queue) * not copied. sample_queue_retain should be called before pkt->data * is reused/freed. */ -static void sample_queue_push(HintSampleQueue *queue, AVPacket *pkt, int sample) +static void sample_queue_push(HintSampleQueue *queue, uint8_t *data, int size, + int sample) { /* No need to keep track of smaller samples, since describing them * with immediates is more efficient. */ - if (pkt->size <= 14) + if (size <= 14) return; if (!queue->samples || queue->len >= queue->size) { HintSample* samples; @@ -108,8 +111,8 @@ static void sample_queue_push(HintSampleQueue *queue, AVPacket *pkt, int sample) return; queue->samples = samples; } - queue->samples[queue->len].data = pkt->data; - queue->samples[queue->len].size = pkt->size; + queue->samples[queue->len].data = data; + queue->samples[queue->len].size = size; queue->samples[queue->len].sample_number = sample; queue->samples[queue->len].offset = 0; queue->samples[queue->len].own_data = 0; @@ -316,7 +319,7 @@ static int write_hint_packets(AVIOContext *out, const uint8_t *data, int64_t count_pos, entries_pos; int count = 0, entries; - count_pos = url_ftell(out); + count_pos = avio_tell(out); /* RTPsample header */ avio_wb16(out, 0); /* packet count */ avio_wb16(out, 0); /* reserved */ @@ -330,7 +333,7 @@ static int write_hint_packets(AVIOContext *out, const uint8_t *data, size -= 4; if (packet_len > size || packet_len <= 12) break; - if (data[1] >= 200 && data[1] <= 204) { + if (RTP_PT_IS_RTCP(data[1])) { /* RTCP packet, just skip */ data += packet_len; size -= packet_len; @@ -358,7 +361,7 @@ static int write_hint_packets(AVIOContext *out, const uint8_t *data, avio_write(out, data, 2); /* RTP header */ avio_wb16(out, seq); /* RTPsequenceseed */ avio_wb16(out, 0); /* reserved + flags */ - entries_pos = url_ftell(out); + entries_pos = avio_tell(out); avio_wb16(out, 0); /* entry count */ data += 12; @@ -371,21 +374,22 @@ static int write_hint_packets(AVIOContext *out, const uint8_t *data, data += packet_len; size -= packet_len; - curpos = url_ftell(out); - url_fseek(out, entries_pos, SEEK_SET); + curpos = avio_tell(out); + avio_seek(out, entries_pos, SEEK_SET); avio_wb16(out, entries); - url_fseek(out, curpos, SEEK_SET); + avio_seek(out, curpos, SEEK_SET); } - curpos = url_ftell(out); - url_fseek(out, count_pos, SEEK_SET); + curpos = avio_tell(out); + avio_seek(out, count_pos, SEEK_SET); avio_wb16(out, count); - url_fseek(out, curpos, SEEK_SET); + avio_seek(out, curpos, SEEK_SET); return count; } int ff_mov_add_hinted_packet(AVFormatContext *s, AVPacket *pkt, - int track_index, int sample) + int track_index, int sample, + uint8_t *sample_data, int sample_size) { MOVMuxContext *mov = s->priv_data; MOVTrack *trk = &mov->tracks[track_index]; @@ -401,15 +405,18 @@ int ff_mov_add_hinted_packet(AVFormatContext *s, AVPacket *pkt, if (!rtp_ctx->pb) return AVERROR(ENOMEM); - sample_queue_push(&trk->sample_queue, pkt, sample); + if (sample_data) + sample_queue_push(&trk->sample_queue, sample_data, sample_size, sample); + else + sample_queue_push(&trk->sample_queue, pkt->data, pkt->size, sample); /* Feed the packet to the RTP muxer */ ff_write_chained(rtp_ctx, 0, pkt, s); /* Fetch the output from the RTP muxer, open a new output buffer * for next time. */ - size = url_close_dyn_buf(rtp_ctx->pb, &buf); - if ((ret = url_open_dyn_packet_buf(&rtp_ctx->pb, + size = avio_close_dyn_buf(rtp_ctx->pb, &buf); + if ((ret = ffio_open_dyn_packet_buf(&rtp_ctx->pb, RTP_MAX_PACKET_SIZE)) < 0) goto done; @@ -417,14 +424,14 @@ int ff_mov_add_hinted_packet(AVFormatContext *s, AVPacket *pkt, goto done; /* Open a buffer for writing the hint */ - if ((ret = url_open_dyn_buf(&hintbuf)) < 0) + if ((ret = avio_open_dyn_buf(&hintbuf)) < 0) goto done; av_init_packet(&hint_pkt); count = write_hint_packets(hintbuf, buf, size, trk, &hint_pkt.dts); av_freep(&buf); /* Write the hint data into the hint track */ - hint_pkt.size = size = url_close_dyn_buf(hintbuf, &buf); + hint_pkt.size = size = avio_close_dyn_buf(hintbuf, &buf); hint_pkt.data = buf; hint_pkt.pts = hint_pkt.dts; hint_pkt.stream_index = track_index; @@ -448,9 +455,8 @@ void ff_mov_close_hinting(MOVTrack *track) { return; if (rtp_ctx->pb) { av_write_trailer(rtp_ctx); - url_close_dyn_buf(rtp_ctx->pb, &ptr); + avio_close_dyn_buf(rtp_ctx->pb, &ptr); av_free(ptr); } avformat_free_context(rtp_ctx); } -