Mercurial > mplayer.hg
annotate loader/dshow/DS_AudioDecoder.c @ 8319:7a56c1b0baf5
fixes
author | gabucino |
---|---|
date | Sat, 30 Nov 2002 22:15:42 +0000 |
parents | 9533c26c0806 |
children | fb88ccbc5ccc |
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" |
3946 | 27 |
2069 | 28 #include <string.h> |
29 #include <stdio.h> | |
3059 | 30 #include <stdlib.h> |
2069 | 31 |
1545 | 32 #define __MODULE__ "DirectShow audio decoder" |
33 | |
34 typedef long STDCALL (*GETCLASS) (GUID*, GUID*, void**); | |
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 |
43 Setup_LDT_Keeper(); | |
44 Setup_FS_Segment(); | |
3059 | 45 |
46 this = malloc(sizeof(DS_AudioDecoder)); | |
47 | |
48 sz = 18 + wf->cbSize; | |
49 this->m_sVhdr = malloc(sz); | |
50 memcpy(this->m_sVhdr, wf, sz); | |
3915 | 51 this->m_sVhdr2 = malloc(18); |
52 memcpy(this->m_sVhdr2, this->m_sVhdr, 18); | |
3059 | 53 |
54 pWF = (WAVEFORMATEX*)this->m_sVhdr2; | |
55 pWF->wFormatTag = 1; | |
56 pWF->wBitsPerSample = 16; | |
3915 | 57 pWF->nBlockAlign = pWF->nChannels * (pWF->wBitsPerSample + 7) / 8; |
3059 | 58 pWF->cbSize = 0; |
3915 | 59 pWF->nAvgBytesPerSec = pWF->nBlockAlign * pWF->nSamplesPerSec; |
3059 | 60 |
61 memcpy(&this->in_fmt,wf,sizeof(WAVEFORMATEX)); | |
1545 | 62 |
3059 | 63 memset(&this->m_sOurType, 0, sizeof(this->m_sOurType)); |
64 this->m_sOurType.majortype=MEDIATYPE_Audio; | |
65 this->m_sOurType.subtype=MEDIASUBTYPE_PCM; | |
66 this->m_sOurType.subtype.f1=wf->wFormatTag; | |
67 this->m_sOurType.formattype=FORMAT_WaveFormatEx; | |
68 this->m_sOurType.lSampleSize=wf->nBlockAlign; | |
69 this->m_sOurType.bFixedSizeSamples=1; | |
70 this->m_sOurType.bTemporalCompression=0; | |
71 this->m_sOurType.pUnk=0; | |
72 this->m_sOurType.cbFormat=sz; | |
73 this->m_sOurType.pbFormat=this->m_sVhdr; | |
1545 | 74 |
3059 | 75 memset(&this->m_sDestType, 0, sizeof(this->m_sDestType)); |
76 this->m_sDestType.majortype=MEDIATYPE_Audio; | |
77 this->m_sDestType.subtype=MEDIASUBTYPE_PCM; | |
3915 | 78 // this->m_sDestType.subtype.f1=pWF->wFormatTag; |
3059 | 79 this->m_sDestType.formattype=FORMAT_WaveFormatEx; |
80 this->m_sDestType.bFixedSizeSamples=1; | |
81 this->m_sDestType.bTemporalCompression=0; | |
3915 | 82 this->m_sDestType.lSampleSize=pWF->nBlockAlign; |
3466 | 83 if (wf->wFormatTag == 0x130) |
84 // ACEL hack to prevent memory corruption | |
85 // obviosly we are missing something here | |
86 this->m_sDestType.lSampleSize *= 288; | |
3059 | 87 this->m_sDestType.pUnk=0; |
3915 | 88 this->m_sDestType.cbFormat=18; //pWF->cbSize; |
3059 | 89 this->m_sDestType.pbFormat=this->m_sVhdr2; |
1545 | 90 |
6139
3898967fcc96
some more output cosmetics, especially for vivo and mov demuxers
arpi
parents:
3946
diff
changeset
|
91 //print_wave_header(this->m_sVhdr); |
3898967fcc96
some more output cosmetics, especially for vivo and mov demuxers
arpi
parents:
3946
diff
changeset
|
92 //print_wave_header(this->m_sVhdr2); |
3915 | 93 |
3059 | 94 /*try*/ |
1545 | 95 { |
3059 | 96 ALLOCATOR_PROPERTIES props, props1; |
3444 | 97 this->m_pDS_Filter = DS_FilterCreate(dllname, guid, &this->m_sOurType, &this->m_sDestType); |
3059 | 98 if( !this->m_pDS_Filter ) { |
99 free(this); | |
100 return NULL; | |
101 } | |
102 | |
3063 | 103 this->m_pDS_Filter->Start(this->m_pDS_Filter); |
1545 | 104 |
105 props.cBuffers=1; | |
3059 | 106 props.cbBuffer=this->m_sOurType.lSampleSize; |
1545 | 107 props.cbAlign=props.cbPrefix=0; |
3059 | 108 this->m_pDS_Filter->m_pAll->vt->SetProperties(this->m_pDS_Filter->m_pAll, &props, &props1); |
109 this->m_pDS_Filter->m_pAll->vt->Commit(this->m_pDS_Filter->m_pAll); | |
1545 | 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 | |
3444 | 142 Setup_FS_Segment(); |
143 | |
3059 | 144 in_size -= in_size%this->in_fmt.nBlockAlign; |
1545 | 145 while (in_size>0) |
146 { | |
3946 | 147 unsigned int frame_size = 0; |
1545 | 148 char* frame_pointer; |
149 IMediaSample* sample=0; | |
3059 | 150 char* ptr; |
151 int result; | |
152 | |
153 // this->m_pOurOutput->SetFramePointer(out_data+written); | |
3063 | 154 this->m_pDS_Filter->m_pOurOutput->SetFramePointer(this->m_pDS_Filter->m_pOurOutput,&frame_pointer); |
155 this->m_pDS_Filter->m_pOurOutput->SetFrameSizePointer(this->m_pDS_Filter->m_pOurOutput,(long*)&frame_size); | |
3059 | 156 this->m_pDS_Filter->m_pAll->vt->GetBuffer(this->m_pDS_Filter->m_pAll, &sample, 0, 0, 0); |
157 if (!sample) | |
1545 | 158 { |
2069 | 159 Debug printf("DS_AudioDecoder::Convert() Error: null sample\n"); |
1545 | 160 break; |
161 } | |
3466 | 162 sample->vt->SetActualDataLength(sample, this->in_fmt.nBlockAlign); |
1545 | 163 sample->vt->GetPointer(sample, (BYTE **)&ptr); |
3059 | 164 memcpy(ptr, (const uint8_t*)in_data + read, this->in_fmt.nBlockAlign); |
165 sample->vt->SetSyncPoint(sample, 1); | |
1545 | 166 sample->vt->SetPreroll(sample, 0); |
3059 | 167 result = this->m_pDS_Filter->m_pImp->vt->Receive(this->m_pDS_Filter->m_pImp, sample); |
1545 | 168 if (result) |
169 Debug printf("DS_AudioDecoder::Convert() Error: putting data into input pin %x\n", result); | |
170 if ((written + frame_size) > out_size) | |
171 { | |
172 sample->vt->Release((IUnknown*)sample); | |
173 break; | |
174 } | |
175 memcpy((uint8_t*)out_data + written, frame_pointer, frame_size); | |
176 sample->vt->Release((IUnknown*)sample); | |
3059 | 177 read+=this->in_fmt.nBlockAlign; |
1545 | 178 written+=frame_size; |
3466 | 179 break; |
1545 | 180 } |
181 if (size_read) | |
182 *size_read = read; | |
183 if (size_written) | |
184 *size_written = written; | |
185 return 0; | |
186 } | |
187 | |
3059 | 188 int DS_AudioDecoder_GetSrcSize(DS_AudioDecoder *this, int dest_size) |
1545 | 189 { |
3059 | 190 double efficiency =(double) this->in_fmt.nAvgBytesPerSec |
191 / (this->in_fmt.nSamplesPerSec*this->in_fmt.nBlockAlign); | |
192 int frames = (int)(dest_size*efficiency);; | |
193 | |
1545 | 194 if (frames < 1) |
195 frames = 1; | |
3059 | 196 return frames * this->in_fmt.nBlockAlign; |
1545 | 197 } |