Browse Source

支持单独推流和边推边录制

main 2.1.4
jiangdongguo 7 years ago
parent
commit
57765b6765
  1. 1
      .gradle/2.14.1/taskArtifacts/cache.properties
  2. BIN
      .gradle/2.14.1/taskArtifacts/cache.properties.lock
  3. BIN
      .gradle/2.14.1/taskArtifacts/fileHashes.bin
  4. BIN
      .gradle/2.14.1/taskArtifacts/fileSnapshots.bin
  5. BIN
      .gradle/2.14.1/taskArtifacts/fileSnapshotsToTreeSnapshotsIndex.bin
  6. BIN
      .gradle/2.14.1/taskArtifacts/taskArtifacts.bin
  7. BIN
      .gradle/3.3/taskArtifacts/fileHashes.bin
  8. BIN
      .gradle/3.3/taskArtifacts/fileSnapshots.bin
  9. BIN
      .gradle/3.3/taskArtifacts/taskArtifacts.bin
  10. BIN
      .gradle/3.3/taskArtifacts/taskArtifacts.lock
  11. BIN
      .gradle/3.3/tasks/_app_compileDebugJavaWithJavac/localClassSetAnalysis/localClassSetAnalysis.bin
  12. BIN
      .gradle/3.3/tasks/_app_compileDebugJavaWithJavac/localClassSetAnalysis/localClassSetAnalysis.lock
  13. BIN
      .gradle/3.3/tasks/_app_compileDebugJavaWithJavac/localJarClasspathSnapshot/localJarClasspathSnapshot.bin
  14. BIN
      .gradle/3.3/tasks/_app_compileDebugJavaWithJavac/localJarClasspathSnapshot/localJarClasspathSnapshot.lock
  15. BIN
      .gradle/3.3/tasks/_libusbcamera_compileReleaseJavaWithJavac/localClassSetAnalysis/localClassSetAnalysis.bin
  16. BIN
      .gradle/3.3/tasks/_libusbcamera_compileReleaseJavaWithJavac/localClassSetAnalysis/localClassSetAnalysis.lock
  17. BIN
      .gradle/3.3/tasks/_libusbcamera_compileReleaseJavaWithJavac/localJarClasspathSnapshot/localJarClasspathSnapshot.bin
  18. BIN
      .gradle/3.3/tasks/_libusbcamera_compileReleaseJavaWithJavac/localJarClasspathSnapshot/localJarClasspathSnapshot.lock
  19. 71
      app/app.iml
  20. 9
      app/src/main/java/com/jiangdg/usbcamera/view/USBCameraActivity.java
  21. 66
      libusbcamera/libusbcamera.iml
  22. 16
      libusbcamera/src/main/java/com/jiangdg/usbcamera/UVCCameraHelper.java
  23. 157
      libusbcamera/src/main/java/com/serenegiant/usb/common/AbstractUVCCameraHandler.java

1
.gradle/2.14.1/taskArtifacts/cache.properties

@ -1 +0,0 @@
#Fri Sep 29 14:50:34 CST 2017

BIN
.gradle/2.14.1/taskArtifacts/cache.properties.lock

Binary file not shown.

BIN
.gradle/2.14.1/taskArtifacts/fileHashes.bin

Binary file not shown.

BIN
.gradle/2.14.1/taskArtifacts/fileSnapshots.bin

Binary file not shown.

BIN
.gradle/2.14.1/taskArtifacts/fileSnapshotsToTreeSnapshotsIndex.bin

Binary file not shown.

BIN
.gradle/2.14.1/taskArtifacts/taskArtifacts.bin

Binary file not shown.

BIN
.gradle/3.3/taskArtifacts/fileHashes.bin

Binary file not shown.

BIN
.gradle/3.3/taskArtifacts/fileSnapshots.bin

Binary file not shown.

BIN
.gradle/3.3/taskArtifacts/taskArtifacts.bin

Binary file not shown.

BIN
.gradle/3.3/taskArtifacts/taskArtifacts.lock

Binary file not shown.

BIN
.gradle/3.3/tasks/_app_compileDebugJavaWithJavac/localClassSetAnalysis/localClassSetAnalysis.bin

Binary file not shown.

BIN
.gradle/3.3/tasks/_app_compileDebugJavaWithJavac/localClassSetAnalysis/localClassSetAnalysis.lock

Binary file not shown.

BIN
.gradle/3.3/tasks/_app_compileDebugJavaWithJavac/localJarClasspathSnapshot/localJarClasspathSnapshot.bin

Binary file not shown.

BIN
.gradle/3.3/tasks/_app_compileDebugJavaWithJavac/localJarClasspathSnapshot/localJarClasspathSnapshot.lock

Binary file not shown.

BIN
.gradle/3.3/tasks/_libusbcamera_compileReleaseJavaWithJavac/localClassSetAnalysis/localClassSetAnalysis.bin

Binary file not shown.

BIN
.gradle/3.3/tasks/_libusbcamera_compileReleaseJavaWithJavac/localClassSetAnalysis/localClassSetAnalysis.lock

Binary file not shown.

BIN
.gradle/3.3/tasks/_libusbcamera_compileReleaseJavaWithJavac/localJarClasspathSnapshot/localJarClasspathSnapshot.bin

Binary file not shown.

BIN
.gradle/3.3/tasks/_libusbcamera_compileReleaseJavaWithJavac/localJarClasspathSnapshot/localJarClasspathSnapshot.lock

Binary file not shown.

71
app/app.iml

