MCPcopy Create free account
hub / github.com/Tencent/libpag / ReadByteDataWithStartCode

Function ReadByteDataWithStartCode

src/codec/utils/NALUReader.cpp:23–49  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

21
22namespace pag {
23std::unique_ptr<ByteData> ReadByteDataWithStartCode(DecodeStream* stream) {
24 auto length = stream->readEncodedUint32();
25 auto bytes = stream->readBytes(length);
26 // must check whether the bytes is valid. otherwise memcpy will crash.
27 if (length == 0 || length > bytes.length() || stream->context->hasException()) {
28 return nullptr;
29 }
30 auto data = new (std::nothrow) uint8_t[length + 4];
31 if (data == nullptr) {
32 return nullptr;
33 }
34 memcpy(data + 4, bytes.data(), length);
35 if (Platform::Current()->naluType() == NALUType::AVCC) {
36 // AVCC
37 data[0] = static_cast<uint8_t>((length >> 24) & 0xFF);
38 data[1] = static_cast<uint8_t>((length >> 16) & 0x00FF);
39 data[2] = static_cast<uint8_t>((length >> 8) & 0x0000FF);
40 data[3] = static_cast<uint8_t>(length & 0x000000FF);
41 } else {
42 // Annex B Prefix
43 data[0] = 0;
44 data[1] = 0;
45 data[2] = 0;
46 data[3] = 1;
47 }
48 return ByteData::MakeAdopted(data, length + 4);
49}
50} // namespace pag

Callers 1

ReadVideoSequenceFunction · 0.85

Calls 7

memcpyFunction · 0.85
hasExceptionMethod · 0.80
readEncodedUint32Method · 0.45
readBytesMethod · 0.45
lengthMethod · 0.45
dataMethod · 0.45
naluTypeMethod · 0.45

Tested by

no test coverage detected