예제 #1
0
def test_music_delivery_rejects_unknown_audio_formats(session_mock,
                                                      audio_mock):

    audio_format = mock.Mock(sample_type=17)
    frames = b"123"
    num_frames = 1
    seeking_event = threading.Event()
    push_audio_data_event = threading.Event()
    push_audio_data_event.set()
    buffer_timestamp = mock.Mock()
    held_buffer = collections.deque([mock.sentinel.gst_buffer])

    with pytest.raises(AssertionError) as excinfo:
        playback.music_delivery_callback(
            session_mock,
            audio_format,
            frames,
            num_frames,
            audio_mock,
            seeking_event,
            push_audio_data_event,
            buffer_timestamp,
            held_buffer,
        )

    assert "Expects 16-bit signed integer samples" in str(excinfo.value)
예제 #2
0
def test_music_delivery_consumes_zero_frames_if_audio_fails(
        session_mock, audio_mock, audio_lib_mock):

    audio_mock.emit_data.return_value.get.return_value = False

    audio_format = mock.Mock(channels=2, sample_rate=44100, sample_type=0)
    frames = b"\x00\x00"
    num_frames = 1
    seeking_event = threading.Event()
    push_audio_data_event = threading.Event()
    push_audio_data_event.set()
    buffer_timestamp = mock.Mock()
    buffer_timestamp.get.return_value = mock.sentinel.timestamp

    result = playback.music_delivery_callback(
        session_mock,
        audio_format,
        frames,
        num_frames,
        audio_mock,
        seeking_event,
        push_audio_data_event,
        buffer_timestamp,
    )

    assert buffer_timestamp.increase.call_count == 0
    assert result == 0
예제 #3
0
def test_music_delivery_creates_gstreamer_buffer_and_gives_it_to_audio(
        session_mock, audio_mock, audio_lib_mock):

    audio_lib_mock.calculate_duration.return_value = mock.sentinel.duration
    audio_lib_mock.create_buffer.return_value = mock.sentinel.gst_buffer

    audio_format = mock.Mock(channels=2, sample_rate=44100, sample_type=0)
    frames = b"\x00\x00"
    num_frames = 1
    seeking_event = threading.Event()
    push_audio_data_event = threading.Event()
    push_audio_data_event.set()
    buffer_timestamp = mock.Mock()
    buffer_timestamp.get.return_value = mock.sentinel.timestamp

    result = playback.music_delivery_callback(
        session_mock,
        audio_format,
        frames,
        num_frames,
        audio_mock,
        seeking_event,
        push_audio_data_event,
        buffer_timestamp,
    )

    audio_lib_mock.calculate_duration.assert_called_once_with(1, 44100)
    audio_lib_mock.create_buffer.assert_called_once_with(
        frames,
        timestamp=mock.sentinel.timestamp,
        duration=mock.sentinel.duration,
    )
    buffer_timestamp.increase.assert_called_once_with(mock.sentinel.duration)
    audio_mock.emit_data.assert_called_once_with(mock.sentinel.gst_buffer)
    assert result == num_frames
예제 #4
0
def test_music_delivery_shortcuts_if_no_data_in_frames(session_mock,
                                                       audio_lib_mock,
                                                       audio_mock):

    audio_format = mock.Mock(channels=2, sample_rate=44100, sample_type=0)
    frames = b""
    num_frames = 1
    seeking_event = threading.Event()
    push_audio_data_event = threading.Event()
    push_audio_data_event.set()
    buffer_timestamp = mock.Mock()

    result = playback.music_delivery_callback(
        session_mock,
        audio_format,
        frames,
        num_frames,
        audio_mock,
        seeking_event,
        push_audio_data_event,
        buffer_timestamp,
    )

    assert result == 0
    assert audio_lib_mock.create_buffer.call_count == 0
    assert audio_mock.emit_data.call_count == 0
예제 #5
0
def test_music_delivery_when_seeking_accepts_data_after_empty_delivery(
        session_mock, audio_mock):

    audio_format = mock.Mock()
    frames = b""
    num_frames = 0
    seeking_event = threading.Event()
    seeking_event.set()
    push_audio_data_event = threading.Event()
    push_audio_data_event.set()
    buffer_timestamp = mock.Mock()
    assert seeking_event.is_set()

    result = playback.music_delivery_callback(
        session_mock,
        audio_format,
        frames,
        num_frames,
        audio_mock,
        seeking_event,
        push_audio_data_event,
        buffer_timestamp,
    )

    assert not seeking_event.is_set()
    assert audio_mock.emit_data.call_count == 0
    assert result == num_frames
예제 #6
0
def test_music_delivery_creates_gstreamer_buffer_and_gives_it_to_audio(
        session_mock, audio_mock, audio_lib_mock):

    audio_lib_mock.calculate_duration.return_value = mock.sentinel.duration
    audio_lib_mock.create_buffer.return_value = mock.sentinel.gst_buffer

    audio_format = mock.Mock(channels=2, sample_rate=44100, sample_type=0)
    frames = b'\x00\x00'
    num_frames = 1
    seeking_event = threading.Event()
    push_audio_data_event = threading.Event()
    push_audio_data_event.set()
    buffer_timestamp = mock.Mock()
    buffer_timestamp.get.return_value = mock.sentinel.timestamp

    result = playback.music_delivery_callback(
        session_mock, audio_format, frames, num_frames,
        audio_mock, seeking_event, push_audio_data_event, buffer_timestamp)

    audio_lib_mock.calculate_duration.assert_called_once_with(1, 44100)
    audio_lib_mock.create_buffer.assert_called_once_with(
        frames, timestamp=mock.sentinel.timestamp,
        duration=mock.sentinel.duration)
    buffer_timestamp.increase.assert_called_once_with(mock.sentinel.duration)
    audio_mock.emit_data.assert_called_once_with(mock.sentinel.gst_buffer)
    assert result == num_frames
예제 #7
0
def test_music_delivery_rejects_unknown_audio_formats(
        session_mock, audio_mock):

    audio_format = mock.Mock(sample_type=17)
    frames = b''
    num_frames = 0
    push_audio_data_event = threading.Event()
    push_audio_data_event.set()
    buffer_timestamp = mock.Mock()

    with pytest.raises(AssertionError) as excinfo:
        playback.music_delivery_callback(
            session_mock, audio_format, frames, num_frames,
            audio_mock, push_audio_data_event, buffer_timestamp)

    assert 'Expects 16-bit signed integer samples' in str(excinfo.value)
예제 #8
0
def test_music_delivery_gives_held_buffer_to_audio_and_holds_created(
        session_mock, audio_mock, audio_lib_mock):
    audio_lib_mock.create_buffer.return_value = mock.sentinel.gst_buffer2

    audio_format = mock.Mock(channels=2, sample_rate=44100, sample_type=0)
    frames = b"\x00\x00"
    num_frames = 1
    seeking_event = threading.Event()
    push_audio_data_event = threading.Event()
    push_audio_data_event.set()
    buffer_timestamp = mock.Mock()
    held_buffer = collections.deque([mock.sentinel.gst_buffer1])

    result = playback.music_delivery_callback(
        session_mock,
        audio_format,
        frames,
        num_frames,
        audio_mock,
        seeking_event,
        push_audio_data_event,
        buffer_timestamp,
        held_buffer,
    )
    assert result == num_frames
    audio_mock.emit_data.assert_called_once_with(mock.sentinel.gst_buffer1)
    assert list(held_buffer) == [mock.sentinel.gst_buffer2]
예제 #9
0
def test_music_delivery_rejects_data_depending_on_push_audio_data_event(
        session_mock, audio_mock):

    audio_format = mock.Mock()
    frames = b"123"
    num_frames = 1
    seeking_event = threading.Event()
    push_audio_data_event = threading.Event()
    buffer_timestamp = mock.Mock()
    held_buffer = collections.deque([mock.sentinel.gst_buffer])
    assert not push_audio_data_event.is_set()

    result = playback.music_delivery_callback(
        session_mock,
        audio_format,
        frames,
        num_frames,
        audio_mock,
        seeking_event,
        push_audio_data_event,
        buffer_timestamp,
        held_buffer,
    )

    assert audio_mock.emit_data.call_count == 0
    assert result == 0
