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 "rtp.h"
00027 #include "libavutil/opt.h"
00028
00029 int ff_rtp_chain_mux_open(AVFormatContext **out, AVFormatContext *s,
00030 AVStream *st, URLContext *handle, int packet_size,
00031 int idx)
00032 {
00033 AVFormatContext *rtpctx = NULL;
00034 int ret;
00035 AVOutputFormat *rtp_format = av_guess_format("rtp", NULL, NULL);
00036 uint8_t *rtpflags;
00037 AVDictionary *opts = NULL;
00038
00039 if (!rtp_format) {
00040 ret = AVERROR(ENOSYS);
00041 goto fail;
00042 }
00043
00044
00045 rtpctx = avformat_alloc_context();
00046 if (!rtpctx) {
00047 ret = AVERROR(ENOMEM);
00048 goto fail;
00049 }
00050
00051 rtpctx->oformat = rtp_format;
00052 if (!avformat_new_stream(rtpctx, NULL)) {
00053 ret = AVERROR(ENOMEM);
00054 goto fail;
00055 }
00056
00057 rtpctx->interrupt_callback = s->interrupt_callback;
00058
00059 rtpctx->max_delay = s->max_delay;
00060
00061 rtpctx->streams[0]->sample_aspect_ratio = st->sample_aspect_ratio;
00062 rtpctx->flags |= s->flags & AVFMT_FLAG_MP4A_LATM;
00063
00064
00065 if (st->id < RTP_PT_PRIVATE)
00066 rtpctx->streams[0]->id =
00067 ff_rtp_get_payload_type(rtpctx, st->codec, idx);
00068 else
00069 rtpctx->streams[0]->id = st->id;
00070
00071
00072 if (av_opt_get(s, "rtpflags", AV_OPT_SEARCH_CHILDREN, &rtpflags) >= 0)
00073 av_dict_set(&opts, "rtpflags", rtpflags, AV_DICT_DONT_STRDUP_VAL);
00074
00075
00076 rtpctx->start_time_realtime = s->start_time_realtime;
00077
00078 avcodec_copy_context(rtpctx->streams[0]->codec, st->codec);
00079
00080 if (handle) {
00081 ffio_fdopen(&rtpctx->pb, handle);
00082 } else
00083 ffio_open_dyn_packet_buf(&rtpctx->pb, packet_size);
00084 ret = avformat_write_header(rtpctx, &opts);
00085 av_dict_free(&opts);
00086
00087 if (ret) {
00088 if (handle) {
00089 avio_close(rtpctx->pb);
00090 } else {
00091 uint8_t *ptr;
00092 avio_close_dyn_buf(rtpctx->pb, &ptr);
00093 av_free(ptr);
00094 }
00095 avformat_free_context(rtpctx);
00096 return ret;
00097 }
00098
00099 *out = rtpctx;
00100 return 0;
00101
00102 fail:
00103 av_free(rtpctx);
00104 if (handle)
00105 ffurl_close(handle);
00106 return ret;
00107 }