9 class Custom
: public Miracle
15 Custom( char *name
= "Custom", int port
= 5290, char *config
= NULL
) :
16 Miracle( name
, port
, config
),
19 // Ensure that we receive the westley document before it's deserialised
20 set( "push-parser-off", 1 );
28 // Optional step - receive the westley document and do something with it
29 Response
*received( char *command
, char *document
)
31 cerr
<< document
<< endl
;
32 Producer
producer( "westley-xml", document
);
33 return push( command
, &producer
);
36 // Push handling - clear the playlist, append, seek to beginning and play
37 Response
*push( char *command
, Service
*service
)
39 Playlist
playlist( ( mlt_playlist
)( unit( 0 )->get_data( "playlist" ) ) );
40 Producer
producer( *service
);
41 if ( producer
.is_valid( ) && playlist
.is_valid( ) )
45 playlist
.append( producer
);
47 playlist
.set_speed( 1 );
49 return new Response( 200, "OK" );
51 return new Response( 400, "Invalid" );
54 // Custom command execution
55 Response
*execute( char *command
)
57 Response
*response
= NULL
;
59 if ( !strcmp( command
, "debug" ) )
61 // Example of a custom command
62 response
= new Response( 200, "Diagnostics output" );
63 for( int i
= 0; unit( i
) != NULL
; i
++ )
65 Properties
*properties
= unit( i
);
67 output
<< string( "Unit " ) << i
<< endl
;
68 for ( int j
= 0; j
< properties
->count( ); j
++ )
69 output
<< properties
->get_name( j
) << " = " << properties
->get( j
) << endl
;
70 response
->write( output
.str( ).c_str( ) );
75 // Use the default command processing
76 response
= Miracle
::execute( command
);
79 // If no event exists and the first unit has been added...
80 if ( event
== NULL
&& unit( 0 ) != NULL
)
82 // Set up the event handling
83 Consumer
consumer( ( mlt_consumer
)( unit( 0 )->get_data( "consumer" ) ) );
84 event
= consumer
.listen( "consumer-frame-render", this, ( mlt_listener
)frame_render
);
86 // In this custom case, we'll loop everything on the unit
87 Playlist
playlist( ( mlt_playlist
)( unit( 0 )->get_data( "playlist" ) ) );
88 playlist
.set( "eof", "loop" );
94 // Callback for frame render notification
95 static void frame_render( mlt_consumer consumer
, Custom
*self
, mlt_frame frame_ptr
)
97 Frame
frame( frame_ptr
);
98 self
->frame_render_event( frame
);
101 // Do something to the frame here
102 void frame_render_event( Frame
&frame
)
108 int main( int argc
, char **argv
)
110 Custom
server( "Server" );
112 server
.execute( "uadd sdl" );
113 server
.execute( "play u0" );
114 server
.wait_for_shutdown( );