【问题标题】:Can VToolBox run background on IOS?VToolBox可以在IOS后台运行吗?
【发布时间】: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


    【解决方案1】:

    一旦您的应用进入后台,VideoToolbox 就会停止解压缩帧。只有在前台应用程序上才允许硬件加速以提供最佳体验。

    【讨论】:

      【解决方案2】:

      iOS 不会让您的应用永远在后台运行。默认情况下,在应用程序移至后台后,它只会为您提供几秒钟的运行时间。除此之外,它会阻止应用程序运行或终止它。

      您可以在 AppDelegate 的 applicationDidEnterBackground: 方法中使用 beginBackgroundTaskWithName:expirationHandler: 请求更多时间。您可以通过backgroundTimeRemaining 查看 iOS 为您提供多长时间。除此之外,您的应用将被终止。

      请注意,很多事情在后台运行时并不相同。不确定该库使用什么资源,但如果您在后台获得对 GPU 的完全访问权限,我会感到惊讶。

      【讨论】:

      • 通过设置“必需的后台模式”或您建议的方式,我们确定应用程序在后台运行。日志“硬件压缩结果:0”也一直在打印。问题是即使我们可以将数据放入 VToolBox,但我们无法从中获取压缩数据。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-01
      • 2012-12-22
      • 2019-07-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多