Switches to the new build system (#87)

* Removes old build system

* Removes old gmock

* Adds new gmock

* Moves source files to new locations

* Adds new build system
This commit is contained in:
Thad House
2017-08-18 17:52:08 -07:00
committed by Peter Johnson
parent 9d45088127
commit 133540f577
96 changed files with 940 additions and 1687 deletions

347
src/arm-linux-jni/LICENSE Normal file
View File

@@ -0,0 +1,347 @@
The GNU General Public License (GPL)
Version 2, June 1991
Copyright (C) 1989, 1991 Free Software Foundation, Inc.
59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Everyone is permitted to copy and distribute verbatim copies of this license
document, but changing it is not allowed.
Preamble
The licenses for most software are designed to take away your freedom to share
and change it. By contrast, the GNU General Public License is intended to
guarantee your freedom to share and change free software--to make sure the
software is free for all its users. This General Public License applies to
most of the Free Software Foundation's software and to any other program whose
authors commit to using it. (Some other Free Software Foundation software is
covered by the GNU Library General Public License instead.) You can apply it to
your programs, too.
When we speak of free software, we are referring to freedom, not price. Our
General Public Licenses are designed to make sure that you have the freedom to
distribute copies of free software (and charge for this service if you wish),
that you receive source code or can get it if you want it, that you can change
the software or use pieces of it in new free programs; and that you know you
can do these things.
To protect your rights, we need to make restrictions that forbid anyone to deny
you these rights or to ask you to surrender the rights. These restrictions
translate to certain responsibilities for you if you distribute copies of the
software, or if you modify it.
For example, if you distribute copies of such a program, whether gratis or for
a fee, you must give the recipients all the rights that you have. You must
make sure that they, too, receive or can get the source code. And you must
show them these terms so they know their rights.
We protect your rights with two steps: (1) copyright the software, and (2)
offer you this license which gives you legal permission to copy, distribute
and/or modify the software.
Also, for each author's protection and ours, we want to make certain that
everyone understands that there is no warranty for this free software. If the
software is modified by someone else and passed on, we want its recipients to
know that what they have is not the original, so that any problems introduced
by others will not reflect on the original authors' reputations.
Finally, any free program is threatened constantly by software patents. We
wish to avoid the danger that redistributors of a free program will
individually obtain patent licenses, in effect making the program proprietary.
To prevent this, we have made it clear that any patent must be licensed for
everyone's free use or not licensed at all.
The precise terms and conditions for copying, distribution and modification
follow.
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. This License applies to any program or other work which contains a notice
placed by the copyright holder saying it may be distributed under the terms of
this General Public License. The "Program", below, refers to any such program
or work, and a "work based on the Program" means either the Program or any
derivative work under copyright law: that is to say, a work containing the
Program or a portion of it, either verbatim or with modifications and/or
translated into another language. (Hereinafter, translation is included
without limitation in the term "modification".) Each licensee is addressed as
"you".
Activities other than copying, distribution and modification are not covered by
this License; they are outside its scope. The act of running the Program is
not restricted, and the output from the Program is covered only if its contents
constitute a work based on the Program (independent of having been made by
running the Program). Whether that is true depends on what the Program does.
1. You may copy and distribute verbatim copies of the Program's source code as
you receive it, in any medium, provided that you conspicuously and
appropriately publish on each copy an appropriate copyright notice and
disclaimer of warranty; keep intact all the notices that refer to this License
and to the absence of any warranty; and give any other recipients of the
Program a copy of this License along with the Program.
You may charge a fee for the physical act of transferring a copy, and you may
at your option offer warranty protection in exchange for a fee.
2. You may modify your copy or copies of the Program or any portion of it, thus
forming a work based on the Program, and copy and distribute such modifications
or work under the terms of Section 1 above, provided that you also meet all of
these conditions:
a) You must cause the modified files to carry prominent notices stating
that you changed the files and the date of any change.
b) You must cause any work that you distribute or publish, that in whole or
in part contains or is derived from the Program or any part thereof, to be
licensed as a whole at no charge to all third parties under the terms of
this License.
c) If the modified program normally reads commands interactively when run,
you must cause it, when started running for such interactive use in the
most ordinary way, to print or display an announcement including an
appropriate copyright notice and a notice that there is no warranty (or
else, saying that you provide a warranty) and that users may redistribute
the program under these conditions, and telling the user how to view a copy
of this License. (Exception: if the Program itself is interactive but does
not normally print such an announcement, your work based on the Program is
not required to print an announcement.)
These requirements apply to the modified work as a whole. If identifiable
sections of that work are not derived from the Program, and can be reasonably
considered independent and separate works in themselves, then this License, and
its terms, do not apply to those sections when you distribute them as separate
works. But when you distribute the same sections as part of a whole which is a
work based on the Program, the distribution of the whole must be on the terms
of this License, whose permissions for other licensees extend to the entire
whole, and thus to each and every part regardless of who wrote it.
Thus, it is not the intent of this section to claim rights or contest your
rights to work written entirely by you; rather, the intent is to exercise the
right to control the distribution of derivative or collective works based on
the Program.
In addition, mere aggregation of another work not based on the Program with the
Program (or with a work based on the Program) on a volume of a storage or
distribution medium does not bring the other work under the scope of this
License.
3. You may copy and distribute the Program (or a work based on it, under
Section 2) in object code or executable form under the terms of Sections 1 and
2 above provided that you also do one of the following:
a) Accompany it with the complete corresponding machine-readable source
code, which must be distributed under the terms of Sections 1 and 2 above
on a medium customarily used for software interchange; or,
b) Accompany it with a written offer, valid for at least three years, to
give any third party, for a charge no more than your cost of physically
performing source distribution, a complete machine-readable copy of the
corresponding source code, to be distributed under the terms of Sections 1
and 2 above on a medium customarily used for software interchange; or,
c) Accompany it with the information you received as to the offer to
distribute corresponding source code. (This alternative is allowed only
for noncommercial distribution and only if you received the program in
object code or executable form with such an offer, in accord with
Subsection b above.)
The source code for a work means the preferred form of the work for making
modifications to it. For an executable work, complete source code means all
the source code for all modules it contains, plus any associated interface
definition files, plus the scripts used to control compilation and installation
of the executable. However, as a special exception, the source code
distributed need not include anything that is normally distributed (in either
source or binary form) with the major components (compiler, kernel, and so on)
of the operating system on which the executable runs, unless that component
itself accompanies the executable.
If distribution of executable or object code is made by offering access to copy
from a designated place, then offering equivalent access to copy the source
code from the same place counts as distribution of the source code, even though
third parties are not compelled to copy the source along with the object code.
4. You may not copy, modify, sublicense, or distribute the Program except as
expressly provided under this License. Any attempt otherwise to copy, modify,
sublicense or distribute the Program is void, and will automatically terminate
your rights under this License. However, parties who have received copies, or
rights, from you under this License will not have their licenses terminated so
long as such parties remain in full compliance.
5. You are not required to accept this License, since you have not signed it.
However, nothing else grants you permission to modify or distribute the Program
or its derivative works. These actions are prohibited by law if you do not
accept this License. Therefore, by modifying or distributing the Program (or
any work based on the Program), you indicate your acceptance of this License to
do so, and all its terms and conditions for copying, distributing or modifying
the Program or works based on it.
6. Each time you redistribute the Program (or any work based on the Program),
the recipient automatically receives a license from the original licensor to
copy, distribute or modify the Program subject to these terms and conditions.
You may not impose any further restrictions on the recipients' exercise of the
rights granted herein. You are not responsible for enforcing compliance by
third parties to this License.
7. If, as a consequence of a court judgment or allegation of patent
infringement or for any other reason (not limited to patent issues), conditions
are imposed on you (whether by court order, agreement or otherwise) that
contradict the conditions of this License, they do not excuse you from the
conditions of this License. If you cannot distribute so as to satisfy
simultaneously your obligations under this License and any other pertinent
obligations, then as a consequence you may not distribute the Program at all.
For example, if a patent license would not permit royalty-free redistribution
of the Program by all those who receive copies directly or indirectly through
you, then the only way you could satisfy both it and this License would be to
refrain entirely from distribution of the Program.
If any portion of this section is held invalid or unenforceable under any
particular circumstance, the balance of the section is intended to apply and
the section as a whole is intended to apply in other circumstances.
It is not the purpose of this section to induce you to infringe any patents or
other property right claims or to contest validity of any such claims; this
section has the sole purpose of protecting the integrity of the free software
distribution system, which is implemented by public license practices. Many
people have made generous contributions to the wide range of software
distributed through that system in reliance on consistent application of that
system; it is up to the author/donor to decide if he or she is willing to
distribute software through any other system and a licensee cannot impose that
choice.
This section is intended to make thoroughly clear what is believed to be a
consequence of the rest of this License.
8. If the distribution and/or use of the Program is restricted in certain
countries either by patents or by copyrighted interfaces, the original
copyright holder who places the Program under this License may add an explicit
geographical distribution limitation excluding those countries, so that
distribution is permitted only in or among countries not thus excluded. In
such case, this License incorporates the limitation as if written in the body
of this License.
9. The Free Software Foundation may publish revised and/or new versions of the
General Public License from time to time. Such new versions will be similar in
spirit to the present version, but may differ in detail to address new problems
or concerns.
Each version is given a distinguishing version number. If the Program
specifies a version number of this License which applies to it and "any later
version", you have the option of following the terms and conditions either of
that version or of any later version published by the Free Software Foundation.
If the Program does not specify a version number of this License, you may
choose any version ever published by the Free Software Foundation.
10. If you wish to incorporate parts of the Program into other free programs
whose distribution conditions are different, write to the author to ask for
permission. For software which is copyrighted by the Free Software Foundation,
write to the Free Software Foundation; we sometimes make exceptions for this.
Our decision will be guided by the two goals of preserving the free status of
all derivatives of our free software and of promoting the sharing and reuse of
software generally.
NO WARRANTY
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR
THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE
STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE
PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND
PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE,
YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL
ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE
PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR
INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA
BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER
OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest possible
use to the public, the best way to achieve this is to make it free software
which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest to attach
them to the start of each source file to most effectively convey the exclusion
of warranty; and each file should have at least the "copyright" line and a
pointer to where the full notice is found.
One line to give the program's name and a brief idea of what it does.
Copyright (C) <year> <name of author>
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the Free
Software Foundation; either version 2 of the License, or (at your option)
any later version.
This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc., 59
Temple Place, Suite 330, Boston, MA 02111-1307 USA
Also add information on how to contact you by electronic and paper mail.
If the program is interactive, make it output a short notice like this when it
starts in an interactive mode:
Gnomovision version 69, Copyright (C) year name of author Gnomovision comes
with ABSOLUTELY NO WARRANTY; for details type 'show w'. This is free
software, and you are welcome to redistribute it under certain conditions;
type 'show c' for details.
The hypothetical commands 'show w' and 'show c' should show the appropriate
parts of the General Public License. Of course, the commands you use may be
called something other than 'show w' and 'show c'; they could even be
mouse-clicks or menu items--whatever suits your program.
You should also get your employer (if you work as a programmer) or your school,
if any, to sign a "copyright disclaimer" for the program, if necessary. Here
is a sample; alter the names:
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
'Gnomovision' (which makes passes at compilers) written by James Hacker.
signature of Ty Coon, 1 April 1989
Ty Coon, President of Vice
This General Public License does not permit incorporating your program into
proprietary programs. If your program is a subroutine library, you may
consider it more useful to permit linking proprietary applications with the
library. If this is what you want to do, use the GNU Library General Public
License instead of this License.
"CLASSPATH" EXCEPTION TO THE GPL
Certain source files distributed by Oracle America and/or its affiliates are
subject to the following clarification and special exception to the GPL, but
only where Oracle has expressly included in the particular source file's header
the words "Oracle designates this particular file as subject to the "Classpath"
exception as provided by Oracle in the LICENSE file that accompanied this code."
Linking this library statically or dynamically with other modules is making
a combined work based on this library. Thus, the terms and conditions of
the GNU General Public License cover the whole combination.
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent modules,
and to copy and distribute the resulting executable under terms of your
choice, provided that you also meet, for each linked independent module,
the terms and conditions of the license of that module. An independent
module is a module which is not derived from or based on this library. If
you modify this library, you may extend this exception to your version of
the library, but you are not obligated to do so. If you do not wish to do
so, delete this exception statement from your version.

1960
src/arm-linux-jni/jni.h Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,51 @@
/*
* Copyright (c) 1996, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
#ifndef _JAVASOFT_JNI_MD_H_
#define _JAVASOFT_JNI_MD_H_
#ifndef __has_attribute
#define __has_attribute(x) 0
#endif
#if (defined(__GNUC__) && ((__GNUC__ > 4) || (__GNUC__ == 4) && (__GNUC_MINOR__ > 2))) || __has_attribute(visibility)
#define JNIEXPORT __attribute__((visibility("default")))
#define JNIIMPORT __attribute__((visibility("default")))
#else
#define JNIEXPORT
#define JNIIMPORT
#endif
#define JNICALL
typedef int jint;
#ifdef _LP64 /* 64-bit Solaris */
typedef long jlong;
#else
typedef long long jlong;
#endif
typedef signed char jbyte;
#endif /* !_JAVASOFT_JNI_MD_H_ */

View File

@@ -0,0 +1,12 @@
package edu.wpi.cscore;
import edu.wpi.cscore.CameraServerJNI;
import edu.wpi.first.wpiutil.RuntimeDetector;
public class DevMain {
public static void main(String[] args) {
System.out.println("Hello World!");
System.out.println(RuntimeDetector.getPlatformPath());
System.out.println(CameraServerJNI.getHostname());
}
}

View File

@@ -0,0 +1,6 @@
#include <iostream>
#include "cscore.h"
int main() {
std::cout << cs::GetHostname() << std::endl;
}

View File

@@ -0,0 +1,43 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2016. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
/*----------------------------------------------------------------------------*/
package edu.wpi.cscore;
/**
* A source that represents an Axis IP camera.
*/
public class AxisCamera extends HttpCamera {
private static String hostToUrl(String host) {
return "http://" + host + "/mjpg/video.mjpg";
}
private static String[] hostToUrl(String[] hosts) {
String[] urls = new String[hosts.length];
for (int i = 0; i < hosts.length; i++) {
urls[i] = hostToUrl(hosts[i]);
}
return urls;
}
/**
* Create a source for an Axis IP camera.
* @param name Source name (arbitrary unique identifier)
* @param host Camera host IP or DNS name (e.g. "10.x.y.11")
*/
public AxisCamera(String name, String host) {
super(name, hostToUrl(host), HttpCameraKind.kAxis);
}
/**
* Create a source for an Axis IP camera.
* @param name Source name (arbitrary unique identifier)
* @param hosts Array of Camera host IPs/DNS names
*/
public AxisCamera(String name, String[] hosts) {
super(name, hostToUrl(hosts), HttpCameraKind.kAxis);
}
}

View File

