Mercurial > mplayer.hg
annotate libmpdemux/demux_fli.c @ 3573:1b2ee529e7b7
*** empty log message ***
author | gabucino |
---|---|
date | Tue, 18 Dec 2001 00:19:28 +0000 |
parents | 61b89c10e4e8 |
children | e47b32c0eca8 |
rev | line source |
---|---|
3101
637e540831b9
mostly complete support for loading and decoding FLI/FLC animations
melanson
parents:
diff
changeset
|
1 /* |
637e540831b9
mostly complete support for loading and decoding FLI/FLC animations
melanson
parents:
diff
changeset
|
2 FLI file parser for the MPlayer program |
637e540831b9
mostly complete support for loading and decoding FLI/FLC animations
melanson
parents:
diff
changeset
|
3 by Mike Melanson |
637e540831b9
mostly complete support for loading and decoding FLI/FLC animations
melanson
parents:
diff
changeset
|
4 */ |
637e540831b9
mostly complete support for loading and decoding FLI/FLC animations
melanson
parents:
diff
changeset
|
5 |
637e540831b9
mostly complete support for loading and decoding FLI/FLC animations
melanson
parents:
diff
changeset
|
6 #include <stdio.h> |
637e540831b9
mostly complete support for loading and decoding FLI/FLC animations
melanson
parents:
diff
changeset
|
7 #include <stdlib.h> |
637e540831b9
mostly complete support for loading and decoding FLI/FLC animations
melanson
parents:
diff
changeset
|
8 #include <unistd.h> |
637e540831b9
mostly complete support for loading and decoding FLI/FLC animations
melanson
parents:
diff
changeset
|
9 |
637e540831b9
mostly complete support for loading and decoding FLI/FLC animations
melanson
parents:
diff
changeset
|
10 #include "config.h" |
637e540831b9
mostly complete support for loading and decoding FLI/FLC animations
melanson
parents:
diff
changeset
|
11 #include "mp_msg.h" |
637e540831b9
mostly complete support for loading and decoding FLI/FLC animations
melanson
parents:
diff
changeset
|
12 #include "help_mp.h" |
637e540831b9
mostly complete support for loading and decoding FLI/FLC animations
melanson
parents:
diff
changeset
|
13 |
637e540831b9
mostly complete support for loading and decoding FLI/FLC animations
melanson
parents:
diff
changeset
|
14 #include "stream.h" |
637e540831b9
mostly complete support for loading and decoding FLI/FLC animations
melanson
parents:
diff
changeset
|
15 #include "demuxer.h" |
637e540831b9
mostly complete support for loading and decoding FLI/FLC animations
melanson
parents:
diff
changeset
|
16 #include "stheader.h" |
637e540831b9
mostly complete support for loading and decoding FLI/FLC animations
melanson
parents:
diff
changeset
|
17 |
637e540831b9
mostly complete support for loading and decoding FLI/FLC animations
melanson
parents:
diff
changeset
|
18 typedef struct _fli_frames_t { |
637e540831b9
mostly complete support for loading and decoding FLI/FLC animations
melanson
parents:
diff
changeset
|
19 int num_frames; |
637e540831b9
mostly complete support for loading and decoding FLI/FLC animations
melanson
parents:
diff
changeset
|
20 int current_frame; |
637e540831b9
mostly complete support for loading and decoding FLI/FLC animations
melanson
parents:
diff
changeset
|
21 off_t *filepos; |
637e540831b9
mostly complete support for loading and decoding FLI/FLC animations
melanson
parents:
diff
changeset
|
22 unsigned int *frame_size; |
637e540831b9
mostly complete support for loading and decoding FLI/FLC animations
melanson
parents:
diff
changeset
|
23 } fli_frames_t; |
637e540831b9
mostly complete support for loading and decoding FLI/FLC animations
melanson
parents:
diff
changeset
|
24 |
3544 | 25 void demux_seek_fli(demuxer_t *demuxer,float rel_seek_secs,int flags){ |
26 fli_frames_t *frames = (fli_frames_t *)demuxer->priv; | |
27 sh_video_t *sh_video = demuxer->video->sh; | |
28 int newpos=(flags&1)?0:frames->current_frame; | |
29 if(flags&2){ | |
30 // float 0..1 | |
31 newpos+=rel_seek_secs*frames->num_frames; | |
32 } else { | |
33 // secs | |
34 newpos+=rel_seek_secs*sh_video->fps; | |
35 } | |
36 if(newpos<0) newpos=0; else | |
37 if(newpos>frames->num_frames) newpos=frames->num_frames; | |
38 frames->current_frame=newpos; | |
39 } | |
40 | |
3101
637e540831b9
mostly complete support for loading and decoding FLI/FLC animations
melanson
parents:
diff
changeset
|
41 // return value: |
637e540831b9
mostly complete support for loading and decoding FLI/FLC animations
melanson
parents:
diff
changeset
|
42 // 0 = EOF or no stream found |
637e540831b9
mostly complete support for loading and decoding FLI/FLC animations
melanson
parents:
diff
changeset
|
43 // 1 = successfully read a packet |
637e540831b9
mostly complete support for loading and decoding FLI/FLC animations
melanson
parents:
diff
changeset
|
44 int demux_fli_fill_buffer(demuxer_t *demuxer){ |
637e540831b9
mostly complete support for loading and decoding FLI/FLC animations
melanson
parents:
diff
changeset
|
45 fli_frames_t *frames = (fli_frames_t *)demuxer->priv; |
3221 | 46 sh_video_t *sh_video = demuxer->video->sh; |
3101
637e540831b9
mostly complete support for loading and decoding FLI/FLC animations
melanson
parents:
diff
changeset
|
47 |
637e540831b9
mostly complete support for loading and decoding FLI/FLC animations
melanson
parents:
diff
changeset
|
48 // see if the end has been reached |
3544 | 49 if (frames->current_frame >= frames->num_frames) |
3101
637e540831b9
mostly complete support for loading and decoding FLI/FLC animations
melanson
parents:
diff
changeset
|
50 return 0; |
637e540831b9
mostly complete support for loading and decoding FLI/FLC animations
melanson
parents:
diff
changeset
|
51 |
637e540831b9
mostly complete support for loading and decoding FLI/FLC animations
melanson
parents:
diff
changeset
|
52 // fetch the frame from the file |
637e540831b9
mostly complete support for loading and decoding FLI/FLC animations
melanson
parents:
diff
changeset
|
53 // first, position the file properly since ds_read_packet() doesn't |
637e540831b9
mostly complete support for loading and decoding FLI/FLC animations
melanson
parents:
diff
changeset
|
54 // seem to do it, even though it takes a file offset as a parameter |
637e540831b9
mostly complete support for loading and decoding FLI/FLC animations
melanson
parents:
diff
changeset
|
55 stream_seek(demuxer->stream, frames->filepos[frames->current_frame]); |
637e540831b9
mostly complete support for loading and decoding FLI/FLC animations
melanson
parents:
diff
changeset
|
56 ds_read_packet(demuxer->video, |
637e540831b9
mostly complete support for loading and decoding FLI/FLC animations
melanson
parents:
diff
changeset
|
57 demuxer->stream, |
637e540831b9
mostly complete support for loading and decoding FLI/FLC animations
melanson
parents:
diff
changeset
|
58 frames->frame_size[frames->current_frame], |
3221 | 59 frames->current_frame/sh_video->fps, |
3101
637e540831b9
mostly complete support for loading and decoding FLI/FLC animations
melanson
parents:
diff
changeset
|
60 frames->filepos[frames->current_frame], |
3221 | 61 0 /* what flags? -> demuxer.h (alex) */ |
3101
637e540831b9
mostly complete support for loading and decoding FLI/FLC animations
melanson
parents:
diff
changeset
|
62 ); |
637e540831b9
mostly complete support for loading and decoding FLI/FLC animations
melanson
parents:
diff
changeset
|
63 |
637e540831b9
mostly complete support for loading and decoding FLI/FLC animations
melanson
parents:
diff
changeset
|
64 // get the next frame ready |
637e540831b9
mostly complete support for loading and decoding FLI/FLC animations
melanson
parents:
diff
changeset
|
65 frames->current_frame++; |
637e540831b9
mostly complete support for loading and decoding FLI/FLC animations
melanson
parents:
diff
changeset
|
66 |
637e540831b9
mostly complete support for loading and decoding FLI/FLC animations
melanson
parents:
diff
changeset
|
67 return 1; |
637e540831b9
mostly complete support for loading and decoding FLI/FLC animations
melanson
parents:
diff
changeset
|
68 } |
637e540831b9
mostly complete support for loading and decoding FLI/FLC animations
melanson
parents:
diff
changeset
|
69 |
637e540831b9
mostly complete support for loading and decoding FLI/FLC animations
melanson
parents:
diff
changeset
|
70 demuxer_t* demux_open_fli(demuxer_t* demuxer){ |
637e540831b9
mostly complete support for loading and decoding FLI/FLC animations
melanson
parents:
diff
changeset
|
71 sh_video_t *sh_video = NULL; |
637e540831b9
mostly complete support for loading and decoding FLI/FLC animations
melanson
parents:
diff
changeset
|
72 fli_frames_t *frames = (fli_frames_t *)malloc(sizeof(fli_frames_t)); |
637e540831b9
mostly complete support for loading and decoding FLI/FLC animations
melanson
parents:
diff
changeset
|
73 int frame_number; |
3104 | 74 int speed; |
3105
f951f3be126c
fixed FLI demuxer so that it skips over app-specific frames
melanson
parents:
3104
diff
changeset
|
75 unsigned int frame_size; |
f951f3be126c
fixed FLI demuxer so that it skips over app-specific frames
melanson
parents:
3104
diff
changeset
|
76 int magic_number; |
3101
637e540831b9
mostly complete support for loading and decoding FLI/FLC animations
melanson
parents:
diff
changeset
|
77 |
637e540831b9
mostly complete support for loading and decoding FLI/FLC animations
melanson
parents:
diff
changeset
|
78 // go back to the beginning |
637e540831b9
mostly complete support for loading and decoding FLI/FLC animations
melanson
parents:
diff
changeset
|
79 stream_reset(demuxer->stream); |
637e540831b9
mostly complete support for loading and decoding FLI/FLC animations
melanson
parents:
diff
changeset
|
80 stream_seek(demuxer->stream, 0); |
637e540831b9
mostly complete support for loading and decoding FLI/FLC animations
melanson
parents:
diff
changeset
|
81 demuxer->movi_start = 128; |
637e540831b9
mostly complete support for loading and decoding FLI/FLC animations
melanson
parents:
diff
changeset
|
82 demuxer->movi_end = stream_read_dword_le(demuxer->stream); |
637e540831b9
mostly complete support for loading and decoding FLI/FLC animations
melanson
parents:
diff
changeset
|
83 |
3229 | 84 magic_number = stream_read_word_le(demuxer->stream); |
85 | |
86 if ((magic_number != 0xAF11) && (magic_number != 0xAF12)) | |
87 { | |
88 mp_msg(MSGT_DEMUX, MSGL_ERR, "Bad/unknown magic number (%04x)\n", | |
89 magic_number); | |
90 return(NULL); | |
91 } | |
3101
637e540831b9
mostly complete support for loading and decoding FLI/FLC animations
melanson
parents:
diff
changeset
|
92 |
637e540831b9
mostly complete support for loading and decoding FLI/FLC animations
melanson
parents:
diff
changeset
|
93 // fetch the number of frames |
637e540831b9
mostly complete support for loading and decoding FLI/FLC animations
melanson
parents:
diff
changeset
|
94 frames->num_frames = stream_read_word_le(demuxer->stream); |
637e540831b9
mostly complete support for loading and decoding FLI/FLC animations
melanson
parents:
diff
changeset
|
95 frames->current_frame = 0; |
637e540831b9
mostly complete support for loading and decoding FLI/FLC animations
melanson
parents:
diff
changeset
|
96 |
637e540831b9
mostly complete support for loading and decoding FLI/FLC animations
melanson
parents:
diff
changeset
|
97 // allocate enough entries for the indices |
637e540831b9
mostly complete support for loading and decoding FLI/FLC animations
melanson
parents:
diff
changeset
|
98 frames->filepos = (off_t *)malloc(frames->num_frames * sizeof(off_t)); |
637e540831b9
mostly complete support for loading and decoding FLI/FLC animations
melanson
parents:
diff
changeset
|
99 frames->frame_size = (int *)malloc(frames->num_frames * sizeof(int)); |
637e540831b9
mostly complete support for loading and decoding FLI/FLC animations
melanson
parents:
diff
changeset
|
100 |
637e540831b9
mostly complete support for loading and decoding FLI/FLC animations
melanson
parents:
diff
changeset
|
101 // create a new video stream header |
637e540831b9
mostly complete support for loading and decoding FLI/FLC animations
melanson
parents:
diff
changeset
|
102 sh_video = new_sh_video(demuxer, 0); |
637e540831b9
mostly complete support for loading and decoding FLI/FLC animations
melanson
parents:
diff
changeset
|
103 |
637e540831b9
mostly complete support for loading and decoding FLI/FLC animations
melanson
parents:
diff
changeset
|
104 // make sure the demuxer knows about the new video stream header |
637e540831b9
mostly complete support for loading and decoding FLI/FLC animations
melanson
parents:
diff
changeset
|
105 // (even though new_sh_video() ought to take care of it) |
637e540831b9
mostly complete support for loading and decoding FLI/FLC animations
melanson
parents:
diff
changeset
|
106 demuxer->video->sh = sh_video; |
637e540831b9
mostly complete support for loading and decoding FLI/FLC animations
melanson
parents:
diff
changeset
|
107 |
637e540831b9
mostly complete support for loading and decoding FLI/FLC animations
melanson
parents:
diff
changeset
|
108 // make sure that the video demuxer stream header knows about its |
637e540831b9
mostly complete support for loading and decoding FLI/FLC animations
melanson
parents:
diff
changeset
|
109 // parent video demuxer stream (this is getting wacky), or else |
637e540831b9
mostly complete support for loading and decoding FLI/FLC animations
melanson
parents:
diff
changeset
|
110 // video_read_properties() will choke |
637e540831b9
mostly complete support for loading and decoding FLI/FLC animations
melanson
parents:
diff
changeset
|
111 sh_video->ds = demuxer->video; |
637e540831b9
mostly complete support for loading and decoding FLI/FLC animations
melanson
parents:
diff
changeset
|
112 |
637e540831b9
mostly complete support for loading and decoding FLI/FLC animations
melanson
parents:
diff
changeset
|
113 // custom fourcc for internal MPlayer use |
637e540831b9
mostly complete support for loading and decoding FLI/FLC animations
melanson
parents:
diff
changeset
|
114 sh_video->format = mmioFOURCC('F', 'L', 'I', 'C'); |
637e540831b9
mostly complete support for loading and decoding FLI/FLC animations
melanson
parents:
diff
changeset
|
115 |
637e540831b9
mostly complete support for loading and decoding FLI/FLC animations
melanson
parents:
diff
changeset
|
116 sh_video->disp_w = stream_read_word_le(demuxer->stream); |
637e540831b9
mostly complete support for loading and decoding FLI/FLC animations
melanson
parents:
diff
changeset
|
117 sh_video->disp_h = stream_read_word_le(demuxer->stream); |
637e540831b9
mostly complete support for loading and decoding FLI/FLC animations
melanson
parents:
diff
changeset
|
118 |
637e540831b9
mostly complete support for loading and decoding FLI/FLC animations
melanson
parents:
diff
changeset
|
119 // skip the video depth and flags |
637e540831b9
mostly complete support for loading and decoding FLI/FLC animations
melanson
parents:
diff
changeset
|
120 stream_skip(demuxer->stream, 4); |
637e540831b9
mostly complete support for loading and decoding FLI/FLC animations
melanson
parents:
diff
changeset
|
121 |
637e540831b9
mostly complete support for loading and decoding FLI/FLC animations
melanson
parents:
diff
changeset
|
122 // get the speed |
3104 | 123 speed = stream_read_word_le(demuxer->stream); |
124 if (speed == 0) | |
125 speed = 1; | |
3229 | 126 if (magic_number == 0xAF11) |
127 speed *= 1000/70; | |
3104 | 128 sh_video->fps = 1000 / speed; |
3101
637e540831b9
mostly complete support for loading and decoding FLI/FLC animations
melanson
parents:
diff
changeset
|
129 sh_video->frametime = 1/sh_video->fps; |
637e540831b9
mostly complete support for loading and decoding FLI/FLC animations
melanson
parents:
diff
changeset
|
130 |
637e540831b9
mostly complete support for loading and decoding FLI/FLC animations
melanson
parents:
diff
changeset
|
131 // build the frame index |
637e540831b9
mostly complete support for loading and decoding FLI/FLC animations
melanson
parents:
diff
changeset
|
132 stream_seek(demuxer->stream, demuxer->movi_start); |
637e540831b9
mostly complete support for loading and decoding FLI/FLC animations
melanson
parents:
diff
changeset
|
133 frame_number = 0; |
637e540831b9
mostly complete support for loading and decoding FLI/FLC animations
melanson
parents:
diff
changeset
|
134 while ((!stream_eof(demuxer->stream)) && (frame_number < frames->num_frames)) |
637e540831b9
mostly complete support for loading and decoding FLI/FLC animations
melanson
parents:
diff
changeset
|
135 { |
637e540831b9
mostly complete support for loading and decoding FLI/FLC animations
melanson
parents:
diff
changeset
|
136 frames->filepos[frame_number] = stream_tell(demuxer->stream); |
3105
f951f3be126c
fixed FLI demuxer so that it skips over app-specific frames
melanson
parents:
3104
diff
changeset
|
137 frame_size = stream_read_dword_le(demuxer->stream); |
f951f3be126c
fixed FLI demuxer so that it skips over app-specific frames
melanson
parents:
3104
diff
changeset
|
138 magic_number = stream_read_word_le(demuxer->stream); |
f951f3be126c
fixed FLI demuxer so that it skips over app-specific frames
melanson
parents:
3104
diff
changeset
|
139 stream_skip(demuxer->stream, frame_size - 6); |
f951f3be126c
fixed FLI demuxer so that it skips over app-specific frames
melanson
parents:
3104
diff
changeset
|
140 |
f951f3be126c
fixed FLI demuxer so that it skips over app-specific frames
melanson
parents:
3104
diff
changeset
|
141 // if this chunk has the right magic number, index it |
f951f3be126c
fixed FLI demuxer so that it skips over app-specific frames
melanson
parents:
3104
diff
changeset
|
142 if (magic_number == 0xF1FA) |
f951f3be126c
fixed FLI demuxer so that it skips over app-specific frames
melanson
parents:
3104
diff
changeset
|
143 { |
f951f3be126c
fixed FLI demuxer so that it skips over app-specific frames
melanson
parents:
3104
diff
changeset
|
144 frames->frame_size[frame_number] = frame_size; |
f951f3be126c
fixed FLI demuxer so that it skips over app-specific frames
melanson
parents:
3104
diff
changeset
|
145 frame_number++; |
f951f3be126c
fixed FLI demuxer so that it skips over app-specific frames
melanson
parents:
3104
diff
changeset
|
146 } |
3101
637e540831b9
mostly complete support for loading and decoding FLI/FLC animations
melanson
parents:
diff
changeset
|
147 } |
637e540831b9
mostly complete support for loading and decoding FLI/FLC animations
melanson
parents:
diff
changeset
|
148 |
3105
f951f3be126c
fixed FLI demuxer so that it skips over app-specific frames
melanson
parents:
3104
diff
changeset
|
149 // save the actual number of frames indexed |
f951f3be126c
fixed FLI demuxer so that it skips over app-specific frames
melanson
parents:
3104
diff
changeset
|
150 frames->num_frames = frame_number; |
f951f3be126c
fixed FLI demuxer so that it skips over app-specific frames
melanson
parents:
3104
diff
changeset
|
151 |
3101
637e540831b9
mostly complete support for loading and decoding FLI/FLC animations
melanson
parents:
diff
changeset
|
152 demuxer->priv = frames; |
637e540831b9
mostly complete support for loading and decoding FLI/FLC animations
melanson
parents:
diff
changeset
|
153 |
637e540831b9
mostly complete support for loading and decoding FLI/FLC animations
melanson
parents:
diff
changeset
|
154 return demuxer; |
637e540831b9
mostly complete support for loading and decoding FLI/FLC animations
melanson
parents:
diff
changeset
|
155 } |