好多开发者提到,为什么大牛直播SDK的Android平台RTMP推送接口怎么这么多?不像一些开源或者商业RTMP推送一样,就几个接口,简单明了。

不解释,以Android平台RTMP推送模块常用接口,看看这些接口有没有存在的意义?本文简单介绍,全当抛砖引玉,相关资料,可参考 Github

1. 初始化Publisher接口,返回推送实例句柄:

  1. /**
  2. * Open publisher(启动推送实例)
  3. *
  4. * @param ctx: get by this.getApplicationContext()
  5. *
  6. * @param audio_opt:
  7. * if 0: 不推送音频
  8. * if 1: 推送编码前音频(PCM)
  9. * if 2: 推送编码后音频(aac/pcma/pcmu/speex).
  10. *
  11. * @param video_opt:
  12. * if 0: 不推送视频
  13. * if 1: 推送编码前视频(YUV420SP/YUV420P/RGBA/ARGB)
  14. * if 2: 推送编码后视频(H.264)
  15. *
  16. * @param width: capture width; height: capture height.
  17. *
  18. * <pre>This function must be called firstly.</pre>
  19. *
  20. * @return the handle of publisher instance
  21. */
  22. public native long SmartPublisherOpen(Object ctx, int audio_opt, int video_opt, int width, int height);

2. 相关Event事件回调,如网络状态、实时快照、录像状态等回调:

  1. /**
  2. * Set callback event(设置事件回调)
  3. *
  4. * @param callbackv2: callback function
  5. *
  6. * @return {0} if successful
  7. */
  8. public native int SetSmartPublisherEventCallbackV2(long handle, NTSmartEventCallbackV2 callbackv2);

  1. class EventHandeV2 implements NTSmartEventCallbackV2 {
  2. @Override
  3. public void onNTSmartEventCallbackV2(long handle, int id, long param1, long param2, String param3, String param4, Object param5) {
  4. Log.i(TAG, "EventHandeV2: handle=" + handle + " id:" + id);
  5. String publisher_event = "";
  6. switch (id) {
  7. case NTSmartEventID.EVENT_DANIULIVE_ERC_PUBLISHER_STARTED:
  8. publisher_event = "开始..";
  9. break;
  10. case NTSmartEventID.EVENT_DANIULIVE_ERC_PUBLISHER_CONNECTING:
  11. publisher_event = "连接中..";
  12. break;
  13. case NTSmartEventID.EVENT_DANIULIVE_ERC_PUBLISHER_CONNECTION_FAILED:
  14. publisher_event = "连接失败..";
  15. break;
  16. case NTSmartEventID.EVENT_DANIULIVE_ERC_PUBLISHER_CONNECTED:
  17. publisher_event = "连接成功..";
  18. break;
  19. case NTSmartEventID.EVENT_DANIULIVE_ERC_PUBLISHER_DISCONNECTED:
  20. publisher_event = "连接断开..";
  21. break;
  22. case NTSmartEventID.EVENT_DANIULIVE_ERC_PUBLISHER_STOP:
  23. publisher_event = "关闭..";
  24. break;
  25. case NTSmartEventID.EVENT_DANIULIVE_ERC_PUBLISHER_RECORDER_START_NEW_FILE:
  26. publisher_event = "开始一个新的录像文件 : " + param3;
  27. break;
  28. case NTSmartEventID.EVENT_DANIULIVE_ERC_PUBLISHER_ONE_RECORDER_FILE_FINISHED:
  29. publisher_event = "已生成一个录像文件 : " + param3;
  30. break;
  31. case NTSmartEventID.EVENT_DANIULIVE_ERC_PUBLISHER_SEND_DELAY:
  32. publisher_event = "发送时延: " + param1 + " 帧数:" + param2;
  33. break;
  34. case NTSmartEventID.EVENT_DANIULIVE_ERC_PUBLISHER_CAPTURE_IMAGE:
  35. publisher_event = "快照: " + param1 + " 路径:" + param3;
  36. if (param1 == 0) {
  37. publisher_event = publisher_event + "截取快照成功..";
  38. } else {
  39. publisher_event = publisher_event + "截取快照失败..";
  40. }
  41. break;
  42. case NTSmartEventID.EVENT_DANIULIVE_ERC_PUBLISHER_RTSP_URL:
  43. publisher_event = "RTSP服务URL: " + param3;
  44. break;
  45. case NTSmartEventID.EVENT_DANIULIVE_ERC_PUSH_RTSP_SERVER_RESPONSE_STATUS_CODE:
  46. publisher_event ="RTSP status code received, codeID: " + param1 + ", RTSP URL: " + param3;
  47. break;
  48. case NTSmartEventID.EVENT_DANIULIVE_ERC_PUSH_RTSP_SERVER_NOT_SUPPORT:
  49. publisher_event ="服务器不支持RTSP推送, 推送的RTSP URL: " + param3;
  50. break;
  51. }
  52. String str = "当前回调状态:" + publisher_event;
  53. Log.i(TAG, str);
  54. Message message = new Message();
  55. message.what = PUBLISHER_EVENT_MSG;
  56. message.obj = publisher_event;
  57. handler.sendMessage(message);
  58. }
  59. }

