subassconvert: do not escape likely ASS override tags
[mplayer.git] / libmpdemux / demux_viv.c
blob06193e9ea852858583966662495399a397f379d1
1 /*
2 * VIVO file parser
3 * copyright (c) 2001 A'rpi
4 * VIVO text header parser and audio support by alex
6 * This file is part of MPlayer.
8 * MPlayer is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * MPlayer is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License along
19 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 #include <stdio.h>
24 #include <stdlib.h>
25 #include <unistd.h>
26 #include <string.h> /* strtok */
28 #include "config.h"
29 #include "mp_msg.h"
31 #include "stream/stream.h"
32 #include "demuxer.h"
33 #include "stheader.h"
35 /* parameters ! */
36 int vivo_param_version = -1;
37 char *vivo_param_acodec = NULL;
38 int vivo_param_abitrate = -1;
39 int vivo_param_samplerate = -1;
40 int vivo_param_bytesperblock = -1;
41 int vivo_param_width = -1;
42 int vivo_param_height = -1;
43 int vivo_param_vformat = -1;
45 /* VIVO audio standards from vivog723.acm:
47 G.723:
48 FormatTag = 0x111
49 Channels = 1 - mono
50 SamplesPerSec = 8000 - 8khz
51 AvgBytesPerSec = 800
52 BlockAlign (bytes per block) = 24
53 BitsPerSample = 8
55 Siren:
56 FormatTag = 0x112
57 Channels = 1 - mono
58 SamplesPerSec = 16000 - 16khz
59 AvgBytesPerSec = 2000
60 BlockAlign (bytes per block) = 40
61 BitsPerSample = 8
64 //enum { VIVO_AUDIO_G723, VIVO_AUDIO_SIREN };
66 #define VIVO_AUDIO_G723 1
67 #define VIVO_AUDIO_SIREN 2
69 typedef struct {
70 /* generic */
71 char version;
72 int supported;
73 /* info */
74 char *title;
75 char *author;
76 char *copyright;
77 char *producer;
78 /* video */
79 float fps;
80 int width;
81 int height;
82 int disp_width;
83 int disp_height;
84 /* audio */
85 int audio_codec;
86 int audio_bitrate;
87 int audio_samplerate;
88 int audio_bytesperblock;
89 } vivo_priv_t;
91 /* parse all possible extra headers */
92 /* (audio headers are separate - mostly with recordtype=3 or 4) */
93 #define TEXTPARSE_ALL 1
95 static void vivo_parse_text_header(demuxer_t *demux, int header_len)
97 vivo_priv_t* priv = demux->priv;
98 char *buf;
99 char *token;
100 char *opt, *param;
101 int parser_in_audio_block = 0;
103 if (!demux->priv)
105 priv = malloc(sizeof(vivo_priv_t));
106 memset(priv, 0, sizeof(vivo_priv_t));
107 demux->priv = priv;
108 priv->supported = 0;
111 buf = malloc(header_len + 1);
112 opt = malloc(header_len + 1);
113 param = malloc(header_len + 1);
114 stream_read(demux->stream, buf, header_len);
115 buf[header_len] = 0;
117 token = strtok(buf, (char *)&("\x0d\x0a"));
118 while (token)
120 if (sscanf(token, "%[^:]:%[^\n]", opt, param) != 2)
122 mp_msg(MSGT_DEMUX, MSGL_V, "viv_text_header_parser: bad line: '%s' at ~%#"PRIx64"\n",
123 token, (int64_t)stream_tell(demux->stream));
124 break;
126 mp_dbg(MSGT_DEMUX, MSGL_DBG3, "token: '%s' (%zd bytes)\n",
127 token, strlen(token));
128 mp_dbg(MSGT_DEMUX, MSGL_DBG3, "token => o: '%s', p: '%s'\n",
129 opt, param);
131 /* checking versions: only v1 or v2 is suitable (or known?:) */
132 if (!strcmp(opt, "Version"))
134 mp_msg(MSGT_DEMUX, MSGL_DBG2, "Version: %s\n", param);
135 if (!strncmp(param, "Vivo/1", 6) || !strncmp(param, "Vivo/2", 6))
137 priv->supported = 1;
138 /* save major version for fourcc */
139 priv->version = param[5];
143 /* video specific */
144 if (!strcmp(opt, "FPS"))
146 mp_msg(MSGT_DEMUX, MSGL_DBG2, "FPS: %f\n", atof(param));
147 priv->fps = atof(param);
149 if (!strcmp(opt, "Width"))
151 mp_msg(MSGT_DEMUX, MSGL_DBG2, "Width: %d\n", atoi(param));
152 priv->width = atoi(param);
154 if (!strcmp(opt, "Height"))
156 mp_msg(MSGT_DEMUX, MSGL_DBG2, "Height: %d\n", atoi(param));
157 priv->height = atoi(param);
159 if (!strcmp(opt, "DisplayWidth"))
161 mp_msg(MSGT_DEMUX, MSGL_DBG2, "Display Width: %d\n", atoi(param));
162 priv->disp_width = atoi(param);
164 if (!strcmp(opt, "DisplayHeight"))
166 mp_msg(MSGT_DEMUX, MSGL_DBG2, "Display Height: %d\n", atoi(param));
167 priv->disp_height = atoi(param);
170 /* audio specific */
171 if (!strcmp(opt, "RecordType"))
173 /* no audio recordblock by Vivo/1.00, 3 and 4 by Vivo/2.00 */
174 if ((atoi(param) == 3) || (atoi(param) == 4))
175 parser_in_audio_block = 1;
176 else
177 parser_in_audio_block = 0;
179 if (!strcmp(opt, "NominalBitrate"))
181 priv->audio_bitrate = atoi(param);
182 if (priv->audio_bitrate == 2000)
183 priv->audio_codec = VIVO_AUDIO_SIREN;
184 if (priv->audio_bitrate == 800)
185 priv->audio_codec = VIVO_AUDIO_G723;
187 if (!strcmp(opt, "SamplingFrequency"))
189 priv->audio_samplerate = atoi(param);
190 if (priv->audio_samplerate == 16000)
191 priv->audio_codec = VIVO_AUDIO_SIREN;
192 if (priv->audio_samplerate == 8000)
193 priv->audio_codec = VIVO_AUDIO_G723;
195 if (!strcmp(opt, "Length") && (parser_in_audio_block == 1))
197 priv->audio_bytesperblock = atoi(param); /* 24 or 40 kbps */
198 if (priv->audio_bytesperblock == 40)
199 priv->audio_codec = VIVO_AUDIO_SIREN;
200 if (priv->audio_bytesperblock == 24)
201 priv->audio_codec = VIVO_AUDIO_G723;
204 /* only for displaying some informations about movie*/
205 if (!strcmp(opt, "Title"))
207 demux_info_add(demux, "title", param);
208 priv->title = strdup(param);
210 if (!strcmp(opt, "Author"))
212 demux_info_add(demux, "author", param);
213 priv->author = strdup(param);
215 if (!strcmp(opt, "Copyright"))
217 demux_info_add(demux, "copyright", param);
218 priv->copyright = strdup(param);
220 if (!strcmp(opt, "Producer"))
222 demux_info_add(demux, "encoder", param);
223 priv->producer = strdup(param);
226 /* get next token */
227 token = strtok(NULL, (char *)&("\x0d\x0a"));
230 free(buf);
231 free(opt);
232 free(param);
235 static int vivo_check_file(demuxer_t* demuxer){
236 int i=0;
237 int len;
238 int c;
239 unsigned char buf[2048+256];
240 vivo_priv_t* priv;
241 int orig_pos = stream_tell(demuxer->stream);
243 mp_msg(MSGT_DEMUX,MSGL_V,"Checking for VIVO\n");
245 c=stream_read_char(demuxer->stream);
246 if(c==-256) return 0;
247 len=0;
248 while((c=stream_read_char(demuxer->stream))>=0x80){
249 len+=0x80*(c-0x80);
250 if(len>1024) return 0;
252 len+=c;
253 mp_msg(MSGT_DEMUX,MSGL_V,"header block 1 size: %d\n",len);
254 //stream_skip(demuxer->stream,len);
256 priv=malloc(sizeof(vivo_priv_t));
257 memset(priv,0,sizeof(vivo_priv_t));
258 demuxer->priv=priv;
260 #if 0
261 vivo_parse_text_header(demuxer, len);
262 if (priv->supported == 0)
263 return 0;
264 #else
265 /* this is enought for check (for now) */
266 stream_read(demuxer->stream,buf,len);
267 buf[len]=0;
268 // printf("VIVO header: '%s'\n",buf);
270 // parse header:
271 i=0;
272 while(i<len && buf[i]==0x0D && buf[i+1]==0x0A) i+=2; // skip empty lines
273 if(strncmp(buf+i,"Version:Vivo/",13)) return 0; // bad version/type!
274 #endif
276 #if 0
277 c=stream_read_char(demuxer->stream);
278 if(c) return 0;
279 len2=0;
280 while((c=stream_read_char(demuxer->stream))>=0x80){
281 len2+=0x80*(c-0x80);
282 if(len+len2>2048) return 0;
284 len2+=c;
285 mp_msg(MSGT_DEMUX,MSGL_V,"header block 2 size: %d\n",len2);
286 stream_skip(demuxer->stream,len2);
287 // stream_read(demuxer->stream,buf+len,len2);
288 #endif
290 // c=stream_read_char(demuxer->stream);
291 // printf("first packet: %02X\n",c);
293 stream_seek(demuxer->stream, orig_pos);
295 return DEMUXER_TYPE_VIVO;
298 static int audio_pos=0;
299 static int audio_rate=0;
301 // return value:
302 // 0 = EOF or no stream found
303 // 1 = successfully read a packet
304 static int demux_vivo_fill_buffer(demuxer_t *demux, demux_stream_t *dsds){
305 demux_stream_t *ds=NULL;
306 int c;
307 int len=0;
308 int seq;
309 int prefix=0;
310 demux->filepos=stream_tell(demux->stream);
312 c=stream_read_char(demux->stream);
313 if (c == -256) /* EOF */
314 return 0;
315 // printf("c=%x,%02X\n",c,c&0xf0);
316 if (c == 0x82)
318 /* ok, this works, but pts calculating from header is required! */
319 /* FIXME: "Calculate PTS from picture header!" */
320 prefix = 1;
321 c = stream_read_char(demux->stream);
322 mp_msg(MSGT_DEMUX, MSGL_V, "packet 0x82(pos=%u) chunk=%x\n",
323 (int)stream_tell(demux->stream), c);
325 switch(c&0xF0){
326 case 0x00: // header - skip it!
328 len=stream_read_char(demux->stream);
329 if(len>=0x80) len=0x80*(len-0x80)+stream_read_char(demux->stream);
330 mp_msg(MSGT_DEMUX, MSGL_V, "vivo extra header: %d bytes\n",len);
331 #ifdef TEXTPARSE_ALL
333 int pos;
334 /* also try to parse all headers */
335 pos = stream_tell(demux->stream);
336 vivo_parse_text_header(demux, len);
337 stream_seek(demux->stream, pos);
339 #endif
340 break;
342 case 0x10: // video packet
343 if (prefix == 1)
344 len = stream_read_char(demux->stream);
345 else
346 len=128;
347 ds=demux->video;
348 break;
349 case 0x20: // video packet
350 len=stream_read_char(demux->stream);
351 ds=demux->video;
352 break;
353 case 0x30: // audio packet
354 if (prefix == 1)
355 len = stream_read_char(demux->stream);
356 else
357 len=40; /* 40kbps */
358 ds=demux->audio;
359 audio_pos+=len;
360 break;
361 case 0x40: // audio packet
362 if (prefix == 1)
363 len = stream_read_char(demux->stream);
364 else
365 len=24; /* 24kbps */
366 ds=demux->audio;
367 audio_pos+=len;
368 break;
369 default:
370 mp_msg(MSGT_DEMUX,MSGL_WARN,"VIVO - unknown ID found: %02X at pos %"PRIu64" contact author!\n",
371 c, (int64_t)stream_tell(demux->stream));
372 return 0;
375 // printf("chunk=%x, len=%d\n", c, len);
377 if(!ds || ds->id<-1){
378 if(len) stream_skip(demux->stream,len);
379 return 1;
382 seq=c&0x0F;
384 if(ds->asf_packet){
385 if(ds->asf_seq!=seq){
386 // closed segment, finalize packet:
387 ds_add_packet(ds,ds->asf_packet);
388 ds->asf_packet=NULL;
389 // printf("packet!\n");
390 } else {
391 // append data to it!
392 demux_packet_t* dp=ds->asf_packet;
393 if(dp->len + len + MP_INPUT_BUFFER_PADDING_SIZE < 0)
394 return 0;
395 dp->buffer=realloc(dp->buffer,dp->len+len+MP_INPUT_BUFFER_PADDING_SIZE);
396 memset(dp->buffer+dp->len+len, 0, MP_INPUT_BUFFER_PADDING_SIZE);
397 //memcpy(dp->buffer+dp->len,data,len);
398 stream_read(demux->stream,dp->buffer+dp->len,len);
399 mp_dbg(MSGT_DEMUX,MSGL_DBG4,"data appended! %d+%d\n",dp->len,len);
400 dp->len+=len;
401 // we are ready now.
402 if((c&0xF0)==0x20) --ds->asf_seq; // hack!
403 return 1;
406 // create new packet:
407 { demux_packet_t* dp;
408 dp=new_demux_packet(len);
409 //memcpy(dp->buffer,data,len);
410 stream_read(demux->stream,dp->buffer,len);
411 dp->pts=audio_rate?((float)audio_pos/(float)audio_rate):0;
412 // dp->flags=keyframe;
413 // if(ds==demux->video) printf("ASF time: %8d dur: %5d \n",time,dur);
414 dp->pos=demux->filepos;
415 ds->asf_packet=dp;
416 ds->asf_seq=seq;
417 // we are ready now.
418 return 1;
423 static const short h263_format[8][2] = {
424 { 0, 0 },
425 { 128, 96 },
426 { 176, 144 },
427 { 352, 288 },
428 { 704, 576 },
429 { 1408, 1152 },
430 { 320, 240 } // ??????? or 240x180 (found in vivo2) ?
433 static unsigned char* buffer;
434 static int bufptr=0;
435 static int bitcnt=0;
436 static unsigned char buf=0;
437 static int format, width, height;
439 static unsigned int x_get_bits(int n){
440 unsigned int x=0;
441 while(n-->0){
442 if(!bitcnt){
443 // fill buff
444 buf=buffer[bufptr++];
445 bitcnt=8;
447 //x=(x<<1)|(buf&1);buf>>=1;
448 x=(x<<1)|(buf>>7);buf<<=1;
449 --bitcnt;
451 return x;
454 #define get_bits(xxx,n) x_get_bits(n)
455 #define get_bits1(xxx) x_get_bits(1)
456 #define skip_bits(xxx,n) x_get_bits(n)
457 #define skip_bits1(xxx) x_get_bits(1)
459 /* most is hardcoded. should extend to handle all h263 streams */
460 static int h263_decode_picture_header(unsigned char *b_ptr)
462 // int i;
464 // for(i=0;i<16;i++) printf(" %02X",b_ptr[i]); printf("\n");
466 buffer=b_ptr;
467 bufptr=bitcnt=buf=0;
469 /* picture header */
470 if (get_bits(&s->gb, 22) != 0x20){
471 mp_msg(MSGT_DEMUX, MSGL_FATAL, "bad picture header\n");
472 return -1;
474 skip_bits(&s->gb, 8); /* picture timestamp */
476 if (get_bits1(&s->gb) != 1){
477 mp_msg(MSGT_DEMUX, MSGL_FATAL, "bad marker\n");
478 return -1; /* marker */
480 if (get_bits1(&s->gb) != 0){
481 mp_msg(MSGT_DEMUX, MSGL_FATAL, "bad h263 id\n");
482 return -1; /* h263 id */
484 skip_bits1(&s->gb); /* split screen off */
485 skip_bits1(&s->gb); /* camera off */
486 skip_bits1(&s->gb); /* freeze picture release off */
488 format = get_bits(&s->gb, 3);
490 if (format != 7) {
491 mp_msg(MSGT_DEMUX, MSGL_V, "h263_plus = 0 format = %d\n", format);
492 /* H.263v1 */
493 width = h263_format[format][0];
494 height = h263_format[format][1];
495 mp_msg(MSGT_DEMUX, MSGL_V, "%d x %d\n", width, height);
496 // if (!width) return -1;
498 mp_msg(MSGT_DEMUX, MSGL_V, "pict_type=%d\n", get_bits1(&s->gb));
499 mp_msg(MSGT_DEMUX, MSGL_V, "unrestricted_mv=%d\n", get_bits1(&s->gb));
500 #if 1
501 mp_msg(MSGT_DEMUX, MSGL_V, "SAC: %d\n", get_bits1(&s->gb));
502 mp_msg(MSGT_DEMUX, MSGL_V, "advanced prediction mode: %d\n", get_bits1(&s->gb));
503 mp_msg(MSGT_DEMUX, MSGL_V, "PB frame: %d\n", get_bits1(&s->gb));
504 #else
505 if (get_bits1(&s->gb) != 0)
506 return -1; /* SAC: off */
507 if (get_bits1(&s->gb) != 0)
508 return -1; /* advanced prediction mode: off */
509 if (get_bits1(&s->gb) != 0)
510 return -1; /* not PB frame */
511 #endif
512 mp_msg(MSGT_DEMUX, MSGL_V, "qscale=%d\n", get_bits(&s->gb, 5));
513 skip_bits1(&s->gb); /* Continuous Presence Multipoint mode: off */
514 } else {
515 mp_msg(MSGT_DEMUX, MSGL_V, "h263_plus = 1\n");
516 /* H.263v2 */
517 if (get_bits(&s->gb, 3) != 1){
518 mp_msg(MSGT_DEMUX, MSGL_FATAL, "H.263v2 A error\n");
519 return -1;
521 if (get_bits(&s->gb, 3) != 6){ /* custom source format */
522 mp_msg(MSGT_DEMUX, MSGL_FATAL, "custom source format\n");
523 return -1;
525 skip_bits(&s->gb, 12);
526 skip_bits(&s->gb, 3);
527 mp_msg(MSGT_DEMUX, MSGL_V, "pict_type=%d\n", get_bits(&s->gb, 3) + 1);
528 // if (s->pict_type != I_TYPE &&
529 // s->pict_type != P_TYPE)
530 // return -1;
531 skip_bits(&s->gb, 7);
532 skip_bits(&s->gb, 4); /* aspect ratio */
533 width = (get_bits(&s->gb, 9) + 1) * 4;
534 skip_bits1(&s->gb);
535 height = get_bits(&s->gb, 9) * 4;
536 mp_msg(MSGT_DEMUX, MSGL_V, "%d x %d\n", width, height);
537 //if (height == 0)
538 // return -1;
539 mp_msg(MSGT_DEMUX, MSGL_V, "qscale=%d\n", get_bits(&s->gb, 5));
542 /* PEI */
543 while (get_bits1(&s->gb) != 0) {
544 skip_bits(&s->gb, 8);
546 // s->f_code = 1;
547 // s->width = width;
548 // s->height = height;
549 return 0;
554 static demuxer_t* demux_open_vivo(demuxer_t* demuxer){
555 vivo_priv_t* priv=demuxer->priv;
557 if(!ds_fill_buffer(demuxer->video)){
558 mp_msg(MSGT_DEMUX, MSGL_ERR, "VIVO: %s",
559 mp_gtext("Missing video stream!? Contact the author, it may be a bug :(\n"));
560 return NULL;
563 audio_pos=0;
565 h263_decode_picture_header(demuxer->video->buffer);
567 if (vivo_param_version != -1)
568 priv->version = '0' + vivo_param_version;
570 { sh_video_t* sh=new_sh_video(demuxer,0);
572 /* viv1, viv2 (for better codecs.conf) */
573 sh->format = mmioFOURCC('v', 'i', 'v', priv->version);
574 if(!sh->fps)
576 if (priv->fps)
577 sh->fps=priv->fps;
578 else
579 sh->fps=15.0f;
581 sh->frametime=1.0f/sh->fps;
583 /* XXX: FIXME: can't scale image. */
584 /* hotfix to disable: */
585 priv->disp_width = priv->width;
586 priv->disp_height = priv->height;
588 if (vivo_param_width != -1)
589 priv->disp_width = priv->width = vivo_param_width;
591 if (vivo_param_height != -1)
592 priv->disp_height = priv->height = vivo_param_height;
594 if (vivo_param_vformat != -1)
596 priv->disp_width = priv->width = h263_format[vivo_param_vformat][0];
597 priv->disp_height = priv->height = h263_format[vivo_param_vformat][1];
600 if (priv->disp_width)
601 sh->disp_w = priv->disp_width;
602 else
603 sh->disp_w = width;
604 if (priv->disp_height)
605 sh->disp_h = priv->disp_height;
606 else
607 sh->disp_h = height;
609 // emulate BITMAPINFOHEADER:
610 sh->bih=calloc(1, sizeof(*sh->bih));
611 sh->bih->biSize=40;
612 if (priv->width)
613 sh->bih->biWidth = priv->width;
614 else
615 sh->bih->biWidth = width;
616 if (priv->height)
617 sh->bih->biHeight = priv->height;
618 else
619 sh->bih->biHeight = height;
620 sh->bih->biPlanes=1;
621 sh->bih->biBitCount=24;
622 sh->bih->biCompression=sh->format;
623 sh->bih->biSizeImage=sh->bih->biWidth*sh->bih->biHeight*3;
625 /* insert as stream */
626 demuxer->video->sh=sh;
627 sh->ds=demuxer->video;
628 demuxer->video->id=0;
630 /* disable seeking */
631 demuxer->seekable = 0;
633 mp_msg(MSGT_DEMUX,MSGL_V,"VIVO Video stream %d size: display: %dx%d, codec: %ux%u\n",
634 demuxer->video->id, sh->disp_w, sh->disp_h, sh->bih->biWidth,
635 sh->bih->biHeight);
638 /* AUDIO init */
639 if (demuxer->audio->id >= -1){
640 if(!ds_fill_buffer(demuxer->audio)){
641 mp_msg(MSGT_DEMUX, MSGL_ERR, "VIVO: %s",
642 mp_gtext("No audio stream found -> no sound.\n"));
643 } else
644 { sh_audio_t* sh=new_sh_audio(demuxer,1);
646 /* Select audio codec */
647 if (priv->audio_codec == 0)
649 if (priv->version == '2')
650 priv->audio_codec = VIVO_AUDIO_SIREN;
651 else
652 priv->audio_codec = VIVO_AUDIO_G723;
654 if (vivo_param_acodec != NULL)
656 if (!strcasecmp(vivo_param_acodec, "g723"))
657 priv->audio_codec = VIVO_AUDIO_G723;
658 if (!strcasecmp(vivo_param_acodec, "siren"))
659 priv->audio_codec = VIVO_AUDIO_SIREN;
662 if (priv->audio_codec == VIVO_AUDIO_G723)
663 sh->format = 0x111;
664 else if (priv->audio_codec == VIVO_AUDIO_SIREN)
665 sh->format = 0x112;
666 else
668 mp_msg(MSGT_DEMUX, MSGL_ERR, "VIVO: Not support audio codec (%d)\n",
669 priv->audio_codec);
670 free_sh_audio(demuxer, 1);
671 goto nosound;
674 // Emulate WAVEFORMATEX struct:
675 sh->wf=calloc(1, sizeof(*sh->wf));
676 sh->wf->wFormatTag=sh->format;
677 sh->wf->nChannels=1; /* 1 channels for both Siren and G.723 */
679 /* Set bits per sample */
680 if (priv->audio_codec == VIVO_AUDIO_SIREN)
681 sh->wf->wBitsPerSample = 16;
682 else
683 if (priv->audio_codec == VIVO_AUDIO_G723)
684 sh->wf->wBitsPerSample = 8;
686 /* Set sampling rate */
687 if (priv->audio_samplerate) /* got from header */
688 sh->wf->nSamplesPerSec = priv->audio_samplerate;
689 else
691 if (priv->audio_codec == VIVO_AUDIO_SIREN)
692 sh->wf->nSamplesPerSec = 16000;
693 if (priv->audio_codec == VIVO_AUDIO_G723)
694 sh->wf->nSamplesPerSec = 8000;
696 if (vivo_param_samplerate != -1)
697 sh->wf->nSamplesPerSec = vivo_param_samplerate;
699 /* Set audio bitrate */
700 if (priv->audio_bitrate) /* got from header */
701 sh->wf->nAvgBytesPerSec = priv->audio_bitrate;
702 else
704 if (priv->audio_codec == VIVO_AUDIO_SIREN)
705 sh->wf->nAvgBytesPerSec = 2000;
706 if (priv->audio_codec == VIVO_AUDIO_G723)
707 sh->wf->nAvgBytesPerSec = 800;
709 if (vivo_param_abitrate != -1)
710 sh->wf->nAvgBytesPerSec = vivo_param_abitrate;
711 audio_rate=sh->wf->nAvgBytesPerSec;
713 if (!priv->audio_bytesperblock)
715 if (priv->audio_codec == VIVO_AUDIO_SIREN)
716 sh->wf->nBlockAlign = 40;
717 if (priv->audio_codec == VIVO_AUDIO_G723)
718 sh->wf->nBlockAlign = 24;
720 else
721 sh->wf->nBlockAlign = priv->audio_bytesperblock;
722 if (vivo_param_bytesperblock != -1)
723 sh->wf->nBlockAlign = vivo_param_bytesperblock;
725 /*sound_ok:*/
726 /* insert as stream */
727 demuxer->audio->sh=sh;
728 sh->ds=demuxer->audio;
729 demuxer->audio->id=1;
730 nosound:
731 return demuxer;
734 return demuxer;
737 static void demux_close_vivo(demuxer_t *demuxer)
739 vivo_priv_t* priv=demuxer->priv;
741 if (priv) {
742 free(priv->title);
743 free(priv->author);
744 free(priv->copyright);
745 free(priv->producer);
746 free(priv);
748 return;
752 const demuxer_desc_t demuxer_desc_vivo = {
753 "Vivo demuxer",
754 "vivo",
755 "VIVO",
756 "A'rpi, Alex Beregszasi",
758 DEMUXER_TYPE_VIVO,
759 0, // unsafe autodetect
760 vivo_check_file,
761 demux_vivo_fill_buffer,
762 demux_open_vivo,
763 demux_close_vivo,
764 NULL,
765 NULL