00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 #include "stdafx.h"
00033 #include "abstractaudioencodeoutputpin.h"
00034
00035
00036
00037 AbstractAudioEncodeOutputPin::AbstractAudioEncodeOutputPin(AbstractAudioEncodeFilter* inParentFilter, CCritSec* inFilterLock, CHAR* inObjectName, LPCWSTR inPinDisplayName, CMediaType* inOutputMediaType)
00038 : CBaseOutputPin(inObjectName, inParentFilter, inFilterLock, &mHR, inPinDisplayName),
00039 mParentFilter(inParentFilter)
00040
00041 , mDataQueue(NULL)
00042 {
00043 mOutputMediaType = inOutputMediaType;
00044 }
00045 AbstractAudioEncodeOutputPin::~AbstractAudioEncodeOutputPin(void)
00046 {
00047
00048 delete mDataQueue;
00049
00050 }
00051 STDMETHODIMP AbstractAudioEncodeOutputPin::NonDelegatingQueryInterface(REFIID riid, void **ppv) {
00052 if (riid == IID_IMediaSeeking) {
00053 *ppv = (IMediaSeeking*)this;
00054 ((IUnknown*)*ppv)->AddRef();
00055 return NOERROR;
00056 }
00057
00058 return CBaseOutputPin::NonDelegatingQueryInterface(riid, ppv);
00059 }
00060
00061 HRESULT AbstractAudioEncodeOutputPin::DecideBufferSize(IMemAllocator* inAllocator, ALLOCATOR_PROPERTIES* inPropertyRequest) {
00062
00063
00064
00065
00066 HRESULT locHR = S_OK;
00067
00068
00069 ALLOCATOR_PROPERTIES locReqAlloc;
00070 ALLOCATOR_PROPERTIES locActualAlloc;
00071
00072 const unsigned long MIN_BUFFER_SIZE = 1096;
00073 const unsigned long DEFAULT_BUFFER_SIZE = 32192;
00074 const unsigned long MIN_NUM_BUFFERS = 3;
00075 const unsigned long DEFAULT_NUM_BUFFERS = 5;
00076
00077
00078
00079
00080 if (inPropertyRequest->cbAlign <= 0) {
00081 locReqAlloc.cbAlign = 1;
00082 } else {
00083 locReqAlloc.cbAlign = inPropertyRequest->cbAlign;
00084 }
00085
00086 if (inPropertyRequest->cbBuffer < MIN_BUFFER_SIZE) {
00087 locReqAlloc.cbBuffer = DEFAULT_BUFFER_SIZE;
00088 } else {
00089 locReqAlloc.cbBuffer = inPropertyRequest->cbBuffer;
00090 }
00091
00092 if (inPropertyRequest->cbPrefix < 0) {
00093 locReqAlloc.cbPrefix = 0;
00094 } else {
00095 locReqAlloc.cbPrefix = inPropertyRequest->cbPrefix;
00096 }
00097
00098 if (inPropertyRequest->cBuffers < MIN_NUM_BUFFERS) {
00099 locReqAlloc.cBuffers = DEFAULT_NUM_BUFFERS;
00100 } else {
00101
00102 locReqAlloc.cBuffers = inPropertyRequest->cBuffers;
00103 }
00104
00105 locHR = inAllocator->SetProperties(&locReqAlloc, &locActualAlloc);
00106
00107 if (locHR != S_OK) {
00108 return locHR;
00109 }
00110
00111
00112 locHR = inAllocator->Commit();
00113
00114 return locHR;
00115 }
00116 HRESULT AbstractAudioEncodeOutputPin::CheckMediaType(const CMediaType *inMediaType) {
00117 if ( (inMediaType->majortype == MEDIATYPE_Audio) &&
00118 (inMediaType->subtype == mOutputMediaType->subtype) && (inMediaType->formattype == mOutputMediaType->formattype)
00119 )
00120 {
00121 return S_OK;
00122 } else {
00123 return S_FALSE;
00124 }
00125
00126 }
00127
00128 HRESULT AbstractAudioEncodeOutputPin::GetMediaType(int inPosition, CMediaType *outMediaType) {
00129
00130 if (inPosition < 0) {
00131 return E_INVALIDARG;
00132 }
00133
00134 BYTE* locFormatBuffer = NULL;
00135 switch (inPosition) {
00136 case 0:
00137
00138 outMediaType->SetType(&MEDIATYPE_Audio);
00139 outMediaType->SetSubtype(&(mOutputMediaType->subtype));
00140 outMediaType->SetFormatType(&(mOutputMediaType->formattype));
00141
00142 locFormatBuffer = new BYTE[FormatBufferSize()];
00143 FillFormatBuffer(locFormatBuffer);
00144 outMediaType->SetFormat(locFormatBuffer, FormatBufferSize());
00145 delete[] locFormatBuffer;
00146
00147 return S_OK;
00148 default:
00149 return VFW_S_NO_MORE_ITEMS;
00150 }
00151 }
00152
00153
00154
00155
00156
00157 HRESULT AbstractAudioEncodeOutputPin::DeliverNewSegment(REFERENCE_TIME tStart, REFERENCE_TIME tStop, double dRate)
00158 {
00159
00160 mDataQueue->NewSegment(tStart, tStop, dRate);
00161
00162 return S_OK;
00163 }
00164 HRESULT AbstractAudioEncodeOutputPin::DeliverEndOfStream(void)
00165 {
00166
00167 mDataQueue->EOS();
00168 return S_OK;
00169 }
00170
00171 HRESULT AbstractAudioEncodeOutputPin::DeliverEndFlush(void)
00172 {
00173 mDataQueue->EndFlush();
00174 return S_OK;
00175 }
00176
00177 HRESULT AbstractAudioEncodeOutputPin::DeliverBeginFlush(void)
00178 {
00179
00180 mDataQueue->BeginFlush();
00181 return S_OK;
00182 }
00183
00184 HRESULT AbstractAudioEncodeOutputPin::CompleteConnect (IPin *inReceivePin)
00185 {
00186 HRESULT locHR = S_OK;
00187
00188 mDataQueue = new COutputQueue (inReceivePin, &locHR, FALSE, TRUE, 1, TRUE, 10);
00189 if (FAILED(locHR)) {
00190 locHR = locHR;
00191 }
00192
00193 return CBaseOutputPin::CompleteConnect(inReceivePin);
00194 }