]> git.sesse.net Git - mlt/blobdiff - src/framework/mlt_service.c
Workaround Win32 apps sometimes hang on exit.
[mlt] / src / framework / mlt_service.c
index dfaad57294ffbaccce771a0b2e119686ca8aefd4..f15ec46af90ff7d087d0ceb775b8d589dd2c7b09 100644 (file)
@@ -87,7 +87,7 @@ int mlt_service_init( mlt_service self, void *child )
        self->child = child;
 
        // Generate local space
-       self->local = calloc( sizeof( mlt_service_base ), 1 );
+       self->local = calloc( 1, sizeof( mlt_service_base ) );
 
        // Associate the methods
        self->get_frame = service_get_frame;
@@ -265,7 +265,7 @@ int mlt_service_connect_producer( mlt_service self, mlt_service producer, int in
 
 /** Disconnect a service from its consumer.
  *
- * \public \memberof mlt_service_s
+ * \private \memberof mlt_service_s
  * \param self a service
  */
 
@@ -521,6 +521,19 @@ static void mlt_service_filter_changed( mlt_service owner, mlt_service self )
        mlt_events_fire( MLT_SERVICE_PROPERTIES( self ), "service-changed", NULL );
 }
 
+/** The property-changed event handler.
+ *
+ * \private \memberof mlt_service_s
+ * \param owner ignored
+ * \param self the service on which the "property-changed" event is fired
+ * \param name the name of the property that changed
+ */
+
+static void mlt_service_filter_property_changed( mlt_service owner, mlt_service self, char *name )
+{
+    mlt_events_fire( MLT_SERVICE_PROPERTIES( self ), "property-changed", name, NULL );
+}
+
 /** Attach a filter.
  *
  * \public \memberof mlt_service_s
@@ -559,7 +572,7 @@ int mlt_service_attach( mlt_service self, mlt_filter filter )
                                mlt_events_fire( properties, "service-changed", NULL );
                                mlt_events_fire( props, "service-changed", NULL );
                                mlt_events_listen( props, self, "service-changed", ( mlt_listener )mlt_service_filter_changed );
-                               mlt_events_listen( props, self, "property-changed", ( mlt_listener )mlt_service_filter_changed );
+                               mlt_events_listen( props, self, "property-changed", ( mlt_listener )mlt_service_filter_property_changed );
                        }
                        else
                        {
@@ -605,7 +618,66 @@ int mlt_service_detach( mlt_service self, mlt_filter filter )
        return error;
 }
 
-/** Retrieve a filter.
+/** Get the number of filters attached.
+ *
+ * \public \memberof mlt_service_s
+ * \param self a service
+ * \return the number of attached filters or -1 if there was an error
+ */
+
+int mlt_service_filter_count( mlt_service self )
+{
+       int result = -1;
+       if ( self )
+       {
+               mlt_service_base *base = self->local;
+               result = base->filter_count;
+       }
+       return result;
+}
+
+/** Reorder the attached filters.
+ *
+ * \public \memberof mlt_service_s
+ * \param self a service
+ * \param from the current index value of the filter to move
+ * \param to the new index value for the filter specified in \p from
+ * \return true if there was an error
+ */
+
+int mlt_service_move_filter( mlt_service self, int from, int to )
+{
+       int error = -1;
+       if ( self )
+       {
+               mlt_service_base *base = self->local;
+               if ( from < 0 ) from = 0;
+               if ( from >= base->filter_count ) from = base->filter_count - 1;
+               if ( to < 0 ) to = 0;
+               if ( to >= base->filter_count ) to = base->filter_count - 1;
+               if ( from != to && base->filter_count > 1 )
+               {
+                       mlt_filter filter = base->filters[from];
+                       int i;
+                       if ( from > to )
+                       {
+                               for ( i = from; i > to; i-- )
+                                       base->filters[i] = base->filters[i - 1];
+                       }
+                       else
+                       {
+                               for ( i = from; i < to; i++ )
+                                       base->filters[i] = base->filters[i + 1];
+                       }
+                       base->filters[to] = filter;
+                       mlt_events_fire( MLT_SERVICE_PROPERTIES(self), "service-changed", NULL );
+                       error = 0;
+               }
+       }
+       return error;
+}
+
+/** Retrieve an attached filter.
  *
  * \public \memberof mlt_service_s
  * \param self a service
@@ -637,6 +709,18 @@ mlt_profile mlt_service_profile( mlt_service self )
        return self? mlt_properties_get_data( MLT_SERVICE_PROPERTIES( self ), "_profile", NULL ) : NULL;
 }
 
+/** Set the profile for a service.
+ *
+ * \public \memberof mlt_service_s
+ * \param self a service
+ * \param profile the profile to set onto the service
+ */
+
+void mlt_service_set_profile( mlt_service self, mlt_profile profile )
+{
+    mlt_properties_set_data( MLT_SERVICE_PROPERTIES( self ), "_profile", profile, 0, NULL, NULL );
+}
+
 /** Destroy a service.
  *
  * \public \memberof mlt_service_s