前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Android平台RTSP|RTMP播放器之视音频效果设置

Android平台RTSP|RTMP播放器之视音频效果设置

原创
作者头像
音视频牛哥
发布2024-09-05 17:30:48
1210
发布2024-09-05 17:30:48
举报
文章被收录于专栏:RTSP/RTMP直播相关

​RTSP|RTMP播放器模块是大牛直播SDK的SmartMediaKit下非常优异的子产品,功能丰富、性能优异,毫秒级超低延迟,支持Windows、Linux(x86_64|aarch64架构)、Android、iOS平台。

先看demo主界面,可以通过界面,做基础的设置,比如旋转、镜像等操作。

下面就视音频效果,做个大概的介绍。

视频填充效果:支持按照比例显示,或整体填充,设计到的接口如下:

代码语言:java
复制
/*
 * SmartPlayerJniV2.java
 *
 * Author: daniusdk.com
 * Created by DaniuLive on 2015/09/26.
 * Copyright © 2014~2024 DaniuLive. All rights reserved.
 */

/**
 * 设置视频画面的填充模式,如填充整个view、等比例填充view,如不设置,默认填充整个view
 * @param handle: return value from SmartPlayerOpen()
 * @param render_scale_mode 0: 填充整个view; 1: 等比例填充view, 默认值是0
 * @return {0} if successful
 */
public native int SmartPlayerSetRenderScaleMode(long handle, int render_scale_mode);

旋转:支持0°、90°、180°和270°四个视频画面渲染角度设置:

代码语言:java
复制
/**
 * 设置顺时针旋转, 注意除了0度之外, 其他角度都会额外消耗性能
 *
 * @param handle: return value from SmartPlayerOpen()
 *
 * @param degress: 当前支持 0度,90度, 180度, 270度 旋转
 *
 * @return {0} if successful
 */
public native int SmartPlayerSetRotation(long handle, int degress);

镜像:支持无镜像、水平镜像和垂直镜像三种镜像模式设置:

代码语言:java
复制
/**
 * 设置视频垂直反转
 *
 * @param handle: return value from SmartPlayerOpen()
 *
 * @param is_flip: 0: 不反转, 1: 反转
 *
 * @return {0} if successful
 */
public native int SmartPlayerSetFlipVertical(long handle, int is_flip);

/**
 * 设置视频水平反转
 *
 * @param handle: return value from SmartPlayerOpen()
 *
 * @param is_flip: 0: 不反转, 1: 反转
 *
 * @return {0} if successful
 */
public native int SmartPlayerSetFlipHorizontal(long handle, int is_flip);

渲染模式:支持SurfaceView和TextureView模式,支持设置hardware render模式:

代码语言:java
复制
if (SURFACE_TYPE_SURFACE_VIEW == surface_type_) {
	if (sSurfaceView != null && sSurfaceView instanceof SurfaceView && ((SurfaceView)sSurfaceView).getHolder() != null)
		surface = ((SurfaceView)sSurfaceView).getHolder().getSurface();
}else if (SURFACE_TYPE_TEXTURE_VIEW == surface_type_) {
	if (null == texture_view_surface_) {
		if (sSurfaceView != null && sSurfaceView instanceof TextureView && ((TextureView) sSurfaceView).getSurfaceTexture() != null)
			texture_view_surface_ = new Surface(((TextureView) sSurfaceView).getSurfaceTexture());
	}

	surface = texture_view_surface_;
} 

libPlayer.SetSurface(playerHandle, surface, surface_codec_media_color_format, disable_codec_render_surface_, disable_sdk_render_surface_);
...
if (isHardwareDecoder && is_enable_hardware_render_mode) {
	libPlayer.SmartPlayerSetHWRenderMode(playerHandle, 1);
}

设置播放音量:播放音量可以播放过程中动态调整,或者一开始就静音:

代码语言:java
复制
/**
 * Set mute or not(设置实时静音)
 *
 * @param handle: return value from SmartPlayerOpen()
 *
 * @param is_mute: if with 1:mute, if with 0: does not mute
 *
 * @return {0} if successful
 */
public native int SmartPlayerSetMute(long handle, int is_mute);

/**
 * 设置播放音量
 *
 * @param handle: return value from SmartPlayerOpen()
 *
 * @param volume: 范围是[0, 100], 0是静音,100是最大音量, 默认是100
 *
 * @return {0} if successful
 */
public native int SmartPlayerSetAudioVolume(long handle, int volume);

设置音频输出模式:支持AudioTrack、OpenSL ES模式,一般来说考虑到通用性,建议使用AudioTrack模式。

代码语言:java
复制
/**
 * Set AudioOutput Type(设置audio输出类型)
 *
 * @param handle: return value from SmartPlayerOpen()
 *
 * @param use_audiotrack:
 *
 * <pre> NOTE: if use_audiotrack with 0: it will use auto-select output devices; if with 1: will use audio-track mode. </pre>
 *
 * @return {0} if successful
 */
public native int SmartPlayerSetAudioOutputType(long handle, int use_audiotrack);

总结

目前Android平台的SmartPlayer主要设计的功能如下:

  • 音频:AAC/Speex(RTMP)/PCMA/PCMU;
  • 视频:H.264、H.265;
  • 播放协议:RTSP|RTMP;
  • 支持纯音频、纯视频、音视频播放;
  • 支持多实例播放;
  • 支持软解码,特定机型硬解码;
  • 支持RTSP TCP、UDP模式设置;
  • 支持RTSP TCP、UDP模式自动切换;
  • 支持RTSP超时时间设置,单位:秒;
  • 支持buffer时间设置,单位:毫秒;
  • 支持超低延迟模式;
  • 支持断网自动重连、视频追赶,支持buffer状态等回调;
  • 支持视频view实时旋转(0° 90° 180° 270°);
  • 支持视频view水平反转、垂直反转;
  • 支持Surfaceview/OpenGL ES/TextureView绘制;
  • 支持视频画面填充模式设置;
  • 音频支持AudioTrack、OpenSL ES模式;
  • 支持jpeg、png实时截图;
  • 支持实时音量调节;
  • 支持解码前音视频数据回调;
  • 支持解码后YUV/RGB数据回调;
  • 支持Enhanced RTMP;
  • 支持扩展录像功能;
  • 支持Android 5.1及以上版本。

一个好的RTMP或RTSP播放器,不仅是需要功能完善,还需要有非常优异的性能,特别是多实例播放,资源占有也是考量的一个重要因素,其次,直播特别是和操控相关的场景,都需要极致的低延迟才行,真是应了那句话,做播放器容易,做个好的播放器,真的太难了!以上抛砖引玉,感兴趣的开发者,可以单独跟我沟通探讨。

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 总结
相关产品与服务
媒体分发播放
媒体分发播放(Media distribution and playback)归属于腾讯云点播产品,依托腾讯云全球2800+加速节点,150Tbps+带宽储备,全球70+ 可用区,提供多终端超级播放器、播放质量监控等云端一体的加速分发服务。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档