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/1272>
This commit is contained in:
He Junyan 2021-09-19 00:19:43 +08:00 committed by GStreamer Marge Bot
parent 7cec3538f5
commit 68f6730221

View file

@ -200,7 +200,7 @@ gst_bit_writer_reset_and_get_data (GstBitWriter * bitwriter)
data = bitwriter->data;
if (bitwriter->owned)
data = g_memdup (data, bitwriter->bit_size >> 3);
data = g_memdup (data, GST_ROUND_UP_8 (bitwriter->bit_size) >> 3);
gst_bit_writer_reset (bitwriter);
return data;
@ -226,7 +226,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