@@ -0,0 +1,255 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2016. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
/*----------------------------------------------------------------------------*/
package edu.wpi.cscore;
import java.io.File;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.util.function.Consumer;
import org.opencv.core.Core;
import edu.wpi.first.wpiutil.RuntimeDetector;
public class CameraServerJNI {
static boolean libraryLoaded = false;
static File jniLibrary = null;
static boolean cvLibraryLoaded = false;
static File cvJniLibrary = null;
static {
if (!libraryLoaded) {
try {
System.loadLibrary("cscore");
} catch (UnsatisfiedLinkError e) {
try {
String resname = RuntimeDetector.getLibraryResource("cscore");
InputStream is = CameraServerJNI.class.getResourceAsStream(resname);
if (is != null) {
// create temporary file
if (System.getProperty("os.name").startsWith("Windows"))
jniLibrary = File.createTempFile("CameraServerJNI", ".dll");
else if (System.getProperty("os.name").startsWith("Mac"))
jniLibrary = File.createTempFile("libCameraServerJNI", ".dylib");
else
jniLibrary = File.createTempFile("libCameraServerJNI", ".so");
// flag for delete on exit
jniLibrary.deleteOnExit();
OutputStream os = new FileOutputStream(jniLibrary);
byte[] buffer = new byte[1024];
int readBytes;
try {
while ((readBytes = is.read(buffer)) != -1) {
os.write(buffer, 0, readBytes);
}
} finally {
os.close();
is.close();
}
System.load(jniLibrary.getAbsolutePath());
} else {
System.loadLibrary("cscore");
}
} catch (IOException ex) {
ex.printStackTrace();
System.exit(1);
}
}
libraryLoaded = true;
}
String opencvName = Core.NATIVE_LIBRARY_NAME;
if (!cvLibraryLoaded) {
try {
System.loadLibrary(opencvName);
} catch (UnsatisfiedLinkError e) {
try {
String resname = RuntimeDetector.getLibraryResource(opencvName);
InputStream is = CameraServerJNI.class.getResourceAsStream(resname);
if (is != null) {
// create temporary file
if (System.getProperty("os.name").startsWith("Windows"))
cvJniLibrary = File.createTempFile("OpenCVJNI", ".dll");
else if (System.getProperty("os.name").startsWith("Mac"))
cvJniLibrary = File.createTempFile("libOpenCVJNI", ".dylib");
else
cvJniLibrary = File.createTempFile("libOpenCVJNI", ".so");
// flag for delete on exit
cvJniLibrary.deleteOnExit();
OutputStream os = new FileOutputStream(cvJniLibrary);
byte[] buffer = new byte[1024];
int readBytes;
try {
while ((readBytes = is.read(buffer)) != -1) {
os.write(buffer, 0, readBytes);
}
} finally {
os.close();
is.close();
}
System.load(cvJniLibrary.getAbsolutePath());
} else {
System.loadLibrary(opencvName);
}
} catch (IOException ex) {
ex.printStackTrace();
System.exit(1);
}
}
cvLibraryLoaded = true;
}
}
public static void ForceLoad() {}
//
// Property Functions
//
public static native int getPropertyKind(int property);
public static native String getPropertyName(int property);
public static native int getProperty(int property);
public static native void setProperty(int property, int value);
public static native int getPropertyMin(int property);
public static native int getPropertyMax(int property);
public static native int getPropertyStep(int property);
public static native int getPropertyDefault(int property);
public static native String getStringProperty(int property);
public static native void setStringProperty(int property, String value);
public static native String[] getEnumPropertyChoices(int property);
//
// Source Creation Functions
//
public static native int createUsbCameraDev(String name, int dev);
public static native int createUsbCameraPath(String name, String path);
public static native int createHttpCamera(String name, String url, int kind);
public static native int createHttpCameraMulti(String name, String[] urls, int kind);
public static native int createCvSource(String name, int pixelFormat, int width, int height, int fps);
//
// Source Functions
//
public static native int getSourceKind(int source);
public static native String getSourceName(int source);
public static native String getSourceDescription(int source);
public static native long getSourceLastFrameTime(int source);
public static native boolean isSourceConnected(int source);
public static native int getSourceProperty(int source, String name);
public static native int[] enumerateSourceProperties(int source);
public static native VideoMode getSourceVideoMode(int source);
public static native boolean setSourceVideoMode(int source, int pixelFormat, int width, int height, int fps);
public static native boolean setSourcePixelFormat(int source, int pixelFormat);
public static native boolean setSourceResolution(int source, int width, int height);
public static native boolean setSourceFPS(int source, int fps);
public static native VideoMode[] enumerateSourceVideoModes(int source);
public static native int[] enumerateSourceSinks(int source);
public static native int copySource(int source);
public static native void releaseSource(int source);
//
// Camera Source Common Property Fuctions
//
public static native void setCameraBrightness(int source, int brightness);
public static native int getCameraBrightness(int source);
public static native void setCameraWhiteBalanceAuto(int source);
public static native void setCameraWhiteBalanceHoldCurrent(int source);
public static native void setCameraWhiteBalanceManual(int source, int value);
public static native void setCameraExposureAuto(int source);
public static native void setCameraExposureHoldCurrent(int source);
public static native void setCameraExposureManual(int source, int value);
//
// UsbCamera Source Functions
//
public static native String getUsbCameraPath(int source);
//
// HttpCamera Source Functions
//
public static native int getHttpCameraKind(int source);
public static native void setHttpCameraUrls(int source, String[] urls);
public static native String[] getHttpCameraUrls(int source);
//
// OpenCV Source Functions
//
public static native void putSourceFrame(int source, long imageNativeObj);
public static native void notifySourceError(int source, String msg);
public static native void setSourceConnected(int source, boolean connected);
public static native void setSourceDescription(int source, String description);
public static native int createSourceProperty(int source, String name, int kind, int minimum, int maximum, int step, int defaultValue, int value);
public static native void setSourceEnumPropertyChoices(int source, int property, String[] choices);
//
// Sink Creation Functions
//
public static native int createMjpegServer(String name, String listenAddress, int port);
public static native int createCvSink(String name);
//public static native int createCvSinkCallback(String name,
// void (*processFrame)(long time));
//
// Sink Functions
//
public static native int getSinkKind(int sink);
public static native String getSinkName(int sink);
public static native String getSinkDescription(int sink);
public static native void setSinkSource(int sink, int source);
public static native int getSinkSourceProperty(int sink, String name);
public static native int getSinkSource(int sink);
public static native int copySink(int sink);
public static native void releaseSink(int sink);
//
// MjpegServer Sink Functions
//
public static native String getMjpegServerListenAddress(int sink);
public static native int getMjpegServerPort(int sink);
//
// OpenCV Sink Functions
//
public static native void setSinkDescription(int sink, String description);
public static native long grabSinkFrame(int sink, long imageNativeObj);
public static native long grabSinkFrameTimeout(int sink, long imageNativeObj, double timeout);
public static native String getSinkError(int sink);
public static native void setSinkEnabled(int sink, boolean enabled);
//
// Listener Functions
//
public static native int addListener(Consumer<VideoEvent> listener,
int eventMask, boolean immediateNotify);
public static native void removeListener(int handle);
//
// Logging Functions
//
@FunctionalInterface
public interface LoggerFunction {
void apply(int level, String file, int line, String msg);
}
public static native void setLogger(LoggerFunction func, int minLevel);
//
// Utility Functions
//
public static native UsbCameraInfo[] enumerateUsbCameras();
public static native int[] enumerateSources();
public static native int[] enumerateSinks();
public static native String getHostname();
public static native String[] getNetworkInterfaces();
}

View File

@@ -0,0 +1,96 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2016. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
/*----------------------------------------------------------------------------*/
package edu.wpi.cscore;
import org.opencv.core.Mat;
/**
* A sink for user code to accept video frames as OpenCV images.
*/
public class CvSink extends VideoSink {
/**
* Create a sink for accepting OpenCV images.
* WaitForFrame() must be called on the created sink to get each new
* image.
* @param name Source name (arbitrary unique identifier)
*/
public CvSink(String name) {
super(CameraServerJNI.createCvSink(name));
}
/// Create a sink for accepting OpenCV images in a separate thread.
/// A thread will be created that calls WaitForFrame() and calls the
/// processFrame() callback each time a new frame arrives.
/// @param name Source name (arbitrary unique identifier)
/// @param processFrame Frame processing function; will be called with a
/// time=0 if an error occurred. processFrame should call GetImage()
/// or GetError() as needed, but should not call (except in very
/// unusual circumstances) WaitForImage().
//public CvSink(llvm::StringRef name,
// std::function<void(uint64_t time)> processFrame) {
// super(CameraServerJNI.createCvSinkCallback(name, processFrame));
//}
/**
* Set sink description.
* @param description Description
*/
public void setDescription(String description) {
CameraServerJNI.setSinkDescription(m_handle, description);
}
/**
* Wait for the next frame and get the image.
* Times out (returning 0) after 0.225 seconds.
* The provided image will have three 3-bit channels stored in BGR order.
* @return Frame time, or 0 on error (call GetError() to obtain the error
* message)
*/
public long grabFrame(Mat image) {
return grabFrame(image, 0.225);
}
/**
* Wait for the next frame and get the image.
* Times out (returning 0) after timeout seconds.
* The provided image will have three 3-bit channels stored in BGR order.
* @return Frame time, or 0 on error (call GetError() to obtain the error
* message)
*/
public long grabFrame(Mat image, double timeout) {
return CameraServerJNI.grabSinkFrameTimeout(m_handle, image.nativeObj, timeout);
}
/**
* Wait for the next frame and get the image. May block forever.
* The provided image will have three 3-bit channels stored in BGR order.
* @return Frame time, or 0 on error (call GetError() to obtain the error
* message)
*/
public long grabFrameNoTimeout(Mat image) {
return CameraServerJNI.grabSinkFrame(m_handle, image.nativeObj);
}
/**
* Get error string. Call this if WaitForFrame() returns 0 to determine
* what the error is.
*/
public String getError() {
return CameraServerJNI.getSinkError(m_handle);
}
/**
* Enable or disable getting new frames.
* Disabling will cause processFrame (for callback-based CvSinks) to not
* be called and WaitForFrame() to not return. This can be used to save
* processor resources when frames are not needed.
*/
public void setEnabled(boolean enabled) {
CameraServerJNI.setSinkEnabled(m_handle, enabled);
}
}

View File

@@ -0,0 +1,145 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2016. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
/*----------------------------------------------------------------------------*/
package edu.wpi.cscore;
import org.opencv.core.Mat;
/**
* A source that represents a video camera.
*/
public class CvSource extends VideoSource {
/**
* Create an OpenCV source.
* @param name Source name (arbitrary unique identifier)
* @param mode Video mode being generated
*/
public CvSource(String name, VideoMode mode) {
super(CameraServerJNI.createCvSource(name, mode.pixelFormat.getValue(), mode.width, mode.height, mode.fps));
}
/**
* Create an OpenCV source.
* @param name Source name (arbitrary unique identifier)
* @param pixelFormat Pixel format
* @param width width
* @param height height
* @param fps fps
*/
public CvSource(String name, VideoMode.PixelFormat pixelFormat, int width, int height, int fps) {
super(CameraServerJNI.createCvSource(name, pixelFormat.getValue(), width, height, fps));
}
/**
* Put an OpenCV image and notify sinks.
* Only 8-bit single-channel or 3-channel (with BGR channel order) images
* are supported. If the format, depth or channel order is different, use
* Mat.convertTo() and/or cvtColor() to convert it first.
* @param image OpenCV image
*/
public void putFrame(Mat image) {
CameraServerJNI.putSourceFrame(m_handle, image.nativeObj);
}
/**
* Signal sinks that an error has occurred. This should be called instead
* of NotifyFrame when an error occurs.
*/
public void notifyError(String msg) {
CameraServerJNI.notifySourceError(m_handle, msg);
}
/**
* Set source connection status. Defaults to true.
* @param connected True for connected, false for disconnected
*/
public void setConnected(boolean connected) {
CameraServerJNI.setSourceConnected(m_handle, connected);
}
/**
* Set source description.
* @param description Description
*/
public void setDescription(String description) {
CameraServerJNI.setSourceDescription(m_handle, description);
}
/**
* Create a property.
* @param name Property name
* @param kind Property kind
* @param minimum Minimum value
* @param maximum Maximum value
* @param step Step value
* @param defaultValue Default value
* @param value Current value
* @return Property
*/
public VideoProperty createProperty(String name, VideoProperty.Kind kind, int minimum, int maximum, int step, int defaultValue, int value) {
return new VideoProperty(
CameraServerJNI.createSourceProperty(m_handle, name, kind.getValue(), minimum, maximum, step, defaultValue, value));
}
/// Create an integer property.
/// @param name Property name
/// @param minimum Minimum value
/// @param maximum Maximum value
/// @param step Step value
/// @param defaultValue Default value
/// @param value Current value
/// @return Property
public VideoProperty createIntegerProperty(String name, int minimum, int maximum, int step, int defaultValue, int value) {
return new VideoProperty(
CameraServerJNI.createSourceProperty(m_handle, name, VideoProperty.Kind.kInteger.getValue(), minimum, maximum, step, defaultValue, value));
}
/// Create a boolean property.
/// @param name Property name
/// @param defaultValue Default value
/// @param value Current value
/// @return Property
public VideoProperty createBooleanProperty(String name, boolean defaultValue, boolean value) {
return new VideoProperty(
CameraServerJNI.createSourceProperty(m_handle, name, VideoProperty.Kind.kBoolean.getValue(), 0, 1, 1, defaultValue ? 1 : 0, value ? 1 : 0));
}
/// Create a string property.
/// @param name Property name
/// @param value Current value
/// @return Property
public VideoProperty createStringProperty(String name, String value) {
VideoProperty prop = new VideoProperty(
CameraServerJNI.createSourceProperty(m_handle, name, VideoProperty.Kind.kString.getValue(), 0, 0, 0, 0, 0));
prop.setString(value);
return prop;
}
/// Create a property with a change callback.
/// @param name Property name
/// @param kind Property kind
/// @param minimum Minimum value
/// @param maximum Maximum value
/// @param step Step value
/// @param defaultValue Default value
/// @param value Current value
/// @param onChange Callback to call when the property value changes
/// @return Property
//public VideoProperty createProperty(
// String name, VideoProperty.Kind kind, int minimum, int maximum, int step, int defaultValue, int value,
// std::function<void(VideoProperty property)>
// onChange);
/**
* Configure enum property choices.
* @param property Property
* @param choices Choices
*/
public void SetEnumPropertyChoices(VideoProperty property, String[] choices) {
CameraServerJNI.setSourceEnumPropertyChoices(m_handle, property.m_handle, choices);
}
}

View File

