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