Esempio n. 1
0
        private void writeVUIParameters(VUIParameters vuip, BitWriter writer)
        {
            CAVLCWriter.writeBool(writer, vuip.aspect_ratio_info_present_flag, "VUI: aspect_ratio_info_present_flag");
            if (vuip.aspect_ratio_info_present_flag)
            {
                CAVLCWriter.writeNBit(writer, vuip.aspect_ratio.getValue(), 8, "VUI: aspect_ratio");
                if (vuip.aspect_ratio == AspectRatio.Extended_SAR)
                {
                    CAVLCWriter.writeNBit(writer, vuip.sar_width, 16, "VUI: sar_width");
                    CAVLCWriter.writeNBit(writer, vuip.sar_height, 16, "VUI: sar_height");
                }
            }
            CAVLCWriter.writeBool(writer, vuip.overscan_info_present_flag, "VUI: overscan_info_present_flag");
            if (vuip.overscan_info_present_flag)
            {
                CAVLCWriter.writeBool(writer, vuip.overscan_appropriate_flag, "VUI: overscan_appropriate_flag");
            }
            CAVLCWriter.writeBool(writer, vuip.video_signal_type_present_flag, "VUI: video_signal_type_present_flag");
            if (vuip.video_signal_type_present_flag)
            {
                CAVLCWriter.writeNBit(writer, vuip.video_format, 3, "VUI: video_format");
                CAVLCWriter.writeBool(writer, vuip.video_full_range_flag, "VUI: video_full_range_flag");
                CAVLCWriter.writeBool(writer, vuip.colour_description_present_flag, "VUI: colour_description_present_flag");
                if (vuip.colour_description_present_flag)
                {
                    CAVLCWriter.writeNBit(writer, vuip.colour_primaries, 8, "VUI: colour_primaries");
                    CAVLCWriter.writeNBit(writer, vuip.transfer_characteristics, 8, "VUI: transfer_characteristics");
                    CAVLCWriter.writeNBit(writer, vuip.matrix_coefficients, 8, "VUI: matrix_coefficients");
                }
            }
            CAVLCWriter.writeBool(writer, vuip.chroma_loc_info_present_flag, "VUI: chroma_loc_info_present_flag");
            if (vuip.chroma_loc_info_present_flag)
            {
                CAVLCWriter.writeUE(writer, vuip.chroma_sample_loc_type_top_field, "VUI: chroma_sample_loc_type_top_field");
                CAVLCWriter.writeUE(writer, vuip.chroma_sample_loc_type_bottom_field, "VUI: chroma_sample_loc_type_bottom_field");
            }
            CAVLCWriter.writeBool(writer, vuip.timing_info_present_flag, "VUI: timing_info_present_flag");
            if (vuip.timing_info_present_flag)
            {
                CAVLCWriter.writeNBit(writer, vuip.num_units_in_tick, 32, "VUI: num_units_in_tick");
                CAVLCWriter.writeNBit(writer, vuip.time_scale, 32, "VUI: time_scale");
                CAVLCWriter.writeBool(writer, vuip.fixed_frame_rate_flag, "VUI: fixed_frame_rate_flag");
            }
            CAVLCWriter.writeBool(writer, vuip.nalHRDParams != null, "VUI: ");
            if (vuip.nalHRDParams != null)
            {
                writeHRDParameters(vuip.nalHRDParams, writer);
            }
            CAVLCWriter.writeBool(writer, vuip.vclHRDParams != null, "VUI: ");
            if (vuip.vclHRDParams != null)
            {
                writeHRDParameters(vuip.vclHRDParams, writer);
            }

            if (vuip.nalHRDParams != null || vuip.vclHRDParams != null)
            {
                CAVLCWriter.writeBool(writer, vuip.low_delay_hrd_flag, "VUI: low_delay_hrd_flag");
            }
            CAVLCWriter.writeBool(writer, vuip.pic_struct_present_flag, "VUI: pic_struct_present_flag");
            CAVLCWriter.writeBool(writer, vuip.bitstreamRestriction != null, "VUI: ");
            if (vuip.bitstreamRestriction != null)
            {
                CAVLCWriter.writeBool(writer, vuip.bitstreamRestriction.motion_vectors_over_pic_boundaries_flag,
                                      "VUI: motion_vectors_over_pic_boundaries_flag");
                CAVLCWriter.writeUE(writer, vuip.bitstreamRestriction.max_bytes_per_pic_denom, "VUI: max_bytes_per_pic_denom");
                CAVLCWriter.writeUE(writer, vuip.bitstreamRestriction.max_bits_per_mb_denom, "VUI: max_bits_per_mb_denom");
                CAVLCWriter.writeUE(writer, vuip.bitstreamRestriction.log2_max_mv_length_horizontal,
                                    "VUI: log2_max_mv_length_horizontal");
                CAVLCWriter.writeUE(writer, vuip.bitstreamRestriction.log2_max_mv_length_vertical, "VUI: log2_max_mv_length_vertical");
                CAVLCWriter.writeUE(writer, vuip.bitstreamRestriction.num_reorder_frames, "VUI: num_reorder_frames");
                CAVLCWriter.writeUE(writer, vuip.bitstreamRestriction.max_dec_frame_buffering, "VUI: max_dec_frame_buffering");
            }
        }
