annotate loader/dshow/DS_AudioDecoder.c @ 3445:0493b9edc4d5

similar to 1.18
author jaf
date Mon, 10 Dec 2001 21:56:21 +0000
parents 0c0042de1f95
children b6caac381405
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1545
da26060c81ef big avifile sync - from now we have common code
arpi
parents:
diff changeset
1 /********************************************************
da26060c81ef big avifile sync - from now we have common code
arpi
parents:
diff changeset
2
da26060c81ef big avifile sync - from now we have common code
arpi
parents:
diff changeset
3 DirectShow audio decoder
da26060c81ef big avifile sync - from now we have common code
arpi
parents:
diff changeset
4 Copyright 2001 Eugene Kuznetsov (divx@euro.ru)
da26060c81ef big avifile sync - from now we have common code
arpi
parents:
diff changeset
5
da26060c81ef big avifile sync - from now we have common code
arpi
parents:
diff changeset
6 *********************************************************/
da26060c81ef big avifile sync - from now we have common code
arpi
parents:
diff changeset
7
2069
ce45cce7f7a5 sync with avifile
arpi
parents: 1545
diff changeset
8 #include "DS_AudioDecoder.h"
ce45cce7f7a5 sync with avifile
arpi
parents: 1545
diff changeset
9 #include <string.h>
ce45cce7f7a5 sync with avifile
arpi
parents: 1545
diff changeset
10 #include <stdio.h>
3059
24fa494bedb1 imported from xine
arpi
parents: 2072
diff changeset
11 #include <stdlib.h>
2069
ce45cce7f7a5 sync with avifile
arpi
parents: 1545
diff changeset
12
1545
da26060c81ef big avifile sync - from now we have common code
arpi
parents:
diff changeset
13 #define __MODULE__ "DirectShow audio decoder"
da26060c81ef big avifile sync - from now we have common code
arpi
parents:
diff changeset
14 const GUID FORMAT_WaveFormatEx = {
da26060c81ef big avifile sync - from now we have common code
arpi
parents:
diff changeset
15 0x05589f81, 0xc356, 0x11CE,
da26060c81ef big avifile sync - from now we have common code
arpi
parents:
diff changeset
16 { 0xBF, 0x01, 0x00, 0xAA, 0x00, 0x55, 0x59, 0x5A }
da26060c81ef big avifile sync - from now we have common code
arpi
parents:
diff changeset
17 };
da26060c81ef big avifile sync - from now we have common code
arpi
parents:
diff changeset
18 const GUID MEDIATYPE_Audio = {
da26060c81ef big avifile sync - from now we have common code
arpi
parents:
diff changeset
19 0x73647561, 0x0000, 0x0010,
da26060c81ef big avifile sync - from now we have common code
arpi
parents:
diff changeset
20 { 0x80, 0x00, 0x00, 0xAA, 0x00, 0x38, 0x9B, 0x71 }
da26060c81ef big avifile sync - from now we have common code
arpi
parents:
diff changeset
21 };
da26060c81ef big avifile sync - from now we have common code
arpi
parents:
diff changeset
22 const GUID MEDIASUBTYPE_PCM = {
da26060c81ef big avifile sync - from now we have common code
arpi
parents:
diff changeset
23 0x00000001, 0x0000, 0x0010,
da26060c81ef big avifile sync - from now we have common code
arpi
parents:
diff changeset
24 { 0x80, 0x00, 0x00, 0xAA, 0x00, 0x38, 0x9B, 0x71 }
da26060c81ef big avifile sync - from now we have common code
arpi
parents:
diff changeset
25 };
da26060c81ef big avifile sync - from now we have common code
arpi
parents:
diff changeset
26
da26060c81ef big avifile sync - from now we have common code
arpi
parents:
diff changeset
27 typedef long STDCALL (*GETCLASS) (GUID*, GUID*, void**);
da26060c81ef big avifile sync - from now we have common code
arpi
parents:
diff changeset
28
3444
0c0042de1f95 API changes - now fully compatible with C++ version
arpi
parents: 3063
diff changeset
29 DS_AudioDecoder * DS_AudioDecoder_Open(char* dllname, GUID* guid, WAVEFORMATEX* wf)
0c0042de1f95 API changes - now fully compatible with C++ version
arpi
parents: 3063
diff changeset
30 //DS_AudioDecoder * DS_AudioDecoder_Create(const CodecInfo * info, const WAVEFORMATEX* wf)
1545
da26060c81ef big avifile sync - from now we have common code
arpi
parents:
diff changeset
31 {
3059
24fa494bedb1 imported from xine
arpi
parents: 2072
diff changeset
32 DS_AudioDecoder *this;
24fa494bedb1 imported from xine
arpi
parents: 2072
diff changeset
33 int sz;
24fa494bedb1 imported from xine
arpi
parents: 2072
diff changeset
34 WAVEFORMATEX* pWF;
3444
0c0042de1f95 API changes - now fully compatible with C++ version
arpi
parents: 3063
diff changeset
35
0c0042de1f95 API changes - now fully compatible with C++ version
arpi
parents: 3063
diff changeset
36 Setup_LDT_Keeper();
0c0042de1f95 API changes - now fully compatible with C++ version
arpi
parents: 3063
diff changeset
37 Setup_FS_Segment();
3059
24fa494bedb1 imported from xine
arpi
parents: 2072
diff changeset
38
24fa494bedb1 imported from xine
arpi
parents: 2072
diff changeset
39 this = malloc(sizeof(DS_AudioDecoder));
24fa494bedb1 imported from xine
arpi
parents: 2072
diff changeset
40
24fa494bedb1 imported from xine
arpi
parents: 2072
diff changeset
41 sz = 18 + wf->cbSize;
24fa494bedb1 imported from xine
arpi
parents: 2072
diff changeset
42 this->m_sVhdr = malloc(sz);
24fa494bedb1 imported from xine
arpi
parents: 2072
diff changeset
43 memcpy(this->m_sVhdr, wf, sz);
24fa494bedb1 imported from xine
arpi
parents: 2072
diff changeset
44 this->m_sVhdr2 = malloc(sz);
24fa494bedb1 imported from xine
arpi
parents: 2072
diff changeset
45 memcpy(this->m_sVhdr2, this->m_sVhdr, sz);
24fa494bedb1 imported from xine
arpi
parents: 2072
diff changeset
46
24fa494bedb1 imported from xine
arpi
parents: 2072
diff changeset
47 pWF = (WAVEFORMATEX*)this->m_sVhdr2;
24fa494bedb1 imported from xine
arpi
parents: 2072
diff changeset
48 pWF->wFormatTag = 1;
24fa494bedb1 imported from xine
arpi
parents: 2072
diff changeset
49 pWF->wBitsPerSample = 16;
24fa494bedb1 imported from xine
arpi
parents: 2072
diff changeset
50 pWF->nBlockAlign = 2*pWF->nChannels;
24fa494bedb1 imported from xine
arpi
parents: 2072
diff changeset
51 pWF->cbSize = 0;
24fa494bedb1 imported from xine
arpi
parents: 2072
diff changeset
52
24fa494bedb1 imported from xine
arpi
parents: 2072
diff changeset
53 memcpy(&this->in_fmt,wf,sizeof(WAVEFORMATEX));
1545
da26060c81ef big avifile sync - from now we have common code
arpi
parents:
diff changeset
54
3059
24fa494bedb1 imported from xine
arpi
parents: 2072
diff changeset
55 memset(&this->m_sOurType, 0, sizeof(this->m_sOurType));
24fa494bedb1 imported from xine
arpi
parents: 2072
diff changeset
56 this->m_sOurType.majortype=MEDIATYPE_Audio;
24fa494bedb1 imported from xine
arpi
parents: 2072
diff changeset
57 this->m_sOurType.subtype=MEDIASUBTYPE_PCM;
24fa494bedb1 imported from xine
arpi
parents: 2072
diff changeset
58 this->m_sOurType.subtype.f1=wf->wFormatTag;
24fa494bedb1 imported from xine
arpi
parents: 2072
diff changeset
59 this->m_sOurType.formattype=FORMAT_WaveFormatEx;
24fa494bedb1 imported from xine
arpi
parents: 2072
diff changeset
60 this->m_sOurType.lSampleSize=wf->nBlockAlign;
24fa494bedb1 imported from xine
arpi
parents: 2072
diff changeset
61 this->m_sOurType.bFixedSizeSamples=1;
24fa494bedb1 imported from xine
arpi
parents: 2072
diff changeset
62 this->m_sOurType.bTemporalCompression=0;
24fa494bedb1 imported from xine
arpi
parents: 2072
diff changeset
63 this->m_sOurType.pUnk=0;
24fa494bedb1 imported from xine
arpi
parents: 2072
diff changeset
64 this->m_sOurType.cbFormat=sz;
24fa494bedb1 imported from xine
arpi
parents: 2072
diff changeset
65 this->m_sOurType.pbFormat=this->m_sVhdr;
1545
da26060c81ef big avifile sync - from now we have common code
arpi
parents:
diff changeset
66
3059
24fa494bedb1 imported from xine
arpi
parents: 2072
diff changeset
67 memset(&this->m_sDestType, 0, sizeof(this->m_sDestType));
24fa494bedb1 imported from xine
arpi
parents: 2072
diff changeset
68 this->m_sDestType.majortype=MEDIATYPE_Audio;
24fa494bedb1 imported from xine
arpi
parents: 2072
diff changeset
69 this->m_sDestType.subtype=MEDIASUBTYPE_PCM;
24fa494bedb1 imported from xine
arpi
parents: 2072
diff changeset
70 this->m_sDestType.subtype.f1=pWF->wFormatTag;
24fa494bedb1 imported from xine
arpi
parents: 2072
diff changeset
71 this->m_sDestType.formattype=FORMAT_WaveFormatEx;
24fa494bedb1 imported from xine
arpi
parents: 2072
diff changeset
72 this->m_sDestType.bFixedSizeSamples=1;
24fa494bedb1 imported from xine
arpi
parents: 2072
diff changeset
73 this->m_sDestType.bTemporalCompression=0;
24fa494bedb1 imported from xine
arpi
parents: 2072
diff changeset
74 this->m_sDestType.lSampleSize=2*wf->nChannels;
24fa494bedb1 imported from xine
arpi
parents: 2072
diff changeset
75 this->m_sDestType.pUnk=0;
24fa494bedb1 imported from xine
arpi
parents: 2072
diff changeset
76 this->m_sDestType.cbFormat=pWF->cbSize;
24fa494bedb1 imported from xine
arpi
parents: 2072
diff changeset
77 this->m_sDestType.pbFormat=this->m_sVhdr2;
1545
da26060c81ef big avifile sync - from now we have common code
arpi
parents:
diff changeset
78
3059
24fa494bedb1 imported from xine
arpi
parents: 2072
diff changeset
79 /*try*/
1545
da26060c81ef big avifile sync - from now we have common code
arpi
parents:
diff changeset
80 {
3059
24fa494bedb1 imported from xine
arpi
parents: 2072
diff changeset
81 ALLOCATOR_PROPERTIES props, props1;
3444
0c0042de1f95 API changes - now fully compatible with C++ version
arpi
parents: 3063
diff changeset
82 this->m_pDS_Filter = DS_FilterCreate(dllname, guid, &this->m_sOurType, &this->m_sDestType);
3059
24fa494bedb1 imported from xine
arpi
parents: 2072
diff changeset
83 if( !this->m_pDS_Filter ) {
24fa494bedb1 imported from xine
arpi
parents: 2072
diff changeset
84 free(this);
24fa494bedb1 imported from xine
arpi
parents: 2072
diff changeset
85 return NULL;
24fa494bedb1 imported from xine
arpi
parents: 2072
diff changeset
86 }
24fa494bedb1 imported from xine
arpi
parents: 2072
diff changeset
87
3063
004e3199fee0 mplayer integration
arpi
parents: 3059
diff changeset
88 this->m_pDS_Filter->Start(this->m_pDS_Filter);
1545
da26060c81ef big avifile sync - from now we have common code
arpi
parents:
diff changeset
89
da26060c81ef big avifile sync - from now we have common code
arpi
parents:
diff changeset
90 props.cBuffers=1;
3059
24fa494bedb1 imported from xine
arpi
parents: 2072
diff changeset
91 props.cbBuffer=this->m_sOurType.lSampleSize;
1545
da26060c81ef big avifile sync - from now we have common code
arpi
parents:
diff changeset
92 props.cbAlign=props.cbPrefix=0;
3059
24fa494bedb1 imported from xine
arpi
parents: 2072
diff changeset
93 this->m_pDS_Filter->m_pAll->vt->SetProperties(this->m_pDS_Filter->m_pAll, &props, &props1);
24fa494bedb1 imported from xine
arpi
parents: 2072
diff changeset
94 this->m_pDS_Filter->m_pAll->vt->Commit(this->m_pDS_Filter->m_pAll);
1545
da26060c81ef big avifile sync - from now we have common code
arpi
parents:
diff changeset
95 }
3059
24fa494bedb1 imported from xine
arpi
parents: 2072
diff changeset
96 /*
24fa494bedb1 imported from xine
arpi
parents: 2072
diff changeset
97 catch (FatalError& e)
1545
da26060c81ef big avifile sync - from now we have common code
arpi
parents:
diff changeset
98 {
da26060c81ef big avifile sync - from now we have common code
arpi
parents:
diff changeset
99 e.PrintAll();
da26060c81ef big avifile sync - from now we have common code
arpi
parents:
diff changeset
100 delete[] m_sVhdr;
da26060c81ef big avifile sync - from now we have common code
arpi
parents:
diff changeset
101 delete[] m_sVhdr2;
da26060c81ef big avifile sync - from now we have common code
arpi
parents:
diff changeset
102 delete m_pDS_Filter;
da26060c81ef big avifile sync - from now we have common code
arpi
parents:
diff changeset
103 throw;
da26060c81ef big avifile sync - from now we have common code
arpi
parents:
diff changeset
104 }
3059
24fa494bedb1 imported from xine
arpi
parents: 2072
diff changeset
105 */
24fa494bedb1 imported from xine
arpi
parents: 2072
diff changeset
106 return this;
1545
da26060c81ef big avifile sync - from now we have common code
arpi
parents:
diff changeset
107 }
da26060c81ef big avifile sync - from now we have common code
arpi
parents:
diff changeset
108
3059
24fa494bedb1 imported from xine
arpi
parents: 2072
diff changeset
109 void DS_AudioDecoder_Destroy(DS_AudioDecoder *this)
1545
da26060c81ef big avifile sync - from now we have common code
arpi
parents:
diff changeset
110 {
3059
24fa494bedb1 imported from xine
arpi
parents: 2072
diff changeset
111 free(this->m_sVhdr);
24fa494bedb1 imported from xine
arpi
parents: 2072
diff changeset
112 free(this->m_sVhdr2);
24fa494bedb1 imported from xine
arpi
parents: 2072
diff changeset
113 DS_Filter_Destroy(this->m_pDS_Filter);
24fa494bedb1 imported from xine
arpi
parents: 2072
diff changeset
114 free(this);
1545
da26060c81ef big avifile sync - from now we have common code
arpi
parents:
diff changeset
115 }
da26060c81ef big avifile sync - from now we have common code
arpi
parents:
diff changeset
116
3059
24fa494bedb1 imported from xine
arpi
parents: 2072
diff changeset
117 int DS_AudioDecoder_Convert(DS_AudioDecoder *this, const void* in_data, uint_t in_size,
24fa494bedb1 imported from xine
arpi
parents: 2072
diff changeset
118 void* out_data, uint_t out_size,
24fa494bedb1 imported from xine
arpi
parents: 2072
diff changeset
119 uint_t* size_read, uint_t* size_written)
1545
da26060c81ef big avifile sync - from now we have common code
arpi
parents:
diff changeset
120 {
3059
24fa494bedb1 imported from xine
arpi
parents: 2072
diff changeset
121 uint_t written = 0;
24fa494bedb1 imported from xine
arpi
parents: 2072
diff changeset
122 uint_t read = 0;
24fa494bedb1 imported from xine
arpi
parents: 2072
diff changeset
123
1545
da26060c81ef big avifile sync - from now we have common code
arpi
parents:
diff changeset
124 if (!in_data || !out_data)
da26060c81ef big avifile sync - from now we have common code
arpi
parents:
diff changeset
125 return -1;
da26060c81ef big avifile sync - from now we have common code
arpi
parents:
diff changeset
126
3444
0c0042de1f95 API changes - now fully compatible with C++ version
arpi
parents: 3063
diff changeset
127 Setup_FS_Segment();
0c0042de1f95 API changes - now fully compatible with C++ version
arpi
parents: 3063
diff changeset
128
3059
24fa494bedb1 imported from xine
arpi
parents: 2072
diff changeset
129 in_size -= in_size%this->in_fmt.nBlockAlign;
1545
da26060c81ef big avifile sync - from now we have common code
arpi
parents:
diff changeset
130 while (in_size>0)
da26060c81ef big avifile sync - from now we have common code
arpi
parents:
diff changeset
131 {
3059
24fa494bedb1 imported from xine
arpi
parents: 2072
diff changeset
132 uint_t frame_size = 0;
1545
da26060c81ef big avifile sync - from now we have common code
arpi
parents:
diff changeset
133 char* frame_pointer;
da26060c81ef big avifile sync - from now we have common code
arpi
parents:
diff changeset
134 IMediaSample* sample=0;
3059
24fa494bedb1 imported from xine
arpi
parents: 2072
diff changeset
135 char* ptr;
24fa494bedb1 imported from xine
arpi
parents: 2072
diff changeset
136 int result;
24fa494bedb1 imported from xine
arpi
parents: 2072
diff changeset
137
24fa494bedb1 imported from xine
arpi
parents: 2072
diff changeset
138 // this->m_pOurOutput->SetFramePointer(out_data+written);
3063
004e3199fee0 mplayer integration
arpi
parents: 3059
diff changeset
139 this->m_pDS_Filter->m_pOurOutput->SetFramePointer(this->m_pDS_Filter->m_pOurOutput,&frame_pointer);
004e3199fee0 mplayer integration
arpi
parents: 3059
diff changeset
140 this->m_pDS_Filter->m_pOurOutput->SetFrameSizePointer(this->m_pDS_Filter->m_pOurOutput,(long*)&frame_size);
3059
24fa494bedb1 imported from xine
arpi
parents: 2072
diff changeset
141 this->m_pDS_Filter->m_pAll->vt->GetBuffer(this->m_pDS_Filter->m_pAll, &sample, 0, 0, 0);
24fa494bedb1 imported from xine
arpi
parents: 2072
diff changeset
142 if (!sample)
1545
da26060c81ef big avifile sync - from now we have common code
arpi
parents:
diff changeset
143 {
2069
ce45cce7f7a5 sync with avifile
arpi
parents: 1545
diff changeset
144 Debug printf("DS_AudioDecoder::Convert() Error: null sample\n");
1545
da26060c81ef big avifile sync - from now we have common code
arpi
parents:
diff changeset
145 break;
da26060c81ef big avifile sync - from now we have common code
arpi
parents:
diff changeset
146 }
da26060c81ef big avifile sync - from now we have common code
arpi
parents:
diff changeset
147 sample->vt->GetPointer(sample, (BYTE **)&ptr);
3059
24fa494bedb1 imported from xine
arpi
parents: 2072
diff changeset
148 memcpy(ptr, (const uint8_t*)in_data + read, this->in_fmt.nBlockAlign);
24fa494bedb1 imported from xine
arpi
parents: 2072
diff changeset
149 sample->vt->SetActualDataLength(sample, this->in_fmt.nBlockAlign);
24fa494bedb1 imported from xine
arpi
parents: 2072
diff changeset
150 sample->vt->SetSyncPoint(sample, 1);
1545
da26060c81ef big avifile sync - from now we have common code
arpi
parents:
diff changeset
151 sample->vt->SetPreroll(sample, 0);
3059
24fa494bedb1 imported from xine
arpi
parents: 2072
diff changeset
152 result = this->m_pDS_Filter->m_pImp->vt->Receive(this->m_pDS_Filter->m_pImp, sample);
1545
da26060c81ef big avifile sync - from now we have common code
arpi
parents:
diff changeset
153 if (result)
da26060c81ef big avifile sync - from now we have common code
arpi
parents:
diff changeset
154 Debug printf("DS_AudioDecoder::Convert() Error: putting data into input pin %x\n", result);
da26060c81ef big avifile sync - from now we have common code
arpi
parents:
diff changeset
155 if ((written + frame_size) > out_size)
da26060c81ef big avifile sync - from now we have common code
arpi
parents:
diff changeset
156 {
da26060c81ef big avifile sync - from now we have common code
arpi
parents:
diff changeset
157 sample->vt->Release((IUnknown*)sample);
da26060c81ef big avifile sync - from now we have common code
arpi
parents:
diff changeset
158 break;
da26060c81ef big avifile sync - from now we have common code
arpi
parents:
diff changeset
159 }
da26060c81ef big avifile sync - from now we have common code
arpi
parents:
diff changeset
160 memcpy((uint8_t*)out_data + written, frame_pointer, frame_size);
da26060c81ef big avifile sync - from now we have common code
arpi
parents:
diff changeset
161 sample->vt->Release((IUnknown*)sample);
3059
24fa494bedb1 imported from xine
arpi
parents: 2072
diff changeset
162 read+=this->in_fmt.nBlockAlign;
1545
da26060c81ef big avifile sync - from now we have common code
arpi
parents:
diff changeset
163 written+=frame_size;
da26060c81ef big avifile sync - from now we have common code
arpi
parents:
diff changeset
164 }
da26060c81ef big avifile sync - from now we have common code
arpi
parents:
diff changeset
165 if (size_read)
da26060c81ef big avifile sync - from now we have common code
arpi
parents:
diff changeset
166 *size_read = read;
da26060c81ef big avifile sync - from now we have common code
arpi
parents:
diff changeset
167 if (size_written)
da26060c81ef big avifile sync - from now we have common code
arpi
parents:
diff changeset
168 *size_written = written;
da26060c81ef big avifile sync - from now we have common code
arpi
parents:
diff changeset
169 return 0;
da26060c81ef big avifile sync - from now we have common code
arpi
parents:
diff changeset
170 }
da26060c81ef big avifile sync - from now we have common code
arpi
parents:
diff changeset
171
3059
24fa494bedb1 imported from xine
arpi
parents: 2072
diff changeset
172 int DS_AudioDecoder_GetSrcSize(DS_AudioDecoder *this, int dest_size)
1545
da26060c81ef big avifile sync - from now we have common code
arpi
parents:
diff changeset
173 {
3059
24fa494bedb1 imported from xine
arpi
parents: 2072
diff changeset
174 double efficiency =(double) this->in_fmt.nAvgBytesPerSec
24fa494bedb1 imported from xine
arpi
parents: 2072
diff changeset
175 / (this->in_fmt.nSamplesPerSec*this->in_fmt.nBlockAlign);
24fa494bedb1 imported from xine
arpi
parents: 2072
diff changeset
176 int frames = (int)(dest_size*efficiency);;
24fa494bedb1 imported from xine
arpi
parents: 2072
diff changeset
177
1545
da26060c81ef big avifile sync - from now we have common code
arpi
parents:
diff changeset
178 if (frames < 1)
da26060c81ef big avifile sync - from now we have common code
arpi
parents:
diff changeset
179 frames = 1;
3059
24fa494bedb1 imported from xine
arpi
parents: 2072
diff changeset
180 return frames * this->in_fmt.nBlockAlign;
1545
da26060c81ef big avifile sync - from now we have common code
arpi
parents:
diff changeset
181 }