[3/4] gif: flush_put_bits before writing each chunk

Message ID 20170226175813.20428-4-stebbins@jetheaddev.com
State New
Headers show

Commit Message

John Stebbins Feb. 26, 2017, 5:58 p.m.
Parts of previous chunk were getting written in next chunk.  This causes
inconsistent output if put_bits caches 64 bits instead of 32.
---
 libavformat/gif.c       | 2 +-
 tests/ref/lavf/gif      | 6 +++---
 tests/ref/seek/lavf-gif | 2 +-
 3 files changed, 5 insertions(+), 5 deletions(-)

Patch

diff --git a/libavformat/gif.c b/libavformat/gif.c
index e7fa37c..a45ed9a 100644
--- a/libavformat/gif.c
+++ b/libavformat/gif.c
@@ -239,8 +239,8 @@  static int gif_image_write_image(AVIOContext *pb,
 
         if (left <= GIF_CHUNKS) {
             put_bits(&p, 9, 0x101); /* end of stream */
-            flush_put_bits(&p);
         }
+        flush_put_bits(&p);
         if (put_bits_ptr(&p) - p.buf > 0) {
             avio_w8(pb, put_bits_ptr(&p) - p.buf); /* byte count of the packet */
             avio_write(pb, p.buf, put_bits_ptr(&p) - p.buf); /* the actual buffer */
diff --git a/tests/ref/lavf/gif b/tests/ref/lavf/gif
index 4a4ebfb..785e22d 100644
--- a/tests/ref/lavf/gif
+++ b/tests/ref/lavf/gif
@@ -1,3 +1,3 @@ 
-e6089fd4ef3b9df44090ab3650bdd810 *./tests/data/lavf/lavf.gif
-2906401 ./tests/data/lavf/lavf.gif
-./tests/data/lavf/lavf.gif CRC=0xe5605ff6
+f0a9568a8962ec066433cad2181e5b76 *./tests/data/lavf/lavf.gif
+2915901 ./tests/data/lavf/lavf.gif
+./tests/data/lavf/lavf.gif CRC=0xed403ded
diff --git a/tests/ref/seek/lavf-gif b/tests/ref/seek/lavf-gif
index 883f187..4d711b6 100644
--- a/tests/ref/seek/lavf-gif
+++ b/tests/ref/seek/lavf-gif
@@ -1,4 +1,4 @@ 
-ret: 0         st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos:     -1 size:2906401
+ret: 0         st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos:     -1 size:2915901
 ret:-EINVAL    st:-1 flags:0  ts:-1.000000
 ret:-EINVAL    st:-1 flags:1  ts: 1.894167
 ret:-EINVAL    st: 0 flags:0  ts: 0.800000