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.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  // writing layer_id_included_flag not supported
94  if (vps->vps_num_layer_sets > 1)
95  return AVERROR_PATCHWELCOME;
96 
100  put_bits32(&pb, vps->vps_time_scale);
104 
105  // writing HRD parameters not supported
106  if (vps->vps_num_hrd_parameters)
107  return AVERROR_PATCHWELCOME;
108  }
109 
110  put_bits(&pb, 1, 0); // extension flag
111 
112  put_bits(&pb, 1, 1); // stop bit
114 
115  return put_bits_count(&pb) / 8;
116 }
static void av_unused put_bits32(PutBitContext *s, uint32_t value)
Write exactly 32 bits into a bitstream.
Definition: put_bits.h:210
static void put_bits(Jpeg2000EncoderContext *s, int val, int n)
put n times val bit
Definition: j2kenc.c:206
static void set_ue_golomb(PutBitContext *pb, int i)
write unsigned exp golomb code.
Definition: golomb.h:458
int vps_num_ticks_poc_diff_one
vps_num_ticks_poc_diff_one_minus1 + 1
Definition: hevc.h:388
void avpriv_align_put_bits(PutBitContext *s)
Pad the bitstream with zeros up to the next byte boundary.
Definition: bitstream.c:49
Definition: hevc.h:364
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.h:356
uint8_t
uint8_t sub_layer_profile_present_flag[MAX_SUB_LAYERS]
Definition: hevc.h:368
unsigned int vps_num_reorder_pics[MAX_SUB_LAYERS]
Definition: hevc.h:380
uint8_t vps_timing_info_present_flag
Definition: hevc.h:384
int vps_max_sub_layers
vps_max_temporal_layers_minus1 + 1
Definition: hevc.h:375
uint8_t tier_flag
Definition: hevc.h:354
int vps_max_layer_id
Definition: hevc.h:382
uint8_t frame_only_constraint_flag
Definition: hevc.h:361
int vps_max_layers
Definition: hevc.h:374
uint8_t vps_temporal_id_nesting_flag
Definition: hevc.h:373
static int put_bits_count(PutBitContext *s)
Definition: put_bits.h:85
uint32_t vps_num_units_in_tick
Definition: hevc.h:385
int vps_num_layer_sets
vps_num_layer_sets_minus1 + 1
Definition: hevc.h:383
uint8_t profile_idc
Definition: hevc.h:355
uint8_t vps_poc_proportional_to_timing_flag
Definition: hevc.h:387
static void write_ptl_layer(PutBitContext *pb, PTLCommon *ptl)
Definition: hevc_ps_enc.c:25
PTLCommon general_ptl
Definition: hevc.h:365
PTL ptl
Definition: hevc.h:377
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
Definition: error.h:62
uint32_t vps_time_scale
Definition: hevc.h:386
uint8_t sub_layer_level_present_flag[MAX_SUB_LAYERS]
Definition: hevc.h:369
Definition: hevc.h:372
void * buf
Definition: avisynth_c.h:690
int vps_num_hrd_parameters
Definition: hevc.h:389
uint8_t level_idc
Definition: hevc.h:357
uint8_t profile_space
Definition: hevc.h:353
static void init_put_bits(PutBitContext *s, uint8_t *buffer, int buffer_size)
Initialize the PutBitContext s.
Definition: put_bits.h:48
PTLCommon sub_layer_ptl[MAX_SUB_LAYERS]
Definition: hevc.h:366
unsigned int vps_max_dec_pic_buffering[MAX_SUB_LAYERS]
Definition: hevc.h:379
unsigned int vps_max_latency_increase[MAX_SUB_LAYERS]
Definition: hevc.h:381
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.h:358
uint8_t non_packed_constraint_flag
Definition: hevc.h:360
exp golomb vlc stuff
uint8_t interlaced_source_flag
Definition: hevc.h:359
int vps_sub_layer_ordering_info_present_flag
Definition: hevc.h:378
bitstream writer API