]> git.sesse.net Git - mlt/blobdiff - src/framework/mlt_repository.c
Add mlt_audio_u8 (sourceforce-182).
[mlt] / src / framework / mlt_repository.c
index 3d75bcbe8e68cab98e08f120f698fb515919949c..e5e5e79388458f3d31fd46f22edafb8d9fcf51a6 100644 (file)
 #include "mlt_properties.h"
 #include "mlt_tokeniser.h"
 #include "mlt_log.h"
+#include "mlt_factory.h"
 
 #include <stdio.h>
 #include <stdlib.h>
 #include <dlfcn.h>
 #include <string.h>
+#include <limits.h>
+#include <dirent.h>
+#include <sys/stat.h>
+
+/** the default subdirectory of the datadir for holding presets */
+#define PRESETS_DIR "/presets"
 
 /** \brief Repository class
  *
@@ -63,7 +70,7 @@ mlt_repository mlt_repository_init( const char *directory )
                return NULL;
 
        // Construct the repository
-       mlt_repository self = calloc( sizeof( struct mlt_repository_s ), 1 );
+       mlt_repository self = calloc( 1, sizeof( struct mlt_repository_s ));
        mlt_properties_init( &self->parent, self );
        self->consumers = mlt_properties_new();
        self->filters = mlt_properties_new();
@@ -426,3 +433,74 @@ mlt_properties mlt_repository_languages( mlt_repository self )
        mlt_properties_set_data( &self->parent, "languages", languages, 0, ( mlt_destructor )mlt_properties_close, NULL );
        return languages;
 }
+
+static void list_presets( mlt_properties properties, const char *path, const char *dirname )
+{
+       DIR *dir = opendir( dirname );
+
+       if ( dir )
+       {
+               struct dirent *de = readdir( dir );
+               char fullname[ PATH_MAX ];
+
+               while ( de != NULL )
+               {
+                       if ( de->d_name[0] != '.' && de->d_name[strlen( de->d_name ) - 1] != '~' )
+                       {
+                               struct stat info;
+
+                               snprintf( fullname, sizeof(fullname), "%s/%s", dirname, de->d_name );
+                               stat( fullname, &info );
+                               if ( S_ISDIR( info.st_mode ) )
+                               {
+                                       // recurse into subdirectories
+                                       char sub[ PATH_MAX ];
+                                       if ( path )
+                                               snprintf( sub, sizeof(sub), "%s/%s", path, de->d_name );
+                                       else
+                                               strncpy( sub, de->d_name, sizeof(sub) );
+                                       list_presets( properties, sub, fullname );
+                               }
+                               else
+                               {
+                                       // load the preset
+                                       mlt_properties preset = mlt_properties_load( fullname );
+                                       if ( preset && mlt_properties_count( preset ) )
+                                       {
+                                               snprintf( fullname, 1024, "%s/%s", path, de->d_name );
+                                               mlt_properties_set_data( properties, fullname, preset, 0, (mlt_destructor) mlt_properties_close, NULL );
+                                       }
+                               }
+                       }
+                       de = readdir( dir );
+               }
+               closedir( dir );
+       }
+}
+
+/** Get the list of presets.
+ *
+ * \public \memberof mlt_repository_s
+ * \return a properties list of all the presets
+ */
+
+mlt_properties mlt_repository_presets( )
+{
+       mlt_properties result = mlt_properties_new();
+       char *path = getenv( "MLT_PRESETS_PATH" );
+
+       if ( path )
+       {
+               path = strdup( path );
+       }
+       else
+       {
+               path = malloc( strlen( mlt_environment( "MLT_DATA" ) ) + strlen( PRESETS_DIR ) + 1 );
+               strcpy( path, mlt_environment( "MLT_DATA" ) );
+               strcat( path, PRESETS_DIR );
+       }
+       list_presets( result, NULL, path );
+       free( path );
+
+       return result;
+}