c语言中结构体在一子函数中赋值,却要在另一子函数中应用,如何实现,C语言在使用中遇到了一个结构体赋值失败的问题?...

我有一个A类:

定义了一个结构体

typedef struct

{

int sockfd;

on_av_frame_cb av_frame_cb;

on_av_frame_cb rtp_cb;

on_error_cb error_cb;

uint8_t *p_buf;

uint8_t *v_buf;

uint8_t *a_buf;

int rtp_flag;

}udp_client_t;

然后我再B类中调用:

static udp_client_t client;

int jldv_create_client(int src_port,int port ,const char *dst_ip){

udp_client_t *udpClient = &client;

assert(udpClient != NULL);

const char *c_ip = dst_ip;

memset(udpClient, 0, sizeof(udp_client_t));

int ret = create_client(src_port, port, c_ip, &udpClient);

if (ret != 0) {

goto err_output;

}

udpClient->av_frame_cb = (on_av_frame_cb )onVideoFrame;

udpClient->error_cb = on_error;

if (rtp_create(&udpClient) < 0) { ///问题所在之处

goto err_output;

}

printf("rtp_client:%d \n",udpClient->rtp_flag);

return 0;

err_output:

destroy_client(udpClient);

return -1;

}

在上述的问题所在之处中,我使用了C类的方法:

int rtp_create(udp_client_t **data)

{

logi("%s", __func__);

udp_client_t *udpClient = *data;

if(udpClient)

{

udpClient->rtp_flag = 1;

memset(&rtp_cxt, 0, sizeof(rtp_context_t));

int ret = init_server();

if (ret < 0)

{

return -1;

}

rtp_cxt.nalu = alloc_nalu(MAX_FRAME_SIZE);//为结构体nalu_t及其成员buf分配空间。返回值为指向nalu_t存储空间的指针

if (!rtp_cxt.nalu)

{

loge("alloc nalu failed");

return -2;

}

}

else

{

loge("%s: data is null", __func__);

return -3;

}

printf("udpClient after==>%d \n",udpClient->rtp_flag);

return 0;

}

然而打印的结果却是:

udpClient after==>1

rtp_client:0

这是为什么?

是我使用的不对吗?求解各位大神。。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值