@ -27,21 +27,20 @@
<output-test url="file://$MODULE_DIR$/build/intermediates/classes/test/debug" /> <output-test url="file://$MODULE_DIR$/build/intermediates/classes/test/debug" />
<exclude-output /> <exclude-output />
<content url="file://$MODULE_DIR$"> <content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/apt/debug" isTestSource="false" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/r/debug" isTestSource="false" generated="true" /> <sourceFolder url="file://$MODULE_DIR$/build/generated/source/r/debug" isTestSource="false" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/aidl/debug" isTestSource="false" generated="true" /> <sourceFolder url="file://$MODULE_DIR$/build/generated/source/aidl/debug" isTestSource="false" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/buildConfig/debug" isTestSource="false" generated="true" /> <sourceFolder url="file://$MODULE_DIR$/build/generated/source/buildConfig/debug" isTestSource="false" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/rs/debug" isTestSource="false" generated="true" /> <sourceFolder url="file://$MODULE_DIR$/build/generated/source/rs/debug" isTestSource="false" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/apt/debug" isTestSource="false" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/rs/debug" type="java-resource" /> <sourceFolder url="file://$MODULE_DIR$/build/generated/res/rs/debug" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/resValues/debug" type="java-resource" /> <sourceFolder url="file://$MODULE_DIR$/build/generated/res/resValues/debug" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/apt/androidTest/debug" isTestSource="true" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/r/androidTest/debug" isTestSource="true" generated="true" /> <sourceFolder url="file://$MODULE_DIR$/build/generated/source/r/androidTest/debug" isTestSource="true" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/aidl/androidTest/debug" isTestSource="true" generated="true" /> <sourceFolder url="file://$MODULE_DIR$/build/generated/source/aidl/androidTest/debug" isTestSource="true" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/buildConfig/androidTest/debug" isTestSource="true" generated="true" /> <sourceFolder url="file://$MODULE_DIR$/build/generated/source/buildConfig/androidTest/debug" isTestSource="true" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/rs/androidTest/debug" isTestSource="true" generated="true" /> <sourceFolder url="file://$MODULE_DIR$/build/generated/source/rs/androidTest/debug" isTestSource="true" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/apt/androidTest/debug" isTestSource="true" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/rs/androidTest/debug" type="java-test-resource" /> <sourceFolder url="file://$MODULE_DIR$/build/generated/res/rs/androidTest/debug" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/resValues/androidTest/debug" type="java-test-resource" /> <sourceFolder url="file://$MODULE_DIR$/build/generated/res/resValues/androidTest/debug" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/apt/test/debug" isTestSource="true" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/src/debug/res" type="java-resource" /> <sourceFolder url="file://$MODULE_DIR$/src/debug/res" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/debug/resources" type="java-resource" /> <sourceFolder url="file://$MODULE_DIR$/src/debug/resources" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/debug/assets" type="java-resource" /> <sourceFolder url="file://$MODULE_DIR$/src/debug/assets" type="java-resource" />
@ -49,13 +48,6 @@
<sourceFolder url="file://$MODULE_DIR$/src/debug/java" isTestSource="false" /> <sourceFolder url="file://$MODULE_DIR$/src/debug/java" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/debug/rs" isTestSource="false" /> <sourceFolder url="file://$MODULE_DIR$/src/debug/rs" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/debug/shaders" isTestSource="false" /> <sourceFolder url="file://$MODULE_DIR$/src/debug/shaders" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTestDebug/res" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTestDebug/resources" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTestDebug/assets" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTestDebug/aidl" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTestDebug/java" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTestDebug/rs" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTestDebug/shaders" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/res" type="java-test-resource" /> <sourceFolder url="file://$MODULE_DIR$/src/testDebug/res" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/resources" type="java-test-resource" /> <sourceFolder url="file://$MODULE_DIR$/src/testDebug/resources" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/assets" type="java-test-resource" /> <sourceFolder url="file://$MODULE_DIR$/src/testDebug/assets" type="java-test-resource" />
@ -88,10 +80,13 @@
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/blame" /> <excludeFolder url="file://$MODULE_DIR$/build/intermediates/blame" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/classes" /> <excludeFolder url="file://$MODULE_DIR$/build/intermediates/classes" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental" /> <excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental-safeguard" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/javaPrecompile" /> <excludeFolder url="file://$MODULE_DIR$/build/intermediates/javaPrecompile" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/jniLibs" /> <excludeFolder url="file://$MODULE_DIR$/build/intermediates/jniLibs" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/manifests" /> <excludeFolder url="file://$MODULE_DIR$/build/intermediates/manifests" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/pre-dexed" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/res" /> <excludeFolder url="file://$MODULE_DIR$/build/intermediates/res" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/rs" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/shaders" /> <excludeFolder url="file://$MODULE_DIR$/build/intermediates/shaders" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/splits-support" /> <excludeFolder url="file://$MODULE_DIR$/build/intermediates/splits-support" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/symbols" /> <excludeFolder url="file://$MODULE_DIR$/build/intermediates/symbols" />
@ -102,33 +97,33 @@
</content> </content>
<orderEntry type="jdk" jdkName="Android API 25 Platform" jdkType="Android SDK" /> <orderEntry type="jdk" jdkName="Android API 25 Platform" jdkType="Android SDK" />
<orderEntry type="sourceFolder" forTests="false" /> <orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" scope="TEST" name="com.android.support.test:exposed-instrumentation-api-publish-0.5" level="project" /> <orderEntry type="library" exported="" scope="TEST" name="com.android.support.test:exposed-instrumentation-api-publish-0.5" level="project" />
<orderEntry type="library" scope="TEST" name="junit:junit:4.12@jar" level="project" /> <orderEntry type="library" exported="" scope="TEST" name="junit:junit:4.12@jar" level="project" />
<orderEntry type="library" scope="TEST" name="javax.inject:javax.inject:1@jar" level="project" /> <orderEntry type="library" exported="" scope="TEST" name="javax.inject:javax.inject:1@jar" level="project" />
<orderEntry type="library" name="com.android.support:support-core-ui-25.3.1" level="project" /> <orderEntry type="library" exported="" name="com.android.support:support-core-ui-25.3.1" level="project" />
<orderEntry type="library" scope="TEST" name="com.squareup:javawriter:2.1.1@jar" level="project" /> <orderEntry type="library" exported="" scope="TEST" name="com.squareup:javawriter:2.1.1@jar" level="project" />
<orderEntry type="library" name="com.android.support:support-compat-25.3.1" level="project" /> <orderEntry type="library" exported="" name="com.android.support:support-compat-25.3.1" level="project" />
<orderEntry type="library" name="com.serenegiant:common-1.5.20" level="project" /> <orderEntry type="library" exported="" name="com.serenegiant:common-1.5.20" level="project" />
<orderEntry type="library" name="com.android.support:support-core-utils-25.3.1" level="project" /> <orderEntry type="library" exported="" name="com.android.support:support-core-utils-25.3.1" level="project" />
<orderEntry type="library" name="com.android.support:support-v4-25.3.1" level="project" /> <orderEntry type="library" exported="" name="com.android.support:support-v4-25.3.1" level="project" />
<orderEntry type="library" name="com.android.support:support-fragment-25.3.1" level="project" /> <orderEntry type="library" exported="" name="com.android.support:support-fragment-25.3.1" level="project" />
<orderEntry type="library" name="com.android.support:support-media-compat-25.3.1" level="project" /> <orderEntry type="library" exported="" name="com.android.support:support-media-compat-25.3.1" level="project" />
<orderEntry type="library" scope="TEST" name="com.google.code.findbugs:jsr305:2.0.1@jar" level="project" /> <orderEntry type="library" exported="" scope="TEST" name="com.google.code.findbugs:jsr305:2.0.1@jar" level="project" />
<orderEntry type="library" scope="TEST" name="org.hamcrest:hamcrest-core:1.3@jar" level="project" /> <orderEntry type="library" exported="" scope="TEST" name="org.hamcrest:hamcrest-core:1.3@jar" level="project" />
<orderEntry type="library" name="com.jakewharton:butterknife-8.8.1" level="project" /> <orderEntry type="library" exported="" name="com.jakewharton:butterknife-8.8.1" level="project" />
<orderEntry type="library" name="com.jakewharton:butterknife-annotations:8.8.1@jar" level="project" /> <orderEntry type="library" exported="" scope="TEST" name="com.android.support.test.espresso:espresso-core-2.2.2" level="project" />
<orderEntry type="library" scope="TEST" name="com.android.support.test.espresso:espresso-core-2.2.2" level="project" /> <orderEntry type="library" exported="" name="com.jakewharton:butterknife-annotations:8.8.1@jar" level="project" />
<orderEntry type="library" name="com.android.support:animated-vector-drawable-25.3.1" level="project" /> <orderEntry type="library" exported="" name="com.android.support:animated-vector-drawable-25.3.1" level="project" />
<orderEntry type="library" scope="TEST" name="com.android.support.test:rules-0.5" level="project" /> <orderEntry type="library" exported="" scope="TEST" name="com.android.support.test:rules-0.5" level="project" />
<orderEntry type="library" scope="TEST" name="org.hamcrest:hamcrest-library:1.3@jar" level="project" /> <orderEntry type="library" exported="" scope="TEST" name="org.hamcrest:hamcrest-library:1.3@jar" level="project" />
<orderEntry type="library" scope="TEST" name="org.hamcrest:hamcrest-integration:1.3@jar" level="project" /> <orderEntry type="library" exported="" scope="TEST" name="org.hamcrest:hamcrest-integration:1.3@jar" level="project" />
<orderEntry type="library" scope="TEST" name="com.android.support.test:runner-0.5" level="project" /> <orderEntry type="library" exported="" scope="TEST" name="com.android.support.test:runner-0.5" level="project" />
<orderEntry type="library" name="com.android.support:appcompat-v7-25.3.1" level="project" /> <orderEntry type="library" exported="" name="com.android.support:appcompat-v7-25.3.1" level="project" />
<orderEntry type="library" scope="TEST" name="com.android.support.test.espresso:espresso-idling-resource-2.2.2" level="project" /> <orderEntry type="library" exported="" scope="TEST" name="com.android.support.test.espresso:espresso-idling-resource-2.2.2" level="project" />
<orderEntry type="library" scope="TEST" name="javax.annotation:javax.annotation-api:1.2@jar" level="project" /> <orderEntry type="library" exported="" scope="TEST" name="javax.annotation:javax.annotation-api:1.2@jar" level="project" />
<orderEntry type="library" name="com.android.support:support-vector-drawable-25.3.1" level="project" /> <orderEntry type="library" exported="" name="com.android.support:support-vector-drawable-25.3.1" level="project" />
<orderEntry type="library" name="com.android.support:recyclerview-v7-25.3.1" level="project" /> <orderEntry type="library" exported="" name="com.android.support:recyclerview-v7-25.3.1" level="project" />
<orderEntry type="library" name="com.android.support:support-annotations:25.3.1@jar" level="project" /> <orderEntry type="library" exported="" name="com.android.support:support-annotations:25.3.1@jar" level="project" />
<orderEntry type="module" module-name="libusbcamera" /> <orderEntry type="module" module-name="libusbcamera" exported="" />
</component> </component>
</module> </module>

