FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
hevc_ps_enc.c
Go to the documentation of this file.
1 /*
2  * HEVC Parameter Set encoding
3  *
4  * This file is part of FFmpeg.
5  *
6  * FFmpeg is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * FFmpeg is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with FFmpeg; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20 
21 #include "golomb.h"
22 #include "hevc_ps.h"
23 #include "put_bits.h"
24 
25 static void write_ptl_layer(PutBitContext *pb, PTLCommon *ptl)
26 {
27  int i;
28 
29  put_bits(pb, 2, ptl->profile_space);
30  put_bits(pb, 1, ptl->tier_flag);
31  put_bits(pb, 5, ptl->profile_idc);
32  for (i = 0; i < 32; i++)
33  put_bits(pb, 1, ptl->profile_compatibility_flag[i]);
34  put_bits(pb, 1, ptl->progressive_source_flag);
35  put_bits(pb, 1, ptl->interlaced_source_flag);
38  put_bits32(pb, 0); // reserved
39  put_bits(pb, 12, 0); // reserved
40 }
41 
42 static void write_ptl(PutBitContext *pb, PTL *ptl, int max_num_sub_layers)
43 {
44  int i;
45 
46  write_ptl_layer(pb, &ptl->general_ptl);
47  put_bits(pb, 8, ptl->general_ptl.level_idc);
48 
49  for (i = 0; i < max_num_sub_layers - 1; i++) {
51  put_bits(pb, 1, ptl->sub_layer_level_present_flag[i]);
52  }
53 
54  if (max_num_sub_layers > 1)
55  for (i = max_num_sub_layers - 1; i < 8; i++)
56  put_bits(pb, 2, 0); // reserved
57 
58  for (i = 0; i < max_num_sub_layers - 1; i++) {
60  write_ptl_layer(pb, &ptl->sub_layer_ptl[i]);
61  if (ptl->sub_layer_level_present_flag[i])
62  put_bits(pb, 8, ptl->sub_layer_ptl[i].level_idc);
63  }
64 }
65 
66 int ff_hevc_encode_nal_vps(HEVCVPS *vps, unsigned int id,
67  uint8_t *buf, int buf_size)
68 {
69  PutBitContext pb;
70  int i;
71 
72  init_put_bits(&pb, buf, buf_size);
73  put_bits(&pb, 4, id);
74  put_bits(&pb, 2, 3); // reserved
75  put_bits(&pb, 6, vps->vps_max_layers - 1);
76  put_bits(&pb, 3, vps->vps_max_sub_layers - 1);
78  put_bits(&pb, 16, 0xffff); // reserved
79 
80  write_ptl(&pb, &vps->ptl, vps->vps_max_sub_layers);
81 
83  for (i = vps->vps_sub_layer_ordering_info_present_flag ? 0 : vps->vps_max_layers - 1;
84  i < vps->vps_max_sub_layers; i++) {
85  set_ue_golomb(&pb, vps->vps_max_dec_pic_buffering[i] - 1);
86  set_ue_golomb(&pb, vps->vps_num_reorder_pics[i]);
87  set_ue_golomb(&pb, vps->vps_max_latency_increase[i] + 1);
88  }
89 
90  put_bits(&pb, 6, vps->vps_max_layer_id);
91  set_ue_golomb(&pb, vps->vps_num_layer_sets - 1);
92 
93  if (vps->vps_num_layer_sets > 1) {
94  avpriv_report_missing_feature(NULL, "Writing layer_id_included_flag");
95  return AVERROR_PATCHWELCOME;
96  }
97 
101  put_bits32(&pb, vps->vps_time_scale);
105 
106  if (vps->vps_num_hrd_parameters) {
107  avpriv_report_missing_feature(NULL, "Writing HRD parameters");
108  return AVERROR_PATCHWELCOME;
109  }
110  }
111 
112  put_bits(&pb, 1, 0); // extension flag
113 
114  put_bits(&pb, 1, 1); // stop bit
116 
117  return put_bits_count(&pb) / 8;
118 }
PTLCommon sub_layer_ptl[HEVC_MAX_SUB_LAYERS]
Definition: hevc_ps.h:189
static void av_unused put_bits32(PutBitContext *s, uint32_t value)
Write exactly 32 bits into a bitstream.
Definition: put_bits.h:250
#define NULL
Definition: coverity.c:32
static void put_bits(Jpeg2000EncoderContext *s, int val, int n)
put n times val bit
Definition: j2kenc.c:208
static void set_ue_golomb(PutBitContext *pb, int i)
write unsigned exp golomb code.
Definition: golomb.h:614
int vps_num_ticks_poc_diff_one
vps_num_ticks_poc_diff_one_minus1 + 1
Definition: hevc_ps.h:211
unsigned int vps_max_latency_increase[HEVC_MAX_SUB_LAYERS]
Definition: hevc_ps.h:204
void avpriv_align_put_bits(PutBitContext *s)
Pad the bitstream with zeros up to the next byte boundary.
Definition: bitstream.c:48
Definition: hevc_ps.h:187
unsigned int vps_max_dec_pic_buffering[HEVC_MAX_SUB_LAYERS]
Definition: hevc_ps.h:202
static void write_ptl(PutBitContext *pb, PTL *ptl, int max_num_sub_layers)
Definition: hevc_ps_enc.c:42
uint8_t profile_compatibility_flag[32]
Definition: hevc_ps.h:179
uint8_t
uint8_t vps_timing_info_present_flag
Definition: hevc_ps.h:207
int vps_max_sub_layers
vps_max_temporal_layers_minus1 + 1
Definition: hevc_ps.h:198
uint8_t tier_flag
Definition: hevc_ps.h:177
int vps_max_layer_id
Definition: hevc_ps.h:205
uint8_t frame_only_constraint_flag
Definition: hevc_ps.h:184
int vps_max_layers
Definition: hevc_ps.h:197
uint8_t vps_temporal_id_nesting_flag
Definition: hevc_ps.h:196
static int put_bits_count(PutBitContext *s)
Definition: put_bits.h:85
uint32_t vps_num_units_in_tick
Definition: hevc_ps.h:208
uint8_t sub_layer_level_present_flag[HEVC_MAX_SUB_LAYERS]
Definition: hevc_ps.h:192
int vps_num_layer_sets
vps_num_layer_sets_minus1 + 1
Definition: hevc_ps.h:206
uint8_t profile_idc
Definition: hevc_ps.h:178
uint8_t vps_poc_proportional_to_timing_flag
Definition: hevc_ps.h:210
unsigned int vps_num_reorder_pics[HEVC_MAX_SUB_LAYERS]
Definition: hevc_ps.h:203
static void write_ptl_layer(PutBitContext *pb, PTLCommon *ptl)
Definition: hevc_ps_enc.c:25
PTLCommon general_ptl
Definition: hevc_ps.h:188
uint8_t sub_layer_profile_present_flag[HEVC_MAX_SUB_LAYERS]
Definition: hevc_ps.h:191
PTL ptl
Definition: hevc_ps.h:200
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
Definition: error.h:62
uint32_t vps_time_scale
Definition: hevc_ps.h:209
void * buf
Definition: avisynth_c.h:690
int vps_num_hrd_parameters
Definition: hevc_ps.h:212
static int FUNC() vps(CodedBitstreamContext *ctx, RWContext *rw, H265RawVPS *current)
void avpriv_report_missing_feature(void *avc, const char *msg,...) av_printf_format(2
Log a generic warning message about a missing feature.
uint8_t level_idc
Definition: hevc_ps.h:180
uint8_t profile_space
Definition: hevc_ps.h:176
static void init_put_bits(PutBitContext *s, uint8_t *buffer, int buffer_size)
Initialize the PutBitContext s.
Definition: put_bits.h:48
int ff_hevc_encode_nal_vps(HEVCVPS *vps, unsigned int id, uint8_t *buf, int buf_size)
Definition: hevc_ps_enc.c:66
uint8_t progressive_source_flag
Definition: hevc_ps.h:181
uint8_t non_packed_constraint_flag
Definition: hevc_ps.h:183
exp golomb vlc stuff
uint8_t interlaced_source_flag
Definition: hevc_ps.h:182
int vps_sub_layer_ordering_info_present_flag
Definition: hevc_ps.h:201
bitstream writer API