Skip to content

Commit 98e14b1

Browse files
committed
增加保存aac数据
1 parent 822a917 commit 98e14b1

File tree

2 files changed

+44
-7
lines changed

2 files changed

+44
-7
lines changed

app/src/main/java/com/example/ivdemo/TweCallActivity.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ class TweCallActivity : BaseIPCActivity<ActivityTweCallBinding>(), IvVoipCallbac
201201
val activeDeviceInfo = VideoNativeInterface.getInstance().voipActiveDeviceInfoV2
202202
if (activeDeviceInfo == null || activeDeviceInfo.expireTime < System.currentTimeMillis()/1000) {
203203
val activateRes = VideoNativeInterface.getInstance()
204-
.activateVoipLicenseV2(VoipActivateType.VOIP_ACT_TEST)
204+
.activateVoipLicenseV2(VoipActivateType.VOIP_ACT_IPC)
205205
if (activateRes == 0) {
206206
showToast("检查设备过期,激活结果成功,resCode:$activateRes")
207207
} else {

app/src/main/java/com/tencent/iotvideo/link/CameraRecorder.java

Lines changed: 43 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,14 @@ public class CameraRecorder implements Camera.PreviewCallback, OnEncodeListener
6060
// for test only
6161
private boolean isSaveRecord = false;
6262

63-
private FileOutputStream fos;
63+
private FileOutputStream h264Fos;
64+
65+
private FileOutputStream aacFos;
66+
6467
private String speakH264FilePath = "/sdcard/video.h264";
6568

69+
private String speakAacFilePath = "/sdcard/audio.aac";
70+
6671
private Activity context;
6772

6873
private TextureView previewView;
@@ -236,6 +241,7 @@ public void onAudioEncoded(byte[] datas, long pts, long seq) {
236241
int ret = VideoNativeInterface.getInstance().sendAvtAudioData(datas, pts, seq, visitor, channel, res_type);
237242
if (ret != 0) Log.e(TAG, "sendAudioData to visitor " + visitor + " failed: " + ret);
238243
}
244+
saveAac(datas);
239245
}
240246
}
241247

@@ -293,21 +299,22 @@ private void stopBitRateAdapter() {
293299
}
294300

295301
/**
296-
* 保存h264数据
302+
* 保存音视频数据
297303
*
298304
* @param isSaveRecord
299305
*/
300306
public void isSaveRecord(boolean isSaveRecord) {
301307
this.isSaveRecord = isSaveRecord;
302308
recordSpeakH264(isSaveRecord);
309+
recordSpeakAac(isSaveRecord);
303310
}
304311

305312
public void recordSpeakH264(boolean isRecord) {
306313
if (isRecord) {
307314
if (!TextUtils.isEmpty(speakH264FilePath)) {
308315
try {
309316
File file = UtilsKt.getFile(speakH264FilePath);
310-
fos = new FileOutputStream(file);
317+
h264Fos = new FileOutputStream(file);
311318
} catch (Exception e) {
312319
e.printStackTrace();
313320
Log.e(TAG, speakH264FilePath + "临时缓存文件未找到");
@@ -316,14 +323,44 @@ public void recordSpeakH264(boolean isRecord) {
316323
}
317324
}
318325

326+
public void recordSpeakAac(boolean isRecord) {
327+
if (isRecord) {
328+
if (!TextUtils.isEmpty(speakAacFilePath)) {
329+
try {
330+
File file = UtilsKt.getFile(speakAacFilePath);
331+
aacFos = new FileOutputStream(file);
332+
} catch (Exception e) {
333+
e.printStackTrace();
334+
Log.e(TAG, speakAacFilePath + "临时缓存文件未找到");
335+
}
336+
}
337+
}
338+
}
339+
319340
public void saveH264(byte[] datas) {
320341
if (isSaveRecord) {
321342
if (executor.isShutdown()) return;
322343
executor.submit(() -> {
323-
if (fos != null) {
344+
if (h264Fos != null) {
345+
try {
346+
h264Fos.write(datas);
347+
h264Fos.flush();
348+
} catch (IOException e) {
349+
e.printStackTrace();
350+
}
351+
}
352+
});
353+
}
354+
}
355+
356+
public void saveAac(byte[] datas) {
357+
if (isSaveRecord) {
358+
if (executor.isShutdown()) return;
359+
executor.submit(() -> {
360+
if (aacFos != null) {
324361
try {
325-
fos.write(datas);
326-
fos.flush();
362+
aacFos.write(datas);
363+
aacFos.flush();
327364
} catch (IOException e) {
328365
e.printStackTrace();
329366
}

0 commit comments

Comments
 (0)