{"action":"created","issue":{"url":"https://api.github.com/repos/sarxos/webcam-capture/issues/316","labels_url":"https://api.github.com/repos/sarxos/webcam-capture/issues/316/labels{/name}","comments_url":"https://api.github.com/repos/sarxos/webcam-capture/issues/316/comments","events_url":"https://api.github.com/repos/sarxos/webcam-capture/issues/316/events","html_url":"https://github.com/sarxos/webcam-capture/issues/316","id":58946426,"number":316,"title":"Would you like a view of architect - project web (running jetty) + Webcam-capture-ipcam","user":{"login":"henriquem","id":5496634,"avatar_url":"https://avatars.githubusercontent.com/u/5496634?v=3","gravatar_id":"","url":"https://api.github.com/users/henriquem","html_url":"https://github.com/henriquem","followers_url":"https://api.github.com/users/henriquem/followers","following_url":"https://api.github.com/users/henriquem/following{/other_user}","gists_url":"https://api.github.com/users/henriquem/gists{/gist_id}","starred_url":"https://api.github.com/users/henriquem/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/henriquem/subscriptions","organizations_url":"https://api.github.com/users/henriquem/orgs","repos_url":"https://api.github.com/users/henriquem/repos","events_url":"https://api.github.com/users/henriquem/events{/privacy}","received_events_url":"https://api.github.com/users/henriquem/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-02-25T18:20:20Z","updated_at":"2015-02-26T12:45:40Z","closed_at":null,"body":"I would like to listen the opinion from Sarxos about this Architecture:\r\nplease at look if It is recommended ?\r\n\r\nI would like to create an project web, in HTML and jetty-websocket I can transmit images in HTML \r\nThe following solution is ugly?\r\n\r\nMy Thread for each Camera registered:\r\n\r\n    class ThreadIpCamera  extends Thread implements WebcamMotionListener{\r\n\t\t\t\t    WebcamMotionDetector detectorMoviment;\r\n\t\t\t\t\tprivate String name; // Related IpCamMpjeg name=#1... for this thread\r\n\t\t\t\t\tThreadIpCamera(WebCam web,String name){\r\n\t\t\t\t\t    this.name=name;\r\n\t\t\t\t\t    detectorMoviment = new WebcamMotionDetector(camera);\r\n\t\t\t\t\t    detectorMoviment.setInterval(500); // one check per 500 ms\r\n\t\t\t\t\t    detectorMoviment.addMotionListener(this);\r\n\t\t\t\t\t    detectorMoviment.start();\r\n\t\t\t\t    }\r\n    }\r\n\r\nIn web.xml (jetty container)\r\n\r\n    <!-- load cameras when starting my jetty container-->\r\n    <servlet>\r\n        <description>Servlet initialize all IPCameras</description>\r\n        <display-name>ThreadsCamerasIP</display-name>\r\n        <servlet-name>ThreadsCamerasIP</servlet-name>\r\n        <servlet-class>com.myproject.LoadCamerasIPServlet</servlet-class>\r\n        <load-on-startup>1</load-on-startup> \r\n    </servlet>\r\n\r\nWhen Start Jetty load All IP Cameras and start an Thread for these:\r\n\r\n     class LoadCamerasIPServlet extends HttpServlet {\r\n            public void init(ServletConfig config) throws ServletException {\r\n                Webcam.setDriver(new IpCamDriver());\r\n                IpCamDeviceRegistry.register(new IPCamMjpeg(\"#1\", \"http://ip1\", IpCamMode.PUSH, \"admin\", \"123456\"));\r\n                IpCamDeviceRegistry.register(new IPCamMjpeg(\"#2\", \"http://ip2\", IpCamMode.PUSH, \"admin\", \"123456\"));\r\n                IpCamDeviceRegistry.register(new IPCamMjpeg(\"#3\", \"http://ip3\", IpCamMode.PUSH, \"admin\", \"123456\"));\r\n\t\t\t\r\n                List<Webcam> webcams = Webcam.getWebcams();\r\n                    for (Webcam webcam : webcams) {\r\n\t\t\t\t    webcam.getLock().disable();\r\n\t\t\t\t    /* start a thread for each camera treatment */\r\n\t\t\t\t    new ThreadIpCamera(webcam, webcam.getName()).start(); \r\n\t\t\t    }\r\n\t\t    }\r\n     }\r\n\r\nConclusion:\r\n\r\nAnother Alternative I send to Trash all code above, and Create 2 projects: 1 Project Web, and Java Desktop;\r\nSo When  starting Jettty container, start also the java desktop, where Java Desktop contains only WebCam framework and ThreadIpCamera class and each motion from camera, send request for http://localhost ? \r\nEx. new URL(\"localhost/NotifyWebSocket?cam=1&img_encoded=AERe324$3ds....... \r\n\r\nPlease could you help me, what the options is better model arquitecture ?\r\n\r\nThks"},"comment":{"url":"https://api.github.com/repos/sarxos/webcam-capture/issues/comments/76172061","html_url":"https://github.com/sarxos/webcam-capture/issues/316#issuecomment-76172061","issue_url":"https://api.github.com/repos/sarxos/webcam-capture/issues/316","id":76172061,"user":{"login":"sarxos","id":472658,"avatar_url":"https://avatars.githubusercontent.com/u/472658?v=3","gravatar_id":"","url":"https://api.github.com/users/sarxos","html_url":"https://github.com/sarxos","followers_url":"https://api.github.com/users/sarxos/followers","following_url":"https://api.github.com/users/sarxos/following{/other_user}","gists_url":"https://api.github.com/users/sarxos/gists{/gist_id}","starred_url":"https://api.github.com/users/sarxos/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sarxos/subscriptions","organizations_url":"https://api.github.com/users/sarxos/orgs","repos_url":"https://api.github.com/users/sarxos/repos","events_url":"https://api.github.com/users/sarxos/events{/privacy}","received_events_url":"https://api.github.com/users/sarxos/received_events","type":"User","site_admin":false},"created_at":"2015-02-26T12:45:40Z","updated_at":"2015-02-26T12:45:40Z","body":"If you consider these two options, either:\r\n\r\n* Have a server stack and transmit images to frontend via ```ws://```, or\r\n* Have a server stack and desktop application to transmit images via MJPEG stream,\r\n\r\nI think the first option is better. The work overhead is smaller in first case and the web traffic generated by the MJPEG and WebSocket is pretty the same. Moreover, if you have motion listener you can send new images just in case when motion has been detected, which decreases traffic needs. This is not true in case of MJPEG.\r\n\r\nJust a note. Please do not mess with the webcam lock. It was designed to prevent opening camera twice. This may not has such big impact in case of IP camera, but you for sure do not want to waste the bandwidth to transmit images which will never be used. Thus, you should get rid of this:\r\n\r\n```java\r\nwebcam.getLock().disable();\r\n```\r\n"}}