If a changed parameter was previously set prior to parsing, change it back to
the old value and send packet side data instead.
---
 libavformat/utils.c |   34 ++++++++++++++++++++++++++++++++++
 1 files changed, 34 insertions(+), 0 deletions(-)

diff --git a/libavformat/utils.c b/libavformat/utils.c
index b932322..e74afb8 100644
--- a/libavformat/utils.c
+++ b/libavformat/utils.c
@@ -21,6 +21,7 @@
 
 /* #define DEBUG */
 
+#include "libavutil/common.h"
 #include "avformat.h"
 #include "avio_internal.h"
 #include "internal.h"
@@ -1018,6 +1019,11 @@ static int parse_packet(AVFormatContext *s, AVPacket 
*pkt, int stream_index)
 
     while (size > 0 || (pkt == &flush_pkt && got_output)) {
         int len;
+        int old_sample_rate         = st->codec->sample_rate;
+        int old_channels            = st->codec->channels;
+        uint64_t old_channel_layout = st->codec->channel_layout;
+        int old_width               = st->codec->width;
+        int old_height              = st->codec->height;
 
         av_init_packet(&out_pkt);
         len = av_parser_parse2(st->parser,  st->codec,
@@ -1034,6 +1040,34 @@ static int parse_packet(AVFormatContext *s, AVPacket 
*pkt, int stream_index)
         if (!out_pkt.size)
             continue;
 
+        /* only allow a parameter to change if it was not set prior to parsing
+           or by sending packet side data */
+        if (old_sample_rate == st->codec->sample_rate)
+            old_sample_rate = 0;
+        else if (old_sample_rate)
+            FFSWAP(int, st->codec->sample_rate, old_sample_rate);
+        if (old_channels == st->codec->channels)
+            old_channels = 0;
+        else if (old_channels)
+            FFSWAP(int, st->codec->channels, old_channels);
+        if (old_channel_layout == st->codec->channel_layout)
+            old_channel_layout = 0;
+        else if (old_channel_layout)
+            FFSWAP(uint64_t, st->codec->channel_layout, old_channel_layout);
+        if (old_width == st->codec->width)
+            old_width = 0;
+        else if (old_width)
+            FFSWAP(int, st->codec->width, old_width);
+        if (old_height == st->codec->height)
+            old_height = 0;
+        else if (old_height)
+            FFSWAP(int, st->codec->height, old_height);
+        if (old_sample_rate || old_channels || old_channel_layout ||
+            old_width || old_height) {
+            ff_add_param_change(&out_pkt, old_channels, old_channel_layout,
+                                old_sample_rate, old_width, old_height);
+        }
+
         /* set the duration */
         out_pkt.duration = 0;
         if (st->codec->codec_type == AVMEDIA_TYPE_AUDIO) {
-- 
1.7.1

_______________________________________________
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel

Reply via email to