annotate ffmpeg/libavformat/rtpenc_chain.c @ 13:844d341cf643 tip

Back up before ISMIR
author Yading Song <yading.song@eecs.qmul.ac.uk>
date Thu, 31 Oct 2013 13:17:06 +0000
parents f445c3017523
children
rev   line source
yading@11 1 /*
yading@11 2 * RTP muxer chaining code
yading@11 3 * Copyright (c) 2010 Martin Storsjo
yading@11 4 *
yading@11 5 * This file is part of FFmpeg.
yading@11 6 *
yading@11 7 * FFmpeg is free software; you can redistribute it and/or
yading@11 8 * modify it under the terms of the GNU Lesser General Public
yading@11 9 * License as published by the Free Software Foundation; either
yading@11 10 * version 2.1 of the License, or (at your option) any later version.
yading@11 11 *
yading@11 12 * FFmpeg is distributed in the hope that it will be useful,
yading@11 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
yading@11 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
yading@11 15 * Lesser General Public License for more details.
yading@11 16 *
yading@11 17 * You should have received a copy of the GNU Lesser General Public
yading@11 18 * License along with FFmpeg; if not, write to the Free Software
yading@11 19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
yading@11 20 */
yading@11 21
yading@11 22 #include "avformat.h"
yading@11 23 #include "avio_internal.h"
yading@11 24 #include "rtpenc_chain.h"
yading@11 25 #include "avio_internal.h"
yading@11 26 #include "rtp.h"
yading@11 27 #include "libavutil/opt.h"
yading@11 28
yading@11 29 int ff_rtp_chain_mux_open(AVFormatContext **out, AVFormatContext *s,
yading@11 30 AVStream *st, URLContext *handle, int packet_size,
yading@11 31 int idx)
yading@11 32 {
yading@11 33 AVFormatContext *rtpctx = NULL;
yading@11 34 int ret;
yading@11 35 AVOutputFormat *rtp_format = av_guess_format("rtp", NULL, NULL);
yading@11 36 uint8_t *rtpflags;
yading@11 37 AVDictionary *opts = NULL;
yading@11 38
yading@11 39 if (!rtp_format) {
yading@11 40 ret = AVERROR(ENOSYS);
yading@11 41 goto fail;
yading@11 42 }
yading@11 43
yading@11 44 /* Allocate an AVFormatContext for each output stream */
yading@11 45 rtpctx = avformat_alloc_context();
yading@11 46 if (!rtpctx) {
yading@11 47 ret = AVERROR(ENOMEM);
yading@11 48 goto fail;
yading@11 49 }
yading@11 50
yading@11 51 rtpctx->oformat = rtp_format;
yading@11 52 if (!avformat_new_stream(rtpctx, NULL)) {
yading@11 53 ret = AVERROR(ENOMEM);
yading@11 54 goto fail;
yading@11 55 }
yading@11 56 /* Pass the interrupt callback on */
yading@11 57 rtpctx->interrupt_callback = s->interrupt_callback;
yading@11 58 /* Copy the max delay setting; the rtp muxer reads this. */
yading@11 59 rtpctx->max_delay = s->max_delay;
yading@11 60 /* Copy other stream parameters. */
yading@11 61 rtpctx->streams[0]->sample_aspect_ratio = st->sample_aspect_ratio;
yading@11 62 rtpctx->flags |= s->flags & AVFMT_FLAG_MP4A_LATM;
yading@11 63
yading@11 64 /* Get the payload type from the codec */
yading@11 65 if (st->id < RTP_PT_PRIVATE)
yading@11 66 rtpctx->streams[0]->id =
yading@11 67 ff_rtp_get_payload_type(s, st->codec, idx);
yading@11 68 else
yading@11 69 rtpctx->streams[0]->id = st->id;
yading@11 70
yading@11 71
yading@11 72 if (av_opt_get(s, "rtpflags", AV_OPT_SEARCH_CHILDREN, &rtpflags) >= 0)
yading@11 73 av_dict_set(&opts, "rtpflags", rtpflags, AV_DICT_DONT_STRDUP_VAL);
yading@11 74
yading@11 75 /* Set the synchronized start time. */
yading@11 76 rtpctx->start_time_realtime = s->start_time_realtime;
yading@11 77
yading@11 78 avcodec_copy_context(rtpctx->streams[0]->codec, st->codec);
yading@11 79
yading@11 80 if (handle) {
yading@11 81 ffio_fdopen(&rtpctx->pb, handle);
yading@11 82 } else
yading@11 83 ffio_open_dyn_packet_buf(&rtpctx->pb, packet_size);
yading@11 84 ret = avformat_write_header(rtpctx, &opts);
yading@11 85 av_dict_free(&opts);
yading@11 86
yading@11 87 if (ret) {
yading@11 88 if (handle) {
yading@11 89 avio_close(rtpctx->pb);
yading@11 90 } else {
yading@11 91 uint8_t *ptr;
yading@11 92 avio_close_dyn_buf(rtpctx->pb, &ptr);
yading@11 93 av_free(ptr);
yading@11 94 }
yading@11 95 avformat_free_context(rtpctx);
yading@11 96 return ret;
yading@11 97 }
yading@11 98
yading@11 99 *out = rtpctx;
yading@11 100 return 0;
yading@11 101
yading@11 102 fail:
yading@11 103 av_free(rtpctx);
yading@11 104 if (handle)
yading@11 105 ffurl_close(handle);
yading@11 106 return ret;
yading@11 107 }