本文整理汇总了C++中json::Value::toPacked方法的典型用法代码示例。如果您正苦于以下问题:C++ Value::toPacked方法的具体用法?C++ Value::toPacked怎么用?C++ Value::toPacked使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类json::Value
的用法示例。
在下文中一共展示了Value::toPacked方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: DTSCFix
//.........这里部分代码省略.........
long long int firstms = 0x7fffffff;
long long int lastms = -1;
for (std::map<std::string,HeaderEntryDTSC>::iterator it = trackData.begin(); it != trackData.end(); it++){
if (it->second.firstms < firstms){
firstms = it->second.firstms;
}
if (it->second.lastms > lastms){
lastms = it->second.lastms;
}
meta["tracks"][it->first]["firstms"] = it->second.firstms;
meta["tracks"][it->first]["lastms"] = it->second.lastms;
meta["tracks"][it->first]["length"] = (it->second.lastms - it->second.firstms) / 1000;
if ( !meta["tracks"][it->first].isMember("bps")){
meta["tracks"][it->first]["bps"] = (long long int)(it->second.lastms / ((it->second.lastms - it->second.firstms) / 1000));
}
if (it->second.trackID != 0){
meta["tracks"][it->first]["trackid"] = trackIDs[it->first];
}else{
meta["tracks"][it->first]["trackid"] = nextFreeID ++;
}
meta["tracks"][it->first]["type"] = it->second.type;
int tmp = meta["tracks"][it->first]["keys"].size();
if (tmp > 0){
if (tmp > 1){
meta["tracks"][it->first]["keys"][tmp - 1]["len"] = it->second.lastms - meta["tracks"][it->first]["keys"][tmp - 2]["time"].asInt();
}else{
meta["tracks"][it->first]["keys"][tmp - 1]["len"] = it->second.lastms;
}
meta["tracks"][it->first]["keys"][tmp - 1]["size"] = it->second.totalSize;
std::string encodeVec = JSON::encodeVector( trackData[it->first].parts.begin(), trackData[it->first].parts.end() );
meta["tracks"][it->first]["keys"][tmp - 1]["parts"] = encodeVec;
meta["tracks"][it->first]["keys"][tmp - 1]["partsize"] = (long long int)trackData[it->first].parts.size();
}else{
meta["tracks"][it->first]["keys"][tmp]["len"] = it->second.lastms;
meta["tracks"][it->first]["keys"][tmp]["size"] = it->second.totalSize;
std::string encodeVec = JSON::encodeVector( trackData[it->first].parts.begin(), trackData[it->first].parts.end() );
meta["tracks"][it->first]["keys"][tmp]["parts"] = encodeVec;
meta["tracks"][it->first]["keys"][tmp]["partsize"] = (long long int)trackData[it->first].parts.size();
meta["tracks"][it->first]["keys"][tmp]["time"] = it->second.firstms;
}
//calculate fragments
meta["tracks"][it->first]["frags"].null();
long long int currFrag = -1;
long long int maxBps = 0;
for (JSON::ArrIter arrIt = meta["tracks"][it->first]["keys"].ArrBegin(); arrIt != meta["tracks"][it->first]["keys"].ArrEnd(); arrIt++) {
if ((*arrIt)["time"].asInt() / 10000 > currFrag){
currFrag = (*arrIt)["time"].asInt() / 10000;
long long int fragLen = 1;
long long int fragDur = (*arrIt)["len"].asInt();
long long int fragSize = (*arrIt)["size"].asInt();
for (JSON::ArrIter it2 = arrIt + 1; it2 != meta["tracks"][it->first]["keys"].ArrEnd(); it2++){
if ((*it2)["time"].asInt() / 10000 > currFrag || (it2 + 1) == meta["tracks"][it->first]["keys"].ArrEnd()){
JSON::Value thisFrag;
thisFrag["num"] = (*arrIt)["num"].asInt();
thisFrag["time"] = (*arrIt)["time"].asInt();
thisFrag["len"] = fragLen;
thisFrag["dur"] = fragDur;
thisFrag["size"] = fragSize;
if (fragDur / 1000){
thisFrag["bps"] = fragSize / (fragDur / 1000);
if (maxBps < (fragSize / (fragDur / 1000))){
maxBps = (fragSize / (fragDur / 999));
}
} else {
thisFrag["bps"] = 1;
}
meta["tracks"][it->first]["frags"].append(thisFrag);
break;
}
fragLen ++;
fragDur += (*it2)["len"].asInt();
fragSize += (*it2)["size"].asInt();
}
}
}
meta["tracks"][it->first]["maxbps"] = maxBps;
}
meta["firstms"] = firstms;
meta["lastms"] = lastms;
meta["length"] = (lastms - firstms) / 1000;
//append the revised header
std::string loader = meta.toPacked();
long long int newHPos = F.addHeader(loader);
if ( !newHPos){
std::cerr << "Failure appending new header." << std::endl;
return -1;
}
//re-write the original header with information about the location of the new one
oriheader["moreheader"] = newHPos;
loader = oriheader.toPacked();
if (F.writeHeader(loader)){
return 0;
}else{
std::cerr << "Failure rewriting header." << std::endl;
return -1;
}
} //DTSCFix
示例2: DTSCMerge
int DTSCMerge(int argc, char ** argv){
Util::Config conf = Util::Config(argv[0], PACKAGE_VERSION);
conf.addOption("output", JSON::fromString("{\"arg_num\":1, \"arg\":\"string\", \"help\":\"Filename of the output file.\"}"));
conf.addOption("input", JSON::fromString("{\"arg_num\":2, \"arg\":\"string\", \"help\":\"Filename of the first input file.\"}"));
conf.addOption("[additional_inputs ...]", JSON::fromString("{\"arg_num\":3, \"default\":\"\", \"arg\":\"string\", \"help\":\"Filenames of any number of aditional inputs.\"}"));
conf.parseArgs(argc, argv);
DTSC::File outFile;
JSON::Value meta;
DTSC::Meta newMeta;
std::map<std::string,std::map<int, int> > trackMapping;
bool fullSort = true;
std::map<std::string, DTSC::File> inFiles;
std::map<std::string, DTSC::Meta> metaData;
std::string outFileName = argv[1];
std::string tmpFileName;
for (int i = 2; i < argc; i++){
tmpFileName = argv[i];
if (tmpFileName == outFileName){
fullSort = false;
}else{
DTSC::File F(tmpFileName);
if (!F.getMeta().isFixed()){
std::cerr << tmpFileName << " has not been run through DTSCFix yet." << std::endl;
return 1;
}
inFiles[tmpFileName] = F;
}
}
if (fullSort){
outFile = DTSC::File(outFileName, true);
}else{
outFile = DTSC::File(outFileName);
if ( !outFile.getMeta().isFixed()){
std::cerr << outFileName << " has not been run through DTSCFix yet." << std::endl;
return 1;
}
meta = outFile.getMeta().toJSON();
newMeta = DTSC::Meta(meta);
if (meta.isMember("tracks") && meta["tracks"].size() > 0){
for (JSON::ObjIter trackIt = meta["tracks"].ObjBegin(); trackIt != meta["tracks"].ObjEnd(); trackIt++){
int nxtMap = getNextFree(trackMapping);
trackMapping[argv[1]].insert(std::pair<int,int>(trackIt->second["trackid"].asInt(),nxtMap));
newMeta.tracks[nxtMap].trackID = nxtMap;
}
}
}
std::multimap<int,keyframeInfo> allSorted;
for (std::map<std::string,DTSC::File>::iterator it = inFiles.begin(); it != inFiles.end(); it++){
DTSC::Meta tmpMeta(it->second.getMeta());
for (std::map<int,DTSC::Track>::iterator trackIt = tmpMeta.tracks.begin(); trackIt != tmpMeta.tracks.end(); trackIt++){
long long int oldID = trackIt->first;
long long int mappedID = getNextFree(trackMapping);
trackMapping[it->first].insert(std::pair<int,int>(oldID,mappedID));
for (std::deque<DTSC::Key>::iterator keyIt = trackIt->second.keys.begin(); keyIt != trackIt->second.keys.end(); keyIt++){
keyframeInfo tmpInfo;
tmpInfo.fileName = it->first;
tmpInfo.trackID = oldID;
tmpInfo.keyTime = keyIt->getTime();
tmpInfo.keyBPos = keyIt->getBpos();
tmpInfo.keyNum = keyIt->getNumber();
tmpInfo.keyLen = keyIt->getLength();
if ((keyIt + 1) != trackIt->second.keys.end()){
tmpInfo.endBPos = (keyIt + 1)->getBpos();
}else{
tmpInfo.endBPos = it->second.getBytePosEOF();
}
allSorted.insert(std::pair<int,keyframeInfo>(keyIt->getTime(),tmpInfo));
}
newMeta.tracks[mappedID] = trackIt->second;
newMeta.tracks[mappedID].trackID = mappedID;
newMeta.tracks[mappedID].reset();
}
}
if (fullSort){
meta.null();
meta["moreheader"] = 0ll;
std::string tmpWrite = meta.toPacked();
outFile.writeHeader(tmpWrite,true);
}
std::set<int> trackSelector;
for (std::multimap<int,keyframeInfo>::iterator sortIt = allSorted.begin(); sortIt != allSorted.end(); sortIt++){
trackSelector.clear();
trackSelector.insert(sortIt->second.trackID);
inFiles[sortIt->second.fileName].selectTracks(trackSelector);
inFiles[sortIt->second.fileName].seek_time(sortIt->second.keyTime);
inFiles[sortIt->second.fileName].seekNext();
while (inFiles[sortIt->second.fileName].getPacket() && inFiles[sortIt->second.fileName].getBytePos() <= sortIt->second.endBPos && !inFiles[sortIt->second.fileName].reachedEOF()){
if (inFiles[sortIt->second.fileName].getPacket().getTrackId() == sortIt->second.trackID){
JSON::Value tmp = inFiles[sortIt->second.fileName].getPacket().toJSON();
tmp["trackid"] = trackMapping[sortIt->second.fileName][sortIt->second.trackID];
outFile.writePacket(tmp);
}
inFiles[sortIt->second.fileName].seekNext();
//.........这里部分代码省略.........