| 21 | |
| 22 | namespace pag { |
| 23 | std::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 |
no test coverage detected