- -

All GStreamer elements

-

This view is for debugging. It shows all GStreamer elements and their status.

+
+

Internal elements

+
+ + +

This view is for debugging. It shows all GStreamer elements and their status.

+
- - +
From e06c1e2c4cbeec43f43776c2d502a88db87dea6e Mon Sep 17 00:00:00 2001 From: Matthew Clark Date: Thu, 1 Nov 2018 14:32:56 +0000 Subject: [PATCH 2/3] A test and logic to support show_inside_bin_elements=yes --- brave/helpers.py | 25 +++++++++++++++------ public/elements_table.html | 6 ++++- tests/test_elements_api_endpoint.py | 35 +++++++++++++++++++++++++++++ 3 files changed, 58 insertions(+), 8 deletions(-) create mode 100644 tests/test_elements_api_endpoint.py diff --git a/brave/helpers.py b/brave/helpers.py index 8a49685..5a9ed27 100644 --- a/brave/helpers.py +++ b/brave/helpers.py @@ -30,24 +30,29 @@ def create_intersink_channel_name(): return 'inter_channel_' + str(channel_count) -def get_pipeline_details(pipeline): +def get_pipeline_details(pipeline, show_inside_bin_elements=True): ''' Given a GStreamer pipeline, returns an object of details about itself. This is used for debugging. ''' elements = [] - def handle_each_element(element): + def handle_each_element(element, parent_element=None): details = { 'name': element.name, - 'type': element.get_factory().name, 'state': element.get_state(0).state.value_nick.upper(), 'pads': {} } - inter_elements = ['interaudiosrc', 'interaudiosink', 'intervideosrc', 'intervideosink'] - if details['type'] in inter_elements: - details['channel'] = element.get_property('channel') + if parent_element is not None: + details['parent'] = parent_element.name + + if element.get_factory() is not None: + details['type'] = element.get_factory().name + + inter_elements = ['interaudiosrc', 'interaudiosink', 'intervideosrc', 'intervideosink'] + if details['type'] in inter_elements: + details['channel'] = element.get_property('channel') def handle_pad(pad): details['pads'][pad.name] = { @@ -65,14 +70,20 @@ def handle_pad(pad): if pad.is_linked(): peer = pad.get_peer() details['pads'][pad.name]['peer'] = { - 'element_name': peer.get_parent_element().name, 'pad_name': peer.name } + parent = peer.get_parent_element() + if parent: + details['pads'][pad.name]['peer']['element_name'] = peer.get_parent_element().name pad_iterator = element.iterate_pads() pad_iterator.foreach(handle_pad) elements.append(details) + if show_inside_bin_elements and hasattr(element, 'iterate_elements'): + iterator = element.iterate_elements() + iterator.foreach(handle_each_element, element) + iterator = pipeline.iterate_elements() iterator.foreach(handle_each_element) diff --git a/public/elements_table.html b/public/elements_table.html index 0d69d8b..8c12415 100644 --- a/public/elements_table.html +++ b/public/elements_table.html @@ -112,11 +112,15 @@

Internal elements

header.append(' ') .append($('').append(state).addClass(data[blockType][blockId].state)) } + table = $('
') table.append(tableHeader) tbody = $('') table.append(tbody) - if (data[blockType][blockId].elements) addElements(tbody, data[blockType][blockId].elements) + if (data[blockType][blockId].elements) { + addElements(tbody, data[blockType][blockId].elements) + header.append(' (' + data[blockType][blockId].elements.length + ' elements)') + } $('#main').append(header, table) }) }) diff --git a/tests/test_elements_api_endpoint.py b/tests/test_elements_api_endpoint.py new file mode 100644 index 0000000..663f569 --- /dev/null +++ b/tests/test_elements_api_endpoint.py @@ -0,0 +1,35 @@ +import time, pytest +from utils import * + + +def test_elements_api_endpoint(run_brave): + ''' + Check that /api/elements returns a list of element details, + including when "?show_inside_bin_elements=yes" + ''' + run_brave() + time.sleep(0.5) + check_brave_is_running() + add_input({'type': 'image', 'props': {'uri': 'file://' + test_directory() + '/assets/image_640_360.png'}}) + time.sleep(1) + + subtest_elements_endpoint() + subtest_elements_endpoint_with_bin_elements() + +def subtest_elements_endpoint(): + elements_response = api_get('/api/elements') + assert elements_response.status_code == 200 + elements_object = elements_response.json() + assert len(elements_object['inputs'].items()) == 1 + assert len(elements_object['mixers'].items()) == 1 + assert len(elements_object['outputs'].items()) == 0 + assert len(elements_object['inputs']['0']['elements']) == 5 + +def subtest_elements_endpoint_with_bin_elements(): + elements_response = api_get('/api/elements?show_inside_bin_elements=yes') + assert elements_response.status_code == 200 + elements_object = elements_response.json() + assert len(elements_object['inputs'].items()) == 1 + assert len(elements_object['mixers'].items()) == 1 + assert len(elements_object['outputs'].items()) == 0 + assert len(elements_object['inputs']['0']['elements']) == 10 From 7ecb187850a52d7575a08620ae5de375cd38db40 Mon Sep 17 00:00:00 2001 From: Matthew Clark Date: Thu, 1 Nov 2018 14:34:26 +0000 Subject: [PATCH 3/3] Remove unnecessary method rename --- brave/api/route_handler.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/brave/api/route_handler.py b/brave/api/route_handler.py index 4255280..b88fb42 100644 --- a/brave/api/route_handler.py +++ b/brave/api/route_handler.py @@ -111,7 +111,7 @@ async def overlay_source(request, id): return _user_error_response('No such input ID') mixer = session.mixers[id] - source = mixer.sources.get_or_create(session.inputs[input_id]) + source = mixer.sources.get_for_input_or_mixer(session.inputs[input_id]) if not source: return _user_error_response('Input is not source on mixer')