Esempio n. 1
0
 private void ReadUserDataUnregistered(H264Bitstream r, uint length)
 {
     byte[] b = new byte[16];
     for (int index = 0; index < b.Length; ++index)
     {
         b[index] = (byte)r.ReadBits(8);
     }
     Guid guid = new Guid(b);
 }
 internal void ParseAud(IList <byte> buffer)
 {
     using (H264Bitstream h264Bitstream = new H264Bitstream((IEnumerable <byte>)buffer))
     {
         h264Bitstream.ReadBits(1);
         h264Bitstream.ReadBits(2);
         h264Bitstream.ReadBits(5);
         h264Bitstream.ReadBits(3);
     }
 }
 internal void ParseSei(ICollection <byte> buffer)
 {
     using (H264Bitstream r = new H264Bitstream((IEnumerable <byte>)buffer))
     {
         r.ReadBits(1);
         r.ReadBits(2);
         r.ReadBits(5);
         this._h264Reader.ReadSei(r, buffer);
     }
     this.CheckConfigure();
 }
 public void ParsePpsBytes(ICollection <byte> value)
 {
     if (EnumerableExtensions.SequencesAreEquivalent <byte>((IEnumerable <byte>)value, this._ppsBytes))
     {
         return;
     }
     this._ppsBytes = (IEnumerable <byte>)Enumerable.ToArray <byte>((IEnumerable <byte>)value);
     using (H264Bitstream r = new H264Bitstream(this._ppsBytes))
         this._h264Reader.ReadPps(r);
     this.CheckConfigure();
 }
 internal void ParseSliceHeader(IList <byte> buffer)
 {
     using (H264Bitstream r = new H264Bitstream((IEnumerable <byte>)buffer))
     {
         r.ReadBits(1);
         r.ReadBits(2);
         uint num = r.ReadBits(5);
         this._h264Reader.ReadSliceHeader(r, 5 == (int)num);
     }
     this._h264Reader.TryReparseTimingSei(this);
     this.CheckConfigure();
 }
Esempio n. 6
0
        private void ParseScalingList(H264Bitstream r, int sizeOfScalingList)
        {
            int num1 = 8;
            int num2 = 8;

            for (int index = 0; index < sizeOfScalingList; ++index)
            {
                if (0 != num2)
                {
                    int num3 = H264BitstreamExtensions.ReadSe(r);
                    num2 = num1 + num3 + 256 & (int)byte.MaxValue;
                    bool flag = index == 0 && 0 == num2;
                }
                num1 = num2 == 0 ? num1 : num2;
            }
        }
Esempio n. 7
0
        private void ReadScalingList(H264Bitstream r, int sizeOfScalingList)
        {
            int num1 = 8;
            int num2 = 8;

            for (int index = 0; index < sizeOfScalingList; ++index)
            {
                if (num2 != 0)
                {
                    int num3 = H264BitstreamExtensions.ReadSe(r);
                    num2 = (num1 + num3 + 256) % 256;
                    bool flag = index == 0 && num2 == 0;
                }
                num1 = num2 == 0 ? num1 : num2;
            }
        }
Esempio n. 8
0
        private void ReadHrdParameters(H264Bitstream r)
        {
            uint num = H264BitstreamExtensions.ReadUe(r);

            r.ReadBits(4);
            r.ReadBits(4);
            for (int index = 0; (long)index <= (long)num; ++index)
            {
                H264BitstreamExtensions.ReadUe(r);
                H264BitstreamExtensions.ReadUe(r);
                r.ReadBits(1);
            }
            r.ReadBits(5);
            this._cpbRemovalDelayLengthMinus1 = new uint?(r.ReadBits(5));
            this._dpbOutputDelayLengthMinus1  = new uint?(r.ReadBits(5));
            this._timeOffsetLength            = new uint?(r.ReadBits(5));
        }
Esempio n. 9
0
        public void ReadSei(H264Bitstream r, ICollection <byte> buffer)
        {
            uint num    = H264BitstreamExtensions.ReadFfSum(r);
            uint length = H264BitstreamExtensions.ReadFfSum(r);

            if ((int)num != 1)
            {
                return;
            }
            if (this._slicePicParameterSetId.HasValue)
            {
                this.ReadPicTiming(r, length);
            }
            else
            {
                if (EnumerableExtensions.SequencesAreEquivalent <byte>((IEnumerable <byte>)buffer, (IEnumerable <byte>) this._timingBytes))
                {
                    return;
                }
                this._timingBytes = (ICollection <byte>)Enumerable.ToArray <byte>((IEnumerable <byte>)buffer);
            }
        }
Esempio n. 10
0
 void ReadScalingList(H264Bitstream r, int sizeOfScalingList)
 {
     var lastScale = 8;
     var nextScale = 8;
     for (var j = 0; j < sizeOfScalingList; j++)
     {
         if (nextScale != 0)
         {
             var delta_scale = r.ReadSe();
             nextScale = (lastScale + delta_scale + 256) % 256;
             var useDefaultScalingMatrixFlag = (j == 0 && nextScale == 0);
         }
         var scalingList_j = (nextScale == 0) ? lastScale : nextScale;
         lastScale = scalingList_j;
     }
 }