3. 检测/设置软硬编码:

  1. /**
  2. * Set Video H.264 HW Encoder, if support HW encoder, it will return 0(设置H.264硬编码)
  3. *
  4. * @param kbps: the kbps of different resolution(25 fps).
  5. *
  6. * @return {0} if successful
  7. */
  8. public native int SetSmartPublisherVideoHWEncoder(long handle, int kbps);
  9. /**
  10. * Set Video H.265(hevc) hardware encoder, if support H.265(hevc) hardware encoder, it will return 0(设置H.265硬编码)
  11. *
  12. * @param kbps: the kbps of different resolution(25 fps).
  13. *
  14. * @return {0} if successful
  15. */
  16. public native int SetSmartPublisherVideoHevcHWEncoder(long handle, int kbps);

4. 设置文字水印、PNG图片水印:

  1. /**
  2. * Set Text water-mark(设置文字水印)
  3. *
  4. * @param fontSize: it should be "MEDIUM", "SMALL", "BIG"
  5. *
  6. * @param waterPostion: it should be "TOPLEFT", "TOPRIGHT", "BOTTOMLEFT", "BOTTOMRIGHT".
  7. *
  8. * @param xPading, yPading: the distance of the original picture.
  9. *
  10. * <pre> The interface is only used for setting font water-mark when publishing stream. </pre>
  11. *
  12. * @return {0} if successful
  13. */
  14. public native int SmartPublisherSetTextWatermark(long handle, String waterText, int isAppendTime, int fontSize, int waterPostion, int xPading, int yPading);
  15. /**
  16. * Set Text water-mark font file name(设置文字水印字体路径)
  17. *
  18. * @param fontFileName: font full file name, e.g: /system/fonts/DroidSansFallback.ttf
  19. *
  20. * @return {0} if successful
  21. */
  22. public native int SmartPublisherSetTextWatermarkFontFileName(long handle, String fontFileName);
  23. /**
  24. * Set picture water-mark(设置png图片水印)
  25. *
  26. * @param picPath: the picture working path, e.g: /sdcard/logo.png
  27. *
  28. * @param waterPostion: it should be "TOPLEFT", "TOPRIGHT", "BOTTOMLEFT", "BOTTOMRIGHT".
  29. *
  30. * @param picWidth, picHeight: picture width & height
  31. *
  32. * @param xPading, yPading: the distance of the original picture.
  33. *
  34. * <pre> The interface is only used for setting picture(logo) water-mark when publishing stream, with "*.png" format </pre>
  35. *
  36. * @return {0} if successful
  37. */
  38. public native int SmartPublisherSetPictureWatermark(long handle, String picPath, int waterPostion, int picWidth, int picHeight, int xPading, int yPading);

5. 软编码可变码率设置(如摄像头采集编码,在设备性能允许的情况下,可以考虑软编码可变码率):

  1. /**
  2. * Set software encode vbr mode(软编码可变码率).
  3. *
  4. * <pre>please set before SmartPublisherStart while after SmartPublisherOpen.</pre>
  5. *
  6. * is_enable_vbr: if 0: NOT enable vbr mode, 1: enable vbr
  7. *
  8. * video_quality: vbr video quality, range with (1,50), default 23
  9. *
  10. * vbr_max_kbitrate: vbr max encode bit-rate(kbps)
  11. *
  12. * @return {0} if successful
  13. */
  14. public native int SmartPublisherSetSwVBRMode(long handle, int is_enable_vbr, int video_quality, int vbr_max_kbitrate);

6. 帧率、软编码码率、关键帧间隔,编码速度、软编码profile等基础设定:

  1. /**
  2. * Set gop interval(设置I帧间隔)
  3. *
  4. * <pre>please set before SmartPublisherStart while after SmartPublisherOpen.</pre>
  5. *
  6. * gopInterval: encode I frame interval, the value always > 0
  7. *
  8. * @return {0} if successful
  9. */
  10. public native int SmartPublisherSetGopInterval(long handle, int gopInterval);
  11. /**
  12. * Set software encode video bit-rate(设置视频软编码bit-rate)
  13. *
  14. * <pre>please set before SmartPublisherStart while after SmartPublisherOpen.</pre>
  15. *
  16. * avgBitRate: average encode bit-rate(kbps)
  17. *
  18. * maxBitRate: max encode bit-rate(kbps)
  19. *
  20. * @return {0} if successful
  21. */
  22. public native int SmartPublisherSetSWVideoBitRate(long handle, int avgBitRate, int maxBitRate);
  23. /**
  24. * Set fps(设置帧率)
  25. *
  26. * <pre>please set before SmartPublisherStart while after SmartPublisherOpen.</pre>
  27. *
  28. * fps: the fps of video, range with (1,25).
  29. *
  30. * @return {0} if successful
  31. */
  32. public native int SmartPublisherSetFPS(long handle, int fps);
  33. /**
  34. * Set software video encoder profile(设置视频编码profile).
  35. *
  36. * <pre>please set before SmartPublisherStart while after SmartPublisherOpen.</pre>
  37. *
  38. * profile: the software video encoder profile, range with (1,3).
  39. *
  40. * 1: baseline profile
  41. * 2: main profile
  42. * 3: high profile
  43. *
  44. * @return {0} if successful
  45. */
  46. public native int SmartPublisherSetSWVideoEncoderProfile(long handle, int profile);
  47. /**
  48. * Set software video encoder speed(设置视频软编码编码速度)
  49. *
  50. * <pre>please set before SmartPublisherStart while after SmartPublisherOpen.</pre>
  51. *
  52. * @param speed: range with(1, 6), the default speed is 6.
  53. *
  54. * if with 1, CPU is lowest.
  55. * if with 6, CPU is highest.
  56. *
  57. * @return {0} if successful
  58. */
  59. public native int SmartPublisherSetSWVideoEncoderSpeed(long handle, int speed);

