Mercurial > mplayer.hg
annotate loader/dshow/DS_AudioDecoder.c @ 22347:c8a46062a210
Move glob-win.c out of MinGW section, configure handles it.
author | diego |
---|---|
date | Tue, 27 Feb 2007 17:12:23 +0000 |
parents | 254733f57707 |
children | 49f01f8fbd60 |
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 | |
3444 | 38 DS_AudioDecoder * DS_AudioDecoder_Open(char* dllname, GUID* guid, WAVEFORMATEX* wf) |
39 //DS_AudioDecoder * DS_AudioDecoder_Create(const CodecInfo * info, const WAVEFORMATEX* wf) | |
1545 | 40 { |
3059 | 41 DS_AudioDecoder *this; |
42 int sz; | |
43 WAVEFORMATEX* pWF; | |
3444 | 44 |
9967
b0d1b415320c
cygwin support patch by Sascha Sommer and some fixes by me
alex
parents:
9503
diff
changeset
|
45 #ifdef WIN32_LOADER |
3444 | 46 Setup_LDT_Keeper(); |
47 Setup_FS_Segment(); | |
9967
b0d1b415320c
cygwin support patch by Sascha Sommer and some fixes by me
alex
parents:
9503
diff
changeset
|
48 #endif |
3059 | 49 |
50 this = malloc(sizeof(DS_AudioDecoder)); | |
51 | |
52 sz = 18 + wf->cbSize; | |
53 this->m_sVhdr = malloc(sz); | |
54 memcpy(this->m_sVhdr, wf, sz); | |
3915 | 55 this->m_sVhdr2 = malloc(18); |
56 memcpy(this->m_sVhdr2, this->m_sVhdr, 18); | |
3059 | 57 |
58 pWF = (WAVEFORMATEX*)this->m_sVhdr2; | |
59 pWF->wFormatTag = 1; | |
60 pWF->wBitsPerSample = 16; | |
3915 | 61 pWF->nBlockAlign = pWF->nChannels * (pWF->wBitsPerSample + 7) / 8; |
3059 | 62 pWF->cbSize = 0; |
3915 | 63 pWF->nAvgBytesPerSec = pWF->nBlockAlign * pWF->nSamplesPerSec; |
3059 | 64 |
65 memcpy(&this->in_fmt,wf,sizeof(WAVEFORMATEX)); | |
1545 | 66 |
3059 | 67 memset(&this->m_sOurType, 0, sizeof(this->m_sOurType)); |
68 this->m_sOurType.majortype=MEDIATYPE_Audio; | |
69 this->m_sOurType.subtype=MEDIASUBTYPE_PCM; | |
70 this->m_sOurType.subtype.f1=wf->wFormatTag; | |
71 this->m_sOurType.formattype=FORMAT_WaveFormatEx; | |
72 this->m_sOurType.lSampleSize=wf->nBlockAlign; | |
73 this->m_sOurType.bFixedSizeSamples=1; | |
74 this->m_sOurType.bTemporalCompression=0; | |
75 this->m_sOurType.pUnk=0; | |
76 this->m_sOurType.cbFormat=sz; | |
77 this->m_sOurType.pbFormat=this->m_sVhdr; | |
1545 | 78 |
3059 | 79 memset(&this->m_sDestType, 0, sizeof(this->m_sDestType)); |
80 this->m_sDestType.majortype=MEDIATYPE_Audio; | |
81 this->m_sDestType.subtype=MEDIASUBTYPE_PCM; | |
3915 | 82 // this->m_sDestType.subtype.f1=pWF->wFormatTag; |
3059 | 83 this->m_sDestType.formattype=FORMAT_WaveFormatEx; |
84 this->m_sDestType.bFixedSizeSamples=1; | |
85 this->m_sDestType.bTemporalCompression=0; | |
3915 | 86 this->m_sDestType.lSampleSize=pWF->nBlockAlign; |
3466 | 87 if (wf->wFormatTag == 0x130) |
88 // ACEL hack to prevent memory corruption | |
89 // obviosly we are missing something here | |
90 this->m_sDestType.lSampleSize *= 288; | |
3059 | 91 this->m_sDestType.pUnk=0; |
3915 | 92 this->m_sDestType.cbFormat=18; //pWF->cbSize; |
3059 | 93 this->m_sDestType.pbFormat=this->m_sVhdr2; |
1545 | 94 |
17977
f70772d02eaa
Convert printfs in aviprint.c to mp_msg and give the information printing
diego
parents:
9967
diff
changeset
|
95 //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
|
96 //print_wave_header(this->m_sVhdr2, MSGL_V); |
3915 | 97 |
3059 | 98 /*try*/ |
1545 | 99 { |
3059 | 100 ALLOCATOR_PROPERTIES props, props1; |
3444 | 101 this->m_pDS_Filter = DS_FilterCreate(dllname, guid, &this->m_sOurType, &this->m_sDestType); |
3059 | 102 if( !this->m_pDS_Filter ) { |
103 free(this); | |
104 return NULL; | |
105 } | |
106 | |
22304
254733f57707
Fixed loading of VoxWare and wma9sp binary audio codecs using dshow engine.
voroshil
parents:
22001
diff
changeset
|
107 //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
|
108 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
|
109 |
3063 | 110 this->m_pDS_Filter->Start(this->m_pDS_Filter); |
1545 | 111 |
112 } | |
3059 | 113 /* |
114 catch (FatalError& e) | |
1545 | 115 { |
116 e.PrintAll(); | |
117 delete[] m_sVhdr; | |
118 delete[] m_sVhdr2; | |
119 delete m_pDS_Filter; | |
120 throw; | |
121 } | |
3059 | 122 */ |
123 return this; | |
1545 | 124 } |
125 | |
3059 | 126 void DS_AudioDecoder_Destroy(DS_AudioDecoder *this) |
1545 | 127 { |
3059 | 128 free(this->m_sVhdr); |
129 free(this->m_sVhdr2); | |
130 DS_Filter_Destroy(this->m_pDS_Filter); | |
131 free(this); | |
1545 | 132 } |
133 | |
3946 | 134 int DS_AudioDecoder_Convert(DS_AudioDecoder *this, const void* in_data, unsigned int in_size, |
135 void* out_data, unsigned int out_size, | |
136 unsigned int* size_read, unsigned int* size_written) | |
1545 | 137 { |
3946 | 138 unsigned int written = 0; |
139 unsigned int read = 0; | |
3059 | 140 |
1545 | 141 if (!in_data || !out_data) |
142 return -1; | |
143 | |
9967
b0d1b415320c
cygwin support patch by Sascha Sommer and some fixes by me
alex
parents:
9503
diff
changeset
|
144 #ifdef WIN32_LOADER |
3444 | 145 Setup_FS_Segment(); |
9967
b0d1b415320c
cygwin support patch by Sascha Sommer and some fixes by me
alex
parents:
9503
diff
changeset
|
146 #endif |
3444 | 147 |
3059 | 148 in_size -= in_size%this->in_fmt.nBlockAlign; |
1545 | 149 while (in_size>0) |
150 { | |
3946 | 151 unsigned int frame_size = 0; |
1545 | 152 char* frame_pointer; |
153 IMediaSample* sample=0; | |
3059 | 154 char* ptr; |
155 int result; | |
156 | |
157 // this->m_pOurOutput->SetFramePointer(out_data+written); | |
3063 | 158 this->m_pDS_Filter->m_pOurOutput->SetFramePointer(this->m_pDS_Filter->m_pOurOutput,&frame_pointer); |
159 this->m_pDS_Filter->m_pOurOutput->SetFrameSizePointer(this->m_pDS_Filter->m_pOurOutput,(long*)&frame_size); | |
3059 | 160 this->m_pDS_Filter->m_pAll->vt->GetBuffer(this->m_pDS_Filter->m_pAll, &sample, 0, 0, 0); |
161 if (!sample) | |
1545 | 162 { |
2069 | 163 Debug printf("DS_AudioDecoder::Convert() Error: null sample\n"); |
1545 | 164 break; |
165 } | |
3466 | 166 sample->vt->SetActualDataLength(sample, this->in_fmt.nBlockAlign); |
1545 | 167 sample->vt->GetPointer(sample, (BYTE **)&ptr); |
3059 | 168 memcpy(ptr, (const uint8_t*)in_data + read, this->in_fmt.nBlockAlign); |
169 sample->vt->SetSyncPoint(sample, 1); | |
1545 | 170 sample->vt->SetPreroll(sample, 0); |
3059 | 171 result = this->m_pDS_Filter->m_pImp->vt->Receive(this->m_pDS_Filter->m_pImp, sample); |
1545 | 172 if (result) |
173 Debug printf("DS_AudioDecoder::Convert() Error: putting data into input pin %x\n", result); | |
174 if ((written + frame_size) > out_size) | |
175 { | |
176 sample->vt->Release((IUnknown*)sample); | |
177 break; | |
178 } | |
179 memcpy((uint8_t*)out_data + written, frame_pointer, frame_size); | |
180 sample->vt->Release((IUnknown*)sample); | |
3059 | 181 read+=this->in_fmt.nBlockAlign; |
1545 | 182 written+=frame_size; |
3466 | 183 break; |
1545 | 184 } |
185 if (size_read) | |
186 *size_read = read; | |
187 if (size_written) | |
188 *size_written = written; | |
189 return 0; | |
190 } | |
191 | |
3059 | 192 int DS_AudioDecoder_GetSrcSize(DS_AudioDecoder *this, int dest_size) |
1545 | 193 { |
3059 | 194 double efficiency =(double) this->in_fmt.nAvgBytesPerSec |
195 / (this->in_fmt.nSamplesPerSec*this->in_fmt.nBlockAlign); | |
196 int frames = (int)(dest_size*efficiency);; | |
197 | |
1545 | 198 if (frames < 1) |
199 frames = 1; | |
3059 | 200 return frames * this->in_fmt.nBlockAlign; |
1545 | 201 } |