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
00035 if (!rtp_format)
00036 return NULL;
00037
00038
00039 rtpctx = avformat_alloc_context();
00040 if (!rtpctx)
00041 return NULL;
00042
00043 rtpctx->oformat = rtp_format;
00044 if (!av_new_stream(rtpctx, 0)) {
00045 av_free(rtpctx);
00046 return NULL;
00047 }
00048
00049 rtpctx->max_delay = s->max_delay;
00050
00051 rtpctx->streams[0]->sample_aspect_ratio = st->sample_aspect_ratio;
00052 rtpctx->flags |= s->flags & AVFMT_FLAG_MP4A_LATM;
00053
00054 av_set_parameters(rtpctx, NULL);
00055
00056 if (s->oformat->priv_class &&
00057 av_find_opt(s->priv_data, "rtpflags", NULL, 0, 0))
00058 av_set_int(rtpctx->priv_data, "rtpflags",
00059 av_get_int(s->priv_data, "rtpflags", NULL));
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, NULL);
00071
00072 if (ret) {
00073 if (handle) {
00074 avio_close(rtpctx->pb);
00075 } else {
00076 uint8_t *ptr;
00077 avio_close_dyn_buf(rtpctx->pb, &ptr);
00078 av_free(ptr);
00079 }
00080 avformat_free_context(rtpctx);
00081 return NULL;
00082 }
00083
00084 return rtpctx;
00085 }
00086