diff mbox series

[FFmpeg-devel,1/2] avformat/movenc: don't negate roll_distance when writing it

Message ID 20210729210651.25168-1-jamrial@gmail.com
State New
Headers show
Series [FFmpeg-devel,1/2] avformat/movenc: don't negate roll_distance when writing it | expand

Checks

Context Check Description
andriy/x86_make success Make finished
andriy/x86_make_fate success Make fate finished
andriy/PPC64_make success Make finished
andriy/PPC64_make_fate success Make fate finished

Commit Message

James Almer July 29, 2021, 9:06 p.m. UTC
Ensure instead that it's the correct value.

Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavformat/movenc.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
diff mbox series

Patch

diff --git a/libavformat/movenc.c b/libavformat/movenc.c
index 57062f45c5..fedc9c0e18 100644
--- a/libavformat/movenc.c
+++ b/libavformat/movenc.c
@@ -2545,7 +2545,7 @@  static int mov_preroll_write_stbl_atoms(AVIOContext *pb, MOVTrack *track)
             int distance = 0;
             for (j = i - 1; j >= 0; j--) {
                 roll_samples_remaining -= get_cluster_duration(track, j);
-                distance++;
+                distance--;
                 if (roll_samples_remaining <= 0)
                     break;
             }
@@ -2555,7 +2555,7 @@  static int mov_preroll_write_stbl_atoms(AVIOContext *pb, MOVTrack *track)
             if (roll_samples_remaining > 0)
                 distance = 0;
             /* Verify distance is a maximum of 32 (2.5ms) packets. */
-            if (distance > 32)
+            if (distance < 32)
                 return AVERROR_INVALIDDATA;
             if (i && distance == sgpd_entries[entries].roll_distance) {
                 sgpd_entries[entries].count++;
@@ -2569,7 +2569,7 @@  static int mov_preroll_write_stbl_atoms(AVIOContext *pb, MOVTrack *track)
     } else {
         entries++;
         sgpd_entries[entries].count = track->sample_count;
-        sgpd_entries[entries].roll_distance = 1;
+        sgpd_entries[entries].roll_distance = -1;
         sgpd_entries[entries].group_description_index = ++group;
     }
     entries++;
@@ -2588,7 +2588,7 @@  static int mov_preroll_write_stbl_atoms(AVIOContext *pb, MOVTrack *track)
     avio_wb32(pb, group); /* entry_count */
     for (i = 0; i < entries; i++) {
         if (sgpd_entries[i].group_description_index) {
-            avio_wb16(pb, -sgpd_entries[i].roll_distance); /* roll_distance */
+            avio_wb16(pb, sgpd_entries[i].roll_distance); /* roll_distance */
         }
     }