Skip to content

Commit

Permalink
更新gvoice的sdk,以及更改播放器回调pcm数据方式。
Browse files Browse the repository at this point in the history
Change-Id: I8abd890bf15e7be9d9d4d2d0eb905d109be3f7fb
  • Loading branch information
SundoggyNew committed Apr 3, 2024
1 parent 4976ee0 commit 29bc587
Show file tree
Hide file tree
Showing 9 changed files with 57 additions and 59 deletions.
Binary file modified sdk/video-link-android/libs/android_gvoice-release.aar
Binary file not shown.
1 change: 1 addition & 0 deletions sdk/video-link-android/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.tencent.iot.video.link">
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public class AudioRecordUtil implements EncoderListener, FLVListener, Handler.Ca
private static final String TAG = AudioRecordUtil.class.getName();
private static final int MSG_START = 1;
private static final int MSG_STOP = 2;
private static final int MSG_ENCODE = 3;
private static final int MSG_REC_PLAY_PCM = 3;
private static final int MSG_RELEASE = 4;
private final HandlerThread readThread;
private final ReadHandler mReadHandler;
Expand Down Expand Up @@ -81,7 +81,6 @@ public class AudioRecordUtil implements EncoderListener, FLVListener, Handler.Ca
private static final int SAVE_PCM_DATA = 1;

private LinkedBlockingDeque<Byte> playPcmData = new LinkedBlockingDeque<>(); // 内存队列,用于缓存获取到的播放器音频pcm
private AudioRecordUtilListener audioRecordUtilListener = null;

