Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/36.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
VToolBox能否在IOS上运行后台?_Ios_Iphone_H.264_Hardware Acceleration - Fatal编程技术网

VToolBox能否在IOS上运行后台?

VToolBox能否在IOS上运行后台?,ios,iphone,h.264,hardware-acceleration,Ios,Iphone,H.264,Hardware Acceleration,我想用VToolBox压缩一些数据。当我在前台运行我的应用程序时,它运行得很好,但当我在后台运行我的应用程序时,它不再提供压缩数据 我在编码开始时添加了日志: - (void) encode1:(CMSampleBufferRef )sampleBuffer wrapTs:(UInt64)ts; { dispatch_sync(aQueue, ^{ frameCount++; // Get the CV Image buffer CVImageBufferRe

我想用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状态”

它似乎从未达到
didcompress264
功能


所以,我想知道VToolBox是否可以在后台运行?如果是,怎么做?感谢您的回答

iOS不会让你的应用程序永远在后台运行。默认情况下,在应用程序移到后台后,它只会给你几秒钟的运行时间。除此之外,它要么阻止应用程序运行,要么杀死它

您可以在AppDelegate的
ApplicationIdentinterBackground:
方法中使用名为expirationHandler:的
BeginBackgroundTask请求更多时间。您可以使用
backgroundTimeRemaining
检查iOS给您的时间。除此之外,你的应用程序将被杀死


请注意,很多事情在后台的工作方式不同。不确定库使用了什么资源,但如果你在后台完全访问GPU,我会感到惊讶。

VideoToolbox会在你的应用程序进入后台后立即停止解压/压缩帧。仅允许在前台应用程序上进行硬件加速,以提供最佳体验。

通过设置“所需后台模式”或您建议的方式,我们可以确保应用程序在后台运行。“硬件压缩结果:0”日志也一直在打印。问题是,我们甚至可以将数据放入VToolBox,但无法从中获取压缩数据。