LaiFengiOS / LFLiveKit

LaiFeng IOS Live Kit,H264 and AAC Hard coding,support GPUImage Beauty, rtmp transmission,weak network lost frame,Dynamic switching rate
MIT License
4.39k stars 1.11k forks source link

How to setup Socks proxy? #193

Open bucky0970 opened 7 years ago

bucky0970 commented 7 years ago

I saw rtmp.c has options for socks, but I do not know where to enable this option?

static struct urlopt {
    AVal name;
    off_t off;
    int otype;
    int omisc;
    char *use;
} options[] = {
    {AVC("socks"), OFF(Link.sockshost), OPT_STR, 0,
     "Use the specified SOCKS proxy"},
    {AVC("app"), OFF(Link.app), OPT_STR, 0,
     "Name of target app on server"},
    {AVC("tcUrl"), OFF(Link.tcUrl), OPT_STR, 0,
     "URL to played stream"},
    {AVC("pageUrl"), OFF(Link.pageUrl), OPT_STR, 0,
     "URL of played media's web page"},
    {AVC("swfUrl"), OFF(Link.swfUrl), OPT_STR, 0,
     "URL to player SWF file"},
    {AVC("flashver"), OFF(Link.flashVer), OPT_STR, 0,
     "Flash version string (default " DEF_VERSTR ")"},
    {AVC("conn"), OFF(Link.extras), OPT_CONN, 0,
     "Append arbitrary AMF data to Connect message"},
    {AVC("playpath"), OFF(Link.playpath), OPT_STR, 0,
     "Path to target media on server"},
    {AVC("playlist"), OFF(Link.lFlags), OPT_BOOL, RTMP_LF_PLST,
     "Set playlist before play command"},
    {AVC("live"), OFF(Link.lFlags), OPT_BOOL, RTMP_LF_LIVE,
     "Stream is live, no seeking possible"},
    {AVC("subscribe"), OFF(Link.subscribepath), OPT_STR, 0,
     "Stream to subscribe to"},
    {AVC("token"), OFF(Link.token), OPT_STR, 0,
     "Key for SecureToken response"},
    {AVC("swfVfy"), OFF(Link.lFlags), OPT_BOOL, RTMP_LF_SWFV,
     "Perform SWF Verification"},
    {AVC("swfAge"), OFF(Link.swfAge), OPT_INT, 0,
     "Number of days to use cached SWF hash"},
    {AVC("start"), OFF(Link.seekTime), OPT_INT, 0,
     "Stream start position in milliseconds"},
    {AVC("stop"), OFF(Link.stopTime), OPT_INT, 0,
     "Stream stop position in milliseconds"},
    {AVC("buffer"), OFF(m_nBufferMS), OPT_INT, 0,
     "Buffer time in milliseconds"},
    {AVC("timeout"), OFF(Link.timeout), OPT_INT, 0,
     "Session timeout in seconds"},
    {{NULL, 0}, 0, 0}};
bucky0970 commented 7 years ago

I found here can do setting. in LFStreamRtmpSocket.m at Top static const AVal av_sockhost = AVC("127.0.0.1"); and modify this method,add Link.sockshost and Link.socksport.

- (NSInteger)RTMP264_Connect:(char *)push_url {
    //由于摄像头的timestamp是一直在累加,需要每次得到相对时间戳
    //分配与初始化
    _rtmp = PILI_RTMP_Alloc();
    PILI_RTMP_Init(_rtmp);

    //设置URL
    if (PILI_RTMP_SetupURL(_rtmp, push_url, &_error) == FALSE) {
        //log(LOG_ERR, "RTMP_SetupURL() failed!");
        goto Failed;
    }

    _rtmp->m_errorCallback = RTMPErrorCallback;
    _rtmp->m_connCallback = ConnectionTimeCallback;
    _rtmp->m_userData = (__bridge void *)self;
    _rtmp->m_msgCounter = 1;
    _rtmp->Link.timeout = RTMP_RECEIVE_TIMEOUT;
    _rtmp->Link.sockshost = av_sockhost;
    _rtmp->Link.socksport = 60111;

    //设置可写,即发布流,这个函数必须在连接前使用,否则无效
    PILI_RTMP_EnableWrite(_rtmp);

    //连接服务器
    if (PILI_RTMP_Connect(_rtmp, NULL, &_error) == FALSE) {
        goto Failed;
    }

    //连接流
    if (PILI_RTMP_ConnectStream(_rtmp, 0, &_error) == FALSE) {
        goto Failed;
    }

    if (self.delegate && [self.delegate respondsToSelector:@selector(socketStatus:status:)]) {
        [self.delegate socketStatus:self status:LFLiveStart];
    }

    [self sendMetaData];

    _isConnected = YES;
    _isConnecting = NO;
    _isReconnecting = NO;
    _isSending = NO;
    return 0;

Failed:
    PILI_RTMP_Close(_rtmp, &_error);
    PILI_RTMP_Free(_rtmp);
    _rtmp = NULL;
    [self reconnect];
    return -1;
}

After run the code, it seems to be setting make different. But it shows

ERROR: PILI_RTMP_Connect0, SOCKS negotiation failed.
liveStateDidChange: 1
ERROR: PILI_RTMP_Connect0, SOCKS negotiation failed.
liveStateDidChange: 5
ERROR: PILI_RTMP_Connect0, SOCKS negotiation failed.
liveStateDidChange: 5

I will keep trying,If anyone can help me with this,it would be great...