[+] c++
This commit is contained in:
10
taoyao-client-harmony/taoyao/.gitignore
vendored
Normal file
10
taoyao-client-harmony/taoyao/.gitignore
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
CMakeCache.txt
|
||||
|
||||
**/*.so
|
||||
**/*.exe
|
||||
**/*.lib
|
||||
|
||||
.vscode/**
|
||||
|
||||
build/**
|
||||
openharmony/**
|
||||
4
taoyao-client-harmony/taoyao/.gitmodules
vendored
Normal file
4
taoyao-client-harmony/taoyao/.gitmodules
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
[submodule "googletest"]
|
||||
path = test/lib/googletest
|
||||
url = https://github.com/google/googletest.git
|
||||
branch = master
|
||||
84
taoyao-client-harmony/taoyao/CMakeLists.txt
Normal file
84
taoyao-client-harmony/taoyao/CMakeLists.txt
Normal file
@@ -0,0 +1,84 @@
|
||||
cmake_minimum_required(VERSION 3.2)
|
||||
|
||||
#define CMAKE_TEMPLATE_VERSION_MAJOR @CMakeTemplate_VERSION_MAJOR@
|
||||
#define CMAKE_TEMPLATE_VERSION_MINOR @CMakeTemplate_VERSION_MINOR@
|
||||
#define CMAKE_TEMPLATE_VERSION_PATCH @CMakeTemplate_VERSION_PATCH@
|
||||
project(taoyao-client-camera VERSION 1.0.0 LANGUAGES C CXX)
|
||||
|
||||
# Debug | Release
|
||||
# DCMAKE_BUILD_TYPE=Debug
|
||||
set(CMAKE_BUILD_TYPE Debug)
|
||||
|
||||
# set(CMAKE_C_COMPILER gcc)
|
||||
# set(CMAKE_CXX_COMPILER g++)
|
||||
|
||||
# 全局宏定义
|
||||
# add_definitions(-DDEBUG)
|
||||
|
||||
# 全局编译选项
|
||||
# add_compile_options()
|
||||
|
||||
# C编译选项
|
||||
set(CMAKE_C_STANDARD 11)
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c11 -O3")
|
||||
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -g -O0")
|
||||
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -O3")
|
||||
|
||||
# C++编译选项
|
||||
set(CMAKE_CXX_STANDARD 11)
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -O3")
|
||||
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -g -O0")
|
||||
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O3")
|
||||
|
||||
# 输出目录
|
||||
set(PROJECT_BINARY_DIR ${PROJECT_SOURCE_DIR}/build)
|
||||
|
||||
# 包含源代码
|
||||
# add_subdirectory(src)
|
||||
# add_subdirectory(test)
|
||||
|
||||
file(
|
||||
GLOB SOURCE_FILE
|
||||
"include/*.h"
|
||||
"include/*.hpp"
|
||||
"src/main.cpp"
|
||||
"src/media/*.c"
|
||||
"src/signal/*.c"
|
||||
"src/media/*.cpp"
|
||||
"src/signal/*.cpp"
|
||||
)
|
||||
|
||||
# -lpthread
|
||||
|
||||
add_executable(${PROJECT_NAME} ${SOURCE_FILE})
|
||||
|
||||
# message("源码地址:" ${SOURCE_FILE})
|
||||
|
||||
# 配置
|
||||
# cmake -B build
|
||||
# Windows:-G "Unix Makefiles"
|
||||
# 安装位置:-DCMAKE_INSTALL_PREFIX=`pwd`/output | --install --prefix <install-path>
|
||||
# 打包位置:-DCPACK_OUTPUT_FILE_PREFIX=`pwd`/output
|
||||
|
||||
# 编译
|
||||
# cmake --build build
|
||||
|
||||
# 安装
|
||||
# cd build && make install && cd -
|
||||
|
||||
# install(
|
||||
# TARGETS taoyao
|
||||
# RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/bin
|
||||
# LIBRARY DESTINATION ${CMAKE_INSTALL_PREFIX}/lib
|
||||
# ARCHIVE DESTINATION ${CMAKE_INSTALL_PREFIX}/lib
|
||||
# )
|
||||
|
||||
# 打包
|
||||
# cd build && cpack && cd -
|
||||
|
||||
# include(CPack)
|
||||
# set(CPACK_GENERATOR "ZIP")
|
||||
# set(CPACK_SET_DESTDIR ON)
|
||||
# set(CPACK_INSTALL_PREFIX "")
|
||||
# set(CPACK_PACKAGE_NAME "taoyao")
|
||||
# set(CPACK_PACKAGE_VERSION ${PROJECT_VERSION})
|
||||
1
taoyao-client-harmony/taoyao/README.md
Normal file
1
taoyao-client-harmony/taoyao/README.md
Normal file
@@ -0,0 +1 @@
|
||||
# 桃夭鸿蒙终端
|
||||
8
taoyao-client-harmony/taoyao/include/AudioPublisher.hpp
Normal file
8
taoyao-client-harmony/taoyao/include/AudioPublisher.hpp
Normal file
@@ -0,0 +1,8 @@
|
||||
#pragma once
|
||||
|
||||
/**
|
||||
* 音频推送器
|
||||
*/
|
||||
namespace acgist {
|
||||
|
||||
}
|
||||
8
taoyao-client-harmony/taoyao/include/MediaClient.hpp
Normal file
8
taoyao-client-harmony/taoyao/include/MediaClient.hpp
Normal file
@@ -0,0 +1,8 @@
|
||||
#pragma once
|
||||
|
||||
/**
|
||||
* 媒体终端
|
||||
*/
|
||||
namespace acgist {
|
||||
|
||||
}
|
||||
8
taoyao-client-harmony/taoyao/include/MediaRecorder.hpp
Normal file
8
taoyao-client-harmony/taoyao/include/MediaRecorder.hpp
Normal file
@@ -0,0 +1,8 @@
|
||||
#pragma once
|
||||
|
||||
/**
|
||||
* 媒体录制
|
||||
*/
|
||||
namespace acgist {
|
||||
|
||||
}
|
||||
72
taoyao-client-harmony/taoyao/include/Taoyao.hpp
Normal file
72
taoyao-client-harmony/taoyao/include/Taoyao.hpp
Normal file
@@ -0,0 +1,72 @@
|
||||
#pragma once
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/shm.h>
|
||||
#include <sys/types.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
|
||||
#include <thread>
|
||||
#include <iostream>
|
||||
|
||||
#define BUFFER_SIZE 8092
|
||||
|
||||
namespace acgist {
|
||||
|
||||
/**
|
||||
* 信令
|
||||
*/
|
||||
class Taoyao {
|
||||
private:
|
||||
// 端口
|
||||
int port;
|
||||
// 地址
|
||||
std::string address;
|
||||
// 通道
|
||||
int socketChannel;
|
||||
// 接收线程
|
||||
std::thread acceptThread;
|
||||
// 超时
|
||||
struct timeval timeout;
|
||||
// 地址
|
||||
struct sockaddr_in serverAddress;
|
||||
public:
|
||||
/**
|
||||
* @param port 端口
|
||||
* @param address 地址
|
||||
* @param timeout 超时
|
||||
*/
|
||||
Taoyao(int port, std::string address, int timeout);
|
||||
/**
|
||||
*
|
||||
*/
|
||||
virtual ~Taoyao();
|
||||
private:
|
||||
/**
|
||||
* 接收消息
|
||||
*/
|
||||
void acceptSignal();
|
||||
public:
|
||||
/**
|
||||
* 连接信令
|
||||
*/
|
||||
void connectSignal();
|
||||
/**
|
||||
* 推送消息
|
||||
*/
|
||||
void push(std::string message);
|
||||
/**
|
||||
* 请求消息
|
||||
*/
|
||||
void request(std::string message);
|
||||
/**
|
||||
* 关闭信令
|
||||
*/
|
||||
void closeSignal();
|
||||
};
|
||||
|
||||
}
|
||||
8
taoyao-client-harmony/taoyao/include/VideoPublisher.hpp
Normal file
8
taoyao-client-harmony/taoyao/include/VideoPublisher.hpp
Normal file
@@ -0,0 +1,8 @@
|
||||
#pragma once
|
||||
|
||||
/**
|
||||
* 视频推送器
|
||||
*/
|
||||
namespace acgist {
|
||||
|
||||
}
|
||||
1
taoyao-client-harmony/taoyao/include/main.hpp
Normal file
1
taoyao-client-harmony/taoyao/include/main.hpp
Normal file
@@ -0,0 +1 @@
|
||||
#pragma once
|
||||
10
taoyao-client-harmony/taoyao/src/main.cpp
Normal file
10
taoyao-client-harmony/taoyao/src/main.cpp
Normal file
@@ -0,0 +1,10 @@
|
||||
#include <iostream>
|
||||
#include "../include/main.hpp"
|
||||
|
||||
using std::cout;
|
||||
using std::endl;
|
||||
|
||||
int main(const int argc, const char **argv) {
|
||||
cout << "测试" << endl;
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
#include "../../include/AudioPublisher.hpp"
|
||||
|
||||
namespace acgist {
|
||||
|
||||
}
|
||||
5
taoyao-client-harmony/taoyao/src/media/MediaClient.cpp
Normal file
5
taoyao-client-harmony/taoyao/src/media/MediaClient.cpp
Normal file
@@ -0,0 +1,5 @@
|
||||
#include "../../include/MediaClient.hpp"
|
||||
|
||||
namespace acgist {
|
||||
|
||||
}
|
||||
5
taoyao-client-harmony/taoyao/src/media/MediaRecorder.cpp
Normal file
5
taoyao-client-harmony/taoyao/src/media/MediaRecorder.cpp
Normal file
@@ -0,0 +1,5 @@
|
||||
#include "../../include/MediaRecorder.hpp"
|
||||
|
||||
namespace acgist {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
#include "../../include/VideoPublisher.hpp"
|
||||
|
||||
namespace acgist {
|
||||
|
||||
}
|
||||
84
taoyao-client-harmony/taoyao/src/signal/Taoyao.cpp
Normal file
84
taoyao-client-harmony/taoyao/src/signal/Taoyao.cpp
Normal file
@@ -0,0 +1,84 @@
|
||||
#include "../../include/Taoyao.hpp"
|
||||
|
||||
namespace acgist {
|
||||
|
||||
Taoyao::Taoyao(int port, std::string address, int timeout = 5) {
|
||||
this->port = port;
|
||||
this->address = address;
|
||||
this->socketChannel = 0;
|
||||
this->timeout = {timeout, 0};
|
||||
memset(&this->serverAddress, 0, sizeof(this->serverAddress));
|
||||
this->serverAddress.sin_family = AF_INET;
|
||||
this->serverAddress.sin_port = htons(this->port);
|
||||
this->serverAddress.sin_addr.s_addr = inet_addr(this->address.c_str());
|
||||
// 接收线程
|
||||
this->acceptThread = std::thread(&acgist::Taoyao::acceptSignal, this);
|
||||
}
|
||||
|
||||
Taoyao::~Taoyao() {
|
||||
}
|
||||
|
||||
void Taoyao::acceptSignal() {
|
||||
int status;
|
||||
char recvbuf[BUFFER_SIZE];
|
||||
while(true) {
|
||||
if(this->socketChannel == 0) {
|
||||
this->connectSignal();
|
||||
continue;
|
||||
}
|
||||
/**
|
||||
* 0 - 服务断开
|
||||
* -1 - 网络故障:如果设置超时也会出现
|
||||
*/
|
||||
status = recv(this->socketChannel, recvbuf, sizeof(recvbuf), 0);
|
||||
if(status == 0) {
|
||||
this->connectSignal();
|
||||
continue;
|
||||
}
|
||||
std::cout << "接收消息:" << status << " - " << recvbuf << std::endl;
|
||||
memset(recvbuf, 0, sizeof(recvbuf));
|
||||
}
|
||||
}
|
||||
|
||||
void Taoyao::connectSignal() {
|
||||
this->closeSignal();
|
||||
this->socketChannel = socket(AF_INET, SOCK_STREAM, 0);
|
||||
setsockopt(this->socketChannel, SOL_SOCKET, SO_SNDTIMEO, &this->timeout, sizeof(this->timeout));
|
||||
setsockopt(this->socketChannel, SOL_SOCKET, SO_RCVTIMEO, &this->timeout, sizeof(this->timeout));
|
||||
if (connect(this->socketChannel, (struct sockaddr *) &this->serverAddress, sizeof(this->serverAddress)) < 0) {
|
||||
std::cout << "连接失败:重试" << std::endl;
|
||||
this->connectSignal();
|
||||
return;
|
||||
}
|
||||
std::cout << "连接成功:" << this->address << ":" << this->port << std::endl;
|
||||
}
|
||||
|
||||
void Taoyao::push(std::string message) {
|
||||
std::cout << "发送消息:" << message << std::endl;
|
||||
char sendbuf[message.length() + 1];
|
||||
strncpy(sendbuf, message.c_str(), message.length() + 1);
|
||||
send(this->socketChannel, sendbuf, sizeof(sendbuf), 0);
|
||||
memset(sendbuf, 0, sizeof(sendbuf));
|
||||
}
|
||||
|
||||
void Taoyao::request(std::string message) {
|
||||
}
|
||||
|
||||
void Taoyao::closeSignal() {
|
||||
if(this->socketChannel != 0) {
|
||||
close(this->socketChannel);
|
||||
this->socketChannel = 0;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
int main(int argc, char const *argv[]) {
|
||||
acgist::Taoyao taoyao(9999, "192.168.1.100");
|
||||
taoyao.connectSignal();
|
||||
char sendbuf[BUFFER_SIZE];
|
||||
while (fgets(sendbuf, sizeof(sendbuf), stdin) != NULL) {
|
||||
taoyao.push(sendbuf);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user