ios VideoToolbox 硬编码 错误码汇总
硬编码错误码OSStatus(VideoToolbox/VTError.h):
• kVTPropertyNotSupportedErr = -12900,
• kVTPropertyReadOnlyErr = -12901,
• kVTParameterErr = -12902,
• kVTInvalidSessionErr = -12903,
• kVTAllocationFailedErr = -12904,
• kVTPixelTransferNotSupportedErr = -12905, // c.f. -8961
• kVTCouldNotFindVideoDecoderErr = -12906,
• kVTCouldNotCreateInstanceErr = -12907,
• kVTCouldNotFindVideoEncoderErr = -12908,
• kVTVideoDecoderBadDataErr = -12909, // c.f. -8969
• kVTVideoDecoderUnsupportedDataFormatErr = -12910, // c.f. -8970
• kVTVideoDecoderMalfunctionErr = -12911, // c.f. -8960
• kVTVideoEncoderMalfunctionErr = -12912,//频繁的启停编码器,报错
• kVTVideoDecoderNotAvailableNowErr = -12913,
• kVTImageRotationNotSupportedErr = -12914,
• kVTVideoEncoderNotAvailableNowErr = -12915,
• kVTFormatDescriptionChangeNotSupportedErr = -12916,
• kVTCouldNotCreateColorCorrectionDataErr = -12918,
• kVTColorSyncTransformConvertFailedErr = -12919,
• kVTVideoDecoderAuthorizationErr = -12210,
• kVTVideoEncoderAuthorizationErr = -12211,
• kVTColorCorrectionPixelTransferFailedErr = -12212,
• kVTMultiPassStorageIdentifierMismatchErr = -12213,
• kVTMultiPassStorageInvalidErr = -12214,
• kVTFrameSiloInvalidTimeStampErr = -12215,
• kVTFrameSiloInvalidTimeRangeErr = -12216,
• kVTCouldNotFindTemporalFilterErr = -12217,
• kVTPixelTransferNotPermittedErr = -12218,
• kVTColorCorrectionImageRotationFailedErr = -12219,
• kVTVideoDecoderRemovedErr = -17690,
除了上述VTErrors,补充遇到CMFormatDescription,CMBlockBuffer,CMSampleBuffer错误。
• kCMFormatDescriptionError_InvalidParameter = -12710,
• kCMFormatDescriptionError_AllocationFailed = -12711,
• kCMFormatDescriptionError_ValueNotAvailable = -12718,
• kCMBlockBufferNoErr = 0,
• kCMBlockBufferStructureAllocationFailedErr = -12700,
• kCMBlockBufferBlockAllocationFailedErr = -12701,
• kCMBlockBufferBadCustomBlockSourceErr = -12702,
• kCMBlockBufferBadOffsetParameterErr = -12703,
• kCMBlockBufferBadLengthParameterErr = -12704,
• kCMBlockBufferBadPointerParameterErr = -12705,
• kCMBlockBufferEmptyBBufErr = -12706,
• kCMBlockBufferUnallocatedBlockErr = -12707,
• kCMBlockBufferInsufficientSpaceErr = -12708,
• kCMSampleBufferError_AllocationFailed = -12730,
• kCMSampleBufferError_RequiredParameterMissing = -12731,
• kCMSampleBufferError_AlreadyHasDataBuffer = -12732,
• kCMSampleBufferError_BufferNotReady = -12733,
• kCMSampleBufferError_SampleIndexOutOfRange = -12734,
• kCMSampleBufferError_BufferHasNoSampleSizes = -12735,
• kCMSampleBufferError_BufferHasNoSampleTimingInfo = -12736,
• kCMSampleBufferError_ArrayTooSmall = -12737,
• kCMSampleBufferError_InvalidEntryCount = -12738,
• kCMSampleBufferError_CannotSubdivide = -12739,
• kCMSampleBufferError_SampleTimingInfoInvalid = -12740,
• kCMSampleBufferError_InvalidMediaTypeForOperation = -12741,
• kCMSampleBufferError_InvalidSampleData = -12742,
• kCMSampleBufferError_InvalidMediaFormat = -12743,
• kCMSampleBufferError_Invalidated = -12744,
• kCMSampleBufferError_DataFailed = -16750,
• kCMSampleBufferError_DataCanceled = -16751,
编码示例:
VTCompressionSessionRef _encoderSession;
CVPixelBufferPoolRef _pixelBufferPool = VTCompressionSessionGetPixelBufferPool(_encoderSession);
if(_pixelBufferPool)
{
CVPixelBufferPoolRetain(_pixelBufferPool);
}
else
{
printf(this," Failed to create Pixel Buffer in current session.");
}
CVPixelBufferRef pixbuf = NULL;
CVReturn r = CVPixelBufferPoolCreatePixelBuffer(kCFAllocatorDefault, _pixelBufferPool, &pixbuf);
if (kCVReturnSuccess != r || NULL == pixbuf)
{
printf(this," create pixel buffer failed! status=%d", r);
return false;
}
CVPixelBufferLockBaseAddress( pixbuf, 0 );
//copy yuv数据
....
CVPixelBufferUnlockBaseAddress( pixbuf, 0);
CMTime timestamp = CMTimeMake(pts - _timestampBase, 1000);
CMTime duration = CMTimeMake(1, _frameRate);
CVImageBufferRef imageBuffer = CMSampleBufferGetImageBuffer(sampleBuffer);
VTEncodeInfoFlags infoFlags = 0;
status = VTCompressionSessionEncodeFrame(_encoderSession,
pixbuf,
timestamp,
duration,
NULL,
imageBuffer,
&infoFlags);
CVPixelBufferRelease(pixbuf);
....
//获取sps pps
CFArrayRef array = CMSampleBufferGetSampleAttachmentsArray(sampleBuffer, true);
const void * value = CFArrayGetValueAtIndex(array, 0);
bool keyframe = !CFDictionaryContainsKey(value, kCMSampleAttachmentKey_NotSync);
CMFormatDescriptionRef format = CMSampleBufferGetFormatDescription(sampleBuf);
size_t spsSize = 0, ppsSize = 0;
const uint8_t *sps = 0, *pps = 0;
size_t parmCount = 0;
CMVideoFormatDescriptionGetH264ParameterSetAtIndex(format, 0, &sps, &spsSize, &parmCount, NULL);
CMVideoFormatDescriptionGetH264ParameterSetAtIndex(format, 1, &pps, &ppsSize, &parmCount, NULL);
memcpy(encoder->_sps, sps, spsSize);
encoder->_spsLen = spsSize;
memcpy(encoder->_pps, pps, ppsSize);
encoder->_ppsLen = ppsSize;
....
if (_encoderSession)
{
VTCompressionSessionCompleteFrames(_encoderSession, kCMTimeInvalid);//如果completeUntilPresentationTimeStamp是数字的话,包括当前时间和之前时间的帧都会在方法返回前发出。如果不是数字的话,全部的未处理的帧都会在方法返回前发出。
VTCompressionSessionInvalidate(_encoderSession);
CFRelease(_encoderSession);
_encoderSession = NULL;
CVPixelBufferPoolRelease(_pixelBufferPool);
_pixelBufferPool = NULL;
}