7. 设置audio编码类型,如AAC编码、Speex编码,并设置如AAC编码码率等参数:

  1. /**
  2. * Set audio encoder type(设置音频编码类型)
  3. *
  4. * @param type: if with 1:AAC, if with 2: SPEEX
  5. *
  6. * @return {0} if successful
  7. */
  8. public native int SmartPublisherSetAudioCodecType(long handle, int type);
  9. /**
  10. * Set audio encoder bit-rate(设置音频编码码率), 当前只对AAC编码有效
  11. *
  12. * @param kbit_rate: 码率(单位是kbps), 如果是0的话将使用默认码率, 必须大于等于0
  13. *
  14. * @return {0} if successful
  15. */
  16. public native int SmartPublisherSetAudioBitRate(long handle, int kbit_rate);
  17. /**
  18. * Set speex encoder quality(设置speex编码质量)
  19. *
  20. * @param quality: range with (0, 10), default value is 8
  21. *
  22. * @return {0} if successful
  23. */
  24. public native int SmartPublisherSetSpeexEncoderQuality(long handle, int quality);

8. 音频处理,如自动增益控制、噪音抑制:

  1. /**
  2. * Set Audio Noise Suppression(设置音频噪音抑制)
  3. *
  4. * @param isNS: if with 1:suppress, if with 0: does not suppress
  5. *
  6. * @return {0} if successful
  7. */
  8. public native int SmartPublisherSetNoiseSuppression(long handle, int isNS);
  9. /**
  10. * Set Audio AGC(设置音频自动增益控制)
  11. *
  12. * @param isAGC: if with 1:AGC, if with 0: does not AGC
  13. *
  14. * @return {0} if successful
  15. */
  16. public native int SmartPublisherSetAGC(long handle, int isAGC);

9. 音频混音接口设置:

  1. /**
  2. * 设置混音,目前支持两路音频混音
  3. *
  4. * @param is_mix: 1混音, 0不混音, 默认不混音
  5. *
  6. * @return {0} if successful
  7. */
  8. public native int SmartPublisherSetAudioMix(long handle, int is_mix);

10. 实时静音设置:

  1. /**
  2. * Set mute or not during publish stream(设置实时静音)
  3. *
  4. * @param isMute: if with 1:mute, if with 0: does not mute
  5. *
  6. * @return {0} if successful
  7. */
  8. public native int SmartPublisherSetMute(long handle, int isMute);

11. 音量调整:

  1. /**
  2. * 设置输入音量, 这个接口一般不建议调用, 在一些特殊情况下可能会用, 一般不建议放大音量
  3. *
  4. * @param index: 一般是0和1, 如果没有混音的只用0, 有混音的话, 0,1分别设置音量
  5. *
  6. * @param volume: 音量,默认是1.0,范围是[0.0, 5.0], 设置成0静音, 1音量不变
  7. *
  8. * @return {0} if successful
  9. */
  10. public native int SmartPublisherSetInputAudioVolume(long handle, int index, float volume);

12. 前置摄像头镜像:

  1. /**
  2. * Set mirror(设置前置摄像头镜像)
  3. *
  4. * @param isMirror: if with 1:mirror mode, if with 0: normal mode
  5. *
  6. * Please note when with "mirror mode", the publisher and player with the same echo direction
  7. *
  8. * @return {0} if successful
  9. */
  10. public native int SmartPublisherSetMirror(long handle, int isMirror);

