jimu-decompiled/sources/com/hw/videoprocessor/util/AudioUtil.java
2025-05-13 19:24:51 +02:00

123 lines
6.1 KiB
Java

package com.hw.videoprocessor.util;
import android.media.MediaCodec;
import android.media.MediaExtractor;
import android.media.MediaFormat;
import android.media.MediaMuxer;
import com.hw.videoprocessor.VideoUtil;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.util.HashMap;
import java.util.Map;
/* loaded from: classes.dex */
public class AudioUtil {
private static final Map<Integer, Integer> a = new HashMap();
static {
a.put(96000, 0);
a.put(88200, 1);
a.put(64000, 2);
a.put(48000, 3);
a.put(44100, 4);
a.put(32000, 5);
a.put(24000, 6);
a.put(22050, 7);
a.put(16000, 8);
a.put(12000, 9);
a.put(11025, 10);
a.put(8000, 11);
a.put(7350, 12);
}
public static long a(MediaExtractor mediaExtractor, MediaMuxer mediaMuxer, int i, Integer num, Integer num2, VideoProgressListener videoProgressListener) throws IOException {
return a(mediaExtractor, mediaMuxer, i, num, num2, 0L, videoProgressListener);
}
public static int b(MediaFormat mediaFormat) {
if (mediaFormat.containsKey("max-input-size")) {
return mediaFormat.getInteger("max-input-size");
}
return 100000;
}
public static long a(MediaExtractor mediaExtractor, MediaMuxer mediaMuxer, int i, Integer num, Integer num2, long j, VideoProgressListener videoProgressListener) throws IOException {
int a2 = VideoUtil.a(mediaExtractor, true);
mediaExtractor.selectTrack(a2);
Integer num3 = num == null ? 0 : num;
mediaExtractor.seekTo(num3.intValue(), 2);
MediaFormat trackFormat = mediaExtractor.getTrackFormat(a2);
long j2 = trackFormat.getLong("durationUs");
ByteBuffer allocateDirect = ByteBuffer.allocateDirect(trackFormat.getInteger("max-input-size"));
MediaCodec.BufferInfo bufferInfo = new MediaCodec.BufferInfo();
long j3 = j;
while (true) {
long sampleTime = mediaExtractor.getSampleTime();
if (sampleTime == -1) {
break;
}
if (sampleTime >= num3.intValue()) {
if (num2 != null && sampleTime > num2.intValue()) {
break;
}
if (videoProgressListener != null) {
float intValue = (sampleTime - num3.intValue()) / (num2 == null ? j2 : num2.intValue() - num3.intValue());
if (intValue < 0.0f) {
intValue = 0.0f;
}
if (intValue > 1.0f) {
intValue = 1.0f;
}
videoProgressListener.onProgress(intValue);
}
bufferInfo.presentationTimeUs = (sampleTime - num3.intValue()) + j;
bufferInfo.flags = mediaExtractor.getSampleFlags();
bufferInfo.size = mediaExtractor.readSampleData(allocateDirect, 0);
if (bufferInfo.size < 0) {
break;
}
CL.c("writeAudioSampleData,time:" + (bufferInfo.presentationTimeUs / 1000.0f), new Object[0]);
mediaMuxer.writeSampleData(i, allocateDirect, bufferInfo);
long j4 = bufferInfo.presentationTimeUs;
mediaExtractor.advance();
j3 = j4;
} else {
mediaExtractor.advance();
}
}
return j3;
}
/* JADX WARN: Removed duplicated region for block: B:11:0x0126 A[Catch: all -> 0x011a, TryCatch #3 {all -> 0x011a, blocks: (B:45:0x0084, B:47:0x008a, B:52:0x00b9, B:11:0x0126, B:36:0x0134, B:33:0x0150, B:18:0x0166, B:21:0x01b3, B:24:0x016f, B:26:0x0193, B:29:0x01ab, B:30:0x01a1, B:53:0x00ce, B:54:0x0098, B:56:0x00a5, B:59:0x00ac), top: B:44:0x0084 }] */
/* JADX WARN: Removed duplicated region for block: B:148:0x0357 A[SYNTHETIC] */
/* JADX WARN: Removed duplicated region for block: B:52:0x00b9 A[Catch: all -> 0x011a, TryCatch #3 {all -> 0x011a, blocks: (B:45:0x0084, B:47:0x008a, B:52:0x00b9, B:11:0x0126, B:36:0x0134, B:33:0x0150, B:18:0x0166, B:21:0x01b3, B:24:0x016f, B:26:0x0193, B:29:0x01ab, B:30:0x01a1, B:53:0x00ce, B:54:0x0098, B:56:0x00a5, B:59:0x00ac), top: B:44:0x0084 }] */
/* JADX WARN: Removed duplicated region for block: B:53:0x00ce A[Catch: all -> 0x011a, TryCatch #3 {all -> 0x011a, blocks: (B:45:0x0084, B:47:0x008a, B:52:0x00b9, B:11:0x0126, B:36:0x0134, B:33:0x0150, B:18:0x0166, B:21:0x01b3, B:24:0x016f, B:26:0x0193, B:29:0x01ab, B:30:0x01a1, B:53:0x00ce, B:54:0x0098, B:56:0x00a5, B:59:0x00ac), top: B:44:0x0084 }] */
/* JADX WARN: Removed duplicated region for block: B:92:0x035b */
/*
Code decompiled incorrectly, please refer to instructions dump.
To view partially-correct code enable 'Show inconsistent code' option in preferences
*/
public static void a(android.content.Context r33, android.media.MediaExtractor r34, android.media.MediaMuxer r35, int r36, java.lang.Integer r37, java.lang.Integer r38, java.lang.Float r39, com.hw.videoprocessor.util.VideoProgressListener r40) throws java.lang.Exception {
/*
Method dump skipped, instructions count: 1224
To view this dump change 'Code comments level' option to 'DEBUG'
*/
throw new UnsupportedOperationException("Method not decompiled: com.hw.videoprocessor.util.AudioUtil.a(android.content.Context, android.media.MediaExtractor, android.media.MediaMuxer, int, java.lang.Integer, java.lang.Integer, java.lang.Float, com.hw.videoprocessor.util.VideoProgressListener):void");
}
public static int a(MediaFormat mediaFormat) {
if (mediaFormat.containsKey("bitrate")) {
return mediaFormat.getInteger("bitrate");
}
return 192000;
}
public static void a(MediaFormat mediaFormat, int i, int i2, int i3) {
int intValue = a.containsKey(Integer.valueOf(i2)) ? a.get(Integer.valueOf(i2)).intValue() : 4;
ByteBuffer allocate = ByteBuffer.allocate(2);
allocate.put(0, (byte) ((i << 3) | (intValue >> 1)));
allocate.put(1, (byte) (((intValue & 1) << 7) | (i3 << 3)));
mediaFormat.setByteBuffer("csd-0", allocate);
}
}