9
app/src/main/java/com/jiangdg/usbcamera/view/USBCameraActivity.java

@ -241,14 +241,15 @@ public class USBCameraActivity extends AppCompatActivity implements CameraDialog
showShortMsg("sorry,camera open failed"); showShortMsg("sorry,camera open failed");
return super.onOptionsItemSelected(item); return super.onOptionsItemSelected(item);
} }
if (!mCameraHelper.isRecording()) { if (!mCameraHelper.isPushing()) {
String videoPath = UVCCameraHelper.ROOT_PATH + System.currentTimeMillis(); String videoPath = UVCCameraHelper.ROOT_PATH + System.currentTimeMillis();
FileUtils.createfile(FileUtils.ROOT_PATH + "test666.h264"); FileUtils.createfile(FileUtils.ROOT_PATH + "test666.h264");
// if you want to record,please create RecordParams like this
RecordParams params = new RecordParams(); RecordParams params = new RecordParams();
params.setRecordPath(videoPath); params.setRecordPath(videoPath);
params.setRecordDuration(0); // 设置为0,不分割保存 params.setRecordDuration(0); // 设置为0,不分割保存
params.setVoiceClose(mSwitchVoice.isChecked()); // is close voice params.setVoiceClose(mSwitchVoice.isChecked()); // is close voice
mCameraHelper.startRecording(params, new AbstractUVCCameraHandler.OnEncodeResultListener() { mCameraHelper.startPusher(params, new AbstractUVCCameraHandler.OnEncodeResultListener() {
@Override @Override
public void onEncodeResult(byte[] data, int offset, int length, long timestamp, int type) { public void onEncodeResult(byte[] data, int offset, int length, long timestamp, int type) {
// type = 1,h264 video stream // type = 1,h264 video stream
@ -266,11 +267,13 @@ public class USBCameraActivity extends AppCompatActivity implements CameraDialog
Log.i(TAG,"videoPath = "+videoPath); Log.i(TAG,"videoPath = "+videoPath);
} }
}); });
// if you only want to push stream,please call like this
// mCameraHelper.startPusher(listener);
showShortMsg("start record..."); showShortMsg("start record...");
mSwitchVoice.setEnabled(false); mSwitchVoice.setEnabled(false);
} else { } else {
FileUtils.releaseFile(); FileUtils.releaseFile();
mCameraHelper.stopRecording(); mCameraHelper.stopPusher();
showShortMsg("stop record..."); showShortMsg("stop record...");
mSwitchVoice.setEnabled(true); mSwitchVoice.setEnabled(true);
} }

66
libusbcamera/libusbcamera.iml

