summaryrefslogtreecommitdiff
path: root/profiles/midi
diff options
context:
space:
mode:
authorTedd Ho-Jeong An <tedd.an@intel.com>2020-06-19 11:34:56 -0700
committerLuiz Augusto von Dentz <luiz.von.dentz@intel.com>2020-06-22 10:13:34 -0700
commitc29241fe129f4a8dbca4adff45eacf9348d6ae2e (patch)
tree3e37b62955255791491359ba2005455eb63ea268 /profiles/midi
parentb53fef50969b49f7c2a1376a11677817d3bdcf80 (diff)
downloadbluez-c29241fe129f4a8dbca4adff45eacf9348d6ae2e.tar.gz
midi: Fix random empty timestamp_high value
The timestamp_high value is assigned from the monotonic time but there is a chance that the value becomes zero because it reads the value between bit8 and bit13. This patch makes sure the timestamp_high value get a non-zero value.
Diffstat (limited to 'profiles/midi')
-rw-r--r--profiles/midi/libmidi.c9
1 files changed, 7 insertions, 2 deletions
diff --git a/profiles/midi/libmidi.c b/profiles/midi/libmidi.c
index 7d57e7335..cb2787db1 100644
--- a/profiles/midi/libmidi.c
+++ b/profiles/midi/libmidi.c
@@ -77,8 +77,13 @@ inline static void append_timestamp_high_maybe(struct midi_write_parser *parser)
if (midi_write_has_data(parser))
return;
- parser->rtime = g_get_monotonic_time() / 1000; /* convert µs to ms */
- timestamp_high |= (parser->rtime & 0x1F80) >> 7;
+ /* Make sure timesampt_high is assigned a non-zero value */
+ do {
+ /* convert µs to ms */
+ parser->rtime = g_get_monotonic_time() / 1000;
+ timestamp_high |= (parser->rtime & 0x1F80) >> 7;
+ } while (timestamp_high == 0x80);
+
/* set timestampHigh */
buffer_append_byte(&parser->midi_stream, timestamp_high);
}