Logging: standardize logging tags
[babeltrace.git] / src / plugins / utils / muxer / muxer.c
CommitLineData
958f7d11
PP
1/*
2 * Copyright 2017 Philippe Proulx <pproulx@efficios.com>
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to deal
6 * in the Software without restriction, including without limitation the rights
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 * copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 * SOFTWARE.
21 */
22
350ad6c1 23#define BT_LOG_TAG "PLUGIN/FLT.UTILS.MUXER"
fed72692
PP
24#include "logging.h"
25
91d81473 26#include "common/macros.h"
578e048b 27#include "compat/uuid.h"
3fadfbc0 28#include <babeltrace2/babeltrace.h>
578e048b
MJ
29#include "lib/value.h"
30#include "lib/graph/component.h"
31#include "lib/graph/message/iterator.h"
32#include "lib/graph/connection.h"
958f7d11 33#include <glib.h>
c55a9f58 34#include <stdbool.h>
fed72692 35#include <inttypes.h>
578e048b
MJ
36#include "common/assert.h"
37#include "common/common.h"
0fbb9a9f 38#include <stdlib.h>
282c8cd0 39#include <string.h>
958f7d11 40
fdf0b89e
FD
41#include "muxer.h"
42
c3acd5f3 43#define ASSUME_ABSOLUTE_CLOCK_CLASSES_PARAM_NAME "assume-absolute-clock-classes"
65ee897d 44
958f7d11 45struct muxer_comp {
958f7d11 46 /* Weak ref */
b19ff26f 47 bt_self_component_filter *self_comp;
d94d92ac 48
958f7d11
PP
49 unsigned int next_port_num;
50 size_t available_input_ports;
d6e69534 51 bool initializing_muxer_msg_iter;
282c8cd0 52 bool assume_absolute_clock_classes;
958f7d11
PP
53};
54
d6e69534 55struct muxer_upstream_msg_iter {
ab11110e 56 /* Owned by this, NULL if ended */
d6e69534 57 bt_self_component_port_input_message_iterator *msg_iter;
958f7d11 58
d6e69534
PP
59 /* Contains `const bt_message *`, owned by this */
60 GQueue *msgs;
958f7d11
PP
61};
62
d6e69534
PP
63enum muxer_msg_iter_clock_class_expectation {
64 MUXER_MSG_ITER_CLOCK_CLASS_EXPECTATION_ANY = 0,
60f3d027 65 MUXER_MSG_ITER_CLOCK_CLASS_EXPECTATION_NONE,
d6e69534
PP
66 MUXER_MSG_ITER_CLOCK_CLASS_EXPECTATION_ABSOLUTE,
67 MUXER_MSG_ITER_CLOCK_CLASS_EXPECTATION_NOT_ABS_SPEC_UUID,
68 MUXER_MSG_ITER_CLOCK_CLASS_EXPECTATION_NOT_ABS_NO_UUID,
282c8cd0
PP
69};
70
d6e69534 71struct muxer_msg_iter {
ab11110e 72 /*
d6e69534 73 * Array of struct muxer_upstream_msg_iter * (owned by this).
ab11110e
PP
74 *
75 * NOTE: This array is searched in linearly to find the youngest
d6e69534 76 * current message. Keep this until benchmarks confirm that
ab11110e
PP
77 * another data structure is faster than this for our typical
78 * use cases.
79 */
54bdc1f7
PP
80 GPtrArray *active_muxer_upstream_msg_iters;
81
82 /*
83 * Array of struct muxer_upstream_msg_iter * (owned by this).
84 *
85 * We move ended message iterators from
86 * `active_muxer_upstream_msg_iters` to this array so as to be
87 * able to restore them when seeking.
88 */
89 GPtrArray *ended_muxer_upstream_msg_iters;
958f7d11 90
d6e69534 91 /* Last time returned in a message */
958f7d11 92 int64_t last_returned_ts_ns;
282c8cd0
PP
93
94 /* Clock class expectation state */
d6e69534 95 enum muxer_msg_iter_clock_class_expectation clock_class_expectation;
282c8cd0
PP
96
97 /*
98 * Expected clock class UUID, only valid when
99 * clock_class_expectation is
d6e69534 100 * MUXER_MSG_ITER_CLOCK_CLASS_EXPECTATION_NOT_ABS_SPEC_UUID.
282c8cd0
PP
101 */
102 unsigned char expected_clock_class_uuid[BABELTRACE_UUID_LEN];
958f7d11
PP
103};
104
54bdc1f7
PP
105static
106void empty_message_queue(struct muxer_upstream_msg_iter *upstream_msg_iter)
107{
108 const bt_message *msg;
109
110 while ((msg = g_queue_pop_head(upstream_msg_iter->msgs))) {
111 bt_message_put_ref(msg);
112 }
113}
114
ab11110e 115static
d6e69534
PP
116void destroy_muxer_upstream_msg_iter(
117 struct muxer_upstream_msg_iter *muxer_upstream_msg_iter)
ab11110e 118{
d6e69534 119 if (!muxer_upstream_msg_iter) {
ab11110e
PP
120 return;
121 }
122
d6e69534
PP
123 BT_LOGD("Destroying muxer's upstream message iterator wrapper: "
124 "addr=%p, msg-iter-addr=%p, queue-len=%u",
125 muxer_upstream_msg_iter,
126 muxer_upstream_msg_iter->msg_iter,
127 muxer_upstream_msg_iter->msgs->length);
54bdc1f7
PP
128 bt_self_component_port_input_message_iterator_put_ref(
129 muxer_upstream_msg_iter->msg_iter);
d4393e08 130
d6e69534 131 if (muxer_upstream_msg_iter->msgs) {
54bdc1f7 132 empty_message_queue(muxer_upstream_msg_iter);
d6e69534 133 g_queue_free(muxer_upstream_msg_iter->msgs);
d4393e08
PP
134 }
135
d6e69534 136 g_free(muxer_upstream_msg_iter);
ab11110e
PP
137}
138
958f7d11 139static
c61018b9 140int muxer_msg_iter_add_upstream_msg_iter(struct muxer_msg_iter *muxer_msg_iter,
d6e69534 141 bt_self_component_port_input_message_iterator *self_msg_iter)
958f7d11 142{
c61018b9 143 int ret = 0;
d6e69534
PP
144 struct muxer_upstream_msg_iter *muxer_upstream_msg_iter =
145 g_new0(struct muxer_upstream_msg_iter, 1);
958f7d11 146
d6e69534
PP
147 if (!muxer_upstream_msg_iter) {
148 BT_LOGE_STR("Failed to allocate one muxer's upstream message iterator wrapper.");
6c20f4a0 149 goto error;
958f7d11
PP
150 }
151
d6e69534
PP
152 muxer_upstream_msg_iter->msg_iter = self_msg_iter;
153 bt_self_component_port_input_message_iterator_get_ref(muxer_upstream_msg_iter->msg_iter);
154 muxer_upstream_msg_iter->msgs = g_queue_new();
155 if (!muxer_upstream_msg_iter->msgs) {
d4393e08 156 BT_LOGE_STR("Failed to allocate a GQueue.");
6c20f4a0 157 goto error;
d4393e08
PP
158 }
159
54bdc1f7 160 g_ptr_array_add(muxer_msg_iter->active_muxer_upstream_msg_iters,
d6e69534
PP
161 muxer_upstream_msg_iter);
162 BT_LOGD("Added muxer's upstream message iterator wrapper: "
163 "addr=%p, muxer-msg-iter-addr=%p, msg-iter-addr=%p",
164 muxer_upstream_msg_iter, muxer_msg_iter,
165 self_msg_iter);
958f7d11 166
6c20f4a0
FD
167 goto end;
168
169error:
170 g_free(muxer_upstream_msg_iter);
c61018b9 171 ret = -1;
6c20f4a0 172
958f7d11 173end:
c61018b9 174 return ret;
958f7d11
PP
175}
176
958f7d11 177static
5badd463 178bt_self_component_status add_available_input_port(
b19ff26f 179 bt_self_component_filter *self_comp)
958f7d11 180{
d94d92ac 181 struct muxer_comp *muxer_comp = bt_self_component_get_data(
707b7d35 182 bt_self_component_filter_as_self_component(self_comp));
4cdfc5e8 183 bt_self_component_status status = BT_SELF_COMPONENT_STATUS_OK;
958f7d11 184 GString *port_name = NULL;
958f7d11 185
f6ccaed9 186 BT_ASSERT(muxer_comp);
958f7d11
PP
187 port_name = g_string_new("in");
188 if (!port_name) {
fed72692 189 BT_LOGE_STR("Failed to allocate a GString.");
d94d92ac 190 status = BT_SELF_COMPONENT_STATUS_NOMEM;
958f7d11
PP
191 goto end;
192 }
193
194 g_string_append_printf(port_name, "%u", muxer_comp->next_port_num);
d94d92ac
PP
195 status = bt_self_component_filter_add_input_port(
196 self_comp, port_name->str, NULL, NULL);
197 if (status != BT_SELF_COMPONENT_STATUS_OK) {
fed72692
PP
198 BT_LOGE("Cannot add input port to muxer component: "
199 "port-name=\"%s\", comp-addr=%p, status=%s",
d94d92ac
PP
200 port_name->str, self_comp,
201 bt_self_component_status_string(status));
958f7d11
PP
202 goto end;
203 }
204
205 muxer_comp->available_input_ports++;
206 muxer_comp->next_port_num++;
3f7d4d90 207 BT_LOGI("Added one input port to muxer component: "
fed72692 208 "port-name=\"%s\", comp-addr=%p",
d94d92ac 209 port_name->str, self_comp);
5badd463 210
958f7d11
PP
211end:
212 if (port_name) {
213 g_string_free(port_name, TRUE);
214 }
215
147337a3 216 return status;
958f7d11
PP
217}
218
958f7d11 219static
4cdfc5e8 220bt_self_component_status create_output_port(
b19ff26f 221 bt_self_component_filter *self_comp)
958f7d11 222{
d94d92ac
PP
223 return bt_self_component_filter_add_output_port(
224 self_comp, "out", NULL, NULL);
958f7d11
PP
225}
226
227static
228void destroy_muxer_comp(struct muxer_comp *muxer_comp)
229{
230 if (!muxer_comp) {
231 return;
232 }
233
958f7d11
PP
234 g_free(muxer_comp);
235}
236
65ee897d 237static
b19ff26f 238bt_value *get_default_params(void)
65ee897d 239{
b19ff26f 240 bt_value *params;
65ee897d
PP
241 int ret;
242
05e21286 243 params = bt_value_map_create();
65ee897d 244 if (!params) {
fed72692 245 BT_LOGE_STR("Cannot create a map value object.");
65ee897d
PP
246 goto error;
247 }
248
05e21286 249 ret = bt_value_map_insert_bool_entry(params,
c3acd5f3 250 ASSUME_ABSOLUTE_CLOCK_CLASSES_PARAM_NAME, false);
65ee897d 251 if (ret) {
fed72692 252 BT_LOGE_STR("Cannot add boolean value to map value object.");
65ee897d
PP
253 goto error;
254 }
255
256 goto end;
257
258error:
c5b9b441 259 BT_VALUE_PUT_REF_AND_RESET(params);
65ee897d
PP
260
261end:
262 return params;
263}
264
265static
05e21286 266int configure_muxer_comp(struct muxer_comp *muxer_comp,
b19ff26f 267 const bt_value *params)
65ee897d 268{
b19ff26f
PP
269 bt_value *default_params = NULL;
270 bt_value *real_params = NULL;
271 const bt_value *assume_absolute_clock_classes = NULL;
65ee897d 272 int ret = 0;
c55a9f58 273 bt_bool bool_val;
65ee897d
PP
274
275 default_params = get_default_params();
276 if (!default_params) {
fed72692
PP
277 BT_LOGE("Cannot get default parameters: "
278 "muxer-comp-addr=%p", muxer_comp);
65ee897d
PP
279 goto error;
280 }
281
35294e83 282 ret = bt_value_map_extend(default_params, params, &real_params);
601b0d3c 283 if (ret) {
fed72692
PP
284 BT_LOGE("Cannot extend default parameters map value: "
285 "muxer-comp-addr=%p, def-params-addr=%p, "
286 "params-addr=%p", muxer_comp, default_params,
287 params);
65ee897d
PP
288 goto error;
289 }
290
05e21286
PP
291 assume_absolute_clock_classes = bt_value_map_borrow_entry_value(real_params,
292 ASSUME_ABSOLUTE_CLOCK_CLASSES_PARAM_NAME);
f6ccaed9
PP
293 if (assume_absolute_clock_classes &&
294 !bt_value_is_bool(assume_absolute_clock_classes)) {
fed72692
PP
295 BT_LOGE("Expecting a boolean value for the `%s` parameter: "
296 "muxer-comp-addr=%p, value-type=%s",
297 ASSUME_ABSOLUTE_CLOCK_CLASSES_PARAM_NAME, muxer_comp,
da91b29a 298 bt_common_value_type_string(
fed72692 299 bt_value_get_type(assume_absolute_clock_classes)));
65ee897d
PP
300 goto error;
301 }
302
601b0d3c 303 bool_val = bt_value_bool_get(assume_absolute_clock_classes);
282c8cd0 304 muxer_comp->assume_absolute_clock_classes = (bool) bool_val;
3f7d4d90 305 BT_LOGI("Configured muxer component: muxer-comp-addr=%p, "
fed72692
PP
306 "assume-absolute-clock-classes=%d",
307 muxer_comp, muxer_comp->assume_absolute_clock_classes);
65ee897d
PP
308 goto end;
309
310error:
311 ret = -1;
312
313end:
c5b9b441
PP
314 bt_value_put_ref(default_params);
315 bt_value_put_ref(real_params);
65ee897d
PP
316 return ret;
317}
318
958f7d11 319BT_HIDDEN
4cdfc5e8 320bt_self_component_status muxer_init(
b19ff26f 321 bt_self_component_filter *self_comp,
fdf0b89e 322 const bt_value *params, void *init_data)
958f7d11
PP
323{
324 int ret;
4cdfc5e8 325 bt_self_component_status status = BT_SELF_COMPONENT_STATUS_OK;
958f7d11
PP
326 struct muxer_comp *muxer_comp = g_new0(struct muxer_comp, 1);
327
3f7d4d90 328 BT_LOGI("Initializing muxer component: "
d94d92ac 329 "comp-addr=%p, params-addr=%p", self_comp, params);
fed72692 330
958f7d11 331 if (!muxer_comp) {
fed72692 332 BT_LOGE_STR("Failed to allocate one muxer component.");
958f7d11
PP
333 goto error;
334 }
335
65ee897d
PP
336 ret = configure_muxer_comp(muxer_comp, params);
337 if (ret) {
fed72692
PP
338 BT_LOGE("Cannot configure muxer component: "
339 "muxer-comp-addr=%p, params-addr=%p",
340 muxer_comp, params);
65ee897d
PP
341 goto error;
342 }
343
d94d92ac
PP
344 muxer_comp->self_comp = self_comp;
345 bt_self_component_set_data(
707b7d35 346 bt_self_component_filter_as_self_component(self_comp),
d94d92ac 347 muxer_comp);
5badd463 348 status = add_available_input_port(self_comp);
d94d92ac 349 if (status != BT_SELF_COMPONENT_STATUS_OK) {
fed72692
PP
350 BT_LOGE("Cannot ensure that at least one muxer component's input port is available: "
351 "muxer-comp-addr=%p, status=%s",
352 muxer_comp,
d94d92ac 353 bt_self_component_status_string(status));
958f7d11
PP
354 goto error;
355 }
356
d94d92ac 357 status = create_output_port(self_comp);
fed72692
PP
358 if (status) {
359 BT_LOGE("Cannot create muxer component's output port: "
360 "muxer-comp-addr=%p, status=%s",
361 muxer_comp,
d94d92ac 362 bt_self_component_status_string(status));
958f7d11
PP
363 goto error;
364 }
365
3f7d4d90 366 BT_LOGI("Initialized muxer component: "
fed72692 367 "comp-addr=%p, params-addr=%p, muxer-comp-addr=%p",
d94d92ac 368 self_comp, params, muxer_comp);
fed72692 369
958f7d11
PP
370 goto end;
371
372error:
373 destroy_muxer_comp(muxer_comp);
d94d92ac 374 bt_self_component_set_data(
707b7d35 375 bt_self_component_filter_as_self_component(self_comp),
d94d92ac 376 NULL);
147337a3 377
d94d92ac
PP
378 if (status == BT_SELF_COMPONENT_STATUS_OK) {
379 status = BT_SELF_COMPONENT_STATUS_ERROR;
147337a3 380 }
958f7d11
PP
381
382end:
383 return status;
384}
385
386BT_HIDDEN
b19ff26f 387void muxer_finalize(bt_self_component_filter *self_comp)
958f7d11 388{
d94d92ac 389 struct muxer_comp *muxer_comp = bt_self_component_get_data(
707b7d35 390 bt_self_component_filter_as_self_component(self_comp));
958f7d11 391
3f7d4d90 392 BT_LOGI("Finalizing muxer component: comp-addr=%p",
d94d92ac 393 self_comp);
958f7d11
PP
394 destroy_muxer_comp(muxer_comp);
395}
396
397static
d6e69534 398bt_self_component_port_input_message_iterator *
5badd463 399create_msg_iter_on_input_port(bt_self_component_port_input *self_port)
958f7d11 400{
b19ff26f 401 const bt_port *port = bt_self_component_port_as_port(
707b7d35 402 bt_self_component_port_input_as_self_component_port(
d94d92ac 403 self_port));
d6e69534 404 bt_self_component_port_input_message_iterator *msg_iter =
d94d92ac 405 NULL;
958f7d11 406
f6ccaed9
PP
407 BT_ASSERT(port);
408 BT_ASSERT(bt_port_is_connected(port));
958f7d11 409
ab11110e 410 // TODO: Advance the iterator to >= the time of the latest
d6e69534 411 // returned message by the muxer message
ab11110e 412 // iterator which creates it.
d6e69534 413 msg_iter = bt_self_component_port_input_message_iterator_create(
d94d92ac 414 self_port);
d6e69534
PP
415 if (!msg_iter) {
416 BT_LOGE("Cannot create upstream message iterator on input port: "
d94d92ac
PP
417 "port-addr=%p, port-name=\"%s\"",
418 port, bt_port_get_name(port));
958f7d11
PP
419 goto end;
420 }
421
3f7d4d90 422 BT_LOGI("Created upstream message iterator on input port: "
d6e69534
PP
423 "port-addr=%p, port-name=\"%s\", msg-iter-addr=%p",
424 port, bt_port_get_name(port), msg_iter);
fed72692 425
958f7d11 426end:
d6e69534 427 return msg_iter;
958f7d11
PP
428}
429
ab11110e 430static
fdf0b89e 431bt_self_message_iterator_status muxer_upstream_msg_iter_next(
54bdc1f7
PP
432 struct muxer_upstream_msg_iter *muxer_upstream_msg_iter,
433 bool *is_ended)
ab11110e 434{
fdf0b89e
FD
435 bt_self_message_iterator_status status;
436 bt_message_iterator_status input_port_iter_status;
d6e69534 437 bt_message_array_const msgs;
d4393e08
PP
438 uint64_t i;
439 uint64_t count;
ab11110e 440
3f7d4d90 441 BT_LOGD("Calling upstream message iterator's \"next\" method: "
d6e69534
PP
442 "muxer-upstream-msg-iter-wrap-addr=%p, msg-iter-addr=%p",
443 muxer_upstream_msg_iter,
444 muxer_upstream_msg_iter->msg_iter);
fdf0b89e 445 input_port_iter_status = bt_self_component_port_input_message_iterator_next(
d6e69534 446 muxer_upstream_msg_iter->msg_iter, &msgs, &count);
3f7d4d90 447 BT_LOGD("Upstream message iterator's \"next\" method returned: "
fdf0b89e 448 "status=%s", bt_message_iterator_status_string(input_port_iter_status));
ab11110e 449
fdf0b89e 450 switch (input_port_iter_status) {
d6e69534 451 case BT_MESSAGE_ITERATOR_STATUS_OK:
089717de 452 /*
d6e69534 453 * Message iterator's current message is
d4393e08 454 * valid: it must be considered for muxing operations.
089717de 455 */
3f7d4d90 456 BT_LOGD_STR("Validated upstream message iterator wrapper.");
d4393e08
PP
457 BT_ASSERT(count > 0);
458
d6e69534 459 /* Move messages to our queue */
d4393e08
PP
460 for (i = 0; i < count; i++) {
461 /*
462 * Push to tail in order; other side
d6e69534 463 * (muxer_msg_iter_do_next_one()) consumes
d4393e08
PP
464 * from the head first.
465 */
d6e69534
PP
466 g_queue_push_tail(muxer_upstream_msg_iter->msgs,
467 (void *) msgs[i]);
d4393e08 468 }
fdf0b89e 469 status = BT_SELF_MESSAGE_ITERATOR_STATUS_OK;
ab11110e 470 break;
d6e69534 471 case BT_MESSAGE_ITERATOR_STATUS_AGAIN:
089717de 472 /*
d6e69534 473 * Message iterator's current message is not
089717de 474 * valid anymore. Return
d6e69534 475 * BT_MESSAGE_ITERATOR_STATUS_AGAIN immediately.
089717de 476 */
fdf0b89e 477 status = BT_SELF_MESSAGE_ITERATOR_STATUS_AGAIN;
ab11110e 478 break;
d6e69534 479 case BT_MESSAGE_ITERATOR_STATUS_END: /* Fall-through. */
ab11110e 480 /*
d6e69534 481 * Message iterator reached the end: release it. It
ab11110e 482 * won't be considered again to find the youngest
d6e69534 483 * message.
ab11110e 484 */
54bdc1f7 485 *is_ended = true;
fdf0b89e 486 status = BT_SELF_MESSAGE_ITERATOR_STATUS_OK;
089717de 487 break;
ab11110e
PP
488 default:
489 /* Error or unsupported status code */
fed72692 490 BT_LOGE("Error or unsupported status code: "
fdf0b89e
FD
491 "status-code=%d", input_port_iter_status);
492 status = BT_SELF_MESSAGE_ITERATOR_STATUS_ERROR;
089717de 493 break;
ab11110e
PP
494 }
495
089717de 496 return status;
ab11110e
PP
497}
498
958f7d11 499static
d6e69534
PP
500int get_msg_ts_ns(struct muxer_comp *muxer_comp,
501 struct muxer_msg_iter *muxer_msg_iter,
502 const bt_message *msg, int64_t last_returned_ts_ns,
958f7d11
PP
503 int64_t *ts_ns)
504{
605e1019 505 const bt_clock_snapshot *clock_snapshot = NULL;
958f7d11 506 int ret = 0;
5366eb53 507 bt_message_stream_activity_clock_snapshot_state sa_cs_state;
649934d2
PP
508 const bt_stream_class *stream_class = NULL;
509 bt_message_type msg_type;
958f7d11 510
d6e69534 511 BT_ASSERT(msg);
f6ccaed9 512 BT_ASSERT(ts_ns);
3f7d4d90 513 BT_LOGD("Getting message's timestamp: "
d6e69534 514 "muxer-msg-iter-addr=%p, msg-addr=%p, "
fed72692 515 "last-returned-ts=%" PRId64,
d6e69534 516 muxer_msg_iter, msg, last_returned_ts_ns);
fed72692 517
91d81473 518 if (G_UNLIKELY(muxer_msg_iter->clock_class_expectation ==
60f3d027
PP
519 MUXER_MSG_ITER_CLOCK_CLASS_EXPECTATION_NONE)) {
520 *ts_ns = last_returned_ts_ns;
521 goto end;
522 }
523
649934d2
PP
524 msg_type = bt_message_get_type(msg);
525
91d81473 526 if (G_UNLIKELY(msg_type == BT_MESSAGE_TYPE_PACKET_BEGINNING)) {
649934d2
PP
527 stream_class = bt_stream_borrow_class_const(
528 bt_packet_borrow_stream_const(
529 bt_message_packet_beginning_borrow_packet_const(
530 msg)));
91d81473 531 } else if (G_UNLIKELY(msg_type == BT_MESSAGE_TYPE_PACKET_END)) {
649934d2
PP
532 stream_class = bt_stream_borrow_class_const(
533 bt_packet_borrow_stream_const(
534 bt_message_packet_end_borrow_packet_const(
535 msg)));
91d81473 536 } else if (G_UNLIKELY(msg_type == BT_MESSAGE_TYPE_DISCARDED_EVENTS)) {
2e90378a
PP
537 stream_class = bt_stream_borrow_class_const(
538 bt_message_discarded_events_borrow_stream_const(msg));
91d81473 539 } else if (G_UNLIKELY(msg_type == BT_MESSAGE_TYPE_DISCARDED_PACKETS)) {
2e90378a
PP
540 stream_class = bt_stream_borrow_class_const(
541 bt_message_discarded_packets_borrow_stream_const(msg));
649934d2
PP
542 }
543
544 switch (msg_type) {
d6e69534 545 case BT_MESSAGE_TYPE_EVENT:
60f3d027
PP
546 BT_ASSERT(bt_message_event_borrow_stream_class_default_clock_class_const(
547 msg));
0cbc2c33
PP
548 clock_snapshot = bt_message_event_borrow_default_clock_snapshot_const(
549 msg);
958f7d11 550 break;
5366eb53 551 case BT_MESSAGE_TYPE_PACKET_BEGINNING:
9b24b6aa 552 if (bt_stream_class_packets_have_beginning_default_clock_snapshot(
649934d2
PP
553 stream_class)) {
554 clock_snapshot = bt_message_packet_beginning_borrow_default_clock_snapshot_const(
555 msg);
556 } else {
557 goto no_clock_snapshot;
558 }
559
5366eb53
PP
560 break;
561 case BT_MESSAGE_TYPE_PACKET_END:
9b24b6aa 562 if (bt_stream_class_packets_have_end_default_clock_snapshot(
649934d2
PP
563 stream_class)) {
564 clock_snapshot = bt_message_packet_end_borrow_default_clock_snapshot_const(
565 msg);
566 } else {
567 goto no_clock_snapshot;
568 }
569
5366eb53
PP
570 break;
571 case BT_MESSAGE_TYPE_DISCARDED_EVENTS:
2e90378a
PP
572 if (bt_stream_class_discarded_events_have_default_clock_snapshots(
573 stream_class)) {
9b24b6aa 574 clock_snapshot = bt_message_discarded_events_borrow_beginning_default_clock_snapshot_const(
2e90378a
PP
575 msg);
576 } else {
577 goto no_clock_snapshot;
578 }
579
5366eb53
PP
580 break;
581 case BT_MESSAGE_TYPE_DISCARDED_PACKETS:
2e90378a
PP
582 if (bt_stream_class_discarded_packets_have_default_clock_snapshots(
583 stream_class)) {
9b24b6aa 584 clock_snapshot = bt_message_discarded_packets_borrow_beginning_default_clock_snapshot_const(
2e90378a
PP
585 msg);
586 } else {
587 goto no_clock_snapshot;
588 }
589
5366eb53
PP
590 break;
591 case BT_MESSAGE_TYPE_STREAM_ACTIVITY_BEGINNING:
60f3d027
PP
592 BT_ASSERT(bt_message_stream_activity_beginning_borrow_stream_class_default_clock_class_const(
593 msg));
5366eb53
PP
594 sa_cs_state = bt_message_stream_activity_beginning_borrow_default_clock_snapshot_const(
595 msg, &clock_snapshot);
596 if (sa_cs_state != BT_MESSAGE_STREAM_ACTIVITY_CLOCK_SNAPSHOT_STATE_KNOWN) {
4c0f1c8c 597 goto no_clock_snapshot;
5366eb53 598 }
958f7d11 599
5366eb53
PP
600 break;
601 case BT_MESSAGE_TYPE_STREAM_ACTIVITY_END:
60f3d027
PP
602 BT_ASSERT(bt_message_stream_activity_end_borrow_stream_class_default_clock_class_const(
603 msg));
5366eb53
PP
604 sa_cs_state = bt_message_stream_activity_end_borrow_default_clock_snapshot_const(
605 msg, &clock_snapshot);
606 if (sa_cs_state != BT_MESSAGE_STREAM_ACTIVITY_CLOCK_SNAPSHOT_STATE_KNOWN) {
4c0f1c8c 607 goto no_clock_snapshot;
5366eb53
PP
608 }
609
610 break;
b9fd9cbb 611 case BT_MESSAGE_TYPE_MESSAGE_ITERATOR_INACTIVITY:
0cbc2c33
PP
612 clock_snapshot = bt_message_message_iterator_inactivity_borrow_default_clock_snapshot_const(
613 msg);
958f7d11
PP
614 break;
615 default:
d6e69534 616 /* All the other messages have a higher priority */
3f7d4d90 617 BT_LOGD_STR("Message has no timestamp: using the last returned timestamp.");
958f7d11
PP
618 *ts_ns = last_returned_ts_ns;
619 goto end;
620 }
621
60f3d027
PP
622 ret = bt_clock_snapshot_get_ns_from_origin(clock_snapshot, ts_ns);
623 if (ret) {
624 BT_LOGE("Cannot get nanoseconds from Epoch of clock snapshot: "
625 "clock-snapshot-addr=%p", clock_snapshot);
626 goto error;
627 }
628
629 goto end;
630
631no_clock_snapshot:
3f7d4d90 632 BT_LOGD_STR("Message's default clock snapshot is missing: "
60f3d027
PP
633 "using the last returned timestamp.");
634 *ts_ns = last_returned_ts_ns;
635 goto end;
636
637error:
638 ret = -1;
639
640end:
641 if (ret == 0) {
3f7d4d90 642 BT_LOGD("Found message's timestamp: "
60f3d027
PP
643 "muxer-msg-iter-addr=%p, msg-addr=%p, "
644 "last-returned-ts=%" PRId64 ", ts=%" PRId64,
645 muxer_msg_iter, msg, last_returned_ts_ns,
646 *ts_ns);
44c440bc
PP
647 }
648
60f3d027
PP
649 return ret;
650}
651
652static inline
653int validate_clock_class(struct muxer_msg_iter *muxer_msg_iter,
654 struct muxer_comp *muxer_comp,
655 const bt_clock_class *clock_class)
656{
657 int ret = 0;
658 const unsigned char *cc_uuid;
659 const char *cc_name;
660
e22b45d0 661 BT_ASSERT(clock_class);
50842bdc
PP
662 cc_uuid = bt_clock_class_get_uuid(clock_class);
663 cc_name = bt_clock_class_get_name(clock_class);
282c8cd0 664
d6e69534
PP
665 if (muxer_msg_iter->clock_class_expectation ==
666 MUXER_MSG_ITER_CLOCK_CLASS_EXPECTATION_ANY) {
282c8cd0
PP
667 /*
668 * This is the first clock class that this muxer
d6e69534 669 * message iterator encounters. Its properties
282c8cd0
PP
670 * determine what to expect for the whole lifetime of
671 * the iterator without a true
672 * `assume-absolute-clock-classes` parameter.
673 */
5552377a 674 if (bt_clock_class_origin_is_unix_epoch(clock_class)) {
282c8cd0 675 /* Expect absolute clock classes */
d6e69534
PP
676 muxer_msg_iter->clock_class_expectation =
677 MUXER_MSG_ITER_CLOCK_CLASS_EXPECTATION_ABSOLUTE;
282c8cd0
PP
678 } else {
679 if (cc_uuid) {
680 /*
681 * Expect non-absolute clock classes
682 * with a specific UUID.
683 */
d6e69534
PP
684 muxer_msg_iter->clock_class_expectation =
685 MUXER_MSG_ITER_CLOCK_CLASS_EXPECTATION_NOT_ABS_SPEC_UUID;
686 memcpy(muxer_msg_iter->expected_clock_class_uuid,
282c8cd0
PP
687 cc_uuid, BABELTRACE_UUID_LEN);
688 } else {
689 /*
690 * Expect non-absolute clock classes
691 * with no UUID.
692 */
d6e69534
PP
693 muxer_msg_iter->clock_class_expectation =
694 MUXER_MSG_ITER_CLOCK_CLASS_EXPECTATION_NOT_ABS_NO_UUID;
282c8cd0
PP
695 }
696 }
697 }
698
699 if (!muxer_comp->assume_absolute_clock_classes) {
d6e69534
PP
700 switch (muxer_msg_iter->clock_class_expectation) {
701 case MUXER_MSG_ITER_CLOCK_CLASS_EXPECTATION_ABSOLUTE:
5552377a 702 if (!bt_clock_class_origin_is_unix_epoch(clock_class)) {
fed72692
PP
703 BT_LOGE("Expecting an absolute clock class, "
704 "but got a non-absolute one: "
705 "clock-class-addr=%p, clock-class-name=\"%s\"",
706 clock_class, cc_name);
282c8cd0
PP
707 goto error;
708 }
709 break;
d6e69534 710 case MUXER_MSG_ITER_CLOCK_CLASS_EXPECTATION_NOT_ABS_NO_UUID:
5552377a 711 if (bt_clock_class_origin_is_unix_epoch(clock_class)) {
fed72692
PP
712 BT_LOGE("Expecting a non-absolute clock class with no UUID, "
713 "but got an absolute one: "
714 "clock-class-addr=%p, clock-class-name=\"%s\"",
715 clock_class, cc_name);
282c8cd0
PP
716 goto error;
717 }
718
719 if (cc_uuid) {
fed72692
PP
720 BT_LOGE("Expecting a non-absolute clock class with no UUID, "
721 "but got one with a UUID: "
722 "clock-class-addr=%p, clock-class-name=\"%s\", "
723 "uuid=\"%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x\"",
724 clock_class, cc_name,
725 (unsigned int) cc_uuid[0],
726 (unsigned int) cc_uuid[1],
727 (unsigned int) cc_uuid[2],
728 (unsigned int) cc_uuid[3],
729 (unsigned int) cc_uuid[4],
730 (unsigned int) cc_uuid[5],
731 (unsigned int) cc_uuid[6],
732 (unsigned int) cc_uuid[7],
733 (unsigned int) cc_uuid[8],
734 (unsigned int) cc_uuid[9],
735 (unsigned int) cc_uuid[10],
736 (unsigned int) cc_uuid[11],
737 (unsigned int) cc_uuid[12],
738 (unsigned int) cc_uuid[13],
739 (unsigned int) cc_uuid[14],
740 (unsigned int) cc_uuid[15]);
282c8cd0
PP
741 goto error;
742 }
743 break;
d6e69534 744 case MUXER_MSG_ITER_CLOCK_CLASS_EXPECTATION_NOT_ABS_SPEC_UUID:
5552377a 745 if (bt_clock_class_origin_is_unix_epoch(clock_class)) {
fed72692
PP
746 BT_LOGE("Expecting a non-absolute clock class with a specific UUID, "
747 "but got an absolute one: "
748 "clock-class-addr=%p, clock-class-name=\"%s\"",
749 clock_class, cc_name);
282c8cd0
PP
750 goto error;
751 }
752
753 if (!cc_uuid) {
fed72692
PP
754 BT_LOGE("Expecting a non-absolute clock class with a specific UUID, "
755 "but got one with no UUID: "
756 "clock-class-addr=%p, clock-class-name=\"%s\"",
757 clock_class, cc_name);
282c8cd0
PP
758 goto error;
759 }
760
d6e69534 761 if (memcmp(muxer_msg_iter->expected_clock_class_uuid,
282c8cd0 762 cc_uuid, BABELTRACE_UUID_LEN) != 0) {
fed72692
PP
763 BT_LOGE("Expecting a non-absolute clock class with a specific UUID, "
764 "but got one with different UUID: "
765 "clock-class-addr=%p, clock-class-name=\"%s\", "
766 "expected-uuid=\"%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x\", "
767 "uuid=\"%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x\"",
768 clock_class, cc_name,
d6e69534
PP
769 (unsigned int) muxer_msg_iter->expected_clock_class_uuid[0],
770 (unsigned int) muxer_msg_iter->expected_clock_class_uuid[1],
771 (unsigned int) muxer_msg_iter->expected_clock_class_uuid[2],
772 (unsigned int) muxer_msg_iter->expected_clock_class_uuid[3],
773 (unsigned int) muxer_msg_iter->expected_clock_class_uuid[4],
774 (unsigned int) muxer_msg_iter->expected_clock_class_uuid[5],
775 (unsigned int) muxer_msg_iter->expected_clock_class_uuid[6],
776 (unsigned int) muxer_msg_iter->expected_clock_class_uuid[7],
777 (unsigned int) muxer_msg_iter->expected_clock_class_uuid[8],
778 (unsigned int) muxer_msg_iter->expected_clock_class_uuid[9],
779 (unsigned int) muxer_msg_iter->expected_clock_class_uuid[10],
780 (unsigned int) muxer_msg_iter->expected_clock_class_uuid[11],
781 (unsigned int) muxer_msg_iter->expected_clock_class_uuid[12],
782 (unsigned int) muxer_msg_iter->expected_clock_class_uuid[13],
783 (unsigned int) muxer_msg_iter->expected_clock_class_uuid[14],
784 (unsigned int) muxer_msg_iter->expected_clock_class_uuid[15],
fed72692
PP
785 (unsigned int) cc_uuid[0],
786 (unsigned int) cc_uuid[1],
787 (unsigned int) cc_uuid[2],
788 (unsigned int) cc_uuid[3],
789 (unsigned int) cc_uuid[4],
790 (unsigned int) cc_uuid[5],
791 (unsigned int) cc_uuid[6],
792 (unsigned int) cc_uuid[7],
793 (unsigned int) cc_uuid[8],
794 (unsigned int) cc_uuid[9],
795 (unsigned int) cc_uuid[10],
796 (unsigned int) cc_uuid[11],
797 (unsigned int) cc_uuid[12],
798 (unsigned int) cc_uuid[13],
799 (unsigned int) cc_uuid[14],
800 (unsigned int) cc_uuid[15]);
282c8cd0
PP
801 goto error;
802 }
803 break;
60f3d027
PP
804 case MUXER_MSG_ITER_CLOCK_CLASS_EXPECTATION_NONE:
805 BT_LOGE("Expecting no clock class, but got one: "
806 "clock-class-addr=%p, clock-class-name=\"%s\"",
807 clock_class, cc_name);
808 goto error;
282c8cd0
PP
809 default:
810 /* Unexpected */
fed72692
PP
811 BT_LOGF("Unexpected clock class expectation: "
812 "expectation-code=%d",
d6e69534 813 muxer_msg_iter->clock_class_expectation);
282c8cd0
PP
814 abort();
815 }
958f7d11
PP
816 }
817
4c0f1c8c
PP
818 goto end;
819
958f7d11
PP
820error:
821 ret = -1;
822
823end:
60f3d027
PP
824 return ret;
825}
826
827static inline
828int validate_new_stream_clock_class(struct muxer_msg_iter *muxer_msg_iter,
829 struct muxer_comp *muxer_comp, const bt_stream *stream)
830{
831 int ret = 0;
832 const bt_stream_class *stream_class =
833 bt_stream_borrow_class_const(stream);
834 const bt_clock_class *clock_class =
835 bt_stream_class_borrow_default_clock_class_const(stream_class);
836
837 if (!clock_class) {
838 if (muxer_msg_iter->clock_class_expectation ==
839 MUXER_MSG_ITER_CLOCK_CLASS_EXPECTATION_ANY) {
840 /* Expect no clock class */
841 muxer_msg_iter->clock_class_expectation =
842 MUXER_MSG_ITER_CLOCK_CLASS_EXPECTATION_NONE;
843 } else {
844 BT_LOGE("Expecting stream class with a default clock class: "
845 "stream-class-addr=%p, stream-class-name=\"%s\", "
846 "stream-class-id=%" PRIu64,
847 stream_class, bt_stream_class_get_name(stream_class),
848 bt_stream_class_get_id(stream_class));
849 ret = -1;
850 }
851
852 goto end;
fed72692
PP
853 }
854
60f3d027
PP
855 ret = validate_clock_class(muxer_msg_iter, muxer_comp, clock_class);
856
857end:
958f7d11
PP
858 return ret;
859}
860
ab11110e 861/*
d6e69534
PP
862 * This function finds the youngest available message amongst the
863 * non-ended upstream message iterators and returns the upstream
864 * message iterator which has it, or
865 * BT_MESSAGE_ITERATOR_STATUS_END if there's no available
866 * message.
ab11110e
PP
867 *
868 * This function does NOT:
869 *
d6e69534 870 * * Update any upstream message iterator.
d6e69534 871 * * Check the upstream message iterators to retry.
ab11110e 872 *
d6e69534
PP
873 * On sucess, this function sets *muxer_upstream_msg_iter to the
874 * upstream message iterator of which the current message is
ab11110e
PP
875 * the youngest, and sets *ts_ns to its time.
876 */
958f7d11 877static
fdf0b89e 878bt_self_message_iterator_status
d6e69534 879muxer_msg_iter_youngest_upstream_msg_iter(
958f7d11 880 struct muxer_comp *muxer_comp,
d6e69534
PP
881 struct muxer_msg_iter *muxer_msg_iter,
882 struct muxer_upstream_msg_iter **muxer_upstream_msg_iter,
958f7d11
PP
883 int64_t *ts_ns)
884{
885 size_t i;
886 int ret;
887 int64_t youngest_ts_ns = INT64_MAX;
fdf0b89e
FD
888 bt_self_message_iterator_status status =
889 BT_SELF_MESSAGE_ITERATOR_STATUS_OK;
958f7d11 890
f6ccaed9 891 BT_ASSERT(muxer_comp);
d6e69534
PP
892 BT_ASSERT(muxer_msg_iter);
893 BT_ASSERT(muxer_upstream_msg_iter);
894 *muxer_upstream_msg_iter = NULL;
895
54bdc1f7
PP
896 for (i = 0; i < muxer_msg_iter->active_muxer_upstream_msg_iters->len;
897 i++) {
d6e69534
PP
898 const bt_message *msg;
899 struct muxer_upstream_msg_iter *cur_muxer_upstream_msg_iter =
54bdc1f7
PP
900 g_ptr_array_index(
901 muxer_msg_iter->active_muxer_upstream_msg_iters,
902 i);
d6e69534
PP
903 int64_t msg_ts_ns;
904
905 if (!cur_muxer_upstream_msg_iter->msg_iter) {
906 /* This upstream message iterator is ended */
907 BT_LOGV("Skipping ended upstream message iterator: "
908 "muxer-upstream-msg-iter-wrap-addr=%p",
909 cur_muxer_upstream_msg_iter);
958f7d11
PP
910 continue;
911 }
912
d6e69534
PP
913 BT_ASSERT(cur_muxer_upstream_msg_iter->msgs->length > 0);
914 msg = g_queue_peek_head(cur_muxer_upstream_msg_iter->msgs);
915 BT_ASSERT(msg);
60f3d027 916
91d81473 917 if (G_UNLIKELY(bt_message_get_type(msg) ==
60f3d027
PP
918 BT_MESSAGE_TYPE_STREAM_BEGINNING)) {
919 ret = validate_new_stream_clock_class(
920 muxer_msg_iter, muxer_comp,
921 bt_message_stream_beginning_borrow_stream_const(
922 msg));
923 if (ret) {
924 /*
925 * validate_new_stream_clock_class() logs
926 * errors.
927 */
928 status = BT_SELF_MESSAGE_ITERATOR_STATUS_ERROR;
929 goto end;
930 }
91d81473 931 } else if (G_UNLIKELY(bt_message_get_type(msg) ==
60f3d027
PP
932 BT_MESSAGE_TYPE_MESSAGE_ITERATOR_INACTIVITY)) {
933 const bt_clock_snapshot *cs;
60f3d027 934
0cbc2c33
PP
935 cs = bt_message_message_iterator_inactivity_borrow_default_clock_snapshot_const(
936 msg);
60f3d027
PP
937 ret = validate_clock_class(muxer_msg_iter, muxer_comp,
938 bt_clock_snapshot_borrow_clock_class_const(cs));
939 if (ret) {
940 /* validate_clock_class() logs errors */
941 status = BT_SELF_MESSAGE_ITERATOR_STATUS_ERROR;
942 goto end;
943 }
944 }
945
d6e69534
PP
946 ret = get_msg_ts_ns(muxer_comp, muxer_msg_iter, msg,
947 muxer_msg_iter->last_returned_ts_ns, &msg_ts_ns);
958f7d11 948 if (ret) {
d6e69534
PP
949 /* get_msg_ts_ns() logs errors */
950 *muxer_upstream_msg_iter = NULL;
fdf0b89e 951 status = BT_SELF_MESSAGE_ITERATOR_STATUS_ERROR;
958f7d11
PP
952 goto end;
953 }
954
d6e69534
PP
955 if (msg_ts_ns <= youngest_ts_ns) {
956 *muxer_upstream_msg_iter =
957 cur_muxer_upstream_msg_iter;
958 youngest_ts_ns = msg_ts_ns;
958f7d11
PP
959 *ts_ns = youngest_ts_ns;
960 }
961 }
962
d6e69534 963 if (!*muxer_upstream_msg_iter) {
fdf0b89e 964 status = BT_SELF_MESSAGE_ITERATOR_STATUS_END;
958f7d11
PP
965 *ts_ns = INT64_MIN;
966 }
967
968end:
969 return status;
970}
971
972static
fdf0b89e 973bt_self_message_iterator_status validate_muxer_upstream_msg_iter(
54bdc1f7
PP
974 struct muxer_upstream_msg_iter *muxer_upstream_msg_iter,
975 bool *is_ended)
958f7d11 976{
fdf0b89e
FD
977 bt_self_message_iterator_status status =
978 BT_SELF_MESSAGE_ITERATOR_STATUS_OK;
958f7d11 979
3f7d4d90 980 BT_LOGD("Validating muxer's upstream message iterator wrapper: "
d6e69534
PP
981 "muxer-upstream-msg-iter-wrap-addr=%p",
982 muxer_upstream_msg_iter);
fed72692 983
d6e69534
PP
984 if (muxer_upstream_msg_iter->msgs->length > 0 ||
985 !muxer_upstream_msg_iter->msg_iter) {
3f7d4d90 986 BT_LOGD("Already valid or not considered: "
d6e69534
PP
987 "queue-len=%u, upstream-msg-iter-addr=%p",
988 muxer_upstream_msg_iter->msgs->length,
989 muxer_upstream_msg_iter->msg_iter);
ab11110e
PP
990 goto end;
991 }
992
d6e69534 993 /* muxer_upstream_msg_iter_next() logs details/errors */
54bdc1f7
PP
994 status = muxer_upstream_msg_iter_next(muxer_upstream_msg_iter,
995 is_ended);
089717de
PP
996
997end:
998 return status;
999}
1000
1001static
fdf0b89e 1002bt_self_message_iterator_status validate_muxer_upstream_msg_iters(
d6e69534 1003 struct muxer_msg_iter *muxer_msg_iter)
089717de 1004{
fdf0b89e
FD
1005 bt_self_message_iterator_status status =
1006 BT_SELF_MESSAGE_ITERATOR_STATUS_OK;
089717de
PP
1007 size_t i;
1008
3f7d4d90 1009 BT_LOGD("Validating muxer's upstream message iterator wrappers: "
d6e69534 1010 "muxer-msg-iter-addr=%p", muxer_msg_iter);
fed72692 1011
54bdc1f7
PP
1012 for (i = 0; i < muxer_msg_iter->active_muxer_upstream_msg_iters->len;
1013 i++) {
6bf2abbd 1014 bool is_ended = false;
d6e69534 1015 struct muxer_upstream_msg_iter *muxer_upstream_msg_iter =
089717de 1016 g_ptr_array_index(
54bdc1f7 1017 muxer_msg_iter->active_muxer_upstream_msg_iters,
089717de
PP
1018 i);
1019
d6e69534 1020 status = validate_muxer_upstream_msg_iter(
54bdc1f7 1021 muxer_upstream_msg_iter, &is_ended);
fdf0b89e 1022 if (status != BT_SELF_MESSAGE_ITERATOR_STATUS_OK) {
fed72692 1023 if (status < 0) {
d6e69534
PP
1024 BT_LOGE("Cannot validate muxer's upstream message iterator wrapper: "
1025 "muxer-msg-iter-addr=%p, "
1026 "muxer-upstream-msg-iter-wrap-addr=%p",
1027 muxer_msg_iter,
1028 muxer_upstream_msg_iter);
fed72692 1029 } else {
3f7d4d90 1030 BT_LOGD("Cannot validate muxer's upstream message iterator wrapper: "
d6e69534
PP
1031 "muxer-msg-iter-addr=%p, "
1032 "muxer-upstream-msg-iter-wrap-addr=%p",
1033 muxer_msg_iter,
1034 muxer_upstream_msg_iter);
fed72692
PP
1035 }
1036
089717de
PP
1037 goto end;
1038 }
744ba28b
PP
1039
1040 /*
54bdc1f7
PP
1041 * Move this muxer upstream message iterator to the
1042 * array of ended iterators if it's ended.
744ba28b 1043 */
91d81473 1044 if (G_UNLIKELY(is_ended)) {
3f7d4d90 1045 BT_LOGD("Muxer's upstream message iterator wrapper: ended or canceled: "
54bdc1f7
PP
1046 "muxer-msg-iter-addr=%p, "
1047 "muxer-upstream-msg-iter-wrap-addr=%p",
1048 muxer_msg_iter, muxer_upstream_msg_iter);
1049 g_ptr_array_add(
1050 muxer_msg_iter->ended_muxer_upstream_msg_iters,
1051 muxer_upstream_msg_iter);
1052 muxer_msg_iter->active_muxer_upstream_msg_iters->pdata[i] = NULL;
1053
744ba28b
PP
1054 /*
1055 * Use g_ptr_array_remove_fast() because the
1056 * order of those elements is not important.
1057 */
1058 g_ptr_array_remove_index_fast(
54bdc1f7 1059 muxer_msg_iter->active_muxer_upstream_msg_iters,
744ba28b
PP
1060 i);
1061 i--;
1062 }
089717de
PP
1063 }
1064
1065end:
1066 return status;
1067}
1068
d4393e08 1069static inline
fdf0b89e 1070bt_self_message_iterator_status muxer_msg_iter_do_next_one(
089717de 1071 struct muxer_comp *muxer_comp,
d6e69534
PP
1072 struct muxer_msg_iter *muxer_msg_iter,
1073 const bt_message **msg)
089717de 1074{
5badd463 1075 bt_self_message_iterator_status status;
d6e69534 1076 struct muxer_upstream_msg_iter *muxer_upstream_msg_iter = NULL;
089717de
PP
1077 int64_t next_return_ts;
1078
5badd463
PP
1079 status = validate_muxer_upstream_msg_iters(muxer_msg_iter);
1080 if (status != BT_SELF_MESSAGE_ITERATOR_STATUS_OK) {
1081 /* validate_muxer_upstream_msg_iters() logs details */
1082 goto end;
958f7d11
PP
1083 }
1084
1085 /*
089717de 1086 * At this point we know that all the existing upstream
d6e69534
PP
1087 * message iterators are valid. We can find the one,
1088 * amongst those, of which the current message is the
089717de 1089 * youngest.
958f7d11 1090 */
d6e69534
PP
1091 status = muxer_msg_iter_youngest_upstream_msg_iter(muxer_comp,
1092 muxer_msg_iter, &muxer_upstream_msg_iter,
089717de 1093 &next_return_ts);
fdf0b89e 1094 if (status < 0 || status == BT_SELF_MESSAGE_ITERATOR_STATUS_END) {
d4393e08 1095 if (status < 0) {
d6e69534 1096 BT_LOGE("Cannot find the youngest upstream message iterator wrapper: "
fed72692 1097 "status=%s",
bd1a54fe 1098 bt_common_self_message_iterator_status_string(status));
fed72692 1099 } else {
3f7d4d90 1100 BT_LOGD("Cannot find the youngest upstream message iterator wrapper: "
fed72692 1101 "status=%s",
bd1a54fe 1102 bt_common_self_message_iterator_status_string(status));
fed72692
PP
1103 }
1104
958f7d11
PP
1105 goto end;
1106 }
1107
d6e69534
PP
1108 if (next_return_ts < muxer_msg_iter->last_returned_ts_ns) {
1109 BT_LOGE("Youngest upstream message iterator wrapper's timestamp is less than muxer's message iterator's last returned timestamp: "
1110 "muxer-msg-iter-addr=%p, ts=%" PRId64 ", "
fed72692 1111 "last-returned-ts=%" PRId64,
d6e69534
PP
1112 muxer_msg_iter, next_return_ts,
1113 muxer_msg_iter->last_returned_ts_ns);
fdf0b89e 1114 status = BT_SELF_MESSAGE_ITERATOR_STATUS_ERROR;
958f7d11
PP
1115 goto end;
1116 }
1117
3f7d4d90 1118 BT_LOGD("Found youngest upstream message iterator wrapper: "
d6e69534
PP
1119 "muxer-msg-iter-addr=%p, "
1120 "muxer-upstream-msg-iter-wrap-addr=%p, "
fed72692 1121 "ts=%" PRId64,
d6e69534 1122 muxer_msg_iter, muxer_upstream_msg_iter, next_return_ts);
fdf0b89e 1123 BT_ASSERT(status == BT_SELF_MESSAGE_ITERATOR_STATUS_OK);
d6e69534 1124 BT_ASSERT(muxer_upstream_msg_iter);
958f7d11
PP
1125
1126 /*
d4393e08 1127 * Consume from the queue's head: other side
d6e69534 1128 * (muxer_upstream_msg_iter_next()) writes to the tail.
958f7d11 1129 */
d6e69534
PP
1130 *msg = g_queue_pop_head(muxer_upstream_msg_iter->msgs);
1131 BT_ASSERT(*msg);
1132 muxer_msg_iter->last_returned_ts_ns = next_return_ts;
958f7d11
PP
1133
1134end:
d4393e08
PP
1135 return status;
1136}
1137
1138static
fdf0b89e 1139bt_self_message_iterator_status muxer_msg_iter_do_next(
d4393e08 1140 struct muxer_comp *muxer_comp,
d6e69534
PP
1141 struct muxer_msg_iter *muxer_msg_iter,
1142 bt_message_array_const msgs, uint64_t capacity,
d4393e08
PP
1143 uint64_t *count)
1144{
fdf0b89e
FD
1145 bt_self_message_iterator_status status =
1146 BT_SELF_MESSAGE_ITERATOR_STATUS_OK;
d4393e08
PP
1147 uint64_t i = 0;
1148
4725a201 1149 while (i < capacity && status == BT_SELF_MESSAGE_ITERATOR_STATUS_OK) {
d6e69534
PP
1150 status = muxer_msg_iter_do_next_one(muxer_comp,
1151 muxer_msg_iter, &msgs[i]);
4725a201 1152 if (status == BT_SELF_MESSAGE_ITERATOR_STATUS_OK) {
d4393e08
PP
1153 i++;
1154 }
1155 }
1156
1157 if (i > 0) {
1158 /*
d6e69534 1159 * Even if muxer_msg_iter_do_next_one() returned
d4393e08 1160 * something else than
d6e69534
PP
1161 * BT_MESSAGE_ITERATOR_STATUS_OK, we accumulated
1162 * message objects in the output message
d4393e08 1163 * array, so we need to return
d6e69534 1164 * BT_MESSAGE_ITERATOR_STATUS_OK so that they are
d4393e08 1165 * transfered to downstream. This other status occurs
d6e69534 1166 * again the next time muxer_msg_iter_do_next() is
d4393e08 1167 * called, possibly without any accumulated
d6e69534 1168 * message, in which case we'll return it.
d4393e08
PP
1169 */
1170 *count = i;
fdf0b89e 1171 status = BT_SELF_MESSAGE_ITERATOR_STATUS_OK;
d4393e08
PP
1172 }
1173
1174 return status;
958f7d11
PP
1175}
1176
1177static
d6e69534 1178void destroy_muxer_msg_iter(struct muxer_msg_iter *muxer_msg_iter)
ab11110e 1179{
d6e69534 1180 if (!muxer_msg_iter) {
ab11110e
PP
1181 return;
1182 }
1183
d6e69534
PP
1184 BT_LOGD("Destroying muxer component's message iterator: "
1185 "muxer-msg-iter-addr=%p", muxer_msg_iter);
fed72692 1186
54bdc1f7
PP
1187 if (muxer_msg_iter->active_muxer_upstream_msg_iters) {
1188 BT_LOGD_STR("Destroying muxer's active upstream message iterator wrappers.");
1189 g_ptr_array_free(
1190 muxer_msg_iter->active_muxer_upstream_msg_iters, TRUE);
1191 }
1192
1193 if (muxer_msg_iter->ended_muxer_upstream_msg_iters) {
1194 BT_LOGD_STR("Destroying muxer's ended upstream message iterator wrappers.");
ab11110e 1195 g_ptr_array_free(
54bdc1f7 1196 muxer_msg_iter->ended_muxer_upstream_msg_iters, TRUE);
ab11110e
PP
1197 }
1198
d6e69534 1199 g_free(muxer_msg_iter);
ab11110e
PP
1200}
1201
1202static
5badd463 1203int muxer_msg_iter_init_upstream_iterators(struct muxer_comp *muxer_comp,
d6e69534 1204 struct muxer_msg_iter *muxer_msg_iter)
958f7d11 1205{
544d0515
PP
1206 int64_t count;
1207 int64_t i;
ab11110e 1208 int ret = 0;
958f7d11 1209
d94d92ac 1210 count = bt_component_filter_get_input_port_count(
707b7d35 1211 bt_self_component_filter_as_component_filter(
d94d92ac 1212 muxer_comp->self_comp));
544d0515 1213 if (count < 0) {
d6e69534
PP
1214 BT_LOGD("No input port to initialize for muxer component's message iterator: "
1215 "muxer-comp-addr=%p, muxer-msg-iter-addr=%p",
1216 muxer_comp, muxer_msg_iter);
ab11110e
PP
1217 goto end;
1218 }
958f7d11
PP
1219
1220 for (i = 0; i < count; i++) {
5badd463 1221 bt_self_component_port_input_message_iterator *upstream_msg_iter;
b19ff26f 1222 bt_self_component_port_input *self_port =
d94d92ac
PP
1223 bt_self_component_filter_borrow_input_port_by_index(
1224 muxer_comp->self_comp, i);
b19ff26f 1225 const bt_port *port;
958f7d11 1226
d94d92ac 1227 BT_ASSERT(self_port);
707b7d35
PP
1228 port = bt_self_component_port_as_port(
1229 bt_self_component_port_input_as_self_component_port(
d94d92ac 1230 self_port));
f6ccaed9 1231 BT_ASSERT(port);
958f7d11
PP
1232
1233 if (!bt_port_is_connected(port)) {
5badd463 1234 /* Skip non-connected port */
958f7d11
PP
1235 continue;
1236 }
1237
5badd463
PP
1238 upstream_msg_iter = create_msg_iter_on_input_port(self_port);
1239 if (!upstream_msg_iter) {
1240 /* create_msg_iter_on_input_port() logs errors */
1241 BT_ASSERT(!upstream_msg_iter);
ab11110e
PP
1242 ret = -1;
1243 goto end;
958f7d11 1244 }
fed72692 1245
c61018b9
FD
1246 ret = muxer_msg_iter_add_upstream_msg_iter(muxer_msg_iter,
1247 upstream_msg_iter);
5badd463
PP
1248 bt_self_component_port_input_message_iterator_put_ref(
1249 upstream_msg_iter);
c61018b9 1250 if (ret) {
5badd463 1251 /* muxer_msg_iter_add_upstream_msg_iter() logs errors */
5badd463
PP
1252 goto end;
1253 }
958f7d11
PP
1254 }
1255
1256end:
958f7d11
PP
1257 return ret;
1258}
1259
958f7d11 1260BT_HIDDEN
4cdfc5e8 1261bt_self_message_iterator_status muxer_msg_iter_init(
d6e69534 1262 bt_self_message_iterator *self_msg_iter,
b19ff26f
PP
1263 bt_self_component_filter *self_comp,
1264 bt_self_component_port_output *port)
958f7d11
PP
1265{
1266 struct muxer_comp *muxer_comp = NULL;
d6e69534 1267 struct muxer_msg_iter *muxer_msg_iter = NULL;
4cdfc5e8 1268 bt_self_message_iterator_status status =
fdf0b89e 1269 BT_SELF_MESSAGE_ITERATOR_STATUS_OK;
958f7d11
PP
1270 int ret;
1271
d94d92ac 1272 muxer_comp = bt_self_component_get_data(
707b7d35 1273 bt_self_component_filter_as_self_component(self_comp));
f6ccaed9 1274 BT_ASSERT(muxer_comp);
d6e69534
PP
1275 BT_LOGD("Initializing muxer component's message iterator: "
1276 "comp-addr=%p, muxer-comp-addr=%p, msg-iter-addr=%p",
1277 self_comp, muxer_comp, self_msg_iter);
a09c6b95 1278
d6e69534 1279 if (muxer_comp->initializing_muxer_msg_iter) {
a09c6b95 1280 /*
089717de 1281 * Weird, unhandled situation detected: downstream
d6e69534
PP
1282 * creates a muxer message iterator while creating
1283 * another muxer message iterator (same component).
a09c6b95 1284 */
d6e69534
PP
1285 BT_LOGE("Recursive initialization of muxer component's message iterator: "
1286 "comp-addr=%p, muxer-comp-addr=%p, msg-iter-addr=%p",
1287 self_comp, muxer_comp, self_msg_iter);
958f7d11
PP
1288 goto error;
1289 }
1290
d6e69534
PP
1291 muxer_comp->initializing_muxer_msg_iter = true;
1292 muxer_msg_iter = g_new0(struct muxer_msg_iter, 1);
1293 if (!muxer_msg_iter) {
1294 BT_LOGE_STR("Failed to allocate one muxer component's message iterator.");
ab11110e
PP
1295 goto error;
1296 }
1297
d6e69534 1298 muxer_msg_iter->last_returned_ts_ns = INT64_MIN;
54bdc1f7 1299 muxer_msg_iter->active_muxer_upstream_msg_iters =
958f7d11 1300 g_ptr_array_new_with_free_func(
d6e69534 1301 (GDestroyNotify) destroy_muxer_upstream_msg_iter);
54bdc1f7
PP
1302 if (!muxer_msg_iter->active_muxer_upstream_msg_iters) {
1303 BT_LOGE_STR("Failed to allocate a GPtrArray.");
1304 goto error;
1305 }
1306
1307 muxer_msg_iter->ended_muxer_upstream_msg_iters =
1308 g_ptr_array_new_with_free_func(
1309 (GDestroyNotify) destroy_muxer_upstream_msg_iter);
1310 if (!muxer_msg_iter->ended_muxer_upstream_msg_iters) {
fed72692 1311 BT_LOGE_STR("Failed to allocate a GPtrArray.");
958f7d11
PP
1312 goto error;
1313 }
1314
5badd463 1315 ret = muxer_msg_iter_init_upstream_iterators(muxer_comp,
d6e69534 1316 muxer_msg_iter);
a09c6b95 1317 if (ret) {
5badd463 1318 BT_LOGE("Cannot initialize connected input ports for muxer component's message iterator: "
fed72692 1319 "comp-addr=%p, muxer-comp-addr=%p, "
d6e69534
PP
1320 "muxer-msg-iter-addr=%p, msg-iter-addr=%p, ret=%d",
1321 self_comp, muxer_comp, muxer_msg_iter,
1322 self_msg_iter, ret);
a09c6b95
PP
1323 goto error;
1324 }
1325
5badd463 1326 bt_self_message_iterator_set_data(self_msg_iter, muxer_msg_iter);
d6e69534
PP
1327 BT_LOGD("Initialized muxer component's message iterator: "
1328 "comp-addr=%p, muxer-comp-addr=%p, muxer-msg-iter-addr=%p, "
1329 "msg-iter-addr=%p",
1330 self_comp, muxer_comp, muxer_msg_iter, self_msg_iter);
958f7d11
PP
1331 goto end;
1332
1333error:
d6e69534 1334 destroy_muxer_msg_iter(muxer_msg_iter);
5badd463 1335 bt_self_message_iterator_set_data(self_msg_iter, NULL);
fdf0b89e 1336 status = BT_SELF_MESSAGE_ITERATOR_STATUS_ERROR;
958f7d11
PP
1337
1338end:
d6e69534 1339 muxer_comp->initializing_muxer_msg_iter = false;
958f7d11
PP
1340 return status;
1341}
1342
1343BT_HIDDEN
54bdc1f7 1344void muxer_msg_iter_finalize(bt_self_message_iterator *self_msg_iter)
958f7d11 1345{
d6e69534
PP
1346 struct muxer_msg_iter *muxer_msg_iter =
1347 bt_self_message_iterator_get_data(self_msg_iter);
b19ff26f 1348 bt_self_component *self_comp = NULL;
958f7d11
PP
1349 struct muxer_comp *muxer_comp = NULL;
1350
d6e69534
PP
1351 self_comp = bt_self_message_iterator_borrow_component(
1352 self_msg_iter);
d94d92ac
PP
1353 BT_ASSERT(self_comp);
1354 muxer_comp = bt_self_component_get_data(self_comp);
d6e69534
PP
1355 BT_LOGD("Finalizing muxer component's message iterator: "
1356 "comp-addr=%p, muxer-comp-addr=%p, muxer-msg-iter-addr=%p, "
1357 "msg-iter-addr=%p",
1358 self_comp, muxer_comp, muxer_msg_iter, self_msg_iter);
958f7d11 1359
5badd463 1360 if (muxer_msg_iter) {
d6e69534 1361 destroy_muxer_msg_iter(muxer_msg_iter);
958f7d11 1362 }
958f7d11
PP
1363}
1364
1365BT_HIDDEN
fdf0b89e 1366bt_self_message_iterator_status muxer_msg_iter_next(
d6e69534
PP
1367 bt_self_message_iterator *self_msg_iter,
1368 bt_message_array_const msgs, uint64_t capacity,
d4393e08 1369 uint64_t *count)
958f7d11 1370{
fdf0b89e 1371 bt_self_message_iterator_status status;
d6e69534
PP
1372 struct muxer_msg_iter *muxer_msg_iter =
1373 bt_self_message_iterator_get_data(self_msg_iter);
b19ff26f 1374 bt_self_component *self_comp = NULL;
958f7d11 1375 struct muxer_comp *muxer_comp = NULL;
958f7d11 1376
d6e69534
PP
1377 BT_ASSERT(muxer_msg_iter);
1378 self_comp = bt_self_message_iterator_borrow_component(
1379 self_msg_iter);
d94d92ac
PP
1380 BT_ASSERT(self_comp);
1381 muxer_comp = bt_self_component_get_data(self_comp);
f6ccaed9 1382 BT_ASSERT(muxer_comp);
d6e69534
PP
1383 BT_LOGV("Muxer component's message iterator's \"next\" method called: "
1384 "comp-addr=%p, muxer-comp-addr=%p, muxer-msg-iter-addr=%p, "
1385 "msg-iter-addr=%p",
1386 self_comp, muxer_comp, muxer_msg_iter, self_msg_iter);
fed72692 1387
d6e69534
PP
1388 status = muxer_msg_iter_do_next(muxer_comp, muxer_msg_iter,
1389 msgs, capacity, count);
d4393e08 1390 if (status < 0) {
d6e69534
PP
1391 BT_LOGE("Cannot get next message: "
1392 "comp-addr=%p, muxer-comp-addr=%p, muxer-msg-iter-addr=%p, "
1393 "msg-iter-addr=%p, status=%s",
1394 self_comp, muxer_comp, muxer_msg_iter, self_msg_iter,
bd1a54fe 1395 bt_common_self_message_iterator_status_string(status));
fed72692 1396 } else {
d6e69534 1397 BT_LOGV("Returning from muxer component's message iterator's \"next\" method: "
d4393e08 1398 "status=%s",
bd1a54fe 1399 bt_common_self_message_iterator_status_string(status));
fed72692 1400 }
958f7d11 1401
d4393e08 1402 return status;
958f7d11
PP
1403}
1404
1405BT_HIDDEN
4cdfc5e8 1406bt_self_component_status muxer_input_port_connected(
b19ff26f
PP
1407 bt_self_component_filter *self_comp,
1408 bt_self_component_port_input *self_port,
1409 const bt_port_output *other_port)
958f7d11 1410{
5badd463 1411 bt_self_component_status status;
958f7d11 1412
5badd463
PP
1413 status = add_available_input_port(self_comp);
1414 if (status) {
06a2cb0d
PP
1415 /*
1416 * Only way to report an error later since this
1417 * method does not return anything.
1418 */
5badd463
PP
1419 BT_LOGE("Cannot add one muxer component's input port: "
1420 "status=%s",
1421 bt_self_component_status_string(status));
06a2cb0d
PP
1422 goto end;
1423 }
1424
958f7d11 1425end:
bf55043c 1426 return status;
958f7d11 1427}
b5443165 1428
54bdc1f7
PP
1429static inline
1430bt_bool muxer_upstream_msg_iters_can_all_seek_beginning(
1431 GPtrArray *muxer_upstream_msg_iters)
b5443165 1432{
b5443165
PP
1433 uint64_t i;
1434 bt_bool ret = BT_TRUE;
1435
54bdc1f7 1436 for (i = 0; i < muxer_upstream_msg_iters->len; i++) {
b5443165 1437 struct muxer_upstream_msg_iter *upstream_msg_iter =
54bdc1f7 1438 muxer_upstream_msg_iters->pdata[i];
b5443165
PP
1439
1440 if (!bt_self_component_port_input_message_iterator_can_seek_beginning(
1441 upstream_msg_iter->msg_iter)) {
1442 ret = BT_FALSE;
1443 goto end;
1444 }
1445 }
1446
1447end:
1448 return ret;
1449}
1450
54bdc1f7
PP
1451BT_HIDDEN
1452bt_bool muxer_msg_iter_can_seek_beginning(
1453 bt_self_message_iterator *self_msg_iter)
1454{
1455 struct muxer_msg_iter *muxer_msg_iter =
1456 bt_self_message_iterator_get_data(self_msg_iter);
1457 bt_bool ret = BT_TRUE;
1458
1459 if (!muxer_upstream_msg_iters_can_all_seek_beginning(
1460 muxer_msg_iter->active_muxer_upstream_msg_iters)) {
1461 ret = BT_FALSE;
1462 goto end;
1463 }
1464
1465 if (!muxer_upstream_msg_iters_can_all_seek_beginning(
1466 muxer_msg_iter->ended_muxer_upstream_msg_iters)) {
1467 ret = BT_FALSE;
1468 goto end;
1469 }
1470
1471end:
1472 return ret;
1473}
1474
b5443165
PP
1475BT_HIDDEN
1476bt_self_message_iterator_status muxer_msg_iter_seek_beginning(
1477 bt_self_message_iterator *self_msg_iter)
1478{
1479 struct muxer_msg_iter *muxer_msg_iter =
1480 bt_self_message_iterator_get_data(self_msg_iter);
ffb12c4f 1481 bt_message_iterator_status status = BT_MESSAGE_ITERATOR_STATUS_OK;
b5443165
PP
1482 uint64_t i;
1483
54bdc1f7
PP
1484 /* Seek all ended upstream iterators first */
1485 for (i = 0; i < muxer_msg_iter->ended_muxer_upstream_msg_iters->len;
1486 i++) {
b5443165 1487 struct muxer_upstream_msg_iter *upstream_msg_iter =
54bdc1f7 1488 muxer_msg_iter->ended_muxer_upstream_msg_iters->pdata[i];
b5443165
PP
1489
1490 status = bt_self_component_port_input_message_iterator_seek_beginning(
1491 upstream_msg_iter->msg_iter);
1492 if (status != BT_MESSAGE_ITERATOR_STATUS_OK) {
1493 goto end;
1494 }
54bdc1f7
PP
1495
1496 empty_message_queue(upstream_msg_iter);
1497 }
1498
1499 /* Seek all previously active upstream iterators */
1500 for (i = 0; i < muxer_msg_iter->active_muxer_upstream_msg_iters->len;
1501 i++) {
1502 struct muxer_upstream_msg_iter *upstream_msg_iter =
1503 muxer_msg_iter->active_muxer_upstream_msg_iters->pdata[i];
1504
1505 status = bt_self_component_port_input_message_iterator_seek_beginning(
1506 upstream_msg_iter->msg_iter);
1507 if (status != BT_MESSAGE_ITERATOR_STATUS_OK) {
1508 goto end;
1509 }
1510
1511 empty_message_queue(upstream_msg_iter);
1512 }
1513
1514 /* Make them all active */
1515 for (i = 0; i < muxer_msg_iter->ended_muxer_upstream_msg_iters->len;
1516 i++) {
1517 struct muxer_upstream_msg_iter *upstream_msg_iter =
1518 muxer_msg_iter->ended_muxer_upstream_msg_iters->pdata[i];
1519
1520 g_ptr_array_add(muxer_msg_iter->active_muxer_upstream_msg_iters,
1521 upstream_msg_iter);
1522 muxer_msg_iter->ended_muxer_upstream_msg_iters->pdata[i] = NULL;
b5443165
PP
1523 }
1524
54bdc1f7
PP
1525 g_ptr_array_remove_range(muxer_msg_iter->ended_muxer_upstream_msg_iters,
1526 0, muxer_msg_iter->ended_muxer_upstream_msg_iters->len);
b5443165 1527 muxer_msg_iter->last_returned_ts_ns = INT64_MIN;
54bdc1f7
PP
1528 muxer_msg_iter->clock_class_expectation =
1529 MUXER_MSG_ITER_CLOCK_CLASS_EXPECTATION_ANY;
b5443165
PP
1530
1531end:
ffb12c4f 1532 return (bt_self_message_iterator_status) status;
b5443165 1533}
This page took 0.126171 seconds and 4 git commands to generate.