【发布时间】:2016-03-15 18:27:15
【问题描述】:
我想用 VToolBox 压缩一些数据。当我在前台运行我的应用程序时,它运行良好,但是当我在后台运行我的应用程序时,它不再提供压缩数据......
我在编码开始时添加了日志:
- (void) encode1:(CMSampleBufferRef )sampleBuffer wrapTs:(UInt64)ts;
{
dispatch_sync(aQueue, ^{
frameCount++;
// Get the CV Image buffer
CVImageBufferRef imageBuffer = CMSampleBufferGetImageBuffer(sampleBuffer);
// Create properties
CMTime presentationTimeStamp = CMTimeMake(frameCount, 1000);
//CMTime duration = CMTimeMake(1, DURATION);
VTEncodeInfoFlags flags;
//NSLog(@"encode sessino status:%d", EncodingSession==nil? 0:1);
// Pass it to the encoder
OSStatus statusCode = VTCompressionSessionEncodeFrame(EncodingSession,
imageBuffer,
presentationTimeStamp,
kCMTimeInvalid,
NULL, (__bridge void*)@(ts), &flags);
NSLog(@"hardware compress result: %d", (int)statusCode);
// Check for error
if (statusCode != noErr) {
在压缩回调中:
void didCompressH264(void *outputCallbackRefCon, void *sourceFrameRefCon, OSStatus status, VTEncodeInfoFlags infoFlags,
CMSampleBufferRef sampleBuffer ){
//get outside stamp
UInt64 pp = [((__bridge NSNumber*)sourceFrameRefCon) longLongValue];
NSLog(@"didCompressH264 status:%d", status);
if (status != 0) return;
if (!CMSampleBufferDataIsReady(sampleBuffer))
{
NSLog(@"didCompressH264 data is not ready ");
return;
}
在后台运行应用程序时,我可以看到日志“硬件压缩结果:0”,表示将数据放入VToolBox,但无法获取日志“didCompressH264状态”。
它似乎永远无法到达didCompressH264 函数。
那么,我想知道VToolBox是否可以在后台运行?如果是这样,怎么做?任何答案表示赞赏!
【问题讨论】:
标签: ios iphone h.264 hardware-acceleration