Mercurial > mplayer.hg
annotate libmpdemux/demux_smjpeg.c @ 12348:9782f90f4f44
typos, wording
author | diego |
---|---|
date | Thu, 29 Apr 2004 13:02:44 +0000 |
parents | 084c271c785e |
children | 6b86089c2edd |
rev | line source |
---|---|
7382 | 1 /* |
2 SMJPEG file parser by Alex Beregszaszi | |
3 | |
4 Only for testing some files. | |
5 Commited only for Nexus' request. | |
6 | |
7 Based on text by Arpi (SMJPEG-format.txt) and later on | |
8 http://www.lokigames.com/development/download/smjpeg/SMJPEG.txt | |
9 */ | |
10 | |
11 #include <stdio.h> | |
12 #include <stdlib.h> | |
13 #include <unistd.h> | |
14 #include <string.h> /* strtok */ | |
15 | |
16 #include "config.h" | |
17 #include "mp_msg.h" | |
18 #include "help_mp.h" | |
19 | |
20 #include "stream.h" | |
21 #include "demuxer.h" | |
22 #include "stheader.h" | |
23 #include "bswap.h" | |
24 | |
25 int smjpeg_check_file(demuxer_t* demuxer){ | |
26 int orig_pos = stream_tell(demuxer->stream); | |
11109
084c271c785e
10l found by Mark Berryman <mplayer@theberrymans.com>
alex
parents:
7382
diff
changeset
|
27 char buf[8]; |
7382 | 28 int version; |
29 | |
30 mp_msg(MSGT_DEMUX, MSGL_V, "Checking for SMJPEG\n"); | |
31 | |
32 if (stream_read_word(demuxer->stream) == 0xA) | |
33 { | |
34 stream_read(demuxer->stream, buf, 6); | |
35 buf[7] = 0; | |
36 | |
37 if (strncmp("SMJPEG", buf, 6)) { | |
38 mp_msg(MSGT_DEMUX, MSGL_DBG2, "Failed: SMJPEG\n"); | |
39 return 0; | |
40 } | |
41 } | |
42 else | |
43 return 0; | |
44 | |
45 version = stream_read_dword(demuxer->stream); | |
46 if (version != 0) | |
47 { | |
48 mp_msg(MSGT_DEMUX, MSGL_ERR, "Unknown version (%d) of SMJPEG. Please report!\n", | |
49 version); | |
50 return 0; | |
51 } | |
52 | |
53 stream_seek(demuxer->stream, orig_pos); | |
54 | |
55 return 1; | |
56 } | |
57 | |
58 | |
59 // return value: | |
60 // 0 = EOF or no stream found | |
61 // 1 = successfully read a packet | |
62 int demux_smjpeg_fill_buffer(demuxer_t *demux) | |
63 { | |
64 int dtype, dsize, dpts; | |
65 | |
66 demux->filepos = stream_tell(demux->stream); | |
67 | |
68 dtype = stream_read_dword_le(demux->stream); | |
69 dpts = stream_read_dword(demux->stream); | |
70 dsize = stream_read_dword(demux->stream); | |
71 | |
72 switch(dtype) | |
73 { | |
74 case mmioFOURCC('s','n','d','D'): | |
75 /* fixme, but no decoder implemented yet */ | |
76 ds_read_packet(demux->audio, demux->stream, dsize, | |
77 (float)dpts/1000.0, demux->filepos, 0); | |
78 break; | |
79 case mmioFOURCC('v','i','d','D'): | |
80 ds_read_packet(demux->video, demux->stream, dsize, | |
81 (float)dpts/1000.0, demux->filepos, 0); | |
82 break; | |
83 case mmioFOURCC('D','O','N','E'): | |
84 return 1; | |
85 default: | |
86 return 0; | |
87 } | |
88 | |
89 return 1; | |
90 } | |
91 | |
92 int demux_open_smjpeg(demuxer_t* demuxer){ | |
93 sh_video_t* sh_video; | |
94 sh_audio_t* sh_audio; | |
95 unsigned int htype = 0, hleng; | |
96 int i = 0; | |
97 | |
98 /* file header */ | |
99 stream_skip(demuxer->stream, 8); /* \x00\x0aSMJPEG */ | |
100 stream_skip(demuxer->stream, 4); | |
101 | |
102 mp_msg(MSGT_DEMUX, MSGL_INFO, "This clip is %d seconds\n", | |
103 stream_read_dword(demuxer->stream)); | |
104 | |
105 /* stream header */ | |
106 while (i < 3) | |
107 { | |
108 i++; | |
109 htype = stream_read_dword_le(demuxer->stream); | |
110 if (htype == mmioFOURCC('H','E','N','D')) | |
111 break; | |
112 hleng = (stream_read_word(demuxer->stream)<<16)|stream_read_word(demuxer->stream); | |
113 switch(htype) | |
114 { | |
115 case mmioFOURCC('_','V','I','D'): | |
116 sh_video = new_sh_video(demuxer, 0); | |
117 demuxer->video->sh = sh_video; | |
118 sh_video->ds = demuxer->video; | |
119 | |
120 sh_video->bih = malloc(sizeof(BITMAPINFOHEADER)); | |
121 memset(sh_video->bih, 0, sizeof(BITMAPINFOHEADER)); | |
122 | |
123 stream_skip(demuxer->stream, 4); /* number of frames */ | |
124 // sh_video->fps = 24; | |
125 // sh_video->frametime = 1.0f/sh_video->fps; | |
126 sh_video->disp_w = stream_read_word(demuxer->stream); | |
127 sh_video->disp_h = stream_read_word(demuxer->stream); | |
128 sh_video->format = stream_read_dword_le(demuxer->stream); | |
129 | |
130 /* these are false values */ | |
131 sh_video->bih->biSize = 40; | |
132 sh_video->bih->biWidth = sh_video->disp_w; | |
133 sh_video->bih->biHeight = sh_video->disp_h; | |
134 sh_video->bih->biPlanes = 3; | |
135 sh_video->bih->biBitCount = 12; | |
136 sh_video->bih->biCompression = sh_video->format; | |
137 sh_video->bih->biSizeImage = sh_video->disp_w*sh_video->disp_h; | |
138 break; | |
139 case mmioFOURCC('_','S','N','D'): | |
140 sh_audio = new_sh_audio(demuxer, 0); | |
141 demuxer->audio->sh = sh_audio; | |
142 sh_audio->ds = demuxer->audio; | |
143 | |
144 sh_audio->wf = malloc(sizeof(WAVEFORMATEX)); | |
145 memset(sh_audio->wf, 0, sizeof(WAVEFORMATEX)); | |
146 | |
147 sh_audio->samplerate = stream_read_word(demuxer->stream); | |
148 sh_audio->wf->wBitsPerSample = stream_read_char(demuxer->stream); | |
149 sh_audio->channels = stream_read_char(demuxer->stream); | |
150 sh_audio->format = stream_read_dword_le(demuxer->stream); | |
151 sh_audio->wf->wFormatTag = sh_audio->format; | |
152 sh_audio->wf->nChannels = sh_audio->channels; | |
153 sh_audio->wf->nSamplesPerSec = sh_audio->samplerate; | |
154 sh_audio->wf->nAvgBytesPerSec = sh_audio->wf->nChannels* | |
155 sh_audio->wf->wBitsPerSample*sh_audio->wf->nSamplesPerSec/8; | |
156 sh_audio->wf->nBlockAlign = sh_audio->channels *2; | |
157 sh_audio->wf->cbSize = 0; | |
158 break; | |
159 case mmioFOURCC('_','T','X','T'): | |
160 stream_skip(demuxer->stream, stream_read_dword(demuxer->stream)); | |
161 break; | |
162 } | |
163 } | |
164 | |
165 demuxer->seekable = 0; | |
166 | |
167 return 1; | |
168 } | |
169 | |
170 void demux_close_smjpeg(demuxer_t *demuxer) | |
171 { | |
172 return; | |
173 } |