Added more H264 SPS decoding
This commit is contained in:
parent
e8e97adb49
commit
eb5cdb32b1
2 changed files with 49 additions and 19 deletions
61
lib/h264.cpp
61
lib/h264.cpp
|
@ -88,15 +88,27 @@ namespace h264 {
|
||||||
dataLen = Bit::btohs(dtscInit.data() + 6);
|
dataLen = Bit::btohs(dtscInit.data() + 6);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void skipScalingList(Utils::bitstream & bs, size_t listSize){
|
||||||
|
size_t lastScale = 8;
|
||||||
|
size_t nextScale = 8;
|
||||||
|
for (size_t i = 0; i < listSize; i++){
|
||||||
|
if (nextScale){
|
||||||
|
uint64_t deltaScale = bs.getExpGolomb();
|
||||||
|
nextScale = (lastScale + deltaScale + 256) % 256;
|
||||||
|
}
|
||||||
|
lastScale = (nextScale ? nextScale : lastScale);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
SPSMeta sequenceParameterSet::getCharacteristics() const {
|
SPSMeta sequenceParameterSet::getCharacteristics() const {
|
||||||
SPSMeta result;
|
SPSMeta result;
|
||||||
|
result.sep_col_plane = false;
|
||||||
|
|
||||||
//For calculating width
|
//For calculating width
|
||||||
unsigned int widthInMbs = 0;
|
unsigned int widthInMbs = 0;
|
||||||
unsigned int cropHorizontal = 0;
|
unsigned int cropHorizontal = 0;
|
||||||
|
|
||||||
//For calculating height
|
//For calculating height
|
||||||
bool mbsOnlyFlag = 0;
|
|
||||||
unsigned int heightInMapUnits = 0;
|
unsigned int heightInMapUnits = 0;
|
||||||
unsigned int cropVertical = 0;
|
unsigned int cropVertical = 0;
|
||||||
|
|
||||||
|
@ -121,33 +133,44 @@ namespace h264 {
|
||||||
bs.getUExpGolomb();
|
bs.getUExpGolomb();
|
||||||
if (profileIdc == 100 || profileIdc == 110 || profileIdc == 122 || profileIdc == 244 || profileIdc == 44 || profileIdc == 83 || profileIdc == 86 || profileIdc == 118 || profileIdc == 128) {
|
if (profileIdc == 100 || profileIdc == 110 || profileIdc == 122 || profileIdc == 244 || profileIdc == 44 || profileIdc == 83 || profileIdc == 86 || profileIdc == 118 || profileIdc == 128) {
|
||||||
//chroma format idc
|
//chroma format idc
|
||||||
if (bs.getUExpGolomb() == 3) {
|
char chromaFormatIdc = bs.getUExpGolomb();
|
||||||
bs.skip(1);
|
if (chromaFormatIdc == 3) {
|
||||||
|
result.sep_col_plane = (bs.get(1) == 1);
|
||||||
}
|
}
|
||||||
bs.getUExpGolomb();
|
bs.getUExpGolomb();//luma
|
||||||
bs.getUExpGolomb();
|
bs.getUExpGolomb();//chroma
|
||||||
bs.skip(1);
|
bs.skip(1);//transform bypass
|
||||||
if (bs.get(1)) {
|
if (bs.get(1)) {//Scaling matrix is present
|
||||||
DEBUG_MSG(DLVL_DEVEL, "Scaling matrix not implemented yet");
|
char listSize = (chromaFormatIdc == 3 ? 12 : 8);
|
||||||
|
for (size_t i = 0; i < listSize; i++){
|
||||||
|
bool thisListPresent = bs.get(1);
|
||||||
|
if (thisListPresent){
|
||||||
|
if (i < 6){
|
||||||
|
skipScalingList(bs, 16);
|
||||||
|
}else{
|
||||||
|
skipScalingList(bs, 64);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
bs.getUExpGolomb();
|
result.log2_max_frame_num = bs.getUExpGolomb() + 4;
|
||||||
unsigned int pic_order_cnt_type = bs.getUExpGolomb();
|
result.cnt_type = bs.getUExpGolomb();
|
||||||
if (!pic_order_cnt_type) {
|
if (!result.cnt_type) {
|
||||||
bs.getUExpGolomb();
|
result.log2_max_order_cnt = bs.getUExpGolomb() + 4;
|
||||||
} else if (pic_order_cnt_type == 1) {
|
} else if (result.cnt_type == 1) {
|
||||||
DEBUG_MSG(DLVL_DEVEL, "This part of the implementation is incomplete(2), to be continued. If this message is shown, contact developers immediately.");
|
DEBUG_MSG(DLVL_DEVEL, "This part of the implementation is incomplete(2), to be continued. If this message is shown, contact developers immediately.");
|
||||||
}
|
}
|
||||||
bs.getUExpGolomb();
|
result.max_ref_frames = bs.getUExpGolomb();//max_num_ref_frames
|
||||||
bs.skip(1);
|
result.gaps = (bs.get(1) == 1);//gaps in frame num allowed
|
||||||
//Stop skipping data and start doing usefull stuff
|
//Stop skipping data and start doing useful stuff
|
||||||
|
|
||||||
|
|
||||||
widthInMbs = bs.getUExpGolomb() + 1;
|
widthInMbs = bs.getUExpGolomb() + 1;
|
||||||
heightInMapUnits = bs.getUExpGolomb() + 1;
|
heightInMapUnits = bs.getUExpGolomb() + 1;
|
||||||
|
|
||||||
mbsOnlyFlag = bs.get(1);//Gets used in height calculation
|
result.mbs_only = (bs.get(1) == 1);//Gets used in height calculation
|
||||||
if (!mbsOnlyFlag) {
|
if (!result.mbs_only) {
|
||||||
bs.skip(1);
|
bs.skip(1);
|
||||||
}
|
}
|
||||||
bs.skip(1);
|
bs.skip(1);
|
||||||
|
@ -191,7 +214,7 @@ namespace h264 {
|
||||||
}
|
}
|
||||||
|
|
||||||
result.width = (widthInMbs * 16) - (cropHorizontal * 2);
|
result.width = (widthInMbs * 16) - (cropHorizontal * 2);
|
||||||
result.height = ((mbsOnlyFlag ? 1 : 2) * heightInMapUnits * 16) - (cropVertical * 2);
|
result.height = ((result.mbs_only ? 1 : 2) * heightInMapUnits * 16) - (cropVertical * 2);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -14,6 +14,13 @@ namespace h264 {
|
||||||
double fps;
|
double fps;
|
||||||
uint8_t profile;
|
uint8_t profile;
|
||||||
uint8_t level;
|
uint8_t level;
|
||||||
|
bool sep_col_plane;
|
||||||
|
uint8_t cnt_type;
|
||||||
|
bool gaps;///< Gaps in frame num allowed flag
|
||||||
|
bool mbs_only;///<MBS only flag
|
||||||
|
uint16_t log2_max_frame_num;
|
||||||
|
uint16_t log2_max_order_cnt;
|
||||||
|
uint16_t max_ref_frames;///<Maximum number of reference frames
|
||||||
};
|
};
|
||||||
|
|
||||||
///Class for analyzing generic nal units
|
///Class for analyzing generic nal units
|
||||||
|
|
Loading…
Add table
Reference in a new issue