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