예제 #10
0
def test_music_delivery_rejects_unknown_audio_formats(
        session_mock, audio_mock):

    audio_format = mock.Mock(sample_type=17)
    frames = b'123'
    num_frames = 1
    seeking_event = threading.Event()
    push_audio_data_event = threading.Event()
    push_audio_data_event.set()
    buffer_timestamp = mock.Mock()

    with pytest.raises(AssertionError) as excinfo:
        playback.music_delivery_callback(
            session_mock, audio_format, frames, num_frames,
            audio_mock, seeking_event, push_audio_data_event, buffer_timestamp)

    assert 'Expects 16-bit signed integer samples' in str(excinfo.value)
예제 #11
0
def test_music_delivery_rejects_data_depending_on_push_audio_data_event(
        session_mock):

    audio_format = mock.Mock()
    frames = b''
    num_frames = 0
    push_audio_data_event = threading.Event()
    buffer_timestamp = mock.Mock()
    assert not push_audio_data_event.is_set()

    result = playback.music_delivery_callback(
        session_mock, audio_format, frames, num_frames,
        audio_mock, push_audio_data_event, buffer_timestamp)

    assert result == 0
예제 #12
0
def test_music_delivery_rejects_data_depending_on_push_audio_data_event(
        session_mock, audio_mock):

    audio_format = mock.Mock()
    frames = b'123'
    num_frames = 1
    seeking_event = threading.Event()
    push_audio_data_event = threading.Event()
    buffer_timestamp = mock.Mock()
    assert not push_audio_data_event.is_set()

    result = playback.music_delivery_callback(
        session_mock, audio_format, frames, num_frames,
        audio_mock, seeking_event, push_audio_data_event, buffer_timestamp)

    assert audio_mock.emit_data.call_count == 0
    assert result == 0
예제 #13
0
def test_music_delivery_shortcuts_if_no_data_in_frames(
        session_mock, audio_lib_mock, audio_mock):

    audio_format = mock.Mock(channels=2, sample_rate=44100, sample_type=0)
    frames = b''
    num_frames = 1
    seeking_event = threading.Event()
    push_audio_data_event = threading.Event()
    push_audio_data_event.set()
    buffer_timestamp = mock.Mock()

    result = playback.music_delivery_callback(
        session_mock, audio_format, frames, num_frames,
        audio_mock, seeking_event, push_audio_data_event, buffer_timestamp)

    assert result == 0
    assert audio_lib_mock.create_buffer.call_count == 0
    assert audio_mock.emit_data.call_count == 0
예제 #14
0
def test_music_delivery_rejects_data_when_seeking(session_mock, audio_mock):
    audio_format = mock.Mock()
    frames = b'123'
    num_frames = 1
    seeking_event = threading.Event()
    seeking_event.set()
    push_audio_data_event = threading.Event()
    push_audio_data_event.set()
    buffer_timestamp = mock.Mock()
    assert seeking_event.is_set()

    result = playback.music_delivery_callback(
        session_mock, audio_format, frames, num_frames,
        audio_mock, seeking_event, push_audio_data_event, buffer_timestamp)

    assert seeking_event.is_set()
    assert audio_mock.emit_data.call_count == 0
    assert result == num_frames
예제 #15
0
def test_music_delivery_consumes_zero_frames_if_audio_fails(
        session_mock, audio_mock, audio_lib_mock):

    audio_mock.emit_data.return_value.get.return_value = False

    audio_format = mock.Mock(channels=2, sample_rate=44100, sample_type=0)
    frames = b'\x00\x00'
    num_frames = 1
    push_audio_data_event = threading.Event()
    push_audio_data_event.set()
    buffer_timestamp = mock.Mock()
    buffer_timestamp.get.return_value = mock.sentinel.timestamp

    result = playback.music_delivery_callback(
        session_mock, audio_format, frames, num_frames,
        audio_mock, push_audio_data_event, buffer_timestamp)

    assert result == 0