1 package com.alivc.live.pusher;
58 import static com.
alivc.
live.utils.ParameterUtil.getInteger;
59 import static com.
alivc.
live.utils.ParameterUtil.getLong;
61 import android.app.Application;
62 import android.app.Service;
63 import android.content.BroadcastReceiver;
64 import android.content.Context;
65 import android.content.Intent;
66 import android.content.IntentFilter;
67 import android.graphics.Bitmap;
68 import android.graphics.BitmapFactory;
69 import android.media.AudioManager;
70 import android.os.Handler;
71 import android.os.Looper;
72 import android.os.Message;
73 import android.telephony.PhoneStateListener;
74 import android.telephony.TelephonyManager;
75 import android.text.TextUtils;
76 import android.view.Surface;
77 import android.view.SurfaceHolder;
78 import android.view.SurfaceView;
79 import android.widget.FrameLayout;
134 import org.json.JSONException;
135 import org.json.JSONObject;
136 import org.webrtc.utils.AlivcLog;
138 import java.lang.ref.WeakReference;
139 import java.util.ArrayList;
140 import java.util.HashMap;
141 import java.util.Iterator;
142 import java.util.Map;
143 import java.util.StringTokenizer;
144 import java.util.concurrent.LinkedBlockingQueue;
145 import java.util.concurrent.ScheduledExecutorService;
146 import java.util.concurrent.ScheduledThreadPoolExecutor;
147 import java.util.concurrent.ThreadFactory;
148 import java.util.concurrent.ThreadPoolExecutor;
149 import java.util.concurrent.TimeUnit;
150 import java.util.concurrent.atomic.AtomicInteger;
287 class AlivcLivePusherBasicImpl
implements ILivePusher {
288 private static final String TAG =
"AlivcLivePusherBasicImpl";
292 SCREEN_RECORD_NORMAL,
293 SCREEN_RECORD_CAMERA_START,
294 SCREEN_RECORD_CAMERA_MIX_START,
297 private static LivePusherJNI mNativeAlivcLivePusher = null;
298 private WeakReference<AlivcLivePusher> mWeakAlivcLivePusher = null;
301 private AlivcLivePlayStats mPlayStats = AlivcLivePlayStats.IDLE;
308 private AlivcLivePusherRenderContextListener mRenderContextListener = null;
312 private SurfaceView mPreviewView = null;
314 private AudioManager mAudioManager = null;
316 private Context mContext = null;
319 private static final int NTP_TIME_OUT_MILLISECOND = 1000;
320 private static final String AUTH_KEY =
"auth_key=";
321 private static final int MAX_CHATS = 4000;
322 private static final float TEXTURE_RANGE_MIN = 0.0f;
323 private static final float TEXTURE_RANGE_MAX = 1.0f;
324 private static final int MAX_DYNAMIC_ADDSON_COUNT = 3;
325 private static final int AlivcLiveMaxWatermarkCount = 3;
327 private Map<Integer, AlivcLivePushError> mErrorMap =
new HashMap<>();
328 private String mPushUrl = null;
330 private int mBGMVolume = 50;
331 private int mCaptureVolume = 50;
332 private boolean mMute =
false;
333 private TelephonyManager manager = null;
336 private static final int MESSAGE_RECONNECT_SUCCESS = 0x12;
337 private boolean registeredCallback =
false;
338 protected BluetoothHeadsetUtils mBluetoothHelper;
339 private boolean isReconnect =
false;
340 private LiveEventReporter mLiveEventReporter = null;
341 private long mTimeStamp = -1;
342 private int mExpiryTime = -1;
344 private int mDynamicAddsonCount = 0;
346 private int mTimeCount = 0;
348 private int mWatermarkCount = 0;
357 private AppFrontBackHelper mAppFrontBackHelper;
359 private ThreadPoolExecutor mThreadPoolExecutor =
new ThreadPoolExecutor(3, 5, 1, TimeUnit.SECONDS,
360 new LinkedBlockingQueue<Runnable>(100));
362 private Handler mHandler =
new Handler(Looper.getMainLooper()) {
364 public void handleMessage(Message msg) {
365 AlivcLog.i(TAG,
"AlivcLivePusher reconnect success");
367 if (mPushNetworkListener != null) {
368 mThreadPoolExecutor.execute(
new Runnable() {
378 private SurfaceHolder.Callback mPreviewCallback =
new SurfaceHolder.Callback() {
380 public void surfaceCreated(SurfaceHolder holder) {
381 AlivcLog.d(TAG,
"LiveActivity-->Preview surface created");
382 if (mPreviewView == null) {
386 if (mSurfaceStatus == SurfaceStatus.
UNINITED) {
387 mSurfaceStatus = SurfaceStatus.
CREATED;
388 }
else if (mSurfaceStatus == SurfaceStatus.
DESTROYED) {
389 mSurfaceStatus = SurfaceStatus.
RECREATED;
390 if (mNativeAlivcLivePusher != null) {
391 mNativeAlivcLivePusher.notifySurfaceReCreate(mPreviewView.getHolder().getSurface());
397 public void surfaceChanged(SurfaceHolder holder,
int format,
int width,
int height) {
398 AlivcLog.d(TAG,
"LiveActivity-->Preview surface changed");
399 if (mPreviewView == null) {
402 mSurfaceStatus = SurfaceStatus.
CHANGED;
403 if (mNativeAlivcLivePusher != null) {
404 mNativeAlivcLivePusher.notifySurfaceChange(holder.getSurface(), mAlivcLivePushConfig.
getPreviewOrientation());
409 public void surfaceDestroyed(SurfaceHolder holder) {
410 AlivcLog.d(TAG,
"LiveActivity-->Preview surface destroyed");
411 if (mPreviewView == null) {
414 if (mNativeAlivcLivePusher != null) {
415 mNativeAlivcLivePusher.notifySurfaceDestroy();
417 mSurfaceStatus = SurfaceStatus.
DESTROYED;
421 private ScheduledExecutorService scheduleExecutor = null;
423 public AlivcLivePusherBasicImpl() {
436 public void init(
final Context context,
final AlivcLivePushConfig config)
throws IllegalArgumentException, IllegalStateException {
437 AlivcLog.i(TAG,
"init");
438 AlivcLog.i(TAG, AlivcLivePushInstance.getSdkBuildInfo());
440 mAlivcLivePushConfig = config;
441 mLiveEventReporter =
new LiveEventReporter(mContext,
this, mAlivcLivePushConfig);
443 if (!AlivcLiveLicenseManager.isLicenseRegistered()) {
444 String errorMessage =
"License not registered! Get HELP from https://help.aliyun.com/document_detail/431730.htm";
445 AlivcLog.e(TAG, errorMessage);
446 throw new IllegalStateException(errorMessage);
449 boolean isLicenseVerified = AlivcLiveLicenseManager.verifyLicense();
451 AlivcLiveLicenseManager.AlivcLiveLicenseResult licenseResult = AlivcLiveLicenseManager.getLatestLicenseResult();
452 if (licenseResult != null) {
453 PusherLicenseEvent.Args args =
new PusherLicenseEvent.Args();
454 args.result = licenseResult.result;
455 args.reason = licenseResult.msg;
456 args.key = licenseResult.licenseKey;
457 mLiveEventReporter.sendEvent(PusherLicenseEvent.kTopicType, PusherLicenseEvent.kTopicValue, PusherLicenseEvent.getArgsStr(args));
460 if (!isLicenseVerified) {
461 String errorMessage =
"License not verified! Get HELP from https://help.aliyun.com/document_detail/431730.htm";
462 AlivcLog.e(TAG, errorMessage);
463 throw new IllegalStateException(errorMessage);
466 if (mPushStatus != AlivcLivePushStats.
IDLE && mPushStatus != AlivcLivePushStats.
INIT) {
467 throw new IllegalStateException(
"init state error, current state is " + AlivcLivePushStats.values()[mPushStatus.ordinal()]);
469 mAudioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
470 mAudioManager.setMode(AudioManager.STREAM_VOICE_CALL);
471 mAudioManager.setSpeakerphoneOn(
true);
473 registerHeadsetPlugReceiver();
475 LogWhenGoBackOrFront((Application) context.getApplicationContext(),
true);
477 AliLiveInfoUtils.setSDKContext(mContext);
479 mBluetoothHelper =
new BluetoothHeadsetUtils(mContext);
480 mBluetoothHelper.start(
new BluetoothHeadsetUtils.BlueToothListener() {
482 public void onBlueTooth(
boolean on) {
483 LivePusherJNI.headSetOn = on;
485 mAudioManager.setMode(AudioManager.STREAM_VOICE_CALL);
486 mAudioManager.setSpeakerphoneOn(
true);
488 mAudioManager.setSpeakerphoneOn(
false);
490 if (mNativeAlivcLivePusher != null) {
491 mNativeAlivcLivePusher.setHeadSet(on);
500 for (AlivcLivePushError error : AlivcLivePushError.values()) {
501 mErrorMap.put(error.getCode(), error);
503 mLiveEventReporter =
new LiveEventReporter(mContext,
this, mAlivcLivePushConfig);
504 mNativeAlivcLivePusher =
new LivePusherJNI(mContext, config,
new LivePusherJNI.LivePusherListener() {
506 public void onNotify(
final int what, String msg,
final int param1,
final int param2,
int param3,
int param4,
int param5,
long arg6, String arg7, String arg8) {
508 if (what == ALIVC_PUSHER_ERROR_SDK_LIVE_PUSH_NETWORK_TOO_POOR.getCode()) {
509 AlivcLog.i(TAG,
"AlivcLivePusher Callback Network Too Poor");
510 if (mPushNetworkListener != null) {
511 mThreadPoolExecutor.execute(
new Runnable() {
514 mPushNetworkListener.
onNetworkPoor(getLivePusherReference());
519 PusherNetworkPoorEvent.Args args = null;
520 mLiveEventReporter.sendEvent(PusherNetworkPoorEvent.kTopicType, PusherNetworkPoorEvent.kTopicValue, PusherNetworkPoorEvent.getArgsStr(args));
521 }
else if (what == ALIVC_PUSHER_EVENT_PUSH_NETWORK_RECOVERY.getCode()) {
522 AlivcLog.i(TAG,
"AlivcLivePusher Callback Network Recovery");
523 if (mPushNetworkListener != null) {
524 mThreadPoolExecutor.execute(
new Runnable() {
532 PusherNetworkRecoveryEvent.Args args = null;
533 mLiveEventReporter.sendEvent(PusherNetworkRecoveryEvent.kTopicType, PusherNetworkRecoveryEvent.kTopicValue, PusherNetworkRecoveryEvent.getArgsStr(args));
534 }
else if (what == ALIVC_PUSHER_EVENT_PUSH_RECONNECT_START.getCode()) {
535 AlivcLog.i(TAG,
"AlivcLivePusher Callback Reconnect Start");
538 if (mPushNetworkListener != null) {
539 mThreadPoolExecutor.execute(
new Runnable() {
548 PusherReconnectStartEvent.Args args =
new PusherReconnectStartEvent.Args();
549 mLiveEventReporter.sendEvent(PusherReconnectStartEvent.kTopicType, PusherReconnectStartEvent.kTopicValue, PusherReconnectStartEvent.getArgsStr(args));
550 }
else if (what == ALIVC_PUSHER_EVENT_PUSH_RECONNECT_SUCCESS.getCode()) {
551 AlivcLog.i(TAG,
"AlivcLivePusher Callback Reconnect Success");
552 if (mHandler != null) {
553 mHandler.removeMessages(MESSAGE_RECONNECT_SUCCESS);
554 mHandler.sendEmptyMessageDelayed(MESSAGE_RECONNECT_SUCCESS, 500);
557 if (mPushStatus != AlivcLivePushStats.
PAUSED) {
558 mPushStatus = AlivcLivePushStats.
PUSHED;
561 PusherReconnectSuccessEvent.Args args = null;
562 mLiveEventReporter.sendEvent(PusherReconnectSuccessEvent.kTopicType, PusherReconnectSuccessEvent.kTopicValue, PusherReconnectSuccessEvent.getArgsStr(args));
563 }
else if (what == ALIVC_PUSHER_EVENT_PUSH_CONNECTION_LOST.getCode()) {
564 AlivcLog.i(TAG,
"AlivcLivePusher Callback Connection Lost");
566 if (mPushNetworkListener != null) {
567 mThreadPoolExecutor.execute(
new Runnable() {
575 PusherConnectionLostEvent.Args args =
new PusherConnectionLostEvent.Args();
577 args.reason =
"rtmp_";
578 }
else if (param1 == 1) {
579 args.reason =
"artc_";
581 args.reason += String.valueOf(param2);
582 mLiveEventReporter.sendEvent(PusherConnectionLostEvent.kTopicType, PusherConnectionLostEvent.kTopicValue, PusherConnectionLostEvent.getArgsStr(args));
583 }
else if (what == ALIVC_PUSHER_ERROR_SDK_PUSH_RECONNECT_FAIL.getCode()) {
584 AlivcLog.i(TAG,
"AlivcLivePusher Callback Reconnect Fail");
587 if (mHandler != null) {
588 mHandler.removeMessages(MESSAGE_RECONNECT_SUCCESS);
590 if (mPushNetworkListener != null) {
591 mThreadPoolExecutor.execute(
new Runnable() {
598 mPushStatus = AlivcLivePushStats.
ERROR;
599 mLastError = ALIVC_PUSHER_ERROR_SDK_PUSH_RECONNECT_FAIL;
601 PusherReconnectFailedEvent.Args args =
new PusherReconnectFailedEvent.Args();
604 mLiveEventReporter.sendEvent(PusherReconnectFailedEvent.kTopicType, PusherReconnectFailedEvent.kTopicValue, PusherReconnectFailedEvent.getArgsStr(args));
605 }
else if (what == ALIVC_PUSHER_ERROR_SDK_PUSH_SEND_DATA_TIMEOUT.getCode()) {
606 AlivcLog.i(TAG,
"AlivcLivePusher Callback Send Data Timeout");
607 if (mPushNetworkListener != null) {
608 mThreadPoolExecutor.execute(
new Runnable() {
616 PusherSendDataTimeoutEvent.Args args = null;
617 mLiveEventReporter.sendEvent(PusherSendDataTimeoutEvent.kTopicType, PusherSendDataTimeoutEvent.kTopicValue, PusherSendDataTimeoutEvent.getArgsStr(args));
618 }
else if (what == ALIVC_PUSHER_ERROR_SDK_PUSH_CONNECT.getCode()
619 || what == ALIVC_LIVE_ERROR_SYSTEM_RTMP_OOM.getCode()
620 || what == ALIVC_PUSHER_ERROR_SDK_PUSH_SETUPURL.getCode()
621 || what == ALIVC_PUSHER_ERROR_SDK_PUSH_CONNECT_STREAM.getCode()
622 || what == ALIVC_PUSHER_ERROR_SDK_PUSH_START_PUSH_TIMEOUT.getCode()) {
623 AlivcLog.i(TAG,
"AlivcLivePusher Callback Push Connect Fail");
625 if (mPushNetworkListener != null) {
626 mThreadPoolExecutor.execute(
new Runnable() {
629 mPushNetworkListener.
onConnectFail(getLivePusherReference());
633 mPushStatus = AlivcLivePushStats.
ERROR;
634 mLastError = getErrorByCode(what);
636 PusherStartPushFailedEvent.Args args =
new PusherStartPushFailedEvent.Args();
639 mLiveEventReporter.sendEvent(PusherStartPushFailedEvent.kTopicType, PusherStartPushFailedEvent.kTopicValue, PusherStartPushFailedEvent.getArgsStr(args));
640 }
else if (what == ALIVC_PUSHER_EVENT_NATIVE_LIVE_PUSH_INIT_SUCCESS.getCode()) {
642 }
else if (what == ALIVC_PUSHER_EVENT_NATIVE_LIVE_PUSH_PREVIEW_STARTED.getCode()) {
643 AlivcLog.i(TAG,
"AlivcLivePusher Callback Preview Started");
645 if (mPushInfoListener != null) {
646 mThreadPoolExecutor.execute(
new Runnable() {
653 mPushStatus = AlivcLivePushStats.
PREVIEWED;
655 }
else if (what == ALIVC_PUSHER_EVENT_NATIVE_LIVE_PUSH_PREVIEW_STOPED.getCode()) {
656 AlivcLog.i(TAG,
"AlivcLivePusher Callback Preview Stoped");
658 if (mPushInfoListener != null) {
659 mThreadPoolExecutor.execute(
new Runnable() {
662 if (mPushInfoListener != null) {
668 mPushStatus = AlivcLivePushStats.
INIT;
669 }
else if (what == ALIVC_PUSHER_EVENT_PUSH_STARTED.getCode()) {
670 AlivcLog.i(TAG,
"AlivcLivePusher Callback Push Started");
672 mPushStatus = AlivcLivePushStats.
PUSHED;
673 if (mPushInfoListener != null) {
674 mThreadPoolExecutor.execute(
new Runnable() {
682 PusherStartPushSuccessEvent.Args args =
new PusherStartPushSuccessEvent.Args();
684 mLiveEventReporter.sendEvent(PusherStartPushSuccessEvent.kTopicType, PusherStartPushSuccessEvent.kTopicValue, PusherStartPushSuccessEvent.getArgsStr(args));
685 }
else if (what == ALIVC_PUSHER_EVENT_PUSH_STOPED.getCode()) {
686 AlivcLog.i(TAG,
"AlivcLivePusher Callback Push Stoped");
688 if (mPushInfoListener != null) {
689 mThreadPoolExecutor.execute(
new Runnable() {
692 if (mPushInfoListener != null) {
698 PusherStopPushSuccessEvent.Args args =
new PusherStopPushSuccessEvent.Args();
700 mLiveEventReporter.sendEvent(PusherStopPushSuccessEvent.kTopicType, PusherStopPushSuccessEvent.kTopicValue, PusherStopPushSuccessEvent.getArgsStr(args));
701 }
else if(what == ALIVC_PUSHER_EVENT_PUSH_CRASH.getCode()){
702 AlivcLog.i(TAG,
"found SDK crashed!");
703 mLiveEventReporter.sendEvent(PusherSDKCrashEvent.kTopicType, PusherSDKCrashEvent.kTopicValue, PusherSDKCrashEvent.getArgsStr(arg7, arg8));
704 }
else if(what == ALIVC_PUSHER_EVENT_GENERAL_MONITOR.getCode()) {
705 AlivcLivePushConstants.Topic topicType = AlivcLivePushConstants.Topic.event;
707 int topicTypeId = (int)arg6;
708 switch (topicTypeId) {
709 case 0: topicType = AlivcLivePushConstants.Topic.action;
break;
710 case 1: topicType = AlivcLivePushConstants.Topic.event;
break;
711 case 2: topicType = AlivcLivePushConstants.Topic.error;
break;
712 case 3: topicType = AlivcLivePushConstants.Topic.biz;
break;
713 default: assert(
false);
716 assert(!arg7.isEmpty());
717 String topicValue = arg7;
718 String argJsonStr = arg8;
719 Map<String, String> param =
new HashMap<String, String>();
721 JSONObject obj =
new JSONObject(argJsonStr);
722 Iterator it = obj.keys();
723 while (it.hasNext()) {
724 String key = it.next().toString();
725 String value = (String)obj.get(key).toString();
726 param.put(key, value);
728 }
catch(JSONException e) {
729 AlivcLog.e(TAG,
"Invalid json object: " + arg8);
730 }
catch(Exception e) {
731 AlivcLog.e(TAG,
"Unknown exception: " + e.getMessage());
733 mLiveEventReporter.sendEvent(topicType, topicValue, param);
734 }
else if(what == ALIVC_PUSHER_EVENT_PUSH_MEDIAINFO.getCode()) {
736 }
else if(what == ALIVC_PUSHER_EVENT_PUSH_DELAY_INFO.getCode()) {
738 PusherDelayInfoEvent.Args args =
new PusherDelayInfoEvent.Args();
739 args.totalDelay = param1;
740 args.captureDelay = param2;
741 args.encoderDelay = param3;
742 args.sendDelay = param4;
744 AlivcLog.d(TAG,
"AlivcLivePusher push delay");
746 mLiveEventReporter.sendEvent(PusherDelayInfoEvent.kTopicType, PusherDelayInfoEvent.kTopicValue, PusherDelayInfoEvent.getArgsStr(args));
749 JSONObject gDelayObject =
new JSONObject();
752 gDelayObject.put(
"gdelay", param1);
754 sendMessageInternal(gDelayObject.toString(),10,0,
false,
true);
756 }
catch (Exception e) {
761 }
else if (what == ALIVC_PUSHER_EVENT_NATIVE_LIVE_PUSH_PUSH_PAUSED.getCode()) {
762 AlivcLog.i(TAG,
"AlivcLivePusher Callback Push Paused");
764 if (mPushInfoListener != null) {
765 mThreadPoolExecutor.execute(
new Runnable() {
768 mPushInfoListener.
onPushPaused(getLivePusherReference());
773 PusherOnPauseEvent.Args args = null;
774 mLiveEventReporter.sendEvent(PusherOnPauseEvent.kTopicType, PusherOnPauseEvent.kTopicValue, PusherOnPauseEvent.getArgsStr(args));
775 }
else if (what == ALIVC_PUSHER_EVENT_NATIVE_LIVE_PUSH_PUSH_RESUMED.getCode()) {
776 AlivcLog.i(TAG,
"AlivcLivePusher Callback Push Resumed");
778 if (mNativeAlivcLivePusher.isPushing()) {
779 mPushStatus = AlivcLivePushStats.
PUSHED;
781 mPushStatus = AlivcLivePushStats.
PREVIEWED;
783 if (mPushInfoListener != null) {
784 mThreadPoolExecutor.execute(
new Runnable() {
792 PusherOnResumeEvent.Args args = null;
793 mLiveEventReporter.sendEvent(PusherOnResumeEvent.kTopicType, PusherOnResumeEvent.kTopicValue, PusherOnResumeEvent.getArgsStr(args));
794 }
else if (what == ALIVC_FRAMEWORK_RENDER_FIRST_FRAME_PREVIEWED.getCode()) {
795 AlivcLog.i(TAG,
"AlivcLivePusher Callback Preview First Frame");
797 if (mPushInfoListener != null) {
798 mThreadPoolExecutor.execute(
new Runnable() {
805 }
else if (what == ALIVC_PUSHER_EVENT_NATIVE_LIVE_PUSH_PUSH_RESTARTED.getCode()) {
806 AlivcLog.i(TAG,
"AlivcLivePusher Callback Push Restarted");
808 mPushStatus = AlivcLivePushStats.
PUSHED;
809 if (mPushInfoListener != null) {
810 mThreadPoolExecutor.execute(
new Runnable() {
818 PusherOnRestartEvent.Args args = null;
819 mLiveEventReporter.sendEvent(PusherOnRestartEvent.kTopicType, PusherOnRestartEvent.kTopicValue, PusherOnRestartEvent.getArgsStr(args));
820 }
else if (what == ALIVC_PUSHER_EVENT_PUSH_DROP_FRAME.getCode()) {
821 AlivcLog.d(TAG,
"AlivcLivePusher Callback Drop Frame");
823 PusherDropFrameEvent.PusherDropFrameArgs args =
new PusherDropFrameEvent.PusherDropFrameArgs();
824 args.vpiubbd = param1;
825 args.vpiubad = param2;
826 args.apiubbd = param3;
827 args.apiubad = param4;
828 mLiveEventReporter.sendEvent(PusherDropFrameEvent.kTopicType, PusherDropFrameEvent.kTopicValue, PusherDropFrameEvent.getArgsStr(args));
829 if (mPushInfoListener != null) {
830 mThreadPoolExecutor.execute(
new Runnable() {
833 mPushInfoListener.
onDropFrame(getLivePusherReference(), param1, param2);
835 if (mPushNetworkListener != null) {
836 mPushNetworkListener.
onPacketsLost(getLivePusherReference());
842 }
else if (what == ALIVC_PUSHER_EVENT_NATIVE_LIVE_PUSH_ADJUST_BITRATE.getCode()) {
843 AlivcLog.d(TAG,
"AlivcLivePusher Callback Adjust Bitrate");
845 PusherAdjustBitrateEvent.Args args =
new PusherAdjustBitrateEvent.Args();
846 args.oeb = param1 / 1000;
847 args.neb = param2 / 1000;
848 Map map = getPerformanceMap();
850 args.ceb = getInteger(map,
"mVideoEncodeBitrate") + getInteger(map,
"mAudioEncodeBitrate");
851 args.cub = getInteger(map,
"mAudioUploadBitrate") + getInteger(map,
"mVideoUploadBitrate");
853 mLiveEventReporter.sendEventWithLevel(PusherAdjustBitrateEvent.kTopicType, PusherAdjustBitrateEvent.kTopicValue, PusherAdjustBitrateEvent.getArgsStr(args), AlivcLivePushMonitorLevel.CUT);
854 if (mPushInfoListener != null) {
855 mThreadPoolExecutor.execute(
new Runnable() {
858 mPushInfoListener.
onAdjustBitrate(getLivePusherReference(), param1 / 1000, param2 / 1000);
862 }
else if (what == ALIVC_PUSHER_EVENT_NATIVE_LIVE_PUSH_CHANGE_FPS.getCode()) {
863 AlivcLog.d(TAG,
"AlivcLivePusher Callback Change FPS");
865 PusherAdjustFpsEvent.Args args =
new PusherAdjustFpsEvent.Args();
866 args.oldFps = param1;
867 args.newFps = param2;
868 mLiveEventReporter.sendEvent(PusherAdjustFpsEvent.kTopicType, PusherAdjustFpsEvent.kTopicValue, PusherAdjustFpsEvent.getArgsStr(args));
869 if (mPushInfoListener != null) {
870 mThreadPoolExecutor.execute(
new Runnable() {
873 mPushInfoListener.
onAdjustFps(getLivePusherReference(), param1, param2);
877 }
else if (what == ALIVC_PUSHER_EVENT_NATIVE_LIVE_PUSH_CHANGE_RESOLUTION.getCode()) {
879 }
else if (what == ALIVC_PUSHER_ERROR_SDK_PUSH_RTS_DOWN_TO_RTMP.getCode()) {
882 }
else if (what == ALIVC_PUSHER_EVENT_PUSH_SENDED_FIRST_AV.getCode()) {
884 PusherFirstFrameSentEvent.Args args =
new PusherFirstFrameSentEvent.Args();
887 args.resolution = mAlivcLivePushConfig.
getResolution().toString().substring(11);
892 args.wc = mAlivcLivePushConfig.getWaterMarkInfos().size();
894 args.fps = mAlivcLivePushConfig.
getFps();
901 args.flash = mAlivcLivePushConfig.
isFlash();
907 mLiveEventReporter.sendEvent(PusherFirstFrameSentEvent.kTopicType, PusherFirstFrameSentEvent.kTopicValue, PusherFirstFrameSentEvent.getArgsStr(args));
908 if (mPushInfoListener != null) {
909 mThreadPoolExecutor.execute(
new Runnable() {
916 }
else if (what == ALIVC_PUSHER_EVENT_CAPTURE_OPEN_CAMERA_SUCCESS.getCode()) {
918 }
else if (what == ALIVC_PUSHER_EVENT_CAPTURE_OPEN_MIC_SUCCESS.getCode()) {
920 }
else if (what == ALIVC_PUSHER_EVENT_CAPTURE_CLOSE_CAMERA_SUCCESS.getCode()) {
922 }
else if (what == ALIVC_PUSHER_EVENT_NATIVE_LIVE_PUSH_OPEN_VIDEO_ENCODER_SUCCESS.getCode()) {
924 }
else if (what == ALIVC_PUSHER_EVENT_NATIVE_LIVE_PUSH_CAPTURE_VIDEO_SAMPLES_OVERFLOW.getCode()) {
926 }
else if (what == ALIVC_PUSHER_EVENT_PUSH_SENDED_SEI.getCode()) {
927 if (mPushNetworkListener != null) {
928 mThreadPoolExecutor.execute(
new Runnable() {
931 mPushNetworkListener.
onSendMessage(getLivePusherReference());
938 else if (what == ALIVC_PUSHER_ERROR_BGM_OPEN_FAILED.getCode()) {
939 mPlayStats = AlivcLivePlayStats.IDLE;
940 if (mPushBGMListener != null) {
943 if (mNativeAlivcLivePusher != null) {
944 mNativeAlivcLivePusher.stopBGM();
946 }
else if (what == ALIVC_PUSHER_ERROR_BGM_TIMEOUT.getCode()) {
947 mPlayStats = AlivcLivePlayStats.IDLE;
948 if (mPushBGMListener != null) {
951 }
else if (what == ALIVC_PUSHER_EVENT_BGM_OPEN_SUCCESS.getCode()) {
952 mPlayStats = AlivcLivePlayStats.STARTED;
953 if (mPushBGMListener != null) {
956 }
else if (what == ALIVC_PUSHER_EVENT_BGM_STOP_SUCCESS.getCode()) {
957 mPlayStats = AlivcLivePlayStats.STOPPED;
958 if (mPushBGMListener != null) {
961 }
else if (what == ALIVC_PUSHER_EVENT_BGM_PAUSE_SUCCESS.getCode()) {
962 mPlayStats = AlivcLivePlayStats.PAUSED;
963 if (mPushBGMListener != null) {
966 }
else if (what == ALIVC_PUSHER_EVENT_BGM_RESUME_SUCCESS.getCode()) {
967 mPlayStats = AlivcLivePlayStats.STARTED;
968 if (mPushBGMListener != null) {
971 }
else if (what == ALIVC_PUSHER_EVENT_BGM_COMPLETED.getCode()) {
972 if (mPushBGMListener != null) {
975 mPlayStats = AlivcLivePlayStats.IDLE;
976 }
else if (what == ALIVC_PUSHER_EVENT_BGM_PROGRESS.getCode()) {
977 if (mPushBGMListener != null) {
978 mPushBGMListener.
onProgress((
long) param1, (
long) param2);
980 }
else if (what == ALIVC_PUSHER_EVENT_CAPTURE_OPEN_SCREENCAPTURE_SUCCESS.getCode()) {
982 }
else if (what == ALIVC_PUSHER_EVENT_CAPTURE_CLOSE_SCREENCAPTURE_SUCCESS.getCode()) {
984 }
else if (what == ALIVC_PUSHER_EVENT_NATIVE_LIVE_PUSH_GL_CONTEXT_CREATED.getCode()) {
985 if (mRenderContextListener != null) {
986 mRenderContextListener.onSharedContextCreated(arg6);
988 }
else if (what == ALIVC_PUSHER_EVENT_NATIVE_LIVE_PUSH_GL_CONTEXT_DESTROYED.getCode()) {
989 if (mRenderContextListener != null) {
990 mRenderContextListener.onSharedContextDestroyed(arg6);
994 else if (what > 0x30010000 && what < 0x30020000) {
995 AlivcLog.e(TAG,
"AlivcLivePusher SystemError Callback error: " + what);
997 if (mErrorMap.get(what) != null) {
998 mErrorMap.get(what).setMsg(msg);
1000 if (mPushErrorListener != null) {
1001 mThreadPoolExecutor.execute(
new Runnable() {
1004 mPushErrorListener.
onSystemError(getLivePusherReference(), mErrorMap.get(what));
1009 PusherSystemErrorEvent.Args args =
new PusherSystemErrorEvent.Args();
1010 Map map = getPerformanceMap();
1012 args.totalUploadSize = getLong(map,
"mTotalSizeOfUploadedPackets");
1013 args.totalTime = getLong(map,
"mTotalTimeOfPublishing");
1014 args.error_code = what;
1015 if (mErrorMap.get(what) != null) {
1016 args.error_msg = msg;
1018 mLiveEventReporter.sendEvent(PusherSystemErrorEvent.kTopicType, PusherSystemErrorEvent.kTopicValue, PusherSystemErrorEvent.getArgsStr(args));
1020 mPushStatus = AlivcLivePushStats.
ERROR;
1021 mLastError = getErrorByCode(what);
1023 else if (what == ALIVC_PUSHER_ERROR_SDK_LIVE_PUSH_LOW_PERFORMANCE.getCode()) {
1025 AlivcLog.i(TAG,
"AlivcLivePusher low performance warning: 0x" + Integer.toHexString(what));
1026 if (mErrorMap.get(what) != null) {
1027 mErrorMap.get(what).setMsg(msg);
1029 PusherSdkErrorEvent.Args args =
new PusherSdkErrorEvent.Args();
1030 Map map = getPerformanceMap();
1032 args.totalUploadSize = ParameterUtil.getLong(map,
"mTotalSizeOfUploadedPackets");
1033 args.totalTime = ParameterUtil.getLong(map,
"mTotalTimeOfPublishing");
1034 args.error_code = what;
1035 if (mErrorMap.get(what) != null) {
1036 args.error_msg = msg;
1038 mLiveEventReporter.sendEvent(PusherSdkErrorEvent.kTopicType, PusherSdkErrorEvent.kTopicValue, PusherSdkErrorEvent.getArgsStr(args));
1043 AlivcLog.e(TAG,
"AlivcLivePusher SDKError Callback error: 0x" + Integer.toHexString(what));
1045 if (mErrorMap.get(what) != null) {
1046 mErrorMap.get(what).setMsg(msg);
1048 if (mPushErrorListener != null) {
1049 mThreadPoolExecutor.execute(
new Runnable() {
1052 mPushErrorListener.
onSDKError(getLivePusherReference(), mErrorMap.get(what));
1057 PusherSdkErrorEvent.Args args =
new PusherSdkErrorEvent.Args();
1058 Map map = getPerformanceMap();
1060 args.totalUploadSize = getLong(map,
"mTotalSizeOfUploadedPackets");
1061 args.totalTime = getLong(map,
"mTotalTimeOfPublishing");
1062 args.error_code = what;
1063 if (mErrorMap.get(what) != null) {
1064 args.error_msg = msg;
1066 mLiveEventReporter.sendEvent(PusherSdkErrorEvent.kTopicType, PusherSdkErrorEvent.kTopicValue, PusherSdkErrorEvent.getArgsStr(args));
1068 mPushStatus = AlivcLivePushStats.
ERROR;
1069 mLastError = getErrorByCode(what);
1070 AlivcLog.e(TAG,
"error is " + what +
" msg is " + what);
1074 mNativeAlivcLivePusher.init();
1075 BGMPlayerJNI.setContext(mContext);
1077 mPushStatus = AlivcLivePushStats.
INIT;
1086 public void setCustomDetect(AlivcLivePushCustomDetect customVideoDetect) {
1087 AlivcLog.i(TAG,
"setCustomDetect");
1088 if (mNativeAlivcLivePusher == null) {
1091 mNativeAlivcLivePusher.setCustomDetect(customVideoDetect);
1100 public void setCustomFilter(AlivcLivePushCustomFilter customVideoFilter) {
1101 AlivcLog.i(TAG,
"setCustomFilter");
1102 if (mNativeAlivcLivePusher == null) {
1105 mNativeAlivcLivePusher.setCustomFilter(customVideoFilter);
1114 public void setCustomAudioFilter(AlivcLivePushCustomAudioFilter customAudioFilter) {
1115 AlivcLog.i(TAG,
"setCustomAudioFilter");
1116 if (mNativeAlivcLivePusher == null) {
1119 mNativeAlivcLivePusher.setCustomAudioFilter(customAudioFilter);
1128 public void destroy() throws IllegalStateException {
1129 AlivcLog.i(TAG,
"destroy");
1130 LogWhenGoBackOrFront((Application) mContext.getApplicationContext(),
false);
1132 if (mNativeAlivcLivePusher != null) {
1133 mNativeAlivcLivePusher.release();
1136 mDynamicAddsonCount = 0;
1138 if (registeredCallback) {
1140 mContext.unregisterReceiver(mHeadsetPlugReceiver);
1141 mContext.unregisterReceiver(mTelephoneReceiver);
1142 }
catch (Exception e) {
1143 AlivcLog.e(TAG,
"unregisterReceiver exception");
1145 registeredCallback =
false;
1147 if (mBluetoothHelper != null) {
1148 mBluetoothHelper.stop();
1150 mPushStatus = AlivcLivePushStats.
IDLE;
1154 if (mThreadPoolExecutor != null && !mThreadPoolExecutor.isShutdown()) {
1155 mThreadPoolExecutor.shutdown();
1157 mThreadPoolExecutor = null;
1159 mNativeAlivcLivePusher = null;
1160 mPushInfoListener = null;
1161 mPushErrorListener = null;
1162 mPushNetworkListener = null;
1163 mPushBGMListener = null;
1165 mPreviewView = null;
1167 mAlivcLivePushConfig = null;
1170 mPreviewCallback = null;
1171 if (mHandler != null) {
1172 mHandler.removeMessages(MESSAGE_RECONNECT_SUCCESS);
1176 if (mWeakAlivcLivePusher != null) {
1177 mWeakAlivcLivePusher.clear();
1178 mWeakAlivcLivePusher = null;
1180 BGMPlayerJNI.setContext(null);
1184 public void setLivePusherReference(AlivcLivePusher livePusher) {
1185 mWeakAlivcLivePusher =
new WeakReference<>(livePusher);
1188 private AlivcLivePusher getLivePusherReference() {
1189 return (mWeakAlivcLivePusher != null) ? mWeakAlivcLivePusher.get() : null;
1200 public void startPreview(SurfaceView surfaceView)
throws IllegalArgumentException, IllegalStateException {
1201 AlivcLog.i(TAG,
"startPreview");
1202 PusherStartPreviewEvent.Args args =
new PusherStartPreviewEvent.Args();
1204 if (mLiveEventReporter != null) {
1205 mLiveEventReporter.sendEvent(PusherStartPreviewEvent.kTopicType, PusherStartPreviewEvent.kTopicValue, PusherStartPreviewEvent.getArgsStr(args));
1208 if (mNativeAlivcLivePusher == null) {
1209 AlivcLog.e(TAG,
"Illegal State, you should init first");
1212 if (mPushStatus != AlivcLivePushStats.
INIT && mPushStatus != AlivcLivePushStats.
PREVIEWED) {
1213 AlivcLog.e(TAG,
"status error current state is " + AlivcLivePushStats.values()[mPushStatus.ordinal()]);
1217 this.mPreviewView = surfaceView;
1219 if (surfaceView == null) {
1220 result = mNativeAlivcLivePusher.startPreview(null,
true);
1222 mPushStatus = AlivcLivePushStats.
PREVIEWED;
1224 AlivcLog.e(TAG,
"start preview error");
1228 result = mNativeAlivcLivePusher.startPreview(surfaceView.getHolder().getSurface(),
true);
1230 surfaceView.getHolder().addCallback(mPreviewCallback);
1231 mPushStatus = AlivcLivePushStats.
PREVIEWED;
1233 AlivcLog.e(TAG,
"start preview error");
1246 public void startPreviewAsync(SurfaceView surfaceView)
throws IllegalArgumentException, IllegalStateException {
1247 AlivcLog.i(TAG,
"startPreviewAsync");
1249 PusherStartPreviewEvent.Args args =
new PusherStartPreviewEvent.Args();
1251 if (mLiveEventReporter != null) {
1252 mLiveEventReporter.sendEvent(PusherStartPreviewEvent.kTopicType, PusherStartPreviewEvent.kTopicValue, PusherStartPreviewEvent.getArgsStr(args));
1255 if (mNativeAlivcLivePusher == null) {
1256 AlivcLog.e(TAG,
"Illegal State, you should init first");
1260 if (mPushStatus != AlivcLivePushStats.
INIT && mPushStatus != AlivcLivePushStats.
PREVIEWED) {
1261 AlivcLog.e(TAG,
"status error current state is " + AlivcLivePushStats.values()[mPushStatus.ordinal()]);
1266 this.mPreviewView = surfaceView;
1268 if (surfaceView == null) {
1269 result = mNativeAlivcLivePusher.startPreview(null,
false);
1271 mPushStatus = AlivcLivePushStats.
PREVIEWED;
1273 AlivcLog.e(TAG,
"start preview async error");
1276 result = mNativeAlivcLivePusher.startPreview(surfaceView.getHolder().getSurface(),
false);
1278 surfaceView.getHolder().addCallback(mPreviewCallback);
1279 mPushStatus = AlivcLivePushStats.
PREVIEWED;
1281 AlivcLog.e(TAG,
"start preview async error");
1287 public void startPreview(Context context, FrameLayout frameLayout,
boolean isAnchor)
throws IllegalArgumentException, IllegalStateException {
1297 public void stopPreview() throws IllegalStateException {
1298 AlivcLog.i(TAG,
"stopPreview");
1299 PusherStopPreviewEvent.Args args = null;
1300 if (mLiveEventReporter != null) {
1301 mLiveEventReporter.sendEvent(PusherStopPreviewEvent.kTopicType, PusherStopPreviewEvent.kTopicValue, PusherStopPreviewEvent.getArgsStr(args));
1304 if (mNativeAlivcLivePusher == null) {
1305 AlivcLog.e(TAG,
"Illegal State, you should init first");
1309 mDynamicAddsonCount = 0;
1311 if (mPushStatus != AlivcLivePushStats.
INIT && mPushStatus != AlivcLivePushStats.
PREVIEWED) {
1312 AlivcLog.e(TAG,
"status error current state is " + AlivcLivePushStats.values()[mPushStatus.ordinal()]);
1316 int result = mNativeAlivcLivePusher.stopPreview();
1318 mPushStatus = AlivcLivePushStats.
INIT;
1320 AlivcLog.e(TAG,
"stop preview error");
1332 public void startPush(String url)
throws IllegalArgumentException, IllegalStateException {
1333 AlivcLog.i(TAG,
"startPush");
1334 if (mNativeAlivcLivePusher == null || mAlivcLivePushConfig == null) {
1335 AlivcLog.e(TAG,
"Illegal State, you should init first");
1339 url = AlivcLiveURLTools.trimUrl(url);
1340 if (!AlivcLiveURLTools.checkPushUrl(url)) {
1341 AlivcLog.e(TAG,
"Illegal argument, push url error!");
1345 if ((mAlivcLivePushConfig.
isAudioOnly() || mAlivcLivePushConfig.
isVideoOnly()) && url.startsWith(AlivcLiveStreamType.EnumType.AlivcLiveStreamRts.getPrefix())) {
1346 AlivcLog.e(TAG,
"RTC protocol don't support audio/video only stream");
1350 if ((mPushStatus != AlivcLivePushStats.
PREVIEWED && mPushStatus != AlivcLivePushStats.
INIT)
1351 && mPushStatus != AlivcLivePushStats.
PUSHED) {
1352 AlivcLog.e(TAG,
"status error current state is " + AlivcLivePushStats.values()[mPushStatus.ordinal()]);
1356 if (mPushStatus.equals(AlivcLivePushStats.INIT)) {
1357 mPreviewView = null;
1358 int result = mNativeAlivcLivePusher.startPreview(null,
true);
1360 AlivcLog.e(TAG,
"start push error : create gl resource failed");
1365 if (mPushUrl.contains(AUTH_KEY)) {
1369 mLiveEventReporter.refreshPushId();
1370 int result = mNativeAlivcLivePusher.startPush(url,
true);
1372 if (mPushStatus != AlivcLivePushStats.
PUSHED) {
1373 mPushStatus = AlivcLivePushStats.
PUSHED;
1375 mScreenStatus = ScreenRecordStatus.SCREEN_RECORD_NORMAL;
1379 AlivcLog.e(TAG,
"start push error");
1383 reportStartPushEvent(
false,
true);
1387 mNativeAlivcLivePusher.addPushImage(pauseImage, networkImage);
1388 startScheduleExecutor();
1399 public void startPushAsync(String url)
throws IllegalArgumentException, IllegalStateException {
1400 AlivcLog.i(TAG,
"startPushAsync");
1401 if (mNativeAlivcLivePusher == null || mAlivcLivePushConfig == null) {
1402 AlivcLog.e(TAG,
"Illegal State, you should init first");
1406 url = AlivcLiveURLTools.trimUrl(url);
1407 if (!AlivcLiveURLTools.checkPushUrl(url)) {
1408 AlivcLog.e(TAG,
"Illegal argument, push url error!");
1412 if ((mPushStatus != AlivcLivePushStats.
PREVIEWED && mPushStatus != AlivcLivePushStats.
INIT)
1413 && mPushStatus != AlivcLivePushStats.
PUSHED) {
1414 AlivcLog.e(TAG,
"status error current state is " + AlivcLivePushStats.values()[mPushStatus.ordinal()]);
1418 if ((mAlivcLivePushConfig.
isAudioOnly() || mAlivcLivePushConfig.
isVideoOnly()) && url.startsWith(AlivcLiveStreamType.EnumType.AlivcLiveStreamRts.getPrefix())) {
1419 AlivcLog.e(TAG,
"RTC protocol don't support audio/video only stream");
1423 if (mPushStatus.equals(AlivcLivePushStats.INIT)) {
1424 mPreviewView = null;
1425 int result = mNativeAlivcLivePusher.startPreview(null,
true);
1427 AlivcLog.e(TAG,
"start push error : create gl resource failed");
1433 if (mPushUrl.contains(AUTH_KEY)) {
1437 mLiveEventReporter.refreshPushId();
1438 int result = mNativeAlivcLivePusher.startPush(url,
false);
1440 if (mPushStatus != AlivcLivePushStats.
PUSHED) {
1441 mPushStatus = AlivcLivePushStats.
PUSHED;
1443 mScreenStatus = ScreenRecordStatus.SCREEN_RECORD_NORMAL;
1447 AlivcLog.e(TAG,
"start push async error");
1451 reportStartPushEvent(
false,
false);
1455 mNativeAlivcLivePusher.addPushImage(pauseImage, networkImage);
1456 startScheduleExecutor();
1465 public void restartPush() throws IllegalStateException {
1466 AlivcLog.i(TAG,
"restartPush");
1467 if (mNativeAlivcLivePusher == null || mAlivcLivePushConfig == null) {
1468 AlivcLog.e(TAG,
"Illegal State, you should init first");
1474 AlivcLog.e(TAG,
"illegal argument");
1479 && (!TextUtils.isEmpty(mPushUrl) && mPushUrl.startsWith(AlivcLiveStreamType.EnumType.AlivcLiveStreamRts.getPrefix()))) {
1480 AlivcLog.e(TAG,
"RTC protocol don't support audio/video only stream");
1484 if (mPushStatus != AlivcLivePushStats.
PUSHED && mPushStatus != AlivcLivePushStats.
ERROR) {
1485 AlivcLog.e(TAG,
"status error current state is " + AlivcLivePushStats.values()[mPushStatus.ordinal()]);
1489 mDynamicAddsonCount = 0;
1493 Surface surface = mPreviewView != null ? mPreviewView.getHolder().getSurface() : null;
1494 int result = mNativeAlivcLivePusher.restartPush(surface,
true, 1000);
1496 mPushStatus = AlivcLivePushStats.
PUSHED;
1498 mScreenStatus = ScreenRecordStatus.SCREEN_RECORD_NORMAL;
1501 AlivcLog.e(TAG,
"restart push error");
1506 mNativeAlivcLivePusher.addPushImage(pauseImage, networkImage);
1508 reportStartPushEvent(
true,
true);
1510 startScheduleExecutor();
1520 public void restartPushAsync() throws IllegalStateException {
1521 AlivcLog.i(TAG,
"restartPushAsync");
1522 if (mNativeAlivcLivePusher == null || mAlivcLivePushConfig == null) {
1523 AlivcLog.e(TAG,
"Illegal State, you should init first");
1529 AlivcLog.e(TAG,
"illegal argument");
1534 && (!TextUtils.isEmpty(mPushUrl) && mPushUrl.startsWith(AlivcLiveStreamType.EnumType.AlivcLiveStreamRts.getPrefix()))) {
1535 AlivcLog.e(TAG,
"RTC protocol don't support audio/video only stream");
1539 if (mPushStatus != AlivcLivePushStats.
PUSHED && mPushStatus != AlivcLivePushStats.
ERROR) {
1540 AlivcLog.e(TAG,
"status error current state is " + AlivcLivePushStats.values()[mPushStatus.ordinal()]);
1544 Surface surface = mPreviewView != null ? mPreviewView.getHolder().getSurface() : null;
1545 int result = mNativeAlivcLivePusher.restartPush(surface,
false, 1000);
1549 AlivcLog.e(TAG,
"restart push async error");
1554 mNativeAlivcLivePusher.addPushImage(pauseImage, networkImage);
1558 reportStartPushEvent(
true,
false);
1560 startScheduleExecutor();
1569 public void reconnectPushAsync(String url)
throws IllegalStateException {
1570 AlivcLog.i(TAG,
"reconnectPushAsync");
1571 if (mNativeAlivcLivePusher == null || mAlivcLivePushConfig == null) {
1572 AlivcLog.e(TAG,
"Illegal State, you should init first");
1576 url = AlivcLiveURLTools.trimUrl(url);
1577 if (!AlivcLiveURLTools.checkPushUrl(url)) {
1581 if (mPushStatus != AlivcLivePushStats.
PUSHED && mPushStatus != AlivcLivePushStats.
PAUSED &&
1582 mPushStatus != AlivcLivePushStats.
ERROR) {
1583 AlivcLog.e(TAG,
"status error current state is " + AlivcLivePushStats.values()[mPushStatus.ordinal()]);
1587 if (isNetworkPushing()) {
1593 int result = mNativeAlivcLivePusher.reconnect(url,
false);
1595 isReconnect =
false;
1596 if (mHandler != null) {
1597 mHandler.removeMessages(MESSAGE_RECONNECT_SUCCESS);
1599 mPushStatus = AlivcLivePushStats.
PUSHED;
1601 mScreenStatus = ScreenRecordStatus.SCREEN_RECORD_NORMAL;
1604 AlivcLog.e(TAG,
"reconnect push async error");
1609 PusherReconnectEvent.Args args =
new PusherReconnectEvent.Args();
1610 Map map = getPerformanceMap();
1612 args.vutMs = getLong(map,
"mVideoDurationFromeCaptureToUpload");
1613 args.autMs = getLong(map,
"mAudioDurationFromeCaptureToUpload");
1614 if (mLiveEventReporter != null) {
1615 mLiveEventReporter.sendEvent(PusherReconnectEvent.kTopicType, PusherReconnectEvent.kTopicValue, PusherReconnectEvent.getArgsStr(args));
1626 public void stopPush() throws IllegalStateException {
1627 AlivcLog.i(TAG,
"stopPush");
1628 PusherStopPushEvent.Args args =
new PusherStopPushEvent.Args();
1629 Map map = getPerformanceMap();
1631 args.totalUploadSize = ParameterUtil.getLong(map,
"mTotalSizeOfUploadedPackets");
1632 args.totalTime = ParameterUtil.getLong(map,
"mTotalTimeOfPublishing");
1633 if (mLiveEventReporter != null) {
1634 mLiveEventReporter.sendEvent(PusherStopPushEvent.kTopicType, PusherStopPushEvent.kTopicValue, PusherStopPushEvent.getArgsStr(args));
1638 if (mNativeAlivcLivePusher == null) {
1639 AlivcLog.e(TAG,
"Illegal State, you should init first");
1642 if (mPushStatus != AlivcLivePushStats.
PREVIEWED && mPushStatus != AlivcLivePushStats.
PUSHED
1643 && mPushStatus != AlivcLivePushStats.
PAUSED && mPushStatus != AlivcLivePushStats.
ERROR) {
1644 AlivcLog.e(TAG,
"status error current state is " + AlivcLivePushStats.values()[mPushStatus.ordinal()]);
1648 int result = mNativeAlivcLivePusher.stopPush();
1650 mPushStatus = AlivcLivePushStats.
PREVIEWED;
1652 AlivcLog.e(TAG,
"stop push error");
1655 if (mPreviewView == null) {
1656 mNativeAlivcLivePusher.stopPreview();
1657 mPushStatus = AlivcLivePushStats.
INIT;
1668 public void pause() throws IllegalStateException {
1669 AlivcLog.i(TAG,
"pause");
1670 if (mNativeAlivcLivePusher == null || mAlivcLivePushConfig == null) {
1671 AlivcLog.e(TAG,
"Illegal State, you should init first");
1677 if (mPushStatus != AlivcLivePushStats.
PUSHED && mPushStatus != AlivcLivePushStats.
PAUSED
1678 && mPushStatus != AlivcLivePushStats.
PREVIEWED) {
1679 AlivcLog.e(TAG,
"status error current state is " + AlivcLivePushStats.values()[mPushStatus.ordinal()]);
1682 mPushStatus = AlivcLivePushStats.
PAUSED;
1684 mNativeAlivcLivePusher.pause();
1687 PusherPauseEvent.mLastPauseTime = System.currentTimeMillis();
1688 PusherPauseEvent.Args args =
new PusherPauseEvent.Args();
1689 Map map = getPerformanceMap();
1691 args.isPauseScreen =
false;
1692 args.totalUploadSize = ParameterUtil.getLong(map,
"mTotalSizeOfUploadedPackets");
1693 args.totalTime = ParameterUtil.getLong(map,
"mTotalTimeOfPublishing");
1694 if (mLiveEventReporter != null) {
1695 mLiveEventReporter.sendEvent(PusherPauseEvent.kTopicType, PusherPauseEvent.kTopicValue, PusherPauseEvent.getArgsStr(args));
1706 public void resume() throws IllegalStateException {
1707 AlivcLog.i(TAG,
"resume");
1708 if (mNativeAlivcLivePusher == null || mAlivcLivePushConfig == null) {
1709 AlivcLog.e(TAG,
"Illegal State, you should init first");
1715 if (mPushStatus != AlivcLivePushStats.
PAUSED && mPushStatus != AlivcLivePushStats.
ERROR) {
1716 AlivcLog.e(TAG,
"status error current state is " + AlivcLivePushStats.values()[mPushStatus.ordinal()]);
1720 mNativeAlivcLivePusher.resume(
true);
1721 PusherResumeEvent.Args args =
new PusherResumeEvent.Args();
1722 Map map = getPerformanceMap();
1725 args.isResumeScreen =
false;
1726 args.totalUploadSize = ParameterUtil.getLong(map,
"mTotalSizeOfUploadedPackets");
1727 args.totalTime = ParameterUtil.getLong(map,
"mTotalTimeOfPublishing");
1728 if (PusherPauseEvent.mLastPauseTime == 0) {
1731 args.cost = System.currentTimeMillis() - PusherPauseEvent.mLastPauseTime;
1733 if (mLiveEventReporter != null) {
1734 mLiveEventReporter.sendEvent(PusherResumeEvent.kTopicType, PusherResumeEvent.kTopicValue, PusherResumeEvent.getArgsStr(args));
1738 PusherPauseEvent.mLastPauseTime = 0;
1740 if (mNativeAlivcLivePusher.isPushing()) {
1741 mPushStatus = AlivcLivePushStats.
PUSHED;
1743 mPushStatus = AlivcLivePushStats.
PREVIEWED;
1753 public void resumeAsync() throws IllegalStateException {
1754 AlivcLog.i(TAG,
"resumeAsync");
1755 if (mNativeAlivcLivePusher == null || mAlivcLivePushConfig == null) {
1756 AlivcLog.e(TAG,
"Illegal State, you should init first");
1762 if (mPushStatus != AlivcLivePushStats.
PAUSED && mPushStatus != AlivcLivePushStats.
ERROR) {
1763 AlivcLog.e(TAG,
"status error current state is " + AlivcLivePushStats.values()[mPushStatus.ordinal()]);
1766 mPushStatus = AlivcLivePushStats.
RESUMING;
1767 mNativeAlivcLivePusher.resume(
false);
1768 PusherResumeEvent.Args args =
new PusherResumeEvent.Args();
1769 Map map = getPerformanceMap();
1772 args.isResumeScreen =
false;
1773 args.totalUploadSize = ParameterUtil.getLong(map,
"mTotalSizeOfUploadedPackets");
1774 args.totalTime = ParameterUtil.getLong(map,
"mTotalTimeOfPublishing");
1775 if (PusherPauseEvent.mLastPauseTime == 0) {
1778 args.cost = System.currentTimeMillis() - PusherPauseEvent.mLastPauseTime;
1780 if (mLiveEventReporter != null) {
1781 mLiveEventReporter.sendEvent(PusherResumeEvent.kTopicType, PusherResumeEvent.kTopicValue, PusherResumeEvent.getArgsStr(args));
1785 PusherPauseEvent.mLastPauseTime = 0;
1794 public void pauseScreenCapture() throws IllegalStateException {
1795 if (mNativeAlivcLivePusher == null) {
1796 AlivcLog.e(TAG,
"Illegal State, you should init first");
1799 if (mPushStatus != AlivcLivePushStats.
PUSHED && mPushStatus != AlivcLivePushStats.
PAUSED
1800 && mPushStatus != AlivcLivePushStats.
PREVIEWED) {
1801 AlivcLog.e(TAG,
"status error current state is " + AlivcLivePushStats.values()[mPushStatus.ordinal()]);
1804 mPushStatus = AlivcLivePushStats.
PAUSED;
1807 PusherPauseEvent.mLastPauseTime = System.currentTimeMillis();
1809 mNativeAlivcLivePusher.pauseScreenCapture();
1810 PusherPauseEvent.Args args =
new PusherPauseEvent.Args();
1811 Map map = getPerformanceMap();
1813 args.isPauseScreen =
true;
1814 args.totalUploadSize = ParameterUtil.getLong(map,
"mTotalSizeOfUploadedPackets");
1815 args.totalTime = ParameterUtil.getLong(map,
"mTotalTimeOfPublishing");
1816 if (mLiveEventReporter != null) {
1817 mLiveEventReporter.sendEvent(PusherPauseEvent.kTopicType, PusherPauseEvent.kTopicValue, PusherPauseEvent.getArgsStr(args));
1828 public void resumeScreenCapture() throws IllegalStateException {
1829 if (mNativeAlivcLivePusher == null) {
1830 AlivcLog.e(TAG,
"Illegal State, you should init first");
1833 if (mPushStatus != AlivcLivePushStats.
PAUSED) {
1834 AlivcLog.e(TAG,
"status error current state is " + AlivcLivePushStats.values()[mPushStatus.ordinal()]);
1838 mNativeAlivcLivePusher.resumeScreenCapture();
1839 PusherResumeEvent.Args args =
new PusherResumeEvent.Args();
1840 Map map = getPerformanceMap();
1843 args.isResumeScreen =
true;
1844 args.totalUploadSize = ParameterUtil.getLong(map,
"mTotalSizeOfUploadedPackets");
1845 args.totalTime = ParameterUtil.getLong(map,
"mTotalTimeOfPublishing");
1846 args.cost = System.currentTimeMillis() - PusherPauseEvent.mLastPauseTime;
1847 if (mLiveEventReporter != null) {
1848 mLiveEventReporter.sendEvent(PusherResumeEvent.kTopicType, PusherResumeEvent.kTopicValue, PusherResumeEvent.getArgsStr(args));
1852 PusherPauseEvent.mLastPauseTime = 0;
1854 if (mNativeAlivcLivePusher.isPushing()) {
1855 mPushStatus = AlivcLivePushStats.
PUSHED;
1857 mPushStatus = AlivcLivePushStats.
PREVIEWED;
1867 public void switchCamera() throws IllegalStateException {
1868 AlivcLog.i(TAG,
"switchCamera");
1869 if (mNativeAlivcLivePusher == null || mAlivcLivePushConfig == null) {
1870 AlivcLog.e(TAG,
"Illegal State, you should init first");
1873 if (mPushStatus != AlivcLivePushStats.
PREVIEWED && mPushStatus != AlivcLivePushStats.
PUSHED) {
1874 AlivcLog.e(TAG,
"status error current state is " + AlivcLivePushStats.values()[mPushStatus.ordinal()]);
1877 mNativeAlivcLivePusher.switchCamera();
1879 if (mAlivcLivePushConfig.
getCameraType() == CAMERA_TYPE_FRONT.getCameraId()) {
1886 PusherSwitchCameraEvent.Args args =
new PusherSwitchCameraEvent.Args();
1887 args.isFrontCamera = mAlivcLivePushConfig.
getCameraType() == CAMERA_TYPE_FRONT.getCameraId();
1888 if (mLiveEventReporter != null) {
1889 mLiveEventReporter.sendEvent(PusherSwitchCameraEvent.kTopicType, PusherSwitchCameraEvent.kTopicValue, PusherSwitchCameraEvent.getArgsStr(args));
1900 public void setAutoFocus(
boolean autoFocus)
throws IllegalStateException {
1901 AlivcLog.i(TAG,
"setAutoFocus auto: " + autoFocus);
1902 if (mNativeAlivcLivePusher == null) {
1903 AlivcLog.e(TAG,
"Illegal State, you should init first");
1906 if (mPushStatus != AlivcLivePushStats.
PREVIEWED && mPushStatus != AlivcLivePushStats.
PUSHED) {
1907 AlivcLog.e(TAG,
"status error current state is " + AlivcLivePushStats.values()[mPushStatus.ordinal()]);
1910 mNativeAlivcLivePusher.setCameraFocus(autoFocus, 0, 0);
1922 public void focusCameraAtAdjustedPoint(
float x,
float y,
boolean autoFocus)
throws IllegalStateException {
1923 AlivcLog.i(TAG,
"focusCameraAtAdjustedPoint x: " + x +
" y: " + y +
" auto: " + autoFocus);
1924 if (mNativeAlivcLivePusher == null) {
1925 AlivcLog.e(TAG,
"Illegal State, you should init first");
1928 if (mPushStatus != AlivcLivePushStats.
PREVIEWED && mPushStatus != AlivcLivePushStats.
PUSHED) {
1929 AlivcLog.e(TAG,
"status error current state is " + AlivcLivePushStats.values()[mPushStatus.ordinal()]);
1932 mNativeAlivcLivePusher.setCameraFocus(autoFocus, x, y);
1939 public void setExposure(
int exposure) {
1940 AlivcLog.i(TAG,
"setExposure exposure: " + exposure);
1941 if (mNativeAlivcLivePusher == null) {
1942 AlivcLog.e(TAG,
"Illegal State, you should init first");
1945 if (mPushStatus != AlivcLivePushStats.
PREVIEWED && mPushStatus != AlivcLivePushStats.
PUSHED) {
1946 AlivcLog.e(TAG,
"status error current state is " + AlivcLivePushStats.values()[mPushStatus.ordinal()]);
1949 mNativeAlivcLivePusher.setExposureCompensation(exposure);
1956 public int getCurrentExposure() {
1957 AlivcLog.i(TAG,
"getCurrentExposure");
1958 if (mNativeAlivcLivePusher == null) {
1959 AlivcLog.e(TAG,
"Illegal State, you should init first");
1962 if (mPushStatus != AlivcLivePushStats.
PREVIEWED && mPushStatus != AlivcLivePushStats.
PUSHED) {
1963 AlivcLog.e(TAG,
"status error current state is " + AlivcLivePushStats.values()[mPushStatus.ordinal()]);
1966 return mNativeAlivcLivePusher.getCurrentExposureCompensation();
1973 public int getSupportedMinExposure() {
1974 AlivcLog.i(TAG,
"getSupportedMinExposure");
1975 if (mNativeAlivcLivePusher == null) {
1976 AlivcLog.e(TAG,
"Illegal State, you should init first");
1979 if (mPushStatus != AlivcLivePushStats.
PREVIEWED && mPushStatus != AlivcLivePushStats.
PUSHED) {
1980 AlivcLog.e(TAG,
"status error current state is " + AlivcLivePushStats.values()[mPushStatus.ordinal()]);
1983 return mNativeAlivcLivePusher.getMinExposureCompensation();
1990 public int getSupportedMaxExposure() {
1991 AlivcLog.i(TAG,
"getSupportedMaxExposure");
1992 if (mNativeAlivcLivePusher == null) {
1993 AlivcLog.e(TAG,
"Illegal State, you should init first");
1996 if (mPushStatus != AlivcLivePushStats.
PREVIEWED && mPushStatus != AlivcLivePushStats.
PUSHED) {
1997 AlivcLog.e(TAG,
"status error current state is " + AlivcLivePushStats.values()[mPushStatus.ordinal()]);
2000 return mNativeAlivcLivePusher.getMaxExposureCompensation();
2004 public int setLiveMixTranscodingConfig(AlivcLiveTranscodingConfig config) {
2009 public int muteLocalCamera(
boolean mute) {
2015 public int enableSpeakerphone(
boolean enable) {
2021 public boolean isSpeakerphoneOn() {
2033 public void setZoom(
int zoom)
throws IllegalStateException {
2034 AlivcLog.i(TAG,
"setZoom zoom: " + zoom);
2035 if (mNativeAlivcLivePusher == null) {
2036 AlivcLog.e(TAG,
"Illegal State, you should init first");
2039 if (mPushStatus != AlivcLivePushStats.
PREVIEWED && mPushStatus != AlivcLivePushStats.
PUSHED) {
2040 AlivcLog.e(TAG,
"status error current state is " + AlivcLivePushStats.values()[mPushStatus.ordinal()]);
2043 mNativeAlivcLivePusher.setCameraZoom(zoom);
2053 public int getMaxZoom() throws IllegalStateException {
2054 AlivcLog.i(TAG,
"getMaxZoom");
2055 if (mNativeAlivcLivePusher == null) {
2056 AlivcLog.e(TAG,
"Illegal State, you should init first");
2059 if (mPushStatus != AlivcLivePushStats.
PREVIEWED && mPushStatus != AlivcLivePushStats.
PUSHED) {
2060 AlivcLog.e(TAG,
"status error current state is " + AlivcLivePushStats.values()[mPushStatus.ordinal()]);
2063 return mNativeAlivcLivePusher.getCameraMaxZoom();
2073 public int getCurrentZoom() throws IllegalStateException {
2074 AlivcLog.i(TAG,
"getCurrentZoom");
2075 if (mNativeAlivcLivePusher == null) {
2076 AlivcLog.e(TAG,
"Illegal State, you should init first");
2079 if (mPushStatus != AlivcLivePushStats.
PREVIEWED && mPushStatus != AlivcLivePushStats.
PUSHED) {
2080 AlivcLog.e(TAG,
"status error current state is " + AlivcLivePushStats.values()[mPushStatus.ordinal()]);
2084 return mNativeAlivcLivePusher.getCameraCurrentZoom();
2094 public void setMute(
boolean mute)
throws IllegalStateException {
2095 AlivcLog.i(TAG,
"setMute mute: " + mute);
2096 if (mNativeAlivcLivePusher == null || mAlivcLivePushConfig == null) {
2097 AlivcLog.e(TAG,
"Illegal State, you should init first");
2100 if (mPushStatus != AlivcLivePushStats.
PREVIEWED && mPushStatus != AlivcLivePushStats.
PUSHED && mPushStatus != AlivcLivePushStats.
PAUSED) {
2101 AlivcLog.e(TAG,
"status error current state is " + AlivcLivePushStats.values()[mPushStatus.ordinal()]);
2104 mNativeAlivcLivePusher.setMute(mute);
2108 if (mLiveEventReporter != null) {
2110 PusherMuteOnEvent.Args args =
new PusherMuteOnEvent.Args();
2111 mLiveEventReporter.sendEvent(PusherMuteOffEvent.kTopicType, PusherMuteOffEvent.kTopicValue, PusherMuteOnEvent.getArgsStr(args));
2113 PusherMuteOffEvent.Args args =
new PusherMuteOffEvent.Args();
2114 mLiveEventReporter.sendEvent(PusherMuteOffEvent.kTopicType, PusherMuteOffEvent.kTopicValue, PusherMuteOffEvent.getArgsStr(args));
2126 public void setFlash(
boolean flash)
throws IllegalStateException {
2127 AlivcLog.i(TAG,
"setFlash flash: " + flash);
2128 if (mNativeAlivcLivePusher == null || mAlivcLivePushConfig == null) {
2129 AlivcLog.e(TAG,
"Illegal State, you should init first");
2132 if (mPushStatus != AlivcLivePushStats.
PREVIEWED && mPushStatus != AlivcLivePushStats.
PUSHED) {
2133 AlivcLog.e(TAG,
"status error current state is " + AlivcLivePushStats.values()[mPushStatus.ordinal()]);
2136 mNativeAlivcLivePusher.setFlash(flash);
2137 mAlivcLivePushConfig.
setFlash(flash);
2139 PusherSetFlashEvent.Args args =
new PusherSetFlashEvent.Args();
2140 args.isOpen = flash;
2141 if (mLiveEventReporter != null) {
2142 mLiveEventReporter.sendEvent(PusherSetFlashEvent.kTopicType, PusherSetFlashEvent.kTopicValue, PusherSetFlashEvent.getArgsStr(args));
2153 public void setPushMirror(
boolean mirror)
throws IllegalStateException {
2154 AlivcLog.i(TAG,
"setPushMirror pushMirror: " + mirror);
2155 if (mNativeAlivcLivePusher == null) {
2156 AlivcLog.e(TAG,
"Illegal State, you should init first");
2159 if (mPushStatus != AlivcLivePushStats.
PREVIEWED && mPushStatus != AlivcLivePushStats.
PUSHED) {
2160 AlivcLog.e(TAG,
"status error current state is " + AlivcLivePushStats.values()[mPushStatus.ordinal()]);
2163 mNativeAlivcLivePusher.setPusherMirror(mirror);
2173 public void setPreviewMirror(
boolean mirror)
throws IllegalStateException {
2174 AlivcLog.i(TAG,
"setPreviewMirror previewMirror: " + mirror);
2175 if (mNativeAlivcLivePusher == null) {
2176 AlivcLog.e(TAG,
"Illegal State, you should init first");
2179 if (mPushStatus != AlivcLivePushStats.
PREVIEWED && mPushStatus != AlivcLivePushStats.
PUSHED) {
2180 AlivcLog.e(TAG,
"status error current state is " + AlivcLivePushStats.values()[mPushStatus.ordinal()]);
2183 mNativeAlivcLivePusher.setPreviewMirror(mirror);
2193 public void setTargetVideoBitrate(
int targetVideoBitrate)
throws IllegalArgumentException, IllegalStateException {
2194 AlivcLog.i(TAG,
"setTargetVideoBitrate targetVideoBitrate: " + targetVideoBitrate);
2195 if (mNativeAlivcLivePusher == null) {
2196 AlivcLog.e(TAG,
"Illegal State, you should init first");
2199 if (mPushStatus != AlivcLivePushStats.
PREVIEWED && mPushStatus != AlivcLivePushStats.
PUSHED) {
2200 AlivcLog.e(TAG,
"status error current state is " + AlivcLivePushStats.values()[mPushStatus.ordinal()]);
2203 mNativeAlivcLivePusher.setVideoBitrateRange(0, targetVideoBitrate, targetVideoBitrate);
2213 public void setMinVideoBitrate(
int minVideoBitrate)
throws IllegalArgumentException, IllegalStateException {
2214 AlivcLog.i(TAG,
"setMinVideoBitrate minVideoBitrate: " + minVideoBitrate);
2215 if (mNativeAlivcLivePusher == null) {
2216 AlivcLog.e(TAG,
"Illegal State, you should init first");
2219 if (mPushStatus != AlivcLivePushStats.
PREVIEWED && mPushStatus != AlivcLivePushStats.
PUSHED) {
2220 AlivcLog.e(TAG,
"status error current state is " + AlivcLivePushStats.values()[mPushStatus.ordinal()]);
2223 mNativeAlivcLivePusher.setVideoBitrateRange(minVideoBitrate, 0, 0);
2232 public boolean isCameraSupportAutoFocus() {
2233 AlivcLog.i(TAG,
"isCameraSupportAutoFocus");
2234 if (mNativeAlivcLivePusher == null) {
2235 AlivcLog.e(TAG,
"Illegal State, you should init first");
2238 if (mPushStatus != AlivcLivePushStats.
PREVIEWED && mPushStatus != AlivcLivePushStats.
PUSHED) {
2239 AlivcLog.e(TAG,
"status error current state is " + AlivcLivePushStats.values()[mPushStatus.ordinal()]);
2242 return mNativeAlivcLivePusher.isCameraSupportAutoFocus();
2251 public boolean isCameraSupportFlash() {
2252 AlivcLog.i(TAG,
"isCameraSupportFlash");
2254 if (mNativeAlivcLivePusher == null) {
2255 AlivcLog.e(TAG,
"Illegal State, you should init first");
2258 if (mPushStatus != AlivcLivePushStats.
PREVIEWED && mPushStatus != AlivcLivePushStats.
PUSHED) {
2259 AlivcLog.e(TAG,
"status error current state is " + AlivcLivePushStats.values()[mPushStatus.ordinal()]);
2262 return mNativeAlivcLivePusher.isCameraSupportFlash();
2272 public boolean isPushing() throws IllegalStateException {
2275 if (mNativeAlivcLivePusher != null) {
2276 return mNativeAlivcLivePusher.isPushing();
2287 public AlivcLivePushStats getCurrentStatus() {
2297 public AlivcLivePushError getLastError() {
2309 public void snapshot(
int count,
int interval, AlivcSnapshotListener listener) {
2310 mSnapshotListener = listener;
2311 if (mNativeAlivcLivePusher != null) {
2312 mNativeAlivcLivePusher.snapshot(count, interval, mInnerSnapshotListener);
2323 public boolean isNetworkPushing() throws IllegalStateException {
2326 if (mNativeAlivcLivePusher != null) {
2327 return mNativeAlivcLivePusher.isNetworkPushing();
2338 public void setLivePushErrorListener(AlivcLivePushErrorListener errorListener) {
2339 this.mPushErrorListener = errorListener;
2348 public void setLivePushInfoListener(AlivcLivePushInfoListener infoListener) {
2349 this.mPushInfoListener = infoListener;
2358 public void setLivePushNetworkListener(AlivcLivePushNetworkListener networkListner) {
2359 this.mPushNetworkListener = networkListner;
2368 public void setLivePushBGMListener(AlivcLivePushBGMListener pushBGMListener) {
2369 this.mPushBGMListener = pushBGMListener;
2378 public void setLivePushRenderContextListener(AlivcLivePusherRenderContextListener renderCtxListener) {
2379 this.mRenderContextListener = renderCtxListener;
2389 public AlivcLivePushStatsInfo getLivePushStatsInfo() throws IllegalStateException {
2392 if (mNativeAlivcLivePusher == null) {
2395 AlivcLivePushStatsInfo info =
new AlivcLivePushStatsInfo();
2396 String mapStr = mNativeAlivcLivePusher.getPerformanceInfo();
2397 if (mapStr == null ||
"".equals(mapStr)) {
2400 Map map =
new HashMap<String, String>();
2401 StringTokenizer items;
2402 for (StringTokenizer entries =
new StringTokenizer(mapStr,
"|"); entries.hasMoreTokens();
2403 map.put(items.nextToken(), items.hasMoreTokens() ? ((String) (items.nextToken())) : null)) {
2404 items =
new StringTokenizer(entries.nextToken(),
":");
2407 info.setVideoCaptureFps(getInteger(map,
"mVideoCaptureFps"));
2408 info.setAudioEncodeBitrate(getInteger(map,
"mAudioEncodeBitrate"));
2409 info.setVideoRenderFps(getInteger(map,
"mVideoRenderingFPS"));
2410 info.setAudioEncodeFps(getInteger(map,
"mAudioEncodeFps"));
2411 info.setVideoEncodeMode(AlivcEncodeModeEnum.values()[getInteger(map,
"mPresetVideoEncoderMode")]);
2412 info.setVideoEncodeBitrate(getInteger(map,
"mVideoEncodeBitrate"));
2413 info.setVideoEncodeFps(getInteger(map,
"mVideoEncodedFps"));
2414 info.setTotalFramesOfEncodedVideo(getLong(map,
"mTotalFramesOfEncodedVideo"));
2415 info.setTotalTimeOfEncodedVideo(getLong(map,
"mTotalTimeOfEncodedVideo"));
2416 info.setVideoEncodeParam(getInteger(map,
"mPresetVideoEncoderBitrate"));
2417 info.setAudioUploadBitrate(getInteger(map,
"mAudioUploadBitrate"));
2418 info.setVideoUploadBitrate(getInteger(map,
"mVideoUploadBitrate"));
2419 info.setAudioPacketsInUploadBuffer(getInteger(map,
"mAudioPacketsInBuffer"));
2420 info.setVideoPacketsInUploadBuffer(getInteger(map,
"mVideoPacketsInBuffer"));
2421 info.setVideoUploadeFps(getInteger(map,
"mVideoUploadedFps"));
2422 info.setAudioUploadFps(getInteger(map,
"mAudioUploadingPacketsPerSecond"));
2423 info.setCurrentlyUploadedVideoFramePts(getLong(map,
"mCurrentlyUploadedVideoFramePts"));
2424 info.setCurrentlyUploadedAudioFramePts(getLong(map,
"mCurrentlyUploadedAudioFramePts"));
2425 info.setPreviousVideoKeyFramePts(getLong(map,
"mPreviousKeyFramePts"));
2426 info.setLastVideoPtsInBuffer(getLong(map,
"mLastVideoFramePTSInQueue"));
2427 info.setLastAudioPtsInBuffer(getLong(map,
"mLastAudioFramePTSInQueue"));
2428 info.setTotalSizeOfUploadedPackets(getLong(map,
"mTotalSizeOfUploadedPackets"));
2429 info.setTotalTimeOfUploading(getLong(map,
"mTotalTimeOfPublishing"));
2430 info.setTotalFramesOfUploadedVideo(getLong(map,
"mTotalFramesOfVideoUploaded"));
2431 info.setTotalDurationOfDropingVideoFrames(getLong(map,
"mDropDurationOfVideoFrames"));
2432 info.setTotalTimesOfDropingVideoFrames(getLong(map,
"mTotalDroppedTimes"));
2433 info.setTotalTimesOfDisconnect(getInteger(map,
"mTotalNetworkDisconnectedTimes"));
2434 info.setTotalTimesOfReconnect(getInteger(map,
"mTotalNetworkReconnectedTimes"));
2435 info.setVideoDurationFromeCaptureToUpload(getInteger(map,
"mVideoDurationFromeCaptureToUpload"));
2436 info.setAudioDurationFromeCaptureToUpload(getInteger(map,
"mAudioDurationFromeCaptureToUpload"));
2437 info.setCurrentUploadPacketSize(getInteger(map,
"mCurrentUploadingPacketSize"));
2438 info.setMaxSizeOfVideoPacketsInBuffer(getInteger(map,
"mMaxVideoPacketSize"));
2439 info.setMaxSizeOfAudioPacketsInBuffer(getInteger(map,
"mMaxAudioPacketSize"));
2440 info.setLastVideoFramePTSInQueue(getLong(map,
"mLastVideoFramePTSInQueue"));
2441 info.setLastAudioFramePTSInQueue(getLong(map,
"mLastAudioFramePTSInQueue"));
2442 info.setAvPTSInterval(getLong(map,
"mAvPTSInterval"));
2443 info.setAudioFrameInEncodeBuffer(getInteger(map,
"mAudioFramesInEncoderQueue"));
2444 info.setVideoFramesInEncodeBuffer(getInteger(map,
"mVideoFramesInEncoderQueue"));
2445 info.setVideoFramesInRenderBuffer(getInteger(map,
"mVideoFramesInRenderQueue"));
2446 info.setVideoRenderConsumingTimePerFrame(getInteger(map,
"mVideoRenderConsumingTimePerFrame"));
2447 info.setTotalDroppedAudioFrames(getInteger(map,
"mTotalDroppedAudioFrames"));
2448 info.setRtt(getInteger(map,
"mRtt"));
2449 info.setVideoLostRate(getInteger(map,
"mVideoLostRate"));
2450 info.setAudioLostRate(getInteger(map,
"mAudioLostRate"));
2451 info.setVideoReSendBitRate(getInteger(map,
"mVideoReSendBitRate"));
2452 info.setAudioReSendBitRate(getInteger(map,
"mAudioReSendBitRate"));
2453 info.setVideoEncodingWidth(getInteger(map,
"mVideoEncodingWidth"));
2454 info.setVideoEncodingHeight(getInteger(map,
"mVideoEncodingHeight"));
2455 info.setVideoEncodingGopSize(getInteger(map,
"mVideoEncodingGopSize"));
2456 info.setAudioCapturingSampleRate(getInteger(map,
"mAudioCapturingSampleRate"));
2457 info.setAudioCaptureVolume(getInteger(map,
"mAudioCaptureVolume"));
2459 info.setCpu((
float)AliLiveInfoUtils.getCPUUsageRatio());
2460 info.setMemory(ParameterUtil.getRunningAppProcessInfo(mContext));
2461 if (!TextUtils.isEmpty(mPushUrl)) {
2462 if (mPushUrl.startsWith(AlivcLiveStreamType.EnumType.AlivcLiveStreamRtmp.getPrefix())) {
2463 info.setAlivcLivePushPublishType(AlivcLiveStreamType.EnumType.AlivcLiveStreamRtmp.getValue());
2464 }
else if (mPushUrl.startsWith(AlivcLiveStreamType.EnumType.AlivcLiveStreamRts.getPrefix())) {
2465 info.setAlivcLivePushPublishType(AlivcLiveStreamType.EnumType.AlivcLiveStreamRts.getValue());
2468 }
catch (IllegalStateException e) {
2469 e.printStackTrace();
2470 }
catch (Exception e) {
2471 e.printStackTrace();
2482 public String getPushUrl() {
2483 return AlivcLiveURLTools.getUrlWithoutParameters(mPushUrl);
2486 private void checkConfig(AlivcLivePushConfig livePushConfig)
throws IllegalStateException {
2487 if (livePushConfig == null) {
2488 throw new IllegalArgumentException(
"Invalid parameter, config is null.");
2491 if (livePushConfig.isVideoOnly() && livePushConfig.isAudioOnly()) {
2492 throw new IllegalStateException(
"cannot set video only and audio only simultaneously");
2495 if (livePushConfig.getTargetVideoBitrate() < 100 || livePushConfig.getTargetVideoBitrate() > 5000) {
2496 throw new IllegalStateException(
"video target bitrate error, Range:[100 5000]");
2498 if (livePushConfig.getMinVideoBitrate() < 100 || livePushConfig.getMinVideoBitrate() > 5000) {
2499 throw new IllegalStateException(
"video min bitrate error, Range:[100 5000]");
2501 if (livePushConfig.getInitialVideoBitrate() < livePushConfig.getMinVideoBitrate() || livePushConfig.getInitialVideoBitrate() < 100
2502 || livePushConfig.getInitialVideoBitrate() > 5000) {
2503 throw new IllegalStateException(
"init bitrate error");
2505 if (livePushConfig.getConnectRetryCount() <= 0 || livePushConfig.getConnectRetryCount() > 100) {
2506 throw new IllegalStateException(
"connect retry count error, Range:[0 100]");
2508 if (livePushConfig.getConnectRetryInterval() <= 0 || livePushConfig.getConnectRetryInterval() > 10000) {
2509 throw new IllegalStateException(
"connect retry interval error, Range:[0 10000]");
2512 if (livePushConfig.getMinFps() <= 0 || livePushConfig.getMinFps() > livePushConfig.getFps()) {
2513 throw new IllegalStateException(
"fps error");
2516 for (
int i = 0; i < livePushConfig.getWaterMarkInfos().size(); i++) {
2518 if (livePushConfig.getWaterMarkInfos().get(i).mWaterMarkCoordX > 1 || livePushConfig.getWaterMarkInfos().get(i).mWaterMarkWidth > 1
2519 || livePushConfig.getWaterMarkInfos().get(i).mWaterMarkCoordY > 1 || livePushConfig.getWaterMarkInfos().get(i).mWaterMarkHeight > 1) {
2520 throw new IllegalStateException(
"watermark param error");
2523 if (livePushConfig.getWaterMarkInfos().get(i).mWaterMarkCoordX < 0 || livePushConfig.getWaterMarkInfos().get(i).mWaterMarkWidth <= 0
2524 || livePushConfig.getWaterMarkInfos().get(i).mWaterMarkCoordY < 0 || livePushConfig.getWaterMarkInfos().get(i).mWaterMarkHeight <= 0) {
2525 throw new IllegalStateException(
"watermark param error");
2536 public void setPreviewOrientation(AlivcPreviewOrientationEnum orientation) {
2537 AlivcLog.i(TAG,
"setPreviewOrientation");
2538 if (mNativeAlivcLivePusher == null) {
2539 AlivcLog.e(TAG,
"Illegal State, you should init first");
2542 if (mPushStatus != AlivcLivePushStats.
PREVIEWED && mPushStatus != AlivcLivePushStats.
PUSHED) {
2543 AlivcLog.e(TAG,
"status error current state is " + AlivcLivePushStats.values()[mPushStatus.ordinal()]);
2547 mNativeAlivcLivePusher.setOrientaion(orientation.getOrientation());
2551 public int setAudioEffectVoiceChangeMode(AlivcLivePushAudioEffectVoiceChangeMode mode) {
2552 AlivcLog.i(TAG,
"setAudioEffectVoiceChangeMode: " + mode);
2554 if (mNativeAlivcLivePusher == null || mAlivcLivePushConfig == null) {
2555 AlivcLog.e(TAG,
"Illegal State, you should init first");
2560 AlivcLog.e(TAG,
"Sound effect can not be used on the video only mode!");
2564 return mNativeAlivcLivePusher.setNativeAudioEffectVoiceMode(mode.getValue());
2568 public int setAudioEffectReverbMode(AlivcLivePushAudioEffectReverbMode mode) {
2569 AlivcLog.i(TAG,
"setAudioEffectReverbMode: " + mode);
2571 if (mNativeAlivcLivePusher == null || mAlivcLivePushConfig == null) {
2572 AlivcLog.e(TAG,
"Illegal State, you should init first");
2577 AlivcLog.e(TAG,
"Sound effect can not be used on the video only mode!");
2581 return mNativeAlivcLivePusher.setNativeAudioEffectReverbMode(mode.getValue());
2584 private Map<String, String> getPerformanceMap() {
2585 if (mNativeAlivcLivePusher == null) {
2588 String mapStr = mNativeAlivcLivePusher.getPerformanceInfo();
2589 if (mapStr == null ||
"".equals(mapStr)) {
2592 Map map =
new HashMap<String, String>();
2593 StringTokenizer items;
2594 for (StringTokenizer entries =
new StringTokenizer(mapStr,
"|"); entries.hasMoreTokens(); map
2595 .put(items.nextToken(), items.hasMoreTokens() ? ((String) (items.nextToken())) : null)) {
2596 items =
new StringTokenizer(entries.nextToken(),
":");
2601 private String getHeartBeatInfo() {
2602 if (mNativeAlivcLivePusher == null) {
2606 String heartBeatInfo = mNativeAlivcLivePusher.getPusherInfo();
2607 heartBeatInfo +=
",cpu:" + AliLiveInfoUtils.getCPUUsageRatio();
2608 heartBeatInfo +=
",mem:" + AliLiveInfoUtils.getMemoryUsageRatio();
2610 return heartBeatInfo;
2614 public String getLiveTraceId() {
2615 if (mNativeAlivcLivePusher == null) {
2618 return mNativeAlivcLivePusher.getPusherTraceId();
2630 public void sendMessage(String info,
int repeat,
int delay,
boolean isKeyFrame) {
2631 AlivcLog.i(TAG,
"sendMessage: " + info +
", repeat:" + repeat +
", delay:" + delay +
", isKeyFrame:" + isKeyFrame);
2634 sendMessageInternal(info, repeat, delay, isKeyFrame,
false);
2635 }
catch (Exception e) {
2636 e.printStackTrace();
2640 private void sendMessageInternal(String info,
int repeat,
int delay,
boolean isKeyFrame,
boolean isGDelayInfo)
throws IllegalStateException, IllegalArgumentException {
2641 if (mNativeAlivcLivePusher == null) {
2642 AlivcLog.e(TAG,
"Illegal State, you should init first");
2645 if (!mNativeAlivcLivePusher.isPushing()) {
2646 AlivcLog.e(TAG,
"Status error, status should be PUSHED");
2649 if (TextUtils.isEmpty(info) || info.length() > MAX_CHATS) {
2650 AlivcLog.e(TAG,
"The maximum length is 4000");
2653 mNativeAlivcLivePusher.addSeiInfo(info, repeat, delay, isKeyFrame, isGDelayInfo);
2656 private int getBGMVolume() {
2663 private int getCaptureVolume() {
2667 return mCaptureVolume;
2670 private boolean getHeadSetPlugOn() {
2671 return LivePusherJNI.headSetOn;
2674 private boolean getBlueToothHeadSetOn() {
2675 if (mBluetoothHelper != null) {
2676 return mBluetoothHelper.isOnHeadsetSco();
2688 public void startBGMAsync(String path)
throws IllegalStateException {
2689 AlivcLog.i(TAG,
"startBGMAsync");
2690 if (mNativeAlivcLivePusher == null) {
2691 AlivcLog.e(TAG,
"Illegal State, you should init first");
2694 if (mPushStatus == AlivcLivePushStats.
IDLE || mPushStatus == AlivcLivePushStats.
ERROR) {
2695 AlivcLog.e(TAG,
"status error current state is " + AlivcLivePushStats.values()[mPushStatus.ordinal()]);
2699 if (mPlayStats == AlivcLivePlayStats.IDLE || mPlayStats == AlivcLivePlayStats.STOPPED) {
2700 PusherSetBGMEvent.Args args =
new PusherSetBGMEvent.Args();
2702 args.music = getBGMVolume();
2703 args.voice = getCaptureVolume();
2704 if (mLiveEventReporter != null) {
2705 mLiveEventReporter.sendEvent(PusherSetBGMEvent.kTopicType, PusherSetBGMEvent.kTopicValue, PusherSetBGMEvent.getArgsStr(args));
2710 mNativeAlivcLivePusher.stopBGM();
2711 mNativeAlivcLivePusher.startBGMAsync(path);
2720 public void stopBGMAsync() throws IllegalStateException {
2721 AlivcLog.i(TAG,
"stopBGMAsync");
2722 if (mNativeAlivcLivePusher == null) {
2723 AlivcLog.e(TAG,
"Illegal State, you should init first");
2726 if (mPlayStats == AlivcLivePlayStats.IDLE) {
2727 AlivcLog.e(TAG,
"status error current state is " + AlivcLivePlayStats.values()[mPlayStats.ordinal()]);
2731 mNativeAlivcLivePusher.stopBGM();
2732 PusherSetBGMEvent.Args args =
new PusherSetBGMEvent.Args();
2733 args.isOpen =
false;
2734 args.music = getBGMVolume();
2735 args.voice = getCaptureVolume();
2736 if (mLiveEventReporter != null) {
2737 mLiveEventReporter.sendEvent(PusherSetBGMEvent.kTopicType, PusherSetBGMEvent.kTopicValue, PusherSetBGMEvent.getArgsStr(args));
2747 public void pauseBGM() throws IllegalStateException {
2748 AlivcLog.i(TAG,
"pauseBGM");
2749 if (mNativeAlivcLivePusher == null) {
2750 AlivcLog.e(TAG,
"Illegal State, you should init first");
2753 if (mPlayStats != AlivcLivePlayStats.STARTED) {
2754 AlivcLog.e(TAG,
"status error current state is " + AlivcLivePlayStats.values()[mPlayStats.ordinal()]);
2758 mNativeAlivcLivePusher.pauseBGM();
2767 public void resumeBGM() throws IllegalStateException {
2768 AlivcLog.i(TAG,
"resumeBGM");
2769 if (mNativeAlivcLivePusher == null) {
2770 AlivcLog.e(TAG,
"Illegal State, you should init first");
2773 if (mPlayStats != AlivcLivePlayStats.PAUSED) {
2774 AlivcLog.e(TAG,
"status error current state is " + AlivcLivePlayStats.values()[mPlayStats.ordinal()]);
2778 mNativeAlivcLivePusher.resumeBGM();
2788 public void setBGMLoop(
boolean isLoop)
throws IllegalStateException {
2789 if (mNativeAlivcLivePusher != null) {
2790 mNativeAlivcLivePusher.setBGMLoop(isLoop);
2792 PusherSetBGMLoopEvent.Args args =
new PusherSetBGMLoopEvent.Args();
2793 args.value = isLoop;
2794 if (mLiveEventReporter != null) {
2795 mLiveEventReporter.sendEvent(PusherSetBGMLoopEvent.kTopicType, PusherSetBGMLoopEvent.kTopicValue, PusherSetBGMLoopEvent.getArgsStr(args));
2806 public void setBGMEarsBack(
boolean isOpen)
throws IllegalStateException {
2807 if (mNativeAlivcLivePusher != null) {
2808 mNativeAlivcLivePusher.setEarsBack(isOpen);
2810 PusherSetBGMEarsBackEvent.Args args =
new PusherSetBGMEarsBackEvent.Args();
2811 args.value = isOpen;
2812 args.bh = getBlueToothHeadSetOn() ? 1 : 0;
2813 args.eh = getHeadSetPlugOn() ? 1 : 0;
2814 if (mLiveEventReporter != null) {
2815 mLiveEventReporter.sendEvent(PusherSetBGMEarsBackEvent.kTopicType, PusherSetBGMEarsBackEvent.kTopicValue, PusherSetBGMEarsBackEvent.getArgsStr(args));
2826 public void setBGMVolume(
int volume)
throws IllegalStateException, IllegalArgumentException {
2827 if (mNativeAlivcLivePusher == null) {
2828 AlivcLog.e(TAG,
"Illegal State, you should init first");
2831 mBGMVolume = (volume > 0 && volume < 10) ? 10 : volume;
2832 mNativeAlivcLivePusher.setBackgroundMusicVolume(mBGMVolume / 10);
2842 public void setCaptureVolume(
int volume)
throws IllegalStateException, IllegalArgumentException {
2843 if (mNativeAlivcLivePusher == null) {
2844 AlivcLog.e(TAG,
"Illegal State, you should init first");
2847 mCaptureVolume = (volume > 0 && volume < 10) ? 10 : volume;
2848 mNativeAlivcLivePusher.setAudioVolume(mCaptureVolume / 10);
2858 public void setAudioDenoise(
boolean on) {
2859 AlivcLog.i(TAG,
"setAudioDenoise, " + on);
2861 if (mNativeAlivcLivePusher == null || mAlivcLivePushConfig == null) {
2862 AlivcLog.e(TAG,
"Illegal State, you should init first");
2867 AlivcLog.e(TAG,
"Audio denoise can not be used on the video only mode!");
2871 mNativeAlivcLivePusher.setAudioDenoise(on);
2875 public int startIntelligentDenoise() {
2876 AlivcLog.i(TAG,
"startIntelligentDenoise");
2877 return setIntelligentDenoiseInternal(
true);
2881 public int stopIntelligentDenoise() {
2882 AlivcLog.i(TAG,
"stopIntelligentDenoise");
2883 return setIntelligentDenoiseInternal(
false);
2886 private int setIntelligentDenoiseInternal(
boolean flag) {
2887 if (!AlivcLivePushIntelligentDenoiseManager.isFeatureWorked(mContext)) {
2888 AlivcLog.e(TAG,
"Intelligent denoise feature not worked due to the lack of native library file! " +
2889 "You can try to read the API doc to find the solution!");
2893 if (mNativeAlivcLivePusher == null || mAlivcLivePushConfig == null) {
2894 AlivcLog.e(TAG,
"Illegal State, you should init first");
2899 AlivcLog.e(TAG,
"Audio denoise can not be used on the video only mode!");
2905 result = mNativeAlivcLivePusher.startNativeIntelligentDenoise();
2907 result = mNativeAlivcLivePusher.stopNativeIntelligentDenoise();
2910 AlivcLog.i(TAG,
"setIntelligentDenoiseInternal " + flag +
", return " + result);
2921 public void setQualityMode(AlivcQualityModeEnum mode)
throws IllegalStateException {
2922 if (mNativeAlivcLivePusher == null) {
2923 AlivcLog.e(TAG,
"Illegal State, you should init first");
2926 if (AlivcQualityModeEnum.QM_CUSTOM.equals(mode)) {
2927 AlivcLog.e(TAG,
"Cannot set QM_CUSTOM dynamically");
2930 mNativeAlivcLivePusher.setQualityMode(mode.getQualityMode());
2940 public void setPreviewMode(AlivcPreviewDisplayMode mode)
throws IllegalStateException {
2941 if (mNativeAlivcLivePusher == null || mAlivcLivePushConfig == null) {
2942 AlivcLog.e(TAG,
"Illegal State, you should init first");
2946 mNativeAlivcLivePusher.setDisplayMode(mode.getPreviewDisplayMode());
2950 private void startScheduleExecutor() {
2951 if (scheduleExecutor != null) {
2954 if (scheduleExecutor == null || scheduleExecutor.isShutdown()) {
2955 scheduleExecutor =
new ScheduledThreadPoolExecutor(1,
new ThreadFactory() {
2956 private AtomicInteger atoInteger =
new AtomicInteger(0);
2959 public Thread newThread(Runnable r) {
2960 Thread t =
new Thread(r);
2961 t.setName(
"LivePusher-report-Thread " + atoInteger.getAndIncrement());
2966 scheduleExecutor.scheduleAtFixedRate(
new Runnable() {
2970 mTimeCount = mTimeCount + 1;
2971 if(mTimeCount == 5) {
2972 if (mTimeStamp != -1) {
2973 if (mExpiryTime < 60) {
2974 if (mPushNetworkListener != null) {
2976 if (!TextUtils.isEmpty(url) && !url.equals(mPushUrl)) {
2977 reconnectPushAsync(url);
2981 mExpiryTime = mExpiryTime - 5;
2985 PusherHeartBeatEvent.Args args =
new PusherHeartBeatEvent.Args();
2986 args.mediaInfo = getHeartBeatInfo();
2987 mLiveEventReporter.sendEvent(PusherHeartBeatEvent.kTopicType, PusherHeartBeatEvent.kTopicValue, PusherHeartBeatEvent.getArgsStr(args));
2990 mPushInfoListener.
onPushStatistics(getLivePusherReference(),getLivePushStatsInfo());
2992 }, 0, 2 * 1000, TimeUnit.MILLISECONDS);
2996 private int[] getImageWidthHeight(String path) {
2997 BitmapFactory.Options options =
new BitmapFactory.Options();
2999 options.inJustDecodeBounds =
true;
3001 Bitmap bitmap = BitmapFactory.decodeFile(path, options);
3002 }
catch (Exception e) {
3003 return new int[]{0, 0};
3006 return new int[]{options.outWidth, options.outHeight};
3010 private void addWaterMark() {
3011 if (mAlivcLivePushConfig == null) {
3012 AlivcLog.e(TAG,
"Illegal State, you should init first");
3015 ArrayList<WaterMarkInfo> waterMarkInfos = mAlivcLivePushConfig.getWaterMarkInfos();
3016 int size = waterMarkInfos.size();
3017 for (
int i = 0; i < size; i++) {
3018 addWaterMark(waterMarkInfos.get(i).mWaterMarkPath, waterMarkInfos.get(i).mWaterMarkCoordX, waterMarkInfos.get(i).mWaterMarkCoordY,
3019 waterMarkInfos.get(i).mWaterMarkWidth);
3023 private void stop5Interval() {
3024 if (scheduleExecutor != null && !scheduleExecutor.isShutdown()) {
3025 scheduleExecutor.shutdown();
3027 scheduleExecutor = null;
3031 private void rtsDownToRtmp() {
3032 AlivcLog.w(TAG,
"rts downgrade to rtmp");
3033 if (TextUtils.isEmpty(mPushUrl) || !mPushUrl.startsWith(AlivcLiveStreamType.EnumType.AlivcLiveStreamRts.getPrefix())) {
3037 AlivcLog.w(TAG,
"pre url: " + mPushUrl);
3038 mPushUrl = mPushUrl.replaceFirst(AlivcLiveStreamType.EnumType.AlivcLiveStreamRts.getPrefix(), AlivcLiveStreamType.EnumType.AlivcLiveStreamRtmp.getPrefix());
3039 AlivcLog.w(TAG,
"after url: " + mPushUrl);
3040 mPushStatus = AlivcLivePushStats.
ERROR;
3043 if (mNativeAlivcLivePusher != null) {
3044 mNativeAlivcLivePusher.release();
3045 mNativeAlivcLivePusher.init();
3048 startPushAsync(mPushUrl);
3051 private void reportStartPushEvent(
boolean isRestart,
boolean isSync) {
3052 PusherStartPushEvent.Args args =
new PusherStartPushEvent.Args();
3053 Map map = getPerformanceMap();
3056 args.vutMs = getInteger(map,
"mVideoDurationFromeCaptureToUpload");
3057 args.autMs = getInteger(map,
"mAudioDurationFromeCaptureToUpload");
3058 args.resolution = mAlivcLivePushConfig.
getResolution().toString().substring(11);
3059 args.st = mAlivcLivePushConfig.
getAudioChannels() == 1 ?
"single" :
"dual";
3063 args.wc = mAlivcLivePushConfig.getWaterMarkInfos().size();
3065 args.fps = mAlivcLivePushConfig.
getFps();
3072 args.flash = mAlivcLivePushConfig.
isFlash();
3080 mLiveEventReporter.sendEvent(PusherRestartPushEvent.kTopicType, PusherRestartPushEvent.kTopicValue, PusherRestartPushEvent.getArgsStr(args));
3082 mLiveEventReporter.sendEvent(PusherStartPushEvent.kTopicType, PusherStartPushEvent.kTopicValue, PusherStartPushEvent.getArgsStr(args));
3087 private BroadcastReceiver mHeadsetPlugReceiver =
new BroadcastReceiver() {
3090 public void onReceive(Context context, Intent intent) {
3092 String action = intent.getAction();
3093 if (AudioManager.ACTION_AUDIO_BECOMING_NOISY.equals(action)) {
3094 AlivcLog.d(
"BluetoothHeadsetUtils",
"ACTION_AUDIO_BECOMING_NOISY headset out");
3096 mAudioManager.setMode(AudioManager.STREAM_VOICE_CALL);
3097 mAudioManager.setSpeakerphoneOn(
true);
3099 LivePusherJNI.headSetOn =
false;
3100 if (mNativeAlivcLivePusher != null) {
3101 mNativeAlivcLivePusher.setHeadSet(
false);
3103 }
else if (
"android.intent.action.HEADSET_PLUG".equals(action)) {
3104 if (intent.hasExtra(
"state")) {
3105 if (intent.getIntExtra(
"state", 0) == 0) {
3106 AlivcLog.d(
"BluetoothHeadsetUtils",
"headset out");
3108 mAudioManager.setMode(AudioManager.STREAM_VOICE_CALL);
3109 mAudioManager.setSpeakerphoneOn(
true);
3111 if (LivePusherJNI.headSetOn) {
3112 LivePusherJNI.headSetOn =
false;
3113 if (mNativeAlivcLivePusher != null) {
3114 mNativeAlivcLivePusher.setHeadSet(
false);
3117 }
else if (intent.getIntExtra(
"state", 0) == 1) {
3119 AlivcLog.d(
"BluetoothHeadsetUtils",
"headset in");
3120 mAudioManager.setSpeakerphoneOn(
false);
3121 LivePusherJNI.headSetOn =
true;
3122 if (mNativeAlivcLivePusher != null) {
3123 mNativeAlivcLivePusher.setHeadSet(
true);
3132 private BroadcastReceiver mTelephoneReceiver =
new BroadcastReceiver() {
3134 public void onReceive(Context context, Intent intent) {
3135 if (intent.getAction().equals(Intent.ACTION_NEW_OUTGOING_CALL)) {
3138 if (manager == null) {
3139 if (Looper.myLooper() == null) {
3142 manager = (TelephonyManager) context.getSystemService(Service.TELEPHONY_SERVICE);
3143 manager.listen(
new PhoneStateListener() {
3145 public void onCallStateChanged(
int state, String incomingNumber) {
3146 super.onCallStateChanged(state, incomingNumber);
3148 case TelephonyManager.CALL_STATE_IDLE:
3150 AlivcLog.i(TAG,
"PHONE: CALL_STATE_IDLE");
3151 if (mNativeAlivcLivePusher != null) {
3152 mNativeAlivcLivePusher.setMute(
false);
3155 case TelephonyManager.CALL_STATE_OFFHOOK:
3157 AlivcLog.i(TAG,
"PHONE: CALL_STATE_OFFHOOK");
3158 if (mNativeAlivcLivePusher != null) {
3159 mNativeAlivcLivePusher.setMute(
true);
3162 case TelephonyManager.CALL_STATE_RINGING:
3164 AlivcLog.i(TAG,
"PHONE: CALL_STATE_RINGING");
3165 if (mNativeAlivcLivePusher != null) {
3166 mNativeAlivcLivePusher.setMute(
true);
3173 }, PhoneStateListener.LISTEN_CALL_STATE);
3180 private void registerHeadsetPlugReceiver() {
3182 IntentFilter intentFilter =
new IntentFilter();
3183 intentFilter.addAction(
"android.intent.action.HEADSET_PLUG");
3184 mContext.registerReceiver(mHeadsetPlugReceiver, intentFilter);
3186 IntentFilter intentFilter1 =
new IntentFilter(AudioManager.ACTION_AUDIO_BECOMING_NOISY);
3187 mContext.registerReceiver(mHeadsetPlugReceiver, intentFilter1);
3190 IntentFilter intentTelephony =
new IntentFilter();
3191 intentTelephony.addAction(
"android.intent.action.PHONE_STATE");
3192 mContext.registerReceiver(mTelephoneReceiver, intentTelephony);
3194 registeredCallback =
true;
3197 private void LogWhenGoBackOrFront(Application app,
boolean bind) {
3199 mAppFrontBackHelper =
new AppFrontBackHelper();
3200 mAppFrontBackHelper.bindApplication(app,
new AppFrontBackHelper.OnAppStatusListener() {
3202 public void onFront() {
3203 if (mNativeAlivcLivePusher != null) {
3204 AlivcLog.i(TAG,
"applicationWillBecomeActive");
3205 mNativeAlivcLivePusher.setAppBackgroundState(
false);
3210 public void onBack() {
3211 if (mNativeAlivcLivePusher != null) {
3212 AlivcLog.i(TAG,
"applicationWillResignActive");
3213 mNativeAlivcLivePusher.setAppBackgroundState(
true);
3218 if(mAppFrontBackHelper != null){
3219 mAppFrontBackHelper.unBindApplication(app);
3220 mAppFrontBackHelper = null;
3225 private void getNetworkTime() {
3226 new ScheduledThreadPoolExecutor(1,
new ThreadFactory() {
3227 private AtomicInteger atoInteger =
new AtomicInteger(0);
3230 public Thread newThread(Runnable r) {
3231 Thread t =
new Thread(r);
3232 t.setName(
"LivePusher-NTP-Time-Thread " + atoInteger.getAndIncrement());
3235 }).execute(
new Runnable() {
3238 for (
int i = 0; i < 3; i++) {
3239 mTimeStamp = getTimeFromNtpServer(
"time.pool.aliyun.com");
3240 if (mTimeStamp > 0) {
3241 mTimeStamp = mTimeStamp / 1000;
3245 if (mTimeStamp < 0) {
3246 mTimeStamp = System.currentTimeMillis() / 1000;
3248 if (getTimestamp(mPushUrl) != -1) {
3249 mExpiryTime = (int) ((getTimestamp(mPushUrl) - mTimeStamp));
3255 private long getTimeFromNtpServer(String ntpHost) {
3256 AlivcLog.d(
"",
"get time from " + ntpHost);
3257 SntpClient client =
new SntpClient();
3258 boolean isSuccessful = client.requestTime(ntpHost, NTP_TIME_OUT_MILLISECOND);
3260 return client.getNtpTime();
3275 public void addWaterMark(String path,
float x,
float y,
float width) {
3276 if (mNativeAlivcLivePusher == null || mAlivcLivePushConfig == null) {
3277 AlivcLog.e(TAG,
"Illegal State, you should init first");
3280 int[] widthHeight = getImageWidthHeight(path);
3281 if (mWatermarkCount >= AlivcLiveMaxWatermarkCount || widthHeight == null || widthHeight[0] == 0 || widthHeight[1] == 0) {
3286 float h = width * widthHeight[1] / widthHeight[0];
3287 if (mAlivcLivePushConfig.
getPreviewOrientation() == AlivcPreviewOrientationEnum.ORIENTATION_LANDSCAPE_HOME_LEFT.getOrientation() ||
3288 mAlivcLivePushConfig.
getPreviewOrientation() == AlivcPreviewOrientationEnum.ORIENTATION_LANDSCAPE_HOME_RIGHT.getOrientation()) {
3294 mNativeAlivcLivePusher.addWaterMark(path, w, h, x + w / 2, y + h / 2);
3304 public void setWatermarkVisible(
boolean visible) {
3305 if (mNativeAlivcLivePusher == null) {
3306 AlivcLog.e(TAG,
"Illegal State, you should init first");
3309 if (mPushStatus != AlivcLivePushStats.
PREVIEWED) {
3310 AlivcLog.e(TAG,
"status error current state is " + AlivcLivePushStats.values()[mPushStatus.ordinal()]);
3313 if (mWatermarkCount <= 0) {
3316 mNativeAlivcLivePusher.setWaterMarkVisible(visible);
3327 public int startCamera(SurfaceView surfaceView)
throws IllegalStateException {
3328 if (mNativeAlivcLivePusher == null || mAlivcLivePushConfig == null) {
3329 AlivcLog.e(TAG,
"Please execute init first ");
3333 AlivcLog.e(TAG,
"Not in ScreenCapture Mode");
3336 if (!ScreenRecordStatus.SCREEN_RECORD_NORMAL.equals(mScreenStatus)) {
3337 AlivcLog.e(TAG,
"you should start push screen first");
3340 Surface surface = null;
3341 if (surfaceView != null) {
3342 surface = surfaceView.getHolder().getSurface();
3344 int ret = mNativeAlivcLivePusher.startCamera(surface);
3345 mScreenStatus = ScreenRecordStatus.SCREEN_RECORD_CAMERA_START;
3355 public void setScreenOrientation(
int orientation) {
3356 if (mNativeAlivcLivePusher == null || mAlivcLivePushConfig == null) {
3357 AlivcLog.e(TAG,
"Please execute init first ");
3361 AlivcLog.e(TAG,
"Not in ScreenCapture Mode");
3364 mNativeAlivcLivePusher.setScreenOrientation(orientation);
3371 public void stopCamera() {
3372 if (mNativeAlivcLivePusher == null || mAlivcLivePushConfig == null) {
3373 AlivcLog.e(TAG,
"Please execute init first ");
3377 AlivcLog.e(TAG,
"Not in ScreenCapture Mode");
3380 mNativeAlivcLivePusher.stopCamera();
3381 mScreenStatus = ScreenRecordStatus.SCREEN_RECORD_NORMAL;
3394 public int startCameraMix(
float x,
float y,
float w,
float h) {
3395 if (mNativeAlivcLivePusher == null || mAlivcLivePushConfig == null) {
3396 AlivcLog.e(TAG,
"Please execute init first ");
3400 AlivcLog.e(TAG,
"Not in ScreenCapture Mode");
3403 if (!mScreenStatus.equals(ScreenRecordStatus.SCREEN_RECORD_CAMERA_START)) {
3404 AlivcLog.e(TAG,
"You should start camera first");
3407 int ret = mNativeAlivcLivePusher.startCameraMix(x, y, w, h);
3408 mScreenStatus = ScreenRecordStatus.SCREEN_RECORD_CAMERA_MIX_START;
3416 public void stopCameraMix() {
3417 if (mNativeAlivcLivePusher == null || mAlivcLivePushConfig == null) {
3418 AlivcLog.e(TAG,
"Please execute init first ");
3422 AlivcLog.e(TAG,
"Not in ScreenCapture Mode");
3425 mNativeAlivcLivePusher.stopCameraMix();
3426 mScreenStatus = ScreenRecordStatus.SCREEN_RECORD_CAMERA_START;
3435 public void changeResolution(AlivcResolutionEnum resolutionEnum) {
3436 if (mNativeAlivcLivePusher == null) {
3437 AlivcLog.e(TAG,
"Please execute init first!");
3440 if (mPushStatus != AlivcLivePushStats.
PUSHED && mPushStatus != AlivcLivePushStats.
PREVIEWED && mPushStatus != AlivcLivePushStats.
INIT) {
3441 AlivcLog.e(TAG,
"changeResolution can only be called in inited or previewed status");
3444 mNativeAlivcLivePusher.changeResolution(AlivcResolutionEnum.GetResolutionWidth(resolutionEnum), AlivcResolutionEnum.GetResolutionHeight(resolutionEnum));
3447 public int mixStreamRequireMain(
int vid,
boolean require) {
3448 if (mNativeAlivcLivePusher == null) {
3451 return mNativeAlivcLivePusher.mixStreamRequireMain(vid, require);
3454 public int mixStreamChangePosition(
int vid,
float x,
float y,
float w,
float h) {
3455 if (mNativeAlivcLivePusher == null) {
3458 return mNativeAlivcLivePusher.mixStreamChangePosition(vid, x, y, w, h);
3461 public void mixStreamMirror(
int vid,
boolean mirror) {
3462 if (mNativeAlivcLivePusher == null) {
3465 mNativeAlivcLivePusher.setMixStreamMirror(vid, mirror);
3481 public int addMixVideo(AlivcImageFormat format,
int width,
int height,
int rotation,
float displayX,
float displayY,
float displayW,
float displayH,
boolean adjustHeight) {
3482 if (mNativeAlivcLivePusher == null) {
3485 return mNativeAlivcLivePusher.addMixVideo(format.getAlivcImageFormat(), width, height, rotation, displayX, displayY, displayW, displayH, adjustHeight);
3493 public void removeMixVideo(
int handler) {
3494 if (mNativeAlivcLivePusher == null) {
3497 mNativeAlivcLivePusher.removeMixVideo(handler);
3512 public void inputMixTexture(
int handler,
int texture,
int width,
int height,
long pts,
int rotation) {
3513 if (mNativeAlivcLivePusher == null) {
3516 mNativeAlivcLivePusher.inputMixTexture(handler, texture, width, height, pts, rotation);
3532 public void inputMixVideoPtr(
int handler,
long dataptr,
int width,
int height,
int stride,
int size,
long pts,
int rotation) {
3533 if (mNativeAlivcLivePusher == null) {
3536 mNativeAlivcLivePusher.inputMixVideoPtr(handler, dataptr, width, height, stride, size, pts, rotation);
3552 public void inputMixVideoData(
int handler, byte[] data,
int width,
int height,
int stride,
int size,
long pts,
int rotation) {
3553 if (mNativeAlivcLivePusher == null) {
3556 mNativeAlivcLivePusher.inputMixVideoData(handler, data, width, height, stride, size, pts, rotation);
3567 public int addMixAudio(
int channels, AlivcSoundFormat format,
int audioSample) {
3568 if (mNativeAlivcLivePusher == null) {
3571 return mNativeAlivcLivePusher.addMixAudio(channels, format.getAlivcSoundFormat(), audioSample);
3579 public void removeMixAudio(
int handler) {
3580 if (mNativeAlivcLivePusher == null) {
3583 mNativeAlivcLivePusher.removeMixAudio(handler);
3596 public boolean inputMixAudioPtr(
int handler,
long dataptr,
int size,
long pts) {
3597 if (mNativeAlivcLivePusher == null) {
3600 return mNativeAlivcLivePusher.inputMixAudioPtr(handler, dataptr, size, pts);
3612 public boolean inputMixAudioData(
int handler, byte[] data,
int size,
long pts) {
3613 if (mNativeAlivcLivePusher == null) {
3616 return mNativeAlivcLivePusher.inputMixAudioData(handler, data, size, pts);
3631 public void inputStreamVideoPtr(
long dataptr,
int width,
int height,
int stride,
int size,
long pts,
int rotation) {
3632 if (mNativeAlivcLivePusher == null) {
3635 mNativeAlivcLivePusher.inputStreamVideoPtr(dataptr, width, height, stride, size, pts, rotation);
3650 public void inputStreamTexture(
int textureId,
int width,
int height,
int stride,
long pts,
int rotation,
long extra) {
3651 if (mNativeAlivcLivePusher == null) {
3654 mNativeAlivcLivePusher.inputStreamTexture(textureId, width, height, stride, pts, rotation, extra);
3669 public void inputStreamVideoData(byte[] data,
int width,
int height,
int stride,
int size,
long pts,
int rotation) {
3670 if (mNativeAlivcLivePusher == null) {
3673 mNativeAlivcLivePusher.inputStreamVideoData(data, width, height, stride, size, pts, rotation);
3685 public void inputStreamAudioPtr(
long dataPtr,
int size,
int sampleRate,
int channels,
long pts) {
3686 if (mNativeAlivcLivePusher == null) {
3689 mNativeAlivcLivePusher.inputStreamAudioPtr(dataPtr, size, sampleRate, channels, pts);
3701 public void inputStreamAudioData(byte[] data,
int size,
int sampleRate,
int channels,
long pts) {
3702 if (mNativeAlivcLivePusher == null) {
3705 mNativeAlivcLivePusher.inputStreamAudioData(data, size, sampleRate, channels, pts);
3719 public int addDynamicsAddons(String path,
float x,
float y,
float w,
float h)
throws IllegalArgumentException {
3720 if (mNativeAlivcLivePusher == null) {
3723 if (x < TEXTURE_RANGE_MIN || x > TEXTURE_RANGE_MAX || y < TEXTURE_RANGE_MIN || y > TEXTURE_RANGE_MAX || w < TEXTURE_RANGE_MIN || w > TEXTURE_RANGE_MAX || h < TEXTURE_RANGE_MIN || h > TEXTURE_RANGE_MAX) {
3724 AlivcLog.e(TAG,
"addDynamicsAddons failed! x, y, w, h should in range [0~1.0f]");
3727 if (mDynamicAddsonCount >= MAX_DYNAMIC_ADDSON_COUNT) {
3730 mDynamicAddsonCount++;
3731 return mNativeAlivcLivePusher.addDynamicsAddons(path, System.currentTimeMillis() * 1000, 0, x, y, w, h, 0,
false);
3740 public void removeDynamicsAddons(
int id) {
3741 if (mNativeAlivcLivePusher == null) {
3744 mDynamicAddsonCount--;
3745 mNativeAlivcLivePusher.removeDynamicsAddons(
id);
3748 public void setMainStreamPosition(
float startX,
float startY,
float w,
float h) {
3749 if (mNativeAlivcLivePusher == null) {
3752 mNativeAlivcLivePusher.setMainStreamPosition(startX, startY, w, h);
3755 private String getFormatString(String
string) {
3757 int index =
string.indexOf(AUTH_KEY);
3759 String temp =
string.substring(index);
3760 if (temp.indexOf(
"-") > 0) {
3761 result = temp.substring(AUTH_KEY.length(), temp.indexOf(
"-"));
3763 result = temp.substring(AUTH_KEY.length());
3769 private int getTimestamp(String
string) {
3771 String tempStamp = getFormatString(
string);
3772 if (tempStamp.length() < 10) {
3775 if (TextUtils.isDigitsOnly(tempStamp)) {
3776 return new Long(Long.valueOf(tempStamp)).intValue();
3782 private AlivcSnapshotListener mInnerSnapshotListener =
new AlivcSnapshotListener() {
3784 public void onSnapshot(
final Bitmap bmp) {
3785 if (mSnapshotListener != null) {
3786 mThreadPoolExecutor.execute(
new Runnable() {
AlivcResolutionEnum getResolution()
void onNetworkPoor(AlivcLivePusher pusher)
AlivcLivePushLogLevelWarn
void onReconnectStart(AlivcLivePusher pusher)
int getPreviewOrientation()
void onFirstFramePreviewed(AlivcLivePusher pusher)
String getPausePushImage()
boolean isPreviewMirror()
void onPushPaused(AlivcLivePusher pusher)
String getNetworkPoorPushImage()
void onNetworkRecovery(AlivcLivePusher pusher)
void onConnectFail(AlivcLivePusher pusher)
boolean isExternMainStream()
void onPushStarted(AlivcLivePusher pusher)
void onConnectionLost(AlivcLivePusher pusher)
void onReconnectFail(AlivcLivePusher pusher)
void setFlash(boolean flash)
void onPreviewStarted(AlivcLivePusher pusher)
void onPushRestarted(AlivcLivePusher pusher)
void onDropFrame(AlivcLivePusher pusher, int beforeCount, int afterCount)
String onPushURLAuthenticationOverdue(AlivcLivePusher pusher)
int getTargetVideoBitrate()
void setCameraType(AlivcLivePushCameraTypeEnum cameraType)
void onReconnectSucceed(AlivcLivePusher pusher)
void onPushStopped(AlivcLivePusher pusher)
void onFirstFramePushed(AlivcLivePusher pusher)
int getConnectRetryCount()
void onSDKError(AlivcLivePusher livePusher, AlivcLivePushError error)
void onAdjustFps(AlivcLivePusher pusher, int currentFps, int targetFps)
void onSnapshot(Bitmap bitmap)
int getConnectRetryInterval()
void onSystemError(AlivcLivePusher livePusher, AlivcLivePushError error)
Intent getMediaProjectionPermissionResultData()
void onPushStatistics(AlivcLivePusher pusher, AlivcLivePushStatsInfo statistics)
int getInitialVideoBitrate()
void onSendDataTimeout(AlivcLivePusher pusher)
void onAdjustBitrate(AlivcLivePusher pusher, int currentBitrate, int targetBitrate)
void onPreviewStopped(AlivcLivePusher pusher)
void onPushResumed(AlivcLivePusher pusher)
void onSendMessage(AlivcLivePusher pusher)
AlivcAudioSampleRateEnum getAudioSampleRate()
void onProgress(long progress, long duration)
void onPacketsLost(AlivcLivePusher pusher)
AlivcEncodeModeEnum getVideoEncodeMode()