@Override
public boolean handleMessage(@NotNull Message msg) {
Expand All @@ -92,8 +91,8 @@ public boolean handleMessage(@NotNull Message msg) {
case MSG_STOP:
stopInternal();
break;
case MSG_ENCODE:
// renderInternal((TRTCCloudDef.TRTCVideoFrame) msg.obj);
case MSG_REC_PLAY_PCM:
recPlayPcmInternal((byte[]) msg.obj);
break;
case MSG_RELEASE:
releaseInternal();
Expand Down Expand Up @@ -182,18 +181,6 @@ public AudioRecordUtil(Context ctx, String id, int sampleRate, int channel, int
readThread.start();
mReadHandler = new ReadHandler(readThread.getLooper(), this);
}
public AudioRecordUtil(Context ctx, String id, int sampleRate, int channel, int bitDepth, int pitch, AudioRecordUtilListener audioRecordUtilListener) {
context = ctx;
deviceId = id;
this.pitch = pitch;
this.enableAEC = true;
this.enableAGC = true;
this.audioRecordUtilListener = audioRecordUtilListener;
init(sampleRate, channel, bitDepth);
readThread = new HandlerThread(TAG);
readThread.start();
mReadHandler = new ReadHandler(readThread.getLooper(), this);
}

private void init(int sampleRate, int channel, int bitDepth) {
recordMinBufferSize = AudioRecord.getMinBufferSize(sampleRate, channel, bitDepth);
Expand All @@ -214,6 +201,7 @@ private void init(int sampleRate, int channel, int bitDepth) {
recordMinBufferSize = (sampleRate*this.channelCount*this.encodeBit/8)/1000*20; //20ms数据长度
Log.e(TAG, "20ms recordMinBufferSize is: "+ recordMinBufferSize);
Log.e(TAG, "AudioRecordUtil init Pitch is: "+ pitch);
GvoiceJNIBridge.init(context);
}

public void recordSpeakFlv(boolean isRecord) {
Expand Down Expand Up @@ -282,6 +270,10 @@ public void setMode(VoiceChangerMode mode) {
}
}

public void setPlayerPcmData(byte[] pcmData) {
mReadHandler.obtainMessage(MSG_REC_PLAY_PCM, pcmData).sendToTarget();
}

/**
* 开始录制
*/
Expand All @@ -299,7 +291,6 @@ private void startInternal() {
if (!playPcmData.isEmpty()) {
playPcmData.clear();
}
GvoiceJNIBridge.init();
reset();
if (!VoiceChangerJNIBridge.isAvailable()) {
if (st == null && pitch != 0) {
Expand All @@ -313,9 +304,6 @@ private void startInternal() {
Log.e(TAG, "turn recorderState : " + recorderState);
audioRecord.startRecording();
new RecordThread().start();
if (audioRecordUtilListener != null) {
new WriteThread().start();
}
}

private void reset() {
Expand Down Expand Up @@ -459,8 +447,8 @@ public void run() {
if (AudioRecord.ERROR_INVALID_OPERATION != read) {
//获取到的pcm数据就是buffer了
if (buffer != null && pcmEncoder != null) {
if (audioRecordUtilListener != null) {
byte [] playerPcmBytes = onReadPlayerPlayPcm(buffer.length);
byte [] playerPcmBytes = onReadPlayerPlayPcm(buffer.length);
if (playerPcmBytes != null && playerPcmBytes.length > 0) {
byte[] aecPcmBytes = GvoiceJNIBridge.cancellation(buffer, playerPcmBytes);
if (isRecord) {
writePcmBytesToFile(buffer, playerPcmBytes, aecPcmBytes);
Expand Down Expand Up @@ -536,22 +524,13 @@ private byte[] onReadPlayerPlayPcm(int length) {
}
}

private class WriteThread extends Thread {
@Override
public void run() {
while (recorderState) {
if (audioRecordUtilListener != null) {
byte[] data = audioRecordUtilListener.onReadPlayerPcmByte();
if (data != null && data.length > 0) {
Log.e(TAG, "data.length: " + data.length + " , recorderState : " + recorderState);
List<Byte> tmpList = new ArrayList<>();
for (byte b : data) {
tmpList.add(b);
}
playPcmData.addAll(tmpList);
}
}
private void recPlayPcmInternal(byte [] pcmData) {
if (pcmData != null && pcmData.length > 0 && recorderState) {
List<Byte> tmpList = new ArrayList<>();
for (byte b : pcmData) {
tmpList.add(b);
}
playPcmData.addAll(tmpList);
}
}

Expand Down

This file was deleted.

8 changes: 4 additions & 4 deletions sdkdemo/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ android {
}
}
ndk {
abiFilters 'armeabi-v7a'
abiFilters 'arm64-v8a', 'armeabi-v7a'
}
}
lintOptions {
Expand Down Expand Up @@ -139,9 +139,9 @@ dependencies {

// implementation 'com.tencent.iot.thirdparty.android:ijkplayer-java:1.0.7'
// implementation 'com.tencent.iot.thirdparty.android:ijkplayer-armv7a:1.0.7'
api 'com.tencent.iot.thirdparty.android:ijkplayer-java:2.0.12'
api 'com.tencent.iot.thirdparty.android:ijkplayer-armv7a:2.0.12'
api 'com.tencent.iot.thirdparty.android:ijkplayer-arm64:2.0.12'
implementation 'com.tencent.iot.thirdparty.android:ijkplayer-java:2.0.14'
implementation 'com.tencent.iot.thirdparty.android:ijkplayer-armv7a:2.0.14'
implementation 'com.tencent.iot.thirdparty.android:ijkplayer-arm64:2.0.14'

implementation 'cn.aigestudio.wheelpicker:WheelPicker:1.1.3'
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.7-mpp-dev-11'
Expand Down
1 change: 1 addition & 0 deletions sdkdemo/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<uses-permission android:name="android.permission.RECORD_AUDIO" /> <!-- 往SDCard写入数据权限 -->
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />

<application
android:name=".App"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,11 @@ class VideoCloudPlaybackFragment: VideoPlaybackBaseFragment(), TextureView.Surfa
): Boolean {
return false
}

override fun onInfoAudioPcmData(mp: IMediaPlayer?, arrPcm: ByteArray?, length: Int) {

}

}

override fun onDestroy() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,10 @@ class VideoLocalPlaybackFragment : VideoPlaybackBaseFragment(), TextureView.Surf
): Boolean {
return false
}

override fun onInfoAudioPcmData(mp: IMediaPlayer?, arrPcm: ByteArray?, length: Int) {

}
}

private var dlgOnClickedListener = object : CalendarDialog.OnClickedListener {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,21 +43,20 @@ import com.tencent.iot.explorer.link.demo.video.utils.VolumeChangeObserver
import com.tencent.iot.video.link.consts.VideoConst
import com.tencent.iot.video.link.entity.DeviceStatus
import com.tencent.iot.video.link.util.audio.AudioRecordUtil
import com.tencent.iot.video.link.util.audio.AudioRecordUtilListener
import com.tencent.xnet.XP2P
import com.tencent.xnet.XP2PCallback
import kotlinx.android.synthetic.main.activity_video_preview.*
import kotlinx.android.synthetic.main.dash_board_layout.*
import kotlinx.android.synthetic.main.fragment_video_cloud_playback.*
import kotlinx.android.synthetic.main.title_layout.*
import kotlinx.coroutines.*
import tv.danmaku.ijk.media.player.IMediaPlayer
import tv.danmaku.ijk.media.player.IjkMediaPlayer
import java.lang.Runnable
import java.lang.ref.WeakReference
import java.util.*
import java.util.concurrent.ConcurrentHashMap
import java.util.concurrent.CountDownLatch
import java.util.concurrent.LinkedBlockingDeque


private var countDownLatchs : MutableMap<String, CountDownLatch> = ConcurrentHashMap()
Expand All @@ -67,7 +66,7 @@ private var keepAliveThreadRuning = true

class VideoPreviewActivity : VideoBaseActivity(), EventView, TextureView.SurfaceTextureListener,
XP2PCallback, CoroutineScope by MainScope(), VolumeChangeObserver.VolumeChangeListener,
AudioRecordUtilListener {
IMediaPlayer.OnInfoListener {

open var tag = VideoPreviewActivity::class.simpleName
var orientationV = true
Expand Down Expand Up @@ -99,6 +98,8 @@ class VideoPreviewActivity : VideoBaseActivity(), EventView, TextureView.Surface
var screenWidth = 0
var screenHeight = 0
var firstIn = true
@Volatile
var speakAble = false

override fun getContentView(): Int {
return R.layout.activity_video_preview
Expand Down Expand Up @@ -171,6 +172,7 @@ class VideoPreviewActivity : VideoBaseActivity(), EventView, TextureView.Surface
open fun startPlayer() {
if (App.data.accessInfo == null || TextUtils.isEmpty(presenter.getDeviceName())) return
player = IjkMediaPlayer()
player.setOnInfoListener(this)
mHandler.sendEmptyMessageDelayed(MSG_UPDATE_HUD, 500)

Thread(Runnable {
Expand Down Expand Up @@ -274,16 +276,19 @@ class VideoPreviewActivity : VideoBaseActivity(), EventView, TextureView.Surface
if (it.size == 1 && it.get(0).status == 0) {
XP2P.runSendService("${accessInfo.productId}/${presenter.getDeviceName()}", Command.getTwoWayRadio(presenter.getChannel()), true)
audioRecordUtil.start()
speakAble = true
return true
}
}

} else {
speakAble = false
audioRecordUtil.stop()
XP2P.stopSendService("${accessInfo.productId}/${presenter.getDeviceName()}", null)
return true
}
}
speakAble = false
return false
}

Expand Down Expand Up @@ -445,6 +450,7 @@ class VideoPreviewActivity : VideoBaseActivity(), EventView, TextureView.Surface
layout_video_preview?.addView(v_preview, 0)

player = IjkMediaPlayer()
player.setOnInfoListener(this@VideoPreviewActivity)
// player._setApmStatus(true)
player?.let {
val url = urlPrefix + suffix
Expand Down Expand Up @@ -738,15 +744,22 @@ class VideoPreviewActivity : VideoBaseActivity(), EventView, TextureView.Surface
tv_video_w_h?.text = "${player.videoWidth} x ${player.videoHeight}"
}

override fun onReadPlayerPcmByte(): ByteArray? {
// val data = ByteArray(10240)
// val len = player._getPcmData(data)
// return if (len > 0) {
// val playerBytes = ByteArray(len)
// System.arraycopy(data, 0, playerBytes, 0, len);
// playerBytes
// } else {
return null
// }
override fun onInfo(mp: IMediaPlayer?, what: Int, extra: Int): Boolean {
return true
}

override fun onInfoSEI(
mp: IMediaPlayer?,
what: Int,
extra: Int,
sei_content: String?
): Boolean {
return false
}

override fun onInfoAudioPcmData(mp: IMediaPlayer?, arrPcm: ByteArray?, length: Int) {
if (audioRecordUtil != null && length > 0 && speakAble) {
audioRecordUtil.setPlayerPcmData(arrPcm);
}
}
}

0 comments on commit 29bc587

Please sign in to comment.