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 * Video event
012 */
013public class VideoEvent {
014  public enum Kind {
015    kUnknown(0x0000),
016    kSourceCreated(0x0001),
017    kSourceDestroyed(0x0002),
018    kSourceConnected(0x0004),
019    kSourceDisconnected(0x0008),
020    kSourceVideoModesUpdated(0x0010),
021    kSourceVideoModeChanged(0x0020),
022    kSourcePropertyCreated(0x0040),
023    kSourcePropertyValueUpdated(0x0080),
024    kSourcePropertyChoicesUpdated(0x0100),
025    kSinkSourceChanged(0x0200),
026    kSinkCreated(0x0400),
027    kSinkDestroyed(0x0800),
028    kSinkEnabled(0x1000),
029    kSinkDisabled(0x2000),
030    kNetworkInterfacesChanged(0x4000);
031
032    private int value;
033
034    private Kind(int value) {
035      this.value = value;
036    }
037
038    public int getValue() {
039      return value;
040    }
041  }
042
043  public static Kind getKindFromInt(int kind) {
044    switch (kind) {
045      case 0x0001: return Kind.kSourceCreated;
046      case 0x0002: return Kind.kSourceDestroyed;
047      case 0x0004: return Kind.kSourceConnected;
048      case 0x0008: return Kind.kSourceDisconnected;
049      case 0x0010: return Kind.kSourceVideoModesUpdated;
050      case 0x0020: return Kind.kSourceVideoModeChanged;
051      case 0x0040: return Kind.kSourcePropertyCreated;
052      case 0x0080: return Kind.kSourcePropertyValueUpdated;
053      case 0x0100: return Kind.kSourcePropertyChoicesUpdated;
054      case 0x0200: return Kind.kSinkSourceChanged;
055      case 0x0400: return Kind.kSinkCreated;
056      case 0x0800: return Kind.kSinkDestroyed;
057      case 0x1000: return Kind.kSinkEnabled;
058      case 0x2000: return Kind.kSinkDisabled;
059      case 0x4000: return Kind.kNetworkInterfacesChanged;
060      default: return Kind.kUnknown;
061    }
062  }
063
064  VideoEvent(int kind, int source, int sink, String name, int pixelFormat,
065             int width, int height, int fps, int property, int propertyKind,
066             int value, String valueStr) {
067    this.kind = getKindFromInt(kind);
068    this.sourceHandle = source;
069    this.sinkHandle = sink;
070    this.name = name;
071    this.mode = new VideoMode(pixelFormat, width, height, fps);
072    this.propertyHandle = property;
073    this.propertyKind = VideoProperty.getKindFromInt(propertyKind);
074    this.value = value;
075    this.valueStr = valueStr;
076  }
077
078  public Kind kind;
079
080  // Valid for kSource* and kSink* respectively
081  public int sourceHandle;
082  public int sinkHandle;
083
084  // Source/sink/property name
085  public String name;
086
087  // Fields for kSourceVideoModeChanged event
088  public VideoMode mode;
089
090  // Fields for kSourceProperty* events
091  public int propertyHandle;
092  public VideoProperty.Kind propertyKind;
093  public int value;
094  public String valueStr;
095
096  public VideoSource getSource() {
097    return new VideoSource(CameraServerJNI.copySource(sourceHandle));
098  }
099
100  public VideoSink getSink() {
101    return new VideoSink(CameraServerJNI.copySink(sinkHandle));
102  }
103
104  public VideoProperty getProperty() {
105    return new VideoProperty(propertyHandle, propertyKind);
106  }
107
108}