/* =========================================================================

DESCRIPTION
   Netease && Xunfei speech processing main program

Copyright (c) 2017 by Netease, Co,LTD.  All Rights Reserved.
============================================================================ */

/* =========================================================================

                             REVISION
 
when                       who                                                why
--------                    ---------                          -------------------------------------------
2017/06/28          wangzijiao                                  Created.
============================================================================ */


#ifndef __RAECORD_H__
#define __RAECORD_H__

#ifdef __cplusplus
extern "C" {
#endif /* C++ */

#include <alsa/asoundlib.h>
#include "AudioQueue.h"
/* ------------------------------------------------------------------------
** Types
** ------------------------------------------------------------------------ */
typedef void* REACORD_HANDLE;
typedef void (*recordrecord_audio_fn)(const void *audio, unsigned int audio_len, int err_code);
typedef void (*record_audio_fn)(const void *audio, unsigned int audio_len, int err_code);


/* Configuration for a stream */
typedef struct _RecordData{
    snd_pcm_t *handle;
    snd_pcm_hw_params_t *params;
    audio_queue_t *queue;
    char *queue_buff;
    char *buffer; 
    snd_pcm_uframes_t frames; 
    record_audio_fn cb;
    void *user_data;
    pthread_t tid_pcm_read;
    pthread_t tid_queue_read;
    int runing;
    int backupfilefd;
    int finalfilefd;
    struct pcm_config *pcm_cfg;
    struct pcm_config *adc;
    size_t significant_bits_per_sample;
    size_t bits_per_sample;
    size_t bits_per_frame;
    snd_pcm_format_t format;
    size_t chunk_bytes;
    size_t chunk_size;
    size_t buff_size;
    size_t buffer_time;
    size_t period_time;

    size_t buffer_frames;
    size_t period_frames;

}RecordData;

struct pcm_config {
    char *device_name;
    unsigned int channels;
    unsigned int rate;
    unsigned int period_size;
    unsigned int period_count;
    record_audio_fn audio_cb;
    RecordData *recordata;
    RecordData *adc;
    char *format;
    char *backupfilename;
    char *finalfilename;
    int backupfile_waveformat;
};

int Neteasae_record_start(struct pcm_config *pcm_cfg);
void Netease_record_stop(struct pcm_config *pcm_cfg);
void device_list(void);
void pcm_list(void);

#ifdef __cplusplus
} /* extern "C" */	
#endif /* C++ */

#endif /* __RAECORD_H__ */



