mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-12-23 00:36:51 +00:00
qsvh264enc: Optimization for byte-stream to packetized format conversion
Allocate single memory instead of per NAL Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/4005>
This commit is contained in:
parent
b1c14b0357
commit
5eb4253547
1 changed files with 22 additions and 11 deletions
|
@ -1755,7 +1755,11 @@ gst_qsv_h264_enc_create_output_buffer (GstQsvEncoder * encoder,
|
|||
buf = gst_buffer_new_memdup (bitstream->Data + bitstream->DataOffset,
|
||||
bitstream->DataLength);
|
||||
} else {
|
||||
buf = gst_buffer_new ();
|
||||
std::vector < GstH264NalUnit > nalu_list;
|
||||
gsize total_size = 0;
|
||||
GstMapInfo info;
|
||||
guint8 *data;
|
||||
|
||||
rst = gst_h264_parser_identify_nalu (self->parser,
|
||||
bitstream->Data + bitstream->DataOffset, 0, bitstream->DataLength,
|
||||
&nalu);
|
||||
|
@ -1763,16 +1767,8 @@ gst_qsv_h264_enc_create_output_buffer (GstQsvEncoder * encoder,
|
|||
rst = GST_H264_PARSER_OK;
|
||||
|
||||
while (rst == GST_H264_PARSER_OK) {
|
||||
GstMemory *mem;
|
||||
guint8 *data;
|
||||
|
||||
data = (guint8 *) g_malloc0 (nalu.size + 4);
|
||||
GST_WRITE_UINT32_BE (data, nalu.size);
|
||||
memcpy (data + 4, nalu.data + nalu.offset, nalu.size);
|
||||
|
||||
mem = gst_memory_new_wrapped ((GstMemoryFlags) 0, data, nalu.size + 4,
|
||||
0, nalu.size + 4, data, (GDestroyNotify) g_free);
|
||||
gst_buffer_append_memory (buf, mem);
|
||||
nalu_list.push_back (nalu);
|
||||
total_size += nalu.size + 4;
|
||||
|
||||
rst = gst_h264_parser_identify_nalu (self->parser,
|
||||
bitstream->Data + bitstream->DataOffset, nalu.offset + nalu.size,
|
||||
|
@ -1781,6 +1777,21 @@ gst_qsv_h264_enc_create_output_buffer (GstQsvEncoder * encoder,
|
|||
if (rst == GST_H264_PARSER_NO_NAL_END)
|
||||
rst = GST_H264_PARSER_OK;
|
||||
}
|
||||
|
||||
buf = gst_buffer_new_and_alloc (total_size);
|
||||
gst_buffer_map (buf, &info, GST_MAP_WRITE);
|
||||
data = (guint8 *) info.data;
|
||||
|
||||
/* *INDENT-OFF* */
|
||||
for (const auto & it : nalu_list) {
|
||||
GST_WRITE_UINT32_BE (data, it.size);
|
||||
data += 4;
|
||||
memcpy (data, it.data + it.offset, it.size);
|
||||
data += it.size;
|
||||
}
|
||||
/* *INDENT-ON* */
|
||||
|
||||
gst_buffer_unmap (buf, &info);
|
||||
}
|
||||
|
||||
/* This buffer must be the end of a frame boundary */
|
||||
|
|
Loading…
Reference in a new issue