FFmpeg
Loading...
Searching...
No Matches
tdrdi.c
Go to the documentation of this file.
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/mem.h"
24#include "libavutil/tdrdi.h"
25
26int main(void)
27{
29 AV3DReferenceDisplay *display;
30 size_t size;
31
32 /* av_tdrdi_alloc with 1 display */
33 printf("Testing av_tdrdi_alloc()\n");
34 tdrdi = av_tdrdi_alloc(1, &size);
35 if (tdrdi) {
36 printf("alloc 1: size>0=%s, num_ref_displays=%u\n",
37 size > 0 ? "yes" : "no", tdrdi->num_ref_displays);
38
39 display = av_tdrdi_get_display(tdrdi, 0);
40 /* pointer consistency check */
41 if ((uint8_t *)display != (uint8_t *)tdrdi + tdrdi->entries_offset)
42 printf("display 0: pointer inconsistent with entries_offset\n");
43
44 /* write and read back */
45 display->exponent_ref_display_width = 3;
46 display->mantissa_ref_display_width = 100;
47 display->left_view_id = 0;
48 display->right_view_id = 1;
49 display = av_tdrdi_get_display(tdrdi, 0);
50 printf("display 0: width_exp=%u width_man=%u left=%u right=%u\n",
53 display->left_view_id, display->right_view_id);
54 av_free(tdrdi);
55 }
56
57 /* alloc with multiple displays */
58 printf("\nTesting multiple displays\n");
59 tdrdi = av_tdrdi_alloc(3, &size);
60 if (tdrdi) {
61 printf("alloc 3: num_ref_displays=%u\n", tdrdi->num_ref_displays);
62 for (int i = 0; i < 3; i++) {
63 display = av_tdrdi_get_display(tdrdi, i);
64 /* verify stride consistency */
65 if ((uint8_t *)display != (uint8_t *)tdrdi + tdrdi->entries_offset +
66 (size_t)i * tdrdi->entry_size)
67 printf("display %d: pointer inconsistent\n", i);
68 display->exponent_ref_display_width = i + 1;
69 }
70 for (int i = 0; i < 3; i++) {
71 display = av_tdrdi_get_display(tdrdi, i);
72 printf("display %d: width_exp=%u\n", i,
74 }
75 av_free(tdrdi);
76 }
77
78 /* alloc with NULL size */
79 tdrdi = av_tdrdi_alloc(1, NULL);
80 printf("\nalloc (no size): %s\n", tdrdi ? "OK" : "FAIL");
81 av_free(tdrdi);
82
83 /* OOM paths via av_max_alloc */
84 printf("\nTesting OOM paths\n");
85 av_max_alloc(1);
86 tdrdi = av_tdrdi_alloc(1, &size);
87 printf("alloc OOM: %s\n", tdrdi ? "FAIL" : "OK");
88 av_free(tdrdi);
89 av_max_alloc(INT_MAX);
90
91 return 0;
92}
#define i(width, name, range_min, range_max)
Definition cbs_h264.c:63
#define NULL
Definition coverity.c:32
__device__ int printf(const char *,...)
void av_max_alloc(size_t max)
Set the maximum size that may be allocated in one block.
Definition mem.c:76
AV3DReferenceDisplaysInfo * av_tdrdi_alloc(unsigned int nb_displays, size_t *out_size)
Allocate a AV3DReferenceDisplaysInfo structure and initialize its fields to default values.
Definition tdrdi.c:25
static av_always_inline AV3DReferenceDisplay * av_tdrdi_get_display(AV3DReferenceDisplaysInfo *tdrdi, unsigned int idx)
Definition tdrdi.h:145
Memory handling functions.
Data structure for single deference display information.
Definition tdrdi.h:100
uint16_t left_view_id
The ViewId of the left view of a stereo pair corresponding to the n-th reference display.
Definition tdrdi.h:104
uint8_t mantissa_ref_display_width
The mantissa part of the reference display width of the n-th reference display.
Definition tdrdi.h:119
uint8_t exponent_ref_display_width
The exponent part of the reference display width of the n-th reference display.
Definition tdrdi.h:114
uint16_t right_view_id
The ViewId of the left view of a stereo pair corresponding to the n-th reference display.
Definition tdrdi.h:109
This structure describes information about the reference display width(s) and reference viewing dista...
Definition tdrdi.h:53
size_t entry_size
Size of each entry in bytes.
Definition tdrdi.h:89
uint8_t num_ref_displays
The number of reference displays that are signalled in this struct.
Definition tdrdi.h:78
size_t entries_offset
Offset in bytes from the beginning of this structure at which the array of reference displays starts.
Definition tdrdi.h:84
#define av_free(p)
Spherical video.
int main(void)
Definition tdrdi.c:26
int size