6

我有一个视频源,这些视频使用基于 AVPlayer 的自定义视频播放器来播放 HLS 流。在导航栏上,有一个启动相机的按钮。在 iOS 7.0.3 更新中,捕获会话现在遇到了严重的问题,它将开始,然后立即自行关闭,发出如下错误:

Capture session error:


NSConcreteNotification 0x146eae70 {name = AVCaptureSessionRuntimeErrorNotification; object = <AVCaptureSession: 0x15976e70 [AVCaptureSessionPresetHigh]>
<AVCaptureDeviceInput: 0x145d3ee0 [Back Camera]> -> <AVCaptureVideoDataOutput: 0x159546f0>
<AVCaptureDeviceInput: 0x1594bd60 [iPhone Microphone]> -> <AVCaptureAudioDataOutput: 0x159823e0>
<AVCaptureDeviceInput: 0x145d3ee0 [Back Camera]> -> <AVCaptureVideoPreviewLayer: 0x1467b370>; userInfo = {
AVCaptureSessionErrorKey = "Error Domain=AVFoundationErrorDomain Code=-11819 \"Cannot Complete Action\" UserInfo=0x146f0ec0 {NSLocalizedRecoverySuggestion=Try again later., NSLocalizedDescription=Cannot Complete Action}";

}}

我设置捕获会话的方法如下所示...

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(captureSessionDidStartRunning:) name:AVCaptureSessionDidStartRunningNotification object:captureSession];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(captureSessionDidStopRunning:) name:AVCaptureSessionDidStopRunningNotification object:captureSession];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(captureSessionDidFailWithError:) name:AVCaptureSessionRuntimeErrorNotification object:captureSession];


discontinuous = NO;
_recording = NO;
_paused = NO;

// Alloc and initialize a capture session
captureSession = [[AVCaptureSession alloc] init];

// Setup and add the video device
AVCaptureDevice *videoDevice = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];

NSError *videoError = nil;
_videoInput = [AVCaptureDeviceInput deviceInputWithDevice:videoDevice error:&videoError];

if (videoError) {
    ErrorLog(@"%@", [videoError userInfo]);
}else {
    if ([captureSession canAddInput:_videoInput])
        [captureSession addInput:_videoInput];
    else
        ErrorLog(@"Cannot add video input");
}

// Setup and add the audio device
AVCaptureDevice *audioDevice = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeAudio];

NSError *audioError = nil;
_audioInput = [AVCaptureDeviceInput deviceInputWithDevice:audioDevice error:&audioError];

if (audioError) {
    ErrorLog(@"%@", [audioError userInfo]);
}else {
    if ([captureSession canAddInput:_audioInput])
        [captureSession addInput:_audioInput];
    else
        ErrorLog(@"Cannot add audio input");
}

// Alloc and initialize video data output
AVCaptureVideoDataOutput *videoDataOutput = [[AVCaptureVideoDataOutput alloc] init];
captureQueue = dispatch_queue_create("tv.present.captureQueue", DISPATCH_QUEUE_SERIAL);
[videoDataOutput setSampleBufferDelegate:self queue:captureQueue];

// Setup default video capture settings (H.264 video pixel format)
NSDictionary *videoCaptureSettings = [NSDictionary dictionaryWithObjectsAndKeys:
                                      [NSNumber numberWithInt:kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange], kCVPixelBufferPixelFormatTypeKey,
                                      nil];
[videoDataOutput setVideoSettings:videoCaptureSettings];

if ([captureSession canAddOutput:videoDataOutput])
    [captureSession addOutput:videoDataOutput];
else
    ErrorLog(@"Cannot add video data output");

// Alloc and initialize audio data output
AVCaptureAudioDataOutput *audioDataOutput = [[AVCaptureAudioDataOutput alloc] init];
[audioDataOutput setSampleBufferDelegate:self queue:captureQueue];

// Add the output
if ([captureSession canAddOutput:audioDataOutput])
    [captureSession addOutput:audioDataOutput];
else
    ErrorLog(@"Cannot add audio data output");

// Setup the video connection
if ([videoDataOutput connectionWithMediaType:AVMediaTypeVideo]) {
    videoConnection = [videoDataOutput connectionWithMediaType:AVMediaTypeVideo];
    [videoConnection setVideoOrientation:AVCaptureVideoOrientationPortrait];


    if ([videoConnection isVideoStabilizationSupported])
        [videoConnection setEnablesVideoStabilizationWhenAvailable:YES];
}

// Setup the audio connection
if ([audioDataOutput connectionWithMediaType:AVMediaTypeAudio])
    audioConnection = [audioDataOutput connectionWithMediaType:AVMediaTypeAudio];

PLog(@"Will start capture session!");
// Start running the capture session
[captureSession startRunning];
PLog(@"Did start capture session!");

