osdep: Remove cruft
[mplayer.git] / libmpdemux / demux_viv.c
blob46ff28841d0e43108f63d8f4c9938fa9be3e46eb
1 // VIVO file parser by A'rpi
2 // VIVO text header parser and audio support by alex
4 #include <stdio.h>
5 #include <stdlib.h>
6 #include <unistd.h>
7 #include <string.h> /* strtok */
9 #include "config.h"
10 #include "mp_msg.h"
11 #include "help_mp.h"
13 #include "stream/stream.h"
14 #include "demuxer.h"
15 #include "stheader.h"
17 #ifdef USE_LIBAVCODEC
18 #include "libavcodec/avcodec.h"
19 #else
20 #define FF_INPUT_BUFFER_PADDING_SIZE 8
21 #endif
23 /* parameters ! */
24 int vivo_param_version = -1;
25 char *vivo_param_acodec = NULL;
26 int vivo_param_abitrate = -1;
27 int vivo_param_samplerate = -1;
28 int vivo_param_bytesperblock = -1;
29 int vivo_param_width = -1;
30 int vivo_param_height = -1;
31 int vivo_param_vformat = -1;
33 /* VIVO audio standards from vivog723.acm:
35 G.723:
36 FormatTag = 0x111
37 Channels = 1 - mono
38 SamplesPerSec = 8000 - 8khz
39 AvgBytesPerSec = 800
40 BlockAlign (bytes per block) = 24
41 BitsPerSample = 8
43 Siren:
44 FormatTag = 0x112
45 Channels = 1 - mono
46 SamplesPerSec = 16000 - 16khz
47 AvgBytesPerSec = 2000
48 BlockAlign (bytes per block) = 40
49 BitsPerSample = 8
52 //enum { VIVO_AUDIO_G723, VIVO_AUDIO_SIREN };
54 #define VIVO_AUDIO_G723 1
55 #define VIVO_AUDIO_SIREN 2
57 typedef struct {
58 /* generic */
59 char version;
60 int supported;
61 /* info */
62 char *title;
63 char *author;
64 char *copyright;
65 char *producer;
66 /* video */
67 float fps;
68 int width;
69 int height;
70 int disp_width;
71 int disp_height;
72 /* audio */
73 int audio_codec;
74 int audio_bitrate;
75 int audio_samplerate;
76 int audio_bytesperblock;
77 } vivo_priv_t;
79 /* parse all possible extra headers */
80 /* (audio headers are separate - mostly with recordtype=3 or 4) */
81 #define TEXTPARSE_ALL 1
83 static void vivo_parse_text_header(demuxer_t *demux, int header_len)
85 vivo_priv_t* priv = demux->priv;
86 char *buf;
87 int i;
88 char *token;
89 char *opt, *param;
90 int parser_in_audio_block = 0;
92 if (!demux->priv)
94 priv = malloc(sizeof(vivo_priv_t));
95 memset(priv, 0, sizeof(vivo_priv_t));
96 demux->priv = priv;
97 priv->supported = 0;
100 buf = malloc(header_len);
101 opt = malloc(header_len);
102 param = malloc(header_len);
103 stream_read(demux->stream, buf, header_len);
104 i=0;
105 while(i<header_len && buf[i]==0x0D && buf[i+1]==0x0A) i+=2; // skip empty lines
107 token = strtok(buf, (char *)&("\x0d\x0a"));
108 while (token && (header_len>2))
110 header_len -= strlen(token)+2;
111 if (sscanf(token, "%[^:]:%[^\n]", opt, param) != 2)
113 mp_msg(MSGT_DEMUX, MSGL_V, "viv_text_header_parser: bad line: '%s' at ~%#"PRIx64"\n",
114 token, (int64_t)stream_tell(demux->stream));
115 break;
117 mp_dbg(MSGT_DEMUX, MSGL_DBG3, "token: '%s' (%d bytes/%d bytes left)\n",
118 token, strlen(token), header_len);
119 mp_dbg(MSGT_DEMUX, MSGL_DBG3, "token => o: '%s', p: '%s'\n",
120 opt, param);
122 /* checking versions: only v1 or v2 is suitable (or known?:) */
123 if (!strcmp(opt, "Version"))
125 mp_msg(MSGT_DEMUX, MSGL_DBG2, "Version: %s\n", param);
126 if (!strncmp(param, "Vivo/1", 6) || !strncmp(param, "Vivo/2", 6))
128 priv->supported = 1;
129 /* save major version for fourcc */
130 priv->version = param[5];
134 /* video specific */
135 if (!strcmp(opt, "FPS"))
137 mp_msg(MSGT_DEMUX, MSGL_DBG2, "FPS: %f\n", atof(param));
138 priv->fps = atof(param);
140 if (!strcmp(opt, "Width"))
142 mp_msg(MSGT_DEMUX, MSGL_DBG2, "Width: %d\n", atoi(param));
143 priv->width = atoi(param);
145 if (!strcmp(opt, "Height"))
147 mp_msg(MSGT_DEMUX, MSGL_DBG2, "Height: %d\n", atoi(param));
148 priv->height = atoi(param);
150 if (!strcmp(opt, "DisplayWidth"))
152 mp_msg(MSGT_DEMUX, MSGL_DBG2, "Display Width: %d\n", atoi(param));
153 priv->disp_width = atoi(param);
155 if (!strcmp(opt, "DisplayHeight"))
157 mp_msg(MSGT_DEMUX, MSGL_DBG2, "Display Height: %d\n", atoi(param));
158 priv->disp_height = atoi(param);
161 /* audio specific */
162 if (!strcmp(opt, "RecordType"))
164 /* no audio recordblock by Vivo/1.00, 3 and 4 by Vivo/2.00 */
165 if ((atoi(param) == 3) || (atoi(param) == 4))
166 parser_in_audio_block = 1;
167 else
168 parser_in_audio_block = 0;
170 if (!strcmp(opt, "NominalBitrate"))
172 priv->audio_bitrate = atoi(param);
173 if (priv->audio_bitrate == 2000)
174 priv->audio_codec = VIVO_AUDIO_SIREN;
175 if (priv->audio_bitrate == 800)
176 priv->audio_codec = VIVO_AUDIO_G723;
178 if (!strcmp(opt, "SamplingFrequency"))
180 priv->audio_samplerate = atoi(param);
181 if (priv->audio_samplerate == 16000)
182 priv->audio_codec = VIVO_AUDIO_SIREN;
183 if (priv->audio_samplerate == 8000)
184 priv->audio_codec = VIVO_AUDIO_G723;
186 if (!strcmp(opt, "Length") && (parser_in_audio_block == 1))
188 priv->audio_bytesperblock = atoi(param); /* 24 or 40 kbps */
189 if (priv->audio_bytesperblock == 40)
190 priv->audio_codec = VIVO_AUDIO_SIREN;
191 if (priv->audio_bytesperblock == 24)
192 priv->audio_codec = VIVO_AUDIO_G723;
195 /* only for displaying some informations about movie*/
196 if (!strcmp(opt, "Title"))
198 demux_info_add(demux, "name", param);
199 priv->title = strdup(param);
201 if (!strcmp(opt, "Author"))
203 demux_info_add(demux, "author", param);
204 priv->author = strdup(param);
206 if (!strcmp(opt, "Copyright"))
208 demux_info_add(demux, "copyright", param);
209 priv->copyright = strdup(param);
211 if (!strcmp(opt, "Producer"))
213 demux_info_add(demux, "encoder", param);
214 priv->producer = strdup(param);
217 /* get next token */
218 token = strtok(NULL, (char *)&("\x0d\x0a"));
221 if (buf)
222 free(buf);
223 if (opt)
224 free(opt);
225 if (param)
226 free(param);
229 static int vivo_check_file(demuxer_t* demuxer){
230 int i=0;
231 int len;
232 int c;
233 unsigned char buf[2048+256];
234 vivo_priv_t* priv;
235 int orig_pos = stream_tell(demuxer->stream);
237 mp_msg(MSGT_DEMUX,MSGL_V,"Checking for VIVO\n");
239 c=stream_read_char(demuxer->stream);
240 if(c==-256) return 0;
241 len=0;
242 while((c=stream_read_char(demuxer->stream))>=0x80){
243 len+=0x80*(c-0x80);
244 if(len>1024) return 0;
246 len+=c;
247 mp_msg(MSGT_DEMUX,MSGL_V,"header block 1 size: %d\n",len);
248 //stream_skip(demuxer->stream,len);
250 priv=malloc(sizeof(vivo_priv_t));
251 memset(priv,0,sizeof(vivo_priv_t));
252 demuxer->priv=priv;
254 #if 0
255 vivo_parse_text_header(demuxer, len);
256 if (priv->supported == 0)
257 return 0;
258 #else
259 /* this is enought for check (for now) */
260 stream_read(demuxer->stream,buf,len);
261 buf[len]=0;
262 // printf("VIVO header: '%s'\n",buf);
264 // parse header:
265 i=0;
266 while(i<len && buf[i]==0x0D && buf[i+1]==0x0A) i+=2; // skip empty lines
267 if(strncmp(buf+i,"Version:Vivo/",13)) return 0; // bad version/type!
268 #endif
270 #if 0
271 c=stream_read_char(demuxer->stream);
272 if(c) return 0;
273 len2=0;
274 while((c=stream_read_char(demuxer->stream))>=0x80){
275 len2+=0x80*(c-0x80);
276 if(len+len2>2048) return 0;
278 len2+=c;
279 mp_msg(MSGT_DEMUX,MSGL_V,"header block 2 size: %d\n",len2);
280 stream_skip(demuxer->stream,len2);
281 // stream_read(demuxer->stream,buf+len,len2);
282 #endif
284 // c=stream_read_char(demuxer->stream);
285 // printf("first packet: %02X\n",c);
287 stream_seek(demuxer->stream, orig_pos);
289 return DEMUXER_TYPE_VIVO;
292 static int audio_pos=0;
293 static int audio_rate=0;
295 // return value:
296 // 0 = EOF or no stream found
297 // 1 = successfully read a packet
298 static int demux_vivo_fill_buffer(demuxer_t *demux, demux_stream_t *dsds){
299 demux_stream_t *ds=NULL;
300 int c;
301 int len=0;
302 int seq;
303 int prefix=0;
304 demux->filepos=stream_tell(demux->stream);
306 c=stream_read_char(demux->stream);
307 if (c == -256) /* EOF */
308 return 0;
309 // printf("c=%x,%02X\n",c,c&0xf0);
310 if (c == 0x82)
312 /* ok, this works, but pts calculating from header is required! */
313 #warning "Calculate PTS from picture header!"
314 prefix = 1;
315 c = stream_read_char(demux->stream);
316 mp_msg(MSGT_DEMUX, MSGL_V, "packet 0x82(pos=%u) chunk=%x\n",
317 (int)stream_tell(demux->stream), c);
319 switch(c&0xF0){
320 case 0x00: // header - skip it!
322 len=stream_read_char(demux->stream);
323 if(len>=0x80) len=0x80*(len-0x80)+stream_read_char(demux->stream);
324 mp_msg(MSGT_DEMUX, MSGL_V, "vivo extra header: %d bytes\n",len);
325 #ifdef TEXTPARSE_ALL
327 int pos;
328 /* also try to parse all headers */
329 pos = stream_tell(demux->stream);
330 vivo_parse_text_header(demux, len);
331 stream_seek(demux->stream, pos);
333 #endif
334 break;
336 case 0x10: // video packet
337 if (prefix == 1)
338 len = stream_read_char(demux->stream);
339 else
340 len=128;
341 ds=demux->video;
342 break;
343 case 0x20: // video packet
344 len=stream_read_char(demux->stream);
345 ds=demux->video;
346 break;
347 case 0x30: // audio packet
348 if (prefix == 1)
349 len = stream_read_char(demux->stream);
350 else
351 len=40; /* 40kbps */
352 ds=demux->audio;
353 audio_pos+=len;
354 break;
355 case 0x40: // audio packet
356 if (prefix == 1)
357 len = stream_read_char(demux->stream);
358 else
359 len=24; /* 24kbps */
360 ds=demux->audio;
361 audio_pos+=len;
362 break;
363 default:
364 mp_msg(MSGT_DEMUX,MSGL_WARN,"VIVO - unknown ID found: %02X at pos %"PRIu64" contact author!\n",
365 c, (int64_t)stream_tell(demux->stream));
366 return 0;
369 // printf("chunk=%x, len=%d\n", c, len);
371 if(!ds || ds->id<-1){
372 if(len) stream_skip(demux->stream,len);
373 return 1;
376 seq=c&0x0F;
378 if(ds->asf_packet){
379 if(ds->asf_seq!=seq){
380 // closed segment, finalize packet:
381 ds_add_packet(ds,ds->asf_packet);
382 ds->asf_packet=NULL;
383 // printf("packet!\n");
384 } else {
385 // append data to it!
386 demux_packet_t* dp=ds->asf_packet;
387 if(dp->len + len + FF_INPUT_BUFFER_PADDING_SIZE < 0)
388 return 0;
389 dp->buffer=realloc(dp->buffer,dp->len+len+FF_INPUT_BUFFER_PADDING_SIZE);
390 memset(dp->buffer+dp->len+len, 0, FF_INPUT_BUFFER_PADDING_SIZE);
391 //memcpy(dp->buffer+dp->len,data,len);
392 stream_read(demux->stream,dp->buffer+dp->len,len);
393 mp_dbg(MSGT_DEMUX,MSGL_DBG4,"data appended! %d+%d\n",dp->len,len);
394 dp->len+=len;
395 // we are ready now.
396 if((c&0xF0)==0x20) --ds->asf_seq; // hack!
397 return 1;
400 // create new packet:
401 { demux_packet_t* dp;
402 dp=new_demux_packet(len);
403 //memcpy(dp->buffer,data,len);
404 stream_read(demux->stream,dp->buffer,len);
405 dp->pts=audio_rate?((float)audio_pos/(float)audio_rate):0;
406 // dp->flags=keyframe;
407 // if(ds==demux->video) printf("ASF time: %8d dur: %5d \n",time,dur);
408 dp->pos=demux->filepos;
409 ds->asf_packet=dp;
410 ds->asf_seq=seq;
411 // we are ready now.
412 return 1;
417 static const short h263_format[8][2] = {
418 { 0, 0 },
419 { 128, 96 },
420 { 176, 144 },
421 { 352, 288 },
422 { 704, 576 },
423 { 1408, 1152 },
424 { 320, 240 } // ??????? or 240x180 (found in vivo2) ?
427 static unsigned char* buffer;
428 static int bufptr=0;
429 static int bitcnt=0;
430 static unsigned char buf=0;
431 static int format, width, height;
433 static unsigned int x_get_bits(int n){
434 unsigned int x=0;
435 while(n-->0){
436 if(!bitcnt){
437 // fill buff
438 buf=buffer[bufptr++];
439 bitcnt=8;
441 //x=(x<<1)|(buf&1);buf>>=1;
442 x=(x<<1)|(buf>>7);buf<<=1;
443 --bitcnt;
445 return x;
448 #define get_bits(xxx,n) x_get_bits(n)
449 #define get_bits1(xxx) x_get_bits(1)
450 #define skip_bits(xxx,n) x_get_bits(n)
451 #define skip_bits1(xxx) x_get_bits(1)
453 /* most is hardcoded. should extend to handle all h263 streams */
454 static int h263_decode_picture_header(unsigned char *b_ptr)
456 // int i;
458 // for(i=0;i<16;i++) printf(" %02X",b_ptr[i]); printf("\n");
460 buffer=b_ptr;
461 bufptr=bitcnt=buf=0;
463 /* picture header */
464 if (get_bits(&s->gb, 22) != 0x20){
465 mp_msg(MSGT_DEMUX, MSGL_FATAL, "bad picture header\n");
466 return -1;
468 skip_bits(&s->gb, 8); /* picture timestamp */
470 if (get_bits1(&s->gb) != 1){
471 mp_msg(MSGT_DEMUX, MSGL_FATAL, "bad marker\n");
472 return -1; /* marker */
474 if (get_bits1(&s->gb) != 0){
475 mp_msg(MSGT_DEMUX, MSGL_FATAL, "bad h263 id\n");
476 return -1; /* h263 id */
478 skip_bits1(&s->gb); /* split screen off */
479 skip_bits1(&s->gb); /* camera off */
480 skip_bits1(&s->gb); /* freeze picture release off */
482 format = get_bits(&s->gb, 3);
484 if (format != 7) {
485 mp_msg(MSGT_DEMUX, MSGL_V, "h263_plus = 0 format = %d\n", format);
486 /* H.263v1 */
487 width = h263_format[format][0];
488 height = h263_format[format][1];
489 mp_msg(MSGT_DEMUX, MSGL_V, "%d x %d\n", width, height);
490 // if (!width) return -1;
492 mp_msg(MSGT_DEMUX, MSGL_V, "pict_type=%d\n", get_bits1(&s->gb));
493 mp_msg(MSGT_DEMUX, MSGL_V, "unrestricted_mv=%d\n", get_bits1(&s->gb));
494 #if 1
495 mp_msg(MSGT_DEMUX, MSGL_V, "SAC: %d\n", get_bits1(&s->gb));
496 mp_msg(MSGT_DEMUX, MSGL_V, "advanced prediction mode: %d\n", get_bits1(&s->gb));
497 mp_msg(MSGT_DEMUX, MSGL_V, "PB frame: %d\n", get_bits1(&s->gb));
498 #else
499 if (get_bits1(&s->gb) != 0)
500 return -1; /* SAC: off */
501 if (get_bits1(&s->gb) != 0)
502 return -1; /* advanced prediction mode: off */
503 if (get_bits1(&s->gb) != 0)
504 return -1; /* not PB frame */
505 #endif
506 mp_msg(MSGT_DEMUX, MSGL_V, "qscale=%d\n", get_bits(&s->gb, 5));
507 skip_bits1(&s->gb); /* Continuous Presence Multipoint mode: off */
508 } else {
509 mp_msg(MSGT_DEMUX, MSGL_V, "h263_plus = 1\n");
510 /* H.263v2 */
511 if (get_bits(&s->gb, 3) != 1){
512 mp_msg(MSGT_DEMUX, MSGL_FATAL, "H.263v2 A error\n");
513 return -1;
515 if (get_bits(&s->gb, 3) != 6){ /* custom source format */
516 mp_msg(MSGT_DEMUX, MSGL_FATAL, "custom source format\n");
517 return -1;
519 skip_bits(&s->gb, 12);
520 skip_bits(&s->gb, 3);
521 mp_msg(MSGT_DEMUX, MSGL_V, "pict_type=%d\n", get_bits(&s->gb, 3) + 1);
522 // if (s->pict_type != I_TYPE &&
523 // s->pict_type != P_TYPE)
524 // return -1;
525 skip_bits(&s->gb, 7);
526 skip_bits(&s->gb, 4); /* aspect ratio */
527 width = (get_bits(&s->gb, 9) + 1) * 4;
528 skip_bits1(&s->gb);
529 height = get_bits(&s->gb, 9) * 4;
530 mp_msg(MSGT_DEMUX, MSGL_V, "%d x %d\n", width, height);
531 //if (height == 0)
532 // return -1;
533 mp_msg(MSGT_DEMUX, MSGL_V, "qscale=%d\n", get_bits(&s->gb, 5));
536 /* PEI */
537 while (get_bits1(&s->gb) != 0) {
538 skip_bits(&s->gb, 8);
540 // s->f_code = 1;
541 // s->width = width;
542 // s->height = height;
543 return 0;
548 static demuxer_t* demux_open_vivo(demuxer_t* demuxer){
549 vivo_priv_t* priv=demuxer->priv;
551 if(!ds_fill_buffer(demuxer->video)){
552 mp_msg(MSGT_DEMUX,MSGL_ERR,"VIVO: " MSGTR_MissingVideoStreamBug);
553 return NULL;
556 audio_pos=0;
558 h263_decode_picture_header(demuxer->video->buffer);
560 if (vivo_param_version != -1)
561 priv->version = '0' + vivo_param_version;
563 { sh_video_t* sh=new_sh_video(demuxer,0);
565 /* viv1, viv2 (for better codecs.conf) */
566 sh->format = mmioFOURCC('v', 'i', 'v', priv->version);
567 if(!sh->fps)
569 if (priv->fps)
570 sh->fps=priv->fps;
571 else
572 sh->fps=15.0f;
574 sh->frametime=1.0f/sh->fps;
576 /* XXX: FIXME: can't scale image. */
577 /* hotfix to disable: */
578 priv->disp_width = priv->width;
579 priv->disp_height = priv->height;
581 if (vivo_param_width != -1)
582 priv->disp_width = priv->width = vivo_param_width;
584 if (vivo_param_height != -1)
585 priv->disp_height = priv->height = vivo_param_height;
587 if (vivo_param_vformat != -1)
589 priv->disp_width = priv->width = h263_format[vivo_param_vformat][0];
590 priv->disp_height = priv->height = h263_format[vivo_param_vformat][1];
593 if (priv->disp_width)
594 sh->disp_w = priv->disp_width;
595 else
596 sh->disp_w = width;
597 if (priv->disp_height)
598 sh->disp_h = priv->disp_height;
599 else
600 sh->disp_h = height;
602 // emulate BITMAPINFOHEADER:
603 sh->bih=malloc(sizeof(BITMAPINFOHEADER));
604 memset(sh->bih,0,sizeof(BITMAPINFOHEADER));
605 sh->bih->biSize=40;
606 if (priv->width)
607 sh->bih->biWidth = priv->width;
608 else
609 sh->bih->biWidth = width;
610 if (priv->height)
611 sh->bih->biHeight = priv->height;
612 else
613 sh->bih->biHeight = height;
614 sh->bih->biPlanes=1;
615 sh->bih->biBitCount=24;
616 sh->bih->biCompression=sh->format;
617 sh->bih->biSizeImage=sh->bih->biWidth*sh->bih->biHeight*3;
619 /* insert as stream */
620 demuxer->video->sh=sh;
621 sh->ds=demuxer->video;
622 demuxer->video->id=0;
624 /* disable seeking */
625 demuxer->seekable = 0;
627 mp_msg(MSGT_DEMUX,MSGL_V,"VIVO Video stream %d size: display: %dx%d, codec: %ux%u\n",
628 demuxer->video->id, sh->disp_w, sh->disp_h, sh->bih->biWidth,
629 sh->bih->biHeight);
632 /* AUDIO init */
633 if (demuxer->audio->id >= -1){
634 if(!ds_fill_buffer(demuxer->audio)){
635 mp_msg(MSGT_DEMUX,MSGL_ERR,"VIVO: " MSGTR_MissingAudioStream);
636 } else
637 { sh_audio_t* sh=new_sh_audio(demuxer,1);
639 /* Select audio codec */
640 if (priv->audio_codec == 0)
642 if (priv->version == '2')
643 priv->audio_codec = VIVO_AUDIO_SIREN;
644 else
645 priv->audio_codec = VIVO_AUDIO_G723;
647 if (vivo_param_acodec != NULL)
649 if (!strcasecmp(vivo_param_acodec, "g723"))
650 priv->audio_codec = VIVO_AUDIO_G723;
651 if (!strcasecmp(vivo_param_acodec, "siren"))
652 priv->audio_codec = VIVO_AUDIO_SIREN;
655 if (priv->audio_codec == VIVO_AUDIO_G723)
656 sh->format = 0x111;
657 else if (priv->audio_codec == VIVO_AUDIO_SIREN)
658 sh->format = 0x112;
659 else
661 mp_msg(MSGT_DEMUX, MSGL_ERR, "VIVO: Not support audio codec (%d)\n",
662 priv->audio_codec);
663 free_sh_audio(demuxer, 1);
664 goto nosound;
667 // Emulate WAVEFORMATEX struct:
668 sh->wf=malloc(sizeof(WAVEFORMATEX));
669 memset(sh->wf,0,sizeof(WAVEFORMATEX));
670 sh->wf->wFormatTag=sh->format;
671 sh->wf->nChannels=1; /* 1 channels for both Siren and G.723 */
673 /* Set bits per sample */
674 if (priv->audio_codec == VIVO_AUDIO_SIREN)
675 sh->wf->wBitsPerSample = 16;
676 else
677 if (priv->audio_codec == VIVO_AUDIO_G723)
678 sh->wf->wBitsPerSample = 8;
680 /* Set sampling rate */
681 if (priv->audio_samplerate) /* got from header */
682 sh->wf->nSamplesPerSec = priv->audio_samplerate;
683 else
685 if (priv->audio_codec == VIVO_AUDIO_SIREN)
686 sh->wf->nSamplesPerSec = 16000;
687 if (priv->audio_codec == VIVO_AUDIO_G723)
688 sh->wf->nSamplesPerSec = 8000;
690 if (vivo_param_samplerate != -1)
691 sh->wf->nSamplesPerSec = vivo_param_samplerate;
693 /* Set audio bitrate */
694 if (priv->audio_bitrate) /* got from header */
695 sh->wf->nAvgBytesPerSec = priv->audio_bitrate;
696 else
698 if (priv->audio_codec == VIVO_AUDIO_SIREN)
699 sh->wf->nAvgBytesPerSec = 2000;
700 if (priv->audio_codec == VIVO_AUDIO_G723)
701 sh->wf->nAvgBytesPerSec = 800;
703 if (vivo_param_abitrate != -1)
704 sh->wf->nAvgBytesPerSec = vivo_param_abitrate;
705 audio_rate=sh->wf->nAvgBytesPerSec;
707 if (!priv->audio_bytesperblock)
709 if (priv->audio_codec == VIVO_AUDIO_SIREN)
710 sh->wf->nBlockAlign = 40;
711 if (priv->audio_codec == VIVO_AUDIO_G723)
712 sh->wf->nBlockAlign = 24;
714 else
715 sh->wf->nBlockAlign = priv->audio_bytesperblock;
716 if (vivo_param_bytesperblock != -1)
717 sh->wf->nBlockAlign = vivo_param_bytesperblock;
719 /*sound_ok:*/
720 /* insert as stream */
721 demuxer->audio->sh=sh;
722 sh->ds=demuxer->audio;
723 demuxer->audio->id=1;
724 nosound:
725 return demuxer;
728 return demuxer;
731 static void demux_close_vivo(demuxer_t *demuxer)
733 vivo_priv_t* priv=demuxer->priv;
735 if (priv) {
736 if (priv->title)
737 free(priv->title);
738 if (priv->author)
739 free(priv->author);
740 if (priv->copyright)
741 free(priv->copyright);
742 if (priv->producer)
743 free(priv->producer);
744 free(priv);
746 return;
750 const demuxer_desc_t demuxer_desc_vivo = {
751 "Vivo demuxer",
752 "vivo",
753 "VIVO",
754 "A'rpi, Alex Beregszasi",
756 DEMUXER_TYPE_VIVO,
757 0, // unsafe autodetect
758 vivo_check_file,
759 demux_vivo_fill_buffer,
760 demux_open_vivo,
761 demux_close_vivo,
762 NULL,
763 NULL