Skip to content

Commit

Permalink
[fix] some device record audio failed
Browse files Browse the repository at this point in the history
  • Loading branch information
jiangdg committed Aug 5, 2022
1 parent ea72294 commit f58a9c4
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 14 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ dependencies {
implementation "com.tencent.bugly:nativecrashreport:$bugly_native_version"

// For debug online
// implementation project(':libausbc')
implementation project(':libausbc')

// demo
implementation 'com.github.jiangdongguo.AndroidUSBCamera:libausbc:3.2.5'
// implementation 'com.github.jiangdongguo.AndroidUSBCamera:libausbc:3.2.5'
}
Binary file modified app/release/app-release.apk
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,9 @@ class AACEncodeProcessor : AbstractProcessor() {
if (readBytes <= 0) {
continue
}
if (Utils.debugCamera) {
Logger.i(TAG, "read pcm data, len = $readBytes")
}
// pcm encode queue
if (mRawDataQueue.size >= MAX_QUEUE_SIZE) {
mRawDataQueue.poll()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import java.util.concurrent.atomic.AtomicBoolean
*
* @author Created by jiangdg on 2022/2/10
*/
abstract class AbstractProcessor {
abstract class AbstractProcessor(private val gLESRender: Boolean = false) {
private var mEncodeThread: HandlerThread? = null
private var mEncodeHandler: Handler? = null
protected var mMediaCodec: MediaCodec? = null
Expand Down Expand Up @@ -101,9 +101,6 @@ abstract class AbstractProcessor {
fun setMp4Muxer(muxer: Mp4Muxer, isVideo: Boolean) {
this.mMp4Muxer = muxer
this.isVideo = isVideo
mMediaCodec?.outputFormat?.let { format->
mMp4Muxer?.addTracker(format, isVideo)
}
}

/**
Expand Down Expand Up @@ -212,6 +209,9 @@ abstract class AbstractProcessor {
if (mRawDataQueue.isEmpty()) {
return@let
}
if (gLESRender && isVideo) {
return@let
}
val rawData = mRawDataQueue.poll() ?: return@let
val inputIndex = codec.dequeueInputBuffer(TIMES_OUT_US)
if (inputIndex < 0) {
Expand All @@ -225,6 +225,9 @@ abstract class AbstractProcessor {
inputBuffer?.clear()
inputBuffer?.put(rawData.data)
codec.queueInputBuffer(inputIndex, 0, rawData.data.size, getPTSUs(rawData.data.size), 0)
if (Utils.debugCamera) {
Logger.i(TAG, "queue mediacodec data, isVideo=$isVideo, len=${rawData.data.size}")
}
}
}

Expand All @@ -233,9 +236,9 @@ abstract class AbstractProcessor {
return
}
if (bufferInfo.flags == MediaCodec.BUFFER_FLAG_KEY_FRAME) {
Logger.i(TAG, "Key frame, len = $length")
Logger.i(TAG, "isVideo = $isVideo, Key frame, len = $length")
} else if (bufferInfo.flags == MediaCodec.BUFFER_FLAG_CODEC_CONFIG) {
Logger.i(TAG, "Pps/sps frame, len = $length")
Logger.i(TAG, "isVideo = $isVideo, Pps/sps frame, len = $length")
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class H264EncodeProcessor(
val width: Int,
val height: Int,
private val gLESRender: Boolean = true
) : AbstractProcessor() {
) : AbstractProcessor(gLESRender) {

private var mFrameRate: Int? = null
private var mBitRate: Int? = null
Expand Down
10 changes: 5 additions & 5 deletions settings.gradle
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
include ':app'

// For debug online
//include ':libausbc'
//include ':libuvc'
//include ':libpush'
//include ':libnative'
//include ':libuvccommon'
include ':libausbc'
include ':libuvc'
include ':libpush'
include ':libnative'
include ':libuvccommon'

0 comments on commit f58a9c4

Please sign in to comment.