10 class Custom : public Miracle
17 Custom( char *name = "Custom", int port = 5290, char *config = NULL ) :
18 Miracle( name, port, config ),
21 // Ensure that we receive the westley document before it's deserialised
22 set( "push-parser-off", 1 );
30 // Optional step - receive the westley document and do something with it
31 Response *received( char *command, char *document )
33 cerr << document << endl;
34 Producer producer( profile, "westley-xml", document );
35 return push( command, &producer );
38 // Push handling - clear the playlist, append, seek to beginning and play
39 Response *push( char*, Service *service )
41 Playlist playlist( ( mlt_playlist )( unit( 0 )->get_data( "playlist" ) ) );
42 Producer producer( *service );
43 if ( producer.is_valid( ) && playlist.is_valid( ) )
47 playlist.append( producer );
49 playlist.set_speed( 1 );
51 return new Response( 200, "OK" );
53 return new Response( 400, "Invalid" );
56 // Custom command execution
57 Response *execute( char *command )
59 Response *response = NULL;
61 if ( !strcmp( command, "debug" ) )
63 // Example of a custom command
64 response = new Response( 200, "Diagnostics output" );
65 for( int i = 0; unit( i ) != NULL; i ++ )
67 Properties *properties = unit( i );
69 output << string( "Unit " ) << i << endl;
70 for ( int j = 0; j < properties->count( ); j ++ )
71 output << properties->get_name( j ) << " = " << properties->get( j ) << endl;
72 response->write( output.str( ).c_str( ) );
77 // Use the default command processing
78 response = Miracle::execute( command );
81 // If no event exists and the first unit has been added...
82 if ( event == NULL && unit( 0 ) != NULL )
84 // Set up the event handling
85 Consumer consumer( ( mlt_consumer )( unit( 0 )->get_data( "consumer" ) ) );
86 event = consumer.listen( "consumer-frame-render", this, ( mlt_listener )frame_render );
88 // In this custom case, we'll loop everything on the unit
89 Playlist playlist( ( mlt_playlist )( unit( 0 )->get_data( "playlist" ) ) );
90 playlist.set( "eof", "loop" );
96 // Callback for frame render notification
97 static void frame_render( mlt_consumer, Custom *self, mlt_frame frame_ptr )
99 Frame frame( frame_ptr );
100 self->frame_render_event( frame );
103 // Remove all supers and attributes
104 void frame_render_event( Frame &frame )
106 // Fetch the c double ended queue structure
107 mlt_deque deque = ( mlt_deque )frame.get_data( "data_queue" );
109 // While the deque isn't empty
110 while( deque != NULL && mlt_deque_peek_back( deque ) != NULL )
112 // Fetch the c properties structure
113 mlt_properties cprops = ( mlt_properties )mlt_deque_pop_back( deque );
115 // For fun, convert it to c++ and output it :-)
116 Properties properties( cprops );
120 mlt_properties_close( cprops );
125 int main( int, char** )
127 Custom server( "Server" );
129 server.execute( "uadd sdl" );
130 server.execute( "play u0" );
131 server.wait_for_shutdown( );