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 "rtpenc_chain.h"
00024
00025 AVFormatContext *ff_rtp_chain_mux_open(AVFormatContext *s, AVStream *st,
00026 URLContext *handle, int packet_size)
00027 {
00028 AVFormatContext *rtpctx;
00029 int ret;
00030 AVOutputFormat *rtp_format = av_guess_format("rtp", NULL, NULL);
00031
00032 if (!rtp_format)
00033 return NULL;
00034
00035
00036 rtpctx = avformat_alloc_context();
00037 if (!rtpctx)
00038 return NULL;
00039
00040 rtpctx->oformat = rtp_format;
00041 if (!av_new_stream(rtpctx, 0)) {
00042 av_free(rtpctx);
00043 return NULL;
00044 }
00045
00046 rtpctx->max_delay = s->max_delay;
00047
00048 rtpctx->streams[0]->sample_aspect_ratio = st->sample_aspect_ratio;
00049
00050
00051 rtpctx->start_time_realtime = s->start_time_realtime;
00052
00053 avcodec_copy_context(rtpctx->streams[0]->codec, st->codec);
00054
00055 if (handle) {
00056 url_fdopen(&rtpctx->pb, handle);
00057 } else
00058 url_open_dyn_packet_buf(&rtpctx->pb, packet_size);
00059 ret = av_write_header(rtpctx);
00060
00061 if (ret) {
00062 if (handle) {
00063 avio_close(rtpctx->pb);
00064 } else {
00065 uint8_t *ptr;
00066 url_close_dyn_buf(rtpctx->pb, &ptr);
00067 av_free(ptr);
00068 }
00069 avformat_free_context(rtpctx);
00070 return NULL;
00071 }
00072
00073 return rtpctx;
00074 }
00075