mxfmux: guard against dividing by 0

Use a placeholder value in that case, it's better than crashing.

Coverity 1139697
This commit is contained in:
Vincent Penquerc'h 2014-04-21 10:07:06 +01:00
parent 467d9267a2
commit d111287995

View file

@ -311,13 +311,13 @@ gst_mxf_mux_event_caps (GstPad * pad, GstCaps * caps)
for (i = 0; i < mux->preface->content_storage->n_packages; i++) {
MXFMetadataSourcePackage *package;
if (!MXF_IS_METADATA_SOURCE_PACKAGE (mux->preface->content_storage->
packages[i]))
if (!MXF_IS_METADATA_SOURCE_PACKAGE (mux->preface->
content_storage->packages[i]))
continue;
package =
MXF_METADATA_SOURCE_PACKAGE (mux->preface->content_storage->
packages[i]);
MXF_METADATA_SOURCE_PACKAGE (mux->preface->
content_storage->packages[i]);
if (!package->descriptor)
continue;
@ -709,8 +709,8 @@ gst_mxf_mux_create_metadata (GstMXFMux * mux)
if (p->parent.n_tracks == 1) {
p->descriptor = (MXFMetadataGenericDescriptor *) cpad->descriptor;
} else {
MXF_METADATA_MULTIPLE_DESCRIPTOR (p->descriptor)->
sub_descriptors[n] =
MXF_METADATA_MULTIPLE_DESCRIPTOR (p->
descriptor)->sub_descriptors[n] =
(MXFMetadataGenericDescriptor *) cpad->descriptor;
}
@ -889,9 +889,12 @@ gst_mxf_mux_create_metadata (GstMXFMux * mux)
&sequence->data_definition, 16);
component->start_timecode = 0;
component->rounded_timecode_base =
(((gdouble) track->edit_rate.n) / ((gdouble) track->edit_rate.d) +
0.5);
if (track->edit_rate.d == 0)
component->rounded_timecode_base = 1;
else
component->rounded_timecode_base =
(((gdouble) track->edit_rate.n) /
((gdouble) track->edit_rate.d) + 0.5);
/* TODO: drop frame */
}
@ -935,8 +938,8 @@ gst_mxf_mux_create_metadata (GstMXFMux * mux)
g_new0 (MXFMetadataEssenceContainerData *, 1);
cstorage->essence_container_data[0] = (MXFMetadataEssenceContainerData *)
g_object_new (MXF_TYPE_METADATA_ESSENCE_CONTAINER_DATA, NULL);
mxf_uuid_init (&MXF_METADATA_BASE (cstorage->
essence_container_data[0])->instance_uid, mux->metadata);
mxf_uuid_init (&MXF_METADATA_BASE (cstorage->essence_container_data[0])->
instance_uid, mux->metadata);
g_hash_table_insert (mux->metadata,
&MXF_METADATA_BASE (cstorage->essence_container_data[0])->instance_uid,
cstorage->essence_container_data[0]);
@ -1259,22 +1262,23 @@ gst_mxf_mux_handle_eos (GstMXFMux * mux)
/* Update durations */
cpad->source_track->parent.sequence->duration = cpad->pos;
MXF_METADATA_SOURCE_CLIP (cpad->source_track->parent.sequence->
structural_components[0])->parent.duration = cpad->pos;
MXF_METADATA_SOURCE_CLIP (cpad->source_track->parent.
sequence->structural_components[0])->parent.duration = cpad->pos;
for (i = 0; i < mux->preface->content_storage->packages[0]->n_tracks; i++) {
MXFMetadataTimelineTrack *track;
if (!MXF_IS_METADATA_TIMELINE_TRACK (mux->preface->content_storage->
packages[0]->tracks[i])
|| !MXF_IS_METADATA_SOURCE_CLIP (mux->preface->content_storage->
packages[0]->tracks[i]->sequence->structural_components[0]))
if (!MXF_IS_METADATA_TIMELINE_TRACK (mux->preface->
content_storage->packages[0]->tracks[i])
|| !MXF_IS_METADATA_SOURCE_CLIP (mux->preface->
content_storage->packages[0]->tracks[i]->sequence->
structural_components[0]))
continue;
track =
MXF_METADATA_TIMELINE_TRACK (mux->preface->content_storage->
packages[0]->tracks[i]);
if (MXF_METADATA_SOURCE_CLIP (track->parent.sequence->
structural_components[0])->source_track_id ==
MXF_METADATA_TIMELINE_TRACK (mux->preface->
content_storage->packages[0]->tracks[i]);
if (MXF_METADATA_SOURCE_CLIP (track->parent.
sequence->structural_components[0])->source_track_id ==
cpad->source_track->parent.track_id) {
track->parent.sequence->structural_components[0]->duration = cpad->pos;
track->parent.sequence->duration = cpad->pos;
@ -1285,8 +1289,8 @@ gst_mxf_mux_handle_eos (GstMXFMux * mux)
/* Update timecode track duration */
{
MXFMetadataTimelineTrack *track =
MXF_METADATA_TIMELINE_TRACK (mux->preface->content_storage->
packages[0]->tracks[0]);
MXF_METADATA_TIMELINE_TRACK (mux->preface->
content_storage->packages[0]->tracks[0]);
MXFMetadataSequence *sequence = track->parent.sequence;
MXFMetadataTimecodeComponent *component =
MXF_METADATA_TIMECODE_COMPONENT (sequence->structural_components[0]);