Skip to content

Commit

Permalink
Merge pull request #8 from SatoshiShimada/dev
Browse files Browse the repository at this point in the history
Add new features
  • Loading branch information
SatoshiShimada authored Nov 18, 2018
2 parents cdb5480 + 9394196 commit ecd76c8
Show file tree
Hide file tree
Showing 11 changed files with 409 additions and 85 deletions.
34 changes: 9 additions & 25 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,37 +1,19 @@
language: cpp
dist: trusty
dist: xenial
sudo: false
matrix:
include:
- env: QT_VERSION=qt4
os: linux
compiler: gcc
addons:
apt:
packages:
- libqt4-core
- libqt4-dev
- libqt4-gui
- qt4-dev-tools
- env: QT_VERSION=qt4
os: linux
compiler: clang
addons:
apt:
packages:
- libqt4-core
- libqt4-dev
- libqt4-gui
- qt4-dev-tools
- env: QT_VERSION=qt5
os: linux
compiler: gcc
addons:
apt:
packages:
- build-essential
- qt5-default
- qt5-qmake
- qtbase5-dev-tools
- qtmultimedia5-dev
- env: QT_VERSION=qt5
os: linux
compiler: clang
Expand All @@ -41,19 +23,21 @@ matrix:
- qt5-default
- qt5-qmake
- qtbase5-dev-tools
- env: QT_VERSION=qt4
- qtmultimedia5-dev
- env: QT_VERSION=qt5
os: osx
osx_image: xcode9.2
compiler: gcc
- env: QT_VERSION=qt4
- env: QT_VERSION=qt5
os: osx
osx_image: xcode8
compiler: gcc
- env: QT_VERSION=qt4
- env: QT_VERSION=qt5
os: osx
osx_image: xcode9.2
compiler: clang
before_install:
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew update -all; fi
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew install cartr/qt4/qt; fi
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew install qt; fi
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew link --force qt; fi
script: ./qt_make.sh
27 changes: 22 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ cmake_minimum_required(VERSION 2.8)

project(game_monitor)

if(CMAME_COMPILER_IS_GNUCXX)
add_definitions(-std=c++11)
endif()
set(CMAKE_CXX_STANDARD 11)

set(SRCS
src/interface.cpp
src/interface.h
Expand All @@ -11,11 +16,14 @@ set(SRCS
src/pos_types.h
src/udp_thread.cpp
src/udp_thread.h
src/capture.cpp
src/capture.h
)

set(MOC_HEADERS
src/interface.h
src/udp_thread.h
src/capture.h
)

include(FindSDL)
Expand All @@ -24,21 +32,30 @@ if(NOT_SDL_FOUND)
message(FATAL ERROR "SDL not found!!!")
endif(NOT_SDL_FOUND)

find_package(Qt4 REQUIRED)
find_package(Qt5Widgets REQUIRED)
find_package(Qt5Gui REQUIRED)
find_package(Qt5Network REQUIRED)
find_package(Qt5Multimedia REQUIRED)
find_package(Qt5MultimediaWidgets REQUIRED)

set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTOMOC ON)

set(QT_USE_QTMAIN true)
set(QT_USE_QTGUI true)
set(QT_USE_QTNETWORK true)
set(QT_USE_QTOPENGL true)
include(${QT_USE_FILE})
set(QT_USE_QTMULTIMEDIA true)
add_definitions(${QT_DEFINITIONS})
include_directories(${CMAKE_BINARY_DIR})

QT4_ADD_RESOURCES(RES_SOURCES ${RESOURCES})
QT4_WRAP_CPP(MOC_SRCS ${MOC_HEADERS})

set(CMAKE_BUILD_TYPE Debug)

include_directories(src)
add_executable(game_monitor ${SRCS} ${MOC_SRCS} ${RES_SORUCES})
target_link_libraries(game_monitor ${QT_LIBRARIES})
target_link_libraries(game_monitor Qt5::Widgets)
target_link_libraries(game_monitor Qt5::Network)
target_link_libraries(game_monitor Qt5::Multimedia)
target_link_libraries(game_monitor Qt5::MultimediaWidgets)

18 changes: 4 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,29 +10,19 @@ Please check Wiki for more information.

## Requirements

