diff --git a/.clang-format b/.clang-format index 38804f78c4..99ec0442e0 100644 --- a/.clang-format +++ b/.clang-format @@ -1,65 +1,89 @@ --- Language: Cpp -# BasedOnStyle: Google +BasedOnStyle: Google AccessModifierOffset: -1 -AlignAfterOpenBracket: true +AlignAfterOpenBracket: Align +AlignConsecutiveAssignments: false +AlignConsecutiveDeclarations: false AlignEscapedNewlinesLeft: true AlignOperands: true -AlignTrailingComments: true +AlignTrailingComments: false AllowAllParametersOfDeclarationOnNextLine: true AllowShortBlocksOnASingleLine: false AllowShortCaseLabelsOnASingleLine: false +AllowShortFunctionsOnASingleLine: All AllowShortIfStatementsOnASingleLine: true AllowShortLoopsOnASingleLine: true -AllowShortFunctionsOnASingleLine: All -AlwaysBreakAfterDefinitionReturnType: false -AlwaysBreakTemplateDeclarations: true +AlwaysBreakAfterDefinitionReturnType: None +AlwaysBreakAfterReturnType: None AlwaysBreakBeforeMultilineStrings: true +AlwaysBreakTemplateDeclarations: true +BinPackArguments: true +BinPackParameters: true +BraceWrapping: + AfterClass: false + AfterControlStatement: false + AfterEnum: false + AfterFunction: false + AfterNamespace: false + AfterObjCDeclaration: false + AfterStruct: false + AfterUnion: false + BeforeCatch: false + BeforeElse: false + IndentBraces: false BreakBeforeBinaryOperators: None +BreakBeforeBraces: Attach BreakBeforeTernaryOperators: true BreakConstructorInitializersBeforeComma: false -BinPackParameters: true -BinPackArguments: true ColumnLimit: 80 +CommentPragmas: '^ IWYU pragma:' ConstructorInitializerAllOnOneLineOrOnePerLine: true ConstructorInitializerIndentWidth: 4 -DerivePointerAlignment: true +ContinuationIndentWidth: 4 +Cpp11BracedListStyle: true +DerivePointerAlignment: false +DisableFormat: false ExperimentalAutoDetectBinPacking: false +ForEachMacros: [ foreach, Q_FOREACH, BOOST_FOREACH ] +IncludeCategories: + - Regex: '^<.*\.h>' + Priority: 1 + - Regex: '^<.*' + Priority: 2 + - Regex: '.*' + Priority: 3 IndentCaseLabels: true +IndentWidth: 2 IndentWrappedFunctionNames: false -IndentFunctionDeclarationAfterType: false -MaxEmptyLinesToKeep: 1 KeepEmptyLinesAtTheStartOfBlocks: false +MacroBlockBegin: '' +MacroBlockEnd: '' +MaxEmptyLinesToKeep: 1 NamespaceIndentation: None ObjCBlockIndentWidth: 2 ObjCSpaceAfterProperty: false ObjCSpaceBeforeProtocolList: false PenaltyBreakBeforeFirstCallParameter: 1 PenaltyBreakComment: 300 -PenaltyBreakString: 1000 PenaltyBreakFirstLessLess: 120 +PenaltyBreakString: 1000 PenaltyExcessCharacter: 1000000 PenaltyReturnTypeOnItsOwnLine: 200 PointerAlignment: Left +ReflowComments: true +SortIncludes: false +SpaceAfterCStyleCast: false +SpaceBeforeAssignmentOperators: true +SpaceBeforeParens: ControlStatements +SpaceInEmptyParentheses: false SpacesBeforeTrailingComments: 2 -Cpp11BracedListStyle: true -Standard: Auto -IndentWidth: 2 -TabWidth: 8 -UseTab: Never -BreakBeforeBraces: Attach +SpacesInAngles: false +SpacesInContainerLiterals: true +SpacesInCStyleCastParentheses: false SpacesInParentheses: false SpacesInSquareBrackets: false -SpacesInAngles: false -SpaceInEmptyParentheses: false -SpacesInCStyleCastParentheses: false -SpaceAfterCStyleCast: false -SpacesInContainerLiterals: true -SpaceBeforeAssignmentOperators: true -ContinuationIndentWidth: 4 -CommentPragmas: '^ IWYU pragma:' -ForEachMacros: [ foreach, Q_FOREACH, BOOST_FOREACH ] -SpaceBeforeParens: ControlStatements -DisableFormat: false +Standard: Auto +TabWidth: 8 +UseTab: Never ... - diff --git a/.styleguide b/.styleguide new file mode 100644 index 0000000000..8f73663169 --- /dev/null +++ b/.styleguide @@ -0,0 +1,35 @@ +cppHeaderExtensions { + h + hpp + inc +} + +cppSrcExtensions { + cpp +} + +otherExtensions { + java +} + +genFileExclude { + gmock/ + src/arm-linux-jni/ + src/main/native/cpp/jni/CameraServerJNI\.cpp$ +} + +licenseUpdateExclude { + src/main/native/cpp/default_init_allocator\.h$ +} + +includeGuardRoots { + src/main/native/cpp/ + src/main/native/include/ +} + +includeOtherLibs { + ^llvm/ + ^opencv2/ + ^support/ + ^tcpsockets/ +} diff --git a/.styleguide-license b/.styleguide-license new file mode 100644 index 0000000000..b8023700ce --- /dev/null +++ b/.styleguide-license @@ -0,0 +1,6 @@ +/*----------------------------------------------------------------------------*/ +/* Copyright (c) {year} FIRST. All Rights Reserved.{padding}*/ +/* 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. */ +/*----------------------------------------------------------------------------*/ diff --git a/examples/enum_usb/enum_usb.cpp b/examples/enum_usb/enum_usb.cpp index 7c46b75b2d..8a326b9620 100644 --- a/examples/enum_usb/enum_usb.cpp +++ b/examples/enum_usb/enum_usb.cpp @@ -1,7 +1,14 @@ -#include "cscore.h" +/*----------------------------------------------------------------------------*/ +/* Copyright (c) 2017 FIRST. 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 "llvm/SmallString.h" -#include "llvm/raw_ostream.h" +#include +#include + +#include "cscore.h" int main() { CS_Status status = 0; @@ -17,7 +24,8 @@ int main() { llvm::outs() << " " << prop.GetName(); switch (prop.GetKind()) { case cs::VideoProperty::kBoolean: - llvm::outs() << " (bool): " << "value=" << prop.Get() + llvm::outs() << " (bool): " + << "value=" << prop.Get() << " default=" << prop.GetDefault(); break; case cs::VideoProperty::kInteger: @@ -30,7 +38,8 @@ int main() { llvm::outs() << " (string): " << prop.GetString(buf); break; case cs::VideoProperty::kEnum: { - llvm::outs() << " (enum): " << "value=" << prop.Get(); + llvm::outs() << " (enum): " + << "value=" << prop.Get(); auto choices = prop.GetChoices(); for (size_t i = 0; i < choices.size(); ++i) { if (choices[i].empty()) continue; @@ -48,10 +57,18 @@ int main() { for (const auto& mode : camera.EnumerateVideoModes()) { llvm::outs() << " PixelFormat:"; switch (mode.pixelFormat) { - case cs::VideoMode::kMJPEG: llvm::outs() << "MJPEG"; break; - case cs::VideoMode::kYUYV: llvm::outs() << "YUYV"; break; - case cs::VideoMode::kRGB565: llvm::outs() << "RGB565"; break; - default: llvm::outs() << "Unknown"; break; + case cs::VideoMode::kMJPEG: + llvm::outs() << "MJPEG"; + break; + case cs::VideoMode::kYUYV: + llvm::outs() << "YUYV"; + break; + case cs::VideoMode::kRGB565: + llvm::outs() << "RGB565"; + break; + default: + llvm::outs() << "Unknown"; + break; } llvm::outs() << " Width:" << mode.width; llvm::outs() << " Height:" << mode.height; diff --git a/examples/httpcvstream/httpcvstream.cpp b/examples/httpcvstream/httpcvstream.cpp index e631218e95..a331fd7b38 100644 --- a/examples/httpcvstream/httpcvstream.cpp +++ b/examples/httpcvstream/httpcvstream.cpp @@ -1,8 +1,16 @@ -#include "cscore.h" -#include "opencv2/core/core.hpp" +/*----------------------------------------------------------------------------*/ +/* Copyright (c) 2017 FIRST. 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 #include -#include + +#include + +#include "cscore.h" int main() { cs::HttpCamera camera{"httpcam", "http://localhost:8081/?action=stream"}; @@ -21,7 +29,8 @@ int main() { std::cout << "error: " << cvsink.GetError() << std::endl; continue; } - std::cout << "got frame at time " << time << " size " << test.size() << std::endl; + std::cout << "got frame at time " << time << " size " << test.size() + << std::endl; cv::flip(test, flip, 0); cvsource.PutFrame(flip); } diff --git a/examples/settings/settings.cpp b/examples/settings/settings.cpp index 69327e7fdd..84e91aa2ca 100644 --- a/examples/settings/settings.cpp +++ b/examples/settings/settings.cpp @@ -1,10 +1,17 @@ +/*----------------------------------------------------------------------------*/ +/* Copyright (c) 2017 FIRST. 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 #include -#include "cscore.h" +#include +#include -#include "llvm/SmallString.h" -#include "llvm/raw_ostream.h" +#include "cscore.h" int main(int argc, char** argv) { if (argc < 2) { @@ -25,9 +32,9 @@ int main(int argc, char** argv) { int arg = 2; llvm::StringRef propName; for (; arg < argc && llvm::StringRef{argv[arg]} != "--"; ++arg) { - if (propName.empty()) + if (propName.empty()) { propName = argv[arg]; - else { + } else { llvm::StringRef propVal{argv[arg]}; int intVal; if (propVal.getAsInteger(10, intVal)) @@ -46,9 +53,9 @@ int main(int argc, char** argv) { // Set rest propName = llvm::StringRef{}; for (; arg < argc; ++arg) { - if (propName.empty()) + if (propName.empty()) { propName = argv[arg]; - else { + } else { llvm::StringRef propVal{argv[arg]}; int intVal; if (propVal.getAsInteger(10, intVal)) @@ -66,7 +73,8 @@ int main(int argc, char** argv) { llvm::outs() << " " << prop.GetName(); switch (prop.GetKind()) { case cs::VideoProperty::kBoolean: - llvm::outs() << " (bool): " << "value=" << prop.Get() + llvm::outs() << " (bool): " + << "value=" << prop.Get() << " default=" << prop.GetDefault(); break; case cs::VideoProperty::kInteger: @@ -79,7 +87,8 @@ int main(int argc, char** argv) { llvm::outs() << " (string): " << prop.GetString(buf); break; case cs::VideoProperty::kEnum: { - llvm::outs() << " (enum): " << "value=" << prop.Get(); + llvm::outs() << " (enum): " + << "value=" << prop.Get(); auto choices = prop.GetChoices(); for (size_t i = 0; i < choices.size(); ++i) { if (choices[i].empty()) continue; diff --git a/examples/usbcvstream/usbcvstream.cpp b/examples/usbcvstream/usbcvstream.cpp index feea0b0a83..8f42bd30ee 100644 --- a/examples/usbcvstream/usbcvstream.cpp +++ b/examples/usbcvstream/usbcvstream.cpp @@ -1,8 +1,16 @@ -#include "cscore.h" -#include "opencv2/core/core.hpp" +/*----------------------------------------------------------------------------*/ +/* Copyright (c) 2017 FIRST. 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 #include -#include + +#include + +#include "cscore.h" int main() { cs::UsbCamera camera{"usbcam", 0}; @@ -23,7 +31,8 @@ int main() { std::cout << "error: " << cvsink.GetError() << std::endl; continue; } - std::cout << "got frame at time " << time << " size " << test.size() << std::endl; + std::cout << "got frame at time " << time << " size " << test.size() + << std::endl; cv::flip(test, flip, 0); cvsource.PutFrame(flip); } diff --git a/examples/usbstream/usbstream.cpp b/examples/usbstream/usbstream.cpp index 16e133fb95..6718370c7d 100644 --- a/examples/usbstream/usbstream.cpp +++ b/examples/usbstream/usbstream.cpp @@ -1,9 +1,16 @@ +/*----------------------------------------------------------------------------*/ +/* Copyright (c) 2017 FIRST. 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 + +#include + #include "cscore.h" -#include - -#include "llvm/raw_ostream.h" - int main() { llvm::outs() << "hostname: " << cs::GetHostname() << '\n'; llvm::outs() << "IPv4 network addresses:\n"; @@ -14,5 +21,5 @@ int main() { cs::MjpegServer mjpegServer{"httpserver", 8081}; mjpegServer.SetSource(camera); - getchar(); + std::getchar(); } diff --git a/src/dev/java/edu/wpi/cscore/DevMain.java b/src/dev/java/edu/wpi/cscore/DevMain.java index e3ba359eb7..f3664fd8a9 100644 --- a/src/dev/java/edu/wpi/cscore/DevMain.java +++ b/src/dev/java/edu/wpi/cscore/DevMain.java @@ -1,3 +1,10 @@ +/*----------------------------------------------------------------------------*/ +/* Copyright (c) 2017 FIRST. 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 edu.wpi.cscore.CameraServerJNI; diff --git a/src/dev/native/cpp/main.cpp b/src/dev/native/cpp/main.cpp index 43045931b7..6d91eae1a7 100644 --- a/src/dev/native/cpp/main.cpp +++ b/src/dev/native/cpp/main.cpp @@ -1,6 +1,12 @@ +/*----------------------------------------------------------------------------*/ +/* Copyright (c) 2017 FIRST. 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 + #include "cscore.h" -int main() { - std::cout << cs::GetHostname() << std::endl; -} +int main() { std::cout << cs::GetHostname() << std::endl; } diff --git a/src/main/java/edu/wpi/cscore/AxisCamera.java b/src/main/java/edu/wpi/cscore/AxisCamera.java index 00e411bc7b..363ee84443 100644 --- a/src/main/java/edu/wpi/cscore/AxisCamera.java +++ b/src/main/java/edu/wpi/cscore/AxisCamera.java @@ -1,5 +1,5 @@ /*----------------------------------------------------------------------------*/ -/* Copyright (c) FIRST 2016. All Rights Reserved. */ +/* Copyright (c) 2016-2017 FIRST. 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. */ diff --git a/src/main/java/edu/wpi/cscore/CameraServerJNI.java b/src/main/java/edu/wpi/cscore/CameraServerJNI.java index 08c16bfcef..684bbf6452 100644 --- a/src/main/java/edu/wpi/cscore/CameraServerJNI.java +++ b/src/main/java/edu/wpi/cscore/CameraServerJNI.java @@ -1,5 +1,5 @@ /*----------------------------------------------------------------------------*/ -/* Copyright (c) FIRST 2016. All Rights Reserved. */ +/* Copyright (c) 2016-2017 FIRST. 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. */ diff --git a/src/main/java/edu/wpi/cscore/CvSink.java b/src/main/java/edu/wpi/cscore/CvSink.java index 3792115713..2512b823d7 100644 --- a/src/main/java/edu/wpi/cscore/CvSink.java +++ b/src/main/java/edu/wpi/cscore/CvSink.java @@ -1,5 +1,5 @@ /*----------------------------------------------------------------------------*/ -/* Copyright (c) FIRST 2016. All Rights Reserved. */ +/* Copyright (c) 2016-2017 FIRST. 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. */ diff --git a/src/main/java/edu/wpi/cscore/CvSource.java b/src/main/java/edu/wpi/cscore/CvSource.java index 8edd34f7e7..bf3e52e98c 100644 --- a/src/main/java/edu/wpi/cscore/CvSource.java +++ b/src/main/java/edu/wpi/cscore/CvSource.java @@ -1,5 +1,5 @@ /*----------------------------------------------------------------------------*/ -/* Copyright (c) FIRST 2016. All Rights Reserved. */ +/* Copyright (c) 2016-2017 FIRST. 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. */ @@ -84,7 +84,7 @@ public class CvSource extends VideoSource { 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 @@ -97,7 +97,7 @@ public class CvSource extends VideoSource { 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 @@ -107,7 +107,7 @@ public class CvSource extends VideoSource { 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 diff --git a/src/main/java/edu/wpi/cscore/HttpCamera.java b/src/main/java/edu/wpi/cscore/HttpCamera.java index c79c5154b1..ae789703e4 100644 --- a/src/main/java/edu/wpi/cscore/HttpCamera.java +++ b/src/main/java/edu/wpi/cscore/HttpCamera.java @@ -1,5 +1,5 @@ /*----------------------------------------------------------------------------*/ -/* Copyright (c) FIRST 2016. All Rights Reserved. */ +/* Copyright (c) 2016-2017 FIRST. 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. */ diff --git a/src/main/java/edu/wpi/cscore/MjpegServer.java b/src/main/java/edu/wpi/cscore/MjpegServer.java index 43900b3760..72a09b848b 100644 --- a/src/main/java/edu/wpi/cscore/MjpegServer.java +++ b/src/main/java/edu/wpi/cscore/MjpegServer.java @@ -1,5 +1,5 @@ /*----------------------------------------------------------------------------*/ -/* Copyright (c) FIRST 2016. All Rights Reserved. */ +/* Copyright (c) 2016-2017 FIRST. 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. */ diff --git a/src/main/java/edu/wpi/cscore/UsbCamera.java b/src/main/java/edu/wpi/cscore/UsbCamera.java index f58d751f28..1649017e20 100644 --- a/src/main/java/edu/wpi/cscore/UsbCamera.java +++ b/src/main/java/edu/wpi/cscore/UsbCamera.java @@ -1,5 +1,5 @@ /*----------------------------------------------------------------------------*/ -/* Copyright (c) FIRST 2016. All Rights Reserved. */ +/* Copyright (c) 2016-2017 FIRST. 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. */ diff --git a/src/main/java/edu/wpi/cscore/UsbCameraInfo.java b/src/main/java/edu/wpi/cscore/UsbCameraInfo.java index 4217c3b8b0..ccc80bbb05 100644 --- a/src/main/java/edu/wpi/cscore/UsbCameraInfo.java +++ b/src/main/java/edu/wpi/cscore/UsbCameraInfo.java @@ -1,5 +1,5 @@ /*----------------------------------------------------------------------------*/ -/* Copyright (c) FIRST 2016. All Rights Reserved. */ +/* Copyright (c) 2016-2017 FIRST. 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. */ diff --git a/src/main/java/edu/wpi/cscore/VideoCamera.java b/src/main/java/edu/wpi/cscore/VideoCamera.java index 718a1fb478..96e7849d29 100644 --- a/src/main/java/edu/wpi/cscore/VideoCamera.java +++ b/src/main/java/edu/wpi/cscore/VideoCamera.java @@ -1,5 +1,5 @@ /*----------------------------------------------------------------------------*/ -/* Copyright (c) FIRST 2016. All Rights Reserved. */ +/* Copyright (c) 2016-2017 FIRST. 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. */ diff --git a/src/main/java/edu/wpi/cscore/VideoEvent.java b/src/main/java/edu/wpi/cscore/VideoEvent.java index bd8fbf9ff7..10960bf55d 100644 --- a/src/main/java/edu/wpi/cscore/VideoEvent.java +++ b/src/main/java/edu/wpi/cscore/VideoEvent.java @@ -1,5 +1,5 @@ /*----------------------------------------------------------------------------*/ -/* Copyright (c) FIRST 2016. All Rights Reserved. */ +/* Copyright (c) 2016-2017 FIRST. 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. */ diff --git a/src/main/java/edu/wpi/cscore/VideoException.java b/src/main/java/edu/wpi/cscore/VideoException.java index affe36feed..2eabe8121e 100644 --- a/src/main/java/edu/wpi/cscore/VideoException.java +++ b/src/main/java/edu/wpi/cscore/VideoException.java @@ -1,5 +1,5 @@ /*----------------------------------------------------------------------------*/ -/* Copyright (c) FIRST 2016. All Rights Reserved. */ +/* Copyright (c) 2016-2017 FIRST. 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. */ diff --git a/src/main/java/edu/wpi/cscore/VideoListener.java b/src/main/java/edu/wpi/cscore/VideoListener.java index 89b351de7b..8bd9ca25eb 100644 --- a/src/main/java/edu/wpi/cscore/VideoListener.java +++ b/src/main/java/edu/wpi/cscore/VideoListener.java @@ -1,5 +1,5 @@ /*----------------------------------------------------------------------------*/ -/* Copyright (c) FIRST 2016. All Rights Reserved. */ +/* Copyright (c) 2016-2017 FIRST. 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. */ diff --git a/src/main/java/edu/wpi/cscore/VideoMode.java b/src/main/java/edu/wpi/cscore/VideoMode.java index 839baf54fd..2ffaad2afa 100644 --- a/src/main/java/edu/wpi/cscore/VideoMode.java +++ b/src/main/java/edu/wpi/cscore/VideoMode.java @@ -1,5 +1,5 @@ /*----------------------------------------------------------------------------*/ -/* Copyright (c) FIRST 2016. All Rights Reserved. */ +/* Copyright (c) 2016-2017 FIRST. 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. */ diff --git a/src/main/java/edu/wpi/cscore/VideoProperty.java b/src/main/java/edu/wpi/cscore/VideoProperty.java index e05b889074..3b038dd2e1 100644 --- a/src/main/java/edu/wpi/cscore/VideoProperty.java +++ b/src/main/java/edu/wpi/cscore/VideoProperty.java @@ -1,5 +1,5 @@ /*----------------------------------------------------------------------------*/ -/* Copyright (c) FIRST 2016. All Rights Reserved. */ +/* Copyright (c) 2016-2017 FIRST. 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. */ diff --git a/src/main/java/edu/wpi/cscore/VideoSink.java b/src/main/java/edu/wpi/cscore/VideoSink.java index d0d72b49fb..d438cd8452 100644 --- a/src/main/java/edu/wpi/cscore/VideoSink.java +++ b/src/main/java/edu/wpi/cscore/VideoSink.java @@ -1,5 +1,5 @@ /*----------------------------------------------------------------------------*/ -/* Copyright (c) FIRST 2016. All Rights Reserved. */ +/* Copyright (c) 2016-2017 FIRST. 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. */ diff --git a/src/main/java/edu/wpi/cscore/VideoSource.java b/src/main/java/edu/wpi/cscore/VideoSource.java index cd98f661cf..5b0d169ae2 100644 --- a/src/main/java/edu/wpi/cscore/VideoSource.java +++ b/src/main/java/edu/wpi/cscore/VideoSource.java @@ -1,5 +1,5 @@ /*----------------------------------------------------------------------------*/ -/* Copyright (c) FIRST 2016. All Rights Reserved. */ +/* Copyright (c) 2016-2017 FIRST. 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. */ diff --git a/src/main/native/cpp/CvSinkImpl.cpp b/src/main/native/cpp/CvSinkImpl.cpp index 1113395b5b..f1adf2fc80 100644 --- a/src/main/native/cpp/CvSinkImpl.cpp +++ b/src/main/native/cpp/CvSinkImpl.cpp @@ -1,5 +1,5 @@ /*----------------------------------------------------------------------------*/ -/* Copyright (c) FIRST 2016. All Rights Reserved. */ +/* Copyright (c) 2016-2017 FIRST. 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. */ @@ -7,16 +7,16 @@ #include "CvSinkImpl.h" -#include "llvm/SmallString.h" -#include "opencv2/core/core.hpp" -#include "opencv2/imgproc/imgproc.hpp" -#include "opencv2/highgui/highgui.hpp" +#include +#include +#include +#include -#include "cscore_cpp.h" -#include "c_util.h" #include "Handle.h" #include "Log.h" #include "Notifier.h" +#include "c_util.h" +#include "cscore_cpp.h" using namespace cs; @@ -35,8 +35,7 @@ void CvSinkImpl::Stop() { m_active = false; // wake up any waiters by forcing an empty frame to be sent - if (auto source = GetSource()) - source->Wakeup(); + if (auto source = GetSource()) source->Wakeup(); // join thread if (m_thread.joinable()) m_thread.join(); @@ -225,7 +224,7 @@ uint64_t CS_GrabSinkFrameTimeout(CS_Sink sink, struct CvMat* image, } uint64_t CS_GrabSinkFrameCpp(CS_Sink sink, cv::Mat* image, CS_Status* status) { - return cs::GrabSinkFrame(sink, *image, status); + return cs::GrabSinkFrame(sink, *image, status); } uint64_t CS_GrabSinkFrameTimeoutCpp(CS_Sink sink, cv::Mat* image, diff --git a/src/main/native/cpp/CvSinkImpl.h b/src/main/native/cpp/CvSinkImpl.h index afb5631b32..64e963922e 100644 --- a/src/main/native/cpp/CvSinkImpl.h +++ b/src/main/native/cpp/CvSinkImpl.h @@ -1,12 +1,12 @@ /*----------------------------------------------------------------------------*/ -/* Copyright (c) FIRST 2016. All Rights Reserved. */ +/* Copyright (c) 2016-2017 FIRST. 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 CS_CVSINKIMPL_H_ -#define CS_CVSINKIMPL_H_ +#ifndef CSCORE_CVSINKIMPL_H_ +#define CSCORE_CVSINKIMPL_H_ #include #include @@ -15,13 +15,13 @@ #include #include -#include "llvm/raw_ostream.h" -#include "llvm/SmallVector.h" -#include "llvm/StringRef.h" -#include "support/raw_istream.h" -#include "support/raw_socket_ostream.h" -#include "tcpsockets/NetworkAcceptor.h" -#include "tcpsockets/NetworkStream.h" +#include +#include +#include +#include +#include +#include +#include #include "SinkImpl.h" @@ -31,7 +31,7 @@ class SourceImpl; class CvSinkImpl : public SinkImpl { public: - CvSinkImpl(llvm::StringRef name); + explicit CvSinkImpl(llvm::StringRef name); CvSinkImpl(llvm::StringRef name, std::function processFrame); ~CvSinkImpl() override; @@ -51,4 +51,4 @@ class CvSinkImpl : public SinkImpl { } // namespace cs -#endif // CS_CVSINKIMPL_H_ +#endif // CSCORE_CVSINKIMPL_H_ diff --git a/src/main/native/cpp/CvSourceImpl.cpp b/src/main/native/cpp/CvSourceImpl.cpp index 559b223624..726b7a64ae 100644 --- a/src/main/native/cpp/CvSourceImpl.cpp +++ b/src/main/native/cpp/CvSourceImpl.cpp @@ -1,5 +1,5 @@ /*----------------------------------------------------------------------------*/ -/* Copyright (c) FIRST 2016. All Rights Reserved. */ +/* Copyright (c) 2016-2017 FIRST. 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. */ @@ -7,17 +7,17 @@ #include "CvSourceImpl.h" -#include "llvm/STLExtras.h" -#include "opencv2/core/core.hpp" -#include "opencv2/imgproc/imgproc.hpp" -#include "opencv2/highgui/highgui.hpp" -#include "support/timestamp.h" +#include +#include +#include +#include +#include -#include "cscore_cpp.h" -#include "c_util.h" #include "Handle.h" #include "Log.h" #include "Notifier.h" +#include "c_util.h" +#include "cscore_cpp.h" using namespace cs; @@ -346,8 +346,7 @@ void CS_PutSourceFrame(CS_Source source, struct CvMat* image, return cs::PutSourceFrame(source, mat, status); } -void CS_PutSourceFrameCpp(CS_Source source, cv::Mat* image, - CS_Status* status) { +void CS_PutSourceFrameCpp(CS_Source source, cv::Mat* image, CS_Status* status) { return cs::PutSourceFrame(source, *image, status); } diff --git a/src/main/native/cpp/CvSourceImpl.h b/src/main/native/cpp/CvSourceImpl.h index d51621cbb5..88f3ae1abf 100644 --- a/src/main/native/cpp/CvSourceImpl.h +++ b/src/main/native/cpp/CvSourceImpl.h @@ -1,15 +1,17 @@ /*----------------------------------------------------------------------------*/ -/* Copyright (c) FIRST 2016. All Rights Reserved. */ +/* Copyright (c) 2016-2017 FIRST. 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 CS_CVSOURCEIMPL_H_ -#define CS_CVSOURCEIMPL_H_ +#ifndef CSCORE_CVSOURCEIMPL_H_ +#define CSCORE_CVSOURCEIMPL_H_ #include #include +#include +#include #include #include "SourceImpl.h" @@ -58,7 +60,7 @@ class CvSourceImpl : public SourceImpl { class PropertyData : public PropertyImpl { public: PropertyData() = default; - PropertyData(llvm::StringRef name_) : PropertyImpl{name_} {} + explicit PropertyData(llvm::StringRef name_) : PropertyImpl{name_} {} PropertyData(llvm::StringRef name_, CS_PropertyKind kind_, int minimum_, int maximum_, int step_, int defaultValue_, int value_) : PropertyImpl{name_, kind_, step_, defaultValue_, value_} { @@ -84,4 +86,4 @@ class CvSourceImpl : public SourceImpl { } // namespace cs -#endif // CS_CVSOURCEIMPL_H_ +#endif // CSCORE_CVSOURCEIMPL_H_ diff --git a/src/main/native/cpp/Frame.cpp b/src/main/native/cpp/Frame.cpp index 8f90b8b012..8fcfe5275a 100644 --- a/src/main/native/cpp/Frame.cpp +++ b/src/main/native/cpp/Frame.cpp @@ -1,5 +1,5 @@ /*----------------------------------------------------------------------------*/ -/* Copyright (c) FIRST 2016. All Rights Reserved. */ +/* Copyright (c) 2016-2017 FIRST. 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. */ @@ -7,9 +7,9 @@ #include "Frame.h" -#include "opencv2/core/core.hpp" -#include "opencv2/imgproc/imgproc.hpp" -#include "opencv2/highgui/highgui.hpp" +#include +#include +#include #include "Log.h" #include "SourceImpl.h" @@ -200,11 +200,11 @@ Image* Frame::Convert(Image* image, VideoMode::PixelFormat pixelFormat, return ConvertBGRToGray(cur); case VideoMode::kBGR: case VideoMode::kMJPEG: - if (cur->pixelFormat == VideoMode::kYUYV) + if (cur->pixelFormat == VideoMode::kYUYV) { cur = ConvertYUYVToBGR(cur); - else if (cur->pixelFormat == VideoMode::kRGB565) + } else if (cur->pixelFormat == VideoMode::kRGB565) { cur = ConvertRGB565ToBGR(cur); - else if (cur->pixelFormat == VideoMode::kGray) { + } else if (cur->pixelFormat == VideoMode::kGray) { if (pixelFormat == VideoMode::kBGR) return ConvertGrayToBGR(cur); else diff --git a/src/main/native/cpp/Frame.h b/src/main/native/cpp/Frame.h index 940c1e7e69..4024fde0e6 100644 --- a/src/main/native/cpp/Frame.h +++ b/src/main/native/cpp/Frame.h @@ -1,21 +1,24 @@ /*----------------------------------------------------------------------------*/ -/* Copyright (c) FIRST 2016. All Rights Reserved. */ +/* Copyright (c) 2016-2017 FIRST. 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 CS_FRAME_H_ -#define CS_FRAME_H_ +#ifndef CSCORE_FRAME_H_ +#define CSCORE_FRAME_H_ #include #include #include +#include +#include +#include -#include "llvm/SmallVector.h" +#include -#include "cscore_cpp.h" #include "Image.h" +#include "cscore_cpp.h" namespace cs { @@ -29,7 +32,7 @@ class Frame { private: struct Impl { - Impl(SourceImpl& source_) : source(source_) {} + explicit Impl(SourceImpl& source_) : source(source_) {} std::recursive_mutex mutex; std::atomic_int refcount{0}; @@ -95,7 +98,7 @@ class Frame { return m_impl->images[0]->pixelFormat; } - Image* GetExistingImage(std::size_t i = 0) const { + Image* GetExistingImage(size_t i = 0) const { if (!m_impl) return nullptr; std::lock_guard lock(m_impl->mutex); if (i >= m_impl->images.size()) return nullptr; @@ -156,4 +159,4 @@ class Frame { } // namespace cs -#endif // CS_FRAME_H_ +#endif // CSCORE_FRAME_H_ diff --git a/src/main/native/cpp/Handle.cpp b/src/main/native/cpp/Handle.cpp index efa198c77f..f47ef53277 100644 --- a/src/main/native/cpp/Handle.cpp +++ b/src/main/native/cpp/Handle.cpp @@ -1,5 +1,5 @@ /*----------------------------------------------------------------------------*/ -/* Copyright (c) FIRST 2016. All Rights Reserved. */ +/* Copyright (c) 2016-2017 FIRST. 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. */ diff --git a/src/main/native/cpp/Handle.h b/src/main/native/cpp/Handle.h index 0dd64b4d13..0b7d5ff62c 100644 --- a/src/main/native/cpp/Handle.h +++ b/src/main/native/cpp/Handle.h @@ -1,19 +1,21 @@ /*----------------------------------------------------------------------------*/ -/* Copyright (c) FIRST 2016. All Rights Reserved. */ +/* Copyright (c) 2016-2017 FIRST. 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 CS_HANDLE_H_ -#define CS_HANDLE_H_ +#ifndef CSCORE_HANDLE_H_ +#define CSCORE_HANDLE_H_ #include +#include +#include -#include "llvm/StringRef.h" +#include -#include "cscore_c.h" #include "UnlimitedHandleResource.h" +#include "cscore_c.h" namespace cs { @@ -27,16 +29,10 @@ class SourceImpl; class Handle { public: - enum Type { - kUndefined = 0, - kProperty = 0x40, - kSource, - kSink, - kListener - }; + enum Type { kUndefined = 0, kProperty = 0x40, kSource, kSink, kListener }; enum { kIndexMax = 0xffff }; - Handle(CS_Handle handle) : m_handle(handle) {} + Handle(CS_Handle handle) : m_handle(handle) {} // NOLINT operator CS_Handle() const { return m_handle; } Handle(int index, Type type) { @@ -129,4 +125,4 @@ class Sinks : public UnlimitedHandleResource { } // namespace cs -#endif // CS_HANDLE_H_ +#endif // CSCORE_HANDLE_H_ diff --git a/src/main/native/cpp/HttpCameraImpl.cpp b/src/main/native/cpp/HttpCameraImpl.cpp index 494bc92abb..ce8f5f644f 100644 --- a/src/main/native/cpp/HttpCameraImpl.cpp +++ b/src/main/native/cpp/HttpCameraImpl.cpp @@ -1,5 +1,5 @@ /*----------------------------------------------------------------------------*/ -/* Copyright (c) FIRST 2016. All Rights Reserved. */ +/* Copyright (c) 2016-2017 FIRST. 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. */ @@ -7,15 +7,15 @@ #include "HttpCameraImpl.h" -#include "llvm/STLExtras.h" -#include "support/timestamp.h" -#include "tcpsockets/TCPConnector.h" +#include +#include +#include -#include "c_util.h" #include "Handle.h" #include "JpegUtil.h" #include "Log.h" #include "Notifier.h" +#include "c_util.h" using namespace cs; @@ -569,8 +569,7 @@ char** CS_GetHttpCameraUrls(CS_Source source, int* count, CS_Status* status) { auto urls = cs::GetHttpCameraUrls(source, status); char** out = static_cast(std::malloc(urls.size() * sizeof(char*))); *count = urls.size(); - for (std::size_t i = 0; i < urls.size(); ++i) - out[i] = cs::ConvertToC(urls[i]); + for (size_t i = 0; i < urls.size(); ++i) out[i] = cs::ConvertToC(urls[i]); return out; } diff --git a/src/main/native/cpp/HttpCameraImpl.h b/src/main/native/cpp/HttpCameraImpl.h index 2cdf203b5d..b4c726be9d 100644 --- a/src/main/native/cpp/HttpCameraImpl.h +++ b/src/main/native/cpp/HttpCameraImpl.h @@ -1,27 +1,29 @@ /*----------------------------------------------------------------------------*/ -/* Copyright (c) FIRST 2016. All Rights Reserved. */ +/* Copyright (c) 2016-2017 FIRST. 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 CS_HTTPCAMERAIMPL_H_ -#define CS_HTTPCAMERAIMPL_H_ +#ifndef CSCORE_HTTPCAMERAIMPL_H_ +#define CSCORE_HTTPCAMERAIMPL_H_ #include #include #include #include +#include +#include #include #include -#include "llvm/SmallString.h" -#include "llvm/StringMap.h" -#include "support/raw_istream.h" +#include +#include +#include -#include "cscore_cpp.h" #include "HttpUtil.h" #include "SourceImpl.h" +#include "cscore_cpp.h" namespace cs { @@ -60,7 +62,7 @@ class HttpCameraImpl : public SourceImpl { class PropertyData : public PropertyImpl { public: PropertyData() = default; - PropertyData(llvm::StringRef name_) : PropertyImpl{name_} {} + explicit PropertyData(llvm::StringRef name_) : PropertyImpl{name_} {} PropertyData(llvm::StringRef name_, llvm::StringRef httpParam_, bool viaSettings_, CS_PropertyKind kind_, int minimum_, int maximum_, int step_, int defaultValue_, int value_) @@ -122,7 +124,7 @@ class HttpCameraImpl : public SourceImpl { CS_HttpCameraKind m_kind; std::vector m_locations; - std::size_t m_nextLocation{0}; + size_t m_nextLocation{0}; int m_prefLocation{-1}; // preferred location std::condition_variable m_sinkEnabledCond; @@ -136,7 +138,8 @@ class HttpCameraImpl : public SourceImpl { class AxisCameraImpl : public HttpCameraImpl { public: - AxisCameraImpl(llvm::StringRef name) : HttpCameraImpl{name, CS_HTTP_AXIS} {} + explicit AxisCameraImpl(llvm::StringRef name) + : HttpCameraImpl{name, CS_HTTP_AXIS} {} #if 0 void SetProperty(int property, int value, CS_Status* status) override; void SetStringProperty(int property, llvm::StringRef value, @@ -148,4 +151,4 @@ class AxisCameraImpl : public HttpCameraImpl { } // namespace cs -#endif // CS_HTTPCAMERAIMPL_H_ +#endif // CSCORE_HTTPCAMERAIMPL_H_ diff --git a/src/main/native/cpp/HttpUtil.cpp b/src/main/native/cpp/HttpUtil.cpp index 0a7b0ad07c..55b7fb1c87 100644 --- a/src/main/native/cpp/HttpUtil.cpp +++ b/src/main/native/cpp/HttpUtil.cpp @@ -1,5 +1,5 @@ /*----------------------------------------------------------------------------*/ -/* Copyright (c) FIRST 2016. All Rights Reserved. */ +/* Copyright (c) 2016-2017 FIRST. 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. */ @@ -9,10 +9,10 @@ #include -#include "llvm/STLExtras.h" -#include "support/Base64.h" -#include "llvm/StringExtras.h" -#include "tcpsockets/TCPConnector.h" +#include +#include +#include +#include #include "Log.h" @@ -76,7 +76,7 @@ llvm::StringRef UnescapeURI(llvm::StringRef str, llvm::StringRef EscapeURI(llvm::StringRef str, llvm::SmallVectorImpl& buf, bool spacePlus) { - static const char *const hexLut = "0123456789ABCDEF"; + static const char* const hexLut = "0123456789ABCDEF"; buf.clear(); for (auto i = str.begin(), end = str.end(); i != end; ++i) { @@ -104,7 +104,6 @@ llvm::StringRef EscapeURI(llvm::StringRef str, llvm::SmallVectorImpl& buf, bool ParseHttpHeaders(wpi::raw_istream& is, llvm::SmallVectorImpl* contentType, llvm::SmallVectorImpl* contentLength) { - if (contentType) contentType->clear(); if (contentLength) contentLength->clear(); @@ -176,11 +175,9 @@ bool FindMultipartBoundary(wpi::raw_istream& is, llvm::StringRef boundary, // Fast-scan for '-' size_t pos = searchBuf.find('-', searchBuf[0] == '-' ? 1 : 0); if (pos == llvm::StringRef::npos) { - if (saveBuf) - saveBuf->append(searchBuf.data(), searchBuf.size()); + if (saveBuf) saveBuf->append(searchBuf.data(), searchBuf.size()); } else { - if (saveBuf) - saveBuf->append(searchBuf.data(), pos); + if (saveBuf) saveBuf->append(searchBuf.data(), pos); // move '-' and following to start of buffer (next read will fill) std::memmove(searchBuf.data(), searchBuf.data() + pos, diff --git a/src/main/native/cpp/HttpUtil.h b/src/main/native/cpp/HttpUtil.h index 95873e52c3..1a19d29066 100644 --- a/src/main/native/cpp/HttpUtil.h +++ b/src/main/native/cpp/HttpUtil.h @@ -1,25 +1,27 @@ /*----------------------------------------------------------------------------*/ -/* Copyright (c) FIRST 2016. All Rights Reserved. */ +/* Copyright (c) 2016-2017 FIRST. 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 CS_HTTPUTIL_H_ -#define CS_HTTPUTIL_H_ +#ifndef CSCORE_HTTPUTIL_H_ +#define CSCORE_HTTPUTIL_H_ #include #include +#include +#include -#include "llvm/ArrayRef.h" -#include "llvm/SmallString.h" -#include "llvm/SmallVector.h" -#include "llvm/StringMap.h" -#include "llvm/StringRef.h" -#include "support/raw_istream.h" -#include "support/raw_socket_istream.h" -#include "support/raw_socket_ostream.h" -#include "tcpsockets/NetworkStream.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include namespace cs { @@ -85,7 +87,8 @@ class HttpRequest { public: HttpRequest() = default; - HttpRequest(const HttpLocation& loc) : host{loc.host}, port{loc.port} { + explicit HttpRequest(const HttpLocation& loc) + : host{loc.host}, port{loc.port} { SetPath(loc.path, loc.params); SetAuth(loc); } @@ -116,13 +119,17 @@ class HttpRequest { void SetPath(llvm::StringRef path_, const T& params); template - static llvm::StringRef GetFirst(const T& elem) { return elem.first; } + static llvm::StringRef GetFirst(const T& elem) { + return elem.first; + } template static llvm::StringRef GetFirst(const llvm::StringMapEntry& elem) { return elem.getKey(); } template - static llvm::StringRef GetSecond(const T& elem) { return elem.second; } + static llvm::StringRef GetSecond(const T& elem) { + return elem.second; + } }; class HttpConnection { @@ -147,4 +154,4 @@ class HttpConnection { #include "HttpUtil.inl" -#endif // CS_HTTPUTIL_H_ +#endif // CSCORE_HTTPUTIL_H_ diff --git a/src/main/native/cpp/Image.h b/src/main/native/cpp/Image.h index d8c7028705..19bfbe955d 100644 --- a/src/main/native/cpp/Image.h +++ b/src/main/native/cpp/Image.h @@ -1,18 +1,17 @@ /*----------------------------------------------------------------------------*/ -/* Copyright (c) FIRST 2016. All Rights Reserved. */ +/* Copyright (c) 2016-2017 FIRST. 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 CS_IMAGE_H_ -#define CS_IMAGE_H_ +#ifndef CSCORE_IMAGE_H_ +#define CSCORE_IMAGE_H_ #include -#include "llvm/StringRef.h" - -#include "opencv2/core/core.hpp" +#include +#include #include "cscore_cpp.h" #include "default_init_allocator.h" @@ -25,13 +24,10 @@ class Image { friend class Frame; public: - #ifndef __linux__ - explicit Image(std::size_t capacity) { - m_data.reserve(capacity); - } + explicit Image(size_t capacity) { m_data.reserve(capacity); } #else - explicit Image(std::size_t capacity) + explicit Image(size_t capacity) : m_data{capacity, default_init_allocator{}} { m_data.resize(0); } @@ -43,18 +39,18 @@ class Image { // Getters operator llvm::StringRef() const { return str(); } llvm::StringRef str() const { return llvm::StringRef(data(), size()); } - std::size_t capacity() const { return m_data.capacity(); } + size_t capacity() const { return m_data.capacity(); } const char* data() const { return reinterpret_cast(m_data.data()); } char* data() { return reinterpret_cast(m_data.data()); } - std::size_t size() const { return m_data.size(); } + size_t size() const { return m_data.size(); } const std::vector& vec() const { return m_data; } std::vector& vec() { return m_data; } - void resize(std::size_t size) { m_data.resize(size); } - void SetSize(std::size_t size) { m_data.resize(size); } + void resize(size_t size) { m_data.resize(size); } + void SetSize(size_t size) { m_data.resize(size); } cv::Mat AsMat() { int type; @@ -103,4 +99,4 @@ class Image { } // namespace cs -#endif // CS_IMAGE_H_ +#endif // CSCORE_IMAGE_H_ diff --git a/src/main/native/cpp/JpegUtil.cpp b/src/main/native/cpp/JpegUtil.cpp index 7f82dc8801..27bfbb5dd2 100644 --- a/src/main/native/cpp/JpegUtil.cpp +++ b/src/main/native/cpp/JpegUtil.cpp @@ -1,5 +1,5 @@ /*----------------------------------------------------------------------------*/ -/* Copyright (c) FIRST 2016. All Rights Reserved. */ +/* Copyright (c) 2016-2017 FIRST. 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. */ @@ -7,7 +7,7 @@ #include "JpegUtil.h" -#include "support/raw_istream.h" +#include namespace cs { @@ -54,8 +54,7 @@ bool IsJpeg(llvm::StringRef data) { // Check for valid SOI auto bytes = data.bytes_begin(); - if (bytes[0] != 0xff || bytes[1] != 0xd8) - return false; + if (bytes[0] != 0xff || bytes[1] != 0xd8) return false; #if 0 // Check for valid JPEG header (null terminated JFIF) if (bytes[2] == 0xff && bytes[3] == 0xe0) { @@ -72,7 +71,7 @@ bool GetJpegSize(llvm::StringRef data, int* width, int* height) { auto bytes = data.bytes_begin(); size_t blockLength = bytes[4] * 256 + bytes[5] + 4; for (;;) { - data = data.substr(blockLength); // Get to the next block + data = data.substr(blockLength); // Get to the next block if (data.size() < 4) return false; // EOF bytes = data.bytes_begin(); if (bytes[0] != 0xff) return false; // not a tag @@ -88,7 +87,7 @@ bool GetJpegSize(llvm::StringRef data, int* width, int* height) { } } -bool JpegNeedsDHT(const char* data, std::size_t* size, std::size_t* locSOF) { +bool JpegNeedsDHT(const char* data, size_t* size, size_t* locSOF) { llvm::StringRef sdata(data, *size); if (!IsJpeg(sdata)) return false; @@ -98,12 +97,12 @@ bool JpegNeedsDHT(const char* data, std::size_t* size, std::size_t* locSOF) { auto bytes = sdata.bytes_begin(); size_t blockLength = bytes[4] * 256 + bytes[5] + 4; for (;;) { - sdata = sdata.substr(blockLength); // Get to the next block + sdata = sdata.substr(blockLength); // Get to the next block if (sdata.size() < 4) return false; // EOF bytes = sdata.bytes_begin(); - if (bytes[0] != 0xff) return false; // not a tag - if (bytes[1] == 0xda) break; // SOS - if (bytes[1] == 0xc4) return false; // DHT + if (bytes[0] != 0xff) return false; // not a tag + if (bytes[1] == 0xda) break; // SOS + if (bytes[1] == 0xc4) return false; // DHT if (bytes[1] == 0xc0) *locSOF = sdata.data() - data; // SOF // Go to the next block blockLength = bytes[2] * 256 + bytes[3] + 2; @@ -129,8 +128,7 @@ static inline void ReadInto(wpi::raw_istream& is, std::string& buf, is.read(&(*buf.begin()) + oldSize, len); } -bool ReadJpeg(wpi::raw_istream& is, std::string& buf, int* width, - int* height) { +bool ReadJpeg(wpi::raw_istream& is, std::string& buf, int* width, int* height) { // in case we don't get a SOF *width = 0; *height = 0; @@ -163,7 +161,7 @@ bool ReadJpeg(wpi::raw_istream& is, std::string& buf, int* width, pos += blockLength; bytes = reinterpret_cast(buf.data() + pos); - if (bytes[0] != 0xff) return false; // not a tag + if (bytes[0] != 0xff) return false; // not a tag if (bytes[1] == 0xda) { // SOS: need to keep reading until we reach a normal marker. // Byte stuffing ensures we don't get false markers. @@ -178,15 +176,16 @@ bool ReadJpeg(wpi::raw_istream& is, std::string& buf, int* width, (bytes[0] < 0xd0 || bytes[0] > 0xd7)) break; maybeMarker = false; - } else if (bytes[0] == 0xff) + } else if (bytes[0] == 0xff) { maybeMarker = true; + } } // Point back to the start of the block --pos; bytes = reinterpret_cast(buf.data() + pos); } - if (bytes[0] != 0xff) return false; // not a tag - if (bytes[1] == 0xd9) return true; // EOI, we're done + if (bytes[0] != 0xff) return false; // not a tag + if (bytes[1] == 0xd9) return true; // EOI, we're done if (bytes[1] == 0xc0) sofBlock = true; // SOF // Go to the next block diff --git a/src/main/native/cpp/JpegUtil.h b/src/main/native/cpp/JpegUtil.h index 808ed4f379..f347b6c62e 100644 --- a/src/main/native/cpp/JpegUtil.h +++ b/src/main/native/cpp/JpegUtil.h @@ -1,14 +1,16 @@ /*----------------------------------------------------------------------------*/ -/* Copyright (c) FIRST 2016. All Rights Reserved. */ +/* Copyright (c) 2016-2017 FIRST. 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 CS_JPEGUTIL_H_ -#define CS_JPEGUTIL_H_ +#ifndef CSCORE_JPEGUTIL_H_ +#define CSCORE_JPEGUTIL_H_ -#include "llvm/StringRef.h" +#include + +#include namespace wpi { class raw_istream; @@ -20,7 +22,7 @@ bool IsJpeg(llvm::StringRef data); bool GetJpegSize(llvm::StringRef data, int* width, int* height); -bool JpegNeedsDHT(const char* data, std::size_t* size, std::size_t* locSOF); +bool JpegNeedsDHT(const char* data, size_t* size, size_t* locSOF); llvm::StringRef JpegGetDHT(); @@ -28,4 +30,4 @@ bool ReadJpeg(wpi::raw_istream& is, std::string& buf, int* width, int* height); } // namespace cs -#endif // CS_JPEGUTIL_H_ +#endif // CSCORE_JPEGUTIL_H_ diff --git a/src/main/native/cpp/Log.cpp b/src/main/native/cpp/Log.cpp index ea46a30858..e20e6d786a 100644 --- a/src/main/native/cpp/Log.cpp +++ b/src/main/native/cpp/Log.cpp @@ -1,5 +1,5 @@ /*----------------------------------------------------------------------------*/ -/* Copyright (c) FIRST 2016. All Rights Reserved. */ +/* Copyright (c) 2016-2017 FIRST. 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. */ @@ -7,19 +7,20 @@ #include "Log.h" -#include -#ifdef _WIN32 - #include -#else - #include -#endif - #ifdef __APPLE__ - #include +#include #endif #ifdef __ANDROID__ - #include +#include +#endif + +#include + +#ifdef _WIN32 +#include +#else +#include #endif using namespace cs; @@ -49,9 +50,9 @@ static void def_log_func(unsigned int level, const char* file, std::fprintf(stderr, "CS: %s: %s (%s%s:%d)\n", levelmsg, msg, fname, ext, line); #elif __APPLE__ - int len = strlen(msg) + 1; + int len = std::strlen(msg) + 1; char* basestr = new char[len + 1]; - strncpy(basestr, file, len); + std::strncpy(basestr, file, len); std::fprintf(stderr, "CS: %s: %s (%s:%d)\n", levelmsg, msg, basename(basestr), line); delete[] basestr; diff --git a/src/main/native/cpp/Log.h b/src/main/native/cpp/Log.h index 744ee13733..070d9d61d5 100644 --- a/src/main/native/cpp/Log.h +++ b/src/main/native/cpp/Log.h @@ -1,15 +1,15 @@ /*----------------------------------------------------------------------------*/ -/* Copyright (c) FIRST 2016. All Rights Reserved. */ +/* Copyright (c) 2016-2017 FIRST. 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 CS_LOG_H_ -#define CS_LOG_H_ +#ifndef CSCORE_LOG_H_ +#define CSCORE_LOG_H_ -#include "support/atomic_static.h" -#include "support/Logger.h" +#include +#include namespace cs { @@ -52,6 +52,6 @@ class Logger : public wpi::Logger { #define SDEBUG3(x) DEBUG3(GetName() << ": " << x) #define SDEBUG4(x) DEBUG4(GetName() << ": " << x) -} // namespace cs +} // namespace cs -#endif // CS_LOG_H_ +#endif // CSCORE_LOG_H_ diff --git a/src/main/native/cpp/MjpegServerImpl.cpp b/src/main/native/cpp/MjpegServerImpl.cpp index d9c6f5888c..1b5ca107b6 100644 --- a/src/main/native/cpp/MjpegServerImpl.cpp +++ b/src/main/native/cpp/MjpegServerImpl.cpp @@ -1,5 +1,5 @@ /*----------------------------------------------------------------------------*/ -/* Copyright (c) FIRST 2016. All Rights Reserved. */ +/* Copyright (c) 2016-2017 FIRST. 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. */ @@ -9,23 +9,22 @@ #include -#include "llvm/SmallString.h" -#include "support/raw_socket_istream.h" -#include "support/raw_socket_ostream.h" -#include "tcpsockets/TCPAcceptor.h" +#include +#include +#include +#include -#include "c_util.h" -#include "cscore_cpp.h" #include "Handle.h" #include "HttpUtil.h" #include "JpegUtil.h" #include "Log.h" #include "Notifier.h" #include "SourceImpl.h" +#include "c_util.h" +#include "cscore_cpp.h" using namespace cs; - // The boundary used for the M-JPEG stream. // It separates the multipart stream of pictures #define BOUNDARY "boundarydonotcross" @@ -38,11 +37,13 @@ static const char* emptyRootPage = ""; // An HTML page to be sent when a source exists -static const char* startRootPage = "\n" +static const char* startRootPage = + "\n" "