GithubHelp home page GithubHelp logo

Comments (1)

LinChengChun avatar LinChengChun commented on May 24, 2024

经过添加log发现是由于连接异常断开,导致出现崩溃。更换网络环境后,没有出现奔溃,可能是连接断开情况下,上层依然往下层push数据导致堆栈溢出。
public class EasyRTMP implements Pusher {
private boolean isRTMPConnectNormal = false; // 用于标记连接是否正常

@OverRide
public synchronized void initPush(final String url, final Context context, final InitCallback callback, int fps) {
/*
*本Key为3个月临时授权License,如需商业使用,请邮件至[email protected]申请此产品的授权。
*/
Log.e(TAG, "startpush begin");
mPusherObj = init(url, RTMP_KEY, context, new OnInitPusherCallback() {
int code = Integer.MAX_VALUE;
@OverRide
public void onCallback(int code) {
if (code != this.code) {
this.code = code;
switch (code) {
case EasyRTMP.OnInitPusherCallback.CODE.EASY_ACTIVATE_INVALID_KEY:
// sendMessage("无效Key");
break;
case EasyRTMP.OnInitPusherCallback.CODE.EASY_ACTIVATE_SUCCESS:
// sendMessage("激活成功");
break;
case EasyRTMP.OnInitPusherCallback.CODE.EASY_RTMP_STATE_CONNECTING:
// sendMessage("连接中");
isRTMPConnectNormal = false; // 标记连接断开
break;
case EasyRTMP.OnInitPusherCallback.CODE.EASY_RTMP_STATE_CONNECTED:
// sendMessage("连接成功");
isRTMPConnectNormal = true; // 标记连接成功
break;
case EasyRTMP.OnInitPusherCallback.CODE.EASY_RTMP_STATE_CONNECT_FAILED:
// sendMessage("连接失败");
break;
case EasyRTMP.OnInitPusherCallback.CODE.EASY_RTMP_STATE_CONNECT_ABORT:
// sendMessage("连接异常中断");
isRTMPConnectNormal = false; // 标记连接断开
break;
case EasyRTMP.OnInitPusherCallback.CODE.EASY_RTMP_STATE_PUSHING:
// sendMessage("推流中");
isRTMPConnectNormal = true; // 标记连接成功
break;
case EasyRTMP.OnInitPusherCallback.CODE.EASY_RTMP_STATE_DISCONNECTED:
// sendMessage("断开连接");
isRTMPConnectNormal = false; // 标记连接断开
break;
case EasyRTMP.OnInitPusherCallback.CODE.EASY_ACTIVATE_PLATFORM_ERR:
// sendMessage("平台不匹配");
break;
case EasyRTMP.OnInitPusherCallback.CODE.EASY_ACTIVATE_COMPANY_ID_LEN_ERR:
// sendMessage("断授权使用商不匹配");
break;
case EasyRTMP.OnInitPusherCallback.CODE.EASY_ACTIVATE_PROCESS_NAME_LEN_ERR:
// sendMessage("进程名称长度不匹配");
break;
}
Log.e("cclin", "RTMP 当前连接状态:"+isRTMPConnectNormal);
if (callback != null) callback.onCallback(code);
}
}
},
fps);
Log.e(TAG, "startpush end");
}

public synchronized void push(byte[] data, int offset, int length, long timestamp, int type){
    mTotal += length;
    if (type == 1){
        mTotalFrms++;
    }
    long interval = System.currentTimeMillis() - pPreviewTS;
    if (interval >= 3000){
        long bps = mTotal * 1000 / (interval);
        long fps = mTotalFrms * 1000 / (interval);
        Log.i(TAG, String.format("bps:%d, fps:%d", fps, bps)+"  myTid = "+android.os.Process.myTid());
        pPreviewTS = System.currentTimeMillis();
        mTotal = 0;
        mTotalFrms = 0;
        if (mCameraId == Camera.CameraInfo.CAMERA_FACING_BACK)
            BUS.post(new StreamStatBack((int)fps, (int)bps));
        else
            BUS.post(new StreamStatFront((int)fps, (int)bps));
    }
    if (mPusherObj == 0 || !isRTMPConnectNormal) return;

    push(mPusherObj, data, offset, length, timestamp,type);
}

不知这样修改,是否能够优化push逻辑呢?

from easyrtmp.

Related Issues (15)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.