| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /* | ||
| 2 | * This file is part of FFmpeg. | ||
| 3 | * | ||
| 4 | * FFmpeg is free software; you can redistribute it and/or | ||
| 5 | * modify it under the terms of the GNU Lesser General Public | ||
| 6 | * License as published by the Free Software Foundation; either | ||
| 7 | * version 2.1 of the License, or (at your option) any later version. | ||
| 8 | * | ||
| 9 | * FFmpeg is distributed in the hope that it will be useful, | ||
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| 12 | * Lesser General Public License for more details. | ||
| 13 | * | ||
| 14 | * You should have received a copy of the GNU Lesser General Public | ||
| 15 | * License along with FFmpeg; if not, write to the Free Software | ||
| 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
| 17 | */ | ||
| 18 | |||
| 19 | #include <limits.h> | ||
| 20 | #include <stdint.h> | ||
| 21 | #include <stdio.h> | ||
| 22 | |||
| 23 | #include "libavutil/dovi_meta.h" | ||
| 24 | #include "libavutil/mem.h" | ||
| 25 | |||
| 26 | 1 | int main(void) | |
| 27 | { | ||
| 28 | AVDOVIDecoderConfigurationRecord *cfg; | ||
| 29 | AVDOVIMetadata *md; | ||
| 30 | size_t size; | ||
| 31 | |||
| 32 | /* av_dovi_alloc */ | ||
| 33 | 1 | printf("Testing av_dovi_alloc()\n"); | |
| 34 | 1 | cfg = av_dovi_alloc(&size); | |
| 35 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | if (cfg) { |
| 36 | 1 | printf("alloc: OK, size>0=%s, dv_profile=%d\n", | |
| 37 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | size > 0 ? "yes" : "no", cfg->dv_profile); |
| 38 | 1 | av_free(cfg); | |
| 39 | } else { | ||
| 40 | ✗ | printf("alloc: FAIL\n"); | |
| 41 | } | ||
| 42 | |||
| 43 | 1 | cfg = av_dovi_alloc(NULL); | |
| 44 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | printf("alloc (no size): %s\n", cfg ? "OK" : "FAIL"); |
| 45 | 1 | av_free(cfg); | |
| 46 | |||
| 47 | /* av_dovi_metadata_alloc */ | ||
| 48 | 1 | printf("\nTesting av_dovi_metadata_alloc()\n"); | |
| 49 | 1 | md = av_dovi_metadata_alloc(&size); | |
| 50 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | if (md) { |
| 51 | AVDOVIRpuDataHeader *header; | ||
| 52 | AVDOVIDataMapping *mapping; | ||
| 53 | AVDOVIColorMetadata *color; | ||
| 54 | |||
| 55 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | printf("alloc: OK, size>0=%s\n", size > 0 ? "yes" : "no"); |
| 56 | 1 | printf("num_ext_blocks=%d\n", md->num_ext_blocks); | |
| 57 | |||
| 58 | /* pointer consistency checks for inline accessors */ | ||
| 59 | 1 | header = av_dovi_get_header(md); | |
| 60 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | if ((uint8_t *)header != (uint8_t *)md + md->header_offset) |
| 61 | ✗ | printf("header: pointer inconsistent with header_offset\n"); | |
| 62 | 1 | printf("header_offset>0=%s, rpu_type=%d\n", | |
| 63 | 1 | md->header_offset > 0 ? "yes" : "no", | |
| 64 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | header->rpu_type); |
| 65 | |||
| 66 | 1 | mapping = av_dovi_get_mapping(md); | |
| 67 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | if ((uint8_t *)mapping != (uint8_t *)md + md->mapping_offset) |
| 68 | ✗ | printf("mapping: pointer inconsistent with mapping_offset\n"); | |
| 69 | 1 | printf("mapping_offset>0=%s, nlq_method_idc=%d\n", | |
| 70 | 1 | md->mapping_offset > 0 ? "yes" : "no", | |
| 71 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | mapping->nlq_method_idc); |
| 72 | |||
| 73 | 1 | color = av_dovi_get_color(md); | |
| 74 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | if ((uint8_t *)color != (uint8_t *)md + md->color_offset) |
| 75 | ✗ | printf("color: pointer inconsistent with color_offset\n"); | |
| 76 | 1 | printf("color_offset>0=%s, dm_metadata_id=%d\n", | |
| 77 | 1 | md->color_offset > 0 ? "yes" : "no", | |
| 78 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | color->dm_metadata_id); |
| 79 | |||
| 80 | 1 | printf("ext_block_size>0=%s\n", | |
| 81 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | md->ext_block_size > 0 ? "yes" : "no"); |
| 82 | |||
| 83 | 1 | av_free(md); | |
| 84 | } else { | ||
| 85 | ✗ | printf("alloc: FAIL\n"); | |
| 86 | } | ||
| 87 | |||
| 88 | 1 | md = av_dovi_metadata_alloc(NULL); | |
| 89 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | printf("alloc (no size): %s\n", md ? "OK" : "FAIL"); |
| 90 | 1 | av_free(md); | |
| 91 | |||
| 92 | /* av_dovi_find_level */ | ||
| 93 | 1 | printf("\nTesting av_dovi_find_level()\n"); | |
| 94 | 1 | md = av_dovi_metadata_alloc(NULL); | |
| 95 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | if (md) { |
| 96 | AVDOVIDmData *ext, *found; | ||
| 97 | |||
| 98 | /* set up 3 ext blocks with different levels */ | ||
| 99 | 1 | md->num_ext_blocks = 3; | |
| 100 | 1 | ext = av_dovi_get_ext(md, 0); | |
| 101 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | if ((uint8_t *)ext != (uint8_t *)md + md->ext_block_offset) |
| 102 | ✗ | printf("ext[0]: pointer inconsistent with ext_block_offset\n"); | |
| 103 | 1 | ext->level = 1; | |
| 104 | 1 | ext = av_dovi_get_ext(md, 1); | |
| 105 | 1 | ext->level = 5; | |
| 106 | 1 | ext = av_dovi_get_ext(md, 2); | |
| 107 | 1 | ext->level = 1; | |
| 108 | |||
| 109 | 1 | found = av_dovi_find_level(md, 1); | |
| 110 |
2/4✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
1 | printf("find level 1: %s\n", found && found->level == 1 ? "OK" : "FAIL"); |
| 111 | |||
| 112 | 1 | found = av_dovi_find_level(md, 5); | |
| 113 |
2/4✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
1 | printf("find level 5: %s\n", found && found->level == 5 ? "OK" : "FAIL"); |
| 114 | |||
| 115 | /* first match -- should return ext[0], not ext[2] */ | ||
| 116 | 1 | found = av_dovi_find_level(md, 1); | |
| 117 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | printf("find level 1 first match: %s\n", |
| 118 | 1 | found == av_dovi_get_ext(md, 0) ? "OK" : "FAIL"); | |
| 119 | |||
| 120 | 1 | found = av_dovi_find_level(md, 99); | |
| 121 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | printf("find level 99 (missing): %s\n", found == NULL ? "OK" : "FAIL"); |
| 122 | |||
| 123 | 1 | av_free(md); | |
| 124 | } | ||
| 125 | |||
| 126 | /* OOM paths via av_max_alloc */ | ||
| 127 | 1 | printf("\nTesting OOM paths\n"); | |
| 128 | 1 | av_max_alloc(1); | |
| 129 | 1 | cfg = av_dovi_alloc(&size); | |
| 130 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | printf("av_dovi_alloc OOM: %s\n", cfg ? "FAIL" : "OK"); |
| 131 | 1 | av_free(cfg); | |
| 132 | 1 | md = av_dovi_metadata_alloc(&size); | |
| 133 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | printf("av_dovi_metadata_alloc OOM: %s\n", md ? "FAIL" : "OK"); |
| 134 | 1 | av_free(md); | |
| 135 | 1 | av_max_alloc(INT_MAX); | |
| 136 | |||
| 137 | 1 | return 0; | |
| 138 | } | ||
| 139 |