I sent this message earlier, but it hasn't appeared in the archives so
far...I think the near- 1MB size of the video is disqualifying it. The video
is now here: http://www.youtube.com/watch?v=Bl1b4NL06DU

---------- Forwarded message ----------
From: Sisir Koppaka <[EMAIL PROTECTED]>
Date: Tue, Apr 1, 2008 at 3:48 PM
Subject: BFI Decoder
To: FFmpeg Google SoC list <[email protected]>


Hi,
I posted the demuxer and the log of shell output on the FFmpeg-devel mailing
list here  :
http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/2008-April/044944.html
The decoder is not yet ready for FFmpeg-devel but I think code suggestions
might come in handy at this stage. I've attached the decoder patch + a low
fps(sorry about that!) screencast of the video playing - maybe someone will
be better able to identify the problem here.
I think the problem might be because of this particular part of the
decompression:

2 : skip chain
      if length is zero, read two more bytes of the length
      if length still zero, finish the decompression

      leave (length) bytes of the output unchanged from the last frame

Right now, that's what the decoder does: just skip those bytes. But it may
not be remembering the previous frame.  Reimar recommended me to do what the
nuv.c decoder was doing, so, I'm going through that code now. This is one
issue.

Another issue is regarding 'data'...In Eli's patch, I saw that he was using
data[0], data[1] and data[2] for Y, U and V but the decoders I was referring
used only data[0]. So, that is another confusion.

Please have a look at the screencast, I hope you might be able to recognize
whether there is any issue other than these that I should be looking into.
-----------------
Sisir Koppaka
Index: Makefile
===================================================================
--- Makefile	(revision 1)
+++ Makefile	(working copy)
@@ -42,6 +42,7 @@
 OBJS-$(CONFIG_ATRAC3_DECODER)          += atrac3.o mdct.o fft.o
 OBJS-$(CONFIG_AVS_DECODER)             += avs.o
 OBJS-$(CONFIG_BETHSOFTVID_DECODER)     += bethsoftvideo.o
+OBJS-$(CONFIG_BFI_DECODER)             += bfi.o
 OBJS-$(CONFIG_BMP_DECODER)             += bmp.o
 OBJS-$(CONFIG_BMP_ENCODER)             += bmpenc.o
 OBJS-$(CONFIG_C93_DECODER)             += c93.o
