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 #include "stdafx.h"
00032 #include "abstractvideoencodeoutputpin.h"
00033
00034 AbstractVideoEncodeOutputPin::AbstractVideoEncodeOutputPin(AbstractVideoEncodeFilter* inParentFilter, CCritSec* inFilterLock, CHAR* inObjectName, LPCWSTR inPinDisplayName, CMediaType* inOutputMediaType)
00035 : CBaseOutputPin(inObjectName, inParentFilter, inFilterLock, &mHR, inPinDisplayName),
00036 mParentFilter(inParentFilter)
00037
00038 , mDataQueue(NULL)
00039 {
00040 mOutputMediaType = inOutputMediaType;
00041 }
00042 AbstractVideoEncodeOutputPin::~AbstractVideoEncodeOutputPin(void)
00043 {
00044
00045 delete mDataQueue;
00046
00047 }
00048
00049 STDMETHODIMP AbstractVideoEncodeOutputPin::NonDelegatingQueryInterface(REFIID riid, void **ppv) {
00050 if (riid == IID_IMediaSeeking) {
00051 *ppv = (IMediaSeeking*)this;
00052 ((IUnknown*)*ppv)->AddRef();
00053 return NOERROR;
00054 }
00055
00056 return CBaseOutputPin::NonDelegatingQueryInterface(riid, ppv);
00057 }
00058
00059 HRESULT AbstractVideoEncodeOutputPin::DecideBufferSize(IMemAllocator* inAllocator, ALLOCATOR_PROPERTIES* inPropertyRequest) {
00060
00061
00062
00063
00064 HRESULT locHR = S_OK;
00065
00066
00067 ALLOCATOR_PROPERTIES locReqAlloc;
00068 ALLOCATOR_PROPERTIES locActualAlloc;
00069
00070 const unsigned long MIN_BUFFER_SIZE = 65536;
00071 const unsigned long DEFAULT_BUFFER_SIZE = 1024*1024;
00072 const unsigned long MIN_NUM_BUFFERS = 3;
00073 const unsigned long DEFAULT_NUM_BUFFERS = 5;
00074
00075
00076
00077
00078 if (inPropertyRequest->cbAlign <= 0) {
00079 locReqAlloc.cbAlign = 1;
00080 } else {
00081 locReqAlloc.cbAlign = inPropertyRequest->cbAlign;
00082 }
00083
00084 if (inPropertyRequest->cbBuffer < MIN_BUFFER_SIZE) {
00085 locReqAlloc.cbBuffer = DEFAULT_BUFFER_SIZE;
00086 } else {
00087 locReqAlloc.cbBuffer = inPropertyRequest->cbBuffer;
00088 }
00089
00090 if (inPropertyRequest->cbPrefix < 0) {
00091 locReqAlloc.cbPrefix = 0;
00092 } else {
00093 locReqAlloc.cbPrefix = inPropertyRequest->cbPrefix;
00094 }
00095
00096 if (inPropertyRequest->cBuffers < MIN_NUM_BUFFERS) {
00097 locReqAlloc.cBuffers = DEFAULT_NUM_BUFFERS;
00098 } else {
00099
00100 locReqAlloc.cBuffers = inPropertyRequest->cBuffers;
00101 }
00102
00103 locHR = inAllocator->SetProperties(&locReqAlloc, &locActualAlloc);
00104
00105 if (locHR != S_OK) {
00106 return locHR;
00107 }
00108
00109
00110 locHR = inAllocator->Commit();
00111
00112 return locHR;
00113 }
00114 HRESULT AbstractVideoEncodeOutputPin::CheckMediaType(const CMediaType *inMediaType) {
00115 if ( (inMediaType->majortype == MEDIATYPE_Video) &&
00116 (inMediaType->subtype == mOutputMediaType->subtype) && (inMediaType->formattype == mOutputMediaType->formattype)
00117 )
00118 {
00119 return S_OK;
00120 } else {
00121 return S_FALSE;
00122 }
00123
00124 }
00125
00126 HRESULT AbstractVideoEncodeOutputPin::GetMediaType(int inPosition, CMediaType *outMediaType) {
00127
00128
00129 if (inPosition < 0) {
00130 return E_INVALIDARG;
00131 }
00132
00133 BYTE* locFormatBuffer = NULL;
00134 switch (inPosition) {
00135 case 0:
00136
00137 outMediaType->SetType(&MEDIATYPE_Video);
00138 outMediaType->SetSubtype(&(mOutputMediaType->subtype));
00139 outMediaType->SetFormatType(&(mOutputMediaType->formattype));
00140
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 AbstractVideoEncodeOutputPin::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 AbstractVideoEncodeOutputPin::DeliverEndOfStream(void)
00165 {
00166
00167 mDataQueue->EOS();
00168 return S_OK;
00169 }
00170
00171 HRESULT AbstractVideoEncodeOutputPin::DeliverEndFlush(void)
00172 {
00173 mDataQueue->EndFlush();
00174 return S_OK;
00175 }
00176
00177 HRESULT AbstractVideoEncodeOutputPin::DeliverBeginFlush(void)
00178 {
00179
00180 mDataQueue->BeginFlush();
00181 return S_OK;
00182 }
00183
00184 HRESULT AbstractVideoEncodeOutputPin::CompleteConnect (IPin *inReceivePin)
00185 {
00186 HRESULT locHR = S_OK;
00187
00188 mDataQueue = new COutputQueue (inReceivePin, &locHR, FALSE, TRUE, 1, TRUE, 25);
00189 if (FAILED(locHR)) {
00190 locHR = locHR;
00191 }
00192
00193 return CBaseOutputPin::CompleteConnect(inReceivePin);
00194 }