a493f80a |
/*
* RTP muxer chaining code
* Copyright (c) 2010 Martin Storsjo
*
* This file is part of FFmpeg.
*
* FFmpeg 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,
* 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
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "avformat.h" |
724f6a0f |
#include "avio_internal.h" |
a493f80a |
#include "rtpenc_chain.h" |
8034130e |
#include "rtp.h" |
ff0824f7 |
#include "libavutil/opt.h" |
a493f80a |
|
68c81308 |
int ff_rtp_chain_mux_open(AVFormatContext **out, AVFormatContext *s, |
8034130e |
AVStream *st, URLContext *handle, int packet_size,
int idx) |
a493f80a |
{ |
93cef6f9 |
AVFormatContext *rtpctx = NULL; |
2c4593dd |
int ret; |
9461e4bc |
ff_const59 AVOutputFormat *rtp_format = av_guess_format("rtp", NULL, NULL); |
3b3ea346 |
uint8_t *rtpflags;
AVDictionary *opts = NULL; |
a493f80a |
|
68c81308 |
if (!rtp_format) {
ret = AVERROR(ENOSYS); |
93cef6f9 |
goto fail; |
68c81308 |
} |
a493f80a |
/* Allocate an AVFormatContext for each output stream */
rtpctx = avformat_alloc_context(); |
68c81308 |
if (!rtpctx) {
ret = AVERROR(ENOMEM); |
93cef6f9 |
goto fail; |
68c81308 |
} |
a493f80a |
rtpctx->oformat = rtp_format; |
3b3bbdd3 |
if (!avformat_new_stream(rtpctx, NULL)) { |
68c81308 |
ret = AVERROR(ENOMEM); |
93cef6f9 |
goto fail; |
a493f80a |
} |
6ef350c1 |
/* Pass the interrupt callback on */
rtpctx->interrupt_callback = s->interrupt_callback; |
a493f80a |
/* Copy the max delay setting; the rtp muxer reads this. */
rtpctx->max_delay = s->max_delay;
/* Copy other stream parameters. */
rtpctx->streams[0]->sample_aspect_ratio = st->sample_aspect_ratio; |
67747c89 |
rtpctx->flags |= s->flags & AVFMT_FLAG_BITEXACT; |
00f54c15 |
rtpctx->strict_std_compliance = s->strict_std_compliance; |
a493f80a |
|
8034130e |
/* Get the payload type from the codec */
if (st->id < RTP_PT_PRIVATE)
rtpctx->streams[0]->id = |
9200514a |
ff_rtp_get_payload_type(s, st->codecpar, idx); |
8034130e |
else
rtpctx->streams[0]->id = st->id; |
a493f80a |
|
a9b1536a |
|
3b3ea346 |
if (av_opt_get(s, "rtpflags", AV_OPT_SEARCH_CHILDREN, &rtpflags) >= 0)
av_dict_set(&opts, "rtpflags", rtpflags, AV_DICT_DONT_STRDUP_VAL); |
ff0824f7 |
|
a493f80a |
/* Set the synchronized start time. */
rtpctx->start_time_realtime = s->start_time_realtime;
|
9200514a |
avcodec_parameters_copy(rtpctx->streams[0]->codecpar, st->codecpar); |
2bb2c2bd |
rtpctx->streams[0]->time_base = st->time_base; |
a493f80a |
if (handle) { |
62572435 |
ret = ffio_fdopen(&rtpctx->pb, handle);
if (ret < 0)
ffurl_close(handle); |
a493f80a |
} else |
62572435 |
ret = ffio_open_dyn_packet_buf(&rtpctx->pb, packet_size);
if (!ret)
ret = avformat_write_header(rtpctx, &opts); |
3b3ea346 |
av_dict_free(&opts); |
a493f80a |
if (ret) { |
62572435 |
if (handle && rtpctx->pb) { |
f9ddaa35 |
avio_closep(&rtpctx->pb); |
62572435 |
} else if (rtpctx->pb) { |
8e32b1f0 |
ffio_free_dyn_buf(&rtpctx->pb); |
a493f80a |
} |
42f97696 |
avformat_free_context(rtpctx); |
68c81308 |
return ret; |
a493f80a |
}
|
68c81308 |
*out = rtpctx;
return 0; |
93cef6f9 |
fail: |
3eff98c9 |
avformat_free_context(rtpctx); |
93cef6f9 |
if (handle)
ffurl_close(handle); |
68c81308 |
return ret; |
a493f80a |
} |