@ -28,21 +28,20 @@
<output-test url="file://$MODULE_DIR$/build/intermediates/classes/test/debug" /> <output-test url="file://$MODULE_DIR$/build/intermediates/classes/test/debug" />
<exclude-output /> <exclude-output />
<content url="file://$MODULE_DIR$"> <content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/apt/debug" isTestSource="false" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/r/debug" isTestSource="false" generated="true" /> <sourceFolder url="file://$MODULE_DIR$/build/generated/source/r/debug" isTestSource="false" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/aidl/debug" isTestSource="false" generated="true" /> <sourceFolder url="file://$MODULE_DIR$/build/generated/source/aidl/debug" isTestSource="false" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/buildConfig/debug" isTestSource="false" generated="true" /> <sourceFolder url="file://$MODULE_DIR$/build/generated/source/buildConfig/debug" isTestSource="false" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/rs/debug" isTestSource="false" generated="true" /> <sourceFolder url="file://$MODULE_DIR$/build/generated/source/rs/debug" isTestSource="false" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/apt/debug" isTestSource="false" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/rs/debug" type="java-resource" /> <sourceFolder url="file://$MODULE_DIR$/build/generated/res/rs/debug" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/resValues/debug" type="java-resource" /> <sourceFolder url="file://$MODULE_DIR$/build/generated/res/resValues/debug" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/apt/androidTest/debug" isTestSource="true" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/r/androidTest/debug" isTestSource="true" generated="true" /> <sourceFolder url="file://$MODULE_DIR$/build/generated/source/r/androidTest/debug" isTestSource="true" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/aidl/androidTest/debug" isTestSource="true" generated="true" /> <sourceFolder url="file://$MODULE_DIR$/build/generated/source/aidl/androidTest/debug" isTestSource="true" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/buildConfig/androidTest/debug" isTestSource="true" generated="true" /> <sourceFolder url="file://$MODULE_DIR$/build/generated/source/buildConfig/androidTest/debug" isTestSource="true" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/rs/androidTest/debug" isTestSource="true" generated="true" /> <sourceFolder url="file://$MODULE_DIR$/build/generated/source/rs/androidTest/debug" isTestSource="true" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/apt/androidTest/debug" isTestSource="true" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/rs/androidTest/debug" type="java-test-resource" /> <sourceFolder url="file://$MODULE_DIR$/build/generated/res/rs/androidTest/debug" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/resValues/androidTest/debug" type="java-test-resource" /> <sourceFolder url="file://$MODULE_DIR$/build/generated/res/resValues/androidTest/debug" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/apt/test/debug" isTestSource="true" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/src/debug/res" type="java-resource" /> <sourceFolder url="file://$MODULE_DIR$/src/debug/res" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/debug/resources" type="java-resource" /> <sourceFolder url="file://$MODULE_DIR$/src/debug/resources" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/debug/assets" type="java-resource" /> <sourceFolder url="file://$MODULE_DIR$/src/debug/assets" type="java-resource" />
@ -57,13 +56,6 @@
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/java" isTestSource="true" /> <sourceFolder url="file://$MODULE_DIR$/src/testDebug/java" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/rs" isTestSource="true" /> <sourceFolder url="file://$MODULE_DIR$/src/testDebug/rs" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/shaders" isTestSource="true" /> <sourceFolder url="file://$MODULE_DIR$/src/testDebug/shaders" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTestDebug/res" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTestDebug/resources" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTestDebug/assets" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTestDebug/aidl" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTestDebug/java" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTestDebug/rs" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTestDebug/shaders" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/main/res" type="java-resource" /> <sourceFolder url="file://$MODULE_DIR$/src/main/res" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" /> <sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/main/assets" type="java-resource" /> <sourceFolder url="file://$MODULE_DIR$/src/main/assets" type="java-resource" />
@ -85,16 +77,20 @@
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/java" isTestSource="true" /> <sourceFolder url="file://$MODULE_DIR$/src/androidTest/java" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/rs" isTestSource="true" /> <sourceFolder url="file://$MODULE_DIR$/src/androidTest/rs" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/shaders" isTestSource="true" /> <sourceFolder url="file://$MODULE_DIR$/src/androidTest/shaders" isTestSource="true" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/annotations" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/attr" /> <excludeFolder url="file://$MODULE_DIR$/build/intermediates/attr" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/blame" /> <excludeFolder url="file://$MODULE_DIR$/build/intermediates/blame" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/bundles" /> <excludeFolder url="file://$MODULE_DIR$/build/intermediates/bundles" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/classes" /> <excludeFolder url="file://$MODULE_DIR$/build/intermediates/classes" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental" /> <excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental-safeguard" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/intermediate-jars" /> <excludeFolder url="file://$MODULE_DIR$/build/intermediates/intermediate-jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/javaPrecompile" /> <excludeFolder url="file://$MODULE_DIR$/build/intermediates/javaPrecompile" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/jniLibs" /> <excludeFolder url="file://$MODULE_DIR$/build/intermediates/jniLibs" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/lint" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/manifests" /> <excludeFolder url="file://$MODULE_DIR$/build/intermediates/manifests" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/res" /> <excludeFolder url="file://$MODULE_DIR$/build/intermediates/res" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/rs" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/shaders" /> <excludeFolder url="file://$MODULE_DIR$/build/intermediates/shaders" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/symbols" /> <excludeFolder url="file://$MODULE_DIR$/build/intermediates/symbols" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/tmp" /> <excludeFolder url="file://$MODULE_DIR$/build/intermediates/tmp" />
@ -104,30 +100,30 @@
</content> </content>
<orderEntry type="jdk" jdkName="Android API 25 Platform" jdkType="Android SDK" /> <orderEntry type="jdk" jdkName="Android API 25 Platform" jdkType="Android SDK" />
<orderEntry type="sourceFolder" forTests="false" /> <orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" scope="TEST" name="com.android.support.test:exposed-instrumentation-api-publish-0.5" level="project" /> <orderEntry type="library" exported="" scope="TEST" name="com.android.support.test:exposed-instrumentation-api-publish-0.5" level="project" />
<orderEntry type="library" scope="TEST" name="junit:junit:4.12@jar" level="project" /> <orderEntry type="library" exported="" scope="TEST" name="junit:junit:4.12@jar" level="project" />
<orderEntry type="library" scope="TEST" name="javax.inject:javax.inject:1@jar" level="project" /> <orderEntry type="library" exported="" scope="TEST" name="javax.inject:javax.inject:1@jar" level="project" />
<orderEntry type="library" name="com.android.support:support-core-ui-25.3.1" level="project" /> <orderEntry type="library" exported="" name="com.android.support:support-core-ui-25.3.1" level="project" />
<orderEntry type="library" scope="TEST" name="com.squareup:javawriter:2.1.1@jar" level="project" /> <orderEntry type="library" exported="" scope="TEST" name="com.squareup:javawriter:2.1.1@jar" level="project" />
<orderEntry type="library" name="com.android.support:support-compat-25.3.1" level="project" /> <orderEntry type="library" exported="" name="com.android.support:support-compat-25.3.1" level="project" />
<orderEntry type="library" name="com.serenegiant:common-1.5.20" level="project" /> <orderEntry type="library" exported="" name="com.serenegiant:common-1.5.20" level="project" />
<orderEntry type="library" name="com.android.support:support-core-utils-25.3.1" level="project" /> <orderEntry type="library" exported="" name="com.android.support:support-core-utils-25.3.1" level="project" />
<orderEntry type="library" name="com.android.support:support-v4-25.3.1" level="project" /> <orderEntry type="library" exported="" name="com.android.support:support-v4-25.3.1" level="project" />
<orderEntry type="library" name="com.android.support:support-fragment-25.3.1" level="project" /> <orderEntry type="library" exported="" name="com.android.support:support-fragment-25.3.1" level="project" />
<orderEntry type="library" name="com.android.support:support-media-compat-25.3.1" level="project" /> <orderEntry type="library" exported="" name="com.android.support:support-media-compat-25.3.1" level="project" />
<orderEntry type="library" scope="TEST" name="com.google.code.findbugs:jsr305:2.0.1@jar" level="project" /> <orderEntry type="library" exported="" scope="TEST" name="com.google.code.findbugs:jsr305:2.0.1@jar" level="project" />
<orderEntry type="library" scope="TEST" name="org.hamcrest:hamcrest-core:1.3@jar" level="project" /> <orderEntry type="library" exported="" scope="TEST" name="org.hamcrest:hamcrest-core:1.3@jar" level="project" />
<orderEntry type="library" scope="TEST" name="com.android.support.test.espresso:espresso-core-2.2.2" level="project" /> <orderEntry type="library" exported="" scope="TEST" name="com.android.support.test.espresso:espresso-core-2.2.2" level="project" />
<orderEntry type="library" name="com.android.support:animated-vector-drawable-25.3.1" level="project" /> <orderEntry type="library" exported="" name="com.android.support:animated-vector-drawable-25.3.1" level="project" />
<orderEntry type="library" scope="TEST" name="com.android.support.test:rules-0.5" level="project" /> <orderEntry type="library" exported="" scope="TEST" name="com.android.support.test:rules-0.5" level="project" />
<orderEntry type="library" scope="TEST" name="org.hamcrest:hamcrest-library:1.3@jar" level="project" /> <orderEntry type="library" exported="" scope="TEST" name="org.hamcrest:hamcrest-library:1.3@jar" level="project" />
<orderEntry type="library" scope="TEST" name="org.hamcrest:hamcrest-integration:1.3@jar" level="project" /> <orderEntry type="library" exported="" scope="TEST" name="org.hamcrest:hamcrest-integration:1.3@jar" level="project" />
<orderEntry type="library" scope="TEST" name="com.android.support.test:runner-0.5" level="project" /> <orderEntry type="library" exported="" scope="TEST" name="com.android.support.test:runner-0.5" level="project" />
<orderEntry type="library" name="com.android.support:appcompat-v7-25.3.1" level="project" /> <orderEntry type="library" exported="" name="com.android.support:appcompat-v7-25.3.1" level="project" />
<orderEntry type="library" scope="TEST" name="com.android.support.test.espresso:espresso-idling-resource-2.2.2" level="project" /> <orderEntry type="library" exported="" scope="TEST" name="com.android.support.test.espresso:espresso-idling-resource-2.2.2" level="project" />
<orderEntry type="library" scope="TEST" name="javax.annotation:javax.annotation-api:1.2@jar" level="project" /> <orderEntry type="library" exported="" scope="TEST" name="javax.annotation:javax.annotation-api:1.2@jar" level="project" />
<orderEntry type="library" name="com.android.support:support-vector-drawable-25.3.1" level="project" /> <orderEntry type="library" exported="" name="com.android.support:support-vector-drawable-25.3.1" level="project" />
<orderEntry type="library" name="com.android.support:recyclerview-v7-25.3.1" level="project" /> <orderEntry type="library" exported="" name="com.android.support:recyclerview-v7-25.3.1" level="project" />
<orderEntry type="library" name="com.android.support:support-annotations:25.3.1@jar" level="project" /> <orderEntry type="library" exported="" name="com.android.support:support-annotations:25.3.1@jar" level="project" />
</component> </component>
</module> </module>

