AliVCSDK  6.3.0
阿里云音视频SDK,为视频开发者提供一站式接入服务
AlivcLivePusher.java
1 package com.alivc.live.pusher;
2 
3 import android.content.Context;
4 import android.view.SurfaceView;
5 import android.widget.FrameLayout;
6 
11 import com.alivc.live.utils.AlivcLiveURLTools;
12 import com.alivc.live.utils.ReflectUtil;
13 
32 @CalledByNative
33 public class AlivcLivePusher implements ILivePusher {
34  private ILivePusher mImpl = null;
35 
36  private static final String BASIC_PUSHER_IMPL_CLASS = "com.alivc.live.pusher.AlivcLivePusherBasicImpl";
37  private static final String INTERACTIVE_PUSHER_IMPL_CLASS = "com.alivc.live.pusher.rtc.AlivcRTCLivePusherImpl";
38 
47  @Override
48  public void init(Context context, AlivcLivePushConfig config) throws IllegalArgumentException, IllegalStateException {
50 
51  if (config == null) {
52  throw new IllegalArgumentException("Invalid parameter, config is null.");
53  }
54 
55  reflectInitPusher(config.getLivePushMode());
57 
58  if (mImpl == null) {
59  return;
60  }
61  mImpl.init(context, config);
62  }
63 
64  private void reflectInitPusher(AlivcLiveMode mode) {
65  Object playerInstance = null;
66 
68  playerInstance = ReflectUtil.reflectInit(INTERACTIVE_PUSHER_IMPL_CLASS, null, null);
69  } else {
70  playerInstance = ReflectUtil.reflectInit(BASIC_PUSHER_IMPL_CLASS, null, null);
71  }
72 
73  if (playerInstance == null) {
74  throw new RuntimeException("init live pusher error! now not support mode: " + mode);
75  }
76 
77  mImpl = (ILivePusher) playerInstance;
78  }
79 
85  @Override
86  public void destroy() throws IllegalStateException {
87  if (mImpl == null) {
88  return;
89  }
90  mImpl.destroy();
91  }
92 
98  @Override
99  public void setLivePusherReference(AlivcLivePusher livePusher) {
100  if (mImpl == null) {
101  return;
102  }
103  mImpl.setLivePusherReference(livePusher);
104  }
105 
114  @Override
115  public void startPreview(SurfaceView surfaceView) throws IllegalArgumentException, IllegalStateException {
116  if (mImpl == null) {
117  return;
118  }
119  mImpl.startPreview(surfaceView);
120  }
121 
130  @Override
131  public void startPreviewAsync(SurfaceView surfaceView) throws IllegalArgumentException, IllegalStateException {
132  if (mImpl == null) {
133  return;
134  }
135  mImpl.startPreviewAsync(surfaceView);
136  }
137 
148  @Override
149  public void startPreview(Context context, FrameLayout frameLayout, boolean isAnchor) throws IllegalArgumentException, IllegalStateException {
150  if (mImpl == null) {
151  return;
152  }
153  mImpl.startPreview(context, frameLayout, isAnchor);
154  }
155 
161  @Override
162  public void stopPreview() throws IllegalStateException {
163  if (mImpl == null) {
164  return;
165  }
166  mImpl.stopPreview();
167  }
168 
176  @Override
177  public void startPush(String url) throws IllegalArgumentException, IllegalStateException {
178  if (mImpl == null) {
179  return;
180  }
181  mImpl.startPush(AlivcLiveURLTools.trimUrl(url));
182  }
183 
191  @Override
192  public void startPushAsync(String url) throws IllegalArgumentException, IllegalStateException {
193  if (mImpl == null) {
194  return;
195  }
196  mImpl.startPushAsync(AlivcLiveURLTools.trimUrl(url));
197  }
198 
204  @Override
205  public void restartPush() throws IllegalStateException {
206  if (mImpl == null) {
207  return;
208  }
209  mImpl.restartPush();
210  }
211 
217  @Override
218  public void restartPushAsync() throws IllegalStateException {
219  if (mImpl == null) {
220  return;
221  }
222  mImpl.restartPushAsync();
223  }
224 
231  @Override
232  public void reconnectPushAsync(String url) throws IllegalStateException {
233  if (mImpl == null) {
234  return;
235  }
236  mImpl.reconnectPushAsync(AlivcLiveURLTools.trimUrl(url));
237  }
238 
244  @Override
245  public void stopPush() throws IllegalStateException {
246  if (mImpl == null) {
247  return;
248  }
249  mImpl.stopPush();
250  }
251 
257  @Override
258  public void pause() throws IllegalStateException {
259  if (mImpl == null) {
260  return;
261  }
262  mImpl.pause();
263  }
264 
270  @Override
271  public void resume() throws IllegalStateException {
272  if (mImpl == null) {
273  return;
274  }
275  mImpl.resume();
276  }
277 
283  @Override
284  public void resumeAsync() throws IllegalStateException {
285  if (mImpl == null) {
286  return;
287  }
288  mImpl.resumeAsync();
289  }
290 
296  @Override
297  public void switchCamera() throws IllegalStateException {
298  if (mImpl == null) {
299  return;
300  }
301  mImpl.switchCamera();
302  }
303 
310  @Override
311  public void setAutoFocus(boolean autoFocus) throws IllegalStateException {
312  if (mImpl == null) {
313  return;
314  }
315  mImpl.setAutoFocus(autoFocus);
316  }
317 
326  @Override
327  public void focusCameraAtAdjustedPoint(float x, float y, boolean autoFocus) throws IllegalArgumentException, IllegalStateException {
328  if (mImpl == null) {
329  return;
330  }
331  mImpl.focusCameraAtAdjustedPoint(x, y, autoFocus);
332  }
333 
340  @Override
341  public void setZoom(int zoom) throws IllegalArgumentException, IllegalStateException {
342  if (mImpl == null) {
343  return;
344  }
345  mImpl.setZoom(zoom);
346  }
347 
354  @Override
355  public int getMaxZoom() throws IllegalStateException {
356  if (mImpl == null) {
357  return -1;
358  }
359  return mImpl.getMaxZoom();
360  }
361 
368  @Override
369  public int getCurrentZoom() throws IllegalStateException {
370  if (mImpl == null) {
371  return -1;
372  }
373  return mImpl.getCurrentZoom();
374  }
375 
382  @Override
383  public void setMute(boolean mute) throws IllegalStateException {
384  if (mImpl == null) {
385  return;
386  }
387  mImpl.setMute(mute);
388  }
389 
396  @Override
397  public void setFlash(boolean flash) throws IllegalStateException {
398  if (mImpl == null) {
399  return;
400  }
401  mImpl.setFlash(flash);
402  }
403 
410  @Override
411  public void setPushMirror(boolean mirror) throws IllegalStateException {
412  if (mImpl == null) {
413  return;
414  }
415  mImpl.setPushMirror(mirror);
416  }
417 
424  @Override
425  public void setPreviewMirror(boolean mirror) throws IllegalStateException {
426  if (mImpl == null) {
427  return;
428  }
429  mImpl.setPreviewMirror(mirror);
430  }
431 
438  @Override
439  public void setTargetVideoBitrate(int targetVideoBitrate) throws IllegalArgumentException, IllegalStateException {
440  if (mImpl == null) {
441  return;
442  }
443  mImpl.setTargetVideoBitrate(targetVideoBitrate);
444  }
445 
452  @Override
453  public void setMinVideoBitrate(int minVideoBitrate) throws IllegalArgumentException, IllegalStateException {
454  if (mImpl == null) {
455  return;
456  }
457  mImpl.setMinVideoBitrate(minVideoBitrate);
458  }
459 
468  @Override
469  public void refreshPushURLToken(String url) {
470  if (mImpl == null) {
471  return;
472  }
473  mImpl.refreshPushURLToken(url);
474  }
475 
481  @Override
482  public boolean isCameraSupportAutoFocus() {
483  if (mImpl == null) {
484  return false;
485  }
486  return mImpl.isCameraSupportAutoFocus();
487  }
488 
494  @Override
495  public boolean isCameraSupportFlash() {
496  if (mImpl == null) {
497  return false;
498  }
499  return mImpl.isCameraSupportFlash();
500  }
501 
508  @Override
509  public boolean isPushing() throws IllegalStateException {
510  if (mImpl == null) {
511  return false;
512  }
513  return mImpl.isPushing();
514  }
515 
522  @Override
523  public boolean isNetworkPushing() throws IllegalStateException {
524  if (mImpl == null) {
525  return false;
526  }
527  return mImpl.isNetworkPushing();
528  }
529 
535  @Override
536  public void setCustomDetect(AlivcLivePushCustomDetect customVideoDetect) {
537  if (mImpl == null) {
538  return;
539  }
540  mImpl.setCustomDetect(customVideoDetect);
541  }
542 
548  @Override
549  public void setCustomFilter(AlivcLivePushCustomFilter customVideoFilter) {
550  if (mImpl == null) {
551  return;
552  }
553  mImpl.setCustomFilter(customVideoFilter);
554  }
555 
561  @Override
562  public void setCustomAudioFilter(AlivcLivePushCustomAudioFilter customAudioFilter) {
563  if (mImpl == null) {
564  return;
565  }
566  mImpl.setCustomAudioFilter(customAudioFilter);
567  }
568 
574  @Override
576  if (mImpl == null) {
577  return AlivcLivePushStats.IDLE;
578  }
579  return mImpl.getCurrentStatus();
580  }
581 
587  @Override
589  if (mImpl == null) {
590  return;
591  }
592  mImpl.setLivePushErrorListener(errorListener);
593  }
594 
600  @Override
602  if (mImpl == null) {
603  return;
604  }
605  mImpl.setLivePushInfoListener(infoListener);
606  }
607 
613  @Override
615  if (mImpl == null) {
616  return;
617  }
618  mImpl.setLivePushNetworkListener(networkListener);
619  }
620 
626  @Override
627  public void setLivePushBGMListener(AlivcLivePushBGMListener pushBGMListener) {
628  if (mImpl == null) {
629  return;
630  }
631  mImpl.setLivePushBGMListener(pushBGMListener);
632  }
633 
639  @Override
640  public void setLivePushRenderContextListener(AlivcLivePusherRenderContextListener renderCtxListener) {
641  if (mImpl == null) {
642  return;
643  }
644  mImpl.setLivePushRenderContextListener(renderCtxListener);
645  }
646 
653  @Override
654  public AlivcLivePushStatsInfo getLivePushStatsInfo() throws IllegalStateException {
655  if (mImpl == null) {
656  return null;
657  }
658  return mImpl.getLivePushStatsInfo();
659  }
660 
666  @Override
667  public String getPushUrl() {
668  if (mImpl == null) {
669  return "";
670  }
671  return mImpl.getPushUrl();
672  }
673 
679  @Override
681  if (mImpl == null) {
682  return;
683  }
684  mImpl.setPreviewOrientation(orientation);
685  }
686 
695  @Override
697  if (mImpl == null) {
698  return -1;
699  }
700  return mImpl.setAudioEffectVoiceChangeMode(mode);
701  }
702 
711  @Override
713  if (mImpl == null) {
714  return -1;
715  }
716  return mImpl.setAudioEffectReverbMode(mode);
717  }
718 
725  @Override
726  public void startBGMAsync(String path) throws IllegalStateException {
727  if (mImpl == null) {
728  return;
729  }
730  mImpl.startBGMAsync(path);
731  }
732 
738  @Override
739  public void stopBGMAsync() throws IllegalStateException {
740  if (mImpl == null) {
741  return;
742  }
743  mImpl.stopBGMAsync();
744  }
745 
751  @Override
752  public void pauseBGM() throws IllegalStateException {
753  if (mImpl == null) {
754  return;
755  }
756  mImpl.pauseBGM();
757  }
758 
764  @Override
765  public void resumeBGM() throws IllegalStateException {
766  if (mImpl == null) {
767  return;
768  }
769  mImpl.resumeBGM();
770  }
771 
778  @Override
779  public void setBGMLoop(boolean isLoop) throws IllegalStateException {
780  if (mImpl == null) {
781  return;
782  }
783  mImpl.setBGMLoop(isLoop);
784  }
785 
792  @Override
793  public void setBGMEarsBack(boolean isOpen) throws IllegalStateException {
794  if (mImpl == null) {
795  return;
796  }
797  mImpl.setBGMEarsBack(isOpen);
798  }
799 
807  @Override
808  public void setBGMVolume(int volume) throws IllegalStateException, IllegalArgumentException {
809  if (mImpl == null) {
810  return;
811  }
812  mImpl.setBGMVolume(volume);
813  }
814 
822  @Override
823  public void setCaptureVolume(int volume) throws IllegalStateException, IllegalArgumentException {
824  if (mImpl == null) {
825  return;
826  }
827  mImpl.setCaptureVolume(volume);
828  }
829 
835  @Override
836  public void setAudioDenoise(boolean on) {
837  if (mImpl == null) {
838  return;
839  }
840  mImpl.setAudioDenoise(on);
841  }
842 
858  @Override
859  public int startIntelligentDenoise() {
860  if (mImpl == null) {
861  return -1;
862  }
863  return mImpl.startIntelligentDenoise();
864  }
865 
872  @Override
873  public int stopIntelligentDenoise() {
874  if (mImpl == null) {
875  return -1;
876  }
877  return mImpl.stopIntelligentDenoise();
878  }
879 
886  @Override
887  public void setQualityMode(AlivcQualityModeEnum mode) throws IllegalStateException {
888  if (mImpl == null) {
889  return;
890  }
891  mImpl.setQualityMode(mode);
892  }
893 
900  @Override
901  public void setPreviewMode(AlivcPreviewDisplayMode mode) throws IllegalStateException {
902  if (mImpl == null) {
903  return;
904  }
905  mImpl.setPreviewMode(mode);
906  }
907 
913  @Override
914  public void pauseScreenCapture() throws IllegalStateException {
915  if (mImpl == null) {
916  return;
917  }
918  mImpl.pauseScreenCapture();
919  }
920 
926  @Override
927  public void resumeScreenCapture() throws IllegalStateException {
928  if (mImpl == null) {
929  return;
930  }
931  mImpl.resumeScreenCapture();
932  }
933 
939  @Override
941  if (mImpl == null) {
942  return AlivcLivePushError.ALIVC_COMMON_RETURN_SUCCESS;
943  }
944  return mImpl.getLastError();
945  }
946 
952  @Override
953  public void changeResolution(AlivcResolutionEnum resolution) {
954  if (mImpl == null) {
955  return;
956  }
957  mImpl.changeResolution(resolution);
958  }
959 
969  @Override
970  public void addWaterMark(String path, float x, float y, float width) {
971  if (mImpl == null) {
972  return;
973  }
974  mImpl.addWaterMark(path, x, y, width);
975  }
976 
982  @Override
983  public void setWatermarkVisible(boolean visible) {
984  if (mImpl == null) {
985  return;
986  }
987  mImpl.setWatermarkVisible(visible);
988  }
989 
997  @Override
998  public int startCamera(SurfaceView surfaceView) throws IllegalStateException {
999  if (mImpl == null) {
1000  return -1;
1001  }
1002  return mImpl.startCamera(surfaceView);
1003  }
1004 
1008  @Override
1009  public void stopCamera() {
1010  if (mImpl == null) {
1011  return;
1012  }
1013  mImpl.stopCamera();
1014  }
1015 
1021  @Override
1022  public void setScreenOrientation(int orientation) {
1023  if (mImpl == null) {
1024  return;
1025  }
1026  mImpl.setScreenOrientation(orientation);
1027  }
1028 
1038  @Override
1039  public int startCameraMix(float x, float y, float w, float h) {
1040  if (mImpl == null) {
1041  return -1;
1042  }
1043  return mImpl.startCameraMix(x, y, w, h);
1044  }
1045 
1049  @Override
1050  public void stopCameraMix() {
1051  if (mImpl == null) {
1052  return;
1053  }
1054  mImpl.stopCameraMix();
1055  }
1056 
1064  @Override
1065  public void snapshot(int count, int interval, AlivcSnapshotListener listener) {
1066  if (mImpl == null) {
1067  return;
1068  }
1069  mImpl.snapshot(count, interval, listener);
1070  }
1071 
1084  @Override
1085  public void inputStreamVideoPtr(long dataPtr, int width, int height, int stride, int size, long pts, int rotation) {
1086  if (mImpl == null) {
1087  return;
1088  }
1089  mImpl.inputStreamVideoPtr(dataPtr, width, height, stride, size, pts, rotation);
1090  }
1091 
1105  @Override
1106  public void inputStreamVideoData(byte[] data, int width, int height, int stride, int size, long pts, int rotation) {
1107  if (mImpl == null) {
1108  return;
1109  }
1110  mImpl.inputStreamVideoData(data, width, height, stride, size, pts, rotation);
1111  }
1112 
1124  @Override
1125  public void inputStreamAudioPtr(long dataPtr, int size, int sampleRate, int channels, long pts) {
1126  if (mImpl == null) {
1127  return;
1128  }
1129  mImpl.inputStreamAudioPtr(dataPtr, size, sampleRate, channels, pts);
1130  }
1131 
1143  @Override
1144  public void inputStreamAudioData(byte[] data, int size, int sampleRate, int channels, long pts) {
1145  if (mImpl == null) {
1146  return;
1147  }
1148  mImpl.inputStreamAudioData(data, size, sampleRate, channels, pts);
1149  }
1150 
1161  @Override
1162  public int addDynamicsAddons(String path, float x, float y, float w, float h) {
1163  if (mImpl == null) {
1164  return -1;
1165  }
1166  return mImpl.addDynamicsAddons(path, x, y, w, h);
1167  }
1168 
1174  @Override
1175  public void removeDynamicsAddons(int id) {
1176  if (mImpl == null) {
1177  return;
1178  }
1179  mImpl.removeDynamicsAddons(id);
1180  }
1181 
1187  @Override
1188  public void setExposure(int exposure) {
1189  if (mImpl == null) {
1190  return;
1191  }
1192  mImpl.setExposure(exposure);
1193  }
1194 
1200  @Override
1201  public int getCurrentExposure() {
1202  if (mImpl == null) {
1203  return -1;
1204  }
1205  return mImpl.getCurrentExposure();
1206  }
1207 
1213  @Override
1215  if (mImpl == null) {
1216  return -1;
1217  }
1218  return mImpl.getSupportedMinExposure();
1219  }
1220 
1226  @Override
1228  if (mImpl == null) {
1229  return -1;
1230  }
1231  return mImpl.getSupportedMaxExposure();
1232  }
1233 
1242  @Override
1243  public void sendMessage(String info, int repeat, int delay, boolean isKeyFrame) {
1244  if (mImpl == null) {
1245  return;
1246  }
1247  mImpl.sendMessage(info, repeat, delay, isKeyFrame);
1248  }
1249 
1264  @Override
1266  if (mImpl == null) {
1267  return -1;
1268  }
1269  return mImpl.setLiveMixTranscodingConfig(config);
1270  }
1271 
1282  @Override
1283  public int muteLocalCamera(boolean mute) {
1284  if (mImpl == null) {
1285  return -1;
1286  }
1287  return mImpl.muteLocalCamera(mute);
1288  }
1289 
1297  @Override
1298  public int enableSpeakerphone(boolean enable) {
1299  if (mImpl == null) {
1300  return -1;
1301  }
1302  return mImpl.enableSpeakerphone(enable);
1303  }
1304 
1311  @Override
1312  public boolean isSpeakerphoneOn() {
1313  if (mImpl == null) {
1314  return false;
1315  }
1316  return mImpl.isSpeakerphoneOn();
1317  }
1318 
1328  @Override
1329  public int enableAudioVolumeIndication(int interval, int smooth, int reportVad) {
1330  if (mImpl == null) {
1331  return -1;
1332  }
1333  return mImpl.enableAudioVolumeIndication(interval, smooth, reportVad);
1334  }
1335 
1342  @Override
1343  public String getLiveTraceId() {
1344  if (mImpl == null) {
1345  return "";
1346  }
1347  return mImpl.getLiveTraceId();
1348  }
1349 }
1350  // end of live_pusher
推流截图结果异步回调通知
void startPreviewAsync(SurfaceView surfaceView)
int setAudioEffectReverbMode(AlivcLivePushAudioEffectReverbMode mode)
void inputStreamVideoData(byte[] data, int width, int height, int stride, int size, long pts, int rotation)
void snapshot(int count, int interval, AlivcSnapshotListener listener)
void startPreview(SurfaceView surfaceView)
void changeResolution(AlivcResolutionEnum resolution)
void setLivePushNetworkListener(AlivcLivePushNetworkListener networkListener)
int enableAudioVolumeIndication(int interval, int smooth, int reportVad)
void init(Context context, AlivcLivePushConfig config)
void sendMessage(String info, int repeat, int delay, boolean isKeyFrame)
void startPreview(Context context, FrameLayout frameLayout, boolean isAnchor)
void setMinVideoBitrate(int minVideoBitrate)
void setLivePushBGMListener(AlivcLivePushBGMListener pushBGMListener)
void setCustomDetect(AlivcLivePushCustomDetect customVideoDetect)
void setPreviewOrientation(AlivcPreviewOrientationEnum orientation)
void inputStreamAudioPtr(long dataPtr, int size, int sampleRate, int channels, long pts)
void inputStreamAudioData(byte[] data, int size, int sampleRate, int channels, long pts)
int addDynamicsAddons(String path, float x, float y, float w, float h)
void setCustomAudioFilter(AlivcLivePushCustomAudioFilter customAudioFilter)
void focusCameraAtAdjustedPoint(float x, float y, boolean autoFocus)
int startCamera(SurfaceView surfaceView)
int startCameraMix(float x, float y, float w, float h)
void setLivePushErrorListener(AlivcLivePushErrorListener errorListener)
int setAudioEffectVoiceChangeMode(AlivcLivePushAudioEffectVoiceChangeMode mode)
void setLivePushInfoListener(AlivcLivePushInfoListener infoListener)
定制filter接口(视频纹理前处理回调)
void setTargetVideoBitrate(int targetVideoBitrate)
int setLiveMixTranscodingConfig(AlivcLiveTranscodingConfig config)
void setLivePushRenderContextListener(AlivcLivePusherRenderContextListener renderCtxListener)
AlivcLivePushStatsInfo getLivePushStatsInfo()
void setPreviewMode(AlivcPreviewDisplayMode mode)
void setCustomFilter(AlivcLivePushCustomFilter customVideoFilter)
void inputStreamVideoPtr(long dataPtr, int width, int height, int stride, int size, long pts, int rotation)
void addWaterMark(String path, float x, float y, float width)
void setLivePusherReference(AlivcLivePusher livePusher)
void setQualityMode(AlivcQualityModeEnum mode)