port to new memory API

This commit is contained in:
Wim Taymans 2012-01-25 14:50:50 +01:00
parent f5cf0caf9f
commit 21073e98cf
20 changed files with 219 additions and 211 deletions

View file

@ -135,6 +135,7 @@ struct _GstSignalProcessorPad
GstPad parent; GstPad parent;
GstBuffer *pen; GstBuffer *pen;
GstMapInfo map; /* mapped data to read from / write to */
/* index for the pad per direction (starting from 0) */ /* index for the pad per direction (starting from 0) */
guint index; guint index;
@ -144,7 +145,6 @@ struct _GstSignalProcessorPad
/* these are only used for sink pads */ /* these are only used for sink pads */
guint samples_avail; /* available mono sample frames */ guint samples_avail; /* available mono sample frames */
gfloat *data; /* data pointer to read from / write to */
}; };
static GType static GType
@ -291,10 +291,8 @@ gst_signal_processor_init (GstSignalProcessor * self,
self->group_in = g_new0 (GstSignalProcessorGroup, klass->num_group_in); self->group_in = g_new0 (GstSignalProcessorGroup, klass->num_group_in);
self->group_out = g_new0 (GstSignalProcessorGroup, klass->num_group_out); self->group_out = g_new0 (GstSignalProcessorGroup, klass->num_group_out);
self->audio_in = g_new0 (gfloat *, klass->num_audio_in); self->audio_in = g_new0 (GstMapInfo, klass->num_audio_in);
self->audio_out = g_new0 (gfloat *, klass->num_audio_out); self->audio_out = g_new0 (GstMapInfo, klass->num_audio_out);
self->control_in = g_new0 (gfloat, klass->num_control_in);
self->control_out = g_new0 (gfloat, klass->num_control_out);
/* init */ /* init */
self->pending_in = klass->num_group_in + klass->num_audio_in; self->pending_in = klass->num_group_in + klass->num_audio_in;
@ -314,10 +312,6 @@ gst_signal_processor_finalize (GObject * object)
self->audio_in = NULL; self->audio_in = NULL;
g_free (self->audio_out); g_free (self->audio_out);
self->audio_out = NULL; self->audio_out = NULL;
g_free (self->control_in);
self->control_in = NULL;
g_free (self->control_out);
self->control_out = NULL;
G_OBJECT_CLASS (parent_class)->finalize (object); G_OBJECT_CLASS (parent_class)->finalize (object);
} }
@ -424,12 +418,12 @@ gst_signal_processor_cleanup (GstSignalProcessor * self)
for (i = 0; i < klass->num_group_in; ++i) { for (i = 0; i < klass->num_group_in; ++i) {
g_free (self->group_in[i].buffer); g_free (self->group_in[i].buffer);
memset (&self->group_in[i], '\0', sizeof (GstSignalProcessorGroup)); memset (&self->group_in[i], 0, sizeof (GstSignalProcessorGroup));
} }
for (i = 0; i < klass->num_group_out; ++i) { for (i = 0; i < klass->num_group_out; ++i) {
g_free (self->group_out[i].buffer); g_free (self->group_out[i].buffer);
memset (&self->group_in[i], '\0', sizeof (GstSignalProcessorGroup)); memset (&self->group_out[i], 0, sizeof (GstSignalProcessorGroup));
} }
self->state = GST_SIGNAL_PROCESSOR_STATE_NULL; self->state = GST_SIGNAL_PROCESSOR_STATE_NULL;
@ -559,12 +553,12 @@ gst_signal_processor_deinterleave_group (GstSignalProcessorGroup * group,
{ {
guint i, j; guint i, j;
g_assert (group->nframes == nframes); g_assert (group->nframes == nframes);
g_assert (group->interleaved_buffer); g_assert (group->interleaved_map.data);
g_assert (group->buffer); g_assert (group->buffer);
for (i = 0; i < nframes; ++i) for (i = 0; i < nframes; ++i)
for (j = 0; j < group->channels; ++j) for (j = 0; j < group->channels; ++j)
group->buffer[(j * nframes) + i] group->buffer[(j * nframes) + i]
= group->interleaved_buffer[(i * group->channels) + j]; = group->interleaved_map.data[(i * group->channels) + j];
} }
/* Interleave a pad (plugin => gstreamer) */ /* Interleave a pad (plugin => gstreamer) */
@ -574,11 +568,11 @@ gst_signal_processor_interleave_group (GstSignalProcessorGroup * group,
{ {
guint i, j; guint i, j;
g_assert (group->nframes == nframes); g_assert (group->nframes == nframes);
g_assert (group->interleaved_buffer); g_assert (group->interleaved_map.data);
g_assert (group->buffer); g_assert (group->buffer);
for (i = 0; i < nframes; ++i) for (i = 0; i < nframes; ++i)
for (j = 0; j < group->channels; ++j) for (j = 0; j < group->channels; ++j)
group->interleaved_buffer[(i * group->channels) + j] group->interleaved_map.data[(i * group->channels) + j]
= group->buffer[(j * nframes) + i]; = group->buffer[(j * nframes) + i];
} }
@ -659,7 +653,7 @@ gst_signal_processor_prepare (GstSignalProcessor * self, guint nframes)
samples_avail = MIN (samples_avail, sinkpad->samples_avail); samples_avail = MIN (samples_avail, sinkpad->samples_avail);
if (sinkpad->channels > 1) { if (sinkpad->channels > 1) {
GstSignalProcessorGroup *group = &self->group_in[in_group_index++]; GstSignalProcessorGroup *group = &self->group_in[in_group_index++];
group->interleaved_buffer = sinkpad->data; group->interleaved_map.data = sinkpad->map.data;
/* allocate buffer for de-interleaving */ /* allocate buffer for de-interleaving */
if (!group->buffer || group->channels < sinkpad->channels if (!group->buffer || group->channels < sinkpad->channels
|| group->nframes < samples_avail) { || group->nframes < samples_avail) {
@ -674,7 +668,7 @@ gst_signal_processor_prepare (GstSignalProcessor * self, guint nframes)
group->nframes = samples_avail; group->nframes = samples_avail;
gst_signal_processor_deinterleave_group (group, samples_avail); gst_signal_processor_deinterleave_group (group, samples_avail);
} else { } else {
self->audio_in[sinkpad->index] = sinkpad->data; self->audio_in[sinkpad->index] = sinkpad->map;
} }
} }
@ -726,7 +720,7 @@ gst_signal_processor_prepare (GstSignalProcessor * self, guint nframes)
g_assert (sinkpad->samples_avail == samples_avail); g_assert (sinkpad->samples_avail == samples_avail);
srcpad->pen = sinkpad->pen; srcpad->pen = sinkpad->pen;
sinkpad->pen = NULL; sinkpad->pen = NULL;
self->audio_out[srcpad->index] = sinkpad->data; self->audio_out[srcpad->index] = sinkpad->map;
self->pending_out++; self->pending_out++;
srcs = srcs->next; srcs = srcs->next;
@ -750,9 +744,7 @@ gst_signal_processor_prepare (GstSignalProcessor * self, guint nframes)
if (srcpad->channels > 1) { if (srcpad->channels > 1) {
GstSignalProcessorGroup *group = &self->group_out[out_group_index++]; GstSignalProcessorGroup *group = &self->group_out[out_group_index++];
group->interleaved_buffer = gst_buffer_map (srcpad->pen, &group->interleaved_map, GST_MAP_READWRITE);
(gfloat *) gst_buffer_map (srcpad->pen, NULL, NULL,
GST_MAP_READWRITE);
if (!group->buffer || group->channels < srcpad->channels if (!group->buffer || group->channels < srcpad->channels
|| group->nframes < samples_avail) || group->nframes < samples_avail)
group->buffer = group->buffer =
@ -762,8 +754,7 @@ gst_signal_processor_prepare (GstSignalProcessor * self, guint nframes)
group->nframes = samples_avail; group->nframes = samples_avail;
self->pending_out++; self->pending_out++;
} else { } else {
self->audio_out[srcpad->index] = gst_buffer_map (srcpad->pen, &self->audio_out[srcpad->index],
(gfloat *) gst_buffer_map (srcpad->pen, NULL, NULL,
GST_MAP_READWRITE); GST_MAP_READWRITE);
self->pending_out++; self->pending_out++;
} }
@ -804,13 +795,13 @@ gst_signal_processor_update_inputs (GstSignalProcessor * self, guint nprocessed)
if (!sinkpad->pen) { if (!sinkpad->pen) {
/* this buffer was used up */ /* this buffer was used up */
self->pending_in++; self->pending_in++;
sinkpad->data = NULL; sinkpad->map.data = NULL;
sinkpad->samples_avail = 0; sinkpad->samples_avail = 0;
} else { } else {
/* advance ->data pointers and decrement ->samples_avail, unreffing buffer /* advance ->data pointers and decrement ->samples_avail, unreffing buffer
if no samples are left */ if no samples are left */
sinkpad->samples_avail -= nprocessed; sinkpad->samples_avail -= nprocessed;
sinkpad->data += nprocessed * sinkpad->channels; /* gfloat* arithmetic */ sinkpad->map.data += nprocessed * sinkpad->channels; /* gfloat* arithmetic */
} }
} }
} }
@ -864,16 +855,14 @@ gst_signal_processor_pen_buffer (GstSignalProcessor * self, GstPad * pad,
GstBuffer * buffer) GstBuffer * buffer)
{ {
GstSignalProcessorPad *spad = (GstSignalProcessorPad *) pad; GstSignalProcessorPad *spad = (GstSignalProcessorPad *) pad;
gsize size;
if (spad->pen) if (spad->pen)
goto had_buffer; goto had_buffer;
/* keep the reference */ /* keep the reference */
spad->pen = buffer; spad->pen = buffer;
spad->data = gst_buffer_map (buffer, &spad->map, GST_MAP_READWRITE);
(gfloat *) gst_buffer_map (buffer, &size, NULL, GST_MAP_READWRITE); spad->samples_avail = spad->map.size / sizeof (float) / spad->channels;
spad->samples_avail = size / sizeof (float) / spad->channels;
g_assert (self->pending_in != 0); g_assert (self->pending_in != 0);
@ -906,10 +895,9 @@ gst_signal_processor_flush (GstSignalProcessor * self)
GstSignalProcessorPad *spad = (GstSignalProcessorPad *) pads->data; GstSignalProcessorPad *spad = (GstSignalProcessorPad *) pads->data;
if (spad->pen) { if (spad->pen) {
gst_buffer_unmap (spad->pen, spad->data, -1); gst_buffer_unmap (spad->pen, &spad->map);
gst_buffer_unref (spad->pen); gst_buffer_unref (spad->pen);
spad->pen = NULL; spad->pen = NULL;
spad->data = NULL;
spad->samples_avail = 0; spad->samples_avail = 0;
} }
} }

