diff --git a/ges/ges-pitivi-formatter.c b/ges/ges-pitivi-formatter.c index c7d80a9ea1..c78f11b4f0 100644 --- a/ges/ges-pitivi-formatter.c +++ b/ges/ges-pitivi-formatter.c @@ -91,17 +91,6 @@ struct _GESPitiviFormatterPrivate guint nb_sources; }; -/* Memory freeing functions */ -static void -free_src_map (SrcMapping * srcmap) -{ - g_free (srcmap->id); - gst_object_unref (srcmap->clip); - g_list_foreach (srcmap->track_element_ids, (GFunc) g_free, NULL); - g_list_free (srcmap->track_element_ids); - g_slice_free (SrcMapping, srcmap); -} - static void list_table_destroyer (gpointer key, gpointer value, void *unused) { @@ -147,329 +136,6 @@ write_int_attribute (xmlTextWriterPtr writer, guint64 nb, const gchar * attr, g_free (str); } -static void -save_track_elements (xmlTextWriterPtr writer, GList * source_list, - GESTrackType type, gint * id) -{ - GList *tmp, *tmp_tck; - gchar *bin_desc; - xmlTextWriterStartElement (writer, BAD_CAST "track-objects"); - - GST_DEBUG ("Saving track elements"); - for (tmp = source_list; tmp; tmp = tmp->next) { - SrcMapping *srcmap; - GESClip *clip; - guint i, j; - guint64 inpoint, duration, start; - - srcmap = (SrcMapping *) tmp->data; - clip = srcmap->clip; - - /* Save track associated objects */ - for (tmp_tck = GES_CONTAINER_CHILDREN (clip); tmp_tck; - tmp_tck = tmp_tck->next) { - xmlChar *cast; - GESTrackElement *trackelement = GES_TRACK_ELEMENT (tmp_tck->data); - GESTrack *track = ges_track_element_get_track (trackelement); - const gchar *active, *locked; - - if (!track) { - GST_WARNING ("Track element %p not in a track yet", trackelement); - continue; - } - - /* We are serializing this track type */ - if (track->type != type) - continue; - - /* Save properties */ - /* Set important properties */ - xmlTextWriterStartElement (writer, BAD_CAST "track-object"); - - active = - ges_track_element_is_active (trackelement) ? "(bool)True" : - "(bool)False"; - xmlTextWriterWriteAttribute (writer, BAD_CAST "active", BAD_CAST active); - locked = - ges_track_element_is_locked (trackelement) ? "(bool)True" : - "(bool)False"; - xmlTextWriterWriteAttribute (writer, BAD_CAST "locked", BAD_CAST locked); - - /* Here the priority correspond to the layer priority */ - write_int_attribute (writer, srcmap->priority, "priority", "(int)"); - g_object_get (G_OBJECT (trackelement), "duration", &duration, "start", - &start, "in-point", &inpoint, NULL); - write_int_attribute (writer, duration, "duration", "(gint64)"); - write_int_attribute (writer, start, "start", "(gint64)"); - write_int_attribute (writer, inpoint, "in_point", "(gint64)"); - - cast = xmlXPathCastNumberToString (*id); - xmlTextWriterWriteAttribute (writer, BAD_CAST "id", BAD_CAST cast); - xmlFree (cast); - - if (GES_IS_BASE_EFFECT (trackelement)) { - GParamSpec **pspecs, *spec; - gchar *serialized, *concatenated; - guint n_props = 0; - - xmlTextWriterWriteAttribute (writer, BAD_CAST "type", - BAD_CAST "pitivi.timeline.track.TrackEffect"); - - g_object_get (trackelement, "bin-description", &bin_desc, NULL); - xmlTextWriterStartElement (writer, BAD_CAST "effect"); - xmlTextWriterStartElement (writer, BAD_CAST "factory"); - xmlTextWriterWriteAttribute (writer, BAD_CAST "name", - BAD_CAST bin_desc); - xmlTextWriterEndElement (writer); - xmlTextWriterStartElement (writer, BAD_CAST "gst-element-properties"); - - pspecs = - ges_track_element_list_children_properties (trackelement, &n_props); - - j = 0; - - while (j < n_props) { - GValue val = { 0 }; - - spec = pspecs[j]; - g_value_init (&val, spec->value_type); - ges_track_element_get_child_property_by_pspec (trackelement, spec, - &val); - serialized = gst_value_serialize (&val); - if (!g_strcmp0 (spec->name, (gchar *) "preset")) { - concatenated = - g_strconcat ("(GEnum)", - xmlXPathCastNumberToString ((g_value_get_enum (&val))), NULL); - xmlTextWriterWriteAttribute (writer, BAD_CAST spec->name, - BAD_CAST concatenated); - } else { - concatenated = - g_strconcat ("(", g_type_name (spec->value_type), ")", - serialized, NULL); - xmlTextWriterWriteAttribute (writer, BAD_CAST spec->name, - BAD_CAST concatenated); - } - j++; - } - - xmlTextWriterEndElement (writer); - - for (i = 0; i < n_props; i++) { - g_param_spec_unref (pspecs[i]); - } - - g_free (pspecs); - - } else { - xmlTextWriterWriteAttribute (writer, BAD_CAST "type", - BAD_CAST "pitivi.timeline.track.SourceTrackObject"); - - xmlTextWriterStartElement (writer, BAD_CAST "factory-ref"); - xmlTextWriterWriteAttribute (writer, BAD_CAST "id", - BAD_CAST srcmap->id); - } - xmlTextWriterEndElement (writer); - xmlTextWriterEndElement (writer); - - /* We add effects at the end of the trackelement list */ - if (GES_IS_BASE_EFFECT (trackelement)) { - srcmap->track_element_ids = g_list_append (srcmap->track_element_ids, - xmlXPathCastNumberToString (*id)); - } else { - srcmap->track_element_ids = g_list_prepend (srcmap->track_element_ids, - xmlXPathCastNumberToString (*id)); - } - *id = *id + 1; - } - } - - xmlTextWriterEndElement (writer); -} - -static void -save_tracks (GESTimeline * timeline, xmlTextWriterPtr writer, - GList * source_list) -{ - GList *tracks, *tmp; - gint id = 0; - - xmlTextWriterStartElement (writer, BAD_CAST "timeline"); - xmlTextWriterStartElement (writer, BAD_CAST "tracks"); - - GST_DEBUG ("Saving tracks"); - - tracks = ges_timeline_get_tracks (timeline); - for (tmp = tracks; tmp; tmp = tmp->next) { - gchar *caps; - GESTrackType type; - - GESTrack *track = GES_TRACK (tmp->data); - - xmlTextWriterStartElement (writer, BAD_CAST "track"); - xmlTextWriterStartElement (writer, BAD_CAST "stream"); - - /* Serialize track type and caps */ - g_object_get (G_OBJECT (track), "track-type", &type, NULL); - caps = gst_caps_to_string (ges_track_get_caps (track)); - xmlTextWriterWriteAttribute (writer, BAD_CAST "caps", BAD_CAST caps); - g_free (caps); - - if (type == GES_TRACK_TYPE_AUDIO) { - xmlTextWriterWriteAttribute (writer, BAD_CAST "type", - BAD_CAST "pitivi.stream.AudioStream"); - xmlTextWriterEndElement (writer); - } else if (type == GES_TRACK_TYPE_VIDEO) { - xmlTextWriterWriteAttribute (writer, BAD_CAST "type", - BAD_CAST "pitivi.stream.VideoStream"); - xmlTextWriterEndElement (writer); - } else { - GST_WARNING ("Track type %i not supported", type); - - continue; - } - - save_track_elements (writer, source_list, type, &id); - xmlTextWriterEndElement (writer); - } - - g_list_foreach (tracks, (GFunc) gst_object_unref, NULL); - g_list_free (tracks); - xmlTextWriterEndElement (writer); -} - -static void -write_source (gchar * uri, gchar * id, xmlTextWriterPtr writer) -{ - xmlTextWriterStartElement (writer, BAD_CAST "source"); - - xmlTextWriterWriteAttribute (writer, BAD_CAST "filename", BAD_CAST uri); - xmlTextWriterWriteAttribute (writer, BAD_CAST "id", BAD_CAST id); - xmlTextWriterEndElement (writer); -} - -static GList * -save_sources (GESPitiviFormatter * formatter, GList * layers, - xmlTextWriterPtr writer) -{ - GList *clips, *tmp, *tmplayer; - GESTimelineLayer *layer; - GESPitiviFormatterPrivate *priv = formatter->priv; - - GList *source_list = NULL; - - GST_DEBUG ("Saving sources"); - - g_hash_table_foreach (priv->saving_source_table, (GHFunc) write_source, - writer); - - for (tmplayer = layers; tmplayer; tmplayer = tmplayer->next) { - layer = GES_TIMELINE_LAYER (tmplayer->data); - - clips = ges_timeline_layer_get_clips (layer); - for (tmp = clips; tmp; tmp = tmp->next) { - SrcMapping *srcmap = g_slice_new0 (SrcMapping); - GESClip *clip; - gchar *uriclip_uri; - clip = tmp->data; - - if (GES_IS_URI_CLIP (clip)) { - - uriclip_uri = (gchar *) ges_uri_clip_get_uri (GES_URI_CLIP (clip)); - - if (!g_hash_table_lookup (priv->saving_source_table, uriclip_uri)) { - gchar *strid = g_strdup_printf ("%i", priv->nb_sources); - - g_hash_table_insert (priv->saving_source_table, - g_strdup (uriclip_uri), strid); - write_source (uriclip_uri, strid, writer); - priv->nb_sources++; - } - - srcmap->id = - g_strdup (g_hash_table_lookup (priv->saving_source_table, - uriclip_uri)); - srcmap->clip = gst_object_ref (clip); - srcmap->priority = ges_timeline_layer_get_priority (layer); - /* We fill up the track_element_ids in save_track_elements */ - source_list = g_list_append (source_list, srcmap); - } - } - g_list_foreach (clips, (GFunc) gst_object_unref, NULL); - g_list_free (clips); - gst_object_unref (G_OBJECT (layer)); - } - - return source_list; -} - -static void -save_clips (xmlTextWriterPtr writer, GList * list) -{ - GList *tmp, *track_element_ids; - - xmlTextWriterStartElement (writer, BAD_CAST "timeline-objects"); - - GST_DEBUG ("Saving clips"); - - for (tmp = list; tmp; tmp = tmp->next) { - - SrcMapping *srcmap = (SrcMapping *) tmp->data; - - xmlTextWriterStartElement (writer, BAD_CAST "timeline-object"); - xmlTextWriterStartElement (writer, BAD_CAST "factory-ref"); - xmlTextWriterWriteAttribute (writer, BAD_CAST "id", BAD_CAST srcmap->id); - xmlTextWriterEndElement (writer); - xmlTextWriterStartElement (writer, BAD_CAST "track-object-refs"); - - for (track_element_ids = srcmap->track_element_ids; track_element_ids; - track_element_ids = track_element_ids->next) { - xmlTextWriterStartElement (writer, BAD_CAST "track-object-ref"); - xmlTextWriterWriteAttribute (writer, BAD_CAST "id", - BAD_CAST track_element_ids->data); - xmlTextWriterEndElement (writer); - } - xmlTextWriterEndElement (writer); - xmlTextWriterEndElement (writer); - } - xmlTextWriterEndElement (writer); -} - -static gboolean -save_pitivi_timeline_to_uri (GESFormatter * formatter, - GESTimeline * timeline, const gchar * uri, gboolean overwrite, - GError ** error) -{ - xmlTextWriterPtr writer; - GList *list = NULL, *layers = NULL; - - writer = xmlNewTextWriterFilename (uri, 0); - xmlTextWriterSetIndent (writer, 1); - xmlTextWriterStartElement (writer, BAD_CAST "pitivi"); - xmlTextWriterWriteAttribute (writer, BAD_CAST "formatter", BAD_CAST "GES"); - /* */ - xmlTextWriterWriteAttribute (writer, BAD_CAST "version", BAD_CAST VERSION); - - xmlTextWriterStartElement (writer, BAD_CAST "factories"); - xmlTextWriterStartElement (writer, BAD_CAST "sources"); - - layers = ges_timeline_get_layers (timeline); - list = save_sources (GES_PITIVI_FORMATTER (formatter), layers, writer); - - xmlTextWriterEndElement (writer); - xmlTextWriterEndElement (writer); - - save_tracks (timeline, writer, list); - save_clips (writer, list); - xmlTextWriterEndDocument (writer); - xmlFreeTextWriter (writer); - - g_list_free (layers); - g_list_foreach (list, (GFunc) free_src_map, NULL); - g_list_free (list); - - return TRUE; -} - /* Project loading functions */ /* Return: a GHashTable containing: @@ -1120,7 +786,7 @@ ges_pitivi_formatter_class_init (GESPitiviFormatterClass * klass) g_type_class_add_private (klass, sizeof (GESPitiviFormatterPrivate)); formatter_klass->can_load_uri = pitivi_can_load_uri; - formatter_klass->save_to_uri = save_pitivi_timeline_to_uri; + formatter_klass->save_to_uri = NULL; formatter_klass->load_from_uri = load_pitivi_file_from_uri; object_class->finalize = ges_pitivi_formatter_finalize;