ce6b869ef09e23b2603f709be92a2eeda5f37724
9 class Custom
: public Miracle
16 Custom( char *name
= "Custom", int port
= 5290, char *config
= NULL
) :
17 Miracle( name
, port
, config
),
20 // Ensure that we receive the westley document before it's deserialised
21 set( "push-parser-off", 1 );
29 // Optional step - receive the westley document and do something with it
30 Response
*received( char *command
, char *document
)
32 cerr
<< document
<< endl
;
33 Producer
producer( profile
, "westley-xml", document
);
34 return push( command
, &producer
);
37 // Push handling - clear the playlist, append, seek to beginning and play
38 Response
*push( char *command
, Service
*service
)
40 Playlist
playlist( ( mlt_playlist
)( unit( 0 )->get_data( "playlist" ) ) );
41 Producer
producer( *service
);
42 if ( producer
.is_valid( ) && playlist
.is_valid( ) )
46 playlist
.append( producer
);
48 playlist
.set_speed( 1 );
50 return new Response( 200, "OK" );
52 return new Response( 400, "Invalid" );
55 // Custom command execution
56 Response
*execute( char *command
)
58 Response
*response
= NULL
;
60 if ( !strcmp( command
, "debug" ) )
62 // Example of a custom command
63 response
= new Response( 200, "Diagnostics output" );
64 for( int i
= 0; unit( i
) != NULL
; i
++ )
66 Properties
*properties
= unit( i
);
68 output
<< string( "Unit " ) << i
<< endl
;
69 for ( int j
= 0; j
< properties
->count( ); j
++ )
70 output
<< properties
->get_name( j
) << " = " << properties
->get( j
) << endl
;
71 response
->write( output
.str( ).c_str( ) );
76 // Use the default command processing
77 response
= Miracle
::execute( command
);
80 // If no event exists and the first unit has been added...
81 if ( event
== NULL
&& unit( 0 ) != NULL
)
83 // Set up the event handling
84 Consumer
consumer( ( mlt_consumer
)( unit( 0 )->get_data( "consumer" ) ) );
85 event
= consumer
.listen( "consumer-frame-render", this, ( mlt_listener
)frame_render
);
87 // In this custom case, we'll loop everything on the unit
88 Playlist
playlist( ( mlt_playlist
)( unit( 0 )->get_data( "playlist" ) ) );
89 playlist
.set( "eof", "loop" );
95 // Callback for frame render notification
96 static void frame_render( mlt_consumer consumer
, Custom
*self
, mlt_frame frame_ptr
)
98 Frame
frame( frame_ptr
);
99 self
->frame_render_event( frame
);
102 // Remove all supers and attributes
103 void frame_render_event( Frame
&frame
)
105 // Fetch the c double ended queue structure
106 mlt_deque deque
= ( mlt_deque
)frame
.get_data( "data_queue" );
108 // While the deque isn't empty
109 while( deque
!= NULL
&& mlt_deque_peek_back( deque
) != NULL
)
111 // Fetch the c properties structure
112 mlt_properties cprops
= ( mlt_properties
)mlt_deque_pop_back( deque
);
114 // For fun, convert it to c++ and output it :-)
115 Properties
properties( cprops
);
119 mlt_properties_close( cprops
);
124 int main( int argc
, char **argv
)
126 Custom
server( "Server" );
128 server
.execute( "uadd sdl" );
129 server
.execute( "play u0" );
130 server
.wait_for_shutdown( );