Esempio n. 11
0
        void ReadHrdParameters(H264Bitstream r)
        {
            var cpb_cnt_minus1 = r.ReadUe();
            var bit_rate_scale = r.ReadBits(4);
            var cpb_size_scale = r.ReadBits(4);
            for (var SchedSelIdx = 0; SchedSelIdx <= cpb_cnt_minus1; SchedSelIdx++)
            {
                var bit_rate_value_minus1_SchedSelIdx = r.ReadUe();
                var cpb_size_value_minus1_SchedSelIdx = r.ReadUe();
                var cbr_flag_SchedSelIdx = r.ReadBits(1);
            }
            var initial_cpb_removal_delay_length_minus1 = r.ReadBits(5);
            var cpb_removal_delay_length_minus1 = r.ReadBits(5);

            _cpbRemovalDelayLengthMinus1 = cpb_removal_delay_length_minus1;

            var dpb_output_delay_length_minus1 = r.ReadBits(5);

            _dpbOutputDelayLengthMinus1 = dpb_output_delay_length_minus1;

            var time_offset_length = r.ReadBits(5);

            _timeOffsetLength = time_offset_length;
        }
Esempio n. 12
0
        // ReSharper disable InconsistentNaming
        // ReSharper disable UnusedVariable

        void ReadVuiParameters(H264Bitstream r)
        {
            var aspect_ratio_info_present_flag = r.ReadBits(1);

            if (0 != aspect_ratio_info_present_flag)
            {
                var aspect_ratio_idc = r.ReadBits(8);

                const int Extended_SAR = 255;

                if (Extended_SAR == aspect_ratio_idc)
                {
                    var sar_width = r.ReadBits(16);
                    var sar_height = r.ReadBits(16);
                }
            }

            var overscan_info_present_flag = r.ReadBits(1);

            if (0 != overscan_info_present_flag)
            {
                var overscan_appropriate_flag = r.ReadBits(1);
            }

            var video_signal_type_present_flag = r.ReadBits(1);
            if (0 != video_signal_type_present_flag)
            {
                var video_format = r.ReadBits(3);
                var video_full_range_flag = r.ReadBits(1);
                var colour_description_present_flag = r.ReadBits(1);
                if (0 != colour_description_present_flag)
                {
                    var colour_primaries = r.ReadBits(8);
                    var transfer_characteristics = r.ReadBits(8);
                    var matrix_coefficients = r.ReadBits(8);
                }
            }

            var chroma_loc_info_present_flag = r.ReadBits(1);
            if (0 != chroma_loc_info_present_flag)
            {
                var chroma_sample_loc_type_top_field = r.ReadUe();
                var chroma_sample_loc_type_bottom_field = r.ReadUe();
            }

            var timing_info_present_flag = r.ReadBits(1);
            if (0 != timing_info_present_flag)
            {
                var num_units_in_tick = r.ReadBits(32);
                _numUnitsInTick = num_units_in_tick;

                var time_scale = r.ReadBits(32);
                _timeScale = time_scale;

                var fixed_frame_rate_flag = r.ReadBits(1);
                _fixedFrameRateFlag = 0 != fixed_frame_rate_flag;
            }

            var nal_hrd_parameters_present_flag = r.ReadBits(1);

            _nalHrdParametersPresentFlag = 0 != nal_hrd_parameters_present_flag;

            if (0 != nal_hrd_parameters_present_flag)
                ReadHrdParameters(r);

            var vcl_hrd_parameters_present_flag = r.ReadBits(1);

            _vclHrdParametersPresentFlag = 0 != vcl_hrd_parameters_present_flag;

            if (0 != vcl_hrd_parameters_present_flag)
                ReadHrdParameters(r);

            if (0 != nal_hrd_parameters_present_flag || 0 != vcl_hrd_parameters_present_flag)
            {
                var low_delay_hrd_flag = r.ReadBits(1);
            }

            var pic_struct_present_flag = r.ReadBits(1);

            _picStructPresentFlag = 0 != pic_struct_present_flag;

            var bitstream_restriction_flag = r.ReadBits(1);
            if (0 != bitstream_restriction_flag)
            {
                var motion_vectors_over_pic_boundaries_flag = r.ReadBits(1);
                var max_bytes_per_pic_denom = r.ReadUe();
                var max_bits_per_mb_denom = r.ReadUe();
                var log2_max_mv_length_horizontal = r.ReadUe();
                var log2_max_mv_length_vertical = r.ReadUe();
                var max_num_reorder_frames = r.ReadUe();
                var max_dec_frame_buffering = r.ReadUe();
            }
        }
