- more work on EVS decoder

This commit is contained in:
Dmytro Bogovych 2020-06-16 09:09:15 +03:00
parent 0072713705
commit 3f797bd09c
7 changed files with 47 additions and 55 deletions

View File

@ -66,20 +66,20 @@
// AMR codec defines - it requires USE_AMR_CODEC defined // AMR codec defines - it requires USE_AMR_CODEC defined
// #define USE_AMR_CODEC // #define USE_AMR_CODEC
#define MT_AMRNB_PAYLOADTYPE -1 #define MT_AMRNB_PAYLOADTYPE 122
#define MT_AMRNB_CODECNAME "amr" #define MT_AMRNB_CODECNAME "amr"
#define MT_AMRNB_OCTET_PAYLOADTYPE -1 #define MT_AMRNB_OCTET_PAYLOADTYPE 123
#define MT_AMRWB_PAYLOADTYPE -1 #define MT_AMRWB_PAYLOADTYPE 124
#define MT_AMRWB_CODECNAME "amr-wb" #define MT_AMRWB_CODECNAME "amr-wb"
#define MT_AMRWB_OCTET_PAYLOADTYPE -1 #define MT_AMRWB_OCTET_PAYLOADTYPE 125
#define MT_GSMEFR_PAYLOADTYPE -1 #define MT_GSMEFR_PAYLOADTYPE 126
#define MT_GSMEFR_CODECNAME "GERAN-EFR" #define MT_GSMEFR_CODECNAME "GERAN-EFR"
#define MT_EVS_PAYLOADTYPE -1 #define MT_EVS_PAYLOADTYPE 127
#define MT_EVS_CODECNAME "EVS" #define MT_EVS_CODECNAME "EVS"
// OPUS codec defines // OPUS codec defines

View File

@ -53,7 +53,7 @@ bool RtpHelper::isRtp(const void* buffer, size_t length)
return false; return false;
unsigned char _type = reinterpret_cast<const RtpHeader*>(buffer)->pt; unsigned char _type = reinterpret_cast<const RtpHeader*>(buffer)->pt;
bool rtp = ( (_type & 0x7F) >= 96 && (_type & 0x7F) < 127) || ((_type & 0x7F) < 35); bool rtp = ( (_type & 0x7F) >= 96 && (_type & 0x7F) <= 127) || ((_type & 0x7F) < 35);
return rtp; return rtp;
} }

View File

@ -738,11 +738,17 @@ int AudioReceiver::timelengthFor(jrtplib::RTPPacket& p)
PCodec codec = codecIter->second; PCodec codec = codecIter->second;
if (codec) if (codec)
{ {
int frameCount = static_cast<int>(p.GetPayloadLength() / codec->rtpLength()); int frame_count = 0;
if (p.GetPayloadType() == 9/*G729A silence*/ && p.GetPayloadLength() % codec->rtpLength()) if (codec->rtpLength() != 0)
frameCount++; {
frame_count = static_cast<int>(p.GetPayloadLength() / codec->rtpLength());
if (p.GetPayloadType() == 9/*G729A silence*/ && p.GetPayloadLength() % codec->rtpLength())
frame_count++;
}
else
frame_count = 1;
return frameCount * codec->frameTime(); return frame_count * codec->frameTime();
} }
else else
return 0; return 0;

View File

@ -49,10 +49,20 @@ public:
virtual const char* name() = 0; virtual const char* name() = 0;
virtual int samplerate() = 0; virtual int samplerate() = 0;
virtual float timestampUnit() { return float(1.0 / samplerate()); } virtual float timestampUnit() { return float(1.0 / samplerate()); }
// Size of decoded audio frame in bytes
virtual int pcmLength() = 0; virtual int pcmLength() = 0;
// Time length of single audio frame
virtual int frameTime() = 0; virtual int frameTime() = 0;
// Size of RTP frame in bytes. Can be zero for variable sized codecs.
virtual int rtpLength() = 0; virtual int rtpLength() = 0;
// Number of audio channels
virtual int channels() { return 1; } virtual int channels() { return 1; }
virtual int encode(const void* input, int inputBytes, void* output, int outputCapacity) = 0; virtual int encode(const void* input, int inputBytes, void* output, int outputCapacity) = 0;
virtual int decode(const void* input, int inputBytes, void* output, int outputCapacity) = 0; virtual int decode(const void* input, int inputBytes, void* output, int outputCapacity) = 0;
virtual int plc(int lostFrames, void* output, int outputCapacity) = 0; virtual int plc(int lostFrames, void* output, int outputCapacity) = 0;

View File

@ -62,8 +62,7 @@ CodecList::CodecList(const Settings& settings)
mFactoryList.push_back(new GsmHrCodec::GsmHrFactory(mSettings.mGsmHrPayloadType)); mFactoryList.push_back(new GsmHrCodec::GsmHrFactory(mSettings.mGsmHrPayloadType));
#endif #endif
if (mSettings.mEvsPayloadType != -1) mFactoryList.push_back(new EVSCodec::EVSFactory(EVSCodec::StreamParameters()));
mFactoryList.push_back(new EVSCodec::EVSFactory(EVSCodec::StreamParameters()));
} }
CodecList::~CodecList() CodecList::~CodecList()
@ -79,7 +78,7 @@ int CodecList::count() const
Codec::Factory& CodecList::codecAt(int index) const Codec::Factory& CodecList::codecAt(int index) const
{ {
return *mFactoryList[index]; return *mFactoryList[static_cast<size_t>(index)];
} }
int CodecList::findCodec(const std::string &name) const int CodecList::findCodec(const std::string &name) const
@ -157,12 +156,12 @@ void CodecListPriority::setupFrom(PVariantMap vmap)
} }
} }
int CodecListPriority::count(const CodecList &cl) const int CodecListPriority::count(const CodecList & /*cl*/) const
{ {
return mPriorityList.size(); return static_cast<int>(mPriorityList.size());
} }
Codec::Factory& CodecListPriority::codecAt(const CodecList& cl, int index) const Codec::Factory& CodecListPriority::codecAt(const CodecList& cl, int index) const
{ {
return cl.codecAt(mPriorityList[index].mCodecIndex); return cl.codecAt(mPriorityList[static_cast<size_t>(index)].mCodecIndex);
} }

