mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-11-26 19:51:11 +00:00
mxfmux: Fix some memory leaks, improve debugging and handle errors better
This commit is contained in:
parent
ddced37a8b
commit
effb5786da
9 changed files with 113 additions and 48 deletions
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue