demux_real.c: Remove unused hexdump() forward declaration
[mplayer/greg.git] / libmpdemux / demux_viv.c
blob1d9999940fefff3cc7a40f6a5701b20814122256
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 if (buf)
234 free(buf);
235 if (opt)
236 free(opt);
237 if (param)
238 free(param);
241 static int vivo_check_file(demuxer_t* demuxer){
242 int i=0;
243 int len;
244 int c;
245 unsigned char buf[2048+256];
246 vivo_priv_t* priv;
247 int orig_pos = stream_tell(demuxer->stream);
249 mp_msg(MSGT_DEMUX,MSGL_V,"Checking for VIVO\n");
251 c=stream_read_char(demuxer->stream);
252 if(c==-256) return 0;
253 len=0;
254 while((c=stream_read_char(demuxer->stream))>=0x80){
255 len+=0x80*(c-0x80);
256 if(len>1024) return 0;
258 len+=c;
259 mp_msg(MSGT_DEMUX,MSGL_V,"header block 1 size: %d\n",len);
260 //stream_skip(demuxer->stream,len);
262 priv=malloc(sizeof(vivo_priv_t));
263 memset(priv,0,sizeof(vivo_priv_t));
264 demuxer->priv=priv;
266 #if 0
267 vivo_parse_text_header(demuxer, len);
268 if (priv->supported == 0)
269 return 0;
270 #else
271 /* this is enought for check (for now) */
272 stream_read(demuxer->stream,buf,len);
273 buf[len]=0;
274 // printf("VIVO header: '%s'\n",buf);
276 // parse header:
277 i=0;
278 while(i<len && buf[i]==0x0D && buf[i+1]==0x0A) i+=2; // skip empty lines
279 if(strncmp(buf+i,"Version:Vivo/",13)) return 0; // bad version/type!
280 #endif
282 #if 0
283 c=stream_read_char(demuxer->stream);
284 if(c) return 0;
285 len2=0;
286 while((c=stream_read_char(demuxer->stream))>=0x80){
287 len2+=0x80*(c-0x80);
288 if(len+len2>2048) return 0;
290 len2+=c;
291 mp_msg(MSGT_DEMUX,MSGL_V,"header block 2 size: %d\n",len2);
292 stream_skip(demuxer->stream,len2);
293 // stream_read(demuxer->stream,buf+len,len2);
294 #endif
296 // c=stream_read_char(demuxer->stream);
297 // printf("first packet: %02X\n",c);
299 stream_seek(demuxer->stream, orig_pos);
301 return DEMUXER_TYPE_VIVO;
304 static int audio_pos=0;
305 static int audio_rate=0;
307 // return value:
308 // 0 = EOF or no stream found
309 // 1 = successfully read a packet
310 static int demux_vivo_fill_buffer(demuxer_t *demux, demux_stream_t *dsds){
311 demux_stream_t *ds=NULL;
312 int c;
313 int len=0;
314 int seq;
315 int prefix=0;
316 demux->filepos=stream_tell(demux->stream);
318 c=stream_read_char(demux->stream);
319 if (c == -256) /* EOF */
320 return 0;
321 // printf("c=%x,%02X\n",c,c&0xf0);
322 if (c == 0x82)
324 /* ok, this works, but pts calculating from header is required! */
325 #warning "Calculate PTS from picture header!"
326 prefix = 1;
327 c = stream_read_char(demux->stream);
328 mp_msg(MSGT_DEMUX, MSGL_V, "packet 0x82(pos=%u) chunk=%x\n",
329 (int)stream_tell(demux->stream), c);
331 switch(c&0xF0){
332 case 0x00: // header - skip it!
334 len=stream_read_char(demux->stream);
335 if(len>=0x80) len=0x80*(len-0x80)+stream_read_char(demux->stream);
336 mp_msg(MSGT_DEMUX, MSGL_V, "vivo extra header: %d bytes\n",len);
337 #ifdef TEXTPARSE_ALL
339 int pos;
340 /* also try to parse all headers */
341 pos = stream_tell(demux->stream);
342 vivo_parse_text_header(demux, len);
343 stream_seek(demux->stream, pos);
345 #endif
346 break;
348 case 0x10: // video packet
349 if (prefix == 1)
350 len = stream_read_char(demux->stream);
351 else
352 len=128;
353 ds=demux->video;
354 break;
355 case 0x20: // video packet
356 len=stream_read_char(demux->stream);
357 ds=demux->video;
358 break;
359 case 0x30: // audio packet
360 if (prefix == 1)
361 len = stream_read_char(demux->stream);
362 else
363 len=40; /* 40kbps */
364 ds=demux->audio;
365 audio_pos+=len;
366 break;
367 case 0x40: // audio packet
368 if (prefix == 1)
369 len = stream_read_char(demux->stream);
370 else
371 len=24; /* 24kbps */
372 ds=demux->audio;
373 audio_pos+=len;
374 break;
375 default:
376 mp_msg(MSGT_DEMUX,MSGL_WARN,"VIVO - unknown ID found: %02X at pos %"PRIu64" contact author!\n",
377 c, (int64_t)stream_tell(demux->stream));
378 return 0;
381 // printf("chunk=%x, len=%d\n", c, len);
383 if(!ds || ds->id<-1){
384 if(len) stream_skip(demux->stream,len);
385 return 1;
388 seq=c&0x0F;
390 if(ds->asf_packet){
391 if(ds->asf_seq!=seq){
392 // closed segment, finalize packet:
393 ds_add_packet(ds,ds->asf_packet);
394 ds->asf_packet=NULL;
395 // printf("packet!\n");
396 } else {
397 // append data to it!
398 demux_packet_t* dp=ds->asf_packet;
399 if(dp->len + len + MP_INPUT_BUFFER_PADDING_SIZE < 0)
400 return 0;
401 dp->buffer=realloc(dp->buffer,dp->len+len+MP_INPUT_BUFFER_PADDING_SIZE);
402 memset(dp->buffer+dp->len+len, 0, MP_INPUT_BUFFER_PADDING_SIZE);
403 //memcpy(dp->buffer+dp->len,data,len);
404 stream_read(demux->stream,dp->buffer+dp->len,len);
405 mp_dbg(MSGT_DEMUX,MSGL_DBG4,"data appended! %d+%d\n",dp->len,len);
406 dp->len+=len;
407 // we are ready now.
408 if((c&0xF0)==0x20) --ds->asf_seq; // hack!
409 return 1;
412 // create new packet:
413 { demux_packet_t* dp;
414 dp=new_demux_packet(len);
415 //memcpy(dp->buffer,data,len);
416 stream_read(demux->stream,dp->buffer,len);
417 dp->pts=audio_rate?((float)audio_pos/(float)audio_rate):0;
418 // dp->flags=keyframe;
419 // if(ds==demux->video) printf("ASF time: %8d dur: %5d \n",time,dur);
420 dp->pos=demux->filepos;
421 ds->asf_packet=dp;
422 ds->asf_seq=seq;
423 // we are ready now.
424 return 1;
429 static const short h263_format[8][2] = {
430 { 0, 0 },
431 { 128, 96 },
432 { 176, 144 },
433 { 352, 288 },
434 { 704, 576 },
435 { 1408, 1152 },
436 { 320, 240 } // ??????? or 240x180 (found in vivo2) ?
439 static unsigned char* buffer;
440 static int bufptr=0;
441 static int bitcnt=0;
442 static unsigned char buf=0;
443 static int format, width, height;
445 static unsigned int x_get_bits(int n){
446 unsigned int x=0;
447 while(n-->0){
448 if(!bitcnt){
449 // fill buff
450 buf=buffer[bufptr++];
451 bitcnt=8;
453 //x=(x<<1)|(buf&1);buf>>=1;
454 x=(x<<1)|(buf>>7);buf<<=1;
455 --bitcnt;
457 return x;
460 #define get_bits(xxx,n) x_get_bits(n)
461 #define get_bits1(xxx) x_get_bits(1)
462 #define skip_bits(xxx,n) x_get_bits(n)
463 #define skip_bits1(xxx) x_get_bits(1)
465 /* most is hardcoded. should extend to handle all h263 streams */
466 static int h263_decode_picture_header(unsigned char *b_ptr)
468 // int i;
470 // for(i=0;i<16;i++) printf(" %02X",b_ptr[i]); printf("\n");
472 buffer=b_ptr;
473 bufptr=bitcnt=buf=0;
475 /* picture header */
476 if (get_bits(&s->gb, 22) != 0x20){
477 mp_msg(MSGT_DEMUX, MSGL_FATAL, "bad picture header\n");
478 return -1;
480 skip_bits(&s->gb, 8); /* picture timestamp */
482 if (get_bits1(&s->gb) != 1){
483 mp_msg(MSGT_DEMUX, MSGL_FATAL, "bad marker\n");
484 return -1; /* marker */
486 if (get_bits1(&s->gb) != 0){
487 mp_msg(MSGT_DEMUX, MSGL_FATAL, "bad h263 id\n");
488 return -1; /* h263 id */
490 skip_bits1(&s->gb); /* split screen off */
491 skip_bits1(&s->gb); /* camera off */
492 skip_bits1(&s->gb); /* freeze picture release off */
494 format = get_bits(&s->gb, 3);
496 if (format != 7) {
497 mp_msg(MSGT_DEMUX, MSGL_V, "h263_plus = 0 format = %d\n", format);
498 /* H.263v1 */
499 width = h263_format[format][0];
500 height = h263_format[format][1];
501 mp_msg(MSGT_DEMUX, MSGL_V, "%d x %d\n", width, height);
502 // if (!width) return -1;
504 mp_msg(MSGT_DEMUX, MSGL_V, "pict_type=%d\n", get_bits1(&s->gb));
505 mp_msg(MSGT_DEMUX, MSGL_V, "unrestricted_mv=%d\n", get_bits1(&s->gb));
506 #if 1
507 mp_msg(MSGT_DEMUX, MSGL_V, "SAC: %d\n", get_bits1(&s->gb));
508 mp_msg(MSGT_DEMUX, MSGL_V, "advanced prediction mode: %d\n", get_bits1(&s->gb));
509 mp_msg(MSGT_DEMUX, MSGL_V, "PB frame: %d\n", get_bits1(&s->gb));
510 #else
511 if (get_bits1(&s->gb) != 0)
512 return -1; /* SAC: off */
513 if (get_bits1(&s->gb) != 0)
514 return -1; /* advanced prediction mode: off */
515 if (get_bits1(&s->gb) != 0)
516 return -1; /* not PB frame */
517 #endif
518 mp_msg(MSGT_DEMUX, MSGL_V, "qscale=%d\n", get_bits(&s->gb, 5));
519 skip_bits1(&s->gb); /* Continuous Presence Multipoint mode: off */
520 } else {
521 mp_msg(MSGT_DEMUX, MSGL_V, "h263_plus = 1\n");
522 /* H.263v2 */
523 if (get_bits(&s->gb, 3) != 1){
524 mp_msg(MSGT_DEMUX, MSGL_FATAL, "H.263v2 A error\n");
525 return -1;
527 if (get_bits(&s->gb, 3) != 6){ /* custom source format */
528 mp_msg(MSGT_DEMUX, MSGL_FATAL, "custom source format\n");
529 return -1;
531 skip_bits(&s->gb, 12);
532 skip_bits(&s->gb, 3);
533 mp_msg(MSGT_DEMUX, MSGL_V, "pict_type=%d\n", get_bits(&s->gb, 3) + 1);
534 // if (s->pict_type != I_TYPE &&
535 // s->pict_type != P_TYPE)
536 // return -1;
537 skip_bits(&s->gb, 7);
538 skip_bits(&s->gb, 4); /* aspect ratio */
539 width = (get_bits(&s->gb, 9) + 1) * 4;
540 skip_bits1(&s->gb);
541 height = get_bits(&s->gb, 9) * 4;
542 mp_msg(MSGT_DEMUX, MSGL_V, "%d x %d\n", width, height);
543 //if (height == 0)
544 // return -1;
545 mp_msg(MSGT_DEMUX, MSGL_V, "qscale=%d\n", get_bits(&s->gb, 5));
548 /* PEI */
549 while (get_bits1(&s->gb) != 0) {
550 skip_bits(&s->gb, 8);
552 // s->f_code = 1;
553 // s->width = width;
554 // s->height = height;
555 return 0;
560 static demuxer_t* demux_open_vivo(demuxer_t* demuxer){
561 vivo_priv_t* priv=demuxer->priv;
563 if(!ds_fill_buffer(demuxer->video)){
564 mp_msg(MSGT_DEMUX, MSGL_ERR, "VIVO: %s",
565 mp_gtext("Missing video stream!? Contact the author, it may be a bug :(\n"));
566 return NULL;
569 audio_pos=0;
571 h263_decode_picture_header(demuxer->video->buffer);
573 if (vivo_param_version != -1)
574 priv->version = '0' + vivo_param_version;
576 { sh_video_t* sh=new_sh_video(demuxer,0);
578 /* viv1, viv2 (for better codecs.conf) */
579 sh->format = mmioFOURCC('v', 'i', 'v', priv->version);
580 if(!sh->fps)
582 if (priv->fps)
583 sh->fps=priv->fps;
584 else
585 sh->fps=15.0f;
587 sh->frametime=1.0f/sh->fps;
589 /* XXX: FIXME: can't scale image. */
590 /* hotfix to disable: */
591 priv->disp_width = priv->width;
592 priv->disp_height = priv->height;
594 if (vivo_param_width != -1)
595 priv->disp_width = priv->width = vivo_param_width;
597 if (vivo_param_height != -1)
598 priv->disp_height = priv->height = vivo_param_height;
600 if (vivo_param_vformat != -1)
602 priv->disp_width = priv->width = h263_format[vivo_param_vformat][0];
603 priv->disp_height = priv->height = h263_format[vivo_param_vformat][1];
606 if (priv->disp_width)
607 sh->disp_w = priv->disp_width;
608 else
609 sh->disp_w = width;
610 if (priv->disp_height)
611 sh->disp_h = priv->disp_height;
612 else
613 sh->disp_h = height;
615 // emulate BITMAPINFOHEADER:
616 sh->bih=calloc(1, sizeof(*sh->bih));
617 sh->bih->biSize=40;
618 if (priv->width)
619 sh->bih->biWidth = priv->width;
620 else
621 sh->bih->biWidth = width;
622 if (priv->height)
623 sh->bih->biHeight = priv->height;
624 else
625 sh->bih->biHeight = height;
626 sh->bih->biPlanes=1;
627 sh->bih->biBitCount=24;
628 sh->bih->biCompression=sh->format;
629 sh->bih->biSizeImage=sh->bih->biWidth*sh->bih->biHeight*3;
631 /* insert as stream */
632 demuxer->video->sh=sh;
633 sh->ds=demuxer->video;
634 demuxer->video->id=0;
636 /* disable seeking */
637 demuxer->seekable = 0;
639 mp_msg(MSGT_DEMUX,MSGL_V,"VIVO Video stream %d size: display: %dx%d, codec: %ux%u\n",
640 demuxer->video->id, sh->disp_w, sh->disp_h, sh->bih->biWidth,
641 sh->bih->biHeight);
644 /* AUDIO init */
645 if (demuxer->audio->id >= -1){
646 if(!ds_fill_buffer(demuxer->audio)){
647 mp_msg(MSGT_DEMUX, MSGL_ERR, "VIVO: %s",
648 mp_gtext("No audio stream found -> no sound.\n"));
649 } else
650 { sh_audio_t* sh=new_sh_audio(demuxer,1);
652 /* Select audio codec */
653 if (priv->audio_codec == 0)
655 if (priv->version == '2')
656 priv->audio_codec = VIVO_AUDIO_SIREN;
657 else
658 priv->audio_codec = VIVO_AUDIO_G723;
660 if (vivo_param_acodec != NULL)
662 if (!strcasecmp(vivo_param_acodec, "g723"))
663 priv->audio_codec = VIVO_AUDIO_G723;
664 if (!strcasecmp(vivo_param_acodec, "siren"))
665 priv->audio_codec = VIVO_AUDIO_SIREN;
668 if (priv->audio_codec == VIVO_AUDIO_G723)
669 sh->format = 0x111;
670 else if (priv->audio_codec == VIVO_AUDIO_SIREN)
671 sh->format = 0x112;
672 else
674 mp_msg(MSGT_DEMUX, MSGL_ERR, "VIVO: Not support audio codec (%d)\n",
675 priv->audio_codec);
676 free_sh_audio(demuxer, 1);
677 goto nosound;
680 // Emulate WAVEFORMATEX struct:
681 sh->wf=calloc(1, sizeof(*sh->wf));
682 sh->wf->wFormatTag=sh->format;
683 sh->wf->nChannels=1; /* 1 channels for both Siren and G.723 */
685 /* Set bits per sample */
686 if (priv->audio_codec == VIVO_AUDIO_SIREN)
687 sh->wf->wBitsPerSample = 16;
688 else
689 if (priv->audio_codec == VIVO_AUDIO_G723)
690 sh->wf->wBitsPerSample = 8;
692 /* Set sampling rate */
693 if (priv->audio_samplerate) /* got from header */
694 sh->wf->nSamplesPerSec = priv->audio_samplerate;
695 else
697 if (priv->audio_codec == VIVO_AUDIO_SIREN)
698 sh->wf->nSamplesPerSec = 16000;
699 if (priv->audio_codec == VIVO_AUDIO_G723)
700 sh->wf->nSamplesPerSec = 8000;
702 if (vivo_param_samplerate != -1)
703 sh->wf->nSamplesPerSec = vivo_param_samplerate;
705 /* Set audio bitrate */
706 if (priv->audio_bitrate) /* got from header */
707 sh->wf->nAvgBytesPerSec = priv->audio_bitrate;
708 else
710 if (priv->audio_codec == VIVO_AUDIO_SIREN)
711 sh->wf->nAvgBytesPerSec = 2000;
712 if (priv->audio_codec == VIVO_AUDIO_G723)
713 sh->wf->nAvgBytesPerSec = 800;
715 if (vivo_param_abitrate != -1)
716 sh->wf->nAvgBytesPerSec = vivo_param_abitrate;
717 audio_rate=sh->wf->nAvgBytesPerSec;
719 if (!priv->audio_bytesperblock)
721 if (priv->audio_codec == VIVO_AUDIO_SIREN)
722 sh->wf->nBlockAlign = 40;
723 if (priv->audio_codec == VIVO_AUDIO_G723)
724 sh->wf->nBlockAlign = 24;
726 else
727 sh->wf->nBlockAlign = priv->audio_bytesperblock;
728 if (vivo_param_bytesperblock != -1)
729 sh->wf->nBlockAlign = vivo_param_bytesperblock;
731 /*sound_ok:*/
732 /* insert as stream */
733 demuxer->audio->sh=sh;
734 sh->ds=demuxer->audio;
735 demuxer->audio->id=1;
736 nosound:
737 return demuxer;
740 return demuxer;
743 static void demux_close_vivo(demuxer_t *demuxer)
745 vivo_priv_t* priv=demuxer->priv;
747 if (priv) {
748 if (priv->title)
749 free(priv->title);
750 if (priv->author)
751 free(priv->author);
752 if (priv->copyright)
753 free(priv->copyright);
754 if (priv->producer)
755 free(priv->producer);
756 free(priv);
758 return;
762 const demuxer_desc_t demuxer_desc_vivo = {
763 "Vivo demuxer",
764 "vivo",
765 "VIVO",
766 "A'rpi, Alex Beregszasi",
768 DEMUXER_TYPE_VIVO,
769 0, // unsafe autodetect
770 vivo_check_file,
771 demux_vivo_fill_buffer,
772 demux_open_vivo,
773 demux_close_vivo,
774 NULL,
775 NULL