View file

@ -71,7 +71,7 @@ typedef struct _GstSignalProcessorClass GstSignalProcessorClass;
struct _GstSignalProcessorGroup { struct _GstSignalProcessorGroup {
guint channels; /**< Number of channels in buffers */ guint channels; /**< Number of channels in buffers */
guint nframes; /**< Number of frames currently allocated per channel */ guint nframes; /**< Number of frames currently allocated per channel */
gfloat *interleaved_buffer; /**< Interleaved buffer (c1c2c1c2...)*/ GstMapInfo interleaved_map; /**< Interleaved buffer (c1c2c1c2...)*/
gfloat *buffer; /**< De-interleaved buffer (c1c1...c2c2...) */ gfloat *buffer; /**< De-interleaved buffer (c1c1...c2c2...) */
}; };
@ -94,12 +94,8 @@ struct _GstSignalProcessor {
GstSignalProcessorGroup *group_out; GstSignalProcessorGroup *group_out;
/* single channel signal pads */ /* single channel signal pads */
gfloat **audio_in; GstMapInfo *audio_in;
gfloat **audio_out; GstMapInfo *audio_out;
/* controls */
gfloat *control_in;
gfloat *control_out;
/* sampling rate */ /* sampling rate */
gint sample_rate; gint sample_rate;
@ -114,8 +110,6 @@ struct _GstSignalProcessorClass {
guint num_group_out; guint num_group_out;
guint num_audio_in; guint num_audio_in;
guint num_audio_out; guint num_audio_out;
guint num_control_in;
guint num_control_out;
guint flags; guint flags;

View file

@ -792,7 +792,7 @@ gst_base_audio_visualizer_chain (GstPad * pad, GstObject * parent,
GstBuffer *inbuf; GstBuffer *inbuf;
guint64 dist, ts; guint64 dist, ts;
guint avail, sbpf; guint avail, sbpf;
gpointer adata, vdata; gpointer adata;
gboolean (*render) (GstBaseAudioVisualizer * scope, GstBuffer * audio, gboolean (*render) (GstBaseAudioVisualizer * scope, GstBuffer * audio,
GstBuffer * video); GstBuffer * video);
@ -835,6 +835,7 @@ gst_base_audio_visualizer_chain (GstPad * pad, GstObject * parent,
GST_LOG_OBJECT (scope, "avail: %u, bpf: %u", avail, sbpf); GST_LOG_OBJECT (scope, "avail: %u, bpf: %u", avail, sbpf);
while (avail >= sbpf) { while (avail >= sbpf) {
GstBuffer *outbuf; GstBuffer *outbuf;
GstMapInfo map;
/* get timestamp of the current adapter content */ /* get timestamp of the current adapter content */
ts = gst_adapter_prev_timestamp (scope->adapter, &dist); ts = gst_adapter_prev_timestamp (scope->adapter, &dist);
@ -881,11 +882,11 @@ gst_base_audio_visualizer_chain (GstPad * pad, GstObject * parent,
GST_BUFFER_TIMESTAMP (outbuf) = ts; GST_BUFFER_TIMESTAMP (outbuf) = ts;
GST_BUFFER_DURATION (outbuf) = scope->frame_duration; GST_BUFFER_DURATION (outbuf) = scope->frame_duration;
vdata = gst_buffer_map (outbuf, NULL, NULL, GST_MAP_WRITE); gst_buffer_map (outbuf, &map, GST_MAP_WRITE);
if (scope->shader) { if (scope->shader) {
memcpy (vdata, scope->pixelbuf, scope->bpf); memcpy (map.data, scope->pixelbuf, scope->bpf);
} else { } else {
memset (vdata, 0, scope->bpf); memset (map.data, 0, scope->bpf);
} }
/* this can fail as the data size we need could have changed */ /* this can fail as the data size we need could have changed */
@ -903,12 +904,13 @@ gst_base_audio_visualizer_chain (GstPad * pad, GstObject * parent,
} else { } else {
/* run various post processing (shading and geometri transformation */ /* run various post processing (shading and geometri transformation */
if (scope->shader) { if (scope->shader) {
scope->shader (scope, vdata, scope->pixelbuf); scope->shader (scope, map.data, scope->pixelbuf);
} }
} }
} }
gst_buffer_unmap (outbuf, vdata, scope->bpf); gst_buffer_unmap (outbuf, &map);
gst_buffer_resize (outbuf, 0, scope->bpf);
g_mutex_unlock (&scope->config_lock); g_mutex_unlock (&scope->config_lock);
ret = gst_pad_push (scope->srcpad, outbuf); ret = gst_pad_push (scope->srcpad, outbuf);

View file

@ -429,16 +429,17 @@ gst_space_scope_render (GstBaseAudioVisualizer * base, GstBuffer * audio,
GstBuffer * video) GstBuffer * video)
{ {
GstSpaceScope *scope = GST_SPACE_SCOPE (base); GstSpaceScope *scope = GST_SPACE_SCOPE (base);
gsize asize; GstMapInfo vmap, amap;
guint32 *vdata =
(guint32 *) gst_buffer_map (video, NULL, NULL, GST_MAP_WRITE);
gint16 *adata = (gint16 *) gst_buffer_map (audio, &asize, NULL, GST_MAP_READ);
guint num_samples; guint num_samples;
num_samples = asize / (base->channels * sizeof (gint16)); gst_buffer_map (audio, &amap, GST_MAP_READ);
scope->process (base, vdata, adata, num_samples); gst_buffer_map (video, &vmap, GST_MAP_WRITE);
gst_buffer_unmap (video, vdata, -1);
gst_buffer_unmap (audio, adata, -1); num_samples = amap.size / (base->channels * sizeof (gint16));
scope->process (base, (guint32 *) vmap.data, (gint16 *) amap.data,
num_samples);
gst_buffer_unmap (video, &vmap);
gst_buffer_unmap (audio, &amap);
return TRUE; return TRUE;
} }

View file

@ -167,20 +167,24 @@ gst_spectra_scope_render (GstBaseAudioVisualizer * bscope, GstBuffer * audio,
GstBuffer * video) GstBuffer * video)
{ {
GstSpectraScope *scope = GST_SPECTRA_SCOPE (bscope); GstSpectraScope *scope = GST_SPECTRA_SCOPE (bscope);
gsize asize; gint16 *mono_adata;
guint32 *vdata =
(guint32 *) gst_buffer_map (video, NULL, NULL, GST_MAP_WRITE);
gint16 *adata = (gint16 *) gst_buffer_map (audio, &asize, NULL, GST_MAP_READ);
gint16 *mono_adata = (gint16 *) g_memdup (adata, asize);
GstFFTS16Complex *fdata = scope->freq_data; GstFFTS16Complex *fdata = scope->freq_data;
guint x, y, off; guint x, y, off;
guint l, h = bscope->height - 1; guint l, h = bscope->height - 1;
gfloat fr, fi; gfloat fr, fi;
guint w = bscope->width; guint w = bscope->width;
GstMapInfo amap, vmap;
guint32 *vdata;
gst_buffer_map (audio, &amap, GST_MAP_READ);
gst_buffer_map (video, &vmap, GST_MAP_WRITE);
vdata = (guint32 *) vmap.data;
mono_adata = (gint16 *) g_memdup (amap.data, amap.size);
if (bscope->channels > 1) { if (bscope->channels > 1) {
guint ch = bscope->channels; guint ch = bscope->channels;
guint num_samples = asize / (ch * sizeof (gint16)); guint num_samples = amap.size / (ch * sizeof (gint16));
guint i, c, v, s = 0; guint i, c, v, s = 0;
/* deinterleave and mixdown adata */ /* deinterleave and mixdown adata */
@ -196,7 +200,7 @@ gst_spectra_scope_render (GstBaseAudioVisualizer * bscope, GstBuffer * audio,
/* run fft */ /* run fft */
gst_fft_s16_window (scope->fft_ctx, mono_adata, GST_FFT_WINDOW_HAMMING); gst_fft_s16_window (scope->fft_ctx, mono_adata, GST_FFT_WINDOW_HAMMING);
gst_fft_s16_fft (scope->fft_ctx, mono_adata, fdata); gst_fft_s16_fft (scope->fft_ctx, mono_adata, fdata);
g_free (adata); g_free (mono_adata);
/* draw lines */ /* draw lines */
for (x = 0; x < bscope->width; x++) { for (x = 0; x < bscope->width; x++) {
@ -215,8 +219,8 @@ gst_spectra_scope_render (GstBaseAudioVisualizer * bscope, GstBuffer * audio,
add_pixel (&vdata[off], 0x007F7F7F); add_pixel (&vdata[off], 0x007F7F7F);
} }
} }
gst_buffer_unmap (video, vdata, -1); gst_buffer_unmap (video, &vmap);
gst_buffer_unmap (audio, adata, -1); gst_buffer_unmap (audio, &amap);
return TRUE; return TRUE;
} }

View file

@ -205,10 +205,9 @@ gst_synae_scope_render (GstBaseAudioVisualizer * bscope, GstBuffer * audio,
GstBuffer * video) GstBuffer * video)
{ {
GstSynaeScope *scope = GST_SYNAE_SCOPE (bscope); GstSynaeScope *scope = GST_SYNAE_SCOPE (bscope);
gsize asize; GstMapInfo amap, vmap;
guint32 *vdata = guint32 *vdata;
(guint32 *) gst_buffer_map (video, NULL, NULL, GST_MAP_WRITE); gint16 *adata;
gint16 *adata = (gint16 *) gst_buffer_map (audio, &asize, NULL, GST_MAP_READ);
gint16 *adata_l = scope->adata_l; gint16 *adata_l = scope->adata_l;
gint16 *adata_r = scope->adata_r; gint16 *adata_r = scope->adata_r;
GstFFTS16Complex *fdata_l = scope->freq_data_l; GstFFTS16Complex *fdata_l = scope->freq_data_l;
@ -221,7 +220,7 @@ gst_synae_scope_render (GstBaseAudioVisualizer * bscope, GstBuffer * audio,
guint *shade = scope->shade; guint *shade = scope->shade;
//guint w2 = w /2; //guint w2 = w /2;
guint ch = bscope->channels; guint ch = bscope->channels;
guint num_samples = asize / (ch * sizeof (gint16)); guint num_samples;
gint i, j, b; gint i, j, b;
gint br, br1, br2; gint br, br1, br2;
gint clarity; gint clarity;
@ -229,6 +228,14 @@ gst_synae_scope_render (GstBaseAudioVisualizer * bscope, GstBuffer * audio,
gdouble frl, fil, frr, fir; gdouble frl, fil, frr, fir;
const guint sl = 30; const guint sl = 30;
gst_buffer_map (video, &vmap, GST_MAP_WRITE);
gst_buffer_map (audio, &amap, GST_MAP_READ);
vdata = (guint32 *) vmap.data;
adata = (gint16 *) amap.data;
num_samples = amap.size / (ch * sizeof (gint16));
/* deinterleave */ /* deinterleave */
for (i = 0, j = 0; i < num_samples; i++) { for (i = 0, j = 0; i < num_samples; i++) {
adata_l[i] = adata[j++]; adata_l[i] = adata[j++];
@ -297,6 +304,8 @@ gst_synae_scope_render (GstBaseAudioVisualizer * bscope, GstBuffer * audio,
} }
} }
} }
gst_buffer_unmap (video, &vmap);
gst_buffer_unmap (audio, &amap);
return TRUE; return TRUE;
} }

View file

@ -407,19 +407,18 @@ gst_wave_scope_render (GstBaseAudioVisualizer * base, GstBuffer * audio,
GstBuffer * video) GstBuffer * video)
{ {
GstWaveScope *scope = GST_WAVE_SCOPE (base); GstWaveScope *scope = GST_WAVE_SCOPE (base);
guint32 *vdata; GstMapInfo amap, vmap;
gsize asize;
gint16 *adata;
guint num_samples; guint num_samples;
adata = gst_buffer_map (audio, &asize, NULL, GST_MAP_READ); gst_buffer_map (audio, &amap, GST_MAP_READ);
vdata = gst_buffer_map (video, NULL, NULL, GST_MAP_WRITE); gst_buffer_map (video, &vmap, GST_MAP_WRITE);
num_samples = asize / (base->channels * sizeof (gint16)); num_samples = amap.size / (base->channels * sizeof (gint16));
scope->process (base, vdata, adata, num_samples); scope->process (base, (guint32 *) vmap.data, (gint16 *) amap.data,
num_samples);
gst_buffer_unmap (video, vdata, -1); gst_buffer_unmap (video, &vmap);
gst_buffer_unmap (audio, adata, -1); gst_buffer_unmap (audio, &amap);
return TRUE; return TRUE;
} }

View file

@ -447,18 +447,19 @@ gst_bayer2rgb_transform (GstBaseTransform * base, GstBuffer * inbuf,
GstBuffer * outbuf) GstBuffer * outbuf)
{ {
GstBayer2RGB *filter = GST_BAYER2RGB (base); GstBayer2RGB *filter = GST_BAYER2RGB (base);
uint8_t *input, *output; GstMapInfo map;
uint8_t *output;
GstVideoFrame frame; GstVideoFrame frame;
GST_DEBUG ("transforming buffer"); GST_DEBUG ("transforming buffer");
input = gst_buffer_map (inbuf, NULL, NULL, GST_MAP_READ); gst_buffer_map (inbuf, &map, GST_MAP_READ);
gst_video_frame_map (&frame, &filter->info, inbuf, GST_MAP_WRITE); gst_video_frame_map (&frame, &filter->info, inbuf, GST_MAP_WRITE);
output = GST_VIDEO_FRAME_PLANE_DATA (&frame, 0); output = GST_VIDEO_FRAME_PLANE_DATA (&frame, 0);
gst_bayer2rgb_process (filter, output, filter->width * 4, gst_bayer2rgb_process (filter, output, filter->width * 4,
input, filter->width); map.data, filter->width);
gst_video_frame_unmap (&frame); gst_video_frame_unmap (&frame);
gst_buffer_unmap (inbuf, input, -1); gst_buffer_unmap (inbuf, &map);
return GST_FLOW_OK; return GST_FLOW_OK;
} }

