Analyser unification finished
This commit is contained in:
parent
051a8c826b
commit
945e6f2d1a
44 changed files with 1264 additions and 2903 deletions
75
lib/h264.cpp
75
lib/h264.cpp
|
@ -810,41 +810,66 @@ namespace h264 {
|
|||
out << " Message of type " << payloadType << ", " << payloadSize << " bytes long" << std::endl;
|
||||
}
|
||||
|
||||
nalUnit * nalFactory(char * _data, size_t _len, size_t & offset, bool annexb) {
|
||||
char * data = _data + offset;
|
||||
size_t len = _len - offset;
|
||||
nalUnit * result = NULL;
|
||||
if (len < 4){
|
||||
return result;
|
||||
}
|
||||
nalUnit * nalFactory(const char * _data, size_t _len, size_t & offset, bool annexb) {
|
||||
if (annexb){
|
||||
FAIL_MSG("Not supported in annexb mode yet");
|
||||
return result;
|
||||
//check if we have a start marker at the beginning, if so, move the offset over
|
||||
if (_len > offset && !_data[offset]){
|
||||
for (size_t i = offset+1; i < _len; ++i){
|
||||
if (_data[i] > 1){
|
||||
FAIL_MSG("Encountered bullshit AnnexB data..?");
|
||||
return 0;
|
||||
}
|
||||
if (_data[i] == 1){offset = i+1; break;}
|
||||
}
|
||||
}
|
||||
//now we know we're starting at real data. Yay!
|
||||
}
|
||||
uint32_t pktLen = Bit::btohl(data);
|
||||
if (len < 4 + pktLen){
|
||||
return result;
|
||||
if (_len < offset + 4){
|
||||
WARN_MSG("Not at least 4 bytes available - cancelling");
|
||||
return 0;
|
||||
}
|
||||
switch (data[5] & 0x1F){
|
||||
uint32_t pktLen = 0;
|
||||
if (!annexb){
|
||||
//read the 4b size in front
|
||||
pktLen = Bit::btohl(_data+offset);
|
||||
if (_len < 4 + pktLen){
|
||||
WARN_MSG("Not at least 4+%lu bytes available - cancelling", pktLen);
|
||||
return 0;
|
||||
}
|
||||
offset += 4;
|
||||
}
|
||||
const char * data = _data + offset;
|
||||
size_t len = _len - offset;
|
||||
if (annexb){
|
||||
//search for the next start marker
|
||||
for (size_t i = 1; i < len-2; ++i){
|
||||
if (data[i] == 0 && data[i+1] == 0 && data[i+2] == 1){
|
||||
offset += i+2;
|
||||
while (i && !data[i]){--i;}
|
||||
pktLen = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}else{
|
||||
offset += pktLen;
|
||||
}
|
||||
if (!pktLen){
|
||||
WARN_MSG("Cannot determine packet length - cancelling");
|
||||
return 0;
|
||||
}
|
||||
switch (data[0] & 0x1F){
|
||||
case 1:
|
||||
case 5:
|
||||
result = new codedSliceUnit(data + 4, pktLen);
|
||||
break;
|
||||
return new codedSliceUnit(data, pktLen);
|
||||
case 6:
|
||||
result = new seiUnit(data + 4, pktLen);
|
||||
break;
|
||||
return new seiUnit(data, pktLen);
|
||||
case 7:
|
||||
result = new spsUnit(data + 4, pktLen);
|
||||
break;
|
||||
return new spsUnit(data, pktLen);
|
||||
case 8:
|
||||
result = new ppsUnit(data + 4, pktLen);
|
||||
break;
|
||||
return new ppsUnit(data, pktLen);
|
||||
default:
|
||||
result = new nalUnit(data + 4, pktLen);
|
||||
break;
|
||||
return new nalUnit(data, pktLen);
|
||||
}
|
||||
offset += 4 + pktLen;
|
||||
return result;
|
||||
}
|
||||
|
||||
nalUnit * nalFactory(FILE * in, bool annexb) {
|
||||
|
|
|
@ -76,6 +76,7 @@ namespace h264 {
|
|||
public:
|
||||
nalUnit(const char * data, size_t len) : payload(data, len) {}
|
||||
uint8_t getType() { return payload[0] & 0x1F; }
|
||||
uint32_t getSize(){return payload.size();}
|
||||
virtual void toPrettyString(std::ostream & out){
|
||||
out << "Nal unit of type " << (((uint8_t)payload[0]) & 0x1F) << ", " << payload.size() << " bytes long" << std::endl;
|
||||
}
|
||||
|
@ -296,5 +297,5 @@ namespace h264 {
|
|||
|
||||
|
||||
nalUnit * nalFactory(FILE * in, bool annexb = true);
|
||||
nalUnit * nalFactory(char * data, size_t len, size_t & offset, bool annexb = true);
|
||||
nalUnit * nalFactory(const char * data, size_t len, size_t & offset, bool annexb = true);
|
||||
}
|
||||
|
|
|
@ -96,6 +96,35 @@ std::string HTTP::URL::getUrl() const{
|
|||
return ret;
|
||||
}
|
||||
|
||||
///Returns a URL object for the given link, resolved relative to the current URL object.
|
||||
HTTP::URL HTTP::URL::link(const std::string &l){
|
||||
//Full link
|
||||
if (l.find("://") < l.find('/')){return URL(l);}
|
||||
//Absolute link
|
||||
if (l[0] == '/'){
|
||||
if (l.size() > 1 && l[1] == '/'){
|
||||
//Same-protocol full link
|
||||
return URL(protocol+":"+l);
|
||||
}else{
|
||||
//Same-domain/port absolute link
|
||||
URL tmp = *this;
|
||||
tmp.args.clear();
|
||||
tmp.path = l.substr(1);
|
||||
//Abuse the fact that we don't check for arguments in getUrl()
|
||||
return URL(tmp.getUrl());
|
||||
}
|
||||
}
|
||||
//Relative link
|
||||
std::string tmpUrl = getUrl();
|
||||
size_t slashPos = tmpUrl.rfind('/');
|
||||
if (slashPos == std::string::npos){
|
||||
tmpUrl += "/";
|
||||
}else{
|
||||
tmpUrl.erase(slashPos+1);
|
||||
}
|
||||
return URL(tmpUrl+l);
|
||||
}
|
||||
|
||||
/// This constructor creates an empty HTTP::Parser, ready for use for either reading or writing.
|
||||
/// All this constructor does is call HTTP::Parser::Clean().
|
||||
HTTP::Parser::Parser() {
|
||||
|
|
|
@ -72,7 +72,7 @@ namespace HTTP {
|
|||
///URL parsing class. Parses full URL into its subcomponents
|
||||
class URL {
|
||||
public:
|
||||
URL(const std::string & url);
|
||||
URL(const std::string & url = "");
|
||||
uint32_t getPort() const;
|
||||
std::string getUrl() const;
|
||||
std::string host;///< Hostname or IP address of URL
|
||||
|
@ -80,6 +80,7 @@ namespace HTTP {
|
|||
std::string port;///<Port of URL
|
||||
std::string path;///<Path after the first slash (not inclusive) but before any question mark
|
||||
std::string args;///<Everything after the question mark in the path, if it was present
|
||||
URL link(const std::string &l);
|
||||
};
|
||||
|
||||
}//HTTP namespace
|
||||
|
|
75
lib/opus.cpp
Normal file
75
lib/opus.cpp
Normal file
|
@ -0,0 +1,75 @@
|
|||
#include "opus.h"
|
||||
#include <sstream>
|
||||
|
||||
namespace Opus{
|
||||
std::string Opus_prettyPacket(const char *part, int len){
|
||||
if (len < 1){return "Invalid packet (0 byte length)";}
|
||||
std::stringstream r;
|
||||
char config = part[0] >> 3;
|
||||
char code = part[0] & 3;
|
||||
if ((part[0] & 4) == 4){
|
||||
r << "Stereo, ";
|
||||
}else{
|
||||
r << "Mono, ";
|
||||
}
|
||||
if (config < 14){
|
||||
r << "SILK, ";
|
||||
if (config < 4){r << "NB, ";}
|
||||
if (config < 8 && config > 3){r << "MB, ";}
|
||||
if (config < 14 && config > 7){r << "WB, ";}
|
||||
if (config % 4 == 0){r << "10ms";}
|
||||
if (config % 4 == 1){r << "20ms";}
|
||||
if (config % 4 == 2){r << "40ms";}
|
||||
if (config % 4 == 3){r << "60ms";}
|
||||
}
|
||||
if (config < 16 && config > 13){
|
||||
r << "Hybrid, ";
|
||||
if (config < 14){
|
||||
r << "SWB, ";
|
||||
}else{
|
||||
r << "FB, ";
|
||||
}
|
||||
if (config % 2 == 0){
|
||||
r << "10ms";
|
||||
}else{
|
||||
r << "20ms";
|
||||
}
|
||||
}
|
||||
if (config > 15){
|
||||
r << "CELT, ";
|
||||
if (config < 20){r << "NB, ";}
|
||||
if (config < 24 && config > 19){r << "WB, ";}
|
||||
if (config < 28 && config > 23){r << "SWB, ";}
|
||||
if (config > 27){r << "FB, ";}
|
||||
if (config % 4 == 0){r << "2.5ms";}
|
||||
if (config % 4 == 1){r << "5ms";}
|
||||
if (config % 4 == 2){r << "10ms";}
|
||||
if (config % 4 == 3){r << "20ms";}
|
||||
}
|
||||
if (code == 0){
|
||||
r << ": 1 packet (" << (len - 1) << "b)";
|
||||
return r.str();
|
||||
}
|
||||
if (code == 1){
|
||||
r << ": 2 packets (" << ((len - 1) / 2) << "b / " << ((len - 1) / 2) << "b)";
|
||||
return r.str();
|
||||
}
|
||||
if (code == 2){
|
||||
if (len < 2){return "Invalid packet (code 2 must be > 1 byte long)";}
|
||||
if (part[1] < 252){
|
||||
r << ": 2 packets (" << (int)part[1] << "b / " << (int)(len - 2 - part[1]) << "b)";
|
||||
}else{
|
||||
int ilen = part[1] + part[2] * 4;
|
||||
r << ": 2 packets (" << ilen << "b / " << (int)(len - 3 - ilen) << "b)";
|
||||
}
|
||||
return r.str();
|
||||
}
|
||||
// code 3
|
||||
bool VBR = (part[1] & 128) == 128;
|
||||
bool pad = (part[1] & 64) == 64;
|
||||
bool packets = (part[1] & 63);
|
||||
r << ": " << packets << " packets (VBR = " << VBR << ", padding = " << pad << ")";
|
||||
return r.str();
|
||||
}
|
||||
}
|
||||
|
6
lib/opus.h
Normal file
6
lib/opus.h
Normal file
|
@ -0,0 +1,6 @@
|
|||
#include <string>
|
||||
|
||||
namespace Opus{
|
||||
std::string Opus_prettyPacket(const char *part, int len);
|
||||
}
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue