CSharpRTMP.Common.BitReader.ReadExpGolomb C# (CSharp) Method

ReadExpGolomb() public method

public ReadExpGolomb ( string name = "" ) : ulong
name string
return ulong
        public ulong ReadExpGolomb(string name = "") {
		    ulong value = 1;
		    uint zeroBitsCount = 0;
		    while (true) {
			    if (AvailableBits == 0) {
                    throw new IOException("Unable to read " + name);
			    }
		        if (ReadBool())break;
		        zeroBitsCount++;
		    }
		    if (AvailableBits < zeroBitsCount) {
                throw new IOException("Unable to read " + name);
		    }
		    for (var i = 0; i < zeroBitsCount; i++)
		    {
		        BitsEnumerator.MoveNext();
			    value = (value << 1) | (byte) BitsEnumerator.Current;
		    }
		    value = value - 1;
            return value;
	    }
    }

Usage Example

        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;
        }
All Usage Examples Of CSharpRTMP.Common.BitReader::ReadExpGolomb