summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim-Philipp Müller <tim@centricular.com>2021-05-22 19:39:32 +0100
committerTim-Philipp Müller <tim@centricular.com>2021-06-02 17:34:38 +0100
commitbf56fd97b6cec2a059abd29b144675aad818e442 (patch)
tree9912970b783a7ffd9d70b970c821a53cba2ae9d6
parentaf3527ce24a0f9a43723e25812e48f590d37f5b5 (diff)
downloadgstreamer-plugins-good-bf56fd97b6cec2a059abd29b144675aad818e442.tar.gz
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>
-rw-r--r--ext/libpng/gstpngdec.c2
-rw-r--r--ext/vpx/gstvpxenc.c4
-rw-r--r--ext/wavpack/gstwavpackenc.c2
-rw-r--r--meson.build4
-rw-r--r--tests/check/elements/rtp-payloading.c18
-rw-r--r--tests/check/elements/rtph264.c6
-rw-r--r--tests/check/elements/rtph265.c6
-rw-r--r--tests/check/elements/rtpopus.c6
-rw-r--r--tests/check/elements/rtpvp8.c23
-rw-r--r--tests/check/elements/rtpvp9.c5
-rw-r--r--tests/icles/gdkpixbufoverlay-test.c2
11 files changed, 46 insertions, 32 deletions
diff --git a/ext/libpng/gstpngdec.c b/ext/libpng/gstpngdec.c
index 804932d90..5f6dc8f88 100644
--- a/ext/libpng/gstpngdec.c
+++ b/ext/libpng/gstpngdec.c
@@ -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;
diff --git a/ext/vpx/gstvpxenc.c b/ext/vpx/gstvpxenc.c
index 0fe0f7a98..9781cc6df 100644
--- a/ext/vpx/gstvpxenc.c
+++ b/ext/vpx/gstvpxenc.c
@@ -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 &&
diff --git a/ext/wavpack/gstwavpackenc.c b/ext/wavpack/gstwavpackenc.c
index 972a5a397..6a68db68e 100644
--- a/ext/wavpack/gstwavpackenc.c
+++ b/ext/wavpack/gstwavpackenc.c
@@ -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);
}
diff --git a/meson.build b/meson.build
index e4316b095..1f433f05a 100644
--- a/meson.build
+++ b/meson.build
@@ -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")')
diff --git a/tests/check/elements/rtp-payloading.c b/tests/check/elements/rtp-payloading.c
index d26261011..bd34794bb 100644
--- a/tests/check/elements/rtp-payloading.c
+++ b/tests/check/elements/rtp-payloading.c
@@ -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);
diff --git a/tests/check/elements/rtph264.c b/tests/check/elements/rtph264.c
index 087a37173..79c249578 100644
--- a/tests/check/elements/rtph264.c
+++ b/tests/check/elements/rtph264.c
@@ -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);
diff --git a/tests/check/elements/rtph265.c b/tests/check/elements/rtph265.c
index 23818084f..e7735ce26 100644
--- a/tests/check/elements/rtph265.c
+++ b/tests/check/elements/rtph265.c
@@ -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);
diff --git a/tests/check/elements/rtpopus.c b/tests/check/elements/rtpopus.c
index ba3fc31a4..d8c2cb43a 100644
--- a/tests/check/elements/rtpopus.c
+++ b/tests/check/elements/rtpopus.c
@@ -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,
diff --git a/tests/check/elements/rtpvp8.c b/tests/check/elements/rtpvp8.c
index 939c0280a..1bcd0d808 100644
--- a/tests/check/elements/rtpvp8.c
+++ b/tests/check/elements/rtpvp8.c
@@ -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 */
diff --git a/tests/check/elements/rtpvp9.c b/tests/check/elements/rtpvp9.c
index 45c2c1bd2..db4a50b70 100644
--- a/tests/check/elements/rtpvp9.c
+++ b/tests/check/elements/rtpvp9.c
@@ -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;
diff --git a/tests/icles/gdkpixbufoverlay-test.c b/tests/icles/gdkpixbufoverlay-test.c
index 45276ee98..c51ac811d 100644
--- a/tests/icles/gdkpixbufoverlay-test.c
+++ b/tests/icles/gdkpixbufoverlay-test.c
@@ -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,