Esempio n. 13
0
        public void ReadPps(H264Bitstream r)
        {
            _slicePicParameterSetId = null;

            var forbidden_zero_bit = r.ReadBits(1);
            var nal_ref_idc = r.ReadBits(2);
            var nal_unit_type = r.ReadBits(5);

            var pic_parameter_set_id = r.ReadUe();

            _picParameterSetId = pic_parameter_set_id;

            var seq_parameter_set_id = r.ReadUe();

            _ppsSeqParameterSetId = seq_parameter_set_id;

            var entropy_coding_mode_flag = r.ReadBits(1);
            var bottom_field_pic_order_in_frame_present_flag = r.ReadBits(1);

            _bottomFieldPicOrderInFramePresentFlag = bottom_field_pic_order_in_frame_present_flag;

            var num_slice_groups_minus1 = r.ReadUe();

            if (num_slice_groups_minus1 > 0)
            {
                var slice_group_map_type = r.ReadUe();
                if (0 == slice_group_map_type)
                {
                    for (var iGroup = 0; iGroup <= num_slice_groups_minus1; iGroup++)
                    {
                        var run_length_minus1_iGroup = r.ReadUe();
                    }
                }
                else if (2 == slice_group_map_type)
                {
                    for (var iGroup = 0; iGroup < num_slice_groups_minus1; iGroup++)
                    {
                        var top_left_iGroup = r.ReadUe();
                        var bottom_right_iGroup = r.ReadUe();
                    }
                }
                else if (3 == slice_group_map_type || 4 == slice_group_map_type || 5 == slice_group_map_type)
                {
                    var slice_group_change_direction_flag = r.ReadBits(1);
                    var slice_group_change_rate_minus1 = r.ReadUe();
                }
                else if (6 == slice_group_map_type)
                {
                    var nsgBits = GetBitSize(num_slice_groups_minus1);

                    var pic_size_in_map_units_minus1 = r.ReadUe();
                    for (var i = 0; i <= pic_size_in_map_units_minus1; i++)
                    {
                        var slice_group_id_i = r.ReadBits(nsgBits);
                    }
                }
            }

            var num_ref_idx_l0_default_active_minus1 = r.ReadUe();
            var num_ref_idx_l1_default_active_minus1 = r.ReadUe();
            var weighted_pred_flag = r.ReadBits(1);
            var weighted_bipred_idc = r.ReadBits(2);
            var pic_init_qp_minus26 /* relative to 26 */ = r.ReadSe();
            var pic_init_qs_minus26 /* relative to 26 */ = r.ReadSe();
            var chroma_qp_index_offset = r.ReadSe();
            var deblocking_filter_control_present_flag = r.ReadBits(1);
            var constrained_intra_pred_flag = r.ReadBits(1);
            var redundant_pic_cnt_present_flag = r.ReadBits(1);

            _redundantPicCntPresentFlag = redundant_pic_cnt_present_flag;

            if (more_rbsp_data(r))
            {
                var transform_8x8_mode_flag = r.ReadBits(1);
                var pic_scaling_matrix_present_flag = r.ReadBits(1);
                if (0 != pic_scaling_matrix_present_flag)
                {
                    for (var i = 0; i < 6 + ((_chromaFormatIdc != 3) ? 2 : 6) * transform_8x8_mode_flag; i++)
                    {
                        var pic_scaling_list_present_flag_i = r.ReadBits(1);
                        if (0 != pic_scaling_list_present_flag_i)
                        {
                            if (i < 6)
                            {
                                ReadScalingList(r, 16);
                                //scaling_list(ScalingList4x4[i], 16, UseDefaultScalingMatrix4x4Flag[i]);
                            }
                            else
                            {
                                ReadScalingList(r, 64);
                                //scaling_list(ScalingList8x8[i - 6], 64, UseDefaultScalingMatrix8x8Flag[i - 6]);
                            }
                        }
                    }
                }

                var second_chroma_qp_index_offset = r.ReadSe();
            }
        }