13. 录像相关配置,如只录制音频或视频,单个文件最大size,录像存放目录,开始/暂停/停止录像:

  1. /**
  2. * 音频录制开关, 目的是为了更细粒度的去控制录像, 一般不需要调用这个接口, 这个接口使用场景比如同时推送音视频,但只想录制视频,可以调用这个接口关闭音频录制
  3. *
  4. * @param is_recoder: 0: do not recorder; 1: recorder; sdk默认是1
  5. *
  6. * @return {0} if successful
  7. */
  8. public native int SmartPublisherSetRecorderAudio(long handle, int is_recoder);
  9. /**
  10. * 视频录制开关, 目的是为了更细粒度的去控制录像, 一般不需要调用这个接口, 这个接口使用场景比如同时推送音视频,但只想录制音频,可以调用这个接口关闭视频录制
  11. *
  12. * @param is_recoder: 0: do not recorder; 1: recorder; sdk默认是1
  13. *
  14. * @return {0} if successful
  15. */
  16. public native int SmartPublisherSetRecorderVideo(long handle, int is_recoder);
  17. /**
  18. * Create file directory(创建录像存放目录)
  19. *
  20. * @param path, E.g: /sdcard/daniulive/rec
  21. *
  22. * <pre> The interface is only used for recording the stream data to local side. </pre>
  23. *
  24. * @return {0} if successful
  25. */
  26. public native int SmartPublisherCreateFileDirectory(String path);
  27. /**
  28. * Set recorder directory(设置录像存放目录)
  29. *
  30. * @param path: the directory of recorder file.
  31. *
  32. * <pre> NOTE: make sure the path should be existed, or else the setting failed. </pre>
  33. *
  34. * @return {0} if successful
  35. */
  36. public native int SmartPublisherSetRecorderDirectory(long handle, String path);
  37. /**
  38. * Set the size of every recorded file(设置单个录像文件大小,如超过最大文件大小,自动切换到下个文件录制)
  39. *
  40. * @param size: (MB), (5M~500M), if not in this range, set default size with 200MB.
  41. *
  42. * @return {0} if successful
  43. */
  44. public native int SmartPublisherSetRecorderFileMaxSize(long handle, int size);
  45. /**
  46. * Start recorder(开始录像)
  47. *
  48. * @return {0} if successful
  49. */
  50. public native int SmartPublisherStartRecorder(long handle);
  51. /**
  52. * Pause recorder(暂停/恢复录像)
  53. *
  54. * is_pause: 1表示暂停, 0表示恢复录像, 输入其他值将调用失败
  55. *
  56. * @return {0} if successful
  57. */
  58. public native int SmartPublisherPauseRecorder(long handle, int is_pause);
  59. /**
  60. * Stop recorder(停止录像)
  61. *
  62. * @return {0} if successful
  63. */
  64. public native int SmartPublisherStopRecorder(long handle);

14. 实时快照:

  1. /**
  2. * Set if needs to save image during publishing stream(设置是否启用快照)
  3. *
  4. * @param is_save_image: if with 1, it will save current image via the interface of SmartPlayerSaveImage(), if with 0: does not it
  5. *
  6. * @return {0} if successful
  7. */
  8. public native int SmartPublisherSaveImageFlag(long handle, int is_save_image);
  9. /**
  10. * Save current image during publishing stream(实时快照)
  11. *
  12. * @param imageName: image name, which including fully path, "/sdcard/daniuliveimage/daniu.png", etc.
  13. *
  14. * @return {0} if successful
  15. */
  16. public native int SmartPublisherSaveCurImage(long handle, String imageName);

15. 设置推送的RTMP URL:

  1. /**
  2. * Set rtmp publish stream url(设置推送的RTMP url)
  3. *
  4. * @param url: rtmp publish url.
  5. *
  6. * @return {0} if successful
  7. */
  8. public native int SmartPublisherSetURL(long handle, String url);

16. Android摄像头前后camera通过OnPreviewFrame()回调的数据接口:

  1. @Override
  2. public void onPreviewFrame(byte[] data, Camera camera) {
  3. frameCount++;
  4. if (frameCount % 3000 == 0) {
  5. Log.i("OnPre", "gc+");
  6. System.gc();
  7. Log.i("OnPre", "gc-");
  8. }
  9. if (data == null) {
  10. Parameters params = camera.getParameters();
  11. Size size = params.getPreviewSize();
  12. int bufferSize = (((size.width | 0x1f) + 1) * size.height * ImageFormat.getBitsPerPixel(params.getPreviewFormat())) / 8;
  13. camera.addCallbackBuffer(new byte[bufferSize]);
  14. } else {
  15. if (isRTSPPublisherRunning || isPushingRtmp || isRecording || isPushingRtsp) {
  16. libPublisher.SmartPublisherOnCaptureVideoData(publisherHandle, data, data.length, currentCameraType, currentOrigentation);
  17. }
  18. camera.addCallbackBuffer(data);
  19. }
  20. }

对应接口定义:

  1. /**
  2.     * Set live video data(no encoded data).
  3.     *
  4.     * @param cameraType: CAMERA_FACING_BACK with 0, CAMERA_FACING_FRONT with 1
  5.     * 
  6.     * @param curOrg:
  7.          * PORTRAIT = 1;    //竖屏
  8.          * LANDSCAPE = 2;    //横屏 home键在右边的情况
  9.          * LANDSCAPE_LEFT_HOME_KEY = 3; //横屏 home键在左边的情况
  10.     *
  11.     * @return {0} if successful
  12.     */
  13.     public native int SmartPublisherOnCaptureVideoData(long handle, byte[] data, int len, int cameraType, int curOrg);

17. 部分定制设备,只支持YV12的数据:

  1.     /**
  2.      * YV12数据接口
  3.      *
  4.      * @param data: YV12 data
  5.      *
  6.      * @param width: 图像宽
  7.      *
  8.      * @param height: 图像高
  9.      *
  10.      * @param y_stride:  y面步长
  11.      *
  12.      * @param v_stride: v面步长
  13.      *
  14.      * @param u_stride: u面步长
  15.      *
  16.      * rotation_degree: 顺时针旋转, 必须是0, 90, 180, 270
  17.      *
  18.      * @return {0} if successful
  19.      */
  20.     public native int SmartPublisherOnYV12Data(long handle, byte[] data, int width, int height, int y_stride,  int v_stride, int u_stride, int rotation_degree);

