From: ddennedy Date: Sun, 15 Jul 2007 01:19:30 +0000 (+0000) Subject: Added new profiles system: mlt_profile, MLT_PROFILE, and profiles documents. X-Git-Url: https://git.sesse.net/?a=commitdiff_plain;h=40b169c095486ba1b868486eb98a47c41f36ce8c;p=mlt Added new profiles system: mlt_profile, MLT_PROFILE, and profiles documents. git-svn-id: https://mlt.svn.sourceforge.net/svnroot/mlt/trunk/mlt@1008 d19143bc-622f-0410-bfdd-b5b2a6649095 --- diff --git a/ChangeLog b/ChangeLog index 9a74663a..6aff12f2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,7 @@ $Id$ +USING svn log NOW + 2007-04-09 Dan Dennedy Cleanup copyrights and attributions, and move Jean-Baptiste's services to a new kdenlive module. diff --git a/Makefile b/Makefile index 2c4766e0..5d127b43 100644 --- a/Makefile +++ b/Makefile @@ -4,7 +4,8 @@ SUBDIRS = src/framework \ src/miracle \ src/humperdink \ src/albino \ - src/modules + src/modules \ + profiles all clean: list='$(SUBDIRS)'; \ @@ -55,4 +56,5 @@ uninstall: dist: [ -d "mlt-$(version)" ] && rm -rf "mlt-$(version)" || echo svn export . "mlt-$(version)" + svn log > "mlt-$(version)/ChangeLog" tar -cvzf "mlt-$(version).tar.gz" "mlt-$(version)" diff --git a/configure b/configure index 66189a91..fe1423d7 100755 --- a/configure +++ b/configure @@ -113,7 +113,7 @@ export build_dir=`dirname $0` export prefix=/usr/local export libdir="" export help=0 -export version=0.2.3 +export version=0.2.4 export debug=true export mmx=true export gpl=false diff --git a/profiles/Makefile b/profiles/Makefile new file mode 100644 index 00000000..6dee6502 --- /dev/null +++ b/profiles/Makefile @@ -0,0 +1,14 @@ +include ../config.mak + +all: + +depend: + +distclean: + +clean: + +install: all + install -d $(DESTDIR)$(prefix)/share/mlt/profiles + install -m 644 * $(DESTDIR)$(prefix)/share/mlt/profiles + rm -f $(DESTDIR)$(prefix)/share/mlt/profiles/{*~,Makefile} diff --git a/profiles/atsc_wide_1080i b/profiles/atsc_wide_1080i new file mode 100644 index 00000000..889379b4 --- /dev/null +++ b/profiles/atsc_wide_1080i @@ -0,0 +1,10 @@ +name=ATSC Widescreen 1080i +frame_rate_num=30000 +frame_rate_den=1001 +width=1920 +height=1080 +progressive=0 +sample_aspect_num=1 +sample_aspect_den=1 +display_aspect_num=16 +display_aspect_den=9 diff --git a/profiles/atsc_wide_720p b/profiles/atsc_wide_720p new file mode 100644 index 00000000..5558016c --- /dev/null +++ b/profiles/atsc_wide_720p @@ -0,0 +1,10 @@ +name=ATSC Widescreen 720p +frame_rate_num=30000 +frame_rate_den=1001 +width=1280 +height=720 +progressive=1 +sample_aspect_num=1 +sample_aspect_den=1 +display_aspect_num=16 +display_aspect_den=9 diff --git a/profiles/cif_ntsc b/profiles/cif_ntsc new file mode 100644 index 00000000..f4e8491b --- /dev/null +++ b/profiles/cif_ntsc @@ -0,0 +1,10 @@ +name=CIF NTSC +frame_rate_num=30000 +frame_rate_den=1001 +width=352 +height=288 +progressive=1 +sample_aspect_num=10 +sample_aspect_den=11 +display_aspect_num=4 +display_aspect_den=3 diff --git a/profiles/cif_pal b/profiles/cif_pal new file mode 100644 index 00000000..dafa2423 --- /dev/null +++ b/profiles/cif_pal @@ -0,0 +1,10 @@ +name=CIF PAL +frame_rate_num=25 +frame_rate_den=1 +width=352 +height=288 +progressive=1 +sample_aspect_num=59 +sample_aspect_den=54 +display_aspect_num=4 +display_aspect_den=3 diff --git a/profiles/cvd_ntsc b/profiles/cvd_ntsc new file mode 100644 index 00000000..af844c4b --- /dev/null +++ b/profiles/cvd_ntsc @@ -0,0 +1,10 @@ +name=CVD NTSC +frame_rate_num=30000 +frame_rate_den=1001 +width=352 +height=480 +progressive=0 +sample_aspect_num=20 +sample_aspect_den=11 +display_aspect_num=4 +display_aspect_den=3 diff --git a/profiles/cvd_pal b/profiles/cvd_pal new file mode 100644 index 00000000..44cd5bc1 --- /dev/null +++ b/profiles/cvd_pal @@ -0,0 +1,10 @@ +name=CVD PAL +frame_rate_num=25 +frame_rate_den=1 +width=352 +height=576 +progressive=0 +sample_aspect_num=59 +sample_aspect_den=27 +display_aspect_num=4 +display_aspect_den=3 diff --git a/profiles/dv_ntsc b/profiles/dv_ntsc new file mode 100644 index 00000000..68cf870b --- /dev/null +++ b/profiles/dv_ntsc @@ -0,0 +1,10 @@ +name=DV NTSC +frame_rate_num=30000 +frame_rate_den=1001 +width=720 +height=480 +progressive=0 +sample_aspect_num=10 +sample_aspect_den=11 +display_aspect_num=4 +display_aspect_den=3 diff --git a/profiles/dv_ntsc_wide b/profiles/dv_ntsc_wide new file mode 100644 index 00000000..cc6879ff --- /dev/null +++ b/profiles/dv_ntsc_wide @@ -0,0 +1,10 @@ +name=DV NTSC Widescreen +frame_rate_num=30000 +frame_rate_den=1001 +width=720 +height=480 +progressive=0 +sample_aspect_num=40 +sample_aspect_den=33 +display_aspect_num=16 +display_aspect_den=9 diff --git a/profiles/dv_pal b/profiles/dv_pal new file mode 100644 index 00000000..32f72c38 --- /dev/null +++ b/profiles/dv_pal @@ -0,0 +1,10 @@ +name=DV PAL +frame_rate_num=25 +frame_rate_den=1 +width=720 +height=576 +progressive=0 +sample_aspect_num=59 +sample_aspect_den=54 +display_aspect_num=4 +display_aspect_den=3 diff --git a/profiles/dv_pal_wide b/profiles/dv_pal_wide new file mode 100644 index 00000000..313f12e6 --- /dev/null +++ b/profiles/dv_pal_wide @@ -0,0 +1,10 @@ +name=DV PAL Widescreen +frame_rate_num=25 +frame_rate_den=1 +width=720 +height=576 +progressive=0 +sample_aspect_num=118 +sample_aspect_den=81 +display_aspect_num=16 +display_aspect_den=9 diff --git a/profiles/hdv_1080_ntsc b/profiles/hdv_1080_ntsc new file mode 100644 index 00000000..61e409b5 --- /dev/null +++ b/profiles/hdv_1080_ntsc @@ -0,0 +1,10 @@ +name=HDV 1080i NTSC +frame_rate_num=30000 +frame_rate_den=1001 +width=1440 +height=1080 +progressive=0 +sample_aspect_num=4 +sample_aspect_den=3 +display_aspect_num=16 +display_aspect_den=9 diff --git a/profiles/hdv_1080_pal b/profiles/hdv_1080_pal new file mode 100644 index 00000000..8ecbacd4 --- /dev/null +++ b/profiles/hdv_1080_pal @@ -0,0 +1,10 @@ +name=HDV 1080i PAL +frame_rate_num=25 +frame_rate_den=1 +width=1440 +height=1080 +progressive=0 +sample_aspect_num=4 +sample_aspect_den=3 +display_aspect_num=16 +display_aspect_den=9 diff --git a/profiles/hdv_720_ntsc b/profiles/hdv_720_ntsc new file mode 100644 index 00000000..08e17c0b --- /dev/null +++ b/profiles/hdv_720_ntsc @@ -0,0 +1,10 @@ +name=HDV 720p NTSC +frame_rate_num=30000 +frame_rate_den=1001 +width=1280 +height=720 +progressive=1 +sample_aspect_num=1 +sample_aspect_den=1 +display_aspect_num=16 +display_aspect_den=9 diff --git a/profiles/hdv_720_pal b/profiles/hdv_720_pal new file mode 100644 index 00000000..c1908b5a --- /dev/null +++ b/profiles/hdv_720_pal @@ -0,0 +1,10 @@ +name=HDV 720p PAL +frame_rate_num=25 +frame_rate_den=1 +width=1280 +height=720 +progressive=1 +sample_aspect_num=1 +sample_aspect_den=1 +display_aspect_num=16 +display_aspect_den=9 diff --git a/profiles/qcif_ntsc b/profiles/qcif_ntsc new file mode 100644 index 00000000..59bd4ffb --- /dev/null +++ b/profiles/qcif_ntsc @@ -0,0 +1,10 @@ +name=QCIF NTSC +frame_rate_num=30000 +frame_rate_den=1001 +width=176 +height=144 +progressive=1 +sample_aspect_num=10 +sample_aspect_den=11 +display_aspect_num=4 +display_aspect_den=3 diff --git a/profiles/qcif_pal b/profiles/qcif_pal new file mode 100644 index 00000000..c96f62f5 --- /dev/null +++ b/profiles/qcif_pal @@ -0,0 +1,10 @@ +name=QCIF PAL +frame_rate_num=25 +frame_rate_den=1 +width=176 +height=144 +progressive=1 +sample_aspect_num=59 +sample_aspect_den=54 +display_aspect_num=4 +display_aspect_den=3 diff --git a/profiles/quarter_ntsc b/profiles/quarter_ntsc new file mode 100644 index 00000000..240a814a --- /dev/null +++ b/profiles/quarter_ntsc @@ -0,0 +1,10 @@ +name=Quarter Square NTSC +frame_rate_num=30000 +frame_rate_den=1001 +width=320 +height=240 +progressive=1 +sample_aspect_num=1 +sample_aspect_den=1 +display_aspect_num=4 +display_aspect_den=3 diff --git a/profiles/quarter_ntsc_wide b/profiles/quarter_ntsc_wide new file mode 100644 index 00000000..bc1cf7d9 --- /dev/null +++ b/profiles/quarter_ntsc_wide @@ -0,0 +1,10 @@ +name=Quarter Square NTSC Widescreen +frame_rate_num=30000 +frame_rate_den=1001 +width=426 +height=240 +progressive=1 +sample_aspect_num=1 +sample_aspect_den=1 +display_aspect_num=16 +display_aspect_den=9 diff --git a/profiles/quarter_pal b/profiles/quarter_pal new file mode 100644 index 00000000..fd64d66e --- /dev/null +++ b/profiles/quarter_pal @@ -0,0 +1,10 @@ +name=Quarter Square PAL +frame_rate_num=25 +frame_rate_den=1 +width=384 +height=288 +progressive=1 +sample_aspect_num=1 +sample_aspect_den=1 +display_aspect_num=4 +display_aspect_den=3 diff --git a/profiles/quarter_pal_wide b/profiles/quarter_pal_wide new file mode 100644 index 00000000..324a11df --- /dev/null +++ b/profiles/quarter_pal_wide @@ -0,0 +1,10 @@ +name=Quarter Square PAL Widescreen +frame_rate_num=25 +frame_rate_den=1 +width=512 +height=288 +progressive=1 +sample_aspect_num=1 +sample_aspect_den=1 +display_aspect_num=16 +display_aspect_den=9 diff --git a/profiles/square_ntsc b/profiles/square_ntsc new file mode 100644 index 00000000..f668b828 --- /dev/null +++ b/profiles/square_ntsc @@ -0,0 +1,10 @@ +name=Square NTSC +frame_rate_num=30000 +frame_rate_den=1001 +width=640 +height=480 +progressive=1 +sample_aspect_num=1 +sample_aspect_den=1 +display_aspect_num=4 +display_aspect_den=3 diff --git a/profiles/square_ntsc_wide b/profiles/square_ntsc_wide new file mode 100644 index 00000000..86addae4 --- /dev/null +++ b/profiles/square_ntsc_wide @@ -0,0 +1,10 @@ +name=Square NTSC Widescreen +frame_rate_num=30000 +frame_rate_den=1001 +width=854 +height=480 +progressive=1 +sample_aspect_num=1 +sample_aspect_den=1 +display_aspect_num=16 +display_aspect_den=9 diff --git a/profiles/square_pal b/profiles/square_pal new file mode 100644 index 00000000..4ece39ba --- /dev/null +++ b/profiles/square_pal @@ -0,0 +1,10 @@ +name=Square PAL +frame_rate_num=25 +frame_rate_den=1 +width=768 +height=576 +progressive=1 +sample_aspect_num=1 +sample_aspect_den=1 +display_aspect_num=4 +display_aspect_den=3 diff --git a/profiles/square_pal_wide b/profiles/square_pal_wide new file mode 100644 index 00000000..0dd94118 --- /dev/null +++ b/profiles/square_pal_wide @@ -0,0 +1,10 @@ +name=Square PAL Widescreen +frame_rate_num=25 +frame_rate_den=1 +width=1024 +height=576 +progressive=1 +sample_aspect_num=1 +sample_aspect_den=1 +display_aspect_num=4 +display_aspect_den=3 diff --git a/profiles/svcd_ntsc b/profiles/svcd_ntsc new file mode 100644 index 00000000..828cccd7 --- /dev/null +++ b/profiles/svcd_ntsc @@ -0,0 +1,10 @@ +name=SVCD NTSC +frame_rate_num=30000 +frame_rate_den=1001 +width=480 +height=480 +progressive=0 +sample_aspect_num=15 +sample_aspect_den=11 +display_aspect_num=4 +display_aspect_den=3 diff --git a/profiles/svcd_ntsc_wide b/profiles/svcd_ntsc_wide new file mode 100644 index 00000000..42f04fcd --- /dev/null +++ b/profiles/svcd_ntsc_wide @@ -0,0 +1,10 @@ +name=SVCD NTSC Widescreen +frame_rate_num=30000 +frame_rate_den=1001 +width=480 +height=480 +progressive=0 +sample_aspect_num=20 +sample_aspect_den=11 +display_aspect_num=16 +display_aspect_den=9 diff --git a/profiles/svcd_pal b/profiles/svcd_pal new file mode 100644 index 00000000..3c41a681 --- /dev/null +++ b/profiles/svcd_pal @@ -0,0 +1,10 @@ +name=SVCD PAL +frame_rate_num=25 +frame_rate_den=1 +width=480 +height=576 +progressive=0 +sample_aspect_num=59 +sample_aspect_den=36 +display_aspect_num=4 +display_aspect_den=3 diff --git a/profiles/svcd_pal_wide b/profiles/svcd_pal_wide new file mode 100644 index 00000000..e634a4af --- /dev/null +++ b/profiles/svcd_pal_wide @@ -0,0 +1,10 @@ +name=SVCD PAL Widescreen +frame_rate_num=25 +frame_rate_den=1 +width=480 +height=576 +progressive=0 +sample_aspect_num=59 +sample_aspect_den=27 +display_aspect_num=4 +display_aspect_den=3 diff --git a/profiles/vcd_ntsc b/profiles/vcd_ntsc new file mode 100644 index 00000000..ae70cad6 --- /dev/null +++ b/profiles/vcd_ntsc @@ -0,0 +1,10 @@ +name=VCD NTSC +frame_rate_num=30000 +frame_rate_den=1001 +width=352 +height=240 +progressive=1 +sample_aspect_num=10 +sample_aspect_den=11 +display_aspect_num=4 +display_aspect_den=3 diff --git a/profiles/vcd_pal b/profiles/vcd_pal new file mode 100644 index 00000000..e5db06c7 --- /dev/null +++ b/profiles/vcd_pal @@ -0,0 +1,10 @@ +name=VCD PAL +frame_rate_num=25 +frame_rate_den=1 +width=352 +height=288 +progressive=1 +sample_aspect_num=59 +sample_aspect_den=54 +display_aspect_num=4 +display_aspect_den=3 diff --git a/src/framework/Makefile b/src/framework/Makefile index 0ce24391..f5df34ca 100644 --- a/src/framework/Makefile +++ b/src/framework/Makefile @@ -32,7 +32,8 @@ OBJS = mlt_frame.o \ mlt_factory.o \ mlt_repository.o \ mlt_pool.o \ - mlt_tokeniser.o + mlt_tokeniser.o \ + mlt_profile.o INCS = mlt_consumer.h \ mlt_factory.h \ @@ -55,7 +56,8 @@ INCS = mlt_consumer.h \ mlt_property.h \ mlt_service.h \ mlt_transition.h \ - mlt_tokeniser.h + mlt_tokeniser.h \ + mlt_profile.h SRCS := $(OBJS:.o=.c) diff --git a/src/framework/mlt.h b/src/framework/mlt.h index 9d3316be..6f974436 100644 --- a/src/framework/mlt.h +++ b/src/framework/mlt.h @@ -41,6 +41,7 @@ extern "C" #include "mlt_tokeniser.h" #include "mlt_parser.h" #include "mlt_geometry.h" +#include "mlt_profile.h" #ifdef __cplusplus } diff --git a/src/framework/mlt_consumer.c b/src/framework/mlt_consumer.c index 1aab394c..f2e653fd 100644 --- a/src/framework/mlt_consumer.c +++ b/src/framework/mlt_consumer.c @@ -23,6 +23,8 @@ #include "mlt_factory.h" #include "mlt_producer.h" #include "mlt_frame.h" +#include "mlt_profile.h" + #include #include #include @@ -30,6 +32,10 @@ static void mlt_consumer_frame_render( mlt_listener listener, mlt_properties owner, mlt_service this, void **args ); static void mlt_consumer_frame_show( mlt_listener listener, mlt_properties owner, mlt_service this, void **args ); +static void mlt_consumer_property_changed( mlt_service owner, mlt_consumer this, char *name ); +static void apply_profile_properties( mlt_profile profile, mlt_properties properties ); + +static mlt_event g_event_listener = NULL; /** Public final methods */ @@ -44,43 +50,9 @@ int mlt_consumer_init( mlt_consumer this, void *child ) { // Get the properties from the service mlt_properties properties = MLT_SERVICE_PROPERTIES( &this->parent ); - - // Get the normalisation preference - char *normalisation = mlt_environment( "MLT_NORMALISATION" ); - - // Deal with normalisation - if ( normalisation == NULL || strcmp( normalisation, "NTSC" ) ) - { - mlt_properties_set( properties, "normalisation", "PAL" ); - mlt_properties_set_double( properties, "fps", 25.0 ); - mlt_properties_set_int( properties, "frame_rate_num", 25 ); - mlt_properties_set_int( properties, "frame_rate_den", 1 ); - mlt_properties_set_int( properties, "width", 720 ); - mlt_properties_set_int( properties, "height", 576 ); - mlt_properties_set_int( properties, "progressive", 0 ); - mlt_properties_set_double( properties, "aspect_ratio", 59.0 / 54.0 ); - mlt_properties_set_int( properties, "aspect_ratio_num", 59 ); - mlt_properties_set_int( properties, "aspect_ratio_den", 54 ); - mlt_properties_set_double( properties, "display_ratio", 4.0 / 3.0 ); - mlt_properties_set_int( properties, "display_ratio_num", 4 ); - mlt_properties_set_int( properties, "display_ratio_den", 3 ); - } - else - { - mlt_properties_set( properties, "normalisation", "NTSC" ); - mlt_properties_set_double( properties, "fps", 30000.0 / 1001.0 ); - mlt_properties_set_int( properties, "frame_rate_num", 30000 ); - mlt_properties_set_int( properties, "frame_rate_den", 1001 ); - mlt_properties_set_int( properties, "width", 720 ); - mlt_properties_set_int( properties, "height", 480 ); - mlt_properties_set_int( properties, "progressive", 0 ); - mlt_properties_set_double( properties, "aspect_ratio", 10.0 / 11.0 ); - mlt_properties_set_int( properties, "aspect_ratio_num", 10 ); - mlt_properties_set_int( properties, "aspect_ratio_den", 11 ); - mlt_properties_set_double( properties, "display_ratio", 4.0 / 3.0 ); - mlt_properties_set_int( properties, "display_ratio_num", 4 ); - mlt_properties_set_int( properties, "display_ratio_den", 3 ); - } + + // Apply the profile to properties for legacy integration + apply_profile_properties( mlt_profile_get(), properties ); // Default rescaler for all consumers mlt_properties_set( properties, "rescale", "bilinear" ); @@ -105,6 +77,10 @@ int mlt_consumer_init( mlt_consumer this, void *child ) mlt_events_register( properties, "consumer-frame-render", ( mlt_transmitter )mlt_consumer_frame_render ); mlt_events_register( properties, "consumer-stopped", NULL ); + // Register a property-changed listener to handle the profile property - + // subsequent properties can override the profile + g_event_listener = mlt_events_listen( properties, this, "property-changed", ( mlt_listener )mlt_consumer_property_changed ); + // Create the push mutex and condition pthread_mutex_init( &this->put_mutex, NULL ); pthread_cond_init( &this->put_cond, NULL ); @@ -113,6 +89,41 @@ int mlt_consumer_init( mlt_consumer this, void *child ) return error; } +static void apply_profile_properties( mlt_profile profile, mlt_properties properties ) +{ + mlt_properties_set_double( properties, "fps", mlt_profile_fps( profile ) ); + mlt_properties_set_int( properties, "frame_rate_num", profile->frame_rate_num ); + mlt_properties_set_int( properties, "frame_rate_den", profile->frame_rate_den ); + mlt_properties_set_int( properties, "width", profile->width ); + mlt_properties_set_int( properties, "height", profile->height ); + mlt_properties_set_int( properties, "progressive", profile->progressive ); + mlt_properties_set_double( properties, "aspect_ratio", mlt_profile_sar( profile ) ); + mlt_properties_set_int( properties, "sample_aspect_num", profile->sample_aspect_num ); + mlt_properties_set_int( properties, "sample_aspect_den", profile->sample_aspect_den ); + mlt_properties_set_double( properties, "display_ratio", mlt_profile_dar( profile ) ); + mlt_properties_set_int( properties, "display_aspect_num", profile->display_aspect_num ); + mlt_properties_set_int( properties, "display_aspect_num", profile->display_aspect_num ); +} + +static void mlt_consumer_property_changed( mlt_service owner, mlt_consumer this, char *name ) +{ + if ( !strcmp( name, "profile" ) ) + { + // Get the properies + mlt_properties properties = MLT_CONSUMER_PROPERTIES( this ); + + // Locate the profile + mlt_profile_select( mlt_properties_get( properties, "profile" ) ); + + // Stop listening to this + mlt_event_close( g_event_listener ); + g_event_listener = NULL; + + // Apply to properties + apply_profile_properties( mlt_profile_get(), properties ); + } +} + static void mlt_consumer_frame_show( mlt_listener listener, mlt_properties owner, mlt_service this, void **args ) { if ( listener != NULL ) @@ -176,16 +187,6 @@ int mlt_consumer_start( mlt_consumer this ) // Determine if there's a test card producer char *test_card = mlt_properties_get( properties, "test_card" ); - // Handle profiles - char *profile = mlt_properties_get( properties, "profile" ); - int profile_ok = mlt_consumer_profile( properties, profile ); - - // Check that everything is OK - if ( !profile_ok ) - fprintf( stderr, "Unrecognised profile %s - continuing with defaults.\n", mlt_properties_get( properties, "profile" ) ); - else if ( profile_ok < 0 ) - fprintf( stderr, "Recognised profile %s with warnings - trying to continue with some defaults.\n", mlt_properties_get( properties, "profile" ) ); - // Just to make sure nothing is hanging around... mlt_frame_close( this->put ); this->put = NULL; @@ -349,164 +350,16 @@ static inline long time_difference( struct timeval *time1 ) int mlt_consumer_profile( mlt_properties properties, char *profile ) { - double fps = mlt_properties_get_double( properties, "fps" ); - int recognised = 1; - double display_num = 0; - double display_den = 0; - double pixel_num = 0; - double pixel_den = 0; - int width = 0; - int height = 0; - - if ( fps == 25.0 && profile != NULL ) - { - width = 720; - height = 576; - display_num = 4; - display_den = 3; - pixel_num = 59; - pixel_den = 54; - - if ( !strcmp( profile, "dv_wide" ) ) - { - display_num = 16; - display_den = 9; - pixel_num = 118; - pixel_den = 81; - } - else if ( !strncmp( profile, "square_wide", 11 ) ) - { - display_num = 16; - display_den = 9; - pixel_num = 1; - pixel_den = 1; - width = 1024; - height = 576; - } - else if ( !strncmp( profile, "square", 6 ) ) - { - pixel_num = 1; - pixel_den = 1; - width = 768; - height = 576; - } - else if ( !strncmp( profile, "vcd", 3 ) ) - { - width = 352; - height = 288; - } - else if ( !strncmp( profile, "cvd", 3 ) ) - { - width = 352; - height = 576; - pixel_num = 59; - pixel_den = 27; - } - else if ( !strncmp( profile, "svcd_wide", 9 ) ) - { - width = 480; - height = 576; - pixel_num = 59; - pixel_den = 27; - display_num = 16; - display_den = 9; - } - else if ( !strncmp( profile, "svcd", 4 ) ) - { - width = 480; - height = 576; - pixel_num = 59; - pixel_den = 36; - } - else if ( strncmp( profile, "frame", 5 ) && strcmp( profile, "dv" ) ) - { - recognised = 0; - } - } - else if ( profile != NULL ) + mlt_profile p = mlt_profile_select( profile ); + if ( p ) { - width = 720; - height = 480; - display_num = 4; - display_den = 3; - pixel_num = 10; - pixel_den = 11; - - if ( !strcmp( profile, "dv_wide" ) ) - { - display_num = 16; - display_den = 9; - pixel_num = 40; - pixel_den = 33; - } - else if ( !strncmp( profile, "square_wide", 11 ) ) - { - display_num = 16; - display_den = 9; - pixel_num = 1; - pixel_den = 1; - width = 854; - height = 480; - } - else if ( !strncmp( profile, "square", 6 ) ) - { - pixel_num = 1; - pixel_den = 1; - width = 640; - height = 480; - } - else if ( !strncmp( profile, "vcd", 3 ) ) - { - width = 352; - height = 240; - } - else if ( !strncmp( profile, "cvd", 3 ) ) - { - width = 352; - height = 480; - pixel_num = 20; - pixel_den = 11; - } - else if ( !strncmp( profile, "svcd_wide", 9 ) ) - { - width = 480; - height = 480; - pixel_num = 20; - pixel_den = 11; - display_num = 16; - display_den = 9; - } - else if ( !strncmp( profile, "svcd", 4 ) ) - { - width = 480; - height = 480; - pixel_num = 15; - pixel_den = 11; - } - else if ( strncmp( profile, "frame", 5 ) && strcmp( profile, "dv" ) ) - { - recognised = 0; - } + apply_profile_properties( p, properties ); + return 1; } - - // If width (or any of the above are 0), we use defaults otherwise we switch to recognised - if ( width != 0 && recognised ) + else { - if ( recognised && strchr( profile, ':' ) ) - if ( sscanf( strchr( profile, ':' ) + 1, "%dx%d", &width, &height ) != 2 ) - recognised = -1; - - mlt_properties_set_int( properties, "width", width ); - mlt_properties_set_int( properties, "height", height ); - mlt_properties_set_double( properties, "aspect_ratio", pixel_num / pixel_den ); - mlt_properties_set_int( properties, "aspect_ratio_num", pixel_num ); - mlt_properties_set_int( properties, "aspect_ratio_den", pixel_den ); - mlt_properties_set_double( properties, "display_ratio", display_num / display_den ); - mlt_properties_set_int( properties, "display_ratio_num", display_num ); - mlt_properties_set_int( properties, "display_ratio_den", display_den ); + return 0; } - - return recognised; } static void *consumer_read_ahead_thread( void *arg ) diff --git a/src/framework/mlt_factory.c b/src/framework/mlt_factory.c index b6241133..12452657 100644 --- a/src/framework/mlt_factory.c +++ b/src/framework/mlt_factory.c @@ -111,8 +111,37 @@ int mlt_factory_init( const char *prefix ) mlt_properties_set_or_default( global_properties, "MLT_PRODUCER", getenv( "MLT_PRODUCER" ), "fezzik" ); mlt_properties_set_or_default( global_properties, "MLT_CONSUMER", getenv( "MLT_CONSUMER" ), "sdl" ); mlt_properties_set( global_properties, "MLT_TEST_CARD", getenv( "MLT_TEST_CARD" ) ); + mlt_properties_set_or_default( global_properties, "MLT_PROFILE", getenv( "MLT_PROFILE" ), "dv_pal" ); + + // Load the most appropriate profile + // MLT_PROFILE preferred + if ( getenv( "MLT_PROFILE" ) ) + { + if ( !mlt_profile_select( mlt_environment( "MLT_PROFILE" ) ) ) + mlt_profile_load_file( mlt_environment( "MLT_PROFILE" ) ); + } + // MLT_NORMALISATION backwards compatibility + else if ( strcmp( mlt_environment( "MLT_NORMALISATION" ), "PAL" ) ) + mlt_profile_select( "dv_ntsc" ); + else + mlt_profile_select( "dv_pal" ); + + // destroy an invalid profile so it can be constructed from hard defauls + if ( mlt_profile_get()->width == 0 ) + mlt_profile_close(); + + // Set MLT_NORMALISATION to appease legacy modules + if ( !getenv( "MLT_NORMALISATION" ) ) + { + const char *profile = mlt_profile_get()->name; + if ( strstr( profile, "_ntsc" ) || strstr( profile, "_atsc" ) ) + setenv( "MLT_NORMALISATION", "NTSC", 1 ); + else if ( strstr( profile, "_pal" ) ) + setenv( "MLT_NORMALISATION", "PAL", 1 ); + } } + return 0; } @@ -279,6 +308,6 @@ void mlt_factory_close( ) free( mlt_prefix ); mlt_prefix = NULL; mlt_pool_close( ); + mlt_profile_close(); } } - diff --git a/src/framework/mlt_frame.c b/src/framework/mlt_frame.c index 92983aab..52de88d9 100644 --- a/src/framework/mlt_frame.c +++ b/src/framework/mlt_frame.c @@ -22,6 +22,8 @@ #include "mlt_frame.h" #include "mlt_producer.h" #include "mlt_factory.h" +#include "mlt_profile.h" + #include #include #include @@ -37,9 +39,6 @@ mlt_frame mlt_frame_init( ) if ( this != NULL ) { - // Get the normalisation - char *normalisation = mlt_environment( "MLT_NORMALISATION" ); - // Initialise the properties mlt_properties properties = &this->parent; mlt_properties_init( properties, this ); @@ -47,24 +46,11 @@ mlt_frame mlt_frame_init( ) // Set default properties on the frame mlt_properties_set_position( properties, "_position", 0.0 ); mlt_properties_set_data( properties, "image", NULL, 0, NULL, NULL ); - - if ( normalisation == NULL || strcmp( normalisation, "NTSC" ) ) - { - mlt_properties_set_int( properties, "width", 720 ); - mlt_properties_set_int( properties, "height", 576 ); - mlt_properties_set_int( properties, "normalised_width", 720 ); - mlt_properties_set_int( properties, "normalised_height", 576 ); - mlt_properties_set_double( properties, "aspect_ratio", 59.0/54.0 ); - } - else - { - mlt_properties_set_int( properties, "width", 720 ); - mlt_properties_set_int( properties, "height", 480 ); - mlt_properties_set_int( properties, "normalised_width", 720 ); - mlt_properties_set_int( properties, "normalised_height", 480 ); - mlt_properties_set_double( properties, "aspect_ratio", 10.0/11.0 ); - } - + mlt_properties_set_int( properties, "width", mlt_profile_get()->width ); + mlt_properties_set_int( properties, "height", mlt_profile_get()->height ); + mlt_properties_set_int( properties, "normalised_width", mlt_profile_get()->width ); + mlt_properties_set_int( properties, "normalised_height", mlt_profile_get()->height ); + mlt_properties_set_double( properties, "aspect_ratio", mlt_profile_sar( NULL ) ); mlt_properties_set_data( properties, "audio", NULL, 0, NULL, NULL ); mlt_properties_set_data( properties, "alpha", NULL, 0, NULL, NULL ); diff --git a/src/framework/mlt_geometry.c b/src/framework/mlt_geometry.c index 50a0d622..67d98ee9 100644 --- a/src/framework/mlt_geometry.c +++ b/src/framework/mlt_geometry.c @@ -21,6 +21,7 @@ #include "mlt_geometry.h" #include "mlt_tokeniser.h" #include "mlt_factory.h" +#include "mlt_profile.h" #include #include @@ -54,12 +55,8 @@ mlt_geometry mlt_geometry_init( ) if ( this->local != NULL ) { geometry self = this->local; - char *normalisation = mlt_environment( "MLT_NORMALISATION" ); - self->nw = 720; - if ( normalisation == NULL || strcmp( normalisation, "NTSC" ) ) - self->nh = 576; - else - self->nh = 480; + self->nw = mlt_profile_get()->width; + self->nh = mlt_profile_get()->height; } else { diff --git a/src/framework/mlt_producer.c b/src/framework/mlt_producer.c index ecd1eedc..56d1d3f3 100644 --- a/src/framework/mlt_producer.c +++ b/src/framework/mlt_producer.c @@ -23,6 +23,8 @@ #include "mlt_factory.h" #include "mlt_frame.h" #include "mlt_parser.h" +#include "mlt_profile.h" + #include #include #include @@ -66,9 +68,6 @@ int mlt_producer_init( mlt_producer this, void *child ) // Initialise the service if ( mlt_service_init( &this->parent, this ) == 0 ) { - // Get the normalisation preference - char *normalisation = mlt_environment( "MLT_NORMALISATION" ); - // The parent is the service mlt_service parent = &this->parent; @@ -86,20 +85,10 @@ int mlt_producer_init( mlt_producer this, void *child ) mlt_properties_set( properties, "mlt_type", "mlt_producer" ); mlt_properties_set_position( properties, "_position", 0.0 ); mlt_properties_set_double( properties, "_frame", 0 ); - if ( normalisation == NULL || strcmp( normalisation, "NTSC" ) ) - { - mlt_properties_set_double( properties, "fps", 25.0 ); - mlt_properties_set_int( properties, "frame_rate_num", 25 ); - mlt_properties_set_int( properties, "frame_rate_den", 1 ); - mlt_properties_set_double( properties, "aspect_ratio", 59.0 / 54.0 ); - } - else - { - mlt_properties_set_double( properties, "fps", 30000.0 / 1001.0 ); - mlt_properties_set_int( properties, "frame_rate_num", 30000 ); - mlt_properties_set_int( properties, "frame_rate_den", 1001 ); - mlt_properties_set_double( properties, "aspect_ratio", 10.0 / 11.0 ); - } + mlt_properties_set_double( properties, "fps", mlt_profile_fps( NULL ) ); + mlt_properties_set_int( properties, "frame_rate_num", mlt_profile_get()->frame_rate_num ); + mlt_properties_set_int( properties, "frame_rate_den", mlt_profile_get()->frame_rate_den ); + mlt_properties_set_double( properties, "aspect_ratio", mlt_profile_sar( NULL ) ); mlt_properties_set_double( properties, "_speed", 1.0 ); mlt_properties_set_position( properties, "in", 0 ); mlt_properties_set_position( properties, "out", 14999 ); diff --git a/src/framework/mlt_profile.c b/src/framework/mlt_profile.c new file mode 100644 index 00000000..d32146a3 --- /dev/null +++ b/src/framework/mlt_profile.c @@ -0,0 +1,193 @@ +/* + * mlt_profile.c -- video output definition + * Copyright (C) 2007 Ushodaya Enterprises Limited + * Author: Dan Dennedy + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "mlt_profile.h" +#include "mlt_factory.h" +#include "mlt_properties.h" + +#include +#include +#include + +#define PROFILES_DIR "/share/mlt/profiles/" + +static mlt_profile profile = NULL; + +/** Get the current profile +* Builds one for PAL DV if non-existing +*/ + +mlt_profile mlt_profile_get( ) +{ + if ( !profile ) + { + profile = calloc( 1, sizeof( struct mlt_profile_s ) ); + if ( profile ) + { + profile->name = strdup( "DV PAL" ); + profile->frame_rate_num = 25; + profile->frame_rate_den = 1; + profile->width = 720; + profile->height = 576; + profile->progressive = 0; + profile->sample_aspect_num = 59; + profile->sample_aspect_den = 54; + profile->display_aspect_num = 4; + profile->display_aspect_den = 3; + } + } + return profile; +} + + +/** Load a profile from the system folder +*/ + +mlt_profile mlt_profile_select( const char *name ) +{ + const char *prefix = PREFIX; + char *filename = calloc( 1, strlen( prefix ) + strlen( PROFILES_DIR ) + strlen( name ) + 1 ); + strcpy( filename, prefix ); + if ( filename[ strlen( filename ) - 1 ] != '/' ) + filename[ strlen( filename ) ] = '/'; + strcat( filename, PROFILES_DIR ); + strcat( filename, name ); + return mlt_profile_load_file( filename ); +} + +/** Load a profile from specific file +*/ + +mlt_profile mlt_profile_load_file( const char *file ) +{ + // Load the profile as properties + mlt_properties properties = mlt_properties_load( file ); + if ( properties && mlt_properties_get_int( properties, "width" ) ) + { + mlt_profile_load_properties( properties ); + if ( !profile->name ) + { + char *filename = strdup( file ); + profile->name = strdup( basename( filename ) ); + free( filename ); + } + } + else + { + mlt_properties_close( properties ); + mlt_profile_close(); + } + return profile; +} + +/** Load a profile from a properties object +*/ + +mlt_profile mlt_profile_load_properties( mlt_properties properties ) +{ + mlt_profile_close(); + profile = calloc( 1, sizeof( struct mlt_profile_s ) ); + if ( profile ) + { + if ( mlt_properties_get( properties, "name" ) ) + profile->name = mlt_properties_get( properties, "name" ); + profile->frame_rate_num = mlt_properties_get_int( properties, "frame_rate_num" ); + profile->frame_rate_den = mlt_properties_get_int( properties, "frame_rate_den" ); + profile->width = mlt_properties_get_int( properties, "width" ); + profile->height = mlt_properties_get_int( properties, "height" ); + profile->progressive = mlt_properties_get_int( properties, "progressive" ); + profile->sample_aspect_num = mlt_properties_get_int( properties, "sample_aspect_num" ); + profile->sample_aspect_den = mlt_properties_get_int( properties, "sample_aspect_den" ); + profile->display_aspect_num = mlt_properties_get_int( properties, "display_aspect_num" ); + profile->display_aspect_den = mlt_properties_get_int( properties, "display_aspect_den" ); + } + return profile; +} + +/** Load an anonymous profile from string +*/ + +mlt_profile mlt_profile_load_string( const char *string ) +{ + mlt_properties properties = mlt_properties_new(); + if ( properties ) + { + const char *p = string; + while ( p ) + { + if ( strcmp( p, "" ) && p[ 0 ] != '#' ) + mlt_properties_parse( properties, p ); + p = strchr( p, '\n' ); + if ( p ) p++; + } + } + mlt_profile_load_properties( properties ); + if ( profile && !profile->name ) + profile->name = strdup( "untitled" ); + return profile; +} + +/** Get the framerate as float +*/ + +double mlt_profile_fps( mlt_profile aprofile ) +{ + if ( aprofile ) + return ( double ) aprofile->frame_rate_num / aprofile->frame_rate_den; + else + return ( double ) mlt_profile_get()->frame_rate_num / mlt_profile_get()->frame_rate_den; +} + +/** Get the sample aspect ratio as float +*/ + +double mlt_profile_sar( mlt_profile aprofile ) +{ + if ( aprofile ) + return ( double ) aprofile->sample_aspect_num / aprofile->sample_aspect_den; + else + return ( double ) mlt_profile_get()->sample_aspect_num / mlt_profile_get()->sample_aspect_den; +} + +/** Get the display aspect ratio as float +*/ + +double mlt_profile_dar( mlt_profile aprofile ) +{ + if ( aprofile ) + return ( double ) aprofile->display_aspect_num / aprofile->display_aspect_den; + else + return ( double ) mlt_profile_get()->display_aspect_num / mlt_profile_get()->display_aspect_den; +} + +/** Free up the global profile resources +*/ + +void mlt_profile_close( ) +{ + if ( profile ) + { + if ( profile->name ) + free( profile->name ); + profile->name = NULL; + free( profile ); + profile = NULL; + } +} diff --git a/src/framework/mlt_profile.h b/src/framework/mlt_profile.h new file mode 100644 index 00000000..29ee633d --- /dev/null +++ b/src/framework/mlt_profile.h @@ -0,0 +1,49 @@ +/* + * mlt_profile.h -- video output definition + * Copyright (C) 2007 Ushodaya Enterprises Limited + * Author: Dan Dennedy + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef _MLT_PROFILE_H +#define _MLT_PROFILE_H + +#include "mlt_types.h" + +struct mlt_profile_s +{ + char* name; + int frame_rate_num; + int frame_rate_den; + int width; + int height; + int progressive; + int sample_aspect_num; + int sample_aspect_den; + int display_aspect_num; + int display_aspect_den; +}; + +extern mlt_profile mlt_profile_get( ); +extern mlt_profile mlt_profile_select( const char *name ); +extern mlt_profile mlt_profile_load_file( const char *file ); +extern mlt_profile mlt_profile_load_properties( mlt_properties properties ); +extern mlt_profile mlt_profile_load_string( const char *string ); +extern double mlt_profile_fps( mlt_profile profile ); +extern double mlt_profile_sar( mlt_profile profile ); +extern double mlt_profile_dar( mlt_profile profile ); +extern void mlt_profile_close( ); +#endif diff --git a/src/framework/mlt_types.h b/src/framework/mlt_types.h index 50baba6d..d550c3f9 100644 --- a/src/framework/mlt_types.h +++ b/src/framework/mlt_types.h @@ -94,6 +94,7 @@ typedef struct mlt_parser_s *mlt_parser; typedef struct mlt_deque_s *mlt_deque; typedef struct mlt_geometry_s *mlt_geometry; typedef struct mlt_geometry_item_s *mlt_geometry_item; +typedef struct mlt_profile_s *mlt_profile; typedef void ( *mlt_destructor )( void * ); typedef char *( *mlt_serialiser )( void *, int length ); diff --git a/src/modules/dv/consumer_libdv.c b/src/modules/dv/consumer_libdv.c index e3deee04..f6c468e3 100644 --- a/src/modules/dv/consumer_libdv.c +++ b/src/modules/dv/consumer_libdv.c @@ -283,7 +283,7 @@ static void consumer_encode_audio( mlt_consumer this, uint8_t *dv_frame, mlt_fra time_t start = time( NULL ); int height = mlt_properties_get_int( this_properties, "height" ); int is_pal = height == 576; - int is_wide = mlt_properties_get_int( this_properties, "display_ratio_num" ) == 16; + int is_wide = mlt_properties_get_int( this_properties, "display_aspect_num" ) == 16; // Temporary - audio buffer allocation int16_t *audio_buffers[ 4 ]; diff --git a/src/modules/sdl/consumer_sdl.c b/src/modules/sdl/consumer_sdl.c index fdfcdc24..70e65d9c 100644 --- a/src/modules/sdl/consumer_sdl.c +++ b/src/modules/sdl/consumer_sdl.c @@ -102,9 +102,6 @@ mlt_consumer consumer_sdl_init( char *arg ) mlt_service service = MLT_CONSUMER_SERVICE( parent ); this->properties = MLT_SERVICE_PROPERTIES( service ); - // Default display aspect ratio - double display_ratio = mlt_properties_get_double( this->properties, "display_ratio" ); - // Set the default volume mlt_properties_set_double( this->properties, "volume", 1.0 ); @@ -136,10 +133,6 @@ mlt_consumer consumer_sdl_init( char *arg ) this->height = mlt_properties_get_int( this->properties, "height" ); } - // Default window size - this->window_width = ( double )this->height * display_ratio; - this->window_height = this->height; - // Set the sdl flags this->sdl_flags = SDL_HWSURFACE | SDL_ASYNCBLIT | SDL_HWACCEL | SDL_RESIZABLE | SDL_DOUBLEBUF; @@ -219,6 +212,11 @@ int consumer_start( mlt_consumer parent ) if ( audio_off == 0 ) SDL_InitSubSystem( SDL_INIT_AUDIO ); + // Default window size + double display_ratio = mlt_properties_get_double( this->properties, "display_ratio" ); + this->window_width = ( double )this->height * display_ratio; + this->window_height = this->height; + if ( this->sdl_screen == NULL && display_off == 0 ) this->sdl_screen = SDL_SetVideoMode( this->window_width, this->window_height, 0, this->sdl_flags );