1818from __future__ import annotations
1919from dataclasses import dataclass
2020
21+ from bumble import core
22+
2123
2224# -----------------------------------------------------------------------------
2325class BitReader :
@@ -40,7 +42,7 @@ def read(self, bits: int) -> int:
4042 """ "Read up to 32 bits."""
4143
4244 if bits > 32 :
43- raise ValueError ('maximum read size is 32' )
45+ raise core . InvalidArgumentError ('maximum read size is 32' )
4446
4547 if self .bits_cached >= bits :
4648 # We have enough bits.
@@ -53,7 +55,7 @@ def read(self, bits: int) -> int:
5355 feed_size = len (feed_bytes )
5456 feed_int = int .from_bytes (feed_bytes , byteorder = 'big' )
5557 if 8 * feed_size + self .bits_cached < bits :
56- raise ValueError ('trying to read past the data' )
58+ raise core . InvalidArgumentError ('trying to read past the data' )
5759 self .byte_position += feed_size
5860
5961 # Combine the new cache and the old cache
@@ -68,7 +70,7 @@ def read(self, bits: int) -> int:
6870
6971 def read_bytes (self , count : int ):
7072 if self .bit_position + 8 * count > 8 * len (self .data ):
71- raise ValueError ('not enough data' )
73+ raise core . InvalidArgumentError ('not enough data' )
7274
7375 if self .bit_position % 8 :
7476 # Not byte aligned
@@ -113,7 +115,7 @@ def latm_value(reader: BitReader) -> int:
113115
114116 @staticmethod
115117 def program_config_element (reader : BitReader ):
116- raise ValueError ('program_config_element not supported' )
118+ raise core . InvalidPacketError ('program_config_element not supported' )
117119
118120 @dataclass
119121 class GASpecificConfig :
@@ -140,7 +142,7 @@ def __init__(
140142 aac_spectral_data_resilience_flags = reader .read (1 )
141143 extension_flag_3 = reader .read (1 )
142144 if extension_flag_3 == 1 :
143- raise ValueError ('extensionFlag3 == 1 not supported' )
145+ raise core . InvalidPacketError ('extensionFlag3 == 1 not supported' )
144146
145147 @staticmethod
146148 def audio_object_type (reader : BitReader ):
@@ -216,7 +218,7 @@ def __init__(self, reader: BitReader) -> None:
216218 reader , self .channel_configuration , self .audio_object_type
217219 )
218220 else :
219- raise ValueError (
221+ raise core . InvalidPacketError (
220222 f'audioObjectType { self .audio_object_type } not supported'
221223 )
222224
@@ -260,18 +262,18 @@ def __init__(self, reader: BitReader) -> None:
260262 else :
261263 audio_mux_version_a = 0
262264 if audio_mux_version_a != 0 :
263- raise ValueError ('audioMuxVersionA != 0 not supported' )
265+ raise core . InvalidPacketError ('audioMuxVersionA != 0 not supported' )
264266 if audio_mux_version == 1 :
265267 tara_buffer_fullness = AacAudioRtpPacket .latm_value (reader )
266268 stream_cnt = 0
267269 all_streams_same_time_framing = reader .read (1 )
268270 num_sub_frames = reader .read (6 )
269271 num_program = reader .read (4 )
270272 if num_program != 0 :
271- raise ValueError ('num_program != 0 not supported' )
273+ raise core . InvalidPacketError ('num_program != 0 not supported' )
272274 num_layer = reader .read (3 )
273275 if num_layer != 0 :
274- raise ValueError ('num_layer != 0 not supported' )
276+ raise core . InvalidPacketError ('num_layer != 0 not supported' )
275277 if audio_mux_version == 0 :
276278 self .audio_specific_config = AacAudioRtpPacket .AudioSpecificConfig (
277279 reader
@@ -284,7 +286,7 @@ def __init__(self, reader: BitReader) -> None:
284286 )
285287 audio_specific_config_len = reader .bit_position - marker
286288 if asc_len < audio_specific_config_len :
287- raise ValueError ('audio_specific_config_len > asc_len' )
289+ raise core . InvalidPacketError ('audio_specific_config_len > asc_len' )
288290 asc_len -= audio_specific_config_len
289291 reader .skip (asc_len )
290292 frame_length_type = reader .read (3 )
@@ -293,7 +295,9 @@ def __init__(self, reader: BitReader) -> None:
293295 elif frame_length_type == 1 :
294296 frame_length = reader .read (9 )
295297 else :
296- raise ValueError (f'frame_length_type { frame_length_type } not supported' )
298+ raise core .InvalidPacketError (
299+ f'frame_length_type { frame_length_type } not supported'
300+ )
297301
298302 self .other_data_present = reader .read (1 )
299303 if self .other_data_present :
@@ -318,12 +322,12 @@ class AudioMuxElement:
318322
319323 def __init__ (self , reader : BitReader , mux_config_present : int ):
320324 if mux_config_present == 0 :
321- raise ValueError ('muxConfigPresent == 0 not supported' )
325+ raise core . InvalidPacketError ('muxConfigPresent == 0 not supported' )
322326
323327 # AudioMuxElement - ISO/EIC 14496-3 Table 1.41
324328 use_same_stream_mux = reader .read (1 )
325329 if use_same_stream_mux :
326- raise ValueError ('useSameStreamMux == 1 not supported' )
330+ raise core . InvalidPacketError ('useSameStreamMux == 1 not supported' )
327331 self .stream_mux_config = AacAudioRtpPacket .StreamMuxConfig (reader )
328332
329333 # We only support:
0 commit comments