Mercurial > mplayer.hg
annotate loader/dshow/DS_AudioDecoder.c @ 23164:e9298e9c6a74
accurate X200 memory size detection (patch by rjoco77 at kezdionline dot ro)
author | ben |
---|---|
date | Mon, 30 Apr 2007 11:46:02 +0000 |
parents | 49f01f8fbd60 |
children | 450bb2a75cba |
rev | line source |
---|---|
1545 | 1 /******************************************************** |
2 | |
3 DirectShow audio decoder | |
4 Copyright 2001 Eugene Kuznetsov (divx@euro.ru) | |
5 | |
6 *********************************************************/ | |
9967
b0d1b415320c
cygwin support patch by Sascha Sommer and some fixes by me
alex
parents:
9503
diff
changeset
|
7 #include "config.h" |
1545 | 8 |
3946 | 9 #ifndef NOAVIFILE_HEADERS |
10 #include "audiodecoder.h" | |
11 #include "except.h" | |
12 #else | |
13 #include "libwin32.h" | |
14 #endif | |
15 | |
16 #include "DS_Filter.h" | |
17 | |
18 struct _DS_AudioDecoder | |
19 { | |
20 WAVEFORMATEX in_fmt; | |
21 AM_MEDIA_TYPE m_sOurType, m_sDestType; | |
22 DS_Filter* m_pDS_Filter; | |
23 char* m_sVhdr; | |
24 char* m_sVhdr2; | |
25 }; | |
26 | |
2069 | 27 #include "DS_AudioDecoder.h" |
9967
b0d1b415320c
cygwin support patch by Sascha Sommer and some fixes by me
alex
parents:
9503
diff
changeset
|
28 #ifdef WIN32_LOADER |
8451 | 29 #include "../ldt_keeper.h" |
9967
b0d1b415320c
cygwin support patch by Sascha Sommer and some fixes by me
alex
parents:
9503
diff
changeset
|
30 #endif |
3946 | 31 |
2069 | 32 #include <string.h> |
33 #include <stdio.h> | |
3059 | 34 #include <stdlib.h> |
2069 | 35 |
1545 | 36 typedef long STDCALL (*GETCLASS) (GUID*, GUID*, void**); |
37 | |
22398
49f01f8fbd60
Rework of copying samples from directshow codecs.
voroshil
parents:
22304
diff
changeset
|
38 static SampleProcUserData sampleProcData; |
49f01f8fbd60
Rework of copying samples from directshow codecs.
voroshil
parents:
22304
diff
changeset
|
39 |
49f01f8fbd60
Rework of copying samples from directshow codecs.
voroshil
parents:
22304
diff
changeset
|
40 |
3444 | 41 DS_AudioDecoder * DS_AudioDecoder_Open(char* dllname, GUID* guid, WAVEFORMATEX* wf) |
42 //DS_AudioDecoder * DS_AudioDecoder_Create(const CodecInfo * info, const WAVEFORMATEX* wf) | |
1545 | 43 { |
3059 | 44 DS_AudioDecoder *this; |
45 int sz; | |
46 WAVEFORMATEX* pWF; | |
3444 | 47 |
9967
b0d1b415320c
cygwin support patch by Sascha Sommer and some fixes by me
alex
parents:
9503
diff
changeset
|
48 #ifdef WIN32_LOADER |
3444 | 49 Setup_LDT_Keeper(); |
50 Setup_FS_Segment(); | |
9967
b0d1b415320c
cygwin support patch by Sascha Sommer and some fixes by me
alex
parents:
9503
diff
changeset
|
51 #endif |
3059 | 52 |
53 this = malloc(sizeof(DS_AudioDecoder)); | |
54 | |
55 sz = 18 + wf->cbSize; | |
56 this->m_sVhdr = malloc(sz); | |
57 memcpy(this->m_sVhdr, wf, sz); | |
3915 | 58 this->m_sVhdr2 = malloc(18); |
59 memcpy(this->m_sVhdr2, this->m_sVhdr, 18); | |
3059 | 60 |
61 pWF = (WAVEFORMATEX*)this->m_sVhdr2; | |
62 pWF->wFormatTag = 1; | |
63 pWF->wBitsPerSample = 16; | |
3915 | 64 pWF->nBlockAlign = pWF->nChannels * (pWF->wBitsPerSample + 7) / 8; |
3059 | 65 pWF->cbSize = 0; |
3915 | 66 pWF->nAvgBytesPerSec = pWF->nBlockAlign * pWF->nSamplesPerSec; |
3059 | 67 |
68 memcpy(&this->in_fmt,wf,sizeof(WAVEFORMATEX)); | |
1545 | 69 |
3059 | 70 memset(&this->m_sOurType, 0, sizeof(this->m_sOurType)); |
71 this->m_sOurType.majortype=MEDIATYPE_Audio; | |
72 this->m_sOurType.subtype=MEDIASUBTYPE_PCM; | |
73 this->m_sOurType.subtype.f1=wf->wFormatTag; | |
74 this->m_sOurType.formattype=FORMAT_WaveFormatEx; | |
75 this->m_sOurType.lSampleSize=wf->nBlockAlign; | |
76 this->m_sOurType.bFixedSizeSamples=1; | |
77 this->m_sOurType.bTemporalCompression=0; | |
78 this->m_sOurType.pUnk=0; | |
79 this->m_sOurType.cbFormat=sz; | |
80 this->m_sOurType.pbFormat=this->m_sVhdr; | |
1545 | 81 |
3059 | 82 memset(&this->m_sDestType, 0, sizeof(this->m_sDestType)); |
83 this->m_sDestType.majortype=MEDIATYPE_Audio; | |
84 this->m_sDestType.subtype=MEDIASUBTYPE_PCM; | |
3915 | 85 // this->m_sDestType.subtype.f1=pWF->wFormatTag; |
3059 | 86 this->m_sDestType.formattype=FORMAT_WaveFormatEx; |
87 this->m_sDestType.bFixedSizeSamples=1; | |
88 this->m_sDestType.bTemporalCompression=0; | |
3915 | 89 this->m_sDestType.lSampleSize=pWF->nBlockAlign; |
3466 | 90 if (wf->wFormatTag == 0x130) |
91 // ACEL hack to prevent memory corruption | |
92 // obviosly we are missing something here | |
93 this->m_sDestType.lSampleSize *= 288; | |
3059 | 94 this->m_sDestType.pUnk=0; |
3915 | 95 this->m_sDestType.cbFormat=18; //pWF->cbSize; |
3059 | 96 this->m_sDestType.pbFormat=this->m_sVhdr2; |
1545 | 97 |
17977
f70772d02eaa
Convert printfs in aviprint.c to mp_msg and give the information printing
diego
parents:
9967
diff
changeset
|
98 //print_wave_header(this->m_sVhdr, MSGL_V); |
f70772d02eaa
Convert printfs in aviprint.c to mp_msg and give the information printing
diego
parents:
9967
diff
changeset
|
99 //print_wave_header(this->m_sVhdr2, MSGL_V); |
3915 | 100 |
3059 | 101 /*try*/ |
1545 | 102 { |
3059 | 103 ALLOCATOR_PROPERTIES props, props1; |
22398
49f01f8fbd60
Rework of copying samples from directshow codecs.
voroshil
parents:
22304
diff
changeset
|
104 this->m_pDS_Filter = DS_FilterCreate(dllname, guid, &this->m_sOurType, &this->m_sDestType,&sampleProcData); |
3059 | 105 if( !this->m_pDS_Filter ) { |
106 free(this); | |
107 return NULL; | |
108 } | |
109 | |
22304
254733f57707
Fixed loading of VoxWare and wma9sp binary audio codecs using dshow engine.
voroshil
parents:
22001
diff
changeset
|
110 //Commit should be done before binary codec start |
254733f57707
Fixed loading of VoxWare and wma9sp binary audio codecs using dshow engine.
voroshil
parents:
22001
diff
changeset
|
111 this->m_pDS_Filter->m_pAll->vt->Commit(this->m_pDS_Filter->m_pAll); |
254733f57707
Fixed loading of VoxWare and wma9sp binary audio codecs using dshow engine.
voroshil
parents:
22001
diff
changeset
|
112 |
3063 | 113 this->m_pDS_Filter->Start(this->m_pDS_Filter); |
1545 | 114 |
115 } | |
3059 | 116 /* |
117 catch (FatalError& e) | |
1545 | 118 { |
119 e.PrintAll(); | |
120 delete[] m_sVhdr; | |
121 delete[] m_sVhdr2; | |
122 delete m_pDS_Filter; | |
123 throw; | |
124 } | |
3059 | 125 */ |
126 return this; | |
1545 | 127 } |
128 | |
3059 | 129 void DS_AudioDecoder_Destroy(DS_AudioDecoder *this) |
1545 | 130 { |
3059 | 131 free(this->m_sVhdr); |
132 free(this->m_sVhdr2); | |
133 DS_Filter_Destroy(this->m_pDS_Filter); | |
134 free(this); | |
1545 | 135 } |
136 | |
3946 | 137 int DS_AudioDecoder_Convert(DS_AudioDecoder *this, const void* in_data, unsigned int in_size, |
138 void* out_data, unsigned int out_size, | |
139 unsigned int* size_read, unsigned int* size_written) | |
1545 | 140 { |
3946 | 141 unsigned int written = 0; |
142 unsigned int read = 0; | |
3059 | 143 |
1545 | 144 if (!in_data || !out_data) |
145 return -1; | |
146 | |
9967
b0d1b415320c
cygwin support patch by Sascha Sommer and some fixes by me
alex
parents:
9503
diff
changeset
|
147 #ifdef WIN32_LOADER |
3444 | 148 Setup_FS_Segment(); |
9967
b0d1b415320c
cygwin support patch by Sascha Sommer and some fixes by me
alex
parents:
9503
diff
changeset
|
149 #endif |
3444 | 150 |
3059 | 151 in_size -= in_size%this->in_fmt.nBlockAlign; |
1545 | 152 while (in_size>0) |
153 { | |
154 IMediaSample* sample=0; | |
3059 | 155 char* ptr; |
156 int result; | |
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); | |
22398
49f01f8fbd60
Rework of copying samples from directshow codecs.
voroshil
parents:
22304
diff
changeset
|
171 if ((written + sampleProcData.frame_size) > out_size) |
1545 | 172 { |
173 sample->vt->Release((IUnknown*)sample); | |
174 break; | |
175 } | |
22398
49f01f8fbd60
Rework of copying samples from directshow codecs.
voroshil
parents:
22304
diff
changeset
|
176 memcpy((uint8_t*)out_data + written, sampleProcData.frame_pointer, sampleProcData.frame_size); |
1545 | 177 sample->vt->Release((IUnknown*)sample); |
3059 | 178 read+=this->in_fmt.nBlockAlign; |
22398
49f01f8fbd60
Rework of copying samples from directshow codecs.
voroshil
parents:
22304
diff
changeset
|
179 written+=sampleProcData.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 } |