001/*----------------------------------------------------------------------------*/
002/* Copyright (c) FIRST 2016. 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/// A source that represents a MJPEG-over-HTTP (IP) camera.
011public class HttpCamera extends VideoCamera {
012  public enum HttpCameraKind {
013    kUnknown(0), kMJPGStreamer(1), kCSCore(2), kAxis(3);
014    private int value;
015
016    private HttpCameraKind(int value) {
017      this.value = value;
018    }
019
020    public int getValue() {
021      return value;
022    }
023  }
024
025  public static HttpCameraKind getHttpCameraKindFromInt(int kind) {
026    switch (kind) {
027      case 1: return HttpCameraKind.kMJPGStreamer;
028      case 2: return HttpCameraKind.kCSCore;
029      case 3: return HttpCameraKind.kAxis;
030      default: return HttpCameraKind.kUnknown;
031    }
032  }
033
034  /// Create a source for a MJPEG-over-HTTP (IP) camera.
035  /// @param name Source name (arbitrary unique identifier)
036  /// @param url Camera URL (e.g. "http://10.x.y.11/video/stream.mjpg")
037  public HttpCamera(String name, String url) {
038    super(CameraServerJNI.createHttpCamera(name, url, HttpCameraKind.kUnknown.getValue()));
039  }
040
041  /// Create a source for a MJPEG-over-HTTP (IP) camera.
042  /// @param name Source name (arbitrary unique identifier)
043  /// @param url Camera URL (e.g. "http://10.x.y.11/video/stream.mjpg")
044  /// @param kind Camera kind (e.g. kAxis)
045  public HttpCamera(String name, String url, HttpCameraKind kind) {
046    super(CameraServerJNI.createHttpCamera(name, url, kind.getValue()));
047  }
048
049  /// Create a source for a MJPEG-over-HTTP (IP) camera.
050  /// @param name Source name (arbitrary unique identifier)
051  /// @param urls Array of Camera URLs
052  public HttpCamera(String name, String[] urls) {
053    super(CameraServerJNI.createHttpCameraMulti(name, urls, HttpCameraKind.kUnknown.getValue()));
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  /// @param kind Camera kind (e.g. kAxis)
060  public HttpCamera(String name, String[] urls, HttpCameraKind kind) {
061    super(CameraServerJNI.createHttpCameraMulti(name, urls, kind.getValue()));
062  }
063
064  /// Get the kind of HTTP camera.
065  /// Autodetection can result in returning a different value than the camera
066  /// was created with.
067  public HttpCameraKind getHttpCameraKind() {
068    return getHttpCameraKindFromInt(CameraServerJNI.getHttpCameraKind(m_handle));
069  }
070
071  /// Change the URLs used to connect to the camera.
072  public void setUrls(String[] urls) {
073    CameraServerJNI.setHttpCameraUrls(m_handle, urls);
074  }
075
076  /// Get the URLs used to connect to the camera.
077  public String[] getUrls() {
078    return CameraServerJNI.getHttpCameraUrls(m_handle);
079  }
080}