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

ReadBitsToShort() public method

public ReadBitsToShort ( byte count = 16 ) : short
count byte
return short
        public short ReadBitsToShort(byte count = 16)
        {
            short result = 0;
            if (AvailableBits < count) throw new EndOfStreamException();
            for (var i = 0; i < count; i++)
            {
                BitsEnumerator.MoveNext();
                result = (short)((result << 1) | BitsEnumerator.Current);
            }
            return result;
        }
        public byte ReadBitsToByte(byte count = 8)

Usage Example

 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;
 }