18. 支持NV21数据接口:

nv21数据接口,除了用于常规的camera数据接入外,部分定制摄像头出来的数据发生翻转,这个接口也支持。

  1.     /**
  2.      * NV21数据接口
  3.      *
  4.      * @param data: nv21 data
  5.      *
  6.      * @param len: data length
  7.      *
  8.      * @param width: 图像宽
  9.      *
  10.      * @param height: 图像高
  11.      *
  12.      * @param y_stride:  y面步长
  13.      *
  14.      * @param uv_stride:  uv面步长
  15.      *
  16.      * rotation_degree: 顺时针旋转, 必须是0, 90, 180, 270
  17.      *
  18.      * @return {0} if successful
  19.      */
  20.     public native int SmartPublisherOnNV21Data(long handle, byte[] data, int len, int width, int height, int y_stride,  int uv_stride, int rotation_degree);
  21.     /**
  22.      * NV21数据接口
  23.      *
  24.      * @param data: nv21 data
  25.      *
  26.      * @param len: data length
  27.      *
  28.      * @param width: 图像宽
  29.      *
  30.      * @param height: 图像高
  31.      *
  32.      * @param y_stride:  y面步长
  33.      *
  34.      * @param uv_stride:  uv面步长
  35.      *
  36.      * rotation_degree: 顺时针旋转, 必须是0, 90, 180, 270
  37.      *
  38.      * @param  is_vertical_flip: 是否垂直翻转, 0不翻转, 1翻转
  39.      *
  40.      * @param  is_horizontal_flip:是否水平翻转, 0不翻转, 1翻转
  41.      *
  42.      * @return {0} if successful
  43.      */
  44.     public native int SmartPublisherOnNV21DataV2(long handle, byte[] data, int len, int width, int height, int y_stride,  int uv_stride, int rotation_degree,
  45.                                                  int is_vertical_flip, int is_horizontal_flip);

19. 支持YUV数据接入:

  1.     /**
  2.     * Set live video data(no encoded data).
  3.     *
  4.     * @param data: I420 data
  5.     * 
  6.     * @param len: I420 data length
  7.     * 
  8.     * @param yStride: y stride
  9.     * 
  10.     * @param uStride: u stride
  11.     * 
  12.     * @param vStride: v stride
  13.     *
  14.     * @return {0} if successful
  15.     */
  16.     public native int SmartPublisherOnCaptureVideoI420Data(long handle,  byte[] data, int len, int yStride, int uStride, int vStride);

20. 支持RGBA数据接入(支持裁剪后数据接入,主要用于同屏场景):

  1.     /**
  2.     * Set live video data(no encoded data).
  3.     *
  4.     * @param data: RGBA data
  5.     * 
  6.     * @param rowStride: stride information
  7.     * 
  8.     * @param width: width
  9.     * 
  10.     * @param height: height
  11.     *
  12.     * @return {0} if successful
  13.     */
  14.     public native int SmartPublisherOnCaptureVideoRGBAData(long handle,  ByteBuffer data, int rowStride, int width, int height);
  15.     /**
  16.      * 投递裁剪过的RGBA数据
  17.      *
  18.      * @param data: RGBA data
  19.      *
  20.      * @param rowStride: stride information
  21.      *
  22.      * @param width: width
  23.      *
  24.      * @param height: height
  25.      *
  26.      * @param clipedLeft: 左;  clipedTop: 上; clipedwidth: 裁剪后的宽; clipedHeight: 裁剪后的高; 确保传下去裁剪后的宽、高均为偶数
  27.      *
  28.      * @return {0} if successful
  29.      */
  30.     public native int SmartPublisherOnCaptureVideoClipedRGBAData(long handle,  ByteBuffer data, int rowStride, int width, int height, int clipedLeft, int clipedTop, int clipedWidth, int clipedHeight);
  31.     /**
  32.      * Set live video data(no encoded data).
  33.      *
  34.      * @param data: ABGR flip vertical(垂直翻转) data
  35.      *
  36.      * @param rowStride: stride information
  37.      *
  38.      * @param width: width
  39.      *
  40.      * @param height: height
  41.      *
  42.      * @return {0} if successful
  43.      */
  44.     public native int SmartPublisherOnCaptureVideoABGRFlipVerticalData(long handle,  ByteBuffer data, int rowStride, int width, int height);

21. 支持RGB565数据接入(主要用于同屏场景):

  1.     /**
  2.      * Set live video data(no encoded data).
  3.      *
  4.      * @param data: RGB565 data
  5.      *
  6.      * @param row_stride: stride information
  7.      *
  8.      * @param width: width
  9.      *
  10.      * @param height: height
  11.      *
  12.      * @return {0} if successful
  13.      */
  14.     public native int SmartPublisherOnCaptureVideoRGB565Data(long handle,ByteBuffer data, int row_stride, int width, int height);

