9 #include <MltResponse.h>
12 class Custom
: public Melted
19 Custom( char *name
= "Custom", int port
= 5290, char *config
= NULL
) :
20 Melted( name
, port
, config
),
23 // Ensure that we receive the MLT XML document before it's deserialised
24 set( "push-parser-off", 1 );
32 // Optional step - receive the MLT XML document and do something with it
33 Response
*received( char *command
, char *document
)
35 cerr
<< document
<< endl
;
36 Producer
producer( profile
, "xml-string", document
);
37 return push( command
, &producer
);
40 // Push handling - clear the playlist, append, seek to beginning and play
41 Response
*push( char*, Service
*service
)
43 Playlist
playlist( ( mlt_playlist
)( unit( 0 )->get_data( "playlist" ) ) );
44 Producer
producer( *service
);
45 if ( producer
.is_valid( ) && playlist
.is_valid( ) )
49 playlist
.append( producer
);
51 playlist
.set_speed( 1 );
53 return new Response( 200, "OK" );
55 return new Response( 400, "Invalid" );
58 // Custom command execution
59 Response
*execute( char *command
)
61 Response
*response
= NULL
;
63 if ( !strcmp( command
, "debug" ) )
65 // Example of a custom command
66 response
= new Response( 200, "Diagnostics output" );
67 for( int i
= 0; unit( i
) != NULL
; i
++ )
69 Properties
*properties
= unit( i
);
71 output
<< string( "Unit " ) << i
<< endl
;
72 for ( int j
= 0; j
< properties
->count( ); j
++ )
73 output
<< properties
->get_name( j
) << " = " << properties
->get( j
) << endl
;
74 response
->write( output
.str( ).c_str( ) );
79 // Use the default command processing
80 response
= Melted
::execute( command
);
83 // If no event exists and the first unit has been added...
84 if ( event
== NULL
&& unit( 0 ) != NULL
)
86 // Set up the event handling
87 Consumer
consumer( ( mlt_consumer
)( unit( 0 )->get_data( "consumer" ) ) );
88 event
= consumer
.listen( "consumer-frame-render", this, ( mlt_listener
)frame_render
);
90 // In this custom case, we'll loop everything on the unit
91 Playlist
playlist( ( mlt_playlist
)( unit( 0 )->get_data( "playlist" ) ) );
92 playlist
.set( "eof", "loop" );
98 // Callback for frame render notification
99 static void frame_render( mlt_consumer
, Custom
*self
, mlt_frame frame_ptr
)
101 Frame
frame( frame_ptr
);
102 self
->frame_render_event( frame
);
105 // Remove all supers and attributes
106 void frame_render_event( Frame
&frame
)
108 // Fetch the c double ended queue structure
109 mlt_deque deque
= ( mlt_deque
)frame
.get_data( "data_queue" );
111 // While the deque isn't empty
112 while( deque
!= NULL
&& mlt_deque_peek_back( deque
) != NULL
)
114 // Fetch the c properties structure
115 mlt_properties cprops
= ( mlt_properties
)mlt_deque_pop_back( deque
);
117 // For fun, convert it to c++ and output it :-)
118 Properties
properties( cprops
);
122 mlt_properties_close( cprops
);
127 int main( int, char** )
129 Custom
server( "Server" );
131 server
.execute( "uadd sdl" );
132 server
.execute( "play u0" );
133 server
.wait_for_shutdown( );