00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "avformat.h"
00023 #include "avio_internal.h"
00024 #include "rtpenc_chain.h"
00025 #include "avio_internal.h"
00026 #include "libavutil/opt.h"
00027
00028 int ff_rtp_chain_mux_open(AVFormatContext **out, AVFormatContext *s,
00029 AVStream *st, URLContext *handle, int packet_size)
00030 {
00031 AVFormatContext *rtpctx = NULL;
00032 int ret;
00033 AVOutputFormat *rtp_format = av_guess_format("rtp", NULL, NULL);
00034 uint8_t *rtpflags;
00035 AVDictionary *opts = NULL;
00036
00037 if (!rtp_format) {
00038 ret = AVERROR(ENOSYS);
00039 goto fail;
00040 }
00041
00042
00043 rtpctx = avformat_alloc_context();
00044 if (!rtpctx) {
00045 ret = AVERROR(ENOMEM);
00046 goto fail;
00047 }
00048
00049 rtpctx->oformat = rtp_format;
00050 if (!avformat_new_stream(rtpctx, NULL)) {
00051 ret = AVERROR(ENOMEM);
00052 goto fail;
00053 }
00054
00055 rtpctx->interrupt_callback = s->interrupt_callback;
00056
00057 rtpctx->max_delay = s->max_delay;
00058
00059 rtpctx->streams[0]->sample_aspect_ratio = st->sample_aspect_ratio;
00060 rtpctx->flags |= s->flags & AVFMT_FLAG_MP4A_LATM;
00061
00062 if (av_opt_get(s, "rtpflags", AV_OPT_SEARCH_CHILDREN, &rtpflags) >= 0)
00063 av_dict_set(&opts, "rtpflags", rtpflags, AV_DICT_DONT_STRDUP_VAL);
00064
00065
00066 rtpctx->start_time_realtime = s->start_time_realtime;
00067
00068 avcodec_copy_context(rtpctx->streams[0]->codec, st->codec);
00069
00070 if (handle) {
00071 ffio_fdopen(&rtpctx->pb, handle);
00072 } else
00073 ffio_open_dyn_packet_buf(&rtpctx->pb, packet_size);
00074 ret = avformat_write_header(rtpctx, &opts);
00075 av_dict_free(&opts);
00076
00077 if (ret) {
00078 if (handle) {
00079 avio_close(rtpctx->pb);
00080 } else {
00081 uint8_t *ptr;
00082 avio_close_dyn_buf(rtpctx->pb, &ptr);
00083 av_free(ptr);
00084 }
00085 avformat_free_context(rtpctx);
00086 return ret;
00087 }
00088
00089 *out = rtpctx;
00090 return 0;
00091
00092 fail:
00093 av_free(rtpctx);
00094 if (handle)
00095 ffurl_close(handle);
00096 return ret;
00097 }