Mercurial > mplayer.hg
comparison libmpcodecs/ad_libdv.c @ 6927:0145bba6e201
native DV audio/video decoders using libdv
based on patch by Alexander Neundorf <neundorf@kde.org>
author | arpi |
---|---|
date | Mon, 05 Aug 2002 17:23:22 +0000 |
parents | |
children | 28677d779205 |
comparison
equal
deleted
inserted
replaced
6926:9f325578fac9 | 6927:0145bba6e201 |
---|---|
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 AFM_LIBDV, | |
28 "Alexander Neundorf <neundorf@kde.org>", | |
29 "http://libdv.sf.net", | |
30 "" | |
31 }; | |
32 | |
33 LIBAD_EXTERN(libdv) | |
34 | |
35 // defined in vd_libdv.c: | |
36 dv_decoder_t* init_global_rawdv_decoder(); | |
37 | |
38 static int preinit(sh_audio_t *sh_audio) | |
39 { | |
40 sh_audio->audio_out_minsize=4*DV_AUDIO_MAX_SAMPLES*2; | |
41 return 1; | |
42 } | |
43 | |
44 static int16_t *audioBuffers[4]={NULL,NULL,NULL,NULL}; | |
45 | |
46 static int init(sh_audio_t *sh) | |
47 { | |
48 int i; | |
49 WAVEFORMATEX *h=sh->wf; | |
50 | |
51 if(!h) return 0; | |
52 | |
53 sh->i_bps=h->nAvgBytesPerSec; | |
54 sh->channels=h->nChannels; | |
55 sh->samplerate=h->nSamplesPerSec; | |
56 sh->samplesize=(h->wBitsPerSample+7)/8; | |
57 | |
58 sh->context=init_global_rawdv_decoder(); | |
59 | |
60 for (i=0; i < 4; i++) | |
61 audioBuffers[i] = malloc(2*DV_AUDIO_MAX_SAMPLES); | |
62 | |
63 return 1; | |
64 } | |
65 | |
66 static void uninit(sh_audio_t *sh_audio) | |
67 { | |
68 int i; | |
69 for (i=0; i < 4; i++) | |
70 free(audioBuffers[i]); | |
71 } | |
72 | |
73 static int control(sh_audio_t *sh,int cmd,void* arg, ...) | |
74 { | |
75 // TODO!!! | |
76 return CONTROL_UNKNOWN; | |
77 } | |
78 | |
79 static int decode_audio(sh_audio_t *audio, unsigned char *buf, int minlen, int maxlen) | |
80 { | |
81 int len=0; | |
82 dv_decoder_t* decoder=audio->context; //global_rawdv_decoder; | |
83 unsigned char* dv_audio_frame=NULL; | |
84 int xx=ds_get_packet(audio->ds,&dv_audio_frame); | |
85 if(xx<=0 || !dv_audio_frame) return 0; // EOF? | |
86 | |
87 dv_parse_header(decoder, dv_audio_frame); | |
88 | |
89 if(xx!=decoder->frame_size) | |
90 printf("warning! audio framesize differs! read=%d hdr=%d \n", | |
91 xx, decoder->frame_size); | |
92 | |
93 if (dv_decode_full_audio(decoder, dv_audio_frame,(int16_t**) audioBuffers)) | |
94 { | |
95 /* Interleave the audio into a single buffer */ | |
96 int i=0; | |
97 int16_t *bufP=(int16_t*)buf; | |
98 | |
99 // printf("samples=%d/%d chans=%d mem=%d \n",decoder->audio->samples_this_frame,DV_AUDIO_MAX_SAMPLES, | |
100 // decoder->audio->num_channels, decoder->audio->samples_this_frame*decoder->audio->num_channels*2); | |
101 | |
102 // return (44100/30)*4; | |
103 | |
104 for (i=0; i < decoder->audio->samples_this_frame; i++) | |
105 { | |
106 int ch; | |
107 for (ch=0; ch < decoder->audio->num_channels; ch++) | |
108 bufP[len++] = audioBuffers[ch][i]; | |
109 } | |
110 } | |
111 return len*2; | |
112 } | |
113 | |
114 #endif | |
115 |