Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions AppDemo/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
*.iml
.gradle
/local.properties
/.idea/caches
/.idea/libraries
/.idea/modules.xml
/.idea/workspace.xml
/.idea/navEditor.xml
/.idea/assetWizardSettings.xml
.DS_Store
/build
/captures
.externalNativeBuild
.cxx
local.properties
4 changes: 4 additions & 0 deletions AppDemo/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
AppDemo是针对指令流的《Kunpeng Computting Media 2.0 RC2 指令流引擎 开发指南》的第三章指令流客户端的开发Demo的apk。

本Demo只是方便用户参考apk开发流程,不能代表其apk能够正常满足用户的要求。

1 change: 1 addition & 0 deletions AppDemo/app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
91 changes: 91 additions & 0 deletions AppDemo/app/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
plugins {
id 'com.android.application'
}

android {
compileSdk 31

defaultConfig {
applicationId "com.huawei.baseuidemo"
minSdk 24
targetSdk 31
versionCode 1
versionName "1.0"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

ndk {
abiFilters "armeabi-v7a"
moduleName "libdrco"
moduleName "libGLESv2_dec"
moduleName "libopus"
moduleName "libOpenglRender"
moduleName "libzstd"
moduleName "libcomm"
moduleName "libemugl_common"
moduleName "libOpenglCodecCommon"
moduleName "libGLESv1_dec"
moduleName "libvncmain"
moduleName "libGLSnapshot"
moduleName "libOpenGLESDispatch"
moduleName "librenderControl"
moduleName "libhandshake"
}

externalNativeBuild {
cmake {
cppFlags "-std=c++1z -fPIC -fno-rtti -Werror -Wreturn-type -Wformat -fexceptions"
cppFlags "-DBUILD_UNITY_PLUGIN"
arguments "-DCMAKE_VERBOSE_MAKEFILE:BOOL=ON"
arguments "-DANDROID_STL=c++_static"
arguments "-DVMI_BINARY_DIR="+file(".")+"/jniLibs"
}

ndk {
abiFilters 'armeabi-v7a'
}
}
packagingOptions {
pickFirst "lib/armeabi-v7a/libVmiLog.so"
pickFirst "lib/armeabi-v7a/libVmiHWSecure.so"
pickFirst "lib/armeabi-v7a/libVmiInstrCommon.so"
pickFirst "lib/armeabi-v7a/libVmiInstructionCommon.so"
pickFirst "lib/armeabi-v7a/libInstructionEngineClient.so"
pickFirst "lib/armeabi-v7a/libc++_shared.so"
pickFirst '/lib/armeabi-v7a/libCommunication.so'
}
}

buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
externalNativeBuild {
cmake {
path file('src/main/cpp/CMakeLists.txt')
version '3.10.2'
}
}
buildFeatures {
viewBinding true
}
lintOptions
}

dependencies {
implementation fileTree(dir: 'libs', includes: ['*.jar', '*.aar'])
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'com.google.android.material:material:1.3.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
implementation 'androidx.navigation:navigation-fragment:2.3.5'
implementation 'androidx.navigation:navigation-ui:2.3.5'
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
}
21 changes: 21 additions & 0 deletions AppDemo/app/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.huawei.baseuidemo;

import static org.junit.Assert.assertEquals;

import android.content.Context;

import androidx.test.ext.junit.runners.AndroidJUnit4;
import androidx.test.platform.app.InstrumentationRegistry;

import org.junit.Test;
import org.junit.runner.RunWith;

/**
* Instrumented test, which will execute on an Android device.
*
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
*/
@RunWith(AndroidJUnit4.class)
public class ExampleInstrumentedTest {
@Test
public void useAppContext() {
// Context of the app under test.
Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
assertEquals("com.huawei.baseuidemo", appContext.getPackageName());
}
}
38 changes: 38 additions & 0 deletions AppDemo/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.huawei.baseuidemo" >
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS"/>
<uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES"/>