@@ -0,0 +1,96 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2016. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
/*----------------------------------------------------------------------------*/
package edu.wpi.cscore;
/**
* A source that represents a MJPEG-over-HTTP (IP) camera.
*/
public class HttpCamera extends VideoCamera {
public enum HttpCameraKind {
kUnknown(0), kMJPGStreamer(1), kCSCore(2), kAxis(3);
private int value;
private HttpCameraKind(int value) {
this.value = value;
}
public int getValue() {
return value;
}
}
public static HttpCameraKind getHttpCameraKindFromInt(int kind) {
switch (kind) {
case 1: return HttpCameraKind.kMJPGStreamer;
case 2: return HttpCameraKind.kCSCore;
case 3: return HttpCameraKind.kAxis;
default: return HttpCameraKind.kUnknown;
}
}
/**
* Create a source for a MJPEG-over-HTTP (IP) camera.
* @param name Source name (arbitrary unique identifier)
* @param url Camera URL (e.g. "http://10.x.y.11/video/stream.mjpg")
*/
public HttpCamera(String name, String url) {
super(CameraServerJNI.createHttpCamera(name, url, HttpCameraKind.kUnknown.getValue()));
}
/**
* Create a source for a MJPEG-over-HTTP (IP) camera.
* @param name Source name (arbitrary unique identifier)
* @param url Camera URL (e.g. "http://10.x.y.11/video/stream.mjpg")
* @param kind Camera kind (e.g. kAxis)
*/
public HttpCamera(String name, String url, HttpCameraKind kind) {
super(CameraServerJNI.createHttpCamera(name, url, kind.getValue()));
}
/**
* Create a source for a MJPEG-over-HTTP (IP) camera.
* @param name Source name (arbitrary unique identifier)
* @param urls Array of Camera URLs
*/
public HttpCamera(String name, String[] urls) {
super(CameraServerJNI.createHttpCameraMulti(name, urls, HttpCameraKind.kUnknown.getValue()));
}
/**
* Create a source for a MJPEG-over-HTTP (IP) camera.
* @param name Source name (arbitrary unique identifier)
* @param urls Array of Camera URLs
* @param kind Camera kind (e.g. kAxis)
*/
public HttpCamera(String name, String[] urls, HttpCameraKind kind) {
super(CameraServerJNI.createHttpCameraMulti(name, urls, kind.getValue()));
}
/**
* Get the kind of HTTP camera.
* Autodetection can result in returning a different value than the camera
* was created with.
*/
public HttpCameraKind getHttpCameraKind() {
return getHttpCameraKindFromInt(CameraServerJNI.getHttpCameraKind(m_handle));
}
/**
* Change the URLs used to connect to the camera.
*/
public void setUrls(String[] urls) {
CameraServerJNI.setHttpCameraUrls(m_handle, urls);
}
/**
* Get the URLs used to connect to the camera.
*/
public String[] getUrls() {
return CameraServerJNI.getHttpCameraUrls(m_handle);
}
}

View File

@@ -0,0 +1,46 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2016. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
/*----------------------------------------------------------------------------*/
package edu.wpi.cscore;
/**
* A sink that acts as a MJPEG-over-HTTP network server.
*/
public class MjpegServer extends VideoSink {
/**
* Create a MJPEG-over-HTTP server sink.
* @param name Sink name (arbitrary unique identifier)
* @param listenAddress TCP listen address (empty string for all addresses)
* @param port TCP port number
*/
public MjpegServer(String name, String listenAddress, int port) {
super(CameraServerJNI.createMjpegServer(name, listenAddress, port));
}
/**
* Create a MJPEG-over-HTTP server sink.
* @param name Sink name (arbitrary unique identifier)
* @param port TCP port number
*/
public MjpegServer(String name, int port) {
this(name, "", port);
}
/**
* Get the listen address of the server.
*/
public String getListenAddress() {
return CameraServerJNI.getMjpegServerListenAddress(m_handle);
}
/**
* Get the port number of the server.
*/
public int getPort() {
return CameraServerJNI.getMjpegServerPort(m_handle);
}
}

View File

@@ -0,0 +1,46 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2016. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
/*----------------------------------------------------------------------------*/
package edu.wpi.cscore;
/**
* A source that represents a USB camera.
*/
public class UsbCamera extends VideoCamera {
/**
* Create a source for a USB camera based on device number.
* @param name Source name (arbitrary unique identifier)
* @param dev Device number (e.g. 0 for /dev/video0)
*/
public UsbCamera(String name, int dev) {
super(CameraServerJNI.createUsbCameraDev(name, dev));
}
/**
* Create a source for a USB camera based on device path.
* @param name Source name (arbitrary unique identifier)
* @param path Path to device (e.g. "/dev/video0" on Linux)
*/
public UsbCamera(String name, String path) {
super(CameraServerJNI.createUsbCameraPath(name, path));
}
/**
* Enumerate USB cameras on the local system.
* @return Vector of USB camera information (one for each camera)
*/
public static UsbCameraInfo[] enumerateUsbCameras() {
return CameraServerJNI.enumerateUsbCameras();
}
/**
* Get the path to the device.
*/
public String getPath() {
return CameraServerJNI.getUsbCameraPath(m_handle);
}
}

View File

@@ -0,0 +1,34 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2016. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
/*----------------------------------------------------------------------------*/
package edu.wpi.cscore;
/**
* USB camera information
*/
public class UsbCameraInfo {
public UsbCameraInfo(int dev, String path, String name) {
this.dev = dev;
this.path = path;
this.name = name;
}
/**
* Device number (e.g. N in '/dev/videoN' on Linux)
*/
public int dev;
/**
* Path to device if available (e.g. '/dev/video0' on Linux)
*/
public String path;
/**
* Vendor/model name of the camera as provided by the USB driver
*/
public String name;
}

View File

@@ -0,0 +1,81 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2016. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
/*----------------------------------------------------------------------------*/
package edu.wpi.cscore;
/**
* A source that represents a video camera.
*/
public class VideoCamera extends VideoSource {
public class WhiteBalance {
public static final int kFixedIndoor = 3000;
public static final int kFixedOutdoor1 = 4000;
public static final int kFixedOutdoor2 = 5000;
public static final int kFixedFluorescent1 = 5100;
public static final int kFixedFlourescent2 = 5200;
}
protected VideoCamera(int handle) {
super(handle);
}
/**
* Set the brightness, as a percentage (0-100).
*/
public synchronized void setBrightness(int brightness) {
CameraServerJNI.setCameraBrightness(m_handle, brightness);
}
/**
* Get the brightness, as a percentage (0-100).
*/
public synchronized int getBrightness() {
return CameraServerJNI.getCameraBrightness(m_handle);
}
/**
* Set the white balance to auto.
*/
public synchronized void setWhiteBalanceAuto() {
CameraServerJNI.setCameraWhiteBalanceAuto(m_handle);
}
/**
* Set the white balance to hold current.
*/
public synchronized void setWhiteBalanceHoldCurrent() {
CameraServerJNI.setCameraWhiteBalanceHoldCurrent(m_handle);
}
/**
* Set the white balance to manual, with specified color temperature.
*/
public synchronized void setWhiteBalanceManual(int value) {
CameraServerJNI.setCameraWhiteBalanceManual(m_handle, value);
}
/**
* Set the exposure to auto aperture.
*/
public synchronized void setExposureAuto() {
CameraServerJNI.setCameraExposureAuto(m_handle);
}
/**
* Set the exposure to hold current.
*/
public synchronized void setExposureHoldCurrent() {
CameraServerJNI.setCameraExposureHoldCurrent(m_handle);
}
/**
* Set the exposure to manual, as a percentage (0-100).
*/
public synchronized void setExposureManual(int value) {
CameraServerJNI.setCameraExposureManual(m_handle, value);
}
}

View File

@@ -0,0 +1,108 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2016. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
/*----------------------------------------------------------------------------*/
package edu.wpi.cscore;
/**
* Video event
*/
public class VideoEvent {
public enum Kind {
kUnknown(0x0000),
kSourceCreated(0x0001),
kSourceDestroyed(0x0002),
kSourceConnected(0x0004),
kSourceDisconnected(0x0008),
kSourceVideoModesUpdated(0x0010),
kSourceVideoModeChanged(0x0020),
kSourcePropertyCreated(0x0040),
kSourcePropertyValueUpdated(0x0080),
kSourcePropertyChoicesUpdated(0x0100),
kSinkSourceChanged(0x0200),
kSinkCreated(0x0400),
kSinkDestroyed(0x0800),
kSinkEnabled(0x1000),
kSinkDisabled(0x2000),
kNetworkInterfacesChanged(0x4000);
private int value;
private Kind(int value) {
this.value = value;
}
public int getValue() {
return value;
}
}
public static Kind getKindFromInt(int kind) {
switch (kind) {
case 0x0001: return Kind.kSourceCreated;
case 0x0002: return Kind.kSourceDestroyed;
case 0x0004: return Kind.kSourceConnected;
case 0x0008: return Kind.kSourceDisconnected;
case 0x0010: return Kind.kSourceVideoModesUpdated;
case 0x0020: return Kind.kSourceVideoModeChanged;
case 0x0040: return Kind.kSourcePropertyCreated;
case 0x0080: return Kind.kSourcePropertyValueUpdated;
case 0x0100: return Kind.kSourcePropertyChoicesUpdated;
case 0x0200: return Kind.kSinkSourceChanged;
case 0x0400: return Kind.kSinkCreated;
case 0x0800: return Kind.kSinkDestroyed;
case 0x1000: return Kind.kSinkEnabled;
case 0x2000: return Kind.kSinkDisabled;
case 0x4000: return Kind.kNetworkInterfacesChanged;
default: return Kind.kUnknown;
}
}
VideoEvent(int kind, int source, int sink, String name, int pixelFormat,
int width, int height, int fps, int property, int propertyKind,
int value, String valueStr) {
this.kind = getKindFromInt(kind);
this.sourceHandle = source;
this.sinkHandle = sink;
this.name = name;
this.mode = new VideoMode(pixelFormat, width, height, fps);
this.propertyHandle = property;
this.propertyKind = VideoProperty.getKindFromInt(propertyKind);
this.value = value;
this.valueStr = valueStr;
}
public Kind kind;
// Valid for kSource* and kSink* respectively
public int sourceHandle;
public int sinkHandle;
// Source/sink/property name
public String name;
// Fields for kSourceVideoModeChanged event
public VideoMode mode;
// Fields for kSourceProperty* events
public int propertyHandle;
public VideoProperty.Kind propertyKind;
public int value;
public String valueStr;
public VideoSource getSource() {
return new VideoSource(CameraServerJNI.copySource(sourceHandle));
}
public VideoSink getSink() {
return new VideoSink(CameraServerJNI.copySink(sinkHandle));
}
public VideoProperty getProperty() {
return new VideoProperty(propertyHandle, propertyKind);
}
}

View File

@@ -0,0 +1,22 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2016. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
/*----------------------------------------------------------------------------*/
package edu.wpi.cscore;
/**
* An exception raised by the camera server.
*/
public class VideoException extends RuntimeException {
public VideoException(String msg) {
super(msg);
}
@Override
public String toString() {
return "VideoException [" + super.toString() + "]";
}
}

View File

@@ -0,0 +1,41 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2016. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
/*----------------------------------------------------------------------------*/
package edu.wpi.cscore;
import java.util.function.Consumer;
/**
* An event listener. This calls back to a desigated callback function when
* an event matching the specified mask is generated by the library.
*/
public class VideoListener {
/**
* Create an event listener.
* @param listener Listener function
* @param eventMask Bitmask of VideoEvent.Type values
* @param immediateNotify Whether callback should be immediately called with
* a representative set of events for the current library state.
*/
public VideoListener(Consumer<VideoEvent> listener, int eventMask,
boolean immediateNotify) {
m_handle = CameraServerJNI.addListener(listener, eventMask, immediateNotify);
}
public synchronized void free() {
if (m_handle != 0) {
CameraServerJNI.removeListener(m_handle);
}
m_handle = 0;
}
public boolean isValid() {
return m_handle != 0;
}
private int m_handle;
}

View File

@@ -0,0 +1,65 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2016. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
/*----------------------------------------------------------------------------*/
package edu.wpi.cscore;
/**
* Video mode
*/
public class VideoMode {
public enum PixelFormat {
kUnknown(0), kMJPEG(1), kYUYV(2), kRGB565(3), kBGR(4), kGray(5);
private int value;
private PixelFormat(int value) {
this.value = value;
}
public int getValue() {
return value;
}
}
private static final PixelFormat[] m_pixelFormatValues = PixelFormat.values();
public static PixelFormat getPixelFormatFromInt(int pixelFormat) {
return m_pixelFormatValues[pixelFormat];
}
public VideoMode(int pixelFormat, int width, int height, int fps) {
this.pixelFormat = getPixelFormatFromInt(pixelFormat);
this.width = width;
this.height = height;
this.fps = fps;
}
public VideoMode(PixelFormat pixelFormat, int width, int height, int fps) {
this.pixelFormat = pixelFormat;
this.width = width;
this.height = height;
this.fps = fps;
}
/**
* Pixel format
*/
public PixelFormat pixelFormat;
/**
* Width in pixels
*/
public int width;
/**
* Height in pixels
*/
public int height;
/**
* Frames per second
*/
public int fps;
}

View File

@@ -0,0 +1,113 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2016. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
/*----------------------------------------------------------------------------*/
package edu.wpi.cscore;
public class VideoProperty {
public enum Kind {
kNone(0), kBoolean(1), kInteger(2), kString(4), kEnum(8);
private int value;
private Kind(int value) {
this.value = value;
}
public int getValue() {
return value;
}
}
public static Kind getKindFromInt(int kind) {
switch (kind) {
case 1: return Kind.kBoolean;
case 2: return Kind.kInteger;
case 4: return Kind.kString;
case 8: return Kind.kEnum;
default: return Kind.kNone;
}
}
public String getName() {
return CameraServerJNI.getPropertyName(m_handle);
}
public Kind getKind() {
return m_kind;
}
public boolean isValid() {
return m_kind != Kind.kNone;
}
// Kind checkers
public boolean isBoolean() {
return m_kind == Kind.kBoolean;
}
public boolean isInteger() {
return m_kind == Kind.kInteger;
}
public boolean isString() {
return m_kind == Kind.kString;
}
public boolean isEnum() {
return m_kind == Kind.kEnum;
}
public int get() {
return CameraServerJNI.getProperty(m_handle);
}
public void set(int value) {
CameraServerJNI.setProperty(m_handle, value);
}
public int getMin() {
return CameraServerJNI.getPropertyMin(m_handle);
}
public int getMax() {
return CameraServerJNI.getPropertyMax(m_handle);
}
public int getStep() {
return CameraServerJNI.getPropertyStep(m_handle);
}
public int getDefault() {
return CameraServerJNI.getPropertyDefault(m_handle);
}
// String-specific functions
public String getString() {
return CameraServerJNI.getStringProperty(m_handle);
}
public void setString(String value) {
CameraServerJNI.setStringProperty(m_handle, value);
}
// Enum-specific functions
public String[] getChoices() {
return CameraServerJNI.getEnumPropertyChoices(m_handle);
}
VideoProperty(int handle) {
m_handle = handle;
m_kind = getKindFromInt(CameraServerJNI.getPropertyKind(handle));
}
VideoProperty(int handle, Kind kind) {
m_handle = handle;
m_kind = kind;
}
int m_handle;
private Kind m_kind;
}

