From a2245645c8b3948de32f2c27f8cb0acb86e4d2d4 Mon Sep 17 00:00:00 2001 From: Loren Merritt Date: Fri, 11 Mar 2005 02:15:25 +0000 Subject: [PATCH] write VUI bitstream restrictions git-svn-id: svn://svn.videolan.org/x264/trunk@162 df754926-b1dd-0310-bc7b-ec298dee348c --- common/set.h | 9 +++++++++ encoder/encoder.c | 1 + encoder/set.c | 26 +++++++++++++++++++++++++- 3 files changed, 35 insertions(+), 1 deletion(-) diff --git a/common/set.h b/common/set.h index 185dc8ed..d559902f 100644 --- a/common/set.h +++ b/common/set.h @@ -83,6 +83,15 @@ typedef struct int i_time_scale; int b_fixed_frame_rate; + int b_bitstream_restriction; + int b_motion_vectors_over_pic_boundaries; + int i_max_bytes_per_pic_denom; + int i_max_bits_per_mb_denom; + int i_log2_max_mv_length_horizontal; + int i_log2_max_mv_length_vertical; + int i_num_reorder_frames; + int i_max_dec_frame_buffering; + /* FIXME to complete */ } vui; } x264_sps_t; diff --git a/encoder/encoder.c b/encoder/encoder.c index a94127f9..a36ab4b7 100644 --- a/encoder/encoder.c +++ b/encoder/encoder.c @@ -396,6 +396,7 @@ x264_t *x264_encoder_open ( x264_param_t *param ) if( h->param.analyse.inter & X264_ANALYSE_PSUB8x8 ) h->param.analyse.inter |= X264_ANALYSE_PSUB16x16; h->param.analyse.i_chroma_qp_offset = x264_clip3(h->param.analyse.i_chroma_qp_offset, -12, 12); + h->param.analyse.i_mv_range = x264_clip3(h->param.analyse.i_mv_range, 32, 2048); if( h->param.rc.f_qblur < 0 ) h->param.rc.f_qblur = 0; diff --git a/encoder/set.c b/encoder/set.c index 47432853..a7292384 100644 --- a/encoder/set.c +++ b/encoder/set.c @@ -30,6 +30,7 @@ #include #include #include +#include #include "x264.h" #include "common/bs.h" @@ -132,6 +133,19 @@ void x264_sps_init( x264_sps_t *sps, int i_id, x264_param_t *param ) sps->vui.b_fixed_frame_rate = 1; } sps->b_vui |= sps->vui.b_timing_info_present; + + sps->vui.b_bitstream_restriction = param->i_bframe > 0; + if( sps->vui.b_bitstream_restriction ) + { + sps->vui.b_motion_vectors_over_pic_boundaries = 1; + sps->vui.i_max_bytes_per_pic_denom = 0; + sps->vui.i_max_bits_per_mb_denom = 0; + sps->vui.i_log2_max_mv_length_horizontal = + sps->vui.i_log2_max_mv_length_vertical = (int)(log(param->analyse.i_mv_range*4-1)/log(2)) + 1; + sps->vui.i_num_reorder_frames = param->b_bframe_pyramid ? 2 : param->i_bframe ? 1 : 0; + sps->vui.i_max_dec_frame_buffering = param->i_frame_reference + sps->vui.i_num_reorder_frames + 1; + } + sps->b_vui |= sps->vui.b_bitstream_restriction; } @@ -240,7 +254,17 @@ void x264_sps_write( bs_t *s, x264_sps_t *sps ) bs_write1( s, 0 ); /* nal_hrd_parameters_present_flag */ bs_write1( s, 0 ); /* vcl_hrd_parameters_present_flag */ bs_write1( s, 0 ); /* pic_struct_present_flag */ - bs_write1( s, 0 ); /* bitstream_restriction_flag */ + bs_write1( s, sps->vui.b_bitstream_restriction ); + if( sps->vui.b_bitstream_restriction ) + { + bs_write1( s, sps->vui.b_motion_vectors_over_pic_boundaries ); + bs_write_ue( s, sps->vui.i_max_bytes_per_pic_denom ); + bs_write_ue( s, sps->vui.i_max_bits_per_mb_denom ); + bs_write_ue( s, sps->vui.i_log2_max_mv_length_horizontal ); + bs_write_ue( s, sps->vui.i_log2_max_mv_length_vertical ); + bs_write_ue( s, sps->vui.i_num_reorder_frames ); + bs_write_ue( s, sps->vui.i_max_dec_frame_buffering ); + } } bs_rbsp_trailing( s ); -- 2.40.0