| 1 |
/* |
| 2 |
libheif AVC (H.264) unit tests |
| 3 |
|
| 4 |
MIT License |
| 5 |
|
| 6 |
Copyright (c) 2023 Brad Hards <[email protected]> |
| 7 |
|
| 8 |
Permission is hereby granted, free of charge, to any person obtaining a copy |
| 9 |
of this software and associated documentation files (the "Software"), to deal |
| 10 |
in the Software without restriction, including without limitation the rights |
| 11 |
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 12 |
copies of the Software, and to permit persons to whom the Software is |
| 13 |
furnished to do so, subject to the following conditions: |
| 14 |
|
| 15 |
The above copyright notice and this permission notice shall be included in all |
| 16 |
copies or substantial portions of the Software. |
| 17 |
|
| 18 |
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 19 |
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 20 |
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 21 |
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 22 |
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 23 |
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 24 |
SOFTWARE. |
| 25 |
*/ |
| 26 |
|
| 27 |
#include "catch_amalgamated.hpp" |
| 28 |
#include "codecs/avc_boxes.h" |
| 29 |
#include "error.h" |
| 30 |
#include <cstdint> |
| 31 |
#include <iostream> |
| 32 |
#include <memory> |
| 33 |
|
| 34 |
|
| 35 |
TEST_CASE("avcC") { |
| 36 |
std::vector<uint8_t> byteArray{ |
| 37 |
0x00, 0x00, 0x00, 0x34, 0x61, 0x76, 0x63, 0x43, 0x01, 0x42, 0x80, |
| 38 |
0x1e, 0xff, 0xe1, 0x00, 0x1a, 0x67, 0x64, 0x00, 0x28, 0xac, 0x72, |
| 39 |
0x04, 0x40, 0x40, 0x04, 0x1a, 0x10, 0x00, 0x00, 0x03, 0x00, 0x10, |
| 40 |
0x00, 0x00, 0x03, 0x03, 0x20, 0xf1, 0x83, 0x18, 0x46, 0x01, 0x00, |
| 41 |
0x07, 0x68, 0xe8, 0x43, 0x83, 0x92, 0xc8, 0xb0}; |
| 42 |
|
| 43 |
auto reader = std::make_shared<StreamReader_memory>(byteArray.data(), |
| 44 |
byteArray.size(), false); |
| 45 |
|
| 46 |
BitstreamRange range(reader, byteArray.size()); |
| 47 |
std::shared_ptr<Box> box; |
| 48 |
Error error = Box::read(range, &box, heif_get_global_security_limits()); |
| 49 |
REQUIRE(error == Error::Ok); |
| 50 |
REQUIRE(range.error() == 0); |
| 51 |
|
| 52 |
REQUIRE(box->get_short_type() == fourcc("avcC")); |
| 53 |
REQUIRE(box->get_type_string() == "avcC"); |
| 54 |
std::shared_ptr<Box_avcC> avcC = std::dynamic_pointer_cast<Box_avcC>(box); |
| 55 |
Box_avcC::configuration configuration = avcC->get_configuration(); |
| 56 |
REQUIRE(configuration.configuration_version == 1); |
| 57 |
REQUIRE(configuration.AVCProfileIndication == 66); |
| 58 |
REQUIRE(configuration.profile_compatibility == 0x80); |
| 59 |
REQUIRE(configuration.AVCLevelIndication == 30); |
| 60 |
REQUIRE(avcC->getSequenceParameterSets().size() == 1); |
| 61 |
REQUIRE(avcC->getSequenceParameterSets()[0].size() == 0x1a); |
| 62 |
REQUIRE(avcC->getPictureParameterSets().size() == 1); |
| 63 |
REQUIRE(avcC->getPictureParameterSets()[0].size() == 7); |
| 64 |
Indent indent; |
| 65 |
std::string dumpResult = box->dump(indent); |
| 66 |
REQUIRE(dumpResult == "Box: avcC -----\n" |
| 67 |
"size: 52 (header size: 8)\n" |
| 68 |
"configuration_version: 1\n" |
| 69 |
"AVCProfileIndication: 66 (Constrained Baseline)\n" |
| 70 |
"profile_compatibility: 128\n" |
| 71 |
"AVCLevelIndication: 30\n" |
| 72 |
"Chroma format: 4:2:0\n" |
| 73 |
"Bit depth luma: 8\n" |
| 74 |
"Bit depth chroma: 8\n" |
| 75 |
"SPS: 67 64 00 28 ac 72 04 40 40 04 1a 10 00 00 03 00 " |
| 76 |
"10 00 00 03 03 20 f1 83 18 46 \n" |
| 77 |
"PPS: 68 e8 43 83 92 c8 b0 \n"); |
| 78 |
|
| 79 |
StreamWriter writer; |
| 80 |
Error err = avcC->write(writer); |
| 81 |
REQUIRE(err.error_code == heif_error_Ok); |
| 82 |
const std::vector<uint8_t> bytes = writer.get_data(); |
| 83 |
REQUIRE(bytes == byteArray); |
| 84 |
} |