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 "common/macros.h"
27 #include "compat/uuid.h"
28 #include <babeltrace2/babeltrace.h>
29 #include "lib/value.h"
30 #include "lib/graph/component.h"
31 #include "lib/graph/message/iterator.h"
32 #include "lib/graph/connection.h"
36 #include "common/assert.h"
37 #include "common/common.h"
43 #define ASSUME_ABSOLUTE_CLOCK_CLASSES_PARAM_NAME "assume-absolute-clock-classes"
47 bt_self_component_filter
*self_comp
;
49 unsigned int next_port_num
;
50 size_t available_input_ports
;
51 bool initializing_muxer_msg_iter
;
52 bool assume_absolute_clock_classes
;
55 struct muxer_upstream_msg_iter
{
56 /* Owned by this, NULL if ended */
57 bt_self_component_port_input_message_iterator
*msg_iter
;
59 /* Contains `const bt_message *`, owned by this */
63 enum muxer_msg_iter_clock_class_expectation
{
64 MUXER_MSG_ITER_CLOCK_CLASS_EXPECTATION_ANY
= 0,
65 MUXER_MSG_ITER_CLOCK_CLASS_EXPECTATION_NONE
,
66 MUXER_MSG_ITER_CLOCK_CLASS_EXPECTATION_ABSOLUTE
,
67 MUXER_MSG_ITER_CLOCK_CLASS_EXPECTATION_NOT_ABS_SPEC_UUID
,
68 MUXER_MSG_ITER_CLOCK_CLASS_EXPECTATION_NOT_ABS_NO_UUID
,
71 struct muxer_msg_iter
{
73 * Array of struct muxer_upstream_msg_iter * (owned by this).
75 * NOTE: This array is searched in linearly to find the youngest
76 * current message. Keep this until benchmarks confirm that
77 * another data structure is faster than this for our typical
80 GPtrArray
*active_muxer_upstream_msg_iters
;
83 * Array of struct muxer_upstream_msg_iter * (owned by this).
85 * We move ended message iterators from
86 * `active_muxer_upstream_msg_iters` to this array so as to be
87 * able to restore them when seeking.
89 GPtrArray
*ended_muxer_upstream_msg_iters
;
91 /* Last time returned in a message */
92 int64_t last_returned_ts_ns
;
94 /* Clock class expectation state */
95 enum muxer_msg_iter_clock_class_expectation clock_class_expectation
;
98 * Expected clock class UUID, only valid when
99 * clock_class_expectation is
100 * MUXER_MSG_ITER_CLOCK_CLASS_EXPECTATION_NOT_ABS_SPEC_UUID.
102 unsigned char expected_clock_class_uuid
[BABELTRACE_UUID_LEN
];
106 void empty_message_queue(struct muxer_upstream_msg_iter
*upstream_msg_iter
)
108 const bt_message
*msg
;
110 while ((msg
= g_queue_pop_head(upstream_msg_iter
->msgs
))) {
111 bt_message_put_ref(msg
);
116 void destroy_muxer_upstream_msg_iter(
117 struct muxer_upstream_msg_iter
*muxer_upstream_msg_iter
)
119 if (!muxer_upstream_msg_iter
) {
123 BT_LOGD("Destroying muxer's upstream message iterator wrapper: "
124 "addr=%p, msg-iter-addr=%p, queue-len=%u",
125 muxer_upstream_msg_iter
,
126 muxer_upstream_msg_iter
->msg_iter
,
127 muxer_upstream_msg_iter
->msgs
->length
);
128 bt_self_component_port_input_message_iterator_put_ref(
129 muxer_upstream_msg_iter
->msg_iter
);
131 if (muxer_upstream_msg_iter
->msgs
) {
132 empty_message_queue(muxer_upstream_msg_iter
);
133 g_queue_free(muxer_upstream_msg_iter
->msgs
);
136 g_free(muxer_upstream_msg_iter
);
140 int muxer_msg_iter_add_upstream_msg_iter(struct muxer_msg_iter
*muxer_msg_iter
,
141 bt_self_component_port_input_message_iterator
*self_msg_iter
)
144 struct muxer_upstream_msg_iter
*muxer_upstream_msg_iter
=
145 g_new0(struct muxer_upstream_msg_iter
, 1);
147 if (!muxer_upstream_msg_iter
) {
148 BT_LOGE_STR("Failed to allocate one muxer's upstream message iterator wrapper.");
152 muxer_upstream_msg_iter
->msg_iter
= self_msg_iter
;
153 bt_self_component_port_input_message_iterator_get_ref(muxer_upstream_msg_iter
->msg_iter
);
154 muxer_upstream_msg_iter
->msgs
= g_queue_new();
155 if (!muxer_upstream_msg_iter
->msgs
) {
156 BT_LOGE_STR("Failed to allocate a GQueue.");
160 g_ptr_array_add(muxer_msg_iter
->active_muxer_upstream_msg_iters
,
161 muxer_upstream_msg_iter
);
162 BT_LOGD("Added muxer's upstream message iterator wrapper: "
163 "addr=%p, muxer-msg-iter-addr=%p, msg-iter-addr=%p",
164 muxer_upstream_msg_iter
, muxer_msg_iter
,
170 g_free(muxer_upstream_msg_iter
);
178 bt_self_component_status
add_available_input_port(
179 bt_self_component_filter
*self_comp
)
181 struct muxer_comp
*muxer_comp
= bt_self_component_get_data(
182 bt_self_component_filter_as_self_component(self_comp
));
183 bt_self_component_status status
= BT_SELF_COMPONENT_STATUS_OK
;
184 GString
*port_name
= NULL
;
186 BT_ASSERT(muxer_comp
);
187 port_name
= g_string_new("in");
189 BT_LOGE_STR("Failed to allocate a GString.");
190 status
= BT_SELF_COMPONENT_STATUS_NOMEM
;
194 g_string_append_printf(port_name
, "%u", muxer_comp
->next_port_num
);
195 status
= bt_self_component_filter_add_input_port(
196 self_comp
, port_name
->str
, NULL
, NULL
);
197 if (status
!= BT_SELF_COMPONENT_STATUS_OK
) {
198 BT_LOGE("Cannot add input port to muxer component: "
199 "port-name=\"%s\", comp-addr=%p, status=%s",
200 port_name
->str
, self_comp
,
201 bt_self_component_status_string(status
));
205 muxer_comp
->available_input_ports
++;
206 muxer_comp
->next_port_num
++;
207 BT_LOGI("Added one input port to muxer component: "
208 "port-name=\"%s\", comp-addr=%p",
209 port_name
->str
, self_comp
);
213 g_string_free(port_name
, TRUE
);
220 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
)
238 bt_value
*get_default_params(void)
243 params
= bt_value_map_create();
245 BT_LOGE_STR("Cannot create a map value object.");
249 ret
= bt_value_map_insert_bool_entry(params
,
250 ASSUME_ABSOLUTE_CLOCK_CLASSES_PARAM_NAME
, false);
252 BT_LOGE_STR("Cannot add boolean value to map value object.");
259 BT_VALUE_PUT_REF_AND_RESET(params
);
266 int configure_muxer_comp(struct muxer_comp
*muxer_comp
,
267 const bt_value
*params
)
269 bt_value
*default_params
= NULL
;
270 bt_value
*real_params
= NULL
;
271 const bt_value
*assume_absolute_clock_classes
= NULL
;
275 default_params
= get_default_params();
276 if (!default_params
) {
277 BT_LOGE("Cannot get default parameters: "
278 "muxer-comp-addr=%p", muxer_comp
);
282 ret
= bt_value_map_extend(default_params
, params
, &real_params
);
284 BT_LOGE("Cannot extend default parameters map value: "
285 "muxer-comp-addr=%p, def-params-addr=%p, "
286 "params-addr=%p", muxer_comp
, default_params
,
291 assume_absolute_clock_classes
= bt_value_map_borrow_entry_value(real_params
,
292 ASSUME_ABSOLUTE_CLOCK_CLASSES_PARAM_NAME
);
293 if (assume_absolute_clock_classes
&&
294 !bt_value_is_bool(assume_absolute_clock_classes
)) {
295 BT_LOGE("Expecting a boolean value for the `%s` parameter: "
296 "muxer-comp-addr=%p, value-type=%s",
297 ASSUME_ABSOLUTE_CLOCK_CLASSES_PARAM_NAME
, muxer_comp
,
298 bt_common_value_type_string(
299 bt_value_get_type(assume_absolute_clock_classes
)));
303 bool_val
= bt_value_bool_get(assume_absolute_clock_classes
);
304 muxer_comp
->assume_absolute_clock_classes
= (bool) bool_val
;
305 BT_LOGI("Configured muxer component: muxer-comp-addr=%p, "
306 "assume-absolute-clock-classes=%d",
307 muxer_comp
, muxer_comp
->assume_absolute_clock_classes
);
314 bt_value_put_ref(default_params
);
315 bt_value_put_ref(real_params
);
320 bt_self_component_status
muxer_init(
321 bt_self_component_filter
*self_comp
,
322 const bt_value
*params
, void *init_data
)
325 bt_self_component_status status
= BT_SELF_COMPONENT_STATUS_OK
;
326 struct muxer_comp
*muxer_comp
= g_new0(struct muxer_comp
, 1);
328 BT_LOGI("Initializing muxer component: "
329 "comp-addr=%p, params-addr=%p", self_comp
, params
);
332 BT_LOGE_STR("Failed to allocate one muxer component.");
336 ret
= configure_muxer_comp(muxer_comp
, params
);
338 BT_LOGE("Cannot configure muxer component: "
339 "muxer-comp-addr=%p, params-addr=%p",
344 muxer_comp
->self_comp
= self_comp
;
345 bt_self_component_set_data(
346 bt_self_component_filter_as_self_component(self_comp
),
348 status
= add_available_input_port(self_comp
);
349 if (status
!= BT_SELF_COMPONENT_STATUS_OK
) {
350 BT_LOGE("Cannot ensure that at least one muxer component's input port is available: "
351 "muxer-comp-addr=%p, status=%s",
353 bt_self_component_status_string(status
));
357 status
= create_output_port(self_comp
);
359 BT_LOGE("Cannot create muxer component's output port: "
360 "muxer-comp-addr=%p, status=%s",
362 bt_self_component_status_string(status
));
366 BT_LOGI("Initialized muxer component: "
367 "comp-addr=%p, params-addr=%p, muxer-comp-addr=%p",
368 self_comp
, params
, muxer_comp
);
373 destroy_muxer_comp(muxer_comp
);
374 bt_self_component_set_data(
375 bt_self_component_filter_as_self_component(self_comp
),
378 if (status
== BT_SELF_COMPONENT_STATUS_OK
) {
379 status
= BT_SELF_COMPONENT_STATUS_ERROR
;
387 void muxer_finalize(bt_self_component_filter
*self_comp
)
389 struct muxer_comp
*muxer_comp
= bt_self_component_get_data(
390 bt_self_component_filter_as_self_component(self_comp
));
392 BT_LOGI("Finalizing muxer component: comp-addr=%p",
394 destroy_muxer_comp(muxer_comp
);
398 bt_self_component_port_input_message_iterator
*
399 create_msg_iter_on_input_port(bt_self_component_port_input
*self_port
)
401 const bt_port
*port
= bt_self_component_port_as_port(
402 bt_self_component_port_input_as_self_component_port(
404 bt_self_component_port_input_message_iterator
*msg_iter
=
408 BT_ASSERT(bt_port_is_connected(port
));
410 // TODO: Advance the iterator to >= the time of the latest
411 // returned message by the muxer message
412 // iterator which creates it.
413 msg_iter
= bt_self_component_port_input_message_iterator_create(
416 BT_LOGE("Cannot create upstream message iterator on input port: "
417 "port-addr=%p, port-name=\"%s\"",
418 port
, bt_port_get_name(port
));
422 BT_LOGI("Created upstream message iterator on input port: "
423 "port-addr=%p, port-name=\"%s\", msg-iter-addr=%p",
424 port
, bt_port_get_name(port
), msg_iter
);
431 bt_self_message_iterator_status
muxer_upstream_msg_iter_next(
432 struct muxer_upstream_msg_iter
*muxer_upstream_msg_iter
,
435 bt_self_message_iterator_status status
;
436 bt_message_iterator_status input_port_iter_status
;
437 bt_message_array_const msgs
;
441 BT_LOGD("Calling upstream message iterator's \"next\" method: "
442 "muxer-upstream-msg-iter-wrap-addr=%p, msg-iter-addr=%p",
443 muxer_upstream_msg_iter
,
444 muxer_upstream_msg_iter
->msg_iter
);
445 input_port_iter_status
= bt_self_component_port_input_message_iterator_next(
446 muxer_upstream_msg_iter
->msg_iter
, &msgs
, &count
);
447 BT_LOGD("Upstream message iterator's \"next\" method returned: "
448 "status=%s", bt_message_iterator_status_string(input_port_iter_status
));
450 switch (input_port_iter_status
) {
451 case BT_MESSAGE_ITERATOR_STATUS_OK
:
453 * Message iterator's current message is
454 * valid: it must be considered for muxing operations.
456 BT_LOGD_STR("Validated upstream message iterator wrapper.");
457 BT_ASSERT(count
> 0);
459 /* Move messages to our queue */
460 for (i
= 0; i
< count
; i
++) {
462 * Push to tail in order; other side
463 * (muxer_msg_iter_do_next_one()) consumes
464 * from the head first.
466 g_queue_push_tail(muxer_upstream_msg_iter
->msgs
,
469 status
= BT_SELF_MESSAGE_ITERATOR_STATUS_OK
;
471 case BT_MESSAGE_ITERATOR_STATUS_AGAIN
:
473 * Message iterator's current message is not
474 * valid anymore. Return
475 * BT_MESSAGE_ITERATOR_STATUS_AGAIN immediately.
477 status
= BT_SELF_MESSAGE_ITERATOR_STATUS_AGAIN
;
479 case BT_MESSAGE_ITERATOR_STATUS_END
: /* Fall-through. */
481 * Message iterator reached the end: release it. It
482 * won't be considered again to find the youngest
486 status
= BT_SELF_MESSAGE_ITERATOR_STATUS_OK
;
489 /* Error or unsupported status code */
490 BT_LOGE("Error or unsupported status code: "
491 "status-code=%d", input_port_iter_status
);
492 status
= BT_SELF_MESSAGE_ITERATOR_STATUS_ERROR
;
500 int get_msg_ts_ns(struct muxer_comp
*muxer_comp
,
501 struct muxer_msg_iter
*muxer_msg_iter
,
502 const bt_message
*msg
, int64_t last_returned_ts_ns
,
505 const bt_clock_snapshot
*clock_snapshot
= NULL
;
507 bt_message_stream_activity_clock_snapshot_state sa_cs_state
;
508 const bt_stream_class
*stream_class
= NULL
;
509 bt_message_type msg_type
;
513 BT_LOGD("Getting message's timestamp: "
514 "muxer-msg-iter-addr=%p, msg-addr=%p, "
515 "last-returned-ts=%" PRId64
,
516 muxer_msg_iter
, msg
, last_returned_ts_ns
);
518 if (G_UNLIKELY(muxer_msg_iter
->clock_class_expectation
==
519 MUXER_MSG_ITER_CLOCK_CLASS_EXPECTATION_NONE
)) {
520 *ts_ns
= last_returned_ts_ns
;
524 msg_type
= bt_message_get_type(msg
);
526 if (G_UNLIKELY(msg_type
== BT_MESSAGE_TYPE_PACKET_BEGINNING
)) {
527 stream_class
= bt_stream_borrow_class_const(
528 bt_packet_borrow_stream_const(
529 bt_message_packet_beginning_borrow_packet_const(
531 } else if (G_UNLIKELY(msg_type
== BT_MESSAGE_TYPE_PACKET_END
)) {
532 stream_class
= bt_stream_borrow_class_const(
533 bt_packet_borrow_stream_const(
534 bt_message_packet_end_borrow_packet_const(
536 } else if (G_UNLIKELY(msg_type
== BT_MESSAGE_TYPE_DISCARDED_EVENTS
)) {
537 stream_class
= bt_stream_borrow_class_const(
538 bt_message_discarded_events_borrow_stream_const(msg
));
539 } else if (G_UNLIKELY(msg_type
== BT_MESSAGE_TYPE_DISCARDED_PACKETS
)) {
540 stream_class
= bt_stream_borrow_class_const(
541 bt_message_discarded_packets_borrow_stream_const(msg
));
545 case BT_MESSAGE_TYPE_EVENT
:
546 BT_ASSERT(bt_message_event_borrow_stream_class_default_clock_class_const(
548 clock_snapshot
= bt_message_event_borrow_default_clock_snapshot_const(
551 case BT_MESSAGE_TYPE_PACKET_BEGINNING
:
552 if (bt_stream_class_packets_have_beginning_default_clock_snapshot(
554 clock_snapshot
= bt_message_packet_beginning_borrow_default_clock_snapshot_const(
557 goto no_clock_snapshot
;
561 case BT_MESSAGE_TYPE_PACKET_END
:
562 if (bt_stream_class_packets_have_end_default_clock_snapshot(
564 clock_snapshot
= bt_message_packet_end_borrow_default_clock_snapshot_const(
567 goto no_clock_snapshot
;
571 case BT_MESSAGE_TYPE_DISCARDED_EVENTS
:
572 if (bt_stream_class_discarded_events_have_default_clock_snapshots(
574 clock_snapshot
= bt_message_discarded_events_borrow_beginning_default_clock_snapshot_const(
577 goto no_clock_snapshot
;
581 case BT_MESSAGE_TYPE_DISCARDED_PACKETS
:
582 if (bt_stream_class_discarded_packets_have_default_clock_snapshots(
584 clock_snapshot
= bt_message_discarded_packets_borrow_beginning_default_clock_snapshot_const(
587 goto no_clock_snapshot
;
591 case BT_MESSAGE_TYPE_STREAM_ACTIVITY_BEGINNING
:
592 BT_ASSERT(bt_message_stream_activity_beginning_borrow_stream_class_default_clock_class_const(
594 sa_cs_state
= bt_message_stream_activity_beginning_borrow_default_clock_snapshot_const(
595 msg
, &clock_snapshot
);
596 if (sa_cs_state
!= BT_MESSAGE_STREAM_ACTIVITY_CLOCK_SNAPSHOT_STATE_KNOWN
) {
597 goto no_clock_snapshot
;
601 case BT_MESSAGE_TYPE_STREAM_ACTIVITY_END
:
602 BT_ASSERT(bt_message_stream_activity_end_borrow_stream_class_default_clock_class_const(
604 sa_cs_state
= bt_message_stream_activity_end_borrow_default_clock_snapshot_const(
605 msg
, &clock_snapshot
);
606 if (sa_cs_state
!= BT_MESSAGE_STREAM_ACTIVITY_CLOCK_SNAPSHOT_STATE_KNOWN
) {
607 goto no_clock_snapshot
;
611 case BT_MESSAGE_TYPE_MESSAGE_ITERATOR_INACTIVITY
:
612 clock_snapshot
= bt_message_message_iterator_inactivity_borrow_default_clock_snapshot_const(
616 /* All the other messages have a higher priority */
617 BT_LOGD_STR("Message has no timestamp: using the last returned timestamp.");
618 *ts_ns
= last_returned_ts_ns
;
622 ret
= bt_clock_snapshot_get_ns_from_origin(clock_snapshot
, ts_ns
);
624 BT_LOGE("Cannot get nanoseconds from Epoch of clock snapshot: "
625 "clock-snapshot-addr=%p", clock_snapshot
);
632 BT_LOGD_STR("Message's default clock snapshot is missing: "
633 "using the last returned timestamp.");
634 *ts_ns
= last_returned_ts_ns
;
642 BT_LOGD("Found message's timestamp: "
643 "muxer-msg-iter-addr=%p, msg-addr=%p, "
644 "last-returned-ts=%" PRId64
", ts=%" PRId64
,
645 muxer_msg_iter
, msg
, last_returned_ts_ns
,
653 int validate_clock_class(struct muxer_msg_iter
*muxer_msg_iter
,
654 struct muxer_comp
*muxer_comp
,
655 const bt_clock_class
*clock_class
)
658 const unsigned char *cc_uuid
;
661 BT_ASSERT(clock_class
);
662 cc_uuid
= bt_clock_class_get_uuid(clock_class
);
663 cc_name
= bt_clock_class_get_name(clock_class
);
665 if (muxer_msg_iter
->clock_class_expectation
==
666 MUXER_MSG_ITER_CLOCK_CLASS_EXPECTATION_ANY
) {
668 * This is the first clock class that this muxer
669 * message iterator encounters. Its properties
670 * determine what to expect for the whole lifetime of
671 * the iterator without a true
672 * `assume-absolute-clock-classes` parameter.
674 if (bt_clock_class_origin_is_unix_epoch(clock_class
)) {
675 /* Expect absolute clock classes */
676 muxer_msg_iter
->clock_class_expectation
=
677 MUXER_MSG_ITER_CLOCK_CLASS_EXPECTATION_ABSOLUTE
;
681 * Expect non-absolute clock classes
682 * with a specific UUID.
684 muxer_msg_iter
->clock_class_expectation
=
685 MUXER_MSG_ITER_CLOCK_CLASS_EXPECTATION_NOT_ABS_SPEC_UUID
;
686 memcpy(muxer_msg_iter
->expected_clock_class_uuid
,
687 cc_uuid
, BABELTRACE_UUID_LEN
);
690 * Expect non-absolute clock classes
693 muxer_msg_iter
->clock_class_expectation
=
694 MUXER_MSG_ITER_CLOCK_CLASS_EXPECTATION_NOT_ABS_NO_UUID
;
699 if (!muxer_comp
->assume_absolute_clock_classes
) {
700 switch (muxer_msg_iter
->clock_class_expectation
) {
701 case MUXER_MSG_ITER_CLOCK_CLASS_EXPECTATION_ABSOLUTE
:
702 if (!bt_clock_class_origin_is_unix_epoch(clock_class
)) {
703 BT_LOGE("Expecting an absolute clock class, "
704 "but got a non-absolute one: "
705 "clock-class-addr=%p, clock-class-name=\"%s\"",
706 clock_class
, cc_name
);
710 case MUXER_MSG_ITER_CLOCK_CLASS_EXPECTATION_NOT_ABS_NO_UUID
:
711 if (bt_clock_class_origin_is_unix_epoch(clock_class
)) {
712 BT_LOGE("Expecting a non-absolute clock class with no UUID, "
713 "but got an absolute one: "
714 "clock-class-addr=%p, clock-class-name=\"%s\"",
715 clock_class
, cc_name
);
720 BT_LOGE("Expecting a non-absolute clock class with no UUID, "
721 "but got one with a UUID: "
722 "clock-class-addr=%p, clock-class-name=\"%s\", "
723 "uuid=\"%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x\"",
724 clock_class
, cc_name
,
725 (unsigned int) cc_uuid
[0],
726 (unsigned int) cc_uuid
[1],
727 (unsigned int) cc_uuid
[2],
728 (unsigned int) cc_uuid
[3],
729 (unsigned int) cc_uuid
[4],
730 (unsigned int) cc_uuid
[5],
731 (unsigned int) cc_uuid
[6],
732 (unsigned int) cc_uuid
[7],
733 (unsigned int) cc_uuid
[8],
734 (unsigned int) cc_uuid
[9],
735 (unsigned int) cc_uuid
[10],
736 (unsigned int) cc_uuid
[11],
737 (unsigned int) cc_uuid
[12],
738 (unsigned int) cc_uuid
[13],
739 (unsigned int) cc_uuid
[14],
740 (unsigned int) cc_uuid
[15]);
744 case MUXER_MSG_ITER_CLOCK_CLASS_EXPECTATION_NOT_ABS_SPEC_UUID
:
745 if (bt_clock_class_origin_is_unix_epoch(clock_class
)) {
746 BT_LOGE("Expecting a non-absolute clock class with a specific UUID, "
747 "but got an absolute one: "
748 "clock-class-addr=%p, clock-class-name=\"%s\"",
749 clock_class
, cc_name
);
754 BT_LOGE("Expecting a non-absolute clock class with a specific UUID, "
755 "but got one with no UUID: "
756 "clock-class-addr=%p, clock-class-name=\"%s\"",
757 clock_class
, cc_name
);
761 if (memcmp(muxer_msg_iter
->expected_clock_class_uuid
,
762 cc_uuid
, BABELTRACE_UUID_LEN
) != 0) {
763 BT_LOGE("Expecting a non-absolute clock class with a specific UUID, "
764 "but got one with different UUID: "
765 "clock-class-addr=%p, clock-class-name=\"%s\", "
766 "expected-uuid=\"%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x\", "
767 "uuid=\"%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x\"",
768 clock_class
, cc_name
,
769 (unsigned int) muxer_msg_iter
->expected_clock_class_uuid
[0],
770 (unsigned int) muxer_msg_iter
->expected_clock_class_uuid
[1],
771 (unsigned int) muxer_msg_iter
->expected_clock_class_uuid
[2],
772 (unsigned int) muxer_msg_iter
->expected_clock_class_uuid
[3],
773 (unsigned int) muxer_msg_iter
->expected_clock_class_uuid
[4],
774 (unsigned int) muxer_msg_iter
->expected_clock_class_uuid
[5],
775 (unsigned int) muxer_msg_iter
->expected_clock_class_uuid
[6],
776 (unsigned int) muxer_msg_iter
->expected_clock_class_uuid
[7],
777 (unsigned int) muxer_msg_iter
->expected_clock_class_uuid
[8],
778 (unsigned int) muxer_msg_iter
->expected_clock_class_uuid
[9],
779 (unsigned int) muxer_msg_iter
->expected_clock_class_uuid
[10],
780 (unsigned int) muxer_msg_iter
->expected_clock_class_uuid
[11],
781 (unsigned int) muxer_msg_iter
->expected_clock_class_uuid
[12],
782 (unsigned int) muxer_msg_iter
->expected_clock_class_uuid
[13],
783 (unsigned int) muxer_msg_iter
->expected_clock_class_uuid
[14],
784 (unsigned int) muxer_msg_iter
->expected_clock_class_uuid
[15],
785 (unsigned int) cc_uuid
[0],
786 (unsigned int) cc_uuid
[1],
787 (unsigned int) cc_uuid
[2],
788 (unsigned int) cc_uuid
[3],
789 (unsigned int) cc_uuid
[4],
790 (unsigned int) cc_uuid
[5],
791 (unsigned int) cc_uuid
[6],
792 (unsigned int) cc_uuid
[7],
793 (unsigned int) cc_uuid
[8],
794 (unsigned int) cc_uuid
[9],
795 (unsigned int) cc_uuid
[10],
796 (unsigned int) cc_uuid
[11],
797 (unsigned int) cc_uuid
[12],
798 (unsigned int) cc_uuid
[13],
799 (unsigned int) cc_uuid
[14],
800 (unsigned int) cc_uuid
[15]);
804 case MUXER_MSG_ITER_CLOCK_CLASS_EXPECTATION_NONE
:
805 BT_LOGE("Expecting no clock class, but got one: "
806 "clock-class-addr=%p, clock-class-name=\"%s\"",
807 clock_class
, cc_name
);
811 BT_LOGF("Unexpected clock class expectation: "
812 "expectation-code=%d",
813 muxer_msg_iter
->clock_class_expectation
);
828 int validate_new_stream_clock_class(struct muxer_msg_iter
*muxer_msg_iter
,
829 struct muxer_comp
*muxer_comp
, const bt_stream
*stream
)
832 const bt_stream_class
*stream_class
=
833 bt_stream_borrow_class_const(stream
);
834 const bt_clock_class
*clock_class
=
835 bt_stream_class_borrow_default_clock_class_const(stream_class
);
838 if (muxer_msg_iter
->clock_class_expectation
==
839 MUXER_MSG_ITER_CLOCK_CLASS_EXPECTATION_ANY
) {
840 /* Expect no clock class */
841 muxer_msg_iter
->clock_class_expectation
=
842 MUXER_MSG_ITER_CLOCK_CLASS_EXPECTATION_NONE
;
844 BT_LOGE("Expecting stream class with a default clock class: "
845 "stream-class-addr=%p, stream-class-name=\"%s\", "
846 "stream-class-id=%" PRIu64
,
847 stream_class
, bt_stream_class_get_name(stream_class
),
848 bt_stream_class_get_id(stream_class
));
855 ret
= validate_clock_class(muxer_msg_iter
, muxer_comp
, clock_class
);
862 * This function finds the youngest available message amongst the
863 * non-ended upstream message iterators and returns the upstream
864 * message iterator which has it, or
865 * BT_MESSAGE_ITERATOR_STATUS_END if there's no available
868 * This function does NOT:
870 * * Update any upstream message iterator.
871 * * Check the upstream message iterators to retry.
873 * On sucess, this function sets *muxer_upstream_msg_iter to the
874 * upstream message iterator of which the current message is
875 * the youngest, and sets *ts_ns to its time.
878 bt_self_message_iterator_status
879 muxer_msg_iter_youngest_upstream_msg_iter(
880 struct muxer_comp
*muxer_comp
,
881 struct muxer_msg_iter
*muxer_msg_iter
,
882 struct muxer_upstream_msg_iter
**muxer_upstream_msg_iter
,
887 int64_t youngest_ts_ns
= INT64_MAX
;
888 bt_self_message_iterator_status status
=
889 BT_SELF_MESSAGE_ITERATOR_STATUS_OK
;
891 BT_ASSERT(muxer_comp
);
892 BT_ASSERT(muxer_msg_iter
);
893 BT_ASSERT(muxer_upstream_msg_iter
);
894 *muxer_upstream_msg_iter
= NULL
;
896 for (i
= 0; i
< muxer_msg_iter
->active_muxer_upstream_msg_iters
->len
;
898 const bt_message
*msg
;
899 struct muxer_upstream_msg_iter
*cur_muxer_upstream_msg_iter
=
901 muxer_msg_iter
->active_muxer_upstream_msg_iters
,
905 if (!cur_muxer_upstream_msg_iter
->msg_iter
) {
906 /* This upstream message iterator is ended */
907 BT_LOGV("Skipping ended upstream message iterator: "
908 "muxer-upstream-msg-iter-wrap-addr=%p",
909 cur_muxer_upstream_msg_iter
);
913 BT_ASSERT(cur_muxer_upstream_msg_iter
->msgs
->length
> 0);
914 msg
= g_queue_peek_head(cur_muxer_upstream_msg_iter
->msgs
);
917 if (G_UNLIKELY(bt_message_get_type(msg
) ==
918 BT_MESSAGE_TYPE_STREAM_BEGINNING
)) {
919 ret
= validate_new_stream_clock_class(
920 muxer_msg_iter
, muxer_comp
,
921 bt_message_stream_beginning_borrow_stream_const(
925 * validate_new_stream_clock_class() logs
928 status
= BT_SELF_MESSAGE_ITERATOR_STATUS_ERROR
;
931 } else if (G_UNLIKELY(bt_message_get_type(msg
) ==
932 BT_MESSAGE_TYPE_MESSAGE_ITERATOR_INACTIVITY
)) {
933 const bt_clock_snapshot
*cs
;
935 cs
= bt_message_message_iterator_inactivity_borrow_default_clock_snapshot_const(
937 ret
= validate_clock_class(muxer_msg_iter
, muxer_comp
,
938 bt_clock_snapshot_borrow_clock_class_const(cs
));
940 /* validate_clock_class() logs errors */
941 status
= BT_SELF_MESSAGE_ITERATOR_STATUS_ERROR
;
946 ret
= get_msg_ts_ns(muxer_comp
, muxer_msg_iter
, msg
,
947 muxer_msg_iter
->last_returned_ts_ns
, &msg_ts_ns
);
949 /* get_msg_ts_ns() logs errors */
950 *muxer_upstream_msg_iter
= NULL
;
951 status
= BT_SELF_MESSAGE_ITERATOR_STATUS_ERROR
;
955 if (msg_ts_ns
<= youngest_ts_ns
) {
956 *muxer_upstream_msg_iter
=
957 cur_muxer_upstream_msg_iter
;
958 youngest_ts_ns
= msg_ts_ns
;
959 *ts_ns
= youngest_ts_ns
;
963 if (!*muxer_upstream_msg_iter
) {
964 status
= BT_SELF_MESSAGE_ITERATOR_STATUS_END
;
973 bt_self_message_iterator_status
validate_muxer_upstream_msg_iter(
974 struct muxer_upstream_msg_iter
*muxer_upstream_msg_iter
,
977 bt_self_message_iterator_status status
=
978 BT_SELF_MESSAGE_ITERATOR_STATUS_OK
;
980 BT_LOGD("Validating muxer's upstream message iterator wrapper: "
981 "muxer-upstream-msg-iter-wrap-addr=%p",
982 muxer_upstream_msg_iter
);
984 if (muxer_upstream_msg_iter
->msgs
->length
> 0 ||
985 !muxer_upstream_msg_iter
->msg_iter
) {
986 BT_LOGD("Already valid or not considered: "
987 "queue-len=%u, upstream-msg-iter-addr=%p",
988 muxer_upstream_msg_iter
->msgs
->length
,
989 muxer_upstream_msg_iter
->msg_iter
);
993 /* muxer_upstream_msg_iter_next() logs details/errors */
994 status
= muxer_upstream_msg_iter_next(muxer_upstream_msg_iter
,
1002 bt_self_message_iterator_status
validate_muxer_upstream_msg_iters(
1003 struct muxer_msg_iter
*muxer_msg_iter
)
1005 bt_self_message_iterator_status status
=
1006 BT_SELF_MESSAGE_ITERATOR_STATUS_OK
;
1009 BT_LOGD("Validating muxer's upstream message iterator wrappers: "
1010 "muxer-msg-iter-addr=%p", muxer_msg_iter
);
1012 for (i
= 0; i
< muxer_msg_iter
->active_muxer_upstream_msg_iters
->len
;
1014 bool is_ended
= false;
1015 struct muxer_upstream_msg_iter
*muxer_upstream_msg_iter
=
1017 muxer_msg_iter
->active_muxer_upstream_msg_iters
,
1020 status
= validate_muxer_upstream_msg_iter(
1021 muxer_upstream_msg_iter
, &is_ended
);
1022 if (status
!= BT_SELF_MESSAGE_ITERATOR_STATUS_OK
) {
1024 BT_LOGE("Cannot validate muxer's upstream message iterator wrapper: "
1025 "muxer-msg-iter-addr=%p, "
1026 "muxer-upstream-msg-iter-wrap-addr=%p",
1028 muxer_upstream_msg_iter
);
1030 BT_LOGD("Cannot validate muxer's upstream message iterator wrapper: "
1031 "muxer-msg-iter-addr=%p, "
1032 "muxer-upstream-msg-iter-wrap-addr=%p",
1034 muxer_upstream_msg_iter
);
1041 * Move this muxer upstream message iterator to the
1042 * array of ended iterators if it's ended.
1044 if (G_UNLIKELY(is_ended
)) {
1045 BT_LOGD("Muxer's upstream message iterator wrapper: ended or canceled: "
1046 "muxer-msg-iter-addr=%p, "
1047 "muxer-upstream-msg-iter-wrap-addr=%p",
1048 muxer_msg_iter
, muxer_upstream_msg_iter
);
1050 muxer_msg_iter
->ended_muxer_upstream_msg_iters
,
1051 muxer_upstream_msg_iter
);
1052 muxer_msg_iter
->active_muxer_upstream_msg_iters
->pdata
[i
] = NULL
;
1055 * Use g_ptr_array_remove_fast() because the
1056 * order of those elements is not important.
1058 g_ptr_array_remove_index_fast(
1059 muxer_msg_iter
->active_muxer_upstream_msg_iters
,
1070 bt_self_message_iterator_status
muxer_msg_iter_do_next_one(
1071 struct muxer_comp
*muxer_comp
,
1072 struct muxer_msg_iter
*muxer_msg_iter
,
1073 const bt_message
**msg
)
1075 bt_self_message_iterator_status status
;
1076 struct muxer_upstream_msg_iter
*muxer_upstream_msg_iter
= NULL
;
1077 int64_t next_return_ts
;
1079 status
= validate_muxer_upstream_msg_iters(muxer_msg_iter
);
1080 if (status
!= BT_SELF_MESSAGE_ITERATOR_STATUS_OK
) {
1081 /* validate_muxer_upstream_msg_iters() logs details */
1086 * At this point we know that all the existing upstream
1087 * message iterators are valid. We can find the one,
1088 * amongst those, of which the current message is the
1091 status
= muxer_msg_iter_youngest_upstream_msg_iter(muxer_comp
,
1092 muxer_msg_iter
, &muxer_upstream_msg_iter
,
1094 if (status
< 0 || status
== BT_SELF_MESSAGE_ITERATOR_STATUS_END
) {
1096 BT_LOGE("Cannot find the youngest upstream message iterator wrapper: "
1098 bt_common_self_message_iterator_status_string(status
));
1100 BT_LOGD("Cannot find the youngest upstream message iterator wrapper: "
1102 bt_common_self_message_iterator_status_string(status
));
1108 if (next_return_ts
< muxer_msg_iter
->last_returned_ts_ns
) {
1109 BT_LOGE("Youngest upstream message iterator wrapper's timestamp is less than muxer's message iterator's last returned timestamp: "
1110 "muxer-msg-iter-addr=%p, ts=%" PRId64
", "
1111 "last-returned-ts=%" PRId64
,
1112 muxer_msg_iter
, next_return_ts
,
1113 muxer_msg_iter
->last_returned_ts_ns
);
1114 status
= BT_SELF_MESSAGE_ITERATOR_STATUS_ERROR
;
1118 BT_LOGD("Found youngest upstream message iterator wrapper: "
1119 "muxer-msg-iter-addr=%p, "
1120 "muxer-upstream-msg-iter-wrap-addr=%p, "
1122 muxer_msg_iter
, muxer_upstream_msg_iter
, next_return_ts
);
1123 BT_ASSERT(status
== BT_SELF_MESSAGE_ITERATOR_STATUS_OK
);
1124 BT_ASSERT(muxer_upstream_msg_iter
);
1127 * Consume from the queue's head: other side
1128 * (muxer_upstream_msg_iter_next()) writes to the tail.
1130 *msg
= g_queue_pop_head(muxer_upstream_msg_iter
->msgs
);
1132 muxer_msg_iter
->last_returned_ts_ns
= next_return_ts
;
1139 bt_self_message_iterator_status
muxer_msg_iter_do_next(
1140 struct muxer_comp
*muxer_comp
,
1141 struct muxer_msg_iter
*muxer_msg_iter
,
1142 bt_message_array_const msgs
, uint64_t capacity
,
1145 bt_self_message_iterator_status status
=
1146 BT_SELF_MESSAGE_ITERATOR_STATUS_OK
;
1149 while (i
< capacity
&& status
== BT_SELF_MESSAGE_ITERATOR_STATUS_OK
) {
1150 status
= muxer_msg_iter_do_next_one(muxer_comp
,
1151 muxer_msg_iter
, &msgs
[i
]);
1152 if (status
== BT_SELF_MESSAGE_ITERATOR_STATUS_OK
) {
1159 * Even if muxer_msg_iter_do_next_one() returned
1160 * something else than
1161 * BT_MESSAGE_ITERATOR_STATUS_OK, we accumulated
1162 * message objects in the output message
1163 * array, so we need to return
1164 * BT_MESSAGE_ITERATOR_STATUS_OK so that they are
1165 * transfered to downstream. This other status occurs
1166 * again the next time muxer_msg_iter_do_next() is
1167 * called, possibly without any accumulated
1168 * message, in which case we'll return it.
1171 status
= BT_SELF_MESSAGE_ITERATOR_STATUS_OK
;
1178 void destroy_muxer_msg_iter(struct muxer_msg_iter
*muxer_msg_iter
)
1180 if (!muxer_msg_iter
) {
1184 BT_LOGD("Destroying muxer component's message iterator: "
1185 "muxer-msg-iter-addr=%p", muxer_msg_iter
);
1187 if (muxer_msg_iter
->active_muxer_upstream_msg_iters
) {
1188 BT_LOGD_STR("Destroying muxer's active upstream message iterator wrappers.");
1190 muxer_msg_iter
->active_muxer_upstream_msg_iters
, TRUE
);
1193 if (muxer_msg_iter
->ended_muxer_upstream_msg_iters
) {
1194 BT_LOGD_STR("Destroying muxer's ended upstream message iterator wrappers.");
1196 muxer_msg_iter
->ended_muxer_upstream_msg_iters
, TRUE
);
1199 g_free(muxer_msg_iter
);
1203 int muxer_msg_iter_init_upstream_iterators(struct muxer_comp
*muxer_comp
,
1204 struct muxer_msg_iter
*muxer_msg_iter
)
1210 count
= bt_component_filter_get_input_port_count(
1211 bt_self_component_filter_as_component_filter(
1212 muxer_comp
->self_comp
));
1214 BT_LOGD("No input port to initialize for muxer component's message iterator: "
1215 "muxer-comp-addr=%p, muxer-msg-iter-addr=%p",
1216 muxer_comp
, muxer_msg_iter
);
1220 for (i
= 0; i
< count
; i
++) {
1221 bt_self_component_port_input_message_iterator
*upstream_msg_iter
;
1222 bt_self_component_port_input
*self_port
=
1223 bt_self_component_filter_borrow_input_port_by_index(
1224 muxer_comp
->self_comp
, i
);
1225 const bt_port
*port
;
1227 BT_ASSERT(self_port
);
1228 port
= bt_self_component_port_as_port(
1229 bt_self_component_port_input_as_self_component_port(
1233 if (!bt_port_is_connected(port
)) {
1234 /* Skip non-connected port */
1238 upstream_msg_iter
= create_msg_iter_on_input_port(self_port
);
1239 if (!upstream_msg_iter
) {
1240 /* create_msg_iter_on_input_port() logs errors */
1241 BT_ASSERT(!upstream_msg_iter
);
1246 ret
= muxer_msg_iter_add_upstream_msg_iter(muxer_msg_iter
,
1248 bt_self_component_port_input_message_iterator_put_ref(
1251 /* muxer_msg_iter_add_upstream_msg_iter() logs errors */
1261 bt_self_message_iterator_status
muxer_msg_iter_init(
1262 bt_self_message_iterator
*self_msg_iter
,
1263 bt_self_component_filter
*self_comp
,
1264 bt_self_component_port_output
*port
)
1266 struct muxer_comp
*muxer_comp
= NULL
;
1267 struct muxer_msg_iter
*muxer_msg_iter
= NULL
;
1268 bt_self_message_iterator_status status
=
1269 BT_SELF_MESSAGE_ITERATOR_STATUS_OK
;
1272 muxer_comp
= bt_self_component_get_data(
1273 bt_self_component_filter_as_self_component(self_comp
));
1274 BT_ASSERT(muxer_comp
);
1275 BT_LOGD("Initializing muxer component's message iterator: "
1276 "comp-addr=%p, muxer-comp-addr=%p, msg-iter-addr=%p",
1277 self_comp
, muxer_comp
, self_msg_iter
);
1279 if (muxer_comp
->initializing_muxer_msg_iter
) {
1281 * Weird, unhandled situation detected: downstream
1282 * creates a muxer message iterator while creating
1283 * another muxer message iterator (same component).
1285 BT_LOGE("Recursive initialization of muxer component's message iterator: "
1286 "comp-addr=%p, muxer-comp-addr=%p, msg-iter-addr=%p",
1287 self_comp
, muxer_comp
, self_msg_iter
);
1291 muxer_comp
->initializing_muxer_msg_iter
= true;
1292 muxer_msg_iter
= g_new0(struct muxer_msg_iter
, 1);
1293 if (!muxer_msg_iter
) {
1294 BT_LOGE_STR("Failed to allocate one muxer component's message iterator.");
1298 muxer_msg_iter
->last_returned_ts_ns
= INT64_MIN
;
1299 muxer_msg_iter
->active_muxer_upstream_msg_iters
=
1300 g_ptr_array_new_with_free_func(
1301 (GDestroyNotify
) destroy_muxer_upstream_msg_iter
);
1302 if (!muxer_msg_iter
->active_muxer_upstream_msg_iters
) {
1303 BT_LOGE_STR("Failed to allocate a GPtrArray.");
1307 muxer_msg_iter
->ended_muxer_upstream_msg_iters
=
1308 g_ptr_array_new_with_free_func(
1309 (GDestroyNotify
) destroy_muxer_upstream_msg_iter
);
1310 if (!muxer_msg_iter
->ended_muxer_upstream_msg_iters
) {
1311 BT_LOGE_STR("Failed to allocate a GPtrArray.");
1315 ret
= muxer_msg_iter_init_upstream_iterators(muxer_comp
,
1318 BT_LOGE("Cannot initialize connected input ports for muxer component's message iterator: "
1319 "comp-addr=%p, muxer-comp-addr=%p, "
1320 "muxer-msg-iter-addr=%p, msg-iter-addr=%p, ret=%d",
1321 self_comp
, muxer_comp
, muxer_msg_iter
,
1322 self_msg_iter
, ret
);
1326 bt_self_message_iterator_set_data(self_msg_iter
, muxer_msg_iter
);
1327 BT_LOGD("Initialized muxer component's message iterator: "
1328 "comp-addr=%p, muxer-comp-addr=%p, muxer-msg-iter-addr=%p, "
1330 self_comp
, muxer_comp
, muxer_msg_iter
, self_msg_iter
);
1334 destroy_muxer_msg_iter(muxer_msg_iter
);
1335 bt_self_message_iterator_set_data(self_msg_iter
, NULL
);
1336 status
= BT_SELF_MESSAGE_ITERATOR_STATUS_ERROR
;
1339 muxer_comp
->initializing_muxer_msg_iter
= false;
1344 void muxer_msg_iter_finalize(bt_self_message_iterator
*self_msg_iter
)
1346 struct muxer_msg_iter
*muxer_msg_iter
=
1347 bt_self_message_iterator_get_data(self_msg_iter
);
1348 bt_self_component
*self_comp
= NULL
;
1349 struct muxer_comp
*muxer_comp
= NULL
;
1351 self_comp
= bt_self_message_iterator_borrow_component(
1353 BT_ASSERT(self_comp
);
1354 muxer_comp
= bt_self_component_get_data(self_comp
);
1355 BT_LOGD("Finalizing muxer component's message iterator: "
1356 "comp-addr=%p, muxer-comp-addr=%p, muxer-msg-iter-addr=%p, "
1358 self_comp
, muxer_comp
, muxer_msg_iter
, self_msg_iter
);
1360 if (muxer_msg_iter
) {
1361 destroy_muxer_msg_iter(muxer_msg_iter
);
1366 bt_self_message_iterator_status
muxer_msg_iter_next(
1367 bt_self_message_iterator
*self_msg_iter
,
1368 bt_message_array_const msgs
, uint64_t capacity
,
1371 bt_self_message_iterator_status status
;
1372 struct muxer_msg_iter
*muxer_msg_iter
=
1373 bt_self_message_iterator_get_data(self_msg_iter
);
1374 bt_self_component
*self_comp
= NULL
;
1375 struct muxer_comp
*muxer_comp
= NULL
;
1377 BT_ASSERT(muxer_msg_iter
);
1378 self_comp
= bt_self_message_iterator_borrow_component(
1380 BT_ASSERT(self_comp
);
1381 muxer_comp
= bt_self_component_get_data(self_comp
);
1382 BT_ASSERT(muxer_comp
);
1383 BT_LOGV("Muxer component's message iterator's \"next\" method called: "
1384 "comp-addr=%p, muxer-comp-addr=%p, muxer-msg-iter-addr=%p, "
1386 self_comp
, muxer_comp
, muxer_msg_iter
, self_msg_iter
);
1388 status
= muxer_msg_iter_do_next(muxer_comp
, muxer_msg_iter
,
1389 msgs
, capacity
, count
);
1391 BT_LOGE("Cannot get next message: "
1392 "comp-addr=%p, muxer-comp-addr=%p, muxer-msg-iter-addr=%p, "
1393 "msg-iter-addr=%p, status=%s",
1394 self_comp
, muxer_comp
, muxer_msg_iter
, self_msg_iter
,
1395 bt_common_self_message_iterator_status_string(status
));
1397 BT_LOGV("Returning from muxer component's message iterator's \"next\" method: "
1399 bt_common_self_message_iterator_status_string(status
));
1406 bt_self_component_status
muxer_input_port_connected(
1407 bt_self_component_filter
*self_comp
,
1408 bt_self_component_port_input
*self_port
,
1409 const bt_port_output
*other_port
)
1411 bt_self_component_status status
;
1413 status
= add_available_input_port(self_comp
);
1416 * Only way to report an error later since this
1417 * method does not return anything.
1419 BT_LOGE("Cannot add one muxer component's input port: "
1421 bt_self_component_status_string(status
));
1430 bt_bool
muxer_upstream_msg_iters_can_all_seek_beginning(
1431 GPtrArray
*muxer_upstream_msg_iters
)
1434 bt_bool ret
= BT_TRUE
;
1436 for (i
= 0; i
< muxer_upstream_msg_iters
->len
; i
++) {
1437 struct muxer_upstream_msg_iter
*upstream_msg_iter
=
1438 muxer_upstream_msg_iters
->pdata
[i
];
1440 if (!bt_self_component_port_input_message_iterator_can_seek_beginning(
1441 upstream_msg_iter
->msg_iter
)) {
1452 bt_bool
muxer_msg_iter_can_seek_beginning(
1453 bt_self_message_iterator
*self_msg_iter
)
1455 struct muxer_msg_iter
*muxer_msg_iter
=
1456 bt_self_message_iterator_get_data(self_msg_iter
);
1457 bt_bool ret
= BT_TRUE
;
1459 if (!muxer_upstream_msg_iters_can_all_seek_beginning(
1460 muxer_msg_iter
->active_muxer_upstream_msg_iters
)) {
1465 if (!muxer_upstream_msg_iters_can_all_seek_beginning(
1466 muxer_msg_iter
->ended_muxer_upstream_msg_iters
)) {
1476 bt_self_message_iterator_status
muxer_msg_iter_seek_beginning(
1477 bt_self_message_iterator
*self_msg_iter
)
1479 struct muxer_msg_iter
*muxer_msg_iter
=
1480 bt_self_message_iterator_get_data(self_msg_iter
);
1481 bt_message_iterator_status status
= BT_MESSAGE_ITERATOR_STATUS_OK
;
1484 /* Seek all ended upstream iterators first */
1485 for (i
= 0; i
< muxer_msg_iter
->ended_muxer_upstream_msg_iters
->len
;
1487 struct muxer_upstream_msg_iter
*upstream_msg_iter
=
1488 muxer_msg_iter
->ended_muxer_upstream_msg_iters
->pdata
[i
];
1490 status
= bt_self_component_port_input_message_iterator_seek_beginning(
1491 upstream_msg_iter
->msg_iter
);
1492 if (status
!= BT_MESSAGE_ITERATOR_STATUS_OK
) {
1496 empty_message_queue(upstream_msg_iter
);
1499 /* Seek all previously active upstream iterators */
1500 for (i
= 0; i
< muxer_msg_iter
->active_muxer_upstream_msg_iters
->len
;
1502 struct muxer_upstream_msg_iter
*upstream_msg_iter
=
1503 muxer_msg_iter
->active_muxer_upstream_msg_iters
->pdata
[i
];
1505 status
= bt_self_component_port_input_message_iterator_seek_beginning(
1506 upstream_msg_iter
->msg_iter
);
1507 if (status
!= BT_MESSAGE_ITERATOR_STATUS_OK
) {
1511 empty_message_queue(upstream_msg_iter
);
1514 /* Make them all active */
1515 for (i
= 0; i
< muxer_msg_iter
->ended_muxer_upstream_msg_iters
->len
;
1517 struct muxer_upstream_msg_iter
*upstream_msg_iter
=
1518 muxer_msg_iter
->ended_muxer_upstream_msg_iters
->pdata
[i
];
1520 g_ptr_array_add(muxer_msg_iter
->active_muxer_upstream_msg_iters
,
1522 muxer_msg_iter
->ended_muxer_upstream_msg_iters
->pdata
[i
] = NULL
;
1525 g_ptr_array_remove_range(muxer_msg_iter
->ended_muxer_upstream_msg_iters
,
1526 0, muxer_msg_iter
->ended_muxer_upstream_msg_iters
->len
);
1527 muxer_msg_iter
->last_returned_ts_ns
= INT64_MIN
;
1528 muxer_msg_iter
->clock_class_expectation
=
1529 MUXER_MSG_ITER_CLOCK_CLASS_EXPECTATION_ANY
;
1532 return (bt_self_message_iterator_status
) status
;