Example #1
0
bool _VIDEO_AVC::Init(const uint8_t *pSPS, uint32_t spsLength, const uint8_t *pPPS,
		uint32_t ppsLength) {
	Clear();
	if ((spsLength <= 0)
			|| (spsLength > 65535)
			|| (ppsLength <= 0)
			|| (ppsLength > 65535)) {
		FATAL("Invalid SPS/PPS lengths");
		return false;
	}
	_spsLength = (uint16_t) spsLength;
	_pSPS = new uint8_t[_spsLength];
	memcpy(_pSPS, pSPS, _spsLength);

	_ppsLength = (uint16_t) ppsLength;
	_pPPS = new uint8_t[_ppsLength];
	memcpy(_pPPS, pPPS, _ppsLength);

	_rate = 90000;

	BitArray spsBa;
	//remove emulation_prevention_three_byte
	for (uint16_t i = 1; i < _spsLength; i++) {
		if (((i + 2)<(_spsLength - 1))
				&& (_pSPS[i + 0] == 0)
				&& (_pSPS[i + 1] == 0)
				&& (_pSPS[i + 2] == 3)) {
			spsBa.ReadFromRepeat(0, 2);
			i += 2;
		} else {
			spsBa.ReadFromRepeat(_pSPS[i], 1);
		}
	}

	if (!ReadSPS(spsBa, _SPSInfo)) {
		WARN("Unable to parse SPS");
	} else {
		_SPSInfo.Compact();
		_width = ((uint32_t) _SPSInfo["pic_width_in_mbs_minus1"] + 1)*16;
		_height = ((uint32_t) _SPSInfo["pic_height_in_map_units_minus1"] + 1)*16;
		//		FINEST("_width: %u (%u); _height: %u (%u)",
		//				_width, (uint32_t) _SPSInfo["pic_width_in_mbs_minus1"],
		//				_height, (uint32_t) _SPSInfo["pic_height_in_map_units_minus1"]);
	}

	BitArray ppsBa;
	//remove emulation_prevention_three_byte
	for (uint16_t i = 1; i < _ppsLength; i++) {
		if (((i + 2)<(_ppsLength - 1))
				&& (_pPPS[i + 0] == 0)
				&& (_pPPS[i + 1] == 0)
				&& (_pPPS[i + 2] == 3)) {
			ppsBa.ReadFromRepeat(0, 2);
			i += 2;
		} else {
			ppsBa.ReadFromRepeat(_pPPS[i], 1);
		}
	}

	if (!ReadPPS(ppsBa, _PPSInfo)) {
		WARN("Unable to read PPS info");
	}

	return true;
}