Restyle
This commit is contained in:
parent
5b79f296d6
commit
fccf66fba2
280 changed files with 56975 additions and 71885 deletions
243
lib/theora.cpp
243
lib/theora.cpp
|
|
@ -1,22 +1,22 @@
|
|||
#include "defines.h"
|
||||
#include "theora.h"
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <sstream>
|
||||
#include "defines.h"
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
namespace theora {
|
||||
namespace theora{
|
||||
bool header::checkDataSize(unsigned int size){
|
||||
if (size > datasize){
|
||||
void * tmp = realloc(data, size);
|
||||
void *tmp = realloc(data, size);
|
||||
if (tmp){
|
||||
data = (char *)tmp;
|
||||
datasize = size;
|
||||
return true;
|
||||
} else {
|
||||
}else{
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
}else{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
@ -36,9 +36,7 @@ namespace theora {
|
|||
}
|
||||
|
||||
uint16_t header::getInt16(size_t index){
|
||||
if (datasize >= (index + 1)){
|
||||
return 0 + (data[index] << 8) + data[index + 1];
|
||||
}
|
||||
if (datasize >= (index + 1)){return 0 + (data[index] << 8) + data[index + 1];}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
@ -49,206 +47,147 @@ namespace theora {
|
|||
return 0;
|
||||
}
|
||||
|
||||
header::header(char * newData, unsigned int length){
|
||||
data = newData;
|
||||
datasize = length;
|
||||
header::header(char *newData, unsigned int length){
|
||||
data = newData;
|
||||
datasize = length;
|
||||
}
|
||||
|
||||
header::~header(){
|
||||
}
|
||||
header::~header(){}
|
||||
|
||||
bool isHeader(const char * newData, unsigned int length){
|
||||
if (length < 7){
|
||||
return false;
|
||||
}
|
||||
bool isHeader(const char *newData, unsigned int length){
|
||||
if (length < 7){return false;}
|
||||
if (!(newData[0] & 0x80)){
|
||||
FAIL_MSG("newdata != 0x80: %.2X", newData[0]);
|
||||
return false;
|
||||
}
|
||||
if (memcmp(newData + 1, "theora", 6) != 0){
|
||||
return false;
|
||||
}
|
||||
if (memcmp(newData + 1, "theora", 6) != 0){return false;}
|
||||
return true;
|
||||
}
|
||||
|
||||
int header::getHeaderType(){
|
||||
return (data[0] & 0x7F);
|
||||
}
|
||||
int header::getHeaderType(){return (data[0] & 0x7F);}
|
||||
|
||||
char header::getVMAJ(){
|
||||
if (getHeaderType() == 0){
|
||||
return data[7];
|
||||
}
|
||||
if (getHeaderType() == 0){return data[7];}
|
||||
return 0;
|
||||
}
|
||||
|
||||
char header::getVMIN(){
|
||||
if (getHeaderType() == 0){
|
||||
return data[8];
|
||||
}
|
||||
if (getHeaderType() == 0){return data[8];}
|
||||
return 0;
|
||||
}
|
||||
|
||||
char header::getVREV(){
|
||||
if (getHeaderType() == 0){
|
||||
return data[9];
|
||||
}
|
||||
if (getHeaderType() == 0){return data[9];}
|
||||
return 0;
|
||||
}
|
||||
|
||||
short header::getFMBW(){
|
||||
if (getHeaderType() == 0){
|
||||
return getInt16(10);
|
||||
}
|
||||
if (getHeaderType() == 0){return getInt16(10);}
|
||||
return 0;
|
||||
}
|
||||
|
||||
short header::getFMBH(){
|
||||
if (getHeaderType() == 0){
|
||||
return getInt16(12);
|
||||
}
|
||||
if (getHeaderType() == 0){return getInt16(12);}
|
||||
return 0;
|
||||
}
|
||||
|
||||
char header::getPICX(){
|
||||
if (getHeaderType() == 0){
|
||||
return data[20];
|
||||
}
|
||||
if (getHeaderType() == 0){return data[20];}
|
||||
return 0;
|
||||
}
|
||||
|
||||
char header::getPICY(){
|
||||
if (getHeaderType() == 0){
|
||||
return data[21];
|
||||
}
|
||||
if (getHeaderType() == 0){return data[21];}
|
||||
return 0;
|
||||
}
|
||||
|
||||
char header::getKFGShift(){
|
||||
if (getHeaderType() == 0){
|
||||
return (getInt16(40) >> 5) & 0x1F;
|
||||
}
|
||||
if (getHeaderType() == 0){return (getInt16(40) >> 5) & 0x1F;}
|
||||
return 0;
|
||||
}
|
||||
|
||||
long unsigned int header::getFRN(){
|
||||
if (getHeaderType() == 0){
|
||||
return getInt32(22);
|
||||
}
|
||||
if (getHeaderType() == 0){return getInt32(22);}
|
||||
return 0;
|
||||
}
|
||||
|
||||
long unsigned int header::getPICH(){
|
||||
if (getHeaderType() == 0){
|
||||
return getInt24(17);
|
||||
}
|
||||
if (getHeaderType() == 0){return getInt24(17);}
|
||||
return 0;
|
||||
}
|
||||
|
||||
long unsigned int header::getPICW(){
|
||||
if (getHeaderType() == 0){
|
||||
return getInt24(14);
|
||||
}
|
||||
if (getHeaderType() == 0){return getInt24(14);}
|
||||
return 0;
|
||||
}
|
||||
|
||||
long unsigned int header::getFRD(){
|
||||
if (getHeaderType() == 0){
|
||||
return getInt32(26);
|
||||
}
|
||||
if (getHeaderType() == 0){return getInt32(26);}
|
||||
return 0;
|
||||
}
|
||||
|
||||
long unsigned int header::getPARN(){
|
||||
if (getHeaderType() == 0){
|
||||
return getInt24(30);
|
||||
}
|
||||
if (getHeaderType() == 0){return getInt24(30);}
|
||||
return 0;
|
||||
}
|
||||
|
||||
long unsigned int header::getPARD(){
|
||||
if (getHeaderType() == 0){
|
||||
return getInt24(33);
|
||||
}
|
||||
if (getHeaderType() == 0){return getInt24(33);}
|
||||
return 0;
|
||||
}
|
||||
|
||||
char header::getCS(){
|
||||
if (getHeaderType() == 0){
|
||||
return data[36];
|
||||
}
|
||||
if (getHeaderType() == 0){return data[36];}
|
||||
return 0;
|
||||
}
|
||||
|
||||
long unsigned int header::getNOMBR(){
|
||||
if (getHeaderType() == 0){
|
||||
return getInt24(37);
|
||||
}
|
||||
if (getHeaderType() == 0){return getInt24(37);}
|
||||
return 0;
|
||||
}
|
||||
|
||||
char header::getQUAL(){
|
||||
if (getHeaderType() == 0){
|
||||
return (data[40] >> 3) & 0x1F;
|
||||
}
|
||||
if (getHeaderType() == 0){return (data[40] >> 3) & 0x1F;}
|
||||
return 0;
|
||||
}
|
||||
|
||||
char header::getPF(){
|
||||
if (getHeaderType() == 0){
|
||||
return (data[41] >> 3) & 0x03;
|
||||
}
|
||||
if (getHeaderType() == 0){return (data[41] >> 3) & 0x03;}
|
||||
return 0;
|
||||
}
|
||||
|
||||
std::string header::getVendor(){
|
||||
if (getHeaderType() != 1){
|
||||
return "";
|
||||
}
|
||||
if (getHeaderType() != 1){return "";}
|
||||
return std::string(data + 11, commentLen(7));
|
||||
}
|
||||
|
||||
long unsigned int header::getNComments(){
|
||||
if (getHeaderType() != 1){
|
||||
return 0;
|
||||
}
|
||||
if (getHeaderType() != 1){return 0;}
|
||||
int offset = 11 + commentLen(7);
|
||||
return commentLen(offset);
|
||||
}
|
||||
|
||||
char header::getLFLIMS(size_t index){
|
||||
if (getHeaderType() != 2){
|
||||
return 0;
|
||||
}
|
||||
if (index >= 64){
|
||||
return 0;
|
||||
}
|
||||
if (getHeaderType() != 2){return 0;}
|
||||
if (index >= 64){return 0;}
|
||||
char NBITS = (data[0] >> 5) & 0x07;
|
||||
return NBITS;
|
||||
}
|
||||
|
||||
std::string header::getUserComment(size_t index){
|
||||
if (index >= getNComments()){
|
||||
return "";
|
||||
}
|
||||
if (index >= getNComments()){return "";}
|
||||
int offset = 11 + commentLen(7) + 4;
|
||||
for (size_t i = 0; i < index; i++){
|
||||
offset += 4 + commentLen(offset);
|
||||
}
|
||||
for (size_t i = 0; i < index; i++){offset += 4 + commentLen(offset);}
|
||||
return std::string(data + offset + 4, commentLen(offset));
|
||||
}
|
||||
|
||||
char header::getFTYPE(){
|
||||
return (data[0] >> 6) & 0x01;
|
||||
}
|
||||
char header::getFTYPE(){return (data[0] >> 6) & 0x01;}
|
||||
|
||||
bool header::isHeader(){
|
||||
return ::theora::isHeader(data, datasize);
|
||||
}
|
||||
bool header::isHeader(){return ::theora::isHeader(data, datasize);}
|
||||
|
||||
std::string header::toPrettyString(size_t indent){
|
||||
std::stringstream result;
|
||||
if(!isHeader()){
|
||||
if (!isHeader()){
|
||||
result << std::string(indent, ' ') << "Theora Frame" << std::endl;
|
||||
result << std::string(indent + 2, ' ') << "FType: " << (int)getFTYPE() << std::endl;
|
||||
return result.str();
|
||||
|
|
@ -256,34 +195,33 @@ namespace theora {
|
|||
result << std::string(indent, ' ') << "Theora header" << std::endl;
|
||||
result << std::string(indent + 2, ' ') << "HeaderType: " << getHeaderType() << std::endl;
|
||||
switch (getHeaderType()){
|
||||
case 0:
|
||||
result << std::string(indent + 2, ' ') << "VMAJ: " << (int)getVMAJ() << std::endl;
|
||||
result << std::string(indent + 2, ' ') << "VMIN: " << (int)getVMIN() << std::endl;
|
||||
result << std::string(indent + 2, ' ') << "VREV: " << (int)getVREV() << std::endl;
|
||||
result << std::string(indent + 2, ' ') << "FMBW: " << getFMBW() << std::endl;
|
||||
result << std::string(indent + 2, ' ') << "FMBH: " << getFMBH() << std::endl;
|
||||
result << std::string(indent + 2, ' ') << "PICH: " << getPICH() << std::endl;
|
||||
result << std::string(indent + 2, ' ') << "PICW: " << getPICW() << std::endl;
|
||||
result << std::string(indent + 2, ' ') << "PICX: " << (int)getPICX() << std::endl;
|
||||
result << std::string(indent + 2, ' ') << "PICY: " << (int)getPICY() << std::endl;
|
||||
result << std::string(indent + 2, ' ') << "FRN: " << getFRN() << std::endl;
|
||||
result << std::string(indent + 2, ' ') << "FRD: " << getFRD() << std::endl;
|
||||
result << std::string(indent + 2, ' ') << "PARN: " << getPARN() << std::endl;
|
||||
result << std::string(indent + 2, ' ') << "PARD: " << getPARD() << std::endl;
|
||||
result << std::string(indent + 2, ' ') << "CS: " << (int)getCS() << std::endl;
|
||||
result << std::string(indent + 2, ' ') << "NOMBR: " << getNOMBR() << std::endl;
|
||||
result << std::string(indent + 2, ' ') << "QUAL: " << (int)getQUAL() << std::endl;
|
||||
result << std::string(indent + 2, ' ') << "KFGShift: " << (int)getKFGShift() << std::endl;
|
||||
break;
|
||||
case 1:
|
||||
result << std::string(indent + 2, ' ') << "Vendor: " << getVendor() << std::endl;
|
||||
result << std::string(indent + 2, ' ') << "User Comments (" << getNComments() << "):" << std::endl;
|
||||
for (long unsigned int i = 0; i < getNComments(); i++){
|
||||
result << std::string(indent + 4, ' ') << "[" << i << "] " << getUserComment(i) << std::endl;
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
result << std::string(indent + 2, ' ') << "NBITS: " << (int)getLFLIMS(0) << std::endl;
|
||||
case 0:
|
||||
result << std::string(indent + 2, ' ') << "VMAJ: " << (int)getVMAJ() << std::endl;
|
||||
result << std::string(indent + 2, ' ') << "VMIN: " << (int)getVMIN() << std::endl;
|
||||
result << std::string(indent + 2, ' ') << "VREV: " << (int)getVREV() << std::endl;
|
||||
result << std::string(indent + 2, ' ') << "FMBW: " << getFMBW() << std::endl;
|
||||
result << std::string(indent + 2, ' ') << "FMBH: " << getFMBH() << std::endl;
|
||||
result << std::string(indent + 2, ' ') << "PICH: " << getPICH() << std::endl;
|
||||
result << std::string(indent + 2, ' ') << "PICW: " << getPICW() << std::endl;
|
||||
result << std::string(indent + 2, ' ') << "PICX: " << (int)getPICX() << std::endl;
|
||||
result << std::string(indent + 2, ' ') << "PICY: " << (int)getPICY() << std::endl;
|
||||
result << std::string(indent + 2, ' ') << "FRN: " << getFRN() << std::endl;
|
||||
result << std::string(indent + 2, ' ') << "FRD: " << getFRD() << std::endl;
|
||||
result << std::string(indent + 2, ' ') << "PARN: " << getPARN() << std::endl;
|
||||
result << std::string(indent + 2, ' ') << "PARD: " << getPARD() << std::endl;
|
||||
result << std::string(indent + 2, ' ') << "CS: " << (int)getCS() << std::endl;
|
||||
result << std::string(indent + 2, ' ') << "NOMBR: " << getNOMBR() << std::endl;
|
||||
result << std::string(indent + 2, ' ') << "QUAL: " << (int)getQUAL() << std::endl;
|
||||
result << std::string(indent + 2, ' ') << "KFGShift: " << (int)getKFGShift() << std::endl;
|
||||
break;
|
||||
case 1:
|
||||
result << std::string(indent + 2, ' ') << "Vendor: " << getVendor() << std::endl;
|
||||
result << std::string(indent + 2, ' ') << "User Comments (" << getNComments() << "):" << std::endl;
|
||||
for (long unsigned int i = 0; i < getNComments(); i++){
|
||||
result << std::string(indent + 4, ' ') << "[" << i << "] " << getUserComment(i) << std::endl;
|
||||
}
|
||||
break;
|
||||
case 2: result << std::string(indent + 2, ' ') << "NBITS: " << (int)getLFLIMS(0) << std::endl;
|
||||
}
|
||||
return result.str();
|
||||
}
|
||||
|
|
@ -307,10 +245,10 @@ namespace theora {
|
|||
data = (char *)tmp;
|
||||
datasize = size;
|
||||
return true;
|
||||
} else {
|
||||
}else{
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
}else{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
@ -324,7 +262,7 @@ namespace theora {
|
|||
}
|
||||
if (checkDataSize(length)){
|
||||
memcpy(data, newData, length);
|
||||
} else {
|
||||
}else{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
|
@ -342,24 +280,19 @@ namespace theora {
|
|||
return 0;
|
||||
}
|
||||
*/
|
||||
/*
|
||||
long long unsigned int header::parseGranuleUpper(long long unsigned int granPos){
|
||||
return granPos >> getKFGShift();
|
||||
}
|
||||
|
||||
long long unsigned int header::parseGranuleLower(long long unsigned int granPos){
|
||||
return (granPos & ((1 << getKFGShift()) - 1));
|
||||
}*/
|
||||
/*
|
||||
std::string frame::toPrettyString(size_t indent){
|
||||
std::stringstream result;
|
||||
result << std::string(indent, ' ') << "Theora Frame" << std::endl;
|
||||
result << std::string(indent + 2, ' ') << "FType: " << (int)getFTYPE() << std::endl;
|
||||
return result.str();
|
||||
}*/
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
long long unsigned int header::parseGranuleUpper(long long unsigned int granPos){
|
||||
return granPos >> getKFGShift();
|
||||
}
|
||||
|
||||
long long unsigned int header::parseGranuleLower(long long unsigned int granPos){
|
||||
return (granPos & ((1 << getKFGShift()) - 1));
|
||||
}*/
|
||||
/*
|
||||
std::string frame::toPrettyString(size_t indent){
|
||||
std::stringstream result;
|
||||
result << std::string(indent, ' ') << "Theora Frame" << std::endl;
|
||||
result << std::string(indent + 2, ' ') << "FType: " << (int)getFTYPE() << std::endl;
|
||||
return result.str();
|
||||
}*/
|
||||
}// namespace theora
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue