├── .gitignore
├── .idea
├── gradle.xml
├── misc.xml
├── modules.xml
├── runConfigurations.xml
└── vcs.xml
├── app
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── com
│ │ └── rockchip
│ │ └── rkmediacodecdemo
│ │ └── ExampleInstrumentedTest.java
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── com
│ │ │ └── rockchip
│ │ │ └── rkmediacodecdemo
│ │ │ ├── MainActivity.java
│ │ │ ├── PlayerView.java
│ │ │ ├── PortScanner.java
│ │ │ ├── RKMediaplayer.java
│ │ │ └── rtsp
│ │ │ ├── AACPackage.java
│ │ │ ├── H264Package.java
│ │ │ ├── NALUnit.java
│ │ │ ├── RTCPPackage.java
│ │ │ ├── RTPConnector.java
│ │ │ ├── RTPPackage.java
│ │ │ └── RTSPConnector.java
│ └── res
│ │ ├── drawable-v24
│ │ └── ic_launcher_foreground.xml
│ │ ├── drawable
│ │ └── ic_launcher_background.xml
│ │ ├── layout
│ │ └── activity_main.xml
│ │ ├── mipmap-anydpi-v26
│ │ ├── ic_launcher.xml
│ │ └── ic_launcher_round.xml
│ │ ├── 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
│ │ └── values
│ │ ├── colors.xml
│ │ ├── strings.xml
│ │ └── styles.xml
│ └── test
│ └── java
│ └── com
│ └── rockchip
│ └── rkmediacodecdemo
│ └── ExampleUnitTest.java
├── build.gradle
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── rkmediacodec
├── .gitignore
├── CMakeLists.txt
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── com
│ │ └── rockchip
│ │ └── rkmediacodec
│ │ └── ExampleInstrumentedTest.java
│ ├── main
│ ├── AndroidManifest.xml
│ ├── cpp
│ │ ├── log.h
│ │ ├── native-lib.cpp
│ │ ├── rk_mpp.cpp
│ │ └── rk_mpp.h
│ ├── java
│ │ └── com
│ │ │ └── rockchip
│ │ │ └── rkmediacodec
│ │ │ └── RKMediaCodec.java
│ ├── jniLibs
│ │ ├── arm64-v8a
│ │ │ ├── libmpp.so
│ │ │ └── libvpu.so
│ │ └── include
│ │ │ ├── mpp_buffer.h
│ │ │ ├── mpp_err.h
│ │ │ ├── mpp_frame.h
│ │ │ ├── mpp_meta.h
│ │ │ ├── mpp_packet.h
│ │ │ ├── mpp_task.h
│ │ │ ├── rk_mpi.h
│ │ │ ├── rk_mpi_cmd.h
│ │ │ ├── rk_type.h
│ │ │ ├── vpu.h
│ │ │ └── vpu_api.h
│ └── res
│ │ └── values
│ │ └── strings.xml
│ └── test
│ └── java
│ └── com
│ └── rockchip
│ └── rkmediacodec
│ └── ExampleUnitTest.java
└── settings.gradle
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea/workspace.xml
5 | /.idea/libraries
6 | .DS_Store
7 | /build
8 | /captures
9 | .externalNativeBuild
10 |
--------------------------------------------------------------------------------
/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
18 |
19 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 | 1.8
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/.idea/runConfigurations.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 26
5 | defaultConfig {
6 | applicationId "com.rockchip.rkmediacodecdemo"
7 | minSdkVersion 25
8 | targetSdkVersion 26
9 | versionCode 1
10 | versionName "1.0"
11 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
12 | }
13 | buildTypes {
14 | release {
15 | minifyEnabled false
16 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
17 | }
18 | }
19 | }
20 |
21 | dependencies {
22 | implementation fileTree(include: ['*.jar'], dir: 'libs')
23 | implementation 'com.android.support:appcompat-v7:26.1.0'
24 | implementation 'com.android.support.constraint:constraint-layout:1.0.2'
25 | testImplementation 'junit:junit:4.12'
26 | androidTestImplementation 'com.android.support.test:runner:1.0.1'
27 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
28 | implementation project(':rkmediacodec')
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/androidTest/java/com/rockchip/rkmediacodecdemo/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.rockchip.rkmediacodecdemo;
2 |
3 | import android.content.Context;
4 | import android.support.test.InstrumentationRegistry;
5 | import android.support.test.runner.AndroidJUnit4;
6 |
7 | import org.junit.Test;
8 | import org.junit.runner.RunWith;
9 |
10 | import static org.junit.Assert.*;
11 |
12 | /**
13 | * Instrumented test, which will execute on an Android device.
14 | *
15 | * @see Testing documentation
16 | */
17 | @RunWith(AndroidJUnit4.class)
18 | public class ExampleInstrumentedTest {
19 | @Test
20 | public void useAppContext() throws Exception {
21 | // Context of the app under test.
22 | Context appContext = InstrumentationRegistry.getTargetContext();
23 |
24 | assertEquals("com.rockchip.rkmediacodecdemo", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/app/src/main/java/com/rockchip/rkmediacodecdemo/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.rockchip.rkmediacodecdemo;
2 |
3 | import android.os.Bundle;
4 | import android.support.v7.app.AppCompatActivity;
5 | import android.util.Log;
6 | import android.view.View;
7 | import android.widget.Button;
8 |
9 | public class MainActivity extends AppCompatActivity {
10 | Button start_button;
11 | private PlayerView mSurfaceView;
12 | private PlayerView mSurfaceView2;
13 | private PlayerView mSurfaceView3;
14 | private PlayerView mSurfaceView4;
15 | // private String RTSP_IP1 = "172.16.9.113";
16 | private String RTSP_IP1 = "192.168.17.102";
17 | private String RTSP_IP2 = "192.168.17.101";
18 | private String RTSP_IP3 = "192.168.17.105";
19 | private String RTSP_IP4 = "192.168.17.106";
20 | private int RTSP_port2 = 8554;
21 | private int RTSP_port = 554;
22 | private String RTSP_func2 = "video";
23 | private String RTSP_func = "live/av0";
24 | private String RTSP_func_av1 = "live/av0";
25 |
26 | @Override
27 | protected void onCreate(Bundle savedInstanceState) {
28 | super.onCreate(savedInstanceState);
29 | setContentView(R.layout.activity_main);
30 | mSurfaceView = (PlayerView) findViewById(R.id.surfaceView1);
31 | mSurfaceView2 = (PlayerView) findViewById(R.id.surfaceView2);
32 | mSurfaceView3 = (PlayerView) findViewById(R.id.surfaceView3);
33 | mSurfaceView4 = (PlayerView) findViewById(R.id.surfaceView4);
34 |
35 | start_button = (Button) findViewById(R.id.start_button);
36 | start_button.setOnClickListener(new View.OnClickListener() {
37 | @Override
38 | public void onClick(View view) {
39 | Log.d("*******", "onClick: ----------------------------------");
40 | mSurfaceView.MediaPaly(RTSP_IP3, RTSP_port, RTSP_func_av1);
41 | // mSurfaceView.MediaPaly(RTSP_IP1,RTSP_port,RTSP_func);
42 | mSurfaceView2.MediaPaly(RTSP_IP4, RTSP_port, RTSP_func_av1);
43 | // mSurfaceView2.MediaPaly(RTSP_IP2, RTSP_port, RTSP_func);
44 | mSurfaceView3.MediaPaly(RTSP_IP3,RTSP_port,RTSP_func);
45 | mSurfaceView4.MediaPaly(RTSP_IP4,RTSP_port,RTSP_func);
46 | }
47 | });
48 | }
49 |
50 | }
51 |
--------------------------------------------------------------------------------
/app/src/main/java/com/rockchip/rkmediacodecdemo/PlayerView.java:
--------------------------------------------------------------------------------
1 | package com.rockchip.rkmediacodecdemo;
2 |
3 | import android.content.Context;
4 | import android.opengl.GLES20;
5 | import android.util.AttributeSet;
6 | import android.util.Log;
7 | import android.view.SurfaceHolder;
8 | import android.view.SurfaceView;
9 |
10 | /**
11 | * Created by cxh on 2018/1/3
12 | * E-mail: shon.chen@rock-chips.com
13 | */
14 |
15 | public class PlayerView extends SurfaceView implements SurfaceHolder.Callback{
16 |
17 | static final String TAG = "PlayerView";
18 | Context mContext;
19 | private RKMediaplayer mRKMediaplayer = null;
20 | private SurfaceHolder mSurfaceHolder;
21 | public PlayerView(Context context) {
22 | super(context);
23 | mContext = context;
24 | init();
25 | }
26 |
27 | private void init() {
28 | mSurfaceHolder = getHolder();
29 | mSurfaceHolder.addCallback(this);
30 | }
31 | public PlayerView(Context context, AttributeSet attrs) {
32 | super(context, attrs);
33 | mContext = context;
34 | init();
35 | }
36 |
37 | public PlayerView(Context context, AttributeSet attrs, int defStyleAttr) {
38 | super(context, attrs, defStyleAttr);
39 | mContext = context;
40 | init();
41 | }
42 |
43 |
44 | public String getfps(){
45 | if (mRKMediaplayer != null) {
46 | return mRKMediaplayer.getfps();
47 | }else {
48 | Log.d(TAG, "MediaPaly: NULLLLLLLLLLLLLLLLLLLLLLLLLLLL");
49 | }
50 | return null;
51 | }
52 |
53 | /**
54 | * 以下为播放器状态控制代码
55 | */
56 | public void MediaPaly(String RTSP, int RTSPport, String RTSPfunc) {
57 | //初始化原本应该得放在OpenGL创建的时候一起的,但是如果在OpenGL初始化的时候创建就会出现闪退的现象
58 | //GLSurfaceView_num > 1 说明是只有一个播放窗口需要为其添加一个播放器
59 | if (mRKMediaplayer == null ){
60 | mRKMediaplayer = new RKMediaplayer(mSurfaceHolder);
61 | }
62 | mRKMediaplayer.playRTSPVideo(RTSP, RTSPport, RTSPfunc);
63 | }
64 |
65 | public void MediaStop() {
66 | if (mRKMediaplayer != null) {
67 | GLES20.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
68 | mRKMediaplayer.stop();
69 | }
70 | }
71 |
72 | public void MediaPause() {
73 | if (mRKMediaplayer != null) {
74 | }
75 | }
76 |
77 | public void MediaContinue() {
78 | if (mRKMediaplayer != null) {
79 | }
80 | }
81 |
82 | @Override
83 | public void surfaceCreated(SurfaceHolder surfaceHolder) {
84 |
85 | }
86 |
87 | @Override
88 | public void surfaceChanged(SurfaceHolder surfaceHolder, int i, int i1, int i2) {
89 | mRKMediaplayer = new RKMediaplayer(mSurfaceHolder);
90 | // mRKPlayer = new RKMediaplayer(surfaceHolder, 0);
91 |
92 | }
93 |
94 | @Override
95 | public void surfaceDestroyed(SurfaceHolder surfaceHolder) {
96 | mRKMediaplayer.stop();
97 | }
98 | }
99 |
--------------------------------------------------------------------------------
/app/src/main/java/com/rockchip/rkmediacodecdemo/PortScanner.java:
--------------------------------------------------------------------------------
1 | package com.rockchip.rkmediacodecdemo;
2 |
3 |
4 | import android.os.Handler;
5 | import android.util.Log;
6 |
7 | import java.io.IOException;
8 | import java.net.InetAddress;
9 | import java.net.InetSocketAddress;
10 | import java.net.InterfaceAddress;
11 | import java.net.NetworkInterface;
12 | import java.net.Socket;
13 | import java.net.SocketAddress;
14 | import java.net.SocketException;
15 | import java.util.Enumeration;
16 |
17 | /**
18 | * Created by cxh on 2017/7/31.
19 | */
20 |
21 | public class PortScanner {
22 |
23 | private static final String TAG = "ContentValues";
24 | private static final boolean netdebug = false;
25 | private static final boolean DEBUG = true;
26 | private static int bindPort = 33333;
27 | Handler handler;
28 |
29 | public PortScanner() {
30 | }
31 |
32 | /**
33 | * 传入当前的handler
34 | *
35 | * @param handler handler
36 | */
37 |
38 |
39 | /**
40 | * 获取本机的IP
41 | *
42 | * @return Ip地址
43 | */
44 | public String getLocalHostIP() {
45 | String ip;
46 | try {
47 | /**返回本地主机。*/
48 | InetAddress addr = InetAddress.getLocalHost();
49 | /**返回 IP 地址字符串(以文本表现形式)*/
50 | ip = addr.getHostAddress();
51 | } catch (Exception ex) {
52 | ip = "";
53 | }
54 | return ip;
55 | }
56 |
57 | /**
58 | * 获取广播地址
59 | *
60 | * @return 广播地址
61 | */
62 | public String getBroadcast() throws SocketException {
63 | System.setProperty("java.net.preferIPv4Stack", "true");
64 | for (Enumeration niEnum = NetworkInterface.getNetworkInterfaces(); niEnum.hasMoreElements(); ) {
65 | NetworkInterface ni = niEnum.nextElement();
66 | if (!ni.isLoopback()) {
67 | for (InterfaceAddress interfaceAddress : ni.getInterfaceAddresses()) {
68 | if (interfaceAddress.getBroadcast() != null) {
69 | return interfaceAddress.getBroadcast().toString().substring(1);
70 | }
71 | }
72 | }
73 | }
74 | return "";
75 | }
76 |
77 |
78 |
79 | /**
80 | * 寻找一个可用的端口
81 | *
82 | * @return 可用的端口号
83 | */
84 | public synchronized static int StartLocalPort() {
85 | int AvailablePort = bindPort;
86 | while (true) {
87 | bindPort++;
88 | AvailablePort = bindPort;
89 | if (isPortAvailable(bindPort)) ;
90 | {
91 | bindPort++;
92 | if (isPortAvailable(bindPort)) ;
93 | {
94 | break;
95 | }
96 | }
97 | }
98 | bindPort += 100;
99 | return AvailablePort;
100 | }
101 |
102 | /**
103 | * 绑定本机指定端口和IP地址(绑定失败抛出异常)
104 | *
105 | * @param host 待扫描IP
106 | * @param port 待扫描端口
107 | */
108 | private static void bindPort(String host, int port) throws Exception {
109 | Socket s = new Socket();
110 | s.bind(new InetSocketAddress(host, port));
111 | s.close();
112 | }
113 |
114 | /**
115 | * 检测本机传入的端口是否被占用
116 | *
117 | * @param port 待扫描端口
118 | * @return 是否被占用
119 | */
120 | private static boolean isPortAvailable(int port) {
121 | try {
122 | bindPort("0.0.0.0", port);
123 | bindPort(InetAddress.getLocalHost().getHostAddress(), port);
124 | return true;
125 | } catch (Exception e) {
126 | return false;
127 | }
128 | }
129 |
130 | /**
131 | * 检测将要连接的IP端口是否可用
132 | *
133 | * @param ip 待加测的IP
134 | * @param Port 待检测的端口
135 | * @param timeout 连接超时时间
136 | * @return 是否被占用
137 | */
138 | private boolean TCPPortIsUsable(String ip, int Port, int timeout) {
139 |
140 | try {
141 | Socket socket;
142 | SocketAddress socketAddress;
143 |
144 | socket = new Socket();
145 | socketAddress = new InetSocketAddress(ip, Port);
146 | socket.connect(socketAddress, timeout);
147 | socket.close();
148 | } catch (IOException e) {
149 | Log.d(TAG, "IP: " + ip + " 端口:" + Port + " 关闭");
150 | return false;
151 | }
152 | return true;
153 | }
154 | }
155 |
--------------------------------------------------------------------------------
/app/src/main/java/com/rockchip/rkmediacodecdemo/rtsp/AACPackage.java:
--------------------------------------------------------------------------------
1 | package com.rockchip.rkmediacodecdemo.rtsp;
2 |
3 | import java.io.IOException;
4 |
5 | /**
6 | * Created by zhanghao on 2017/1/6.
7 | */
8 |
9 | public class AACPackage {
10 | public byte[] ADTS = {(byte)0xFF, (byte)0xF1, 0x00, 0x00, 0x00, 0x00, (byte)0xFC};
11 | public int AU_HEADER_LENGTH = 2;
12 | public byte[] data;
13 |
14 | public AACPackage() {
15 |
16 | }
17 |
18 | public AACPackage(int samplerate, int channel, int bit) {
19 | switch(samplerate)
20 | {
21 | case 16000:
22 | ADTS[2] = 0x60;
23 | break;
24 | case 32000:
25 | ADTS[2] = 0x54;
26 | break;
27 | case 44100:
28 | ADTS[2] = 0x50;
29 | break;
30 | case 48000:
31 | ADTS[2] = 0x4C;
32 | break;
33 | case 96000:
34 | ADTS[2] = 0x40;
35 | break;
36 | default:
37 | break;
38 | }
39 | ADTS[3] = (channel==2)?(byte)0x80:0x40;
40 | }
41 |
42 | public AACPackage getCompleteAACPackage(RTPPackage rtp) throws IOException {
43 | AACPackage aac = new AACPackage(44100, 2, 16); // TODO:: audio format
44 | aac.AU_HEADER_LENGTH = 2;//(rtp.csrc[0]&0xFF)<<8 | (rtp.csrc[1]&0xFF);
45 | //if (aac.AU_HEADER_LENGTH != 2) throw new IOException("unknown AU_HEADER_LENGTH!" + rtp.csrc[0] + ":" + rtp.csrc[1]);
46 | final int len = rtp.csrc.length - 2 - aac.AU_HEADER_LENGTH + aac.ADTS.length;
47 | int plen = (len << 5)|0x1F;
48 | aac.ADTS[4] = (byte)(plen >> 8);
49 | aac.ADTS[5] = (byte)(plen&0xFF);
50 | //aac.data = new byte[len];
51 | //System.arraycopy(aac.ADTS, 0, aac.data, 0, aac.ADTS.length);
52 | //System.arraycopy(rtp.csrc, 2 + aac.AU_HEADER_LENGTH, aac.data, aac.ADTS.length, rtp.csrc.length - 2 - aac.AU_HEADER_LENGTH);
53 |
54 | aac.data = new byte[len-aac.ADTS.length];
55 | System.arraycopy(rtp.csrc, 2 + aac.AU_HEADER_LENGTH, aac.data, 0, rtp.csrc.length - 2 - aac.AU_HEADER_LENGTH);
56 | return aac;
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/app/src/main/java/com/rockchip/rkmediacodecdemo/rtsp/H264Package.java:
--------------------------------------------------------------------------------
1 | package com.rockchip.rkmediacodecdemo.rtsp;
2 |
3 | import android.util.Log;
4 |
5 | import java.util.ArrayDeque;
6 | import java.util.ArrayList;
7 | import java.util.List;
8 | import java.util.Queue;
9 |
10 | /**
11 | * Created by zhanghao on 2017/1/2.
12 | */
13 |
14 | public class H264Package {
15 | private static final String TAG = "H264Package";
16 | H264Package sLastH264Worker = null;
17 | List mNALU = null;
18 | Queue sCompleteH264Frame = new ArrayDeque<>(3);
19 |
20 | public H264Package() {
21 | mNALU = new ArrayList<>();
22 | }
23 |
24 | private void append(NALUnit unit) {
25 | mNALU.add(unit);
26 | }
27 |
28 | private boolean checkSN() {
29 | long last_sn = -1;
30 | for(int i=0; i. sendNALUnit: " + unit.first_mb_in_slice);
47 | //H264Package tmp = null;
48 | if (unit.nal_unit_type == 31) { /* Rockchip End Frame */
49 | // if (DefaultConfig.DEFAULT_DEBUG_DELAY)
50 | // Log.d(DefaultConfig.TAG, "----------------- END FRAME ----------------");
51 | // if(sLastH264Worker != null) {
52 | // sCompleteH264Frame.add(sLastH264Worker);
53 | // }
54 | sLastH264Worker = null;
55 | } else if (unit.first_mb_in_slice == 0) {
56 | //tmp = sLastH264Worker;
57 | if(sLastH264Worker != null) {
58 | sCompleteH264Frame.add(sLastH264Worker);
59 | //Log.d("Rockchip", ">.0 sCompleteH264Frame add " + sLastH264Worker);
60 | }
61 | sLastH264Worker = new H264Package();
62 | sLastH264Worker.append(unit);
63 | } else if (unit.first_mb_in_slice == -1) {
64 | //ret = sLastH264Worker;
65 | if(sLastH264Worker != null) {
66 | sCompleteH264Frame.add(sLastH264Worker);
67 | //Log.d("Rockchip", ">.-1 sCompleteH264Frame add " + sLastH264Worker);
68 | }
69 | sLastH264Worker = new H264Package();
70 | sLastH264Worker.append(unit);
71 | sCompleteH264Frame.add(sLastH264Worker);
72 | //Log.d("Rockchip", ">.-1+ sCompleteH264Frame add " + sLastH264Worker);
73 | sLastH264Worker = null;
74 | } else {
75 | if (sLastH264Worker != null)
76 | sLastH264Worker.append(unit);
77 | else
78 | Log.w(TAG, "Got a broken 264 package !");
79 | }
80 | }
81 |
82 | public H264Package getCompleteH264() {
83 | H264Package ret = sCompleteH264Frame.poll();
84 | //Log.d("Rockchip", ">. getCompleteH264 poll: " + ret);
85 | return ret;
86 | }
87 |
88 |
89 | public byte[] getBytes() {
90 | int size = 0;
91 | for (NALUnit unit: mNALU) {
92 | size += unit.getLength();
93 | }
94 |
95 | byte[] bytes = new byte[size];
96 | int offset = 0;
97 | for (int i=0; i mFUADataWorker = null;
37 | /*
38 | * 取一段码流分析如下:
39 | 80 60 01 0f 00 0e 10 00 00 00 00 00 7c 85 88 82 €`..........|???
40 | 00 0a 7f ca 94 05 3b 7f 3e 7f fe 14 2b 27 26 f8 ...??.;.>.?.+'&?
41 | 89 88 dd 85 62 e1 6d fc 33 01 38 1a 10 35 f2 14 ????b?m?3.8..5?.
42 | 84 6e 21 24 8f 72 62 f0 51 7e 10 5f 0d 42 71 12 ?n!$?rb?Q~._.Bq.
43 | 17 65 62 a1 f1 44 dc df 4b 4a 38 aa 96 b7 dd 24 .eb??D??KJ8????$
44 |
45 | 前12字节是RTP Header
46 | 7c是FU indicator
47 | 85是FU Header
48 | FU indicator(0x7C)和FU Header(0x85)换成二进制如下
49 | 0111 1100 1000 0101
50 | 按顺序解析如下:
51 | 0 是F
52 | 11 是NRI
53 | 11100 是FU Type,这里是28,即FU-A
54 |
55 | 1 是S,Start,说明是分片的第一包
56 | 0 是E,End,如果是分片的最后一包,设置为1,这里不是
57 | 0 是R,Remain,保留位,总是0
58 | 00101 是NAl Type,这里是5,说明是关键帧
59 | * */
60 | /* 分片单元指示
61 | NALU_HEADER
62 | +---------------+
63 | |0|1|2|3|4|5|6|7|
64 | +-+-+-+-+-+-+-+-+
65 | |F|NRI| Type |
66 | +---------------+*/
67 |
68 | /* 分片单元头
69 | FU_HEADER
70 | +---------------+
71 | |0|1|2|3|4|5|6|7|
72 | +-+-+-+-+-+-+-+-+
73 | |S|E|R| Type |
74 | +---------------+*/
75 | public NALUnit parseHeader(RTPPackage rtp) throws IOException {
76 | NALUnit unit = new NALUnit();
77 | unit.nal_unit_type = rtp.csrc[0]&0x1F;
78 |
79 | if (unit.nal_unit_type == NALU_HEADER_TYPE_SLICE_NON_IDR ||
80 | unit.nal_unit_type == NALU_HEADER_TYPE_SLICE_IDR) {
81 | unit.first_mb_in_slice = getExpGolomb(rtp.csrc[1]);
82 | } else if (unit.nal_unit_type == NALU_HEADER_TYPE_FU_A) {
83 | unit.fu_isStart = (rtp.csrc[1]&0x80) != 0;
84 | unit.fu_isEnd = (rtp.csrc[1]&0x40) !=0;
85 | unit.fua_nal_unit_type = rtp.csrc[1]&0x1F;
86 | if (unit.fua_nal_unit_type == NALU_HEADER_TYPE_SLICE_NON_IDR ||
87 | unit.fua_nal_unit_type == NALU_HEADER_TYPE_SLICE_IDR) {
88 | unit.fua_first_mb_in_slice = getExpGolomb(rtp.csrc[2]);
89 | }
90 | }
91 | return unit;
92 | }
93 |
94 | private void filldata(byte[] buf, int startFlagLength) throws IOException {
95 | data = new byte[buf.length + startFlagLength];
96 | for (int f=0; f();
113 | mFUADataWorker.add(unit);
114 | return null;
115 | } else if (unit.fu_isEnd && !unit.fu_isStart) {
116 | if (mFUADataWorker == null) {
117 | return null;
118 | }
119 | mFUADataWorker.add(unit);
120 |
121 | int length = 5; // add 4byte start flag + NALU_header
122 | for (NALUnit b: mFUADataWorker) {
123 | length += (b.data.length-2); // reduce NALU_header & fua_header
124 | }
125 |
126 | // Log.d(TAG, "complexUnit.data.length:" + length + " mFUADataWorker.get(0).data[].length" + mFUADataWorker.get(0).data.length);
127 | NALUnit complexUnit = new NALUnit();
128 | complexUnit.nal_unit_type = unit.fua_nal_unit_type;
129 | complexUnit.first_mb_in_slice = mFUADataWorker.get(0).fua_first_mb_in_slice;
130 | complexUnit.data = new byte[length];
131 | complexUnit.data[0] = 0x0;
132 | complexUnit.data[1] = 0x0;
133 | complexUnit.data[2] = 0x0;
134 | complexUnit.data[3] = 0x1;
135 | complexUnit.data[4] = (byte)((mFUADataWorker.get(0).data[0] & 0xE0) | (mFUADataWorker.get(0).data[1] & 0x1F));
136 | //Log.d("Rockchip", ">> fua type:"+unit.fua_nal_unit_type + " ; 4: " + complexUnit.data[4]);
137 | complexUnit.sequece_number = ++sNALU_Sequece_Number; // set sNALU_Sequece_Number
138 | //Log.d(TAG," complexUnit.sequece_number = " + complexUnit.sequece_number);
139 |
140 | int offset = 5;
141 | long checkSequeceNum = -1;
142 | for (int i=0; i 0 && unit.nal_unit_type < 13) {
167 | return create(rtp);
168 | } else if (unit.nal_unit_type == 31){ /* Rockchip End Frame Flag */
169 | return create(rtp);
170 | } else {
171 | throw new IOException("unknown nalu type :"+unit.nal_unit_type);
172 | }
173 | }
174 |
175 | private NALUnit create(RTPPackage rtp) throws IOException {
176 | NALUnit unit = parseHeader(rtp);
177 | unit.sequece_number = ++sNALU_Sequece_Number; // set sNALU_Sequece_Number
178 | //Log.d(TAG," unit.sequece_number = " + unit.sequece_number);
179 |
180 | if (unit.first_mb_in_slice > 0){
181 | unit.filldata(rtp.csrc, NALU_START_FLAG_3);
182 | } else { /* 0 or -1*/
183 | unit.filldata(rtp.csrc, NALU_START_FLAG_4);
184 | }
185 | return unit;
186 | }
187 |
188 | public int getLength() {
189 | return data.length;
190 | }
191 |
192 | public int getExpGolomb(byte buf) {
193 | return (buf & 0x80) != 0 ? 0 : 1;
194 | }
195 | }
196 |
--------------------------------------------------------------------------------
/app/src/main/java/com/rockchip/rkmediacodecdemo/rtsp/RTCPPackage.java:
--------------------------------------------------------------------------------
1 | package com.rockchip.rkmediacodecdemo.rtsp;
2 |
3 | import java.util.Random;
4 |
5 | /**
6 | * Created by zhanghao on 2017/1/3.
7 | */
8 |
9 | public class RTCPPackage {
10 | private static final String TAG = "RTCPPackage";
11 |
12 | public static final byte RTCP_PAYLOAD_TYPE_SR = (byte)200; // Sender Report
13 | public static final byte RTCP_PAYLOAD_TYPE_RR = (byte)201; // Receiver Report
14 | public static final byte RTCP_PAYLOAD_TYPE_SDES = (byte)202; // Source Description
15 | public static final byte RTCP_PAYLOAD_TYPE_BYE = (byte)203; // Say Goodbye
16 |
17 | private byte mVP = (byte)0x80; // & 0xE0; // 1110 0000
18 | private byte mRC = (byte)0x01; // & 0x1F; // 0001 1111
19 | private byte mPT = 0;
20 | private byte mLength = 0;
21 | private int mHighestSequenceNum = 0;
22 | public long mLastSR = 0;
23 | public long mDelayLastSR = 0;
24 | public long mNtpTimestamp = 0;
25 |
26 | private int mSSRC0 = -1; // sender ssrc
27 | private int mSSRC1 = 0;
28 |
29 | public RTCPPackage create(byte pt, int ssrc, int lastsn, long lsr, long dlsr) {
30 | mSSRC1 = ssrc;
31 | RTCPPackage packet = new RTCPPackage();
32 | packet.mPT = pt;
33 | packet.mHighestSequenceNum = lastsn;
34 | packet.mLastSR = lsr;
35 | packet.mDelayLastSR = dlsr;
36 |
37 | if (mSSRC0 == -1) {
38 | Random rnd = new Random(System.currentTimeMillis());
39 | mSSRC0 = rnd.nextInt();
40 | }
41 |
42 | return packet;
43 | }
44 |
45 | public RTCPPackage parseSR(byte[] sr){
46 | RTCPPackage packet = new RTCPPackage();
47 | if(sr.length >= 14)
48 | packet.mNtpTimestamp = ((sr[10]&0xFF)<<24) | ((sr[11]&0xFF)<<16) | ((sr[12]&0xFF)<<8) | (sr[13]&0xFF);
49 | //if(sr.length >= 48)
50 | // packet.mLastSR = sr[44]<<24 | sr[45]<<16 | sr[46]<<8 | sr[47];
51 | //if(sr.length >= 52)
52 | // packet.mDelayLastSR = sr[48]<<24 | sr[49]<<16 | sr[50]<<8 | sr[51];
53 | return packet;
54 | }
55 |
56 | /* Sendor Report
57 | 0 1 2 3
58 | 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7
59 | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
60 | |V=2|P| RC | PT | length | 3
61 | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
62 | | SSRC of sender | 7
63 | +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
64 | | NTP timestamp, most significant word | 11
65 | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
66 | | NTP timestamp, least significant word | 15
67 | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
68 | | RTP timestampe | 19
69 | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
70 | | sender's packet count | 23
71 | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
72 | | sender's octet count | 27
73 | +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
74 | | SSRC_1 | 31
75 | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
76 | | fraction lost | cumulative number of packets lost | 35
77 | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
78 | | extended highest sequence number received | 39
79 | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
80 | | interarrival jitter | 43
81 | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
82 | | last SR (LSR) | 47
83 | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
84 | | delay since last SR (DLSR) | 51
85 | +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
86 | */
87 |
88 | /* Receiver Report
89 | 0 1 2 3
90 | 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7
91 | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
92 | |V=2|P| RC | PT | length | 3
93 | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
94 | | SSRC of sender | 7
95 | +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
96 | | SSRC_1 | 11
97 | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
98 | | fraction lost | cumulative number of packets lost | 15
99 | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
100 | | extended highest sequence number received | 19
101 | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
102 | | interarrival jitter | 23
103 | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
104 | | last SR (LSR) | 27
105 | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
106 | | delay since last SR (DLSR) | 31
107 | +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
108 | */
109 |
110 | /* Source Description
111 | 0 1 2 3
112 | 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7
113 | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
114 | |V=2|P| RC | PT | length | 3
115 | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
116 | | SSRC / CSRC_1 | 7
117 | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
118 | | SDES items | 11
119 | | ... |
120 | +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
121 | | ... |
122 | +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
123 |
124 | Items:
125 | 0 1 2 3
126 | 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7
127 | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
128 | | ITEM | length | content ...
129 | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
130 |
131 | CNAME=1
132 | NAME=2
133 | EMAIL=3
134 | PHONE=4
135 | LOC=5 // Location
136 | TOOL=6 // Client Tool
137 | NOTE=7
138 | PRIV=8
139 | */
140 |
141 | /* BYE
142 | 0 1 2 3
143 | 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7
144 | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
145 | |V=2|P| RC | PT | length | 3
146 | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
147 | | SSRC / CSRC_1 | 7
148 | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
149 | | ... |
150 | +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
151 | | length | reason for leaving |
152 | +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
153 | */
154 |
155 |
156 | public byte[] getRRBytes() {
157 | // Head :
158 | // SR/RR = 8byte
159 | // SDES = 4byte
160 | byte[] bytes = new byte[32];
161 | bytes[0] = (byte)((mVP&0xE0)|(mRC&0x1F));
162 | bytes[1] = mPT;
163 | bytes[2] = 0; // Length H16
164 | bytes[3] = (byte)(bytes.length/4-1); // Length L16 (32bit=1)
165 |
166 | // SSRC
167 | bytes[4] = (byte)((mSSRC0&0xFF000000) >> 24);
168 | bytes[5] = (byte)((mSSRC0&0x00FF0000) >> 16);
169 | bytes[6] = (byte)((mSSRC0&0x0000FF00) >> 8);
170 | bytes[7] = (byte)((mSSRC0&0x000000FF));
171 |
172 | // SSRC 1
173 | bytes[8] = (byte)((mSSRC1&0xFF000000) >> 24);
174 | bytes[9] = (byte)((mSSRC1&0x00FF0000) >> 16);
175 | bytes[10] = (byte)((mSSRC1&0x0000FF00) >> 8);
176 | bytes[11] = (byte)((mSSRC1&0x000000FF));
177 |
178 | // fraction lost
179 | bytes[12] = 0;
180 | // cumulative number of packets lost
181 | bytes[13] = (byte)0xFF;
182 | bytes[14] = (byte)0xFF;
183 | bytes[15] = (byte)0xFF;
184 |
185 | // extended highest sequence number received
186 | bytes[16] = (byte)((mHighestSequenceNum&0xFF000000) >> 24);
187 | bytes[17] = (byte)((mHighestSequenceNum&0x00FF0000) >> 16);
188 | bytes[18] = (byte)((mHighestSequenceNum&0x0000FF00) >> 8);
189 | bytes[19] = (byte)((mHighestSequenceNum&0x000000FF));
190 |
191 | // interarrival jitter // TODO::
192 | bytes[20] = 0x0;
193 | bytes[21] = 0x0;
194 | bytes[22] = 0x0;
195 | bytes[23] = 0x3E;
196 |
197 | // last SR
198 | bytes[24] = (byte)((mLastSR&0xFF000000) >> 24);
199 | bytes[25] = (byte)((mLastSR&0x00FF0000) >> 16);
200 | bytes[26] = (byte)((mLastSR&0x0000FF00) >> 8);
201 | bytes[27] = (byte)((mLastSR&0x000000FF));
202 |
203 | // delay since last SR
204 | bytes[28] = (byte)((mDelayLastSR&0xFF000000) >> 24);
205 | bytes[29] = (byte)((mDelayLastSR&0x00FF0000) >> 16);
206 | bytes[30] = (byte)((mDelayLastSR&0x0000FF00) >> 8);
207 | bytes[31] = (byte)((mDelayLastSR&0x000000FF));
208 | return bytes;
209 | }
210 |
211 | public byte[] getSDESBytes() {
212 | // TODO::
213 | byte[] bytes = new byte[32];
214 | bytes[0] = (byte)0x80;
215 | bytes[1] = RTCP_PAYLOAD_TYPE_SDES;
216 | bytes[2] = 0; // Length H16
217 | bytes[3] = (byte)(bytes.length/4-1); // Length L16 (32bit=1)
218 | return bytes;
219 | }
220 |
221 | public byte[] getBYEBytes() {
222 | byte[] bytes = new byte[8];
223 | bytes[0] = (byte)((mVP&0xE0)|(mRC&0x1F));
224 | bytes[1] = mPT;
225 | bytes[2] = 0; // Length H16
226 | bytes[3] = (byte)(bytes.length/4-1); // Length L16 (32bit=1)
227 |
228 | // SSRC
229 | bytes[4] = (byte)((mSSRC0&0xFF000000) >> 24);
230 | bytes[5] = (byte)((mSSRC0&0x00FF0000) >> 16);
231 | bytes[6] = (byte)((mSSRC0&0x0000FF00) >> 8);
232 | bytes[7] = (byte)((mSSRC0&0x000000FF));
233 | return bytes;
234 | }
235 | }
236 |
--------------------------------------------------------------------------------
/app/src/main/java/com/rockchip/rkmediacodecdemo/rtsp/RTPConnector.java:
--------------------------------------------------------------------------------
1 | package com.rockchip.rkmediacodecdemo.rtsp;
2 |
3 | import android.os.Handler;
4 | import android.os.HandlerThread;
5 | import android.util.Log;
6 |
7 | import java.io.IOException;
8 | import java.net.DatagramPacket;
9 | import java.net.DatagramSocket;
10 | import java.net.InetAddress;
11 | import java.net.SocketException;
12 | import java.net.UnknownHostException;
13 |
14 | /**
15 | * Created by zhanghao on 2016/12/29.
16 | */
17 |
18 | public class RTPConnector {
19 | private static final String TAG = "RTPConnector";
20 | private static final boolean DEBUG_NALU = false;
21 |
22 | private RTPType mRTPType = null;
23 | private RTPThread mRTPThread = null;
24 | private RTCPThread mRTCPThread = null;
25 |
26 | private boolean mIsTCP = false;
27 | private String mServerIP = "";
28 | private int mClientPort = 0;
29 | private int mServerPort = 0;
30 | private byte[] message = new byte[2048];
31 |
32 | private long mLastSequenceNum = -1;
33 | private int mServerSSRC = -1;
34 | private long mLastSR = 0;
35 | private long mLastTimestamp = 0;
36 | private long mLast264Timestamp = 0;
37 | private long mFirstPackageTimestamp = 0;
38 | private long mH264FrameDelay = 0;
39 | private long mH264FrameInterval = 0;
40 |
41 | private int mLostPackageCount = 0;
42 | private int mRecvPackageCount = 0;
43 | private long mLastestSequenceTime = 0;
44 | private long mBps = 0;
45 | private int[] mNaluTypeCount = {0,0,0,0,0,0,0,0,0,0};
46 |
47 | private OnFrameListener mOnFrameCallback = null;
48 |
49 | public enum RTPType { VIDEO, AUDIO }
50 |
51 | public RTPConnector(boolean isTCP, int clientPort, String serverIP, int serverPort, RTPType rtpType) {
52 | mIsTCP = isTCP;
53 | mClientPort = clientPort;
54 | mServerIP = serverIP;
55 | mServerPort = serverPort;
56 | mRTPType = rtpType;
57 | }
58 |
59 | public void connect() {
60 |
61 | if(mIsTCP) {
62 | Log.e(TAG, "unsupport tcp yet !");
63 | } else {
64 | mRTPThread = new RTPThread(mClientPort, mServerIP, mServerPort);
65 | mRTCPThread = new RTCPThread(mClientPort+1, mServerIP, mServerPort+1);
66 | mRTPThread.start();
67 | mRTCPThread.start();
68 | }
69 | }
70 |
71 | public void disconnect() {
72 | if (mRTPThread == null || mRTCPThread == null)
73 | return; // Already Disconnected
74 | Log.w(TAG, "RTP Connector disconnecting ...");
75 | mRTCPThread.sendReciveReport(RTCPPackage.RTCP_PAYLOAD_TYPE_BYE);
76 | try {
77 | mRTPThread.join();
78 | mRTCPThread.join();
79 | mRTPThread = null;
80 | mRTCPThread = null;
81 | } catch (InterruptedException e) {
82 | e.printStackTrace();
83 | }
84 | }
85 |
86 | public int getLostPackageCount() {
87 | return mLostPackageCount;
88 | }
89 | public int getRecvPackageCount() {return mRecvPackageCount;}
90 | public long getLastestSequeceTime() {return mLastestSequenceTime;}
91 | public long getH264FrameDelay() {long r = mH264FrameDelay;mH264FrameDelay = 0;return r;}
92 | public long getH264FrameInterval() {long r = mH264FrameInterval;mH264FrameInterval = 0;return r;}
93 | public long getH264Bps() {long r=mBps;mBps=0;return r;}
94 | public int[] getH264NaluTypeCount() {int[] r=mNaluTypeCount;mNaluTypeCount= new int[10];return r;}
95 | public void resetPackageCount() {mLostPackageCount = 0;mRecvPackageCount = 0;}
96 |
97 | private class RTPThread extends Thread {
98 | private int mLocalPort = 0;
99 | private int mRemotePort = 0;
100 | private String mSerIP = "";
101 | private volatile boolean mIsStop = false;
102 | private long recordTime = 0;
103 | private boolean mDbgIsComplete = false;
104 |
105 | private DatagramSocket mSocket;
106 | private DatagramPacket mPacket;
107 |
108 |
109 | public RTPThread(int localPort, String serverip, int serverPort){
110 | mLocalPort = localPort;
111 | mRemotePort = serverPort;
112 | mSerIP = serverip;
113 |
114 | try {
115 | mSocket = new DatagramSocket(mClientPort);
116 | mPacket = new DatagramPacket(message,message.length);
117 | } catch (SocketException e) {
118 | e.printStackTrace();
119 | }
120 | }
121 |
122 | public void exit(){
123 | Log.w(TAG, "RTP thread exiting ...");
124 | mIsStop = true;
125 | }
126 |
127 | public void disconnect() {
128 | mSocket.disconnect();
129 | mSocket.close();
130 | }
131 |
132 | @Override
133 | public void run() {
134 | RTPPackage rtppkg =new RTPPackage().create(mPacket.getData(), mPacket.getLength());
135 | // int size = 170*1024;
136 | while(!mIsStop) {
137 | long currentTime;
138 | try {
139 | if (mSocket.isClosed())
140 | return;
141 | mSocket.receive(mPacket);
142 | // if(DefaultConfig.DEFAULT_DEBUG_DELAY) Log.d(DefaultConfig.TAG, "1. recv a package: size:" + mPacket.getLength() + " : " + System.currentTimeMillis());
143 | rtppkg =rtppkg.create(mPacket.getData(), mPacket.getLength());
144 | ++mRecvPackageCount;
145 | mBps += mPacket.getLength();
146 | mLastestSequenceTime = rtppkg.timestamp;
147 | if (mServerSSRC != rtppkg.ssrc)
148 | mServerSSRC = rtppkg.ssrc;
149 | if(DEBUG_NALU) Log.d(TAG, "got rtp len:" + mPacket.getLength() + ";" + rtppkg.toString());
150 | if (rtppkg.sequenceNumber != mLastSequenceNum + 1 && mLastSequenceNum != -1) {
151 | Log.w(TAG, "lost RTP package !! last:" + mLastSequenceNum + " ; recv:"+rtppkg.sequenceNumber);
152 | // if(DefaultConfig.DEFAULT_DEBUG_DELAY) Log.e(DefaultConfig.TAG, "x. lost RTP package !! last:" + mLastSequenceNum + " ; recv:"+rtppkg.sequenceNumber);
153 | mLostPackageCount += (rtppkg.sequenceNumber-mLastSequenceNum-1);
154 | }
155 | mLastSequenceNum = rtppkg.sequenceNumber;
156 | //有些负载类型由于诞生的较晚,没有具体的PT值,只能使用动态(dynamic)PT值,即96到127,这就是为什么大家普遍指定H264的PT值为96。
157 | if (rtppkg.ptype >= RTPPackage.PTYPE_DYNAMIC_MIN && rtppkg.ptype <= RTPPackage.PTYPE_DYNAMIC_MAX) {
158 | // Log.d(TAG, "run: mRTPType = " +mRTPType);
159 | if(mRTPType!=null)
160 | switch (mRTPType) {
161 | case VIDEO:
162 | recoverH264Package(rtppkg);
163 | break;
164 | case AUDIO:
165 | recoverAACPackage(rtppkg);
166 | break;
167 | }
168 | } else {
169 | Log.w(TAG, "got a unknowable RTP package, type=" + rtppkg.ptype);
170 | }
171 |
172 | //RTCP START : every 10s send a rtcp packet to server
173 | currentTime = System.currentTimeMillis();
174 | if(currentTime - recordTime > 10000) {
175 | recordTime = currentTime;
176 | mRTCPThread.sendReciveReport(RTCPPackage.RTCP_PAYLOAD_TYPE_RR);
177 | }
178 | // RTCP END
179 | } catch (IOException e) {
180 | //e.printStackTrace();
181 | Log.e(TAG, "RTP Socket maybe exited !");
182 | }
183 | }
184 | Log.d(TAG, "RTPThread over !");
185 | }
186 |
187 | H264Package mH264Package = new H264Package();
188 | NALUnit mNALUnit = new NALUnit();
189 | private long test = 8;
190 | private void recoverH264Package(RTPPackage rtp) throws IOException {
191 | if(mDbgIsComplete) {
192 | mFirstPackageTimestamp = System.currentTimeMillis();
193 | mDbgIsComplete = false;
194 | }
195 | NALUnit nalu = mNALUnit.getCompleteNALUnit(rtp);
196 | // NALUnit tmpHeader = NALUnit.parseHeader(rtp); //没用到?
197 | /*Log.d(DefaultConfig.TAG, ">. get one NALU. type="+tmpHeader.nal_unit_type+";mb="+tmpHeader.first_mb_in_slice
198 | +";fu_type="+tmpHeader.fua_nal_unit_type+";fu_mb="+tmpHeader.fua_first_mb_in_slice
199 | +";fu_start?"+tmpHeader.fu_isStart+";fu_end?"+tmpHeader.fu_isEnd);*/
200 |
201 | if (nalu != null) {
202 | if(DEBUG_NALU) Log.d(TAG, "** get complete NALU frame ! **");
203 | H264Package h264frame = null;
204 | mH264Package.sendNALUnit(nalu);
205 | while((h264frame = mH264Package.getCompleteH264()) != null) {
206 | if (h264frame != null) {
207 | long currentTime = System.currentTimeMillis();
208 | mH264FrameInterval = Math.max(currentTime - mLast264Timestamp, mH264FrameInterval);
209 | mLast264Timestamp = currentTime;
210 | mH264FrameDelay = Math.max(currentTime - mFirstPackageTimestamp, mH264FrameDelay);
211 | mDbgIsComplete = true;
212 | mNaluTypeCount[h264frame.mNALU.get(0).nal_unit_type] += 1;
213 | //Log.d(TAG, "** get complete h264 frame ! **");
214 | if (mOnFrameCallback != null) {
215 | // if (DefaultConfig.DEFAULT_DEBUG_DELAY)
216 | // Log.e(DefaultConfig.TAG, "2. get a complete h264 frame:[" + h264frame.mNALU.get(0).nal_unit_type + "]: " + System.currentTimeMillis());
217 | mOnFrameCallback.OnFrame(h264frame.getBytes());
218 | //else Log.e(DefaultConfig.TAG, "*. skip");
219 | }
220 | } else {
221 | //Log.d(TAG, "** combining h264 frame ... **");
222 | }
223 | }
224 | } else {
225 | //Log.d(TAG, "** combining NALU frame ... **");
226 | }
227 | }
228 |
229 | AACPackage aac =new AACPackage();
230 | private void recoverAACPackage(RTPPackage rtp) throws IOException {
231 | aac = aac.getCompleteAACPackage(rtp);
232 | if (mOnFrameCallback != null)
233 | mOnFrameCallback.OnFrame(new AACPackage().getCompleteAACPackage(rtp).data);
234 | }
235 | }
236 |
237 | private class RTCPThread extends Thread {
238 | private HandlerThread mSenderThread;
239 | private Handler mSenderHandler;
240 | private DatagramSocket mSocket;
241 | private DatagramPacket mPacket;
242 | private volatile boolean mIsStop = false;
243 |
244 | private int mLocalPort = 0;
245 | private int mRemotePort = 0;
246 | private String mSerIP = "";
247 |
248 | public RTCPThread(int localPort, String serverip, int serverPort) {
249 | mLocalPort = localPort;
250 | mRemotePort = serverPort;
251 | mSerIP = serverip;
252 |
253 | mSenderThread = new HandlerThread("RTCHSender");
254 | mSenderThread.start();
255 | mSenderHandler = new Handler(mSenderThread.getLooper());
256 | try {
257 | mSocket = new DatagramSocket(mLocalPort);
258 | } catch (SocketException e) {
259 | e.printStackTrace();
260 | }
261 | mPacket = new DatagramPacket(message,message.length);
262 | }
263 |
264 | public void exit(){
265 | Log.w(TAG, "RTCP thread exiting ...");
266 | mIsStop = true;
267 | }
268 |
269 | public void disconnect() {
270 | mSocket.disconnect();
271 | mSocket.close();
272 | }
273 | RTCPPackage mRTCPPackage = new RTCPPackage();
274 | @Override
275 | public void run() {
276 | while(!mIsStop) {
277 | try {
278 | if (mSocket.isClosed())
279 | return;
280 | mSocket.receive(mPacket);
281 | RTCPPackage sr = mRTCPPackage.parseSR(mPacket.getData());
282 | //byte[] sr = mPacket.getData();
283 | mLastSR = sr.mNtpTimestamp;
284 | mLastTimestamp = (short) System.currentTimeMillis();
285 | Log.d(TAG, "RTCP recieve a SR package("+mPacket.getData().length+"): ntp="+sr.mNtpTimestamp);
286 | } catch (IOException e) {
287 | //e.printStackTrace();
288 | Log.e(TAG, "RTCP Socket maybe exited !");
289 | }
290 | }
291 | Log.d(TAG, "RTCPThread over !");
292 | }
293 |
294 | public void sendReciveReport(final byte ptype) {
295 | mSenderHandler.post(new Runnable() {
296 | @Override
297 | public void run() {
298 | Log.d(TAG, "Rtcp send report :"+ptype);
299 | sendReport(ptype);
300 | }
301 | });
302 | }
303 |
304 | private void sendReport(final byte ptype) {
305 | if (mServerSSRC == -1)
306 | return;
307 |
308 | long dlsr = (System.currentTimeMillis() - mLastTimestamp)/65536000;
309 | RTCPPackage packet = mRTCPPackage.create(ptype, mServerSSRC, (int)mLastSequenceNum, mLastSR, dlsr);
310 | try {
311 | if (ptype == RTCPPackage.RTCP_PAYLOAD_TYPE_RR) {
312 | byte[] rtcpRR = packet.getRRBytes();
313 | Log.d(TAG, "send RR, len:" + packet.getRRBytes().length + "| ssrc:" + mServerSSRC);
314 | mPacket = new DatagramPacket(rtcpRR, rtcpRR.length, InetAddress.getByName(mSerIP), mRemotePort);
315 | } else if (ptype == RTCPPackage.RTCP_PAYLOAD_TYPE_BYE) {
316 | byte[] rtcpBYE = packet.getBYEBytes();
317 | Log.d(TAG, "send BYE, len:" + packet.getBYEBytes().length + "| ssrc:" + mServerSSRC);
318 | mPacket = new DatagramPacket(rtcpBYE, rtcpBYE.length, InetAddress.getByName(mSerIP), mRemotePort);
319 | }
320 |
321 | mSocket.send(mPacket);
322 |
323 | if (ptype == RTCPPackage.RTCP_PAYLOAD_TYPE_BYE) {
324 | mRTCPThread.exit();
325 | mRTPThread.exit();
326 | mRTCPThread.disconnect();
327 | mRTPThread.disconnect();
328 | }
329 | } catch (UnknownHostException e) {
330 | e.printStackTrace();
331 | } catch (IOException e) {
332 | e.printStackTrace();
333 | }
334 | }
335 |
336 | }
337 |
338 | public interface OnFrameListener {
339 | void OnFrame(byte[] buffer);
340 | }
341 | public void setOnFrameListener(OnFrameListener listener) {
342 | mOnFrameCallback = listener;
343 | }
344 | }
345 |
--------------------------------------------------------------------------------
/app/src/main/java/com/rockchip/rkmediacodecdemo/rtsp/RTPPackage.java:
--------------------------------------------------------------------------------
1 | package com.rockchip.rkmediacodecdemo.rtsp;
2 |
3 | /**
4 | * Created by zhanghao on 2016/12/30.
5 | */
6 |
7 | public class RTPPackage {
8 | private static final String TAG = "RTPPackage";
9 |
10 | public static final int PTYPE_DYNAMIC_MIN = 96;
11 | public static final int PTYPE_DYNAMIC_MAX = 127;
12 |
13 | public byte ver;
14 | public byte pillow;
15 | public byte extend;
16 | public byte csrcCnt;
17 | public byte mark;
18 | public byte ptype;
19 | public int sequenceNumber;
20 | public long timestamp;
21 | public int ssrc;
22 | public byte[] csrc;
23 | /*
24 | ver 版本号(V):2比特,用来标志使用的RTP版本。
25 | pillow 填充位(P):1比特,如果该位置位,则该RTP包的尾部就包含附加的填充字节。
26 | extend 扩展位(X):1比特,如果该位置位的话,RTP固定头部后面就跟有一个扩展头部。
27 | csrcCnt CSRC计数器(CC):4比特,含有固定头部后面跟着的CSRC的数目。
28 | mark 标记位(M):1比特,该位的解释由配置文档(Profile)来承担.
29 | ptype 载荷类型(PT):7比特,标识了RTP载荷的类型。
30 | sequenceNumber 序列号(SN):16比特,发送方在每发送完一个RTP包后就将该域的值增加1,
31 | 接收方可以由该域检测包的丢失及恢复包序列。序列号的初始值是随机的。
32 | timestamp 时间戳:32比特,记录了该包中数据的第一个字节的采样时刻。在一次会话开始时,时间戳初始化成一个初始值。
33 | 即使在没有信号发送时,时间戳的数值也要随时间而不断地增加(时间在流逝嘛)。x`
34 | 时间戳是去除抖动和实现同步不可缺少的。
35 | ssrc 同步源标识符(SSRC):32比特,同步源就是指RTP包流的来源。在同一个RTP会话中不能有两个相同的SSRC值。
36 | 该标识符是随机选取的 RFC1889推荐了MD5随机算法。
37 | csrc 贡献源列表(CSRC List):0~15项,每项32比特,用来标志对一个RTP混合器产生的新包有贡献的所有RTP包的源。
38 | 由混合器将这些有贡献的SSRC标识符插入表中。SSRC标识符都被列出来,以便接收端能正确指出交谈双方的身份。
39 | */
40 |
41 | /*
42 | 0 1 2 3
43 | 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7
44 | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
45 | |V=2|P|X| CC |M| PT | sequence number |
46 | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
47 | | timestamp |
48 | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
49 | | synchronization source (SSRC) identifier |
50 | +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
51 | | contributing source (CSRC) identifiers |
52 | | .... |
53 | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
54 | */
55 | public RTPPackage create(byte[] buf, int size){
56 | RTPPackage rtpPack = new RTPPackage();
57 | // byte 0
58 | rtpPack.ver = (byte)((buf[0]&0xC0) >> 6);
59 | rtpPack.pillow = (byte)((buf[0]&0x20) >> 5);
60 | rtpPack.extend = (byte)((buf[0]&0x10) >> 4);
61 | rtpPack.csrcCnt = (byte)(buf[0]&0xF);
62 |
63 | // byte 1
64 | rtpPack.mark = (byte)((buf[1]&0x80) >> 7);
65 | rtpPack.ptype = (byte)(buf[1]&0x7F);
66 |
67 | // byte 2-3
68 | rtpPack.sequenceNumber = (((buf[2] & 0xFF) << 8) | (buf[3] & 0xFF));
69 |
70 | // byte 4
71 | rtpPack.timestamp = ((long)(buf[4] & 0xFF) << 24) | ((long)(buf[5]&0xFF) << 16) | ((long)(buf[6]&0xFF) << 8) | (long)(buf[7]&0xFF);
72 |
73 | // byte 5
74 | rtpPack.ssrc = ((buf[8]&0xFF) << 24) | ((buf[9]&0xFF) << 16) | ((buf[10]&0xFF) << 8) | (buf[11]&0xFF);
75 |
76 | // byte 6
77 | rtpPack.csrc = new byte[size-12];
78 | System.arraycopy(buf, 12, rtpPack.csrc, 0, size - 12);
79 |
80 | return rtpPack;
81 | }
82 |
83 | public String toString(){
84 | return "[V="+ver+" csrcCnt="+csrcCnt + " ptype="+ ptype +" sequence num="+sequenceNumber + " timestamp=" + timestamp + "]";
85 | }
86 | }
87 |
--------------------------------------------------------------------------------
/app/src/main/java/com/rockchip/rkmediacodecdemo/rtsp/RTSPConnector.java:
--------------------------------------------------------------------------------
1 | package com.rockchip.rkmediacodecdemo.rtsp;
2 |
3 | import android.os.Handler;
4 | import android.os.HandlerThread;
5 | import android.util.Log;
6 |
7 | import java.io.IOException;
8 | import java.io.InputStream;
9 | import java.io.OutputStream;
10 | import java.net.Socket;
11 | import java.util.HashMap;
12 | import java.util.Locale;
13 | import java.util.regex.Matcher;
14 | import java.util.regex.Pattern;
15 |
16 | /**
17 | * Created by zhanghao on 2016/12/28.
18 | */
19 |
20 | public class RTSPConnector {
21 | private static final String TAG = "RTSPConnector";
22 | private Socket mSocket = null;
23 | private InputStream mInputStream = null;
24 | private OutputStream mOutputStream = null;
25 | private int mCSeq = 1;
26 | private String mIP = null;
27 | private int mPort = 554;
28 | private String mFunc = null;
29 | private boolean mIsTCP = false;
30 |
31 | private HandlerThread mResponseThread = null;
32 | private Handler mResponseHandler = null;
33 |
34 | private RTPConnector mRTPConnect = null;
35 | private HashMap mHeaders = null;
36 | private String mSession = null;
37 | private boolean mHasAudioTrack = false;
38 | private boolean mHasVideoTrack = false;
39 | private boolean mDidSessionSet = false;
40 | private boolean mDidMediaScriptSet = false;
41 |
42 | private int mRTPClientPort = 0;
43 | private int mRTPServerPort = 0;
44 |
45 |
46 | private RTPConnector.OnFrameListener mOnFrameCallback = null;
47 |
48 | private final Pattern regexStatus = Pattern.compile("RTSP/\\d.\\d (\\d+) .+", Pattern.CASE_INSENSITIVE);
49 | private final Pattern regexHeader = Pattern.compile("(\\S+): (.+)", Pattern.CASE_INSENSITIVE);
50 | private final Pattern regexUDPTransport = Pattern.compile("client_port=(\\d+)-\\d+;server_port=(\\d+)-\\d+", Pattern.CASE_INSENSITIVE);
51 | private final Pattern regexTCPTransport = Pattern.compile("client_port=(\\d+)-\\d+;", Pattern.CASE_INSENSITIVE);
52 | private final Pattern regexSessionWithTimeout = Pattern.compile("(\\S+);timeout=(\\d+)", Pattern.CASE_INSENSITIVE);
53 | // private final Pattern regexSDPgetTrack1 = Pattern.compile("trackID=(\\d+)",Pattern.CASE_INSENSITIVE);
54 | // private final Pattern regexSDPgetTrack2 = Pattern.compile("control:(\\S+)",Pattern.CASE_INSENSITIVE);
55 | private final Pattern regexSDP_MediadeScript = Pattern.compile("m=(\\S+) .+", Pattern.CASE_INSENSITIVE);
56 | private final Pattern regexSDP_PacketizationMode = Pattern.compile("packetization-mode=(\\d);", Pattern.CASE_INSENSITIVE);
57 | private final Pattern regexSDP_SPS_PPS = Pattern.compile("sprop-parameter-sets=(\\S+),(\\S+)", Pattern.CASE_INSENSITIVE);
58 | private final Pattern regexSDP_Length = Pattern.compile("Content-length: (\\d+)", Pattern.CASE_INSENSITIVE);
59 | // private static final Pattern regexSDPstartFlag = Pattern.compile("v=(\\d)",Pattern.CASE_INSENSITIVE);
60 |
61 | public RTSPConnector(String IP, int port, String func) throws IOException {
62 | mIP = IP;
63 | mPort= port;
64 | mFunc = func;
65 |
66 | mSocket = new Socket(IP, port);
67 | mInputStream = mSocket.getInputStream();
68 | mOutputStream = mSocket.getOutputStream();
69 |
70 | mResponseThread = new HandlerThread(TAG+"Rep");
71 | mResponseThread.start();
72 | mResponseHandler = new Handler(mResponseThread.getLooper());
73 |
74 | mHeaders = new HashMap<>();
75 | }
76 |
77 | public byte[] recvMsg(InputStream inpustream) {
78 | try {
79 | byte len[] = new byte[2048];
80 | int count = inpustream.read(len);
81 | if(count<=0)
82 | return null;
83 | byte[] temp = new byte[count];
84 | for (int i = 0; i < count; i++) {
85 | temp[i] = len[i];
86 | }
87 | return temp;
88 | } catch (IOException e) {
89 | e.printStackTrace();
90 | }
91 | return null;
92 | }
93 | private String getHeaders() {
94 | return "CSeq: " + (++mCSeq) + "\r\n"
95 | + "User-Agent: RockchipRtspClient("+"1.0"+") \r\n"
96 | + ((mSession == null)?"":("Session: " + mSession + "\r\n"));
97 | //+ "\r\n";
98 | }
99 |
100 | public void requestOptions() throws IOException {
101 | String request = "OPTIONS rtsp://" + mIP + ":" + mPort + "/" + mFunc + " RTSP/1.0\r\n" + getHeaders() + "\r\n";
102 | Log.d(TAG, ">> " + request);
103 | mOutputStream.write(request.getBytes("UTF-8"));
104 | mOutputStream.flush();
105 | parseResponse();
106 |
107 |
108 | }
109 |
110 | public void requestDescribe() throws IOException {
111 | String request = "DESCRIBE rtsp://" + mIP + ":" + mPort + "/" + mFunc + " RTSP/1.0\r\n" + getHeaders()
112 | + "Accept: application/sdp\r\n" + "\r\n";
113 | Log.d(TAG, ">> " + request);
114 | mOutputStream.write(request.getBytes("UTF-8"));
115 | mOutputStream.flush();
116 | parseResponse();
117 | }
118 |
119 | public void requestSetup(String track, int clientport) throws IOException {
120 | Matcher matcher;
121 | String request = "SETUP rtsp://" + mIP + "/" + mFunc + "/" + track +" RTSP/1.0\r\n"
122 | + getHeaders()
123 | + "Transport: RTP/AVP/"+ (mIsTCP?"TCP":"UDP") + ";unicast;client_port="+clientport+"-"+(clientport+1) + "\r\n"
124 | + "\r\n";
125 | Log.d(TAG, ">> " + request);
126 | mOutputStream.write(request.getBytes("UTF-8"));
127 | mOutputStream.flush();
128 |
129 | //wait(mDidSessionSet,"mDidSessionSet");
130 | while(!mDidSessionSet){
131 | try {
132 | parseResponse();
133 | Thread.sleep(10);
134 | //Log.d(TAG, "wait mDidSessionSet:" + mDidSessionSet);
135 | } catch (InterruptedException e) {
136 | e.printStackTrace();
137 | }
138 | }
139 |
140 | matcher = regexSessionWithTimeout.matcher(mHeaders.get("session"));
141 | if(matcher.find()) {
142 | mSession = matcher.group(1);
143 | }
144 | else {
145 | mSession = mHeaders.get("session");
146 | }
147 | Log.d(TAG, "the session is " + mSession);
148 |
149 | Log.d(TAG, "requestSetup: mHeaders" + mHeaders.toString());
150 | try {
151 | if(mIsTCP) matcher = regexTCPTransport.matcher(mHeaders.get("transport"));
152 | else matcher = regexUDPTransport.matcher(mHeaders.get("transport"));
153 | }catch (NullPointerException e){
154 | e.printStackTrace();
155 | }
156 | if(matcher.find()) {
157 | Log.d(TAG, "The client port is:" + matcher.group(1) + " ,the server prot is:" + (mIsTCP?"null":matcher.group(2)) + "...");
158 | mRTPClientPort = Integer.parseInt(matcher.group(1));
159 | if(!mIsTCP) mRTPServerPort = Integer.parseInt(matcher.group(2));
160 | //prepare for the decoder
161 | //wait(mDidMediaScriptSet,"mDidMediaScriptSet");
162 | while(!mDidMediaScriptSet){
163 | try {
164 | Thread.sleep(10);
165 | //Log.d(TAG, "wait mDidMediaScriptSet:" + mDidMediaScriptSet);
166 | } catch (InterruptedException e) {
167 | e.printStackTrace();
168 | }
169 | }
170 | RTPConnector.RTPType rtpType = null;
171 | Log.d(TAG, "requestSetup: mHasVideoTrack = "+mHasVideoTrack);
172 | Log.d(TAG, "requestSetup: mHasAudioTrack = "+mHasAudioTrack);
173 | if (mHasVideoTrack ) rtpType = RTPConnector.RTPType.VIDEO;
174 | else if(mHasAudioTrack ) rtpType = RTPConnector.RTPType.AUDIO;
175 | else Log.e(TAG, "unsupport multi track !");
176 | Log.d(TAG, "Create Socket from client :"+mRTPClientPort+" to server:"+mIP+":"+mRTPServerPort);
177 | mRTPConnect = new RTPConnector(mIsTCP, mRTPClientPort, mIP, mRTPServerPort, rtpType);
178 | mRTPConnect.setOnFrameListener(mOnFrameCallback);
179 | mRTPConnect.connect();
180 | } else {
181 | Log.e(TAG, "transport setting no found !");
182 | }
183 | }
184 |
185 | public void requestPlay() throws IOException {
186 | String request = "PLAY rtsp://" + mIP + ":" + mPort + "/" + mFunc + "/ RTSP/1.0\r\n"
187 | + getHeaders()
188 | + "Range: npt=0.000-\r\n"
189 | + "\r\n";
190 | Log.d(TAG, ">> " + request);
191 | mOutputStream.write(request.getBytes("UTF-8"));
192 | mOutputStream.flush();
193 | parseResponse();
194 | }
195 |
196 | public void requestGetParameter() throws IOException {
197 | String request = "GET_PARAMETER rtsp://" + mIP + ":" + mPort + "/" + mFunc + "/ RTSP/1.0\r\n"
198 | + getHeaders() + "\r\n";
199 | Log.d(TAG, ">> " + request);
200 | mOutputStream.write(request.getBytes("UTF-8"));
201 | mOutputStream.flush();
202 | parseResponse();
203 | }
204 |
205 | public void requestTeardown(String track) throws IOException {
206 | String request = "TEARDOWN rtsp://" + mIP + "/" + mFunc + "/" + track + " RTSP/1.0\r\n" + getHeaders() + "\r\n";
207 | Log.d(TAG, ">> " + request);
208 | mOutputStream.write(request.getBytes("UTF-8"));
209 | mOutputStream.flush();
210 | }
211 |
212 | public void parseResponse(/*InputStream input*/) throws IOException {
213 | // BufferedReader bufferReader = new BufferedReader(new InputStreamReader(input));
214 |
215 | String line;
216 | Matcher matcher;
217 | int state = -1;
218 |
219 | int sdpContentLength = 0;
220 | int packetizationMode = 0;
221 | String SPS = "";
222 | String PPS = "";
223 |
224 | // 接受服务器的信息
225 | // while (true) {
226 | byte[] by = recvMsg(mInputStream);
227 | if (by == null) {
228 | return;
229 | }
230 |
231 | try {
232 | line = new String(by);
233 |
234 | String[] sArray = line.split("\r\n");
235 | for (int i = 0; i < sArray.length; i++) {
236 |
237 | Log.d(TAG, "-----------------------i" + i + ":" + sArray[i].toString());
238 | // while ( (file_dialog_item = bufferReader.readLine()) != null) {
239 | Log.d(TAG, "<< " + sArray[i]);
240 |
241 | /* GET STATUS */
242 | matcher = regexStatus.matcher(sArray[i]);
243 | if (matcher.find()) {
244 | state = Integer.parseInt(matcher.group(1));
245 | // Log.d(TAG, "++ [STATUS = "+state+"]");
246 | }
247 |
248 | /* GET HEADER */
249 | matcher = regexHeader.matcher(sArray[i]);
250 | if (matcher.find()) {
251 | String key = matcher.group(1).toLowerCase(Locale.US);
252 | String value = matcher.group(2);
253 | mHeaders.put(key, value);
254 | // Log.d(TAG, "++ [HEADER] "+ key + " : " + value);
255 |
256 | if (key.equals("session")) {
257 | mDidSessionSet = true;
258 | Log.d(TAG, "session set !" + mDidSessionSet);
259 | }
260 | }
261 |
262 | /* GET SDP length */
263 | matcher = regexSDP_Length.matcher(sArray[i]);
264 | if (matcher.find()) {
265 | sdpContentLength = Integer.parseInt(matcher.group(1));
266 | // Log.d(TAG, "++ [SDP LENGTH]");
267 | }
268 |
269 | /* GET SDP MediaScript */
270 | matcher = regexSDP_MediadeScript.matcher(sArray[i]);
271 | if (matcher.find()) {
272 | if (matcher.group(1).equalsIgnoreCase("audio")) {
273 | mHasAudioTrack = true;
274 | mDidMediaScriptSet = true;
275 | } else if (matcher.group(1).equalsIgnoreCase("video")) {
276 | mHasVideoTrack = true;
277 | mDidMediaScriptSet = true;
278 | }
279 | // Log.d(TAG, "++ [SDP MEDIASCRIPT]" + matcher.group(1));
280 | }
281 |
282 | mHasVideoTrack = true;
283 | /* GET SDP Packetization Mode */
284 | matcher = regexSDP_PacketizationMode.matcher(sArray[i]);
285 | if (matcher.find()) {
286 | packetizationMode = Integer.parseInt(matcher.group(1));
287 | // Log.d(TAG, "++ [SDP PacketizationMode]" + packetizationMode);
288 | }
289 |
290 | /* GET SDP SPS PPS */
291 | matcher = regexSDP_SPS_PPS.matcher(sArray[i]);
292 | if (matcher.find()) {
293 | SPS = matcher.group(1);
294 | PPS = matcher.group(2);
295 | // Log.d(TAG, "++ [SDP SPS PPS]");
296 | }
297 | }
298 | // break;
299 | }catch (Exception e){
300 | e.printStackTrace();
301 | Log.d(TAG, "run Thread::解析Socket数据异常!!!!!!!!!!!!!!!" );
302 | }
303 |
304 | // }
305 |
306 | Log.w(TAG, "== Connection lost");
307 | }
308 |
309 | public void disconnect() {
310 | if(mRTPConnect != null)
311 | mRTPConnect.disconnect();
312 | }
313 |
314 | /*private void wait(Boolean sth, String debug){
315 | while(!sth){
316 | try {
317 | Thread.sleep(1000);
318 | Log.d(TAG, "wait .." + debug + ":" + sth);
319 | } catch (InterruptedException e) {
320 | e.printStackTrace();
321 | }
322 | }
323 | }*/
324 |
325 | public void setOnFrameListener(RTPConnector.OnFrameListener listener) {
326 | mOnFrameCallback = listener;
327 | }
328 |
329 | public int getLostPackageCount(){
330 | if (mRTPConnect != null)
331 | return mRTPConnect.getLostPackageCount();
332 | else
333 | return 0;
334 | }
335 | public int getRecvPackageCount(){
336 | if (mRTPConnect != null)
337 | return mRTPConnect.getRecvPackageCount();
338 | else
339 | return 0;
340 | }
341 | public long getLastestTimestamp(){
342 | if (mRTPConnect != null)
343 | return mRTPConnect.getLastestSequeceTime();
344 | else
345 | return 0;
346 | }
347 | public void resetPackageCount(){
348 | if (mRTPConnect != null)
349 | mRTPConnect.resetPackageCount();
350 | }
351 |
352 | public long getH264FrameDelay(){
353 | if (mRTPConnect != null)
354 | return mRTPConnect.getH264FrameDelay();
355 | else
356 | return 0;
357 | }
358 | public long getH264FrameInterval(){
359 | if (mRTPConnect != null)
360 | return mRTPConnect.getH264FrameInterval();
361 | else
362 | return 0;
363 | }
364 | public long getH264Bps() {
365 | if (mRTPConnect != null)
366 | return mRTPConnect.getH264Bps();
367 | else
368 | return 0;
369 | }
370 | public int[] getH264NaluTypeCount(){
371 | if (mRTPConnect != null)
372 | return mRTPConnect.getH264NaluTypeCount();
373 | else
374 | return new int[10];
375 | }
376 | }
377 |
--------------------------------------------------------------------------------
/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/res/drawable/ic_launcher_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
10 |
15 |
20 |
25 |
30 |
35 |
40 |
45 |
50 |
55 |
60 |
65 |
70 |
75 |
80 |
85 |
90 |
95 |
100 |
105 |
110 |
115 |
120 |
125 |
130 |
135 |
140 |
145 |
150 |
155 |
160 |
165 |
170 |
171 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
12 |
13 |
19 |
20 |
26 |
27 |
31 |
32 |
33 |
38 |
39 |
43 |
44 |
45 |
46 |
52 |
53 |
59 |
60 |
64 |
65 |
66 |
71 |
72 |
76 |
77 |
78 |
79 |
85 |
86 |
87 |
--------------------------------------------------------------------------------
/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/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/c-xh/RKMediaCodecDemo/38b85b3c160bf58f2237d5f49b601c1636d484a5/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/c-xh/RKMediaCodecDemo/38b85b3c160bf58f2237d5f49b601c1636d484a5/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/c-xh/RKMediaCodecDemo/38b85b3c160bf58f2237d5f49b601c1636d484a5/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/c-xh/RKMediaCodecDemo/38b85b3c160bf58f2237d5f49b601c1636d484a5/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/c-xh/RKMediaCodecDemo/38b85b3c160bf58f2237d5f49b601c1636d484a5/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/c-xh/RKMediaCodecDemo/38b85b3c160bf58f2237d5f49b601c1636d484a5/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/c-xh/RKMediaCodecDemo/38b85b3c160bf58f2237d5f49b601c1636d484a5/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/c-xh/RKMediaCodecDemo/38b85b3c160bf58f2237d5f49b601c1636d484a5/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/c-xh/RKMediaCodecDemo/38b85b3c160bf58f2237d5f49b601c1636d484a5/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/c-xh/RKMediaCodecDemo/38b85b3c160bf58f2237d5f49b601c1636d484a5/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | RKMediaCodecDemo
3 |
4 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/test/java/com/rockchip/rkmediacodecdemo/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.rockchip.rkmediacodecdemo;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest {
13 | @Test
14 | public void addition_isCorrect() throws Exception {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 |
5 | repositories {
6 | google()
7 | jcenter()
8 | }
9 | dependencies {
10 | classpath 'com.android.tools.build:gradle:3.0.1'
11 |
12 |
13 | // NOTE: Do not place your application dependencies here; they belong
14 | // in the individual module build.gradle files
15 | }
16 | }
17 |
18 | allprojects {
19 | repositories {
20 | google()
21 | jcenter()
22 | }
23 | }
24 |
25 | task clean(type: Delete) {
26 | delete rootProject.buildDir
27 | }
28 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | org.gradle.jvmargs=-Xmx1536m
13 |
14 | # When configured, Gradle will run in incubating parallel mode.
15 | # This option should only be used with decoupled projects. More details, visit
16 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
17 | # org.gradle.parallel=true
18 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/c-xh/RKMediaCodecDemo/38b85b3c160bf58f2237d5f49b601c1636d484a5/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Tue Jan 09 09:24:00 CST 2018
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-4.1-all.zip
7 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # Attempt to set APP_HOME
46 | # Resolve links: $0 may be a link
47 | PRG="$0"
48 | # Need this for relative symlinks.
49 | while [ -h "$PRG" ] ; do
50 | ls=`ls -ld "$PRG"`
51 | link=`expr "$ls" : '.*-> \(.*\)$'`
52 | if expr "$link" : '/.*' > /dev/null; then
53 | PRG="$link"
54 | else
55 | PRG=`dirname "$PRG"`"/$link"
56 | fi
57 | done
58 | SAVED="`pwd`"
59 | cd "`dirname \"$PRG\"`/" >/dev/null
60 | APP_HOME="`pwd -P`"
61 | cd "$SAVED" >/dev/null
62 |
63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
64 |
65 | # Determine the Java command to use to start the JVM.
66 | if [ -n "$JAVA_HOME" ] ; then
67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
68 | # IBM's JDK on AIX uses strange locations for the executables
69 | JAVACMD="$JAVA_HOME/jre/sh/java"
70 | else
71 | JAVACMD="$JAVA_HOME/bin/java"
72 | fi
73 | if [ ! -x "$JAVACMD" ] ; then
74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
75 |
76 | Please set the JAVA_HOME variable in your environment to match the
77 | location of your Java installation."
78 | fi
79 | else
80 | JAVACMD="java"
81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
82 |
83 | Please set the JAVA_HOME variable in your environment to match the
84 | location of your Java installation."
85 | fi
86 |
87 | # Increase the maximum file descriptors if we can.
88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
89 | MAX_FD_LIMIT=`ulimit -H -n`
90 | if [ $? -eq 0 ] ; then
91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
92 | MAX_FD="$MAX_FD_LIMIT"
93 | fi
94 | ulimit -n $MAX_FD
95 | if [ $? -ne 0 ] ; then
96 | warn "Could not set maximum file descriptor limit: $MAX_FD"
97 | fi
98 | else
99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
100 | fi
101 | fi
102 |
103 | # For Darwin, add options to specify how the application appears in the dock
104 | if $darwin; then
105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
106 | fi
107 |
108 | # For Cygwin, switch paths to Windows format before running java
109 | if $cygwin ; then
110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
112 | JAVACMD=`cygpath --unix "$JAVACMD"`
113 |
114 | # We build the pattern for arguments to be converted via cygpath
115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
116 | SEP=""
117 | for dir in $ROOTDIRSRAW ; do
118 | ROOTDIRS="$ROOTDIRS$SEP$dir"
119 | SEP="|"
120 | done
121 | OURCYGPATTERN="(^($ROOTDIRS))"
122 | # Add a user-defined pattern to the cygpath arguments
123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
125 | fi
126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
127 | i=0
128 | for arg in "$@" ; do
129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
131 |
132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
134 | else
135 | eval `echo args$i`="\"$arg\""
136 | fi
137 | i=$((i+1))
138 | done
139 | case $i in
140 | (0) set -- ;;
141 | (1) set -- "$args0" ;;
142 | (2) set -- "$args0" "$args1" ;;
143 | (3) set -- "$args0" "$args1" "$args2" ;;
144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
150 | esac
151 | fi
152 |
153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
154 | function splitJvmOpts() {
155 | JVM_OPTS=("$@")
156 | }
157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
159 |
160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
161 |
--------------------------------------------------------------------------------
/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 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
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 Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/rkmediacodec/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/rkmediacodec/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | # Sets the minimum version of CMake required to build your native library.
2 | # This ensures that a certain set of CMake features is available to
3 | # your build.
4 |
5 | cmake_minimum_required(VERSION 3.4.1)
6 |
7 | # Specifies a library name, specifies whether the library is STATIC or
8 | # SHARED, and provides relative paths to the source code. You can
9 | # define multiple libraries by adding multiple add.library() commands,
10 | # and CMake builds them for you. When you build your app, Gradle
11 | # automatically packages shared libraries with your APK.
12 |
13 | add_library( # Specifies the name of the library.
14 | native-lib
15 |
16 | # Sets the library as a shared library.
17 | SHARED
18 |
19 | # Provides a relative path to your source file(s).
20 | src/main/cpp/native-lib.cpp
21 | src/main/cpp/rk_mpp.cpp)
22 |
23 | add_library(mpp SHARED IMPORTED)
24 | #add_library(vpu SHARED IMPORTED)
25 | set_target_properties(mpp PROPERTIES IMPORTED_LOCATION ${PROJECT_SOURCE_DIR}/src/main/jniLibs/${ANDROID_ABI}/libmpp.so)
26 | #set_target_properties(vpu PROPERTIES IMPORTED_LOCATION ${PROJECT_SOURCE_DIR}/src/main/jniLibs/${ANDROID_ABI}/libvpu.so)
27 |
28 | # Specifies a path to native header files.
29 | include_directories(src/main/jniLibs/include
30 | src/main/cpp)
31 |
32 | find_library( # Defines the name of the path variable that stores the
33 | # location of the NDK library.
34 | log-lib
35 |
36 | # Specifies the name of the NDK library that
37 | # CMake needs to locate.
38 | log )
39 |
40 |
41 | # Links your native library against one or more other native libraries.
42 | target_link_libraries( # Specifies the target library.
43 | native-lib
44 |
45 | # Links the log library to the target library.
46 | ${log-lib} )
47 |
48 | add_library( app-glue
49 | STATIC
50 | ${ANDROID_NDK}/sources/android/native_app_glue/android_native_app_glue.c )
51 |
52 | # You need to link static libraries against your shared native library.
53 | target_link_libraries( native-lib app-glue ${log-lib} mpp )
--------------------------------------------------------------------------------
/rkmediacodec/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 |
3 | android {
4 | compileSdkVersion 26
5 |
6 |
7 |
8 | defaultConfig {
9 | minSdkVersion 25
10 | targetSdkVersion 26
11 | versionCode 1
12 | versionName "1.0"
13 |
14 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
15 |
16 | ndk {
17 | abiFilters 'arm64-v8a'
18 | }
19 | }
20 |
21 | buildTypes {
22 | release {
23 | minifyEnabled false
24 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
25 | }
26 | }
27 | externalNativeBuild {
28 | cmake {
29 | path "CMakeLists.txt"
30 | }
31 | }
32 |
33 | }
34 |
35 | dependencies {
36 | implementation fileTree(dir: 'libs', include: ['*.jar'])
37 |
38 | implementation 'com.android.support:appcompat-v7:26.1.0'
39 | testImplementation 'junit:junit:4.12'
40 | androidTestImplementation 'com.android.support.test:runner:1.0.1'
41 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
42 | }
43 |
--------------------------------------------------------------------------------
/rkmediacodec/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 |
--------------------------------------------------------------------------------
/rkmediacodec/src/androidTest/java/com/rockchip/rkmediacodec/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.rockchip.rkmediacodec;
2 |
3 | import android.content.Context;
4 | import android.support.test.InstrumentationRegistry;
5 | import android.support.test.runner.AndroidJUnit4;
6 |
7 | import org.junit.Test;
8 | import org.junit.runner.RunWith;
9 |
10 | import static org.junit.Assert.*;
11 |
12 | /**
13 | * Instrumented test, which will execute on an Android device.
14 | *
15 | * @see Testing documentation
16 | */
17 | @RunWith(AndroidJUnit4.class)
18 | public class ExampleInstrumentedTest {
19 | @Test
20 | public void useAppContext() throws Exception {
21 | // Context of the app under test.
22 | Context appContext = InstrumentationRegistry.getTargetContext();
23 |
24 | assertEquals("com.rockchip.rkmediacodec.test", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/rkmediacodec/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
--------------------------------------------------------------------------------
/rkmediacodec/src/main/cpp/log.h:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | #define TAG "RKMPP-JNI"
4 | #define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG, TAG ,__VA_ARGS__)
5 | #define LOGI(...) __android_log_print(ANDROID_LOG_INFO, TAG ,__VA_ARGS__)
6 | #define LOGW(...) __android_log_print(ANDROID_LOG_WARN, TAG ,__VA_ARGS__)
7 | #define LOGE(...) __android_log_print(ANDROID_LOG_ERROR, TAG ,__VA_ARGS__)
8 | #define LOGF(...) __android_log_print(ANDROID_LOG_FATAL, TAG ,__VA_ARGS__)
--------------------------------------------------------------------------------
/rkmediacodec/src/main/cpp/native-lib.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include "log.h"
3 | #include "rk_mpp.h"
4 |
5 | extern "C" {
6 | JNIEXPORT void JNICALL
7 | Java_com_rockchip_rkmediacodec_RKMediaCodec_native_1flush(JNIEnv *env, jobject instance) {
8 |
9 |
10 | }
11 |
12 | JNIEXPORT jlong JNICALL
13 | Java_com_rockchip_rkmediacodec_RKMediaCodec_native_1create(JNIEnv *env, jobject instance,
14 | jstring name_, jboolean encoder) {
15 | const char *name = env->GetStringUTFChars(name_, 0);
16 | LOGD("type name : %s", name);
17 | env->ReleaseStringUTFChars(name_, name);
18 |
19 | RKMpp *rkmpp = new RKMpp();
20 | if (rkmpp->initCodec(name, encoder)) {
21 | jclass Exception = env->FindClass("java/lang/Exception");
22 | env->ThrowNew(Exception, "RKMediaCodec can't support this codec type");
23 | }
24 |
25 | return (jlong) rkmpp;
26 | }
27 |
28 | JNIEXPORT jlong JNICALL
29 | Java_com_rockchip_rkmediacodec_RKMediaCodec_native_1configure(JNIEnv *env, jobject instance,
30 | jlong pMpp) {
31 | RKMpp *rkmpp = (RKMpp *) pMpp;
32 | LOGD("configure ........");
33 |
34 | }
35 |
36 | JNIEXPORT jobjectArray JNICALL
37 | Java_com_rockchip_rkmediacodec_RKMediaCodec_native_1getBuffers(jlong mpp_instance, jboolean input) {
38 |
39 | }
40 |
41 | JNIEXPORT jint JNICALL
42 | Java_com_rockchip_rkmediacodec_RKMediaCodec_native_1dequeueInputBuffer(JNIEnv *env,
43 | jobject instance,
44 | jlong pMpp, jint timeoutUS) {
45 | RKMpp *rkmpp = (RKMpp *) pMpp;
46 | LOGD("dequeue Input Buffer ");
47 | return rkmpp->dequeueInputBuffer(timeoutUS);
48 | }
49 |
50 | JNIEXPORT jobject JNICALL
51 | Java_com_rockchip_rkmediacodec_RKMediaCodec_native_1getInputBuffer(JNIEnv *env, jobject instance,
52 | jlong pMpp, jint index) {
53 | LOGD("get Input Buffer : %d", index);
54 | RKMpp *rkmpp = (RKMpp *) pMpp;
55 | return env->NewDirectByteBuffer(rkmpp->getInputBuffer(index), MPP_MAX_INPUT_BUF_SIZE);
56 | }
57 |
58 | JNIEXPORT void JNICALL
59 | Java_com_rockchip_rkmediacodec_RKMediaCodec_native_1queueInputBuffer(JNIEnv *env, jobject instance,
60 | jlong pMpp,
61 | jint index,
62 | jint offset,
63 | jint size,
64 | jlong presentationTimeUs,
65 | jint flags) {
66 |
67 | LOGD("queue Input Buffer: %d, siz: %d", index, size);
68 | RKMpp *rkmpp = (RKMpp *) pMpp;
69 | rkmpp->queueInputBuffer(index, offset, size, presentationTimeUs);
70 | }
71 |
72 | JNIEXPORT jint JNICALL
73 | Java_com_rockchip_rkmediacodec_RKMediaCodec_native_1dequeueOutputBuffer(JNIEnv *env, jobject instance,
74 | jlong pMpp, jlong timeoutUs) {
75 | LOGD("dequeue Output Buffer ");
76 | RKMpp *rkmpp = (RKMpp *) pMpp;
77 | return rkmpp->dequeueOutputBuffer(timeoutUs);
78 | }
79 |
80 | } /* Extern C */
--------------------------------------------------------------------------------
/rkmediacodec/src/main/cpp/rk_mpp.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include "rk_mpp.h"
4 | #include "log.h"
5 |
6 | RKMpp::RKMpp() : mTaskIndexCursor(0) {
7 | MPP_RET ret = mpp_create(&mMppCtx, &mMppApi);
8 | if (ret) {
9 | LOGE("mpp create failure! ret = %d", ret);
10 | }
11 |
12 | this->createInputBuffers();
13 | }
14 |
15 | RKMpp::~RKMpp() {
16 | mpp_destroy(mMppCtx);
17 |
18 | for (auto &p : mInputBuffers)
19 | free(p);
20 | }
21 |
22 | void RKMpp::createInputBuffers() {
23 | for (auto &p : mInputBuffers) {
24 | p = (char*)malloc(MPP_MAX_INPUT_BUF_SIZE);
25 | LOGD("createInputBuffers : %p", (void*)p);
26 | }
27 | }
28 |
29 | char *RKMpp::getInputBuffer(int index) {
30 | return mInputBuffers[index];
31 | }
32 |
33 | int RKMpp::initCodec(std::string type, bool isEncoder) {
34 | MppCodingType codingType;
35 | if (type == "video/x-vnd.on2.vp8") {
36 | codingType = MPP_VIDEO_CodingVP8;
37 | } else if (type == "video/x-vnd.on2.vp9") {
38 | codingType = MPP_VIDEO_CodingVP9;
39 | } else if (type == "video/avc") {
40 | codingType = MPP_VIDEO_CodingAVC;
41 | } else if (type == "video/hevc") {
42 | codingType = MPP_VIDEO_CodingHEVC;
43 | } else if (type == "video/mp4v-es") {
44 | codingType = MPP_VIDEO_CodingMPEG4;
45 | } else if (type == "video/3gpp") {
46 | codingType = MPP_VIDEO_CodingFLV1;
47 | } else {
48 | LOGE("Can't support %s", type.c_str());
49 | return -1;
50 | }
51 |
52 | MppCtxType ctxType;
53 | if (isEncoder)
54 | ctxType = MPP_CTX_ENC;
55 | else
56 | ctxType = MPP_CTX_DEC;
57 |
58 | MPP_RET ret = mpp_init(mMppCtx, ctxType, codingType);
59 | if (ret) {
60 | LOGE("mpp_init failure !");
61 | return -2;
62 | }
63 | return 0;
64 | }
65 |
66 | int RKMpp::dequeueInputBuffer(long timeoutUs) {
67 | int index = mTaskIndexCursor;
68 | mTaskIndexCursor = (mTaskIndexCursor + 1) % MPP_MAX_INPUT_TASK;
69 | return index;
70 | }
71 |
72 | void RKMpp::queueInputBuffer(int index, int offset, int size, long timeoutUs) {
73 | this->putPacket(mInputBuffers[index] + offset, (size_t)size);
74 | }
75 |
76 | int RKMpp::dequeueOutputBuffer(long timeoutUs) {
77 | return this->getFrame();
78 | }
79 |
80 | void RKMpp::putPacket(char *buf, size_t size) {
81 | MPP_RET ret = MPP_OK;
82 | MppPacket packet = NULL;
83 |
84 | ret = mpp_packet_init(&packet, buf, size);
85 | if (ret) {
86 | LOGE("failed to init packet!");
87 | return;
88 | }
89 |
90 | mpp_packet_write(packet, 0, buf, size);
91 | mpp_packet_set_pos(packet, buf);
92 | mpp_packet_set_length(packet, size);
93 |
94 | //LOGD("put packet %lu", size);
95 | int retry_put = 0;
96 | while(mMppApi->decode_put_packet(mMppCtx, packet)) {
97 | //LOGD("put packet error !");
98 | if(++retry_put > 30) {
99 | LOGW("skip this packet !");
100 | break;
101 | }
102 | usleep(3*1000);
103 | }
104 |
105 | //LOGD("put packet left len: %lu", mpp_packet_get_length(packet));
106 |
107 | if (packet) {
108 | mpp_packet_deinit(&packet);
109 | }
110 | }
111 |
112 | int RKMpp::getFrame() {
113 | MPP_RET ret = MPP_OK;
114 | MppFrame frame = NULL;
115 |
116 | ret = mMppApi->decode_get_frame(mMppCtx, &frame);
117 | if (MPP_OK != ret) {
118 | LOGW("decode_get_frame failed ret %d\n", ret);
119 | return -1;
120 | }
121 |
122 | if (frame) {
123 | if (mpp_frame_get_info_change(frame)) {
124 | mWidth = mpp_frame_get_width(frame);
125 | mHeight = mpp_frame_get_height(frame);
126 | RK_U32 hor_stride = mpp_frame_get_hor_stride(frame);
127 | RK_U32 ver_stride = mpp_frame_get_ver_stride(frame);
128 |
129 | LOGD("decode_get_frame get info changed found\n");
130 | LOGD("decoder require buffer w:h [%u:%u] stride [%d:%d]", mWidth, mHeight, hor_stride, ver_stride);
131 |
132 | //mMppApi->control(mMppCtx, MPP_DEC_SET_EXT_BUF_GROUP, output_grp);
133 | mMppApi->control(mMppCtx, MPP_DEC_SET_INFO_CHANGE_READY, NULL);
134 | } else {
135 | //RK_U32 width = mpp_frame_get_width(frame);
136 | //RK_U32 height = mpp_frame_get_height(frame);
137 | RK_U32 h_stride = mpp_frame_get_hor_stride(frame);
138 | RK_U32 v_stride = mpp_frame_get_ver_stride(frame);
139 | MppFrameFormat fmt = mpp_frame_get_fmt(frame);
140 | MppBuffer buf = mpp_frame_get_buffer(frame);
141 | int fd = mpp_buffer_get_fd(buf);
142 | char *ptr = (char *)mpp_buffer_get_ptr(buf);
143 | size_t siz = mpp_buffer_get_size(buf);
144 |
145 | //LOGD("got frame [fd:%d] . %dx%d [%dx%d]. size: %u", fd , width, height, h_stride, v_stride, siz);
146 | if (siz > 0) {
147 | // PRbsBuffer rbsBuff = RbsBuffer::createWithFd(siz, nullptr, fd, ptr);
148 | // BufferInfo info = {0};
149 | // info.type = UNIT_DATATYPE_YUV420;
150 | // info.width = h_stride;
151 | // info.height = v_stride;
152 | // info.pitch = h_stride;
153 | // info.drm_format = DRM_FORMAT_NV12;
154 | // info.timestamp = nanoTime();
155 | // rbsBuff->setBufferInfo(info);
156 | // rbsBuff->setValidSize(h_stride * v_stride * 3 / 2);
157 |
158 | /// check frame error
159 | int err = mpp_frame_get_errinfo(frame) | mpp_frame_get_discard(frame);
160 | if (err) {
161 | //LOGW("mpp: get err info %d discard %d,go back.",
162 | // mpp_frame_get_errinfo(frame),
163 | // mpp_frame_get_discard(frame));
164 | } else {
165 | //if(DEBUG_DECODER_DELAY) LOGD("Decoder delay: %u ms", (nanoTime() - mDelayTime)/NANOTIME_PER_MSECOND);
166 | }
167 | }
168 |
169 | //LOGD("- mpp_frame_deinit :%d", fd);
170 | mpp_frame_deinit(&frame);
171 |
172 | frame = NULL;
173 | }
174 | } else {
175 | //usleep(10 * 1000); /* 1ms */
176 | LOGD("no frame !");
177 | }
178 |
179 | return 0;
180 | }
181 |
182 |
183 |
184 |
--------------------------------------------------------------------------------
/rkmediacodec/src/main/cpp/rk_mpp.h:
--------------------------------------------------------------------------------
1 | #include "rk_mpi.h"
2 | #include
3 |
4 | #define MPP_MAX_INPUT_TASK 3
5 | #define MPP_MAX_INPUT_BUF_SIZE 1920*1080
6 |
7 | class RKMpp {
8 | public:
9 | RKMpp();
10 | ~RKMpp();
11 | int initCodec(std::string type, bool isEncoder);
12 | void createInputBuffers();
13 | char *getInputBuffer(int index);
14 | int dequeueInputBuffer(long timeoutUs);
15 | void queueInputBuffer(int index, int offset, int size, long timeoutUs);
16 | int dequeueOutputBuffer(long timeoutUs);
17 |
18 | void putPacket(char* buf, size_t size);
19 | int getFrame();
20 |
21 | private:
22 | MppCtx mMppCtx;
23 | MppApi *mMppApi;
24 | MppTask mInputTaskList[MPP_MAX_INPUT_TASK];
25 | int mTaskIndexCursor;
26 | char *mInputBuffers[MPP_MAX_INPUT_TASK];
27 |
28 | long mWidth;
29 | long mHeight;
30 | };
--------------------------------------------------------------------------------
/rkmediacodec/src/main/jniLibs/arm64-v8a/libmpp.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/c-xh/RKMediaCodecDemo/38b85b3c160bf58f2237d5f49b601c1636d484a5/rkmediacodec/src/main/jniLibs/arm64-v8a/libmpp.so
--------------------------------------------------------------------------------
/rkmediacodec/src/main/jniLibs/arm64-v8a/libvpu.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/c-xh/RKMediaCodecDemo/38b85b3c160bf58f2237d5f49b601c1636d484a5/rkmediacodec/src/main/jniLibs/arm64-v8a/libvpu.so
--------------------------------------------------------------------------------
/rkmediacodec/src/main/jniLibs/include/mpp_buffer.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015 Rockchip Electronics Co. LTD
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | #ifndef __MPP_BUFFER_H__
18 | #define __MPP_BUFFER_H__
19 |
20 | #include "rk_type.h"
21 | #include "mpp_err.h"
22 |
23 | /*
24 | * because buffer usage maybe unknown when decoder is not started
25 | * buffer group may need to set a default group size limit
26 | */
27 | #define SZ_1K (1024)
28 | #define SZ_2K (SZ_1K*2)
29 | #define SZ_4K (SZ_1K*4)
30 | #define SZ_8K (SZ_1K*8)
31 | #define SZ_16K (SZ_1K*16)
32 | #define SZ_32K (SZ_1K*32)
33 | #define SZ_64K (SZ_1K*64)
34 | #define SZ_128K (SZ_1K*128)
35 | #define SZ_256K (SZ_1K*256)
36 | #define SZ_512K (SZ_1K*512)
37 | #define SZ_1M (SZ_1K*SZ_1K)
38 | #define SZ_2M (SZ_1M*2)
39 | #define SZ_4M (SZ_1M*4)
40 | #define SZ_8M (SZ_1M*8)
41 | #define SZ_16M (SZ_1M*16)
42 | #define SZ_32M (SZ_1M*32)
43 | #define SZ_64M (SZ_1M*64)
44 | #define SZ_80M (SZ_1M*80)
45 | #define SZ_128M (SZ_1M*128)
46 |
47 | /*
48 | * MppBuffer module has several functions:
49 | *
50 | * 1. buffer get / put / reference management / external commit / get info.
51 | * this part is the basic user interface for MppBuffer.
52 | *
53 | * function:
54 | *
55 | * mpp_buffer_get
56 | * mpp_buffer_put
57 | * mpp_buffer_inc_ref
58 | * mpp_buffer_commit
59 | * mpp_buffer_info_get
60 | *
61 | * 2. user buffer working flow control abstraction.
62 | * buffer should attach to certain group, and buffer mode control the buffer usage flow.
63 | * this part is also a part of user interface.
64 | *
65 | * function:
66 | *
67 | * mpp_buffer_group_get
68 | * mpp_buffer_group_normal_get
69 | * mpp_buffer_group_limit_get
70 | * mpp_buffer_group_put
71 | * mpp_buffer_group_limit_config
72 | *
73 | * 3. buffer allocator management
74 | * this part is for allocator on different os, it does not have user interface
75 | * it will support normal buffer, Android ion buffer, Linux v4l2 vb2 buffer
76 | * user can only use MppBufferType to choose.
77 | *
78 | */
79 | typedef void* MppBuffer;
80 | typedef void* MppBufferGroup;
81 |
82 | /*
83 | * mpp buffer group support two work flow mode:
84 | *
85 | * normal flow: all buffer are generated by MPP
86 | * under this mode, buffer pool is maintained internally
87 | *
88 | * typical call flow:
89 | *
90 | * mpp_buffer_group_get() return A
91 | * mpp_buffer_get(A) return a ref +1 -> used
92 | * mpp_buffer_inc_ref(a) ref +1
93 | * mpp_buffer_put(a) ref -1
94 | * mpp_buffer_put(a) ref -1 -> unused
95 | * mpp_buffer_group_put(A)
96 | *
97 | * commit flow: all buffer are commited out of MPP
98 | * under this mode, buffers is commit by external api.
99 | * normally MPP only use it but not generate it.
100 | *
101 | * typical call flow:
102 | *
103 | * ==== external allocator ====
104 | * mpp_buffer_group_get() return A
105 | * mpp_buffer_commit(A, x)
106 | * mpp_buffer_commit(A, y)
107 | *
108 | * ======= internal user ======
109 | * mpp_buffer_get(A) return a
110 | * mpp_buffer_get(A) return b
111 | * mpp_buffer_put(a)
112 | * mpp_buffer_put(b)
113 | *
114 | * ==== external allocator ====
115 | * mpp_buffer_group_put(A)
116 | *
117 | * NOTE: commit interface required group handle to record group information
118 | */
119 |
120 | /*
121 | * mpp buffer group has two buffer limit mode: normal and limit
122 | *
123 | * normal mode: allows any buffer size and always general new buffer is no unused buffer
124 | * is available.
125 | * This mode normally use with normal flow and is used for table / stream buffer
126 | *
127 | * limit mode : restrict the buffer's size and count in the buffer group. if try to calloc
128 | * buffer with different size or extra count it will fail.
129 | * This mode normally use with commit flow and is used for frame buffer
130 | */
131 |
132 | /*
133 | * NOTE: normal mode is recommanded to work with normal flow, working with limit mode is not.
134 | * limit mode is recommanded to work with commit flow, working with normal mode is not.
135 | */
136 | typedef enum {
137 | MPP_BUFFER_INTERNAL,
138 | MPP_BUFFER_EXTERNAL,
139 | MPP_BUFFER_MODE_BUTT,
140 | } MppBufferMode;
141 |
142 | /*
143 | * mpp buffer has two types:
144 | *
145 | * normal : normal malloc buffer for unit test or hardware simulation
146 | * ion : use ion device under Android/Linux, MppBuffer will encapsulte ion file handle
147 | */
148 | typedef enum {
149 | MPP_BUFFER_TYPE_NORMAL,
150 | MPP_BUFFER_TYPE_ION,
151 | MPP_BUFFER_TYPE_V4L2,
152 | MPP_BUFFER_TYPE_DRM,
153 | MPP_BUFFER_TYPE_BUTT,
154 | } MppBufferType;
155 |
156 | /*
157 | * MppBufferInfo variable's meaning is different in different MppBufferType
158 | *
159 | * MPP_BUFFER_TYPE_NORMAL
160 | *
161 | * ptr - virtual address of normal malloced buffer
162 | * fd - unused and set to -1
163 | *
164 | * MPP_BUFFER_TYPE_ION
165 | *
166 | * ptr - virtual address of ion buffer in user space
167 | * hnd - ion handle in user space
168 | * fd - ion buffer file handle for map / unmap
169 | *
170 | * MPP_BUFFER_TYPE_V4L2
171 | *
172 | * TODO: to be implemented.
173 | */
174 | typedef struct MppBufferInfo_t {
175 | MppBufferType type;
176 | size_t size;
177 | void *ptr;
178 | void *hnd;
179 | int fd;
180 | int index;
181 | } MppBufferInfo;
182 |
183 | #define BUFFER_GROUP_SIZE_DEFAULT (SZ_1M*80)
184 |
185 | /*
186 | * mpp_buffer_import_with_tag(MppBufferGroup group, MppBufferInfo *info, MppBuffer *buffer)
187 | *
188 | * 1. group - specified the MppBuffer to be attached to.
189 | * group can be NULL then this buffer will attached to default legecy group
190 | * Default to NULL on mpp_buffer_import case
191 | *
192 | * 2. info - input information for the output MppBuffer
193 | * info can NOT be NULL. It must contain at least one of ptr/fd.
194 | *
195 | * 3. buffer - generated MppBuffer from MppBufferInfo.
196 | * buffer can be NULL then the buffer is commit to group with unused status.
197 | * Otherwise generated buffer will be directly got and ref_count increased.
198 | * Default to NULL on mpp_buffer_commit case
199 | *
200 | * mpp_buffer_commit usage:
201 | *
202 | * Add a external buffer info to group. This buffer will be on unused status.
203 | * Typical usage is on Android. MediaPlayer gralloc Graphic buffer then commit these buffer
204 | * to decoder's buffer group. Then decoder will recycle these buffer and return buffer reference
205 | * to MediaPlayer for display.
206 | *
207 | * mpp_buffer_import usage:
208 | *
209 | * Transfer a external buffer info to MppBuffer but it is not expected to attached to certain
210 | * buffer group. So the group is set to NULL. Then this buffer can be used for MppFrame/MppPacket.
211 | * Typical usage is for image processing. Image processing normally will be a oneshot operation
212 | * It does not need complicated group management. But in other hand mpp still need to know the
213 | * imported buffer is leak or not and trace its usage inside mpp process. So we attach this kind
214 | * of buffer to default misc buffer group for management.
215 | */
216 | #define mpp_buffer_commit(group, info) \
217 | mpp_buffer_import_with_tag(group, info, NULL, MODULE_TAG, __FUNCTION__)
218 |
219 | #define mpp_buffer_import(buffer, info) \
220 | mpp_buffer_import_with_tag(NULL, info, buffer, MODULE_TAG, __FUNCTION__)
221 |
222 | #define mpp_buffer_get(group, buffer, size) \
223 | mpp_buffer_get_with_tag(group, buffer, size, MODULE_TAG, __FUNCTION__)
224 |
225 | #define mpp_buffer_put(buffer) \
226 | mpp_buffer_put_with_caller(buffer, __FUNCTION__)
227 |
228 | #define mpp_buffer_inc_ref(buffer) \
229 | mpp_buffer_inc_ref_with_caller(buffer, __FUNCTION__)
230 |
231 | #define mpp_buffer_info_get(buffer, info) \
232 | mpp_buffer_info_get_with_caller(buffer, info, __FUNCTION__)
233 |
234 | #define mpp_buffer_read(buffer, offset, data, size) \
235 | mpp_buffer_read_with_caller(buffer, offset, data, size, __FUNCTION__)
236 |
237 | #define mpp_buffer_write(buffer, offset, data, size) \
238 | mpp_buffer_write_with_caller(buffer, offset, data, size, __FUNCTION__)
239 |
240 | #define mpp_buffer_get_ptr(buffer) \
241 | mpp_buffer_get_ptr_with_caller(buffer, __FUNCTION__)
242 |
243 | #define mpp_buffer_get_fd(buffer) \
244 | mpp_buffer_get_fd_with_caller(buffer, __FUNCTION__)
245 |
246 | #define mpp_buffer_get_size(buffer) \
247 | mpp_buffer_get_size_with_caller(buffer, __FUNCTION__)
248 |
249 | #define mpp_buffer_get_index(buffer) \
250 | mpp_buffer_get_index_with_caller(buffer, __FUNCTION__)
251 |
252 | #define mpp_buffer_set_index(buffer, index) \
253 | mpp_buffer_set_index_with_caller(buffer, index, __FUNCTION__)
254 |
255 | #define mpp_buffer_group_get_internal(group, type, ...) \
256 | mpp_buffer_group_get(group, type, MPP_BUFFER_INTERNAL, MODULE_TAG, __FUNCTION__)
257 |
258 | #define mpp_buffer_group_get_external(group, type, ...) \
259 | mpp_buffer_group_get(group, type, MPP_BUFFER_EXTERNAL, MODULE_TAG, __FUNCTION__)
260 |
261 | #ifdef __cplusplus
262 | extern "C" {
263 | #endif
264 |
265 | /*
266 | * MppBuffer interface
267 | * these interface will change value of group and buffer so before calling functions
268 | * parameter need to be checked.
269 | *
270 | * IMPORTANT:
271 | * mpp_buffer_import_with_tag - compounded interface for commit and import
272 | *
273 | */
274 | MPP_RET mpp_buffer_import_with_tag(MppBufferGroup group, MppBufferInfo *info, MppBuffer *buffer,
275 | const char *tag, const char *caller);
276 | MPP_RET mpp_buffer_get_with_tag(MppBufferGroup group, MppBuffer *buffer, size_t size,
277 | const char *tag, const char *caller);
278 | MPP_RET mpp_buffer_put_with_caller(MppBuffer buffer, const char *caller);
279 | MPP_RET mpp_buffer_inc_ref_with_caller(MppBuffer buffer, const char *caller);
280 |
281 | MPP_RET mpp_buffer_info_get_with_caller(MppBuffer buffer, MppBufferInfo *info, const char *caller);
282 | MPP_RET mpp_buffer_read_with_caller(MppBuffer buffer, size_t offset, void *data, size_t size, const char *caller);
283 | MPP_RET mpp_buffer_write_with_caller(MppBuffer buffer, size_t offset, void *data, size_t size, const char *caller);
284 | void *mpp_buffer_get_ptr_with_caller(MppBuffer buffer, const char *caller);
285 | int mpp_buffer_get_fd_with_caller(MppBuffer buffer, const char *caller);
286 | size_t mpp_buffer_get_size_with_caller(MppBuffer buffer, const char *caller);
287 | int mpp_buffer_get_index_with_caller(MppBuffer buffer, const char *caller);
288 | MPP_RET mpp_buffer_set_index_with_caller(MppBuffer buffer, int index, const char *caller);
289 |
290 | MPP_RET mpp_buffer_group_get(MppBufferGroup *group, MppBufferType type, MppBufferMode mode,
291 | const char *tag, const char *caller);
292 | MPP_RET mpp_buffer_group_put(MppBufferGroup group);
293 | MPP_RET mpp_buffer_group_clear(MppBufferGroup group);
294 | RK_S32 mpp_buffer_group_unused(MppBufferGroup group);
295 | MppBufferMode mpp_buffer_group_mode(MppBufferGroup group);
296 | MppBufferType mpp_buffer_group_type(MppBufferGroup group);
297 |
298 | /*
299 | * size : 0 - no limit, other - max buffer size
300 | * count : 0 - no limit, other - max buffer count
301 | */
302 | MPP_RET mpp_buffer_group_limit_config(MppBufferGroup group, size_t size, RK_S32 count);
303 |
304 | #ifdef __cplusplus
305 | }
306 | #endif
307 |
308 | #endif /*__MPP_BUFFER_H__*/
309 |
--------------------------------------------------------------------------------
/rkmediacodec/src/main/jniLibs/include/mpp_err.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015 Rockchip Electronics Co. LTD
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | #ifndef __MPP_ERR_H__
18 | #define __MPP_ERR_H__
19 |
20 | #define RK_OK 0
21 | #define RK_SUCCESS 0
22 |
23 | typedef enum {
24 | MPP_SUCCESS = RK_SUCCESS,
25 | MPP_OK = RK_OK,
26 |
27 | MPP_NOK = -1,
28 | MPP_ERR_UNKNOW = -2,
29 | MPP_ERR_NULL_PTR = -3,
30 | MPP_ERR_MALLOC = -4,
31 | MPP_ERR_OPEN_FILE = -5,
32 | MPP_ERR_VALUE = -6,
33 | MPP_ERR_READ_BIT = -7,
34 | MPP_ERR_TIMEOUT = -8,
35 |
36 | MPP_ERR_BASE = -1000,
37 |
38 | MPP_ERR_LIST_STREAM = MPP_ERR_BASE - 1,
39 | MPP_ERR_INIT = MPP_ERR_BASE - 2,
40 | MPP_ERR_VPU_CODEC_INIT = MPP_ERR_BASE - 3,
41 | MPP_ERR_STREAM = MPP_ERR_BASE - 4,
42 | MPP_ERR_FATAL_THREAD = MPP_ERR_BASE - 5,
43 | MPP_ERR_NOMEM = MPP_ERR_BASE - 6,
44 | MPP_ERR_PROTOL = MPP_ERR_BASE - 7,
45 | MPP_FAIL_SPLIT_FRAME = MPP_ERR_BASE - 8,
46 | MPP_ERR_VPUHW = MPP_ERR_BASE - 9,
47 | MPP_EOS_STREAM_REACHED = MPP_ERR_BASE - 11,
48 | MPP_ERR_BUFFER_FULL = MPP_ERR_BASE - 12,
49 | } MPP_RET;
50 |
51 | #endif /*__MPP_ERR_H__*/
52 |
--------------------------------------------------------------------------------
/rkmediacodec/src/main/jniLibs/include/mpp_frame.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015 Rockchip Electronics Co. LTD
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | #ifndef __MPP_FRAME_H__
18 | #define __MPP_FRAME_H__
19 |
20 | #include "mpp_buffer.h"
21 |
22 | typedef void* MppFrame;
23 |
24 | /*
25 | * bit definition for mode flag in MppFrame
26 | */
27 | /* progressive frame */
28 | #define MPP_FRAME_FLAG_FRAME (0x00000000)
29 | /* top field only */
30 | #define MPP_FRAME_FLAG_TOP_FIELD (0x00000001)
31 | /* bottom field only */
32 | #define MPP_FRAME_FLAG_BOT_FIELD (0x00000002)
33 | /* paired field */
34 | #define MPP_FRAME_FLAG_PAIRED_FIELD (MPP_FRAME_FLAG_TOP_FIELD|MPP_FRAME_FLAG_BOT_FIELD)
35 | /* paired field with field order of top first */
36 | #define MPP_FRAME_FLAG_TOP_FIRST (0x00000004)
37 | /* paired field with field order of bottom first */
38 | #define MPP_FRAME_FLAG_BOT_FIRST (0x00000008)
39 | /* paired field with unknown field order (MBAFF) */
40 | #define MPP_FRAME_FLAG_DEINTERLACED (MPP_FRAME_FLAG_TOP_FIRST|MPP_FRAME_FLAG_BOT_FIRST)
41 | #define MPP_FRAME_FLAG_FIELD_ORDER_MASK (0x0000000C)
42 | // for multiview stream
43 | #define MPP_FRAME_FLAG_VIEW_ID_MASK (0x000000f0)
44 |
45 |
46 | /*
47 | * MPEG vs JPEG YUV range.
48 | */
49 | typedef enum {
50 | MPP_FRAME_RANGE_UNSPECIFIED = 0,
51 | MPP_FRAME_RANGE_MPEG = 1, ///< the normal 219*2^(n-8) "MPEG" YUV ranges
52 | MPP_FRAME_RANGE_JPEG = 2, ///< the normal 2^n-1 "JPEG" YUV ranges
53 | MPP_FRAME_RANGE_NB, ///< Not part of ABI
54 | } MppFrameColorRange;
55 |
56 | /*
57 | * Chromaticity coordinates of the source primaries.
58 | */
59 | typedef enum {
60 | MPP_FRAME_PRI_RESERVED0 = 0,
61 | MPP_FRAME_PRI_BT709 = 1, ///< also ITU-R BT1361 / IEC 61966-2-4 / SMPTE RP177 Annex B
62 | MPP_FRAME_PRI_UNSPECIFIED = 2,
63 | MPP_FRAME_PRI_RESERVED = 3,
64 | MPP_FRAME_PRI_BT470M = 4, ///< also FCC Title 47 Code of Federal Regulations 73.682 (a)(20)
65 |
66 | MPP_FRAME_PRI_BT470BG = 5, ///< also ITU-R BT601-6 625 / ITU-R BT1358 625 / ITU-R BT1700 625 PAL & SECAM
67 | MPP_FRAME_PRI_SMPTE170M = 6, ///< also ITU-R BT601-6 525 / ITU-R BT1358 525 / ITU-R BT1700 NTSC
68 | MPP_FRAME_PRI_SMPTE240M = 7, ///< functionally identical to above
69 | MPP_FRAME_PRI_FILM = 8, ///< colour filters using Illuminant C
70 | MPP_FRAME_PRI_BT2020 = 9, ///< ITU-R BT2020
71 | MPP_FRAME_PRI_SMPTEST428_1 = 10, ///< SMPTE ST 428-1 (CIE 1931 XYZ)
72 | MPP_FRAME_PRI_NB, ///< Not part of ABI
73 | } MppFrameColorPrimaries;
74 |
75 | /*
76 | * Color Transfer Characteristic.
77 | */
78 | typedef enum {
79 | MPP_FRAME_TRC_RESERVED0 = 0,
80 | MPP_FRAME_TRC_BT709 = 1, ///< also ITU-R BT1361
81 | MPP_FRAME_TRC_UNSPECIFIED = 2,
82 | MPP_FRAME_TRC_RESERVED = 3,
83 | MPP_FRAME_TRC_GAMMA22 = 4, ///< also ITU-R BT470M / ITU-R BT1700 625 PAL & SECAM
84 | MPP_FRAME_TRC_GAMMA28 = 5, ///< also ITU-R BT470BG
85 | MPP_FRAME_TRC_SMPTE170M = 6, ///< also ITU-R BT601-6 525 or 625 / ITU-R BT1358 525 or 625 / ITU-R BT1700 NTSC
86 | MPP_FRAME_TRC_SMPTE240M = 7,
87 | MPP_FRAME_TRC_LINEAR = 8, ///< "Linear transfer characteristics"
88 | MPP_FRAME_TRC_LOG = 9, ///< "Logarithmic transfer characteristic (100:1 range)"
89 | MPP_FRAME_TRC_LOG_SQRT = 10, ///< "Logarithmic transfer characteristic (100 * Sqrt(10) : 1 range)"
90 | MPP_FRAME_TRC_IEC61966_2_4 = 11, ///< IEC 61966-2-4
91 | MPP_FRAME_TRC_BT1361_ECG = 12, ///< ITU-R BT1361 Extended Colour Gamut
92 | MPP_FRAME_TRC_IEC61966_2_1 = 13, ///< IEC 61966-2-1 (sRGB or sYCC)
93 | MPP_FRAME_TRC_BT2020_10 = 14, ///< ITU-R BT2020 for 10 bit system
94 | MPP_FRAME_TRC_BT2020_12 = 15, ///< ITU-R BT2020 for 12 bit system
95 | MPP_FRAME_TRC_SMPTEST2084 = 16, ///< SMPTE ST 2084 for 10-, 12-, 14- and 16-bit systems
96 | MPP_FRAME_TRC_SMPTEST428_1 = 17, ///< SMPTE ST 428-1
97 | MPP_FRAME_TRC_ARIB_STD_B67 = 18, ///< ARIB STD-B67, known as "Hybrid log-gamma"
98 | MPP_FRAME_TRC_NB, ///< Not part of ABI
99 | } MppFrameColorTransferCharacteristic;
100 |
101 | /*
102 | * YUV colorspace type.
103 | */
104 | typedef enum {
105 | MPP_FRAME_SPC_RGB = 0, ///< order of coefficients is actually GBR, also IEC 61966-2-1 (sRGB)
106 | MPP_FRAME_SPC_BT709 = 1, ///< also ITU-R BT1361 / IEC 61966-2-4 xvYCC709 / SMPTE RP177 Annex B
107 | MPP_FRAME_SPC_UNSPECIFIED = 2,
108 | MPP_FRAME_SPC_RESERVED = 3,
109 | MPP_FRAME_SPC_FCC = 4, ///< FCC Title 47 Code of Federal Regulations 73.682 (a)(20)
110 | MPP_FRAME_SPC_BT470BG = 5, ///< also ITU-R BT601-6 625 / ITU-R BT1358 625 / ITU-R BT1700 625 PAL & SECAM / IEC 61966-2-4 xvYCC601
111 | MPP_FRAME_SPC_SMPTE170M = 6, ///< also ITU-R BT601-6 525 / ITU-R BT1358 525 / ITU-R BT1700 NTSC / functionally identical to above
112 | MPP_FRAME_SPC_SMPTE240M = 7,
113 | MPP_FRAME_SPC_YCOCG = 8, ///< Used by Dirac / VC-2 and H.264 FRext, see ITU-T SG16
114 | MPP_FRAME_SPC_BT2020_NCL = 9, ///< ITU-R BT2020 non-constant luminance system
115 | MPP_FRAME_SPC_BT2020_CL = 10, ///< ITU-R BT2020 constant luminance system
116 | MPP_FRAME_SPC_NB, ///< Not part of ABI
117 | } MppFrameColorSpace;
118 |
119 | /*
120 | * Location of chroma samples.
121 | *
122 | * Illustration showing the location of the first (top left) chroma sample of the
123 | * image, the left shows only luma, the right
124 | * shows the location of the chroma sample, the 2 could be imagined to overlay
125 | * each other but are drawn separately due to limitations of ASCII
126 | *
127 | * 1st 2nd 1st 2nd horizontal luma sample positions
128 | * v v v v
129 | * ______ ______
130 | *1st luma line > |X X ... |3 4 X ... X are luma samples,
131 | * | |1 2 1-6 are possible chroma positions
132 | *2nd luma line > |X X ... |5 6 X ... 0 is undefined/unknown position
133 | */
134 | typedef enum {
135 | MPP_CHROMA_LOC_UNSPECIFIED = 0,
136 | MPP_CHROMA_LOC_LEFT = 1, ///< mpeg2/4 4:2:0, h264 default for 4:2:0
137 | MPP_CHROMA_LOC_CENTER = 2, ///< mpeg1 4:2:0, jpeg 4:2:0, h263 4:2:0
138 | MPP_CHROMA_LOC_TOPLEFT = 3, ///< ITU-R 601, SMPTE 274M 296M S314M(DV 4:1:1), mpeg2 4:2:2
139 | MPP_CHROMA_LOC_TOP = 4,
140 | MPP_CHROMA_LOC_BOTTOMLEFT = 5,
141 | MPP_CHROMA_LOC_BOTTOM = 6,
142 | MPP_CHROMA_LOC_NB, ///< Not part of ABI
143 | } MppFrameChromaLocation;
144 |
145 | #define MPP_FRAME_FMT_MASK 0x000f0000
146 | #define MPP_FRAME_FMT_YUV 0x00000000
147 | #define MPP_FRAME_FMT_RGB 0x00010000
148 | #define MPP_FRAME_FMT_COMPLEX 0x00020000
149 |
150 | /*
151 | *mpp color format define
152 | */
153 | typedef enum {
154 | MPP_FMT_YUV420SP = MPP_FRAME_FMT_YUV, /* YYYY... UV... (NV12) */
155 | /*
156 | * A rockchip specific pixel format, without gap between pixel aganist
157 | * the P010_10LE/P010_10BE
158 | */
159 | MPP_FMT_YUV420SP_10BIT,
160 | MPP_FMT_YUV422SP, /* YYYY... UVUV... (NV24) */
161 | MPP_FMT_YUV422SP_10BIT, ///< Not part of ABI
162 | MPP_FMT_YUV420P, /* YYYY... U...V... (I420) */
163 | MPP_FMT_YUV420SP_VU, /* YYYY... VUVUVU... (NV21) */
164 | MPP_FMT_YUV422P, /* YYYY... UU...VV...(422P) */
165 | MPP_FMT_YUV422SP_VU, /* YYYY... VUVUVU... (NV42) */
166 | MPP_FMT_YUV422_YUYV, /* YUYVYUYV... (YUY2) */
167 | MPP_FMT_YUV422_UYVY, /* UYVYUYVY... (UYVY) */
168 | MPP_FMT_YUV400SP, /* YYYY... */
169 | MPP_FMT_YUV440SP, /* YYYY... UVUV... */
170 | MPP_FMT_YUV411SP, /* YYYY... UV... */
171 | MPP_FMT_YUV444SP, /* YYYY... UVUVUVUV... */
172 | MPP_FMT_YUV_BUTT,
173 | MPP_FMT_RGB565 = MPP_FRAME_FMT_RGB, /* 16-bit RGB */
174 | MPP_FMT_BGR565, /* 16-bit RGB */
175 | MPP_FMT_RGB555, /* 15-bit RGB */
176 | MPP_FMT_BGR555, /* 15-bit RGB */
177 | MPP_FMT_RGB444, /* 12-bit RGB */
178 | MPP_FMT_BGR444, /* 12-bit RGB */
179 | MPP_FMT_RGB888, /* 24-bit RGB */
180 | MPP_FMT_BGR888, /* 24-bit RGB */
181 | MPP_FMT_RGB101010, /* 30-bit RGB */
182 | MPP_FMT_BGR101010, /* 30-bit RGB */
183 | MPP_FMT_ARGB8888, /* 32-bit RGB */
184 | MPP_FMT_ABGR8888, /* 32-bit RGB */
185 | MPP_FMT_RGB_BUTT,
186 | /* simliar to I420, but Pixels are grouped in macroblocks of 8x4 size */
187 | MPP_FMT_YUV420_8Z4 = MPP_FRAME_FMT_COMPLEX,
188 | /* The end of the formats have a complex layout */
189 | MPP_FMT_COMPLEX_BUTT,
190 | MPP_FMT_BUTT = MPP_FMT_COMPLEX_BUTT,
191 | } MppFrameFormat;
192 |
193 | typedef enum {
194 | MPP_FRAME_ERR_UNKNOW = 0x0001,
195 | MPP_FRAME_ERR_UNSUPPORT = 0x0002,
196 | } MPP_FRAME_ERR;
197 |
198 | #ifdef __cplusplus
199 | extern "C" {
200 | #endif
201 |
202 | /*
203 | * MppFrame interface
204 | */
205 | MPP_RET mpp_frame_init(MppFrame *frame);
206 | MPP_RET mpp_frame_deinit(MppFrame *frame);
207 | MppFrame mpp_frame_get_next(MppFrame frame);
208 |
209 | /*
210 | * normal parameter
211 | */
212 | RK_U32 mpp_frame_get_width(const MppFrame frame);
213 | void mpp_frame_set_width(MppFrame frame, RK_U32 width);
214 | RK_U32 mpp_frame_get_height(const MppFrame frame);
215 | void mpp_frame_set_height(MppFrame frame, RK_U32 height);
216 | RK_U32 mpp_frame_get_hor_stride(const MppFrame frame);
217 | void mpp_frame_set_hor_stride(MppFrame frame, RK_U32 hor_stride);
218 | RK_U32 mpp_frame_get_ver_stride(const MppFrame frame);
219 | void mpp_frame_set_ver_stride(MppFrame frame, RK_U32 ver_stride);
220 | RK_U32 mpp_frame_get_mode(const MppFrame frame);
221 | void mpp_frame_set_mode(MppFrame frame, RK_U32 mode);
222 | RK_U32 mpp_frame_get_discard(const MppFrame frame);
223 | void mpp_frame_set_discard(MppFrame frame, RK_U32 discard);
224 | RK_U32 mpp_frame_get_viewid(const MppFrame frame);
225 | void mpp_frame_set_viewid(MppFrame frame, RK_U32 viewid);
226 | RK_U32 mpp_frame_get_poc(const MppFrame frame);
227 | void mpp_frame_set_poc(MppFrame frame, RK_U32 poc);
228 | RK_S64 mpp_frame_get_pts(const MppFrame frame);
229 | void mpp_frame_set_pts(MppFrame frame, RK_S64 pts);
230 | RK_S64 mpp_frame_get_dts(const MppFrame frame);
231 | void mpp_frame_set_dts(MppFrame frame, RK_S64 dts);
232 | RK_U32 mpp_frame_get_errinfo(const MppFrame frame);
233 | void mpp_frame_set_errinfo(MppFrame frame, RK_U32 errinfo);
234 | size_t mpp_frame_get_buf_size(const MppFrame frame);
235 | void mpp_frame_set_buf_size(MppFrame frame, size_t buf_size);
236 | /*
237 | * flow control parmeter
238 | */
239 | RK_U32 mpp_frame_get_eos(const MppFrame frame);
240 | void mpp_frame_set_eos(MppFrame frame, RK_U32 eos);
241 | RK_U32 mpp_frame_get_info_change(const MppFrame frame);
242 | void mpp_frame_set_info_change(MppFrame frame, RK_U32 info_change);
243 |
244 | /*
245 | * buffer parameter
246 | */
247 | MppBuffer mpp_frame_get_buffer(const MppFrame frame);
248 | void mpp_frame_set_buffer(MppFrame frame, MppBuffer buffer);
249 |
250 | /*
251 | * color related parameter
252 | */
253 | MppFrameColorRange mpp_frame_get_color_range(const MppFrame frame);
254 | void mpp_frame_set_color_range(MppFrame frame, MppFrameColorRange color_range);
255 | MppFrameColorPrimaries mpp_frame_get_color_primaries(const MppFrame frame);
256 | void mpp_frame_set_color_primaries(MppFrame frame, MppFrameColorPrimaries color_primaries);
257 | MppFrameColorTransferCharacteristic mpp_frame_get_color_trc(const MppFrame frame);
258 | void mpp_frame_set_color_trc(MppFrame frame, MppFrameColorTransferCharacteristic color_trc);
259 | MppFrameColorSpace mpp_frame_get_colorspace(const MppFrame frame);
260 | void mpp_frame_set_colorspace(MppFrame frame, MppFrameColorSpace colorspace);
261 | MppFrameChromaLocation mpp_frame_get_chroma_location(const MppFrame frame);
262 | void mpp_frame_set_chroma_location(MppFrame frame, MppFrameChromaLocation chroma_location);
263 | MppFrameFormat mpp_frame_get_fmt(MppFrame frame);
264 | void mpp_frame_set_fmt(MppFrame frame, MppFrameFormat fmt);
265 |
266 |
267 | /*
268 | * HDR parameter
269 | */
270 |
271 | #ifdef __cplusplus
272 | }
273 | #endif
274 |
275 | #endif /*__MPP_FRAME_H__*/
276 |
--------------------------------------------------------------------------------
/rkmediacodec/src/main/jniLibs/include/mpp_meta.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015 Rockchip Electronics Co. LTD
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | #ifndef __MPP_META_H__
18 | #define __MPP_META_H__
19 |
20 | #include
21 | #include "rk_type.h"
22 |
23 | #include "mpp_frame.h"
24 | #include "mpp_packet.h"
25 |
26 | #define FOURCC_META(a, b, c, d) ((RK_U32)(a) << 24 | \
27 | ((RK_U32)(b) << 16) | \
28 | ((RK_U32)(c) << 8) | \
29 | ((RK_U32)(d) << 0))
30 |
31 | /*
32 | * Mpp Metadata definition
33 | *
34 | * Metadata is for information transmision in mpp.
35 | * Mpp task will contain two meta data:
36 | *
37 | * 1. Data flow metadata
38 | * This metadata contains information of input / output data flow. For example
39 | * A. decoder input side task the input packet must be defined and output frame
40 | * may not be defined. Then decoder will try malloc or use committed buffer to
41 | * complete decoding.
42 | * B. decoder output side task
43 | *
44 | *
45 | * 2. Flow control metadata
46 | *
47 | */
48 | typedef enum MppMetaDataType_e {
49 | /*
50 | * mpp meta data of data flow
51 | * reference counter will be used for these meta data type
52 | */
53 | TYPE_FRAME = FOURCC_META('m', 'f', 'r', 'm'),
54 | TYPE_PACKET = FOURCC_META('m', 'p', 'k', 't'),
55 | TYPE_BUFFER = FOURCC_META('m', 'b', 'u', 'f'),
56 |
57 | /* mpp meta data of normal data type */
58 | TYPE_S32 = FOURCC_META('s', '3', '2', ' '),
59 | TYPE_S64 = FOURCC_META('s', '6', '4', ' '),
60 | TYPE_PTR = FOURCC_META('p', 't', 'r', ' '),
61 | } MppMetaType;
62 |
63 | typedef enum MppMetaKey_e {
64 | /* data flow key */
65 | KEY_INPUT_FRAME = FOURCC_META('i', 'f', 'r', 'm'),
66 | KEY_INPUT_PACKET = FOURCC_META('i', 'p', 'k', 't'),
67 | KEY_OUTPUT_FRAME = FOURCC_META('o', 'f', 'r', 'm'),
68 | KEY_OUTPUT_PACKET = FOURCC_META('o', 'p', 'k', 't'),
69 | /* output motion information for motion detection */
70 | KEY_MOTION_INFO = FOURCC_META('m', 'v', 'i', 'f'),
71 | KEY_HDR_INFO = FOURCC_META('h', 'd', 'r', ' '),
72 |
73 | /* flow control key */
74 | KEY_INPUT_BLOCK = FOURCC_META('i', 'b', 'l', 'k'),
75 | KEY_OUTPUT_BLOCK = FOURCC_META('o', 'b', 'l', 'k'),
76 | KEY_INPUT_IDR_REQ = FOURCC_META('i', 'i', 'd', 'r'), /* input idr frame request flag */
77 | KEY_OUTPUT_INTRA = FOURCC_META('o', 'i', 'd', 'r'), /* output intra frame indicator */
78 |
79 | /* flow control key */
80 | KEY_WIDTH = FOURCC_META('w', 'd', 't', 'h'),
81 | KEY_HEIGHT = FOURCC_META('h', 'g', 'h', 't'),
82 | KEY_BITRATE = FOURCC_META('b', 'p', 's', ' '),
83 | KEY_BITRATE_UP = FOURCC_META('b', 'p', 's', 'u'),
84 | KEY_BITRATE_LOW = FOURCC_META('b', 'p', 's', 'l'),
85 | KEY_INPUT_FPS = FOURCC_META('i', 'f', 'p', 's'),
86 | KEY_OUTPUT_FPS = FOURCC_META('o', 'f', 'p', 's'),
87 | KEY_GOP = FOURCC_META('g', 'o', 'p', ' '),
88 | KEY_QP = FOURCC_META('q', 'p', ' ', ' '),
89 | KEY_QP_MIN = FOURCC_META('q', 'm', 'i', 'n'),
90 | KEY_QP_MAX = FOURCC_META('q', 'm', 'a', 'x'),
91 | KEY_QP_DIFF_RANGE = FOURCC_META('q', 'd', 'i', 'f'),
92 | KEY_RC_MODE = FOURCC_META('r', 'c', 'm', 'o'),
93 | } MppMetaKey;
94 |
95 | typedef void* MppMeta;
96 |
97 | #define mpp_meta_get(meta) mpp_meta_get_with_tag(meta, MODULE_TAG, __FUNCTION__)
98 |
99 | #ifdef __cplusplus
100 | extern "C" {
101 | #endif
102 |
103 | MPP_RET mpp_meta_get_with_tag(MppMeta *meta, const char *tag, const char *caller);
104 | MPP_RET mpp_meta_put(MppMeta meta);
105 |
106 | MPP_RET mpp_meta_set_s32(MppMeta meta, MppMetaKey key, RK_S32 val);
107 | MPP_RET mpp_meta_set_s64(MppMeta meta, MppMetaKey key, RK_S64 val);
108 | MPP_RET mpp_meta_set_ptr(MppMeta meta, MppMetaKey key, void *val);
109 | MPP_RET mpp_meta_get_s32(MppMeta meta, MppMetaKey key, RK_S32 *val);
110 | MPP_RET mpp_meta_get_s64(MppMeta meta, MppMetaKey key, RK_S64 *val);
111 | MPP_RET mpp_meta_get_ptr(MppMeta meta, MppMetaKey key, void **val);
112 |
113 | MPP_RET mpp_meta_set_frame (MppMeta meta, MppMetaKey key, MppFrame frame);
114 | MPP_RET mpp_meta_set_packet(MppMeta meta, MppMetaKey key, MppPacket packet);
115 | MPP_RET mpp_meta_set_buffer(MppMeta meta, MppMetaKey key, MppBuffer buffer);
116 | MPP_RET mpp_meta_get_frame (MppMeta meta, MppMetaKey key, MppFrame *frame);
117 | MPP_RET mpp_meta_get_packet(MppMeta meta, MppMetaKey key, MppPacket *packet);
118 | MPP_RET mpp_meta_get_buffer(MppMeta meta, MppMetaKey key, MppBuffer *buffer);
119 |
120 | #ifdef __cplusplus
121 | }
122 | #endif
123 |
124 | #endif /*__MPP_META_H__*/
125 |
--------------------------------------------------------------------------------
/rkmediacodec/src/main/jniLibs/include/mpp_packet.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015 Rockchip Electronics Co. LTD
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | #ifndef __MPP_PACKET_H__
18 | #define __MPP_PACKET_H__
19 |
20 | #include "mpp_buffer.h"
21 |
22 | typedef void* MppPacket;
23 |
24 | #ifdef __cplusplus
25 | extern "C" {
26 | #endif
27 |
28 | /*
29 | * MppPacket interface
30 | *
31 | * mpp_packet_init = mpp_packet_new + mpp_packet_set_data + mpp_packet_set_size
32 | * mpp_packet_copy_init = mpp_packet_init + memcpy
33 | */
34 | MPP_RET mpp_packet_new(MppPacket *packet);
35 | MPP_RET mpp_packet_init(MppPacket *packet, void *data, size_t size);
36 | MPP_RET mpp_packet_init_with_buffer(MppPacket *packet, MppBuffer buffer);
37 | MPP_RET mpp_packet_copy_init(MppPacket *packet, const MppPacket src);
38 | MPP_RET mpp_packet_deinit(MppPacket *packet);
39 |
40 | /*
41 | * data : ( R/W ) start address of the whole packet memory
42 | * size : ( R/W ) total size of the whole packet memory
43 | * pos : ( R/W ) current access position of the whole packet memory, used for buffer read/write
44 | * length : ( R/W ) the rest length from current position to end of buffer
45 | * NOTE: normally length is updated only by set_pos,
46 | * so set length must be used carefully for special usage
47 | */
48 | void mpp_packet_set_data(MppPacket packet, void *data);
49 | void mpp_packet_set_size(MppPacket packet, size_t size);
50 | void mpp_packet_set_pos(MppPacket packet, void *pos);
51 | void mpp_packet_set_length(MppPacket packet, size_t size);
52 |
53 | void* mpp_packet_get_data(const MppPacket packet);
54 | void* mpp_packet_get_pos(const MppPacket packet);
55 | size_t mpp_packet_get_size(const MppPacket packet);
56 | size_t mpp_packet_get_length(const MppPacket packet);
57 |
58 |
59 | void mpp_packet_set_pts(MppPacket packet, RK_S64 pts);
60 | RK_S64 mpp_packet_get_pts(const MppPacket packet);
61 | void mpp_packet_set_dts(MppPacket packet, RK_S64 dts);
62 | RK_S64 mpp_packet_get_dts(const MppPacket packet);
63 |
64 | void mpp_packet_set_flag(MppPacket packet, RK_U32 flag);
65 | RK_U32 mpp_packet_get_flag(const MppPacket packet);
66 |
67 | MPP_RET mpp_packet_set_eos(MppPacket packet);
68 | RK_U32 mpp_packet_get_eos(MppPacket packet);
69 | MPP_RET mpp_packet_set_extra_data(MppPacket packet);
70 |
71 | void mpp_packet_set_buffer(MppPacket packet, MppBuffer buffer);
72 | MppBuffer mpp_packet_get_buffer(const MppPacket packet);
73 |
74 | /*
75 | * data access interface
76 | */
77 | MPP_RET mpp_packet_read(MppPacket packet, size_t offset, void *data, size_t size);
78 | MPP_RET mpp_packet_write(MppPacket packet, size_t offset, void *data, size_t size);
79 |
80 |
81 | #ifdef __cplusplus
82 | }
83 | #endif
84 |
85 | #endif /*__MPP_PACKET_H__*/
86 |
--------------------------------------------------------------------------------
/rkmediacodec/src/main/jniLibs/include/mpp_task.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015 Rockchip Electronics Co. LTD
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | #ifndef __MPP_TASK_H__
18 | #define __MPP_TASK_H__
19 |
20 | #include "mpp_meta.h"
21 |
22 | /*
23 | * Advanced task flow
24 | * Advanced task flow introduces three concepts: port, task and item
25 | *
26 | * Port is from OpenMAX
27 | * Port has two type: input port and output port which are all for data transaction.
28 | * Port work like a queue. task will be dequeue from or enqueue to one port.
29 | * On input side user will dequeue task from input port, setup task and enqueue task
30 | * back to input port.
31 | * On output side user will dequeue task from output port, get the information from
32 | * and then enqueue task back to output port.
33 | *
34 | * Task indicates one transaction on the port.
35 | * Task has two working mode: async mode and sync mode
36 | * If mpp is work in sync mode on task enqueue function return the task has been done
37 | * If mpp is work in async mode on task enqueue function return the task is just put
38 | * on the task queue for process.
39 | * Task can carry different items. Task just like a container of items
40 | *
41 | * Item indicates MppPacket or MppFrame which is contained in one task
42 | */
43 |
44 | /*
45 | * One mpp task queue has two ports: input and output
46 | *
47 | * The whole picture is:
48 | * Top layer mpp has two ports: mpp_input_port and mpp_output_port
49 | * But internally these two ports belongs to two task queue.
50 | * The mpp_input_port is the mpp_input_task_queue's input port.
51 | * The mpp_output_port is the mpp_output_task_queue's output port.
52 | *
53 | * Each port uses its task queue to communication
54 | */
55 | typedef enum {
56 | MPP_PORT_INPUT,
57 | MPP_PORT_OUTPUT,
58 | MPP_PORT_BUTT,
59 | } MppPortType;
60 |
61 | /*
62 | * Advance task work flow mode:
63 | ******************************************************************************
64 | * 1. async mode (default_val)
65 | *
66 | * mpp_init(type, coding, MPP_WORK_ASYNC)
67 | *
68 | * input thread
69 | * a - dequeue(input, *task)
70 | * b - task_set_item(packet/frame)
71 | * c - enqueue(input, task) // when enqueue return the task is not done yet
72 | *
73 | * output thread
74 | * a - dequeue(output, *task)
75 | * b - task_get_item(frame/packet)
76 | * c - enqueue(output, task)
77 | ******************************************************************************
78 | * 2. sync mode
79 | *
80 | * mpp_init(type, coding, MPP_WORK_SYNC)
81 | *
82 | * a - dequeue(input, *task)
83 | * b - task_set_item(packet/frame)
84 | * c - enqueue(task) // when enqueue return the task is finished
85 | ******************************************************************************
86 | */
87 | typedef enum {
88 | MPP_TASK_ASYNC,
89 | MPP_TASK_SYNC,
90 | MPP_TASK_WORK_MODE_BUTT,
91 | } MppTaskWorkMode;
92 |
93 | /*
94 | * Mpp port pull type
95 | *
96 | * MPP_POLL_BLOCK - for block poll
97 | * MPP_POLL_NON_BLOCK - for non-block poll
98 | * small than MPP_POLL_MAX - for poll with timeout in ms
99 | * small than MPP_POLL_BUTT or larger than MPP_POLL_MAX is invalid value
100 | */
101 | typedef enum {
102 | MPP_POLL_BUTT = -2,
103 | MPP_POLL_BLOCK = -1,
104 | MPP_POLL_NON_BLOCK = 0,
105 | MPP_POLL_MAX = 1000,
106 | } MppPollType;
107 |
108 | /*
109 | * MppTask is descriptor of a task which send to mpp for process
110 | * mpp can support different type of work mode, for example:
111 | *
112 | * decoder:
113 | *
114 | * 1. typical decoder mode:
115 | * input - MppPacket (normal cpu buffer, need cpu copy)
116 | * output - MppFrame (ion/drm buffer in external/internal mode)
117 | * 2. secure decoder mode:
118 | * input - MppPacket (externel ion/drm buffer, cpu can not access)
119 | * output - MppFrame (ion/drm buffer in external/internal mode, cpu can not access)
120 | *
121 | * interface usage:
122 | *
123 | * typical flow
124 | * input side:
125 | * task_dequeue(ctx, PORT_INPUT, &task);
126 | * task_put_item(task, MODE_INPUT, packet)
127 | * task_enqueue(ctx, PORT_INPUT, task);
128 | * output side:
129 | * task_dequeue(ctx, PORT_OUTPUT, &task);
130 | * task_get_item(task, MODE_OUTPUT, &frame)
131 | * task_enqueue(ctx, PORT_OUTPUT, task);
132 | *
133 | * secure flow
134 | * input side:
135 | * task_dequeue(ctx, PORT_INPUT, &task);
136 | * task_put_item(task, MODE_INPUT, packet)
137 | * task_put_item(task, MODE_OUTPUT, frame) // buffer will be specified here
138 | * task_enqueue(ctx, PORT_INPUT, task);
139 | * output side:
140 | * task_dequeue(ctx, PORT_OUTPUT, &task);
141 | * task_get_item(task, MODE_OUTPUT, &frame)
142 | * task_enqueue(ctx, PORT_OUTPUT, task);
143 | *
144 | * encoder:
145 | *
146 | * 1. typical encoder mode:
147 | * input - MppFrame (ion/drm buffer in external mode)
148 | * output - MppPacket (normal cpu buffer, need cpu copy)
149 | * 2. user input encoder mode:
150 | * input - MppFrame (normal cpu buffer, need to build hardware table for this buffer)
151 | * output - MppPacket (normal cpu buffer, need cpu copy)
152 | * 3. secure encoder mode:
153 | * input - MppFrame (ion/drm buffer in external mode, cpu can not access)
154 | * output - MppPacket (externel ion/drm buffer, cpu can not access)
155 | *
156 | * typical / user input flow
157 | * input side:
158 | * task_dequeue(ctx, PORT_INPUT, &task);
159 | * task_put_item(task, MODE_INPUT, frame)
160 | * task_enqueue(ctx, PORT_INPUT, task);
161 | * output side:
162 | * task_dequeue(ctx, PORT_OUTPUT, &task);
163 | * task_get_item(task, MODE_OUTPUT, &packet)
164 | * task_enqueue(ctx, PORT_OUTPUT, task);
165 | *
166 | * secure flow
167 | * input side:
168 | * task_dequeue(ctx, PORT_INPUT, &task);
169 | * task_put_item(task, MODE_OUTPUT, packet) // buffer will be specified here
170 | * task_put_item(task, MODE_INPUT, frame)
171 | * task_enqueue(ctx, PORT_INPUT, task);
172 | * output side:
173 | * task_dequeue(ctx, PORT_OUTPUT, &task);
174 | * task_get_item(task, MODE_OUTPUT, &packet)
175 | * task_get_item(task, MODE_OUTPUT, &frame)
176 | * task_enqueue(ctx, PORT_OUTPUT, task);
177 | *
178 | * NOTE: this flow can specify the output frame. User will setup both intput frame and output packet
179 | * buffer at the input side. Then at output side when user gets a finished task user can get the output
180 | * packet and corresponding released input frame.
181 | *
182 | * image processing
183 | *
184 | * 1. typical image process mode:
185 | * input - MppFrame (ion/drm buffer in external mode)
186 | * output - MppFrame (ion/drm buffer in external mode)
187 | *
188 | * typical / user input flow
189 | * input side:
190 | * task_dequeue(ctx, PORT_INPUT, &task);
191 | * task_put_item(task, MODE_INPUT, frame)
192 | * task_enqueue(ctx, PORT_INPUT, task);
193 | * output side:
194 | * task_dequeue(ctx, PORT_OUTPUT, &task);
195 | * task_get_item(task, MODE_OUTPUT, &frame)
196 | * task_enqueue(ctx, PORT_OUTPUT, task);
197 | */
198 | /* NOTE: use index rather then handle to descripbe task */
199 | typedef void* MppTask;
200 | typedef void* MppPort;
201 | typedef void* MppTaskQueue;
202 |
203 | #ifdef __cplusplus
204 | extern "C" {
205 | #endif
206 |
207 | /*
208 | * Mpp task queue function:
209 | *
210 | * mpp_task_queue_init - create task queue structure
211 | * mpp_task_queue_deinit - destory task queue structure
212 | * mpp_task_queue_get_port - return input or output port of task queue
213 | *
214 | * Typical work flow, task mpp_dec for example:
215 | *
216 | * 1. Mpp layer creates one task queue in order to connect mpp input and mpp_dec input.
217 | * 2. Mpp layer setups the task count in task queue input port.
218 | * 3. Get input port from the task queue and assign to mpp input as mpp_input_port.
219 | * 4. Get output port from the task queue and assign to mpp_dec input as dec_input_port.
220 | * 5. Let the loop start.
221 | * a. mpi user will dequeue task from mpp_input_port.
222 | * b. mpi user will setup task.
223 | * c. mpi user will enqueue task back to mpp_input_port.
224 | * d. task will automatically transfer to dec_input_port.
225 | * e. mpp_dec will dequeue task from dec_input_port.
226 | * f. mpp_dec will process task.
227 | * g. mpp_dec will enqueue task back to dec_input_port.
228 | * h. task will automatically transfer to mpp_input_port.
229 | * 6. Stop the loop. All tasks must be return to input port with idle status.
230 | * 6. Mpp layer destory the task queue.
231 | */
232 | MPP_RET mpp_task_queue_init(MppTaskQueue *queue);
233 | MPP_RET mpp_task_queue_setup(MppTaskQueue queue, RK_S32 task_count);
234 | MPP_RET mpp_task_queue_deinit(MppTaskQueue queue);
235 | MppPort mpp_task_queue_get_port(MppTaskQueue queue, MppPortType type);
236 |
237 | MPP_RET mpp_port_poll(MppPort port, MppPollType timeout);
238 | MPP_RET mpp_port_dequeue(MppPort port, MppTask *task);
239 | MPP_RET mpp_port_enqueue(MppPort port, MppTask task);
240 | MPP_RET mpp_port_awake(MppPort port);
241 |
242 | MPP_RET mpp_task_meta_set_s32(MppTask task, MppMetaKey key, RK_S32 val);
243 | MPP_RET mpp_task_meta_set_s64(MppTask task, MppMetaKey key, RK_S64 val);
244 | MPP_RET mpp_task_meta_set_ptr(MppTask task, MppMetaKey key, void *val);
245 | MPP_RET mpp_task_meta_set_frame (MppTask task, MppMetaKey key, MppFrame frame);
246 | MPP_RET mpp_task_meta_set_packet(MppTask task, MppMetaKey key, MppPacket packet);
247 | MPP_RET mpp_task_meta_set_buffer(MppTask task, MppMetaKey key, MppBuffer buffer);
248 |
249 | MPP_RET mpp_task_meta_get_s32(MppTask task, MppMetaKey key, RK_S32 *val, RK_S32 default_val);
250 | MPP_RET mpp_task_meta_get_s64(MppTask task, MppMetaKey key, RK_S64 *val, RK_S64 default_val);
251 | MPP_RET mpp_task_meta_get_ptr(MppTask task, MppMetaKey key, void **val, void *default_val);
252 | MPP_RET mpp_task_meta_get_frame (MppTask task, MppMetaKey key, MppFrame *frame);
253 | MPP_RET mpp_task_meta_get_packet(MppTask task, MppMetaKey key, MppPacket *packet);
254 | MPP_RET mpp_task_meta_get_buffer(MppTask task, MppMetaKey key, MppBuffer *buffer);
255 |
256 | #ifdef __cplusplus
257 | }
258 | #endif
259 |
260 | #endif /*__MPP_QUEUE_H__*/
261 |
--------------------------------------------------------------------------------
/rkmediacodec/src/main/jniLibs/include/rk_mpi.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015 Rockchip Electronics Co. LTD
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | #ifndef __RK_MPI_H__
18 | #define __RK_MPI_H__
19 |
20 | #include "mpp_task.h"
21 | #include "rk_mpi_cmd.h"
22 |
23 | /**
24 | * @addtogroup rk_mpi
25 | * @brief rockchip media process interface
26 | *
27 | * Mpp provides application programming interface for the application layer.
28 | */
29 |
30 | /**
31 | * @ingroup rk_mpi
32 | * @brief The type of mpp context
33 | */
34 | typedef enum {
35 | MPP_CTX_DEC, /**< decoder */
36 | MPP_CTX_ENC, /**< encoder */
37 | MPP_CTX_ISP, /**< isp */
38 | MPP_CTX_BUTT, /**< undefined */
39 | } MppCtxType;
40 |
41 | /**
42 | * @ingroup rk_mpi
43 | * @brief Enumeration used to define the possible video compression codings.
44 | * sync with the omx_video.h
45 | *
46 | * @note This essentially refers to file extensions. If the coding is
47 | * being used to specify the ENCODE type, then additional work
48 | * must be done to configure the exact flavor of the compression
49 | * to be used. For decode cases where the user application can
50 | * not differentiate between MPEG-4 and H.264 bit streams, it is
51 | * up to the codec to handle this.
52 | */
53 | typedef enum {
54 | MPP_VIDEO_CodingUnused, /**< Value when coding is N/A */
55 | MPP_VIDEO_CodingAutoDetect, /**< Autodetection of coding type */
56 | MPP_VIDEO_CodingMPEG2, /**< AKA: H.262 */
57 | MPP_VIDEO_CodingH263, /**< H.263 */
58 | MPP_VIDEO_CodingMPEG4, /**< MPEG-4 */
59 | MPP_VIDEO_CodingWMV, /**< Windows Media Video (WMV1,WMV2,WMV3)*/
60 | MPP_VIDEO_CodingRV, /**< all versions of Real Video */
61 | MPP_VIDEO_CodingAVC, /**< H.264/AVC */
62 | MPP_VIDEO_CodingMJPEG, /**< Motion JPEG */
63 | MPP_VIDEO_CodingVP8, /**< VP8 */
64 | MPP_VIDEO_CodingVP9, /**< VP9 */
65 | MPP_VIDEO_CodingVC1 = 0x01000000, /**< Windows Media Video (WMV1,WMV2,WMV3)*/
66 | MPP_VIDEO_CodingFLV1, /**< Sorenson H.263 */
67 | MPP_VIDEO_CodingDIVX3, /**< DIVX3 */
68 | MPP_VIDEO_CodingVP6,
69 | MPP_VIDEO_CodingHEVC, /**< H.265/HEVC */
70 | MPP_VIDEO_CodingAVSPLUS, /**< AVS+ */
71 | MPP_VIDEO_CodingAVS, /**< AVS profile=0x20 */
72 | MPP_VIDEO_CodingKhronosExtensions = 0x6F000000, /**< Reserved region for introducing Khronos Standard Extensions */
73 | MPP_VIDEO_CodingVendorStartUnused = 0x7F000000, /**< Reserved region for introducing Vendor Extensions */
74 | MPP_VIDEO_CodingMax = 0x7FFFFFFF
75 | } MppCodingType;
76 |
77 | typedef void* MppCtx;
78 | typedef void* MppParam;
79 |
80 | /*
81 | * in decoder mode application need to specify the coding type first
82 | * send a stream header to mpi ctx using parameter data / size
83 | * and decoder will try to decode the
84 | */
85 | typedef struct MppEncCodecCfg_t {
86 | MppCodingType coding;
87 |
88 | union {
89 | RK_U32 change;
90 | MppEncH264Cfg h264;
91 | MppEncH265Cfg h265;
92 | MppEncJpegCfg jpeg;
93 | MppEncVp8Cfg vp8;
94 | };
95 | } MppEncCodecCfg;
96 |
97 | typedef struct MppEncCfgSet_t {
98 | MppEncPrepCfg prep;
99 | MppEncRcCfg rc;
100 | MppEncCodecCfg codec;
101 | } MppEncCfgSet;
102 |
103 | /**
104 | * @ingroup rk_mpi
105 | * @brief mpp main work function set
106 | *
107 | * @note all api function are seperated into two sets: data io api set and control api set
108 | *
109 | * the data api set is for data input/output flow including:
110 | *
111 | * simple data api set:
112 | *
113 | * decode : both send video stream packet to decoder and get video frame from
114 | * decoder at the same time.
115 | * encode : both send video frame to encoder and get encoded video stream from
116 | * encoder at the same time.
117 | *
118 | * decode_put_packet: send video stream packet to decoder only, async interface
119 | * decode_get_frame : get video frame from decoder only, async interface
120 | *
121 | * encode_put_frame : send video frame to encoder only, async interface
122 | * encode_get_packet: get encoded video packet from encoder only, async interface
123 | *
124 | * advance task api set:
125 | *
126 | *
127 | * the control api set is for mpp context control including:
128 | * control : similiar to ioctl in kernel driver, setup or get mpp internal parameter
129 | * reset : clear all data in mpp context, reset to initialized status
130 | * the simple api set is for simple codec usage including:
131 | *
132 | *
133 | * reset : discard all packet and frame, reset all component,
134 | * for both decoder and encoder
135 | * control : control function for mpp property setting
136 | */
137 | typedef struct MppApi_t {
138 | RK_U32 size;
139 | RK_U32 version;
140 |
141 | // simple data flow interface
142 | /**
143 | * @brief both send video stream packet to decoder and get video frame from
144 | * decoder at the same time
145 | * @param ctx The context of mpp
146 | * @param packet[in] The input video stream
147 | * @param frame[out] The output picture
148 | * @return 0 for decode success, others for failure
149 | */
150 | MPP_RET (*decode)(MppCtx ctx, MppPacket packet, MppFrame *frame);
151 | /**
152 | * @brief send video stream packet to decoder only, async interface
153 | * @param ctx The context of mpp
154 | * @param packet The input video stream
155 | * @return 0 for success, others for failure
156 | */
157 | MPP_RET (*decode_put_packet)(MppCtx ctx, MppPacket packet);
158 | /**
159 | * @brief get video frame from decoder only, async interface
160 | * @param ctx The context of mpp
161 | * @param frame The output picture
162 | * @return 0 for success, others for failure
163 | */
164 | MPP_RET (*decode_get_frame)(MppCtx ctx, MppFrame *frame);
165 | /**
166 | * @brief both send video frame to encoder and get encoded video stream from
167 | * encoder at the same time
168 | * @param ctx The context of mpp
169 | * @param frame[in] The input video data
170 | * @param packet[out] The output compressed data
171 | * @return 0 for encode success, others for failure
172 | */
173 | MPP_RET (*encode)(MppCtx ctx, MppFrame frame, MppPacket *packet);
174 | /**
175 | * @brief send video frame to encoder only, async interface
176 | * @param ctx The context of mpp
177 | * @param frame The input video data
178 | * @return 0 for success, others for failure
179 | */
180 | MPP_RET (*encode_put_frame)(MppCtx ctx, MppFrame frame);
181 | /**
182 | * @brief get encoded video packet from encoder only, async interface
183 | * @param ctx The context of mpp
184 | * @param packet The output compressed data
185 | * @return 0 for success, others for failure
186 | */
187 | MPP_RET (*encode_get_packet)(MppCtx ctx, MppPacket *packet);
188 |
189 | MPP_RET (*isp)(MppCtx ctx, MppFrame dst, MppFrame src);
190 | MPP_RET (*isp_put_frame)(MppCtx ctx, MppFrame frame);
191 | MPP_RET (*isp_get_frame)(MppCtx ctx, MppFrame *frame);
192 |
193 | // advance data flow interface
194 | /**
195 | * @brief poll port for dequeue
196 | * @param ctx The context of mpp
197 | * @param type input port or output port which are both for data transaction
198 | * @return 0 for success there is valid task for dequeue, others for failure
199 | */
200 | MPP_RET (*poll)(MppCtx ctx, MppPortType type, MppPollType timeout);
201 | /**
202 | * @brief dequeue MppTask
203 | * @param ctx The context of mpp
204 | * @param type input port or output port which are both for data transaction
205 | * @param task MppTask which is sent to mpp for process
206 | * @return 0 for success, others for failure
207 | */
208 | MPP_RET (*dequeue)(MppCtx ctx, MppPortType type, MppTask *task);
209 | /**
210 | * @brief enqueue MppTask
211 | * @param ctx The context of mpp
212 | * @param type input port or output port which are both for data transaction
213 | * @param task MppTask which is sent to mpp for process
214 | * @return 0 for success, others for failure
215 | */
216 | MPP_RET (*enqueue)(MppCtx ctx, MppPortType type, MppTask task);
217 |
218 | // control interface
219 | /**
220 | * @brief discard all packet and frame, reset all component,
221 | * for both decoder and encoder
222 | * @param ctx The context of mpp
223 | */
224 | MPP_RET (*reset)(MppCtx ctx);
225 | /**
226 | * @brief control function for mpp property setting
227 | * @param ctx The context of mpp
228 | * @param cmd The mpi command
229 | * @param param The mpi command parameter
230 | * @return 0 for success, others for failure
231 | */
232 | MPP_RET (*control)(MppCtx ctx, MpiCmd cmd, MppParam param);
233 |
234 | /**
235 | * @brief The reserved segment
236 | */
237 | RK_U32 reserv[16];
238 | } MppApi;
239 |
240 |
241 | #ifdef __cplusplus
242 | extern "C" {
243 | #endif
244 |
245 | /**
246 | * @ingroup rk_mpi
247 | * @brief Create empty context structure and mpi function pointers.
248 | * Use functions in MppApi to access mpp services.
249 | * @param ctx pointer of the mpp context
250 | * @param mpi pointer of mpi function
251 | */
252 | MPP_RET mpp_create(MppCtx *ctx, MppApi **mpi);
253 | /**
254 | * @ingroup rk_mpi
255 | * @brief Call after mpp_create to setup mpp type and video format.
256 | * This function will call internal context init function.
257 | * @param ctx The context of mpp
258 | * @param type MppCtxType, decoder or encoder
259 | * @param coding video compression coding
260 | */
261 | MPP_RET mpp_init(MppCtx ctx, MppCtxType type, MppCodingType coding);
262 | /**
263 | * @ingroup rk_mpi
264 | * @brief Destroy mpp context and free both context and mpi structure
265 | * @param ctx The context of mpp
266 | */
267 | MPP_RET mpp_destroy(MppCtx ctx);
268 |
269 | // coding type format function
270 | MPP_RET mpp_check_support_format(MppCtxType type, MppCodingType coding);
271 | void mpp_show_support_format(void);
272 |
273 | #ifdef __cplusplus
274 | }
275 | #endif
276 |
277 | #endif /*__RK_MPI_H__*/
278 |
--------------------------------------------------------------------------------
/rkmediacodec/src/main/jniLibs/include/rk_type.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015 Rockchip Electronics Co. LTD
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | #ifndef __RK_TYPE_H__
18 | #define __RK_TYPE_H__
19 |
20 | #include
21 |
22 | #if defined(_WIN32) && !defined(__MINGW32CE__)
23 |
24 | typedef unsigned char RK_U8;
25 | typedef unsigned short RK_U16;
26 | typedef unsigned int RK_U32;
27 | typedef unsigned __int64 RK_U64;
28 |
29 | typedef signed char RK_S8;
30 | typedef signed short RK_S16;
31 | typedef signed int RK_S32;
32 | typedef signed __int64 RK_S64;
33 |
34 | #else
35 |
36 | typedef unsigned char RK_U8;
37 | typedef unsigned short RK_U16;
38 | typedef unsigned int RK_U32;
39 | typedef unsigned long long int RK_U64;
40 |
41 |
42 | typedef signed char RK_S8;
43 | typedef signed short RK_S16;
44 | typedef signed int RK_S32;
45 | typedef signed long long int RK_S64;
46 |
47 | #endif
48 |
49 | #ifndef MODULE_TAG
50 | #define MODULE_TAG NULL
51 | #endif
52 |
53 |
54 |
55 | #endif /*__RK_TYPE_H__*/
56 |
--------------------------------------------------------------------------------
/rkmediacodec/src/main/jniLibs/include/vpu.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015 Rockchip Electronics Co. LTD
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | #ifndef __VPU_H__
18 | #define __VPU_H__
19 |
20 | #ifdef __cplusplus
21 | extern "C"
22 | {
23 | #endif
24 |
25 | #include "rk_type.h"
26 |
27 | #define VPU_SUCCESS (0)
28 | #define VPU_FAILURE (-1)
29 |
30 | #define VPU_HW_WAIT_OK VPU_SUCCESS
31 | #define VPU_HW_WAIT_ERROR VPU_FAILURE
32 | #define VPU_HW_WAIT_TIMEOUT 1
33 |
34 | // vpu decoder 60 registers, size 240B
35 | #define VPU_REG_NUM_DEC (60)
36 | // vpu post processor 41 registers, size 164B
37 | #define VPU_REG_NUM_PP (41)
38 | // vpu decoder + post processor 101 registers, size 404B
39 | #define VPU_REG_NUM_DEC_PP (VPU_REG_NUM_DEC+VPU_REG_NUM_PP)
40 | // vpu encoder 96 registers, size 384B
41 | #define VPU_REG_NUM_ENC (96)
42 |
43 | typedef enum {
44 |
45 | VPU_ENC = 0x0,
46 | VPU_DEC = 0x1,
47 | VPU_PP = 0x2,
48 | VPU_DEC_PP = 0x3,
49 | VPU_DEC_HEVC = 0x4,
50 | VPU_DEC_RKV = 0x5,
51 | VPU_ENC_RKV = 0x6,
52 | VPU_DEC_AVS = 0x7,
53 | VPU_TYPE_BUTT ,
54 |
55 | } VPU_CLIENT_TYPE;
56 |
57 | /* Hardware decoder configuration description */
58 |
59 | typedef struct VPUHwDecConfig {
60 | RK_U32 maxDecPicWidth; /* Maximum video decoding width supported */
61 | RK_U32 maxPpOutPicWidth; /* Maximum output width of Post-Processor */
62 | RK_U32 h264Support; /* HW supports h.264 */
63 | RK_U32 jpegSupport; /* HW supports JPEG */
64 | RK_U32 mpeg4Support; /* HW supports MPEG-4 */
65 | RK_U32 customMpeg4Support; /* HW supports custom MPEG-4 features */
66 | RK_U32 vc1Support; /* HW supports VC-1 Simple */
67 | RK_U32 mpeg2Support; /* HW supports MPEG-2 */
68 | RK_U32 ppSupport; /* HW supports post-processor */
69 | RK_U32 ppConfig; /* HW post-processor functions bitmask */
70 | RK_U32 sorensonSparkSupport; /* HW supports Sorenson Spark */
71 | RK_U32 refBufSupport; /* HW supports reference picture buffering */
72 | RK_U32 vp6Support; /* HW supports VP6 */
73 | RK_U32 vp7Support; /* HW supports VP7 */
74 | RK_U32 vp8Support; /* HW supports VP8 */
75 | RK_U32 avsSupport; /* HW supports AVS */
76 | RK_U32 jpegESupport; /* HW supports JPEG extensions */
77 | RK_U32 rvSupport; /* HW supports REAL */
78 | RK_U32 mvcSupport; /* HW supports H264 MVC extension */
79 | } VPUHwDecConfig_t;
80 |
81 | /* Hardware encoder configuration description */
82 |
83 | typedef struct VPUHwEndConfig {
84 | RK_U32 maxEncodedWidth; /* Maximum supported width for video encoding (not JPEG) */
85 | RK_U32 h264Enabled; /* HW supports H.264 */
86 | RK_U32 jpegEnabled; /* HW supports JPEG */
87 | RK_U32 mpeg4Enabled; /* HW supports MPEG-4 */
88 | RK_U32 vsEnabled; /* HW supports video stabilization */
89 | RK_U32 rgbEnabled; /* HW supports RGB input */
90 | RK_U32 reg_size; /* HW bus type in use */
91 | RK_U32 reserv[2];
92 | } VPUHwEncConfig_t;
93 |
94 | typedef enum {
95 |
96 | // common command
97 | VPU_CMD_REGISTER ,
98 | VPU_CMD_REGISTER_ACK_OK ,
99 | VPU_CMD_REGISTER_ACK_FAIL ,
100 | VPU_CMD_UNREGISTER ,
101 |
102 | VPU_SEND_CONFIG ,
103 | VPU_SEND_CONFIG_ACK_OK ,
104 | VPU_SEND_CONFIG_ACK_FAIL ,
105 |
106 | VPU_GET_HW_INFO ,
107 | VPU_GET_HW_INFO_ACK_OK ,
108 | VPU_GET_HW_INFO_ACK_FAIL ,
109 |
110 | VPU_CMD_BUTT ,
111 | } VPU_CMD_TYPE;
112 |
113 | int VPUClientInit(VPU_CLIENT_TYPE type);
114 | RK_S32 VPUClientRelease(int socket);
115 | RK_S32 VPUClientSendReg(int socket, RK_U32 *regs, RK_U32 nregs);
116 | RK_S32 VPUClientSendReg2(RK_S32 socket, RK_S32 offset, RK_S32 size, void *param);
117 | RK_S32 VPUClientWaitResult(int socket, RK_U32 *regs, RK_U32 nregs, VPU_CMD_TYPE *cmd, RK_S32 *len);
118 | RK_S32 VPUClientGetHwCfg(int socket, RK_U32 *cfg, RK_U32 cfg_size);
119 | RK_S32 VPUClientGetIOMMUStatus();
120 | RK_U32 VPUCheckSupportWidth();
121 |
122 | #ifdef __cplusplus
123 | }
124 |
125 | #endif
126 |
127 | #endif /* __VPU_H__ */
128 |
129 |
130 |
--------------------------------------------------------------------------------
/rkmediacodec/src/main/jniLibs/include/vpu_api.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015 Rockchip Electronics Co. LTD
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | #ifndef __VPU_API_LEGACY_H__
18 | #define __VPU_API_LEGACY_H__
19 |
20 | #include "rk_type.h"
21 | #include "mpp_err.h"
22 |
23 | /**
24 | * @brief rockchip media process interface
25 | */
26 |
27 | #define VPU_API_NOPTS_VALUE (0x8000000000000000LL)
28 |
29 | /*
30 | * bit definition of ColorType in structure VPU_FRAME
31 | */
32 | #define VPU_OUTPUT_FORMAT_TYPE_MASK (0x0000ffff)
33 | #define VPU_OUTPUT_FORMAT_ARGB8888 (0x00000000)
34 | #define VPU_OUTPUT_FORMAT_ABGR8888 (0x00000001)
35 | #define VPU_OUTPUT_FORMAT_RGB888 (0x00000002)
36 | #define VPU_OUTPUT_FORMAT_RGB565 (0x00000003)
37 | #define VPU_OUTPUT_FORMAT_RGB555 (0x00000004)
38 | #define VPU_OUTPUT_FORMAT_YUV420_SEMIPLANAR (0x00000005)
39 | #define VPU_OUTPUT_FORMAT_YUV420_PLANAR (0x00000006)
40 | #define VPU_OUTPUT_FORMAT_YUV422 (0x00000007)
41 | #define VPU_OUTPUT_FORMAT_YUV444 (0x00000008)
42 | #define VPU_OUTPUT_FORMAT_YCH420 (0x00000009)
43 | #define VPU_OUTPUT_FORMAT_BIT_MASK (0x000f0000)
44 | #define VPU_OUTPUT_FORMAT_BIT_8 (0x00000000)
45 | #define VPU_OUTPUT_FORMAT_BIT_10 (0x00010000)
46 | #define VPU_OUTPUT_FORMAT_BIT_12 (0x00020000)
47 | #define VPU_OUTPUT_FORMAT_BIT_14 (0x00030000)
48 | #define VPU_OUTPUT_FORMAT_BIT_16 (0x00040000)
49 | #define VPU_OUTPUT_FORMAT_COLORSPACE_MASK (0x00f00000)
50 | #define VPU_OUTPUT_FORMAT_COLORSPACE_BT709 (0x00100000)
51 | #define VPU_OUTPUT_FORMAT_COLORSPACE_BT2020 (0x00200000)
52 | #define VPU_OUTPUT_FORMAT_DYNCRANGE_MASK (0x0f000000)
53 | #define VPU_OUTPUT_FORMAT_DYNCRANGE_SDR (0x00000000)
54 | #define VPU_OUTPUT_FORMAT_DYNCRANGE_HDR10 (0x01000000)
55 | #define VPU_OUTPUT_FORMAT_DYNCRANGE_HDR_HLG (0x02000000)
56 | #define VPU_OUTPUT_FORMAT_DYNCRANGE_HDR_DOLBY (0x03000000)
57 |
58 | /**
59 | * @brief input picture type
60 | */
61 | typedef enum {
62 | ENC_INPUT_YUV420_PLANAR = 0, /**< YYYY... UUUU... VVVV */
63 | ENC_INPUT_YUV420_SEMIPLANAR = 1, /**< YYYY... UVUVUV... */
64 | ENC_INPUT_YUV422_INTERLEAVED_YUYV = 2, /**< YUYVYUYV... */
65 | ENC_INPUT_YUV422_INTERLEAVED_UYVY = 3, /**< UYVYUYVY... */
66 | ENC_INPUT_RGB565 = 4, /**< 16-bit RGB */
67 | ENC_INPUT_BGR565 = 5, /**< 16-bit RGB */
68 | ENC_INPUT_RGB555 = 6, /**< 15-bit RGB */
69 | ENC_INPUT_BGR555 = 7, /**< 15-bit RGB */
70 | ENC_INPUT_RGB444 = 8, /**< 12-bit RGB */
71 | ENC_INPUT_BGR444 = 9, /**< 12-bit RGB */
72 | ENC_INPUT_RGB888 = 10, /**< 24-bit RGB */
73 | ENC_INPUT_BGR888 = 11, /**< 24-bit RGB */
74 | ENC_INPUT_RGB101010 = 12, /**< 30-bit RGB */
75 | ENC_INPUT_BGR101010 = 13 /**< 30-bit RGB */
76 | } EncInputPictureType;
77 |
78 | typedef enum VPU_API_CMD {
79 | VPU_API_ENC_SETCFG,
80 | VPU_API_ENC_GETCFG,
81 | VPU_API_ENC_SETFORMAT,
82 | VPU_API_ENC_SETIDRFRAME,
83 |
84 | VPU_API_ENABLE_DEINTERLACE,
85 | VPU_API_SET_VPUMEM_CONTEXT,
86 | VPU_API_USE_PRESENT_TIME_ORDER,
87 | VPU_API_SET_DEFAULT_WIDTH_HEIGH,
88 | VPU_API_SET_INFO_CHANGE,
89 | VPU_API_USE_FAST_MODE,
90 | VPU_API_DEC_GET_STREAM_COUNT,
91 | VPU_API_GET_VPUMEM_USED_COUNT,
92 | VPU_API_GET_FRAME_INFO,
93 | VPU_API_SET_OUTPUT_BLOCK,
94 | VPU_API_GET_EOS_STATUS,
95 | } VPU_API_CMD;
96 |
97 | typedef struct {
98 | RK_U32 TimeLow;
99 | RK_U32 TimeHigh;
100 | } TIME_STAMP;
101 |
102 | typedef struct {
103 | RK_U32 CodecType;
104 | RK_U32 ImgWidth;
105 | RK_U32 ImgHeight;
106 | RK_U32 ImgHorStride;
107 | RK_U32 ImgVerStride;
108 | RK_U32 BufSize;
109 | } VPU_GENERIC;
110 |
111 | typedef struct VPUMem {
112 | RK_U32 phy_addr;
113 | RK_U32 *vir_addr;
114 | RK_U32 size;
115 | RK_U32 *offset;
116 | } VPUMemLinear_t;
117 |
118 | typedef struct tVPU_FRAME {
119 | RK_U32 FrameBusAddr[2]; // 0: Y address; 1: UV address;
120 | RK_U32 FrameWidth; // buffer horizontal stride
121 | RK_U32 FrameHeight; // buffer vertical stride
122 | RK_U32 OutputWidth; // deprecated
123 | RK_U32 OutputHeight; // deprecated
124 | RK_U32 DisplayWidth; // valid width for display
125 | RK_U32 DisplayHeight; // valid height for display
126 | RK_U32 CodingType;
127 | RK_U32 FrameType; // frame; top_field_first; bot_field_first
128 | RK_U32 ColorType;
129 | RK_U32 DecodeFrmNum;
130 | TIME_STAMP ShowTime;
131 | RK_U32 ErrorInfo; // error information
132 | RK_U32 employ_cnt;
133 | VPUMemLinear_t vpumem;
134 | struct tVPU_FRAME *next_frame;
135 | RK_U32 Res[4];
136 | } VPU_FRAME;
137 |
138 | typedef struct VideoPacket {
139 | RK_S64 pts; /* with unit of us*/
140 | RK_S64 dts; /* with unit of us*/
141 | RK_U8 *data;
142 | RK_S32 size;
143 | RK_U32 capability;
144 | RK_U32 nFlags;
145 | } VideoPacket_t;
146 |
147 | typedef struct DecoderOut {
148 | RK_U8 *data;
149 | RK_U32 size;
150 | RK_S64 timeUs;
151 | RK_S32 nFlags;
152 | } DecoderOut_t;
153 |
154 | typedef struct ParserOut {
155 | RK_U8 *data;
156 | RK_U32 size;
157 | RK_S64 timeUs;
158 | RK_U32 nFlags;
159 | RK_U32 width;
160 | RK_U32 height;
161 | } ParserOut_t;
162 |
163 | typedef struct EncInputStream {
164 | RK_U8 *buf;
165 | RK_S32 size;
166 | RK_U32 bufPhyAddr;
167 | RK_S64 timeUs;
168 | RK_U32 nFlags;
169 | } EncInputStream_t;
170 |
171 | typedef struct EncoderOut {
172 | RK_U8 *data;
173 | RK_S32 size;
174 | RK_S64 timeUs;
175 | RK_S32 keyFrame;
176 |
177 | } EncoderOut_t;
178 |
179 | /*
180 | * @brief Enumeration used to define the possible video compression codings.
181 | * @note This essentially refers to file extensions. If the coding is
182 | * being used to specify the ENCODE type, then additional work
183 | * must be done to configure the exact flavor of the compression
184 | * to be used. For decode cases where the user application can
185 | * not differentiate between MPEG-4 and H.264 bit streams, it is
186 | * up to the codec to handle this.
187 | *
188 | * sync with the omx_video.h
189 | */
190 | typedef enum OMX_RK_VIDEO_CODINGTYPE {
191 | OMX_RK_VIDEO_CodingUnused, /**< Value when coding is N/A */
192 | OMX_RK_VIDEO_CodingAutoDetect, /**< Autodetection of coding type */
193 | OMX_RK_VIDEO_CodingMPEG2, /**< AKA: H.262 */
194 | OMX_RK_VIDEO_CodingH263, /**< H.263 */
195 | OMX_RK_VIDEO_CodingMPEG4, /**< MPEG-4 */
196 | OMX_RK_VIDEO_CodingWMV, /**< Windows Media Video (WMV1,WMV2,WMV3)*/
197 | OMX_RK_VIDEO_CodingRV, /**< all versions of Real Video */
198 | OMX_RK_VIDEO_CodingAVC, /**< H.264/AVC */
199 | OMX_RK_VIDEO_CodingMJPEG, /**< Motion JPEG */
200 | OMX_RK_VIDEO_CodingVP8, /**< VP8 */
201 | OMX_RK_VIDEO_CodingVP9, /**< VP9 */
202 | OMX_RK_VIDEO_CodingVC1 = 0x01000000, /**< Windows Media Video (WMV1,WMV2,WMV3)*/
203 | OMX_RK_VIDEO_CodingFLV1, /**< Sorenson H.263 */
204 | OMX_RK_VIDEO_CodingDIVX3, /**< DIVX3 */
205 | OMX_RK_VIDEO_CodingVP6,
206 | OMX_RK_VIDEO_CodingHEVC, /**< H.265/HEVC */
207 | OMX_RK_VIDEO_CodingAVS, /**< AVS+ */
208 | OMX_RK_VIDEO_CodingKhronosExtensions = 0x6F000000, /**< Reserved region for introducing Khronos Standard Extensions */
209 | OMX_RK_VIDEO_CodingVendorStartUnused = 0x7F000000, /**< Reserved region for introducing Vendor Extensions */
210 | OMX_RK_VIDEO_CodingMax = 0x7FFFFFFF
211 | } OMX_RK_VIDEO_CODINGTYPE;
212 |
213 | typedef enum CODEC_TYPE {
214 | CODEC_NONE,
215 | CODEC_DECODER,
216 | CODEC_ENCODER,
217 | CODEC_BUTT,
218 | } CODEC_TYPE;
219 |
220 | typedef enum VPU_API_ERR {
221 | VPU_API_OK = 0,
222 | VPU_API_ERR_UNKNOW = -1,
223 | VPU_API_ERR_BASE = -1000,
224 | VPU_API_ERR_LIST_STREAM = VPU_API_ERR_BASE - 1,
225 | VPU_API_ERR_INIT = VPU_API_ERR_BASE - 2,
226 | VPU_API_ERR_VPU_CODEC_INIT = VPU_API_ERR_BASE - 3,
227 | VPU_API_ERR_STREAM = VPU_API_ERR_BASE - 4,
228 | VPU_API_ERR_FATAL_THREAD = VPU_API_ERR_BASE - 5,
229 | VPU_API_EOS_STREAM_REACHED = VPU_API_ERR_BASE - 11,
230 |
231 | VPU_API_ERR_BUTT,
232 | } VPU_API_ERR;
233 |
234 | typedef enum VPU_FRAME_ERR {
235 | VPU_FRAME_ERR_UNKNOW = 0x0001,
236 | VPU_FRAME_ERR_UNSUPPORT = 0x0002,
237 |
238 | } VPU_FRAME_ERR;
239 |
240 | typedef struct EncParameter {
241 | RK_S32 width;
242 | RK_S32 height;
243 | RK_S32 rc_mode; /* 0 - CQP mode; 1 - CBR mode; */
244 | RK_S32 bitRate; /* target bitrate */
245 | RK_S32 framerate;
246 | RK_S32 qp;
247 | RK_S32 enableCabac;
248 | RK_S32 cabacInitIdc;
249 | RK_S32 format;
250 | RK_S32 intraPicRate;
251 | RK_S32 framerateout;
252 | RK_S32 profileIdc;
253 | RK_S32 levelIdc;
254 | RK_S32 reserved[3];
255 | } EncParameter_t;
256 |
257 | typedef struct EXtraCfg {
258 | RK_S32 vc1extra_size;
259 | RK_S32 vp6codeid;
260 | RK_S32 tsformat;
261 | RK_U32 ori_vpu; /* use origin vpu framework */
262 | /* below used in decode */
263 | RK_U32 mpp_mode; /* use mpp framework */
264 | RK_U32 bit_depth; /* 8 or 10 bit */
265 | RK_U32 yuv_format; /* 0:420 1:422 2:444 */
266 | RK_U32 reserved[16];
267 | } EXtraCfg_t;
268 |
269 | /**
270 | * @brief vpu function interface
271 | */
272 | typedef struct VpuCodecContext {
273 | void* vpuApiObj;
274 |
275 | CODEC_TYPE codecType;
276 | OMX_RK_VIDEO_CODINGTYPE videoCoding;
277 |
278 | RK_U32 width;
279 | RK_U32 height;
280 | void *extradata;
281 | RK_S32 extradata_size;
282 |
283 | RK_U8 enableparsing;
284 |
285 | RK_S32 no_thread;
286 | EXtraCfg_t extra_cfg;
287 |
288 | void* private_data;
289 |
290 | /*
291 | ** 1: error state(not working) 0: working
292 | */
293 | RK_S32 decoder_err;
294 |
295 |
296 | /**
297 | * Allocate and initialize an VpuCodecContext.
298 | *
299 | * @param ctx The context of vpu api, allocated in this function.
300 | * @param extraData The extra data of codec, some codecs need / can
301 | * use extradata like Huffman tables, also live VC1 codec can
302 | * use extradata to initialize itself.
303 | * @param extra_size The size of extra data.
304 | *
305 | * @return 0 for init success, others for failure.
306 | * @note check whether ctx has been allocated success after you do init.
307 | */
308 | RK_S32 (*init)(struct VpuCodecContext *ctx, RK_U8 *extraData, RK_U32 extra_size);
309 | /**
310 | * @brief both send video stream packet to decoder and get video frame from
311 | * decoder at the same time
312 | * @param ctx The context of vpu codec
313 | * @param pkt[in] Stream to be decoded
314 | * @param aDecOut[out] Decoding frame
315 | * @return 0 for decode success, others for failure.
316 | */
317 | RK_S32 (*decode)(struct VpuCodecContext *ctx, VideoPacket_t *pkt, DecoderOut_t *aDecOut);
318 | /**
319 | * @brief both send video frame to encoder and get encoded video stream from
320 | * encoder at the same time.
321 | * @param ctx The context of vpu codec
322 | * @param aEncInStrm[in] Frame to be encoded
323 | * @param aEncOut[out] Encoding stream
324 | * @return 0 for encode success, others for failure.
325 | */
326 | RK_S32 (*encode)(struct VpuCodecContext *ctx, EncInputStream_t *aEncInStrm, EncoderOut_t *aEncOut);
327 | /**
328 | * @brief flush codec while do fast forward playing.
329 | * @param ctx The context of vpu codec
330 | * @return 0 for flush success, others for failure.
331 | */
332 | RK_S32 (*flush)(struct VpuCodecContext *ctx);
333 | RK_S32 (*control)(struct VpuCodecContext *ctx, VPU_API_CMD cmdType, void* param);
334 | /**
335 | * @brief send video stream packet to decoder only, async interface
336 | * @param ctx The context of vpu codec
337 | * @param pkt Stream to be decoded
338 | * @return 0 for success, others for failure.
339 | */
340 | RK_S32 (*decode_sendstream)(struct VpuCodecContext *ctx, VideoPacket_t *pkt);
341 | /**
342 | * @brief get video frame from decoder only, async interface
343 | * @param ctx The context of vpu codec
344 | * @param aDecOut Decoding frame
345 | * @return 0 for success, others for failure.
346 | */
347 | RK_S32 (*decode_getframe)(struct VpuCodecContext *ctx, DecoderOut_t *aDecOut);
348 | /**
349 | * @brief send video frame to encoder only, async interface
350 | * @param ctx The context of vpu codec
351 | * @param aEncInStrm Frame to be encoded
352 | * @return 0 for success, others for failure.
353 | */
354 | RK_S32 (*encoder_sendframe)(struct VpuCodecContext *ctx, EncInputStream_t *aEncInStrm);
355 | /**
356 | * @brief get encoded video packet from encoder only, async interface
357 | * @param ctx The context of vpu codec
358 | * @param aEncOut Encoding stream
359 | * @return 0 for success, others for failure.
360 | */
361 | RK_S32 (*encoder_getstream)(struct VpuCodecContext *ctx, EncoderOut_t *aEncOut);
362 | } VpuCodecContext_t;
363 |
364 | /* allocated vpu codec context */
365 | #ifdef __cplusplus
366 | extern "C"
367 | {
368 | #endif
369 |
370 | /**
371 | * @brief open context of vpu
372 | * @param ctx pointer of vpu codec context
373 | */
374 | RK_S32 vpu_open_context(struct VpuCodecContext **ctx);
375 | /**
376 | * @brief close context of vpu
377 | * @param ctx pointer of vpu codec context
378 | */
379 | RK_S32 vpu_close_context(struct VpuCodecContext **ctx);
380 |
381 | #ifdef __cplusplus
382 | }
383 | #endif
384 |
385 | /*
386 | * vpu_mem api
387 | */
388 | #define vpu_display_mem_pool_FIELDS \
389 | RK_S32 (*commit_hdl)(vpu_display_mem_pool *p, RK_S32 hdl, RK_S32 size); \
390 | void* (*get_free)(vpu_display_mem_pool *p); \
391 | RK_S32 (*inc_used)(vpu_display_mem_pool *p, void *hdl); \
392 | RK_S32 (*put_used)(vpu_display_mem_pool *p, void *hdl); \
393 | RK_S32 (*reset)(vpu_display_mem_pool *p); \
394 | RK_S32 (*get_unused_num)(vpu_display_mem_pool *p); \
395 | RK_S32 buff_size;\
396 | float version; \
397 | RK_S32 res[18];
398 |
399 | typedef struct vpu_display_mem_pool vpu_display_mem_pool;
400 |
401 | struct vpu_display_mem_pool {
402 | vpu_display_mem_pool_FIELDS
403 | };
404 |
405 | #ifdef __cplusplus
406 | extern "C"
407 | {
408 | #endif
409 |
410 | /*
411 | * vpu memory handle interface
412 | */
413 | RK_S32 VPUMemJudgeIommu(void);
414 | RK_S32 VPUMallocLinear(VPUMemLinear_t *p, RK_U32 size);
415 | RK_S32 VPUFreeLinear(VPUMemLinear_t *p);
416 | RK_S32 VPUMemDuplicate(VPUMemLinear_t *dst, VPUMemLinear_t *src);
417 | RK_S32 VPUMemLink(VPUMemLinear_t *p);
418 | RK_S32 VPUMemFlush(VPUMemLinear_t *p);
419 | RK_S32 VPUMemClean(VPUMemLinear_t *p);
420 | RK_S32 VPUMemInvalidate(VPUMemLinear_t *p);
421 | RK_S32 VPUMemGetFD(VPUMemLinear_t *p);
422 | RK_S32 VPUMallocLinearFromRender(VPUMemLinear_t *p, RK_U32 size, void *ctx);
423 |
424 | /*
425 | * vpu memory allocator and manager interface
426 | */
427 | vpu_display_mem_pool* open_vpu_memory_pool(void);
428 | void close_vpu_memory_pool(vpu_display_mem_pool *p);
429 | int create_vpu_memory_pool_allocator(vpu_display_mem_pool **ipool, int num, int size);
430 | void release_vpu_memory_pool_allocator(vpu_display_mem_pool *ipool);
431 |
432 | #ifdef __cplusplus
433 | }
434 | #endif
435 |
436 | #endif /*__VPU_API_LEGACY_H__*/
437 |
--------------------------------------------------------------------------------
/rkmediacodec/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | RKMediaCodec
3 |
4 |
--------------------------------------------------------------------------------
/rkmediacodec/src/test/java/com/rockchip/rkmediacodec/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.rockchip.rkmediacodec;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest {
13 | @Test
14 | public void addition_isCorrect() throws Exception {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app', ':rkmediacodec'
2 |
--------------------------------------------------------------------------------