如何使网络摄像机的视频与插座由动作?插座、摄像机、动作、网络

2023-09-08 11:47:05 作者:爱你需要你的努力

到目前为止,我找到了解决办法需要一个的crossdomain.xml 工作,但这不是用一个IP摄像头:

 < XML版本=1.0编码=UTF-8&GT?;
< MX:应用的xmlns:MX =htt​​p://www.adobe.com/2006/mxml布局=绝对applicationComplete =的init()>
    < MX:脚本>
        <![CDATA [
            进口utils.video.mjpeg.MJPEG;
            公共职能的init():无效{
                在Security.loadPolicyFile(的xmlsocket:HTTP://10.8.0.54/crossdomain.xml);
                跟踪(的xmlsocket:HTTP://10.8.0.54/crossdomain.xml)
                VAR VID:MJPEG =新MJPEG(10.8​​.0.54,,8081);
                video.rawChildren.addChild(VID);
            }
        ]]≥
    < / MX:脚本>
    < MX:垂直框ID =视频>< / MX:垂直框>
< / MX:用途>
//////////////////////////
包utils.video.mjpeg
{
    进口flash.display.Loader;
    进口对象类型:flash.events.Event;
    进口flash.events.ProgressEvent;
    进口flash.net.Socket;
    进口flash.utils.ByteArray的;

    进口mx.utils.Base64En codeR;

    / **
     *这是一个用来查看MJPEG类
     * @author乔什·切尔诺夫| GFX复杂
     *
     * /
    公共类MJPEG扩展装载机
    {
        私人VAR _user:字符串; //验证用户名
        私人VAR _pass:字符串; //验证用户密码

        私人VAR _host:字符串; //主机流服务器
        私人VAR _port:INT; //流口
        私人VAR _file:字符串; // MJPEG的位置
        私人VAR _start:= 0; //标记JPG开始

        私人VAR webcamSocket:插座=新的Socket(); //套接字连接
        私人VAR ImageBuffer的:ByteArray的=新的ByteArray(); //图像载体

        / **
         *创建的MJPEG编码类的新实例。请注意,由于沙箱的安全性问题,除非你能放置的crossdomain.xml
         *在主机服务器上,你只能在你的AIR应用程序使用这个类。
         *
         * @example进口MJPEG;
         * VAR凸轮:MJPEG =新MJPEG(192.168.0.100,/img/video.mjpeg,80);
         *的addChild(凸轮);
         *
         * @参数主持人:字符串|主机服务器。不包括协议
         * @参数文件:字符串|路径到服务器上的文件。以正斜杠
         *参数端口:INT |端口的主机服务器;
         * @参数用户:字符串|用户名验证
         * @参数通:字符串|用户密码验证
         * /
        公共职能MJPEG(主持人:字符串,文件:字符串,端口:INT = 80,用户:字符串=空,道:字符串= NULL)
        {
            _host =主机;
            _file =文件;
            _port =口;
            _user =用户;
            _pass =通;

            webcamSocket.addEventListener(Event.CONNECT,handleConnect);
            webcamSocket.addEventListener(ProgressEvent.SOCKET_DATA,handleData);
            webcamSocket.connect(主机,端口);

        }

        私有函数handleConnect(五:事件):无效
        {
            //我们发送连接请求
            VAR HTT prequest:字符串=GET+ _file +HTTP / 1.1 \ r \ N的;
            HTT prequest + =主机:本地主机:80 \ r \ N的;
            / *
            如果(_user = NULL和放大器;!&安培;!_pass = NULL){
                            VAR来源:字符串=字符串(_user +:+ _pass);
                            VAR AUTH:字符串= Base64.en code(源);
                            HTT prequest + =授权:基本+ auth.toString()+\ r \ N的; //注意,这可能NEEED进行编辑以与您的CAM
            }
             * /
            HTT prequest + =连接:保持活动\ r \ñ\ r \ N的;
            webcamSocket.writeMultiByte(HTT prequest,US-ASCII);
        }

        私有函数handleData(E:ProgressEvent):无效{
            //跟踪(得到的数据!+ E);
            //获取我们接收到的数据。

            //将数据追加到我们ImageBuffer的
            webcamSocket.readBytes(ImageBuffer的,imageBuffer.length);
            //trace(imageBuffer.length);
            而(findImages()){
            //没做什么
            }


        }


        私有函数findImages():布尔
        {

            VAR X:INT = _start;
            VAR startMarker:ByteArray的=新的ByteArray();
            VAR结束:= 0;
            VAR图片:ByteArray的;

            如果(imageBuffer.length→1){
                如果(_start == 0){
                    //检查JPG开始
                    为(X,X< imageBuffer.length  -  1; X ++){

                        //取得的前两个字节。
                        imageBuffer.position = X;
                        imageBuffer.readBytes(startMarker,0,2);

                        //检查JPG结束
                        如果(startMarker [0] == 255安培;&安培; startMarker [1] == 216){
                            _start = X;
                            打破;
                        }
                    }
                }
                为(X,X< imageBuffer.length  -  1; X ++){
                    //取得的前两个字节。
                    imageBuffer.position = X;
                    imageBuffer.readBytes(startMarker,0,2);
                    如果(startMarker [0] == 255安培;&安培; startMarker [1] == 217){

                        结束= X;

                        图像=新的ByteArray();
                        imageBuffer.position = _start;
                        imageBuffer.readBytes(图像,0,结束 -  _start);

                        displayImage(图像);

                        //截断ImageBuffer的
                        VAR newImageBuffer:ByteArray的=新的ByteArray();

                        imageBuffer.position =结束;
                        imageBuffer.readBytes(newImageBuffer,0);
                        ImageBuffer的= newImageBuffer;

                        _start = 0;
                        X = 0;
                        返回true;
                    }
                }
            }

            返回false;
        }

        私有函数displayImage(图片:ByteArray的):无效
        {
            this.loadBytes(图像);
        }

    }

}
 

解决方案

也许我不理解你的问题,但是如果我们在谈论同样的事情...

在我的闪存(这是写在AS2所以你可能需要查看它是如何在AS3不同,我注意到你不使用系统的安全类...他们可能已经删除了),我有这个行...

  System.security.loadPolicyFile(xml_root.socket://+ _root.HOST +:+ _root.GAME_PORT);
 
高清红外夜视插座摄像头远程监控无线飞利浦插排摄像机

我是pretty的肯定,这只是去,从我的服务器的文档根目录取静的crossdomain.xml。

在物联网的服务器端的套接字code(那是什么写的?)可以直接传递跨域策略。

下面是响应闪光灯插座的初始请求那块从我的Perl的插座。我很久以前写的这一点,但它会出现在插槽发送这个小小的XML片断作为它的插座上的初始通信<政策性文件的请求/>中针对您要做到以下几点...

 如果($输入EQ<政策性文件的请求/>中){#如果到达插座==&LT字符串;政策性文件的要求和GT;

  #assemble打印响应,活脱脱一个跨域策略文件。设置权限,你通常会。
  #如果你不知道的perl,QQ的〜就是一种提供多行code一大块的一个片段。但要注意的\ 0结尾。所有插座的消息都必须返回null手动终止。
  $消息= QQ〜<?XML版本=1.0>
                      <交域政策>
                      <允许存取来自域=*到端口=*/>
                      < /跨域策略> \ 0〜;
}
打印$消息; #send字符串后面的插座
 

确认这其实是你所需要的。有时候,你需要的是让服务器才有的crossdomain.xml策略文件坐在文档根目录。

So far the solution I found requires a crossdomain.xml to work,but this is not available on an IP camera:

<?xml version="1.0" encoding="utf-8"?>  
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" applicationComplete="init()">  
    <mx:Script>  
        <![CDATA[  
            import utils.video.mjpeg.MJPEG;  
            public function init():void{  
                Security.loadPolicyFile("xmlsocket:http://10.8.0.54/crossdomain.xml");  
                trace("xmlsocket:http://10.8.0.54/crossdomain.xml")  
                var vid:MJPEG = new MJPEG("10.8.0.54", "", 8081);  
                video.rawChildren.addChild(vid);  
            }  
        ]]>  
    </mx:Script>  
    <mx:VBox id="video"></mx:VBox>  
</mx:Application>  
//////////////////////////  
package  utils.video.mjpeg  
{  
    import flash.display.Loader;  
    import flash.events.Event;  
    import flash.events.ProgressEvent;  
    import flash.net.Socket;  
    import flash.utils.ByteArray;  

    import mx.utils.Base64Encoder;  

    /** 
     * This is a class used to view a MJPEG 
     * @author Josh Chernoff | GFX Complex 
     *  
     */  
    public class  MJPEG extends Loader  
    {  
        private var _user:String;                                   //Auth user name  
        private var _pass:String;                                   //Auth user password  

        private var _host:String;                                   //host server of stream  
        private var _port:int;                                      //port of stream          
        private var _file:String;                                   //Location of MJPEG  
        private var _start:int = 0;                                 //marker for start of jpg  

        private var webcamSocket:Socket = new Socket();             //socket connection  
        private var imageBuffer:ByteArray = new ByteArray();        //image holder  

        /** 
         * Create's a new instance of the MJPEG class. Note that due a sandbox security problem, unless you can place a crossdomain.xml  
         * on the host server you will only be able to use this class in your AIR applications. 
         *  
         * @example import MJPEG; 
         *          var cam:MJPEG = new MJPEG("192.168.0.100", "/img/video.mjpeg", 80); 
         *          addChild(cam); 
         *           
         * @param   host:String | Host of the server. Do not include protocol  
         * @param   file:String | Path to the file on the server. Start with a forward slash 
         * @param   port:int    | Port of the host server; 
         * @param   user:String | User name for Auth 
         * @param   pass:String | User password for Auth 
         */  
        public function MJPEG (host:String, file:String, port:int = 80, user:String = null, pass:String = null )  
        {  
            _host = host;  
            _file = file;  
            _port = port;  
            _user = user;  
            _pass = pass;  

            webcamSocket.addEventListener(Event.CONNECT, handleConnect);  
            webcamSocket.addEventListener(ProgressEvent.SOCKET_DATA, handleData);  
            webcamSocket.connect(host, port);  

        }  

        private function handleConnect(e:Event):void   
        {  
            // we're connected send a request  
            var httpRequest:String = "GET "+_file+" HTTP/1.1\r\n";  
            httpRequest+= "Host: localhost:80\r\n";  
            /*  
            if(_user != null && _pass != null){ 
                            var source:String = String(_user + ":" + _pass); 
                            var auth:String = Base64.encode(source); 
                            httpRequest += "Authorization: Basic " + auth.toString()+ "\r\n";   //NOTE THIS MAY NEEED TO BE EDITED TO WORK WITH YOUR CAM 
            } 
             */  
            httpRequest+="Connection: keep-alive\r\n\r\n";  
            webcamSocket.writeMultiByte(httpRequest, "us-ascii");  
        }  

        private function handleData(e:ProgressEvent):void {  
            //trace("Got Data!" + e);  
            // get the data that we received.  

            // append the data to our imageBuffer  
            webcamSocket.readBytes(imageBuffer, imageBuffer.length);  
            //trace(imageBuffer.length);  
            while(findImages()){  
            //donothing  
            }  


        }  


        private function findImages():Boolean  
        {  

            var x:int = _start;  
            var startMarker:ByteArray = new ByteArray();      
            var end:int = 0;  
            var image:ByteArray;  

            if (imageBuffer.length > 1) {  
                if(_start == 0){  
                    //Check for start of JPG  
                    for (x; x < imageBuffer.length - 1; x++) {  

                        // get the first two bytes.  
                        imageBuffer.position = x;  
                        imageBuffer.readBytes(startMarker, 0, 2);  

                        //Check for end of JPG  
                        if (startMarker[0] == 255 && startMarker[1] == 216) {  
                            _start = x;  
                            break;                    
                        }  
                    }  
                }  
                for (x; x < imageBuffer.length - 1; x++) {  
                    // get the first two bytes.  
                    imageBuffer.position = x;  
                    imageBuffer.readBytes(startMarker, 0, 2);  
                    if (startMarker[0] == 255 && startMarker[1] == 217){  

                        end = x;  

                        image = new ByteArray();  
                        imageBuffer.position = _start;  
                        imageBuffer.readBytes(image, 0, end - _start);  

                        displayImage(image);  

                        // truncate the imageBuffer  
                        var newImageBuffer:ByteArray = new ByteArray();  

                        imageBuffer.position = end;  
                        imageBuffer.readBytes(newImageBuffer, 0);  
                        imageBuffer = newImageBuffer;  

                        _start = 0;  
                        x = 0;  
                        return true;  
                    }  
                }  
            }  

            return false;  
        }  

        private function displayImage(image:ByteArray):void  
        {  
            this.loadBytes(image);  
        }  

    }  

}  

解决方案

Maybe I'm not understanding your question, but if we're talking about the same thing...

In my flash (which was written in AS2 so you may need to look up how it's different in AS3, I notice you're not using the security class of System... they may have removed that), I have this line...

System.security.loadPolicyFile("xml_root.socket://" + _root.HOST + ":" +_root.GAME_PORT );

I'm pretty sure this simply goes and fetches the static crossdomain.xml from the docroot of my server.

On the server side of things your socket code (what is that written in?) can deliver the crossdomain policy directly.

Here's the piece from my Perl socket that responds to the flash socket's initial request. I wrote this a long time ago but it would appear that the socket sends this tiny xml fragment as its initial communication to the socket "<policy-file-request/>" in response to which you want to do the following...

if($input eq "<policy-file-request/>"){ #if the string arriving on the socket == <policy-file-request>"

  #assemble the printed response to look just like a crossdomain policy file. Set permissions as you normally would.
  #if you don't know perl, the qq~ is just a way to provide a chunk of multiline code in one fragment.  But note the \0 at the end. All socket messages have to be null terminated manually by you.
  $MESSAGE =      qq~<?xml version="1.0"?>
                      <cross-domain-policy>
                      <allow-access-from domain="*" to-ports="*"/>
                      </cross-domain-policy>\0~;
}
print "$MESSAGE"; #send the string back on the socket

Make sure this is actually what you need. Sometimes all you need is for the server to just have the crossdomain.xml policy file sitting at the docroot.