annotate libmpdemux/demux_smjpeg.c @ 10111:a570a78537aa

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