gpt4 book ai didi

ios - 如何使用 libRTMP.a 将 AMFObject 发送到服务器

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:16:17 30 4
gpt4 key购买 nike

我正在尝试使用 RTMP 开发聊天功能,所以我得到并编译了 libRTMP。

如何向服务器发送 NSDictionary

我使用了AMFObject,但是Xcode编译的时候出现了错误。

    RTMPPacket packet;
char pbuf[1024];
char *pend = pbuf + sizeof(pbuf);
char *enc;
//块流ID为4
packet.m_nChannel = 0x04; /* source channel (invoke) */
packet.m_headerType = RTMP_PACKET_SIZE_LARGE;
packet.m_packetType = RTMP_PACKET_TYPE_INVOKE; /* INVOKE */
packet.m_nTimeStamp = (uint32_t)[[NSDate date] timeIntervalSince1970];
//流ID
packet.m_nInfoField2 = sendRtmp->m_stream_id;
packet.m_hasAbsTimestamp = 0;
packet.m_body = pbuf + RTMP_MAX_HEADER_SIZE;
//指向Chunk的负载
enc = packet.m_body;

/*组装方法*/
AVal methodName;
NSString *methodNameString = @"login1";
methodName.av_val = (char*)[methodNameString UTF8String];
methodName.av_len = (int)[[methodNameString dataUsingEncoding:NSUTF8StringEncoding] length];
//对“publish”字符串进行AMF编码
enc = AMF_EncodeString(enc, pend, &methodName);
enc = AMF_EncodeNumber(enc, pend, ++sendRtmp->m_numInvokes);
*enc++ = AMF_NULL;

struct AMFObject *object = (struct AMFObject *)malloc(sizeof(struct AMFObject));
struct AMFObjectProperty *property = (struct AMFObjectProperty *)malloc(sizeof(struct AMFObjectProperty));
/*key*/
AVal key;
NSString *keyString = @"name";
key.av_val = (char*)[keyString UTF8String];
key.av_len = (int)[[keyString dataUsingEncoding:NSUTF8StringEncoding] length];

/*value*/
AVal value;
NSString *valueString = @"liubo";
value.av_val = (char*)[valueString UTF8String];
value.av_len = (int)[[valueString dataUsingEncoding:NSUTF8StringEncoding] length];
AMFProp_SetName(property, &key);
AMFProp_SetString(property, &value);
AMF_AddProp(object, property);
AMF_Encode(object, enc, pend);
enc = AMF_EncodeNumber(enc, pend, ++sendRtmp->m_numInvokes);
*enc++ = AMF_NULL;

free(object);
free(property);

if (!enc)
return;

packet.m_nBodySize = enc - packet.m_body;

int code = RTMP_SendPacket(sendRtmp, &packet, TRUE);
NSLog(@"发送消息完毕:%@ 返回值:%d",message,code);

Xcode编译时出现错误:

enter image description here

最佳答案

我在 iOS 上发现了与 AMFProp_SetString 相同的错误。我以这种方式添加属性:

AMFObject object;
object.o_props = malloc(sizeof(AMFObjectProperty *)); // Needs a malloc for AMF_AddProp

AMFObjectProperty prop;

AVal name = AVC("test");
AVal nothing = AVC("");

prop.p_type = AMF_STRING;
prop.p_vu.p_aval = name;
prop.p_name = nothing;

object.o_num = 0;

AMF_AddProp(&object, &prop);

希望对您有所帮助。

关于ios - 如何使用 libRTMP.a 将 AMFObject 发送到服务器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29693711/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com