175 lines
3.9 KiB
C++
175 lines
3.9 KiB
C++
#pragma once
|
|
|
|
#include <iostream>
|
|
#include "Observer.h"
|
|
#include "Subject.h"
|
|
|
|
#define MTU_SIZE 1500
|
|
#define VBAN_MAX_PACKET MTU_SIZE - sizeof(VBAN_HEADER) -28
|
|
|
|
|
|
typedef unsigned int uint32_t ;
|
|
typedef unsigned char uint8_t;
|
|
typedef unsigned short uint16_t;
|
|
|
|
#define VBAN_MARKER 0x4e414256
|
|
|
|
|
|
#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 noFrame; // 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
|
|
};
|
|
|
|
class VBAN_Stream;
|
|
|
|
typedef int (*VBAN_StreamSamplesReady)(VBAN_Stream* stream, char* samples, int noSamples);
|
|
|
|
class VBAN_Stream :public Observer
|
|
{
|
|
public:
|
|
VBAN_Stream(std::string name, VBAN_CODEC codec, VBAN_SAMPLERATE samplerate, VBAN_DATATYPE datatype, uint8_t noChannels);
|
|
virtual ~VBAN_Stream();
|
|
|
|
|
|
int encodePacket(char * packet, uint16_t packetSize);
|
|
int decodePacket(char* packet, uint16_t packetSize);
|
|
|
|
std::pair<char*, unsigned int>* getLastPacket();
|
|
void dropLastPacket();
|
|
|
|
void update(Subject* s);
|
|
private:
|
|
std::string m_name;
|
|
VBAN_CODEC m_codec;
|
|
VBAN_SAMPLERATE m_samplerate;
|
|
VBAN_DATATYPE m_datatype;
|
|
uint8_t m_noChannels;
|
|
|
|
uint32_t m_FrameCounter;
|
|
|
|
VBAN_StreamSamplesReady m_packetReadyCB;
|
|
|
|
std::list<std::pair<char*,unsigned int>> m_packetBuffer;
|
|
VBAN_HEADER m_header;
|
|
};
|