Patch by Sisir Koppaka (sisir.koppaka at G.M!A.I!L.com)
Originally committed as revision 12808 to svn://svn.ffmpeg.org/ffmpeg/trunk
... | ... |
@@ -135,6 +135,8 @@ different game cutscenes repacked for use with ScummVM. |
135 | 135 |
@tab Audio and video format used in some games by Entertainment Software Partners |
136 | 136 |
@item IFF @tab @tab X |
137 | 137 |
@tab Interchange File Format |
138 |
+@item BFI @tab @tab |
|
139 |
+@tab Brute Force & Ignorance, used in Flash Traffic: City of Angels |
|
138 | 140 |
@end multitable |
139 | 141 |
|
140 | 142 |
@code{X} means that encoding (resp. decoding) is supported. |
... | ... |
@@ -33,6 +33,7 @@ OBJS-$(CONFIG_AVISYNTH) += avisynth.o |
33 | 33 |
OBJS-$(CONFIG_AVM2_MUXER) += swf.o |
34 | 34 |
OBJS-$(CONFIG_AVS_DEMUXER) += avs.o vocdec.o voc.o |
35 | 35 |
OBJS-$(CONFIG_BETHSOFTVID_DEMUXER) += bethsoftvid.o |
36 |
+OBJS-$(CONFIG_BFI_DEMUXER) += bfi.o |
|
36 | 37 |
OBJS-$(CONFIG_C93_DEMUXER) += c93.o vocdec.o voc.o |
37 | 38 |
OBJS-$(CONFIG_CRC_MUXER) += crcenc.o |
38 | 39 |
OBJS-$(CONFIG_DAUD_DEMUXER) += daud.o |
... | ... |
@@ -65,6 +65,7 @@ void av_register_all(void) |
65 | 65 |
REGISTER_MUXER (AVM2, avm2); |
66 | 66 |
REGISTER_DEMUXER (AVS, avs); |
67 | 67 |
REGISTER_DEMUXER (BETHSOFTVID, bethsoftvid); |
68 |
+ REGISTER_DEMUXER (BFI, bfi); |
|
68 | 69 |
REGISTER_DEMUXER (C93, c93); |
69 | 70 |
REGISTER_MUXER (CRC, crc); |
70 | 71 |
REGISTER_DEMUXER (DAUD, daud); |
71 | 72 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,167 @@ |
0 |
+/* |
|
1 |
+ * Brute Force & Ignorance (BFI) demuxer |
|
2 |
+ * Copyright (c) 2008 Sisir Koppaka |
|
3 |
+ * |
|
4 |
+ * This file is part of FFmpeg. |
|
5 |
+ * |
|
6 |
+ * FFmpeg is free software; you can redistribute it and/or |
|
7 |
+ * modify it under the terms of the GNU Lesser General Public |
|
8 |
+ * License as published by the Free Software Foundation; either |
|
9 |
+ * version 2.1 of the License, or (at your option) any later version. |
|
10 |
+ * |
|
11 |
+ * FFmpeg is distributed in the hope that it will be useful, |
|
12 |
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 |
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
14 |
+ * Lesser General Public License for more details. |
|
15 |
+ * |
|
16 |
+ * You should have received a copy of the GNU Lesser General Public |
|
17 |
+ * License along with FFmpeg; if not, write to the Free Software |
|
18 |
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
|
19 |
+ */ |
|
20 |
+ |
|
21 |
+/** |
|
22 |
+ * @file bfi.c |
|
23 |
+ * @brief Brute Force & Ignorance (.bfi) file demuxer |
|
24 |
+ * @author Sisir Koppaka ( sisir.koppaka at gmail dot com ) |
|
25 |
+ * @sa http://wiki.multimedia.cx/index.php?title=BFI |
|
26 |
+ */ |
|
27 |
+ |
|
28 |
+#include "avformat.h" |
|
29 |
+ |
|
30 |
+typedef struct BFIContext { |
|
31 |
+ int nframes; |
|
32 |
+ int audio_frame; |
|
33 |
+ int video_frame; |
|
34 |
+ int video_size; |
|
35 |
+ int avflag; |
|
36 |
+} BFIContext; |
|
37 |
+ |
|
38 |
+static int bfi_probe(AVProbeData * p) |
|
39 |
+{ |
|
40 |
+ /* Check file header */ |
|
41 |
+ if (AV_RL32(p->buf) == MKTAG('B', 'F', '&', 'I')) |
|
42 |
+ return AVPROBE_SCORE_MAX; |
|
43 |
+ else |
|
44 |
+ return 0; |
|
45 |
+} |
|
46 |
+ |
|
47 |
+static int bfi_read_header(AVFormatContext * s, AVFormatParameters * ap) |
|
48 |
+{ |
|
49 |
+ BFIContext *bfi = s->priv_data; |
|
50 |
+ ByteIOContext *pb = s->pb; |
|
51 |
+ AVStream *vstream; |
|
52 |
+ AVStream *astream; |
|
53 |
+ int fps, chunk_header; |
|
54 |
+ |
|
55 |
+ /* Initialize the video codec... */ |
|
56 |
+ vstream = av_new_stream(s, 0); |
|
57 |
+ if (!vstream) |
|
58 |
+ return AVERROR(ENOMEM); |
|
59 |
+ |
|
60 |
+ /* Initialize the audio codec... */ |
|
61 |
+ astream = av_new_stream(s, 0); |
|
62 |
+ if (!astream) |
|
63 |
+ return AVERROR(ENOMEM); |
|
64 |
+ |
|
65 |
+ /* Set the total number of frames. */ |
|
66 |
+ url_fskip(pb, 8); |
|
67 |
+ chunk_header = get_le32(pb); |
|
68 |
+ bfi->nframes = get_le32(pb); |
|
69 |
+ get_le32(pb); |
|
70 |
+ get_le32(pb); |
|
71 |
+ get_le32(pb); |
|
72 |
+ fps = get_le32(pb); |
|
73 |
+ url_fskip(pb, 12); |
|
74 |
+ vstream->codec->width = get_le32(pb); |
|
75 |
+ vstream->codec->height = get_le32(pb); |
|
76 |
+ |
|
77 |
+ /*Load the palette to extradata */ |
|
78 |
+ url_fskip(pb, 8); |
|
79 |
+ vstream->codec->extradata = av_malloc(768); |
|
80 |
+ vstream->codec->extradata_size = 768; |
|
81 |
+ get_buffer(pb, vstream->codec->extradata, |
|
82 |
+ vstream->codec->extradata_size); |
|
83 |
+ |
|
84 |
+ astream->codec->sample_rate = get_le32(pb); |
|
85 |
+ |
|
86 |
+ /* Set up the video codec... */ |
|
87 |
+ av_set_pts_info(vstream, 32, 1, fps); |
|
88 |
+ vstream->codec->codec_type = CODEC_TYPE_VIDEO; |
|
89 |
+ vstream->codec->codec_id = CODEC_ID_BFI; |
|
90 |
+ vstream->codec->pix_fmt = PIX_FMT_PAL8; |
|
91 |
+ |
|
92 |
+ /* Set up the audio codec now... */ |
|
93 |
+ astream->codec->codec_type = CODEC_TYPE_AUDIO; |
|
94 |
+ astream->codec->codec_id = CODEC_ID_PCM_U8; |
|
95 |
+ astream->codec->channels = 1; |
|
96 |
+ astream->codec->bits_per_sample = 8; |
|
97 |
+ astream->codec->bit_rate = |
|
98 |
+ astream->codec->sample_rate * astream->codec->bits_per_sample; |
|
99 |
+ url_fseek(pb, chunk_header - 3, SEEK_SET); |
|
100 |
+ av_set_pts_info(astream, 64, 1, astream->codec->sample_rate); |
|
101 |
+ return 0; |
|
102 |
+} |
|
103 |
+ |
|
104 |
+ |
|
105 |
+static int bfi_read_packet(AVFormatContext * s, AVPacket * pkt) |
|
106 |
+{ |
|
107 |
+ BFIContext *bfi = s->priv_data; |
|
108 |
+ ByteIOContext *pb = s->pb; |
|
109 |
+ int ret, audio_offset, video_offset, chunk_size, audio_size = 0; |
|
110 |
+ if (bfi->nframes == 0 || url_feof(pb)) { |
|
111 |
+ return AVERROR(EIO); |
|
112 |
+ } |
|
113 |
+ |
|
114 |
+ /* If all previous chunks were completely read, then find a new one... */ |
|
115 |
+ if (!bfi->avflag) { |
|
116 |
+ uint32_t state = 0; |
|
117 |
+ while(state != MKTAG('S','A','V','I')){ |
|
118 |
+ if (url_feof(pb)) |
|
119 |
+ return AVERROR(EIO); |
|
120 |
+ state = 256*state + get_byte(pb); |
|
121 |
+ } |
|
122 |
+ /* Now that the chunk's location is confirmed, we proceed... */ |
|
123 |
+ chunk_size = get_le32(pb); |
|
124 |
+ get_le32(pb); |
|
125 |
+ audio_offset = get_le32(pb); |
|
126 |
+ get_le32(pb); |
|
127 |
+ video_offset = get_le32(pb); |
|
128 |
+ audio_size = video_offset - audio_offset; |
|
129 |
+ bfi->video_size = chunk_size - video_offset; |
|
130 |
+ |
|
131 |
+ //Tossing an audio packet at the audio decoder. |
|
132 |
+ ret = av_get_packet(pb, pkt, audio_size); |
|
133 |
+ if (ret < 0) |
|
134 |
+ return ret; |
|
135 |
+ |
|
136 |
+ pkt->pts = bfi->audio_frame; |
|
137 |
+ bfi->audio_frame += ret; |
|
138 |
+ } |
|
139 |
+ |
|
140 |
+ else { |
|
141 |
+ |
|
142 |
+ //Tossing a video packet at the video decoder. |
|
143 |
+ ret = av_get_packet(pb, pkt, bfi->video_size); |
|
144 |
+ if (ret < 0) |
|
145 |
+ return ret; |
|
146 |
+ |
|
147 |
+ pkt->pts = bfi->video_frame; |
|
148 |
+ bfi->video_frame += ret / bfi->video_size; |
|
149 |
+ |
|
150 |
+ /* One less frame to read. A cursory decrement. */ |
|
151 |
+ bfi->nframes--; |
|
152 |
+ } |
|
153 |
+ |
|
154 |
+ bfi->avflag = !bfi->avflag; |
|
155 |
+ pkt->stream_index = bfi->avflag; |
|
156 |
+ return ret; |
|
157 |
+} |
|
158 |
+ |
|
159 |
+AVInputFormat bfi_demuxer = { |
|
160 |
+ "bfi", |
|
161 |
+ "Brute Force & Ignorance", |
|
162 |
+ sizeof(BFIContext), |
|
163 |
+ bfi_probe, |
|
164 |
+ bfi_read_header, |
|
165 |
+ bfi_read_packet, |
|
166 |
+}; |