* [Qt](https://www.qt.io/) (Version: 4.8 or 5)
* [Qt](https://www.qt.io/) (Version: 5.3 or greater)
* gcc (only Linux)
* XCode (only Mac OS)
* Visual Studio (only Windows)

## How to build

### Linux (Ubuntu 14.04)
### Linux (Ubuntu 16.04)

1. Install libraries.

```
apt-get install libqt4-core libqt4-dev libqt4-gui qt4-dev-tools
```

If your system is Ubuntu 12.04, run follow commands.

```
add-apt-repository ppa:ubuntu-toolchain-r/test
apt-get update
apt-get install gcc-4.8 g++-4.8
update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.8 20
update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.8 20
apt install qt5-default
```

2. Build application.
Expand All @@ -47,7 +37,7 @@ update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.8 20

```
brew update -all
brew install cartr/qt4/qt
brew install qt
```

2. Build application.
Expand Down
2 changes: 1 addition & 1 deletion qt_make.bat
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

qmake -project -o game_monitor.pro
qmake "QT += network widgets"
qmake "QT += network widgets multimedia meltimediawidgets"
nmake release
copy release\game_monitor.exe .\
mkdir log
36 changes: 4 additions & 32 deletions qt_make.sh
Original file line number Diff line number Diff line change
@@ -1,43 +1,12 @@
#!/bin/bash -xe

###################
# Requirement
###################
# * g++ (version > 4.8)
# * qt

###################
# HOW TO INSTALL Qt4
# on Ubuntu 14.04
###################
# execute follow command:
#sudo apt-get update && sudo apt-get upgrade
#sudo apt-get install libqt4-core libqt4-dev libqt4-gui qt4-dev-tools

###################
# HOW TO INSTALL g++ version 4.8
# on Ubuntu 12.04
###################
#sudo add-apt-repository ppa:ubuntu-toolchain-r/test
#sudo apt-get update
#sudo apt-get install gcc-4.8 g++-4.8
#sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.8 20
#sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.8 20

###################
# HOW TO BUILD on MacOSX
# install qt4
###################
#brew update -all
#brew install qt4

PROJECT='GameMonitor.pro'

QMAKE='qmake'
echo $($QMAKE --version)
$QMAKE -project -o $PROJECT
echo 'QMAKE_CXXFLAGS += --std=c++11' >> $PROJECT
echo 'QT += network widgets' >> $PROJECT
echo 'QT += network widgets multimedia multimediawidgets' >> $PROJECT

if [ ! -d build ]; then
mkdir build
Expand All @@ -54,4 +23,7 @@ make all -j8
if [ ! -d log ]; then
mkdir log
fi
if [ ! -d videos ]; then
mkdir videos
fi

131 changes: 131 additions & 0 deletions src/capture.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
#include <QMediaService>
#include <QMediaRecorder>
#include <QCameraViewfinder>
#include <QCameraInfo>
#include <QMediaMetaData>

#include "capture.h"

Q_DECLARE_METATYPE(QCameraInfo)

Capture::Capture() : m_isCaptureingImage(false), m_applicationExiting(false)
{
availableCameras = QCameraInfo::availableCameras();
setCamera(QCameraInfo::defaultCamera());
}

Capture::~Capture()
{
}

QList<QCameraInfo> Capture::getCameras(void)
{
return availableCameras;
}

void Capture::setCamera(const QCameraInfo &cameraInfo)
{
m_camera.reset(new QCamera(cameraInfo));

//connect(m_camera.data(), QOverload<QCamera::Error>::of(&QCamera::error), this, &Capture::displayCameraError);

m_mediaRecorder.reset(new QMediaRecorder(m_camera.data()));
connect(m_mediaRecorder.data(), &QMediaRecorder::stateChanged, this, &Capture::updateRecorderState);

connect(m_mediaRecorder.data(), &QMediaRecorder::durationChanged, this, &Capture::updateRecordTime);
//connect(m_mediaRecorder.data(), QOverload<QMediaRecorder::Error>::of(&QMediaRecorder::error), this, &Capture::displayRecorderError);

m_mediaRecorder->setMetaData(QMediaMetaData::Title, QVariant(QLatin1String("Test Title")));

viewfinder = new QCameraViewfinder;
viewfinder->hide();
m_camera->setViewfinder(viewfinder);

updateRecorderState(m_mediaRecorder->state());

//connect(m_camera.data(), QOverload<QCamera::LockStatus, QCamera::LockChangeReason>::of(&QCamera::lockStatusChanged), this, &Camera::updateLockStatus);

updateCaptureMode();
m_camera->start();
}

void Capture::updateCameraDevice(QAction *action)
{
setCamera(qvariant_cast<QCameraInfo>(action->data()));
}

void Capture::updateCaptureMode(void)
{
QCamera::CaptureModes captureMode = QCamera::CaptureVideo;
if(m_camera->isCaptureModeSupported(captureMode))
m_camera->setCaptureMode(captureMode);
}

void Capture::setExposureCompensation(int index)
{
m_camera->exposure()->setExposureCompensation(index * 0.5);
}

void Capture::startCamera(void)
{
m_camera->start();
}

void Capture::stopCamera(void)
{
m_camera->stop();
}

void Capture::record(void)
{
m_mediaRecorder->record();
viewfinder->show();
}

void Capture::pause(void)
{
m_mediaRecorder->pause();
}

void Capture::stop(void)
{
m_mediaRecorder->stop();
viewfinder->hide();
}

void Capture::setFilename(QString filename)
{
QDir name(filename);
m_mediaRecorder->setOutputLocation(QUrl(name.absolutePath()));
}

void Capture::displayCameraError(void)
{
QMessageBox::warning(this, tr("Camera Error"), m_camera->errorString());
}

void Capture::displayRecorderError(void)
{
QMessageBox::warning(this, tr("Capture Error"), m_mediaRecorder->errorString());
}

void Capture::updateRecordTime(void)
{
QString str = QString("Record %1 sec").arg(m_mediaRecorder->duration() / 1000);
emit updateRecordTimeSignal(str);
}

void Capture::updateRecorderState(QMediaRecorder::State state)
{
switch(state) {
case QMediaRecorder::StoppedState:
emit updateRecordButtonMessage(QString("Record"));
break;
case QMediaRecorder::PausedState:
break;
case QMediaRecorder::RecordingState:
emit updateRecordButtonMessage(QString("Stop record"));
break;
}
}

Loading

0 comments on commit ecd76c8

Please sign in to comment.