Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 0 additions & 9 deletions XcodeLibraryProject/iVidCapPro/GPUImageMovieWriter.m
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,6 @@ @interface GPUImageMovieWriter ()

GLuint inputTextureForMovieRendering;

GLubyte *frameData;

CMTime startTime, previousFrameTime;

BOOL isRecording;
Expand Down Expand Up @@ -195,11 +193,6 @@ - (id)initWithMovieURL:(NSURL *)newMovieURL size:(CGSize)newSize fileType:(NSStr
- (void)dealloc;
{
[self destroyDataFBO];

if (frameData != NULL)
{
free(frameData);
}
}

#pragma mark -
Expand All @@ -210,9 +203,7 @@ - (void)initializeMovieWithOutputSettings:(NSMutableDictionary *)outputSettings;
isRecording = NO;

self.enabled = YES;
frameData = (GLubyte *) malloc((int)videoSize.width * (int)videoSize.height * 4);

// frameData = (GLubyte *) calloc(videoSize.width * videoSize.height * 4, sizeof(GLubyte));
NSError *error = nil;
assetWriter = [[AVAssetWriter alloc] initWithURL:movieURL fileType:fileType error:&error];
if (error != nil)
Expand Down
10 changes: 8 additions & 2 deletions XcodeLibraryProject/iVidCapPro/iVidCap.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ static int Demo_FrameLimit = 10 * 30; // set later based on actual
enum AudioCapture {
No_Audio = 0,
Audio = 1,
Audio_Plus_Mic = 2
Audio_Plus_Mic = 2,
Audio_Mic = 3
};

// This enum must be kept in sync with the VideoDisposition enum in iVidCap.cs.
Expand Down Expand Up @@ -75,7 +76,7 @@ enum VideoCaptureFramerateLock {
Throttled = 2
};

@interface ivcp_VideoRecorder : NSObject {
@interface ivcp_VideoRecorder : NSObject <AVAudioRecorderDelegate> {


// Video attributes.
Expand Down Expand Up @@ -124,6 +125,11 @@ enum VideoCaptureFramerateLock {
AVAsset* userAudioAsset2;
AVAsset* mixedAudioAsset;

// Mic audio recording.
AVAudioRecorder * micAudioRecorder;
BOOL bMicAudioRecordFinished;
BOOL bMovieWriterFinished;

// Debug.
BOOL showDebug;

Expand Down
95 changes: 91 additions & 4 deletions XcodeLibraryProject/iVidCapPro/iVidCap.mm
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,8 @@ - (void)dealloc {
finalVideoFileName = nil;
}

[self micAudioRecorderKill];

strcpy(iVidCapGameObject, "");

[super dealloc];
Expand Down Expand Up @@ -587,11 +589,17 @@ -(BOOL) beginRecordingSession {
glFinish();
[EAGLContext setCurrentContext: unity_context];

if(captureAudio == Audio_Mic) {
[self micAudioRecorderStart];
bMicAudioRecordFinished = NO;
}

// Set the video recording start time.
recordStartTime = [[NSDate alloc] init];
[recordStartTime retain];

isRecording = true;
bMovieWriterFinished = NO;

if (showDebug)
NSLog(@"iVidCapPro - beginRecordingSession exiting.");
Expand Down Expand Up @@ -625,11 +633,31 @@ - (int) endRecordingSession: (VideoDisposition) action AddAudioFile1:(NSString*)
// When the movie writer is finished, we'll continue completing the recording
// session.
[movieWriter finishRecordingWithCompletionHandler:^{
[self movieWriterCompleteHandler];}];
bMovieWriterFinished = YES;
[self checkAllRecordingsAreFinished];
}];

if(captureAudio == Audio_Mic) {
[self micAudioRecorderStop];
}

return 0;
}

- (void)checkAllRecordingsAreFinished {

BOOL bFinaliseVideo = YES;
bFinaliseVideo = bFinaliseVideo && bMovieWriterFinished;
if(captureAudio == Audio_Mic) {
bFinaliseVideo = bFinaliseVideo && bMicAudioRecordFinished;
}
if(bFinaliseVideo == NO) {
return; // still waiting on either the video or audio to finish before they can be mixed together.
}

[self movieWriterCompleteHandler];
}

// This is the continuation of endRecordingSession.
// It's called when the GPUImage movie writer has completed writing the movie.
- (void) movieWriterCompleteHandler {
Expand All @@ -655,7 +683,7 @@ - (void) movieWriterCompleteHandler {
if (showDebug) {
NSLog(@"iVidCapPro - endRecordingSession tempVideoFileName=%@\n", tempVideoFileName);
NSLog(@"iVidCapPro - endRecordingSession finalVideoFileName=%@\n", finalVideoFileName);
if (captureAudio == Audio || captureAudio == Audio_Plus_Mic)
if (captureAudio == Audio || captureAudio == Audio_Plus_Mic || captureAudio == Audio_Mic)
NSLog(@"iVidCapPro - endRecordingSession capturedAudioFileName=%@\n", capturedAudioFileName);
else
NSLog(@"iVidCapPro - endRecordingSession capturedAudioFileName=not in use\n");
Expand All @@ -669,7 +697,7 @@ - (void) movieWriterCompleteHandler {
NSLog(@"iVidCapPro - endRecordingSession userAudioFileName2=not in use\n");
}

if (captureAudio == Audio || captureAudio == Audio_Plus_Mic || userAudioFile1 != nil || userAudioFile2 != nil) {
if (captureAudio == Audio || captureAudio == Audio_Plus_Mic || captureAudio == Audio_Mic || userAudioFile1 != nil || userAudioFile2 != nil) {
// We have audio. Mix the audio and video.
[self createVideoWithAudio];

Expand Down Expand Up @@ -711,7 +739,7 @@ - (void) createVideoWithAudio {
NSURL* userAudioFileURL2 = nil;
NSURL* capturedAudioFileURL = nil;

if (captureAudio == Audio || captureAudio == Audio_Plus_Mic) {
if (captureAudio == Audio || captureAudio == Audio_Plus_Mic || captureAudio == Audio_Mic) {
// We're capturing audio from scene. Get the URL for the file.
capturedAudioFileURL = [self getDocumentsFileURL:capturedAudioFileName];
}
Expand Down Expand Up @@ -1322,6 +1350,65 @@ - (void)exportDidFinish:(AVAssetExportSession*)session
NSLog(@"iVidCapPro - exportDidFinish: exiting.");
}

- (void)micAudioRecorderKill {
if(micAudioRecorder == nil) {
return;
}
[micAudioRecorder stop];
[micAudioRecorder setDelegate:nil];
[micAudioRecorder release];
micAudioRecorder = nil;
}

- (void)micAudioRecorderStart {
[self micAudioRecorderKill];

NSError * error = nil;

AVAudioSession * audioSession = [AVAudioSession sharedInstance];
[audioSession setCategory: AVAudioSessionCategoryPlayAndRecord
withOptions: AVAudioSessionCategoryOptionDefaultToSpeaker
error: &error];
if(error){
NSLog(@"audioSession: %@ %li %@", [error domain], [error code], [[error userInfo] description]);
return;
}
[audioSession setActive:YES error:&error];
if(error){
NSLog(@"audioSession: %@ %li %@", [error domain], [error code], [[error userInfo] description]);
return;
}

NSMutableDictionary * recordSetting = [NSMutableDictionary dictionary];
[recordSetting setValue :[NSNumber numberWithInt:kAudioFormatLinearPCM] forKey:AVFormatIDKey];
[recordSetting setValue:[NSNumber numberWithFloat:44100.0] forKey:AVSampleRateKey];
[recordSetting setValue:[NSNumber numberWithInt: 2] forKey:AVNumberOfChannelsKey];
[recordSetting setValue :[NSNumber numberWithInt:16] forKey:AVLinearPCMBitDepthKey];
[recordSetting setValue :[NSNumber numberWithBool:NO] forKey:AVLinearPCMIsBigEndianKey];
[recordSetting setValue :[NSNumber numberWithBool:NO] forKey:AVLinearPCMIsFloatKey];

NSURL * url = [self getDocumentsFileURL:capturedAudioFileName];
micAudioRecorder = [[ AVAudioRecorder alloc] initWithURL:url settings:recordSetting error:&error];
if(error){
NSLog(@"micAudioRecorder: %@ %li %@", [error domain], [error code], [[error userInfo] description]);
return;
}

[micAudioRecorder setDelegate:self];
[micAudioRecorder record];
}

- (void)micAudioRecorderStop {
[micAudioRecorder stop];
}

- (void)audioRecorderDidFinishRecording:(AVAudioRecorder *)recorder
successfully:(BOOL)flag {

bMicAudioRecordFinished = YES;
[self checkAllRecordingsAreFinished];
}

@end


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,13 @@ public enum CaptureAudio {
/// <summary>
/// Audio from the scene and microphone will be recorded in addition to video.
/// </summary>
Audio_Plus_Mic = 2
Audio_Plus_Mic = 2,


/// <summary>
/// Audio from the microphone only will be recorded in addition to video.
/// </summary>
Audio_Mic = 3
}

/// <summary>
Expand Down