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 
14 
15 
27 @CalledByNative
28 public class AlivcLivePusher implements ILivePusher {
29  private ILivePusher mImpl = null;
30 
31  private static final String BASIC_PUSHER_IMPL_CLASS = "com.alivc.live.pusher.AlivcLivePusherBasicImpl";
32  private static final String INTERACTIVE_PUSHER_IMPL_CLASS = "com.alivc.live.pusher.rtc.AlivcRTCLivePusherImpl";
33 
42  @Override
43  public void init(Context context, AlivcLivePushConfig config) throws IllegalArgumentException, IllegalStateException {
45 
46  if (config == null) {
47  throw new IllegalArgumentException("Invalid parameter, config is null.");
48  }
49 
50  reflectInitPusher(config.getLivePushMode());
52 
53  if (mImpl == null) {
54  return;
55  }
56  mImpl.init(context, config);
57  }
58 
59  private void reflectInitPusher(AlivcLiveMode mode) {
60  Object playerInstance = null;
61 
63  playerInstance = ReflectUtil.reflectInit(INTERACTIVE_PUSHER_IMPL_CLASS, null, null);
64  } else {
65  playerInstance = ReflectUtil.reflectInit(BASIC_PUSHER_IMPL_CLASS, null, null);
66  }
67 
68  if (playerInstance == null) {
69  throw new RuntimeException("init live pusher error! now not support mode: " + mode);
70  }
71 
72  mImpl = (ILivePusher) playerInstance;
73  }
74 
80  @Override
81  public void destroy() throws IllegalStateException {
82  if (mImpl == null) {
83  return;
84  }
85  mImpl.destroy();
86  }
87 
93  @Override
94  public void setLivePusherReference(AlivcLivePusher livePusher) {
95  if (mImpl == null) {
96  return;
97  }
98  mImpl.setLivePusherReference(livePusher);
99  }
100 
108  @Override
109  public void startPreview(SurfaceView surfaceView) throws IllegalArgumentException, IllegalStateException {
110  if (mImpl == null) {
111  return;
112  }
113  mImpl.startPreview(surfaceView);
114  }
115 
123  @Override
124  public void startPreviewAsync(SurfaceView surfaceView) throws IllegalArgumentException, IllegalStateException {
125  if (mImpl == null) {
126  return;
127  }
128  mImpl.startPreviewAsync(surfaceView);
129  }
130 
141  @Override
142  public void startPreview(Context context, FrameLayout frameLayout, boolean isAnchor) throws IllegalArgumentException, IllegalStateException {
143  if (mImpl == null) {
144  return;
145  }
146  mImpl.startPreview(context, frameLayout, isAnchor);
147  }
148 
154  @Override
155  public void stopPreview() throws IllegalStateException {
156  if (mImpl == null) {
157  return;
158  }
159  mImpl.stopPreview();
160  }
161 
169  @Override
170  public void startPush(String url) throws IllegalArgumentException, IllegalStateException {
171  if (mImpl == null) {
172  return;
173  }
174  mImpl.startPush(AlivcLiveURLTools.trimUrl(url));
175  }
176 
184  @Override
185  public void startPushAsync(String url) throws IllegalArgumentException, IllegalStateException {
186  if (mImpl == null) {
187  return;
188  }
189  mImpl.startPushAsync(AlivcLiveURLTools.trimUrl(url));
190  }
191 
197  @Override
198  public void restartPush() throws IllegalStateException {
199  if (mImpl == null) {
200  return;
201  }
202  mImpl.restartPush();
203  }
204 
210  @Override
211  public void restartPushAsync() throws IllegalStateException {
212  if (mImpl == null) {
213  return;
214  }
215  mImpl.restartPushAsync();
216  }
217 
224  @Override
225  public void reconnectPushAsync(String url) throws IllegalStateException {
226  if (mImpl == null) {
227  return;
228  }
229  mImpl.reconnectPushAsync(AlivcLiveURLTools.trimUrl(url));
230  }
231 
237  @Override
238  public void stopPush() throws IllegalStateException {
239  if (mImpl == null) {
240  return;
241  }
242  mImpl.stopPush();
243  }
244 
250  @Override
251  public void pause() throws IllegalStateException {
252  if (mImpl == null) {
253  return;
254  }
255  mImpl.pause();
256  }
257 
263  @Override
264  public void resume() throws IllegalStateException {
265  if (mImpl == null) {
266  return;
267  }
268  mImpl.resume();
269  }
270 
276  @Override
277  public void resumeAsync() throws IllegalStateException {
278  if (mImpl == null) {
279  return;
280  }
281  mImpl.resumeAsync();
282  }
283 
289  @Override
290  public void switchCamera() throws IllegalStateException {
291  if (mImpl == null) {
292  return;
293  }
294  mImpl.switchCamera();
295  }
296 
303  @Override
304  public void setAutoFocus(boolean autoFocus) throws IllegalStateException {
305  if (mImpl == null) {
306  return;
307  }
308  mImpl.setAutoFocus(autoFocus);
309  }
310 
319  @Override
320  public void focusCameraAtAdjustedPoint(float x, float y, boolean autoFocus) throws IllegalArgumentException, IllegalStateException {
321  if (mImpl == null) {
322  return;
323  }
324  mImpl.focusCameraAtAdjustedPoint(x, y, autoFocus);
325  }
326 
333  @Override
334  public void setZoom(int zoom) throws IllegalArgumentException, IllegalStateException {
335  if (mImpl == null) {
336  return;
337  }
338  mImpl.setZoom(zoom);
339  }
340 
347  @Override
348  public int getMaxZoom() throws IllegalStateException {
349  if (mImpl == null) {
350  return -1;
351  }
352  return mImpl.getMaxZoom();
353  }
354 
361  @Override
362  public int getCurrentZoom() throws IllegalStateException {
363  if (mImpl == null) {
364  return -1;
365  }
366  return mImpl.getCurrentZoom();
367  }
368 
375  @Override
376  public void setMute(boolean mute) throws IllegalStateException {
377  if (mImpl == null) {
378  return;
379  }
380  mImpl.setMute(mute);
381  }
382 
389  @Override
390  public void setFlash(boolean flash) throws IllegalStateException {
391  if (mImpl == null) {
392  return;
393  }
394  mImpl.setFlash(flash);
395  }
396 
403  @Override
404  public void setPushMirror(boolean mirror) throws IllegalStateException {
405  if (mImpl == null) {
406  return;
407  }
408  mImpl.setPushMirror(mirror);
409  }
410 
417  @Override
418  public void setPreviewMirror(boolean mirror) throws IllegalStateException {
419  if (mImpl == null) {
420  return;
421  }
422  mImpl.setPreviewMirror(mirror);
423  }
424 
431  @Override
432  public void setTargetVideoBitrate(int targetVideoBitrate) throws IllegalArgumentException, IllegalStateException {
433  if (mImpl == null) {
434  return;
435  }
436  mImpl.setTargetVideoBitrate(targetVideoBitrate);
437  }
438 
445  @Override
446  public void setMinVideoBitrate(int minVideoBitrate) throws IllegalArgumentException, IllegalStateException {
447  if (mImpl == null) {
448  return;
449  }
450  mImpl.setMinVideoBitrate(minVideoBitrate);
451  }
452 
458  @Override
459  public boolean isCameraSupportAutoFocus() {
460  if (mImpl == null) {
461  return false;
462  }
463  return mImpl.isCameraSupportAutoFocus();
464  }
465 
471  @Override
472  public boolean isCameraSupportFlash() {
473  if (mImpl == null) {
474  return false;
475  }
476  return mImpl.isCameraSupportFlash();
477  }
478 
485  @Override
486  public boolean isPushing() throws IllegalStateException {
487  if (mImpl == null) {
488  return false;
489  }
490  return mImpl.isPushing();
491  }
492 
499  @Override
500  public boolean isNetworkPushing() throws IllegalStateException {
501  if (mImpl == null) {
502  return false;
503  }
504  return mImpl.isNetworkPushing();
505  }
506 
512  @Override
513  public void setCustomDetect(AlivcLivePushCustomDetect customVideoDetect) {
514  if (mImpl == null) {
515  return;
516  }
517  mImpl.setCustomDetect(customVideoDetect);
518  }
519 
525  @Override
526  public void setCustomFilter(AlivcLivePushCustomFilter customVideoFilter) {
527  if (mImpl == null) {
528  return;
529  }
530  mImpl.setCustomFilter(customVideoFilter);
531  }
532 
538  @Override
539  public void setCustomAudioFilter(AlivcLivePushCustomAudioFilter customAudioFilter) {
540  if (mImpl == null) {
541  return;
542  }
543  mImpl.setCustomAudioFilter(customAudioFilter);
544  }
545 
551  @Override
553  if (mImpl == null) {
554  return AlivcLivePushStats.IDLE;
555  }
556  return mImpl.getCurrentStatus();
557  }
558 
564  @Override
566  if (mImpl == null) {
567  return;
568  }
569  mImpl.setLivePushErrorListener(errorListener);
570  }
571 
577  @Override
579  if (mImpl == null) {
580  return;
581  }
582  mImpl.setLivePushInfoListener(infoListener);
583  }
584 
590  @Override
592  if (mImpl == null) {
593  return;
594  }
595  mImpl.setLivePushNetworkListener(networkListener);
596  }
597 
603  @Override
604  public void setLivePushBGMListener(AlivcLivePushBGMListener pushBGMListener) {
605  if (mImpl == null) {
606  return;
607  }
608  mImpl.setLivePushBGMListener(pushBGMListener);
609  }
610 
616  @Override
617  public void setLivePushRenderContextListener(AlivcLivePusherRenderContextListener renderCtxListener) {
618  if (mImpl == null) {
619  return;
620  }
621  mImpl.setLivePushRenderContextListener(renderCtxListener);
622  }
623 
630  @Override
631  public AlivcLivePushStatsInfo getLivePushStatsInfo() throws IllegalStateException {
632  if (mImpl == null) {
633  return null;
634  }
635  return mImpl.getLivePushStatsInfo();
636  }
637 
643  @Override
644  public String getPushUrl() {
645  if (mImpl == null) {
646  return "";
647  }
648  return mImpl.getPushUrl();
649  }
650 
656  @Override
658  if (mImpl == null) {
659  return;
660  }
661  mImpl.setPreviewOrientation(orientation);
662  }
663 
672  @Override
674  if (mImpl == null) {
675  return -1;
676  }
677  return mImpl.setAudioEffectVoiceChangeMode(mode);
678  }
679 
688  @Override
690  if (mImpl == null) {
691  return -1;
692  }
693  return mImpl.setAudioEffectReverbMode(mode);
694  }
695 
702  @Override
703  public void startBGMAsync(String path) throws IllegalStateException {
704  if (mImpl == null) {
705  return;
706  }
707  mImpl.startBGMAsync(path);
708  }
709 
715  @Override
716  public void stopBGMAsync() throws IllegalStateException {
717  if (mImpl == null) {
718  return;
719  }
720  mImpl.stopBGMAsync();
721  }
722 
728  @Override
729  public void pauseBGM() throws IllegalStateException {
730  if (mImpl == null) {
731  return;
732  }
733  mImpl.pauseBGM();
734  }
735 
741  @Override
742  public void resumeBGM() throws IllegalStateException {
743  if (mImpl == null) {
744  return;
745  }
746  mImpl.resumeBGM();
747  }
748 
755  @Override
756  public void setBGMLoop(boolean isLoop) throws IllegalStateException {
757  if (mImpl == null) {
758  return;
759  }
760  mImpl.setBGMLoop(isLoop);
761  }
762 
769  @Override
770  public void setBGMEarsBack(boolean isOpen) throws IllegalStateException {
771  if (mImpl == null) {
772  return;
773  }
774  mImpl.setBGMEarsBack(isOpen);
775  }
776 
784  @Override
785  public void setBGMVolume(int volume) throws IllegalStateException, IllegalArgumentException {
786  if (mImpl == null) {
787  return;
788  }
789  mImpl.setBGMVolume(volume);
790  }
791 
799  @Override
800  public void setCaptureVolume(int volume) throws IllegalStateException, IllegalArgumentException {
801  if (mImpl == null) {
802  return;
803  }
804  mImpl.setCaptureVolume(volume);
805  }
806 
812  @Override
813  public void setAudioDenoise(boolean on) {
814  if (mImpl == null) {
815  return;
816  }
817  mImpl.setAudioDenoise(on);
818  }
819 
835  @Override
836  public int startIntelligentDenoise() {
837  if (mImpl == null) {
838  return -1;
839  }
840  return mImpl.startIntelligentDenoise();
841  }
842 
849  @Override
850  public int stopIntelligentDenoise() {
851  if (mImpl == null) {
852  return -1;
853  }
854  return mImpl.stopIntelligentDenoise();
855  }
856 
863  @Override
864  public void setQualityMode(AlivcQualityModeEnum mode) throws IllegalStateException {
865  if (mImpl == null) {
866  return;
867  }
868  mImpl.setQualityMode(mode);
869  }
870 
877  @Override
878  public void setPreviewMode(AlivcPreviewDisplayMode mode) throws IllegalStateException {
879  if (mImpl == null) {
880  return;
881  }
882  mImpl.setPreviewMode(mode);
883  }
884 
890  @Override
891  public void pauseScreenCapture() throws IllegalStateException {
892  if (mImpl == null) {
893  return;
894  }
895  mImpl.pauseScreenCapture();
896  }
897 
903  @Override
904  public void resumeScreenCapture() throws IllegalStateException {
905  if (mImpl == null) {
906  return;
907  }
908  mImpl.resumeScreenCapture();
909  }
910 
916  @Override
918  if (mImpl == null) {
919  return AlivcLivePushError.ALIVC_COMMON_RETURN_SUCCESS;
920  }
921  return mImpl.getLastError();
922  }
923 
929  @Override
930  public void changeResolution(AlivcResolutionEnum resolution) {
931  if (mImpl == null) {
932  return;
933  }
934  mImpl.changeResolution(resolution);
935  }
936 
946  @Override
947  public void addWaterMark(String path, float x, float y, float width) {
948  if (mImpl == null) {
949  return;
950  }
951  mImpl.addWaterMark(path, x, y, width);
952  }
953 
959  @Override
960  public void setWatermarkVisible(boolean visible) {
961  if (mImpl == null) {
962  return;
963  }
964  mImpl.setWatermarkVisible(visible);
965  }
966 
974  @Override
975  public int startCamera(SurfaceView surfaceView) throws IllegalStateException {
976  if (mImpl == null) {
977  return -1;
978  }
979  return mImpl.startCamera(surfaceView);
980  }
981 
985  @Override
986  public void stopCamera() {
987  if (mImpl == null) {
988  return;
989  }
990  mImpl.stopCamera();
991  }
992 
998  @Override
999  public void setScreenOrientation(int orientation) {
1000  if (mImpl == null) {
1001  return;
1002  }
1003  mImpl.setScreenOrientation(orientation);
1004  }
1005 
1015  @Override
1016  public int startCameraMix(float x, float y, float w, float h) {
1017  if (mImpl == null) {
1018  return -1;
1019  }
1020  return mImpl.startCameraMix(x, y, w, h);
1021  }
1022 
1026  @Override
1027  public void stopCameraMix() {
1028  if (mImpl == null) {
1029  return;
1030  }
1031  mImpl.stopCameraMix();
1032  }
1033 
1041  @Override
1042  public void snapshot(int count, int interval, AlivcSnapshotListener listener) {
1043  if (mImpl == null) {
1044  return;
1045  }
1046  mImpl.snapshot(count, interval, listener);
1047  }
1048 
1062  @Override
1063  public void inputStreamVideoPtr(long dataPtr, int width, int height, int stride, int size, long pts, int rotation) {
1064  if (mImpl == null) {
1065  return;
1066  }
1067  mImpl.inputStreamVideoPtr(dataPtr, width, height, stride, size, pts, rotation);
1068  }
1069 
1083  @Override
1084  public void inputStreamVideoData(byte[] data, int width, int height, int stride, int size, long pts, int rotation) {
1085  if (mImpl == null) {
1086  return;
1087  }
1088  mImpl.inputStreamVideoData(data, width, height, stride, size, pts, rotation);
1089  }
1090 
1102  @Override
1103  public void inputStreamAudioPtr(long dataPtr, int size, int sampleRate, int channels, long pts) {
1104  if (mImpl == null) {
1105  return;
1106  }
1107  mImpl.inputStreamAudioPtr(dataPtr, size, sampleRate, channels, pts);
1108  }
1109 
1121  @Override
1122  public void inputStreamAudioData(byte[] data, int size, int sampleRate, int channels, long pts) {
1123  if (mImpl == null) {
1124  return;
1125  }
1126  mImpl.inputStreamAudioData(data, size, sampleRate, channels, pts);
1127  }
1128 
1139  @Override
1140  public int addDynamicsAddons(String path, float x, float y, float w, float h) {
1141  if (mImpl == null) {
1142  return -1;
1143  }
1144  return mImpl.addDynamicsAddons(path, x, y, w, h);
1145  }
1146 
1152  @Override
1153  public void removeDynamicsAddons(int id) {
1154  if (mImpl == null) {
1155  return;
1156  }
1157  mImpl.removeDynamicsAddons(id);
1158  }
1159 
1165  @Override
1166  public void setExposure(int exposure) {
1167  if (mImpl == null) {
1168  return;
1169  }
1170  mImpl.setExposure(exposure);
1171  }
1172 
1178  @Override
1179  public int getCurrentExposure() {
1180  if (mImpl == null) {
1181  return -1;
1182  }
1183  return mImpl.getCurrentExposure();
1184  }
1185 
1191  @Override
1193  if (mImpl == null) {
1194  return -1;
1195  }
1196  return mImpl.getSupportedMinExposure();
1197  }
1198 
1204  @Override
1206  if (mImpl == null) {
1207  return -1;
1208  }
1209  return mImpl.getSupportedMaxExposure();
1210  }
1211 
1220  @Override
1221  public void sendMessage(String info, int repeat, int delay, boolean isKeyFrame) {
1222  if (mImpl == null) {
1223  return;
1224  }
1225  mImpl.sendMessage(info, repeat, delay, isKeyFrame);
1226  }
1227 
1242  @Override
1244  if (mImpl == null) {
1245  return -1;
1246  }
1247  return mImpl.setLiveMixTranscodingConfig(config);
1248  }
1249 
1260  @Override
1261  public int muteLocalCamera(boolean mute) {
1262  if (mImpl == null) {
1263  return -1;
1264  }
1265  return mImpl.muteLocalCamera(mute);
1266  }
1267 
1275  @Override
1276  public int enableSpeakerphone(boolean enable) {
1277  if (mImpl == null) {
1278  return -1;
1279  }
1280  return mImpl.enableSpeakerphone(enable);
1281  }
1282 
1289  @Override
1290  public boolean isSpeakerphoneOn() {
1291  if (mImpl == null) {
1292  return false;
1293  }
1294  return mImpl.isSpeakerphoneOn();
1295  }
1296 
1303  @Override
1304  public String getLiveTraceId() {
1305  if (mImpl == null) {
1306  return "";
1307  }
1308  return mImpl.getLiveTraceId();
1309  }
1310 }
1311 
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)
Live pusher abstract class.
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)