12 #include "img_format.h"
15 #include <libdv/dv_types.h>
17 #include "stream/stream.h"
18 #include "libmpdemux/demuxer.h"
19 #include "libmpdemux/stheader.h"
21 #include "ad_internal.h"
23 static ad_info_t info
=
25 "Raw DV Audio Decoder",
27 "Alexander Neundorf <neundorf@kde.org>",
28 "http://libdv.sf.net",
34 // defined in vd_libdv.c:
35 dv_decoder_t
* init_global_rawdv_decoder(void);
37 static int preinit(sh_audio_t
*sh_audio
)
39 sh_audio
->audio_out_minsize
=4*DV_AUDIO_MAX_SAMPLES
*2;
43 static int16_t *audioBuffers
[4]={NULL
,NULL
,NULL
,NULL
};
45 static int init(sh_audio_t
*sh
)
48 WAVEFORMATEX
*h
=sh
->wf
;
52 sh
->i_bps
=h
->nAvgBytesPerSec
;
53 sh
->channels
=h
->nChannels
;
54 sh
->samplerate
=h
->nSamplesPerSec
;
55 sh
->samplesize
=(h
->wBitsPerSample
+7)/8;
57 sh
->context
=init_global_rawdv_decoder();
60 audioBuffers
[i
] = malloc(2*DV_AUDIO_MAX_SAMPLES
);
65 static void uninit(sh_audio_t
*sh_audio
)
69 free(audioBuffers
[i
]);
72 static int control(sh_audio_t
*sh
,int cmd
,void* arg
, ...)
75 return CONTROL_UNKNOWN
;
78 static int decode_audio(sh_audio_t
*audio
, unsigned char *buf
, int minlen
, int maxlen
)
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?
86 dv_parse_header(decoder
, dv_audio_frame
);
88 if(xx
!=decoder
->frame_size
)
89 mp_msg(MSGT_GLOBAL
,MSGL_WARN
,MSGTR_MPCODECS_AudioFramesizeDiffers
,
90 xx
, decoder
->frame_size
);
92 if (dv_decode_full_audio(decoder
, dv_audio_frame
,(int16_t**) audioBuffers
))
94 /* Interleave the audio into a single buffer */
96 int16_t *bufP
=(int16_t*)buf
;
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);
101 // return (44100/30)*4;
103 for (i
=0; i
< decoder
->audio
->samples_this_frame
; i
++)
106 for (ch
=0; ch
< decoder
->audio
->num_channels
; ch
++)
107 bufP
[len
++] = audioBuffers
[ch
][i
];