Esempio n. 14
0
        public void ReadSps(H264Bitstream r)
        {
            _ppsSeqParameterSetId = null;

            uint profile_idc;
            uint constraint_sets;
            uint level_idc;
            uint width;
            uint height;

            var forbidden_zero_bit = r.ReadBits(1);
            var nal_ref_idc = r.ReadBits(2);
            var nal_unit_type = r.ReadBits(5);

            profile_idc = r.ReadBits(8);
            constraint_sets = r.ReadBits(8);
            level_idc = r.ReadBits(8);
            var seq_parameter_set_id = r.ReadUe();

            _seqParameterSetId = seq_parameter_set_id;

            if (Array.BinarySearch(ProfileIdcHasChromaFormat, profile_idc) >= 0)
            {
                var chroma_format_idc = r.ReadUe();

                _chromaFormatIdc = chroma_format_idc;

                if (3 == chroma_format_idc)
                {
                    var separate_colour_plane_flag = r.ReadBits(1);

                    _separateColourPlaneFlag = separate_colour_plane_flag;
                }

                var bit_depth_luma_minus8 = r.ReadUe();

                var bit_depth_chroma_minus8 = r.ReadUe();

                var qpprime_y_zero_transform_bypass_flag = r.ReadBits(1);

                var seq_scaling_matrix_present_flag = r.ReadBits(1);

                if (0 != seq_scaling_matrix_present_flag)
                {
                    for (var i = 0; i < (3 != chroma_format_idc ? 8 : 12); ++i)
                    {
                        var seq_scaling_list_present_flag = r.ReadBits(1);

                        if (0 != seq_scaling_list_present_flag)
                            ParseScalingList(r, i < 6 ? 16 : 64);
                    }
                }
            }

            var log2_max_frame_num_minus4 = r.ReadUe();

            _log2MaxFrameNumMinus4 = log2_max_frame_num_minus4;

            var pic_order_cnt_type = r.ReadUe();

            _picOrderCntType = pic_order_cnt_type;

            if (0 == pic_order_cnt_type)
            {
                var log2_max_pic_order_cnt_lsb_minus4 = r.ReadUe();
            }
            else if (1 == pic_order_cnt_type)
            {
                var delta_pic_order_always_zero_flag = r.ReadBits(1);

                _deltaPicOrderAlwaysZeroFlag = delta_pic_order_always_zero_flag;

                var offset_for_non_ref_pic = r.ReadSe();
                var offset_for_top_to_bottom_field = r.ReadSe();
                var num_ref_frames_in_pic_order_cnt_cycle = r.ReadUe();

                for (var i = 0; i < num_ref_frames_in_pic_order_cnt_cycle; ++i)
                {
                    var offset_for_ref_frame = r.ReadSe();
                }
            }

            var max_num_ref_frames = r.ReadUe();
            var gaps_in_frame_num_value_allowed_flag = r.ReadBits(1);
            var pic_width_in_mbs_minus1 = r.ReadUe();
            var pic_height_in_map_units_minus1 = r.ReadUe();
            var frame_mbs_only_flag = r.ReadBits(1);

            _frameMbsOnlyFlag = frame_mbs_only_flag;

            if (0 == frame_mbs_only_flag)
            {
                var mb_adaptive_frame_field_flag = r.ReadBits(1);
            }

            var direct_8x8_inference_flag = r.ReadBits(1);
            var frame_cropping_flag = r.ReadBits(1);

            width = ((pic_width_in_mbs_minus1 + 1) * 16);
            height = ((2 - frame_mbs_only_flag) * (pic_height_in_map_units_minus1 + 1) * 16);

            if (0 != frame_cropping_flag)
            {
                var frame_crop_left_offset = r.ReadUe();
                var frame_crop_right_offset = r.ReadUe();
                var frame_crop_top_offset = r.ReadUe();
                var frame_crop_bottom_offset = r.ReadUe();

                width = width - frame_crop_left_offset * 2 - frame_crop_right_offset * 2;
                height = height - (frame_crop_top_offset * 2) - (frame_crop_bottom_offset * 2);
            }

            var vui_parameters_present_flag = r.ReadBits(1);

            if (0 != vui_parameters_present_flag)
            {
                ReadVuiParameters(r);
            }

            Height = (int)height;
            Width = (int)width;

            var profileName = ProfileName(profile_idc, constraint_sets);

            Name = String.Format("H.264 \"{0}\" profile, level {1} {2}x{3}",
                profileName, level_idc / 10.0, width, height);
        }
Esempio n. 15
0
        public void ReadSei(H264Bitstream r, ICollection<byte> buffer)
        {
            var payloadType = r.ReadFfSum();
            var payloadLength = r.ReadFfSum();

            // Rec. ITU-T H.264 (04/2013) Section D.1
            switch (payloadType)
            {
                case 1: // pic_timing
                    if (_slicePicParameterSetId.HasValue)
                        ReadPicTiming(r, payloadLength);
                    else if (!buffer.SequencesAreEquivalent(_timingBytes))
                        _timingBytes = buffer.ToArray();

                    break;
#if false
                case 5: // user_data_unregistered
                    ReadUserDataUnregistered(r, payloadLength);
                    break;
#endif
            }
        }