View File

@@ -0,0 +1,139 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2016. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
/*----------------------------------------------------------------------------*/
package edu.wpi.cscore;
/**
* A source for video that provides a sequence of frames. Each frame may
* consist of multiple images (e.g. from a stereo or depth camera); these
* are called channels.
*/
public class VideoSink {
public enum Kind {
kUnknown(0), kMjpeg(2), kCv(4);
private int value;
private Kind(int value) {
this.value = value;
}
public int getValue() {
return value;
}
}
public static Kind getKindFromInt(int kind) {
switch (kind) {
case 2: return Kind.kMjpeg;
case 4: return Kind.kCv;
default: return Kind.kUnknown;
}
}
protected VideoSink(int handle) {
m_handle = handle;
}
public synchronized void free() {
if (m_handle != 0) {
CameraServerJNI.releaseSink(m_handle);
}
m_handle = 0;
}
public boolean isValid() {
return m_handle != 0;
}
public int getHandle() {
return m_handle;
}
public boolean equals(Object other) {
if (this == other) return true;
if (other == null) return false;
if (getClass() != other.getClass()) return false;
VideoSink sink = (VideoSink) other;
return m_handle == sink.m_handle;
}
public int hashCode() {
return m_handle;
}
/**
* Get the kind of the sink.
*/
public Kind getKind() {
return getKindFromInt(CameraServerJNI.getSinkKind(m_handle));
}
/**
* Get the name of the sink. The name is an arbitrary identifier
* provided when the sink is created, and should be unique.
*/
public String getName() {
return CameraServerJNI.getSinkName(m_handle);
}
/**
* Get the sink description. This is sink-kind specific.
*/
public String getDescription() {
return CameraServerJNI.getSinkDescription(m_handle);
}
/**
* Configure which source should provide frames to this sink. Each sink
* can accept frames from only a single source, but a single source can
* provide frames to multiple clients.
* @param source Source
*/
public void setSource(VideoSource source) {
if (source == null) {
CameraServerJNI.setSinkSource(m_handle, 0);
} else {
CameraServerJNI.setSinkSource(m_handle, source.m_handle);
}
}
/**
* Get the connected source.
* @return Connected source; nullptr if no source connected.
*/
public VideoSource getSource() {
// While VideoSource.free() will call releaseSource(), getSinkSource()
// increments the internal reference count so this is okay to do.
return new VideoSource(CameraServerJNI.getSinkSource(m_handle));
}
/**
* Get a property of the associated source.
* @param name Property name
* @return Property (kind Property::kNone if no property with
* the given name exists or no source connected)
*/
public VideoProperty getSourceProperty(String name) {
return new VideoProperty(
CameraServerJNI.getSinkSourceProperty(m_handle, name));
}
/**
* Enumerate all existing sinks.
* @return Vector of sinks.
*/
public static VideoSink[] enumerateSinks() {
int[] handles = CameraServerJNI.enumerateSinks();
VideoSink[] rv = new VideoSink[handles.length];
for (int i=0; i<handles.length; i++) {
rv[i] = new VideoSink(handles[i]);
}
return rv;
}
protected int m_handle;
}

View File

@@ -0,0 +1,216 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2016. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
/*----------------------------------------------------------------------------*/
package edu.wpi.cscore;
/**
* A source for video that provides a sequence of frames. Each frame may
* consist of multiple images (e.g. from a stereo or depth camera); these
* are called channels.
*/
public class VideoSource {
public enum Kind {
kUnknown(0), kUsb(1), kHttp(2), kCv(4);
private int value;
private Kind(int value) {
this.value = value;
}
public int getValue() {
return value;
}
}
public static Kind getKindFromInt(int kind) {
switch (kind) {
case 1: return Kind.kUsb;
case 2: return Kind.kHttp;
case 4: return Kind.kCv;
default: return Kind.kUnknown;
}
}
protected VideoSource(int handle) {
m_handle = handle;
}
public synchronized void free() {
if (m_handle != 0) {
CameraServerJNI.releaseSource(m_handle);
}
m_handle = 0;
}
public boolean isValid() {
return m_handle != 0;
}
public int getHandle() {
return m_handle;
}
public boolean equals(Object other) {
if (this == other) return true;
if (other == null) return false;
if (getClass() != other.getClass()) return false;
VideoSource source = (VideoSource) other;
return m_handle == source.m_handle;
}
public int hashCode() {
return m_handle;
}
/**
* Get the kind of the source.
*/
public Kind getKind() {
return getKindFromInt(CameraServerJNI.getSourceKind(m_handle));
}
/**
* Get the name of the source. The name is an arbitrary identifier
* provided when the source is created, and should be unique.
*/
public String getName() {
return CameraServerJNI.getSourceName(m_handle);
}
/**
* Get the source description. This is source-kind specific.
*/
public String getDescription() {
return CameraServerJNI.getSourceDescription(m_handle);
}
/**
* Get the last time a frame was captured.
*/
public long getLastFrameTime() {
return CameraServerJNI.getSourceLastFrameTime(m_handle);
}
/**
* Is the source currently connected to whatever is providing the images?
*/
public boolean isConnected() {
return CameraServerJNI.isSourceConnected(m_handle);
}
/**
* Get a property.
* @param name Property name
* @return Property contents (of kind Property::kNone if no property with
* the given name exists)
*/
public VideoProperty getProperty(String name) {
return new VideoProperty(CameraServerJNI.getSourceProperty(m_handle, name));
}
/**
* Enumerate all properties of this source.
*/
public VideoProperty[] enumerateProperties() {
int[] handles = CameraServerJNI.enumerateSourceProperties(m_handle);
VideoProperty[] rv = new VideoProperty[handles.length];
for (int i=0; i<handles.length; i++) {
rv[i] = new VideoProperty(handles[i]);
}
return rv;
}
/**
* Get the current video mode.
*/
public VideoMode getVideoMode() {
return CameraServerJNI.getSourceVideoMode(m_handle);
}
/**
* Set the video mode.
* @param mode Video mode
*/
public boolean setVideoMode(VideoMode mode) {
return CameraServerJNI.setSourceVideoMode(m_handle, mode.pixelFormat.getValue(), mode.width, mode.height, mode.fps);
}
/**
* Set the video mode.
* @param pixelFormat desired pixel format
* @param width desired width
* @param height desired height
* @param fps desired FPS
* @return True if set successfully
*/
public boolean setVideoMode(VideoMode.PixelFormat pixelFormat, int width, int height, int fps) {
return CameraServerJNI.setSourceVideoMode(m_handle, pixelFormat.getValue(), width, height, fps);
}
/**
* Set the pixel format.
* @param pixelFormat desired pixel format
* @return True if set successfully
*/
public boolean setPixelFormat(VideoMode.PixelFormat pixelFormat) {
return CameraServerJNI.setSourcePixelFormat(m_handle, pixelFormat.getValue());
}
/**
* Set the resolution.
* @param width desired width
* @param height desired height
* @return True if set successfully
*/
public boolean setResolution(int width, int height) {
return CameraServerJNI.setSourceResolution(m_handle, width, height);
}
/**
* Set the frames per second (FPS).
* @param fps desired FPS
* @return True if set successfully
*/
public boolean setFPS(int fps) {
return CameraServerJNI.setSourceFPS(m_handle, fps);
}
/**
* Enumerate all known video modes for this source.
*/
public VideoMode[] enumerateVideoModes() {
return CameraServerJNI.enumerateSourceVideoModes(m_handle);
}
/**
* Enumerate all sinks connected to this source.
* @return Vector of sinks.
*/
public VideoSink[] enumerateSinks() {
int[] handles = CameraServerJNI.enumerateSourceSinks(m_handle);
VideoSink[] rv = new VideoSink[handles.length];
for (int i=0; i<handles.length; i++) {
rv[i] = new VideoSink(handles[i]);
}
return rv;
}
/**
* Enumerate all existing sources.
* @return Vector of sources.
*/
public static VideoSource[] enumerateSources() {
int[] handles = CameraServerJNI.enumerateSources();
VideoSource[] rv = new VideoSource[handles.length];
for (int i=0; i<handles.length; i++) {
rv[i] = new VideoSource(handles[i]);
}
return rv;
}
protected int m_handle;
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,20 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2016. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
/*----------------------------------------------------------------------------*/
#ifndef CSCORE_H_
#define CSCORE_H_
/* C API */
#include "cscore_c.h"
#ifdef __cplusplus
/* C++ API */
#include "cscore_cpp.h"
#include "cscore_oo.h"
#endif /* __cplusplus */
#endif /* CSCORE_H_ */

View File

@@ -0,0 +1,386 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2016. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
/*----------------------------------------------------------------------------*/
#ifndef CSCORE_C_H_
#define CSCORE_C_H_
#include <stddef.h>
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
struct CvMat;
//
// The C API is handle-based. Sources and sinks are reference counted
// internally to the library. Any time a source or sink handle is returned
// or provided to a callback, the reference count is incremented.
// Calling CS_ReleaseSource() or CS_ReleaseSink() decrements the reference
// count, and when the reference count reaches zero, the object is destroyed.
// Connecting a source to a sink increments the reference count of the source,
// and when the sink is destroyed (its reference count reaches zero), the
// source reference count is decremented.
//
//
// Typedefs
//
typedef int CS_Bool;
typedef int CS_Status;
typedef int CS_Handle;
typedef CS_Handle CS_Property;
typedef CS_Handle CS_Listener;
typedef CS_Handle CS_Sink;
typedef CS_Handle CS_Source;
//
// Status values
//
enum CS_StatusValue {
CS_PROPERTY_WRITE_FAILED = 2000,
CS_OK = 0,
CS_INVALID_HANDLE = -2000, // handle was invalid (does not exist)
CS_WRONG_HANDLE_SUBTYPE = -2001,
CS_INVALID_PROPERTY = -2002,
CS_WRONG_PROPERTY_TYPE = -2003,
CS_READ_FAILED = -2004,
CS_SOURCE_IS_DISCONNECTED = -2005,
CS_EMPTY_VALUE = -2006,
CS_BAD_URL = -2007
};
//
// Logging levels
//
enum CS_LogLevel {
CS_LOG_CRITICAL = 50,
CS_LOG_ERROR = 40,
CS_LOG_WARNING = 30,
CS_LOG_INFO = 20,
CS_LOG_DEBUG = 10,
CS_LOG_DEBUG1 = 9,
CS_LOG_DEBUG2 = 8,
CS_LOG_DEBUG3 = 7,
CS_LOG_DEBUG4 = 6
};
//
// Pixel formats
//
enum CS_PixelFormat {
CS_PIXFMT_UNKNOWN = 0,
CS_PIXFMT_MJPEG,
CS_PIXFMT_YUYV,
CS_PIXFMT_RGB565,
CS_PIXFMT_BGR,
CS_PIXFMT_GRAY
};
//
// Frame formats
//
typedef struct CS_VideoMode {
int pixelFormat;
int width;
int height;
int fps;
} CS_VideoMode;
//
// Property kinds
//
enum CS_PropertyKind {
CS_PROP_NONE = 0,
CS_PROP_BOOLEAN = 1,
CS_PROP_INTEGER = 2,
CS_PROP_STRING = 4,
CS_PROP_ENUM = 8
};
//
// Source kinds
//
enum CS_SourceKind {
CS_SOURCE_UNKNOWN = 0,
CS_SOURCE_USB = 1,
CS_SOURCE_HTTP = 2,
CS_SOURCE_CV = 4
};
//
// HTTP Camera kinds
//
enum CS_HttpCameraKind {
CS_HTTP_UNKNOWN = 0,
CS_HTTP_MJPGSTREAMER = 1,
CS_HTTP_CSCORE = 2,
CS_HTTP_AXIS = 3
};
//
// Sink kinds
//
enum CS_SinkKind {
CS_SINK_UNKNOWN = 0,
CS_SINK_MJPEG = 2,
CS_SINK_CV = 4
};
//
// Listener event kinds
//
enum CS_EventKind {
CS_SOURCE_CREATED = 0x0001,
CS_SOURCE_DESTROYED = 0x0002,
CS_SOURCE_CONNECTED = 0x0004,
CS_SOURCE_DISCONNECTED = 0x0008,
CS_SOURCE_VIDEOMODES_UPDATED = 0x0010,
CS_SOURCE_VIDEOMODE_CHANGED = 0x0020,
CS_SOURCE_PROPERTY_CREATED = 0x0040,
CS_SOURCE_PROPERTY_VALUE_UPDATED = 0x0080,
CS_SOURCE_PROPERTY_CHOICES_UPDATED = 0x0100,
CS_SINK_SOURCE_CHANGED = 0x0200,
CS_SINK_CREATED = 0x0400,
CS_SINK_DESTROYED = 0x0800,
CS_SINK_ENABLED = 0x1000,
CS_SINK_DISABLED = 0x2000,
CS_NETWORK_INTERFACES_CHANGED = 0x4000
};
//
// Listener event
//
struct CS_Event {
CS_EventKind kind;
// Valid for CS_SOURCE_* and CS_SINK_* respectively
CS_Source source;
CS_Sink sink;
// Source/sink/property name
const char *name;
// Fields for CS_SOURCE_VIDEOMODE_CHANGED event
CS_VideoMode mode;
// Fields for CS_SOURCE_PROPERTY_* events
CS_Property property;
CS_PropertyKind propertyKind;
int value;
const char* valueStr;
};
//
// Property Functions
//
enum CS_PropertyKind CS_GetPropertyKind(CS_Property property,
CS_Status* status);
char* CS_GetPropertyName(CS_Property property, CS_Status* status);
int CS_GetProperty(CS_Property property, CS_Status* status);
void CS_SetProperty(CS_Property property, int value, CS_Status* status);
int CS_GetPropertyMin(CS_Property property, CS_Status* status);
int CS_GetPropertyMax(CS_Property property, CS_Status* status);
int CS_GetPropertyStep(CS_Property property, CS_Status* status);
int CS_GetPropertyDefault(CS_Property property, CS_Status* status);
char* CS_GetStringProperty(CS_Property property, CS_Status* status);
void CS_SetStringProperty(CS_Property property, const char* value,
CS_Status* status);
char** CS_GetEnumPropertyChoices(CS_Property property, int* count,
CS_Status* status);
//
// Source Creation Functions
//
CS_Source CS_CreateUsbCameraDev(const char* name, int dev, CS_Status* status);
CS_Source CS_CreateUsbCameraPath(const char* name, const char* path,
CS_Status* status);
CS_Source CS_CreateHttpCamera(const char* name, const char* url,
enum CS_HttpCameraKind kind, CS_Status* status);
CS_Source CS_CreateHttpCameraMulti(const char* name, const char** urls,
int count, enum CS_HttpCameraKind kind,
CS_Status* status);
CS_Source CS_CreateCvSource(const char* name, const CS_VideoMode* mode,
CS_Status* status);
//
// Source Functions
//
CS_SourceKind CS_GetSourceKind(CS_Source source, CS_Status* status);
char* CS_GetSourceName(CS_Source source, CS_Status* status);
char* CS_GetSourceDescription(CS_Source source, CS_Status* status);
uint64_t CS_GetSourceLastFrameTime(CS_Source source, CS_Status* status);
CS_Bool CS_IsSourceConnected(CS_Source source, CS_Status* status);
CS_Property CS_GetSourceProperty(CS_Source source, const char* name,
CS_Status* status);
CS_Property* CS_EnumerateSourceProperties(CS_Source source, int* count,
CS_Status* status);
void CS_GetSourceVideoMode(CS_Source source, CS_VideoMode* mode,
CS_Status* status);
CS_Bool CS_SetSourceVideoMode(CS_Source source, const CS_VideoMode* mode,
CS_Status* status);
CS_Bool CS_SetSourceVideoModeDiscrete(CS_Source source,
enum CS_PixelFormat pixelFormat,
int width, int height, int fps,
CS_Status* status);
CS_Bool CS_SetSourcePixelFormat(CS_Source source,
enum CS_PixelFormat pixelFormat,
CS_Status* status);
CS_Bool CS_SetSourceResolution(CS_Source source, int width, int height,
CS_Status* status);
CS_Bool CS_SetSourceFPS(CS_Source source, int fps, CS_Status* status);
CS_VideoMode* CS_EnumerateSourceVideoModes(CS_Source source, int* count,
CS_Status* status);
CS_Sink* CS_EnumerateSourceSinks(CS_Source source, int* count,
CS_Status* status);
CS_Source CS_CopySource(CS_Source source, CS_Status* status);
void CS_ReleaseSource(CS_Source source, CS_Status* status);
//
// Camera Source Common Property Fuctions
//
void CS_SetCameraBrightness(CS_Source source, int brightness,
CS_Status* status);
int CS_GetCameraBrightness(CS_Source source, CS_Status* status);
void CS_SetCameraWhiteBalanceAuto(CS_Source source, CS_Status* status);
void CS_SetCameraWhiteBalanceHoldCurrent(CS_Source source, CS_Status* status);
void CS_SetCameraWhiteBalanceManual(CS_Source source, int value,
CS_Status* status);
void CS_SetCameraExposureAuto(CS_Source source, CS_Status* status);
void CS_SetCameraExposureHoldCurrent(CS_Source source, CS_Status* status);
void CS_SetCameraExposureManual(CS_Source source, int value, CS_Status* status);
//
// UsbCamera Source Functions
//
char* CS_GetUsbCameraPath(CS_Source source, CS_Status* status);
//
// HttpCamera Source Functions
//
CS_HttpCameraKind CS_GetHttpCameraKind(CS_Source source, CS_Status* status);
void CS_SetHttpCameraUrls(CS_Source source, const char** urls, int count,
CS_Status* status);
char** CS_GetHttpCameraUrls(CS_Source source, int* count, CS_Status* status);
//
// OpenCV Source Functions
//
void CS_PutSourceFrame(CS_Source source, struct CvMat* image,
CS_Status* status);
void CS_NotifySourceError(CS_Source source, const char* msg, CS_Status* status);
void CS_SetSourceConnected(CS_Source source, CS_Bool connected,
CS_Status* status);
void CS_SetSourceDescription(CS_Source source, const char* description,
CS_Status* status);
CS_Property CS_CreateSourceProperty(CS_Source source, const char* name,
enum CS_PropertyKind kind, int minimum,
int maximum, int step, int defaultValue,
int value, CS_Status* status);
void CS_SetSourceEnumPropertyChoices(CS_Source source, CS_Property property,
const char** choices, int count,
CS_Status* status);
//
// Sink Creation Functions
//
CS_Sink CS_CreateMjpegServer(const char* name, const char* listenAddress,
int port, CS_Status* status);
CS_Sink CS_CreateCvSink(const char* name, CS_Status* status);
CS_Sink CS_CreateCvSinkCallback(const char* name, void* data,
void (*processFrame)(void* data, uint64_t time),
CS_Status* status);
//
// Sink Functions
//
CS_SinkKind CS_GetSinkKind(CS_Sink sink, CS_Status* status);
char* CS_GetSinkName(CS_Sink sink, CS_Status* status);
char* CS_GetSinkDescription(CS_Sink sink, CS_Status* status);
void CS_SetSinkSource(CS_Sink sink, CS_Source source, CS_Status* status);
CS_Property CS_GetSinkSourceProperty(CS_Sink sink, const char* name,
CS_Status* status);
CS_Source CS_GetSinkSource(CS_Sink sink, CS_Status* status);
CS_Sink CS_CopySink(CS_Sink sink, CS_Status* status);
void CS_ReleaseSink(CS_Sink sink, CS_Status* status);
//
// MjpegServer Sink Functions
//
char* CS_GetMjpegServerListenAddress(CS_Sink sink, CS_Status* status);
int CS_GetMjpegServerPort(CS_Sink sink, CS_Status* status);
//
// OpenCV Sink Functions
//
void CS_SetSinkDescription(CS_Sink sink, const char* description,
CS_Status* status);
uint64_t CS_GrabSinkFrame(CS_Sink sink, struct CvMat* image, CS_Status* status);
uint64_t CS_GrabSinkFrameTimeout(CS_Sink sink, struct CvMat* image,
double timeout, CS_Status* status);
char* CS_GetSinkError(CS_Sink sink, CS_Status* status);
void CS_SetSinkEnabled(CS_Sink sink, CS_Bool enabled, CS_Status* status);
//
// Listener Functions
//
void CS_SetListenerOnStart(void (*onStart)(void* data), void* data);
void CS_SetListenerOnExit(void (*onExit)(void* data), void* data);
CS_Listener CS_AddListener(void* data,
void (*callback)(void* data, const CS_Event* event),
int eventMask, int immediateNotify,
CS_Status* status);
void CS_RemoveListener(CS_Listener handle, CS_Status* status);
int CS_NotifierDestroyed(void);
//
// Logging Functions
//
typedef void (*CS_LogFunc)(unsigned int level, const char* file,
unsigned int line, const char* msg);
void CS_SetLogger(CS_LogFunc func, unsigned int min_level);
void CS_SetDefaultLogger(unsigned int min_level);
//
// Utility Functions
//
typedef struct CS_UsbCameraInfo {
int dev;
char* path;
char* name;
} CS_UsbCameraInfo;
CS_UsbCameraInfo* CS_EnumerateUsbCameras(int* count, CS_Status* status);
void CS_FreeEnumeratedUsbCameras(CS_UsbCameraInfo* cameras, int count);
CS_Source* CS_EnumerateSources(int* count, CS_Status* status);
void CS_ReleaseEnumeratedSources(CS_Source* sources, int count);
CS_Sink* CS_EnumerateSinks(int* count, CS_Status* status);
void CS_ReleaseEnumeratedSinks(CS_Sink* sinks, int count);
void CS_FreeString(char* str);
void CS_FreeEnumPropertyChoices(char** choices, int count);
void CS_FreeHttpCameraUrls(char** urls, int count);
void CS_FreeEnumeratedProperties(CS_Property* properties, int count);
void CS_FreeEnumeratedVideoModes(CS_VideoMode* modes, int count);
char* CS_GetHostname();
char** CS_GetNetworkInterfaces(int* count);
void CS_FreeNetworkInterfaces(char** interfaces, int count);
#ifdef __cplusplus
}
#endif
#endif /* CSCORE_C_H_ */

