//
//  CSAacEncoder.h
//  CocoaSplit
//
//  Created by Zakk on 11/9/14.
//  Copyright (c) 2014 Zakk. All rights reserved.
//

#import <Foundation/Foundation.h>
#import <AudioToolbox/AudioToolbox.h>
#import <AVFoundation/AVFoundation.h>
#import "TPCircularBuffer.h"
#import "TPCircularBuffer+AudioBufferList.h"


@class CaptureController;


@interface CSAacEncoder : NSObject
{
    dispatch_queue_t encoderQueue;
    AudioCodec aacCodec;
    UInt32 maxOutputSize;
    char *magicCookie;
    int *magicCookieSize;
    
    long outputSampleCount;
    CMAudioFormatDescriptionRef cmFormat;
    void *_pcmData;
    u_int64_t _last_sample_time;
    int _last_write_sample_cnt;
    TPCircularBuffer _inputBuffer;
    TPCircularBuffer _scratchBuffer;
    dispatch_source_t _dispatch_timer;
    dispatch_semaphore_t _aSemaphore;
    
    
}

@property (assign) bool encoderStarted;
@property (weak) CaptureController *encodedReceiver;
@property (assign) int sampleRate;
@property (assign) int bitRate;
@property (assign) int preallocatedBuffersize;
@property (assign) AudioStreamBasicDescription *inputASBD;

-(void) enqueuePCM:(AudioBufferList *)pcmBuffer atTime:(const AudioTimeStamp *)atTime;
-(void) setupEncoderBuffer;

-(void) stopEncoder;



@end


