diff options
author | Sebastian Dröge <sebastian.droege@collabora.co.uk> | 2009-03-22 15:51:37 +0100 |
---|---|---|
committer | Sebastian Dröge <sebastian.droege@collabora.co.uk> | 2009-03-22 15:51:37 +0100 |
commit | effb5786da04e28effadc0602ef1ec5465458801 (patch) | |
tree | 0c187c241f51bda6bcec5cccdba7df8330803c0c /gst | |
parent | ddced37a8b83be290343502d4099d8f325da4e3f (diff) | |
download | gstreamer-plugins-bad-effb5786da04e28effadc0602ef1ec5465458801.tar.gz |
mxfmux: Fix some memory leaks, improve debugging and handle errors better
Diffstat (limited to 'gst')
-rw-r--r-- | gst/mxf/mxfaes-bwf.c | 18 | ||||
-rw-r--r-- | gst/mxf/mxfalaw.c | 16 | ||||
-rw-r--r-- | gst/mxf/mxfdv-dif.c | 7 | ||||
-rw-r--r-- | gst/mxf/mxfjpeg2000.c | 16 | ||||
-rw-r--r-- | gst/mxf/mxfmetadata.c | 36 | ||||
-rw-r--r-- | gst/mxf/mxfmetadata.h | 4 | ||||
-rw-r--r-- | gst/mxf/mxfmpeg.c | 25 | ||||
-rw-r--r-- | gst/mxf/mxfup.c | 27 | ||||
-rw-r--r-- | gst/mxf/mxfvc3.c | 12 |
9 files changed, 113 insertions, 48 deletions
diff --git a/gst/mxf/mxfaes-bwf.c b/gst/mxf/mxfaes-bwf.c index 9b08ffbb3..cf61ea7e5 100644 --- a/gst/mxf/mxfaes-bwf.c +++ b/gst/mxf/mxfaes-bwf.c @@ -1445,14 +1445,14 @@ mxf_bwf_get_descriptor (GstPadTemplate * tmpl, GstCaps * caps, gint width, rate, channels, endianness; s = gst_caps_get_structure (caps, 0); - if (strcmp (gst_structure_get_name (s), "audio/x-raw-int") != 0) - return NULL; - - if (!gst_structure_get_int (s, "width", &width) || + if (strcmp (gst_structure_get_name (s), "audio/x-raw-int") != 0 || + !gst_structure_get_int (s, "width", &width) || !gst_structure_get_int (s, "rate", &rate) || !gst_structure_get_int (s, "channels", &channels) || - !gst_structure_get_int (s, "endianness", &endianness)) + !gst_structure_get_int (s, "endianness", &endianness)) { + GST_ERROR ("Invalid caps %" GST_PTR_FORMAT, caps); return NULL; + } ret = (MXFMetadataWaveAudioEssenceDescriptor *) gst_mini_object_new (MXF_TYPE_METADATA_WAVE_AUDIO_ESSENCE_DESCRIPTOR); @@ -1468,7 +1468,13 @@ mxf_bwf_get_descriptor (GstPadTemplate * tmpl, GstCaps * caps, ret->block_align = (width / 8) * channels; ret->parent.quantization_bits = width; ret->avg_bps = ret->block_align * rate; - mxf_metadata_generic_sound_essence_descriptor_from_caps (&ret->parent, caps); + + if (!mxf_metadata_generic_sound_essence_descriptor_from_caps (&ret->parent, + caps)) { + gst_mini_object_unref (GST_MINI_OBJECT_CAST (ret)); + return NULL; + } + *handler = mxf_bwf_write_func; md = g_new0 (BWFMappingData, 1); diff --git a/gst/mxf/mxfalaw.c b/gst/mxf/mxfalaw.c index db7456cbb..52df480fe 100644 --- a/gst/mxf/mxfalaw.c +++ b/gst/mxf/mxfalaw.c @@ -196,12 +196,12 @@ mxf_alaw_get_descriptor (GstPadTemplate * tmpl, GstCaps * caps, gint rate, channels; s = gst_caps_get_structure (caps, 0); - if (strcmp (gst_structure_get_name (s), "audio/x-alaw") != 0) - return NULL; - - if (!gst_structure_get_int (s, "rate", &rate) || - !gst_structure_get_int (s, "channels", &channels)) + if (strcmp (gst_structure_get_name (s), "audio/x-alaw") != 0 || + !gst_structure_get_int (s, "rate", &rate) || + !gst_structure_get_int (s, "channels", &channels)) { + GST_ERROR ("Invalid caps %" GST_PTR_FORMAT, caps); return NULL; + } ret = (MXFMetadataGenericSoundEssenceDescriptor *) gst_mini_object_new (MXF_TYPE_METADATA_GENERIC_SOUND_ESSENCE_DESCRIPTOR); @@ -210,7 +210,11 @@ mxf_alaw_get_descriptor (GstPadTemplate * tmpl, GstCaps * caps, memcpy (&ret->sound_essence_compression, &mxf_sound_essence_compression_alaw, 16); - mxf_metadata_generic_sound_essence_descriptor_from_caps (ret, caps); + if (!mxf_metadata_generic_sound_essence_descriptor_from_caps (ret, caps)) { + gst_mini_object_unref (GST_MINI_OBJECT_CAST (ret)); + return NULL; + } + *handler = mxf_alaw_write_func; md = g_new0 (ALawMappingData, 1); diff --git a/gst/mxf/mxfdv-dif.c b/gst/mxf/mxfdv-dif.c index eb76be9d4..508a69fe1 100644 --- a/gst/mxf/mxfdv-dif.c +++ b/gst/mxf/mxfdv-dif.c @@ -179,8 +179,11 @@ mxf_dv_dif_get_descriptor (GstPadTemplate * tmpl, GstCaps * caps, memcpy (&ret->parent.parent.essence_container, &dv_dif_essence_container_ul, 16); - mxf_metadata_generic_picture_essence_descriptor_from_caps (&ret->parent, - caps); + if (!mxf_metadata_generic_picture_essence_descriptor_from_caps (&ret->parent, + caps)) { + gst_mini_object_unref (GST_MINI_OBJECT_CAST (ret)); + return NULL; + } *handler = mxf_dv_dif_write_func; return (MXFMetadataFileDescriptor *) ret; diff --git a/gst/mxf/mxfjpeg2000.c b/gst/mxf/mxfjpeg2000.c index 9ff13f70a..1f76d76a7 100644 --- a/gst/mxf/mxfjpeg2000.c +++ b/gst/mxf/mxfjpeg2000.c @@ -232,11 +232,11 @@ mxf_jpeg2000_get_descriptor (GstPadTemplate * tmpl, GstCaps * caps, guint32 fourcc; s = gst_caps_get_structure (caps, 0); - if (strcmp (gst_structure_get_name (s), "image/x-jpc") != 0) - return NULL; - - if (!gst_structure_get_fourcc (s, "fourcc", &fourcc)) + if (strcmp (gst_structure_get_name (s), "image/x-jpc") != 0 || + !gst_structure_get_fourcc (s, "fourcc", &fourcc)) { + GST_ERROR ("Invalid caps %" GST_PTR_FORMAT, caps); return NULL; + } ret = (MXFMetadataRGBAPictureEssenceDescriptor *) gst_mini_object_new (MXF_TYPE_METADATA_RGBA_PICTURE_ESSENCE_DESCRIPTOR); @@ -268,8 +268,12 @@ mxf_jpeg2000_get_descriptor (GstPadTemplate * tmpl, GstCaps * caps, g_assert_not_reached (); } - mxf_metadata_generic_picture_essence_descriptor_from_caps (&ret->parent, - caps); + if (!mxf_metadata_generic_picture_essence_descriptor_from_caps (&ret->parent, + caps)) { + gst_mini_object_unref (GST_MINI_OBJECT_CAST (ret)); + return NULL; + } + *handler = mxf_jpeg2000_write_func; return (MXFMetadataFileDescriptor *) ret; diff --git a/gst/mxf/mxfmetadata.c b/gst/mxf/mxfmetadata.c index 29bd8a5f8..07c18b0f3 100644 --- a/gst/mxf/mxfmetadata.c +++ b/gst/mxf/mxfmetadata.c @@ -5317,23 +5317,24 @@ gst_greatest_common_divisor (gint a, gint b) return ABS (a); } -void mxf_metadata_generic_picture_essence_descriptor_from_caps - (MXFMetadataGenericPictureEssenceDescriptor * self, GstCaps * caps) -{ +gboolean + mxf_metadata_generic_picture_essence_descriptor_from_caps + (MXFMetadataGenericPictureEssenceDescriptor * self, GstCaps * caps) { gint par_n, par_d, gcd; gint width, height; gint fps_n, fps_d; MXFMetadataFileDescriptor *f = (MXFMetadataFileDescriptor *) self; GstStructure *s; - g_return_if_fail (MXF_IS_METADATA_GENERIC_PICTURE_ESSENCE_DESCRIPTOR (self)); - g_return_if_fail (GST_IS_CAPS (caps)); + g_return_val_if_fail (MXF_IS_METADATA_GENERIC_PICTURE_ESSENCE_DESCRIPTOR + (self), FALSE); + g_return_val_if_fail (GST_IS_CAPS (caps), FALSE); s = gst_caps_get_structure (caps, 0); if (!gst_structure_get_fraction (s, "framerate", &fps_n, &fps_d)) { GST_ERROR ("Invalid framerate"); - return; + return FALSE; } f->sample_rate.n = fps_n; f->sample_rate.d = fps_d; @@ -5341,7 +5342,7 @@ void mxf_metadata_generic_picture_essence_descriptor_from_caps if (!gst_structure_get_int (s, "width", &width) || !gst_structure_get_int (s, "height", &height)) { GST_ERROR ("Invalid width/height"); - return; + return FALSE; } self->stored_width = width; @@ -5358,6 +5359,8 @@ void mxf_metadata_generic_picture_essence_descriptor_from_caps gst_greatest_common_divisor (self->aspect_ratio.n, self->aspect_ratio.d); self->aspect_ratio.n /= gcd; self->aspect_ratio.d /= gcd; + + return TRUE; } @@ -5674,30 +5677,35 @@ void mxf_metadata_generic_sound_essence_descriptor_set_caps } } -void mxf_metadata_generic_sound_essence_descriptor_from_caps - (MXFMetadataGenericSoundEssenceDescriptor * self, GstCaps * caps) -{ +gboolean + mxf_metadata_generic_sound_essence_descriptor_from_caps + (MXFMetadataGenericSoundEssenceDescriptor * self, GstCaps * caps) { gint rate; gint channels; GstStructure *s; - g_return_if_fail (MXF_IS_METADATA_GENERIC_SOUND_ESSENCE_DESCRIPTOR (self)); - g_return_if_fail (GST_IS_CAPS (caps)); + g_return_val_if_fail (MXF_IS_METADATA_GENERIC_SOUND_ESSENCE_DESCRIPTOR (self), + FALSE); + g_return_val_if_fail (GST_IS_CAPS (caps), FALSE); s = gst_caps_get_structure (caps, 0); - if (!gst_structure_get_int (s, "rate", &rate)) { + if (!gst_structure_get_int (s, "rate", &rate) || rate == 0) { GST_WARNING ("No samplerate"); + return FALSE; } else { self->audio_sampling_rate.n = rate; self->audio_sampling_rate.d = 1; } - if (!gst_structure_get_int (s, "channels", &channels)) { + if (!gst_structure_get_int (s, "channels", &channels) || channels == 0) { GST_WARNING ("No channels"); + return FALSE; } else { self->channel_count = channels; } + + return TRUE; } diff --git a/gst/mxf/mxfmetadata.h b/gst/mxf/mxfmetadata.h index a29b5834e..bbdbc62ff 100644 --- a/gst/mxf/mxfmetadata.h +++ b/gst/mxf/mxfmetadata.h @@ -762,10 +762,10 @@ MXFMetadataTrackType mxf_metadata_track_identifier_parse (const MXFUL * track_id const MXFUL * mxf_metadata_track_identifier_get (MXFMetadataTrackType type); void mxf_metadata_generic_picture_essence_descriptor_set_caps (MXFMetadataGenericPictureEssenceDescriptor * self, GstCaps * caps); -void mxf_metadata_generic_picture_essence_descriptor_from_caps (MXFMetadataGenericPictureEssenceDescriptor * self, GstCaps * caps); +gboolean mxf_metadata_generic_picture_essence_descriptor_from_caps (MXFMetadataGenericPictureEssenceDescriptor * self, GstCaps * caps); void mxf_metadata_generic_sound_essence_descriptor_set_caps (MXFMetadataGenericSoundEssenceDescriptor * self, GstCaps * caps); -void mxf_metadata_generic_sound_essence_descriptor_from_caps (MXFMetadataGenericSoundEssenceDescriptor * self, GstCaps * caps); +gboolean mxf_metadata_generic_sound_essence_descriptor_from_caps (MXFMetadataGenericSoundEssenceDescriptor * self, GstCaps * caps); void mxf_descriptive_metadata_register (guint8 scheme, GType *types); MXFDescriptiveMetadata * mxf_descriptive_metadata_new (guint8 scheme, guint32 type, MXFPrimerPack * primer, guint64 offset, const guint8 * data, guint size); diff --git a/gst/mxf/mxfmpeg.c b/gst/mxf/mxfmpeg.c index 534b9fc8a..868aeb80a 100644 --- a/gst/mxf/mxfmpeg.c +++ b/gst/mxf/mxfmpeg.c @@ -900,8 +900,11 @@ mxf_mpeg_audio_get_descriptor (GstPadTemplate * tmpl, GstCaps * caps, if (strcmp (gst_structure_get_name (s), "audio/mpeg") == 0) { gint mpegversion; - if (!gst_structure_get_int (s, "mpegversion", &mpegversion)) + if (!gst_structure_get_int (s, "mpegversion", &mpegversion)) { + GST_ERROR ("Invalid caps %" GST_PTR_FORMAT, caps); + gst_mini_object_unref (GST_MINI_OBJECT_CAST (ret)); return NULL; + } if (mpegversion == 1) { gint layer = 0; @@ -943,13 +946,18 @@ mxf_mpeg_audio_get_descriptor (GstPadTemplate * tmpl, GstCaps * caps, if (!gst_structure_get_int (s, "rate", &rate)) { GST_ERROR ("Invalid rate"); + gst_mini_object_unref (GST_MINI_OBJECT_CAST (ret)); return NULL; } md->rate = rate; memcpy (&ret->parent.essence_container, &mpeg_essence_container_ul, 16); - mxf_metadata_generic_sound_essence_descriptor_from_caps (ret, caps); + if (!mxf_metadata_generic_sound_essence_descriptor_from_caps (ret, caps)) { + gst_mini_object_unref (GST_MINI_OBJECT_CAST (ret)); + return NULL; + } + *handler = mxf_mpeg_audio_write_func; return (MXFMetadataFileDescriptor *) ret; @@ -1157,8 +1165,11 @@ mxf_mpeg_video_get_descriptor (GstPadTemplate * tmpl, GstCaps * caps, if (strcmp (gst_structure_get_name (s), "video/mpeg") == 0) { gint mpegversion; - if (!gst_structure_get_int (s, "mpegversion", &mpegversion)) + if (!gst_structure_get_int (s, "mpegversion", &mpegversion)) { + GST_ERROR ("Invalid caps %" GST_PTR_FORMAT, caps); + gst_mini_object_unref (GST_MINI_OBJECT_CAST (ret)); return NULL; + } if (mpegversion == 1) { MXFMPEGEssenceType type = MXF_MPEG_ESSENCE_TYPE_VIDEO_MPEG2; @@ -1201,8 +1212,12 @@ mxf_mpeg_video_get_descriptor (GstPadTemplate * tmpl, GstCaps * caps, } - mxf_metadata_generic_picture_essence_descriptor_from_caps (&ret-> - parent.parent, caps); + if (!mxf_metadata_generic_picture_essence_descriptor_from_caps (&ret-> + parent.parent, caps)) { + gst_mini_object_unref (GST_MINI_OBJECT_CAST (ret)); + return NULL; + } + *handler = mxf_mpeg_video_write_func; return (MXFMetadataFileDescriptor *) ret; diff --git a/gst/mxf/mxfup.c b/gst/mxf/mxfup.c index 412a66224..a86a2c193 100644 --- a/gst/mxf/mxfup.c +++ b/gst/mxf/mxfup.c @@ -424,10 +424,20 @@ mxf_up_get_rgba_descriptor (GstPadTemplate * tmpl, GstCaps * caps, gst_caps_unref (intersection); } + if (md->fourcc == 0) { + GST_ERROR ("Invalid caps %" GST_PTR_FORMAT, caps); + gst_mini_object_unref (GST_MINI_OBJECT_CAST (ret)); + return NULL; + } + + memcpy (&ret->parent.parent.essence_container, &up_essence_container_ul, 16); - mxf_metadata_generic_picture_essence_descriptor_from_caps (&ret->parent, - caps); + if (!mxf_metadata_generic_picture_essence_descriptor_from_caps (&ret->parent, + caps)) { + gst_mini_object_unref (GST_MINI_OBJECT_CAST (ret)); + return NULL; + } md->width = ret->parent.stored_width; md->height = ret->parent.stored_height; @@ -469,10 +479,19 @@ mxf_up_get_cdci_descriptor (GstPadTemplate * tmpl, GstCaps * caps, gst_caps_unref (intersection); } + if (md->fourcc == 0) { + GST_ERROR ("Invalid caps %" GST_PTR_FORMAT, caps); + gst_mini_object_unref (GST_MINI_OBJECT_CAST (ret)); + return NULL; + } + memcpy (&ret->parent.parent.essence_container, &up_essence_container_ul, 16); - mxf_metadata_generic_picture_essence_descriptor_from_caps (&ret->parent, - caps); + if (!mxf_metadata_generic_picture_essence_descriptor_from_caps (&ret->parent, + caps)) { + gst_mini_object_unref (GST_MINI_OBJECT_CAST (ret)); + return NULL; + } md->width = ret->parent.stored_width; md->height = ret->parent.stored_height; diff --git a/gst/mxf/mxfvc3.c b/gst/mxf/mxfvc3.c index e3e7bc522..ec14734ea 100644 --- a/gst/mxf/mxfvc3.c +++ b/gst/mxf/mxfvc3.c @@ -178,16 +178,22 @@ mxf_vc3_get_descriptor (GstPadTemplate * tmpl, GstCaps * caps, GstStructure *s; s = gst_caps_get_structure (caps, 0); - if (strcmp (gst_structure_get_name (s), "video/x-dnxhd") != 0) + if (strcmp (gst_structure_get_name (s), "video/x-dnxhd") != 0) { + GST_ERROR ("Invalid caps %" GST_PTR_FORMAT, caps); return NULL; + } ret = (MXFMetadataCDCIPictureEssenceDescriptor *) gst_mini_object_new (MXF_TYPE_METADATA_CDCI_PICTURE_ESSENCE_DESCRIPTOR); memcpy (&ret->parent.parent.essence_container, &vc3_essence_container_ul, 16); - mxf_metadata_generic_picture_essence_descriptor_from_caps (&ret->parent, - caps); + if (!mxf_metadata_generic_picture_essence_descriptor_from_caps (&ret->parent, + caps)) { + gst_mini_object_unref (GST_MINI_OBJECT_CAST (ret)); + return NULL; + } + *handler = mxf_vc3_write_func; return (MXFMetadataFileDescriptor *) ret; |