1 package com.alivc.live.pusher;
58 import static com.
alivc.
live.utils.ParameterUtil.getInteger;
59 import static com.
alivc.
live.utils.ParameterUtil.getLong;
61 import android.app.Application;
62 import android.app.Service;
63 import android.content.BroadcastReceiver;
64 import android.content.Context;
65 import android.content.Intent;
66 import android.content.IntentFilter;
67 import android.graphics.Bitmap;
68 import android.graphics.BitmapFactory;
69 import android.media.AudioManager;
70 import android.os.Handler;
71 import android.os.Looper;
72 import android.os.Message;
73 import android.telephony.PhoneStateListener;
74 import android.telephony.TelephonyManager;
75 import android.text.TextUtils;
76 import android.view.Surface;
77 import android.view.SurfaceHolder;
78 import android.view.SurfaceView;
79 import android.widget.FrameLayout;
134 import org.json.JSONException;
135 import org.json.JSONObject;
136 import org.webrtc.utils.AlivcLog;
138 import java.lang.ref.WeakReference;
139 import java.util.ArrayList;
140 import java.util.HashMap;
141 import java.util.Iterator;
142 import java.util.Map;
143 import java.util.StringTokenizer;
144 import java.util.concurrent.LinkedBlockingQueue;
145 import java.util.concurrent.ScheduledExecutorService;
146 import java.util.concurrent.ScheduledThreadPoolExecutor;
147 import java.util.concurrent.ThreadFactory;
148 import java.util.concurrent.ThreadPoolExecutor;
149 import java.util.concurrent.TimeUnit;
150 import java.util.concurrent.atomic.AtomicInteger;
153 class AlivcLivePusherBasicImpl
implements ILivePusher {
154 private static final String TAG =
"AlivcLivePusherBasicImpl";
158 SCREEN_RECORD_NORMAL,
159 SCREEN_RECORD_CAMERA_START,
160 SCREEN_RECORD_CAMERA_MIX_START,
163 private static LivePusherJNI mNativeAlivcLivePusher = null;
164 private WeakReference<AlivcLivePusher> mWeakAlivcLivePusher = null;
167 private AlivcLivePlayStats mPlayStats = AlivcLivePlayStats.IDLE;
174 private AlivcLivePusherRenderContextListener mRenderContextListener = null;
178 private SurfaceView mPreviewView = null;
180 private AudioManager mAudioManager = null;
182 private Context mContext = null;
185 private static final int NTP_TIME_OUT_MILLISECOND = 1000;
186 private static final String AUTH_KEY =
"auth_key=";
187 private static final int MAX_CHATS = 4000;
188 private static final float TEXTURE_RANGE_MIN = 0.0f;
189 private static final float TEXTURE_RANGE_MAX = 1.0f;
190 private static final int MAX_DYNAMIC_ADDSON_COUNT = 3;
191 private static final int AlivcLiveMaxWatermarkCount = 3;
193 private Map<Integer, AlivcLivePushError> mErrorMap =
new HashMap<>();
194 private String mPushUrl = null;
196 private int mBGMVolume = 50;
197 private int mCaptureVolume = 50;
198 private boolean mMute =
false;
199 private TelephonyManager manager = null;
202 private static final int MESSAGE_RECONNECT_SUCCESS = 0x12;
203 private boolean registeredCallback =
false;
204 protected BluetoothHeadsetUtils mBluetoothHelper;
205 private boolean isReconnect =
false;
206 private LiveEventReporter mLiveEventReporter = null;
207 private long mTimeStamp = -1;
208 private int mExpiryTime = -1;
210 private int mDynamicAddsonCount = 0;
212 private int mTimeCount = 0;
214 private int mWatermarkCount = 0;
220 private AppFrontBackHelper mAppFrontBackHelper;
222 private ThreadPoolExecutor mThreadPoolExecutor =
new ThreadPoolExecutor(3, 5, 1, TimeUnit.SECONDS,
223 new LinkedBlockingQueue<Runnable>(100));
225 private Handler mHandler =
new Handler(Looper.getMainLooper()) {
227 public void handleMessage(Message msg) {
228 AlivcLog.i(TAG,
"AlivcLivePusher reconnect success");
230 if (mPushNetworkListener != null) {
231 mThreadPoolExecutor.execute(
new Runnable() {
241 private SurfaceHolder.Callback mPreviewCallback =
new SurfaceHolder.Callback() {
243 public void surfaceCreated(SurfaceHolder holder) {
244 AlivcLog.d(TAG,
"LiveActivity-->Preview surface created");
245 if (mPreviewView == null) {
249 if (mSurfaceStatus == SurfaceStatus.
UNINITED) {
250 mSurfaceStatus = SurfaceStatus.
CREATED;
251 }
else if (mSurfaceStatus == SurfaceStatus.
DESTROYED) {
252 mSurfaceStatus = SurfaceStatus.
RECREATED;
253 if (mNativeAlivcLivePusher != null) {
254 mNativeAlivcLivePusher.notifySurfaceReCreate(mPreviewView.getHolder().getSurface());
260 public void surfaceChanged(SurfaceHolder holder,
int format,
int width,
int height) {
261 AlivcLog.d(TAG,
"LiveActivity-->Preview surface changed");
262 if (mPreviewView == null) {
265 mSurfaceStatus = SurfaceStatus.
CHANGED;
266 if (mNativeAlivcLivePusher != null) {
267 mNativeAlivcLivePusher.notifySurfaceChange(holder.getSurface(), mAlivcLivePushConfig.
getPreviewOrientation());
272 public void surfaceDestroyed(SurfaceHolder holder) {
273 AlivcLog.d(TAG,
"LiveActivity-->Preview surface destroyed");
274 if (mPreviewView == null) {
277 if (mNativeAlivcLivePusher != null) {
278 mNativeAlivcLivePusher.notifySurfaceDestroy();
280 mSurfaceStatus = SurfaceStatus.
DESTROYED;
284 private ScheduledExecutorService scheduleExecutor = null;
286 public AlivcLivePusherBasicImpl() {
291 public void init(
final Context context,
final AlivcLivePushConfig config)
throws IllegalArgumentException, IllegalStateException {
292 AlivcLog.i(TAG,
"init");
293 AlivcLog.i(TAG, AlivcLivePushInstance.getSdkBuildInfo());
295 mAlivcLivePushConfig = config;
296 mLiveEventReporter =
new LiveEventReporter(mContext,
this, mAlivcLivePushConfig);
298 if (!AlivcLiveLicenseManager.isLicenseRegistered()) {
299 String errorMessage =
"License not registered! Get HELP from https://help.aliyun.com/document_detail/431730.htm";
300 AlivcLog.e(TAG, errorMessage);
301 throw new IllegalStateException(errorMessage);
304 boolean isLicenseVerified = AlivcLiveLicenseManager.verifyLicense();
306 AlivcLiveLicenseManager.AlivcLiveLicenseResult licenseResult = AlivcLiveLicenseManager.getLatestLicenseResult();
307 if (licenseResult != null) {
308 PusherLicenseEvent.Args args =
new PusherLicenseEvent.Args();
309 args.result = licenseResult.result;
310 args.reason = licenseResult.msg;
311 args.key = licenseResult.licenseKey;
312 mLiveEventReporter.sendEvent(PusherLicenseEvent.kTopicType, PusherLicenseEvent.kTopicValue, PusherLicenseEvent.getArgsStr(args));
315 if (!isLicenseVerified) {
316 String errorMessage =
"License not verified! Get HELP from https://help.aliyun.com/document_detail/431730.htm";
317 AlivcLog.e(TAG, errorMessage);
318 throw new IllegalStateException(errorMessage);
321 if (mPushStatus != AlivcLivePushStats.
IDLE && mPushStatus != AlivcLivePushStats.
INIT) {
322 throw new IllegalStateException(
"init state error, current state is " + AlivcLivePushStats.values()[mPushStatus.ordinal()]);
324 mAudioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
325 mAudioManager.setMode(AudioManager.STREAM_VOICE_CALL);
326 mAudioManager.setSpeakerphoneOn(
true);
328 registerHeadsetPlugReceiver();
330 LogWhenGoBackOrFront((Application) context.getApplicationContext(),
true);
332 AliLiveInfoUtils.setSDKContext(mContext);
334 mBluetoothHelper =
new BluetoothHeadsetUtils(mContext);
335 mBluetoothHelper.start(
new BluetoothHeadsetUtils.BlueToothListener() {
337 public void onBlueTooth(
boolean on) {
338 LivePusherJNI.headSetOn = on;
340 mAudioManager.setMode(AudioManager.STREAM_VOICE_CALL);
341 mAudioManager.setSpeakerphoneOn(
true);
343 mAudioManager.setSpeakerphoneOn(
false);
345 if (mNativeAlivcLivePusher != null) {
346 mNativeAlivcLivePusher.setHeadSet(on);
355 for (AlivcLivePushError error : AlivcLivePushError.values()) {
356 mErrorMap.put(error.getCode(), error);
358 mLiveEventReporter =
new LiveEventReporter(mContext,
this, mAlivcLivePushConfig);
359 mNativeAlivcLivePusher =
new LivePusherJNI(mContext, config,
new LivePusherJNI.LivePusherListener() {
361 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) {
363 if (what == ALIVC_PUSHER_ERROR_SDK_LIVE_PUSH_NETWORK_TOO_POOR.getCode()) {
364 AlivcLog.i(TAG,
"AlivcLivePusher Callback Network Too Poor");
365 if (mPushNetworkListener != null) {
366 mThreadPoolExecutor.execute(
new Runnable() {
369 mPushNetworkListener.
onNetworkPoor(getLivePusherReference());
374 PusherNetworkPoorEvent.Args args = null;
375 mLiveEventReporter.sendEvent(PusherNetworkPoorEvent.kTopicType, PusherNetworkPoorEvent.kTopicValue, PusherNetworkPoorEvent.getArgsStr(args));
376 }
else if (what == ALIVC_PUSHER_EVENT_PUSH_NETWORK_RECOVERY.getCode()) {
377 AlivcLog.i(TAG,
"AlivcLivePusher Callback Network Recovery");
378 if (mPushNetworkListener != null) {
379 mThreadPoolExecutor.execute(
new Runnable() {
387 PusherNetworkRecoveryEvent.Args args = null;
388 mLiveEventReporter.sendEvent(PusherNetworkRecoveryEvent.kTopicType, PusherNetworkRecoveryEvent.kTopicValue, PusherNetworkRecoveryEvent.getArgsStr(args));
389 }
else if (what == ALIVC_PUSHER_EVENT_PUSH_RECONNECT_START.getCode()) {
390 AlivcLog.i(TAG,
"AlivcLivePusher Callback Reconnect Start");
393 if (mPushNetworkListener != null) {
394 mThreadPoolExecutor.execute(
new Runnable() {
403 PusherReconnectStartEvent.Args args =
new PusherReconnectStartEvent.Args();
404 mLiveEventReporter.sendEvent(PusherReconnectStartEvent.kTopicType, PusherReconnectStartEvent.kTopicValue, PusherReconnectStartEvent.getArgsStr(args));
405 }
else if (what == ALIVC_PUSHER_EVENT_PUSH_RECONNECT_SUCCESS.getCode()) {
406 AlivcLog.i(TAG,
"AlivcLivePusher Callback Reconnect Success");
407 if (mHandler != null) {
408 mHandler.removeMessages(MESSAGE_RECONNECT_SUCCESS);
409 mHandler.sendEmptyMessageDelayed(MESSAGE_RECONNECT_SUCCESS, 500);
412 if (mPushStatus != AlivcLivePushStats.
PAUSED) {
413 mPushStatus = AlivcLivePushStats.
PUSHED;
416 PusherReconnectSuccessEvent.Args args = null;
417 mLiveEventReporter.sendEvent(PusherReconnectSuccessEvent.kTopicType, PusherReconnectSuccessEvent.kTopicValue, PusherReconnectSuccessEvent.getArgsStr(args));
418 }
else if (what == ALIVC_PUSHER_EVENT_PUSH_CONNECTION_LOST.getCode()) {
419 AlivcLog.i(TAG,
"AlivcLivePusher Callback Connection Lost");
421 if (mPushNetworkListener != null) {
422 mThreadPoolExecutor.execute(
new Runnable() {
430 PusherConnectionLostEvent.Args args =
new PusherConnectionLostEvent.Args();
432 args.reason =
"rtmp_";
433 }
else if (param1 == 1) {
434 args.reason =
"artc_";
436 args.reason += String.valueOf(param2);
437 mLiveEventReporter.sendEvent(PusherConnectionLostEvent.kTopicType, PusherConnectionLostEvent.kTopicValue, PusherConnectionLostEvent.getArgsStr(args));
438 }
else if (what == ALIVC_PUSHER_ERROR_SDK_PUSH_RECONNECT_FAIL.getCode()) {
439 AlivcLog.i(TAG,
"AlivcLivePusher Callback Reconnect Fail");
442 if (mHandler != null) {
443 mHandler.removeMessages(MESSAGE_RECONNECT_SUCCESS);
445 if (mPushNetworkListener != null) {
446 mThreadPoolExecutor.execute(
new Runnable() {
453 mPushStatus = AlivcLivePushStats.
ERROR;
454 mLastError = ALIVC_PUSHER_ERROR_SDK_PUSH_RECONNECT_FAIL;
456 PusherReconnectFailedEvent.Args args =
new PusherReconnectFailedEvent.Args();
459 mLiveEventReporter.sendEvent(PusherReconnectFailedEvent.kTopicType, PusherReconnectFailedEvent.kTopicValue, PusherReconnectFailedEvent.getArgsStr(args));
460 }
else if (what == ALIVC_PUSHER_ERROR_SDK_PUSH_SEND_DATA_TIMEOUT.getCode()) {
461 AlivcLog.i(TAG,
"AlivcLivePusher Callback Send Data Timeout");
462 if (mPushNetworkListener != null) {
463 mThreadPoolExecutor.execute(
new Runnable() {
471 PusherSendDataTimeoutEvent.Args args = null;
472 mLiveEventReporter.sendEvent(PusherSendDataTimeoutEvent.kTopicType, PusherSendDataTimeoutEvent.kTopicValue, PusherSendDataTimeoutEvent.getArgsStr(args));
473 }
else if (what == ALIVC_PUSHER_ERROR_SDK_PUSH_CONNECT.getCode()
474 || what == ALIVC_LIVE_ERROR_SYSTEM_RTMP_OOM.getCode()
475 || what == ALIVC_PUSHER_ERROR_SDK_PUSH_SETUPURL.getCode()
476 || what == ALIVC_PUSHER_ERROR_SDK_PUSH_CONNECT_STREAM.getCode()
477 || what == ALIVC_PUSHER_ERROR_SDK_PUSH_START_PUSH_TIMEOUT.getCode()) {
478 AlivcLog.i(TAG,
"AlivcLivePusher Callback Push Connect Fail");
480 if (mPushNetworkListener != null) {
481 mThreadPoolExecutor.execute(
new Runnable() {
484 mPushNetworkListener.
onConnectFail(getLivePusherReference());
488 mPushStatus = AlivcLivePushStats.
ERROR;
489 mLastError = getErrorByCode(what);
491 PusherStartPushFailedEvent.Args args =
new PusherStartPushFailedEvent.Args();
494 mLiveEventReporter.sendEvent(PusherStartPushFailedEvent.kTopicType, PusherStartPushFailedEvent.kTopicValue, PusherStartPushFailedEvent.getArgsStr(args));
495 }
else if (what == ALIVC_PUSHER_EVENT_NATIVE_LIVE_PUSH_INIT_SUCCESS.getCode()) {
497 }
else if (what == ALIVC_PUSHER_EVENT_NATIVE_LIVE_PUSH_PREVIEW_STARTED.getCode()) {
498 AlivcLog.i(TAG,
"AlivcLivePusher Callback Preview Started");
500 if (mPushInfoListener != null) {
501 mThreadPoolExecutor.execute(
new Runnable() {
508 mPushStatus = AlivcLivePushStats.
PREVIEWED;
510 }
else if (what == ALIVC_PUSHER_EVENT_NATIVE_LIVE_PUSH_PREVIEW_STOPED.getCode()) {
511 AlivcLog.i(TAG,
"AlivcLivePusher Callback Preview Stoped");
513 if (mPushInfoListener != null) {
514 mThreadPoolExecutor.execute(
new Runnable() {
517 if (mPushInfoListener != null) {
523 mPushStatus = AlivcLivePushStats.
INIT;
524 }
else if (what == ALIVC_PUSHER_EVENT_PUSH_STARTED.getCode()) {
525 AlivcLog.i(TAG,
"AlivcLivePusher Callback Push Started");
527 mPushStatus = AlivcLivePushStats.
PUSHED;
528 if (mPushInfoListener != null) {
529 mThreadPoolExecutor.execute(
new Runnable() {
537 PusherStartPushSuccessEvent.Args args =
new PusherStartPushSuccessEvent.Args();
539 mLiveEventReporter.sendEvent(PusherStartPushSuccessEvent.kTopicType, PusherStartPushSuccessEvent.kTopicValue, PusherStartPushSuccessEvent.getArgsStr(args));
540 }
else if (what == ALIVC_PUSHER_EVENT_PUSH_STOPED.getCode()) {
541 AlivcLog.i(TAG,
"AlivcLivePusher Callback Push Stoped");
543 if (mPushInfoListener != null) {
544 mThreadPoolExecutor.execute(
new Runnable() {
547 if (mPushInfoListener != null) {
553 PusherStopPushSuccessEvent.Args args =
new PusherStopPushSuccessEvent.Args();
555 mLiveEventReporter.sendEvent(PusherStopPushSuccessEvent.kTopicType, PusherStopPushSuccessEvent.kTopicValue, PusherStopPushSuccessEvent.getArgsStr(args));
556 }
else if(what == ALIVC_PUSHER_EVENT_PUSH_CRASH.getCode()){
557 AlivcLog.i(TAG,
"found SDK crashed!");
558 mLiveEventReporter.sendEvent(PusherSDKCrashEvent.kTopicType, PusherSDKCrashEvent.kTopicValue, PusherSDKCrashEvent.getArgsStr(arg7, arg8));
559 }
else if(what == ALIVC_PUSHER_EVENT_GENERAL_MONITOR.getCode()) {
560 AlivcLivePushConstants.Topic topicType = AlivcLivePushConstants.Topic.event;
562 int topicTypeId = (int)arg6;
563 switch (topicTypeId) {
564 case 0: topicType = AlivcLivePushConstants.Topic.action;
break;
565 case 1: topicType = AlivcLivePushConstants.Topic.event;
break;
566 case 2: topicType = AlivcLivePushConstants.Topic.error;
break;
567 case 3: topicType = AlivcLivePushConstants.Topic.biz;
break;
568 default: assert(
false);
571 assert(!arg7.isEmpty());
572 String topicValue = arg7;
573 String argJsonStr = arg8;
574 Map<String, String> param =
new HashMap<String, String>();
576 JSONObject obj =
new JSONObject(argJsonStr);
577 Iterator it = obj.keys();
578 while (it.hasNext()) {
579 String key = it.next().toString();
580 String value = (String)obj.get(key).toString();
581 param.put(key, value);
583 }
catch(JSONException e) {
584 AlivcLog.e(TAG,
"Invalid json object: " + arg8);
585 }
catch(Exception e) {
586 AlivcLog.e(TAG,
"Unknown exception: " + e.getMessage());
588 mLiveEventReporter.sendEvent(topicType, topicValue, param);
589 }
else if(what == ALIVC_PUSHER_EVENT_PUSH_MEDIAINFO.getCode()) {
591 }
else if(what == ALIVC_PUSHER_EVENT_PUSH_DELAY_INFO.getCode()) {
593 PusherDelayInfoEvent.Args args =
new PusherDelayInfoEvent.Args();
594 args.totalDelay = param1;
595 args.captureDelay = param2;
596 args.encoderDelay = param3;
597 args.sendDelay = param4;
599 AlivcLog.d(TAG,
"AlivcLivePusher push delay");
601 mLiveEventReporter.sendEvent(PusherDelayInfoEvent.kTopicType, PusherDelayInfoEvent.kTopicValue, PusherDelayInfoEvent.getArgsStr(args));
604 JSONObject gDelayObject =
new JSONObject();
607 gDelayObject.put(
"gdelay", param1);
609 sendMessageInternal(gDelayObject.toString(),10,0,
false,
true);
611 }
catch (Exception e) {
616 }
else if (what == ALIVC_PUSHER_EVENT_NATIVE_LIVE_PUSH_PUSH_PAUSED.getCode()) {
617 AlivcLog.i(TAG,
"AlivcLivePusher Callback Push Paused");
619 if (mPushInfoListener != null) {
620 mThreadPoolExecutor.execute(
new Runnable() {
623 mPushInfoListener.
onPushPaused(getLivePusherReference());
628 PusherOnPauseEvent.Args args = null;
629 mLiveEventReporter.sendEvent(PusherOnPauseEvent.kTopicType, PusherOnPauseEvent.kTopicValue, PusherOnPauseEvent.getArgsStr(args));
630 }
else if (what == ALIVC_PUSHER_EVENT_NATIVE_LIVE_PUSH_PUSH_RESUMED.getCode()) {
631 AlivcLog.i(TAG,
"AlivcLivePusher Callback Push Resumed");
633 if (mNativeAlivcLivePusher.isPushing()) {
634 mPushStatus = AlivcLivePushStats.
PUSHED;
636 mPushStatus = AlivcLivePushStats.
PREVIEWED;
638 if (mPushInfoListener != null) {
639 mThreadPoolExecutor.execute(
new Runnable() {
647 PusherOnResumeEvent.Args args = null;
648 mLiveEventReporter.sendEvent(PusherOnResumeEvent.kTopicType, PusherOnResumeEvent.kTopicValue, PusherOnResumeEvent.getArgsStr(args));
649 }
else if (what == ALIVC_FRAMEWORK_RENDER_FIRST_FRAME_PREVIEWED.getCode()) {
650 AlivcLog.i(TAG,
"AlivcLivePusher Callback Preview First Frame");
652 if (mPushInfoListener != null) {
653 mThreadPoolExecutor.execute(
new Runnable() {
660 }
else if (what == ALIVC_PUSHER_EVENT_NATIVE_LIVE_PUSH_PUSH_RESTARTED.getCode()) {
661 AlivcLog.i(TAG,
"AlivcLivePusher Callback Push Restarted");
663 mPushStatus = AlivcLivePushStats.
PUSHED;
664 if (mPushInfoListener != null) {
665 mThreadPoolExecutor.execute(
new Runnable() {
673 PusherOnRestartEvent.Args args = null;
674 mLiveEventReporter.sendEvent(PusherOnRestartEvent.kTopicType, PusherOnRestartEvent.kTopicValue, PusherOnRestartEvent.getArgsStr(args));
675 }
else if (what == ALIVC_PUSHER_EVENT_PUSH_DROP_FRAME.getCode()) {
676 AlivcLog.d(TAG,
"AlivcLivePusher Callback Drop Frame");
678 PusherDropFrameEvent.PusherDropFrameArgs args =
new PusherDropFrameEvent.PusherDropFrameArgs();
679 args.vpiubbd = param1;
680 args.vpiubad = param2;
681 args.apiubbd = param3;
682 args.apiubad = param4;
683 mLiveEventReporter.sendEvent(PusherDropFrameEvent.kTopicType, PusherDropFrameEvent.kTopicValue, PusherDropFrameEvent.getArgsStr(args));
684 if (mPushInfoListener != null) {
685 mThreadPoolExecutor.execute(
new Runnable() {
688 mPushInfoListener.
onDropFrame(getLivePusherReference(), param1, param2);
690 if (mPushNetworkListener != null) {
691 mPushNetworkListener.
onPacketsLost(getLivePusherReference());
697 }
else if (what == ALIVC_PUSHER_EVENT_NATIVE_LIVE_PUSH_ADJUST_BITRATE.getCode()) {
698 AlivcLog.d(TAG,
"AlivcLivePusher Callback Adjust Bitrate");
700 PusherAdjustBitrateEvent.Args args =
new PusherAdjustBitrateEvent.Args();
701 args.oeb = param1 / 1000;
702 args.neb = param2 / 1000;
703 Map map = getPerformanceMap();
705 args.ceb = getInteger(map,
"mVideoEncodeBitrate") + getInteger(map,
"mAudioEncodeBitrate");
706 args.cub = getInteger(map,
"mAudioUploadBitrate") + getInteger(map,
"mVideoUploadBitrate");
708 mLiveEventReporter.sendEventWithLevel(PusherAdjustBitrateEvent.kTopicType, PusherAdjustBitrateEvent.kTopicValue, PusherAdjustBitrateEvent.getArgsStr(args), AlivcLivePushMonitorLevel.CUT);
709 if (mPushInfoListener != null) {
710 mThreadPoolExecutor.execute(
new Runnable() {
713 mPushInfoListener.
onAdjustBitrate(getLivePusherReference(), param1 / 1000, param2 / 1000);
717 }
else if (what == ALIVC_PUSHER_EVENT_NATIVE_LIVE_PUSH_CHANGE_FPS.getCode()) {
718 AlivcLog.d(TAG,
"AlivcLivePusher Callback Change FPS");
720 PusherAdjustFpsEvent.Args args =
new PusherAdjustFpsEvent.Args();
721 args.oldFps = param1;
722 args.newFps = param2;
723 mLiveEventReporter.sendEvent(PusherAdjustFpsEvent.kTopicType, PusherAdjustFpsEvent.kTopicValue, PusherAdjustFpsEvent.getArgsStr(args));
724 if (mPushInfoListener != null) {
725 mThreadPoolExecutor.execute(
new Runnable() {
728 mPushInfoListener.
onAdjustFps(getLivePusherReference(), param1, param2);
732 }
else if (what == ALIVC_PUSHER_EVENT_NATIVE_LIVE_PUSH_CHANGE_RESOLUTION.getCode()) {
734 }
else if (what == ALIVC_PUSHER_ERROR_SDK_PUSH_RTS_DOWN_TO_RTMP.getCode()) {
737 }
else if (what == ALIVC_PUSHER_EVENT_PUSH_SENDED_FIRST_AV.getCode()) {
739 PusherFirstFrameSentEvent.Args args =
new PusherFirstFrameSentEvent.Args();
742 args.resolution = mAlivcLivePushConfig.
getResolution().toString().substring(11);
747 args.wc = mAlivcLivePushConfig.getWaterMarkInfos().size();
749 args.fps = mAlivcLivePushConfig.
getFps();
756 args.flash = mAlivcLivePushConfig.
isFlash();
762 mLiveEventReporter.sendEvent(PusherFirstFrameSentEvent.kTopicType, PusherFirstFrameSentEvent.kTopicValue, PusherFirstFrameSentEvent.getArgsStr(args));
763 if (mPushInfoListener != null) {
764 mThreadPoolExecutor.execute(
new Runnable() {
771 }
else if (what == ALIVC_PUSHER_EVENT_CAPTURE_OPEN_CAMERA_SUCCESS.getCode()) {
773 }
else if (what == ALIVC_PUSHER_EVENT_CAPTURE_OPEN_MIC_SUCCESS.getCode()) {
775 }
else if (what == ALIVC_PUSHER_EVENT_CAPTURE_CLOSE_CAMERA_SUCCESS.getCode()) {
777 }
else if (what == ALIVC_PUSHER_EVENT_NATIVE_LIVE_PUSH_OPEN_VIDEO_ENCODER_SUCCESS.getCode()) {
779 }
else if (what == ALIVC_PUSHER_EVENT_NATIVE_LIVE_PUSH_CAPTURE_VIDEO_SAMPLES_OVERFLOW.getCode()) {
781 }
else if (what == ALIVC_PUSHER_EVENT_PUSH_SENDED_SEI.getCode()) {
782 if (mPushNetworkListener != null) {
783 mThreadPoolExecutor.execute(
new Runnable() {
786 mPushNetworkListener.
onSendMessage(getLivePusherReference());
793 else if (what == ALIVC_PUSHER_ERROR_BGM_OPEN_FAILED.getCode()) {
794 mPlayStats = AlivcLivePlayStats.IDLE;
795 if (mPushBGMListener != null) {
798 if (mNativeAlivcLivePusher != null) {
799 mNativeAlivcLivePusher.stopBGM();
801 }
else if (what == ALIVC_PUSHER_ERROR_BGM_TIMEOUT.getCode()) {
802 mPlayStats = AlivcLivePlayStats.IDLE;
803 if (mPushBGMListener != null) {
806 }
else if (what == ALIVC_PUSHER_EVENT_BGM_OPEN_SUCCESS.getCode()) {
807 mPlayStats = AlivcLivePlayStats.STARTED;
808 if (mPushBGMListener != null) {
811 }
else if (what == ALIVC_PUSHER_EVENT_BGM_STOP_SUCCESS.getCode()) {
812 mPlayStats = AlivcLivePlayStats.STOPPED;
813 if (mPushBGMListener != null) {
816 }
else if (what == ALIVC_PUSHER_EVENT_BGM_PAUSE_SUCCESS.getCode()) {
817 mPlayStats = AlivcLivePlayStats.PAUSED;
818 if (mPushBGMListener != null) {
821 }
else if (what == ALIVC_PUSHER_EVENT_BGM_RESUME_SUCCESS.getCode()) {
822 mPlayStats = AlivcLivePlayStats.STARTED;
823 if (mPushBGMListener != null) {
826 }
else if (what == ALIVC_PUSHER_EVENT_BGM_COMPLETED.getCode()) {
827 if (mPushBGMListener != null) {
830 mPlayStats = AlivcLivePlayStats.IDLE;
831 }
else if (what == ALIVC_PUSHER_EVENT_BGM_PROGRESS.getCode()) {
832 if (mPushBGMListener != null) {
833 mPushBGMListener.
onProgress((
long) param1, (
long) param2);
835 }
else if (what == ALIVC_PUSHER_EVENT_CAPTURE_OPEN_SCREENCAPTURE_SUCCESS.getCode()) {
837 }
else if (what == ALIVC_PUSHER_EVENT_CAPTURE_CLOSE_SCREENCAPTURE_SUCCESS.getCode()) {
839 }
else if (what == ALIVC_PUSHER_EVENT_NATIVE_LIVE_PUSH_GL_CONTEXT_CREATED.getCode()) {
840 if (mRenderContextListener != null) {
841 mRenderContextListener.onSharedContextCreated(arg6);
843 }
else if (what == ALIVC_PUSHER_EVENT_NATIVE_LIVE_PUSH_GL_CONTEXT_DESTROYED.getCode()) {
844 if (mRenderContextListener != null) {
845 mRenderContextListener.onSharedContextDestroyed(arg6);
849 else if (what > 0x30010000 && what < 0x30020000) {
850 AlivcLog.e(TAG,
"AlivcLivePusher SystemError Callback error: " + what);
852 if (mErrorMap.get(what) != null) {
853 mErrorMap.get(what).setMsg(msg);
855 if (mPushErrorListener != null) {
856 mThreadPoolExecutor.execute(
new Runnable() {
859 mPushErrorListener.
onSystemError(getLivePusherReference(), mErrorMap.get(what));
864 PusherSystemErrorEvent.Args args =
new PusherSystemErrorEvent.Args();
865 Map map = getPerformanceMap();
867 args.totalUploadSize = getLong(map,
"mTotalSizeOfUploadedPackets");
868 args.totalTime = getLong(map,
"mTotalTimeOfPublishing");
869 args.error_code = what;
870 if (mErrorMap.get(what) != null) {
871 args.error_msg = msg;
873 mLiveEventReporter.sendEvent(PusherSystemErrorEvent.kTopicType, PusherSystemErrorEvent.kTopicValue, PusherSystemErrorEvent.getArgsStr(args));
875 mPushStatus = AlivcLivePushStats.
ERROR;
876 mLastError = getErrorByCode(what);
878 else if (what == ALIVC_PUSHER_ERROR_SDK_LIVE_PUSH_LOW_PERFORMANCE.getCode()) {
880 AlivcLog.i(TAG,
"AlivcLivePusher low performance warning: 0x" + Integer.toHexString(what));
881 if (mErrorMap.get(what) != null) {
882 mErrorMap.get(what).setMsg(msg);
884 PusherSdkErrorEvent.Args args =
new PusherSdkErrorEvent.Args();
885 Map map = getPerformanceMap();
887 args.totalUploadSize = ParameterUtil.getLong(map,
"mTotalSizeOfUploadedPackets");
888 args.totalTime = ParameterUtil.getLong(map,
"mTotalTimeOfPublishing");
889 args.error_code = what;
890 if (mErrorMap.get(what) != null) {
891 args.error_msg = msg;
893 mLiveEventReporter.sendEvent(PusherSdkErrorEvent.kTopicType, PusherSdkErrorEvent.kTopicValue, PusherSdkErrorEvent.getArgsStr(args));
898 AlivcLog.e(TAG,
"AlivcLivePusher SDKError Callback error: 0x" + Integer.toHexString(what));
900 if (mErrorMap.get(what) != null) {
901 mErrorMap.get(what).setMsg(msg);
903 if (mPushErrorListener != null) {
904 mThreadPoolExecutor.execute(
new Runnable() {
907 mPushErrorListener.
onSDKError(getLivePusherReference(), mErrorMap.get(what));
912 PusherSdkErrorEvent.Args args =
new PusherSdkErrorEvent.Args();
913 Map map = getPerformanceMap();
915 args.totalUploadSize = getLong(map,
"mTotalSizeOfUploadedPackets");
916 args.totalTime = getLong(map,
"mTotalTimeOfPublishing");
917 args.error_code = what;
918 if (mErrorMap.get(what) != null) {
919 args.error_msg = msg;
921 mLiveEventReporter.sendEvent(PusherSdkErrorEvent.kTopicType, PusherSdkErrorEvent.kTopicValue, PusherSdkErrorEvent.getArgsStr(args));
923 mPushStatus = AlivcLivePushStats.
ERROR;
924 mLastError = getErrorByCode(what);
925 AlivcLog.e(TAG,
"error is " + what +
" msg is " + what);
929 mNativeAlivcLivePusher.init();
930 BGMPlayerJNI.setContext(mContext);
932 mPushStatus = AlivcLivePushStats.
INIT;
936 public void setCustomDetect(AlivcLivePushCustomDetect customVideoDetect) {
937 AlivcLog.i(TAG,
"setCustomDetect");
938 if (mNativeAlivcLivePusher == null) {
941 mNativeAlivcLivePusher.setCustomDetect(customVideoDetect);
945 public void setCustomFilter(AlivcLivePushCustomFilter customVideoFilter) {
946 AlivcLog.i(TAG,
"setCustomFilter");
947 if (mNativeAlivcLivePusher == null) {
950 mNativeAlivcLivePusher.setCustomFilter(customVideoFilter);
954 public void setCustomAudioFilter(AlivcLivePushCustomAudioFilter customAudioFilter) {
955 AlivcLog.i(TAG,
"setCustomAudioFilter");
956 if (mNativeAlivcLivePusher == null) {
959 mNativeAlivcLivePusher.setCustomAudioFilter(customAudioFilter);
963 public void destroy() throws IllegalStateException {
964 AlivcLog.i(TAG,
"destroy");
965 LogWhenGoBackOrFront((Application) mContext.getApplicationContext(),
false);
967 if (mNativeAlivcLivePusher != null) {
968 mNativeAlivcLivePusher.release();
971 mDynamicAddsonCount = 0;
973 if (registeredCallback) {
975 mContext.unregisterReceiver(mHeadsetPlugReceiver);
976 mContext.unregisterReceiver(mTelephoneReceiver);
977 }
catch (Exception e) {
978 AlivcLog.e(TAG,
"unregisterReceiver exception");
980 registeredCallback =
false;
982 if (mBluetoothHelper != null) {
983 mBluetoothHelper.stop();
985 mPushStatus = AlivcLivePushStats.
IDLE;
989 if (mThreadPoolExecutor != null && !mThreadPoolExecutor.isShutdown()) {
990 mThreadPoolExecutor.shutdown();
992 mThreadPoolExecutor = null;
994 mNativeAlivcLivePusher = null;
995 mPushInfoListener = null;
996 mPushErrorListener = null;
997 mPushNetworkListener = null;
998 mPushBGMListener = null;
1000 mPreviewView = null;
1002 mAlivcLivePushConfig = null;
1005 mPreviewCallback = null;
1006 if (mHandler != null) {
1007 mHandler.removeMessages(MESSAGE_RECONNECT_SUCCESS);
1011 if (mWeakAlivcLivePusher != null) {
1012 mWeakAlivcLivePusher.clear();
1013 mWeakAlivcLivePusher = null;
1015 BGMPlayerJNI.setContext(null);
1019 public void setLivePusherReference(AlivcLivePusher livePusher) {
1020 mWeakAlivcLivePusher =
new WeakReference<>(livePusher);
1023 private AlivcLivePusher getLivePusherReference() {
1024 return (mWeakAlivcLivePusher != null) ? mWeakAlivcLivePusher.get() : null;
1028 public void startPreview(SurfaceView surfaceView)
throws IllegalArgumentException, IllegalStateException {
1029 AlivcLog.i(TAG,
"startPreview");
1030 PusherStartPreviewEvent.Args args =
new PusherStartPreviewEvent.Args();
1032 if (mLiveEventReporter != null) {
1033 mLiveEventReporter.sendEvent(PusherStartPreviewEvent.kTopicType, PusherStartPreviewEvent.kTopicValue, PusherStartPreviewEvent.getArgsStr(args));
1036 if (mNativeAlivcLivePusher == null) {
1037 AlivcLog.e(TAG,
"Illegal State, you should init first");
1040 if (mPushStatus != AlivcLivePushStats.
INIT && mPushStatus != AlivcLivePushStats.
PREVIEWED) {
1041 AlivcLog.e(TAG,
"status error current state is " + AlivcLivePushStats.values()[mPushStatus.ordinal()]);
1045 this.mPreviewView = surfaceView;
1047 if (surfaceView == null) {
1048 result = mNativeAlivcLivePusher.startPreview(null,
true);
1050 mPushStatus = AlivcLivePushStats.
PREVIEWED;
1052 AlivcLog.e(TAG,
"start preview error");
1056 result = mNativeAlivcLivePusher.startPreview(surfaceView.getHolder().getSurface(),
true);
1058 surfaceView.getHolder().addCallback(mPreviewCallback);
1059 mPushStatus = AlivcLivePushStats.
PREVIEWED;
1061 AlivcLog.e(TAG,
"start preview error");
1067 public void startPreviewAsync(SurfaceView surfaceView)
throws IllegalArgumentException, IllegalStateException {
1068 AlivcLog.i(TAG,
"startPreviewAsync");
1070 PusherStartPreviewEvent.Args args =
new PusherStartPreviewEvent.Args();
1072 if (mLiveEventReporter != null) {
1073 mLiveEventReporter.sendEvent(PusherStartPreviewEvent.kTopicType, PusherStartPreviewEvent.kTopicValue, PusherStartPreviewEvent.getArgsStr(args));
1076 if (mNativeAlivcLivePusher == null) {
1077 AlivcLog.e(TAG,
"Illegal State, you should init first");
1081 if (mPushStatus != AlivcLivePushStats.
INIT && mPushStatus != AlivcLivePushStats.
PREVIEWED) {
1082 AlivcLog.e(TAG,
"status error current state is " + AlivcLivePushStats.values()[mPushStatus.ordinal()]);
1087 this.mPreviewView = surfaceView;
1089 if (surfaceView == null) {
1090 result = mNativeAlivcLivePusher.startPreview(null,
false);
1092 mPushStatus = AlivcLivePushStats.
PREVIEWED;
1094 AlivcLog.e(TAG,
"start preview async error");
1097 result = mNativeAlivcLivePusher.startPreview(surfaceView.getHolder().getSurface(),
false);
1099 surfaceView.getHolder().addCallback(mPreviewCallback);
1100 mPushStatus = AlivcLivePushStats.
PREVIEWED;
1102 AlivcLog.e(TAG,
"start preview async error");
1108 public void startPreview(Context context, FrameLayout frameLayout,
boolean isAnchor)
throws IllegalArgumentException, IllegalStateException {
1113 public void stopPreview() throws IllegalStateException {
1114 AlivcLog.i(TAG,
"stopPreview");
1115 PusherStopPreviewEvent.Args args = null;
1116 if (mLiveEventReporter != null) {
1117 mLiveEventReporter.sendEvent(PusherStopPreviewEvent.kTopicType, PusherStopPreviewEvent.kTopicValue, PusherStopPreviewEvent.getArgsStr(args));
1120 if (mNativeAlivcLivePusher == null) {
1121 AlivcLog.e(TAG,
"Illegal State, you should init first");
1125 mDynamicAddsonCount = 0;
1127 if (mPushStatus != AlivcLivePushStats.
INIT && mPushStatus != AlivcLivePushStats.
PREVIEWED) {
1128 AlivcLog.e(TAG,
"status error current state is " + AlivcLivePushStats.values()[mPushStatus.ordinal()]);
1132 int result = mNativeAlivcLivePusher.stopPreview();
1134 mPushStatus = AlivcLivePushStats.
INIT;
1136 AlivcLog.e(TAG,
"stop preview error");
1141 public void startPush(String url)
throws IllegalArgumentException, IllegalStateException {
1142 AlivcLog.i(TAG,
"startPush");
1143 if (mNativeAlivcLivePusher == null || mAlivcLivePushConfig == null) {
1144 AlivcLog.e(TAG,
"Illegal State, you should init first");
1148 url = AlivcLiveURLTools.trimUrl(url);
1149 if (!AlivcLiveURLTools.checkPushUrl(url)) {
1150 AlivcLog.e(TAG,
"Illegal argument, push url error!");
1154 if ((mAlivcLivePushConfig.
isAudioOnly() || mAlivcLivePushConfig.
isVideoOnly()) && url.startsWith(AlivcLiveStreamType.EnumType.AlivcLiveStreamRts.getPrefix())) {
1155 AlivcLog.e(TAG,
"RTC protocol don't support audio/video only stream");
1159 if ((mPushStatus != AlivcLivePushStats.
PREVIEWED && mPushStatus != AlivcLivePushStats.
INIT)
1160 && mPushStatus != AlivcLivePushStats.
PUSHED) {
1161 AlivcLog.e(TAG,
"status error current state is " + AlivcLivePushStats.values()[mPushStatus.ordinal()]);
1165 if (mPushStatus.equals(AlivcLivePushStats.INIT)) {
1166 mPreviewView = null;
1167 int result = mNativeAlivcLivePusher.startPreview(null,
true);
1169 AlivcLog.e(TAG,
"start push error : create gl resource failed");
1174 if (mPushUrl.contains(AUTH_KEY)) {
1178 mLiveEventReporter.refreshPushId();
1179 int result = mNativeAlivcLivePusher.startPush(url,
true);
1181 if (mPushStatus != AlivcLivePushStats.
PUSHED) {
1182 mPushStatus = AlivcLivePushStats.
PUSHED;
1184 mScreenStatus = ScreenRecordStatus.SCREEN_RECORD_NORMAL;
1188 AlivcLog.e(TAG,
"start push error");
1192 reportStartPushEvent(
false,
true);
1196 mNativeAlivcLivePusher.addPushImage(pauseImage, networkImage);
1197 startScheduleExecutor();
1201 public void startPushAsync(String url)
throws IllegalArgumentException, IllegalStateException {
1202 AlivcLog.i(TAG,
"startPushAsync");
1203 if (mNativeAlivcLivePusher == null || mAlivcLivePushConfig == null) {
1204 AlivcLog.e(TAG,
"Illegal State, you should init first");
1208 url = AlivcLiveURLTools.trimUrl(url);
1209 if (!AlivcLiveURLTools.checkPushUrl(url)) {
1210 AlivcLog.e(TAG,
"Illegal argument, push url error!");
1214 if ((mPushStatus != AlivcLivePushStats.
PREVIEWED && mPushStatus != AlivcLivePushStats.
INIT)
1215 && mPushStatus != AlivcLivePushStats.
PUSHED) {
1216 AlivcLog.e(TAG,
"status error current state is " + AlivcLivePushStats.values()[mPushStatus.ordinal()]);
1220 if ((mAlivcLivePushConfig.
isAudioOnly() || mAlivcLivePushConfig.
isVideoOnly()) && url.startsWith(AlivcLiveStreamType.EnumType.AlivcLiveStreamRts.getPrefix())) {
1221 AlivcLog.e(TAG,
"RTC protocol don't support audio/video only stream");
1225 if (mPushStatus.equals(AlivcLivePushStats.INIT)) {
1226 mPreviewView = null;
1227 int result = mNativeAlivcLivePusher.startPreview(null,
true);
1229 AlivcLog.e(TAG,
"start push error : create gl resource failed");
1235 if (mPushUrl.contains(AUTH_KEY)) {
1239 mLiveEventReporter.refreshPushId();
1240 int result = mNativeAlivcLivePusher.startPush(url,
false);
1242 if (mPushStatus != AlivcLivePushStats.
PUSHED) {
1243 mPushStatus = AlivcLivePushStats.
PUSHED;
1245 mScreenStatus = ScreenRecordStatus.SCREEN_RECORD_NORMAL;
1249 AlivcLog.e(TAG,
"start push async error");
1253 reportStartPushEvent(
false,
false);
1257 mNativeAlivcLivePusher.addPushImage(pauseImage, networkImage);
1258 startScheduleExecutor();
1262 public void restartPush() throws IllegalStateException {
1263 AlivcLog.i(TAG,
"restartPush");
1264 if (mNativeAlivcLivePusher == null || mAlivcLivePushConfig == null) {
1265 AlivcLog.e(TAG,
"Illegal State, you should init first");
1271 AlivcLog.e(TAG,
"illegal argument");
1276 && (!TextUtils.isEmpty(mPushUrl) && mPushUrl.startsWith(AlivcLiveStreamType.EnumType.AlivcLiveStreamRts.getPrefix()))) {
1277 AlivcLog.e(TAG,
"RTC protocol don't support audio/video only stream");
1281 if (mPushStatus != AlivcLivePushStats.
PUSHED && mPushStatus != AlivcLivePushStats.
ERROR) {
1282 AlivcLog.e(TAG,
"status error current state is " + AlivcLivePushStats.values()[mPushStatus.ordinal()]);
1286 mDynamicAddsonCount = 0;
1290 Surface surface = mPreviewView != null ? mPreviewView.getHolder().getSurface() : null;
1291 int result = mNativeAlivcLivePusher.restartPush(surface,
true, 1000);
1293 mPushStatus = AlivcLivePushStats.
PUSHED;
1295 mScreenStatus = ScreenRecordStatus.SCREEN_RECORD_NORMAL;
1298 AlivcLog.e(TAG,
"restart push error");
1303 mNativeAlivcLivePusher.addPushImage(pauseImage, networkImage);
1305 reportStartPushEvent(
true,
true);
1307 startScheduleExecutor();
1312 public void restartPushAsync() throws IllegalStateException {
1313 AlivcLog.i(TAG,
"restartPushAsync");
1314 if (mNativeAlivcLivePusher == null || mAlivcLivePushConfig == null) {
1315 AlivcLog.e(TAG,
"Illegal State, you should init first");
1321 AlivcLog.e(TAG,
"illegal argument");
1326 && (!TextUtils.isEmpty(mPushUrl) && mPushUrl.startsWith(AlivcLiveStreamType.EnumType.AlivcLiveStreamRts.getPrefix()))) {
1327 AlivcLog.e(TAG,
"RTC protocol don't support audio/video only stream");
1331 if (mPushStatus != AlivcLivePushStats.
PUSHED && mPushStatus != AlivcLivePushStats.
ERROR) {
1332 AlivcLog.e(TAG,
"status error current state is " + AlivcLivePushStats.values()[mPushStatus.ordinal()]);
1336 Surface surface = mPreviewView != null ? mPreviewView.getHolder().getSurface() : null;
1337 int result = mNativeAlivcLivePusher.restartPush(surface,
false, 1000);
1341 AlivcLog.e(TAG,
"restart push async error");
1346 mNativeAlivcLivePusher.addPushImage(pauseImage, networkImage);
1350 reportStartPushEvent(
true,
false);
1352 startScheduleExecutor();
1356 public void reconnectPushAsync(String url)
throws IllegalStateException {
1357 AlivcLog.i(TAG,
"reconnectPushAsync");
1358 if (mNativeAlivcLivePusher == null || mAlivcLivePushConfig == null) {
1359 AlivcLog.e(TAG,
"Illegal State, you should init first");
1363 url = AlivcLiveURLTools.trimUrl(url);
1364 if (!AlivcLiveURLTools.checkPushUrl(url)) {
1368 if (mPushStatus != AlivcLivePushStats.
PUSHED && mPushStatus != AlivcLivePushStats.
PAUSED &&
1369 mPushStatus != AlivcLivePushStats.
ERROR) {
1370 AlivcLog.e(TAG,
"status error current state is " + AlivcLivePushStats.values()[mPushStatus.ordinal()]);
1374 if (isNetworkPushing()) {
1380 int result = mNativeAlivcLivePusher.reconnect(url,
false);
1382 isReconnect =
false;
1383 if (mHandler != null) {
1384 mHandler.removeMessages(MESSAGE_RECONNECT_SUCCESS);
1386 mPushStatus = AlivcLivePushStats.
PUSHED;
1388 mScreenStatus = ScreenRecordStatus.SCREEN_RECORD_NORMAL;
1391 AlivcLog.e(TAG,
"reconnect push async error");
1396 PusherReconnectEvent.Args args =
new PusherReconnectEvent.Args();
1397 Map map = getPerformanceMap();
1399 args.vutMs = getLong(map,
"mVideoDurationFromeCaptureToUpload");
1400 args.autMs = getLong(map,
"mAudioDurationFromeCaptureToUpload");
1401 if (mLiveEventReporter != null) {
1402 mLiveEventReporter.sendEvent(PusherReconnectEvent.kTopicType, PusherReconnectEvent.kTopicValue, PusherReconnectEvent.getArgsStr(args));
1408 public void stopPush() throws IllegalStateException {
1409 AlivcLog.i(TAG,
"stopPush");
1410 PusherStopPushEvent.Args args =
new PusherStopPushEvent.Args();
1411 Map map = getPerformanceMap();
1413 args.totalUploadSize = ParameterUtil.getLong(map,
"mTotalSizeOfUploadedPackets");
1414 args.totalTime = ParameterUtil.getLong(map,
"mTotalTimeOfPublishing");
1415 if (mLiveEventReporter != null) {
1416 mLiveEventReporter.sendEvent(PusherStopPushEvent.kTopicType, PusherStopPushEvent.kTopicValue, PusherStopPushEvent.getArgsStr(args));
1420 if (mNativeAlivcLivePusher == null) {
1421 AlivcLog.e(TAG,
"Illegal State, you should init first");
1424 if (mPushStatus != AlivcLivePushStats.
PREVIEWED && mPushStatus != AlivcLivePushStats.
PUSHED
1425 && mPushStatus != AlivcLivePushStats.
PAUSED && mPushStatus != AlivcLivePushStats.
ERROR) {
1426 AlivcLog.e(TAG,
"status error current state is " + AlivcLivePushStats.values()[mPushStatus.ordinal()]);
1430 int result = mNativeAlivcLivePusher.stopPush();
1432 mPushStatus = AlivcLivePushStats.
PREVIEWED;
1434 AlivcLog.e(TAG,
"stop push error");
1437 if (mPreviewView == null) {
1438 mNativeAlivcLivePusher.stopPreview();
1439 mPushStatus = AlivcLivePushStats.
INIT;
1445 public void pause() throws IllegalStateException {
1446 AlivcLog.i(TAG,
"pause");
1447 if (mNativeAlivcLivePusher == null || mAlivcLivePushConfig == null) {
1448 AlivcLog.e(TAG,
"Illegal State, you should init first");
1454 if (mPushStatus != AlivcLivePushStats.
PUSHED && mPushStatus != AlivcLivePushStats.
PAUSED
1455 && mPushStatus != AlivcLivePushStats.
PREVIEWED) {
1456 AlivcLog.e(TAG,
"status error current state is " + AlivcLivePushStats.values()[mPushStatus.ordinal()]);
1459 mPushStatus = AlivcLivePushStats.
PAUSED;
1461 mNativeAlivcLivePusher.pause();
1464 PusherPauseEvent.mLastPauseTime = System.currentTimeMillis();
1465 PusherPauseEvent.Args args =
new PusherPauseEvent.Args();
1466 Map map = getPerformanceMap();
1468 args.isPauseScreen =
false;
1469 args.totalUploadSize = ParameterUtil.getLong(map,
"mTotalSizeOfUploadedPackets");
1470 args.totalTime = ParameterUtil.getLong(map,
"mTotalTimeOfPublishing");
1471 if (mLiveEventReporter != null) {
1472 mLiveEventReporter.sendEvent(PusherPauseEvent.kTopicType, PusherPauseEvent.kTopicValue, PusherPauseEvent.getArgsStr(args));
1478 public void resume() throws IllegalStateException {
1479 AlivcLog.i(TAG,
"resume");
1480 if (mNativeAlivcLivePusher == null || mAlivcLivePushConfig == null) {
1481 AlivcLog.e(TAG,
"Illegal State, you should init first");
1487 if (mPushStatus != AlivcLivePushStats.
PAUSED && mPushStatus != AlivcLivePushStats.
ERROR) {
1488 AlivcLog.e(TAG,
"status error current state is " + AlivcLivePushStats.values()[mPushStatus.ordinal()]);
1492 mNativeAlivcLivePusher.resume(
true);
1493 PusherResumeEvent.Args args =
new PusherResumeEvent.Args();
1494 Map map = getPerformanceMap();
1497 args.isResumeScreen =
false;
1498 args.totalUploadSize = ParameterUtil.getLong(map,
"mTotalSizeOfUploadedPackets");
1499 args.totalTime = ParameterUtil.getLong(map,
"mTotalTimeOfPublishing");
1500 if (PusherPauseEvent.mLastPauseTime == 0) {
1503 args.cost = System.currentTimeMillis() - PusherPauseEvent.mLastPauseTime;
1505 if (mLiveEventReporter != null) {
1506 mLiveEventReporter.sendEvent(PusherResumeEvent.kTopicType, PusherResumeEvent.kTopicValue, PusherResumeEvent.getArgsStr(args));
1510 PusherPauseEvent.mLastPauseTime = 0;
1512 if (mNativeAlivcLivePusher.isPushing()) {
1513 mPushStatus = AlivcLivePushStats.
PUSHED;
1515 mPushStatus = AlivcLivePushStats.
PREVIEWED;
1520 public void resumeAsync() throws IllegalStateException {
1521 AlivcLog.i(TAG,
"resumeAsync");
1522 if (mNativeAlivcLivePusher == null || mAlivcLivePushConfig == null) {
1523 AlivcLog.e(TAG,
"Illegal State, you should init first");
1529 if (mPushStatus != AlivcLivePushStats.
PAUSED && mPushStatus != AlivcLivePushStats.
ERROR) {
1530 AlivcLog.e(TAG,
"status error current state is " + AlivcLivePushStats.values()[mPushStatus.ordinal()]);
1533 mPushStatus = AlivcLivePushStats.
RESUMING;
1534 mNativeAlivcLivePusher.resume(
false);
1535 PusherResumeEvent.Args args =
new PusherResumeEvent.Args();
1536 Map map = getPerformanceMap();
1539 args.isResumeScreen =
false;
1540 args.totalUploadSize = ParameterUtil.getLong(map,
"mTotalSizeOfUploadedPackets");
1541 args.totalTime = ParameterUtil.getLong(map,
"mTotalTimeOfPublishing");
1542 if (PusherPauseEvent.mLastPauseTime == 0) {
1545 args.cost = System.currentTimeMillis() - PusherPauseEvent.mLastPauseTime;
1547 if (mLiveEventReporter != null) {
1548 mLiveEventReporter.sendEvent(PusherResumeEvent.kTopicType, PusherResumeEvent.kTopicValue, PusherResumeEvent.getArgsStr(args));
1552 PusherPauseEvent.mLastPauseTime = 0;
1556 public void pauseScreenCapture() throws IllegalStateException {
1557 if (mNativeAlivcLivePusher == null) {
1558 AlivcLog.e(TAG,
"Illegal State, you should init first");
1561 if (mPushStatus != AlivcLivePushStats.
PUSHED && mPushStatus != AlivcLivePushStats.
PAUSED
1562 && mPushStatus != AlivcLivePushStats.
PREVIEWED) {
1563 AlivcLog.e(TAG,
"status error current state is " + AlivcLivePushStats.values()[mPushStatus.ordinal()]);
1566 mPushStatus = AlivcLivePushStats.
PAUSED;
1569 PusherPauseEvent.mLastPauseTime = System.currentTimeMillis();
1571 mNativeAlivcLivePusher.pauseScreenCapture();
1572 PusherPauseEvent.Args args =
new PusherPauseEvent.Args();
1573 Map map = getPerformanceMap();
1575 args.isPauseScreen =
true;
1576 args.totalUploadSize = ParameterUtil.getLong(map,
"mTotalSizeOfUploadedPackets");
1577 args.totalTime = ParameterUtil.getLong(map,
"mTotalTimeOfPublishing");
1578 if (mLiveEventReporter != null) {
1579 mLiveEventReporter.sendEvent(PusherPauseEvent.kTopicType, PusherPauseEvent.kTopicValue, PusherPauseEvent.getArgsStr(args));
1585 public void resumeScreenCapture() throws IllegalStateException {
1586 if (mNativeAlivcLivePusher == null) {
1587 AlivcLog.e(TAG,
"Illegal State, you should init first");
1590 if (mPushStatus != AlivcLivePushStats.
PAUSED) {
1591 AlivcLog.e(TAG,
"status error current state is " + AlivcLivePushStats.values()[mPushStatus.ordinal()]);
1595 mNativeAlivcLivePusher.resumeScreenCapture();
1596 PusherResumeEvent.Args args =
new PusherResumeEvent.Args();
1597 Map map = getPerformanceMap();
1600 args.isResumeScreen =
true;
1601 args.totalUploadSize = ParameterUtil.getLong(map,
"mTotalSizeOfUploadedPackets");
1602 args.totalTime = ParameterUtil.getLong(map,
"mTotalTimeOfPublishing");
1603 args.cost = System.currentTimeMillis() - PusherPauseEvent.mLastPauseTime;
1604 if (mLiveEventReporter != null) {
1605 mLiveEventReporter.sendEvent(PusherResumeEvent.kTopicType, PusherResumeEvent.kTopicValue, PusherResumeEvent.getArgsStr(args));
1609 PusherPauseEvent.mLastPauseTime = 0;
1611 if (mNativeAlivcLivePusher.isPushing()) {
1612 mPushStatus = AlivcLivePushStats.
PUSHED;
1614 mPushStatus = AlivcLivePushStats.
PREVIEWED;
1619 public void switchCamera() throws IllegalStateException {
1620 AlivcLog.i(TAG,
"switchCamera");
1621 if (mNativeAlivcLivePusher == null || mAlivcLivePushConfig == null) {
1622 AlivcLog.e(TAG,
"Illegal State, you should init first");
1625 if (mPushStatus != AlivcLivePushStats.
PREVIEWED && mPushStatus != AlivcLivePushStats.
PUSHED) {
1626 AlivcLog.e(TAG,
"status error current state is " + AlivcLivePushStats.values()[mPushStatus.ordinal()]);
1629 mNativeAlivcLivePusher.switchCamera();
1631 if (mAlivcLivePushConfig.
getCameraType() == CAMERA_TYPE_FRONT.getCameraId()) {
1638 PusherSwitchCameraEvent.Args args =
new PusherSwitchCameraEvent.Args();
1639 args.isFrontCamera = mAlivcLivePushConfig.
getCameraType() == CAMERA_TYPE_FRONT.getCameraId();
1640 if (mLiveEventReporter != null) {
1641 mLiveEventReporter.sendEvent(PusherSwitchCameraEvent.kTopicType, PusherSwitchCameraEvent.kTopicValue, PusherSwitchCameraEvent.getArgsStr(args));
1646 public void setAutoFocus(
boolean autoFocus)
throws IllegalStateException {
1647 AlivcLog.i(TAG,
"setAutoFocus auto: " + autoFocus);
1648 if (mNativeAlivcLivePusher == null) {
1649 AlivcLog.e(TAG,
"Illegal State, you should init first");
1652 if (mPushStatus != AlivcLivePushStats.
PREVIEWED && mPushStatus != AlivcLivePushStats.
PUSHED) {
1653 AlivcLog.e(TAG,
"status error current state is " + AlivcLivePushStats.values()[mPushStatus.ordinal()]);
1656 mNativeAlivcLivePusher.setCameraFocus(autoFocus, 0, 0);
1660 public void focusCameraAtAdjustedPoint(
float x,
float y,
boolean autoFocus)
throws IllegalStateException {
1661 AlivcLog.i(TAG,
"focusCameraAtAdjustedPoint x: " + x +
" y: " + y +
" auto: " + autoFocus);
1662 if (mNativeAlivcLivePusher == null) {
1663 AlivcLog.e(TAG,
"Illegal State, you should init first");
1666 if (mPushStatus != AlivcLivePushStats.
PREVIEWED && mPushStatus != AlivcLivePushStats.
PUSHED) {
1667 AlivcLog.e(TAG,
"status error current state is " + AlivcLivePushStats.values()[mPushStatus.ordinal()]);
1670 mNativeAlivcLivePusher.setCameraFocus(autoFocus, x, y);
1674 public void setExposure(
int exposure) {
1675 AlivcLog.i(TAG,
"setExposure exposure: " + exposure);
1676 if (mNativeAlivcLivePusher == null) {
1677 AlivcLog.e(TAG,
"Illegal State, you should init first");
1680 if (mPushStatus != AlivcLivePushStats.
PREVIEWED && mPushStatus != AlivcLivePushStats.
PUSHED) {
1681 AlivcLog.e(TAG,
"status error current state is " + AlivcLivePushStats.values()[mPushStatus.ordinal()]);
1684 mNativeAlivcLivePusher.setExposureCompensation(exposure);
1688 public int getCurrentExposure() {
1689 AlivcLog.i(TAG,
"getCurrentExposure");
1690 if (mNativeAlivcLivePusher == null) {
1691 AlivcLog.e(TAG,
"Illegal State, you should init first");
1694 if (mPushStatus != AlivcLivePushStats.
PREVIEWED && mPushStatus != AlivcLivePushStats.
PUSHED) {
1695 AlivcLog.e(TAG,
"status error current state is " + AlivcLivePushStats.values()[mPushStatus.ordinal()]);
1698 return mNativeAlivcLivePusher.getCurrentExposureCompensation();
1702 public int getSupportedMinExposure() {
1703 AlivcLog.i(TAG,
"getSupportedMinExposure");
1704 if (mNativeAlivcLivePusher == null) {
1705 AlivcLog.e(TAG,
"Illegal State, you should init first");
1708 if (mPushStatus != AlivcLivePushStats.
PREVIEWED && mPushStatus != AlivcLivePushStats.
PUSHED) {
1709 AlivcLog.e(TAG,
"status error current state is " + AlivcLivePushStats.values()[mPushStatus.ordinal()]);
1712 return mNativeAlivcLivePusher.getMinExposureCompensation();
1716 public int getSupportedMaxExposure() {
1717 AlivcLog.i(TAG,
"getSupportedMaxExposure");
1718 if (mNativeAlivcLivePusher == null) {
1719 AlivcLog.e(TAG,
"Illegal State, you should init first");
1722 if (mPushStatus != AlivcLivePushStats.
PREVIEWED && mPushStatus != AlivcLivePushStats.
PUSHED) {
1723 AlivcLog.e(TAG,
"status error current state is " + AlivcLivePushStats.values()[mPushStatus.ordinal()]);
1726 return mNativeAlivcLivePusher.getMaxExposureCompensation();
1730 public int setLiveMixTranscodingConfig(AlivcLiveTranscodingConfig config) {
1735 public int muteLocalCamera(
boolean mute) {
1741 public int enableSpeakerphone(
boolean enable) {
1747 public boolean isSpeakerphoneOn() {
1753 public void setZoom(
int zoom)
throws IllegalStateException {
1754 AlivcLog.i(TAG,
"setZoom zoom: " + zoom);
1755 if (mNativeAlivcLivePusher == null) {
1756 AlivcLog.e(TAG,
"Illegal State, you should init first");
1759 if (mPushStatus != AlivcLivePushStats.
PREVIEWED && mPushStatus != AlivcLivePushStats.
PUSHED) {
1760 AlivcLog.e(TAG,
"status error current state is " + AlivcLivePushStats.values()[mPushStatus.ordinal()]);
1763 mNativeAlivcLivePusher.setCameraZoom(zoom);
1767 public int getMaxZoom() throws IllegalStateException {
1768 AlivcLog.i(TAG,
"getMaxZoom");
1769 if (mNativeAlivcLivePusher == null) {
1770 AlivcLog.e(TAG,
"Illegal State, you should init first");
1773 if (mPushStatus != AlivcLivePushStats.
PREVIEWED && mPushStatus != AlivcLivePushStats.
PUSHED) {
1774 AlivcLog.e(TAG,
"status error current state is " + AlivcLivePushStats.values()[mPushStatus.ordinal()]);
1777 return mNativeAlivcLivePusher.getCameraMaxZoom();
1781 public int getCurrentZoom() throws IllegalStateException {
1782 AlivcLog.i(TAG,
"getCurrentZoom");
1783 if (mNativeAlivcLivePusher == null) {
1784 AlivcLog.e(TAG,
"Illegal State, you should init first");
1787 if (mPushStatus != AlivcLivePushStats.
PREVIEWED && mPushStatus != AlivcLivePushStats.
PUSHED) {
1788 AlivcLog.e(TAG,
"status error current state is " + AlivcLivePushStats.values()[mPushStatus.ordinal()]);
1792 return mNativeAlivcLivePusher.getCameraCurrentZoom();
1796 public void setMute(
boolean mute)
throws IllegalStateException {
1797 AlivcLog.i(TAG,
"setMute mute: " + mute);
1798 if (mNativeAlivcLivePusher == null || mAlivcLivePushConfig == null) {
1799 AlivcLog.e(TAG,
"Illegal State, you should init first");
1802 if (mPushStatus != AlivcLivePushStats.
PREVIEWED && mPushStatus != AlivcLivePushStats.
PUSHED && mPushStatus != AlivcLivePushStats.
PAUSED) {
1803 AlivcLog.e(TAG,
"status error current state is " + AlivcLivePushStats.values()[mPushStatus.ordinal()]);
1806 mNativeAlivcLivePusher.setMute(mute);
1810 if (mLiveEventReporter != null) {
1812 PusherMuteOnEvent.Args args =
new PusherMuteOnEvent.Args();
1813 mLiveEventReporter.sendEvent(PusherMuteOffEvent.kTopicType, PusherMuteOffEvent.kTopicValue, PusherMuteOnEvent.getArgsStr(args));
1815 PusherMuteOffEvent.Args args =
new PusherMuteOffEvent.Args();
1816 mLiveEventReporter.sendEvent(PusherMuteOffEvent.kTopicType, PusherMuteOffEvent.kTopicValue, PusherMuteOffEvent.getArgsStr(args));
1822 public void setFlash(
boolean flash)
throws IllegalStateException {
1823 AlivcLog.i(TAG,
"setFlash flash: " + flash);
1824 if (mNativeAlivcLivePusher == null || mAlivcLivePushConfig == null) {
1825 AlivcLog.e(TAG,
"Illegal State, you should init first");
1828 if (mPushStatus != AlivcLivePushStats.
PREVIEWED && mPushStatus != AlivcLivePushStats.
PUSHED) {
1829 AlivcLog.e(TAG,
"status error current state is " + AlivcLivePushStats.values()[mPushStatus.ordinal()]);
1832 mNativeAlivcLivePusher.setFlash(flash);
1833 mAlivcLivePushConfig.
setFlash(flash);
1835 PusherSetFlashEvent.Args args =
new PusherSetFlashEvent.Args();
1836 args.isOpen = flash;
1837 if (mLiveEventReporter != null) {
1838 mLiveEventReporter.sendEvent(PusherSetFlashEvent.kTopicType, PusherSetFlashEvent.kTopicValue, PusherSetFlashEvent.getArgsStr(args));
1843 public void setPushMirror(
boolean mirror)
throws IllegalStateException {
1844 AlivcLog.i(TAG,
"setPushMirror pushMirror: " + mirror);
1845 if (mNativeAlivcLivePusher == null) {
1846 AlivcLog.e(TAG,
"Illegal State, you should init first");
1849 if (mPushStatus != AlivcLivePushStats.
PREVIEWED && mPushStatus != AlivcLivePushStats.
PUSHED) {
1850 AlivcLog.e(TAG,
"status error current state is " + AlivcLivePushStats.values()[mPushStatus.ordinal()]);
1853 mNativeAlivcLivePusher.setPusherMirror(mirror);
1857 public void setPreviewMirror(
boolean mirror)
throws IllegalStateException {
1858 AlivcLog.i(TAG,
"setPreviewMirror previewMirror: " + mirror);
1859 if (mNativeAlivcLivePusher == null) {
1860 AlivcLog.e(TAG,
"Illegal State, you should init first");
1863 if (mPushStatus != AlivcLivePushStats.
PREVIEWED && mPushStatus != AlivcLivePushStats.
PUSHED) {
1864 AlivcLog.e(TAG,
"status error current state is " + AlivcLivePushStats.values()[mPushStatus.ordinal()]);
1867 mNativeAlivcLivePusher.setPreviewMirror(mirror);
1871 public void setTargetVideoBitrate(
int targetVideoBitrate)
throws IllegalArgumentException, IllegalStateException {
1872 AlivcLog.i(TAG,
"setTargetVideoBitrate targetVideoBitrate: " + targetVideoBitrate);
1873 if (mNativeAlivcLivePusher == null) {
1874 AlivcLog.e(TAG,
"Illegal State, you should init first");
1877 if (mPushStatus != AlivcLivePushStats.
PREVIEWED && mPushStatus != AlivcLivePushStats.
PUSHED) {
1878 AlivcLog.e(TAG,
"status error current state is " + AlivcLivePushStats.values()[mPushStatus.ordinal()]);
1881 mNativeAlivcLivePusher.setVideoBitrateRange(0, targetVideoBitrate, targetVideoBitrate);
1885 public void setMinVideoBitrate(
int minVideoBitrate)
throws IllegalArgumentException, IllegalStateException {
1886 AlivcLog.i(TAG,
"setMinVideoBitrate minVideoBitrate: " + minVideoBitrate);
1887 if (mNativeAlivcLivePusher == null) {
1888 AlivcLog.e(TAG,
"Illegal State, you should init first");
1891 if (mPushStatus != AlivcLivePushStats.
PREVIEWED && mPushStatus != AlivcLivePushStats.
PUSHED) {
1892 AlivcLog.e(TAG,
"status error current state is " + AlivcLivePushStats.values()[mPushStatus.ordinal()]);
1895 mNativeAlivcLivePusher.setVideoBitrateRange(minVideoBitrate, 0, 0);
1899 public boolean isCameraSupportAutoFocus() {
1900 AlivcLog.i(TAG,
"isCameraSupportAutoFocus");
1901 if (mNativeAlivcLivePusher == null) {
1902 AlivcLog.e(TAG,
"Illegal State, you should init first");
1905 if (mPushStatus != AlivcLivePushStats.
PREVIEWED && mPushStatus != AlivcLivePushStats.
PUSHED) {
1906 AlivcLog.e(TAG,
"status error current state is " + AlivcLivePushStats.values()[mPushStatus.ordinal()]);
1909 return mNativeAlivcLivePusher.isCameraSupportAutoFocus();
1913 public boolean isCameraSupportFlash() {
1914 AlivcLog.i(TAG,
"isCameraSupportFlash");
1916 if (mNativeAlivcLivePusher == null) {
1917 AlivcLog.e(TAG,
"Illegal State, you should init first");
1920 if (mPushStatus != AlivcLivePushStats.
PREVIEWED && mPushStatus != AlivcLivePushStats.
PUSHED) {
1921 AlivcLog.e(TAG,
"status error current state is " + AlivcLivePushStats.values()[mPushStatus.ordinal()]);
1924 return mNativeAlivcLivePusher.isCameraSupportFlash();
1928 public boolean isPushing() throws IllegalStateException {
1931 if (mNativeAlivcLivePusher != null) {
1932 return mNativeAlivcLivePusher.isPushing();
1938 public AlivcLivePushStats getCurrentStatus() {
1943 public AlivcLivePushError getLastError() {
1948 public void snapshot(
int count,
int interval, AlivcSnapshotListener listener) {
1949 mSnapshotListener = listener;
1950 if (mNativeAlivcLivePusher != null) {
1951 mNativeAlivcLivePusher.snapshot(count, interval, mInnerSnapshotListener);
1956 public boolean isNetworkPushing() throws IllegalStateException {
1959 if (mNativeAlivcLivePusher != null) {
1960 return mNativeAlivcLivePusher.isNetworkPushing();
1966 public void setLivePushErrorListener(AlivcLivePushErrorListener errorListener) {
1967 this.mPushErrorListener = errorListener;
1971 public void setLivePushInfoListener(AlivcLivePushInfoListener infoListener) {
1972 this.mPushInfoListener = infoListener;
1976 public void setLivePushNetworkListener(AlivcLivePushNetworkListener networkListner) {
1977 this.mPushNetworkListener = networkListner;
1981 public void setLivePushBGMListener(AlivcLivePushBGMListener pushBGMListener) {
1982 this.mPushBGMListener = pushBGMListener;
1986 public void setLivePushRenderContextListener(AlivcLivePusherRenderContextListener renderCtxListener) {
1987 this.mRenderContextListener = renderCtxListener;
1991 public AlivcLivePushStatsInfo getLivePushStatsInfo() throws IllegalStateException {
1994 if (mNativeAlivcLivePusher == null) {
1997 AlivcLivePushStatsInfo info =
new AlivcLivePushStatsInfo();
1998 String mapStr = mNativeAlivcLivePusher.getPerformanceInfo();
1999 if (mapStr == null ||
"".equals(mapStr)) {
2002 Map map =
new HashMap<String, String>();
2003 StringTokenizer items;
2004 for (StringTokenizer entries =
new StringTokenizer(mapStr,
"|"); entries.hasMoreTokens();
2005 map.put(items.nextToken(), items.hasMoreTokens() ? ((String) (items.nextToken())) : null)) {
2006 items =
new StringTokenizer(entries.nextToken(),
":");
2009 info.setVideoCaptureFps(getInteger(map,
"mVideoCaptureFps"));
2010 info.setAudioEncodeBitrate(getInteger(map,
"mAudioEncodeBitrate"));
2011 info.setVideoRenderFps(getInteger(map,
"mVideoRenderingFPS"));
2012 info.setAudioEncodeFps(getInteger(map,
"mAudioEncodeFps"));
2013 info.setVideoEncodeMode(AlivcEncodeModeEnum.values()[getInteger(map,
"mPresetVideoEncoderMode")]);
2014 info.setVideoEncodeBitrate(getInteger(map,
"mVideoEncodeBitrate"));
2015 info.setVideoEncodeFps(getInteger(map,
"mVideoEncodedFps"));
2016 info.setTotalFramesOfEncodedVideo(getLong(map,
"mTotalFramesOfEncodedVideo"));
2017 info.setTotalTimeOfEncodedVideo(getLong(map,
"mTotalTimeOfEncodedVideo"));
2018 info.setVideoEncodeParam(getInteger(map,
"mPresetVideoEncoderBitrate"));
2019 info.setAudioUploadBitrate(getInteger(map,
"mAudioUploadBitrate"));
2020 info.setVideoUploadBitrate(getInteger(map,
"mVideoUploadBitrate"));
2021 info.setAudioPacketsInUploadBuffer(getInteger(map,
"mAudioPacketsInBuffer"));
2022 info.setVideoPacketsInUploadBuffer(getInteger(map,
"mVideoPacketsInBuffer"));
2023 info.setVideoUploadeFps(getInteger(map,
"mVideoUploadedFps"));
2024 info.setAudioUploadFps(getInteger(map,
"mAudioUploadingPacketsPerSecond"));
2025 info.setCurrentlyUploadedVideoFramePts(getLong(map,
"mCurrentlyUploadedVideoFramePts"));
2026 info.setCurrentlyUploadedAudioFramePts(getLong(map,
"mCurrentlyUploadedAudioFramePts"));
2027 info.setPreviousVideoKeyFramePts(getLong(map,
"mPreviousKeyFramePts"));
2028 info.setLastVideoPtsInBuffer(getLong(map,
"mLastVideoFramePTSInQueue"));
2029 info.setLastAudioPtsInBuffer(getLong(map,
"mLastAudioFramePTSInQueue"));
2030 info.setTotalSizeOfUploadedPackets(getLong(map,
"mTotalSizeOfUploadedPackets"));
2031 info.setTotalTimeOfUploading(getLong(map,
"mTotalTimeOfPublishing"));
2032 info.setTotalFramesOfUploadedVideo(getLong(map,
"mTotalFramesOfVideoUploaded"));
2033 info.setTotalDurationOfDropingVideoFrames(getLong(map,
"mDropDurationOfVideoFrames"));
2034 info.setTotalTimesOfDropingVideoFrames(getLong(map,
"mTotalDroppedTimes"));
2035 info.setTotalTimesOfDisconnect(getInteger(map,
"mTotalNetworkDisconnectedTimes"));
2036 info.setTotalTimesOfReconnect(getInteger(map,
"mTotalNetworkReconnectedTimes"));
2037 info.setVideoDurationFromeCaptureToUpload(getInteger(map,
"mVideoDurationFromeCaptureToUpload"));
2038 info.setAudioDurationFromeCaptureToUpload(getInteger(map,
"mAudioDurationFromeCaptureToUpload"));
2039 info.setCurrentUploadPacketSize(getInteger(map,
"mCurrentUploadingPacketSize"));
2040 info.setMaxSizeOfVideoPacketsInBuffer(getInteger(map,
"mMaxVideoPacketSize"));
2041 info.setMaxSizeOfAudioPacketsInBuffer(getInteger(map,
"mMaxAudioPacketSize"));
2042 info.setLastVideoFramePTSInQueue(getLong(map,
"mLastVideoFramePTSInQueue"));
2043 info.setLastAudioFramePTSInQueue(getLong(map,
"mLastAudioFramePTSInQueue"));
2044 info.setAvPTSInterval(getLong(map,
"mAvPTSInterval"));
2045 info.setAudioFrameInEncodeBuffer(getInteger(map,
"mAudioFramesInEncoderQueue"));
2046 info.setVideoFramesInEncodeBuffer(getInteger(map,
"mVideoFramesInEncoderQueue"));
2047 info.setVideoFramesInRenderBuffer(getInteger(map,
"mVideoFramesInRenderQueue"));
2048 info.setVideoRenderConsumingTimePerFrame(getInteger(map,
"mVideoRenderConsumingTimePerFrame"));
2049 info.setTotalDroppedAudioFrames(getInteger(map,
"mTotalDroppedAudioFrames"));
2050 info.setRtt(getInteger(map,
"mRtt"));
2051 info.setVideoLostRate(getInteger(map,
"mVideoLostRate"));
2052 info.setAudioLostRate(getInteger(map,
"mAudioLostRate"));
2053 info.setVideoReSendBitRate(getInteger(map,
"mVideoReSendBitRate"));
2054 info.setAudioReSendBitRate(getInteger(map,
"mAudioReSendBitRate"));
2055 info.setVideoEncodingWidth(getInteger(map,
"mVideoEncodingWidth"));
2056 info.setVideoEncodingHeight(getInteger(map,
"mVideoEncodingHeight"));
2057 info.setVideoEncodingGopSize(getInteger(map,
"mVideoEncodingGopSize"));
2058 info.setAudioCapturingSampleRate(getInteger(map,
"mAudioCapturingSampleRate"));
2059 info.setAudioCaptureVolume(getInteger(map,
"mAudioCaptureVolume"));
2061 info.setCpu((
float)AliLiveInfoUtils.getCPUUsageRatio());
2062 info.setMemory(ParameterUtil.getRunningAppProcessInfo(mContext));
2063 if (!TextUtils.isEmpty(mPushUrl)) {
2064 if (mPushUrl.startsWith(AlivcLiveStreamType.EnumType.AlivcLiveStreamRtmp.getPrefix())) {
2065 info.setAlivcLivePushPublishType(AlivcLiveStreamType.EnumType.AlivcLiveStreamRtmp.getValue());
2066 }
else if (mPushUrl.startsWith(AlivcLiveStreamType.EnumType.AlivcLiveStreamRts.getPrefix())) {
2067 info.setAlivcLivePushPublishType(AlivcLiveStreamType.EnumType.AlivcLiveStreamRts.getValue());
2070 }
catch (IllegalStateException e) {
2071 e.printStackTrace();
2072 }
catch (Exception e) {
2073 e.printStackTrace();
2079 public String getPushUrl() {
2080 return AlivcLiveURLTools.getUrlWithoutParameters(mPushUrl);
2083 private void checkConfig(AlivcLivePushConfig livePushConfig)
throws IllegalStateException {
2084 if (livePushConfig == null) {
2085 throw new IllegalArgumentException(
"Invalid parameter, config is null.");
2088 if (livePushConfig.isVideoOnly() && livePushConfig.isAudioOnly()) {
2089 throw new IllegalStateException(
"cannot set video only and audio only simultaneously");
2092 if (livePushConfig.getTargetVideoBitrate() < 100 || livePushConfig.getTargetVideoBitrate() > 5000) {
2093 throw new IllegalStateException(
"video target bitrate error, Range:[100 5000]");
2095 if (livePushConfig.getMinVideoBitrate() < 100 || livePushConfig.getMinVideoBitrate() > 5000) {
2096 throw new IllegalStateException(
"video min bitrate error, Range:[100 5000]");
2098 if (livePushConfig.getInitialVideoBitrate() < livePushConfig.getMinVideoBitrate() || livePushConfig.getInitialVideoBitrate() < 100
2099 || livePushConfig.getInitialVideoBitrate() > 5000) {
2100 throw new IllegalStateException(
"init bitrate error");
2102 if (livePushConfig.getConnectRetryCount() <= 0 || livePushConfig.getConnectRetryCount() > 100) {
2103 throw new IllegalStateException(
"connect retry count error, Range:[0 100]");
2105 if (livePushConfig.getConnectRetryInterval() <= 0 || livePushConfig.getConnectRetryInterval() > 10000) {
2106 throw new IllegalStateException(
"connect retry interval error, Range:[0 10000]");
2109 if (livePushConfig.getMinFps() <= 0 || livePushConfig.getMinFps() > livePushConfig.getFps()) {
2110 throw new IllegalStateException(
"fps error");
2113 for (
int i = 0; i < livePushConfig.getWaterMarkInfos().size(); i++) {
2115 if (livePushConfig.getWaterMarkInfos().get(i).mWaterMarkCoordX > 1 || livePushConfig.getWaterMarkInfos().get(i).mWaterMarkWidth > 1
2116 || livePushConfig.getWaterMarkInfos().get(i).mWaterMarkCoordY > 1 || livePushConfig.getWaterMarkInfos().get(i).mWaterMarkHeight > 1) {
2117 throw new IllegalStateException(
"watermark param error");
2120 if (livePushConfig.getWaterMarkInfos().get(i).mWaterMarkCoordX < 0 || livePushConfig.getWaterMarkInfos().get(i).mWaterMarkWidth <= 0
2121 || livePushConfig.getWaterMarkInfos().get(i).mWaterMarkCoordY < 0 || livePushConfig.getWaterMarkInfos().get(i).mWaterMarkHeight <= 0) {
2122 throw new IllegalStateException(
"watermark param error");
2128 public void setPreviewOrientation(AlivcPreviewOrientationEnum orientation) {
2129 AlivcLog.i(TAG,
"setPreviewOrientation");
2130 if (mNativeAlivcLivePusher == null) {
2131 AlivcLog.e(TAG,
"Illegal State, you should init first");
2134 if (mPushStatus != AlivcLivePushStats.
PREVIEWED && mPushStatus != AlivcLivePushStats.
PUSHED) {
2135 AlivcLog.e(TAG,
"status error current state is " + AlivcLivePushStats.values()[mPushStatus.ordinal()]);
2139 mNativeAlivcLivePusher.setOrientaion(orientation.getOrientation());
2143 public int setAudioEffectVoiceChangeMode(AlivcLivePushAudioEffectVoiceChangeMode mode) {
2144 AlivcLog.i(TAG,
"setAudioEffectVoiceChangeMode: " + mode);
2146 if (mNativeAlivcLivePusher == null || mAlivcLivePushConfig == null) {
2147 AlivcLog.e(TAG,
"Illegal State, you should init first");
2152 AlivcLog.e(TAG,
"Sound effect can not be used on the video only mode!");
2156 return mNativeAlivcLivePusher.setNativeAudioEffectVoiceMode(mode.getValue());
2160 public int setAudioEffectReverbMode(AlivcLivePushAudioEffectReverbMode mode) {
2161 AlivcLog.i(TAG,
"setAudioEffectReverbMode: " + mode);
2163 if (mNativeAlivcLivePusher == null || mAlivcLivePushConfig == null) {
2164 AlivcLog.e(TAG,
"Illegal State, you should init first");
2169 AlivcLog.e(TAG,
"Sound effect can not be used on the video only mode!");
2173 return mNativeAlivcLivePusher.setNativeAudioEffectReverbMode(mode.getValue());
2176 private Map<String, String> getPerformanceMap() {
2177 if (mNativeAlivcLivePusher == null) {
2180 String mapStr = mNativeAlivcLivePusher.getPerformanceInfo();
2181 if (mapStr == null ||
"".equals(mapStr)) {
2184 Map map =
new HashMap<String, String>();
2185 StringTokenizer items;
2186 for (StringTokenizer entries =
new StringTokenizer(mapStr,
"|"); entries.hasMoreTokens(); map
2187 .put(items.nextToken(), items.hasMoreTokens() ? ((String) (items.nextToken())) : null)) {
2188 items =
new StringTokenizer(entries.nextToken(),
":");
2193 private String getHeartBeatInfo() {
2194 if (mNativeAlivcLivePusher == null) {
2198 String heartBeatInfo = mNativeAlivcLivePusher.getPusherInfo();
2199 heartBeatInfo +=
",cpu:" + AliLiveInfoUtils.getCPUUsageRatio();
2200 heartBeatInfo +=
",mem:" + AliLiveInfoUtils.getMemoryUsageRatio();
2202 return heartBeatInfo;
2206 public String getLiveTraceId() {
2207 if (mNativeAlivcLivePusher == null) {
2210 return mNativeAlivcLivePusher.getPusherTraceId();
2214 public void sendMessage(String info,
int repeat,
int delay,
boolean isKeyFrame) {
2215 AlivcLog.i(TAG,
"sendMessage: " + info +
", repeat:" + repeat +
", delay:" + delay +
", isKeyFrame:" + isKeyFrame);
2218 sendMessageInternal(info, repeat, delay, isKeyFrame,
false);
2219 }
catch (Exception e) {
2220 e.printStackTrace();
2224 private void sendMessageInternal(String info,
int repeat,
int delay,
boolean isKeyFrame,
boolean isGDelayInfo)
throws IllegalStateException, IllegalArgumentException {
2225 if (mNativeAlivcLivePusher == null) {
2226 AlivcLog.e(TAG,
"Illegal State, you should init first");
2229 if (!mNativeAlivcLivePusher.isPushing()) {
2230 AlivcLog.e(TAG,
"Status error, status should be PUSHED");
2233 if (TextUtils.isEmpty(info) || info.length() > MAX_CHATS) {
2234 AlivcLog.e(TAG,
"The maximum length is 4000");
2237 mNativeAlivcLivePusher.addSeiInfo(info, repeat, delay, isKeyFrame, isGDelayInfo);
2240 private int getBGMVolume() {
2247 private int getCaptureVolume() {
2251 return mCaptureVolume;
2254 private boolean getHeadSetPlugOn() {
2255 return LivePusherJNI.headSetOn;
2258 private boolean getBlueToothHeadSetOn() {
2259 if (mBluetoothHelper != null) {
2260 return mBluetoothHelper.isOnHeadsetSco();
2266 public void startBGMAsync(String path)
throws IllegalStateException {
2267 AlivcLog.i(TAG,
"startBGMAsync");
2268 if (mNativeAlivcLivePusher == null) {
2269 AlivcLog.e(TAG,
"Illegal State, you should init first");
2272 if (mPushStatus == AlivcLivePushStats.
IDLE || mPushStatus == AlivcLivePushStats.
ERROR) {
2273 AlivcLog.e(TAG,
"status error current state is " + AlivcLivePushStats.values()[mPushStatus.ordinal()]);
2277 if (mPlayStats == AlivcLivePlayStats.IDLE || mPlayStats == AlivcLivePlayStats.STOPPED) {
2278 PusherSetBGMEvent.Args args =
new PusherSetBGMEvent.Args();
2280 args.music = getBGMVolume();
2281 args.voice = getCaptureVolume();
2282 if (mLiveEventReporter != null) {
2283 mLiveEventReporter.sendEvent(PusherSetBGMEvent.kTopicType, PusherSetBGMEvent.kTopicValue, PusherSetBGMEvent.getArgsStr(args));
2288 mNativeAlivcLivePusher.stopBGM();
2289 mNativeAlivcLivePusher.startBGMAsync(path);
2293 public void stopBGMAsync() throws IllegalStateException {
2294 AlivcLog.i(TAG,
"stopBGMAsync");
2295 if (mNativeAlivcLivePusher == null) {
2296 AlivcLog.e(TAG,
"Illegal State, you should init first");
2299 if (mPlayStats == AlivcLivePlayStats.IDLE) {
2300 AlivcLog.e(TAG,
"status error current state is " + AlivcLivePlayStats.values()[mPlayStats.ordinal()]);
2304 mNativeAlivcLivePusher.stopBGM();
2305 PusherSetBGMEvent.Args args =
new PusherSetBGMEvent.Args();
2306 args.isOpen =
false;
2307 args.music = getBGMVolume();
2308 args.voice = getCaptureVolume();
2309 if (mLiveEventReporter != null) {
2310 mLiveEventReporter.sendEvent(PusherSetBGMEvent.kTopicType, PusherSetBGMEvent.kTopicValue, PusherSetBGMEvent.getArgsStr(args));
2315 public void pauseBGM() throws IllegalStateException {
2316 AlivcLog.i(TAG,
"pauseBGM");
2317 if (mNativeAlivcLivePusher == null) {
2318 AlivcLog.e(TAG,
"Illegal State, you should init first");
2321 if (mPlayStats != AlivcLivePlayStats.STARTED) {
2322 AlivcLog.e(TAG,
"status error current state is " + AlivcLivePlayStats.values()[mPlayStats.ordinal()]);
2326 mNativeAlivcLivePusher.pauseBGM();
2330 public void resumeBGM() throws IllegalStateException {
2331 AlivcLog.i(TAG,
"resumeBGM");
2332 if (mNativeAlivcLivePusher == null) {
2333 AlivcLog.e(TAG,
"Illegal State, you should init first");
2336 if (mPlayStats != AlivcLivePlayStats.PAUSED) {
2337 AlivcLog.e(TAG,
"status error current state is " + AlivcLivePlayStats.values()[mPlayStats.ordinal()]);
2341 mNativeAlivcLivePusher.resumeBGM();
2345 public void setBGMLoop(
boolean isLoop)
throws IllegalStateException {
2346 if (mNativeAlivcLivePusher != null) {
2347 mNativeAlivcLivePusher.setBGMLoop(isLoop);
2349 PusherSetBGMLoopEvent.Args args =
new PusherSetBGMLoopEvent.Args();
2350 args.value = isLoop;
2351 if (mLiveEventReporter != null) {
2352 mLiveEventReporter.sendEvent(PusherSetBGMLoopEvent.kTopicType, PusherSetBGMLoopEvent.kTopicValue, PusherSetBGMLoopEvent.getArgsStr(args));
2357 public void setBGMEarsBack(
boolean isOpen)
throws IllegalStateException {
2358 if (mNativeAlivcLivePusher != null) {
2359 mNativeAlivcLivePusher.setEarsBack(isOpen);
2361 PusherSetBGMEarsBackEvent.Args args =
new PusherSetBGMEarsBackEvent.Args();
2362 args.value = isOpen;
2363 args.bh = getBlueToothHeadSetOn() ? 1 : 0;
2364 args.eh = getHeadSetPlugOn() ? 1 : 0;
2365 if (mLiveEventReporter != null) {
2366 mLiveEventReporter.sendEvent(PusherSetBGMEarsBackEvent.kTopicType, PusherSetBGMEarsBackEvent.kTopicValue, PusherSetBGMEarsBackEvent.getArgsStr(args));
2371 public void setBGMVolume(
int volume)
throws IllegalStateException, IllegalArgumentException {
2372 if (mNativeAlivcLivePusher == null) {
2373 AlivcLog.e(TAG,
"Illegal State, you should init first");
2376 mBGMVolume = (volume > 0 && volume < 10) ? 10 : volume;
2377 mNativeAlivcLivePusher.setBackgroundMusicVolume(mBGMVolume / 10);
2381 public void setCaptureVolume(
int volume)
throws IllegalStateException, IllegalArgumentException {
2382 if (mNativeAlivcLivePusher == null) {
2383 AlivcLog.e(TAG,
"Illegal State, you should init first");
2386 mCaptureVolume = (volume > 0 && volume < 10) ? 10 : volume;
2387 mNativeAlivcLivePusher.setAudioVolume(mCaptureVolume / 10);
2391 public void setAudioDenoise(
boolean on) {
2392 AlivcLog.i(TAG,
"setAudioDenoise, " + on);
2394 if (mNativeAlivcLivePusher == null || mAlivcLivePushConfig == null) {
2395 AlivcLog.e(TAG,
"Illegal State, you should init first");
2400 AlivcLog.e(TAG,
"Audio denoise can not be used on the video only mode!");
2404 mNativeAlivcLivePusher.setAudioDenoise(on);
2408 public int startIntelligentDenoise() {
2409 AlivcLog.i(TAG,
"startIntelligentDenoise");
2410 return setIntelligentDenoiseInternal(
true);
2414 public int stopIntelligentDenoise() {
2415 AlivcLog.i(TAG,
"stopIntelligentDenoise");
2416 return setIntelligentDenoiseInternal(
false);
2419 private int setIntelligentDenoiseInternal(
boolean flag) {
2420 if (!AlivcLivePushIntelligentDenoiseManager.isFeatureWorked(mContext)) {
2421 AlivcLog.e(TAG,
"Intelligent denoise feature not worked due to the lack of native library file! " +
2422 "You can try to read the API doc to find the solution!");
2426 if (mNativeAlivcLivePusher == null || mAlivcLivePushConfig == null) {
2427 AlivcLog.e(TAG,
"Illegal State, you should init first");
2432 AlivcLog.e(TAG,
"Audio denoise can not be used on the video only mode!");
2438 result = mNativeAlivcLivePusher.startNativeIntelligentDenoise();
2440 result = mNativeAlivcLivePusher.stopNativeIntelligentDenoise();
2443 AlivcLog.i(TAG,
"setIntelligentDenoiseInternal " + flag +
", return " + result);
2448 public void setQualityMode(AlivcQualityModeEnum mode)
throws IllegalStateException {
2449 if (mNativeAlivcLivePusher == null) {
2450 AlivcLog.e(TAG,
"Illegal State, you should init first");
2453 if (AlivcQualityModeEnum.QM_CUSTOM.equals(mode)) {
2454 AlivcLog.e(TAG,
"Cannot set QM_CUSTOM dynamically");
2457 mNativeAlivcLivePusher.setQualityMode(mode.getQualityMode());
2461 public void setPreviewMode(AlivcPreviewDisplayMode mode)
throws IllegalStateException {
2462 if (mNativeAlivcLivePusher == null || mAlivcLivePushConfig == null) {
2463 AlivcLog.e(TAG,
"Illegal State, you should init first");
2467 mNativeAlivcLivePusher.setDisplayMode(mode.getPreviewDisplayMode());
2471 private void startScheduleExecutor() {
2472 if (scheduleExecutor != null) {
2475 if (scheduleExecutor == null || scheduleExecutor.isShutdown()) {
2476 scheduleExecutor =
new ScheduledThreadPoolExecutor(1,
new ThreadFactory() {
2477 private AtomicInteger atoInteger =
new AtomicInteger(0);
2480 public Thread newThread(Runnable r) {
2481 Thread t =
new Thread(r);
2482 t.setName(
"LivePusher-report-Thread " + atoInteger.getAndIncrement());
2487 scheduleExecutor.scheduleAtFixedRate(
new Runnable() {
2491 mTimeCount = mTimeCount + 1;
2492 if(mTimeCount == 5) {
2493 if (mTimeStamp != -1) {
2494 if (mExpiryTime < 60) {
2495 if (mPushNetworkListener != null) {
2497 if (!TextUtils.isEmpty(url) && !url.equals(mPushUrl)) {
2498 reconnectPushAsync(url);
2502 mExpiryTime = mExpiryTime - 5;
2506 PusherHeartBeatEvent.Args args =
new PusherHeartBeatEvent.Args();
2507 args.mediaInfo = getHeartBeatInfo();
2508 mLiveEventReporter.sendEvent(PusherHeartBeatEvent.kTopicType, PusherHeartBeatEvent.kTopicValue, PusherHeartBeatEvent.getArgsStr(args));
2511 mPushInfoListener.
onPushStatistics(getLivePusherReference(),getLivePushStatsInfo());
2513 }, 0, 2 * 1000, TimeUnit.MILLISECONDS);
2517 private int[] getImageWidthHeight(String path) {
2518 BitmapFactory.Options options =
new BitmapFactory.Options();
2520 options.inJustDecodeBounds =
true;
2522 Bitmap bitmap = BitmapFactory.decodeFile(path, options);
2523 }
catch (Exception e) {
2524 return new int[]{0, 0};
2527 return new int[]{options.outWidth, options.outHeight};
2531 private void addWaterMark() {
2532 if (mAlivcLivePushConfig == null) {
2533 AlivcLog.e(TAG,
"Illegal State, you should init first");
2536 ArrayList<WaterMarkInfo> waterMarkInfos = mAlivcLivePushConfig.getWaterMarkInfos();
2537 int size = waterMarkInfos.size();
2538 for (
int i = 0; i < size; i++) {
2539 addWaterMark(waterMarkInfos.get(i).mWaterMarkPath, waterMarkInfos.get(i).mWaterMarkCoordX, waterMarkInfos.get(i).mWaterMarkCoordY,
2540 waterMarkInfos.get(i).mWaterMarkWidth);
2544 private void stop5Interval() {
2545 if (scheduleExecutor != null && !scheduleExecutor.isShutdown()) {
2546 scheduleExecutor.shutdown();
2548 scheduleExecutor = null;
2552 private void rtsDownToRtmp() {
2553 AlivcLog.w(TAG,
"rts downgrade to rtmp");
2554 if (TextUtils.isEmpty(mPushUrl) || !mPushUrl.startsWith(AlivcLiveStreamType.EnumType.AlivcLiveStreamRts.getPrefix())) {
2558 AlivcLog.w(TAG,
"pre url: " + mPushUrl);
2559 mPushUrl = mPushUrl.replaceFirst(AlivcLiveStreamType.EnumType.AlivcLiveStreamRts.getPrefix(), AlivcLiveStreamType.EnumType.AlivcLiveStreamRtmp.getPrefix());
2560 AlivcLog.w(TAG,
"after url: " + mPushUrl);
2561 mPushStatus = AlivcLivePushStats.
ERROR;
2564 if (mNativeAlivcLivePusher != null) {
2565 mNativeAlivcLivePusher.release();
2566 mNativeAlivcLivePusher.init();
2569 startPushAsync(mPushUrl);
2572 private void reportStartPushEvent(
boolean isRestart,
boolean isSync) {
2573 PusherStartPushEvent.Args args =
new PusherStartPushEvent.Args();
2574 Map map = getPerformanceMap();
2577 args.vutMs = getInteger(map,
"mVideoDurationFromeCaptureToUpload");
2578 args.autMs = getInteger(map,
"mAudioDurationFromeCaptureToUpload");
2579 args.resolution = mAlivcLivePushConfig.
getResolution().toString().substring(11);
2580 args.st = mAlivcLivePushConfig.
getAudioChannels() == 1 ?
"single" :
"dual";
2584 args.wc = mAlivcLivePushConfig.getWaterMarkInfos().size();
2586 args.fps = mAlivcLivePushConfig.
getFps();
2593 args.flash = mAlivcLivePushConfig.
isFlash();
2601 mLiveEventReporter.sendEvent(PusherRestartPushEvent.kTopicType, PusherRestartPushEvent.kTopicValue, PusherRestartPushEvent.getArgsStr(args));
2603 mLiveEventReporter.sendEvent(PusherStartPushEvent.kTopicType, PusherStartPushEvent.kTopicValue, PusherStartPushEvent.getArgsStr(args));
2608 private BroadcastReceiver mHeadsetPlugReceiver =
new BroadcastReceiver() {
2611 public void onReceive(Context context, Intent intent) {
2613 String action = intent.getAction();
2614 if (AudioManager.ACTION_AUDIO_BECOMING_NOISY.equals(action)) {
2615 AlivcLog.d(
"BluetoothHeadsetUtils",
"ACTION_AUDIO_BECOMING_NOISY headset out");
2617 mAudioManager.setMode(AudioManager.STREAM_VOICE_CALL);
2618 mAudioManager.setSpeakerphoneOn(
true);
2620 LivePusherJNI.headSetOn =
false;
2621 if (mNativeAlivcLivePusher != null) {
2622 mNativeAlivcLivePusher.setHeadSet(
false);
2624 }
else if (
"android.intent.action.HEADSET_PLUG".equals(action)) {
2625 if (intent.hasExtra(
"state")) {
2626 if (intent.getIntExtra(
"state", 0) == 0) {
2627 AlivcLog.d(
"BluetoothHeadsetUtils",
"headset out");
2629 mAudioManager.setMode(AudioManager.STREAM_VOICE_CALL);
2630 mAudioManager.setSpeakerphoneOn(
true);
2632 if (LivePusherJNI.headSetOn) {
2633 LivePusherJNI.headSetOn =
false;
2634 if (mNativeAlivcLivePusher != null) {
2635 mNativeAlivcLivePusher.setHeadSet(
false);
2638 }
else if (intent.getIntExtra(
"state", 0) == 1) {
2640 AlivcLog.d(
"BluetoothHeadsetUtils",
"headset in");
2641 mAudioManager.setSpeakerphoneOn(
false);
2642 LivePusherJNI.headSetOn =
true;
2643 if (mNativeAlivcLivePusher != null) {
2644 mNativeAlivcLivePusher.setHeadSet(
true);
2653 private BroadcastReceiver mTelephoneReceiver =
new BroadcastReceiver() {
2655 public void onReceive(Context context, Intent intent) {
2656 if (intent.getAction().equals(Intent.ACTION_NEW_OUTGOING_CALL)) {
2659 if (manager == null) {
2660 if (Looper.myLooper() == null) {
2663 manager = (TelephonyManager) context.getSystemService(Service.TELEPHONY_SERVICE);
2664 manager.listen(
new PhoneStateListener() {
2666 public void onCallStateChanged(
int state, String incomingNumber) {
2667 super.onCallStateChanged(state, incomingNumber);
2669 case TelephonyManager.CALL_STATE_IDLE:
2671 AlivcLog.i(TAG,
"PHONE: CALL_STATE_IDLE");
2672 if (mNativeAlivcLivePusher != null) {
2673 mNativeAlivcLivePusher.setMute(
false);
2676 case TelephonyManager.CALL_STATE_OFFHOOK:
2678 AlivcLog.i(TAG,
"PHONE: CALL_STATE_OFFHOOK");
2679 if (mNativeAlivcLivePusher != null) {
2680 mNativeAlivcLivePusher.setMute(
true);
2683 case TelephonyManager.CALL_STATE_RINGING:
2685 AlivcLog.i(TAG,
"PHONE: CALL_STATE_RINGING");
2686 if (mNativeAlivcLivePusher != null) {
2687 mNativeAlivcLivePusher.setMute(
true);
2694 }, PhoneStateListener.LISTEN_CALL_STATE);
2701 private void registerHeadsetPlugReceiver() {
2703 IntentFilter intentFilter =
new IntentFilter();
2704 intentFilter.addAction(
"android.intent.action.HEADSET_PLUG");
2705 mContext.registerReceiver(mHeadsetPlugReceiver, intentFilter);
2707 IntentFilter intentFilter1 =
new IntentFilter(AudioManager.ACTION_AUDIO_BECOMING_NOISY);
2708 mContext.registerReceiver(mHeadsetPlugReceiver, intentFilter1);
2711 IntentFilter intentTelephony =
new IntentFilter();
2712 intentTelephony.addAction(
"android.intent.action.PHONE_STATE");
2713 mContext.registerReceiver(mTelephoneReceiver, intentTelephony);
2715 registeredCallback =
true;
2718 private void LogWhenGoBackOrFront(Application app,
boolean bind) {
2720 mAppFrontBackHelper =
new AppFrontBackHelper();
2721 mAppFrontBackHelper.bindApplication(app,
new AppFrontBackHelper.OnAppStatusListener() {
2723 public void onFront() {
2724 if (mNativeAlivcLivePusher != null) {
2725 AlivcLog.i(TAG,
"applicationWillBecomeActive");
2726 mNativeAlivcLivePusher.setAppBackgroundState(
false);
2731 public void onBack() {
2732 if (mNativeAlivcLivePusher != null) {
2733 AlivcLog.i(TAG,
"applicationWillResignActive");
2734 mNativeAlivcLivePusher.setAppBackgroundState(
true);
2739 if(mAppFrontBackHelper != null){
2740 mAppFrontBackHelper.unBindApplication(app);
2741 mAppFrontBackHelper = null;
2746 private void getNetworkTime() {
2747 new ScheduledThreadPoolExecutor(1,
new ThreadFactory() {
2748 private AtomicInteger atoInteger =
new AtomicInteger(0);
2751 public Thread newThread(Runnable r) {
2752 Thread t =
new Thread(r);
2753 t.setName(
"LivePusher-NTP-Time-Thread " + atoInteger.getAndIncrement());
2756 }).execute(
new Runnable() {
2759 for (
int i = 0; i < 3; i++) {
2760 mTimeStamp = getTimeFromNtpServer(
"time.pool.aliyun.com");
2761 if (mTimeStamp > 0) {
2762 mTimeStamp = mTimeStamp / 1000;
2766 if (mTimeStamp < 0) {
2767 mTimeStamp = System.currentTimeMillis() / 1000;
2769 if (getTimestamp(mPushUrl) != -1) {
2770 mExpiryTime = (int) ((getTimestamp(mPushUrl) - mTimeStamp));
2776 private long getTimeFromNtpServer(String ntpHost) {
2777 AlivcLog.d(
"",
"get time from " + ntpHost);
2778 SntpClient client =
new SntpClient();
2779 boolean isSuccessful = client.requestTime(ntpHost, NTP_TIME_OUT_MILLISECOND);
2781 return client.getNtpTime();
2787 public void addWaterMark(String path,
float x,
float y,
float width) {
2788 if (mNativeAlivcLivePusher == null || mAlivcLivePushConfig == null) {
2789 AlivcLog.e(TAG,
"Illegal State, you should init first");
2792 int[] widthHeight = getImageWidthHeight(path);
2793 if (mWatermarkCount >= AlivcLiveMaxWatermarkCount || widthHeight == null || widthHeight[0] == 0 || widthHeight[1] == 0) {
2798 float h = width * widthHeight[1] / widthHeight[0];
2799 if (mAlivcLivePushConfig.
getPreviewOrientation() == AlivcPreviewOrientationEnum.ORIENTATION_LANDSCAPE_HOME_LEFT.getOrientation() ||
2800 mAlivcLivePushConfig.
getPreviewOrientation() == AlivcPreviewOrientationEnum.ORIENTATION_LANDSCAPE_HOME_RIGHT.getOrientation()) {
2806 mNativeAlivcLivePusher.addWaterMark(path, w, h, x + w / 2, y + h / 2);
2811 public void setWatermarkVisible(
boolean visible) {
2812 if (mNativeAlivcLivePusher == null) {
2813 AlivcLog.e(TAG,
"Illegal State, you should init first");
2816 if (mPushStatus != AlivcLivePushStats.
PREVIEWED) {
2817 AlivcLog.e(TAG,
"status error current state is " + AlivcLivePushStats.values()[mPushStatus.ordinal()]);
2820 if (mWatermarkCount <= 0) {
2823 mNativeAlivcLivePusher.setWaterMarkVisible(visible);
2827 public int startCamera(SurfaceView surfaceView)
throws IllegalStateException {
2828 if (mNativeAlivcLivePusher == null || mAlivcLivePushConfig == null) {
2829 AlivcLog.e(TAG,
"Please execute init first ");
2833 AlivcLog.e(TAG,
"Not in ScreenCapture Mode");
2836 if (!ScreenRecordStatus.SCREEN_RECORD_NORMAL.equals(mScreenStatus)) {
2837 AlivcLog.e(TAG,
"you should start push screen first");
2840 Surface surface = null;
2841 if (surfaceView != null) {
2842 surface = surfaceView.getHolder().getSurface();
2844 int ret = mNativeAlivcLivePusher.startCamera(surface);
2845 mScreenStatus = ScreenRecordStatus.SCREEN_RECORD_CAMERA_START;
2850 public void setScreenOrientation(
int orientation) {
2851 if (mNativeAlivcLivePusher == null || mAlivcLivePushConfig == null) {
2852 AlivcLog.e(TAG,
"Please execute init first ");
2856 AlivcLog.e(TAG,
"Not in ScreenCapture Mode");
2859 mNativeAlivcLivePusher.setScreenOrientation(orientation);
2863 public void stopCamera() {
2864 if (mNativeAlivcLivePusher == null || mAlivcLivePushConfig == null) {
2865 AlivcLog.e(TAG,
"Please execute init first ");
2869 AlivcLog.e(TAG,
"Not in ScreenCapture Mode");
2872 mNativeAlivcLivePusher.stopCamera();
2873 mScreenStatus = ScreenRecordStatus.SCREEN_RECORD_NORMAL;
2877 public int startCameraMix(
float x,
float y,
float w,
float h) {
2878 if (mNativeAlivcLivePusher == null || mAlivcLivePushConfig == null) {
2879 AlivcLog.e(TAG,
"Please execute init first ");
2883 AlivcLog.e(TAG,
"Not in ScreenCapture Mode");
2886 if (!mScreenStatus.equals(ScreenRecordStatus.SCREEN_RECORD_CAMERA_START)) {
2887 AlivcLog.e(TAG,
"You should start camera first");
2890 int ret = mNativeAlivcLivePusher.startCameraMix(x, y, w, h);
2891 mScreenStatus = ScreenRecordStatus.SCREEN_RECORD_CAMERA_MIX_START;
2896 public void stopCameraMix() {
2897 if (mNativeAlivcLivePusher == null || mAlivcLivePushConfig == null) {
2898 AlivcLog.e(TAG,
"Please execute init first ");
2902 AlivcLog.e(TAG,
"Not in ScreenCapture Mode");
2905 mNativeAlivcLivePusher.stopCameraMix();
2906 mScreenStatus = ScreenRecordStatus.SCREEN_RECORD_CAMERA_START;
2910 public void changeResolution(AlivcResolutionEnum resolutionEnum) {
2911 if (mNativeAlivcLivePusher == null) {
2912 AlivcLog.e(TAG,
"Please execute init first!");
2915 if (mPushStatus != AlivcLivePushStats.
PUSHED && mPushStatus != AlivcLivePushStats.
PREVIEWED && mPushStatus != AlivcLivePushStats.
INIT) {
2916 AlivcLog.e(TAG,
"changeResolution can only be called in inited or previewed status");
2919 mNativeAlivcLivePusher.changeResolution(AlivcResolutionEnum.GetResolutionWidth(resolutionEnum), AlivcResolutionEnum.GetResolutionHeight(resolutionEnum));
2922 public int mixStreamRequireMain(
int vid,
boolean require) {
2923 if (mNativeAlivcLivePusher == null) {
2926 return mNativeAlivcLivePusher.mixStreamRequireMain(vid, require);
2929 public int mixStreamChangePosition(
int vid,
float x,
float y,
float w,
float h) {
2930 if (mNativeAlivcLivePusher == null) {
2933 return mNativeAlivcLivePusher.mixStreamChangePosition(vid, x, y, w, h);
2936 public void mixStreamMirror(
int vid,
boolean mirror) {
2937 if (mNativeAlivcLivePusher == null) {
2940 mNativeAlivcLivePusher.setMixStreamMirror(vid, mirror);
2943 public int addMixVideo(AlivcImageFormat format,
int width,
int height,
int rotation,
float displayX,
float displayY,
float displayW,
float displayH,
boolean adjustHeight) {
2944 if (mNativeAlivcLivePusher == null) {
2947 return mNativeAlivcLivePusher.addMixVideo(format.getAlivcImageFormat(), width, height, rotation, displayX, displayY, displayW, displayH, adjustHeight);
2950 public void removeMixVideo(
int handler) {
2951 if (mNativeAlivcLivePusher == null) {
2954 mNativeAlivcLivePusher.removeMixVideo(handler);
2957 public void inputMixTexture(
int handler,
int texture,
int width,
int height,
long pts,
int rotation) {
2958 if (mNativeAlivcLivePusher == null) {
2961 mNativeAlivcLivePusher.inputMixTexture(handler, texture, width, height, pts, rotation);
2964 public void inputMixVideoPtr(
int handler,
long dataptr,
int width,
int height,
int stride,
int size,
long pts,
int rotation) {
2965 if (mNativeAlivcLivePusher == null) {
2968 mNativeAlivcLivePusher.inputMixVideoPtr(handler, dataptr, width, height, stride, size, pts, rotation);
2971 public void inputMixVideoData(
int handler, byte[] data,
int width,
int height,
int stride,
int size,
long pts,
int rotation) {
2972 if (mNativeAlivcLivePusher == null) {
2975 mNativeAlivcLivePusher.inputMixVideoData(handler, data, width, height, stride, size, pts, rotation);
2978 public int addMixAudio(
int channels, AlivcSoundFormat format,
int audioSample) {
2979 if (mNativeAlivcLivePusher == null) {
2982 return mNativeAlivcLivePusher.addMixAudio(channels, format.getAlivcSoundFormat(), audioSample);
2985 public void removeMixAudio(
int handler) {
2986 if (mNativeAlivcLivePusher == null) {
2989 mNativeAlivcLivePusher.removeMixAudio(handler);
2992 public boolean inputMixAudioPtr(
int handler,
long dataptr,
int size,
long pts) {
2993 if (mNativeAlivcLivePusher == null) {
2996 return mNativeAlivcLivePusher.inputMixAudioPtr(handler, dataptr, size, pts);
2999 public boolean inputMixAudioData(
int handler, byte[] data,
int size,
long pts) {
3000 if (mNativeAlivcLivePusher == null) {
3003 return mNativeAlivcLivePusher.inputMixAudioData(handler, data, size, pts);
3007 public void inputStreamVideoPtr(
long dataptr,
int width,
int height,
int stride,
int size,
long pts,
int rotation) {
3008 if (mNativeAlivcLivePusher == null) {
3011 mNativeAlivcLivePusher.inputStreamVideoPtr(dataptr, width, height, stride, size, pts, rotation);
3014 public void inputStreamTexture(
int textureId,
int width,
int height,
int stride,
long pts,
int rotation,
long extra) {
3015 if (mNativeAlivcLivePusher == null) {
3018 mNativeAlivcLivePusher.inputStreamTexture(textureId, width, height, stride, pts, rotation, extra);
3022 public void inputStreamVideoData(byte[] data,
int width,
int height,
int stride,
int size,
long pts,
int rotation) {
3023 if (mNativeAlivcLivePusher == null) {
3026 mNativeAlivcLivePusher.inputStreamVideoData(data, width, height, stride, size, pts, rotation);
3030 public void inputStreamAudioPtr(
long dataPtr,
int size,
int sampleRate,
int channels,
long pts) {
3031 if (mNativeAlivcLivePusher == null) {
3034 mNativeAlivcLivePusher.inputStreamAudioPtr(dataPtr, size, sampleRate, channels, pts);
3038 public void inputStreamAudioData(byte[] data,
int size,
int sampleRate,
int channels,
long pts) {
3039 if (mNativeAlivcLivePusher == null) {
3042 mNativeAlivcLivePusher.inputStreamAudioData(data, size, sampleRate, channels, pts);
3046 public int addDynamicsAddons(String path,
float x,
float y,
float w,
float h)
throws IllegalArgumentException {
3047 if (mNativeAlivcLivePusher == null) {
3050 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) {
3051 AlivcLog.e(TAG,
"addDynamicsAddons failed! x, y, w, h should in range [0~1.0f]");
3054 if (mDynamicAddsonCount >= MAX_DYNAMIC_ADDSON_COUNT) {
3057 mDynamicAddsonCount++;
3058 return mNativeAlivcLivePusher.addDynamicsAddons(path, System.currentTimeMillis() * 1000, 0, x, y, w, h, 0,
false);
3062 public void removeDynamicsAddons(
int id) {
3063 if (mNativeAlivcLivePusher == null) {
3066 mDynamicAddsonCount--;
3067 mNativeAlivcLivePusher.removeDynamicsAddons(
id);
3070 public void setMainStreamPosition(
float startX,
float startY,
float w,
float h) {
3071 if (mNativeAlivcLivePusher == null) {
3074 mNativeAlivcLivePusher.setMainStreamPosition(startX, startY, w, h);
3077 private String getFormatString(String
string) {
3079 int index =
string.indexOf(AUTH_KEY);
3081 String temp =
string.substring(index);
3082 if (temp.indexOf(
"-") > 0) {
3083 result = temp.substring(AUTH_KEY.length(), temp.indexOf(
"-"));
3085 result = temp.substring(AUTH_KEY.length());
3091 private int getTimestamp(String
string) {
3093 String tempStamp = getFormatString(
string);
3094 if (tempStamp.length() < 10) {
3097 if (TextUtils.isDigitsOnly(tempStamp)) {
3098 return new Long(Long.valueOf(tempStamp)).intValue();
3104 private AlivcSnapshotListener mInnerSnapshotListener =
new AlivcSnapshotListener() {
3106 public void onSnapshot(
final Bitmap bmp) {
3107 if (mSnapshotListener != null) {
3108 mThreadPoolExecutor.execute(
new Runnable() {
AlivcResolutionEnum getResolution()
Live push snapshot async callback.
void onNetworkPoor(AlivcLivePusher pusher)
AlivcLivePushLogLevelWarn
void onReconnectStart(AlivcLivePusher pusher)
int getPreviewOrientation()
void onFirstFramePreviewed(AlivcLivePusher pusher)
String getPausePushImage()
boolean isPreviewMirror()
void onPushPaused(AlivcLivePusher pusher)
Live push surface status.
String getNetworkPoorPushImage()
void onNetworkRecovery(AlivcLivePusher pusher)
void onConnectFail(AlivcLivePusher pusher)
boolean isExternMainStream()
void onPushStarted(AlivcLivePusher pusher)
void onConnectionLost(AlivcLivePusher pusher)
void onReconnectFail(AlivcLivePusher pusher)
void setFlash(boolean flash)
void onPreviewStarted(AlivcLivePusher pusher)
void onPushRestarted(AlivcLivePusher pusher)
void onDropFrame(AlivcLivePusher pusher, int beforeCount, int afterCount)
String onPushURLAuthenticationOverdue(AlivcLivePusher pusher)
Live push network listener.
int getTargetVideoBitrate()
Live push error listener.
void setCameraType(AlivcLivePushCameraTypeEnum cameraType)
Enumeration of streaming encode mode.
void onReconnectSucceed(AlivcLivePusher pusher)
void onPushStopped(AlivcLivePusher pusher)
void onFirstFramePushed(AlivcLivePusher pusher)
int getConnectRetryCount()
Customizing the filter interface.
void onSDKError(AlivcLivePusher livePusher, AlivcLivePushError error)
void onAdjustFps(AlivcLivePusher pusher, int currentFps, int targetFps)
void onSnapshot(Bitmap bitmap)
int getConnectRetryInterval()
void onSystemError(AlivcLivePusher livePusher, AlivcLivePushError error)
Intent getMediaProjectionPermissionResultData()
void onPushStatistics(AlivcLivePusher pusher, AlivcLivePushStatsInfo statistics)
int getInitialVideoBitrate()
void onSendDataTimeout(AlivcLivePusher pusher)
Live push video resolution.
Customizing the audio filter interface.
void onAdjustBitrate(AlivcLivePusher pusher, int currentBitrate, int targetBitrate)
User defined video custom detect callback.
Enumeration of streaming video camera type.
void onPreviewStopped(AlivcLivePusher pusher)
void onPushResumed(AlivcLivePusher pusher)
void onSendMessage(AlivcLivePusher pusher)
AlivcAudioSampleRateEnum getAudioSampleRate()
void onProgress(long progress, long duration)
void onPacketsLost(AlivcLivePusher pusher)
AlivcEncodeModeEnum getVideoEncodeMode()