summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorzhou_xin <zhou_xin@dl.cn.nexty-ele.com>2019-03-15 09:55:47 +0800
committerzhou_xin <zhou_xin@dl.cn.nexty-ele.com>2019-03-15 09:55:47 +0800
commit05e2633e175e98f5b510777f9402b70f3d4ba751 (patch)
tree434f220102a56b1a9a672507c0e9d5a2568294f6
parent1e69db0b5eb9cfa6781e2c046d05dcca3a5bd909 (diff)
Commit original sourcesandbox/wanglu/settings-log-utils
-rw-r--r--CMakeLists.txt23
-rw-r--r--LICENSE54
-rw-r--r--tsutils/CMakeLists.txt30
-rw-r--r--tsutils/tsplayer.c309
-rw-r--r--tsutils/tsrecorder.c134
-rw-r--r--tsutils/tsutils.c80
-rw-r--r--videoutils/CMakeLists.txt34
-rw-r--r--videoutils/videoutils.cpp239
-rw-r--r--videoutils/videoutils.h58
9 files changed, 961 insertions, 0 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
new file mode 100644
index 0000000..67e4185
--- /dev/null
+++ b/CMakeLists.txt
@@ -0,0 +1,23 @@
+#
+# Copyright (c) 2018 TOYOTA MOTOR CORPORATION
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+cmake_minimum_required(VERSION 2.8)
+
+project(log-utils)
+
+add_subdirectory(tsutils)
+add_subdirectory(videoutils)
+
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..31c692a
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,54 @@
+Apache License
+
+Version 2.0, January 2004
+
+http://www.apache.org/licenses/
+
+TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+1. Definitions.
+
+"License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document.
+
+"Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License.
+
+"Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity.
+
+"You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License.
+
+"Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files.
+
+"Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types.
+
+"Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below).
+
+"Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof.
+
+"Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution."
+
+"Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work.
+
+2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form.
+
+3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed.
+
+4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions:
+
+ You must give any other recipients of the Work or Derivative Works a copy of this License; and
+ You must cause any modified files to carry prominent notices stating that You changed the files; and
+ You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and
+ If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License.
+
+5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions.
+
+6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file.
+
+7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License.
+
+8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages.
+
+9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability.
+
+END OF TERMS AND CONDITIONS
diff --git a/tsutils/CMakeLists.txt b/tsutils/CMakeLists.txt
new file mode 100644
index 0000000..96e457c
--- /dev/null
+++ b/tsutils/CMakeLists.txt
@@ -0,0 +1,30 @@
+#
+# Copyright (c) 2018 TOYOTA MOTOR CORPORATION
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+set(TARGETS_REC tsrecorder)
+set(TARGETS_PLAY tsplayer)
+
+#add executable file
+add_executable(${TARGETS_REC}
+ tsrecorder.c tsutils.c)
+
+add_executable(${TARGETS_PLAY}
+ tsplayer.c tsutils.c)
+
+install(TARGETS ${TARGETS_REC} ${TARGETS_PLAY}
+ RUNTIME DESTINATION /usr/bin
+)
+
diff --git a/tsutils/tsplayer.c b/tsutils/tsplayer.c
new file mode 100644
index 0000000..9410514
--- /dev/null
+++ b/tsutils/tsplayer.c
@@ -0,0 +1,309 @@
+#include <fcntl.h>
+#include <linux/input.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <stdint.h>
+#include <unistd.h>
+
+typedef struct List
+{
+ int operIndex;
+ int seconds;
+ int microseconds;
+ uint16_t event_Type;
+ uint16_t event_Code;
+ float event_Value;
+ struct List *nextGp;
+}List;
+
+List *eventListHeader;
+List *eventListLast1;
+List *eventListLast2;
+List *eventListLast3;
+
+int touchScreenFd;
+
+extern char* getTouchScreenInfo();
+
+void deleteEventList() {
+ List *prevItem = eventListHeader;
+ List *nextItem = prevItem->nextGp;
+ while(prevItem && nextItem) {
+ free(prevItem);
+ prevItem = nextItem;
+ nextItem = nextItem->nextGp;
+ }
+
+ if (prevItem) {
+ free(prevItem);
+ }
+}
+
+void initEventList()
+{
+ eventListHeader = (struct List*)malloc(sizeof(struct List));
+
+ if (!eventListHeader)
+ {
+ printf("init event list failed. Exit\n");
+ exit(0);
+ }
+ else
+ {
+ memset(eventListHeader,0,sizeof(struct List));
+ eventListHeader->nextGp = NULL;
+ }
+
+ eventListLast1 = NULL;
+ eventListLast2 = NULL;
+ eventListLast3 = NULL;
+}
+
+void checkTouchUp(List *temp)
+{
+ if((temp->event_Type == 3) && (temp->event_Code == 57) && (temp->event_Value == -1))
+ {
+ if(eventListLast1 == NULL)
+ {
+ eventListLast1 = temp;
+ }
+ else if(eventListLast2 == NULL)
+ {
+ eventListLast2 = eventListLast1;
+ eventListLast1 = temp;
+ }
+ else
+ {
+ eventListLast3 = eventListLast2;
+ eventListLast2 = eventListLast1;
+ eventListLast1 = temp;
+ }
+ }
+}
+
+void deleteRedundantData()
+{
+ List *prevItem = eventListLast3->nextGp->nextGp->nextGp;
+ List *nextItem = prevItem->nextGp;
+ while(prevItem && nextItem) {
+ free(prevItem);
+ prevItem = nextItem;
+ nextItem = nextItem->nextGp;
+ }
+
+ if (prevItem) {
+ free(prevItem);
+ }
+}
+
+void tailCreatList(char *fname)
+{
+ List *tmpData;
+ List *tail;
+
+ char buffer[512];
+
+ FILE *inFile;
+ inFile = fopen(fname,"r");
+
+ if (inFile == NULL)
+ {
+ printf("\nFailed to open the file : %s . Exit\n",fname);
+ exit(0);
+ }
+
+ initEventList();
+ tail = eventListHeader;
+
+ memset(buffer,0,sizeof(buffer));
+
+ while(fgets(buffer,sizeof(buffer),inFile))
+ {
+ tmpData = (struct List*)malloc(sizeof(struct List));
+ if (!tmpData)
+ {
+ printf("Faild to create event list. Exit\n");
+ fclose(inFile);
+ exit(0);
+ }
+
+ memset(tmpData,0,sizeof(struct List));
+
+ tmpData->nextGp = NULL;
+ sscanf(buffer,"%d %d %d %hu %hu %f",&(tmpData->operIndex),&(tmpData->seconds),&(tmpData->microseconds),&(tmpData->event_Type),&(tmpData->event_Code),&(tmpData->event_Value));
+
+ checkTouchUp(tmpData);
+ tail->nextGp = tmpData;
+ tail = tmpData;
+
+ memset(buffer,0,sizeof(buffer));
+ }
+
+ if(eventListLast3 != NULL)
+ {
+ tail = eventListLast3->nextGp->nextGp;
+ deleteRedundantData();
+ }
+
+ tail->nextGp = NULL;
+
+ fclose(inFile);
+
+ return;
+}
+
+int reportKey(int fd, uint16_t type, uint16_t code, int32_t value)
+{
+ struct input_event event;
+ event.type = type;
+ event.code = code;
+ event.value = value;
+
+ gettimeofday(&event.time, 0);
+
+ if (write(fd, &event, sizeof(struct input_event)) < 0) {
+ printf("report key error!\n");
+ return -1;
+ }
+
+ return 0;
+}
+
+void touchEventTest(List *listHeader, int screenWidth, int screenHeight,
+ int delayTime)
+{
+ List *p = listHeader->nextGp;
+ printf("--------Touch Event Test Start!!!--------\n");
+
+ while(p != NULL)
+ {
+ if ((p->event_Type == 3) && ((p->event_Code == 53) || (p->event_Code == 0)))
+ {
+ reportKey(touchScreenFd,p->event_Type,p->event_Code,p->event_Value * screenWidth);
+ }
+ else if ((p->event_Type == 3) && ((p->event_Code == 54) || (p->event_Code == 1)))
+ {
+ reportKey(touchScreenFd,p->event_Type,p->event_Code,p->event_Value * screenHeight);
+ }
+ else
+ {
+ reportKey(touchScreenFd,p->event_Type,p->event_Code,p->event_Value);
+ }
+
+ if (p->nextGp != NULL)
+ {
+ usleep((p->nextGp->seconds - p->seconds) * 1000000 + (p->nextGp->microseconds - p->microseconds));
+ }
+
+ p = p->nextGp;
+
+ }
+ printf("--------Touch Event Test End!!!--------\n");
+}
+
+int appNeedEventTestStart(int tsWidth, int tsHeight, char* eventNode,
+ char* eventFile, int delayTime)
+{
+ touchScreenFd = open(eventNode, O_RDWR);
+
+ if (touchScreenFd < 0)
+ {
+ printf("Open %s failed.\n", eventNode);
+ return -1;
+ }
+
+ tailCreatList(eventFile);
+
+ touchEventTest(eventListHeader, tsWidth, tsHeight, delayTime);
+
+ close(touchScreenFd);
+ deleteEventList();
+
+ return 1;
+}
+
+void printUsage(char* myName)
+{
+ printf("usage:\n \
+ %s -a <string> -d <number> -c <string> -e <number> -f <string>\n \
+ -a : application name(must)\n \
+ -d : the time interval(> 0) for capturing logs(unit:ms)(must).\n \
+ -c : child process name(s).If more than one, sperated by ','. \n\t\tEg. -c process1,prcocess2,process3.\n \
+ -f : file name for recorded event. If -e is 1, then -f must be specified.\n \
+ -e : 1 for apps that need events, 0 for apps that does not need events.Default is 0. \n", myName);
+}
+
+int main(int argc,char *argv[])
+{
+ int index = 0;
+ int screenWidth, screenHeight;
+ char eventFileName[100];
+ char eventNode[50];
+ const char* tsInfo;
+ int needEvents = 0;
+ int delayTime = 0;
+
+ if (argc < 5)
+ {
+ printUsage(argv[0]);
+ return -1;
+ }
+
+ memset(eventFileName, 0, sizeof(eventFileName));
+ memset(eventNode, 0, sizeof(eventNode));
+
+ for (index = 1; index < argc; index ++)
+ {
+ if (strcmp(argv[index], "-f") == 0)
+ {
+ memcpy(eventFileName, argv[++index], strlen(argv[index]));
+ }
+ else if (strcmp(argv[index], "-d") == 0)
+ {
+ delayTime = atoi(argv[++index]);
+ }
+ else if (strcmp(argv[index], "-e") == 0)
+ {
+ needEvents = atoi(argv[++index]);
+ }
+ else
+ {
+ printUsage(argv[0]);
+ return -1;
+ }
+ }
+
+ if (0 == delayTime) {
+ printf("Please specify an interval time(> 0)\n");
+ printUsage(argv[0]);
+ return -1;
+ }
+
+ printf("step %d. \n", __LINE__);
+ if ((1 == needEvents) && (0 == strlen(eventFileName))) {
+ printf("You should specify a file for recorded event.\n");
+ printUsage(argv[0]);
+ return -1;
+ }
+ printf("step %d. \n", __LINE__);
+
+ if (1 == needEvents)
+ {
+ printf("step %d. \n", __LINE__);
+ tsInfo = getTouchScreenInfo();
+ printf("step %d. \n", __LINE__);
+ if (NULL == tsInfo) {
+ printf("Failed to get touch screen info.\n");
+ return -1;
+ }
+ printf("step %d. tsInfo = %s. \n", __LINE__, tsInfo);
+
+ sscanf(tsInfo, "%s %d %d", eventNode, &screenWidth, &screenHeight);
+ appNeedEventTestStart(screenWidth, screenHeight, eventNode, eventFileName,
+ delayTime);
+ printf("step %d. \n", __LINE__);
+
+ }
+ return 0;
+} \ No newline at end of file
diff --git a/tsutils/tsrecorder.c b/tsutils/tsrecorder.c
new file mode 100644
index 0000000..63accac
--- /dev/null
+++ b/tsutils/tsrecorder.c
@@ -0,0 +1,134 @@
+#include <fcntl.h>
+#include <linux/input.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <stdint.h>
+#include <unistd.h>
+
+static int eventFd = -1;
+static FILE* pfile;
+struct input_event ev0[64];
+static int screenWidth = 0;
+static int screenHeight = 0;
+
+extern char* getTouchScreenInfo();
+
+static int handle_event()
+{
+ int i, rd;
+ char str[256];
+ float x = 0, y = 0;
+
+ rd = read(eventFd, ev0, sizeof(struct input_event)* 64);
+
+ if(rd < sizeof(struct input_event))
+ return 0;
+
+ for(i=0;i<rd/sizeof(struct input_event); i++)
+ {
+ memset(str, 0, sizeof(str));
+
+ if(ev0[i].type == 3)
+ {
+ if(ev0[i].code == 53 || ev0[i].code == 0)
+ {//screen widthに対して変換
+ x = (float)ev0[i].value / screenWidth;
+ sprintf(str, "%2d\t%ld\t%ld\t%3hu\t%3hu\t%f\r\n",
+ i, ev0[i].time.tv_sec, ev0[i].time.tv_usec, ev0[i].type, ev0[i].code, x);
+ }
+ else if(ev0[i].code == 54 || ev0[i].code == 1)
+ {//screen heightに対して変換
+ y = (float)ev0[i].value / screenHeight;
+ sprintf(str, "%2d\t%ld\t%ld\t%3hu\t%3hu\t%f\r\n",
+ i, ev0[i].time.tv_sec, ev0[i].time.tv_usec, ev0[i].type, ev0[i].code, y);
+ }
+ else
+ {
+ sprintf(str, "%2d\t%ld\t%ld\t%3hu\t%3hu\t%d\r\n", i, ev0[i].time.tv_sec, ev0[i].time.tv_usec, ev0[i].type, ev0[i].code, ev0[i].value);
+ }
+ }
+ else
+ {
+ sprintf(str, "%2d\t%ld\t%ld\t%3hu\t%3hu\t%d\r\n", i, ev0[i].time.tv_sec, ev0[i].time.tv_usec, ev0[i].type, ev0[i].code, ev0[i].value);
+ }
+
+ fputs(str, pfile);
+ }
+ fflush(pfile);
+ return 1;
+}
+
+void printUsage(char* myName)
+{
+ printf("usage:\n \
+ %s -f <string>\n \
+ -f : file name for recording event\n", myName);
+}
+
+int main(int argc,char *argv[])
+{
+ int done = 1;
+ int index = 0;
+ char* fName = NULL;
+ char eventNode[50];
+ const char* tsInfo;
+
+ if (argc < 3)
+ {
+ printUsage(argv[0]);
+ return -1;
+ }
+
+ for (index = 1; index < argc; index++)
+ {
+ if (strcmp(argv[index], "-f") == 0)
+ {
+ fName = argv[++index];
+ }
+ else
+ {
+ printUsage(argv[0]);
+ return -1;
+ }
+ }
+
+ tsInfo = getTouchScreenInfo();
+ if (NULL == tsInfo) {
+ printf("Failed to get touch screen info.\n");
+ return -1;
+ }
+
+ memset(eventNode, 0, sizeof(eventNode));
+ sscanf(tsInfo, "%s %d %d", eventNode, &screenWidth, &screenHeight);
+
+ eventFd = open(eventNode, 02);
+ if(eventFd <0) {
+ printf("open input device error\n");
+ return -1;
+ }
+
+ pfile = fopen(fName, "wb+");
+ if(pfile == NULL)
+ {
+ printf("Failed to create file!\n");
+ return -1;
+ }
+
+ while (done)
+ {
+ printf("begin %s...\n", eventNode);
+ done = handle_event();
+ printf("end %s...\n", eventNode);
+ }
+
+ fclose(pfile);
+
+ if(eventFd > 0)
+ {
+ close(eventFd);
+ eventFd = -1;
+ }
+
+ return 0;
+}
diff --git a/tsutils/tsutils.c b/tsutils/tsutils.c
new file mode 100644
index 0000000..8a6d400
--- /dev/null
+++ b/tsutils/tsutils.c
@@ -0,0 +1,80 @@
+#include <dirent.h>
+#include <linux/input.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include <string.h>
+
+#define LONG_BITS (sizeof(long) << 3)
+#define NUM_LONGS(bits) (((bits) + LONG_BITS - 1) / LONG_BITS)
+#define DEV_INPUT "/dev/input"
+
+char tsInfo[200];
+
+static inline int testBit(long bit, const long *array) {
+ return (array[bit / LONG_BITS] >> bit % LONG_BITS) & 1;
+}
+
+char* getTouchScreenInfo() {
+ DIR* dir;
+ struct dirent* itemPtr;
+ int fd;
+ int isSingleTouch = 0, hasTouchScreen = 0;
+ long absbits[NUM_LONGS(ABS_CNT)];
+ char tsDevNode[100];
+ struct input_absinfo absInfo;
+
+ int maxX, maxY;
+
+ memset(tsDevNode, 0, sizeof(tsDevNode));
+ memset(tsInfo, 0, sizeof(tsInfo));
+
+ if ((dir = opendir(DEV_INPUT)) == NULL) {
+ printf("open %s failed.\n", DEV_INPUT);
+ return NULL;
+ }
+
+ while ((itemPtr = readdir(dir)) != NULL) {
+ //printf("name : %s---type : %d\n", itemPtr->d_name, itemPtr->d_type);
+ if ((strstr(itemPtr->d_name, "event") != NULL) && (2 == itemPtr->d_type)) {
+ sprintf(tsDevNode, "%s/%s", DEV_INPUT, itemPtr->d_name);
+ fd = open(tsDevNode, O_RDONLY);
+ if (fd < 0) {
+ printf("open %s failed.\n", tsDevNode);
+ return NULL;
+ }
+
+ if (ioctl(fd, EVIOCGBIT(EV_ABS, sizeof(absbits)), absbits) >= 0) {
+ isSingleTouch = !testBit(ABS_MT_POSITION_X, absbits);
+ } else {
+ close(fd);
+ continue;
+ }
+
+ if (ioctl(fd, EVIOCGABS((isSingleTouch ? ABS_X : ABS_MT_POSITION_X)), &absInfo) >= 0) {
+ maxX = absInfo.maximum;
+ } else {
+ close(fd);
+ continue;
+ }
+
+ if (ioctl(fd, EVIOCGABS((isSingleTouch ? ABS_Y : ABS_MT_POSITION_Y)), &absInfo) >= 0) {
+ maxY = absInfo.maximum;
+ } else {
+ close(fd);
+ continue;
+ }
+
+ hasTouchScreen = 1;
+ break;
+ }
+ }
+
+ if (!hasTouchScreen) return NULL;
+
+ sprintf(tsInfo, "%s %d %d", tsDevNode, maxX, maxY);
+
+ close(fd);
+ closedir(dir);
+ return tsInfo;
+} \ No newline at end of file
diff --git a/videoutils/CMakeLists.txt b/videoutils/CMakeLists.txt
new file mode 100644
index 0000000..c92782c
--- /dev/null
+++ b/videoutils/CMakeLists.txt
@@ -0,0 +1,34 @@
+#
+# Copyright (c) 2018 TOYOTA MOTOR CORPORATION
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+include(FindPkgConfig)
+pkg_check_modules(GLIB2 REQUIRED glib-2.0)
+pkg_check_modules(OPENCV REQUIRED opencv)
+
+set(TARGETS_VIDEO videoutils)
+
+include_directories(${GLIB2_INCLUDE_DIRS} ${OPENCV_INCLUDE_DIRS})
+link_directories(${GLIB2_LIBRARY_DIRS} ${OPENCV_LIBRARY_DIRS})
+link_libraries(${GLIB2_LIBRARIES} ${OPENCV_LIBRARIES})
+
+#add executable file
+add_executable(${TARGETS_VIDEO}
+ videoutils.cpp)
+
+install(TARGETS ${TARGETS_VIDEO}
+ RUNTIME DESTINATION /usr/bin
+)
+
diff --git a/videoutils/videoutils.cpp b/videoutils/videoutils.cpp
new file mode 100644
index 0000000..88da625
--- /dev/null
+++ b/videoutils/videoutils.cpp
@@ -0,0 +1,239 @@
+#include "videoutils.h"
+#include <opencv2/core.hpp>
+#include <opencv2/imgproc/imgproc.hpp>
+
+#include <iostream>
+#include <unistd.h>
+#include <stdlib.h>
+#include <boost/algorithm/string.hpp>
+#include <glib.h>
+#include <sys/time.h>
+
+using namespace VIDEO_UTILS;
+
+GMainLoop * mainloop = NULL;
+static int grabImage(void *data);
+static void printhelp(const char *argv0);
+static void mainLoopQuit(int sig);
+
+VideoUtils::VideoUtils(int device, int framerate, int wid, int hght, std::string file, std::string co)
+ : fps(framerate), width(wid), height(hght), deviceno(device), codec(co), filename(file)
+{
+ cvCapture = std::unique_ptr < cv::VideoCapture > (new cv::VideoCapture());
+ cvWriter = std::unique_ptr < cv::VideoWriter > (new cv::VideoWriter());
+
+ isReady = false;
+ framecount = 0;
+
+ if (cvCapture && !cvCapture->isOpened())
+ {
+ if (cvCapture->open(deviceno))
+ {
+ cvCapture->set(cv::CAP_PROP_FRAME_WIDTH, width);
+ cvCapture->set(cv::CAP_PROP_FRAME_HEIGHT, height);
+
+ if (cvWriter && !cvWriter->isOpened())
+ {
+ isReady = openVideoWriter();
+ }
+ }
+ }
+}
+
+void VideoUtils::releaseSource()
+{
+ if (cvCapture && cvCapture->isOpened())
+ {
+ cvCapture->release();
+ }
+
+ if (cvWriter && cvWriter->isOpened())
+ {
+ cvWriter->release();
+ }
+}
+
+bool VideoUtils::openVideoWriter()
+{
+ if (!cvCapture || !cvCapture->isOpened() || !cvWriter)
+ {
+ return false;
+ }
+
+ /* Get the size of a frame from the device. */
+ cv::Size framesize = cv::Size((int) cvCapture->get(cv::CAP_PROP_FRAME_WIDTH), (int) cvCapture->get(cv::CAP_PROP_FRAME_HEIGHT));
+
+ /* Get the CODEC. */
+ if (codec.empty() || codec.size() != 4)
+ {
+ codec = "MJPG";
+ }
+ boost::algorithm::to_upper(codec);
+
+ return cvWriter->open(filename, cv::VideoWriter::fourcc(codec.at(0), codec.at(1), codec.at(2), codec.at(3)), fps, framesize);
+}
+
+void VideoUtils::writeVideoFrame(const cv::UMat& f)
+{
+ if (!cvWriter || !cvWriter->isOpened())
+ {
+ return;
+ }
+
+ if (framecount < fps)
+ {
+ framecount++;
+ return;
+ }
+
+ cv::Mat frame;
+ f.copyTo(frame);
+
+ /* Put the current time into the frame. */
+ int fontFace = cv::FONT_HERSHEY_SIMPLEX;
+ double fontScale = 0.6;
+ int baseline = 0;
+ int thickness = 2;
+ std::stringstream datestr;
+
+ datestr << getCurrentTime();
+
+ cv::Size dateTextSize = cv::getTextSize(datestr.str(), fontFace, fontScale, thickness, &baseline);
+
+ for (; fontScale > 0.1 && dateTextSize.width > frame.cols; )
+ {
+ fontScale -= 0.2;
+ dateTextSize = cv::getTextSize(datestr.str(), fontFace, fontScale, thickness, &baseline);
+ }
+
+ cv::Point dateOrg(frame.cols - dateTextSize.width, dateTextSize.height);
+
+ cv::putText(frame, datestr.str(), dateOrg, fontFace, fontScale, cv::Scalar(255, 255, 255), thickness);
+
+ /* Write the frame into the log file. */
+ *(cvWriter.get()) << frame;
+}
+
+std::string VideoUtils::getCurrentTime()
+{
+ time_t seconds;
+ struct tm currenttime;
+ if (time(&seconds) == (time_t) - 1)
+ {
+ return "";
+ }
+ localtime_r(&seconds, &currenttime);
+
+ char timestr[] = "1900/01/01/00/00/00";
+
+ sprintf(timestr, "%04d/%02d/%02d %02d:%02d:%02d", currenttime.tm_year + 1900, currenttime.tm_mon + 1, currenttime.tm_mday, currenttime.tm_hour, currenttime.tm_min, currenttime.tm_sec);
+
+ return timestr;
+}
+
+static int grabImage(void *data)
+{
+ VideoUtils* utils = reinterpret_cast<VideoUtils*>(data);
+
+ if (!utils->cvCapture || !utils->cvCapture->isOpened())
+ {
+ return false;
+ }
+
+ cv::UMat frame;
+ *(utils->cvCapture.get()) >> frame;
+
+ if (!frame.empty())
+ {
+ /* Write the frame into the log file. */
+ utils->writeVideoFrame(frame);
+ return true;
+ }
+ else
+ {
+ return false;
+ }
+}
+
+static void printhelp(const char *argv0)
+{
+ printf("Usage: %s [args]\n"
+ " [-d|--device <0-5> ] set the device\n"
+ " [-w|--width] specify the width\n"
+ " [-h|--height] specify the height\n"
+ " [-r]--frame rate] specify the frame rate\n"
+ " [-c]--codec] specify the codec\n"
+ " [-f]--folder name] specify a folder to save the video file\n", argv0);
+}
+
+static void mainLoopQuit(int sig)
+{
+ if ((sig == SIGUSR1) && (mainloop != NULL))
+ {
+ g_main_loop_quit(mainloop);
+ }
+}
+
+int main(int argc, char **argv)
+{
+ static int opt;
+ int device = 0;
+ int framerate = 30;
+ int width = 640;
+ int height = 480;
+ std::string filename = "/tmp/temp.avi";
+ std::string codec = "MP42";
+
+ while ((opt = getopt(argc, argv, "d:w:h:r:f:c:")) != -1)
+ {
+ switch (opt)
+ {
+ case 'd':
+ device = atoi(optarg);
+ break;
+ case 'w':
+ width = atoi(optarg);
+ break;
+ case 'h':
+ height = atoi(optarg);
+ break;
+ case 'r':
+ framerate = atoi(optarg);
+ break;
+ case 'f':
+ filename.assign(optarg);
+ break;
+ case 'c':
+ codec.assign(optarg);
+ break;
+ default:
+ printhelp(basename(argv[0]));
+ return (0);
+ }
+ }
+
+ VideoUtils utils(device, framerate, width, height, filename, codec);
+
+ if (utils.isReady && framerate > 0)
+ {
+ void (*oldSigUsr1Handler)(int);
+
+ oldSigUsr1Handler = signal(SIGUSR1, mainLoopQuit);
+
+ mainloop = g_main_loop_new(NULL, FALSE);
+
+ g_timeout_add(1000 / framerate, grabImage, &utils);
+
+ g_main_loop_run(mainloop);
+ g_main_loop_unref(mainloop);
+
+ if (oldSigUsr1Handler != SIG_ERR)
+ {
+ signal(SIGUSR1, oldSigUsr1Handler);
+ }
+ }
+
+ utils.releaseSource();
+
+ return 0;
+} \ No newline at end of file
diff --git a/videoutils/videoutils.h b/videoutils/videoutils.h
new file mode 100644
index 0000000..b0aa161
--- /dev/null
+++ b/videoutils/videoutils.h
@@ -0,0 +1,58 @@
+/*
+ Copyright (C) 2017 TOYOTA TSUSHO Corporation
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ This library 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
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this library; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef VIDEOUTILS_H
+#define VIDEOUTILS_H
+
+#include <memory>
+#include <string>
+#include <opencv2/videoio.hpp>
+
+namespace VIDEO_UTILS
+{
+class VideoUtils
+{
+public:
+ VideoUtils(int device, int framerate, int wid, int hght, std::string file, std::string co);
+ ~VideoUtils()
+ {
+ }
+ void writeVideoFrame(const cv::UMat& f);
+ void releaseSource();
+
+private:
+ std::string getCurrentTime();
+ bool openVideoWriter();
+
+public:
+ bool isReady;
+ std::unique_ptr<cv::VideoCapture> cvCapture;
+
+private:
+ int fps;
+ int width;
+ int height;
+ int deviceno;
+ int framecount;
+ std::string codec;
+ std::string filename;
+ std::unique_ptr<cv::VideoWriter> cvWriter;
+};
+}
+
+#endif // VIDEOUTILS_H