Module: BRS::Option

Defined in:
lib/brs/option.rb

Overview

BRS::Option module.

Constant Summary collapse

DEFAULT_BUFFER_LENGTH =

Current default buffer length.

0
COMPRESSOR_DEFAULTS =

Current compressor defaults.

{
  # Enables global VM lock where possible.
  :gvl                              => false,
  # Compressor mode.
  :mode                             => nil,
  # Compression level.
  :quality                          => nil,
  # Compressor window size.
  :lgwin                            => nil,
  # Compressor input block size.
  :lgblock                          => nil,
  # Recommended number of postfix bits.
  :npostfix                         => nil,
  # Recommended number of direct distance codes (step 1 << npostfix, max 15 << npostfix).
  :ndirect                          => nil,
  # Disables literal context modeling format.
  :disable_literal_context_modeling => nil,
  # Enables large window.
  :large_window                     => nil
}
.freeze
DECOMPRESSOR_DEFAULTS =

Current decompressor defaults.

{
  # Enables global VM lock where possible.
  :gvl                              => false,
  # Disables ring buffer reallocation.
  :disable_ring_buffer_reallocation => nil,
  # Enables large window.
  :large_window                     => nil
}
.freeze

Class Method Summary collapse

Class Method Details

.get_compressor_options(options, buffer_length_names) ⇒ Object

Processes compressor options and buffer_length_names. Option: :source_buffer_length source buffer length. Option: :destination_buffer_length destination buffer length. Option: :gvl enables global VM lock where possible. Option: :mode compressor mode. Option: :quality compression level. Option: :lgwin compressor window size. Option: :lgblock compressor input block size. Option: :npostfix recommended number of postfix bits. Option: :ndirect recommended number of direct distance codes (step 1 << npostfix, max 15 << npostfix). Option: :disable_literal_context_modeling Disables literal context modeling format. Option: :large_window enables large window. Returns processed compressor options.



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# File 'lib/brs/option.rb', line 62

def self.get_compressor_options(options, buffer_length_names)
  Validation.validate_hash options

  buffer_length_defaults = buffer_length_names.each_with_object({}) do |name, defaults|
    defaults[name] = DEFAULT_BUFFER_LENGTH
  end

  options = COMPRESSOR_DEFAULTS.merge(buffer_length_defaults).merge options

  buffer_length_names.each { |name| Validation.validate_not_negative_integer options[name] }

  Validation.validate_bool options[:gvl]

  mode = options[:mode]
  unless mode.nil?
    Validation.validate_symbol mode
    raise ValidateError, "invalid mode" unless MODES.include? mode
  end

  quality = options[:quality]
  unless quality.nil?
    Validation.validate_not_negative_integer quality
    raise ValidateError, "invalid quality" if quality < MIN_QUALITY || quality > MAX_QUALITY
  end

  lgwin = options[:lgwin]
  unless lgwin.nil?
    Validation.validate_not_negative_integer lgwin
    raise ValidateError, "invalid lgwin" if lgwin < MIN_LGWIN || lgwin > MAX_LGWIN
  end

  lgblock = options[:lgblock]
  unless lgblock.nil?
    Validation.validate_not_negative_integer lgblock
    raise ValidateError, "invalid lgblock" if lgblock < MIN_LGBLOCK || lgblock > MAX_LGBLOCK
  end

  npostfix = options[:npostfix]
  unless npostfix.nil?
    Validation.validate_not_negative_integer npostfix
    raise ValidateError, "invalid npostfix" if npostfix < MIN_NPOSTFIX || npostfix > MAX_NPOSTFIX
  end

  ndirect = options[:ndirect]
  unless ndirect.nil?
    Validation.validate_not_negative_integer ndirect
    raise ValidateError, "invalid ndirect" if ndirect < MIN_NDIRECT || ndirect > MAX_NDIRECT

    raise ValidateError, "invalid ndirect" if
      !npostfix.nil? && (
        (ndirect - MIN_NDIRECT) % (NDIRECT_NPOSTFIX_STEP_BASE << npostfix) != 0 ||
        (ndirect - MIN_NDIRECT) > (NDIRECT_NPOSTFIX_MAX_BASE << npostfix)
      )
  end

  disable_literal_context_modeling = options[:disable_literal_context_modeling]
  Validation.validate_bool disable_literal_context_modeling unless disable_literal_context_modeling.nil?

  large_window = options[:large_window]
  Validation.validate_bool large_window unless large_window.nil?

  options
end

.get_decompressor_options(options, buffer_length_names) ⇒ Object

Processes decompressor options and buffer_length_names. Option: :source_buffer_length source buffer length. Option: :destination_buffer_length destination buffer length. Option: :gvl enables global VM lock where possible. Option: :disable_ring_buffer_reallocation disables ring buffer reallocation. Option: :large_window enables large window. Returns processed decompressor options.



133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
# File 'lib/brs/option.rb', line 133

def self.get_decompressor_options(options, buffer_length_names)
  Validation.validate_hash options

  buffer_length_defaults = buffer_length_names.each_with_object({}) do |name, defaults|
    defaults[name] = DEFAULT_BUFFER_LENGTH
  end

  options = DECOMPRESSOR_DEFAULTS.merge(buffer_length_defaults).merge options

  buffer_length_names.each { |name| Validation.validate_not_negative_integer options[name] }

  Validation.validate_bool options[:gvl]

  disable_ring_buffer_reallocation = options[:disable_ring_buffer_reallocation]
  Validation.validate_bool disable_ring_buffer_reallocation unless disable_ring_buffer_reallocation.nil?

  large_window = options[:large_window]
  Validation.validate_bool large_window unless large_window.nil?

  options
end