Mercurial > mplayer.hg
annotate loader/dmo/DMO_AudioDecoder.c @ 18313:b73c04429a00
EDL no longer conditionally compiled.
author | diego |
---|---|
date | Thu, 27 Apr 2006 13:10:38 +0000 |
parents | d026c9bb2938 |
children | 2934974c366a |
rev | line source |
---|---|
8325 | 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:
8451
diff
changeset
|
7 #include "config.h" |
8325 | 8 #ifndef NOAVIFILE_HEADERS |
9 #include "audiodecoder.h" | |
10 #include "except.h" | |
11 #else | |
12 #include "libwin32.h" | |
9967
b0d1b415320c
cygwin support patch by Sascha Sommer and some fixes by me
alex
parents:
8451
diff
changeset
|
13 #ifdef WIN32_LOADER |
8451 | 14 #include "ldt_keeper.h" |
8325 | 15 #endif |
9967
b0d1b415320c
cygwin support patch by Sascha Sommer and some fixes by me
alex
parents:
8451
diff
changeset
|
16 #endif |
8325 | 17 |
18 #include "DMO_Filter.h" | |
19 #include "DMO_AudioDecoder.h" | |
20 | |
21 struct _DMO_AudioDecoder | |
22 { | |
23 DMO_MEDIA_TYPE m_sOurType, m_sDestType; | |
24 DMO_Filter* m_pDMO_Filter; | |
25 char* m_sVhdr; | |
26 char* m_sVhdr2; | |
27 int m_iFlushed; | |
28 }; | |
29 | |
30 #include "DMO_AudioDecoder.h" | |
31 | |
32 #include <string.h> | |
33 #include <stdio.h> | |
34 #include <stdlib.h> | |
35 | |
17978 | 36 #include "../../mp_msg.h" |
37 | |
8325 | 38 #define __MODULE__ "DirectShow audio decoder" |
39 | |
40 typedef long STDCALL (*GETCLASS) (GUID*, GUID*, void**); | |
17977
f70772d02eaa
Convert printfs in aviprint.c to mp_msg and give the information printing
diego
parents:
9967
diff
changeset
|
41 extern void print_wave_header(WAVEFORMATEX *h, int verbose_level); |
8325 | 42 |
43 DMO_AudioDecoder * DMO_AudioDecoder_Open(char* dllname, GUID* guid, WAVEFORMATEX* wf,int out_channels) | |
44 //DMO_AudioDecoder * DMO_AudioDecoder_Create(const CodecInfo * info, const WAVEFORMATEX* wf) | |
45 { | |
46 DMO_AudioDecoder *this; | |
47 int sz; | |
48 WAVEFORMATEX* pWF; | |
49 | |
9967
b0d1b415320c
cygwin support patch by Sascha Sommer and some fixes by me
alex
parents:
8451
diff
changeset
|
50 #ifdef WIN32_LOADER |
8325 | 51 Setup_LDT_Keeper(); |
52 Setup_FS_Segment(); | |
9967
b0d1b415320c
cygwin support patch by Sascha Sommer and some fixes by me
alex
parents:
8451
diff
changeset
|
53 #endif |
8325 | 54 |
55 this = malloc(sizeof(DMO_AudioDecoder)); | |
56 | |
57 this->m_iFlushed=1; | |
58 | |
59 sz = 18 + wf->cbSize; | |
60 this->m_sVhdr = malloc(sz); | |
61 memcpy(this->m_sVhdr, wf, sz); | |
62 this->m_sVhdr2 = malloc(18); | |
63 memcpy(this->m_sVhdr2, this->m_sVhdr, 18); | |
64 | |
65 pWF = (WAVEFORMATEX*)this->m_sVhdr2; | |
66 pWF->wFormatTag = 1; | |
67 pWF->wBitsPerSample = 16; | |
68 pWF->nChannels = out_channels; | |
69 pWF->nBlockAlign = 2*pWF->nChannels; //pWF->nChannels * (pWF->wBitsPerSample + 7) / 8; | |
70 pWF->nAvgBytesPerSec = pWF->nBlockAlign * pWF->nSamplesPerSec; | |
71 pWF->cbSize = 0; | |
72 | |
73 memset(&this->m_sOurType, 0, sizeof(this->m_sOurType)); | |
74 this->m_sOurType.majortype=MEDIATYPE_Audio; | |
75 this->m_sOurType.subtype=MEDIASUBTYPE_PCM; | |
76 this->m_sOurType.subtype.f1=wf->wFormatTag; | |
77 this->m_sOurType.formattype=FORMAT_WaveFormatEx; | |
78 this->m_sOurType.lSampleSize=wf->nBlockAlign; | |
79 this->m_sOurType.bFixedSizeSamples=1; | |
80 this->m_sOurType.bTemporalCompression=0; | |
81 this->m_sOurType.cbFormat=sz; | |
82 this->m_sOurType.pbFormat=this->m_sVhdr; | |
83 | |
84 memset(&this->m_sDestType, 0, sizeof(this->m_sDestType)); | |
85 this->m_sDestType.majortype=MEDIATYPE_Audio; | |
86 this->m_sDestType.subtype=MEDIASUBTYPE_PCM; | |
87 this->m_sDestType.formattype=FORMAT_WaveFormatEx; | |
88 this->m_sDestType.bFixedSizeSamples=1; | |
89 this->m_sDestType.bTemporalCompression=0; | |
90 this->m_sDestType.lSampleSize=pWF->nBlockAlign; | |
91 this->m_sDestType.cbFormat=18; //pWF->cbSize; | |
92 this->m_sDestType.pbFormat=this->m_sVhdr2; | |
93 | |
17977
f70772d02eaa
Convert printfs in aviprint.c to mp_msg and give the information printing
diego
parents:
9967
diff
changeset
|
94 print_wave_header((WAVEFORMATEX *)this->m_sVhdr, MSGL_V); |
f70772d02eaa
Convert printfs in aviprint.c to mp_msg and give the information printing
diego
parents:
9967
diff
changeset
|
95 print_wave_header((WAVEFORMATEX *)this->m_sVhdr2, MSGL_V); |
8325 | 96 |
97 this->m_pDMO_Filter = DMO_FilterCreate(dllname, guid, &this->m_sOurType, &this->m_sDestType); | |
98 if( !this->m_pDMO_Filter ) { | |
99 free(this); | |
100 return NULL; | |
101 } | |
102 | |
103 return this; | |
104 } | |
105 | |
106 void DMO_AudioDecoder_Destroy(DMO_AudioDecoder *this) | |
107 { | |
108 free(this->m_sVhdr); | |
109 free(this->m_sVhdr2); | |
110 DMO_Filter_Destroy(this->m_pDMO_Filter); | |
111 free(this); | |
112 } | |
113 | |
114 int DMO_AudioDecoder_Convert(DMO_AudioDecoder *this, const void* in_data, unsigned int in_size, | |
115 void* out_data, unsigned int out_size, | |
116 unsigned int* size_read, unsigned int* size_written) | |
117 { | |
118 DMO_OUTPUT_DATA_BUFFER db; | |
119 CMediaBuffer* bufferin; | |
8451 | 120 unsigned long written = 0; |
121 unsigned long read = 0; | |
8325 | 122 int r = 0; |
123 | |
124 if (!in_data || !out_data) | |
125 return -1; | |
126 | |
9967
b0d1b415320c
cygwin support patch by Sascha Sommer and some fixes by me
alex
parents:
8451
diff
changeset
|
127 #ifdef WIN32_LOADER |
8325 | 128 Setup_FS_Segment(); |
9967
b0d1b415320c
cygwin support patch by Sascha Sommer and some fixes by me
alex
parents:
8451
diff
changeset
|
129 #endif |
8325 | 130 |
131 //m_pDMO_Filter->m_pMedia->vt->Lock(m_pDMO_Filter->m_pMedia, 1); | |
132 bufferin = CMediaBufferCreate(in_size, (void*)in_data, in_size, 1); | |
133 r = this->m_pDMO_Filter->m_pMedia->vt->ProcessInput(this->m_pDMO_Filter->m_pMedia, 0, | |
134 (IMediaBuffer*)bufferin, | |
135 (this->m_iFlushed) ? DMO_INPUT_DATA_BUFFERF_SYNCPOINT : 0, | |
136 0, 0); | |
137 if (r == 0){ | |
138 ((IMediaBuffer*)bufferin)->vt->GetBufferAndLength((IMediaBuffer*)bufferin, 0, &read); | |
139 this->m_iFlushed = 0; | |
140 } | |
141 | |
142 ((IMediaBuffer*)bufferin)->vt->Release((IUnknown*)bufferin); | |
143 | |
144 //printf("RESULTA: %d 0x%x %ld %d %d\n", r, r, read, m_iFlushed, out_size); | |
145 if (r == 0 || (unsigned)r == DMO_E_NOTACCEPTING){ | |
146 unsigned long status = 0; | |
147 /* something for process */ | |
148 db.rtTimestamp = 0; | |
149 db.rtTimelength = 0; | |
150 db.dwStatus = 0; | |
151 db.pBuffer = (IMediaBuffer*) CMediaBufferCreate(out_size, out_data, 0, 0); | |
152 //printf("OUTSIZE %d\n", out_size); | |
153 r = this->m_pDMO_Filter->m_pMedia->vt->ProcessOutput(this->m_pDMO_Filter->m_pMedia, | |
154 0, 1, &db, &status); | |
155 | |
156 ((IMediaBuffer*)db.pBuffer)->vt->GetBufferAndLength((IMediaBuffer*)db.pBuffer, 0, &written); | |
157 ((IMediaBuffer*)db.pBuffer)->vt->Release((IUnknown*)db.pBuffer); | |
158 | |
159 //printf("RESULTB: %d 0x%x %ld\n", r, r, written); | |
160 //printf("Converted %d -> %d\n", in_size, out_size); | |
161 } | |
162 else if (in_size > 0) | |
163 printf("ProcessInputError r:0x%x=%d\n", r, r); | |
164 | |
165 if (size_read) | |
166 *size_read = read; | |
167 if (size_written) | |
168 *size_written = written; | |
169 return r; | |
170 } | |
171 | |
172 int DMO_AudioDecoder_GetSrcSize(DMO_AudioDecoder *this, int dest_size) | |
173 { | |
174 // unsigned long inputs, outputs; | |
175 // Setup_FS_Segment(); | |
176 // this->m_pDMO_Filter->m_pMedia->vt->GetOutputSizeInfo(this->m_pDMO_Filter->m_pMedia, 0, &inputs, &outputs); | |
177 return ((WAVEFORMATEX*)this->m_sVhdr)->nBlockAlign*4; | |
178 } |