Commit 4345d105 authored by Wim Taymans's avatar Wim Taymans

WIP: porting to 0.11

parent 739b439f
......@@ -42,17 +42,17 @@ gst_ffmpeg_get_palette (const GstCaps * caps, AVCodecContext * context)
{
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);
}
}
......@@ -64,8 +64,7 @@ gst_ffmpeg_set_palette (GstCaps * caps, AVCodecContext * context)
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);
}
}
......@@ -1623,8 +1622,7 @@ gst_ffmpeg_codecid_to_caps (enum CodecID codec_id,
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);
}
......@@ -2278,7 +2276,7 @@ gst_ffmpeg_caps_with_codecid (enum CodecID codec_id,
{
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);
......@@ -2290,12 +2288,11 @@ gst_ffmpeg_caps_with_codecid (enum CodecID codec_id,
/* 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)
......@@ -2336,6 +2333,8 @@ gst_ffmpeg_caps_with_codecid (enum CodecID codec_id,
}
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. */
......
......@@ -2240,7 +2240,7 @@ gst_ffmpegdec_frame (GstFFMpegDec * ffmpegdec,
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) {
......@@ -2451,6 +2451,8 @@ gst_ffmpegdec_chain (GstPad * pad, GstBuffer * inbuf)
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;
......@@ -2539,12 +2541,6 @@ gst_ffmpegdec_chain (GstPad * pad, GstBuffer * inbuf)
}
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.
......@@ -2554,8 +2550,16 @@ gst_ffmpegdec_chain (GstPad * pad, GstBuffer * inbuf)
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 */
......@@ -2691,6 +2695,8 @@ gst_ffmpegdec_chain (GstPad * pad, GstBuffer * inbuf)
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);
......@@ -2700,8 +2706,8 @@ gst_ffmpegdec_chain (GstPad * pad, GstBuffer * 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;
......
......@@ -757,6 +757,8 @@ gst_ffmpegenc_chain_video (GstPad * pad, GstBuffer * inbuf)
{
GstFFMpegEnc *ffmpegenc = (GstFFMpegEnc *) (GST_PAD_PARENT (pad));
GstBuffer *outbuf;
guint8 *data;
gsize size;
gint ret_size = 0, frame_size;
gboolean force_keyframe;
......@@ -772,11 +774,12 @@ gst_ffmpegenc_chain_video (GstPad * pad, GstBuffer * inbuf)
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) /
......@@ -787,6 +790,8 @@ gst_ffmpegenc_chain_video (GstPad * pad, GstBuffer * 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 =
......@@ -815,7 +820,7 @@ gst_ffmpegenc_chain_video (GstPad * pad, GstBuffer * inbuf)
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 */
......@@ -858,7 +863,7 @@ gst_ffmpegenc_encode_audio (GstFFMpegEnc * ffmpegenc, guint8 * audio_in,
/* 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)
......@@ -867,13 +872,14 @@ gst_ffmpegenc_encode_audio (GstFFMpegEnc * ffmpegenc, guint8 * audio_in,
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)
......@@ -895,7 +901,7 @@ gst_ffmpegenc_chain_audio (GstPad * pad, GstBuffer * inbuf)
GstFFMpegEncClass *oclass;
AVCodecContext *ctx;
GstClockTime timestamp, duration;
guint size, frame_size;
gsize size, frame_size;
gint osize;
GstFlowReturn ret;
gint out_size;
......@@ -907,7 +913,7 @@ gst_ffmpegenc_chain_audio (GstPad * pad, GstBuffer * inbuf)
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);
......@@ -996,7 +1002,7 @@ gst_ffmpegenc_chain_audio (GstPad * pad, GstBuffer * 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
......@@ -1013,7 +1019,7 @@ gst_ffmpegenc_chain_audio (GstPad * pad, GstBuffer * inbuf)
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;
......@@ -1036,9 +1042,10 @@ gst_ffmpegenc_chain_audio (GstPad * pad, GstBuffer * inbuf)
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)
......@@ -1096,7 +1103,7 @@ gst_ffmpegenc_flush_buffers (GstFFMpegEnc * ffmpegenc, gboolean send)
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);
......
......@@ -111,8 +111,8 @@ gst_ffmpegdata_peek (URLContext * h, unsigned char *buf, int size)
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:
......@@ -169,7 +169,7 @@ gst_ffmpegdata_write (URLContext * h, const unsigned char *buf, int size)
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;
......@@ -333,7 +333,6 @@ static int
gst_ffmpeg_pipe_read (URLContext * h, unsigned char *buf, int size)
{
GstFFMpegPipe *ffpipe;
const guint8 *data;
guint available;
ffpipe = (GstFFMpegPipe *) h->priv_data;
......@@ -355,8 +354,7 @@ gst_ffmpeg_pipe_read (URLContext * h, unsigned char *buf, int size)
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));
......
......@@ -435,9 +435,8 @@ new_aligned_buffer (gint size, GstCaps * caps)
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);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment