audio-buffer: Don't fail to map buffers with zero samples

Instead initialize the map infos, etc to NULL like gst_buffer_map()
would be doing on a zero-sized buffer.

This fixes a crash in audioresample if the first output buffer would
contain zero samples.
This commit is contained in:
Sebastian Dröge 2019-11-14 12:37:58 +01:00
parent 4960f385cf
commit 89f613abf5

View file

@ -154,16 +154,22 @@ gst_audio_buffer_map (GstAudioBuffer * buffer, const GstAudioInfo * info,
buffer->map_infos = buffer->priv_map_infos_arr;
}
for (i = 0; i < buffer->n_planes; i++) {
if (!gst_buffer_find_memory (gstbuffer, meta->offsets[i],
GST_AUDIO_BUFFER_PLANE_SIZE (buffer), &idx, &length, &skip))
goto no_memory;
if (buffer->n_samples == 0) {
memset (buffer->map_infos, 0,
buffer->n_planes * sizeof (buffer->map_infos[0]));
memset (buffer->planes, 0, buffer->n_planes * sizeof (buffer->planes[0]));
} else {
for (i = 0; i < buffer->n_planes; i++) {
if (!gst_buffer_find_memory (gstbuffer, meta->offsets[i],
GST_AUDIO_BUFFER_PLANE_SIZE (buffer), &idx, &length, &skip))
goto no_memory;
if (!gst_buffer_map_range (gstbuffer, idx, length, &buffer->map_infos[i],
flags))
goto cannot_map;
if (!gst_buffer_map_range (gstbuffer, idx, length,
&buffer->map_infos[i], flags))
goto cannot_map;
buffer->planes[i] = buffer->map_infos[i].data + skip;
buffer->planes[i] = buffer->map_infos[i].data + skip;
}
}
}