View File

@@ -0,0 +1,342 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2015. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
/*----------------------------------------------------------------------------*/
#ifndef CSCORE_CPP_H_
#define CSCORE_CPP_H_
#include <stdint.h>
#include <functional>
#include <string>
#include <vector>
#include "llvm/ArrayRef.h"
#include "llvm/SmallVector.h"
#include "llvm/StringRef.h"
#include "cscore_c.h"
namespace cv {
class Mat;
}
namespace cs {
//
// Handle-based interface for C++. Users are encouraged to use the
// object oriented interface instead; this interface is intended for use
// in applications such as JNI which require handle-based access.
//
/// USB camera information
struct UsbCameraInfo {
/// Device number (e.g. N in '/dev/videoN' on Linux)
int dev;
/// Path to device if available (e.g. '/dev/video0' on Linux)
std::string path;
/// Vendor/model name of the camera as provided by the USB driver
std::string name;
};
/// Video mode
struct VideoMode : public CS_VideoMode {
enum PixelFormat {
kUnknown = CS_PIXFMT_UNKNOWN,
kMJPEG = CS_PIXFMT_MJPEG,
kYUYV = CS_PIXFMT_YUYV,
kRGB565 = CS_PIXFMT_RGB565,
kBGR = CS_PIXFMT_BGR,
kGray = CS_PIXFMT_GRAY
};
VideoMode() {
pixelFormat = 0;
width = 0;
height = 0;
fps = 0;
}
VideoMode(PixelFormat pixelFormat_, int width_, int height_, int fps_) {
pixelFormat = pixelFormat_;
width = width_;
height = height_;
fps = fps_;
}
explicit operator bool() const { return pixelFormat == kUnknown; }
};
/// Listener event
struct RawEvent {
enum Kind {
kSourceCreated = CS_SOURCE_CREATED,
kSourceDestroyed = CS_SOURCE_DESTROYED,
kSourceConnected = CS_SOURCE_CONNECTED,
kSourceDisconnected = CS_SOURCE_DISCONNECTED,
kSourceVideoModesUpdated = CS_SOURCE_VIDEOMODES_UPDATED,
kSourceVideoModeChanged = CS_SOURCE_VIDEOMODE_CHANGED,
kSourcePropertyCreated = CS_SOURCE_PROPERTY_CREATED,
kSourcePropertyValueUpdated = CS_SOURCE_PROPERTY_VALUE_UPDATED,
kSourcePropertyChoicesUpdated = CS_SOURCE_PROPERTY_CHOICES_UPDATED,
kSinkSourceChanged = CS_SINK_SOURCE_CHANGED,
kSinkCreated = CS_SINK_CREATED,
kSinkDestroyed = CS_SINK_DESTROYED,
kSinkEnabled = CS_SINK_ENABLED,
kSinkDisabled = CS_SINK_DISABLED,
kNetworkInterfacesChanged = CS_NETWORK_INTERFACES_CHANGED
};
RawEvent() = default;
RawEvent(RawEvent::Kind kind_) : kind{kind_} {}
RawEvent(llvm::StringRef name_, CS_Handle handle_, RawEvent::Kind kind_)
: kind{kind_}, name{name_} {
if (kind_ == kSinkCreated || kind_ == kSinkDestroyed ||
kind_ == kSinkEnabled || kind_ == kSinkDisabled)
sinkHandle = handle_;
else
sourceHandle = handle_;
}
RawEvent(llvm::StringRef name_, CS_Source source_, const VideoMode& mode_)
: kind{kSourceVideoModeChanged},
sourceHandle{source_},
name{name_},
mode{mode_} {}
RawEvent(llvm::StringRef name_, CS_Source source_, RawEvent::Kind kind_,
CS_Property property_, CS_PropertyKind propertyKind_, int value_,
llvm::StringRef valueStr_)
: kind{kind_},
sourceHandle{source_},
name{name_},
propertyHandle{property_},
propertyKind{propertyKind_},
value{value_},
valueStr{valueStr_} {}
Kind kind;
// Valid for kSource* and kSink* respectively
CS_Source sourceHandle = CS_INVALID_HANDLE;
CS_Sink sinkHandle = CS_INVALID_HANDLE;
// Source/sink/property name
std::string name;
// Fields for kSourceVideoModeChanged event
VideoMode mode;
// Fields for kSourceProperty* events
CS_Property propertyHandle;
CS_PropertyKind propertyKind;
int value;
std::string valueStr;
};
//
// Property Functions
//
CS_PropertyKind GetPropertyKind(CS_Property property, CS_Status* status);
std::string GetPropertyName(CS_Property property, CS_Status* status);
llvm::StringRef GetPropertyName(CS_Property property,
llvm::SmallVectorImpl<char>& buf,
CS_Status* status);
int GetProperty(CS_Property property, CS_Status* status);
void SetProperty(CS_Property property, int value, CS_Status* status);
int GetPropertyMin(CS_Property property, CS_Status* status);
int GetPropertyMax(CS_Property property, CS_Status* status);
int GetPropertyStep(CS_Property property, CS_Status* status);
int GetPropertyDefault(CS_Property property, CS_Status* status);
std::string GetStringProperty(CS_Property property, CS_Status* status);
llvm::StringRef GetStringProperty(CS_Property property,
llvm::SmallVectorImpl<char>& buf,
CS_Status* status);
void SetStringProperty(CS_Property property, llvm::StringRef value,
CS_Status* status);
std::vector<std::string> GetEnumPropertyChoices(CS_Property property,
CS_Status* status);
//
// Source Creation Functions
//
CS_Source CreateUsbCameraDev(llvm::StringRef name, int dev, CS_Status* status);
CS_Source CreateUsbCameraPath(llvm::StringRef name, llvm::StringRef path,
CS_Status* status);
CS_Source CreateHttpCamera(llvm::StringRef name, llvm::StringRef url,
CS_HttpCameraKind kind, CS_Status* status);
CS_Source CreateHttpCamera(llvm::StringRef name,
llvm::ArrayRef<std::string> urls,
CS_HttpCameraKind kind, CS_Status* status);
CS_Source CreateCvSource(llvm::StringRef name, const VideoMode& mode,
CS_Status* status);
//
// Source Functions
//
CS_SourceKind GetSourceKind(CS_Source source, CS_Status* status);
std::string GetSourceName(CS_Source source, CS_Status* status);
llvm::StringRef GetSourceName(CS_Source source,
llvm::SmallVectorImpl<char>& buf,
CS_Status* status);
std::string GetSourceDescription(CS_Source source, CS_Status* status);
llvm::StringRef GetSourceDescription(CS_Source source,
llvm::SmallVectorImpl<char>& buf,
CS_Status* status);
uint64_t GetSourceLastFrameTime(CS_Source source, CS_Status* status);
bool IsSourceConnected(CS_Source source, CS_Status* status);
CS_Property GetSourceProperty(CS_Source source, llvm::StringRef name,
CS_Status* status);
llvm::ArrayRef<CS_Property> EnumerateSourceProperties(
CS_Source source, llvm::SmallVectorImpl<CS_Property>& vec,
CS_Status* status);
VideoMode GetSourceVideoMode(CS_Source source, CS_Status* status);
bool SetSourceVideoMode(CS_Source source, const VideoMode& mode,
CS_Status* status);
bool SetSourcePixelFormat(CS_Source source, VideoMode::PixelFormat pixelFormat,
CS_Status* status);
bool SetSourceResolution(CS_Source source, int width, int height,
CS_Status* status);
bool SetSourceFPS(CS_Source source, int fps, CS_Status* status);
std::vector<VideoMode> EnumerateSourceVideoModes(CS_Source source,
CS_Status* status);
llvm::ArrayRef<CS_Sink> EnumerateSourceSinks(
CS_Source source, llvm::SmallVectorImpl<CS_Sink>& vec, CS_Status* status);
CS_Source CopySource(CS_Source source, CS_Status* status);
void ReleaseSource(CS_Source source, CS_Status* status);
//
// Camera Source Common Property Fuctions
//
void SetCameraBrightness(CS_Source source, int brightness, CS_Status* status);
int GetCameraBrightness(CS_Source source, CS_Status* status);
void SetCameraWhiteBalanceAuto(CS_Source source, CS_Status* status);
void SetCameraWhiteBalanceHoldCurrent(CS_Source source, CS_Status* status);
void SetCameraWhiteBalanceManual(CS_Source source, int value,
CS_Status* status);
void SetCameraExposureAuto(CS_Source source, CS_Status* status);
void SetCameraExposureHoldCurrent(CS_Source source, CS_Status* status);
void SetCameraExposureManual(CS_Source source, int value, CS_Status* status);
//
// UsbCamera Source Functions
//
std::string GetUsbCameraPath(CS_Source source, CS_Status* status);
//
// HttpCamera Source Functions
//
CS_HttpCameraKind GetHttpCameraKind(CS_Source source, CS_Status* status);
void SetHttpCameraUrls(CS_Source source, llvm::ArrayRef<std::string> urls,
CS_Status* status);
std::vector<std::string> GetHttpCameraUrls(CS_Source source, CS_Status* status);
//
// OpenCV Source Functions
//
void PutSourceFrame(CS_Source source, cv::Mat& image, CS_Status* status);
void NotifySourceError(CS_Source source, llvm::StringRef msg,
CS_Status* status);
void SetSourceConnected(CS_Source source, bool connected, CS_Status* status);
void SetSourceDescription(CS_Source source, llvm::StringRef description,
CS_Status* status);
CS_Property CreateSourceProperty(CS_Source source, llvm::StringRef name,
CS_PropertyKind kind, int minimum, int maximum,
int step, int defaultValue, int value,
CS_Status* status);
void SetSourceEnumPropertyChoices(CS_Source source, CS_Property property,
llvm::ArrayRef<std::string> choices,
CS_Status* status);
//
// Sink Creation Functions
//
CS_Sink CreateMjpegServer(llvm::StringRef name, llvm::StringRef listenAddress,
int port, CS_Status* status);
CS_Sink CreateCvSink(llvm::StringRef name, CS_Status* status);
CS_Sink CreateCvSinkCallback(llvm::StringRef name,
std::function<void(uint64_t time)> processFrame,
CS_Status* status);
//
// Sink Functions
//
CS_SinkKind GetSinkKind(CS_Sink sink, CS_Status* status);
std::string GetSinkName(CS_Sink sink, CS_Status* status);
llvm::StringRef GetSinkName(CS_Sink sink, llvm::SmallVectorImpl<char>& buf,
CS_Status* status);
std::string GetSinkDescription(CS_Sink sink, CS_Status* status);
llvm::StringRef GetSinkDescription(CS_Sink sink,
llvm::SmallVectorImpl<char>& buf,
CS_Status* status);
void SetSinkSource(CS_Sink sink, CS_Source source, CS_Status* status);
CS_Property GetSinkSourceProperty(CS_Sink sink, llvm::StringRef name,
CS_Status* status);
CS_Source GetSinkSource(CS_Sink sink, CS_Status* status);
CS_Sink CopySink(CS_Sink sink, CS_Status* status);
void ReleaseSink(CS_Sink sink, CS_Status* status);
//
// MjpegServer Sink Functions
//
std::string GetMjpegServerListenAddress(CS_Sink sink, CS_Status* status);
int GetMjpegServerPort(CS_Sink sink, CS_Status* status);
//
// OpenCV Sink Functions
//
void SetSinkDescription(CS_Sink sink, llvm::StringRef description,
CS_Status* status);
uint64_t GrabSinkFrame(CS_Sink sink, cv::Mat& image, CS_Status* status);
uint64_t GrabSinkFrameTimeout(CS_Sink sink, cv::Mat& image, double timeout,
CS_Status* status);
std::string GetSinkError(CS_Sink sink, CS_Status* status);
llvm::StringRef GetSinkError(CS_Sink sink, llvm::SmallVectorImpl<char>& buf,
CS_Status* status);
void SetSinkEnabled(CS_Sink sink, bool enabled, CS_Status* status);
//
// Listener Functions
//
void SetListenerOnStart(std::function<void()> onStart);
void SetListenerOnExit(std::function<void()> onExit);
CS_Listener AddListener(std::function<void(const RawEvent& event)> callback,
int eventMask, bool immediateNotify, CS_Status* status);
void RemoveListener(CS_Listener handle, CS_Status* status);
bool NotifierDestroyed();
//
// Logging Functions
//
typedef std::function<void(unsigned int level, const char* file,
unsigned int line, const char* msg)>
LogFunc;
void SetLogger(LogFunc func, unsigned int min_level);
void SetDefaultLogger(unsigned int min_level);
//
// Utility Functions
//
std::vector<UsbCameraInfo> EnumerateUsbCameras(CS_Status* status);
llvm::ArrayRef<CS_Source> EnumerateSourceHandles(
llvm::SmallVectorImpl<CS_Source>& vec, CS_Status* status);
llvm::ArrayRef<CS_Sink> EnumerateSinkHandles(
llvm::SmallVectorImpl<CS_Sink>& vec, CS_Status* status);
std::string GetHostname();
std::vector<std::string> GetNetworkInterfaces();
} // namespace cs
// C functions taking a cv::Mat* for specific interop implementations
extern "C" {
uint64_t CS_GrabSinkFrameCpp(CS_Sink sink, cv::Mat* image, CS_Status* status);
uint64_t CS_GrabSinkFrameTimeoutCpp(CS_Sink sink, cv::Mat* image,
double timeout, CS_Status* status);
void CS_PutSourceFrameCpp(CS_Source source, cv::Mat* image, CS_Status* status);
}
#endif // CSCORE_CPP_H_

