Skip to content

Commit 9281b0c

Browse files
committed
修复呼叫页面不出声音问题
1 parent 81ac706 commit 9281b0c

File tree

3 files changed

+23
-6
lines changed

3 files changed

+23
-6
lines changed

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,19 @@ class CustomDuplexVideoActivity : BaseIPCActivity<ActivityCustomDuplexVideoBindi
214214
}
215215
}
216216

217+
override fun onStartRecvAudioStream(
218+
visitor: Int,
219+
channel: Int,
220+
type: Int,
221+
option: Int,
222+
mode: Int,
223+
width: Int,
224+
sample_rate: Int,
225+
sample_num: Int
226+
): Int {
227+
return player.startAudioPlay(visitor, type, option, mode, width, sample_rate, sample_num)
228+
}
229+
217230
private fun checkConditions() {
218231
if (condition1 && condition2 && remotePreviewSurface != null && surface == null) {
219232
surface = Surface(remotePreviewSurface)

app/src/main/java/com/tencent/iotvideo/link/decoder/VideoDecoder.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,10 @@ private void initVideo(int width, int height, Surface surface) throws IOExceptio
6363
mFormat.setInteger(MediaFormat.KEY_ROTATION, 0);
6464
mFormat.setInteger(MediaFormat.KEY_PROFILE, MediaCodecInfo.CodecProfileLevel.AVCProfileBaseline);
6565
mFormat.setInteger(MediaFormat.KEY_LEVEL, MediaCodecInfo.CodecProfileLevel.AVCLevel31);
66+
mFormat.setInteger(MediaFormat.KEY_PRIORITY, 0); // 设置低优先级
67+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
68+
mFormat.setInteger(MediaFormat.KEY_LOW_LATENCY, 1); // 启用低延迟模式
69+
}
6670
String model = Build.MODEL;
6771
if (model.contains("KONKA") && model.contains("9652") || model.contains("KONKA") && model.contains("9653") || model.contains("XY01")) { // 康佳 MTK的一个SoC 型号
6872
mFormat.setInteger("low-latency", 1);
@@ -88,22 +92,22 @@ public int decoderH264(byte[] data, int len, long pts) {
8892
try {
8993
ByteBuffer[] inputBuffers = mVideoCodec.getInputBuffers();
9094
// queue and decode
91-
int inputBufferIndex = mVideoCodec.dequeueInputBuffer(-1);
95+
int inputBufferIndex = mVideoCodec.dequeueInputBuffer(10000);
9296
if (inputBufferIndex >= 0) {
9397
ByteBuffer inputBuffer = inputBuffers[inputBufferIndex];
9498
inputBuffer.clear();
9599
inputBuffer.put(data, 0, len);
96-
mVideoCodec.queueInputBuffer(inputBufferIndex, 0, len, 0, 0);
100+
mVideoCodec.queueInputBuffer(inputBufferIndex, 0, len, pts * 1000, 0);
97101
} else {
98102
Log.e(TAG, "video inputBufferIndex invalid: " + inputBufferIndex);
99103
}
100104

101105
// dequeue and render
102106
MediaCodec.BufferInfo bufferInfo = new MediaCodec.BufferInfo();
103-
int outputBufferIndex = mVideoCodec.dequeueOutputBuffer(bufferInfo, 0);
107+
int outputBufferIndex = mVideoCodec.dequeueOutputBuffer(bufferInfo, 10000);
104108
while (outputBufferIndex >= 0) {
105109
mVideoCodec.releaseOutputBuffer(outputBufferIndex, true);
106-
outputBufferIndex = mVideoCodec.dequeueOutputBuffer(bufferInfo, 0);
110+
outputBufferIndex = mVideoCodec.dequeueOutputBuffer(bufferInfo, 10000);
107111
}
108112
} catch (Throwable t) {
109113
t.printStackTrace();

app/src/main/res/layout/activity_custom_duplex_video.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@
7676
<androidx.constraintlayout.widget.ConstraintLayout
7777
android:id="@+id/cl_call"
7878
android:layout_width="match_parent"
79-
android:layout_height="0dp"
79+
android:layout_height="550dp"
8080
android:visibility="gone"
8181
app:layout_constraintBottom_toBottomOf="parent"
8282
app:layout_constraintEnd_toEndOf="parent"
@@ -95,7 +95,7 @@
9595
android:id="@+id/surfaceView_duplex"
9696
android:layout_width="0dp"
9797
android:layout_height="0dp"
98-
app:layout_constraintBottom_toBottomOf="parent"
98+
app:layout_constraintBottom_toBottomOf="@+id/bg_surfaceView"
9999
app:layout_constraintEnd_toEndOf="@+id/bg_surfaceView"
100100
app:layout_constraintStart_toStartOf="@+id/bg_surfaceView"
101101
app:layout_constraintTop_toTopOf="@+id/bg_surfaceView" />

0 commit comments

Comments
 (0)