summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWim Taymans <wim.taymans@collabora.co.uk>2012-01-24 14:40:37 +0100
committerWim Taymans <wim.taymans@collabora.co.uk>2012-01-25 11:59:04 +0100
commitcf3d3fe00d36acf98b12bbdb5efacfca06eb82a2 (patch)
treed2dc2256e1ef8cb6e41c2e284be89e6e80b54115
parenta011fdbb954c0812dc45cadeff588398d3d37160 (diff)
ffmpeg: port to new memory API
-rw-r--r--ext/ffmpeg/gstffmpegcodecmap.c20
-rw-r--r--ext/ffmpeg/gstffmpegdec.c20
-rw-r--r--ext/ffmpeg/gstffmpegdeinterlace.c15
-rw-r--r--ext/ffmpeg/gstffmpegdemux.c9
-rw-r--r--ext/ffmpeg/gstffmpegenc.c30
-rw-r--r--ext/ffmpeg/gstffmpegmux.c16
6 files changed, 56 insertions, 54 deletions
diff --git a/ext/ffmpeg/gstffmpegcodecmap.c b/ext/ffmpeg/gstffmpegcodecmap.c
index ae2c712..a93b292 100644
--- a/ext/ffmpeg/gstffmpegcodecmap.c
+++ b/ext/ffmpeg/gstffmpegcodecmap.c
@@ -2203,11 +2203,10 @@ 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"))) {
- gsize size;
- guint8 *data;
+ GstMapInfo map;
buf = gst_value_get_buffer (value);
- data = gst_buffer_map (buf, &size, NULL, GST_MAP_READ);
+ gst_buffer_map (buf, &map, GST_MAP_READ);
/* free the old one if it is there */
if (context->extradata)
@@ -2237,19 +2236,20 @@ gst_ffmpeg_caps_with_codecid (enum CodecID codec_id,
/* allocate with enough padding */
GST_DEBUG ("copy codec_data");
context->extradata =
- av_mallocz (GST_ROUND_UP_16 (size + FF_INPUT_BUFFER_PADDING_SIZE));
- memcpy (context->extradata, data, size);
- context->extradata_size = size;
+ av_mallocz (GST_ROUND_UP_16 (map.size +
+ FF_INPUT_BUFFER_PADDING_SIZE));
+ memcpy (context->extradata, map.data, map.size);
+ context->extradata_size = map.size;
}
/* Hack for VC1. Sometimes the first (length) byte is 0 for some files */
- if (codec_id == CODEC_ID_VC1 && size > 0 && data[0] == 0) {
- context->extradata[0] = (guint8) size;
+ if (codec_id == CODEC_ID_VC1 && map.size > 0 && map.data[0] == 0) {
+ context->extradata[0] = (guint8) map.size;
}
- GST_DEBUG ("have codec data of size %d", size);
+ GST_DEBUG ("have codec data of size %d", map.size);
- gst_buffer_unmap (buf, data, size);
+ gst_buffer_unmap (buf, &map);
} else if (context->extradata == NULL && codec_id != CODEC_ID_AAC_LATM &&
codec_id != CODEC_ID_FLAC) {
/* no extradata, alloc dummy with 0 sized, some codecs insist on reading
diff --git a/ext/ffmpeg/gstffmpegdec.c b/ext/ffmpeg/gstffmpegdec.c
index cbcde22..2dd5217 100644
--- a/ext/ffmpeg/gstffmpegdec.c
+++ b/ext/ffmpeg/gstffmpegdec.c
@@ -2243,6 +2243,7 @@ gst_ffmpegdec_audio_frame (GstFFMpegDec * ffmpegdec,
gint len = -1;
gint have_data = AVCODEC_MAX_AUDIO_FRAME_SIZE;
GstClockTime out_timestamp, out_duration;
+ GstMapInfo map;
gint64 out_offset;
int16_t *odata;
AVPacket packet;
@@ -2255,7 +2256,8 @@ gst_ffmpegdec_audio_frame (GstFFMpegDec * ffmpegdec,
*outbuf = new_aligned_buffer (AVCODEC_MAX_AUDIO_FRAME_SIZE);
- odata = gst_buffer_map (*outbuf, NULL, NULL, GST_MAP_WRITE);
+ gst_buffer_map (*outbuf, &map, GST_MAP_WRITE);
+ odata = (int16_t *) map.data;
gst_avpacket_init (&packet, data, size);
len = avcodec_decode_audio3 (ffmpegdec->context, odata, &have_data, &packet);
@@ -2267,7 +2269,8 @@ gst_ffmpegdec_audio_frame (GstFFMpegDec * ffmpegdec,
GstAudioFormat fmt;
/* Buffer size */
- gst_buffer_unmap (*outbuf, odata, have_data);
+ gst_buffer_unmap (*outbuf, &map);
+ gst_buffer_resize (*outbuf, 0, have_data);
GST_DEBUG_OBJECT (ffmpegdec, "Creating output buffer");
if (!gst_ffmpegdec_audio_negotiate (ffmpegdec, FALSE)) {
@@ -2335,7 +2338,7 @@ gst_ffmpegdec_audio_frame (GstFFMpegDec * ffmpegdec,
ffmpegdec->format.audio.ffmpeg_layout,
ffmpegdec->format.audio.gst_layout);
} else {
- gst_buffer_unmap (*outbuf, odata, 0);
+ gst_buffer_unmap (*outbuf, &map);
gst_buffer_unref (*outbuf);
*outbuf = NULL;
}
@@ -2665,8 +2668,7 @@ gst_ffmpegdec_chain (GstPad * pad, GstObject * parent, GstBuffer * inbuf)
GstFFMpegDec *ffmpegdec;
GstFFMpegDecClass *oclass;
guint8 *data, *bdata;
- guint8 *odata;
- gsize osize;
+ GstMapInfo map;
gint size, bsize, len, have_data;
GstFlowReturn ret = GST_FLOW_OK;
GstClockTime in_timestamp;
@@ -2764,10 +2766,10 @@ gst_ffmpegdec_chain (GstPad * pad, GstObject * parent, GstBuffer * inbuf)
inbuf = gst_buffer_make_writable (inbuf);
}
- odata = gst_buffer_map (inbuf, &osize, NULL, GST_MAP_READ);
+ gst_buffer_map (inbuf, &map, GST_MAP_READ);
- bdata = odata;
- bsize = osize;
+ bdata = map.data;
+ bsize = map.size;
GST_LOG_OBJECT (ffmpegdec,
"Received new data of size %u, offset:%" G_GUINT64_FORMAT ", ts:%"
@@ -2917,7 +2919,7 @@ gst_ffmpegdec_chain (GstPad * pad, GstObject * parent, GstBuffer * inbuf)
bsize, bdata);
} while (bsize > 0);
- gst_buffer_unmap (inbuf, odata, osize);
+ gst_buffer_unmap (inbuf, &map);
/* keep left-over */
if (ffmpegdec->pctx && bsize > 0) {
diff --git a/ext/ffmpeg/gstffmpegdeinterlace.c b/ext/ffmpeg/gstffmpegdeinterlace.c
index c4f9fb6..238a92c 100644
--- a/ext/ffmpeg/gstffmpegdeinterlace.c
+++ b/ext/ffmpeg/gstffmpegdeinterlace.c
@@ -284,8 +284,7 @@ gst_ffmpegdeinterlace_chain (GstPad * pad, GstObject * parent,
GstFFMpegDeinterlace *deinterlace = GST_FFMPEGDEINTERLACE (parent);
GstBuffer *outbuf = NULL;
GstFlowReturn result;
- guint8 *from_data, *to_data;
- gsize from_size, to_size;
+ GstMapInfo from_map, to_map;
GST_OBJECT_LOCK (deinterlace);
if (deinterlace->reconfigure) {
@@ -311,18 +310,18 @@ gst_ffmpegdeinterlace_chain (GstPad * pad, GstObject * parent,
outbuf = gst_buffer_new_and_alloc (deinterlace->to_size);
- from_data = gst_buffer_map (inbuf, &from_size, NULL, GST_MAP_READ);
- gst_ffmpeg_avpicture_fill (&deinterlace->from_frame, from_data,
+ gst_buffer_map (inbuf, &from_map, GST_MAP_READ);
+ gst_ffmpeg_avpicture_fill (&deinterlace->from_frame, from_map.data,
deinterlace->pixfmt, deinterlace->width, deinterlace->height);
- to_data = gst_buffer_map (outbuf, &to_size, NULL, GST_MAP_WRITE);
- gst_ffmpeg_avpicture_fill (&deinterlace->to_frame, to_data,
+ gst_buffer_map (outbuf, &to_map, GST_MAP_WRITE);
+ gst_ffmpeg_avpicture_fill (&deinterlace->to_frame, to_map.data,
deinterlace->pixfmt, deinterlace->width, deinterlace->height);
avpicture_deinterlace (&deinterlace->to_frame, &deinterlace->from_frame,
deinterlace->pixfmt, deinterlace->width, deinterlace->height);
- gst_buffer_unmap (outbuf, to_data, to_size);
- gst_buffer_unmap (inbuf, from_data, from_size);
+ gst_buffer_unmap (outbuf, &to_map);
+ gst_buffer_unmap (inbuf, &from_map);
gst_buffer_copy_into (outbuf, inbuf, GST_BUFFER_COPY_TIMESTAMPS, 0, -1);
diff --git a/ext/ffmpeg/gstffmpegdemux.c b/ext/ffmpeg/gstffmpegdemux.c
index 5c8bb34..9caf27b 100644
--- a/ext/ffmpeg/gstffmpegdemux.c
+++ b/ext/ffmpeg/gstffmpegdemux.c
@@ -1393,8 +1393,7 @@ gst_ffmpegdemux_loop (GstFFMpegDemux * demux)
AVPicture src, dst;
const gchar *plugin_name =
((GstFFMpegDemuxClass *) (G_OBJECT_GET_CLASS (demux)))->in_plugin->name;
- guint8 *data;
- gsize size;
+ GstMapInfo map;
if (strcmp (plugin_name, "gif") == 0) {
src.data[0] = pkt.data;
@@ -1408,14 +1407,14 @@ gst_ffmpegdemux_loop (GstFFMpegDemux * demux)
avstream->codec->height);
}
- data = gst_buffer_map (outbuf, &size, NULL, GST_MAP_WRITE);
- gst_ffmpeg_avpicture_fill (&dst, data,
+ gst_buffer_map (outbuf, &map, GST_MAP_WRITE);
+ gst_ffmpeg_avpicture_fill (&dst, map.data,
avstream->codec->pix_fmt, avstream->codec->width,
avstream->codec->height);
av_picture_copy (&dst, &src, avstream->codec->pix_fmt,
avstream->codec->width, avstream->codec->height);
- gst_buffer_unmap (outbuf, data, size);
+ gst_buffer_unmap (outbuf, &map);
} else {
gst_buffer_fill (outbuf, 0, pkt.data, outsize);
}
diff --git a/ext/ffmpeg/gstffmpegenc.c b/ext/ffmpeg/gstffmpegenc.c
index 33e05c5..4e4bd1e 100644
--- a/ext/ffmpeg/gstffmpegenc.c
+++ b/ext/ffmpeg/gstffmpegenc.c
@@ -777,8 +777,7 @@ gst_ffmpegenc_chain_video (GstPad * pad, GstObject * parent, GstBuffer * inbuf)
{
GstFFMpegEnc *ffmpegenc = (GstFFMpegEnc *) parent;
GstBuffer *outbuf;
- guint8 *data;
- gsize size;
+ GstMapInfo map;
gint ret_size = 0, frame_size;
gboolean force_keyframe;
@@ -797,13 +796,12 @@ gst_ffmpegenc_chain_video (GstPad * pad, GstObject * parent, GstBuffer * inbuf)
if (force_keyframe)
ffmpegenc->picture->pict_type = FF_I_TYPE;
- data = gst_buffer_map (inbuf, &size, NULL, GST_MAP_READ);
+ gst_buffer_map (inbuf, &map, GST_MAP_READ);
frame_size = gst_ffmpeg_avpicture_fill ((AVPicture *) ffmpegenc->picture,
- data,
+ map.data,
ffmpegenc->context->pix_fmt,
ffmpegenc->context->width, ffmpegenc->context->height);
- g_return_val_if_fail (frame_size == size, GST_FLOW_ERROR);
-
+ g_return_val_if_fail (frame_size == map.size, GST_FLOW_ERROR);
ffmpegenc->picture->pts =
gst_ffmpeg_time_gst_to_ff (GST_BUFFER_TIMESTAMP (inbuf) /
ffmpegenc->context->ticks_per_frame, ffmpegenc->context->time_base);
@@ -813,7 +811,7 @@ gst_ffmpegenc_chain_video (GstPad * pad, GstObject * parent, GstBuffer * inbuf)
ret_size = avcodec_encode_video (ffmpegenc->context,
ffmpegenc->working_buf, ffmpegenc->working_buf_size, ffmpegenc->picture);
- gst_buffer_unmap (inbuf, data, size);
+ gst_buffer_unmap (inbuf, &map);
if (ret_size < 0) {
#ifndef GST_DISABLE_GST_DEBUG
@@ -886,7 +884,7 @@ gst_ffmpegenc_encode_audio (GstFFMpegEnc * ffmpegenc, guint8 * audio_in,
{
GstBuffer *outbuf;
AVCodecContext *ctx;
- guint8 *audio_out;
+ GstMapInfo map;
gint res;
GstFlowReturn ret;
@@ -894,23 +892,24 @@ 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_map (outbuf, NULL, NULL, GST_MAP_WRITE);
+ gst_buffer_map (outbuf, &map, GST_MAP_WRITE);
GST_LOG_OBJECT (ffmpegenc, "encoding buffer of max size %d", max_size);
if (ffmpegenc->buffer_size != max_size)
ffmpegenc->buffer_size = max_size;
- res = avcodec_encode_audio (ctx, audio_out, max_size, (short *) audio_in);
+ res = avcodec_encode_audio (ctx, map.data, max_size, (short *) audio_in);
if (res < 0) {
- gst_buffer_unmap (outbuf, audio_out, 0);
+ gst_buffer_unmap (outbuf, &map);
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_unmap (outbuf, &map);
+ gst_buffer_resize (outbuf, 0, res);
- gst_buffer_unmap (outbuf, audio_out, res);
GST_BUFFER_TIMESTAMP (outbuf) = timestamp;
GST_BUFFER_DURATION (outbuf) = duration;
if (discont)
@@ -1066,6 +1065,7 @@ gst_ffmpegenc_chain_audio (GstPad * pad, GstObject * parent, GstBuffer * inbuf)
}
GST_LOG_OBJECT (ffmpegenc, "%u bytes left in the adapter", avail);
} else {
+ GstMapInfo map;
/* we have no frame_size, feed the encoder all the data and expect a fixed
* output size */
int coded_bps = av_get_bits_per_sample (oclass->in_plugin->id);
@@ -1076,10 +1076,12 @@ gst_ffmpegenc_chain_audio (GstPad * pad, GstObject * parent, GstBuffer * inbuf)
if (coded_bps)
out_size = (out_size * coded_bps) / 8;
- in_data = (guint8 *) gst_buffer_map (inbuf, &size, NULL, GST_MAP_READ);
+ gst_buffer_map (inbuf, &map, GST_MAP_READ);
+ in_data = map.data;
+ size = map.size;
ret = gst_ffmpegenc_encode_audio (ffmpegenc, in_data, size, out_size,
timestamp, duration, discont);
- gst_buffer_unmap (inbuf, in_data, size);
+ gst_buffer_unmap (inbuf, &map);
gst_buffer_unref (inbuf);
if (ret != GST_FLOW_OK)
diff --git a/ext/ffmpeg/gstffmpegmux.c b/ext/ffmpeg/gstffmpegmux.c
index 6b75c97..6b82759 100644
--- a/ext/ffmpeg/gstffmpegmux.c
+++ b/ext/ffmpeg/gstffmpegmux.c
@@ -721,7 +721,7 @@ gst_ffmpegmux_collected (GstCollectPads2 * pads, gpointer user_data)
GstBuffer *buf;
AVPacket pkt;
gboolean need_free = FALSE;
- gsize size;
+ GstMapInfo map;
/* push out current buffer */
buf = gst_collect_pads2_pop (ffmpegmux->collect,
@@ -737,7 +737,6 @@ gst_ffmpegmux_collected (GstCollectPads2 * pads, gpointer user_data)
if (strcmp (ffmpegmux->context->oformat->name, "gif") == 0) {
AVStream *st = ffmpegmux->context->streams[best_pad->padnum];
AVPicture src, dst;
- guint8 *data;
need_free = TRUE;
pkt.size = st->codec->width * st->codec->height * 3;
@@ -748,16 +747,17 @@ gst_ffmpegmux_collected (GstCollectPads2 * pads, gpointer user_data)
dst.data[2] = NULL;
dst.linesize[0] = st->codec->width * 3;
- data = gst_buffer_map (buf, &size, NULL, GST_MAP_READ);
- gst_ffmpeg_avpicture_fill (&src, data,
+ gst_buffer_map (buf, &map, GST_MAP_READ);
+ gst_ffmpeg_avpicture_fill (&src, map.data,
PIX_FMT_RGB24, st->codec->width, st->codec->height);
av_picture_copy (&dst, &src, PIX_FMT_RGB24,
st->codec->width, st->codec->height);
- gst_buffer_unmap (buf, data, size);
+ gst_buffer_unmap (buf, &map);
} else {
- pkt.data = gst_buffer_map (buf, &size, NULL, GST_MAP_READ);
- pkt.size = size;
+ gst_buffer_map (buf, &map, GST_MAP_READ);
+ pkt.data = map.data;
+ pkt.size = map.size;
}
pkt.stream_index = best_pad->padnum;
@@ -776,7 +776,7 @@ gst_ffmpegmux_collected (GstCollectPads2 * pads, gpointer user_data)
if (need_free) {
g_free (pkt.data);
} else {
- gst_buffer_unmap (buf, pkt.data, pkt.size);
+ gst_buffer_unmap (buf, &map);
}
gst_buffer_unref (buf);
} else {