code
stringlengths 26
870k
| docstring
stringlengths 1
65.6k
| func_name
stringlengths 1
194
| language
stringclasses 1
value | repo
stringlengths 8
68
| path
stringlengths 5
194
| url
stringlengths 46
254
| license
stringclasses 4
values |
---|---|---|---|---|---|---|---|
def __init__(self, hass, config, connection):
"""Initialize the number."""
super().__init__(hass, config)
self._message_id = config[CONF_ID]
self._connection = connection | Initialize the number. | __init__ | python | zachowj/hass-node-red | custom_components/nodered/select.py | https://github.com/zachowj/hass-node-red/blob/master/custom_components/nodered/select.py | MIT |
async def async_select_option(self, option: str) -> None:
"""Set new option."""
self._connection.send_message(
event_message(
self._message_id, {CONF_TYPE: EVENT_VALUE_CHANGE, CONF_VALUE: option}
)
) | Set new option. | async_select_option | python | zachowj/hass-node-red | custom_components/nodered/select.py | https://github.com/zachowj/hass-node-red/blob/master/custom_components/nodered/select.py | MIT |
def update_entity_state_attributes(self, msg):
"""Update the entity state attributes."""
super().update_entity_state_attributes(msg)
self._attr_current_option = msg.get(CONF_STATE) | Update the entity state attributes. | update_entity_state_attributes | python | zachowj/hass-node-red | custom_components/nodered/select.py | https://github.com/zachowj/hass-node-red/blob/master/custom_components/nodered/select.py | MIT |
def update_discovery_config(self, msg):
"""Update the entity config."""
super().update_discovery_config(msg)
self._attr_icon = msg[CONF_CONFIG].get(CONF_ICON, SELECT_ICON)
if msg[CONF_CONFIG].get(CONF_OPTIONS) is not None:
self._attr_options = msg[CONF_CONFIG].get(CONF_OPTIONS) | Update the entity config. | update_discovery_config | python | zachowj/hass-node-red | custom_components/nodered/select.py | https://github.com/zachowj/hass-node-red/blob/master/custom_components/nodered/select.py | MIT |
async def async_setup_entry(hass, config_entry, async_add_entities):
"""Set up the Switch platform."""
async def async_discover(config, connection):
await _async_setup_entity(hass, config, async_add_entities, connection)
async_dispatcher_connect(
hass,
NODERED_DISCOVERY_NEW.format(CONF_SWITCH),
async_discover,
)
platform = entity_platform.current_platform.get()
platform.async_register_entity_service(
SERVICE_TRIGGER, SERVICE_TRIGGER_SCHEMA, "async_trigger_node"
) | Set up the Switch platform. | async_setup_entry | python | zachowj/hass-node-red | custom_components/nodered/switch.py | https://github.com/zachowj/hass-node-red/blob/master/custom_components/nodered/switch.py | MIT |
async def _async_setup_entity(hass, config, async_add_entities, connection):
"""Set up the Node-RED Switch."""
async_add_entities([NodeRedSwitch(hass, config, connection)]) | Set up the Node-RED Switch. | _async_setup_entity | python | zachowj/hass-node-red | custom_components/nodered/switch.py | https://github.com/zachowj/hass-node-red/blob/master/custom_components/nodered/switch.py | MIT |
def __init__(self, hass, config, connection):
"""Initialize the switch."""
super().__init__(hass, config)
self._message_id = config[CONF_ID]
self._connection = connection
self._attr_state = config.get(CONF_STATE, True)
self._attr_icon = self._config.get(CONF_ICON) | Initialize the switch. | __init__ | python | zachowj/hass-node-red | custom_components/nodered/switch.py | https://github.com/zachowj/hass-node-red/blob/master/custom_components/nodered/switch.py | MIT |
def is_on(self) -> bool:
"""Return the state of the switch."""
return self._attr_state | Return the state of the switch. | is_on | python | zachowj/hass-node-red | custom_components/nodered/switch.py | https://github.com/zachowj/hass-node-red/blob/master/custom_components/nodered/switch.py | MIT |
async def async_turn_off(self, **kwargs) -> None:
"""Turn off the switch."""
self._update_node_red(False) | Turn off the switch. | async_turn_off | python | zachowj/hass-node-red | custom_components/nodered/switch.py | https://github.com/zachowj/hass-node-red/blob/master/custom_components/nodered/switch.py | MIT |
async def async_turn_on(self, **kwargs) -> None:
"""Turn on the switch."""
self._update_node_red(True) | Turn on the switch. | async_turn_on | python | zachowj/hass-node-red | custom_components/nodered/switch.py | https://github.com/zachowj/hass-node-red/blob/master/custom_components/nodered/switch.py | MIT |
async def async_trigger_node(self, **kwargs) -> None:
"""Trigger node in Node-RED."""
data = {}
data[CONF_OUTPUT_PATH] = kwargs.get(CONF_OUTPUT_PATH, True)
if kwargs.get(CONF_MESSAGE) is not None:
data[CONF_MESSAGE] = kwargs[CONF_MESSAGE]
self._connection.send_message(
event_message(
self._message_id,
{CONF_TYPE: EVENT_TRIGGER_NODE, CONF_DATA: data},
)
) | Trigger node in Node-RED. | async_trigger_node | python | zachowj/hass-node-red | custom_components/nodered/switch.py | https://github.com/zachowj/hass-node-red/blob/master/custom_components/nodered/switch.py | MIT |
def update_entity_state_attributes(self, msg):
"""Update the entity state attributes."""
super().update_entity_state_attributes(msg)
self._attr_state = msg.get(CONF_STATE) | Update the entity state attributes. | update_entity_state_attributes | python | zachowj/hass-node-red | custom_components/nodered/switch.py | https://github.com/zachowj/hass-node-red/blob/master/custom_components/nodered/switch.py | MIT |
def update_discovery_config(self, msg):
"""Update the entity config."""
super().update_discovery_config(msg)
self._attr_icon = msg[CONF_CONFIG].get(CONF_ICON, SWITCH_ICON) | Update the entity config. | update_discovery_config | python | zachowj/hass-node-red | custom_components/nodered/switch.py | https://github.com/zachowj/hass-node-red/blob/master/custom_components/nodered/switch.py | MIT |
async def async_setup_entry(hass, config_entry, async_add_entities):
"""Set up the number platform."""
async def async_discover(config, connection):
await _async_setup_entity(hass, config, async_add_entities, connection)
async_dispatcher_connect(
hass,
NODERED_DISCOVERY_NEW.format(CONF_NUMBER),
async_discover,
) | Set up the number platform. | async_setup_entry | python | zachowj/hass-node-red | custom_components/nodered/number.py | https://github.com/zachowj/hass-node-red/blob/master/custom_components/nodered/number.py | MIT |
async def _async_setup_entity(hass, config, async_add_entities, connection):
"""Set up the Node-RED number."""
async_add_entities([NodeRedNumber(hass, config, connection)]) | Set up the Node-RED number. | _async_setup_entity | python | zachowj/hass-node-red | custom_components/nodered/number.py | https://github.com/zachowj/hass-node-red/blob/master/custom_components/nodered/number.py | MIT |
def __init__(self, hass, config, connection):
"""Initialize the number."""
super().__init__(hass, config)
self._message_id = config[CONF_ID]
self._connection = connection
self._attr_icon = self._config.get(CONF_ICON, NUMBER_ICON)
self._attr_native_value = config.get(CONF_STATE)
self._attr_native_min_value = self._config.get(
CONF_MIN_VALUE, DEFAULT_MIN_VALUE
)
self._attr_native_max_value = self._config.get(
CONF_MAX_VALUE, DEFAULT_MAX_VALUE
)
self._attr_native_step = self._config.get(CONF_STEP_VALUE, DEFAULT_STEP)
self._attr_mode = self._config.get(CONF_MODE, NumberMode.AUTO) | Initialize the number. | __init__ | python | zachowj/hass-node-red | custom_components/nodered/number.py | https://github.com/zachowj/hass-node-red/blob/master/custom_components/nodered/number.py | MIT |
async def async_set_native_value(self, value: float) -> None:
"""Set new value."""
self._connection.send_message(
event_message(
self._message_id, {CONF_TYPE: EVENT_VALUE_CHANGE, CONF_VALUE: value}
)
) | Set new value. | async_set_native_value | python | zachowj/hass-node-red | custom_components/nodered/number.py | https://github.com/zachowj/hass-node-red/blob/master/custom_components/nodered/number.py | MIT |
async def async_added_to_hass(self) -> None:
"""Load the last known state when added to hass."""
await super().async_added_to_hass()
if (last_state := await self.async_get_last_state()) and (
last_number_data := await self.async_get_last_number_data()
):
if last_state.state not in (STATE_UNKNOWN, STATE_UNAVAILABLE):
self._attr_native_value = last_number_data.native_value | Load the last known state when added to hass. | async_added_to_hass | python | zachowj/hass-node-red | custom_components/nodered/number.py | https://github.com/zachowj/hass-node-red/blob/master/custom_components/nodered/number.py | MIT |
def update_entity_state_attributes(self, msg):
"""Update the entity state attributes."""
super().update_entity_state_attributes(msg)
self._attr_native_value = msg.get(CONF_STATE) | Update the entity state attributes. | update_entity_state_attributes | python | zachowj/hass-node-red | custom_components/nodered/number.py | https://github.com/zachowj/hass-node-red/blob/master/custom_components/nodered/number.py | MIT |
def update_discovery_config(self, msg):
"""Update the entity config."""
super().update_discovery_config(msg)
self._attr_icon = self._config.get(CONF_ICON, NUMBER_ICON)
self._attr_native_min_value = self._config.get(
CONF_MIN_VALUE, DEFAULT_MIN_VALUE
)
self._attr_native_max_value = self._config.get(
CONF_MAX_VALUE, DEFAULT_MAX_VALUE
)
self._attr_native_step = self._config.get(CONF_STEP_VALUE, DEFAULT_STEP)
self._attr_mode = self._config.get(CONF_MODE, NumberMode.AUTO)
self._attr_native_unit_of_measurement = self._config.get(
CONF_UNIT_OF_MEASUREMENT
) | Update the entity config. | update_discovery_config | python | zachowj/hass-node-red | custom_components/nodered/number.py | https://github.com/zachowj/hass-node-red/blob/master/custom_components/nodered/number.py | MIT |
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
"""Set up this integration using UI."""
if hass.data.get(DOMAIN_DATA) is None:
hass.data.setdefault(DOMAIN_DATA, {})
_LOGGER.info(STARTUP_MESSAGE)
register_websocket_handlers(hass)
await start_discovery(hass, hass.data[DOMAIN_DATA], entry)
hass.bus.async_fire(DOMAIN, {CONF_TYPE: "loaded", CONF_VERSION: VERSION})
entry.async_on_unload(entry.add_update_listener(async_reload_entry))
return True | Set up this integration using UI. | async_setup_entry | python | zachowj/hass-node-red | custom_components/nodered/__init__.py | https://github.com/zachowj/hass-node-red/blob/master/custom_components/nodered/__init__.py | MIT |
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry):
"""Handle removal of an entry."""
unloaded = all(
await asyncio.gather(
*[
hass.config_entries.async_forward_entry_unload(entry, platform)
for platform in hass.data[DOMAIN_DATA][CONFIG_ENTRY_IS_SETUP]
]
)
)
if unloaded:
stop_discovery(hass)
hass.data.pop(DOMAIN_DATA)
hass.bus.async_fire(DOMAIN, {CONF_TYPE: "unloaded"})
return unloaded | Handle removal of an entry. | async_unload_entry | python | zachowj/hass-node-red | custom_components/nodered/__init__.py | https://github.com/zachowj/hass-node-red/blob/master/custom_components/nodered/__init__.py | MIT |
def __init__(self, hass, config):
"""Initialize the entity."""
self.hass = hass
self._device_info = config.get(CONF_DEVICE_INFO)
self._server_id = config[CONF_SERVER_ID]
self._node_id = config[CONF_NODE_ID]
self._attr_unique_id = f"{DOMAIN}-{self._server_id}-{self._node_id}"
self._attr_should_poll = False
self.update_discovery_config(config)
self.update_entity_state_attributes(config) | Initialize the entity. | __init__ | python | zachowj/hass-node-red | custom_components/nodered/__init__.py | https://github.com/zachowj/hass-node-red/blob/master/custom_components/nodered/__init__.py | MIT |
def device_info(self) -> Optional[dict[str, Any]]:
"""Return device specific attributes."""
info = None
if self._device_info is not None and "id" in self._device_info:
# Use the id property to create the device identifier then delete it
info = {"identifiers": {(DOMAIN, self._device_info["id"])}}
del self._device_info["id"]
info.update(self._device_info)
return info | Return device specific attributes. | device_info | python | zachowj/hass-node-red | custom_components/nodered/__init__.py | https://github.com/zachowj/hass-node-red/blob/master/custom_components/nodered/__init__.py | MIT |
def handle_config_update(self, msg):
"""Handle config update."""
self.update_config(msg)
self.async_write_ha_state() | Handle config update. | handle_config_update | python | zachowj/hass-node-red | custom_components/nodered/__init__.py | https://github.com/zachowj/hass-node-red/blob/master/custom_components/nodered/__init__.py | MIT |
def handle_entity_update(self, msg):
"""Update entity state."""
_LOGGER.debug(f"Entity Update: {msg}")
self.update_entity_state_attributes(msg)
self.async_write_ha_state() | Update entity state. | handle_entity_update | python | zachowj/hass-node-red | custom_components/nodered/__init__.py | https://github.com/zachowj/hass-node-red/blob/master/custom_components/nodered/__init__.py | MIT |
def update_entity_state_attributes(self, msg):
"""Update entity state attributes."""
self._attr_extra_state_attributes = msg.get(CONF_ATTRIBUTES, {}) | Update entity state attributes. | update_entity_state_attributes | python | zachowj/hass-node-red | custom_components/nodered/__init__.py | https://github.com/zachowj/hass-node-red/blob/master/custom_components/nodered/__init__.py | MIT |
def handle_lost_connection(self):
"""Set availability to False when disconnected."""
self._attr_available = False
self.async_write_ha_state() | Set availability to False when disconnected. | handle_lost_connection | python | zachowj/hass-node-red | custom_components/nodered/__init__.py | https://github.com/zachowj/hass-node-red/blob/master/custom_components/nodered/__init__.py | MIT |
def recreate_entity():
"""Create entity with new type."""
del msg[CONF_REMOVE]
async_dispatcher_send(
self.hass,
NODERED_DISCOVERY.format(msg[CONF_COMPONENT]),
msg,
connection,
) | Create entity with new type. | handle_discovery_update.recreate_entity | python | zachowj/hass-node-red | custom_components/nodered/__init__.py | https://github.com/zachowj/hass-node-red/blob/master/custom_components/nodered/__init__.py | MIT |
def handle_discovery_update(self, msg, connection):
"""Update entity config."""
if CONF_REMOVE in msg:
if msg[CONF_REMOVE] == CHANGE_ENTITY_TYPE:
# recreate entity if component type changed
@callback
def recreate_entity():
"""Create entity with new type."""
del msg[CONF_REMOVE]
async_dispatcher_send(
self.hass,
NODERED_DISCOVERY.format(msg[CONF_COMPONENT]),
msg,
connection,
)
self.async_on_remove(recreate_entity)
# Remove entity
self.hass.async_create_task(self.async_remove(force_remove=True))
else:
self.update_discovery_config(msg)
self.update_discovery_device_info(msg)
if self._bidirectional:
self._attr_available = True
self._message_id = msg[CONF_ID]
self._connection = connection
self._connection.subscriptions[msg[CONF_ID]] = (
self.handle_lost_connection
)
self.async_write_ha_state() | Update entity config. | handle_discovery_update | python | zachowj/hass-node-red | custom_components/nodered/__init__.py | https://github.com/zachowj/hass-node-red/blob/master/custom_components/nodered/__init__.py | MIT |
def entity_category_mapper(self, category):
"""Map Node-RED category to Home Assistant entity category."""
if category == "config":
return EntityCategory.CONFIG
if category == "diagnostic":
return EntityCategory.DIAGNOSTIC
return None | Map Node-RED category to Home Assistant entity category. | entity_category_mapper | python | zachowj/hass-node-red | custom_components/nodered/__init__.py | https://github.com/zachowj/hass-node-red/blob/master/custom_components/nodered/__init__.py | MIT |
def update_discovery_config(self, msg):
"""Update entity config."""
self._config = msg[CONF_CONFIG]
self._attr_icon = self._config.get(CONF_ICON)
self._attr_name = self._config.get(CONF_NAME, f"{DOMAIN} {self._node_id}")
self._attr_device_class = self._config.get(CONF_DEVICE_CLASS)
self._attr_entity_category = self.entity_category_mapper(
self._config.get(CONF_ENTITY_CATEGORY)
)
self._attr_entity_picture = self._config.get(CONF_ENTITY_PICTURE)
self._attr_unit_of_measurement = self._config.get(CONF_UNIT_OF_MEASUREMENT) | Update entity config. | update_discovery_config | python | zachowj/hass-node-red | custom_components/nodered/__init__.py | https://github.com/zachowj/hass-node-red/blob/master/custom_components/nodered/__init__.py | MIT |
def update_config(self, msg):
"""Update entity config."""
config = msg.get(CONF_CONFIG, {})
if config.get(CONF_NAME):
self._attr_name = config.get(CONF_NAME)
if config.get(CONF_ICON):
self._attr_icon = config.get(CONF_ICON)
if config.get(CONF_ENTITY_PICTURE):
self._attr_entity_picture = config.get(CONF_ENTITY_PICTURE)
if config.get(CONF_OPTIONS):
self._attr_options = config.get(CONF_OPTIONS) | Update entity config. | update_config | python | zachowj/hass-node-red | custom_components/nodered/__init__.py | https://github.com/zachowj/hass-node-red/blob/master/custom_components/nodered/__init__.py | MIT |
def update_discovery_device_info(self, msg):
"""Update entity device info."""
entity_registry = async_get(self.hass)
entity_id = entity_registry.async_get_entity_id(
self._component,
DOMAIN,
self.unique_id,
)
self._device_info = msg.get(CONF_DEVICE_INFO)
# Remove entity from device registry if device info is removed
if self._device_info is None and entity_id is not None:
entity_registry.async_update_entity(entity_id, device_id=None)
# Update device info
if self._device_info is not None:
device_registry = dr.async_get(self.hass)
device_info = self.device_info
indentifiers = device_info.pop("identifiers")
device = device_registry.async_get_device(indentifiers)
if device is not None:
device_registry.async_update_device(
device.id,
**device_info,
)
# add entity to device
if entity_id is not None:
entity_registry.async_update_entity(entity_id, device_id=device.id) | Update entity device info. | update_discovery_device_info | python | zachowj/hass-node-red | custom_components/nodered/__init__.py | https://github.com/zachowj/hass-node-red/blob/master/custom_components/nodered/__init__.py | MIT |
async def async_added_to_hass(self) -> None:
"""Run when entity about to be added to hass."""
self._remove_signal_entity_update = async_dispatcher_connect(
self.hass,
NODERED_ENTITY.format(self._server_id, self._node_id),
self.handle_entity_update,
)
self._remove_signal_discovery_update = async_dispatcher_connect(
self.hass,
NODERED_DISCOVERY_UPDATED.format(self.unique_id),
self.handle_discovery_update,
)
self._remove_signal_config_update = async_dispatcher_connect(
self.hass,
NODERED_CONFIG_UPDATE.format(self._server_id, self._node_id),
self.handle_config_update,
)
if self._bidirectional:
self._connection.subscriptions[self._message_id] = (
self.handle_lost_connection
) | Run when entity about to be added to hass. | async_added_to_hass | python | zachowj/hass-node-red | custom_components/nodered/__init__.py | https://github.com/zachowj/hass-node-red/blob/master/custom_components/nodered/__init__.py | MIT |
async def async_will_remove_from_hass(self) -> None:
"""Run when entity will be removed from hass."""
if self._remove_signal_entity_update is not None:
self._remove_signal_entity_update()
if self._remove_signal_discovery_update is not None:
self._remove_signal_discovery_update()
del self.hass.data[DOMAIN_DATA][ALREADY_DISCOVERED][self.unique_id]
# Remove the entity_id from the entity registry
entity_registry = async_get(self.hass)
entity_id = entity_registry.async_get_entity_id(
self._component,
DOMAIN,
self.unique_id,
)
if entity_id:
entity_registry.async_remove(entity_id)
_LOGGER.info(f"Entity removed: {entity_id}") | Run when entity will be removed from hass. | async_will_remove_from_hass | python | zachowj/hass-node-red | custom_components/nodered/__init__.py | https://github.com/zachowj/hass-node-red/blob/master/custom_components/nodered/__init__.py | MIT |
async def async_reload_entry(hass: HomeAssistant, entry: ConfigEntry):
"""Reload config entry."""
await async_unload_entry(hass, entry)
await async_setup_entry(hass, entry) | Reload config entry. | async_reload_entry | python | zachowj/hass-node-red | custom_components/nodered/__init__.py | https://github.com/zachowj/hass-node-red/blob/master/custom_components/nodered/__init__.py | MIT |
async def async_remove_config_entry_device(
hass: HomeAssistant, config_entry: ConfigEntry, device_entry: DeviceEntry
) -> bool:
"""Remove a entry from the device registry."""
entity_registry = async_get(hass)
entries = async_entries_for_device(entity_registry, device_entry.id)
# Remove entities from device before removing device so the entities are not removed from HA
if entries:
for entry in entries:
entity_registry.async_update_entity(entry.entity_id, device_id=None)
return True | Remove a entry from the device registry. | async_remove_config_entry_device | python | zachowj/hass-node-red | custom_components/nodered/__init__.py | https://github.com/zachowj/hass-node-red/blob/master/custom_components/nodered/__init__.py | MIT |
def test_json_encoder(hass):
"""Test the NodeRedJSONEncoder."""
ha_json_enc = NodeRedJSONEncoder()
# Test serializing a timedelta
data = timedelta(
days=1,
hours=2,
minutes=3,
)
assert ha_json_enc.default(data) == data.total_seconds() | Test the NodeRedJSONEncoder. | test_json_encoder | python | zachowj/hass-node-red | tests/test_utils.py | https://github.com/zachowj/hass-node-red/blob/master/tests/test_utils.py | MIT |
def auto_enable_custom_integrations(enable_custom_integrations):
"""Enable custom integrations."""
yield | Enable custom integrations. | auto_enable_custom_integrations | python | zachowj/hass-node-red | tests/conftest.py | https://github.com/zachowj/hass-node-red/blob/master/tests/conftest.py | MIT |
def skip_notifications_fixture():
"""Skip notification calls."""
with patch("homeassistant.components.persistent_notification.async_create"), patch(
"homeassistant.components.persistent_notification.async_dismiss"
):
yield | Skip notification calls. | skip_notifications_fixture | python | zachowj/hass-node-red | tests/conftest.py | https://github.com/zachowj/hass-node-red/blob/master/tests/conftest.py | MIT |
def bypass_setup_fixture():
"""Prevent setup."""
with patch(
"custom_components.nodered.async_setup",
return_value=True,
), patch(
"custom_components.nodered.async_setup_entry",
return_value=True,
):
yield | Prevent setup. | bypass_setup_fixture | python | zachowj/hass-node-red | tests/test_config_flow.py | https://github.com/zachowj/hass-node-red/blob/master/tests/test_config_flow.py | MIT |
async def test_successful_config_flow(hass):
"""Test a successful config flow."""
# Initialize a config flow
result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": config_entries.SOURCE_USER}
)
# Check that the config flow shows the user form as the first step
assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
assert result["step_id"] == "user"
result = await hass.config_entries.flow.async_configure(
result["flow_id"], user_input={}
)
# Check that the config flow is complete and a new entry is created with
# the input data
assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
assert result["title"] == CONF_NAME
assert result["data"] == {}
assert result["result"] | Test a successful config flow. | test_successful_config_flow | python | zachowj/hass-node-red | tests/test_config_flow.py | https://github.com/zachowj/hass-node-red/blob/master/tests/test_config_flow.py | MIT |
async def test_setup_unload_and_reload_entry(hass):
"""Test entry setup and unload."""
# Create a mock entry so we don't have to go through config flow
config_entry = MockConfigEntry(domain=DOMAIN, data={})
# Set up the entry and assert that the values set during setup are where we expect
# them to be.
assert await async_setup_entry(hass, config_entry)
assert DOMAIN_DATA in hass.data
# Reload the entry and assert that the data from above is still there
assert await async_reload_entry(hass, config_entry) is None
assert DOMAIN_DATA in hass.data
# Unload the entry and verify that the data has been removed
assert await async_unload_entry(hass, config_entry)
assert DOMAIN_DATA not in hass.data | Test entry setup and unload. | test_setup_unload_and_reload_entry | python | zachowj/hass-node-red | tests/test_init.py | https://github.com/zachowj/hass-node-red/blob/master/tests/test_init.py | MIT |
def test_short_picture_id_17(self):
"""
From RFC 7741 - 4.6.3
"""
descr, rest = VpxPayloadDescriptor.parse(b"\x90\x80\x11")
self.assertEqual(descr.partition_start, 1)
self.assertEqual(descr.partition_id, 0)
self.assertEqual(descr.picture_id, 17)
self.assertEqual(descr.tl0picidx, None)
self.assertEqual(descr.tid, None)
self.assertEqual(descr.keyidx, None)
self.assertEqual(bytes(descr), b"\x90\x80\x11")
self.assertEqual(repr(descr), "VpxPayloadDescriptor(S=1, PID=0, pic_id=17)")
self.assertEqual(rest, b"") | From RFC 7741 - 4.6.3 | test_short_picture_id_17 | python | aiortc/aiortc | tests/test_vpx.py | https://github.com/aiortc/aiortc/blob/master/tests/test_vpx.py | BSD-3-Clause |
def test_long_picture_id_4711(self):
"""
From RFC 7741 - 4.6.5
"""
descr, rest = VpxPayloadDescriptor.parse(b"\x90\x80\x92\x67")
self.assertEqual(descr.partition_start, 1)
self.assertEqual(descr.partition_id, 0)
self.assertEqual(descr.picture_id, 4711)
self.assertEqual(descr.tl0picidx, None)
self.assertEqual(descr.tid, None)
self.assertEqual(descr.keyidx, None)
self.assertEqual(bytes(descr), b"\x90\x80\x92\x67")
self.assertEqual(rest, b"") | From RFC 7741 - 4.6.5 | test_long_picture_id_4711 | python | aiortc/aiortc | tests/test_vpx.py | https://github.com/aiortc/aiortc/blob/master/tests/test_vpx.py | BSD-3-Clause |
async def test_connection_error(self):
"""
Close the underlying transport before the sender.
"""
async with dummy_dtls_transport_pair() as (local_transport, _):
sender = RTCRtpSender(AudioStreamTrack(), local_transport)
self.assertEqual(sender.kind, "audio")
await sender.send(RTCRtpParameters(codecs=[PCMU_CODEC]))
await local_transport.stop() | Close the underlying transport before the sender. | test_connection_error | python | aiortc/aiortc | tests/test_rtcrtpsender.py | https://github.com/aiortc/aiortc/blob/master/tests/test_rtcrtpsender.py | BSD-3-Clause |
async def test_send_keyframe(self):
"""
Ask for a keyframe.
"""
queue = asyncio.Queue()
async def mock_send_rtp(data):
if not is_rtcp(data):
await queue.put(RtpPacket.parse(data))
async with dummy_dtls_transport_pair() as (local_transport, _):
local_transport._send_rtp = mock_send_rtp
sender = RTCRtpSender(VideoStreamTrack(), local_transport)
self.assertEqual(sender.kind, "video")
await sender.send(RTCRtpParameters(codecs=[VP8_CODEC]))
# wait for one packet to be transmitted, and ask for keyframe
await queue.get()
sender._send_keyframe()
# wait for packet to be transmitted, then shutdown
await asyncio.sleep(0.1)
await sender.stop() | Ask for a keyframe. | test_send_keyframe | python | aiortc/aiortc | tests/test_rtcrtpsender.py | https://github.com/aiortc/aiortc/blob/master/tests/test_rtcrtpsender.py | BSD-3-Clause |
async def test_retransmit(self):
"""
Ask for an RTP packet retransmission.
"""
queue = asyncio.Queue()
async def mock_send_rtp(data):
if not is_rtcp(data):
await queue.put(RtpPacket.parse(data))
async with dummy_dtls_transport_pair() as (local_transport, _):
local_transport._send_rtp = mock_send_rtp
sender = RTCRtpSender(VideoStreamTrack(), local_transport)
sender._ssrc = 1234
self.assertEqual(sender.kind, "video")
await sender.send(RTCRtpParameters(codecs=[VP8_CODEC]))
# wait for one packet to be transmitted, and ask to retransmit
packet = await queue.get()
await sender._retransmit(packet.sequence_number)
# wait for packet to be retransmitted, then shutdown
await asyncio.sleep(0.1)
await sender.stop()
# check packet was retransmitted
found_rtx = None
while not queue.empty():
queue_packet = queue.get_nowait()
if queue_packet.sequence_number == packet.sequence_number:
found_rtx = queue_packet
break
self.assertIsNotNone(found_rtx)
self.assertEqual(found_rtx.payload_type, 100)
self.assertEqual(found_rtx.ssrc, 1234) | Ask for an RTP packet retransmission. | test_retransmit | python | aiortc/aiortc | tests/test_rtcrtpsender.py | https://github.com/aiortc/aiortc/blob/master/tests/test_rtcrtpsender.py | BSD-3-Clause |
async def test_retransmit_with_rtx(self):
"""
Ask for an RTP packet retransmission.
"""
queue = asyncio.Queue()
async def mock_send_rtp(data):
if not is_rtcp(data):
await queue.put(RtpPacket.parse(data))
async with dummy_dtls_transport_pair() as (local_transport, _):
local_transport._send_rtp = mock_send_rtp
sender = RTCRtpSender(VideoStreamTrack(), local_transport)
sender._ssrc = 1234
sender._rtx_ssrc = 2345
self.assertEqual(sender.kind, "video")
await sender.send(
RTCRtpParameters(
codecs=[
VP8_CODEC,
RTCRtpCodecParameters(
mimeType="video/rtx",
clockRate=90000,
payloadType=101,
parameters={"apt": 100},
),
]
)
)
# wait for one packet to be transmitted, and ask to retransmit
packet = await queue.get()
await sender._retransmit(packet.sequence_number)
# wait for packet to be retransmitted, then shutdown
await asyncio.sleep(0.1)
await sender.stop()
# check packet was retransmitted
found_rtx = None
while not queue.empty():
queue_packet = queue.get_nowait()
if queue_packet.payload_type == 101:
found_rtx = queue_packet
break
self.assertIsNotNone(found_rtx)
self.assertEqual(found_rtx.payload_type, 101)
self.assertEqual(found_rtx.ssrc, 2345)
self.assertEqual(found_rtx.payload[0:2], pack("!H", packet.sequence_number)) | Ask for an RTP packet retransmission. | test_retransmit_with_rtx | python | aiortc/aiortc | tests/test_rtcrtpsender.py | https://github.com/aiortc/aiortc/blob/master/tests/test_rtcrtpsender.py | BSD-3-Clause |
async def test_lossy_channel(self):
"""
Transport with 25% loss eventually connects.
"""
transport1, transport2 = dummy_ice_transport_pair()
loss_pattern = [True, False, False, False]
transport1._connection.loss_pattern = loss_pattern
transport2._connection.loss_pattern = loss_pattern
certificate1 = RTCCertificate.generateCertificate()
session1 = RTCDtlsTransport(transport1, [certificate1])
certificate2 = RTCCertificate.generateCertificate()
session2 = RTCDtlsTransport(transport2, [certificate2])
await asyncio.gather(
session1.start(session2.getLocalParameters()),
session2.start(session1.getLocalParameters()),
)
await session1.stop()
await session2.stop() | Transport with 25% loss eventually connects. | test_lossy_channel | python | aiortc/aiortc | tests/test_rtcdtlstransport.py | https://github.com/aiortc/aiortc/blob/master/tests/test_rtcdtlstransport.py | BSD-3-Clause |
def test_remove_audio_frame(self):
"""
Audio jitter buffer.
"""
jbuffer = JitterBuffer(capacity=16, prefetch=4)
packet = RtpPacket(sequence_number=0, timestamp=1234)
packet._data = b"0000"
pli_flag, frame = jbuffer.add(packet)
self.assertIsNone(frame)
packet = RtpPacket(sequence_number=1, timestamp=1235)
packet._data = b"0001"
pli_flag, frame = jbuffer.add(packet)
self.assertIsNone(frame)
packet = RtpPacket(sequence_number=2, timestamp=1236)
packet._data = b"0002"
pli_flag, frame = jbuffer.add(packet)
self.assertIsNone(frame)
packet = RtpPacket(sequence_number=3, timestamp=1237)
packet._data = b"0003"
pli_flag, frame = jbuffer.add(packet)
self.assertIsNone(frame)
packet = RtpPacket(sequence_number=4, timestamp=1238)
packet._data = b"0003"
pli_flag, frame = jbuffer.add(packet)
self.assertIsNotNone(frame)
self.assertEqual(frame.data, b"0000")
self.assertEqual(frame.timestamp, 1234)
packet = RtpPacket(sequence_number=5, timestamp=1239)
packet._data = b"0004"
pli_flag, frame = jbuffer.add(packet)
self.assertIsNotNone(frame)
self.assertEqual(frame.data, b"0001")
self.assertEqual(frame.timestamp, 1235) | Audio jitter buffer. | test_remove_audio_frame | python | aiortc/aiortc | tests/test_jitterbuffer.py | https://github.com/aiortc/aiortc/blob/master/tests/test_jitterbuffer.py | BSD-3-Clause |
def test_remove_video_frame(self):
"""
Video jitter buffer.
"""
jbuffer = JitterBuffer(capacity=128, is_video=True)
packet = RtpPacket(sequence_number=0, timestamp=1234)
packet._data = b"0000"
pli_flag, frame = jbuffer.add(packet)
self.assertIsNone(frame)
packet = RtpPacket(sequence_number=1, timestamp=1234)
packet._data = b"0001"
pli_flag, frame = jbuffer.add(packet)
self.assertIsNone(frame)
packet = RtpPacket(sequence_number=2, timestamp=1234)
packet._data = b"0002"
pli_flag, frame = jbuffer.add(packet)
self.assertIsNone(frame)
packet = RtpPacket(sequence_number=3, timestamp=1235)
packet._data = b"0003"
pli_flag, frame = jbuffer.add(packet)
self.assertIsNotNone(frame)
self.assertEqual(frame.data, b"000000010002")
self.assertEqual(frame.timestamp, 1234) | Video jitter buffer. | test_remove_video_frame | python | aiortc/aiortc | tests/test_jitterbuffer.py | https://github.com/aiortc/aiortc/blob/master/tests/test_jitterbuffer.py | BSD-3-Clause |
def test_pli_flag(self):
"""
Video jitter buffer.
"""
jbuffer = JitterBuffer(capacity=128, is_video=True)
pli_flag, frame = jbuffer.add(RtpPacket(sequence_number=2000, timestamp=1234))
self.assertIsNone(frame)
self.assertEqual(jbuffer._origin, 2000)
self.assertFalse(pli_flag)
# test_add_seq_too_low_reset for video (capacity >= 128)
pli_flag, frame = jbuffer.add(RtpPacket(sequence_number=1, timestamp=1234))
self.assertIsNone(frame)
self.assertEqual(jbuffer._origin, 1)
self.assertTrue(pli_flag)
pli_flag, frame = jbuffer.add(RtpPacket(sequence_number=128, timestamp=1235))
self.assertIsNone(frame)
self.assertEqual(jbuffer._origin, 1)
self.assertFalse(pli_flag)
# test_add_seq_too_high_discard_one for video (capacity >= 128)
pli_flag, frame = jbuffer.add(RtpPacket(sequence_number=129, timestamp=1235))
self.assertIsNone(frame)
self.assertEqual(jbuffer._origin, 128)
self.assertTrue(pli_flag)
# test_add_seq_too_high_reset for video (capacity >= 128)
pli_flag, frame = jbuffer.add(RtpPacket(sequence_number=2000, timestamp=2345))
self.assertIsNone(frame)
self.assertEqual(jbuffer._origin, 2000)
self.assertTrue(pli_flag) | Video jitter buffer. | test_pli_flag | python | aiortc/aiortc | tests/test_jitterbuffer.py | https://github.com/aiortc/aiortc/blob/master/tests/test_jitterbuffer.py | BSD-3-Clause |
async def test_connection_error(self):
"""
Close the underlying transport before the receiver.
"""
async with create_receiver("audio") as receiver:
receiver._track = RemoteStreamTrack(kind="audio")
receiver._set_rtcp_ssrc(1234)
await receiver.receive(RTCRtpReceiveParameters(codecs=[PCMU_CODEC]))
# receive a packet to prime RTCP
packet = RtpPacket.parse(load("rtp.bin"))
await receiver._handle_rtp_packet(packet, arrival_time_ms=0)
# break connection
await receiver.transport.stop()
# give RTCP time to send a report
await asyncio.sleep(2) | Close the underlying transport before the receiver. | test_connection_error | python | aiortc/aiortc | tests/test_rtcrtpreceiver.py | https://github.com/aiortc/aiortc/blob/master/tests/test_rtcrtpreceiver.py | BSD-3-Clause |
async def _test_connect_audio_bidirectional(self, pc1, pc2):
pc1_states = track_states(pc1)
pc1_tracks = track_remote_tracks(pc1)
pc2_states = track_states(pc2)
pc2_tracks = track_remote_tracks(pc2)
self.assertEqual(pc1.iceConnectionState, "new")
self.assertEqual(pc1.iceGatheringState, "new")
self.assertIsNone(pc1.localDescription)
self.assertIsNone(pc1.remoteDescription)
self.assertEqual(pc2.iceConnectionState, "new")
self.assertEqual(pc2.iceGatheringState, "new")
self.assertIsNone(pc2.localDescription)
self.assertIsNone(pc2.remoteDescription)
# create offer
track1 = AudioStreamTrack()
pc1.addTrack(track1)
offer = await pc1.createOffer()
self.assertEqual(offer.type, "offer")
self.assertTrue("m=audio " in offer.sdp)
self.assertFalse("a=candidate:" in offer.sdp)
self.assertFalse("a=end-of-candidates" in offer.sdp)
await pc1.setLocalDescription(offer)
self.assertEqual(pc1.iceConnectionState, "new")
self.assertEqual(pc1.iceGatheringState, "complete")
self.assertEqual(mids(pc1), ["0"])
self.assertTrue("m=audio " in pc1.localDescription.sdp)
self.assertTrue(
lf2crlf(
"""a=rtpmap:96 opus/48000/2
a=rtpmap:0 PCMU/8000
a=rtpmap:8 PCMA/8000
"""
)
in pc1.localDescription.sdp
)
self.assertTrue("a=sendrecv" in pc1.localDescription.sdp)
self.assertHasIceCandidates(pc1.localDescription)
self.assertHasDtls(pc1.localDescription, "actpass")
# handle offer
await pc2.setRemoteDescription(pc1.localDescription)
self.assertEqual(pc2.remoteDescription, pc1.localDescription)
self.assertEqual(len(pc2.getReceivers()), 1)
self.assertEqual(len(pc2.getSenders()), 1)
self.assertEqual(len(pc2.getTransceivers()), 1)
self.assertEqual(mids(pc2), ["0"])
# the RemoteStreamTrack should have the same ID as the source track
self.assertEqual(len(pc2_tracks), 1)
self.assertEqual(pc2_tracks[0].id, track1.id)
# create answer
track2 = AudioStreamTrack()
pc2.addTrack(track2)
answer = await pc2.createAnswer()
self.assertEqual(answer.type, "answer")
self.assertTrue("m=audio " in answer.sdp)
self.assertFalse("a=candidate:" in answer.sdp)
self.assertFalse("a=end-of-candidates" in answer.sdp)
await pc2.setLocalDescription(answer)
await self.assertIceChecking(pc2)
self.assertEqual(mids(pc2), ["0"])
self.assertTrue("m=audio " in pc2.localDescription.sdp)
self.assertTrue(
lf2crlf(
"""a=rtpmap:96 opus/48000/2
a=rtpmap:0 PCMU/8000
a=rtpmap:8 PCMA/8000
"""
)
in pc2.localDescription.sdp
)
self.assertTrue("a=sendrecv" in pc2.localDescription.sdp)
self.assertHasIceCandidates(pc2.localDescription)
self.assertHasDtls(pc2.localDescription, "active")
self.assertEqual(pc2.getTransceivers()[0].currentDirection, "sendrecv")
self.assertEqual(pc2.getTransceivers()[0].direction, "sendrecv")
# handle answer
await pc1.setRemoteDescription(pc2.localDescription)
self.assertEqual(pc1.remoteDescription, pc2.localDescription)
self.assertEqual(pc1.getTransceivers()[0].currentDirection, "sendrecv")
self.assertEqual(pc1.getTransceivers()[0].direction, "sendrecv")
# the RemoteStreamTrack should have the same ID as the source track
self.assertEqual(len(pc1_tracks), 1)
self.assertEqual(pc1_tracks[0].id, track2.id)
# check outcome
await self.assertIceCompleted(pc1, pc2)
# allow media to flow long enough to collect stats
await asyncio.sleep(2)
# check stats
report = await pc1.getStats()
self.assertIsInstance(report, RTCStatsReport)
self.assertEqual(
sorted([s.type for s in report.values()]),
[
"inbound-rtp",
"outbound-rtp",
"remote-inbound-rtp",
"remote-outbound-rtp",
"transport",
],
)
# close
await pc1.close()
await pc2.close()
self.assertClosed(pc1)
self.assertClosed(pc2)
# check state changes
self.assertEqual(
pc1_states["connectionState"], ["new", "connecting", "connected", "closed"]
)
self.assertEqual(
pc1_states["iceConnectionState"], ["new", "checking", "completed", "closed"]
)
self.assertEqual(
pc1_states["iceGatheringState"], ["new", "gathering", "complete"]
)
self.assertEqual(
pc1_states["signalingState"],
["stable", "have-local-offer", "stable", "closed"],
)
self.assertEqual(
pc2_states["connectionState"], ["new", "connecting", "connected", "closed"]
)
self.assertEqual(
pc2_states["iceConnectionState"], ["new", "checking", "completed", "closed"]
)
self.assertEqual(
pc2_states["iceGatheringState"], ["new", "gathering", "complete"]
)
self.assertEqual(
pc2_states["signalingState"],
["stable", "have-remote-offer", "stable", "closed"],
) | a=rtpmap:96 opus/48000/2
a=rtpmap:0 PCMU/8000
a=rtpmap:8 PCMA/8000 | _test_connect_audio_bidirectional | python | aiortc/aiortc | tests/test_rtcpeerconnection.py | https://github.com/aiortc/aiortc/blob/master/tests/test_rtcpeerconnection.py | BSD-3-Clause |
async def test_connect_audio_codec_preferences_offerer(self):
pc1 = RTCPeerConnection()
pc1_states = track_states(pc1)
pc2 = RTCPeerConnection()
pc2_states = track_states(pc2)
self.assertEqual(pc1.iceConnectionState, "new")
self.assertEqual(pc1.iceGatheringState, "new")
self.assertIsNone(pc1.localDescription)
self.assertIsNone(pc1.remoteDescription)
self.assertEqual(pc2.iceConnectionState, "new")
self.assertEqual(pc2.iceGatheringState, "new")
self.assertIsNone(pc2.localDescription)
self.assertIsNone(pc2.remoteDescription)
# add track and set codec preferences to prefer PCMA / PCMU
pc1.addTrack(AudioStreamTrack())
capabilities = RTCRtpSender.getCapabilities("audio")
preferences = list(filter(lambda x: x.name == "PCMA", capabilities.codecs))
preferences += list(filter(lambda x: x.name == "PCMU", capabilities.codecs))
transceiver = pc1.getTransceivers()[0]
transceiver.setCodecPreferences(preferences)
# create offer
offer = await pc1.createOffer()
self.assertEqual(offer.type, "offer")
self.assertTrue("m=audio " in offer.sdp)
self.assertFalse("a=candidate:" in offer.sdp)
self.assertFalse("a=end-of-candidates" in offer.sdp)
await pc1.setLocalDescription(offer)
self.assertEqual(pc1.iceConnectionState, "new")
self.assertEqual(pc1.iceGatheringState, "complete")
self.assertEqual(mids(pc1), ["0"])
self.assertTrue("m=audio " in pc1.localDescription.sdp)
self.assertTrue(
lf2crlf(
"""a=rtpmap:8 PCMA/8000
a=rtpmap:0 PCMU/8000
"""
)
in pc1.localDescription.sdp
)
self.assertTrue("a=sendrecv" in pc1.localDescription.sdp)
self.assertHasIceCandidates(pc1.localDescription)
self.assertHasDtls(pc1.localDescription, "actpass")
# handle offer
await pc2.setRemoteDescription(pc1.localDescription)
self.assertEqual(pc2.remoteDescription, pc1.localDescription)
self.assertEqual(len(pc2.getReceivers()), 1)
self.assertEqual(len(pc2.getSenders()), 1)
self.assertEqual(len(pc2.getTransceivers()), 1)
self.assertEqual(mids(pc2), ["0"])
# create answer
pc2.addTrack(AudioStreamTrack())
answer = await pc2.createAnswer()
self.assertEqual(answer.type, "answer")
self.assertTrue("m=audio " in answer.sdp)
self.assertFalse("a=candidate:" in answer.sdp)
self.assertFalse("a=end-of-candidates" in answer.sdp)
await pc2.setLocalDescription(answer)
await self.assertIceChecking(pc2)
self.assertEqual(mids(pc2), ["0"])
self.assertTrue("m=audio " in pc2.localDescription.sdp)
self.assertTrue(
lf2crlf(
"""a=rtpmap:8 PCMA/8000
a=rtpmap:0 PCMU/8000
"""
)
in pc2.localDescription.sdp
)
self.assertTrue("a=sendrecv" in pc2.localDescription.sdp)
self.assertHasIceCandidates(pc2.localDescription)
self.assertHasDtls(pc2.localDescription, "active")
self.assertEqual(pc2.getTransceivers()[0].currentDirection, "sendrecv")
self.assertEqual(pc2.getTransceivers()[0].direction, "sendrecv")
# handle answer
await pc1.setRemoteDescription(pc2.localDescription)
self.assertEqual(pc1.remoteDescription, pc2.localDescription)
self.assertEqual(pc1.getTransceivers()[0].currentDirection, "sendrecv")
self.assertEqual(pc1.getTransceivers()[0].direction, "sendrecv")
# check outcome
await self.assertIceCompleted(pc1, pc2)
# allow media to flow long enough to collect stats
await asyncio.sleep(2)
# check stats
report = await pc1.getStats()
self.assertIsInstance(report, RTCStatsReport)
self.assertEqual(
sorted([s.type for s in report.values()]),
[
"inbound-rtp",
"outbound-rtp",
"remote-inbound-rtp",
"remote-outbound-rtp",
"transport",
],
)
# close
await pc1.close()
await pc2.close()
self.assertClosed(pc1)
self.assertClosed(pc2)
# check state changes
self.assertEqual(
pc1_states["connectionState"], ["new", "connecting", "connected", "closed"]
)
self.assertEqual(
pc1_states["iceConnectionState"], ["new", "checking", "completed", "closed"]
)
self.assertEqual(
pc1_states["iceGatheringState"], ["new", "gathering", "complete"]
)
self.assertEqual(
pc1_states["signalingState"],
["stable", "have-local-offer", "stable", "closed"],
)
self.assertEqual(
pc2_states["connectionState"], ["new", "connecting", "connected", "closed"]
)
self.assertEqual(
pc2_states["iceConnectionState"], ["new", "checking", "completed", "closed"]
)
self.assertEqual(
pc2_states["iceGatheringState"], ["new", "gathering", "complete"]
)
self.assertEqual(
pc2_states["signalingState"],
["stable", "have-remote-offer", "stable", "closed"],
) | a=rtpmap:8 PCMA/8000
a=rtpmap:0 PCMU/8000 | test_connect_audio_codec_preferences_offerer | python | aiortc/aiortc | tests/test_rtcpeerconnection.py | https://github.com/aiortc/aiortc/blob/master/tests/test_rtcpeerconnection.py | BSD-3-Clause |
async def _test_connect_audio_and_video_mediaplayer(self, stop_tracks: bool):
"""
Negotiate bidirectional audio + video, with one party reading media from a file.
We can optionally stop the media tracks before closing the peer connections.
"""
media_test = MediaTestCase()
media_test.setUp()
media_path = media_test.create_audio_and_video_file(name="test.mp4", duration=5)
player = MediaPlayer(media_path)
pc1 = RTCPeerConnection()
pc1_states = track_states(pc1)
pc2 = RTCPeerConnection()
pc2_states = track_states(pc2)
self.assertEqual(pc1.iceConnectionState, "new")
self.assertEqual(pc1.iceGatheringState, "new")
self.assertIsNone(pc1.localDescription)
self.assertIsNone(pc1.remoteDescription)
self.assertEqual(pc2.iceConnectionState, "new")
self.assertEqual(pc2.iceGatheringState, "new")
self.assertIsNone(pc2.localDescription)
self.assertIsNone(pc2.remoteDescription)
# create offer
pc1.addTrack(player.audio)
pc1.addTrack(player.video)
offer = await pc1.createOffer()
self.assertEqual(offer.type, "offer")
self.assertTrue("m=audio " in offer.sdp)
self.assertTrue("m=video " in offer.sdp)
await pc1.setLocalDescription(offer)
self.assertEqual(pc1.iceConnectionState, "new")
self.assertEqual(pc1.iceGatheringState, "complete")
self.assertEqual(mids(pc1), ["0", "1"])
# handle offer
await pc2.setRemoteDescription(pc1.localDescription)
self.assertEqual(pc2.remoteDescription, pc1.localDescription)
self.assertEqual(len(pc2.getReceivers()), 2)
self.assertEqual(len(pc2.getSenders()), 2)
self.assertEqual(len(pc2.getTransceivers()), 2)
self.assertEqual(mids(pc2), ["0", "1"])
# create answer
pc2.addTrack(AudioStreamTrack())
pc2.addTrack(VideoStreamTrack())
answer = await pc2.createAnswer()
self.assertEqual(answer.type, "answer")
self.assertTrue("m=audio " in answer.sdp)
self.assertTrue("m=video " in answer.sdp)
await pc2.setLocalDescription(answer)
await self.assertIceChecking(pc2)
self.assertTrue("m=audio " in pc2.localDescription.sdp)
self.assertTrue("m=video " in pc2.localDescription.sdp)
# handle answer
await pc1.setRemoteDescription(pc2.localDescription)
self.assertEqual(pc1.remoteDescription, pc2.localDescription)
# check outcome
await self.assertIceCompleted(pc1, pc2)
# check a single transport is used
self.assertBundled(pc1)
self.assertBundled(pc2)
# let media flow
await asyncio.sleep(1)
# stop tracks
if stop_tracks:
player.audio.stop()
player.video.stop()
# close
await pc1.close()
await pc2.close()
self.assertClosed(pc1)
self.assertClosed(pc2)
# check state changes
self.assertEqual(
pc1_states["connectionState"], ["new", "connecting", "connected", "closed"]
)
self.assertEqual(
pc1_states["iceConnectionState"], ["new", "checking", "completed", "closed"]
)
self.assertEqual(
pc1_states["iceGatheringState"], ["new", "gathering", "complete"]
)
self.assertEqual(
pc1_states["signalingState"],
["stable", "have-local-offer", "stable", "closed"],
)
self.assertEqual(
pc2_states["connectionState"], ["new", "connecting", "connected", "closed"]
)
self.assertEqual(
pc2_states["iceConnectionState"], ["new", "checking", "completed", "closed"]
)
self.assertEqual(
pc2_states["iceGatheringState"], ["new", "gathering", "complete"]
)
self.assertEqual(
pc2_states["signalingState"],
["stable", "have-remote-offer", "stable", "closed"],
)
media_test.tearDown() | Negotiate bidirectional audio + video, with one party reading media from a file.
We can optionally stop the media tracks before closing the peer connections. | _test_connect_audio_and_video_mediaplayer | python | aiortc/aiortc | tests/test_rtcpeerconnection.py | https://github.com/aiortc/aiortc/blob/master/tests/test_rtcpeerconnection.py | BSD-3-Clause |
async def test_setRemoteDescription_media_datachannel_bundled(self):
pc1 = RTCPeerConnection()
pc2 = RTCPeerConnection()
pc1_states = track_states(pc1)
pc2_states = track_states(pc2)
self.assertEqual(pc1.iceConnectionState, "new")
self.assertEqual(pc1.iceGatheringState, "new")
self.assertIsNone(pc1.localDescription)
self.assertIsNone(pc1.remoteDescription)
self.assertEqual(pc2.iceConnectionState, "new")
self.assertEqual(pc2.iceGatheringState, "new")
self.assertIsNone(pc2.localDescription)
self.assertIsNone(pc2.remoteDescription)
"""
initial negotiation
"""
# create offer
pc1.addTrack(AudioStreamTrack())
pc1.createDataChannel("chat", protocol="")
offer = await pc1.createOffer()
self.assertEqual(offer.type, "offer")
await pc1.setLocalDescription(offer)
self.assertEqual(pc1.iceConnectionState, "new")
self.assertEqual(pc1.iceGatheringState, "complete")
self.assertEqual(mids(pc1), ["0", "1"])
self.assertTrue("a=group:BUNDLE 0 1" in pc1.localDescription.sdp)
self.assertTrue("m=audio " in pc1.localDescription.sdp)
# handle offer
await pc2.setRemoteDescription(pc1.localDescription)
self.assertEqual(pc2.remoteDescription, pc1.localDescription)
self.assertEqual(len(pc2.getReceivers()), 1)
self.assertEqual(len(pc2.getSenders()), 1)
self.assertEqual(len(pc2.getTransceivers()), 1)
self.assertEqual(mids(pc2), ["0", "1"])
# create answer
answer = await pc2.createAnswer()
self.assertEqual(answer.type, "answer")
self.assertTrue("a=group:BUNDLE 0 1" in answer.sdp)
self.assertTrue("m=audio " in answer.sdp)
self.assertTrue("m=application " in answer.sdp)
await pc2.setLocalDescription(answer)
await self.assertIceChecking(pc2)
self.assertEqual(mids(pc2), ["0", "1"])
self.assertTrue("a=group:BUNDLE 0 1" in pc2.localDescription.sdp)
self.assertTrue("m=audio " in pc2.localDescription.sdp)
self.assertTrue("m=application " in pc2.localDescription.sdp)
# handle answer
await pc1.setRemoteDescription(pc2.localDescription)
self.assertEqual(pc1.remoteDescription, pc2.localDescription)
# check outcome
await self.assertIceCompleted(pc1, pc2)
"""
renegotiation
"""
# create offer
offer = await pc1.createOffer()
self.assertEqual(offer.type, "offer")
await pc1.setLocalDescription(offer)
self.assertEqual(pc1.iceConnectionState, "completed")
self.assertEqual(pc1.iceGatheringState, "complete")
self.assertEqual(mids(pc1), ["0", "1"])
self.assertTrue("a=group:BUNDLE 0 1" in pc1.localDescription.sdp)
self.assertTrue("m=audio " in pc1.localDescription.sdp)
self.assertTrue("m=application " in pc1.localDescription.sdp)
self.assertHasDtls(pc1.localDescription, "actpass")
# handle offer
await pc2.setRemoteDescription(pc1.localDescription)
self.assertEqual(pc2.remoteDescription, pc1.localDescription)
self.assertEqual(len(pc2.getReceivers()), 1)
self.assertEqual(len(pc2.getSenders()), 1)
self.assertEqual(len(pc2.getTransceivers()), 1)
self.assertEqual(mids(pc2), ["0", "1"])
# create answer
answer = await pc2.createAnswer()
self.assertEqual(answer.type, "answer")
self.assertTrue("a=group:BUNDLE 0 1" in answer.sdp)
self.assertTrue("m=audio " in answer.sdp)
self.assertTrue("m=application " in answer.sdp)
await pc2.setLocalDescription(answer)
self.assertEqual(pc2.iceConnectionState, "completed")
self.assertEqual(pc2.iceGatheringState, "complete")
self.assertEqual(mids(pc2), ["0", "1"])
self.assertTrue("a=group:BUNDLE 0 1" in pc2.localDescription.sdp)
self.assertTrue("m=audio " in pc2.localDescription.sdp)
self.assertTrue("m=application " in pc2.localDescription.sdp)
self.assertHasDtls(pc2.localDescription, "active")
# handle answer
await pc1.setRemoteDescription(pc2.localDescription)
self.assertEqual(pc1.remoteDescription, pc2.localDescription)
self.assertEqual(pc1.iceConnectionState, "completed")
# allow media to flow long enough to collect stats
await asyncio.sleep(2)
# close
await pc1.close()
await pc2.close()
self.assertClosed(pc1)
self.assertClosed(pc2)
# check state changes
self.assertEqual(
pc1_states["connectionState"], ["new", "connecting", "connected", "closed"]
)
self.assertEqual(
pc1_states["iceConnectionState"], ["new", "checking", "completed", "closed"]
)
self.assertEqual(
pc1_states["iceGatheringState"], ["new", "gathering", "complete"]
)
self.assertEqual(
pc1_states["signalingState"],
[
"stable",
"have-local-offer",
"stable",
"have-local-offer",
"stable",
"closed",
],
)
self.assertEqual(
pc2_states["connectionState"], ["new", "connecting", "connected", "closed"]
)
self.assertEqual(
pc2_states["iceConnectionState"], ["new", "checking", "completed", "closed"]
)
self.assertEqual(
pc2_states["iceGatheringState"], ["new", "gathering", "complete"]
)
self.assertEqual(
pc2_states["signalingState"],
[
"stable",
"have-remote-offer",
"stable",
"have-remote-offer",
"stable",
"closed",
],
) | initial negotiation | test_setRemoteDescription_media_datachannel_bundled | python | aiortc/aiortc | tests/test_rtcpeerconnection.py | https://github.com/aiortc/aiortc/blob/master/tests/test_rtcpeerconnection.py | BSD-3-Clause |
async def test_connect_broken_transport(self):
"""
Transport with 100% loss never connects.
"""
loss_pattern = [True]
async with client_and_server() as (client, server):
client._rto = 0.1
client.transport.transport._connection.loss_pattern = loss_pattern
server._rto = 0.1
server.transport.transport._connection.loss_pattern = loss_pattern
# connect
await server.start(client.getCapabilities(), client.port)
await client.start(server.getCapabilities(), server.port)
# check outcome
await wait_for_outcome(client, server)
self.assertEqual(client._association_state, RTCSctpTransport.State.CLOSED)
self.assertEqual(client.state, "closed")
self.assertEqual(server._association_state, RTCSctpTransport.State.CLOSED)
self.assertEqual(server.state, "connecting") | Transport with 100% loss never connects. | test_connect_broken_transport | python | aiortc/aiortc | tests/test_rtcsctptransport.py | https://github.com/aiortc/aiortc/blob/master/tests/test_rtcsctptransport.py | BSD-3-Clause |
async def test_connect_lossy_transport(self):
"""
Transport with 25% loss eventually connects.
"""
loss_pattern = [True, False, False, False]
async with client_and_server() as (client, server):
client._rto = 0.1
client.transport.transport._connection.loss_pattern = loss_pattern
server._rto = 0.1
server.transport.transport._connection.loss_pattern = loss_pattern
# connect
await server.start(client.getCapabilities(), client.port)
await client.start(server.getCapabilities(), server.port)
# check outcome
await wait_for_outcome(client, server)
self.assertEqual(
client._association_state, RTCSctpTransport.State.ESTABLISHED
)
self.assertEqual(client.state, "connected")
self.assertEqual(
server._association_state, RTCSctpTransport.State.ESTABLISHED
)
self.assertEqual(server.state, "connected")
# transmit data
server_queue = asyncio.Queue()
async def server_fake_receive(*args):
await server_queue.put(args)
server._receive = server_fake_receive
for i in range(20):
message = (123, i, b"ping")
await client._send(*message)
received = await server_queue.get()
self.assertEqual(received, message) | Transport with 25% loss eventually connects. | test_connect_lossy_transport | python | aiortc/aiortc | tests/test_rtcsctptransport.py | https://github.com/aiortc/aiortc/blob/master/tests/test_rtcsctptransport.py | BSD-3-Clause |
async def test_abrupt_disconnect(self):
"""
Abrupt disconnect causes sending ABORT chunk to fail.
"""
async with client_and_server() as (client, server):
# connect
await server.start(client.getCapabilities(), client.port)
await client.start(server.getCapabilities(), server.port)
# check outcome
await wait_for_outcome(client, server)
self.assertEqual(
client._association_state, RTCSctpTransport.State.ESTABLISHED
)
self.assertEqual(
server._association_state, RTCSctpTransport.State.ESTABLISHED
)
# break connection
await client.transport.stop()
await server.transport.stop()
await asyncio.sleep(0) # FIXME | Abrupt disconnect causes sending ABORT chunk to fail. | test_abrupt_disconnect | python | aiortc/aiortc | tests/test_rtcsctptransport.py | https://github.com/aiortc/aiortc/blob/master/tests/test_rtcsctptransport.py | BSD-3-Clause |
def test_audio_chrome(self):
d = SessionDescription.parse(
lf2crlf(
"""v=0
o=- 863426017819471768 2 IN IP4 127.0.0.1
s=-
t=0 0
a=group:BUNDLE audio
a=msid-semantic: WMS TF6VRif1dxuAfe5uefrV2953LhUZt1keYvxU
m=audio 45076 UDP/TLS/RTP/SAVPF 111 103 104 9 0 8 106 105 13 110 112 113 126
c=IN IP4 192.168.99.58
a=rtcp:9 IN IP4 0.0.0.0
a=candidate:2665802302 1 udp 2122262783 2a02:a03f:3eb0:e000:b0aa:d60a:cff2:933c 38475 typ host generation 0 network-id 2 network-cost 10
a=candidate:1039001212 1 udp 2122194687 192.168.99.58 45076 typ host generation 0 network-id 1 network-cost 10
a=candidate:3496416974 1 tcp 1518283007 2a02:a03f:3eb0:e000:b0aa:d60a:cff2:933c 9 typ host tcptype active generation 0 network-id 2 network-cost 10
a=candidate:1936595596 1 tcp 1518214911 192.168.99.58 9 typ host tcptype active generation 0 network-id 1 network-cost 10
a=ice-ufrag:5+Ix
a=ice-pwd:uK8IlylxzDMUhrkVzdmj0M+v
a=ice-options:trickle
a=fingerprint:sha-256 6B:8B:5D:EA:59:04:20:23:29:C8:87:1C:CC:87:32:BE:DD:8C:66:A5:8E:50:55:EA:8C:D3:B6:5C:09:5E:D6:BC
a=setup:actpass
a=mid:audio
a=extmap:1 urn:ietf:params:rtp-hdrext:ssrc-audio-level
a=sendrecv
a=rtcp-mux
a=rtpmap:111 opus/48000/2
a=rtcp-fb:111 transport-cc
a=fmtp:111 minptime=10;useinbandfec=1
a=rtpmap:103 ISAC/16000
a=rtpmap:104 ISAC/32000
a=rtpmap:9 G722/8000
a=rtpmap:0 PCMU/8000
a=rtpmap:8 PCMA/8000
a=rtpmap:106 CN/32000
a=rtpmap:105 CN/16000
a=rtpmap:13 CN/8000
a=rtpmap:110 telephone-event/48000
a=rtpmap:112 telephone-event/32000
a=rtpmap:113 telephone-event/16000
a=rtpmap:126 telephone-event/8000
a=ssrc:1944796561 cname:/vC4ULAr8vHNjXmq
a=ssrc:1944796561 msid:TF6VRif1dxuAfe5uefrV2953LhUZt1keYvxU ec1eb8de-8df8-4956-ae81-879e5d062d12
a=ssrc:1944796561 mslabel:TF6VRif1dxuAfe5uefrV2953LhUZt1keYvxU
a=ssrc:1944796561 label:ec1eb8de-8df8-4956-ae81-879e5d062d12"""
)
)
self.assertEqual(
d.group, [GroupDescription(semantic="BUNDLE", items=["audio"])]
)
self.assertEqual(
d.msid_semantic,
[
GroupDescription(
semantic="WMS", items=["TF6VRif1dxuAfe5uefrV2953LhUZt1keYvxU"]
)
],
)
self.assertEqual(d.host, None)
self.assertEqual(d.name, "-")
self.assertEqual(d.origin, "- 863426017819471768 2 IN IP4 127.0.0.1")
self.assertEqual(d.time, "0 0")
self.assertEqual(d.version, 0)
self.assertEqual(len(d.media), 1)
self.assertEqual(d.media[0].kind, "audio")
self.assertEqual(d.media[0].host, "192.168.99.58")
self.assertEqual(d.media[0].port, 45076)
self.assertEqual(d.media[0].profile, "UDP/TLS/RTP/SAVPF")
self.assertEqual(d.media[0].direction, "sendrecv")
self.assertEqual(d.media[0].msid, None)
self.assertEqual(
d.media[0].rtp.codecs,
[
RTCRtpCodecParameters(
mimeType="audio/opus",
clockRate=48000,
channels=2,
payloadType=111,
rtcpFeedback=[RTCRtcpFeedback(type="transport-cc")],
parameters={"minptime": 10, "useinbandfec": 1},
),
RTCRtpCodecParameters(
mimeType="audio/ISAC", clockRate=16000, channels=1, payloadType=103
),
RTCRtpCodecParameters(
mimeType="audio/ISAC", clockRate=32000, channels=1, payloadType=104
),
RTCRtpCodecParameters(
mimeType="audio/G722", clockRate=8000, channels=1, payloadType=9
),
RTCRtpCodecParameters(
mimeType="audio/PCMU", clockRate=8000, channels=1, payloadType=0
),
RTCRtpCodecParameters(
mimeType="audio/PCMA", clockRate=8000, channels=1, payloadType=8
),
RTCRtpCodecParameters(
mimeType="audio/CN", clockRate=32000, channels=1, payloadType=106
),
RTCRtpCodecParameters(
mimeType="audio/CN", clockRate=16000, channels=1, payloadType=105
),
RTCRtpCodecParameters(
mimeType="audio/CN", clockRate=8000, channels=1, payloadType=13
),
RTCRtpCodecParameters(
mimeType="audio/telephone-event",
clockRate=48000,
channels=1,
payloadType=110,
),
RTCRtpCodecParameters(
mimeType="audio/telephone-event",
clockRate=32000,
channels=1,
payloadType=112,
),
RTCRtpCodecParameters(
mimeType="audio/telephone-event",
clockRate=16000,
channels=1,
payloadType=113,
),
RTCRtpCodecParameters(
mimeType="audio/telephone-event",
clockRate=8000,
channels=1,
payloadType=126,
),
],
)
self.assertEqual(
d.media[0].rtp.headerExtensions,
[
RTCRtpHeaderExtensionParameters(
id=1, uri="urn:ietf:params:rtp-hdrext:ssrc-audio-level"
)
],
)
self.assertEqual(d.media[0].rtp.muxId, "audio")
self.assertEqual(d.media[0].rtcp_host, "0.0.0.0")
self.assertEqual(d.media[0].rtcp_port, 9)
self.assertEqual(d.media[0].rtcp_mux, True)
# ssrc
self.assertEqual(
d.media[0].ssrc,
[
SsrcDescription(
ssrc=1944796561,
cname="/vC4ULAr8vHNjXmq",
msid="TF6VRif1dxuAfe5uefrV2953LhUZt1keYvxU ec1eb8de-8df8-4956-ae81-879e5d062d12",
mslabel="TF6VRif1dxuAfe5uefrV2953LhUZt1keYvxU",
label="ec1eb8de-8df8-4956-ae81-879e5d062d12",
)
],
)
self.assertEqual(d.media[0].ssrc_group, [])
# formats
self.assertEqual(
d.media[0].fmt, [111, 103, 104, 9, 0, 8, 106, 105, 13, 110, 112, 113, 126]
)
self.assertEqual(d.media[0].sctpmap, {})
self.assertEqual(d.media[0].sctp_port, None)
# ice
self.assertEqual(len(d.media[0].ice_candidates), 4)
self.assertEqual(d.media[0].ice_candidates_complete, False)
self.assertEqual(d.media[0].ice_options, "trickle")
self.assertEqual(d.media[0].ice.iceLite, False)
self.assertEqual(d.media[0].ice.usernameFragment, "5+Ix")
self.assertEqual(d.media[0].ice.password, "uK8IlylxzDMUhrkVzdmj0M+v")
# dtls
self.assertEqual(len(d.media[0].dtls.fingerprints), 1)
self.assertEqual(d.media[0].dtls.fingerprints[0].algorithm, "sha-256")
self.assertEqual(
d.media[0].dtls.fingerprints[0].value,
"6B:8B:5D:EA:59:04:20:23:29:C8:87:1C:CC:87:32:BE:DD:8C:66:A5:8E:50:55:EA:8C:D3:B6:5C:09:5E:D6:BC",
)
self.assertEqual(d.media[0].dtls.role, "auto")
self.assertEqual(
str(d),
lf2crlf(
"""v=0
o=- 863426017819471768 2 IN IP4 127.0.0.1
s=-
t=0 0
a=group:BUNDLE audio
a=msid-semantic:WMS TF6VRif1dxuAfe5uefrV2953LhUZt1keYvxU
m=audio 45076 UDP/TLS/RTP/SAVPF 111 103 104 9 0 8 106 105 13 110 112 113 126
c=IN IP4 192.168.99.58
a=sendrecv
a=extmap:1 urn:ietf:params:rtp-hdrext:ssrc-audio-level
a=mid:audio
a=rtcp:9 IN IP4 0.0.0.0
a=rtcp-mux
a=ssrc:1944796561 cname:/vC4ULAr8vHNjXmq
a=ssrc:1944796561 msid:TF6VRif1dxuAfe5uefrV2953LhUZt1keYvxU ec1eb8de-8df8-4956-ae81-879e5d062d12
a=ssrc:1944796561 mslabel:TF6VRif1dxuAfe5uefrV2953LhUZt1keYvxU
a=ssrc:1944796561 label:ec1eb8de-8df8-4956-ae81-879e5d062d12
a=rtpmap:111 opus/48000/2
a=rtcp-fb:111 transport-cc
a=fmtp:111 minptime=10;useinbandfec=1
a=rtpmap:103 ISAC/16000
a=rtpmap:104 ISAC/32000
a=rtpmap:9 G722/8000
a=rtpmap:0 PCMU/8000
a=rtpmap:8 PCMA/8000
a=rtpmap:106 CN/32000
a=rtpmap:105 CN/16000
a=rtpmap:13 CN/8000
a=rtpmap:110 telephone-event/48000
a=rtpmap:112 telephone-event/32000
a=rtpmap:113 telephone-event/16000
a=rtpmap:126 telephone-event/8000
a=candidate:2665802302 1 udp 2122262783 2a02:a03f:3eb0:e000:b0aa:d60a:cff2:933c 38475 typ host
a=candidate:1039001212 1 udp 2122194687 192.168.99.58 45076 typ host
a=candidate:3496416974 1 tcp 1518283007 2a02:a03f:3eb0:e000:b0aa:d60a:cff2:933c 9 typ host tcptype active
a=candidate:1936595596 1 tcp 1518214911 192.168.99.58 9 typ host tcptype active
a=ice-ufrag:5+Ix
a=ice-pwd:uK8IlylxzDMUhrkVzdmj0M+v
a=ice-options:trickle
a=fingerprint:sha-256 6B:8B:5D:EA:59:04:20:23:29:C8:87:1C:CC:87:32:BE:DD:8C:66:A5:8E:50:55:EA:8C:D3:B6:5C:09:5E:D6:BC
a=setup:actpass
"""
),
) | v=0
o=- 863426017819471768 2 IN IP4 127.0.0.1
s=-
t=0 0
a=group:BUNDLE audio
a=msid-semantic: WMS TF6VRif1dxuAfe5uefrV2953LhUZt1keYvxU
m=audio 45076 UDP/TLS/RTP/SAVPF 111 103 104 9 0 8 106 105 13 110 112 113 126
c=IN IP4 192.168.99.58
a=rtcp:9 IN IP4 0.0.0.0
a=candidate:2665802302 1 udp 2122262783 2a02:a03f:3eb0:e000:b0aa:d60a:cff2:933c 38475 typ host generation 0 network-id 2 network-cost 10
a=candidate:1039001212 1 udp 2122194687 192.168.99.58 45076 typ host generation 0 network-id 1 network-cost 10
a=candidate:3496416974 1 tcp 1518283007 2a02:a03f:3eb0:e000:b0aa:d60a:cff2:933c 9 typ host tcptype active generation 0 network-id 2 network-cost 10
a=candidate:1936595596 1 tcp 1518214911 192.168.99.58 9 typ host tcptype active generation 0 network-id 1 network-cost 10
a=ice-ufrag:5+Ix
a=ice-pwd:uK8IlylxzDMUhrkVzdmj0M+v
a=ice-options:trickle
a=fingerprint:sha-256 6B:8B:5D:EA:59:04:20:23:29:C8:87:1C:CC:87:32:BE:DD:8C:66:A5:8E:50:55:EA:8C:D3:B6:5C:09:5E:D6:BC
a=setup:actpass
a=mid:audio
a=extmap:1 urn:ietf:params:rtp-hdrext:ssrc-audio-level
a=sendrecv
a=rtcp-mux
a=rtpmap:111 opus/48000/2
a=rtcp-fb:111 transport-cc
a=fmtp:111 minptime=10;useinbandfec=1
a=rtpmap:103 ISAC/16000
a=rtpmap:104 ISAC/32000
a=rtpmap:9 G722/8000
a=rtpmap:0 PCMU/8000
a=rtpmap:8 PCMA/8000
a=rtpmap:106 CN/32000
a=rtpmap:105 CN/16000
a=rtpmap:13 CN/8000
a=rtpmap:110 telephone-event/48000
a=rtpmap:112 telephone-event/32000
a=rtpmap:113 telephone-event/16000
a=rtpmap:126 telephone-event/8000
a=ssrc:1944796561 cname:/vC4ULAr8vHNjXmq
a=ssrc:1944796561 msid:TF6VRif1dxuAfe5uefrV2953LhUZt1keYvxU ec1eb8de-8df8-4956-ae81-879e5d062d12
a=ssrc:1944796561 mslabel:TF6VRif1dxuAfe5uefrV2953LhUZt1keYvxU
a=ssrc:1944796561 label:ec1eb8de-8df8-4956-ae81-879e5d062d12 | test_audio_chrome | python | aiortc/aiortc | tests/test_sdp.py | https://github.com/aiortc/aiortc/blob/master/tests/test_sdp.py | BSD-3-Clause |
def test_audio_firefox(self):
d = SessionDescription.parse(
lf2crlf(
"""v=0
o=mozilla...THIS_IS_SDPARTA-58.0.1 4934139885953732403 1 IN IP4 0.0.0.0
s=-
t=0 0
a=sendrecv
a=fingerprint:sha-256 EB:A9:3E:50:D7:E3:B3:86:0F:7B:01:C1:EB:D6:AF:E4:97:DE:15:05:A8:DE:7B:83:56:C7:4B:6E:9D:75:D4:17
a=group:BUNDLE sdparta_0
a=ice-options:trickle
a=msid-semantic:WMS *
m=audio 45274 UDP/TLS/RTP/SAVPF 109 9 0 8 101
c=IN IP4 192.168.99.58
a=candidate:0 1 UDP 2122187007 192.168.99.58 45274 typ host
a=candidate:2 1 UDP 2122252543 2a02:a03f:3eb0:e000:b0aa:d60a:cff2:933c 47387 typ host
a=candidate:3 1 TCP 2105458943 192.168.99.58 9 typ host tcptype active
a=candidate:4 1 TCP 2105524479 2a02:a03f:3eb0:e000:b0aa:d60a:cff2:933c 9 typ host tcptype active
a=candidate:0 2 UDP 2122187006 192.168.99.58 38612 typ host
a=candidate:2 2 UDP 2122252542 2a02:a03f:3eb0:e000:b0aa:d60a:cff2:933c 54301 typ host
a=candidate:3 2 TCP 2105458942 192.168.99.58 9 typ host tcptype active
a=candidate:4 2 TCP 2105524478 2a02:a03f:3eb0:e000:b0aa:d60a:cff2:933c 9 typ host tcptype active
a=candidate:1 1 UDP 1685921791 1.2.3.4 37264 typ srflx raddr 192.168.99.58 rport 37264
a=candidate:1 2 UDP 1685921790 1.2.3.4 52902 typ srflx raddr 192.168.99.58 rport 52902
a=sendrecv
a=end-of-candidates
a=extmap:1/sendonly urn:ietf:params:rtp-hdrext:ssrc-audio-level
a=extmap:2 urn:ietf:params:rtp-hdrext:sdes:mid
a=fmtp:109 maxplaybackrate=48000;stereo=1;useinbandfec=1
a=fmtp:101 0-15
a=ice-pwd:f9b83487285016f7492197a5790ceee5
a=ice-ufrag:403a81e1
a=ice-options:trickle
a=mid:sdparta_0
a=msid:{dee771c7-671a-451e-b847-f86f8e87c7d8} {12692dea-686c-47ca-b3e9-48f38fc92b78}
a=rtcp:38612 IN IP4 192.168.99.58
a=rtcp-mux
a=rtpmap:109 opus/48000/2
a=rtpmap:9 G722/8000/1
a=rtpmap:0 PCMU/8000
a=rtpmap:8 PCMA/8000
a=rtpmap:101 telephone-event/8000
a=setup:actpass
a=ssrc:882128807 cname:{ed463ac5-dabf-44d4-8b9f-e14318427b2b}
"""
)
)
self.assertEqual(
d.group, [GroupDescription(semantic="BUNDLE", items=["sdparta_0"])]
)
self.assertEqual(
d.msid_semantic, [GroupDescription(semantic="WMS", items=["*"])]
)
self.assertEqual(d.host, None)
self.assertEqual(d.name, "-")
self.assertEqual(
d.origin,
"mozilla...THIS_IS_SDPARTA-58.0.1 4934139885953732403 1 IN IP4 0.0.0.0",
)
self.assertEqual(d.time, "0 0")
self.assertEqual(d.version, 0)
self.assertEqual(len(d.media), 1)
self.assertEqual(d.media[0].kind, "audio")
self.assertEqual(d.media[0].host, "192.168.99.58")
self.assertEqual(d.media[0].port, 45274)
self.assertEqual(d.media[0].profile, "UDP/TLS/RTP/SAVPF")
self.assertEqual(d.media[0].direction, "sendrecv")
self.assertEqual(
d.media[0].msid,
"{dee771c7-671a-451e-b847-f86f8e87c7d8} "
"{12692dea-686c-47ca-b3e9-48f38fc92b78}",
)
self.assertEqual(
d.media[0].rtp.codecs,
[
RTCRtpCodecParameters(
mimeType="audio/opus",
clockRate=48000,
channels=2,
payloadType=109,
parameters={
"maxplaybackrate": 48000,
"stereo": 1,
"useinbandfec": 1,
},
),
RTCRtpCodecParameters(
mimeType="audio/G722", clockRate=8000, channels=1, payloadType=9
),
RTCRtpCodecParameters(
mimeType="audio/PCMU", clockRate=8000, channels=1, payloadType=0
),
RTCRtpCodecParameters(
mimeType="audio/PCMA", clockRate=8000, channels=1, payloadType=8
),
RTCRtpCodecParameters(
mimeType="audio/telephone-event",
clockRate=8000,
channels=1,
payloadType=101,
parameters={"0-15": None},
),
],
)
self.assertEqual(
d.media[0].rtp.headerExtensions,
[
RTCRtpHeaderExtensionParameters(
id=1, uri="urn:ietf:params:rtp-hdrext:ssrc-audio-level"
),
RTCRtpHeaderExtensionParameters(
id=2, uri="urn:ietf:params:rtp-hdrext:sdes:mid"
),
],
)
self.assertEqual(d.media[0].rtp.muxId, "sdparta_0")
self.assertEqual(d.media[0].rtcp_host, "192.168.99.58")
self.assertEqual(d.media[0].rtcp_port, 38612)
self.assertEqual(d.media[0].rtcp_mux, True)
self.assertEqual(
d.webrtc_track_id(d.media[0]), "{12692dea-686c-47ca-b3e9-48f38fc92b78}"
)
# ssrc
self.assertEqual(
d.media[0].ssrc,
[
SsrcDescription(
ssrc=882128807, cname="{ed463ac5-dabf-44d4-8b9f-e14318427b2b}"
)
],
)
self.assertEqual(d.media[0].ssrc_group, [])
# formats
self.assertEqual(d.media[0].fmt, [109, 9, 0, 8, 101])
self.assertEqual(d.media[0].sctpmap, {})
self.assertEqual(d.media[0].sctp_port, None)
# ice
self.assertEqual(len(d.media[0].ice_candidates), 10)
self.assertEqual(d.media[0].ice_candidates_complete, True)
self.assertEqual(d.media[0].ice_options, "trickle")
self.assertEqual(d.media[0].ice.iceLite, False)
self.assertEqual(d.media[0].ice.usernameFragment, "403a81e1")
self.assertEqual(d.media[0].ice.password, "f9b83487285016f7492197a5790ceee5")
# dtls
self.assertEqual(len(d.media[0].dtls.fingerprints), 1)
self.assertEqual(d.media[0].dtls.fingerprints[0].algorithm, "sha-256")
self.assertEqual(
d.media[0].dtls.fingerprints[0].value,
"EB:A9:3E:50:D7:E3:B3:86:0F:7B:01:C1:EB:D6:AF:E4:97:DE:15:05:A8:DE:7B:83:56:C7:4B:6E:9D:75:D4:17",
)
self.assertEqual(d.media[0].dtls.role, "auto")
self.assertEqual(
str(d),
lf2crlf(
"""v=0
o=mozilla...THIS_IS_SDPARTA-58.0.1 4934139885953732403 1 IN IP4 0.0.0.0
s=-
t=0 0
a=group:BUNDLE sdparta_0
a=msid-semantic:WMS *
m=audio 45274 UDP/TLS/RTP/SAVPF 109 9 0 8 101
c=IN IP4 192.168.99.58
a=sendrecv
a=extmap:1 urn:ietf:params:rtp-hdrext:ssrc-audio-level
a=extmap:2 urn:ietf:params:rtp-hdrext:sdes:mid
a=mid:sdparta_0
a=msid:{dee771c7-671a-451e-b847-f86f8e87c7d8} {12692dea-686c-47ca-b3e9-48f38fc92b78}
a=rtcp:38612 IN IP4 192.168.99.58
a=rtcp-mux
a=ssrc:882128807 cname:{ed463ac5-dabf-44d4-8b9f-e14318427b2b}
a=rtpmap:109 opus/48000/2
a=fmtp:109 maxplaybackrate=48000;stereo=1;useinbandfec=1
a=rtpmap:9 G722/8000
a=rtpmap:0 PCMU/8000
a=rtpmap:8 PCMA/8000
a=rtpmap:101 telephone-event/8000
a=fmtp:101 0-15
a=candidate:0 1 UDP 2122187007 192.168.99.58 45274 typ host
a=candidate:2 1 UDP 2122252543 2a02:a03f:3eb0:e000:b0aa:d60a:cff2:933c 47387 typ host
a=candidate:3 1 TCP 2105458943 192.168.99.58 9 typ host tcptype active
a=candidate:4 1 TCP 2105524479 2a02:a03f:3eb0:e000:b0aa:d60a:cff2:933c 9 typ host tcptype active
a=candidate:0 2 UDP 2122187006 192.168.99.58 38612 typ host
a=candidate:2 2 UDP 2122252542 2a02:a03f:3eb0:e000:b0aa:d60a:cff2:933c 54301 typ host
a=candidate:3 2 TCP 2105458942 192.168.99.58 9 typ host tcptype active
a=candidate:4 2 TCP 2105524478 2a02:a03f:3eb0:e000:b0aa:d60a:cff2:933c 9 typ host tcptype active
a=candidate:1 1 UDP 1685921791 1.2.3.4 37264 typ srflx raddr 192.168.99.58 rport 37264
a=candidate:1 2 UDP 1685921790 1.2.3.4 52902 typ srflx raddr 192.168.99.58 rport 52902
a=end-of-candidates
a=ice-ufrag:403a81e1
a=ice-pwd:f9b83487285016f7492197a5790ceee5
a=ice-options:trickle
a=fingerprint:sha-256 EB:A9:3E:50:D7:E3:B3:86:0F:7B:01:C1:EB:D6:AF:E4:97:DE:15:05:A8:DE:7B:83:56:C7:4B:6E:9D:75:D4:17
a=setup:actpass
"""
),
) | v=0
o=mozilla...THIS_IS_SDPARTA-58.0.1 4934139885953732403 1 IN IP4 0.0.0.0
s=-
t=0 0
a=sendrecv
a=fingerprint:sha-256 EB:A9:3E:50:D7:E3:B3:86:0F:7B:01:C1:EB:D6:AF:E4:97:DE:15:05:A8:DE:7B:83:56:C7:4B:6E:9D:75:D4:17
a=group:BUNDLE sdparta_0
a=ice-options:trickle
a=msid-semantic:WMS *
m=audio 45274 UDP/TLS/RTP/SAVPF 109 9 0 8 101
c=IN IP4 192.168.99.58
a=candidate:0 1 UDP 2122187007 192.168.99.58 45274 typ host
a=candidate:2 1 UDP 2122252543 2a02:a03f:3eb0:e000:b0aa:d60a:cff2:933c 47387 typ host
a=candidate:3 1 TCP 2105458943 192.168.99.58 9 typ host tcptype active
a=candidate:4 1 TCP 2105524479 2a02:a03f:3eb0:e000:b0aa:d60a:cff2:933c 9 typ host tcptype active
a=candidate:0 2 UDP 2122187006 192.168.99.58 38612 typ host
a=candidate:2 2 UDP 2122252542 2a02:a03f:3eb0:e000:b0aa:d60a:cff2:933c 54301 typ host
a=candidate:3 2 TCP 2105458942 192.168.99.58 9 typ host tcptype active
a=candidate:4 2 TCP 2105524478 2a02:a03f:3eb0:e000:b0aa:d60a:cff2:933c 9 typ host tcptype active
a=candidate:1 1 UDP 1685921791 1.2.3.4 37264 typ srflx raddr 192.168.99.58 rport 37264
a=candidate:1 2 UDP 1685921790 1.2.3.4 52902 typ srflx raddr 192.168.99.58 rport 52902
a=sendrecv
a=end-of-candidates
a=extmap:1/sendonly urn:ietf:params:rtp-hdrext:ssrc-audio-level
a=extmap:2 urn:ietf:params:rtp-hdrext:sdes:mid
a=fmtp:109 maxplaybackrate=48000;stereo=1;useinbandfec=1
a=fmtp:101 0-15
a=ice-pwd:f9b83487285016f7492197a5790ceee5
a=ice-ufrag:403a81e1
a=ice-options:trickle
a=mid:sdparta_0
a=msid:{dee771c7-671a-451e-b847-f86f8e87c7d8} {12692dea-686c-47ca-b3e9-48f38fc92b78}
a=rtcp:38612 IN IP4 192.168.99.58
a=rtcp-mux
a=rtpmap:109 opus/48000/2
a=rtpmap:9 G722/8000/1
a=rtpmap:0 PCMU/8000
a=rtpmap:8 PCMA/8000
a=rtpmap:101 telephone-event/8000
a=setup:actpass
a=ssrc:882128807 cname:{ed463ac5-dabf-44d4-8b9f-e14318427b2b} | test_audio_firefox | python | aiortc/aiortc | tests/test_sdp.py | https://github.com/aiortc/aiortc/blob/master/tests/test_sdp.py | BSD-3-Clause |
def test_audio_freeswitch(self):
d = SessionDescription.parse(
lf2crlf(
"""v=0
o=FreeSWITCH 1538380016 1538380017 IN IP4 1.2.3.4
s=FreeSWITCH
c=IN IP4 1.2.3.4
t=0 0
a=msid-semantic: WMS lyNSTe6w2ijnMrDEiqTHFyhqjdAag3ys
m=audio 16628 UDP/TLS/RTP/SAVPF 8 101
a=rtpmap:8 PCMA/8000
a=rtpmap:101 telephone-event/8000
a=ptime:20
a=fingerprint:sha-256 35:5A:BC:8E:CD:F8:CD:EB:36:00:BB:C4:C3:33:54:B5:9B:70:3C:E9:C4:33:8F:39:3C:4B:5B:5C:AD:88:12:2B
a=setup:active
a=rtcp-mux
a=rtcp:16628 IN IP4 1.2.3.4
a=ice-ufrag:75EDuLTEOkEUd3cu
a=ice-pwd:5dvb9SbfooWc49814CupdeTS
a=candidate:0560693492 1 udp 659136 1.2.3.4 16628 typ host generation 0
a=end-of-candidates
a=ssrc:2690029308 cname:rbaag6w9fGmRXQm6
a=ssrc:2690029308 msid:lyNSTe6w2ijnMrDEiqTHFyhqjdAag3ys a0
a=ssrc:2690029308 mslabel:lyNSTe6w2ijnMrDEiqTHFyhqjdAag3ys
a=ssrc:2690029308 label:lyNSTe6w2ijnMrDEiqTHFyhqjdAag3ysa0"""
)
)
self.assertEqual(d.group, [])
self.assertEqual(
d.msid_semantic,
[
GroupDescription(
semantic="WMS", items=["lyNSTe6w2ijnMrDEiqTHFyhqjdAag3ys"]
)
],
)
self.assertEqual(d.host, "1.2.3.4")
self.assertEqual(d.name, "FreeSWITCH")
self.assertEqual(d.origin, "FreeSWITCH 1538380016 1538380017 IN IP4 1.2.3.4")
self.assertEqual(d.time, "0 0")
self.assertEqual(d.version, 0)
self.assertEqual(len(d.media), 1)
self.assertEqual(d.media[0].kind, "audio")
self.assertEqual(d.media[0].host, None)
self.assertEqual(d.media[0].port, 16628)
self.assertEqual(d.media[0].profile, "UDP/TLS/RTP/SAVPF")
self.assertEqual(d.media[0].direction, None)
self.assertEqual(
d.media[0].rtp.codecs,
[
RTCRtpCodecParameters(
mimeType="audio/PCMA", clockRate=8000, channels=1, payloadType=8
),
RTCRtpCodecParameters(
mimeType="audio/telephone-event",
clockRate=8000,
channels=1,
payloadType=101,
),
],
)
self.assertEqual(d.media[0].rtp.headerExtensions, [])
self.assertEqual(d.media[0].rtp.muxId, "")
self.assertEqual(d.media[0].rtcp_host, "1.2.3.4")
self.assertEqual(d.media[0].rtcp_port, 16628)
self.assertEqual(d.media[0].rtcp_mux, True)
# ssrc
self.assertEqual(
d.media[0].ssrc,
[
SsrcDescription(
ssrc=2690029308,
cname="rbaag6w9fGmRXQm6",
msid="lyNSTe6w2ijnMrDEiqTHFyhqjdAag3ys a0",
mslabel="lyNSTe6w2ijnMrDEiqTHFyhqjdAag3ys",
label="lyNSTe6w2ijnMrDEiqTHFyhqjdAag3ysa0",
)
],
)
self.assertEqual(d.media[0].ssrc_group, [])
# formats
self.assertEqual(d.media[0].fmt, [8, 101])
self.assertEqual(d.media[0].sctpmap, {})
self.assertEqual(d.media[0].sctp_port, None)
# ice
self.assertEqual(len(d.media[0].ice_candidates), 1)
self.assertEqual(d.media[0].ice_candidates_complete, True)
self.assertEqual(d.media[0].ice_options, None)
self.assertEqual(d.media[0].ice.iceLite, False)
self.assertEqual(d.media[0].ice.usernameFragment, "75EDuLTEOkEUd3cu")
self.assertEqual(d.media[0].ice.password, "5dvb9SbfooWc49814CupdeTS")
# dtls
self.assertEqual(len(d.media[0].dtls.fingerprints), 1)
self.assertEqual(d.media[0].dtls.fingerprints[0].algorithm, "sha-256")
self.assertEqual(
d.media[0].dtls.fingerprints[0].value,
"35:5A:BC:8E:CD:F8:CD:EB:36:00:BB:C4:C3:33:54:B5:9B:70:3C:E9:C4:33:8F:39:3C:4B:5B:5C:AD:88:12:2B",
)
self.assertEqual(d.media[0].dtls.role, "client")
self.assertEqual(
str(d),
lf2crlf(
"""v=0
o=FreeSWITCH 1538380016 1538380017 IN IP4 1.2.3.4
s=FreeSWITCH
c=IN IP4 1.2.3.4
t=0 0
a=msid-semantic:WMS lyNSTe6w2ijnMrDEiqTHFyhqjdAag3ys
m=audio 16628 UDP/TLS/RTP/SAVPF 8 101
a=rtcp:16628 IN IP4 1.2.3.4
a=rtcp-mux
a=ssrc:2690029308 cname:rbaag6w9fGmRXQm6
a=ssrc:2690029308 msid:lyNSTe6w2ijnMrDEiqTHFyhqjdAag3ys a0
a=ssrc:2690029308 mslabel:lyNSTe6w2ijnMrDEiqTHFyhqjdAag3ys
a=ssrc:2690029308 label:lyNSTe6w2ijnMrDEiqTHFyhqjdAag3ysa0
a=rtpmap:8 PCMA/8000
a=rtpmap:101 telephone-event/8000
a=candidate:0560693492 1 udp 659136 1.2.3.4 16628 typ host
a=end-of-candidates
a=ice-ufrag:75EDuLTEOkEUd3cu
a=ice-pwd:5dvb9SbfooWc49814CupdeTS
a=fingerprint:sha-256 35:5A:BC:8E:CD:F8:CD:EB:36:00:BB:C4:C3:33:54:B5:9B:70:3C:E9:C4:33:8F:39:3C:4B:5B:5C:AD:88:12:2B
a=setup:active
"""
),
) | v=0
o=FreeSWITCH 1538380016 1538380017 IN IP4 1.2.3.4
s=FreeSWITCH
c=IN IP4 1.2.3.4
t=0 0
a=msid-semantic: WMS lyNSTe6w2ijnMrDEiqTHFyhqjdAag3ys
m=audio 16628 UDP/TLS/RTP/SAVPF 8 101
a=rtpmap:8 PCMA/8000
a=rtpmap:101 telephone-event/8000
a=ptime:20
a=fingerprint:sha-256 35:5A:BC:8E:CD:F8:CD:EB:36:00:BB:C4:C3:33:54:B5:9B:70:3C:E9:C4:33:8F:39:3C:4B:5B:5C:AD:88:12:2B
a=setup:active
a=rtcp-mux
a=rtcp:16628 IN IP4 1.2.3.4
a=ice-ufrag:75EDuLTEOkEUd3cu
a=ice-pwd:5dvb9SbfooWc49814CupdeTS
a=candidate:0560693492 1 udp 659136 1.2.3.4 16628 typ host generation 0
a=end-of-candidates
a=ssrc:2690029308 cname:rbaag6w9fGmRXQm6
a=ssrc:2690029308 msid:lyNSTe6w2ijnMrDEiqTHFyhqjdAag3ys a0
a=ssrc:2690029308 mslabel:lyNSTe6w2ijnMrDEiqTHFyhqjdAag3ys
a=ssrc:2690029308 label:lyNSTe6w2ijnMrDEiqTHFyhqjdAag3ysa0 | test_audio_freeswitch | python | aiortc/aiortc | tests/test_sdp.py | https://github.com/aiortc/aiortc/blob/master/tests/test_sdp.py | BSD-3-Clause |
def test_audio_freeswitch_no_dtls(self):
d = SessionDescription.parse(
lf2crlf(
"""v=0
o=FreeSWITCH 1538380016 1538380017 IN IP4 1.2.3.4
s=FreeSWITCH
c=IN IP4 1.2.3.4
t=0 0
a=msid-semantic: WMS lyNSTe6w2ijnMrDEiqTHFyhqjdAag3ys
m=audio 16628 UDP/TLS/RTP/SAVPF 8 101
a=rtpmap:8 PCMA/8000
a=rtpmap:101 telephone-event/8000
a=ptime:20
a=rtcp-mux
a=rtcp:16628 IN IP4 1.2.3.4
a=ice-ufrag:75EDuLTEOkEUd3cu
a=ice-pwd:5dvb9SbfooWc49814CupdeTS
a=candidate:0560693492 1 udp 659136 1.2.3.4 16628 typ host generation 0
a=end-of-candidates
a=ssrc:2690029308 cname:rbaag6w9fGmRXQm6
a=ssrc:2690029308 msid:lyNSTe6w2ijnMrDEiqTHFyhqjdAag3ys a0
a=ssrc:2690029308 mslabel:lyNSTe6w2ijnMrDEiqTHFyhqjdAag3ys
a=ssrc:2690029308 label:lyNSTe6w2ijnMrDEiqTHFyhqjdAag3ysa0"""
)
)
self.assertEqual(d.group, [])
self.assertEqual(
d.msid_semantic,
[
GroupDescription(
semantic="WMS", items=["lyNSTe6w2ijnMrDEiqTHFyhqjdAag3ys"]
)
],
)
self.assertEqual(d.host, "1.2.3.4")
self.assertEqual(d.name, "FreeSWITCH")
self.assertEqual(d.origin, "FreeSWITCH 1538380016 1538380017 IN IP4 1.2.3.4")
self.assertEqual(d.time, "0 0")
self.assertEqual(d.version, 0)
self.assertEqual(len(d.media), 1)
self.assertEqual(d.media[0].kind, "audio")
self.assertEqual(d.media[0].host, None)
self.assertEqual(d.media[0].port, 16628)
self.assertEqual(d.media[0].profile, "UDP/TLS/RTP/SAVPF")
self.assertEqual(d.media[0].direction, None)
self.assertEqual(
d.media[0].rtp.codecs,
[
RTCRtpCodecParameters(
mimeType="audio/PCMA", clockRate=8000, channels=1, payloadType=8
),
RTCRtpCodecParameters(
mimeType="audio/telephone-event",
clockRate=8000,
channels=1,
payloadType=101,
),
],
)
self.assertEqual(d.media[0].rtp.headerExtensions, [])
self.assertEqual(d.media[0].rtp.muxId, "")
self.assertEqual(d.media[0].rtcp_host, "1.2.3.4")
self.assertEqual(d.media[0].rtcp_port, 16628)
self.assertEqual(d.media[0].rtcp_mux, True)
# ssrc
self.assertEqual(
d.media[0].ssrc,
[
SsrcDescription(
ssrc=2690029308,
cname="rbaag6w9fGmRXQm6",
msid="lyNSTe6w2ijnMrDEiqTHFyhqjdAag3ys a0",
mslabel="lyNSTe6w2ijnMrDEiqTHFyhqjdAag3ys",
label="lyNSTe6w2ijnMrDEiqTHFyhqjdAag3ysa0",
)
],
)
self.assertEqual(d.media[0].ssrc_group, [])
# formats
self.assertEqual(d.media[0].fmt, [8, 101])
self.assertEqual(d.media[0].sctpmap, {})
self.assertEqual(d.media[0].sctp_port, None)
# ice
self.assertEqual(len(d.media[0].ice_candidates), 1)
self.assertEqual(d.media[0].ice_candidates_complete, True)
self.assertEqual(d.media[0].ice_options, None)
self.assertEqual(d.media[0].ice.iceLite, False)
self.assertEqual(d.media[0].ice.usernameFragment, "75EDuLTEOkEUd3cu")
self.assertEqual(d.media[0].ice.password, "5dvb9SbfooWc49814CupdeTS")
# dtls
self.assertEqual(d.media[0].dtls, None)
self.assertEqual(
str(d),
lf2crlf(
"""v=0
o=FreeSWITCH 1538380016 1538380017 IN IP4 1.2.3.4
s=FreeSWITCH
c=IN IP4 1.2.3.4
t=0 0
a=msid-semantic:WMS lyNSTe6w2ijnMrDEiqTHFyhqjdAag3ys
m=audio 16628 UDP/TLS/RTP/SAVPF 8 101
a=rtcp:16628 IN IP4 1.2.3.4
a=rtcp-mux
a=ssrc:2690029308 cname:rbaag6w9fGmRXQm6
a=ssrc:2690029308 msid:lyNSTe6w2ijnMrDEiqTHFyhqjdAag3ys a0
a=ssrc:2690029308 mslabel:lyNSTe6w2ijnMrDEiqTHFyhqjdAag3ys
a=ssrc:2690029308 label:lyNSTe6w2ijnMrDEiqTHFyhqjdAag3ysa0
a=rtpmap:8 PCMA/8000
a=rtpmap:101 telephone-event/8000
a=candidate:0560693492 1 udp 659136 1.2.3.4 16628 typ host
a=end-of-candidates
a=ice-ufrag:75EDuLTEOkEUd3cu
a=ice-pwd:5dvb9SbfooWc49814CupdeTS
"""
),
) | v=0
o=FreeSWITCH 1538380016 1538380017 IN IP4 1.2.3.4
s=FreeSWITCH
c=IN IP4 1.2.3.4
t=0 0
a=msid-semantic: WMS lyNSTe6w2ijnMrDEiqTHFyhqjdAag3ys
m=audio 16628 UDP/TLS/RTP/SAVPF 8 101
a=rtpmap:8 PCMA/8000
a=rtpmap:101 telephone-event/8000
a=ptime:20
a=rtcp-mux
a=rtcp:16628 IN IP4 1.2.3.4
a=ice-ufrag:75EDuLTEOkEUd3cu
a=ice-pwd:5dvb9SbfooWc49814CupdeTS
a=candidate:0560693492 1 udp 659136 1.2.3.4 16628 typ host generation 0
a=end-of-candidates
a=ssrc:2690029308 cname:rbaag6w9fGmRXQm6
a=ssrc:2690029308 msid:lyNSTe6w2ijnMrDEiqTHFyhqjdAag3ys a0
a=ssrc:2690029308 mslabel:lyNSTe6w2ijnMrDEiqTHFyhqjdAag3ys
a=ssrc:2690029308 label:lyNSTe6w2ijnMrDEiqTHFyhqjdAag3ysa0 | test_audio_freeswitch_no_dtls | python | aiortc/aiortc | tests/test_sdp.py | https://github.com/aiortc/aiortc/blob/master/tests/test_sdp.py | BSD-3-Clause |
def test_audio_dtls_session_level(self):
d = SessionDescription.parse(
lf2crlf(
"""v=0
o=- 863426017819471768 2 IN IP4 127.0.0.1
s=-
t=0 0
a=fingerprint:sha-256 6B:8B:5D:EA:59:04:20:23:29:C8:87:1C:CC:87:32:BE:DD:8C:66:A5:8E:50:55:EA:8C:D3:B6:5C:09:5E:D6:BC
a=setup:actpass
m=audio 45076 UDP/TLS/RTP/SAVPF 0 8
c=IN IP4 192.168.99.58
a=rtcp:9 IN IP4 0.0.0.0
a=candidate:2665802302 1 udp 2122262783 2a02:a03f:3eb0:e000:b0aa:d60a:cff2:933c 38475 typ host generation 0 network-id 2 network-cost 10
a=candidate:1039001212 1 udp 2122194687 192.168.99.58 45076 typ host generation 0 network-id 1 network-cost 10
a=ice-ufrag:5+Ix
a=ice-pwd:uK8IlylxzDMUhrkVzdmj0M+v
a=mid:audio
a=sendrecv
a=rtcp-mux
a=rtpmap:0 PCMU/8000
a=rtpmap:8 PCMA/8000"""
)
)
self.assertEqual(d.group, [])
self.assertEqual(d.msid_semantic, [])
self.assertEqual(d.host, None)
self.assertEqual(d.name, "-")
self.assertEqual(d.origin, "- 863426017819471768 2 IN IP4 127.0.0.1")
self.assertEqual(d.time, "0 0")
self.assertEqual(d.version, 0)
self.assertEqual(len(d.media), 1)
self.assertEqual(d.media[0].kind, "audio")
self.assertEqual(d.media[0].host, "192.168.99.58")
self.assertEqual(d.media[0].port, 45076)
self.assertEqual(d.media[0].profile, "UDP/TLS/RTP/SAVPF")
self.assertEqual(d.media[0].direction, "sendrecv")
self.assertEqual(d.media[0].msid, None)
self.assertEqual(
d.media[0].rtp.codecs,
[
RTCRtpCodecParameters(
mimeType="audio/PCMU", clockRate=8000, channels=1, payloadType=0
),
RTCRtpCodecParameters(
mimeType="audio/PCMA", clockRate=8000, channels=1, payloadType=8
),
],
)
self.assertEqual(d.media[0].rtp.headerExtensions, [])
self.assertEqual(d.media[0].rtp.muxId, "audio")
self.assertEqual(d.media[0].rtcp_host, "0.0.0.0")
self.assertEqual(d.media[0].rtcp_port, 9)
self.assertEqual(d.media[0].rtcp_mux, True)
# ssrc
self.assertEqual(d.media[0].ssrc, [])
self.assertEqual(d.media[0].ssrc_group, [])
# formats
self.assertEqual(d.media[0].fmt, [0, 8])
self.assertEqual(d.media[0].sctpmap, {})
self.assertEqual(d.media[0].sctp_port, None)
# ice
self.assertEqual(len(d.media[0].ice_candidates), 2)
self.assertEqual(d.media[0].ice_candidates_complete, False)
self.assertEqual(d.media[0].ice_options, None)
self.assertEqual(d.media[0].ice.iceLite, False)
self.assertEqual(d.media[0].ice.usernameFragment, "5+Ix")
self.assertEqual(d.media[0].ice.password, "uK8IlylxzDMUhrkVzdmj0M+v")
# dtls
self.assertEqual(len(d.media[0].dtls.fingerprints), 1)
self.assertEqual(d.media[0].dtls.fingerprints[0].algorithm, "sha-256")
self.assertEqual(
d.media[0].dtls.fingerprints[0].value,
"6B:8B:5D:EA:59:04:20:23:29:C8:87:1C:CC:87:32:BE:DD:8C:66:A5:8E:50:55:EA:8C:D3:B6:5C:09:5E:D6:BC",
)
self.assertEqual(d.media[0].dtls.role, "auto")
self.assertEqual(
str(d),
lf2crlf(
"""v=0
o=- 863426017819471768 2 IN IP4 127.0.0.1
s=-
t=0 0
m=audio 45076 UDP/TLS/RTP/SAVPF 0 8
c=IN IP4 192.168.99.58
a=sendrecv
a=mid:audio
a=rtcp:9 IN IP4 0.0.0.0
a=rtcp-mux
a=rtpmap:0 PCMU/8000
a=rtpmap:8 PCMA/8000
a=candidate:2665802302 1 udp 2122262783 2a02:a03f:3eb0:e000:b0aa:d60a:cff2:933c 38475 typ host
a=candidate:1039001212 1 udp 2122194687 192.168.99.58 45076 typ host
a=ice-ufrag:5+Ix
a=ice-pwd:uK8IlylxzDMUhrkVzdmj0M+v
a=fingerprint:sha-256 6B:8B:5D:EA:59:04:20:23:29:C8:87:1C:CC:87:32:BE:DD:8C:66:A5:8E:50:55:EA:8C:D3:B6:5C:09:5E:D6:BC
a=setup:actpass
"""
),
) | v=0
o=- 863426017819471768 2 IN IP4 127.0.0.1
s=-
t=0 0
a=fingerprint:sha-256 6B:8B:5D:EA:59:04:20:23:29:C8:87:1C:CC:87:32:BE:DD:8C:66:A5:8E:50:55:EA:8C:D3:B6:5C:09:5E:D6:BC
a=setup:actpass
m=audio 45076 UDP/TLS/RTP/SAVPF 0 8
c=IN IP4 192.168.99.58
a=rtcp:9 IN IP4 0.0.0.0
a=candidate:2665802302 1 udp 2122262783 2a02:a03f:3eb0:e000:b0aa:d60a:cff2:933c 38475 typ host generation 0 network-id 2 network-cost 10
a=candidate:1039001212 1 udp 2122194687 192.168.99.58 45076 typ host generation 0 network-id 1 network-cost 10
a=ice-ufrag:5+Ix
a=ice-pwd:uK8IlylxzDMUhrkVzdmj0M+v
a=mid:audio
a=sendrecv
a=rtcp-mux
a=rtpmap:0 PCMU/8000
a=rtpmap:8 PCMA/8000 | test_audio_dtls_session_level | python | aiortc/aiortc | tests/test_sdp.py | https://github.com/aiortc/aiortc/blob/master/tests/test_sdp.py | BSD-3-Clause |
def test_audio_ice_lite(self):
d = SessionDescription.parse(
lf2crlf(
"""v=0
o=- 863426017819471768 2 IN IP4 127.0.0.1
s=-
t=0 0
a=ice-lite
m=audio 45076 UDP/TLS/RTP/SAVPF 0 8
c=IN IP4 192.168.99.58
a=rtcp:9 IN IP4 0.0.0.0
a=candidate:2665802302 1 udp 2122262783 2a02:a03f:3eb0:e000:b0aa:d60a:cff2:933c 38475 typ host generation 0 network-id 2 network-cost 10
a=candidate:1039001212 1 udp 2122194687 192.168.99.58 45076 typ host generation 0 network-id 1 network-cost 10
a=ice-ufrag:5+Ix
a=ice-pwd:uK8IlylxzDMUhrkVzdmj0M+v
a=fingerprint:sha-256 6B:8B:5D:EA:59:04:20:23:29:C8:87:1C:CC:87:32:BE:DD:8C:66:A5:8E:50:55:EA:8C:D3:B6:5C:09:5E:D6:BC
a=setup:actpass
a=mid:audio
a=sendrecv
a=rtcp-mux
a=rtpmap:0 PCMU/8000
a=rtpmap:8 PCMA/8000"""
)
)
self.assertEqual(d.group, [])
self.assertEqual(d.msid_semantic, [])
self.assertEqual(d.host, None)
self.assertEqual(d.name, "-")
self.assertEqual(d.origin, "- 863426017819471768 2 IN IP4 127.0.0.1")
self.assertEqual(d.time, "0 0")
self.assertEqual(d.version, 0)
self.assertEqual(len(d.media), 1)
self.assertEqual(d.media[0].kind, "audio")
self.assertEqual(d.media[0].host, "192.168.99.58")
self.assertEqual(d.media[0].port, 45076)
self.assertEqual(d.media[0].profile, "UDP/TLS/RTP/SAVPF")
self.assertEqual(d.media[0].direction, "sendrecv")
self.assertEqual(d.media[0].msid, None)
self.assertEqual(
d.media[0].rtp.codecs,
[
RTCRtpCodecParameters(
mimeType="audio/PCMU", clockRate=8000, channels=1, payloadType=0
),
RTCRtpCodecParameters(
mimeType="audio/PCMA", clockRate=8000, channels=1, payloadType=8
),
],
)
self.assertEqual(d.media[0].rtp.headerExtensions, [])
self.assertEqual(d.media[0].rtp.muxId, "audio")
self.assertEqual(d.media[0].rtcp_host, "0.0.0.0")
self.assertEqual(d.media[0].rtcp_port, 9)
self.assertEqual(d.media[0].rtcp_mux, True)
# ssrc
self.assertEqual(d.media[0].ssrc, [])
self.assertEqual(d.media[0].ssrc_group, [])
# formats
self.assertEqual(d.media[0].fmt, [0, 8])
self.assertEqual(d.media[0].sctpmap, {})
self.assertEqual(d.media[0].sctp_port, None)
# ice
self.assertEqual(len(d.media[0].ice_candidates), 2)
self.assertEqual(d.media[0].ice_candidates_complete, False)
self.assertEqual(d.media[0].ice_options, None)
self.assertEqual(d.media[0].ice.iceLite, True)
self.assertEqual(d.media[0].ice.usernameFragment, "5+Ix")
self.assertEqual(d.media[0].ice.password, "uK8IlylxzDMUhrkVzdmj0M+v")
# dtls
self.assertEqual(len(d.media[0].dtls.fingerprints), 1)
self.assertEqual(d.media[0].dtls.fingerprints[0].algorithm, "sha-256")
self.assertEqual(
d.media[0].dtls.fingerprints[0].value,
"6B:8B:5D:EA:59:04:20:23:29:C8:87:1C:CC:87:32:BE:DD:8C:66:A5:8E:50:55:EA:8C:D3:B6:5C:09:5E:D6:BC",
)
self.assertEqual(d.media[0].dtls.role, "auto")
self.assertEqual(
str(d),
lf2crlf(
"""v=0
o=- 863426017819471768 2 IN IP4 127.0.0.1
s=-
t=0 0
a=ice-lite
m=audio 45076 UDP/TLS/RTP/SAVPF 0 8
c=IN IP4 192.168.99.58
a=sendrecv
a=mid:audio
a=rtcp:9 IN IP4 0.0.0.0
a=rtcp-mux
a=rtpmap:0 PCMU/8000
a=rtpmap:8 PCMA/8000
a=candidate:2665802302 1 udp 2122262783 2a02:a03f:3eb0:e000:b0aa:d60a:cff2:933c 38475 typ host
a=candidate:1039001212 1 udp 2122194687 192.168.99.58 45076 typ host
a=ice-ufrag:5+Ix
a=ice-pwd:uK8IlylxzDMUhrkVzdmj0M+v
a=fingerprint:sha-256 6B:8B:5D:EA:59:04:20:23:29:C8:87:1C:CC:87:32:BE:DD:8C:66:A5:8E:50:55:EA:8C:D3:B6:5C:09:5E:D6:BC
a=setup:actpass
"""
),
) | v=0
o=- 863426017819471768 2 IN IP4 127.0.0.1
s=-
t=0 0
a=ice-lite
m=audio 45076 UDP/TLS/RTP/SAVPF 0 8
c=IN IP4 192.168.99.58
a=rtcp:9 IN IP4 0.0.0.0
a=candidate:2665802302 1 udp 2122262783 2a02:a03f:3eb0:e000:b0aa:d60a:cff2:933c 38475 typ host generation 0 network-id 2 network-cost 10
a=candidate:1039001212 1 udp 2122194687 192.168.99.58 45076 typ host generation 0 network-id 1 network-cost 10
a=ice-ufrag:5+Ix
a=ice-pwd:uK8IlylxzDMUhrkVzdmj0M+v
a=fingerprint:sha-256 6B:8B:5D:EA:59:04:20:23:29:C8:87:1C:CC:87:32:BE:DD:8C:66:A5:8E:50:55:EA:8C:D3:B6:5C:09:5E:D6:BC
a=setup:actpass
a=mid:audio
a=sendrecv
a=rtcp-mux
a=rtpmap:0 PCMU/8000
a=rtpmap:8 PCMA/8000 | test_audio_ice_lite | python | aiortc/aiortc | tests/test_sdp.py | https://github.com/aiortc/aiortc/blob/master/tests/test_sdp.py | BSD-3-Clause |
def test_audio_ice_session_level_credentials(self):
d = SessionDescription.parse(
lf2crlf(
"""v=0
o=- 863426017819471768 2 IN IP4 127.0.0.1
s=-
t=0 0
a=ice-ufrag:5+Ix
a=ice-pwd:uK8IlylxzDMUhrkVzdmj0M+v
m=audio 45076 UDP/TLS/RTP/SAVPF 0 8
c=IN IP4 192.168.99.58
a=rtcp:9 IN IP4 0.0.0.0
a=candidate:2665802302 1 udp 2122262783 2a02:a03f:3eb0:e000:b0aa:d60a:cff2:933c 38475 typ host generation 0 network-id 2 network-cost 10
a=candidate:1039001212 1 udp 2122194687 192.168.99.58 45076 typ host generation 0 network-id 1 network-cost 10
a=fingerprint:sha-256 6B:8B:5D:EA:59:04:20:23:29:C8:87:1C:CC:87:32:BE:DD:8C:66:A5:8E:50:55:EA:8C:D3:B6:5C:09:5E:D6:BC
a=setup:actpass
a=mid:audio
a=sendrecv
a=rtcp-mux
a=rtpmap:0 PCMU/8000
a=rtpmap:8 PCMA/8000"""
)
)
self.assertEqual(d.group, [])
self.assertEqual(d.msid_semantic, [])
self.assertEqual(d.host, None)
self.assertEqual(d.name, "-")
self.assertEqual(d.origin, "- 863426017819471768 2 IN IP4 127.0.0.1")
self.assertEqual(d.time, "0 0")
self.assertEqual(d.version, 0)
self.assertEqual(len(d.media), 1)
self.assertEqual(d.media[0].kind, "audio")
self.assertEqual(d.media[0].host, "192.168.99.58")
self.assertEqual(d.media[0].port, 45076)
self.assertEqual(d.media[0].profile, "UDP/TLS/RTP/SAVPF")
self.assertEqual(d.media[0].direction, "sendrecv")
self.assertEqual(d.media[0].msid, None)
self.assertEqual(
d.media[0].rtp.codecs,
[
RTCRtpCodecParameters(
mimeType="audio/PCMU", clockRate=8000, channels=1, payloadType=0
),
RTCRtpCodecParameters(
mimeType="audio/PCMA", clockRate=8000, channels=1, payloadType=8
),
],
)
self.assertEqual(d.media[0].rtp.headerExtensions, [])
self.assertEqual(d.media[0].rtp.muxId, "audio")
self.assertEqual(d.media[0].rtcp_host, "0.0.0.0")
self.assertEqual(d.media[0].rtcp_port, 9)
self.assertEqual(d.media[0].rtcp_mux, True)
# ssrc
self.assertEqual(d.media[0].ssrc, [])
self.assertEqual(d.media[0].ssrc_group, [])
# formats
self.assertEqual(d.media[0].fmt, [0, 8])
self.assertEqual(d.media[0].sctpmap, {})
self.assertEqual(d.media[0].sctp_port, None)
# ice
self.assertEqual(len(d.media[0].ice_candidates), 2)
self.assertEqual(d.media[0].ice_candidates_complete, False)
self.assertEqual(d.media[0].ice_options, None)
self.assertEqual(d.media[0].ice.iceLite, False)
self.assertEqual(d.media[0].ice.usernameFragment, "5+Ix")
self.assertEqual(d.media[0].ice.password, "uK8IlylxzDMUhrkVzdmj0M+v")
# dtls
self.assertEqual(len(d.media[0].dtls.fingerprints), 1)
self.assertEqual(d.media[0].dtls.fingerprints[0].algorithm, "sha-256")
self.assertEqual(
d.media[0].dtls.fingerprints[0].value,
"6B:8B:5D:EA:59:04:20:23:29:C8:87:1C:CC:87:32:BE:DD:8C:66:A5:8E:50:55:EA:8C:D3:B6:5C:09:5E:D6:BC",
)
self.assertEqual(d.media[0].dtls.role, "auto")
self.assertEqual(
str(d),
lf2crlf(
"""v=0
o=- 863426017819471768 2 IN IP4 127.0.0.1
s=-
t=0 0
m=audio 45076 UDP/TLS/RTP/SAVPF 0 8
c=IN IP4 192.168.99.58
a=sendrecv
a=mid:audio
a=rtcp:9 IN IP4 0.0.0.0
a=rtcp-mux
a=rtpmap:0 PCMU/8000
a=rtpmap:8 PCMA/8000
a=candidate:2665802302 1 udp 2122262783 2a02:a03f:3eb0:e000:b0aa:d60a:cff2:933c 38475 typ host
a=candidate:1039001212 1 udp 2122194687 192.168.99.58 45076 typ host
a=ice-ufrag:5+Ix
a=ice-pwd:uK8IlylxzDMUhrkVzdmj0M+v
a=fingerprint:sha-256 6B:8B:5D:EA:59:04:20:23:29:C8:87:1C:CC:87:32:BE:DD:8C:66:A5:8E:50:55:EA:8C:D3:B6:5C:09:5E:D6:BC
a=setup:actpass
"""
),
) | v=0
o=- 863426017819471768 2 IN IP4 127.0.0.1
s=-
t=0 0
a=ice-ufrag:5+Ix
a=ice-pwd:uK8IlylxzDMUhrkVzdmj0M+v
m=audio 45076 UDP/TLS/RTP/SAVPF 0 8
c=IN IP4 192.168.99.58
a=rtcp:9 IN IP4 0.0.0.0
a=candidate:2665802302 1 udp 2122262783 2a02:a03f:3eb0:e000:b0aa:d60a:cff2:933c 38475 typ host generation 0 network-id 2 network-cost 10
a=candidate:1039001212 1 udp 2122194687 192.168.99.58 45076 typ host generation 0 network-id 1 network-cost 10
a=fingerprint:sha-256 6B:8B:5D:EA:59:04:20:23:29:C8:87:1C:CC:87:32:BE:DD:8C:66:A5:8E:50:55:EA:8C:D3:B6:5C:09:5E:D6:BC
a=setup:actpass
a=mid:audio
a=sendrecv
a=rtcp-mux
a=rtpmap:0 PCMU/8000
a=rtpmap:8 PCMA/8000 | test_audio_ice_session_level_credentials | python | aiortc/aiortc | tests/test_sdp.py | https://github.com/aiortc/aiortc/blob/master/tests/test_sdp.py | BSD-3-Clause |
def test_datachannel_firefox(self):
d = SessionDescription.parse(
lf2crlf(
"""v=0
o=mozilla...THIS_IS_SDPARTA-58.0.1 7514673380034989017 0 IN IP4 0.0.0.0
s=-
t=0 0
a=sendrecv
a=fingerprint:sha-256 39:4A:09:1E:0E:33:32:85:51:03:49:95:54:0B:41:09:A2:10:60:CC:39:8F:C0:C4:45:FC:37:3A:55:EA:11:74
a=group:BUNDLE sdparta_0
a=ice-options:trickle
a=msid-semantic:WMS *
m=application 45791 DTLS/SCTP 5000
c=IN IP4 192.168.99.58
a=candidate:0 1 UDP 2122187007 192.168.99.58 45791 typ host
a=candidate:1 1 UDP 2122252543 2a02:a03f:3eb0:e000:b0aa:d60a:cff2:933c 44087 typ host
a=candidate:2 1 TCP 2105458943 192.168.99.58 9 typ host tcptype active
a=candidate:3 1 TCP 2105524479 2a02:a03f:3eb0:e000:b0aa:d60a:cff2:933c 9 typ host tcptype active
a=sendrecv
a=end-of-candidates
a=ice-pwd:d30a5aec4dd81f07d4ff3344209400ab
a=ice-ufrag:9889e0c4
a=mid:sdparta_0
a=sctpmap:5000 webrtc-datachannel 256
a=setup:actpass
a=max-message-size:1073741823
"""
)
)
self.assertEqual(
d.group, [GroupDescription(semantic="BUNDLE", items=["sdparta_0"])]
)
self.assertEqual(
d.msid_semantic, [GroupDescription(semantic="WMS", items=["*"])]
)
self.assertEqual(d.host, None)
self.assertEqual(d.name, "-")
self.assertEqual(
d.origin,
"mozilla...THIS_IS_SDPARTA-58.0.1 7514673380034989017 0 IN IP4 0.0.0.0",
)
self.assertEqual(d.time, "0 0")
self.assertEqual(d.version, 0)
self.assertEqual(len(d.media), 1)
self.assertEqual(d.media[0].kind, "application")
self.assertEqual(d.media[0].host, "192.168.99.58")
self.assertEqual(d.media[0].port, 45791)
self.assertEqual(d.media[0].profile, "DTLS/SCTP")
self.assertEqual(d.media[0].fmt, ["5000"])
# sctp
self.assertEqual(d.media[0].sctpmap, {5000: "webrtc-datachannel 256"})
self.assertEqual(d.media[0].sctp_port, None)
self.assertIsNotNone(d.media[0].sctpCapabilities)
self.assertEqual(d.media[0].sctpCapabilities.maxMessageSize, 1073741823)
# ice
self.assertEqual(len(d.media[0].ice_candidates), 4)
self.assertEqual(d.media[0].ice_candidates_complete, True)
self.assertEqual(d.media[0].ice_options, "trickle")
self.assertEqual(d.media[0].ice.iceLite, False)
self.assertEqual(d.media[0].ice.usernameFragment, "9889e0c4")
self.assertEqual(d.media[0].ice.password, "d30a5aec4dd81f07d4ff3344209400ab")
# dtls
self.assertEqual(len(d.media[0].dtls.fingerprints), 1)
self.assertEqual(d.media[0].dtls.fingerprints[0].algorithm, "sha-256")
self.assertEqual(
d.media[0].dtls.fingerprints[0].value,
"39:4A:09:1E:0E:33:32:85:51:03:49:95:54:0B:41:09:A2:10:60:CC:39:8F:C0:C4:45:FC:37:3A:55:EA:11:74",
)
self.assertEqual(d.media[0].dtls.role, "auto")
self.assertEqual(
str(d),
lf2crlf(
"""v=0
o=mozilla...THIS_IS_SDPARTA-58.0.1 7514673380034989017 0 IN IP4 0.0.0.0
s=-
t=0 0
a=group:BUNDLE sdparta_0
a=msid-semantic:WMS *
m=application 45791 DTLS/SCTP 5000
c=IN IP4 192.168.99.58
a=sendrecv
a=mid:sdparta_0
a=sctpmap:5000 webrtc-datachannel 256
a=max-message-size:1073741823
a=candidate:0 1 UDP 2122187007 192.168.99.58 45791 typ host
a=candidate:1 1 UDP 2122252543 2a02:a03f:3eb0:e000:b0aa:d60a:cff2:933c 44087 typ host
a=candidate:2 1 TCP 2105458943 192.168.99.58 9 typ host tcptype active
a=candidate:3 1 TCP 2105524479 2a02:a03f:3eb0:e000:b0aa:d60a:cff2:933c 9 typ host tcptype active
a=end-of-candidates
a=ice-ufrag:9889e0c4
a=ice-pwd:d30a5aec4dd81f07d4ff3344209400ab
a=ice-options:trickle
a=fingerprint:sha-256 39:4A:09:1E:0E:33:32:85:51:03:49:95:54:0B:41:09:A2:10:60:CC:39:8F:C0:C4:45:FC:37:3A:55:EA:11:74
a=setup:actpass
"""
),
) | v=0
o=mozilla...THIS_IS_SDPARTA-58.0.1 7514673380034989017 0 IN IP4 0.0.0.0
s=-
t=0 0
a=sendrecv
a=fingerprint:sha-256 39:4A:09:1E:0E:33:32:85:51:03:49:95:54:0B:41:09:A2:10:60:CC:39:8F:C0:C4:45:FC:37:3A:55:EA:11:74
a=group:BUNDLE sdparta_0
a=ice-options:trickle
a=msid-semantic:WMS *
m=application 45791 DTLS/SCTP 5000
c=IN IP4 192.168.99.58
a=candidate:0 1 UDP 2122187007 192.168.99.58 45791 typ host
a=candidate:1 1 UDP 2122252543 2a02:a03f:3eb0:e000:b0aa:d60a:cff2:933c 44087 typ host
a=candidate:2 1 TCP 2105458943 192.168.99.58 9 typ host tcptype active
a=candidate:3 1 TCP 2105524479 2a02:a03f:3eb0:e000:b0aa:d60a:cff2:933c 9 typ host tcptype active
a=sendrecv
a=end-of-candidates
a=ice-pwd:d30a5aec4dd81f07d4ff3344209400ab
a=ice-ufrag:9889e0c4
a=mid:sdparta_0
a=sctpmap:5000 webrtc-datachannel 256
a=setup:actpass
a=max-message-size:1073741823 | test_datachannel_firefox | python | aiortc/aiortc | tests/test_sdp.py | https://github.com/aiortc/aiortc/blob/master/tests/test_sdp.py | BSD-3-Clause |
def test_datachannel_firefox_63(self):
d = SessionDescription.parse(
lf2crlf(
"""v=0
o=mozilla...THIS_IS_SDPARTA-58.0.1 7514673380034989017 0 IN IP4 0.0.0.0
s=-
t=0 0
a=sendrecv
a=fingerprint:sha-256 39:4A:09:1E:0E:33:32:85:51:03:49:95:54:0B:41:09:A2:10:60:CC:39:8F:C0:C4:45:FC:37:3A:55:EA:11:74
a=group:BUNDLE sdparta_0
a=ice-options:trickle
a=msid-semantic:WMS *
m=application 45791 UDP/DTLS/SCTP webrtc-datachannel
c=IN IP4 192.168.99.58
a=candidate:0 1 UDP 2122187007 192.168.99.58 45791 typ host
a=candidate:1 1 UDP 2122252543 2a02:a03f:3eb0:e000:b0aa:d60a:cff2:933c 44087 typ host
a=candidate:2 1 TCP 2105458943 192.168.99.58 9 typ host tcptype active
a=candidate:3 1 TCP 2105524479 2a02:a03f:3eb0:e000:b0aa:d60a:cff2:933c 9 typ host tcptype active
a=sendrecv
a=end-of-candidates
a=ice-pwd:d30a5aec4dd81f07d4ff3344209400ab
a=ice-ufrag:9889e0c4
a=mid:sdparta_0
a=sctp-port:5000
a=setup:actpass
a=max-message-size:1073741823
"""
)
)
self.assertEqual(
d.group, [GroupDescription(semantic="BUNDLE", items=["sdparta_0"])]
)
self.assertEqual(
d.msid_semantic, [GroupDescription(semantic="WMS", items=["*"])]
)
self.assertEqual(d.host, None)
self.assertEqual(d.name, "-")
self.assertEqual(
d.origin,
"mozilla...THIS_IS_SDPARTA-58.0.1 7514673380034989017 0 IN IP4 0.0.0.0",
)
self.assertEqual(d.time, "0 0")
self.assertEqual(d.version, 0)
self.assertEqual(len(d.media), 1)
self.assertEqual(d.media[0].kind, "application")
self.assertEqual(d.media[0].host, "192.168.99.58")
self.assertEqual(d.media[0].port, 45791)
self.assertEqual(d.media[0].profile, "UDP/DTLS/SCTP")
self.assertEqual(d.media[0].fmt, ["webrtc-datachannel"])
# sctp
self.assertEqual(d.media[0].sctpmap, {})
self.assertEqual(d.media[0].sctp_port, 5000)
self.assertIsNotNone(d.media[0].sctpCapabilities)
self.assertEqual(d.media[0].sctpCapabilities.maxMessageSize, 1073741823)
# ice
self.assertEqual(len(d.media[0].ice_candidates), 4)
self.assertEqual(d.media[0].ice_candidates_complete, True)
self.assertEqual(d.media[0].ice_options, "trickle")
self.assertEqual(d.media[0].ice.iceLite, False)
self.assertEqual(d.media[0].ice.usernameFragment, "9889e0c4")
self.assertEqual(d.media[0].ice.password, "d30a5aec4dd81f07d4ff3344209400ab")
# dtls
self.assertEqual(len(d.media[0].dtls.fingerprints), 1)
self.assertEqual(d.media[0].dtls.fingerprints[0].algorithm, "sha-256")
self.assertEqual(
d.media[0].dtls.fingerprints[0].value,
"39:4A:09:1E:0E:33:32:85:51:03:49:95:54:0B:41:09:A2:10:60:CC:39:8F:C0:C4:45:FC:37:3A:55:EA:11:74",
)
self.assertEqual(d.media[0].dtls.role, "auto")
self.assertEqual(
str(d),
lf2crlf(
"""v=0
o=mozilla...THIS_IS_SDPARTA-58.0.1 7514673380034989017 0 IN IP4 0.0.0.0
s=-
t=0 0
a=group:BUNDLE sdparta_0
a=msid-semantic:WMS *
m=application 45791 UDP/DTLS/SCTP webrtc-datachannel
c=IN IP4 192.168.99.58
a=sendrecv
a=mid:sdparta_0
a=sctp-port:5000
a=max-message-size:1073741823
a=candidate:0 1 UDP 2122187007 192.168.99.58 45791 typ host
a=candidate:1 1 UDP 2122252543 2a02:a03f:3eb0:e000:b0aa:d60a:cff2:933c 44087 typ host
a=candidate:2 1 TCP 2105458943 192.168.99.58 9 typ host tcptype active
a=candidate:3 1 TCP 2105524479 2a02:a03f:3eb0:e000:b0aa:d60a:cff2:933c 9 typ host tcptype active
a=end-of-candidates
a=ice-ufrag:9889e0c4
a=ice-pwd:d30a5aec4dd81f07d4ff3344209400ab
a=ice-options:trickle
a=fingerprint:sha-256 39:4A:09:1E:0E:33:32:85:51:03:49:95:54:0B:41:09:A2:10:60:CC:39:8F:C0:C4:45:FC:37:3A:55:EA:11:74
a=setup:actpass
"""
),
) | v=0
o=mozilla...THIS_IS_SDPARTA-58.0.1 7514673380034989017 0 IN IP4 0.0.0.0
s=-
t=0 0
a=sendrecv
a=fingerprint:sha-256 39:4A:09:1E:0E:33:32:85:51:03:49:95:54:0B:41:09:A2:10:60:CC:39:8F:C0:C4:45:FC:37:3A:55:EA:11:74
a=group:BUNDLE sdparta_0
a=ice-options:trickle
a=msid-semantic:WMS *
m=application 45791 UDP/DTLS/SCTP webrtc-datachannel
c=IN IP4 192.168.99.58
a=candidate:0 1 UDP 2122187007 192.168.99.58 45791 typ host
a=candidate:1 1 UDP 2122252543 2a02:a03f:3eb0:e000:b0aa:d60a:cff2:933c 44087 typ host
a=candidate:2 1 TCP 2105458943 192.168.99.58 9 typ host tcptype active
a=candidate:3 1 TCP 2105524479 2a02:a03f:3eb0:e000:b0aa:d60a:cff2:933c 9 typ host tcptype active
a=sendrecv
a=end-of-candidates
a=ice-pwd:d30a5aec4dd81f07d4ff3344209400ab
a=ice-ufrag:9889e0c4
a=mid:sdparta_0
a=sctp-port:5000
a=setup:actpass
a=max-message-size:1073741823 | test_datachannel_firefox_63 | python | aiortc/aiortc | tests/test_sdp.py | https://github.com/aiortc/aiortc/blob/master/tests/test_sdp.py | BSD-3-Clause |
def test_video_chrome(self):
d = SessionDescription.parse(
lf2crlf(
"""v=0
o=- 5195484278799753993 2 IN IP4 127.0.0.1
s=-
t=0 0
a=group:BUNDLE video
a=msid-semantic: WMS bbgewhUzS6hvFDlSlrhQ6zYlwW7ttRrK8QeQ
m=video 34955 UDP/TLS/RTP/SAVPF 96 97 98 99 100 101 102
c=IN IP4 10.101.2.67
a=rtcp:9 IN IP4 0.0.0.0
a=candidate:638323114 1 udp 2122260223 10.101.2.67 34955 typ host generation 0 network-id 2 network-cost 10
a=candidate:1754264922 1 tcp 1518280447 10.101.2.67 9 typ host tcptype active generation 0 network-id 2 network-cost 10
a=ice-ufrag:9KhP
a=ice-pwd:mlPea2xBCmFmNLfmy/jlqw1D
a=ice-options:trickle
a=fingerprint:sha-256 30:4A:BF:65:23:D1:99:AB:AE:9F:FD:5D:B1:08:4F:09:7C:9F:F2:CC:50:16:13:81:1B:5D:DD:D0:98:45:81:1E
a=setup:actpass
a=mid:video
a=extmap:2 urn:ietf:params:rtp-hdrext:toffset
a=extmap:3 http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time
a=extmap:4 urn:3gpp:video-orientation
a=extmap:5 http://www.ietf.org/id/draft-holmer-rmcat-transport-wide-cc-extensions-01
a=extmap:6 http://www.webrtc.org/experiments/rtp-hdrext/playout-delay
a=extmap:7 http://www.webrtc.org/experiments/rtp-hdrext/video-content-type
a=extmap:8 http://www.webrtc.org/experiments/rtp-hdrext/video-timing
a=sendrecv
a=rtcp-mux
a=rtcp-rsize
a=rtpmap:96 VP8/90000
a=rtcp-fb:96 goog-remb
a=rtcp-fb:96 transport-cc
a=rtcp-fb:96 ccm fir
a=rtcp-fb:96 nack
a=rtcp-fb:96 nack pli
a=rtpmap:97 rtx/90000
a=fmtp:97 apt=96
a=rtpmap:98 VP9/90000
a=rtcp-fb:98 goog-remb
a=rtcp-fb:98 transport-cc
a=rtcp-fb:98 ccm fir
a=rtcp-fb:98 nack
a=rtcp-fb:98 nack pli
a=rtpmap:99 rtx/90000
a=fmtp:99 apt=98
a=rtpmap:100 red/90000
a=rtpmap:101 rtx/90000
a=fmtp:101 apt=100
a=rtpmap:102 ulpfec/90000
a=ssrc-group:FID 1845476211 3305256354
a=ssrc:1845476211 cname:9iW3jspLCZJ5WjOZ
a=ssrc:1845476211 msid:bbgewhUzS6hvFDlSlrhQ6zYlwW7ttRrK8QeQ 420c6f28-439d-4ead-b93c-94e14c0a16b4
a=ssrc:1845476211 mslabel:bbgewhUzS6hvFDlSlrhQ6zYlwW7ttRrK8QeQ
a=ssrc:1845476211 label:420c6f28-439d-4ead-b93c-94e14c0a16b4
a=ssrc:3305256354 cname:9iW3jspLCZJ5WjOZ
a=ssrc:3305256354 msid:bbgewhUzS6hvFDlSlrhQ6zYlwW7ttRrK8QeQ 420c6f28-439d-4ead-b93c-94e14c0a16b4
a=ssrc:3305256354 mslabel:bbgewhUzS6hvFDlSlrhQ6zYlwW7ttRrK8QeQ
a=ssrc:3305256354 label:420c6f28-439d-4ead-b93c-94e14c0a16b4
"""
)
)
self.assertEqual(
d.group, [GroupDescription(semantic="BUNDLE", items=["video"])]
)
self.assertEqual(
d.msid_semantic,
[
GroupDescription(
semantic="WMS", items=["bbgewhUzS6hvFDlSlrhQ6zYlwW7ttRrK8QeQ"]
)
],
)
self.assertEqual(d.host, None)
self.assertEqual(d.name, "-")
self.assertEqual(d.origin, "- 5195484278799753993 2 IN IP4 127.0.0.1")
self.assertEqual(d.time, "0 0")
self.assertEqual(d.version, 0)
self.assertEqual(len(d.media), 1)
self.assertEqual(d.media[0].kind, "video")
self.assertEqual(d.media[0].host, "10.101.2.67")
self.assertEqual(d.media[0].port, 34955)
self.assertEqual(d.media[0].profile, "UDP/TLS/RTP/SAVPF")
self.assertEqual(d.media[0].direction, "sendrecv")
self.assertEqual(d.media[0].msid, None)
self.assertEqual(
d.media[0].rtp.codecs,
[
RTCRtpCodecParameters(
mimeType="video/VP8",
clockRate=90000,
payloadType=96,
rtcpFeedback=[
RTCRtcpFeedback(type="goog-remb"),
RTCRtcpFeedback(type="transport-cc"),
RTCRtcpFeedback(type="ccm", parameter="fir"),
RTCRtcpFeedback(type="nack"),
RTCRtcpFeedback(type="nack", parameter="pli"),
],
),
RTCRtpCodecParameters(
mimeType="video/rtx",
clockRate=90000,
payloadType=97,
parameters={"apt": 96},
),
RTCRtpCodecParameters(
mimeType="video/VP9",
clockRate=90000,
payloadType=98,
rtcpFeedback=[
RTCRtcpFeedback(type="goog-remb"),
RTCRtcpFeedback(type="transport-cc"),
RTCRtcpFeedback(type="ccm", parameter="fir"),
RTCRtcpFeedback(type="nack"),
RTCRtcpFeedback(type="nack", parameter="pli"),
],
),
RTCRtpCodecParameters(
mimeType="video/rtx",
clockRate=90000,
payloadType=99,
parameters={"apt": 98},
),
RTCRtpCodecParameters(
mimeType="video/red", clockRate=90000, payloadType=100
),
RTCRtpCodecParameters(
mimeType="video/rtx",
clockRate=90000,
payloadType=101,
parameters={"apt": 100},
),
RTCRtpCodecParameters(
mimeType="video/ulpfec", clockRate=90000, payloadType=102
),
],
)
self.assertEqual(
d.media[0].rtp.headerExtensions,
[
RTCRtpHeaderExtensionParameters(
id=2, uri="urn:ietf:params:rtp-hdrext:toffset"
),
RTCRtpHeaderExtensionParameters(
id=3,
uri="http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time",
),
RTCRtpHeaderExtensionParameters(id=4, uri="urn:3gpp:video-orientation"),
RTCRtpHeaderExtensionParameters(
id=5,
uri="http://www.ietf.org/id/draft-holmer-rmcat-transport-wide-cc-extensions-01",
),
RTCRtpHeaderExtensionParameters(
id=6,
uri="http://www.webrtc.org/experiments/rtp-hdrext/playout-delay",
),
RTCRtpHeaderExtensionParameters(
id=7,
uri="http://www.webrtc.org/experiments/rtp-hdrext/video-content-type",
),
RTCRtpHeaderExtensionParameters(
id=8,
uri="http://www.webrtc.org/experiments/rtp-hdrext/video-timing",
),
],
)
self.assertEqual(d.media[0].rtp.muxId, "video")
self.assertEqual(d.media[0].rtcp_host, "0.0.0.0")
self.assertEqual(d.media[0].rtcp_port, 9)
self.assertEqual(d.media[0].rtcp_mux, True)
self.assertEqual(d.webrtc_track_id(d.media[0]), None)
# ssrc
self.assertEqual(
d.media[0].ssrc,
[
SsrcDescription(
ssrc=1845476211,
cname="9iW3jspLCZJ5WjOZ",
msid="bbgewhUzS6hvFDlSlrhQ6zYlwW7ttRrK8QeQ 420c6f28-439d-4ead-b93c-94e14c0a16b4",
mslabel="bbgewhUzS6hvFDlSlrhQ6zYlwW7ttRrK8QeQ",
label="420c6f28-439d-4ead-b93c-94e14c0a16b4",
),
SsrcDescription(
ssrc=3305256354,
cname="9iW3jspLCZJ5WjOZ",
msid="bbgewhUzS6hvFDlSlrhQ6zYlwW7ttRrK8QeQ 420c6f28-439d-4ead-b93c-94e14c0a16b4",
mslabel="bbgewhUzS6hvFDlSlrhQ6zYlwW7ttRrK8QeQ",
label="420c6f28-439d-4ead-b93c-94e14c0a16b4",
),
],
)
self.assertEqual(
d.media[0].ssrc_group,
[GroupDescription(semantic="FID", items=[1845476211, 3305256354])],
)
# formats
self.assertEqual(d.media[0].fmt, [96, 97, 98, 99, 100, 101, 102])
self.assertEqual(d.media[0].sctpmap, {})
self.assertEqual(d.media[0].sctp_port, None)
# ice
self.assertEqual(len(d.media[0].ice_candidates), 2)
self.assertEqual(d.media[0].ice_candidates_complete, False)
self.assertEqual(d.media[0].ice_options, "trickle")
self.assertEqual(d.media[0].ice.iceLite, False)
self.assertEqual(d.media[0].ice.usernameFragment, "9KhP")
self.assertEqual(d.media[0].ice.password, "mlPea2xBCmFmNLfmy/jlqw1D")
# dtls
self.assertEqual(len(d.media[0].dtls.fingerprints), 1)
self.assertEqual(d.media[0].dtls.fingerprints[0].algorithm, "sha-256")
self.assertEqual(
d.media[0].dtls.fingerprints[0].value,
"30:4A:BF:65:23:D1:99:AB:AE:9F:FD:5D:B1:08:4F:09:7C:9F:F2:CC:50:16:13:81:1B:5D:DD:D0:98:45:81:1E",
)
self.assertEqual(d.media[0].dtls.role, "auto")
self.assertEqual(
str(d),
lf2crlf(
"""v=0
o=- 5195484278799753993 2 IN IP4 127.0.0.1
s=-
t=0 0
a=group:BUNDLE video
a=msid-semantic:WMS bbgewhUzS6hvFDlSlrhQ6zYlwW7ttRrK8QeQ
m=video 34955 UDP/TLS/RTP/SAVPF 96 97 98 99 100 101 102
c=IN IP4 10.101.2.67
a=sendrecv
a=extmap:2 urn:ietf:params:rtp-hdrext:toffset
a=extmap:3 http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time
a=extmap:4 urn:3gpp:video-orientation
a=extmap:5 http://www.ietf.org/id/draft-holmer-rmcat-transport-wide-cc-extensions-01
a=extmap:6 http://www.webrtc.org/experiments/rtp-hdrext/playout-delay
a=extmap:7 http://www.webrtc.org/experiments/rtp-hdrext/video-content-type
a=extmap:8 http://www.webrtc.org/experiments/rtp-hdrext/video-timing
a=mid:video
a=rtcp:9 IN IP4 0.0.0.0
a=rtcp-mux
a=ssrc-group:FID 1845476211 3305256354
a=ssrc:1845476211 cname:9iW3jspLCZJ5WjOZ
a=ssrc:1845476211 msid:bbgewhUzS6hvFDlSlrhQ6zYlwW7ttRrK8QeQ 420c6f28-439d-4ead-b93c-94e14c0a16b4
a=ssrc:1845476211 mslabel:bbgewhUzS6hvFDlSlrhQ6zYlwW7ttRrK8QeQ
a=ssrc:1845476211 label:420c6f28-439d-4ead-b93c-94e14c0a16b4
a=ssrc:3305256354 cname:9iW3jspLCZJ5WjOZ
a=ssrc:3305256354 msid:bbgewhUzS6hvFDlSlrhQ6zYlwW7ttRrK8QeQ 420c6f28-439d-4ead-b93c-94e14c0a16b4
a=ssrc:3305256354 mslabel:bbgewhUzS6hvFDlSlrhQ6zYlwW7ttRrK8QeQ
a=ssrc:3305256354 label:420c6f28-439d-4ead-b93c-94e14c0a16b4
a=rtpmap:96 VP8/90000
a=rtcp-fb:96 goog-remb
a=rtcp-fb:96 transport-cc
a=rtcp-fb:96 ccm fir
a=rtcp-fb:96 nack
a=rtcp-fb:96 nack pli
a=rtpmap:97 rtx/90000
a=fmtp:97 apt=96
a=rtpmap:98 VP9/90000
a=rtcp-fb:98 goog-remb
a=rtcp-fb:98 transport-cc
a=rtcp-fb:98 ccm fir
a=rtcp-fb:98 nack
a=rtcp-fb:98 nack pli
a=rtpmap:99 rtx/90000
a=fmtp:99 apt=98
a=rtpmap:100 red/90000
a=rtpmap:101 rtx/90000
a=fmtp:101 apt=100
a=rtpmap:102 ulpfec/90000
a=candidate:638323114 1 udp 2122260223 10.101.2.67 34955 typ host
a=candidate:1754264922 1 tcp 1518280447 10.101.2.67 9 typ host tcptype active
a=ice-ufrag:9KhP
a=ice-pwd:mlPea2xBCmFmNLfmy/jlqw1D
a=ice-options:trickle
a=fingerprint:sha-256 30:4A:BF:65:23:D1:99:AB:AE:9F:FD:5D:B1:08:4F:09:7C:9F:F2:CC:50:16:13:81:1B:5D:DD:D0:98:45:81:1E
a=setup:actpass
"""
),
) | v=0
o=- 5195484278799753993 2 IN IP4 127.0.0.1
s=-
t=0 0
a=group:BUNDLE video
a=msid-semantic: WMS bbgewhUzS6hvFDlSlrhQ6zYlwW7ttRrK8QeQ
m=video 34955 UDP/TLS/RTP/SAVPF 96 97 98 99 100 101 102
c=IN IP4 10.101.2.67
a=rtcp:9 IN IP4 0.0.0.0
a=candidate:638323114 1 udp 2122260223 10.101.2.67 34955 typ host generation 0 network-id 2 network-cost 10
a=candidate:1754264922 1 tcp 1518280447 10.101.2.67 9 typ host tcptype active generation 0 network-id 2 network-cost 10
a=ice-ufrag:9KhP
a=ice-pwd:mlPea2xBCmFmNLfmy/jlqw1D
a=ice-options:trickle
a=fingerprint:sha-256 30:4A:BF:65:23:D1:99:AB:AE:9F:FD:5D:B1:08:4F:09:7C:9F:F2:CC:50:16:13:81:1B:5D:DD:D0:98:45:81:1E
a=setup:actpass
a=mid:video
a=extmap:2 urn:ietf:params:rtp-hdrext:toffset
a=extmap:3 http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time
a=extmap:4 urn:3gpp:video-orientation
a=extmap:5 http://www.ietf.org/id/draft-holmer-rmcat-transport-wide-cc-extensions-01
a=extmap:6 http://www.webrtc.org/experiments/rtp-hdrext/playout-delay
a=extmap:7 http://www.webrtc.org/experiments/rtp-hdrext/video-content-type
a=extmap:8 http://www.webrtc.org/experiments/rtp-hdrext/video-timing
a=sendrecv
a=rtcp-mux
a=rtcp-rsize
a=rtpmap:96 VP8/90000
a=rtcp-fb:96 goog-remb
a=rtcp-fb:96 transport-cc
a=rtcp-fb:96 ccm fir
a=rtcp-fb:96 nack
a=rtcp-fb:96 nack pli
a=rtpmap:97 rtx/90000
a=fmtp:97 apt=96
a=rtpmap:98 VP9/90000
a=rtcp-fb:98 goog-remb
a=rtcp-fb:98 transport-cc
a=rtcp-fb:98 ccm fir
a=rtcp-fb:98 nack
a=rtcp-fb:98 nack pli
a=rtpmap:99 rtx/90000
a=fmtp:99 apt=98
a=rtpmap:100 red/90000
a=rtpmap:101 rtx/90000
a=fmtp:101 apt=100
a=rtpmap:102 ulpfec/90000
a=ssrc-group:FID 1845476211 3305256354
a=ssrc:1845476211 cname:9iW3jspLCZJ5WjOZ
a=ssrc:1845476211 msid:bbgewhUzS6hvFDlSlrhQ6zYlwW7ttRrK8QeQ 420c6f28-439d-4ead-b93c-94e14c0a16b4
a=ssrc:1845476211 mslabel:bbgewhUzS6hvFDlSlrhQ6zYlwW7ttRrK8QeQ
a=ssrc:1845476211 label:420c6f28-439d-4ead-b93c-94e14c0a16b4
a=ssrc:3305256354 cname:9iW3jspLCZJ5WjOZ
a=ssrc:3305256354 msid:bbgewhUzS6hvFDlSlrhQ6zYlwW7ttRrK8QeQ 420c6f28-439d-4ead-b93c-94e14c0a16b4
a=ssrc:3305256354 mslabel:bbgewhUzS6hvFDlSlrhQ6zYlwW7ttRrK8QeQ
a=ssrc:3305256354 label:420c6f28-439d-4ead-b93c-94e14c0a16b4 | test_video_chrome | python | aiortc/aiortc | tests/test_sdp.py | https://github.com/aiortc/aiortc/blob/master/tests/test_sdp.py | BSD-3-Clause |
def test_video_firefox(self):
d = SessionDescription.parse(
lf2crlf(
"""v=0
o=mozilla...THIS_IS_SDPARTA-61.0 8964514366714082732 0 IN IP4 0.0.0.0
s=-
t=0 0
a=sendrecv
a=fingerprint:sha-256 AF:9E:29:99:AC:F6:F6:A2:86:A7:2E:A5:83:94:21:7F:F1:39:C5:E3:8F:E4:08:04:D9:D8:70:6D:6C:A2:A1:D5
a=group:BUNDLE sdparta_0
a=ice-options:trickle
a=msid-semantic:WMS *
m=video 42738 UDP/TLS/RTP/SAVPF 120 121
c=IN IP4 192.168.99.7
a=candidate:0 1 UDP 2122252543 192.168.99.7 42738 typ host
a=candidate:1 1 TCP 2105524479 192.168.99.7 9 typ host tcptype active
a=candidate:0 2 UDP 2122252542 192.168.99.7 52914 typ host
a=candidate:1 2 TCP 2105524478 192.168.99.7 9 typ host tcptype active
a=sendrecv
a=end-of-candidates
a=extmap:3 urn:ietf:params:rtp-hdrext:sdes:mid
a=extmap:4 http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time
a=extmap:5 urn:ietf:params:rtp-hdrext:toffset
a=fmtp:120 max-fs=12288;max-fr=60
a=fmtp:121 max-fs=12288;max-fr=60
a=ice-pwd:c43b0306087bb4de15f70e4405c4dafe
a=ice-ufrag:1a0e6b24
a=mid:sdparta_0
a=msid:{38c9a1f0-d360-4ad8-afe3-4d7f6d4ae4e1} {d27161f3-ab5d-4aff-9dd8-4a24bfbe56d4}
a=rtcp:52914 IN IP4 192.168.99.7
a=rtcp-fb:120 nack
a=rtcp-fb:120 nack pli
a=rtcp-fb:120 ccm fir
a=rtcp-fb:120 goog-remb
a=rtcp-fb:121 nack
a=rtcp-fb:121 nack pli
a=rtcp-fb:121 ccm fir
a=rtcp-fb:121 goog-remb
a=rtcp-mux
a=rtpmap:120 VP8/90000
a=rtpmap:121 VP9/90000
a=setup:actpass
a=ssrc:3408404552 cname:{6f52d07e-17ef-42c5-932b-3b57c64fe049}
"""
)
)
self.assertEqual(
d.group, [GroupDescription(semantic="BUNDLE", items=["sdparta_0"])]
)
self.assertEqual(
d.msid_semantic, [GroupDescription(semantic="WMS", items=["*"])]
)
self.assertEqual(d.host, None)
self.assertEqual(d.name, "-")
self.assertEqual(
d.origin,
"mozilla...THIS_IS_SDPARTA-61.0 8964514366714082732 0 IN IP4 0.0.0.0",
)
self.assertEqual(d.time, "0 0")
self.assertEqual(d.version, 0)
self.assertEqual(len(d.media), 1)
self.assertEqual(d.media[0].kind, "video")
self.assertEqual(d.media[0].host, "192.168.99.7")
self.assertEqual(d.media[0].port, 42738)
self.assertEqual(d.media[0].profile, "UDP/TLS/RTP/SAVPF")
self.assertEqual(d.media[0].direction, "sendrecv")
self.assertEqual(
d.media[0].msid,
"{38c9a1f0-d360-4ad8-afe3-4d7f6d4ae4e1} "
"{d27161f3-ab5d-4aff-9dd8-4a24bfbe56d4}",
)
self.assertEqual(
d.media[0].rtp.codecs,
[
RTCRtpCodecParameters(
mimeType="video/VP8",
clockRate=90000,
payloadType=120,
rtcpFeedback=[
RTCRtcpFeedback(type="nack"),
RTCRtcpFeedback(type="nack", parameter="pli"),
RTCRtcpFeedback(type="ccm", parameter="fir"),
RTCRtcpFeedback(type="goog-remb"),
],
parameters={"max-fs": 12288, "max-fr": 60},
),
RTCRtpCodecParameters(
mimeType="video/VP9",
clockRate=90000,
payloadType=121,
rtcpFeedback=[
RTCRtcpFeedback(type="nack"),
RTCRtcpFeedback(type="nack", parameter="pli"),
RTCRtcpFeedback(type="ccm", parameter="fir"),
RTCRtcpFeedback(type="goog-remb"),
],
parameters={"max-fs": 12288, "max-fr": 60},
),
],
)
self.assertEqual(
d.media[0].rtp.headerExtensions,
[
RTCRtpHeaderExtensionParameters(
id=3, uri="urn:ietf:params:rtp-hdrext:sdes:mid"
),
RTCRtpHeaderExtensionParameters(
id=4,
uri="http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time",
),
RTCRtpHeaderExtensionParameters(
id=5, uri="urn:ietf:params:rtp-hdrext:toffset"
),
],
)
self.assertEqual(d.media[0].rtp.muxId, "sdparta_0")
self.assertEqual(d.media[0].rtcp_host, "192.168.99.7")
self.assertEqual(d.media[0].rtcp_port, 52914)
self.assertEqual(d.media[0].rtcp_mux, True)
self.assertEqual(
d.webrtc_track_id(d.media[0]), "{d27161f3-ab5d-4aff-9dd8-4a24bfbe56d4}"
)
# formats
self.assertEqual(d.media[0].fmt, [120, 121])
self.assertEqual(d.media[0].sctpmap, {})
self.assertEqual(d.media[0].sctp_port, None)
# ice
self.assertEqual(len(d.media[0].ice_candidates), 4)
self.assertEqual(d.media[0].ice_candidates_complete, True)
self.assertEqual(d.media[0].ice_options, "trickle")
self.assertEqual(d.media[0].ice.iceLite, False)
self.assertEqual(d.media[0].ice.usernameFragment, "1a0e6b24")
self.assertEqual(d.media[0].ice.password, "c43b0306087bb4de15f70e4405c4dafe")
# dtls
self.assertEqual(len(d.media[0].dtls.fingerprints), 1)
self.assertEqual(d.media[0].dtls.fingerprints[0].algorithm, "sha-256")
self.assertEqual(
d.media[0].dtls.fingerprints[0].value,
"AF:9E:29:99:AC:F6:F6:A2:86:A7:2E:A5:83:94:21:7F:F1:39:C5:E3:8F:E4:08:04:D9:D8:70:6D:6C:A2:A1:D5",
)
self.assertEqual(d.media[0].dtls.role, "auto")
self.assertEqual(
str(d),
lf2crlf(
"""v=0
o=mozilla...THIS_IS_SDPARTA-61.0 8964514366714082732 0 IN IP4 0.0.0.0
s=-
t=0 0
a=group:BUNDLE sdparta_0
a=msid-semantic:WMS *
m=video 42738 UDP/TLS/RTP/SAVPF 120 121
c=IN IP4 192.168.99.7
a=sendrecv
a=extmap:3 urn:ietf:params:rtp-hdrext:sdes:mid
a=extmap:4 http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time
a=extmap:5 urn:ietf:params:rtp-hdrext:toffset
a=mid:sdparta_0
a=msid:{38c9a1f0-d360-4ad8-afe3-4d7f6d4ae4e1} {d27161f3-ab5d-4aff-9dd8-4a24bfbe56d4}
a=rtcp:52914 IN IP4 192.168.99.7
a=rtcp-mux
a=ssrc:3408404552 cname:{6f52d07e-17ef-42c5-932b-3b57c64fe049}
a=rtpmap:120 VP8/90000
a=rtcp-fb:120 nack
a=rtcp-fb:120 nack pli
a=rtcp-fb:120 ccm fir
a=rtcp-fb:120 goog-remb
a=fmtp:120 max-fs=12288;max-fr=60
a=rtpmap:121 VP9/90000
a=rtcp-fb:121 nack
a=rtcp-fb:121 nack pli
a=rtcp-fb:121 ccm fir
a=rtcp-fb:121 goog-remb
a=fmtp:121 max-fs=12288;max-fr=60
a=candidate:0 1 UDP 2122252543 192.168.99.7 42738 typ host
a=candidate:1 1 TCP 2105524479 192.168.99.7 9 typ host tcptype active
a=candidate:0 2 UDP 2122252542 192.168.99.7 52914 typ host
a=candidate:1 2 TCP 2105524478 192.168.99.7 9 typ host tcptype active
a=end-of-candidates
a=ice-ufrag:1a0e6b24
a=ice-pwd:c43b0306087bb4de15f70e4405c4dafe
a=ice-options:trickle
a=fingerprint:sha-256 AF:9E:29:99:AC:F6:F6:A2:86:A7:2E:A5:83:94:21:7F:F1:39:C5:E3:8F:E4:08:04:D9:D8:70:6D:6C:A2:A1:D5
a=setup:actpass
"""
),
) | v=0
o=mozilla...THIS_IS_SDPARTA-61.0 8964514366714082732 0 IN IP4 0.0.0.0
s=-
t=0 0
a=sendrecv
a=fingerprint:sha-256 AF:9E:29:99:AC:F6:F6:A2:86:A7:2E:A5:83:94:21:7F:F1:39:C5:E3:8F:E4:08:04:D9:D8:70:6D:6C:A2:A1:D5
a=group:BUNDLE sdparta_0
a=ice-options:trickle
a=msid-semantic:WMS *
m=video 42738 UDP/TLS/RTP/SAVPF 120 121
c=IN IP4 192.168.99.7
a=candidate:0 1 UDP 2122252543 192.168.99.7 42738 typ host
a=candidate:1 1 TCP 2105524479 192.168.99.7 9 typ host tcptype active
a=candidate:0 2 UDP 2122252542 192.168.99.7 52914 typ host
a=candidate:1 2 TCP 2105524478 192.168.99.7 9 typ host tcptype active
a=sendrecv
a=end-of-candidates
a=extmap:3 urn:ietf:params:rtp-hdrext:sdes:mid
a=extmap:4 http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time
a=extmap:5 urn:ietf:params:rtp-hdrext:toffset
a=fmtp:120 max-fs=12288;max-fr=60
a=fmtp:121 max-fs=12288;max-fr=60
a=ice-pwd:c43b0306087bb4de15f70e4405c4dafe
a=ice-ufrag:1a0e6b24
a=mid:sdparta_0
a=msid:{38c9a1f0-d360-4ad8-afe3-4d7f6d4ae4e1} {d27161f3-ab5d-4aff-9dd8-4a24bfbe56d4}
a=rtcp:52914 IN IP4 192.168.99.7
a=rtcp-fb:120 nack
a=rtcp-fb:120 nack pli
a=rtcp-fb:120 ccm fir
a=rtcp-fb:120 goog-remb
a=rtcp-fb:121 nack
a=rtcp-fb:121 nack pli
a=rtcp-fb:121 ccm fir
a=rtcp-fb:121 goog-remb
a=rtcp-mux
a=rtpmap:120 VP8/90000
a=rtpmap:121 VP9/90000
a=setup:actpass
a=ssrc:3408404552 cname:{6f52d07e-17ef-42c5-932b-3b57c64fe049} | test_video_firefox | python | aiortc/aiortc | tests/test_sdp.py | https://github.com/aiortc/aiortc/blob/master/tests/test_sdp.py | BSD-3-Clause |
def test_video_session_star_rtcp_fb(self):
d = SessionDescription.parse(
lf2crlf(
"""v=0
o=mozilla...THIS_IS_SDPARTA-61.0 8964514366714082732 0 IN IP4 0.0.0.0
s=-
t=0 0
a=group:BUNDLE sdparta_0
a=msid-semantic:WMS *
m=video 42738 UDP/TLS/RTP/SAVPF 120 121
c=IN IP4 192.168.99.7
a=sendrecv
a=extmap:3 urn:ietf:params:rtp-hdrext:sdes:mid
a=extmap:4 http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time
a=extmap:5 urn:ietf:params:rtp-hdrext:toffset
a=mid:sdparta_0
a=msid:{38c9a1f0-d360-4ad8-afe3-4d7f6d4ae4e1} {d27161f3-ab5d-4aff-9dd8-4a24bfbe56d4}
a=rtcp:52914 IN IP4 192.168.99.7
a=rtcp-mux
a=ssrc:3408404552 cname:{6f52d07e-17ef-42c5-932b-3b57c64fe049}
a=rtpmap:120 VP8/90000
a=fmtp:120 max-fs=12288;max-fr=60
a=rtpmap:121 VP9/90000
a=fmtp:121 max-fs=12288;max-fr=60
a=rtcp-fb:* nack
a=rtcp-fb:* nack pli
a=rtcp-fb:* goog-remb
a=candidate:0 1 UDP 2122252543 192.168.99.7 42738 typ host
a=candidate:1 1 TCP 2105524479 192.168.99.7 9 typ host tcptype active
a=candidate:0 2 UDP 2122252542 192.168.99.7 52914 typ host
a=candidate:1 2 TCP 2105524478 192.168.99.7 9 typ host tcptype active
a=end-of-candidates
a=ice-ufrag:1a0e6b24
a=ice-pwd:c43b0306087bb4de15f70e4405c4dafe
a=ice-options:trickle
a=fingerprint:sha-256 AF:9E:29:99:AC:F6:F6:A2:86:A7:2E:A5:83:94:21:7F:F1:39:C5:E3:8F:E4:08:04:D9:D8:70:6D:6C:A2:A1:D5
a=setup:actpass
"""
)
)
self.assertEqual(
d.media[0].rtp.codecs,
[
RTCRtpCodecParameters(
mimeType="video/VP8",
clockRate=90000,
payloadType=120,
rtcpFeedback=[
RTCRtcpFeedback(type="nack"),
RTCRtcpFeedback(type="nack", parameter="pli"),
RTCRtcpFeedback(type="goog-remb"),
],
parameters={"max-fs": 12288, "max-fr": 60},
),
RTCRtpCodecParameters(
mimeType="video/VP9",
clockRate=90000,
payloadType=121,
rtcpFeedback=[
RTCRtcpFeedback(type="nack"),
RTCRtcpFeedback(type="nack", parameter="pli"),
RTCRtcpFeedback(type="goog-remb"),
],
parameters={"max-fs": 12288, "max-fr": 60},
),
],
) | v=0
o=mozilla...THIS_IS_SDPARTA-61.0 8964514366714082732 0 IN IP4 0.0.0.0
s=-
t=0 0
a=group:BUNDLE sdparta_0
a=msid-semantic:WMS *
m=video 42738 UDP/TLS/RTP/SAVPF 120 121
c=IN IP4 192.168.99.7
a=sendrecv
a=extmap:3 urn:ietf:params:rtp-hdrext:sdes:mid
a=extmap:4 http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time
a=extmap:5 urn:ietf:params:rtp-hdrext:toffset
a=mid:sdparta_0
a=msid:{38c9a1f0-d360-4ad8-afe3-4d7f6d4ae4e1} {d27161f3-ab5d-4aff-9dd8-4a24bfbe56d4}
a=rtcp:52914 IN IP4 192.168.99.7
a=rtcp-mux
a=ssrc:3408404552 cname:{6f52d07e-17ef-42c5-932b-3b57c64fe049}
a=rtpmap:120 VP8/90000
a=fmtp:120 max-fs=12288;max-fr=60
a=rtpmap:121 VP9/90000
a=fmtp:121 max-fs=12288;max-fr=60
a=rtcp-fb:* nack
a=rtcp-fb:* nack pli
a=rtcp-fb:* goog-remb
a=candidate:0 1 UDP 2122252543 192.168.99.7 42738 typ host
a=candidate:1 1 TCP 2105524479 192.168.99.7 9 typ host tcptype active
a=candidate:0 2 UDP 2122252542 192.168.99.7 52914 typ host
a=candidate:1 2 TCP 2105524478 192.168.99.7 9 typ host tcptype active
a=end-of-candidates
a=ice-ufrag:1a0e6b24
a=ice-pwd:c43b0306087bb4de15f70e4405c4dafe
a=ice-options:trickle
a=fingerprint:sha-256 AF:9E:29:99:AC:F6:F6:A2:86:A7:2E:A5:83:94:21:7F:F1:39:C5:E3:8F:E4:08:04:D9:D8:70:6D:6C:A2:A1:D5
a=setup:actpass | test_video_session_star_rtcp_fb | python | aiortc/aiortc | tests/test_sdp.py | https://github.com/aiortc/aiortc/blob/master/tests/test_sdp.py | BSD-3-Clause |
def test_safari(self):
d = SessionDescription.parse(
lf2crlf(
"""
v=0
o=- 8148572839875102105 2 IN IP4 127.0.0.1
s=-
t=0 0
a=group:BUNDLE audio video data
a=msid-semantic: WMS cb7e185b-6110-4f65-b027-ddb8b5fa78c7
m=audio 61015 UDP/TLS/RTP/SAVPF 111 103 9 102 0 8 105 13 110 113 126
c=IN IP4 1.2.3.4
a=rtcp:9 IN IP4 0.0.0.0
a=candidate:3317362580 1 udp 2113937151 192.168.0.87 61015 typ host generation 0 network-cost 999
a=candidate:3103151263 1 udp 2113939711 2a01:e0a:151:dc10:a8cb:5e93:9627:557c 61016 typ host generation 0 network-cost 999
a=candidate:842163049 1 udp 1677729535 1.2.3.4 61015 typ srflx raddr 192.168.0.87 rport 61015 generation 0 network-cost 999
a=ice-ufrag:XSmV
a=ice-pwd:Ss5xY4RMFEJASRvK5TIPgLN9
a=ice-options:trickle
a=fingerprint:sha-256 F2:68:A5:17:E7:85:D6:4E:23:F1:5D:02:39:9E:0F:B5:EA:C0:BD:FC:F5:27:3E:38:9B:BA:4E:AF:8B:35:AF:89
a=setup:actpass
a=mid:audio
a=extmap:1 urn:ietf:params:rtp-hdrext:ssrc-audio-level
a=sendrecv
a=rtcp-mux
a=rtpmap:111 opus/48000/2
a=rtcp-fb:111 transport-cc
a=fmtp:111 minptime=10;useinbandfec=1
a=rtpmap:103 ISAC/16000
a=rtpmap:9 G722/8000
a=rtpmap:102 ILBC/8000
a=rtpmap:0 PCMU/8000
a=rtpmap:8 PCMA/8000
a=rtpmap:105 CN/16000
a=rtpmap:13 CN/8000
a=rtpmap:110 telephone-event/48000
a=rtpmap:113 telephone-event/16000
a=rtpmap:126 telephone-event/8000
a=ssrc:205815247 cname:JTNiIZ6eJ7ghkHaB
a=ssrc:205815247 msid:cb7e185b-6110-4f65-b027-ddb8b5fa78c7 f473166a-7fe5-4ab6-a3af-c5eb806a13b9
a=ssrc:205815247 mslabel:cb7e185b-6110-4f65-b027-ddb8b5fa78c7
a=ssrc:205815247 label:f473166a-7fe5-4ab6-a3af-c5eb806a13b9
m=video 51044 UDP/TLS/RTP/SAVPF 96 97 98 99 100 101 127 125 104
c=IN IP4 1.2.3.4
a=rtcp:9 IN IP4 0.0.0.0
a=candidate:3317362580 1 udp 2113937151 192.168.0.87 51044 typ host generation 0 network-cost 999
a=candidate:3103151263 1 udp 2113939711 2a01:e0a:151:dc10:a8cb:5e93:9627:557c 51045 typ host generation 0 network-cost 999
a=candidate:842163049 1 udp 1677729535 82.64.133.208 51044 typ srflx raddr 192.168.0.87 rport 51044 generation 0 network-cost 999
a=ice-ufrag:XSmV
a=ice-pwd:Ss5xY4RMFEJASRvK5TIPgLN9
a=ice-options:trickle
a=fingerprint:sha-256 F2:68:A5:17:E7:85:D6:4E:23:F1:5D:02:39:9E:0F:B5:EA:C0:BD:FC:F5:27:3E:38:9B:BA:4E:AF:8B:35:AF:89
a=setup:actpass
a=mid:video
a=extmap:2 urn:ietf:params:rtp-hdrext:toffset
a=extmap:3 http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time
a=extmap:4 urn:3gpp:video-orientation
a=extmap:5 http://www.ietf.org/id/draft-holmer-rmcat-transport-wide-cc-extensions-01
a=extmap:6 http://www.webrtc.org/experiments/rtp-hdrext/playout-delay
a=extmap:7 http://www.webrtc.org/experiments/rtp-hdrext/video-content-type
a=extmap:8 http://www.webrtc.org/experiments/rtp-hdrext/video-timing
a=extmap:10 http://tools.ietf.org/html/draft-ietf-avtext-framemarking-07
a=sendrecv
a=rtcp-mux
a=rtcp-rsize
a=rtpmap:96 H264/90000
a=rtcp-fb:96 goog-remb
a=rtcp-fb:96 transport-cc
a=rtcp-fb:96 ccm fir
a=rtcp-fb:96 nack
a=rtcp-fb:96 nack pli
a=fmtp:96 level-asymmetry-allowed=1;packetization-mode=1;profile-level-id=640c1f
a=rtpmap:97 rtx/90000
a=fmtp:97 apt=96
a=rtpmap:98 H264/90000
a=rtcp-fb:98 goog-remb
a=rtcp-fb:98 transport-cc
a=rtcp-fb:98 ccm fir
a=rtcp-fb:98 nack
a=rtcp-fb:98 nack pli
a=fmtp:98 level-asymmetry-allowed=1;packetization-mode=1;profile-level-id=42e01f
a=rtpmap:99 rtx/90000
a=fmtp:99 apt=98
a=rtpmap:100 VP8/90000
a=rtcp-fb:100 goog-remb
a=rtcp-fb:100 transport-cc
a=rtcp-fb:100 ccm fir
a=rtcp-fb:100 nack
a=rtcp-fb:100 nack pli
a=rtpmap:101 rtx/90000
a=fmtp:101 apt=100
a=rtpmap:127 red/90000
a=rtpmap:125 rtx/90000
a=fmtp:125 apt=127
a=rtpmap:104 ulpfec/90000
a=ssrc-group:FID 11942296 149700150
a=ssrc:11942296 cname:JTNiIZ6eJ7ghkHaB
a=ssrc:11942296 msid:cb7e185b-6110-4f65-b027-ddb8b5fa78c7 bd201f69-1364-40da-828f-cc695ff54a37
a=ssrc:11942296 mslabel:cb7e185b-6110-4f65-b027-ddb8b5fa78c7
a=ssrc:11942296 label:bd201f69-1364-40da-828f-cc695ff54a37
a=ssrc:149700150 cname:JTNiIZ6eJ7ghkHaB
a=ssrc:149700150 msid:cb7e185b-6110-4f65-b027-ddb8b5fa78c7 bd201f69-1364-40da-828f-cc695ff54a37
a=ssrc:149700150 mslabel:cb7e185b-6110-4f65-b027-ddb8b5fa78c7
a=ssrc:149700150 label:bd201f69-1364-40da-828f-cc695ff54a37
m=application 60277 DTLS/SCTP 5000
c=IN IP4 1.2.3.4
a=candidate:3317362580 1 udp 2113937151 192.168.0.87 60277 typ host generation 0 network-cost 999
a=candidate:3103151263 1 udp 2113939711 2a01:e0a:151:dc10:a8cb:5e93:9627:557c 60278 typ host generation 0 network-cost 999
a=candidate:842163049 1 udp 1677729535 82.64.133.208 60277 typ srflx raddr 192.168.0.87 rport 60277 generation 0 network-cost 999
a=ice-ufrag:XSmV
a=ice-pwd:Ss5xY4RMFEJASRvK5TIPgLN9
a=ice-options:trickle
a=fingerprint:sha-256 F2:68:A5:17:E7:85:D6:4E:23:F1:5D:02:39:9E:0F:B5:EA:C0:BD:FC:F5:27:3E:38:9B:BA:4E:AF:8B:35:AF:89
a=setup:actpass
a=mid:data
a=sctpmap:5000 webrtc-datachannel 1024
"""
)
)
self.assertEqual(
d.group,
[GroupDescription(semantic="BUNDLE", items=["audio", "video", "data"])],
)
self.assertEqual(
d.msid_semantic,
[
GroupDescription(
semantic="WMS", items=["cb7e185b-6110-4f65-b027-ddb8b5fa78c7"]
)
],
)
self.assertEqual(d.host, None)
self.assertEqual(d.name, "-")
self.assertEqual(d.origin, "- 8148572839875102105 2 IN IP4 127.0.0.1")
self.assertEqual(d.time, "0 0")
self.assertEqual(d.version, 0)
self.assertEqual(len(d.media), 3)
self.assertEqual(d.media[0].kind, "audio")
self.assertEqual(d.media[0].host, "1.2.3.4")
self.assertEqual(d.media[0].port, 61015)
self.assertEqual(d.media[0].profile, "UDP/TLS/RTP/SAVPF")
self.assertEqual(d.media[0].direction, "sendrecv")
self.assertEqual(d.media[0].msid, None)
self.assertEqual(d.webrtc_track_id(d.media[0]), None)
self.assertEqual(d.media[1].kind, "video")
self.assertEqual(d.media[1].host, "1.2.3.4")
self.assertEqual(d.media[1].port, 51044)
self.assertEqual(d.media[1].profile, "UDP/TLS/RTP/SAVPF")
self.assertEqual(d.media[1].direction, "sendrecv")
self.assertEqual(d.media[1].msid, None)
self.assertEqual(d.webrtc_track_id(d.media[0]), None)
self.assertEqual(d.media[2].kind, "application")
self.assertEqual(d.media[2].host, "1.2.3.4")
self.assertEqual(d.media[2].port, 60277)
self.assertEqual(d.media[2].profile, "DTLS/SCTP")
self.assertEqual(d.media[2].direction, None)
self.assertEqual(d.media[2].msid, None) | v=0
o=- 8148572839875102105 2 IN IP4 127.0.0.1
s=-
t=0 0
a=group:BUNDLE audio video data
a=msid-semantic: WMS cb7e185b-6110-4f65-b027-ddb8b5fa78c7
m=audio 61015 UDP/TLS/RTP/SAVPF 111 103 9 102 0 8 105 13 110 113 126
c=IN IP4 1.2.3.4
a=rtcp:9 IN IP4 0.0.0.0
a=candidate:3317362580 1 udp 2113937151 192.168.0.87 61015 typ host generation 0 network-cost 999
a=candidate:3103151263 1 udp 2113939711 2a01:e0a:151:dc10:a8cb:5e93:9627:557c 61016 typ host generation 0 network-cost 999
a=candidate:842163049 1 udp 1677729535 1.2.3.4 61015 typ srflx raddr 192.168.0.87 rport 61015 generation 0 network-cost 999
a=ice-ufrag:XSmV
a=ice-pwd:Ss5xY4RMFEJASRvK5TIPgLN9
a=ice-options:trickle
a=fingerprint:sha-256 F2:68:A5:17:E7:85:D6:4E:23:F1:5D:02:39:9E:0F:B5:EA:C0:BD:FC:F5:27:3E:38:9B:BA:4E:AF:8B:35:AF:89
a=setup:actpass
a=mid:audio
a=extmap:1 urn:ietf:params:rtp-hdrext:ssrc-audio-level
a=sendrecv
a=rtcp-mux
a=rtpmap:111 opus/48000/2
a=rtcp-fb:111 transport-cc
a=fmtp:111 minptime=10;useinbandfec=1
a=rtpmap:103 ISAC/16000
a=rtpmap:9 G722/8000
a=rtpmap:102 ILBC/8000
a=rtpmap:0 PCMU/8000
a=rtpmap:8 PCMA/8000
a=rtpmap:105 CN/16000
a=rtpmap:13 CN/8000
a=rtpmap:110 telephone-event/48000
a=rtpmap:113 telephone-event/16000
a=rtpmap:126 telephone-event/8000
a=ssrc:205815247 cname:JTNiIZ6eJ7ghkHaB
a=ssrc:205815247 msid:cb7e185b-6110-4f65-b027-ddb8b5fa78c7 f473166a-7fe5-4ab6-a3af-c5eb806a13b9
a=ssrc:205815247 mslabel:cb7e185b-6110-4f65-b027-ddb8b5fa78c7
a=ssrc:205815247 label:f473166a-7fe5-4ab6-a3af-c5eb806a13b9
m=video 51044 UDP/TLS/RTP/SAVPF 96 97 98 99 100 101 127 125 104
c=IN IP4 1.2.3.4
a=rtcp:9 IN IP4 0.0.0.0
a=candidate:3317362580 1 udp 2113937151 192.168.0.87 51044 typ host generation 0 network-cost 999
a=candidate:3103151263 1 udp 2113939711 2a01:e0a:151:dc10:a8cb:5e93:9627:557c 51045 typ host generation 0 network-cost 999
a=candidate:842163049 1 udp 1677729535 82.64.133.208 51044 typ srflx raddr 192.168.0.87 rport 51044 generation 0 network-cost 999
a=ice-ufrag:XSmV
a=ice-pwd:Ss5xY4RMFEJASRvK5TIPgLN9
a=ice-options:trickle
a=fingerprint:sha-256 F2:68:A5:17:E7:85:D6:4E:23:F1:5D:02:39:9E:0F:B5:EA:C0:BD:FC:F5:27:3E:38:9B:BA:4E:AF:8B:35:AF:89
a=setup:actpass
a=mid:video
a=extmap:2 urn:ietf:params:rtp-hdrext:toffset
a=extmap:3 http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time
a=extmap:4 urn:3gpp:video-orientation
a=extmap:5 http://www.ietf.org/id/draft-holmer-rmcat-transport-wide-cc-extensions-01
a=extmap:6 http://www.webrtc.org/experiments/rtp-hdrext/playout-delay
a=extmap:7 http://www.webrtc.org/experiments/rtp-hdrext/video-content-type
a=extmap:8 http://www.webrtc.org/experiments/rtp-hdrext/video-timing
a=extmap:10 http://tools.ietf.org/html/draft-ietf-avtext-framemarking-07
a=sendrecv
a=rtcp-mux
a=rtcp-rsize
a=rtpmap:96 H264/90000
a=rtcp-fb:96 goog-remb
a=rtcp-fb:96 transport-cc
a=rtcp-fb:96 ccm fir
a=rtcp-fb:96 nack
a=rtcp-fb:96 nack pli
a=fmtp:96 level-asymmetry-allowed=1;packetization-mode=1;profile-level-id=640c1f
a=rtpmap:97 rtx/90000
a=fmtp:97 apt=96
a=rtpmap:98 H264/90000
a=rtcp-fb:98 goog-remb
a=rtcp-fb:98 transport-cc
a=rtcp-fb:98 ccm fir
a=rtcp-fb:98 nack
a=rtcp-fb:98 nack pli
a=fmtp:98 level-asymmetry-allowed=1;packetization-mode=1;profile-level-id=42e01f
a=rtpmap:99 rtx/90000
a=fmtp:99 apt=98
a=rtpmap:100 VP8/90000
a=rtcp-fb:100 goog-remb
a=rtcp-fb:100 transport-cc
a=rtcp-fb:100 ccm fir
a=rtcp-fb:100 nack
a=rtcp-fb:100 nack pli
a=rtpmap:101 rtx/90000
a=fmtp:101 apt=100
a=rtpmap:127 red/90000
a=rtpmap:125 rtx/90000
a=fmtp:125 apt=127
a=rtpmap:104 ulpfec/90000
a=ssrc-group:FID 11942296 149700150
a=ssrc:11942296 cname:JTNiIZ6eJ7ghkHaB
a=ssrc:11942296 msid:cb7e185b-6110-4f65-b027-ddb8b5fa78c7 bd201f69-1364-40da-828f-cc695ff54a37
a=ssrc:11942296 mslabel:cb7e185b-6110-4f65-b027-ddb8b5fa78c7
a=ssrc:11942296 label:bd201f69-1364-40da-828f-cc695ff54a37
a=ssrc:149700150 cname:JTNiIZ6eJ7ghkHaB
a=ssrc:149700150 msid:cb7e185b-6110-4f65-b027-ddb8b5fa78c7 bd201f69-1364-40da-828f-cc695ff54a37
a=ssrc:149700150 mslabel:cb7e185b-6110-4f65-b027-ddb8b5fa78c7
a=ssrc:149700150 label:bd201f69-1364-40da-828f-cc695ff54a37
m=application 60277 DTLS/SCTP 5000
c=IN IP4 1.2.3.4
a=candidate:3317362580 1 udp 2113937151 192.168.0.87 60277 typ host generation 0 network-cost 999
a=candidate:3103151263 1 udp 2113939711 2a01:e0a:151:dc10:a8cb:5e93:9627:557c 60278 typ host generation 0 network-cost 999
a=candidate:842163049 1 udp 1677729535 82.64.133.208 60277 typ srflx raddr 192.168.0.87 rport 60277 generation 0 network-cost 999
a=ice-ufrag:XSmV
a=ice-pwd:Ss5xY4RMFEJASRvK5TIPgLN9
a=ice-options:trickle
a=fingerprint:sha-256 F2:68:A5:17:E7:85:D6:4E:23:F1:5D:02:39:9E:0F:B5:EA:C0:BD:FC:F5:27:3E:38:9B:BA:4E:AF:8B:35:AF:89
a=setup:actpass
a=mid:data
a=sctpmap:5000 webrtc-datachannel 1024 | test_safari | python | aiortc/aiortc | tests/test_sdp.py | https://github.com/aiortc/aiortc/blob/master/tests/test_sdp.py | BSD-3-Clause |
async def recv(self) -> Packet:
"""
Receive the next :class:`~av.packet.Packet`.
The base implementation dummy packet h264 for tests
"""
pts, time_base = await self.next_timestamp()
header = [0, 0, 0, 1]
buffer = header + [0] * 1020
packet = Packet(len(buffer))
packet.update(bytes(buffer))
packet.pts = pts
packet.time_base = time_base
return packet | Receive the next :class:`~av.packet.Packet`.
The base implementation dummy packet h264 for tests | recv | python | aiortc/aiortc | tests/test_mediastreams.py | https://github.com/aiortc/aiortc/blob/master/tests/test_mediastreams.py | BSD-3-Clause |
def create_packet(self, payload: bytes, pts: int) -> Packet:
"""
Create a packet.
"""
packet = Packet(len(payload))
packet.update(payload)
packet.pts = pts
packet.time_base = fractions.Fraction(1, 1000)
return packet | Create a packet. | create_packet | python | aiortc/aiortc | tests/codecs.py | https://github.com/aiortc/aiortc/blob/master/tests/codecs.py | BSD-3-Clause |
def create_video_frame(
self, width, height, pts, format="yuv420p", time_base=VIDEO_TIME_BASE
):
"""
Create a single blank video frame.
"""
frame = VideoFrame(width=width, height=height, format=format)
for p in frame.planes:
p.update(bytes(p.buffer_size))
frame.pts = pts
frame.time_base = time_base
return frame | Create a single blank video frame. | create_video_frame | python | aiortc/aiortc | tests/codecs.py | https://github.com/aiortc/aiortc/blob/master/tests/codecs.py | BSD-3-Clause |
def create_video_frames(self, width, height, count, time_base=VIDEO_TIME_BASE):
"""
Create consecutive blank video frames.
"""
frames = []
for i in range(count):
frames.append(
self.create_video_frame(
width=width,
height=height,
pts=int(i / time_base / 30),
time_base=time_base,
)
)
return frames | Create consecutive blank video frames. | create_video_frames | python | aiortc/aiortc | tests/codecs.py | https://github.com/aiortc/aiortc/blob/master/tests/codecs.py | BSD-3-Clause |
def roundtrip_audio(
self,
codec,
output_layout,
output_sample_rate,
input_layout="mono",
input_sample_rate=8000,
drop=[],
):
"""
Round-trip an AudioFrame through encoder then decoder.
"""
encoder = get_encoder(codec)
decoder = get_decoder(codec)
input_frames = self.create_audio_frames(
layout=input_layout, sample_rate=input_sample_rate, count=10
)
output_sample_count = int(output_sample_rate * AUDIO_PTIME)
for i, frame in enumerate(input_frames):
# encode
packages, timestamp = encoder.encode(frame)
if i not in drop:
# depacketize
data = b""
for package in packages:
data += depayload(codec, package)
# decode
frames = decoder.decode(JitterFrame(data=data, timestamp=timestamp))
self.assertEqual(len(frames), 1)
self.assertEqual(frames[0].format.name, "s16")
self.assertEqual(frames[0].layout.name, output_layout)
self.assertEqual(frames[0].samples, output_sample_rate * AUDIO_PTIME)
self.assertEqual(frames[0].sample_rate, output_sample_rate)
self.assertEqual(frames[0].pts, i * output_sample_count)
self.assertEqual(
frames[0].time_base, fractions.Fraction(1, output_sample_rate)
) | Round-trip an AudioFrame through encoder then decoder. | roundtrip_audio | python | aiortc/aiortc | tests/codecs.py | https://github.com/aiortc/aiortc/blob/master/tests/codecs.py | BSD-3-Clause |
def roundtrip_video(self, codec, width, height, time_base=VIDEO_TIME_BASE):
"""
Round-trip a VideoFrame through encoder then decoder.
"""
encoder = get_encoder(codec)
decoder = get_decoder(codec)
input_frames = self.create_video_frames(
width=width, height=height, count=30, time_base=time_base
)
for i, frame in enumerate(input_frames):
# encode
packages, timestamp = encoder.encode(frame)
# depacketize
data = b""
for package in packages:
data += depayload(codec, package)
# decode
frames = decoder.decode(JitterFrame(data=data, timestamp=timestamp))
self.assertEqual(len(frames), 1)
self.assertEqual(frames[0].width, frame.width)
self.assertEqual(frames[0].height, frame.height)
self.assertEqual(frames[0].pts, i * 3000)
self.assertEqual(frames[0].time_base, VIDEO_TIME_BASE) | Round-trip a VideoFrame through encoder then decoder. | roundtrip_video | python | aiortc/aiortc | tests/codecs.py | https://github.com/aiortc/aiortc/blob/master/tests/codecs.py | BSD-3-Clause |
def bufferedAmount(self) -> int:
"""
The number of bytes of data currently queued to be sent over the data channel.
"""
return self.__bufferedAmount | The number of bytes of data currently queued to be sent over the data channel. | bufferedAmount | python | aiortc/aiortc | src/aiortc/rtcdatachannel.py | https://github.com/aiortc/aiortc/blob/master/src/aiortc/rtcdatachannel.py | BSD-3-Clause |
def bufferedAmountLowThreshold(self) -> int:
"""
The number of bytes of buffered outgoing data that is considered "low".
"""
return self.__bufferedAmountLowThreshold | The number of bytes of buffered outgoing data that is considered "low". | bufferedAmountLowThreshold | python | aiortc/aiortc | src/aiortc/rtcdatachannel.py | https://github.com/aiortc/aiortc/blob/master/src/aiortc/rtcdatachannel.py | BSD-3-Clause |
def negotiated(self) -> bool:
"""
Whether data channel was negotiated out-of-band.
"""
return self.__parameters.negotiated | Whether data channel was negotiated out-of-band. | negotiated | python | aiortc/aiortc | src/aiortc/rtcdatachannel.py | https://github.com/aiortc/aiortc/blob/master/src/aiortc/rtcdatachannel.py | BSD-3-Clause |
def id(self) -> Optional[int]:
"""
An ID number which uniquely identifies the data channel.
"""
return self.__id | An ID number which uniquely identifies the data channel. | id | python | aiortc/aiortc | src/aiortc/rtcdatachannel.py | https://github.com/aiortc/aiortc/blob/master/src/aiortc/rtcdatachannel.py | BSD-3-Clause |
def label(self) -> str:
"""
A name describing the data channel.
These labels are not required to be unique.
"""
return self.__parameters.label | A name describing the data channel.
These labels are not required to be unique. | label | python | aiortc/aiortc | src/aiortc/rtcdatachannel.py | https://github.com/aiortc/aiortc/blob/master/src/aiortc/rtcdatachannel.py | BSD-3-Clause |
def ordered(self) -> bool:
"""
Indicates whether or not the data channel guarantees in-order delivery of
messages.
"""
return self.__parameters.ordered | Indicates whether or not the data channel guarantees in-order delivery of
messages. | ordered | python | aiortc/aiortc | src/aiortc/rtcdatachannel.py | https://github.com/aiortc/aiortc/blob/master/src/aiortc/rtcdatachannel.py | BSD-3-Clause |
def maxPacketLifeTime(self) -> Optional[int]:
"""
The maximum time in milliseconds during which transmissions are attempted.
"""
return self.__parameters.maxPacketLifeTime | The maximum time in milliseconds during which transmissions are attempted. | maxPacketLifeTime | python | aiortc/aiortc | src/aiortc/rtcdatachannel.py | https://github.com/aiortc/aiortc/blob/master/src/aiortc/rtcdatachannel.py | BSD-3-Clause |
def maxRetransmits(self) -> Optional[int]:
"""
"The maximum number of retransmissions that are attempted.
"""
return self.__parameters.maxRetransmits | "The maximum number of retransmissions that are attempted. | maxRetransmits | python | aiortc/aiortc | src/aiortc/rtcdatachannel.py | https://github.com/aiortc/aiortc/blob/master/src/aiortc/rtcdatachannel.py | BSD-3-Clause |
def protocol(self) -> str:
"""
The name of the subprotocol in use.
"""
return self.__parameters.protocol | The name of the subprotocol in use. | protocol | python | aiortc/aiortc | src/aiortc/rtcdatachannel.py | https://github.com/aiortc/aiortc/blob/master/src/aiortc/rtcdatachannel.py | BSD-3-Clause |
def readyState(self) -> str:
"""
A string indicating the current state of the underlying data transport.
"""
return self.__readyState | A string indicating the current state of the underlying data transport. | readyState | python | aiortc/aiortc | src/aiortc/rtcdatachannel.py | https://github.com/aiortc/aiortc/blob/master/src/aiortc/rtcdatachannel.py | BSD-3-Clause |
def transport(self):
"""
The :class:`RTCSctpTransport` over which data is transmitted.
"""
return self.__transport | The :class:`RTCSctpTransport` over which data is transmitted. | transport | python | aiortc/aiortc | src/aiortc/rtcdatachannel.py | https://github.com/aiortc/aiortc/blob/master/src/aiortc/rtcdatachannel.py | BSD-3-Clause |
def close(self) -> None:
"""
Close the data channel.
"""
self.transport._data_channel_close(self) | Close the data channel. | close | python | aiortc/aiortc | src/aiortc/rtcdatachannel.py | https://github.com/aiortc/aiortc/blob/master/src/aiortc/rtcdatachannel.py | BSD-3-Clause |
def send(self, data: Union[bytes, str]) -> None:
"""
Send `data` across the data channel to the remote peer.
"""
if self.readyState != "open":
raise InvalidStateError
if not isinstance(data, (str, bytes)):
raise ValueError(f"Cannot send unsupported data type: {type(data)}")
self.transport._data_channel_send(self, data) | Send `data` across the data channel to the remote peer. | send | python | aiortc/aiortc | src/aiortc/rtcdatachannel.py | https://github.com/aiortc/aiortc/blob/master/src/aiortc/rtcdatachannel.py | BSD-3-Clause |
def pack_remb_fci(bitrate: int, ssrcs: List[int]) -> bytes:
"""
Pack the FCI for a Receiver Estimated Maximum Bitrate report.
https://tools.ietf.org/html/draft-alvestrand-rmcat-remb-03
"""
data = b"REMB"
exponent = 0
mantissa = bitrate
while mantissa > 0x3FFFF:
mantissa >>= 1
exponent += 1
data += pack(
"!BBH", len(ssrcs), (exponent << 2) | (mantissa >> 16), (mantissa & 0xFFFF)
)
for ssrc in ssrcs:
data += pack("!L", ssrc)
return data | Pack the FCI for a Receiver Estimated Maximum Bitrate report.
https://tools.ietf.org/html/draft-alvestrand-rmcat-remb-03 | pack_remb_fci | python | aiortc/aiortc | src/aiortc/rtp.py | https://github.com/aiortc/aiortc/blob/master/src/aiortc/rtp.py | BSD-3-Clause |
def unpack_remb_fci(data: bytes) -> Tuple[int, List[int]]:
"""
Unpack the FCI for a Receiver Estimated Maximum Bitrate report.
https://tools.ietf.org/html/draft-alvestrand-rmcat-remb-03
"""
if len(data) < 8 or data[0:4] != b"REMB":
raise ValueError("Invalid REMB prefix")
exponent = (data[5] & 0xFC) >> 2
mantissa = ((data[5] & 0x03) << 16) | (data[6] << 8) | data[7]
bitrate = mantissa << exponent
pos = 8
ssrcs = []
for r in range(data[4]):
ssrcs.append(unpack_from("!L", data, pos)[0])
pos += 4
return (bitrate, ssrcs) | Unpack the FCI for a Receiver Estimated Maximum Bitrate report.
https://tools.ietf.org/html/draft-alvestrand-rmcat-remb-03 | unpack_remb_fci | python | aiortc/aiortc | src/aiortc/rtp.py | https://github.com/aiortc/aiortc/blob/master/src/aiortc/rtp.py | BSD-3-Clause |
def padl(length: int) -> int:
"""
Return amount of padding needed for a 4-byte multiple.
"""
return 4 * ((length + 3) // 4) - length | Return amount of padding needed for a 4-byte multiple. | padl | python | aiortc/aiortc | src/aiortc/rtp.py | https://github.com/aiortc/aiortc/blob/master/src/aiortc/rtp.py | BSD-3-Clause |
def unpack_header_extensions(
extension_profile: int, extension_value: bytes
) -> List[Tuple[int, bytes]]:
"""
Parse header extensions according to RFC 5285.
"""
extensions = []
pos = 0
if extension_profile == 0xBEDE:
# One-Byte Header
while pos < len(extension_value):
# skip padding byte
if extension_value[pos] == 0:
pos += 1
continue
x_id = (extension_value[pos] & 0xF0) >> 4
x_length = (extension_value[pos] & 0x0F) + 1
pos += 1
if len(extension_value) < pos + x_length:
raise ValueError("RTP one-byte header extension value is truncated")
x_value = extension_value[pos : pos + x_length]
extensions.append((x_id, x_value))
pos += x_length
elif extension_profile == 0x1000:
# Two-Byte Header
while pos < len(extension_value):
# skip padding byte
if extension_value[pos] == 0:
pos += 1
continue
if len(extension_value) < pos + 2:
raise ValueError("RTP two-byte header extension is truncated")
x_id, x_length = unpack_from("!BB", extension_value, pos)
pos += 2
if len(extension_value) < pos + x_length:
raise ValueError("RTP two-byte header extension value is truncated")
x_value = extension_value[pos : pos + x_length]
extensions.append((x_id, x_value))
pos += x_length
return extensions | Parse header extensions according to RFC 5285. | unpack_header_extensions | python | aiortc/aiortc | src/aiortc/rtp.py | https://github.com/aiortc/aiortc/blob/master/src/aiortc/rtp.py | BSD-3-Clause |
def pack_header_extensions(extensions: List[Tuple[int, bytes]]) -> Tuple[int, bytes]:
"""
Serialize header extensions according to RFC 5285.
"""
extension_profile = 0
extension_value = b""
if not extensions:
return extension_profile, extension_value
one_byte = True
for x_id, x_value in extensions:
x_length = len(x_value)
assert x_id > 0 and x_id < 256
assert x_length >= 0 and x_length < 256
if x_id > 14 or x_length == 0 or x_length > 16:
one_byte = False
if one_byte:
# One-Byte Header
extension_profile = 0xBEDE
extension_value = b""
for x_id, x_value in extensions:
x_length = len(x_value)
extension_value += pack("!B", (x_id << 4) | (x_length - 1))
extension_value += x_value
else:
# Two-Byte Header
extension_profile = 0x1000
extension_value = b""
for x_id, x_value in extensions:
x_length = len(x_value)
extension_value += pack("!BB", x_id, x_length)
extension_value += x_value
extension_value += b"\x00" * padl(len(extension_value))
return extension_profile, extension_value | Serialize header extensions according to RFC 5285. | pack_header_extensions | python | aiortc/aiortc | src/aiortc/rtp.py | https://github.com/aiortc/aiortc/blob/master/src/aiortc/rtp.py | BSD-3-Clause |
def compute_audio_level_dbov(frame: AudioFrame) -> int:
"""
Compute the energy level as spelled out in RFC 6465, Appendix A.
"""
MAX_SAMPLE_VALUE = 32767
MAX_AUDIO_LEVEL = 0
MIN_AUDIO_LEVEL = -127
rms = 0.0
buf = bytes(frame.planes[0])
s = struct.Struct("h")
for unpacked in s.iter_unpack(buf):
sample = unpacked[0]
rms += sample * sample
rms = math.sqrt(rms / (frame.samples * MAX_SAMPLE_VALUE * MAX_SAMPLE_VALUE))
if rms > 0:
db = 20 * math.log10(rms)
db = max(db, MIN_AUDIO_LEVEL)
db = min(db, MAX_AUDIO_LEVEL)
else:
db = MIN_AUDIO_LEVEL
return round(db) | Compute the energy level as spelled out in RFC 6465, Appendix A. | compute_audio_level_dbov | python | aiortc/aiortc | src/aiortc/rtp.py | https://github.com/aiortc/aiortc/blob/master/src/aiortc/rtp.py | BSD-3-Clause |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.