]> granicus.if.org Git - libx264/commitdiff
write VUI bitstream restrictions
authorLoren Merritt <pengvado@videolan.org>
Fri, 11 Mar 2005 02:15:25 +0000 (02:15 +0000)
committerLoren Merritt <pengvado@videolan.org>
Fri, 11 Mar 2005 02:15:25 +0000 (02:15 +0000)
git-svn-id: svn://svn.videolan.org/x264/trunk@162 df754926-b1dd-0310-bc7b-ec298dee348c

common/set.h
encoder/encoder.c
encoder/set.c

index 185dc8ed08f90c87ccf8d0d6109d9f7839a53989..d559902f43bc8f49cfaad937a02be4f8a3b32cdf 100644 (file)
@@ -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;
index a94127f90973489c73f69b2d5d65b55fceaf8916..a36ab4b7c9ca26974dc6157617832b4b0d090099 100644 (file)
@@ -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;
index 4743285319ea9c07368812f5207c30ef13a0d431..a729238459b1b080bd7805f0f339b43f367ecb27 100644 (file)
@@ -30,6 +30,7 @@
 #include <stdio.h>
 #include <string.h>
 #include <stdarg.h>
+#include <math.h>
 
 #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 );