ReadBitsToInt() public method

public ReadBitsToInt ( byte count = 32 ) : int
count byte
return int
Exemplo n.º 1
0
        public bool Init(Stream pBuffer, int length)
        {
            Clear();
            var oldPosition = pBuffer.Position;
            if (length < 2)
            {
                Logger.FATAL("Invalid length:{0}", length);
                return false;
            }
            var bitReader = new BitReader(pBuffer);

            _audioObjectType = bitReader.ReadBitsToByte(5);
            if ((_audioObjectType != 1)
                && (_audioObjectType != 2)
                && (_audioObjectType != 3)
                && (_audioObjectType != 4)
                && (_audioObjectType != 6)
                && (_audioObjectType != 17)
                && (_audioObjectType != 19)
                && (_audioObjectType != 20)
                && (_audioObjectType != 23)
                && (_audioObjectType != 39))
            {
                Logger.FATAL("Invalid _audioObjectType: {0}", _audioObjectType);
                return false;
            }
            //3. Read the sample rate index
            _sampleRateIndex = bitReader.ReadBitsToByte(4);
            if ((_sampleRateIndex == 13)
                    || (_sampleRateIndex == 14))
            {
                Logger.FATAL("Invalid sample rate: {0}", _sampleRateIndex);
                return false;
            }
            if (_sampleRateIndex == 15)
            {
                if (length < 5)
                {
                    Logger.FATAL("Invalid length:{0}", length);
                    return false;
                }
                _sampleRate = (uint)bitReader.ReadBitsToInt(24);
            }
            else
            {
                var rates = new uint[]{
			96000, 88200, 64000, 48000, 44100, 32000, 24000, 22050, 16000,
			12000, 11025, 8000, 7350
		};
                _sampleRate = rates[_sampleRateIndex];
            }

            //4. read the channel configuration index
            _channelConfigurationIndex = bitReader.ReadBitsToByte(4);
            if ((_channelConfigurationIndex == 0)
                    || (_channelConfigurationIndex >= 8))
            {
                Logger.FATAL("Invalid _channelConfigurationIndex: {0}", _channelConfigurationIndex);
                return false;
            }

            pBuffer.Position = oldPosition;
            _pAAC = new byte[length];
            pBuffer.Read(_pAAC, 0, length);
            _aacLength = (uint) length;
            return true;
        }
Exemplo n.º 2
0
        private bool ReadPPS(BitReader ppsReader, Variant ppsInfo)
        {
            //7.3.2.2 Picture parameter set RBSP syntax
            //14496-10.pdf 44/280
            ppsInfo["pic_parameter_set_id"] = ppsReader.ReadExpGolomb("pic_parameter_set_id");
            ppsInfo["seq_parameter_set_id"] = ppsReader.ReadExpGolomb("seq_parameter_set_id");
            ppsInfo["entropy_coding_mode_flag"] = ppsReader.ReadBool();
            ppsInfo["pic_order_present_flag"] = ppsReader.ReadBool();
            ppsInfo["num_slice_groups_minus1"] = ppsReader.ReadExpGolomb("num_slice_groups_minus1");
            
            if (ppsInfo["num_slice_groups_minus1"] > 0)
            {
                long sliceGroupMapType = ppsInfo["slice_group_map_type"] = ppsReader.ReadExpGolomb("slice_group_map_type");

                switch (sliceGroupMapType)
                {
                    case 0:
                        ppsInfo["run_length_minus1"] = Variant.Get();
                        for (var i = 0; i < ppsInfo["num_slice_groups_minus1"]; i++)
                        {
                            var val = ppsReader.ReadExpGolomb("run_length_minus1");
                            ppsInfo["run_length_minus1"].Add(val);
                        }
                        break;
                    case 2:
                        ppsInfo["top_left"] = Variant.Get();
                        ppsInfo["bottom_right"] = Variant.Get();
                        for (var i = 0; i < ppsInfo["num_slice_groups_minus1"]; i++)
                        {
                            ppsInfo["top_left"].Add(ppsReader.ReadExpGolomb("top_left"));
                            ppsInfo["bottom_right"].Add(ppsReader.ReadExpGolomb("bottom_right"));
                        }
                        break;
                    case 3:
                    case 4:
                    case 5:
                        ppsInfo["slice_group_change_direction_flag"] = ppsReader.ReadBool();
                        ppsInfo["slice_group_change_rate_minus1"] = ppsReader.ReadExpGolomb("slice_group_change_rate_minus1");
                        break;
                    case 6:
                        ppsInfo["pic_size_in_map_units_minus1"] = ppsReader.ReadExpGolomb("pic_size_in_map_units_minus1");
                        ppsInfo["slice_group_id"] = Variant.Get();
                        for (var i = 0; i <= ppsInfo["pic_size_in_map_units_minus1"]; i++)
                        {
                            ppsInfo["slice_group_id"].Add(ppsReader.ReadExpGolomb("slice_group_id"));
                        }
                        break;
                }
            }
            ppsInfo["num_ref_idx_l0_active_minus1"] = ppsReader.ReadExpGolomb("num_ref_idx_l0_active_minus1");
            ppsInfo["num_ref_idx_l1_active_minus1"] = ppsReader.ReadExpGolomb("num_ref_idx_l1_active_minus1");
            ppsInfo["weighted_pred_flag"] = ppsReader.ReadBool();
            ppsInfo["weighted_bipred_idc"] = ppsReader.ReadBitsToInt(2);
            ppsInfo["pic_init_qp_minus26"] = ppsReader.ReadExpGolomb("pic_init_qp_minus26");
            ppsInfo["pic_init_qs_minus26"] = ppsReader.ReadExpGolomb("pic_init_qs_minus26");
            ppsInfo["chromqp_index_offset"] = ppsReader.ReadExpGolomb("chromqp_index_offset");
            ppsInfo["deblocking_filter_control_present_flag"] = ppsReader.ReadBool();
            ppsInfo["constrained_intrpred_flag"] = ppsReader.ReadBool();
            ppsInfo["redundant_pic_cnt_present_flag"] = ppsReader.ReadBool();
            return true;
        }
