comparison loader/dshow/DS_AudioDec.c @ 1545:da26060c81ef

big avifile sync - from now we have common code
author arpi
date Thu, 16 Aug 2001 00:50:02 +0000
parents 53f5b3b991f5
children a5a4143d5599
comparison
equal deleted inserted replaced
1544:558c1b03b8d0 1545:da26060c81ef
1 /********************************************************
2
3 DirectShow Audio decoder implementation
4 Copyright 2000 Eugene Kuznetsov (divx@euro.ru)
5 Converted C++ --> C :) by A'rpi/ESP-team
6
7 *********************************************************/
8
9 //#include <config.h>
10
11 //#include "DS_AudioDecoder.h"
12 //#include <string.h>
13 using namespace std;
14 #include <stdlib.h>
15 #include <except.h>
16 #define __MODULE__ "DirectShow_AudioDecoder"
17
18 #include <errno.h>
19 #ifdef HAVE_MALLOC_H
20 #include <malloc.h>
21 #endif
22 //#include <loader.h>
23 //#include <wine/winbase.h>
24 #include <stdio.h>
25 #include <unistd.h>
26 #include <fcntl.h>
27 #include <strstream>
28 #include <dlfcn.h>
29 #include <sys/types.h>
30 #include <sys/mman.h>
31
32 #include <registry.h>
33 #include <wine/winreg.h>
34 1
35 #include "guids.h" 2 #include "guids.h"
36 #include "interfaces.h" 3 #include "interfaces.h"
37 #include "DS_Filter.h"
38 4
39 #include "BitmapInfo.h" 5 #include "DS_AudioDecoder.h"
6 #include <wine/winerror.h>
7 #include <libwin32.h>
8 //#include <cpuinfo.h>
40 9
41 #include <string> 10 #include <unistd.h>
42 #include <default.h> 11 #include <fcntl.h>
12 #include <errno.h>
13 #include <sys/types.h>
14 #include <sys/mman.h>
15 #include <cstdio>
16 #include <iostream>
17 #include <strstream>
43 18
44 #include "DS_AudioDec.h" 19 #include "DS_AudioDec.h"
45 20
46 const GUID FORMAT_WaveFormatEx={ 21 // DS_Decoder(const CodecInfo& info, const WAVEFORMATEX*);
47 0x05589f81, 0xc356, 0x11ce, 0xbf, 0x01, 0x00, 0xaa, 0x00, 0x55, 0x59, 0x5a}; 22 // virtual ~DS_Decoder();
48 const GUID MEDIATYPE_Audio={ 23 // virtual int Convert(const void*, size_t, void*, size_t, size_t*, size_t*);
49 0x73647561, 0x0000, 0x0010, 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}; 24 // virtual int GetSrcSize(int);
50 const GUID MEDIASUBTYPE_PCM={
51 0x00000001, 0x0000, 0x0010, 0x80, 0x00, 0x00, 0xAA, 0x00, 0x38, 0x9B, 0x71};
52 25
26 static void* _handle;
53 27
54 extern "C" char* def_path; 28 extern "C" void Setup_LDT_Keeper();
29 extern "C" void setup_FS_Segment();
55 30
56 static DS_Filter* dsf=0; 31 extern "C" int DS_AudioDecoder_Open(char* dllname, GUID* guid, WAVEFORMATEX* wf){
57 32
58 static AM_MEDIA_TYPE m_sOurType, m_sDestType; 33 Setup_LDT_Keeper();
59 // static void* m_pCust; 34 setup_FS_Segment();
60 static char* m_sVhdr;
61 static char* m_sVhdr2;
62 35
63 static WAVEFORMATEX in_fmt; 36 CodecInfo ci;
37 ci.dll=dllname;
38 ci.guid=*guid;
64 39
65 // int m_iState=0; 40 DS_AudioDecoder* dec=new DS_AudioDecoder(ci, wf);
66 41 _handle=(void*)dec;
67 extern "C" int DS_AudioDecoder_Open(char* dllname, GUID* guid, WAVEFORMATEX* wf)
68 {
69
70 m_sVhdr=new char[18+wf->cbSize];
71 memcpy(m_sVhdr, wf, 18+wf->cbSize);
72 m_sVhdr2=new char[18];
73 memcpy(m_sVhdr2, m_sVhdr, 18);
74 WAVEFORMATEX* pWF=(WAVEFORMATEX*)m_sVhdr2;
75 pWF->wFormatTag=1;
76 pWF->wBitsPerSample=16;
77 pWF->nBlockAlign=2*pWF->nChannels;
78 pWF->cbSize=0;
79 in_fmt=*wf;
80
81 memset(&m_sOurType, 0, sizeof m_sOurType);
82 m_sOurType.majortype=MEDIATYPE_Audio;
83 m_sOurType.subtype=MEDIASUBTYPE_PCM;
84 m_sOurType.subtype.f1=wf->wFormatTag;
85 m_sOurType.formattype=FORMAT_WaveFormatEx;
86 m_sOurType.lSampleSize=wf->nBlockAlign;
87 m_sOurType.bFixedSizeSamples=true;
88 m_sOurType.bTemporalCompression=false;
89 m_sOurType.pUnk=0;
90 m_sOurType.cbFormat=18+wf->cbSize;
91 m_sOurType.pbFormat=m_sVhdr;
92
93 memset(&m_sDestType, 0, sizeof m_sDestType);
94 m_sDestType.majortype=MEDIATYPE_Audio;
95 m_sDestType.subtype=MEDIASUBTYPE_PCM;
96 m_sDestType.formattype=FORMAT_WaveFormatEx;
97 m_sDestType.bFixedSizeSamples=true;
98 m_sDestType.bTemporalCompression=false;
99 m_sDestType.lSampleSize=2*wf->nChannels;
100 m_sDestType.pUnk=0;
101 m_sDestType.cbFormat=18;
102 m_sDestType.pbFormat=m_sVhdr2;
103
104 try
105 {
106
107 dsf=new DS_Filter();
108 dsf->Create(dllname, guid, &m_sOurType, &m_sDestType);
109 dsf->Start();
110
111 ALLOCATOR_PROPERTIES props, props1;
112 props.cBuffers=1;
113 props.cbBuffer=m_sOurType.lSampleSize;
114 props.cbAlign=props.cbPrefix=0;
115 dsf->m_pAll->vt->SetProperties(dsf->m_pAll, &props, &props1);
116 dsf->m_pAll->vt->Commit(dsf->m_pAll);
117 }
118 catch(FatalError e)
119 {
120 e.PrintAll();
121 delete[] m_sVhdr;
122 delete[] m_sVhdr2;
123 return 1;
124 }
125 42
126 return 0; 43 return 0;
127 } 44 }
128 45
129 extern "C" void DS_AudioDecoder_Close(){ 46 extern "C" void DS_AudioDecoder_Close(){
130 delete[] m_sVhdr;
131 delete[] m_sVhdr2;
132 } 47 }
133 48
134 extern "C" int DS_AudioDecoder_GetSrcSize(int dest_size) 49 extern "C" int DS_AudioDecoder_GetSrcSize(int dest_size){
135 { 50 DS_AudioDecoder* dec=(DS_AudioDecoder*)_handle;
136 double efficiency=in_fmt.nAvgBytesPerSec/double(in_fmt.nSamplesPerSec*in_fmt.nBlockAlign); 51 return dec->GetSrcSize(dest_size);
137 int frames=(int)(dest_size*efficiency);
138 if(frames<1)frames=1;
139 return frames*in_fmt.nBlockAlign;
140 } 52 }
141
142 53
143 extern "C" int DS_AudioDecoder_Convert(unsigned char* in_data, unsigned in_size, 54 extern "C" int DS_AudioDecoder_Convert(unsigned char* in_data, unsigned in_size,
144 unsigned char* out_data, unsigned out_size, 55 unsigned char* out_data, unsigned out_size,
145 unsigned* size_read, unsigned* size_written) 56 unsigned* size_read, unsigned* size_written){
146 { 57 DS_AudioDecoder* dec=(DS_AudioDecoder*)_handle;
147 if(in_data==0)return -1; 58 setup_FS_Segment();
148 if(out_data==0)return -1; 59 return dec->Convert( (void*)in_data,(size_t)in_size,
149 int written=0; 60 (void*)out_data,(size_t)out_size,
150 int read=0; 61 (size_t*)size_read, (size_t*)size_written );
151 in_size-=in_size%in_fmt.nBlockAlign;
152 while(in_size>0)
153 {
154 long frame_size=0;
155 char* frame_pointer;
156 // m_pOurOutput->SetFramePointer(out_data+written);
157 dsf->m_pOurOutput->SetFramePointer(&frame_pointer);
158 dsf->m_pOurOutput->SetFrameSizePointer(&frame_size);
159 IMediaSample* sample=0;
160 dsf->m_pAll->vt->GetBuffer(dsf->m_pAll, &sample, 0, 0, 0);
161 if(!sample)
162 {
163 cerr<<"ERROR: null sample"<<endl;
164 break;
165 }
166 char* ptr;
167 sample->vt->GetPointer(sample, (BYTE **)&ptr);
168 memcpy(ptr, in_data+read, in_fmt.nBlockAlign);
169 sample->vt->SetActualDataLength(sample, in_fmt.nBlockAlign);
170 sample->vt->SetSyncPoint(sample, true);
171 sample->vt->SetPreroll(sample, 0);
172 int result=dsf->m_pImp->vt->Receive(dsf->m_pImp, sample);
173 if(result) printf("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(out_data+written, frame_pointer, frame_size);
180 sample->vt->Release((IUnknown*)sample);
181 read+=in_fmt.nBlockAlign;
182 written+=frame_size;
183 }
184 if(size_read) *size_read=read;
185 if(size_written) *size_written=written;
186 return 0;
187 } 62 }
188 63