typo fix
[mplayer/greg.git] / libmpdemux / demux_viv.c
blob7c14a989bf77e2c0c6e4a7ed29dfc444590958ce
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_SO
18 #include <ffmpeg/avcodec.h>
19 #elif defined(USE_LIBAVCODEC)
20 #include "libavcodec/avcodec.h"
21 #else
22 #define FF_INPUT_BUFFER_PADDING_SIZE 8
23 #endif
25 /* parameters ! */
26 int vivo_param_version = -1;
27 char *vivo_param_acodec = NULL;
28 int vivo_param_abitrate = -1;
29 int vivo_param_samplerate = -1;
30 int vivo_param_bytesperblock = -1;
31 int vivo_param_width = -1;
32 int vivo_param_height = -1;
33 int vivo_param_vformat = -1;
35 /* VIVO audio standards from vivog723.acm:
37 G.723:
38 FormatTag = 0x111
39 Channels = 1 - mono
40 SamplesPerSec = 8000 - 8khz
41 AvgBytesPerSec = 800
42 BlockAlign (bytes per block) = 24
43 BitsPerSample = 8
45 Siren:
46 FormatTag = 0x112
47 Channels = 1 - mono
48 SamplesPerSec = 16000 - 16khz
49 AvgBytesPerSec = 2000
50 BlockAlign (bytes per block) = 40
51 BitsPerSample = 8
54 //enum { VIVO_AUDIO_G723, VIVO_AUDIO_SIREN };
56 #define VIVO_AUDIO_G723 1
57 #define VIVO_AUDIO_SIREN 2
59 typedef struct {
60 /* generic */
61 char version;
62 int supported;
63 /* info */
64 char *title;
65 char *author;
66 char *copyright;
67 char *producer;
68 /* video */
69 float fps;
70 int width;
71 int height;
72 int disp_width;
73 int disp_height;
74 /* audio */
75 int audio_codec;
76 int audio_bitrate;
77 int audio_samplerate;
78 int audio_bytesperblock;
79 } vivo_priv_t;
81 /* parse all possible extra headers */
82 /* (audio headers are separate - mostly with recordtype=3 or 4) */
83 #define TEXTPARSE_ALL 1
85 static void vivo_parse_text_header(demuxer_t *demux, int header_len)
87 vivo_priv_t* priv = demux->priv;
88 char *buf;
89 int i;
90 char *token;
91 char *opt, *param;
92 int parser_in_audio_block = 0;
94 if (!demux->priv)
96 priv = malloc(sizeof(vivo_priv_t));
97 memset(priv, 0, sizeof(vivo_priv_t));
98 demux->priv = priv;
99 priv->supported = 0;
102 buf = malloc(header_len);
103 opt = malloc(header_len);
104 param = malloc(header_len);
105 stream_read(demux->stream, buf, header_len);
106 i=0;
107 while(i<header_len && buf[i]==0x0D && buf[i+1]==0x0A) i+=2; // skip empty lines
109 token = strtok(buf, (char *)&("\x0d\x0a"));
110 while (token && (header_len>2))
112 header_len -= strlen(token)+2;
113 if (sscanf(token, "%[^:]:%[^\n]", opt, param) != 2)
115 mp_msg(MSGT_DEMUX, MSGL_V, "viv_text_header_parser: bad line: '%s' at ~%#"PRIx64"\n",
116 token, (int64_t)stream_tell(demux->stream));
117 break;
119 mp_dbg(MSGT_DEMUX, MSGL_DBG3, "token: '%s' (%d bytes/%d bytes left)\n",
120 token, strlen(token), header_len);
121 mp_dbg(MSGT_DEMUX, MSGL_DBG3, "token => o: '%s', p: '%s'\n",
122 opt, param);
124 /* checking versions: only v1 or v2 is suitable (or known?:) */
125 if (!strcmp(opt, "Version"))
127 mp_msg(MSGT_DEMUX, MSGL_DBG2, "Version: %s\n", param);
128 if (!strncmp(param, "Vivo/1", 6) || !strncmp(param, "Vivo/2", 6))
130 priv->supported = 1;
131 /* save major version for fourcc */
132 priv->version = param[5];
136 /* video specific */
137 if (!strcmp(opt, "FPS"))
139 mp_msg(MSGT_DEMUX, MSGL_DBG2, "FPS: %f\n", atof(param));
140 priv->fps = atof(param);
142 if (!strcmp(opt, "Width"))
144 mp_msg(MSGT_DEMUX, MSGL_DBG2, "Width: %d\n", atoi(param));
145 priv->width = atoi(param);
147 if (!strcmp(opt, "Height"))
149 mp_msg(MSGT_DEMUX, MSGL_DBG2, "Height: %d\n", atoi(param));
150 priv->height = atoi(param);
152 if (!strcmp(opt, "DisplayWidth"))
154 mp_msg(MSGT_DEMUX, MSGL_DBG2, "Display Width: %d\n", atoi(param));
155 priv->disp_width = atoi(param);
157 if (!strcmp(opt, "DisplayHeight"))
159 mp_msg(MSGT_DEMUX, MSGL_DBG2, "Display Height: %d\n", atoi(param));
160 priv->disp_height = atoi(param);
163 /* audio specific */
164 if (!strcmp(opt, "RecordType"))
166 /* no audio recordblock by Vivo/1.00, 3 and 4 by Vivo/2.00 */
167 if ((atoi(param) == 3) || (atoi(param) == 4))
168 parser_in_audio_block = 1;
169 else
170 parser_in_audio_block = 0;
172 if (!strcmp(opt, "NominalBitrate"))
174 priv->audio_bitrate = atoi(param);
175 if (priv->audio_bitrate == 2000)
176 priv->audio_codec = VIVO_AUDIO_SIREN;
177 if (priv->audio_bitrate == 800)
178 priv->audio_codec = VIVO_AUDIO_G723;
180 if (!strcmp(opt, "SamplingFrequency"))
182 priv->audio_samplerate = atoi(param);
183 if (priv->audio_samplerate == 16000)
184 priv->audio_codec = VIVO_AUDIO_SIREN;
185 if (priv->audio_samplerate == 8000)
186 priv->audio_codec = VIVO_AUDIO_G723;
188 if (!strcmp(opt, "Length") && (parser_in_audio_block == 1))
190 priv->audio_bytesperblock = atoi(param); /* 24 or 40 kbps */
191 if (priv->audio_bytesperblock == 40)
192 priv->audio_codec = VIVO_AUDIO_SIREN;
193 if (priv->audio_bytesperblock == 24)
194 priv->audio_codec = VIVO_AUDIO_G723;
197 /* only for displaying some informations about movie*/
198 if (!strcmp(opt, "Title"))
200 demux_info_add(demux, "name", param);
201 priv->title = strdup(param);
203 if (!strcmp(opt, "Author"))
205 demux_info_add(demux, "author", param);
206 priv->author = strdup(param);
208 if (!strcmp(opt, "Copyright"))
210 demux_info_add(demux, "copyright", param);
211 priv->copyright = strdup(param);
213 if (!strcmp(opt, "Producer"))
215 demux_info_add(demux, "encoder", param);
216 priv->producer = strdup(param);
219 /* get next token */
220 token = strtok(NULL, (char *)&("\x0d\x0a"));
223 if (buf)
224 free(buf);
225 if (opt)
226 free(opt);
227 if (param)
228 free(param);
231 static int vivo_check_file(demuxer_t* demuxer){
232 int i=0;
233 int len;
234 int c;
235 unsigned char buf[2048+256];
236 vivo_priv_t* priv;
237 int orig_pos = stream_tell(demuxer->stream);
239 mp_msg(MSGT_DEMUX,MSGL_V,"Checking for VIVO\n");
241 c=stream_read_char(demuxer->stream);
242 if(c==-256) return 0;
243 len=0;
244 while((c=stream_read_char(demuxer->stream))>=0x80){
245 len+=0x80*(c-0x80);
246 if(len>1024) return 0;
248 len+=c;
249 mp_msg(MSGT_DEMUX,MSGL_V,"header block 1 size: %d\n",len);
250 //stream_skip(demuxer->stream,len);
252 priv=malloc(sizeof(vivo_priv_t));
253 memset(priv,0,sizeof(vivo_priv_t));
254 demuxer->priv=priv;
256 #if 0
257 vivo_parse_text_header(demuxer, len);
258 if (priv->supported == 0)
259 return 0;
260 #else
261 /* this is enought for check (for now) */
262 stream_read(demuxer->stream,buf,len);
263 buf[len]=0;
264 // printf("VIVO header: '%s'\n",buf);
266 // parse header:
267 i=0;
268 while(i<len && buf[i]==0x0D && buf[i+1]==0x0A) i+=2; // skip empty lines
269 if(strncmp(buf+i,"Version:Vivo/",13)) return 0; // bad version/type!
270 #endif
272 #if 0
273 c=stream_read_char(demuxer->stream);
274 if(c) return 0;
275 len2=0;
276 while((c=stream_read_char(demuxer->stream))>=0x80){
277 len2+=0x80*(c-0x80);
278 if(len+len2>2048) return 0;
280 len2+=c;
281 mp_msg(MSGT_DEMUX,MSGL_V,"header block 2 size: %d\n",len2);
282 stream_skip(demuxer->stream,len2);
283 // stream_read(demuxer->stream,buf+len,len2);
284 #endif
286 // c=stream_read_char(demuxer->stream);
287 // printf("first packet: %02X\n",c);
289 stream_seek(demuxer->stream, orig_pos);
291 return DEMUXER_TYPE_VIVO;
294 static int audio_pos=0;
295 static int audio_rate=0;
297 // return value:
298 // 0 = EOF or no stream found
299 // 1 = successfully read a packet
300 static int demux_vivo_fill_buffer(demuxer_t *demux, demux_stream_t *dsds){
301 demux_stream_t *ds=NULL;
302 int c;
303 int len=0;
304 int seq;
305 int prefix=0;
306 demux->filepos=stream_tell(demux->stream);
308 c=stream_read_char(demux->stream);
309 if (c == -256) /* EOF */
310 return 0;
311 // printf("c=%x,%02X\n",c,c&0xf0);
312 if (c == 0x82)
314 /* ok, this works, but pts calculating from header is required! */
315 #warning "Calculate PTS from picture header!"
316 prefix = 1;
317 c = stream_read_char(demux->stream);
318 mp_msg(MSGT_DEMUX, MSGL_V, "packet 0x82(pos=%u) chunk=%x\n",
319 (int)stream_tell(demux->stream), c);
321 switch(c&0xF0){
322 case 0x00: // header - skip it!
324 len=stream_read_char(demux->stream);
325 if(len>=0x80) len=0x80*(len-0x80)+stream_read_char(demux->stream);
326 mp_msg(MSGT_DEMUX, MSGL_V, "vivo extra header: %d bytes\n",len);
327 #ifdef TEXTPARSE_ALL
329 int pos;
330 /* also try to parse all headers */
331 pos = stream_tell(demux->stream);
332 vivo_parse_text_header(demux, len);
333 stream_seek(demux->stream, pos);
335 #endif
336 break;
338 case 0x10: // video packet
339 if (prefix == 1)
340 len = stream_read_char(demux->stream);
341 else
342 len=128;
343 ds=demux->video;
344 break;
345 case 0x20: // video packet
346 len=stream_read_char(demux->stream);
347 ds=demux->video;
348 break;
349 case 0x30: // audio packet
350 if (prefix == 1)
351 len = stream_read_char(demux->stream);
352 else
353 len=40; /* 40kbps */
354 ds=demux->audio;
355 audio_pos+=len;
356 break;
357 case 0x40: // audio packet
358 if (prefix == 1)
359 len = stream_read_char(demux->stream);
360 else
361 len=24; /* 24kbps */
362 ds=demux->audio;
363 audio_pos+=len;
364 break;
365 default:
366 mp_msg(MSGT_DEMUX,MSGL_WARN,"VIVO - unknown ID found: %02X at pos %"PRIu64" contact author!\n",
367 c, (int64_t)stream_tell(demux->stream));
368 return 0;
371 // printf("chunk=%x, len=%d\n", c, len);
373 if(!ds || ds->id<-1){
374 if(len) stream_skip(demux->stream,len);
375 return 1;
378 seq=c&0x0F;
380 if(ds->asf_packet){
381 if(ds->asf_seq!=seq){
382 // closed segment, finalize packet:
383 ds_add_packet(ds,ds->asf_packet);
384 ds->asf_packet=NULL;
385 // printf("packet!\n");
386 } else {
387 // append data to it!
388 demux_packet_t* dp=ds->asf_packet;
389 if(dp->len + len + FF_INPUT_BUFFER_PADDING_SIZE < 0)
390 return 0;
391 dp->buffer=realloc(dp->buffer,dp->len+len+FF_INPUT_BUFFER_PADDING_SIZE);
392 memset(dp->buffer+dp->len+len, 0, FF_INPUT_BUFFER_PADDING_SIZE);
393 //memcpy(dp->buffer+dp->len,data,len);
394 stream_read(demux->stream,dp->buffer+dp->len,len);
395 mp_dbg(MSGT_DEMUX,MSGL_DBG4,"data appended! %d+%d\n",dp->len,len);
396 dp->len+=len;
397 // we are ready now.
398 if((c&0xF0)==0x20) --ds->asf_seq; // hack!
399 return 1;
402 // create new packet:
403 { demux_packet_t* dp;
404 dp=new_demux_packet(len);
405 //memcpy(dp->buffer,data,len);
406 stream_read(demux->stream,dp->buffer,len);
407 dp->pts=audio_rate?((float)audio_pos/(float)audio_rate):0;
408 // dp->flags=keyframe;
409 // if(ds==demux->video) printf("ASF time: %8d dur: %5d \n",time,dur);
410 dp->pos=demux->filepos;
411 ds->asf_packet=dp;
412 ds->asf_seq=seq;
413 // we are ready now.
414 return 1;
419 static const short h263_format[8][2] = {
420 { 0, 0 },
421 { 128, 96 },
422 { 176, 144 },
423 { 352, 288 },
424 { 704, 576 },
425 { 1408, 1152 },
426 { 320, 240 } // ??????? or 240x180 (found in vivo2) ?
429 static unsigned char* buffer;
430 static int bufptr=0;
431 static int bitcnt=0;
432 static unsigned char buf=0;
433 static int format, width, height;
435 static unsigned int x_get_bits(int n){
436 unsigned int x=0;
437 while(n-->0){
438 if(!bitcnt){
439 // fill buff
440 buf=buffer[bufptr++];
441 bitcnt=8;
443 //x=(x<<1)|(buf&1);buf>>=1;
444 x=(x<<1)|(buf>>7);buf<<=1;
445 --bitcnt;
447 return x;
450 #define get_bits(xxx,n) x_get_bits(n)
451 #define get_bits1(xxx) x_get_bits(1)
452 #define skip_bits(xxx,n) x_get_bits(n)
453 #define skip_bits1(xxx) x_get_bits(1)
455 /* most is hardcoded. should extend to handle all h263 streams */
456 static int h263_decode_picture_header(unsigned char *b_ptr)
458 // int i;
460 // for(i=0;i<16;i++) printf(" %02X",b_ptr[i]); printf("\n");
462 buffer=b_ptr;
463 bufptr=bitcnt=buf=0;
465 /* picture header */
466 if (get_bits(&s->gb, 22) != 0x20){
467 mp_msg(MSGT_DEMUX, MSGL_FATAL, "bad picture header\n");
468 return -1;
470 skip_bits(&s->gb, 8); /* picture timestamp */
472 if (get_bits1(&s->gb) != 1){
473 mp_msg(MSGT_DEMUX, MSGL_FATAL, "bad marker\n");
474 return -1; /* marker */
476 if (get_bits1(&s->gb) != 0){
477 mp_msg(MSGT_DEMUX, MSGL_FATAL, "bad h263 id\n");
478 return -1; /* h263 id */
480 skip_bits1(&s->gb); /* split screen off */
481 skip_bits1(&s->gb); /* camera off */
482 skip_bits1(&s->gb); /* freeze picture release off */
484 format = get_bits(&s->gb, 3);
486 if (format != 7) {
487 mp_msg(MSGT_DEMUX, MSGL_V, "h263_plus = 0 format = %d\n", format);
488 /* H.263v1 */
489 width = h263_format[format][0];
490 height = h263_format[format][1];
491 mp_msg(MSGT_DEMUX, MSGL_V, "%d x %d\n", width, height);
492 // if (!width) return -1;
494 mp_msg(MSGT_DEMUX, MSGL_V, "pict_type=%d\n", get_bits1(&s->gb));
495 mp_msg(MSGT_DEMUX, MSGL_V, "unrestricted_mv=%d\n", get_bits1(&s->gb));
496 #if 1
497 mp_msg(MSGT_DEMUX, MSGL_V, "SAC: %d\n", get_bits1(&s->gb));
498 mp_msg(MSGT_DEMUX, MSGL_V, "advanced prediction mode: %d\n", get_bits1(&s->gb));
499 mp_msg(MSGT_DEMUX, MSGL_V, "PB frame: %d\n", get_bits1(&s->gb));
500 #else
501 if (get_bits1(&s->gb) != 0)
502 return -1; /* SAC: off */
503 if (get_bits1(&s->gb) != 0)
504 return -1; /* advanced prediction mode: off */
505 if (get_bits1(&s->gb) != 0)
506 return -1; /* not PB frame */
507 #endif
508 mp_msg(MSGT_DEMUX, MSGL_V, "qscale=%d\n", get_bits(&s->gb, 5));
509 skip_bits1(&s->gb); /* Continuous Presence Multipoint mode: off */
510 } else {
511 mp_msg(MSGT_DEMUX, MSGL_V, "h263_plus = 1\n");
512 /* H.263v2 */
513 if (get_bits(&s->gb, 3) != 1){
514 mp_msg(MSGT_DEMUX, MSGL_FATAL, "H.263v2 A error\n");
515 return -1;
517 if (get_bits(&s->gb, 3) != 6){ /* custom source format */
518 mp_msg(MSGT_DEMUX, MSGL_FATAL, "custom source format\n");
519 return -1;
521 skip_bits(&s->gb, 12);
522 skip_bits(&s->gb, 3);
523 mp_msg(MSGT_DEMUX, MSGL_V, "pict_type=%d\n", get_bits(&s->gb, 3) + 1);
524 // if (s->pict_type != I_TYPE &&
525 // s->pict_type != P_TYPE)
526 // return -1;
527 skip_bits(&s->gb, 7);
528 skip_bits(&s->gb, 4); /* aspect ratio */
529 width = (get_bits(&s->gb, 9) + 1) * 4;
530 skip_bits1(&s->gb);
531 height = get_bits(&s->gb, 9) * 4;
532 mp_msg(MSGT_DEMUX, MSGL_V, "%d x %d\n", width, height);
533 //if (height == 0)
534 // return -1;
535 mp_msg(MSGT_DEMUX, MSGL_V, "qscale=%d\n", get_bits(&s->gb, 5));
538 /* PEI */
539 while (get_bits1(&s->gb) != 0) {
540 skip_bits(&s->gb, 8);
542 // s->f_code = 1;
543 // s->width = width;
544 // s->height = height;
545 return 0;
550 static demuxer_t* demux_open_vivo(demuxer_t* demuxer){
551 vivo_priv_t* priv=demuxer->priv;
553 if(!ds_fill_buffer(demuxer->video)){
554 mp_msg(MSGT_DEMUX,MSGL_ERR,"VIVO: " MSGTR_MissingVideoStreamBug);
555 return NULL;
558 audio_pos=0;
560 h263_decode_picture_header(demuxer->video->buffer);
562 if (vivo_param_version != -1)
563 priv->version = '0' + vivo_param_version;
565 { sh_video_t* sh=new_sh_video(demuxer,0);
567 /* viv1, viv2 (for better codecs.conf) */
568 sh->format = mmioFOURCC('v', 'i', 'v', priv->version);
569 if(!sh->fps)
571 if (priv->fps)
572 sh->fps=priv->fps;
573 else
574 sh->fps=15.0f;
576 sh->frametime=1.0f/sh->fps;
578 /* XXX: FIXME: can't scale image. */
579 /* hotfix to disable: */
580 priv->disp_width = priv->width;
581 priv->disp_height = priv->height;
583 if (vivo_param_width != -1)
584 priv->disp_width = priv->width = vivo_param_width;
586 if (vivo_param_height != -1)
587 priv->disp_height = priv->height = vivo_param_height;
589 if (vivo_param_vformat != -1)
591 priv->disp_width = priv->width = h263_format[vivo_param_vformat][0];
592 priv->disp_height = priv->height = h263_format[vivo_param_vformat][1];
595 if (priv->disp_width)
596 sh->disp_w = priv->disp_width;
597 else
598 sh->disp_w = width;
599 if (priv->disp_height)
600 sh->disp_h = priv->disp_height;
601 else
602 sh->disp_h = height;
604 // emulate BITMAPINFOHEADER:
605 sh->bih=malloc(sizeof(BITMAPINFOHEADER));
606 memset(sh->bih,0,sizeof(BITMAPINFOHEADER));
607 sh->bih->biSize=40;
608 if (priv->width)
609 sh->bih->biWidth = priv->width;
610 else
611 sh->bih->biWidth = width;
612 if (priv->height)
613 sh->bih->biHeight = priv->height;
614 else
615 sh->bih->biHeight = height;
616 sh->bih->biPlanes=1;
617 sh->bih->biBitCount=24;
618 sh->bih->biCompression=sh->format;
619 sh->bih->biSizeImage=sh->bih->biWidth*sh->bih->biHeight*3;
621 /* insert as stream */
622 demuxer->video->sh=sh;
623 sh->ds=demuxer->video;
624 demuxer->video->id=0;
626 /* disable seeking */
627 demuxer->seekable = 0;
629 mp_msg(MSGT_DEMUX,MSGL_V,"VIVO Video stream %d size: display: %dx%d, codec: %ux%u\n",
630 demuxer->video->id, sh->disp_w, sh->disp_h, sh->bih->biWidth,
631 sh->bih->biHeight);
634 /* AUDIO init */
635 if (demuxer->audio->id >= -1){
636 if(!ds_fill_buffer(demuxer->audio)){
637 mp_msg(MSGT_DEMUX,MSGL_ERR,"VIVO: " MSGTR_MissingAudioStream);
638 } else
639 { sh_audio_t* sh=new_sh_audio(demuxer,1);
641 /* Select audio codec */
642 if (priv->audio_codec == 0)
644 if (priv->version == '2')
645 priv->audio_codec = VIVO_AUDIO_SIREN;
646 else
647 priv->audio_codec = VIVO_AUDIO_G723;
649 if (vivo_param_acodec != NULL)
651 if (!strcasecmp(vivo_param_acodec, "g723"))
652 priv->audio_codec = VIVO_AUDIO_G723;
653 if (!strcasecmp(vivo_param_acodec, "siren"))
654 priv->audio_codec = VIVO_AUDIO_SIREN;
657 if (priv->audio_codec == VIVO_AUDIO_G723)
658 sh->format = 0x111;
659 else if (priv->audio_codec == VIVO_AUDIO_SIREN)
660 sh->format = 0x112;
661 else
663 mp_msg(MSGT_DEMUX, MSGL_ERR, "VIVO: Not support audio codec (%d)\n",
664 priv->audio_codec);
665 free_sh_audio(demuxer, 1);
666 goto nosound;
669 // Emulate WAVEFORMATEX struct:
670 sh->wf=malloc(sizeof(WAVEFORMATEX));
671 memset(sh->wf,0,sizeof(WAVEFORMATEX));
672 sh->wf->wFormatTag=sh->format;
673 sh->wf->nChannels=1; /* 1 channels for both Siren and G.723 */
675 /* Set bits per sample */
676 if (priv->audio_codec == VIVO_AUDIO_SIREN)
677 sh->wf->wBitsPerSample = 16;
678 else
679 if (priv->audio_codec == VIVO_AUDIO_G723)
680 sh->wf->wBitsPerSample = 8;
682 /* Set sampling rate */
683 if (priv->audio_samplerate) /* got from header */
684 sh->wf->nSamplesPerSec = priv->audio_samplerate;
685 else
687 if (priv->audio_codec == VIVO_AUDIO_SIREN)
688 sh->wf->nSamplesPerSec = 16000;
689 if (priv->audio_codec == VIVO_AUDIO_G723)
690 sh->wf->nSamplesPerSec = 8000;
692 if (vivo_param_samplerate != -1)
693 sh->wf->nSamplesPerSec = vivo_param_samplerate;
695 /* Set audio bitrate */
696 if (priv->audio_bitrate) /* got from header */
697 sh->wf->nAvgBytesPerSec = priv->audio_bitrate;
698 else
700 if (priv->audio_codec == VIVO_AUDIO_SIREN)
701 sh->wf->nAvgBytesPerSec = 2000;
702 if (priv->audio_codec == VIVO_AUDIO_G723)
703 sh->wf->nAvgBytesPerSec = 800;
705 if (vivo_param_abitrate != -1)
706 sh->wf->nAvgBytesPerSec = vivo_param_abitrate;
707 audio_rate=sh->wf->nAvgBytesPerSec;
709 if (!priv->audio_bytesperblock)
711 if (priv->audio_codec == VIVO_AUDIO_SIREN)
712 sh->wf->nBlockAlign = 40;
713 if (priv->audio_codec == VIVO_AUDIO_G723)
714 sh->wf->nBlockAlign = 24;
716 else
717 sh->wf->nBlockAlign = priv->audio_bytesperblock;
718 if (vivo_param_bytesperblock != -1)
719 sh->wf->nBlockAlign = vivo_param_bytesperblock;
721 /*sound_ok:*/
722 /* insert as stream */
723 demuxer->audio->sh=sh;
724 sh->ds=demuxer->audio;
725 demuxer->audio->id=1;
726 nosound:
727 return demuxer;
730 return demuxer;
733 static void demux_close_vivo(demuxer_t *demuxer)
735 vivo_priv_t* priv=demuxer->priv;
737 if (priv) {
738 if (priv->title)
739 free(priv->title);
740 if (priv->author)
741 free(priv->author);
742 if (priv->copyright)
743 free(priv->copyright);
744 if (priv->producer)
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