Windows: ao_pcm: add io.h include for MinGW64
[mplayer.git] / libmpdemux / demux_viv.c
blob0f14033976abe6cf4ef1983cbc2409c681ebea77
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 int i;
100 char *token;
101 char *opt, *param;
102 int parser_in_audio_block = 0;
104 if (!demux->priv)
106 priv = malloc(sizeof(vivo_priv_t));
107 memset(priv, 0, sizeof(vivo_priv_t));
108 demux->priv = priv;
109 priv->supported = 0;
112 buf = malloc(header_len);
113 opt = malloc(header_len);
114 param = malloc(header_len);
115 stream_read(demux->stream, buf, header_len);
116 i=0;
117 while(i<header_len && buf[i]==0x0D && buf[i+1]==0x0A) i+=2; // skip empty lines
119 token = strtok(buf, (char *)&("\x0d\x0a"));
120 while (token && (header_len>2))
122 header_len -= strlen(token)+2;
123 if (sscanf(token, "%[^:]:%[^\n]", opt, param) != 2)
125 mp_msg(MSGT_DEMUX, MSGL_V, "viv_text_header_parser: bad line: '%s' at ~%#"PRIx64"\n",
126 token, (int64_t)stream_tell(demux->stream));
127 break;
129 mp_dbg(MSGT_DEMUX, MSGL_DBG3, "token: '%s' (%d bytes/%d bytes left)\n",
130 token, strlen(token), header_len);
131 mp_dbg(MSGT_DEMUX, MSGL_DBG3, "token => o: '%s', p: '%s'\n",
132 opt, param);
134 /* checking versions: only v1 or v2 is suitable (or known?:) */
135 if (!strcmp(opt, "Version"))
137 mp_msg(MSGT_DEMUX, MSGL_DBG2, "Version: %s\n", param);
138 if (!strncmp(param, "Vivo/1", 6) || !strncmp(param, "Vivo/2", 6))
140 priv->supported = 1;
141 /* save major version for fourcc */
142 priv->version = param[5];
146 /* video specific */
147 if (!strcmp(opt, "FPS"))
149 mp_msg(MSGT_DEMUX, MSGL_DBG2, "FPS: %f\n", atof(param));
150 priv->fps = atof(param);
152 if (!strcmp(opt, "Width"))
154 mp_msg(MSGT_DEMUX, MSGL_DBG2, "Width: %d\n", atoi(param));
155 priv->width = atoi(param);
157 if (!strcmp(opt, "Height"))
159 mp_msg(MSGT_DEMUX, MSGL_DBG2, "Height: %d\n", atoi(param));
160 priv->height = atoi(param);
162 if (!strcmp(opt, "DisplayWidth"))
164 mp_msg(MSGT_DEMUX, MSGL_DBG2, "Display Width: %d\n", atoi(param));
165 priv->disp_width = atoi(param);
167 if (!strcmp(opt, "DisplayHeight"))
169 mp_msg(MSGT_DEMUX, MSGL_DBG2, "Display Height: %d\n", atoi(param));
170 priv->disp_height = atoi(param);
173 /* audio specific */
174 if (!strcmp(opt, "RecordType"))
176 /* no audio recordblock by Vivo/1.00, 3 and 4 by Vivo/2.00 */
177 if ((atoi(param) == 3) || (atoi(param) == 4))
178 parser_in_audio_block = 1;
179 else
180 parser_in_audio_block = 0;
182 if (!strcmp(opt, "NominalBitrate"))
184 priv->audio_bitrate = atoi(param);
185 if (priv->audio_bitrate == 2000)
186 priv->audio_codec = VIVO_AUDIO_SIREN;
187 if (priv->audio_bitrate == 800)
188 priv->audio_codec = VIVO_AUDIO_G723;
190 if (!strcmp(opt, "SamplingFrequency"))
192 priv->audio_samplerate = atoi(param);
193 if (priv->audio_samplerate == 16000)
194 priv->audio_codec = VIVO_AUDIO_SIREN;
195 if (priv->audio_samplerate == 8000)
196 priv->audio_codec = VIVO_AUDIO_G723;
198 if (!strcmp(opt, "Length") && (parser_in_audio_block == 1))
200 priv->audio_bytesperblock = atoi(param); /* 24 or 40 kbps */
201 if (priv->audio_bytesperblock == 40)
202 priv->audio_codec = VIVO_AUDIO_SIREN;
203 if (priv->audio_bytesperblock == 24)
204 priv->audio_codec = VIVO_AUDIO_G723;
207 /* only for displaying some informations about movie*/
208 if (!strcmp(opt, "Title"))
210 demux_info_add(demux, "title", param);
211 priv->title = strdup(param);
213 if (!strcmp(opt, "Author"))
215 demux_info_add(demux, "author", param);
216 priv->author = strdup(param);
218 if (!strcmp(opt, "Copyright"))
220 demux_info_add(demux, "copyright", param);
221 priv->copyright = strdup(param);
223 if (!strcmp(opt, "Producer"))
225 demux_info_add(demux, "encoder", param);
226 priv->producer = strdup(param);
229 /* get next token */
230 token = strtok(NULL, (char *)&("\x0d\x0a"));
233 free(buf);
234 free(opt);
235 free(param);
238 static int vivo_check_file(demuxer_t* demuxer){
239 int i=0;
240 int len;
241 int c;
242 unsigned char buf[2048+256];
243 vivo_priv_t* priv;
244 int orig_pos = stream_tell(demuxer->stream);
246 mp_msg(MSGT_DEMUX,MSGL_V,"Checking for VIVO\n");
248 c=stream_read_char(demuxer->stream);
249 if(c==-256) return 0;
250 len=0;
251 while((c=stream_read_char(demuxer->stream))>=0x80){
252 len+=0x80*(c-0x80);
253 if(len>1024) return 0;
255 len+=c;
256 mp_msg(MSGT_DEMUX,MSGL_V,"header block 1 size: %d\n",len);
257 //stream_skip(demuxer->stream,len);
259 priv=malloc(sizeof(vivo_priv_t));
260 memset(priv,0,sizeof(vivo_priv_t));
261 demuxer->priv=priv;
263 #if 0
264 vivo_parse_text_header(demuxer, len);
265 if (priv->supported == 0)
266 return 0;
267 #else
268 /* this is enought for check (for now) */
269 stream_read(demuxer->stream,buf,len);
270 buf[len]=0;
271 // printf("VIVO header: '%s'\n",buf);
273 // parse header:
274 i=0;
275 while(i<len && buf[i]==0x0D && buf[i+1]==0x0A) i+=2; // skip empty lines
276 if(strncmp(buf+i,"Version:Vivo/",13)) return 0; // bad version/type!
277 #endif
279 #if 0
280 c=stream_read_char(demuxer->stream);
281 if(c) return 0;
282 len2=0;
283 while((c=stream_read_char(demuxer->stream))>=0x80){
284 len2+=0x80*(c-0x80);
285 if(len+len2>2048) return 0;
287 len2+=c;
288 mp_msg(MSGT_DEMUX,MSGL_V,"header block 2 size: %d\n",len2);
289 stream_skip(demuxer->stream,len2);
290 // stream_read(demuxer->stream,buf+len,len2);
291 #endif
293 // c=stream_read_char(demuxer->stream);
294 // printf("first packet: %02X\n",c);
296 stream_seek(demuxer->stream, orig_pos);
298 return DEMUXER_TYPE_VIVO;
301 static int audio_pos=0;
302 static int audio_rate=0;
304 // return value:
305 // 0 = EOF or no stream found
306 // 1 = successfully read a packet
307 static int demux_vivo_fill_buffer(demuxer_t *demux, demux_stream_t *dsds){
308 demux_stream_t *ds=NULL;
309 int c;
310 int len=0;
311 int seq;
312 int prefix=0;
313 demux->filepos=stream_tell(demux->stream);
315 c=stream_read_char(demux->stream);
316 if (c == -256) /* EOF */
317 return 0;
318 // printf("c=%x,%02X\n",c,c&0xf0);
319 if (c == 0x82)
321 /* ok, this works, but pts calculating from header is required! */
322 /* FIXME: "Calculate PTS from picture header!" */
323 prefix = 1;
324 c = stream_read_char(demux->stream);
325 mp_msg(MSGT_DEMUX, MSGL_V, "packet 0x82(pos=%u) chunk=%x\n",
326 (int)stream_tell(demux->stream), c);
328 switch(c&0xF0){
329 case 0x00: // header - skip it!
331 len=stream_read_char(demux->stream);
332 if(len>=0x80) len=0x80*(len-0x80)+stream_read_char(demux->stream);
333 mp_msg(MSGT_DEMUX, MSGL_V, "vivo extra header: %d bytes\n",len);
334 #ifdef TEXTPARSE_ALL
336 int pos;
337 /* also try to parse all headers */
338 pos = stream_tell(demux->stream);
339 vivo_parse_text_header(demux, len);
340 stream_seek(demux->stream, pos);
342 #endif
343 break;
345 case 0x10: // video packet
346 if (prefix == 1)
347 len = stream_read_char(demux->stream);
348 else
349 len=128;
350 ds=demux->video;
351 break;
352 case 0x20: // video packet
353 len=stream_read_char(demux->stream);
354 ds=demux->video;
355 break;
356 case 0x30: // audio packet
357 if (prefix == 1)
358 len = stream_read_char(demux->stream);
359 else
360 len=40; /* 40kbps */
361 ds=demux->audio;
362 audio_pos+=len;
363 break;
364 case 0x40: // audio packet
365 if (prefix == 1)
366 len = stream_read_char(demux->stream);
367 else
368 len=24; /* 24kbps */
369 ds=demux->audio;
370 audio_pos+=len;
371 break;
372 default:
373 mp_msg(MSGT_DEMUX,MSGL_WARN,"VIVO - unknown ID found: %02X at pos %"PRIu64" contact author!\n",
374 c, (int64_t)stream_tell(demux->stream));
375 return 0;
378 // printf("chunk=%x, len=%d\n", c, len);
380 if(!ds || ds->id<-1){
381 if(len) stream_skip(demux->stream,len);
382 return 1;
385 seq=c&0x0F;
387 if(ds->asf_packet){
388 if(ds->asf_seq!=seq){
389 // closed segment, finalize packet:
390 ds_add_packet(ds,ds->asf_packet);
391 ds->asf_packet=NULL;
392 // printf("packet!\n");
393 } else {
394 // append data to it!
395 demux_packet_t* dp=ds->asf_packet;
396 if(dp->len + len + MP_INPUT_BUFFER_PADDING_SIZE < 0)
397 return 0;
398 dp->buffer=realloc(dp->buffer,dp->len+len+MP_INPUT_BUFFER_PADDING_SIZE);
399 memset(dp->buffer+dp->len+len, 0, MP_INPUT_BUFFER_PADDING_SIZE);
400 //memcpy(dp->buffer+dp->len,data,len);
401 stream_read(demux->stream,dp->buffer+dp->len,len);
402 mp_dbg(MSGT_DEMUX,MSGL_DBG4,"data appended! %d+%d\n",dp->len,len);
403 dp->len+=len;
404 // we are ready now.
405 if((c&0xF0)==0x20) --ds->asf_seq; // hack!
406 return 1;
409 // create new packet:
410 { demux_packet_t* dp;
411 dp=new_demux_packet(len);
412 //memcpy(dp->buffer,data,len);
413 stream_read(demux->stream,dp->buffer,len);
414 dp->pts=audio_rate?((float)audio_pos/(float)audio_rate):0;
415 // dp->flags=keyframe;
416 // if(ds==demux->video) printf("ASF time: %8d dur: %5d \n",time,dur);
417 dp->pos=demux->filepos;
418 ds->asf_packet=dp;
419 ds->asf_seq=seq;
420 // we are ready now.
421 return 1;
426 static const short h263_format[8][2] = {
427 { 0, 0 },
428 { 128, 96 },
429 { 176, 144 },
430 { 352, 288 },
431 { 704, 576 },
432 { 1408, 1152 },
433 { 320, 240 } // ??????? or 240x180 (found in vivo2) ?
436 static unsigned char* buffer;
437 static int bufptr=0;
438 static int bitcnt=0;
439 static unsigned char buf=0;
440 static int format, width, height;
442 static unsigned int x_get_bits(int n){
443 unsigned int x=0;
444 while(n-->0){
445 if(!bitcnt){
446 // fill buff
447 buf=buffer[bufptr++];
448 bitcnt=8;
450 //x=(x<<1)|(buf&1);buf>>=1;
451 x=(x<<1)|(buf>>7);buf<<=1;
452 --bitcnt;
454 return x;
457 #define get_bits(xxx,n) x_get_bits(n)
458 #define get_bits1(xxx) x_get_bits(1)
459 #define skip_bits(xxx,n) x_get_bits(n)
460 #define skip_bits1(xxx) x_get_bits(1)
462 /* most is hardcoded. should extend to handle all h263 streams */
463 static int h263_decode_picture_header(unsigned char *b_ptr)
465 // int i;
467 // for(i=0;i<16;i++) printf(" %02X",b_ptr[i]); printf("\n");
469 buffer=b_ptr;
470 bufptr=bitcnt=buf=0;
472 /* picture header */
473 if (get_bits(&s->gb, 22) != 0x20){
474 mp_msg(MSGT_DEMUX, MSGL_FATAL, "bad picture header\n");
475 return -1;
477 skip_bits(&s->gb, 8); /* picture timestamp */
479 if (get_bits1(&s->gb) != 1){
480 mp_msg(MSGT_DEMUX, MSGL_FATAL, "bad marker\n");
481 return -1; /* marker */
483 if (get_bits1(&s->gb) != 0){
484 mp_msg(MSGT_DEMUX, MSGL_FATAL, "bad h263 id\n");
485 return -1; /* h263 id */
487 skip_bits1(&s->gb); /* split screen off */
488 skip_bits1(&s->gb); /* camera off */
489 skip_bits1(&s->gb); /* freeze picture release off */
491 format = get_bits(&s->gb, 3);
493 if (format != 7) {
494 mp_msg(MSGT_DEMUX, MSGL_V, "h263_plus = 0 format = %d\n", format);
495 /* H.263v1 */
496 width = h263_format[format][0];
497 height = h263_format[format][1];
498 mp_msg(MSGT_DEMUX, MSGL_V, "%d x %d\n", width, height);
499 // if (!width) return -1;
501 mp_msg(MSGT_DEMUX, MSGL_V, "pict_type=%d\n", get_bits1(&s->gb));
502 mp_msg(MSGT_DEMUX, MSGL_V, "unrestricted_mv=%d\n", get_bits1(&s->gb));
503 #if 1
504 mp_msg(MSGT_DEMUX, MSGL_V, "SAC: %d\n", get_bits1(&s->gb));
505 mp_msg(MSGT_DEMUX, MSGL_V, "advanced prediction mode: %d\n", get_bits1(&s->gb));
506 mp_msg(MSGT_DEMUX, MSGL_V, "PB frame: %d\n", get_bits1(&s->gb));
507 #else
508 if (get_bits1(&s->gb) != 0)
509 return -1; /* SAC: off */
510 if (get_bits1(&s->gb) != 0)
511 return -1; /* advanced prediction mode: off */
512 if (get_bits1(&s->gb) != 0)
513 return -1; /* not PB frame */
514 #endif
515 mp_msg(MSGT_DEMUX, MSGL_V, "qscale=%d\n", get_bits(&s->gb, 5));
516 skip_bits1(&s->gb); /* Continuous Presence Multipoint mode: off */
517 } else {
518 mp_msg(MSGT_DEMUX, MSGL_V, "h263_plus = 1\n");
519 /* H.263v2 */
520 if (get_bits(&s->gb, 3) != 1){
521 mp_msg(MSGT_DEMUX, MSGL_FATAL, "H.263v2 A error\n");
522 return -1;
524 if (get_bits(&s->gb, 3) != 6){ /* custom source format */
525 mp_msg(MSGT_DEMUX, MSGL_FATAL, "custom source format\n");
526 return -1;
528 skip_bits(&s->gb, 12);
529 skip_bits(&s->gb, 3);
530 mp_msg(MSGT_DEMUX, MSGL_V, "pict_type=%d\n", get_bits(&s->gb, 3) + 1);
531 // if (s->pict_type != I_TYPE &&
532 // s->pict_type != P_TYPE)
533 // return -1;
534 skip_bits(&s->gb, 7);
535 skip_bits(&s->gb, 4); /* aspect ratio */
536 width = (get_bits(&s->gb, 9) + 1) * 4;
537 skip_bits1(&s->gb);
538 height = get_bits(&s->gb, 9) * 4;
539 mp_msg(MSGT_DEMUX, MSGL_V, "%d x %d\n", width, height);
540 //if (height == 0)
541 // return -1;
542 mp_msg(MSGT_DEMUX, MSGL_V, "qscale=%d\n", get_bits(&s->gb, 5));
545 /* PEI */
546 while (get_bits1(&s->gb) != 0) {
547 skip_bits(&s->gb, 8);
549 // s->f_code = 1;
550 // s->width = width;
551 // s->height = height;
552 return 0;
557 static demuxer_t* demux_open_vivo(demuxer_t* demuxer){
558 vivo_priv_t* priv=demuxer->priv;
560 if(!ds_fill_buffer(demuxer->video)){
561 mp_msg(MSGT_DEMUX, MSGL_ERR, "VIVO: %s",
562 mp_gtext("Missing video stream!? Contact the author, it may be a bug :(\n"));
563 return NULL;
566 audio_pos=0;
568 h263_decode_picture_header(demuxer->video->buffer);
570 if (vivo_param_version != -1)
571 priv->version = '0' + vivo_param_version;
573 { sh_video_t* sh=new_sh_video(demuxer,0);
575 /* viv1, viv2 (for better codecs.conf) */
576 sh->format = mmioFOURCC('v', 'i', 'v', priv->version);
577 if(!sh->fps)
579 if (priv->fps)
580 sh->fps=priv->fps;
581 else
582 sh->fps=15.0f;
584 sh->frametime=1.0f/sh->fps;
586 /* XXX: FIXME: can't scale image. */
587 /* hotfix to disable: */
588 priv->disp_width = priv->width;
589 priv->disp_height = priv->height;
591 if (vivo_param_width != -1)
592 priv->disp_width = priv->width = vivo_param_width;
594 if (vivo_param_height != -1)
595 priv->disp_height = priv->height = vivo_param_height;
597 if (vivo_param_vformat != -1)
599 priv->disp_width = priv->width = h263_format[vivo_param_vformat][0];
600 priv->disp_height = priv->height = h263_format[vivo_param_vformat][1];
603 if (priv->disp_width)
604 sh->disp_w = priv->disp_width;
605 else
606 sh->disp_w = width;
607 if (priv->disp_height)
608 sh->disp_h = priv->disp_height;
609 else
610 sh->disp_h = height;
612 // emulate BITMAPINFOHEADER:
613 sh->bih=calloc(1, sizeof(*sh->bih));
614 sh->bih->biSize=40;
615 if (priv->width)
616 sh->bih->biWidth = priv->width;
617 else
618 sh->bih->biWidth = width;
619 if (priv->height)
620 sh->bih->biHeight = priv->height;
621 else
622 sh->bih->biHeight = height;
623 sh->bih->biPlanes=1;
624 sh->bih->biBitCount=24;
625 sh->bih->biCompression=sh->format;
626 sh->bih->biSizeImage=sh->bih->biWidth*sh->bih->biHeight*3;
628 /* insert as stream */
629 demuxer->video->sh=sh;
630 sh->ds=demuxer->video;
631 demuxer->video->id=0;
633 /* disable seeking */
634 demuxer->seekable = 0;
636 mp_msg(MSGT_DEMUX,MSGL_V,"VIVO Video stream %d size: display: %dx%d, codec: %ux%u\n",
637 demuxer->video->id, sh->disp_w, sh->disp_h, sh->bih->biWidth,
638 sh->bih->biHeight);
641 /* AUDIO init */
642 if (demuxer->audio->id >= -1){
643 if(!ds_fill_buffer(demuxer->audio)){
644 mp_msg(MSGT_DEMUX, MSGL_ERR, "VIVO: %s",
645 mp_gtext("No audio stream found -> no sound.\n"));
646 } else
647 { sh_audio_t* sh=new_sh_audio(demuxer,1);
649 /* Select audio codec */
650 if (priv->audio_codec == 0)
652 if (priv->version == '2')
653 priv->audio_codec = VIVO_AUDIO_SIREN;
654 else
655 priv->audio_codec = VIVO_AUDIO_G723;
657 if (vivo_param_acodec != NULL)
659 if (!strcasecmp(vivo_param_acodec, "g723"))
660 priv->audio_codec = VIVO_AUDIO_G723;
661 if (!strcasecmp(vivo_param_acodec, "siren"))
662 priv->audio_codec = VIVO_AUDIO_SIREN;
665 if (priv->audio_codec == VIVO_AUDIO_G723)
666 sh->format = 0x111;
667 else if (priv->audio_codec == VIVO_AUDIO_SIREN)
668 sh->format = 0x112;
669 else
671 mp_msg(MSGT_DEMUX, MSGL_ERR, "VIVO: Not support audio codec (%d)\n",
672 priv->audio_codec);
673 free_sh_audio(demuxer, 1);
674 goto nosound;
677 // Emulate WAVEFORMATEX struct:
678 sh->wf=calloc(1, sizeof(*sh->wf));
679 sh->wf->wFormatTag=sh->format;
680 sh->wf->nChannels=1; /* 1 channels for both Siren and G.723 */
682 /* Set bits per sample */
683 if (priv->audio_codec == VIVO_AUDIO_SIREN)
684 sh->wf->wBitsPerSample = 16;
685 else
686 if (priv->audio_codec == VIVO_AUDIO_G723)
687 sh->wf->wBitsPerSample = 8;
689 /* Set sampling rate */
690 if (priv->audio_samplerate) /* got from header */
691 sh->wf->nSamplesPerSec = priv->audio_samplerate;
692 else
694 if (priv->audio_codec == VIVO_AUDIO_SIREN)
695 sh->wf->nSamplesPerSec = 16000;
696 if (priv->audio_codec == VIVO_AUDIO_G723)
697 sh->wf->nSamplesPerSec = 8000;
699 if (vivo_param_samplerate != -1)
700 sh->wf->nSamplesPerSec = vivo_param_samplerate;
702 /* Set audio bitrate */
703 if (priv->audio_bitrate) /* got from header */
704 sh->wf->nAvgBytesPerSec = priv->audio_bitrate;
705 else
707 if (priv->audio_codec == VIVO_AUDIO_SIREN)
708 sh->wf->nAvgBytesPerSec = 2000;
709 if (priv->audio_codec == VIVO_AUDIO_G723)
710 sh->wf->nAvgBytesPerSec = 800;
712 if (vivo_param_abitrate != -1)
713 sh->wf->nAvgBytesPerSec = vivo_param_abitrate;
714 audio_rate=sh->wf->nAvgBytesPerSec;
716 if (!priv->audio_bytesperblock)
718 if (priv->audio_codec == VIVO_AUDIO_SIREN)
719 sh->wf->nBlockAlign = 40;
720 if (priv->audio_codec == VIVO_AUDIO_G723)
721 sh->wf->nBlockAlign = 24;
723 else
724 sh->wf->nBlockAlign = priv->audio_bytesperblock;
725 if (vivo_param_bytesperblock != -1)
726 sh->wf->nBlockAlign = vivo_param_bytesperblock;
728 /*sound_ok:*/
729 /* insert as stream */
730 demuxer->audio->sh=sh;
731 sh->ds=demuxer->audio;
732 demuxer->audio->id=1;
733 nosound:
734 return demuxer;
737 return demuxer;
740 static void demux_close_vivo(demuxer_t *demuxer)
742 vivo_priv_t* priv=demuxer->priv;
744 if (priv) {
745 free(priv->title);
746 free(priv->author);
747 free(priv->copyright);
748 free(priv->producer);
749 free(priv);
751 return;
755 const demuxer_desc_t demuxer_desc_vivo = {
756 "Vivo demuxer",
757 "vivo",
758 "VIVO",
759 "A'rpi, Alex Beregszasi",
761 DEMUXER_TYPE_VIVO,
762 0, // unsafe autodetect
763 vivo_check_file,
764 demux_vivo_fill_buffer,
765 demux_open_vivo,
766 demux_close_vivo,
767 NULL,
768 NULL