Mercurial > mplayer.hg
annotate loader/dshow/DS_AudioDecoder.c @ 9840:2a219cbb1435
Chinese translation for main branch
author | luran |
---|---|
date | Sun, 06 Apr 2003 13:27:10 +0000 |
parents | f47d484d8f28 |
children | b0d1b415320c |
rev | line source |
---|---|
1545 | 1 /******************************************************** |
2 | |
3 DirectShow audio decoder | |
4 Copyright 2001 Eugene Kuznetsov (divx@euro.ru) | |
5 | |
6 *********************************************************/ | |
7 | |
3946 | 8 #ifndef NOAVIFILE_HEADERS |
9 #include "audiodecoder.h" | |
10 #include "except.h" | |
11 #else | |
12 #include "libwin32.h" | |
13 #endif | |
14 | |
15 #include "DS_Filter.h" | |
16 | |
17 struct _DS_AudioDecoder | |
18 { | |
19 WAVEFORMATEX in_fmt; | |
20 AM_MEDIA_TYPE m_sOurType, m_sDestType; | |
21 DS_Filter* m_pDS_Filter; | |
22 char* m_sVhdr; | |
23 char* m_sVhdr2; | |
24 }; | |
25 | |
2069 | 26 #include "DS_AudioDecoder.h" |
8451 | 27 #include "../ldt_keeper.h" |
3946 | 28 |
2069 | 29 #include <string.h> |
30 #include <stdio.h> | |
3059 | 31 #include <stdlib.h> |
2069 | 32 |
1545 | 33 #define __MODULE__ "DirectShow audio decoder" |
34 | |
35 typedef long STDCALL (*GETCLASS) (GUID*, GUID*, void**); | |
36 | |
3444 | 37 DS_AudioDecoder * DS_AudioDecoder_Open(char* dllname, GUID* guid, WAVEFORMATEX* wf) |
38 //DS_AudioDecoder * DS_AudioDecoder_Create(const CodecInfo * info, const WAVEFORMATEX* wf) | |
1545 | 39 { |
3059 | 40 DS_AudioDecoder *this; |
41 int sz; | |
42 WAVEFORMATEX* pWF; | |
3444 | 43 |
44 Setup_LDT_Keeper(); | |
45 Setup_FS_Segment(); | |
3059 | 46 |
47 this = malloc(sizeof(DS_AudioDecoder)); | |
48 | |
49 sz = 18 + wf->cbSize; | |
50 this->m_sVhdr = malloc(sz); | |
51 memcpy(this->m_sVhdr, wf, sz); | |
3915 | 52 this->m_sVhdr2 = malloc(18); |
53 memcpy(this->m_sVhdr2, this->m_sVhdr, 18); | |
3059 | 54 |
55 pWF = (WAVEFORMATEX*)this->m_sVhdr2; | |
56 pWF->wFormatTag = 1; | |
57 pWF->wBitsPerSample = 16; | |
3915 | 58 pWF->nBlockAlign = pWF->nChannels * (pWF->wBitsPerSample + 7) / 8; |
3059 | 59 pWF->cbSize = 0; |
3915 | 60 pWF->nAvgBytesPerSec = pWF->nBlockAlign * pWF->nSamplesPerSec; |
3059 | 61 |
62 memcpy(&this->in_fmt,wf,sizeof(WAVEFORMATEX)); | |
1545 | 63 |
3059 | 64 memset(&this->m_sOurType, 0, sizeof(this->m_sOurType)); |
65 this->m_sOurType.majortype=MEDIATYPE_Audio; | |
66 this->m_sOurType.subtype=MEDIASUBTYPE_PCM; | |
67 this->m_sOurType.subtype.f1=wf->wFormatTag; | |
68 this->m_sOurType.formattype=FORMAT_WaveFormatEx; | |
69 this->m_sOurType.lSampleSize=wf->nBlockAlign; | |
70 this->m_sOurType.bFixedSizeSamples=1; | |
71 this->m_sOurType.bTemporalCompression=0; | |
72 this->m_sOurType.pUnk=0; | |
73 this->m_sOurType.cbFormat=sz; | |
74 this->m_sOurType.pbFormat=this->m_sVhdr; | |
1545 | 75 |
3059 | 76 memset(&this->m_sDestType, 0, sizeof(this->m_sDestType)); |
77 this->m_sDestType.majortype=MEDIATYPE_Audio; | |
78 this->m_sDestType.subtype=MEDIASUBTYPE_PCM; | |
3915 | 79 // this->m_sDestType.subtype.f1=pWF->wFormatTag; |
3059 | 80 this->m_sDestType.formattype=FORMAT_WaveFormatEx; |
81 this->m_sDestType.bFixedSizeSamples=1; | |
82 this->m_sDestType.bTemporalCompression=0; | |
3915 | 83 this->m_sDestType.lSampleSize=pWF->nBlockAlign; |
3466 | 84 if (wf->wFormatTag == 0x130) |
85 // ACEL hack to prevent memory corruption | |
86 // obviosly we are missing something here | |
87 this->m_sDestType.lSampleSize *= 288; | |
3059 | 88 this->m_sDestType.pUnk=0; |
3915 | 89 this->m_sDestType.cbFormat=18; //pWF->cbSize; |
3059 | 90 this->m_sDestType.pbFormat=this->m_sVhdr2; |
1545 | 91 |
6139
3898967fcc96
some more output cosmetics, especially for vivo and mov demuxers
arpi
parents:
3946
diff
changeset
|
92 //print_wave_header(this->m_sVhdr); |
3898967fcc96
some more output cosmetics, especially for vivo and mov demuxers
arpi
parents:
3946
diff
changeset
|
93 //print_wave_header(this->m_sVhdr2); |
3915 | 94 |
3059 | 95 /*try*/ |
1545 | 96 { |
3059 | 97 ALLOCATOR_PROPERTIES props, props1; |
3444 | 98 this->m_pDS_Filter = DS_FilterCreate(dllname, guid, &this->m_sOurType, &this->m_sDestType); |
3059 | 99 if( !this->m_pDS_Filter ) { |
100 free(this); | |
101 return NULL; | |
102 } | |
103 | |
3063 | 104 this->m_pDS_Filter->Start(this->m_pDS_Filter); |
1545 | 105 |
106 props.cBuffers=1; | |
3059 | 107 props.cbBuffer=this->m_sOurType.lSampleSize; |
9503
f47d484d8f28
cbAlign=1 fix for proper Windows support (noticed by Sascha Sommer)
alex
parents:
8451
diff
changeset
|
108 props.cbAlign=1; |
f47d484d8f28
cbAlign=1 fix for proper Windows support (noticed by Sascha Sommer)
alex
parents:
8451
diff
changeset
|
109 props.cbPrefix=0; |
3059 | 110 this->m_pDS_Filter->m_pAll->vt->SetProperties(this->m_pDS_Filter->m_pAll, &props, &props1); |
111 this->m_pDS_Filter->m_pAll->vt->Commit(this->m_pDS_Filter->m_pAll); | |
1545 | 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 | |
3444 | 144 Setup_FS_Segment(); |
145 | |
3059 | 146 in_size -= in_size%this->in_fmt.nBlockAlign; |
1545 | 147 while (in_size>0) |
148 { | |
3946 | 149 unsigned int frame_size = 0; |
1545 | 150 char* frame_pointer; |
151 IMediaSample* sample=0; | |
3059 | 152 char* ptr; |
153 int result; | |
154 | |
155 // this->m_pOurOutput->SetFramePointer(out_data+written); | |
3063 | 156 this->m_pDS_Filter->m_pOurOutput->SetFramePointer(this->m_pDS_Filter->m_pOurOutput,&frame_pointer); |
157 this->m_pDS_Filter->m_pOurOutput->SetFrameSizePointer(this->m_pDS_Filter->m_pOurOutput,(long*)&frame_size); | |
3059 | 158 this->m_pDS_Filter->m_pAll->vt->GetBuffer(this->m_pDS_Filter->m_pAll, &sample, 0, 0, 0); |
159 if (!sample) | |
1545 | 160 { |
2069 | 161 Debug printf("DS_AudioDecoder::Convert() Error: null sample\n"); |
1545 | 162 break; |
163 } | |
3466 | 164 sample->vt->SetActualDataLength(sample, this->in_fmt.nBlockAlign); |
1545 | 165 sample->vt->GetPointer(sample, (BYTE **)&ptr); |
3059 | 166 memcpy(ptr, (const uint8_t*)in_data + read, this->in_fmt.nBlockAlign); |
167 sample->vt->SetSyncPoint(sample, 1); | |
1545 | 168 sample->vt->SetPreroll(sample, 0); |
3059 | 169 result = this->m_pDS_Filter->m_pImp->vt->Receive(this->m_pDS_Filter->m_pImp, sample); |
1545 | 170 if (result) |
171 Debug printf("DS_AudioDecoder::Convert() Error: putting data into input pin %x\n", result); | |
172 if ((written + frame_size) > out_size) | |
173 { | |
174 sample->vt->Release((IUnknown*)sample); | |
175 break; | |
176 } | |
177 memcpy((uint8_t*)out_data + written, frame_pointer, frame_size); | |
178 sample->vt->Release((IUnknown*)sample); | |
3059 | 179 read+=this->in_fmt.nBlockAlign; |
1545 | 180 written+=frame_size; |
3466 | 181 break; |
1545 | 182 } |
183 if (size_read) | |
184 *size_read = read; | |
185 if (size_written) | |
186 *size_written = written; | |
187 return 0; | |
188 } | |
189 | |
3059 | 190 int DS_AudioDecoder_GetSrcSize(DS_AudioDecoder *this, int dest_size) |
1545 | 191 { |
3059 | 192 double efficiency =(double) this->in_fmt.nAvgBytesPerSec |
193 / (this->in_fmt.nSamplesPerSec*this->in_fmt.nBlockAlign); | |
194 int frames = (int)(dest_size*efficiency);; | |
195 | |
1545 | 196 if (frames < 1) |
197 frames = 1; | |
3059 | 198 return frames * this->in_fmt.nBlockAlign; |
1545 | 199 } |