AVCaptureSession запускается, а затем сразу же выходит из строя

У меня есть канал видео, в котором используется собственный видеоплеер на основе 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];

... и вызывается в viewDidAppear моего CameraViewController.

Из того, что я собираю, кажется, что когда видеоплеер освобождается при представлении CameraViewController над FeedTableViewController, что-то происходит, вызывая ошибку 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

person HighFlyingFantasy    schedule 02.11.2013    source источник
comment
Вы решили эту ситуацию?   -  person Vasanth    schedule 20.02.2015
comment
@Vasanth да, проверьте github.com/Present-Inc/CameraKit   -  person HighFlyingFantasy    schedule 10.04.2015
comment
@Vasanth, не могли бы вы рассказать о решении? Я сталкиваюсь с той же проблемой. Когда я добавляю AVCaptureAudioDataOutput, сеанс моей камеры немедленно останавливается.   -  person Andy Poes    schedule 05.11.2015
comment
@AndyPoes Я не помню или, кажется, никогда не решал эту проблему.   -  person Vasanth    schedule 07.11.2015
comment
@Vasanth такая странная проблема :|   -  person Andy Poes    schedule 12.11.2015


Ответы (1)


Я бы попробовал пару вещей:

Я бы переместил эту строку:

captureSession = [[AVCaptureSession alloc] init];

Я бы переместил его выше, где вы добавляете наблюдателей уведомлений.

Я также попытался бы сделать свойства класса вывода данных (аудио и видео).

person Amos    schedule 08.07.2014