AVCamRecorder.h
#import <AVFoundation/AVFoundation.h>@interface AVCamRecorder : NSObject {} @property (nonatomic,retain) AVCaptureVIDeoDataOutput *vIDeoDataOutput; @property (nonatomic,retain) AVCaptureAudioDataOutput *audioDataOutput;@end
AVCamRecorder.m
#import "AVCamRecorder.h"#import <AVFoundation/AVFoundation.h>@interface AVCamRecorder (VIDeoDataOutputDelegate) <AVCaptureVIDeoDataOutputSampleBufferDelegate>@end@interface AVCamRecorder (AudioDataOutputDelegate) <AVCaptureAudioDataOutputSampleBufferDelegate>@end-(ID)initWithSession:(AVCaptureSession *)aSession{ self = [super init]; if (self != nil) { //AudioDataoutput AVCaptureAudioDataOutput *aAudioDataOutput = [[AVCaptureAudioDataOutput alloc] init]; //VIDeoDataoutput AVCaptureVIDeoDataOutput *aMovIEDataOutput = [[AVCaptureVIDeoDataOutput alloc] init]; if ([aSession canAddOutput:aAudioDataOutput]) { [aSession addOutput:aAudioDataOutput]; } if ([aSession canAddOutput:aMovIEDataOutput]) { [aSession addOutput:aMovIEDataOutput]; } [aAudioDataOutput setSampleBufferDelegate:self queue:dispatch_get_main_queue()]; [aMovIEDataOutput setSampleBufferDelegate:self queue:dispatch_get_main_queue()]; [self setAudioDataOutput:aAudioDataOutput]; [self setVIDeoDataOutput:aMovIEDataOutput]; [self setSession:aSession]; } return self;}@implementation AVCamRecorder (VIDeoDataOutputDelegate)- (voID)captureOutput:(AVCaptureOutput *)captureOutputdIDOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer fromConnection:(AVCaptureConnection *)connection{ NSLog(@"VIDeoDataOutputDelegate = %@",captureOutput);} @end@implementation AVCamRecorder (AudioDataOutputDelegate)- (voID)captureOutput:(AVCaptureOutput *)captureOutputdIDOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer fromConnection:(AVCaptureConnection *)connection{ NSLog(@"AudioDataOutputDelegate = %@",captureOutput);}@end
奇怪的是,我在“@implementation AVCamRecorder(AudioDataOutputDelegate)”中获得了视频数据.
AudioDataOutputDelegate = <AVCaptureVIDeoDataOutput: 0x208a7df0>
我切换了“@implementation AVCamRecorder(VIDeoDataOutputDelegate)”和“@implementation AVCamRecorder(VIDeoDataOutputDelegate)”的顺序,我得到了
VIDeoDataOutputDelegate = <AVCaptureVIDeoDataOutput: 0x208a7df0>
似乎我无法设置2“captureOutput:dIDOutputSampleBuffer:fromConnection:”.否则,数据进入任何一个.
或者,我是否错误地设置了“@implementation AVCamRecorder(VIDeoDataOutputDelegate)”和“@implementation AVCamRecorder(AudioDataOutputDelegate)”?
我想我不需要单独回调,但我只是想知道出了什么问题.
提前谢谢你的帮助.
解决方法 您已在同一个类中定义了两个类别AVCamRecorder (VIDeoDataOutputDelegate)AVCamRecorder (AudioDataOutputDelegate)
声明相同的方法
- (voID)captureOutput:(AVCaptureOutput *)captureOutputdIDOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer fromConnection:(AVCaptureConnection *)connection;
这导致未定义的行为.请参阅“使用Objective-C编程”指南中的Avoid Category Method Name Clashes:
If the name of a method declared in a category is the same as a method
in the original class,or a method in another category on the same
class (or even a superclass),the behavior is undefined as to which
method implementation is used at runtime.
…
所以你的设置无法正常工作.你可以改为
>定义两个单独的类,一个作为音频,一个作为视频代表,>定义一个充当音频视频委托的类类别(并检查调用它的函数的回调方法),>只需将AVCamRecorder本身用作音频视频代表.
总结以上是内存溢出为你收集整理的objective-c – AVCaptureVideoDataOutput和AVCaptureAudioDataOutput的委托全部内容,希望文章能够帮你解决objective-c – AVCaptureVideoDataOutput和AVCaptureAudioDataOutput的委托所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)