def create_audio_frames(self, channels, sample_rate, count): frames = [] timestamp = 0 samples_per_frame = int(AUDIO_PTIME * sample_rate) for i in range(count): frame = AudioFrame(channels=channels, data=bytes(2 * channels * samples_per_frame), sample_rate=sample_rate) frame.pts = timestamp frame.time_base = fractions.Fraction(1, sample_rate) frames.append(frame) timestamp += samples_per_frame return frames
def roundtrip_audio(self, codec, output_channels, output_sample_rate): """ Round-trip an AudioFrame through encoder then decoder. """ encoder = get_encoder(codec) decoder = get_decoder(codec) # encode frame = AudioFrame(channels=1, data=b'\x00\x00' * 160, sample_rate=8000, timestamp=0) self.assertEqual(len(frame.data), 320) data = encoder.encode(frame) # decode frames = decoder.decode(JitterFrame(data=data, timestamp=0)) self.assertEqual(len(frames), 1) self.assertEqual( len(frames[0].data), output_sample_rate * AUDIO_PTIME * output_channels * 2) self.assertEqual(frames[0].channels, output_channels) self.assertEqual(frames[0].sample_rate, output_sample_rate) self.assertEqual(frames[0].sample_width, 2) self.assertEqual(frames[0].timestamp, 0)
def test_audio(self): frame = AudioFrame(channels=1, data=bytes(320), sample_rate=8000) frame.pts = 160 frame.time_base = fractions.Fraction(1, 8000) self.assertEqual(frame.time, 0.02)
def test_audio_no_time_base(self): frame = AudioFrame(channels=1, data=bytes(320), sample_rate=8000) frame.pts = 160 self.assertEqual(frame.time, None)