16
libusbcamera/src/main/java/com/jiangdg/usbcamera/UVCCameraHelper.java

@ -247,19 +247,25 @@ public class UVCCameraHelper {
} }
} }
public void startRecording(RecordParams params, AbstractUVCCameraHandler.OnEncodeResultListener listener) { public void startPusher(AbstractUVCCameraHandler.OnEncodeResultListener listener) {
if (mCameraHandler != null && !isRecording()) { if (mCameraHandler != null && !isPushing()) {
mCameraHandler.startRecording(null, listener);
}
}
public void startPusher(RecordParams params, AbstractUVCCameraHandler.OnEncodeResultListener listener) {
if (mCameraHandler != null && !isPushing()) {
mCameraHandler.startRecording(params, listener); mCameraHandler.startRecording(params, listener);
} }
} }
public void stopRecording() { public void stopPusher() {
if (mCameraHandler != null && isRecording()) { if (mCameraHandler != null && isPushing()) {
mCameraHandler.stopRecording(); mCameraHandler.stopRecording();
} }
} }
public boolean isRecording() { public boolean isPushing() {
if (mCameraHandler != null) { if (mCameraHandler != null) {
return mCameraHandler.isRecording(); return mCameraHandler.isRecording();
} }

157
libusbcamera/src/main/java/com/serenegiant/usb/common/AbstractUVCCameraHandler.java

@ -51,8 +51,7 @@ import java.util.concurrent.CopyOnWriteArraySet;
/** /**
* Camera业务处理抽象类 * Camera业务处理抽象类
* */
* */
public abstract class AbstractUVCCameraHandler extends Handler { public abstract class AbstractUVCCameraHandler extends Handler {
private static final boolean DEBUG = true; // TODO set false on release private static final boolean DEBUG = true; // TODO set false on release
@ -62,11 +61,17 @@ public abstract class AbstractUVCCameraHandler extends Handler {
// 对外回调接口 // 对外回调接口
public interface CameraCallback { public interface CameraCallback {
public void onOpen(); public void onOpen();
public void onClose(); public void onClose();
public void onStartPreview(); public void onStartPreview();
public void onStopPreview(); public void onStopPreview();
public void onStartRecording(); public void onStartRecording();
public void onStopRecording(); public void onStopRecording();
public void onError(final Exception e); public void onError(final Exception e);
} }
@ -74,12 +79,13 @@ public abstract class AbstractUVCCameraHandler extends Handler {
public static OnPreViewResultListener mPreviewListener; public static OnPreViewResultListener mPreviewListener;
public static OnCaptureListener mCaptureListener; public static OnCaptureListener mCaptureListener;
public interface OnEncodeResultListener{ public interface OnEncodeResultListener {
void onEncodeResult(byte[] data, int offset, int length, long timestamp, int type); void onEncodeResult(byte[] data, int offset, int length, long timestamp, int type);
void onRecordResult(String videoPath); void onRecordResult(String videoPath);
} }
public interface OnPreViewResultListener{ public interface OnPreViewResultListener {
void onPreviewResult(byte[] data); void onPreviewResult(byte[] data);
} }
@ -184,7 +190,7 @@ public abstract class AbstractUVCCameraHandler extends Handler {
public void startPreview(final Object surface) { public void startPreview(final Object surface) {
checkReleased(); checkReleased();
if (!((surface instanceof SurfaceHolder) || (surface instanceof Surface) || (surface instanceof SurfaceTexture))) { if (!((surface instanceof SurfaceHolder) || (surface instanceof Surface) || (surface instanceof SurfaceTexture))) {
throw new IllegalArgumentException("surface should be one of SurfaceHolder, Surface or SurfaceTexture: "+surface); throw new IllegalArgumentException("surface should be one of SurfaceHolder, Surface or SurfaceTexture: " + surface);
} }
sendMessage(obtainMessage(MSG_PREVIEW_START, surface)); sendMessage(obtainMessage(MSG_PREVIEW_START, surface));
@ -198,7 +204,7 @@ public abstract class AbstractUVCCameraHandler extends Handler {
public void stopPreview() { public void stopPreview() {
if (DEBUG) Log.v(TAG, "stopPreview:"); if (DEBUG) Log.v(TAG, "stopPreview:");
removeMessages(MSG_PREVIEW_START); removeMessages(MSG_PREVIEW_START);
if(isRecording()) { if (isRecording()) {
stopRecording(); stopRecording();
} }
if (isPreviewing()) { if (isPreviewing()) {
@ -220,7 +226,7 @@ public abstract class AbstractUVCCameraHandler extends Handler {
if (DEBUG) Log.v(TAG, "stopPreview:finished"); if (DEBUG) Log.v(TAG, "stopPreview:finished");
} }
public void captureStill(final String path,AbstractUVCCameraHandler.OnCaptureListener listener) { public void captureStill(final String path, AbstractUVCCameraHandler.OnCaptureListener listener) {
AbstractUVCCameraHandler.mCaptureListener = listener; AbstractUVCCameraHandler.mCaptureListener = listener;
checkReleased(); checkReleased();
sendMessage(obtainMessage(MSG_CAPTURE_STILL, path)); sendMessage(obtainMessage(MSG_CAPTURE_STILL, path));
@ -239,11 +245,11 @@ public abstract class AbstractUVCCameraHandler extends Handler {
sendEmptyMessage(MSG_CAPTURE_STOP); sendEmptyMessage(MSG_CAPTURE_STOP);
} }
public void startCameraFoucs(){ public void startCameraFoucs() {
sendEmptyMessage(MSG_CAMERA_FOUCS); sendEmptyMessage(MSG_CAMERA_FOUCS);
} }
public List<Size> getSupportedPreviewSizes(){ public List<Size> getSupportedPreviewSizes() {
return mWeakThread.get().getSupportedSizes(); return mWeakThread.get().getSupportedSizes();
} }
@ -345,7 +351,7 @@ public abstract class AbstractUVCCameraHandler extends Handler {
if (thread == null) return; if (thread == null) return;
switch (msg.what) { switch (msg.what) {
case MSG_OPEN: case MSG_OPEN:
thread.handleOpen((USBMonitor.UsbControlBlock)msg.obj); thread.handleOpen((USBMonitor.UsbControlBlock) msg.obj);
break; break;
case MSG_CLOSE: case MSG_CLOSE:
thread.handleClose(); thread.handleClose();
@ -358,17 +364,17 @@ public abstract class AbstractUVCCameraHandler extends Handler {
break; break;
case MSG_CAPTURE_STILL: case MSG_CAPTURE_STILL:
// thread.handleCaptureStill((String)msg.obj); // thread.handleCaptureStill((String)msg.obj);
thread.handleStillPicture((String)msg.obj); thread.handleStillPicture((String) msg.obj);
break; break;
case MSG_CAPTURE_START: case MSG_CAPTURE_START:
// thread.handleStartRecording((String)msg.obj); // thread.handleStartRecording((String)msg.obj);
thread.handleStartRecording((RecordParams)msg.obj); thread.handleStartPusher((RecordParams) msg.obj);
break; break;
case MSG_CAPTURE_STOP: case MSG_CAPTURE_STOP:
thread.handleStopRecording(); thread.handleStopPusher();
break; break;
case MSG_MEDIA_UPDATE: case MSG_MEDIA_UPDATE:
thread.handleUpdateMedia((String)msg.obj); thread.handleUpdateMedia((String) msg.obj);
break; break;
case MSG_RELEASE: case MSG_RELEASE:
thread.handleRelease(); thread.handleRelease();
@ -402,14 +408,16 @@ public abstract class AbstractUVCCameraHandler extends Handler {
// 处理与Camera相关的逻辑,比如获取byte数据流等 // 处理与Camera相关的逻辑,比如获取byte数据流等
private UVCCamera mUVCCamera; private UVCCamera mUVCCamera;
// private MediaMuxerWrapper mMuxer; // private MediaMuxerWrapper mMuxer;
private MediaVideoBufferEncoder mVideoEncoder; private MediaVideoBufferEncoder mVideoEncoder;
private Mp4MediaMuxer mMuxer; private Mp4MediaMuxer mMuxer;
private boolean isPushing;
private String videoPath; private String videoPath;
// private boolean isAudioThreadStart; // private boolean isAudioThreadStart;
/** 构造方法 /**
* * 构造方法
* <p>
* clazz 继承于AbstractUVCCameraHandler * clazz 继承于AbstractUVCCameraHandler
* parent Activity子类 * parent Activity子类
* cameraView 用于捕获静止图像 * cameraView 用于捕获静止图像
@ -480,7 +488,7 @@ public abstract class AbstractUVCCameraHandler extends Handler {
public boolean isRecording() { public boolean isRecording() {
synchronized (mSync) { synchronized (mSync) {
return (mUVCCamera != null) && (mMuxer != null); return (mUVCCamera != null) && (mH264Consumer != null);
} }
} }
@ -507,12 +515,13 @@ public abstract class AbstractUVCCameraHandler extends Handler {
} catch (final Exception e) { } catch (final Exception e) {
callOnError(e); callOnError(e);
} }
if (DEBUG) Log.i(TAG, "supportedSize:" + (mUVCCamera != null ? mUVCCamera.getSupportedSize() : null)); if (DEBUG)
Log.i(TAG, "supportedSize:" + (mUVCCamera != null ? mUVCCamera.getSupportedSize() : null));
} }
public void handleClose() { public void handleClose() {
if (DEBUG) Log.v(TAG_THREAD, "handleClose:"); if (DEBUG) Log.v(TAG_THREAD, "handleClose:");
handleStopRecording(); handleStopPusher();
final UVCCamera camera; final UVCCamera camera;
synchronized (mSync) { synchronized (mSync) {
camera = mUVCCamera; camera = mUVCCamera;
@ -544,11 +553,12 @@ public abstract class AbstractUVCCameraHandler extends Handler {
} }
} }
if (surface instanceof SurfaceHolder) { if (surface instanceof SurfaceHolder) {
mUVCCamera.setPreviewDisplay((SurfaceHolder)surface); mUVCCamera.setPreviewDisplay((SurfaceHolder) surface);
} if (surface instanceof Surface) { }
mUVCCamera.setPreviewDisplay((Surface)surface); if (surface instanceof Surface) {
mUVCCamera.setPreviewDisplay((Surface) surface);
} else { } else {
mUVCCamera.setPreviewTexture((SurfaceTexture)surface); mUVCCamera.setPreviewTexture((SurfaceTexture) surface);
} }
mUVCCamera.startPreview(); mUVCCamera.startPreview();
mUVCCamera.updateCameraParams(); mUVCCamera.updateCameraParams();
@ -581,7 +591,7 @@ public abstract class AbstractUVCCameraHandler extends Handler {
if (parent == null) return; if (parent == null) return;
// mSoundPool.play(mSoundId, 0.2f, 0.2f, 0, 0, 1.0f); // play shutter sound // mSoundPool.play(mSoundId, 0.2f, 0.2f, 0, 0, 1.0f); // play shutter sound
try { try {
final Bitmap bitmap = mWeakCameraView.get().captureStillImage(mWidth,mHeight); final Bitmap bitmap = mWeakCameraView.get().captureStillImage(mWidth, mHeight);
// get buffered output stream for saving a captured still image as a file on external storage. // get buffered output stream for saving a captured still image as a file on external storage.
// the file name is came from current time. // the file name is came from current time.
// You should use extension name as same as CompressFormat when calling Bitmap#compress. // You should use extension name as same as CompressFormat when calling Bitmap#compress.
@ -599,7 +609,7 @@ public abstract class AbstractUVCCameraHandler extends Handler {
} finally { } finally {
os.close(); os.close();
} }
if(mCaptureListener != null) { if (mCaptureListener != null) {
mCaptureListener.onCaptureResult(path); mCaptureListener.onCaptureResult(path);
} }
} catch (final Exception e) { } catch (final Exception e) {
@ -652,34 +662,33 @@ public abstract class AbstractUVCCameraHandler extends Handler {
private AACEncodeConsumer mAacConsumer; private AACEncodeConsumer mAacConsumer;
private H264EncodeConsumer mH264Consumer; private H264EncodeConsumer mH264Consumer;
public void handleStartRecording(RecordParams params){ public void handleStartPusher(RecordParams params) {
if ((mUVCCamera == null) || (mMuxer != null)) if ((mUVCCamera == null) || (mH264Consumer != null))
return; return;
if (params == null)
throw new NullPointerException("RecordParams can not be null!");
// // 获取USB Camera预览数据 // // 获取USB Camera预览数据
// mUVCCamera.setFrameCallback(mIFrameCallback, UVCCamera.PIXEL_FORMAT_NV21); // mUVCCamera.setFrameCallback(mIFrameCallback, UVCCamera.PIXEL_FORMAT_NV21);
// 初始化混合器 // 初始化混合器
if (params != null) {
videoPath = params.getRecordPath(); videoPath = params.getRecordPath();
mMuxer = new Mp4MediaMuxer(params.getRecordPath(), mMuxer = new Mp4MediaMuxer(params.getRecordPath(),
params.getRecordDuration() * 60 * 1000,params.isVoiceClose()); params.getRecordDuration() * 60 * 1000, params.isVoiceClose());
}
// 启动视频编码线程 // 启动视频编码线程
startVideoRecord(); startVideoRecord();
// 启动音频编码线程 // 启动音频编码线程
if(! params.isVoiceClose()) { if (!params.isVoiceClose()) {
startAudioRecord(); startAudioRecord();
} }
callOnStartRecording(); callOnStartRecording();
} }
public void handleStopRecording(){ public void handleStopPusher() {
// 停止混合器 // 停止混合器
if (mMuxer != null){ if (mMuxer != null) {
mMuxer.release(); mMuxer.release();
mMuxer = null; mMuxer = null;
Log.i(TAG,TAG+"---->停止本地录制"); Log.i(TAG, TAG + "---->停止本地录制");
} }
// 停止音视频编码线程 // 停止音视频编码线程
stopAudioRecord(); stopAudioRecord();
@ -692,36 +701,38 @@ public abstract class AbstractUVCCameraHandler extends Handler {
// you should not wait here // you should not wait here
callOnStopRecording(); callOnStopRecording();
// 返回路径 // 返回路径
if(mListener != null) { if (mListener != null) {
mListener.onRecordResult(videoPath+".mp4"); mListener.onRecordResult(videoPath + ".mp4");
} }
} }
private void startVideoRecord() { private void startVideoRecord() {
mH264Consumer = new H264EncodeConsumer(getWidth(),getHeight()); mH264Consumer = new H264EncodeConsumer(getWidth(), getHeight());
mH264Consumer.setOnH264EncodeResultListener(new H264EncodeConsumer.OnH264EncodeResultListener() { mH264Consumer.setOnH264EncodeResultListener(new H264EncodeConsumer.OnH264EncodeResultListener() {
@Override @Override
public void onEncodeResult(byte[] data, int offset, int length, long timestamp) { public void onEncodeResult(byte[] data, int offset, int length, long timestamp) {
if(mListener != null){ if (mListener != null) {
mListener.onEncodeResult(data,offset,length,timestamp,1); mListener.onEncodeResult(data, offset, length, timestamp, 1);
} }
} }
}); });
mH264Consumer.start(); mH264Consumer.start();
// 添加混合器 // 添加混合器
if(mH264Consumer != null){ if (mMuxer != null) {
if (mH264Consumer != null) {
mH264Consumer.setTmpuMuxer(mMuxer); mH264Consumer.setTmpuMuxer(mMuxer);
} }
} }
}
private void stopVideoRecord(){ private void stopVideoRecord() {
if(mH264Consumer != null){ if (mH264Consumer != null) {
mH264Consumer.exit(); mH264Consumer.exit();
mH264Consumer.setTmpuMuxer(null); mH264Consumer.setTmpuMuxer(null);
try { try {
Thread t2 = mH264Consumer; Thread t2 = mH264Consumer;
mH264Consumer = null; mH264Consumer = null;
if(t2 != null){ if (t2 != null) {
t2.interrupt(); t2.interrupt();
t2.join(); t2.join();
} }
@ -731,31 +742,33 @@ public abstract class AbstractUVCCameraHandler extends Handler {
} }
} }
private void startAudioRecord(){ private void startAudioRecord() {
mAacConsumer = new AACEncodeConsumer(); mAacConsumer = new AACEncodeConsumer();
mAacConsumer.setOnAACEncodeResultListener(new AACEncodeConsumer.OnAACEncodeResultListener() { mAacConsumer.setOnAACEncodeResultListener(new AACEncodeConsumer.OnAACEncodeResultListener() {
@Override @Override
public void onEncodeResult(byte[] data, int offset, int length, long timestamp) { public void onEncodeResult(byte[] data, int offset, int length, long timestamp) {
if(mListener != null){ if (mListener != null) {
mListener.onEncodeResult(data,offset,length,timestamp,0); mListener.onEncodeResult(data, offset, length, timestamp, 0);
} }
} }
}); });
mAacConsumer.start(); mAacConsumer.start();
// 添加混合器 // 添加混合器
if(mAacConsumer != null){ if (mMuxer != null) {
if (mAacConsumer != null) {
mAacConsumer.setTmpuMuxer(mMuxer); mAacConsumer.setTmpuMuxer(mMuxer);
} }
} }
}
private void stopAudioRecord(){ private void stopAudioRecord() {
if(mAacConsumer != null){ if (mAacConsumer != null) {
mAacConsumer.exit(); mAacConsumer.exit();
mAacConsumer.setTmpuMuxer(null); mAacConsumer.setTmpuMuxer(null);
try { try {
Thread t1 = mAacConsumer; Thread t1 = mAacConsumer;
mAacConsumer = null; mAacConsumer = null;
if(t1 != null){ if (t1 != null) {
t1.interrupt(); t1.interrupt();
t1.join(); t1.join();
} }
@ -788,34 +801,34 @@ public abstract class AbstractUVCCameraHandler extends Handler {
final byte[] yuv = new byte[len]; final byte[] yuv = new byte[len];
frame.get(yuv); frame.get(yuv);
// nv21 yuv data callback // nv21 yuv data callback
if(mPreviewListener != null) { if (mPreviewListener != null) {
mPreviewListener.onPreviewResult(yuv); mPreviewListener.onPreviewResult(yuv);
} }
// 捕获图片 // 捕获图片
if(isCaptureStill && ! TextUtils.isEmpty(picPath)) { if (isCaptureStill && !TextUtils.isEmpty(picPath)) {
isCaptureStill = false; isCaptureStill = false;
new Thread(new Runnable() { new Thread(new Runnable() {
@Override @Override
public void run() { public void run() {
saveYuv2Jpeg(picPath,yuv); saveYuv2Jpeg(picPath, yuv);
} }
}).start(); }).start();
isCaptureStill = false; isCaptureStill = false;
} }
// 视频 // 视频
if(mH264Consumer != null){ if (mH264Consumer != null) {
// 修改分辨率参数 // 修改分辨率参数
mH264Consumer.setRawYuv(yuv,mWidth,mHeight); mH264Consumer.setRawYuv(yuv, mWidth, mHeight);
} }
} }
}; };
private void saveYuv2Jpeg(String path,byte[] data){ private void saveYuv2Jpeg(String path, byte[] data) {
YuvImage yuvImage = new YuvImage(data, ImageFormat.NV21, mWidth, mHeight, null); YuvImage yuvImage = new YuvImage(data, ImageFormat.NV21, mWidth, mHeight, null);
ByteArrayOutputStream bos = new ByteArrayOutputStream(data.length); ByteArrayOutputStream bos = new ByteArrayOutputStream(data.length);
boolean result = yuvImage.compressToJpeg(new Rect(0, 0, mWidth, mHeight), 100, bos); boolean result = yuvImage.compressToJpeg(new Rect(0, 0, mWidth, mHeight), 100, bos);
if(result){ if (result) {
byte[] buffer = bos.toByteArray(); byte[] buffer = bos.toByteArray();
Bitmap bmp = BitmapFactory.decodeByteArray(buffer, 0, buffer.length); Bitmap bmp = BitmapFactory.decodeByteArray(buffer, 0, buffer.length);
@ -831,7 +844,7 @@ public abstract class AbstractUVCCameraHandler extends Handler {
fos.flush(); fos.flush();
fos.close(); fos.close();
bmp.recycle(); bmp.recycle();
if(mCaptureListener != null) { if (mCaptureListener != null) {
mCaptureListener.onCaptureResult(path); mCaptureListener.onCaptureResult(path);
} }
} catch (IOException e) { } catch (IOException e) {
@ -853,7 +866,7 @@ public abstract class AbstractUVCCameraHandler extends Handler {
if (parent != null && parent.getApplicationContext() != null) { if (parent != null && parent.getApplicationContext() != null) {
try { try {
if (DEBUG) Log.i(TAG, "MediaScannerConnection#scanFile"); if (DEBUG) Log.i(TAG, "MediaScannerConnection#scanFile");
MediaScannerConnection.scanFile(parent.getApplicationContext(), new String[]{ path }, null, null); MediaScannerConnection.scanFile(parent.getApplicationContext(), new String[]{path}, null, null);
} catch (final Exception e) { } catch (final Exception e) {
Log.e(TAG, "handleUpdateMedia:", e); Log.e(TAG, "handleUpdateMedia:", e);
} }
@ -900,14 +913,14 @@ public abstract class AbstractUVCCameraHandler extends Handler {
mIsRecording = true; mIsRecording = true;
if (encoder instanceof MediaVideoEncoder) if (encoder instanceof MediaVideoEncoder)
try { try {
mWeakCameraView.get().setVideoEncoder((MediaVideoEncoder)encoder); mWeakCameraView.get().setVideoEncoder((MediaVideoEncoder) encoder);
} catch (final Exception e) { } catch (final Exception e) {
Log.e(TAG, "onPrepared:", e); Log.e(TAG, "onPrepared:", e);
} }
if (encoder instanceof MediaSurfaceEncoder) if (encoder instanceof MediaSurfaceEncoder)
try { try {
mWeakCameraView.get().setVideoEncoder((MediaSurfaceEncoder)encoder); mWeakCameraView.get().setVideoEncoder((MediaSurfaceEncoder) encoder);
mUVCCamera.startCapture(((MediaSurfaceEncoder)encoder).getInputSurface()); mUVCCamera.startCapture(((MediaSurfaceEncoder) encoder).getInputSurface());
} catch (final Exception e) { } catch (final Exception e) {
Log.e(TAG, "onPrepared:", e); Log.e(TAG, "onPrepared:", e);
} }
@ -944,7 +957,7 @@ public abstract class AbstractUVCCameraHandler extends Handler {
@Override @Override
public void onEncodeResult(byte[] data, int offset, int length, long timestamp, int type) { public void onEncodeResult(byte[] data, int offset, int length, long timestamp, int type) {
if(mListener != null){ if (mListener != null) {
mListener.onEncodeResult(data, offset, length, timestamp, type); mListener.onEncodeResult(data, offset, length, timestamp, type);
} }
} }
@ -1037,7 +1050,7 @@ public abstract class AbstractUVCCameraHandler extends Handler {
} }
private void callOnOpen() { private void callOnOpen() {
for (final CameraCallback callback: mCallbacks) { for (final CameraCallback callback : mCallbacks) {
try { try {
callback.onOpen(); callback.onOpen();
} catch (final Exception e) { } catch (final Exception e) {
@ -1048,7 +1061,7 @@ public abstract class AbstractUVCCameraHandler extends Handler {
} }
private void callOnClose() { private void callOnClose() {
for (final CameraCallback callback: mCallbacks) { for (final CameraCallback callback : mCallbacks) {
try { try {
callback.onClose(); callback.onClose();
} catch (final Exception e) { } catch (final Exception e) {
@ -1059,7 +1072,7 @@ public abstract class AbstractUVCCameraHandler extends Handler {
} }
private void callOnStartPreview() { private void callOnStartPreview() {
for (final CameraCallback callback: mCallbacks) { for (final CameraCallback callback : mCallbacks) {
try { try {
callback.onStartPreview(); callback.onStartPreview();
} catch (final Exception e) { } catch (final Exception e) {
@ -1070,7 +1083,7 @@ public abstract class AbstractUVCCameraHandler extends Handler {
} }
private void callOnStopPreview() { private void callOnStopPreview() {
for (final CameraCallback callback: mCallbacks) { for (final CameraCallback callback : mCallbacks) {
try { try {
callback.onStopPreview(); callback.onStopPreview();
} catch (final Exception e) { } catch (final Exception e) {
@ -1081,7 +1094,7 @@ public abstract class AbstractUVCCameraHandler extends Handler {
} }
private void callOnStartRecording() { private void callOnStartRecording() {
for (final CameraCallback callback: mCallbacks) { for (final CameraCallback callback : mCallbacks) {
try { try {
callback.onStartRecording(); callback.onStartRecording();
} catch (final Exception e) { } catch (final Exception e) {
@ -1092,7 +1105,7 @@ public abstract class AbstractUVCCameraHandler extends Handler {
} }
private void callOnStopRecording() { private void callOnStopRecording() {
for (final CameraCallback callback: mCallbacks) { for (final CameraCallback callback : mCallbacks) {
try { try {
callback.onStopRecording(); callback.onStopRecording();
} catch (final Exception e) { } catch (final Exception e) {
@ -1103,7 +1116,7 @@ public abstract class AbstractUVCCameraHandler extends Handler {
} }
private void callOnError(final Exception e) { private void callOnError(final Exception e) {
for (final CameraCallback callback: mCallbacks) { for (final CameraCallback callback : mCallbacks) {
try { try {
callback.onError(e); callback.onError(e);
} catch (final Exception e1) { } catch (final Exception e1) {

Loading…
Cancel
Save