]> git.sesse.net Git - ffmpeg/blobdiff - libavformat/rtpenc_chain.c
avprobe: fix formatting.
[ffmpeg] / libavformat / rtpenc_chain.c
index 77633ed53eb0794be5e1fbf63c811b41fad43cd4..374209931406bc560e5e900d82ea08d66466a7bf 100644 (file)
  */
 
 #include "avformat.h"
+#include "avio_internal.h"
 #include "rtpenc_chain.h"
+#include "avio_internal.h"
+#include "libavutil/opt.h"
 
-AVFormatContext *ff_rtp_chain_mux_open(AVFormatContext *s, AVStream *st,
-                                       URLContext *handle, int packet_size)
+int ff_rtp_chain_mux_open(AVFormatContext **out, AVFormatContext *s,
+                          AVStream *st, URLContext *handle, int packet_size)
 {
-    AVFormatContext *rtpctx;
+    AVFormatContext *rtpctx = NULL;
     int ret;
     AVOutputFormat *rtp_format = av_guess_format("rtp", NULL, NULL);
+    uint8_t *rtpflags;
+    AVDictionary *opts = NULL;
 
-    if (!rtp_format)
-        return NULL;
+    if (!rtp_format) {
+        ret = AVERROR(ENOSYS);
+        goto fail;
+    }
 
     /* Allocate an AVFormatContext for each output stream */
     rtpctx = avformat_alloc_context();
-    if (!rtpctx)
-        return NULL;
+    if (!rtpctx) {
+        ret = AVERROR(ENOMEM);
+        goto fail;
+    }
 
     rtpctx->oformat = rtp_format;
-    if (!av_new_stream(rtpctx, 0)) {
-        av_free(rtpctx);
-        return NULL;
+    if (!avformat_new_stream(rtpctx, NULL)) {
+        ret = AVERROR(ENOMEM);
+        goto fail;
     }
+    /* Pass the interrupt callback on */
+    rtpctx->interrupt_callback = s->interrupt_callback;
     /* Copy the max delay setting; the rtp muxer reads this. */
     rtpctx->max_delay = s->max_delay;
     /* Copy other stream parameters. */
     rtpctx->streams[0]->sample_aspect_ratio = st->sample_aspect_ratio;
 
+    if (av_opt_get(s, "rtpflags", AV_OPT_SEARCH_CHILDREN, &rtpflags) >= 0)
+        av_dict_set(&opts, "rtpflags", rtpflags, AV_DICT_DONT_STRDUP_VAL);
+
     /* Set the synchronized start time. */
     rtpctx->start_time_realtime = s->start_time_realtime;
 
     avcodec_copy_context(rtpctx->streams[0]->codec, st->codec);
 
     if (handle) {
-        url_fdopen(&rtpctx->pb, handle);
+        ffio_fdopen(&rtpctx->pb, handle);
     } else
-        url_open_dyn_packet_buf(&rtpctx->pb, packet_size);
-    ret = av_write_header(rtpctx);
+        ffio_open_dyn_packet_buf(&rtpctx->pb, packet_size);
+    ret = avformat_write_header(rtpctx, &opts);
+    av_dict_free(&opts);
 
     if (ret) {
         if (handle) {
@@ -67,9 +82,15 @@ AVFormatContext *ff_rtp_chain_mux_open(AVFormatContext *s, AVStream *st,
             av_free(ptr);
         }
         avformat_free_context(rtpctx);
-        return NULL;
+        return ret;
     }
 
-    return rtpctx;
-}
+    *out = rtpctx;
+    return 0;
 
+fail:
+    av_free(rtpctx);
+    if (handle)
+        ffurl_close(handle);
+    return ret;
+}