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/FLT.UTILS.MUXER"
26 #include "common/macros.h"
27 #include "compat/uuid.h"
28 #include <babeltrace2/babeltrace.h>
32 #include "common/assert.h"
33 #include "common/common.h"
39 #define ASSUME_ABSOLUTE_CLOCK_CLASSES_PARAM_NAME "assume-absolute-clock-classes"
43 bt_self_component_filter
*self_comp
;
45 unsigned int next_port_num
;
46 size_t available_input_ports
;
47 bool initializing_muxer_msg_iter
;
48 bool assume_absolute_clock_classes
;
51 struct muxer_upstream_msg_iter
{
52 /* Owned by this, NULL if ended */
53 bt_self_component_port_input_message_iterator
*msg_iter
;
55 /* Contains `const bt_message *`, owned by this */
59 enum muxer_msg_iter_clock_class_expectation
{
60 MUXER_MSG_ITER_CLOCK_CLASS_EXPECTATION_ANY
= 0,
61 MUXER_MSG_ITER_CLOCK_CLASS_EXPECTATION_NONE
,
62 MUXER_MSG_ITER_CLOCK_CLASS_EXPECTATION_ABSOLUTE
,
63 MUXER_MSG_ITER_CLOCK_CLASS_EXPECTATION_NOT_ABS_SPEC_UUID
,
64 MUXER_MSG_ITER_CLOCK_CLASS_EXPECTATION_NOT_ABS_NO_UUID
,
67 struct muxer_msg_iter
{
69 * Array of struct muxer_upstream_msg_iter * (owned by this).
71 * NOTE: This array is searched in linearly to find the youngest
72 * current message. Keep this until benchmarks confirm that
73 * another data structure is faster than this for our typical
76 GPtrArray
*active_muxer_upstream_msg_iters
;
79 * Array of struct muxer_upstream_msg_iter * (owned by this).
81 * We move ended message iterators from
82 * `active_muxer_upstream_msg_iters` to this array so as to be
83 * able to restore them when seeking.
85 GPtrArray
*ended_muxer_upstream_msg_iters
;
87 /* Last time returned in a message */
88 int64_t last_returned_ts_ns
;
90 /* Clock class expectation state */
91 enum muxer_msg_iter_clock_class_expectation clock_class_expectation
;
94 * Expected clock class UUID, only valid when
95 * clock_class_expectation is
96 * MUXER_MSG_ITER_CLOCK_CLASS_EXPECTATION_NOT_ABS_SPEC_UUID.
98 unsigned char expected_clock_class_uuid
[BABELTRACE_UUID_LEN
];
102 void empty_message_queue(struct muxer_upstream_msg_iter
*upstream_msg_iter
)
104 const bt_message
*msg
;
106 while ((msg
= g_queue_pop_head(upstream_msg_iter
->msgs
))) {
107 bt_message_put_ref(msg
);
112 void destroy_muxer_upstream_msg_iter(
113 struct muxer_upstream_msg_iter
*muxer_upstream_msg_iter
)
115 if (!muxer_upstream_msg_iter
) {
119 BT_LOGD("Destroying muxer's upstream message iterator wrapper: "
120 "addr=%p, msg-iter-addr=%p, queue-len=%u",
121 muxer_upstream_msg_iter
,
122 muxer_upstream_msg_iter
->msg_iter
,
123 muxer_upstream_msg_iter
->msgs
->length
);
124 bt_self_component_port_input_message_iterator_put_ref(
125 muxer_upstream_msg_iter
->msg_iter
);
127 if (muxer_upstream_msg_iter
->msgs
) {
128 empty_message_queue(muxer_upstream_msg_iter
);
129 g_queue_free(muxer_upstream_msg_iter
->msgs
);
132 g_free(muxer_upstream_msg_iter
);
136 int muxer_msg_iter_add_upstream_msg_iter(struct muxer_msg_iter
*muxer_msg_iter
,
137 bt_self_component_port_input_message_iterator
*self_msg_iter
)
140 struct muxer_upstream_msg_iter
*muxer_upstream_msg_iter
=
141 g_new0(struct muxer_upstream_msg_iter
, 1);
143 if (!muxer_upstream_msg_iter
) {
144 BT_LOGE_STR("Failed to allocate one muxer's upstream message iterator wrapper.");
148 muxer_upstream_msg_iter
->msg_iter
= self_msg_iter
;
149 bt_self_component_port_input_message_iterator_get_ref(muxer_upstream_msg_iter
->msg_iter
);
150 muxer_upstream_msg_iter
->msgs
= g_queue_new();
151 if (!muxer_upstream_msg_iter
->msgs
) {
152 BT_LOGE_STR("Failed to allocate a GQueue.");
156 g_ptr_array_add(muxer_msg_iter
->active_muxer_upstream_msg_iters
,
157 muxer_upstream_msg_iter
);
158 BT_LOGD("Added muxer's upstream message iterator wrapper: "
159 "addr=%p, muxer-msg-iter-addr=%p, msg-iter-addr=%p",
160 muxer_upstream_msg_iter
, muxer_msg_iter
,
166 g_free(muxer_upstream_msg_iter
);
174 bt_self_component_status
add_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 bt_self_component_status status
= BT_SELF_COMPONENT_STATUS_OK
;
180 GString
*port_name
= NULL
;
182 BT_ASSERT(muxer_comp
);
183 port_name
= g_string_new("in");
185 BT_LOGE_STR("Failed to allocate a GString.");
186 status
= BT_SELF_COMPONENT_STATUS_NOMEM
;
190 g_string_append_printf(port_name
, "%u", muxer_comp
->next_port_num
);
191 status
= bt_self_component_filter_add_input_port(
192 self_comp
, port_name
->str
, NULL
, NULL
);
193 if (status
!= BT_SELF_COMPONENT_STATUS_OK
) {
194 BT_LOGE("Cannot add input port to muxer component: "
195 "port-name=\"%s\", comp-addr=%p, status=%s",
196 port_name
->str
, self_comp
,
197 bt_self_component_status_string(status
));
201 muxer_comp
->available_input_ports
++;
202 muxer_comp
->next_port_num
++;
203 BT_LOGI("Added one input port to muxer component: "
204 "port-name=\"%s\", comp-addr=%p",
205 port_name
->str
, self_comp
);
209 g_string_free(port_name
, TRUE
);
216 bt_self_component_status
create_output_port(
217 bt_self_component_filter
*self_comp
)
219 return bt_self_component_filter_add_output_port(
220 self_comp
, "out", NULL
, NULL
);
224 void destroy_muxer_comp(struct muxer_comp
*muxer_comp
)
234 bt_value
*get_default_params(void)
239 params
= bt_value_map_create();
241 BT_LOGE_STR("Cannot create a map value object.");
245 ret
= bt_value_map_insert_bool_entry(params
,
246 ASSUME_ABSOLUTE_CLOCK_CLASSES_PARAM_NAME
, false);
248 BT_LOGE_STR("Cannot add boolean value to map value object.");
255 BT_VALUE_PUT_REF_AND_RESET(params
);
262 int configure_muxer_comp(struct muxer_comp
*muxer_comp
,
263 const bt_value
*params
)
265 bt_value
*default_params
= NULL
;
266 bt_value
*real_params
= NULL
;
267 const bt_value
*assume_absolute_clock_classes
= NULL
;
271 default_params
= get_default_params();
272 if (!default_params
) {
273 BT_LOGE("Cannot get default parameters: "
274 "muxer-comp-addr=%p", muxer_comp
);
278 ret
= bt_value_map_extend(default_params
, params
, &real_params
);
280 BT_LOGE("Cannot extend default parameters map value: "
281 "muxer-comp-addr=%p, def-params-addr=%p, "
282 "params-addr=%p", muxer_comp
, default_params
,
287 assume_absolute_clock_classes
= bt_value_map_borrow_entry_value(real_params
,
288 ASSUME_ABSOLUTE_CLOCK_CLASSES_PARAM_NAME
);
289 if (assume_absolute_clock_classes
&&
290 !bt_value_is_bool(assume_absolute_clock_classes
)) {
291 BT_LOGE("Expecting a boolean value for the `%s` parameter: "
292 "muxer-comp-addr=%p, value-type=%s",
293 ASSUME_ABSOLUTE_CLOCK_CLASSES_PARAM_NAME
, muxer_comp
,
294 bt_common_value_type_string(
295 bt_value_get_type(assume_absolute_clock_classes
)));
299 bool_val
= bt_value_bool_get(assume_absolute_clock_classes
);
300 muxer_comp
->assume_absolute_clock_classes
= (bool) bool_val
;
301 BT_LOGI("Configured muxer component: muxer-comp-addr=%p, "
302 "assume-absolute-clock-classes=%d",
303 muxer_comp
, muxer_comp
->assume_absolute_clock_classes
);
310 bt_value_put_ref(default_params
);
311 bt_value_put_ref(real_params
);
316 bt_self_component_status
muxer_init(
317 bt_self_component_filter
*self_comp
,
318 const bt_value
*params
, void *init_data
)
321 bt_self_component_status status
= BT_SELF_COMPONENT_STATUS_OK
;
322 struct muxer_comp
*muxer_comp
= g_new0(struct muxer_comp
, 1);
324 BT_LOGI("Initializing muxer component: "
325 "comp-addr=%p, params-addr=%p", self_comp
, params
);
328 BT_LOGE_STR("Failed to allocate one muxer component.");
332 ret
= configure_muxer_comp(muxer_comp
, params
);
334 BT_LOGE("Cannot configure muxer component: "
335 "muxer-comp-addr=%p, params-addr=%p",
340 muxer_comp
->self_comp
= self_comp
;
341 bt_self_component_set_data(
342 bt_self_component_filter_as_self_component(self_comp
),
344 status
= add_available_input_port(self_comp
);
345 if (status
!= BT_SELF_COMPONENT_STATUS_OK
) {
346 BT_LOGE("Cannot ensure that at least one muxer component's input port is available: "
347 "muxer-comp-addr=%p, status=%s",
349 bt_self_component_status_string(status
));
353 status
= create_output_port(self_comp
);
355 BT_LOGE("Cannot create muxer component's output port: "
356 "muxer-comp-addr=%p, status=%s",
358 bt_self_component_status_string(status
));
362 BT_LOGI("Initialized muxer component: "
363 "comp-addr=%p, params-addr=%p, muxer-comp-addr=%p",
364 self_comp
, params
, muxer_comp
);
369 destroy_muxer_comp(muxer_comp
);
370 bt_self_component_set_data(
371 bt_self_component_filter_as_self_component(self_comp
),
374 if (status
== BT_SELF_COMPONENT_STATUS_OK
) {
375 status
= BT_SELF_COMPONENT_STATUS_ERROR
;
383 void muxer_finalize(bt_self_component_filter
*self_comp
)
385 struct muxer_comp
*muxer_comp
= bt_self_component_get_data(
386 bt_self_component_filter_as_self_component(self_comp
));
388 BT_LOGI("Finalizing muxer component: comp-addr=%p",
390 destroy_muxer_comp(muxer_comp
);
394 bt_self_component_port_input_message_iterator
*
395 create_msg_iter_on_input_port(bt_self_component_port_input
*self_port
)
397 const bt_port
*port
= bt_self_component_port_as_port(
398 bt_self_component_port_input_as_self_component_port(
400 bt_self_component_port_input_message_iterator
*msg_iter
=
404 BT_ASSERT(bt_port_is_connected(port
));
406 // TODO: Advance the iterator to >= the time of the latest
407 // returned message by the muxer message
408 // iterator which creates it.
409 msg_iter
= bt_self_component_port_input_message_iterator_create(
412 BT_LOGE("Cannot create upstream message iterator on input port: "
413 "port-addr=%p, port-name=\"%s\"",
414 port
, bt_port_get_name(port
));
418 BT_LOGI("Created upstream message iterator on input port: "
419 "port-addr=%p, port-name=\"%s\", msg-iter-addr=%p",
420 port
, bt_port_get_name(port
), msg_iter
);
427 bt_self_message_iterator_status
muxer_upstream_msg_iter_next(
428 struct muxer_upstream_msg_iter
*muxer_upstream_msg_iter
,
431 bt_self_message_iterator_status status
;
432 bt_message_iterator_status input_port_iter_status
;
433 bt_message_array_const msgs
;
437 BT_LOGD("Calling upstream message iterator's \"next\" method: "
438 "muxer-upstream-msg-iter-wrap-addr=%p, msg-iter-addr=%p",
439 muxer_upstream_msg_iter
,
440 muxer_upstream_msg_iter
->msg_iter
);
441 input_port_iter_status
= bt_self_component_port_input_message_iterator_next(
442 muxer_upstream_msg_iter
->msg_iter
, &msgs
, &count
);
443 BT_LOGD("Upstream message iterator's \"next\" method returned: "
444 "status=%s", bt_message_iterator_status_string(input_port_iter_status
));
446 switch (input_port_iter_status
) {
447 case BT_MESSAGE_ITERATOR_STATUS_OK
:
449 * Message iterator's current message is
450 * valid: it must be considered for muxing operations.
452 BT_LOGD_STR("Validated upstream message iterator wrapper.");
453 BT_ASSERT(count
> 0);
455 /* Move messages to our queue */
456 for (i
= 0; i
< count
; i
++) {
458 * Push to tail in order; other side
459 * (muxer_msg_iter_do_next_one()) consumes
460 * from the head first.
462 g_queue_push_tail(muxer_upstream_msg_iter
->msgs
,
465 status
= BT_SELF_MESSAGE_ITERATOR_STATUS_OK
;
467 case BT_MESSAGE_ITERATOR_STATUS_AGAIN
:
469 * Message iterator's current message is not
470 * valid anymore. Return
471 * BT_MESSAGE_ITERATOR_STATUS_AGAIN immediately.
473 status
= BT_SELF_MESSAGE_ITERATOR_STATUS_AGAIN
;
475 case BT_MESSAGE_ITERATOR_STATUS_END
: /* Fall-through. */
477 * Message iterator reached the end: release it. It
478 * won't be considered again to find the youngest
482 status
= BT_SELF_MESSAGE_ITERATOR_STATUS_OK
;
485 /* Error or unsupported status code */
486 BT_LOGE("Error or unsupported status code: "
487 "status-code=%d", input_port_iter_status
);
488 status
= BT_SELF_MESSAGE_ITERATOR_STATUS_ERROR
;
496 int get_msg_ts_ns(struct muxer_comp
*muxer_comp
,
497 struct muxer_msg_iter
*muxer_msg_iter
,
498 const bt_message
*msg
, int64_t last_returned_ts_ns
,
501 const bt_clock_snapshot
*clock_snapshot
= NULL
;
503 bt_message_stream_activity_clock_snapshot_state sa_cs_state
;
504 const bt_stream_class
*stream_class
= NULL
;
505 bt_message_type msg_type
;
509 BT_LOGD("Getting message's timestamp: "
510 "muxer-msg-iter-addr=%p, msg-addr=%p, "
511 "last-returned-ts=%" PRId64
,
512 muxer_msg_iter
, msg
, last_returned_ts_ns
);
514 if (G_UNLIKELY(muxer_msg_iter
->clock_class_expectation
==
515 MUXER_MSG_ITER_CLOCK_CLASS_EXPECTATION_NONE
)) {
516 *ts_ns
= last_returned_ts_ns
;
520 msg_type
= bt_message_get_type(msg
);
522 if (G_UNLIKELY(msg_type
== BT_MESSAGE_TYPE_PACKET_BEGINNING
)) {
523 stream_class
= bt_stream_borrow_class_const(
524 bt_packet_borrow_stream_const(
525 bt_message_packet_beginning_borrow_packet_const(
527 } else if (G_UNLIKELY(msg_type
== BT_MESSAGE_TYPE_PACKET_END
)) {
528 stream_class
= bt_stream_borrow_class_const(
529 bt_packet_borrow_stream_const(
530 bt_message_packet_end_borrow_packet_const(
532 } else if (G_UNLIKELY(msg_type
== BT_MESSAGE_TYPE_DISCARDED_EVENTS
)) {
533 stream_class
= bt_stream_borrow_class_const(
534 bt_message_discarded_events_borrow_stream_const(msg
));
535 } else if (G_UNLIKELY(msg_type
== BT_MESSAGE_TYPE_DISCARDED_PACKETS
)) {
536 stream_class
= bt_stream_borrow_class_const(
537 bt_message_discarded_packets_borrow_stream_const(msg
));
541 case BT_MESSAGE_TYPE_EVENT
:
542 BT_ASSERT(bt_message_event_borrow_stream_class_default_clock_class_const(
544 clock_snapshot
= bt_message_event_borrow_default_clock_snapshot_const(
547 case BT_MESSAGE_TYPE_PACKET_BEGINNING
:
548 if (bt_stream_class_packets_have_beginning_default_clock_snapshot(
550 clock_snapshot
= bt_message_packet_beginning_borrow_default_clock_snapshot_const(
553 goto no_clock_snapshot
;
557 case BT_MESSAGE_TYPE_PACKET_END
:
558 if (bt_stream_class_packets_have_end_default_clock_snapshot(
560 clock_snapshot
= bt_message_packet_end_borrow_default_clock_snapshot_const(
563 goto no_clock_snapshot
;
567 case BT_MESSAGE_TYPE_DISCARDED_EVENTS
:
568 if (bt_stream_class_discarded_events_have_default_clock_snapshots(
570 clock_snapshot
= bt_message_discarded_events_borrow_beginning_default_clock_snapshot_const(
573 goto no_clock_snapshot
;
577 case BT_MESSAGE_TYPE_DISCARDED_PACKETS
:
578 if (bt_stream_class_discarded_packets_have_default_clock_snapshots(
580 clock_snapshot
= bt_message_discarded_packets_borrow_beginning_default_clock_snapshot_const(
583 goto no_clock_snapshot
;
587 case BT_MESSAGE_TYPE_STREAM_ACTIVITY_BEGINNING
:
588 BT_ASSERT(bt_message_stream_activity_beginning_borrow_stream_class_default_clock_class_const(
590 sa_cs_state
= bt_message_stream_activity_beginning_borrow_default_clock_snapshot_const(
591 msg
, &clock_snapshot
);
592 if (sa_cs_state
!= BT_MESSAGE_STREAM_ACTIVITY_CLOCK_SNAPSHOT_STATE_KNOWN
) {
593 goto no_clock_snapshot
;
597 case BT_MESSAGE_TYPE_STREAM_ACTIVITY_END
:
598 BT_ASSERT(bt_message_stream_activity_end_borrow_stream_class_default_clock_class_const(
600 sa_cs_state
= bt_message_stream_activity_end_borrow_default_clock_snapshot_const(
601 msg
, &clock_snapshot
);
602 if (sa_cs_state
!= BT_MESSAGE_STREAM_ACTIVITY_CLOCK_SNAPSHOT_STATE_KNOWN
) {
603 goto no_clock_snapshot
;
607 case BT_MESSAGE_TYPE_MESSAGE_ITERATOR_INACTIVITY
:
608 clock_snapshot
= bt_message_message_iterator_inactivity_borrow_default_clock_snapshot_const(
612 /* All the other messages have a higher priority */
613 BT_LOGD_STR("Message has no timestamp: using the last returned timestamp.");
614 *ts_ns
= last_returned_ts_ns
;
618 ret
= bt_clock_snapshot_get_ns_from_origin(clock_snapshot
, ts_ns
);
620 BT_LOGE("Cannot get nanoseconds from Epoch of clock snapshot: "
621 "clock-snapshot-addr=%p", clock_snapshot
);
628 BT_LOGD_STR("Message's default clock snapshot is missing: "
629 "using the last returned timestamp.");
630 *ts_ns
= last_returned_ts_ns
;
638 BT_LOGD("Found message's timestamp: "
639 "muxer-msg-iter-addr=%p, msg-addr=%p, "
640 "last-returned-ts=%" PRId64
", ts=%" PRId64
,
641 muxer_msg_iter
, msg
, last_returned_ts_ns
,
649 int validate_clock_class(struct muxer_msg_iter
*muxer_msg_iter
,
650 struct muxer_comp
*muxer_comp
,
651 const bt_clock_class
*clock_class
)
654 const unsigned char *cc_uuid
;
657 BT_ASSERT(clock_class
);
658 cc_uuid
= bt_clock_class_get_uuid(clock_class
);
659 cc_name
= bt_clock_class_get_name(clock_class
);
661 if (muxer_msg_iter
->clock_class_expectation
==
662 MUXER_MSG_ITER_CLOCK_CLASS_EXPECTATION_ANY
) {
664 * This is the first clock class that this muxer
665 * message iterator encounters. Its properties
666 * determine what to expect for the whole lifetime of
667 * the iterator without a true
668 * `assume-absolute-clock-classes` parameter.
670 if (bt_clock_class_origin_is_unix_epoch(clock_class
)) {
671 /* Expect absolute clock classes */
672 muxer_msg_iter
->clock_class_expectation
=
673 MUXER_MSG_ITER_CLOCK_CLASS_EXPECTATION_ABSOLUTE
;
677 * Expect non-absolute clock classes
678 * with a specific UUID.
680 muxer_msg_iter
->clock_class_expectation
=
681 MUXER_MSG_ITER_CLOCK_CLASS_EXPECTATION_NOT_ABS_SPEC_UUID
;
682 memcpy(muxer_msg_iter
->expected_clock_class_uuid
,
683 cc_uuid
, BABELTRACE_UUID_LEN
);
686 * Expect non-absolute clock classes
689 muxer_msg_iter
->clock_class_expectation
=
690 MUXER_MSG_ITER_CLOCK_CLASS_EXPECTATION_NOT_ABS_NO_UUID
;
695 if (!muxer_comp
->assume_absolute_clock_classes
) {
696 switch (muxer_msg_iter
->clock_class_expectation
) {
697 case MUXER_MSG_ITER_CLOCK_CLASS_EXPECTATION_ABSOLUTE
:
698 if (!bt_clock_class_origin_is_unix_epoch(clock_class
)) {
699 BT_LOGE("Expecting an absolute clock class, "
700 "but got a non-absolute one: "
701 "clock-class-addr=%p, clock-class-name=\"%s\"",
702 clock_class
, cc_name
);
706 case MUXER_MSG_ITER_CLOCK_CLASS_EXPECTATION_NOT_ABS_NO_UUID
:
707 if (bt_clock_class_origin_is_unix_epoch(clock_class
)) {
708 BT_LOGE("Expecting a non-absolute clock class with no UUID, "
709 "but got an absolute one: "
710 "clock-class-addr=%p, clock-class-name=\"%s\"",
711 clock_class
, cc_name
);
716 BT_LOGE("Expecting a non-absolute clock class with no UUID, "
717 "but got one with a UUID: "
718 "clock-class-addr=%p, clock-class-name=\"%s\", "
719 "uuid=\"%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x\"",
720 clock_class
, cc_name
,
721 (unsigned int) cc_uuid
[0],
722 (unsigned int) cc_uuid
[1],
723 (unsigned int) cc_uuid
[2],
724 (unsigned int) cc_uuid
[3],
725 (unsigned int) cc_uuid
[4],
726 (unsigned int) cc_uuid
[5],
727 (unsigned int) cc_uuid
[6],
728 (unsigned int) cc_uuid
[7],
729 (unsigned int) cc_uuid
[8],
730 (unsigned int) cc_uuid
[9],
731 (unsigned int) cc_uuid
[10],
732 (unsigned int) cc_uuid
[11],
733 (unsigned int) cc_uuid
[12],
734 (unsigned int) cc_uuid
[13],
735 (unsigned int) cc_uuid
[14],
736 (unsigned int) cc_uuid
[15]);
740 case MUXER_MSG_ITER_CLOCK_CLASS_EXPECTATION_NOT_ABS_SPEC_UUID
:
741 if (bt_clock_class_origin_is_unix_epoch(clock_class
)) {
742 BT_LOGE("Expecting a non-absolute clock class with a specific UUID, "
743 "but got an absolute one: "
744 "clock-class-addr=%p, clock-class-name=\"%s\"",
745 clock_class
, cc_name
);
750 BT_LOGE("Expecting a non-absolute clock class with a specific UUID, "
751 "but got one with no UUID: "
752 "clock-class-addr=%p, clock-class-name=\"%s\"",
753 clock_class
, cc_name
);
757 if (memcmp(muxer_msg_iter
->expected_clock_class_uuid
,
758 cc_uuid
, BABELTRACE_UUID_LEN
) != 0) {
759 BT_LOGE("Expecting a non-absolute clock class with a specific UUID, "
760 "but got one with different UUID: "
761 "clock-class-addr=%p, clock-class-name=\"%s\", "
762 "expected-uuid=\"%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x\", "
763 "uuid=\"%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x\"",
764 clock_class
, cc_name
,
765 (unsigned int) muxer_msg_iter
->expected_clock_class_uuid
[0],
766 (unsigned int) muxer_msg_iter
->expected_clock_class_uuid
[1],
767 (unsigned int) muxer_msg_iter
->expected_clock_class_uuid
[2],
768 (unsigned int) muxer_msg_iter
->expected_clock_class_uuid
[3],
769 (unsigned int) muxer_msg_iter
->expected_clock_class_uuid
[4],
770 (unsigned int) muxer_msg_iter
->expected_clock_class_uuid
[5],
771 (unsigned int) muxer_msg_iter
->expected_clock_class_uuid
[6],
772 (unsigned int) muxer_msg_iter
->expected_clock_class_uuid
[7],
773 (unsigned int) muxer_msg_iter
->expected_clock_class_uuid
[8],
774 (unsigned int) muxer_msg_iter
->expected_clock_class_uuid
[9],
775 (unsigned int) muxer_msg_iter
->expected_clock_class_uuid
[10],
776 (unsigned int) muxer_msg_iter
->expected_clock_class_uuid
[11],
777 (unsigned int) muxer_msg_iter
->expected_clock_class_uuid
[12],
778 (unsigned int) muxer_msg_iter
->expected_clock_class_uuid
[13],
779 (unsigned int) muxer_msg_iter
->expected_clock_class_uuid
[14],
780 (unsigned int) muxer_msg_iter
->expected_clock_class_uuid
[15],
781 (unsigned int) cc_uuid
[0],
782 (unsigned int) cc_uuid
[1],
783 (unsigned int) cc_uuid
[2],
784 (unsigned int) cc_uuid
[3],
785 (unsigned int) cc_uuid
[4],
786 (unsigned int) cc_uuid
[5],
787 (unsigned int) cc_uuid
[6],
788 (unsigned int) cc_uuid
[7],
789 (unsigned int) cc_uuid
[8],
790 (unsigned int) cc_uuid
[9],
791 (unsigned int) cc_uuid
[10],
792 (unsigned int) cc_uuid
[11],
793 (unsigned int) cc_uuid
[12],
794 (unsigned int) cc_uuid
[13],
795 (unsigned int) cc_uuid
[14],
796 (unsigned int) cc_uuid
[15]);
800 case MUXER_MSG_ITER_CLOCK_CLASS_EXPECTATION_NONE
:
801 BT_LOGE("Expecting no clock class, but got one: "
802 "clock-class-addr=%p, clock-class-name=\"%s\"",
803 clock_class
, cc_name
);
807 BT_LOGF("Unexpected clock class expectation: "
808 "expectation-code=%d",
809 muxer_msg_iter
->clock_class_expectation
);
824 int validate_new_stream_clock_class(struct muxer_msg_iter
*muxer_msg_iter
,
825 struct muxer_comp
*muxer_comp
, const bt_stream
*stream
)
828 const bt_stream_class
*stream_class
=
829 bt_stream_borrow_class_const(stream
);
830 const bt_clock_class
*clock_class
=
831 bt_stream_class_borrow_default_clock_class_const(stream_class
);
834 if (muxer_msg_iter
->clock_class_expectation
==
835 MUXER_MSG_ITER_CLOCK_CLASS_EXPECTATION_ANY
) {
836 /* Expect no clock class */
837 muxer_msg_iter
->clock_class_expectation
=
838 MUXER_MSG_ITER_CLOCK_CLASS_EXPECTATION_NONE
;
840 BT_LOGE("Expecting stream class with a default clock class: "
841 "stream-class-addr=%p, stream-class-name=\"%s\", "
842 "stream-class-id=%" PRIu64
,
843 stream_class
, bt_stream_class_get_name(stream_class
),
844 bt_stream_class_get_id(stream_class
));
851 ret
= validate_clock_class(muxer_msg_iter
, muxer_comp
, clock_class
);
858 * This function finds the youngest available message amongst the
859 * non-ended upstream message iterators and returns the upstream
860 * message iterator which has it, or
861 * BT_MESSAGE_ITERATOR_STATUS_END if there's no available
864 * This function does NOT:
866 * * Update any upstream message iterator.
867 * * Check the upstream message iterators to retry.
869 * On sucess, this function sets *muxer_upstream_msg_iter to the
870 * upstream message iterator of which the current message is
871 * the youngest, and sets *ts_ns to its time.
874 bt_self_message_iterator_status
875 muxer_msg_iter_youngest_upstream_msg_iter(
876 struct muxer_comp
*muxer_comp
,
877 struct muxer_msg_iter
*muxer_msg_iter
,
878 struct muxer_upstream_msg_iter
**muxer_upstream_msg_iter
,
883 int64_t youngest_ts_ns
= INT64_MAX
;
884 bt_self_message_iterator_status status
=
885 BT_SELF_MESSAGE_ITERATOR_STATUS_OK
;
887 BT_ASSERT(muxer_comp
);
888 BT_ASSERT(muxer_msg_iter
);
889 BT_ASSERT(muxer_upstream_msg_iter
);
890 *muxer_upstream_msg_iter
= NULL
;
892 for (i
= 0; i
< muxer_msg_iter
->active_muxer_upstream_msg_iters
->len
;
894 const bt_message
*msg
;
895 struct muxer_upstream_msg_iter
*cur_muxer_upstream_msg_iter
=
897 muxer_msg_iter
->active_muxer_upstream_msg_iters
,
901 if (!cur_muxer_upstream_msg_iter
->msg_iter
) {
902 /* This upstream message iterator is ended */
903 BT_LOGV("Skipping ended upstream message iterator: "
904 "muxer-upstream-msg-iter-wrap-addr=%p",
905 cur_muxer_upstream_msg_iter
);
909 BT_ASSERT(cur_muxer_upstream_msg_iter
->msgs
->length
> 0);
910 msg
= g_queue_peek_head(cur_muxer_upstream_msg_iter
->msgs
);
913 if (G_UNLIKELY(bt_message_get_type(msg
) ==
914 BT_MESSAGE_TYPE_STREAM_BEGINNING
)) {
915 ret
= validate_new_stream_clock_class(
916 muxer_msg_iter
, muxer_comp
,
917 bt_message_stream_beginning_borrow_stream_const(
921 * validate_new_stream_clock_class() logs
924 status
= BT_SELF_MESSAGE_ITERATOR_STATUS_ERROR
;
927 } else if (G_UNLIKELY(bt_message_get_type(msg
) ==
928 BT_MESSAGE_TYPE_MESSAGE_ITERATOR_INACTIVITY
)) {
929 const bt_clock_snapshot
*cs
;
931 cs
= bt_message_message_iterator_inactivity_borrow_default_clock_snapshot_const(
933 ret
= validate_clock_class(muxer_msg_iter
, muxer_comp
,
934 bt_clock_snapshot_borrow_clock_class_const(cs
));
936 /* validate_clock_class() logs errors */
937 status
= BT_SELF_MESSAGE_ITERATOR_STATUS_ERROR
;
942 ret
= get_msg_ts_ns(muxer_comp
, muxer_msg_iter
, msg
,
943 muxer_msg_iter
->last_returned_ts_ns
, &msg_ts_ns
);
945 /* get_msg_ts_ns() logs errors */
946 *muxer_upstream_msg_iter
= NULL
;
947 status
= BT_SELF_MESSAGE_ITERATOR_STATUS_ERROR
;
951 if (msg_ts_ns
<= youngest_ts_ns
) {
952 *muxer_upstream_msg_iter
=
953 cur_muxer_upstream_msg_iter
;
954 youngest_ts_ns
= msg_ts_ns
;
955 *ts_ns
= youngest_ts_ns
;
959 if (!*muxer_upstream_msg_iter
) {
960 status
= BT_SELF_MESSAGE_ITERATOR_STATUS_END
;
969 bt_self_message_iterator_status
validate_muxer_upstream_msg_iter(
970 struct muxer_upstream_msg_iter
*muxer_upstream_msg_iter
,
973 bt_self_message_iterator_status status
=
974 BT_SELF_MESSAGE_ITERATOR_STATUS_OK
;
976 BT_LOGD("Validating muxer's upstream message iterator wrapper: "
977 "muxer-upstream-msg-iter-wrap-addr=%p",
978 muxer_upstream_msg_iter
);
980 if (muxer_upstream_msg_iter
->msgs
->length
> 0 ||
981 !muxer_upstream_msg_iter
->msg_iter
) {
982 BT_LOGD("Already valid or not considered: "
983 "queue-len=%u, upstream-msg-iter-addr=%p",
984 muxer_upstream_msg_iter
->msgs
->length
,
985 muxer_upstream_msg_iter
->msg_iter
);
989 /* muxer_upstream_msg_iter_next() logs details/errors */
990 status
= muxer_upstream_msg_iter_next(muxer_upstream_msg_iter
,
998 bt_self_message_iterator_status
validate_muxer_upstream_msg_iters(
999 struct muxer_msg_iter
*muxer_msg_iter
)
1001 bt_self_message_iterator_status status
=
1002 BT_SELF_MESSAGE_ITERATOR_STATUS_OK
;
1005 BT_LOGD("Validating muxer's upstream message iterator wrappers: "
1006 "muxer-msg-iter-addr=%p", muxer_msg_iter
);
1008 for (i
= 0; i
< muxer_msg_iter
->active_muxer_upstream_msg_iters
->len
;
1010 bool is_ended
= false;
1011 struct muxer_upstream_msg_iter
*muxer_upstream_msg_iter
=
1013 muxer_msg_iter
->active_muxer_upstream_msg_iters
,
1016 status
= validate_muxer_upstream_msg_iter(
1017 muxer_upstream_msg_iter
, &is_ended
);
1018 if (status
!= BT_SELF_MESSAGE_ITERATOR_STATUS_OK
) {
1020 BT_LOGE("Cannot validate muxer's upstream message iterator wrapper: "
1021 "muxer-msg-iter-addr=%p, "
1022 "muxer-upstream-msg-iter-wrap-addr=%p",
1024 muxer_upstream_msg_iter
);
1026 BT_LOGD("Cannot validate muxer's upstream message iterator wrapper: "
1027 "muxer-msg-iter-addr=%p, "
1028 "muxer-upstream-msg-iter-wrap-addr=%p",
1030 muxer_upstream_msg_iter
);
1037 * Move this muxer upstream message iterator to the
1038 * array of ended iterators if it's ended.
1040 if (G_UNLIKELY(is_ended
)) {
1041 BT_LOGD("Muxer's upstream message iterator wrapper: ended or canceled: "
1042 "muxer-msg-iter-addr=%p, "
1043 "muxer-upstream-msg-iter-wrap-addr=%p",
1044 muxer_msg_iter
, muxer_upstream_msg_iter
);
1046 muxer_msg_iter
->ended_muxer_upstream_msg_iters
,
1047 muxer_upstream_msg_iter
);
1048 muxer_msg_iter
->active_muxer_upstream_msg_iters
->pdata
[i
] = NULL
;
1051 * Use g_ptr_array_remove_fast() because the
1052 * order of those elements is not important.
1054 g_ptr_array_remove_index_fast(
1055 muxer_msg_iter
->active_muxer_upstream_msg_iters
,
1066 bt_self_message_iterator_status
muxer_msg_iter_do_next_one(
1067 struct muxer_comp
*muxer_comp
,
1068 struct muxer_msg_iter
*muxer_msg_iter
,
1069 const bt_message
**msg
)
1071 bt_self_message_iterator_status status
;
1072 struct muxer_upstream_msg_iter
*muxer_upstream_msg_iter
= NULL
;
1073 int64_t next_return_ts
;
1075 status
= validate_muxer_upstream_msg_iters(muxer_msg_iter
);
1076 if (status
!= BT_SELF_MESSAGE_ITERATOR_STATUS_OK
) {
1077 /* validate_muxer_upstream_msg_iters() logs details */
1082 * At this point we know that all the existing upstream
1083 * message iterators are valid. We can find the one,
1084 * amongst those, of which the current message is the
1087 status
= muxer_msg_iter_youngest_upstream_msg_iter(muxer_comp
,
1088 muxer_msg_iter
, &muxer_upstream_msg_iter
,
1090 if (status
< 0 || status
== BT_SELF_MESSAGE_ITERATOR_STATUS_END
) {
1092 BT_LOGE("Cannot find the youngest upstream message iterator wrapper: "
1094 bt_common_self_message_iterator_status_string(status
));
1096 BT_LOGD("Cannot find the youngest upstream message iterator wrapper: "
1098 bt_common_self_message_iterator_status_string(status
));
1104 if (next_return_ts
< muxer_msg_iter
->last_returned_ts_ns
) {
1105 BT_LOGE("Youngest upstream message iterator wrapper's timestamp is less than muxer's message iterator's last returned timestamp: "
1106 "muxer-msg-iter-addr=%p, ts=%" PRId64
", "
1107 "last-returned-ts=%" PRId64
,
1108 muxer_msg_iter
, next_return_ts
,
1109 muxer_msg_iter
->last_returned_ts_ns
);
1110 status
= BT_SELF_MESSAGE_ITERATOR_STATUS_ERROR
;
1114 BT_LOGD("Found youngest upstream message iterator wrapper: "
1115 "muxer-msg-iter-addr=%p, "
1116 "muxer-upstream-msg-iter-wrap-addr=%p, "
1118 muxer_msg_iter
, muxer_upstream_msg_iter
, next_return_ts
);
1119 BT_ASSERT(status
== BT_SELF_MESSAGE_ITERATOR_STATUS_OK
);
1120 BT_ASSERT(muxer_upstream_msg_iter
);
1123 * Consume from the queue's head: other side
1124 * (muxer_upstream_msg_iter_next()) writes to the tail.
1126 *msg
= g_queue_pop_head(muxer_upstream_msg_iter
->msgs
);
1128 muxer_msg_iter
->last_returned_ts_ns
= next_return_ts
;
1135 bt_self_message_iterator_status
muxer_msg_iter_do_next(
1136 struct muxer_comp
*muxer_comp
,
1137 struct muxer_msg_iter
*muxer_msg_iter
,
1138 bt_message_array_const msgs
, uint64_t capacity
,
1141 bt_self_message_iterator_status status
=
1142 BT_SELF_MESSAGE_ITERATOR_STATUS_OK
;
1145 while (i
< capacity
&& status
== BT_SELF_MESSAGE_ITERATOR_STATUS_OK
) {
1146 status
= muxer_msg_iter_do_next_one(muxer_comp
,
1147 muxer_msg_iter
, &msgs
[i
]);
1148 if (status
== BT_SELF_MESSAGE_ITERATOR_STATUS_OK
) {
1155 * Even if muxer_msg_iter_do_next_one() returned
1156 * something else than
1157 * BT_MESSAGE_ITERATOR_STATUS_OK, we accumulated
1158 * message objects in the output message
1159 * array, so we need to return
1160 * BT_MESSAGE_ITERATOR_STATUS_OK so that they are
1161 * transfered to downstream. This other status occurs
1162 * again the next time muxer_msg_iter_do_next() is
1163 * called, possibly without any accumulated
1164 * message, in which case we'll return it.
1167 status
= BT_SELF_MESSAGE_ITERATOR_STATUS_OK
;
1174 void destroy_muxer_msg_iter(struct muxer_msg_iter
*muxer_msg_iter
)
1176 if (!muxer_msg_iter
) {
1180 BT_LOGD("Destroying muxer component's message iterator: "
1181 "muxer-msg-iter-addr=%p", muxer_msg_iter
);
1183 if (muxer_msg_iter
->active_muxer_upstream_msg_iters
) {
1184 BT_LOGD_STR("Destroying muxer's active upstream message iterator wrappers.");
1186 muxer_msg_iter
->active_muxer_upstream_msg_iters
, TRUE
);
1189 if (muxer_msg_iter
->ended_muxer_upstream_msg_iters
) {
1190 BT_LOGD_STR("Destroying muxer's ended upstream message iterator wrappers.");
1192 muxer_msg_iter
->ended_muxer_upstream_msg_iters
, TRUE
);
1195 g_free(muxer_msg_iter
);
1199 int muxer_msg_iter_init_upstream_iterators(struct muxer_comp
*muxer_comp
,
1200 struct muxer_msg_iter
*muxer_msg_iter
)
1206 count
= bt_component_filter_get_input_port_count(
1207 bt_self_component_filter_as_component_filter(
1208 muxer_comp
->self_comp
));
1210 BT_LOGD("No input port to initialize for muxer component's message iterator: "
1211 "muxer-comp-addr=%p, muxer-msg-iter-addr=%p",
1212 muxer_comp
, muxer_msg_iter
);
1216 for (i
= 0; i
< count
; i
++) {
1217 bt_self_component_port_input_message_iterator
*upstream_msg_iter
;
1218 bt_self_component_port_input
*self_port
=
1219 bt_self_component_filter_borrow_input_port_by_index(
1220 muxer_comp
->self_comp
, i
);
1221 const bt_port
*port
;
1223 BT_ASSERT(self_port
);
1224 port
= bt_self_component_port_as_port(
1225 bt_self_component_port_input_as_self_component_port(
1229 if (!bt_port_is_connected(port
)) {
1230 /* Skip non-connected port */
1234 upstream_msg_iter
= create_msg_iter_on_input_port(self_port
);
1235 if (!upstream_msg_iter
) {
1236 /* create_msg_iter_on_input_port() logs errors */
1237 BT_ASSERT(!upstream_msg_iter
);
1242 ret
= muxer_msg_iter_add_upstream_msg_iter(muxer_msg_iter
,
1244 bt_self_component_port_input_message_iterator_put_ref(
1247 /* muxer_msg_iter_add_upstream_msg_iter() logs errors */
1257 bt_self_message_iterator_status
muxer_msg_iter_init(
1258 bt_self_message_iterator
*self_msg_iter
,
1259 bt_self_component_filter
*self_comp
,
1260 bt_self_component_port_output
*port
)
1262 struct muxer_comp
*muxer_comp
= NULL
;
1263 struct muxer_msg_iter
*muxer_msg_iter
= NULL
;
1264 bt_self_message_iterator_status status
=
1265 BT_SELF_MESSAGE_ITERATOR_STATUS_OK
;
1268 muxer_comp
= bt_self_component_get_data(
1269 bt_self_component_filter_as_self_component(self_comp
));
1270 BT_ASSERT(muxer_comp
);
1271 BT_LOGD("Initializing muxer component's message iterator: "
1272 "comp-addr=%p, muxer-comp-addr=%p, msg-iter-addr=%p",
1273 self_comp
, muxer_comp
, self_msg_iter
);
1275 if (muxer_comp
->initializing_muxer_msg_iter
) {
1277 * Weird, unhandled situation detected: downstream
1278 * creates a muxer message iterator while creating
1279 * another muxer message iterator (same component).
1281 BT_LOGE("Recursive initialization of muxer component's message iterator: "
1282 "comp-addr=%p, muxer-comp-addr=%p, msg-iter-addr=%p",
1283 self_comp
, muxer_comp
, self_msg_iter
);
1287 muxer_comp
->initializing_muxer_msg_iter
= true;
1288 muxer_msg_iter
= g_new0(struct muxer_msg_iter
, 1);
1289 if (!muxer_msg_iter
) {
1290 BT_LOGE_STR("Failed to allocate one muxer component's message iterator.");
1294 muxer_msg_iter
->last_returned_ts_ns
= INT64_MIN
;
1295 muxer_msg_iter
->active_muxer_upstream_msg_iters
=
1296 g_ptr_array_new_with_free_func(
1297 (GDestroyNotify
) destroy_muxer_upstream_msg_iter
);
1298 if (!muxer_msg_iter
->active_muxer_upstream_msg_iters
) {
1299 BT_LOGE_STR("Failed to allocate a GPtrArray.");
1303 muxer_msg_iter
->ended_muxer_upstream_msg_iters
=
1304 g_ptr_array_new_with_free_func(
1305 (GDestroyNotify
) destroy_muxer_upstream_msg_iter
);
1306 if (!muxer_msg_iter
->ended_muxer_upstream_msg_iters
) {
1307 BT_LOGE_STR("Failed to allocate a GPtrArray.");
1311 ret
= muxer_msg_iter_init_upstream_iterators(muxer_comp
,
1314 BT_LOGE("Cannot initialize connected input ports for muxer component's message iterator: "
1315 "comp-addr=%p, muxer-comp-addr=%p, "
1316 "muxer-msg-iter-addr=%p, msg-iter-addr=%p, ret=%d",
1317 self_comp
, muxer_comp
, muxer_msg_iter
,
1318 self_msg_iter
, ret
);
1322 bt_self_message_iterator_set_data(self_msg_iter
, muxer_msg_iter
);
1323 BT_LOGD("Initialized muxer component's message iterator: "
1324 "comp-addr=%p, muxer-comp-addr=%p, muxer-msg-iter-addr=%p, "
1326 self_comp
, muxer_comp
, muxer_msg_iter
, self_msg_iter
);
1330 destroy_muxer_msg_iter(muxer_msg_iter
);
1331 bt_self_message_iterator_set_data(self_msg_iter
, NULL
);
1332 status
= BT_SELF_MESSAGE_ITERATOR_STATUS_ERROR
;
1335 muxer_comp
->initializing_muxer_msg_iter
= false;
1340 void muxer_msg_iter_finalize(bt_self_message_iterator
*self_msg_iter
)
1342 struct muxer_msg_iter
*muxer_msg_iter
=
1343 bt_self_message_iterator_get_data(self_msg_iter
);
1344 bt_self_component
*self_comp
= NULL
;
1345 struct muxer_comp
*muxer_comp
= NULL
;
1347 self_comp
= bt_self_message_iterator_borrow_component(
1349 BT_ASSERT(self_comp
);
1350 muxer_comp
= bt_self_component_get_data(self_comp
);
1351 BT_LOGD("Finalizing muxer component's message iterator: "
1352 "comp-addr=%p, muxer-comp-addr=%p, muxer-msg-iter-addr=%p, "
1354 self_comp
, muxer_comp
, muxer_msg_iter
, self_msg_iter
);
1356 if (muxer_msg_iter
) {
1357 destroy_muxer_msg_iter(muxer_msg_iter
);
1362 bt_self_message_iterator_status
muxer_msg_iter_next(
1363 bt_self_message_iterator
*self_msg_iter
,
1364 bt_message_array_const msgs
, uint64_t capacity
,
1367 bt_self_message_iterator_status status
;
1368 struct muxer_msg_iter
*muxer_msg_iter
=
1369 bt_self_message_iterator_get_data(self_msg_iter
);
1370 bt_self_component
*self_comp
= NULL
;
1371 struct muxer_comp
*muxer_comp
= NULL
;
1373 BT_ASSERT(muxer_msg_iter
);
1374 self_comp
= bt_self_message_iterator_borrow_component(
1376 BT_ASSERT(self_comp
);
1377 muxer_comp
= bt_self_component_get_data(self_comp
);
1378 BT_ASSERT(muxer_comp
);
1379 BT_LOGV("Muxer component's message iterator's \"next\" method called: "
1380 "comp-addr=%p, muxer-comp-addr=%p, muxer-msg-iter-addr=%p, "
1382 self_comp
, muxer_comp
, muxer_msg_iter
, self_msg_iter
);
1384 status
= muxer_msg_iter_do_next(muxer_comp
, muxer_msg_iter
,
1385 msgs
, capacity
, count
);
1387 BT_LOGE("Cannot get next message: "
1388 "comp-addr=%p, muxer-comp-addr=%p, muxer-msg-iter-addr=%p, "
1389 "msg-iter-addr=%p, status=%s",
1390 self_comp
, muxer_comp
, muxer_msg_iter
, self_msg_iter
,
1391 bt_common_self_message_iterator_status_string(status
));
1393 BT_LOGV("Returning from muxer component's message iterator's \"next\" method: "
1395 bt_common_self_message_iterator_status_string(status
));
1402 bt_self_component_status
muxer_input_port_connected(
1403 bt_self_component_filter
*self_comp
,
1404 bt_self_component_port_input
*self_port
,
1405 const bt_port_output
*other_port
)
1407 bt_self_component_status status
;
1409 status
= add_available_input_port(self_comp
);
1412 * Only way to report an error later since this
1413 * method does not return anything.
1415 BT_LOGE("Cannot add one muxer component's input port: "
1417 bt_self_component_status_string(status
));
1426 bt_bool
muxer_upstream_msg_iters_can_all_seek_beginning(
1427 GPtrArray
*muxer_upstream_msg_iters
)
1430 bt_bool ret
= BT_TRUE
;
1432 for (i
= 0; i
< muxer_upstream_msg_iters
->len
; i
++) {
1433 struct muxer_upstream_msg_iter
*upstream_msg_iter
=
1434 muxer_upstream_msg_iters
->pdata
[i
];
1436 if (!bt_self_component_port_input_message_iterator_can_seek_beginning(
1437 upstream_msg_iter
->msg_iter
)) {
1448 bt_bool
muxer_msg_iter_can_seek_beginning(
1449 bt_self_message_iterator
*self_msg_iter
)
1451 struct muxer_msg_iter
*muxer_msg_iter
=
1452 bt_self_message_iterator_get_data(self_msg_iter
);
1453 bt_bool ret
= BT_TRUE
;
1455 if (!muxer_upstream_msg_iters_can_all_seek_beginning(
1456 muxer_msg_iter
->active_muxer_upstream_msg_iters
)) {
1461 if (!muxer_upstream_msg_iters_can_all_seek_beginning(
1462 muxer_msg_iter
->ended_muxer_upstream_msg_iters
)) {
1472 bt_self_message_iterator_status
muxer_msg_iter_seek_beginning(
1473 bt_self_message_iterator
*self_msg_iter
)
1475 struct muxer_msg_iter
*muxer_msg_iter
=
1476 bt_self_message_iterator_get_data(self_msg_iter
);
1477 bt_message_iterator_status status
= BT_MESSAGE_ITERATOR_STATUS_OK
;
1480 /* Seek all ended upstream iterators first */
1481 for (i
= 0; i
< muxer_msg_iter
->ended_muxer_upstream_msg_iters
->len
;
1483 struct muxer_upstream_msg_iter
*upstream_msg_iter
=
1484 muxer_msg_iter
->ended_muxer_upstream_msg_iters
->pdata
[i
];
1486 status
= bt_self_component_port_input_message_iterator_seek_beginning(
1487 upstream_msg_iter
->msg_iter
);
1488 if (status
!= BT_MESSAGE_ITERATOR_STATUS_OK
) {
1492 empty_message_queue(upstream_msg_iter
);
1495 /* Seek all previously active upstream iterators */
1496 for (i
= 0; i
< muxer_msg_iter
->active_muxer_upstream_msg_iters
->len
;
1498 struct muxer_upstream_msg_iter
*upstream_msg_iter
=
1499 muxer_msg_iter
->active_muxer_upstream_msg_iters
->pdata
[i
];
1501 status
= bt_self_component_port_input_message_iterator_seek_beginning(
1502 upstream_msg_iter
->msg_iter
);
1503 if (status
!= BT_MESSAGE_ITERATOR_STATUS_OK
) {
1507 empty_message_queue(upstream_msg_iter
);
1510 /* Make them all active */
1511 for (i
= 0; i
< muxer_msg_iter
->ended_muxer_upstream_msg_iters
->len
;
1513 struct muxer_upstream_msg_iter
*upstream_msg_iter
=
1514 muxer_msg_iter
->ended_muxer_upstream_msg_iters
->pdata
[i
];
1516 g_ptr_array_add(muxer_msg_iter
->active_muxer_upstream_msg_iters
,
1518 muxer_msg_iter
->ended_muxer_upstream_msg_iters
->pdata
[i
] = NULL
;
1521 g_ptr_array_remove_range(muxer_msg_iter
->ended_muxer_upstream_msg_iters
,
1522 0, muxer_msg_iter
->ended_muxer_upstream_msg_iters
->len
);
1523 muxer_msg_iter
->last_returned_ts_ns
= INT64_MIN
;
1524 muxer_msg_iter
->clock_class_expectation
=
1525 MUXER_MSG_ITER_CLOCK_CLASS_EXPECTATION_ANY
;
1528 return (bt_self_message_iterator_status
) status
;