Originally committed as revision 8587 to svn://svn.ffmpeg.org/ffmpeg/trunk
Diego Biurrun authored on 2007/04/01 23:28:48... | ... |
@@ -901,6 +901,8 @@ library: |
901 | 901 |
@item DXA @tab @tab X |
902 | 902 |
@tab This format is used in non-Windows version of Feeble Files game and |
903 | 903 |
different game cutscenes repacked for use with ScummVM. |
904 |
+@item THP @tab @tab X |
|
905 |
+@tab Used on the Nintendo GameCube (video only) |
|
904 | 906 |
@end multitable |
905 | 907 |
|
906 | 908 |
@code{X} means that encoding (resp. decoding) is supported. |
... | ... |
@@ -130,6 +130,7 @@ void avcodec_register_all(void) |
130 | 130 |
REGISTER_DECODER(SVQ3, svq3); |
131 | 131 |
REGISTER_ENCDEC (TARGA, targa); |
132 | 132 |
REGISTER_DECODER(THEORA, theora); |
133 |
+ REGISTER_DECODER(THP, thp); |
|
133 | 134 |
REGISTER_DECODER(TIERTEXSEQVIDEO, tiertexseqvideo); |
134 | 135 |
REGISTER_DECODER(TIFF, tiff); |
135 | 136 |
REGISTER_DECODER(TRUEMOTION1, truemotion1); |
... | ... |
@@ -158,6 +158,7 @@ enum CodecID { |
158 | 158 |
CODEC_ID_FFH264, |
159 | 159 |
CODEC_ID_DXA, |
160 | 160 |
CODEC_ID_DNXHD, |
161 |
+ CODEC_ID_THP, |
|
161 | 162 |
|
162 | 163 |
/* various pcm "codecs" */ |
163 | 164 |
CODEC_ID_PCM_S16LE= 0x10000, |
... | ... |
@@ -2329,6 +2330,7 @@ extern AVCodec svq1_decoder; |
2329 | 2329 |
extern AVCodec svq3_decoder; |
2330 | 2330 |
extern AVCodec targa_decoder; |
2331 | 2331 |
extern AVCodec theora_decoder; |
2332 |
+extern AVCodec thp_decoder; |
|
2332 | 2333 |
extern AVCodec tiertexseqvideo_decoder; |
2333 | 2334 |
extern AVCodec tiff_decoder; |
2334 | 2335 |
extern AVCodec truemotion1_decoder; |
... | ... |
@@ -2044,6 +2044,8 @@ static int mjpeg_decode_frame(AVCodecContext *avctx, |
2044 | 2044 |
uint8_t x = *(src++); |
2045 | 2045 |
|
2046 | 2046 |
*(dst++) = x; |
2047 |
+ if (avctx->codec_id != CODEC_ID_THP) |
|
2048 |
+ { |
|
2047 | 2049 |
if (x == 0xff) |
2048 | 2050 |
{ |
2049 | 2051 |
while(src<buf_end && x == 0xff) |
... | ... |
@@ -2054,6 +2056,7 @@ static int mjpeg_decode_frame(AVCodecContext *avctx, |
2054 | 2054 |
else if (x) |
2055 | 2055 |
break; |
2056 | 2056 |
} |
2057 |
+ } |
|
2057 | 2058 |
} |
2058 | 2059 |
init_get_bits(&s->gb, s->buffer, (dst - s->buffer)*8); |
2059 | 2060 |
|
... | ... |
@@ -2583,6 +2586,19 @@ AVCodec mjpeg_decoder = { |
2583 | 2583 |
NULL |
2584 | 2584 |
}; |
2585 | 2585 |
|
2586 |
+AVCodec thp_decoder = { |
|
2587 |
+ "thp", |
|
2588 |
+ CODEC_TYPE_VIDEO, |
|
2589 |
+ CODEC_ID_THP, |
|
2590 |
+ sizeof(MJpegDecodeContext), |
|
2591 |
+ mjpeg_decode_init, |
|
2592 |
+ NULL, |
|
2593 |
+ mjpeg_decode_end, |
|
2594 |
+ mjpeg_decode_frame, |
|
2595 |
+ CODEC_CAP_DR1, |
|
2596 |
+ NULL |
|
2597 |
+}; |
|
2598 |
+ |
|
2586 | 2599 |
AVCodec mjpegb_decoder = { |
2587 | 2600 |
"mjpegb", |
2588 | 2601 |
CODEC_TYPE_VIDEO, |
... | ... |
@@ -120,6 +120,7 @@ OBJS-$(CONFIG_SMACKER_DEMUXER) += smacker.o |
120 | 120 |
OBJS-$(CONFIG_SOL_DEMUXER) += sol.o |
121 | 121 |
OBJS-$(CONFIG_SWF_DEMUXER) += swf.o |
122 | 122 |
OBJS-$(CONFIG_SWF_MUXER) += swf.o |
123 |
+OBJS-$(CONFIG_THP_DEMUXER) += thp.o |
|
123 | 124 |
OBJS-$(CONFIG_TIERTEXSEQ_DEMUXER) += tiertexseq.o |
124 | 125 |
OBJS-$(CONFIG_TTA_DEMUXER) += tta.o |
125 | 126 |
OBJS-$(CONFIG_V4L2_DEMUXER) += v4l2.o |
... | ... |
@@ -142,6 +142,7 @@ void av_register_all(void) |
142 | 142 |
REGISTER_MUXDEMUX(SWF, swf); |
143 | 143 |
REGISTER_MUXER (TG2, tg2); |
144 | 144 |
REGISTER_MUXER (TGP, tgp); |
145 |
+ REGISTER_DEMUXER (THP, thp); |
|
145 | 146 |
REGISTER_DEMUXER (TIERTEXSEQ, tiertexseq); |
146 | 147 |
REGISTER_DEMUXER (TTA, tta); |
147 | 148 |
REGISTER_DEMUXER (V4L2, v4l2); |
... | ... |
@@ -168,6 +168,7 @@ extern AVOutputFormat yuv4mpegpipe_muxer; |
168 | 168 |
extern AVInputFormat yuv4mpegpipe_demuxer; |
169 | 169 |
extern AVInputFormat tiertexseq_demuxer; |
170 | 170 |
extern AVInputFormat x11_grab_device_demuxer; |
171 |
+extern AVInputFormat thp_demuxer; |
|
171 | 172 |
|
172 | 173 |
/* raw.c */ |
173 | 174 |
int pcm_read_seek(AVFormatContext *s, |
174 | 175 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,170 @@ |
0 |
+/* |
|
1 |
+ * THP Demuxer |
|
2 |
+ * Copyright (c) 2007 Marco Gerards. |
|
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 |
+#include "avformat.h" |
|
23 |
+#include "allformats.h" |
|
24 |
+ |
|
25 |
+typedef struct ThpDemuxContext { |
|
26 |
+ int version; |
|
27 |
+ int first_frame; |
|
28 |
+ int first_framesz; |
|
29 |
+ int last_frame; |
|
30 |
+ int compoff; |
|
31 |
+ int framecnt; |
|
32 |
+ AVRational fps; |
|
33 |
+ int frame; |
|
34 |
+ int next_frame; |
|
35 |
+ int next_framesz; |
|
36 |
+ int video_stream_index; |
|
37 |
+ int compcount; |
|
38 |
+ unsigned char components[16]; |
|
39 |
+ AVStream* vst; |
|
40 |
+ int has_audio; |
|
41 |
+} ThpDemuxContext; |
|
42 |
+ |
|
43 |
+ |
|
44 |
+static int thp_probe(AVProbeData *p) |
|
45 |
+{ |
|
46 |
+ /* check file header */ |
|
47 |
+ if (p->buf_size < 4) |
|
48 |
+ return 0; |
|
49 |
+ |
|
50 |
+ if (AV_RL32(p->buf) == MKTAG('T', 'H', 'P', '\0')) |
|
51 |
+ return AVPROBE_SCORE_MAX; |
|
52 |
+ else |
|
53 |
+ return 0; |
|
54 |
+} |
|
55 |
+ |
|
56 |
+static int thp_read_header(AVFormatContext *s, |
|
57 |
+ AVFormatParameters *ap) |
|
58 |
+{ |
|
59 |
+ ThpDemuxContext *thp = s->priv_data; |
|
60 |
+ AVStream *st; |
|
61 |
+ ByteIOContext *pb = &s->pb; |
|
62 |
+ int i; |
|
63 |
+ |
|
64 |
+ /* Read the file header. */ |
|
65 |
+ |
|
66 |
+ get_be32(pb); /* Skip Magic. */ |
|
67 |
+ thp->version = get_be32(pb); |
|
68 |
+ |
|
69 |
+ get_be32(pb); /* Max buf size. */ |
|
70 |
+ get_be32(pb); /* Max samples. */ |
|
71 |
+ |
|
72 |
+ thp->fps = av_d2q(av_int2flt(get_be32(pb)), INT_MAX); |
|
73 |
+ thp->framecnt = get_be32(pb); |
|
74 |
+ thp->first_framesz = get_be32(pb); |
|
75 |
+ get_be32(pb); /* Data size. */ |
|
76 |
+ |
|
77 |
+ thp->compoff = get_be32(pb); |
|
78 |
+ get_be32(pb); /* offsetDataOffset. */ |
|
79 |
+ thp->first_frame = get_be32(pb); |
|
80 |
+ thp->last_frame = get_be32(pb); |
|
81 |
+ |
|
82 |
+ thp->next_framesz = thp->first_framesz; |
|
83 |
+ thp->next_frame = thp->first_frame; |
|
84 |
+ |
|
85 |
+ /* Read the component structure. */ |
|
86 |
+ url_fseek (pb, thp->compoff, SEEK_SET); |
|
87 |
+ thp->compcount = get_be32(pb); |
|
88 |
+ |
|
89 |
+ /* Read the list of component types. */ |
|
90 |
+ get_buffer(pb, thp->components, 16); |
|
91 |
+ |
|
92 |
+ for (i = 0; i < thp->compcount; i++) { |
|
93 |
+ if (thp->components[i] == 0) { |
|
94 |
+ if (thp->vst != 0) |
|
95 |
+ break; |
|
96 |
+ |
|
97 |
+ /* Video component. */ |
|
98 |
+ st = av_new_stream(s, 0); |
|
99 |
+ if (!st) |
|
100 |
+ return AVERROR_NOMEM; |
|
101 |
+ |
|
102 |
+ /* The denominator and numerator are switched because 1/fps |
|
103 |
+ is required. */ |
|
104 |
+ av_set_pts_info(st, 64, thp->fps.den, thp->fps.num); |
|
105 |
+ st->codec->codec_type = CODEC_TYPE_VIDEO; |
|
106 |
+ st->codec->codec_id = CODEC_ID_THP; |
|
107 |
+ st->codec->codec_tag = 0; /* no fourcc */ |
|
108 |
+ st->codec->width = get_be32(pb); |
|
109 |
+ st->codec->height = get_be32(pb); |
|
110 |
+ st->codec->sample_rate = av_q2d(thp->fps); |
|
111 |
+ thp->vst = st; |
|
112 |
+ thp->video_stream_index = st->index; |
|
113 |
+ |
|
114 |
+ if (thp->version == 0x11000) |
|
115 |
+ get_be32(pb); /* Unknown. */ |
|
116 |
+ } |
|
117 |
+ else if (thp->components[i] == 1) { |
|
118 |
+ /* XXX: Required for audio playback. */ |
|
119 |
+ thp->has_audio = 1; |
|
120 |
+ } |
|
121 |
+ } |
|
122 |
+ |
|
123 |
+ return 0; |
|
124 |
+} |
|
125 |
+ |
|
126 |
+static int thp_read_packet(AVFormatContext *s, |
|
127 |
+ AVPacket *pkt) |
|
128 |
+{ |
|
129 |
+ ThpDemuxContext *thp = s->priv_data; |
|
130 |
+ ByteIOContext *pb = &s->pb; |
|
131 |
+ int size; |
|
132 |
+ int ret; |
|
133 |
+ |
|
134 |
+ /* Terminate when last frame is reached. */ |
|
135 |
+ if (thp->frame >= thp->framecnt) |
|
136 |
+ return AVERROR_IO; |
|
137 |
+ |
|
138 |
+ url_fseek(pb, thp->next_frame, SEEK_SET); |
|
139 |
+ |
|
140 |
+ /* Locate the next frame and read out its size. */ |
|
141 |
+ thp->next_frame += thp->next_framesz; |
|
142 |
+ thp->next_framesz = get_be32(pb); |
|
143 |
+ |
|
144 |
+ get_be32(pb); /* Previous total size. */ |
|
145 |
+ size = get_be32(pb); /* Total size of this frame. */ |
|
146 |
+ |
|
147 |
+ if (thp->has_audio) |
|
148 |
+ get_be32(pb); /* Audio size. */ |
|
149 |
+ |
|
150 |
+ ret = av_get_packet(pb, pkt, size); |
|
151 |
+ if (ret != size) { |
|
152 |
+ av_free_packet(pkt); |
|
153 |
+ return AVERROR_IO; |
|
154 |
+ } |
|
155 |
+ |
|
156 |
+ pkt->stream_index = thp->video_stream_index; |
|
157 |
+ thp->frame++; |
|
158 |
+ |
|
159 |
+ return 0; |
|
160 |
+} |
|
161 |
+ |
|
162 |
+AVInputFormat thp_demuxer = { |
|
163 |
+ "thp", |
|
164 |
+ "THP", |
|
165 |
+ sizeof(ThpDemuxContext), |
|
166 |
+ thp_probe, |
|
167 |
+ thp_read_header, |
|
168 |
+ thp_read_packet |
|
169 |
+}; |