{
GstStructure *str = gst_caps_get_structure (caps, 0);
const GValue *palette_v;
- const GstBuffer *palette;
+ GstBuffer *palette;
/* do we have a palette? */
if ((palette_v = gst_structure_get_value (str, "palette_data")) && context) {
palette = gst_value_get_buffer (palette_v);
- if (GST_BUFFER_SIZE (palette) >= AVPALETTE_SIZE) {
+ if (gst_buffer_get_size (palette) >= AVPALETTE_SIZE) {
if (context->palctrl)
av_free (context->palctrl);
context->palctrl = av_malloc (sizeof (AVPaletteControl));
context->palctrl->palette_changed = 1;
- memcpy (context->palctrl->palette, GST_BUFFER_DATA (palette),
+ gst_buffer_extract (palette, 0, context->palctrl->palette,
AVPALETTE_SIZE);
}
}
if (context->palctrl) {
GstBuffer *palette = gst_buffer_new_and_alloc (AVPALETTE_SIZE);
- memcpy (GST_BUFFER_DATA (palette), context->palctrl->palette,
- AVPALETTE_SIZE);
+ gst_buffer_fill (palette, 0, context->palctrl->palette, AVPALETTE_SIZE);
gst_caps_set_simple (caps, "palette_data", GST_TYPE_BUFFER, palette, NULL);
}
}
if (context && context->extradata_size > 0) {
GstBuffer *data = gst_buffer_new_and_alloc (context->extradata_size);
- memcpy (GST_BUFFER_DATA (data), context->extradata,
- context->extradata_size);
+ gst_buffer_fill (data, 0, context->extradata, context->extradata_size);
gst_caps_set_simple (caps, "codec_data", GST_TYPE_BUFFER, data, NULL);
gst_buffer_unref (data);
}
{
GstStructure *str;
const GValue *value;
- const GstBuffer *buf;
+ GstBuffer *buf;
GST_LOG ("codec_id:%d, codec_type:%d, caps:%" GST_PTR_FORMAT " context:%p",
codec_id, codec_type, caps, context);
/* extradata parsing (esds [mpeg4], wma/wmv, msmpeg4v1/2/3, etc.) */
if ((value = gst_structure_get_value (str, "codec_data"))) {
- guint size;
+ gsize size;
guint8 *data;
buf = gst_value_get_buffer (value);
- size = GST_BUFFER_SIZE (buf);
- data = GST_BUFFER_DATA (buf);
+ data = gst_buffer_map (buf, &size, NULL, GST_MAP_READ);
/* free the old one if it is there */
if (context->extradata)
}
GST_DEBUG ("have codec data of size %d", size);
+
+ gst_buffer_unmap (buf, data, size);
} else if (context->extradata == NULL) {
/* no extradata, alloc dummy with 0 sized, some codecs insist on reading
* extradata anyway which makes then segfault. */
ffmpegdec->discont = FALSE;
}
/* set caps */
- outbuf = gst_buffer_make_metadata_writable (outbuf);
+ outbuf = gst_buffer_make_writable (outbuf);
gst_buffer_set_caps (outbuf, GST_PAD_CAPS (ffmpegdec->srcpad));
if (ffmpegdec->segment.rate > 0.0) {
GstFFMpegDec *ffmpegdec;
GstFFMpegDecClass *oclass;
guint8 *data, *bdata, *pdata;
+ guint8 *odata;
+ gsize osize;
gint size, bsize, len, have_data;
GstFlowReturn ret = GST_FLOW_OK;
GstClockTime in_timestamp;
}
ffmpegdec->last_frames = 0;
- GST_LOG_OBJECT (ffmpegdec,
- "Received new data of size %u, offset:%" G_GUINT64_FORMAT ", ts:%"
- GST_TIME_FORMAT ", dur:%" GST_TIME_FORMAT ", info %d",
- GST_BUFFER_SIZE (inbuf), GST_BUFFER_OFFSET (inbuf),
- GST_TIME_ARGS (in_timestamp), GST_TIME_ARGS (in_duration), in_info->idx);
-
/* workarounds, functions write to buffers:
* libavcodec/svq1.c:svq1_decode_frame writes to the given buffer.
* libavcodec/svq3.c:svq3_decode_slice_header too.
inbuf = gst_buffer_make_writable (inbuf);
}
- bdata = GST_BUFFER_DATA (inbuf);
- bsize = GST_BUFFER_SIZE (inbuf);
+ odata = gst_buffer_map (inbuf, &osize, NULL, GST_MAP_READ);
+
+ bdata = odata;
+ bsize = osize;
+
+ GST_LOG_OBJECT (ffmpegdec,
+ "Received new data of size %u, offset:%" G_GUINT64_FORMAT ", ts:%"
+ GST_TIME_FORMAT ", dur:%" GST_TIME_FORMAT ", info %d",
+ bsize, in_offset, GST_TIME_ARGS (in_timestamp),
+ GST_TIME_ARGS (in_duration), in_info->idx);
do {
/* parse, if at all possible */
bsize, bdata);
} while (bsize > 0);
+ gst_buffer_unmap (inbuf, odata, osize);
+
/* keep left-over */
if (ffmpegdec->pctx && bsize > 0) {
in_timestamp = GST_BUFFER_TIMESTAMP (inbuf);
"Keeping %d bytes of data with offset %" G_GINT64_FORMAT ", timestamp %"
GST_TIME_FORMAT, bsize, in_offset, GST_TIME_ARGS (in_timestamp));
- ffmpegdec->pcache = gst_buffer_create_sub (inbuf,
- GST_BUFFER_SIZE (inbuf) - bsize, bsize);
+ ffmpegdec->pcache = gst_buffer_copy_region (inbuf, GST_BUFFER_COPY_ALL,
+ gst_buffer_get_size (inbuf) - bsize, bsize);
/* we keep timestamp, even though all we really know is that the correct
* timestamp is not below the one from inbuf */
GST_BUFFER_TIMESTAMP (ffmpegdec->pcache) = in_timestamp;
{
GstFFMpegEnc *ffmpegenc = (GstFFMpegEnc *) (GST_PAD_PARENT (pad));
GstBuffer *outbuf;
+ guint8 *data;
+ gsize size;
gint ret_size = 0, frame_size;
gboolean force_keyframe;
if (force_keyframe)
ffmpegenc->picture->pict_type = FF_I_TYPE;
+ data = gst_buffer_map (inbuf, &size, NULL, GST_MAP_READ);
frame_size = gst_ffmpeg_avpicture_fill ((AVPicture *) ffmpegenc->picture,
- GST_BUFFER_DATA (inbuf),
+ data,
ffmpegenc->context->pix_fmt,
ffmpegenc->context->width, ffmpegenc->context->height);
- g_return_val_if_fail (frame_size == GST_BUFFER_SIZE (inbuf), GST_FLOW_ERROR);
+ g_return_val_if_fail (frame_size == size, GST_FLOW_ERROR);
ffmpegenc->picture->pts =
gst_ffmpeg_time_gst_to_ff (GST_BUFFER_TIMESTAMP (inbuf) /
ret_size = avcodec_encode_video (ffmpegenc->context,
ffmpegenc->working_buf, ffmpegenc->working_buf_size, ffmpegenc->picture);
+ gst_buffer_unmap (inbuf, data, size);
+
if (ret_size < 0) {
#ifndef GST_DISABLE_GST_DEBUG
GstFFMpegEncClass *oclass =
GST_ERROR_SYSTEM);
outbuf = gst_buffer_new_and_alloc (ret_size);
- memcpy (GST_BUFFER_DATA (outbuf), ffmpegenc->working_buf, ret_size);
+ gst_buffer_fill (outbuf, 0, ffmpegenc->working_buf, ret_size);
GST_BUFFER_TIMESTAMP (outbuf) = GST_BUFFER_TIMESTAMP (inbuf);
GST_BUFFER_DURATION (outbuf) = GST_BUFFER_DURATION (inbuf);
/* buggy codec may not set coded_frame */
/* We need to provide at least ffmpegs minimal buffer size */
outbuf = gst_buffer_new_and_alloc (max_size + FF_MIN_BUFFER_SIZE);
- audio_out = GST_BUFFER_DATA (outbuf);
+ audio_out = gst_buffer_map (outbuf, NULL, NULL, GST_MAP_WRITE);
GST_LOG_OBJECT (ffmpegenc, "encoding buffer of max size %d", max_size);
if (ffmpegenc->buffer_size != max_size)
res = avcodec_encode_audio (ctx, audio_out, in_size, (short *) audio_in);
if (res < 0) {
+ gst_buffer_unmap (outbuf, audio_out, 0);
GST_ERROR_OBJECT (ffmpegenc, "Failed to encode buffer: %d", res);
gst_buffer_unref (outbuf);
return GST_FLOW_OK;
}
GST_LOG_OBJECT (ffmpegenc, "got output size %d", res);
- GST_BUFFER_SIZE (outbuf) = res;
+ gst_buffer_unmap (outbuf, audio_out, res);
GST_BUFFER_TIMESTAMP (outbuf) = timestamp;
GST_BUFFER_DURATION (outbuf) = duration;
if (discont)
GstFFMpegEncClass *oclass;
AVCodecContext *ctx;
GstClockTime timestamp, duration;
- guint size, frame_size;
+ gsize size, frame_size;
gint osize;
GstFlowReturn ret;
gint out_size;
ctx = ffmpegenc->context;
- size = GST_BUFFER_SIZE (inbuf);
+ size = gst_buffer_get_size (inbuf);
timestamp = GST_BUFFER_TIMESTAMP (inbuf);
duration = GST_BUFFER_DURATION (inbuf);
discont = GST_BUFFER_IS_DISCONT (inbuf);
* or samplesize to divide by the samplerate */
/* take an audio buffer out of the adapter */
- in_data = (guint8 *) gst_adapter_peek (ffmpegenc->adapter, frame_bytes);
+ in_data = (guint8 *) gst_adapter_map (ffmpegenc->adapter, frame_bytes);
ffmpegenc->adapter_consumed += frame_size;
/* calculate timestamp and duration relative to start of adapter and to
gst_ffmpegenc_encode_audio (ffmpegenc, in_data, frame_bytes, out_size,
timestamp, duration, ffmpegenc->discont);
- gst_adapter_flush (ffmpegenc->adapter, frame_bytes);
+ gst_adapter_unmap (ffmpegenc->adapter, frame_bytes);
if (ret != GST_FLOW_OK)
goto push_failed;
if (coded_bps)
out_size = (out_size * coded_bps) / 8;
- in_data = (guint8 *) GST_BUFFER_DATA (inbuf);
+ in_data = (guint8 *) gst_buffer_map (inbuf, &size, NULL, GST_MAP_READ);
ret = gst_ffmpegenc_encode_audio (ffmpegenc, in_data, size, out_size,
timestamp, duration, discont);
+ gst_buffer_unmap (inbuf, in_data, size);
gst_buffer_unref (inbuf);
if (ret != GST_FLOW_OK)
inbuf = g_queue_pop_head (ffmpegenc->delay);
outbuf = gst_buffer_new_and_alloc (ret_size);
- memcpy (GST_BUFFER_DATA (outbuf), ffmpegenc->working_buf, ret_size);
+ gst_buffer_fill (outbuf, 0, ffmpegenc->working_buf, ret_size);
GST_BUFFER_TIMESTAMP (outbuf) = GST_BUFFER_TIMESTAMP (inbuf);
GST_BUFFER_DURATION (outbuf) = GST_BUFFER_DURATION (inbuf);
switch (ret) {
case GST_FLOW_OK:
- total = (gint) GST_BUFFER_SIZE (inbuf);
- memcpy (buf, GST_BUFFER_DATA (inbuf), total);
+ total = (gint) gst_buffer_get_size (inbuf);
+ gst_buffer_extract (inbuf, 0, buf, total);
gst_buffer_unref (inbuf);
break;
case GST_FLOW_UNEXPECTED:
info->offset, size, GST_PAD_CAPS (info->pad), &outbuf) != GST_FLOW_OK)
return 0;
- memcpy (GST_BUFFER_DATA (outbuf), buf, size);
+ gst_buffer_fill (outbuf, 0, buf, size);
if (gst_pad_push (info->pad, outbuf) != GST_FLOW_OK)
return 0;
gst_ffmpeg_pipe_read (URLContext * h, unsigned char *buf, int size)
{
GstFFMpegPipe *ffpipe;
- const guint8 *data;
guint available;
ffpipe = (GstFFMpegPipe *) h->priv_data;
size = MIN (available, size);
if (size) {
GST_LOG ("Getting %d bytes", size);
- data = gst_adapter_peek (ffpipe->adapter, size);
- memcpy (buf, data, size);
+ gst_adapter_copy (ffpipe->adapter, buf, 0, size);
gst_adapter_flush (ffpipe->adapter, size);
GST_LOG ("%d bytes left in adapter",
gst_adapter_available (ffpipe->adapter));
GstBuffer *buf;
buf = gst_buffer_new ();
- GST_BUFFER_DATA (buf) = GST_BUFFER_MALLOCDATA (buf) = av_malloc (size);
- GST_BUFFER_SIZE (buf) = size;
- GST_BUFFER_FREE_FUNC (buf) = av_free;
+ gst_buffer_take_memory (buf,
+ gst_memory_new_wrapped (0, av_malloc (size), av_free, size, 0, size));
if (caps)
gst_buffer_set_caps (buf, caps);