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