Use g_memdup2() where available and add fallback for older GLib versions

- png: alloc size variable is a png type that's always 32-bit
- vpx: alloc size based on existing allocation
- wavpack: alloc size based on existing allocation
- icles: gdkpixbufoverlay: trusted and hard-coded input data
- rtp tests: rtp-payloading, vp8, vp9, h264, h265: trusted and/or static input data

g_memdup() is deprecated since GLib 2.68 and we want to avoid
deprecation warnings with recent versions of GLib.

Also use gst_buffer_new_memdup() instead of _wrapped(g_memdup(),..)

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-good/-/merge_requests/993>
This commit is contained in:
Tim-Philipp Müller 2021-05-22 19:39:32 +01:00
parent af3527ce24
commit bf56fd97b6
11 changed files with 46 additions and 32 deletions

View file

@ -356,7 +356,7 @@ gst_pngdec_caps_create_and_set (GstPngDec * pngdec)
&icc_compression_type, &icc_profile, &icc_proflen);
if ((ret & PNG_INFO_iCCP)) {
gpointer gst_icc_prof = g_memdup (icc_profile, icc_proflen);
gpointer gst_icc_prof = g_memdup2 (icc_profile, icc_proflen);
GstBuffer *tagbuffer = NULL;
GstSample *tagsample = NULL;
GstTagList *taglist = NULL;

View file

@ -2045,9 +2045,7 @@ gst_vpx_enc_process (GstVPXEnc * encoder)
g_assert (frame != NULL);
/* FIXME : It would be nice to avoid the memory copy ... */
buffer =
gst_buffer_new_wrapped (g_memdup (pkt->data.frame.buf,
pkt->data.frame.sz), pkt->data.frame.sz);
buffer = gst_buffer_new_memdup (pkt->data.frame.buf, pkt->data.frame.sz);
user_data = vpx_enc_class->process_frame_user_data (encoder, frame);
if (vpx_enc_class->get_frame_temporal_settings &&

View file

@ -619,7 +619,7 @@ gst_wavpack_enc_push_block (void *id, void *data, int32_t count)
GstMapInfo map;
gst_buffer_map (buffer, &map, GST_MAP_READ);
enc->first_block = g_memdup (map.data, map.size);
enc->first_block = g_memdup2 (map.data, map.size);
enc->first_block_size = map.size;
gst_buffer_unmap (buffer, &map);
}

View file

@ -491,6 +491,10 @@ if gst_version_nano == 0
endif
endif
if gio_dep.version().version_compare('< 2.67.4')
cdata.set('g_memdup2(ptr,sz)', '(G_LIKELY(((guint64)(sz)) < G_MAXUINT)) ? g_memdup(ptr,sz) : (g_abort(),NULL)')
endif
configure_file(output : 'config.h', configuration : cdata)
run_command(python3, '-c', 'import shutil; shutil.copy("hooks/pre-commit.hook", ".git/hooks/pre-commit")')

View file

@ -17,6 +17,10 @@
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <gst/check/gstcheck.h>
#include <gst/check/gstharness.h>
#include <gst/audio/audio.h>
@ -701,7 +705,7 @@ rtp_h264depay_run (const gchar * stream_format)
gst_harness_play (h);
size = sizeof (h264_16x16_black_bs);
buf = gst_buffer_new_wrapped (g_memdup (h264_16x16_black_bs, size), size);
buf = gst_buffer_new_memdup (h264_16x16_black_bs, size);
fail_unless_equals_int (gst_harness_push (h, buf), GST_FLOW_OK);
fail_unless (gst_harness_push_event (h, gst_event_new_eos ()));
@ -1716,17 +1720,13 @@ test_rtp_opus_dtx (gboolean dtx)
"application/x-rtp, media=audio, clock-rate=48000, encoding-name=OPUS, sprop-stereo=(string)0, encoding-params=(string)2, sprop-maxcapturerate=(string)48000, payload=96");
/* push first opus frame */
buf =
gst_buffer_new_wrapped (g_memdup (opus_frame, sizeof (opus_frame)),
sizeof (opus_frame));
buf = gst_buffer_new_memdup (opus_frame, sizeof (opus_frame));
fail_unless_equals_int (gst_harness_push (h, buf), GST_FLOW_OK);
seq = pull_rtp_buffer (h, TRUE);
expected_seq = seq + 1;
/* push empty frame */
buf =
gst_buffer_new_wrapped (g_memdup (opus_empty, sizeof (opus_empty)),
sizeof (opus_empty));
buf = gst_buffer_new_memdup (opus_empty, sizeof (opus_empty));
fail_unless_equals_int (gst_harness_push (h, buf), GST_FLOW_OK);
if (dtx) {
/* buffer is not transmitted if dtx is enabled */
@ -1739,9 +1739,7 @@ test_rtp_opus_dtx (gboolean dtx)
}
/* push second opus frame */
buf =
gst_buffer_new_wrapped (g_memdup (opus_frame, sizeof (opus_frame)),
sizeof (opus_frame));
buf = gst_buffer_new_memdup (opus_frame, sizeof (opus_frame));
fail_unless_equals_int (gst_harness_push (h, buf), GST_FLOW_OK);
seq = pull_rtp_buffer (h, dtx);
fail_unless_equals_int (seq, expected_seq);

View file

