6927
|
1 #include <stdio.h>
|
|
2 #include <stdlib.h>
|
|
3 #include <string.h>
|
|
4 #include <sys/types.h>
|
|
5 #include <unistd.h>
|
|
6 #include <math.h>
|
|
7
|
|
8 #include "config.h"
|
|
9
|
|
10 #ifdef HAVE_LIBDV095
|
|
11
|
|
12 #include "img_format.h"
|
|
13
|
|
14 #include <libdv/dv.h>
|
|
15 #include <libdv/dv_types.h>
|
|
16
|
|
17 #include "stream.h"
|
|
18 #include "demuxer.h"
|
|
19 #include "stheader.h"
|
|
20
|
|
21 #include "ad_internal.h"
|
|
22
|
|
23 static ad_info_t info =
|
|
24 {
|
|
25 "Raw DV Audio Decoder",
|
|
26 "libdv",
|
|
27 "Alexander Neundorf <neundorf@kde.org>",
|
|
28 "http://libdv.sf.net",
|
|
29 ""
|
|
30 };
|
|
31
|
|
32 LIBAD_EXTERN(libdv)
|
|
33
|
|
34 // defined in vd_libdv.c:
|
|
35 dv_decoder_t* init_global_rawdv_decoder();
|
|
36
|
|
37 static int preinit(sh_audio_t *sh_audio)
|
|
38 {
|
|
39 sh_audio->audio_out_minsize=4*DV_AUDIO_MAX_SAMPLES*2;
|
|
40 return 1;
|
|
41 }
|
|
42
|
|
43 static int16_t *audioBuffers[4]={NULL,NULL,NULL,NULL};
|
|
44
|
|
45 static int init(sh_audio_t *sh)
|
|
46 {
|
|
47 int i;
|
|
48 WAVEFORMATEX *h=sh->wf;
|
|
49
|
|
50 if(!h) return 0;
|
|
51
|
|
52 sh->i_bps=h->nAvgBytesPerSec;
|
|
53 sh->channels=h->nChannels;
|
|
54 sh->samplerate=h->nSamplesPerSec;
|
|
55 sh->samplesize=(h->wBitsPerSample+7)/8;
|
|
56
|
|
57 sh->context=init_global_rawdv_decoder();
|
|
58
|
|
59 for (i=0; i < 4; i++)
|
|
60 audioBuffers[i] = malloc(2*DV_AUDIO_MAX_SAMPLES);
|
|
61
|
|
62 return 1;
|
|
63 }
|
|
64
|
|
65 static void uninit(sh_audio_t *sh_audio)
|
|
66 {
|
|
67 int i;
|
|
68 for (i=0; i < 4; i++)
|
|
69 free(audioBuffers[i]);
|
|
70 }
|
|
71
|
|
72 static int control(sh_audio_t *sh,int cmd,void* arg, ...)
|
|
73 {
|
|
74 // TODO!!!
|
|
75 return CONTROL_UNKNOWN;
|
|
76 }
|
|
77
|
|
78 static int decode_audio(sh_audio_t *audio, unsigned char *buf, int minlen, int maxlen)
|
|
79 {
|
|
80 int len=0;
|
|
81 dv_decoder_t* decoder=audio->context; //global_rawdv_decoder;
|
|
82 unsigned char* dv_audio_frame=NULL;
|
|
83 int xx=ds_get_packet(audio->ds,&dv_audio_frame);
|
|
84 if(xx<=0 || !dv_audio_frame) return 0; // EOF?
|
|
85
|
|
86 dv_parse_header(decoder, dv_audio_frame);
|
|
87
|
|
88 if(xx!=decoder->frame_size)
|
|
89 printf("warning! audio framesize differs! read=%d hdr=%d \n",
|
|
90 xx, decoder->frame_size);
|
|
91
|
|
92 if (dv_decode_full_audio(decoder, dv_audio_frame,(int16_t**) audioBuffers))
|
|
93 {
|
|
94 /* Interleave the audio into a single buffer */
|
|
95 int i=0;
|
|
96 int16_t *bufP=(int16_t*)buf;
|
|
97
|
|
98 // printf("samples=%d/%d chans=%d mem=%d \n",decoder->audio->samples_this_frame,DV_AUDIO_MAX_SAMPLES,
|
|
99 // decoder->audio->num_channels, decoder->audio->samples_this_frame*decoder->audio->num_channels*2);
|
|
100
|
|
101 // return (44100/30)*4;
|
|
102
|
|
103 for (i=0; i < decoder->audio->samples_this_frame; i++)
|
|
104 {
|
|
105 int ch;
|
|
106 for (ch=0; ch < decoder->audio->num_channels; ch++)
|
|
107 bufP[len++] = audioBuffers[ch][i];
|
|
108 }
|
|
109 }
|
|
110 return len*2;
|
|
111 }
|
|
112
|
|
113 #endif
|
|
114
|