annotate libmpdemux/demux_viv.c @ 4994:e74227031a12

dr + libmpcodecs
author arpi
date Fri, 08 Mar 2002 20:17:33 +0000
parents 760481d8421c
children 3898967fcc96
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2687
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
1 // VIVO file parser by A'rpi
3471
e5aae38e6a09 hacked audio support to work with acm
alex
parents: 3439
diff changeset
2 // VIVO text header parser and audio support by alex
2687
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
3
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
4 #include <stdio.h>
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
5 #include <stdlib.h>
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
6 #include <unistd.h>
2928
3f8798f1f4bc some minor fixes
alex
parents: 2809
diff changeset
7 #include <string.h> /* strtok */
2687
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
8
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
9 #include "config.h"
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
10 #include "mp_msg.h"
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
11 #include "help_mp.h"
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
12
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
13 #include "stream.h"
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
14 #include "demuxer.h"
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
15 #include "stheader.h"
3471
e5aae38e6a09 hacked audio support to work with acm
alex
parents: 3439
diff changeset
16 #include "bswap.h"
2687
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
17
3502
1ff0ff94ac91 added -vivo subconfig
alex
parents: 3471
diff changeset
18 /* parameters ! */
3503
7aed2edd99ab -vivo version option added
alex
parents: 3502
diff changeset
19 int vivo_param_version = -1;
3502
1ff0ff94ac91 added -vivo subconfig
alex
parents: 3471
diff changeset
20 char *vivo_param_acodec = NULL;
1ff0ff94ac91 added -vivo subconfig
alex
parents: 3471
diff changeset
21 int vivo_param_abitrate = -1;
1ff0ff94ac91 added -vivo subconfig
alex
parents: 3471
diff changeset
22 int vivo_param_samplerate = -1;
1ff0ff94ac91 added -vivo subconfig
alex
parents: 3471
diff changeset
23 int vivo_param_bytesperblock = -1;
1ff0ff94ac91 added -vivo subconfig
alex
parents: 3471
diff changeset
24 int vivo_param_width = -1;
1ff0ff94ac91 added -vivo subconfig
alex
parents: 3471
diff changeset
25 int vivo_param_height = -1;
1ff0ff94ac91 added -vivo subconfig
alex
parents: 3471
diff changeset
26 int vivo_param_vformat = -1;
1ff0ff94ac91 added -vivo subconfig
alex
parents: 3471
diff changeset
27
3471
e5aae38e6a09 hacked audio support to work with acm
alex
parents: 3439
diff changeset
28 /* VIVO audio standards from vivog723.acm:
e5aae38e6a09 hacked audio support to work with acm
alex
parents: 3439
diff changeset
29
e5aae38e6a09 hacked audio support to work with acm
alex
parents: 3439
diff changeset
30 G.723:
e5aae38e6a09 hacked audio support to work with acm
alex
parents: 3439
diff changeset
31 FormatTag = 0x111
e5aae38e6a09 hacked audio support to work with acm
alex
parents: 3439
diff changeset
32 Channels = 1 - mono
e5aae38e6a09 hacked audio support to work with acm
alex
parents: 3439
diff changeset
33 SamplesPerSec = 8000 - 8khz
e5aae38e6a09 hacked audio support to work with acm
alex
parents: 3439
diff changeset
34 AvgBytesPerSec = 800
e5aae38e6a09 hacked audio support to work with acm
alex
parents: 3439
diff changeset
35 BlockAlign (bytes per block) = 24
e5aae38e6a09 hacked audio support to work with acm
alex
parents: 3439
diff changeset
36 BitsPerSample = 8
e5aae38e6a09 hacked audio support to work with acm
alex
parents: 3439
diff changeset
37
e5aae38e6a09 hacked audio support to work with acm
alex
parents: 3439
diff changeset
38 Siren:
e5aae38e6a09 hacked audio support to work with acm
alex
parents: 3439
diff changeset
39 FormatTag = 0x112
e5aae38e6a09 hacked audio support to work with acm
alex
parents: 3439
diff changeset
40 Channels = 1 - mono
e5aae38e6a09 hacked audio support to work with acm
alex
parents: 3439
diff changeset
41 SamplesPerSec = 16000 - 16khz
e5aae38e6a09 hacked audio support to work with acm
alex
parents: 3439
diff changeset
42 AvgBytesPerSec = 2000
e5aae38e6a09 hacked audio support to work with acm
alex
parents: 3439
diff changeset
43 BlockAlign (bytes per block) = 40
e5aae38e6a09 hacked audio support to work with acm
alex
parents: 3439
diff changeset
44 BitsPerSample = 8
e5aae38e6a09 hacked audio support to work with acm
alex
parents: 3439
diff changeset
45 */
e5aae38e6a09 hacked audio support to work with acm
alex
parents: 3439
diff changeset
46
3502
1ff0ff94ac91 added -vivo subconfig
alex
parents: 3471
diff changeset
47 //enum { VIVO_AUDIO_G723, VIVO_AUDIO_SIREN };
1ff0ff94ac91 added -vivo subconfig
alex
parents: 3471
diff changeset
48
3471
e5aae38e6a09 hacked audio support to work with acm
alex
parents: 3439
diff changeset
49 #define VIVO_AUDIO_G723 1
e5aae38e6a09 hacked audio support to work with acm
alex
parents: 3439
diff changeset
50 #define VIVO_AUDIO_SIREN 2
2687
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
51
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
52 typedef struct {
2784
6caec0df4189 added text block parser
alex
parents: 2695
diff changeset
53 /* generic */
3113
c0e6a39d2ab7 changed to generate fourcc's like: viv<version> -> viv1,viv2
alex
parents: 3069
diff changeset
54 char version;
2784
6caec0df4189 added text block parser
alex
parents: 2695
diff changeset
55 int supported;
6caec0df4189 added text block parser
alex
parents: 2695
diff changeset
56 /* info */
6caec0df4189 added text block parser
alex
parents: 2695
diff changeset
57 char *title;
6caec0df4189 added text block parser
alex
parents: 2695
diff changeset
58 char *author;
6caec0df4189 added text block parser
alex
parents: 2695
diff changeset
59 char *copyright;
6caec0df4189 added text block parser
alex
parents: 2695
diff changeset
60 char *producer;
6caec0df4189 added text block parser
alex
parents: 2695
diff changeset
61 /* video */
6caec0df4189 added text block parser
alex
parents: 2695
diff changeset
62 float fps;
6caec0df4189 added text block parser
alex
parents: 2695
diff changeset
63 int width;
6caec0df4189 added text block parser
alex
parents: 2695
diff changeset
64 int height;
6caec0df4189 added text block parser
alex
parents: 2695
diff changeset
65 int disp_width;
6caec0df4189 added text block parser
alex
parents: 2695
diff changeset
66 int disp_height;
6caec0df4189 added text block parser
alex
parents: 2695
diff changeset
67 /* audio */
3471
e5aae38e6a09 hacked audio support to work with acm
alex
parents: 3439
diff changeset
68 int audio_codec;
e5aae38e6a09 hacked audio support to work with acm
alex
parents: 3439
diff changeset
69 int audio_bitrate;
e5aae38e6a09 hacked audio support to work with acm
alex
parents: 3439
diff changeset
70 int audio_samplerate;
e5aae38e6a09 hacked audio support to work with acm
alex
parents: 3439
diff changeset
71 int audio_bytesperblock;
2687
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
72 } vivo_priv_t;
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
73
2784
6caec0df4189 added text block parser
alex
parents: 2695
diff changeset
74 /* parse all possible extra headers */
3439
192449c155c7 fixed Waveformatheader emu and added vivo1/2 audio detection
alex
parents: 3245
diff changeset
75 /* (audio headers are seperate - mostly with recordtype=3 or 4) */
2784
6caec0df4189 added text block parser
alex
parents: 2695
diff changeset
76 #define TEXTPARSE_ALL 1
6caec0df4189 added text block parser
alex
parents: 2695
diff changeset
77
6caec0df4189 added text block parser
alex
parents: 2695
diff changeset
78 static void vivo_parse_text_header(demuxer_t *demux, int header_len)
6caec0df4189 added text block parser
alex
parents: 2695
diff changeset
79 {
6caec0df4189 added text block parser
alex
parents: 2695
diff changeset
80 vivo_priv_t* priv = demux->priv;
6caec0df4189 added text block parser
alex
parents: 2695
diff changeset
81 char *buf;
6caec0df4189 added text block parser
alex
parents: 2695
diff changeset
82 int i;
6caec0df4189 added text block parser
alex
parents: 2695
diff changeset
83 char *token;
6caec0df4189 added text block parser
alex
parents: 2695
diff changeset
84 char *opt, *param;
3439
192449c155c7 fixed Waveformatheader emu and added vivo1/2 audio detection
alex
parents: 3245
diff changeset
85 int parser_in_audio_block = 0;
2784
6caec0df4189 added text block parser
alex
parents: 2695
diff changeset
86
6caec0df4189 added text block parser
alex
parents: 2695
diff changeset
87 if (!demux->priv)
6caec0df4189 added text block parser
alex
parents: 2695
diff changeset
88 {
6caec0df4189 added text block parser
alex
parents: 2695
diff changeset
89 priv = malloc(sizeof(vivo_priv_t));
6caec0df4189 added text block parser
alex
parents: 2695
diff changeset
90 memset(priv, 0, sizeof(vivo_priv_t));
6caec0df4189 added text block parser
alex
parents: 2695
diff changeset
91 demux->priv = priv;
6caec0df4189 added text block parser
alex
parents: 2695
diff changeset
92 priv->supported = 0;
6caec0df4189 added text block parser
alex
parents: 2695
diff changeset
93 }
6caec0df4189 added text block parser
alex
parents: 2695
diff changeset
94
6caec0df4189 added text block parser
alex
parents: 2695
diff changeset
95 buf = malloc(header_len);
6caec0df4189 added text block parser
alex
parents: 2695
diff changeset
96 opt = malloc(header_len);
6caec0df4189 added text block parser
alex
parents: 2695
diff changeset
97 param = malloc(header_len);
6caec0df4189 added text block parser
alex
parents: 2695
diff changeset
98 stream_read(demux->stream, buf, header_len);
6caec0df4189 added text block parser
alex
parents: 2695
diff changeset
99 i=0;
6caec0df4189 added text block parser
alex
parents: 2695
diff changeset
100 while(i<header_len && buf[i]==0x0D && buf[i+1]==0x0A) i+=2; // skip empty lines
6caec0df4189 added text block parser
alex
parents: 2695
diff changeset
101
6caec0df4189 added text block parser
alex
parents: 2695
diff changeset
102 token = strtok(buf, (char *)&("\x0d\x0a"));
6caec0df4189 added text block parser
alex
parents: 2695
diff changeset
103 while (token && (header_len>2))
6caec0df4189 added text block parser
alex
parents: 2695
diff changeset
104 {
6caec0df4189 added text block parser
alex
parents: 2695
diff changeset
105 header_len -= strlen(token)+2;
6caec0df4189 added text block parser
alex
parents: 2695
diff changeset
106 if (sscanf(token, "%[^:]:%[^\n]", opt, param) != 2)
6caec0df4189 added text block parser
alex
parents: 2695
diff changeset
107 {
6caec0df4189 added text block parser
alex
parents: 2695
diff changeset
108 mp_msg(MSGT_DEMUX, MSGL_V, "viv_text_header_parser: bad line: '%s' at ~%p\n",
6caec0df4189 added text block parser
alex
parents: 2695
diff changeset
109 token, stream_tell(demux->stream));
6caec0df4189 added text block parser
alex
parents: 2695
diff changeset
110 break;
6caec0df4189 added text block parser
alex
parents: 2695
diff changeset
111 }
3471
e5aae38e6a09 hacked audio support to work with acm
alex
parents: 3439
diff changeset
112 mp_dbg(MSGT_DEMUX, MSGL_DBG3, "token: '%s' (%d bytes/%d bytes left)\n",
2784
6caec0df4189 added text block parser
alex
parents: 2695
diff changeset
113 token, strlen(token), header_len);
3471
e5aae38e6a09 hacked audio support to work with acm
alex
parents: 3439
diff changeset
114 mp_dbg(MSGT_DEMUX, MSGL_DBG3, "token => o: '%s', p: '%s'\n",
2784
6caec0df4189 added text block parser
alex
parents: 2695
diff changeset
115 opt, param);
6caec0df4189 added text block parser
alex
parents: 2695
diff changeset
116
6caec0df4189 added text block parser
alex
parents: 2695
diff changeset
117 /* checking versions: only v1 or v2 is suitable (or known?:) */
6caec0df4189 added text block parser
alex
parents: 2695
diff changeset
118 if (!strcmp(opt, "Version"))
6caec0df4189 added text block parser
alex
parents: 2695
diff changeset
119 {
6caec0df4189 added text block parser
alex
parents: 2695
diff changeset
120 mp_msg(MSGT_DEMUX, MSGL_DBG2, "Version: %s\n", param);
2928
3f8798f1f4bc some minor fixes
alex
parents: 2809
diff changeset
121 if (!strncmp(param, "Vivo/1", 6) || !strncmp(param, "Vivo/2", 6))
3113
c0e6a39d2ab7 changed to generate fourcc's like: viv<version> -> viv1,viv2
alex
parents: 3069
diff changeset
122 {
2784
6caec0df4189 added text block parser
alex
parents: 2695
diff changeset
123 priv->supported = 1;
3439
192449c155c7 fixed Waveformatheader emu and added vivo1/2 audio detection
alex
parents: 3245
diff changeset
124 /* save major version for fourcc */
3113
c0e6a39d2ab7 changed to generate fourcc's like: viv<version> -> viv1,viv2
alex
parents: 3069
diff changeset
125 priv->version = param[5];
c0e6a39d2ab7 changed to generate fourcc's like: viv<version> -> viv1,viv2
alex
parents: 3069
diff changeset
126 }
2784
6caec0df4189 added text block parser
alex
parents: 2695
diff changeset
127 }
6caec0df4189 added text block parser
alex
parents: 2695
diff changeset
128
6caec0df4189 added text block parser
alex
parents: 2695
diff changeset
129 /* video specific */
6caec0df4189 added text block parser
alex
parents: 2695
diff changeset
130 if (!strcmp(opt, "FPS"))
6caec0df4189 added text block parser
alex
parents: 2695
diff changeset
131 {
6caec0df4189 added text block parser
alex
parents: 2695
diff changeset
132 mp_msg(MSGT_DEMUX, MSGL_DBG2, "FPS: %f\n", atof(param));
6caec0df4189 added text block parser
alex
parents: 2695
diff changeset
133 priv->fps = atof(param);
6caec0df4189 added text block parser
alex
parents: 2695
diff changeset
134 }
6caec0df4189 added text block parser
alex
parents: 2695
diff changeset
135 if (!strcmp(opt, "Width"))
6caec0df4189 added text block parser
alex
parents: 2695
diff changeset
136 {
6caec0df4189 added text block parser
alex
parents: 2695
diff changeset
137 mp_msg(MSGT_DEMUX, MSGL_DBG2, "Width: %d\n", atoi(param));
6caec0df4189 added text block parser
alex
parents: 2695
diff changeset
138 priv->width = atoi(param);
6caec0df4189 added text block parser
alex
parents: 2695
diff changeset
139 }
6caec0df4189 added text block parser
alex
parents: 2695
diff changeset
140 if (!strcmp(opt, "Height"))
6caec0df4189 added text block parser
alex
parents: 2695
diff changeset
141 {
6caec0df4189 added text block parser
alex
parents: 2695
diff changeset
142 mp_msg(MSGT_DEMUX, MSGL_DBG2, "Height: %d\n", atoi(param));
6caec0df4189 added text block parser
alex
parents: 2695
diff changeset
143 priv->height = atoi(param);
6caec0df4189 added text block parser
alex
parents: 2695
diff changeset
144 }
6caec0df4189 added text block parser
alex
parents: 2695
diff changeset
145 if (!strcmp(opt, "DisplayWidth"))
6caec0df4189 added text block parser
alex
parents: 2695
diff changeset
146 {
6caec0df4189 added text block parser
alex
parents: 2695
diff changeset
147 mp_msg(MSGT_DEMUX, MSGL_DBG2, "Display Width: %d\n", atoi(param));
6caec0df4189 added text block parser
alex
parents: 2695
diff changeset
148 priv->disp_width = atoi(param);
6caec0df4189 added text block parser
alex
parents: 2695
diff changeset
149 }
6caec0df4189 added text block parser
alex
parents: 2695
diff changeset
150 if (!strcmp(opt, "DisplayHeight"))
6caec0df4189 added text block parser
alex
parents: 2695
diff changeset
151 {
6caec0df4189 added text block parser
alex
parents: 2695
diff changeset
152 mp_msg(MSGT_DEMUX, MSGL_DBG2, "Display Height: %d\n", atoi(param));
6caec0df4189 added text block parser
alex
parents: 2695
diff changeset
153 priv->disp_height = atoi(param);
6caec0df4189 added text block parser
alex
parents: 2695
diff changeset
154 }
6caec0df4189 added text block parser
alex
parents: 2695
diff changeset
155
6caec0df4189 added text block parser
alex
parents: 2695
diff changeset
156 /* audio specific */
3439
192449c155c7 fixed Waveformatheader emu and added vivo1/2 audio detection
alex
parents: 3245
diff changeset
157 if (!strcmp(opt, "RecordType"))
192449c155c7 fixed Waveformatheader emu and added vivo1/2 audio detection
alex
parents: 3245
diff changeset
158 {
3471
e5aae38e6a09 hacked audio support to work with acm
alex
parents: 3439
diff changeset
159 /* no audio recordblock by Vivo/1.00, 3 and 4 by Vivo/2.00 */
3439
192449c155c7 fixed Waveformatheader emu and added vivo1/2 audio detection
alex
parents: 3245
diff changeset
160 if ((atoi(param) == 3) || (atoi(param) == 4))
192449c155c7 fixed Waveformatheader emu and added vivo1/2 audio detection
alex
parents: 3245
diff changeset
161 parser_in_audio_block = 1;
192449c155c7 fixed Waveformatheader emu and added vivo1/2 audio detection
alex
parents: 3245
diff changeset
162 else
192449c155c7 fixed Waveformatheader emu and added vivo1/2 audio detection
alex
parents: 3245
diff changeset
163 parser_in_audio_block = 0;
192449c155c7 fixed Waveformatheader emu and added vivo1/2 audio detection
alex
parents: 3245
diff changeset
164 }
2784
6caec0df4189 added text block parser
alex
parents: 2695
diff changeset
165 if (!strcmp(opt, "NominalBitrate"))
6caec0df4189 added text block parser
alex
parents: 2695
diff changeset
166 {
3471
e5aae38e6a09 hacked audio support to work with acm
alex
parents: 3439
diff changeset
167 priv->audio_bitrate = atoi(param);
e5aae38e6a09 hacked audio support to work with acm
alex
parents: 3439
diff changeset
168 if (priv->audio_bitrate == 2000)
e5aae38e6a09 hacked audio support to work with acm
alex
parents: 3439
diff changeset
169 priv->audio_codec = VIVO_AUDIO_SIREN;
e5aae38e6a09 hacked audio support to work with acm
alex
parents: 3439
diff changeset
170 if (priv->audio_bitrate == 800)
e5aae38e6a09 hacked audio support to work with acm
alex
parents: 3439
diff changeset
171 priv->audio_codec = VIVO_AUDIO_G723;
2784
6caec0df4189 added text block parser
alex
parents: 2695
diff changeset
172 }
6caec0df4189 added text block parser
alex
parents: 2695
diff changeset
173 if (!strcmp(opt, "SamplingFrequency"))
6caec0df4189 added text block parser
alex
parents: 2695
diff changeset
174 {
3471
e5aae38e6a09 hacked audio support to work with acm
alex
parents: 3439
diff changeset
175 priv->audio_samplerate = atoi(param);
e5aae38e6a09 hacked audio support to work with acm
alex
parents: 3439
diff changeset
176 if (priv->audio_samplerate == 16000)
e5aae38e6a09 hacked audio support to work with acm
alex
parents: 3439
diff changeset
177 priv->audio_codec = VIVO_AUDIO_SIREN;
e5aae38e6a09 hacked audio support to work with acm
alex
parents: 3439
diff changeset
178 if (priv->audio_samplerate == 8000)
e5aae38e6a09 hacked audio support to work with acm
alex
parents: 3439
diff changeset
179 priv->audio_codec = VIVO_AUDIO_G723;
2784
6caec0df4189 added text block parser
alex
parents: 2695
diff changeset
180 }
3439
192449c155c7 fixed Waveformatheader emu and added vivo1/2 audio detection
alex
parents: 3245
diff changeset
181 if (!strcmp(opt, "Length") && (parser_in_audio_block == 1))
192449c155c7 fixed Waveformatheader emu and added vivo1/2 audio detection
alex
parents: 3245
diff changeset
182 {
3471
e5aae38e6a09 hacked audio support to work with acm
alex
parents: 3439
diff changeset
183 priv->audio_bytesperblock = atoi(param); /* 24 or 40 kbps */
e5aae38e6a09 hacked audio support to work with acm
alex
parents: 3439
diff changeset
184 if (priv->audio_bytesperblock == 40)
e5aae38e6a09 hacked audio support to work with acm
alex
parents: 3439
diff changeset
185 priv->audio_codec = VIVO_AUDIO_SIREN;
e5aae38e6a09 hacked audio support to work with acm
alex
parents: 3439
diff changeset
186 if (priv->audio_bytesperblock == 24)
e5aae38e6a09 hacked audio support to work with acm
alex
parents: 3439
diff changeset
187 priv->audio_codec = VIVO_AUDIO_G723;
3439
192449c155c7 fixed Waveformatheader emu and added vivo1/2 audio detection
alex
parents: 3245
diff changeset
188 }
2784
6caec0df4189 added text block parser
alex
parents: 2695
diff changeset
189
6caec0df4189 added text block parser
alex
parents: 2695
diff changeset
190 /* only for displaying some informations about movie*/
6caec0df4189 added text block parser
alex
parents: 2695
diff changeset
191 if (!strcmp(opt, "Title"))
6caec0df4189 added text block parser
alex
parents: 2695
diff changeset
192 {
3068
572a94255d1e added support for demux_info
alex
parents: 2928
diff changeset
193 demux_info_add(demux, "name", param);
3612
a1522fa7728a x = malloc(strlen(s) + c) ... strcpy(x, s)
pl
parents: 3526
diff changeset
194 priv->title = strdup(param);
2784
6caec0df4189 added text block parser
alex
parents: 2695
diff changeset
195 }
6caec0df4189 added text block parser
alex
parents: 2695
diff changeset
196 if (!strcmp(opt, "Author"))
6caec0df4189 added text block parser
alex
parents: 2695
diff changeset
197 {
3068
572a94255d1e added support for demux_info
alex
parents: 2928
diff changeset
198 demux_info_add(demux, "author", param);
3612
a1522fa7728a x = malloc(strlen(s) + c) ... strcpy(x, s)
pl
parents: 3526
diff changeset
199 priv->author = strdup(param);
2784
6caec0df4189 added text block parser
alex
parents: 2695
diff changeset
200 }
6caec0df4189 added text block parser
alex
parents: 2695
diff changeset
201 if (!strcmp(opt, "Copyright"))
6caec0df4189 added text block parser
alex
parents: 2695
diff changeset
202 {
3068
572a94255d1e added support for demux_info
alex
parents: 2928
diff changeset
203 demux_info_add(demux, "copyright", param);
3612
a1522fa7728a x = malloc(strlen(s) + c) ... strcpy(x, s)
pl
parents: 3526
diff changeset
204 priv->copyright = strdup(param);
2784
6caec0df4189 added text block parser
alex
parents: 2695
diff changeset
205 }
6caec0df4189 added text block parser
alex
parents: 2695
diff changeset
206 if (!strcmp(opt, "Producer"))
6caec0df4189 added text block parser
alex
parents: 2695
diff changeset
207 {
3069
e6bbc5e6a054 wrote a very annoying bug
alex
parents: 3068
diff changeset
208 demux_info_add(demux, "encoder", param);
3612
a1522fa7728a x = malloc(strlen(s) + c) ... strcpy(x, s)
pl
parents: 3526
diff changeset
209 priv->producer = strdup(param);
2784
6caec0df4189 added text block parser
alex
parents: 2695
diff changeset
210 }
6caec0df4189 added text block parser
alex
parents: 2695
diff changeset
211
6caec0df4189 added text block parser
alex
parents: 2695
diff changeset
212 /* get next token */
6caec0df4189 added text block parser
alex
parents: 2695
diff changeset
213 token = strtok(NULL, (char *)&("\x0d\x0a"));
6caec0df4189 added text block parser
alex
parents: 2695
diff changeset
214 }
2788
4a909be26ea1 freeing up space and some debug
alex
parents: 2785
diff changeset
215
4a909be26ea1 freeing up space and some debug
alex
parents: 2785
diff changeset
216 if (buf)
4a909be26ea1 freeing up space and some debug
alex
parents: 2785
diff changeset
217 free(buf);
4a909be26ea1 freeing up space and some debug
alex
parents: 2785
diff changeset
218 if (opt)
4a909be26ea1 freeing up space and some debug
alex
parents: 2785
diff changeset
219 free(opt);
4a909be26ea1 freeing up space and some debug
alex
parents: 2785
diff changeset
220 if (param)
4a909be26ea1 freeing up space and some debug
alex
parents: 2785
diff changeset
221 free(param);
2784
6caec0df4189 added text block parser
alex
parents: 2695
diff changeset
222 }
6caec0df4189 added text block parser
alex
parents: 2695
diff changeset
223
2687
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
224 int vivo_check_file(demuxer_t* demuxer){
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
225 int flags=0;
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
226 int i=0;
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
227 int len;
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
228 int len2;
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
229 int c;
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
230 unsigned char buf[2048+256];
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
231 vivo_priv_t* priv;
2784
6caec0df4189 added text block parser
alex
parents: 2695
diff changeset
232 int orig_pos = stream_tell(demuxer->stream);
2687
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
233
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
234 mp_msg(MSGT_DEMUX,MSGL_V,"Checking for VIVO\n");
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
235
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
236 c=stream_read_char(demuxer->stream);
2792
ad82a618b371 checking for EOF
alex
parents: 2788
diff changeset
237 if(c==-256) return 0;
2687
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
238 len=0;
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
239 while((c=stream_read_char(demuxer->stream))>=0x80){
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
240 len+=0x80*(c-0x80);
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
241 if(len>1024) return 0;
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
242 }
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
243 len+=c;
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
244 printf("header block 1 size: %d\n",len);
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
245 //stream_skip(demuxer->stream,len);
2928
3f8798f1f4bc some minor fixes
alex
parents: 2809
diff changeset
246
3f8798f1f4bc some minor fixes
alex
parents: 2809
diff changeset
247 priv=malloc(sizeof(vivo_priv_t));
3f8798f1f4bc some minor fixes
alex
parents: 2809
diff changeset
248 memset(priv,0,sizeof(vivo_priv_t));
3f8798f1f4bc some minor fixes
alex
parents: 2809
diff changeset
249 demuxer->priv=priv;
2784
6caec0df4189 added text block parser
alex
parents: 2695
diff changeset
250
2805
478202620831 disabled vivo2 scaling (decodes some vivo2 files)
alex
parents: 2792
diff changeset
251 #if 0
2785
c70b93e738e1 vivo_check_file uses also new textparser
alex
parents: 2784
diff changeset
252 vivo_parse_text_header(demuxer, len);
2784
6caec0df4189 added text block parser
alex
parents: 2695
diff changeset
253 if (priv->supported == 0)
6caec0df4189 added text block parser
alex
parents: 2695
diff changeset
254 return 0;
6caec0df4189 added text block parser
alex
parents: 2695
diff changeset
255 #else
2928
3f8798f1f4bc some minor fixes
alex
parents: 2809
diff changeset
256 /* this is enought for check (for now) */
3f8798f1f4bc some minor fixes
alex
parents: 2809
diff changeset
257 stream_read(demuxer->stream,buf,len);
3f8798f1f4bc some minor fixes
alex
parents: 2809
diff changeset
258 buf[len]=0;
3f8798f1f4bc some minor fixes
alex
parents: 2809
diff changeset
259 // printf("VIVO header: '%s'\n",buf);
3f8798f1f4bc some minor fixes
alex
parents: 2809
diff changeset
260
2687
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
261 // parse header:
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
262 i=0;
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
263 while(i<len && buf[i]==0x0D && buf[i+1]==0x0A) i+=2; // skip empty lines
2695
af8b2c0e4dad vivo 2.0 compatibility
arpi
parents: 2687
diff changeset
264 if(strncmp(buf+i,"Version:Vivo/",13)) return 0; // bad version/type!
2784
6caec0df4189 added text block parser
alex
parents: 2695
diff changeset
265 #endif
2687
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
266
2695
af8b2c0e4dad vivo 2.0 compatibility
arpi
parents: 2687
diff changeset
267 #if 0
2687
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
268 c=stream_read_char(demuxer->stream);
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
269 if(c) return 0;
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
270 len2=0;
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
271 while((c=stream_read_char(demuxer->stream))>=0x80){
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
272 len2+=0x80*(c-0x80);
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
273 if(len+len2>2048) return 0;
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
274 }
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
275 len2+=c;
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
276 printf("header block 2 size: %d\n",len2);
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
277 stream_skip(demuxer->stream,len2);
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
278 // stream_read(demuxer->stream,buf+len,len2);
2695
af8b2c0e4dad vivo 2.0 compatibility
arpi
parents: 2687
diff changeset
279 #endif
2687
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
280
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
281 // c=stream_read_char(demuxer->stream);
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
282 // printf("first packet: %02X\n",c);
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
283
2784
6caec0df4189 added text block parser
alex
parents: 2695
diff changeset
284 stream_seek(demuxer->stream, orig_pos);
6caec0df4189 added text block parser
alex
parents: 2695
diff changeset
285
2687
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
286 return 1;
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
287 }
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
288
3733
8dcc18663e60 warning fix
pl
parents: 3612
diff changeset
289 static int audio_pos=0;
8dcc18663e60 warning fix
pl
parents: 3612
diff changeset
290 static int audio_rate=0;
3526
cf787373f0aa vivo A-V sync fixed
arpi
parents: 3503
diff changeset
291
2687
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
292 // return value:
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
293 // 0 = EOF or no stream found
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
294 // 1 = successfully read a packet
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
295 int demux_vivo_fill_buffer(demuxer_t *demux){
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
296 demux_stream_t *ds=NULL;
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
297 int c;
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
298 int len=0;
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
299 int seq;
3245
1e2a87b7cae8 added support for packet 0x82 (from vivodump.c by arpi)
alex
parents: 3113
diff changeset
300 int prefix=0;
2687
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
301 demux->filepos=stream_tell(demux->stream);
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
302
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
303 c=stream_read_char(demux->stream);
2792
ad82a618b371 checking for EOF
alex
parents: 2788
diff changeset
304 if (c == -256) /* EOF */
ad82a618b371 checking for EOF
alex
parents: 2788
diff changeset
305 return 0;
3245
1e2a87b7cae8 added support for packet 0x82 (from vivodump.c by arpi)
alex
parents: 3113
diff changeset
306 // printf("c=%x,%02X\n",c,c&0xf0);
1e2a87b7cae8 added support for packet 0x82 (from vivodump.c by arpi)
alex
parents: 3113
diff changeset
307 if (c == 0x82)
1e2a87b7cae8 added support for packet 0x82 (from vivodump.c by arpi)
alex
parents: 3113
diff changeset
308 {
1e2a87b7cae8 added support for packet 0x82 (from vivodump.c by arpi)
alex
parents: 3113
diff changeset
309 /* ok, this works, but pts calculating from header is required! */
1e2a87b7cae8 added support for packet 0x82 (from vivodump.c by arpi)
alex
parents: 3113
diff changeset
310 #warning "Calculate PTS from picture header!"
1e2a87b7cae8 added support for packet 0x82 (from vivodump.c by arpi)
alex
parents: 3113
diff changeset
311 prefix = 1;
1e2a87b7cae8 added support for packet 0x82 (from vivodump.c by arpi)
alex
parents: 3113
diff changeset
312 c = stream_read_char(demux->stream);
1e2a87b7cae8 added support for packet 0x82 (from vivodump.c by arpi)
alex
parents: 3113
diff changeset
313 printf("packet 0x82(pos=%lu) chunk=%x\n",
1e2a87b7cae8 added support for packet 0x82 (from vivodump.c by arpi)
alex
parents: 3113
diff changeset
314 stream_tell(demux->stream), c);
1e2a87b7cae8 added support for packet 0x82 (from vivodump.c by arpi)
alex
parents: 3113
diff changeset
315 }
2687
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
316 switch(c&0xF0){
2695
af8b2c0e4dad vivo 2.0 compatibility
arpi
parents: 2687
diff changeset
317 case 0x00: // header - skip it!
2784
6caec0df4189 added text block parser
alex
parents: 2695
diff changeset
318 {
2687
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
319 len=stream_read_char(demux->stream);
2695
af8b2c0e4dad vivo 2.0 compatibility
arpi
parents: 2687
diff changeset
320 if(len>=0x80) len=0x80*(len-0x80)+stream_read_char(demux->stream);
af8b2c0e4dad vivo 2.0 compatibility
arpi
parents: 2687
diff changeset
321 printf("vivo extra header: %d bytes\n",len);
2784
6caec0df4189 added text block parser
alex
parents: 2695
diff changeset
322 #ifdef TEXTPARSE_ALL
6caec0df4189 added text block parser
alex
parents: 2695
diff changeset
323 {
6caec0df4189 added text block parser
alex
parents: 2695
diff changeset
324 int pos;
6caec0df4189 added text block parser
alex
parents: 2695
diff changeset
325 /* also try to parse all headers */
6caec0df4189 added text block parser
alex
parents: 2695
diff changeset
326 pos = stream_tell(demux->stream);
6caec0df4189 added text block parser
alex
parents: 2695
diff changeset
327 vivo_parse_text_header(demux, len);
6caec0df4189 added text block parser
alex
parents: 2695
diff changeset
328 stream_seek(demux->stream, pos);
6caec0df4189 added text block parser
alex
parents: 2695
diff changeset
329 }
6caec0df4189 added text block parser
alex
parents: 2695
diff changeset
330 #endif
2687
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
331 break;
2784
6caec0df4189 added text block parser
alex
parents: 2695
diff changeset
332 }
2687
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
333 case 0x10: // video packet
3245
1e2a87b7cae8 added support for packet 0x82 (from vivodump.c by arpi)
alex
parents: 3113
diff changeset
334 if (prefix == 1)
1e2a87b7cae8 added support for packet 0x82 (from vivodump.c by arpi)
alex
parents: 3113
diff changeset
335 len = stream_read_char(demux->stream);
1e2a87b7cae8 added support for packet 0x82 (from vivodump.c by arpi)
alex
parents: 3113
diff changeset
336 else
1e2a87b7cae8 added support for packet 0x82 (from vivodump.c by arpi)
alex
parents: 3113
diff changeset
337 len=128;
2687
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
338 ds=demux->video;
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
339 break;
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
340 case 0x20: // video packet
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
341 len=stream_read_char(demux->stream);
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
342 ds=demux->video;
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
343 break;
3068
572a94255d1e added support for demux_info
alex
parents: 2928
diff changeset
344 case 0x30: // audio packet
3245
1e2a87b7cae8 added support for packet 0x82 (from vivodump.c by arpi)
alex
parents: 3113
diff changeset
345 if (prefix == 1)
1e2a87b7cae8 added support for packet 0x82 (from vivodump.c by arpi)
alex
parents: 3113
diff changeset
346 len = stream_read_char(demux->stream);
1e2a87b7cae8 added support for packet 0x82 (from vivodump.c by arpi)
alex
parents: 3113
diff changeset
347 else
1e2a87b7cae8 added support for packet 0x82 (from vivodump.c by arpi)
alex
parents: 3113
diff changeset
348 len=40; /* 40kbps */
2695
af8b2c0e4dad vivo 2.0 compatibility
arpi
parents: 2687
diff changeset
349 ds=demux->audio;
3526
cf787373f0aa vivo A-V sync fixed
arpi
parents: 3503
diff changeset
350 audio_pos+=len;
2695
af8b2c0e4dad vivo 2.0 compatibility
arpi
parents: 2687
diff changeset
351 break;
2687
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
352 case 0x40: // audio packet
3245
1e2a87b7cae8 added support for packet 0x82 (from vivodump.c by arpi)
alex
parents: 3113
diff changeset
353 if (prefix == 1)
1e2a87b7cae8 added support for packet 0x82 (from vivodump.c by arpi)
alex
parents: 3113
diff changeset
354 len = stream_read_char(demux->stream);
1e2a87b7cae8 added support for packet 0x82 (from vivodump.c by arpi)
alex
parents: 3113
diff changeset
355 else
1e2a87b7cae8 added support for packet 0x82 (from vivodump.c by arpi)
alex
parents: 3113
diff changeset
356 len=24; /* 24kbps */
2687
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
357 ds=demux->audio;
3526
cf787373f0aa vivo A-V sync fixed
arpi
parents: 3503
diff changeset
358 audio_pos+=len;
2687
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
359 break;
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
360 default:
3245
1e2a87b7cae8 added support for packet 0x82 (from vivodump.c by arpi)
alex
parents: 3113
diff changeset
361 mp_msg(MSGT_DEMUX,MSGL_WARN,"VIVO - unknown ID found: %02X at pos %lu contact author!\n",
1e2a87b7cae8 added support for packet 0x82 (from vivodump.c by arpi)
alex
parents: 3113
diff changeset
362 c, stream_tell(demux->stream));
1e2a87b7cae8 added support for packet 0x82 (from vivodump.c by arpi)
alex
parents: 3113
diff changeset
363 return 0;
2687
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
364 }
3245
1e2a87b7cae8 added support for packet 0x82 (from vivodump.c by arpi)
alex
parents: 3113
diff changeset
365
1e2a87b7cae8 added support for packet 0x82 (from vivodump.c by arpi)
alex
parents: 3113
diff changeset
366 // printf("chunk=%x, len=%d\n", c, len);
2687
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
367
2695
af8b2c0e4dad vivo 2.0 compatibility
arpi
parents: 2687
diff changeset
368 if(!ds || ds->id<-1){
2687
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
369 if(len) stream_skip(demux->stream,len);
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
370 return 1;
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
371 }
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
372
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
373 seq=c&0x0F;
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
374
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
375 if(ds->asf_packet){
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
376 if(ds->asf_seq!=seq){
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
377 // closed segment, finalize packet:
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
378 ds_add_packet(ds,ds->asf_packet);
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
379 ds->asf_packet=NULL;
2695
af8b2c0e4dad vivo 2.0 compatibility
arpi
parents: 2687
diff changeset
380 // printf("packet!\n");
2687
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
381 } else {
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
382 // append data to it!
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
383 demux_packet_t* dp=ds->asf_packet;
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
384 dp->buffer=realloc(dp->buffer,dp->len+len);
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
385 //memcpy(dp->buffer+dp->len,data,len);
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
386 stream_read(demux->stream,dp->buffer+dp->len,len);
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
387 mp_dbg(MSGT_DEMUX,MSGL_DBG4,"data appended! %d+%d\n",dp->len,len);
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
388 dp->len+=len;
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
389 // we are ready now.
2695
af8b2c0e4dad vivo 2.0 compatibility
arpi
parents: 2687
diff changeset
390 if((c&0xF0)==0x20) --ds->asf_seq; // hack!
2687
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
391 return 1;
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
392 }
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
393 }
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
394 // create new packet:
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
395 { demux_packet_t* dp;
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
396 dp=new_demux_packet(len);
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
397 //memcpy(dp->buffer,data,len);
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
398 stream_read(demux->stream,dp->buffer,len);
3526
cf787373f0aa vivo A-V sync fixed
arpi
parents: 3503
diff changeset
399 dp->pts=audio_rate?((float)audio_pos/(float)audio_rate):0;
2687
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
400 // dp->flags=keyframe;
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
401 // if(ds==demux->video) printf("ASF time: %8d dur: %5d \n",time,dur);
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
402 dp->pos=demux->filepos;
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
403 ds->asf_packet=dp;
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
404 ds->asf_seq=seq;
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
405 // we are ready now.
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
406 return 1;
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
407 }
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
408
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
409 }
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
410
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
411 static const short h263_format[8][2] = {
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
412 { 0, 0 },
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
413 { 128, 96 },
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
414 { 176, 144 },
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
415 { 352, 288 },
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
416 { 704, 576 },
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
417 { 1408, 1152 },
2784
6caec0df4189 added text block parser
alex
parents: 2695
diff changeset
418 { 320, 240 } // ??????? or 240x180 (found in vivo2) ?
2687
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
419 };
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
420
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
421 static unsigned char* buffer;
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
422 static int bufptr=0;
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
423 static int bitcnt=0;
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
424 static unsigned char buf=0;
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
425 static int format, width, height;
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
426
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
427 static unsigned int x_get_bits(int n){
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
428 unsigned int x=0;
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
429 while(n-->0){
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
430 if(!bitcnt){
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
431 // fill buff
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
432 buf=buffer[bufptr++];
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
433 bitcnt=8;
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
434 }
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
435 //x=(x<<1)|(buf&1);buf>>=1;
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
436 x=(x<<1)|(buf>>7);buf<<=1;
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
437 --bitcnt;
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
438 }
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
439 return x;
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
440 }
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
441
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
442 #define get_bits(xxx,n) x_get_bits(n)
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
443 #define get_bits1(xxx) x_get_bits(1)
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
444 #define skip_bits(xxx,n) x_get_bits(n)
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
445 #define skip_bits1(xxx) x_get_bits(1)
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
446
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
447 /* most is hardcoded. should extend to handle all h263 streams */
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
448 static int h263_decode_picture_header(unsigned char *b_ptr)
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
449 {
2928
3f8798f1f4bc some minor fixes
alex
parents: 2809
diff changeset
450 // int i;
2695
af8b2c0e4dad vivo 2.0 compatibility
arpi
parents: 2687
diff changeset
451
af8b2c0e4dad vivo 2.0 compatibility
arpi
parents: 2687
diff changeset
452 // for(i=0;i<16;i++) printf(" %02X",b_ptr[i]); printf("\n");
2687
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
453
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
454 buffer=b_ptr;
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
455 bufptr=bitcnt=buf=0;
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
456
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
457 /* picture header */
2695
af8b2c0e4dad vivo 2.0 compatibility
arpi
parents: 2687
diff changeset
458 if (get_bits(&s->gb, 22) != 0x20){
af8b2c0e4dad vivo 2.0 compatibility
arpi
parents: 2687
diff changeset
459 printf("bad picture header\n");
2687
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
460 return -1;
2695
af8b2c0e4dad vivo 2.0 compatibility
arpi
parents: 2687
diff changeset
461 }
2687
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
462 skip_bits(&s->gb, 8); /* picture timestamp */
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
463
2695
af8b2c0e4dad vivo 2.0 compatibility
arpi
parents: 2687
diff changeset
464 if (get_bits1(&s->gb) != 1){
af8b2c0e4dad vivo 2.0 compatibility
arpi
parents: 2687
diff changeset
465 printf("bad marker\n");
2687
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
466 return -1; /* marker */
2695
af8b2c0e4dad vivo 2.0 compatibility
arpi
parents: 2687
diff changeset
467 }
af8b2c0e4dad vivo 2.0 compatibility
arpi
parents: 2687
diff changeset
468 if (get_bits1(&s->gb) != 0){
af8b2c0e4dad vivo 2.0 compatibility
arpi
parents: 2687
diff changeset
469 printf("bad h263 id\n");
2687
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
470 return -1; /* h263 id */
2695
af8b2c0e4dad vivo 2.0 compatibility
arpi
parents: 2687
diff changeset
471 }
2687
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
472 skip_bits1(&s->gb); /* split screen off */
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
473 skip_bits1(&s->gb); /* camera off */
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
474 skip_bits1(&s->gb); /* freeze picture release off */
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
475
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
476 format = get_bits(&s->gb, 3);
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
477
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
478 if (format != 7) {
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
479 printf("h263_plus = 0 format = %d\n",format);
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
480 /* H.263v1 */
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
481 width = h263_format[format][0];
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
482 height = h263_format[format][1];
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
483 printf("%d x %d\n",width,height);
2695
af8b2c0e4dad vivo 2.0 compatibility
arpi
parents: 2687
diff changeset
484 // if (!width) return -1;
2687
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
485
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
486 printf("pict_type=%d\n",get_bits1(&s->gb));
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
487 printf("unrestricted_mv=%d\n",get_bits1(&s->gb));
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
488 #if 1
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
489 printf("SAC: %d\n",get_bits1(&s->gb));
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
490 printf("advanced prediction mode: %d\n",get_bits1(&s->gb));
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
491 printf("PB frame: %d\n",get_bits1(&s->gb));
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
492 #else
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
493 if (get_bits1(&s->gb) != 0)
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
494 return -1; /* SAC: off */
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
495 if (get_bits1(&s->gb) != 0)
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
496 return -1; /* advanced prediction mode: off */
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
497 if (get_bits1(&s->gb) != 0)
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
498 return -1; /* not PB frame */
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
499 #endif
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
500 printf("qscale=%d\n",get_bits(&s->gb, 5));
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
501 skip_bits1(&s->gb); /* Continuous Presence Multipoint mode: off */
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
502 } else {
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
503 printf("h263_plus = 1\n");
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
504 /* H.263v2 */
2695
af8b2c0e4dad vivo 2.0 compatibility
arpi
parents: 2687
diff changeset
505 if (get_bits(&s->gb, 3) != 1){
af8b2c0e4dad vivo 2.0 compatibility
arpi
parents: 2687
diff changeset
506 printf("H.263v2 A error\n");
2687
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
507 return -1;
2695
af8b2c0e4dad vivo 2.0 compatibility
arpi
parents: 2687
diff changeset
508 }
af8b2c0e4dad vivo 2.0 compatibility
arpi
parents: 2687
diff changeset
509 if (get_bits(&s->gb, 3) != 6){ /* custom source format */
af8b2c0e4dad vivo 2.0 compatibility
arpi
parents: 2687
diff changeset
510 printf("custom source format\n");
2687
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
511 return -1;
2695
af8b2c0e4dad vivo 2.0 compatibility
arpi
parents: 2687
diff changeset
512 }
2687
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
513 skip_bits(&s->gb, 12);
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
514 skip_bits(&s->gb, 3);
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
515 printf("pict_type=%d\n",get_bits(&s->gb, 3) + 1);
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
516 // if (s->pict_type != I_TYPE &&
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
517 // s->pict_type != P_TYPE)
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
518 // return -1;
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
519 skip_bits(&s->gb, 7);
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
520 skip_bits(&s->gb, 4); /* aspect ratio */
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
521 width = (get_bits(&s->gb, 9) + 1) * 4;
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
522 skip_bits1(&s->gb);
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
523 height = get_bits(&s->gb, 9) * 4;
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
524 printf("%d x %d\n",width,height);
2695
af8b2c0e4dad vivo 2.0 compatibility
arpi
parents: 2687
diff changeset
525 //if (height == 0)
af8b2c0e4dad vivo 2.0 compatibility
arpi
parents: 2687
diff changeset
526 // return -1;
2687
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
527 printf("qscale=%d\n",get_bits(&s->gb, 5));
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
528 }
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
529
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
530 /* PEI */
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
531 while (get_bits1(&s->gb) != 0) {
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
532 skip_bits(&s->gb, 8);
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
533 }
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
534 // s->f_code = 1;
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
535 // s->width = width;
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
536 // s->height = height;
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
537 return 0;
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
538 }
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
539
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
540
2695
af8b2c0e4dad vivo 2.0 compatibility
arpi
parents: 2687
diff changeset
541
2687
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
542 void demux_open_vivo(demuxer_t* demuxer){
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
543 vivo_priv_t* priv=demuxer->priv;
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
544
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
545 if(!ds_fill_buffer(demuxer->video)){
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
546 mp_msg(MSGT_DEMUX,MSGL_ERR,"VIVO: " MSGTR_MissingVideoStreamBug);
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
547 return;
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
548 }
3526
cf787373f0aa vivo A-V sync fixed
arpi
parents: 3503
diff changeset
549
cf787373f0aa vivo A-V sync fixed
arpi
parents: 3503
diff changeset
550 audio_pos=0;
2687
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
551
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
552 h263_decode_picture_header(demuxer->video->buffer);
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
553
3503
7aed2edd99ab -vivo version option added
alex
parents: 3502
diff changeset
554 if (vivo_param_version != -1)
7aed2edd99ab -vivo version option added
alex
parents: 3502
diff changeset
555 priv->version = '0' + vivo_param_version;
2687
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
556
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
557 { sh_video_t* sh=new_sh_video(demuxer,0);
3113
c0e6a39d2ab7 changed to generate fourcc's like: viv<version> -> viv1,viv2
alex
parents: 3069
diff changeset
558
c0e6a39d2ab7 changed to generate fourcc's like: viv<version> -> viv1,viv2
alex
parents: 3069
diff changeset
559 /* viv1, viv2 (for better codecs.conf) */
c0e6a39d2ab7 changed to generate fourcc's like: viv<version> -> viv1,viv2
alex
parents: 3069
diff changeset
560 sh->format = mmioFOURCC('v', 'i', 'v', priv->version);
2784
6caec0df4189 added text block parser
alex
parents: 2695
diff changeset
561 if(!sh->fps)
2928
3f8798f1f4bc some minor fixes
alex
parents: 2809
diff changeset
562 {
2784
6caec0df4189 added text block parser
alex
parents: 2695
diff changeset
563 if (priv->fps)
6caec0df4189 added text block parser
alex
parents: 2695
diff changeset
564 sh->fps=priv->fps;
6caec0df4189 added text block parser
alex
parents: 2695
diff changeset
565 else
6caec0df4189 added text block parser
alex
parents: 2695
diff changeset
566 sh->fps=15.0f;
2928
3f8798f1f4bc some minor fixes
alex
parents: 2809
diff changeset
567 }
2687
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
568 sh->frametime=1.0f/sh->fps;
2805
478202620831 disabled vivo2 scaling (decodes some vivo2 files)
alex
parents: 2792
diff changeset
569
3502
1ff0ff94ac91 added -vivo subconfig
alex
parents: 3471
diff changeset
570 /* XXX: FIXME: can't scale image. */
1ff0ff94ac91 added -vivo subconfig
alex
parents: 3471
diff changeset
571 /* hotfix to disable: */
2805
478202620831 disabled vivo2 scaling (decodes some vivo2 files)
alex
parents: 2792
diff changeset
572 priv->disp_width = priv->width;
478202620831 disabled vivo2 scaling (decodes some vivo2 files)
alex
parents: 2792
diff changeset
573 priv->disp_height = priv->height;
478202620831 disabled vivo2 scaling (decodes some vivo2 files)
alex
parents: 2792
diff changeset
574
3502
1ff0ff94ac91 added -vivo subconfig
alex
parents: 3471
diff changeset
575 if (vivo_param_width != -1)
1ff0ff94ac91 added -vivo subconfig
alex
parents: 3471
diff changeset
576 priv->disp_width = priv->width = vivo_param_width;
1ff0ff94ac91 added -vivo subconfig
alex
parents: 3471
diff changeset
577
1ff0ff94ac91 added -vivo subconfig
alex
parents: 3471
diff changeset
578 if (vivo_param_height != -1)
1ff0ff94ac91 added -vivo subconfig
alex
parents: 3471
diff changeset
579 priv->disp_height = priv->height = vivo_param_height;
1ff0ff94ac91 added -vivo subconfig
alex
parents: 3471
diff changeset
580
1ff0ff94ac91 added -vivo subconfig
alex
parents: 3471
diff changeset
581 if (vivo_param_vformat != -1)
1ff0ff94ac91 added -vivo subconfig
alex
parents: 3471
diff changeset
582 {
1ff0ff94ac91 added -vivo subconfig
alex
parents: 3471
diff changeset
583 priv->disp_width = priv->width = h263_format[vivo_param_vformat][0];
1ff0ff94ac91 added -vivo subconfig
alex
parents: 3471
diff changeset
584 priv->disp_height = priv->height = h263_format[vivo_param_vformat][1];
1ff0ff94ac91 added -vivo subconfig
alex
parents: 3471
diff changeset
585 }
1ff0ff94ac91 added -vivo subconfig
alex
parents: 3471
diff changeset
586
2784
6caec0df4189 added text block parser
alex
parents: 2695
diff changeset
587 if (priv->disp_width)
6caec0df4189 added text block parser
alex
parents: 2695
diff changeset
588 sh->disp_w = priv->disp_width;
6caec0df4189 added text block parser
alex
parents: 2695
diff changeset
589 else
6caec0df4189 added text block parser
alex
parents: 2695
diff changeset
590 sh->disp_w = width;
6caec0df4189 added text block parser
alex
parents: 2695
diff changeset
591 if (priv->disp_height)
6caec0df4189 added text block parser
alex
parents: 2695
diff changeset
592 sh->disp_h = priv->disp_height;
6caec0df4189 added text block parser
alex
parents: 2695
diff changeset
593 else
6caec0df4189 added text block parser
alex
parents: 2695
diff changeset
594 sh->disp_h = height;
2687
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
595
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
596 // emulate BITMAPINFOHEADER:
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
597 sh->bih=malloc(sizeof(BITMAPINFOHEADER));
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
598 memset(sh->bih,0,sizeof(BITMAPINFOHEADER));
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
599 sh->bih->biSize=40;
2784
6caec0df4189 added text block parser
alex
parents: 2695
diff changeset
600 if (priv->width)
6caec0df4189 added text block parser
alex
parents: 2695
diff changeset
601 sh->bih->biWidth = priv->width;
6caec0df4189 added text block parser
alex
parents: 2695
diff changeset
602 else
6caec0df4189 added text block parser
alex
parents: 2695
diff changeset
603 sh->bih->biWidth = width;
6caec0df4189 added text block parser
alex
parents: 2695
diff changeset
604 if (priv->height)
6caec0df4189 added text block parser
alex
parents: 2695
diff changeset
605 sh->bih->biHeight = priv->height;
6caec0df4189 added text block parser
alex
parents: 2695
diff changeset
606 else
6caec0df4189 added text block parser
alex
parents: 2695
diff changeset
607 sh->bih->biHeight = height;
2687
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
608 sh->bih->biPlanes=1;
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
609 sh->bih->biBitCount=24;
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
610 sh->bih->biCompression=sh->format;
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
611 sh->bih->biSizeImage=sh->bih->biWidth*sh->bih->biHeight*3;
3502
1ff0ff94ac91 added -vivo subconfig
alex
parents: 3471
diff changeset
612
1ff0ff94ac91 added -vivo subconfig
alex
parents: 3471
diff changeset
613 /* insert as stream */
1ff0ff94ac91 added -vivo subconfig
alex
parents: 3471
diff changeset
614 demuxer->video->sh=sh;
1ff0ff94ac91 added -vivo subconfig
alex
parents: 3471
diff changeset
615 sh->ds=demuxer->video;
2687
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
616 demuxer->video->id=0;
2928
3f8798f1f4bc some minor fixes
alex
parents: 2809
diff changeset
617
3502
1ff0ff94ac91 added -vivo subconfig
alex
parents: 3471
diff changeset
618 /* disable seeking */
2928
3f8798f1f4bc some minor fixes
alex
parents: 2809
diff changeset
619 demuxer->seekable = 0;
2788
4a909be26ea1 freeing up space and some debug
alex
parents: 2785
diff changeset
620
2928
3f8798f1f4bc some minor fixes
alex
parents: 2809
diff changeset
621 printf("VIVO Video stream %d size: display: %dx%d, codec: %lux%lu\n",
2788
4a909be26ea1 freeing up space and some debug
alex
parents: 2785
diff changeset
622 demuxer->video->id, sh->disp_w, sh->disp_h, sh->bih->biWidth,
4a909be26ea1 freeing up space and some debug
alex
parents: 2785
diff changeset
623 sh->bih->biHeight);
2687
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
624 }
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
625
3502
1ff0ff94ac91 added -vivo subconfig
alex
parents: 3471
diff changeset
626 /* AUDIO init */
1ff0ff94ac91 added -vivo subconfig
alex
parents: 3471
diff changeset
627 if (demuxer->audio->id >= -1){
2687
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
628 if(!ds_fill_buffer(demuxer->audio)){
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
629 mp_msg(MSGT_DEMUX,MSGL_ERR,"VIVO: " MSGTR_MissingAudioStream);
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
630 } else
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
631 { sh_audio_t* sh=new_sh_audio(demuxer,1);
2788
4a909be26ea1 freeing up space and some debug
alex
parents: 2785
diff changeset
632
3502
1ff0ff94ac91 added -vivo subconfig
alex
parents: 3471
diff changeset
633 /* Select audio codec */
3471
e5aae38e6a09 hacked audio support to work with acm
alex
parents: 3439
diff changeset
634 if (priv->audio_codec == 0)
e5aae38e6a09 hacked audio support to work with acm
alex
parents: 3439
diff changeset
635 {
e5aae38e6a09 hacked audio support to work with acm
alex
parents: 3439
diff changeset
636 if (priv->version == '2')
e5aae38e6a09 hacked audio support to work with acm
alex
parents: 3439
diff changeset
637 priv->audio_codec = VIVO_AUDIO_SIREN;
e5aae38e6a09 hacked audio support to work with acm
alex
parents: 3439
diff changeset
638 else
e5aae38e6a09 hacked audio support to work with acm
alex
parents: 3439
diff changeset
639 priv->audio_codec = VIVO_AUDIO_G723;
e5aae38e6a09 hacked audio support to work with acm
alex
parents: 3439
diff changeset
640 }
3502
1ff0ff94ac91 added -vivo subconfig
alex
parents: 3471
diff changeset
641 if (vivo_param_acodec != NULL)
1ff0ff94ac91 added -vivo subconfig
alex
parents: 3471
diff changeset
642 {
1ff0ff94ac91 added -vivo subconfig
alex
parents: 3471
diff changeset
643 if (!strcasecmp(vivo_param_acodec, "g723"))
1ff0ff94ac91 added -vivo subconfig
alex
parents: 3471
diff changeset
644 priv->audio_codec = VIVO_AUDIO_G723;
1ff0ff94ac91 added -vivo subconfig
alex
parents: 3471
diff changeset
645 if (!strcasecmp(vivo_param_acodec, "siren"))
1ff0ff94ac91 added -vivo subconfig
alex
parents: 3471
diff changeset
646 priv->audio_codec = VIVO_AUDIO_SIREN;
1ff0ff94ac91 added -vivo subconfig
alex
parents: 3471
diff changeset
647 }
3471
e5aae38e6a09 hacked audio support to work with acm
alex
parents: 3439
diff changeset
648
3502
1ff0ff94ac91 added -vivo subconfig
alex
parents: 3471
diff changeset
649 sh->format = -1;
1ff0ff94ac91 added -vivo subconfig
alex
parents: 3471
diff changeset
650 if (priv->audio_codec == VIVO_AUDIO_G723)
1ff0ff94ac91 added -vivo subconfig
alex
parents: 3471
diff changeset
651 sh->format = 0x111;
3471
e5aae38e6a09 hacked audio support to work with acm
alex
parents: 3439
diff changeset
652 if (priv->audio_codec == VIVO_AUDIO_SIREN)
3502
1ff0ff94ac91 added -vivo subconfig
alex
parents: 3471
diff changeset
653 sh->format = 0x112;
1ff0ff94ac91 added -vivo subconfig
alex
parents: 3471
diff changeset
654 if (sh->format == -1)
1ff0ff94ac91 added -vivo subconfig
alex
parents: 3471
diff changeset
655 {
1ff0ff94ac91 added -vivo subconfig
alex
parents: 3471
diff changeset
656 mp_msg(MSGT_DEMUX, MSGL_ERR, "VIVO: Not support audio codec (%d)\n",
1ff0ff94ac91 added -vivo subconfig
alex
parents: 3471
diff changeset
657 priv->audio_codec);
1ff0ff94ac91 added -vivo subconfig
alex
parents: 3471
diff changeset
658 goto nosound;
1ff0ff94ac91 added -vivo subconfig
alex
parents: 3471
diff changeset
659 }
3439
192449c155c7 fixed Waveformatheader emu and added vivo1/2 audio detection
alex
parents: 3245
diff changeset
660
2687
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
661 // Emulate WAVEFORMATEX struct:
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
662 sh->wf=malloc(sizeof(WAVEFORMATEX));
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
663 memset(sh->wf,0,sizeof(WAVEFORMATEX));
3439
192449c155c7 fixed Waveformatheader emu and added vivo1/2 audio detection
alex
parents: 3245
diff changeset
664 sh->wf->wFormatTag=sh->format;
3502
1ff0ff94ac91 added -vivo subconfig
alex
parents: 3471
diff changeset
665 sh->wf->nChannels=1; /* 1 channels for both Siren and G.723 */
1ff0ff94ac91 added -vivo subconfig
alex
parents: 3471
diff changeset
666
1ff0ff94ac91 added -vivo subconfig
alex
parents: 3471
diff changeset
667 /* Set bits per sample */
3471
e5aae38e6a09 hacked audio support to work with acm
alex
parents: 3439
diff changeset
668 if (priv->audio_codec == VIVO_AUDIO_SIREN)
3502
1ff0ff94ac91 added -vivo subconfig
alex
parents: 3471
diff changeset
669 sh->wf->wBitsPerSample = 16;
3471
e5aae38e6a09 hacked audio support to work with acm
alex
parents: 3439
diff changeset
670 else
3502
1ff0ff94ac91 added -vivo subconfig
alex
parents: 3471
diff changeset
671 if (priv->audio_codec == VIVO_AUDIO_G723)
1ff0ff94ac91 added -vivo subconfig
alex
parents: 3471
diff changeset
672 sh->wf->wBitsPerSample = 8;
1ff0ff94ac91 added -vivo subconfig
alex
parents: 3471
diff changeset
673
1ff0ff94ac91 added -vivo subconfig
alex
parents: 3471
diff changeset
674 /* Set sampling rate */
1ff0ff94ac91 added -vivo subconfig
alex
parents: 3471
diff changeset
675 if (priv->audio_samplerate) /* got from header */
1ff0ff94ac91 added -vivo subconfig
alex
parents: 3471
diff changeset
676 sh->wf->nSamplesPerSec = priv->audio_samplerate;
3471
e5aae38e6a09 hacked audio support to work with acm
alex
parents: 3439
diff changeset
677 else
e5aae38e6a09 hacked audio support to work with acm
alex
parents: 3439
diff changeset
678 {
e5aae38e6a09 hacked audio support to work with acm
alex
parents: 3439
diff changeset
679 if (priv->audio_codec == VIVO_AUDIO_SIREN)
3502
1ff0ff94ac91 added -vivo subconfig
alex
parents: 3471
diff changeset
680 sh->wf->nSamplesPerSec = 16000;
1ff0ff94ac91 added -vivo subconfig
alex
parents: 3471
diff changeset
681 if (priv->audio_codec == VIVO_AUDIO_G723)
1ff0ff94ac91 added -vivo subconfig
alex
parents: 3471
diff changeset
682 sh->wf->nSamplesPerSec = 8000;
3471
e5aae38e6a09 hacked audio support to work with acm
alex
parents: 3439
diff changeset
683 }
3502
1ff0ff94ac91 added -vivo subconfig
alex
parents: 3471
diff changeset
684 if (vivo_param_samplerate != -1)
1ff0ff94ac91 added -vivo subconfig
alex
parents: 3471
diff changeset
685 sh->wf->nSamplesPerSec = vivo_param_samplerate;
1ff0ff94ac91 added -vivo subconfig
alex
parents: 3471
diff changeset
686
1ff0ff94ac91 added -vivo subconfig
alex
parents: 3471
diff changeset
687 /* Set audio bitrate */
1ff0ff94ac91 added -vivo subconfig
alex
parents: 3471
diff changeset
688 if (priv->audio_bitrate) /* got from header */
1ff0ff94ac91 added -vivo subconfig
alex
parents: 3471
diff changeset
689 sh->wf->nAvgBytesPerSec = priv->audio_bitrate;
2784
6caec0df4189 added text block parser
alex
parents: 2695
diff changeset
690 else
3471
e5aae38e6a09 hacked audio support to work with acm
alex
parents: 3439
diff changeset
691 {
e5aae38e6a09 hacked audio support to work with acm
alex
parents: 3439
diff changeset
692 if (priv->audio_codec == VIVO_AUDIO_SIREN)
e5aae38e6a09 hacked audio support to work with acm
alex
parents: 3439
diff changeset
693 sh->wf->nAvgBytesPerSec = 2000;
3502
1ff0ff94ac91 added -vivo subconfig
alex
parents: 3471
diff changeset
694 if (priv->audio_codec == VIVO_AUDIO_G723)
3471
e5aae38e6a09 hacked audio support to work with acm
alex
parents: 3439
diff changeset
695 sh->wf->nAvgBytesPerSec = 800;
e5aae38e6a09 hacked audio support to work with acm
alex
parents: 3439
diff changeset
696 }
3502
1ff0ff94ac91 added -vivo subconfig
alex
parents: 3471
diff changeset
697 if (vivo_param_abitrate != -1)
1ff0ff94ac91 added -vivo subconfig
alex
parents: 3471
diff changeset
698 sh->wf->nAvgBytesPerSec = vivo_param_abitrate;
3526
cf787373f0aa vivo A-V sync fixed
arpi
parents: 3503
diff changeset
699 audio_rate=sh->wf->nAvgBytesPerSec;
3502
1ff0ff94ac91 added -vivo subconfig
alex
parents: 3471
diff changeset
700
3471
e5aae38e6a09 hacked audio support to work with acm
alex
parents: 3439
diff changeset
701 if (!priv->audio_bytesperblock)
e5aae38e6a09 hacked audio support to work with acm
alex
parents: 3439
diff changeset
702 {
e5aae38e6a09 hacked audio support to work with acm
alex
parents: 3439
diff changeset
703 if (priv->audio_codec == VIVO_AUDIO_SIREN)
3502
1ff0ff94ac91 added -vivo subconfig
alex
parents: 3471
diff changeset
704 sh->wf->nBlockAlign = 40;
1ff0ff94ac91 added -vivo subconfig
alex
parents: 3471
diff changeset
705 if (priv->audio_codec == VIVO_AUDIO_G723)
1ff0ff94ac91 added -vivo subconfig
alex
parents: 3471
diff changeset
706 sh->wf->nBlockAlign = 24;
3471
e5aae38e6a09 hacked audio support to work with acm
alex
parents: 3439
diff changeset
707 }
e5aae38e6a09 hacked audio support to work with acm
alex
parents: 3439
diff changeset
708 else
3502
1ff0ff94ac91 added -vivo subconfig
alex
parents: 3471
diff changeset
709 sh->wf->nBlockAlign = priv->audio_bytesperblock;
1ff0ff94ac91 added -vivo subconfig
alex
parents: 3471
diff changeset
710 if (vivo_param_bytesperblock != -1)
1ff0ff94ac91 added -vivo subconfig
alex
parents: 3471
diff changeset
711 sh->wf->nBlockAlign = vivo_param_bytesperblock;
1ff0ff94ac91 added -vivo subconfig
alex
parents: 3471
diff changeset
712
1ff0ff94ac91 added -vivo subconfig
alex
parents: 3471
diff changeset
713 sound_ok:
1ff0ff94ac91 added -vivo subconfig
alex
parents: 3471
diff changeset
714 /* insert as stream */
1ff0ff94ac91 added -vivo subconfig
alex
parents: 3471
diff changeset
715 demuxer->audio->sh=sh;
1ff0ff94ac91 added -vivo subconfig
alex
parents: 3471
diff changeset
716 sh->ds=demuxer->audio;
2687
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
717 demuxer->audio->id=1;
3502
1ff0ff94ac91 added -vivo subconfig
alex
parents: 3471
diff changeset
718 nosound:
4407
760481d8421c warning (proper) fix
pl
parents: 3733
diff changeset
719 ;
2687
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
720 }
2695
af8b2c0e4dad vivo 2.0 compatibility
arpi
parents: 2687
diff changeset
721 }
2687
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
722
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
723 }
8c75a9a639c1 vivo demuxer
arpi
parents:
diff changeset
724
2788
4a909be26ea1 freeing up space and some debug
alex
parents: 2785
diff changeset
725 void demux_close_vivo(demuxer_t *demuxer)
4a909be26ea1 freeing up space and some debug
alex
parents: 2785
diff changeset
726 {
4a909be26ea1 freeing up space and some debug
alex
parents: 2785
diff changeset
727 vivo_priv_t* priv=demuxer->priv;
2809
b8e0d8204ff2 small fix
pl
parents: 2805
diff changeset
728
b8e0d8204ff2 small fix
pl
parents: 2805
diff changeset
729 if (priv) {
b8e0d8204ff2 small fix
pl
parents: 2805
diff changeset
730 if (priv->title)
b8e0d8204ff2 small fix
pl
parents: 2805
diff changeset
731 free(priv->title);
b8e0d8204ff2 small fix
pl
parents: 2805
diff changeset
732 if (priv->author)
b8e0d8204ff2 small fix
pl
parents: 2805
diff changeset
733 free(priv->author);
b8e0d8204ff2 small fix
pl
parents: 2805
diff changeset
734 if (priv->copyright)
b8e0d8204ff2 small fix
pl
parents: 2805
diff changeset
735 free(priv->copyright);
b8e0d8204ff2 small fix
pl
parents: 2805
diff changeset
736 if (priv->producer)
b8e0d8204ff2 small fix
pl
parents: 2805
diff changeset
737 free(priv->producer);
2788
4a909be26ea1 freeing up space and some debug
alex
parents: 2785
diff changeset
738 free(priv);
2809
b8e0d8204ff2 small fix
pl
parents: 2805
diff changeset
739 }
2788
4a909be26ea1 freeing up space and some debug
alex
parents: 2785
diff changeset
740 return;
4a909be26ea1 freeing up space and some debug
alex
parents: 2785
diff changeset
741 }