00001 /* 00002 * RTP muxer chaining code 00003 * Copyright (c) 2010 Martin Storsjo 00004 * 00005 * This file is part of FFmpeg. 00006 * 00007 * FFmpeg is free software; you can redistribute it and/or 00008 * modify it under the terms of the GNU Lesser General Public 00009 * License as published by the Free Software Foundation; either 00010 * version 2.1 of the License, or (at your option) any later version. 00011 * 00012 * FFmpeg is distributed in the hope that it will be useful, 00013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00015 * Lesser General Public License for more details. 00016 * 00017 * You should have received a copy of the GNU Lesser General Public 00018 * License along with FFmpeg; if not, write to the Free Software 00019 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 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 /* Allocate an AVFormatContext for each output stream */ 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 /* Copy the max delay setting; the rtp muxer reads this. */ 00046 rtpctx->max_delay = s->max_delay; 00047 /* Copy other stream parameters. */ 00048 rtpctx->streams[0]->sample_aspect_ratio = st->sample_aspect_ratio; 00049 00050 /* Set the synchronized start time. */ 00051 rtpctx->start_time_realtime = s->start_time_realtime; 00052 00053 /* Remove the local codec, link to the original codec 00054 * context instead, to give the rtp muxer access to 00055 * codec parameters. */ 00056 av_free(rtpctx->streams[0]->codec); 00057 rtpctx->streams[0]->codec = st->codec; 00058 00059 if (handle) { 00060 url_fdopen(&rtpctx->pb, handle); 00061 } else 00062 url_open_dyn_packet_buf(&rtpctx->pb, packet_size); 00063 ret = av_write_header(rtpctx); 00064 00065 if (ret) { 00066 if (handle) { 00067 url_fclose(rtpctx->pb); 00068 } else { 00069 uint8_t *ptr; 00070 url_close_dyn_buf(rtpctx->pb, &ptr); 00071 av_free(ptr); 00072 } 00073 av_free(rtpctx->streams[0]); 00074 av_free(rtpctx); 00075 return NULL; 00076 } 00077 00078 /* Copy the RTP AVStream timebase back to the original AVStream */ 00079 st->time_base = rtpctx->streams[0]->time_base; 00080 return rtpctx; 00081 } 00082
1.5.6