]> git.sesse.net Git - ffmpeg/blobdiff - libavformat/bfi.c
Ignore all generated example binaries
[ffmpeg] / libavformat / bfi.c
index 5b723223209a5aa950ed364629b6b8290abed36b..99371bd4c091355bbfa8953e7b40b2c751a3ceca 100644 (file)
@@ -2,20 +2,20 @@
  * Brute Force & Ignorance (BFI) demuxer
  * Copyright (c) 2008 Sisir Koppaka
  *
- * 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
  * @brief Brute Force & Ignorance (.bfi) file demuxer
  * @author Sisir Koppaka ( sisir.koppaka at gmail dot com )
- * @sa http://wiki.multimedia.cx/index.php?title=BFI
+ * @see http://wiki.multimedia.cx/index.php?title=BFI
  */
 
+#include "libavutil/channel_layout.h"
 #include "libavutil/intreadwrite.h"
 #include "avformat.h"
+#include "internal.h"
 
 typedef struct BFIContext {
     int nframes;
@@ -46,7 +48,7 @@ static int bfi_probe(AVProbeData * p)
         return 0;
 }
 
-static int bfi_read_header(AVFormatContext * s, AVFormatParameters * ap)
+static int bfi_read_header(AVFormatContext * s)
 {
     BFIContext *bfi = s->priv_data;
     AVIOContext *pb = s->pb;
@@ -55,12 +57,12 @@ static int bfi_read_header(AVFormatContext * s, AVFormatParameters * ap)
     int fps, chunk_header;
 
     /* Initialize the video codec... */
-    vstream = av_new_stream(s, 0);
+    vstream = avformat_new_stream(s, NULL);
     if (!vstream)
         return AVERROR(ENOMEM);
 
     /* Initialize the audio codec... */
-    astream = av_new_stream(s, 0);
+    astream = avformat_new_stream(s, NULL);
     if (!astream)
         return AVERROR(ENOMEM);
 
@@ -73,33 +75,34 @@ static int bfi_read_header(AVFormatContext * s, AVFormatParameters * ap)
     avio_rl32(pb);
     fps                    = avio_rl32(pb);
     avio_skip(pb, 12);
-    vstream->codec->width  = avio_rl32(pb);
-    vstream->codec->height = avio_rl32(pb);
+    vstream->codecpar->width  = avio_rl32(pb);
+    vstream->codecpar->height = avio_rl32(pb);
 
     /*Load the palette to extradata */
     avio_skip(pb, 8);
-    vstream->codec->extradata      = av_malloc(768);
-    vstream->codec->extradata_size = 768;
-    avio_read(pb, vstream->codec->extradata,
-               vstream->codec->extradata_size);
+    vstream->codecpar->extradata      = av_malloc(768);
+    vstream->codecpar->extradata_size = 768;
+    avio_read(pb, vstream->codecpar->extradata,
+              vstream->codecpar->extradata_size);
 
-    astream->codec->sample_rate = avio_rl32(pb);
+    astream->codecpar->sample_rate = avio_rl32(pb);
 
     /* Set up the video codec... */
-    av_set_pts_info(vstream, 32, 1, fps);
-    vstream->codec->codec_type = AVMEDIA_TYPE_VIDEO;
-    vstream->codec->codec_id   = CODEC_ID_BFI;
-    vstream->codec->pix_fmt    = PIX_FMT_PAL8;
+    avpriv_set_pts_info(vstream, 32, 1, fps);
+    vstream->codecpar->codec_type = AVMEDIA_TYPE_VIDEO;
+    vstream->codecpar->codec_id   = AV_CODEC_ID_BFI;
+    vstream->codecpar->format     = AV_PIX_FMT_PAL8;
 
     /* Set up the audio codec now... */
-    astream->codec->codec_type      = AVMEDIA_TYPE_AUDIO;
-    astream->codec->codec_id        = CODEC_ID_PCM_U8;
-    astream->codec->channels        = 1;
-    astream->codec->bits_per_coded_sample = 8;
-    astream->codec->bit_rate        =
-        astream->codec->sample_rate * astream->codec->bits_per_coded_sample;
+    astream->codecpar->codec_type      = AVMEDIA_TYPE_AUDIO;
+    astream->codecpar->codec_id        = AV_CODEC_ID_PCM_U8;
+    astream->codecpar->channels        = 1;
+    astream->codecpar->channel_layout  = AV_CH_LAYOUT_MONO;
+    astream->codecpar->bits_per_coded_sample = 8;
+    astream->codecpar->bit_rate        =
+        astream->codecpar->sample_rate * astream->codecpar->bits_per_coded_sample;
     avio_seek(pb, chunk_header - 3, SEEK_SET);
-    av_set_pts_info(astream, 64, 1, astream->codec->sample_rate);
+    avpriv_set_pts_info(astream, 64, 1, astream->codecpar->sample_rate);
     return 0;
 }
 
@@ -129,6 +132,10 @@ static int bfi_read_packet(AVFormatContext * s, AVPacket * pkt)
         video_offset    = avio_rl32(pb);
         audio_size      = video_offset - audio_offset;
         bfi->video_size = chunk_size - video_offset;
+        if (audio_size < 0 || bfi->video_size < 0) {
+            av_log(s, AV_LOG_ERROR, "Invalid audio/video offsets or chunk size\n");
+            return AVERROR_INVALIDDATA;
+        }
 
         //Tossing an audio packet at the audio decoder.
         ret = av_get_packet(pb, pkt, audio_size);
@@ -137,9 +144,7 @@ static int bfi_read_packet(AVFormatContext * s, AVPacket * pkt)
 
         pkt->pts          = bfi->audio_frame;
         bfi->audio_frame += ret;
-    }
-
-    else {
+    } else if (bfi->video_size > 0) {
 
         //Tossing a video packet at the video decoder.
         ret = av_get_packet(pb, pkt, bfi->video_size);
@@ -151,6 +156,9 @@ static int bfi_read_packet(AVFormatContext * s, AVPacket * pkt)
 
         /* One less frame to read. A cursory decrement. */
         bfi->nframes--;
+    } else {
+        /* Empty video packet */
+        ret = AVERROR(EAGAIN);
     }
 
     bfi->avflag       = !bfi->avflag;
@@ -159,10 +167,10 @@ static int bfi_read_packet(AVFormatContext * s, AVPacket * pkt)
 }
 
 AVInputFormat ff_bfi_demuxer = {
-    "bfi",
-    NULL_IF_CONFIG_SMALL("Brute Force & Ignorance"),
-    sizeof(BFIContext),
-    bfi_probe,
-    bfi_read_header,
-    bfi_read_packet,
+    .name           = "bfi",
+    .long_name      = NULL_IF_CONFIG_SMALL("Brute Force & Ignorance"),
+    .priv_data_size = sizeof(BFIContext),
+    .read_probe     = bfi_probe,
+    .read_header    = bfi_read_header,
+    .read_packet    = bfi_read_packet,
 };