annotate libmpdemux/demux_smjpeg.c @ 22454:0f5455fc2d5d

removed unused definition of insertRTPData(); it's not only unused, but conceptually wrong as it passed extradata as first demux_packet to the corresponding demux_stream. Patch by Carl Eugen Hoyos
author nicodvb
date Mon, 05 Mar 2007 22:23:30 +0000
parents d7b2fa4c39da
children 4d81dbdf46b9
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
16175
6b86089c2edd Demuxer modularization
rtognimp
parents: 11109
diff changeset
24 static int smjpeg_check_file(demuxer_t* demuxer){
7382
89cbab549659 added smjpeg demuxer only for nexus' request
alex
parents:
diff changeset
25 int orig_pos = stream_tell(demuxer->stream);
11109
084c271c785e 10l found by Mark Berryman <mplayer@theberrymans.com>
alex
parents: 7382
diff changeset
26 char buf[8];
7382
89cbab549659 added smjpeg demuxer only for nexus' request
alex
parents:
diff changeset
27 int version;
89cbab549659 added smjpeg demuxer only for nexus' request
alex
parents:
diff changeset
28
89cbab549659 added smjpeg demuxer only for nexus' request
alex
parents:
diff changeset
29 mp_msg(MSGT_DEMUX, MSGL_V, "Checking for SMJPEG\n");
89cbab549659 added smjpeg demuxer only for nexus' request
alex
parents:
diff changeset
30
89cbab549659 added smjpeg demuxer only for nexus' request
alex
parents:
diff changeset
31 if (stream_read_word(demuxer->stream) == 0xA)
89cbab549659 added smjpeg demuxer only for nexus' request
alex
parents:
diff changeset
32 {
89cbab549659 added smjpeg demuxer only for nexus' request
alex
parents:
diff changeset
33 stream_read(demuxer->stream, buf, 6);
89cbab549659 added smjpeg demuxer only for nexus' request
alex
parents:
diff changeset
34 buf[7] = 0;
89cbab549659 added smjpeg demuxer only for nexus' request
alex
parents:
diff changeset
35
89cbab549659 added smjpeg demuxer only for nexus' request
alex
parents:
diff changeset
36 if (strncmp("SMJPEG", buf, 6)) {
89cbab549659 added smjpeg demuxer only for nexus' request
alex
parents:
diff changeset
37 mp_msg(MSGT_DEMUX, MSGL_DBG2, "Failed: SMJPEG\n");
89cbab549659 added smjpeg demuxer only for nexus' request
alex
parents:
diff changeset
38 return 0;
89cbab549659 added smjpeg demuxer only for nexus' request
alex
parents:
diff changeset
39 }
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 else
89cbab549659 added smjpeg demuxer only for nexus' request
alex
parents:
diff changeset
42 return 0;
89cbab549659 added smjpeg demuxer only for nexus' request
alex
parents:
diff changeset
43
89cbab549659 added smjpeg demuxer only for nexus' request
alex
parents:
diff changeset
44 version = stream_read_dword(demuxer->stream);
89cbab549659 added smjpeg demuxer only for nexus' request
alex
parents:
diff changeset
45 if (version != 0)
89cbab549659 added smjpeg demuxer only for nexus' request
alex
parents:
diff changeset
46 {
89cbab549659 added smjpeg demuxer only for nexus' request
alex
parents:
diff changeset
47 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
48 version);
89cbab549659 added smjpeg demuxer only for nexus' request
alex
parents:
diff changeset
49 return 0;
89cbab549659 added smjpeg demuxer only for nexus' request
alex
parents:
diff changeset
50 }
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 stream_seek(demuxer->stream, orig_pos);
89cbab549659 added smjpeg demuxer only for nexus' request
alex
parents:
diff changeset
53
16175
6b86089c2edd Demuxer modularization
rtognimp
parents: 11109
diff changeset
54 return DEMUXER_TYPE_SMJPEG;
7382
89cbab549659 added smjpeg demuxer only for nexus' request
alex
parents:
diff changeset
55 }
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 // return value:
89cbab549659 added smjpeg demuxer only for nexus' request
alex
parents:
diff changeset
59 // 0 = EOF or no stream found
89cbab549659 added smjpeg demuxer only for nexus' request
alex
parents:
diff changeset
60 // 1 = successfully read a packet
16175
6b86089c2edd Demuxer modularization
rtognimp
parents: 11109
diff changeset
61 static int demux_smjpeg_fill_buffer(demuxer_t *demux, demux_stream_t *ds)
7382
89cbab549659 added smjpeg demuxer only for nexus' request
alex
parents:
diff changeset
62 {
89cbab549659 added smjpeg demuxer only for nexus' request
alex
parents:
diff changeset
63 int dtype, dsize, dpts;
89cbab549659 added smjpeg demuxer only for nexus' request
alex
parents:
diff changeset
64
89cbab549659 added smjpeg demuxer only for nexus' request
alex
parents:
diff changeset
65 demux->filepos = stream_tell(demux->stream);
89cbab549659 added smjpeg demuxer only for nexus' request
alex
parents:
diff changeset
66
89cbab549659 added smjpeg demuxer only for nexus' request
alex
parents:
diff changeset
67 dtype = stream_read_dword_le(demux->stream);
89cbab549659 added smjpeg demuxer only for nexus' request
alex
parents:
diff changeset
68 dpts = stream_read_dword(demux->stream);
89cbab549659 added smjpeg demuxer only for nexus' request
alex
parents:
diff changeset
69 dsize = stream_read_dword(demux->stream);
89cbab549659 added smjpeg demuxer only for nexus' request
alex
parents:
diff changeset
70
89cbab549659 added smjpeg demuxer only for nexus' request
alex
parents:
diff changeset
71 switch(dtype)
89cbab549659 added smjpeg demuxer only for nexus' request
alex
parents:
diff changeset
72 {
89cbab549659 added smjpeg demuxer only for nexus' request
alex
parents:
diff changeset
73 case mmioFOURCC('s','n','d','D'):
89cbab549659 added smjpeg demuxer only for nexus' request
alex
parents:
diff changeset
74 /* fixme, but no decoder implemented yet */
89cbab549659 added smjpeg demuxer only for nexus' request
alex
parents:
diff changeset
75 ds_read_packet(demux->audio, demux->stream, dsize,
89cbab549659 added smjpeg demuxer only for nexus' request
alex
parents:
diff changeset
76 (float)dpts/1000.0, demux->filepos, 0);
89cbab549659 added smjpeg demuxer only for nexus' request
alex
parents:
diff changeset
77 break;
89cbab549659 added smjpeg demuxer only for nexus' request
alex
parents:
diff changeset
78 case mmioFOURCC('v','i','d','D'):
89cbab549659 added smjpeg demuxer only for nexus' request
alex
parents:
diff changeset
79 ds_read_packet(demux->video, demux->stream, dsize,
89cbab549659 added smjpeg demuxer only for nexus' request
alex
parents:
diff changeset
80 (float)dpts/1000.0, demux->filepos, 0);
89cbab549659 added smjpeg demuxer only for nexus' request
alex
parents:
diff changeset
81 break;
89cbab549659 added smjpeg demuxer only for nexus' request
alex
parents:
diff changeset
82 case mmioFOURCC('D','O','N','E'):
89cbab549659 added smjpeg demuxer only for nexus' request
alex
parents:
diff changeset
83 return 1;
89cbab549659 added smjpeg demuxer only for nexus' request
alex
parents:
diff changeset
84 default:
89cbab549659 added smjpeg demuxer only for nexus' request
alex
parents:
diff changeset
85 return 0;
89cbab549659 added smjpeg demuxer only for nexus' request
alex
parents:
diff changeset
86 }
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 return 1;
89cbab549659 added smjpeg demuxer only for nexus' request
alex
parents:
diff changeset
89 }
89cbab549659 added smjpeg demuxer only for nexus' request
alex
parents:
diff changeset
90
16175
6b86089c2edd Demuxer modularization
rtognimp
parents: 11109
diff changeset
91 static demuxer_t* demux_open_smjpeg(demuxer_t* demuxer){
7382
89cbab549659 added smjpeg demuxer only for nexus' request
alex
parents:
diff changeset
92 sh_video_t* sh_video;
89cbab549659 added smjpeg demuxer only for nexus' request
alex
parents:
diff changeset
93 sh_audio_t* sh_audio;
89cbab549659 added smjpeg demuxer only for nexus' request
alex
parents:
diff changeset
94 unsigned int htype = 0, hleng;
89cbab549659 added smjpeg demuxer only for nexus' request
alex
parents:
diff changeset
95 int i = 0;
89cbab549659 added smjpeg demuxer only for nexus' request
alex
parents:
diff changeset
96
89cbab549659 added smjpeg demuxer only for nexus' request
alex
parents:
diff changeset
97 /* file header */
89cbab549659 added smjpeg demuxer only for nexus' request
alex
parents:
diff changeset
98 stream_skip(demuxer->stream, 8); /* \x00\x0aSMJPEG */
89cbab549659 added smjpeg demuxer only for nexus' request
alex
parents:
diff changeset
99 stream_skip(demuxer->stream, 4);
89cbab549659 added smjpeg demuxer only for nexus' request
alex
parents:
diff changeset
100
89cbab549659 added smjpeg demuxer only for nexus' request
alex
parents:
diff changeset
101 mp_msg(MSGT_DEMUX, MSGL_INFO, "This clip is %d seconds\n",
89cbab549659 added smjpeg demuxer only for nexus' request
alex
parents:
diff changeset
102 stream_read_dword(demuxer->stream));
89cbab549659 added smjpeg demuxer only for nexus' request
alex
parents:
diff changeset
103
89cbab549659 added smjpeg demuxer only for nexus' request
alex
parents:
diff changeset
104 /* stream header */
89cbab549659 added smjpeg demuxer only for nexus' request
alex
parents:
diff changeset
105 while (i < 3)
89cbab549659 added smjpeg demuxer only for nexus' request
alex
parents:
diff changeset
106 {
89cbab549659 added smjpeg demuxer only for nexus' request
alex
parents:
diff changeset
107 i++;
89cbab549659 added smjpeg demuxer only for nexus' request
alex
parents:
diff changeset
108 htype = stream_read_dword_le(demuxer->stream);
89cbab549659 added smjpeg demuxer only for nexus' request
alex
parents:
diff changeset
109 if (htype == mmioFOURCC('H','E','N','D'))
89cbab549659 added smjpeg demuxer only for nexus' request
alex
parents:
diff changeset
110 break;
89cbab549659 added smjpeg demuxer only for nexus' request
alex
parents:
diff changeset
111 hleng = (stream_read_word(demuxer->stream)<<16)|stream_read_word(demuxer->stream);
89cbab549659 added smjpeg demuxer only for nexus' request
alex
parents:
diff changeset
112 switch(htype)
89cbab549659 added smjpeg demuxer only for nexus' request
alex
parents:
diff changeset
113 {
89cbab549659 added smjpeg demuxer only for nexus' request
alex
parents:
diff changeset
114 case mmioFOURCC('_','V','I','D'):
89cbab549659 added smjpeg demuxer only for nexus' request
alex
parents:
diff changeset
115 sh_video = new_sh_video(demuxer, 0);
89cbab549659 added smjpeg demuxer only for nexus' request
alex
parents:
diff changeset
116 demuxer->video->sh = sh_video;
89cbab549659 added smjpeg demuxer only for nexus' request
alex
parents:
diff changeset
117 sh_video->ds = demuxer->video;
89cbab549659 added smjpeg demuxer only for nexus' request
alex
parents:
diff changeset
118
89cbab549659 added smjpeg demuxer only for nexus' request
alex
parents:
diff changeset
119 sh_video->bih = malloc(sizeof(BITMAPINFOHEADER));
89cbab549659 added smjpeg demuxer only for nexus' request
alex
parents:
diff changeset
120 memset(sh_video->bih, 0, sizeof(BITMAPINFOHEADER));
89cbab549659 added smjpeg demuxer only for nexus' request
alex
parents:
diff changeset
121
89cbab549659 added smjpeg demuxer only for nexus' request
alex
parents:
diff changeset
122 stream_skip(demuxer->stream, 4); /* number of frames */
89cbab549659 added smjpeg demuxer only for nexus' request
alex
parents:
diff changeset
123 // sh_video->fps = 24;
89cbab549659 added smjpeg demuxer only for nexus' request
alex
parents:
diff changeset
124 // sh_video->frametime = 1.0f/sh_video->fps;
89cbab549659 added smjpeg demuxer only for nexus' request
alex
parents:
diff changeset
125 sh_video->disp_w = stream_read_word(demuxer->stream);
89cbab549659 added smjpeg demuxer only for nexus' request
alex
parents:
diff changeset
126 sh_video->disp_h = stream_read_word(demuxer->stream);
89cbab549659 added smjpeg demuxer only for nexus' request
alex
parents:
diff changeset
127 sh_video->format = stream_read_dword_le(demuxer->stream);
89cbab549659 added smjpeg demuxer only for nexus' request
alex
parents:
diff changeset
128
89cbab549659 added smjpeg demuxer only for nexus' request
alex
parents:
diff changeset
129 /* these are false values */
89cbab549659 added smjpeg demuxer only for nexus' request
alex
parents:
diff changeset
130 sh_video->bih->biSize = 40;
89cbab549659 added smjpeg demuxer only for nexus' request
alex
parents:
diff changeset
131 sh_video->bih->biWidth = sh_video->disp_w;
89cbab549659 added smjpeg demuxer only for nexus' request
alex
parents:
diff changeset
132 sh_video->bih->biHeight = sh_video->disp_h;
89cbab549659 added smjpeg demuxer only for nexus' request
alex
parents:
diff changeset
133 sh_video->bih->biPlanes = 3;
89cbab549659 added smjpeg demuxer only for nexus' request
alex
parents:
diff changeset
134 sh_video->bih->biBitCount = 12;
89cbab549659 added smjpeg demuxer only for nexus' request
alex
parents:
diff changeset
135 sh_video->bih->biCompression = sh_video->format;
89cbab549659 added smjpeg demuxer only for nexus' request
alex
parents:
diff changeset
136 sh_video->bih->biSizeImage = sh_video->disp_w*sh_video->disp_h;
89cbab549659 added smjpeg demuxer only for nexus' request
alex
parents:
diff changeset
137 break;
89cbab549659 added smjpeg demuxer only for nexus' request
alex
parents:
diff changeset
138 case mmioFOURCC('_','S','N','D'):
89cbab549659 added smjpeg demuxer only for nexus' request
alex
parents:
diff changeset
139 sh_audio = new_sh_audio(demuxer, 0);
89cbab549659 added smjpeg demuxer only for nexus' request
alex
parents:
diff changeset
140 demuxer->audio->sh = sh_audio;
89cbab549659 added smjpeg demuxer only for nexus' request
alex
parents:
diff changeset
141 sh_audio->ds = demuxer->audio;
89cbab549659 added smjpeg demuxer only for nexus' request
alex
parents:
diff changeset
142
89cbab549659 added smjpeg demuxer only for nexus' request
alex
parents:
diff changeset
143 sh_audio->wf = malloc(sizeof(WAVEFORMATEX));
89cbab549659 added smjpeg demuxer only for nexus' request
alex
parents:
diff changeset
144 memset(sh_audio->wf, 0, sizeof(WAVEFORMATEX));
89cbab549659 added smjpeg demuxer only for nexus' request
alex
parents:
diff changeset
145
89cbab549659 added smjpeg demuxer only for nexus' request
alex
parents:
diff changeset
146 sh_audio->samplerate = stream_read_word(demuxer->stream);
89cbab549659 added smjpeg demuxer only for nexus' request
alex
parents:
diff changeset
147 sh_audio->wf->wBitsPerSample = stream_read_char(demuxer->stream);
89cbab549659 added smjpeg demuxer only for nexus' request
alex
parents:
diff changeset
148 sh_audio->channels = stream_read_char(demuxer->stream);
89cbab549659 added smjpeg demuxer only for nexus' request
alex
parents:
diff changeset
149 sh_audio->format = stream_read_dword_le(demuxer->stream);
89cbab549659 added smjpeg demuxer only for nexus' request
alex
parents:
diff changeset
150 sh_audio->wf->wFormatTag = sh_audio->format;
89cbab549659 added smjpeg demuxer only for nexus' request
alex
parents:
diff changeset
151 sh_audio->wf->nChannels = sh_audio->channels;
89cbab549659 added smjpeg demuxer only for nexus' request
alex
parents:
diff changeset
152 sh_audio->wf->nSamplesPerSec = sh_audio->samplerate;
89cbab549659 added smjpeg demuxer only for nexus' request
alex
parents:
diff changeset
153 sh_audio->wf->nAvgBytesPerSec = sh_audio->wf->nChannels*
89cbab549659 added smjpeg demuxer only for nexus' request
alex
parents:
diff changeset
154 sh_audio->wf->wBitsPerSample*sh_audio->wf->nSamplesPerSec/8;
89cbab549659 added smjpeg demuxer only for nexus' request
alex
parents:
diff changeset
155 sh_audio->wf->nBlockAlign = sh_audio->channels *2;
89cbab549659 added smjpeg demuxer only for nexus' request
alex
parents:
diff changeset
156 sh_audio->wf->cbSize = 0;
89cbab549659 added smjpeg demuxer only for nexus' request
alex
parents:
diff changeset
157 break;
89cbab549659 added smjpeg demuxer only for nexus' request
alex
parents:
diff changeset
158 case mmioFOURCC('_','T','X','T'):
89cbab549659 added smjpeg demuxer only for nexus' request
alex
parents:
diff changeset
159 stream_skip(demuxer->stream, stream_read_dword(demuxer->stream));
89cbab549659 added smjpeg demuxer only for nexus' request
alex
parents:
diff changeset
160 break;
89cbab549659 added smjpeg demuxer only for nexus' request
alex
parents:
diff changeset
161 }
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 demuxer->seekable = 0;
89cbab549659 added smjpeg demuxer only for nexus' request
alex
parents:
diff changeset
165
16175
6b86089c2edd Demuxer modularization
rtognimp
parents: 11109
diff changeset
166 return demuxer;
7382
89cbab549659 added smjpeg demuxer only for nexus' request
alex
parents:
diff changeset
167 }
89cbab549659 added smjpeg demuxer only for nexus' request
alex
parents:
diff changeset
168
16175
6b86089c2edd Demuxer modularization
rtognimp
parents: 11109
diff changeset
169 static void demux_close_smjpeg(demuxer_t *demuxer)
7382
89cbab549659 added smjpeg demuxer only for nexus' request
alex
parents:
diff changeset
170 {
89cbab549659 added smjpeg demuxer only for nexus' request
alex
parents:
diff changeset
171 return;
89cbab549659 added smjpeg demuxer only for nexus' request
alex
parents:
diff changeset
172 }
16175
6b86089c2edd Demuxer modularization
rtognimp
parents: 11109
diff changeset
173
6b86089c2edd Demuxer modularization
rtognimp
parents: 11109
diff changeset
174
6b86089c2edd Demuxer modularization
rtognimp
parents: 11109
diff changeset
175 demuxer_desc_t demuxer_desc_smjpeg = {
6b86089c2edd Demuxer modularization
rtognimp
parents: 11109
diff changeset
176 "smjpeg demuxer",
6b86089c2edd Demuxer modularization
rtognimp
parents: 11109
diff changeset
177 "smjpeg",
6b86089c2edd Demuxer modularization
rtognimp
parents: 11109
diff changeset
178 "SMJPEG",
6b86089c2edd Demuxer modularization
rtognimp
parents: 11109
diff changeset
179 "Alex Beregszasi",
6b86089c2edd Demuxer modularization
rtognimp
parents: 11109
diff changeset
180 "",
6b86089c2edd Demuxer modularization
rtognimp
parents: 11109
diff changeset
181 DEMUXER_TYPE_SMJPEG,
6b86089c2edd Demuxer modularization
rtognimp
parents: 11109
diff changeset
182 1, // safe autodetect
6b86089c2edd Demuxer modularization
rtognimp
parents: 11109
diff changeset
183 smjpeg_check_file,
6b86089c2edd Demuxer modularization
rtognimp
parents: 11109
diff changeset
184 demux_smjpeg_fill_buffer,
6b86089c2edd Demuxer modularization
rtognimp
parents: 11109
diff changeset
185 demux_open_smjpeg,
6b86089c2edd Demuxer modularization
rtognimp
parents: 11109
diff changeset
186 demux_close_smjpeg,
6b86089c2edd Demuxer modularization
rtognimp
parents: 11109
diff changeset
187 NULL,
6b86089c2edd Demuxer modularization
rtognimp
parents: 11109
diff changeset
188 NULL
6b86089c2edd Demuxer modularization
rtognimp
parents: 11109
diff changeset
189 };