Skip to content

Commit e65d312

Browse files
committed
更新gvoice库版本,以及修改调用。
Change-Id: Ia00d39663662dfa9f88dfaeb4f251a8dccafaf7d
1 parent bb8a7b0 commit e65d312

File tree

9 files changed

+308
-201
lines changed

9 files changed

+308
-201
lines changed

build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ buildscript {
1010
dependencies {
1111
classpath 'com.android.tools.build:gradle:3.6.3'
1212
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
13+
classpath 'com.github.kezong:fat-aar:1.3.8'
1314
// NOTE: Do not place your application dependencies here; they belong
1415
// in the individual module build.gradle files
1516
}

explorer/device-android-demo/src/main/java/com/tencent/iot/explorer/device/video/call/RecordVideoActivity.java

Lines changed: 21 additions & 165 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
3737

3838
import com.alibaba.fastjson.JSON;
39-
//import com.iot.gvoice.interfaces.GvoiceJNIBridge;
4039
import com.tencent.iot.explorer.device.android.app.R;
4140
import com.tencent.iot.explorer.device.android.app.utils.CommonUtils;
4241
import com.tencent.iot.explorer.device.common.stateflow.entity.CallingType;
@@ -49,7 +48,6 @@
4948
import com.tencent.iot.explorer.device.video.recorder.encoder.AudioEncoder;
5049
import com.tencent.iot.explorer.device.video.recorder.encoder.VideoEncoder;
5150
import com.tencent.iot.explorer.device.video.recorder.listener.OnEncodeListener;
52-
import com.tencent.iot.explorer.device.video.recorder.listener.OnReadAECProcessedPcmListener;
5351
import com.tencent.iot.explorer.device.video.recorder.param.AudioEncodeParam;
5452
import com.tencent.iot.explorer.device.video.recorder.param.MicParam;
5553
import com.tencent.iot.explorer.device.video.recorder.param.VideoEncodeParam;
@@ -79,7 +77,8 @@
7977
import static com.tencent.iot.explorer.device.android.utils.ConvertUtils.byte2HexOnlyLatest8;
8078
import static com.tencent.iot.explorer.device.video.recorder.consts.LogConst.RTC_TAG;
8179

82-
public class RecordVideoActivity extends AppCompatActivity implements TextureView.SurfaceTextureListener, OnEncodeListener, SurfaceHolder.Callback {
80+
public class RecordVideoActivity extends AppCompatActivity implements TextureView.SurfaceTextureListener, OnEncodeListener, SurfaceHolder.Callback,
81+
IMediaPlayer.OnInfoListener {
8382

8483
private static Timer bitRateTimer;
8584
private String TAG = RecordVideoActivity.class.getSimpleName();
@@ -117,14 +116,6 @@ public class RecordVideoActivity extends AppCompatActivity implements TextureVie
117116
private int vh = 240;
118117
private int frameRate = 15;
119118

120-
private LinkedBlockingDeque<Byte> playPcmData = new LinkedBlockingDeque<>(); // 内存队列,用于缓存获取到的播放器音频pcm
121-
private String audioCacheFilePath = Environment.getExternalStorageDirectory().getAbsolutePath()+ "/audio1_cache_file";
122-
private Handler writeHandler;
123-
private final int MESSAGE_AUDIO_ENCODE_FROM_BYTE = 3000;
124-
private FileOutputStream fos1;
125-
private FileOutputStream fos2;
126-
private FileOutputStream fos3;
127-
128119
@Override
129120
protected void onCreate(@Nullable Bundle savedInstanceState) {
130121
super.onCreate(savedInstanceState);
@@ -187,97 +178,33 @@ private void initAudioEncoder() {
187178
.setAudioFormat(AudioFormat.ENCODING_PCM_16BIT) // PCM
188179
.build();
189180
AudioEncodeParam audioEncodeParam = new AudioEncodeParam.Builder().build();
190-
audioEncoder = new AudioEncoder(micParam, audioEncodeParam, processedPcmListener);
181+
audioEncoder = new AudioEncoder(this, micParam, audioEncodeParam, true, true);
191182
audioEncoder.setOnEncodeListener(this);
192183
}
193184

194-
private OnReadAECProcessedPcmListener processedPcmListener = new OnReadAECProcessedPcmListener() {
195-
@Override
196-
public byte[] onReadAECProcessedPcmListener(byte[] micPcmBytes) {
197-
// byte[] playerPcmBytes = onReadPlayerPlayPcm(micPcmBytes.length);
198-
// byte[] cancell = new byte[micPcmBytes.length];
199-
// for (int i = 0; i<4; i++) {
200-
// byte[] tempAudioR = new byte[640];
201-
// byte[] tempPlayer = new byte[640];
202-
// System.arraycopy(micPcmBytes, i*640, tempAudioR, 0, 640);
203-
// System.arraycopy(playerPcmBytes, i*640, tempPlayer, 0, 640);
204-
// byte[] tempC = GvoiceJNIBridge.cancellation(tempAudioR, tempPlayer);
205-
// System.arraycopy(tempC, 0, cancell, i*640, 640);
206-
// }
207-
//
208-
// if (writeHandler != null) {
209-
// JSONObject jsonObject = new JSONObject();
210-
// try {
211-
// jsonObject.put("micBytesData", micPcmBytes);
212-
// jsonObject.put("playerBytesData", playerPcmBytes);
213-
// jsonObject.put("cancellBytesData", cancell);
214-
// } catch (JSONException e) {
215-
// e.printStackTrace();
216-
// }
217-
// Message message = writeHandler.obtainMessage(MESSAGE_AUDIO_ENCODE_FROM_BYTE, jsonObject);
218-
// message.arg1 = micPcmBytes.length;
219-
// writeHandler.sendMessage(message);
220-
// }
221-
// return cancell;
222-
return micPcmBytes;
223-
}
224-
225-
@Override
226-
public void audioCodecRelease() {
227-
// GvoiceJNIBridge.destory();
228-
// playPcmData.clear();
229-
}
230-
};
231-
232-
private byte[] onReadPlayerPlayPcm(int length) {
233-
if (player != null && player.isPlaying()) {
234-
byte[] data = new byte[204800];
235-
int len = player._getPcmData(data);
236-
if (playPcmData.size() > 8*length) {
237-
if (len > 6*length) {
238-
len = 6*length;
239-
} else if (len == 0) {
240-
} else {
241-
int temp = playPcmData.size() - (6*length - len);
242-
for (int i = 0 ; i < temp ; i++) {
243-
playPcmData.remove();
244-
}
245-
}
246-
} else if (len > 8*length) {
247-
len = 6*length;
248-
}
249-
if (len > 0) {
250-
byte[] playerBytes = new byte[len];
251-
System.arraycopy(data, 0, playerBytes, 0, len);
252-
List<Byte> tmpList = new ArrayList<>();
253-
for (byte b : playerBytes){
254-
tmpList.add(b);
255-
}
256-
playPcmData.addAll(tmpList);
257-
}
258-
if (playPcmData.size() > length) {
259-
byte[] res = new byte[length];
260-
try {
261-
for (int i = 0 ; i < length ; i++) {
262-
res[i] = playPcmData.take();
263-
}
264-
} catch (InterruptedException e) {
265-
e.printStackTrace();
266-
}
267-
return res;
268-
} else {
269-
return new byte[length];
270-
}
271-
}
272-
return new byte[length];
273-
}
274-
275185
private void initVideoEncoder() {
276186
VideoEncodeParam videoEncodeParam = new VideoEncodeParam.Builder().setSize(vw, vh).setFrameRate(frameRate).setBitRate(vw*vh).build();
277187
videoEncoder = new VideoEncoder(videoEncodeParam);
278188
videoEncoder.setEncoderListener(this);
279189
}
280190

191+
@Override
192+
public boolean onInfo(IMediaPlayer mp, int what, int extra) {
193+
return false;
194+
}
195+
196+
@Override
197+
public boolean onInfoSEI(IMediaPlayer mp, int what, int extra, String sei_content) {
198+
return false;
199+
}
200+
201+
@Override
202+
public void onInfoAudioPcmData(IMediaPlayer mp, byte[] arrPcm, int length) {
203+
if (audioEncoder != null && length > 0) {
204+
audioEncoder.setPlayerPcmData(arrPcm);
205+
}
206+
}
207+
281208

282209
public class AdapterBitRateTask extends TimerTask {
283210
@Override
@@ -335,11 +262,7 @@ private void startRecord() {
335262
if (phoneInfo.getCallType() == CallingType.TYPE_VIDEO_CALL) {
336263
startEncodeVideo = true;
337264
}
338-
if (!TextUtils.isEmpty(audioCacheFilePath)) {
339-
new WriteThread().start();
340-
}
341265
audioEncoder.start();
342-
// GvoiceJNIBridge.init();
343266

344267
startBitRateAdapter();
345268
}
@@ -400,7 +323,6 @@ private void releasePlayer() {
400323
if (player.isPlaying()) {
401324
player.stop();
402325
}
403-
player._setApmStatus(false);
404326
player.release();
405327
}
406328
}
@@ -443,6 +365,7 @@ private void play() {
443365
}
444366
player = new IjkMediaPlayer();
445367
player.reset();
368+
player.setOnInfoListener(this);
446369
mHandler.sendEmptyMessageDelayed(MSG_UPDATE_HUD, 500);
447370
/*
448371
* probesize & analyzeduration 可通过这两个参数进行首开延时优化
@@ -470,7 +393,6 @@ private void play() {
470393
player.setMaxPacketNum(2);
471394
player.setSurface(this.surface);
472395
player.setAndroidIOCallback(ReadByteIO.Companion.getInstance());
473-
player._setApmStatus(true);
474396
player.setOnErrorListener(new IMediaPlayer.OnErrorListener() {
475397
@Override
476398
public boolean onError(IMediaPlayer mp, int what, int extra) {
@@ -725,70 +647,4 @@ private String getSendStreamStatus() {
725647
return "Unkown";
726648
}
727649

728-
class WriteThread extends Thread {
729-
@SuppressLint("HandlerLeak")
730-
@Override
731-
public void run() {
732-
super.run();
733-
Looper.prepare();
734-
File file1 = new File(audioCacheFilePath+"_file1.pcm");
735-
File file2 = new File(audioCacheFilePath+"_file2.pcm");
736-
File file3 = new File(audioCacheFilePath+"_file3.pcm");
737-
Log.i(TAG, "audio cache pcm file path:" + audioCacheFilePath);
738-
if (file1.exists()) {
739-
file1.delete();
740-
}
741-
if (file2.exists()) {
742-
file2.delete();
743-
}
744-
if (file3.exists()) {
745-
file3.delete();
746-
}
747-
try {
748-
file1.createNewFile();
749-
file2.createNewFile();
750-
file3.createNewFile();
751-
} catch (IOException e) {
752-
e.printStackTrace();
753-
}
754-
try {
755-
fos1 = new FileOutputStream(file1);
756-
fos2 = new FileOutputStream(file2);
757-
fos3 = new FileOutputStream(file3);
758-
} catch (FileNotFoundException e) {
759-
e.printStackTrace();
760-
Log.e(TAG, "临时缓存文件未找到");
761-
}
762-
writeHandler = new Handler() {
763-
@Override
764-
public void handleMessage(Message msg) {
765-
super.handleMessage(msg);
766-
if (msg.what == MESSAGE_AUDIO_ENCODE_FROM_BYTE) {
767-
JSONObject jsonObject = (JSONObject) msg.obj;
768-
if (AudioRecord.ERROR_INVALID_OPERATION != msg.arg1) {
769-
if (fos1 != null && fos2 != null && fos3 != null) {
770-
try {
771-
byte[] micBytesData = (byte[]) jsonObject.get("micBytesData");
772-
byte[] playerBytesData = (byte[]) jsonObject.get("playerBytesData");
773-
byte[] cancellBytesData = (byte[]) jsonObject.get("cancellBytesData");
774-
fos1.write(micBytesData);
775-
fos1.flush();
776-
fos2.write(playerBytesData);
777-
fos2.flush();
778-
fos3.write(cancellBytesData);
779-
fos3.flush();
780-
} catch (IOException e) {
781-
e.printStackTrace();
782-
} catch (JSONException e) {
783-
e.printStackTrace();
784-
}
785-
}
786-
}
787-
}
788-
}
789-
};
790-
Looper.loop();
791-
}
792-
}
793-
794650
}

explorer/device-android-demo/src/main/java/com/tencent/iot/explorer/device/video/device_and_device/RecordVideoActivity3.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ private void initAudioEncoder() {
143143
.setAudioFormat(AudioFormat.ENCODING_PCM_16BIT) // PCM
144144
.build();
145145
AudioEncodeParam audioEncodeParam = new AudioEncodeParam.Builder().build();
146-
audioEncoder = new AudioEncoder(micParam, audioEncodeParam);
146+
audioEncoder = new AudioEncoder(this, micParam, audioEncodeParam);
147147
audioEncoder.setOnEncodeListener(this);
148148
}
149149

explorer/device-android-demo/src/main/java/com/tencent/iot/explorer/device/video/device_and_device/RecordVideoActivity4.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ private void initAudioEncoder() {
237237
.setAudioFormat(AudioFormat.ENCODING_PCM_16BIT) // PCM
238238
.build();
239239
AudioEncodeParam audioEncodeParam = new AudioEncodeParam.Builder().build();
240-
audioEncoder = new AudioEncoder(micParam, audioEncodeParam);
240+
audioEncoder = new AudioEncoder(this, micParam, audioEncodeParam);
241241
audioEncoder.setOnEncodeListener(this);
242242
}
243243

explorer/device-android-demo/src/main/java/com/tencent/iot/explorer/device/video/push_stream/RecordVideoActivity2.java

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,10 @@
5151
import java.util.concurrent.ExecutorService;
5252
import java.util.concurrent.Executors;
5353

54+
import tv.danmaku.ijk.media.player.IMediaPlayer;
5455
import tv.danmaku.ijk.media.player.IjkMediaPlayer;
5556

56-
public class RecordVideoActivity2 extends AppCompatActivity implements TextureView.SurfaceTextureListener, OnEncodeListener, SurfaceHolder.Callback {
57+
public class RecordVideoActivity2 extends AppCompatActivity implements TextureView.SurfaceTextureListener, OnEncodeListener, SurfaceHolder.Callback, IMediaPlayer.OnInfoListener {
5758

5859
private static final String TAG = RecordVideoActivity2.class.getSimpleName();
5960
private static final int MAX_CONNECT_NUM = 4;
@@ -131,20 +132,21 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
131132
}
132133
initAudioEncoder();
133134
initVideoEncoder();
134-
VideoFormat format = new VideoFormat.Builder().setVideoWidth(vw).setVideoHeight(vh).build();
135+
VideoFormat format = new VideoFormat.Builder().setVideoWidth(vw).setVideoHeight(vh).setAudioSampleRate(16000).build();
135136
VideoNativeInteface.getInstance().initVideoFormat(format);
136137
}
137138

138139
private void initAudioEncoder() {
139140
MicParam micParam = new MicParam.Builder()
140141
.setAudioSource(MediaRecorder.AudioSource.MIC)
141-
.setSampleRateInHz(8000) // 采样率
142+
.setSampleRateInHz(16000) // 采样率
142143
.setChannelConfig(AudioFormat.CHANNEL_IN_MONO)
143144
.setAudioFormat(AudioFormat.ENCODING_PCM_16BIT) // PCM
144145
.build();
145146
AudioEncodeParam audioEncodeParam = new AudioEncodeParam.Builder().build();
146-
audioEncoder = new AudioEncoder(micParam, audioEncodeParam);
147+
audioEncoder = new AudioEncoder(this, micParam, audioEncodeParam, true, true);
147148
audioEncoder.setOnEncodeListener(this);
149+
audioEncoder.recordPcmFile(true);
148150
}
149151

150152
private void initVideoEncoder() {
@@ -253,6 +255,7 @@ public void onSurfaceTextureUpdated(SurfaceTexture surface) { }
253255
private void play() {
254256
player = new IjkMediaPlayer();
255257
player.reset();
258+
player.setOnInfoListener(this);
256259
if (phoneInfo.getCallType() == CallingType.TYPE_AUDIO_CALL) {
257260
player.setOption(IjkMediaPlayer.OPT_CATEGORY_FORMAT, "analyzeduration", 1000);
258261
player.setOption(IjkMediaPlayer.OPT_CATEGORY_FORMAT, "probesize", 64);
@@ -419,5 +422,22 @@ public void surfaceChanged(SurfaceHolder surfaceHolder, int i, int i1, int i2) {
419422
public void surfaceDestroyed(SurfaceHolder surfaceHolder) {
420423
Log.d(TAG, "surface destroyed.");
421424
}
425+
426+
@Override
427+
public boolean onInfo(IMediaPlayer mp, int what, int extra) {
428+
return false;
429+
}
430+
431+
@Override
432+
public boolean onInfoSEI(IMediaPlayer mp, int what, int extra, String sei_content) {
433+
return false;
434+
}
435+
436+
@Override
437+
public void onInfoAudioPcmData(IMediaPlayer mp, byte[] arrPcm, int length) {
438+
if (audioEncoder != null && length > 0) {
439+
audioEncoder.setPlayerPcmData(arrPcm);
440+
}
441+
}
422442
}
423443

explorer/explorer-device-video/build.gradle

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ apply plugin: 'signing'
44

55
apply plugin: 'kotlin-android'
66
apply plugin: 'kotlin-android-extensions'
7+
apply plugin: 'com.kezong.fat-aar'
78

89
android {
910
compileSdkVersion 29
@@ -39,23 +40,26 @@ android {
3940
lintOptions {
4041
abortOnError false
4142
}
43+
repositories {
44+
flatDir { dirs 'libs' }
45+
}
4246
}
4347

4448
repositories {
4549
maven { url "https://oss.sonatype.org/content/repositories/snapshots" }
4650
}
4751

4852
dependencies {
49-
api fileTree(include: ['*.jar', '*.aar'], dir: 'libs')
53+
embed (name:'android_gvoice-release',ext:'aar')
5054
testImplementation 'junit:junit:4.+'
5155
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
5256
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
5357
implementation 'com.alibaba:fastjson:1.2.73'
5458
api 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.4'
5559
api 'com.tencent.iot.thirdparty.android:xp2p-sdk:2.4.35'
56-
api 'com.tencent.iot.thirdparty.android:ijkplayer-java:2.0.7'
57-
api 'com.tencent.iot.thirdparty.android:ijkplayer-armv7a:2.0.7'
58-
api 'com.tencent.iot.thirdparty.android:ijkplayer-arm64:2.0.7'
60+
api 'com.tencent.iot.thirdparty.android:ijkplayer-java:2.0.14'
61+
api 'com.tencent.iot.thirdparty.android:ijkplayer-armv7a:2.0.14'
62+
api 'com.tencent.iot.thirdparty.android:ijkplayer-arm64:2.0.14'
5963
api project(':explorer:explorer-media-common')
6064
//xxxapi project(':explorer:explorer//xxx-media-common')
6165
if (findProject(':explorer:explorer-device-android') != null) {
6.03 MB
Binary file not shown.

0 commit comments

Comments
 (0)