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