1 /********************************************************
3 DirectShow audio decoder
4 Copyright 2001 Eugene Kuznetsov (divx@euro.ru)
6 *********************************************************/
8 #include "dshow/libwin32.h"
10 #include "ldt_keeper.h"
13 #include "DMO_Filter.h"
14 #include "DMO_AudioDecoder.h"
16 struct DMO_AudioDecoder
18 DMO_MEDIA_TYPE m_sOurType
, m_sDestType
;
19 DMO_Filter
* m_pDMO_Filter
;
25 #include "DMO_AudioDecoder.h"
33 typedef long STDCALL (*GETCLASS
) (GUID
*, GUID
*, void**);
34 void print_wave_header(WAVEFORMATEX
*h
, int verbose_level
);
36 DMO_AudioDecoder
* DMO_AudioDecoder_Open(char* dllname
, GUID
* guid
, WAVEFORMATEX
* wf
,int out_channels
)
37 //DMO_AudioDecoder * DMO_AudioDecoder_Create(const CodecInfo * info, const WAVEFORMATEX* wf)
39 DMO_AudioDecoder
*this;
48 this = malloc(sizeof(DMO_AudioDecoder
));
53 this->m_sVhdr
= malloc(sz
);
54 memcpy(this->m_sVhdr
, wf
, sz
);
55 this->m_sVhdr2
= malloc(18);
56 memcpy(this->m_sVhdr2
, this->m_sVhdr
, 18);
58 pWF
= (WAVEFORMATEX
*)this->m_sVhdr2
;
60 pWF
->wBitsPerSample
= 16;
61 pWF
->nChannels
= out_channels
;
62 pWF
->nBlockAlign
= 2*pWF
->nChannels
; //pWF->nChannels * (pWF->wBitsPerSample + 7) / 8;
63 pWF
->nAvgBytesPerSec
= pWF
->nBlockAlign
* pWF
->nSamplesPerSec
;
66 memset(&this->m_sOurType
, 0, sizeof(this->m_sOurType
));
67 this->m_sOurType
.majortype
=MEDIATYPE_Audio
;
68 this->m_sOurType
.subtype
=MEDIASUBTYPE_PCM
;
69 this->m_sOurType
.subtype
.f1
=wf
->wFormatTag
;
70 this->m_sOurType
.formattype
=FORMAT_WaveFormatEx
;
71 this->m_sOurType
.lSampleSize
=wf
->nBlockAlign
;
72 this->m_sOurType
.bFixedSizeSamples
=1;
73 this->m_sOurType
.bTemporalCompression
=0;
74 this->m_sOurType
.cbFormat
=sz
;
75 this->m_sOurType
.pbFormat
=this->m_sVhdr
;
77 memset(&this->m_sDestType
, 0, sizeof(this->m_sDestType
));
78 this->m_sDestType
.majortype
=MEDIATYPE_Audio
;
79 this->m_sDestType
.subtype
=MEDIASUBTYPE_PCM
;
80 this->m_sDestType
.formattype
=FORMAT_WaveFormatEx
;
81 this->m_sDestType
.bFixedSizeSamples
=1;
82 this->m_sDestType
.bTemporalCompression
=0;
83 this->m_sDestType
.lSampleSize
=pWF
->nBlockAlign
;
84 this->m_sDestType
.cbFormat
=18; //pWF->cbSize;
85 this->m_sDestType
.pbFormat
=this->m_sVhdr2
;
87 print_wave_header((WAVEFORMATEX
*)this->m_sVhdr
, MSGL_V
);
88 print_wave_header((WAVEFORMATEX
*)this->m_sVhdr2
, MSGL_V
);
90 this->m_pDMO_Filter
= DMO_FilterCreate(dllname
, guid
, &this->m_sOurType
, &this->m_sDestType
);
91 if( !this->m_pDMO_Filter
) {
99 void DMO_AudioDecoder_Destroy(DMO_AudioDecoder
*this)
102 free(this->m_sVhdr2
);
103 DMO_Filter_Destroy(this->m_pDMO_Filter
);
107 int DMO_AudioDecoder_Convert(DMO_AudioDecoder
*this, const void* in_data
, unsigned int in_size
,
108 void* out_data
, unsigned int out_size
,
109 unsigned int* size_read
, unsigned int* size_written
)
111 DMO_OUTPUT_DATA_BUFFER db
;
112 CMediaBuffer
* bufferin
;
113 unsigned long written
= 0;
114 unsigned long read
= 0;
117 if (!in_data
|| !out_data
)
124 //m_pDMO_Filter->m_pMedia->vt->Lock(m_pDMO_Filter->m_pMedia, 1);
125 bufferin
= CMediaBufferCreate(in_size
, (void*)in_data
, in_size
, 1);
126 r
= this->m_pDMO_Filter
->m_pMedia
->vt
->ProcessInput(this->m_pDMO_Filter
->m_pMedia
, 0,
127 (IMediaBuffer
*)bufferin
,
128 (this->m_iFlushed
) ? DMO_INPUT_DATA_BUFFERF_SYNCPOINT
: 0,
131 ((IMediaBuffer
*)bufferin
)->vt
->GetBufferAndLength((IMediaBuffer
*)bufferin
, 0, &read
);
132 this->m_iFlushed
= 0;
135 ((IMediaBuffer
*)bufferin
)->vt
->Release((IUnknown
*)bufferin
);
137 //printf("RESULTA: %d 0x%x %ld %d %d\n", r, r, read, m_iFlushed, out_size);
138 if (r
== 0 || (unsigned)r
== DMO_E_NOTACCEPTING
){
139 unsigned long status
= 0;
140 /* something for process */
144 db
.pBuffer
= (IMediaBuffer
*) CMediaBufferCreate(out_size
, out_data
, 0, 0);
145 //printf("OUTSIZE %d\n", out_size);
146 r
= this->m_pDMO_Filter
->m_pMedia
->vt
->ProcessOutput(this->m_pDMO_Filter
->m_pMedia
,
149 ((IMediaBuffer
*)db
.pBuffer
)->vt
->GetBufferAndLength((IMediaBuffer
*)db
.pBuffer
, 0, &written
);
150 ((IMediaBuffer
*)db
.pBuffer
)->vt
->Release((IUnknown
*)db
.pBuffer
);
152 //printf("RESULTB: %d 0x%x %ld\n", r, r, written);
153 //printf("Converted %d -> %d\n", in_size, out_size);
155 else if (in_size
> 0)
156 printf("ProcessInputError r:0x%x=%d\n", r
, r
);
161 *size_written
= written
;
165 int DMO_AudioDecoder_GetSrcSize(DMO_AudioDecoder
*this, int dest_size
)
167 // unsigned long inputs, outputs;
168 // Setup_FS_Segment();
169 // this->m_pDMO_Filter->m_pMedia->vt->GetOutputSizeInfo(this->m_pDMO_Filter->m_pMedia, 0, &inputs, &outputs);
170 return ((WAVEFORMATEX
*)this->m_sVhdr
)->nBlockAlign
*4;