Module: BRS::Option

Defined in:
lib/brs/option.rb

Constant Summary collapse

DEFAULT_BUFFER_LENGTH =
0
COMPRESSOR_DEFAULTS =
{
  :gvl                              => false,
  :mode                             => nil,
  :quality                          => nil,
  :lgwin                            => nil,
  :lgblock                          => nil,
  :npostfix                         => nil,
  :ndirect                          => nil,
  :disable_literal_context_modeling => nil,
  :large_window                     => nil
}
.freeze
DECOMPRESSOR_DEFAULTS =
{
  :gvl                              => false,
  :disable_ring_buffer_reallocation => nil,
  :large_window                     => nil
}
.freeze

Class Method Summary collapse

Class Method Details

.get_compressor_options(options, buffer_length_names) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
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
# File 'lib/brs/option.rb', line 33

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



97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# File 'lib/brs/option.rb', line 97

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