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_PRE(!bt_component_graph_is_canceled(comp
),
352 "Input port's component's graph is canceled: "
353 "%![port-]+p, %![comp-]+c", port
, comp
);
354 BT_ASSERT(port
->connection
);
355 upstream_port
= port
->connection
->upstream_port
;
356 BT_ASSERT(upstream_port
);
357 upstream_comp
= bt_port_borrow_component_inline(upstream_port
);
358 BT_ASSERT(upstream_comp
);
360 bt_component_borrow_graph(upstream_comp
)->config_state
!=
361 BT_GRAPH_CONFIGURATION_STATE_CONFIGURING
,
362 "Graph is not configured: %!+g",
363 bt_component_borrow_graph(upstream_comp
));
364 upstream_comp_cls
= upstream_comp
->class;
365 BT_ASSERT(upstream_comp
->class->type
==
366 BT_COMPONENT_CLASS_TYPE_SOURCE
||
367 upstream_comp
->class->type
==
368 BT_COMPONENT_CLASS_TYPE_FILTER
);
369 BT_LIB_LOGI("Creating message iterator on self component input port: "
370 "%![up-comp-]+c, %![up-port-]+p", upstream_comp
, upstream_port
);
372 struct bt_self_component_port_input_message_iterator
, 1);
374 BT_LIB_LOGE_APPEND_CAUSE(
375 "Failed to allocate one self component input port "
376 "message iterator.");
380 ret
= init_message_iterator((void *) iterator
,
381 BT_MESSAGE_ITERATOR_TYPE_SELF_COMPONENT_PORT_INPUT
,
382 bt_self_component_port_input_message_iterator_destroy
);
384 /* init_message_iterator() logs errors */
388 iterator
->last_ns_from_origin
= INT64_MIN
;
389 iterator
->auto_seek
.msgs
= g_queue_new();
390 if (!iterator
->auto_seek
.msgs
) {
391 BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate a GQueue.");
395 iterator
->upstream_msg_iters
= g_ptr_array_new();
396 if (!iterator
->upstream_msg_iters
) {
397 BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate a GPtrArray.");
401 iterator
->upstream_component
= upstream_comp
;
402 iterator
->upstream_port
= upstream_port
;
403 iterator
->connection
= iterator
->upstream_port
->connection
;
404 iterator
->graph
= bt_component_borrow_graph(upstream_comp
);
405 set_self_comp_port_input_msg_iterator_state(iterator
,
406 BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_STATE_NON_INITIALIZED
);
408 switch (iterator
->upstream_component
->class->type
) {
409 case BT_COMPONENT_CLASS_TYPE_SOURCE
:
411 struct bt_component_class_source
*src_comp_cls
=
412 (void *) iterator
->upstream_component
->class;
414 iterator
->methods
.next
=
415 (bt_self_component_port_input_message_iterator_next_method
)
416 src_comp_cls
->methods
.msg_iter_next
;
417 iterator
->methods
.seek_ns_from_origin
=
418 (bt_self_component_port_input_message_iterator_seek_ns_from_origin_method
)
419 src_comp_cls
->methods
.msg_iter_seek_ns_from_origin
;
420 iterator
->methods
.seek_beginning
=
421 (bt_self_component_port_input_message_iterator_seek_beginning_method
)
422 src_comp_cls
->methods
.msg_iter_seek_beginning
;
423 iterator
->methods
.can_seek_ns_from_origin
=
424 (bt_self_component_port_input_message_iterator_can_seek_ns_from_origin_method
)
425 src_comp_cls
->methods
.msg_iter_can_seek_ns_from_origin
;
426 iterator
->methods
.can_seek_beginning
=
427 (bt_self_component_port_input_message_iterator_can_seek_beginning_method
)
428 src_comp_cls
->methods
.msg_iter_can_seek_beginning
;
431 case BT_COMPONENT_CLASS_TYPE_FILTER
:
433 struct bt_component_class_filter
*flt_comp_cls
=
434 (void *) iterator
->upstream_component
->class;
436 iterator
->methods
.next
=
437 (bt_self_component_port_input_message_iterator_next_method
)
438 flt_comp_cls
->methods
.msg_iter_next
;
439 iterator
->methods
.seek_ns_from_origin
=
440 (bt_self_component_port_input_message_iterator_seek_ns_from_origin_method
)
441 flt_comp_cls
->methods
.msg_iter_seek_ns_from_origin
;
442 iterator
->methods
.seek_beginning
=
443 (bt_self_component_port_input_message_iterator_seek_beginning_method
)
444 flt_comp_cls
->methods
.msg_iter_seek_beginning
;
445 iterator
->methods
.can_seek_ns_from_origin
=
446 (bt_self_component_port_input_message_iterator_can_seek_ns_from_origin_method
)
447 flt_comp_cls
->methods
.msg_iter_can_seek_ns_from_origin
;
448 iterator
->methods
.can_seek_beginning
=
449 (bt_self_component_port_input_message_iterator_can_seek_beginning_method
)
450 flt_comp_cls
->methods
.msg_iter_can_seek_beginning
;
457 if (iterator
->methods
.seek_ns_from_origin
&&
458 !iterator
->methods
.can_seek_ns_from_origin
) {
459 iterator
->methods
.can_seek_ns_from_origin
=
460 (bt_self_component_port_input_message_iterator_can_seek_ns_from_origin_method
)
461 can_seek_ns_from_origin_true
;
464 if (iterator
->methods
.seek_beginning
&&
465 !iterator
->methods
.can_seek_beginning
) {
466 iterator
->methods
.can_seek_beginning
=
467 (bt_self_component_port_input_message_iterator_seek_beginning_method
)
468 can_seek_beginning_true
;
471 switch (upstream_comp_cls
->type
) {
472 case BT_COMPONENT_CLASS_TYPE_SOURCE
:
474 struct bt_component_class_source
*src_comp_cls
=
475 (void *) upstream_comp_cls
;
478 (init_method_t
) src_comp_cls
->methods
.msg_iter_init
;
481 case BT_COMPONENT_CLASS_TYPE_FILTER
:
483 struct bt_component_class_filter
*flt_comp_cls
=
484 (void *) upstream_comp_cls
;
487 (init_method_t
) flt_comp_cls
->methods
.msg_iter_init
;
496 enum bt_component_class_message_iterator_init_method_status iter_status
;
498 BT_LIB_LOGD("Calling user's initialization method: %!+i", iterator
);
499 iter_status
= init_method(iterator
, upstream_comp
,
501 BT_LOGD("User method returned: status=%s",
502 bt_common_func_status_string(iter_status
));
503 if (iter_status
!= BT_FUNC_STATUS_OK
) {
504 BT_LIB_LOGW_APPEND_CAUSE(
505 "Component input port message iterator initialization method failed: "
506 "%![iter-]+i, status=%s",
508 bt_common_func_status_string(iter_status
));
513 if (downstream_msg_iter
) {
514 /* Set this message iterator's downstream message iterator */
515 iterator
->downstream_msg_iter
= downstream_msg_iter
;
518 * Add this message iterator to the downstream message
519 * iterator's array of upstream message iterators.
521 g_ptr_array_add(downstream_msg_iter
->upstream_msg_iters
,
525 set_self_comp_port_input_msg_iterator_state(iterator
,
526 BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_STATE_ACTIVE
);
527 g_ptr_array_add(port
->connection
->iterators
, iterator
);
528 BT_LIB_LOGI("Created message iterator on self component input port: "
529 "%![up-port-]+p, %![up-comp-]+c, %![iter-]+i",
530 upstream_port
, upstream_comp
, iterator
);
534 BT_OBJECT_PUT_REF_AND_RESET(iterator
);
540 struct bt_self_component_port_input_message_iterator
*
541 bt_self_component_port_input_message_iterator_create_from_message_iterator(
542 struct bt_self_message_iterator
*self_msg_iter
,
543 struct bt_self_component_port_input
*input_port
)
545 BT_ASSERT_PRE_NON_NULL(self_msg_iter
, "Message iterator");
546 return create_self_component_input_port_message_iterator(self_msg_iter
,
550 struct bt_self_component_port_input_message_iterator
*
551 bt_self_component_port_input_message_iterator_create_from_sink_component(
552 struct bt_self_component_sink
*self_comp
,
553 struct bt_self_component_port_input
*input_port
)
555 BT_ASSERT_PRE_NON_NULL(self_comp
, "Sink component");
556 return create_self_component_input_port_message_iterator(NULL
,
560 void *bt_self_message_iterator_get_data(
561 const struct bt_self_message_iterator
*self_iterator
)
563 struct bt_self_component_port_input_message_iterator
*iterator
=
564 (void *) self_iterator
;
566 BT_ASSERT_PRE_DEV_NON_NULL(iterator
, "Message iterator");
567 return iterator
->user_data
;
570 void bt_self_message_iterator_set_data(
571 struct bt_self_message_iterator
*self_iterator
, void *data
)
573 struct bt_self_component_port_input_message_iterator
*iterator
=
574 (void *) self_iterator
;
576 BT_ASSERT_PRE_DEV_NON_NULL(iterator
, "Message iterator");
577 iterator
->user_data
= data
;
578 BT_LIB_LOGD("Set message iterator's user data: "
579 "%!+i, user-data-addr=%p", iterator
, data
);
583 * Validate that the default clock snapshot in `msg` doesn't make us go back in
587 BT_ASSERT_POST_DEV_FUNC
589 bool clock_snapshots_are_monotonic_one(
590 struct bt_self_component_port_input_message_iterator
*iterator
,
591 const bt_message
*msg
)
593 const struct bt_clock_snapshot
*clock_snapshot
= NULL
;
594 bt_message_type message_type
= bt_message_get_type(msg
);
595 int64_t ns_from_origin
;
596 enum bt_clock_snapshot_get_ns_from_origin_status clock_snapshot_status
;
599 * The default is true: if we can't figure out the clock snapshot
600 * (or there is none), assume it is fine.
604 switch (message_type
) {
605 case BT_MESSAGE_TYPE_EVENT
:
607 struct bt_message_event
*event_msg
= (struct bt_message_event
*) msg
;
608 clock_snapshot
= event_msg
->default_cs
;
611 case BT_MESSAGE_TYPE_MESSAGE_ITERATOR_INACTIVITY
:
613 struct bt_message_message_iterator_inactivity
*inactivity_msg
=
614 (struct bt_message_message_iterator_inactivity
*) msg
;
615 clock_snapshot
= inactivity_msg
->default_cs
;
618 case BT_MESSAGE_TYPE_PACKET_BEGINNING
:
619 case BT_MESSAGE_TYPE_PACKET_END
:
621 struct bt_message_packet
*packet_msg
= (struct bt_message_packet
*) msg
;
622 clock_snapshot
= packet_msg
->default_cs
;
625 case BT_MESSAGE_TYPE_STREAM_BEGINNING
:
626 case BT_MESSAGE_TYPE_STREAM_END
:
628 struct bt_message_stream
*stream_msg
= (struct bt_message_stream
*) msg
;
629 if (stream_msg
->default_cs_state
!= BT_MESSAGE_STREAM_CLOCK_SNAPSHOT_STATE_KNOWN
) {
633 clock_snapshot
= stream_msg
->default_cs
;
636 case BT_MESSAGE_TYPE_DISCARDED_EVENTS
:
637 case BT_MESSAGE_TYPE_DISCARDED_PACKETS
:
639 struct bt_message_discarded_items
*discarded_msg
=
640 (struct bt_message_discarded_items
*) msg
;
642 clock_snapshot
= discarded_msg
->default_begin_cs
;
647 if (!clock_snapshot
) {
651 clock_snapshot_status
= bt_clock_snapshot_get_ns_from_origin(clock_snapshot
, &ns_from_origin
);
652 if (clock_snapshot_status
!= BT_FUNC_STATUS_OK
) {
656 result
= ns_from_origin
>= iterator
->last_ns_from_origin
;
657 iterator
->last_ns_from_origin
= ns_from_origin
;
662 BT_ASSERT_POST_DEV_FUNC
664 bool clock_snapshots_are_monotonic(
665 struct bt_self_component_port_input_message_iterator
*iterator
,
666 bt_message_array_const msgs
, uint64_t msg_count
)
671 for (i
= 0; i
< msg_count
; i
++) {
672 if (!clock_snapshots_are_monotonic_one(iterator
, msgs
[i
])) {
685 * When a new stream begins, verify that the clock class tied to this
686 * stream is compatible with what we've seen before.
689 BT_ASSERT_POST_DEV_FUNC
691 bool clock_classes_are_compatible_one(struct bt_self_component_port_input_message_iterator
*iterator
,
692 const struct bt_message
*msg
)
694 enum bt_message_type message_type
= bt_message_get_type(msg
);
697 if (message_type
== BT_MESSAGE_TYPE_STREAM_BEGINNING
) {
698 const struct bt_message_stream
*stream_msg
= (struct bt_message_stream
*) msg
;
699 const struct bt_clock_class
*clock_class
= stream_msg
->stream
->class->default_clock_class
;
700 bt_uuid clock_class_uuid
= NULL
;
703 clock_class_uuid
= bt_clock_class_get_uuid(clock_class
);
706 switch (iterator
->clock_expectation
.type
) {
707 case CLOCK_EXPECTATION_UNSET
:
709 * This is the first time we see a message with a clock
710 * snapshot: record the properties of that clock, against
711 * which we'll compare the clock properties of the following
716 iterator
->clock_expectation
.type
= CLOCK_EXPECTATION_NONE
;
717 } else if (bt_clock_class_origin_is_unix_epoch(clock_class
)) {
718 iterator
->clock_expectation
.type
= CLOCK_EXPECTATION_ORIGIN_UNIX
;
719 } else if (clock_class_uuid
) {
720 iterator
->clock_expectation
.type
= CLOCK_EXPECTATION_ORIGIN_OTHER_UUID
;
721 bt_uuid_copy(iterator
->clock_expectation
.uuid
, clock_class_uuid
);
723 iterator
->clock_expectation
.type
= CLOCK_EXPECTATION_ORIGIN_OTHER_NO_UUID
;
727 case CLOCK_EXPECTATION_NONE
:
729 BT_ASSERT_POST_DEV_MSG(
730 "Expecting no clock class, got one: %![cc-]+K",
738 case CLOCK_EXPECTATION_ORIGIN_UNIX
:
740 BT_ASSERT_POST_DEV_MSG(
741 "Expecting a clock class, got none.");
746 if (!bt_clock_class_origin_is_unix_epoch(clock_class
)) {
747 BT_ASSERT_POST_DEV_MSG(
748 "Expecting a clock class with Unix epoch origin: %![cc-]+K",
755 case CLOCK_EXPECTATION_ORIGIN_OTHER_UUID
:
757 BT_ASSERT_POST_DEV_MSG(
758 "Expecting a clock class, got none.");
763 if (bt_clock_class_origin_is_unix_epoch(clock_class
)) {
764 BT_ASSERT_POST_DEV_MSG(
765 "Expecting a clock class without Unix epoch origin: %![cc-]+K",
771 if (!clock_class_uuid
) {
772 BT_ASSERT_POST_DEV_MSG(
773 "Expecting a clock class with UUID: %![cc-]+K",
779 if (bt_uuid_compare(iterator
->clock_expectation
.uuid
, clock_class_uuid
)) {
780 BT_ASSERT_POST_DEV_MSG(
781 "Expecting a clock class with UUID, got one "
782 "with a different UUID: %![cc-]+K, expected-uuid=%!u",
783 clock_class
, iterator
->clock_expectation
.uuid
);
789 case CLOCK_EXPECTATION_ORIGIN_OTHER_NO_UUID
:
791 BT_ASSERT_POST_DEV_MSG(
792 "Expecting a clock class, got none.");
797 if (bt_clock_class_origin_is_unix_epoch(clock_class
)) {
798 BT_ASSERT_POST_DEV_MSG(
799 "Expecting a clock class without Unix epoch origin: %![cc-]+K",
805 if (clock_class_uuid
) {
806 BT_ASSERT_POST_DEV_MSG(
807 "Expecting a clock class without UUID: %![cc-]+K",
822 BT_ASSERT_POST_DEV_FUNC
824 bool clock_classes_are_compatible(
825 struct bt_self_component_port_input_message_iterator
*iterator
,
826 bt_message_array_const msgs
, uint64_t msg_count
)
831 for (i
= 0; i
< msg_count
; i
++) {
832 if (!clock_classes_are_compatible_one(iterator
, msgs
[i
])) {
845 * Call the `next` method of the iterator. Do some validation on the returned
850 enum bt_component_class_message_iterator_next_method_status
851 call_iterator_next_method(
852 struct bt_self_component_port_input_message_iterator
*iterator
,
853 bt_message_array_const msgs
, uint64_t capacity
, uint64_t *user_count
)
855 enum bt_component_class_message_iterator_next_method_status status
;
857 BT_ASSERT(iterator
->methods
.next
);
858 BT_LOGD_STR("Calling user's \"next\" method.");
859 status
= iterator
->methods
.next(iterator
, msgs
, capacity
, user_count
);
860 BT_LOGD("User method returned: status=%s, msg-count=%" PRIu64
,
861 bt_common_func_status_string(status
), *user_count
);
863 if (status
== BT_FUNC_STATUS_OK
) {
864 BT_ASSERT_POST_DEV(clock_classes_are_compatible(iterator
, msgs
, *user_count
),
865 "Clocks are not compatible");
866 BT_ASSERT_POST_DEV(clock_snapshots_are_monotonic(iterator
, msgs
, *user_count
),
867 "Clock snapshots are not monotonic");
873 enum bt_message_iterator_next_status
874 bt_self_component_port_input_message_iterator_next(
875 struct bt_self_component_port_input_message_iterator
*iterator
,
876 bt_message_array_const
*msgs
, uint64_t *user_count
)
878 enum bt_message_iterator_next_status status
= BT_FUNC_STATUS_OK
;
880 BT_ASSERT_PRE_DEV_NON_NULL(iterator
, "Message iterator");
881 BT_ASSERT_PRE_DEV_NON_NULL(msgs
, "Message array (output)");
882 BT_ASSERT_PRE_DEV_NON_NULL(user_count
, "Message count (output)");
883 BT_ASSERT_PRE_DEV(iterator
->state
==
884 BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_STATE_ACTIVE
,
885 "Message iterator's \"next\" called, but "
886 "message iterator is in the wrong state: %!+i", iterator
);
887 BT_ASSERT(iterator
->upstream_component
);
888 BT_ASSERT(iterator
->upstream_component
->class);
890 bt_component_borrow_graph(iterator
->upstream_component
)->config_state
!=
891 BT_GRAPH_CONFIGURATION_STATE_CONFIGURING
,
892 "Graph is not configured: %!+g",
893 bt_component_borrow_graph(iterator
->upstream_component
));
894 BT_LIB_LOGD("Getting next self component input port "
895 "message iterator's messages: %!+i, batch-size=%u",
896 iterator
, MSG_BATCH_SIZE
);
899 * Call the user's "next" method to get the next messages
903 status
= (int) call_iterator_next_method(iterator
,
904 (void *) iterator
->base
.msgs
->pdata
, MSG_BATCH_SIZE
,
906 BT_LOGD("User method returned: status=%s, msg-count=%" PRIu64
,
907 bt_common_func_status_string(status
), *user_count
);
909 BT_LIB_LOGW_APPEND_CAUSE(
910 "Component input port message iterator's \"next\" method failed: "
911 "%![iter-]+i, status=%s",
912 iterator
, bt_common_func_status_string(status
));
917 * There is no way that this iterator could have been finalized
918 * during its "next" method, as the only way to do this is to
919 * put the last iterator's reference, and this can only be done
920 * by its downstream owner.
922 * For the same reason, there is no way that this iterator could
923 * have seeked (cannot seek a self message iterator).
925 BT_ASSERT(iterator
->state
==
926 BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_STATE_ACTIVE
);
929 case BT_FUNC_STATUS_OK
:
930 BT_ASSERT_POST_DEV(*user_count
<= MSG_BATCH_SIZE
,
931 "Invalid returned message count: greater than "
932 "batch size: count=%" PRIu64
", batch-size=%u",
933 *user_count
, MSG_BATCH_SIZE
);
934 *msgs
= (void *) iterator
->base
.msgs
->pdata
;
936 case BT_FUNC_STATUS_AGAIN
:
938 case BT_FUNC_STATUS_END
:
939 set_self_comp_port_input_msg_iterator_state(iterator
,
940 BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_STATE_ENDED
);
943 /* Unknown non-error status */
951 enum bt_message_iterator_next_status
bt_port_output_message_iterator_next(
952 struct bt_port_output_message_iterator
*iterator
,
953 bt_message_array_const
*msgs_to_user
,
954 uint64_t *count_to_user
)
956 enum bt_message_iterator_next_status status
;
959 BT_ASSERT_PRE_DEV_NON_NULL(iterator
, "Message iterator");
960 BT_ASSERT_PRE_DEV_NON_NULL(msgs_to_user
, "Message array (output)");
961 BT_ASSERT_PRE_DEV_NON_NULL(count_to_user
, "Message count (output)");
962 BT_LIB_LOGD("Getting next output port message iterator's messages: "
964 graph_status
= bt_graph_consume_sink_no_check(iterator
->graph
,
966 switch (graph_status
) {
967 case BT_FUNC_STATUS_CANCELED
:
968 case BT_FUNC_STATUS_AGAIN
:
969 case BT_FUNC_STATUS_END
:
970 case BT_FUNC_STATUS_MEMORY_ERROR
:
971 status
= (int) graph_status
;
973 case BT_FUNC_STATUS_OK
:
974 status
= BT_FUNC_STATUS_OK
;
977 * On success, the colander sink moves the messages
978 * to this iterator's array and sets this iterator's
979 * message count: move them to the user.
981 *msgs_to_user
= (void *) iterator
->base
.msgs
->pdata
;
982 *count_to_user
= iterator
->count
;
986 status
= BT_FUNC_STATUS_ERROR
;
992 struct bt_component
*
993 bt_self_component_port_input_message_iterator_borrow_component(
994 struct bt_self_component_port_input_message_iterator
*iterator
)
996 BT_ASSERT_PRE_DEV_NON_NULL(iterator
, "Message iterator");
997 return iterator
->upstream_component
;
1000 const struct bt_component
*
1001 bt_self_component_port_input_message_iterator_borrow_component_const(
1002 const struct bt_self_component_port_input_message_iterator
*iterator
)
1004 BT_ASSERT_PRE_DEV_NON_NULL(iterator
, "Message iterator");
1005 return iterator
->upstream_component
;
1008 struct bt_self_component
*bt_self_message_iterator_borrow_component(
1009 struct bt_self_message_iterator
*self_iterator
)
1011 struct bt_self_component_port_input_message_iterator
*iterator
=
1012 (void *) self_iterator
;
1014 BT_ASSERT_PRE_DEV_NON_NULL(iterator
, "Message iterator");
1015 return (void *) iterator
->upstream_component
;
1018 struct bt_self_port_output
*bt_self_message_iterator_borrow_port(
1019 struct bt_self_message_iterator
*self_iterator
)
1021 struct bt_self_component_port_input_message_iterator
*iterator
=
1022 (void *) self_iterator
;
1024 BT_ASSERT_PRE_DEV_NON_NULL(iterator
, "Message iterator");
1025 return (void *) iterator
->upstream_port
;
1029 void bt_port_output_message_iterator_destroy(struct bt_object
*obj
)
1031 struct bt_port_output_message_iterator
*iterator
= (void *) obj
;
1033 BT_LIB_LOGI("Destroying output port message iterator object: %!+i",
1035 BT_LOGD_STR("Putting graph.");
1036 BT_OBJECT_PUT_REF_AND_RESET(iterator
->graph
);
1037 BT_LOGD_STR("Putting colander sink component.");
1038 BT_OBJECT_PUT_REF_AND_RESET(iterator
->colander
);
1039 destroy_base_message_iterator(obj
);
1042 struct bt_port_output_message_iterator
*
1043 bt_port_output_message_iterator_create(struct bt_graph
*graph
,
1044 const struct bt_port_output
*output_port
)
1046 struct bt_port_output_message_iterator
*iterator
= NULL
;
1047 struct bt_component_class_sink
*colander_comp_cls
= NULL
;
1048 struct bt_component
*output_port_comp
= NULL
;
1049 struct bt_component_sink
*colander_comp
;
1051 struct bt_port_input
*colander_in_port
= NULL
;
1052 struct bt_component_class_sink_colander_data colander_data
;
1055 BT_ASSERT_PRE_NON_NULL(graph
, "Graph");
1056 BT_ASSERT_PRE_NON_NULL(output_port
, "Output port");
1057 output_port_comp
= bt_port_borrow_component_inline(
1058 (const void *) output_port
);
1059 BT_ASSERT_PRE(output_port_comp
,
1060 "Output port has no component: %!+p", output_port
);
1061 BT_ASSERT_PRE(bt_component_borrow_graph(output_port_comp
) ==
1063 "Output port is not part of graph: %![graph-]+g, %![port-]+p",
1064 graph
, output_port
);
1065 BT_ASSERT_PRE(!graph
->has_sink
,
1066 "Graph already has a sink component: %![graph-]+g");
1068 /* Create message iterator */
1069 BT_LIB_LOGI("Creating message iterator on output port: "
1070 "%![port-]+p, %![comp-]+c", output_port
, output_port_comp
);
1071 iterator
= g_new0(struct bt_port_output_message_iterator
, 1);
1073 BT_LIB_LOGE_APPEND_CAUSE(
1074 "Failed to allocate one output port message iterator.");
1078 ret
= init_message_iterator((void *) iterator
,
1079 BT_MESSAGE_ITERATOR_TYPE_PORT_OUTPUT
,
1080 bt_port_output_message_iterator_destroy
);
1082 /* init_message_iterator() logs errors */
1083 BT_OBJECT_PUT_REF_AND_RESET(iterator
);
1087 /* Create colander component */
1088 colander_comp_cls
= bt_component_class_sink_colander_get();
1089 if (!colander_comp_cls
) {
1090 /* bt_component_class_sink_colander_get() logs errors */
1091 BT_LIB_LOGE_APPEND_CAUSE(
1092 "Cannot get colander sink component class.");
1096 iterator
->graph
= graph
;
1097 bt_object_get_no_null_check(iterator
->graph
);
1098 colander_data
.msgs
= (void *) iterator
->base
.msgs
->pdata
;
1099 colander_data
.count_addr
= &iterator
->count
;
1102 * Hope that nobody uses this very unique name.
1104 * We pass `BT_LOGGING_LEVEL_NONE` but the colander component
1105 * class module does not use this level anyway since it belongs
1108 graph_status
= bt_graph_add_sink_component_with_init_method_data(
1109 (void *) graph
, colander_comp_cls
,
1110 "colander-36ac3409-b1a8-4d60-ab1f-4fdf341a8fb1",
1111 NULL
, &colander_data
, BT_LOGGING_LEVEL_NONE
,
1112 (void *) &iterator
->colander
);
1113 if (graph_status
!= BT_FUNC_STATUS_OK
) {
1114 BT_LIB_LOGE_APPEND_CAUSE(
1115 "Cannot add colander sink component to graph: "
1116 "%![graph-]+g, status=%s", graph
,
1117 bt_common_func_status_string(graph_status
));
1122 * Connect provided output port to the colander component's
1126 (void *) bt_component_sink_borrow_input_port_by_index_const(
1127 (void *) iterator
->colander
, 0);
1128 BT_ASSERT(colander_in_port
);
1129 graph_status
= bt_graph_connect_ports(graph
,
1130 output_port
, colander_in_port
, NULL
);
1131 if (graph_status
!= BT_FUNC_STATUS_OK
) {
1132 BT_LIB_LOGW_APPEND_CAUSE(
1133 "Cannot connect colander sink's port: "
1134 "%![graph-]+g, %![comp-]+c, status=%s", graph
,
1136 bt_common_func_status_string(graph_status
));
1141 * At this point everything went fine. Make the graph
1142 * nonconsumable forever so that only this message iterator
1143 * can consume (thanks to bt_graph_consume_sink_no_check()).
1144 * This avoids leaking the message created by the colander
1145 * sink and moved to the message iterator's message
1148 bt_graph_set_can_consume(iterator
->graph
, false);
1150 /* Also set the graph as being configured. */
1151 graph_status
= bt_graph_configure(graph
);
1152 if (graph_status
!= BT_FUNC_STATUS_OK
) {
1153 BT_LIB_LOGW_APPEND_CAUSE(
1154 "Cannot configure graph after having "
1155 "added and connected colander sink: "
1156 "%![graph-]+g, %![comp-]+c, status=%s", graph
,
1158 bt_common_func_status_string(graph_status
));
1164 if (iterator
&& iterator
->graph
&& iterator
->colander
) {
1167 /* Remove created colander component from graph if any */
1168 colander_comp
= iterator
->colander
;
1169 BT_OBJECT_PUT_REF_AND_RESET(iterator
->colander
);
1172 * At this point the colander component's reference
1173 * count is 0 because iterator->colander was the only
1174 * owner. We also know that it is not connected because
1175 * this is the last operation before this function
1178 * Since we honor the preconditions here,
1179 * bt_graph_remove_unconnected_component() always
1182 ret
= bt_graph_remove_unconnected_component(iterator
->graph
,
1183 (void *) colander_comp
);
1184 BT_ASSERT(ret
== 0);
1187 BT_OBJECT_PUT_REF_AND_RESET(iterator
);
1190 bt_object_put_ref(colander_comp_cls
);
1191 return (void *) iterator
;
1194 bt_bool
bt_self_component_port_input_message_iterator_can_seek_ns_from_origin(
1195 struct bt_self_component_port_input_message_iterator
*iterator
,
1196 int64_t ns_from_origin
)
1198 bt_bool can
= BT_FALSE
;
1200 BT_ASSERT_PRE_NON_NULL(iterator
, "Message iterator");
1201 BT_ASSERT_PRE_ITER_HAS_STATE_TO_SEEK(iterator
);
1203 bt_component_borrow_graph(iterator
->upstream_component
)->config_state
!=
1204 BT_GRAPH_CONFIGURATION_STATE_CONFIGURING
,
1205 "Graph is not configured: %!+g",
1206 bt_component_borrow_graph(iterator
->upstream_component
));
1208 if (iterator
->methods
.can_seek_ns_from_origin
) {
1209 can
= iterator
->methods
.can_seek_ns_from_origin(iterator
,
1215 * Automatic seeking fall back: if we can seek to the beginning,
1216 * then we can automatically seek to any message.
1218 if (iterator
->methods
.can_seek_beginning
) {
1219 can
= iterator
->methods
.can_seek_beginning(iterator
);
1226 bt_bool
bt_self_component_port_input_message_iterator_can_seek_beginning(
1227 struct bt_self_component_port_input_message_iterator
*iterator
)
1229 bt_bool can
= BT_FALSE
;
1231 BT_ASSERT_PRE_NON_NULL(iterator
, "Message iterator");
1232 BT_ASSERT_PRE_ITER_HAS_STATE_TO_SEEK(iterator
);
1234 bt_component_borrow_graph(iterator
->upstream_component
)->config_state
!=
1235 BT_GRAPH_CONFIGURATION_STATE_CONFIGURING
,
1236 "Graph is not configured: %!+g",
1237 bt_component_borrow_graph(iterator
->upstream_component
));
1239 if (iterator
->methods
.can_seek_beginning
) {
1240 can
= iterator
->methods
.can_seek_beginning(iterator
);
1247 void set_iterator_state_after_seeking(
1248 struct bt_self_component_port_input_message_iterator
*iterator
,
1251 enum bt_self_component_port_input_message_iterator_state new_state
= 0;
1253 /* Set iterator's state depending on seeking status */
1255 case BT_FUNC_STATUS_OK
:
1256 new_state
= BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_STATE_ACTIVE
;
1258 case BT_FUNC_STATUS_AGAIN
:
1259 new_state
= BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_STATE_LAST_SEEKING_RETURNED_AGAIN
;
1261 case BT_FUNC_STATUS_ERROR
:
1262 case BT_FUNC_STATUS_MEMORY_ERROR
:
1263 new_state
= BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_STATE_LAST_SEEKING_RETURNED_ERROR
;
1265 case BT_FUNC_STATUS_END
:
1266 new_state
= BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_STATE_ENDED
;
1272 set_self_comp_port_input_msg_iterator_state(iterator
, new_state
);
1276 void reset_iterator_expectations(
1277 struct bt_self_component_port_input_message_iterator
*iterator
)
1279 iterator
->last_ns_from_origin
= INT64_MIN
;
1280 iterator
->clock_expectation
.type
= CLOCK_EXPECTATION_UNSET
;
1283 enum bt_message_iterator_seek_beginning_status
1284 bt_self_component_port_input_message_iterator_seek_beginning(
1285 struct bt_self_component_port_input_message_iterator
*iterator
)
1289 BT_ASSERT_PRE_NON_NULL(iterator
, "Message iterator");
1290 BT_ASSERT_PRE_ITER_HAS_STATE_TO_SEEK(iterator
);
1292 bt_component_borrow_graph(iterator
->upstream_component
)->config_state
!=
1293 BT_GRAPH_CONFIGURATION_STATE_CONFIGURING
,
1294 "Graph is not configured: %!+g",
1295 bt_component_borrow_graph(iterator
->upstream_component
));
1297 bt_self_component_port_input_message_iterator_can_seek_beginning(
1299 "Message iterator cannot seek beginning: %!+i", iterator
);
1302 * We are seeking, reset our expectations about how the following
1303 * messages should look like.
1305 reset_iterator_expectations(iterator
);
1307 BT_LIB_LOGD("Calling user's \"seek beginning\" method: %!+i", iterator
);
1308 set_self_comp_port_input_msg_iterator_state(iterator
,
1309 BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_STATE_SEEKING
);
1310 status
= iterator
->methods
.seek_beginning(iterator
);
1311 BT_LOGD("User method returned: status=%s",
1312 bt_common_func_status_string(status
));
1313 BT_ASSERT_POST(status
== BT_FUNC_STATUS_OK
||
1314 status
== BT_FUNC_STATUS_ERROR
||
1315 status
== BT_FUNC_STATUS_MEMORY_ERROR
||
1316 status
== BT_FUNC_STATUS_AGAIN
,
1317 "Unexpected status: %![iter-]+i, status=%s",
1318 iterator
, bt_common_func_status_string(status
));
1320 BT_LIB_LOGW_APPEND_CAUSE(
1321 "Component input port message iterator's \"seek beginning\" method failed: "
1322 "%![iter-]+i, status=%s",
1323 iterator
, bt_common_func_status_string(status
));
1326 set_iterator_state_after_seeking(iterator
, status
);
1331 * Structure used to record the state of a given stream during the fast-forward
1332 * phase of an auto-seek.
1334 struct auto_seek_stream_state
{
1336 * Value representing which step of this timeline we are at.
1339 * [SB] 1 [PB] 2 [PE] 1 [SE]
1341 * At each point in the timeline, the messages we need to replicate are:
1343 * 1: Stream beginning
1344 * 2: Stream beginning, packet beginning
1346 * Before "Stream beginning" and after "Stream end", we don't need to
1347 * replicate anything as the stream doesn't exist.
1350 AUTO_SEEK_STREAM_STATE_STREAM_BEGAN
,
1351 AUTO_SEEK_STREAM_STATE_PACKET_BEGAN
,
1355 * If `state` is AUTO_SEEK_STREAM_STATE_PACKET_BEGAN, the packet we are
1356 * in. This is a weak reference, since the packet will always be
1357 * alive by the time we use it.
1359 struct bt_packet
*packet
;
1361 /* Have we see a message with a clock snapshot yet? */
1362 bool seen_clock_snapshot
;
1366 struct auto_seek_stream_state
*create_auto_seek_stream_state(void)
1368 return g_new0(struct auto_seek_stream_state
, 1);
1372 void destroy_auto_seek_stream_state(void *ptr
)
1378 GHashTable
*create_auto_seek_stream_states(void)
1380 return g_hash_table_new_full(g_direct_hash
, g_direct_equal
, NULL
,
1381 destroy_auto_seek_stream_state
);
1385 void destroy_auto_seek_stream_states(GHashTable
*stream_states
)
1387 g_hash_table_destroy(stream_states
);
1391 * Handle one message while we are in the fast-forward phase of an auto-seek.
1393 * Sets `*got_first` to true if the message's timestamp is greater or equal to
1394 * `ns_from_origin`. In other words, if this is the first message after our
1397 * `stream_states` is an hash table of `bt_stream *` (weak reference) to
1398 * `struct auto_seek_stream_state` used to keep the state of each stream
1399 * during the fast-forward.
1403 int auto_seek_handle_message(
1404 struct bt_self_component_port_input_message_iterator
*iterator
,
1405 int64_t ns_from_origin
, const struct bt_message
*msg
,
1406 bool *got_first
, GHashTable
*stream_states
)
1408 int status
= BT_FUNC_STATUS_OK
;
1409 int64_t msg_ns_from_origin
;
1410 const struct bt_clock_snapshot
*clk_snapshot
= NULL
;
1414 BT_ASSERT(got_first
);
1416 switch (msg
->type
) {
1417 case BT_MESSAGE_TYPE_EVENT
:
1419 const struct bt_message_event
*event_msg
=
1422 clk_snapshot
= event_msg
->default_cs
;
1423 BT_ASSERT_POST_DEV(clk_snapshot
,
1424 "Event message has no default clock snapshot: %!+n",
1428 case BT_MESSAGE_TYPE_MESSAGE_ITERATOR_INACTIVITY
:
1430 const struct bt_message_message_iterator_inactivity
*inactivity_msg
=
1433 clk_snapshot
= inactivity_msg
->default_cs
;
1434 BT_ASSERT(clk_snapshot
);
1437 case BT_MESSAGE_TYPE_PACKET_BEGINNING
:
1438 case BT_MESSAGE_TYPE_PACKET_END
:
1440 const struct bt_message_packet
*packet_msg
=
1443 clk_snapshot
= packet_msg
->default_cs
;
1444 BT_ASSERT_POST_DEV(clk_snapshot
,
1445 "Packet message has no default clock snapshot: %!+n",
1449 case BT_MESSAGE_TYPE_DISCARDED_EVENTS
:
1450 case BT_MESSAGE_TYPE_DISCARDED_PACKETS
:
1452 struct bt_message_discarded_items
*msg_disc_items
=
1455 BT_ASSERT_POST_DEV(msg_disc_items
->default_begin_cs
&&
1456 msg_disc_items
->default_end_cs
,
1457 "Discarded events/packets message has no default clock snapshots: %!+n",
1459 ret
= bt_clock_snapshot_get_ns_from_origin(
1460 msg_disc_items
->default_begin_cs
,
1461 &msg_ns_from_origin
);
1463 status
= BT_FUNC_STATUS_ERROR
;
1467 if (msg_ns_from_origin
>= ns_from_origin
) {
1472 ret
= bt_clock_snapshot_get_ns_from_origin(
1473 msg_disc_items
->default_end_cs
,
1474 &msg_ns_from_origin
);
1476 status
= BT_FUNC_STATUS_ERROR
;
1480 if (msg_ns_from_origin
>= ns_from_origin
) {
1482 * The discarded items message's beginning time
1483 * is before the requested seeking time, but its
1484 * end time is after. Modify the message so as
1485 * to set its beginning time to the requested
1486 * seeking time, and make its item count unknown
1487 * as we don't know if items were really
1488 * discarded within the new time range.
1490 uint64_t new_begin_raw_value
= 0;
1492 ret
= bt_clock_class_clock_value_from_ns_from_origin(
1493 msg_disc_items
->default_end_cs
->clock_class
,
1494 ns_from_origin
, &new_begin_raw_value
);
1496 status
= BT_FUNC_STATUS_ERROR
;
1500 bt_clock_snapshot_set_raw_value(
1501 msg_disc_items
->default_begin_cs
,
1502 new_begin_raw_value
);
1503 msg_disc_items
->count
.base
.avail
=
1504 BT_PROPERTY_AVAILABILITY_NOT_AVAILABLE
;
1507 * It is safe to push it because its beginning
1508 * time is exactly the requested seeking time.
1515 case BT_MESSAGE_TYPE_STREAM_BEGINNING
:
1516 case BT_MESSAGE_TYPE_STREAM_END
:
1518 struct bt_message_stream
*stream_msg
=
1519 (struct bt_message_stream
*) msg
;
1521 if (stream_msg
->default_cs_state
!= BT_MESSAGE_STREAM_CLOCK_SNAPSHOT_STATE_KNOWN
) {
1526 clk_snapshot
= stream_msg
->default_cs
;
1533 BT_ASSERT(clk_snapshot
);
1534 ret
= bt_clock_snapshot_get_ns_from_origin(clk_snapshot
,
1535 &msg_ns_from_origin
);
1537 status
= BT_FUNC_STATUS_ERROR
;
1541 if (msg_ns_from_origin
>= ns_from_origin
) {
1547 /* This message won't be sent downstream. */
1548 switch (msg
->type
) {
1549 case BT_MESSAGE_TYPE_STREAM_BEGINNING
:
1551 const struct bt_message_stream
*stream_msg
= (const void *) msg
;
1552 struct auto_seek_stream_state
*stream_state
;
1554 /* Update stream's state: stream began. */
1555 stream_state
= create_auto_seek_stream_state();
1556 if (!stream_state
) {
1557 status
= BT_FUNC_STATUS_MEMORY_ERROR
;
1561 stream_state
->state
= AUTO_SEEK_STREAM_STATE_STREAM_BEGAN
;
1563 if (stream_msg
->default_cs_state
== BT_MESSAGE_STREAM_CLOCK_SNAPSHOT_STATE_KNOWN
) {
1564 stream_state
->seen_clock_snapshot
= true;
1567 BT_ASSERT(!bt_g_hash_table_contains(stream_states
, stream_msg
->stream
));
1568 g_hash_table_insert(stream_states
, stream_msg
->stream
, stream_state
);
1571 case BT_MESSAGE_TYPE_PACKET_BEGINNING
:
1573 const struct bt_message_packet
*packet_msg
=
1575 struct auto_seek_stream_state
*stream_state
;
1577 /* Update stream's state: packet began. */
1578 stream_state
= g_hash_table_lookup(stream_states
, packet_msg
->packet
->stream
);
1579 BT_ASSERT(stream_state
);
1581 BT_ASSERT(stream_state
->state
== AUTO_SEEK_STREAM_STATE_STREAM_BEGAN
);
1582 stream_state
->state
= AUTO_SEEK_STREAM_STATE_PACKET_BEGAN
;
1583 BT_ASSERT(!stream_state
->packet
);
1584 stream_state
->packet
= packet_msg
->packet
;
1586 if (packet_msg
->packet
->stream
->class->packets_have_beginning_default_clock_snapshot
) {
1587 stream_state
->seen_clock_snapshot
= true;
1592 case BT_MESSAGE_TYPE_EVENT
:
1594 const struct bt_message_event
*event_msg
= (const void *) msg
;
1595 struct auto_seek_stream_state
*stream_state
;
1597 stream_state
= g_hash_table_lookup(stream_states
,
1598 event_msg
->event
->packet
->stream
);
1599 BT_ASSERT(stream_state
);
1601 // HELPME: are we sure that event messages have clock snapshots at this point?
1602 stream_state
->seen_clock_snapshot
= true;
1606 case BT_MESSAGE_TYPE_PACKET_END
:
1608 const struct bt_message_packet
*packet_msg
=
1610 struct auto_seek_stream_state
*stream_state
;
1612 /* Update stream's state: packet ended. */
1613 stream_state
= g_hash_table_lookup(stream_states
, packet_msg
->packet
->stream
);
1614 BT_ASSERT(stream_state
);
1616 BT_ASSERT(stream_state
->state
== AUTO_SEEK_STREAM_STATE_PACKET_BEGAN
);
1617 stream_state
->state
= AUTO_SEEK_STREAM_STATE_STREAM_BEGAN
;
1618 BT_ASSERT(stream_state
->packet
);
1619 stream_state
->packet
= NULL
;
1621 if (packet_msg
->packet
->stream
->class->packets_have_end_default_clock_snapshot
) {
1622 stream_state
->seen_clock_snapshot
= true;
1627 case BT_MESSAGE_TYPE_STREAM_END
:
1629 const struct bt_message_stream
*stream_msg
= (const void *) msg
;
1630 struct auto_seek_stream_state
*stream_state
;
1632 stream_state
= g_hash_table_lookup(stream_states
, stream_msg
->stream
);
1633 BT_ASSERT(stream_state
);
1634 BT_ASSERT(stream_state
->state
== AUTO_SEEK_STREAM_STATE_STREAM_BEGAN
);
1635 BT_ASSERT(!stream_state
->packet
);
1637 /* Update stream's state: this stream doesn't exist anymore. */
1638 g_hash_table_remove(stream_states
, stream_msg
->stream
);
1641 case BT_MESSAGE_TYPE_DISCARDED_EVENTS
:
1642 case BT_MESSAGE_TYPE_DISCARDED_PACKETS
:
1644 const struct bt_message_discarded_items
*discarded_msg
=
1646 struct auto_seek_stream_state
*stream_state
;
1648 stream_state
= g_hash_table_lookup(stream_states
, discarded_msg
->stream
);
1649 BT_ASSERT(stream_state
);
1651 if ((msg
->type
== BT_MESSAGE_TYPE_DISCARDED_EVENTS
&& discarded_msg
->stream
->class->discarded_events_have_default_clock_snapshots
) ||
1652 (msg
->type
== BT_MESSAGE_TYPE_DISCARDED_PACKETS
&& discarded_msg
->stream
->class->discarded_packets_have_default_clock_snapshots
)) {
1653 stream_state
->seen_clock_snapshot
= true;
1662 bt_object_put_no_null_check(msg
);
1667 g_queue_push_tail(iterator
->auto_seek
.msgs
, (void *) msg
);
1671 BT_ASSERT(!msg
|| status
!= BT_FUNC_STATUS_OK
);
1676 int find_message_ge_ns_from_origin(
1677 struct bt_self_component_port_input_message_iterator
*iterator
,
1678 int64_t ns_from_origin
, GHashTable
*stream_states
)
1681 enum bt_self_component_port_input_message_iterator_state init_state
=
1683 const struct bt_message
*messages
[MSG_BATCH_SIZE
];
1684 uint64_t user_count
= 0;
1686 bool got_first
= false;
1688 BT_ASSERT(iterator
);
1689 memset(&messages
[0], 0, sizeof(messages
[0]) * MSG_BATCH_SIZE
);
1692 * Make this iterator temporarily active (not seeking) to call
1693 * the "next" method.
1695 set_self_comp_port_input_msg_iterator_state(iterator
,
1696 BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_STATE_ACTIVE
);
1698 BT_ASSERT(iterator
->methods
.next
);
1700 while (!got_first
) {
1702 * Call the user's "next" method to get the next
1703 * messages and status.
1705 status
= call_iterator_next_method(iterator
,
1706 &messages
[0], MSG_BATCH_SIZE
, &user_count
);
1707 BT_LOGD("User method returned: status=%s",
1708 bt_common_func_status_string(status
));
1710 BT_LIB_LOGW_APPEND_CAUSE(
1711 "Component input port message iterator's \"next\" method failed: "
1712 "%![iter-]+i, status=%s",
1713 iterator
, bt_common_func_status_string(status
));
1717 * The user's "next" method must not do any action which
1718 * would change the iterator's state.
1720 BT_ASSERT(iterator
->state
==
1721 BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_STATE_ACTIVE
);
1724 case BT_FUNC_STATUS_OK
:
1725 BT_ASSERT_POST_DEV(user_count
<= MSG_BATCH_SIZE
,
1726 "Invalid returned message count: greater than "
1727 "batch size: count=%" PRIu64
", batch-size=%u",
1728 user_count
, MSG_BATCH_SIZE
);
1730 case BT_FUNC_STATUS_AGAIN
:
1731 case BT_FUNC_STATUS_ERROR
:
1732 case BT_FUNC_STATUS_MEMORY_ERROR
:
1733 case BT_FUNC_STATUS_END
:
1739 for (i
= 0; i
< user_count
; i
++) {
1741 g_queue_push_tail(iterator
->auto_seek
.msgs
,
1742 (void *) messages
[i
]);
1747 status
= auto_seek_handle_message(iterator
,
1748 ns_from_origin
, messages
[i
], &got_first
,
1750 if (status
== BT_FUNC_STATUS_OK
) {
1751 /* Message was either pushed or moved */
1760 for (i
= 0; i
< user_count
; i
++) {
1762 bt_object_put_no_null_check(messages
[i
]);
1766 set_self_comp_port_input_msg_iterator_state(iterator
, init_state
);
1771 * This function is installed as the iterator's next callback after we have
1772 * auto-seeked (seeked to the beginning and fast-forwarded) to send the
1773 * messages saved in iterator->auto_seek.msgs. Once this is done, the original
1774 * next callback is put back.
1778 enum bt_component_class_message_iterator_next_method_status
post_auto_seek_next(
1779 struct bt_self_component_port_input_message_iterator
*iterator
,
1780 bt_message_array_const msgs
, uint64_t capacity
,
1783 BT_ASSERT(!g_queue_is_empty(iterator
->auto_seek
.msgs
));
1787 * Move auto-seek messages to the output array (which is this
1788 * iterator's base message array).
1790 while (capacity
> 0 && !g_queue_is_empty(iterator
->auto_seek
.msgs
)) {
1791 msgs
[*count
] = g_queue_pop_head(iterator
->auto_seek
.msgs
);
1796 BT_ASSERT(*count
> 0);
1798 if (g_queue_is_empty(iterator
->auto_seek
.msgs
)) {
1799 /* No more auto-seek messages, restore user's next callback. */
1800 BT_ASSERT(iterator
->auto_seek
.original_next_callback
);
1801 iterator
->methods
.next
= iterator
->auto_seek
.original_next_callback
;
1802 iterator
->auto_seek
.original_next_callback
= NULL
;
1805 return BT_FUNC_STATUS_OK
;
1809 int clock_raw_value_from_ns_from_origin(const bt_clock_class
*clock_class
,
1810 int64_t ns_from_origin
, uint64_t *raw_value
)
1813 int64_t cc_offset_s
= clock_class
->offset_seconds
;
1814 uint64_t cc_offset_cycles
= clock_class
->offset_cycles
;
1815 uint64_t cc_freq
= clock_class
->frequency
;
1817 return bt_common_clock_value_from_ns_from_origin(cc_offset_s
,
1818 cc_offset_cycles
, cc_freq
, ns_from_origin
, raw_value
);
1822 enum bt_message_iterator_seek_ns_from_origin_status
1823 bt_self_component_port_input_message_iterator_seek_ns_from_origin(
1824 struct bt_self_component_port_input_message_iterator
*iterator
,
1825 int64_t ns_from_origin
)
1828 GHashTable
*stream_states
= NULL
;
1830 BT_ASSERT_PRE_NON_NULL(iterator
, "Message iterator");
1831 BT_ASSERT_PRE_ITER_HAS_STATE_TO_SEEK(iterator
);
1833 bt_component_borrow_graph(iterator
->upstream_component
)->config_state
!=
1834 BT_GRAPH_CONFIGURATION_STATE_CONFIGURING
,
1835 "Graph is not configured: %!+g",
1836 bt_component_borrow_graph(iterator
->upstream_component
));
1838 bt_self_component_port_input_message_iterator_can_seek_ns_from_origin(
1839 iterator
, ns_from_origin
),
1840 "Message iterator cannot seek nanoseconds from origin: %!+i, "
1841 "ns-from-origin=%" PRId64
, iterator
, ns_from_origin
);
1842 set_self_comp_port_input_msg_iterator_state(iterator
,
1843 BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_STATE_SEEKING
);
1846 * We are seeking, reset our expectations about how the following
1847 * messages should look like.
1849 reset_iterator_expectations(iterator
);
1851 if (iterator
->methods
.seek_ns_from_origin
) {
1852 /* The iterator knows how to seek to a particular time, let it handle this. */
1853 BT_LIB_LOGD("Calling user's \"seek nanoseconds from origin\" method: "
1854 "%![iter-]+i, ns=%" PRId64
, iterator
, ns_from_origin
);
1855 status
= iterator
->methods
.seek_ns_from_origin(iterator
,
1857 BT_LOGD("User method returned: status=%s",
1858 bt_common_func_status_string(status
));
1859 BT_ASSERT_POST(status
== BT_FUNC_STATUS_OK
||
1860 status
== BT_FUNC_STATUS_ERROR
||
1861 status
== BT_FUNC_STATUS_MEMORY_ERROR
||
1862 status
== BT_FUNC_STATUS_AGAIN
,
1863 "Unexpected status: %![iter-]+i, status=%s",
1864 iterator
, bt_common_func_status_string(status
));
1866 BT_LIB_LOGW_APPEND_CAUSE(
1867 "Component input port message iterator's \"seek nanoseconds from origin\" method failed: "
1868 "%![iter-]+i, status=%s",
1869 iterator
, bt_common_func_status_string(status
));
1873 * The iterator doesn't know how to seek to a particular time. We will
1874 * seek to the beginning and fast forward to the right place.
1876 BT_ASSERT(iterator
->methods
.can_seek_beginning(iterator
));
1877 BT_ASSERT(iterator
->methods
.seek_beginning
);
1878 BT_LIB_LOGD("Calling user's \"seek beginning\" method: %!+i",
1880 status
= iterator
->methods
.seek_beginning(iterator
);
1881 BT_LOGD("User method returned: status=%s",
1882 bt_common_func_status_string(status
));
1883 BT_ASSERT_POST(status
== BT_FUNC_STATUS_OK
||
1884 status
== BT_FUNC_STATUS_ERROR
||
1885 status
== BT_FUNC_STATUS_MEMORY_ERROR
||
1886 status
== BT_FUNC_STATUS_AGAIN
,
1887 "Unexpected status: %![iter-]+i, status=%s",
1888 iterator
, bt_common_func_status_string(status
));
1890 BT_LIB_LOGW_APPEND_CAUSE(
1891 "Component input port message iterator's \"seek beginning\" method failed: "
1892 "%![iter-]+i, status=%s",
1893 iterator
, bt_common_func_status_string(status
));
1897 case BT_FUNC_STATUS_OK
:
1899 case BT_FUNC_STATUS_ERROR
:
1900 case BT_FUNC_STATUS_MEMORY_ERROR
:
1901 case BT_FUNC_STATUS_AGAIN
:
1908 * Find the first message which has a default clock
1909 * snapshot greater than or equal to the requested
1910 * seeking time, and move the received messages from
1911 * this point in the batch to this iterator's auto-seek
1914 while (!g_queue_is_empty(iterator
->auto_seek
.msgs
)) {
1915 bt_object_put_no_null_check(
1916 g_queue_pop_tail(iterator
->auto_seek
.msgs
));
1919 stream_states
= create_auto_seek_stream_states();
1920 if (!stream_states
) {
1921 BT_LIB_LOGE_APPEND_CAUSE(
1922 "Failed to allocate one GHashTable.");
1923 status
= BT_FUNC_STATUS_MEMORY_ERROR
;
1927 status
= find_message_ge_ns_from_origin(iterator
,
1928 ns_from_origin
, stream_states
);
1930 case BT_FUNC_STATUS_OK
:
1931 case BT_FUNC_STATUS_END
:
1933 GHashTableIter iter
;
1934 gpointer key
, value
;
1937 * If some streams exist at the seek time, prepend the
1938 * required messages to put those streams in the right
1941 g_hash_table_iter_init(&iter
, stream_states
);
1942 while (g_hash_table_iter_next (&iter
, &key
, &value
)) {
1943 const bt_stream
*stream
= key
;
1944 struct auto_seek_stream_state
*stream_state
=
1945 (struct auto_seek_stream_state
*) value
;
1947 const bt_clock_class
*clock_class
= bt_stream_class_borrow_default_clock_class_const(
1948 bt_stream_borrow_class_const(stream
));
1949 /* Initialize to silence maybe-uninitialized warning. */
1950 uint64_t raw_value
= 0;
1953 * If we haven't seen a message with a clock snapshot, we don't know if our seek time is within
1954 * the clock's range, so it wouldn't be safe to try to convert ns_from_origin to a clock value.
1956 * Also, it would be a bit of a lie to generate a stream begin message with the seek time as its
1957 * clock snapshot, because we don't really know if the stream existed at that time. If we have
1958 * seen a message with a clock snapshot in our seeking, then we are sure that the
1959 * seek time is not below the clock range, and we know the stream was active at that
1960 * time (and that we cut it short).
1962 if (stream_state
->seen_clock_snapshot
) {
1963 if (clock_raw_value_from_ns_from_origin(clock_class
, ns_from_origin
, &raw_value
) != 0) {
1964 BT_LIB_LOGW("Could not convert nanoseconds from origin to clock value: ns-from-origin=%" PRId64
", %![cc-]+K",
1965 ns_from_origin
, clock_class
);
1966 status
= BT_FUNC_STATUS_ERROR
;
1971 switch (stream_state
->state
) {
1972 case AUTO_SEEK_STREAM_STATE_PACKET_BEGAN
:
1973 BT_ASSERT(stream_state
->packet
);
1974 BT_LIB_LOGD("Creating packet message: %![packet-]+a", stream_state
->packet
);
1976 if (stream
->class->packets_have_beginning_default_clock_snapshot
) {
1978 * If we are in the PACKET_BEGAN state, it means we have seen a "packet beginning"
1979 * message. If "packet beginning" packets have clock snapshots, then we must have
1980 * seen a clock snapshot.
1982 BT_ASSERT(stream_state
->seen_clock_snapshot
);
1984 msg
= bt_message_packet_beginning_create_with_default_clock_snapshot(
1985 (bt_self_message_iterator
*) iterator
, stream_state
->packet
, raw_value
);
1987 msg
= bt_message_packet_beginning_create((bt_self_message_iterator
*) iterator
,
1988 stream_state
->packet
);
1992 status
= BT_FUNC_STATUS_MEMORY_ERROR
;
1996 g_queue_push_head(iterator
->auto_seek
.msgs
, msg
);
2000 case AUTO_SEEK_STREAM_STATE_STREAM_BEGAN
:
2001 msg
= bt_message_stream_beginning_create(
2002 (bt_self_message_iterator
*) iterator
, stream
);
2004 status
= BT_FUNC_STATUS_MEMORY_ERROR
;
2008 if (stream_state
->seen_clock_snapshot
) {
2009 bt_message_stream_beginning_set_default_clock_snapshot(msg
, raw_value
);
2012 g_queue_push_head(iterator
->auto_seek
.msgs
, msg
);
2019 * If there are messages in the auto-seek
2020 * message queue, replace the user's "next"
2021 * method with a custom, temporary "next" method
2022 * which returns them.
2024 if (!g_queue_is_empty(iterator
->auto_seek
.msgs
)) {
2025 BT_ASSERT(!iterator
->auto_seek
.original_next_callback
);
2026 iterator
->auto_seek
.original_next_callback
= iterator
->methods
.next
;
2028 iterator
->methods
.next
=
2029 (bt_self_component_port_input_message_iterator_next_method
)
2030 post_auto_seek_next
;
2034 * `BT_FUNC_STATUS_END` becomes
2035 * `BT_FUNC_STATUS_OK`: the next
2036 * time this iterator's "next" method is called,
2038 * `BT_FUNC_STATUS_END`.
2040 status
= BT_FUNC_STATUS_OK
;
2043 case BT_FUNC_STATUS_ERROR
:
2044 case BT_FUNC_STATUS_MEMORY_ERROR
:
2045 case BT_FUNC_STATUS_AGAIN
:
2053 * The following messages returned by the next method (including
2054 * post_auto_seek_next) must be after (or at) `ns_from_origin`.
2056 iterator
->last_ns_from_origin
= ns_from_origin
;
2059 if (stream_states
) {
2060 destroy_auto_seek_stream_states(stream_states
);
2061 stream_states
= NULL
;
2064 set_iterator_state_after_seeking(iterator
, status
);
2069 bt_self_component_port_input_message_iterator
*
2070 borrow_output_port_message_iterator_upstream_iterator(
2071 struct bt_port_output_message_iterator
*iterator
)
2073 struct bt_component_class_sink_colander_priv_data
*colander_data
;
2075 BT_ASSERT(iterator
);
2076 colander_data
= (void *) iterator
->colander
->parent
.user_data
;
2077 BT_ASSERT(colander_data
);
2078 BT_ASSERT(colander_data
->msg_iter
);
2079 return colander_data
->msg_iter
;
2082 bt_bool
bt_port_output_message_iterator_can_seek_ns_from_origin(
2083 struct bt_port_output_message_iterator
*iterator
,
2084 int64_t ns_from_origin
)
2086 BT_ASSERT_PRE_NON_NULL(iterator
, "Message iterator");
2087 return bt_self_component_port_input_message_iterator_can_seek_ns_from_origin(
2088 borrow_output_port_message_iterator_upstream_iterator(
2089 iterator
), ns_from_origin
);
2092 bt_bool
bt_port_output_message_iterator_can_seek_beginning(
2093 struct bt_port_output_message_iterator
*iterator
)
2095 BT_ASSERT_PRE_NON_NULL(iterator
, "Message iterator");
2096 return bt_self_component_port_input_message_iterator_can_seek_beginning(
2097 borrow_output_port_message_iterator_upstream_iterator(
2101 enum bt_message_iterator_seek_ns_from_origin_status
2102 bt_port_output_message_iterator_seek_ns_from_origin(
2103 struct bt_port_output_message_iterator
*iterator
,
2104 int64_t ns_from_origin
)
2106 BT_ASSERT_PRE_NON_NULL(iterator
, "Message iterator");
2107 return bt_self_component_port_input_message_iterator_seek_ns_from_origin(
2108 borrow_output_port_message_iterator_upstream_iterator(iterator
),
2112 enum bt_message_iterator_seek_beginning_status
2113 bt_port_output_message_iterator_seek_beginning(
2114 struct bt_port_output_message_iterator
*iterator
)
2116 BT_ASSERT_PRE_NON_NULL(iterator
, "Message iterator");
2117 return bt_self_component_port_input_message_iterator_seek_beginning(
2118 borrow_output_port_message_iterator_upstream_iterator(
2122 void bt_port_output_message_iterator_get_ref(
2123 const struct bt_port_output_message_iterator
*iterator
)
2125 bt_object_get_ref(iterator
);
2128 void bt_port_output_message_iterator_put_ref(
2129 const struct bt_port_output_message_iterator
*iterator
)
2131 bt_object_put_ref(iterator
);
2134 void bt_self_component_port_input_message_iterator_get_ref(
2135 const struct bt_self_component_port_input_message_iterator
*iterator
)
2137 bt_object_get_ref(iterator
);
2140 void bt_self_component_port_input_message_iterator_put_ref(
2141 const struct bt_self_component_port_input_message_iterator
*iterator
)
2143 bt_object_put_ref(iterator
);