View File

@@ -0,0 +1,644 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2015. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
/*----------------------------------------------------------------------------*/
#ifndef CSCORE_OO_H_
#define CSCORE_OO_H_
#include <initializer_list>
#include "cscore_cpp.h"
namespace cs {
//
// Object-oriented interface
//
// Forward declarations so friend declarations work correctly
class CvSource;
class VideoEvent;
class VideoSink;
class VideoSource;
class VideoProperty {
friend class CvSource;
friend class VideoEvent;
friend class VideoSink;
friend class VideoSource;
public:
enum Kind {
kNone = CS_PROP_NONE,
kBoolean = CS_PROP_BOOLEAN,
kInteger = CS_PROP_INTEGER,
kString = CS_PROP_STRING,
kEnum = CS_PROP_ENUM
};
VideoProperty() : m_handle(0), m_kind(kNone) {}
std::string GetName() const;
Kind GetKind() const { return m_kind; }
explicit operator bool() const { return m_kind != kNone; }
// Kind checkers
bool IsBoolean() const { return m_kind == kBoolean; }
bool IsInteger() const { return m_kind == kInteger; }
bool IsString() const { return m_kind == kString; }
bool IsEnum() const { return m_kind == kEnum; }
int Get() const;
void Set(int value);
int GetMin() const;
int GetMax() const;
int GetStep() const;
int GetDefault() const;
// String-specific functions
std::string GetString() const;
llvm::StringRef GetString(llvm::SmallVectorImpl<char>& buf) const;
void SetString(llvm::StringRef value);
// Enum-specific functions
std::vector<std::string> GetChoices() const;
CS_Status GetLastStatus() const { return m_status; }
private:
explicit VideoProperty(CS_Property handle);
VideoProperty(CS_Property handle, Kind kind);
mutable CS_Status m_status;
CS_Property m_handle;
Kind m_kind;
};
/// A source for video that provides a sequence of frames.
class VideoSource {
friend class VideoEvent;
friend class VideoSink;
public:
enum Kind {
kUnknown = CS_SOURCE_UNKNOWN,
kUsb = CS_SOURCE_USB,
kHttp = CS_SOURCE_HTTP,
kCv = CS_SOURCE_CV
};
VideoSource() noexcept : m_handle(0) {}
VideoSource(const VideoSource& source);
VideoSource(VideoSource&& other) noexcept;
VideoSource& operator=(VideoSource other) noexcept;
~VideoSource();
explicit operator bool() const { return m_handle != 0; }
int GetHandle() const { return m_handle; }
bool operator==(const VideoSource& other) const {
return m_handle == other.m_handle;
}
bool operator!=(const VideoSource& other) const { return !(*this == other); }
/// Get the kind of the source.
Kind GetKind() const;
/// Get the name of the source. The name is an arbitrary identifier
/// provided when the source is created, and should be unique.
std::string GetName() const;
/// Get the source description. This is source-kind specific.
std::string GetDescription() const;
/// Get the last time a frame was captured.
uint64_t GetLastFrameTime() const;
/// Is the source currently connected to whatever is providing the images?
bool IsConnected() const;
/// Get a property.
/// @param name Property name
/// @return Property contents (of kind Property::kNone if no property with
/// the given name exists)
VideoProperty GetProperty(llvm::StringRef name);
/// Enumerate all properties of this source.
std::vector<VideoProperty> EnumerateProperties() const;
/// Get the current video mode.
VideoMode GetVideoMode() const;
/// Set the video mode.
/// @param mode Video mode
bool SetVideoMode(const VideoMode& mode);
/// Set the video mode.
/// @param pixelFormat desired pixel format
/// @param width desired width
/// @param height desired height
/// @param fps desired FPS
/// @return True if set successfully
bool SetVideoMode(VideoMode::PixelFormat pixelFormat, int width, int height,
int fps);
/// Set the pixel format.
/// @param pixelFormat desired pixel format
/// @return True if set successfully
bool SetPixelFormat(VideoMode::PixelFormat pixelFormat);
/// Set the resolution.
/// @param width desired width
/// @param height desired height
/// @return True if set successfully
bool SetResolution(int width, int height);
/// Set the frames per second (FPS).
/// @param fps desired FPS
/// @return True if set successfully
bool SetFPS(int fps);
/// Enumerate all known video modes for this source.
std::vector<VideoMode> EnumerateVideoModes() const;
CS_Status GetLastStatus() const { return m_status; }
/// Enumerate all sinks connected to this source.
/// @return Vector of sinks.
std::vector<VideoSink> EnumerateSinks();
/// Enumerate all existing sources.
/// @return Vector of sources.
static std::vector<VideoSource> EnumerateSources();
friend void swap(VideoSource& first, VideoSource& second) noexcept {
using std::swap;
swap(first.m_status, second.m_status);
swap(first.m_handle, second.m_handle);
}
protected:
explicit VideoSource(CS_Source handle) : m_handle(handle) {}
mutable CS_Status m_status = 0;
CS_Source m_handle;
};
/// A source that represents a video camera.
class VideoCamera : public VideoSource {
public:
enum WhiteBalance {
kFixedIndoor = 3000,
kFixedOutdoor1 = 4000,
kFixedOutdoor2 = 5000,
kFixedFluorescent1 = 5100,
kFixedFlourescent2 = 5200
};
VideoCamera() = default;
/// Set the brightness, as a percentage (0-100).
void SetBrightness(int brightness);
/// Get the brightness, as a percentage (0-100).
int GetBrightness();
/// Set the white balance to auto.
void SetWhiteBalanceAuto();
/// Set the white balance to hold current.
void SetWhiteBalanceHoldCurrent();
/// Set the white balance to manual, with specified color temperature.
void SetWhiteBalanceManual(int value);
/// Set the exposure to auto aperature.
void SetExposureAuto();
/// Set the exposure to hold current.
void SetExposureHoldCurrent();
/// Set the exposure to manual, as a percentage (0-100).
void SetExposureManual(int value);
protected:
explicit VideoCamera(CS_Source handle) : VideoSource(handle) {}
};
/// A source that represents a USB camera.
class UsbCamera : public VideoCamera {
public:
UsbCamera() = default;
/// Create a source for a USB camera based on device number.
/// @param name Source name (arbitrary unique identifier)
/// @param dev Device number (e.g. 0 for /dev/video0)
UsbCamera(llvm::StringRef name, int dev);
/// Create a source for a USB camera based on device path.
/// @param name Source name (arbitrary unique identifier)
/// @param path Path to device (e.g. "/dev/video0" on Linux)
UsbCamera(llvm::StringRef name, llvm::StringRef path);
/// Enumerate USB cameras on the local system.
/// @return Vector of USB camera information (one for each camera)
static std::vector<UsbCameraInfo> EnumerateUsbCameras();
/// Get the path to the device.
std::string GetPath() const;
};
/// A source that represents a MJPEG-over-HTTP (IP) camera.
class HttpCamera : public VideoCamera {
public:
enum HttpCameraKind {
kUnknown = CS_HTTP_UNKNOWN,
kMJPGStreamer = CS_HTTP_MJPGSTREAMER,
kCSCore = CS_HTTP_CSCORE,
kAxis = CS_HTTP_AXIS
};
/// Create a source for a MJPEG-over-HTTP (IP) camera.
/// @param name Source name (arbitrary unique identifier)
/// @param url Camera URL (e.g. "http://10.x.y.11/video/stream.mjpg")
/// @param kind Camera kind (e.g. kAxis)
HttpCamera(llvm::StringRef name, llvm::StringRef url,
HttpCameraKind kind = kUnknown);
/// Create a source for a MJPEG-over-HTTP (IP) camera.
/// @param name Source name (arbitrary unique identifier)
/// @param url Camera URL (e.g. "http://10.x.y.11/video/stream.mjpg")
/// @param kind Camera kind (e.g. kAxis)
HttpCamera(llvm::StringRef name, const char* url,
HttpCameraKind kind = kUnknown);
/// Create a source for a MJPEG-over-HTTP (IP) camera.
/// @param name Source name (arbitrary unique identifier)
/// @param url Camera URL (e.g. "http://10.x.y.11/video/stream.mjpg")
/// @param kind Camera kind (e.g. kAxis)
HttpCamera(llvm::StringRef name, const std::string& url,
HttpCameraKind kind = kUnknown);
/// Create a source for a MJPEG-over-HTTP (IP) camera.
/// @param name Source name (arbitrary unique identifier)
/// @param urls Array of Camera URLs
/// @param kind Camera kind (e.g. kAxis)
HttpCamera(llvm::StringRef name, llvm::ArrayRef<std::string> urls,
HttpCameraKind kind = kUnknown);
/// Create a source for a MJPEG-over-HTTP (IP) camera.
/// @param name Source name (arbitrary unique identifier)
/// @param urls Array of Camera URLs
/// @param kind Camera kind (e.g. kAxis)
template <typename T>
HttpCamera(llvm::StringRef name, std::initializer_list<T> urls,
HttpCameraKind kind = kUnknown);
/// Get the kind of HTTP camera.
/// Autodetection can result in returning a different value than the camera
/// was created with.
HttpCameraKind GetHttpCameraKind() const;
/// Change the URLs used to connect to the camera.
void SetUrls(llvm::ArrayRef<std::string> urls);
/// Change the URLs used to connect to the camera.
template <typename T>
void SetUrls(std::initializer_list<T> urls);
/// Get the URLs used to connect to the camera.
std::vector<std::string> GetUrls() const;
};
/// A source that represents an Axis IP camera.
class AxisCamera : public HttpCamera {
static std::string HostToUrl(llvm::StringRef host);
static std::vector<std::string> HostToUrl(llvm::ArrayRef<std::string> hosts);
template <typename T>
static std::vector<std::string> HostToUrl(std::initializer_list<T> hosts);
public:
/// Create a source for an Axis IP camera.
/// @param name Source name (arbitrary unique identifier)
/// @param host Camera host IP or DNS name (e.g. "10.x.y.11")
/// @param kind Camera kind (e.g. kAxis)
AxisCamera(llvm::StringRef name, llvm::StringRef host);
/// Create a source for an Axis IP camera.
/// @param name Source name (arbitrary unique identifier)
/// @param host Camera host IP or DNS name (e.g. "10.x.y.11")
/// @param kind Camera kind (e.g. kAxis)
AxisCamera(llvm::StringRef name, const char* host);
/// Create a source for an Axis IP camera.
/// @param name Source name (arbitrary unique identifier)
/// @param host Camera host IP or DNS name (e.g. "10.x.y.11")
/// @param kind Camera kind (e.g. kAxis)
AxisCamera(llvm::StringRef name, const std::string& host);
/// Create a source for an Axis IP camera.
/// @param name Source name (arbitrary unique identifier)
/// @param hosts Array of Camera host IPs/DNS names
/// @param kind Camera kind (e.g. kAxis)
AxisCamera(llvm::StringRef name, llvm::ArrayRef<std::string> hosts);
/// Create a source for an Axis IP camera.
/// @param name Source name (arbitrary unique identifier)
/// @param hosts Array of Camera host IPs/DNS names
/// @param kind Camera kind (e.g. kAxis)
template <typename T>
AxisCamera(llvm::StringRef name, std::initializer_list<T> hosts);
};
/// A source for user code to provide OpenCV images as video frames.
class CvSource : public VideoSource {
public:
CvSource() = default;
/// Create an OpenCV source.
/// @param name Source name (arbitrary unique identifier)
/// @param mode Video mode being generated
CvSource(llvm::StringRef name, const VideoMode& mode);
/// Create an OpenCV source.
/// @param name Source name (arbitrary unique identifier)
/// @param pixelFormat Pixel format
/// @param width width
/// @param height height
/// @param fps fps
CvSource(llvm::StringRef name, VideoMode::PixelFormat pixelFormat, int width,
int height, int fps);
/// Put an OpenCV image and notify sinks.
/// Only 8-bit single-channel or 3-channel (with BGR channel order) images
/// are supported. If the format, depth or channel order is different, use
/// cv::Mat::convertTo() and/or cv::cvtColor() to convert it first.
/// @param image OpenCV image
void PutFrame(cv::Mat& image);
/// Signal sinks that an error has occurred. This should be called instead
/// of NotifyFrame when an error occurs.
void NotifyError(llvm::StringRef msg);
/// Set source connection status. Defaults to true.
/// @param connected True for connected, false for disconnected
void SetConnected(bool connected);
/// Set source description.
/// @param description Description
void SetDescription(llvm::StringRef description);
/// Create a property.
/// @param name Property name
/// @param kind Property kind
/// @param minimum Minimum value
/// @param maximum Maximum value
/// @param step Step value
/// @param defaultValue Default value
/// @param value Current value
/// @return Property
VideoProperty CreateProperty(llvm::StringRef name, VideoProperty::Kind kind,
int minimum, int maximum, int step,
int defaultValue, int value);
/// Create an integer property.
/// @param name Property name
/// @param minimum Minimum value
/// @param maximum Maximum value
/// @param step Step value
/// @param defaultValue Default value
/// @param value Current value
/// @return Property
VideoProperty CreateIntegerProperty(llvm::StringRef name,
int minimum, int maximum, int step,
int defaultValue, int value);
/// Create a boolean property.
/// @param name Property name
/// @param defaultValue Default value
/// @param value Current value
/// @return Property
VideoProperty CreateBooleanProperty(llvm::StringRef name,
bool defaultValue, bool value);
/// Create a string property.
/// @param name Property name
/// @param defaultValue Default value
/// @param value Current value
/// @return Property
VideoProperty CreateStringProperty(llvm::StringRef name,
llvm::StringRef value);
/// Configure enum property choices.
/// @param property Property
/// @param choices Choices
void SetEnumPropertyChoices(const VideoProperty& property,
llvm::ArrayRef<std::string> choices);
/// Configure enum property choices.
/// @param property Property
/// @param choices Choices
template <typename T>
void SetEnumPropertyChoices(const VideoProperty& property,
std::initializer_list<T> choices);
};
/// A sink for video that accepts a sequence of frames.
class VideoSink {
friend class VideoEvent;
friend class VideoSource;
public:
enum Kind {
kUnknown = CS_SINK_UNKNOWN,
kMjpeg = CS_SINK_MJPEG,
kCv = CS_SINK_CV
};
VideoSink() noexcept : m_handle(0) {}
VideoSink(const VideoSink& sink);
VideoSink(VideoSink&& sink) noexcept;
VideoSink& operator=(VideoSink other) noexcept;
~VideoSink();
explicit operator bool() const { return m_handle != 0; }
int GetHandle() const { return m_handle; }
bool operator==(const VideoSink& other) const {
return m_handle == other.m_handle;
}
bool operator!=(const VideoSink& other) const { return !(*this == other); }
/// Get the kind of the sink.
Kind GetKind() const;
/// Get the name of the sink. The name is an arbitrary identifier
/// provided when the sink is created, and should be unique.
std::string GetName() const;
/// Get the sink description. This is sink-kind specific.
std::string GetDescription() const;
/// Configure which source should provide frames to this sink. Each sink
/// can accept frames from only a single source, but a single source can
/// provide frames to multiple clients.
/// @param source Source
void SetSource(VideoSource source);
/// Get the connected source.
/// @return Connected source (empty if none connected).
VideoSource GetSource() const;
/// Get a property of the associated source.
/// @param name Property name
/// @return Property (kind Property::kNone if no property with
/// the given name exists or no source connected)
VideoProperty GetSourceProperty(llvm::StringRef name);
CS_Status GetLastStatus() const { return m_status; }
/// Enumerate all existing sinks.
/// @return Vector of sinks.
static std::vector<VideoSink> EnumerateSinks();
friend void swap(VideoSink& first, VideoSink& second) noexcept {
using std::swap;
swap(first.m_status, second.m_status);
swap(first.m_handle, second.m_handle);
}
protected:
explicit VideoSink(CS_Sink handle) : m_handle(handle) {}
mutable CS_Status m_status = 0;
CS_Sink m_handle;
};
/// A sink that acts as a MJPEG-over-HTTP network server.
class MjpegServer : public VideoSink {
public:
MjpegServer() = default;
/// Create a MJPEG-over-HTTP server sink.
/// @param name Sink name (arbitrary unique identifier)
/// @param listenAddress TCP listen address (empty string for all addresses)
/// @param port TCP port number
MjpegServer(llvm::StringRef name, llvm::StringRef listenAddress, int port);
/// Create a MJPEG-over-HTTP server sink.
/// @param name Sink name (arbitrary unique identifier)
/// @param port TCP port number
MjpegServer(llvm::StringRef name, int port) : MjpegServer(name, "", port) {}
/// Get the listen address of the server.
std::string GetListenAddress() const;
/// Get the port number of the server.
int GetPort() const;
};
/// A sink for user code to accept video frames as OpenCV images.
class CvSink : public VideoSink {
public:
CvSink() = default;
/// Create a sink for accepting OpenCV images.
/// WaitForFrame() must be called on the created sink to get each new
/// image.
/// @param name Source name (arbitrary unique identifier)
explicit CvSink(llvm::StringRef name);
/// Create a sink for accepting OpenCV images in a separate thread.
/// A thread will be created that calls WaitForFrame() and calls the
/// processFrame() callback each time a new frame arrives.
/// @param name Source name (arbitrary unique identifier)
/// @param processFrame Frame processing function; will be called with a
/// time=0 if an error occurred. processFrame should call GetImage()
/// or GetError() as needed, but should not call (except in very
/// unusual circumstances) WaitForImage().
CvSink(llvm::StringRef name, std::function<void(uint64_t time)> processFrame);
/// Set sink description.
/// @param description Description
void SetDescription(llvm::StringRef description);
/// Wait for the next frame and get the image.
/// Times out (returning 0) after timeout seconds.
/// The provided image will have three 8-bit channels stored in BGR order.
/// @return Frame time, or 0 on error (call GetError() to obtain the error
/// message);
uint64_t GrabFrame(cv::Mat& image, double timeout = 0.225) const;
/// Wait for the next frame and get the image. May block forever.
/// The provided image will have three 8-bit channels stored in BGR order.
/// @return Frame time, or 0 on error (call GetError() to obtain the error
/// message);
uint64_t GrabFrameNoTimeout(cv::Mat& image) const;
/// Get error string. Call this if WaitForFrame() returns 0 to determine
/// what the error is.
std::string GetError() const;
/// Enable or disable getting new frames.
/// Disabling will cause processFrame (for callback-based CvSinks) to not
/// be called and WaitForFrame() to not return. This can be used to save
/// processor resources when frames are not needed.
void SetEnabled(bool enabled);
};
/// An event generated by the library and provided to event listeners.
class VideoEvent : public RawEvent {
public:
/// Get the source associated with the event (if any).
VideoSource GetSource() const;
/// Get the sink associated with the event (if any).
VideoSink GetSink() const;
/// Get the property associated with the event (if any).
VideoProperty GetProperty() const;
};
/// An event listener. This calls back to a desigated callback function when
/// an event matching the specified mask is generated by the library.
class VideoListener {
public:
VideoListener() : m_handle(0) {}
/// Create an event listener.
/// @param callback Callback function
/// @param eventMask Bitmask of VideoEvent::Kind values
/// @param immediateNotify Whether callback should be immediately called with
/// a representative set of events for the current library state.
VideoListener(std::function<void(const VideoEvent& event)> callback,
int eventMask, bool immediateNotify);
VideoListener(const VideoListener&) = delete;
VideoListener& operator=(const VideoListener&) = delete;
VideoListener(VideoListener&& other) noexcept;
VideoListener& operator=(VideoListener&& other) noexcept;
~VideoListener();
friend void swap(VideoListener& first, VideoListener& second) noexcept {
using std::swap;
swap(first.m_handle, second.m_handle);
}
private:
CS_Listener m_handle;
};
} // namespace cs
#include "cscore_oo.inl"
#endif // CSCORE_OO_H_

