Mercurial > mplayer.hg
annotate loader/dshow/DS_AudioDecoder.c @ 9001:01a9cf43074c
An AltiVec-enhanced IMDCT for liba52 (liba52/imdct.c)
It's nearly bit-perfect, I have a couple of lsb
changed in a 128 frames sample. I can't hear the
differences :-)
patch by Romain Dolbeau <dolbeau@irisa.fr>
author | arpi |
---|---|
date | Sat, 18 Jan 2003 19:28:29 +0000 |
parents | fb88ccbc5ccc |
children | f47d484d8f28 |
rev | line source |
---|---|
1545 | 1 /******************************************************** |
2 | |
3 DirectShow audio decoder | |
4 Copyright 2001 Eugene Kuznetsov (divx@euro.ru) | |
5 | |
6 *********************************************************/ | |
7 | |
3946 | 8 #ifndef NOAVIFILE_HEADERS |
9 #include "audiodecoder.h" | |
10 #include "except.h" | |
11 #else | |
12 #include "libwin32.h" | |
13 #endif | |
14 | |
15 #include "DS_Filter.h" | |
16 | |
17 struct _DS_AudioDecoder | |
18 { | |
19 WAVEFORMATEX in_fmt; | |
20 AM_MEDIA_TYPE m_sOurType, m_sDestType; | |
21 DS_Filter* m_pDS_Filter; | |
22 char* m_sVhdr; | |
23 char* m_sVhdr2; | |
24 }; | |
25 | |
2069 | 26 #include "DS_AudioDecoder.h" |
8451 | 27 #include "../ldt_keeper.h" |
3946 | 28 |
2069 | 29 #include <string.h> |
30 #include <stdio.h> | |
3059 | 31 #include <stdlib.h> |
2069 | 32 |
1545 | 33 #define __MODULE__ "DirectShow audio decoder" |
34 | |
35 typedef long STDCALL (*GETCLASS) (GUID*, GUID*, void**); | |
36 | |
3444 | 37 DS_AudioDecoder * DS_AudioDecoder_Open(char* dllname, GUID* guid, WAVEFORMATEX* wf) |
38 //DS_AudioDecoder * DS_AudioDecoder_Create(const CodecInfo * info, const WAVEFORMATEX* wf) | |
1545 | 39 { |
3059 | 40 DS_AudioDecoder *this; |
41 int sz; | |
42 WAVEFORMATEX* pWF; | |
3444 | 43 |
44 Setup_LDT_Keeper(); | |
45 Setup_FS_Segment(); | |
3059 | 46 |
47 this = malloc(sizeof(DS_AudioDecoder)); | |
48 | |
49 sz = 18 + wf->cbSize; | |
50 this->m_sVhdr = malloc(sz); | |
51 memcpy(this->m_sVhdr, wf, sz); | |
3915 | 52 this->m_sVhdr2 = malloc(18); |
53 memcpy(this->m_sVhdr2, this->m_sVhdr, 18); | |
3059 | 54 |
55 pWF = (WAVEFORMATEX*)this->m_sVhdr2; | |
56 pWF->wFormatTag = 1; | |
57 pWF->wBitsPerSample = 16; | |
3915 | 58 pWF->nBlockAlign = pWF->nChannels * (pWF->wBitsPerSample + 7) / 8; |
3059 | 59 pWF->cbSize = 0; |
3915 | 60 pWF->nAvgBytesPerSec = pWF->nBlockAlign * pWF->nSamplesPerSec; |
3059 | 61 |
62 memcpy(&this->in_fmt,wf,sizeof(WAVEFORMATEX)); | |
1545 | 63 |
3059 | 64 memset(&this->m_sOurType, 0, sizeof(this->m_sOurType)); |
65 this->m_sOurType.majortype=MEDIATYPE_Audio; | |
66 this->m_sOurType.subtype=MEDIASUBTYPE_PCM; | |
67 this->m_sOurType.subtype.f1=wf->wFormatTag; | |
68 this->m_sOurType.formattype=FORMAT_WaveFormatEx; | |
69 this->m_sOurType.lSampleSize=wf->nBlockAlign; | |
70 this->m_sOurType.bFixedSizeSamples=1; | |
71 this->m_sOurType.bTemporalCompression=0; | |
72 this->m_sOurType.pUnk=0; | |
73 this->m_sOurType.cbFormat=sz; | |
74 this->m_sOurType.pbFormat=this->m_sVhdr; | |
1545 | 75 |
3059 | 76 memset(&this->m_sDestType, 0, sizeof(this->m_sDestType)); |
77 this->m_sDestType.majortype=MEDIATYPE_Audio; | |
78 this->m_sDestType.subtype=MEDIASUBTYPE_PCM; | |
3915 | 79 // this->m_sDestType.subtype.f1=pWF->wFormatTag; |
3059 | 80 this->m_sDestType.formattype=FORMAT_WaveFormatEx; |
81 this->m_sDestType.bFixedSizeSamples=1; | |
82 this->m_sDestType.bTemporalCompression=0; | |
3915 | 83 this->m_sDestType.lSampleSize=pWF->nBlockAlign; |
3466 | 84 if (wf->wFormatTag == 0x130) |
85 // ACEL hack to prevent memory corruption | |
86 // obviosly we are missing something here | |
87 this->m_sDestType.lSampleSize *= 288; | |
3059 | 88 this->m_sDestType.pUnk=0; |
3915 | 89 this->m_sDestType.cbFormat=18; //pWF->cbSize; |
3059 | 90 this->m_sDestType.pbFormat=this->m_sVhdr2; |
1545 | 91 |
6139
3898967fcc96
some more output cosmetics, especially for vivo and mov demuxers
arpi
parents:
3946
diff
changeset
|
92 //print_wave_header(this->m_sVhdr); |
3898967fcc96
some more output cosmetics, especially for vivo and mov demuxers
arpi
parents:
3946
diff
changeset
|
93 //print_wave_header(this->m_sVhdr2); |
3915 | 94 |
3059 | 95 /*try*/ |
1545 | 96 { |
3059 | 97 ALLOCATOR_PROPERTIES props, props1; |
3444 | 98 this->m_pDS_Filter = DS_FilterCreate(dllname, guid, &this->m_sOurType, &this->m_sDestType); |
3059 | 99 if( !this->m_pDS_Filter ) { |
100 free(this); | |
101 return NULL; | |
102 } | |
103 | |
3063 | 104 this->m_pDS_Filter->Start(this->m_pDS_Filter); |
1545 | 105 |
106 props.cBuffers=1; | |
3059 | 107 props.cbBuffer=this->m_sOurType.lSampleSize; |
1545 | 108 props.cbAlign=props.cbPrefix=0; |
3059 | 109 this->m_pDS_Filter->m_pAll->vt->SetProperties(this->m_pDS_Filter->m_pAll, &props, &props1); |
110 this->m_pDS_Filter->m_pAll->vt->Commit(this->m_pDS_Filter->m_pAll); | |
1545 | 111 } |
3059 | 112 /* |
113 catch (FatalError& e) | |
1545 | 114 { |
115 e.PrintAll(); | |
116 delete[] m_sVhdr; | |
117 delete[] m_sVhdr2; | |
118 delete m_pDS_Filter; | |
119 throw; | |
120 } | |
3059 | 121 */ |
122 return this; | |
1545 | 123 } |
124 | |
3059 | 125 void DS_AudioDecoder_Destroy(DS_AudioDecoder *this) |
1545 | 126 { |
3059 | 127 free(this->m_sVhdr); |
128 free(this->m_sVhdr2); | |
129 DS_Filter_Destroy(this->m_pDS_Filter); | |
130 free(this); | |
1545 | 131 } |
132 | |
3946 | 133 int DS_AudioDecoder_Convert(DS_AudioDecoder *this, const void* in_data, unsigned int in_size, |
134 void* out_data, unsigned int out_size, | |
135 unsigned int* size_read, unsigned int* size_written) | |
1545 | 136 { |
3946 | 137 unsigned int written = 0; |
138 unsigned int read = 0; | |
3059 | 139 |
1545 | 140 if (!in_data || !out_data) |
141 return -1; | |
142 | |
3444 | 143 Setup_FS_Segment(); |
144 | |
3059 | 145 in_size -= in_size%this->in_fmt.nBlockAlign; |
1545 | 146 while (in_size>0) |
147 { | |
3946 | 148 unsigned int frame_size = 0; |
1545 | 149 char* frame_pointer; |
150 IMediaSample* sample=0; | |
3059 | 151 char* ptr; |
152 int result; | |
153 | |
154 // this->m_pOurOutput->SetFramePointer(out_data+written); | |
3063 | 155 this->m_pDS_Filter->m_pOurOutput->SetFramePointer(this->m_pDS_Filter->m_pOurOutput,&frame_pointer); |
156 this->m_pDS_Filter->m_pOurOutput->SetFrameSizePointer(this->m_pDS_Filter->m_pOurOutput,(long*)&frame_size); | |
3059 | 157 this->m_pDS_Filter->m_pAll->vt->GetBuffer(this->m_pDS_Filter->m_pAll, &sample, 0, 0, 0); |
158 if (!sample) | |
1545 | 159 { |
2069 | 160 Debug printf("DS_AudioDecoder::Convert() Error: null sample\n"); |
1545 | 161 break; |
162 } | |
3466 | 163 sample->vt->SetActualDataLength(sample, this->in_fmt.nBlockAlign); |
1545 | 164 sample->vt->GetPointer(sample, (BYTE **)&ptr); |
3059 | 165 memcpy(ptr, (const uint8_t*)in_data + read, this->in_fmt.nBlockAlign); |
166 sample->vt->SetSyncPoint(sample, 1); | |
1545 | 167 sample->vt->SetPreroll(sample, 0); |
3059 | 168 result = this->m_pDS_Filter->m_pImp->vt->Receive(this->m_pDS_Filter->m_pImp, sample); |
1545 | 169 if (result) |
170 Debug printf("DS_AudioDecoder::Convert() Error: putting data into input pin %x\n", result); | |
171 if ((written + frame_size) > out_size) | |
172 { | |
173 sample->vt->Release((IUnknown*)sample); | |
174 break; | |
175 } | |
176 memcpy((uint8_t*)out_data + written, frame_pointer, frame_size); | |
177 sample->vt->Release((IUnknown*)sample); | |
3059 | 178 read+=this->in_fmt.nBlockAlign; |
1545 | 179 written+=frame_size; |
3466 | 180 break; |
1545 | 181 } |
182 if (size_read) | |
183 *size_read = read; | |
184 if (size_written) | |
185 *size_written = written; | |
186 return 0; | |
187 } | |
188 | |
3059 | 189 int DS_AudioDecoder_GetSrcSize(DS_AudioDecoder *this, int dest_size) |
1545 | 190 { |
3059 | 191 double efficiency =(double) this->in_fmt.nAvgBytesPerSec |
192 / (this->in_fmt.nSamplesPerSec*this->in_fmt.nBlockAlign); | |
193 int frames = (int)(dest_size*efficiency);; | |
194 | |
1545 | 195 if (frames < 1) |
196 frames = 1; | |
3059 | 197 return frames * this->in_fmt.nBlockAlign; |
1545 | 198 } |