#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <stdarg.h>
#include <signal.h>
#include <errno.h>
#include <assert.h>
#include <math.h>
#include <sys/time.h>
#include <netinet/tcp.h>

// SocketWrapper.h 
#include <sys/socket.h>
#include <sys/types.h>
#include <sys/time.h>
#include <sys/select.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>

#include <unistd.h>
#include <errno.h>

//#include "SocketWrapper.h"
#include "ulaw.h"
#include "SayTranUtil.h"

#define ERROR_SVR_INFO			-1
#define ERROR_SVR_CONNECT		-2

#define AUDIO_TYPE_MULAW		1
#define AUDIO_TYPE_PCM			2

#define ERR_INVALID_USER_LENGTH		-100
#define ERR_RECV_RECOG_DATA		-300

#define SUCCESS_SEND_DATA		100
#define SUCCESS_RECV_HEADER_DATA	200
#define SUCCESS_RECV_RECOG_DATA		300

#if defined(_16K_AUDIO_)
#define SAMP_PER_MS			16
#elif defined(_8K_AUDIO_)
#define SAMP_PER_MS			8
#else
#define SAMP_PER_MS			16
#endif
#define FRAME_SHIFT			10 * SAMP_PER_MS	// One frame size

// Open
int VST_Connect_To_Server(char *server_ip, int server_port);

// Close
int VST_Disconnect(int sockfd);

// Write (Send)
int VST_Send_Header_Data(int sockfd, char *User, char *Type);
int VST_Send_Audio_Data(int sockfd, char *data, short len);
int VST_Send_Final_Data(int sockfd, char *data, int sample_rate, int type);

// Read (Recv)
int VST_Recv_Header_Data(int sockfd, int *code, int *size);
int VST_Recv_Recog_Data(int sockfd, int size, char *result, FILE *output);

// Option
long VST_Get_filesize(FILE *fd);