AliVCSDK  4.5.1
阿里云音视频SDK,为视频开发者提供一站式接入服务
AlivcLivePusherBasicImpl.java
1 package com.alivc.live.pusher;
2 
6 import static com.alivc.live.pusher.AlivcLivePushError.ALIVC_FRAMEWORK_RENDER_FIRST_FRAME_PREVIEWED;
7 import static com.alivc.live.pusher.AlivcLivePushError.ALIVC_LIVE_ERROR_SYSTEM_RTMP_OOM;
8 import static com.alivc.live.pusher.AlivcLivePushError.ALIVC_PUSHER_ERROR_BGM_OPEN_FAILED;
9 import static com.alivc.live.pusher.AlivcLivePushError.ALIVC_PUSHER_ERROR_BGM_TIMEOUT;
10 import static com.alivc.live.pusher.AlivcLivePushError.ALIVC_PUSHER_ERROR_SDK_LIVE_PUSH_LOW_PERFORMANCE;
11 import static com.alivc.live.pusher.AlivcLivePushError.ALIVC_PUSHER_ERROR_SDK_LIVE_PUSH_NETWORK_TOO_POOR;
12 import static com.alivc.live.pusher.AlivcLivePushError.ALIVC_PUSHER_ERROR_SDK_PUSH_CONNECT;
13 import static com.alivc.live.pusher.AlivcLivePushError.ALIVC_PUSHER_ERROR_SDK_PUSH_CONNECT_STREAM;
14 import static com.alivc.live.pusher.AlivcLivePushError.ALIVC_PUSHER_ERROR_SDK_PUSH_RECONNECT_FAIL;
15 import static com.alivc.live.pusher.AlivcLivePushError.ALIVC_PUSHER_ERROR_SDK_PUSH_RTS_DOWN_TO_RTMP;
16 import static com.alivc.live.pusher.AlivcLivePushError.ALIVC_PUSHER_ERROR_SDK_PUSH_SEND_DATA_TIMEOUT;
17 import static com.alivc.live.pusher.AlivcLivePushError.ALIVC_PUSHER_ERROR_SDK_PUSH_SETUPURL;
18 import static com.alivc.live.pusher.AlivcLivePushError.ALIVC_PUSHER_ERROR_SDK_PUSH_START_PUSH_TIMEOUT;
19 import static com.alivc.live.pusher.AlivcLivePushError.getErrorByCode;
21 import static com.alivc.live.pusher.LivePushNotification.ALIVC_PUSHER_EVENT_BGM_COMPLETED;
22 import static com.alivc.live.pusher.LivePushNotification.ALIVC_PUSHER_EVENT_BGM_OPEN_SUCCESS;
23 import static com.alivc.live.pusher.LivePushNotification.ALIVC_PUSHER_EVENT_BGM_PAUSE_SUCCESS;
24 import static com.alivc.live.pusher.LivePushNotification.ALIVC_PUSHER_EVENT_BGM_PROGRESS;
25 import static com.alivc.live.pusher.LivePushNotification.ALIVC_PUSHER_EVENT_BGM_RESUME_SUCCESS;
26 import static com.alivc.live.pusher.LivePushNotification.ALIVC_PUSHER_EVENT_BGM_STOP_SUCCESS;
27 import static com.alivc.live.pusher.LivePushNotification.ALIVC_PUSHER_EVENT_CAPTURE_CLOSE_CAMERA_SUCCESS;
29 import static com.alivc.live.pusher.LivePushNotification.ALIVC_PUSHER_EVENT_CAPTURE_OPEN_CAMERA_SUCCESS;
30 import static com.alivc.live.pusher.LivePushNotification.ALIVC_PUSHER_EVENT_CAPTURE_OPEN_MIC_SUCCESS;
32 import static com.alivc.live.pusher.LivePushNotification.ALIVC_PUSHER_EVENT_GENERAL_MONITOR;
35 import static com.alivc.live.pusher.LivePushNotification.ALIVC_PUSHER_EVENT_NATIVE_LIVE_PUSH_CHANGE_FPS;
39 import static com.alivc.live.pusher.LivePushNotification.ALIVC_PUSHER_EVENT_NATIVE_LIVE_PUSH_INIT_SUCCESS;
43 import static com.alivc.live.pusher.LivePushNotification.ALIVC_PUSHER_EVENT_NATIVE_LIVE_PUSH_PUSH_PAUSED;
45 import static com.alivc.live.pusher.LivePushNotification.ALIVC_PUSHER_EVENT_NATIVE_LIVE_PUSH_PUSH_RESUMED;
46 import static com.alivc.live.pusher.LivePushNotification.ALIVC_PUSHER_EVENT_PUSH_CONNECTION_LOST;
47 import static com.alivc.live.pusher.LivePushNotification.ALIVC_PUSHER_EVENT_PUSH_CRASH;
48 import static com.alivc.live.pusher.LivePushNotification.ALIVC_PUSHER_EVENT_PUSH_DELAY_INFO;
49 import static com.alivc.live.pusher.LivePushNotification.ALIVC_PUSHER_EVENT_PUSH_DROP_FRAME;
50 import static com.alivc.live.pusher.LivePushNotification.ALIVC_PUSHER_EVENT_PUSH_MEDIAINFO;
51 import static com.alivc.live.pusher.LivePushNotification.ALIVC_PUSHER_EVENT_PUSH_NETWORK_RECOVERY;
52 import static com.alivc.live.pusher.LivePushNotification.ALIVC_PUSHER_EVENT_PUSH_RECONNECT_START;
53 import static com.alivc.live.pusher.LivePushNotification.ALIVC_PUSHER_EVENT_PUSH_RECONNECT_SUCCESS;
54 import static com.alivc.live.pusher.LivePushNotification.ALIVC_PUSHER_EVENT_PUSH_SENDED_FIRST_AV;
55 import static com.alivc.live.pusher.LivePushNotification.ALIVC_PUSHER_EVENT_PUSH_SENDED_SEI;
56 import static com.alivc.live.pusher.LivePushNotification.ALIVC_PUSHER_EVENT_PUSH_STARTED;
57 import static com.alivc.live.pusher.LivePushNotification.ALIVC_PUSHER_EVENT_PUSH_STOPED;
58 import static com.alivc.live.utils.ParameterUtil.getInteger;
59 import static com.alivc.live.utils.ParameterUtil.getLong;
60 
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;
80 
84 import com.alivc.component.player.BGMPlayerJNI;
85 import com.alivc.live.annotations.AlivcLiveStreamType;
87 import com.alivc.live.pusher.logreport.PusherAdjustFpsEvent;
89 import com.alivc.live.pusher.logreport.PusherDelayInfoEvent;
90 import com.alivc.live.pusher.logreport.PusherDropFrameEvent;
92 import com.alivc.live.pusher.logreport.PusherHeartBeatEvent;
93 import com.alivc.live.pusher.logreport.PusherLicenseEvent;
94 import com.alivc.live.pusher.logreport.PusherMuteOffEvent;
95 import com.alivc.live.pusher.logreport.PusherMuteOnEvent;
96 import com.alivc.live.pusher.logreport.PusherNetworkPoorEvent;
98 import com.alivc.live.pusher.logreport.PusherOnPauseEvent;
99 import com.alivc.live.pusher.logreport.PusherOnRestartEvent;
100 import com.alivc.live.pusher.logreport.PusherOnResumeEvent;
101 import com.alivc.live.pusher.logreport.PusherPauseEvent;
102 import com.alivc.live.pusher.logreport.PusherReconnectEvent;
106 import com.alivc.live.pusher.logreport.PusherRestartPushEvent;
107 import com.alivc.live.pusher.logreport.PusherResumeEvent;
108 import com.alivc.live.pusher.logreport.PusherSDKCrashEvent;
109 import com.alivc.live.pusher.logreport.PusherSdkErrorEvent;
112 import com.alivc.live.pusher.logreport.PusherSetBGMEvent;
113 import com.alivc.live.pusher.logreport.PusherSetBGMLoopEvent;
114 import com.alivc.live.pusher.logreport.PusherSetFlashEvent;
115 import com.alivc.live.pusher.logreport.PusherStartPreviewEvent;
116 import com.alivc.live.pusher.logreport.PusherStartPushEvent;
119 import com.alivc.live.pusher.logreport.PusherStopPreviewEvent;
120 import com.alivc.live.pusher.logreport.PusherStopPushEvent;
122 import com.alivc.live.pusher.logreport.PusherSwitchCameraEvent;
123 import com.alivc.live.pusher.logreport.PusherSystemErrorEvent;
124 import com.alivc.live.pusher.logreport.core.AliLiveInfoUtils;
125 import com.alivc.live.pusher.logreport.core.LiveEventReporter;
128 import com.alivc.live.utils.AlivcLiveURLTools;
129 import com.alivc.live.utils.AppFrontBackHelper;
130 import com.alivc.live.utils.BluetoothHeadsetUtils;
131 import com.alivc.live.utils.ParameterUtil;
132 import com.alivc.live.utils.SntpClient;
133 
134 import org.json.JSONException;
135 import org.json.JSONObject;
136 import org.webrtc.utils.AlivcLog;
137 
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;
151 
286 @CalledByNative
287 class AlivcLivePusherBasicImpl implements ILivePusher {
288  private static final String TAG = "AlivcLivePusherBasicImpl";
289 
290  protected enum ScreenRecordStatus {
291  SCREEN_RECORD_NONE,
292  SCREEN_RECORD_NORMAL,
293  SCREEN_RECORD_CAMERA_START,
294  SCREEN_RECORD_CAMERA_MIX_START,
295  }
296 
297  private static LivePusherJNI mNativeAlivcLivePusher = null;
298  private WeakReference<AlivcLivePusher> mWeakAlivcLivePusher = null;
299 
300  private AlivcLivePushStats mPushStatus = AlivcLivePushStats.IDLE;
301  private AlivcLivePlayStats mPlayStats = AlivcLivePlayStats.IDLE;
302  private AlivcLivePushError mLastError = AlivcLivePushError.ALIVC_COMMON_RETURN_SUCCESS;
303 
304  private AlivcLivePushInfoListener mPushInfoListener = null;
305  private AlivcLivePushErrorListener mPushErrorListener = null;
306  private AlivcLivePushNetworkListener mPushNetworkListener = null;
307  private AlivcLivePushBGMListener mPushBGMListener = null;
308  private AlivcLivePusherRenderContextListener mRenderContextListener = null;
309 
310  private SurfaceStatus mSurfaceStatus = SurfaceStatus.UNINITED;
311 
312  private SurfaceView mPreviewView = null;
313 
314  private AudioManager mAudioManager = null;
315 
316  private Context mContext = null;
317  private AlivcLivePushConfig mAlivcLivePushConfig = 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; // 最多输入3个水印
326 
327  private Map<Integer, AlivcLivePushError> mErrorMap = new HashMap<>();
328  private String mPushUrl = null;
329 
330  private int mBGMVolume = 50;
331  private int mCaptureVolume = 50;
332  private boolean mMute = false;
333  private TelephonyManager manager = null;
334  private AlivcLivePushLogLevel mLogLevel = AlivcLivePushLogLevelWarn;
335 
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;
343 
344  private int mDynamicAddsonCount = 0;
345 
346  private int mTimeCount = 0;
347 
348  private int mWatermarkCount = 0;
349 
350  private AlivcSnapshotListener mSnapshotListener = null;
351 
352  private ScreenRecordStatus mScreenStatus = ScreenRecordStatus.SCREEN_RECORD_NONE;
353 
357  private AppFrontBackHelper mAppFrontBackHelper;
358 
359  private ThreadPoolExecutor mThreadPoolExecutor = new ThreadPoolExecutor(3, 5, 1, TimeUnit.SECONDS,
360  new LinkedBlockingQueue<Runnable>(100));
361 
362  private Handler mHandler = new Handler(Looper.getMainLooper()) {
363  @Override
364  public void handleMessage(Message msg) {
365  AlivcLog.i(TAG, "AlivcLivePusher reconnect success");
366  isReconnect = false;
367  if (mPushNetworkListener != null) {
368  mThreadPoolExecutor.execute(new Runnable() {
369  @Override
370  public void run() {
371  mPushNetworkListener.onReconnectSucceed(getLivePusherReference());
372  }
373  });
374  }
375  }
376  };
377 
378  private SurfaceHolder.Callback mPreviewCallback = new SurfaceHolder.Callback() {
379  @Override
380  public void surfaceCreated(SurfaceHolder holder) {
381  AlivcLog.d(TAG, "LiveActivity-->Preview surface created");
382  if (mPreviewView == null) {
383  return;
384  }
385  //记录Surface的状态
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());
392  }
393  }
394  }
395 
396  @Override
397  public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
398  AlivcLog.d(TAG, "LiveActivity-->Preview surface changed");
399  if (mPreviewView == null) {
400  return;
401  }
402  mSurfaceStatus = SurfaceStatus.CHANGED;
403  if (mNativeAlivcLivePusher != null) {
404  mNativeAlivcLivePusher.notifySurfaceChange(holder.getSurface(), mAlivcLivePushConfig.getPreviewOrientation());
405  }
406  }
407 
408  @Override
409  public void surfaceDestroyed(SurfaceHolder holder) {
410  AlivcLog.d(TAG, "LiveActivity-->Preview surface destroyed");
411  if (mPreviewView == null) {
412  return;
413  }
414  if (mNativeAlivcLivePusher != null) {
415  mNativeAlivcLivePusher.notifySurfaceDestroy();
416  }
417  mSurfaceStatus = SurfaceStatus.DESTROYED;
418  }
419  };
420  //定时器
421  private ScheduledExecutorService scheduleExecutor = null;
422 
423  public AlivcLivePusherBasicImpl() {
424 
425  }
426 
435  @Override
436  public void init(final Context context, final AlivcLivePushConfig config) throws IllegalArgumentException, IllegalStateException {
437  AlivcLog.i(TAG, "init");
438  AlivcLog.i(TAG, AlivcLivePushInstance.getSdkBuildInfo());
439  mContext = context;
440  mAlivcLivePushConfig = config;
441  mLiveEventReporter = new LiveEventReporter(mContext, this, mAlivcLivePushConfig);
442 
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);
447  }
448 
449  boolean isLicenseVerified = AlivcLiveLicenseManager.verifyLicense();
450 
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));
458  }
459 
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);
464  }
465 
466  if (mPushStatus != AlivcLivePushStats.IDLE && mPushStatus != AlivcLivePushStats.INIT) {
467  throw new IllegalStateException("init state error, current state is " + AlivcLivePushStats.values()[mPushStatus.ordinal()]);
468  }
469  mAudioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
470  mAudioManager.setMode(AudioManager.STREAM_VOICE_CALL);
471  mAudioManager.setSpeakerphoneOn(true);
472 
473  registerHeadsetPlugReceiver();
474 
475  LogWhenGoBackOrFront((Application) context.getApplicationContext(), true);
476 
477  AliLiveInfoUtils.setSDKContext(mContext);
478 
479  mBluetoothHelper = new BluetoothHeadsetUtils(mContext);
480  mBluetoothHelper.start(new BluetoothHeadsetUtils.BlueToothListener() {
481  @Override
482  public void onBlueTooth(boolean on) {
483  LivePusherJNI.headSetOn = on;
484  if (!on) {
485  mAudioManager.setMode(AudioManager.STREAM_VOICE_CALL);
486  mAudioManager.setSpeakerphoneOn(true);
487  } else {
488  mAudioManager.setSpeakerphoneOn(false);
489  }
490  if (mNativeAlivcLivePusher != null) {
491  mNativeAlivcLivePusher.setHeadSet(on);
492  }
493  }
494  });
495 
496  checkConfig(config);
497 
498  res = mAlivcLivePushConfig.getResolution();
499 
500  for (AlivcLivePushError error : AlivcLivePushError.values()) {
501  mErrorMap.put(error.getCode(), error);
502  }
503  mLiveEventReporter = new LiveEventReporter(mContext, this, mAlivcLivePushConfig);
504  mNativeAlivcLivePusher = new LivePusherJNI(mContext, config, new LivePusherJNI.LivePusherListener() {
505  @Override
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) {
507  // 网络监听器
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() {
512  @Override
513  public void run() {
514  mPushNetworkListener.onNetworkPoor(getLivePusherReference());
515  }
516  });
517  }
518 
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() {
525  @Override
526  public void run() {
527  mPushNetworkListener.onNetworkRecovery(getLivePusherReference());
528  }
529  });
530  }
531 
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");
536  if (!isReconnect) {
537  isReconnect = true;
538  if (mPushNetworkListener != null) {
539  mThreadPoolExecutor.execute(new Runnable() {
540  @Override
541  public void run() {
542  mPushNetworkListener.onReconnectStart(getLivePusherReference());
543  }
544  });
545  }
546  }
547 
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);
555  }
556  //todo ! keep paused status
557  if (mPushStatus != AlivcLivePushStats.PAUSED) {
558  mPushStatus = AlivcLivePushStats.PUSHED;
559  }
560 
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");
565 
566  if (mPushNetworkListener != null) {
567  mThreadPoolExecutor.execute(new Runnable() {
568  @Override
569  public void run() {
570  mPushNetworkListener.onConnectionLost(getLivePusherReference());
571  }
572  });
573  }
574 
575  PusherConnectionLostEvent.Args args = new PusherConnectionLostEvent.Args();
576  if (param1 == 0) {
577  args.reason = "rtmp_";
578  } else if (param1 == 1) {
579  args.reason = "artc_";
580  }
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");
585 
586  isReconnect = false;
587  if (mHandler != null) {
588  mHandler.removeMessages(MESSAGE_RECONNECT_SUCCESS);
589  }
590  if (mPushNetworkListener != null) {
591  mThreadPoolExecutor.execute(new Runnable() {
592  @Override
593  public void run() {
594  mPushNetworkListener.onReconnectFail(getLivePusherReference());
595  }
596  });
597  }
598  mPushStatus = AlivcLivePushStats.ERROR;
599  mLastError = ALIVC_PUSHER_ERROR_SDK_PUSH_RECONNECT_FAIL;
600 
601  PusherReconnectFailedEvent.Args args = new PusherReconnectFailedEvent.Args();
602  args.errCode = what;
603  args.errMsg = msg;
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() {
609  @Override
610  public void run() {
611  mPushNetworkListener.onSendDataTimeout(getLivePusherReference());
612  }
613  });
614  }
615 
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");
624 
625  if (mPushNetworkListener != null) {
626  mThreadPoolExecutor.execute(new Runnable() {
627  @Override
628  public void run() {
629  mPushNetworkListener.onConnectFail(getLivePusherReference());
630  }
631  });
632  }
633  mPushStatus = AlivcLivePushStats.ERROR;
634  mLastError = getErrorByCode(what);
635 
636  PusherStartPushFailedEvent.Args args = new PusherStartPushFailedEvent.Args();
637  args.errCode = what;
638  args.errMsg = msg;
639  mLiveEventReporter.sendEvent(PusherStartPushFailedEvent.kTopicType, PusherStartPushFailedEvent.kTopicValue, PusherStartPushFailedEvent.getArgsStr(args));
640  } else if (what == ALIVC_PUSHER_EVENT_NATIVE_LIVE_PUSH_INIT_SUCCESS.getCode()) {
641 
642  } else if (what == ALIVC_PUSHER_EVENT_NATIVE_LIVE_PUSH_PREVIEW_STARTED.getCode()) {
643  AlivcLog.i(TAG, "AlivcLivePusher Callback Preview Started");
644 
645  if (mPushInfoListener != null) {
646  mThreadPoolExecutor.execute(new Runnable() {
647  @Override
648  public void run() {
649  mPushInfoListener.onPreviewStarted(getLivePusherReference());
650  }
651  });
652  }
653  mPushStatus = AlivcLivePushStats.PREVIEWED;
654  addWaterMark();
655  } else if (what == ALIVC_PUSHER_EVENT_NATIVE_LIVE_PUSH_PREVIEW_STOPED.getCode()) {
656  AlivcLog.i(TAG, "AlivcLivePusher Callback Preview Stoped");
657 
658  if (mPushInfoListener != null) {
659  mThreadPoolExecutor.execute(new Runnable() {
660  @Override
661  public void run() {
662  if (mPushInfoListener != null) {
663  mPushInfoListener.onPreviewStopped(getLivePusherReference());
664  }
665  }
666  });
667  }
668  mPushStatus = AlivcLivePushStats.INIT;
669  } else if (what == ALIVC_PUSHER_EVENT_PUSH_STARTED.getCode()) {
670  AlivcLog.i(TAG, "AlivcLivePusher Callback Push Started");
671 
672  mPushStatus = AlivcLivePushStats.PUSHED;
673  if (mPushInfoListener != null) {
674  mThreadPoolExecutor.execute(new Runnable() {
675  @Override
676  public void run() {
677  mPushInfoListener.onPushStarted(getLivePusherReference());
678  }
679  });
680  }
681 
682  PusherStartPushSuccessEvent.Args args = new PusherStartPushSuccessEvent.Args();
683  args.url = mPushUrl;
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");
687 
688  if (mPushInfoListener != null) {
689  mThreadPoolExecutor.execute(new Runnable() {
690  @Override
691  public void run() {
692  if (mPushInfoListener != null) {
693  mPushInfoListener.onPushStopped(getLivePusherReference());
694  }
695  }
696  });
697  }
698  PusherStopPushSuccessEvent.Args args = new PusherStopPushSuccessEvent.Args();
699  args.url = mPushUrl;
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;
706  //kAction=0, kEvent=1, kError=2, kBiz=3
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);
714  }
715 
716  assert(!arg7.isEmpty());
717  String topicValue = arg7;
718  String argJsonStr = arg8;
719  Map<String, String> param = new HashMap<String, String>();
720  try {
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);
727  }
728  } catch(JSONException e) {
729  AlivcLog.e(TAG, "Invalid json object: " + arg8);
730  } catch(Exception e) {
731  AlivcLog.e(TAG, "Unknown exception: " + e.getMessage());
732  }
733  mLiveEventReporter.sendEvent(topicType, topicValue, param);
734  } else if(what == ALIVC_PUSHER_EVENT_PUSH_MEDIAINFO.getCode()) {
735 
736  } else if(what == ALIVC_PUSHER_EVENT_PUSH_DELAY_INFO.getCode()) {
737 
738  PusherDelayInfoEvent.Args args = new PusherDelayInfoEvent.Args();
739  args.totalDelay = param1;
740  args.captureDelay = param2;
741  args.encoderDelay = param3;
742  args.sendDelay = param4;
743 
744  AlivcLog.d(TAG, "AlivcLivePusher push delay");
745 
746  mLiveEventReporter.sendEvent(PusherDelayInfoEvent.kTopicType, PusherDelayInfoEvent.kTopicValue, PusherDelayInfoEvent.getArgsStr(args));
747 
748 
749  JSONObject gDelayObject = new JSONObject();
750 
751  try {
752  gDelayObject.put("gdelay", param1);
753 
754  sendMessageInternal(gDelayObject.toString(),10,0,false, true);
755 
756  } catch (Exception e) {
757  e.printStackTrace();
758  }
759 
760 
761  } else if (what == ALIVC_PUSHER_EVENT_NATIVE_LIVE_PUSH_PUSH_PAUSED.getCode()) {
762  AlivcLog.i(TAG, "AlivcLivePusher Callback Push Paused");
763 
764  if (mPushInfoListener != null) {
765  mThreadPoolExecutor.execute(new Runnable() {
766  @Override
767  public void run() {
768  mPushInfoListener.onPushPaused(getLivePusherReference());
769  }
770  });
771  }
772 
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");
777 
778  if (mNativeAlivcLivePusher.isPushing()) {
779  mPushStatus = AlivcLivePushStats.PUSHED;
780  } else {
781  mPushStatus = AlivcLivePushStats.PREVIEWED;
782  }
783  if (mPushInfoListener != null) {
784  mThreadPoolExecutor.execute(new Runnable() {
785  @Override
786  public void run() {
787  mPushInfoListener.onPushResumed(getLivePusherReference());
788  }
789  });
790  }
791 
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");
796 
797  if (mPushInfoListener != null) {
798  mThreadPoolExecutor.execute(new Runnable() {
799  @Override
800  public void run() {
801  mPushInfoListener.onFirstFramePreviewed(getLivePusherReference());
802  }
803  });
804  }
805  } else if (what == ALIVC_PUSHER_EVENT_NATIVE_LIVE_PUSH_PUSH_RESTARTED.getCode()) {
806  AlivcLog.i(TAG, "AlivcLivePusher Callback Push Restarted");
807 
808  mPushStatus = AlivcLivePushStats.PUSHED;
809  if (mPushInfoListener != null) {
810  mThreadPoolExecutor.execute(new Runnable() {
811  @Override
812  public void run() {
813  mPushInfoListener.onPushRestarted(getLivePusherReference());
814  }
815  });
816  }
817 
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");
822 
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() {
831  @Override
832  public void run() {
833  mPushInfoListener.onDropFrame(getLivePusherReference(), param1, param2);
834 
835  if (mPushNetworkListener != null) {
836  mPushNetworkListener.onPacketsLost(getLivePusherReference());
837  }
838  }
839  });
840  }
841 
842  } else if (what == ALIVC_PUSHER_EVENT_NATIVE_LIVE_PUSH_ADJUST_BITRATE.getCode()) {
843  AlivcLog.d(TAG, "AlivcLivePusher Callback Adjust Bitrate");
844 
845  PusherAdjustBitrateEvent.Args args = new PusherAdjustBitrateEvent.Args();
846  args.oeb = param1 / 1000;
847  args.neb = param2 / 1000;
848  Map map = getPerformanceMap();
849  if (map != null) {
850  args.ceb = getInteger(map, "mVideoEncodeBitrate") + getInteger(map, "mAudioEncodeBitrate");
851  args.cub = getInteger(map, "mAudioUploadBitrate") + getInteger(map, "mVideoUploadBitrate");
852  }
853  mLiveEventReporter.sendEventWithLevel(PusherAdjustBitrateEvent.kTopicType, PusherAdjustBitrateEvent.kTopicValue, PusherAdjustBitrateEvent.getArgsStr(args), AlivcLivePushMonitorLevel.CUT);
854  if (mPushInfoListener != null) {
855  mThreadPoolExecutor.execute(new Runnable() {
856  @Override
857  public void run() {
858  mPushInfoListener.onAdjustBitrate(getLivePusherReference(), param1 / 1000, param2 / 1000);
859  }
860  });
861  }
862  } else if (what == ALIVC_PUSHER_EVENT_NATIVE_LIVE_PUSH_CHANGE_FPS.getCode()) {
863  AlivcLog.d(TAG, "AlivcLivePusher Callback Change FPS");
864 
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() {
871  @Override
872  public void run() {
873  mPushInfoListener.onAdjustFps(getLivePusherReference(), param1, param2);
874  }
875  });
876  }
877  } else if (what == ALIVC_PUSHER_EVENT_NATIVE_LIVE_PUSH_CHANGE_RESOLUTION.getCode()) {
878 
879  } else if (what == ALIVC_PUSHER_ERROR_SDK_PUSH_RTS_DOWN_TO_RTMP.getCode()) {
880  //RTS降级到RTMP逻辑
881  //rtsDownToRtmp();
882  } else if (what == ALIVC_PUSHER_EVENT_PUSH_SENDED_FIRST_AV.getCode()) {
883  //开始推流
884  PusherFirstFrameSentEvent.Args args = new PusherFirstFrameSentEvent.Args();
885  args.vutMs = param2;
886  args.autMs = param1;
887  args.resolution = mAlivcLivePushConfig.getResolution().toString().substring(11);
888  args.st = mAlivcLivePushConfig.getAudioChannels() == 1 ? "single" : "dual";
889  args.ao = mAlivcLivePushConfig.isAudioOnly();
890  args.vo = mAlivcLivePushConfig.isVideoOnly();
891  args.he = mAlivcLivePushConfig.getVideoEncodeMode().equals(Encode_MODE_HARD);//是否使用硬编
892  args.wc = mAlivcLivePushConfig.getWaterMarkInfos().size();//水印
893  args.pum = mAlivcLivePushConfig.isPushMirror();
894  args.fps = mAlivcLivePushConfig.getFps();
895  args.ivb = mAlivcLivePushConfig.getInitialVideoBitrate();
896  args.mavb = mAlivcLivePushConfig.getTargetVideoBitrate();
897  args.mivb = mAlivcLivePushConfig.getMinVideoBitrate();
898  args.asr = mAlivcLivePushConfig.getAudioSampleRate().getAudioSampleRate();
899  args.po = mAlivcLivePushConfig.getPreviewOrientation();
900  args.ct = mAlivcLivePushConfig.getCameraType();
901  args.flash = mAlivcLivePushConfig.isFlash();
902  args.crmc = mAlivcLivePushConfig.getConnectRetryCount();
903  args.cri = mAlivcLivePushConfig.getConnectRetryInterval();
904  args.prm = mAlivcLivePushConfig.isPreviewMirror();
905  args.gop = mAlivcLivePushConfig.getVideoEncodeGop();
906  args.utm = (mAlivcLivePushConfig.getConnectRetryCount() * mAlivcLivePushConfig.getConnectRetryInterval()) / 1000;
907  mLiveEventReporter.sendEvent(PusherFirstFrameSentEvent.kTopicType, PusherFirstFrameSentEvent.kTopicValue, PusherFirstFrameSentEvent.getArgsStr(args));
908  if (mPushInfoListener != null) {
909  mThreadPoolExecutor.execute(new Runnable() {
910  @Override
911  public void run() {
912  mPushInfoListener.onFirstFramePushed(getLivePusherReference());
913  }
914  });
915  }
916  } else if (what == ALIVC_PUSHER_EVENT_CAPTURE_OPEN_CAMERA_SUCCESS.getCode()) {
917 
918  } else if (what == ALIVC_PUSHER_EVENT_CAPTURE_OPEN_MIC_SUCCESS.getCode()) {
919 
920  } else if (what == ALIVC_PUSHER_EVENT_CAPTURE_CLOSE_CAMERA_SUCCESS.getCode()) {
921 
922  } else if (what == ALIVC_PUSHER_EVENT_NATIVE_LIVE_PUSH_OPEN_VIDEO_ENCODER_SUCCESS.getCode()) {
923 
924  } else if (what == ALIVC_PUSHER_EVENT_NATIVE_LIVE_PUSH_CAPTURE_VIDEO_SAMPLES_OVERFLOW.getCode()) {
925  //render 处理不过来,capture丢帧
926  } else if (what == ALIVC_PUSHER_EVENT_PUSH_SENDED_SEI.getCode()) {
927  if (mPushNetworkListener != null) {
928  mThreadPoolExecutor.execute(new Runnable() {
929  @Override
930  public void run() {
931  mPushNetworkListener.onSendMessage(getLivePusherReference());
932  }
933  });
934  }
935  }
936 
937  //播放器监听
938  else if (what == ALIVC_PUSHER_ERROR_BGM_OPEN_FAILED.getCode()) {
939  mPlayStats = AlivcLivePlayStats.IDLE;
940  if (mPushBGMListener != null) {
941  mPushBGMListener.onOpenFailed();
942  }
943  if (mNativeAlivcLivePusher != null) {
944  mNativeAlivcLivePusher.stopBGM();
945  }
946  } else if (what == ALIVC_PUSHER_ERROR_BGM_TIMEOUT.getCode()) {
947  mPlayStats = AlivcLivePlayStats.IDLE;
948  if (mPushBGMListener != null) {
949  mPushBGMListener.onDownloadTimeout();
950  }
951  } else if (what == ALIVC_PUSHER_EVENT_BGM_OPEN_SUCCESS.getCode()) {
952  mPlayStats = AlivcLivePlayStats.STARTED;
953  if (mPushBGMListener != null) {
954  mPushBGMListener.onStarted();
955  }
956  } else if (what == ALIVC_PUSHER_EVENT_BGM_STOP_SUCCESS.getCode()) {
957  mPlayStats = AlivcLivePlayStats.STOPPED;
958  if (mPushBGMListener != null) {
959  mPushBGMListener.onStopped();
960  }
961  } else if (what == ALIVC_PUSHER_EVENT_BGM_PAUSE_SUCCESS.getCode()) {
962  mPlayStats = AlivcLivePlayStats.PAUSED;
963  if (mPushBGMListener != null) {
964  mPushBGMListener.onPaused();
965  }
966  } else if (what == ALIVC_PUSHER_EVENT_BGM_RESUME_SUCCESS.getCode()) {
967  mPlayStats = AlivcLivePlayStats.STARTED;
968  if (mPushBGMListener != null) {
969  mPushBGMListener.onResumed();
970  }
971  } else if (what == ALIVC_PUSHER_EVENT_BGM_COMPLETED.getCode()) {
972  if (mPushBGMListener != null) {
973  mPushBGMListener.onCompleted();
974  }
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);
979  }
980  } else if (what == ALIVC_PUSHER_EVENT_CAPTURE_OPEN_SCREENCAPTURE_SUCCESS.getCode()) {
981 
982  } else if (what == ALIVC_PUSHER_EVENT_CAPTURE_CLOSE_SCREENCAPTURE_SUCCESS.getCode()) {
983 
984  } else if (what == ALIVC_PUSHER_EVENT_NATIVE_LIVE_PUSH_GL_CONTEXT_CREATED.getCode()) {
985  if (mRenderContextListener != null) {
986  mRenderContextListener.onSharedContextCreated(arg6);
987  }
988  } else if (what == ALIVC_PUSHER_EVENT_NATIVE_LIVE_PUSH_GL_CONTEXT_DESTROYED.getCode()) {
989  if (mRenderContextListener != null) {
990  mRenderContextListener.onSharedContextDestroyed(arg6);
991  }
992  }
993  // 系统错误监听器
994  else if (what > 0x30010000 && what < 0x30020000) {
995  AlivcLog.e(TAG, "AlivcLivePusher SystemError Callback error: " + what);
996 
997  if (mErrorMap.get(what) != null) {
998  mErrorMap.get(what).setMsg(msg);
999  }
1000  if (mPushErrorListener != null) {
1001  mThreadPoolExecutor.execute(new Runnable() {
1002  @Override
1003  public void run() {
1004  mPushErrorListener.onSystemError(getLivePusherReference(), mErrorMap.get(what));
1005  }
1006  });
1007  }
1008 
1009  PusherSystemErrorEvent.Args args = new PusherSystemErrorEvent.Args();
1010  Map map = getPerformanceMap();
1011  if (map != null) {
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;
1017  }
1018  mLiveEventReporter.sendEvent(PusherSystemErrorEvent.kTopicType, PusherSystemErrorEvent.kTopicValue, PusherSystemErrorEvent.getArgsStr(args));
1019  }
1020  mPushStatus = AlivcLivePushStats.ERROR;
1021  mLastError = getErrorByCode(what);
1022  }
1023  else if (what == ALIVC_PUSHER_ERROR_SDK_LIVE_PUSH_LOW_PERFORMANCE.getCode()) {
1024  // When callback is low performance, do not set the status into a forbidden state.
1025  AlivcLog.i(TAG, "AlivcLivePusher low performance warning: 0x" + Integer.toHexString(what));
1026  if (mErrorMap.get(what) != null) {
1027  mErrorMap.get(what).setMsg(msg);
1028  }
1029  PusherSdkErrorEvent.Args args = new PusherSdkErrorEvent.Args();
1030  Map map = getPerformanceMap();
1031  if (map != null) {
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;
1037  }
1038  mLiveEventReporter.sendEvent(PusherSdkErrorEvent.kTopicType, PusherSdkErrorEvent.kTopicValue, PusherSdkErrorEvent.getArgsStr(args));
1039  }
1040  }
1041  // 其他
1042  else {
1043  AlivcLog.e(TAG, "AlivcLivePusher SDKError Callback error: 0x" + Integer.toHexString(what));
1044 
1045  if (mErrorMap.get(what) != null) {
1046  mErrorMap.get(what).setMsg(msg);
1047  }
1048  if (mPushErrorListener != null) {
1049  mThreadPoolExecutor.execute(new Runnable() {
1050  @Override
1051  public void run() {
1052  mPushErrorListener.onSDKError(getLivePusherReference(), mErrorMap.get(what));
1053  }
1054  });
1055  }
1056 
1057  PusherSdkErrorEvent.Args args = new PusherSdkErrorEvent.Args();
1058  Map map = getPerformanceMap();
1059  if (map != null) {
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;
1065  }
1066  mLiveEventReporter.sendEvent(PusherSdkErrorEvent.kTopicType, PusherSdkErrorEvent.kTopicValue, PusherSdkErrorEvent.getArgsStr(args));
1067  }
1068  mPushStatus = AlivcLivePushStats.ERROR;
1069  mLastError = getErrorByCode(what);
1070  AlivcLog.e(TAG, "error is " + what + " msg is " + what);
1071  }
1072  }
1073  });
1074  mNativeAlivcLivePusher.init();
1075  BGMPlayerJNI.setContext(mContext);
1076  // AlivcLiveBase.setLogLevel(mLogLevel); // 如果用户之前设置,此处会覆盖用户设置, 暂时默认先不设置
1077  mPushStatus = AlivcLivePushStats.INIT;
1078  }
1079 
1085  @Override
1086  public void setCustomDetect(AlivcLivePushCustomDetect customVideoDetect) {
1087  AlivcLog.i(TAG, "setCustomDetect");
1088  if (mNativeAlivcLivePusher == null) {
1089  return;
1090  }
1091  mNativeAlivcLivePusher.setCustomDetect(customVideoDetect);
1092  }
1093 
1099  @Override
1100  public void setCustomFilter(AlivcLivePushCustomFilter customVideoFilter) {
1101  AlivcLog.i(TAG, "setCustomFilter");
1102  if (mNativeAlivcLivePusher == null) {
1103  return;
1104  }
1105  mNativeAlivcLivePusher.setCustomFilter(customVideoFilter);
1106  }
1107 
1113  @Override
1114  public void setCustomAudioFilter(AlivcLivePushCustomAudioFilter customAudioFilter) {
1115  AlivcLog.i(TAG, "setCustomAudioFilter");
1116  if (mNativeAlivcLivePusher == null) {
1117  return;
1118  }
1119  mNativeAlivcLivePusher.setCustomAudioFilter(customAudioFilter);
1120  }
1121 
1127  @Override
1128  public void destroy() throws IllegalStateException {
1129  AlivcLog.i(TAG, "destroy");
1130  LogWhenGoBackOrFront((Application) mContext.getApplicationContext(), false);
1131 
1132  if (mNativeAlivcLivePusher != null) {
1133  mNativeAlivcLivePusher.release();
1134  }
1135 
1136  mDynamicAddsonCount = 0;
1137 
1138  if (registeredCallback) {
1139  try {
1140  mContext.unregisterReceiver(mHeadsetPlugReceiver);
1141  mContext.unregisterReceiver(mTelephoneReceiver);
1142  } catch (Exception e) {
1143  AlivcLog.e(TAG, "unregisterReceiver exception");
1144  }
1145  registeredCallback = false;
1146  }
1147  if (mBluetoothHelper != null) {
1148  mBluetoothHelper.stop();
1149  }
1150  mPushStatus = AlivcLivePushStats.IDLE;
1151 
1152  stop5Interval();
1153 
1154  if (mThreadPoolExecutor != null && !mThreadPoolExecutor.isShutdown()) {
1155  mThreadPoolExecutor.shutdown();
1156  }
1157  mThreadPoolExecutor = null;
1158 
1159  mNativeAlivcLivePusher = null;
1160  mPushInfoListener = null;
1161  mPushErrorListener = null;
1162  mPushNetworkListener = null;
1163  mPushBGMListener = null;
1164 
1165  mPreviewView = null;
1166  mContext = null;
1167  mAlivcLivePushConfig = null;
1168 
1169  mErrorMap = null;
1170  mPreviewCallback = null;
1171  if (mHandler != null) {
1172  mHandler.removeMessages(MESSAGE_RECONNECT_SUCCESS);
1173  }
1174  mHandler = null;
1175 
1176  if (mWeakAlivcLivePusher != null) {
1177  mWeakAlivcLivePusher.clear();
1178  mWeakAlivcLivePusher = null;
1179  }
1180  BGMPlayerJNI.setContext(null);
1181  }
1182 
1183  @Override
1184  public void setLivePusherReference(AlivcLivePusher livePusher) {
1185  mWeakAlivcLivePusher = new WeakReference<>(livePusher);
1186  }
1187 
1188  private AlivcLivePusher getLivePusherReference() {
1189  return (mWeakAlivcLivePusher != null) ? mWeakAlivcLivePusher.get() : null;
1190  }
1191 
1199  @Override
1200  public void startPreview(SurfaceView surfaceView) throws IllegalArgumentException, IllegalStateException {
1201  AlivcLog.i(TAG, "startPreview");
1202  PusherStartPreviewEvent.Args args = new PusherStartPreviewEvent.Args();
1203  args.sync = true;
1204  if (mLiveEventReporter != null) {
1205  mLiveEventReporter.sendEvent(PusherStartPreviewEvent.kTopicType, PusherStartPreviewEvent.kTopicValue, PusherStartPreviewEvent.getArgsStr(args));
1206  }
1207 
1208  if (mNativeAlivcLivePusher == null) {
1209  AlivcLog.e(TAG, "Illegal State, you should init first");
1210  return;
1211  }
1212  if (mPushStatus != AlivcLivePushStats.INIT && mPushStatus != AlivcLivePushStats.PREVIEWED) {
1213  AlivcLog.e(TAG, "status error current state is " + AlivcLivePushStats.values()[mPushStatus.ordinal()]);
1214  return;
1215  }
1216 
1217  this.mPreviewView = surfaceView;
1218  int result = 0;
1219  if (surfaceView == null) {
1220  result = mNativeAlivcLivePusher.startPreview(null, true);
1221  if (result == 0) {
1222  mPushStatus = AlivcLivePushStats.PREVIEWED;
1223  } else {
1224  AlivcLog.e(TAG, "start preview error");
1225  return;
1226  }
1227  } else {
1228  result = mNativeAlivcLivePusher.startPreview(surfaceView.getHolder().getSurface(), true);
1229  if (result == 0) {
1230  surfaceView.getHolder().addCallback(mPreviewCallback);
1231  mPushStatus = AlivcLivePushStats.PREVIEWED;
1232  } else {
1233  AlivcLog.e(TAG, "start preview error");
1234  }
1235  }
1236  }
1237 
1245  @Override
1246  public void startPreviewAsync(SurfaceView surfaceView) throws IllegalArgumentException, IllegalStateException {
1247  AlivcLog.i(TAG, "startPreviewAsync");
1248 
1249  PusherStartPreviewEvent.Args args = new PusherStartPreviewEvent.Args();
1250  args.sync = false;
1251  if (mLiveEventReporter != null) {
1252  mLiveEventReporter.sendEvent(PusherStartPreviewEvent.kTopicType, PusherStartPreviewEvent.kTopicValue, PusherStartPreviewEvent.getArgsStr(args));
1253  }
1254 
1255  if (mNativeAlivcLivePusher == null) {
1256  AlivcLog.e(TAG, "Illegal State, you should init first");
1257  return;
1258  }
1259 
1260  if (mPushStatus != AlivcLivePushStats.INIT && mPushStatus != AlivcLivePushStats.PREVIEWED) {
1261  AlivcLog.e(TAG, "status error current state is " + AlivcLivePushStats.values()[mPushStatus.ordinal()]);
1262  return;
1263  }
1264 
1265  mPushStatus = AlivcLivePushStats.PREVIEWING;
1266  this.mPreviewView = surfaceView;
1267  int result = 0;
1268  if (surfaceView == null) {
1269  result = mNativeAlivcLivePusher.startPreview(null, false);
1270  if (result == 0) {
1271  mPushStatus = AlivcLivePushStats.PREVIEWED;
1272  } else {
1273  AlivcLog.e(TAG, "start preview async error");
1274  }
1275  } else {
1276  result = mNativeAlivcLivePusher.startPreview(surfaceView.getHolder().getSurface(), false);
1277  if (result == 0) {
1278  surfaceView.getHolder().addCallback(mPreviewCallback);
1279  mPushStatus = AlivcLivePushStats.PREVIEWED;
1280  } else {
1281  AlivcLog.e(TAG, "start preview async error");
1282  }
1283  }
1284  }
1285 
1286  @Override
1287  public void startPreview(Context context, FrameLayout frameLayout, boolean isAnchor) throws IllegalArgumentException, IllegalStateException {
1288 
1289  }
1290 
1296  @Override
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));
1302  }
1303 
1304  if (mNativeAlivcLivePusher == null) {
1305  AlivcLog.e(TAG, "Illegal State, you should init first");
1306  return;
1307  }
1308 
1309  mDynamicAddsonCount = 0;
1310 
1311  if (mPushStatus != AlivcLivePushStats.INIT && mPushStatus != AlivcLivePushStats.PREVIEWED) {
1312  AlivcLog.e(TAG, "status error current state is " + AlivcLivePushStats.values()[mPushStatus.ordinal()]);
1313  return;
1314  }
1315 
1316  int result = mNativeAlivcLivePusher.stopPreview();
1317  if (result == 0) {
1318  mPushStatus = AlivcLivePushStats.INIT;
1319  } else {
1320  AlivcLog.e(TAG, "stop preview error");
1321  }
1322  }
1323 
1331  @Override
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");
1336  return;
1337  }
1338 
1339  url = AlivcLiveURLTools.trimUrl(url);
1340  if (!AlivcLiveURLTools.checkPushUrl(url)) {
1341  AlivcLog.e(TAG, "Illegal argument, push url error!");
1342  return;
1343  }
1344 
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");
1347  return;
1348  }
1349 
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()]);
1353  return;
1354  }
1355 
1356  if (mPushStatus.equals(AlivcLivePushStats.INIT)) {
1357  mPreviewView = null;
1358  int result = mNativeAlivcLivePusher.startPreview(null, true);
1359  if (result != 0) {
1360  AlivcLog.e(TAG, "start push error : create gl resource failed");
1361  return;
1362  }
1363  }
1364  mPushUrl = url;
1365  if (mPushUrl.contains(AUTH_KEY)) {
1366  getNetworkTime();
1367  }
1368 
1369  mLiveEventReporter.refreshPushId();
1370  int result = mNativeAlivcLivePusher.startPush(url, true);
1371  if (result == 0) {
1372  if (mPushStatus != AlivcLivePushStats.PUSHED) {
1373  mPushStatus = AlivcLivePushStats.PUSHED;
1374  if (mAlivcLivePushConfig.getMediaProjectionPermissionResultData() != null) {
1375  mScreenStatus = ScreenRecordStatus.SCREEN_RECORD_NORMAL;
1376  }
1377  }
1378  } else {
1379  AlivcLog.e(TAG, "start push error");
1380  return;
1381  }
1382 
1383  reportStartPushEvent(false, true);
1384 
1385  String pauseImage = mAlivcLivePushConfig.getPausePushImage() == null ? "" : mAlivcLivePushConfig.getPausePushImage();
1386  String networkImage = mAlivcLivePushConfig.getNetworkPoorPushImage() == null ? "" : mAlivcLivePushConfig.getNetworkPoorPushImage();
1387  mNativeAlivcLivePusher.addPushImage(pauseImage, networkImage);
1388  startScheduleExecutor();
1389  }
1390 
1398  @Override
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");
1403  return;
1404  }
1405 
1406  url = AlivcLiveURLTools.trimUrl(url);
1407  if (!AlivcLiveURLTools.checkPushUrl(url)) {
1408  AlivcLog.e(TAG, "Illegal argument, push url error!");
1409  return;
1410  }
1411 
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()]);
1415  return;
1416  }
1417 
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");
1420  return;
1421  }
1422 
1423  if (mPushStatus.equals(AlivcLivePushStats.INIT)) {
1424  mPreviewView = null;
1425  int result = mNativeAlivcLivePusher.startPreview(null, true);
1426  if (result != 0) {
1427  AlivcLog.e(TAG, "start push error : create gl resource failed");
1428  return;
1429  }
1430  }
1431 
1432  mPushUrl = url;
1433  if (mPushUrl.contains(AUTH_KEY)) {
1434  getNetworkTime();
1435  }
1436 
1437  mLiveEventReporter.refreshPushId();
1438  int result = mNativeAlivcLivePusher.startPush(url, false);
1439  if (result == 0) {
1440  if (mPushStatus != AlivcLivePushStats.PUSHED) {
1441  mPushStatus = AlivcLivePushStats.PUSHED;
1442  if (mAlivcLivePushConfig.getMediaProjectionPermissionResultData() != null) {
1443  mScreenStatus = ScreenRecordStatus.SCREEN_RECORD_NORMAL;
1444  }
1445  }
1446  } else {
1447  AlivcLog.e(TAG, "start push async error");
1448  return;
1449  }
1450 
1451  reportStartPushEvent(false, false);
1452 
1453  String pauseImage = mAlivcLivePushConfig.getPausePushImage() == null ? "" : mAlivcLivePushConfig.getPausePushImage();
1454  String networkImage = mAlivcLivePushConfig.getNetworkPoorPushImage() == null ? "" : mAlivcLivePushConfig.getNetworkPoorPushImage();
1455  mNativeAlivcLivePusher.addPushImage(pauseImage, networkImage);
1456  startScheduleExecutor();
1457  }
1458 
1464  @Override
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");
1469  return;
1470  }
1471 
1472  if (mPreviewView == null && mAlivcLivePushConfig.getMediaProjectionPermissionResultData() == null
1473  && !mAlivcLivePushConfig.isAudioOnly()) {
1474  AlivcLog.e(TAG, "illegal argument");
1475  return;
1476  }
1477 
1478  if ((mAlivcLivePushConfig.isAudioOnly() || mAlivcLivePushConfig.isVideoOnly())
1479  && (!TextUtils.isEmpty(mPushUrl) && mPushUrl.startsWith(AlivcLiveStreamType.EnumType.AlivcLiveStreamRts.getPrefix()))) {
1480  AlivcLog.e(TAG, "RTC protocol don't support audio/video only stream");
1481  return;
1482  }
1483 
1484  if (mPushStatus != AlivcLivePushStats.PUSHED && mPushStatus != AlivcLivePushStats.ERROR) {
1485  AlivcLog.e(TAG, "status error current state is " + AlivcLivePushStats.values()[mPushStatus.ordinal()]);
1486  return;
1487  }
1488 
1489  mDynamicAddsonCount = 0;
1490 
1491  stop5Interval();
1492 
1493  Surface surface = mPreviewView != null ? mPreviewView.getHolder().getSurface() : null;
1494  int result = mNativeAlivcLivePusher.restartPush(surface, true, 1000);
1495  if (result == 0) {
1496  mPushStatus = AlivcLivePushStats.PUSHED;
1497  if (mAlivcLivePushConfig.getMediaProjectionPermissionResultData() != null) {
1498  mScreenStatus = ScreenRecordStatus.SCREEN_RECORD_NORMAL;
1499  }
1500  } else {
1501  AlivcLog.e(TAG, "restart push error");
1502  return;
1503  }
1504  String pauseImage = mAlivcLivePushConfig.getPausePushImage() == null ? "" : mAlivcLivePushConfig.getPausePushImage();
1505  String networkImage = mAlivcLivePushConfig.getNetworkPoorPushImage() == null ? "" : mAlivcLivePushConfig.getNetworkPoorPushImage();
1506  mNativeAlivcLivePusher.addPushImage(pauseImage, networkImage);
1507 
1508  reportStartPushEvent(true, true);
1509 
1510  startScheduleExecutor();
1511 
1512  }
1513 
1519  @Override
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");
1524  return;
1525  }
1526 
1527  if (mPreviewView == null && mAlivcLivePushConfig.getMediaProjectionPermissionResultData() == null
1528  && !mAlivcLivePushConfig.isAudioOnly()) {
1529  AlivcLog.e(TAG, "illegal argument");
1530  return;
1531  }
1532 
1533  if ((mAlivcLivePushConfig.isAudioOnly() || mAlivcLivePushConfig.isVideoOnly())
1534  && (!TextUtils.isEmpty(mPushUrl) && mPushUrl.startsWith(AlivcLiveStreamType.EnumType.AlivcLiveStreamRts.getPrefix()))) {
1535  AlivcLog.e(TAG, "RTC protocol don't support audio/video only stream");
1536  return;
1537  }
1538 
1539  if (mPushStatus != AlivcLivePushStats.PUSHED && mPushStatus != AlivcLivePushStats.ERROR) {
1540  AlivcLog.e(TAG, "status error current state is " + AlivcLivePushStats.values()[mPushStatus.ordinal()]);
1541  return;
1542  }
1543 
1544  Surface surface = mPreviewView != null ? mPreviewView.getHolder().getSurface() : null;
1545  int result = mNativeAlivcLivePusher.restartPush(surface, false, 1000);
1546  if (result == 0) {
1547  mPushStatus = AlivcLivePushStats.RESTARTING;
1548  } else {
1549  AlivcLog.e(TAG, "restart push async error");
1550  return;
1551  }
1552  String pauseImage = mAlivcLivePushConfig.getPausePushImage() == null ? "" : mAlivcLivePushConfig.getPausePushImage();
1553  String networkImage = mAlivcLivePushConfig.getNetworkPoorPushImage() == null ? "" : mAlivcLivePushConfig.getNetworkPoorPushImage();
1554  mNativeAlivcLivePusher.addPushImage(pauseImage, networkImage);
1555 
1556  stop5Interval();
1557 
1558  reportStartPushEvent(true, false);
1559 
1560  startScheduleExecutor();
1561  }
1562 
1568  @Override
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");
1573  return;
1574  }
1575 
1576  url = AlivcLiveURLTools.trimUrl(url);
1577  if (!AlivcLiveURLTools.checkPushUrl(url)) {
1578  return;
1579  }
1580 
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()]);
1584  return;
1585  }
1586 
1587  if (isNetworkPushing()) {
1588  return;
1589  }
1590  mPushUrl = url;
1591  getNetworkTime();
1592 
1593  int result = mNativeAlivcLivePusher.reconnect(url, false);
1594  if (result == 0) {
1595  isReconnect = false;
1596  if (mHandler != null) {
1597  mHandler.removeMessages(MESSAGE_RECONNECT_SUCCESS);
1598  }
1599  mPushStatus = AlivcLivePushStats.PUSHED;
1600  if (mAlivcLivePushConfig.getMediaProjectionPermissionResultData() != null) {
1601  mScreenStatus = ScreenRecordStatus.SCREEN_RECORD_NORMAL;
1602  }
1603  } else {
1604  AlivcLog.e(TAG, "reconnect push async error");
1605  return;
1606  }
1607 
1608  //重新连接推流
1609  PusherReconnectEvent.Args args = new PusherReconnectEvent.Args();
1610  Map map = getPerformanceMap();
1611  if (map != null) {
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));
1616  }
1617  }
1618  }
1619 
1625  @Override
1626  public void stopPush() throws IllegalStateException {
1627  AlivcLog.i(TAG, "stopPush");
1628  PusherStopPushEvent.Args args = new PusherStopPushEvent.Args();
1629  Map map = getPerformanceMap();
1630  if (map != null) {
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));
1635  }
1636  }
1637 
1638  if (mNativeAlivcLivePusher == null) {
1639  AlivcLog.e(TAG, "Illegal State, you should init first");
1640  return;
1641  }
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()]);
1645  return;
1646  }
1647 
1648  int result = mNativeAlivcLivePusher.stopPush();
1649  if (result == 0) {
1650  mPushStatus = AlivcLivePushStats.PREVIEWED;
1651  } else {
1652  AlivcLog.e(TAG, "stop push error");
1653  return;
1654  }
1655  if (mPreviewView == null) {
1656  mNativeAlivcLivePusher.stopPreview();
1657  mPushStatus = AlivcLivePushStats.INIT;
1658  }
1659  stop5Interval();
1660  }
1661 
1667  @Override
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");
1672  return;
1673  }
1674  if (mAlivcLivePushConfig.isExternMainStream()) {
1675  return;
1676  }
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()]);
1680  return;
1681  }
1682  mPushStatus = AlivcLivePushStats.PAUSED;
1683 
1684  mNativeAlivcLivePusher.pause();
1685 
1686  //reclock pause time
1687  PusherPauseEvent.mLastPauseTime = System.currentTimeMillis();
1688  PusherPauseEvent.Args args = new PusherPauseEvent.Args();
1689  Map map = getPerformanceMap();
1690  if (map != null) {
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));
1696  }
1697  }
1698  }
1699 
1705  @Override
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");
1710  return;
1711  }
1712  if (mAlivcLivePushConfig.isExternMainStream()) {
1713  return;
1714  }
1715  if (mPushStatus != AlivcLivePushStats.PAUSED && mPushStatus != AlivcLivePushStats.ERROR) {
1716  AlivcLog.e(TAG, "status error current state is " + AlivcLivePushStats.values()[mPushStatus.ordinal()]);
1717  return;
1718  }
1719 
1720  mNativeAlivcLivePusher.resume(true);
1721  PusherResumeEvent.Args args = new PusherResumeEvent.Args();
1722  Map map = getPerformanceMap();
1723  if (map != null) {
1724  args.sync = true;
1725  args.isResumeScreen = false;
1726  args.totalUploadSize = ParameterUtil.getLong(map, "mTotalSizeOfUploadedPackets");
1727  args.totalTime = ParameterUtil.getLong(map, "mTotalTimeOfPublishing");
1728  if (PusherPauseEvent.mLastPauseTime == 0) {
1729  args.cost = 0;
1730  } else {
1731  args.cost = System.currentTimeMillis() - PusherPauseEvent.mLastPauseTime;
1732  }
1733  if (mLiveEventReporter != null) {
1734  mLiveEventReporter.sendEvent(PusherResumeEvent.kTopicType, PusherResumeEvent.kTopicValue, PusherResumeEvent.getArgsStr(args));
1735  }
1736  }
1737  //reset to 0
1738  PusherPauseEvent.mLastPauseTime = 0;
1739 
1740  if (mNativeAlivcLivePusher.isPushing()) {
1741  mPushStatus = AlivcLivePushStats.PUSHED;
1742  } else {
1743  mPushStatus = AlivcLivePushStats.PREVIEWED;
1744  }
1745  }
1746 
1752  @Override
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");
1757  return;
1758  }
1759  if (mAlivcLivePushConfig.isExternMainStream()) {
1760  return;
1761  }
1762  if (mPushStatus != AlivcLivePushStats.PAUSED && mPushStatus != AlivcLivePushStats.ERROR) {
1763  AlivcLog.e(TAG, "status error current state is " + AlivcLivePushStats.values()[mPushStatus.ordinal()]);
1764  return;
1765  }
1766  mPushStatus = AlivcLivePushStats.RESUMING;
1767  mNativeAlivcLivePusher.resume(false);
1768  PusherResumeEvent.Args args = new PusherResumeEvent.Args();
1769  Map map = getPerformanceMap();
1770  if (map != null) {
1771  args.sync = false;
1772  args.isResumeScreen = false;
1773  args.totalUploadSize = ParameterUtil.getLong(map, "mTotalSizeOfUploadedPackets");
1774  args.totalTime = ParameterUtil.getLong(map, "mTotalTimeOfPublishing");
1775  if (PusherPauseEvent.mLastPauseTime == 0) {
1776  args.cost = 0;
1777  } else {
1778  args.cost = System.currentTimeMillis() - PusherPauseEvent.mLastPauseTime;
1779  }
1780  if (mLiveEventReporter != null) {
1781  mLiveEventReporter.sendEvent(PusherResumeEvent.kTopicType, PusherResumeEvent.kTopicValue, PusherResumeEvent.getArgsStr(args));
1782  }
1783  }
1784  //reset to 0
1785  PusherPauseEvent.mLastPauseTime = 0;
1786  }
1787 
1793  @Override
1794  public void pauseScreenCapture() throws IllegalStateException {
1795  if (mNativeAlivcLivePusher == null) {
1796  AlivcLog.e(TAG, "Illegal State, you should init first");
1797  return;
1798  }
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()]);
1802  return;
1803  }
1804  mPushStatus = AlivcLivePushStats.PAUSED;
1805 
1806  //reclock pause time
1807  PusherPauseEvent.mLastPauseTime = System.currentTimeMillis();
1808 
1809  mNativeAlivcLivePusher.pauseScreenCapture();
1810  PusherPauseEvent.Args args = new PusherPauseEvent.Args();
1811  Map map = getPerformanceMap();
1812  if (map != null) {
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));
1818  }
1819  }
1820  }
1821 
1827  @Override
1828  public void resumeScreenCapture() throws IllegalStateException {
1829  if (mNativeAlivcLivePusher == null) {
1830  AlivcLog.e(TAG, "Illegal State, you should init first");
1831  return;
1832  }
1833  if (mPushStatus != AlivcLivePushStats.PAUSED) {
1834  AlivcLog.e(TAG, "status error current state is " + AlivcLivePushStats.values()[mPushStatus.ordinal()]);
1835  return;
1836  }
1837 
1838  mNativeAlivcLivePusher.resumeScreenCapture();
1839  PusherResumeEvent.Args args = new PusherResumeEvent.Args();
1840  Map map = getPerformanceMap();
1841  if (map != null) {
1842  args.sync = true;
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));
1849  }
1850  }
1851  //reset to 0
1852  PusherPauseEvent.mLastPauseTime = 0;
1853 
1854  if (mNativeAlivcLivePusher.isPushing()) {
1855  mPushStatus = AlivcLivePushStats.PUSHED;
1856  } else {
1857  mPushStatus = AlivcLivePushStats.PREVIEWED;
1858  }
1859  }
1860 
1866  @Override
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");
1871  return;
1872  }
1873  if (mPushStatus != AlivcLivePushStats.PREVIEWED && mPushStatus != AlivcLivePushStats.PUSHED) {
1874  AlivcLog.e(TAG, "status error current state is " + AlivcLivePushStats.values()[mPushStatus.ordinal()]);
1875  return;
1876  }
1877  mNativeAlivcLivePusher.switchCamera();
1878 
1879  if (mAlivcLivePushConfig.getCameraType() == CAMERA_TYPE_FRONT.getCameraId()) {
1880  mAlivcLivePushConfig.setCameraType(CAMERA_TYPE_BACK);
1881  } else {
1882  mAlivcLivePushConfig.setCameraType(CAMERA_TYPE_FRONT);
1883  }
1884 
1885  //send switch camera
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));
1890  }
1891  }
1892 
1899  @Override
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");
1904  return;
1905  }
1906  if (mPushStatus != AlivcLivePushStats.PREVIEWED && mPushStatus != AlivcLivePushStats.PUSHED) {
1907  AlivcLog.e(TAG, "status error current state is " + AlivcLivePushStats.values()[mPushStatus.ordinal()]);
1908  return;
1909  }
1910  mNativeAlivcLivePusher.setCameraFocus(autoFocus, 0, 0);
1911  }
1912 
1921  @Override
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");
1926  return;
1927  }
1928  if (mPushStatus != AlivcLivePushStats.PREVIEWED && mPushStatus != AlivcLivePushStats.PUSHED) {
1929  AlivcLog.e(TAG, "status error current state is " + AlivcLivePushStats.values()[mPushStatus.ordinal()]);
1930  return;
1931  }
1932  mNativeAlivcLivePusher.setCameraFocus(autoFocus, x, y);
1933  }
1934 
1938  @Override
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");
1943  return;
1944  }
1945  if (mPushStatus != AlivcLivePushStats.PREVIEWED && mPushStatus != AlivcLivePushStats.PUSHED) {
1946  AlivcLog.e(TAG, "status error current state is " + AlivcLivePushStats.values()[mPushStatus.ordinal()]);
1947  return;
1948  }
1949  mNativeAlivcLivePusher.setExposureCompensation(exposure);
1950  }
1951 
1955  @Override
1956  public int getCurrentExposure() {
1957  AlivcLog.i(TAG, "getCurrentExposure");
1958  if (mNativeAlivcLivePusher == null) {
1959  AlivcLog.e(TAG, "Illegal State, you should init first");
1960  return -1;
1961  }
1962  if (mPushStatus != AlivcLivePushStats.PREVIEWED && mPushStatus != AlivcLivePushStats.PUSHED) {
1963  AlivcLog.e(TAG, "status error current state is " + AlivcLivePushStats.values()[mPushStatus.ordinal()]);
1964  return -1;
1965  }
1966  return mNativeAlivcLivePusher.getCurrentExposureCompensation();
1967  }
1968 
1972  @Override
1973  public int getSupportedMinExposure() {
1974  AlivcLog.i(TAG, "getSupportedMinExposure");
1975  if (mNativeAlivcLivePusher == null) {
1976  AlivcLog.e(TAG, "Illegal State, you should init first");
1977  return -1;
1978  }
1979  if (mPushStatus != AlivcLivePushStats.PREVIEWED && mPushStatus != AlivcLivePushStats.PUSHED) {
1980  AlivcLog.e(TAG, "status error current state is " + AlivcLivePushStats.values()[mPushStatus.ordinal()]);
1981  return -1;
1982  }
1983  return mNativeAlivcLivePusher.getMinExposureCompensation();
1984  }
1985 
1989  @Override
1990  public int getSupportedMaxExposure() {
1991  AlivcLog.i(TAG, "getSupportedMaxExposure");
1992  if (mNativeAlivcLivePusher == null) {
1993  AlivcLog.e(TAG, "Illegal State, you should init first");
1994  return -1;
1995  }
1996  if (mPushStatus != AlivcLivePushStats.PREVIEWED && mPushStatus != AlivcLivePushStats.PUSHED) {
1997  AlivcLog.e(TAG, "status error current state is " + AlivcLivePushStats.values()[mPushStatus.ordinal()]);
1998  return -1;
1999  }
2000  return mNativeAlivcLivePusher.getMaxExposureCompensation();
2001  }
2002 
2003  @Override
2004  public int setLiveMixTranscodingConfig(AlivcLiveTranscodingConfig config) {
2005  return -1;
2006  }
2007 
2008  @Override
2009  public int muteLocalCamera(boolean mute) {
2010  // TODO need implement
2011  return -1;
2012  }
2013 
2014  @Override
2015  public int enableSpeakerphone(boolean enable) {
2016  // TODO need implement
2017  return -1;
2018  }
2019 
2020  @Override
2021  public boolean isSpeakerphoneOn() {
2022  // TODO need implement
2023  return false;
2024  }
2025 
2032  @Override
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");
2037  return;
2038  }
2039  if (mPushStatus != AlivcLivePushStats.PREVIEWED && mPushStatus != AlivcLivePushStats.PUSHED) {
2040  AlivcLog.e(TAG, "status error current state is " + AlivcLivePushStats.values()[mPushStatus.ordinal()]);
2041  return;
2042  }
2043  mNativeAlivcLivePusher.setCameraZoom(zoom);
2044  }
2045 
2052  @Override
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");
2057  return -1;
2058  }
2059  if (mPushStatus != AlivcLivePushStats.PREVIEWED && mPushStatus != AlivcLivePushStats.PUSHED) {
2060  AlivcLog.e(TAG, "status error current state is " + AlivcLivePushStats.values()[mPushStatus.ordinal()]);
2061  return -1;
2062  }
2063  return mNativeAlivcLivePusher.getCameraMaxZoom();
2064  }
2065 
2072  @Override
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");
2077  return -1;
2078  }
2079  if (mPushStatus != AlivcLivePushStats.PREVIEWED && mPushStatus != AlivcLivePushStats.PUSHED) {
2080  AlivcLog.e(TAG, "status error current state is " + AlivcLivePushStats.values()[mPushStatus.ordinal()]);
2081  return -1;
2082  }
2083 
2084  return mNativeAlivcLivePusher.getCameraCurrentZoom();
2085  }
2086 
2093  @Override
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");
2098  return;
2099  }
2100  if (mPushStatus != AlivcLivePushStats.PREVIEWED && mPushStatus != AlivcLivePushStats.PUSHED && mPushStatus != AlivcLivePushStats.PAUSED) {
2101  AlivcLog.e(TAG, "status error current state is " + AlivcLivePushStats.values()[mPushStatus.ordinal()]);
2102  return;
2103  }
2104  mNativeAlivcLivePusher.setMute(mute);
2105 
2106  mMute = mute;
2107  //send mute event
2108  if (mLiveEventReporter != null) {
2109  if (mute) {
2110  PusherMuteOnEvent.Args args = new PusherMuteOnEvent.Args();
2111  mLiveEventReporter.sendEvent(PusherMuteOffEvent.kTopicType, PusherMuteOffEvent.kTopicValue, PusherMuteOnEvent.getArgsStr(args));
2112  } else {
2113  PusherMuteOffEvent.Args args = new PusherMuteOffEvent.Args();
2114  mLiveEventReporter.sendEvent(PusherMuteOffEvent.kTopicType, PusherMuteOffEvent.kTopicValue, PusherMuteOffEvent.getArgsStr(args));
2115  }
2116  }
2117  }
2118 
2125  @Override
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");
2130  return;
2131  }
2132  if (mPushStatus != AlivcLivePushStats.PREVIEWED && mPushStatus != AlivcLivePushStats.PUSHED) {
2133  AlivcLog.e(TAG, "status error current state is " + AlivcLivePushStats.values()[mPushStatus.ordinal()]);
2134  return;
2135  }
2136  mNativeAlivcLivePusher.setFlash(flash);
2137  mAlivcLivePushConfig.setFlash(flash);
2138  //send flash event
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));
2143  }
2144  }
2145 
2152  @Override
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");
2157  return;
2158  }
2159  if (mPushStatus != AlivcLivePushStats.PREVIEWED && mPushStatus != AlivcLivePushStats.PUSHED) {
2160  AlivcLog.e(TAG, "status error current state is " + AlivcLivePushStats.values()[mPushStatus.ordinal()]);
2161  return;
2162  }
2163  mNativeAlivcLivePusher.setPusherMirror(mirror);
2164  }
2165 
2172  @Override
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");
2177  return;
2178  }
2179  if (mPushStatus != AlivcLivePushStats.PREVIEWED && mPushStatus != AlivcLivePushStats.PUSHED) {
2180  AlivcLog.e(TAG, "status error current state is " + AlivcLivePushStats.values()[mPushStatus.ordinal()]);
2181  return;
2182  }
2183  mNativeAlivcLivePusher.setPreviewMirror(mirror);
2184  }
2185 
2192  @Override
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");
2197  return;
2198  }
2199  if (mPushStatus != AlivcLivePushStats.PREVIEWED && mPushStatus != AlivcLivePushStats.PUSHED) {
2200  AlivcLog.e(TAG, "status error current state is " + AlivcLivePushStats.values()[mPushStatus.ordinal()]);
2201  return;
2202  }
2203  mNativeAlivcLivePusher.setVideoBitrateRange(0, targetVideoBitrate, targetVideoBitrate);
2204  }
2205 
2212  @Override
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");
2217  return;
2218  }
2219  if (mPushStatus != AlivcLivePushStats.PREVIEWED && mPushStatus != AlivcLivePushStats.PUSHED) {
2220  AlivcLog.e(TAG, "status error current state is " + AlivcLivePushStats.values()[mPushStatus.ordinal()]);
2221  return;
2222  }
2223  mNativeAlivcLivePusher.setVideoBitrateRange(minVideoBitrate, 0, 0);
2224  }
2225 
2231  @Override
2232  public boolean isCameraSupportAutoFocus() {
2233  AlivcLog.i(TAG, "isCameraSupportAutoFocus");
2234  if (mNativeAlivcLivePusher == null) {
2235  AlivcLog.e(TAG, "Illegal State, you should init first");
2236  return false;
2237  }
2238  if (mPushStatus != AlivcLivePushStats.PREVIEWED && mPushStatus != AlivcLivePushStats.PUSHED) {
2239  AlivcLog.e(TAG, "status error current state is " + AlivcLivePushStats.values()[mPushStatus.ordinal()]);
2240  return false;
2241  }
2242  return mNativeAlivcLivePusher.isCameraSupportAutoFocus();
2243  }
2244 
2250  @Override
2251  public boolean isCameraSupportFlash() {
2252  AlivcLog.i(TAG, "isCameraSupportFlash");
2253 
2254  if (mNativeAlivcLivePusher == null) {
2255  AlivcLog.e(TAG, "Illegal State, you should init first");
2256  return false;
2257  }
2258  if (mPushStatus != AlivcLivePushStats.PREVIEWED && mPushStatus != AlivcLivePushStats.PUSHED) {
2259  AlivcLog.e(TAG, "status error current state is " + AlivcLivePushStats.values()[mPushStatus.ordinal()]);
2260  return false;
2261  }
2262  return mNativeAlivcLivePusher.isCameraSupportFlash();
2263  }
2264 
2271  @Override
2272  public boolean isPushing() throws IllegalStateException {
2273  // AlivcLog.d(TAG, "isPushing");
2274 
2275  if (mNativeAlivcLivePusher != null) {
2276  return mNativeAlivcLivePusher.isPushing();
2277  }
2278  return false;
2279  }
2280 
2286  @Override
2287  public AlivcLivePushStats getCurrentStatus() {
2288  return mPushStatus;
2289  }
2290 
2296  @Override
2297  public AlivcLivePushError getLastError() {
2298  return mLastError;
2299  }
2300 
2308  @Override
2309  public void snapshot(int count, int interval, AlivcSnapshotListener listener) {
2310  mSnapshotListener = listener;
2311  if (mNativeAlivcLivePusher != null) {
2312  mNativeAlivcLivePusher.snapshot(count, interval, mInnerSnapshotListener);
2313  }
2314  }
2315 
2322  @Override
2323  public boolean isNetworkPushing() throws IllegalStateException {
2324  // AlivcLog.d(TAG, "isNetworkPushing");
2325 
2326  if (mNativeAlivcLivePusher != null) {
2327  return mNativeAlivcLivePusher.isNetworkPushing();
2328  }
2329  return false;
2330  }
2331 
2337  @Override
2338  public void setLivePushErrorListener(AlivcLivePushErrorListener errorListener) {
2339  this.mPushErrorListener = errorListener;
2340  }
2341 
2347  @Override
2348  public void setLivePushInfoListener(AlivcLivePushInfoListener infoListener) {
2349  this.mPushInfoListener = infoListener;
2350  }
2351 
2357  @Override
2358  public void setLivePushNetworkListener(AlivcLivePushNetworkListener networkListner) {
2359  this.mPushNetworkListener = networkListner;
2360  }
2361 
2367  @Override
2368  public void setLivePushBGMListener(AlivcLivePushBGMListener pushBGMListener) {
2369  this.mPushBGMListener = pushBGMListener;
2370  }
2371 
2377  @Override
2378  public void setLivePushRenderContextListener(AlivcLivePusherRenderContextListener renderCtxListener) {
2379  this.mRenderContextListener = renderCtxListener;
2380  }
2381 
2388  @Override
2389  public AlivcLivePushStatsInfo getLivePushStatsInfo() throws IllegalStateException {
2390  // AlivcLog.d(TAG, "getLivePushStatsInfo");
2391 
2392  if (mNativeAlivcLivePusher == null) {
2393  return null;
2394  }
2395  AlivcLivePushStatsInfo info = new AlivcLivePushStatsInfo();
2396  String mapStr = mNativeAlivcLivePusher.getPerformanceInfo();
2397  if (mapStr == null || "".equals(mapStr)) {
2398  return null;
2399  }
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(), ":");
2405  }
2406  try {
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"));
2458 
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());
2466  }
2467  }
2468  } catch (IllegalStateException e) {
2469  e.printStackTrace();
2470  } catch (Exception e) {
2471  e.printStackTrace();
2472  }
2473  return info;
2474  }
2475 
2481  @Override
2482  public String getPushUrl() {
2483  return AlivcLiveURLTools.getUrlWithoutParameters(mPushUrl);
2484  }
2485 
2486  private void checkConfig(AlivcLivePushConfig livePushConfig) throws IllegalStateException {
2487  if (livePushConfig == null) {
2488  throw new IllegalArgumentException("Invalid parameter, config is null.");
2489  }
2490 
2491  if (livePushConfig.isVideoOnly() && livePushConfig.isAudioOnly()) {
2492  throw new IllegalStateException("cannot set video only and audio only simultaneously");
2493  }
2494 
2495  if (livePushConfig.getTargetVideoBitrate() < 100 || livePushConfig.getTargetVideoBitrate() > 5000) {
2496  throw new IllegalStateException("video target bitrate error, Range:[100 5000]");
2497  }
2498  if (livePushConfig.getMinVideoBitrate() < 100 || livePushConfig.getMinVideoBitrate() > 5000) {
2499  throw new IllegalStateException("video min bitrate error, Range:[100 5000]");
2500  }
2501  if (livePushConfig.getInitialVideoBitrate() < livePushConfig.getMinVideoBitrate() || livePushConfig.getInitialVideoBitrate() < 100
2502  || livePushConfig.getInitialVideoBitrate() > 5000) {
2503  throw new IllegalStateException("init bitrate error");
2504  }
2505  if (livePushConfig.getConnectRetryCount() <= 0 || livePushConfig.getConnectRetryCount() > 100) {
2506  throw new IllegalStateException("connect retry count error, Range:[0 100]");
2507  }
2508  if (livePushConfig.getConnectRetryInterval() <= 0 || livePushConfig.getConnectRetryInterval() > 10000) {
2509  throw new IllegalStateException("connect retry interval error, Range:[0 10000]");
2510  }
2511 
2512  if (livePushConfig.getMinFps() <= 0 || livePushConfig.getMinFps() > livePushConfig.getFps()) {
2513  throw new IllegalStateException("fps error");
2514  }
2515 
2516  for (int i = 0; i < livePushConfig.getWaterMarkInfos().size(); i++) {
2517 
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");
2521  }
2522 
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");
2526  }
2527  }
2528  }
2529 
2535  @Override
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");
2540  return;
2541  }
2542  if (mPushStatus != AlivcLivePushStats.PREVIEWED && mPushStatus != AlivcLivePushStats.PUSHED) {
2543  AlivcLog.e(TAG, "status error current state is " + AlivcLivePushStats.values()[mPushStatus.ordinal()]);
2544  return;
2545  }
2546 
2547  mNativeAlivcLivePusher.setOrientaion(orientation.getOrientation());
2548  }
2549 
2550  @Override
2551  public int setAudioEffectVoiceChangeMode(AlivcLivePushAudioEffectVoiceChangeMode mode) {
2552  AlivcLog.i(TAG, "setAudioEffectVoiceChangeMode: " + mode);
2553 
2554  if (mNativeAlivcLivePusher == null || mAlivcLivePushConfig == null) {
2555  AlivcLog.e(TAG, "Illegal State, you should init first");
2556  return -1;
2557  }
2558 
2559  if (mAlivcLivePushConfig.isVideoOnly()) {
2560  AlivcLog.e(TAG, "Sound effect can not be used on the video only mode!");
2561  return -1;
2562  }
2563 
2564  return mNativeAlivcLivePusher.setNativeAudioEffectVoiceMode(mode.getValue());
2565  }
2566 
2567  @Override
2568  public int setAudioEffectReverbMode(AlivcLivePushAudioEffectReverbMode mode) {
2569  AlivcLog.i(TAG, "setAudioEffectReverbMode: " + mode);
2570 
2571  if (mNativeAlivcLivePusher == null || mAlivcLivePushConfig == null) {
2572  AlivcLog.e(TAG, "Illegal State, you should init first");
2573  return -1;
2574  }
2575 
2576  if (mAlivcLivePushConfig.isVideoOnly()) {
2577  AlivcLog.e(TAG, "Sound effect can not be used on the video only mode!");
2578  return -1;
2579  }
2580 
2581  return mNativeAlivcLivePusher.setNativeAudioEffectReverbMode(mode.getValue());
2582  }
2583 
2584  private Map<String, String> getPerformanceMap() {
2585  if (mNativeAlivcLivePusher == null) {
2586  return null;
2587  }
2588  String mapStr = mNativeAlivcLivePusher.getPerformanceInfo();
2589  if (mapStr == null || "".equals(mapStr)) {
2590  return null;
2591  }
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(), ":");
2597  }
2598  return map;
2599  }
2600 
2601  private String getHeartBeatInfo() {
2602  if (mNativeAlivcLivePusher == null) {
2603  return null;
2604  }
2605 
2606  String heartBeatInfo = mNativeAlivcLivePusher.getPusherInfo();
2607  heartBeatInfo += ",cpu:" + AliLiveInfoUtils.getCPUUsageRatio();
2608  heartBeatInfo += ",mem:" + AliLiveInfoUtils.getMemoryUsageRatio();
2609 
2610  return heartBeatInfo;
2611  }
2612 
2613  @Override
2614  public String getLiveTraceId() {
2615  if (mNativeAlivcLivePusher == null) {
2616  return null;
2617  }
2618  return mNativeAlivcLivePusher.getPusherTraceId();
2619  }
2620 
2629  @Override
2630  public void sendMessage(String info, int repeat, int delay, boolean isKeyFrame) {
2631  AlivcLog.i(TAG, "sendMessage: " + info + ", repeat:" + repeat + ", delay:" + delay + ", isKeyFrame:" + isKeyFrame);
2632 
2633  try {
2634  sendMessageInternal(info, repeat, delay, isKeyFrame, false);
2635  } catch (Exception e) {
2636  e.printStackTrace();
2637  }
2638  }
2639 
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");
2643  return;
2644  }
2645  if (!mNativeAlivcLivePusher.isPushing()) {
2646  AlivcLog.e(TAG, "Status error, status should be PUSHED");
2647  return;
2648  }
2649  if (TextUtils.isEmpty(info) || info.length() > MAX_CHATS) {
2650  AlivcLog.e(TAG, "The maximum length is 4000");
2651  return;
2652  }
2653  mNativeAlivcLivePusher.addSeiInfo(info, repeat, delay, isKeyFrame, isGDelayInfo);
2654  }
2655 
2656  private int getBGMVolume() {
2657  if (mMute) {
2658  return 0;
2659  }
2660  return mBGMVolume;
2661  }
2662 
2663  private int getCaptureVolume() {
2664  if (mMute) {
2665  return 0;
2666  }
2667  return mCaptureVolume;
2668  }
2669 
2670  private boolean getHeadSetPlugOn() {
2671  return LivePusherJNI.headSetOn;
2672  }
2673 
2674  private boolean getBlueToothHeadSetOn() {
2675  if (mBluetoothHelper != null) {
2676  return mBluetoothHelper.isOnHeadsetSco();
2677  }
2678  return false;
2679  }
2680 
2687  @Override
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");
2692  return;
2693  }
2694  if (mPushStatus == AlivcLivePushStats.IDLE || mPushStatus == AlivcLivePushStats.ERROR) {
2695  AlivcLog.e(TAG, "status error current state is " + AlivcLivePushStats.values()[mPushStatus.ordinal()]);
2696  return;
2697  }
2698 
2699  if (mPlayStats == AlivcLivePlayStats.IDLE || mPlayStats == AlivcLivePlayStats.STOPPED) {
2700  PusherSetBGMEvent.Args args = new PusherSetBGMEvent.Args();
2701  args.isOpen = true;
2702  args.music = getBGMVolume();
2703  args.voice = getCaptureVolume();
2704  if (mLiveEventReporter != null) {
2705  mLiveEventReporter.sendEvent(PusherSetBGMEvent.kTopicType, PusherSetBGMEvent.kTopicValue, PusherSetBGMEvent.getArgsStr(args));
2706  }
2707  }
2708 
2709  //mNativeAlivcLivePusher.resumeBGM();
2710  mNativeAlivcLivePusher.stopBGM();
2711  mNativeAlivcLivePusher.startBGMAsync(path);
2712  }
2713 
2719  @Override
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");
2724  return;
2725  }
2726  if (mPlayStats == AlivcLivePlayStats.IDLE) {
2727  AlivcLog.e(TAG, "status error current state is " + AlivcLivePlayStats.values()[mPlayStats.ordinal()]);
2728  return;
2729  }
2730 
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));
2738  }
2739  }
2740 
2746  @Override
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");
2751  return;
2752  }
2753  if (mPlayStats != AlivcLivePlayStats.STARTED) {
2754  AlivcLog.e(TAG, "status error current state is " + AlivcLivePlayStats.values()[mPlayStats.ordinal()]);
2755  return;
2756  }
2757 
2758  mNativeAlivcLivePusher.pauseBGM();
2759  }
2760 
2766  @Override
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");
2771  return;
2772  }
2773  if (mPlayStats != AlivcLivePlayStats.PAUSED) {
2774  AlivcLog.e(TAG, "status error current state is " + AlivcLivePlayStats.values()[mPlayStats.ordinal()]);
2775  return;
2776  }
2777 
2778  mNativeAlivcLivePusher.resumeBGM();
2779  }
2780 
2787  @Override
2788  public void setBGMLoop(boolean isLoop) throws IllegalStateException {
2789  if (mNativeAlivcLivePusher != null) {
2790  mNativeAlivcLivePusher.setBGMLoop(isLoop);
2791  }
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));
2796  }
2797  }
2798 
2805  @Override
2806  public void setBGMEarsBack(boolean isOpen) throws IllegalStateException {
2807  if (mNativeAlivcLivePusher != null) {
2808  mNativeAlivcLivePusher.setEarsBack(isOpen);
2809  }
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));
2816  }
2817  }
2818 
2825  @Override
2826  public void setBGMVolume(int volume) throws IllegalStateException, IllegalArgumentException {
2827  if (mNativeAlivcLivePusher == null) {
2828  AlivcLog.e(TAG, "Illegal State, you should init first");
2829  return;
2830  }
2831  mBGMVolume = (volume > 0 && volume < 10) ? 10 : volume;
2832  mNativeAlivcLivePusher.setBackgroundMusicVolume(mBGMVolume / 10);
2833  }
2834 
2841  @Override
2842  public void setCaptureVolume(int volume) throws IllegalStateException, IllegalArgumentException {
2843  if (mNativeAlivcLivePusher == null) {
2844  AlivcLog.e(TAG, "Illegal State, you should init first");
2845  return;
2846  }
2847  mCaptureVolume = (volume > 0 && volume < 10) ? 10 : volume;
2848  mNativeAlivcLivePusher.setAudioVolume(mCaptureVolume / 10);
2849  }
2850 
2857  @Override
2858  public void setAudioDenoise(boolean on) {
2859  AlivcLog.i(TAG, "setAudioDenoise, " + on);
2860 
2861  if (mNativeAlivcLivePusher == null || mAlivcLivePushConfig == null) {
2862  AlivcLog.e(TAG, "Illegal State, you should init first");
2863  return;
2864  }
2865 
2866  if (mAlivcLivePushConfig.isVideoOnly()) {
2867  AlivcLog.e(TAG, "Audio denoise can not be used on the video only mode!");
2868  return;
2869  }
2870 
2871  mNativeAlivcLivePusher.setAudioDenoise(on);
2872  }
2873 
2874  @Override
2875  public int startIntelligentDenoise() {
2876  AlivcLog.i(TAG, "startIntelligentDenoise");
2877  return setIntelligentDenoiseInternal(true);
2878  }
2879 
2880  @Override
2881  public int stopIntelligentDenoise() {
2882  AlivcLog.i(TAG, "stopIntelligentDenoise");
2883  return setIntelligentDenoiseInternal(false);
2884  }
2885 
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!");
2890  return -1;
2891  }
2892 
2893  if (mNativeAlivcLivePusher == null || mAlivcLivePushConfig == null) {
2894  AlivcLog.e(TAG, "Illegal State, you should init first");
2895  return -1;
2896  }
2897 
2898  if (mAlivcLivePushConfig.isVideoOnly()) {
2899  AlivcLog.e(TAG, "Audio denoise can not be used on the video only mode!");
2900  return -1;
2901  }
2902 
2903  int result = 0;
2904  if (flag) {
2905  result = mNativeAlivcLivePusher.startNativeIntelligentDenoise();
2906  } else {
2907  result = mNativeAlivcLivePusher.stopNativeIntelligentDenoise();
2908  }
2909 
2910  AlivcLog.i(TAG, "setIntelligentDenoiseInternal " + flag + ", return " + result);
2911  return result;
2912  }
2913 
2920  @Override
2921  public void setQualityMode(AlivcQualityModeEnum mode) throws IllegalStateException {
2922  if (mNativeAlivcLivePusher == null) {
2923  AlivcLog.e(TAG, "Illegal State, you should init first");
2924  return;
2925  }
2926  if (AlivcQualityModeEnum.QM_CUSTOM.equals(mode)) {
2927  AlivcLog.e(TAG, "Cannot set QM_CUSTOM dynamically");
2928  return;
2929  }
2930  mNativeAlivcLivePusher.setQualityMode(mode.getQualityMode());
2931  }
2932 
2939  @Override
2940  public void setPreviewMode(AlivcPreviewDisplayMode mode) throws IllegalStateException {
2941  if (mNativeAlivcLivePusher == null || mAlivcLivePushConfig == null) {
2942  AlivcLog.e(TAG, "Illegal State, you should init first");
2943  return;
2944  }
2945  if (mAlivcLivePushConfig.getMediaProjectionPermissionResultData() == null) {
2946  mNativeAlivcLivePusher.setDisplayMode(mode.getPreviewDisplayMode());
2947  }
2948  }
2949 
2950  private void startScheduleExecutor() {
2951  if (scheduleExecutor != null) {
2952  return;
2953  }
2954  if (scheduleExecutor == null || scheduleExecutor.isShutdown()) {
2955  scheduleExecutor = new ScheduledThreadPoolExecutor(1, new ThreadFactory() {
2956  private AtomicInteger atoInteger = new AtomicInteger(0);
2957 
2958  @Override
2959  public Thread newThread(Runnable r) {
2960  Thread t = new Thread(r);
2961  t.setName("LivePusher-report-Thread " + atoInteger.getAndIncrement());
2962  return t;
2963  }
2964  });
2965  }
2966  scheduleExecutor.scheduleAtFixedRate(new Runnable() {
2967 
2968  @Override
2969  public void run() {
2970  mTimeCount = mTimeCount + 1;
2971  if(mTimeCount == 5) {
2972  if (mTimeStamp != -1) {
2973  if (mExpiryTime < 60) {
2974  if (mPushNetworkListener != null) {
2975  String url = mPushNetworkListener.onPushURLAuthenticationOverdue(getLivePusherReference());
2976  if (!TextUtils.isEmpty(url) && !url.equals(mPushUrl)) {
2977  reconnectPushAsync(url);
2978  }
2979  }
2980  } else {
2981  mExpiryTime = mExpiryTime - 5;
2982  }
2983  }
2984 
2985  PusherHeartBeatEvent.Args args = new PusherHeartBeatEvent.Args();
2986  args.mediaInfo = getHeartBeatInfo();
2987  mLiveEventReporter.sendEvent(PusherHeartBeatEvent.kTopicType, PusherHeartBeatEvent.kTopicValue, PusherHeartBeatEvent.getArgsStr(args));
2988  mTimeCount = 0;
2989  }
2990  mPushInfoListener.onPushStatistics(getLivePusherReference(),getLivePushStatsInfo());
2991  }
2992  }, 0, 2 * 1000, TimeUnit.MILLISECONDS);
2993 
2994  }
2995 
2996  private int[] getImageWidthHeight(String path) {
2997  BitmapFactory.Options options = new BitmapFactory.Options();
2998 
2999  options.inJustDecodeBounds = true;
3000  try {
3001  Bitmap bitmap = BitmapFactory.decodeFile(path, options); // 此时返回的bitmap为null
3002  } catch (Exception e) {
3003  return new int[]{0, 0};
3004  }
3005 
3006  return new int[]{options.outWidth, options.outHeight};
3007  }
3008 
3009 
3010  private void addWaterMark() {
3011  if (mAlivcLivePushConfig == null) {
3012  AlivcLog.e(TAG, "Illegal State, you should init first");
3013  return;
3014  }
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);
3020  }
3021  }
3022 
3023  private void stop5Interval() {
3024  if (scheduleExecutor != null && !scheduleExecutor.isShutdown()) {
3025  scheduleExecutor.shutdown();
3026  }
3027  scheduleExecutor = null;
3028  }
3029 
3030  // RTS降级到RTMP逻辑
3031  private void rtsDownToRtmp() {
3032  AlivcLog.w(TAG, "rts downgrade to rtmp");
3033  if (TextUtils.isEmpty(mPushUrl) || !mPushUrl.startsWith(AlivcLiveStreamType.EnumType.AlivcLiveStreamRts.getPrefix())) {
3034  return;
3035  }
3036 
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;
3041 
3042  stopPush();
3043  if (mNativeAlivcLivePusher != null) {
3044  mNativeAlivcLivePusher.release();
3045  mNativeAlivcLivePusher.init();
3046  }
3047 
3048  startPushAsync(mPushUrl);
3049  }
3050 
3051  private void reportStartPushEvent(boolean isRestart, boolean isSync) {
3052  PusherStartPushEvent.Args args = new PusherStartPushEvent.Args();
3053  Map map = getPerformanceMap();
3054  if (map != null) {
3055  args.sync = isSync;
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";
3060  args.ao = mAlivcLivePushConfig.isAudioOnly();
3061  args.vo = mAlivcLivePushConfig.isVideoOnly();
3062  args.he = mAlivcLivePushConfig.getVideoEncodeMode().equals(Encode_MODE_HARD);//是否使用硬编
3063  args.wc = mAlivcLivePushConfig.getWaterMarkInfos().size();//水印
3064  args.pum = mAlivcLivePushConfig.isPushMirror();
3065  args.fps = mAlivcLivePushConfig.getFps();
3066  args.ivb = mAlivcLivePushConfig.getInitialVideoBitrate();
3067  args.mavb = mAlivcLivePushConfig.getTargetVideoBitrate();
3068  args.mivb = mAlivcLivePushConfig.getMinVideoBitrate();
3069  args.asr = mAlivcLivePushConfig.getAudioSampleRate().getAudioSampleRate();
3070  args.po = mAlivcLivePushConfig.getPreviewOrientation();
3071  args.ct = mAlivcLivePushConfig.getCameraType();
3072  args.flash = mAlivcLivePushConfig.isFlash();
3073  args.crmc = mAlivcLivePushConfig.getConnectRetryCount();
3074  args.cri = mAlivcLivePushConfig.getConnectRetryInterval();
3075  args.prm = mAlivcLivePushConfig.isPreviewMirror();
3076  args.gop = mAlivcLivePushConfig.getVideoEncodeGop();
3077  args.utm = (mAlivcLivePushConfig.getConnectRetryCount() * mAlivcLivePushConfig.getConnectRetryInterval()) / 1000;
3078 
3079  if (isRestart) {
3080  mLiveEventReporter.sendEvent(PusherRestartPushEvent.kTopicType, PusherRestartPushEvent.kTopicValue, PusherRestartPushEvent.getArgsStr(args));
3081  } else {
3082  mLiveEventReporter.sendEvent(PusherStartPushEvent.kTopicType, PusherStartPushEvent.kTopicValue, PusherStartPushEvent.getArgsStr(args));
3083  }
3084  }
3085  }
3086 
3087  private BroadcastReceiver mHeadsetPlugReceiver = new BroadcastReceiver() {
3088 
3089  @Override
3090  public void onReceive(Context context, Intent intent) {
3091 
3092  String action = intent.getAction();
3093  if (AudioManager.ACTION_AUDIO_BECOMING_NOISY.equals(action)) {
3094  AlivcLog.d("BluetoothHeadsetUtils", "ACTION_AUDIO_BECOMING_NOISY headset out");
3095  //拔出耳机
3096  mAudioManager.setMode(AudioManager.STREAM_VOICE_CALL);
3097  mAudioManager.setSpeakerphoneOn(true);
3098 
3099  LivePusherJNI.headSetOn = false;
3100  if (mNativeAlivcLivePusher != null) {
3101  mNativeAlivcLivePusher.setHeadSet(false);
3102  }
3103  } else if ("android.intent.action.HEADSET_PLUG".equals(action)) {// extra
3104  if (intent.hasExtra("state")) {
3105  if (intent.getIntExtra("state", 0) == 0) {
3106  AlivcLog.d("BluetoothHeadsetUtils", "headset out");
3107  //拔出耳机
3108  mAudioManager.setMode(AudioManager.STREAM_VOICE_CALL);
3109  mAudioManager.setSpeakerphoneOn(true);
3110 
3111  if (LivePusherJNI.headSetOn) {
3112  LivePusherJNI.headSetOn = false;
3113  if (mNativeAlivcLivePusher != null) {
3114  mNativeAlivcLivePusher.setHeadSet(false);
3115  }
3116  }
3117  } else if (intent.getIntExtra("state", 0) == 1) {
3118  //插上耳机
3119  AlivcLog.d("BluetoothHeadsetUtils", "headset in");
3120  mAudioManager.setSpeakerphoneOn(false);//
3121  LivePusherJNI.headSetOn = true;
3122  if (mNativeAlivcLivePusher != null) {
3123  mNativeAlivcLivePusher.setHeadSet(true);
3124  }
3125  }
3126  }
3127  }
3128  }
3129 
3130  };
3131 
3132  private BroadcastReceiver mTelephoneReceiver = new BroadcastReceiver() {
3133  @Override
3134  public void onReceive(Context context, Intent intent) {
3135  if (intent.getAction().equals(Intent.ACTION_NEW_OUTGOING_CALL)) {
3136 
3137  } else {
3138  if (manager == null) {
3139  if (Looper.myLooper() == null) {
3140  Looper.prepare();
3141  }
3142  manager = (TelephonyManager) context.getSystemService(Service.TELEPHONY_SERVICE);
3143  manager.listen(new PhoneStateListener() {
3144  @Override
3145  public void onCallStateChanged(int state, String incomingNumber) {
3146  super.onCallStateChanged(state, incomingNumber);
3147  switch (state) {
3148  case TelephonyManager.CALL_STATE_IDLE:
3149  //挂断
3150  AlivcLog.i(TAG, "PHONE: CALL_STATE_IDLE");
3151  if (mNativeAlivcLivePusher != null) {
3152  mNativeAlivcLivePusher.setMute(false);
3153  }
3154  break;
3155  case TelephonyManager.CALL_STATE_OFFHOOK:
3156  //接听
3157  AlivcLog.i(TAG, "PHONE: CALL_STATE_OFFHOOK");
3158  if (mNativeAlivcLivePusher != null) {
3159  mNativeAlivcLivePusher.setMute(true);
3160  }
3161  break;
3162  case TelephonyManager.CALL_STATE_RINGING:
3163  //响铃
3164  AlivcLog.i(TAG, "PHONE: CALL_STATE_RINGING");
3165  if (mNativeAlivcLivePusher != null) {
3166  mNativeAlivcLivePusher.setMute(true);
3167  }
3168  break;
3169  default:
3170  break;
3171  }
3172  }
3173  }, PhoneStateListener.LISTEN_CALL_STATE);
3174  Looper.loop();
3175  }
3176  }
3177  }
3178  };
3179 
3180  private void registerHeadsetPlugReceiver() {
3181  //for ear headset receiver, extra
3182  IntentFilter intentFilter = new IntentFilter();
3183  intentFilter.addAction("android.intent.action.HEADSET_PLUG");
3184  mContext.registerReceiver(mHeadsetPlugReceiver, intentFilter);
3185 
3186  IntentFilter intentFilter1 = new IntentFilter(AudioManager.ACTION_AUDIO_BECOMING_NOISY);
3187  mContext.registerReceiver(mHeadsetPlugReceiver, intentFilter1);
3188 
3189 
3190  IntentFilter intentTelephony = new IntentFilter();
3191  intentTelephony.addAction("android.intent.action.PHONE_STATE");
3192  mContext.registerReceiver(mTelephoneReceiver, intentTelephony);
3193 
3194  registeredCallback = true;
3195  }
3196 
3197  private void LogWhenGoBackOrFront(Application app, boolean bind) {
3198  if(bind){
3199  mAppFrontBackHelper = new AppFrontBackHelper();
3200  mAppFrontBackHelper.bindApplication(app, new AppFrontBackHelper.OnAppStatusListener() {
3201  @Override
3202  public void onFront() {
3203  if (mNativeAlivcLivePusher != null) {
3204  AlivcLog.i(TAG, "applicationWillBecomeActive");
3205  mNativeAlivcLivePusher.setAppBackgroundState(false);
3206  }
3207  }
3208 
3209  @Override
3210  public void onBack() {
3211  if (mNativeAlivcLivePusher != null) {
3212  AlivcLog.i(TAG, "applicationWillResignActive");
3213  mNativeAlivcLivePusher.setAppBackgroundState(true);
3214  }
3215  }
3216  });
3217  } else {
3218  if(mAppFrontBackHelper != null){
3219  mAppFrontBackHelper.unBindApplication(app);
3220  mAppFrontBackHelper = null;
3221  }
3222  }
3223  }
3224 
3225  private void getNetworkTime() {
3226  new ScheduledThreadPoolExecutor(1, new ThreadFactory() {
3227  private AtomicInteger atoInteger = new AtomicInteger(0);
3228 
3229  @Override
3230  public Thread newThread(Runnable r) {
3231  Thread t = new Thread(r);
3232  t.setName("LivePusher-NTP-Time-Thread " + atoInteger.getAndIncrement());
3233  return t;
3234  }
3235  }).execute(new Runnable() {
3236  @Override
3237  public void run() {
3238  for (int i = 0; i < 3; i++) {
3239  mTimeStamp = getTimeFromNtpServer("time.pool.aliyun.com");
3240  if (mTimeStamp > 0) {
3241  mTimeStamp = mTimeStamp / 1000;
3242  break;
3243  }
3244  }
3245  if (mTimeStamp < 0) {
3246  mTimeStamp = System.currentTimeMillis() / 1000;
3247  }
3248  if (getTimestamp(mPushUrl) != -1) {
3249  mExpiryTime = (int) ((getTimestamp(mPushUrl) - mTimeStamp));
3250  }
3251  }
3252  });
3253  }
3254 
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);
3259  if (isSuccessful) {
3260  return client.getNtpTime();
3261  }
3262  return -1;
3263  }
3264 
3274  @Override
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");
3278  return;
3279  }
3280  int[] widthHeight = getImageWidthHeight(path);
3281  if (mWatermarkCount >= AlivcLiveMaxWatermarkCount || widthHeight == null || widthHeight[0] == 0 || widthHeight[1] == 0) {
3282  return;
3283  }
3284 
3285  float w = width;
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()) {
3289  h = h * mAlivcLivePushConfig.getHeight() / mAlivcLivePushConfig.getWidth();
3290  } else {
3291  h = h * mAlivcLivePushConfig.getWidth() / mAlivcLivePushConfig.getHeight();
3292  }
3293  // 逻辑与IOS端同步
3294  mNativeAlivcLivePusher.addWaterMark(path, w, h, x + w / 2, y + h / 2);
3295  mWatermarkCount++;
3296  }
3297 
3303  @Override
3304  public void setWatermarkVisible(boolean visible) {
3305  if (mNativeAlivcLivePusher == null) {
3306  AlivcLog.e(TAG, "Illegal State, you should init first");
3307  return;
3308  }
3309  if (mPushStatus != AlivcLivePushStats.PREVIEWED) {
3310  AlivcLog.e(TAG, "status error current state is " + AlivcLivePushStats.values()[mPushStatus.ordinal()]);
3311  return;
3312  }
3313  if (mWatermarkCount <= 0) {
3314  return;
3315  }
3316  mNativeAlivcLivePusher.setWaterMarkVisible(visible);
3317  }
3318 
3326  @Override
3327  public int startCamera(SurfaceView surfaceView) throws IllegalStateException {
3328  if (mNativeAlivcLivePusher == null || mAlivcLivePushConfig == null) {
3329  AlivcLog.e(TAG, "Please execute init first ");
3330  return -1;
3331  }
3332  if (mAlivcLivePushConfig.getMediaProjectionPermissionResultData() == null) {
3333  AlivcLog.e(TAG, "Not in ScreenCapture Mode");
3334  return -1;
3335  }
3336  if (!ScreenRecordStatus.SCREEN_RECORD_NORMAL.equals(mScreenStatus)) {
3337  AlivcLog.e(TAG, "you should start push screen first");
3338  return -1;
3339  }
3340  Surface surface = null;
3341  if (surfaceView != null) {
3342  surface = surfaceView.getHolder().getSurface();
3343  }
3344  int ret = mNativeAlivcLivePusher.startCamera(surface);
3345  mScreenStatus = ScreenRecordStatus.SCREEN_RECORD_CAMERA_START;
3346  return ret;
3347  }
3348 
3354  @Override
3355  public void setScreenOrientation(int orientation) {
3356  if (mNativeAlivcLivePusher == null || mAlivcLivePushConfig == null) {
3357  AlivcLog.e(TAG, "Please execute init first ");
3358  return;
3359  }
3360  if (mAlivcLivePushConfig.getMediaProjectionPermissionResultData() == null) {
3361  AlivcLog.e(TAG, "Not in ScreenCapture Mode");
3362  return;
3363  }
3364  mNativeAlivcLivePusher.setScreenOrientation(orientation);
3365  }
3366 
3370  @Override
3371  public void stopCamera() {
3372  if (mNativeAlivcLivePusher == null || mAlivcLivePushConfig == null) {
3373  AlivcLog.e(TAG, "Please execute init first ");
3374  return;
3375  }
3376  if (mAlivcLivePushConfig.getMediaProjectionPermissionResultData() == null) {
3377  AlivcLog.e(TAG, "Not in ScreenCapture Mode");
3378  return;
3379  }
3380  mNativeAlivcLivePusher.stopCamera();
3381  mScreenStatus = ScreenRecordStatus.SCREEN_RECORD_NORMAL;
3382  }
3383 
3393  @Override
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 ");
3397  return -1;
3398  }
3399  if (mAlivcLivePushConfig.getMediaProjectionPermissionResultData() == null) {
3400  AlivcLog.e(TAG, "Not in ScreenCapture Mode");
3401  return -1;
3402  }
3403  if (!mScreenStatus.equals(ScreenRecordStatus.SCREEN_RECORD_CAMERA_START)) {
3404  AlivcLog.e(TAG, "You should start camera first");
3405  return -1;
3406  }
3407  int ret = mNativeAlivcLivePusher.startCameraMix(x, y, w, h);
3408  mScreenStatus = ScreenRecordStatus.SCREEN_RECORD_CAMERA_MIX_START;
3409  return ret;
3410  }
3411 
3415  @Override
3416  public void stopCameraMix() {
3417  if (mNativeAlivcLivePusher == null || mAlivcLivePushConfig == null) {
3418  AlivcLog.e(TAG, "Please execute init first ");
3419  return;
3420  }
3421  if (mAlivcLivePushConfig.getMediaProjectionPermissionResultData() == null) {
3422  AlivcLog.e(TAG, "Not in ScreenCapture Mode");
3423  return;
3424  }
3425  mNativeAlivcLivePusher.stopCameraMix();
3426  mScreenStatus = ScreenRecordStatus.SCREEN_RECORD_CAMERA_START;
3427  }
3428 
3434  @Override
3435  public void changeResolution(AlivcResolutionEnum resolutionEnum) {
3436  if (mNativeAlivcLivePusher == null) {
3437  AlivcLog.e(TAG, "Please execute init first!");
3438  return;
3439  }
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");
3442  return;
3443  }
3444  mNativeAlivcLivePusher.changeResolution(AlivcResolutionEnum.GetResolutionWidth(resolutionEnum), AlivcResolutionEnum.GetResolutionHeight(resolutionEnum));
3445  }
3446 
3447  public int mixStreamRequireMain(int vid, boolean require) {
3448  if (mNativeAlivcLivePusher == null) {
3449  return -1;
3450  }
3451  return mNativeAlivcLivePusher.mixStreamRequireMain(vid, require);
3452  }
3453 
3454  public int mixStreamChangePosition(int vid, float x, float y, float w, float h) {
3455  if (mNativeAlivcLivePusher == null) {
3456  return -1;
3457  }
3458  return mNativeAlivcLivePusher.mixStreamChangePosition(vid, x, y, w, h);
3459  }
3460 
3461  public void mixStreamMirror(int vid, boolean mirror) {
3462  if (mNativeAlivcLivePusher == null) {
3463  return;
3464  }
3465  mNativeAlivcLivePusher.setMixStreamMirror(vid, mirror);
3466  }
3467 
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) {
3483  return -1;
3484  }
3485  return mNativeAlivcLivePusher.addMixVideo(format.getAlivcImageFormat(), width, height, rotation, displayX, displayY, displayW, displayH, adjustHeight);
3486  }
3487 
3493  public void removeMixVideo(int handler) {
3494  if (mNativeAlivcLivePusher == null) {
3495  return;
3496  }
3497  mNativeAlivcLivePusher.removeMixVideo(handler);
3498  }
3499 
3512  public void inputMixTexture(int handler, int texture, int width, int height, long pts, int rotation) {
3513  if (mNativeAlivcLivePusher == null) {
3514  return;
3515  }
3516  mNativeAlivcLivePusher.inputMixTexture(handler, texture, width, height, pts, rotation);
3517  }
3518 
3532  public void inputMixVideoPtr(int handler, long dataptr, int width, int height, int stride, int size, long pts, int rotation) {
3533  if (mNativeAlivcLivePusher == null) {
3534  return;
3535  }
3536  mNativeAlivcLivePusher.inputMixVideoPtr(handler, dataptr, width, height, stride, size, pts, rotation);
3537  }
3538 
3552  public void inputMixVideoData(int handler, byte[] data, int width, int height, int stride, int size, long pts, int rotation) {
3553  if (mNativeAlivcLivePusher == null) {
3554  return;
3555  }
3556  mNativeAlivcLivePusher.inputMixVideoData(handler, data, width, height, stride, size, pts, rotation);
3557  }
3558 
3567  public int addMixAudio(int channels, AlivcSoundFormat format, int audioSample) {
3568  if (mNativeAlivcLivePusher == null) {
3569  return -1;
3570  }
3571  return mNativeAlivcLivePusher.addMixAudio(channels, format.getAlivcSoundFormat(), audioSample);
3572  }
3573 
3579  public void removeMixAudio(int handler) {
3580  if (mNativeAlivcLivePusher == null) {
3581  return;
3582  }
3583  mNativeAlivcLivePusher.removeMixAudio(handler);
3584  }
3585 
3596  public boolean inputMixAudioPtr(int handler, long dataptr, int size, long pts) {
3597  if (mNativeAlivcLivePusher == null) {
3598  return false;
3599  }
3600  return mNativeAlivcLivePusher.inputMixAudioPtr(handler, dataptr, size, pts);
3601  }
3602 
3612  public boolean inputMixAudioData(int handler, byte[] data, int size, long pts) {
3613  if (mNativeAlivcLivePusher == null) {
3614  return false;
3615  }
3616  return mNativeAlivcLivePusher.inputMixAudioData(handler, data, size, pts);
3617  }
3618 
3630  @Override
3631  public void inputStreamVideoPtr(long dataptr, int width, int height, int stride, int size, long pts, int rotation) {
3632  if (mNativeAlivcLivePusher == null) {
3633  return;
3634  }
3635  mNativeAlivcLivePusher.inputStreamVideoPtr(dataptr, width, height, stride, size, pts, rotation);
3636  }
3637 
3650  public void inputStreamTexture(int textureId, int width, int height, int stride, long pts, int rotation, long extra) {
3651  if (mNativeAlivcLivePusher == null) {
3652  return;
3653  }
3654  mNativeAlivcLivePusher.inputStreamTexture(textureId, width, height, stride, pts, rotation, extra);
3655  }
3656 
3668  @Override
3669  public void inputStreamVideoData(byte[] data, int width, int height, int stride, int size, long pts, int rotation) {
3670  if (mNativeAlivcLivePusher == null) {
3671  return;
3672  }
3673  mNativeAlivcLivePusher.inputStreamVideoData(data, width, height, stride, size, pts, rotation);
3674  }
3675 
3684  @Override
3685  public void inputStreamAudioPtr(long dataPtr, int size, int sampleRate, int channels, long pts) {
3686  if (mNativeAlivcLivePusher == null) {
3687  return;
3688  }
3689  mNativeAlivcLivePusher.inputStreamAudioPtr(dataPtr, size, sampleRate, channels, pts);
3690  }
3691 
3700  @Override
3701  public void inputStreamAudioData(byte[] data, int size, int sampleRate, int channels, long pts) {
3702  if (mNativeAlivcLivePusher == null) {
3703  return;
3704  }
3705  mNativeAlivcLivePusher.inputStreamAudioData(data, size, sampleRate, channels, pts);
3706  }
3707 
3718  @Override
3719  public int addDynamicsAddons(String path, float x, float y, float w, float h) throws IllegalArgumentException {
3720  if (mNativeAlivcLivePusher == null) {
3721  return -1;
3722  }
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]");
3725  return -1;
3726  }
3727  if (mDynamicAddsonCount >= MAX_DYNAMIC_ADDSON_COUNT) {
3728  return -1;
3729  }
3730  mDynamicAddsonCount++;
3731  return mNativeAlivcLivePusher.addDynamicsAddons(path, System.currentTimeMillis() * 1000, 0, x, y, w, h, 0, false);
3732  }
3733 
3739  @Override
3740  public void removeDynamicsAddons(int id) {
3741  if (mNativeAlivcLivePusher == null) {
3742  return;
3743  }
3744  mDynamicAddsonCount--;
3745  mNativeAlivcLivePusher.removeDynamicsAddons(id);
3746  }
3747 
3748  public void setMainStreamPosition(float startX, float startY, float w, float h) {
3749  if (mNativeAlivcLivePusher == null) {
3750  return;
3751  }
3752  mNativeAlivcLivePusher.setMainStreamPosition(startX, startY, w, h);
3753  }
3754 
3755  private String getFormatString(String string) {
3756  String result = "";
3757  int index = string.indexOf(AUTH_KEY);
3758  if (index > 0) {
3759  String temp = string.substring(index);
3760  if (temp.indexOf("-") > 0) {
3761  result = temp.substring(AUTH_KEY.length(), temp.indexOf("-"));
3762  } else {
3763  result = temp.substring(AUTH_KEY.length());
3764  }
3765  }
3766  return result;
3767  }
3768 
3769  private int getTimestamp(String string) {
3770  int result = -1;
3771  String tempStamp = getFormatString(string);
3772  if (tempStamp.length() < 10) {
3773  return -1;
3774  }
3775  if (TextUtils.isDigitsOnly(tempStamp)) {
3776  return new Long(Long.valueOf(tempStamp)).intValue();
3777  }
3778 
3779  return result;
3780  }
3781 
3782  private AlivcSnapshotListener mInnerSnapshotListener = new AlivcSnapshotListener() {
3783  @Override
3784  public void onSnapshot(final Bitmap bmp) {
3785  if (mSnapshotListener != null) {
3786  mThreadPoolExecutor.execute(new Runnable() {
3787  @Override
3788  public void run() {
3789  mSnapshotListener.onSnapshot(bmp);
3790  }
3791  });
3792  }
3793  }
3794  };
3795 }
推流截图结果异步回调通知
void onReconnectStart(AlivcLivePusher pusher)
void onFirstFramePreviewed(AlivcLivePusher pusher)
void onPushPaused(AlivcLivePusher pusher)
void onNetworkRecovery(AlivcLivePusher pusher)
void onPushStarted(AlivcLivePusher pusher)
void onConnectionLost(AlivcLivePusher pusher)
void onReconnectFail(AlivcLivePusher pusher)
void onPreviewStarted(AlivcLivePusher pusher)
void onPushRestarted(AlivcLivePusher pusher)
void onDropFrame(AlivcLivePusher pusher, int beforeCount, int afterCount)
String onPushURLAuthenticationOverdue(AlivcLivePusher pusher)
void setCameraType(AlivcLivePushCameraTypeEnum cameraType)
void onReconnectSucceed(AlivcLivePusher pusher)
void onPushStopped(AlivcLivePusher pusher)
void onFirstFramePushed(AlivcLivePusher pusher)
void onSDKError(AlivcLivePusher livePusher, AlivcLivePushError error)
void onAdjustFps(AlivcLivePusher pusher, int currentFps, int targetFps)
void onSystemError(AlivcLivePusher livePusher, AlivcLivePushError error)
void onPushStatistics(AlivcLivePusher pusher, AlivcLivePushStatsInfo statistics)
void onSendDataTimeout(AlivcLivePusher pusher)
void onAdjustBitrate(AlivcLivePusher pusher, int currentBitrate, int targetBitrate)
void onPreviewStopped(AlivcLivePusher pusher)
void onPushResumed(AlivcLivePusher pusher)
void onProgress(long progress, long duration)