<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
<uses-permission android:name="android.permission.WRITE_SETTINGS"/>
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
<uses-permission android:name="android.permission.RECORD_AUDIO"/>

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.AppCompat.NoActionBar">
<activity
android:name=".BaseUiActivity"
android:process=":remote"
android:exported="true" />
<activity
android:name=".ConnectActivity"
android:exported="true" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

</manifest>
40 changes: 40 additions & 0 deletions AppDemo/app/src/main/cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
cmake_minimum_required(VERSION 3.6)
project(InstructionEngineJni)
set(NORMAL_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14" )
set(CMAKE_SKIP_RPATH TRUE)
set(CMAKE_CXX_FLAGS "${NORMAL_CXX_FLAGS}")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_FORTIFY_SOURCE=2 -O2")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_FORTIFY_SOURCE=2 -O2")
set(DISTRIBUTION_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../jniLibs/armeabi-v7a)

add_library(InstructionEngineJni SHARED
InstructionEngineJni.cpp)

add_library(InstructionEngineClient
SHARED
IMPORTED)
set_target_properties(InstructionEngineClient
PROPERTIES IMPORTED_LOCATION
${DISTRIBUTION_DIR}/libInstructionEngineClient.so)
find_library(android-lib android)

target_compile_options(InstructionEngineJni PRIVATE
-Wpedantic -pedantic-errors -Wextra -Werror
-Wno-zero-length-array
-Wno-gnu-zero-variadic-macro-arguments
-Wno-unused-command-line-argument
-Wall -Wformat
-Wno-undefined-var-template
-D_FORTIFY_SOURCE=2 -O2
)

target_link_libraries(InstructionEngineJni
PRIVATE
-static-libgcc
-static-libstdc++
-ldl
android
InstructionEngineClient
log
-Wl,--build-id=none -Wformat
)
55 changes: 55 additions & 0 deletions AppDemo/app/src/main/cpp/InstructionEngine.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* 版权所有 (c) 华为技术有限公司 2017-2021
* 功能说明: 指令流引擎定义的函数以及返回值
*/

#ifndef INSTRUCTION_ENGINE_H
#define INSTRUCTION_ENGINE_H

#include <cstdint>

enum VMIMsgType : uint8_t {
INVALID,
HEARTBEAT,
GL,
AUDIO,
TOUCH_INPUT,
NAVBAR_INPUT,
END
};

enum VmiInstructionEngineRetCode : uint32_t {
VMI_SUCCESS = 0,
VMI_INSTRUCTION_ENGINE_INVALID_PARAM = 1,
VMI_INSTRUCTION_ENGINE_UNINIT_SOCK = 2,
VMI_INSTRUCTION_ENGINE_SEND_ALLOC_FAILED = 3,
VMI_INSTRUCTION_ENGINE_SEND_MEMSET_FAILED = 4,
VMI_INSTRUCTION_ENGINE_SEND_MEMCPY_FAILED = 5,
VMI_INSTRUCTION_ENGINE_SEND_FAIL = 6,
VMI_INSTRUCTION_ENGINE_HOOK_REGISTER_FAIL = 7,
VMI_INSTRUCTION_CLIENT_INVALID_PARAM = 0x0A050001,
VMI_INSTRUCTION_CLIENT_START_FAIL = 0x0A050002,
VMI_INSTRUCTION_CLIENT_ALREADY_STARTED = 0x0A050003,
VMI_INSTRUCTION_CLIENT_STOP_FAIL = 0x0A050004,
VMI_INSTRUCTION_CLIENT_SEND_HOOK_REGISTER_FAIL = 0x0A050005,
VMI_INSTRUCTION_CLIENT_SEND_FAIL = 0x0A050006,
VMI_INSTRUCTION_CLIENT_SEND_AGAIN = 0x0A050007,
VMI_INSTRUCTION_CLIENT_INITIALIZE_FAIL = 0x0A050008
};