View file

@ -229,6 +229,7 @@ gst_rgb2bayer_transform (GstBaseTransform * trans, GstBuffer * inbuf,
GstBuffer * outbuf) GstBuffer * outbuf)
{ {
GstRGB2Bayer *rgb2bayer = GST_RGB_2_BAYER (trans); GstRGB2Bayer *rgb2bayer = GST_RGB_2_BAYER (trans);
GstMapInfo map;
guint8 *dest; guint8 *dest;
guint8 *src; guint8 *src;
int i, j; int i, j;
@ -238,7 +239,8 @@ gst_rgb2bayer_transform (GstBaseTransform * trans, GstBuffer * inbuf,
gst_video_frame_map (&frame, &rgb2bayer->info, inbuf, GST_MAP_READ); gst_video_frame_map (&frame, &rgb2bayer->info, inbuf, GST_MAP_READ);
dest = gst_buffer_map (outbuf, NULL, NULL, GST_MAP_READ); gst_buffer_map (outbuf, &map, GST_MAP_READ);
dest = map.data;
src = GST_VIDEO_FRAME_PLANE_DATA (&frame, 0); src = GST_VIDEO_FRAME_PLANE_DATA (&frame, 0);
for (j = 0; j < height; j++) { for (j = 0; j < height; j++) {
@ -256,7 +258,7 @@ gst_rgb2bayer_transform (GstBaseTransform * trans, GstBuffer * inbuf,
} }
} }
} }
gst_buffer_unmap (outbuf, dest, -1); gst_buffer_unmap (outbuf, &map);
gst_video_frame_unmap (&frame); gst_video_frame_unmap (&frame);
return GST_FLOW_OK; return GST_FLOW_OK;

View file

