[FFmpeg-cvslog] avformat/alp: allow seeking to start

Zane van Iperen git at videolan.org
Thu Mar 25 05:04:11 EET 2021


ffmpeg | branch: master | Zane van Iperen <zane at zanevaniperen.com> | Mon Mar 22 23:12:34 2021 +1000| [ea9732c5d618c92e9fef3c4ffcb803b969524539] | committer: Zane van Iperen

avformat/alp: allow seeking to start

Allows "ffplay -loop" to work.

Signed-off-by: Zane van Iperen <zane at zanevaniperen.com>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=ea9732c5d618c92e9fef3c4ffcb803b969524539
---

 libavformat/alp.c | 50 ++++++++++++++++++++++++++++++++------------------
 1 file changed, 32 insertions(+), 18 deletions(-)

diff --git a/libavformat/alp.c b/libavformat/alp.c
index f2b0c37730..222cc246a2 100644
--- a/libavformat/alp.c
+++ b/libavformat/alp.c
@@ -72,38 +72,39 @@ static int alp_read_header(AVFormatContext *s)
 {
     int ret;
     AVStream *st;
-    ALPHeader hdr;
+    ALPHeader *hdr = s->priv_data;
     AVCodecParameters *par;
 
-    if ((hdr.magic = avio_rl32(s->pb)) != ALP_TAG)
+    if ((hdr->magic = avio_rl32(s->pb)) != ALP_TAG)
         return AVERROR_INVALIDDATA;
 
-    hdr.header_size = avio_rl32(s->pb);
+    hdr->header_size = avio_rl32(s->pb);
 
-    if (hdr.header_size != 8 && hdr.header_size != 12) {
+    if (hdr->header_size != 8 && hdr->header_size != 12) {
         return AVERROR_INVALIDDATA;
     }
 
-    if ((ret = avio_read(s->pb, hdr.adpcm, sizeof(hdr.adpcm))) < 0)
+    if ((ret = avio_read(s->pb, hdr->adpcm, sizeof(hdr->adpcm))) < 0)
         return ret;
-    else if (ret != sizeof(hdr.adpcm))
+    else if (ret != sizeof(hdr->adpcm))
         return AVERROR(EIO);
 
-    if (strncmp("ADPCM", hdr.adpcm, sizeof(hdr.adpcm)) != 0)
+    if (strncmp("ADPCM", hdr->adpcm, sizeof(hdr->adpcm)) != 0)
         return AVERROR_INVALIDDATA;
 
-    hdr.unk1                    = avio_r8(s->pb);
-    hdr.num_channels            = avio_r8(s->pb);
+    hdr->unk1                   = avio_r8(s->pb);
+    hdr->num_channels           = avio_r8(s->pb);
 
-    if (hdr.header_size == 8) {
+    if (hdr->header_size == 8) {
         /* .TUN music file */
-        hdr.sample_rate         = 22050;
+        hdr->sample_rate        = 22050;
+
     } else {
         /* .PCM sound file */
-        hdr.sample_rate         = avio_rl32(s->pb);
+        hdr->sample_rate        = avio_rl32(s->pb);
     }
 
-    if (hdr.sample_rate > 44100) {
+    if (hdr->sample_rate > 44100) {
         avpriv_request_sample(s, "Sample Rate > 44100");
         return AVERROR_PATCHWELCOME;
     }
@@ -115,12 +116,12 @@ static int alp_read_header(AVFormatContext *s)
     par->codec_type             = AVMEDIA_TYPE_AUDIO;
     par->codec_id               = AV_CODEC_ID_ADPCM_IMA_ALP;
     par->format                 = AV_SAMPLE_FMT_S16;
-    par->sample_rate            = hdr.sample_rate;
-    par->channels               = hdr.num_channels;
+    par->sample_rate            = hdr->sample_rate;
+    par->channels               = hdr->num_channels;
 
-    if (hdr.num_channels == 1)
+    if (hdr->num_channels == 1)
         par->channel_layout     = AV_CH_LAYOUT_MONO;
-    else if (hdr.num_channels == 2)
+    else if (hdr->num_channels == 2)
         par->channel_layout     = AV_CH_LAYOUT_STEREO;
     else
         return AVERROR_INVALIDDATA;
@@ -151,12 +152,25 @@ static int alp_read_packet(AVFormatContext *s, AVPacket *pkt)
     return 0;
 }
 
+static int alp_seek(AVFormatContext *s, int stream_index,
+                     int64_t pts, int flags)
+{
+    const ALPHeader *hdr = s->priv_data;
+
+    if (pts != 0)
+        return AVERROR(EINVAL);
+
+    return avio_seek(s->pb, hdr->header_size + 8, SEEK_SET);
+}
+
 AVInputFormat ff_alp_demuxer = {
     .name           = "alp",
     .long_name      = NULL_IF_CONFIG_SMALL("LEGO Racers ALP"),
+    .priv_data_size = sizeof(ALPHeader),
     .read_probe     = alp_probe,
     .read_header    = alp_read_header,
-    .read_packet    = alp_read_packet
+    .read_packet    = alp_read_packet,
+    .read_seek      = alp_seek,
 };
 #endif
 



More information about the ffmpeg-cvslog mailing list