// Setup the preview layer
_previewLayer = [AVCaptureVideoPreviewLayer layerWithSession:captureSession];
[_previewLayer setVideoGravity:AVLayerVideoGravityResizeAspectFill];

...并在我的 CameraViewController 的 viewDidAppear 中调用。

从我收集的信息来看,似乎当视频播放器在 FeedTableViewController 上显示 CameraViewController 时被释放时,会发生一些事情导致 mediaserverd 和 mediaremoted 错误。以下是控制台日志:

Nov  1 17:28:19 Justin-Makailas-iPhone Present[1320] <Warning>: -[PVideoProcessor setupAndStartCaptureSession] [Line 158]

 Will start capture session!
Nov  1 17:28:20 Justin-Makailas-iPhone kernel[0] <Debug>: AppleH4CamIn::setPowerStateGated: 1
Nov  1 17:28:20 Justin-Makailas-iPhone kernel[0] <Debug>: AppleH4CamIn::power_on_hardware
Nov  1 17:28:20 Justin-Makailas-iPhone voiced[1324] <Warning>: Error (hex)80000008 (int)-2147483640 at /SourceCache/VoiceServices/VoiceServices-225.1/Daemon/VSSpeechServer.m:1286 (destroying TTS instance)
Nov  1 17:28:29 Justin-Makailas-iPhone Present[1320] <Warning>: -[PVideoProcessor captureSessionDidStartRunning:] [Line 218]

 Capture session did start running
Nov  1 17:28:29 Justin-Makailas-iPhone kernel[0] <Debug>: 016737.297413 wlan.A[1075] AppleBCMWLANNetManager::checkRealTimeTraffic():  now 16737.297403541 num entries 4
Nov  1 17:28:29 Justin-Makailas-iPhone kernel[0] <Debug>: 016737.297437 wlan.A[1076] AppleBCMWLANCore::dumpWmeCounters():  per TIDs tx counters: 43722 18715 0 0 0 68128 1584 0, per TIDs rx counters: 30945 256327 1484 0 0 473 104 0 
Nov  1 17:28:29 Justin-Makailas-iPhone kernel[0] <Debug>: 016737.297458 wlan.A[1077] AppleBCMWLANCore::dumpWmeCounters():                AWDL: Tx 0 0 0 0 0 0 0 0,                   Rx: 0 0 0 0 0 0 0 0 
Nov  1 17:28:29 Justin-Makailas-iPhone Present[1320] <Warning>: -[PVideoProcessor setupAndStartCaptureSession] [Line 161]

 Did start capture session!
Nov  1 17:28:30 Justin-Makailas-iPhone ReportCrash[1327] <Notice>: Saved crashreport to /Library/Logs/CrashReporter/stacks+mediaserverd-2013-11-01-172830.plist using uid: 0 gid: 0, synthetic_euid: 0 egid: 0
Nov  1 17:28:30 Justin-Makailas-iPhone mediaremoted[21] <Error>: Property list invalid for format: 200 (property lists cannot contain NULL)
Nov  1 17:28:30 Justin-Makailas-iPhone kernel[0] <Debug>: AppleH4CamInUserClient::clientDied
Nov  1 17:28:30 Justin-Makailas-iPhone Present[1320] <Warning>: NSConcreteNotification 0x14678540 {name = AVCaptureSessionDidStopRunningNotification; object = <AVCaptureSession: 0x15976e70 [AVCaptureSessionPresetHigh]>
      <AVCaptureDeviceInput: 0x145d3ee0 [Back Camera]> -> <AVCaptureVideoDataOutput: 0x159546f0>
      <AVCaptureDeviceInput: 0x1594bd60 [iPhone Microphone]> -> <AVCaptureAudioDataOutput: 0x159823e0>
      <AVCaptureDeviceInput: 0x145d3ee0 [Back Camera]> -> <AVCaptureVideoPreviewLayer: 0x1467b370>}
Nov  1 17:28:30 Justin-Makailas-iPhone Present[1320] <Warning>: -[PVideoProcessor captureSessionDidStopRunning:] [Line 214]

 Capture session did stop running
Nov  1 17:28:30 Justin-Makailas-iPhone Present[1320] <Warning>: -[PVideoProcessor captureSessionDidFailWithError:] [Line 222]

 Capture session error: NSConcreteNotification 0x146eae70 {name = AVCaptureSessionRuntimeErrorNotification; object = <AVCaptureSession: 0x15976e70 [AVCaptureSessionPresetHigh]>
      <AVCaptureDeviceInput: 0x145d3ee0 [Back Camera]> -> <AVCaptureVideoDataOutput: 0x159546f0>
      <AVCaptureDeviceInput: 0x1594bd60 [iPhone Microphone]> -> <AVCaptureAudioDataOutput: 0x159823e0>
      <AVCaptureDeviceInput: 0x145d3ee0 [Back Camera]> -> <AVCaptureVideoPreviewLayer: 0x1467b370>; userInfo = {
     AVCaptureSessionErrorKey = "Error Domain=AVFoundationErrorDomain Code=-11819 \"Cannot Complete Action\" UserInfo=0x146f0ec0 {NSLocalizedRecoverySuggestion=Try again later., NSLocalizedDescription=Cannot Complete Action}";
 }}
