libavcodec/tests/packet_side_data_handle.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 | ||
| 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 <stdio.h> | ||
| 20 | #include <string.h> | ||
| 21 | |||
| 22 | #include "libavcodec/packet.h" | ||
| 23 | #include "libavcodec/packet_internal.h" | ||
| 24 | |||
| 25 | #define HANDLE_CHARS "abcdefghijklmnopqrstuvwxyz0123456789_" | ||
| 26 | |||
| 27 | #define SET_HANDLE(type, handle) \ | ||
| 28 | if (handles[AV_PKT_DATA_ ## type]) { \ | ||
| 29 | printf("%s: second handle %s\n", #type, handle); \ | ||
| 30 | ret = 1; \ | ||
| 31 | } \ | ||
| 32 | handles[AV_PKT_DATA_ ## type] = handle; | ||
| 33 | |||
| 34 | /* | ||
| 35 | * Every side data type needs exactly one handle, and no two types may share | ||
| 36 | * one. A handle is typed in options, where '+' and '-' have a meaning, so it | ||
| 37 | * is made of [a-z0-9_] only. The handles are printed and compared with the | ||
| 38 | * reference, since a released handle must not change. | ||
| 39 | */ | ||
| 40 | 1 | int main(void) | |
| 41 | { | ||
| 42 | 1 | const char *handles[AV_PKT_DATA_NB] = { NULL }; | |
| 43 | 1 | int ret = 0; | |
| 44 | |||
| 45 | 1 | FF_PACKET_SIDE_DATA_HANDLES(SET_HANDLE) | |
| 46 | |||
| 47 | 45 | for (int type = 0; type < AV_PKT_DATA_NB; type++) { | |
| 48 | 44 | printf("%2d: %s\n", type, handles[type] ? handles[type] : "(none)"); | |
| 49 | 44 | if (!handles[type]) | |
| 50 | ✗ | ret = 1; | |
| 51 | 44 | else if (strspn(handles[type], HANDLE_CHARS) != strlen(handles[type])) { | |
| 52 | ✗ | printf("%2d: character outside of [a-z0-9_]\n", type); | |
| 53 | ✗ | ret = 1; | |
| 54 | } | ||
| 55 | |||
| 56 | 990 | for (int other = 0; handles[type] && other < type; other++) { | |
| 57 | 946 | if (handles[other] && !strcmp(handles[type], handles[other])) { | |
| 58 | ✗ | printf("%2d: handle of type %d\n", type, other); | |
| 59 | ✗ | ret = 1; | |
| 60 | } | ||
| 61 | } | ||
| 62 | } | ||
| 63 | |||
| 64 | 1 | return ret; | |
| 65 | } | ||
| 66 |