Esempio n. 2
0
        private static VUIParameters readVUIParameters(BitReader inb)
        {
            VUIParameters vuip = new VUIParameters();

            vuip.aspect_ratio_info_present_flag = CAVLCReader.readBool(inb, "VUI: aspect_ratio_info_present_flag");
            if (vuip.aspect_ratio_info_present_flag)
            {
                vuip.aspect_ratio = AspectRatio.fromValue((int)CAVLCReader.readNBit(inb, 8, "VUI: aspect_ratio"));
                if (vuip.aspect_ratio == AspectRatio.Extended_SAR)
                {
                    vuip.sar_width  = (int)CAVLCReader.readNBit(inb, 16, "VUI: sar_width");
                    vuip.sar_height = (int)CAVLCReader.readNBit(inb, 16, "VUI: sar_height");
                }
            }
            vuip.overscan_info_present_flag = CAVLCReader.readBool(inb, "VUI: overscan_info_present_flag");
            if (vuip.overscan_info_present_flag)
            {
                vuip.overscan_appropriate_flag = CAVLCReader.readBool(inb, "VUI: overscan_appropriate_flag");
            }
            vuip.video_signal_type_present_flag = CAVLCReader.readBool(inb, "VUI: video_signal_type_present_flag");
            if (vuip.video_signal_type_present_flag)
            {
                vuip.video_format                    = (int)CAVLCReader.readNBit(inb, 3, "VUI: video_format");
                vuip.video_full_range_flag           = CAVLCReader.readBool(inb, "VUI: video_full_range_flag");
                vuip.colour_description_present_flag = CAVLCReader.readBool(inb, "VUI: colour_description_present_flag");
                if (vuip.colour_description_present_flag)
                {
                    vuip.colour_primaries         = (int)CAVLCReader.readNBit(inb, 8, "VUI: colour_primaries");
                    vuip.transfer_characteristics = (int)CAVLCReader.readNBit(inb, 8, "VUI: transfer_characteristics");
                    vuip.matrix_coefficients      = (int)CAVLCReader.readNBit(inb, 8, "VUI: matrix_coefficients");
                }
            }
            vuip.chroma_loc_info_present_flag = CAVLCReader.readBool(inb, "VUI: chroma_loc_info_present_flag");
            if (vuip.chroma_loc_info_present_flag)
            {
                vuip.chroma_sample_loc_type_top_field    = CAVLCReader.readUE(inb, "VUI chroma_sample_loc_type_top_field");
                vuip.chroma_sample_loc_type_bottom_field = CAVLCReader.readUE(inb, "VUI chroma_sample_loc_type_bottom_field");
            }
            vuip.timing_info_present_flag = CAVLCReader.readBool(inb, "VUI: timing_info_present_flag");
            if (vuip.timing_info_present_flag)
            {
                vuip.num_units_in_tick     = (int)CAVLCReader.readNBit(inb, 32, "VUI: num_units_in_tick");
                vuip.time_scale            = (int)CAVLCReader.readNBit(inb, 32, "VUI: time_scale");
                vuip.fixed_frame_rate_flag = CAVLCReader.readBool(inb, "VUI: fixed_frame_rate_flag");
            }
            bool nal_hrd_parameters_present_flag = CAVLCReader.readBool(inb, "VUI: nal_hrd_parameters_present_flag");

            if (nal_hrd_parameters_present_flag)
            {
                vuip.nalHRDParams = readHRDParameters(inb);
            }
            bool vcl_hrd_parameters_present_flag = CAVLCReader.readBool(inb, "VUI: vcl_hrd_parameters_present_flag");

            if (vcl_hrd_parameters_present_flag)
            {
                vuip.vclHRDParams = readHRDParameters(inb);
            }
            if (nal_hrd_parameters_present_flag || vcl_hrd_parameters_present_flag)
            {
                vuip.low_delay_hrd_flag = CAVLCReader.readBool(inb, "VUI: low_delay_hrd_flag");
            }
            vuip.pic_struct_present_flag = CAVLCReader.readBool(inb, "VUI: pic_struct_present_flag");
            bool bitstream_restriction_flag = CAVLCReader.readBool(inb, "VUI: bitstream_restriction_flag");

            if (bitstream_restriction_flag)
            {
                vuip.bitstreamRestriction = new VUIParameters.BitstreamRestriction();
                vuip.bitstreamRestriction.motion_vectors_over_pic_boundaries_flag = CAVLCReader.readBool(inb,
                                                                                                         "VUI: motion_vectors_over_pic_boundaries_flag");
                vuip.bitstreamRestriction.max_bytes_per_pic_denom       = CAVLCReader.readUE(inb, "VUI max_bytes_per_pic_denom");
                vuip.bitstreamRestriction.max_bits_per_mb_denom         = CAVLCReader.readUE(inb, "VUI max_bits_per_mb_denom");
                vuip.bitstreamRestriction.log2_max_mv_length_horizontal = CAVLCReader.readUE(inb, "VUI log2_max_mv_length_horizontal");
                vuip.bitstreamRestriction.log2_max_mv_length_vertical   = CAVLCReader.readUE(inb, "VUI log2_max_mv_length_vertical");
                vuip.bitstreamRestriction.num_reorder_frames            = CAVLCReader.readUE(inb, "VUI num_reorder_frames");
                vuip.bitstreamRestriction.max_dec_frame_buffering       = CAVLCReader.readUE(inb, "VUI max_dec_frame_buffering");
            }

            return(vuip);
        }