RISC-V平台编译 state-thread x264 ffmpeg zlog
1.state-threads
源码下来之后
直接 make linux-debug
目录下生成了对应的.a 和 .h文件
gcc test.c -o test -l st -L .
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <st.h>
#define BACKLOG 5
#define IOBUFSIZE 8192
#define PORT 7474
static void *handle_request(void *arg)
{
st_netfd_t cli_nfd = (st_netfd_t) arg;
struct pollfd pd;
pd.fd = st_netfd_fileno(cli_nfd);
pd.events = POLLIN;
char buf[IOBUFSIZE];
int nw, nr;
for ( ; ; ) {
/*pd.revents = 0;
if (st_poll(&pd, 1, ST_UTIME_NO_TIMEOUT) <= 0) {
printf("st_poll<=0\n");
break;
}*/
//if (pd.revents & POLLIN) {
nr = (int) st_read(cli_nfd, buf, IOBUFSIZE, ST_UTIME_NO_TIMEOUT);
if (nr <= 0)break;
printf("[recv][%d] %s\n",nr,buf);
nw = st_write(cli_nfd, buf, nr, ST_UTIME_NO_TIMEOUT);
printf("[write] %d\n",nw);
if (nw == nr)break;
//}
}
done:
st_netfd_close(cli_nfd);
return NULL;
}
int main() {
int sock, client_fd;
struct sockaddr_in address;
struct sockaddr_in cli_addr;
socklen_t addrlen = sizeof(address);
st_netfd_t cli_nfd, srv_nfd;
int n =0;
// 初始化StateThreads库
if (st_init() != 0) {
perror("st_init");
return 0;
}
if ((sock = socket(PF_INET, SOCK_STREAM, 0)) < 0) {
printf("socket");
exit(1);
}
n = 1;
if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (char *)&n, sizeof(n)) < 0) {
printf("setsockopt");
exit(1);
}
// 绑定socket到端口
address.sin_family = AF_INET;
address.sin_addr.s_addr = INADDR_ANY;
address.sin_port = htons(PORT);
if (bind(sock, (struct sockaddr *)&address, sizeof(address)) < 0) {
printf("bind");
exit(1);
}
listen(sock, 128);
if ((srv_nfd = st_netfd_open_socket(sock)) == NULL) {
printf("st_netfd_open");
exit(1);
}
printf("tcp srv start\n");
for ( ; ; ) {
n = sizeof(cli_addr);
cli_nfd = st_accept(srv_nfd, (struct sockaddr *)&cli_addr, &n,ST_UTIME_NO_TIMEOUT);
if (cli_nfd == NULL) {
printf("st_accept\n");
continue;
}
if (st_thread_create(handle_request, cli_nfd, 0, 0) == NULL) {
printf("st_thread_create\n");
continue;
}
}
close(sock);
st_netfd_close(srv_nfd);
return 0;
}
用网络助手测试下正常
2.x264
默认的官网的不支持risc-v平台 去下面链接下载支持此架构的
Jiayan Qian / x264-riscv-dev · GitLab (videolan.org)
./configure \
--prefix=./ubuntu \
--enable-static \
--enable-shared \
如上图所示生成了对应的.a文件 和头文件
3.ffmpeg
执行 脚本
打了一大串信息