AliVCSDK  6.0.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 
31 @CalledByNative
32 public class AlivcLivePusher implements ILivePusher {
33  private ILivePusher mImpl = null;
34 
35  private static final String BASIC_PUSHER_IMPL_CLASS = "com.alivc.live.pusher.AlivcLivePusherBasicImpl";
36  private static final String INTERACTIVE_PUSHER_IMPL_CLASS = "com.alivc.live.pusher.rtc.AlivcRTCLivePusherImpl";
37 
46  @Override
47  public void init(Context context, AlivcLivePushConfig config) throws IllegalArgumentException, IllegalStateException {
49 
50  if (config == null) {
51  throw new IllegalArgumentException("Invalid parameter, config is null.");
52  }
53 
54  reflectInitPusher(config.getLivePushMode());
56 
57  if (mImpl == null) {
58  return;
59  }
60  mImpl.init(context, config);
61  }
62 
63  private void reflectInitPusher(AlivcLiveMode mode) {
64  Object playerInstance = null;
65 
67  playerInstance = ReflectUtil.reflectInit(INTERACTIVE_PUSHER_IMPL_CLASS, null, null);
68  } else {
69  playerInstance = ReflectUtil.reflectInit(BASIC_PUSHER_IMPL_CLASS, null, null);
70  }
71 
72  if (playerInstance == null) {
73  throw new RuntimeException("init live pusher error! now not support mode: " + mode);
74  }
75 
76  mImpl = (ILivePusher) playerInstance;
77  }
78 
84  @Override
85  public void destroy() throws IllegalStateException {
86  if (mImpl == null) {
87  return;
88  }
89  mImpl.destroy();
90  }
91 
97  @Override
98  public void setLivePusherReference(AlivcLivePusher livePusher) {
99  if (mImpl == null) {
100  return;
101  }
102  mImpl.setLivePusherReference(livePusher);
103  }
104 
112  @Override
113  public void startPreview(SurfaceView surfaceView) throws IllegalArgumentException, IllegalStateException {
114  if (mImpl == null) {
115  return;
116  }
117  mImpl.startPreview(surfaceView);
118  }
119 
127  @Override
128  public void startPreviewAsync(SurfaceView surfaceView) throws IllegalArgumentException, IllegalStateException {
129  if (mImpl == null) {
130  return;
131  }
132  mImpl.startPreviewAsync(surfaceView);
133  }
134 
145  @Override
146  public void startPreview(Context context, FrameLayout frameLayout, boolean isAnchor) throws IllegalArgumentException, IllegalStateException {
147  if (mImpl == null) {
148  return;
149  }
150  mImpl.startPreview(context, frameLayout, isAnchor);
151  }
152 
158  @Override
159  public void stopPreview() throws IllegalStateException {
160  if (mImpl == null) {
161  return;
162  }
163  mImpl.stopPreview();
164  }
165 
173  @Override
174  public void startPush(String url) throws IllegalArgumentException, IllegalStateException {
175  if (mImpl == null) {
176  return;
177  }
178  mImpl.startPush(AlivcLiveURLTools.trimUrl(url));
179  }
180 
188  @Override
189  public void startPushAsync(String url) throws IllegalArgumentException, IllegalStateException {
190  if (mImpl == null) {
191  return;
192  }
193  mImpl.startPushAsync(AlivcLiveURLTools.trimUrl(url));
194  }
195 
201  @Override
202  public void restartPush() throws IllegalStateException {
203  if (mImpl == null) {
204  return;
205  }
206  mImpl.restartPush();
207  }
208 
214  @Override
215  public void restartPushAsync() throws IllegalStateException {
216  if (mImpl == null) {
217  return;
218  }
219  mImpl.restartPushAsync();
220  }
221 
228  @Override
229  public void reconnectPushAsync(String url) throws IllegalStateException {
230  if (mImpl == null) {
231  return;
232  }
233  mImpl.reconnectPushAsync(AlivcLiveURLTools.trimUrl(url));
234  }
235 
241  @Override
242  public void stopPush() throws IllegalStateException {
243  if (mImpl == null) {
244  return;
245  }
246  mImpl.stopPush();
247  }
248 
254  @Override
255  public void pause() throws IllegalStateException {
256  if (mImpl == null) {
257  return;
258  }
259  mImpl.pause();
260  }
261 
267  @Override
268  public void resume() throws IllegalStateException {
269  if (mImpl == null) {
270  return;
271  }
272  mImpl.resume();
273  }
274 
280  @Override
281  public void resumeAsync() throws IllegalStateException {
282  if (mImpl == null) {
283  return;
284  }
285  mImpl.resumeAsync();
286  }
287 
293  @Override
294  public void switchCamera() throws IllegalStateException {
295  if (mImpl == null) {
296  return;
297  }
298  mImpl.switchCamera();
299  }
300 
307  @Override
308  public void setAutoFocus(boolean autoFocus) throws IllegalStateException {
309  if (mImpl == null) {
310  return;
311  }
312  mImpl.setAutoFocus(autoFocus);
313  }
314 
323  @Override
324  public void focusCameraAtAdjustedPoint(float x, float y, boolean autoFocus) throws IllegalArgumentException, IllegalStateException {
325  if (mImpl == null) {
326  return;
327  }
328  mImpl.focusCameraAtAdjustedPoint(x, y, autoFocus);
329  }
330 
337  @Override
338  public void setZoom(int zoom) throws IllegalArgumentException, IllegalStateException {
339  if (mImpl == null) {
340  return;
341  }
342  mImpl.setZoom(zoom);
343  }
344 
351  @Override
352  public int getMaxZoom() throws IllegalStateException {
353  if (mImpl == null) {
354  return -1;
355  }
356  return mImpl.getMaxZoom();
357  }
358 
365  @Override
366  public int getCurrentZoom() throws IllegalStateException {
367  if (mImpl == null) {
368  return -1;
369  }
370  return mImpl.getCurrentZoom();
371  }
372 
379  @Override
380  public void setMute(boolean mute) throws IllegalStateException {
381  if (mImpl == null) {
382  return;
383  }
384  mImpl.setMute(mute);
385  }
386 
393  @Override
394  public void setFlash(boolean flash) throws IllegalStateException {
395  if (mImpl == null) {
396  return;
397  }
398  mImpl.setFlash(flash);
399  }
400 
407  @Override
408  public void setPushMirror(boolean mirror) throws IllegalStateException {
409  if (mImpl == null) {
410  return;
411  }
412  mImpl.setPushMirror(mirror);
413  }
414 
421  @Override
422  public void setPreviewMirror(boolean mirror) throws IllegalStateException {
423  if (mImpl == null) {
424  return;
425  }
426  mImpl.setPreviewMirror(mirror);
427  }
428 
435  @Override
436  public void setTargetVideoBitrate(int targetVideoBitrate) throws IllegalArgumentException, IllegalStateException {
437  if (mImpl == null) {
438  return;
439  }
440  mImpl.setTargetVideoBitrate(targetVideoBitrate);
441  }
442 
449  @Override
450  public void setMinVideoBitrate(int minVideoBitrate) throws IllegalArgumentException, IllegalStateException {
451  if (mImpl == null) {
452  return;
453  }
454  mImpl.setMinVideoBitrate(minVideoBitrate);
455  }
456 
462  @Override
463  public boolean isCameraSupportAutoFocus() {
464  if (mImpl == null) {
465  return false;
466  }
467  return mImpl.isCameraSupportAutoFocus();
468  }
469 
475  @Override
476  public boolean isCameraSupportFlash() {
477  if (mImpl == null) {
478  return false;
479  }
480  return mImpl.isCameraSupportFlash();
481  }
482 
489  @Override
490  public boolean isPushing() throws IllegalStateException {
491  if (mImpl == null) {
492  return false;
493  }
494  return mImpl.isPushing();
495  }
496 
503  @Override
504  public boolean isNetworkPushing() throws IllegalStateException {
505  if (mImpl == null) {
506  return false;
507  }
508  return mImpl.isNetworkPushing();
509  }
510 
516  @Override
517  public void setCustomDetect(AlivcLivePushCustomDetect customVideoDetect) {
518  if (mImpl == null) {
519  return;
520  }
521  mImpl.setCustomDetect(customVideoDetect);
522  }
523 
529  @Override
530  public void setCustomFilter(AlivcLivePushCustomFilter customVideoFilter) {
531  if (mImpl == null) {
532  return;
533  }
534  mImpl.setCustomFilter(customVideoFilter);
535  }
536 
542  @Override
543  public void setCustomAudioFilter(AlivcLivePushCustomAudioFilter customAudioFilter) {
544  if (mImpl == null) {
545  return;
546  }
547  mImpl.setCustomAudioFilter(customAudioFilter);
548  }
549 
555  @Override
557  if (mImpl == null) {
558  return AlivcLivePushStats.IDLE;
559  }
560  return mImpl.getCurrentStatus();
561  }
562 
568  @Override
570  if (mImpl == null) {
571  return;
572  }
573  mImpl.setLivePushErrorListener(errorListener);
574  }
575 
581  @Override
583  if (mImpl == null) {
584  return;
585  }
586  mImpl.setLivePushInfoListener(infoListener);
587  }
588 
594  @Override
596  if (mImpl == null) {
597  return;
598  }
599  mImpl.setLivePushNetworkListener(networkListener);
600  }
601 
607  @Override
608  public void setLivePushBGMListener(AlivcLivePushBGMListener pushBGMListener) {
609  if (mImpl == null) {
610  return;
611  }
612  mImpl.setLivePushBGMListener(pushBGMListener);
613  }
614 
620  @Override
621  public void setLivePushRenderContextListener(AlivcLivePusherRenderContextListener renderCtxListener) {
622  if (mImpl == null) {
623  return;
624  }
625  mImpl.setLivePushRenderContextListener(renderCtxListener);
626  }
627 
634  @Override
635  public AlivcLivePushStatsInfo getLivePushStatsInfo() throws IllegalStateException {
636  if (mImpl == null) {
637  return null;
638  }
639  return mImpl.getLivePushStatsInfo();
640  }
641 
647  @Override
648  public String getPushUrl() {
649  if (mImpl == null) {
650  return "";
651  }
652  return mImpl.getPushUrl();
653  }
654 
660  @Override
662  if (mImpl == null) {
663  return;
664  }
665  mImpl.setPreviewOrientation(orientation);
666  }
667 
676  @Override
678  if (mImpl == null) {
679  return -1;
680  }
681  return mImpl.setAudioEffectVoiceChangeMode(mode);
682  }
683 
692  @Override
694  if (mImpl == null) {
695  return -1;
696  }
697  return mImpl.setAudioEffectReverbMode(mode);
698  }
699 
706  @Override
707  public void startBGMAsync(String path) throws IllegalStateException {
708  if (mImpl == null) {
709  return;
710  }
711  mImpl.startBGMAsync(path);
712  }
713 
719  @Override
720  public void stopBGMAsync() throws IllegalStateException {
721  if (mImpl == null) {
722  return;
723  }
724  mImpl.stopBGMAsync();
725  }
726 
732  @Override
733  public void pauseBGM() throws IllegalStateException {
734  if (mImpl == null) {
735  return;
736  }
737  mImpl.pauseBGM();
738  }
739 
745  @Override
746  public void resumeBGM() throws IllegalStateException {
747  if (mImpl == null) {
748  return;
749  }
750  mImpl.resumeBGM();
751  }
752 
759  @Override
760  public void setBGMLoop(boolean isLoop) throws IllegalStateException {
761  if (mImpl == null) {
762  return;
763  }
764  mImpl.setBGMLoop(isLoop);
765  }
766 
773  @Override
774  public void setBGMEarsBack(boolean isOpen) throws IllegalStateException {
775  if (mImpl == null) {
776  return;
777  }
778  mImpl.setBGMEarsBack(isOpen);
779  }
780 
788  @Override
789  public void setBGMVolume(int volume) throws IllegalStateException, IllegalArgumentException {
790  if (mImpl == null) {
791  return;
792  }
793  mImpl.setBGMVolume(volume);
794  }
795 
803  @Override
804  public void setCaptureVolume(int volume) throws IllegalStateException, IllegalArgumentException {
805  if (mImpl == null) {
806  return;
807  }
808  mImpl.setCaptureVolume(volume);
809  }
810 
816  @Override
817  public void setAudioDenoise(boolean on) {
818  if (mImpl == null) {
819  return;
820  }
821  mImpl.setAudioDenoise(on);
822  }
823 
839  @Override
840  public int startIntelligentDenoise() {
841  if (mImpl == null) {
842  return -1;
843  }
844  return mImpl.startIntelligentDenoise();
845  }
846 
853  @Override
854  public int stopIntelligentDenoise() {
855  if (mImpl == null) {
856  return -1;
857  }
858  return mImpl.stopIntelligentDenoise();
859  }
860 
867  @Override
868  public void setQualityMode(AlivcQualityModeEnum mode) throws IllegalStateException {
869  if (mImpl == null) {
870  return;
871  }
872  mImpl.setQualityMode(mode);
873  }
874 
881  @Override
882  public void setPreviewMode(AlivcPreviewDisplayMode mode) throws IllegalStateException {
883  if (mImpl == null) {
884  return;
885  }
886  mImpl.setPreviewMode(mode);
887  }
888 
894  @Override
895  public void pauseScreenCapture() throws IllegalStateException {
896  if (mImpl == null) {
897  return;
898  }
899  mImpl.pauseScreenCapture();
900  }
901 
907  @Override
908  public void resumeScreenCapture() throws IllegalStateException {
909  if (mImpl == null) {
910  return;
911  }
912  mImpl.resumeScreenCapture();
913  }
914 
920  @Override
922  if (mImpl == null) {
923  return AlivcLivePushError.ALIVC_COMMON_RETURN_SUCCESS;
924  }
925  return mImpl.getLastError();
926  }
927 
933  @Override
934  public void changeResolution(AlivcResolutionEnum resolution) {
935  if (mImpl == null) {
936  return;
937  }
938  mImpl.changeResolution(resolution);
939  }
940 
950  @Override
951  public void addWaterMark(String path, float x, float y, float width) {
952  if (mImpl == null) {
953  return;
954  }
955  mImpl.addWaterMark(path, x, y, width);
956  }
957 
963  @Override
964  public void setWatermarkVisible(boolean visible) {
965  if (mImpl == null) {
966  return;
967  }
968  mImpl.setWatermarkVisible(visible);
969  }
970 
978  @Override
979  public int startCamera(SurfaceView surfaceView) throws IllegalStateException {
980  if (mImpl == null) {
981  return -1;
982  }
983  return mImpl.startCamera(surfaceView);
984  }
985 
989  @Override
990  public void stopCamera() {
991  if (mImpl == null) {
992  return;
993  }
994  mImpl.stopCamera();
995  }
996 
1002  @Override
1003  public void setScreenOrientation(int orientation) {
1004  if (mImpl == null) {
1005  return;
1006  }
1007  mImpl.setScreenOrientation(orientation);
1008  }
1009 
1019  @Override
1020  public int startCameraMix(float x, float y, float w, float h) {
1021  if (mImpl == null) {
1022  return -1;
1023  }
1024  return mImpl.startCameraMix(x, y, w, h);
1025  }
1026 
1030  @Override
1031  public void stopCameraMix() {
1032  if (mImpl == null) {
1033  return;
1034  }
1035  mImpl.stopCameraMix();
1036  }
1037 
1045  @Override
1046  public void snapshot(int count, int interval, AlivcSnapshotListener listener) {
1047  if (mImpl == null) {
1048  return;
1049  }
1050  mImpl.snapshot(count, interval, listener);
1051  }
1052 
1065  @Override
1066  public void inputStreamVideoPtr(long dataPtr, int width, int height, int stride, int size, long pts, int rotation) {
1067  if (mImpl == null) {
1068  return;
1069  }
1070  mImpl.inputStreamVideoPtr(dataPtr, width, height, stride, size, pts, rotation);
1071  }
1072 
1086  @Override
1087  public void inputStreamVideoData(byte[] data, int width, int height, int stride, int size, long pts, int rotation) {
1088  if (mImpl == null) {
1089  return;
1090  }
1091  mImpl.inputStreamVideoData(data, width, height, stride, size, pts, rotation);
1092  }
1093 
1105  @Override
1106  public void inputStreamAudioPtr(long dataPtr, int size, int sampleRate, int channels, long pts) {
1107  if (mImpl == null) {
1108  return;
1109  }
1110  mImpl.inputStreamAudioPtr(dataPtr, size, sampleRate, channels, pts);
1111  }
1112 
1124  @Override
1125  public void inputStreamAudioData(byte[] data, int size, int sampleRate, int channels, long pts) {
1126  if (mImpl == null) {
1127  return;
1128  }
1129  mImpl.inputStreamAudioData(data, size, sampleRate, channels, pts);
1130  }
1131 
1142  @Override
1143  public int addDynamicsAddons(String path, float x, float y, float w, float h) {
1144  if (mImpl == null) {
1145  return -1;
1146  }
1147  return mImpl.addDynamicsAddons(path, x, y, w, h);
1148  }
1149 
1155  @Override
1156  public void removeDynamicsAddons(int id) {
1157  if (mImpl == null) {
1158  return;
1159  }
1160  mImpl.removeDynamicsAddons(id);
1161  }
1162 
1168  @Override
1169  public void setExposure(int exposure) {
1170  if (mImpl == null) {
1171  return;
1172  }
1173  mImpl.setExposure(exposure);
1174  }
1175 
1181  @Override
1182  public int getCurrentExposure() {
1183  if (mImpl == null) {
1184  return -1;
1185  }
1186  return mImpl.getCurrentExposure();
1187  }
1188 
1194  @Override
1196  if (mImpl == null) {
1197  return -1;
1198  }
1199  return mImpl.getSupportedMinExposure();
1200  }
1201 
1207  @Override
1209  if (mImpl == null) {
1210  return -1;
1211  }
1212  return mImpl.getSupportedMaxExposure();
1213  }
1214 
1223  @Override
1224  public void sendMessage(String info, int repeat, int delay, boolean isKeyFrame) {
1225  if (mImpl == null) {
1226  return;
1227  }
1228  mImpl.sendMessage(info, repeat, delay, isKeyFrame);
1229  }
1230 
1245  @Override
1247  if (mImpl == null) {
1248  return -1;
1249  }
1250  return mImpl.setLiveMixTranscodingConfig(config);
1251  }
1252 
1263  @Override
1264  public int muteLocalCamera(boolean mute) {
1265  if (mImpl == null) {
1266  return -1;
1267  }
1268  return mImpl.muteLocalCamera(mute);
1269  }
1270 
1278  @Override
1279  public int enableSpeakerphone(boolean enable) {
1280  if (mImpl == null) {
1281  return -1;
1282  }
1283  return mImpl.enableSpeakerphone(enable);
1284  }
1285 
1292  @Override
1293  public boolean isSpeakerphoneOn() {
1294  if (mImpl == null) {
1295  return false;
1296  }
1297  return mImpl.isSpeakerphoneOn();
1298  }
1299 
1306  @Override
1307  public String getLiveTraceId() {
1308  if (mImpl == null) {
1309  return "";
1310  }
1311  return mImpl.getLiveTraceId();
1312  }
1313 }
1314  // 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)
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)
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)