我有一个使用GCDAsyncSocket作为网络接口库可可的直播视频节目。 还有播放视频帧时明显低迷。 例如,在视频时间的推移几乎两倍慢是正常的。 通过检查的表现,我发现GCDAsyncSocket的readDataToLength方法被称为太稀疏。 下面是日志,时间戳:
2012-05-16 11:18:27.054 DVRLibDemo[1181:903] readDataToLength
2012-05-16 11:18:27.256 DVRLibDemo[1181:903] readDataToLength
2012-05-16 11:18:27.285 DVRLibDemo[1181:903] readDataToLength
2012-05-16 11:18:27.452 DVRLibDemo[1181:903] readDataToLength
2012-05-16 11:18:27.475 DVRLibDemo[1181:903] readDataToLength
2012-05-16 11:18:27.697 DVRLibDemo[1181:903] readDataToLength
2012-05-16 11:18:27.726 DVRLibDemo[1181:903] readDataToLength
2012-05-16 11:18:27.856 DVRLibDemo[1181:903] readDataToLength
我创建套接字时设置了单独的委托调度队列,但它并没有太大的帮助。 该消息具有固定报头和我读出的首先则有效载荷。
- (void)socket:(GCDAsyncSocket *)sock didReadData:(NSData *)data withTag:(long)tag
{
DVRConnection *conn = [self getConnectionWithSocket:sock];
//DebugLogInfo(@"Receive raw data: %@ for connection: %d", data, conn.tag);
if (conn != nil && conn.connected)
{
if (tag == TAG_XM_MESSAGE_HEADER)
{
uint32_t bodyLen = [_parser parseMessageHeader:data];
[sock readDataToLength:bodyLen withTimeout:-1 tag:TAG_XM_MESSAGE_PAYLOAD];
}
else if (tag == TAG_XM_MESSAGE_PAYLOAD)
{
[_parser parseMessage:data forConnection:conn device:self];
[sock readDataToLength:XM_MESSAGE_HEADER_LENGTH withTimeout:-1 tag:TAG_XM_MESSAGE_HEADER];
}
}
}
没有人有任何想法,以提高从套接字读取数据的速度? 谢谢!