22. 支持camera数据接入(主要用于camera2接口对接):

  1. /*
  2.     *  专门为android.media.Image的android.graphics.ImageFormat.YUV_420_888格式提供的接口
  3.     *
  4.     * @param  width: 必须是8的倍数
  5.     *
  6.     * @param  height: 必须是8的倍数
  7.     *
  8.     * @param  crop_left: 剪切左上角水平坐标, 一般根据android.media.Image.getCropRect() 填充
  9.     *
  10.     * @param  crop_top: 剪切左上角垂直坐标, 一般根据android.media.Image.getCropRect() 填充
  11.     *
  12.     * @param  crop_width: 必须是8的倍数, 填0将忽略这个参数, 一般根据android.media.Image.getCropRect() 填充
  13.     *
  14.     * @param  crop_height: 必须是8的倍数, 填0将忽略这个参数,一般根据android.media.Image.getCropRect() 填充
  15.     *
  16.     * @param y_plane 对应android.media.Image.Plane[0].getBuffer()
  17.     *
  18.     * @param y_row_stride 对应android.media.Image.Plane[0].getRowStride()
  19.     *
  20.     * @param u_plane 对应android.media.Image.Plane[1].getBuffer()
  21.     *
  22.     * @param v_plane 对应android.media.Image.Plane[2].getBuffer()
  23.     *
  24.     * @param uv_row_stride 对应android.media.Image.Plane[1].getRowStride()
  25.     *
  26.     * @param uv_pixel_stride 对应android.media.Image.Plane[1].getPixelStride()
  27.     *
  28.     * @param  rotation_degree: 顺时针旋转, 必须是0, 90, 180, 270
  29.     *
  30.     * @param  is_vertical_flip: 是否垂直翻转, 0不翻转, 1翻转
  31.     *
  32.     * @param  is_horizontal_flip:是否水平翻转, 0不翻转, 1翻转
  33.     *
  34.     * @param  scale_width: 缩放宽,必须是8的倍数, 0不缩放
  35.     *
  36.     * @param  scale_height: 缩放高, 必须是8的倍数, 0不缩放
  37.     *
  38.     * @param  scale_filter_mode: 缩放质量, 范围必须是[1,3], 传0使用默认速度
  39.     *
  40.     * @return {0} if successful
  41.     */
  42.     public native int SmartPublisherOnImageYUV420888(long handle, int width, int height,
  43.                                                      int crop_left, int crop_top, int crop_width, int crop_height,
  44.                                                      ByteBuffer y_plane, int y_row_stride,
  45.                                                      ByteBuffer u_plane, ByteBuffer v_plane, int uv_row_stride, int uv_pixel_stride,
  46.                                                      int rotation_degree, int is_vertical_flip, int is_horizontal_flip,
  47.                                                      int scale_width, int scale_height, int scale_filter_mode);

23. 支持PCM数据接入:

  1.     /**
  2.      * 传递PCM音频数据给SDK, 每10ms音频数据传入一次
  3.      * 
  4.      *  @param pcmdata: pcm数据, 需要使用ByteBuffer.allocateDirect分配, ByteBuffer.isDirect()是true的才行.
  5.      *  @param size: pcm数据大小
  6.      *  @param sample_rate: 采样率,当前只支持{44100, 8000, 16000, 24000, 32000, 48000}, 推荐44100
  7.      *  @param channel: 通道, 当前通道支持单通道(1)和双通道(2),推荐单通道(1)
  8.      *  @param per_channel_sample_number: 这个请传入的是 sample_rate/100
  9.      */
  10.     public native int SmartPublisherOnPCMData(long handle, ByteBuffer pcmdata, int size, int sample_rate, int channel, int per_channel_sample_number);
  11.     /**
  12.      * 传递PCM音频数据给SDK, 每10ms音频数据传入一次
  13.      *
  14.      *  @param pcmdata: pcm数据, 需要使用ByteBuffer.allocateDirect分配, ByteBuffer.isDirect()是true的才行.
  15.      *  @param offset: pcmdata的偏移
  16.      *  @param size: pcm数据大小
  17.      *  @param sample_rate: 采样率,当前只支持{44100, 8000, 16000, 24000, 32000, 48000}, 推荐44100
  18.      *  @param channel: 通道, 当前通道支持单通道(1)和双通道(2),推荐单通道(1)
  19.      *  @param per_channel_sample_number: 这个请传入的是 sample_rate/100
  20.      */
  21.     public native int SmartPublisherOnPCMDataV2(long handle, ByteBuffer pcmdata, int offset, int size, int sample_rate, int channel, int per_channel_sample_number);
  22.     /**
  23.      * 传递PCM音频数据给SDK, 每10ms音频数据传入一次
  24.      *
  25.      *  @param pcm_short_array: pcm数据, short是native endian order
  26.      *  @param offset: 数组偏移
  27.      *  @param len: 数组项数
  28.      *  @param sample_rate: 采样率,当前只支持{44100, 8000, 16000, 24000, 32000, 48000}, 推荐44100
  29.      *  @param channel: 通道, 当前通道支持单通道(1)和双通道(2),推荐单通道(1)
  30.      *  @param per_channel_sample_number: 这个请传入的是 sample_rate/100
  31.      */
  32.     public native int SmartPublisherOnPCMShortArray(long handle, short[] pcm_short_array, int offset, int len, int sample_rate, int channel, int per_channel_sample_number);

