]> git.sesse.net Git - ffmpeg/blobdiff - libavformat/rtpenc_chain.c
smoothstreamingenc: explict cast to avoid overflow
[ffmpeg] / libavformat / rtpenc_chain.c
index adc432aa0043a8431f05ab6e71840b3a12fceeda..773a7dbbc8e67df45e5ccc89037818a3569e9510 100644 (file)
@@ -31,7 +31,7 @@ int ff_rtp_chain_mux_open(AVFormatContext **out, AVFormatContext *s,
                           int idx)
 {
     AVFormatContext *rtpctx = NULL;
-    int ret, pt;
+    int ret;
     AVOutputFormat *rtp_format = av_guess_format("rtp", NULL, NULL);
     uint8_t *rtpflags;
     AVDictionary *opts = NULL;
@@ -62,7 +62,7 @@ int ff_rtp_chain_mux_open(AVFormatContext **out, AVFormatContext *s,
     /* Get the payload type from the codec */
     if (st->id < RTP_PT_PRIVATE)
         rtpctx->streams[0]->id =
-            ff_rtp_get_payload_type(rtpctx, st->codec, idx);
+            ff_rtp_get_payload_type(s, st->codec, idx);
     else
         rtpctx->streams[0]->id = st->id;
 
@@ -73,18 +73,22 @@ int ff_rtp_chain_mux_open(AVFormatContext **out, AVFormatContext *s,
     rtpctx->start_time_realtime = s->start_time_realtime;
 
     avcodec_copy_context(rtpctx->streams[0]->codec, st->codec);
+    rtpctx->streams[0]->time_base = st->time_base;
 
     if (handle) {
-        ffio_fdopen(&rtpctx->pb, handle);
+        ret = ffio_fdopen(&rtpctx->pb, handle);
+        if (ret < 0)
+            ffurl_close(handle);
     } else
-        ffio_open_dyn_packet_buf(&rtpctx->pb, packet_size);
-    ret = avformat_write_header(rtpctx, &opts);
+        ret = ffio_open_dyn_packet_buf(&rtpctx->pb, packet_size);
+    if (!ret)
+        ret = avformat_write_header(rtpctx, &opts);
     av_dict_free(&opts);
 
     if (ret) {
-        if (handle) {
+        if (handle && rtpctx->pb) {
             avio_close(rtpctx->pb);
-        } else {
+        } else if (rtpctx->pb) {
             uint8_t *ptr;
             avio_close_dyn_buf(rtpctx->pb, &ptr);
             av_free(ptr);