예제 #1
0
def test_camera_stream_frames_trunc_left():
    camera = mock.Mock()
    encoder = mock.Mock()
    camera._encoders = {1: encoder}
    stream = PiCameraCircularIO(camera, size=10)
    frames = []
    for data, frame in generate_frames('hkffkffhkff'):
        encoder.frame = frame
        if frame.complete:
            frames.append(frame)
        stream.write(data)
    del frames[:3]
    # As we've gotten rid of the start of the stream we need to re-calc the
    # video and split sizes in the comparison meta-data
    sizes = accumulate(f.frame_size for f in frames)
    frames = [
        PiVideoFrame(
            f.index,
            f.frame_type,
            f.frame_size,
            size,
            size,
            f.timestamp,
            f.complete
            )
        for f, size in zip(frames, sizes)
        ]
    assert stream.getvalue() == b'fkkffhkkff'
    assert list(stream.frames) == frames
    assert list(reversed(stream.frames)) == frames[::-1]
예제 #2
0
def test_camera_stream_clear():
    camera = mock.Mock()
    encoder = mock.Mock()
    camera._encoders = {1: encoder}
    stream = PiCameraCircularIO(camera, size=10)
    for data, frame in generate_frames('hkffkff'):
        encoder.frame = frame
        stream.write(data)
    stream.clear()
    assert stream.getvalue() == b''
    assert list(stream.frames) == []
    assert list(reversed(stream.frames)) == []
예제 #3
0
def test_camera_stream_copy_seconds():
    camera = mock.Mock()
    encoder = mock.Mock()
    camera._encoders = {1: encoder}
    stream = PiCameraCircularIO(camera, size=10)
    for data, frame in generate_frames('hkffkff'):
        encoder.frame = frame
        stream.write(data)
    output = io.BytesIO()
    stream.copy_to(output, seconds=1)
    assert output.getvalue() == b''
    stream.copy_to(output, seconds=10)
    assert output.getvalue() == b'hkkffkkff'
예제 #4
0
def test_camera_stream_frames():
    camera = mock.Mock()
    encoder = mock.Mock()
    camera._encoders = {1: encoder}
    stream = PiCameraCircularIO(camera, size=10)
    frames = []
    for data, frame in generate_frames('hkffkff'):
        encoder.frame = frame
        if frame.complete:
            frames.append(frame)
        stream.write(data)
    assert stream.getvalue() == b'hkkffkkff'
    assert list(stream.frames) == frames
    assert list(reversed(stream.frames)) == frames[::-1]
예제 #5
0
def test_camera_stream_frames_trunc_right():
    # We don't officially support this but the code should work if entire
    # frames are truncated (without leaving partial frame data) which is what
    # we're testing for here (of course, the resulting H.264 stream won't be
    # valid, but we're not testing that...)
    camera = mock.Mock()
    encoder = mock.Mock()
    camera._encoders = {1: encoder}
    stream = PiCameraCircularIO(camera, size=10)
    frames = []
    for data, frame in generate_frames('hkffkff'):
        encoder.frame = frame
        if frame.complete:
            frames.append(frame)
        stream.write(data)
    stream.seek(7)
    stream.truncate()
    del frames[-2:]
    assert stream.getvalue() == b'hkkffkk'
    assert list(stream.frames) == frames
    assert list(reversed(stream.frames)) == frames[::-1]