bitwriter: Fix the trailing bits lost when getting its data.

In reset_and_get_data and reset_and_get_buffer, it fails to include
the trailing bits less than 8. So, when the bit_size is not byte
aligned, the trailing bits are lost in the return buffer.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/886>
This commit is contained in:
He Junyan 2021-09-19 00:19:43 +08:00
parent c6acee201e
commit 81cf9754e3

View file

@ -202,7 +202,7 @@ gst_bit_writer_reset_and_get_data (GstBitWriter * bitwriter)
data = bitwriter->data;
if (bitwriter->owned)
data = g_memdup2 (data, bitwriter->bit_size >> 3);
data = g_memdup2 (data, GST_ROUND_UP_8 (bitwriter->bit_size) >> 3);
gst_bit_writer_reset (bitwriter);
return data;
@ -228,7 +228,7 @@ gst_bit_writer_reset_and_get_buffer (GstBitWriter * bitwriter)
g_return_val_if_fail (bitwriter != NULL, NULL);
size = bitwriter->bit_size >> 3;
size = GST_ROUND_UP_8 (bitwriter->bit_size) >> 3;
data = gst_bit_writer_reset_and_get_data (bitwriter);
/* we cannot rely on buffers allocated externally, thus let's dup