1# Copyright 2023 Google LLC 2# 3# Licensed under the Apache License, Version 2.0 (the "License"); 4# you may not use this file except in compliance with the License. 5# You may obtain a copy of the License at 6# 7# https://www.apache.org/licenses/LICENSE-2.0 8# 9# Unless required by applicable law or agreed to in writing, software 10# distributed under the License is distributed on an "AS IS" BASIS, 11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12# See the License for the specific language governing permissions and 13# limitations under the License. 14 15# ----------------------------------------------------------------------------- 16# Imports 17# ----------------------------------------------------------------------------- 18import hashlib 19import os 20from bumble.decoder import G722Decoder 21 22 23# ----------------------------------------------------------------------------- 24def test_decode_file(): 25 decoder = G722Decoder() 26 output_bytes = bytearray() 27 28 with open( 29 os.path.join(os.path.dirname(__file__), 'g722_sample.g722'), 'rb' 30 ) as file: 31 file_content = file.read() 32 frame_length = 80 33 data_length = int(len(file_content) / frame_length) 34 35 for i in range(0, data_length): 36 decoded_data = decoder.decode_frame( 37 file_content[i * frame_length : i * frame_length + frame_length] 38 ) 39 output_bytes.extend(decoded_data) 40 41 result = hashlib.md5(output_bytes).hexdigest() 42 assert result == 'b58e0cdd012d12f5633fc796c3b0fbd4' 43 44 45# ----------------------------------------------------------------------------- 46if __name__ == '__main__': 47 test_decode_file() 48