d8478553bb98c6d32005b5f38224461141564888
[babeltrace.git] / src / lib / graph / iterator.c
1 /*
2 * SPDX-License-Identifier: MIT
3 *
4 * Copyright 2017-2018 Philippe Proulx <pproulx@efficios.com>
5 * Copyright 2015 Jérémie Galarneau <jeremie.galarneau@efficios.com>
6 */
7
8 #define BT_LOG_TAG "LIB/MSG-ITER"
9 #include "lib/logging.h"
10
11 #include "compat/compiler.h"
12 #include "compat/glib.h"
13 #include "lib/trace-ir/clock-class.h"
14 #include "lib/trace-ir/clock-snapshot.h"
15 #include <babeltrace2/trace-ir/field.h>
16 #include <babeltrace2/trace-ir/event.h>
17 #include "lib/trace-ir/event.h"
18 #include <babeltrace2/trace-ir/packet.h>
19 #include "lib/trace-ir/packet.h"
20 #include "lib/trace-ir/stream.h"
21 #include <babeltrace2/trace-ir/clock-class.h>
22 #include <babeltrace2/trace-ir/stream-class.h>
23 #include <babeltrace2/trace-ir/stream.h>
24 #include <babeltrace2/graph/connection.h>
25 #include <babeltrace2/graph/component.h>
26 #include <babeltrace2/graph/message.h>
27 #include <babeltrace2/graph/self-component.h>
28 #include <babeltrace2/graph/port.h>
29 #include <babeltrace2/graph/graph.h>
30 #include <babeltrace2/graph/message-iterator.h>
31 #include <babeltrace2/types.h>
32 #include "common/assert.h"
33 #include "lib/assert-cond.h"
34 #include <stdint.h>
35 #include <inttypes.h>
36 #include <stdbool.h>
37 #include <stdlib.h>
38
39 #include "component-class.h"
40 #include "component.h"
41 #include "component-sink.h"
42 #include "component-source.h"
43 #include "connection.h"
44 #include "graph.h"
45 #include "message-iterator-class.h"
46 #include "message/discarded-items.h"
47 #include "message/event.h"
48 #include "message/iterator.h"
49 #include "message/message.h"
50 #include "message/message-iterator-inactivity.h"
51 #include "message/stream.h"
52 #include "message/packet.h"
53 #include "lib/func-status.h"
54
55 /*
56 * TODO: Use graph's state (number of active iterators, etc.) and
57 * possibly system specifications to make a better guess than this.
58 */
59 #define MSG_BATCH_SIZE 15
60
61 #define BT_ASSERT_PRE_ITER_HAS_STATE_TO_SEEK(_iter) \
62 BT_ASSERT_PRE((_iter)->state == BT_MESSAGE_ITERATOR_STATE_ACTIVE || \
63 (_iter)->state == BT_MESSAGE_ITERATOR_STATE_ENDED || \
64 (_iter)->state == BT_MESSAGE_ITERATOR_STATE_LAST_SEEKING_RETURNED_AGAIN || \
65 (_iter)->state == BT_MESSAGE_ITERATOR_STATE_LAST_SEEKING_RETURNED_ERROR, \
66 "Message iterator is in the wrong state: %!+i", _iter)
67
68 static inline
69 void set_msg_iterator_state(struct bt_message_iterator *iterator,
70 enum bt_message_iterator_state state)
71 {
72 BT_ASSERT_DBG(iterator);
73 BT_LIB_LOGD("Updating message iterator's state: new-state=%s",
74 bt_message_iterator_state_string(state));
75 iterator->state = state;
76 }
77
78 static
79 void bt_message_iterator_destroy(struct bt_object *obj)
80 {
81 struct bt_message_iterator *iterator;
82
83 BT_ASSERT(obj);
84
85 /*
86 * The message iterator's reference count is 0 if we're
87 * here. Increment it to avoid a double-destroy (possibly
88 * infinitely recursive). This could happen for example if the
89 * message iterator's finalization function does
90 * bt_object_get_ref() (or anything that causes
91 * bt_object_get_ref() to be called) on itself (ref. count goes
92 * from 0 to 1), and then bt_object_put_ref(): the reference
93 * count would go from 1 to 0 again and this function would be
94 * called again.
95 */
96 obj->ref_count++;
97 iterator = (void *) obj;
98 BT_LIB_LOGI("Destroying self component input port message iterator object: "
99 "%!+i", iterator);
100 bt_message_iterator_try_finalize(iterator);
101
102 if (iterator->connection) {
103 /*
104 * Remove ourself from the originating connection so
105 * that it does not try to finalize a dangling pointer
106 * later.
107 */
108 bt_connection_remove_iterator(iterator->connection, iterator);
109 iterator->connection = NULL;
110 }
111
112 if (iterator->auto_seek.msgs) {
113 while (!g_queue_is_empty(iterator->auto_seek.msgs)) {
114 bt_object_put_ref_no_null_check(
115 g_queue_pop_tail(iterator->auto_seek.msgs));
116 }
117
118 g_queue_free(iterator->auto_seek.msgs);
119 iterator->auto_seek.msgs = NULL;
120 }
121
122 if (iterator->upstream_msg_iters) {
123 /*
124 * At this point the message iterator is finalized, so
125 * it's detached from any upstream message iterator.
126 */
127 BT_ASSERT(iterator->upstream_msg_iters->len == 0);
128 g_ptr_array_free(iterator->upstream_msg_iters, TRUE);
129 iterator->upstream_msg_iters = NULL;
130 }
131
132 if (iterator->msgs) {
133 g_ptr_array_free(iterator->msgs, TRUE);
134 iterator->msgs = NULL;
135 }
136
137 g_free(iterator);
138 }
139
140 BT_HIDDEN
141 void bt_message_iterator_try_finalize(
142 struct bt_message_iterator *iterator)
143 {
144 uint64_t i;
145 bool call_user_finalize = true;
146
147 BT_ASSERT(iterator);
148
149 switch (iterator->state) {
150 case BT_MESSAGE_ITERATOR_STATE_NON_INITIALIZED:
151 /*
152 * If this function is called while the iterator is in the
153 * NON_INITIALIZED state, it means the user initialization
154 * method has either not been called, or has failed. We
155 * therefore don't want to call the user finalization method.
156 * However, the initialization method might have created some
157 * upstream message iterators before failing, so we want to
158 * execute the rest of this function, which unlinks the related
159 * iterators.
160 */
161 call_user_finalize = false;
162 break;
163 case BT_MESSAGE_ITERATOR_STATE_FINALIZED:
164 /* Already finalized */
165 BT_LIB_LOGD("Not finalizing message iterator: already finalized: "
166 "%!+i", iterator);
167 goto end;
168 case BT_MESSAGE_ITERATOR_STATE_FINALIZING:
169 /* Finalizing */
170 BT_LIB_LOGF("Message iterator is already being finalized: "
171 "%!+i", iterator);
172 bt_common_abort();
173 default:
174 break;
175 }
176
177 BT_LIB_LOGD("Finalizing message iterator: %!+i", iterator);
178 set_msg_iterator_state(iterator,
179 BT_MESSAGE_ITERATOR_STATE_FINALIZING);
180 BT_ASSERT(iterator->upstream_component);
181
182 /* Call user-defined destroy method */
183 if (call_user_finalize) {
184 typedef void (*method_t)(void *);
185 method_t method;
186 struct bt_component_class *comp_class =
187 iterator->upstream_component->class;
188 struct bt_component_class_with_iterator_class *class_with_iter_class;
189
190 BT_ASSERT(bt_component_class_has_message_iterator_class(comp_class));
191 class_with_iter_class = container_of(comp_class,
192 struct bt_component_class_with_iterator_class, parent);
193 method = (method_t) class_with_iter_class->msg_iter_cls->methods.finalize;
194
195 if (method) {
196 const bt_error *saved_error;
197
198 saved_error = bt_current_thread_take_error();
199
200 BT_LIB_LOGD("Calling user's finalization method: %!+i",
201 iterator);
202 method(iterator);
203
204 if (saved_error) {
205 BT_CURRENT_THREAD_MOVE_ERROR_AND_RESET(saved_error);
206 }
207 }
208 }
209
210 /* Detach upstream message iterators */
211 for (i = 0; i < iterator->upstream_msg_iters->len; i++) {
212 struct bt_message_iterator *upstream_msg_iter =
213 iterator->upstream_msg_iters->pdata[i];
214
215 upstream_msg_iter->downstream_msg_iter = NULL;
216 }
217
218 g_ptr_array_set_size(iterator->upstream_msg_iters, 0);
219
220 /* Detach downstream message iterator */
221 if (iterator->downstream_msg_iter) {
222 gboolean existed;
223
224 BT_ASSERT(iterator->downstream_msg_iter->upstream_msg_iters);
225 existed = g_ptr_array_remove_fast(
226 iterator->downstream_msg_iter->upstream_msg_iters,
227 iterator);
228 BT_ASSERT(existed);
229 }
230
231 iterator->upstream_component = NULL;
232 iterator->upstream_port = NULL;
233 set_msg_iterator_state(iterator,
234 BT_MESSAGE_ITERATOR_STATE_FINALIZED);
235 BT_LIB_LOGD("Finalized message iterator: %!+i", iterator);
236
237 end:
238 return;
239 }
240
241 BT_HIDDEN
242 void bt_message_iterator_set_connection(
243 struct bt_message_iterator *iterator,
244 struct bt_connection *connection)
245 {
246 BT_ASSERT(iterator);
247 iterator->connection = connection;
248 BT_LIB_LOGI("Set message iterator's connection: "
249 "%![iter-]+i, %![conn-]+x", iterator, connection);
250 }
251
252 static
253 enum bt_message_iterator_can_seek_beginning_status can_seek_ns_from_origin_true(
254 struct bt_message_iterator *iterator,
255 int64_t ns_from_origin, bt_bool *can_seek)
256 {
257 *can_seek = BT_TRUE;
258
259 return BT_FUNC_STATUS_OK;
260 }
261
262 static
263 enum bt_message_iterator_can_seek_beginning_status can_seek_beginning_true(
264 struct bt_message_iterator *iterator,
265 bt_bool *can_seek)
266 {
267 *can_seek = BT_TRUE;
268
269 return BT_FUNC_STATUS_OK;
270 }
271
272 static
273 int create_self_component_input_port_message_iterator(
274 struct bt_self_message_iterator *self_downstream_msg_iter,
275 struct bt_self_component_port_input *self_port,
276 struct bt_message_iterator **message_iterator)
277 {
278 bt_message_iterator_class_initialize_method init_method = NULL;
279 struct bt_message_iterator *iterator =
280 NULL;
281 struct bt_message_iterator *downstream_msg_iter =
282 (void *) self_downstream_msg_iter;
283 struct bt_port *port = (void *) self_port;
284 struct bt_port *upstream_port;
285 struct bt_component *comp;
286 struct bt_component *upstream_comp;
287 struct bt_component_class *upstream_comp_cls;
288 struct bt_component_class_with_iterator_class *upstream_comp_cls_with_iter_cls;
289 int status;
290
291 BT_ASSERT_PRE_NON_NULL(message_iterator, "Created message iterator");
292 BT_ASSERT_PRE_NON_NULL(port, "Input port");
293 comp = bt_port_borrow_component_inline(port);
294 BT_ASSERT_PRE(bt_port_is_connected(port),
295 "Input port is not connected: %![port-]+p", port);
296 BT_ASSERT_PRE(comp, "Input port is not part of a component: %![port-]+p",
297 port);
298 BT_ASSERT(port->connection);
299 upstream_port = port->connection->upstream_port;
300 BT_ASSERT(upstream_port);
301 upstream_comp = bt_port_borrow_component_inline(upstream_port);
302 BT_ASSERT(upstream_comp);
303 BT_ASSERT_PRE(
304 bt_component_borrow_graph(upstream_comp)->config_state ==
305 BT_GRAPH_CONFIGURATION_STATE_PARTIALLY_CONFIGURED ||
306 bt_component_borrow_graph(upstream_comp)->config_state ==
307 BT_GRAPH_CONFIGURATION_STATE_CONFIGURED,
308 "Graph is not configured: %!+g",
309 bt_component_borrow_graph(upstream_comp));
310 upstream_comp_cls = upstream_comp->class;
311 BT_ASSERT(upstream_comp->class->type ==
312 BT_COMPONENT_CLASS_TYPE_SOURCE ||
313 upstream_comp->class->type ==
314 BT_COMPONENT_CLASS_TYPE_FILTER);
315 BT_LIB_LOGI("Creating message iterator on self component input port: "
316 "%![up-comp-]+c, %![up-port-]+p", upstream_comp, upstream_port);
317 iterator = g_new0(
318 struct bt_message_iterator, 1);
319 if (!iterator) {
320 BT_LIB_LOGE_APPEND_CAUSE(
321 "Failed to allocate one self component input port "
322 "message iterator.");
323 status = BT_FUNC_STATUS_MEMORY_ERROR;
324 goto error;
325 }
326
327 bt_object_init_shared(&iterator->base,
328 bt_message_iterator_destroy);
329 iterator->msgs = g_ptr_array_new();
330 if (!iterator->msgs) {
331 BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate a GPtrArray.");
332 status = BT_FUNC_STATUS_MEMORY_ERROR;
333 goto error;
334 }
335
336 g_ptr_array_set_size(iterator->msgs, MSG_BATCH_SIZE);
337 iterator->last_ns_from_origin = INT64_MIN;
338 iterator->auto_seek.msgs = g_queue_new();
339 if (!iterator->auto_seek.msgs) {
340 BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate a GQueue.");
341 status = BT_FUNC_STATUS_MEMORY_ERROR;
342 goto error;
343 }
344
345 iterator->upstream_msg_iters = g_ptr_array_new();
346 if (!iterator->upstream_msg_iters) {
347 BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate a GPtrArray.");
348 status = BT_FUNC_STATUS_MEMORY_ERROR;
349 goto error;
350 }
351
352 iterator->upstream_component = upstream_comp;
353 iterator->upstream_port = upstream_port;
354 iterator->connection = iterator->upstream_port->connection;
355 iterator->graph = bt_component_borrow_graph(upstream_comp);
356 set_msg_iterator_state(iterator,
357 BT_MESSAGE_ITERATOR_STATE_NON_INITIALIZED);
358
359 /* Copy methods from the message iterator class to the message iterator. */
360 BT_ASSERT(bt_component_class_has_message_iterator_class(upstream_comp_cls));
361 upstream_comp_cls_with_iter_cls = container_of(upstream_comp_cls,
362 struct bt_component_class_with_iterator_class, parent);
363
364 iterator->methods.next =
365 (bt_message_iterator_next_method)
366 upstream_comp_cls_with_iter_cls->msg_iter_cls->methods.next;
367 iterator->methods.seek_ns_from_origin =
368 (bt_message_iterator_seek_ns_from_origin_method)
369 upstream_comp_cls_with_iter_cls->msg_iter_cls->methods.seek_ns_from_origin;
370 iterator->methods.seek_beginning =
371 (bt_message_iterator_seek_beginning_method)
372 upstream_comp_cls_with_iter_cls->msg_iter_cls->methods.seek_beginning;
373 iterator->methods.can_seek_ns_from_origin =
374 (bt_message_iterator_can_seek_ns_from_origin_method)
375 upstream_comp_cls_with_iter_cls->msg_iter_cls->methods.can_seek_ns_from_origin;
376 iterator->methods.can_seek_beginning =
377 (bt_message_iterator_can_seek_beginning_method)
378 upstream_comp_cls_with_iter_cls->msg_iter_cls->methods.can_seek_beginning;
379
380 if (iterator->methods.seek_ns_from_origin &&
381 !iterator->methods.can_seek_ns_from_origin) {
382 iterator->methods.can_seek_ns_from_origin =
383 (bt_message_iterator_can_seek_ns_from_origin_method)
384 can_seek_ns_from_origin_true;
385 }
386
387 if (iterator->methods.seek_beginning &&
388 !iterator->methods.can_seek_beginning) {
389 iterator->methods.can_seek_beginning =
390 (bt_message_iterator_can_seek_beginning_method)
391 can_seek_beginning_true;
392 }
393
394 /* Call iterator's init method. */
395 init_method = upstream_comp_cls_with_iter_cls->msg_iter_cls->methods.initialize;
396
397 if (init_method) {
398 enum bt_message_iterator_class_initialize_method_status iter_status;
399
400 BT_LIB_LOGD("Calling user's initialization method: %!+i", iterator);
401 iter_status = init_method(
402 (struct bt_self_message_iterator *) iterator,
403 &iterator->config,
404 (struct bt_self_component_port_output *) upstream_port);
405 BT_LOGD("User method returned: status=%s",
406 bt_common_func_status_string(iter_status));
407 BT_ASSERT_POST_NO_ERROR_IF_NO_ERROR_STATUS(iter_status);
408 if (iter_status != BT_FUNC_STATUS_OK) {
409 BT_LIB_LOGW_APPEND_CAUSE(
410 "Component input port message iterator initialization method failed: "
411 "%![iter-]+i, status=%s",
412 iterator,
413 bt_common_func_status_string(iter_status));
414 status = iter_status;
415 goto error;
416 }
417
418 iterator->config.frozen = true;
419 }
420
421 if (downstream_msg_iter) {
422 /* Set this message iterator's downstream message iterator */
423 iterator->downstream_msg_iter = downstream_msg_iter;
424
425 /*
426 * Add this message iterator to the downstream message
427 * iterator's array of upstream message iterators.
428 */
429 g_ptr_array_add(downstream_msg_iter->upstream_msg_iters,
430 iterator);
431 }
432
433 set_msg_iterator_state(iterator,
434 BT_MESSAGE_ITERATOR_STATE_ACTIVE);
435 g_ptr_array_add(port->connection->iterators, iterator);
436 BT_LIB_LOGI("Created message iterator on self component input port: "
437 "%![up-port-]+p, %![up-comp-]+c, %![iter-]+i",
438 upstream_port, upstream_comp, iterator);
439
440 *message_iterator = iterator;
441 status = BT_FUNC_STATUS_OK;
442 goto end;
443
444 error:
445 BT_OBJECT_PUT_REF_AND_RESET(iterator);
446
447 end:
448 return status;
449 }
450
451 bt_message_iterator_create_from_message_iterator_status
452 bt_message_iterator_create_from_message_iterator(
453 struct bt_self_message_iterator *self_msg_iter,
454 struct bt_self_component_port_input *input_port,
455 struct bt_message_iterator **message_iterator)
456 {
457 BT_ASSERT_PRE_NO_ERROR();
458 BT_ASSERT_PRE_NON_NULL(self_msg_iter, "Message iterator");
459 return create_self_component_input_port_message_iterator(self_msg_iter,
460 input_port, message_iterator);
461 }
462
463 bt_message_iterator_create_from_sink_component_status
464 bt_message_iterator_create_from_sink_component(
465 struct bt_self_component_sink *self_comp,
466 struct bt_self_component_port_input *input_port,
467 struct bt_message_iterator **message_iterator)
468 {
469 BT_ASSERT_PRE_NO_ERROR();
470 BT_ASSERT_PRE_NON_NULL(self_comp, "Sink component");
471 return create_self_component_input_port_message_iterator(NULL,
472 input_port, message_iterator);
473 }
474
475 void *bt_self_message_iterator_get_data(
476 const struct bt_self_message_iterator *self_iterator)
477 {
478 struct bt_message_iterator *iterator =
479 (void *) self_iterator;
480
481 BT_ASSERT_PRE_DEV_NON_NULL(iterator, "Message iterator");
482 return iterator->user_data;
483 }
484
485 void bt_self_message_iterator_set_data(
486 struct bt_self_message_iterator *self_iterator, void *data)
487 {
488 struct bt_message_iterator *iterator =
489 (void *) self_iterator;
490
491 BT_ASSERT_PRE_DEV_NON_NULL(iterator, "Message iterator");
492 iterator->user_data = data;
493 BT_LIB_LOGD("Set message iterator's user data: "
494 "%!+i, user-data-addr=%p", iterator, data);
495 }
496
497 void bt_self_message_iterator_configuration_set_can_seek_forward(
498 bt_self_message_iterator_configuration *config,
499 bt_bool can_seek_forward)
500 {
501 BT_ASSERT_PRE_NON_NULL(config, "Message iterator configuration");
502 BT_ASSERT_PRE_DEV_HOT(config, "Message iterator configuration", "");
503
504 config->can_seek_forward = can_seek_forward;
505 }
506
507 /*
508 * Validate that the default clock snapshot in `msg` doesn't make us go back in
509 * time.
510 */
511
512 BT_ASSERT_COND_DEV_FUNC
513 static
514 bool clock_snapshots_are_monotonic_one(
515 struct bt_message_iterator *iterator,
516 const bt_message *msg)
517 {
518 const struct bt_clock_snapshot *clock_snapshot = NULL;
519 bt_message_type message_type = bt_message_get_type(msg);
520 int64_t ns_from_origin;
521 enum bt_clock_snapshot_get_ns_from_origin_status clock_snapshot_status;
522
523 /*
524 * The default is true: if we can't figure out the clock snapshot
525 * (or there is none), assume it is fine.
526 */
527 bool result = true;
528
529 switch (message_type) {
530 case BT_MESSAGE_TYPE_EVENT:
531 {
532 struct bt_message_event *event_msg = (struct bt_message_event *) msg;
533 clock_snapshot = event_msg->default_cs;
534 break;
535 }
536 case BT_MESSAGE_TYPE_MESSAGE_ITERATOR_INACTIVITY:
537 {
538 struct bt_message_message_iterator_inactivity *inactivity_msg =
539 (struct bt_message_message_iterator_inactivity *) msg;
540 clock_snapshot = inactivity_msg->cs;
541 break;
542 }
543 case BT_MESSAGE_TYPE_PACKET_BEGINNING:
544 case BT_MESSAGE_TYPE_PACKET_END:
545 {
546 struct bt_message_packet *packet_msg = (struct bt_message_packet *) msg;
547 clock_snapshot = packet_msg->default_cs;
548 break;
549 }
550 case BT_MESSAGE_TYPE_STREAM_BEGINNING:
551 case BT_MESSAGE_TYPE_STREAM_END:
552 {
553 struct bt_message_stream *stream_msg = (struct bt_message_stream *) msg;
554 if (stream_msg->default_cs_state != BT_MESSAGE_STREAM_CLOCK_SNAPSHOT_STATE_KNOWN) {
555 goto end;
556 }
557
558 clock_snapshot = stream_msg->default_cs;
559 break;
560 }
561 case BT_MESSAGE_TYPE_DISCARDED_EVENTS:
562 case BT_MESSAGE_TYPE_DISCARDED_PACKETS:
563 {
564 struct bt_message_discarded_items *discarded_msg =
565 (struct bt_message_discarded_items *) msg;
566
567 clock_snapshot = discarded_msg->default_begin_cs;
568 break;
569 }
570 }
571
572 if (!clock_snapshot) {
573 goto end;
574 }
575
576 clock_snapshot_status = bt_clock_snapshot_get_ns_from_origin(
577 clock_snapshot, &ns_from_origin);
578 if (clock_snapshot_status != BT_FUNC_STATUS_OK) {
579 /*
580 * bt_clock_snapshot_get_ns_from_origin can return
581 * OVERFLOW_ERROR. We don't really want to report an error to
582 * our caller, so just clear it.
583 */
584 bt_current_thread_clear_error();
585 goto end;
586 }
587
588 result = ns_from_origin >= iterator->last_ns_from_origin;
589 iterator->last_ns_from_origin = ns_from_origin;
590 end:
591 return result;
592 }
593
594 BT_ASSERT_COND_DEV_FUNC
595 static
596 bool clock_snapshots_are_monotonic(
597 struct bt_message_iterator *iterator,
598 bt_message_array_const msgs, uint64_t msg_count)
599 {
600 uint64_t i;
601 bool result;
602
603 for (i = 0; i < msg_count; i++) {
604 if (!clock_snapshots_are_monotonic_one(iterator, msgs[i])) {
605 result = false;
606 goto end;
607 }
608 }
609
610 result = true;
611
612 end:
613 return result;
614 }
615
616 /*
617 * When a new stream begins, verify that the clock class tied to this
618 * stream is compatible with what we've seen before.
619 */
620
621 BT_ASSERT_COND_DEV_FUNC
622 static
623 bool clock_classes_are_compatible_one(struct bt_message_iterator *iterator,
624 const struct bt_message *msg)
625 {
626 enum bt_message_type message_type = bt_message_get_type(msg);
627 bool result;
628
629 if (message_type == BT_MESSAGE_TYPE_STREAM_BEGINNING) {
630 const struct bt_message_stream *stream_msg = (struct bt_message_stream *) msg;
631 const struct bt_clock_class *clock_class = stream_msg->stream->class->default_clock_class;
632 bt_uuid clock_class_uuid = NULL;
633
634 if (clock_class) {
635 clock_class_uuid = bt_clock_class_get_uuid(clock_class);
636 }
637
638 switch (iterator->clock_expectation.type) {
639 case CLOCK_EXPECTATION_UNSET:
640 /*
641 * This is the first time we see a message with a clock
642 * snapshot: record the properties of that clock, against
643 * which we'll compare the clock properties of the following
644 * messages.
645 */
646
647 if (!clock_class) {
648 iterator->clock_expectation.type = CLOCK_EXPECTATION_NONE;
649 } else if (bt_clock_class_origin_is_unix_epoch(clock_class)) {
650 iterator->clock_expectation.type = CLOCK_EXPECTATION_ORIGIN_UNIX;
651 } else if (clock_class_uuid) {
652 iterator->clock_expectation.type = CLOCK_EXPECTATION_ORIGIN_OTHER_UUID;
653 bt_uuid_copy(iterator->clock_expectation.uuid, clock_class_uuid);
654 } else {
655 iterator->clock_expectation.type = CLOCK_EXPECTATION_ORIGIN_OTHER_NO_UUID;
656 }
657 break;
658
659 case CLOCK_EXPECTATION_NONE:
660 if (clock_class) {
661 BT_ASSERT_COND_DEV_MSG(
662 "Expecting no clock class, got one: %![cc-]+K",
663 clock_class);
664 result = false;
665 goto end;
666 }
667
668 break;
669
670 case CLOCK_EXPECTATION_ORIGIN_UNIX:
671 if (!clock_class) {
672 BT_ASSERT_COND_DEV_MSG(
673 "Expecting a clock class, got none.");
674 result = false;
675 goto end;
676 }
677
678 if (!bt_clock_class_origin_is_unix_epoch(clock_class)) {
679 BT_ASSERT_COND_DEV_MSG(
680 "Expecting a clock class with Unix epoch origin: %![cc-]+K",
681 clock_class);
682 result = false;
683 goto end;
684 }
685 break;
686
687 case CLOCK_EXPECTATION_ORIGIN_OTHER_UUID:
688 if (!clock_class) {
689 BT_ASSERT_COND_DEV_MSG(
690 "Expecting a clock class, got none.");
691 result = false;
692 goto end;
693 }
694
695 if (bt_clock_class_origin_is_unix_epoch(clock_class)) {
696 BT_ASSERT_COND_DEV_MSG(
697 "Expecting a clock class without Unix epoch origin: %![cc-]+K",
698 clock_class);
699 result = false;
700 goto end;
701 }
702
703 if (!clock_class_uuid) {
704 BT_ASSERT_COND_DEV_MSG(
705 "Expecting a clock class with UUID: %![cc-]+K",
706 clock_class);
707 result = false;
708 goto end;
709 }
710
711 if (bt_uuid_compare(iterator->clock_expectation.uuid, clock_class_uuid)) {
712 BT_ASSERT_COND_DEV_MSG(
713 "Expecting a clock class with UUID, got one "
714 "with a different UUID: %![cc-]+K, expected-uuid=%!u",
715 clock_class, iterator->clock_expectation.uuid);
716 result = false;
717 goto end;
718 }
719 break;
720
721 case CLOCK_EXPECTATION_ORIGIN_OTHER_NO_UUID:
722 if (!clock_class) {
723 BT_ASSERT_COND_DEV_MSG(
724 "Expecting a clock class, got none.");
725 result = false;
726 goto end;
727 }
728
729 if (bt_clock_class_origin_is_unix_epoch(clock_class)) {
730 BT_ASSERT_COND_DEV_MSG(
731 "Expecting a clock class without Unix epoch origin: %![cc-]+K",
732 clock_class);
733 result = false;
734 goto end;
735 }
736
737 if (clock_class_uuid) {
738 BT_ASSERT_COND_DEV_MSG(
739 "Expecting a clock class without UUID: %![cc-]+K",
740 clock_class);
741 result = false;
742 goto end;
743 }
744 break;
745 }
746 }
747
748 result = true;
749
750 end:
751 return result;
752 }
753
754 BT_ASSERT_COND_DEV_FUNC
755 static
756 bool clock_classes_are_compatible(
757 struct bt_message_iterator *iterator,
758 bt_message_array_const msgs, uint64_t msg_count)
759 {
760 uint64_t i;
761 bool result;
762
763 for (i = 0; i < msg_count; i++) {
764 if (!clock_classes_are_compatible_one(iterator, msgs[i])) {
765 result = false;
766 goto end;
767 }
768 }
769
770 result = true;
771
772 end:
773 return result;
774 }
775
776 /*
777 * Call the `next` method of the iterator. Do some validation on the returned
778 * messages.
779 */
780
781 static
782 enum bt_message_iterator_class_next_method_status
783 call_iterator_next_method(
784 struct bt_message_iterator *iterator,
785 bt_message_array_const msgs, uint64_t capacity, uint64_t *user_count)
786 {
787 enum bt_message_iterator_class_next_method_status status;
788
789 BT_ASSERT_DBG(iterator->methods.next);
790 BT_LOGD_STR("Calling user's \"next\" method.");
791 status = iterator->methods.next(iterator, msgs, capacity, user_count);
792 BT_LOGD("User method returned: status=%s, msg-count=%" PRIu64,
793 bt_common_func_status_string(status), *user_count);
794
795 if (status == BT_FUNC_STATUS_OK) {
796 BT_ASSERT_POST_DEV(clock_classes_are_compatible(iterator, msgs, *user_count),
797 "Clocks are not compatible");
798 BT_ASSERT_POST_DEV(clock_snapshots_are_monotonic(iterator, msgs, *user_count),
799 "Clock snapshots are not monotonic");
800 }
801
802 BT_ASSERT_POST_DEV_NO_ERROR_IF_NO_ERROR_STATUS(status);
803
804 return status;
805 }
806
807 enum bt_message_iterator_next_status
808 bt_message_iterator_next(
809 struct bt_message_iterator *iterator,
810 bt_message_array_const *msgs, uint64_t *user_count)
811 {
812 enum bt_message_iterator_next_status status = BT_FUNC_STATUS_OK;
813
814 BT_ASSERT_PRE_DEV_NO_ERROR();
815 BT_ASSERT_PRE_DEV_NON_NULL(iterator, "Message iterator");
816 BT_ASSERT_PRE_DEV_NON_NULL(msgs, "Message array (output)");
817 BT_ASSERT_PRE_DEV_NON_NULL(user_count, "Message count (output)");
818 BT_ASSERT_PRE_DEV(iterator->state ==
819 BT_MESSAGE_ITERATOR_STATE_ACTIVE,
820 "Message iterator's \"next\" called, but "
821 "message iterator is in the wrong state: %!+i", iterator);
822 BT_ASSERT_DBG(iterator->upstream_component);
823 BT_ASSERT_DBG(iterator->upstream_component->class);
824 BT_ASSERT_PRE_DEV(
825 bt_component_borrow_graph(iterator->upstream_component)->config_state !=
826 BT_GRAPH_CONFIGURATION_STATE_CONFIGURING,
827 "Graph is not configured: %!+g",
828 bt_component_borrow_graph(iterator->upstream_component));
829 BT_LIB_LOGD("Getting next self component input port "
830 "message iterator's messages: %!+i, batch-size=%u",
831 iterator, MSG_BATCH_SIZE);
832
833 /*
834 * Call the user's "next" method to get the next messages
835 * and status.
836 */
837 *user_count = 0;
838 status = (int) call_iterator_next_method(iterator,
839 (void *) iterator->msgs->pdata, MSG_BATCH_SIZE,
840 user_count);
841 BT_LOGD("User method returned: status=%s, msg-count=%" PRIu64,
842 bt_common_func_status_string(status), *user_count);
843 if (status < 0) {
844 BT_LIB_LOGW_APPEND_CAUSE(
845 "Component input port message iterator's \"next\" method failed: "
846 "%![iter-]+i, status=%s",
847 iterator, bt_common_func_status_string(status));
848 goto end;
849 }
850
851 /*
852 * There is no way that this iterator could have been finalized
853 * during its "next" method, as the only way to do this is to
854 * put the last iterator's reference, and this can only be done
855 * by its downstream owner.
856 *
857 * For the same reason, there is no way that this iterator could
858 * have seeked (cannot seek a self message iterator).
859 */
860 BT_ASSERT_DBG(iterator->state ==
861 BT_MESSAGE_ITERATOR_STATE_ACTIVE);
862
863 switch (status) {
864 case BT_FUNC_STATUS_OK:
865 BT_ASSERT_POST_DEV(*user_count <= MSG_BATCH_SIZE,
866 "Invalid returned message count: greater than "
867 "batch size: count=%" PRIu64 ", batch-size=%u",
868 *user_count, MSG_BATCH_SIZE);
869 *msgs = (void *) iterator->msgs->pdata;
870 break;
871 case BT_FUNC_STATUS_AGAIN:
872 goto end;
873 case BT_FUNC_STATUS_END:
874 set_msg_iterator_state(iterator,
875 BT_MESSAGE_ITERATOR_STATE_ENDED);
876 goto end;
877 default:
878 /* Unknown non-error status */
879 bt_common_abort();
880 }
881
882 end:
883 return status;
884 }
885
886 struct bt_component *
887 bt_message_iterator_borrow_component(
888 struct bt_message_iterator *iterator)
889 {
890 BT_ASSERT_PRE_DEV_NON_NULL(iterator, "Message iterator");
891 return iterator->upstream_component;
892 }
893
894 struct bt_self_component *bt_self_message_iterator_borrow_component(
895 struct bt_self_message_iterator *self_iterator)
896 {
897 struct bt_message_iterator *iterator =
898 (void *) self_iterator;
899
900 BT_ASSERT_PRE_DEV_NON_NULL(iterator, "Message iterator");
901 return (void *) iterator->upstream_component;
902 }
903
904 struct bt_self_component_port_output *bt_self_message_iterator_borrow_port(
905 struct bt_self_message_iterator *self_iterator)
906 {
907 struct bt_message_iterator *iterator =
908 (void *) self_iterator;
909
910 BT_ASSERT_PRE_DEV_NON_NULL(iterator, "Message iterator");
911 return (void *) iterator->upstream_port;
912 }
913
914 enum bt_message_iterator_can_seek_ns_from_origin_status
915 bt_message_iterator_can_seek_ns_from_origin(
916 struct bt_message_iterator *iterator,
917 int64_t ns_from_origin, bt_bool *can_seek)
918 {
919 enum bt_message_iterator_can_seek_ns_from_origin_status status;
920
921 BT_ASSERT_PRE_NO_ERROR();
922 BT_ASSERT_PRE_NON_NULL(iterator, "Message iterator");
923 BT_ASSERT_PRE_NON_NULL(can_seek, "Result (output)");
924 BT_ASSERT_PRE_ITER_HAS_STATE_TO_SEEK(iterator);
925 BT_ASSERT_PRE(
926 bt_component_borrow_graph(iterator->upstream_component)->config_state !=
927 BT_GRAPH_CONFIGURATION_STATE_CONFIGURING,
928 "Graph is not configured: %!+g",
929 bt_component_borrow_graph(iterator->upstream_component));
930
931 if (iterator->methods.can_seek_ns_from_origin) {
932 /*
933 * Initialize to an invalid value, so we can post-assert that
934 * the method returned a valid value.
935 */
936 *can_seek = -1;
937
938 BT_LIB_LOGD("Calling user's \"can seek nanoseconds from origin\" method: %!+i",
939 iterator);
940
941 status = (int) iterator->methods.can_seek_ns_from_origin(iterator,
942 ns_from_origin, can_seek);
943
944 BT_ASSERT_POST_NO_ERROR_IF_NO_ERROR_STATUS(status);
945
946 if (status != BT_FUNC_STATUS_OK) {
947 BT_LIB_LOGW_APPEND_CAUSE(
948 "Component input port message iterator's \"can seek nanoseconds from origin\" method failed: "
949 "%![iter-]+i, status=%s",
950 iterator, bt_common_func_status_string(status));
951 goto end;
952 }
953
954 BT_ASSERT_POST(*can_seek == BT_TRUE || *can_seek == BT_FALSE,
955 "Unexpected boolean value returned from user's \"can seek ns from origin\" method: val=%d, %![iter-]+i",
956 *can_seek, iterator);
957
958 BT_LIB_LOGD(
959 "User's \"can seek nanoseconds from origin\" returned successfully: "
960 "%![iter-]+i, can-seek=%d",
961 iterator, *can_seek);
962
963 if (*can_seek) {
964 goto end;
965 }
966 }
967
968 /*
969 * Automatic seeking fall back: if we can seek to the beginning and the
970 * iterator supports forward seeking then we can automatically seek to
971 * any timestamp.
972 */
973 status = (int) bt_message_iterator_can_seek_beginning(
974 iterator, can_seek);
975 if (status != BT_FUNC_STATUS_OK) {
976 goto end;
977 }
978
979 *can_seek = *can_seek && iterator->config.can_seek_forward;
980
981 end:
982 return status;
983 }
984
985 enum bt_message_iterator_can_seek_beginning_status
986 bt_message_iterator_can_seek_beginning(
987 struct bt_message_iterator *iterator,
988 bt_bool *can_seek)
989 {
990 enum bt_message_iterator_can_seek_beginning_status status;
991
992 BT_ASSERT_PRE_NO_ERROR();
993 BT_ASSERT_PRE_NON_NULL(iterator, "Message iterator");
994 BT_ASSERT_PRE_NON_NULL(can_seek, "Result (output)");
995 BT_ASSERT_PRE_ITER_HAS_STATE_TO_SEEK(iterator);
996 BT_ASSERT_PRE(
997 bt_component_borrow_graph(iterator->upstream_component)->config_state !=
998 BT_GRAPH_CONFIGURATION_STATE_CONFIGURING,
999 "Graph is not configured: %!+g",
1000 bt_component_borrow_graph(iterator->upstream_component));
1001
1002 if (iterator->methods.can_seek_beginning) {
1003 /*
1004 * Initialize to an invalid value, so we can post-assert that
1005 * the method returned a valid value.
1006 */
1007 *can_seek = -1;
1008
1009 status = (int) iterator->methods.can_seek_beginning(iterator, can_seek);
1010
1011 BT_ASSERT_POST(
1012 status != BT_FUNC_STATUS_OK ||
1013 *can_seek == BT_TRUE ||
1014 *can_seek == BT_FALSE,
1015 "Unexpected boolean value returned from user's \"can seek beginning\" method: val=%d, %![iter-]+i",
1016 *can_seek, iterator);
1017 BT_ASSERT_POST_NO_ERROR_IF_NO_ERROR_STATUS(status);
1018 } else {
1019 *can_seek = BT_FALSE;
1020 status = BT_FUNC_STATUS_OK;
1021 }
1022
1023 return status;
1024 }
1025
1026 static inline
1027 void set_iterator_state_after_seeking(
1028 struct bt_message_iterator *iterator,
1029 int status)
1030 {
1031 enum bt_message_iterator_state new_state = 0;
1032
1033 /* Set iterator's state depending on seeking status */
1034 switch (status) {
1035 case BT_FUNC_STATUS_OK:
1036 new_state = BT_MESSAGE_ITERATOR_STATE_ACTIVE;
1037 break;
1038 case BT_FUNC_STATUS_AGAIN:
1039 new_state = BT_MESSAGE_ITERATOR_STATE_LAST_SEEKING_RETURNED_AGAIN;
1040 break;
1041 case BT_FUNC_STATUS_ERROR:
1042 case BT_FUNC_STATUS_MEMORY_ERROR:
1043 new_state = BT_MESSAGE_ITERATOR_STATE_LAST_SEEKING_RETURNED_ERROR;
1044 break;
1045 case BT_FUNC_STATUS_END:
1046 new_state = BT_MESSAGE_ITERATOR_STATE_ENDED;
1047 break;
1048 default:
1049 bt_common_abort();
1050 }
1051
1052 set_msg_iterator_state(iterator, new_state);
1053 }
1054
1055 static
1056 void reset_iterator_expectations(
1057 struct bt_message_iterator *iterator)
1058 {
1059 iterator->last_ns_from_origin = INT64_MIN;
1060 iterator->clock_expectation.type = CLOCK_EXPECTATION_UNSET;
1061 }
1062
1063 static
1064 bool message_iterator_can_seek_beginning(
1065 struct bt_message_iterator *iterator)
1066 {
1067 enum bt_message_iterator_can_seek_beginning_status status;
1068 bt_bool can_seek;
1069
1070 status = bt_message_iterator_can_seek_beginning(
1071 iterator, &can_seek);
1072 if (status != BT_FUNC_STATUS_OK) {
1073 can_seek = BT_FALSE;
1074 }
1075
1076 return can_seek;
1077 }
1078
1079 enum bt_message_iterator_seek_beginning_status
1080 bt_message_iterator_seek_beginning(
1081 struct bt_message_iterator *iterator)
1082 {
1083 int status;
1084
1085 BT_ASSERT_PRE_NO_ERROR();
1086 BT_ASSERT_PRE_NON_NULL(iterator, "Message iterator");
1087 BT_ASSERT_PRE_ITER_HAS_STATE_TO_SEEK(iterator);
1088 BT_ASSERT_PRE(
1089 bt_component_borrow_graph(iterator->upstream_component)->config_state !=
1090 BT_GRAPH_CONFIGURATION_STATE_CONFIGURING,
1091 "Graph is not configured: %!+g",
1092 bt_component_borrow_graph(iterator->upstream_component));
1093 BT_ASSERT_PRE(message_iterator_can_seek_beginning(iterator),
1094 "Message iterator cannot seek beginning: %!+i", iterator);
1095
1096 /*
1097 * We are seeking, reset our expectations about how the following
1098 * messages should look like.
1099 */
1100 reset_iterator_expectations(iterator);
1101
1102 BT_LIB_LOGD("Calling user's \"seek beginning\" method: %!+i", iterator);
1103 set_msg_iterator_state(iterator,
1104 BT_MESSAGE_ITERATOR_STATE_SEEKING);
1105 status = iterator->methods.seek_beginning(iterator);
1106 BT_LOGD("User method returned: status=%s",
1107 bt_common_func_status_string(status));
1108 BT_ASSERT_POST(status == BT_FUNC_STATUS_OK ||
1109 status == BT_FUNC_STATUS_ERROR ||
1110 status == BT_FUNC_STATUS_MEMORY_ERROR ||
1111 status == BT_FUNC_STATUS_AGAIN,
1112 "Unexpected status: %![iter-]+i, status=%s",
1113 iterator, bt_common_func_status_string(status));
1114 BT_ASSERT_POST_NO_ERROR_IF_NO_ERROR_STATUS(status);
1115 if (status < 0) {
1116 BT_LIB_LOGW_APPEND_CAUSE(
1117 "Component input port message iterator's \"seek beginning\" method failed: "
1118 "%![iter-]+i, status=%s",
1119 iterator, bt_common_func_status_string(status));
1120 }
1121
1122 set_iterator_state_after_seeking(iterator, status);
1123 return status;
1124 }
1125
1126 bt_bool
1127 bt_message_iterator_can_seek_forward(
1128 bt_message_iterator *iterator)
1129 {
1130 BT_ASSERT_PRE_NON_NULL(iterator, "Message iterator");
1131
1132 return iterator->config.can_seek_forward;
1133 }
1134
1135 /*
1136 * Structure used to record the state of a given stream during the fast-forward
1137 * phase of an auto-seek.
1138 */
1139 struct auto_seek_stream_state {
1140 /*
1141 * Value representing which step of this timeline we are at.
1142 *
1143 * time --->
1144 * [SB] 1 [PB] 2 [PE] 1 [SE]
1145 *
1146 * At each point in the timeline, the messages we need to replicate are:
1147 *
1148 * 1: Stream beginning
1149 * 2: Stream beginning, packet beginning
1150 *
1151 * Before "Stream beginning" and after "Stream end", we don't need to
1152 * replicate anything as the stream doesn't exist.
1153 */
1154 enum {
1155 AUTO_SEEK_STREAM_STATE_STREAM_BEGAN,
1156 AUTO_SEEK_STREAM_STATE_PACKET_BEGAN,
1157 } state;
1158
1159 /*
1160 * If `state` is AUTO_SEEK_STREAM_STATE_PACKET_BEGAN, the packet we are
1161 * in. This is a weak reference, since the packet will always be
1162 * alive by the time we use it.
1163 */
1164 struct bt_packet *packet;
1165
1166 /* Have we see a message with a clock snapshot yet? */
1167 bool seen_clock_snapshot;
1168 };
1169
1170 static
1171 struct auto_seek_stream_state *create_auto_seek_stream_state(void)
1172 {
1173 return g_new0(struct auto_seek_stream_state, 1);
1174 }
1175
1176 static
1177 void destroy_auto_seek_stream_state(void *ptr)
1178 {
1179 g_free(ptr);
1180 }
1181
1182 static
1183 GHashTable *create_auto_seek_stream_states(void)
1184 {
1185 return g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL,
1186 destroy_auto_seek_stream_state);
1187 }
1188
1189 static
1190 void destroy_auto_seek_stream_states(GHashTable *stream_states)
1191 {
1192 g_hash_table_destroy(stream_states);
1193 }
1194
1195 /*
1196 * Handle one message while we are in the fast-forward phase of an auto-seek.
1197 *
1198 * Sets `*got_first` to true if the message's timestamp is greater or equal to
1199 * `ns_from_origin`. In other words, if this is the first message after our
1200 * seek point.
1201 *
1202 * `stream_states` is an hash table of `bt_stream *` (weak reference) to
1203 * `struct auto_seek_stream_state` used to keep the state of each stream
1204 * during the fast-forward.
1205 */
1206
1207 static inline
1208 int auto_seek_handle_message(
1209 struct bt_message_iterator *iterator,
1210 int64_t ns_from_origin, const struct bt_message *msg,
1211 bool *got_first, GHashTable *stream_states)
1212 {
1213 int status = BT_FUNC_STATUS_OK;
1214 int64_t msg_ns_from_origin;
1215 const struct bt_clock_snapshot *clk_snapshot = NULL;
1216 int ret;
1217
1218 BT_ASSERT_DBG(msg);
1219 BT_ASSERT_DBG(got_first);
1220
1221 switch (msg->type) {
1222 case BT_MESSAGE_TYPE_EVENT:
1223 {
1224 const struct bt_message_event *event_msg =
1225 (const void *) msg;
1226
1227 clk_snapshot = event_msg->default_cs;
1228 BT_ASSERT_POST_DEV(clk_snapshot,
1229 "Event message has no default clock snapshot: %!+n",
1230 event_msg);
1231 break;
1232 }
1233 case BT_MESSAGE_TYPE_MESSAGE_ITERATOR_INACTIVITY:
1234 {
1235 const struct bt_message_message_iterator_inactivity *inactivity_msg =
1236 (const void *) msg;
1237
1238 clk_snapshot = inactivity_msg->cs;
1239 BT_ASSERT_DBG(clk_snapshot);
1240 break;
1241 }
1242 case BT_MESSAGE_TYPE_PACKET_BEGINNING:
1243 case BT_MESSAGE_TYPE_PACKET_END:
1244 {
1245 const struct bt_message_packet *packet_msg =
1246 (const void *) msg;
1247
1248 clk_snapshot = packet_msg->default_cs;
1249 BT_ASSERT_POST_DEV(clk_snapshot,
1250 "Packet message has no default clock snapshot: %!+n",
1251 packet_msg);
1252 break;
1253 }
1254 case BT_MESSAGE_TYPE_DISCARDED_EVENTS:
1255 case BT_MESSAGE_TYPE_DISCARDED_PACKETS:
1256 {
1257 struct bt_message_discarded_items *msg_disc_items =
1258 (void *) msg;
1259
1260 BT_ASSERT_POST_DEV(msg_disc_items->default_begin_cs &&
1261 msg_disc_items->default_end_cs,
1262 "Discarded events/packets message has no default clock snapshots: %!+n",
1263 msg_disc_items);
1264 ret = bt_clock_snapshot_get_ns_from_origin(
1265 msg_disc_items->default_begin_cs,
1266 &msg_ns_from_origin);
1267 if (ret) {
1268 status = BT_FUNC_STATUS_ERROR;
1269 goto end;
1270 }
1271
1272 if (msg_ns_from_origin >= ns_from_origin) {
1273 *got_first = true;
1274 goto push_msg;
1275 }
1276
1277 ret = bt_clock_snapshot_get_ns_from_origin(
1278 msg_disc_items->default_end_cs,
1279 &msg_ns_from_origin);
1280 if (ret) {
1281 status = BT_FUNC_STATUS_ERROR;
1282 goto end;
1283 }
1284
1285 if (msg_ns_from_origin >= ns_from_origin) {
1286 /*
1287 * The discarded items message's beginning time
1288 * is before the requested seeking time, but its
1289 * end time is after. Modify the message so as
1290 * to set its beginning time to the requested
1291 * seeking time, and make its item count unknown
1292 * as we don't know if items were really
1293 * discarded within the new time range.
1294 */
1295 uint64_t new_begin_raw_value = 0;
1296
1297 ret = bt_clock_class_clock_value_from_ns_from_origin(
1298 msg_disc_items->default_end_cs->clock_class,
1299 ns_from_origin, &new_begin_raw_value);
1300 if (ret) {
1301 status = BT_FUNC_STATUS_ERROR;
1302 goto end;
1303 }
1304
1305 bt_clock_snapshot_set_raw_value(
1306 msg_disc_items->default_begin_cs,
1307 new_begin_raw_value);
1308 msg_disc_items->count.base.avail =
1309 BT_PROPERTY_AVAILABILITY_NOT_AVAILABLE;
1310
1311 /*
1312 * It is safe to push it because its beginning
1313 * time is exactly the requested seeking time.
1314 */
1315 goto push_msg;
1316 } else {
1317 goto skip_msg;
1318 }
1319 }
1320 case BT_MESSAGE_TYPE_STREAM_BEGINNING:
1321 case BT_MESSAGE_TYPE_STREAM_END:
1322 {
1323 struct bt_message_stream *stream_msg =
1324 (struct bt_message_stream *) msg;
1325
1326 if (stream_msg->default_cs_state != BT_MESSAGE_STREAM_CLOCK_SNAPSHOT_STATE_KNOWN) {
1327 /* Ignore */
1328 goto skip_msg;
1329 }
1330
1331 clk_snapshot = stream_msg->default_cs;
1332 break;
1333 }
1334 default:
1335 bt_common_abort();
1336 }
1337
1338 BT_ASSERT_DBG(clk_snapshot);
1339 ret = bt_clock_snapshot_get_ns_from_origin(clk_snapshot,
1340 &msg_ns_from_origin);
1341 if (ret) {
1342 status = BT_FUNC_STATUS_ERROR;
1343 goto end;
1344 }
1345
1346 if (msg_ns_from_origin >= ns_from_origin) {
1347 *got_first = true;
1348 goto push_msg;
1349 }
1350
1351 skip_msg:
1352 /* This message won't be sent downstream. */
1353 switch (msg->type) {
1354 case BT_MESSAGE_TYPE_STREAM_BEGINNING:
1355 {
1356 const struct bt_message_stream *stream_msg = (const void *) msg;
1357 struct auto_seek_stream_state *stream_state;
1358
1359 /* Update stream's state: stream began. */
1360 stream_state = create_auto_seek_stream_state();
1361 if (!stream_state) {
1362 status = BT_FUNC_STATUS_MEMORY_ERROR;
1363 goto end;
1364 }
1365
1366 stream_state->state = AUTO_SEEK_STREAM_STATE_STREAM_BEGAN;
1367
1368 if (stream_msg->default_cs_state == BT_MESSAGE_STREAM_CLOCK_SNAPSHOT_STATE_KNOWN) {
1369 stream_state->seen_clock_snapshot = true;
1370 }
1371
1372 BT_ASSERT_DBG(!bt_g_hash_table_contains(stream_states, stream_msg->stream));
1373 g_hash_table_insert(stream_states, stream_msg->stream, stream_state);
1374 break;
1375 }
1376 case BT_MESSAGE_TYPE_PACKET_BEGINNING:
1377 {
1378 const struct bt_message_packet *packet_msg =
1379 (const void *) msg;
1380 struct auto_seek_stream_state *stream_state;
1381
1382 /* Update stream's state: packet began. */
1383 stream_state = g_hash_table_lookup(stream_states, packet_msg->packet->stream);
1384 BT_ASSERT_DBG(stream_state);
1385 BT_ASSERT_DBG(stream_state->state == AUTO_SEEK_STREAM_STATE_STREAM_BEGAN);
1386 stream_state->state = AUTO_SEEK_STREAM_STATE_PACKET_BEGAN;
1387 BT_ASSERT_DBG(!stream_state->packet);
1388 stream_state->packet = packet_msg->packet;
1389
1390 if (packet_msg->packet->stream->class->packets_have_beginning_default_clock_snapshot) {
1391 stream_state->seen_clock_snapshot = true;
1392 }
1393
1394 break;
1395 }
1396 case BT_MESSAGE_TYPE_EVENT:
1397 {
1398 const struct bt_message_event *event_msg = (const void *) msg;
1399 struct auto_seek_stream_state *stream_state;
1400
1401 stream_state = g_hash_table_lookup(stream_states,
1402 event_msg->event->stream);
1403 BT_ASSERT_DBG(stream_state);
1404
1405 // HELPME: are we sure that event messages have clock snapshots at this point?
1406 stream_state->seen_clock_snapshot = true;
1407
1408 break;
1409 }
1410 case BT_MESSAGE_TYPE_PACKET_END:
1411 {
1412 const struct bt_message_packet *packet_msg =
1413 (const void *) msg;
1414 struct auto_seek_stream_state *stream_state;
1415
1416 /* Update stream's state: packet ended. */
1417 stream_state = g_hash_table_lookup(stream_states, packet_msg->packet->stream);
1418 BT_ASSERT_DBG(stream_state);
1419 BT_ASSERT_DBG(stream_state->state == AUTO_SEEK_STREAM_STATE_PACKET_BEGAN);
1420 stream_state->state = AUTO_SEEK_STREAM_STATE_STREAM_BEGAN;
1421 BT_ASSERT_DBG(stream_state->packet);
1422 stream_state->packet = NULL;
1423
1424 if (packet_msg->packet->stream->class->packets_have_end_default_clock_snapshot) {
1425 stream_state->seen_clock_snapshot = true;
1426 }
1427
1428 break;
1429 }
1430 case BT_MESSAGE_TYPE_STREAM_END:
1431 {
1432 const struct bt_message_stream *stream_msg = (const void *) msg;
1433 struct auto_seek_stream_state *stream_state;
1434
1435 stream_state = g_hash_table_lookup(stream_states, stream_msg->stream);
1436 BT_ASSERT_DBG(stream_state);
1437 BT_ASSERT_DBG(stream_state->state == AUTO_SEEK_STREAM_STATE_STREAM_BEGAN);
1438 BT_ASSERT_DBG(!stream_state->packet);
1439
1440 /* Update stream's state: this stream doesn't exist anymore. */
1441 g_hash_table_remove(stream_states, stream_msg->stream);
1442 break;
1443 }
1444 case BT_MESSAGE_TYPE_DISCARDED_EVENTS:
1445 case BT_MESSAGE_TYPE_DISCARDED_PACKETS:
1446 {
1447 const struct bt_message_discarded_items *discarded_msg =
1448 (const void *) msg;
1449 struct auto_seek_stream_state *stream_state;
1450
1451 stream_state = g_hash_table_lookup(stream_states, discarded_msg->stream);
1452 BT_ASSERT_DBG(stream_state);
1453
1454 if ((msg->type == BT_MESSAGE_TYPE_DISCARDED_EVENTS && discarded_msg->stream->class->discarded_events_have_default_clock_snapshots) ||
1455 (msg->type == BT_MESSAGE_TYPE_DISCARDED_PACKETS && discarded_msg->stream->class->discarded_packets_have_default_clock_snapshots)) {
1456 stream_state->seen_clock_snapshot = true;
1457 }
1458
1459 break;
1460 }
1461 default:
1462 break;
1463 }
1464
1465 bt_object_put_ref_no_null_check(msg);
1466 msg = NULL;
1467 goto end;
1468
1469 push_msg:
1470 g_queue_push_tail(iterator->auto_seek.msgs, (void *) msg);
1471 msg = NULL;
1472
1473 end:
1474 BT_ASSERT_DBG(!msg || status != BT_FUNC_STATUS_OK);
1475 return status;
1476 }
1477
1478 static
1479 int find_message_ge_ns_from_origin(
1480 struct bt_message_iterator *iterator,
1481 int64_t ns_from_origin, GHashTable *stream_states)
1482 {
1483 int status = BT_FUNC_STATUS_OK;
1484 enum bt_message_iterator_state init_state =
1485 iterator->state;
1486 const struct bt_message *messages[MSG_BATCH_SIZE];
1487 uint64_t user_count = 0;
1488 uint64_t i;
1489 bool got_first = false;
1490
1491 BT_ASSERT_DBG(iterator);
1492 memset(&messages[0], 0, sizeof(messages[0]) * MSG_BATCH_SIZE);
1493
1494 /*
1495 * Make this iterator temporarily active (not seeking) to call
1496 * the "next" method.
1497 */
1498 set_msg_iterator_state(iterator,
1499 BT_MESSAGE_ITERATOR_STATE_ACTIVE);
1500
1501 BT_ASSERT_DBG(iterator->methods.next);
1502
1503 while (!got_first) {
1504 /*
1505 * Call the user's "next" method to get the next
1506 * messages and status.
1507 */
1508 status = call_iterator_next_method(iterator,
1509 &messages[0], MSG_BATCH_SIZE, &user_count);
1510 BT_LOGD("User method returned: status=%s",
1511 bt_common_func_status_string(status));
1512 if (status < 0) {
1513 BT_LIB_LOGW_APPEND_CAUSE(
1514 "Component input port message iterator's \"next\" method failed: "
1515 "%![iter-]+i, status=%s",
1516 iterator, bt_common_func_status_string(status));
1517 }
1518
1519 /*
1520 * The user's "next" method must not do any action which
1521 * would change the iterator's state.
1522 */
1523 BT_ASSERT_DBG(iterator->state ==
1524 BT_MESSAGE_ITERATOR_STATE_ACTIVE);
1525
1526 switch (status) {
1527 case BT_FUNC_STATUS_OK:
1528 BT_ASSERT_POST_DEV(user_count <= MSG_BATCH_SIZE,
1529 "Invalid returned message count: greater than "
1530 "batch size: count=%" PRIu64 ", batch-size=%u",
1531 user_count, MSG_BATCH_SIZE);
1532 break;
1533 case BT_FUNC_STATUS_AGAIN:
1534 case BT_FUNC_STATUS_ERROR:
1535 case BT_FUNC_STATUS_MEMORY_ERROR:
1536 case BT_FUNC_STATUS_END:
1537 goto end;
1538 default:
1539 bt_common_abort();
1540 }
1541
1542 for (i = 0; i < user_count; i++) {
1543 if (got_first) {
1544 g_queue_push_tail(iterator->auto_seek.msgs,
1545 (void *) messages[i]);
1546 messages[i] = NULL;
1547 continue;
1548 }
1549
1550 status = auto_seek_handle_message(iterator,
1551 ns_from_origin, messages[i], &got_first,
1552 stream_states);
1553 if (status == BT_FUNC_STATUS_OK) {
1554 /* Message was either pushed or moved */
1555 messages[i] = NULL;
1556 } else {
1557 goto end;
1558 }
1559 }
1560 }
1561
1562 end:
1563 for (i = 0; i < user_count; i++) {
1564 if (messages[i]) {
1565 bt_object_put_ref_no_null_check(messages[i]);
1566 }
1567 }
1568
1569 set_msg_iterator_state(iterator, init_state);
1570 return status;
1571 }
1572
1573 /*
1574 * This function is installed as the iterator's next callback after we have
1575 * auto-seeked (seeked to the beginning and fast-forwarded) to send the
1576 * messages saved in iterator->auto_seek.msgs. Once this is done, the original
1577 * next callback is put back.
1578 */
1579
1580 static
1581 enum bt_message_iterator_class_next_method_status post_auto_seek_next(
1582 struct bt_message_iterator *iterator,
1583 bt_message_array_const msgs, uint64_t capacity,
1584 uint64_t *count)
1585 {
1586 BT_ASSERT(!g_queue_is_empty(iterator->auto_seek.msgs));
1587 *count = 0;
1588
1589 /*
1590 * Move auto-seek messages to the output array (which is this
1591 * iterator's base message array).
1592 */
1593 while (capacity > 0 && !g_queue_is_empty(iterator->auto_seek.msgs)) {
1594 msgs[*count] = g_queue_pop_head(iterator->auto_seek.msgs);
1595 capacity--;
1596 (*count)++;
1597 }
1598
1599 BT_ASSERT(*count > 0);
1600
1601 if (g_queue_is_empty(iterator->auto_seek.msgs)) {
1602 /* No more auto-seek messages, restore user's next callback. */
1603 BT_ASSERT(iterator->auto_seek.original_next_callback);
1604 iterator->methods.next = iterator->auto_seek.original_next_callback;
1605 iterator->auto_seek.original_next_callback = NULL;
1606 }
1607
1608 return BT_FUNC_STATUS_OK;
1609 }
1610
1611 static inline
1612 int clock_raw_value_from_ns_from_origin(const bt_clock_class *clock_class,
1613 int64_t ns_from_origin, uint64_t *raw_value)
1614 {
1615
1616 int64_t cc_offset_s = clock_class->offset_seconds;
1617 uint64_t cc_offset_cycles = clock_class->offset_cycles;
1618 uint64_t cc_freq = clock_class->frequency;
1619
1620 return bt_common_clock_value_from_ns_from_origin(cc_offset_s,
1621 cc_offset_cycles, cc_freq, ns_from_origin, raw_value);
1622 }
1623
1624 static
1625 bool message_iterator_can_seek_ns_from_origin(
1626 struct bt_message_iterator *iterator,
1627 int64_t ns_from_origin)
1628 {
1629 enum bt_message_iterator_can_seek_ns_from_origin_status status;
1630 bt_bool can_seek;
1631
1632 status = bt_message_iterator_can_seek_ns_from_origin(
1633 iterator, ns_from_origin, &can_seek);
1634 if (status != BT_FUNC_STATUS_OK) {
1635 can_seek = BT_FALSE;
1636 }
1637
1638 return can_seek;
1639 }
1640
1641 enum bt_message_iterator_seek_ns_from_origin_status
1642 bt_message_iterator_seek_ns_from_origin(
1643 struct bt_message_iterator *iterator,
1644 int64_t ns_from_origin)
1645 {
1646 int status;
1647 GHashTable *stream_states = NULL;
1648 bt_bool can_seek_by_itself;
1649
1650 BT_ASSERT_PRE_NO_ERROR();
1651 BT_ASSERT_PRE_NON_NULL(iterator, "Message iterator");
1652 BT_ASSERT_PRE_ITER_HAS_STATE_TO_SEEK(iterator);
1653 BT_ASSERT_PRE(
1654 bt_component_borrow_graph(iterator->upstream_component)->config_state !=
1655 BT_GRAPH_CONFIGURATION_STATE_CONFIGURING,
1656 "Graph is not configured: %!+g",
1657 bt_component_borrow_graph(iterator->upstream_component));
1658 /* The iterator must be able to seek ns from origin one way or another. */
1659 BT_ASSERT_PRE(
1660 message_iterator_can_seek_ns_from_origin(iterator, ns_from_origin),
1661 "Message iterator cannot seek nanoseconds from origin: %!+i, "
1662 "ns-from-origin=%" PRId64, iterator, ns_from_origin);
1663 set_msg_iterator_state(iterator,
1664 BT_MESSAGE_ITERATOR_STATE_SEEKING);
1665
1666 /*
1667 * We are seeking, reset our expectations about how the following
1668 * messages should look like.
1669 */
1670 reset_iterator_expectations(iterator);
1671
1672 /* Check if the iterator can seek by itself. If not we'll use autoseek. */
1673 if (iterator->methods.can_seek_ns_from_origin) {
1674 bt_message_iterator_class_can_seek_ns_from_origin_method_status
1675 can_seek_status;
1676
1677 can_seek_status =
1678 iterator->methods.can_seek_ns_from_origin(
1679 iterator, ns_from_origin, &can_seek_by_itself);
1680 if (can_seek_status != BT_FUNC_STATUS_OK) {
1681 status = can_seek_status;
1682 goto end;
1683 }
1684 } else {
1685 can_seek_by_itself = false;
1686 }
1687
1688 if (can_seek_by_itself) {
1689 /* The iterator knows how to seek to a particular time, let it handle this. */
1690 BT_ASSERT(iterator->methods.seek_ns_from_origin);
1691 BT_LIB_LOGD("Calling user's \"seek nanoseconds from origin\" method: "
1692 "%![iter-]+i, ns=%" PRId64, iterator, ns_from_origin);
1693 status = iterator->methods.seek_ns_from_origin(iterator,
1694 ns_from_origin);
1695 BT_LOGD("User method returned: status=%s",
1696 bt_common_func_status_string(status));
1697 BT_ASSERT_POST(status == BT_FUNC_STATUS_OK ||
1698 status == BT_FUNC_STATUS_ERROR ||
1699 status == BT_FUNC_STATUS_MEMORY_ERROR ||
1700 status == BT_FUNC_STATUS_AGAIN,
1701 "Unexpected status: %![iter-]+i, status=%s",
1702 iterator, bt_common_func_status_string(status));
1703 BT_ASSERT_POST_NO_ERROR_IF_NO_ERROR_STATUS(status);
1704 if (status < 0) {
1705 BT_LIB_LOGW_APPEND_CAUSE(
1706 "Component input port message iterator's \"seek nanoseconds from origin\" method failed: "
1707 "%![iter-]+i, status=%s",
1708 iterator, bt_common_func_status_string(status));
1709 }
1710 } else {
1711 /*
1712 * The iterator doesn't know how to seek by itself to a
1713 * particular time. We will seek to the beginning and fast
1714 * forward to the right place.
1715 */
1716 enum bt_message_iterator_class_can_seek_beginning_method_status can_seek_status;
1717 bt_bool can_seek_beginning;
1718
1719 can_seek_status = iterator->methods.can_seek_beginning(iterator,
1720 &can_seek_beginning);
1721 BT_ASSERT(can_seek_status == BT_FUNC_STATUS_OK);
1722 BT_ASSERT(can_seek_beginning);
1723 BT_ASSERT(iterator->methods.seek_beginning);
1724 BT_LIB_LOGD("Calling user's \"seek beginning\" method: %!+i",
1725 iterator);
1726 status = iterator->methods.seek_beginning(iterator);
1727 BT_LOGD("User method returned: status=%s",
1728 bt_common_func_status_string(status));
1729 BT_ASSERT_POST(status == BT_FUNC_STATUS_OK ||
1730 status == BT_FUNC_STATUS_ERROR ||
1731 status == BT_FUNC_STATUS_MEMORY_ERROR ||
1732 status == BT_FUNC_STATUS_AGAIN,
1733 "Unexpected status: %![iter-]+i, status=%s",
1734 iterator, bt_common_func_status_string(status));
1735 if (status < 0) {
1736 BT_LIB_LOGW_APPEND_CAUSE(
1737 "Component input port message iterator's \"seek beginning\" method failed: "
1738 "%![iter-]+i, status=%s",
1739 iterator, bt_common_func_status_string(status));
1740 }
1741
1742 switch (status) {
1743 case BT_FUNC_STATUS_OK:
1744 break;
1745 case BT_FUNC_STATUS_ERROR:
1746 case BT_FUNC_STATUS_MEMORY_ERROR:
1747 case BT_FUNC_STATUS_AGAIN:
1748 goto end;
1749 default:
1750 bt_common_abort();
1751 }
1752
1753 /*
1754 * Find the first message which has a default clock
1755 * snapshot greater than or equal to the requested
1756 * seeking time, and move the received messages from
1757 * this point in the batch to this iterator's auto-seek
1758 * message queue.
1759 */
1760 while (!g_queue_is_empty(iterator->auto_seek.msgs)) {
1761 bt_object_put_ref_no_null_check(
1762 g_queue_pop_tail(iterator->auto_seek.msgs));
1763 }
1764
1765 stream_states = create_auto_seek_stream_states();
1766 if (!stream_states) {
1767 BT_LIB_LOGE_APPEND_CAUSE(
1768 "Failed to allocate one GHashTable.");
1769 status = BT_FUNC_STATUS_MEMORY_ERROR;
1770 goto end;
1771 }
1772
1773 status = find_message_ge_ns_from_origin(iterator,
1774 ns_from_origin, stream_states);
1775 switch (status) {
1776 case BT_FUNC_STATUS_OK:
1777 case BT_FUNC_STATUS_END:
1778 {
1779 GHashTableIter iter;
1780 gpointer key, value;
1781
1782 /*
1783 * If some streams exist at the seek time, prepend the
1784 * required messages to put those streams in the right
1785 * state.
1786 */
1787 g_hash_table_iter_init(&iter, stream_states);
1788 while (g_hash_table_iter_next (&iter, &key, &value)) {
1789 const bt_stream *stream = key;
1790 struct auto_seek_stream_state *stream_state =
1791 (struct auto_seek_stream_state *) value;
1792 bt_message *msg;
1793 const bt_clock_class *clock_class = bt_stream_class_borrow_default_clock_class_const(
1794 bt_stream_borrow_class_const(stream));
1795 /* Initialize to silence maybe-uninitialized warning. */
1796 uint64_t raw_value = 0;
1797
1798 /*
1799 * If we haven't seen a message with a clock snapshot, we don't know if our seek time is within
1800 * the clock's range, so it wouldn't be safe to try to convert ns_from_origin to a clock value.
1801 *
1802 * Also, it would be a bit of a lie to generate a stream begin message with the seek time as its
1803 * clock snapshot, because we don't really know if the stream existed at that time. If we have
1804 * seen a message with a clock snapshot in our seeking, then we are sure that the
1805 * seek time is not below the clock range, and we know the stream was active at that
1806 * time (and that we cut it short).
1807 */
1808 if (stream_state->seen_clock_snapshot) {
1809 if (clock_raw_value_from_ns_from_origin(clock_class, ns_from_origin, &raw_value) != 0) {
1810 BT_LIB_LOGW("Could not convert nanoseconds from origin to clock value: ns-from-origin=%" PRId64 ", %![cc-]+K",
1811 ns_from_origin, clock_class);
1812 status = BT_FUNC_STATUS_ERROR;
1813 goto end;
1814 }
1815 }
1816
1817 switch (stream_state->state) {
1818 case AUTO_SEEK_STREAM_STATE_PACKET_BEGAN:
1819 BT_ASSERT(stream_state->packet);
1820 BT_LIB_LOGD("Creating packet message: %![packet-]+a", stream_state->packet);
1821
1822 if (stream->class->packets_have_beginning_default_clock_snapshot) {
1823 /*
1824 * If we are in the PACKET_BEGAN state, it means we have seen a "packet beginning"
1825 * message. If "packet beginning" packets have clock snapshots, then we must have
1826 * seen a clock snapshot.
1827 */
1828 BT_ASSERT(stream_state->seen_clock_snapshot);
1829
1830 msg = bt_message_packet_beginning_create_with_default_clock_snapshot(
1831 (bt_self_message_iterator *) iterator, stream_state->packet, raw_value);
1832 } else {
1833 msg = bt_message_packet_beginning_create((bt_self_message_iterator *) iterator,
1834 stream_state->packet);
1835 }
1836
1837 if (!msg) {
1838 status = BT_FUNC_STATUS_MEMORY_ERROR;
1839 goto end;
1840 }
1841
1842 g_queue_push_head(iterator->auto_seek.msgs, msg);
1843 msg = NULL;
1844 /* fall-thru */
1845
1846 case AUTO_SEEK_STREAM_STATE_STREAM_BEGAN:
1847 msg = bt_message_stream_beginning_create(
1848 (bt_self_message_iterator *) iterator, stream);
1849 if (!msg) {
1850 status = BT_FUNC_STATUS_MEMORY_ERROR;
1851 goto end;
1852 }
1853
1854 if (stream_state->seen_clock_snapshot) {
1855 bt_message_stream_beginning_set_default_clock_snapshot(msg, raw_value);
1856 }
1857
1858 g_queue_push_head(iterator->auto_seek.msgs, msg);
1859 msg = NULL;
1860 break;
1861 }
1862 }
1863
1864 /*
1865 * If there are messages in the auto-seek
1866 * message queue, replace the user's "next"
1867 * method with a custom, temporary "next" method
1868 * which returns them.
1869 */
1870 if (!g_queue_is_empty(iterator->auto_seek.msgs)) {
1871 BT_ASSERT(!iterator->auto_seek.original_next_callback);
1872 iterator->auto_seek.original_next_callback = iterator->methods.next;
1873
1874 iterator->methods.next =
1875 (bt_message_iterator_next_method)
1876 post_auto_seek_next;
1877 }
1878
1879 /*
1880 * `BT_FUNC_STATUS_END` becomes
1881 * `BT_FUNC_STATUS_OK`: the next
1882 * time this iterator's "next" method is called,
1883 * it will return
1884 * `BT_FUNC_STATUS_END`.
1885 */
1886 status = BT_FUNC_STATUS_OK;
1887 break;
1888 }
1889 case BT_FUNC_STATUS_ERROR:
1890 case BT_FUNC_STATUS_MEMORY_ERROR:
1891 case BT_FUNC_STATUS_AGAIN:
1892 goto end;
1893 default:
1894 bt_common_abort();
1895 }
1896 }
1897
1898 /*
1899 * The following messages returned by the next method (including
1900 * post_auto_seek_next) must be after (or at) `ns_from_origin`.
1901 */
1902 iterator->last_ns_from_origin = ns_from_origin;
1903
1904 end:
1905 if (stream_states) {
1906 destroy_auto_seek_stream_states(stream_states);
1907 stream_states = NULL;
1908 }
1909
1910 set_iterator_state_after_seeking(iterator, status);
1911 return status;
1912 }
1913
1914 bt_bool bt_self_message_iterator_is_interrupted(
1915 const struct bt_self_message_iterator *self_msg_iter)
1916 {
1917 const struct bt_message_iterator *iterator =
1918 (const void *) self_msg_iter;
1919
1920 BT_ASSERT_PRE_NON_NULL(iterator, "Message iterator");
1921 return (bt_bool) bt_graph_is_interrupted(iterator->graph);
1922 }
1923
1924 void bt_message_iterator_get_ref(
1925 const struct bt_message_iterator *iterator)
1926 {
1927 bt_object_get_ref(iterator);
1928 }
1929
1930 void bt_message_iterator_put_ref(
1931 const struct bt_message_iterator *iterator)
1932 {
1933 bt_object_put_ref(iterator);
1934 }
This page took 0.065958 seconds and 3 git commands to generate.