Mercurial > mplayer.hg
annotate loader/dshow/DS_AudioDecoder.c @ 23919:440d23a28592
big 10L of r9888 located: passed fd instead of pointer to sun_vcd_read
author | reimar |
---|---|
date | Mon, 30 Jul 2007 15:47:17 +0000 |
parents | 450bb2a75cba |
children | edbf07d80f62 |
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 | |
13 struct _DS_AudioDecoder | |
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 |
8451 | 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 { |
3059 | 98 ALLOCATOR_PROPERTIES props, props1; |
22398
49f01f8fbd60
Rework of copying samples from directshow codecs.
voroshil
parents:
22304
diff
changeset
|
99 this->m_pDS_Filter = DS_FilterCreate(dllname, guid, &this->m_sOurType, &this->m_sDestType,&sampleProcData); |
3059 | 100 if( !this->m_pDS_Filter ) { |
101 free(this); | |
102 return NULL; | |
103 } | |
104 | |
22304
254733f57707
Fixed loading of VoxWare and wma9sp binary audio codecs using dshow engine.
voroshil
parents:
22001
diff
changeset
|
105 //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
|
106 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
|
107 |
3063 | 108 this->m_pDS_Filter->Start(this->m_pDS_Filter); |
1545 | 109 |
110 } | |
3059 | 111 /* |
112 catch (FatalError& e) | |
1545 | 113 { |
114 e.PrintAll(); | |
115 delete[] m_sVhdr; | |
116 delete[] m_sVhdr2; | |
117 delete m_pDS_Filter; | |
118 throw; | |
119 } | |
3059 | 120 */ |
121 return this; | |
1545 | 122 } |
123 | |
3059 | 124 void DS_AudioDecoder_Destroy(DS_AudioDecoder *this) |
1545 | 125 { |
3059 | 126 free(this->m_sVhdr); |
127 free(this->m_sVhdr2); | |
128 DS_Filter_Destroy(this->m_pDS_Filter); | |
129 free(this); | |
1545 | 130 } |
131 | |
3946 | 132 int DS_AudioDecoder_Convert(DS_AudioDecoder *this, const void* in_data, unsigned int in_size, |
133 void* out_data, unsigned int out_size, | |
134 unsigned int* size_read, unsigned int* size_written) | |
1545 | 135 { |
3946 | 136 unsigned int written = 0; |
137 unsigned int read = 0; | |
3059 | 138 |
1545 | 139 if (!in_data || !out_data) |
140 return -1; | |
141 | |
9967
b0d1b415320c
cygwin support patch by Sascha Sommer and some fixes by me
alex
parents:
9503
diff
changeset
|
142 #ifdef WIN32_LOADER |
3444 | 143 Setup_FS_Segment(); |
9967
b0d1b415320c
cygwin support patch by Sascha Sommer and some fixes by me
alex
parents:
9503
diff
changeset
|
144 #endif |
3444 | 145 |
3059 | 146 in_size -= in_size%this->in_fmt.nBlockAlign; |
1545 | 147 while (in_size>0) |
148 { | |
149 IMediaSample* sample=0; | |
3059 | 150 char* ptr; |
151 int result; | |
152 this->m_pDS_Filter->m_pAll->vt->GetBuffer(this->m_pDS_Filter->m_pAll, &sample, 0, 0, 0); | |
153 if (!sample) | |
1545 | 154 { |
2069 | 155 Debug printf("DS_AudioDecoder::Convert() Error: null sample\n"); |
1545 | 156 break; |
157 } | |
3466 | 158 sample->vt->SetActualDataLength(sample, this->in_fmt.nBlockAlign); |
1545 | 159 sample->vt->GetPointer(sample, (BYTE **)&ptr); |
3059 | 160 memcpy(ptr, (const uint8_t*)in_data + read, this->in_fmt.nBlockAlign); |
161 sample->vt->SetSyncPoint(sample, 1); | |
1545 | 162 sample->vt->SetPreroll(sample, 0); |
3059 | 163 result = this->m_pDS_Filter->m_pImp->vt->Receive(this->m_pDS_Filter->m_pImp, sample); |
1545 | 164 if (result) |
165 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
|
166 if ((written + sampleProcData.frame_size) > out_size) |
1545 | 167 { |
168 sample->vt->Release((IUnknown*)sample); | |
169 break; | |
170 } | |
22398
49f01f8fbd60
Rework of copying samples from directshow codecs.
voroshil
parents:
22304
diff
changeset
|
171 memcpy((uint8_t*)out_data + written, sampleProcData.frame_pointer, sampleProcData.frame_size); |
1545 | 172 sample->vt->Release((IUnknown*)sample); |
3059 | 173 read+=this->in_fmt.nBlockAlign; |
22398
49f01f8fbd60
Rework of copying samples from directshow codecs.
voroshil
parents:
22304
diff
changeset
|
174 written+=sampleProcData.frame_size; |
3466 | 175 break; |
1545 | 176 } |
177 if (size_read) | |
178 *size_read = read; | |
179 if (size_written) | |
180 *size_written = written; | |
181 return 0; | |
182 } | |
183 | |
3059 | 184 int DS_AudioDecoder_GetSrcSize(DS_AudioDecoder *this, int dest_size) |
1545 | 185 { |
3059 | 186 double efficiency =(double) this->in_fmt.nAvgBytesPerSec |
187 / (this->in_fmt.nSamplesPerSec*this->in_fmt.nBlockAlign); | |
188 int frames = (int)(dest_size*efficiency);; | |
189 | |
1545 | 190 if (frames < 1) |
191 frames = 1; | |
3059 | 192 return frames * this->in_fmt.nBlockAlign; |
1545 | 193 } |