@@ -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