This commit is contained in:
acgist
2023-03-18 22:59:54 +08:00
parent f8c458295d
commit dcdf4c0217
24 changed files with 544 additions and 27 deletions

10
taoyao-client-harmony/taoyao/.gitignore vendored Normal file
View File

@@ -0,0 +1,10 @@
CMakeCache.txt
**/*.so
**/*.exe
**/*.lib
.vscode/**
build/**
openharmony/**

View File

@@ -0,0 +1,4 @@
[submodule "googletest"]
path = test/lib/googletest
url = https://github.com/google/googletest.git
branch = master

View 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})

View File

@@ -0,0 +1 @@
# 桃夭鸿蒙终端

View File

@@ -0,0 +1,8 @@
#pragma once
/**
* 音频推送器
*/
namespace acgist {
}

View File

@@ -0,0 +1,8 @@
#pragma once
/**
* 媒体终端
*/
namespace acgist {
}

View File

@@ -0,0 +1,8 @@
#pragma once
/**
* 媒体录制
*/
namespace acgist {
}

View 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();
};
}

View File

@@ -0,0 +1,8 @@
#pragma once
/**
* 视频推送器
*/
namespace acgist {
}

View File

@@ -0,0 +1 @@
#pragma once

View 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;
}

View File

@@ -0,0 +1,5 @@
#include "../../include/AudioPublisher.hpp"
namespace acgist {
}

View File

@@ -0,0 +1,5 @@
#include "../../include/MediaClient.hpp"
namespace acgist {
}

View File

@@ -0,0 +1,5 @@
#include "../../include/MediaRecorder.hpp"
namespace acgist {
}

View File

@@ -0,0 +1,5 @@
#include "../../include/VideoPublisher.hpp"
namespace acgist {
}

View 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;
}