MCPcopy Create free account
hub / github.com/cisco/openh264 / readPicture

Function readPicture

codec/console/dec/src/h264dec.cpp:105–176  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

103}
104
105int32_t readPicture (uint8_t* pBuf, const int32_t& iFileSize, const int32_t& bufPos, uint8_t*& pSpsBuf,
106 int32_t& sps_byte_count) {
107 int32_t bytes_available = iFileSize - bufPos;
108 if (bytes_available < 4) {
109 return bytes_available;
110 }
111 uint8_t* ptr = pBuf + bufPos;
112 int32_t read_bytes = 0;
113 int32_t sps_count = 0;
114 int32_t pps_count = 0;
115 int32_t non_idr_pict_count = 0;
116 int32_t idr_pict_count = 0;
117 int32_t nal_deliminator = 0;
118 pSpsBuf = NULL;
119 sps_byte_count = 0;
120 while (read_bytes < bytes_available - 4) {
121 bool has4ByteStartCode = ptr[0] == 0 && ptr[1] == 0 && ptr[2] == 0 && ptr[3] == 1;
122 bool has3ByteStartCode = false;
123 if (!has4ByteStartCode) {
124 has3ByteStartCode = ptr[0] == 0 && ptr[1] == 0 && ptr[2] == 1;
125 }
126 if (has4ByteStartCode || has3ByteStartCode) {
127 int32_t byteOffset = has4ByteStartCode ? 4 : 3;
128 uint8_t nal_unit_type = has4ByteStartCode ? (ptr[4] & 0x1F) : (ptr[3] & 0x1F);
129 if (nal_unit_type == 1) {
130 int32_t firstMBInSlice = readFirstMbInSlice (ptr + byteOffset);
131 if (++non_idr_pict_count >= 1 && idr_pict_count >= 1 && firstMBInSlice == 0) {
132 return read_bytes;
133 }
134 if (non_idr_pict_count >= 2 && firstMBInSlice == 0) {
135 return read_bytes;
136 }
137 } else if (nal_unit_type == 5) {
138 int32_t firstMBInSlice = readFirstMbInSlice (ptr + byteOffset);
139 if (++idr_pict_count >= 1 && non_idr_pict_count >= 1 && firstMBInSlice == 0) {
140 return read_bytes;
141 }
142 if (idr_pict_count >= 2 && firstMBInSlice == 0) {
143 return read_bytes;
144 }
145 } else if (nal_unit_type == 7) {
146 pSpsBuf = ptr + (has4ByteStartCode ? 4 : 3);
147 if ((++sps_count >= 1) && (non_idr_pict_count >= 1 || idr_pict_count >= 1)) {
148 return read_bytes;
149 }
150 if (sps_count == 2) {
151 return read_bytes;
152 }
153 } else if (nal_unit_type == 8) {
154 if (++pps_count == 1 && sps_count == 1) {
155 sps_byte_count = int32_t (ptr - pSpsBuf);
156 }
157 if (pps_count >= 1 && (non_idr_pict_count >= 1 || idr_pict_count >= 1)) {
158 return read_bytes;
159 }
160 } else if (nal_unit_type == 9) {
161 if (++nal_deliminator == 2) {
162 return read_bytes;

Callers 1

H264DecodeInstanceFunction · 0.85

Calls 1

readFirstMbInSliceFunction · 0.70

Tested by

no test coverage detected