179 lines
4 KiB
C
179 lines
4 KiB
C
|
#pragma once
|
||
|
|
||
|
#define WINDOWS 1
|
||
|
|
||
|
#ifdef WINDOWS
|
||
|
#include <iostream>
|
||
|
#endif // WINDOWS
|
||
|
|
||
|
|
||
|
#define MTU_SIZE 1500
|
||
|
#define VBAN_MAX_PACKET MTU_SIZE - sizeof(VBAN_HEADER) -28
|
||
|
|
||
|
typedef long long uint32_t ;
|
||
|
typedef unsigned char uint8_t;
|
||
|
typedef unsigned short uint16_t;
|
||
|
|
||
|
#pragma pack(1)
|
||
|
struct VBAN_HEADER
|
||
|
{
|
||
|
uint32_t vban; // contains 'V' 'B', 'A', 'N'
|
||
|
uint8_t format_SR; // SR index (see SRList above)
|
||
|
uint8_t format_nbs; // nb sample per frame (1 to 256)
|
||
|
uint8_t format_nbc; // nb channel (1 to 256)
|
||
|
uint8_t format_bit; // mask = 0x07 (see DATATYPE table below)
|
||
|
char streamname[16]; // stream name
|
||
|
uint32_t nuFrame; // growing frame number
|
||
|
};
|
||
|
#pragma pack()
|
||
|
|
||
|
#define VBAN_CODEC_PCM 0x00
|
||
|
#define VBAN_CODEC_VBCA 0x10 //VB-AUDIO AOIP CODEC
|
||
|
#define VBAN_CODEC_VBCV 0x20 //VB-AUDIO VOIP CODEC
|
||
|
#define VBAN_CODEC_UNDEFINED_1 0x30
|
||
|
#define VBAN_CODEC_UNDEFINED_2 0x40
|
||
|
#define VBAN_CODEC_UNDEFINED_3 0x50
|
||
|
#define VBAN_CODEC_UNDEFINED_4 0x60
|
||
|
#define VBAN_CODEC_UNDEFINED_5 0x70
|
||
|
#define VBAN_CODEC_UNDEFINED_6 0x80
|
||
|
#define VBAN_CODEC_UNDEFINED_7 0x90
|
||
|
#define VBAN_CODEC_UNDEFINED_8 0xA0
|
||
|
#define VBAN_CODEC_UNDEFINED_9 0xB0
|
||
|
#define VBAN_CODEC_UNDEFINED_10 0xC0
|
||
|
#define VBAN_CODEC_UNDEFINED_11 0xD0
|
||
|
#define VBAN_CODEC_UNDEFINED_12 0xE0
|
||
|
#define VBAN_CODEC_USER 0xF0
|
||
|
|
||
|
enum VBAN_CODEC
|
||
|
{
|
||
|
CODEC_PCM = 0x00,
|
||
|
CODEC_VBCA = 0x10,
|
||
|
CODEC_VBCV = 0x20,
|
||
|
CODEC_UNDEF1 = 0x30,
|
||
|
CODEC_UNDEF2 = 0x40,
|
||
|
CODEC_UNDEF3 = 0x50,
|
||
|
CODEC_UNDEF4 = 0x60,
|
||
|
CODEC_UNDEF5 = 0x70,
|
||
|
CODEC_UNDEF6 = 0x80,
|
||
|
CODEC_UNDEF7 = 0x90,
|
||
|
CODEC_UNDEF8 = 0xA0,
|
||
|
CODEC_UNDEF9 = 0xB0,
|
||
|
CODEC_UNDEF10 = 0xC0,
|
||
|
CODEC_UNDEF11 = 0xD0,
|
||
|
CODEC_UNDEF12 = 0xE0,
|
||
|
CODEC_USER = 0xF0
|
||
|
|
||
|
};
|
||
|
|
||
|
#define VBAN_DATATYPE_BYTE8 0x00
|
||
|
#define VBAN_DATATYPE_INT16 0x01
|
||
|
#define VBAN_DATATYPE_INT24 0x02
|
||
|
#define VBAN_DATATYPE_INT32 0x03
|
||
|
#define VBAN_DATATYPE_FLOAT32 0x04
|
||
|
#define VBAN_DATATYPE_FLOAT64 0x05
|
||
|
#define VBAN_DATATYPE_12BITS 0x06
|
||
|
#define VBAN_DATATYPE_10BITS 0x07
|
||
|
|
||
|
enum VBAN_DATATYPE
|
||
|
{
|
||
|
DATATYPE_BYTE8 = 0x00,
|
||
|
DATATYPE_INT16 = 0x01,
|
||
|
DATATYPE_INT24 = 0x02,
|
||
|
DATATYPE_INT32 = 0x03,
|
||
|
DATATYPE_FLOAT32= 0x04,
|
||
|
DATATYPE_FLOAT64= 0x05,
|
||
|
DATATYPE_12BITS =0x06,
|
||
|
DATATYPE_10BITS =0x07
|
||
|
};
|
||
|
|
||
|
#define VBAN_PROTOCOL_AUDIO 0x00
|
||
|
#define VBAN_PROTOCOL_SERIAL 0x20
|
||
|
#define VBAN_PROTOCOL_TXT 0x40
|
||
|
#define VBAN_PROTOCOL_SERVICE 0x60
|
||
|
#define VBAN_PROTOCOL_UNDEFINED_1 0x80
|
||
|
#define VBAN_PROTOCOL_UNDEFINED_2 0xA0
|
||
|
#define VBAN_PROTOCOL_UNDEFINED_3 0xC0
|
||
|
#define VBAN_PROTOCOL_USER 0xE0
|
||
|
|
||
|
enum VBAN_PROTOCOL
|
||
|
{
|
||
|
PROTOCOL_AUDIO = 0x00,
|
||
|
PROTOCOL_SERIAL = 0x20,
|
||
|
PROTOCOL_TXT = 0x40,
|
||
|
PROTOCOL_SERVICE = 0x60,
|
||
|
PROTOCOL_UNDEFINED_1 = 0x80,
|
||
|
PROTOCOL_UNDEFINED_2 = 0xA0,
|
||
|
PROTOCOL_UNDEFINED_3 = 0xC0,
|
||
|
PROTOCOL_USER = 0xE0
|
||
|
};
|
||
|
|
||
|
|
||
|
#define VBAN_SR_MAXNUMBER 21
|
||
|
static long VBAN_SRList[VBAN_SR_MAXNUMBER] =
|
||
|
{ 6000, 12000, 24000, 48000, 96000, 192000, 384000,
|
||
|
8000, 16000, 32000, 64000, 128000, 256000, 512000,
|
||
|
11025, 22050, 44100, 88200, 176400, 352800, 705600 };
|
||
|
|
||
|
enum VBAN_SAMPLERATE
|
||
|
{
|
||
|
SR_6000,
|
||
|
SR_12000,
|
||
|
SR_24000,
|
||
|
SR_48000,
|
||
|
SR_96000,
|
||
|
SR_192000,
|
||
|
SR_384000,
|
||
|
SR_8000,
|
||
|
SR_16000,
|
||
|
SR_32000,
|
||
|
SR_64000,
|
||
|
SR_128000,
|
||
|
SR_256000,
|
||
|
SR_512000,
|
||
|
SR_11025,
|
||
|
SR_22050,
|
||
|
SR_44100,
|
||
|
SR_88200,
|
||
|
SR_176400,
|
||
|
SR_352800,
|
||
|
SR_705600
|
||
|
};
|
||
|
|
||
|
typedef int VBAN_StreamSamplesReady(VBAN_STREAM* stream, char* samples, int noSamples);
|
||
|
|
||
|
typedef struct VBAN_handle
|
||
|
{
|
||
|
VBAN_STREAM* streams;
|
||
|
uint8_t noStreams;
|
||
|
|
||
|
VBAN_StreamSamplesReady* readyCallback;
|
||
|
} VBAN_handle;
|
||
|
|
||
|
|
||
|
typedef struct VBAN_STREAM
|
||
|
{
|
||
|
char name[16];
|
||
|
VBAN_CODEC codec;
|
||
|
VBAN_SAMPLERATE samplerate;
|
||
|
VBAN_DATATYPE datatype;
|
||
|
uint8_t noChannels;
|
||
|
|
||
|
uint32_t frameCounter;
|
||
|
|
||
|
char* buffer;
|
||
|
uint16_t bufferSize;
|
||
|
} VBAN_STREAM;
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
//Returns -1 for error
|
||
|
int VBAN_Init(VBAN_handle*, char * buffer, uint16_t bufferSize);
|
||
|
|
||
|
int VBAN_GetCodec();
|
||
|
|
||
|
//Returns the size of the byte in the packet, -1 means error
|
||
|
int VBAN_Encode(VBAN_handle *handle, char *packet, uint16_t packetSize, char* audioStream, uint16_t noSamples);
|
||
|
|
||
|
//Returns the number of samples decoded from the packet, -1 means error
|
||
|
int VBAN_Decode(VBAN_handle* handle, char* packet, uint16_t packetSize, char* audioStream, uint16_t noSamples);
|