Esempio n. 16
0
        private void ReadVuiParameters(H264Bitstream r)
        {
            if (0 != (int)r.ReadBits(1) && (int)byte.MaxValue == (int)r.ReadBits(8))
            {
                r.ReadBits(16);
                r.ReadBits(16);
            }
            if (0 != (int)r.ReadBits(1))
            {
                r.ReadBits(1);
            }
            if (0 != (int)r.ReadBits(1))
            {
                r.ReadBits(3);
                r.ReadBits(1);
                if (0 != (int)r.ReadBits(1))
                {
                    r.ReadBits(8);
                    r.ReadBits(8);
                    r.ReadBits(8);
                }
            }
            if (0 != (int)r.ReadBits(1))
            {
                H264BitstreamExtensions.ReadUe(r);
                H264BitstreamExtensions.ReadUe(r);
            }
            if (0 != (int)r.ReadBits(1))
            {
                this._numUnitsInTick     = new uint?(r.ReadBits(32));
                this._timeScale          = new uint?(r.ReadBits(32));
                this._fixedFrameRateFlag = new bool?(0 != (int)r.ReadBits(1));
            }
            uint num1 = r.ReadBits(1);

            this._nalHrdParametersPresentFlag = new bool?(0 != (int)num1);
            if (0 != (int)num1)
            {
                this.ReadHrdParameters(r);
            }
            uint num2 = r.ReadBits(1);

            this._vclHrdParametersPresentFlag = new bool?(0 != (int)num2);
            if (0 != (int)num2)
            {
                this.ReadHrdParameters(r);
            }
            if ((int)num1 != 0 || 0 != (int)num2)
            {
                r.ReadBits(1);
            }
            this._picStructPresentFlag = new bool?(0 != (int)r.ReadBits(1));
            if (0 == (int)r.ReadBits(1))
            {
                return;
            }
            r.ReadBits(1);
            H264BitstreamExtensions.ReadUe(r);
            H264BitstreamExtensions.ReadUe(r);
            H264BitstreamExtensions.ReadUe(r);
            H264BitstreamExtensions.ReadUe(r);
            H264BitstreamExtensions.ReadUe(r);
            H264BitstreamExtensions.ReadUe(r);
        }
Esempio n. 17
0
        public void ReadSliceHeader(H264Bitstream r, bool IdrPicFlag)
        {
            H264BitstreamExtensions.ReadUe(r);
            H264BitstreamExtensions.ReadUe(r);
            this._slicePicParameterSetId = new uint?(H264BitstreamExtensions.ReadUe(r));
            uint?nullable = this._separateColourPlaneFlag;

            if (((int)nullable.GetValueOrDefault() != 1 ? 0 : (nullable.HasValue ? 1 : 0)) != 0)
            {
                r.ReadBits(2);
            }
            H264Bitstream h264Bitstream1 = r;

            nullable = this._log2MaxFrameNumMinus4;
            int count1 = (nullable.HasValue ? (int)nullable.GetValueOrDefault() : 0) + 4;

            h264Bitstream1.ReadBits(count1);
            uint num1 = 0;

            nullable = this._frameMbsOnlyFlag;
            if (((int)nullable.GetValueOrDefault() != 0 ? 0 : (nullable.HasValue ? 1 : 0)) != 0)
            {
                num1 = r.ReadBits(1);
                if (0 != (int)num1)
                {
                    r.ReadBits(1);
                }
            }
            this._fieldPicFlag = new bool?(0 != (int)num1);
            if (!IdrPicFlag)
            {
                return;
            }
            H264BitstreamExtensions.ReadUe(r);
            nullable = this._picOrderCntType;
            if (((int)nullable.GetValueOrDefault() != 0 ? 0 : (nullable.HasValue ? 1 : 0)) != 0)
            {
                H264Bitstream h264Bitstream2 = r;
                nullable = this._log2MaxFrameNumMinus4;
                int count2 = (nullable.HasValue ? (int)nullable.GetValueOrDefault() : 0) + 4;
                h264Bitstream2.ReadBits(count2);
                nullable = this._bottomFieldPicOrderInFramePresentFlag;
                if (((int)nullable.GetValueOrDefault() != 0 ? 1 : (!nullable.HasValue ? 1 : 0)) != 0 && 0 == (int)num1)
                {
                    H264BitstreamExtensions.ReadSe(r);
                }
            }
            nullable = this._picOrderCntType;
            int num2;

            if (((int)nullable.GetValueOrDefault() != 1 ? 0 : (nullable.HasValue ? 1 : 0)) != 0)
            {
                nullable = this._deltaPicOrderAlwaysZeroFlag;
                num2     = ((int)nullable.GetValueOrDefault() != 0 ? 0 : (nullable.HasValue ? 1 : 0)) == 0 ? 1 : 0;
            }
            else
            {
                num2 = 1;
            }
            if (num2 == 0)
            {
                H264BitstreamExtensions.ReadSe(r);
                nullable = this._bottomFieldPicOrderInFramePresentFlag;
                if (((int)nullable.GetValueOrDefault() != 0 ? 1 : (!nullable.HasValue ? 1 : 0)) != 0 && 0 == (int)num1)
                {
                    H264BitstreamExtensions.ReadSe(r);
                }
            }
            nullable = this._redundantPicCntPresentFlag;
            if (((int)nullable.GetValueOrDefault() != 0 ? 1 : (!nullable.HasValue ? 1 : 0)) != 0)
            {
                H264BitstreamExtensions.ReadUe(r);
            }
        }
Esempio n. 18
0
        void ParseScalingList(H264Bitstream r, int sizeOfScalingList)
        {
            var lastScale = 8;
            var nextScale = 8;

            for (var j = 0; j < sizeOfScalingList; ++j)
            {
                if (0 != nextScale)
                {
                    var delta_scale = r.ReadSe();

                    nextScale = (lastScale + delta_scale + 256) & 0xff;
                    var useDefaultScalingMatrixFlag = (0 == j && 0 == nextScale);
                }

                var scalingList = 0 == nextScale ? lastScale : nextScale;
                lastScale = scalingList;
            }
        }
