001/*----------------------------------------------------------------------------*/
002/* Copyright (c) 2016-2018 FIRST. All Rights Reserved.                        */
003/* Open Source Software - may be modified and shared by FRC teams. The code   */
004/* must be accompanied by the FIRST BSD license file in the root directory of */
005/* the project.                                                               */
006/*----------------------------------------------------------------------------*/
007
008package edu.wpi.cscore;
009
010/**
011 * A source that represents a MJPEG-over-HTTP (IP) camera.
012 */
013public class HttpCamera extends VideoCamera {
014  public enum HttpCameraKind {
015    kUnknown(0), kMJPGStreamer(1), kCSCore(2), kAxis(3);
016    private int value;
017
018    private HttpCameraKind(int value) {
019      this.value = value;
020    }
021
022    public int getValue() {
023      return value;
024    }
025  }
026
027  public static HttpCameraKind getHttpCameraKindFromInt(int kind) {
028    switch (kind) {
029      case 1: return HttpCameraKind.kMJPGStreamer;
030      case 2: return HttpCameraKind.kCSCore;
031      case 3: return HttpCameraKind.kAxis;
032      default: return HttpCameraKind.kUnknown;
033    }
034  }
035
036  /**
037   * Create a source for a MJPEG-over-HTTP (IP) camera.
038   * @param name Source name (arbitrary unique identifier)
039   * @param url Camera URL (e.g. "http://10.x.y.11/video/stream.mjpg")
040   */
041  public HttpCamera(String name, String url) {
042    super(CameraServerJNI.createHttpCamera(name, url, HttpCameraKind.kUnknown.getValue()));
043  }
044
045  /**
046   * Create a source for a MJPEG-over-HTTP (IP) camera.
047   * @param name Source name (arbitrary unique identifier)
048   * @param url Camera URL (e.g. "http://10.x.y.11/video/stream.mjpg")
049   * @param kind Camera kind (e.g. kAxis)
050   */
051  public HttpCamera(String name, String url, HttpCameraKind kind) {
052    super(CameraServerJNI.createHttpCamera(name, url, kind.getValue()));
053  }
054
055  /**
056   * Create a source for a MJPEG-over-HTTP (IP) camera.
057   * @param name Source name (arbitrary unique identifier)
058   * @param urls Array of Camera URLs
059   */
060  public HttpCamera(String name, String[] urls) {
061    super(CameraServerJNI.createHttpCameraMulti(name, urls, HttpCameraKind.kUnknown.getValue()));
062  }
063
064  /**
065   * Create a source for a MJPEG-over-HTTP (IP) camera.
066   * @param name Source name (arbitrary unique identifier)
067   * @param urls Array of Camera URLs
068   * @param kind Camera kind (e.g. kAxis)
069   */
070  public HttpCamera(String name, String[] urls, HttpCameraKind kind) {
071    super(CameraServerJNI.createHttpCameraMulti(name, urls, kind.getValue()));
072  }
073
074  /**
075   * Get the kind of HTTP camera.
076   * Autodetection can result in returning a different value than the camera
077   * was created with.
078   */
079  public HttpCameraKind getHttpCameraKind() {
080    return getHttpCameraKindFromInt(CameraServerJNI.getHttpCameraKind(m_handle));
081  }
082
083  /**
084   * Change the URLs used to connect to the camera.
085   */
086  public void setUrls(String[] urls) {
087    CameraServerJNI.setHttpCameraUrls(m_handle, urls);
088  }
089
090  /**
091   * Get the URLs used to connect to the camera.
092   */
093  public String[] getUrls() {
094    return CameraServerJNI.getHttpCameraUrls(m_handle);
095  }
096}