@ -18,6 +18,9 @@
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <gst/check/check.h>
#include <gst/app/app.h>
@ -302,8 +305,7 @@ GST_START_TEST (test_rtph264depay_with_downstream_allocator)
fail_unless (len >= 2 + packet_len);
flow = gst_app_src_push_buffer (GST_APP_SRC (src),
gst_buffer_new_wrapped (g_memdup (pdata + 2, packet_len),
packet_len));
gst_buffer_new_memdup (pdata + 2, packet_len));
fail_unless_equals_int (flow, GST_FLOW_OK);

View file

@ -20,6 +20,9 @@
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <gst/check/check.h>
#include <gst/app/app.h>
@ -258,8 +261,7 @@ GST_START_TEST (test_rtph265depay_with_downstream_allocator)
fail_unless (len >= 2 + packet_len);
flow = gst_app_src_push_buffer (GST_APP_SRC (src),
gst_buffer_new_wrapped (g_memdup (pdata + 2, packet_len),
packet_len));
gst_buffer_new_memdup (pdata + 2, packet_len));
fail_unless_equals_int (flow, GST_FLOW_OK);

View file

@ -18,11 +18,15 @@
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <gst/check/check.h>
#include <gst/check/gstharness.h>
#include <gst/rtp/gstrtpbuffer.h>
#define buffer_from_array(a) gst_buffer_new_wrapped (g_memdup (a, G_N_ELEMENTS (a)), G_N_ELEMENTS (a));
#define buffer_from_array(a) gst_buffer_new_memdup (a, G_N_ELEMENTS (a))
static guint8 opus_data[] = {
0xf8, 0xb5, 0x0e, 0x7d, 0x91, 0xcc, 0x05, 0x82,

View file

@ -18,6 +18,9 @@
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <gst/check/check.h>
#include <gst/check/gstharness.h>
@ -25,9 +28,9 @@
#define RTP_VP8_CAPS_STR \
"application/x-rtp,media=video,encoding-name=VP8,clock-rate=90000,payload=96"
#define gst_buffer_new_from_array(array) gst_buffer_new_wrapped ( \
g_memdup (vp8_bitstream_payload, sizeof (vp8_bitstream_payload)), \
sizeof (vp8_bitstream_payload))
/* FIXME: array argument is unused! */
#define gst_buffer_new_from_array(array) \
gst_buffer_new_memdup (vp8_bitstream_payload, sizeof (vp8_bitstream_payload))
static guint8 intra_picid6336_seqnum0[] = {
0x80, 0xe0, 0x00, 0x00, 0x9a, 0xbb, 0xe3, 0xb3, 0x8b, 0xe9, 0x1d, 0x61,
@ -59,14 +62,14 @@ create_rtp_vp8_buffer_full (guint seqnum, guint picid, gint picid_bits,
if (picid_bits == 0) {
size = sizeof (intra_nopicid_seqnum0);
packet = g_memdup (intra_nopicid_seqnum0, size);
packet = g_memdup2 (intra_nopicid_seqnum0, size);
} else if (picid_bits == 7) {
size = sizeof (intra_picid24_seqnum0);
packet = g_memdup (intra_picid24_seqnum0, size);
packet = g_memdup2 (intra_picid24_seqnum0, size);
packet[14] = picid & 0x7f;
} else {
size = sizeof (intra_picid6336_seqnum0);
packet = g_memdup (intra_picid6336_seqnum0, size);
packet = g_memdup2 (intra_picid6336_seqnum0, size);
packet[14] = ((picid >> 8) & 0xff) | 0x80;
packet[15] = (picid >> 0) & 0xff;
}
@ -165,8 +168,8 @@ GST_START_TEST (test_pay_no_meta)
g_object_set (h->element, "picture-id-mode", test_data->pid,
"picture-id-offset", 0x5A5A, NULL);
buffer = gst_buffer_new_wrapped (g_memdup (vp8_bitstream_payload,
sizeof (vp8_bitstream_payload)), sizeof (vp8_bitstream_payload));
buffer = gst_buffer_new_memdup (vp8_bitstream_payload,
sizeof (vp8_bitstream_payload));
/* set droppable if N flag set */
if ((test_data->vp8_payload_control_value & 0x20) != 0) {
@ -276,8 +279,8 @@ GST_START_TEST (test_pay_with_meta)
"picture-id-offset", 0x5A5A, NULL);
/* Push a buffer in */
buffer = gst_buffer_new_wrapped (g_memdup (vp8_bitstream_payload,
sizeof (vp8_bitstream_payload)), sizeof (vp8_bitstream_payload));
buffer = gst_buffer_new_memdup (vp8_bitstream_payload,
sizeof (vp8_bitstream_payload));
add_vp8_meta (buffer, test_data->use_temporal_scaling, test_data->y_flag,
2, 255);
/* set droppable if N flag set */

View file

@ -18,6 +18,9 @@
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <gst/check/check.h>
#include <gst/check/gstharness.h>
@ -168,7 +171,7 @@ create_rtp_vp9_buffer_full (guint seqnum, guint picid, guint buffer_type,
*/
};
struct BufferTemplate *template = &templates[buffer_type];
guint8 *packet = g_memdup (template->template, template->size);
guint8 *packet = g_memdup2 (template->template, template->size);
GstBuffer *ret;
packet[2] = (seqnum >> 8) & 0xff;

View file

@ -126,7 +126,7 @@ create_overlay_pixbuf (void)
g_assert (pixdata_size == 24 + height * stride);
pixels_copy = g_memdup (pixdata + 24, height * stride);
pixels_copy = g_memdup2 (pixdata + 24, height * stride);
pixbuf =
gdk_pixbuf_new_from_data (pixels_copy, GDK_COLORSPACE_RGB, TRUE, 8,