View File

@ -129,7 +129,7 @@ int EVSCodec::EVSFactory::samplerate()
int EVSCodec::EVSFactory::payloadType() int EVSCodec::EVSFactory::payloadType()
{ {
return 0; return MT_EVS_PAYLOADTYPE;
} }
PCodec EVSCodec::EVSFactory::create() PCodec EVSCodec::EVSFactory::create()
@ -145,19 +145,10 @@ EVSCodec::EVSCodec(const StreamParameters &sp)
{ {
EVSCodec::sp = sp; EVSCodec::sp = sp;
if ((st_dec = (evs::Decoder_State*)malloc(sizeof(evs::Decoder_State))) == NULL) if ((st_dec = reinterpret_cast<evs::Decoder_State*>(malloc(sizeof(evs::Decoder_State)))) == nullptr)
{ throw std::bad_alloc();
std::stringstream out;
out << "Can not allocate memory for decoder state structure\n"; initDecoder(sp);
throw std::out_of_range(out.str());
}
/*if ((st_enc = (Encoder_State*)malloc(sizeof(Encoder_State))) == NULL)
{
std::stringstream out;
out << "Can not allocate memory for encoder state structure\n";
throw std::out_of_range(out.str());
}*/
initDecoder(sp);
} }
EVSCodec::~EVSCodec() EVSCodec::~EVSCodec()
@ -165,7 +156,7 @@ EVSCodec::~EVSCodec()
if (st_dec) if (st_dec)
{ {
destroy_decoder(st_dec); destroy_decoder(st_dec);
free(st_dec); free(st_dec); st_dec = nullptr;
} }
} }
@ -174,19 +165,9 @@ int EVSCodec::samplerate()
return st_dec->output_Fs; return st_dec->output_Fs;
} }
int EVSCodec::samplerate(int CodecMode)
{
return samplerate();
}
int EVSCodec::pcmLength() int EVSCodec::pcmLength()
{ {
return samplerate() / 50; return samplerate() / 50 * 2;
}
int EVSCodec::pcmLength(int CodecMode)
{
return pcmLength();
} }
int EVSCodec::frameTime() int EVSCodec::frameTime()
@ -196,22 +177,20 @@ int EVSCodec::frameTime()
int EVSCodec::rtpLength() int EVSCodec::rtpLength()
{ {
// Variable sized codec - bitrate can be changed during the call
return 0; return 0;
} }
int EVSCodec::encode(const void* input, int inputBytes, void* output, int outputCapacity) int EVSCodec::encode(const void* input, int inputBytes, void* output, int outputCapacity)
{ {
// Encoding is not supported yet.
return 0; return 0;
} }
int EVSCodec::decode(const void* input, int input_length, void* output, int outputCapacity) int EVSCodec::decode(const void* input, int input_length, void* output, int outputCapacity)
{ {
if (outputCapacity < L_FRAME8k) if (outputCapacity < pcmLength())
{ return 0;
std::stringstream out;
out << "Buffer for pcm frame is to small\n";
throw std::out_of_range(out.str());
}
std::string buffer; std::string buffer;
@ -260,15 +239,15 @@ int EVSCodec::decode(const void* input, int input_length, void* output, int outp
} }
/* convert 'float' output data to 'short' */ /* convert 'float' output data to 'short' */
evs::syn_output(data, this->pcmLength(), static_cast<short*>(output) + offset); evs::syn_output(data, static_cast<short>(pcmLength() / 2), static_cast<short*>(output) + offset);
offset += this->pcmLength(); offset += pcmLength() / 2;
if (st_dec->ini_frame < MAX_FRAME_COUNTER) if (st_dec->ini_frame < MAX_FRAME_COUNTER)
{ {
st_dec->ini_frame++; st_dec->ini_frame++;
} }
} }
// std::fclose(temp);
return 1; return pcmLength();
} }
int EVSCodec::plc(int lostFrames, void* output, int outputCapacity) int EVSCodec::plc(int lostFrames, void* output, int outputCapacity)

View File

@ -53,9 +53,7 @@ public:
const char* name() { return MT_EVS_CODECNAME; }; const char* name() { return MT_EVS_CODECNAME; };
int samplerate(); int samplerate();
int samplerate(int CodecMode); // DEC or ENC defined in cnst.h
int pcmLength(); int pcmLength();
int pcmLength(int CodecMode); // DEC or ENC defined in cnst.h
int frameTime(); int frameTime();
int rtpLength(); int rtpLength();
int encode(const void* input, int inputBytes, void* output, int outputCapacity); int encode(const void* input, int inputBytes, void* output, int outputCapacity);