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

Function ReadFrame

test/api/BaseThreadDecoderTest.cpp:42–102  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

40}
41
42static int32_t ReadFrame (uint8_t* pBuf, const int32_t& iFileSize, const int32_t& bufPos) {
43 int32_t bytes_available = iFileSize - bufPos;
44 if (bytes_available < 4) {
45 return bytes_available;
46 }
47 uint8_t* ptr = pBuf + bufPos;
48 int32_t read_bytes = 0;
49 int32_t sps_count = 0;
50 int32_t pps_count = 0;
51 int32_t non_idr_pict_count = 0;
52 int32_t idr_pict_count = 0;
53 int32_t nal_deliminator = 0;
54 while (read_bytes < bytes_available - 4) {
55 bool has4ByteStartCode = ptr[0] == 0 && ptr[1] == 0 && ptr[2] == 0 && ptr[3] == 1;
56 bool has3ByteStartCode = false;
57 if (!has4ByteStartCode) {
58 has3ByteStartCode = ptr[0] == 0 && ptr[1] == 0 && ptr[2] == 1;
59 }
60 if (has4ByteStartCode || has3ByteStartCode) {
61 int32_t byteOffset = has4ByteStartCode ? 4 : 3;
62 uint8_t nal_unit_type = has4ByteStartCode ? (ptr[4] & 0x1F) : (ptr[3] & 0x1F);
63 if (nal_unit_type == 1) {
64 int32_t firstMBInSlice = readFirstMbInSlice (ptr + byteOffset);
65 if (++non_idr_pict_count >= 1 && idr_pict_count >= 1 && firstMBInSlice == 0) {
66 return read_bytes;
67 }
68 if (non_idr_pict_count >= 2 && firstMBInSlice == 0) {
69 return read_bytes;
70 }
71 } else if (nal_unit_type == 5) {
72 int32_t firstMBInSlice = readFirstMbInSlice (ptr + byteOffset);
73 if (++idr_pict_count >= 1 && non_idr_pict_count >= 1 && firstMBInSlice == 0) {
74 return read_bytes;
75 }
76 if (idr_pict_count >= 2 && firstMBInSlice == 0) {
77 return read_bytes;
78 }
79 } else if (nal_unit_type == 7) {
80 if ((++sps_count >= 1) && (non_idr_pict_count >= 1 || idr_pict_count >= 1)) {
81 return read_bytes;
82 }
83 if (sps_count == 2) return read_bytes;
84 } else if (nal_unit_type == 8) {
85 if (++pps_count >= 1 && (non_idr_pict_count >= 1 || idr_pict_count >= 1)) return read_bytes;
86 } else if (nal_unit_type == 9) {
87 if (++nal_deliminator == 2) {
88 return read_bytes;
89 }
90 }
91 if (read_bytes >= bytes_available - 4) {
92 return bytes_available;
93 }
94 read_bytes += 4;
95 ptr += 4;
96 } else {
97 ++ptr;
98 ++read_bytes;
99 }

Callers 1

ThreadDecodeFileMethod · 0.70

Calls 1

readFirstMbInSliceFunction · 0.70

Tested by

no test coverage detected