View File

@@ -0,0 +1,561 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2015. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
/*----------------------------------------------------------------------------*/
#ifndef CSCORE_OO_INL_
#define CSCORE_OO_INL_
namespace cs {
inline std::string VideoProperty::GetName() const {
m_status = 0;
return GetPropertyName(m_handle, &m_status);
}
inline int VideoProperty::Get() const {
m_status = 0;
return GetProperty(m_handle, &m_status);
}
inline void VideoProperty::Set(int value) {
m_status = 0;
SetProperty(m_handle, value, &m_status);
}
inline int VideoProperty::GetMin() const {
m_status = 0;
return GetPropertyMin(m_handle, &m_status);
}
inline int VideoProperty::GetMax() const {
m_status = 0;
return GetPropertyMax(m_handle, &m_status);
}
inline int VideoProperty::GetStep() const {
m_status = 0;
return GetPropertyStep(m_handle, &m_status);
}
inline int VideoProperty::GetDefault() const {
m_status = 0;
return GetPropertyDefault(m_handle, &m_status);
}
inline std::string VideoProperty::GetString() const {
m_status = 0;
return GetStringProperty(m_handle, &m_status);
}
inline llvm::StringRef VideoProperty::GetString(
llvm::SmallVectorImpl<char>& buf) const {
m_status = 0;
return GetStringProperty(m_handle, buf, &m_status);
}
inline void VideoProperty::SetString(llvm::StringRef value) {
m_status = 0;
SetStringProperty(m_handle, value, &m_status);
}
inline std::vector<std::string> VideoProperty::GetChoices() const {
m_status = 0;
return GetEnumPropertyChoices(m_handle, &m_status);
}
inline VideoProperty::VideoProperty(CS_Property handle) : m_handle(handle) {
m_status = 0;
if (handle == 0)
m_kind = kNone;
else
m_kind =
static_cast<Kind>(static_cast<int>(GetPropertyKind(handle, &m_status)));
}
inline VideoProperty::VideoProperty(CS_Property handle, Kind kind)
: m_handle(handle), m_kind(kind) {}
inline VideoSource::VideoSource(const VideoSource& source)
: m_handle(source.m_handle == 0 ? 0
: CopySource(source.m_handle, &m_status)) {}
inline VideoSource::VideoSource(VideoSource&& other) noexcept : VideoSource() {
swap(*this, other);
}
inline VideoSource& VideoSource::operator=(VideoSource other) noexcept {
swap(*this, other);
return *this;
}
inline VideoSource::~VideoSource() {
m_status = 0;
if (m_handle != 0) ReleaseSource(m_handle, &m_status);
}
inline VideoSource::Kind VideoSource::GetKind() const {
m_status = 0;
return static_cast<VideoSource::Kind>(GetSourceKind(m_handle, &m_status));
}
inline std::string VideoSource::GetName() const {
m_status = 0;
return GetSourceName(m_handle, &m_status);
}
inline std::string VideoSource::GetDescription() const {
m_status = 0;
return GetSourceDescription(m_handle, &m_status);
}
inline uint64_t VideoSource::GetLastFrameTime() const {
m_status = 0;
return GetSourceLastFrameTime(m_handle, &m_status);
}
inline bool VideoSource::IsConnected() const {
m_status = 0;
return IsSourceConnected(m_handle, &m_status);
}
inline VideoProperty VideoSource::GetProperty(llvm::StringRef name) {
m_status = 0;
return VideoProperty{GetSourceProperty(m_handle, name, &m_status)};
}
inline VideoMode VideoSource::GetVideoMode() const {
m_status = 0;
return GetSourceVideoMode(m_handle, &m_status);
}
inline bool VideoSource::SetVideoMode(const VideoMode& mode) {
m_status = 0;
return SetSourceVideoMode(m_handle, mode, &m_status);
}
inline bool VideoSource::SetVideoMode(VideoMode::PixelFormat pixelFormat,
int width, int height, int fps) {
m_status = 0;
return SetSourceVideoMode(
m_handle, VideoMode{pixelFormat, width, height, fps}, &m_status);
}
inline bool VideoSource::SetPixelFormat(VideoMode::PixelFormat pixelFormat) {
m_status = 0;
return SetSourcePixelFormat(m_handle, pixelFormat, &m_status);
}
inline bool VideoSource::SetResolution(int width, int height) {
m_status = 0;
return SetSourceResolution(m_handle, width, height, &m_status);
}
inline bool VideoSource::SetFPS(int fps) {
m_status = 0;
return SetSourceFPS(m_handle, fps, &m_status);
}
inline std::vector<VideoMode> VideoSource::EnumerateVideoModes() const {
CS_Status status = 0;
return EnumerateSourceVideoModes(m_handle, &status);
}
inline void VideoCamera::SetBrightness(int brightness) {
m_status = 0;
SetCameraBrightness(m_handle, brightness, &m_status);
}
inline int VideoCamera::GetBrightness() {
m_status = 0;
return GetCameraBrightness(m_handle, &m_status);
}
inline void VideoCamera::SetWhiteBalanceAuto() {
m_status = 0;
SetCameraWhiteBalanceAuto(m_handle, &m_status);
}
inline void VideoCamera::SetWhiteBalanceHoldCurrent() {
m_status = 0;
SetCameraWhiteBalanceHoldCurrent(m_handle, &m_status);
}
inline void VideoCamera::SetWhiteBalanceManual(int value) {
m_status = 0;
SetCameraWhiteBalanceManual(m_handle, value, &m_status);
}
inline void VideoCamera::SetExposureAuto() {
m_status = 0;
SetCameraExposureAuto(m_handle, &m_status);
}
inline void VideoCamera::SetExposureHoldCurrent() {
m_status = 0;
SetCameraExposureHoldCurrent(m_handle, &m_status);
}
inline void VideoCamera::SetExposureManual(int value) {
m_status = 0;
SetCameraExposureManual(m_handle, value, &m_status);
}
inline UsbCamera::UsbCamera(llvm::StringRef name, int dev) {
m_handle = CreateUsbCameraDev(name, dev, &m_status);
}
inline UsbCamera::UsbCamera(llvm::StringRef name, llvm::StringRef path) {
m_handle = CreateUsbCameraPath(name, path, &m_status);
}
inline std::vector<UsbCameraInfo> UsbCamera::EnumerateUsbCameras() {
CS_Status status = 0;
return ::cs::EnumerateUsbCameras(&status);
}
inline std::string UsbCamera::GetPath() const {
m_status = 0;
return ::cs::GetUsbCameraPath(m_handle, &m_status);
}
inline HttpCamera::HttpCamera(llvm::StringRef name, llvm::StringRef url,
HttpCameraKind kind) {
m_handle = CreateHttpCamera(
name, url, static_cast<CS_HttpCameraKind>(static_cast<int>(kind)),
&m_status);
}
inline HttpCamera::HttpCamera(llvm::StringRef name, const char* url,
HttpCameraKind kind) {
m_handle = CreateHttpCamera(
name, url, static_cast<CS_HttpCameraKind>(static_cast<int>(kind)),
&m_status);
}
inline HttpCamera::HttpCamera(llvm::StringRef name, const std::string& url,
HttpCameraKind kind)
: HttpCamera(name, llvm::StringRef{url}, kind) {}
inline HttpCamera::HttpCamera(llvm::StringRef name,
llvm::ArrayRef<std::string> urls,
HttpCameraKind kind) {
m_handle = CreateHttpCamera(
name, urls, static_cast<CS_HttpCameraKind>(static_cast<int>(kind)),
&m_status);
}
template <typename T>
inline HttpCamera::HttpCamera(llvm::StringRef name,
std::initializer_list<T> urls,
HttpCameraKind kind) {
std::vector<std::string> vec;
vec.reserve(urls.size());
for (const auto& url : urls) vec.emplace_back(url);
m_handle = CreateHttpCamera(
name, vec, static_cast<CS_HttpCameraKind>(static_cast<int>(kind)),
&m_status);
}
inline HttpCamera::HttpCameraKind HttpCamera::GetHttpCameraKind() const {
m_status = 0;
return static_cast<HttpCameraKind>(
static_cast<int>(::cs::GetHttpCameraKind(m_handle, &m_status)));
}
inline void HttpCamera::SetUrls(llvm::ArrayRef<std::string> urls) {
m_status = 0;
::cs::SetHttpCameraUrls(m_handle, urls, &m_status);
}
template <typename T>
inline void HttpCamera::SetUrls(std::initializer_list<T> urls) {
std::vector<std::string> vec;
vec.reserve(urls.size());
for (const auto& url : urls) vec.emplace_back(url);
m_status = 0;
::cs::SetHttpCameraUrls(m_handle, vec, &m_status);
}
inline std::vector<std::string> HttpCamera::GetUrls() const {
m_status = 0;
return ::cs::GetHttpCameraUrls(m_handle, &m_status);
}
inline std::string AxisCamera::HostToUrl(llvm::StringRef host) {
std::string rv{"http://"};
rv += host;
rv += "/mjpg/video.mjpg";
return rv;
}
inline std::vector<std::string> AxisCamera::HostToUrl(
llvm::ArrayRef<std::string> hosts) {
std::vector<std::string> rv;
rv.reserve(hosts.size());
for (const auto& host : hosts)
rv.emplace_back(HostToUrl(llvm::StringRef{host}));
return rv;
}
template <typename T>
inline std::vector<std::string> AxisCamera::HostToUrl(
std::initializer_list<T> hosts) {
std::vector<std::string> rv;
rv.reserve(hosts.size());
for (const auto& host : hosts)
rv.emplace_back(HostToUrl(llvm::StringRef{host}));
return rv;
}
inline AxisCamera::AxisCamera(llvm::StringRef name, llvm::StringRef host)
: HttpCamera(name, HostToUrl(host), kAxis) {}
inline AxisCamera::AxisCamera(llvm::StringRef name, const char* host)
: HttpCamera(name, HostToUrl(host), kAxis) {}
inline AxisCamera::AxisCamera(llvm::StringRef name, const std::string& host)
: HttpCamera(name, HostToUrl(llvm::StringRef{host}), kAxis) {}
inline AxisCamera::AxisCamera(llvm::StringRef name,
llvm::ArrayRef<std::string> hosts)
: HttpCamera(name, HostToUrl(hosts), kAxis) {}
template <typename T>
inline AxisCamera::AxisCamera(llvm::StringRef name,
std::initializer_list<T> hosts)
: HttpCamera(name, HostToUrl(hosts), kAxis) {}
inline CvSource::CvSource(llvm::StringRef name, const VideoMode& mode) {
m_handle = CreateCvSource(name, mode, &m_status);
}
inline CvSource::CvSource(llvm::StringRef name, VideoMode::PixelFormat format,
int width, int height, int fps) {
m_handle =
CreateCvSource(name, VideoMode{format, width, height, fps}, &m_status);
}
inline void CvSource::PutFrame(cv::Mat& image) {
m_status = 0;
PutSourceFrame(m_handle, image, &m_status);
}
inline void CvSource::NotifyError(llvm::StringRef msg) {
m_status = 0;
NotifySourceError(m_handle, msg, &m_status);
}
inline void CvSource::SetConnected(bool connected) {
m_status = 0;
SetSourceConnected(m_handle, connected, &m_status);
}
inline void CvSource::SetDescription(llvm::StringRef description) {
m_status = 0;
SetSourceDescription(m_handle, description, &m_status);
}
inline VideoProperty CvSource::CreateProperty(llvm::StringRef name,
VideoProperty::Kind kind,
int minimum, int maximum,
int step, int defaultValue,
int value) {
m_status = 0;
return VideoProperty{CreateSourceProperty(
m_handle, name, static_cast<CS_PropertyKind>(static_cast<int>(kind)),
minimum, maximum, step, defaultValue, value, &m_status)};
}
inline VideoProperty CvSource::CreateIntegerProperty(llvm::StringRef name,
int minimum, int maximum,
int step, int defaultValue,
int value) {
m_status = 0;
return VideoProperty{CreateSourceProperty(
m_handle, name, static_cast<CS_PropertyKind>(static_cast<int>(VideoProperty::Kind::kInteger)),
minimum, maximum, step, defaultValue, value, &m_status)};
}
inline VideoProperty CvSource::CreateBooleanProperty(llvm::StringRef name,
bool defaultValue,
bool value) {
m_status = 0;
return VideoProperty{CreateSourceProperty(
m_handle, name, static_cast<CS_PropertyKind>(static_cast<int>(VideoProperty::Kind::kBoolean)),
0, 1, 1, defaultValue ? 1 : 0, value ? 1 : 0, &m_status)};
}
inline VideoProperty CvSource::CreateStringProperty(llvm::StringRef name,
llvm::StringRef value) {
m_status = 0;
auto prop = VideoProperty{CreateSourceProperty(
m_handle, name, static_cast<CS_PropertyKind>(static_cast<int>(VideoProperty::Kind::kString)),
0, 0, 0, 0, 0, &m_status)};
prop.SetString(value);
return prop;
}
inline void CvSource::SetEnumPropertyChoices(
const VideoProperty& property, llvm::ArrayRef<std::string> choices) {
m_status = 0;
SetSourceEnumPropertyChoices(m_handle, property.m_handle, choices, &m_status);
}
template <typename T>
inline void CvSource::SetEnumPropertyChoices(const VideoProperty& property,
std::initializer_list<T> choices) {
std::vector<std::string> vec;
vec.reserve(choices.size());
for (const auto& choice : choices) vec.emplace_back(choice);
m_status = 0;
SetSourceEnumPropertyChoices(m_handle, property.m_handle, vec, &m_status);
}
inline VideoSink::VideoSink(const VideoSink& sink)
: m_handle(sink.m_handle == 0 ? 0 : CopySink(sink.m_handle, &m_status)) {}
inline VideoSink::VideoSink(VideoSink&& other) noexcept : VideoSink() {
swap(*this, other);
}
inline VideoSink& VideoSink::operator=(VideoSink other) noexcept {
swap(*this, other);
return *this;
}
inline VideoSink::~VideoSink() {
m_status = 0;
if (m_handle != 0) ReleaseSink(m_handle, &m_status);
}
inline VideoSink::Kind VideoSink::GetKind() const {
m_status = 0;
return static_cast<VideoSink::Kind>(GetSinkKind(m_handle, &m_status));
}
inline std::string VideoSink::GetName() const {
m_status = 0;
return GetSinkName(m_handle, &m_status);
}
inline std::string VideoSink::GetDescription() const {
m_status = 0;
return GetSinkDescription(m_handle, &m_status);
}
inline void VideoSink::SetSource(VideoSource source) {
m_status = 0;
if (!source)
SetSinkSource(m_handle, 0, &m_status);
else
SetSinkSource(m_handle, source.m_handle, &m_status);
}
inline VideoSource VideoSink::GetSource() const {
m_status = 0;
auto handle = GetSinkSource(m_handle, &m_status);
return VideoSource{handle == 0 ? 0 : CopySource(handle, &m_status)};
}
inline VideoProperty VideoSink::GetSourceProperty(llvm::StringRef name) {
m_status = 0;
return VideoProperty{GetSinkSourceProperty(m_handle, name, &m_status)};
}
inline MjpegServer::MjpegServer(llvm::StringRef name,
llvm::StringRef listenAddress, int port) {
m_handle = CreateMjpegServer(name, listenAddress, port, &m_status);
}
inline std::string MjpegServer::GetListenAddress() const {
m_status = 0;
return cs::GetMjpegServerListenAddress(m_handle, &m_status);
}
inline int MjpegServer::GetPort() const {
m_status = 0;
return cs::GetMjpegServerPort(m_handle, &m_status);
}
inline CvSink::CvSink(llvm::StringRef name) {
m_handle = CreateCvSink(name, &m_status);
}
inline CvSink::CvSink(llvm::StringRef name,
std::function<void(uint64_t time)> processFrame) {
m_handle = CreateCvSinkCallback(name, processFrame, &m_status);
}
inline void CvSink::SetDescription(llvm::StringRef description) {
m_status = 0;
SetSinkDescription(m_handle, description, &m_status);
}
inline uint64_t CvSink::GrabFrame(cv::Mat& image, double timeout) const {
m_status = 0;
return GrabSinkFrameTimeout(m_handle, image, timeout, &m_status);
}
inline uint64_t CvSink::GrabFrameNoTimeout(cv::Mat& image) const {
m_status = 0;
return GrabSinkFrame(m_handle, image, &m_status);
}
inline std::string CvSink::GetError() const {
m_status = 0;
return GetSinkError(m_handle, &m_status);
}
inline void CvSink::SetEnabled(bool enabled) {
m_status = 0;
SetSinkEnabled(m_handle, enabled, &m_status);
}
inline VideoSource VideoEvent::GetSource() const {
CS_Status status = 0;
return VideoSource{sourceHandle == 0 ? 0 : CopySource(sourceHandle, &status)};
}
inline VideoSink VideoEvent::GetSink() const {
CS_Status status = 0;
return VideoSink{sinkHandle == 0 ? 0 : CopySink(sinkHandle, &status)};
}
inline VideoProperty VideoEvent::GetProperty() const {
return VideoProperty{propertyHandle,
static_cast<VideoProperty::Kind>(propertyKind)};
}
inline VideoListener::VideoListener(
std::function<void(const VideoEvent& event)> callback, int eventMask,
bool immediateNotify) {
CS_Status status = 0;
m_handle = AddListener(
[=](const RawEvent& event) {
callback(static_cast<const VideoEvent&>(event));
},
eventMask, immediateNotify, &status);
}
inline VideoListener::VideoListener(VideoListener&& other) noexcept
: VideoListener() {
swap(*this, other);
}
inline VideoListener& VideoListener::operator=(VideoListener&& other) noexcept {
swap(*this, other);
return *this;
}
inline VideoListener::~VideoListener() {
CS_Status status = 0;
if (m_handle != 0) RemoveListener(m_handle, &status);
}
} // namespace cs
#endif /* CSCORE_OO_INL_ */

View File

@@ -0,0 +1,11 @@
package edu.wpi.cscore;
import org.junit.Test;
public class JNITest {
@Test
public void jniLinkTest() {
// Test to verify that the JNI test link works correctly.
edu.wpi.cscore.CameraServerJNI.getHostname();
}
}

View File

@@ -0,0 +1,24 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2015. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
/*----------------------------------------------------------------------------*/
#include "gtest/gtest.h"
#include "cscore.h"
namespace cs {
class CameraSourceTest : public ::testing::Test {
protected:
CameraSourceTest() {
}
};
TEST_F(CameraSourceTest, HTTPCamera) {
auto source = HttpCamera("axis", "http://localhost:8000");
}
} // namespace cs

View File

@@ -0,0 +1,15 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2015. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
/*----------------------------------------------------------------------------*/
#include "gtest/gtest.h"
int main(int argc, char **argv)
{
::testing::InitGoogleTest(&argc, argv);
int ret = RUN_ALL_TESTS();
return ret;
}