Mercurial > mplayer.hg
annotate loader/dshow/DS_AudioDecoder.c @ 22014:9472dc33de99
Cosmetics. Doxygen comments.
author | voroshil |
---|---|
date | Sat, 27 Jan 2007 15:49:53 +0000 |
parents | 2934974c366a |
children | 254733f57707 |
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 | |
3063 | 107 this->m_pDS_Filter->Start(this->m_pDS_Filter); |
1545 | 108 |
109 props.cBuffers=1; | |
3059 | 110 props.cbBuffer=this->m_sOurType.lSampleSize; |
9503
f47d484d8f28
cbAlign=1 fix for proper Windows support (noticed by Sascha Sommer)
alex
parents:
8451
diff
changeset
|
111 props.cbAlign=1; |
f47d484d8f28
cbAlign=1 fix for proper Windows support (noticed by Sascha Sommer)
alex
parents:
8451
diff
changeset
|
112 props.cbPrefix=0; |
3059 | 113 this->m_pDS_Filter->m_pAll->vt->SetProperties(this->m_pDS_Filter->m_pAll, &props, &props1); |
114 this->m_pDS_Filter->m_pAll->vt->Commit(this->m_pDS_Filter->m_pAll); | |
1545 | 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 { | |
3946 | 154 unsigned int frame_size = 0; |
1545 | 155 char* frame_pointer; |
156 IMediaSample* sample=0; | |
3059 | 157 char* ptr; |
158 int result; | |
159 | |
160 // this->m_pOurOutput->SetFramePointer(out_data+written); | |
3063 | 161 this->m_pDS_Filter->m_pOurOutput->SetFramePointer(this->m_pDS_Filter->m_pOurOutput,&frame_pointer); |
162 this->m_pDS_Filter->m_pOurOutput->SetFrameSizePointer(this->m_pDS_Filter->m_pOurOutput,(long*)&frame_size); | |
3059 | 163 this->m_pDS_Filter->m_pAll->vt->GetBuffer(this->m_pDS_Filter->m_pAll, &sample, 0, 0, 0); |
164 if (!sample) | |
1545 | 165 { |
2069 | 166 Debug printf("DS_AudioDecoder::Convert() Error: null sample\n"); |
1545 | 167 break; |
168 } | |
3466 | 169 sample->vt->SetActualDataLength(sample, this->in_fmt.nBlockAlign); |
1545 | 170 sample->vt->GetPointer(sample, (BYTE **)&ptr); |
3059 | 171 memcpy(ptr, (const uint8_t*)in_data + read, this->in_fmt.nBlockAlign); |
172 sample->vt->SetSyncPoint(sample, 1); | |
1545 | 173 sample->vt->SetPreroll(sample, 0); |
3059 | 174 result = this->m_pDS_Filter->m_pImp->vt->Receive(this->m_pDS_Filter->m_pImp, sample); |
1545 | 175 if (result) |
176 Debug printf("DS_AudioDecoder::Convert() Error: putting data into input pin %x\n", result); | |
177 if ((written + frame_size) > out_size) | |
178 { | |
179 sample->vt->Release((IUnknown*)sample); | |
180 break; | |
181 } | |
182 memcpy((uint8_t*)out_data + written, frame_pointer, frame_size); | |
183 sample->vt->Release((IUnknown*)sample); | |
3059 | 184 read+=this->in_fmt.nBlockAlign; |
1545 | 185 written+=frame_size; |
3466 | 186 break; |
1545 | 187 } |
188 if (size_read) | |
189 *size_read = read; | |
190 if (size_written) | |
191 *size_written = written; | |
192 return 0; | |
193 } | |
194 | |
3059 | 195 int DS_AudioDecoder_GetSrcSize(DS_AudioDecoder *this, int dest_size) |
1545 | 196 { |
3059 | 197 double efficiency =(double) this->in_fmt.nAvgBytesPerSec |
198 / (this->in_fmt.nSamplesPerSec*this->in_fmt.nBlockAlign); | |
199 int frames = (int)(dest_size*efficiency);; | |
200 | |
1545 | 201 if (frames < 1) |
202 frames = 1; | |
3059 | 203 return frames * this->in_fmt.nBlockAlign; |
1545 | 204 } |