4 * Babeltrace CTF IR - Stream
6 * Copyright 2013, 2014 Jérémie Galarneau <jeremie.galarneau@efficios.com>
8 * Author: Jérémie Galarneau <jeremie.galarneau@efficios.com>
10 * Permission is hereby granted, free of charge, to any person obtaining a copy
11 * of this software and associated documentation files (the "Software"), to deal
12 * in the Software without restriction, including without limitation the rights
13 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14 * copies of the Software, and to permit persons to whom the Software is
15 * furnished to do so, subject to the following conditions:
17 * The above copyright notice and this permission notice shall be included in
18 * all copies or substantial portions of the Software.
20 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
29 #include <babeltrace/ctf-ir/clock.h>
30 #include <babeltrace/ctf-ir/clock-internal.h>
31 #include <babeltrace/ctf-writer/event.h>
32 #include <babeltrace/ctf-ir/event-internal.h>
33 #include <babeltrace/ctf-ir/field-types-internal.h>
34 #include <babeltrace/ctf-ir/fields-internal.h>
35 #include <babeltrace/ctf-ir/stream.h>
36 #include <babeltrace/ctf-ir/stream-internal.h>
37 #include <babeltrace/ctf-ir/stream-class-internal.h>
38 #include <babeltrace/ctf-ir/trace-internal.h>
39 #include <babeltrace/ctf-writer/writer-internal.h>
40 #include <babeltrace/ref.h>
41 #include <babeltrace/ctf-writer/functor-internal.h>
42 #include <babeltrace/compiler.h>
43 #include <babeltrace/align.h>
44 #include <babeltrace/ctf/ctf-index.h>
47 void bt_ctf_stream_destroy(struct bt_object
*obj
);
49 int set_structure_field_integer(struct bt_ctf_field
*, char *, uint64_t);
52 int set_packet_header_magic(struct bt_ctf_stream
*stream
)
55 struct bt_ctf_field_type
*magic_field_type
= NULL
;
56 struct bt_ctf_field
*magic_field
= bt_ctf_field_structure_get_field(
57 stream
->packet_header
, "magic");
60 /* No magic field found. Not an error, skip. */
64 if (!bt_ctf_field_validate(magic_field
)) {
65 /* Value already set. Not an error, skip. */
69 magic_field_type
= bt_ctf_field_get_type(magic_field
);
70 assert(magic_field_type
);
72 if (bt_ctf_field_type_get_type_id(magic_field_type
) !=
73 BT_CTF_TYPE_ID_INTEGER
) {
74 /* Magic field is not an integer. Not an error, skip. */
78 if (bt_ctf_field_type_integer_get_size(magic_field_type
) != 32) {
80 * Magic field is not of the expected size.
86 ret
= bt_ctf_field_type_integer_get_signed(magic_field_type
);
89 ret
= bt_ctf_field_signed_integer_set_value(magic_field
,
90 (int64_t) 0xC1FC1FC1);
92 ret
= bt_ctf_field_unsigned_integer_set_value(magic_field
,
93 (uint64_t) 0xC1FC1FC1);
97 bt_put(magic_field_type
);
102 int set_packet_header_uuid(struct bt_ctf_stream
*stream
)
105 struct bt_ctf_trace
*trace
= NULL
;
106 struct bt_ctf_field_type
*uuid_field_type
= NULL
;
107 struct bt_ctf_field_type
*element_field_type
= NULL
;
108 struct bt_ctf_field
*uuid_field
= bt_ctf_field_structure_get_field(
109 stream
->packet_header
, "uuid");
112 /* No uuid field found. Not an error, skip. */
116 if (!bt_ctf_field_validate(uuid_field
)) {
117 /* Value already set. Not an error, skip. */
121 uuid_field_type
= bt_ctf_field_get_type(uuid_field
);
122 assert(uuid_field_type
);
123 if (bt_ctf_field_type_get_type_id(uuid_field_type
) !=
124 BT_CTF_TYPE_ID_ARRAY
) {
125 /* UUID field is not an array. Not an error, skip. */
129 if (bt_ctf_field_type_array_get_length(uuid_field_type
) != 16) {
131 * UUID field is not of the expected size.
132 * Not an error, skip.
137 element_field_type
= bt_ctf_field_type_array_get_element_type(
139 assert(element_field_type
);
140 if (bt_ctf_field_type_get_type_id(element_field_type
) !=
141 BT_CTF_TYPE_ID_INTEGER
) {
142 /* UUID array elements are not integers. Not an error, skip */
146 trace
= (struct bt_ctf_trace
*) bt_object_get_parent(stream
);
147 for (i
= 0; i
< 16; i
++) {
148 struct bt_ctf_field
*uuid_element
=
149 bt_ctf_field_array_get_field(uuid_field
, i
);
151 ret
= bt_ctf_field_type_integer_get_signed(element_field_type
);
155 ret
= bt_ctf_field_signed_integer_set_value(
156 uuid_element
, (int64_t) trace
->uuid
[i
]);
158 ret
= bt_ctf_field_unsigned_integer_set_value(
160 (uint64_t) trace
->uuid
[i
]);
162 bt_put(uuid_element
);
170 bt_put(uuid_field_type
);
171 bt_put(element_field_type
);
176 int set_packet_header_stream_id(struct bt_ctf_stream
*stream
)
180 struct bt_ctf_field_type
*stream_id_field_type
= NULL
;
181 struct bt_ctf_field
*stream_id_field
= bt_ctf_field_structure_get_field(
182 stream
->packet_header
, "stream_id");
184 if (!stream_id_field
) {
185 /* No stream_id field found. Not an error, skip. */
189 if (!bt_ctf_field_validate(stream_id_field
)) {
190 /* Value already set. Not an error, skip. */
194 stream_id_field_type
= bt_ctf_field_get_type(stream_id_field
);
195 assert(stream_id_field_type
);
196 if (bt_ctf_field_type_get_type_id(stream_id_field_type
) !=
197 BT_CTF_TYPE_ID_INTEGER
) {
198 /* stream_id field is not an integer. Not an error, skip. */
202 stream_id
= stream
->stream_class
->id
;
203 ret
= bt_ctf_field_type_integer_get_signed(stream_id_field_type
);
206 ret
= bt_ctf_field_signed_integer_set_value(stream_id_field
,
207 (int64_t) stream_id
);
209 ret
= bt_ctf_field_unsigned_integer_set_value(stream_id_field
,
210 (uint64_t) stream_id
);
213 bt_put(stream_id_field
);
214 bt_put(stream_id_field_type
);
219 int set_packet_header(struct bt_ctf_stream
*stream
)
223 ret
= set_packet_header_magic(stream
);
228 ret
= set_packet_header_uuid(stream
);
233 ret
= set_packet_header_stream_id(stream
);
242 void release_event(struct bt_ctf_event
*event
)
244 if (bt_object_get_ref_count(event
)) {
246 * The event is being orphaned, but it must guarantee the
247 * existence of its event class for the duration of its
250 bt_get(event
->event_class
);
251 BT_PUT(event
->base
.parent
);
253 bt_object_release(event
);
258 int create_stream_file(struct bt_ctf_writer
*writer
,
259 struct bt_ctf_stream
*stream
)
262 GString
*filename
= g_string_new(stream
->stream_class
->name
->str
);
264 if (stream
->stream_class
->name
->len
== 0) {
267 ret
= bt_ctf_stream_class_get_id(stream
->stream_class
);
273 g_string_printf(filename
, "stream_%" PRId64
, ret
);
276 g_string_append_printf(filename
, "_%" PRIu32
, stream
->id
);
277 fd
= openat(writer
->trace_dir_fd
, filename
->str
,
278 O_RDWR
| O_CREAT
| O_TRUNC
,
279 S_IRUSR
| S_IWUSR
| S_IRGRP
| S_IWGRP
);
281 g_string_free(filename
, TRUE
);
286 int set_stream_fd(struct bt_ctf_stream
*stream
, int fd
)
290 if (stream
->pos
.fd
!= -1) {
295 ctf_init_pos(&stream
->pos
, NULL
, fd
, O_RDWR
);
301 struct bt_ctf_stream
*bt_ctf_stream_create(
302 struct bt_ctf_stream_class
*stream_class
,
306 struct bt_ctf_stream
*stream
= NULL
;
307 struct bt_ctf_trace
*trace
= NULL
;
308 struct bt_ctf_writer
*writer
= NULL
;
314 trace
= bt_ctf_stream_class_get_trace(stream_class
);
319 stream
= g_new0(struct bt_ctf_stream
, 1);
324 bt_object_init(stream
, bt_ctf_stream_destroy
);
326 * Acquire reference to parent since stream will become publicly
327 * reachable; it needs its parent to remain valid.
329 bt_object_set_parent(stream
, trace
);
330 stream
->id
= stream_class
->next_stream_id
++;
331 stream
->stream_class
= stream_class
;
335 stream
->name
= g_string_new(name
);
341 if (trace
->is_created_by_writer
) {
343 writer
= (struct bt_ctf_writer
*)
344 bt_object_get_parent(trace
);
347 stream
->packet_context
= bt_ctf_field_create(
348 stream_class
->packet_context_type
);
349 if (!stream
->packet_context
) {
353 /* Initialize events_discarded */
354 ret
= set_structure_field_integer(stream
->packet_context
,
355 "events_discarded", 0);
360 stream
->events
= g_ptr_array_new_with_free_func(
361 (GDestroyNotify
) release_event
);
362 if (!stream
->events
) {
366 /* A trace is not allowed to have a NULL packet header */
367 assert(trace
->packet_header_type
);
368 stream
->packet_header
=
369 bt_ctf_field_create(trace
->packet_header_type
);
370 if (!stream
->packet_header
) {
375 * Attempt to populate the default trace packet header fields
376 * (magic, uuid and stream_id). This will _not_ fail shall the
377 * fields not be found or be of an incompatible type; they will
378 * simply not be populated automatically. The user will have to
379 * make sure to set the trace packet header fields himself
382 ret
= set_packet_header(stream
);
387 /* Create file associated with this stream */
388 fd
= create_stream_file(writer
, stream
);
393 ret
= set_stream_fd(stream
, fd
);
398 /* Freeze the writer */
399 bt_ctf_writer_freeze(writer
);
401 /* Non-writer stream indicated by a negative FD */
402 ret
= set_stream_fd(stream
, -1);
407 stream
->clock_values
= g_hash_table_new_full(g_direct_hash
,
408 g_direct_equal
, NULL
, g_free
);
411 /* Add this stream to the trace's streams */
412 g_ptr_array_add(trace
->streams
, stream
);
424 struct bt_ctf_stream_class
*bt_ctf_stream_get_class(
425 struct bt_ctf_stream
*stream
)
427 struct bt_ctf_stream_class
*stream_class
= NULL
;
433 stream_class
= stream
->stream_class
;
434 bt_get(stream_class
);
439 int bt_ctf_stream_get_discarded_events_count(
440 struct bt_ctf_stream
*stream
, uint64_t *count
)
444 struct bt_ctf_field
*events_discarded_field
= NULL
;
445 struct bt_ctf_field_type
*events_discarded_field_type
= NULL
;
447 if (!stream
|| !count
|| !stream
->packet_context
||
448 stream
->pos
.fd
< 0) {
453 events_discarded_field
= bt_ctf_field_structure_get_field(
454 stream
->packet_context
, "events_discarded");
455 if (!events_discarded_field
) {
460 events_discarded_field_type
= bt_ctf_field_get_type(
461 events_discarded_field
);
462 if (!events_discarded_field_type
) {
467 field_signed
= bt_ctf_field_type_integer_get_signed(
468 events_discarded_field_type
);
469 if (field_signed
< 0) {
475 int64_t signed_count
;
477 ret
= bt_ctf_field_signed_integer_get_value(
478 events_discarded_field
, &signed_count
);
482 if (signed_count
< 0) {
487 *count
= (uint64_t) signed_count
;
489 ret
= bt_ctf_field_unsigned_integer_get_value(
490 events_discarded_field
, count
);
496 bt_put(events_discarded_field
);
497 bt_put(events_discarded_field_type
);
501 void bt_ctf_stream_append_discarded_events(struct bt_ctf_stream
*stream
,
502 uint64_t event_count
)
506 uint64_t previous_count
;
508 struct bt_ctf_field
*events_discarded_field
= NULL
;
509 struct bt_ctf_field_type
*events_discarded_field_type
= NULL
;
511 if (!stream
|| !stream
->packet_context
|| stream
->pos
.fd
< 0) {
515 ret
= bt_ctf_stream_get_discarded_events_count(stream
,
521 events_discarded_field
= bt_ctf_field_structure_get_field(
522 stream
->packet_context
, "events_discarded");
523 if (!events_discarded_field
) {
527 events_discarded_field_type
= bt_ctf_field_get_type(
528 events_discarded_field
);
529 if (!events_discarded_field_type
) {
533 field_signed
= bt_ctf_field_type_integer_get_signed(
534 events_discarded_field_type
);
535 if (field_signed
< 0) {
539 new_count
= previous_count
+ event_count
;
541 ret
= bt_ctf_field_signed_integer_set_value(
542 events_discarded_field
, (int64_t) new_count
);
547 ret
= bt_ctf_field_unsigned_integer_set_value(
548 events_discarded_field
, new_count
);
555 bt_put(events_discarded_field
);
556 bt_put(events_discarded_field_type
);
559 int bt_ctf_stream_append_event(struct bt_ctf_stream
*stream
,
560 struct bt_ctf_event
*event
)
564 if (!stream
|| !event
|| stream
->pos
.fd
< 0) {
570 * The event is not supposed to have a parent stream at this
571 * point. The only other way an event can have a parent stream
572 * is if it was assigned when setting a packet to the event,
573 * in which case the packet's stream is not a writer stream,
574 * and thus the user is trying to append an event which belongs
577 if (event
->base
.parent
) {
582 bt_object_set_parent(event
, stream
);
583 ret
= bt_ctf_event_populate_event_header(event
);
588 /* Make sure the various scopes of the event are set */
589 ret
= bt_ctf_event_validate(event
);
594 /* Save the new event and freeze it */
595 bt_ctf_event_freeze(event
);
596 g_ptr_array_add(stream
->events
, event
);
599 * Event had to hold a reference to its event class as long as it wasn't
600 * part of the same trace hierarchy. From now on, the event and its
601 * class share the same lifetime guarantees and the reference is no
604 bt_put(event
->event_class
);
608 * Orphan the event; we were not succesful in associating it to
611 bt_object_set_parent(event
, NULL
);
616 struct bt_ctf_field
*bt_ctf_stream_get_packet_context(
617 struct bt_ctf_stream
*stream
)
619 struct bt_ctf_field
*packet_context
= NULL
;
621 if (!stream
|| stream
->pos
.fd
< 0) {
625 packet_context
= stream
->packet_context
;
626 if (packet_context
) {
627 bt_get(packet_context
);
630 return packet_context
;
633 int bt_ctf_stream_set_packet_context(struct bt_ctf_stream
*stream
,
634 struct bt_ctf_field
*field
)
637 struct bt_ctf_field_type
*field_type
;
639 if (!stream
|| !field
|| stream
->pos
.fd
< 0) {
644 field_type
= bt_ctf_field_get_type(field
);
645 if (bt_ctf_field_type_compare(field_type
,
646 stream
->stream_class
->packet_context_type
)) {
653 bt_put(stream
->packet_context
);
654 stream
->packet_context
= field
;
659 struct bt_ctf_field
*bt_ctf_stream_get_packet_header(
660 struct bt_ctf_stream
*stream
)
662 struct bt_ctf_field
*packet_header
= NULL
;
664 if (!stream
|| stream
->pos
.fd
< 0) {
668 packet_header
= stream
->packet_header
;
670 bt_get(packet_header
);
673 return packet_header
;
676 int bt_ctf_stream_set_packet_header(struct bt_ctf_stream
*stream
,
677 struct bt_ctf_field
*field
)
680 struct bt_ctf_trace
*trace
= NULL
;
681 struct bt_ctf_field_type
*field_type
= NULL
;
683 if (!stream
|| !field
|| stream
->pos
.fd
< 0) {
688 trace
= (struct bt_ctf_trace
*) bt_object_get_parent(stream
);
689 field_type
= bt_ctf_field_get_type(field
);
690 if (bt_ctf_field_type_compare(field_type
, trace
->packet_header_type
)) {
696 bt_put(stream
->packet_header
);
697 stream
->packet_header
= field
;
705 int get_event_header_timestamp(struct bt_ctf_field
*event_header
, uint64_t *timestamp
)
708 struct bt_ctf_field
*timestamp_field
= NULL
;
709 struct bt_ctf_field_type
*timestamp_field_type
= NULL
;
711 timestamp_field
= bt_ctf_field_structure_get_field(event_header
,
713 if (!timestamp_field
) {
718 timestamp_field_type
= bt_ctf_field_get_type(timestamp_field
);
719 assert(timestamp_field_type
);
720 if (bt_ctf_field_type_get_type_id(timestamp_field_type
) !=
721 BT_CTF_TYPE_ID_INTEGER
) {
726 if (bt_ctf_field_type_integer_get_signed(timestamp_field_type
)) {
729 ret
= bt_ctf_field_signed_integer_get_value(timestamp_field
,
734 *timestamp
= (uint64_t) val
;
736 ret
= bt_ctf_field_unsigned_integer_get_value(timestamp_field
,
743 bt_put(timestamp_field
);
744 bt_put(timestamp_field_type
);
748 int bt_ctf_stream_flush(struct bt_ctf_stream
*stream
)
752 uint64_t timestamp_begin
, timestamp_end
, events_discarded
;
753 struct bt_ctf_field
*integer
= NULL
;
754 struct ctf_stream_pos packet_context_pos
;
756 if (!stream
|| stream
->pos
.fd
< 0) {
758 * Stream does not have an associated fd. It is,
759 * therefore, not a stream being used to write events.
765 if (!stream
->events
->len
) {
769 ret
= bt_ctf_field_validate(stream
->packet_header
);
774 /* mmap the next packet */
775 ctf_packet_seek(&stream
->pos
.parent
, 0, SEEK_CUR
);
777 ret
= bt_ctf_field_serialize(stream
->packet_header
, &stream
->pos
);
782 /* Set the default context attributes if present and unset. */
783 if (!get_event_header_timestamp(
784 ((struct bt_ctf_event
*) g_ptr_array_index(
785 stream
->events
, 0))->event_header
, ×tamp_begin
)) {
786 ret
= set_structure_field_integer(stream
->packet_context
,
787 "timestamp_begin", timestamp_begin
);
793 if (!get_event_header_timestamp(
794 ((struct bt_ctf_event
*) g_ptr_array_index(
795 stream
->events
, stream
->events
->len
- 1))->event_header
,
798 ret
= set_structure_field_integer(stream
->packet_context
,
799 "timestamp_end", timestamp_end
);
804 ret
= set_structure_field_integer(stream
->packet_context
,
805 "content_size", UINT64_MAX
);
810 ret
= set_structure_field_integer(stream
->packet_context
,
811 "packet_size", UINT64_MAX
);
816 /* Write packet context */
817 memcpy(&packet_context_pos
, &stream
->pos
,
818 sizeof(struct ctf_stream_pos
));
819 ret
= bt_ctf_field_serialize(stream
->packet_context
,
825 ret
= bt_ctf_stream_get_discarded_events_count(stream
,
831 /* Unset the packet context's fields. */
832 ret
= bt_ctf_field_reset(stream
->packet_context
);
837 /* Set the previous number of discarded events. */
838 ret
= set_structure_field_integer(stream
->packet_context
,
839 "events_discarded", events_discarded
);
844 for (i
= 0; i
< stream
->events
->len
; i
++) {
845 struct bt_ctf_event
*event
= g_ptr_array_index(
848 ret
= bt_ctf_field_reset(event
->event_header
);
853 /* Write event header */
854 ret
= bt_ctf_field_serialize(event
->event_header
,
860 /* Write stream event context */
861 if (event
->stream_event_context
) {
862 ret
= bt_ctf_field_serialize(
863 event
->stream_event_context
, &stream
->pos
);
869 /* Write event content */
870 ret
= bt_ctf_event_serialize(event
, &stream
->pos
);
877 * Update the packet total size and content size and overwrite the
879 * Copy base_mma as the packet may have been remapped (e.g. when a
880 * packet is resized).
882 packet_context_pos
.base_mma
= stream
->pos
.base_mma
;
883 ret
= set_structure_field_integer(stream
->packet_context
,
884 "content_size", stream
->pos
.offset
);
889 ret
= set_structure_field_integer(stream
->packet_context
,
890 "packet_size", stream
->pos
.packet_size
);
895 ret
= bt_ctf_field_serialize(stream
->packet_context
,
896 &packet_context_pos
);
901 g_ptr_array_set_size(stream
->events
, 0);
902 stream
->flushed_packet_count
++;
908 void bt_ctf_stream_get(struct bt_ctf_stream
*stream
)
913 void bt_ctf_stream_put(struct bt_ctf_stream
*stream
)
919 void bt_ctf_stream_destroy(struct bt_object
*obj
)
921 struct bt_ctf_stream
*stream
;
923 stream
= container_of(obj
, struct bt_ctf_stream
, base
);
924 ctf_fini_pos(&stream
->pos
);
925 if (stream
->pos
.fd
>= 0 && close(stream
->pos
.fd
)) {
929 if (stream
->events
) {
930 g_ptr_array_free(stream
->events
, TRUE
);
934 g_string_free(stream
->name
, TRUE
);
937 if (stream
->clock_values
) {
938 g_hash_table_destroy(stream
->clock_values
);
941 bt_put(stream
->packet_header
);
942 bt_put(stream
->packet_context
);
947 int set_structure_field_integer(struct bt_ctf_field
*structure
, char *name
,
951 struct bt_ctf_field_type
*field_type
= NULL
;
952 struct bt_ctf_field
*integer
=
953 bt_ctf_field_structure_get_field(structure
, name
);
955 if (!structure
|| !name
) {
961 /* Field not found, not an error. */
965 /* Make sure the payload has not already been set. */
966 if (!bt_ctf_field_validate(integer
)) {
967 /* Payload already set, not an error */
971 field_type
= bt_ctf_field_get_type(integer
);
972 /* Something is serioulsly wrong */
974 if (bt_ctf_field_type_get_type_id(field_type
) != BT_CTF_TYPE_ID_INTEGER
) {
976 * The user most likely meant for us to populate this field
977 * automatically. However, we can only do this if the field
978 * is an integer. Return an error.
984 if (bt_ctf_field_type_integer_get_signed(field_type
)) {
985 ret
= bt_ctf_field_signed_integer_set_value(integer
,
988 ret
= bt_ctf_field_unsigned_integer_set_value(integer
, value
);
996 const char *bt_ctf_stream_get_name(struct bt_ctf_stream
*stream
)
998 const char *name
= NULL
;
1004 name
= stream
->name
? stream
->name
->str
: NULL
;
1011 void bt_ctf_stream_update_clock_value(struct bt_ctf_stream
*stream
,
1012 struct bt_ctf_field
*value_field
)
1014 struct bt_ctf_field_type
*value_type
= NULL
;
1015 struct bt_ctf_clock
*clock
= NULL
;
1016 uint64_t requested_new_value
;
1017 uint64_t requested_new_value_mask
;
1018 uint64_t *cur_value
;
1019 uint64_t cur_value_masked
;
1020 int requested_new_value_size
;
1025 assert(value_field
);
1026 value_type
= bt_ctf_field_get_type(value_field
);
1028 clock
= bt_ctf_field_type_integer_get_mapped_clock(value_type
);
1030 requested_new_value_size
=
1031 bt_ctf_field_type_integer_get_size(value_type
);
1032 assert(requested_new_value_size
> 0);
1033 ret
= bt_ctf_field_unsigned_integer_get_value(value_field
,
1034 &requested_new_value
);
1036 cur_value
= g_hash_table_lookup(stream
->clock_values
, clock
);
1040 * Updating the value of a clock which is not registered
1041 * yet, so register it with the new value as its initial
1044 uint64_t *requested_new_value_ptr
= g_new0(uint64_t, 1);
1046 *requested_new_value_ptr
= requested_new_value
;
1047 g_hash_table_insert(stream
->clock_values
, clock
,
1048 requested_new_value_ptr
);
1053 * Special case for a 64-bit new value, which is the limit
1054 * of a clock value as of this version: overwrite the
1055 * current value directly.
1057 if (requested_new_value_size
== 64) {
1058 *cur_value
= requested_new_value
;
1062 requested_new_value_mask
= (1ULL << requested_new_value_size
) - 1;
1063 cur_value_masked
= *cur_value
& requested_new_value_mask
;
1065 if (requested_new_value
< cur_value_masked
) {
1067 * It looks like a wrap happened on the number of bits
1068 * of the requested new value. Assume that the clock
1069 * value wrapped only one time.
1071 *cur_value
+= requested_new_value_mask
+ 1;
1074 /* Clear the low bits of the current clock value */
1075 *cur_value
&= ~requested_new_value_mask
;
1077 /* Set the low bits of the current clock value */
1078 *cur_value
|= requested_new_value
;