@ -161,17 +161,16 @@ gst_dtmf_detect_transform_ip (GstBaseTransform * trans, GstBuffer * buf)
gint dtmf_count; gint dtmf_count;
gchar dtmfbuf[MAX_DTMF_DIGITS] = ""; gchar dtmfbuf[MAX_DTMF_DIGITS] = "";
gint i; gint i;
gpointer data; GstMapInfo map;
gsize size;
if (GST_BUFFER_IS_DISCONT (buf)) if (GST_BUFFER_IS_DISCONT (buf))
zap_dtmf_detect_init (&self->dtmf_state); zap_dtmf_detect_init (&self->dtmf_state);
if (GST_BUFFER_FLAG_IS_SET (buf, GST_BUFFER_FLAG_GAP)) if (GST_BUFFER_FLAG_IS_SET (buf, GST_BUFFER_FLAG_GAP))
return GST_FLOW_OK; return GST_FLOW_OK;
data = gst_buffer_map (buf, &size, NULL, GST_MAP_READ); gst_buffer_map (buf, &map, GST_MAP_READ);
zap_dtmf_detect (&self->dtmf_state, (gint16 *) data, size / 2, FALSE); zap_dtmf_detect (&self->dtmf_state, (gint16 *) map.data, map.size / 2, FALSE);
dtmf_count = zap_dtmf_get (&self->dtmf_state, dtmfbuf, MAX_DTMF_DIGITS); dtmf_count = zap_dtmf_get (&self->dtmf_state, dtmfbuf, MAX_DTMF_DIGITS);
@ -180,7 +179,7 @@ gst_dtmf_detect_transform_ip (GstBaseTransform * trans, GstBuffer * buf)
else else
GST_LOG_OBJECT (self, "Got no DTMF events"); GST_LOG_OBJECT (self, "Got no DTMF events");
gst_buffer_unmap (buf, data, size); gst_buffer_unmap (buf, &map);
for (i = 0; i < dtmf_count; i++) { for (i = 0; i < dtmf_count; i++) {
GstMessage *dtmf_message = NULL; GstMessage *dtmf_message = NULL;

View file

@ -541,6 +541,7 @@ gst_dtmf_src_generate_tone (GstDTMFSrcEvent * event, DTMF_KEY key,
float duration, gint sample_rate) float duration, gint sample_rate)
{ {
GstBuffer *buffer; GstBuffer *buffer;
GstMapInfo map;
gint16 *p; gint16 *p;
gint tone_size; gint tone_size;
double i = 0; double i = 0;
@ -552,7 +553,8 @@ gst_dtmf_src_generate_tone (GstDTMFSrcEvent * event, DTMF_KEY key,
buffer = gst_buffer_new_allocate (NULL, tone_size, 1); buffer = gst_buffer_new_allocate (NULL, tone_size, 1);
p = (gint16 *) gst_buffer_map (buffer, NULL, NULL, GST_MAP_READWRITE); gst_buffer_map (buffer, &map, GST_MAP_READWRITE);
p = (gint16 *) map.data;
volume_factor = pow (10, (-event->volume) / 20); volume_factor = pow (10, (-event->volume) / 20);
@ -581,7 +583,7 @@ gst_dtmf_src_generate_tone (GstDTMFSrcEvent * event, DTMF_KEY key,
(event->sample)++; (event->sample)++;
} }
gst_buffer_unmap (buffer, p, tone_size); gst_buffer_unmap (buffer, &map);
return buffer; return buffer;
} }

View file

@ -333,6 +333,7 @@ gst_dtmf_src_generate_tone (GstRtpDTMFDepay * rtpdtmfdepay,
GstRTPDTMFPayload payload) GstRTPDTMFPayload payload)
{ {
GstBuffer *buf; GstBuffer *buf;
GstMapInfo map;
gint16 *p; gint16 *p;
gint tone_size; gint tone_size;
double i = 0; double i = 0;
@ -351,7 +352,8 @@ gst_dtmf_src_generate_tone (GstRtpDTMFDepay * rtpdtmfdepay,
GST_BUFFER_DURATION (buf) = payload.duration * GST_SECOND / clock_rate; GST_BUFFER_DURATION (buf) = payload.duration * GST_SECOND / clock_rate;
volume = payload.volume; volume = payload.volume;
p = (gint16 *) gst_buffer_map (buf, NULL, NULL, GST_MAP_WRITE); gst_buffer_map (buf, &map, GST_MAP_WRITE);
p = (gint16 *) map.data;
volume_factor = pow (10, (-volume) / 20); volume_factor = pow (10, (-volume) / 20);
@ -382,7 +384,7 @@ gst_dtmf_src_generate_tone (GstRtpDTMFDepay * rtpdtmfdepay,
(rtpdtmfdepay->sample)++; (rtpdtmfdepay->sample)++;
} }
gst_buffer_unmap (buf, p, tone_size); gst_buffer_unmap (buf, &map);
return buf; return buf;
} }

View file

@ -702,23 +702,23 @@ static void
gst_dvbsub_overlay_process_text (GstDVBSubOverlay * overlay, GstBuffer * buffer, gst_dvbsub_overlay_process_text (GstDVBSubOverlay * overlay, GstBuffer * buffer,
guint64 pts) guint64 pts)
{ {
guint8 *data; GstMapInfo map;
gsize size;
GST_DEBUG_OBJECT (overlay, GST_DEBUG_OBJECT (overlay,
"Processing subtitles with fake PTS=%" G_GUINT64_FORMAT "Processing subtitles with fake PTS=%" G_GUINT64_FORMAT
" which is a running time of %" GST_TIME_FORMAT, " which is a running time of %" GST_TIME_FORMAT,
pts, GST_TIME_ARGS (pts)); pts, GST_TIME_ARGS (pts));
GST_DEBUG_OBJECT (overlay, "Feeding %" G_GSIZE_FORMAT " bytes to libdvbsub",
size);
data = gst_buffer_map (buffer, &size, NULL, GST_MAP_READ); gst_buffer_map (buffer, &map, GST_MAP_READ);
GST_DEBUG_OBJECT (overlay, "Feeding %" G_GSIZE_FORMAT " bytes to libdvbsub",
map.size);
g_mutex_lock (&overlay->dvbsub_mutex); g_mutex_lock (&overlay->dvbsub_mutex);
dvb_sub_feed_with_pts (overlay->dvb_sub, pts, data, size); dvb_sub_feed_with_pts (overlay->dvb_sub, pts, map.data, map.size);
g_mutex_unlock (&overlay->dvbsub_mutex); g_mutex_unlock (&overlay->dvbsub_mutex);
gst_buffer_unmap (buffer, data, size); gst_buffer_unmap (buffer, &map);
gst_buffer_unref (buffer); gst_buffer_unref (buffer);
} }

View file

@ -951,14 +951,14 @@ gst_dvd_spu_subpic_chain (GstPad * pad, GstObject * parent, GstBuffer * buf)
* we've collected */ * we've collected */
guint8 packet_type; guint8 packet_type;
guint16 packet_size; guint16 packet_size;
guint8 *data, *ptr, *end; GstMapInfo map;
gsize size; guint8 *ptr, *end;
gboolean invalid = FALSE; gboolean invalid = FALSE;
data = gst_buffer_map (dvdspu->partial_spu, &size, NULL, GST_MAP_READ); gst_buffer_map (dvdspu->partial_spu, &map, GST_MAP_READ);
ptr = data; ptr = map.data;
end = ptr + size; end = ptr + map.size;
/* FIXME: There's no need to walk the command set each time. We can set a /* FIXME: There's no need to walk the command set each time. We can set a
* marker and resume where we left off next time */ * marker and resume where we left off next time */
@ -979,7 +979,7 @@ gst_dvd_spu_subpic_chain (GstPad * pad, GstObject * parent, GstBuffer * buf)
break; break;
} }
} }
gst_buffer_unmap (dvdspu->partial_spu, data, size); gst_buffer_unmap (dvdspu->partial_spu, &map);
if (invalid) { if (invalid) {
gst_buffer_unref (dvdspu->partial_spu); gst_buffer_unref (dvdspu->partial_spu);
@ -987,7 +987,7 @@ gst_dvd_spu_subpic_chain (GstPad * pad, GstObject * parent, GstBuffer * buf)
} else if (ptr == end) { } else if (ptr == end) {
GST_DEBUG_OBJECT (dvdspu, GST_DEBUG_OBJECT (dvdspu,
"Have complete PGS packet of size %" G_GSIZE_FORMAT ". Enqueueing.", "Have complete PGS packet of size %" G_GSIZE_FORMAT ". Enqueueing.",
size); map.size);
submit_new_spu_packet (dvdspu, dvdspu->partial_spu); submit_new_spu_packet (dvdspu, dvdspu->partial_spu);
dvdspu->partial_spu = NULL; dvdspu->partial_spu = NULL;
} }

View file

