libavformat/tests/codecstring.c
| 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 License | ||
| 6 | * 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 | ||
| 12 | * GNU Lesser General Public License for more details. | ||
| 13 | * | ||
| 14 | * You should have received a copy of the GNU Lesser General Public License | ||
| 15 | * 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 <stdio.h> | ||
| 20 | #include <string.h> | ||
| 21 | |||
| 22 | #include "libavutil/bprint.h" | ||
| 23 | #include "libavutil/macros.h" | ||
| 24 | #include "libavutil/mem.h" | ||
| 25 | #include "libavcodec/codec_par.h" | ||
| 26 | #include "libavcodec/defs.h" | ||
| 27 | #include "libavformat/avformat.h" | ||
| 28 | |||
| 29 | /* Extradata of a 160x120 encoding: libx264 High profile, libx265 Main | ||
| 30 | * profile. */ | ||
| 31 | static const uint8_t h264_annexb[] = { | ||
| 32 | 0x00, 0x00, 0x00, 0x01, 0x67, 0x64, 0x00, 0x0b, 0xac, 0xd9, 0x42, 0x84, | ||
| 33 | 0x7e, 0x5c, 0x04, 0x40, 0x00, 0x00, 0x03, 0x00, 0x40, 0x00, 0x00, 0x0c, | ||
| 34 | 0x83, 0xc5, 0x0a, 0x65, 0x80, | ||
| 35 | }; | ||
| 36 | |||
| 37 | static const uint8_t h264_avcc[] = { | ||
| 38 | 0x01, 0x64, 0x00, 0x0b, 0xff, 0xe1, | ||
| 39 | }; | ||
| 40 | |||
| 41 | static const uint8_t hevc_annexb[] = { | ||
| 42 | 0x00, 0x00, 0x00, 0x01, 0x42, 0x01, 0x01, 0x01, 0x60, 0x00, 0x00, 0x03, | ||
| 43 | 0x00, 0x90, 0x00, 0x00, 0x03, 0x00, 0x00, 0x03, 0x00, 0x1e, 0xa0, 0x14, | ||
| 44 | 0x20, 0x79, 0x65, 0x95, 0x9a, 0x49, 0x32, 0xbc, 0x05, 0xa0, 0x20, 0x00, | ||
| 45 | 0x00, 0x03, 0x00, 0x20, 0x00, 0x00, 0x03, 0x03, 0x21, 0x00, | ||
| 46 | }; | ||
| 47 | |||
| 48 | static const uint8_t hevc_annexb_3byte_start_code[] = { | ||
| 49 | 0x00, 0x00, 0x01, 0x42, 0x01, 0x01, 0x01, 0x60, 0x00, 0x00, 0x03, 0x00, | ||
| 50 | 0x90, 0x00, 0x00, 0x03, 0x00, 0x00, 0x03, 0x00, 0x1e, 0xa0, 0x14, 0x20, | ||
| 51 | 0x79, 0x65, 0x95, 0x9a, 0x49, 0x32, 0xbc, 0x05, 0xa0, 0x20, 0x00, 0x00, | ||
| 52 | 0x03, 0x00, 0x20, 0x00, 0x00, 0x03, 0x03, 0x21, 0x00, | ||
| 53 | }; | ||
| 54 | |||
| 55 | static const uint8_t hevc_hvcc[] = { | ||
| 56 | 0x01, 0x01, 0x60, 0x00, 0x00, 0x00, 0x90, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
| 57 | 0x1e, 0xf0, 0x00, 0xfc, 0xfd, 0xf8, 0xf8, 0x00, 0x00, 0x0f, 0x00, | ||
| 58 | }; | ||
| 59 | |||
| 60 | static const uint8_t hevc_hvcc_version0[] = { | ||
| 61 | 0x00, 0x01, 0x60, 0x00, 0x00, 0x00, 0x90, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
| 62 | 0x1e, 0xf0, 0x00, 0xfc, 0xfd, 0xf8, 0xf8, 0x00, 0x00, 0x0f, 0x00, | ||
| 63 | }; | ||
| 64 | |||
| 65 | static const uint8_t hevc_hvcc_zeroed[] = { | ||
| 66 | 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
| 67 | 0x00, 0xf0, 0x00, 0xfc, 0xfd, 0xf8, 0xf8, 0x00, 0x00, 0x0f, 0x00, | ||
| 68 | }; | ||
| 69 | |||
| 70 | static const uint8_t hevc_hvcc_profile_space[] = { | ||
| 71 | 0x01, 0x41, 0x60, 0x00, 0x00, 0x00, 0x90, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
| 72 | 0x1e, 0xf0, 0x00, 0xfc, 0xfd, 0xf8, 0xf8, 0x00, 0x00, 0x0f, 0x00, | ||
| 73 | }; | ||
| 74 | |||
| 75 | static const uint8_t hevc_hvcc_constraints[] = { | ||
| 76 | 0x01, 0x01, 0x60, 0x00, 0x00, 0x00, 0x90, 0x00, 0x10, 0x00, 0x00, 0x00, | ||
| 77 | 0x1e, 0xf0, 0x00, 0xfc, 0xfd, 0xf8, 0xf8, 0x00, 0x00, 0x0f, 0x00, | ||
| 78 | }; | ||
| 79 | |||
| 80 | static const uint8_t hevc_hvcc_constraints_full[] = { | ||
| 81 | 0x01, 0x01, 0x60, 0x00, 0x00, 0x00, 0x90, 0x10, 0x20, 0x30, 0x40, 0x50, | ||
| 82 | 0x1e, 0xf0, 0x00, 0xfc, 0xfd, 0xf8, 0xf8, 0x00, 0x00, 0x0f, 0x00, | ||
| 83 | }; | ||
| 84 | |||
| 85 | static const uint8_t hevc_annexb_leading_zero[] = { | ||
| 86 | 0x00, 0x00, 0x00, 0x00, 0x01, 0x42, 0x01, 0x01, 0x01, 0x60, 0x00, 0x00, | ||
| 87 | 0x03, 0x00, 0x90, 0x00, 0x00, 0x03, 0x00, 0x00, 0x03, 0x00, 0x1e, 0xa0, | ||
| 88 | 0x14, 0x20, 0x79, 0x65, 0x95, 0x9a, 0x49, 0x32, 0xbc, 0x05, 0xa0, 0x20, | ||
| 89 | 0x00, 0x00, 0x03, 0x00, 0x20, 0x00, 0x00, 0x03, 0x03, 0x21, 0x00, | ||
| 90 | }; | ||
| 91 | |||
| 92 | /* hevc_annexb with the maximum of 32 long-term reference pictures */ | ||
| 93 | static const uint8_t hevc_annexb_32_long_term_refs[] = { | ||
| 94 | 0x00, 0x00, 0x00, 0x01, 0x42, 0x01, 0x01, 0x01, 0x60, 0x00, 0x00, 0x03, | ||
| 95 | 0x00, 0x90, 0x00, 0x00, 0x03, 0x00, 0x00, 0x03, 0x00, 0x1e, 0xa0, 0x14, | ||
| 96 | 0x20, 0x79, 0x65, 0x95, 0x9a, 0x49, 0x32, 0xc1, 0x08, 0x00, 0x04, 0x04, | ||
| 97 | 0x03, 0x02, 0x01, 0x40, 0xc0, 0x70, 0x40, 0x24, 0x14, 0x0b, 0x06, 0x03, | ||
| 98 | 0x41, 0xc0, 0xf0, 0x80, 0x44, 0x24, 0x13, 0x0a, 0x05, 0x42, 0xc1, 0x70, | ||
| 99 | 0xc0, 0x64, 0x34, 0x1b, 0x0e, 0x07, 0x43, 0xc1, 0xf7, 0x80, 0xb4, 0x04, | ||
| 100 | 0x00, 0x00, 0x03, 0x00, 0x04, 0x00, 0x00, 0x03, 0x00, 0x64, 0x20, | ||
| 101 | }; | ||
| 102 | |||
| 103 | typedef struct TestCase { | ||
| 104 | const char *name; | ||
| 105 | enum AVCodecID codec_id; | ||
| 106 | uint32_t codec_tag; | ||
| 107 | int profile; | ||
| 108 | const uint8_t *extradata; | ||
| 109 | int extradata_size; | ||
| 110 | } TestCase; | ||
| 111 | |||
| 112 | static const TestCase cases[] = { | ||
| 113 | { "h264-annexb", AV_CODEC_ID_H264, 0, | ||
| 114 | AV_PROFILE_UNKNOWN, h264_annexb, sizeof(h264_annexb) }, | ||
| 115 | { "h264-annexb-avc3", AV_CODEC_ID_H264, MKTAG('a', 'v', 'c', '3'), | ||
| 116 | AV_PROFILE_UNKNOWN, h264_annexb, sizeof(h264_annexb) }, | ||
| 117 | { "h264-avcc", AV_CODEC_ID_H264, MKTAG('a', 'v', 'c', '1'), | ||
| 118 | AV_PROFILE_UNKNOWN, h264_avcc, sizeof(h264_avcc) }, | ||
| 119 | { "hevc-annexb-hvc1", AV_CODEC_ID_HEVC, MKTAG('h', 'v', 'c', '1'), | ||
| 120 | AV_PROFILE_UNKNOWN, hevc_annexb, sizeof(hevc_annexb) }, | ||
| 121 | { "hevc-annexb-hev1", AV_CODEC_ID_HEVC, MKTAG('h', 'e', 'v', '1'), | ||
| 122 | AV_PROFILE_UNKNOWN, hevc_annexb, sizeof(hevc_annexb) }, | ||
| 123 | { "hevc-annexb-3byte-start-code", AV_CODEC_ID_HEVC, | ||
| 124 | MKTAG('h', 'v', 'c', '1'), AV_PROFILE_UNKNOWN, | ||
| 125 | hevc_annexb_3byte_start_code, sizeof(hevc_annexb_3byte_start_code) }, | ||
| 126 | { "hevc-annexb-untagged", AV_CODEC_ID_HEVC, 0, | ||
| 127 | AV_PROFILE_UNKNOWN, hevc_annexb, sizeof(hevc_annexb) }, | ||
| 128 | { "hevc-hvcc-hvc1", AV_CODEC_ID_HEVC, MKTAG('h', 'v', 'c', '1'), | ||
| 129 | AV_PROFILE_UNKNOWN, hevc_hvcc, sizeof(hevc_hvcc) }, | ||
| 130 | { "hevc-hvcc-hev1", AV_CODEC_ID_HEVC, MKTAG('h', 'e', 'v', '1'), | ||
| 131 | AV_PROFILE_UNKNOWN, hevc_hvcc, sizeof(hevc_hvcc) }, | ||
| 132 | { "hevc-hvcc-version0", AV_CODEC_ID_HEVC, MKTAG('h', 'v', 'c', '1'), | ||
| 133 | AV_PROFILE_UNKNOWN, hevc_hvcc_version0, sizeof(hevc_hvcc_version0) }, | ||
| 134 | { "hevc-hvcc-zeroed", AV_CODEC_ID_HEVC, MKTAG('h', 'v', 'c', '1'), | ||
| 135 | AV_PROFILE_HEVC_MAIN, hevc_hvcc_zeroed, sizeof(hevc_hvcc_zeroed) }, | ||
| 136 | { "hevc-hvcc-profile-space", AV_CODEC_ID_HEVC, MKTAG('h', 'v', 'c', '1'), | ||
| 137 | AV_PROFILE_UNKNOWN, hevc_hvcc_profile_space, | ||
| 138 | sizeof(hevc_hvcc_profile_space) }, | ||
| 139 | { "hevc-hvcc-constraints", AV_CODEC_ID_HEVC, MKTAG('h', 'v', 'c', '1'), | ||
| 140 | AV_PROFILE_UNKNOWN, hevc_hvcc_constraints, | ||
| 141 | sizeof(hevc_hvcc_constraints) }, | ||
| 142 | { "hevc-hvcc-constraints-full", AV_CODEC_ID_HEVC, | ||
| 143 | MKTAG('h', 'v', 'c', '1'), AV_PROFILE_UNKNOWN, | ||
| 144 | hevc_hvcc_constraints_full, sizeof(hevc_hvcc_constraints_full) }, | ||
| 145 | { "hevc-annexb-32-long-term-refs", AV_CODEC_ID_HEVC, | ||
| 146 | MKTAG('h', 'v', 'c', '1'), AV_PROFILE_UNKNOWN, | ||
| 147 | hevc_annexb_32_long_term_refs, sizeof(hevc_annexb_32_long_term_refs) }, | ||
| 148 | { "hevc-annexb-leading-zero", AV_CODEC_ID_HEVC, MKTAG('h', 'v', 'c', '1'), | ||
| 149 | AV_PROFILE_UNKNOWN, hevc_annexb_leading_zero, | ||
| 150 | sizeof(hevc_annexb_leading_zero) }, | ||
| 151 | { "aac-lc", AV_CODEC_ID_AAC, 0, | ||
| 152 | AV_PROFILE_AAC_LOW, NULL, 0 }, | ||
| 153 | }; | ||
| 154 | |||
| 155 | 17 | static int run_case(const TestCase *test) | |
| 156 | { | ||
| 157 | 17 | AVCodecParameters *par = avcodec_parameters_alloc(); | |
| 158 | AVBPrint out; | ||
| 159 | int ret; | ||
| 160 | |||
| 161 | 17 | if (!par) | |
| 162 | ✗ | return AVERROR(ENOMEM); | |
| 163 | 17 | par->codec_id = test->codec_id; | |
| 164 | 17 | par->codec_tag = test->codec_tag; | |
| 165 | 17 | par->profile = test->profile; | |
| 166 | 17 | if (test->extradata_size) { | |
| 167 | 16 | par->extradata = av_mallocz(test->extradata_size + | |
| 168 | AV_INPUT_BUFFER_PADDING_SIZE); | ||
| 169 | 16 | if (!par->extradata) { | |
| 170 | ✗ | avcodec_parameters_free(&par); | |
| 171 | ✗ | return AVERROR(ENOMEM); | |
| 172 | } | ||
| 173 | 16 | memcpy(par->extradata, test->extradata, test->extradata_size); | |
| 174 | 16 | par->extradata_size = test->extradata_size; | |
| 175 | } | ||
| 176 | |||
| 177 | 17 | av_bprint_init(&out, 0, AV_BPRINT_SIZE_UNLIMITED); | |
| 178 | 17 | ret = av_mime_codec_str(par, (AVRational){ 1, 0 }, &out); | |
| 179 | 17 | printf("%s: %s\n", test->name, ret < 0 ? "error" : out.str); | |
| 180 | 17 | av_bprint_finalize(&out, NULL); | |
| 181 | 17 | avcodec_parameters_free(&par); | |
| 182 | |||
| 183 | 17 | return ret == AVERROR(ENOMEM) ? ret : 0; | |
| 184 | } | ||
| 185 | |||
| 186 | 1 | int main(void) | |
| 187 | { | ||
| 188 | 18 | for (size_t i = 0; i < FF_ARRAY_ELEMS(cases); i++) | |
| 189 | 17 | if (run_case(&cases[i]) < 0) | |
| 190 | ✗ | return 1; | |
| 191 | 1 | return 0; | |
| 192 | } | ||
| 193 |