]> git.sesse.net Git - ffmpeg/blobdiff - libavformat/brstm.c
Merge commit '271ce76d317c5432e151216cf23f12b77ed6cb7e'
[ffmpeg] / libavformat / brstm.c
index b6108e3ec824b461109fd77d20f5c342365dc374..291a4628bcf27c9bf33fb5689ebf58ad272e2810 100644 (file)
@@ -93,6 +93,7 @@ static int read_header(AVFormatContext *s)
     uint32_t size, asize, start = 0;
     AVStream *st;
     int ret = AVERROR_EOF;
+    int loop = 0;
     int bfstm = !strcmp("bfstm", s->iformat->name);
 
     st = avformat_new_stream(s, NULL);
@@ -195,7 +196,7 @@ static int read_header(AVFormatContext *s)
         return AVERROR_PATCHWELCOME;
     }
 
-    avio_skip(s->pb, 1); // loop flag
+    loop = avio_r8(s->pb); // loop flag
     st->codec->codec_id = codec;
     st->codec->channels = avio_r8(s->pb);
     if (!st->codec->channels)
@@ -209,7 +210,17 @@ static int read_header(AVFormatContext *s)
 
     if (!bfstm)
         avio_skip(s->pb, 2); // padding
-    avio_skip(s->pb, 4); // loop start sample
+
+    if (loop) {
+        if (av_dict_set_int(&s->metadata, "loop_start",
+                            av_rescale(read32(s), AV_TIME_BASE,
+                                       st->codec->sample_rate),
+                            0) < 0)
+            return AVERROR(ENOMEM);
+    } else {
+        avio_skip(s->pb, 4);
+    }
+
     st->start_time = 0;
     st->duration = read32(s);
     avpriv_set_pts_info(st, 64, 1, st->codec->sample_rate);
@@ -358,6 +369,15 @@ static int read_packet(AVFormatContext *s, AVPacket *pkt)
         size    = b->last_block_used_bytes;
         samples = b->last_block_samples;
         skip    = b->last_block_size - b->last_block_used_bytes;
+
+        if (samples < size * 14 / 8) {
+            uint32_t adjusted_size = samples / 14 * 8;
+            if (samples % 14)
+                adjusted_size += (samples % 14 + 1) / 2 + 1;
+
+            skip += size - adjusted_size;
+            size = adjusted_size;
+        }
     } else if (b->current_block < b->block_count) {
         size    = b->block_size;
         samples = b->samples_per_block;