我想解码从UDP接收到的vp8帧数据。那么,我如何在libvpx.so中调用函数呢?
我下载了libvpx v1.8.1。包和我编译了libvpx以获得libvpx.so。我的电脑是:
Linux ubuntu 4.18.0-25-通用#26~18.04.1-Ubuntu SMP
我的libvpx.so配置是:
./配置-log=yes-target=x86_64-linux-启用-pic-启用-ccache-启用-调试-启用-安装-docs-启用-单元测试-启用-解码-perf-测试-启用-编码-perf-允许-更好-兼容性-启用-更好-兼容-启用-vp9启用-内部状态-启用-内部状态-启用-encoding --启用-webm-io-启用-libyuv
我写了一个c文件来做上面的事情。我的源文件是:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include "vpx/vpx_decoder.h"
#include "vpx/vp8dx.h"
#define DEBUGPRINT
#ifdef DEBUGPRINT
#define DPRINT(format, arg...) printf(format, ##arg)
#else
#define DPRINT(format, arg...) do{}while(0)
#endif
#define UDP_SERV_PORT (12345)
#define UDP_RECV_DATA_MAXLEN (65535)
#define IVF_HEADER_SIZE (12)
int main(int argc, char **argv)
{
int sockfd;
struct sockaddr_in servaddr, cliaddr;
sockfd = socket(PF_INET, SOCK_DGRAM, 0);
if(sockfd < 0) {
perror("socket create failed!");
exit(0);
}
bzero(&servaddr, sizeof(servaddr));
servaddr.sin_family = AF_INET;
servaddr.sin_addr.s_addr = htonl(INADDR_ANY);
servaddr.sin_port = htons(UDP_SERV_PORT);
if( bind(sockfd, (struct sockaddr *)&servaddr, sizeof(servaddr)) ) {
perror("bind failed!");
exit(0);
}
char recvdata[UDP_RECV_DATA_MAXLEN];
int rdatalen = 0, clilen = 0;
vpx_codec_ctx_t decoder;
vpx_codec_dec_cfg_t* dec_cfg = NULL;
vpx_codec_flags_t dec_flags = 0;
vpx_codec_dec_init(&decoder, &vpx_codec_vp8_dx_algo, dec_cfg, dec_flags);
while(1) {
memset(recvdata, 0, UDP_RECV_DATA_MAXLEN);
rdatalen = recvfrom(sockfd, recvdata, UDP_RECV_DATA_MAXLEN, 0, (struct sockaddr *)&cliaddr, &clilen);
DPRINT(" recv %d data from %s:%d\n", rdatalen, inet_ntoa(cliaddr.sin_addr), ntohs(cliaddr.sin_port));
vpx_codec_iter_t iter = NULL;
vpx_image_t* img;
int frame_size = 0;
frame_size += (int) ((recvdata[0]));
frame_size += (int) ((recvdata[1]) << 8);
frame_size += (int) ((recvdata[2]) << 16);
frame_size += (int) ((recvdata[3]) << 24);
vpx_codec_decode(&decoder, &recvdata[IVF_HEADER_SIZE], frame_size, NULL, 0);
img = vpx_codec_get_frame(&decoder, &iter);
DPRINT(" img: d_w=%d d_h=%d\n", img->d_w, img->d_h);
}
return 0;
// close(sockfd);
}我将包中的libvpx.so文件和vpx/*源代码与源代码放在相同的路径上。我用gcc编写了这样的文件:
gcc -Wall -L.-lvpx udpframedecoder.c解码器c -o main
但我得到了这个
udpframedecoder.c: In function ‘main’:
udpframedecoder.c:66:101: warning: pointer targets in passing argument 6 of ‘recvfrom’ differ in signedness [-Wpointer-sign]
rdatalen = recvfrom(sockfd, recvdata, UDP_RECV_DATA_MAXLEN, 0, (struct sockaddr *)&cliaddr, &clilen);
^
In file included from udpframedecoder.c:5:0:
/usr/include/x86_64-linux-gnu/sys/socket.h:163:16: note: expected ‘socklen_t * restrict {aka unsigned int * restrict}’ but argument is of type ‘int *’
extern ssize_t recvfrom (int __fd, void *__restrict __buf, size_t __n,
^~~~~~~~
udpframedecoder.c:76:36: warning: pointer targets in passing argument 2 of ‘vpx_codec_decode’ differ in signedness [-Wpointer-sign]
vpx_codec_decode(&decoder, &recvdata[IVF_HEADER_SIZE], frame_size, NULL, 0);
^
In file included from udpframedecoder.c:9:0:
vpx/vpx_decoder.h:215:17: note: expected ‘const uint8_t * {aka const unsigned char *}’ but argument is of type ‘char *’
vpx_codec_err_t vpx_codec_decode(vpx_codec_ctx_t *ctx, const uint8_t *data,
^~~~~~~~~~~~~~~~
/tmp/ccHVjYj5.o: In function `vpx_codec_control_VP8_SET_REFERENCE':
udpframedecoder.c:(.text+0x29): undefined reference to `vpx_codec_control_'
/tmp/ccHVjYj5.o: In function `vpx_codec_control_VP8_COPY_REFERENCE':
udpframedecoder.c:(.text+0x58): undefined reference to `vpx_codec_control_'
/tmp/ccHVjYj5.o: In function `vpx_codec_control_VP8_SET_POSTPROC':
udpframedecoder.c:(.text+0x87): undefined reference to `vpx_codec_control_'
/tmp/ccHVjYj5.o: In function `vpx_codec_control_VP9_GET_REFERENCE':
udpframedecoder.c:(.text+0xb6): undefined reference to `vpx_codec_control_'
/tmp/ccHVjYj5.o: In function `vpx_codec_control_VP8D_GET_LAST_REF_UPDATES':
udpframedecoder.c:(.text+0xe5): undefined reference to `vpx_codec_control_'
/tmp/ccHVjYj5.o:udpframedecoder.c:(.text+0x114): more undefined references to `vpx_codec_control_' follow
/tmp/ccHVjYj5.o: In function `main':
udpframedecoder.c:(.text+0x461): undefined reference to `vpx_codec_vp8_dx_algo'
udpframedecoder.c:(.text+0x469): undefined reference to `vpx_codec_dec_init_ver'
udpframedecoder.c:(.text+0x582): undefined reference to `vpx_codec_decode'
udpframedecoder.c:(.text+0x59b): undefined reference to `vpx_codec_get_frame'
collect2: error: ld returned 1 exit status"vpx_codec_control_“包含在"vpx/vpx_codec.h”中。“vpx/vpx_decder.h”包括"vpx/vpx_codec.h“。似乎我没有很好地链接.so文件。但我不知道哪里出了问题。有人能帮我吗?
发布于 2019-08-29 11:23:17
我已经找到了原因。我应该像这样编译这个文件:
gcc udpframedecoder.c -o main -Wall -L. -lvpx 这可以解决这个问题。
https://stackoverflow.com/questions/57322425
复制相似问题