summaryrefslogtreecommitdiffstats
path: root/gst
diff options
context:
space:
mode:
authorOlivier Crete <olivier.crete@collabora.co.uk>2008-07-04 22:17:43 +0000
committerEdward Hervey <bilboed@bilboed.com>2009-02-17 19:29:40 +0100
commitae01ec198053cb6c35af11bc006a28a796319aff (patch)
treeceea66e4e07078672185f045f9c7d5b2a222e134 /gst
parent1c3fa06a8f33fa423732f4ad46ffbfb7e6d2fc31 (diff)
downloadgst-plugins-bad-ae01ec198053cb6c35af11bc006a28a796319aff.tar.gz
gst-plugins-bad-ae01ec198053cb6c35af11bc006a28a796319aff.tar.bz2
gst-plugins-bad-ae01ec198053cb6c35af11bc006a28a796319aff.zip
[MOVED FROM GST-P-FARSIGHT] make sirenenc thread safe
20080704221743-3e2dc-f93da86438f753e14be25166aee45f8802f7d100.gz
Diffstat (limited to 'gst')
-rw-r--r--gst/siren/gstsirenenc.c44
-rw-r--r--gst/siren/gstsirenenc.h2
2 files changed, 24 insertions, 22 deletions
diff --git a/gst/siren/gstsirenenc.c b/gst/siren/gstsirenenc.c
index 70936e05..cd0f274a 100644
--- a/gst/siren/gstsirenenc.c
+++ b/gst/siren/gstsirenenc.c
@@ -178,15 +178,9 @@ gst_siren_enc_chain (GstPad *pad, GstBuffer *buf)
gint offset = 0;
gint encode_ret = 0;
gint size = 0;
+ guint in_offset = 0;
- if (enc->encoder == NULL) {
- GST_WARNING ("Siren encoder not set");
- return GST_FLOW_WRONG_STATE;
- }
- if (enc->adapter == NULL) {
- GST_ERROR ("Adapter not set");
- return GST_FLOW_ERROR;
- }
+ GST_OBJECT_LOCK (enc);
gst_adapter_push (enc->adapter, buf);
@@ -197,41 +191,47 @@ gst_siren_enc_chain (GstPad *pad, GstBuffer *buf)
size /= 16;
size -= size % 40;
- if (size == 0)
- return GST_FLOW_OK;
+ if (size == 0) {
+ GST_OBJECT_UNLOCK (enc);
+ goto out;
+ }
+
+ data = gst_adapter_take (enc->adapter, size * 16);
+
+ GST_OBJECT_UNLOCK (enc);
ret = gst_pad_alloc_buffer_and_set_caps (enc->srcpad,
GST_BUFFER_OFFSET (buf) / 16, size, enc->srccaps, &encoded);
- if (ret != GST_FLOW_OK)
- return ret;
-
- data = GST_BUFFER_DATA (encoded);
- while (gst_adapter_available (enc->adapter) >= 640 &&
- ret == GST_FLOW_OK) {
+ if (ret != GST_FLOW_OK)
+ goto out;
+ while (offset < size && ret == GST_FLOW_OK) {
GST_LOG_OBJECT (enc, "Encoding frame");
encode_ret = Siren7_EncodeFrame (enc->encoder,
- (guint8 *)gst_adapter_peek (enc->adapter, 640),
- data + offset);
+ data + in_offset,
+ GST_BUFFER_DATA (encoded) + offset);
if (encode_ret != 0) {
GST_ERROR_OBJECT (enc, "Siren7_EncodeFrame returned %d", encode_ret);
ret = GST_FLOW_ERROR;
+ gst_buffer_unref (encoded);
+ goto out;
}
- gst_adapter_flush (enc->adapter, 640);
offset += 40;
+ in_offset += 640;
}
GST_LOG_OBJECT (enc, "Finished encoding : %d", offset);
- GST_BUFFER_SIZE (encoded) = offset;
-
ret = gst_pad_push (enc->srcpad, encoded);
- gst_object_unref (enc);
+ out:
+ if (data)
+ g_free (data);
+ gst_object_unref (enc);
return ret;
}
diff --git a/gst/siren/gstsirenenc.h b/gst/siren/gstsirenenc.h
index 1b404e03..0063e2cb 100644
--- a/gst/siren/gstsirenenc.h
+++ b/gst/siren/gstsirenenc.h
@@ -52,7 +52,9 @@ struct _GstSirenEnc
{
GstElement parent;
+ /* protected by the stream lock */
SirenEncoder encoder;
+ /* protected by the object lock */
GstAdapter *adapter;
GstPad *srcpad;