001package com.github.sarxos.webcam.ds.ipcam.device.xvision; 002 003import java.awt.Dimension; 004import java.net.MalformedURLException; 005import java.net.URL; 006 007import com.github.sarxos.webcam.WebcamException; 008import com.github.sarxos.webcam.ds.ipcam.IpCamDevice; 009import com.github.sarxos.webcam.ds.ipcam.IpCamMode; 010 011 012/** 013 * Speed Dome X104S IP Camera by XVision. 014 * 015 * @author Bartosz Firyn (SarXos) 016 */ 017public class X104S extends IpCamDevice { 018 019 public static final Dimension SIZE_SXGA = new Dimension(1280, 1024); 020 public static final Dimension SIZE_VGA = new Dimension(640, 480); 021 public static final Dimension SIZE_QVGA = new Dimension(320, 240); 022 public static final Dimension SIZE_QQVGA = new Dimension(160, 128); 023 024 //@formatter:off 025 private static final Dimension[] SIZES = new Dimension[] { 026 SIZE_SXGA, 027 SIZE_VGA, 028 SIZE_QVGA, 029 SIZE_QQVGA, 030 }; 031 //@formatter:on 032 033 private URL base = null; 034 035 public X104S(String name, String urlBase) { 036 this(name, toURL(urlBase)); 037 } 038 039 public X104S(String name, URL base) { 040 super(name, (URL) null, IpCamMode.PUSH); 041 this.base = base; 042 } 043 044 @Override 045 public Dimension[] getResolutions() { 046 return SIZES; 047 } 048 049 @Override 050 public void setResolution(Dimension size) { 051 052 int index = -1; 053 for (int i = 0; i < SIZES.length; i++) { 054 if (SIZES[i].equals(size)) { 055 index = i; 056 break; 057 } 058 } 059 060 if (index == -1) { 061 throw new IllegalArgumentException(String.format("Incorrect size %s", size)); 062 } 063 064 super.setResolution(size); 065 } 066 067 @Override 068 public URL getURL() { 069 070 int index = -1; 071 for (int i = 0; i < SIZES.length; i++) { 072 if (SIZES[i].equals(getResolution())) { 073 index = i; 074 break; 075 } 076 } 077 078 String r = ""; 079 switch (index) { 080 case 0: 081 r = "sxga"; 082 break; 083 case 1: 084 r = "vga"; 085 break; 086 case 2: 087 r = "qvga"; 088 break; 089 case 3: 090 r = "qqvga"; 091 break; 092 } 093 094 String url = String.format("%s/video.cgi?resolution=%s&random=0.%s", base, r, System.currentTimeMillis()); 095 096 try { 097 return new URL(url); 098 } catch (MalformedURLException e) { 099 throw new WebcamException(String.format("Incorrect URL %s", url), e); 100 } 101 } 102 103}