├── app
├── .gitignore
├── src
│ ├── main
│ │ ├── res
│ │ │ ├── values
│ │ │ │ ├── strings.xml
│ │ │ │ ├── colors.xml
│ │ │ │ └── styles.xml
│ │ │ ├── drawable
│ │ │ │ └── cover.jpg
│ │ │ ├── mipmap-hdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-mdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-xhdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-xxhdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-xxxhdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-anydpi-v26
│ │ │ │ ├── ic_launcher.xml
│ │ │ │ └── ic_launcher_round.xml
│ │ │ ├── layout
│ │ │ │ ├── activity_opengl_player.xml
│ │ │ │ ├── activity_simpler_render.xml
│ │ │ │ ├── activity_egl_player.xml
│ │ │ │ ├── activity_ffmpeg_info.xml
│ │ │ │ ├── activity_synthesizer.xml
│ │ │ │ ├── activity_simple_player.xml
│ │ │ │ └── activity_main.xml
│ │ │ └── drawable-v24
│ │ │ │ └── ic_launcher_foreground.xml
│ │ ├── jniLibs
│ │ │ ├── x86
│ │ │ │ ├── libavcodec.so
│ │ │ │ ├── libavutil.so
│ │ │ │ ├── libswscale.so
│ │ │ │ ├── libavdevice.so
│ │ │ │ ├── libavfilter.so
│ │ │ │ ├── libavformat.so
│ │ │ │ └── libswresample.so
│ │ │ └── armeabi-v7a
│ │ │ │ ├── libavutil.so
│ │ │ │ ├── libavcodec.so
│ │ │ │ ├── libavdevice.so
│ │ │ │ ├── libavfilter.so
│ │ │ │ ├── libavformat.so
│ │ │ │ ├── libswscale.so
│ │ │ │ └── libswresample.so
│ │ ├── cpp
│ │ │ ├── ffmpeg
│ │ │ │ └── include
│ │ │ │ │ ├── libavutil
│ │ │ │ │ ├── avconfig.h
│ │ │ │ │ ├── ffversion.h
│ │ │ │ │ ├── hwcontext_mediacodec.h
│ │ │ │ │ ├── macros.h
│ │ │ │ │ ├── hwcontext_vdpau.h
│ │ │ │ │ ├── random_seed.h
│ │ │ │ │ ├── hwcontext_cuda.h
│ │ │ │ │ ├── hwcontext_qsv.h
│ │ │ │ │ ├── replaygain.h
│ │ │ │ │ ├── adler32.h
│ │ │ │ │ ├── motion_vector.h
│ │ │ │ │ ├── time.h
│ │ │ │ │ ├── intfloat.h
│ │ │ │ │ ├── aes.h
│ │ │ │ │ ├── hwcontext_videotoolbox.h
│ │ │ │ │ ├── rc4.h
│ │ │ │ │ ├── pixelutils.h
│ │ │ │ │ ├── lzo.h
│ │ │ │ │ ├── tea.h
│ │ │ │ │ ├── camellia.h
│ │ │ │ │ ├── twofish.h
│ │ │ │ │ ├── base64.h
│ │ │ │ │ ├── aes_ctr.h
│ │ │ │ │ ├── des.h
│ │ │ │ │ ├── ripemd.h
│ │ │ │ │ ├── avassert.h
│ │ │ │ │ ├── hwcontext_dxva2.h
│ │ │ │ │ ├── blowfish.h
│ │ │ │ │ ├── md5.h
│ │ │ │ │ ├── lfg.h
│ │ │ │ │ ├── cast5.h
│ │ │ │ │ ├── sha.h
│ │ │ │ │ ├── timestamp.h
│ │ │ │ │ ├── sha512.h
│ │ │ │ │ ├── file.h
│ │ │ │ │ ├── tx.h
│ │ │ │ │ ├── xtea.h
│ │ │ │ │ ├── hmac.h
│ │ │ │ │ ├── bswap.h
│ │ │ │ │ ├── crc.h
│ │ │ │ │ └── downmix_info.h
│ │ │ │ │ ├── libavcodec
│ │ │ │ │ ├── ac3_parser.h
│ │ │ │ │ ├── adts_parser.h
│ │ │ │ │ ├── jni.h
│ │ │ │ │ ├── vorbis_parser.h
│ │ │ │ │ ├── vaapi.h
│ │ │ │ │ ├── dxva2.h
│ │ │ │ │ ├── avdct.h
│ │ │ │ │ ├── d3d11va.h
│ │ │ │ │ └── avfft.h
│ │ │ │ │ ├── libswresample
│ │ │ │ │ └── version.h
│ │ │ │ │ ├── libavdevice
│ │ │ │ │ └── version.h
│ │ │ │ │ ├── libswscale
│ │ │ │ │ └── version.h
│ │ │ │ │ └── libavfilter
│ │ │ │ │ └── version.h
│ │ │ ├── native-lib.cpp
│ │ │ └── CMakeLists.txt
│ │ ├── java
│ │ │ └── com
│ │ │ │ └── cxp
│ │ │ │ └── learningvideo
│ │ │ │ ├── media
│ │ │ │ ├── encoder
│ │ │ │ │ ├── IEncodeStateListener.kt
│ │ │ │ │ ├── DefEncodeStateListener.kt
│ │ │ │ │ ├── AudioEncoder.kt
│ │ │ │ │ └── VideoEncoder.kt
│ │ │ │ ├── DecodeState.kt
│ │ │ │ ├── IDecorderProgress.kt
│ │ │ │ ├── Frame.kt
│ │ │ │ ├── IDecoderStateListener.kt
│ │ │ │ ├── IExtractor.kt
│ │ │ │ ├── decoder
│ │ │ │ │ ├── DefDecodeStateListener.kt
│ │ │ │ │ ├── VideoDecoder.kt
│ │ │ │ │ └── AudioDecoder.kt
│ │ │ │ ├── extractor
│ │ │ │ │ ├── AudioExtractor.kt
│ │ │ │ │ ├── VideoExtractor.kt
│ │ │ │ │ └── MMExtractor.kt
│ │ │ │ ├── IDecoder.kt
│ │ │ │ └── muxer
│ │ │ │ │ └── MP4Repack.kt
│ │ │ │ ├── MainApp.kt
│ │ │ │ ├── opengl
│ │ │ │ ├── drawer
│ │ │ │ │ └── IDrawer.kt
│ │ │ │ ├── DefGLSurfaceView.kt
│ │ │ │ ├── SimpleRender.kt
│ │ │ │ ├── egl
│ │ │ │ │ └── EGLSurfaceHolder.kt
│ │ │ │ └── OpenGLTools.kt
│ │ │ │ ├── FFmpegActivity.kt
│ │ │ │ ├── SimpleRenderActivity.kt
│ │ │ │ ├── MainActivity.kt
│ │ │ │ ├── SimplePlayerActivity.kt
│ │ │ │ ├── utils
│ │ │ │ └── Test.kt
│ │ │ │ ├── OpenGLPlayerActivity.kt
│ │ │ │ ├── SoulPlayerActivity.kt
│ │ │ │ ├── EGLPlayerActivity.kt
│ │ │ │ └── MultiOpenGLPlayerActivity.kt
│ │ └── AndroidManifest.xml
│ ├── test
│ │ └── java
│ │ │ └── com
│ │ │ └── cxp
│ │ │ └── learningvideo
│ │ │ └── ExampleUnitTest.kt
│ └── androidTest
│ │ └── java
│ │ └── com
│ │ └── cxp
│ │ └── learningvideo
│ │ └── ExampleInstrumentedTest.kt
├── proguard-rules.pro
└── build.gradle
├── settings.gradle
├── cover.jpg
├── qrcode_for_wx.jpg
├── .gitignore
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradle.properties
├── README.md
└── gradlew.bat
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app'
2 |
--------------------------------------------------------------------------------
/cover.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/githubhaohao/LearningVideo/HEAD/cover.jpg
--------------------------------------------------------------------------------
/qrcode_for_wx.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/githubhaohao/LearningVideo/HEAD/qrcode_for_wx.jpg
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea/*
5 | .DS_Store
6 | /build
7 | /captures
8 | .externalNativeBuild
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | Learning Video
3 |
4 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/githubhaohao/LearningVideo/HEAD/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/app/src/main/res/drawable/cover.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/githubhaohao/LearningVideo/HEAD/app/src/main/res/drawable/cover.jpg
--------------------------------------------------------------------------------
/app/src/main/jniLibs/x86/libavcodec.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/githubhaohao/LearningVideo/HEAD/app/src/main/jniLibs/x86/libavcodec.so
--------------------------------------------------------------------------------
/app/src/main/jniLibs/x86/libavutil.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/githubhaohao/LearningVideo/HEAD/app/src/main/jniLibs/x86/libavutil.so
--------------------------------------------------------------------------------
/app/src/main/jniLibs/x86/libswscale.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/githubhaohao/LearningVideo/HEAD/app/src/main/jniLibs/x86/libswscale.so
--------------------------------------------------------------------------------
/app/src/main/jniLibs/x86/libavdevice.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/githubhaohao/LearningVideo/HEAD/app/src/main/jniLibs/x86/libavdevice.so
--------------------------------------------------------------------------------
/app/src/main/jniLibs/x86/libavfilter.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/githubhaohao/LearningVideo/HEAD/app/src/main/jniLibs/x86/libavfilter.so
--------------------------------------------------------------------------------
/app/src/main/jniLibs/x86/libavformat.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/githubhaohao/LearningVideo/HEAD/app/src/main/jniLibs/x86/libavformat.so
--------------------------------------------------------------------------------
/app/src/main/jniLibs/x86/libswresample.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/githubhaohao/LearningVideo/HEAD/app/src/main/jniLibs/x86/libswresample.so
--------------------------------------------------------------------------------
/app/src/main/jniLibs/armeabi-v7a/libavutil.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/githubhaohao/LearningVideo/HEAD/app/src/main/jniLibs/armeabi-v7a/libavutil.so
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/githubhaohao/LearningVideo/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/githubhaohao/LearningVideo/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/githubhaohao/LearningVideo/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/jniLibs/armeabi-v7a/libavcodec.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/githubhaohao/LearningVideo/HEAD/app/src/main/jniLibs/armeabi-v7a/libavcodec.so
--------------------------------------------------------------------------------
/app/src/main/jniLibs/armeabi-v7a/libavdevice.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/githubhaohao/LearningVideo/HEAD/app/src/main/jniLibs/armeabi-v7a/libavdevice.so
--------------------------------------------------------------------------------
/app/src/main/jniLibs/armeabi-v7a/libavfilter.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/githubhaohao/LearningVideo/HEAD/app/src/main/jniLibs/armeabi-v7a/libavfilter.so
--------------------------------------------------------------------------------
/app/src/main/jniLibs/armeabi-v7a/libavformat.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/githubhaohao/LearningVideo/HEAD/app/src/main/jniLibs/armeabi-v7a/libavformat.so
--------------------------------------------------------------------------------
/app/src/main/jniLibs/armeabi-v7a/libswscale.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/githubhaohao/LearningVideo/HEAD/app/src/main/jniLibs/armeabi-v7a/libswscale.so
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/githubhaohao/LearningVideo/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/githubhaohao/LearningVideo/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/jniLibs/armeabi-v7a/libswresample.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/githubhaohao/LearningVideo/HEAD/app/src/main/jniLibs/armeabi-v7a/libswresample.so
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/githubhaohao/LearningVideo/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/githubhaohao/LearningVideo/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/githubhaohao/LearningVideo/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/githubhaohao/LearningVideo/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/githubhaohao/LearningVideo/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/cpp/ffmpeg/include/libavutil/avconfig.h:
--------------------------------------------------------------------------------
1 | /* Generated by ffmpeg configure */
2 | #ifndef AVUTIL_AVCONFIG_H
3 | #define AVUTIL_AVCONFIG_H
4 | #define AV_HAVE_BIGENDIAN 0
5 | #define AV_HAVE_FAST_UNALIGNED 1
6 | #endif /* AVUTIL_AVCONFIG_H */
7 |
--------------------------------------------------------------------------------
/app/src/main/cpp/ffmpeg/include/libavutil/ffversion.h:
--------------------------------------------------------------------------------
1 | /* Automatically generated by version.sh, do not manually edit! */
2 | #ifndef AVUTIL_FFVERSION_H
3 | #define AVUTIL_FFVERSION_H
4 | #define FFMPEG_VERSION "4.2.2"
5 | #endif /* AVUTIL_FFVERSION_H */
6 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #008577
4 | #00574B
5 | #D81B60
6 |
7 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Mon Sep 02 09:37:42 CST 2019
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-all.zip
7 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/main/java/com/cxp/learningvideo/media/encoder/IEncodeStateListener.kt:
--------------------------------------------------------------------------------
1 | package com.cxp.learningvideo.media.encoder
2 |
3 |
4 | /**
5 | * 编码状态回调接口
6 | *
7 | * @author Chen Xiaoping (562818444@qq.com)
8 | * @since LearningVideo
9 | * @version LearningVideo
10 | *
11 | */
12 | interface IEncodeStateListener {
13 | fun encodeStart(encoder: BaseEncoder)
14 | fun encodeProgress(encoder: BaseEncoder)
15 | fun encoderFinish(encoder: BaseEncoder)
16 | }
--------------------------------------------------------------------------------
/app/src/test/java/com/cxp/learningvideo/ExampleUnitTest.kt:
--------------------------------------------------------------------------------
1 | package com.cxp.learningvideo
2 |
3 | import org.junit.Test
4 |
5 | import org.junit.Assert.*
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * See [testing documentation](http://d.android.com/tools/testing).
11 | */
12 | class ExampleUnitTest {
13 | @Test
14 | fun addition_isCorrect() {
15 | assertEquals(4, 2 + 2)
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/app/src/main/java/com/cxp/learningvideo/media/DecodeState.kt:
--------------------------------------------------------------------------------
1 | package com.cxp.learningvideo.media
2 |
3 |
4 | /**
5 | * 解码状态
6 | *
7 | * @author Chen Xiaoping (562818444@qq.com)
8 | * @since LearningVideo
9 | * @version LearningVideo
10 | * @Datetime 2019-09-02 10:00
11 | *
12 | */
13 | enum class DecodeState {
14 | /**开始状态*/
15 | START,
16 | /**解码中*/
17 | DECODING,
18 | /**解码暂停*/
19 | PAUSE,
20 | /**正在快进*/
21 | SEEKING,
22 | /**解码完成*/
23 | FINISH,
24 | /**解码器释放*/
25 | STOP
26 | }
27 |
--------------------------------------------------------------------------------
/app/src/main/java/com/cxp/learningvideo/media/IDecorderProgress.kt:
--------------------------------------------------------------------------------
1 | package com.cxp.learningvideo.media
2 |
3 |
4 | /**
5 | * 解码进度
6 | *
7 | * @author Chen Xiaoping (562818444@qq.com)
8 | * @since LearningVideo
9 | * @version LearningVideo
10 | * @Datetime 2019-09-02 09:54
11 | *
12 | */
13 | interface IDecoderProgress {
14 | /**
15 | * 视频宽高回调
16 | */
17 | fun videoSizeChange(width: Int, height: Int, rotationAngle: Int)
18 |
19 | /**
20 | * 视频播放进度回调
21 | */
22 | fun videoProgressChange(pos: Long)
23 | }
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_opengl_player.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
10 |
--------------------------------------------------------------------------------
/app/src/main/java/com/cxp/learningvideo/media/encoder/DefEncodeStateListener.kt:
--------------------------------------------------------------------------------
1 | package com.cxp.learningvideo.media.encoder
2 |
3 |
4 | /**
5 | * 默认编码回调接口
6 | *
7 | * @author Chen Xiaoping (562818444@qq.com)
8 | * @since LearningVideo
9 | * @version LearningVideo
10 | *
11 | */
12 | interface DefEncodeStateListener: IEncodeStateListener {
13 |
14 | override fun encodeStart(encoder: BaseEncoder) {
15 |
16 | }
17 |
18 | override fun encodeProgress(encoder: BaseEncoder) {
19 |
20 | }
21 |
22 | override fun encoderFinish(encoder: BaseEncoder) {
23 |
24 | }
25 | }
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_simpler_render.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
9 |
--------------------------------------------------------------------------------
/app/src/main/java/com/cxp/learningvideo/MainApp.kt:
--------------------------------------------------------------------------------
1 | package com.cxp.learningvideo
2 |
3 | import android.annotation.SuppressLint
4 | import android.app.Application
5 | import android.content.Context
6 |
7 |
8 | /**
9 | *
10 | * @author Chen Xiaoping (562818444@qq.com)
11 | * @since LearningVideo
12 | * @version LearningVideo
13 | * @Datetime 2019-10-10 09:28
14 | *
15 | */
16 |
17 | @SuppressLint("StaticFieldLeak")
18 | var CONTEXT: Context? = null
19 |
20 | class MainApp: Application() {
21 |
22 |
23 | override fun onCreate() {
24 | super.onCreate()
25 | CONTEXT = this
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_egl_player.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
11 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_ffmpeg_info.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
8 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/main/java/com/cxp/learningvideo/media/Frame.kt:
--------------------------------------------------------------------------------
1 | package com.cxp.learningvideo.media
2 |
3 | import android.media.MediaCodec
4 | import java.nio.ByteBuffer
5 |
6 |
7 | /**
8 | * 一帧数据
9 | *
10 | * @author Chen Xiaoping (562818444@qq.com)
11 | * @since LearningVideo
12 | * @version LearningVideo
13 | * @Datetime 2019-12-15 19:28
14 | *
15 | */
16 | class Frame {
17 | var buffer: ByteBuffer? = null
18 |
19 | var bufferInfo = MediaCodec.BufferInfo()
20 | private set
21 |
22 | fun setBufferInfo(info: MediaCodec.BufferInfo) {
23 | bufferInfo.set(info.offset, info.size, info.presentationTimeUs, info.flags)
24 | }
25 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/cxp/learningvideo/opengl/drawer/IDrawer.kt:
--------------------------------------------------------------------------------
1 | package com.cxp.learningvideo.opengl.drawer
2 |
3 | import android.graphics.SurfaceTexture
4 |
5 |
6 | /**
7 | * 渲染器
8 | *
9 | * @author Chen Xiaoping (562818444@qq.com)
10 | * @since LearningVideo
11 | * @version LearningVideo
12 | * @Datetime 2019-10-12 10:04
13 | *
14 | */
15 | interface IDrawer {
16 | fun setVideoSize(videoW: Int, videoH: Int)
17 | fun setWorldSize(worldW: Int, worldH: Int)
18 | fun setAlpha(alpha: Float)
19 | fun draw()
20 | fun setTextureID(id: Int)
21 | fun getSurfaceTexture(cb: (st: SurfaceTexture)->Unit) {}
22 | fun release()
23 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/cxp/learningvideo/media/IDecoderStateListener.kt:
--------------------------------------------------------------------------------
1 | package com.cxp.learningvideo.media
2 |
3 |
4 | /**
5 | * 解码状态回调接口
6 | *
7 | * @author Chen Xiaoping (562818444@qq.com)
8 | * @since LearningVideo
9 | * @version LearningVideo
10 | * @Datetime 2019-09-02 09:56
11 | *
12 | */
13 | interface IDecoderStateListener {
14 | fun decoderPrepare(decodeJob: BaseDecoder?)
15 | fun decoderReady(decodeJob: BaseDecoder?)
16 | fun decoderRunning(decodeJob: BaseDecoder?)
17 | fun decoderPause(decodeJob: BaseDecoder?)
18 | fun decodeOneFrame(decodeJob: BaseDecoder?, frame: Frame)
19 | fun decoderFinish(decodeJob: BaseDecoder?)
20 | fun decoderDestroy(decodeJob: BaseDecoder?)
21 | fun decoderError(decodeJob: BaseDecoder?, msg: String)
22 | }
--------------------------------------------------------------------------------
/app/src/androidTest/java/com/cxp/learningvideo/ExampleInstrumentedTest.kt:
--------------------------------------------------------------------------------
1 | package com.cxp.learningvideo
2 |
3 | import android.support.test.InstrumentationRegistry
4 | import android.support.test.runner.AndroidJUnit4
5 |
6 | import org.junit.Test
7 | import org.junit.runner.RunWith
8 |
9 | import org.junit.Assert.*
10 |
11 | /**
12 | * Instrumented test, which will execute on an Android device.
13 | *
14 | * See [testing documentation](http://d.android.com/tools/testing).
15 | */
16 | @RunWith(AndroidJUnit4::class)
17 | class ExampleInstrumentedTest {
18 | @Test
19 | fun useAppContext() {
20 | // Context of the app under test.
21 | val appContext = InstrumentationRegistry.getTargetContext()
22 | assertEquals("com.cxp.learningvideo", appContext.packageName)
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/app/src/main/java/com/cxp/learningvideo/FFmpegActivity.kt:
--------------------------------------------------------------------------------
1 | package com.cxp.learningvideo
2 |
3 | import android.os.Bundle
4 | import android.support.v7.app.AppCompatActivity
5 | import kotlinx.android.synthetic.main.activity_ffmpeg_info.*
6 |
7 |
8 | /**
9 | * FFmpeg测试页面
10 | *
11 | * @author Chen Xiaoping (562818444@qq.com)
12 | * @since LearningVideo
13 | * @version LearningVideo
14 | *
15 | */
16 | class FFmpegActivity: AppCompatActivity() {
17 | override fun onCreate(savedInstanceState: Bundle?) {
18 | super.onCreate(savedInstanceState)
19 | setContentView(R.layout.activity_ffmpeg_info)
20 | tv.text = ffmpegInfo()
21 | }
22 |
23 | private external fun ffmpegInfo(): String
24 |
25 | companion object {
26 | init {
27 | System.loadLibrary("native-lib")
28 | }
29 | }
30 | }
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_synthesizer.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
15 |
--------------------------------------------------------------------------------
/app/src/main/java/com/cxp/learningvideo/media/IExtractor.kt:
--------------------------------------------------------------------------------
1 | package com.cxp.learningvideo.media
2 |
3 | import android.media.MediaFormat
4 | import java.nio.ByteBuffer
5 |
6 |
7 | /**
8 | * 音视频分离器定义
9 | *
10 | * @author Chen Xiaoping (562818444@qq.com)
11 | * @since LearningVideo
12 | * @version LearningVideo
13 | * @Datetime 2019-09-02 10:07
14 | *
15 | */
16 | interface IExtractor {
17 |
18 | fun getFormat(): MediaFormat?
19 |
20 | /**
21 | * 读取音视频数据
22 | */
23 | fun readBuffer(byteBuffer: ByteBuffer): Int
24 |
25 | /**
26 | * 获取当前帧时间
27 | */
28 | fun getCurrentTimestamp(): Long
29 |
30 | fun getSampleFlag(): Int
31 |
32 | /**
33 | * Seek到指定位置,并返回实际帧的时间戳
34 | */
35 | fun seek(pos: Long): Long
36 |
37 | fun setStartPos(pos: Long)
38 |
39 | /**
40 | * 停止读取数据
41 | */
42 | fun stop()
43 | }
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 | # IDE (e.g. Android Studio) users:
3 | # Gradle settings configured through the IDE *will override*
4 | # any settings specified in this file.
5 | # For more details on how to configure your build environment visit
6 | # http://www.gradle.org/docs/current/userguide/build_environment.html
7 | # Specifies the JVM arguments used for the daemon process.
8 | # The setting is particularly useful for tweaking memory settings.
9 | org.gradle.jvmargs=-Xmx1536m
10 | # When configured, Gradle will run in incubating parallel mode.
11 | # This option should only be used with decoupled projects. More details, visit
12 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
13 | # org.gradle.parallel=true
14 | # Kotlin code style for this project: "official" or "obsolete":
15 | kotlin.code.style=official
16 |
--------------------------------------------------------------------------------
/app/src/main/java/com/cxp/learningvideo/media/decoder/DefDecodeStateListener.kt:
--------------------------------------------------------------------------------
1 | package com.cxp.learningvideo.media.decoder
2 |
3 | import com.cxp.learningvideo.media.BaseDecoder
4 | import com.cxp.learningvideo.media.Frame
5 | import com.cxp.learningvideo.media.IDecoderStateListener
6 |
7 |
8 | /**
9 | * 默认解码状态监听器
10 | *
11 | * @author Chen Xiaoping (562818444@qq.com)
12 | * @since LearningVideo
13 | * @version LearningVideo
14 | *
15 | */
16 | interface DefDecodeStateListener: IDecoderStateListener {
17 | override fun decoderPrepare(decodeJob: BaseDecoder?) {}
18 | override fun decoderReady(decodeJob: BaseDecoder?) {}
19 | override fun decoderRunning(decodeJob: BaseDecoder?) {}
20 | override fun decoderPause(decodeJob: BaseDecoder?) {}
21 | override fun decodeOneFrame(decodeJob: BaseDecoder?, frame: Frame) {}
22 | override fun decoderFinish(decodeJob: BaseDecoder?) {}
23 | override fun decoderDestroy(decodeJob: BaseDecoder?) {}
24 | override fun decoderError(decodeJob: BaseDecoder?, msg: String) {}
25 | }
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_simple_player.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
13 |
14 |
22 |
--------------------------------------------------------------------------------
/app/src/main/cpp/ffmpeg/include/libavcodec/ac3_parser.h:
--------------------------------------------------------------------------------
1 | /*
2 | * AC-3 parser prototypes
3 | * Copyright (c) 2003 Fabrice Bellard
4 | * Copyright (c) 2003 Michael Niedermayer
5 | *
6 | * This file is part of FFmpeg.
7 | *
8 | * FFmpeg is free software; you can redistribute it and/or
9 | * modify it under the terms of the GNU Lesser General Public
10 | * License as published by the Free Software Foundation; either
11 | * version 2.1 of the License, or (at your option) any later version.
12 | *
13 | * FFmpeg is distributed in the hope that it will be useful,
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 | * Lesser General Public License for more details.
17 | *
18 | * You should have received a copy of the GNU Lesser General Public
19 | * License along with FFmpeg; if not, write to the Free Software
20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 | */
22 |
23 | #ifndef AVCODEC_AC3_PARSER_H
24 | #define AVCODEC_AC3_PARSER_H
25 |
26 | #include
27 | #include
28 |
29 | /**
30 | * Extract the bitstream ID and the frame size from AC-3 data.
31 | */
32 | int av_ac3_parse_header(const uint8_t *buf, size_t size,
33 | uint8_t *bitstream_id, uint16_t *frame_size);
34 |
35 |
36 | #endif /* AVCODEC_AC3_PARSER_H */
37 |
--------------------------------------------------------------------------------
/app/src/main/cpp/ffmpeg/include/libavutil/hwcontext_mediacodec.h:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of FFmpeg.
3 | *
4 | * FFmpeg is free software; you can redistribute it and/or
5 | * modify it under the terms of the GNU Lesser General Public
6 | * License as published by the Free Software Foundation; either
7 | * version 2.1 of the License, or (at your option) any later version.
8 | *
9 | * FFmpeg is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 | * Lesser General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU Lesser General Public
15 | * License along with FFmpeg; if not, write to the Free Software
16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 | */
18 |
19 | #ifndef AVUTIL_HWCONTEXT_MEDIACODEC_H
20 | #define AVUTIL_HWCONTEXT_MEDIACODEC_H
21 |
22 | /**
23 | * MediaCodec details.
24 | *
25 | * Allocated as AVHWDeviceContext.hwctx
26 | */
27 | typedef struct AVMediaCodecDeviceContext {
28 | /**
29 | * android/view/Surface handle, to be filled by the user.
30 | *
31 | * This is the default surface used by decoders on this device.
32 | */
33 | void *surface;
34 | } AVMediaCodecDeviceContext;
35 |
36 | #endif /* AVUTIL_HWCONTEXT_MEDIACODEC_H */
37 |
--------------------------------------------------------------------------------
/app/src/main/java/com/cxp/learningvideo/media/extractor/AudioExtractor.kt:
--------------------------------------------------------------------------------
1 | package com.cxp.learningvideo.media.extractor
2 |
3 | import android.media.MediaFormat
4 | import com.chenlittleping.videoeditor.decoder.MMExtractor
5 | import com.cxp.learningvideo.media.IExtractor
6 | import java.nio.ByteBuffer
7 |
8 |
9 | /**
10 | * 音频数据提取器
11 | *
12 | * @author Chen Xiaoping (562818444@qq.com)
13 | * @since LearningVideo
14 | * @version LearningVideo
15 | * @Datetime 2019-09-03 11:05
16 | *
17 | */
18 | class AudioExtractor(path: String): IExtractor {
19 |
20 | private val mMediaExtractor = MMExtractor(path)
21 |
22 | override fun getFormat(): MediaFormat? {
23 | return mMediaExtractor.getAudioFormat()
24 | }
25 |
26 | override fun readBuffer(byteBuffer: ByteBuffer): Int {
27 | return mMediaExtractor.readBuffer(byteBuffer)
28 | }
29 |
30 | override fun getCurrentTimestamp(): Long {
31 | return mMediaExtractor.getCurrentTimestamp()
32 | }
33 |
34 | override fun getSampleFlag(): Int {
35 | return mMediaExtractor.getSampleFlag()
36 | }
37 |
38 | override fun seek(pos: Long): Long {
39 | return mMediaExtractor.seek(pos)
40 | }
41 |
42 | override fun setStartPos(pos: Long) {
43 | return mMediaExtractor.setStartPos(pos)
44 | }
45 |
46 | override fun stop() {
47 | mMediaExtractor.stop()
48 | }
49 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/cxp/learningvideo/media/extractor/VideoExtractor.kt:
--------------------------------------------------------------------------------
1 | package com.cxp.learningvideo.media.extractor
2 |
3 | import android.media.MediaFormat
4 | import com.chenlittleping.videoeditor.decoder.MMExtractor
5 | import com.cxp.learningvideo.media.IExtractor
6 | import java.nio.ByteBuffer
7 |
8 |
9 | /**
10 | * 视频数据提取器
11 | *
12 | * @author Chen Xiaoping (562818444@qq.com)
13 | * @since LearningVideo
14 | * @version LearningVideo
15 | * @Datetime 2019-09-03 11:06
16 | *
17 | */
18 | class VideoExtractor(path: String): IExtractor {
19 |
20 | private val mMediaExtractor = MMExtractor(path)
21 |
22 | override fun getFormat(): MediaFormat? {
23 | return mMediaExtractor.getVideoFormat()
24 | }
25 |
26 | override fun readBuffer(byteBuffer: ByteBuffer): Int {
27 | return mMediaExtractor.readBuffer(byteBuffer)
28 | }
29 |
30 | override fun getCurrentTimestamp(): Long {
31 | return mMediaExtractor.getCurrentTimestamp()
32 | }
33 |
34 | override fun getSampleFlag(): Int {
35 | return mMediaExtractor.getSampleFlag()
36 | }
37 |
38 | override fun seek(pos: Long): Long {
39 | return mMediaExtractor.seek(pos)
40 | }
41 |
42 | override fun setStartPos(pos: Long) {
43 | return mMediaExtractor.setStartPos(pos)
44 | }
45 |
46 | override fun stop() {
47 | mMediaExtractor.stop()
48 | }
49 | }
--------------------------------------------------------------------------------
/app/src/main/cpp/native-lib.cpp:
--------------------------------------------------------------------------------
1 | //
2 | // Created by cxp on 2018/11/13.
3 | //
4 |
5 | #include
6 | #include
7 | #include
8 |
9 | extern "C" {
10 | #include
11 | #include
12 | #include
13 | #include
14 |
15 | JNIEXPORT jstring JNICALL
16 | Java_com_cxp_learningvideo_FFmpegActivity_ffmpegInfo(JNIEnv *env, jobject /* this */) {
17 |
18 | char info[40000] = {0};
19 | AVCodec *c_temp = av_codec_next(NULL);
20 | while (c_temp != NULL) {
21 | if (c_temp->decode != NULL) {
22 | sprintf(info, "%sdecode:", info);
23 | } else {
24 | sprintf(info, "%sencode:", info);
25 | }
26 | switch (c_temp->type) {
27 | case AVMEDIA_TYPE_VIDEO:
28 | sprintf(info, "%s(video):", info);
29 | break;
30 | case AVMEDIA_TYPE_AUDIO:
31 | sprintf(info, "%s(audio):", info);
32 | break;
33 | default:
34 | sprintf(info, "%s(other):", info);
35 | break;
36 | }
37 | sprintf(info, "%s[%s]\n", info, c_temp->name);
38 | c_temp = c_temp->next;
39 | }
40 | return env->NewStringUTF(info);
41 | }
42 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/cxp/learningvideo/opengl/DefGLSurfaceView.kt:
--------------------------------------------------------------------------------
1 | package com.cxp.learningvideo.opengl
2 |
3 | import android.content.Context
4 | import android.graphics.PointF
5 | import android.opengl.GLSurfaceView
6 | import android.util.AttributeSet
7 | import android.view.MotionEvent
8 | import com.cxp.learningvideo.opengl.drawer.VideoDrawer
9 |
10 |
11 | /**
12 | * 自定义GLSurfaceView
13 | *
14 | * @author Chen Xiaoping (562818444@qq.com)
15 | *
16 | */
17 | class DefGLSurfaceView : GLSurfaceView {
18 |
19 | constructor(context: Context): super(context)
20 |
21 | constructor(context: Context, attrs: AttributeSet): super(context, attrs)
22 |
23 | private var mPrePoint = PointF()
24 |
25 | private var mDrawer: VideoDrawer? = null
26 |
27 | override fun onTouchEvent(event: MotionEvent): Boolean {
28 | when (event.action) {
29 | MotionEvent.ACTION_DOWN -> {
30 | mPrePoint.x = event.x
31 | mPrePoint.y = event.y
32 | }
33 | MotionEvent.ACTION_MOVE -> {
34 | val dx = (event.x - mPrePoint.x) / width
35 | val dy = (event.y - mPrePoint.y) / height
36 | mDrawer?.translate(dx, dy)
37 | mPrePoint.x = event.x
38 | mPrePoint.y = event.y
39 | }
40 | }
41 | return true
42 | }
43 |
44 | fun addDrawer(drawer: VideoDrawer) {
45 | mDrawer = drawer
46 | }
47 | }
--------------------------------------------------------------------------------
/app/src/main/cpp/ffmpeg/include/libavutil/macros.h:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of FFmpeg.
3 | *
4 | * FFmpeg is free software; you can redistribute it and/or
5 | * modify it under the terms of the GNU Lesser General Public
6 | * License as published by the Free Software Foundation; either
7 | * version 2.1 of the License, or (at your option) any later version.
8 | *
9 | * FFmpeg is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 | * Lesser General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU Lesser General Public
15 | * License along with FFmpeg; if not, write to the Free Software
16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 | */
18 |
19 | /**
20 | * @file
21 | * @ingroup lavu
22 | * Utility Preprocessor macros
23 | */
24 |
25 | #ifndef AVUTIL_MACROS_H
26 | #define AVUTIL_MACROS_H
27 |
28 | /**
29 | * @addtogroup preproc_misc Preprocessor String Macros
30 | *
31 | * String manipulation macros
32 | *
33 | * @{
34 | */
35 |
36 | #define AV_STRINGIFY(s) AV_TOSTRING(s)
37 | #define AV_TOSTRING(s) #s
38 |
39 | #define AV_GLUE(a, b) a ## b
40 | #define AV_JOIN(a, b) AV_GLUE(a, b)
41 |
42 | /**
43 | * @}
44 | */
45 |
46 | #define AV_PRAGMA(s) _Pragma(#s)
47 |
48 | #define FFALIGN(x, a) (((x)+(a)-1)&~((a)-1))
49 |
50 | #endif /* AVUTIL_MACROS_H */
51 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
8 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
--------------------------------------------------------------------------------
/app/src/main/cpp/ffmpeg/include/libavcodec/adts_parser.h:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of FFmpeg.
3 | *
4 | * FFmpeg is free software; you can redistribute it and/or
5 | * modify it under the terms of the GNU Lesser General Public
6 | * License as published by the Free Software Foundation; either
7 | * version 2.1 of the License, or (at your option) any later version.
8 | *
9 | * FFmpeg is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 | * Lesser General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU Lesser General Public
15 | * License along with FFmpeg; if not, write to the Free Software
16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 | */
18 |
19 | #ifndef AVCODEC_ADTS_PARSER_H
20 | #define AVCODEC_ADTS_PARSER_H
21 |
22 | #include
23 | #include
24 |
25 | #define AV_AAC_ADTS_HEADER_SIZE 7
26 |
27 | /**
28 | * Extract the number of samples and frames from AAC data.
29 | * @param[in] buf pointer to AAC data buffer
30 | * @param[out] samples Pointer to where number of samples is written
31 | * @param[out] frames Pointer to where number of frames is written
32 | * @return Returns 0 on success, error code on failure.
33 | */
34 | int av_adts_header_parse(const uint8_t *buf, uint32_t *samples,
35 | uint8_t *frames);
36 |
37 | #endif /* AVCODEC_ADTS_PARSER_H */
38 |
--------------------------------------------------------------------------------
/app/src/main/cpp/ffmpeg/include/libavutil/hwcontext_vdpau.h:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of FFmpeg.
3 | *
4 | * FFmpeg is free software; you can redistribute it and/or
5 | * modify it under the terms of the GNU Lesser General Public
6 | * License as published by the Free Software Foundation; either
7 | * version 2.1 of the License, or (at your option) any later version.
8 | *
9 | * FFmpeg is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 | * Lesser General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU Lesser General Public
15 | * License along with FFmpeg; if not, write to the Free Software
16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 | */
18 |
19 | #ifndef AVUTIL_HWCONTEXT_VDPAU_H
20 | #define AVUTIL_HWCONTEXT_VDPAU_H
21 |
22 | #include
23 |
24 | /**
25 | * @file
26 | * An API-specific header for AV_HWDEVICE_TYPE_VDPAU.
27 | *
28 | * This API supports dynamic frame pools. AVHWFramesContext.pool must return
29 | * AVBufferRefs whose data pointer is a VdpVideoSurface.
30 | */
31 |
32 | /**
33 | * This struct is allocated as AVHWDeviceContext.hwctx
34 | */
35 | typedef struct AVVDPAUDeviceContext {
36 | VdpDevice device;
37 | VdpGetProcAddress *get_proc_address;
38 | } AVVDPAUDeviceContext;
39 |
40 | /**
41 | * AVHWFramesContext.hwctx is currently not used
42 | */
43 |
44 | #endif /* AVUTIL_HWCONTEXT_VDPAU_H */
45 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | apply plugin: 'kotlin-android'
4 |
5 | apply plugin: 'kotlin-android-extensions'
6 |
7 | android {
8 | compileSdkVersion 28
9 | defaultConfig {
10 | applicationId "com.cxp.learningvideo"
11 | minSdkVersion 19
12 | targetSdkVersion 28
13 | versionCode 1
14 | versionName "1.0"
15 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
16 |
17 | externalNativeBuild {
18 | cmake {
19 | cppFlags "-std=c++11 -frtti -fexceptions"
20 | }
21 | }
22 | // ndk {
23 | // abiFilters "armeabi-v7a"
24 | // }
25 | }
26 | buildTypes {
27 | release {
28 | minifyEnabled false
29 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
30 | }
31 | }
32 | externalNativeBuild {
33 | cmake {
34 | path file('src/main/cpp/CMakeLists.txt')
35 | }
36 | }
37 | }
38 |
39 | dependencies {
40 | implementation fileTree(dir: 'libs', include: ['*.jar'])
41 | implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
42 | implementation 'com.android.support:appcompat-v7:28.0.0'
43 | implementation 'com.android.support.constraint:constraint-layout:1.1.3'
44 | testImplementation 'junit:junit:4.12'
45 | androidTestImplementation 'com.android.support.test:runner:1.0.2'
46 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
47 | }
48 |
--------------------------------------------------------------------------------
/app/src/main/java/com/cxp/learningvideo/SimpleRenderActivity.kt:
--------------------------------------------------------------------------------
1 | package com.cxp.learningvideo
2 |
3 | import android.graphics.BitmapFactory
4 | import android.os.Bundle
5 | import android.support.v7.app.AppCompatActivity
6 | import com.cxp.learningvideo.opengl.SimpleRender
7 | import com.cxp.learningvideo.opengl.drawer.BitmapDrawer
8 | import com.cxp.learningvideo.opengl.drawer.IDrawer
9 | import com.cxp.learningvideo.opengl.drawer.TriangleDrawer
10 | import kotlinx.android.synthetic.main.activity_simpler_render.*
11 |
12 |
13 | /**
14 | * 简单渲染页面
15 | *
16 | * @author Chen Xiaoping (562818444@qq.com)
17 | * @since LearningVideo
18 | * @version LearningVideo
19 | * @Datetime 2019-10-09 09:23
20 | *
21 | */
22 | class SimpleRenderActivity : AppCompatActivity() {
23 | private lateinit var drawer: IDrawer
24 |
25 | override fun onCreate(savedInstanceState: Bundle?) {
26 | super.onCreate(savedInstanceState)
27 | setContentView(R.layout.activity_simpler_render)
28 |
29 | drawer = if (intent.getIntExtra("type", 0) == 0) {
30 | TriangleDrawer()
31 | } else {
32 | BitmapDrawer(BitmapFactory.decodeResource(CONTEXT!!.resources, R.drawable.cover))
33 | }
34 | initRender(drawer)
35 | }
36 |
37 | private fun initRender(drawer: IDrawer) {
38 | gl_surface.setEGLContextClientVersion(2)
39 | val render = SimpleRender()
40 | render.addDrawer(drawer)
41 | gl_surface.setRenderer(render)
42 | }
43 |
44 | override fun onDestroy() {
45 | drawer.release()
46 | super.onDestroy()
47 | }
48 | }
--------------------------------------------------------------------------------
/app/src/main/cpp/ffmpeg/include/libavutil/random_seed.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2009 Baptiste Coudurier
3 | *
4 | * This file is part of FFmpeg.
5 | *
6 | * FFmpeg is free software; you can redistribute it and/or
7 | * modify it under the terms of the GNU Lesser General Public
8 | * License as published by the Free Software Foundation; either
9 | * version 2.1 of the License, or (at your option) any later version.
10 | *
11 | * FFmpeg is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 | * Lesser General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU Lesser General Public
17 | * License along with FFmpeg; if not, write to the Free Software
18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 | */
20 |
21 | #ifndef AVUTIL_RANDOM_SEED_H
22 | #define AVUTIL_RANDOM_SEED_H
23 |
24 | #include
25 | /**
26 | * @addtogroup lavu_crypto
27 | * @{
28 | */
29 |
30 | /**
31 | * Get a seed to use in conjunction with random functions.
32 | * This function tries to provide a good seed at a best effort bases.
33 | * Its possible to call this function multiple times if more bits are needed.
34 | * It can be quite slow, which is why it should only be used as seed for a faster
35 | * PRNG. The quality of the seed depends on the platform.
36 | */
37 | uint32_t av_get_random_seed(void);
38 |
39 | /**
40 | * @}
41 | */
42 |
43 | #endif /* AVUTIL_RANDOM_SEED_H */
44 |
--------------------------------------------------------------------------------
/app/src/main/java/com/cxp/learningvideo/opengl/SimpleRender.kt:
--------------------------------------------------------------------------------
1 | package com.cxp.learningvideo.opengl
2 |
3 | import android.opengl.GLES20
4 | import android.opengl.GLSurfaceView
5 | import com.cxp.learningvideo.opengl.drawer.IDrawer
6 | import javax.microedition.khronos.egl.EGLConfig
7 | import javax.microedition.khronos.opengles.GL10
8 |
9 |
10 | /**
11 | * 简单的OpenGL渲染器
12 | *
13 | * @author Chen Xiaoping (562818444@qq.com)
14 | * @since LearningVideo
15 | * @version LearningVideo
16 | * @Datetime 2019-19-09 08:55
17 | *
18 | */
19 | class SimpleRender: GLSurfaceView.Renderer {
20 |
21 | private val drawers = mutableListOf()
22 |
23 | override fun onSurfaceCreated(gl: GL10?, config: EGLConfig?) {
24 | GLES20.glClearColor(0f, 0f, 0f, 0f)
25 | //开启混合,即半透明
26 | GLES20.glEnable(GLES20.GL_BLEND)
27 | GLES20.glBlendFunc(GLES20.GL_SRC_ALPHA, GLES20.GL_ONE_MINUS_SRC_ALPHA)
28 |
29 | val textureIds = OpenGLTools.createTextureIds(drawers.size)
30 | for ((idx, drawer) in drawers.withIndex()) {
31 | drawer.setTextureID(textureIds[idx])
32 | }
33 | }
34 |
35 | override fun onSurfaceChanged(gl: GL10?, width: Int, height: Int) {
36 | GLES20.glViewport(0, 0, width, height)
37 | for (drawer in drawers) {
38 | drawer.setWorldSize(width, height)
39 | }
40 | }
41 |
42 | override fun onDrawFrame(gl: GL10?) {
43 | GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT or GLES20.GL_DEPTH_BUFFER_BIT)
44 | drawers.forEach {
45 | it.draw()
46 | }
47 | }
48 |
49 | fun addDrawer(drawer: IDrawer) {
50 | drawers.add(drawer)
51 | }
52 | }
--------------------------------------------------------------------------------
/app/src/main/cpp/ffmpeg/include/libavutil/hwcontext_cuda.h:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of FFmpeg.
3 | *
4 | * FFmpeg is free software; you can redistribute it and/or
5 | * modify it under the terms of the GNU Lesser General Public
6 | * License as published by the Free Software Foundation; either
7 | * version 2.1 of the License, or (at your option) any later version.
8 | *
9 | * FFmpeg is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 | * Lesser General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU Lesser General Public
15 | * License along with FFmpeg; if not, write to the Free Software
16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 | */
18 |
19 |
20 | #ifndef AVUTIL_HWCONTEXT_CUDA_H
21 | #define AVUTIL_HWCONTEXT_CUDA_H
22 |
23 | #ifndef CUDA_VERSION
24 | #include
25 | #endif
26 |
27 | #include "pixfmt.h"
28 |
29 | /**
30 | * @file
31 | * An API-specific header for AV_HWDEVICE_TYPE_CUDA.
32 | *
33 | * This API supports dynamic frame pools. AVHWFramesContext.pool must return
34 | * AVBufferRefs whose data pointer is a CUdeviceptr.
35 | */
36 |
37 | typedef struct AVCUDADeviceContextInternal AVCUDADeviceContextInternal;
38 |
39 | /**
40 | * This struct is allocated as AVHWDeviceContext.hwctx
41 | */
42 | typedef struct AVCUDADeviceContext {
43 | CUcontext cuda_ctx;
44 | CUstream stream;
45 | AVCUDADeviceContextInternal *internal;
46 | } AVCUDADeviceContext;
47 |
48 | /**
49 | * AVHWFramesContext.hwctx is currently not used
50 | */
51 |
52 | #endif /* AVUTIL_HWCONTEXT_CUDA_H */
53 |
--------------------------------------------------------------------------------
/app/src/main/java/com/cxp/learningvideo/MainActivity.kt:
--------------------------------------------------------------------------------
1 | package com.cxp.learningvideo
2 |
3 | import android.content.Intent
4 | import android.os.Bundle
5 | import android.support.v7.app.AppCompatActivity
6 | import android.view.View
7 |
8 | class MainActivity : AppCompatActivity() {
9 | override fun onCreate(savedInstanceState: Bundle?) {
10 | super.onCreate(savedInstanceState)
11 | setContentView(R.layout.activity_main)
12 | }
13 |
14 | fun clickSimplePlayer(view: View) {
15 | startActivity(Intent(this, SimplePlayerActivity::class.java))
16 | }
17 |
18 | fun clickSimpleTriangle(view: View) {
19 | val intent = Intent(this, SimpleRenderActivity::class.java)
20 | intent.putExtra("type", 0)
21 | startActivity(intent)
22 | }
23 |
24 | fun clickSimpleTexture(view: View) {
25 | val intent = Intent(this, SimpleRenderActivity::class.java)
26 | intent.putExtra("type", 1)
27 | startActivity(intent)
28 | }
29 |
30 | fun clickOpenGLPlayer(view: View?) {
31 | startActivity(Intent(this, OpenGLPlayerActivity::class.java))
32 | }
33 |
34 | fun clickMultiOpenGLPlayer(view: View?) {
35 | startActivity(Intent(this, MultiOpenGLPlayerActivity::class.java))
36 | }
37 |
38 | fun clickEGLPlayer(view: View?) {
39 | startActivity(Intent(this, EGLPlayerActivity::class.java))
40 | }
41 |
42 | fun clickSoulPlayer(view: View?) {
43 | startActivity(Intent(this, SoulPlayerActivity::class.java))
44 | }
45 |
46 | fun clickEncoder(view: View?) {
47 | startActivity(Intent(this, SynthesizerActivity::class.java))
48 | }
49 |
50 | fun clickFFmpegInfo(view: View?) {
51 | startActivity(Intent(this, FFmpegActivity::class.java))
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/app/src/main/java/com/cxp/learningvideo/opengl/egl/EGLSurfaceHolder.kt:
--------------------------------------------------------------------------------
1 | package com.cxp.learningvideo.opengl.egl
2 |
3 | import android.opengl.EGLContext
4 | import android.opengl.EGLSurface
5 |
6 |
7 | /**
8 | * EGLSurface 持有者
9 | *
10 | * @author Chen Xiaoping (562818444@qq.com)
11 | * @since LearningVideo
12 | * @version LearningVideo
13 | * @Datetime 2019-11-30 23:27
14 | *
15 | */
16 | class EGLSurfaceHolder {
17 |
18 | private val TAG = "EGLSurfaceHolder"
19 |
20 | private lateinit var mEGLCore: EGLCore
21 |
22 | private var mEGLSurface: EGLSurface? = null
23 |
24 | fun init(shareContext: EGLContext? = null, flags: Int) {
25 | mEGLCore = EGLCore()
26 | mEGLCore.init(shareContext, flags)
27 | }
28 |
29 | fun createEGLSurface(surface: Any?, width: Int = -1, height: Int = -1) {
30 | mEGLSurface = if (surface != null) {
31 | mEGLCore.createWindowSurface(surface)
32 | } else {
33 | mEGLCore.createOffscreenSurface(width, height)
34 | }
35 | }
36 |
37 | fun makeCurrent() {
38 | if (mEGLSurface != null) {
39 | mEGLCore.makeCurrent(mEGLSurface!!)
40 | }
41 | }
42 |
43 | fun swapBuffers() {
44 | if (mEGLSurface != null) {
45 | mEGLCore.swapBuffers(mEGLSurface!!)
46 | }
47 | }
48 |
49 | fun setTimestamp(timeMs: Long) {
50 | if (mEGLSurface != null) {
51 | mEGLCore.setPresentationTime(mEGLSurface!!, timeMs * 1000)
52 | }
53 | }
54 |
55 | fun destroyEGLSurface() {
56 | if (mEGLSurface != null) {
57 | mEGLCore.destroySurface(mEGLSurface!!)
58 | mEGLSurface = null
59 | }
60 | }
61 |
62 | fun release() {
63 | mEGLCore.release()
64 | }
65 | }
--------------------------------------------------------------------------------
/app/src/main/cpp/ffmpeg/include/libavutil/hwcontext_qsv.h:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of FFmpeg.
3 | *
4 | * FFmpeg is free software; you can redistribute it and/or
5 | * modify it under the terms of the GNU Lesser General Public
6 | * License as published by the Free Software Foundation; either
7 | * version 2.1 of the License, or (at your option) any later version.
8 | *
9 | * FFmpeg is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 | * Lesser General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU Lesser General Public
15 | * License along with FFmpeg; if not, write to the Free Software
16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 | */
18 |
19 | #ifndef AVUTIL_HWCONTEXT_QSV_H
20 | #define AVUTIL_HWCONTEXT_QSV_H
21 |
22 | #include
23 |
24 | /**
25 | * @file
26 | * An API-specific header for AV_HWDEVICE_TYPE_QSV.
27 | *
28 | * This API does not support dynamic frame pools. AVHWFramesContext.pool must
29 | * contain AVBufferRefs whose data pointer points to an mfxFrameSurface1 struct.
30 | */
31 |
32 | /**
33 | * This struct is allocated as AVHWDeviceContext.hwctx
34 | */
35 | typedef struct AVQSVDeviceContext {
36 | mfxSession session;
37 | } AVQSVDeviceContext;
38 |
39 | /**
40 | * This struct is allocated as AVHWFramesContext.hwctx
41 | */
42 | typedef struct AVQSVFramesContext {
43 | mfxFrameSurface1 *surfaces;
44 | int nb_surfaces;
45 |
46 | /**
47 | * A combination of MFX_MEMTYPE_* describing the frame pool.
48 | */
49 | int frame_type;
50 | } AVQSVFramesContext;
51 |
52 | #endif /* AVUTIL_HWCONTEXT_QSV_H */
53 |
54 |
--------------------------------------------------------------------------------
/app/src/main/cpp/ffmpeg/include/libavutil/replaygain.h:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of FFmpeg.
3 | *
4 | * FFmpeg is free software; you can redistribute it and/or
5 | * modify it under the terms of the GNU Lesser General Public
6 | * License as published by the Free Software Foundation; either
7 | * version 2.1 of the License, or (at your option) any later version.
8 | *
9 | * FFmpeg is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 | * Lesser General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU Lesser General Public
15 | * License along with FFmpeg; if not, write to the Free Software
16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 | */
18 |
19 | #ifndef AVUTIL_REPLAYGAIN_H
20 | #define AVUTIL_REPLAYGAIN_H
21 |
22 | #include
23 |
24 | /**
25 | * ReplayGain information (see
26 | * http://wiki.hydrogenaudio.org/index.php?title=ReplayGain_1.0_specification).
27 | * The size of this struct is a part of the public ABI.
28 | */
29 | typedef struct AVReplayGain {
30 | /**
31 | * Track replay gain in microbels (divide by 100000 to get the value in dB).
32 | * Should be set to INT32_MIN when unknown.
33 | */
34 | int32_t track_gain;
35 | /**
36 | * Peak track amplitude, with 100000 representing full scale (but values
37 | * may overflow). 0 when unknown.
38 | */
39 | uint32_t track_peak;
40 | /**
41 | * Same as track_gain, but for the whole album.
42 | */
43 | int32_t album_gain;
44 | /**
45 | * Same as track_peak, but for the whole album,
46 | */
47 | uint32_t album_peak;
48 | } AVReplayGain;
49 |
50 | #endif /* AVUTIL_REPLAYGAIN_H */
51 |
--------------------------------------------------------------------------------
/app/src/main/cpp/ffmpeg/include/libavcodec/jni.h:
--------------------------------------------------------------------------------
1 | /*
2 | * JNI public API functions
3 | *
4 | * Copyright (c) 2015-2016 Matthieu Bouron
5 | *
6 | * This file is part of FFmpeg.
7 | *
8 | * FFmpeg is free software; you can redistribute it and/or
9 | * modify it under the terms of the GNU Lesser General Public
10 | * License as published by the Free Software Foundation; either
11 | * version 2.1 of the License, or (at your option) any later version.
12 | *
13 | * FFmpeg is distributed in the hope that it will be useful,
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 | * Lesser General Public License for more details.
17 | *
18 | * You should have received a copy of the GNU Lesser General Public
19 | * License along with FFmpeg; if not, write to the Free Software
20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 | */
22 |
23 | #ifndef AVCODEC_JNI_H
24 | #define AVCODEC_JNI_H
25 |
26 | /*
27 | * Manually set a Java virtual machine which will be used to retrieve the JNI
28 | * environment. Once a Java VM is set it cannot be changed afterwards, meaning
29 | * you can call multiple times av_jni_set_java_vm with the same Java VM pointer
30 | * however it will error out if you try to set a different Java VM.
31 | *
32 | * @param vm Java virtual machine
33 | * @param log_ctx context used for logging, can be NULL
34 | * @return 0 on success, < 0 otherwise
35 | */
36 | int av_jni_set_java_vm(void *vm, void *log_ctx);
37 |
38 | /*
39 | * Get the Java virtual machine which has been set with av_jni_set_java_vm.
40 | *
41 | * @param vm Java virtual machine
42 | * @return a pointer to the Java virtual machine
43 | */
44 | void *av_jni_get_java_vm(void *log_ctx);
45 |
46 | #endif /* AVCODEC_JNI_H */
47 |
--------------------------------------------------------------------------------
/app/src/main/java/com/cxp/learningvideo/SimplePlayerActivity.kt:
--------------------------------------------------------------------------------
1 | package com.cxp.learningvideo
2 |
3 | import android.os.Bundle
4 | import android.os.Environment
5 | import android.support.v7.app.AppCompatActivity
6 | import android.view.View
7 | import com.cxp.learningvideo.media.decoder.AudioDecoder
8 | import com.cxp.learningvideo.media.decoder.VideoDecoder
9 | import com.cxp.learningvideo.media.muxer.MP4Repack
10 | import kotlinx.android.synthetic.main.activity_simple_player.*
11 | import java.util.concurrent.Executors
12 |
13 |
14 | /**
15 | * 简单播放器页面
16 | *
17 | * @author Chen Xiaoping (562818444@qq.com)
18 | * @since LearningVideo
19 | * @version LearningVideo
20 | * @Datetime 2019-10-12 09:33
21 | *
22 | */
23 | class SimplePlayerActivity: AppCompatActivity() {
24 | val path = Environment.getExternalStorageDirectory().absolutePath + "/mvtest_2.mp4"
25 | lateinit var videoDecoder: VideoDecoder
26 | lateinit var audioDecoder: AudioDecoder
27 |
28 | override fun onCreate(savedInstanceState: Bundle?) {
29 | super.onCreate(savedInstanceState)
30 | setContentView(R.layout.activity_simple_player)
31 | initPlayer()
32 | }
33 |
34 | private fun initPlayer() {
35 | val threadPool = Executors.newFixedThreadPool(10)
36 |
37 | videoDecoder = VideoDecoder(path, sfv, null)
38 | threadPool.execute(videoDecoder)
39 |
40 | audioDecoder = AudioDecoder(path)
41 | threadPool.execute(audioDecoder)
42 |
43 | videoDecoder.goOn()
44 | audioDecoder.goOn()
45 | }
46 |
47 | fun clickRepack(view: View) {
48 | repack()
49 | }
50 |
51 | private fun repack() {
52 | val repack = MP4Repack(path)
53 | repack.start()
54 | }
55 |
56 | override fun onDestroy() {
57 | videoDecoder.stop()
58 | audioDecoder.stop()
59 | super.onDestroy()
60 | }
61 | }
62 |
--------------------------------------------------------------------------------
/app/src/main/cpp/ffmpeg/include/libswresample/version.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Version macros.
3 | *
4 | * This file is part of libswresample
5 | *
6 | * libswresample is free software; you can redistribute it and/or
7 | * modify it under the terms of the GNU Lesser General Public
8 | * License as published by the Free Software Foundation; either
9 | * version 2.1 of the License, or (at your option) any later version.
10 | *
11 | * libswresample is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 | * Lesser General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU Lesser General Public
17 | * License along with libswresample; if not, write to the Free Software
18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 | */
20 |
21 | #ifndef SWRESAMPLE_VERSION_H
22 | #define SWRESAMPLE_VERSION_H
23 |
24 | /**
25 | * @file
26 | * Libswresample version macros
27 | */
28 |
29 | #include "libavutil/avutil.h"
30 |
31 | #define LIBSWRESAMPLE_VERSION_MAJOR 3
32 | #define LIBSWRESAMPLE_VERSION_MINOR 5
33 | #define LIBSWRESAMPLE_VERSION_MICRO 100
34 |
35 | #define LIBSWRESAMPLE_VERSION_INT AV_VERSION_INT(LIBSWRESAMPLE_VERSION_MAJOR, \
36 | LIBSWRESAMPLE_VERSION_MINOR, \
37 | LIBSWRESAMPLE_VERSION_MICRO)
38 | #define LIBSWRESAMPLE_VERSION AV_VERSION(LIBSWRESAMPLE_VERSION_MAJOR, \
39 | LIBSWRESAMPLE_VERSION_MINOR, \
40 | LIBSWRESAMPLE_VERSION_MICRO)
41 | #define LIBSWRESAMPLE_BUILD LIBSWRESAMPLE_VERSION_INT
42 |
43 | #define LIBSWRESAMPLE_IDENT "SwR" AV_STRINGIFY(LIBSWRESAMPLE_VERSION)
44 |
45 | #endif /* SWRESAMPLE_VERSION_H */
46 |
--------------------------------------------------------------------------------
/app/src/main/cpp/ffmpeg/include/libavutil/adler32.h:
--------------------------------------------------------------------------------
1 | /*
2 | * copyright (c) 2006 Mans Rullgard
3 | *
4 | * This file is part of FFmpeg.
5 | *
6 | * FFmpeg is free software; you can redistribute it and/or
7 | * modify it under the terms of the GNU Lesser General Public
8 | * License as published by the Free Software Foundation; either
9 | * version 2.1 of the License, or (at your option) any later version.
10 | *
11 | * FFmpeg is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 | * Lesser General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU Lesser General Public
17 | * License along with FFmpeg; if not, write to the Free Software
18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 | */
20 |
21 | /**
22 | * @file
23 | * @ingroup lavu_adler32
24 | * Public header for Adler-32 hash function implementation.
25 | */
26 |
27 | #ifndef AVUTIL_ADLER32_H
28 | #define AVUTIL_ADLER32_H
29 |
30 | #include
31 | #include "attributes.h"
32 |
33 | /**
34 | * @defgroup lavu_adler32 Adler-32
35 | * @ingroup lavu_hash
36 | * Adler-32 hash function implementation.
37 | *
38 | * @{
39 | */
40 |
41 | /**
42 | * Calculate the Adler32 checksum of a buffer.
43 | *
44 | * Passing the return value to a subsequent av_adler32_update() call
45 | * allows the checksum of multiple buffers to be calculated as though
46 | * they were concatenated.
47 | *
48 | * @param adler initial checksum value
49 | * @param buf pointer to input buffer
50 | * @param len size of input buffer
51 | * @return updated checksum
52 | */
53 | unsigned long av_adler32_update(unsigned long adler, const uint8_t *buf,
54 | unsigned int len) av_pure;
55 |
56 | /**
57 | * @}
58 | */
59 |
60 | #endif /* AVUTIL_ADLER32_H */
61 |
--------------------------------------------------------------------------------
/app/src/main/java/com/cxp/learningvideo/utils/Test.kt:
--------------------------------------------------------------------------------
1 | package com.cxp.learningvideo.utils
2 |
3 | import android.media.MediaCodecInfo
4 | import android.media.MediaCodecList
5 | import android.util.Log
6 |
7 |
8 | /**
9 | * 测试工具
10 | *
11 | * @author Chen Xiaoping (562818444@qq.com)
12 | * @since LearningVideo
13 | * @version LearningVideo
14 | * @Datetime 2019-10-11 11:06
15 | *
16 | */
17 | fun printMediaCodecInfo() {
18 | var codecCount = 0
19 | try {
20 | codecCount = MediaCodecList.getCodecCount()
21 | } catch (e: Exception) {
22 | Log.e("cccccc", "##### Failed to get codec count!")
23 | e.printStackTrace()
24 | return
25 | }
26 |
27 | for (i in 0 until codecCount) {
28 | var info: MediaCodecInfo? = null
29 | try {
30 | info = MediaCodecList.getCodecInfoAt(i)
31 | } catch (e: IllegalArgumentException) {
32 | Log.e("cccccc", "Cannot retrieve decoder codec info", e)
33 | }
34 |
35 | if (info == null) {
36 | continue
37 | }
38 |
39 | var codecInfo = "MediaCodec, name=" + info.name + ", ["
40 |
41 | for (mimeType in info.supportedTypes) {
42 | codecInfo += "$mimeType,"
43 | val capabilities: MediaCodecInfo.CodecCapabilities
44 | try {
45 | capabilities = info.getCapabilitiesForType(mimeType)
46 | } catch (e: IllegalArgumentException) {
47 | Log.e("cccccc", "Cannot retrieve decoder capabilities", e)
48 | continue
49 | }
50 |
51 | codecInfo += " max inst:" + capabilities.maxSupportedInstances + ","
52 |
53 | var strColorFormatList = ""
54 | for (colorFormat in capabilities.colorFormats) {
55 | strColorFormatList += " 0x" + Integer.toHexString(colorFormat)
56 | }
57 | codecInfo += "$strColorFormatList] ["
58 | }
59 | Log.w("cccccc", codecInfo)
60 | }
61 |
62 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/cxp/learningvideo/OpenGLPlayerActivity.kt:
--------------------------------------------------------------------------------
1 | package com.cxp.learningvideo
2 |
3 | import android.os.Bundle
4 | import android.os.Environment
5 | import android.support.v7.app.AppCompatActivity
6 | import android.view.Surface
7 | import com.cxp.learningvideo.media.decoder.AudioDecoder
8 | import com.cxp.learningvideo.media.decoder.VideoDecoder
9 | import com.cxp.learningvideo.opengl.SimpleRender
10 | import com.cxp.learningvideo.opengl.drawer.IDrawer
11 | import com.cxp.learningvideo.opengl.drawer.VideoDrawer
12 | import kotlinx.android.synthetic.main.activity_opengl_player.*
13 | import java.util.concurrent.Executors
14 |
15 |
16 | /**
17 | * 使用OpenGL渲染的播放器
18 | *
19 | * @author Chen Xiaoping (562818444@qq.com)
20 | * @since LearningVideo
21 | * @version LearningVideo
22 | * @Datetime 2019-10-26 21:07
23 | *
24 | */
25 | class OpenGLPlayerActivity: AppCompatActivity() {
26 | val path = Environment.getExternalStorageDirectory().absolutePath + "/mvtest.mp4"
27 | lateinit var drawer: IDrawer
28 |
29 | override fun onCreate(savedInstanceState: Bundle?) {
30 | super.onCreate(savedInstanceState)
31 | setContentView(R.layout.activity_opengl_player)
32 | initRender()
33 | }
34 |
35 | private fun initRender() {
36 | drawer = VideoDrawer()
37 | drawer.setVideoSize(1920, 1080)
38 | drawer.getSurfaceTexture {
39 | initPlayer(Surface(it))
40 | }
41 | gl_surface.setEGLContextClientVersion(2)
42 | val render = SimpleRender()
43 | render.addDrawer(drawer)
44 | gl_surface.setRenderer(render)
45 | }
46 |
47 | private fun initPlayer(sf: Surface) {
48 | val threadPool = Executors.newFixedThreadPool(10)
49 |
50 | val videoDecoder = VideoDecoder(path, null, sf)
51 | threadPool.execute(videoDecoder)
52 |
53 | val audioDecoder = AudioDecoder(path)
54 | threadPool.execute(audioDecoder)
55 |
56 | videoDecoder.goOn()
57 | audioDecoder.goOn()
58 | }
59 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/cxp/learningvideo/SoulPlayerActivity.kt:
--------------------------------------------------------------------------------
1 | package com.cxp.learningvideo
2 |
3 | import android.os.Bundle
4 | import android.os.Environment
5 | import android.support.v7.app.AppCompatActivity
6 | import android.view.Surface
7 | import com.cxp.learningvideo.media.decoder.AudioDecoder
8 | import com.cxp.learningvideo.media.decoder.VideoDecoder
9 | import com.cxp.learningvideo.opengl.SimpleRender
10 | import com.cxp.learningvideo.opengl.drawer.IDrawer
11 | import com.cxp.learningvideo.opengl.drawer.SoulVideoDrawer
12 | import kotlinx.android.synthetic.main.activity_opengl_player.*
13 | import java.util.concurrent.Executors
14 |
15 |
16 | /**
17 | * 灵魂出窍播放
18 | *
19 | * @author Chen Xiaoping (562818444@qq.com)
20 | * @since LearningVideo
21 | * @version LearningVideo
22 | * @Datetime 2019-10-26 21:07
23 | *
24 | */
25 | class SoulPlayerActivity: AppCompatActivity() {
26 | val path = Environment.getExternalStorageDirectory().absolutePath + "/mvtest.mp4"
27 | lateinit var drawer: IDrawer
28 |
29 | override fun onCreate(savedInstanceState: Bundle?) {
30 | super.onCreate(savedInstanceState)
31 | setContentView(R.layout.activity_opengl_player)
32 | initRender()
33 | }
34 |
35 | private fun initRender() {
36 | drawer = SoulVideoDrawer()
37 | drawer.setVideoSize(1920, 1080)
38 | drawer.getSurfaceTexture {
39 | initPlayer(Surface(it))
40 | }
41 | gl_surface.setEGLContextClientVersion(2)
42 | val render = SimpleRender()
43 | render.addDrawer(drawer)
44 | gl_surface.setRenderer(render)
45 | }
46 |
47 | private fun initPlayer(sf: Surface) {
48 | val threadPool = Executors.newFixedThreadPool(10)
49 |
50 | val videoDecoder = VideoDecoder(path, null, sf)
51 | threadPool.execute(videoDecoder)
52 |
53 | val audioDecoder = AudioDecoder(path)
54 | threadPool.execute(audioDecoder)
55 |
56 | videoDecoder.goOn()
57 | audioDecoder.goOn()
58 | }
59 | }
--------------------------------------------------------------------------------
/app/src/main/cpp/ffmpeg/include/libavutil/motion_vector.h:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of FFmpeg.
3 | *
4 | * FFmpeg is free software; you can redistribute it and/or
5 | * modify it under the terms of the GNU Lesser General Public
6 | * License as published by the Free Software Foundation; either
7 | * version 2.1 of the License, or (at your option) any later version.
8 | *
9 | * FFmpeg is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 | * Lesser General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU Lesser General Public
15 | * License along with FFmpeg; if not, write to the Free Software
16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 | */
18 |
19 | #ifndef AVUTIL_MOTION_VECTOR_H
20 | #define AVUTIL_MOTION_VECTOR_H
21 |
22 | #include
23 |
24 | typedef struct AVMotionVector {
25 | /**
26 | * Where the current macroblock comes from; negative value when it comes
27 | * from the past, positive value when it comes from the future.
28 | * XXX: set exact relative ref frame reference instead of a +/- 1 "direction".
29 | */
30 | int32_t source;
31 | /**
32 | * Width and height of the block.
33 | */
34 | uint8_t w, h;
35 | /**
36 | * Absolute source position. Can be outside the frame area.
37 | */
38 | int16_t src_x, src_y;
39 | /**
40 | * Absolute destination position. Can be outside the frame area.
41 | */
42 | int16_t dst_x, dst_y;
43 | /**
44 | * Extra flag information.
45 | * Currently unused.
46 | */
47 | uint64_t flags;
48 | /**
49 | * Motion vector
50 | * src_x = dst_x + motion_x / motion_scale
51 | * src_y = dst_y + motion_y / motion_scale
52 | */
53 | int32_t motion_x, motion_y;
54 | uint16_t motion_scale;
55 | } AVMotionVector;
56 |
57 | #endif /* AVUTIL_MOTION_VECTOR_H */
58 |
--------------------------------------------------------------------------------
/app/src/main/cpp/ffmpeg/include/libavutil/time.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2000-2003 Fabrice Bellard
3 | *
4 | * This file is part of FFmpeg.
5 | *
6 | * FFmpeg is free software; you can redistribute it and/or
7 | * modify it under the terms of the GNU Lesser General Public
8 | * License as published by the Free Software Foundation; either
9 | * version 2.1 of the License, or (at your option) any later version.
10 | *
11 | * FFmpeg is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 | * Lesser General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU Lesser General Public
17 | * License along with FFmpeg; if not, write to the Free Software
18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 | */
20 |
21 | #ifndef AVUTIL_TIME_H
22 | #define AVUTIL_TIME_H
23 |
24 | #include
25 |
26 | /**
27 | * Get the current time in microseconds.
28 | */
29 | int64_t av_gettime(void);
30 |
31 | /**
32 | * Get the current time in microseconds since some unspecified starting point.
33 | * On platforms that support it, the time comes from a monotonic clock
34 | * This property makes this time source ideal for measuring relative time.
35 | * The returned values may not be monotonic on platforms where a monotonic
36 | * clock is not available.
37 | */
38 | int64_t av_gettime_relative(void);
39 |
40 | /**
41 | * Indicates with a boolean result if the av_gettime_relative() time source
42 | * is monotonic.
43 | */
44 | int av_gettime_relative_is_monotonic(void);
45 |
46 | /**
47 | * Sleep for a period of time. Although the duration is expressed in
48 | * microseconds, the actual delay may be rounded to the precision of the
49 | * system timer.
50 | *
51 | * @param usec Number of microseconds to sleep.
52 | * @return zero on success or (negative) error code.
53 | */
54 | int av_usleep(unsigned usec);
55 |
56 | #endif /* AVUTIL_TIME_H */
57 |
--------------------------------------------------------------------------------
/app/src/main/cpp/ffmpeg/include/libavdevice/version.h:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of FFmpeg.
3 | *
4 | * FFmpeg is free software; you can redistribute it and/or
5 | * modify it under the terms of the GNU Lesser General Public
6 | * License as published by the Free Software Foundation; either
7 | * version 2.1 of the License, or (at your option) any later version.
8 | *
9 | * FFmpeg is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 | * Lesser General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU Lesser General Public
15 | * License along with FFmpeg; if not, write to the Free Software
16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 | */
18 |
19 | #ifndef AVDEVICE_VERSION_H
20 | #define AVDEVICE_VERSION_H
21 |
22 | /**
23 | * @file
24 | * @ingroup lavd
25 | * Libavdevice version macros
26 | */
27 |
28 | #include "libavutil/version.h"
29 |
30 | #define LIBAVDEVICE_VERSION_MAJOR 58
31 | #define LIBAVDEVICE_VERSION_MINOR 8
32 | #define LIBAVDEVICE_VERSION_MICRO 100
33 |
34 | #define LIBAVDEVICE_VERSION_INT AV_VERSION_INT(LIBAVDEVICE_VERSION_MAJOR, \
35 | LIBAVDEVICE_VERSION_MINOR, \
36 | LIBAVDEVICE_VERSION_MICRO)
37 | #define LIBAVDEVICE_VERSION AV_VERSION(LIBAVDEVICE_VERSION_MAJOR, \
38 | LIBAVDEVICE_VERSION_MINOR, \
39 | LIBAVDEVICE_VERSION_MICRO)
40 | #define LIBAVDEVICE_BUILD LIBAVDEVICE_VERSION_INT
41 |
42 | #define LIBAVDEVICE_IDENT "Lavd" AV_STRINGIFY(LIBAVDEVICE_VERSION)
43 |
44 | /**
45 | * FF_API_* defines may be placed below to indicate public API that will be
46 | * dropped at a future version bump. The defines themselves are not part of
47 | * the public API and may change, break or disappear at any time.
48 | */
49 |
50 | #endif /* AVDEVICE_VERSION_H */
51 |
--------------------------------------------------------------------------------
/app/src/main/cpp/ffmpeg/include/libavutil/intfloat.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2011 Mans Rullgard
3 | *
4 | * This file is part of FFmpeg.
5 | *
6 | * FFmpeg is free software; you can redistribute it and/or
7 | * modify it under the terms of the GNU Lesser General Public
8 | * License as published by the Free Software Foundation; either
9 | * version 2.1 of the License, or (at your option) any later version.
10 | *
11 | * FFmpeg is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 | * Lesser General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU Lesser General Public
17 | * License along with FFmpeg; if not, write to the Free Software
18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 | */
20 |
21 | #ifndef AVUTIL_INTFLOAT_H
22 | #define AVUTIL_INTFLOAT_H
23 |
24 | #include
25 | #include "attributes.h"
26 |
27 | union av_intfloat32 {
28 | uint32_t i;
29 | float f;
30 | };
31 |
32 | union av_intfloat64 {
33 | uint64_t i;
34 | double f;
35 | };
36 |
37 | /**
38 | * Reinterpret a 32-bit integer as a float.
39 | */
40 | static av_always_inline float av_int2float(uint32_t i)
41 | {
42 | union av_intfloat32 v;
43 | v.i = i;
44 | return v.f;
45 | }
46 |
47 | /**
48 | * Reinterpret a float as a 32-bit integer.
49 | */
50 | static av_always_inline uint32_t av_float2int(float f)
51 | {
52 | union av_intfloat32 v;
53 | v.f = f;
54 | return v.i;
55 | }
56 |
57 | /**
58 | * Reinterpret a 64-bit integer as a double.
59 | */
60 | static av_always_inline double av_int2double(uint64_t i)
61 | {
62 | union av_intfloat64 v;
63 | v.i = i;
64 | return v.f;
65 | }
66 |
67 | /**
68 | * Reinterpret a double as a 64-bit integer.
69 | */
70 | static av_always_inline uint64_t av_double2int(double f)
71 | {
72 | union av_intfloat64 v;
73 | v.f = f;
74 | return v.i;
75 | }
76 |
77 | #endif /* AVUTIL_INTFLOAT_H */
78 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable-v24/ic_launcher_foreground.xml:
--------------------------------------------------------------------------------
1 |
7 |
12 |
13 |
19 |
22 |
25 |
26 |
27 |
28 |
34 |
35 |
--------------------------------------------------------------------------------
/app/src/main/cpp/ffmpeg/include/libavutil/aes.h:
--------------------------------------------------------------------------------
1 | /*
2 | * copyright (c) 2007 Michael Niedermayer
3 | *
4 | * This file is part of FFmpeg.
5 | *
6 | * FFmpeg is free software; you can redistribute it and/or
7 | * modify it under the terms of the GNU Lesser General Public
8 | * License as published by the Free Software Foundation; either
9 | * version 2.1 of the License, or (at your option) any later version.
10 | *
11 | * FFmpeg is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 | * Lesser General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU Lesser General Public
17 | * License along with FFmpeg; if not, write to the Free Software
18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 | */
20 |
21 | #ifndef AVUTIL_AES_H
22 | #define AVUTIL_AES_H
23 |
24 | #include
25 |
26 | #include "attributes.h"
27 | #include "version.h"
28 |
29 | /**
30 | * @defgroup lavu_aes AES
31 | * @ingroup lavu_crypto
32 | * @{
33 | */
34 |
35 | extern const int av_aes_size;
36 |
37 | struct AVAES;
38 |
39 | /**
40 | * Allocate an AVAES context.
41 | */
42 | struct AVAES *av_aes_alloc(void);
43 |
44 | /**
45 | * Initialize an AVAES context.
46 | * @param key_bits 128, 192 or 256
47 | * @param decrypt 0 for encryption, 1 for decryption
48 | */
49 | int av_aes_init(struct AVAES *a, const uint8_t *key, int key_bits, int decrypt);
50 |
51 | /**
52 | * Encrypt or decrypt a buffer using a previously initialized context.
53 | * @param count number of 16 byte blocks
54 | * @param dst destination array, can be equal to src
55 | * @param src source array, can be equal to dst
56 | * @param iv initialization vector for CBC mode, if NULL then ECB will be used
57 | * @param decrypt 0 for encryption, 1 for decryption
58 | */
59 | void av_aes_crypt(struct AVAES *a, uint8_t *dst, const uint8_t *src, int count, uint8_t *iv, int decrypt);
60 |
61 | /**
62 | * @}
63 | */
64 |
65 | #endif /* AVUTIL_AES_H */
66 |
--------------------------------------------------------------------------------
/app/src/main/cpp/ffmpeg/include/libavutil/hwcontext_videotoolbox.h:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of FFmpeg.
3 | *
4 | * FFmpeg is free software; you can redistribute it and/or
5 | * modify it under the terms of the GNU Lesser General Public
6 | * License as published by the Free Software Foundation; either
7 | * version 2.1 of the License, or (at your option) any later version.
8 | *
9 | * FFmpeg is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 | * Lesser General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU Lesser General Public
15 | * License along with FFmpeg; if not, write to the Free Software
16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 | */
18 |
19 | #ifndef AVUTIL_HWCONTEXT_VIDEOTOOLBOX_H
20 | #define AVUTIL_HWCONTEXT_VIDEOTOOLBOX_H
21 |
22 | #include
23 |
24 | #include
25 |
26 | #include "pixfmt.h"
27 |
28 | /**
29 | * @file
30 | * An API-specific header for AV_HWDEVICE_TYPE_VIDEOTOOLBOX.
31 | *
32 | * This API currently does not support frame allocation, as the raw VideoToolbox
33 | * API does allocation, and FFmpeg itself never has the need to allocate frames.
34 | *
35 | * If the API user sets a custom pool, AVHWFramesContext.pool must return
36 | * AVBufferRefs whose data pointer is a CVImageBufferRef or CVPixelBufferRef.
37 | *
38 | * Currently AVHWDeviceContext.hwctx and AVHWFramesContext.hwctx are always
39 | * NULL.
40 | */
41 |
42 | /**
43 | * Convert a VideoToolbox (actually CoreVideo) format to AVPixelFormat.
44 | * Returns AV_PIX_FMT_NONE if no known equivalent was found.
45 | */
46 | enum AVPixelFormat av_map_videotoolbox_format_to_pixfmt(uint32_t cv_fmt);
47 |
48 | /**
49 | * Convert an AVPixelFormat to a VideoToolbox (actually CoreVideo) format.
50 | * Returns 0 if no known equivalent was found.
51 | */
52 | uint32_t av_map_videotoolbox_format_from_pixfmt(enum AVPixelFormat pix_fmt);
53 |
54 | #endif /* AVUTIL_HWCONTEXT_VIDEOTOOLBOX_H */
55 |
--------------------------------------------------------------------------------
/app/src/main/cpp/ffmpeg/include/libswscale/version.h:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of FFmpeg.
3 | *
4 | * FFmpeg is free software; you can redistribute it and/or
5 | * modify it under the terms of the GNU Lesser General Public
6 | * License as published by the Free Software Foundation; either
7 | * version 2.1 of the License, or (at your option) any later version.
8 | *
9 | * FFmpeg is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 | * Lesser General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU Lesser General Public
15 | * License along with FFmpeg; if not, write to the Free Software
16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 | */
18 |
19 | #ifndef SWSCALE_VERSION_H
20 | #define SWSCALE_VERSION_H
21 |
22 | /**
23 | * @file
24 | * swscale version macros
25 | */
26 |
27 | #include "libavutil/version.h"
28 |
29 | #define LIBSWSCALE_VERSION_MAJOR 5
30 | #define LIBSWSCALE_VERSION_MINOR 5
31 | #define LIBSWSCALE_VERSION_MICRO 100
32 |
33 | #define LIBSWSCALE_VERSION_INT AV_VERSION_INT(LIBSWSCALE_VERSION_MAJOR, \
34 | LIBSWSCALE_VERSION_MINOR, \
35 | LIBSWSCALE_VERSION_MICRO)
36 | #define LIBSWSCALE_VERSION AV_VERSION(LIBSWSCALE_VERSION_MAJOR, \
37 | LIBSWSCALE_VERSION_MINOR, \
38 | LIBSWSCALE_VERSION_MICRO)
39 | #define LIBSWSCALE_BUILD LIBSWSCALE_VERSION_INT
40 |
41 | #define LIBSWSCALE_IDENT "SwS" AV_STRINGIFY(LIBSWSCALE_VERSION)
42 |
43 | /**
44 | * FF_API_* defines may be placed below to indicate public API that will be
45 | * dropped at a future version bump. The defines themselves are not part of
46 | * the public API and may change, break or disappear at any time.
47 | */
48 |
49 | #ifndef FF_API_SWS_VECTOR
50 | #define FF_API_SWS_VECTOR (LIBSWSCALE_VERSION_MAJOR < 6)
51 | #endif
52 |
53 | #endif /* SWSCALE_VERSION_H */
54 |
--------------------------------------------------------------------------------
/app/src/main/cpp/ffmpeg/include/libavutil/rc4.h:
--------------------------------------------------------------------------------
1 | /*
2 | * RC4 encryption/decryption/pseudo-random number generator
3 | *
4 | * This file is part of FFmpeg.
5 | *
6 | * FFmpeg is free software; you can redistribute it and/or
7 | * modify it under the terms of the GNU Lesser General Public
8 | * License as published by the Free Software Foundation; either
9 | * version 2.1 of the License, or (at your option) any later version.
10 | *
11 | * FFmpeg is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 | * Lesser General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU Lesser General Public
17 | * License along with FFmpeg; if not, write to the Free Software
18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 | */
20 |
21 | #ifndef AVUTIL_RC4_H
22 | #define AVUTIL_RC4_H
23 |
24 | #include
25 |
26 | /**
27 | * @defgroup lavu_rc4 RC4
28 | * @ingroup lavu_crypto
29 | * @{
30 | */
31 |
32 | typedef struct AVRC4 {
33 | uint8_t state[256];
34 | int x, y;
35 | } AVRC4;
36 |
37 | /**
38 | * Allocate an AVRC4 context.
39 | */
40 | AVRC4 *av_rc4_alloc(void);
41 |
42 | /**
43 | * @brief Initializes an AVRC4 context.
44 | *
45 | * @param key_bits must be a multiple of 8
46 | * @param decrypt 0 for encryption, 1 for decryption, currently has no effect
47 | * @return zero on success, negative value otherwise
48 | */
49 | int av_rc4_init(struct AVRC4 *d, const uint8_t *key, int key_bits, int decrypt);
50 |
51 | /**
52 | * @brief Encrypts / decrypts using the RC4 algorithm.
53 | *
54 | * @param count number of bytes
55 | * @param dst destination array, can be equal to src
56 | * @param src source array, can be equal to dst, may be NULL
57 | * @param iv not (yet) used for RC4, should be NULL
58 | * @param decrypt 0 for encryption, 1 for decryption, not (yet) used
59 | */
60 | void av_rc4_crypt(struct AVRC4 *d, uint8_t *dst, const uint8_t *src, int count, uint8_t *iv, int decrypt);
61 |
62 | /**
63 | * @}
64 | */
65 |
66 | #endif /* AVUTIL_RC4_H */
67 |
--------------------------------------------------------------------------------
/app/src/main/java/com/cxp/learningvideo/media/IDecoder.kt:
--------------------------------------------------------------------------------
1 | package com.cxp.learningvideo.media
2 |
3 | import android.media.MediaFormat
4 |
5 |
6 | /**
7 | * 解码器定义
8 | *
9 | * @author Chen Xiaoping (562818444@qq.com)
10 | * @since LearningVideo
11 | * @version LearningVideo
12 | * @Datetime 2019-09-02 09:49
13 | *
14 | */
15 | interface IDecoder: Runnable {
16 |
17 | /**
18 | * 暂停解码
19 | */
20 | fun pause()
21 |
22 | /**
23 | * 继续解码
24 | */
25 | fun goOn()
26 |
27 | /**
28 | * 跳转到指定位置
29 | * 并返回实际帧的时间
30 | *
31 | * @param pos: 毫秒
32 | * @return 实际时间戳,单位:毫秒
33 | */
34 | fun seekTo(pos: Long): Long
35 |
36 | /**
37 | * 跳转到指定位置,并播放
38 | * 并返回实际帧的时间
39 | *
40 | * @param pos: 毫秒
41 | * @return 实际时间戳,单位:毫秒
42 | */
43 | fun seekAndPlay(pos: Long): Long
44 |
45 | /**
46 | * 停止解码
47 | */
48 | fun stop()
49 |
50 | /**
51 | * 是否正在解码
52 | */
53 | fun isDecoding(): Boolean
54 |
55 | /**
56 | * 是否正在快进
57 | */
58 | fun isSeeking(): Boolean
59 |
60 | /**
61 | * 是否停止解码
62 | */
63 | fun isStop(): Boolean
64 |
65 | /**
66 | * 设置尺寸监听器
67 | */
68 | fun setSizeListener(l: IDecoderProgress)
69 |
70 | /**
71 | * 设置状态监听器
72 | */
73 | fun setStateListener(l: IDecoderStateListener?)
74 |
75 | /**
76 | * 获取视频宽
77 | */
78 | fun getWidth(): Int
79 |
80 | /**
81 | * 获取视频高
82 | */
83 | fun getHeight(): Int
84 |
85 | /**
86 | * 获取视频长度
87 | */
88 | fun getDuration(): Long
89 |
90 | /**
91 | * 当前帧时间,单位:ms
92 | */
93 | fun getCurTimeStamp(): Long
94 |
95 | /**
96 | * 获取视频旋转角度
97 | */
98 | fun getRotationAngle(): Int
99 |
100 | /**
101 | * 获取音视频对应的格式参数
102 | */
103 | fun getMediaFormat(): MediaFormat?
104 |
105 | /**
106 | * 获取音视频对应的媒体轨道
107 | */
108 | fun getTrack(): Int
109 |
110 | /**
111 | * 获取解码的文件路径
112 | */
113 | fun getFilePath(): String
114 |
115 | /**
116 | * 无需音视频同步
117 | */
118 | fun withoutSync(): IDecoder
119 | }
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
2 | 
3 |
4 | #### 简介
5 |
6 | 本项目为【Android音视频开发打怪升级】系列教程的代码实例,教程正在陆续完善中。
7 |
8 | **简书和微信公众号同步更新,欢迎关注**
9 |
10 | 我在简书:https://www.jianshu.com/u/8c0a3b9c0e47
11 |
12 | 我在掘金:https://juejin.im/user/57c5b0040a2b58006c0a5132
13 |
14 | 微信公众号:开发的猫
15 |
16 | 
17 |
18 | ##### 炙手可热,望而生畏的音视频开发
19 |
20 | 时至今日,短视频App可谓是如日中天,一片兴兴向荣。随着短视频的兴起,音视频开发也越来越受到重视,但是由于音视频开发涉及知识面比较广,入门门槛相对较高,让许许多多开发者望而生畏。
21 |
22 | ##### 为什么写这一系列博文
23 |
24 | 虽然网上有很多的博文总结了音视频打怪升级的路线,但是音视频开发相关的知识都相对独立,有讲“音视频解码相关”的,有讲“OpenGL相关”的,也有讲“FFmpeg相关的”,但是对于新手来说,把所有的知识衔接串联起来,并很好的理解所有的知识,却是非常困难的。
25 |
26 | 本人在学习音视频开发的过程中,深刻体会到了由于知识的分散,过渡断层带来的种种困惑和痛苦,因此,希望通过自己的理解,可以把音视频开发相关的知识总结出来,并形成系列文章,循序渐进,剖析各个环节,一则对自己所学做一个总结和巩固,二则希望可以帮助想入门音视频开发的开发者小伙伴们。
27 |
28 | #### 声 明
29 |
30 | > **首先**,这一系列文章均基于自己的理解和实践,可能有不对的地方,欢迎大家指正。
31 | **其次**,这是一个入门系列,涉及的知识也仅限于够用,深入的知识网上也有许许多多的博文供大家学习了。
32 | **最后**,写文章过程中,会借鉴参考其他人分享的文章,会在文章最后列出,感谢这些作者的分享。
33 |
34 | **码字不易,转载请注明出处!**
35 |
36 | ---
37 |
38 | #### 目录
39 | ##### 一、Android音视频硬解码篇:
40 | - [x] 1,[音视频基础知识](https://www.jianshu.com/p/1749d2d43ecb)
41 | - [x] 2,[音视频硬解码流程:封装基础解码框架](https://www.jianshu.com/p/ff65ef5207ce)
42 | - [x] 3,[音视频播放:音视频同步](https://www.jianshu.com/p/ba8db84f8fe8)
43 | - [x] 4,[音视频解封和封装:生成一个MP4](https://www.jianshu.com/p/105147d75dfa)
44 |
45 | ##### 二、使用OpenGL渲染视频画面篇
46 | - [x] 1,[初步了解OpenGL ES](https://www.jianshu.com/p/2158d4aec142)
47 | - [x] 2,[使用OpenGL渲染视频画面](https://www.jianshu.com/p/176880b2b3a2)
48 | - [x] 3,[OpenGL渲染多视屏,实现画中画](https://www.jianshu.com/p/0e56e9678dd5)
49 | - [x] 4,[深入了解OpenGL之EGL](https://www.jianshu.com/p/9f4f6c72ef5a)
50 | - [x] 5,[OpenGL FBO数据缓冲区](https://www.jianshu.com/p/1a7741608083)
51 | - [x] 6,[Android音视频硬编码:生成一个MP4](https://www.jianshu.com/p/bfdeac7da147)
52 |
53 | ##### 三、Android FFmpeg音视频解码篇
54 | - [x] 1,[FFmpeg so库编译](https://www.jianshu.com/p/350f8e083e82)
55 | - [x] 2,[Android 引入FFmpeg](https://www.jianshu.com/p/2c9918546edc)
56 | - 3,Android FFmpeg视频解码播放
57 | - 4,Android FFmpeg+OpenSL ES音频解码播放
58 | - 5,Android FFmpeg+OpenGL ES播放视频
59 | - 6,Android FFmpeg简单合成MP4:视屏解封与重新封装
60 | - 7,Android FFmpeg视频编码
61 | ---
62 |
--------------------------------------------------------------------------------
/app/src/main/cpp/ffmpeg/include/libavutil/pixelutils.h:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of FFmpeg.
3 | *
4 | * FFmpeg is free software; you can redistribute it and/or
5 | * modify it under the terms of the GNU Lesser General Public
6 | * License as published by the Free Software Foundation; either
7 | * version 2.1 of the License, or (at your option) any later version.
8 | *
9 | * FFmpeg is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 | * Lesser General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU Lesser General Public
15 | * License along with FFmpeg; if not, write to the Free Software
16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 | */
18 |
19 | #ifndef AVUTIL_PIXELUTILS_H
20 | #define AVUTIL_PIXELUTILS_H
21 |
22 | #include
23 | #include
24 | #include "common.h"
25 |
26 | /**
27 | * Sum of abs(src1[x] - src2[x])
28 | */
29 | typedef int (*av_pixelutils_sad_fn)(const uint8_t *src1, ptrdiff_t stride1,
30 | const uint8_t *src2, ptrdiff_t stride2);
31 |
32 | /**
33 | * Get a potentially optimized pointer to a Sum-of-absolute-differences
34 | * function (see the av_pixelutils_sad_fn prototype).
35 | *
36 | * @param w_bits 1<
2 |
9 |
10 |
15 |
16 |
21 |
22 |
27 |
32 |
37 |
42 |
47 |
52 |
57 |
58 |
--------------------------------------------------------------------------------
/app/src/main/cpp/ffmpeg/include/libavutil/lzo.h:
--------------------------------------------------------------------------------
1 | /*
2 | * LZO 1x decompression
3 | * copyright (c) 2006 Reimar Doeffinger
4 | *
5 | * This file is part of FFmpeg.
6 | *
7 | * FFmpeg is free software; you can redistribute it and/or
8 | * modify it under the terms of the GNU Lesser General Public
9 | * License as published by the Free Software Foundation; either
10 | * version 2.1 of the License, or (at your option) any later version.
11 | *
12 | * FFmpeg is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 | * Lesser General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU Lesser General Public
18 | * License along with FFmpeg; if not, write to the Free Software
19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 | */
21 |
22 | #ifndef AVUTIL_LZO_H
23 | #define AVUTIL_LZO_H
24 |
25 | /**
26 | * @defgroup lavu_lzo LZO
27 | * @ingroup lavu_crypto
28 | *
29 | * @{
30 | */
31 |
32 | #include
33 |
34 | /** @name Error flags returned by av_lzo1x_decode
35 | * @{ */
36 | /// end of the input buffer reached before decoding finished
37 | #define AV_LZO_INPUT_DEPLETED 1
38 | /// decoded data did not fit into output buffer
39 | #define AV_LZO_OUTPUT_FULL 2
40 | /// a reference to previously decoded data was wrong
41 | #define AV_LZO_INVALID_BACKPTR 4
42 | /// a non-specific error in the compressed bitstream
43 | #define AV_LZO_ERROR 8
44 | /** @} */
45 |
46 | #define AV_LZO_INPUT_PADDING 8
47 | #define AV_LZO_OUTPUT_PADDING 12
48 |
49 | /**
50 | * @brief Decodes LZO 1x compressed data.
51 | * @param out output buffer
52 | * @param outlen size of output buffer, number of bytes left are returned here
53 | * @param in input buffer
54 | * @param inlen size of input buffer, number of bytes left are returned here
55 | * @return 0 on success, otherwise a combination of the error flags above
56 | *
57 | * Make sure all buffers are appropriately padded, in must provide
58 | * AV_LZO_INPUT_PADDING, out must provide AV_LZO_OUTPUT_PADDING additional bytes.
59 | */
60 | int av_lzo1x_decode(void *out, int *outlen, const void *in, int *inlen);
61 |
62 | /**
63 | * @}
64 | */
65 |
66 | #endif /* AVUTIL_LZO_H */
67 |
--------------------------------------------------------------------------------
/app/src/main/cpp/ffmpeg/include/libavutil/tea.h:
--------------------------------------------------------------------------------
1 | /*
2 | * A 32-bit implementation of the TEA algorithm
3 | * Copyright (c) 2015 Vesselin Bontchev
4 | *
5 | * This file is part of FFmpeg.
6 | *
7 | * FFmpeg is free software; you can redistribute it and/or
8 | * modify it under the terms of the GNU Lesser General Public
9 | * License as published by the Free Software Foundation; either
10 | * version 2.1 of the License, or (at your option) any later version.
11 | *
12 | * FFmpeg is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 | * Lesser General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU Lesser General Public
18 | * License along with FFmpeg; if not, write to the Free Software
19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 | */
21 |
22 | #ifndef AVUTIL_TEA_H
23 | #define AVUTIL_TEA_H
24 |
25 | #include
26 |
27 | /**
28 | * @file
29 | * @brief Public header for libavutil TEA algorithm
30 | * @defgroup lavu_tea TEA
31 | * @ingroup lavu_crypto
32 | * @{
33 | */
34 |
35 | extern const int av_tea_size;
36 |
37 | struct AVTEA;
38 |
39 | /**
40 | * Allocate an AVTEA context
41 | * To free the struct: av_free(ptr)
42 | */
43 | struct AVTEA *av_tea_alloc(void);
44 |
45 | /**
46 | * Initialize an AVTEA context.
47 | *
48 | * @param ctx an AVTEA context
49 | * @param key a key of 16 bytes used for encryption/decryption
50 | * @param rounds the number of rounds in TEA (64 is the "standard")
51 | */
52 | void av_tea_init(struct AVTEA *ctx, const uint8_t key[16], int rounds);
53 |
54 | /**
55 | * Encrypt or decrypt a buffer using a previously initialized context.
56 | *
57 | * @param ctx an AVTEA context
58 | * @param dst destination array, can be equal to src
59 | * @param src source array, can be equal to dst
60 | * @param count number of 8 byte blocks
61 | * @param iv initialization vector for CBC mode, if NULL then ECB will be used
62 | * @param decrypt 0 for encryption, 1 for decryption
63 | */
64 | void av_tea_crypt(struct AVTEA *ctx, uint8_t *dst, const uint8_t *src,
65 | int count, uint8_t *iv, int decrypt);
66 |
67 | /**
68 | * @}
69 | */
70 |
71 | #endif /* AVUTIL_TEA_H */
72 |
--------------------------------------------------------------------------------
/app/src/main/cpp/ffmpeg/include/libavutil/camellia.h:
--------------------------------------------------------------------------------
1 | /*
2 | * An implementation of the CAMELLIA algorithm as mentioned in RFC3713
3 | * Copyright (c) 2014 Supraja Meedinti
4 | *
5 | * This file is part of FFmpeg.
6 | *
7 | * FFmpeg is free software; you can redistribute it and/or
8 | * modify it under the terms of the GNU Lesser General Public
9 | * License as published by the Free Software Foundation; either
10 | * version 2.1 of the License, or (at your option) any later version.
11 | *
12 | * FFmpeg is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 | * Lesser General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU Lesser General Public
18 | * License along with FFmpeg; if not, write to the Free Software
19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 | */
21 |
22 | #ifndef AVUTIL_CAMELLIA_H
23 | #define AVUTIL_CAMELLIA_H
24 |
25 | #include
26 |
27 |
28 | /**
29 | * @file
30 | * @brief Public header for libavutil CAMELLIA algorithm
31 | * @defgroup lavu_camellia CAMELLIA
32 | * @ingroup lavu_crypto
33 | * @{
34 | */
35 |
36 | extern const int av_camellia_size;
37 |
38 | struct AVCAMELLIA;
39 |
40 | /**
41 | * Allocate an AVCAMELLIA context
42 | * To free the struct: av_free(ptr)
43 | */
44 | struct AVCAMELLIA *av_camellia_alloc(void);
45 |
46 | /**
47 | * Initialize an AVCAMELLIA context.
48 | *
49 | * @param ctx an AVCAMELLIA context
50 | * @param key a key of 16, 24, 32 bytes used for encryption/decryption
51 | * @param key_bits number of keybits: possible are 128, 192, 256
52 | */
53 | int av_camellia_init(struct AVCAMELLIA *ctx, const uint8_t *key, int key_bits);
54 |
55 | /**
56 | * Encrypt or decrypt a buffer using a previously initialized context
57 | *
58 | * @param ctx an AVCAMELLIA context
59 | * @param dst destination array, can be equal to src
60 | * @param src source array, can be equal to dst
61 | * @param count number of 16 byte blocks
62 | * @paran iv initialization vector for CBC mode, NULL for ECB mode
63 | * @param decrypt 0 for encryption, 1 for decryption
64 | */
65 | void av_camellia_crypt(struct AVCAMELLIA *ctx, uint8_t *dst, const uint8_t *src, int count, uint8_t* iv, int decrypt);
66 |
67 | /**
68 | * @}
69 | */
70 | #endif /* AVUTIL_CAMELLIA_H */
71 |
--------------------------------------------------------------------------------
/app/src/main/java/com/cxp/learningvideo/media/muxer/MP4Repack.kt:
--------------------------------------------------------------------------------
1 | package com.cxp.learningvideo.media.muxer
2 |
3 | import android.media.MediaCodec
4 | import android.util.Log
5 | import com.cxp.learningvideo.media.extractor.AudioExtractor
6 | import com.cxp.learningvideo.media.extractor.VideoExtractor
7 | import java.nio.ByteBuffer
8 |
9 |
10 | /**
11 | * MP4重打包工具
12 | *
13 | * @author Chen Xiaoping (562818444@qq.com)
14 | * @since LearningVideo
15 | * @version LearningVideo
16 | * @Datetime 2019-09-19 14:09
17 | *
18 | */
19 | class MP4Repack(path: String) {
20 |
21 | private val TAG = "MP4Repack"
22 |
23 | private val mAExtractor: AudioExtractor = AudioExtractor(path)
24 | private val mVExtractor: VideoExtractor = VideoExtractor(path)
25 | private val mMuxer: MMuxer = MMuxer()
26 |
27 | fun start() {
28 | val audioFormat = mAExtractor.getFormat()
29 | val videoFormat = mVExtractor.getFormat()
30 |
31 | if (audioFormat != null) {
32 | mMuxer.addAudioTrack(audioFormat)
33 | } else {
34 | mMuxer.setNoAudio()
35 | }
36 | if (videoFormat != null) {
37 | mMuxer.addVideoTrack(videoFormat)
38 | } else {
39 | mMuxer.setNoVideo()
40 | }
41 |
42 | Thread {
43 | val buffer = ByteBuffer.allocate(500 * 1024)
44 | val bufferInfo = MediaCodec.BufferInfo()
45 | if (audioFormat != null) {
46 | var size = mAExtractor.readBuffer(buffer)
47 | while (size > 0) {
48 | bufferInfo.set(0, size, mAExtractor.getCurrentTimestamp(), mAExtractor.getSampleFlag())
49 | mMuxer.writeAudioData(buffer, bufferInfo)
50 | size = mAExtractor.readBuffer(buffer)
51 | }
52 | }
53 | if (videoFormat != null) {
54 | var size = mVExtractor.readBuffer(buffer)
55 | while (size > 0) {
56 | bufferInfo.set(0, size, mVExtractor.getCurrentTimestamp(), mVExtractor.getSampleFlag())
57 | mMuxer.writeVideoData(buffer, bufferInfo)
58 | size = mVExtractor.readBuffer(buffer)
59 | }
60 | }
61 | mAExtractor.stop()
62 | mVExtractor.stop()
63 | mMuxer.releaseAudioTrack()
64 | mMuxer.releaseVideoTrack()
65 | Log.i(TAG, "MP4 重打包完成")
66 | }.start()
67 | }
68 | }
--------------------------------------------------------------------------------
/app/src/main/cpp/ffmpeg/include/libavutil/twofish.h:
--------------------------------------------------------------------------------
1 | /*
2 | * An implementation of the TwoFish algorithm
3 | * Copyright (c) 2015 Supraja Meedinti
4 | *
5 | * This file is part of FFmpeg.
6 | *
7 | * FFmpeg is free software; you can redistribute it and/or
8 | * modify it under the terms of the GNU Lesser General Public
9 | * License as published by the Free Software Foundation; either
10 | * version 2.1 of the License, or (at your option) any later version.
11 | *
12 | * FFmpeg is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 | * Lesser General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU Lesser General Public
18 | * License along with FFmpeg; if not, write to the Free Software
19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 | */
21 |
22 | #ifndef AVUTIL_TWOFISH_H
23 | #define AVUTIL_TWOFISH_H
24 |
25 | #include
26 |
27 |
28 | /**
29 | * @file
30 | * @brief Public header for libavutil TWOFISH algorithm
31 | * @defgroup lavu_twofish TWOFISH
32 | * @ingroup lavu_crypto
33 | * @{
34 | */
35 |
36 | extern const int av_twofish_size;
37 |
38 | struct AVTWOFISH;
39 |
40 | /**
41 | * Allocate an AVTWOFISH context
42 | * To free the struct: av_free(ptr)
43 | */
44 | struct AVTWOFISH *av_twofish_alloc(void);
45 |
46 | /**
47 | * Initialize an AVTWOFISH context.
48 | *
49 | * @param ctx an AVTWOFISH context
50 | * @param key a key of size ranging from 1 to 32 bytes used for encryption/decryption
51 | * @param key_bits number of keybits: 128, 192, 256 If less than the required, padded with zeroes to nearest valid value; return value is 0 if key_bits is 128/192/256, -1 if less than 0, 1 otherwise
52 | */
53 | int av_twofish_init(struct AVTWOFISH *ctx, const uint8_t *key, int key_bits);
54 |
55 | /**
56 | * Encrypt or decrypt a buffer using a previously initialized context
57 | *
58 | * @param ctx an AVTWOFISH context
59 | * @param dst destination array, can be equal to src
60 | * @param src source array, can be equal to dst
61 | * @param count number of 16 byte blocks
62 | * @paran iv initialization vector for CBC mode, NULL for ECB mode
63 | * @param decrypt 0 for encryption, 1 for decryption
64 | */
65 | void av_twofish_crypt(struct AVTWOFISH *ctx, uint8_t *dst, const uint8_t *src, int count, uint8_t* iv, int decrypt);
66 |
67 | /**
68 | * @}
69 | */
70 | #endif /* AVUTIL_TWOFISH_H */
71 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | set DIRNAME=%~dp0
12 | if "%DIRNAME%" == "" set DIRNAME=.
13 | set APP_BASE_NAME=%~n0
14 | set APP_HOME=%DIRNAME%
15 |
16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
17 | set DEFAULT_JVM_OPTS=
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windows variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 |
53 | :win9xME_args
54 | @rem Slurp the command line arguments.
55 | set CMD_LINE_ARGS=
56 | set _SKIP=2
57 |
58 | :win9xME_args_slurp
59 | if "x%~1" == "x" goto execute
60 |
61 | set CMD_LINE_ARGS=%*
62 |
63 | :execute
64 | @rem Setup the command line
65 |
66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
67 |
68 | @rem Execute Gradle
69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
70 |
71 | :end
72 | @rem End local scope for the variables with windows NT shell
73 | if "%ERRORLEVEL%"=="0" goto mainEnd
74 |
75 | :fail
76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
77 | rem the _cmd.exe /c_ return code!
78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
79 | exit /b 1
80 |
81 | :mainEnd
82 | if "%OS%"=="Windows_NT" endlocal
83 |
84 | :omega
85 |
--------------------------------------------------------------------------------
/app/src/main/cpp/ffmpeg/include/libavutil/base64.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2006 Ryan Martell. (rdm4@martellventures.com)
3 | *
4 | * This file is part of FFmpeg.
5 | *
6 | * FFmpeg is free software; you can redistribute it and/or
7 | * modify it under the terms of the GNU Lesser General Public
8 | * License as published by the Free Software Foundation; either
9 | * version 2.1 of the License, or (at your option) any later version.
10 | *
11 | * FFmpeg is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 | * Lesser General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU Lesser General Public
17 | * License along with FFmpeg; if not, write to the Free Software
18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 | */
20 |
21 | #ifndef AVUTIL_BASE64_H
22 | #define AVUTIL_BASE64_H
23 |
24 | #include
25 |
26 | /**
27 | * @defgroup lavu_base64 Base64
28 | * @ingroup lavu_crypto
29 | * @{
30 | */
31 |
32 | /**
33 | * Decode a base64-encoded string.
34 | *
35 | * @param out buffer for decoded data
36 | * @param in null-terminated input string
37 | * @param out_size size in bytes of the out buffer, must be at
38 | * least 3/4 of the length of in, that is AV_BASE64_DECODE_SIZE(strlen(in))
39 | * @return number of bytes written, or a negative value in case of
40 | * invalid input
41 | */
42 | int av_base64_decode(uint8_t *out, const char *in, int out_size);
43 |
44 | /**
45 | * Calculate the output size in bytes needed to decode a base64 string
46 | * with length x to a data buffer.
47 | */
48 | #define AV_BASE64_DECODE_SIZE(x) ((x) * 3LL / 4)
49 |
50 | /**
51 | * Encode data to base64 and null-terminate.
52 | *
53 | * @param out buffer for encoded data
54 | * @param out_size size in bytes of the out buffer (including the
55 | * null terminator), must be at least AV_BASE64_SIZE(in_size)
56 | * @param in input buffer containing the data to encode
57 | * @param in_size size in bytes of the in buffer
58 | * @return out or NULL in case of error
59 | */
60 | char *av_base64_encode(char *out, int out_size, const uint8_t *in, int in_size);
61 |
62 | /**
63 | * Calculate the output size needed to base64-encode x bytes to a
64 | * null-terminated string.
65 | */
66 | #define AV_BASE64_SIZE(x) (((x)+2) / 3 * 4 + 1)
67 |
68 | /**
69 | * @}
70 | */
71 |
72 | #endif /* AVUTIL_BASE64_H */
73 |
--------------------------------------------------------------------------------
/app/src/main/cpp/ffmpeg/include/libavcodec/vorbis_parser.h:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of FFmpeg.
3 | *
4 | * FFmpeg is free software; you can redistribute it and/or
5 | * modify it under the terms of the GNU Lesser General Public
6 | * License as published by the Free Software Foundation; either
7 | * version 2.1 of the License, or (at your option) any later version.
8 | *
9 | * FFmpeg is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 | * Lesser General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU Lesser General Public
15 | * License along with FFmpeg; if not, write to the Free Software
16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 | */
18 |
19 | /**
20 | * @file
21 | * A public API for Vorbis parsing
22 | *
23 | * Determines the duration for each packet.
24 | */
25 |
26 | #ifndef AVCODEC_VORBIS_PARSER_H
27 | #define AVCODEC_VORBIS_PARSER_H
28 |
29 | #include
30 |
31 | typedef struct AVVorbisParseContext AVVorbisParseContext;
32 |
33 | /**
34 | * Allocate and initialize the Vorbis parser using headers in the extradata.
35 | */
36 | AVVorbisParseContext *av_vorbis_parse_init(const uint8_t *extradata,
37 | int extradata_size);
38 |
39 | /**
40 | * Free the parser and everything associated with it.
41 | */
42 | void av_vorbis_parse_free(AVVorbisParseContext **s);
43 |
44 | #define VORBIS_FLAG_HEADER 0x00000001
45 | #define VORBIS_FLAG_COMMENT 0x00000002
46 | #define VORBIS_FLAG_SETUP 0x00000004
47 |
48 | /**
49 | * Get the duration for a Vorbis packet.
50 | *
51 | * If @p flags is @c NULL,
52 | * special frames are considered invalid.
53 | *
54 | * @param s Vorbis parser context
55 | * @param buf buffer containing a Vorbis frame
56 | * @param buf_size size of the buffer
57 | * @param flags flags for special frames
58 | */
59 | int av_vorbis_parse_frame_flags(AVVorbisParseContext *s, const uint8_t *buf,
60 | int buf_size, int *flags);
61 |
62 | /**
63 | * Get the duration for a Vorbis packet.
64 | *
65 | * @param s Vorbis parser context
66 | * @param buf buffer containing a Vorbis frame
67 | * @param buf_size size of the buffer
68 | */
69 | int av_vorbis_parse_frame(AVVorbisParseContext *s, const uint8_t *buf,
70 | int buf_size);
71 |
72 | void av_vorbis_parse_reset(AVVorbisParseContext *s);
73 |
74 | #endif /* AVCODEC_VORBIS_PARSER_H */
75 |
--------------------------------------------------------------------------------
/app/src/main/cpp/ffmpeg/include/libavfilter/version.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Version macros.
3 | *
4 | * This file is part of FFmpeg.
5 | *
6 | * FFmpeg is free software; you can redistribute it and/or
7 | * modify it under the terms of the GNU Lesser General Public
8 | * License as published by the Free Software Foundation; either
9 | * version 2.1 of the License, or (at your option) any later version.
10 | *
11 | * FFmpeg is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 | * Lesser General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU Lesser General Public
17 | * License along with FFmpeg; if not, write to the Free Software
18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 | */
20 |
21 | #ifndef AVFILTER_VERSION_H
22 | #define AVFILTER_VERSION_H
23 |
24 | /**
25 | * @file
26 | * @ingroup lavfi
27 | * Libavfilter version macros
28 | */
29 |
30 | #include "libavutil/version.h"
31 |
32 | #define LIBAVFILTER_VERSION_MAJOR 7
33 | #define LIBAVFILTER_VERSION_MINOR 57
34 | #define LIBAVFILTER_VERSION_MICRO 100
35 |
36 |
37 | #define LIBAVFILTER_VERSION_INT AV_VERSION_INT(LIBAVFILTER_VERSION_MAJOR, \
38 | LIBAVFILTER_VERSION_MINOR, \
39 | LIBAVFILTER_VERSION_MICRO)
40 | #define LIBAVFILTER_VERSION AV_VERSION(LIBAVFILTER_VERSION_MAJOR, \
41 | LIBAVFILTER_VERSION_MINOR, \
42 | LIBAVFILTER_VERSION_MICRO)
43 | #define LIBAVFILTER_BUILD LIBAVFILTER_VERSION_INT
44 |
45 | #define LIBAVFILTER_IDENT "Lavfi" AV_STRINGIFY(LIBAVFILTER_VERSION)
46 |
47 | /**
48 | * FF_API_* defines may be placed below to indicate public API that will be
49 | * dropped at a future version bump. The defines themselves are not part of
50 | * the public API and may change, break or disappear at any time.
51 | */
52 |
53 | #ifndef FF_API_OLD_FILTER_OPTS_ERROR
54 | #define FF_API_OLD_FILTER_OPTS_ERROR (LIBAVFILTER_VERSION_MAJOR < 8)
55 | #endif
56 | #ifndef FF_API_LAVR_OPTS
57 | #define FF_API_LAVR_OPTS (LIBAVFILTER_VERSION_MAJOR < 8)
58 | #endif
59 | #ifndef FF_API_FILTER_GET_SET
60 | #define FF_API_FILTER_GET_SET (LIBAVFILTER_VERSION_MAJOR < 8)
61 | #endif
62 | #ifndef FF_API_NEXT
63 | #define FF_API_NEXT (LIBAVFILTER_VERSION_MAJOR < 8)
64 | #endif
65 |
66 | #endif /* AVFILTER_VERSION_H */
67 |
--------------------------------------------------------------------------------
/app/src/main/cpp/ffmpeg/include/libavutil/aes_ctr.h:
--------------------------------------------------------------------------------
1 | /*
2 | * AES-CTR cipher
3 | * Copyright (c) 2015 Eran Kornblau
4 | *
5 | * This file is part of FFmpeg.
6 | *
7 | * FFmpeg is free software; you can redistribute it and/or
8 | * modify it under the terms of the GNU Lesser General Public
9 | * License as published by the Free Software Foundation; either
10 | * version 2.1 of the License, or (at your option) any later version.
11 | *
12 | * FFmpeg is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 | * Lesser General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU Lesser General Public
18 | * License along with FFmpeg; if not, write to the Free Software
19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 | */
21 |
22 | #ifndef AVUTIL_AES_CTR_H
23 | #define AVUTIL_AES_CTR_H
24 |
25 | #include
26 |
27 | #include "attributes.h"
28 | #include "version.h"
29 |
30 | #define AES_CTR_KEY_SIZE (16)
31 | #define AES_CTR_IV_SIZE (8)
32 |
33 | struct AVAESCTR;
34 |
35 | /**
36 | * Allocate an AVAESCTR context.
37 | */
38 | struct AVAESCTR *av_aes_ctr_alloc(void);
39 |
40 | /**
41 | * Initialize an AVAESCTR context.
42 | * @param key encryption key, must have a length of AES_CTR_KEY_SIZE
43 | */
44 | int av_aes_ctr_init(struct AVAESCTR *a, const uint8_t *key);
45 |
46 | /**
47 | * Release an AVAESCTR context.
48 | */
49 | void av_aes_ctr_free(struct AVAESCTR *a);
50 |
51 | /**
52 | * Process a buffer using a previously initialized context.
53 | * @param dst destination array, can be equal to src
54 | * @param src source array, can be equal to dst
55 | * @param size the size of src and dst
56 | */
57 | void av_aes_ctr_crypt(struct AVAESCTR *a, uint8_t *dst, const uint8_t *src, int size);
58 |
59 | /**
60 | * Get the current iv
61 | */
62 | const uint8_t* av_aes_ctr_get_iv(struct AVAESCTR *a);
63 |
64 | /**
65 | * Generate a random iv
66 | */
67 | void av_aes_ctr_set_random_iv(struct AVAESCTR *a);
68 |
69 | /**
70 | * Forcefully change the 8-byte iv
71 | */
72 | void av_aes_ctr_set_iv(struct AVAESCTR *a, const uint8_t* iv);
73 |
74 | /**
75 | * Forcefully change the "full" 16-byte iv, including the counter
76 | */
77 | void av_aes_ctr_set_full_iv(struct AVAESCTR *a, const uint8_t* iv);
78 |
79 | /**
80 | * Increment the top 64 bit of the iv (performed after each frame)
81 | */
82 | void av_aes_ctr_increment_iv(struct AVAESCTR *a);
83 |
84 | /**
85 | * @}
86 | */
87 |
88 | #endif /* AVUTIL_AES_CTR_H */
89 |
--------------------------------------------------------------------------------
/app/src/main/cpp/ffmpeg/include/libavutil/des.h:
--------------------------------------------------------------------------------
1 | /*
2 | * DES encryption/decryption
3 | * Copyright (c) 2007 Reimar Doeffinger
4 | *
5 | * This file is part of FFmpeg.
6 | *
7 | * FFmpeg is free software; you can redistribute it and/or
8 | * modify it under the terms of the GNU Lesser General Public
9 | * License as published by the Free Software Foundation; either
10 | * version 2.1 of the License, or (at your option) any later version.
11 | *
12 | * FFmpeg is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 | * Lesser General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU Lesser General Public
18 | * License along with FFmpeg; if not, write to the Free Software
19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 | */
21 |
22 | #ifndef AVUTIL_DES_H
23 | #define AVUTIL_DES_H
24 |
25 | #include
26 |
27 | /**
28 | * @defgroup lavu_des DES
29 | * @ingroup lavu_crypto
30 | * @{
31 | */
32 |
33 | typedef struct AVDES {
34 | uint64_t round_keys[3][16];
35 | int triple_des;
36 | } AVDES;
37 |
38 | /**
39 | * Allocate an AVDES context.
40 | */
41 | AVDES *av_des_alloc(void);
42 |
43 | /**
44 | * @brief Initializes an AVDES context.
45 | *
46 | * @param key_bits must be 64 or 192
47 | * @param decrypt 0 for encryption/CBC-MAC, 1 for decryption
48 | * @return zero on success, negative value otherwise
49 | */
50 | int av_des_init(struct AVDES *d, const uint8_t *key, int key_bits, int decrypt);
51 |
52 | /**
53 | * @brief Encrypts / decrypts using the DES algorithm.
54 | *
55 | * @param count number of 8 byte blocks
56 | * @param dst destination array, can be equal to src, must be 8-byte aligned
57 | * @param src source array, can be equal to dst, must be 8-byte aligned, may be NULL
58 | * @param iv initialization vector for CBC mode, if NULL then ECB will be used,
59 | * must be 8-byte aligned
60 | * @param decrypt 0 for encryption, 1 for decryption
61 | */
62 | void av_des_crypt(struct AVDES *d, uint8_t *dst, const uint8_t *src, int count, uint8_t *iv, int decrypt);
63 |
64 | /**
65 | * @brief Calculates CBC-MAC using the DES algorithm.
66 | *
67 | * @param count number of 8 byte blocks
68 | * @param dst destination array, can be equal to src, must be 8-byte aligned
69 | * @param src source array, can be equal to dst, must be 8-byte aligned, may be NULL
70 | */
71 | void av_des_mac(struct AVDES *d, uint8_t *dst, const uint8_t *src, int count);
72 |
73 | /**
74 | * @}
75 | */
76 |
77 | #endif /* AVUTIL_DES_H */
78 |
--------------------------------------------------------------------------------
/app/src/main/cpp/ffmpeg/include/libavutil/ripemd.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2007 Michael Niedermayer
3 | * Copyright (C) 2013 James Almer
4 | *
5 | * This file is part of FFmpeg.
6 | *
7 | * FFmpeg is free software; you can redistribute it and/or
8 | * modify it under the terms of the GNU Lesser General Public
9 | * License as published by the Free Software Foundation; either
10 | * version 2.1 of the License, or (at your option) any later version.
11 | *
12 | * FFmpeg is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 | * Lesser General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU Lesser General Public
18 | * License along with FFmpeg; if not, write to the Free Software
19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 | */
21 |
22 | /**
23 | * @file
24 | * @ingroup lavu_ripemd
25 | * Public header for RIPEMD hash function implementation.
26 | */
27 |
28 | #ifndef AVUTIL_RIPEMD_H
29 | #define AVUTIL_RIPEMD_H
30 |
31 | #include
32 |
33 | #include "attributes.h"
34 | #include "version.h"
35 |
36 | /**
37 | * @defgroup lavu_ripemd RIPEMD
38 | * @ingroup lavu_hash
39 | * RIPEMD hash function implementation.
40 | *
41 | * @{
42 | */
43 |
44 | extern const int av_ripemd_size;
45 |
46 | struct AVRIPEMD;
47 |
48 | /**
49 | * Allocate an AVRIPEMD context.
50 | */
51 | struct AVRIPEMD *av_ripemd_alloc(void);
52 |
53 | /**
54 | * Initialize RIPEMD hashing.
55 | *
56 | * @param context pointer to the function context (of size av_ripemd_size)
57 | * @param bits number of bits in digest (128, 160, 256 or 320 bits)
58 | * @return zero if initialization succeeded, -1 otherwise
59 | */
60 | int av_ripemd_init(struct AVRIPEMD* context, int bits);
61 |
62 | /**
63 | * Update hash value.
64 | *
65 | * @param context hash function context
66 | * @param data input data to update hash with
67 | * @param len input data length
68 | */
69 | #if FF_API_CRYPTO_SIZE_T
70 | void av_ripemd_update(struct AVRIPEMD* context, const uint8_t* data, unsigned int len);
71 | #else
72 | void av_ripemd_update(struct AVRIPEMD* context, const uint8_t* data, size_t len);
73 | #endif
74 |
75 | /**
76 | * Finish hashing and output digest value.
77 | *
78 | * @param context hash function context
79 | * @param digest buffer where output digest value is stored
80 | */
81 | void av_ripemd_final(struct AVRIPEMD* context, uint8_t *digest);
82 |
83 | /**
84 | * @}
85 | */
86 |
87 | #endif /* AVUTIL_RIPEMD_H */
88 |
--------------------------------------------------------------------------------
/app/src/main/cpp/ffmpeg/include/libavcodec/vaapi.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Video Acceleration API (shared data between FFmpeg and the video player)
3 | * HW decode acceleration for MPEG-2, MPEG-4, H.264 and VC-1
4 | *
5 | * Copyright (C) 2008-2009 Splitted-Desktop Systems
6 | *
7 | * This file is part of FFmpeg.
8 | *
9 | * FFmpeg is free software; you can redistribute it and/or
10 | * modify it under the terms of the GNU Lesser General Public
11 | * License as published by the Free Software Foundation; either
12 | * version 2.1 of the License, or (at your option) any later version.
13 | *
14 | * FFmpeg is distributed in the hope that it will be useful,
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 | * Lesser General Public License for more details.
18 | *
19 | * You should have received a copy of the GNU Lesser General Public
20 | * License along with FFmpeg; if not, write to the Free Software
21 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22 | */
23 |
24 | #ifndef AVCODEC_VAAPI_H
25 | #define AVCODEC_VAAPI_H
26 |
27 | /**
28 | * @file
29 | * @ingroup lavc_codec_hwaccel_vaapi
30 | * Public libavcodec VA API header.
31 | */
32 |
33 | #include
34 | #include "libavutil/attributes.h"
35 | #include "version.h"
36 |
37 | #if FF_API_STRUCT_VAAPI_CONTEXT
38 |
39 | /**
40 | * @defgroup lavc_codec_hwaccel_vaapi VA API Decoding
41 | * @ingroup lavc_codec_hwaccel
42 | * @{
43 | */
44 |
45 | /**
46 | * This structure is used to share data between the FFmpeg library and
47 | * the client video application.
48 | * This shall be zero-allocated and available as
49 | * AVCodecContext.hwaccel_context. All user members can be set once
50 | * during initialization or through each AVCodecContext.get_buffer()
51 | * function call. In any case, they must be valid prior to calling
52 | * decoding functions.
53 | *
54 | * Deprecated: use AVCodecContext.hw_frames_ctx instead.
55 | */
56 | struct attribute_deprecated vaapi_context {
57 | /**
58 | * Window system dependent data
59 | *
60 | * - encoding: unused
61 | * - decoding: Set by user
62 | */
63 | void *display;
64 |
65 | /**
66 | * Configuration ID
67 | *
68 | * - encoding: unused
69 | * - decoding: Set by user
70 | */
71 | uint32_t config_id;
72 |
73 | /**
74 | * Context ID (video decode pipeline)
75 | *
76 | * - encoding: unused
77 | * - decoding: Set by user
78 | */
79 | uint32_t context_id;
80 | };
81 |
82 | /* @} */
83 |
84 | #endif /* FF_API_STRUCT_VAAPI_CONTEXT */
85 |
86 | #endif /* AVCODEC_VAAPI_H */
87 |
--------------------------------------------------------------------------------
/app/src/main/cpp/ffmpeg/include/libavutil/avassert.h:
--------------------------------------------------------------------------------
1 | /*
2 | * copyright (c) 2010 Michael Niedermayer
3 | *
4 | * This file is part of FFmpeg.
5 | *
6 | * FFmpeg is free software; you can redistribute it and/or
7 | * modify it under the terms of the GNU Lesser General Public
8 | * License as published by the Free Software Foundation; either
9 | * version 2.1 of the License, or (at your option) any later version.
10 | *
11 | * FFmpeg is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 | * Lesser General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU Lesser General Public
17 | * License along with FFmpeg; if not, write to the Free Software
18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 | */
20 |
21 | /**
22 | * @file
23 | * simple assert() macros that are a bit more flexible than ISO C assert().
24 | * @author Michael Niedermayer
25 | */
26 |
27 | #ifndef AVUTIL_AVASSERT_H
28 | #define AVUTIL_AVASSERT_H
29 |
30 | #include
31 | #include "avutil.h"
32 | #include "log.h"
33 |
34 | /**
35 | * assert() equivalent, that is always enabled.
36 | */
37 | #define av_assert0(cond) do { \
38 | if (!(cond)) { \
39 | av_log(NULL, AV_LOG_PANIC, "Assertion %s failed at %s:%d\n", \
40 | AV_STRINGIFY(cond), __FILE__, __LINE__); \
41 | abort(); \
42 | } \
43 | } while (0)
44 |
45 |
46 | /**
47 | * assert() equivalent, that does not lie in speed critical code.
48 | * These asserts() thus can be enabled without fearing speed loss.
49 | */
50 | #if defined(ASSERT_LEVEL) && ASSERT_LEVEL > 0
51 | #define av_assert1(cond) av_assert0(cond)
52 | #else
53 | #define av_assert1(cond) ((void)0)
54 | #endif
55 |
56 |
57 | /**
58 | * assert() equivalent, that does lie in speed critical code.
59 | */
60 | #if defined(ASSERT_LEVEL) && ASSERT_LEVEL > 1
61 | #define av_assert2(cond) av_assert0(cond)
62 | #define av_assert2_fpu() av_assert0_fpu()
63 | #else
64 | #define av_assert2(cond) ((void)0)
65 | #define av_assert2_fpu() ((void)0)
66 | #endif
67 |
68 | /**
69 | * Assert that floating point operations can be executed.
70 | *
71 | * This will av_assert0() that the cpu is not in MMX state on X86
72 | */
73 | void av_assert0_fpu(void);
74 |
75 | #endif /* AVUTIL_AVASSERT_H */
76 |
--------------------------------------------------------------------------------
/app/src/main/java/com/cxp/learningvideo/opengl/OpenGLTools.kt:
--------------------------------------------------------------------------------
1 | package com.cxp.learningvideo.opengl
2 |
3 | import android.opengl.GLES20
4 |
5 |
6 | /**
7 | * OpenGL 常用方法集合
8 | *
9 | * @author Chen Xiaoping (562818444@qq.com)
10 | * @since LearningVideo
11 | * @version LearningVideo
12 | * @Datetime 2019-19-09 08:55
13 | *
14 | */
15 | object OpenGLTools {
16 |
17 | fun createTextureIds(count: Int): IntArray {
18 | val texture = IntArray(count)
19 | GLES20.glGenTextures(count, texture, 0) //生成纹理
20 | return texture
21 | }
22 |
23 | fun createFBOTexture(width: Int, height: Int): Int {
24 | val textures = IntArray(1)
25 | GLES20.glGenTextures(1, textures, 0)
26 | GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, textures[0])
27 | GLES20.glTexImage2D(GLES20.GL_TEXTURE_2D, 0, GLES20.GL_RGBA, width, height,
28 | 0, GLES20.GL_RGBA, GLES20.GL_UNSIGNED_BYTE, null)
29 | GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_NEAREST.toFloat())
30 | GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MAG_FILTER,GLES20.GL_LINEAR.toFloat())
31 | GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_S,GLES20.GL_CLAMP_TO_EDGE.toFloat())
32 | GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_T,GLES20.GL_CLAMP_TO_EDGE.toFloat())
33 | GLES20.glBindTexture(GLES20.GL_TEXTURE_2D,0)
34 | return textures[0]
35 | }
36 |
37 | fun createFrameBuffer(): Int {
38 | val fbs = IntArray(1)
39 | GLES20.glGenFramebuffers(1, fbs, 0)
40 | return fbs[0]
41 | }
42 |
43 | fun bindFBO(fb: Int, textureId: Int) {
44 | GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, fb)
45 | GLES20.glFramebufferTexture2D(GLES20.GL_FRAMEBUFFER, GLES20.GL_COLOR_ATTACHMENT0,
46 | GLES20.GL_TEXTURE_2D, textureId, 0)
47 | }
48 |
49 | fun unbindFBO() {
50 | GLES20.glBindRenderbuffer(GLES20.GL_RENDERBUFFER, GLES20.GL_NONE)
51 | GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, GLES20.GL_NONE)
52 | GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, 0)
53 | }
54 |
55 | fun deleteFBO(frame: IntArray, texture:IntArray) {
56 | //删除Render Buffer
57 | GLES20.glBindRenderbuffer(GLES20.GL_RENDERBUFFER, GLES20.GL_NONE)
58 | // GLES20.glDeleteRenderbuffers(1, fRender, 0)
59 | //删除Frame Buffer
60 | GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, GLES20.GL_NONE)
61 | GLES20.glDeleteFramebuffers(1, frame, 0)
62 | //删除纹理
63 | GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, 0)
64 | GLES20.glDeleteTextures(1, texture, 0)
65 | }
66 |
67 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/cxp/learningvideo/EGLPlayerActivity.kt:
--------------------------------------------------------------------------------
1 | package com.cxp.learningvideo
2 |
3 | import android.os.Bundle
4 | import android.os.Environment
5 | import android.os.Handler
6 | import android.support.v7.app.AppCompatActivity
7 | import android.view.Surface
8 | import com.cxp.learningvideo.media.decoder.AudioDecoder
9 | import com.cxp.learningvideo.media.decoder.VideoDecoder
10 | import com.cxp.learningvideo.opengl.drawer.VideoDrawer
11 | import com.cxp.learningvideo.opengl.egl.CustomerGLRenderer
12 | import kotlinx.android.synthetic.main.activity_egl_player.*
13 | import java.util.concurrent.Executors
14 |
15 |
16 | /**
17 | * 使用自定义的OpenGL(EGL+Thread)渲染器,渲染多个视频画面的播放器
18 | *
19 | * @author Chen Xiaoping (562818444@qq.com)
20 | * @since LearningVideo
21 | * @version LearningVideo
22 | * @Datetime 2019-10-26 21:07
23 | *
24 | */
25 | class EGLPlayerActivity: AppCompatActivity() {
26 | private val path = Environment.getExternalStorageDirectory().absolutePath + "/mvtest_2.mp4"
27 | private val path2 = Environment.getExternalStorageDirectory().absolutePath + "/mvtest.mp4"
28 |
29 | private val threadPool = Executors.newFixedThreadPool(10)
30 |
31 | private var mRenderer = CustomerGLRenderer()
32 |
33 | override fun onCreate(savedInstanceState: Bundle?) {
34 | super.onCreate(savedInstanceState)
35 | setContentView(R.layout.activity_egl_player)
36 | initFirstVideo()
37 | initSecondVideo()
38 | setRenderSurface()
39 | }
40 |
41 | private fun initFirstVideo() {
42 | val drawer = VideoDrawer()
43 | drawer.setVideoSize(1920, 1080)
44 | drawer.getSurfaceTexture {
45 | initPlayer(path, Surface(it), true)
46 | }
47 | mRenderer.addDrawer(drawer)
48 | }
49 |
50 | private fun initSecondVideo() {
51 | val drawer = VideoDrawer()
52 | drawer.setAlpha(0.5f)
53 | drawer.setVideoSize(1920, 1080)
54 | drawer.getSurfaceTexture {
55 | initPlayer(path2, Surface(it), false)
56 | }
57 | mRenderer.addDrawer(drawer)
58 |
59 | Handler().postDelayed({
60 | drawer.scale(0.5f, 0.5f)
61 | }, 1000)
62 | }
63 |
64 | private fun initPlayer(path: String, sf: Surface, withSound: Boolean) {
65 | val videoDecoder = VideoDecoder(path, null, sf)
66 | threadPool.execute(videoDecoder)
67 | videoDecoder.goOn()
68 |
69 | if (withSound) {
70 | val audioDecoder = AudioDecoder(path)
71 | threadPool.execute(audioDecoder)
72 | audioDecoder.goOn()
73 | }
74 | }
75 |
76 | private fun setRenderSurface() {
77 | mRenderer.setSurface(sfv)
78 | }
79 | }
--------------------------------------------------------------------------------
/app/src/main/cpp/ffmpeg/include/libavutil/hwcontext_dxva2.h:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of FFmpeg.
3 | *
4 | * FFmpeg is free software; you can redistribute it and/or
5 | * modify it under the terms of the GNU Lesser General Public
6 | * License as published by the Free Software Foundation; either
7 | * version 2.1 of the License, or (at your option) any later version.
8 | *
9 | * FFmpeg is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 | * Lesser General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU Lesser General Public
15 | * License along with FFmpeg; if not, write to the Free Software
16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 | */
18 |
19 |
20 | #ifndef AVUTIL_HWCONTEXT_DXVA2_H
21 | #define AVUTIL_HWCONTEXT_DXVA2_H
22 |
23 | /**
24 | * @file
25 | * An API-specific header for AV_HWDEVICE_TYPE_DXVA2.
26 | *
27 | * Only fixed-size pools are supported.
28 | *
29 | * For user-allocated pools, AVHWFramesContext.pool must return AVBufferRefs
30 | * with the data pointer set to a pointer to IDirect3DSurface9.
31 | */
32 |
33 | #include
34 | #include
35 |
36 | /**
37 | * This struct is allocated as AVHWDeviceContext.hwctx
38 | */
39 | typedef struct AVDXVA2DeviceContext {
40 | IDirect3DDeviceManager9 *devmgr;
41 | } AVDXVA2DeviceContext;
42 |
43 | /**
44 | * This struct is allocated as AVHWFramesContext.hwctx
45 | */
46 | typedef struct AVDXVA2FramesContext {
47 | /**
48 | * The surface type (e.g. DXVA2_VideoProcessorRenderTarget or
49 | * DXVA2_VideoDecoderRenderTarget). Must be set by the caller.
50 | */
51 | DWORD surface_type;
52 |
53 | /**
54 | * The surface pool. When an external pool is not provided by the caller,
55 | * this will be managed (allocated and filled on init, freed on uninit) by
56 | * libavutil.
57 | */
58 | IDirect3DSurface9 **surfaces;
59 | int nb_surfaces;
60 |
61 | /**
62 | * Certain drivers require the decoder to be destroyed before the surfaces.
63 | * To allow internally managed pools to work properly in such cases, this
64 | * field is provided.
65 | *
66 | * If it is non-NULL, libavutil will call IDirectXVideoDecoder_Release() on
67 | * it just before the internal surface pool is freed.
68 | *
69 | * This is for convenience only. Some code uses other methods to manage the
70 | * decoder reference.
71 | */
72 | IDirectXVideoDecoder *decoder_to_release;
73 | } AVDXVA2FramesContext;
74 |
75 | #endif /* AVUTIL_HWCONTEXT_DXVA2_H */
76 |
--------------------------------------------------------------------------------
/app/src/main/cpp/ffmpeg/include/libavutil/blowfish.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Blowfish algorithm
3 | * Copyright (c) 2012 Samuel Pitoiset
4 | *
5 | * This file is part of FFmpeg.
6 | *
7 | * FFmpeg is free software; you can redistribute it and/or
8 | * modify it under the terms of the GNU Lesser General Public
9 | * License as published by the Free Software Foundation; either
10 | * version 2.1 of the License, or (at your option) any later version.
11 | *
12 | * FFmpeg is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 | * Lesser General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU Lesser General Public
18 | * License along with FFmpeg; if not, write to the Free Software
19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 | */
21 |
22 | #ifndef AVUTIL_BLOWFISH_H
23 | #define AVUTIL_BLOWFISH_H
24 |
25 | #include
26 |
27 | /**
28 | * @defgroup lavu_blowfish Blowfish
29 | * @ingroup lavu_crypto
30 | * @{
31 | */
32 |
33 | #define AV_BF_ROUNDS 16
34 |
35 | typedef struct AVBlowfish {
36 | uint32_t p[AV_BF_ROUNDS + 2];
37 | uint32_t s[4][256];
38 | } AVBlowfish;
39 |
40 | /**
41 | * Allocate an AVBlowfish context.
42 | */
43 | AVBlowfish *av_blowfish_alloc(void);
44 |
45 | /**
46 | * Initialize an AVBlowfish context.
47 | *
48 | * @param ctx an AVBlowfish context
49 | * @param key a key
50 | * @param key_len length of the key
51 | */
52 | void av_blowfish_init(struct AVBlowfish *ctx, const uint8_t *key, int key_len);
53 |
54 | /**
55 | * Encrypt or decrypt a buffer using a previously initialized context.
56 | *
57 | * @param ctx an AVBlowfish context
58 | * @param xl left four bytes halves of input to be encrypted
59 | * @param xr right four bytes halves of input to be encrypted
60 | * @param decrypt 0 for encryption, 1 for decryption
61 | */
62 | void av_blowfish_crypt_ecb(struct AVBlowfish *ctx, uint32_t *xl, uint32_t *xr,
63 | int decrypt);
64 |
65 | /**
66 | * Encrypt or decrypt a buffer using a previously initialized context.
67 | *
68 | * @param ctx an AVBlowfish context
69 | * @param dst destination array, can be equal to src
70 | * @param src source array, can be equal to dst
71 | * @param count number of 8 byte blocks
72 | * @param iv initialization vector for CBC mode, if NULL ECB will be used
73 | * @param decrypt 0 for encryption, 1 for decryption
74 | */
75 | void av_blowfish_crypt(struct AVBlowfish *ctx, uint8_t *dst, const uint8_t *src,
76 | int count, uint8_t *iv, int decrypt);
77 |
78 | /**
79 | * @}
80 | */
81 |
82 | #endif /* AVUTIL_BLOWFISH_H */
83 |
--------------------------------------------------------------------------------
/app/src/main/cpp/ffmpeg/include/libavutil/md5.h:
--------------------------------------------------------------------------------
1 | /*
2 | * copyright (c) 2006 Michael Niedermayer
3 | *
4 | * This file is part of FFmpeg.
5 | *
6 | * FFmpeg is free software; you can redistribute it and/or
7 | * modify it under the terms of the GNU Lesser General Public
8 | * License as published by the Free Software Foundation; either
9 | * version 2.1 of the License, or (at your option) any later version.
10 | *
11 | * FFmpeg is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 | * Lesser General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU Lesser General Public
17 | * License along with FFmpeg; if not, write to the Free Software
18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 | */
20 |
21 | /**
22 | * @file
23 | * @ingroup lavu_md5
24 | * Public header for MD5 hash function implementation.
25 | */
26 |
27 | #ifndef AVUTIL_MD5_H
28 | #define AVUTIL_MD5_H
29 |
30 | #include
31 | #include
32 |
33 | #include "attributes.h"
34 | #include "version.h"
35 |
36 | /**
37 | * @defgroup lavu_md5 MD5
38 | * @ingroup lavu_hash
39 | * MD5 hash function implementation.
40 | *
41 | * @{
42 | */
43 |
44 | extern const int av_md5_size;
45 |
46 | struct AVMD5;
47 |
48 | /**
49 | * Allocate an AVMD5 context.
50 | */
51 | struct AVMD5 *av_md5_alloc(void);
52 |
53 | /**
54 | * Initialize MD5 hashing.
55 | *
56 | * @param ctx pointer to the function context (of size av_md5_size)
57 | */
58 | void av_md5_init(struct AVMD5 *ctx);
59 |
60 | /**
61 | * Update hash value.
62 | *
63 | * @param ctx hash function context
64 | * @param src input data to update hash with
65 | * @param len input data length
66 | */
67 | #if FF_API_CRYPTO_SIZE_T
68 | void av_md5_update(struct AVMD5 *ctx, const uint8_t *src, int len);
69 | #else
70 | void av_md5_update(struct AVMD5 *ctx, const uint8_t *src, size_t len);
71 | #endif
72 |
73 | /**
74 | * Finish hashing and output digest value.
75 | *
76 | * @param ctx hash function context
77 | * @param dst buffer where output digest value is stored
78 | */
79 | void av_md5_final(struct AVMD5 *ctx, uint8_t *dst);
80 |
81 | /**
82 | * Hash an array of data.
83 | *
84 | * @param dst The output buffer to write the digest into
85 | * @param src The data to hash
86 | * @param len The length of the data, in bytes
87 | */
88 | #if FF_API_CRYPTO_SIZE_T
89 | void av_md5_sum(uint8_t *dst, const uint8_t *src, const int len);
90 | #else
91 | void av_md5_sum(uint8_t *dst, const uint8_t *src, size_t len);
92 | #endif
93 |
94 | /**
95 | * @}
96 | */
97 |
98 | #endif /* AVUTIL_MD5_H */
99 |
--------------------------------------------------------------------------------
/app/src/main/java/com/cxp/learningvideo/MultiOpenGLPlayerActivity.kt:
--------------------------------------------------------------------------------
1 | package com.cxp.learningvideo
2 |
3 | import android.os.Bundle
4 | import android.os.Environment
5 | import android.os.Handler
6 | import android.support.v7.app.AppCompatActivity
7 | import android.view.Surface
8 | import com.cxp.learningvideo.media.decoder.AudioDecoder
9 | import com.cxp.learningvideo.media.decoder.VideoDecoder
10 | import com.cxp.learningvideo.opengl.SimpleRender
11 | import com.cxp.learningvideo.opengl.drawer.VideoDrawer
12 | import kotlinx.android.synthetic.main.activity_opengl_player.*
13 | import java.util.concurrent.Executors
14 |
15 |
16 | /**
17 | * 使用OpenGL渲染多个视频画面的播放器
18 | *
19 | * @author Chen Xiaoping (562818444@qq.com)
20 | * @since LearningVideo
21 | * @version LearningVideo
22 | * @Datetime 2019-10-26 21:07
23 | *
24 | */
25 | class MultiOpenGLPlayerActivity: AppCompatActivity() {
26 | private val path = Environment.getExternalStorageDirectory().absolutePath + "/mvtest_2.mp4"
27 | private val path2 = Environment.getExternalStorageDirectory().absolutePath + "/mvtest.mp4"
28 |
29 | private val render = SimpleRender()
30 |
31 | private val threadPool = Executors.newFixedThreadPool(10)
32 |
33 | override fun onCreate(savedInstanceState: Bundle?) {
34 | super.onCreate(savedInstanceState)
35 | setContentView(R.layout.activity_opengl_player)
36 | initFirstVideo()
37 | initSecondVideo()
38 | initRender()
39 | }
40 |
41 | private fun initFirstVideo() {
42 | val drawer = VideoDrawer()
43 | drawer.setVideoSize(1920, 1080)
44 | drawer.getSurfaceTexture {
45 | initPlayer(path, Surface(it), true)
46 | }
47 | render.addDrawer(drawer)
48 | }
49 |
50 | private fun initSecondVideo() {
51 | val drawer = VideoDrawer()
52 | drawer.setAlpha(0.5f)
53 | drawer.setVideoSize(1920, 1080)
54 | drawer.getSurfaceTexture {
55 | initPlayer(path2, Surface(it), false)
56 | }
57 | render.addDrawer(drawer)
58 | gl_surface.addDrawer(drawer)
59 |
60 | Handler().postDelayed({
61 | drawer.scale(0.5f, 0.5f)
62 | }, 1000)
63 | }
64 |
65 | private fun initPlayer(path: String, sf: Surface, withSound: Boolean) {
66 | val videoDecoder = VideoDecoder(path, null, sf)
67 | threadPool.execute(videoDecoder)
68 | videoDecoder.goOn()
69 |
70 | if (withSound) {
71 | val audioDecoder = AudioDecoder(path)
72 | threadPool.execute(audioDecoder)
73 | audioDecoder.goOn()
74 | }
75 | }
76 |
77 | private fun initRender() {
78 | gl_surface.setEGLContextClientVersion(2)
79 | gl_surface.setRenderer(render)
80 | }
81 |
82 | }
--------------------------------------------------------------------------------
/app/src/main/cpp/ffmpeg/include/libavcodec/dxva2.h:
--------------------------------------------------------------------------------
1 | /*
2 | * DXVA2 HW acceleration
3 | *
4 | * copyright (c) 2009 Laurent Aimar
5 | *
6 | * This file is part of FFmpeg.
7 | *
8 | * FFmpeg is free software; you can redistribute it and/or
9 | * modify it under the terms of the GNU Lesser General Public
10 | * License as published by the Free Software Foundation; either
11 | * version 2.1 of the License, or (at your option) any later version.
12 | *
13 | * FFmpeg is distributed in the hope that it will be useful,
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 | * Lesser General Public License for more details.
17 | *
18 | * You should have received a copy of the GNU Lesser General Public
19 | * License along with FFmpeg; if not, write to the Free Software
20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 | */
22 |
23 | #ifndef AVCODEC_DXVA2_H
24 | #define AVCODEC_DXVA2_H
25 |
26 | /**
27 | * @file
28 | * @ingroup lavc_codec_hwaccel_dxva2
29 | * Public libavcodec DXVA2 header.
30 | */
31 |
32 | #if !defined(_WIN32_WINNT) || _WIN32_WINNT < 0x0602
33 | #undef _WIN32_WINNT
34 | #define _WIN32_WINNT 0x0602
35 | #endif
36 |
37 | #include
38 | #include
39 | #include
40 |
41 | /**
42 | * @defgroup lavc_codec_hwaccel_dxva2 DXVA2
43 | * @ingroup lavc_codec_hwaccel
44 | *
45 | * @{
46 | */
47 |
48 | #define FF_DXVA2_WORKAROUND_SCALING_LIST_ZIGZAG 1 ///< Work around for DXVA2 and old UVD/UVD+ ATI video cards
49 | #define FF_DXVA2_WORKAROUND_INTEL_CLEARVIDEO 2 ///< Work around for DXVA2 and old Intel GPUs with ClearVideo interface
50 |
51 | /**
52 | * This structure is used to provides the necessary configurations and data
53 | * to the DXVA2 FFmpeg HWAccel implementation.
54 | *
55 | * The application must make it available as AVCodecContext.hwaccel_context.
56 | */
57 | struct dxva_context {
58 | /**
59 | * DXVA2 decoder object
60 | */
61 | IDirectXVideoDecoder *decoder;
62 |
63 | /**
64 | * DXVA2 configuration used to create the decoder
65 | */
66 | const DXVA2_ConfigPictureDecode *cfg;
67 |
68 | /**
69 | * The number of surface in the surface array
70 | */
71 | unsigned surface_count;
72 |
73 | /**
74 | * The array of Direct3D surfaces used to create the decoder
75 | */
76 | LPDIRECT3DSURFACE9 *surface;
77 |
78 | /**
79 | * A bit field configuring the workarounds needed for using the decoder
80 | */
81 | uint64_t workaround;
82 |
83 | /**
84 | * Private to the FFmpeg AVHWAccel implementation
85 | */
86 | unsigned report_id;
87 | };
88 |
89 | /**
90 | * @}
91 | */
92 |
93 | #endif /* AVCODEC_DXVA2_H */
94 |
--------------------------------------------------------------------------------
/app/src/main/java/com/cxp/learningvideo/media/decoder/VideoDecoder.kt:
--------------------------------------------------------------------------------
1 | package com.cxp.learningvideo.media.decoder
2 |
3 | import android.media.MediaCodec
4 | import android.media.MediaFormat
5 | import android.util.Log
6 | import android.view.Surface
7 | import android.view.SurfaceHolder
8 | import android.view.SurfaceView
9 | import com.cxp.learningvideo.media.BaseDecoder
10 | import com.cxp.learningvideo.media.IExtractor
11 | import com.cxp.learningvideo.media.extractor.VideoExtractor
12 | import java.nio.ByteBuffer
13 |
14 |
15 | /**
16 | * 视频解码器
17 | *
18 | * @author Chen Xiaoping (562818444@qq.com)
19 | * @since LearningVideo
20 | * @version LearningVideo
21 | * @Datetime 2019-09-03 10:52
22 | *
23 | */
24 | class VideoDecoder(path: String, sfv: SurfaceView?, surface: Surface?): BaseDecoder(path) {
25 | private val TAG = "VideoDecoder"
26 |
27 | private val mSurfaceView = sfv
28 | private var mSurface = surface
29 |
30 | override fun check(): Boolean {
31 | if (mSurfaceView == null && mSurface == null) {
32 | Log.w(TAG, "SurfaceView和Surface都为空,至少需要一个不为空")
33 | mStateListener?.decoderError(this, "显示器为空")
34 | return false
35 | }
36 | return true
37 | }
38 |
39 | override fun initExtractor(path: String): IExtractor {
40 | return VideoExtractor(path)
41 | }
42 |
43 | override fun initSpecParams(format: MediaFormat) {
44 | }
45 |
46 | override fun configCodec(codec: MediaCodec, format: MediaFormat): Boolean {
47 | if (mSurface != null) {
48 | codec.configure(format, mSurface , null, 0)
49 | notifyDecode()
50 | } else if (mSurfaceView?.holder?.surface != null) {
51 | mSurface = mSurfaceView?.holder?.surface
52 | configCodec(codec, format)
53 | } else {
54 | mSurfaceView?.holder?.addCallback(object : SurfaceHolder.Callback2 {
55 | override fun surfaceRedrawNeeded(holder: SurfaceHolder) {
56 | }
57 |
58 | override fun surfaceChanged(holder: SurfaceHolder, format: Int, width: Int, height: Int) {
59 | }
60 |
61 | override fun surfaceDestroyed(holder: SurfaceHolder) {
62 | }
63 |
64 | override fun surfaceCreated(holder: SurfaceHolder) {
65 | mSurface = holder.surface
66 | configCodec(codec, format)
67 | }
68 | })
69 |
70 | return false
71 | }
72 | return true
73 | }
74 |
75 | override fun initRender(): Boolean {
76 | return true
77 | }
78 |
79 | override fun render(outputBuffer: ByteBuffer,
80 | bufferInfo: MediaCodec.BufferInfo) {
81 | }
82 |
83 | override fun doneDecode() {
84 | }
85 | }
--------------------------------------------------------------------------------
/app/src/main/cpp/ffmpeg/include/libavutil/lfg.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Lagged Fibonacci PRNG
3 | * Copyright (c) 2008 Michael Niedermayer
4 | *
5 | * This file is part of FFmpeg.
6 | *
7 | * FFmpeg is free software; you can redistribute it and/or
8 | * modify it under the terms of the GNU Lesser General Public
9 | * License as published by the Free Software Foundation; either
10 | * version 2.1 of the License, or (at your option) any later version.
11 | *
12 | * FFmpeg is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 | * Lesser General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU Lesser General Public
18 | * License along with FFmpeg; if not, write to the Free Software
19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 | */
21 |
22 | #ifndef AVUTIL_LFG_H
23 | #define AVUTIL_LFG_H
24 |
25 | #include
26 |
27 | /**
28 | * Context structure for the Lagged Fibonacci PRNG.
29 | * The exact layout, types and content of this struct may change and should
30 | * not be accessed directly. Only its sizeof() is guranteed to stay the same
31 | * to allow easy instanciation.
32 | */
33 | typedef struct AVLFG {
34 | unsigned int state[64];
35 | int index;
36 | } AVLFG;
37 |
38 | void av_lfg_init(AVLFG *c, unsigned int seed);
39 |
40 | /**
41 | * Seed the state of the ALFG using binary data.
42 | *
43 | * Return value: 0 on success, negative value (AVERROR) on failure.
44 | */
45 | int av_lfg_init_from_data(AVLFG *c, const uint8_t *data, unsigned int length);
46 |
47 | /**
48 | * Get the next random unsigned 32-bit number using an ALFG.
49 | *
50 | * Please also consider a simple LCG like state= state*1664525+1013904223,
51 | * it may be good enough and faster for your specific use case.
52 | */
53 | static inline unsigned int av_lfg_get(AVLFG *c){
54 | unsigned a = c->state[c->index & 63] = c->state[(c->index-24) & 63] + c->state[(c->index-55) & 63];
55 | c->index += 1U;
56 | return a;
57 | }
58 |
59 | /**
60 | * Get the next random unsigned 32-bit number using a MLFG.
61 | *
62 | * Please also consider av_lfg_get() above, it is faster.
63 | */
64 | static inline unsigned int av_mlfg_get(AVLFG *c){
65 | unsigned int a= c->state[(c->index-55) & 63];
66 | unsigned int b= c->state[(c->index-24) & 63];
67 | a = c->state[c->index & 63] = 2*a*b+a+b;
68 | c->index += 1U;
69 | return a;
70 | }
71 |
72 | /**
73 | * Get the next two numbers generated by a Box-Muller Gaussian
74 | * generator using the random numbers issued by lfg.
75 | *
76 | * @param out array where the two generated numbers are placed
77 | */
78 | void av_bmg_get(AVLFG *lfg, double out[2]);
79 |
80 | #endif /* AVUTIL_LFG_H */
81 |
--------------------------------------------------------------------------------
/app/src/main/cpp/ffmpeg/include/libavutil/cast5.h:
--------------------------------------------------------------------------------
1 | /*
2 | * An implementation of the CAST128 algorithm as mentioned in RFC2144
3 | * Copyright (c) 2014 Supraja Meedinti
4 | *
5 | * This file is part of FFmpeg.
6 | *
7 | * FFmpeg is free software; you can redistribute it and/or
8 | * modify it under the terms of the GNU Lesser General Public
9 | * License as published by the Free Software Foundation; either
10 | * version 2.1 of the License, or (at your option) any later version.
11 | *
12 | * FFmpeg is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 | * Lesser General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU Lesser General Public
18 | * License along with FFmpeg; if not, write to the Free Software
19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 | */
21 |
22 | #ifndef AVUTIL_CAST5_H
23 | #define AVUTIL_CAST5_H
24 |
25 | #include
26 |
27 |
28 | /**
29 | * @file
30 | * @brief Public header for libavutil CAST5 algorithm
31 | * @defgroup lavu_cast5 CAST5
32 | * @ingroup lavu_crypto
33 | * @{
34 | */
35 |
36 | extern const int av_cast5_size;
37 |
38 | struct AVCAST5;
39 |
40 | /**
41 | * Allocate an AVCAST5 context
42 | * To free the struct: av_free(ptr)
43 | */
44 | struct AVCAST5 *av_cast5_alloc(void);
45 | /**
46 | * Initialize an AVCAST5 context.
47 | *
48 | * @param ctx an AVCAST5 context
49 | * @param key a key of 5,6,...16 bytes used for encryption/decryption
50 | * @param key_bits number of keybits: possible are 40,48,...,128
51 | * @return 0 on success, less than 0 on failure
52 | */
53 | int av_cast5_init(struct AVCAST5 *ctx, const uint8_t *key, int key_bits);
54 |
55 | /**
56 | * Encrypt or decrypt a buffer using a previously initialized context, ECB mode only
57 | *
58 | * @param ctx an AVCAST5 context
59 | * @param dst destination array, can be equal to src
60 | * @param src source array, can be equal to dst
61 | * @param count number of 8 byte blocks
62 | * @param decrypt 0 for encryption, 1 for decryption
63 | */
64 | void av_cast5_crypt(struct AVCAST5 *ctx, uint8_t *dst, const uint8_t *src, int count, int decrypt);
65 |
66 | /**
67 | * Encrypt or decrypt a buffer using a previously initialized context
68 | *
69 | * @param ctx an AVCAST5 context
70 | * @param dst destination array, can be equal to src
71 | * @param src source array, can be equal to dst
72 | * @param count number of 8 byte blocks
73 | * @param iv initialization vector for CBC mode, NULL for ECB mode
74 | * @param decrypt 0 for encryption, 1 for decryption
75 | */
76 | void av_cast5_crypt2(struct AVCAST5 *ctx, uint8_t *dst, const uint8_t *src, int count, uint8_t *iv, int decrypt);
77 | /**
78 | * @}
79 | */
80 | #endif /* AVUTIL_CAST5_H */
81 |
--------------------------------------------------------------------------------
/app/src/main/cpp/ffmpeg/include/libavutil/sha.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2007 Michael Niedermayer
3 | *
4 | * This file is part of FFmpeg.
5 | *
6 | * FFmpeg is free software; you can redistribute it and/or
7 | * modify it under the terms of the GNU Lesser General Public
8 | * License as published by the Free Software Foundation; either
9 | * version 2.1 of the License, or (at your option) any later version.
10 | *
11 | * FFmpeg is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 | * Lesser General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU Lesser General Public
17 | * License along with FFmpeg; if not, write to the Free Software
18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 | */
20 |
21 | /**
22 | * @file
23 | * @ingroup lavu_sha
24 | * Public header for SHA-1 & SHA-256 hash function implementations.
25 | */
26 |
27 | #ifndef AVUTIL_SHA_H
28 | #define AVUTIL_SHA_H
29 |
30 | #include
31 | #include
32 |
33 | #include "attributes.h"
34 | #include "version.h"
35 |
36 | /**
37 | * @defgroup lavu_sha SHA
38 | * @ingroup lavu_hash
39 | * SHA-1 and SHA-256 (Secure Hash Algorithm) hash function implementations.
40 | *
41 | * This module supports the following SHA hash functions:
42 | *
43 | * - SHA-1: 160 bits
44 | * - SHA-224: 224 bits, as a variant of SHA-2
45 | * - SHA-256: 256 bits, as a variant of SHA-2
46 | *
47 | * @see For SHA-384, SHA-512, and variants thereof, see @ref lavu_sha512.
48 | *
49 | * @{
50 | */
51 |
52 | extern const int av_sha_size;
53 |
54 | struct AVSHA;
55 |
56 | /**
57 | * Allocate an AVSHA context.
58 | */
59 | struct AVSHA *av_sha_alloc(void);
60 |
61 | /**
62 | * Initialize SHA-1 or SHA-2 hashing.
63 | *
64 | * @param context pointer to the function context (of size av_sha_size)
65 | * @param bits number of bits in digest (SHA-1 - 160 bits, SHA-2 224 or 256 bits)
66 | * @return zero if initialization succeeded, -1 otherwise
67 | */
68 | int av_sha_init(struct AVSHA* context, int bits);
69 |
70 | /**
71 | * Update hash value.
72 | *
73 | * @param ctx hash function context
74 | * @param data input data to update hash with
75 | * @param len input data length
76 | */
77 | #if FF_API_CRYPTO_SIZE_T
78 | void av_sha_update(struct AVSHA *ctx, const uint8_t *data, unsigned int len);
79 | #else
80 | void av_sha_update(struct AVSHA *ctx, const uint8_t *data, size_t len);
81 | #endif
82 |
83 | /**
84 | * Finish hashing and output digest value.
85 | *
86 | * @param context hash function context
87 | * @param digest buffer where output digest value is stored
88 | */
89 | void av_sha_final(struct AVSHA* context, uint8_t *digest);
90 |
91 | /**
92 | * @}
93 | */
94 |
95 | #endif /* AVUTIL_SHA_H */
96 |
--------------------------------------------------------------------------------
/app/src/main/cpp/ffmpeg/include/libavcodec/avdct.h:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of FFmpeg.
3 | *
4 | * FFmpeg is free software; you can redistribute it and/or
5 | * modify it under the terms of the GNU Lesser General Public
6 | * License as published by the Free Software Foundation; either
7 | * version 2.1 of the License, or (at your option) any later version.
8 | *
9 | * FFmpeg is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 | * Lesser General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU Lesser General Public
15 | * License along with FFmpeg; if not, write to the Free Software
16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 | */
18 |
19 | #ifndef AVCODEC_AVDCT_H
20 | #define AVCODEC_AVDCT_H
21 |
22 | #include "libavutil/opt.h"
23 |
24 | /**
25 | * AVDCT context.
26 | * @note function pointers can be NULL if the specific features have been
27 | * disabled at build time.
28 | */
29 | typedef struct AVDCT {
30 | const AVClass *av_class;
31 |
32 | void (*idct)(int16_t *block /* align 16 */);
33 |
34 | /**
35 | * IDCT input permutation.
36 | * Several optimized IDCTs need a permutated input (relative to the
37 | * normal order of the reference IDCT).
38 | * This permutation must be performed before the idct_put/add.
39 | * Note, normally this can be merged with the zigzag/alternate scan
40 | * An example to avoid confusion:
41 | * - (->decode coeffs -> zigzag reorder -> dequant -> reference IDCT -> ...)
42 | * - (x -> reference DCT -> reference IDCT -> x)
43 | * - (x -> reference DCT -> simple_mmx_perm = idct_permutation
44 | * -> simple_idct_mmx -> x)
45 | * - (-> decode coeffs -> zigzag reorder -> simple_mmx_perm -> dequant
46 | * -> simple_idct_mmx -> ...)
47 | */
48 | uint8_t idct_permutation[64];
49 |
50 | void (*fdct)(int16_t *block /* align 16 */);
51 |
52 |
53 | /**
54 | * DCT algorithm.
55 | * must use AVOptions to set this field.
56 | */
57 | int dct_algo;
58 |
59 | /**
60 | * IDCT algorithm.
61 | * must use AVOptions to set this field.
62 | */
63 | int idct_algo;
64 |
65 | void (*get_pixels)(int16_t *block /* align 16 */,
66 | const uint8_t *pixels /* align 8 */,
67 | ptrdiff_t line_size);
68 |
69 | int bits_per_sample;
70 | } AVDCT;
71 |
72 | /**
73 | * Allocates a AVDCT context.
74 | * This needs to be initialized with avcodec_dct_init() after optionally
75 | * configuring it with AVOptions.
76 | *
77 | * To free it use av_free()
78 | */
79 | AVDCT *avcodec_dct_alloc(void);
80 | int avcodec_dct_init(AVDCT *);
81 |
82 | const AVClass *avcodec_dct_get_class(void);
83 |
84 | #endif /* AVCODEC_AVDCT_H */
85 |
--------------------------------------------------------------------------------
/app/src/main/cpp/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | cmake_minimum_required(VERSION 3.4.1)
2 |
3 | # 设置生成的so动态库最后输出的路径
4 | # set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/../jniLibs/${ANDROID_ABI})
5 |
6 | # 支持C++11标准和GNU扩展特性
7 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++11")
8 |
9 | # 1. 定义so库和头文件所在目录,方面后面使用
10 | set(ffmpeg_lib_dir ${CMAKE_SOURCE_DIR}/../jniLibs/${ANDROID_ABI})
11 | set(ffmpeg_head_dir ${CMAKE_SOURCE_DIR}/ffmpeg)
12 |
13 | # 2. 添加头文件目录
14 | include_directories(${ffmpeg_head_dir}/include)
15 |
16 | # 3. 添加ffmpeg相关的so库
17 | add_library( avutil
18 | SHARED
19 | IMPORTED )
20 | set_target_properties( avutil
21 | PROPERTIES IMPORTED_LOCATION
22 | ${ffmpeg_lib_dir}/libavutil.so )
23 |
24 | add_library( swresample
25 | SHARED
26 | IMPORTED )
27 | set_target_properties( swresample
28 | PROPERTIES IMPORTED_LOCATION
29 | ${ffmpeg_lib_dir}/libswresample.so )
30 |
31 | add_library( avcodec
32 | SHARED
33 | IMPORTED )
34 | set_target_properties( avcodec
35 | PROPERTIES IMPORTED_LOCATION
36 | ${ffmpeg_lib_dir}/libavcodec.so )
37 |
38 | add_library( avfilter
39 | SHARED
40 | IMPORTED)
41 | set_target_properties( avfilter
42 | PROPERTIES IMPORTED_LOCATION
43 | ${ffmpeg_lib_dir}/libavfilter.so )
44 |
45 | add_library( swscale
46 | SHARED
47 | IMPORTED)
48 | set_target_properties( swscale
49 | PROPERTIES IMPORTED_LOCATION
50 | ${ffmpeg_lib_dir}/libswscale.so )
51 |
52 | add_library( avformat
53 | SHARED
54 | IMPORTED)
55 | set_target_properties( avformat
56 | PROPERTIES IMPORTED_LOCATION
57 | ${ffmpeg_lib_dir}/libavformat.so )
58 |
59 | add_library( avdevice
60 | SHARED
61 | IMPORTED)
62 | set_target_properties( avdevice
63 | PROPERTIES IMPORTED_LOCATION
64 | ${ffmpeg_lib_dir}/libavdevice.so )
65 |
66 | # 查找代码中使用到的系统库
67 | find_library( # Sets the name of the path variable.
68 | log-lib
69 |
70 | # Specifies the name of the NDK library that
71 | # you want CMake to locate.
72 | log )
73 |
74 | # 配置目标so库编译信息
75 | add_library( # Sets the name of the library.
76 | native-lib
77 |
78 | # Sets the library as a shared library.
79 | SHARED
80 |
81 | # Provides a relative path to your source file(s).
82 | native-lib.cpp
83 | )
84 |
85 | # 指定编译目标库时,cmake要链接的库
86 | target_link_libraries(
87 |
88 | # 指定目标库,native-lib 是在上面 add_library 中配置的目标库
89 | native-lib
90 |
91 | # 4. 连接 FFmpeg 相关的库
92 | avutil
93 | swresample
94 | avcodec
95 | avfilter
96 | swscale
97 | avformat
98 | avdevice
99 |
100 | # Links the target library to the log library
101 | # included in the NDK.
102 | ${log-lib} )
--------------------------------------------------------------------------------
/app/src/main/cpp/ffmpeg/include/libavutil/timestamp.h:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of FFmpeg.
3 | *
4 | * FFmpeg is free software; you can redistribute it and/or
5 | * modify it under the terms of the GNU Lesser General Public
6 | * License as published by the Free Software Foundation; either
7 | * version 2.1 of the License, or (at your option) any later version.
8 | *
9 | * FFmpeg is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 | * Lesser General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU Lesser General Public
15 | * License along with FFmpeg; if not, write to the Free Software
16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 | */
18 |
19 | /**
20 | * @file
21 | * timestamp utils, mostly useful for debugging/logging purposes
22 | */
23 |
24 | #ifndef AVUTIL_TIMESTAMP_H
25 | #define AVUTIL_TIMESTAMP_H
26 |
27 | #include "common.h"
28 |
29 | #if defined(__cplusplus) && !defined(__STDC_FORMAT_MACROS) && !defined(PRId64)
30 | #error missing -D__STDC_FORMAT_MACROS / #define __STDC_FORMAT_MACROS
31 | #endif
32 |
33 | #define AV_TS_MAX_STRING_SIZE 32
34 |
35 | /**
36 | * Fill the provided buffer with a string containing a timestamp
37 | * representation.
38 | *
39 | * @param buf a buffer with size in bytes of at least AV_TS_MAX_STRING_SIZE
40 | * @param ts the timestamp to represent
41 | * @return the buffer in input
42 | */
43 | static inline char *av_ts_make_string(char *buf, int64_t ts)
44 | {
45 | if (ts == AV_NOPTS_VALUE) snprintf(buf, AV_TS_MAX_STRING_SIZE, "NOPTS");
46 | else snprintf(buf, AV_TS_MAX_STRING_SIZE, "%" PRId64, ts);
47 | return buf;
48 | }
49 |
50 | /**
51 | * Convenience macro, the return value should be used only directly in
52 | * function arguments but never stand-alone.
53 | */
54 | #define av_ts2str(ts) av_ts_make_string((char[AV_TS_MAX_STRING_SIZE]){0}, ts)
55 |
56 | /**
57 | * Fill the provided buffer with a string containing a timestamp time
58 | * representation.
59 | *
60 | * @param buf a buffer with size in bytes of at least AV_TS_MAX_STRING_SIZE
61 | * @param ts the timestamp to represent
62 | * @param tb the timebase of the timestamp
63 | * @return the buffer in input
64 | */
65 | static inline char *av_ts_make_time_string(char *buf, int64_t ts, AVRational *tb)
66 | {
67 | if (ts == AV_NOPTS_VALUE) snprintf(buf, AV_TS_MAX_STRING_SIZE, "NOPTS");
68 | else snprintf(buf, AV_TS_MAX_STRING_SIZE, "%.6g", av_q2d(*tb) * ts);
69 | return buf;
70 | }
71 |
72 | /**
73 | * Convenience macro, the return value should be used only directly in
74 | * function arguments but never stand-alone.
75 | */
76 | #define av_ts2timestr(ts, tb) av_ts_make_time_string((char[AV_TS_MAX_STRING_SIZE]){0}, ts, tb)
77 |
78 | #endif /* AVUTIL_TIMESTAMP_H */
79 |
--------------------------------------------------------------------------------
/app/src/main/cpp/ffmpeg/include/libavutil/sha512.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2007 Michael Niedermayer
3 | * Copyright (C) 2013 James Almer
4 | *
5 | * This file is part of FFmpeg.
6 | *
7 | * FFmpeg is free software; you can redistribute it and/or
8 | * modify it under the terms of the GNU Lesser General Public
9 | * License as published by the Free Software Foundation; either
10 | * version 2.1 of the License, or (at your option) any later version.
11 | *
12 | * FFmpeg is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 | * Lesser General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU Lesser General Public
18 | * License along with FFmpeg; if not, write to the Free Software
19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 | */
21 |
22 | /**
23 | * @file
24 | * @ingroup lavu_sha512
25 | * Public header for SHA-512 implementation.
26 | */
27 |
28 | #ifndef AVUTIL_SHA512_H
29 | #define AVUTIL_SHA512_H
30 |
31 | #include
32 | #include
33 |
34 | #include "attributes.h"
35 | #include "version.h"
36 |
37 | /**
38 | * @defgroup lavu_sha512 SHA-512
39 | * @ingroup lavu_hash
40 | * SHA-512 (Secure Hash Algorithm) hash function implementations.
41 | *
42 | * This module supports the following SHA-2 hash functions:
43 | *
44 | * - SHA-512/224: 224 bits
45 | * - SHA-512/256: 256 bits
46 | * - SHA-384: 384 bits
47 | * - SHA-512: 512 bits
48 | *
49 | * @see For SHA-1, SHA-256, and variants thereof, see @ref lavu_sha.
50 | *
51 | * @{
52 | */
53 |
54 | extern const int av_sha512_size;
55 |
56 | struct AVSHA512;
57 |
58 | /**
59 | * Allocate an AVSHA512 context.
60 | */
61 | struct AVSHA512 *av_sha512_alloc(void);
62 |
63 | /**
64 | * Initialize SHA-2 512 hashing.
65 | *
66 | * @param context pointer to the function context (of size av_sha512_size)
67 | * @param bits number of bits in digest (224, 256, 384 or 512 bits)
68 | * @return zero if initialization succeeded, -1 otherwise
69 | */
70 | int av_sha512_init(struct AVSHA512* context, int bits);
71 |
72 | /**
73 | * Update hash value.
74 | *
75 | * @param context hash function context
76 | * @param data input data to update hash with
77 | * @param len input data length
78 | */
79 | #if FF_API_CRYPTO_SIZE_T
80 | void av_sha512_update(struct AVSHA512* context, const uint8_t* data, unsigned int len);
81 | #else
82 | void av_sha512_update(struct AVSHA512* context, const uint8_t* data, size_t len);
83 | #endif
84 |
85 | /**
86 | * Finish hashing and output digest value.
87 | *
88 | * @param context hash function context
89 | * @param digest buffer where output digest value is stored
90 | */
91 | void av_sha512_final(struct AVSHA512* context, uint8_t *digest);
92 |
93 | /**
94 | * @}
95 | */
96 |
97 | #endif /* AVUTIL_SHA512_H */
98 |
--------------------------------------------------------------------------------
/app/src/main/cpp/ffmpeg/include/libavutil/file.h:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of FFmpeg.
3 | *
4 | * FFmpeg is free software; you can redistribute it and/or
5 | * modify it under the terms of the GNU Lesser General Public
6 | * License as published by the Free Software Foundation; either
7 | * version 2.1 of the License, or (at your option) any later version.
8 | *
9 | * FFmpeg is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 | * Lesser General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU Lesser General Public
15 | * License along with FFmpeg; if not, write to the Free Software
16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 | */
18 |
19 | #ifndef AVUTIL_FILE_H
20 | #define AVUTIL_FILE_H
21 |
22 | #include
23 |
24 | #include "avutil.h"
25 |
26 | /**
27 | * @file
28 | * Misc file utilities.
29 | */
30 |
31 | /**
32 | * Read the file with name filename, and put its content in a newly
33 | * allocated buffer or map it with mmap() when available.
34 | * In case of success set *bufptr to the read or mmapped buffer, and
35 | * *size to the size in bytes of the buffer in *bufptr.
36 | * Unlike mmap this function succeeds with zero sized files, in this
37 | * case *bufptr will be set to NULL and *size will be set to 0.
38 | * The returned buffer must be released with av_file_unmap().
39 | *
40 | * @param log_offset loglevel offset used for logging
41 | * @param log_ctx context used for logging
42 | * @return a non negative number in case of success, a negative value
43 | * corresponding to an AVERROR error code in case of failure
44 | */
45 | av_warn_unused_result
46 | int av_file_map(const char *filename, uint8_t **bufptr, size_t *size,
47 | int log_offset, void *log_ctx);
48 |
49 | /**
50 | * Unmap or free the buffer bufptr created by av_file_map().
51 | *
52 | * @param size size in bytes of bufptr, must be the same as returned
53 | * by av_file_map()
54 | */
55 | void av_file_unmap(uint8_t *bufptr, size_t size);
56 |
57 | /**
58 | * Wrapper to work around the lack of mkstemp() on mingw.
59 | * Also, tries to create file in /tmp first, if possible.
60 | * *prefix can be a character constant; *filename will be allocated internally.
61 | * @return file descriptor of opened file (or negative value corresponding to an
62 | * AVERROR code on error)
63 | * and opened file name in **filename.
64 | * @note On very old libcs it is necessary to set a secure umask before
65 | * calling this, av_tempfile() can't call umask itself as it is used in
66 | * libraries and could interfere with the calling application.
67 | * @deprecated as fd numbers cannot be passed saftely between libs on some platforms
68 | */
69 | int av_tempfile(const char *prefix, char **filename, int log_offset, void *log_ctx);
70 |
71 | #endif /* AVUTIL_FILE_H */
72 |
--------------------------------------------------------------------------------
/app/src/main/java/com/cxp/learningvideo/media/encoder/AudioEncoder.kt:
--------------------------------------------------------------------------------
1 | package com.cxp.learningvideo.media.encoder
2 |
3 | import android.media.MediaCodec
4 | import android.media.MediaCodecInfo
5 | import android.media.MediaFormat
6 | import android.os.Build
7 | import android.util.Log
8 | import com.cxp.learningvideo.media.muxer.MMuxer
9 | import java.nio.ByteBuffer
10 |
11 |
12 | /**
13 | * 视频编码器
14 | *
15 | * @author Chen Xiaoping (562818444@qq.com)
16 | * @since LearningVideo
17 | * @version LearningVideo
18 | *
19 | */
20 |
21 | // 编码采样率率
22 | val DEST_SAMPLE_RATE = 44100
23 | // 编码码率
24 | private val DEST_BIT_RATE = 128000
25 |
26 | class AudioEncoder(muxer: MMuxer): BaseEncoder(muxer) {
27 |
28 | private val TAG = "AudioEncoder"
29 |
30 | override fun encodeType(): String {
31 | return "audio/mp4a-latm"
32 | }
33 |
34 | override fun configEncoder(codec: MediaCodec) {
35 | val audioFormat = MediaFormat.createAudioFormat(encodeType(), DEST_SAMPLE_RATE, 2)
36 | audioFormat.setInteger(MediaFormat.KEY_BIT_RATE, DEST_BIT_RATE)
37 | audioFormat.setInteger(MediaFormat.KEY_MAX_INPUT_SIZE, 100*1024)
38 | try {
39 | configEncoderWithCQ(codec, audioFormat)
40 | } catch (e: Exception) {
41 | e.printStackTrace()
42 | try {
43 | configEncoderWithVBR(codec, audioFormat)
44 | } catch (e: Exception) {
45 | e.printStackTrace()
46 | Log.e(TAG, "配置音频编码器失败")
47 | }
48 | }
49 | }
50 |
51 | private fun configEncoderWithCQ(codec: MediaCodec, outputFormat: MediaFormat) {
52 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
53 | // 本部分手机不支持 BITRATE_MODE_CQ 模式,有可能会异常
54 | outputFormat.setInteger(
55 | MediaFormat.KEY_BITRATE_MODE,
56 | MediaCodecInfo.EncoderCapabilities.BITRATE_MODE_CQ
57 | )
58 | }
59 | codec.configure(outputFormat, null, null, MediaCodec.CONFIGURE_FLAG_ENCODE)
60 | }
61 |
62 | private fun configEncoderWithVBR(codec: MediaCodec, outputFormat: MediaFormat) {
63 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
64 | outputFormat.setInteger(
65 | MediaFormat.KEY_BITRATE_MODE,
66 | MediaCodecInfo.EncoderCapabilities.BITRATE_MODE_VBR
67 | )
68 | }
69 | codec.configure(outputFormat, null, null, MediaCodec.CONFIGURE_FLAG_ENCODE)
70 | }
71 |
72 | override fun addTrack(muxer: MMuxer, mediaFormat: MediaFormat) {
73 | muxer.addAudioTrack(mediaFormat)
74 | }
75 |
76 | override fun frameWaitTimeMs(): Long {
77 | return 5
78 | }
79 |
80 | override fun writeData(
81 | muxer: MMuxer,
82 | byteBuffer: ByteBuffer,
83 | bufferInfo: MediaCodec.BufferInfo
84 | ) {
85 | muxer.writeAudioData(byteBuffer, bufferInfo)
86 | }
87 |
88 | override fun release(muxer: MMuxer) {
89 | muxer.releaseAudioTrack()
90 | }
91 | }
--------------------------------------------------------------------------------
/app/src/main/cpp/ffmpeg/include/libavutil/tx.h:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of FFmpeg.
3 | *
4 | * FFmpeg is free software; you can redistribute it and/or
5 | * modify it under the terms of the GNU Lesser General Public
6 | * License as published by the Free Software Foundation; either
7 | * version 2.1 of the License, or (at your option) any later version.
8 | *
9 | * FFmpeg is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 | * Lesser General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU Lesser General Public
15 | * License along with FFmpeg; if not, write to the Free Software
16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 | */
18 |
19 | #ifndef AVUTIL_TX_H
20 | #define AVUTIL_TX_H
21 |
22 | #include
23 | #include
24 |
25 | typedef struct AVTXContext AVTXContext;
26 |
27 | typedef struct AVComplexFloat {
28 | float re, im;
29 | } AVComplexFloat;
30 |
31 | enum AVTXType {
32 | /**
33 | * Standard complex to complex FFT with sample data type AVComplexFloat.
34 | * Scaling currently unsupported
35 | */
36 | AV_TX_FLOAT_FFT = 0,
37 | /**
38 | * Standard MDCT with sample data type of float and a scale type of
39 | * float. Length is the frame size, not the window size (which is 2x frame)
40 | */
41 | AV_TX_FLOAT_MDCT = 1,
42 | };
43 |
44 | /**
45 | * Function pointer to a function to perform the transform.
46 | *
47 | * @note Using a different context than the one allocated during av_tx_init()
48 | * is not allowed.
49 | *
50 | * @param s the transform context
51 | * @param out the output array
52 | * @param in the input array
53 | * @param stride the input or output stride (depending on transform direction)
54 | * in bytes, currently implemented for all MDCT transforms
55 | */
56 | typedef void (*av_tx_fn)(AVTXContext *s, void *out, void *in, ptrdiff_t stride);
57 |
58 | /**
59 | * Initialize a transform context with the given configuration
60 | * Currently power of two lengths from 4 to 131072 are supported, along with
61 | * any length decomposable to a power of two and either 3, 5 or 15.
62 | *
63 | * @param ctx the context to allocate, will be NULL on error
64 | * @param tx pointer to the transform function pointer to set
65 | * @param type type the type of transform
66 | * @param inv whether to do an inverse or a forward transform
67 | * @param len the size of the transform in samples
68 | * @param scale pointer to the value to scale the output if supported by type
69 | * @param flags currently unused
70 | *
71 | * @return 0 on success, negative error code on failure
72 | */
73 | int av_tx_init(AVTXContext **ctx, av_tx_fn *tx, enum AVTXType type,
74 | int inv, int len, const void *scale, uint64_t flags);
75 |
76 | /**
77 | * Frees a context and sets ctx to NULL, does nothing when ctx == NULL
78 | */
79 | void av_tx_uninit(AVTXContext **ctx);
80 |
81 | #endif /* AVUTIL_TX_H */
82 |
--------------------------------------------------------------------------------
/app/src/main/cpp/ffmpeg/include/libavutil/xtea.h:
--------------------------------------------------------------------------------
1 | /*
2 | * A 32-bit implementation of the XTEA algorithm
3 | * Copyright (c) 2012 Samuel Pitoiset
4 | *
5 | * This file is part of FFmpeg.
6 | *
7 | * FFmpeg is free software; you can redistribute it and/or
8 | * modify it under the terms of the GNU Lesser General Public
9 | * License as published by the Free Software Foundation; either
10 | * version 2.1 of the License, or (at your option) any later version.
11 | *
12 | * FFmpeg is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 | * Lesser General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU Lesser General Public
18 | * License along with FFmpeg; if not, write to the Free Software
19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 | */
21 |
22 | #ifndef AVUTIL_XTEA_H
23 | #define AVUTIL_XTEA_H
24 |
25 | #include
26 |
27 | /**
28 | * @file
29 | * @brief Public header for libavutil XTEA algorithm
30 | * @defgroup lavu_xtea XTEA
31 | * @ingroup lavu_crypto
32 | * @{
33 | */
34 |
35 | typedef struct AVXTEA {
36 | uint32_t key[16];
37 | } AVXTEA;
38 |
39 | /**
40 | * Allocate an AVXTEA context.
41 | */
42 | AVXTEA *av_xtea_alloc(void);
43 |
44 | /**
45 | * Initialize an AVXTEA context.
46 | *
47 | * @param ctx an AVXTEA context
48 | * @param key a key of 16 bytes used for encryption/decryption,
49 | * interpreted as big endian 32 bit numbers
50 | */
51 | void av_xtea_init(struct AVXTEA *ctx, const uint8_t key[16]);
52 |
53 | /**
54 | * Initialize an AVXTEA context.
55 | *
56 | * @param ctx an AVXTEA context
57 | * @param key a key of 16 bytes used for encryption/decryption,
58 | * interpreted as little endian 32 bit numbers
59 | */
60 | void av_xtea_le_init(struct AVXTEA *ctx, const uint8_t key[16]);
61 |
62 | /**
63 | * Encrypt or decrypt a buffer using a previously initialized context,
64 | * in big endian format.
65 | *
66 | * @param ctx an AVXTEA context
67 | * @param dst destination array, can be equal to src
68 | * @param src source array, can be equal to dst
69 | * @param count number of 8 byte blocks
70 | * @param iv initialization vector for CBC mode, if NULL then ECB will be used
71 | * @param decrypt 0 for encryption, 1 for decryption
72 | */
73 | void av_xtea_crypt(struct AVXTEA *ctx, uint8_t *dst, const uint8_t *src,
74 | int count, uint8_t *iv, int decrypt);
75 |
76 | /**
77 | * Encrypt or decrypt a buffer using a previously initialized context,
78 | * in little endian format.
79 | *
80 | * @param ctx an AVXTEA context
81 | * @param dst destination array, can be equal to src
82 | * @param src source array, can be equal to dst
83 | * @param count number of 8 byte blocks
84 | * @param iv initialization vector for CBC mode, if NULL then ECB will be used
85 | * @param decrypt 0 for encryption, 1 for decryption
86 | */
87 | void av_xtea_le_crypt(struct AVXTEA *ctx, uint8_t *dst, const uint8_t *src,
88 | int count, uint8_t *iv, int decrypt);
89 |
90 | /**
91 | * @}
92 | */
93 |
94 | #endif /* AVUTIL_XTEA_H */
95 |
--------------------------------------------------------------------------------
/app/src/main/cpp/ffmpeg/include/libavutil/hmac.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2012 Martin Storsjo
3 | *
4 | * This file is part of FFmpeg.
5 | *
6 | * FFmpeg is free software; you can redistribute it and/or
7 | * modify it under the terms of the GNU Lesser General Public
8 | * License as published by the Free Software Foundation; either
9 | * version 2.1 of the License, or (at your option) any later version.
10 | *
11 | * FFmpeg is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 | * Lesser General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU Lesser General Public
17 | * License along with FFmpeg; if not, write to the Free Software
18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 | */
20 |
21 | #ifndef AVUTIL_HMAC_H
22 | #define AVUTIL_HMAC_H
23 |
24 | #include
25 |
26 | #include "version.h"
27 | /**
28 | * @defgroup lavu_hmac HMAC
29 | * @ingroup lavu_crypto
30 | * @{
31 | */
32 |
33 | enum AVHMACType {
34 | AV_HMAC_MD5,
35 | AV_HMAC_SHA1,
36 | AV_HMAC_SHA224,
37 | AV_HMAC_SHA256,
38 | AV_HMAC_SHA384,
39 | AV_HMAC_SHA512,
40 | };
41 |
42 | typedef struct AVHMAC AVHMAC;
43 |
44 | /**
45 | * Allocate an AVHMAC context.
46 | * @param type The hash function used for the HMAC.
47 | */
48 | AVHMAC *av_hmac_alloc(enum AVHMACType type);
49 |
50 | /**
51 | * Free an AVHMAC context.
52 | * @param ctx The context to free, may be NULL
53 | */
54 | void av_hmac_free(AVHMAC *ctx);
55 |
56 | /**
57 | * Initialize an AVHMAC context with an authentication key.
58 | * @param ctx The HMAC context
59 | * @param key The authentication key
60 | * @param keylen The length of the key, in bytes
61 | */
62 | void av_hmac_init(AVHMAC *ctx, const uint8_t *key, unsigned int keylen);
63 |
64 | /**
65 | * Hash data with the HMAC.
66 | * @param ctx The HMAC context
67 | * @param data The data to hash
68 | * @param len The length of the data, in bytes
69 | */
70 | void av_hmac_update(AVHMAC *ctx, const uint8_t *data, unsigned int len);
71 |
72 | /**
73 | * Finish hashing and output the HMAC digest.
74 | * @param ctx The HMAC context
75 | * @param out The output buffer to write the digest into
76 | * @param outlen The length of the out buffer, in bytes
77 | * @return The number of bytes written to out, or a negative error code.
78 | */
79 | int av_hmac_final(AVHMAC *ctx, uint8_t *out, unsigned int outlen);
80 |
81 | /**
82 | * Hash an array of data with a key.
83 | * @param ctx The HMAC context
84 | * @param data The data to hash
85 | * @param len The length of the data, in bytes
86 | * @param key The authentication key
87 | * @param keylen The length of the key, in bytes
88 | * @param out The output buffer to write the digest into
89 | * @param outlen The length of the out buffer, in bytes
90 | * @return The number of bytes written to out, or a negative error code.
91 | */
92 | int av_hmac_calc(AVHMAC *ctx, const uint8_t *data, unsigned int len,
93 | const uint8_t *key, unsigned int keylen,
94 | uint8_t *out, unsigned int outlen);
95 |
96 | /**
97 | * @}
98 | */
99 |
100 | #endif /* AVUTIL_HMAC_H */
101 |
--------------------------------------------------------------------------------
/app/src/main/cpp/ffmpeg/include/libavutil/bswap.h:
--------------------------------------------------------------------------------
1 | /*
2 | * copyright (c) 2006 Michael Niedermayer
3 | *
4 | * This file is part of FFmpeg.
5 | *
6 | * FFmpeg is free software; you can redistribute it and/or
7 | * modify it under the terms of the GNU Lesser General Public
8 | * License as published by the Free Software Foundation; either
9 | * version 2.1 of the License, or (at your option) any later version.
10 | *
11 | * FFmpeg is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 | * Lesser General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU Lesser General Public
17 | * License along with FFmpeg; if not, write to the Free Software
18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 | */
20 |
21 | /**
22 | * @file
23 | * byte swapping routines
24 | */
25 |
26 | #ifndef AVUTIL_BSWAP_H
27 | #define AVUTIL_BSWAP_H
28 |
29 | #include
30 | #include "libavutil/avconfig.h"
31 | #include "attributes.h"
32 |
33 | #ifdef HAVE_AV_CONFIG_H
34 |
35 | #include "config.h"
36 |
37 | #if ARCH_AARCH64
38 | # include "aarch64/bswap.h"
39 | #elif ARCH_ARM
40 | # include "arm/bswap.h"
41 | #elif ARCH_AVR32
42 | # include "avr32/bswap.h"
43 | #elif ARCH_SH4
44 | # include "sh4/bswap.h"
45 | #elif ARCH_X86
46 | # include "x86/bswap.h"
47 | #endif
48 |
49 | #endif /* HAVE_AV_CONFIG_H */
50 |
51 | #define AV_BSWAP16C(x) (((x) << 8 & 0xff00) | ((x) >> 8 & 0x00ff))
52 | #define AV_BSWAP32C(x) (AV_BSWAP16C(x) << 16 | AV_BSWAP16C((x) >> 16))
53 | #define AV_BSWAP64C(x) (AV_BSWAP32C(x) << 32 | AV_BSWAP32C((x) >> 32))
54 |
55 | #define AV_BSWAPC(s, x) AV_BSWAP##s##C(x)
56 |
57 | #ifndef av_bswap16
58 | static av_always_inline av_const uint16_t av_bswap16(uint16_t x)
59 | {
60 | x= (x>>8) | (x<<8);
61 | return x;
62 | }
63 | #endif
64 |
65 | #ifndef av_bswap32
66 | static av_always_inline av_const uint32_t av_bswap32(uint32_t x)
67 | {
68 | return AV_BSWAP32C(x);
69 | }
70 | #endif
71 |
72 | #ifndef av_bswap64
73 | static inline uint64_t av_const av_bswap64(uint64_t x)
74 | {
75 | return (uint64_t)av_bswap32(x) << 32 | av_bswap32(x >> 32);
76 | }
77 | #endif
78 |
79 | // be2ne ... big-endian to native-endian
80 | // le2ne ... little-endian to native-endian
81 |
82 | #if AV_HAVE_BIGENDIAN
83 | #define av_be2ne16(x) (x)
84 | #define av_be2ne32(x) (x)
85 | #define av_be2ne64(x) (x)
86 | #define av_le2ne16(x) av_bswap16(x)
87 | #define av_le2ne32(x) av_bswap32(x)
88 | #define av_le2ne64(x) av_bswap64(x)
89 | #define AV_BE2NEC(s, x) (x)
90 | #define AV_LE2NEC(s, x) AV_BSWAPC(s, x)
91 | #else
92 | #define av_be2ne16(x) av_bswap16(x)
93 | #define av_be2ne32(x) av_bswap32(x)
94 | #define av_be2ne64(x) av_bswap64(x)
95 | #define av_le2ne16(x) (x)
96 | #define av_le2ne32(x) (x)
97 | #define av_le2ne64(x) (x)
98 | #define AV_BE2NEC(s, x) AV_BSWAPC(s, x)
99 | #define AV_LE2NEC(s, x) (x)
100 | #endif
101 |
102 | #define AV_BE2NE16C(x) AV_BE2NEC(16, x)
103 | #define AV_BE2NE32C(x) AV_BE2NEC(32, x)
104 | #define AV_BE2NE64C(x) AV_BE2NEC(64, x)
105 | #define AV_LE2NE16C(x) AV_LE2NEC(16, x)
106 | #define AV_LE2NE32C(x) AV_LE2NEC(32, x)
107 | #define AV_LE2NE64C(x) AV_LE2NEC(64, x)
108 |
109 | #endif /* AVUTIL_BSWAP_H */
110 |
--------------------------------------------------------------------------------
/app/src/main/java/com/cxp/learningvideo/media/decoder/AudioDecoder.kt:
--------------------------------------------------------------------------------
1 | package com.cxp.learningvideo.media.decoder
2 |
3 | import android.media.*
4 | import com.cxp.learningvideo.media.BaseDecoder
5 | import com.cxp.learningvideo.media.IExtractor
6 | import com.cxp.learningvideo.media.extractor.AudioExtractor
7 | import java.nio.ByteBuffer
8 |
9 |
10 | /**
11 | * 音频解码器
12 | *
13 | * @author Chen Xiaoping (562818444@qq.com)
14 | * @since LearningVideo
15 | * @version LearningVideo
16 | * @Datetime 2019-09-03 10:52
17 | *
18 | */
19 | class AudioDecoder(path: String): BaseDecoder(path) {
20 | /**采样率*/
21 | private var mSampleRate = -1
22 |
23 | /**声音通道数量*/
24 | private var mChannels = 1
25 |
26 | /**PCM采样位数*/
27 | private var mPCMEncodeBit = AudioFormat.ENCODING_PCM_16BIT
28 |
29 | /**音频播放器*/
30 | private var mAudioTrack: AudioTrack? = null
31 |
32 | /**音频数据缓存*/
33 | private var mAudioOutTempBuf: ShortArray? = null
34 |
35 | override fun check(): Boolean {
36 | return true
37 | }
38 |
39 | override fun initExtractor(path: String): IExtractor {
40 | return AudioExtractor(path)
41 | }
42 |
43 | override fun initSpecParams(format: MediaFormat) {
44 | try {
45 | mChannels = format.getInteger(MediaFormat.KEY_CHANNEL_COUNT)
46 | mSampleRate = format.getInteger(MediaFormat.KEY_SAMPLE_RATE)
47 |
48 | mPCMEncodeBit = if (format.containsKey(MediaFormat.KEY_PCM_ENCODING)) {
49 | format.getInteger(MediaFormat.KEY_PCM_ENCODING)
50 | } else {
51 | //如果没有这个参数,默认为16位采样
52 | AudioFormat.ENCODING_PCM_16BIT
53 | }
54 | } catch (e: Exception) {
55 | }
56 | }
57 |
58 | override fun configCodec(codec: MediaCodec, format: MediaFormat): Boolean {
59 | codec.configure(format, null , null, 0)
60 | return true
61 | }
62 |
63 | override fun initRender(): Boolean {
64 | val channel = if (mChannels == 1) {
65 | //单声道
66 | AudioFormat.CHANNEL_OUT_MONO
67 | } else {
68 | //双声道
69 | AudioFormat.CHANNEL_OUT_STEREO
70 | }
71 |
72 | //获取最小缓冲区
73 | val minBufferSize = AudioTrack.getMinBufferSize(mSampleRate, channel, mPCMEncodeBit)
74 |
75 | mAudioOutTempBuf = ShortArray(minBufferSize/2)
76 |
77 | mAudioTrack = AudioTrack(
78 | AudioManager.STREAM_MUSIC,//播放类型:音乐
79 | mSampleRate, //采样率
80 | channel, //通道
81 | mPCMEncodeBit, //采样位数
82 | minBufferSize, //缓冲区大小
83 | AudioTrack.MODE_STREAM) //播放模式:数据流动态写入,另一种是一次性写入
84 |
85 | mAudioTrack!!.play()
86 | return true
87 | }
88 |
89 | override fun render(outputBuffer: ByteBuffer,
90 | bufferInfo: MediaCodec.BufferInfo) {
91 | if (mAudioOutTempBuf!!.size < bufferInfo.size / 2) {
92 | mAudioOutTempBuf = ShortArray(bufferInfo.size / 2)
93 | }
94 | outputBuffer.position(0)
95 | outputBuffer.asShortBuffer().get(mAudioOutTempBuf, 0, bufferInfo.size/2)
96 | mAudioTrack!!.write(mAudioOutTempBuf!!, 0, bufferInfo.size / 2)
97 | }
98 |
99 | override fun doneDecode() {
100 | mAudioTrack?.stop()
101 | mAudioTrack?.release()
102 | }
103 | }
--------------------------------------------------------------------------------
/app/src/main/cpp/ffmpeg/include/libavcodec/d3d11va.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Direct3D11 HW acceleration
3 | *
4 | * copyright (c) 2009 Laurent Aimar
5 | * copyright (c) 2015 Steve Lhomme
6 | *
7 | * This file is part of FFmpeg.
8 | *
9 | * FFmpeg is free software; you can redistribute it and/or
10 | * modify it under the terms of the GNU Lesser General Public
11 | * License as published by the Free Software Foundation; either
12 | * version 2.1 of the License, or (at your option) any later version.
13 | *
14 | * FFmpeg is distributed in the hope that it will be useful,
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 | * Lesser General Public License for more details.
18 | *
19 | * You should have received a copy of the GNU Lesser General Public
20 | * License along with FFmpeg; if not, write to the Free Software
21 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22 | */
23 |
24 | #ifndef AVCODEC_D3D11VA_H
25 | #define AVCODEC_D3D11VA_H
26 |
27 | /**
28 | * @file
29 | * @ingroup lavc_codec_hwaccel_d3d11va
30 | * Public libavcodec D3D11VA header.
31 | */
32 |
33 | #if !defined(_WIN32_WINNT) || _WIN32_WINNT < 0x0602
34 | #undef _WIN32_WINNT
35 | #define _WIN32_WINNT 0x0602
36 | #endif
37 |
38 | #include
39 | #include
40 |
41 | /**
42 | * @defgroup lavc_codec_hwaccel_d3d11va Direct3D11
43 | * @ingroup lavc_codec_hwaccel
44 | *
45 | * @{
46 | */
47 |
48 | #define FF_DXVA2_WORKAROUND_SCALING_LIST_ZIGZAG 1 ///< Work around for Direct3D11 and old UVD/UVD+ ATI video cards
49 | #define FF_DXVA2_WORKAROUND_INTEL_CLEARVIDEO 2 ///< Work around for Direct3D11 and old Intel GPUs with ClearVideo interface
50 |
51 | /**
52 | * This structure is used to provides the necessary configurations and data
53 | * to the Direct3D11 FFmpeg HWAccel implementation.
54 | *
55 | * The application must make it available as AVCodecContext.hwaccel_context.
56 | *
57 | * Use av_d3d11va_alloc_context() exclusively to allocate an AVD3D11VAContext.
58 | */
59 | typedef struct AVD3D11VAContext {
60 | /**
61 | * D3D11 decoder object
62 | */
63 | ID3D11VideoDecoder *decoder;
64 |
65 | /**
66 | * D3D11 VideoContext
67 | */
68 | ID3D11VideoContext *video_context;
69 |
70 | /**
71 | * D3D11 configuration used to create the decoder
72 | */
73 | D3D11_VIDEO_DECODER_CONFIG *cfg;
74 |
75 | /**
76 | * The number of surface in the surface array
77 | */
78 | unsigned surface_count;
79 |
80 | /**
81 | * The array of Direct3D surfaces used to create the decoder
82 | */
83 | ID3D11VideoDecoderOutputView **surface;
84 |
85 | /**
86 | * A bit field configuring the workarounds needed for using the decoder
87 | */
88 | uint64_t workaround;
89 |
90 | /**
91 | * Private to the FFmpeg AVHWAccel implementation
92 | */
93 | unsigned report_id;
94 |
95 | /**
96 | * Mutex to access video_context
97 | */
98 | HANDLE context_mutex;
99 | } AVD3D11VAContext;
100 |
101 | /**
102 | * Allocate an AVD3D11VAContext.
103 | *
104 | * @return Newly-allocated AVD3D11VAContext or NULL on failure.
105 | */
106 | AVD3D11VAContext *av_d3d11va_alloc_context(void);
107 |
108 | /**
109 | * @}
110 | */
111 |
112 | #endif /* AVCODEC_D3D11VA_H */
113 |
--------------------------------------------------------------------------------
/app/src/main/cpp/ffmpeg/include/libavutil/crc.h:
--------------------------------------------------------------------------------
1 | /*
2 | * copyright (c) 2006 Michael Niedermayer
3 | *
4 | * This file is part of FFmpeg.
5 | *
6 | * FFmpeg is free software; you can redistribute it and/or
7 | * modify it under the terms of the GNU Lesser General Public
8 | * License as published by the Free Software Foundation; either
9 | * version 2.1 of the License, or (at your option) any later version.
10 | *
11 | * FFmpeg is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 | * Lesser General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU Lesser General Public
17 | * License along with FFmpeg; if not, write to the Free Software
18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 | */
20 |
21 | /**
22 | * @file
23 | * @ingroup lavu_crc32
24 | * Public header for CRC hash function implementation.
25 | */
26 |
27 | #ifndef AVUTIL_CRC_H
28 | #define AVUTIL_CRC_H
29 |
30 | #include
31 | #include
32 | #include "attributes.h"
33 | #include "version.h"
34 |
35 | /**
36 | * @defgroup lavu_crc32 CRC
37 | * @ingroup lavu_hash
38 | * CRC (Cyclic Redundancy Check) hash function implementation.
39 | *
40 | * This module supports numerous CRC polynomials, in addition to the most
41 | * widely used CRC-32-IEEE. See @ref AVCRCId for a list of available
42 | * polynomials.
43 | *
44 | * @{
45 | */
46 |
47 | typedef uint32_t AVCRC;
48 |
49 | typedef enum {
50 | AV_CRC_8_ATM,
51 | AV_CRC_16_ANSI,
52 | AV_CRC_16_CCITT,
53 | AV_CRC_32_IEEE,
54 | AV_CRC_32_IEEE_LE, /*< reversed bitorder version of AV_CRC_32_IEEE */
55 | AV_CRC_16_ANSI_LE, /*< reversed bitorder version of AV_CRC_16_ANSI */
56 | AV_CRC_24_IEEE,
57 | AV_CRC_8_EBU,
58 | AV_CRC_MAX, /*< Not part of public API! Do not use outside libavutil. */
59 | }AVCRCId;
60 |
61 | /**
62 | * Initialize a CRC table.
63 | * @param ctx must be an array of size sizeof(AVCRC)*257 or sizeof(AVCRC)*1024
64 | * @param le If 1, the lowest bit represents the coefficient for the highest
65 | * exponent of the corresponding polynomial (both for poly and
66 | * actual CRC).
67 | * If 0, you must swap the CRC parameter and the result of av_crc
68 | * if you need the standard representation (can be simplified in
69 | * most cases to e.g. bswap16):
70 | * av_bswap32(crc << (32-bits))
71 | * @param bits number of bits for the CRC
72 | * @param poly generator polynomial without the x**bits coefficient, in the
73 | * representation as specified by le
74 | * @param ctx_size size of ctx in bytes
75 | * @return <0 on failure
76 | */
77 | int av_crc_init(AVCRC *ctx, int le, int bits, uint32_t poly, int ctx_size);
78 |
79 | /**
80 | * Get an initialized standard CRC table.
81 | * @param crc_id ID of a standard CRC
82 | * @return a pointer to the CRC table or NULL on failure
83 | */
84 | const AVCRC *av_crc_get_table(AVCRCId crc_id);
85 |
86 | /**
87 | * Calculate the CRC of a block.
88 | * @param crc CRC of previous blocks if any or initial value for CRC
89 | * @return CRC updated with the data from the given block
90 | *
91 | * @see av_crc_init() "le" parameter
92 | */
93 | uint32_t av_crc(const AVCRC *ctx, uint32_t crc,
94 | const uint8_t *buffer, size_t length) av_pure;
95 |
96 | /**
97 | * @}
98 | */
99 |
100 | #endif /* AVUTIL_CRC_H */
101 |
--------------------------------------------------------------------------------
/app/src/main/cpp/ffmpeg/include/libavcodec/avfft.h:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of FFmpeg.
3 | *
4 | * FFmpeg is free software; you can redistribute it and/or
5 | * modify it under the terms of the GNU Lesser General Public
6 | * License as published by the Free Software Foundation; either
7 | * version 2.1 of the License, or (at your option) any later version.
8 | *
9 | * FFmpeg is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 | * Lesser General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU Lesser General Public
15 | * License along with FFmpeg; if not, write to the Free Software
16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 | */
18 |
19 | #ifndef AVCODEC_AVFFT_H
20 | #define AVCODEC_AVFFT_H
21 |
22 | /**
23 | * @file
24 | * @ingroup lavc_fft
25 | * FFT functions
26 | */
27 |
28 | /**
29 | * @defgroup lavc_fft FFT functions
30 | * @ingroup lavc_misc
31 | *
32 | * @{
33 | */
34 |
35 | typedef float FFTSample;
36 |
37 | typedef struct FFTComplex {
38 | FFTSample re, im;
39 | } FFTComplex;
40 |
41 | typedef struct FFTContext FFTContext;
42 |
43 | /**
44 | * Set up a complex FFT.
45 | * @param nbits log2 of the length of the input array
46 | * @param inverse if 0 perform the forward transform, if 1 perform the inverse
47 | */
48 | FFTContext *av_fft_init(int nbits, int inverse);
49 |
50 | /**
51 | * Do the permutation needed BEFORE calling ff_fft_calc().
52 | */
53 | void av_fft_permute(FFTContext *s, FFTComplex *z);
54 |
55 | /**
56 | * Do a complex FFT with the parameters defined in av_fft_init(). The
57 | * input data must be permuted before. No 1.0/sqrt(n) normalization is done.
58 | */
59 | void av_fft_calc(FFTContext *s, FFTComplex *z);
60 |
61 | void av_fft_end(FFTContext *s);
62 |
63 | FFTContext *av_mdct_init(int nbits, int inverse, double scale);
64 | void av_imdct_calc(FFTContext *s, FFTSample *output, const FFTSample *input);
65 | void av_imdct_half(FFTContext *s, FFTSample *output, const FFTSample *input);
66 | void av_mdct_calc(FFTContext *s, FFTSample *output, const FFTSample *input);
67 | void av_mdct_end(FFTContext *s);
68 |
69 | /* Real Discrete Fourier Transform */
70 |
71 | enum RDFTransformType {
72 | DFT_R2C,
73 | IDFT_C2R,
74 | IDFT_R2C,
75 | DFT_C2R,
76 | };
77 |
78 | typedef struct RDFTContext RDFTContext;
79 |
80 | /**
81 | * Set up a real FFT.
82 | * @param nbits log2 of the length of the input array
83 | * @param trans the type of transform
84 | */
85 | RDFTContext *av_rdft_init(int nbits, enum RDFTransformType trans);
86 | void av_rdft_calc(RDFTContext *s, FFTSample *data);
87 | void av_rdft_end(RDFTContext *s);
88 |
89 | /* Discrete Cosine Transform */
90 |
91 | typedef struct DCTContext DCTContext;
92 |
93 | enum DCTTransformType {
94 | DCT_II = 0,
95 | DCT_III,
96 | DCT_I,
97 | DST_I,
98 | };
99 |
100 | /**
101 | * Set up DCT.
102 | *
103 | * @param nbits size of the input array:
104 | * (1 << nbits) for DCT-II, DCT-III and DST-I
105 | * (1 << nbits) + 1 for DCT-I
106 | * @param type the type of transform
107 | *
108 | * @note the first element of the input of DST-I is ignored
109 | */
110 | DCTContext *av_dct_init(int nbits, enum DCTTransformType type);
111 | void av_dct_calc(DCTContext *s, FFTSample *data);
112 | void av_dct_end (DCTContext *s);
113 |
114 | /**
115 | * @}
116 | */
117 |
118 | #endif /* AVCODEC_AVFFT_H */
119 |
--------------------------------------------------------------------------------
/app/src/main/cpp/ffmpeg/include/libavutil/downmix_info.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2014 Tim Walker
3 | *
4 | * This file is part of FFmpeg.
5 | *
6 | * FFmpeg is free software; you can redistribute it and/or
7 | * modify it under the terms of the GNU Lesser General Public
8 | * License as published by the Free Software Foundation; either
9 | * version 2.1 of the License, or (at your option) any later version.
10 | *
11 | * FFmpeg is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 | * Lesser General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU Lesser General Public
17 | * License along with FFmpeg; if not, write to the Free Software
18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 | */
20 |
21 | #ifndef AVUTIL_DOWNMIX_INFO_H
22 | #define AVUTIL_DOWNMIX_INFO_H
23 |
24 | #include "frame.h"
25 |
26 | /**
27 | * @file
28 | * audio downmix medatata
29 | */
30 |
31 | /**
32 | * @addtogroup lavu_audio
33 | * @{
34 | */
35 |
36 | /**
37 | * @defgroup downmix_info Audio downmix metadata
38 | * @{
39 | */
40 |
41 | /**
42 | * Possible downmix types.
43 | */
44 | enum AVDownmixType {
45 | AV_DOWNMIX_TYPE_UNKNOWN, /**< Not indicated. */
46 | AV_DOWNMIX_TYPE_LORO, /**< Lo/Ro 2-channel downmix (Stereo). */
47 | AV_DOWNMIX_TYPE_LTRT, /**< Lt/Rt 2-channel downmix, Dolby Surround compatible. */
48 | AV_DOWNMIX_TYPE_DPLII, /**< Lt/Rt 2-channel downmix, Dolby Pro Logic II compatible. */
49 | AV_DOWNMIX_TYPE_NB /**< Number of downmix types. Not part of ABI. */
50 | };
51 |
52 | /**
53 | * This structure describes optional metadata relevant to a downmix procedure.
54 | *
55 | * All fields are set by the decoder to the value indicated in the audio
56 | * bitstream (if present), or to a "sane" default otherwise.
57 | */
58 | typedef struct AVDownmixInfo {
59 | /**
60 | * Type of downmix preferred by the mastering engineer.
61 | */
62 | enum AVDownmixType preferred_downmix_type;
63 |
64 | /**
65 | * Absolute scale factor representing the nominal level of the center
66 | * channel during a regular downmix.
67 | */
68 | double center_mix_level;
69 |
70 | /**
71 | * Absolute scale factor representing the nominal level of the center
72 | * channel during an Lt/Rt compatible downmix.
73 | */
74 | double center_mix_level_ltrt;
75 |
76 | /**
77 | * Absolute scale factor representing the nominal level of the surround
78 | * channels during a regular downmix.
79 | */
80 | double surround_mix_level;
81 |
82 | /**
83 | * Absolute scale factor representing the nominal level of the surround
84 | * channels during an Lt/Rt compatible downmix.
85 | */
86 | double surround_mix_level_ltrt;
87 |
88 | /**
89 | * Absolute scale factor representing the level at which the LFE data is
90 | * mixed into L/R channels during downmixing.
91 | */
92 | double lfe_mix_level;
93 | } AVDownmixInfo;
94 |
95 | /**
96 | * Get a frame's AV_FRAME_DATA_DOWNMIX_INFO side data for editing.
97 | *
98 | * If the side data is absent, it is created and added to the frame.
99 | *
100 | * @param frame the frame for which the side data is to be obtained or created
101 | *
102 | * @return the AVDownmixInfo structure to be edited by the caller, or NULL if
103 | * the structure cannot be allocated.
104 | */
105 | AVDownmixInfo *av_downmix_info_update_side_data(AVFrame *frame);
106 |
107 | /**
108 | * @}
109 | */
110 |
111 | /**
112 | * @}
113 | */
114 |
115 | #endif /* AVUTIL_DOWNMIX_INFO_H */
116 |
--------------------------------------------------------------------------------
/app/src/main/java/com/cxp/learningvideo/media/encoder/VideoEncoder.kt:
--------------------------------------------------------------------------------
1 | package com.cxp.learningvideo.media.encoder
2 |
3 | import android.media.MediaCodec
4 | import android.media.MediaCodecInfo
5 | import android.media.MediaFormat
6 | import android.os.Build
7 | import android.util.Log
8 | import android.view.Surface
9 | import com.cxp.learningvideo.media.muxer.MMuxer
10 | import java.nio.ByteBuffer
11 |
12 |
13 | /**
14 | * 视频编码器
15 | *
16 | * @author Chen Xiaoping (562818444@qq.com)
17 | * @since LearningVideo
18 | * @version LearningVideo
19 | * @Datetime 2019-12-15 22:00
20 | *
21 | */
22 |
23 | const val DEFAULT_ENCODE_FRAME_RATE = 30
24 |
25 | class VideoEncoder(muxer: MMuxer, width: Int, height: Int): BaseEncoder(muxer, width, height) {
26 |
27 | private val TAG = "VideoEncoder"
28 |
29 | private var mSurface: Surface? = null
30 |
31 | override fun encodeType(): String {
32 | return "video/avc"
33 | }
34 |
35 | override fun configEncoder(codec: MediaCodec) {
36 | if (mWidth <= 0 || mHeight <= 0) {
37 | throw IllegalArgumentException("Encode width or height is invalid, width: $mWidth, height: $mHeight")
38 | }
39 | val bitrate = 3 * mWidth * mHeight
40 | val outputFormat = MediaFormat.createVideoFormat(encodeType(), mWidth, mHeight)
41 | outputFormat.setInteger(MediaFormat.KEY_BIT_RATE, bitrate)
42 | outputFormat.setInteger(MediaFormat.KEY_FRAME_RATE, DEFAULT_ENCODE_FRAME_RATE)
43 | outputFormat.setInteger(MediaFormat.KEY_I_FRAME_INTERVAL, 1)
44 | outputFormat.setInteger(MediaFormat.KEY_COLOR_FORMAT, MediaCodecInfo.CodecCapabilities.COLOR_FormatSurface)
45 |
46 | try {
47 | configEncoderWithCQ(codec, outputFormat)
48 | } catch (e: Exception) {
49 | e.printStackTrace()
50 | // 捕获异常,设置为系统默认配置 BITRATE_MODE_VBR
51 | try {
52 | configEncoderWithVBR(codec, outputFormat)
53 | } catch (e: Exception) {
54 | e.printStackTrace()
55 | Log.e(TAG, "配置视频编码器失败")
56 | }
57 | }
58 |
59 | mSurface = codec.createInputSurface()
60 | }
61 |
62 | private fun configEncoderWithCQ(codec: MediaCodec, outputFormat: MediaFormat) {
63 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
64 | // 本部分手机不支持 BITRATE_MODE_CQ 模式,有可能会异常
65 | outputFormat.setInteger(
66 | MediaFormat.KEY_BITRATE_MODE,
67 | MediaCodecInfo.EncoderCapabilities.BITRATE_MODE_CQ
68 | )
69 | }
70 | codec.configure(outputFormat, null, null, MediaCodec.CONFIGURE_FLAG_ENCODE)
71 | }
72 |
73 | private fun configEncoderWithVBR(codec: MediaCodec, outputFormat: MediaFormat) {
74 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
75 | outputFormat.setInteger(
76 | MediaFormat.KEY_BITRATE_MODE,
77 | MediaCodecInfo.EncoderCapabilities.BITRATE_MODE_VBR
78 | )
79 | }
80 | codec.configure(outputFormat, null, null, MediaCodec.CONFIGURE_FLAG_ENCODE)
81 | }
82 |
83 | override fun addTrack(muxer: MMuxer, mediaFormat: MediaFormat) {
84 | muxer.addVideoTrack(mediaFormat)
85 | }
86 |
87 | override fun writeData(
88 | muxer: MMuxer,
89 | byteBuffer: ByteBuffer,
90 | bufferInfo: MediaCodec.BufferInfo
91 | ) {
92 | muxer.writeVideoData(byteBuffer, bufferInfo)
93 | }
94 |
95 | override fun encodeManually(): Boolean {
96 | return false
97 | }
98 |
99 | override fun release(muxer: MMuxer) {
100 | muxer.releaseVideoTrack()
101 | }
102 |
103 | fun getEncodeSurface(): Surface? {
104 | return mSurface
105 | }
106 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/cxp/learningvideo/media/extractor/MMExtractor.kt:
--------------------------------------------------------------------------------
1 | package com.chenlittleping.videoeditor.decoder
2 |
3 | import android.media.MediaExtractor
4 | import android.media.MediaFormat
5 | import java.nio.ByteBuffer
6 |
7 |
8 | /**
9 | * 音视频分离器
10 | *
11 | * @author Chen Xiaoping (562818444@qq.com)
12 | * @since VideoEditor
13 | * @version VideoEditor
14 | * @Datetime 2019-09-03
15 | *
16 | */
17 |
18 | class MMExtractor(path: String?) {
19 |
20 | /**音视频分离器*/
21 | private var mExtractor: MediaExtractor? = null
22 |
23 | /**音频通道索引*/
24 | private var mAudioTrack = -1
25 |
26 | /**视频通道索引*/
27 | private var mVideoTrack = -1
28 |
29 | /**当前帧时间戳*/
30 | private var mCurSampleTime: Long = 0
31 |
32 | /**当前帧标志*/
33 | private var mCurSampleFlag: Int = 0
34 |
35 | /**开始解码时间点*/
36 | private var mStartPos: Long = 0
37 |
38 | init {
39 | mExtractor = MediaExtractor()
40 | mExtractor?.setDataSource(path)
41 | }
42 |
43 | /**
44 | * 获取视频格式参数
45 | */
46 | fun getVideoFormat(): MediaFormat? {
47 | for (i in 0 until mExtractor!!.trackCount) {
48 | val mediaFormat = mExtractor!!.getTrackFormat(i)
49 | val mime = mediaFormat.getString(MediaFormat.KEY_MIME)
50 | if (mime.startsWith("video/")) {
51 | mVideoTrack = i
52 | break
53 | }
54 | }
55 | return if (mVideoTrack >= 0)
56 | mExtractor!!.getTrackFormat(mVideoTrack)
57 | else null
58 | }
59 |
60 | /**
61 | * 获取音频格式参数
62 | */
63 | fun getAudioFormat(): MediaFormat? {
64 | for (i in 0 until mExtractor!!.trackCount) {
65 | val mediaFormat = mExtractor!!.getTrackFormat(i)
66 | val mime = mediaFormat.getString(MediaFormat.KEY_MIME)
67 | if (mime.startsWith("audio/")) {
68 | mAudioTrack = i
69 | break
70 | }
71 | }
72 | return if (mAudioTrack >= 0) {
73 | mExtractor!!.getTrackFormat(mAudioTrack)
74 | } else null
75 | }
76 |
77 | /**
78 | * 读取视频数据
79 | */
80 | fun readBuffer(byteBuffer: ByteBuffer): Int {
81 | byteBuffer.clear()
82 | selectSourceTrack()
83 | var readSampleCount = mExtractor!!.readSampleData(byteBuffer, 0)
84 | if (readSampleCount < 0) {
85 | return -1
86 | }
87 | //记录当前帧的时间戳
88 | mCurSampleTime = mExtractor!!.sampleTime
89 | mCurSampleFlag = mExtractor!!.sampleFlags
90 | //进入下一帧
91 | mExtractor!!.advance()
92 | return readSampleCount
93 | }
94 |
95 | /**
96 | * 选择通道
97 | */
98 | private fun selectSourceTrack() {
99 | if (mVideoTrack >= 0) {
100 | mExtractor!!.selectTrack(mVideoTrack)
101 | } else if (mAudioTrack >= 0) {
102 | mExtractor!!.selectTrack(mAudioTrack)
103 | }
104 | }
105 |
106 | /**
107 | * Seek到指定位置,并返回实际帧的时间戳
108 | */
109 | fun seek(pos: Long): Long {
110 | mExtractor!!.seekTo(pos, MediaExtractor.SEEK_TO_PREVIOUS_SYNC)
111 | return mExtractor!!.sampleTime
112 | }
113 |
114 | /**
115 | * 停止读取数据
116 | */
117 | fun stop() {
118 | mExtractor?.release()
119 | mExtractor = null
120 | }
121 |
122 | fun getVideoTrack(): Int {
123 | return mVideoTrack
124 | }
125 |
126 | fun getAudioTrack(): Int {
127 | return mAudioTrack
128 | }
129 |
130 | fun setStartPos(pos: Long) {
131 | mStartPos = pos
132 | }
133 |
134 | /**
135 | * 获取当前帧时间
136 | */
137 | fun getCurrentTimestamp(): Long {
138 | return mCurSampleTime
139 | }
140 |
141 | fun getSampleFlag(): Int {
142 | return mCurSampleFlag
143 | }
144 | }
--------------------------------------------------------------------------------