RTMP client
The RTMP server supports any RTMP client, the industry standard being the one integrated into Adobe Flash/Flex. The method of connecting to and displaying an RTMP stream from neuray is identical to connecting to any other RTMP server. Adobe Flex 3 will be the example platform used; however, the concepts will transfer to any other platform.
The most convenient way to integrate RTMP stream into a Flex application is to create a new UIComponent which can simply be placed onto your Flex application canvas. This component will need instances of the three standard classes required to stream RTMP video: NetConnection, NetStream and Video.
public class Rs_rtmp_video extends UIComponent { private var m_connection:NetConnection = null; private var m_video:Video = null; private var m_stream:NetStream = null; ... }
The first thing that is required is to create a connection to the neuray RTMP server in an init() function.
public function init(url:String):void { m_connection = new NetConnection(); m_connection.addEventListener(NetStatusEvent.NET_STATUS, net_status_handler); m_connection.connect(url); }
When the connection is complete (or fails), Flex will call the net_status_handler listener registered in the init() call. This handler can then create the NetStream object and begin displaying the video.
private function net_status_handler(event:NetStatusEvent):void { if (event.info) { switch (event.info.code) { case "NetConnection.Connect.Success": m_stream = new NetStream(m_connection); m_video = new Video(this.width,this.height); m_video.attachNetStream(m_stream); addChild(m_video); m_stream.play("rs_stream"); break; case "NetConnection.Connect.Failed": break; } } }
The above implements a fully functional RTMP video streaming client. However, it is not particularly useful as it provides no interaction with neuray. For this we need to use the NetConnection::call interface to call registered RTMP call command message handlers.
The registered call handler is then called via the NetConnection call mechanism:
protected function move_camera(pan_x:Number, pan_y:Number):void { var arguments:Object = new Object(); arguments["pan_x"] = pan_x; arguments["pan_y"] = pan_y; m_connection.call("move_camera",null,arguments); }
The move_camera function would typically be called in reaction to mouse movement events.
The server side C++ application handler code for the above command call would look something like the code snippet below and would be registered on the server side as a call command handler using the Iray API method mi::rtmp::IConnection::register_remote_call_handler() on the mi::rtmp::IConnection interface.
class Call_event_handler : public mi::base::Interface_implement<mi::rtmp::ICall_event_handler> { public: bool handle( const char* procedure_name, const mi::IData* command_arguments, const mi::IData* user_arguments, mi::IData** response_arguments) { // Get the x and y coordinates from the user_argument and // reposition the camera. ... return true; } };
The examples included in the distribution include a complete flash client implementation with commented source code. This, together with the example RTMP application server source code provides a great start for building video streaming solutions.