Esempio n. 19
0
        private void ReadPicTiming(H264Bitstream r, uint length)
        {
            if (this._nalHrdParametersPresentFlag.HasValue && this._nalHrdParametersPresentFlag.Value || this._vclHrdParametersPresentFlag.HasValue && this._vclHrdParametersPresentFlag.Value)
            {
                if (!this._cpbRemovalDelayLengthMinus1.HasValue)
                {
                    return;
                }
                r.ReadBits((int)this._cpbRemovalDelayLengthMinus1.Value + 1);
                if (!this._dpbOutputDelayLengthMinus1.HasValue)
                {
                    return;
                }
                r.ReadBits((int)this._dpbOutputDelayLengthMinus1.Value + 1);
            }
            if (!this._picStructPresentFlag.HasValue || !this._picStructPresentFlag.Value)
            {
                return;
            }
            this._picStruct = new uint?(r.ReadBits(4));
            int?numClockTs = this.GetNumClockTs();

            if (!numClockTs.HasValue)
            {
                return;
            }
            int num1 = numClockTs.Value;

            for (int index = 0; index < num1; ++index)
            {
                if (0 != (int)r.ReadBits(1))
                {
                    r.ReadBits(2);
                    r.ReadBits(1);
                    r.ReadBits(5);
                    uint num2 = r.ReadBits(1);
                    r.ReadBits(1);
                    r.ReadBits(1);
                    r.ReadBits(8);
                    uint num3;
                    uint num4;
                    uint num5;
                    if (0 != (int)num2)
                    {
                        num3 = r.ReadBits(6);
                        num4 = r.ReadBits(6);
                        num5 = r.ReadBits(5);
                    }
                    else if (0 != (int)r.ReadBits(1))
                    {
                        num3 = r.ReadBits(6);
                        if (0 != (int)r.ReadBits(1))
                        {
                            num4 = r.ReadBits(6);
                            if (0 != (int)r.ReadBits(1))
                            {
                                num5 = r.ReadBits(5);
                            }
                        }
                    }
                    uint?nullable = this._timeOffsetLength;
                    uint num6     = nullable.HasValue ? nullable.GetValueOrDefault() : 24U;
                    if (num6 > 0U)
                    {
                        H264BitstreamExtensions.ReadSignedBits(r, (int)num6);
                    }
                }
            }
        }
Esempio n. 20
0
        public void ReadSps(H264Bitstream r)
        {
            this._ppsSeqParameterSetId = new uint?();
            r.ReadBits(1);
            r.ReadBits(2);
            r.ReadBits(5);
            uint profile_idc     = r.ReadBits(8);
            uint constraint_sets = r.ReadBits(8);
            uint num1            = r.ReadBits(8);

            this._seqParameterSetId = new uint?(H264BitstreamExtensions.ReadUe(r));
            if (Array.BinarySearch <uint>(H264Reader.ProfileIdcHasChromaFormat, profile_idc) >= 0)
            {
                uint num2 = H264BitstreamExtensions.ReadUe(r);
                this._chromaFormatIdc = new uint?(num2);
                if (3 == (int)num2)
                {
                    this._separateColourPlaneFlag = new uint?(r.ReadBits(1));
                }
                H264BitstreamExtensions.ReadUe(r);
                H264BitstreamExtensions.ReadUe(r);
                r.ReadBits(1);
                if (0 != (int)r.ReadBits(1))
                {
                    for (int index = 0; index < (3 != (int)num2 ? 8 : 12); ++index)
                    {
                        if (0 != (int)r.ReadBits(1))
                        {
                            this.ParseScalingList(r, index < 6 ? 16 : 64);
                        }
                    }
                }
            }
            this._log2MaxFrameNumMinus4 = new uint?(H264BitstreamExtensions.ReadUe(r));
            uint num3 = H264BitstreamExtensions.ReadUe(r);

            this._picOrderCntType = new uint?(num3);
            if (0 == (int)num3)
            {
                H264BitstreamExtensions.ReadUe(r);
            }
            else if (1 == (int)num3)
            {
                this._deltaPicOrderAlwaysZeroFlag = new uint?(r.ReadBits(1));
                H264BitstreamExtensions.ReadSe(r);
                H264BitstreamExtensions.ReadSe(r);
                uint num2 = H264BitstreamExtensions.ReadUe(r);
                for (int index = 0; (long)index < (long)num2; ++index)
                {
                    H264BitstreamExtensions.ReadSe(r);
                }
            }
            H264BitstreamExtensions.ReadUe(r);
            r.ReadBits(1);
            uint num4 = H264BitstreamExtensions.ReadUe(r);
            uint num5 = H264BitstreamExtensions.ReadUe(r);
            uint num6 = r.ReadBits(1);

            this._frameMbsOnlyFlag = new uint?(num6);
            if (0 == (int)num6)
            {
                r.ReadBits(1);
            }
            r.ReadBits(1);
            uint num7 = r.ReadBits(1);
            uint num8 = (uint)(((int)num4 + 1) * 16);
            uint num9 = (uint)((2 - (int)num6) * ((int)num5 + 1) * 16);

            if (0 != (int)num7)
            {
                uint num2  = H264BitstreamExtensions.ReadUe(r);
                uint num10 = H264BitstreamExtensions.ReadUe(r);
                uint num11 = H264BitstreamExtensions.ReadUe(r);
                uint num12 = H264BitstreamExtensions.ReadUe(r);
                num8 = (uint)((int)num8 - (int)num2 * 2 - (int)num10 * 2);
                num9 = (uint)((int)num9 - (int)num11 * 2 - (int)num12 * 2);
            }
            if (0 != (int)r.ReadBits(1))
            {
                this.ReadVuiParameters(r);
            }
            this.Height = new int?((int)num9);
            this.Width  = new int?((int)num8);
            this.Name   = string.Format("H.264 \"{0}\" profile, level {1} {2}x{3}", (object)H264Reader.ProfileName(profile_idc, constraint_sets), (object)((double)num1 / 10.0), (object)num8, (object)num9);
        }