@ -679,15 +679,15 @@ parse_pgs_packet (GstDVDSpu * dvdspu, guint8 type, guint8 * payload,
gint gint
gstspu_exec_pgs_buffer (GstDVDSpu * dvdspu, GstBuffer * buf) gstspu_exec_pgs_buffer (GstDVDSpu * dvdspu, GstBuffer * buf)
{ {
guint8 *data, *pos, *end; GstMapInfo map;
gsize size; guint8 *pos, *end;
guint8 type; guint8 type;
guint16 packet_len; guint16 packet_len;
data = gst_buffer_map (buf, &size, NULL, GST_MAP_READ); gst_buffer_map (buf, &map, GST_MAP_READ);
pos = data; pos = map.data;
end = pos + size; end = pos + map.size;
/* Need at least 3 bytes */ /* Need at least 3 bytes */
if (pos + 3 > end) { if (pos + 3 > end) {
@ -703,7 +703,7 @@ gstspu_exec_pgs_buffer (GstDVDSpu * dvdspu, GstBuffer * buf)
pos += 2; pos += 2;
if (pos + packet_len > end) { if (pos + packet_len > end) {
gst_buffer_unmap (buf, data, size); gst_buffer_unmap (buf, &map);
PGS_DUMP ("Invalid packet length %u (only have %u bytes)\n", packet_len, PGS_DUMP ("Invalid packet length %u (only have %u bytes)\n", packet_len,
end - pos); end - pos);
goto error; goto error;
@ -716,12 +716,12 @@ gstspu_exec_pgs_buffer (GstDVDSpu * dvdspu, GstBuffer * buf)
} while (pos + 3 <= end); } while (pos + 3 <= end);
PGS_DUMP ("End dumping command buffer with %u bytes remaining\n", end - pos); PGS_DUMP ("End dumping command buffer with %u bytes remaining\n", end - pos);
return (pos - data); return (pos - map.data);
/* ERRORS */ /* ERRORS */
error: error:
{ {
gst_buffer_unmap (buf, data, size); gst_buffer_unmap (buf, &map);
return -1; return -1;
} }
} }

View file

@ -322,8 +322,8 @@ void
gstspu_vobsub_handle_new_buf (GstDVDSpu * dvdspu, GstClockTime event_ts, gstspu_vobsub_handle_new_buf (GstDVDSpu * dvdspu, GstClockTime event_ts,
GstBuffer * buf) GstBuffer * buf)
{ {
GstMapInfo map;
guint8 *start, *end; guint8 *start, *end;
gsize size;
SpuState *state = &dvdspu->spu_state; SpuState *state = &dvdspu->spu_state;
#if DUMP_DCSQ #if DUMP_DCSQ
@ -340,8 +340,9 @@ gstspu_vobsub_handle_new_buf (GstDVDSpu * dvdspu, GstClockTime event_ts,
state->vobsub.buf = buf; state->vobsub.buf = buf;
state->vobsub.base_ts = event_ts; state->vobsub.base_ts = event_ts;
start = gst_buffer_map (state->vobsub.buf, &size, NULL, GST_MAP_READ); gst_buffer_map (state->vobsub.buf, &map, GST_MAP_READ);
end = start + size; start = map.data;
end = start + map.size;
/* Configure the first command block in this buffer as our initial blk */ /* Configure the first command block in this buffer as our initial blk */
state->vobsub.cur_cmd_blk = GST_READ_UINT16_BE (start + 2); state->vobsub.cur_cmd_blk = GST_READ_UINT16_BE (start + 2);
@ -352,7 +353,7 @@ gstspu_vobsub_handle_new_buf (GstDVDSpu * dvdspu, GstClockTime event_ts,
g_free (state->vobsub.line_ctrl_i); g_free (state->vobsub.line_ctrl_i);
state->vobsub.line_ctrl_i = NULL; state->vobsub.line_ctrl_i = NULL;
} }
gst_buffer_unmap (state->vobsub.buf, start, size); gst_buffer_unmap (state->vobsub.buf, &map);
return; return;
invalid: invalid:
@ -363,9 +364,9 @@ invalid:
gboolean gboolean
gstspu_vobsub_execute_event (GstDVDSpu * dvdspu) gstspu_vobsub_execute_event (GstDVDSpu * dvdspu)
{ {
GstMapInfo map;
guint8 *start, *cmd_blk, *end; guint8 *start, *cmd_blk, *end;
guint16 next_blk; guint16 next_blk;
gsize size;
SpuState *state = &dvdspu->spu_state; SpuState *state = &dvdspu->spu_state;
if (state->vobsub.buf == NULL) if (state->vobsub.buf == NULL)
@ -375,13 +376,14 @@ gstspu_vobsub_execute_event (GstDVDSpu * dvdspu)
" @ offset %u", GST_TIME_ARGS (state->next_ts), " @ offset %u", GST_TIME_ARGS (state->next_ts),
state->vobsub.cur_cmd_blk); state->vobsub.cur_cmd_blk);
start = gst_buffer_map (state->vobsub.buf, &size, NULL, GST_MAP_READ); gst_buffer_map (state->vobsub.buf, &map, GST_MAP_READ);
end = start + size; start = map.data;
end = start + map.size;
cmd_blk = start + state->vobsub.cur_cmd_blk; cmd_blk = start + state->vobsub.cur_cmd_blk;
if (G_UNLIKELY (cmd_blk + 5 >= end)) { if (G_UNLIKELY (cmd_blk + 5 >= end)) {
gst_buffer_unmap (state->vobsub.buf, start, size); gst_buffer_unmap (state->vobsub.buf, &map);
/* Invalid. Finish the buffer and loop again */ /* Invalid. Finish the buffer and loop again */
gst_dvd_spu_finish_spu_buf (dvdspu); gst_dvd_spu_finish_spu_buf (dvdspu);
return FALSE; return FALSE;
@ -396,11 +398,11 @@ gstspu_vobsub_execute_event (GstDVDSpu * dvdspu)
} else { } else {
/* Next Block points to the current block, so we're finished with this /* Next Block points to the current block, so we're finished with this
* SPU buffer */ * SPU buffer */
gst_buffer_unmap (state->vobsub.buf, start, size); gst_buffer_unmap (state->vobsub.buf, &map);
gst_dvd_spu_finish_spu_buf (dvdspu); gst_dvd_spu_finish_spu_buf (dvdspu);
return FALSE; return FALSE;
} }
gst_buffer_unmap (state->vobsub.buf, start, size); gst_buffer_unmap (state->vobsub.buf, &map);
return TRUE; return TRUE;
} }

View file

@ -960,16 +960,15 @@ mpegts_base_handle_psi (MpegTSBase * base, MpegTSPacketizerSection * section)
/* table ids 0x70 - 0x73 do not have a crc */ /* table ids 0x70 - 0x73 do not have a crc */
if (G_LIKELY (section->table_id < 0x70 || section->table_id > 0x73)) { if (G_LIKELY (section->table_id < 0x70 || section->table_id > 0x73)) {
gpointer data; GstMapInfo map;
gsize size;
data = gst_buffer_map (section->buffer, &size, 0, GST_MAP_READ); gst_buffer_map (section->buffer, &map, GST_MAP_READ);
if (G_UNLIKELY (mpegts_base_calc_crc32 (data, size) != 0)) { if (G_UNLIKELY (mpegts_base_calc_crc32 (map.data, map.size) != 0)) {
gst_buffer_unmap (section->buffer, data, size); gst_buffer_unmap (section->buffer, &map);
GST_WARNING_OBJECT (base, "bad crc in psi pid 0x%x", section->pid); GST_WARNING_OBJECT (base, "bad crc in psi pid 0x%x", section->pid);
return FALSE; return FALSE;
} }
gst_buffer_unmap (section->buffer, data, size); gst_buffer_unmap (section->buffer, &map);
} }
switch (section->table_id) { switch (section->table_id) {

View file

@ -287,7 +287,7 @@ mpegts_packetizer_parse_packet (MpegTSPacketizer2 * packetizer,
packet->data = data; packet->data = data;
gst_buffer_unmap (packet->buffer, packet->bufdata, packet->bufsize); gst_buffer_unmap (packet->buffer, &packet->bufmap);
if (packet->adaptation_field_control & 0x02) if (packet->adaptation_field_control & 0x02)
if (!mpegts_packetizer_parse_adaptation_field_control (packetizer, packet)) if (!mpegts_packetizer_parse_adaptation_field_control (packetizer, packet))
@ -305,9 +305,9 @@ static gboolean
mpegts_packetizer_parse_section_header (MpegTSPacketizer2 * packetizer, mpegts_packetizer_parse_section_header (MpegTSPacketizer2 * packetizer,
MpegTSPacketizerStream * stream, MpegTSPacketizerSection * section) MpegTSPacketizerStream * stream, MpegTSPacketizerSection * section)
{ {
GstMapInfo map;
guint8 tmp; guint8 tmp;
guint8 *bufdata, *data, *crc_data; guint8 *data, *crc_data;
gsize size;
MpegTSPacketizerStreamSubtable *subtable; MpegTSPacketizerStreamSubtable *subtable;
GSList *subtable_list = NULL; GSList *subtable_list = NULL;
@ -316,7 +316,8 @@ mpegts_packetizer_parse_section_header (MpegTSPacketizer2 * packetizer,
/* get the section buffer, pass the ownership to the caller */ /* get the section buffer, pass the ownership to the caller */
section->buffer = gst_adapter_take_buffer (stream->section_adapter, section->buffer = gst_adapter_take_buffer (stream->section_adapter,
3 + stream->section_length); 3 + stream->section_length);
bufdata = data = gst_buffer_map (section->buffer, &size, 0, GST_MAP_READ); gst_buffer_map (section->buffer, &map, GST_MAP_READ);
data = map.data;
GST_BUFFER_OFFSET (section->buffer) = stream->offset; GST_BUFFER_OFFSET (section->buffer) = stream->offset;
section->table_id = *data++; section->table_id = *data++;
@ -352,7 +353,7 @@ mpegts_packetizer_parse_section_header (MpegTSPacketizer2 * packetizer,
goto not_applicable; goto not_applicable;
/* CRC is at the end of the section */ /* CRC is at the end of the section */
crc_data = bufdata + size - 4; crc_data = map.data + map.size - 4;
section->crc = GST_READ_UINT32_BE (crc_data); section->crc = GST_READ_UINT32_BE (crc_data);
if (section->version_number == subtable->version_number && if (section->version_number == subtable->version_number &&
@ -363,7 +364,7 @@ mpegts_packetizer_parse_section_header (MpegTSPacketizer2 * packetizer,
subtable->crc = section->crc; subtable->crc = section->crc;
stream->section_table_id = section->table_id; stream->section_table_id = section->table_id;
gst_buffer_unmap (section->buffer, bufdata, size); gst_buffer_unmap (section->buffer, &map);
return TRUE; return TRUE;
@ -373,7 +374,7 @@ not_applicable:
section->pid, section->table_id, section->subtable_extension, section->pid, section->table_id, section->subtable_extension,
section->current_next_indicator, section->version_number, section->crc); section->current_next_indicator, section->version_number, section->crc);
section->complete = FALSE; section->complete = FALSE;
gst_buffer_unmap (section->buffer, bufdata, size); gst_buffer_unmap (section->buffer, &map);
gst_buffer_unref (section->buffer); gst_buffer_unref (section->buffer);
return TRUE; return TRUE;
} }
@ -427,8 +428,8 @@ mpegts_packetizer_parse_pat (MpegTSPacketizer2 * packetizer,
MpegTSPacketizerSection * section) MpegTSPacketizerSection * section)
{ {
GstStructure *pat_info = NULL; GstStructure *pat_info = NULL;
guint8 *bufdata, *data, *end; GstMapInfo map;
gsize size; guint8 *data, *end;
guint transport_stream_id; guint transport_stream_id;
guint8 tmp; guint8 tmp;
guint program_number; guint program_number;
@ -438,7 +439,8 @@ mpegts_packetizer_parse_pat (MpegTSPacketizer2 * packetizer,
GstStructure *entry = NULL; GstStructure *entry = NULL;
gchar *struct_name; gchar *struct_name;
bufdata = data = gst_buffer_map (section->buffer, &size, 0, GST_MAP_READ); gst_buffer_map (section->buffer, &map, GST_MAP_READ);
data = map.data;
section->table_id = *data++; section->table_id = *data++;
section->section_length = GST_READ_UINT16_BE (data) & 0x0FFF; section->section_length = GST_READ_UINT16_BE (data) & 0x0FFF;
@ -459,7 +461,7 @@ mpegts_packetizer_parse_pat (MpegTSPacketizer2 * packetizer,
g_value_init (&entries, GST_TYPE_LIST); g_value_init (&entries, GST_TYPE_LIST);
/* stop at the CRC */ /* stop at the CRC */
end = bufdata + size; end = map.data + map.size;
while (data < end - 4) { while (data < end - 4) {
program_number = GST_READ_UINT16_BE (data); program_number = GST_READ_UINT16_BE (data);
@ -483,7 +485,7 @@ mpegts_packetizer_parse_pat (MpegTSPacketizer2 * packetizer,
gst_structure_id_set_value (pat_info, QUARK_PROGRAMS, &entries); gst_structure_id_set_value (pat_info, QUARK_PROGRAMS, &entries);
g_value_unset (&entries); g_value_unset (&entries);
gst_buffer_unmap (section->buffer, bufdata, size); gst_buffer_unmap (section->buffer, &map);
if (data != end - 4) { if (data != end - 4) {
/* FIXME: check the CRC before parsing the packet */ /* FIXME: check the CRC before parsing the packet */
@ -501,8 +503,8 @@ mpegts_packetizer_parse_pmt (MpegTSPacketizer2 * packetizer,
MpegTSPacketizerSection * section) MpegTSPacketizerSection * section)
{ {
GstStructure *pmt = NULL; GstStructure *pmt = NULL;
guint8 *bufdata, *data, *end; GstMapInfo map;
gsize size; guint8 *data, *end;
guint16 program_number; guint16 program_number;
guint8 tmp; guint8 tmp;
guint pcr_pid; guint pcr_pid;
@ -516,16 +518,17 @@ mpegts_packetizer_parse_pmt (MpegTSPacketizer2 * packetizer,
GstStructure *stream_info = NULL; GstStructure *stream_info = NULL;
gchar *struct_name; gchar *struct_name;
data = bufdata = gst_buffer_map (section->buffer, &size, 0, GST_MAP_READ); gst_buffer_map (section->buffer, &map, GST_MAP_READ);
data = map.data;
/* fixed header + CRC == 16 */ /* fixed header + CRC == 16 */
if (size < 16) { if (map.size < 16) {
GST_WARNING ("PID %d invalid PMT size %d", GST_WARNING ("PID %d invalid PMT size %d",
section->pid, section->section_length); section->pid, section->section_length);
goto error; goto error;
} }
end = data + size; end = map.data + map.size;
section->table_id = *data++; section->table_id = *data++;
section->section_length = GST_READ_UINT16_BE (data) & 0x0FFF; section->section_length = GST_READ_UINT16_BE (data) & 0x0FFF;
@ -695,7 +698,7 @@ mpegts_packetizer_parse_pmt (MpegTSPacketizer2 * packetizer,
gst_structure_id_set_value (pmt, QUARK_STREAMS, &programs); gst_structure_id_set_value (pmt, QUARK_STREAMS, &programs);
g_value_unset (&programs); g_value_unset (&programs);
gst_buffer_unmap (section->buffer, bufdata, size); gst_buffer_unmap (section->buffer, &map);
g_assert (data == end - 4); g_assert (data == end - 4);
@ -704,7 +707,7 @@ mpegts_packetizer_parse_pmt (MpegTSPacketizer2 * packetizer,
error: error:
if (pmt) if (pmt)
gst_structure_free (pmt); gst_structure_free (pmt);
gst_buffer_unmap (section->buffer, bufdata, size); gst_buffer_unmap (section->buffer, &map);
return NULL; return NULL;
} }
@ -714,8 +717,8 @@ mpegts_packetizer_parse_nit (MpegTSPacketizer2 * packetizer,
MpegTSPacketizerSection * section) MpegTSPacketizerSection * section)
{ {
GstStructure *nit = NULL, *transport = NULL, *delivery_structure = NULL; GstStructure *nit = NULL, *transport = NULL, *delivery_structure = NULL;
guint8 *bufdata, *data, *end, *entry_begin; GstMapInfo map;
gsize size; guint8 *data, *end, *entry_begin;
guint16 network_id, transport_stream_id, original_network_id; guint16 network_id, transport_stream_id, original_network_id;
guint tmp; guint tmp;
guint16 descriptors_loop_length, transport_stream_loop_length; guint16 descriptors_loop_length, transport_stream_loop_length;
@ -725,16 +728,17 @@ mpegts_packetizer_parse_nit (MpegTSPacketizer2 * packetizer,
GST_DEBUG ("NIT"); GST_DEBUG ("NIT");
data = bufdata = gst_buffer_map (section->buffer, &size, 0, GST_MAP_READ); gst_buffer_map (section->buffer, &map, GST_MAP_READ);
data = map.data;
/* fixed header + CRC == 16 */ /* fixed header + CRC == 16 */
if (size < 23) { if (map.size < 23) {
GST_WARNING ("PID %d invalid NIT size %d", GST_WARNING ("PID %d invalid NIT size %d",
section->pid, section->section_length); section->pid, section->section_length);
goto error; goto error;
} }
end = data + size; end = map.data + map.size;
section->table_id = *data++; section->table_id = *data++;
section->section_length = GST_READ_UINT16_BE (data) & 0x0FFF; section->section_length = GST_READ_UINT16_BE (data) & 0x0FFF;
@ -1323,14 +1327,14 @@ mpegts_packetizer_parse_nit (MpegTSPacketizer2 * packetizer,
if (data != end - 4) { if (data != end - 4) {
GST_WARNING ("PID %d invalid NIT parsed %d length %" G_GSIZE_FORMAT, GST_WARNING ("PID %d invalid NIT parsed %d length %" G_GSIZE_FORMAT,
section->pid, (gint) (data - bufdata), size); section->pid, (gint) (data - map.data), map.size);
goto error; goto error;
} }
gst_structure_id_set_value (nit, QUARK_TRANSPORTS, &transports); gst_structure_id_set_value (nit, QUARK_TRANSPORTS, &transports);
g_value_unset (&transports); g_value_unset (&transports);
gst_buffer_unmap (section->buffer, bufdata, size); gst_buffer_unmap (section->buffer, &map);
GST_DEBUG ("NIT %" GST_PTR_FORMAT, nit); GST_DEBUG ("NIT %" GST_PTR_FORMAT, nit);
@ -1340,7 +1344,7 @@ error:
if (nit) if (nit)
gst_structure_free (nit); gst_structure_free (nit);
gst_buffer_unmap (section->buffer, bufdata, size); gst_buffer_unmap (section->buffer, &map);
if (GST_VALUE_HOLDS_LIST (&transports)) if (GST_VALUE_HOLDS_LIST (&transports))
g_value_unset (&transports); g_value_unset (&transports);
@ -1352,9 +1356,9 @@ GstStructure *
mpegts_packetizer_parse_sdt (MpegTSPacketizer2 * packetizer, mpegts_packetizer_parse_sdt (MpegTSPacketizer2 * packetizer,
MpegTSPacketizerSection * section) MpegTSPacketizerSection * section)
{ {
GstMapInfo map;
GstStructure *sdt = NULL, *service = NULL; GstStructure *sdt = NULL, *service = NULL;
guint8 *data, *bufdata, *end, *entry_begin; guint8 *data, *end, *entry_begin;
gsize size;
guint16 transport_stream_id, original_network_id, service_id; guint16 transport_stream_id, original_network_id, service_id;
guint tmp; guint tmp;
guint sdt_info_length; guint sdt_info_length;
@ -1367,16 +1371,17 @@ mpegts_packetizer_parse_sdt (MpegTSPacketizer2 * packetizer,
GST_DEBUG ("SDT"); GST_DEBUG ("SDT");
data = bufdata = gst_buffer_map (section->buffer, &size, 0, GST_MAP_READ); gst_buffer_map (section->buffer, &map, GST_MAP_READ);
data = map.data;
/* fixed header + CRC == 16 */ /* fixed header + CRC == 16 */
if (size < 14) { if (map.size < 14) {
GST_WARNING ("PID %d invalid SDT size %d", GST_WARNING ("PID %d invalid SDT size %d",
section->pid, section->section_length); section->pid, section->section_length);
goto error; goto error;
} }
end = data + size; end = map.data + map.size;
section->table_id = *data++; section->table_id = *data++;
section->section_length = GST_READ_UINT16_BE (data) & 0x0FFF; section->section_length = GST_READ_UINT16_BE (data) & 0x0FFF;
@ -1534,14 +1539,14 @@ mpegts_packetizer_parse_sdt (MpegTSPacketizer2 * packetizer,
if (data != end - 4) { if (data != end - 4) {
GST_WARNING ("PID %d invalid SDT parsed %d length %" G_GSIZE_FORMAT, GST_WARNING ("PID %d invalid SDT parsed %d length %" G_GSIZE_FORMAT,
section->pid, (gint) (data - bufdata), size); section->pid, (gint) (data - map.data), map.size);
goto error; goto error;
} }
gst_structure_id_set_value (sdt, QUARK_SERVICES, &services); gst_structure_id_set_value (sdt, QUARK_SERVICES, &services);
g_value_unset (&services); g_value_unset (&services);
gst_buffer_unmap (section->buffer, bufdata, size); gst_buffer_unmap (section->buffer, &map);
return sdt; return sdt;
@ -1549,7 +1554,7 @@ error:
if (sdt) if (sdt)
gst_structure_free (sdt); gst_structure_free (sdt);
gst_buffer_unmap (section->buffer, bufdata, size); gst_buffer_unmap (section->buffer, &map);
if (GST_VALUE_HOLDS_LIST (&services)) if (GST_VALUE_HOLDS_LIST (&services))
g_value_unset (&services); g_value_unset (&services);
@ -1569,8 +1574,8 @@ mpegts_packetizer_parse_eit (MpegTSPacketizer2 * packetizer,
guint16 mjd; guint16 mjd;
guint year, month, day, hour, minute, second; guint year, month, day, hour, minute, second;
guint duration; guint duration;
guint8 *data, *bufdata, *end, *duration_ptr, *utc_ptr; GstMapInfo map;
gsize size; guint8 *data, *end, *duration_ptr, *utc_ptr;
guint16 descriptors_loop_length; guint16 descriptors_loop_length;
GValue events = { 0 }; GValue events = { 0 };
GValue event_value = { 0 }; GValue event_value = { 0 };
@ -1578,16 +1583,17 @@ mpegts_packetizer_parse_eit (MpegTSPacketizer2 * packetizer,
gchar *event_name; gchar *event_name;
guint tmp; guint tmp;
data = bufdata = gst_buffer_map (section->buffer, &size, 0, GST_MAP_READ); gst_buffer_map (section->buffer, &map, GST_MAP_READ);
data = map.data;
/* fixed header + CRC == 16 */ /* fixed header + CRC == 16 */
if (size < 18) { if (map.size < 18) {
GST_WARNING ("PID %d invalid EIT size %d", GST_WARNING ("PID %d invalid EIT size %d",
section->pid, section->section_length); section->pid, section->section_length);
goto error; goto error;
} }
end = data + size; end = map.data + map.size;
section->table_id = *data++; section->table_id = *data++;
section->section_length = GST_READ_UINT16_BE (data) & 0x0FFF; section->section_length = GST_READ_UINT16_BE (data) & 0x0FFF;
@ -1998,14 +2004,14 @@ mpegts_packetizer_parse_eit (MpegTSPacketizer2 * packetizer,
if (data != end - 4) { if (data != end - 4) {
GST_WARNING ("PID %d invalid EIT parsed %d length %" G_GSIZE_FORMAT, GST_WARNING ("PID %d invalid EIT parsed %d length %" G_GSIZE_FORMAT,
section->pid, (gint) (data - bufdata), size); section->pid, (gint) (data - map.data), map.size);
goto error; goto error;
} }
gst_structure_id_set_value (eit, QUARK_EVENTS, &events); gst_structure_id_set_value (eit, QUARK_EVENTS, &events);
g_value_unset (&events); g_value_unset (&events);
gst_buffer_unmap (section->buffer, bufdata, size); gst_buffer_unmap (section->buffer, &map);
GST_DEBUG ("EIT %" GST_PTR_FORMAT, eit); GST_DEBUG ("EIT %" GST_PTR_FORMAT, eit);
@ -2015,7 +2021,7 @@ error:
if (eit) if (eit)
gst_structure_free (eit); gst_structure_free (eit);
gst_buffer_unmap (section->buffer, bufdata, size); gst_buffer_unmap (section->buffer, &map);
if (GST_VALUE_HOLDS_LIST (&events)) if (GST_VALUE_HOLDS_LIST (&events))
g_value_unset (&events); g_value_unset (&events);
@ -2030,21 +2036,22 @@ mpegts_packetizer_parse_tdt (MpegTSPacketizer2 * packetizer,
GstStructure *tdt = NULL; GstStructure *tdt = NULL;
guint16 mjd; guint16 mjd;
guint year, month, day, hour, minute, second; guint year, month, day, hour, minute, second;
guint8 *data, *bufdata, *end, *utc_ptr; GstMapInfo map;
gsize size; guint8 *data, *end, *utc_ptr;
GST_DEBUG ("TDT"); GST_DEBUG ("TDT");
data = bufdata = gst_buffer_map (section->buffer, &size, 0, GST_MAP_READ); gst_buffer_map (section->buffer, &map, GST_MAP_READ);
data = map.data;
/* length always 8 */ /* length always 8 */
if (G_UNLIKELY (size != 8)) { if (G_UNLIKELY (map.size != 8)) {
GST_WARNING ("PID %d invalid TDT size %d", GST_WARNING ("PID %d invalid TDT size %d",
section->pid, section->section_length); section->pid, section->section_length);
goto error; goto error;
} }
end = data + size; end = map.data + map.size;
section->table_id = *data++; section->table_id = *data++;
section->section_length = GST_READ_UINT16_BE (data) & 0x0FFF; section->section_length = GST_READ_UINT16_BE (data) & 0x0FFF;
@ -2085,7 +2092,7 @@ mpegts_packetizer_parse_tdt (MpegTSPacketizer2 * packetizer,
"hour", G_TYPE_UINT, hour, "hour", G_TYPE_UINT, hour,
"minute", G_TYPE_UINT, minute, "second", G_TYPE_UINT, second, NULL); "minute", G_TYPE_UINT, minute, "second", G_TYPE_UINT, second, NULL);
gst_buffer_unmap (section->buffer, bufdata, size); gst_buffer_unmap (section->buffer, &map);
return tdt; return tdt;
@ -2093,7 +2100,7 @@ error:
if (tdt) if (tdt)
gst_structure_free (tdt); gst_structure_free (tdt);
gst_buffer_unmap (section->buffer, bufdata, size); gst_buffer_unmap (section->buffer, &map);
return NULL; return NULL;
} }
@ -2281,8 +2288,9 @@ mpegts_packetizer_next_packet (MpegTSPacketizer2 * packetizer,
packet->buffer = gst_adapter_take_buffer (packetizer->adapter, packet->buffer = gst_adapter_take_buffer (packetizer->adapter,
packetizer->packet_size); packetizer->packet_size);
bufdata = packet->bufdata = packet->data_start = gst_buffer_map (packet->buffer, &packet->bufmap, GST_MAP_READ);
gst_buffer_map (packet->buffer, &packet->bufsize, 0, GST_MAP_READ);
bufdata = packet->data_start = packet->bufmap.data;
/* M2TS packets don't start with the sync byte, all other variants do */ /* M2TS packets don't start with the sync byte, all other variants do */
if (packetizer->packet_size == MPEGTS_M2TS_PACKETSIZE) if (packetizer->packet_size == MPEGTS_M2TS_PACKETSIZE)
@ -2312,7 +2320,7 @@ mpegts_packetizer_next_packet (MpegTSPacketizer2 * packetizer,
if (G_UNLIKELY (i == packetizer->packet_size)) { if (G_UNLIKELY (i == packetizer->packet_size)) {
GST_ERROR ("REALLY lost the sync"); GST_ERROR ("REALLY lost the sync");
gst_buffer_unmap (packet->buffer, bufdata, packet->bufsize); gst_buffer_unmap (packet->buffer, &packet->bufmap);
gst_buffer_unref (packet->buffer); gst_buffer_unref (packet->buffer);
goto done; goto done;
} }
@ -2325,7 +2333,7 @@ mpegts_packetizer_next_packet (MpegTSPacketizer2 * packetizer,
} }
/* Pop out the remaining data... */ /* Pop out the remaining data... */
gst_buffer_resize (packet->buffer, i, packet->bufsize - i); gst_buffer_resize (packet->buffer, i, packet->bufmap.size - i);
GST_BUFFER_OFFSET (packet->buffer) += i; GST_BUFFER_OFFSET (packet->buffer) += i;
tmpbuf = tmpbuf =
gst_adapter_take_buffer (packetizer->adapter, gst_adapter_take_buffer (packetizer->adapter,
@ -2384,7 +2392,7 @@ mpegts_packetizer_push_section (MpegTSPacketizer2 * packetizer,
section->section_length = GST_READ_UINT24_BE (data) & 0x000FFF; section->section_length = GST_READ_UINT24_BE (data) & 0x000FFF;
section->buffer = section->buffer =
gst_buffer_copy_region (packet->buffer, GST_BUFFER_COPY_ALL, gst_buffer_copy_region (packet->buffer, GST_BUFFER_COPY_ALL,
data - packet->bufdata, section->section_length + 3); data - packet->bufmap.data, section->section_length + 3);
section->table_id = table_id; section->table_id = table_id;
section->complete = TRUE; section->complete = TRUE;
res = TRUE; res = TRUE;
@ -2396,7 +2404,7 @@ mpegts_packetizer_push_section (MpegTSPacketizer2 * packetizer,
/* create a sub buffer from the start of the section (table_id and /* create a sub buffer from the start of the section (table_id and
* section_length included) to the end */ * section_length included) to the end */
sub_buf = gst_buffer_copy_region (packet->buffer, GST_BUFFER_COPY_ALL, sub_buf = gst_buffer_copy_region (packet->buffer, GST_BUFFER_COPY_ALL,
data - packet->bufdata, packet->data_end - data); data - packet->bufmap.data, packet->data_end - data);
stream = packetizer->streams[packet->pid]; stream = packetizer->streams[packet->pid];

View file

@ -94,9 +94,8 @@ typedef struct
guint8 continuity_counter; guint8 continuity_counter;
guint8 *payload; guint8 *payload;
/* temporary copies of gst_buffer_map */ /* gst_buffer_map */
guint8 *bufdata; GstMapInfo bufmap;
gsize bufsize;
guint8 *data_start; /* Location of 0x47 marker byte */ guint8 *data_start; /* Location of 0x47 marker byte */
guint8 *data_end; guint8 *data_end;

View file

@ -1726,8 +1726,8 @@ process_pcr (MpegTSBase * base, guint64 initoff, TSPcrOffset * pcroffset,
for (i = 0; (i < 20) && (nbpcr < numpcr); i++) { for (i = 0; (i < 20) && (nbpcr < numpcr); i++) {
guint offset; guint offset;
gsize size, bufsize; GstMapInfo map;
gpointer data; gsize size;
ret = ret =
gst_pad_pull_range (base->sinkpad, gst_pad_pull_range (base->sinkpad,
@ -1736,10 +1736,10 @@ process_pcr (MpegTSBase * base, guint64 initoff, TSPcrOffset * pcroffset,
if (G_UNLIKELY (ret != GST_FLOW_OK)) if (G_UNLIKELY (ret != GST_FLOW_OK))
goto beach; goto beach;
data = gst_buffer_map (buf, &bufsize, 0, GST_MAP_READ); gst_buffer_map (buf, &map, GST_MAP_READ);
size = bufsize; size = map.size;
gst_byte_reader_init (&br, data, size); gst_byte_reader_init (&br, map.data, map.size);
offset = 0; offset = 0;
@ -1748,7 +1748,7 @@ process_pcr (MpegTSBase * base, guint64 initoff, TSPcrOffset * pcroffset,
0, base->packetsize); 0, base->packetsize);
if (offset == -1) { if (offset == -1) {
gst_buffer_unmap (buf, data, bufsize); gst_buffer_unmap (buf, &map);
continue; continue;
} }
@ -1799,7 +1799,7 @@ process_pcr (MpegTSBase * base, guint64 initoff, TSPcrOffset * pcroffset,
size -= base->packetsize; size -= base->packetsize;
offset += base->packetsize; offset += base->packetsize;
} }
gst_buffer_unmap (buf, data, bufsize); gst_buffer_unmap (buf, &map);
} }
beach: beach:
@ -2013,19 +2013,18 @@ gst_ts_demux_parse_pes_header (GstTSDemux * demux, TSDemuxStream * stream)
GstBuffer *buf = stream->pendingbuffers[0]; GstBuffer *buf = stream->pendingbuffers[0];
GstFlowReturn res = GST_FLOW_OK; GstFlowReturn res = GST_FLOW_OK;
gint offset = 0; gint offset = 0;
guint8 *data; GstMapInfo map;
gsize length;
guint64 bufferoffset; guint64 bufferoffset;
PESParsingResult parseres; PESParsingResult parseres;
GstClockTime origts; GstClockTime origts;
data = gst_buffer_map (buf, &length, 0, GST_MAP_READ); gst_buffer_map (buf, &map, GST_MAP_READ);
bufferoffset = GST_BUFFER_OFFSET (buf); bufferoffset = GST_BUFFER_OFFSET (buf);
origts = GST_BUFFER_TIMESTAMP (buf); origts = GST_BUFFER_TIMESTAMP (buf);
GST_MEMDUMP ("Header buffer", data, MIN (length, 32)); GST_MEMDUMP ("Header buffer", map.data, MIN (map.size, 32));
parseres = mpegts_parse_pes_header (data, length, &header, &offset); parseres = mpegts_parse_pes_header (map.data, map.size, &header, &offset);
if (G_UNLIKELY (parseres == PES_PARSING_NEED_MORE)) if (G_UNLIKELY (parseres == PES_PARSING_NEED_MORE))
goto discont; goto discont;
@ -2123,11 +2122,11 @@ gst_ts_demux_parse_pes_header (GstTSDemux * demux, TSDemuxStream * stream)
if (header.DTS != -1) if (header.DTS != -1)
gst_ts_demux_record_dts (demux, stream, header.DTS, bufferoffset); gst_ts_demux_record_dts (demux, stream, header.DTS, bufferoffset);
gst_buffer_unmap (buf, data, length); gst_buffer_unmap (buf, &map);
/* Remove PES headers */ /* Remove PES headers */
GST_DEBUG ("Moving data forward by %d bytes", header.header_size); GST_DEBUG ("Moving data forward by %d bytes", header.header_size);
gst_buffer_resize (buf, header.header_size, length - header.header_size); gst_buffer_resize (buf, header.header_size, map.size - header.header_size);
/* FIXME : responsible for switching to PENDING_PACKET_BUFFER and /* FIXME : responsible for switching to PENDING_PACKET_BUFFER and
* creating the bufferlist */ * creating the bufferlist */
@ -2162,21 +2161,19 @@ gst_ts_demux_queue_data (GstTSDemux * demux, TSDemuxStream * stream,
MpegTSPacketizerPacket * packet) MpegTSPacketizerPacket * packet)
{ {
GstBuffer *buf; GstBuffer *buf;
guint8 *data; GstMapInfo map;
gsize size;
GST_DEBUG ("state:%d", stream->state); GST_DEBUG ("state:%d", stream->state);
buf = packet->buffer; buf = packet->buffer;
data = gst_buffer_map (buf, &size, 0, GST_MAP_READ); gst_buffer_map (buf, &map, GST_MAP_READ);
GST_DEBUG ("Resizing buffer to %d (size:%d) (Was %" G_GSIZE_FORMAT GST_DEBUG ("Resizing buffer to %d (size:%d) (Was %" G_GSIZE_FORMAT
" bytes long)", (int) (packet->payload - data), " bytes long)", (int) (packet->payload - map.data),
(int) (packet->data_end - packet->payload), size); (int) (packet->data_end - packet->payload), map.size);
gst_buffer_unmap (buf, data, size); gst_buffer_resize (buf, packet->payload - map.data,
gst_buffer_resize (buf, packet->payload - data,
packet->data_end - packet->payload); packet->data_end - packet->payload);
gst_buffer_unmap (buf, &map);
if (stream->state == PENDING_PACKET_EMPTY) { if (stream->state == PENDING_PACKET_EMPTY) {
if (G_UNLIKELY (!packet->payload_unit_start_indicator)) { if (G_UNLIKELY (!packet->payload_unit_start_indicator)) {