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>
41 #define ASSUME_ABSOLUTE_CLOCK_CLASSES_PARAM_NAME "assume-absolute-clock-classes"
46 * bt_private_connection_private_notification_iterator *
49 GPtrArray
*muxer_notif_iters
;
52 struct bt_private_component
*priv_comp
;
53 unsigned int next_port_num
;
54 size_t available_input_ports
;
56 bool initializing_muxer_notif_iter
;
57 bool assume_absolute_clock_classes
;
60 struct muxer_upstream_notif_iter
{
61 /* Owned by this, NULL if ended */
62 struct bt_notification_iterator
*notif_iter
;
64 /* Contains `struct bt_notification *`, owned by this */
68 enum muxer_notif_iter_clock_class_expectation
{
69 MUXER_NOTIF_ITER_CLOCK_CLASS_EXPECTATION_ANY
= 0,
70 MUXER_NOTIF_ITER_CLOCK_CLASS_EXPECTATION_ABSOLUTE
,
71 MUXER_NOTIF_ITER_CLOCK_CLASS_EXPECTATION_NOT_ABS_SPEC_UUID
,
72 MUXER_NOTIF_ITER_CLOCK_CLASS_EXPECTATION_NOT_ABS_NO_UUID
,
75 struct muxer_notif_iter
{
77 * Array of struct muxer_upstream_notif_iter * (owned by this).
79 * NOTE: This array is searched in linearly to find the youngest
80 * current notification. Keep this until benchmarks confirm that
81 * another data structure is faster than this for our typical
84 GPtrArray
*muxer_upstream_notif_iters
;
87 * List of "recently" connected input ports (weak) to
88 * handle by this muxer notification iterator.
89 * muxer_port_connected() adds entries to this list, and the
90 * entries are removed when a notification iterator is created
91 * on the port's connection and put into
92 * muxer_upstream_notif_iters above by
93 * muxer_notif_iter_handle_newly_connected_ports().
95 GList
*newly_connected_priv_ports
;
97 /* Last time returned in a notification */
98 int64_t last_returned_ts_ns
;
100 /* Clock class expectation state */
101 enum muxer_notif_iter_clock_class_expectation clock_class_expectation
;
104 * Expected clock class UUID, only valid when
105 * clock_class_expectation is
106 * MUXER_NOTIF_ITER_CLOCK_CLASS_EXPECTATION_NOT_ABS_SPEC_UUID.
108 unsigned char expected_clock_class_uuid
[BABELTRACE_UUID_LEN
];
112 void destroy_muxer_upstream_notif_iter(
113 struct muxer_upstream_notif_iter
*muxer_upstream_notif_iter
)
115 if (!muxer_upstream_notif_iter
) {
119 BT_LOGD("Destroying muxer's upstream notification iterator wrapper: "
120 "addr=%p, notif-iter-addr=%p, queue-len=%u",
121 muxer_upstream_notif_iter
,
122 muxer_upstream_notif_iter
->notif_iter
,
123 muxer_upstream_notif_iter
->notifs
->length
);
124 bt_put(muxer_upstream_notif_iter
->notif_iter
);
126 if (muxer_upstream_notif_iter
->notifs
) {
127 struct bt_notification
*notif
;
129 while ((notif
= g_queue_pop_head(
130 muxer_upstream_notif_iter
->notifs
))) {
134 g_queue_free(muxer_upstream_notif_iter
->notifs
);
137 g_free(muxer_upstream_notif_iter
);
141 struct muxer_upstream_notif_iter
*muxer_notif_iter_add_upstream_notif_iter(
142 struct muxer_notif_iter
*muxer_notif_iter
,
143 struct bt_notification_iterator
*notif_iter
,
144 struct bt_private_port
*priv_port
)
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_get(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.");
162 g_ptr_array_add(muxer_notif_iter
->muxer_upstream_notif_iters
,
163 muxer_upstream_notif_iter
);
164 BT_LOGD("Added muxer's upstream notification iterator wrapper: "
165 "addr=%p, muxer-notif-iter-addr=%p, notif-iter-addr=%p",
166 muxer_upstream_notif_iter
, muxer_notif_iter
,
170 return muxer_upstream_notif_iter
;
174 enum bt_component_status
ensure_available_input_port(
175 struct bt_private_component
*priv_comp
)
177 struct muxer_comp
*muxer_comp
=
178 bt_private_component_get_user_data(priv_comp
);
179 enum bt_component_status status
= BT_COMPONENT_STATUS_OK
;
180 GString
*port_name
= NULL
;
182 BT_ASSERT(muxer_comp
);
184 if (muxer_comp
->available_input_ports
>= 1) {
188 port_name
= g_string_new("in");
190 BT_LOGE_STR("Failed to allocate a GString.");
191 status
= BT_COMPONENT_STATUS_NOMEM
;
195 g_string_append_printf(port_name
, "%u", muxer_comp
->next_port_num
);
196 status
= bt_private_component_filter_add_input_private_port(
197 priv_comp
, port_name
->str
, NULL
, NULL
);
198 if (status
!= BT_COMPONENT_STATUS_OK
) {
199 BT_LOGE("Cannot add input port to muxer component: "
200 "port-name=\"%s\", comp-addr=%p, status=%s",
201 port_name
->str
, priv_comp
,
202 bt_component_status_string(status
));
206 muxer_comp
->available_input_ports
++;
207 muxer_comp
->next_port_num
++;
208 BT_LOGD("Added one input port to muxer component: "
209 "port-name=\"%s\", comp-addr=%p",
210 port_name
->str
, priv_comp
);
213 g_string_free(port_name
, TRUE
);
220 enum bt_component_status
create_output_port(
221 struct bt_private_component
*priv_comp
)
223 return bt_private_component_filter_add_output_private_port(
224 priv_comp
, "out", NULL
, NULL
);
228 void destroy_muxer_comp(struct muxer_comp
*muxer_comp
)
234 BT_LOGD("Destroying muxer component: muxer-comp-addr=%p, "
235 "muxer-notif-iter-count=%u", muxer_comp
,
236 muxer_comp
->muxer_notif_iters
?
237 muxer_comp
->muxer_notif_iters
->len
: 0);
239 if (muxer_comp
->muxer_notif_iters
) {
240 g_ptr_array_free(muxer_comp
->muxer_notif_iters
, TRUE
);
247 struct bt_value
*get_default_params(void)
249 struct bt_value
*params
;
252 params
= bt_value_map_create();
254 BT_LOGE_STR("Cannot create a map value object.");
258 ret
= bt_value_map_insert_bool(params
,
259 ASSUME_ABSOLUTE_CLOCK_CLASSES_PARAM_NAME
, false);
261 BT_LOGE_STR("Cannot add boolean value to map value object.");
275 int configure_muxer_comp(struct muxer_comp
*muxer_comp
, struct bt_value
*params
)
277 struct bt_value
*default_params
= NULL
;
278 struct bt_value
*real_params
= NULL
;
279 struct bt_value
*assume_absolute_clock_classes
= NULL
;
283 default_params
= get_default_params();
284 if (!default_params
) {
285 BT_LOGE("Cannot get default parameters: "
286 "muxer-comp-addr=%p", muxer_comp
);
290 real_params
= bt_value_map_extend(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(real_params
,
300 ASSUME_ABSOLUTE_CLOCK_CLASSES_PARAM_NAME
);
301 if (assume_absolute_clock_classes
&&
302 !bt_value_is_bool(assume_absolute_clock_classes
)) {
303 BT_LOGE("Expecting a boolean value for the `%s` parameter: "
304 "muxer-comp-addr=%p, value-type=%s",
305 ASSUME_ABSOLUTE_CLOCK_CLASSES_PARAM_NAME
, muxer_comp
,
306 bt_value_type_string(
307 bt_value_get_type(assume_absolute_clock_classes
)));
311 ret
= bt_value_bool_get(assume_absolute_clock_classes
, &bool_val
);
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_put(default_params
);
329 enum bt_component_status
muxer_init(
330 struct bt_private_component
*priv_comp
,
331 struct bt_value
*params
, void *init_data
)
334 enum bt_component_status status
= BT_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", priv_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
->priv_comp
= priv_comp
;
360 ret
= bt_private_component_set_user_data(priv_comp
, muxer_comp
);
362 status
= ensure_available_input_port(priv_comp
);
363 if (status
!= BT_COMPONENT_STATUS_OK
) {
364 BT_LOGE("Cannot ensure that at least one muxer component's input port is available: "
365 "muxer-comp-addr=%p, status=%s",
367 bt_component_status_string(status
));
371 status
= create_output_port(priv_comp
);
373 BT_LOGE("Cannot create muxer component's output port: "
374 "muxer-comp-addr=%p, status=%s",
376 bt_component_status_string(status
));
380 BT_LOGD("Initialized muxer component: "
381 "comp-addr=%p, params-addr=%p, muxer-comp-addr=%p",
382 priv_comp
, params
, muxer_comp
);
387 destroy_muxer_comp(muxer_comp
);
388 ret
= bt_private_component_set_user_data(priv_comp
, NULL
);
391 if (status
== BT_COMPONENT_STATUS_OK
) {
392 status
= BT_COMPONENT_STATUS_ERROR
;
400 void muxer_finalize(struct bt_private_component
*priv_comp
)
402 struct muxer_comp
*muxer_comp
=
403 bt_private_component_get_user_data(priv_comp
);
405 BT_LOGD("Finalizing muxer component: comp-addr=%p",
407 destroy_muxer_comp(muxer_comp
);
411 struct bt_notification_iterator
*create_notif_iter_on_input_port(
412 struct bt_private_port
*priv_port
, int *ret
)
414 struct bt_port
*port
= bt_port_borrow_from_private(priv_port
);
415 struct bt_notification_iterator
*notif_iter
= NULL
;
416 struct bt_private_connection
*priv_conn
= NULL
;
417 enum bt_connection_status conn_status
;
422 BT_ASSERT(bt_port_is_connected(port
));
423 priv_conn
= bt_private_port_get_private_connection(priv_port
);
424 BT_ASSERT(priv_conn
);
426 // TODO: Advance the iterator to >= the time of the latest
427 // returned notification by the muxer notification
428 // iterator which creates it.
429 conn_status
= bt_private_connection_create_notification_iterator(
430 priv_conn
, ¬if_iter
);
431 if (conn_status
!= BT_CONNECTION_STATUS_OK
) {
432 BT_LOGE("Cannot create upstream notification iterator on input port's connection: "
433 "port-addr=%p, port-name=\"%s\", conn-addr=%p, "
435 port
, bt_port_get_name(port
), priv_conn
,
436 bt_connection_status_string(conn_status
));
441 BT_LOGD("Created upstream notification iterator on input port's connection: "
442 "port-addr=%p, port-name=\"%s\", conn-addr=%p, "
443 "notif-iter-addr=%p",
444 port
, bt_port_get_name(port
), priv_conn
, notif_iter
);
452 enum bt_notification_iterator_status
muxer_upstream_notif_iter_next(
453 struct muxer_upstream_notif_iter
*muxer_upstream_notif_iter
)
455 enum bt_notification_iterator_status status
;
456 bt_notification_array notifs
;
460 BT_LOGV("Calling upstream notification iterator's \"next\" method: "
461 "muxer-upstream-notif-iter-wrap-addr=%p, notif-iter-addr=%p",
462 muxer_upstream_notif_iter
,
463 muxer_upstream_notif_iter
->notif_iter
);
464 status
= bt_private_connection_notification_iterator_next(
465 muxer_upstream_notif_iter
->notif_iter
, ¬ifs
, &count
);
466 BT_LOGV("Upstream notification iterator's \"next\" method returned: "
467 "status=%s", bt_notification_iterator_status_string(status
));
470 case BT_NOTIFICATION_ITERATOR_STATUS_OK
:
472 * Notification iterator's current notification is
473 * valid: it must be considered for muxing operations.
475 BT_LOGV_STR("Validated upstream notification iterator wrapper.");
476 BT_ASSERT(count
> 0);
478 /* Move notifications to our queue */
479 for (i
= 0; i
< count
; i
++) {
481 * Push to tail in order; other side
482 * (muxer_notif_iter_do_next_one()) consumes
483 * from the head first.
485 g_queue_push_tail(muxer_upstream_notif_iter
->notifs
,
489 case BT_NOTIFICATION_ITERATOR_STATUS_AGAIN
:
491 * Notification iterator's current notification is not
492 * valid anymore. Return
493 * BT_NOTIFICATION_ITERATOR_STATUS_AGAIN immediately.
496 case BT_NOTIFICATION_ITERATOR_STATUS_END
: /* Fall-through. */
497 case BT_NOTIFICATION_ITERATOR_STATUS_CANCELED
:
499 * Notification iterator reached the end: release it. It
500 * won't be considered again to find the youngest
503 BT_PUT(muxer_upstream_notif_iter
->notif_iter
);
504 status
= BT_NOTIFICATION_ITERATOR_STATUS_OK
;
507 /* Error or unsupported status code */
508 BT_LOGE("Error or unsupported status code: "
509 "status-code=%d", status
);
510 status
= BT_NOTIFICATION_ITERATOR_STATUS_ERROR
;
518 int muxer_notif_iter_handle_newly_connected_ports(
519 struct muxer_notif_iter
*muxer_notif_iter
)
523 BT_LOGV("Handling newly connected ports: "
524 "muxer-notif-iter-addr=%p", muxer_notif_iter
);
527 * Here we create one upstream notification iterator for each
528 * newly connected port. We do NOT perform an initial "next" on
529 * those new upstream notification iterators: they are
530 * invalidated, to be validated later. The list of newly
531 * connected ports to handle here is updated by
532 * muxer_port_connected().
535 GList
*node
= muxer_notif_iter
->newly_connected_priv_ports
;
536 struct bt_private_port
*priv_port
;
537 struct bt_port
*port
;
538 struct bt_notification_iterator
*upstream_notif_iter
= NULL
;
539 struct muxer_upstream_notif_iter
*muxer_upstream_notif_iter
;
545 priv_port
= node
->data
;
546 port
= bt_port_borrow_from_private(priv_port
);
549 if (!bt_port_is_connected(port
)) {
551 * Looks like this port is not connected
552 * anymore: we can't create an upstream
553 * notification iterator on its (non-existing)
554 * connection in this case.
559 upstream_notif_iter
= create_notif_iter_on_input_port(priv_port
,
562 /* create_notif_iter_on_input_port() logs errors */
563 BT_ASSERT(!upstream_notif_iter
);
567 muxer_upstream_notif_iter
=
568 muxer_notif_iter_add_upstream_notif_iter(
569 muxer_notif_iter
, upstream_notif_iter
,
571 BT_PUT(upstream_notif_iter
);
572 if (!muxer_upstream_notif_iter
) {
574 * muxer_notif_iter_add_upstream_notif_iter()
581 bt_put(upstream_notif_iter
);
582 muxer_notif_iter
->newly_connected_priv_ports
=
584 muxer_notif_iter
->newly_connected_priv_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_priority_map
*cc_prio_map
= NULL
;
606 struct bt_clock_class
*clock_class
= NULL
;
607 struct bt_clock_value
*clock_value
= NULL
;
608 struct bt_event
*event
= NULL
;
610 const unsigned char *cc_uuid
;
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
:
624 bt_notification_event_borrow_clock_class_priority_map(
628 case BT_NOTIFICATION_TYPE_INACTIVITY
:
630 bt_notification_inactivity_borrow_clock_class_priority_map(
634 /* All the other notifications have a higher priority */
635 BT_LOGV_STR("Notification has no timestamp: using the last returned timestamp.");
636 *ts_ns
= last_returned_ts_ns
;
641 BT_LOGE("Cannot get notification's clock class priority map: "
642 "notif-addr=%p", notif
);
647 * If the clock class priority map is empty, then we consider
648 * that this notification has no time. In this case it's always
651 if (bt_clock_class_priority_map_get_clock_class_count(cc_prio_map
) == 0) {
652 BT_LOGV_STR("Notification's clock class priority map contains 0 clock classes: "
653 "using the last returned timestamp.");
654 *ts_ns
= last_returned_ts_ns
;
659 bt_clock_class_priority_map_borrow_highest_priority_clock_class(
662 BT_LOGE("Cannot get the clock class with the highest priority from clock class priority map: "
663 "cc-prio-map-addr=%p", cc_prio_map
);
667 cc_uuid
= bt_clock_class_get_uuid(clock_class
);
668 cc_name
= bt_clock_class_get_name(clock_class
);
670 if (muxer_notif_iter
->clock_class_expectation
==
671 MUXER_NOTIF_ITER_CLOCK_CLASS_EXPECTATION_ANY
) {
673 * This is the first clock class that this muxer
674 * notification iterator encounters. Its properties
675 * determine what to expect for the whole lifetime of
676 * the iterator without a true
677 * `assume-absolute-clock-classes` parameter.
679 if (bt_clock_class_is_absolute(clock_class
)) {
680 /* Expect absolute clock classes */
681 muxer_notif_iter
->clock_class_expectation
=
682 MUXER_NOTIF_ITER_CLOCK_CLASS_EXPECTATION_ABSOLUTE
;
686 * Expect non-absolute clock classes
687 * with a specific UUID.
689 muxer_notif_iter
->clock_class_expectation
=
690 MUXER_NOTIF_ITER_CLOCK_CLASS_EXPECTATION_NOT_ABS_SPEC_UUID
;
691 memcpy(muxer_notif_iter
->expected_clock_class_uuid
,
692 cc_uuid
, BABELTRACE_UUID_LEN
);
695 * Expect non-absolute clock classes
698 muxer_notif_iter
->clock_class_expectation
=
699 MUXER_NOTIF_ITER_CLOCK_CLASS_EXPECTATION_NOT_ABS_NO_UUID
;
704 if (!muxer_comp
->assume_absolute_clock_classes
) {
705 switch (muxer_notif_iter
->clock_class_expectation
) {
706 case MUXER_NOTIF_ITER_CLOCK_CLASS_EXPECTATION_ABSOLUTE
:
707 if (!bt_clock_class_is_absolute(clock_class
)) {
708 BT_LOGE("Expecting an absolute clock class, "
709 "but got a non-absolute one: "
710 "clock-class-addr=%p, clock-class-name=\"%s\"",
711 clock_class
, cc_name
);
715 case MUXER_NOTIF_ITER_CLOCK_CLASS_EXPECTATION_NOT_ABS_NO_UUID
:
716 if (bt_clock_class_is_absolute(clock_class
)) {
717 BT_LOGE("Expecting a non-absolute clock class with no UUID, "
718 "but got an absolute one: "
719 "clock-class-addr=%p, clock-class-name=\"%s\"",
720 clock_class
, cc_name
);
725 BT_LOGE("Expecting a non-absolute clock class with no UUID, "
726 "but got one with a UUID: "
727 "clock-class-addr=%p, clock-class-name=\"%s\", "
728 "uuid=\"%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x\"",
729 clock_class
, cc_name
,
730 (unsigned int) cc_uuid
[0],
731 (unsigned int) cc_uuid
[1],
732 (unsigned int) cc_uuid
[2],
733 (unsigned int) cc_uuid
[3],
734 (unsigned int) cc_uuid
[4],
735 (unsigned int) cc_uuid
[5],
736 (unsigned int) cc_uuid
[6],
737 (unsigned int) cc_uuid
[7],
738 (unsigned int) cc_uuid
[8],
739 (unsigned int) cc_uuid
[9],
740 (unsigned int) cc_uuid
[10],
741 (unsigned int) cc_uuid
[11],
742 (unsigned int) cc_uuid
[12],
743 (unsigned int) cc_uuid
[13],
744 (unsigned int) cc_uuid
[14],
745 (unsigned int) cc_uuid
[15]);
749 case MUXER_NOTIF_ITER_CLOCK_CLASS_EXPECTATION_NOT_ABS_SPEC_UUID
:
750 if (bt_clock_class_is_absolute(clock_class
)) {
751 BT_LOGE("Expecting a non-absolute clock class with a specific UUID, "
752 "but got an absolute one: "
753 "clock-class-addr=%p, clock-class-name=\"%s\"",
754 clock_class
, cc_name
);
759 BT_LOGE("Expecting a non-absolute clock class with a specific UUID, "
760 "but got one with no UUID: "
761 "clock-class-addr=%p, clock-class-name=\"%s\"",
762 clock_class
, cc_name
);
766 if (memcmp(muxer_notif_iter
->expected_clock_class_uuid
,
767 cc_uuid
, BABELTRACE_UUID_LEN
) != 0) {
768 BT_LOGE("Expecting a non-absolute clock class with a specific UUID, "
769 "but got one with different UUID: "
770 "clock-class-addr=%p, clock-class-name=\"%s\", "
771 "expected-uuid=\"%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x\", "
772 "uuid=\"%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x\"",
773 clock_class
, cc_name
,
774 (unsigned int) muxer_notif_iter
->expected_clock_class_uuid
[0],
775 (unsigned int) muxer_notif_iter
->expected_clock_class_uuid
[1],
776 (unsigned int) muxer_notif_iter
->expected_clock_class_uuid
[2],
777 (unsigned int) muxer_notif_iter
->expected_clock_class_uuid
[3],
778 (unsigned int) muxer_notif_iter
->expected_clock_class_uuid
[4],
779 (unsigned int) muxer_notif_iter
->expected_clock_class_uuid
[5],
780 (unsigned int) muxer_notif_iter
->expected_clock_class_uuid
[6],
781 (unsigned int) muxer_notif_iter
->expected_clock_class_uuid
[7],
782 (unsigned int) muxer_notif_iter
->expected_clock_class_uuid
[8],
783 (unsigned int) muxer_notif_iter
->expected_clock_class_uuid
[9],
784 (unsigned int) muxer_notif_iter
->expected_clock_class_uuid
[10],
785 (unsigned int) muxer_notif_iter
->expected_clock_class_uuid
[11],
786 (unsigned int) muxer_notif_iter
->expected_clock_class_uuid
[12],
787 (unsigned int) muxer_notif_iter
->expected_clock_class_uuid
[13],
788 (unsigned int) muxer_notif_iter
->expected_clock_class_uuid
[14],
789 (unsigned int) muxer_notif_iter
->expected_clock_class_uuid
[15],
790 (unsigned int) cc_uuid
[0],
791 (unsigned int) cc_uuid
[1],
792 (unsigned int) cc_uuid
[2],
793 (unsigned int) cc_uuid
[3],
794 (unsigned int) cc_uuid
[4],
795 (unsigned int) cc_uuid
[5],
796 (unsigned int) cc_uuid
[6],
797 (unsigned int) cc_uuid
[7],
798 (unsigned int) cc_uuid
[8],
799 (unsigned int) cc_uuid
[9],
800 (unsigned int) cc_uuid
[10],
801 (unsigned int) cc_uuid
[11],
802 (unsigned int) cc_uuid
[12],
803 (unsigned int) cc_uuid
[13],
804 (unsigned int) cc_uuid
[14],
805 (unsigned int) cc_uuid
[15]);
811 BT_LOGF("Unexpected clock class expectation: "
812 "expectation-code=%d",
813 muxer_notif_iter
->clock_class_expectation
);
818 switch (bt_notification_get_type(notif
)) {
819 case BT_NOTIFICATION_TYPE_EVENT
:
820 event
= bt_notification_event_borrow_event(notif
);
822 clock_value
= bt_event_borrow_clock_value(event
,
825 case BT_NOTIFICATION_TYPE_INACTIVITY
:
826 clock_value
= bt_notification_inactivity_borrow_clock_value(
830 BT_LOGF("Unexpected notification type at this point: "
831 "type=%d", bt_notification_get_type(notif
));
836 BT_LOGE("Cannot get notification's clock value for clock class: "
837 "clock-class-addr=%p, clock-class-name=\"%s\"",
838 clock_class
, cc_name
);
842 ret
= bt_clock_value_get_value_ns_from_epoch(clock_value
, ts_ns
);
844 BT_LOGE("Cannot get nanoseconds from Epoch of clock value: "
845 "clock-value-addr=%p", clock_value
);
856 BT_LOGV("Found notification's timestamp: "
857 "muxer-notif-iter-addr=%p, notif-addr=%p, "
858 "last-returned-ts=%" PRId64
", ts=%" PRId64
,
859 muxer_notif_iter
, notif
, last_returned_ts_ns
,
867 * This function finds the youngest available notification amongst the
868 * non-ended upstream notification iterators and returns the upstream
869 * notification iterator which has it, or
870 * BT_NOTIFICATION_ITERATOR_STATUS_END if there's no available
873 * This function does NOT:
875 * * Update any upstream notification iterator.
876 * * Check for newly connected ports.
877 * * Check the upstream notification iterators to retry.
879 * On sucess, this function sets *muxer_upstream_notif_iter to the
880 * upstream notification iterator of which the current notification is
881 * the youngest, and sets *ts_ns to its time.
884 enum bt_notification_iterator_status
885 muxer_notif_iter_youngest_upstream_notif_iter(
886 struct muxer_comp
*muxer_comp
,
887 struct muxer_notif_iter
*muxer_notif_iter
,
888 struct muxer_upstream_notif_iter
**muxer_upstream_notif_iter
,
893 int64_t youngest_ts_ns
= INT64_MAX
;
894 enum bt_notification_iterator_status status
=
895 BT_NOTIFICATION_ITERATOR_STATUS_OK
;
897 BT_ASSERT(muxer_comp
);
898 BT_ASSERT(muxer_notif_iter
);
899 BT_ASSERT(muxer_upstream_notif_iter
);
900 *muxer_upstream_notif_iter
= NULL
;
902 for (i
= 0; i
< muxer_notif_iter
->muxer_upstream_notif_iters
->len
; i
++) {
903 struct bt_notification
*notif
;
904 struct muxer_upstream_notif_iter
*cur_muxer_upstream_notif_iter
=
905 g_ptr_array_index(muxer_notif_iter
->muxer_upstream_notif_iters
, i
);
908 if (!cur_muxer_upstream_notif_iter
->notif_iter
) {
909 /* This upstream notification iterator is ended */
910 BT_LOGV("Skipping ended upstream notification iterator: "
911 "muxer-upstream-notif-iter-wrap-addr=%p",
912 cur_muxer_upstream_notif_iter
);
916 BT_ASSERT(cur_muxer_upstream_notif_iter
->notifs
->length
> 0);
917 notif
= g_queue_peek_head(cur_muxer_upstream_notif_iter
->notifs
);
919 ret
= get_notif_ts_ns(muxer_comp
, muxer_notif_iter
, notif
,
920 muxer_notif_iter
->last_returned_ts_ns
, ¬if_ts_ns
);
922 /* get_notif_ts_ns() logs errors */
923 *muxer_upstream_notif_iter
= NULL
;
924 status
= BT_NOTIFICATION_ITERATOR_STATUS_ERROR
;
928 if (notif_ts_ns
<= youngest_ts_ns
) {
929 *muxer_upstream_notif_iter
=
930 cur_muxer_upstream_notif_iter
;
931 youngest_ts_ns
= notif_ts_ns
;
932 *ts_ns
= youngest_ts_ns
;
936 if (!*muxer_upstream_notif_iter
) {
937 status
= BT_NOTIFICATION_ITERATOR_STATUS_END
;
946 enum bt_notification_iterator_status
validate_muxer_upstream_notif_iter(
947 struct muxer_upstream_notif_iter
*muxer_upstream_notif_iter
)
949 enum bt_notification_iterator_status status
=
950 BT_NOTIFICATION_ITERATOR_STATUS_OK
;
952 BT_LOGV("Validating muxer's upstream notification iterator wrapper: "
953 "muxer-upstream-notif-iter-wrap-addr=%p",
954 muxer_upstream_notif_iter
);
956 if (muxer_upstream_notif_iter
->notifs
->length
> 0 ||
957 !muxer_upstream_notif_iter
->notif_iter
) {
958 BT_LOGV("Already valid or not considered: "
959 "queue-len=%u, upstream-notif-iter-addr=%p",
960 muxer_upstream_notif_iter
->notifs
->length
,
961 muxer_upstream_notif_iter
->notif_iter
);
965 /* muxer_upstream_notif_iter_next() logs details/errors */
966 status
= muxer_upstream_notif_iter_next(muxer_upstream_notif_iter
);
973 enum bt_notification_iterator_status
validate_muxer_upstream_notif_iters(
974 struct muxer_notif_iter
*muxer_notif_iter
)
976 enum bt_notification_iterator_status status
=
977 BT_NOTIFICATION_ITERATOR_STATUS_OK
;
980 BT_LOGV("Validating muxer's upstream notification iterator wrappers: "
981 "muxer-notif-iter-addr=%p", muxer_notif_iter
);
983 for (i
= 0; i
< muxer_notif_iter
->muxer_upstream_notif_iters
->len
; i
++) {
984 struct muxer_upstream_notif_iter
*muxer_upstream_notif_iter
=
986 muxer_notif_iter
->muxer_upstream_notif_iters
,
989 status
= validate_muxer_upstream_notif_iter(
990 muxer_upstream_notif_iter
);
991 if (status
!= BT_NOTIFICATION_ITERATOR_STATUS_OK
) {
993 BT_LOGE("Cannot validate muxer's upstream notification iterator wrapper: "
994 "muxer-notif-iter-addr=%p, "
995 "muxer-upstream-notif-iter-wrap-addr=%p",
997 muxer_upstream_notif_iter
);
999 BT_LOGV("Cannot validate muxer's upstream notification iterator wrapper: "
1000 "muxer-notif-iter-addr=%p, "
1001 "muxer-upstream-notif-iter-wrap-addr=%p",
1003 muxer_upstream_notif_iter
);
1010 * Remove this muxer upstream notification iterator
1011 * if it's ended or canceled.
1013 if (!muxer_upstream_notif_iter
->notif_iter
) {
1015 * Use g_ptr_array_remove_fast() because the
1016 * order of those elements is not important.
1018 BT_LOGV("Removing muxer's upstream notification iterator wrapper: ended or canceled: "
1019 "muxer-notif-iter-addr=%p, "
1020 "muxer-upstream-notif-iter-wrap-addr=%p",
1021 muxer_notif_iter
, muxer_upstream_notif_iter
);
1022 g_ptr_array_remove_index_fast(
1023 muxer_notif_iter
->muxer_upstream_notif_iters
,
1034 enum bt_notification_iterator_status
muxer_notif_iter_do_next_one(
1035 struct muxer_comp
*muxer_comp
,
1036 struct muxer_notif_iter
*muxer_notif_iter
,
1037 struct bt_notification
**notif
)
1039 enum bt_notification_iterator_status status
=
1040 BT_NOTIFICATION_ITERATOR_STATUS_OK
;
1041 struct muxer_upstream_notif_iter
*muxer_upstream_notif_iter
= NULL
;
1042 int64_t next_return_ts
;
1045 int ret
= muxer_notif_iter_handle_newly_connected_ports(
1049 BT_LOGE("Cannot handle newly connected input ports for muxer's notification iterator: "
1050 "muxer-comp-addr=%p, muxer-notif-iter-addr=%p, "
1052 muxer_comp
, muxer_notif_iter
, ret
);
1053 status
= BT_NOTIFICATION_ITERATOR_STATUS_ERROR
;
1057 status
= validate_muxer_upstream_notif_iters(muxer_notif_iter
);
1058 if (status
!= BT_NOTIFICATION_ITERATOR_STATUS_OK
) {
1059 /* validate_muxer_upstream_notif_iters() logs details */
1064 * At this point, we know that all the existing upstream
1065 * notification iterators are valid. However the
1066 * operations to validate them (during
1067 * validate_muxer_upstream_notif_iters()) may have
1068 * connected new ports. If no ports were connected
1069 * during this operation, exit the loop.
1071 if (!muxer_notif_iter
->newly_connected_priv_ports
) {
1072 BT_LOGV("Not breaking this loop: muxer's notification iterator still has newly connected input ports to handle: "
1073 "muxer-comp-addr=%p", muxer_comp
);
1078 BT_ASSERT(!muxer_notif_iter
->newly_connected_priv_ports
);
1081 * At this point we know that all the existing upstream
1082 * notification iterators are valid. We can find the one,
1083 * amongst those, of which the current notification is the
1086 status
= muxer_notif_iter_youngest_upstream_notif_iter(muxer_comp
,
1087 muxer_notif_iter
, &muxer_upstream_notif_iter
,
1089 if (status
< 0 || status
== BT_NOTIFICATION_ITERATOR_STATUS_END
||
1090 status
== BT_NOTIFICATION_ITERATOR_STATUS_CANCELED
) {
1092 BT_LOGE("Cannot find the youngest upstream notification iterator wrapper: "
1094 bt_notification_iterator_status_string(status
));
1096 BT_LOGV("Cannot find the youngest upstream notification iterator wrapper: "
1098 bt_notification_iterator_status_string(status
));
1104 if (next_return_ts
< muxer_notif_iter
->last_returned_ts_ns
) {
1105 BT_LOGE("Youngest upstream notification iterator wrapper's timestamp is less than muxer's notification iterator's last returned timestamp: "
1106 "muxer-notif-iter-addr=%p, ts=%" PRId64
", "
1107 "last-returned-ts=%" PRId64
,
1108 muxer_notif_iter
, next_return_ts
,
1109 muxer_notif_iter
->last_returned_ts_ns
);
1110 status
= BT_NOTIFICATION_ITERATOR_STATUS_ERROR
;
1114 BT_LOGV("Found youngest upstream notification iterator wrapper: "
1115 "muxer-notif-iter-addr=%p, "
1116 "muxer-upstream-notif-iter-wrap-addr=%p, "
1118 muxer_notif_iter
, muxer_upstream_notif_iter
, next_return_ts
);
1119 BT_ASSERT(status
== BT_NOTIFICATION_ITERATOR_STATUS_OK
);
1120 BT_ASSERT(muxer_upstream_notif_iter
);
1123 * Consume from the queue's head: other side
1124 * (muxer_upstream_notif_iter_next()) writes to the tail.
1126 *notif
= g_queue_pop_head(muxer_upstream_notif_iter
->notifs
);
1128 muxer_notif_iter
->last_returned_ts_ns
= next_return_ts
;
1135 enum bt_notification_iterator_status
muxer_notif_iter_do_next(
1136 struct muxer_comp
*muxer_comp
,
1137 struct muxer_notif_iter
*muxer_notif_iter
,
1138 bt_notification_array notifs
, uint64_t capacity
,
1141 enum bt_notification_iterator_status status
=
1142 BT_NOTIFICATION_ITERATOR_STATUS_OK
;
1145 while (i
< capacity
&& status
== BT_NOTIFICATION_ITERATOR_STATUS_OK
) {
1146 status
= muxer_notif_iter_do_next_one(muxer_comp
,
1147 muxer_notif_iter
, ¬ifs
[i
]);
1148 if (status
== BT_NOTIFICATION_ITERATOR_STATUS_OK
) {
1155 * Even if muxer_notif_iter_do_next_one() returned
1156 * something else than
1157 * BT_NOTIFICATION_ITERATOR_STATUS_OK, we accumulated
1158 * notification objects in the output notification
1159 * array, so we need to return
1160 * BT_NOTIFICATION_ITERATOR_STATUS_OK so that they are
1161 * transfered to downstream. This other status occurs
1162 * again the next time muxer_notif_iter_do_next() is
1163 * called, possibly without any accumulated
1164 * notification, in which case we'll return it.
1167 status
= BT_NOTIFICATION_ITERATOR_STATUS_OK
;
1174 void destroy_muxer_notif_iter(struct muxer_notif_iter
*muxer_notif_iter
)
1176 if (!muxer_notif_iter
) {
1180 BT_LOGD("Destroying muxer component's notification iterator: "
1181 "muxer-notif-iter-addr=%p", muxer_notif_iter
);
1183 if (muxer_notif_iter
->muxer_upstream_notif_iters
) {
1184 BT_LOGD_STR("Destroying muxer's upstream notification iterator wrappers.");
1186 muxer_notif_iter
->muxer_upstream_notif_iters
, TRUE
);
1189 g_list_free(muxer_notif_iter
->newly_connected_priv_ports
);
1190 g_free(muxer_notif_iter
);
1194 int muxer_notif_iter_init_newly_connected_ports(struct muxer_comp
*muxer_comp
,
1195 struct muxer_notif_iter
*muxer_notif_iter
)
1197 struct bt_component
*comp
;
1203 * Add the connected input ports to this muxer notification
1204 * iterator's list of newly connected ports. They will be
1205 * handled by muxer_notif_iter_handle_newly_connected_ports().
1207 comp
= bt_component_borrow_from_private(muxer_comp
->priv_comp
);
1209 count
= bt_component_filter_get_input_port_count(comp
);
1211 BT_LOGD("No input port to initialize for muxer component's notification iterator: "
1212 "muxer-comp-addr=%p, muxer-notif-iter-addr=%p",
1213 muxer_comp
, muxer_notif_iter
);
1217 for (i
= 0; i
< count
; i
++) {
1218 struct bt_private_port
*priv_port
=
1219 bt_private_component_filter_get_input_private_port_by_index(
1220 muxer_comp
->priv_comp
, i
);
1221 struct bt_port
*port
;
1223 BT_ASSERT(priv_port
);
1224 port
= bt_port_borrow_from_private(priv_port
);
1227 if (!bt_port_is_connected(port
)) {
1228 BT_LOGD("Skipping input port: not connected: "
1229 "muxer-comp-addr=%p, port-addr=%p, port-name\"%s\"",
1230 muxer_comp
, port
, bt_port_get_name(port
));
1236 muxer_notif_iter
->newly_connected_priv_ports
=
1238 muxer_notif_iter
->newly_connected_priv_ports
,
1240 if (!muxer_notif_iter
->newly_connected_priv_ports
) {
1241 BT_LOGE("Cannot append port to muxer's notification iterator list of newly connected input ports: "
1242 "port-addr=%p, port-name=\"%s\", "
1243 "muxer-notif-iter-addr=%p", port
,
1244 bt_port_get_name(port
), muxer_notif_iter
);
1249 BT_LOGD("Appended port to muxer's notification iterator list of newly connected input ports: "
1250 "port-addr=%p, port-name=\"%s\", "
1251 "muxer-notif-iter-addr=%p", port
,
1252 bt_port_get_name(port
), muxer_notif_iter
);
1260 enum bt_notification_iterator_status
muxer_notif_iter_init(
1261 struct bt_private_connection_private_notification_iterator
*priv_notif_iter
,
1262 struct bt_private_port
*output_priv_port
)
1264 struct muxer_comp
*muxer_comp
= NULL
;
1265 struct muxer_notif_iter
*muxer_notif_iter
= NULL
;
1266 struct bt_private_component
*priv_comp
= NULL
;
1267 enum bt_notification_iterator_status status
=
1268 BT_NOTIFICATION_ITERATOR_STATUS_OK
;
1271 priv_comp
= bt_private_connection_private_notification_iterator_get_private_component(
1273 BT_ASSERT(priv_comp
);
1274 muxer_comp
= bt_private_component_get_user_data(priv_comp
);
1275 BT_ASSERT(muxer_comp
);
1276 BT_LOGD("Initializing muxer component's notification iterator: "
1277 "comp-addr=%p, muxer-comp-addr=%p, notif-iter-addr=%p",
1278 priv_comp
, muxer_comp
, priv_notif_iter
);
1280 if (muxer_comp
->initializing_muxer_notif_iter
) {
1282 * Weird, unhandled situation detected: downstream
1283 * creates a muxer notification iterator while creating
1284 * another muxer notification iterator (same component).
1286 BT_LOGE("Recursive initialization of muxer component's notification iterator: "
1287 "comp-addr=%p, muxer-comp-addr=%p, notif-iter-addr=%p",
1288 priv_comp
, muxer_comp
, priv_notif_iter
);
1292 muxer_comp
->initializing_muxer_notif_iter
= true;
1293 muxer_notif_iter
= g_new0(struct muxer_notif_iter
, 1);
1294 if (!muxer_notif_iter
) {
1295 BT_LOGE_STR("Failed to allocate one muxer component's notification iterator.");
1299 muxer_notif_iter
->last_returned_ts_ns
= INT64_MIN
;
1300 muxer_notif_iter
->muxer_upstream_notif_iters
=
1301 g_ptr_array_new_with_free_func(
1302 (GDestroyNotify
) destroy_muxer_upstream_notif_iter
);
1303 if (!muxer_notif_iter
->muxer_upstream_notif_iters
) {
1304 BT_LOGE_STR("Failed to allocate a GPtrArray.");
1309 * Add the muxer notification iterator to the component's array
1310 * of muxer notification iterators here because
1311 * muxer_notif_iter_init_newly_connected_ports() can cause
1312 * muxer_port_connected() to be called, which adds the newly
1313 * connected port to each muxer notification iterator's list of
1314 * newly connected ports.
1316 g_ptr_array_add(muxer_comp
->muxer_notif_iters
, muxer_notif_iter
);
1317 ret
= muxer_notif_iter_init_newly_connected_ports(muxer_comp
,
1320 BT_LOGE("Cannot initialize newly connected input ports for muxer component's notification iterator: "
1321 "comp-addr=%p, muxer-comp-addr=%p, "
1322 "muxer-notif-iter-addr=%p, notif-iter-addr=%p, ret=%d",
1323 priv_comp
, muxer_comp
, muxer_notif_iter
,
1324 priv_notif_iter
, ret
);
1328 ret
= bt_private_connection_private_notification_iterator_set_user_data(priv_notif_iter
,
1330 BT_ASSERT(ret
== 0);
1331 BT_LOGD("Initialized muxer component's notification iterator: "
1332 "comp-addr=%p, muxer-comp-addr=%p, muxer-notif-iter-addr=%p, "
1333 "notif-iter-addr=%p",
1334 priv_comp
, muxer_comp
, muxer_notif_iter
, priv_notif_iter
);
1338 if (g_ptr_array_index(muxer_comp
->muxer_notif_iters
,
1339 muxer_comp
->muxer_notif_iters
->len
- 1) == muxer_notif_iter
) {
1340 g_ptr_array_remove_index(muxer_comp
->muxer_notif_iters
,
1341 muxer_comp
->muxer_notif_iters
->len
- 1);
1344 destroy_muxer_notif_iter(muxer_notif_iter
);
1345 ret
= bt_private_connection_private_notification_iterator_set_user_data(priv_notif_iter
,
1347 BT_ASSERT(ret
== 0);
1348 status
= BT_NOTIFICATION_ITERATOR_STATUS_ERROR
;
1351 muxer_comp
->initializing_muxer_notif_iter
= false;
1357 void muxer_notif_iter_finalize(
1358 struct bt_private_connection_private_notification_iterator
*priv_notif_iter
)
1360 struct muxer_notif_iter
*muxer_notif_iter
=
1361 bt_private_connection_private_notification_iterator_get_user_data(priv_notif_iter
);
1362 struct bt_private_component
*priv_comp
= NULL
;
1363 struct muxer_comp
*muxer_comp
= NULL
;
1365 priv_comp
= bt_private_connection_private_notification_iterator_get_private_component(
1367 BT_ASSERT(priv_comp
);
1368 muxer_comp
= bt_private_component_get_user_data(priv_comp
);
1369 BT_LOGD("Finalizing muxer component's notification iterator: "
1370 "comp-addr=%p, muxer-comp-addr=%p, muxer-notif-iter-addr=%p, "
1371 "notif-iter-addr=%p",
1372 priv_comp
, muxer_comp
, muxer_notif_iter
, priv_notif_iter
);
1375 (void) g_ptr_array_remove_fast(muxer_comp
->muxer_notif_iters
,
1377 destroy_muxer_notif_iter(muxer_notif_iter
);
1384 enum bt_notification_iterator_status
muxer_notif_iter_next(
1385 struct bt_private_connection_private_notification_iterator
*priv_notif_iter
,
1386 bt_notification_array notifs
, uint64_t capacity
,
1389 enum bt_notification_iterator_status status
;
1390 struct muxer_notif_iter
*muxer_notif_iter
=
1391 bt_private_connection_private_notification_iterator_get_user_data(priv_notif_iter
);
1392 struct bt_private_component
*priv_comp
= NULL
;
1393 struct muxer_comp
*muxer_comp
= NULL
;
1395 BT_ASSERT(muxer_notif_iter
);
1396 priv_comp
= bt_private_connection_private_notification_iterator_get_private_component(
1398 BT_ASSERT(priv_comp
);
1399 muxer_comp
= bt_private_component_get_user_data(priv_comp
);
1400 BT_ASSERT(muxer_comp
);
1401 BT_LOGV("Muxer component's notification iterator's \"next\" method called: "
1402 "comp-addr=%p, muxer-comp-addr=%p, muxer-notif-iter-addr=%p, "
1403 "notif-iter-addr=%p",
1404 priv_comp
, muxer_comp
, muxer_notif_iter
, priv_notif_iter
);
1406 /* Are we in an error state set elsewhere? */
1407 if (unlikely(muxer_comp
->error
)) {
1408 BT_LOGE("Muxer component is already in an error state: returning BT_NOTIFICATION_ITERATOR_STATUS_ERROR: "
1409 "comp-addr=%p, muxer-comp-addr=%p, muxer-notif-iter-addr=%p, "
1410 "notif-iter-addr=%p",
1411 priv_comp
, muxer_comp
, muxer_notif_iter
, priv_notif_iter
);
1412 status
= BT_NOTIFICATION_ITERATOR_STATUS_ERROR
;
1416 status
= muxer_notif_iter_do_next(muxer_comp
, muxer_notif_iter
,
1417 notifs
, capacity
, count
);
1419 BT_LOGE("Cannot get next notification: "
1420 "comp-addr=%p, muxer-comp-addr=%p, muxer-notif-iter-addr=%p, "
1421 "notif-iter-addr=%p, status=%s",
1422 priv_comp
, muxer_comp
, muxer_notif_iter
, priv_notif_iter
,
1423 bt_notification_iterator_status_string(status
));
1425 BT_LOGV("Returning from muxer component's notification iterator's \"next\" method: "
1427 bt_notification_iterator_status_string(status
));
1436 void muxer_port_connected(
1437 struct bt_private_component
*priv_comp
,
1438 struct bt_private_port
*self_private_port
,
1439 struct bt_port
*other_port
)
1441 struct bt_port
*self_port
=
1442 bt_port_borrow_from_private(self_private_port
);
1443 struct muxer_comp
*muxer_comp
=
1444 bt_private_component_get_user_data(priv_comp
);
1448 BT_ASSERT(self_port
);
1449 BT_ASSERT(muxer_comp
);
1450 BT_LOGD("Port connected: "
1451 "comp-addr=%p, muxer-comp-addr=%p, "
1452 "port-addr=%p, port-name=\"%s\", "
1453 "other-port-addr=%p, other-port-name=\"%s\"",
1454 priv_comp
, muxer_comp
, self_port
, bt_port_get_name(self_port
),
1455 other_port
, bt_port_get_name(other_port
));
1457 if (bt_port_get_type(self_port
) == BT_PORT_TYPE_OUTPUT
) {
1461 for (i
= 0; i
< muxer_comp
->muxer_notif_iters
->len
; i
++) {
1462 struct muxer_notif_iter
*muxer_notif_iter
=
1463 g_ptr_array_index(muxer_comp
->muxer_notif_iters
, i
);
1466 * Add this port to the list of newly connected ports
1467 * for this muxer notification iterator. We append at
1468 * the end of this list while
1469 * muxer_notif_iter_handle_newly_connected_ports()
1470 * removes the nodes from the beginning.
1472 muxer_notif_iter
->newly_connected_priv_ports
=
1474 muxer_notif_iter
->newly_connected_priv_ports
,
1476 if (!muxer_notif_iter
->newly_connected_priv_ports
) {
1477 BT_LOGE("Cannot append port to muxer's notification iterator list of newly connected input ports: "
1478 "port-addr=%p, port-name=\"%s\", "
1479 "muxer-notif-iter-addr=%p", self_port
,
1480 bt_port_get_name(self_port
), muxer_notif_iter
);
1481 muxer_comp
->error
= true;
1485 BT_LOGD("Appended port to muxer's notification iterator list of newly connected input ports: "
1486 "port-addr=%p, port-name=\"%s\", "
1487 "muxer-notif-iter-addr=%p", self_port
,
1488 bt_port_get_name(self_port
), muxer_notif_iter
);
1491 /* One less available input port */
1492 muxer_comp
->available_input_ports
--;
1493 ret
= ensure_available_input_port(priv_comp
);
1496 * Only way to report an error later since this
1497 * method does not return anything.
1499 BT_LOGE("Cannot ensure that at least one muxer component's input port is available: "
1500 "muxer-comp-addr=%p, status=%s",
1501 muxer_comp
, bt_component_status_string(ret
));
1502 muxer_comp
->error
= true;
1511 void muxer_port_disconnected(struct bt_private_component
*priv_comp
,
1512 struct bt_private_port
*priv_port
)
1514 struct bt_port
*port
= bt_port_borrow_from_private(priv_port
);
1515 struct muxer_comp
*muxer_comp
=
1516 bt_private_component_get_user_data(priv_comp
);
1519 BT_ASSERT(muxer_comp
);
1520 BT_LOGD("Port disconnected: "
1521 "comp-addr=%p, muxer-comp-addr=%p, port-addr=%p, "
1522 "port-name=\"%s\"", priv_comp
, muxer_comp
,
1523 port
, bt_port_get_name(port
));
1526 * There's nothing special to do when a port is disconnected
1527 * because this component deals with upstream notification
1528 * iterators which were already created thanks to connected
1529 * ports. The fact that the port is disconnected does not cancel
1530 * the upstream notification iterators created using its
1531 * connection: they still exist, even if the connection is dead.
1532 * The only way to remove an upstream notification iterator is
1533 * for its "next" operation to return
1534 * BT_NOTIFICATION_ITERATOR_STATUS_END.
1536 if (bt_port_get_type(port
) == BT_PORT_TYPE_INPUT
) {
1537 /* One more available input port */
1538 muxer_comp
->available_input_ports
++;
1539 BT_LOGD("Leaving disconnected input port available for future connections: "
1540 "comp-addr=%p, muxer-comp-addr=%p, port-addr=%p, "
1541 "port-name=\"%s\", avail-input-port-count=%zu",
1542 priv_comp
, muxer_comp
, port
, bt_port_get_name(port
),
1543 muxer_comp
->available_input_ports
);