Index: bfi.c
===================================================================
--- bfi.c	(revision 0)
+++ bfi.c	(revision 12)
@@ -0,0 +1,212 @@
+/*
+ * Brute Force & Ignorance(BFI) Video Decoder
+ * Copyright (c) 2008 Sisir Koppaka.
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg 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,
+ * 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
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/*
+ * Based on http://wiki.multimedia.cx/index.php?title=BFI
+ */
+
+#include "avcodec.h"
+#include "common.h"
+#include "bytestream.h"
+
+typedef struct BFIContext {
+    AVCodecContext *avctx;
+    AVFrame frame;
+} BFIContext;
+
+static int bfi_decode_init(AVCodecContext * avctx)
+{
+    BFIContext *bfi = avctx->priv_data;
+    bfi->frame.reference = 1;
+    bfi->frame.buffer_hints =
+        FF_BUFFER_HINTS_VALID | FF_BUFFER_HINTS_READABLE |
+        FF_BUFFER_HINTS_PRESERVE | FF_BUFFER_HINTS_REUSABLE;
+    avctx->pix_fmt = PIX_FMT_PAL8;
+    bfi->frame.data[0] = NULL;
+    av_log(NULL, AV_LOG_INFO, "\n[DECODER] Initialization done.");
+    return 0;
+}
+
+static int bfi_decode_frame(AVCodecContext * avctx, void *data,
+                            int *data_size, const uint8_t * buf,
+                            int buf_size)
+{
+    BFIContext *bfi = avctx->priv_data;
+    uint8_t *dst;
+    uint8_t *dst_offset;
+    uint8_t colour1, colour2;
+    uint32_t *pal;
+    uint8_t *frame_end;
+    unsigned int code, byte, length, offset;
+    int remaining = avctx->width, i, j;
+    const int wrap_to_next_line = bfi->frame.linesize[0] - avctx->width;
+    bfi->avctx = avctx;
+    if (avctx->reget_buffer(avctx, &bfi->frame)) {
+        av_log(avctx, AV_LOG_ERROR, "reget_buffer() failed\n");
+        return -1;
+    }
+    avcodec_set_dimensions(avctx, avctx->width, avctx->height);
+    dst = bfi->frame.data[0];
+    frame_end =
+        bfi->frame.data[0] + bfi->frame.linesize[0] * avctx->height;
+    /* Setting the palette */
+    pal = (uint32_t *) bfi->frame.data[1];
+    for (i = 0; i < 256; i++)
+        *pal++ = AV_RB24(&bfi->avctx->extradata[i * 3]);        //If necessary change avcc to avctx.
+    bfi->frame.palette_has_changed = 1;
+    // av_log(NULL,AV_LOG_INFO, "\n[DECODER] Palette has been set.");        
+    while (dst != frame_end) {
+        byte = *buf++;
+        code = byte >> 6;
+        length = byte & ~0xC0;
+        switch (code) {
+        case 0:                //Normal Chain
+            if (length == 0) {
+                length = bytestream_get_le16(&buf);
+            }
+            while (length > remaining) {
+                bytestream_get_buffer(&buf, dst, remaining);
+                length -= remaining;
+                dst += remaining + wrap_to_next_line;
+                remaining = avctx->width;
+                if (dst == frame_end)
+                    goto finish;
+            }
+            bytestream_get_buffer(&buf, dst, length);
+            remaining -= length;
+            dst += length;
+            // av_log(NULL,AV_LOG_INFO, "\n[DECODER] Normal Chain.");
+            break;
+        case 1:                //Back Chain
+            if (length == 0) {
+                length = bytestream_get_byte(&buf);
+                offset = bytestream_get_le16(&buf);
+            } else {
+                offset = bytestream_get_byte(&buf);
+            }
+            dst_offset = dst - offset;
+            length *= 4;        //Converting dwords to bytes.
+            while (length > remaining) {
+                i = (remaining - (remaining % 4));
+                for (j = 0; j < i; j++)
+                    *dst++ = *dst_offset++;
+                length -= i;
+                while (remaining % 4) {
+                    *dst++ = *dst_offset++;
+                    remaining--;
+                    length--;
+                }
+                dst += wrap_to_next_line;
+                remaining = avctx->width;
+                if (dst == frame_end)
+                    goto finish;
+            }
+            i = length - (length % 4);
+            for (j = 0; j < i; j++) {
+                *dst++ = *dst_offset++;
+            }
+            remaining -= i;
+            length -= i;
+            while (length % 4) {
+                *dst++ = *dst_offset++;
+                remaining--;
+                length--;
+            }
+            //av_log(NULL,AV_LOG_INFO, "\n[DECODER] Back Chain.");
+            break;
+        case 2:                //Skip Chain
+            if (length == 0) {
+                length = bytestream_get_le16(&buf);
+            }
+            if (length == 0)
+                goto finish;
+            while (length > remaining) {
+                dst += remaining + wrap_to_next_line;
+                length -= remaining;
+                remaining = avctx->width;
+                if (dst == frame_end)
+                    goto finish;
+            }
+            dst += length;
+            remaining -= length;
+            //av_log(NULL,AV_LOG_INFO, "\n[DECODER] Skip Chain.");                                  
+            break;
+        case 3:                //Fill Chain
+            if (length == 0) {
+                length = bytestream_get_le16(&buf);
+            }
+            length *= 2;        //Converting words to bytes.
+            colour1 = bytestream_get_byte(&buf);
+            colour2 = bytestream_get_byte(&buf);
+            while (length > remaining) {
+                i = (remaining % 2 ? (remaining - 1) : remaining) / 2;
+                for (j = 0; j < i; j++) {
+                    *dst++ = colour1;
+                    *dst++ = colour2;
+                }
+                if (remaining % 2)
+                    *dst++ = colour1;
+                dst += wrap_to_next_line;
+                length -= remaining;
+                remaining = avctx->width;
+                if (dst == frame_end)
+                    goto finish;
+            }
+            i = (length % 2 ? (length - 1) : length);
+            for (j = 0; j < i; j++) {
+                *dst++ = colour1;
+                *dst++ = colour2;
+            }
+            if (length % 2)
+                *dst++ = colour1;
+            remaining -= length;
+            //av_log(NULL,AV_LOG_INFO, "\n[DECODER] Fill Chain.");
+            break;
+        default:
+            av_log(NULL, AV_LOG_INFO,
+                   "\nOops! Couldn't recognize the 'code'...");
+            break;
+        }
+    }
+  finish:
+    *data_size = sizeof(AVFrame);
+    *(AVFrame *) data = bfi->frame;
+    return buf_size;
+}
+
+static int bfi_decode_close(AVCodecContext * avctx)
+{
+    BFIContext *bfi = avctx->priv_data;
+    if (bfi->frame.data[0])
+        avctx->release_buffer(avctx, &bfi->frame);
+    av_log(NULL, AV_LOG_INFO, "\n[DECODER] Finished decoding the frame.");
+    return 0;
+}
+
+AVCodec bfi_decoder = {
+    .name = "bfi",
+    .type = CODEC_TYPE_VIDEO,
+    .id = CODEC_ID_BFI,
+    .priv_data_size = sizeof(BFIContext),
+    .init = bfi_decode_init,
+    .close = bfi_decode_close,
+    .decode = bfi_decode_frame,
+};
Index: allcodecs.c
===================================================================
--- allcodecs.c	(revision 1)
+++ allcodecs.c	(working copy)
@@ -66,6 +66,7 @@
     REGISTER_ENCDEC  (ASV2, asv2);
     REGISTER_DECODER (AVS, avs);
     REGISTER_DECODER (BETHSOFTVID, bethsoftvid);
+    REGISTER_DECODER (BFI, bfi);
     REGISTER_ENCDEC  (BMP, bmp);
     REGISTER_DECODER (C93, c93);
     REGISTER_DECODER (CAVS, cavs);
Index: avcodec.h
===================================================================
--- avcodec.h	(revision 1)
+++ avcodec.h	(working copy)
@@ -178,6 +178,7 @@
     CODEC_ID_INDEO4,
     CODEC_ID_INDEO5,
     CODEC_ID_MIMIC,
+    CODEC_ID_BFI,
 
     /* various PCM "codecs" */
     CODEC_ID_PCM_S16LE= 0x10000,
_______________________________________________
FFmpeg-soc mailing list
[email protected]
https://lists.mplayerhq.hu/mailman/listinfo/ffmpeg-soc

Reply via email to