2 * Copyright 2017-2018 Philippe Proulx <pproulx@efficios.com>
3 * Copyright 2015 Jérémie Galarneau <jeremie.galarneau@efficios.com>
5 * Permission is hereby granted, free of charge, to any person obtaining a copy
6 * of this software and associated documentation files (the "Software"), to deal
7 * in the Software without restriction, including without limitation the rights
8 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 * copies of the Software, and to permit persons to whom the Software is
10 * furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24 #define BT_LOG_TAG "LIB/MSG-ITER"
25 #include "lib/logging.h"
27 #include "compat/compiler.h"
28 #include "compat/glib.h"
29 #include "lib/trace-ir/clock-class.h"
30 #include "lib/trace-ir/clock-snapshot.h"
31 #include <babeltrace2/trace-ir/field.h>
32 #include <babeltrace2/trace-ir/event-const.h>
33 #include "lib/trace-ir/event.h"
34 #include <babeltrace2/trace-ir/packet-const.h>
35 #include "lib/trace-ir/packet.h"
36 #include "lib/trace-ir/stream.h"
37 #include <babeltrace2/trace-ir/clock-class-const.h>
38 #include <babeltrace2/trace-ir/stream-class-const.h>
39 #include <babeltrace2/trace-ir/stream-const.h>
40 #include <babeltrace2/graph/connection-const.h>
41 #include <babeltrace2/graph/component-const.h>
42 #include <babeltrace2/graph/component-sink-const.h>
43 #include <babeltrace2/graph/message-const.h>
44 #include <babeltrace2/graph/message-iterator.h>
45 #include <babeltrace2/graph/self-component-port-input-message-iterator.h>
46 #include <babeltrace2/graph/port-output-message-iterator.h>
47 #include <babeltrace2/graph/message-event-const.h>
48 #include <babeltrace2/graph/message-message-iterator-inactivity-const.h>
49 #include <babeltrace2/graph/message-packet-beginning.h>
50 #include <babeltrace2/graph/message-packet-beginning-const.h>
51 #include <babeltrace2/graph/message-packet-end-const.h>
52 #include <babeltrace2/graph/message-stream-beginning.h>
53 #include <babeltrace2/graph/message-stream-beginning-const.h>
54 #include <babeltrace2/graph/message-stream-end-const.h>
55 #include <babeltrace2/graph/port-const.h>
56 #include <babeltrace2/graph/graph.h>
57 #include <babeltrace2/graph/graph-const.h>
58 #include <babeltrace2/types.h>
59 #include "common/assert.h"
60 #include "lib/assert-pre.h"
61 #include "lib/assert-post.h"
66 #include "component-class.h"
67 #include "component-class-sink-colander.h"
68 #include "component.h"
69 #include "component-sink.h"
70 #include "component-source.h"
71 #include "connection.h"
73 #include "message/discarded-items.h"
74 #include "message/event.h"
75 #include "message/iterator.h"
76 #include "message/message.h"
77 #include "message/message-iterator-inactivity.h"
78 #include "message/stream.h"
79 #include "message/packet.h"
80 #include "lib/func-status.h"
83 * TODO: Use graph's state (number of active iterators, etc.) and
84 * possibly system specifications to make a better guess than this.
86 #define MSG_BATCH_SIZE 15
88 #define BT_ASSERT_PRE_ITER_HAS_STATE_TO_SEEK(_iter) \
89 BT_ASSERT_PRE((_iter)->state == BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_STATE_ACTIVE || \
90 (_iter)->state == BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_STATE_ENDED || \
91 (_iter)->state == BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_STATE_LAST_SEEKING_RETURNED_AGAIN || \
92 (_iter)->state == BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_STATE_LAST_SEEKING_RETURNED_ERROR, \
93 "Message iterator is in the wrong state: %!+i", _iter)
96 void set_self_comp_port_input_msg_iterator_state(
97 struct bt_self_component_port_input_message_iterator
*iterator
,
98 enum bt_self_component_port_input_message_iterator_state state
)
101 BT_LIB_LOGD("Updating message iterator's state: new-state=%s",
102 bt_self_component_port_input_message_iterator_state_string(state
));
103 iterator
->state
= state
;
107 void destroy_base_message_iterator(struct bt_object
*obj
)
109 struct bt_message_iterator
*iterator
= (void *) obj
;
113 if (iterator
->msgs
) {
114 g_ptr_array_free(iterator
->msgs
, TRUE
);
115 iterator
->msgs
= NULL
;
122 void bt_self_component_port_input_message_iterator_destroy(struct bt_object
*obj
)
124 struct bt_self_component_port_input_message_iterator
*iterator
;
129 * The message iterator's reference count is 0 if we're
130 * here. Increment it to avoid a double-destroy (possibly
131 * infinitely recursive). This could happen for example if the
132 * message iterator's finalization function does
133 * bt_object_get_ref() (or anything that causes
134 * bt_object_get_ref() to be called) on itself (ref. count goes
135 * from 0 to 1), and then bt_object_put_ref(): the reference
136 * count would go from 1 to 0 again and this function would be
140 iterator
= (void *) obj
;
141 BT_LIB_LOGI("Destroying self component input port message iterator object: "
143 bt_self_component_port_input_message_iterator_try_finalize(iterator
);
145 if (iterator
->connection
) {
147 * Remove ourself from the originating connection so
148 * that it does not try to finalize a dangling pointer
151 bt_connection_remove_iterator(iterator
->connection
, iterator
);
152 iterator
->connection
= NULL
;
155 if (iterator
->auto_seek
.msgs
) {
156 while (!g_queue_is_empty(iterator
->auto_seek
.msgs
)) {
157 bt_object_put_no_null_check(
158 g_queue_pop_tail(iterator
->auto_seek
.msgs
));
161 g_queue_free(iterator
->auto_seek
.msgs
);
162 iterator
->auto_seek
.msgs
= NULL
;
165 if (iterator
->upstream_msg_iters
) {
167 * At this point the message iterator is finalized, so
168 * it's detached from any upstream message iterator.
170 BT_ASSERT(iterator
->upstream_msg_iters
->len
== 0);
171 g_ptr_array_free(iterator
->upstream_msg_iters
, TRUE
);
172 iterator
->upstream_msg_iters
= NULL
;
175 destroy_base_message_iterator(obj
);
179 void bt_self_component_port_input_message_iterator_try_finalize(
180 struct bt_self_component_port_input_message_iterator
*iterator
)
183 typedef void (*method_t
)(void *);
185 struct bt_component_class
*comp_class
= NULL
;
186 method_t method
= NULL
;
190 switch (iterator
->state
) {
191 case BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_STATE_NON_INITIALIZED
:
192 /* Skip user finalization if user initialization failed */
193 BT_LIB_LOGD("Not finalizing non-initialized message iterator: "
196 case BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_STATE_FINALIZED
:
197 /* Already finalized */
198 BT_LIB_LOGD("Not finalizing message iterator: already finalized: "
201 case BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_STATE_FINALIZING
:
203 BT_LIB_LOGF("Message iterator is already being finalized: "
210 BT_LIB_LOGD("Finalizing message iterator: %!+i", iterator
);
211 set_self_comp_port_input_msg_iterator_state(iterator
,
212 BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_STATE_FINALIZING
);
213 BT_ASSERT(iterator
->upstream_component
);
214 comp_class
= iterator
->upstream_component
->class;
216 /* Call user-defined destroy method */
217 switch (comp_class
->type
) {
218 case BT_COMPONENT_CLASS_TYPE_SOURCE
:
220 struct bt_component_class_source
*src_comp_cls
=
223 method
= (method_t
) src_comp_cls
->methods
.msg_iter_finalize
;
226 case BT_COMPONENT_CLASS_TYPE_FILTER
:
228 struct bt_component_class_filter
*flt_comp_cls
=
231 method
= (method_t
) flt_comp_cls
->methods
.msg_iter_finalize
;
240 BT_LIB_LOGD("Calling user's finalization method: %!+i",
245 /* Detach upstream message iterators */
246 for (i
= 0; i
< iterator
->upstream_msg_iters
->len
; i
++) {
247 struct bt_self_component_port_input_message_iterator
*upstream_msg_iter
=
248 iterator
->upstream_msg_iters
->pdata
[i
];
250 upstream_msg_iter
->downstream_msg_iter
= NULL
;
253 g_ptr_array_set_size(iterator
->upstream_msg_iters
, 0);
255 /* Detach downstream message iterator */
256 if (iterator
->downstream_msg_iter
) {
259 BT_ASSERT(iterator
->downstream_msg_iter
->upstream_msg_iters
);
260 existed
= g_ptr_array_remove_fast(
261 iterator
->downstream_msg_iter
->upstream_msg_iters
,
266 iterator
->upstream_component
= NULL
;
267 iterator
->upstream_port
= NULL
;
268 set_self_comp_port_input_msg_iterator_state(iterator
,
269 BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_STATE_FINALIZED
);
270 BT_LIB_LOGD("Finalized message iterator: %!+i", iterator
);
277 void bt_self_component_port_input_message_iterator_set_connection(
278 struct bt_self_component_port_input_message_iterator
*iterator
,
279 struct bt_connection
*connection
)
282 iterator
->connection
= connection
;
283 BT_LIB_LOGI("Set message iterator's connection: "
284 "%![iter-]+i, %![conn-]+x", iterator
, connection
);
288 int init_message_iterator(struct bt_message_iterator
*iterator
,
289 enum bt_message_iterator_type type
,
290 bt_object_release_func destroy
)
294 bt_object_init_shared(&iterator
->base
, destroy
);
295 iterator
->type
= type
;
296 iterator
->msgs
= g_ptr_array_new();
297 if (!iterator
->msgs
) {
298 BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate a GPtrArray.");
303 g_ptr_array_set_size(iterator
->msgs
, MSG_BATCH_SIZE
);
310 bt_bool
can_seek_ns_from_origin_true(
311 struct bt_self_component_port_input_message_iterator
*iterator
,
312 int64_t ns_from_origin
)
318 bt_bool
can_seek_beginning_true(
319 struct bt_self_component_port_input_message_iterator
*iterator
)
325 struct bt_self_component_port_input_message_iterator
*
326 create_self_component_input_port_message_iterator(
327 struct bt_self_message_iterator
*self_downstream_msg_iter
,
328 struct bt_self_component_port_input
*self_port
)
330 typedef enum bt_component_class_message_iterator_init_method_status (*init_method_t
)(
331 void *, void *, void *);
334 init_method_t init_method
= NULL
;
335 struct bt_self_component_port_input_message_iterator
*iterator
=
337 struct bt_self_component_port_input_message_iterator
*downstream_msg_iter
=
338 (void *) self_downstream_msg_iter
;
339 struct bt_port
*port
= (void *) self_port
;
340 struct bt_port
*upstream_port
;
341 struct bt_component
*comp
;
342 struct bt_component
*upstream_comp
;
343 struct bt_component_class
*upstream_comp_cls
;
345 BT_ASSERT_PRE_NON_NULL(port
, "Input port");
346 comp
= bt_port_borrow_component_inline(port
);
347 BT_ASSERT_PRE(bt_port_is_connected(port
),
348 "Input port is not connected: %![port-]+p", port
);
349 BT_ASSERT_PRE(comp
, "Input port is not part of a component: %![port-]+p",
351 BT_ASSERT(port
->connection
);
352 upstream_port
= port
->connection
->upstream_port
;
353 BT_ASSERT(upstream_port
);
354 upstream_comp
= bt_port_borrow_component_inline(upstream_port
);
355 BT_ASSERT(upstream_comp
);
357 bt_component_borrow_graph(upstream_comp
)->config_state
==
358 BT_GRAPH_CONFIGURATION_STATE_PARTIALLY_CONFIGURED
||
359 bt_component_borrow_graph(upstream_comp
)->config_state
==
360 BT_GRAPH_CONFIGURATION_STATE_CONFIGURED
,
361 "Graph is not configured: %!+g",
362 bt_component_borrow_graph(upstream_comp
));
363 upstream_comp_cls
= upstream_comp
->class;
364 BT_ASSERT(upstream_comp
->class->type
==
365 BT_COMPONENT_CLASS_TYPE_SOURCE
||
366 upstream_comp
->class->type
==
367 BT_COMPONENT_CLASS_TYPE_FILTER
);
368 BT_LIB_LOGI("Creating message iterator on self component input port: "
369 "%![up-comp-]+c, %![up-port-]+p", upstream_comp
, upstream_port
);
371 struct bt_self_component_port_input_message_iterator
, 1);
373 BT_LIB_LOGE_APPEND_CAUSE(
374 "Failed to allocate one self component input port "
375 "message iterator.");
379 ret
= init_message_iterator((void *) iterator
,
380 BT_MESSAGE_ITERATOR_TYPE_SELF_COMPONENT_PORT_INPUT
,
381 bt_self_component_port_input_message_iterator_destroy
);
383 /* init_message_iterator() logs errors */
387 iterator
->last_ns_from_origin
= INT64_MIN
;
388 iterator
->auto_seek
.msgs
= g_queue_new();
389 if (!iterator
->auto_seek
.msgs
) {
390 BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate a GQueue.");
394 iterator
->upstream_msg_iters
= g_ptr_array_new();
395 if (!iterator
->upstream_msg_iters
) {
396 BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate a GPtrArray.");
400 iterator
->upstream_component
= upstream_comp
;
401 iterator
->upstream_port
= upstream_port
;
402 iterator
->connection
= iterator
->upstream_port
->connection
;
403 iterator
->graph
= bt_component_borrow_graph(upstream_comp
);
404 set_self_comp_port_input_msg_iterator_state(iterator
,
405 BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_STATE_NON_INITIALIZED
);
407 switch (iterator
->upstream_component
->class->type
) {
408 case BT_COMPONENT_CLASS_TYPE_SOURCE
:
410 struct bt_component_class_source
*src_comp_cls
=
411 (void *) iterator
->upstream_component
->class;
413 iterator
->methods
.next
=
414 (bt_self_component_port_input_message_iterator_next_method
)
415 src_comp_cls
->methods
.msg_iter_next
;
416 iterator
->methods
.seek_ns_from_origin
=
417 (bt_self_component_port_input_message_iterator_seek_ns_from_origin_method
)
418 src_comp_cls
->methods
.msg_iter_seek_ns_from_origin
;
419 iterator
->methods
.seek_beginning
=
420 (bt_self_component_port_input_message_iterator_seek_beginning_method
)
421 src_comp_cls
->methods
.msg_iter_seek_beginning
;
422 iterator
->methods
.can_seek_ns_from_origin
=
423 (bt_self_component_port_input_message_iterator_can_seek_ns_from_origin_method
)
424 src_comp_cls
->methods
.msg_iter_can_seek_ns_from_origin
;
425 iterator
->methods
.can_seek_beginning
=
426 (bt_self_component_port_input_message_iterator_can_seek_beginning_method
)
427 src_comp_cls
->methods
.msg_iter_can_seek_beginning
;
430 case BT_COMPONENT_CLASS_TYPE_FILTER
:
432 struct bt_component_class_filter
*flt_comp_cls
=
433 (void *) iterator
->upstream_component
->class;
435 iterator
->methods
.next
=
436 (bt_self_component_port_input_message_iterator_next_method
)
437 flt_comp_cls
->methods
.msg_iter_next
;
438 iterator
->methods
.seek_ns_from_origin
=
439 (bt_self_component_port_input_message_iterator_seek_ns_from_origin_method
)
440 flt_comp_cls
->methods
.msg_iter_seek_ns_from_origin
;
441 iterator
->methods
.seek_beginning
=
442 (bt_self_component_port_input_message_iterator_seek_beginning_method
)
443 flt_comp_cls
->methods
.msg_iter_seek_beginning
;
444 iterator
->methods
.can_seek_ns_from_origin
=
445 (bt_self_component_port_input_message_iterator_can_seek_ns_from_origin_method
)
446 flt_comp_cls
->methods
.msg_iter_can_seek_ns_from_origin
;
447 iterator
->methods
.can_seek_beginning
=
448 (bt_self_component_port_input_message_iterator_can_seek_beginning_method
)
449 flt_comp_cls
->methods
.msg_iter_can_seek_beginning
;
456 if (iterator
->methods
.seek_ns_from_origin
&&
457 !iterator
->methods
.can_seek_ns_from_origin
) {
458 iterator
->methods
.can_seek_ns_from_origin
=
459 (bt_self_component_port_input_message_iterator_can_seek_ns_from_origin_method
)
460 can_seek_ns_from_origin_true
;
463 if (iterator
->methods
.seek_beginning
&&
464 !iterator
->methods
.can_seek_beginning
) {
465 iterator
->methods
.can_seek_beginning
=
466 (bt_self_component_port_input_message_iterator_seek_beginning_method
)
467 can_seek_beginning_true
;
470 switch (upstream_comp_cls
->type
) {
471 case BT_COMPONENT_CLASS_TYPE_SOURCE
:
473 struct bt_component_class_source
*src_comp_cls
=
474 (void *) upstream_comp_cls
;
477 (init_method_t
) src_comp_cls
->methods
.msg_iter_init
;
480 case BT_COMPONENT_CLASS_TYPE_FILTER
:
482 struct bt_component_class_filter
*flt_comp_cls
=
483 (void *) upstream_comp_cls
;
486 (init_method_t
) flt_comp_cls
->methods
.msg_iter_init
;
495 enum bt_component_class_message_iterator_init_method_status iter_status
;
497 BT_LIB_LOGD("Calling user's initialization method: %!+i", iterator
);
498 iter_status
= init_method(iterator
, upstream_comp
,
500 BT_LOGD("User method returned: status=%s",
501 bt_common_func_status_string(iter_status
));
502 if (iter_status
!= BT_FUNC_STATUS_OK
) {
503 BT_LIB_LOGW_APPEND_CAUSE(
504 "Component input port message iterator initialization method failed: "
505 "%![iter-]+i, status=%s",
507 bt_common_func_status_string(iter_status
));
512 if (downstream_msg_iter
) {
513 /* Set this message iterator's downstream message iterator */
514 iterator
->downstream_msg_iter
= downstream_msg_iter
;
517 * Add this message iterator to the downstream message
518 * iterator's array of upstream message iterators.
520 g_ptr_array_add(downstream_msg_iter
->upstream_msg_iters
,
524 set_self_comp_port_input_msg_iterator_state(iterator
,
525 BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_STATE_ACTIVE
);
526 g_ptr_array_add(port
->connection
->iterators
, iterator
);
527 BT_LIB_LOGI("Created message iterator on self component input port: "
528 "%![up-port-]+p, %![up-comp-]+c, %![iter-]+i",
529 upstream_port
, upstream_comp
, iterator
);
533 BT_OBJECT_PUT_REF_AND_RESET(iterator
);
539 struct bt_self_component_port_input_message_iterator
*
540 bt_self_component_port_input_message_iterator_create_from_message_iterator(
541 struct bt_self_message_iterator
*self_msg_iter
,
542 struct bt_self_component_port_input
*input_port
)
544 BT_ASSERT_PRE_NON_NULL(self_msg_iter
, "Message iterator");
545 return create_self_component_input_port_message_iterator(self_msg_iter
,
549 struct bt_self_component_port_input_message_iterator
*
550 bt_self_component_port_input_message_iterator_create_from_sink_component(
551 struct bt_self_component_sink
*self_comp
,
552 struct bt_self_component_port_input
*input_port
)
554 BT_ASSERT_PRE_NON_NULL(self_comp
, "Sink component");
555 return create_self_component_input_port_message_iterator(NULL
,
559 void *bt_self_message_iterator_get_data(
560 const struct bt_self_message_iterator
*self_iterator
)
562 struct bt_self_component_port_input_message_iterator
*iterator
=
563 (void *) self_iterator
;
565 BT_ASSERT_PRE_DEV_NON_NULL(iterator
, "Message iterator");
566 return iterator
->user_data
;
569 void bt_self_message_iterator_set_data(
570 struct bt_self_message_iterator
*self_iterator
, void *data
)
572 struct bt_self_component_port_input_message_iterator
*iterator
=
573 (void *) self_iterator
;
575 BT_ASSERT_PRE_DEV_NON_NULL(iterator
, "Message iterator");
576 iterator
->user_data
= data
;
577 BT_LIB_LOGD("Set message iterator's user data: "
578 "%!+i, user-data-addr=%p", iterator
, data
);
582 * Validate that the default clock snapshot in `msg` doesn't make us go back in
586 BT_ASSERT_POST_DEV_FUNC
588 bool clock_snapshots_are_monotonic_one(
589 struct bt_self_component_port_input_message_iterator
*iterator
,
590 const bt_message
*msg
)
592 const struct bt_clock_snapshot
*clock_snapshot
= NULL
;
593 bt_message_type message_type
= bt_message_get_type(msg
);
594 int64_t ns_from_origin
;
595 enum bt_clock_snapshot_get_ns_from_origin_status clock_snapshot_status
;
598 * The default is true: if we can't figure out the clock snapshot
599 * (or there is none), assume it is fine.
603 switch (message_type
) {
604 case BT_MESSAGE_TYPE_EVENT
:
606 struct bt_message_event
*event_msg
= (struct bt_message_event
*) msg
;
607 clock_snapshot
= event_msg
->default_cs
;
610 case BT_MESSAGE_TYPE_MESSAGE_ITERATOR_INACTIVITY
:
612 struct bt_message_message_iterator_inactivity
*inactivity_msg
=
613 (struct bt_message_message_iterator_inactivity
*) msg
;
614 clock_snapshot
= inactivity_msg
->default_cs
;
617 case BT_MESSAGE_TYPE_PACKET_BEGINNING
:
618 case BT_MESSAGE_TYPE_PACKET_END
:
620 struct bt_message_packet
*packet_msg
= (struct bt_message_packet
*) msg
;
621 clock_snapshot
= packet_msg
->default_cs
;
624 case BT_MESSAGE_TYPE_STREAM_BEGINNING
:
625 case BT_MESSAGE_TYPE_STREAM_END
:
627 struct bt_message_stream
*stream_msg
= (struct bt_message_stream
*) msg
;
628 if (stream_msg
->default_cs_state
!= BT_MESSAGE_STREAM_CLOCK_SNAPSHOT_STATE_KNOWN
) {
632 clock_snapshot
= stream_msg
->default_cs
;
635 case BT_MESSAGE_TYPE_DISCARDED_EVENTS
:
636 case BT_MESSAGE_TYPE_DISCARDED_PACKETS
:
638 struct bt_message_discarded_items
*discarded_msg
=
639 (struct bt_message_discarded_items
*) msg
;
641 clock_snapshot
= discarded_msg
->default_begin_cs
;
646 if (!clock_snapshot
) {
650 clock_snapshot_status
= bt_clock_snapshot_get_ns_from_origin(clock_snapshot
, &ns_from_origin
);
651 if (clock_snapshot_status
!= BT_FUNC_STATUS_OK
) {
655 result
= ns_from_origin
>= iterator
->last_ns_from_origin
;
656 iterator
->last_ns_from_origin
= ns_from_origin
;
661 BT_ASSERT_POST_DEV_FUNC
663 bool clock_snapshots_are_monotonic(
664 struct bt_self_component_port_input_message_iterator
*iterator
,
665 bt_message_array_const msgs
, uint64_t msg_count
)
670 for (i
= 0; i
< msg_count
; i
++) {
671 if (!clock_snapshots_are_monotonic_one(iterator
, msgs
[i
])) {
684 * When a new stream begins, verify that the clock class tied to this
685 * stream is compatible with what we've seen before.
688 BT_ASSERT_POST_DEV_FUNC
690 bool clock_classes_are_compatible_one(struct bt_self_component_port_input_message_iterator
*iterator
,
691 const struct bt_message
*msg
)
693 enum bt_message_type message_type
= bt_message_get_type(msg
);
696 if (message_type
== BT_MESSAGE_TYPE_STREAM_BEGINNING
) {
697 const struct bt_message_stream
*stream_msg
= (struct bt_message_stream
*) msg
;
698 const struct bt_clock_class
*clock_class
= stream_msg
->stream
->class->default_clock_class
;
699 bt_uuid clock_class_uuid
= NULL
;
702 clock_class_uuid
= bt_clock_class_get_uuid(clock_class
);
705 switch (iterator
->clock_expectation
.type
) {
706 case CLOCK_EXPECTATION_UNSET
:
708 * This is the first time we see a message with a clock
709 * snapshot: record the properties of that clock, against
710 * which we'll compare the clock properties of the following
715 iterator
->clock_expectation
.type
= CLOCK_EXPECTATION_NONE
;
716 } else if (bt_clock_class_origin_is_unix_epoch(clock_class
)) {
717 iterator
->clock_expectation
.type
= CLOCK_EXPECTATION_ORIGIN_UNIX
;
718 } else if (clock_class_uuid
) {
719 iterator
->clock_expectation
.type
= CLOCK_EXPECTATION_ORIGIN_OTHER_UUID
;
720 bt_uuid_copy(iterator
->clock_expectation
.uuid
, clock_class_uuid
);
722 iterator
->clock_expectation
.type
= CLOCK_EXPECTATION_ORIGIN_OTHER_NO_UUID
;
726 case CLOCK_EXPECTATION_NONE
:
728 BT_ASSERT_POST_DEV_MSG(
729 "Expecting no clock class, got one: %![cc-]+K",
737 case CLOCK_EXPECTATION_ORIGIN_UNIX
:
739 BT_ASSERT_POST_DEV_MSG(
740 "Expecting a clock class, got none.");
745 if (!bt_clock_class_origin_is_unix_epoch(clock_class
)) {
746 BT_ASSERT_POST_DEV_MSG(
747 "Expecting a clock class with Unix epoch origin: %![cc-]+K",
754 case CLOCK_EXPECTATION_ORIGIN_OTHER_UUID
:
756 BT_ASSERT_POST_DEV_MSG(
757 "Expecting a clock class, got none.");
762 if (bt_clock_class_origin_is_unix_epoch(clock_class
)) {
763 BT_ASSERT_POST_DEV_MSG(
764 "Expecting a clock class without Unix epoch origin: %![cc-]+K",
770 if (!clock_class_uuid
) {
771 BT_ASSERT_POST_DEV_MSG(
772 "Expecting a clock class with UUID: %![cc-]+K",
778 if (bt_uuid_compare(iterator
->clock_expectation
.uuid
, clock_class_uuid
)) {
779 BT_ASSERT_POST_DEV_MSG(
780 "Expecting a clock class with UUID, got one "
781 "with a different UUID: %![cc-]+K, expected-uuid=%!u",
782 clock_class
, iterator
->clock_expectation
.uuid
);
788 case CLOCK_EXPECTATION_ORIGIN_OTHER_NO_UUID
:
790 BT_ASSERT_POST_DEV_MSG(
791 "Expecting a clock class, got none.");
796 if (bt_clock_class_origin_is_unix_epoch(clock_class
)) {
797 BT_ASSERT_POST_DEV_MSG(
798 "Expecting a clock class without Unix epoch origin: %![cc-]+K",
804 if (clock_class_uuid
) {
805 BT_ASSERT_POST_DEV_MSG(
806 "Expecting a clock class without UUID: %![cc-]+K",
821 BT_ASSERT_POST_DEV_FUNC
823 bool clock_classes_are_compatible(
824 struct bt_self_component_port_input_message_iterator
*iterator
,
825 bt_message_array_const msgs
, uint64_t msg_count
)
830 for (i
= 0; i
< msg_count
; i
++) {
831 if (!clock_classes_are_compatible_one(iterator
, msgs
[i
])) {
844 * Call the `next` method of the iterator. Do some validation on the returned
849 enum bt_component_class_message_iterator_next_method_status
850 call_iterator_next_method(
851 struct bt_self_component_port_input_message_iterator
*iterator
,
852 bt_message_array_const msgs
, uint64_t capacity
, uint64_t *user_count
)
854 enum bt_component_class_message_iterator_next_method_status status
;
856 BT_ASSERT(iterator
->methods
.next
);
857 BT_LOGD_STR("Calling user's \"next\" method.");
858 status
= iterator
->methods
.next(iterator
, msgs
, capacity
, user_count
);
859 BT_LOGD("User method returned: status=%s, msg-count=%" PRIu64
,
860 bt_common_func_status_string(status
), *user_count
);
862 if (status
== BT_FUNC_STATUS_OK
) {
863 BT_ASSERT_POST_DEV(clock_classes_are_compatible(iterator
, msgs
, *user_count
),
864 "Clocks are not compatible");
865 BT_ASSERT_POST_DEV(clock_snapshots_are_monotonic(iterator
, msgs
, *user_count
),
866 "Clock snapshots are not monotonic");
872 enum bt_message_iterator_next_status
873 bt_self_component_port_input_message_iterator_next(
874 struct bt_self_component_port_input_message_iterator
*iterator
,
875 bt_message_array_const
*msgs
, uint64_t *user_count
)
877 enum bt_message_iterator_next_status status
= BT_FUNC_STATUS_OK
;
879 BT_ASSERT_PRE_DEV_NON_NULL(iterator
, "Message iterator");
880 BT_ASSERT_PRE_DEV_NON_NULL(msgs
, "Message array (output)");
881 BT_ASSERT_PRE_DEV_NON_NULL(user_count
, "Message count (output)");
882 BT_ASSERT_PRE_DEV(iterator
->state
==
883 BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_STATE_ACTIVE
,
884 "Message iterator's \"next\" called, but "
885 "message iterator is in the wrong state: %!+i", iterator
);
886 BT_ASSERT(iterator
->upstream_component
);
887 BT_ASSERT(iterator
->upstream_component
->class);
889 bt_component_borrow_graph(iterator
->upstream_component
)->config_state
!=
890 BT_GRAPH_CONFIGURATION_STATE_CONFIGURING
,
891 "Graph is not configured: %!+g",
892 bt_component_borrow_graph(iterator
->upstream_component
));
893 BT_LIB_LOGD("Getting next self component input port "
894 "message iterator's messages: %!+i, batch-size=%u",
895 iterator
, MSG_BATCH_SIZE
);
898 * Call the user's "next" method to get the next messages
902 status
= (int) call_iterator_next_method(iterator
,
903 (void *) iterator
->base
.msgs
->pdata
, MSG_BATCH_SIZE
,
905 BT_LOGD("User method returned: status=%s, msg-count=%" PRIu64
,
906 bt_common_func_status_string(status
), *user_count
);
908 BT_LIB_LOGW_APPEND_CAUSE(
909 "Component input port message iterator's \"next\" method failed: "
910 "%![iter-]+i, status=%s",
911 iterator
, bt_common_func_status_string(status
));
916 * There is no way that this iterator could have been finalized
917 * during its "next" method, as the only way to do this is to
918 * put the last iterator's reference, and this can only be done
919 * by its downstream owner.
921 * For the same reason, there is no way that this iterator could
922 * have seeked (cannot seek a self message iterator).
924 BT_ASSERT(iterator
->state
==
925 BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_STATE_ACTIVE
);
928 case BT_FUNC_STATUS_OK
:
929 BT_ASSERT_POST_DEV(*user_count
<= MSG_BATCH_SIZE
,
930 "Invalid returned message count: greater than "
931 "batch size: count=%" PRIu64
", batch-size=%u",
932 *user_count
, MSG_BATCH_SIZE
);
933 *msgs
= (void *) iterator
->base
.msgs
->pdata
;
935 case BT_FUNC_STATUS_AGAIN
:
937 case BT_FUNC_STATUS_END
:
938 set_self_comp_port_input_msg_iterator_state(iterator
,
939 BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_STATE_ENDED
);
942 /* Unknown non-error status */
950 enum bt_message_iterator_next_status
bt_port_output_message_iterator_next(
951 struct bt_port_output_message_iterator
*iterator
,
952 bt_message_array_const
*msgs_to_user
,
953 uint64_t *count_to_user
)
955 enum bt_message_iterator_next_status status
;
958 BT_ASSERT_PRE_DEV_NON_NULL(iterator
, "Message iterator");
959 BT_ASSERT_PRE_DEV_NON_NULL(msgs_to_user
, "Message array (output)");
960 BT_ASSERT_PRE_DEV_NON_NULL(count_to_user
, "Message count (output)");
961 BT_LIB_LOGD("Getting next output port message iterator's messages: "
963 graph_status
= bt_graph_consume_sink_no_check(iterator
->graph
,
965 switch (graph_status
) {
966 case BT_FUNC_STATUS_AGAIN
:
967 case BT_FUNC_STATUS_END
:
968 case BT_FUNC_STATUS_MEMORY_ERROR
:
969 status
= (int) graph_status
;
971 case BT_FUNC_STATUS_OK
:
972 status
= BT_FUNC_STATUS_OK
;
975 * On success, the colander sink moves the messages
976 * to this iterator's array and sets this iterator's
977 * message count: move them to the user.
979 *msgs_to_user
= (void *) iterator
->base
.msgs
->pdata
;
980 *count_to_user
= iterator
->count
;
984 status
= BT_FUNC_STATUS_ERROR
;
990 struct bt_component
*
991 bt_self_component_port_input_message_iterator_borrow_component(
992 struct bt_self_component_port_input_message_iterator
*iterator
)
994 BT_ASSERT_PRE_DEV_NON_NULL(iterator
, "Message iterator");
995 return iterator
->upstream_component
;
998 const struct bt_component
*
999 bt_self_component_port_input_message_iterator_borrow_component_const(
1000 const struct bt_self_component_port_input_message_iterator
*iterator
)
1002 BT_ASSERT_PRE_DEV_NON_NULL(iterator
, "Message iterator");
1003 return iterator
->upstream_component
;
1006 struct bt_self_component
*bt_self_message_iterator_borrow_component(
1007 struct bt_self_message_iterator
*self_iterator
)
1009 struct bt_self_component_port_input_message_iterator
*iterator
=
1010 (void *) self_iterator
;
1012 BT_ASSERT_PRE_DEV_NON_NULL(iterator
, "Message iterator");
1013 return (void *) iterator
->upstream_component
;
1016 struct bt_self_port_output
*bt_self_message_iterator_borrow_port(
1017 struct bt_self_message_iterator
*self_iterator
)
1019 struct bt_self_component_port_input_message_iterator
*iterator
=
1020 (void *) self_iterator
;
1022 BT_ASSERT_PRE_DEV_NON_NULL(iterator
, "Message iterator");
1023 return (void *) iterator
->upstream_port
;
1027 void bt_port_output_message_iterator_destroy(struct bt_object
*obj
)
1029 struct bt_port_output_message_iterator
*iterator
= (void *) obj
;
1031 BT_LIB_LOGI("Destroying output port message iterator object: %!+i",
1033 BT_LOGD_STR("Putting graph.");
1034 BT_OBJECT_PUT_REF_AND_RESET(iterator
->graph
);
1035 BT_LOGD_STR("Putting colander sink component.");
1036 BT_OBJECT_PUT_REF_AND_RESET(iterator
->colander
);
1037 destroy_base_message_iterator(obj
);
1040 struct bt_port_output_message_iterator
*
1041 bt_port_output_message_iterator_create(struct bt_graph
*graph
,
1042 const struct bt_port_output
*output_port
)
1044 struct bt_port_output_message_iterator
*iterator
= NULL
;
1045 struct bt_component_class_sink
*colander_comp_cls
= NULL
;
1046 struct bt_component
*output_port_comp
= NULL
;
1047 struct bt_component_sink
*colander_comp
;
1049 struct bt_port_input
*colander_in_port
= NULL
;
1050 struct bt_component_class_sink_colander_data colander_data
;
1053 BT_ASSERT_PRE_NON_NULL(graph
, "Graph");
1054 BT_ASSERT_PRE_NON_NULL(output_port
, "Output port");
1055 output_port_comp
= bt_port_borrow_component_inline(
1056 (const void *) output_port
);
1057 BT_ASSERT_PRE(output_port_comp
,
1058 "Output port has no component: %!+p", output_port
);
1059 BT_ASSERT_PRE(bt_component_borrow_graph(output_port_comp
) ==
1061 "Output port is not part of graph: %![graph-]+g, %![port-]+p",
1062 graph
, output_port
);
1063 BT_ASSERT_PRE(!graph
->has_sink
,
1064 "Graph already has a sink component: %![graph-]+g");
1066 /* Create message iterator */
1067 BT_LIB_LOGI("Creating message iterator on output port: "
1068 "%![port-]+p, %![comp-]+c", output_port
, output_port_comp
);
1069 iterator
= g_new0(struct bt_port_output_message_iterator
, 1);
1071 BT_LIB_LOGE_APPEND_CAUSE(
1072 "Failed to allocate one output port message iterator.");
1076 ret
= init_message_iterator((void *) iterator
,
1077 BT_MESSAGE_ITERATOR_TYPE_PORT_OUTPUT
,
1078 bt_port_output_message_iterator_destroy
);
1080 /* init_message_iterator() logs errors */
1081 BT_OBJECT_PUT_REF_AND_RESET(iterator
);
1085 /* Create colander component */
1086 colander_comp_cls
= bt_component_class_sink_colander_get();
1087 if (!colander_comp_cls
) {
1088 /* bt_component_class_sink_colander_get() logs errors */
1089 BT_LIB_LOGE_APPEND_CAUSE(
1090 "Cannot get colander sink component class.");
1094 iterator
->graph
= graph
;
1095 bt_object_get_no_null_check(iterator
->graph
);
1096 colander_data
.msgs
= (void *) iterator
->base
.msgs
->pdata
;
1097 colander_data
.count_addr
= &iterator
->count
;
1100 * Hope that nobody uses this very unique name.
1102 * We pass `BT_LOGGING_LEVEL_NONE` but the colander component
1103 * class module does not use this level anyway since it belongs
1106 graph_status
= bt_graph_add_sink_component_with_init_method_data(
1107 (void *) graph
, colander_comp_cls
,
1108 "colander-36ac3409-b1a8-4d60-ab1f-4fdf341a8fb1",
1109 NULL
, &colander_data
, BT_LOGGING_LEVEL_NONE
,
1110 (void *) &iterator
->colander
);
1111 if (graph_status
!= BT_FUNC_STATUS_OK
) {
1112 BT_LIB_LOGE_APPEND_CAUSE(
1113 "Cannot add colander sink component to graph: "
1114 "%![graph-]+g, status=%s", graph
,
1115 bt_common_func_status_string(graph_status
));
1120 * Connect provided output port to the colander component's
1124 (void *) bt_component_sink_borrow_input_port_by_index_const(
1125 (void *) iterator
->colander
, 0);
1126 BT_ASSERT(colander_in_port
);
1127 graph_status
= bt_graph_connect_ports(graph
,
1128 output_port
, colander_in_port
, NULL
);
1129 if (graph_status
!= BT_FUNC_STATUS_OK
) {
1130 BT_LIB_LOGW_APPEND_CAUSE(
1131 "Cannot connect colander sink's port: "
1132 "%![graph-]+g, %![comp-]+c, status=%s", graph
,
1134 bt_common_func_status_string(graph_status
));
1139 * At this point everything went fine. Make the graph
1140 * nonconsumable forever so that only this message iterator
1141 * can consume (thanks to bt_graph_consume_sink_no_check()).
1142 * This avoids leaking the message created by the colander
1143 * sink and moved to the message iterator's message
1146 bt_graph_set_can_consume(iterator
->graph
, false);
1148 /* Also set the graph as being configured. */
1149 graph_status
= bt_graph_configure(graph
);
1150 if (graph_status
!= BT_FUNC_STATUS_OK
) {
1151 BT_LIB_LOGW_APPEND_CAUSE(
1152 "Cannot configure graph after having "
1153 "added and connected colander sink: "
1154 "%![graph-]+g, %![comp-]+c, status=%s", graph
,
1156 bt_common_func_status_string(graph_status
));
1162 if (iterator
&& iterator
->graph
&& iterator
->colander
) {
1165 /* Remove created colander component from graph if any */
1166 colander_comp
= iterator
->colander
;
1167 BT_OBJECT_PUT_REF_AND_RESET(iterator
->colander
);
1170 * At this point the colander component's reference
1171 * count is 0 because iterator->colander was the only
1172 * owner. We also know that it is not connected because
1173 * this is the last operation before this function
1176 * Since we honor the preconditions here,
1177 * bt_graph_remove_unconnected_component() always
1180 ret
= bt_graph_remove_unconnected_component(iterator
->graph
,
1181 (void *) colander_comp
);
1182 BT_ASSERT(ret
== 0);
1185 BT_OBJECT_PUT_REF_AND_RESET(iterator
);
1188 bt_object_put_ref(colander_comp_cls
);
1189 return (void *) iterator
;
1192 bt_bool
bt_self_component_port_input_message_iterator_can_seek_ns_from_origin(
1193 struct bt_self_component_port_input_message_iterator
*iterator
,
1194 int64_t ns_from_origin
)
1196 bt_bool can
= BT_FALSE
;
1198 BT_ASSERT_PRE_NON_NULL(iterator
, "Message iterator");
1199 BT_ASSERT_PRE_ITER_HAS_STATE_TO_SEEK(iterator
);
1201 bt_component_borrow_graph(iterator
->upstream_component
)->config_state
!=
1202 BT_GRAPH_CONFIGURATION_STATE_CONFIGURING
,
1203 "Graph is not configured: %!+g",
1204 bt_component_borrow_graph(iterator
->upstream_component
));
1206 if (iterator
->methods
.can_seek_ns_from_origin
) {
1207 can
= iterator
->methods
.can_seek_ns_from_origin(iterator
,
1213 * Automatic seeking fall back: if we can seek to the beginning,
1214 * then we can automatically seek to any message.
1216 if (iterator
->methods
.can_seek_beginning
) {
1217 can
= iterator
->methods
.can_seek_beginning(iterator
);
1224 bt_bool
bt_self_component_port_input_message_iterator_can_seek_beginning(
1225 struct bt_self_component_port_input_message_iterator
*iterator
)
1227 bt_bool can
= BT_FALSE
;
1229 BT_ASSERT_PRE_NON_NULL(iterator
, "Message iterator");
1230 BT_ASSERT_PRE_ITER_HAS_STATE_TO_SEEK(iterator
);
1232 bt_component_borrow_graph(iterator
->upstream_component
)->config_state
!=
1233 BT_GRAPH_CONFIGURATION_STATE_CONFIGURING
,
1234 "Graph is not configured: %!+g",
1235 bt_component_borrow_graph(iterator
->upstream_component
));
1237 if (iterator
->methods
.can_seek_beginning
) {
1238 can
= iterator
->methods
.can_seek_beginning(iterator
);
1245 void set_iterator_state_after_seeking(
1246 struct bt_self_component_port_input_message_iterator
*iterator
,
1249 enum bt_self_component_port_input_message_iterator_state new_state
= 0;
1251 /* Set iterator's state depending on seeking status */
1253 case BT_FUNC_STATUS_OK
:
1254 new_state
= BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_STATE_ACTIVE
;
1256 case BT_FUNC_STATUS_AGAIN
:
1257 new_state
= BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_STATE_LAST_SEEKING_RETURNED_AGAIN
;
1259 case BT_FUNC_STATUS_ERROR
:
1260 case BT_FUNC_STATUS_MEMORY_ERROR
:
1261 new_state
= BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_STATE_LAST_SEEKING_RETURNED_ERROR
;
1263 case BT_FUNC_STATUS_END
:
1264 new_state
= BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_STATE_ENDED
;
1270 set_self_comp_port_input_msg_iterator_state(iterator
, new_state
);
1274 void reset_iterator_expectations(
1275 struct bt_self_component_port_input_message_iterator
*iterator
)
1277 iterator
->last_ns_from_origin
= INT64_MIN
;
1278 iterator
->clock_expectation
.type
= CLOCK_EXPECTATION_UNSET
;
1281 enum bt_message_iterator_seek_beginning_status
1282 bt_self_component_port_input_message_iterator_seek_beginning(
1283 struct bt_self_component_port_input_message_iterator
*iterator
)
1287 BT_ASSERT_PRE_NON_NULL(iterator
, "Message iterator");
1288 BT_ASSERT_PRE_ITER_HAS_STATE_TO_SEEK(iterator
);
1290 bt_component_borrow_graph(iterator
->upstream_component
)->config_state
!=
1291 BT_GRAPH_CONFIGURATION_STATE_CONFIGURING
,
1292 "Graph is not configured: %!+g",
1293 bt_component_borrow_graph(iterator
->upstream_component
));
1295 bt_self_component_port_input_message_iterator_can_seek_beginning(
1297 "Message iterator cannot seek beginning: %!+i", iterator
);
1300 * We are seeking, reset our expectations about how the following
1301 * messages should look like.
1303 reset_iterator_expectations(iterator
);
1305 BT_LIB_LOGD("Calling user's \"seek beginning\" method: %!+i", iterator
);
1306 set_self_comp_port_input_msg_iterator_state(iterator
,
1307 BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_STATE_SEEKING
);
1308 status
= iterator
->methods
.seek_beginning(iterator
);
1309 BT_LOGD("User method returned: status=%s",
1310 bt_common_func_status_string(status
));
1311 BT_ASSERT_POST(status
== BT_FUNC_STATUS_OK
||
1312 status
== BT_FUNC_STATUS_ERROR
||
1313 status
== BT_FUNC_STATUS_MEMORY_ERROR
||
1314 status
== BT_FUNC_STATUS_AGAIN
,
1315 "Unexpected status: %![iter-]+i, status=%s",
1316 iterator
, bt_common_func_status_string(status
));
1318 BT_LIB_LOGW_APPEND_CAUSE(
1319 "Component input port message iterator's \"seek beginning\" method failed: "
1320 "%![iter-]+i, status=%s",
1321 iterator
, bt_common_func_status_string(status
));
1324 set_iterator_state_after_seeking(iterator
, status
);
1329 * Structure used to record the state of a given stream during the fast-forward
1330 * phase of an auto-seek.
1332 struct auto_seek_stream_state
{
1334 * Value representing which step of this timeline we are at.
1337 * [SB] 1 [PB] 2 [PE] 1 [SE]
1339 * At each point in the timeline, the messages we need to replicate are:
1341 * 1: Stream beginning
1342 * 2: Stream beginning, packet beginning
1344 * Before "Stream beginning" and after "Stream end", we don't need to
1345 * replicate anything as the stream doesn't exist.
1348 AUTO_SEEK_STREAM_STATE_STREAM_BEGAN
,
1349 AUTO_SEEK_STREAM_STATE_PACKET_BEGAN
,
1353 * If `state` is AUTO_SEEK_STREAM_STATE_PACKET_BEGAN, the packet we are
1354 * in. This is a weak reference, since the packet will always be
1355 * alive by the time we use it.
1357 struct bt_packet
*packet
;
1359 /* Have we see a message with a clock snapshot yet? */
1360 bool seen_clock_snapshot
;
1364 struct auto_seek_stream_state
*create_auto_seek_stream_state(void)
1366 return g_new0(struct auto_seek_stream_state
, 1);
1370 void destroy_auto_seek_stream_state(void *ptr
)
1376 GHashTable
*create_auto_seek_stream_states(void)
1378 return g_hash_table_new_full(g_direct_hash
, g_direct_equal
, NULL
,
1379 destroy_auto_seek_stream_state
);
1383 void destroy_auto_seek_stream_states(GHashTable
*stream_states
)
1385 g_hash_table_destroy(stream_states
);
1389 * Handle one message while we are in the fast-forward phase of an auto-seek.
1391 * Sets `*got_first` to true if the message's timestamp is greater or equal to
1392 * `ns_from_origin`. In other words, if this is the first message after our
1395 * `stream_states` is an hash table of `bt_stream *` (weak reference) to
1396 * `struct auto_seek_stream_state` used to keep the state of each stream
1397 * during the fast-forward.
1401 int auto_seek_handle_message(
1402 struct bt_self_component_port_input_message_iterator
*iterator
,
1403 int64_t ns_from_origin
, const struct bt_message
*msg
,
1404 bool *got_first
, GHashTable
*stream_states
)
1406 int status
= BT_FUNC_STATUS_OK
;
1407 int64_t msg_ns_from_origin
;
1408 const struct bt_clock_snapshot
*clk_snapshot
= NULL
;
1412 BT_ASSERT(got_first
);
1414 switch (msg
->type
) {
1415 case BT_MESSAGE_TYPE_EVENT
:
1417 const struct bt_message_event
*event_msg
=
1420 clk_snapshot
= event_msg
->default_cs
;
1421 BT_ASSERT_POST_DEV(clk_snapshot
,
1422 "Event message has no default clock snapshot: %!+n",
1426 case BT_MESSAGE_TYPE_MESSAGE_ITERATOR_INACTIVITY
:
1428 const struct bt_message_message_iterator_inactivity
*inactivity_msg
=
1431 clk_snapshot
= inactivity_msg
->default_cs
;
1432 BT_ASSERT(clk_snapshot
);
1435 case BT_MESSAGE_TYPE_PACKET_BEGINNING
:
1436 case BT_MESSAGE_TYPE_PACKET_END
:
1438 const struct bt_message_packet
*packet_msg
=
1441 clk_snapshot
= packet_msg
->default_cs
;
1442 BT_ASSERT_POST_DEV(clk_snapshot
,
1443 "Packet message has no default clock snapshot: %!+n",
1447 case BT_MESSAGE_TYPE_DISCARDED_EVENTS
:
1448 case BT_MESSAGE_TYPE_DISCARDED_PACKETS
:
1450 struct bt_message_discarded_items
*msg_disc_items
=
1453 BT_ASSERT_POST_DEV(msg_disc_items
->default_begin_cs
&&
1454 msg_disc_items
->default_end_cs
,
1455 "Discarded events/packets message has no default clock snapshots: %!+n",
1457 ret
= bt_clock_snapshot_get_ns_from_origin(
1458 msg_disc_items
->default_begin_cs
,
1459 &msg_ns_from_origin
);
1461 status
= BT_FUNC_STATUS_ERROR
;
1465 if (msg_ns_from_origin
>= ns_from_origin
) {
1470 ret
= bt_clock_snapshot_get_ns_from_origin(
1471 msg_disc_items
->default_end_cs
,
1472 &msg_ns_from_origin
);
1474 status
= BT_FUNC_STATUS_ERROR
;
1478 if (msg_ns_from_origin
>= ns_from_origin
) {
1480 * The discarded items message's beginning time
1481 * is before the requested seeking time, but its
1482 * end time is after. Modify the message so as
1483 * to set its beginning time to the requested
1484 * seeking time, and make its item count unknown
1485 * as we don't know if items were really
1486 * discarded within the new time range.
1488 uint64_t new_begin_raw_value
= 0;
1490 ret
= bt_clock_class_clock_value_from_ns_from_origin(
1491 msg_disc_items
->default_end_cs
->clock_class
,
1492 ns_from_origin
, &new_begin_raw_value
);
1494 status
= BT_FUNC_STATUS_ERROR
;
1498 bt_clock_snapshot_set_raw_value(
1499 msg_disc_items
->default_begin_cs
,
1500 new_begin_raw_value
);
1501 msg_disc_items
->count
.base
.avail
=
1502 BT_PROPERTY_AVAILABILITY_NOT_AVAILABLE
;
1505 * It is safe to push it because its beginning
1506 * time is exactly the requested seeking time.
1513 case BT_MESSAGE_TYPE_STREAM_BEGINNING
:
1514 case BT_MESSAGE_TYPE_STREAM_END
:
1516 struct bt_message_stream
*stream_msg
=
1517 (struct bt_message_stream
*) msg
;
1519 if (stream_msg
->default_cs_state
!= BT_MESSAGE_STREAM_CLOCK_SNAPSHOT_STATE_KNOWN
) {
1524 clk_snapshot
= stream_msg
->default_cs
;
1531 BT_ASSERT(clk_snapshot
);
1532 ret
= bt_clock_snapshot_get_ns_from_origin(clk_snapshot
,
1533 &msg_ns_from_origin
);
1535 status
= BT_FUNC_STATUS_ERROR
;
1539 if (msg_ns_from_origin
>= ns_from_origin
) {
1545 /* This message won't be sent downstream. */
1546 switch (msg
->type
) {
1547 case BT_MESSAGE_TYPE_STREAM_BEGINNING
:
1549 const struct bt_message_stream
*stream_msg
= (const void *) msg
;
1550 struct auto_seek_stream_state
*stream_state
;
1552 /* Update stream's state: stream began. */
1553 stream_state
= create_auto_seek_stream_state();
1554 if (!stream_state
) {
1555 status
= BT_FUNC_STATUS_MEMORY_ERROR
;
1559 stream_state
->state
= AUTO_SEEK_STREAM_STATE_STREAM_BEGAN
;
1561 if (stream_msg
->default_cs_state
== BT_MESSAGE_STREAM_CLOCK_SNAPSHOT_STATE_KNOWN
) {
1562 stream_state
->seen_clock_snapshot
= true;
1565 BT_ASSERT(!bt_g_hash_table_contains(stream_states
, stream_msg
->stream
));
1566 g_hash_table_insert(stream_states
, stream_msg
->stream
, stream_state
);
1569 case BT_MESSAGE_TYPE_PACKET_BEGINNING
:
1571 const struct bt_message_packet
*packet_msg
=
1573 struct auto_seek_stream_state
*stream_state
;
1575 /* Update stream's state: packet began. */
1576 stream_state
= g_hash_table_lookup(stream_states
, packet_msg
->packet
->stream
);
1577 BT_ASSERT(stream_state
);
1579 BT_ASSERT(stream_state
->state
== AUTO_SEEK_STREAM_STATE_STREAM_BEGAN
);
1580 stream_state
->state
= AUTO_SEEK_STREAM_STATE_PACKET_BEGAN
;
1581 BT_ASSERT(!stream_state
->packet
);
1582 stream_state
->packet
= packet_msg
->packet
;
1584 if (packet_msg
->packet
->stream
->class->packets_have_beginning_default_clock_snapshot
) {
1585 stream_state
->seen_clock_snapshot
= true;
1590 case BT_MESSAGE_TYPE_EVENT
:
1592 const struct bt_message_event
*event_msg
= (const void *) msg
;
1593 struct auto_seek_stream_state
*stream_state
;
1595 stream_state
= g_hash_table_lookup(stream_states
,
1596 event_msg
->event
->packet
->stream
);
1597 BT_ASSERT(stream_state
);
1599 // HELPME: are we sure that event messages have clock snapshots at this point?
1600 stream_state
->seen_clock_snapshot
= true;
1604 case BT_MESSAGE_TYPE_PACKET_END
:
1606 const struct bt_message_packet
*packet_msg
=
1608 struct auto_seek_stream_state
*stream_state
;
1610 /* Update stream's state: packet ended. */
1611 stream_state
= g_hash_table_lookup(stream_states
, packet_msg
->packet
->stream
);
1612 BT_ASSERT(stream_state
);
1614 BT_ASSERT(stream_state
->state
== AUTO_SEEK_STREAM_STATE_PACKET_BEGAN
);
1615 stream_state
->state
= AUTO_SEEK_STREAM_STATE_STREAM_BEGAN
;
1616 BT_ASSERT(stream_state
->packet
);
1617 stream_state
->packet
= NULL
;
1619 if (packet_msg
->packet
->stream
->class->packets_have_end_default_clock_snapshot
) {
1620 stream_state
->seen_clock_snapshot
= true;
1625 case BT_MESSAGE_TYPE_STREAM_END
:
1627 const struct bt_message_stream
*stream_msg
= (const void *) msg
;
1628 struct auto_seek_stream_state
*stream_state
;
1630 stream_state
= g_hash_table_lookup(stream_states
, stream_msg
->stream
);
1631 BT_ASSERT(stream_state
);
1632 BT_ASSERT(stream_state
->state
== AUTO_SEEK_STREAM_STATE_STREAM_BEGAN
);
1633 BT_ASSERT(!stream_state
->packet
);
1635 /* Update stream's state: this stream doesn't exist anymore. */
1636 g_hash_table_remove(stream_states
, stream_msg
->stream
);
1639 case BT_MESSAGE_TYPE_DISCARDED_EVENTS
:
1640 case BT_MESSAGE_TYPE_DISCARDED_PACKETS
:
1642 const struct bt_message_discarded_items
*discarded_msg
=
1644 struct auto_seek_stream_state
*stream_state
;
1646 stream_state
= g_hash_table_lookup(stream_states
, discarded_msg
->stream
);
1647 BT_ASSERT(stream_state
);
1649 if ((msg
->type
== BT_MESSAGE_TYPE_DISCARDED_EVENTS
&& discarded_msg
->stream
->class->discarded_events_have_default_clock_snapshots
) ||
1650 (msg
->type
== BT_MESSAGE_TYPE_DISCARDED_PACKETS
&& discarded_msg
->stream
->class->discarded_packets_have_default_clock_snapshots
)) {
1651 stream_state
->seen_clock_snapshot
= true;
1660 bt_object_put_no_null_check(msg
);
1665 g_queue_push_tail(iterator
->auto_seek
.msgs
, (void *) msg
);
1669 BT_ASSERT(!msg
|| status
!= BT_FUNC_STATUS_OK
);
1674 int find_message_ge_ns_from_origin(
1675 struct bt_self_component_port_input_message_iterator
*iterator
,
1676 int64_t ns_from_origin
, GHashTable
*stream_states
)
1679 enum bt_self_component_port_input_message_iterator_state init_state
=
1681 const struct bt_message
*messages
[MSG_BATCH_SIZE
];
1682 uint64_t user_count
= 0;
1684 bool got_first
= false;
1686 BT_ASSERT(iterator
);
1687 memset(&messages
[0], 0, sizeof(messages
[0]) * MSG_BATCH_SIZE
);
1690 * Make this iterator temporarily active (not seeking) to call
1691 * the "next" method.
1693 set_self_comp_port_input_msg_iterator_state(iterator
,
1694 BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_STATE_ACTIVE
);
1696 BT_ASSERT(iterator
->methods
.next
);
1698 while (!got_first
) {
1700 * Call the user's "next" method to get the next
1701 * messages and status.
1703 status
= call_iterator_next_method(iterator
,
1704 &messages
[0], MSG_BATCH_SIZE
, &user_count
);
1705 BT_LOGD("User method returned: status=%s",
1706 bt_common_func_status_string(status
));
1708 BT_LIB_LOGW_APPEND_CAUSE(
1709 "Component input port message iterator's \"next\" method failed: "
1710 "%![iter-]+i, status=%s",
1711 iterator
, bt_common_func_status_string(status
));
1715 * The user's "next" method must not do any action which
1716 * would change the iterator's state.
1718 BT_ASSERT(iterator
->state
==
1719 BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_STATE_ACTIVE
);
1722 case BT_FUNC_STATUS_OK
:
1723 BT_ASSERT_POST_DEV(user_count
<= MSG_BATCH_SIZE
,
1724 "Invalid returned message count: greater than "
1725 "batch size: count=%" PRIu64
", batch-size=%u",
1726 user_count
, MSG_BATCH_SIZE
);
1728 case BT_FUNC_STATUS_AGAIN
:
1729 case BT_FUNC_STATUS_ERROR
:
1730 case BT_FUNC_STATUS_MEMORY_ERROR
:
1731 case BT_FUNC_STATUS_END
:
1737 for (i
= 0; i
< user_count
; i
++) {
1739 g_queue_push_tail(iterator
->auto_seek
.msgs
,
1740 (void *) messages
[i
]);
1745 status
= auto_seek_handle_message(iterator
,
1746 ns_from_origin
, messages
[i
], &got_first
,
1748 if (status
== BT_FUNC_STATUS_OK
) {
1749 /* Message was either pushed or moved */
1758 for (i
= 0; i
< user_count
; i
++) {
1760 bt_object_put_no_null_check(messages
[i
]);
1764 set_self_comp_port_input_msg_iterator_state(iterator
, init_state
);
1769 * This function is installed as the iterator's next callback after we have
1770 * auto-seeked (seeked to the beginning and fast-forwarded) to send the
1771 * messages saved in iterator->auto_seek.msgs. Once this is done, the original
1772 * next callback is put back.
1776 enum bt_component_class_message_iterator_next_method_status
post_auto_seek_next(
1777 struct bt_self_component_port_input_message_iterator
*iterator
,
1778 bt_message_array_const msgs
, uint64_t capacity
,
1781 BT_ASSERT(!g_queue_is_empty(iterator
->auto_seek
.msgs
));
1785 * Move auto-seek messages to the output array (which is this
1786 * iterator's base message array).
1788 while (capacity
> 0 && !g_queue_is_empty(iterator
->auto_seek
.msgs
)) {
1789 msgs
[*count
] = g_queue_pop_head(iterator
->auto_seek
.msgs
);
1794 BT_ASSERT(*count
> 0);
1796 if (g_queue_is_empty(iterator
->auto_seek
.msgs
)) {
1797 /* No more auto-seek messages, restore user's next callback. */
1798 BT_ASSERT(iterator
->auto_seek
.original_next_callback
);
1799 iterator
->methods
.next
= iterator
->auto_seek
.original_next_callback
;
1800 iterator
->auto_seek
.original_next_callback
= NULL
;
1803 return BT_FUNC_STATUS_OK
;
1807 int clock_raw_value_from_ns_from_origin(const bt_clock_class
*clock_class
,
1808 int64_t ns_from_origin
, uint64_t *raw_value
)
1811 int64_t cc_offset_s
= clock_class
->offset_seconds
;
1812 uint64_t cc_offset_cycles
= clock_class
->offset_cycles
;
1813 uint64_t cc_freq
= clock_class
->frequency
;
1815 return bt_common_clock_value_from_ns_from_origin(cc_offset_s
,
1816 cc_offset_cycles
, cc_freq
, ns_from_origin
, raw_value
);
1820 enum bt_message_iterator_seek_ns_from_origin_status
1821 bt_self_component_port_input_message_iterator_seek_ns_from_origin(
1822 struct bt_self_component_port_input_message_iterator
*iterator
,
1823 int64_t ns_from_origin
)
1826 GHashTable
*stream_states
= NULL
;
1828 BT_ASSERT_PRE_NON_NULL(iterator
, "Message iterator");
1829 BT_ASSERT_PRE_ITER_HAS_STATE_TO_SEEK(iterator
);
1831 bt_component_borrow_graph(iterator
->upstream_component
)->config_state
!=
1832 BT_GRAPH_CONFIGURATION_STATE_CONFIGURING
,
1833 "Graph is not configured: %!+g",
1834 bt_component_borrow_graph(iterator
->upstream_component
));
1836 bt_self_component_port_input_message_iterator_can_seek_ns_from_origin(
1837 iterator
, ns_from_origin
),
1838 "Message iterator cannot seek nanoseconds from origin: %!+i, "
1839 "ns-from-origin=%" PRId64
, iterator
, ns_from_origin
);
1840 set_self_comp_port_input_msg_iterator_state(iterator
,
1841 BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_STATE_SEEKING
);
1844 * We are seeking, reset our expectations about how the following
1845 * messages should look like.
1847 reset_iterator_expectations(iterator
);
1849 if (iterator
->methods
.seek_ns_from_origin
) {
1850 /* The iterator knows how to seek to a particular time, let it handle this. */
1851 BT_LIB_LOGD("Calling user's \"seek nanoseconds from origin\" method: "
1852 "%![iter-]+i, ns=%" PRId64
, iterator
, ns_from_origin
);
1853 status
= iterator
->methods
.seek_ns_from_origin(iterator
,
1855 BT_LOGD("User method returned: status=%s",
1856 bt_common_func_status_string(status
));
1857 BT_ASSERT_POST(status
== BT_FUNC_STATUS_OK
||
1858 status
== BT_FUNC_STATUS_ERROR
||
1859 status
== BT_FUNC_STATUS_MEMORY_ERROR
||
1860 status
== BT_FUNC_STATUS_AGAIN
,
1861 "Unexpected status: %![iter-]+i, status=%s",
1862 iterator
, bt_common_func_status_string(status
));
1864 BT_LIB_LOGW_APPEND_CAUSE(
1865 "Component input port message iterator's \"seek nanoseconds from origin\" method failed: "
1866 "%![iter-]+i, status=%s",
1867 iterator
, bt_common_func_status_string(status
));
1871 * The iterator doesn't know how to seek to a particular time. We will
1872 * seek to the beginning and fast forward to the right place.
1874 BT_ASSERT(iterator
->methods
.can_seek_beginning(iterator
));
1875 BT_ASSERT(iterator
->methods
.seek_beginning
);
1876 BT_LIB_LOGD("Calling user's \"seek beginning\" method: %!+i",
1878 status
= iterator
->methods
.seek_beginning(iterator
);
1879 BT_LOGD("User method returned: status=%s",
1880 bt_common_func_status_string(status
));
1881 BT_ASSERT_POST(status
== BT_FUNC_STATUS_OK
||
1882 status
== BT_FUNC_STATUS_ERROR
||
1883 status
== BT_FUNC_STATUS_MEMORY_ERROR
||
1884 status
== BT_FUNC_STATUS_AGAIN
,
1885 "Unexpected status: %![iter-]+i, status=%s",
1886 iterator
, bt_common_func_status_string(status
));
1888 BT_LIB_LOGW_APPEND_CAUSE(
1889 "Component input port message iterator's \"seek beginning\" method failed: "
1890 "%![iter-]+i, status=%s",
1891 iterator
, bt_common_func_status_string(status
));
1895 case BT_FUNC_STATUS_OK
:
1897 case BT_FUNC_STATUS_ERROR
:
1898 case BT_FUNC_STATUS_MEMORY_ERROR
:
1899 case BT_FUNC_STATUS_AGAIN
:
1906 * Find the first message which has a default clock
1907 * snapshot greater than or equal to the requested
1908 * seeking time, and move the received messages from
1909 * this point in the batch to this iterator's auto-seek
1912 while (!g_queue_is_empty(iterator
->auto_seek
.msgs
)) {
1913 bt_object_put_no_null_check(
1914 g_queue_pop_tail(iterator
->auto_seek
.msgs
));
1917 stream_states
= create_auto_seek_stream_states();
1918 if (!stream_states
) {
1919 BT_LIB_LOGE_APPEND_CAUSE(
1920 "Failed to allocate one GHashTable.");
1921 status
= BT_FUNC_STATUS_MEMORY_ERROR
;
1925 status
= find_message_ge_ns_from_origin(iterator
,
1926 ns_from_origin
, stream_states
);
1928 case BT_FUNC_STATUS_OK
:
1929 case BT_FUNC_STATUS_END
:
1931 GHashTableIter iter
;
1932 gpointer key
, value
;
1935 * If some streams exist at the seek time, prepend the
1936 * required messages to put those streams in the right
1939 g_hash_table_iter_init(&iter
, stream_states
);
1940 while (g_hash_table_iter_next (&iter
, &key
, &value
)) {
1941 const bt_stream
*stream
= key
;
1942 struct auto_seek_stream_state
*stream_state
=
1943 (struct auto_seek_stream_state
*) value
;
1945 const bt_clock_class
*clock_class
= bt_stream_class_borrow_default_clock_class_const(
1946 bt_stream_borrow_class_const(stream
));
1947 /* Initialize to silence maybe-uninitialized warning. */
1948 uint64_t raw_value
= 0;
1951 * If we haven't seen a message with a clock snapshot, we don't know if our seek time is within
1952 * the clock's range, so it wouldn't be safe to try to convert ns_from_origin to a clock value.
1954 * Also, it would be a bit of a lie to generate a stream begin message with the seek time as its
1955 * clock snapshot, because we don't really know if the stream existed at that time. If we have
1956 * seen a message with a clock snapshot in our seeking, then we are sure that the
1957 * seek time is not below the clock range, and we know the stream was active at that
1958 * time (and that we cut it short).
1960 if (stream_state
->seen_clock_snapshot
) {
1961 if (clock_raw_value_from_ns_from_origin(clock_class
, ns_from_origin
, &raw_value
) != 0) {
1962 BT_LIB_LOGW("Could not convert nanoseconds from origin to clock value: ns-from-origin=%" PRId64
", %![cc-]+K",
1963 ns_from_origin
, clock_class
);
1964 status
= BT_FUNC_STATUS_ERROR
;
1969 switch (stream_state
->state
) {
1970 case AUTO_SEEK_STREAM_STATE_PACKET_BEGAN
:
1971 BT_ASSERT(stream_state
->packet
);
1972 BT_LIB_LOGD("Creating packet message: %![packet-]+a", stream_state
->packet
);
1974 if (stream
->class->packets_have_beginning_default_clock_snapshot
) {
1976 * If we are in the PACKET_BEGAN state, it means we have seen a "packet beginning"
1977 * message. If "packet beginning" packets have clock snapshots, then we must have
1978 * seen a clock snapshot.
1980 BT_ASSERT(stream_state
->seen_clock_snapshot
);
1982 msg
= bt_message_packet_beginning_create_with_default_clock_snapshot(
1983 (bt_self_message_iterator
*) iterator
, stream_state
->packet
, raw_value
);
1985 msg
= bt_message_packet_beginning_create((bt_self_message_iterator
*) iterator
,
1986 stream_state
->packet
);
1990 status
= BT_FUNC_STATUS_MEMORY_ERROR
;
1994 g_queue_push_head(iterator
->auto_seek
.msgs
, msg
);
1998 case AUTO_SEEK_STREAM_STATE_STREAM_BEGAN
:
1999 msg
= bt_message_stream_beginning_create(
2000 (bt_self_message_iterator
*) iterator
, stream
);
2002 status
= BT_FUNC_STATUS_MEMORY_ERROR
;
2006 if (stream_state
->seen_clock_snapshot
) {
2007 bt_message_stream_beginning_set_default_clock_snapshot(msg
, raw_value
);
2010 g_queue_push_head(iterator
->auto_seek
.msgs
, msg
);
2017 * If there are messages in the auto-seek
2018 * message queue, replace the user's "next"
2019 * method with a custom, temporary "next" method
2020 * which returns them.
2022 if (!g_queue_is_empty(iterator
->auto_seek
.msgs
)) {
2023 BT_ASSERT(!iterator
->auto_seek
.original_next_callback
);
2024 iterator
->auto_seek
.original_next_callback
= iterator
->methods
.next
;
2026 iterator
->methods
.next
=
2027 (bt_self_component_port_input_message_iterator_next_method
)
2028 post_auto_seek_next
;
2032 * `BT_FUNC_STATUS_END` becomes
2033 * `BT_FUNC_STATUS_OK`: the next
2034 * time this iterator's "next" method is called,
2036 * `BT_FUNC_STATUS_END`.
2038 status
= BT_FUNC_STATUS_OK
;
2041 case BT_FUNC_STATUS_ERROR
:
2042 case BT_FUNC_STATUS_MEMORY_ERROR
:
2043 case BT_FUNC_STATUS_AGAIN
:
2051 * The following messages returned by the next method (including
2052 * post_auto_seek_next) must be after (or at) `ns_from_origin`.
2054 iterator
->last_ns_from_origin
= ns_from_origin
;
2057 if (stream_states
) {
2058 destroy_auto_seek_stream_states(stream_states
);
2059 stream_states
= NULL
;
2062 set_iterator_state_after_seeking(iterator
, status
);
2067 bt_self_component_port_input_message_iterator
*
2068 borrow_output_port_message_iterator_upstream_iterator(
2069 struct bt_port_output_message_iterator
*iterator
)
2071 struct bt_component_class_sink_colander_priv_data
*colander_data
;
2073 BT_ASSERT(iterator
);
2074 colander_data
= (void *) iterator
->colander
->parent
.user_data
;
2075 BT_ASSERT(colander_data
);
2076 BT_ASSERT(colander_data
->msg_iter
);
2077 return colander_data
->msg_iter
;
2080 bt_bool
bt_port_output_message_iterator_can_seek_ns_from_origin(
2081 struct bt_port_output_message_iterator
*iterator
,
2082 int64_t ns_from_origin
)
2084 BT_ASSERT_PRE_NON_NULL(iterator
, "Message iterator");
2085 return bt_self_component_port_input_message_iterator_can_seek_ns_from_origin(
2086 borrow_output_port_message_iterator_upstream_iterator(
2087 iterator
), ns_from_origin
);
2090 bt_bool
bt_port_output_message_iterator_can_seek_beginning(
2091 struct bt_port_output_message_iterator
*iterator
)
2093 BT_ASSERT_PRE_NON_NULL(iterator
, "Message iterator");
2094 return bt_self_component_port_input_message_iterator_can_seek_beginning(
2095 borrow_output_port_message_iterator_upstream_iterator(
2099 enum bt_message_iterator_seek_ns_from_origin_status
2100 bt_port_output_message_iterator_seek_ns_from_origin(
2101 struct bt_port_output_message_iterator
*iterator
,
2102 int64_t ns_from_origin
)
2104 BT_ASSERT_PRE_NON_NULL(iterator
, "Message iterator");
2105 return bt_self_component_port_input_message_iterator_seek_ns_from_origin(
2106 borrow_output_port_message_iterator_upstream_iterator(iterator
),
2110 enum bt_message_iterator_seek_beginning_status
2111 bt_port_output_message_iterator_seek_beginning(
2112 struct bt_port_output_message_iterator
*iterator
)
2114 BT_ASSERT_PRE_NON_NULL(iterator
, "Message iterator");
2115 return bt_self_component_port_input_message_iterator_seek_beginning(
2116 borrow_output_port_message_iterator_upstream_iterator(
2120 bt_bool
bt_self_message_iterator_is_interrupted(
2121 const struct bt_self_message_iterator
*self_msg_iter
)
2123 const struct bt_self_component_port_input_message_iterator
*iterator
=
2124 (const void *) self_msg_iter
;
2126 BT_ASSERT_PRE_NON_NULL(iterator
, "Message iterator");
2127 return (bt_bool
) bt_graph_is_interrupted(iterator
->graph
);
2130 void bt_port_output_message_iterator_get_ref(
2131 const struct bt_port_output_message_iterator
*iterator
)
2133 bt_object_get_ref(iterator
);
2136 void bt_port_output_message_iterator_put_ref(
2137 const struct bt_port_output_message_iterator
*iterator
)
2139 bt_object_put_ref(iterator
);
2142 void bt_self_component_port_input_message_iterator_get_ref(
2143 const struct bt_self_component_port_input_message_iterator
*iterator
)
2145 bt_object_get_ref(iterator
);
2148 void bt_self_component_port_input_message_iterator_put_ref(
2149 const struct bt_self_component_port_input_message_iterator
*iterator
)
2151 bt_object_put_ref(iterator
);