]> git.sesse.net Git - ffmpeg/blobdiff - libavformat/anm.c
lavf: replace AVStream.codec with AVStream.codecpar
[ffmpeg] / libavformat / anm.c
index de59b40675512ee90618c6785df825629568c4f6..2ab6712f267b32cf432191534708d80fa659f2cf 100644 (file)
@@ -2,45 +2,46 @@
  * Deluxe Paint Animation demuxer
  * Copyright (c) 2009 Peter Ross
  *
- * This file is part of FFmpeg.
+ * This file is part of Libav.
  *
- * FFmpeg is free software; you can redistribute it and/or
+ * Libav is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
  * License as published by the Free Software Foundation; either
  * version 2.1 of the License, or (at your option) any later version.
  *
- * FFmpeg is distributed in the hope that it will be useful,
+ * Libav is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  * Lesser General Public License for more details.
  *
  * You should have received a copy of the GNU Lesser General Public
- * License along with FFmpeg; if not, write to the Free Software
+ * License along with Libav; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
 /**
- * @file libavformat/anm.c
+ * @file
  * Deluxe Paint Animation demuxer
  */
 
 #include "libavutil/intreadwrite.h"
 #include "avformat.h"
+#include "internal.h"
 
-typedef struct {
+typedef struct Page {
     int base_record;
     unsigned int nb_records;
     int size;
 } Page;
 
-typedef struct {
-    unsigned int nb_pages;    /** total pages in file */
-    unsigned int nb_records;  /** total records in file */
+typedef struct AnmDemuxContext {
+    unsigned int nb_pages;    /**< total pages in file */
+    unsigned int nb_records;  /**< total records in file */
     int page_table_offset;
-#define MAX_PAGES  256        /** Deluxe Paint hardcoded value */
-    Page pt[MAX_PAGES];       /** page table */
-    int page;                 /** current page (or AVERROR_xxx code) */
-    int record;               /** current record (with in page) */
+#define MAX_PAGES  256        /**< Deluxe Paint hardcoded value */
+    Page pt[MAX_PAGES];       /**< page table */
+    int page;                 /**< current page (or AVERROR_xxx code) */
+    int record;               /**< current record (with in page) */
 } AnmDemuxContext;
 
 #define LPF_TAG  MKTAG('L','P','F',' ')
@@ -75,113 +76,106 @@ static int find_record(const AnmDemuxContext *anm, int record)
     return AVERROR_INVALIDDATA;
 }
 
-static int read_header(AVFormatContext *s,
-                       AVFormatParameters *ap)
+static int read_header(AVFormatContext *s)
 {
     AnmDemuxContext *anm = s->priv_data;
-    ByteIOContext *pb = s->pb;
+    AVIOContext *pb = s->pb;
     AVStream *st;
     int i, ret;
 
-    url_fskip(pb, 4); /* magic number */
-    if (get_le16(pb) != MAX_PAGES) {
-        av_log_ask_for_sample(s, "max_pages != " AV_STRINGIFY(MAX_PAGES) "\n");
-        return AVERROR_INVALIDDATA;
+    avio_skip(pb, 4); /* magic number */
+    if (avio_rl16(pb) != MAX_PAGES) {
+        avpriv_request_sample(s, "max_pages != " AV_STRINGIFY(MAX_PAGES));
+        return AVERROR_PATCHWELCOME;
     }
 
-    anm->nb_pages   = get_le16(pb);
-    anm->nb_records = get_le32(pb);
-    url_fskip(pb, 2); /* max records per page */
-    anm->page_table_offset = get_le16(pb);
-    if (get_le32(pb) != ANIM_TAG)
+    anm->nb_pages   = avio_rl16(pb);
+    anm->nb_records = avio_rl32(pb);
+    avio_skip(pb, 2); /* max records per page */
+    anm->page_table_offset = avio_rl16(pb);
+    if (avio_rl32(pb) != ANIM_TAG)
         return AVERROR_INVALIDDATA;
 
     /* video stream */
-    st = av_new_stream(s, 0);
+    st = avformat_new_stream(s, NULL);
     if (!st)
         return AVERROR(ENOMEM);
-    st->codec->codec_type = AVMEDIA_TYPE_VIDEO;
-    st->codec->codec_id   = CODEC_ID_ANM;
-    st->codec->codec_tag  = 0; /* no fourcc */
-    st->codec->width      = get_le16(pb);
-    st->codec->height     = get_le16(pb);
-    if (get_byte(pb) != 0)
+    st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO;
+    st->codecpar->codec_id   = AV_CODEC_ID_ANM;
+    st->codecpar->codec_tag  = 0; /* no fourcc */
+    st->codecpar->width      = avio_rl16(pb);
+    st->codecpar->height     = avio_rl16(pb);
+    if (avio_r8(pb) != 0)
         goto invalid;
-    url_fskip(pb, 1); /* frame rate multiplier info */
+    avio_skip(pb, 1); /* frame rate multiplier info */
 
     /* ignore last delta record (used for looping) */
-    if (get_byte(pb))  /* has_last_delta */
+    if (avio_r8(pb))  /* has_last_delta */
         anm->nb_records = FFMAX(anm->nb_records - 1, 0);
 
-    url_fskip(pb, 1); /* last_delta_valid */
+    avio_skip(pb, 1); /* last_delta_valid */
 
-    if (get_byte(pb) != 0)
+    if (avio_r8(pb) != 0)
         goto invalid;
 
-    if (get_byte(pb) != 1)
+    if (avio_r8(pb) != 1)
         goto invalid;
 
-    url_fskip(pb, 1); /* other recs per frame */
+    avio_skip(pb, 1); /* other recs per frame */
 
-    if (get_byte(pb) != 1)
+    if (avio_r8(pb) != 1)
         goto invalid;
 
-    url_fskip(pb, 32); /* record_types */
-    st->nb_frames = get_le32(pb);
-    av_set_pts_info(st, 64, 1, get_le16(pb));
-    url_fskip(pb, 58);
+    avio_skip(pb, 32); /* record_types */
+    st->nb_frames = avio_rl32(pb);
+    avpriv_set_pts_info(st, 64, 1, avio_rl16(pb));
+    avio_skip(pb, 58);
 
     /* color cycling and palette data */
-    st->codec->extradata_size = 16*8 + 4*256;
-    st->codec->extradata      = av_mallocz(st->codec->extradata_size + FF_INPUT_BUFFER_PADDING_SIZE);
-    if (!st->codec->extradata) {
-        ret = AVERROR(ENOMEM);
-        goto close_and_return;
+    st->codecpar->extradata_size = 16*8 + 4*256;
+    st->codecpar->extradata      = av_mallocz(st->codecpar->extradata_size + AV_INPUT_BUFFER_PADDING_SIZE);
+    if (!st->codecpar->extradata) {
+        return AVERROR(ENOMEM);
     }
-    ret = get_buffer(pb, st->codec->extradata, st->codec->extradata_size);
+    ret = avio_read(pb, st->codecpar->extradata, st->codecpar->extradata_size);
     if (ret < 0)
-        goto close_and_return;
+        return ret;
 
     /* read page table */
-    ret = url_fseek(pb, anm->page_table_offset, SEEK_SET);
+    ret = avio_seek(pb, anm->page_table_offset, SEEK_SET);
     if (ret < 0)
-        goto close_and_return;
+        return ret;
 
     for (i = 0; i < MAX_PAGES; i++) {
         Page *p = &anm->pt[i];
-        p->base_record = get_le16(pb);
-        p->nb_records  = get_le16(pb);
-        p->size        = get_le16(pb);
+        p->base_record = avio_rl16(pb);
+        p->nb_records  = avio_rl16(pb);
+        p->size        = avio_rl16(pb);
     }
 
     /* find page of first frame */
     anm->page = find_record(anm, 0);
     if (anm->page < 0) {
-        ret = anm->page;
-        goto close_and_return;
+        return anm->page;
     }
 
     anm->record = -1;
     return 0;
 
 invalid:
-    av_log_ask_for_sample(s, NULL);
-    ret = AVERROR_INVALIDDATA;
-
-close_and_return:
-    av_close_input_stream(s);
-    return ret;
+    avpriv_request_sample(s, "Invalid header element");
+    return AVERROR_PATCHWELCOME;
 }
 
 static int read_packet(AVFormatContext *s,
                        AVPacket *pkt)
 {
     AnmDemuxContext *anm = s->priv_data;
-    ByteIOContext *pb = s->pb;
+    AVIOContext *pb = s->pb;
     Page *p;
     int tmp, record_size;
 
-    if (url_feof(s->pb))
+    if (s->pb->eof_reached)
         return AVERROR(EIO);
 
     if (anm->page < 0)
@@ -192,8 +186,8 @@ repeat:
 
     /* parse page header */
     if (anm->record < 0) {
-        url_fseek(pb, anm->page_table_offset + MAX_PAGES*6 + (anm->page<<16), SEEK_SET);
-        url_fskip(pb, 8 + 2*p->nb_records);
+        avio_seek(pb, anm->page_table_offset + MAX_PAGES*6 + (anm->page<<16), SEEK_SET);
+        avio_skip(pb, 8 + 2*p->nb_records);
         anm->record = 0;
     }
 
@@ -208,11 +202,11 @@ repeat:
     }
 
     /* fetch record size */
-    tmp = url_ftell(pb);
-    url_fseek(pb, anm->page_table_offset + MAX_PAGES*6 + (anm->page<<16) +
+    tmp = avio_tell(pb);
+    avio_seek(pb, anm->page_table_offset + MAX_PAGES*6 + (anm->page<<16) +
               8 + anm->record * 2, SEEK_SET);
-    record_size = get_le16(pb);
-    url_fseek(pb, tmp, SEEK_SET);
+    record_size = avio_rl16(pb);
+    avio_seek(pb, tmp, SEEK_SET);
 
     /* fetch record */
     pkt->size = av_get_packet(s->pb, pkt, record_size);
@@ -225,11 +219,11 @@ repeat:
     return 0;
 }
 
-AVInputFormat anm_demuxer = {
-    "anm",
-    NULL_IF_CONFIG_SMALL("Deluxe Paint Animation"),
-    sizeof(AnmDemuxContext),
-    probe,
-    read_header,
-    read_packet,
+AVInputFormat ff_anm_demuxer = {
+    .name           = "anm",
+    .long_name      = NULL_IF_CONFIG_SMALL("Deluxe Paint Animation"),
+    .priv_data_size = sizeof(AnmDemuxContext),
+    .read_probe     = probe,
+    .read_header    = read_header,
+    .read_packet    = read_packet,
 };