本文整理汇总了C++中Codec类的典型用法代码示例。如果您正苦于以下问题:C++ Codec类的具体用法?C++ Codec怎么用?C++ Codec使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Codec类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: encode
Bytes
encode(const Unicode& ustring,
const Bytes& encoding)
{
Codec* codec = lookup(encoding);
Bytes bstring = codec->encode(bstring);
delete codec;
return bstring;
}
示例2: decodeArray
const_byteptr decodeArray(Codec const& codec, Uint *xs, unsigned n, const_byteptr p, const_byteptr end) {
if (codec.k_max_bytes * n + p > end)
for (unsigned i = 0; i < n; ++i)
p = codec.decode(xs[i], p, end);
else
for (unsigned i = 0; i < n; ++i)
p = codec.decode(xs[i], p);
return p;
}
示例3: encodeArray
byteptr encodeArray(Codec const& codec, byteptr p, byteptr end, Uint const* xs, unsigned n) {
if (codec.k_max_bytes * n + p > end)
for (unsigned i = 0; i < n; ++i)
p = codec.encode(p, end, xs[i]);
else
for (unsigned i = 0; i < n; ++i)
p = codec.encode(p, xs[i]);
return p;
}
示例4: main
int main() {
Codec s;
vector<int> preorder({1, 2, 4, 3}), inorder({4, 2, 1, 3});
TreeNode *root = buildTree(preorder, inorder);
root->print();
cout << s.serialize(root) << endl;
TreeNode* node = s.deserialize(s.serialize(root));
node->print();
return 0;
}
示例5: main
int main(void) {
Codec codec;
vector<string> strs = {"", "vn"};
string encoded_string = codec.encode(strs);
vector<string> strs2 = codec.decode(encoded_string);
assert(strs.size() == strs2.size());
for (size_t i = 0; i < strs.size(); i++) assert(strs[i] == strs2[i]);
cout << "\nPassed All\n";
return 0;
}
示例6: OGRE_FREE
//-----------------------------------------------------------------------------
Image & Image::load(DataStreamPtr& stream, const String& type )
{
if( m_pBuffer && m_bAutoDelete )
{
OGRE_FREE(m_pBuffer, MEMCATEGORY_GENERAL);
m_pBuffer = NULL;
}
Codec * pCodec = 0;
if (!type.empty())
{
// use named codec
pCodec = Codec::getCodec(type);
}
else
{
// derive from magic number
// read the first 32 bytes or file size, if less
size_t magicLen = std::min(stream->size(), (size_t)32);
char magicBuf[32];
stream->read(magicBuf, magicLen);
// return to start
stream->seek(0);
pCodec = Codec::getCodec(magicBuf, magicLen);
}
if( !pCodec )
OGRE_EXCEPT(
Exception::ERR_INVALIDPARAMS,
"Unable to load image - unable to identify codec. Check file extension "
"and file format.",
"Image::load" );
Codec::DecodeResult res = pCodec->decode(stream);
ImageCodec::ImageData* pData =
static_cast<ImageCodec::ImageData*>(res.second.getPointer());
m_uWidth = pData->width;
m_uHeight = pData->height;
m_uDepth = pData->depth;
m_uSize = pData->size;
m_uNumMipmaps = pData->num_mipmaps;
m_uFlags = pData->flags;
// Get the format and compute the pixel size
m_eFormat = pData->format;
m_ucPixelSize = static_cast<uchar>(PixelUtil::getNumElemBytes( m_eFormat ));
// Just use internal buffer of returned memory stream
m_pBuffer = res.first->getPtr();
// Make sure stream does not delete
res.first->setFreeOnClose(false);
return *this;
}
示例7: main
int main()
{
Codec codec;
string data = "null";
TreeNode* root = codec.deserialize(data);
// print_tree(root);
auto ret = codec.serialize(root);
cout<<ret<<endl;
return 0;
}
示例8: freeMemory
//-----------------------------------------------------------------------------
Image & Image::load(DataStreamPtr& stream, const String& type )
{
freeMemory();
Codec * pCodec = 0;
if (!type.empty())
{
// use named codec
pCodec = Codec::getCodec(type);
}
else
{
// derive from magic number
// read the first 32 bytes or file size, if less
size_t magicLen = std::min(stream->size(), (size_t)32);
char magicBuf[32];
stream->read(magicBuf, magicLen);
// return to start
stream->seek(0);
pCodec = Codec::getCodec(magicBuf, magicLen);
if( !pCodec )
OGRE_EXCEPT(
Exception::ERR_INVALIDPARAMS,
"Unable to load image: Image format is unknown. Unable to identify codec. "
"Check it or specify format explicitly.",
"Image::load" );
}
Codec::DecodeResult res = pCodec->decode(stream);
ImageCodec::ImageData* pData =
static_cast<ImageCodec::ImageData*>(res.second.getPointer());
mWidth = pData->width;
mHeight = pData->height;
mDepth = pData->depth;
mBufSize = pData->size;
mNumMipmaps = pData->num_mipmaps;
mFlags = pData->flags;
// Get the format and compute the pixel size
mFormat = pData->format;
mPixelSize = static_cast<uchar>(PixelUtil::getNumElemBytes( mFormat ));
// Just use internal buffer of returned memory stream
mBuffer = res.first->getPtr();
// Make sure stream does not delete
res.first->setFreeOnClose(false);
// make sure we delete
mAutoDelete = true;
return *this;
}
示例9: OgreGuard
//-----------------------------------------------------------------------------
Image & Image::load(const String& strFileName, const String& group)
{
OgreGuard( "Image::load" );
freeData();
String strExt;
size_t pos = strFileName.find_last_of(".");
if( pos == String::npos )
OGRE_EXCEPT(
Exception::ERR_INVALIDPARAMS,
"Unable to load image file '" + strFileName + "' - invalid extension.",
"Image::load" );
while( pos != strFileName.length() - 1 )
strExt += strFileName[++pos];
Codec * pCodec = Codec::getCodec(strExt);
if( !pCodec )
OGRE_EXCEPT(
Exception::ERR_INVALIDPARAMS,
"Unable to load image file '" + strFileName + "' - invalid extension.",
"Image::load" );
DataStreamPtr encoded =
ResourceGroupManager::getSingleton().openResource(strFileName, group);
Codec::DecodeResult res = pCodec->decode(encoded);
ImageCodec::ImageData* pData =
static_cast<ImageCodec::ImageData*>(res.second.getPointer());
// Get the format and compute the pixel size
m_uWidth = pData->width;
m_uHeight = pData->height;
m_uDepth = pData->depth;
m_uSize = pData->size;
m_eFormat = pData->format;
m_uNumMipmaps = pData->num_mipmaps;
m_ucPixelSize = PixelUtil::getNumElemBytes( m_eFormat );
m_uFlags = pData->flags;
// re-use the decoded buffer
m_pBuffer = res.first->getPtr();
// ensure we don't delete when stream is closed
res.first->setFreeOnClose(false);
OgreUnguardRet( *this );
}
示例10: main
// Your Codec object will be instantiated and called as such:
// Codec codec;
// codec.decode(codec.encode(strs));
//
int main() {
Codec codec;
vector<string> strs;
strs.push_back("hello");
strs.push_back("");
strs.push_back("gaobo");
string coded_str = codec.encode(strs);
cout << "coded str: " << coded_str << endl;
vector<string> decoded_strs = codec.decode(coded_str);
for (int i = 0; i < decoded_strs.size(); i++) {
cout << decoded_strs[i] << endl;
}
return 0;
}
示例11: clear_if
void CodecContext::open(const Codec &codec, AVDictionary **options, error_code &ec)
{
clear_if(ec);
if (m_isOpened || !isValid()) {
throws_if(ec, m_isOpened ? Errors::CodecAlreadyOpened : Errors::CodecInvalid);
return;
}
int stat = avcodec_open2(m_raw, codec.isNull() ? m_raw->codec : codec.raw(), options);
if (stat < 0)
throws_if(ec, stat, ffmpeg_category());
else
m_isOpened = true;
}
示例12: getFileExtFromMagic
//---------------------------------------------------------------------
String Image::getFileExtFromMagic(DataStreamPtr stream)
{
// read the first 32 bytes or file size, if less
size_t magicLen = std::min(stream->size(), (size_t)32);
char magicBuf[32];
stream->read(magicBuf, magicLen);
// return to start
stream->seek(0);
Codec* pCodec = Codec::getCodec(magicBuf, magicLen);
if(pCodec)
return pCodec->getType();
else
return BLANKSTRING;
}
示例13: LOG4CXX_DEBUG
void Mixer::remoteStartTransmission(const ::Ice::Current& curr) {
stringstream a;
stringstream b;
LOG4CXX_DEBUG(logger, string("Mixer::remoteStartTransmission()"));
IPV4Address *tmpAddr = new IPV4Address(getRemoteAddressFromConnection(curr.con));
a << string("Mixer::remoteStartTransmission() rem hostAddr: ") << tmpAddr->getHostname();
LOG4CXX_DEBUG(logger, a.str());
TerminalInfo *info = remoteHostsM[tmpAddr->getHostname()];
if (remoteHostsM.find(tmpAddr->getHostname()) == remoteHostsM.end() ) {
cout << "ERROR info not found\n";
}
if (this->currentState != States::PASSIVE_CONNECTED) {
LOG4CXX_DEBUG(logger, string("Mixer::remoteStartTransmission() bad state"));
} else {
changeState(States::PASSIVE_OPERATIONAL);
cout << "TRANSCEIVER STARTED\n";
// TODO start RTP.RTCP transmission
CodecFactory codecfactory;
Codec* codecInc = codecfactory.getCodec(AudioCodec::PCMU); // HACK
// Codec* codecInc = codecfactory.getCodec(info->incomingCodec);
Codec* codecOut = codecfactory.getCodec(AudioCodec::PCMU);
// Codec* codecOut = codecfactory.getCodec(info->outgoingCodec); // HACK
info->transport = new TransportCCRTP();
info->transport->setParams(codecInc->getFrameCount(), codecInc->getFrameSize());
info->transport->setLocalEndpoint("0.0.0.0", localRTPPort);
info->transport->setRemoteEndpoint(info->address, info->rtpPort);
info->buf = new RingBuffer(1024*1024, 1);
// b << "Mixer::remoteStartTransmission() creating transport,
localRTPPort += 2;
stringstream a;
a << "rem address: " << info->address << " port: " << info->rtpPort;
LOG4CXX_DEBUG(logger, a.str());
info->transport->start();
LOG4CXX_DEBUG(logger, string("Mixer::remoteStartTransmission() transmission started"));
}
}
示例14: CodecFactory
bool MainObject::StartCodec()
{
Codec *codec;
if((codec=
CodecFactory(sir_config->audioFormat(),sir_ringbuffers[sir_codecs.size()],
this))==NULL) {
Log(LOG_ERR,
QString().sprintf("unsupported codec type \"%s\"",
(const char *)Codec::codecTypeText(Codec::TypeMpegL3).toUtf8()));
return false;
}
if(sir_config->audioBitrateQuantity()>0) {
codec->
setBitrate(sir_config->audioBitrate(sir_config->audioBitrateQuantity()-1));
}
else {
codec->setBitrate(0);
}
codec->setChannels(sir_config->audioChannels());
codec->setQuality(sir_config->audioQuality());
codec->setSourceSamplerate(sir_audio_device->deviceSamplerate());
codec->setStreamSamplerate(sir_config->audioSamplerate());
codec->setCompleteFrames(sir_config->audioAtomicFrames());
sir_codecs.push_back(codec);
return sir_codecs.back()->start();
}
示例15: main
int main(int argc, char const *argv[])
{
/* code */
TreeNode* n1 = new TreeNode(5);
TreeNode* n2 = new TreeNode(4);
TreeNode* n3 = new TreeNode(2);
n1 -> left = n2;
n1 -> right = n3;
TreeNode* n4 = new TreeNode(11);
n2 ->right = n4;
TreeNode* n5 = new TreeNode(7);
TreeNode* n6 = new TreeNode(8);
n3 -> left = n5;
n3 -> right = n6;
Codec c;
string test = "5,4,#,11,#,#,2,7,#,#,8,#,#,";
//c.dfs(n1);
cout << "---------" << endl;
c.dfs(c.deserialize(test));
cout << endl;
cout << c.serialize(n1)<<endl;
cout << test<<endl;
c.dfs(c.deserialize(c.serialize(n1)));
return 0;
}