Esempio n. 21
0
        void ReadUserDataUnregistered(H264Bitstream r, uint length)
        {
            var buffer = new byte[16];

            for (var i = 0; i < buffer.Length; ++i)
                buffer[i] = (byte)r.ReadBits(8);

            var uuid = new Guid(buffer); // Byte order...?
        }
Esempio n. 22
0
        public void ReadSliceHeader(H264Bitstream r, bool IdrPicFlag)
        {
            var first_mb_in_slice = r.ReadUe();
            var slice_type = r.ReadUe();
            var pic_parameter_set_id = r.ReadUe();

            _slicePicParameterSetId = pic_parameter_set_id;

            if (_separateColourPlaneFlag == 1)
            {
                var colour_plane_id = r.ReadBits(2);
            }

            var frame_num = r.ReadBits((int)(_log2MaxFrameNumMinus4 ?? 0) + 4);

            uint field_pic_flag = 0;

            if (0 == _frameMbsOnlyFlag)
            {
                field_pic_flag = r.ReadBits(1);
                if (0 != field_pic_flag)
                {
                    var bottom_field_flag = r.ReadBits(1);
                }
            }

            _fieldPicFlag = 0 != field_pic_flag;

            if (IdrPicFlag)
            {
                var idr_pic_id = r.ReadUe();

                if (_picOrderCntType == 0)
                {
                    var pic_order_cnt_lsb = r.ReadBits((int)(_log2MaxFrameNumMinus4 ?? 0) + 4);

                    if (0 != _bottomFieldPicOrderInFramePresentFlag && 0 == field_pic_flag)
                    {
                        var delta_pic_order_cnt_bottom = r.ReadSe();
                    }
                }
                if (_picOrderCntType == 1 && 0 == _deltaPicOrderAlwaysZeroFlag)
                {
                    var delta_pic_order_cnt_0 = r.ReadSe();

                    if (0 != _bottomFieldPicOrderInFramePresentFlag && 0 == field_pic_flag)
                    {
                        var delta_pic_order_cnt_1 = r.ReadSe();
                    }
                }

                if (0 != _redundantPicCntPresentFlag)
                {
                    var redundant_pic_cnt = r.ReadUe();
                }
            }
        }
