- fixes to parse EVS payload types with CMR & ToC

This commit is contained in:
Dmytro Bogovych 2020-07-02 13:09:22 +03:00
parent ed12569ad6
commit 328ae8d5b5
2 changed files with 31 additions and 9 deletions

View File

@ -32,7 +32,10 @@ CodecList::Settings::EvsSpec CodecList::Settings::EvsSpec::parse(const std::stri
auto parts = strx::split(spec, "-/");
if (parts.size() == 3)
{
// Payload type number
result.mPayloadType = strx::toInt(strx::trim(parts.front()).c_str(), -1);
// Encoding
std::string& encoding_type = parts[1];
if (encoding_type == "mime")
result.mEncodingType = Encoding_MIME;
@ -42,6 +45,7 @@ CodecList::Settings::EvsSpec CodecList::Settings::EvsSpec::parse(const std::stri
else
throw std::logic_error("Bad EVS codec encoding type");
// Bandwidth
std::string& bandwidth = parts.back();
if (bandwidth == "nb" || bandwidth == "NB")
result.mBandwidth = Bandwidth_NB;

View File

@ -202,17 +202,35 @@ int EVSCodec::decode(const void* input, int input_length, void* output, int outp
std::string buffer;
/*if we have FixedPayload without ToC*/
if (FixedPayload_EVSPrimary.find(input_length * 8) != FixedPayload_EVSPrimary.end())
// Check if we get payload with CMR
auto payload_iter = FixedPayload_EVSPrimary.find((input_length - 2) * 8);
if (payload_iter == FixedPayload_EVSPrimary.end())
{
char c = evs::rate2EVSmode(FixedPayload_EVSPrimary.find(input_length * 8)->second);
/* Add ToC byte.
* WARNING maybe it will be work incorrect with 56bit payload,
* see 3GPP TS 26.445 Annex A, A.2.1.3 */
buffer += c;
}
// Check if we get payload with ToC and without CMR
payload_iter = FixedPayload_EVSPrimary.find((input_length - 1) * 8);
if (payload_iter == FixedPayload_EVSPrimary.end())
{
// Maybe there is no ToC ?
payload_iter = FixedPayload_EVSPrimary.find(input_length * 8);
if (payload_iter == FixedPayload_EVSPrimary.end())
{
// Bad payload size at all
return 0;
}
/* Add ToC byte.
* WARNING maybe it will be work incorrect with 56bit payload,
* see 3GPP TS 26.445 Annex A, A.2.1.3 */
char c = evs::rate2EVSmode(FixedPayload_EVSPrimary.find(input_length * 8)->second);
buffer += c;
buffer += std::string(reinterpret_cast<const char*>(input), input_length);
}
else
buffer = std::string(reinterpret_cast<const char*>(input), input_length);
}
else
// Skip CMR byte
buffer = std::string(reinterpret_cast<const char*>(input) + 1, input_length);
buffer += std::string(reinterpret_cast<const char*>(input), input_length);
// Output buffer for 48 KHz
float data[L_FRAME48k];