FFmpeg
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 "put_golomb.h"
22 #include "hevc_ps.h"
23 #include "put_bits.h"
24 
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);
36  put_bits(pb, 1, ptl->non_packed_constraint_flag);
37  put_bits(pb, 1, ptl->frame_only_constraint_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++) {
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]);
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, data_size;
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);
77  put_bits(&pb, 1, vps->vps_temporal_id_nesting_flag);
78  put_bits(&pb, 16, 0xffff); // reserved
79 
80  write_ptl(&pb, &vps->ptl, vps->vps_max_sub_layers);
81 
82  put_bits(&pb, 1, vps->vps_sub_layer_ordering_info_present_flag);
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 
98  put_bits(&pb, 1, vps->vps_timing_info_present_flag);
99  if (vps->vps_timing_info_present_flag) {
100  put_bits32(&pb, vps->vps_num_units_in_tick);
101  put_bits32(&pb, vps->vps_time_scale);
102  put_bits(&pb, 1, vps->vps_poc_proportional_to_timing_flag);
103  if (vps->vps_poc_proportional_to_timing_flag)
104  set_ue_golomb(&pb, vps->vps_num_ticks_poc_diff_one - 1);
105 
106  set_ue_golomb(&pb, vps->vps_num_hrd_parameters);
107  if (vps->vps_num_hrd_parameters) {
108  avpriv_report_missing_feature(NULL, "Writing HRD parameters");
109  return AVERROR_PATCHWELCOME;
110  }
111  }
112 
113  put_bits(&pb, 1, 0); // extension flag
114 
115  put_bits(&pb, 1, 1); // stop bit
116  flush_put_bits(&pb);
117 
118  data_size = put_bytes_output(&pb);
119 
120  return data_size;
121 }
put_bits32
static void av_unused put_bits32(PutBitContext *s, uint32_t value)
Write exactly 32 bits into a bitstream.
Definition: put_bits.h:291
put_bytes_output
static int put_bytes_output(const PutBitContext *s)
Definition: put_bits.h:89
init_put_bits
static void init_put_bits(PutBitContext *s, uint8_t *buffer, int buffer_size)
Initialize the PutBitContext s.
Definition: put_bits.h:62
put_bits
static void put_bits(Jpeg2000EncoderContext *s, int val, int n)
put n times val bit
Definition: j2kenc.c:223
H265RawProfileTierLevel::sub_layer_level_present_flag
uint8_t sub_layer_level_present_flag[HEVC_MAX_SUB_LAYERS]
Definition: cbs_h265.h:63
H265RawProfileTierLevel::sub_layer_profile_present_flag
uint8_t sub_layer_profile_present_flag[HEVC_MAX_SUB_LAYERS]
Definition: cbs_h265.h:62
put_golomb.h
exp golomb vlc writing stuff
write_ptl
static void write_ptl(PutBitContext *pb, PTL *ptl, int max_num_sub_layers)
Definition: hevc_ps_enc.c:42
ptl
const H265RawProfileTierLevel * ptl
Definition: h265_levels.c:170
PTLCommon
Definition: hevc_ps.h:124
PutBitContext
Definition: put_bits.h:50
NULL
#define NULL
Definition: coverity.c:32
AVERROR_PATCHWELCOME
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
Definition: error.h:64
PTL
Definition: hevc_ps.h:147
vps
static int FUNC() vps(CodedBitstreamContext *ctx, RWContext *rw, H265RawVPS *current)
Definition: cbs_h265_syntax_template.c:423
write_ptl_layer
static void write_ptl_layer(PutBitContext *pb, PTLCommon *ptl)
Definition: hevc_ps_enc.c:25
avpriv_report_missing_feature
void avpriv_report_missing_feature(void *avc, const char *msg,...) av_printf_format(2
Log a generic warning message about a missing feature.
hevc_ps.h
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:256
set_ue_golomb
static void set_ue_golomb(PutBitContext *pb, int i)
write unsigned exp golomb code.
Definition: put_golomb.h:41
HEVCVPS
Definition: hevc_ps.h:155
flush_put_bits
static void flush_put_bits(PutBitContext *s)
Pad the end of the output stream with zeros.
Definition: put_bits.h:143
put_bits.h
ff_hevc_encode_nal_vps
int ff_hevc_encode_nal_vps(HEVCVPS *vps, unsigned int id, uint8_t *buf, int buf_size)
Definition: hevc_ps_enc.c:66