100 lines
2.8 KiB
C++
100 lines
2.8 KiB
C++
/*
|
|
*******************************************************************************
|
|
* INCLUDE
|
|
*******************************************************************************
|
|
*/
|
|
#include "Util.h"
|
|
#include <Poco/Exception.h>
|
|
#include <Poco/Format.h>
|
|
#include <array>
|
|
|
|
namespace Video
|
|
{
|
|
namespace MPP5
|
|
{
|
|
/*
|
|
*******************************************************************************
|
|
* TYPEDEFS
|
|
*******************************************************************************
|
|
*/
|
|
struct CodecIDMapItem
|
|
{
|
|
Core::CodecID id;
|
|
hi_payload_type pt;
|
|
};
|
|
|
|
/*
|
|
*******************************************************************************
|
|
* LOCAL VARIABLES
|
|
*******************************************************************************
|
|
*/
|
|
static const std::array<CodecIDMapItem, 7> codecMap = {{
|
|
{Core::CodecID::H264, HI_PT_H264},
|
|
{Core::CodecID::H265, HI_PT_H265},
|
|
{Core::CodecID::MJPEG, HI_PT_MJPEG},
|
|
{Core::CodecID::MP3, HI_PT_MP3},
|
|
{Core::CodecID::AAC, HI_PT_AAC},
|
|
{Core::CodecID::G711A, HI_PT_G711A},
|
|
{Core::CodecID::G711U, HI_PT_G711U},
|
|
}};
|
|
|
|
/*
|
|
*******************************************************************************
|
|
* FUNCTIONS
|
|
*******************************************************************************
|
|
*/
|
|
|
|
static hi_payload_type findPayloadType(Core::CodecID id)
|
|
{
|
|
for (const auto& m : codecMap)
|
|
{
|
|
if (id == m.id)
|
|
return m.pt;
|
|
}
|
|
|
|
throw Poco::NotFoundException(Poco::format("Video::MPP5: Can't find %s in codec-map", Core::codecIDToString(id)));
|
|
}
|
|
|
|
/*
|
|
*******************************************************************************
|
|
* CLASS DECLARE
|
|
*******************************************************************************
|
|
*/
|
|
hi_audio_bit_width Util::getBitWidth(Core::SampleFormat format)
|
|
{
|
|
if (16 == Core::sampleFormatBitWidth(format))
|
|
return HI_AUDIO_BIT_WIDTH_16;
|
|
|
|
throw Poco::InvalidArgumentException("MPP5: Only support 16 bit-width", -EINVAL);
|
|
}
|
|
|
|
hi_audio_snd_mode Util::getSndMode(Core::ChannelLayout layout)
|
|
{
|
|
if (Core::ChannelLayout::STEREO == layout)
|
|
return HI_AUDIO_SOUND_MODE_STEREO;
|
|
|
|
return HI_AUDIO_SOUND_MODE_MONO;
|
|
}
|
|
|
|
hi_payload_type Util::getPayloadType(Core::CodecID id)
|
|
{
|
|
return findPayloadType(id);
|
|
}
|
|
|
|
uint32_t Util::getChannelId(const std::string& name)
|
|
{
|
|
if (name.find("NET0") != std::string::npos)
|
|
return 2;
|
|
else if (name.find("NET1") != std::string::npos)
|
|
return 3;
|
|
else if (name.find("NET2") != std::string::npos)
|
|
return 4;
|
|
else if (name.find("NET3") != std::string::npos)
|
|
return 5;
|
|
else if (name.find("USB") != std::string::npos)
|
|
return 6;
|
|
else if (name.find("File") != std::string::npos)
|
|
return 7;
|
|
}
|
|
}
|
|
}
|