]> git.sesse.net Git - ffmpeg/blob - libavcodec/cbs_sei_syntax_template.c
cbs_h2645: Merge SEI messages in common between codecs
[ffmpeg] / libavcodec / cbs_sei_syntax_template.c
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 static int FUNC(sei_user_data_registered)
20     (CodedBitstreamContext *ctx, RWContext *rw,
21      SEIRawUserDataRegistered *current, uint32_t *payload_size)
22 {
23     int err, i, j;
24
25     HEADER("User Data Registered ITU-T T.35");
26
27     u(8, itu_t_t35_country_code, 0x00, 0xff);
28     if (current->itu_t_t35_country_code != 0xff)
29         i = 1;
30     else {
31         u(8, itu_t_t35_country_code_extension_byte, 0x00, 0xff);
32         i = 2;
33     }
34
35 #ifdef READ
36     if (*payload_size < i) {
37         av_log(ctx->log_ctx, AV_LOG_ERROR,
38                "Invalid SEI user data registered payload.\n");
39         return AVERROR_INVALIDDATA;
40     }
41     current->data_length = *payload_size - i;
42 #else
43     *payload_size = i + current->data_length;
44 #endif
45
46     allocate(current->data, current->data_length);
47     for (j = 0; j < current->data_length; j++)
48         xu(8, itu_t_t35_payload_byte[], current->data[j], 0x00, 0xff, 1, i + j);
49
50     return 0;
51 }
52
53 static int FUNC(sei_user_data_unregistered)
54     (CodedBitstreamContext *ctx, RWContext *rw,
55      SEIRawUserDataUnregistered *current, uint32_t *payload_size)
56 {
57     int err, i;
58
59     HEADER("User Data Unregistered");
60
61 #ifdef READ
62     if (*payload_size < 16) {
63         av_log(ctx->log_ctx, AV_LOG_ERROR,
64                "Invalid SEI user data unregistered payload.\n");
65         return AVERROR_INVALIDDATA;
66     }
67     current->data_length = *payload_size - 16;
68 #else
69     *payload_size = 16 + current->data_length;
70 #endif
71
72     for (i = 0; i < 16; i++)
73         us(8, uuid_iso_iec_11578[i], 0x00, 0xff, 1, i);
74
75     allocate(current->data, current->data_length);
76
77     for (i = 0; i < current->data_length; i++)
78         xu(8, user_data_payload_byte[i], current->data[i], 0x00, 0xff, 1, i);
79
80     return 0;
81 }
82
83 static int FUNC(sei_mastering_display_colour_volume)
84     (CodedBitstreamContext *ctx, RWContext *rw,
85      SEIRawMasteringDisplayColourVolume *current)
86 {
87     int err, c;
88
89     HEADER("Mastering Display Colour Volume");
90
91     for (c = 0; c < 3; c++) {
92         us(16, display_primaries_x[c], 0, 50000, 1, c);
93         us(16, display_primaries_y[c], 0, 50000, 1, c);
94     }
95
96     u(16, white_point_x, 0, 50000);
97     u(16, white_point_y, 0, 50000);
98
99     u(32, max_display_mastering_luminance,
100       1, MAX_UINT_BITS(32));
101     u(32, min_display_mastering_luminance,
102       0, current->max_display_mastering_luminance - 1);
103
104     return 0;
105 }
106
107 static int FUNC(sei_content_light_level)
108     (CodedBitstreamContext *ctx, RWContext *rw,
109      SEIRawContentLightLevelInfo *current)
110 {
111     int err;
112
113     HEADER("Content Light Level");
114
115     ub(16, max_content_light_level);
116     ub(16, max_pic_average_light_level);
117
118     return 0;
119 }
120
121 static int FUNC(sei_alternative_transfer_characteristics)
122     (CodedBitstreamContext *ctx, RWContext *rw,
123      SEIRawAlternativeTransferCharacteristics *current)
124 {
125     int err;
126
127     HEADER("Alternative Transfer Characteristics");
128
129     ub(8, preferred_transfer_characteristics);
130
131     return 0;
132 }