diff --git a/ext/annodex/gstcmmldec.c b/ext/annodex/gstcmmldec.c index 050224ae5f..4a04be0832 100644 --- a/ext/annodex/gstcmmldec.c +++ b/ext/annodex/gstcmmldec.c @@ -358,10 +358,13 @@ gst_cmml_dec_chain (GstPad * pad, GstObject * parent, GstBuffer * buffer) { GstCmmlDec *dec = GST_CMML_DEC (parent); GstCmmlPacketType packet; + GstMapInfo map; guint8 *data; gsize size; - data = gst_buffer_map (buffer, &size, NULL, GST_MAP_READ); + gst_buffer_map (buffer, &map, GST_MAP_READ); + data = map.data; + size = map.size; if (size == 0) { /* the EOS page could be empty */ @@ -400,7 +403,7 @@ gst_cmml_dec_chain (GstPad * pad, GstObject * parent, GstBuffer * buffer) } done: - gst_buffer_unmap (buffer, data, size); + gst_buffer_unmap (buffer, &map); gst_buffer_unref (buffer); return dec->flow_return; diff --git a/ext/annodex/gstcmmlenc.c b/ext/annodex/gstcmmlenc.c index 57675581f2..3a466cd8a6 100644 --- a/ext/annodex/gstcmmlenc.c +++ b/ext/annodex/gstcmmlenc.c @@ -598,23 +598,23 @@ gst_cmml_enc_chain (GstPad * pad, GstObject * parent, GstBuffer * buffer) { GError *err = NULL; GstCmmlEnc *enc = GST_CMML_ENC (parent); - gchar *data; - gsize size; + GstMapInfo map; /* the CMML handlers registered with enc->parser will override this when * encoding/pushing the buffers downstream */ enc->flow_return = GST_FLOW_OK; - data = gst_buffer_map (buffer, &size, NULL, GST_MAP_READ); + gst_buffer_map (buffer, &map, GST_MAP_READ); - if (!gst_cmml_parser_parse_chunk (enc->parser, data, size, &err)) { + if (!gst_cmml_parser_parse_chunk (enc->parser, (gchar *) map.data, map.size, + &err)) { GST_ELEMENT_ERROR (enc, STREAM, ENCODE, (NULL), ("%s", err->message)); g_error_free (err); enc->flow_return = GST_FLOW_ERROR; } - gst_buffer_unmap (buffer, data, size); + gst_buffer_unmap (buffer, &map); gst_buffer_unref (buffer); return enc->flow_return; } diff --git a/ext/flac/gstflacdec.c b/ext/flac/gstflacdec.c index c71a7ec959..3cba558d74 100644 --- a/ext/flac/gstflacdec.c +++ b/ext/flac/gstflacdec.c @@ -536,8 +536,7 @@ gst_flac_dec_write (GstFlacDec * flacdec, const FLAC__Frame * frame, guint channels = frame->header.channels; guint samples = frame->header.blocksize; guint j, i; - gpointer data; - gsize size; + GstMapInfo map; gboolean caps_changed; GST_LOG_OBJECT (flacdec, "samples in frame header: %d", samples); @@ -618,9 +617,9 @@ gst_flac_dec_write (GstFlacDec * flacdec, const FLAC__Frame * frame, GST_LOG_OBJECT (flacdec, "alloc_buffer_and_set_caps"); outbuf = gst_buffer_new_allocate (NULL, samples * channels * (width / 8), 0); - data = gst_buffer_map (outbuf, &size, NULL, GST_MAP_WRITE); + gst_buffer_map (outbuf, &map, GST_MAP_WRITE); if (width == 8) { - gint8 *outbuffer = (gint8 *) data; + gint8 *outbuffer = (gint8 *) map.data; gint *reorder_map = flacdec->channel_reorder_map; if (width != depth) { @@ -637,7 +636,7 @@ gst_flac_dec_write (GstFlacDec * flacdec, const FLAC__Frame * frame, } } } else if (width == 16) { - gint16 *outbuffer = (gint16 *) data; + gint16 *outbuffer = (gint16 *) map.data; gint *reorder_map = flacdec->channel_reorder_map; if (width != depth) { @@ -655,7 +654,7 @@ gst_flac_dec_write (GstFlacDec * flacdec, const FLAC__Frame * frame, } } } else if (width == 32) { - gint32 *outbuffer = (gint32 *) data; + gint32 *outbuffer = (gint32 *) map.data; gint *reorder_map = flacdec->channel_reorder_map; if (width != depth) { @@ -675,7 +674,7 @@ gst_flac_dec_write (GstFlacDec * flacdec, const FLAC__Frame * frame, } else { g_assert_not_reached (); } - gst_buffer_unmap (outbuf, data, size); + gst_buffer_unmap (outbuf, &map); GST_DEBUG_OBJECT (flacdec, "pushing %d samples", samples); @@ -743,17 +742,17 @@ gst_flac_dec_handle_frame (GstAudioDecoder * audio_dec, GstBuffer * buf) if (G_UNLIKELY (!dec->got_headers)) { gboolean got_audio_frame; gint64 unused; - guint8 *data; - gsize size; + GstMapInfo map; /* check if this is a flac audio frame (rather than a header or junk) */ - data = gst_buffer_map (buf, &size, NULL, GST_MAP_READ); - got_audio_frame = gst_flac_dec_scan_got_frame (dec, data, size, &unused); - gst_buffer_unmap (buf, data, size); + gst_buffer_map (buf, &map, GST_MAP_READ); + got_audio_frame = + gst_flac_dec_scan_got_frame (dec, map.data, map.size, &unused); + gst_buffer_unmap (buf, &map); if (!got_audio_frame) { GST_INFO_OBJECT (dec, "dropping in-stream header, %" G_GSIZE_FORMAT " " - "bytes", size); + "bytes", map.size); gst_audio_decoder_finish_frame (audio_dec, NULL, 1); return GST_FLOW_OK; } diff --git a/ext/flac/gstflacenc.c b/ext/flac/gstflacenc.c index ad876c2b0f..e08284de52 100644 --- a/ext/flac/gstflacenc.c +++ b/ext/flac/gstflacenc.c @@ -516,8 +516,7 @@ gst_flac_enc_set_metadata (GstFlacEnc * flacenc, guint64 total_samples) GstTagImageType image_type = GST_TAG_IMAGE_TYPE_NONE; #endif gint i; - guint8 *data; - gsize size; + GstMapInfo map; for (i = 0; i < n_images + n_preview_images; i++) { if (i < n_images) { @@ -545,10 +544,10 @@ gst_flac_enc_set_metadata (GstFlacEnc * flacenc, guint64 total_samples) image_type = image_type + 2; #endif - data = gst_buffer_map (buffer, &size, NULL, GST_MAP_READ); + gst_buffer_map (buffer, &map, GST_MAP_READ); FLAC__metadata_object_picture_set_data (flacenc->meta[entries], - data, size, TRUE); - gst_buffer_unmap (buffer, data, size); + map.data, map.size, TRUE); + gst_buffer_unmap (buffer, &map); #if 0 /* FIXME: There's no way to set the picture type in libFLAC */ @@ -915,6 +914,7 @@ gst_flac_enc_process_stream_headers (GstFlacEnc * enc) for (l = enc->headers; l != NULL; l = l->next) { GstBuffer *buf; + GstMapInfo map; guint8 *data; gsize size; @@ -925,7 +925,9 @@ gst_flac_enc_process_stream_headers (GstFlacEnc * enc) buf = GST_BUFFER_CAST (l->data); GST_BUFFER_FLAG_SET (buf, GST_BUFFER_FLAG_IN_CAPS); - data = gst_buffer_map (buf, &size, NULL, GST_MAP_READ); + gst_buffer_map (buf, &map, GST_MAP_READ); + data = map.data; + size = map.size; /* find initial 4-byte marker which we need to skip later on */ if (size == 4 && memcmp (data, "fLaC", 4) == 0) { @@ -936,7 +938,7 @@ gst_flac_enc_process_stream_headers (GstFlacEnc * enc) vorbiscomment = buf; } - gst_buffer_unmap (buf, data, size); + gst_buffer_unmap (buf, &map); } if (marker == NULL || streaminfo == NULL || vorbiscomment == NULL) { @@ -951,8 +953,9 @@ gst_flac_enc_process_stream_headers (GstFlacEnc * enc) { GstBuffer *buf; guint16 num; + GstMapInfo map; guint8 *bdata; - gsize bsize, slen; + gsize slen; /* minus one for the marker that is merged with streaminfo here */ num = g_list_length (enc->headers) - 1; @@ -960,7 +963,8 @@ gst_flac_enc_process_stream_headers (GstFlacEnc * enc) slen = gst_buffer_get_size (streaminfo); buf = gst_buffer_new_and_alloc (13 + slen); - bdata = gst_buffer_map (buf, &bsize, NULL, GST_MAP_WRITE); + gst_buffer_map (buf, &map, GST_MAP_WRITE); + bdata = map.data; bdata[0] = 0x7f; memcpy (bdata + 1, "FLAC", 4); bdata[5] = 0x01; /* mapping version major */ @@ -969,7 +973,7 @@ gst_flac_enc_process_stream_headers (GstFlacEnc * enc) bdata[8] = (num & 0x00FF) >> 0; memcpy (bdata + 9, "fLaC", 4); gst_buffer_extract (streaminfo, 0, bdata + 13, slen); - gst_buffer_unmap (buf, bdata, bsize); + gst_buffer_unmap (buf, &map); notgst_value_array_append_buffer (&array, buf); gst_buffer_unref (buf); @@ -1169,12 +1173,11 @@ gst_flac_enc_handle_frame (GstAudioEncoder * enc, GstBuffer * buffer) { GstFlacEnc *flacenc; FLAC__int32 *data; - gsize bsize; gint samples, width, channels; gulong i; gint j; FLAC__bool res; - gpointer bdata; + GstMapInfo map; GstAudioInfo *info = gst_audio_encoder_get_audio_info (GST_AUDIO_ENCODER (enc)); gint *reorder_map; @@ -1202,28 +1205,28 @@ gst_flac_enc_handle_frame (GstAudioEncoder * enc, GstBuffer * buffer) return flacenc->last_flow; } - bdata = gst_buffer_map (buffer, &bsize, NULL, GST_MAP_READ); - samples = bsize / (width >> 3); + gst_buffer_map (buffer, &map, GST_MAP_READ); + samples = map.size / (width >> 3); data = g_malloc (samples * sizeof (FLAC__int32)); samples /= channels; if (width == 8) { - gint8 *indata = (gint8 *) bdata; + gint8 *indata = (gint8 *) map.data; for (i = 0; i < samples; i++) for (j = 0; j < channels; j++) data[i * channels + reorder_map[j]] = (FLAC__int32) indata[i * channels + j]; } else if (width == 16) { - gint16 *indata = (gint16 *) bdata; + gint16 *indata = (gint16 *) map.data; for (i = 0; i < samples; i++) for (j = 0; j < channels; j++) data[i * channels + reorder_map[j]] = (FLAC__int32) indata[i * channels + j]; } else if (width == 24) { - guint8 *indata = (guint8 *) bdata; + guint8 *indata = (guint8 *) map.data; guint32 val; for (i = 0; i < samples; i++) @@ -1234,7 +1237,7 @@ gst_flac_enc_handle_frame (GstAudioEncoder * enc, GstBuffer * buffer) data[i * channels + reorder_map[j]] = (FLAC__int32) val; } } else if (width == 32) { - gint32 *indata = (gint32 *) bdata; + gint32 *indata = (gint32 *) map.data; for (i = 0; i < samples; i++) for (j = 0; j < channels; j++) @@ -1243,7 +1246,7 @@ gst_flac_enc_handle_frame (GstAudioEncoder * enc, GstBuffer * buffer) } else { g_assert_not_reached (); } - gst_buffer_unmap (buffer, bdata, bsize); + gst_buffer_unmap (buffer, &map); res = FLAC__stream_encoder_process_interleaved (flacenc->encoder, (const FLAC__int32 *) data, samples / channels); diff --git a/ext/flac/gstflactag.c b/ext/flac/gstflactag.c index 4a1428e067..5c15bfd577 100644 --- a/ext/flac/gstflactag.c +++ b/ext/flac/gstflactag.c @@ -191,7 +191,7 @@ gst_flac_tag_chain (GstPad * pad, GstObject * parent, GstBuffer * buffer) { GstFlacTag *tag; GstFlowReturn ret; - guint8 *data; + GstMapInfo map; gsize size; ret = GST_FLOW_OK; @@ -284,9 +284,9 @@ gst_flac_tag_chain (GstPad * pad, GstObject * parent, GstBuffer * buffer) /* clear the is-last flag, as the last metadata block will * be the vorbis comment block which we will build ourselves. */ - data = gst_buffer_map (metadata_buffer, &size, NULL, GST_MAP_READWRITE); - data[0] &= (~0x80); - gst_buffer_unmap (metadata_buffer, data, size); + gst_buffer_map (metadata_buffer, &map, GST_MAP_READWRITE); + map.data[0] &= (~0x80); + gst_buffer_unmap (metadata_buffer, &map); if (tag->state == GST_FLAC_TAG_STATE_WRITING_METADATA_BLOCK) { GST_DEBUG_OBJECT (tag, "pushing metadata block buffer"); @@ -362,11 +362,11 @@ gst_flac_tag_chain (GstPad * pad, GstObject * parent, GstBuffer * buffer) if (buffer == NULL) goto no_buffer; - data = gst_buffer_map (buffer, &size, NULL, GST_MAP_WRITE); - memset (data, 0, size); - data[0] = 0x81; /* 0x80 = Last metadata block, + gst_buffer_map (buffer, &map, GST_MAP_WRITE); + memset (map.data, 0, map.size); + map.data[0] = 0x81; /* 0x80 = Last metadata block, * 0x01 = padding block */ - gst_buffer_unmap (buffer, data, size); + gst_buffer_unmap (buffer, &map); } else { guchar header[4]; guint8 fbit[1]; @@ -399,14 +399,14 @@ gst_flac_tag_chain (GstPad * pad, GstObject * parent, GstBuffer * buffer) /* The 4 byte metadata block header isn't accounted for in the total * size of the metadata block */ - data = gst_buffer_map (buffer, &size, NULL, GST_MAP_WRITE); - data[1] = (((size - 4) & 0xFF0000) >> 16); - data[2] = (((size - 4) & 0x00FF00) >> 8); - data[3] = ((size - 4) & 0x0000FF); - gst_buffer_unmap (buffer, data, size); + gst_buffer_map (buffer, &map, GST_MAP_WRITE); + map.data[1] = (((map.size - 4) & 0xFF0000) >> 16); + map.data[2] = (((map.size - 4) & 0x00FF00) >> 8); + map.data[3] = ((map.size - 4) & 0x0000FF); + gst_buffer_unmap (buffer, &map); GST_DEBUG_OBJECT (tag, "pushing %" G_GSIZE_FORMAT " byte vorbiscomment " - "buffer", size); + "buffer", map.size); ret = gst_pad_push (tag->srcpad, buffer); if (ret != GST_FLOW_OK) { diff --git a/ext/jpeg/gstjpegenc.c b/ext/jpeg/gstjpegenc.c index 305780287a..bb0767f0e8 100644 --- a/ext/jpeg/gstjpegenc.c +++ b/ext/jpeg/gstjpegenc.c @@ -159,10 +159,11 @@ static void ensure_memory (GstJpegEnc * jpegenc) { GstMemory *new_memory; + GstMapInfo map; gsize old_size, desired_size, new_size; guint8 *new_data; - old_size = jpegenc->output_size; + old_size = jpegenc->output_map.size; if (old_size == 0) desired_size = jpegenc->bufsize; else @@ -171,19 +172,20 @@ ensure_memory (GstJpegEnc * jpegenc) /* Our output memory wasn't big enough. * Make a new memory that's twice the size, */ new_memory = gst_allocator_alloc (NULL, desired_size, 3); - new_data = gst_memory_map (new_memory, &new_size, NULL, GST_MAP_READWRITE); + gst_memory_map (new_memory, &map, GST_MAP_READWRITE); + new_data = map.data; + new_size = map.size; /* copy previous data if any */ if (jpegenc->output_mem) { - memcpy (new_data, jpegenc->output_data, old_size); - gst_memory_unmap (jpegenc->output_mem); + memcpy (new_data, jpegenc->output_map.data, old_size); + gst_memory_unmap (jpegenc->output_mem, &jpegenc->output_map); gst_memory_unref (jpegenc->output_mem); } /* drop it into place, */ jpegenc->output_mem = new_memory; - jpegenc->output_data = new_data; - jpegenc->output_size = new_size; + jpegenc->output_map = map; /* and last, update libjpeg on where to work. */ jpegenc->jdest.next_output_byte = new_data + old_size; @@ -215,12 +217,12 @@ gst_jpegenc_term_destination (j_compress_ptr cinfo) GstJpegEnc *jpegenc = (GstJpegEnc *) (cinfo->client_data); GST_DEBUG_OBJECT (jpegenc, "gst_jpegenc_chain: term_source"); - gst_memory_unmap (jpegenc->output_mem); + gst_memory_unmap (jpegenc->output_mem, &jpegenc->output_map); /* Trim the buffer size. we will push it in the chain function */ gst_memory_resize (jpegenc->output_mem, 0, - jpegenc->output_size - jpegenc->jdest.free_in_buffer); - jpegenc->output_data = NULL; - jpegenc->output_size = 0; + jpegenc->output_map.size - jpegenc->jdest.free_in_buffer); + jpegenc->output_map.data = NULL; + jpegenc->output_map.size = 0; } static void @@ -566,12 +568,10 @@ gst_jpegenc_chain (GstPad * pad, GstObject * parent, GstBuffer * buf) } jpegenc->output_mem = gst_allocator_alloc (NULL, jpegenc->bufsize, 3); - jpegenc->output_data = - gst_memory_map (jpegenc->output_mem, &jpegenc->output_size, NULL, - GST_MAP_READWRITE); + gst_memory_map (jpegenc->output_mem, &jpegenc->output_map, GST_MAP_READWRITE); - jpegenc->jdest.next_output_byte = jpegenc->output_data; - jpegenc->jdest.free_in_buffer = jpegenc->output_size; + jpegenc->jdest.next_output_byte = jpegenc->output_map.data; + jpegenc->jdest.free_in_buffer = jpegenc->output_map.size; /* prepare for raw input */ #if JPEG_LIB_VERSION >= 70 diff --git a/ext/jpeg/gstjpegenc.h b/ext/jpeg/gstjpegenc.h index f677887d83..f684ff8da4 100644 --- a/ext/jpeg/gstjpegenc.h +++ b/ext/jpeg/gstjpegenc.h @@ -86,8 +86,7 @@ struct _GstJpegEnc GstFlowReturn last_ret; GstMemory *output_mem; - gpointer output_data; - gsize output_size; + GstMapInfo output_map; }; struct _GstJpegEncClass diff --git a/ext/pulse/pulsesink.c b/ext/pulse/pulsesink.c index 8699ccf0dc..4d1d5c8f34 100644 --- a/ext/pulse/pulsesink.c +++ b/ext/pulse/pulsesink.c @@ -1737,8 +1737,7 @@ gst_pulsesink_payload (GstAudioBaseSink * sink, GstBuffer * buf) /* FIXME: alloc memory from PA if possible */ gint framesize = gst_audio_iec61937_frame_size (&sink->ringbuffer->spec); GstBuffer *out; - guint8 *indata, *outdata; - gsize insize, outsize; + GstMapInfo inmap, outmap; gboolean res; if (framesize <= 0) @@ -1746,14 +1745,14 @@ gst_pulsesink_payload (GstAudioBaseSink * sink, GstBuffer * buf) out = gst_buffer_new_and_alloc (framesize); - indata = gst_buffer_map (buf, &insize, NULL, GST_MAP_READ); - outdata = gst_buffer_map (out, &outsize, NULL, GST_MAP_WRITE); + gst_buffer_map (buf, &inmap, GST_MAP_READ); + gst_buffer_map (out, &outmap, GST_MAP_WRITE); - res = gst_audio_iec61937_payload (indata, insize, - outdata, outsize, &sink->ringbuffer->spec); + res = gst_audio_iec61937_payload (inmap.data, inmap.size, + outmap.data, outmap.size, &sink->ringbuffer->spec); - gst_buffer_unmap (buf, indata, insize); - gst_buffer_unmap (out, outdata, outsize); + gst_buffer_unmap (buf, &inmap); + gst_buffer_unmap (out, &outmap); if (!res) { gst_buffer_unref (out); diff --git a/ext/soup/gstsouphttpclientsink.c b/ext/soup/gstsouphttpclientsink.c index 712cee56d2..c1ef3f464e 100644 --- a/ext/soup/gstsouphttpclientsink.c +++ b/ext/soup/gstsouphttpclientsink.c @@ -623,30 +623,28 @@ send_message_locked (GstSoupHttpClientSink * souphttpsink) if (souphttpsink->offset == 0) { for (g = souphttpsink->streamheader_buffers; g; g = g_list_next (g)) { GstBuffer *buffer = g->data; - gpointer data; - gsize size; + GstMapInfo map; /* FIXME, lifetime of the buffer? */ - data = gst_buffer_map (buffer, &size, NULL, GST_MAP_READ); + gst_buffer_map (buffer, &map, GST_MAP_READ); soup_message_body_append (souphttpsink->message->request_body, - SOUP_MEMORY_STATIC, data, size); - n += size; - gst_buffer_unmap (buffer, data, size); + SOUP_MEMORY_STATIC, map.data, map.size); + n += map.size; + gst_buffer_unmap (buffer, &map); } } for (g = souphttpsink->queued_buffers; g; g = g_list_next (g)) { GstBuffer *buffer = g->data; if (!GST_BUFFER_FLAG_IS_SET (buffer, GST_BUFFER_FLAG_IN_CAPS)) { - gpointer data; - gsize size; + GstMapInfo map; /* FIXME, lifetime of the buffer? */ - data = gst_buffer_map (buffer, &size, NULL, GST_MAP_READ); + gst_buffer_map (buffer, &map, GST_MAP_READ); soup_message_body_append (souphttpsink->message->request_body, - SOUP_MEMORY_STATIC, data, size); - n += size; - gst_buffer_unmap (buffer, data, size); + SOUP_MEMORY_STATIC, map.data, map.size); + n += map.size; + gst_buffer_unmap (buffer, &map); } } diff --git a/ext/soup/gstsouphttpsrc.c b/ext/soup/gstsouphttpsrc.c index 42723ee4b0..55f52fecda 100644 --- a/ext/soup/gstsouphttpsrc.c +++ b/ext/soup/gstsouphttpsrc.c @@ -876,7 +876,7 @@ gst_soup_http_src_finished_cb (SoupMessage * msg, GstSoupHTTPSrc * src) typedef struct { GstBuffer *buffer; - gpointer data; + GstMapInfo map; } SoupGstChunk; static void @@ -884,7 +884,7 @@ gst_soup_http_src_chunk_free (gpointer user_data) { SoupGstChunk *chunk = (SoupGstChunk *) user_data; - gst_buffer_unmap (chunk->buffer, chunk->data, -1); + gst_buffer_unmap (chunk->buffer, &chunk->map); gst_buffer_unref (chunk->buffer); g_slice_free (SoupGstChunk, chunk); } @@ -919,9 +919,9 @@ gst_soup_http_src_chunk_allocator (SoupMessage * msg, gsize max_len, chunk = g_slice_new0 (SoupGstChunk); chunk->buffer = gstbuf; - chunk->data = gst_buffer_map (gstbuf, &length, NULL, GST_MAP_READWRITE); + gst_buffer_map (gstbuf, &chunk->map, GST_MAP_READWRITE); - soupbuf = soup_buffer_new_with_owner (chunk->data, length, + soupbuf = soup_buffer_new_with_owner (chunk->map.data, chunk->map.size, chunk, gst_soup_http_src_chunk_free); return soupbuf; diff --git a/ext/speex/gstspeexdec.c b/ext/speex/gstspeexdec.c index 4ba4d285fd..6ec7d5ba94 100644 --- a/ext/speex/gstspeexdec.c +++ b/ext/speex/gstspeexdec.c @@ -190,13 +190,12 @@ static GstFlowReturn gst_speex_dec_parse_header (GstSpeexDec * dec, GstBuffer * buf) { GstCaps *caps; - char *data; - gsize size; + GstMapInfo map; /* get the header */ - data = gst_buffer_map (buf, &size, NULL, GST_MAP_READ); - dec->header = speex_packet_to_header (data, size); - gst_buffer_unmap (buf, data, size); + gst_buffer_map (buf, &map, GST_MAP_READ); + dec->header = speex_packet_to_header ((gchar *) map.data, map.size); + gst_buffer_unmap (buf, &map); if (!dec->header) goto no_header; @@ -368,23 +367,22 @@ gst_speex_dec_parse_data (GstSpeexDec * dec, GstBuffer * buf) GstFlowReturn res = GST_FLOW_OK; gint i, fpp; SpeexBits *bits; - gsize size; - char *data; + GstMapInfo map; if (!dec->frame_duration) goto not_negotiated; if (G_LIKELY (gst_buffer_get_size (buf))) { /* send data to the bitstream */ - data = gst_buffer_map (buf, &size, NULL, GST_MAP_READ); - speex_bits_read_from (&dec->bits, data, size); - gst_buffer_unmap (buf, data, size); + gst_buffer_map (buf, &map, GST_MAP_READ); + speex_bits_read_from (&dec->bits, (gchar *) map.data, map.size); + gst_buffer_unmap (buf, &map); fpp = dec->header->frames_per_packet; bits = &dec->bits; GST_DEBUG_OBJECT (dec, "received buffer of size %" G_GSIZE_FORMAT - ", fpp %d, %d bits", size, fpp, speex_bits_remaining (bits)); + ", fpp %d, %d bits", map.size, fpp, speex_bits_remaining (bits)); } else { /* FIXME ? actually consider how much concealment is needed */ /* concealment data, pass NULL as the bits parameters */ @@ -396,7 +394,6 @@ gst_speex_dec_parse_data (GstSpeexDec * dec, GstBuffer * buf) /* now decode each frame, catering for unknown number of them (e.g. rtp) */ for (i = 0; i < fpp; i++) { GstBuffer *outbuf; - gint16 *out_data; gint ret; GST_LOG_OBJECT (dec, "decoding frame %d/%d, %d bits remaining", i, fpp, @@ -418,9 +415,8 @@ gst_speex_dec_parse_data (GstSpeexDec * dec, GstBuffer * buf) gst_buffer_new_allocate (NULL, dec->frame_size * dec->header->nb_channels * 2, 0); - out_data = gst_buffer_map (outbuf, &size, NULL, GST_MAP_WRITE); - ret = speex_decode_int (dec->state, bits, out_data); - gst_buffer_unmap (outbuf, out_data, size); + gst_buffer_map (outbuf, &map, GST_MAP_WRITE); + ret = speex_decode_int (dec->state, bits, (spx_int16_t *) map.data); if (ret == -1) { /* uh? end of stream */ @@ -445,7 +441,10 @@ gst_speex_dec_parse_data (GstSpeexDec * dec, GstBuffer * buf) gst_buffer_unref (outbuf); } if (dec->header->nb_channels == 2) - speex_decode_stereo_int (out_data, dec->frame_size, dec->stereo); + speex_decode_stereo_int ((spx_int16_t *) map.data, dec->frame_size, + dec->stereo); + + gst_buffer_unmap (outbuf, &map); res = gst_audio_decoder_finish_frame (GST_AUDIO_DECODER (dec), outbuf, 1); @@ -469,8 +468,8 @@ not_negotiated: static gboolean memcmp_buffers (GstBuffer * buf1, GstBuffer * buf2) { + GstMapInfo map; gsize size1, size2; - gpointer data1; gboolean res; size1 = gst_buffer_get_size (buf1); @@ -479,9 +478,9 @@ memcmp_buffers (GstBuffer * buf1, GstBuffer * buf2) if (size1 != size2) return FALSE; - data1 = gst_buffer_map (buf1, NULL, NULL, GST_MAP_READ); - res = gst_buffer_memcmp (buf2, 0, data1, size1) == 0; - gst_buffer_unmap (buf1, data1, size1); + gst_buffer_map (buf1, &map, GST_MAP_READ); + res = gst_buffer_memcmp (buf2, 0, map.data, map.size) == 0; + gst_buffer_unmap (buf1, &map); return res; } diff --git a/ext/speex/gstspeexenc.c b/ext/speex/gstspeexenc.c index 3bf2bbc5e3..ebcc686a9f 100644 --- a/ext/speex/gstspeexenc.c +++ b/ext/speex/gstspeexenc.c @@ -539,13 +539,16 @@ gst_speex_enc_encode (GstSpeexEnc * enc, GstBuffer * buf) gint frame_size = enc->frame_size; gint bytes = frame_size * 2 * enc->channels, samples; gint outsize, written, dtx_ret = 0; - guint8 *data, *data0 = NULL, *bdata, *outdata; + GstMapInfo map; + guint8 *data, *data0 = NULL, *bdata; gsize bsize, size; GstBuffer *outbuf; GstFlowReturn ret = GST_FLOW_OK; if (G_LIKELY (buf)) { - bdata = gst_buffer_map (buf, &bsize, NULL, GST_MAP_READ); + gst_buffer_map (buf, &map, GST_MAP_READ); + bdata = map.data; + bsize = map.size; if (G_UNLIKELY (bsize % bytes)) { GST_DEBUG_OBJECT (enc, "draining; adding silence samples"); @@ -553,7 +556,7 @@ gst_speex_enc_encode (GstSpeexEnc * enc, GstBuffer * buf) size = ((bsize / bytes) + 1) * bytes; data0 = data = g_malloc0 (size); memcpy (data, bdata, bsize); - gst_buffer_unmap (buf, bdata, bsize); + gst_buffer_unmap (buf, &map); bdata = NULL; } else { data = bdata; @@ -585,7 +588,7 @@ gst_speex_enc_encode (GstSpeexEnc * enc, GstBuffer * buf) outsize = speex_bits_nbytes (&enc->bits); if (bdata) - gst_buffer_unmap (buf, bdata, bsize); + gst_buffer_unmap (buf, &map); #if 0 ret = gst_pad_alloc_buffer_and_set_caps (GST_AUDIO_ENCODER_SRC_PAD (enc), @@ -596,9 +599,9 @@ gst_speex_enc_encode (GstSpeexEnc * enc, GstBuffer * buf) goto done; #endif outbuf = gst_buffer_new_allocate (NULL, outsize, 0); - outdata = gst_buffer_map (outbuf, NULL, NULL, GST_MAP_WRITE); + gst_buffer_map (outbuf, &map, GST_MAP_WRITE); - written = speex_bits_write (&enc->bits, (gchar *) outdata, outsize); + written = speex_bits_write (&enc->bits, (gchar *) map.data, outsize); if (G_UNLIKELY (written < outsize)) { GST_ERROR_OBJECT (enc, "short write: %d < %d bytes", written, outsize); @@ -606,7 +609,8 @@ gst_speex_enc_encode (GstSpeexEnc * enc, GstBuffer * buf) GST_ERROR_OBJECT (enc, "overrun: %d > %d bytes", written, outsize); written = outsize; } - gst_buffer_unmap (outbuf, outdata, written); + gst_buffer_unmap (outbuf, &map); + gst_buffer_resize (outbuf, 0, written); if (!dtx_ret) GST_BUFFER_FLAG_SET (outbuf, GST_BUFFER_FLAG_GAP); diff --git a/gst/rtp/gstrtpvorbisdepay.c b/gst/rtp/gstrtpvorbisdepay.c index ccd4b3e0bb..d2017acb15 100644 --- a/gst/rtp/gstrtpvorbisdepay.c +++ b/gst/rtp/gstrtpvorbisdepay.c @@ -152,12 +152,15 @@ gst_rtp_vorbis_depay_parse_configuration (GstRtpVorbisDepay * rtpvorbisdepay, { GstBuffer *buf; guint32 num_headers; - guint8 *data, *bdata; + GstMapInfo map; + guint8 *data; gsize size; guint offset; gint i, j; - bdata = data = gst_buffer_map (confbuf, &size, NULL, GST_MAP_READ); + gst_buffer_map (confbuf, &map, GST_MAP_READ); + data = map.data; + size = map.size; GST_DEBUG_OBJECT (rtpvorbisdepay, "config size %" G_GSIZE_FORMAT, size); @@ -295,7 +298,7 @@ gst_rtp_vorbis_depay_parse_configuration (GstRtpVorbisDepay * rtpvorbisdepay, rtpvorbisdepay->configs = g_list_append (rtpvorbisdepay->configs, conf); } - gst_buffer_unmap (confbuf, bdata, -1); + gst_buffer_unmap (confbuf, &map); gst_buffer_unref (confbuf); return TRUE; @@ -304,7 +307,7 @@ gst_rtp_vorbis_depay_parse_configuration (GstRtpVorbisDepay * rtpvorbisdepay, too_small: { GST_DEBUG_OBJECT (rtpvorbisdepay, "configuration too small"); - gst_buffer_unmap (confbuf, bdata, -1); + gst_buffer_unmap (confbuf, &map); gst_buffer_unref (confbuf); return FALSE; } @@ -316,23 +319,23 @@ gst_rtp_vorbis_depay_parse_inband_configuration (GstRtpVorbisDepay * guint length) { GstBuffer *confbuf; - guint8 *conf; + GstMapInfo map; if (G_UNLIKELY (size < 4)) return FALSE; /* transform inline to out-of-band and parse that one */ confbuf = gst_buffer_new_and_alloc (size + 9); - conf = gst_buffer_map (confbuf, NULL, NULL, -1); + gst_buffer_map (confbuf, &map, GST_MAP_WRITE); /* 1 header */ - GST_WRITE_UINT32_BE (conf, 1); + GST_WRITE_UINT32_BE (map.data, 1); /* write Ident */ - GST_WRITE_UINT24_BE (conf + 4, ident); + GST_WRITE_UINT24_BE (map.data + 4, ident); /* write sort-of-length */ - GST_WRITE_UINT16_BE (conf + 7, length); + GST_WRITE_UINT16_BE (map.data + 7, length); /* copy remainder */ - memcpy (conf + 9, configuration, size); - gst_buffer_unmap (confbuf, conf, -1); + memcpy (map.data + 9, configuration, size); + gst_buffer_unmap (confbuf, &map); return gst_rtp_vorbis_depay_parse_configuration (rtpvorbisdepay, confbuf); } @@ -595,12 +598,8 @@ gst_rtp_vorbis_depay_process (GstRTPBaseDepayload * depayload, GstBuffer * buf) (payload - to_free) + length, payload - to_free, length)); to_free = NULL; } else { - guint8 *data; - outbuf = gst_buffer_new_and_alloc (length); - data = gst_buffer_map (outbuf, NULL, NULL, GST_MAP_WRITE); - memcpy (data, payload, length); - gst_buffer_unmap (outbuf, data, -1); + gst_buffer_fill (outbuf, 0, payload, length); } payload += length; diff --git a/gst/rtp/gstrtpvorbispay.c b/gst/rtp/gstrtpvorbispay.c index 75b961e6b9..c9c9028c74 100644 --- a/gst/rtp/gstrtpvorbispay.c +++ b/gst/rtp/gstrtpvorbispay.c @@ -291,10 +291,10 @@ gst_rtp_vorbis_pay_finish_headers (GstRTPBasePayload * basepayload) ident = fnv1_hash_32_new (); for (walk = rtpvorbispay->headers; walk; walk = g_list_next (walk)) { GstBuffer *buf = GST_BUFFER_CAST (walk->data); - guint bsize, osize; - guint8 *data; + GstMapInfo map; + guint bsize; - bsize = osize = gst_buffer_get_size (buf); + bsize = gst_buffer_get_size (buf); length += bsize; n_headers++; @@ -307,9 +307,9 @@ gst_rtp_vorbis_pay_finish_headers (GstRTPBasePayload * basepayload) } while (bsize); } /* update hash */ - data = gst_buffer_map (buf, NULL, NULL, GST_MAP_READ); - ident = fnv1_hash_32_update (ident, data, osize); - gst_buffer_unmap (buf, data, -1); + gst_buffer_map (buf, &map, GST_MAP_READ); + ident = fnv1_hash_32_update (ident, map.data, map.size); + gst_buffer_unmap (buf, &map); } /* packet length is header size + packet length */ @@ -475,6 +475,7 @@ gst_rtp_vorbis_pay_handle_buffer (GstRTPBasePayload * basepayload, GstRtpVorbisPay *rtpvorbispay; GstFlowReturn ret; guint newsize; + GstMapInfo map; gsize size; guint8 *data; guint packet_len; @@ -488,7 +489,9 @@ gst_rtp_vorbis_pay_handle_buffer (GstRTPBasePayload * basepayload, rtpvorbispay = GST_RTP_VORBIS_PAY (basepayload); - data = gst_buffer_map (buffer, &size, NULL, GST_MAP_READ); + gst_buffer_map (buffer, &map, GST_MAP_READ); + data = map.data; + size = map.size; duration = GST_BUFFER_DURATION (buffer); timestamp = GST_BUFFER_TIMESTAMP (buffer); @@ -523,7 +526,7 @@ gst_rtp_vorbis_pay_handle_buffer (GstRTPBasePayload * basepayload, if (VDT != 0) { GST_DEBUG_OBJECT (rtpvorbispay, "collecting header"); /* append header to the list of headers */ - gst_buffer_unmap (buffer, data, -1); + gst_buffer_unmap (buffer, &map); rtpvorbispay->headers = g_list_append (rtpvorbispay->headers, buffer); ret = GST_FLOW_OK; goto done; @@ -623,7 +626,7 @@ gst_rtp_vorbis_pay_handle_buffer (GstRTPBasePayload * basepayload, if (rtp.buffer) gst_rtp_buffer_unmap (&rtp); - gst_buffer_unmap (buffer, data, -1); + gst_buffer_unmap (buffer, &map); gst_buffer_unref (buffer); done: @@ -635,13 +638,13 @@ wrong_size: GST_ELEMENT_WARNING (rtpvorbispay, STREAM, DECODE, ("Invalid packet size (1 < %" G_GSIZE_FORMAT " <= 0xffff)", size), (NULL)); - gst_buffer_unmap (buffer, data, -1); + gst_buffer_unmap (buffer, &map); gst_buffer_unref (buffer); return GST_FLOW_OK; } parse_id_failed: { - gst_buffer_unmap (buffer, data, -1); + gst_buffer_unmap (buffer, &map); gst_buffer_unref (buffer); return GST_FLOW_ERROR; } @@ -649,7 +652,7 @@ unknown_header: { GST_ELEMENT_WARNING (rtpvorbispay, STREAM, DECODE, (NULL), ("Ignoring unknown header received")); - gst_buffer_unmap (buffer, data, -1); + gst_buffer_unmap (buffer, &map); gst_buffer_unref (buffer); return GST_FLOW_OK; } @@ -657,7 +660,7 @@ header_error: { GST_ELEMENT_WARNING (rtpvorbispay, STREAM, DECODE, (NULL), ("Error initializing header config")); - gst_buffer_unmap (buffer, data, -1); + gst_buffer_unmap (buffer, &map); gst_buffer_unref (buffer); return GST_FLOW_OK; } diff --git a/gst/rtpmanager/rtpsession.c b/gst/rtpmanager/rtpsession.c index 4846d92109..994601b129 100644 --- a/gst/rtpmanager/rtpsession.c +++ b/gst/rtpmanager/rtpsession.c @@ -2233,7 +2233,8 @@ rtp_session_process_feedback (RTPSession * sess, GstRTCPPacket * packet, if (fci_length > 0) { fci_buffer = gst_buffer_copy_region (packet->rtcp->buffer, - GST_BUFFER_COPY_MEMORY, fci_data - packet->rtcp->data, fci_length); + GST_BUFFER_COPY_MEMORY, fci_data - packet->rtcp->map.data, + fci_length); GST_BUFFER_TIMESTAMP (fci_buffer) = arrival->running_time; } diff --git a/gst/rtsp/gstrtspsrc.c b/gst/rtsp/gstrtspsrc.c index 4f29a06ca1..9a4df408c6 100644 --- a/gst/rtsp/gstrtspsrc.c +++ b/gst/rtsp/gstrtspsrc.c @@ -2095,9 +2095,9 @@ gst_rtspsrc_sink_chain (GstPad * pad, GstObject * parent, GstBuffer * buffer) GstRTSPSrc *src; GstRTSPStream *stream; GstFlowReturn res = GST_FLOW_OK; + GstMapInfo map; guint8 *data; guint size; - gsize bsize; GstRTSPResult ret; GstRTSPMessage message = { 0 }; GstRTSPConnection *conn; @@ -2105,8 +2105,9 @@ gst_rtspsrc_sink_chain (GstPad * pad, GstObject * parent, GstBuffer * buffer) stream = (GstRTSPStream *) gst_pad_get_element_private (pad); src = stream->parent; - data = gst_buffer_map (buffer, &bsize, NULL, GST_MAP_READ); - size = bsize; + gst_buffer_map (buffer, &map, GST_MAP_READ); + size = map.size; + data = map.data; gst_rtsp_message_init_data (&message, stream->channel[1]); @@ -2127,7 +2128,7 @@ gst_rtspsrc_sink_chain (GstPad * pad, GstObject * parent, GstBuffer * buffer) gst_rtsp_message_steal_body (&message, &data, &size); gst_rtsp_message_unset (&message); - gst_buffer_unmap (buffer, data, size); + gst_buffer_unmap (buffer, &map); gst_buffer_unref (buffer); return res; diff --git a/gst/spectrum/gstspectrum.c b/gst/spectrum/gstspectrum.c index aa281e7a79..fa6b29d57c 100644 --- a/gst/spectrum/gstspectrum.c +++ b/gst/spectrum/gstspectrum.c @@ -857,14 +857,17 @@ gst_spectrum_transform_ip (GstBaseTransform * trans, GstBuffer * buffer) guint nfft = 2 * bands - 2; guint input_pos; gfloat *input; - const guint8 *data, *mdata; + GstMapInfo map; + const guint8 *data; gsize size; guint fft_todo, msg_todo, block_size; gboolean have_full_interval; GstSpectrumChannel *cd; GstSpectrumInputData input_data; - data = mdata = gst_buffer_map (buffer, &size, NULL, GST_MAP_READ); + gst_buffer_map (buffer, &map, GST_MAP_READ); + data = map.data; + size = map.size; GST_LOG_OBJECT (spectrum, "input size: %" G_GSIZE_FORMAT " bytes", size); @@ -993,7 +996,7 @@ gst_spectrum_transform_ip (GstBaseTransform * trans, GstBuffer * buffer) spectrum->input_pos = input_pos; - gst_buffer_unmap (buffer, (guint8 *) mdata, -1); + gst_buffer_unmap (buffer, &map); g_assert (size == 0); diff --git a/gst/udp/gstdynudpsink.c b/gst/udp/gstdynudpsink.c index 255f2f5165..9f4d6881f0 100644 --- a/gst/udp/gstdynudpsink.c +++ b/gst/udp/gstdynudpsink.c @@ -167,8 +167,7 @@ gst_dynudpsink_render (GstBaseSink * bsink, GstBuffer * buffer) { GstDynUDPSink *sink; gssize ret; - gsize size; - guint8 *data; + GstMapInfo map; GstNetAddressMeta *meta; GSocketAddress *addr; GError *err = NULL; @@ -190,9 +189,9 @@ gst_dynudpsink_render (GstBaseSink * bsink, GstBuffer * buffer) if (sink->family != family && family != G_SOCKET_FAMILY_IPV4) goto invalid_family; - data = gst_buffer_map (buffer, &size, NULL, GST_MAP_READ); + gst_buffer_map (buffer, &map, GST_MAP_READ); - GST_DEBUG ("about to send %" G_GSIZE_FORMAT " bytes", size); + GST_DEBUG ("about to send %" G_GSIZE_FORMAT " bytes", map.size); #ifndef GST_DISABLE_GST_DEBUG { @@ -201,16 +200,17 @@ gst_dynudpsink_render (GstBaseSink * bsink, GstBuffer * buffer) host = g_inet_address_to_string (g_inet_socket_address_get_address (G_INET_SOCKET_ADDRESS (addr))); - GST_DEBUG ("sending %" G_GSIZE_FORMAT " bytes to client %s port %d", size, - host, g_inet_socket_address_get_port (G_INET_SOCKET_ADDRESS (addr))); + GST_DEBUG ("sending %" G_GSIZE_FORMAT " bytes to client %s port %d", + map.size, host, + g_inet_socket_address_get_port (G_INET_SOCKET_ADDRESS (addr))); g_free (host); } #endif ret = - g_socket_send_to (sink->used_socket, addr, (gchar *) data, size, + g_socket_send_to (sink->used_socket, addr, (gchar *) map.data, map.size, sink->cancellable, &err); - gst_buffer_unmap (buffer, data, size); + gst_buffer_unmap (buffer, &map); if (ret < 0) goto send_error; diff --git a/gst/udp/gstmultiudpsink.c b/gst/udp/gstmultiudpsink.c index 8eef113ebc..f75e74d91a 100644 --- a/gst/udp/gstmultiudpsink.c +++ b/gst/udp/gstmultiudpsink.c @@ -440,9 +440,9 @@ gst_multiudpsink_render (GstBaseSink * bsink, GstBuffer * buffer) GstMultiUDPSink *sink; GList *clients; GOutputVector *vec; + GstMapInfo *map; guint n_mem, i; - gpointer bdata; - gsize bsize, size; + gsize size; GstMemory *mem; gint num, no_clients; GError *err = NULL; @@ -454,21 +454,22 @@ gst_multiudpsink_render (GstBaseSink * bsink, GstBuffer * buffer) goto no_data; vec = g_new (GOutputVector, n_mem); + map = g_new (GstMapInfo, n_mem); size = 0; for (i = 0; i < n_mem; i++) { mem = gst_buffer_peek_memory (buffer, i, GST_MAP_READ); - bdata = gst_memory_map (mem, &bsize, NULL, GST_MAP_READ); + gst_memory_map (mem, &map[i], GST_MAP_READ); - if (bsize > UDP_MAX_SIZE) { + if (map[i].size > UDP_MAX_SIZE) { GST_WARNING ("Attempting to send a UDP packet larger than maximum " - "size (%" G_GSIZE_FORMAT " > %d)", bsize, UDP_MAX_SIZE); + "size (%" G_GSIZE_FORMAT " > %d)", map[i].size, UDP_MAX_SIZE); } - vec[i].buffer = bdata; - vec[i].size = bsize; + vec[i].buffer = map[i].data; + vec[i].size = map[i].size; - size += bsize; + size += map[i].size; } sink->bytes_to_serve += size; @@ -509,11 +510,11 @@ gst_multiudpsink_render (GstBaseSink * bsink, GstBuffer * buffer) g_mutex_unlock (&sink->client_lock); /* unmap all memory again */ - for (i = 0; i < n_mem; i++) { - mem = gst_buffer_peek_memory (buffer, i, GST_MAP_READ); - gst_memory_unmap (mem); - } + for (i = 0; i < n_mem; i++) + gst_memory_unmap (map[i].memory, &map[i]); + g_free (vec); + g_free (map); GST_LOG_OBJECT (sink, "sent %d bytes to %d (of %d) clients", size, num, no_clients); diff --git a/gst/videocrop/gstvideocrop.c b/gst/videocrop/gstvideocrop.c index 1c199e0808..0e8750199c 100644 --- a/gst/videocrop/gstvideocrop.c +++ b/gst/videocrop/gstvideocrop.c @@ -308,18 +308,17 @@ static void gst_video_crop_transform_packed_complex (GstVideoCrop * vcrop, GstBuffer * inbuf, GstBuffer * outbuf) { + GstMapInfo in_map, out_map; guint8 *in_data, *out_data; - gpointer in_bufdata, out_bufdata; - gsize insize, outsize; guint i, dx; gint in_stride; gint out_stride; - in_bufdata = gst_buffer_map (inbuf, &insize, NULL, GST_MAP_READ); - out_bufdata = gst_buffer_map (outbuf, &outsize, NULL, GST_MAP_WRITE); + gst_buffer_map (inbuf, &in_map, GST_MAP_READ); + gst_buffer_map (outbuf, &out_map, GST_MAP_WRITE); - in_data = in_bufdata; - out_data = out_bufdata; + in_data = in_map.data; + out_data = out_map.data; in_stride = GST_VIDEO_INFO_PLANE_STRIDE (&vcrop->in.info, 0); out_stride = GST_VIDEO_INFO_PLANE_STRIDE (&vcrop->out.info, 0); @@ -358,25 +357,24 @@ gst_video_crop_transform_packed_complex (GstVideoCrop * vcrop, out_data += out_stride; } } - gst_buffer_unmap (inbuf, in_bufdata, insize); - gst_buffer_unmap (outbuf, out_bufdata, outsize); + gst_buffer_unmap (inbuf, &in_map); + gst_buffer_unmap (outbuf, &out_map); } static void gst_video_crop_transform_packed_simple (GstVideoCrop * vcrop, GstBuffer * inbuf, GstBuffer * outbuf) { + GstMapInfo in_map, out_map; guint8 *in_data, *out_data; - gpointer in_bufdata, out_bufdata; - gsize insize, outsize; guint i, dx; gint in_stride, out_stride; - in_bufdata = gst_buffer_map (inbuf, &insize, NULL, GST_MAP_READ); - out_bufdata = gst_buffer_map (outbuf, &outsize, NULL, GST_MAP_WRITE); + gst_buffer_map (inbuf, &in_map, GST_MAP_READ); + gst_buffer_map (outbuf, &out_map, GST_MAP_WRITE); - in_data = in_bufdata; - out_data = out_bufdata; + in_data = in_map.data; + out_data = out_map.data; in_stride = GST_VIDEO_INFO_PLANE_STRIDE (&vcrop->in.info, 0); out_stride = GST_VIDEO_INFO_PLANE_STRIDE (&vcrop->out.info, 0); @@ -393,26 +391,25 @@ gst_video_crop_transform_packed_simple (GstVideoCrop * vcrop, in_data += in_stride; out_data += out_stride; } - gst_buffer_unmap (inbuf, in_bufdata, insize); - gst_buffer_unmap (outbuf, out_bufdata, outsize); + gst_buffer_unmap (inbuf, &in_map); + gst_buffer_unmap (outbuf, &out_map); } static void gst_video_crop_transform_planar (GstVideoCrop * vcrop, GstBuffer * inbuf, GstBuffer * outbuf) { + GstMapInfo in_map, out_map; guint8 *y_out, *u_out, *v_out; guint8 *y_in, *u_in, *v_in; guint i, dx; - gpointer in_bufdata, out_bufdata; - gsize insize, outsize; - in_bufdata = gst_buffer_map (inbuf, &insize, NULL, GST_MAP_READ); - out_bufdata = gst_buffer_map (outbuf, &outsize, NULL, GST_MAP_WRITE); + gst_buffer_map (inbuf, &in_map, GST_MAP_READ); + gst_buffer_map (outbuf, &out_map, GST_MAP_WRITE); /* Y plane */ - y_in = in_bufdata; - y_out = out_bufdata; + y_in = in_map.data; + y_out = out_map.data; y_in += (vcrop->crop_top * GST_VIDEO_INFO_PLANE_STRIDE (&vcrop->in.info, @@ -427,9 +424,9 @@ gst_video_crop_transform_planar (GstVideoCrop * vcrop, GstBuffer * inbuf, /* U + V planes */ u_in = - (guint8 *) in_bufdata + GST_VIDEO_INFO_PLANE_OFFSET (&vcrop->in.info, 1); + (guint8 *) in_map.data + GST_VIDEO_INFO_PLANE_OFFSET (&vcrop->in.info, 1); u_out = - (guint8 *) out_bufdata + GST_VIDEO_INFO_PLANE_OFFSET (&vcrop->out.info, + (guint8 *) out_map.data + GST_VIDEO_INFO_PLANE_OFFSET (&vcrop->out.info, 1); u_in += @@ -437,9 +434,9 @@ gst_video_crop_transform_planar (GstVideoCrop * vcrop, GstBuffer * inbuf, u_in += vcrop->crop_left / 2; v_in = - (guint8 *) in_bufdata + GST_VIDEO_INFO_PLANE_OFFSET (&vcrop->in.info, 2); + (guint8 *) in_map.data + GST_VIDEO_INFO_PLANE_OFFSET (&vcrop->in.info, 2); v_out = - (guint8 *) out_bufdata + GST_VIDEO_INFO_PLANE_OFFSET (&vcrop->out.info, + (guint8 *) out_map.data + GST_VIDEO_INFO_PLANE_OFFSET (&vcrop->out.info, 2); v_in += @@ -458,8 +455,8 @@ gst_video_crop_transform_planar (GstVideoCrop * vcrop, GstBuffer * inbuf, v_out += GST_VIDEO_INFO_PLANE_STRIDE (&vcrop->out.info, 2); } - gst_buffer_unmap (inbuf, in_bufdata, insize); - gst_buffer_unmap (outbuf, out_bufdata, outsize); + gst_buffer_unmap (inbuf, &in_map); + gst_buffer_unmap (outbuf, &out_map); } static GstFlowReturn diff --git a/gst/wavenc/gstwavenc.c b/gst/wavenc/gstwavenc.c index c7cae6f87d..56c7eb9e26 100644 --- a/gst/wavenc/gstwavenc.c +++ b/gst/wavenc/gstwavenc.c @@ -169,10 +169,12 @@ gst_wavenc_create_header_buf (GstWavEnc * wavenc, guint audio_data_size) { struct wave_header wave; GstBuffer *buf; + GstMapInfo map; guint8 *header; buf = gst_buffer_new_and_alloc (WAV_HEADER_LEN); - header = gst_buffer_map (buf, NULL, NULL, GST_MAP_WRITE); + gst_buffer_map (buf, &map, GST_MAP_WRITE); + header = map.data; memset (header, 0, WAV_HEADER_LEN); wave.common.wChannels = wavenc->channels; @@ -209,7 +211,7 @@ gst_wavenc_create_header_buf (GstWavEnc * wavenc, guint audio_data_size) memcpy (header + 36, (char *) wave.data.id, 4); GST_WRITE_UINT32_LE (header + 40, wave.data.len); - gst_buffer_unmap (buf, header, -1); + gst_buffer_unmap (buf, &map); return buf; } diff --git a/gst/wavparse/gstwavparse.c b/gst/wavparse/gstwavparse.c index 9045ecd7cd..3930dab591 100644 --- a/gst/wavparse/gstwavparse.c +++ b/gst/wavparse/gstwavparse.c @@ -1283,16 +1283,16 @@ gst_wavparse_stream_headers (GstWavParse * wav) if (!gst_wavparse_peek_chunk_info (wav, &tag, &size)) goto exit; } else { - guint8 *data; + GstMapInfo map; if ((res = gst_pad_pull_range (wav->sinkpad, wav->offset, 8, &buf)) != GST_FLOW_OK) goto header_read_error; - data = gst_buffer_map (buf, NULL, NULL, -1); - tag = GST_READ_UINT32_LE (data); - size = GST_READ_UINT32_LE (data + 4); - gst_buffer_unmap (buf, data, -1); + gst_buffer_map (buf, &map, GST_MAP_READ); + tag = GST_READ_UINT32_LE (map.data); + size = GST_READ_UINT32_LE (map.data + 4); + gst_buffer_unmap (buf, &map); } GST_INFO_OBJECT (wav, @@ -1409,15 +1409,16 @@ gst_wavparse_stream_headers (GstWavParse * wav) tempo = acid->tempo; gst_adapter_unmap (wav->adapter); } else { + GstMapInfo map; gst_buffer_unref (buf); if ((res = gst_pad_pull_range (wav->sinkpad, wav->offset + 8, size, &buf)) != GST_FLOW_OK) goto header_read_error; - acid = (const gst_riff_acid *) gst_buffer_map (buf, NULL, NULL, - GST_MAP_READ); + gst_buffer_map (buf, &map, GST_MAP_READ); + acid = (const gst_riff_acid *) map.data; tempo = acid->tempo; - gst_buffer_unmap (buf, (guint8 *) acid, -1); + gst_buffer_unmap (buf, &map); } /* send data as tags */ if (!wav->tags) diff --git a/sys/v4l2/gstv4l2bufferpool.c b/sys/v4l2/gstv4l2bufferpool.c index d25d7ae691..f052aadb03 100644 --- a/sys/v4l2/gstv4l2bufferpool.c +++ b/sys/v4l2/gstv4l2bufferpool.c @@ -892,20 +892,20 @@ gst_v4l2_do_read (GstV4l2BufferPool * pool, GstBuffer * buf) GstFlowReturn res; GstV4l2Object *obj = pool->obj; gint amount; - gpointer data; + GstMapInfo map; gint toread; toread = obj->sizeimage; GST_LOG_OBJECT (pool, "reading %d bytes into buffer %p", toread, buf); - data = gst_buffer_map (buf, NULL, NULL, GST_MAP_WRITE); + gst_buffer_map (buf, &map, GST_MAP_WRITE); do { if ((res = gst_v4l2_object_poll (obj)) != GST_FLOW_OK) goto poll_error; - amount = v4l2_read (obj->video_fd, data, toread); + amount = v4l2_read (obj->video_fd, map.data, toread); if (amount == toread) { break; @@ -921,7 +921,8 @@ gst_v4l2_do_read (GstV4l2BufferPool * pool, GstBuffer * buf) } while (TRUE); GST_LOG_OBJECT (pool, "read %d bytes", amount); - gst_buffer_unmap (buf, data, amount); + gst_buffer_unmap (buf, &map); + gst_buffer_resize (buf, 0, amount); return GST_FLOW_OK; @@ -941,7 +942,8 @@ read_error: } cleanup: { - gst_buffer_unmap (buf, data, 0); + gst_buffer_unmap (buf, &map); + gst_buffer_resize (buf, 0, 0); return res; } } diff --git a/sys/v4l2/gstv4l2object.c b/sys/v4l2/gstv4l2object.c index 1f52bb6f4e..82600ad59e 100644 --- a/sys/v4l2/gstv4l2object.c +++ b/sys/v4l2/gstv4l2object.c @@ -2579,9 +2579,6 @@ gboolean gst_v4l2_object_copy (GstV4l2Object * v4l2object, GstBuffer * dest, GstBuffer * src) { - guint8 *data; - gsize size; - if (v4l2object->info.finfo) { GstVideoFrame src_frame, dest_frame; @@ -2602,10 +2599,12 @@ gst_v4l2_object_copy (GstV4l2Object * v4l2object, GstBuffer * dest, gst_video_frame_unmap (&src_frame); gst_video_frame_unmap (&dest_frame); } else { + GstMapInfo map; + GST_DEBUG_OBJECT (v4l2object->element, "copy raw bytes"); - data = gst_buffer_map (src, &size, NULL, GST_MAP_READ); - gst_buffer_fill (dest, 0, data, size); - gst_buffer_unmap (src, data, size); + gst_buffer_map (src, &map, GST_MAP_READ); + gst_buffer_fill (dest, 0, map.data, map.size); + gst_buffer_unmap (src, &map); } GST_CAT_LOG_OBJECT (GST_CAT_PERFORMANCE, v4l2object->element, "slow copy into buffer %p", dest); diff --git a/sys/ximage/gstximagesrc.c b/sys/ximage/gstximagesrc.c index 6ed75ce87d..774314f0a6 100644 --- a/sys/ximage/gstximagesrc.c +++ b/sys/ximage/gstximagesrc.c @@ -437,12 +437,11 @@ composite_pixel (GstXContext * xcontext, guchar * dest, guchar * src) static void copy_buffer (GstBuffer * dest, GstBuffer * src) { - guint8 *data; - gsize size; + GstMapInfo map; - data = gst_buffer_map (src, &size, NULL, GST_MAP_READ); - gst_buffer_fill (dest, 0, data, size); - gst_buffer_unmap (src, data, size); + gst_buffer_map (src, &map, GST_MAP_READ); + gst_buffer_fill (dest, 0, map.data, map.size); + gst_buffer_unmap (src, &map); } #endif diff --git a/tests/check/elements/parser.c b/tests/check/elements/parser.c index 7b47c033a8..c369278b9b 100644 --- a/tests/check/elements/parser.c +++ b/tests/check/elements/parser.c @@ -69,15 +69,14 @@ buffer_new (const unsigned char *buffer_data, guint size) gst_buffer_fill (buffer, 0, buffer_data, size); } else { guint i; - guint8 *data; - gsize wantsize = size; + GstMapInfo map; - data = gst_buffer_map (buffer, &wantsize, NULL, GST_MAP_WRITE); + gst_buffer_map (buffer, &map, GST_MAP_WRITE); /* Create a recognizable pattern (loop 0x00 -> 0xff) in the data block */ - for (i = 0; i < wantsize; i++) { - data[i] = i % 0x100; + for (i = 0; i < map.size; i++) { + map.data[i] = i % 0x100; } - gst_buffer_unmap (buffer, data, wantsize); + gst_buffer_unmap (buffer, &map); } /* gst_buffer_set_caps (buffer, GST_PAD_CAPS (srcpad)); */