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  /** HTTP camera kind. */
010  public enum HttpCameraKind {
011    /** Unknown camera kind. */
012    kUnknown(0),
013    /** MJPG Streamer camera. */
014    kMJPGStreamer(1),
015    /** CS Core camera. */
016    kCSCore(2),
017    /** Axis camera. */
018    kAxis(3);
019
020    private final int value;
021
022    HttpCameraKind(int value) {
023      this.value = value;
024    }
025
026    /**
027     * Returns HttpCameraKind value.
028     *
029     * @return HttpCameraKind value.
030     */
031    public int getValue() {
032      return value;
033    }
034  }
035
036  /**
037   * Convert from the numerical representation of kind to an enum type.
038   *
039   * @param kind The numerical representation of kind
040   * @return The kind
041   */
042  public static HttpCameraKind getHttpCameraKindFromInt(int kind) {
043    switch (kind) {
044      case 1:
045        return HttpCameraKind.kMJPGStreamer;
046      case 2:
047        return HttpCameraKind.kCSCore;
048      case 3:
049        return HttpCameraKind.kAxis;
050      default:
051        return HttpCameraKind.kUnknown;
052    }
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   */
061  public HttpCamera(String name, String url) {
062    super(CameraServerJNI.createHttpCamera(name, url, HttpCameraKind.kUnknown.getValue()));
063  }
064
065  /**
066   * Create a source for a MJPEG-over-HTTP (IP) camera.
067   *
068   * @param name Source name (arbitrary unique identifier)
069   * @param url Camera URL (e.g. "http://10.x.y.11/video/stream.mjpg")
070   * @param kind Camera kind (e.g. kAxis)
071   */
072  public HttpCamera(String name, String url, HttpCameraKind kind) {
073    super(CameraServerJNI.createHttpCamera(name, url, kind.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   */
082  public HttpCamera(String name, String[] urls) {
083    super(CameraServerJNI.createHttpCameraMulti(name, urls, HttpCameraKind.kUnknown.getValue()));
084  }
085
086  /**
087   * Create a source for a MJPEG-over-HTTP (IP) camera.
088   *
089   * @param name Source name (arbitrary unique identifier)
090   * @param urls Array of Camera URLs
091   * @param kind Camera kind (e.g. kAxis)
092   */
093  public HttpCamera(String name, String[] urls, HttpCameraKind kind) {
094    super(CameraServerJNI.createHttpCameraMulti(name, urls, kind.getValue()));
095  }
096
097  /**
098   * Get the kind of HTTP camera.
099   *
100   * <p>Autodetection can result in returning a different value than the camera was created with.
101   *
102   * @return The kind of HTTP camera.
103   */
104  public HttpCameraKind getHttpCameraKind() {
105    return getHttpCameraKindFromInt(CameraServerJNI.getHttpCameraKind(m_handle));
106  }
107
108  /**
109   * Change the URLs used to connect to the camera.
110   *
111   * @param urls Array of Camera URLs
112   */
113  public void setUrls(String[] urls) {
114    CameraServerJNI.setHttpCameraUrls(m_handle, urls);
115  }
116
117  /**
118   * Get the URLs used to connect to the camera.
119   *
120   * @return Array of camera URLs.
121   */
122  public String[] getUrls() {
123    return CameraServerJNI.getHttpCameraUrls(m_handle);
124  }
125}