24. 支持远端PCM数据接入和混音后PCM数据接入(主要用于一对一互动):

  1. /**
  2.      * Set far end pcm data
  3.      * 
  4.      * @param pcmdata : 16bit pcm data
  5.      * @param sampleRate: audio sample rate
  6.      * @param channel: auido channel
  7.      * @param per_channel_sample_number: per channel sample numbers
  8.      * @param is_low_latency: if with 0, it is not low_latency, if with 1, it is low_latency
  9.      * @return {0} if successful
  10.      */
  11.     public native int SmartPublisherOnFarEndPCMData(long handle,  ByteBuffer pcmdata, int sampleRate, int channel, int per_channel_sample_number, int is_low_latency);
  12.     /**
  13.      * 传递PCM混音音频数据给SDK, 每10ms音频数据传入一次
  14.      *
  15.      *  @param stream_index: 当前只能传1, 传其他返回错误
  16.      *  @param pcm_data: pcm数据, 需要使用ByteBuffer.allocateDirect分配, ByteBuffer.isDirect()是true的才行.
  17.      *  @param offset: pcmdata的偏移
  18.      *  @param size: pcm数据大小
  19.      *  @param sample_rate: 采样率,当前只支持{44100, 8000, 16000, 24000, 32000, 48000}
  20.      *  @param channels: 通道, 当前通道支持单通道(1)和双通道(2)
  21.      *  @param per_channel_sample_number: 这个请传入的是 sample_rate/100
  22.      */
  23.     public native int SmartPublisherOnMixPCMData(long handle, int stream_index, ByteBuffer pcm_data, int offset, int size, int sample_rate, int channels, int per_channel_sample_number);
  24.     /**
  25.      * 传递PCM混音音频数据给SDK, 每10ms音频数据传入一次
  26.      *
  27.      *  @param stream_index: 当前只能传1, 传其他返回错误
  28.      *  @param pcm_short_array: pcm数据, short是native endian order
  29.      *  @param offset: 数组偏移
  30.      *  @param len: 数组项数
  31.      *  @param sample_rate: 采样率,当前只支持{44100, 8000, 16000, 24000, 32000, 48000}
  32.      *  @param channels: 通道, 当前通道支持单通道(1)和双通道(2)
  33.      *  @param per_channel_sample_number: 这个请传入的是 sample_rate/100
  34.      */
  35.     public native int SmartPublisherOnMixPCMShortArray(long handle, int stream_index, short[] pcm_short_array, int offset, int len, int sample_rate, int channels, int per_channel_sample_number);

25. H264扩展SEI消息:

  1. /**
  2. * 设置发送队列大小,为保证实时性,默认大小为3, 必须设置一个大于0的数
  3. *
  4. * @param max_size: 队列最大长度
  5. *
  6. * @param reserve: 保留字段
  7. *
  8. * NOTE: 1. 如果数据超过队列大小,将丢掉队头数据; 2. 这个接口请在 StartPublisher 之前调用
  9. *
  10. * @return {0} if successful
  11. */
  12. public native int SmartPublisherSetPostUserDataQueueMaxSize(long handle, int max_size, int reserve);
  13. /**
  14. * 清空用户数据队列, 有些情况可能会用到,比如发送队列里面有4条消息再等待发送,又想把最新的消息快速发出去, 可以先清除掉正在排队消息, 再调用PostUserXXX
  15. *
  16. * @return {0} if successful
  17. */
  18. public native int SmartPublisherClearPostUserDataQueue(long handle);
  19. /**
  20. * 发送二进制数据
  21. *
  22. * NOTE:
  23. * 1.目前数据大小限制在256个字节以内,太大可能会影响视频传输,如果有特殊需求,需要增大限制,请联系我们
  24. * 2. 如果积累的数据超过了设置的队列大小,之前的队头数据将被丢弃
  25. * 3. 必须再调用StartPublisher之后再发送数据
  26. *
  27. * @param data: 二进制数据
  28. *
  29. * @param size: 数据大小
  30. *
  31. * @param reserve: 保留字段
  32. *
  33. * @return {0} if successful
  34. */
  35. public native int SmartPublisherPostUserData(long handle, byte[] data, int size, int reserve);
  36. /**
  37. * 发送utf8字符串
  38. *
  39. * NOTE:
  40. * 1. 字符串长度不能超过256, 太大可能会影响视频传输,如果有特殊需求,需要增大限制,请联系我们
  41. * 2. 如果积累的数据超过了设置的队列大小,之前的队头数据将被丢弃
  42. * 3. 必须再调用StartPublisher之后再发送数据
  43. *
  44. * @param utf8_str: utf8字符串
  45. *
  46. * @param reserve: 保留字段
  47. *
  48. * @return {0} if successful
  49. */
  50. public native int SmartPublisherPostUserUTF8StringData(long handle, String utf8_str, int reserve);

26. 关闭推送实例:

  1. /**
  2. * 关闭推送实例,结束时必须调用close接口释放资源
  3. *
  4. * @return {0} if successful
  5. */
  6. public native int SmartPublisherClose(long handle);

