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