Esempio n. 23
0
        void ReadPicTiming(H264Bitstream r, uint length)
        {
            // Rec. ITU-T H.264 (04/2013) Section D.2.2

            var CpbDpbDelaysPresentFlag = (_nalHrdParametersPresentFlag.HasValue && _nalHrdParametersPresentFlag.Value)
                                          || (_vclHrdParametersPresentFlag.HasValue && _vclHrdParametersPresentFlag.Value);

            if (CpbDpbDelaysPresentFlag)
            {
                if (!_cpbRemovalDelayLengthMinus1.HasValue)
                    return;

                var cpb_removal_delay = r.ReadBits((int)_cpbRemovalDelayLengthMinus1.Value + 1);
                if (!_dpbOutputDelayLengthMinus1.HasValue)
                    return;

                var dpb_output_delay = r.ReadBits((int)_dpbOutputDelayLengthMinus1.Value + 1);
            }

            if (_picStructPresentFlag.HasValue && _picStructPresentFlag.Value)
            {
                var pic_struct = r.ReadBits(4);

                _picStruct = pic_struct;

                var nct = GetNumClockTs();

                if (!nct.HasValue)
                    return;

                var NumClockTS = nct.Value;

                for (var i = 0; i < NumClockTS; i++)
                {
                    var clock_timestamp_flag_i = r.ReadBits(1);
                    if (0 != clock_timestamp_flag_i)
                    {
                        var ct_type = r.ReadBits(2);
                        var nuit_field_based_flag = r.ReadBits(1);
                        var counting_type = r.ReadBits(5);
                        var full_timestamp_flag = r.ReadBits(1);
                        var discontinuity_flag = r.ReadBits(1);
                        var cnt_dropped_flag = r.ReadBits(1);
                        var n_frames = r.ReadBits(8);
                        if (0 != full_timestamp_flag)
                        {
                            var seconds_value /* 0..59 */ = r.ReadBits(6);
                            var minutes_value /* 0..59 */ = r.ReadBits(6);
                            var hours_value /* 0..23 */ = r.ReadBits(5);
                        }
                        else
                        {
                            var seconds_flag = r.ReadBits(1);
                            if (0 != seconds_flag)
                            {
                                var seconds_value /* range 0..59 */ = r.ReadBits(6);
                                var minutes_flag = r.ReadBits(1);
                                if (0 != minutes_flag)
                                {
                                    var minutes_value /* 0..59 */ = r.ReadBits(6);
                                    var hours_flag = r.ReadBits(1);
                                    if (0 != hours_flag)
                                    {
                                        var hours_value /* 0..23 */ = r.ReadBits(5);
                                    }
                                }
                            }
                        }

                        var time_offset_length = _timeOffsetLength ?? 24;

                        if (time_offset_length > 0)
                        {
                            var time_offset = r.ReadSignedBits((int)time_offset_length);
                        }
                    }
                }
            }
        }
Esempio n. 24
0
        public void ReadPps(H264Bitstream r)
        {
            this._slicePicParameterSetId = new uint?();
            r.ReadBits(1);
            r.ReadBits(2);
            r.ReadBits(5);
            this._picParameterSetId    = new uint?(H264BitstreamExtensions.ReadUe(r));
            this._ppsSeqParameterSetId = new uint?(H264BitstreamExtensions.ReadUe(r));
            r.ReadBits(1);
            this._bottomFieldPicOrderInFramePresentFlag = new uint?(r.ReadBits(1));
            uint num1 = H264BitstreamExtensions.ReadUe(r);

            if (num1 > 0U)
            {
                uint num2 = H264BitstreamExtensions.ReadUe(r);
                if (0 == (int)num2)
                {
                    for (int index = 0; (long)index <= (long)num1; ++index)
                    {
                        H264BitstreamExtensions.ReadUe(r);
                    }
                }
                else if (2 == (int)num2)
                {
                    for (int index = 0; (long)index < (long)num1; ++index)
                    {
                        H264BitstreamExtensions.ReadUe(r);
                        H264BitstreamExtensions.ReadUe(r);
                    }
                }
                else if (3 == (int)num2 || 4 == (int)num2 || 5 == (int)num2)
                {
                    r.ReadBits(1);
                    H264BitstreamExtensions.ReadUe(r);
                }
                else if (6 == (int)num2)
                {
                    int  bitSize = H264Reader.GetBitSize(num1);
                    uint num3    = H264BitstreamExtensions.ReadUe(r);
                    for (int index = 0; (long)index <= (long)num3; ++index)
                    {
                        r.ReadBits(bitSize);
                    }
                }
            }
            H264BitstreamExtensions.ReadUe(r);
            H264BitstreamExtensions.ReadUe(r);
            r.ReadBits(1);
            r.ReadBits(2);
            H264BitstreamExtensions.ReadSe(r);
            H264BitstreamExtensions.ReadSe(r);
            H264BitstreamExtensions.ReadSe(r);
            r.ReadBits(1);
            r.ReadBits(1);
            this._redundantPicCntPresentFlag = new uint?(r.ReadBits(1));
            if (!this.more_rbsp_data(r))
            {
                return;
            }
            uint num4 = r.ReadBits(1);

            if (0 != (int)r.ReadBits(1))
            {
                int num2 = 0;
                while (true)
                {
                    long num3     = (long)num2;
                    long num5     = 6;
                    uint?nullable = this._chromaFormatIdc;
                    long num6     = (((int)nullable.GetValueOrDefault() != 3 ? 1 : (!nullable.HasValue ? 1 : 0)) != 0 ? 2L : 6L) * (long)num4;
                    long num7     = num5 + num6;
                    if (num3 < num7)
                    {
                        if (0 != (int)r.ReadBits(1))
                        {
                            if (num2 < 6)
                            {
                                this.ReadScalingList(r, 16);
                            }
                            else
                            {
                                this.ReadScalingList(r, 64);
                            }
                        }
                        ++num2;
                    }
                    else
                    {
                        break;
                    }
                }
            }
            H264BitstreamExtensions.ReadSe(r);
        }
Esempio n. 25
0
 bool more_rbsp_data(H264Bitstream r)
 {
     return r.HasData;
 }
Esempio n. 26
0
 private bool more_rbsp_data(H264Bitstream r)
 {
     return(r.HasData);
 }