Mercurial > mplayer.hg
annotate loader/dshow/DS_AudioDecoder.c @ 29251:cada7608488b
Get rid of some more trailing whitespace
author | reynaldo |
---|---|
date | Tue, 12 May 2009 02:41:04 +0000 |
parents | a6b506faeb34 |
children | 0f1b5b68af32 |
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 #include "libwin32.h" |
10 | |
11 #include "DS_Filter.h" | |
12 | |
25794
2c8cdb9123b8
Fix a ton of illegal identifiers. Identifiers starting with __ or _ and a
diego
parents:
24389
diff
changeset
|
13 struct DS_AudioDecoder |
3946 | 14 { |
15 WAVEFORMATEX in_fmt; | |
16 AM_MEDIA_TYPE m_sOurType, m_sDestType; | |
17 DS_Filter* m_pDS_Filter; | |
18 char* m_sVhdr; | |
19 char* m_sVhdr2; | |
20 }; | |
21 | |
2069 | 22 #include "DS_AudioDecoder.h" |
9967
b0d1b415320c
cygwin support patch by Sascha Sommer and some fixes by me
alex
parents:
9503
diff
changeset
|
23 #ifdef WIN32_LOADER |
26544 | 24 #include "ldt_keeper.h" |
9967
b0d1b415320c
cygwin support patch by Sascha Sommer and some fixes by me
alex
parents:
9503
diff
changeset
|
25 #endif |
3946 | 26 |
2069 | 27 #include <string.h> |
28 #include <stdio.h> | |
3059 | 29 #include <stdlib.h> |
2069 | 30 |
1545 | 31 typedef long STDCALL (*GETCLASS) (GUID*, GUID*, void**); |
32 | |
22398
49f01f8fbd60
Rework of copying samples from directshow codecs.
voroshil
parents:
22304
diff
changeset
|
33 static SampleProcUserData sampleProcData; |
49f01f8fbd60
Rework of copying samples from directshow codecs.
voroshil
parents:
22304
diff
changeset
|
34 |
49f01f8fbd60
Rework of copying samples from directshow codecs.
voroshil
parents:
22304
diff
changeset
|
35 |
3444 | 36 DS_AudioDecoder * DS_AudioDecoder_Open(char* dllname, GUID* guid, WAVEFORMATEX* wf) |
37 //DS_AudioDecoder * DS_AudioDecoder_Create(const CodecInfo * info, const WAVEFORMATEX* wf) | |
1545 | 38 { |
3059 | 39 DS_AudioDecoder *this; |
40 int sz; | |
41 WAVEFORMATEX* pWF; | |
3444 | 42 |
9967
b0d1b415320c
cygwin support patch by Sascha Sommer and some fixes by me
alex
parents:
9503
diff
changeset
|
43 #ifdef WIN32_LOADER |
3444 | 44 Setup_LDT_Keeper(); |
45 Setup_FS_Segment(); | |
9967
b0d1b415320c
cygwin support patch by Sascha Sommer and some fixes by me
alex
parents:
9503
diff
changeset
|
46 #endif |
3059 | 47 |
48 this = malloc(sizeof(DS_AudioDecoder)); | |
49 | |
50 sz = 18 + wf->cbSize; | |
51 this->m_sVhdr = malloc(sz); | |
52 memcpy(this->m_sVhdr, wf, sz); | |
3915 | 53 this->m_sVhdr2 = malloc(18); |
54 memcpy(this->m_sVhdr2, this->m_sVhdr, 18); | |
3059 | 55 |
56 pWF = (WAVEFORMATEX*)this->m_sVhdr2; | |
57 pWF->wFormatTag = 1; | |
58 pWF->wBitsPerSample = 16; | |
3915 | 59 pWF->nBlockAlign = pWF->nChannels * (pWF->wBitsPerSample + 7) / 8; |
3059 | 60 pWF->cbSize = 0; |
3915 | 61 pWF->nAvgBytesPerSec = pWF->nBlockAlign * pWF->nSamplesPerSec; |
3059 | 62 |
63 memcpy(&this->in_fmt,wf,sizeof(WAVEFORMATEX)); | |
1545 | 64 |
3059 | 65 memset(&this->m_sOurType, 0, sizeof(this->m_sOurType)); |
66 this->m_sOurType.majortype=MEDIATYPE_Audio; | |
67 this->m_sOurType.subtype=MEDIASUBTYPE_PCM; | |
68 this->m_sOurType.subtype.f1=wf->wFormatTag; | |
69 this->m_sOurType.formattype=FORMAT_WaveFormatEx; | |
70 this->m_sOurType.lSampleSize=wf->nBlockAlign; | |
71 this->m_sOurType.bFixedSizeSamples=1; | |
72 this->m_sOurType.bTemporalCompression=0; | |
73 this->m_sOurType.pUnk=0; | |
74 this->m_sOurType.cbFormat=sz; | |
75 this->m_sOurType.pbFormat=this->m_sVhdr; | |
1545 | 76 |
3059 | 77 memset(&this->m_sDestType, 0, sizeof(this->m_sDestType)); |
78 this->m_sDestType.majortype=MEDIATYPE_Audio; | |
79 this->m_sDestType.subtype=MEDIASUBTYPE_PCM; | |
3915 | 80 // this->m_sDestType.subtype.f1=pWF->wFormatTag; |
3059 | 81 this->m_sDestType.formattype=FORMAT_WaveFormatEx; |
82 this->m_sDestType.bFixedSizeSamples=1; | |
83 this->m_sDestType.bTemporalCompression=0; | |
3915 | 84 this->m_sDestType.lSampleSize=pWF->nBlockAlign; |
3466 | 85 if (wf->wFormatTag == 0x130) |
86 // ACEL hack to prevent memory corruption | |
87 // obviosly we are missing something here | |
88 this->m_sDestType.lSampleSize *= 288; | |
3059 | 89 this->m_sDestType.pUnk=0; |
3915 | 90 this->m_sDestType.cbFormat=18; //pWF->cbSize; |
3059 | 91 this->m_sDestType.pbFormat=this->m_sVhdr2; |
1545 | 92 |
17977
f70772d02eaa
Convert printfs in aviprint.c to mp_msg and give the information printing
diego
parents:
9967
diff
changeset
|
93 //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
|
94 //print_wave_header(this->m_sVhdr2, MSGL_V); |
3915 | 95 |
3059 | 96 /*try*/ |
1545 | 97 { |
22398
49f01f8fbd60
Rework of copying samples from directshow codecs.
voroshil
parents:
22304
diff
changeset
|
98 this->m_pDS_Filter = DS_FilterCreate(dllname, guid, &this->m_sOurType, &this->m_sDestType,&sampleProcData); |
3059 | 99 if( !this->m_pDS_Filter ) { |
100 free(this); | |
101 return NULL; | |
102 } | |
103 | |
22304
254733f57707
Fixed loading of VoxWare and wma9sp binary audio codecs using dshow engine.
voroshil
parents:
22001
diff
changeset
|
104 //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
|
105 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
|
106 |
3063 | 107 this->m_pDS_Filter->Start(this->m_pDS_Filter); |
1545 | 108 |
109 } | |
3059 | 110 /* |
111 catch (FatalError& e) | |
1545 | 112 { |
113 e.PrintAll(); | |
114 delete[] m_sVhdr; | |
115 delete[] m_sVhdr2; | |
116 delete m_pDS_Filter; | |
117 throw; | |
118 } | |
3059 | 119 */ |
120 return this; | |
1545 | 121 } |
122 | |
3059 | 123 void DS_AudioDecoder_Destroy(DS_AudioDecoder *this) |
1545 | 124 { |
3059 | 125 free(this->m_sVhdr); |
126 free(this->m_sVhdr2); | |
127 DS_Filter_Destroy(this->m_pDS_Filter); | |
128 free(this); | |
1545 | 129 } |
130 | |
3946 | 131 int DS_AudioDecoder_Convert(DS_AudioDecoder *this, const void* in_data, unsigned int in_size, |
132 void* out_data, unsigned int out_size, | |
133 unsigned int* size_read, unsigned int* size_written) | |
1545 | 134 { |
3946 | 135 unsigned int written = 0; |
136 unsigned int read = 0; | |
3059 | 137 |
1545 | 138 if (!in_data || !out_data) |
139 return -1; | |
140 | |
9967
b0d1b415320c
cygwin support patch by Sascha Sommer and some fixes by me
alex
parents:
9503
diff
changeset
|
141 #ifdef WIN32_LOADER |
3444 | 142 Setup_FS_Segment(); |
9967
b0d1b415320c
cygwin support patch by Sascha Sommer and some fixes by me
alex
parents:
9503
diff
changeset
|
143 #endif |
3444 | 144 |
3059 | 145 in_size -= in_size%this->in_fmt.nBlockAlign; |
1545 | 146 while (in_size>0) |
147 { | |
148 IMediaSample* sample=0; | |
3059 | 149 char* ptr; |
150 int result; | |
151 this->m_pDS_Filter->m_pAll->vt->GetBuffer(this->m_pDS_Filter->m_pAll, &sample, 0, 0, 0); | |
152 if (!sample) | |
1545 | 153 { |
2069 | 154 Debug printf("DS_AudioDecoder::Convert() Error: null sample\n"); |
1545 | 155 break; |
156 } | |
3466 | 157 sample->vt->SetActualDataLength(sample, this->in_fmt.nBlockAlign); |
1545 | 158 sample->vt->GetPointer(sample, (BYTE **)&ptr); |
3059 | 159 memcpy(ptr, (const uint8_t*)in_data + read, this->in_fmt.nBlockAlign); |
160 sample->vt->SetSyncPoint(sample, 1); | |
1545 | 161 sample->vt->SetPreroll(sample, 0); |
3059 | 162 result = this->m_pDS_Filter->m_pImp->vt->Receive(this->m_pDS_Filter->m_pImp, sample); |
1545 | 163 if (result) |
164 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
|
165 if ((written + sampleProcData.frame_size) > out_size) |
1545 | 166 { |
167 sample->vt->Release((IUnknown*)sample); | |
168 break; | |
169 } | |
22398
49f01f8fbd60
Rework of copying samples from directshow codecs.
voroshil
parents:
22304
diff
changeset
|
170 memcpy((uint8_t*)out_data + written, sampleProcData.frame_pointer, sampleProcData.frame_size); |
1545 | 171 sample->vt->Release((IUnknown*)sample); |
3059 | 172 read+=this->in_fmt.nBlockAlign; |
22398
49f01f8fbd60
Rework of copying samples from directshow codecs.
voroshil
parents:
22304
diff
changeset
|
173 written+=sampleProcData.frame_size; |
3466 | 174 break; |
1545 | 175 } |
176 if (size_read) | |
177 *size_read = read; | |
178 if (size_written) | |
179 *size_written = written; | |
180 return 0; | |
181 } | |
182 | |
3059 | 183 int DS_AudioDecoder_GetSrcSize(DS_AudioDecoder *this, int dest_size) |
1545 | 184 { |
3059 | 185 double efficiency =(double) this->in_fmt.nAvgBytesPerSec |
186 / (this->in_fmt.nSamplesPerSec*this->in_fmt.nBlockAlign); | |
28576 | 187 int frames = (int)(dest_size*efficiency); |
3059 | 188 |
1545 | 189 if (frames < 1) |
190 frames = 1; | |
3059 | 191 return frames * this->in_fmt.nBlockAlign; |
1545 | 192 } |