Example #1
0
def test_init(mock_driver):
    """Test that the camera init properly computes TLV values"""
    acc = camera.Camera(_OPTIONS, mock_driver, 'Camera')

    management = acc.get_service('CameraRTPStreamManagement')

    assert management.get_characteristic('SupportedRTPConfiguration').get_value() == \
        'AgEA'
    assert (management.get_characteristic('SupportedVideoStreamConfiguration')
                      .get_value() ==
        'AX4BAQACCQMBAAEBAAIBAAMMAQJAAQIC8AADAg8AAwwBAgAEAgIAAwMCHgADDAECgAICAuA'
        'BAwIeAAMMAQKAAgICaAEDAh4AAwwBAuABAgJoAQMCHgADDAEC4AECAg4BAwIeAAMMAQJAAQ'
        'IC8AADAh4AAwwBAkABAgK0AAMCHgA=')
    assert (management.get_characteristic('SupportedAudioStreamConfiguration')
                      .get_value() ==
        'AQ4BAQMCCQEBAQIBAAMBAgEOAQECAgkBAQECAQADAQECAQA=')
Example #2
0
def test_setup_endpoints(mock_driver):
    """Test that the SetupEndpoint response is computed correctly"""
    set_endpoint_req = ('ARCszGzBBWNFFY2pdLRQkAaRAxoBAQACDTE5Mi4xNjguMS4xMTQDAjPFBAKs1gQ'
                        'lAhDYlmCkyTBZQfxqFS3OnxVOAw4bQZm5NuoQjyanlqWA0QEBAAUlAhAKRPSRVa'
                        'qGeNmESTIojxNiAw78WkjTLtGv0waWnLo9gQEBAA==')

    set_endpoint_res = ('ARCszGzBBWNFFY2pdLRQkAaRAgEAAxoBAQACDTE5Mi4xNjguMS4yMjYDAjPFBAK'
                        's1gQlAQEAAhDYlmCkyTBZQfxqFS3OnxVOAw4bQZm5NuoQjyanlqWA0QUlAQEAAh'
                        'AKRPSRVaqGeNmESTIojxNiAw78WkjTLtGv0waWnLo9gQYBAQcBAQ==')

    acc = camera.Camera(_OPTIONS, mock_driver, 'Camera')
    setup_endpoints = acc.get_service('CameraRTPStreamManagement')\
                         .get_characteristic('SetupEndpoints')
    setup_endpoints.client_update_value(set_endpoint_req)

    assert setup_endpoints.get_value() == set_endpoint_res
Example #3
0
def test_set_selected_stream_start_stop(mock_driver):
    """Test starting a stream request"""
    selected_config_req = (
        'ARUCAQEBEKzMbMEFY0UVjal0tFCQBpECNAEBAAIJAQEAAgEAAwEAAwsBAoAC'
        'AgJoAQMBHgQXAQFjAgQr66FSAwKEAAQEAAAAPwUCYgUDLAEBAgIMAQEBAgEA'
        'AwEBBAEeAxYBAW4CBMUInmQDAhgABAQAAKBABgENBAEA')

    session_id = UUID('accc6cc1-0563-4515-8da9-74b450900691')

    session_info = {
        'id': session_id,
        'address': '192.168.1.114',
        'v_port': 50483,
        'v_srtp_key': '2JZgpMkwWUH8ahUtzp8VThtBmbk26hCPJqeWpYDR',
        'a_port': 54956,
        'a_srtp_key': 'CkT0kVWqhnjZhEkyKI8TYvxaSNMu0a/TBpacuj2B',
        'process': None
    }

    acc = camera.Camera(_OPTIONS, mock_driver, 'Camera')
    acc.sessions[session_id] = session_info

    selected_config = acc.get_service('CameraRTPStreamManagement')\
                         .get_characteristic('SelectedRTPStreamConfiguration')

    patcher = patch('subprocess.Popen', spec=True)
    patched_popen = patcher.start()
    patched_popen.return_value.pid = 42
    patched_popen.return_value.stderr = Mock(return_value='Process stderr')
    selected_config.client_update_value(selected_config_req)
    patcher.stop()

    assert acc.streaming_status == camera.STREAMING_STATUS['STREAMING']

    selected_config_stop_req = 'ARUCAQABEKzMbMEFY0UVjal0tFCQBpE='
    selected_config.client_update_value(selected_config_stop_req)

    assert session_id not in acc.sessions
    assert patched_popen.return_value.terminate.called
    assert acc.streaming_status == camera.STREAMING_STATUS['AVAILABLE']
Example #4
0
            # [480, 270, 30],
            # [320, 240, 30],
            # [320, 180, 30],
        ],
    },
    "audio": {
        "codecs": [{
            'type': 'OPUS',
            'samplerate': 24,
        }, {
            'type': 'AAC-eld',
            'samplerate': 16
        }],
    },
    "srtp": True,

    # hard code the address if auto-detection does not work as desired: e.g. "192.168.1.226"
    "address": util.get_local_address(),
    "start_stream_cmd": FFMPEG_CMD
}

# Start the accessory on port 51826
driver = AccessoryDriver(port=51826)
acc = camera.Camera(options, driver, "Camera")
driver.add_accessory(accessory=acc)

# We want KeyboardInterrupts and SIGTERM (terminate) to be handled by the driver itself,
# so that it can gracefully stop the accessory, server and advertising.
signal.signal(signal.SIGTERM, driver.signal_handler)
# Start it!
driver.start()