Nov  1 17:28:30 Justin-Makailas-iPhone kernel[0] <Debug>: AppleH4CamInUserClient::clientDied
Nov  1 17:28:30 Justin-Makailas-iPhone kernel[0] <Debug>: AppleH4CamIn::setPowerStateGated: 0
Nov  1 17:28:30 Justin-Makailas-iPhone kernel[0] <Debug>: AppleH4CamIn::power_off_hardware
Nov  1 17:28:30 Justin-Makailas-iPhone mediaremoted[21] <Error>: Property list invalid for format: 200 (property lists cannot contain NULL)
Nov  1 17:28:30 Justin-Makailas-iPhone mediaremoted[21] <Error>: Property list invalid for format: 200 (property lists cannot contain NULL)
Nov  1 17:28:30 Justin-Makailas-iPhone com.apple.launchd[1] (com.apple.mediaserverd[1308]) <Notice>: (com.apple.mediaserverd) Exited: Killed: 9
Nov  1 17:28:30 Justin-Makailas-iPhone mediaserverd[1328] <Notice>: 
Nov  1 17:28:30 Justin-Makailas-iPhone mediaserverd[1328] <Notice>: 2013-11-01 05:28:30.579219 PM [AirPlay] HAL plugin initializing
Nov  1 17:28:30 Justin-Makailas-iPhone mediaserverd[1328] <Notice>: 2013-11-01 05:28:30.581993 PM [AirPlay] HAL plugin initialized
Nov  1 17:28:30 Justin-Makailas-iPhone mediaserverd[1328] <Notice>: <vad> NOTE:     17:28:30.616 [tid 0x3c6af18c] [304]: Logging defaults: [ General Priority: Note; Trace Priority: Note; Async Priority: Error; Traced Scopes: { } ].
Nov  1 17:28:30 Justin-Makailas-iPhone mediaremoted[21] <Error>: Property list invalid for format: 200 (property lists cannot contain NULL)
Nov  1 17:28:30 Justin-Makailas-iPhone mediaremoted[21] <Error>: Property list invalid for format: 200 (property lists cannot contain NULL)
Nov  1 17:28:30 Justin-Makailas-iPhone mediaremoted[21] <Error>: Property list invalid for format: 200 (property lists cannot contain NULL)
Nov  1 17:28:30 Justin-Makailas-iPhone mediaremoted[21] <Error>: Property list invalid for format: 200 (property lists cannot contain NULL)
Nov  1 17:28:30 Justin-Makailas-iPhone mediaremoted[21] <Error>: Property list invalid for format: 200 (property lists cannot contain NULL)
Nov  1 17:28:30 Justin-Makailas-iPhone mediaremoted[21] <Error>: Property list invalid for format: 200 (property lists cannot contain NULL)
Nov  1 17:28:30 Justin-Makailas-iPhone mediaremoted[21] <Error>: Property list invalid for format: 200 (property lists cannot contain NULL)
Nov  1 17:28:30 Justin-Makailas-iPhone mediaremoted[21] <Error>: Property list invalid for format: 200 (property lists cannot contain NULL)
Nov  1 17:28:30 Justin-Makailas-iPhone mediaremoted[21] <Error>: Property list invalid for format: 200 (property lists cannot contain NULL)
Nov  1 17:28:30 Justin-Makailas-iPhone mediaremoted[21] <Error>: Property list invalid for format: 200 (property lists cannot contain NULL)
Nov  1 17:28:30 Justin-Makailas-iPhone mediaremoted[21] <Error>: Property list invalid for format: 200 (property lists cannot contain NULL)
Nov  1 17:28:30 Justin-Makailas-iPhone mediaremoted[21] <Error>: Property list invalid for format: 200 (property lists cannot contain NULL)
Nov  1 17:28:30 Justin-Makailas-iPhone mediaremoted[21] <Error>: Property list invalid for format: 200 (property lists cannot contain NULL)
Nov  1 17:28:33 Justin-Makailas-iPhone Present[1320] <Warning>: -[PVideoProcessor stopAndTeardownCaptureSession] [Line 169]

 Stop and teardown
4

1 回答 1

0

我会尝试几件事:

我会移动这条线:

captureSession = [[AVCaptureSession alloc] init];

我会把它移到你添加通知观察者的地方。

我也会尝试制作数据输出(音频和视频)类属性。

于 2014-07-08T21:01:43.037 回答