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/** Video event. */ 008@SuppressWarnings("MemberName") 009public class VideoEvent { 010 /** VideoEvent kind. */ 011 public enum Kind { 012 /** Unknown video event. */ 013 kUnknown(0x0000), 014 /** Source Created event. */ 015 kSourceCreated(0x0001), 016 /** Source Destroyed event. */ 017 kSourceDestroyed(0x0002), 018 /** Source Connected event. */ 019 kSourceConnected(0x0004), 020 /** Source Disconnected event. */ 021 kSourceDisconnected(0x0008), 022 /** Source Video Modes Updated event. */ 023 kSourceVideoModesUpdated(0x0010), 024 /** Source VideoMode Changed event. */ 025 kSourceVideoModeChanged(0x0020), 026 /** Source Property Created event. */ 027 kSourcePropertyCreated(0x0040), 028 /** Source Property Value Updated event. */ 029 kSourcePropertyValueUpdated(0x0080), 030 /** Source Property Choices Updated event. */ 031 kSourcePropertyChoicesUpdated(0x0100), 032 /** Sink Source Changed event. */ 033 kSinkSourceChanged(0x0200), 034 /** Sink Created event. */ 035 kSinkCreated(0x0400), 036 /** Sink Destroyed event. */ 037 kSinkDestroyed(0x0800), 038 /** Sink Enabled event. */ 039 kSinkEnabled(0x1000), 040 /** Sink Disabled event. */ 041 kSinkDisabled(0x2000), 042 /** Network Interfaces Changed event. */ 043 kNetworkInterfacesChanged(0x4000), 044 /** Telemetry Updated event. */ 045 kTelemetryUpdated(0x8000), 046 /** Sink Property Created event. */ 047 kSinkPropertyCreated(0x10000), 048 /** Sink Property Value Updated event. */ 049 kSinkPropertyValueUpdated(0x20000), 050 /** Sink Property Choices Updated event. */ 051 kSinkPropertyChoicesUpdated(0x40000), 052 /** Usb Cameras Changed event. */ 053 kUsbCamerasChanged(0x80000); 054 055 private final int value; 056 057 Kind(int value) { 058 this.value = value; 059 } 060 061 /** 062 * Returns the kind value. 063 * 064 * @return The kind value. 065 */ 066 public int getValue() { 067 return value; 068 } 069 } 070 071 /** 072 * Convert from the numerical representation of kind to an enum type. 073 * 074 * @param kind The numerical representation of kind 075 * @return The kind 076 */ 077 public static Kind getKindFromInt(int kind) { 078 switch (kind) { 079 case 0x0001: 080 return Kind.kSourceCreated; 081 case 0x0002: 082 return Kind.kSourceDestroyed; 083 case 0x0004: 084 return Kind.kSourceConnected; 085 case 0x0008: 086 return Kind.kSourceDisconnected; 087 case 0x0010: 088 return Kind.kSourceVideoModesUpdated; 089 case 0x0020: 090 return Kind.kSourceVideoModeChanged; 091 case 0x0040: 092 return Kind.kSourcePropertyCreated; 093 case 0x0080: 094 return Kind.kSourcePropertyValueUpdated; 095 case 0x0100: 096 return Kind.kSourcePropertyChoicesUpdated; 097 case 0x0200: 098 return Kind.kSinkSourceChanged; 099 case 0x0400: 100 return Kind.kSinkCreated; 101 case 0x0800: 102 return Kind.kSinkDestroyed; 103 case 0x1000: 104 return Kind.kSinkEnabled; 105 case 0x2000: 106 return Kind.kSinkDisabled; 107 case 0x4000: 108 return Kind.kNetworkInterfacesChanged; 109 case 0x10000: 110 return Kind.kSinkPropertyCreated; 111 case 0x20000: 112 return Kind.kSinkPropertyValueUpdated; 113 case 0x40000: 114 return Kind.kSinkPropertyChoicesUpdated; 115 case 0x80000: 116 return Kind.kUsbCamerasChanged; 117 default: 118 return Kind.kUnknown; 119 } 120 } 121 122 VideoEvent( 123 int kind, 124 int source, 125 int sink, 126 String name, 127 int pixelFormat, 128 int width, 129 int height, 130 int fps, 131 int property, 132 int propertyKind, 133 int value, 134 String valueStr, 135 int listener) { 136 this.kind = getKindFromInt(kind); 137 this.sourceHandle = source; 138 this.sinkHandle = sink; 139 this.name = name; 140 this.mode = new VideoMode(pixelFormat, width, height, fps); 141 this.propertyHandle = property; 142 this.propertyKind = VideoProperty.getKindFromInt(propertyKind); 143 this.value = value; 144 this.valueStr = valueStr; 145 this.listener = listener; 146 } 147 148 /** The video event kind. */ 149 public Kind kind; 150 151 /** 152 * The source handle. 153 * 154 * <p>Valid for kSource* and kSink* respectively. 155 */ 156 public int sourceHandle; 157 158 /** The sink handle. */ 159 public int sinkHandle; 160 161 /** Source/sink/property name. */ 162 public String name; 163 164 // Fields for kSourceVideoModeChanged event. 165 166 /** New source video mode. */ 167 public VideoMode mode; 168 169 // Fields for kSourceProperty* events. 170 171 /** Source property handle. */ 172 public int propertyHandle; 173 174 /** Source property kind. */ 175 public VideoProperty.Kind propertyKind; 176 177 /** Event value. */ 178 public int value; 179 180 /** Event value as a string. */ 181 public String valueStr; 182 183 /** Listener that was triggered. */ 184 public int listener; 185 186 /** 187 * Returns the source associated with the event (if any). 188 * 189 * @return The source associated with the event (if any). 190 */ 191 public VideoSource getSource() { 192 return new VideoSource(CameraServerJNI.copySource(sourceHandle)); 193 } 194 195 /** 196 * Returns the sink associated with the event (if any). 197 * 198 * @return The sink associated with the event (if any). 199 */ 200 public VideoSink getSink() { 201 return new VideoSink(CameraServerJNI.copySink(sinkHandle)); 202 } 203 204 /** 205 * Returns the property associated with the event (if any). 206 * 207 * @return The property associated with the event (if any). 208 */ 209 public VideoProperty getProperty() { 210 return new VideoProperty(propertyHandle, propertyKind); 211 } 212}