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 AVFormatContext *ff_rtp_chain_mux_open(AVFormatContext *s, AVStream *st,
00029 URLContext *handle, int packet_size)
00030 {
00031 AVFormatContext *rtpctx;
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 return NULL;
00039
00040
00041 rtpctx = avformat_alloc_context();
00042 if (!rtpctx)
00043 return NULL;
00044
00045 rtpctx->oformat = rtp_format;
00046 if (!avformat_new_stream(rtpctx, NULL)) {
00047 av_free(rtpctx);
00048 return NULL;
00049 }
00050
00051 rtpctx->interrupt_callback = s->interrupt_callback;
00052
00053 rtpctx->max_delay = s->max_delay;
00054
00055 rtpctx->streams[0]->sample_aspect_ratio = st->sample_aspect_ratio;
00056 rtpctx->flags |= s->flags & AVFMT_FLAG_MP4A_LATM;
00057
00058 if (av_opt_get(s, "rtpflags", AV_OPT_SEARCH_CHILDREN, &rtpflags) >= 0)
00059 av_dict_set(&opts, "rtpflags", rtpflags, AV_DICT_DONT_STRDUP_VAL);
00060
00061
00062 rtpctx->start_time_realtime = s->start_time_realtime;
00063
00064 avcodec_copy_context(rtpctx->streams[0]->codec, st->codec);
00065
00066 if (handle) {
00067 ffio_fdopen(&rtpctx->pb, handle);
00068 } else
00069 ffio_open_dyn_packet_buf(&rtpctx->pb, packet_size);
00070 ret = avformat_write_header(rtpctx, &opts);
00071 av_dict_free(&opts);
00072
00073 if (ret) {
00074 if (handle) {
00075 avio_close(rtpctx->pb);
00076 } else {
00077 uint8_t *ptr;
00078 avio_close_dyn_buf(rtpctx->pb, &ptr);
00079 av_free(ptr);
00080 }
00081 avformat_free_context(rtpctx);
00082 return NULL;
00083 }
00084
00085 return rtpctx;
00086 }
00087