001// Copyright (c) FIRST and other WPILib contributors.
002// Open Source Software; you can modify and/or share it under the terms of
003// the WPILib BSD license file in the root directory of this project.
004
005package edu.wpi.first.cscore;
006
007/** A source that represents a MJPEG-over-HTTP (IP) camera. */
008public class HttpCamera extends VideoCamera {
009  public enum HttpCameraKind {
010    kUnknown(0),
011    kMJPGStreamer(1),
012    kCSCore(2),
013    kAxis(3);
014
015    private final int value;
016
017    HttpCameraKind(int value) {
018      this.value = value;
019    }
020
021    public int getValue() {
022      return value;
023    }
024  }
025
026  /**
027   * Convert from the numerical representation of kind to an enum type.
028   *
029   * @param kind The numerical representation of kind
030   * @return The kind
031   */
032  public static HttpCameraKind getHttpCameraKindFromInt(int kind) {
033    switch (kind) {
034      case 1:
035        return HttpCameraKind.kMJPGStreamer;
036      case 2:
037        return HttpCameraKind.kCSCore;
038      case 3:
039        return HttpCameraKind.kAxis;
040      default:
041        return HttpCameraKind.kUnknown;
042    }
043  }
044
045  /**
046   * Create a source for a MJPEG-over-HTTP (IP) camera.
047   *
048   * @param name Source name (arbitrary unique identifier)
049   * @param url Camera URL (e.g. "http://10.x.y.11/video/stream.mjpg")
050   */
051  public HttpCamera(String name, String url) {
052    super(CameraServerJNI.createHttpCamera(name, url, HttpCameraKind.kUnknown.getValue()));
053  }
054
055  /**
056   * Create a source for a MJPEG-over-HTTP (IP) camera.
057   *
058   * @param name Source name (arbitrary unique identifier)
059   * @param url Camera URL (e.g. "http://10.x.y.11/video/stream.mjpg")
060   * @param kind Camera kind (e.g. kAxis)
061   */
062  public HttpCamera(String name, String url, HttpCameraKind kind) {
063    super(CameraServerJNI.createHttpCamera(name, url, kind.getValue()));
064  }
065
066  /**
067   * Create a source for a MJPEG-over-HTTP (IP) camera.
068   *
069   * @param name Source name (arbitrary unique identifier)
070   * @param urls Array of Camera URLs
071   */
072  public HttpCamera(String name, String[] urls) {
073    super(CameraServerJNI.createHttpCameraMulti(name, urls, HttpCameraKind.kUnknown.getValue()));
074  }
075
076  /**
077   * Create a source for a MJPEG-over-HTTP (IP) camera.
078   *
079   * @param name Source name (arbitrary unique identifier)
080   * @param urls Array of Camera URLs
081   * @param kind Camera kind (e.g. kAxis)
082   */
083  public HttpCamera(String name, String[] urls, HttpCameraKind kind) {
084    super(CameraServerJNI.createHttpCameraMulti(name, urls, kind.getValue()));
085  }
086
087  /**
088   * Get the kind of HTTP camera.
089   *
090   * <p>Autodetection can result in returning a different value than the camera was created with.
091   *
092   * @return The kind of HTTP camera.
093   */
094  public HttpCameraKind getHttpCameraKind() {
095    return getHttpCameraKindFromInt(CameraServerJNI.getHttpCameraKind(m_handle));
096  }
097
098  /**
099   * Change the URLs used to connect to the camera.
100   *
101   * @param urls Array of Camera URLs
102   */
103  public void setUrls(String[] urls) {
104    CameraServerJNI.setHttpCameraUrls(m_handle, urls);
105  }
106
107  /**
108   * Get the URLs used to connect to the camera.
109   *
110   * @return Array of camera URLs.
111   */
112  public String[] getUrls() {
113    return CameraServerJNI.getHttpCameraUrls(m_handle);
114  }
115}