enum VmiInstructionEngineEvent {
VMI_INSTRUCTION_ENGINE_EVENT_SOCK_DISCONN = -2, // 连接断开
VMI_INSTRUCTION_ENGINE_EVENT_PKG_BROKEN = -3, // 数据包损坏
VMI_INSTRUCTION_ENGINE_EVENT_VERSION_ERROR = -4, // 服务端和客户端的版本不匹配
VMI_INSTRUCTION_ENGINE_EVENT_READY = -5, // 引擎渲染第一帧画面成功
VMI_INSTRUCTION_ENGINE_EVENT_ORIENTATION_CHANGED = -6, // 服务端方向转屏事件
};

typedef struct EngineEvent {
int event;
int reserved[4];
} EngineEvent;

// 参数值event是什么事件
using OnVmiInstructionEngineEvent = void (*)(EngineEvent event);
#endif
68 changes: 68 additions & 0 deletions AppDemo/app/src/main/cpp/InstructionEngineClient.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/*
* 版权所有 (c) 华为技术有限公司 2017-2021
* 功能说明:指令流引擎接口C++函数
*/
#ifndef INSTRUCTION_ENGINE_CLIENT_H
#define INSTRUCTION_ENGINE_CLIENT_H
#include "InstructionEngine.h"
typedef struct FrameInfo {
uint64_t tid; // 渲染线程id
uint32_t fps; // 渲染线程帧率
uint64_t frameCount; // 渲染线程帧数
} FrameInfo;

typedef struct StatusInfo {
uint64_t bytesRecv; // 接收字节数
uint64_t bytesSend; // 发送字节数
uint64_t lag; // 网路延迟(ms)
FrameInfo info[4]; // 渲染线程统计信息
} StatusInfo;

/**
* @功能描述:指令引擎初始化函数
* @参数 [in] event:传入的指令流事件回调函数指针
* @返回值:VMI_SUCCESS,初始化成功,VMI_INSTRUCTION_CLIENT_INITIALIZE_FAIL,初始化失败。
*/
uint32_t Initialize(OnVmiInstructionEngineEvent event);

/**
* @功能描述:指令引擎启动函数
* @参数 [in] surface:java层传入的surface,在jni层转成ANativeWindow指针。
* @返回值:VMI_SUCCESS,初始化成功,VMI_INSTRUCTION_CLIENT_INVALID_PARAM,参数异常,
* VMI_INSTRUCTION_CLIENT_ALREADY_STARTED,代表重复启动,VMI_INSTRUCTION_CLIENT_START_FAIL,
* 代表启动失败
*/
uint32_t Start(uint64_t surface, uint32_t width, uint32_t height, uint32_t densityDpi);

/**
* @功能描述:指令引擎停止函数
*/
void Stop();

/**
* @功能描述:获取指令流引擎渲染线程统计信息
* @返回值:返回指令流引擎渲染线程统计信息,请参考InstructionEngine.h中StatusInfo结构体定义
*/
StatusInfo GetStat();

/**
* @功能描述:指令引擎socket接收函数
* @参数 [in] type:接收数据类型,请参考InstructionEngine.h中VMIMsgType枚举定义
* @参数 [in] data:接收数据buffer地址
* @参数 [in] length:接收数据buffer长度
* @返回值:大于0,代表接收的字节数。0代表失败
*/
uint32_t RecvData(VMIMsgType type, uint8_t* data, uint32_t length);


/**
* @功能描述:指令引擎socket发送函数
* @参数 [in] type:发送数据类型,请参考InstructionEngine.h中VMIMsgType枚举定义
* @参数 [in] data:发送数据buffer地址
* @参数 [in] length:发送数据buffer长度
* @返回值:VMI_SUCCESS, 代表发送成功,VMI_INSTRUCTION_ENGINE_INVALID_PARAM代表type类型不支持。
* VMI_INSTRUCTION_ENGINE_UNINIT_SOCK,代表socket未开建立。 VMI_INSTRUCTION_ENGINE_SEND_ALLOC_FAILED代表底层发送buffer生成失败。
* VMI_INSTRUCTION_ENGINE_SEND_MEMCPY_FAILED,代表底层发送buffer拷贝失败,VMI_INSTRUCTION_ENGINE_SEND_FAIL代表底层发送失败。
*/
uint32_t SendData(VMIMsgType type, uint8_t* data, uint32_t length);
#endif
Loading