2 * Copyright 2017 Philippe Proulx <pproulx@efficios.com>
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to deal
6 * in the Software without restriction, including without limitation the rights
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 * copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23 #define BT_LOG_TAG "PLUGIN-UTILS-MUXER-FLT"
26 #include <babeltrace/babeltrace-internal.h>
27 #include <babeltrace/compat/uuid-internal.h>
28 #include <babeltrace/babeltrace.h>
29 #include <babeltrace/values-internal.h>
30 #include <babeltrace/graph/component-internal.h>
31 #include <babeltrace/graph/notification-iterator-internal.h>
32 #include <babeltrace/graph/connection-internal.h>
33 #include <plugins-common.h>
37 #include <babeltrace/assert-internal.h>
38 #include <babeltrace/common-internal.h>
42 #define ASSUME_ABSOLUTE_CLOCK_CLASSES_PARAM_NAME "assume-absolute-clock-classes"
47 * bt_self_notification_iterator *
50 GPtrArray
*muxer_notif_iters
;
53 struct bt_self_component_filter
*self_comp
;
55 unsigned int next_port_num
;
56 size_t available_input_ports
;
57 bool initializing_muxer_notif_iter
;
58 bool assume_absolute_clock_classes
;
61 struct muxer_upstream_notif_iter
{
62 /* Owned by this, NULL if ended */
63 struct bt_self_component_port_input_notification_iterator
*notif_iter
;
65 /* Contains `struct bt_notification *`, owned by this */
69 enum muxer_notif_iter_clock_class_expectation
{
70 MUXER_NOTIF_ITER_CLOCK_CLASS_EXPECTATION_ANY
= 0,
71 MUXER_NOTIF_ITER_CLOCK_CLASS_EXPECTATION_ABSOLUTE
,
72 MUXER_NOTIF_ITER_CLOCK_CLASS_EXPECTATION_NOT_ABS_SPEC_UUID
,
73 MUXER_NOTIF_ITER_CLOCK_CLASS_EXPECTATION_NOT_ABS_NO_UUID
,
76 struct muxer_notif_iter
{
78 * Array of struct muxer_upstream_notif_iter * (owned by this).
80 * NOTE: This array is searched in linearly to find the youngest
81 * current notification. Keep this until benchmarks confirm that
82 * another data structure is faster than this for our typical
85 GPtrArray
*muxer_upstream_notif_iters
;
88 * List of "recently" connected input ports (weak) to
89 * handle by this muxer notification iterator.
90 * muxer_port_connected() adds entries to this list, and the
91 * entries are removed when a notification iterator is created
92 * on the port's connection and put into
93 * muxer_upstream_notif_iters above by
94 * muxer_notif_iter_handle_newly_connected_ports().
96 GList
*newly_connected_self_ports
;
98 /* Last time returned in a notification */
99 int64_t last_returned_ts_ns
;
101 /* Clock class expectation state */
102 enum muxer_notif_iter_clock_class_expectation clock_class_expectation
;
105 * Expected clock class UUID, only valid when
106 * clock_class_expectation is
107 * MUXER_NOTIF_ITER_CLOCK_CLASS_EXPECTATION_NOT_ABS_SPEC_UUID.
109 unsigned char expected_clock_class_uuid
[BABELTRACE_UUID_LEN
];
113 void destroy_muxer_upstream_notif_iter(
114 struct muxer_upstream_notif_iter
*muxer_upstream_notif_iter
)
116 if (!muxer_upstream_notif_iter
) {
120 BT_LOGD("Destroying muxer's upstream notification iterator wrapper: "
121 "addr=%p, notif-iter-addr=%p, queue-len=%u",
122 muxer_upstream_notif_iter
,
123 muxer_upstream_notif_iter
->notif_iter
,
124 muxer_upstream_notif_iter
->notifs
->length
);
125 bt_object_put_ref(muxer_upstream_notif_iter
->notif_iter
);
127 if (muxer_upstream_notif_iter
->notifs
) {
128 struct bt_notification
*notif
;
130 while ((notif
= g_queue_pop_head(
131 muxer_upstream_notif_iter
->notifs
))) {
132 bt_object_put_ref(notif
);
135 g_queue_free(muxer_upstream_notif_iter
->notifs
);
138 g_free(muxer_upstream_notif_iter
);
142 struct muxer_upstream_notif_iter
*muxer_notif_iter_add_upstream_notif_iter(
143 struct muxer_notif_iter
*muxer_notif_iter
,
144 struct bt_self_component_port_input_notification_iterator
*self_notif_iter
)
146 struct muxer_upstream_notif_iter
*muxer_upstream_notif_iter
=
147 g_new0(struct muxer_upstream_notif_iter
, 1);
149 if (!muxer_upstream_notif_iter
) {
150 BT_LOGE_STR("Failed to allocate one muxer's upstream notification iterator wrapper.");
154 muxer_upstream_notif_iter
->notif_iter
= bt_object_get_ref(self_notif_iter
);
155 muxer_upstream_notif_iter
->notifs
= g_queue_new();
156 if (!muxer_upstream_notif_iter
->notifs
) {
157 BT_LOGE_STR("Failed to allocate a GQueue.");
161 g_ptr_array_add(muxer_notif_iter
->muxer_upstream_notif_iters
,
162 muxer_upstream_notif_iter
);
163 BT_LOGD("Added muxer's upstream notification iterator wrapper: "
164 "addr=%p, muxer-notif-iter-addr=%p, notif-iter-addr=%p",
165 muxer_upstream_notif_iter
, muxer_notif_iter
,
169 return muxer_upstream_notif_iter
;
173 enum bt_self_component_status
ensure_available_input_port(
174 struct bt_self_component_filter
*self_comp
)
176 struct muxer_comp
*muxer_comp
= bt_self_component_get_data(
177 bt_self_component_filter_borrow_self_component(self_comp
));
178 enum bt_self_component_status status
= BT_SELF_COMPONENT_STATUS_OK
;
179 GString
*port_name
= NULL
;
181 BT_ASSERT(muxer_comp
);
183 if (muxer_comp
->available_input_ports
>= 1) {
187 port_name
= g_string_new("in");
189 BT_LOGE_STR("Failed to allocate a GString.");
190 status
= BT_SELF_COMPONENT_STATUS_NOMEM
;
194 g_string_append_printf(port_name
, "%u", muxer_comp
->next_port_num
);
195 status
= bt_self_component_filter_add_input_port(
196 self_comp
, port_name
->str
, NULL
, NULL
);
197 if (status
!= BT_SELF_COMPONENT_STATUS_OK
) {
198 BT_LOGE("Cannot add input port to muxer component: "
199 "port-name=\"%s\", comp-addr=%p, status=%s",
200 port_name
->str
, self_comp
,
201 bt_self_component_status_string(status
));
205 muxer_comp
->available_input_ports
++;
206 muxer_comp
->next_port_num
++;
207 BT_LOGD("Added one input port to muxer component: "
208 "port-name=\"%s\", comp-addr=%p",
209 port_name
->str
, self_comp
);
212 g_string_free(port_name
, TRUE
);
219 enum bt_self_component_status
create_output_port(
220 struct bt_self_component_filter
*self_comp
)
222 return bt_self_component_filter_add_output_port(
223 self_comp
, "out", NULL
, NULL
);
227 void destroy_muxer_comp(struct muxer_comp
*muxer_comp
)
233 BT_LOGD("Destroying muxer component: muxer-comp-addr=%p, "
234 "muxer-notif-iter-count=%u", muxer_comp
,
235 muxer_comp
->muxer_notif_iters
?
236 muxer_comp
->muxer_notif_iters
->len
: 0);
238 if (muxer_comp
->muxer_notif_iters
) {
239 g_ptr_array_free(muxer_comp
->muxer_notif_iters
, TRUE
);
246 struct bt_private_value
*get_default_params(void)
248 struct bt_private_value
*params
;
251 params
= bt_private_value_map_create();
253 BT_LOGE_STR("Cannot create a map value object.");
257 ret
= bt_private_value_map_insert_bool_entry(params
,
258 ASSUME_ABSOLUTE_CLOCK_CLASSES_PARAM_NAME
, false);
260 BT_LOGE_STR("Cannot add boolean value to map value object.");
267 BT_OBJECT_PUT_REF_AND_RESET(params
);
274 int configure_muxer_comp(struct muxer_comp
*muxer_comp
, struct bt_value
*params
)
276 struct bt_private_value
*default_params
= NULL
;
277 struct bt_private_value
*real_params
= NULL
;
278 struct bt_value
*assume_absolute_clock_classes
= NULL
;
282 default_params
= get_default_params();
283 if (!default_params
) {
284 BT_LOGE("Cannot get default parameters: "
285 "muxer-comp-addr=%p", muxer_comp
);
289 ret
= bt_value_map_extend(&real_params
,
290 bt_private_value_borrow_value(default_params
), params
);
292 BT_LOGE("Cannot extend default parameters map value: "
293 "muxer-comp-addr=%p, def-params-addr=%p, "
294 "params-addr=%p", muxer_comp
, default_params
,
299 assume_absolute_clock_classes
= bt_value_map_borrow_entry_value(
300 bt_private_value_borrow_value(real_params
),
301 ASSUME_ABSOLUTE_CLOCK_CLASSES_PARAM_NAME
);
302 if (assume_absolute_clock_classes
&&
303 !bt_value_is_bool(assume_absolute_clock_classes
)) {
304 BT_LOGE("Expecting a boolean value for the `%s` parameter: "
305 "muxer-comp-addr=%p, value-type=%s",
306 ASSUME_ABSOLUTE_CLOCK_CLASSES_PARAM_NAME
, muxer_comp
,
307 bt_common_value_type_string(
308 bt_value_get_type(assume_absolute_clock_classes
)));
312 bool_val
= bt_value_bool_get(assume_absolute_clock_classes
);
313 muxer_comp
->assume_absolute_clock_classes
= (bool) bool_val
;
314 BT_LOGD("Configured muxer component: muxer-comp-addr=%p, "
315 "assume-absolute-clock-classes=%d",
316 muxer_comp
, muxer_comp
->assume_absolute_clock_classes
);
323 bt_object_put_ref(default_params
);
324 bt_object_put_ref(real_params
);
329 enum bt_self_component_status
muxer_init(
330 struct bt_self_component_filter
*self_comp
,
331 struct bt_value
*params
, void *init_data
)
334 enum bt_self_component_status status
= BT_SELF_COMPONENT_STATUS_OK
;
335 struct muxer_comp
*muxer_comp
= g_new0(struct muxer_comp
, 1);
337 BT_LOGD("Initializing muxer component: "
338 "comp-addr=%p, params-addr=%p", self_comp
, params
);
341 BT_LOGE_STR("Failed to allocate one muxer component.");
345 ret
= configure_muxer_comp(muxer_comp
, params
);
347 BT_LOGE("Cannot configure muxer component: "
348 "muxer-comp-addr=%p, params-addr=%p",
353 muxer_comp
->muxer_notif_iters
= g_ptr_array_new();
354 if (!muxer_comp
->muxer_notif_iters
) {
355 BT_LOGE_STR("Failed to allocate a GPtrArray.");
359 muxer_comp
->self_comp
= self_comp
;
360 bt_self_component_set_data(
361 bt_self_component_filter_borrow_self_component(self_comp
),
363 status
= ensure_available_input_port(self_comp
);
364 if (status
!= BT_SELF_COMPONENT_STATUS_OK
) {
365 BT_LOGE("Cannot ensure that at least one muxer component's input port is available: "
366 "muxer-comp-addr=%p, status=%s",
368 bt_self_component_status_string(status
));
372 status
= create_output_port(self_comp
);
374 BT_LOGE("Cannot create muxer component's output port: "
375 "muxer-comp-addr=%p, status=%s",
377 bt_self_component_status_string(status
));
381 BT_LOGD("Initialized muxer component: "
382 "comp-addr=%p, params-addr=%p, muxer-comp-addr=%p",
383 self_comp
, params
, muxer_comp
);
388 destroy_muxer_comp(muxer_comp
);
389 bt_self_component_set_data(
390 bt_self_component_filter_borrow_self_component(self_comp
),
393 if (status
== BT_SELF_COMPONENT_STATUS_OK
) {
394 status
= BT_SELF_COMPONENT_STATUS_ERROR
;
402 void muxer_finalize(struct bt_self_component_filter
*self_comp
)
404 struct muxer_comp
*muxer_comp
= bt_self_component_get_data(
405 bt_self_component_filter_borrow_self_component(self_comp
));
407 BT_LOGD("Finalizing muxer component: comp-addr=%p",
409 destroy_muxer_comp(muxer_comp
);
413 struct bt_self_component_port_input_notification_iterator
*
414 create_notif_iter_on_input_port(
415 struct bt_self_component_port_input
*self_port
, int *ret
)
417 struct bt_port
*port
= bt_self_component_port_borrow_port(
418 bt_self_component_port_input_borrow_self_component_port(
420 struct bt_self_component_port_input_notification_iterator
*notif_iter
=
426 BT_ASSERT(bt_port_is_connected(port
));
428 // TODO: Advance the iterator to >= the time of the latest
429 // returned notification by the muxer notification
430 // iterator which creates it.
431 notif_iter
= bt_self_component_port_input_notification_iterator_create(
434 BT_LOGE("Cannot create upstream notification iterator on input port: "
435 "port-addr=%p, port-name=\"%s\"",
436 port
, bt_port_get_name(port
));
441 BT_LOGD("Created upstream notification iterator on input port: "
442 "port-addr=%p, port-name=\"%s\", notif-iter-addr=%p",
443 port
, bt_port_get_name(port
), notif_iter
);
450 enum bt_notification_iterator_status
muxer_upstream_notif_iter_next(
451 struct muxer_upstream_notif_iter
*muxer_upstream_notif_iter
)
453 enum bt_notification_iterator_status status
;
454 bt_notification_array notifs
;
458 BT_LOGV("Calling upstream notification iterator's \"next\" method: "
459 "muxer-upstream-notif-iter-wrap-addr=%p, notif-iter-addr=%p",
460 muxer_upstream_notif_iter
,
461 muxer_upstream_notif_iter
->notif_iter
);
462 status
= bt_self_component_port_input_notification_iterator_next(
463 muxer_upstream_notif_iter
->notif_iter
, ¬ifs
, &count
);
464 BT_LOGV("Upstream notification iterator's \"next\" method returned: "
465 "status=%s", bt_notification_iterator_status_string(status
));
468 case BT_NOTIFICATION_ITERATOR_STATUS_OK
:
470 * Notification iterator's current notification is
471 * valid: it must be considered for muxing operations.
473 BT_LOGV_STR("Validated upstream notification iterator wrapper.");
474 BT_ASSERT(count
> 0);
476 /* Move notifications to our queue */
477 for (i
= 0; i
< count
; i
++) {
479 * Push to tail in order; other side
480 * (muxer_notif_iter_do_next_one()) consumes
481 * from the head first.
483 g_queue_push_tail(muxer_upstream_notif_iter
->notifs
,
487 case BT_NOTIFICATION_ITERATOR_STATUS_AGAIN
:
489 * Notification iterator's current notification is not
490 * valid anymore. Return
491 * BT_NOTIFICATION_ITERATOR_STATUS_AGAIN immediately.
494 case BT_NOTIFICATION_ITERATOR_STATUS_END
: /* Fall-through. */
495 case BT_NOTIFICATION_ITERATOR_STATUS_CANCELED
:
497 * Notification iterator reached the end: release it. It
498 * won't be considered again to find the youngest
501 BT_OBJECT_PUT_REF_AND_RESET(muxer_upstream_notif_iter
->notif_iter
);
502 status
= BT_NOTIFICATION_ITERATOR_STATUS_OK
;
505 /* Error or unsupported status code */
506 BT_LOGE("Error or unsupported status code: "
507 "status-code=%d", status
);
508 status
= BT_NOTIFICATION_ITERATOR_STATUS_ERROR
;
516 int muxer_notif_iter_handle_newly_connected_ports(
517 struct muxer_notif_iter
*muxer_notif_iter
)
521 BT_LOGV("Handling newly connected ports: "
522 "muxer-notif-iter-addr=%p", muxer_notif_iter
);
525 * Here we create one upstream notification iterator for each
526 * newly connected port. We do NOT perform an initial "next" on
527 * those new upstream notification iterators: they are
528 * invalidated, to be validated later. The list of newly
529 * connected ports to handle here is updated by
530 * muxer_port_connected().
533 GList
*node
= muxer_notif_iter
->newly_connected_self_ports
;
534 struct bt_self_component_port_input
*self_port
;
535 struct bt_port
*port
;
536 struct bt_self_component_port_input_notification_iterator
*
537 upstream_notif_iter
= NULL
;
538 struct muxer_upstream_notif_iter
*muxer_upstream_notif_iter
;
544 self_port
= node
->data
;
545 port
= bt_self_component_port_borrow_port(
546 bt_self_component_port_input_borrow_self_component_port(
550 if (!bt_port_is_connected(port
)) {
552 * Looks like this port is not connected
553 * anymore: we can't create an upstream
554 * notification iterator on its (non-existing)
555 * connection in this case.
560 upstream_notif_iter
= create_notif_iter_on_input_port(
563 /* create_notif_iter_on_input_port() logs errors */
564 BT_ASSERT(!upstream_notif_iter
);
568 muxer_upstream_notif_iter
=
569 muxer_notif_iter_add_upstream_notif_iter(
570 muxer_notif_iter
, upstream_notif_iter
);
571 BT_OBJECT_PUT_REF_AND_RESET(upstream_notif_iter
);
572 if (!muxer_upstream_notif_iter
) {
574 * muxer_notif_iter_add_upstream_notif_iter()
581 bt_object_put_ref(upstream_notif_iter
);
582 muxer_notif_iter
->newly_connected_self_ports
=
584 muxer_notif_iter
->newly_connected_self_ports
,
600 int get_notif_ts_ns(struct muxer_comp
*muxer_comp
,
601 struct muxer_notif_iter
*muxer_notif_iter
,
602 struct bt_notification
*notif
, int64_t last_returned_ts_ns
,
605 struct bt_clock_class
*clock_class
= NULL
;
606 struct bt_clock_value
*clock_value
= NULL
;
607 struct bt_event
*event
= NULL
;
609 const unsigned char *cc_uuid
;
611 enum bt_clock_value_status cv_status
= BT_CLOCK_VALUE_STATUS_KNOWN
;
616 BT_LOGV("Getting notification's timestamp: "
617 "muxer-notif-iter-addr=%p, notif-addr=%p, "
618 "last-returned-ts=%" PRId64
,
619 muxer_notif_iter
, notif
, last_returned_ts_ns
);
621 switch (bt_notification_get_type(notif
)) {
622 case BT_NOTIFICATION_TYPE_EVENT
:
623 event
= bt_notification_event_borrow_event(notif
);
625 cv_status
= bt_event_borrow_default_clock_value(event
,
629 case BT_NOTIFICATION_TYPE_INACTIVITY
:
631 bt_notification_inactivity_borrow_default_clock_value(
635 /* All the other notifications have a higher priority */
636 BT_LOGV_STR("Notification has no timestamp: using the last returned timestamp.");
637 *ts_ns
= last_returned_ts_ns
;
641 if (cv_status
!= BT_CLOCK_VALUE_STATUS_KNOWN
) {
642 BT_LOGE_STR("Unsupported unknown clock value.");
648 * If the clock value is missing, then we consider that this
649 * notification has no time. In this case it's always the
653 BT_LOGV_STR("Notification's default clock value is missing: "
654 "using the last returned timestamp.");
655 *ts_ns
= last_returned_ts_ns
;
659 clock_class
= bt_clock_value_borrow_clock_class(clock_value
);
660 BT_ASSERT(clock_class
);
661 cc_uuid
= bt_clock_class_get_uuid(clock_class
);
662 cc_name
= bt_clock_class_get_name(clock_class
);
664 if (muxer_notif_iter
->clock_class_expectation
==
665 MUXER_NOTIF_ITER_CLOCK_CLASS_EXPECTATION_ANY
) {
667 * This is the first clock class that this muxer
668 * notification iterator encounters. Its properties
669 * determine what to expect for the whole lifetime of
670 * the iterator without a true
671 * `assume-absolute-clock-classes` parameter.
673 if (bt_clock_class_is_absolute(clock_class
)) {
674 /* Expect absolute clock classes */
675 muxer_notif_iter
->clock_class_expectation
=
676 MUXER_NOTIF_ITER_CLOCK_CLASS_EXPECTATION_ABSOLUTE
;
680 * Expect non-absolute clock classes
681 * with a specific UUID.
683 muxer_notif_iter
->clock_class_expectation
=
684 MUXER_NOTIF_ITER_CLOCK_CLASS_EXPECTATION_NOT_ABS_SPEC_UUID
;
685 memcpy(muxer_notif_iter
->expected_clock_class_uuid
,
686 cc_uuid
, BABELTRACE_UUID_LEN
);
689 * Expect non-absolute clock classes
692 muxer_notif_iter
->clock_class_expectation
=
693 MUXER_NOTIF_ITER_CLOCK_CLASS_EXPECTATION_NOT_ABS_NO_UUID
;
698 if (!muxer_comp
->assume_absolute_clock_classes
) {
699 switch (muxer_notif_iter
->clock_class_expectation
) {
700 case MUXER_NOTIF_ITER_CLOCK_CLASS_EXPECTATION_ABSOLUTE
:
701 if (!bt_clock_class_is_absolute(clock_class
)) {
702 BT_LOGE("Expecting an absolute clock class, "
703 "but got a non-absolute one: "
704 "clock-class-addr=%p, clock-class-name=\"%s\"",
705 clock_class
, cc_name
);
709 case MUXER_NOTIF_ITER_CLOCK_CLASS_EXPECTATION_NOT_ABS_NO_UUID
:
710 if (bt_clock_class_is_absolute(clock_class
)) {
711 BT_LOGE("Expecting a non-absolute clock class with no UUID, "
712 "but got an absolute one: "
713 "clock-class-addr=%p, clock-class-name=\"%s\"",
714 clock_class
, cc_name
);
719 BT_LOGE("Expecting a non-absolute clock class with no UUID, "
720 "but got one with a UUID: "
721 "clock-class-addr=%p, clock-class-name=\"%s\", "
722 "uuid=\"%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x\"",
723 clock_class
, cc_name
,
724 (unsigned int) cc_uuid
[0],
725 (unsigned int) cc_uuid
[1],
726 (unsigned int) cc_uuid
[2],
727 (unsigned int) cc_uuid
[3],
728 (unsigned int) cc_uuid
[4],
729 (unsigned int) cc_uuid
[5],
730 (unsigned int) cc_uuid
[6],
731 (unsigned int) cc_uuid
[7],
732 (unsigned int) cc_uuid
[8],
733 (unsigned int) cc_uuid
[9],
734 (unsigned int) cc_uuid
[10],
735 (unsigned int) cc_uuid
[11],
736 (unsigned int) cc_uuid
[12],
737 (unsigned int) cc_uuid
[13],
738 (unsigned int) cc_uuid
[14],
739 (unsigned int) cc_uuid
[15]);
743 case MUXER_NOTIF_ITER_CLOCK_CLASS_EXPECTATION_NOT_ABS_SPEC_UUID
:
744 if (bt_clock_class_is_absolute(clock_class
)) {
745 BT_LOGE("Expecting a non-absolute clock class with a specific UUID, "
746 "but got an absolute one: "
747 "clock-class-addr=%p, clock-class-name=\"%s\"",
748 clock_class
, cc_name
);
753 BT_LOGE("Expecting a non-absolute clock class with a specific UUID, "
754 "but got one with no UUID: "
755 "clock-class-addr=%p, clock-class-name=\"%s\"",
756 clock_class
, cc_name
);
760 if (memcmp(muxer_notif_iter
->expected_clock_class_uuid
,
761 cc_uuid
, BABELTRACE_UUID_LEN
) != 0) {
762 BT_LOGE("Expecting a non-absolute clock class with a specific UUID, "
763 "but got one with different UUID: "
764 "clock-class-addr=%p, clock-class-name=\"%s\", "
765 "expected-uuid=\"%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x\", "
766 "uuid=\"%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x\"",
767 clock_class
, cc_name
,
768 (unsigned int) muxer_notif_iter
->expected_clock_class_uuid
[0],
769 (unsigned int) muxer_notif_iter
->expected_clock_class_uuid
[1],
770 (unsigned int) muxer_notif_iter
->expected_clock_class_uuid
[2],
771 (unsigned int) muxer_notif_iter
->expected_clock_class_uuid
[3],
772 (unsigned int) muxer_notif_iter
->expected_clock_class_uuid
[4],
773 (unsigned int) muxer_notif_iter
->expected_clock_class_uuid
[5],
774 (unsigned int) muxer_notif_iter
->expected_clock_class_uuid
[6],
775 (unsigned int) muxer_notif_iter
->expected_clock_class_uuid
[7],
776 (unsigned int) muxer_notif_iter
->expected_clock_class_uuid
[8],
777 (unsigned int) muxer_notif_iter
->expected_clock_class_uuid
[9],
778 (unsigned int) muxer_notif_iter
->expected_clock_class_uuid
[10],
779 (unsigned int) muxer_notif_iter
->expected_clock_class_uuid
[11],
780 (unsigned int) muxer_notif_iter
->expected_clock_class_uuid
[12],
781 (unsigned int) muxer_notif_iter
->expected_clock_class_uuid
[13],
782 (unsigned int) muxer_notif_iter
->expected_clock_class_uuid
[14],
783 (unsigned int) muxer_notif_iter
->expected_clock_class_uuid
[15],
784 (unsigned int) cc_uuid
[0],
785 (unsigned int) cc_uuid
[1],
786 (unsigned int) cc_uuid
[2],
787 (unsigned int) cc_uuid
[3],
788 (unsigned int) cc_uuid
[4],
789 (unsigned int) cc_uuid
[5],
790 (unsigned int) cc_uuid
[6],
791 (unsigned int) cc_uuid
[7],
792 (unsigned int) cc_uuid
[8],
793 (unsigned int) cc_uuid
[9],
794 (unsigned int) cc_uuid
[10],
795 (unsigned int) cc_uuid
[11],
796 (unsigned int) cc_uuid
[12],
797 (unsigned int) cc_uuid
[13],
798 (unsigned int) cc_uuid
[14],
799 (unsigned int) cc_uuid
[15]);
805 BT_LOGF("Unexpected clock class expectation: "
806 "expectation-code=%d",
807 muxer_notif_iter
->clock_class_expectation
);
812 ret
= bt_clock_value_get_ns_from_origin(clock_value
, ts_ns
);
814 BT_LOGE("Cannot get nanoseconds from Epoch of clock value: "
815 "clock-value-addr=%p", clock_value
);
826 BT_LOGV("Found notification's timestamp: "
827 "muxer-notif-iter-addr=%p, notif-addr=%p, "
828 "last-returned-ts=%" PRId64
", ts=%" PRId64
,
829 muxer_notif_iter
, notif
, last_returned_ts_ns
,
837 * This function finds the youngest available notification amongst the
838 * non-ended upstream notification iterators and returns the upstream
839 * notification iterator which has it, or
840 * BT_NOTIFICATION_ITERATOR_STATUS_END if there's no available
843 * This function does NOT:
845 * * Update any upstream notification iterator.
846 * * Check for newly connected ports.
847 * * Check the upstream notification iterators to retry.
849 * On sucess, this function sets *muxer_upstream_notif_iter to the
850 * upstream notification iterator of which the current notification is
851 * the youngest, and sets *ts_ns to its time.
854 enum bt_notification_iterator_status
855 muxer_notif_iter_youngest_upstream_notif_iter(
856 struct muxer_comp
*muxer_comp
,
857 struct muxer_notif_iter
*muxer_notif_iter
,
858 struct muxer_upstream_notif_iter
**muxer_upstream_notif_iter
,
863 int64_t youngest_ts_ns
= INT64_MAX
;
864 enum bt_notification_iterator_status status
=
865 BT_NOTIFICATION_ITERATOR_STATUS_OK
;
867 BT_ASSERT(muxer_comp
);
868 BT_ASSERT(muxer_notif_iter
);
869 BT_ASSERT(muxer_upstream_notif_iter
);
870 *muxer_upstream_notif_iter
= NULL
;
872 for (i
= 0; i
< muxer_notif_iter
->muxer_upstream_notif_iters
->len
; i
++) {
873 struct bt_notification
*notif
;
874 struct muxer_upstream_notif_iter
*cur_muxer_upstream_notif_iter
=
875 g_ptr_array_index(muxer_notif_iter
->muxer_upstream_notif_iters
, i
);
878 if (!cur_muxer_upstream_notif_iter
->notif_iter
) {
879 /* This upstream notification iterator is ended */
880 BT_LOGV("Skipping ended upstream notification iterator: "
881 "muxer-upstream-notif-iter-wrap-addr=%p",
882 cur_muxer_upstream_notif_iter
);
886 BT_ASSERT(cur_muxer_upstream_notif_iter
->notifs
->length
> 0);
887 notif
= g_queue_peek_head(cur_muxer_upstream_notif_iter
->notifs
);
889 ret
= get_notif_ts_ns(muxer_comp
, muxer_notif_iter
, notif
,
890 muxer_notif_iter
->last_returned_ts_ns
, ¬if_ts_ns
);
892 /* get_notif_ts_ns() logs errors */
893 *muxer_upstream_notif_iter
= NULL
;
894 status
= BT_NOTIFICATION_ITERATOR_STATUS_ERROR
;
898 if (notif_ts_ns
<= youngest_ts_ns
) {
899 *muxer_upstream_notif_iter
=
900 cur_muxer_upstream_notif_iter
;
901 youngest_ts_ns
= notif_ts_ns
;
902 *ts_ns
= youngest_ts_ns
;
906 if (!*muxer_upstream_notif_iter
) {
907 status
= BT_NOTIFICATION_ITERATOR_STATUS_END
;
916 enum bt_notification_iterator_status
validate_muxer_upstream_notif_iter(
917 struct muxer_upstream_notif_iter
*muxer_upstream_notif_iter
)
919 enum bt_notification_iterator_status status
=
920 BT_NOTIFICATION_ITERATOR_STATUS_OK
;
922 BT_LOGV("Validating muxer's upstream notification iterator wrapper: "
923 "muxer-upstream-notif-iter-wrap-addr=%p",
924 muxer_upstream_notif_iter
);
926 if (muxer_upstream_notif_iter
->notifs
->length
> 0 ||
927 !muxer_upstream_notif_iter
->notif_iter
) {
928 BT_LOGV("Already valid or not considered: "
929 "queue-len=%u, upstream-notif-iter-addr=%p",
930 muxer_upstream_notif_iter
->notifs
->length
,
931 muxer_upstream_notif_iter
->notif_iter
);
935 /* muxer_upstream_notif_iter_next() logs details/errors */
936 status
= muxer_upstream_notif_iter_next(muxer_upstream_notif_iter
);
943 enum bt_notification_iterator_status
validate_muxer_upstream_notif_iters(
944 struct muxer_notif_iter
*muxer_notif_iter
)
946 enum bt_notification_iterator_status status
=
947 BT_NOTIFICATION_ITERATOR_STATUS_OK
;
950 BT_LOGV("Validating muxer's upstream notification iterator wrappers: "
951 "muxer-notif-iter-addr=%p", muxer_notif_iter
);
953 for (i
= 0; i
< muxer_notif_iter
->muxer_upstream_notif_iters
->len
; i
++) {
954 struct muxer_upstream_notif_iter
*muxer_upstream_notif_iter
=
956 muxer_notif_iter
->muxer_upstream_notif_iters
,
959 status
= validate_muxer_upstream_notif_iter(
960 muxer_upstream_notif_iter
);
961 if (status
!= BT_NOTIFICATION_ITERATOR_STATUS_OK
) {
963 BT_LOGE("Cannot validate muxer's upstream notification iterator wrapper: "
964 "muxer-notif-iter-addr=%p, "
965 "muxer-upstream-notif-iter-wrap-addr=%p",
967 muxer_upstream_notif_iter
);
969 BT_LOGV("Cannot validate muxer's upstream notification iterator wrapper: "
970 "muxer-notif-iter-addr=%p, "
971 "muxer-upstream-notif-iter-wrap-addr=%p",
973 muxer_upstream_notif_iter
);
980 * Remove this muxer upstream notification iterator
981 * if it's ended or canceled.
983 if (!muxer_upstream_notif_iter
->notif_iter
) {
985 * Use g_ptr_array_remove_fast() because the
986 * order of those elements is not important.
988 BT_LOGV("Removing muxer's upstream notification iterator wrapper: ended or canceled: "
989 "muxer-notif-iter-addr=%p, "
990 "muxer-upstream-notif-iter-wrap-addr=%p",
991 muxer_notif_iter
, muxer_upstream_notif_iter
);
992 g_ptr_array_remove_index_fast(
993 muxer_notif_iter
->muxer_upstream_notif_iters
,
1004 enum bt_notification_iterator_status
muxer_notif_iter_do_next_one(
1005 struct muxer_comp
*muxer_comp
,
1006 struct muxer_notif_iter
*muxer_notif_iter
,
1007 struct bt_notification
**notif
)
1009 enum bt_notification_iterator_status status
=
1010 BT_NOTIFICATION_ITERATOR_STATUS_OK
;
1011 struct muxer_upstream_notif_iter
*muxer_upstream_notif_iter
= NULL
;
1012 int64_t next_return_ts
;
1015 int ret
= muxer_notif_iter_handle_newly_connected_ports(
1019 BT_LOGE("Cannot handle newly connected input ports for muxer's notification iterator: "
1020 "muxer-comp-addr=%p, muxer-notif-iter-addr=%p, "
1022 muxer_comp
, muxer_notif_iter
, ret
);
1023 status
= BT_NOTIFICATION_ITERATOR_STATUS_ERROR
;
1027 status
= validate_muxer_upstream_notif_iters(muxer_notif_iter
);
1028 if (status
!= BT_NOTIFICATION_ITERATOR_STATUS_OK
) {
1029 /* validate_muxer_upstream_notif_iters() logs details */
1034 * At this point, we know that all the existing upstream
1035 * notification iterators are valid. However the
1036 * operations to validate them (during
1037 * validate_muxer_upstream_notif_iters()) may have
1038 * connected new ports. If no ports were connected
1039 * during this operation, exit the loop.
1041 if (!muxer_notif_iter
->newly_connected_self_ports
) {
1042 BT_LOGV("Not breaking this loop: muxer's notification iterator still has newly connected input ports to handle: "
1043 "muxer-comp-addr=%p", muxer_comp
);
1048 BT_ASSERT(!muxer_notif_iter
->newly_connected_self_ports
);
1051 * At this point we know that all the existing upstream
1052 * notification iterators are valid. We can find the one,
1053 * amongst those, of which the current notification is the
1056 status
= muxer_notif_iter_youngest_upstream_notif_iter(muxer_comp
,
1057 muxer_notif_iter
, &muxer_upstream_notif_iter
,
1059 if (status
< 0 || status
== BT_NOTIFICATION_ITERATOR_STATUS_END
||
1060 status
== BT_NOTIFICATION_ITERATOR_STATUS_CANCELED
) {
1062 BT_LOGE("Cannot find the youngest upstream notification iterator wrapper: "
1064 bt_notification_iterator_status_string(status
));
1066 BT_LOGV("Cannot find the youngest upstream notification iterator wrapper: "
1068 bt_notification_iterator_status_string(status
));
1074 if (next_return_ts
< muxer_notif_iter
->last_returned_ts_ns
) {
1075 BT_LOGE("Youngest upstream notification iterator wrapper's timestamp is less than muxer's notification iterator's last returned timestamp: "
1076 "muxer-notif-iter-addr=%p, ts=%" PRId64
", "
1077 "last-returned-ts=%" PRId64
,
1078 muxer_notif_iter
, next_return_ts
,
1079 muxer_notif_iter
->last_returned_ts_ns
);
1080 status
= BT_NOTIFICATION_ITERATOR_STATUS_ERROR
;
1084 BT_LOGV("Found youngest upstream notification iterator wrapper: "
1085 "muxer-notif-iter-addr=%p, "
1086 "muxer-upstream-notif-iter-wrap-addr=%p, "
1088 muxer_notif_iter
, muxer_upstream_notif_iter
, next_return_ts
);
1089 BT_ASSERT(status
== BT_NOTIFICATION_ITERATOR_STATUS_OK
);
1090 BT_ASSERT(muxer_upstream_notif_iter
);
1093 * Consume from the queue's head: other side
1094 * (muxer_upstream_notif_iter_next()) writes to the tail.
1096 *notif
= g_queue_pop_head(muxer_upstream_notif_iter
->notifs
);
1098 muxer_notif_iter
->last_returned_ts_ns
= next_return_ts
;
1105 enum bt_notification_iterator_status
muxer_notif_iter_do_next(
1106 struct muxer_comp
*muxer_comp
,
1107 struct muxer_notif_iter
*muxer_notif_iter
,
1108 bt_notification_array notifs
, uint64_t capacity
,
1111 enum bt_notification_iterator_status status
=
1112 BT_NOTIFICATION_ITERATOR_STATUS_OK
;
1115 while (i
< capacity
&& status
== BT_NOTIFICATION_ITERATOR_STATUS_OK
) {
1116 status
= muxer_notif_iter_do_next_one(muxer_comp
,
1117 muxer_notif_iter
, ¬ifs
[i
]);
1118 if (status
== BT_NOTIFICATION_ITERATOR_STATUS_OK
) {
1125 * Even if muxer_notif_iter_do_next_one() returned
1126 * something else than
1127 * BT_NOTIFICATION_ITERATOR_STATUS_OK, we accumulated
1128 * notification objects in the output notification
1129 * array, so we need to return
1130 * BT_NOTIFICATION_ITERATOR_STATUS_OK so that they are
1131 * transfered to downstream. This other status occurs
1132 * again the next time muxer_notif_iter_do_next() is
1133 * called, possibly without any accumulated
1134 * notification, in which case we'll return it.
1137 status
= BT_NOTIFICATION_ITERATOR_STATUS_OK
;
1144 void destroy_muxer_notif_iter(struct muxer_notif_iter
*muxer_notif_iter
)
1146 if (!muxer_notif_iter
) {
1150 BT_LOGD("Destroying muxer component's notification iterator: "
1151 "muxer-notif-iter-addr=%p", muxer_notif_iter
);
1153 if (muxer_notif_iter
->muxer_upstream_notif_iters
) {
1154 BT_LOGD_STR("Destroying muxer's upstream notification iterator wrappers.");
1156 muxer_notif_iter
->muxer_upstream_notif_iters
, TRUE
);
1159 g_list_free(muxer_notif_iter
->newly_connected_self_ports
);
1160 g_free(muxer_notif_iter
);
1164 int muxer_notif_iter_init_newly_connected_ports(struct muxer_comp
*muxer_comp
,
1165 struct muxer_notif_iter
*muxer_notif_iter
)
1172 * Add the connected input ports to this muxer notification
1173 * iterator's list of newly connected ports. They will be
1174 * handled by muxer_notif_iter_handle_newly_connected_ports().
1176 count
= bt_component_filter_get_input_port_count(
1177 bt_self_component_filter_borrow_component_filter(
1178 muxer_comp
->self_comp
));
1180 BT_LOGD("No input port to initialize for muxer component's notification iterator: "
1181 "muxer-comp-addr=%p, muxer-notif-iter-addr=%p",
1182 muxer_comp
, muxer_notif_iter
);
1186 for (i
= 0; i
< count
; i
++) {
1187 struct bt_self_component_port_input
*self_port
=
1188 bt_self_component_filter_borrow_input_port_by_index(
1189 muxer_comp
->self_comp
, i
);
1190 struct bt_port
*port
;
1192 BT_ASSERT(self_port
);
1193 port
= bt_self_component_port_borrow_port(
1194 bt_self_component_port_input_borrow_self_component_port(
1198 if (!bt_port_is_connected(port
)) {
1199 BT_LOGD("Skipping input port: not connected: "
1200 "muxer-comp-addr=%p, port-addr=%p, port-name\"%s\"",
1201 muxer_comp
, port
, bt_port_get_name(port
));
1205 muxer_notif_iter
->newly_connected_self_ports
=
1207 muxer_notif_iter
->newly_connected_self_ports
,
1209 if (!muxer_notif_iter
->newly_connected_self_ports
) {
1210 BT_LOGE("Cannot append port to muxer's notification iterator list of newly connected input ports: "
1211 "port-addr=%p, port-name=\"%s\", "
1212 "muxer-notif-iter-addr=%p", port
,
1213 bt_port_get_name(port
), muxer_notif_iter
);
1218 BT_LOGD("Appended port to muxer's notification iterator list of newly connected input ports: "
1219 "port-addr=%p, port-name=\"%s\", "
1220 "muxer-notif-iter-addr=%p", port
,
1221 bt_port_get_name(port
), muxer_notif_iter
);
1229 enum bt_self_notification_iterator_status
muxer_notif_iter_init(
1230 struct bt_self_notification_iterator
*self_notif_iter
,
1231 struct bt_self_component_filter
*self_comp
,
1232 struct bt_self_component_port_output
*port
)
1234 struct muxer_comp
*muxer_comp
= NULL
;
1235 struct muxer_notif_iter
*muxer_notif_iter
= NULL
;
1236 enum bt_self_notification_iterator_status status
=
1237 BT_NOTIFICATION_ITERATOR_STATUS_OK
;
1240 muxer_comp
= bt_self_component_get_data(
1241 bt_self_component_filter_borrow_self_component(self_comp
));
1242 BT_ASSERT(muxer_comp
);
1243 BT_LOGD("Initializing muxer component's notification iterator: "
1244 "comp-addr=%p, muxer-comp-addr=%p, notif-iter-addr=%p",
1245 self_comp
, muxer_comp
, self_notif_iter
);
1247 if (muxer_comp
->initializing_muxer_notif_iter
) {
1249 * Weird, unhandled situation detected: downstream
1250 * creates a muxer notification iterator while creating
1251 * another muxer notification iterator (same component).
1253 BT_LOGE("Recursive initialization of muxer component's notification iterator: "
1254 "comp-addr=%p, muxer-comp-addr=%p, notif-iter-addr=%p",
1255 self_comp
, muxer_comp
, self_notif_iter
);
1259 muxer_comp
->initializing_muxer_notif_iter
= true;
1260 muxer_notif_iter
= g_new0(struct muxer_notif_iter
, 1);
1261 if (!muxer_notif_iter
) {
1262 BT_LOGE_STR("Failed to allocate one muxer component's notification iterator.");
1266 muxer_notif_iter
->last_returned_ts_ns
= INT64_MIN
;
1267 muxer_notif_iter
->muxer_upstream_notif_iters
=
1268 g_ptr_array_new_with_free_func(
1269 (GDestroyNotify
) destroy_muxer_upstream_notif_iter
);
1270 if (!muxer_notif_iter
->muxer_upstream_notif_iters
) {
1271 BT_LOGE_STR("Failed to allocate a GPtrArray.");
1276 * Add the muxer notification iterator to the component's array
1277 * of muxer notification iterators here because
1278 * muxer_notif_iter_init_newly_connected_ports() can cause
1279 * muxer_port_connected() to be called, which adds the newly
1280 * connected port to each muxer notification iterator's list of
1281 * newly connected ports.
1283 g_ptr_array_add(muxer_comp
->muxer_notif_iters
, muxer_notif_iter
);
1284 ret
= muxer_notif_iter_init_newly_connected_ports(muxer_comp
,
1287 BT_LOGE("Cannot initialize newly connected input ports for muxer component's notification iterator: "
1288 "comp-addr=%p, muxer-comp-addr=%p, "
1289 "muxer-notif-iter-addr=%p, notif-iter-addr=%p, ret=%d",
1290 self_comp
, muxer_comp
, muxer_notif_iter
,
1291 self_notif_iter
, ret
);
1295 bt_self_notification_iterator_set_data(self_notif_iter
,
1297 BT_LOGD("Initialized muxer component's notification iterator: "
1298 "comp-addr=%p, muxer-comp-addr=%p, muxer-notif-iter-addr=%p, "
1299 "notif-iter-addr=%p",
1300 self_comp
, muxer_comp
, muxer_notif_iter
, self_notif_iter
);
1304 if (g_ptr_array_index(muxer_comp
->muxer_notif_iters
,
1305 muxer_comp
->muxer_notif_iters
->len
- 1) == muxer_notif_iter
) {
1306 g_ptr_array_remove_index(muxer_comp
->muxer_notif_iters
,
1307 muxer_comp
->muxer_notif_iters
->len
- 1);
1310 destroy_muxer_notif_iter(muxer_notif_iter
);
1311 bt_self_notification_iterator_set_data(self_notif_iter
,
1313 status
= BT_NOTIFICATION_ITERATOR_STATUS_ERROR
;
1316 muxer_comp
->initializing_muxer_notif_iter
= false;
1321 void muxer_notif_iter_finalize(
1322 struct bt_self_notification_iterator
*self_notif_iter
)
1324 struct muxer_notif_iter
*muxer_notif_iter
=
1325 bt_self_notification_iterator_get_data(self_notif_iter
);
1326 struct bt_self_component
*self_comp
= NULL
;
1327 struct muxer_comp
*muxer_comp
= NULL
;
1329 self_comp
= bt_self_notification_iterator_borrow_component(
1331 BT_ASSERT(self_comp
);
1332 muxer_comp
= bt_self_component_get_data(self_comp
);
1333 BT_LOGD("Finalizing muxer component's notification iterator: "
1334 "comp-addr=%p, muxer-comp-addr=%p, muxer-notif-iter-addr=%p, "
1335 "notif-iter-addr=%p",
1336 self_comp
, muxer_comp
, muxer_notif_iter
, self_notif_iter
);
1339 (void) g_ptr_array_remove_fast(muxer_comp
->muxer_notif_iters
,
1341 destroy_muxer_notif_iter(muxer_notif_iter
);
1346 enum bt_notification_iterator_status
muxer_notif_iter_next(
1347 struct bt_self_notification_iterator
*self_notif_iter
,
1348 bt_notification_array notifs
, uint64_t capacity
,
1351 enum bt_notification_iterator_status status
;
1352 struct muxer_notif_iter
*muxer_notif_iter
=
1353 bt_self_notification_iterator_get_data(self_notif_iter
);
1354 struct bt_self_component
*self_comp
= NULL
;
1355 struct muxer_comp
*muxer_comp
= NULL
;
1357 BT_ASSERT(muxer_notif_iter
);
1358 self_comp
= bt_self_notification_iterator_borrow_component(
1360 BT_ASSERT(self_comp
);
1361 muxer_comp
= bt_self_component_get_data(self_comp
);
1362 BT_ASSERT(muxer_comp
);
1363 BT_LOGV("Muxer component's notification iterator's \"next\" method called: "
1364 "comp-addr=%p, muxer-comp-addr=%p, muxer-notif-iter-addr=%p, "
1365 "notif-iter-addr=%p",
1366 self_comp
, muxer_comp
, muxer_notif_iter
, self_notif_iter
);
1368 status
= muxer_notif_iter_do_next(muxer_comp
, muxer_notif_iter
,
1369 notifs
, capacity
, count
);
1371 BT_LOGE("Cannot get next notification: "
1372 "comp-addr=%p, muxer-comp-addr=%p, muxer-notif-iter-addr=%p, "
1373 "notif-iter-addr=%p, status=%s",
1374 self_comp
, muxer_comp
, muxer_notif_iter
, self_notif_iter
,
1375 bt_notification_iterator_status_string(status
));
1377 BT_LOGV("Returning from muxer component's notification iterator's \"next\" method: "
1379 bt_notification_iterator_status_string(status
));
1386 enum bt_self_component_status
muxer_input_port_connected(
1387 struct bt_self_component_filter
*self_comp
,
1388 struct bt_self_component_port_input
*self_port
,
1389 struct bt_port_output
*other_port
)
1391 enum bt_self_component_status status
= BT_SELF_COMPONENT_STATUS_OK
;
1392 struct bt_port
*port
= bt_self_component_port_borrow_port(
1393 bt_self_component_port_input_borrow_self_component_port(
1395 struct muxer_comp
*muxer_comp
=
1396 bt_self_component_get_data(
1397 bt_self_component_filter_borrow_self_component(
1403 BT_ASSERT(muxer_comp
);
1404 BT_LOGD("Port connected: "
1405 "comp-addr=%p, muxer-comp-addr=%p, "
1406 "port-addr=%p, port-name=\"%s\", "
1407 "other-port-addr=%p, other-port-name=\"%s\"",
1408 self_comp
, muxer_comp
, self_port
, bt_port_get_name(port
),
1410 bt_port_get_name(bt_port_output_borrow_port(other_port
)));
1412 for (i
= 0; i
< muxer_comp
->muxer_notif_iters
->len
; i
++) {
1413 struct muxer_notif_iter
*muxer_notif_iter
=
1414 g_ptr_array_index(muxer_comp
->muxer_notif_iters
, i
);
1417 * Add this port to the list of newly connected ports
1418 * for this muxer notification iterator. We append at
1419 * the end of this list while
1420 * muxer_notif_iter_handle_newly_connected_ports()
1421 * removes the nodes from the beginning.
1423 muxer_notif_iter
->newly_connected_self_ports
=
1425 muxer_notif_iter
->newly_connected_self_ports
,
1427 if (!muxer_notif_iter
->newly_connected_self_ports
) {
1428 BT_LOGE("Cannot append port to muxer's notification iterator list of newly connected input ports: "
1429 "port-addr=%p, port-name=\"%s\", "
1430 "muxer-notif-iter-addr=%p", self_port
,
1431 bt_port_get_name(port
), muxer_notif_iter
);
1432 status
= BT_SELF_COMPONENT_STATUS_ERROR
;
1436 BT_LOGD("Appended port to muxer's notification iterator list of newly connected input ports: "
1437 "port-addr=%p, port-name=\"%s\", "
1438 "muxer-notif-iter-addr=%p", self_port
,
1439 bt_port_get_name(port
), muxer_notif_iter
);
1442 /* One less available input port */
1443 muxer_comp
->available_input_ports
--;
1444 ret
= ensure_available_input_port(self_comp
);
1447 * Only way to report an error later since this
1448 * method does not return anything.
1450 BT_LOGE("Cannot ensure that at least one muxer component's input port is available: "
1451 "muxer-comp-addr=%p, status=%s",
1452 muxer_comp
, bt_self_component_status_string(ret
));
1453 status
= BT_SELF_COMPONENT_STATUS_ERROR
;
1462 void muxer_input_port_disconnected(
1463 struct bt_self_component_filter
*self_component
,
1464 struct bt_self_component_port_input
*self_port
)
1466 struct muxer_comp
*muxer_comp
=
1467 bt_self_component_get_data(
1468 bt_self_component_filter_borrow_self_component(
1470 struct bt_port
*port
=
1471 bt_self_component_port_borrow_port(
1472 bt_self_component_port_input_borrow_self_component_port(
1476 BT_ASSERT(muxer_comp
);
1478 /* One more available input port */
1479 muxer_comp
->available_input_ports
++;
1480 BT_LOGD("Leaving disconnected input port available for future connections: "
1481 "comp-addr=%p, muxer-comp-addr=%p, port-addr=%p, "
1482 "port-name=\"%s\", avail-input-port-count=%zu",
1483 self_component
, muxer_comp
, port
, bt_port_get_name(port
),
1484 muxer_comp
->available_input_ports
);