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/value-internal.h>
30 #include <babeltrace/graph/component-internal.h>
31 #include <babeltrace/graph/message-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_message_iterator *
50 GPtrArray
*muxer_msg_iters
;
53 bt_self_component_filter
*self_comp
;
55 unsigned int next_port_num
;
56 size_t available_input_ports
;
57 bool initializing_muxer_msg_iter
;
58 bool assume_absolute_clock_classes
;
61 struct muxer_upstream_msg_iter
{
62 /* Owned by this, NULL if ended */
63 bt_self_component_port_input_message_iterator
*msg_iter
;
65 /* Contains `const bt_message *`, owned by this */
69 enum muxer_msg_iter_clock_class_expectation
{
70 MUXER_MSG_ITER_CLOCK_CLASS_EXPECTATION_ANY
= 0,
71 MUXER_MSG_ITER_CLOCK_CLASS_EXPECTATION_ABSOLUTE
,
72 MUXER_MSG_ITER_CLOCK_CLASS_EXPECTATION_NOT_ABS_SPEC_UUID
,
73 MUXER_MSG_ITER_CLOCK_CLASS_EXPECTATION_NOT_ABS_NO_UUID
,
76 struct muxer_msg_iter
{
78 * Array of struct muxer_upstream_msg_iter * (owned by this).
80 * NOTE: This array is searched in linearly to find the youngest
81 * current message. Keep this until benchmarks confirm that
82 * another data structure is faster than this for our typical
85 GPtrArray
*muxer_upstream_msg_iters
;
88 * List of "recently" connected input ports (weak) to
89 * handle by this muxer message iterator.
90 * muxer_port_connected() adds entries to this list, and the
91 * entries are removed when a message iterator is created
92 * on the port's connection and put into
93 * muxer_upstream_msg_iters above by
94 * muxer_msg_iter_handle_newly_connected_ports().
96 GList
*newly_connected_self_ports
;
98 /* Last time returned in a message */
99 int64_t last_returned_ts_ns
;
101 /* Clock class expectation state */
102 enum muxer_msg_iter_clock_class_expectation clock_class_expectation
;
105 * Expected clock class UUID, only valid when
106 * clock_class_expectation is
107 * MUXER_MSG_ITER_CLOCK_CLASS_EXPECTATION_NOT_ABS_SPEC_UUID.
109 unsigned char expected_clock_class_uuid
[BABELTRACE_UUID_LEN
];
113 void destroy_muxer_upstream_msg_iter(
114 struct muxer_upstream_msg_iter
*muxer_upstream_msg_iter
)
116 if (!muxer_upstream_msg_iter
) {
120 BT_LOGD("Destroying muxer's upstream message iterator wrapper: "
121 "addr=%p, msg-iter-addr=%p, queue-len=%u",
122 muxer_upstream_msg_iter
,
123 muxer_upstream_msg_iter
->msg_iter
,
124 muxer_upstream_msg_iter
->msgs
->length
);
125 bt_self_component_port_input_message_iterator_put_ref(muxer_upstream_msg_iter
->msg_iter
);
127 if (muxer_upstream_msg_iter
->msgs
) {
128 const bt_message
*msg
;
130 while ((msg
= g_queue_pop_head(
131 muxer_upstream_msg_iter
->msgs
))) {
132 bt_message_put_ref(msg
);
135 g_queue_free(muxer_upstream_msg_iter
->msgs
);
138 g_free(muxer_upstream_msg_iter
);
142 struct muxer_upstream_msg_iter
*muxer_msg_iter_add_upstream_msg_iter(
143 struct muxer_msg_iter
*muxer_msg_iter
,
144 bt_self_component_port_input_message_iterator
*self_msg_iter
)
146 struct muxer_upstream_msg_iter
*muxer_upstream_msg_iter
=
147 g_new0(struct muxer_upstream_msg_iter
, 1);
149 if (!muxer_upstream_msg_iter
) {
150 BT_LOGE_STR("Failed to allocate one muxer's upstream message iterator wrapper.");
154 muxer_upstream_msg_iter
->msg_iter
= self_msg_iter
;
155 bt_self_component_port_input_message_iterator_get_ref(muxer_upstream_msg_iter
->msg_iter
);
156 muxer_upstream_msg_iter
->msgs
= g_queue_new();
157 if (!muxer_upstream_msg_iter
->msgs
) {
158 BT_LOGE_STR("Failed to allocate a GQueue.");
162 g_ptr_array_add(muxer_msg_iter
->muxer_upstream_msg_iters
,
163 muxer_upstream_msg_iter
);
164 BT_LOGD("Added muxer's upstream message iterator wrapper: "
165 "addr=%p, muxer-msg-iter-addr=%p, msg-iter-addr=%p",
166 muxer_upstream_msg_iter
, muxer_msg_iter
,
170 return muxer_upstream_msg_iter
;
174 enum bt_self_component_status
ensure_available_input_port(
175 bt_self_component_filter
*self_comp
)
177 struct muxer_comp
*muxer_comp
= bt_self_component_get_data(
178 bt_self_component_filter_as_self_component(self_comp
));
179 enum bt_self_component_status status
= BT_SELF_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_SELF_COMPONENT_STATUS_NOMEM
;
195 g_string_append_printf(port_name
, "%u", muxer_comp
->next_port_num
);
196 status
= bt_self_component_filter_add_input_port(
197 self_comp
, port_name
->str
, NULL
, NULL
);
198 if (status
!= BT_SELF_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
, self_comp
,
202 bt_self_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
, self_comp
);
213 g_string_free(port_name
, TRUE
);
220 enum bt_self_component_status
create_output_port(
221 bt_self_component_filter
*self_comp
)
223 return bt_self_component_filter_add_output_port(
224 self_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-msg-iter-count=%u", muxer_comp
,
236 muxer_comp
->muxer_msg_iters
?
237 muxer_comp
->muxer_msg_iters
->len
: 0);
239 if (muxer_comp
->muxer_msg_iters
) {
240 g_ptr_array_free(muxer_comp
->muxer_msg_iters
, TRUE
);
247 bt_value
*get_default_params(void)
252 params
= bt_value_map_create();
254 BT_LOGE_STR("Cannot create a map value object.");
258 ret
= bt_value_map_insert_bool_entry(params
,
259 ASSUME_ABSOLUTE_CLOCK_CLASSES_PARAM_NAME
, false);
261 BT_LOGE_STR("Cannot add boolean value to map value object.");
268 BT_VALUE_PUT_REF_AND_RESET(params
);
275 int configure_muxer_comp(struct muxer_comp
*muxer_comp
,
276 const bt_value
*params
)
278 bt_value
*default_params
= NULL
;
279 bt_value
*real_params
= NULL
;
280 const bt_value
*assume_absolute_clock_classes
= NULL
;
284 default_params
= get_default_params();
285 if (!default_params
) {
286 BT_LOGE("Cannot get default parameters: "
287 "muxer-comp-addr=%p", muxer_comp
);
291 ret
= bt_value_map_extend(default_params
, params
, &real_params
);
293 BT_LOGE("Cannot extend default parameters map value: "
294 "muxer-comp-addr=%p, def-params-addr=%p, "
295 "params-addr=%p", muxer_comp
, default_params
,
300 assume_absolute_clock_classes
= bt_value_map_borrow_entry_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_value_put_ref(default_params
);
324 bt_value_put_ref(real_params
);
329 enum bt_self_component_status
muxer_init(
330 bt_self_component_filter
*self_comp
,
331 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_msg_iters
= g_ptr_array_new();
354 if (!muxer_comp
->muxer_msg_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_as_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_as_self_component(self_comp
),
393 if (status
== BT_SELF_COMPONENT_STATUS_OK
) {
394 status
= BT_SELF_COMPONENT_STATUS_ERROR
;
402 void muxer_finalize(bt_self_component_filter
*self_comp
)
404 struct muxer_comp
*muxer_comp
= bt_self_component_get_data(
405 bt_self_component_filter_as_self_component(self_comp
));
407 BT_LOGD("Finalizing muxer component: comp-addr=%p",
409 destroy_muxer_comp(muxer_comp
);
413 bt_self_component_port_input_message_iterator
*
414 create_msg_iter_on_input_port(
415 bt_self_component_port_input
*self_port
, int *ret
)
417 const bt_port
*port
= bt_self_component_port_as_port(
418 bt_self_component_port_input_as_self_component_port(
420 bt_self_component_port_input_message_iterator
*msg_iter
=
426 BT_ASSERT(bt_port_is_connected(port
));
428 // TODO: Advance the iterator to >= the time of the latest
429 // returned message by the muxer message
430 // iterator which creates it.
431 msg_iter
= bt_self_component_port_input_message_iterator_create(
434 BT_LOGE("Cannot create upstream message iterator on input port: "
435 "port-addr=%p, port-name=\"%s\"",
436 port
, bt_port_get_name(port
));
441 BT_LOGD("Created upstream message iterator on input port: "
442 "port-addr=%p, port-name=\"%s\", msg-iter-addr=%p",
443 port
, bt_port_get_name(port
), msg_iter
);
450 enum bt_message_iterator_status
muxer_upstream_msg_iter_next(
451 struct muxer_upstream_msg_iter
*muxer_upstream_msg_iter
)
453 enum bt_message_iterator_status status
;
454 bt_message_array_const msgs
;
458 BT_LOGV("Calling upstream message iterator's \"next\" method: "
459 "muxer-upstream-msg-iter-wrap-addr=%p, msg-iter-addr=%p",
460 muxer_upstream_msg_iter
,
461 muxer_upstream_msg_iter
->msg_iter
);
462 status
= bt_self_component_port_input_message_iterator_next(
463 muxer_upstream_msg_iter
->msg_iter
, &msgs
, &count
);
464 BT_LOGV("Upstream message iterator's \"next\" method returned: "
465 "status=%s", bt_message_iterator_status_string(status
));
468 case BT_MESSAGE_ITERATOR_STATUS_OK
:
470 * Message iterator's current message is
471 * valid: it must be considered for muxing operations.
473 BT_LOGV_STR("Validated upstream message iterator wrapper.");
474 BT_ASSERT(count
> 0);
476 /* Move messages to our queue */
477 for (i
= 0; i
< count
; i
++) {
479 * Push to tail in order; other side
480 * (muxer_msg_iter_do_next_one()) consumes
481 * from the head first.
483 g_queue_push_tail(muxer_upstream_msg_iter
->msgs
,
487 case BT_MESSAGE_ITERATOR_STATUS_AGAIN
:
489 * Message iterator's current message is not
490 * valid anymore. Return
491 * BT_MESSAGE_ITERATOR_STATUS_AGAIN immediately.
494 case BT_MESSAGE_ITERATOR_STATUS_END
: /* Fall-through. */
495 case BT_MESSAGE_ITERATOR_STATUS_CANCELED
:
497 * Message iterator reached the end: release it. It
498 * won't be considered again to find the youngest
501 BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_PUT_REF_AND_RESET(muxer_upstream_msg_iter
->msg_iter
);
502 status
= BT_MESSAGE_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_MESSAGE_ITERATOR_STATUS_ERROR
;
516 int muxer_msg_iter_handle_newly_connected_ports(
517 struct muxer_msg_iter
*muxer_msg_iter
)
521 BT_LOGV("Handling newly connected ports: "
522 "muxer-msg-iter-addr=%p", muxer_msg_iter
);
525 * Here we create one upstream message iterator for each
526 * newly connected port. We do NOT perform an initial "next" on
527 * those new upstream message 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_msg_iter
->newly_connected_self_ports
;
534 bt_self_component_port_input
*self_port
;
536 bt_self_component_port_input_message_iterator
*
537 upstream_msg_iter
= NULL
;
538 struct muxer_upstream_msg_iter
*muxer_upstream_msg_iter
;
544 self_port
= node
->data
;
545 port
= bt_self_component_port_as_port(
546 bt_self_component_port_input_as_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 * message iterator on its (non-existing)
555 * connection in this case.
560 upstream_msg_iter
= create_msg_iter_on_input_port(
563 /* create_msg_iter_on_input_port() logs errors */
564 BT_ASSERT(!upstream_msg_iter
);
568 muxer_upstream_msg_iter
=
569 muxer_msg_iter_add_upstream_msg_iter(
570 muxer_msg_iter
, upstream_msg_iter
);
571 BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_PUT_REF_AND_RESET(upstream_msg_iter
);
572 if (!muxer_upstream_msg_iter
) {
574 * muxer_msg_iter_add_upstream_msg_iter()
581 bt_self_component_port_input_message_iterator_put_ref(upstream_msg_iter
);
582 muxer_msg_iter
->newly_connected_self_ports
=
584 muxer_msg_iter
->newly_connected_self_ports
,
600 int get_msg_ts_ns(struct muxer_comp
*muxer_comp
,
601 struct muxer_msg_iter
*muxer_msg_iter
,
602 const bt_message
*msg
, int64_t last_returned_ts_ns
,
605 const bt_clock_class
*clock_class
= NULL
;
606 const bt_clock_value
*clock_value
= NULL
;
607 const 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 message's timestamp: "
617 "muxer-msg-iter-addr=%p, msg-addr=%p, "
618 "last-returned-ts=%" PRId64
,
619 muxer_msg_iter
, msg
, last_returned_ts_ns
);
621 switch (bt_message_get_type(msg
)) {
622 case BT_MESSAGE_TYPE_EVENT
:
623 event
= bt_message_event_borrow_event_const(msg
);
625 cv_status
= bt_event_borrow_default_clock_value_const(event
,
629 case BT_MESSAGE_TYPE_INACTIVITY
:
631 bt_message_inactivity_borrow_default_clock_value_const(
635 /* All the other messages have a higher priority */
636 BT_LOGV_STR("Message 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 * message has no time. In this case it's always the
653 BT_LOGV_STR("Message'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_const(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_msg_iter
->clock_class_expectation
==
665 MUXER_MSG_ITER_CLOCK_CLASS_EXPECTATION_ANY
) {
667 * This is the first clock class that this muxer
668 * message 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_msg_iter
->clock_class_expectation
=
676 MUXER_MSG_ITER_CLOCK_CLASS_EXPECTATION_ABSOLUTE
;
680 * Expect non-absolute clock classes
681 * with a specific UUID.
683 muxer_msg_iter
->clock_class_expectation
=
684 MUXER_MSG_ITER_CLOCK_CLASS_EXPECTATION_NOT_ABS_SPEC_UUID
;
685 memcpy(muxer_msg_iter
->expected_clock_class_uuid
,
686 cc_uuid
, BABELTRACE_UUID_LEN
);
689 * Expect non-absolute clock classes
692 muxer_msg_iter
->clock_class_expectation
=
693 MUXER_MSG_ITER_CLOCK_CLASS_EXPECTATION_NOT_ABS_NO_UUID
;
698 if (!muxer_comp
->assume_absolute_clock_classes
) {
699 switch (muxer_msg_iter
->clock_class_expectation
) {
700 case MUXER_MSG_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_MSG_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_MSG_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_msg_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_msg_iter
->expected_clock_class_uuid
[0],
769 (unsigned int) muxer_msg_iter
->expected_clock_class_uuid
[1],
770 (unsigned int) muxer_msg_iter
->expected_clock_class_uuid
[2],
771 (unsigned int) muxer_msg_iter
->expected_clock_class_uuid
[3],
772 (unsigned int) muxer_msg_iter
->expected_clock_class_uuid
[4],
773 (unsigned int) muxer_msg_iter
->expected_clock_class_uuid
[5],
774 (unsigned int) muxer_msg_iter
->expected_clock_class_uuid
[6],
775 (unsigned int) muxer_msg_iter
->expected_clock_class_uuid
[7],
776 (unsigned int) muxer_msg_iter
->expected_clock_class_uuid
[8],
777 (unsigned int) muxer_msg_iter
->expected_clock_class_uuid
[9],
778 (unsigned int) muxer_msg_iter
->expected_clock_class_uuid
[10],
779 (unsigned int) muxer_msg_iter
->expected_clock_class_uuid
[11],
780 (unsigned int) muxer_msg_iter
->expected_clock_class_uuid
[12],
781 (unsigned int) muxer_msg_iter
->expected_clock_class_uuid
[13],
782 (unsigned int) muxer_msg_iter
->expected_clock_class_uuid
[14],
783 (unsigned int) muxer_msg_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_msg_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 message's timestamp: "
827 "muxer-msg-iter-addr=%p, msg-addr=%p, "
828 "last-returned-ts=%" PRId64
", ts=%" PRId64
,
829 muxer_msg_iter
, msg
, last_returned_ts_ns
,
837 * This function finds the youngest available message amongst the
838 * non-ended upstream message iterators and returns the upstream
839 * message iterator which has it, or
840 * BT_MESSAGE_ITERATOR_STATUS_END if there's no available
843 * This function does NOT:
845 * * Update any upstream message iterator.
846 * * Check for newly connected ports.
847 * * Check the upstream message iterators to retry.
849 * On sucess, this function sets *muxer_upstream_msg_iter to the
850 * upstream message iterator of which the current message is
851 * the youngest, and sets *ts_ns to its time.
854 enum bt_message_iterator_status
855 muxer_msg_iter_youngest_upstream_msg_iter(
856 struct muxer_comp
*muxer_comp
,
857 struct muxer_msg_iter
*muxer_msg_iter
,
858 struct muxer_upstream_msg_iter
**muxer_upstream_msg_iter
,
863 int64_t youngest_ts_ns
= INT64_MAX
;
864 enum bt_message_iterator_status status
=
865 BT_MESSAGE_ITERATOR_STATUS_OK
;
867 BT_ASSERT(muxer_comp
);
868 BT_ASSERT(muxer_msg_iter
);
869 BT_ASSERT(muxer_upstream_msg_iter
);
870 *muxer_upstream_msg_iter
= NULL
;
872 for (i
= 0; i
< muxer_msg_iter
->muxer_upstream_msg_iters
->len
; i
++) {
873 const bt_message
*msg
;
874 struct muxer_upstream_msg_iter
*cur_muxer_upstream_msg_iter
=
875 g_ptr_array_index(muxer_msg_iter
->muxer_upstream_msg_iters
, i
);
878 if (!cur_muxer_upstream_msg_iter
->msg_iter
) {
879 /* This upstream message iterator is ended */
880 BT_LOGV("Skipping ended upstream message iterator: "
881 "muxer-upstream-msg-iter-wrap-addr=%p",
882 cur_muxer_upstream_msg_iter
);
886 BT_ASSERT(cur_muxer_upstream_msg_iter
->msgs
->length
> 0);
887 msg
= g_queue_peek_head(cur_muxer_upstream_msg_iter
->msgs
);
889 ret
= get_msg_ts_ns(muxer_comp
, muxer_msg_iter
, msg
,
890 muxer_msg_iter
->last_returned_ts_ns
, &msg_ts_ns
);
892 /* get_msg_ts_ns() logs errors */
893 *muxer_upstream_msg_iter
= NULL
;
894 status
= BT_MESSAGE_ITERATOR_STATUS_ERROR
;
898 if (msg_ts_ns
<= youngest_ts_ns
) {
899 *muxer_upstream_msg_iter
=
900 cur_muxer_upstream_msg_iter
;
901 youngest_ts_ns
= msg_ts_ns
;
902 *ts_ns
= youngest_ts_ns
;
906 if (!*muxer_upstream_msg_iter
) {
907 status
= BT_MESSAGE_ITERATOR_STATUS_END
;
916 enum bt_message_iterator_status
validate_muxer_upstream_msg_iter(
917 struct muxer_upstream_msg_iter
*muxer_upstream_msg_iter
)
919 enum bt_message_iterator_status status
=
920 BT_MESSAGE_ITERATOR_STATUS_OK
;
922 BT_LOGV("Validating muxer's upstream message iterator wrapper: "
923 "muxer-upstream-msg-iter-wrap-addr=%p",
924 muxer_upstream_msg_iter
);
926 if (muxer_upstream_msg_iter
->msgs
->length
> 0 ||
927 !muxer_upstream_msg_iter
->msg_iter
) {
928 BT_LOGV("Already valid or not considered: "
929 "queue-len=%u, upstream-msg-iter-addr=%p",
930 muxer_upstream_msg_iter
->msgs
->length
,
931 muxer_upstream_msg_iter
->msg_iter
);
935 /* muxer_upstream_msg_iter_next() logs details/errors */
936 status
= muxer_upstream_msg_iter_next(muxer_upstream_msg_iter
);
943 enum bt_message_iterator_status
validate_muxer_upstream_msg_iters(
944 struct muxer_msg_iter
*muxer_msg_iter
)
946 enum bt_message_iterator_status status
=
947 BT_MESSAGE_ITERATOR_STATUS_OK
;
950 BT_LOGV("Validating muxer's upstream message iterator wrappers: "
951 "muxer-msg-iter-addr=%p", muxer_msg_iter
);
953 for (i
= 0; i
< muxer_msg_iter
->muxer_upstream_msg_iters
->len
; i
++) {
954 struct muxer_upstream_msg_iter
*muxer_upstream_msg_iter
=
956 muxer_msg_iter
->muxer_upstream_msg_iters
,
959 status
= validate_muxer_upstream_msg_iter(
960 muxer_upstream_msg_iter
);
961 if (status
!= BT_MESSAGE_ITERATOR_STATUS_OK
) {
963 BT_LOGE("Cannot validate muxer's upstream message iterator wrapper: "
964 "muxer-msg-iter-addr=%p, "
965 "muxer-upstream-msg-iter-wrap-addr=%p",
967 muxer_upstream_msg_iter
);
969 BT_LOGV("Cannot validate muxer's upstream message iterator wrapper: "
970 "muxer-msg-iter-addr=%p, "
971 "muxer-upstream-msg-iter-wrap-addr=%p",
973 muxer_upstream_msg_iter
);
980 * Remove this muxer upstream message iterator
981 * if it's ended or canceled.
983 if (!muxer_upstream_msg_iter
->msg_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 message iterator wrapper: ended or canceled: "
989 "muxer-msg-iter-addr=%p, "
990 "muxer-upstream-msg-iter-wrap-addr=%p",
991 muxer_msg_iter
, muxer_upstream_msg_iter
);
992 g_ptr_array_remove_index_fast(
993 muxer_msg_iter
->muxer_upstream_msg_iters
,
1004 enum bt_message_iterator_status
muxer_msg_iter_do_next_one(
1005 struct muxer_comp
*muxer_comp
,
1006 struct muxer_msg_iter
*muxer_msg_iter
,
1007 const bt_message
**msg
)
1009 enum bt_message_iterator_status status
=
1010 BT_MESSAGE_ITERATOR_STATUS_OK
;
1011 struct muxer_upstream_msg_iter
*muxer_upstream_msg_iter
= NULL
;
1012 int64_t next_return_ts
;
1015 int ret
= muxer_msg_iter_handle_newly_connected_ports(
1019 BT_LOGE("Cannot handle newly connected input ports for muxer's message iterator: "
1020 "muxer-comp-addr=%p, muxer-msg-iter-addr=%p, "
1022 muxer_comp
, muxer_msg_iter
, ret
);
1023 status
= BT_MESSAGE_ITERATOR_STATUS_ERROR
;
1027 status
= validate_muxer_upstream_msg_iters(muxer_msg_iter
);
1028 if (status
!= BT_MESSAGE_ITERATOR_STATUS_OK
) {
1029 /* validate_muxer_upstream_msg_iters() logs details */
1034 * At this point, we know that all the existing upstream
1035 * message iterators are valid. However the
1036 * operations to validate them (during
1037 * validate_muxer_upstream_msg_iters()) may have
1038 * connected new ports. If no ports were connected
1039 * during this operation, exit the loop.
1041 if (!muxer_msg_iter
->newly_connected_self_ports
) {
1042 BT_LOGV("Not breaking this loop: muxer's message iterator still has newly connected input ports to handle: "
1043 "muxer-comp-addr=%p", muxer_comp
);
1048 BT_ASSERT(!muxer_msg_iter
->newly_connected_self_ports
);
1051 * At this point we know that all the existing upstream
1052 * message iterators are valid. We can find the one,
1053 * amongst those, of which the current message is the
1056 status
= muxer_msg_iter_youngest_upstream_msg_iter(muxer_comp
,
1057 muxer_msg_iter
, &muxer_upstream_msg_iter
,
1059 if (status
< 0 || status
== BT_MESSAGE_ITERATOR_STATUS_END
||
1060 status
== BT_MESSAGE_ITERATOR_STATUS_CANCELED
) {
1062 BT_LOGE("Cannot find the youngest upstream message iterator wrapper: "
1064 bt_message_iterator_status_string(status
));
1066 BT_LOGV("Cannot find the youngest upstream message iterator wrapper: "
1068 bt_message_iterator_status_string(status
));
1074 if (next_return_ts
< muxer_msg_iter
->last_returned_ts_ns
) {
1075 BT_LOGE("Youngest upstream message iterator wrapper's timestamp is less than muxer's message iterator's last returned timestamp: "
1076 "muxer-msg-iter-addr=%p, ts=%" PRId64
", "
1077 "last-returned-ts=%" PRId64
,
1078 muxer_msg_iter
, next_return_ts
,
1079 muxer_msg_iter
->last_returned_ts_ns
);
1080 status
= BT_MESSAGE_ITERATOR_STATUS_ERROR
;
1084 BT_LOGV("Found youngest upstream message iterator wrapper: "
1085 "muxer-msg-iter-addr=%p, "
1086 "muxer-upstream-msg-iter-wrap-addr=%p, "
1088 muxer_msg_iter
, muxer_upstream_msg_iter
, next_return_ts
);
1089 BT_ASSERT(status
== BT_MESSAGE_ITERATOR_STATUS_OK
);
1090 BT_ASSERT(muxer_upstream_msg_iter
);
1093 * Consume from the queue's head: other side
1094 * (muxer_upstream_msg_iter_next()) writes to the tail.
1096 *msg
= g_queue_pop_head(muxer_upstream_msg_iter
->msgs
);
1098 muxer_msg_iter
->last_returned_ts_ns
= next_return_ts
;
1105 enum bt_message_iterator_status
muxer_msg_iter_do_next(
1106 struct muxer_comp
*muxer_comp
,
1107 struct muxer_msg_iter
*muxer_msg_iter
,
1108 bt_message_array_const msgs
, uint64_t capacity
,
1111 enum bt_message_iterator_status status
=
1112 BT_MESSAGE_ITERATOR_STATUS_OK
;
1115 while (i
< capacity
&& status
== BT_MESSAGE_ITERATOR_STATUS_OK
) {
1116 status
= muxer_msg_iter_do_next_one(muxer_comp
,
1117 muxer_msg_iter
, &msgs
[i
]);
1118 if (status
== BT_MESSAGE_ITERATOR_STATUS_OK
) {
1125 * Even if muxer_msg_iter_do_next_one() returned
1126 * something else than
1127 * BT_MESSAGE_ITERATOR_STATUS_OK, we accumulated
1128 * message objects in the output message
1129 * array, so we need to return
1130 * BT_MESSAGE_ITERATOR_STATUS_OK so that they are
1131 * transfered to downstream. This other status occurs
1132 * again the next time muxer_msg_iter_do_next() is
1133 * called, possibly without any accumulated
1134 * message, in which case we'll return it.
1137 status
= BT_MESSAGE_ITERATOR_STATUS_OK
;
1144 void destroy_muxer_msg_iter(struct muxer_msg_iter
*muxer_msg_iter
)
1146 if (!muxer_msg_iter
) {
1150 BT_LOGD("Destroying muxer component's message iterator: "
1151 "muxer-msg-iter-addr=%p", muxer_msg_iter
);
1153 if (muxer_msg_iter
->muxer_upstream_msg_iters
) {
1154 BT_LOGD_STR("Destroying muxer's upstream message iterator wrappers.");
1156 muxer_msg_iter
->muxer_upstream_msg_iters
, TRUE
);
1159 g_list_free(muxer_msg_iter
->newly_connected_self_ports
);
1160 g_free(muxer_msg_iter
);
1164 int muxer_msg_iter_init_newly_connected_ports(struct muxer_comp
*muxer_comp
,
1165 struct muxer_msg_iter
*muxer_msg_iter
)
1172 * Add the connected input ports to this muxer message
1173 * iterator's list of newly connected ports. They will be
1174 * handled by muxer_msg_iter_handle_newly_connected_ports().
1176 count
= bt_component_filter_get_input_port_count(
1177 bt_self_component_filter_as_component_filter(
1178 muxer_comp
->self_comp
));
1180 BT_LOGD("No input port to initialize for muxer component's message iterator: "
1181 "muxer-comp-addr=%p, muxer-msg-iter-addr=%p",
1182 muxer_comp
, muxer_msg_iter
);
1186 for (i
= 0; i
< count
; i
++) {
1187 bt_self_component_port_input
*self_port
=
1188 bt_self_component_filter_borrow_input_port_by_index(
1189 muxer_comp
->self_comp
, i
);
1190 const bt_port
*port
;
1192 BT_ASSERT(self_port
);
1193 port
= bt_self_component_port_as_port(
1194 bt_self_component_port_input_as_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_msg_iter
->newly_connected_self_ports
=
1207 muxer_msg_iter
->newly_connected_self_ports
,
1209 if (!muxer_msg_iter
->newly_connected_self_ports
) {
1210 BT_LOGE("Cannot append port to muxer's message iterator list of newly connected input ports: "
1211 "port-addr=%p, port-name=\"%s\", "
1212 "muxer-msg-iter-addr=%p", port
,
1213 bt_port_get_name(port
), muxer_msg_iter
);
1218 BT_LOGD("Appended port to muxer's message iterator list of newly connected input ports: "
1219 "port-addr=%p, port-name=\"%s\", "
1220 "muxer-msg-iter-addr=%p", port
,
1221 bt_port_get_name(port
), muxer_msg_iter
);
1229 enum bt_self_message_iterator_status
muxer_msg_iter_init(
1230 bt_self_message_iterator
*self_msg_iter
,
1231 bt_self_component_filter
*self_comp
,
1232 bt_self_component_port_output
*port
)
1234 struct muxer_comp
*muxer_comp
= NULL
;
1235 struct muxer_msg_iter
*muxer_msg_iter
= NULL
;
1236 enum bt_self_message_iterator_status status
=
1237 BT_MESSAGE_ITERATOR_STATUS_OK
;
1240 muxer_comp
= bt_self_component_get_data(
1241 bt_self_component_filter_as_self_component(self_comp
));
1242 BT_ASSERT(muxer_comp
);
1243 BT_LOGD("Initializing muxer component's message iterator: "
1244 "comp-addr=%p, muxer-comp-addr=%p, msg-iter-addr=%p",
1245 self_comp
, muxer_comp
, self_msg_iter
);
1247 if (muxer_comp
->initializing_muxer_msg_iter
) {
1249 * Weird, unhandled situation detected: downstream
1250 * creates a muxer message iterator while creating
1251 * another muxer message iterator (same component).
1253 BT_LOGE("Recursive initialization of muxer component's message iterator: "
1254 "comp-addr=%p, muxer-comp-addr=%p, msg-iter-addr=%p",
1255 self_comp
, muxer_comp
, self_msg_iter
);
1259 muxer_comp
->initializing_muxer_msg_iter
= true;
1260 muxer_msg_iter
= g_new0(struct muxer_msg_iter
, 1);
1261 if (!muxer_msg_iter
) {
1262 BT_LOGE_STR("Failed to allocate one muxer component's message iterator.");
1266 muxer_msg_iter
->last_returned_ts_ns
= INT64_MIN
;
1267 muxer_msg_iter
->muxer_upstream_msg_iters
=
1268 g_ptr_array_new_with_free_func(
1269 (GDestroyNotify
) destroy_muxer_upstream_msg_iter
);
1270 if (!muxer_msg_iter
->muxer_upstream_msg_iters
) {
1271 BT_LOGE_STR("Failed to allocate a GPtrArray.");
1276 * Add the muxer message iterator to the component's array
1277 * of muxer message iterators here because
1278 * muxer_msg_iter_init_newly_connected_ports() can cause
1279 * muxer_port_connected() to be called, which adds the newly
1280 * connected port to each muxer message iterator's list of
1281 * newly connected ports.
1283 g_ptr_array_add(muxer_comp
->muxer_msg_iters
, muxer_msg_iter
);
1284 ret
= muxer_msg_iter_init_newly_connected_ports(muxer_comp
,
1287 BT_LOGE("Cannot initialize newly connected input ports for muxer component's message iterator: "
1288 "comp-addr=%p, muxer-comp-addr=%p, "
1289 "muxer-msg-iter-addr=%p, msg-iter-addr=%p, ret=%d",
1290 self_comp
, muxer_comp
, muxer_msg_iter
,
1291 self_msg_iter
, ret
);
1295 bt_self_message_iterator_set_data(self_msg_iter
,
1297 BT_LOGD("Initialized muxer component's message iterator: "
1298 "comp-addr=%p, muxer-comp-addr=%p, muxer-msg-iter-addr=%p, "
1300 self_comp
, muxer_comp
, muxer_msg_iter
, self_msg_iter
);
1304 if (g_ptr_array_index(muxer_comp
->muxer_msg_iters
,
1305 muxer_comp
->muxer_msg_iters
->len
- 1) == muxer_msg_iter
) {
1306 g_ptr_array_remove_index(muxer_comp
->muxer_msg_iters
,
1307 muxer_comp
->muxer_msg_iters
->len
- 1);
1310 destroy_muxer_msg_iter(muxer_msg_iter
);
1311 bt_self_message_iterator_set_data(self_msg_iter
,
1313 status
= BT_MESSAGE_ITERATOR_STATUS_ERROR
;
1316 muxer_comp
->initializing_muxer_msg_iter
= false;
1321 void muxer_msg_iter_finalize(
1322 bt_self_message_iterator
*self_msg_iter
)
1324 struct muxer_msg_iter
*muxer_msg_iter
=
1325 bt_self_message_iterator_get_data(self_msg_iter
);
1326 bt_self_component
*self_comp
= NULL
;
1327 struct muxer_comp
*muxer_comp
= NULL
;
1329 self_comp
= bt_self_message_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 message iterator: "
1334 "comp-addr=%p, muxer-comp-addr=%p, muxer-msg-iter-addr=%p, "
1336 self_comp
, muxer_comp
, muxer_msg_iter
, self_msg_iter
);
1339 (void) g_ptr_array_remove_fast(muxer_comp
->muxer_msg_iters
,
1341 destroy_muxer_msg_iter(muxer_msg_iter
);
1346 enum bt_message_iterator_status
muxer_msg_iter_next(
1347 bt_self_message_iterator
*self_msg_iter
,
1348 bt_message_array_const msgs
, uint64_t capacity
,
1351 enum bt_message_iterator_status status
;
1352 struct muxer_msg_iter
*muxer_msg_iter
=
1353 bt_self_message_iterator_get_data(self_msg_iter
);
1354 bt_self_component
*self_comp
= NULL
;
1355 struct muxer_comp
*muxer_comp
= NULL
;
1357 BT_ASSERT(muxer_msg_iter
);
1358 self_comp
= bt_self_message_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 message iterator's \"next\" method called: "
1364 "comp-addr=%p, muxer-comp-addr=%p, muxer-msg-iter-addr=%p, "
1366 self_comp
, muxer_comp
, muxer_msg_iter
, self_msg_iter
);
1368 status
= muxer_msg_iter_do_next(muxer_comp
, muxer_msg_iter
,
1369 msgs
, capacity
, count
);
1371 BT_LOGE("Cannot get next message: "
1372 "comp-addr=%p, muxer-comp-addr=%p, muxer-msg-iter-addr=%p, "
1373 "msg-iter-addr=%p, status=%s",
1374 self_comp
, muxer_comp
, muxer_msg_iter
, self_msg_iter
,
1375 bt_message_iterator_status_string(status
));
1377 BT_LOGV("Returning from muxer component's message iterator's \"next\" method: "
1379 bt_message_iterator_status_string(status
));
1386 enum bt_self_component_status
muxer_input_port_connected(
1387 bt_self_component_filter
*self_comp
,
1388 bt_self_component_port_input
*self_port
,
1389 const bt_port_output
*other_port
)
1391 enum bt_self_component_status status
= BT_SELF_COMPONENT_STATUS_OK
;
1392 const bt_port
*port
= bt_self_component_port_as_port(
1393 bt_self_component_port_input_as_self_component_port(
1395 struct muxer_comp
*muxer_comp
=
1396 bt_self_component_get_data(
1397 bt_self_component_filter_as_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_as_port_const(other_port
)));
1412 for (i
= 0; i
< muxer_comp
->muxer_msg_iters
->len
; i
++) {
1413 struct muxer_msg_iter
*muxer_msg_iter
=
1414 g_ptr_array_index(muxer_comp
->muxer_msg_iters
, i
);
1417 * Add this port to the list of newly connected ports
1418 * for this muxer message iterator. We append at
1419 * the end of this list while
1420 * muxer_msg_iter_handle_newly_connected_ports()
1421 * removes the nodes from the beginning.
1423 muxer_msg_iter
->newly_connected_self_ports
=
1425 muxer_msg_iter
->newly_connected_self_ports
,
1427 if (!muxer_msg_iter
->newly_connected_self_ports
) {
1428 BT_LOGE("Cannot append port to muxer's message iterator list of newly connected input ports: "
1429 "port-addr=%p, port-name=\"%s\", "
1430 "muxer-msg-iter-addr=%p", self_port
,
1431 bt_port_get_name(port
), muxer_msg_iter
);
1432 status
= BT_SELF_COMPONENT_STATUS_ERROR
;
1436 BT_LOGD("Appended port to muxer's message iterator list of newly connected input ports: "
1437 "port-addr=%p, port-name=\"%s\", "
1438 "muxer-msg-iter-addr=%p", self_port
,
1439 bt_port_get_name(port
), muxer_msg_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 bt_self_component_filter
*self_component
,
1464 bt_self_component_port_input
*self_port
)
1466 struct muxer_comp
*muxer_comp
=
1467 bt_self_component_get_data(
1468 bt_self_component_filter_as_self_component(
1470 const bt_port
*port
=
1471 bt_self_component_port_as_port(
1472 bt_self_component_port_input_as_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
);