내 목표는 iDevice 화면을 가능한 한 지연이없는 OSX로 미러링하는 것입니다.VideoToolbox는 기본적으로 H264 Annex B를 디코딩 할 수 있습니까? 오류 코드 -8969 BadData
Airplay Mirroring
(예 : 리플렉터) 내가 두 번째 방법을 추구하기 위해 선택한
번개 (예 : 퀵타임 녹음)를 통해
CoreMediaIO
: 제가 알기로 이 2 가지 방법이 있습니다 왜냐하면 (내 지식으로) 연결된 iD 디바이스는 한 번 설정 한 후 자동으로 DAL 디바이스로 인식 될 수 있기 때문입니다. 당신이로 연결된의 iDevice를 인식 한 후에는 AVFoundation
작업 할 수처럼 https://nadavrub.wordpress.com/2015/07/06/macos-media-capture-using-coremediaio/ 블로그 CoreMediaIO
을 사용하는 방법에 매우 깊이 들어가
, 그러나 그것은 것 같다
이 작업을 수행하는 방법에 대한 주요 자원이 블로그 AVCaptureDevice
.
이 질문 : How to mirror iOS screen via USB?은 iDevice에서 제공하는 H264 (Annex B) muxxed 데이터 스트림의 각 프레임을 가져 오는 방법에 대한 솔루션을 게시했습니다.
그러나 내 문제는 코드에 차이가 있어서는 안되지만 VideoToolbox
은 (오류 코드 -8969, BadData) 올바르게 디코딩되지 않는다는 것입니다.
vtDecompressionDuctDecodeSingleFrame는 /SourceCache/CoreMedia_frameworks/CoreMedia-1562.240/Sources/VideoToolbox/VTDecompressionSession.c 줄에서 ERR = -8969 (ERR) (VTVideoDecoderDecodeFrame 반환 오류) 신호 3241
전체 코드 :
#import "ViewController.h"
@import CoreMediaIO;
@import AVFoundation;
@import AppKit;
@implementation ViewController
AVCaptureSession *session;
AVCaptureDeviceInput *newVideoDeviceInput;
AVCaptureVideoDataOutput *videoDataOutput;
- (void)viewDidLoad {
[super viewDidLoad];
}
- (instancetype)initWithCoder:(NSCoder *)coder
{
self = [super initWithCoder:coder];
if (self) {
// Allow iOS Devices Discovery
CMIOObjectPropertyAddress prop =
{ kCMIOHardwarePropertyAllowScreenCaptureDevices,
kCMIOObjectPropertyScopeGlobal,
kCMIOObjectPropertyElementMaster };
UInt32 allow = 1;
CMIOObjectSetPropertyData(kCMIOObjectSystemObject,
&prop, 0, NULL,
sizeof(allow), &allow);
// Get devices
NSArray *devices = [AVCaptureDevice devicesWithMediaType:AVMediaTypeMuxed];
BOOL deviceAttahced = false;
for (int i = 0; i < [devices count]; i++) {
AVCaptureDevice *device = devices[i];
if ([[device uniqueID] isEqualToString:@"b48defcadf92f300baf5821923f7b3e2e9fb3947"]) {
deviceAttahced = true;
[self startSession:device];
break;
}
}
}
return self;
}
- (void) deviceConnected:(AVCaptureDevice *)device {
if ([[device uniqueID] isEqualToString:@"b48defcadf92f300baf5821923f7b3e2e9fb3947"]) {
[self startSession:device];
}
}
- (void) startSession:(AVCaptureDevice *)device {
// Init capturing session
session = [[AVCaptureSession alloc] init];
// Star session configuration
[session beginConfiguration];
// Add session input
NSError *error;
newVideoDeviceInput = [AVCaptureDeviceInput deviceInputWithDevice:device error:&error];
if (newVideoDeviceInput == nil) {
dispatch_async(dispatch_get_main_queue(), ^(void) {
NSLog(@"%@", error);
});
} else {
[session addInput:newVideoDeviceInput];
}
// Add session output
videoDataOutput = [[AVCaptureVideoDataOutput alloc] init];
videoDataOutput.videoSettings = [NSDictionary dictionaryWithObject: [NSNumber numberWithInt:kCVPixelFormatType_32BGRA] forKey: (id)kCVPixelBufferPixelFormatTypeKey];
dispatch_queue_t videoQueue = dispatch_queue_create("videoQueue", NULL);
[videoDataOutput setSampleBufferDelegate:self queue:videoQueue];
[session addOutput:videoDataOutput];
// Finish session configuration
[session commitConfiguration];
// Start the session
[session startRunning];
}
#pragma mark - AVCaptureAudioDataOutputSampleBufferDelegate
- (void)captureOutput:(AVCaptureOutput *)captureOutput didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer fromConnection:(AVCaptureConnection *)connection {
//NSImage *resultNSImage = [self imageFromSampleBuffer:sampleBuffer];
//self.imageView.image = [self nsImageFromSampleBuffer:sampleBuffer];
self.imageView.image = [[NSImage alloc] initWithData:imageToBuffer(sampleBuffer)];
}
NSData* imageToBuffer(CMSampleBufferRef source) {
CVImageBufferRef imageBuffer = CMSampleBufferGetImageBuffer(source);
CVPixelBufferLockBaseAddress(imageBuffer,0);
size_t bytesPerRow = CVPixelBufferGetBytesPerRow(imageBuffer);
size_t height = CVPixelBufferGetHeight(imageBuffer);
void *src_buff = CVPixelBufferGetBaseAddress(imageBuffer);
NSData *data = [NSData dataWithBytes:src_buff length:bytesPerRow * height];
CVPixelBufferUnlockBaseAddress(imageBuffer, 0);
return data;
}