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/ctf-ir/clock-class.h>
29 #include <babeltrace/ctf-ir/event.h>
30 #include <babeltrace/graph/clock-class-priority-map.h>
31 #include <babeltrace/graph/component-filter.h>
32 #include <babeltrace/graph/component.h>
33 #include <babeltrace/graph/component-internal.h>
34 #include <babeltrace/graph/notification-event.h>
35 #include <babeltrace/graph/notification-inactivity.h>
36 #include <babeltrace/graph/notification-iterator.h>
37 #include <babeltrace/graph/notification-iterator-internal.h>
38 #include <babeltrace/graph/notification.h>
39 #include <babeltrace/graph/port.h>
40 #include <babeltrace/graph/private-component-filter.h>
41 #include <babeltrace/graph/private-component.h>
42 #include <babeltrace/graph/private-component.h>
43 #include <babeltrace/graph/private-connection.h>
44 #include <babeltrace/graph/private-notification-iterator.h>
45 #include <babeltrace/graph/private-port.h>
46 #include <babeltrace/graph/connection.h>
47 #include <babeltrace/graph/connection-internal.h>
48 #include <babeltrace/values-internal.h>
49 #include <plugins-common.h>
57 #define ASSUME_ABSOLUTE_CLOCK_CLASSES_PARAM_NAME "assume-absolute-clock-classes"
60 /* Array of struct bt_private_notification_iterator * (weak refs) */
61 GPtrArray
*muxer_notif_iters
;
64 struct bt_private_component
*priv_comp
;
65 unsigned int next_port_num
;
66 size_t available_input_ports
;
68 bool initializing_muxer_notif_iter
;
69 bool assume_absolute_clock_classes
;
72 struct muxer_upstream_notif_iter
{
73 /* Owned by this, NULL if ended */
74 struct bt_notification_iterator
*notif_iter
;
77 * This flag is true if the upstream notification iterator's
78 * current notification must be considered for the multiplexing
79 * operations. If the upstream iterator returns
80 * BT_NOTIFICATION_ITERATOR_STATUS_AGAIN, then this object
81 * is considered invalid, because its current notification is
82 * still the previous one, but we already took it into account.
84 * The value of this flag is not important if notif_iter above
85 * is NULL (which means the upstream iterator is finished).
90 enum muxer_notif_iter_clock_class_expectation
{
91 MUXER_NOTIF_ITER_CLOCK_CLASS_EXPECTATION_ANY
= 0,
92 MUXER_NOTIF_ITER_CLOCK_CLASS_EXPECTATION_ABSOLUTE
,
93 MUXER_NOTIF_ITER_CLOCK_CLASS_EXPECTATION_NOT_ABS_SPEC_UUID
,
94 MUXER_NOTIF_ITER_CLOCK_CLASS_EXPECTATION_NOT_ABS_NO_UUID
,
97 struct muxer_notif_iter
{
99 * Array of struct muxer_upstream_notif_iter * (owned by this).
101 * NOTE: This array is searched in linearly to find the youngest
102 * current notification. Keep this until benchmarks confirm that
103 * another data structure is faster than this for our typical
106 GPtrArray
*muxer_upstream_notif_iters
;
109 * List of "recently" connected input ports (weak) to
110 * handle by this muxer notification iterator.
111 * muxer_port_connected() adds entries to this list, and the
112 * entries are removed when a notification iterator is created
113 * on the port's connection and put into
114 * muxer_upstream_notif_iters above by
115 * muxer_notif_iter_handle_newly_connected_ports().
117 GList
*newly_connected_priv_ports
;
119 /* Next thing to return by the "next" method */
120 struct bt_notification_iterator_next_return next_next_return
;
122 /* Last time returned in a notification */
123 int64_t last_returned_ts_ns
;
125 /* Clock class expectation state */
126 enum muxer_notif_iter_clock_class_expectation clock_class_expectation
;
129 * Expected clock class UUID, only valid when
130 * clock_class_expectation is
131 * MUXER_NOTIF_ITER_CLOCK_CLASS_EXPECTATION_NOT_ABS_SPEC_UUID.
133 unsigned char expected_clock_class_uuid
[BABELTRACE_UUID_LEN
];
137 void destroy_muxer_upstream_notif_iter(
138 struct muxer_upstream_notif_iter
*muxer_upstream_notif_iter
)
140 if (!muxer_upstream_notif_iter
) {
144 BT_LOGD("Destroying muxer's upstream notification iterator wrapper: "
145 "addr=%p, notif-iter-addr=%p, is-valid=%d",
146 muxer_upstream_notif_iter
,
147 muxer_upstream_notif_iter
->notif_iter
,
148 muxer_upstream_notif_iter
->is_valid
);
149 bt_put(muxer_upstream_notif_iter
->notif_iter
);
150 g_free(muxer_upstream_notif_iter
);
154 struct muxer_upstream_notif_iter
*muxer_notif_iter_add_upstream_notif_iter(
155 struct muxer_notif_iter
*muxer_notif_iter
,
156 struct bt_notification_iterator
*notif_iter
,
157 struct bt_private_port
*priv_port
)
159 struct muxer_upstream_notif_iter
*muxer_upstream_notif_iter
=
160 g_new0(struct muxer_upstream_notif_iter
, 1);
162 if (!muxer_upstream_notif_iter
) {
163 BT_LOGE_STR("Failed to allocate one muxer's upstream notification iterator wrapper.");
167 muxer_upstream_notif_iter
->notif_iter
= bt_get(notif_iter
);
168 muxer_upstream_notif_iter
->is_valid
= false;
169 g_ptr_array_add(muxer_notif_iter
->muxer_upstream_notif_iters
,
170 muxer_upstream_notif_iter
);
171 BT_LOGD("Added muxer's upstream notification iterator wrapper: "
172 "addr=%p, muxer-notif-iter-addr=%p, notif-iter-addr=%p",
173 muxer_upstream_notif_iter
, muxer_notif_iter
,
177 return muxer_upstream_notif_iter
;
181 enum bt_component_status
ensure_available_input_port(
182 struct bt_private_component
*priv_comp
)
184 struct muxer_comp
*muxer_comp
=
185 bt_private_component_get_user_data(priv_comp
);
186 enum bt_component_status status
= BT_COMPONENT_STATUS_OK
;
187 GString
*port_name
= NULL
;
191 if (muxer_comp
->available_input_ports
>= 1) {
195 port_name
= g_string_new("in");
197 BT_LOGE_STR("Failed to allocate a GString.");
198 status
= BT_COMPONENT_STATUS_NOMEM
;
202 g_string_append_printf(port_name
, "%u", muxer_comp
->next_port_num
);
203 status
= bt_private_component_filter_add_input_private_port(
204 priv_comp
, port_name
->str
, NULL
, NULL
);
205 if (status
!= BT_COMPONENT_STATUS_OK
) {
206 BT_LOGE("Cannot add input port to muxer component: "
207 "port-name=\"%s\", comp-addr=%p, status=%s",
208 port_name
->str
, priv_comp
,
209 bt_component_status_string(status
));
213 muxer_comp
->available_input_ports
++;
214 muxer_comp
->next_port_num
++;
215 BT_LOGD("Added one input port to muxer component: "
216 "port-name=\"%s\", comp-addr=%p",
217 port_name
->str
, priv_comp
);
220 g_string_free(port_name
, TRUE
);
227 enum bt_component_status
create_output_port(
228 struct bt_private_component
*priv_comp
)
230 return bt_private_component_filter_add_output_private_port(
231 priv_comp
, "out", NULL
, NULL
);
235 void destroy_muxer_comp(struct muxer_comp
*muxer_comp
)
241 BT_LOGD("Destroying muxer component: muxer-comp-addr=%p, "
242 "muxer-notif-iter-count=%u", muxer_comp
,
243 muxer_comp
->muxer_notif_iters
->len
);
245 if (muxer_comp
->muxer_notif_iters
) {
246 g_ptr_array_free(muxer_comp
->muxer_notif_iters
, TRUE
);
253 struct bt_value
*get_default_params(void)
255 struct bt_value
*params
;
258 params
= bt_value_map_create();
260 BT_LOGE_STR("Cannot create a map value object.");
264 ret
= bt_value_map_insert_bool(params
,
265 ASSUME_ABSOLUTE_CLOCK_CLASSES_PARAM_NAME
, false);
267 BT_LOGE_STR("Cannot add boolean value to map value object.");
281 int configure_muxer_comp(struct muxer_comp
*muxer_comp
, struct bt_value
*params
)
283 struct bt_value
*default_params
= NULL
;
284 struct bt_value
*real_params
= NULL
;
285 struct bt_value
*assume_absolute_clock_classes
= NULL
;
289 default_params
= get_default_params();
290 if (!default_params
) {
291 BT_LOGE("Cannot get default parameters: "
292 "muxer-comp-addr=%p", muxer_comp
);
296 real_params
= bt_value_map_extend(default_params
, params
);
298 BT_LOGE("Cannot extend default parameters map value: "
299 "muxer-comp-addr=%p, def-params-addr=%p, "
300 "params-addr=%p", muxer_comp
, default_params
,
305 assume_absolute_clock_classes
= bt_value_map_get(real_params
,
306 ASSUME_ABSOLUTE_CLOCK_CLASSES_PARAM_NAME
);
307 if (!bt_value_is_bool(assume_absolute_clock_classes
)) {
308 BT_LOGE("Expecting a boolean value for the `%s` parameter: "
309 "muxer-comp-addr=%p, value-type=%s",
310 ASSUME_ABSOLUTE_CLOCK_CLASSES_PARAM_NAME
, muxer_comp
,
311 bt_value_type_string(
312 bt_value_get_type(assume_absolute_clock_classes
)));
316 ret
= bt_value_bool_get(assume_absolute_clock_classes
, &bool_val
);
318 muxer_comp
->assume_absolute_clock_classes
= (bool) bool_val
;
319 BT_LOGD("Configured muxer component: muxer-comp-addr=%p, "
320 "assume-absolute-clock-classes=%d",
321 muxer_comp
, muxer_comp
->assume_absolute_clock_classes
);
328 bt_put(default_params
);
330 bt_put(assume_absolute_clock_classes
);
335 enum bt_component_status
muxer_init(
336 struct bt_private_component
*priv_comp
,
337 struct bt_value
*params
, void *init_data
)
340 enum bt_component_status status
= BT_COMPONENT_STATUS_OK
;
341 struct muxer_comp
*muxer_comp
= g_new0(struct muxer_comp
, 1);
343 BT_LOGD("Initializing muxer component: "
344 "comp-addr=%p, params-addr=%p", priv_comp
, params
);
347 BT_LOGE_STR("Failed to allocate one muxer component.");
351 ret
= configure_muxer_comp(muxer_comp
, params
);
353 BT_LOGE("Cannot configure muxer component: "
354 "muxer-comp-addr=%p, params-addr=%p",
359 muxer_comp
->muxer_notif_iters
= g_ptr_array_new();
360 if (!muxer_comp
->muxer_notif_iters
) {
361 BT_LOGE_STR("Failed to allocate a GPtrArray.");
365 muxer_comp
->priv_comp
= priv_comp
;
366 ret
= bt_private_component_set_user_data(priv_comp
, muxer_comp
);
368 status
= ensure_available_input_port(priv_comp
);
369 if (status
!= BT_COMPONENT_STATUS_OK
) {
370 BT_LOGE("Cannot ensure that at least one muxer component's input port is available: "
371 "muxer-comp-addr=%p, status=%s",
373 bt_component_status_string(status
));
377 status
= create_output_port(priv_comp
);
379 BT_LOGE("Cannot create muxer component's output port: "
380 "muxer-comp-addr=%p, status=%s",
382 bt_component_status_string(status
));
386 BT_LOGD("Initialized muxer component: "
387 "comp-addr=%p, params-addr=%p, muxer-comp-addr=%p",
388 priv_comp
, params
, muxer_comp
);
393 destroy_muxer_comp(muxer_comp
);
394 ret
= bt_private_component_set_user_data(priv_comp
, NULL
);
397 if (status
== BT_COMPONENT_STATUS_OK
) {
398 status
= BT_COMPONENT_STATUS_ERROR
;
406 void muxer_finalize(struct bt_private_component
*priv_comp
)
408 struct muxer_comp
*muxer_comp
=
409 bt_private_component_get_user_data(priv_comp
);
411 BT_LOGD("Finalizing muxer component: comp-addr=%p",
413 destroy_muxer_comp(muxer_comp
);
417 struct bt_notification_iterator
*create_notif_iter_on_input_port(
418 struct bt_private_port
*priv_port
, int *ret
)
420 struct bt_port
*port
= bt_port_from_private_port(priv_port
);
421 struct bt_notification_iterator
*notif_iter
= NULL
;
422 struct bt_private_connection
*priv_conn
= NULL
;
423 enum bt_connection_status conn_status
;
428 assert(bt_port_is_connected(port
));
429 priv_conn
= bt_private_port_get_private_connection(priv_port
);
432 // TODO: Advance the iterator to >= the time of the latest
433 // returned notification by the muxer notification
434 // iterator which creates it.
435 conn_status
= bt_private_connection_create_notification_iterator(
436 priv_conn
, NULL
, ¬if_iter
);
437 if (conn_status
!= BT_CONNECTION_STATUS_OK
) {
438 BT_LOGE("Cannot create upstream notification iterator on input port's connection: "
439 "port-addr=%p, port-name=\"%s\", conn-addr=%p, "
441 port
, bt_port_get_name(port
), priv_conn
,
442 bt_connection_status_string(conn_status
));
447 BT_LOGD("Created upstream notification iterator on input port's connection: "
448 "port-addr=%p, port-name=\"%s\", conn-addr=%p, "
449 "notif-iter-addr=%p",
450 port
, bt_port_get_name(port
), priv_conn
, notif_iter
);
459 enum bt_notification_iterator_status
muxer_upstream_notif_iter_next(
460 struct muxer_upstream_notif_iter
*muxer_upstream_notif_iter
)
462 enum bt_notification_iterator_status status
;
464 BT_LOGV("Calling upstream notification iterator's \"next\" method: "
465 "muxer-upstream-notif-iter-wrap-addr=%p, notif-iter-addr=%p",
466 muxer_upstream_notif_iter
,
467 muxer_upstream_notif_iter
->notif_iter
);
468 status
= bt_notification_iterator_next(
469 muxer_upstream_notif_iter
->notif_iter
);
470 BT_LOGV("Upstream notification iterator's \"next\" method returned: "
471 "status=%s", bt_notification_iterator_status_string(status
));
474 case BT_NOTIFICATION_ITERATOR_STATUS_OK
:
476 * Notification iterator's current notification is valid:
477 * it must be considered for muxing operations.
479 BT_LOGV_STR("Validated upstream notification iterator wrapper.");
480 muxer_upstream_notif_iter
->is_valid
= true;
482 case BT_NOTIFICATION_ITERATOR_STATUS_AGAIN
:
484 * Notification iterator's current notification is not
485 * valid anymore. Return
486 * BT_NOTIFICATION_ITERATOR_STATUS_AGAIN
489 BT_LOGV_STR("Invalidated upstream notification iterator wrapper because of BT_NOTIFICATION_ITERATOR_STATUS_AGAIN.");
490 muxer_upstream_notif_iter
->is_valid
= false;
492 case BT_NOTIFICATION_ITERATOR_STATUS_END
: /* Fall-through. */
493 case BT_NOTIFICATION_ITERATOR_STATUS_CANCELED
:
495 * Notification iterator reached the end: release it. It
496 * won't be considered again to find the youngest
499 BT_LOGV_STR("Invalidated upstream notification iterator wrapper because of BT_NOTIFICATION_ITERATOR_STATUS_END or BT_NOTIFICATION_ITERATOR_STATUS_CANCELED.");
500 BT_PUT(muxer_upstream_notif_iter
->notif_iter
);
501 muxer_upstream_notif_iter
->is_valid
= false;
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_priv_ports
;
534 struct bt_private_port
*priv_port
;
535 struct bt_port
*port
;
536 struct bt_notification_iterator
*upstream_notif_iter
= NULL
;
537 struct muxer_upstream_notif_iter
*muxer_upstream_notif_iter
;
543 priv_port
= node
->data
;
544 port
= bt_port_from_private_port(priv_port
);
547 if (!bt_port_is_connected(port
)) {
549 * Looks like this port is not connected
550 * anymore: we can't create an upstream
551 * notification iterator on its (non-existing)
552 * connection in this case.
558 upstream_notif_iter
= create_notif_iter_on_input_port(priv_port
,
561 /* create_notif_iter_on_input_port() logs errors */
562 assert(!upstream_notif_iter
);
566 muxer_upstream_notif_iter
=
567 muxer_notif_iter_add_upstream_notif_iter(
568 muxer_notif_iter
, upstream_notif_iter
,
570 BT_PUT(upstream_notif_iter
);
571 if (!muxer_upstream_notif_iter
) {
573 * muxer_notif_iter_add_upstream_notif_iter()
580 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_ctf_clock_class
*clock_class
= NULL
;
607 struct bt_ctf_clock_value
*clock_value
= NULL
;
608 struct bt_ctf_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_get_clock_class_priority_map(
628 case BT_NOTIFICATION_TYPE_INACTIVITY
:
630 bt_notification_inactivity_get_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 priorty map contains 0 clock classes: "
653 "using the last returned timestamp.");
654 *ts_ns
= last_returned_ts_ns
;
659 bt_clock_class_priority_map_get_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_ctf_clock_class_get_uuid(clock_class
);
668 cc_name
= bt_ctf_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_ctf_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_ctf_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_ctf_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_ctf_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_get_event(notif
);
822 clock_value
= bt_ctf_event_get_clock_value(event
,
825 case BT_NOTIFICATION_TYPE_INACTIVITY
:
826 clock_value
= bt_notification_inactivity_get_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_ctf_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
,
871 * This function finds the youngest available notification amongst the
872 * non-ended upstream notification iterators and returns the upstream
873 * notification iterator which has it, or
874 * BT_NOTIFICATION_ITERATOR_STATUS_END if there's no available
877 * This function does NOT:
879 * * Update any upstream notification iterator.
880 * * Check for newly connected ports.
881 * * Check the upstream notification iterators to retry.
883 * On sucess, this function sets *muxer_upstream_notif_iter to the
884 * upstream notification iterator of which the current notification is
885 * the youngest, and sets *ts_ns to its time.
888 enum bt_notification_iterator_status
889 muxer_notif_iter_youngest_upstream_notif_iter(
890 struct muxer_comp
*muxer_comp
,
891 struct muxer_notif_iter
*muxer_notif_iter
,
892 struct muxer_upstream_notif_iter
**muxer_upstream_notif_iter
,
897 int64_t youngest_ts_ns
= INT64_MAX
;
898 enum bt_notification_iterator_status status
=
899 BT_NOTIFICATION_ITERATOR_STATUS_OK
;
902 assert(muxer_notif_iter
);
903 assert(muxer_upstream_notif_iter
);
904 *muxer_upstream_notif_iter
= NULL
;
906 for (i
= 0; i
< muxer_notif_iter
->muxer_upstream_notif_iters
->len
; i
++) {
907 struct bt_notification
*notif
;
908 struct muxer_upstream_notif_iter
*cur_muxer_upstream_notif_iter
=
909 g_ptr_array_index(muxer_notif_iter
->muxer_upstream_notif_iters
, i
);
912 if (!cur_muxer_upstream_notif_iter
->notif_iter
) {
913 /* This upstream notification iterator is ended */
914 BT_LOGV("Skipping ended upstream notification iterator: "
915 "muxer-upstream-notif-iter-wrap-addr=%p",
916 cur_muxer_upstream_notif_iter
);
920 assert(cur_muxer_upstream_notif_iter
->is_valid
);
921 notif
= bt_notification_iterator_get_notification(
922 cur_muxer_upstream_notif_iter
->notif_iter
);
924 ret
= get_notif_ts_ns(muxer_comp
, muxer_notif_iter
, notif
,
925 muxer_notif_iter
->last_returned_ts_ns
, ¬if_ts_ns
);
928 /* get_notif_ts_ns() logs errors */
929 *muxer_upstream_notif_iter
= NULL
;
930 status
= BT_NOTIFICATION_ITERATOR_STATUS_ERROR
;
934 if (notif_ts_ns
<= youngest_ts_ns
) {
935 *muxer_upstream_notif_iter
=
936 cur_muxer_upstream_notif_iter
;
937 youngest_ts_ns
= notif_ts_ns
;
938 *ts_ns
= youngest_ts_ns
;
942 if (!*muxer_upstream_notif_iter
) {
943 status
= BT_NOTIFICATION_ITERATOR_STATUS_END
;
952 enum bt_notification_iterator_status
validate_muxer_upstream_notif_iter(
953 struct muxer_upstream_notif_iter
*muxer_upstream_notif_iter
)
955 enum bt_notification_iterator_status status
=
956 BT_NOTIFICATION_ITERATOR_STATUS_OK
;
958 BT_LOGV("Validating muxer's upstream notification iterator wrapper: "
959 "muxer-upstream-notif-iter-wrap-addr=%p",
960 muxer_upstream_notif_iter
);
962 if (muxer_upstream_notif_iter
->is_valid
||
963 !muxer_upstream_notif_iter
->notif_iter
) {
967 /* muxer_upstream_notif_iter_next() logs details/errors */
968 status
= muxer_upstream_notif_iter_next(muxer_upstream_notif_iter
);
975 enum bt_notification_iterator_status
validate_muxer_upstream_notif_iters(
976 struct muxer_notif_iter
*muxer_notif_iter
)
978 enum bt_notification_iterator_status status
=
979 BT_NOTIFICATION_ITERATOR_STATUS_OK
;
982 BT_LOGV("Validating muxer's upstream notification iterator wrappers: "
983 "muxer-notif-iter-addr=%p", muxer_notif_iter
);
985 for (i
= 0; i
< muxer_notif_iter
->muxer_upstream_notif_iters
->len
; i
++) {
986 struct muxer_upstream_notif_iter
*muxer_upstream_notif_iter
=
988 muxer_notif_iter
->muxer_upstream_notif_iters
,
991 status
= validate_muxer_upstream_notif_iter(
992 muxer_upstream_notif_iter
);
993 if (status
!= BT_NOTIFICATION_ITERATOR_STATUS_OK
) {
995 BT_LOGE("Cannot validate muxer's upstream notification iterator wrapper: "
996 "muxer-notif-iter-addr=%p, "
997 "muxer-upstream-notif-iter-wrap-addr=%p",
999 muxer_upstream_notif_iter
);
1001 BT_LOGV("Cannot validate muxer's upstream notification iterator wrapper: "
1002 "muxer-notif-iter-addr=%p, "
1003 "muxer-upstream-notif-iter-wrap-addr=%p",
1005 muxer_upstream_notif_iter
);
1012 * Remove this muxer upstream notification iterator
1013 * if it's ended or canceled.
1015 if (!muxer_upstream_notif_iter
->notif_iter
) {
1017 * Use g_ptr_array_remove_fast() because the
1018 * order of those elements is not important.
1020 BT_LOGV("Removing muxer's upstream notification iterator wrapper: ended or canceled: "
1021 "muxer-notif-iter-addr=%p, "
1022 "muxer-upstream-notif-iter-wrap-addr=%p",
1023 muxer_notif_iter
, muxer_upstream_notif_iter
);
1024 g_ptr_array_remove_index_fast(
1025 muxer_notif_iter
->muxer_upstream_notif_iters
,
1036 struct bt_notification_iterator_next_return
muxer_notif_iter_do_next(
1037 struct muxer_comp
*muxer_comp
,
1038 struct muxer_notif_iter
*muxer_notif_iter
)
1040 struct muxer_upstream_notif_iter
*muxer_upstream_notif_iter
= NULL
;
1041 struct bt_notification_iterator_next_return next_return
= {
1042 .notification
= NULL
,
1043 .status
= BT_NOTIFICATION_ITERATOR_STATUS_OK
,
1045 int64_t next_return_ts
;
1048 int ret
= muxer_notif_iter_handle_newly_connected_ports(
1052 BT_LOGE("Cannot handle newly connected input ports for muxer's notification iterator: "
1053 "muxer-comp-addr=%p, muxer-notif-iter-addr=%p, "
1055 muxer_comp
, muxer_notif_iter
, ret
);
1056 next_return
.status
=
1057 BT_NOTIFICATION_ITERATOR_STATUS_ERROR
;
1061 next_return
.status
=
1062 validate_muxer_upstream_notif_iters(muxer_notif_iter
);
1063 if (next_return
.status
!= BT_NOTIFICATION_ITERATOR_STATUS_OK
) {
1064 /* validate_muxer_upstream_notif_iters() logs details */
1069 * At this point, we know that all the existing upstream
1070 * notification iterators are valid. However the
1071 * operations to validate them (during
1072 * validate_muxer_upstream_notif_iters()) may have
1073 * connected new ports. If no ports were connected
1074 * during this operation, exit the loop.
1076 if (!muxer_notif_iter
->newly_connected_priv_ports
) {
1077 BT_LOGV("Not breaking this loop: muxer's notification iterator still has newly connected input ports to handle: "
1078 "muxer-comp-addr=%p", muxer_comp
);
1083 assert(!muxer_notif_iter
->newly_connected_priv_ports
);
1086 * At this point we know that all the existing upstream
1087 * notification iterators are valid. We can find the one,
1088 * amongst those, of which the current notification is the
1091 next_return
.status
=
1092 muxer_notif_iter_youngest_upstream_notif_iter(muxer_comp
,
1093 muxer_notif_iter
, &muxer_upstream_notif_iter
,
1095 if (next_return
.status
< 0 ||
1096 next_return
.status
== BT_NOTIFICATION_ITERATOR_STATUS_END
||
1097 next_return
.status
== BT_NOTIFICATION_ITERATOR_STATUS_CANCELED
) {
1098 if (next_return
.status
< 0) {
1099 BT_LOGE("Cannot find the youngest upstream notification iterator wrapper: "
1101 bt_notification_iterator_status_string(next_return
.status
));
1103 BT_LOGV("Cannot find the youngest upstream notification iterator wrapper: "
1105 bt_notification_iterator_status_string(next_return
.status
));
1111 if (next_return_ts
< muxer_notif_iter
->last_returned_ts_ns
) {
1112 BT_LOGE("Youngest upstream notification iterator wrapper's timestamp is less than muxer's notification iterator's last returned timestamp: "
1113 "muxer-notif-iter-addr=%p, ts=%" PRId64
", "
1114 "last-returned-ts=%" PRId64
,
1115 muxer_notif_iter
, next_return_ts
,
1116 muxer_notif_iter
->last_returned_ts_ns
);
1117 next_return
.status
= BT_NOTIFICATION_ITERATOR_STATUS_ERROR
;
1121 BT_LOGV("Found youngest upstream notification iterator wrapper: "
1122 "muxer-notif-iter-addr=%p, "
1123 "muxer-upstream-notif-iter-wrap-addr=%p, "
1125 muxer_notif_iter
, muxer_upstream_notif_iter
, next_return_ts
);
1126 assert(next_return
.status
== BT_NOTIFICATION_ITERATOR_STATUS_OK
);
1127 assert(muxer_upstream_notif_iter
);
1128 next_return
.notification
= bt_notification_iterator_get_notification(
1129 muxer_upstream_notif_iter
->notif_iter
);
1130 assert(next_return
.notification
);
1133 * We invalidate the upstream notification iterator so that, the
1134 * next time this function is called,
1135 * validate_muxer_upstream_notif_iters() will make it valid.
1137 muxer_upstream_notif_iter
->is_valid
= false;
1138 muxer_notif_iter
->last_returned_ts_ns
= next_return_ts
;
1145 void destroy_muxer_notif_iter(struct muxer_notif_iter
*muxer_notif_iter
)
1147 if (!muxer_notif_iter
) {
1151 BT_LOGD("Destroying muxer component's notification iterator: "
1152 "muxer-notif-iter-addr=%p", muxer_notif_iter
);
1154 if (muxer_notif_iter
->muxer_upstream_notif_iters
) {
1155 BT_LOGD_STR("Destroying muxer's upstream notification iterator wrappers.");
1157 muxer_notif_iter
->muxer_upstream_notif_iters
, TRUE
);
1160 g_list_free(muxer_notif_iter
->newly_connected_priv_ports
);
1161 g_free(muxer_notif_iter
);
1165 int muxer_notif_iter_init_newly_connected_ports(struct muxer_comp
*muxer_comp
,
1166 struct muxer_notif_iter
*muxer_notif_iter
)
1168 struct bt_component
*comp
;
1174 * Add the connected input ports to this muxer notification
1175 * iterator's list of newly connected ports. They will be
1176 * handled by muxer_notif_iter_handle_newly_connected_ports().
1178 comp
= bt_component_from_private_component(muxer_comp
->priv_comp
);
1180 count
= bt_component_filter_get_input_port_count(comp
);
1182 BT_LOGD("No input port to initialize for muxer component's notification iterator: "
1183 "muxer-comp-addr=%p, muxer-notif-iter-addr=%p",
1184 muxer_comp
, muxer_notif_iter
);
1188 for (i
= 0; i
< count
; i
++) {
1189 struct bt_private_port
*priv_port
=
1190 bt_private_component_filter_get_input_private_port_by_index(
1191 muxer_comp
->priv_comp
, i
);
1192 struct bt_port
*port
;
1195 port
= bt_port_from_private_port(priv_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
));
1209 muxer_notif_iter
->newly_connected_priv_ports
=
1211 muxer_notif_iter
->newly_connected_priv_ports
,
1213 if (!muxer_notif_iter
->newly_connected_priv_ports
) {
1214 BT_LOGE("Cannot append port to muxer's notification iterator list of newly connected input ports: "
1215 "port-addr=%p, port-name=\"%s\", "
1216 "muxer-notif-iter-addr=%p", port
,
1217 bt_port_get_name(port
), muxer_notif_iter
);
1222 BT_LOGD("Appended port to muxer's notification iterator list of newly connected input ports: "
1223 "port-addr=%p, port-name=\"%s\", "
1224 "muxer-notif-iter-addr=%p", port
,
1225 bt_port_get_name(port
), muxer_notif_iter
);
1234 enum bt_notification_iterator_status
muxer_notif_iter_init(
1235 struct bt_private_notification_iterator
*priv_notif_iter
,
1236 struct bt_private_port
*output_priv_port
)
1238 struct muxer_comp
*muxer_comp
= NULL
;
1239 struct muxer_notif_iter
*muxer_notif_iter
= NULL
;
1240 struct bt_private_component
*priv_comp
= NULL
;
1241 enum bt_notification_iterator_status status
=
1242 BT_NOTIFICATION_ITERATOR_STATUS_OK
;
1245 priv_comp
= bt_private_notification_iterator_get_private_component(
1248 muxer_comp
= bt_private_component_get_user_data(priv_comp
);
1250 BT_LOGD("Initializing muxer component's notification iterator: "
1251 "comp-addr=%p, muxer-comp-addr=%p, notif-iter-addr=%p",
1252 priv_comp
, muxer_comp
, priv_notif_iter
);
1254 if (muxer_comp
->initializing_muxer_notif_iter
) {
1256 * Weird, unhandled situation detected: downstream
1257 * creates a muxer notification iterator while creating
1258 * another muxer notification iterator (same component).
1260 BT_LOGE("Recursive initialization of muxer component's notification iterator: "
1261 "comp-addr=%p, muxer-comp-addr=%p, notif-iter-addr=%p",
1262 priv_comp
, muxer_comp
, priv_notif_iter
);
1266 muxer_comp
->initializing_muxer_notif_iter
= true;
1267 muxer_notif_iter
= g_new0(struct muxer_notif_iter
, 1);
1268 if (!muxer_notif_iter
) {
1269 BT_LOGE_STR("Failed to allocate one muxer component's notification iterator.");
1273 muxer_notif_iter
->last_returned_ts_ns
= INT64_MIN
;
1274 muxer_notif_iter
->muxer_upstream_notif_iters
=
1275 g_ptr_array_new_with_free_func(
1276 (GDestroyNotify
) destroy_muxer_upstream_notif_iter
);
1277 if (!muxer_notif_iter
->muxer_upstream_notif_iters
) {
1278 BT_LOGE_STR("Failed to allocate a GPtrArray.");
1283 * Add the muxer notification iterator to the component's array
1284 * of muxer notification iterators here because
1285 * muxer_notif_iter_init_newly_connected_ports() can cause
1286 * muxer_port_connected() to be called, which adds the newly
1287 * connected port to each muxer notification iterator's list of
1288 * newly connected ports.
1290 g_ptr_array_add(muxer_comp
->muxer_notif_iters
, muxer_notif_iter
);
1291 ret
= muxer_notif_iter_init_newly_connected_ports(muxer_comp
,
1294 BT_LOGE("Cannot initialize newly connected input ports for muxer component's notification iterator: "
1295 "comp-addr=%p, muxer-comp-addr=%p, "
1296 "muxer-notif-iter-addr=%p, notif-iter-addr=%p, ret=%d",
1297 priv_comp
, muxer_comp
, muxer_notif_iter
,
1298 priv_notif_iter
, ret
);
1302 ret
= bt_private_notification_iterator_set_user_data(priv_notif_iter
,
1305 BT_LOGD("Initialized muxer component's notification iterator: "
1306 "comp-addr=%p, muxer-comp-addr=%p, muxer-notif-iter-addr=%p, "
1307 "notif-iter-addr=%p",
1308 priv_comp
, muxer_comp
, muxer_notif_iter
, priv_notif_iter
);
1312 if (g_ptr_array_index(muxer_comp
->muxer_notif_iters
,
1313 muxer_comp
->muxer_notif_iters
->len
- 1) == muxer_notif_iter
) {
1314 g_ptr_array_remove_index(muxer_comp
->muxer_notif_iters
,
1315 muxer_comp
->muxer_notif_iters
->len
- 1);
1318 destroy_muxer_notif_iter(muxer_notif_iter
);
1319 ret
= bt_private_notification_iterator_set_user_data(priv_notif_iter
,
1322 status
= BT_NOTIFICATION_ITERATOR_STATUS_ERROR
;
1325 muxer_comp
->initializing_muxer_notif_iter
= false;
1331 void muxer_notif_iter_finalize(
1332 struct bt_private_notification_iterator
*priv_notif_iter
)
1334 struct muxer_notif_iter
*muxer_notif_iter
=
1335 bt_private_notification_iterator_get_user_data(priv_notif_iter
);
1336 struct bt_private_component
*priv_comp
= NULL
;
1337 struct muxer_comp
*muxer_comp
= NULL
;
1339 priv_comp
= bt_private_notification_iterator_get_private_component(
1342 muxer_comp
= bt_private_component_get_user_data(priv_comp
);
1343 BT_LOGD("Finalizing muxer component's notification iterator: "
1344 "comp-addr=%p, muxer-comp-addr=%p, muxer-notif-iter-addr=%p, "
1345 "notif-iter-addr=%p",
1346 priv_comp
, muxer_comp
, muxer_notif_iter
, priv_notif_iter
);
1349 (void) g_ptr_array_remove_fast(muxer_comp
->muxer_notif_iters
,
1351 destroy_muxer_notif_iter(muxer_notif_iter
);
1358 struct bt_notification_iterator_next_return
muxer_notif_iter_next(
1359 struct bt_private_notification_iterator
*priv_notif_iter
)
1361 struct bt_notification_iterator_next_return next_ret
;
1362 struct muxer_notif_iter
*muxer_notif_iter
=
1363 bt_private_notification_iterator_get_user_data(priv_notif_iter
);
1364 struct bt_private_component
*priv_comp
= NULL
;
1365 struct muxer_comp
*muxer_comp
= NULL
;
1367 assert(muxer_notif_iter
);
1368 priv_comp
= bt_private_notification_iterator_get_private_component(
1371 muxer_comp
= bt_private_component_get_user_data(priv_comp
);
1374 BT_LOGV("Muxer component's notification iterator's \"next\" method called: "
1375 "comp-addr=%p, muxer-comp-addr=%p, muxer-notif-iter-addr=%p, "
1376 "notif-iter-addr=%p",
1377 priv_comp
, muxer_comp
, muxer_notif_iter
, priv_notif_iter
);
1379 /* Are we in an error state set elsewhere? */
1380 if (unlikely(muxer_comp
->error
)) {
1381 BT_LOGE("Muxer component is already in an error state: returning BT_NOTIFICATION_ITERATOR_STATUS_ERROR: "
1382 "comp-addr=%p, muxer-comp-addr=%p, muxer-notif-iter-addr=%p, "
1383 "notif-iter-addr=%p",
1384 priv_comp
, muxer_comp
, muxer_notif_iter
, priv_notif_iter
);
1385 next_ret
.notification
= NULL
;
1386 next_ret
.status
= BT_NOTIFICATION_ITERATOR_STATUS_ERROR
;
1390 next_ret
= muxer_notif_iter_do_next(muxer_comp
, muxer_notif_iter
);
1391 if (next_ret
.status
< 0) {
1392 BT_LOGE("Cannot get next notification: "
1393 "comp-addr=%p, muxer-comp-addr=%p, muxer-notif-iter-addr=%p, "
1394 "notif-iter-addr=%p, status=%s",
1395 priv_comp
, muxer_comp
, muxer_notif_iter
, priv_notif_iter
,
1396 bt_notification_iterator_status_string(next_ret
.status
));
1398 BT_LOGV("Returning from muxer component's notification iterator's \"next\" method: "
1399 "status=%s, notif-addr=%p",
1400 bt_notification_iterator_status_string(next_ret
.status
),
1401 next_ret
.notification
);
1410 void muxer_port_connected(
1411 struct bt_private_component
*priv_comp
,
1412 struct bt_private_port
*self_private_port
,
1413 struct bt_port
*other_port
)
1415 struct bt_port
*self_port
=
1416 bt_port_from_private_port(self_private_port
);
1417 struct muxer_comp
*muxer_comp
=
1418 bt_private_component_get_user_data(priv_comp
);
1424 BT_LOGD("Port connected: "
1425 "comp-addr=%p, muxer-comp-addr=%p, "
1426 "port-addr=%p, port-name=\"%s\", "
1427 "other-port-addr=%p, other-port-name=\"%s\"",
1428 priv_comp
, muxer_comp
, self_port
, bt_port_get_name(self_port
),
1429 other_port
, bt_port_get_name(other_port
));
1431 if (bt_port_get_type(self_port
) == BT_PORT_TYPE_OUTPUT
) {
1435 for (i
= 0; i
< muxer_comp
->muxer_notif_iters
->len
; i
++) {
1436 struct muxer_notif_iter
*muxer_notif_iter
=
1437 g_ptr_array_index(muxer_comp
->muxer_notif_iters
, i
);
1440 * Add this port to the list of newly connected ports
1441 * for this muxer notification iterator. We append at
1442 * the end of this list while
1443 * muxer_notif_iter_handle_newly_connected_ports()
1444 * removes the nodes from the beginning.
1446 muxer_notif_iter
->newly_connected_priv_ports
=
1448 muxer_notif_iter
->newly_connected_priv_ports
,
1450 if (!muxer_notif_iter
->newly_connected_priv_ports
) {
1451 BT_LOGE("Cannot append port to muxer's notification iterator list of newly connected input ports: "
1452 "port-addr=%p, port-name=\"%s\", "
1453 "muxer-notif-iter-addr=%p", self_port
,
1454 bt_port_get_name(self_port
), muxer_notif_iter
);
1455 muxer_comp
->error
= true;
1459 BT_LOGD("Appended port to muxer's notification iterator list of newly connected input ports: "
1460 "port-addr=%p, port-name=\"%s\", "
1461 "muxer-notif-iter-addr=%p", self_port
,
1462 bt_port_get_name(self_port
), muxer_notif_iter
);
1465 /* One less available input port */
1466 muxer_comp
->available_input_ports
--;
1467 ret
= ensure_available_input_port(priv_comp
);
1470 * Only way to report an error later since this
1471 * method does not return anything.
1473 BT_LOGE("Cannot ensure that at least one muxer component's input port is available: "
1474 "muxer-comp-addr=%p, status=%s",
1475 muxer_comp
, bt_component_status_string(ret
));
1476 muxer_comp
->error
= true;
1485 void muxer_port_disconnected(struct bt_private_component
*priv_comp
,
1486 struct bt_private_port
*priv_port
)
1488 struct bt_port
*port
= bt_port_from_private_port(priv_port
);
1489 struct muxer_comp
*muxer_comp
=
1490 bt_private_component_get_user_data(priv_comp
);
1494 BT_LOGD("Port disconnected: "
1495 "comp-addr=%p, muxer-comp-addr=%p, port-addr=%p, "
1496 "port-name=\"%s\"", priv_comp
, muxer_comp
,
1497 port
, bt_port_get_name(port
));
1500 * There's nothing special to do when a port is disconnected
1501 * because this component deals with upstream notification
1502 * iterators which were already created thanks to connected
1503 * ports. The fact that the port is disconnected does not cancel
1504 * the upstream notification iterators created using its
1505 * connection: they still exist, even if the connection is dead.
1506 * The only way to remove an upstream notification iterator is
1507 * for its "next" operation to return
1508 * BT_NOTIFICATION_ITERATOR_STATUS_END.
1510 if (bt_port_get_type(port
) == BT_PORT_TYPE_INPUT
) {
1511 /* One more available input port */
1512 muxer_comp
->available_input_ports
++;
1513 BT_LOGD("Leaving disconnected input port available for future connections: "
1514 "comp-addr=%p, muxer-comp-addr=%p, port-addr=%p, "
1515 "port-name=\"%s\", avail-input-port-count=%zu",
1516 priv_comp
, muxer_comp
, port
, bt_port_get_name(port
),
1517 muxer_comp
->available_input_ports
);