Exemplo n.º 3
0
 private bool ReadSPSVUI(BitReader spsReader, Variant v)
 {
     //E.1.1 VUI parameters syntax
     //14496-10.pdf 267/280
     v["aspect_ratio_info_present_flag"] = spsReader.ReadBool();
     if (v["aspect_ratio_info_present_flag"])
     {
         v["aspect_ratio_idc"] = spsReader.ReadBitsToByte();
         if ((byte)v["aspect_ratio_idc"] == 255)
         {
             v["sar_width"] = (ushort)spsReader.ReadBitsToShort();
             v["sar_height"] = (ushort)spsReader.ReadBitsToShort();
         }
     }
     v["overscan_info_present_flag"] = spsReader.ReadBool();
     if (v["overscan_info_present_flag"])
         v["overscan_appropriate_flag"] = spsReader.ReadBool();
     v["video_signal_type_present_flag"] = spsReader.ReadBool();
     if (v["video_signal_type_present_flag"])
     {
         v["video_format"] = spsReader.ReadBitsToByte(3);
         v["video_full_range_flag"] = spsReader.ReadBool();
         v["colour_description_present_flag"] = spsReader.ReadBool();
         if (v["colour_description_present_flag"])
         {
             v["colour_primaries"] = spsReader.ReadBitsToByte();
             v["transfer_characteristics"] = spsReader.ReadBitsToByte();
             v["matrix_coefficients"] = spsReader.ReadBitsToByte();
         }
     }
     v["chromloc_info_present_flag"] = spsReader.ReadBool();
     if (v["chromloc_info_present_flag"])
     {
         v["chromsample_loc_type_top_field"] = spsReader.ReadExpGolomb("chromsample_loc_type_top_field");
         v["chromsample_loc_type_bottom_field"] = spsReader.ReadExpGolomb("chromsample_loc_type_bottom_field");
     }
     v["timing_info_present_flag"] = spsReader.ReadBool();
     if (v["timing_info_present_flag"])
     {
         v["num_units_in_tick"] = spsReader.ReadBitsToInt();
         v["time_scale"] = spsReader.ReadBitsToInt();
         v["fixed_frame_rate_flag"] = spsReader.ReadBool();
     }
     v["nal_hrd_parameters_present_flag"] = spsReader.ReadBool();
     if (v["nal_hrd_parameters_present_flag"])
     {
         if (!ReadSPSVUIHRD(spsReader, v["nal_hrd"] = Variant.Get()))
         {
             Logger.FATAL("Unable to read VUIHRD");
             return false;
         }
     }
     v["vcl_hrd_parameters_present_flag"] = spsReader.ReadBool();
     if (v["vcl_hrd_parameters_present_flag"])
     {
         if (!ReadSPSVUIHRD(spsReader, v["vcl_hrd"] = Variant.Get()))
         {
             Logger.FATAL("Unable to read VUIHRD");
             return false;
         }
     }
     if (v["nal_hrd_parameters_present_flag"]
             || v["vcl_hrd_parameters_present_flag"])
         v["low_delay_hrd_flag"] = spsReader.ReadBool();
     v["pic_struct_present_flag"] = spsReader.ReadBool();
     v["bitstream_restriction_flag"] = spsReader.ReadBool();
     if (v["bitstream_restriction_flag"])
     {
         v["motion_vectors_over_pic_boundaries_flag"] = spsReader.ReadBool();
         v["max_bytes_per_pic_denom"] = spsReader.ReadExpGolomb("max_bytes_per_pic_denom");
         v["max_bits_per_mb_denom"] = spsReader.ReadExpGolomb("max_bits_per_mb_denom");
         v["log2_max_mv_length_horizontal"] = spsReader.ReadExpGolomb("log2_max_mv_length_horizontal");
         v["log2_max_mv_length_vertical"] = spsReader.ReadExpGolomb("log2_max_mv_length_vertical");
         v["num_reorder_frames"] = spsReader.ReadExpGolomb("num_reorder_frames");
         v["max_dec_frame_buffering"] = spsReader.ReadExpGolomb("max_dec_frame_buffering");
     }
     return true;
 }