14 #include "img_format.h"
17 #include <libdv/dv_types.h>
23 #include "ad_internal.h"
25 static ad_info_t info
=
27 "Raw DV Audio Decoder",
29 "Alexander Neundorf <neundorf@kde.org>",
30 "http://libdv.sf.net",
36 // defined in vd_libdv.c:
37 dv_decoder_t
* init_global_rawdv_decoder();
39 static int preinit(sh_audio_t
*sh_audio
)
41 sh_audio
->audio_out_minsize
=4*DV_AUDIO_MAX_SAMPLES
*2;
45 static int16_t *audioBuffers
[4]={NULL
,NULL
,NULL
,NULL
};
47 static int init(sh_audio_t
*sh
)
50 WAVEFORMATEX
*h
=sh
->wf
;
54 sh
->i_bps
=h
->nAvgBytesPerSec
;
55 sh
->channels
=h
->nChannels
;
56 sh
->samplerate
=h
->nSamplesPerSec
;
57 sh
->samplesize
=(h
->wBitsPerSample
+7)/8;
59 sh
->context
=init_global_rawdv_decoder();
62 audioBuffers
[i
] = malloc(2*DV_AUDIO_MAX_SAMPLES
);
67 static void uninit(sh_audio_t
*sh_audio
)
71 free(audioBuffers
[i
]);
74 static int control(sh_audio_t
*sh
,int cmd
,void* arg
, ...)
77 return CONTROL_UNKNOWN
;
80 static int decode_audio(sh_audio_t
*audio
, unsigned char *buf
, int minlen
, int maxlen
)
83 dv_decoder_t
* decoder
=audio
->context
; //global_rawdv_decoder;
84 unsigned char* dv_audio_frame
=NULL
;
85 int xx
=ds_get_packet(audio
->ds
,&dv_audio_frame
);
86 if(xx
<=0 || !dv_audio_frame
) return 0; // EOF?
88 dv_parse_header(decoder
, dv_audio_frame
);
90 if(xx
!=decoder
->frame_size
)
91 mp_msg(MSGT_GLOBAL
,MSGL_WARN
,MSGTR_MPCODECS_AudioFramesizeDiffers
,
92 xx
, decoder
->frame_size
);
94 if (dv_decode_full_audio(decoder
, dv_audio_frame
,(int16_t**) audioBuffers
))
96 /* Interleave the audio into a single buffer */
98 int16_t *bufP
=(int16_t*)buf
;
100 // printf("samples=%d/%d chans=%d mem=%d \n",decoder->audio->samples_this_frame,DV_AUDIO_MAX_SAMPLES,
101 // decoder->audio->num_channels, decoder->audio->samples_this_frame*decoder->audio->num_channels*2);
103 // return (44100/30)*4;
105 for (i
=0; i
< decoder
->audio
->samples_this_frame
; i
++)
108 for (ch
=0; ch
< decoder
->audio
->num_channels
; ch
++)
109 bufP
[len
++] = audioBuffers
[ch
][i
];