Android平台摄像头/屏幕/外部数据采集及RTMP推送接口设计描述的更多相关文章

  1. Windows平台摄像头或屏幕RTMP推送介绍:OBS VS SmartPublisher

    好多开发者问道,既然有了OBS,你们为什么还要开发SmartPublisher? 的确,在我们进行Windows平台RTMP推送模块开发之前,市面上为数不多的Windows平台RTMP推流工具当属OB ...

  2. Android同屏、摄像头RTMP推送常用的数据接口设计探讨

    前言 好多开发者在调用Android平台RTMP推送或轻量级RTSP服务接口时,采集到的video数据类型多样化,如420sp.I420.yv12.nv21.rgb的,还有的拿到的图像是倒置的,如果开 ...

  3. 最简单的基于Flash的流媒体示例:RTMP推送和接收(ActionScript)

    ===================================================== Flash流媒体文章列表: 最简单的基于Flash的流媒体示例:RTMP推送和接收(Acti ...

  4. EasyRTMP推送扩展支持HEVC(H265) RTMP推送之Metadata结构填写详解

    我们在<EasyNVR摄像机网页直播中,推流组件EasyRTMP推送RTMP扩展支持HEVC(H.265)的方案>中描述了关于EasyRTMP进行RTMP HEVC(H.265)推流的概括 ...

  5. javaCV开发详解之6:本地音频(话筒设备)和视频(摄像头)抓取、混合并推送(录制)到服务器(本地)

    javaCV系列文章: javacv开发详解之1:调用本机摄像头视频 javaCV开发详解之2:推流器实现,推本地摄像头视频到流媒体服务器以及摄像头录制视频功能实现(基于javaCV-FFMPEG.j ...

  6. android系统和ios系统是如何实现推送的,ios为什么没有后台推送

    ios系统为什么没有后台推送? iOS 为了真正地为用户体验负责,不允许应用在后台活动.有了这个限制,但是对于终端设备,应用又是有必要“通知”到达用户的,随时与用户主动沟通起来的(典型的如聊天应用). ...

  7. 解决RTMP推送时间戳问题引起HLS切片不均匀导致手机浏览器播放卡顿的问题

    本文转自EasyDarwin开源团队成员Kim的博客:http://blog.csdn.net/jinlong0603/article/details/74161115 引言 最近在测试EasyNVR ...

  8. EasyRTMP实现对接海康、大华等IPCamera SDK进行RTMP推送直播功能

    本文转自EasyDarwin团队Kim的博客:http://blog.csdn.net/jinlong0603 Demo项目介绍 EasyRTMP Demo代码下载地址https://github.c ...

  9. EasyRTMP实现Demux解析MP4文件进行rtmp推送实现RTMP直播功能

    本文转自EasyDarwin团队Kim的博客:http://blog.csdn.net/jinlong0603/article/details/52965101 前面已经介绍过EasyRTMP,这里不 ...

随机推荐

  1. 教你用VS code 生成vue-cli代码片段

    可以自定义设置名字:name.json { "Print to console": { "prefix": "vue", "bod ...

  2. RPA应用场景-海关报关

    场景概述海关报关 所涉系统名称海关页面,业务核心系统 人工操作(时间/次) 10 分钟 所涉人工数量 3 操作频率实时 场景流程 1.每日接收报关申请邮件: 2.根据邮件信息进入业务核心系统查询相关数 ...

  3. Python实现简繁体转换,真的玩得花

    大家好鸭, 我是小熊猫 直接开搞!!! 1.opencc-python 首先介绍opencc中的Python实现库,它具有安装简单,翻译准确,使用方便等优点.对于我们日常的需求完全能够胜任. 1.1安 ...

  4. js导入excel&导出excel

    Excel导入 html代码 <button style={{ color: '#1890ff', fontSize: '14px', cursor: 'pointer' }} onClick= ...

  5. gnet: 一个轻量级且高性能的 Go 网络框架 使用笔记

    一个偶然的机会接触到了golang,被它的高并发传说所吸引,就开始学这门语言,越学感觉越有意思^_^ 注册了博客园这么多年,第一次写东西,年纪大了,脑子不好使了,就得写下来,记下来,为了自己以后查阅, ...

  6. 基于单层决策树的AdaBoost算法原理+python实现

    这里整理一下实验课实现的基于单层决策树的弱分类器的AdaBoost算法. 由于是初学,实验课在找资料的时候看到别人的代码中有太多英文的缩写,不容易看懂,而且还要同时看代码实现的细节.算法的原理什么的, ...

  7. centos7 netstat command not found

    只需要执行: yum install net-tools 就ok.

  8. [javaweb]javaweb中HttpServletResponse实现文件下载,验证码和请求重定向功能

    HttpServletResponse web服务器接受到客户端的http请求之后,针对这个请求,分别创建一个代表请求的httpServletRequest和代表响应的HttpServletRespo ...

  9. 关于 CMS 垃圾回收器,你真的懂了吗?

    大家好,我是树哥. 前段时间有个小伙伴去面试,被问到了 CMS 垃圾回收器的详细内容,没答出来.实际上,CMS 垃圾回收器是回收器历史上很重要的一个节点,其开启了 GC 回收器关注 GC 停顿时间的历 ...

  10. Calendar类介绍_获取对象的方式和Calendar类的常用成员方式

    java.util.Calendar是日历类,在Date后出现,替换掉了许多Date方法.该类将所有可能用到的时间信息封装为静态成员变量,方便获取.日历类就是方便获取各个时间属性的. Calendar ...