Skip to content

Commit 112df89

Browse files
committed
update sample to Android SDK 4.10.
1 parent a783e06 commit 112df89

5 files changed

Lines changed: 53 additions & 16 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ This sample code demonstrates how to use [FFmpeg](https://ffmpeg.org) for video
88

99
- Android Studio 2.0+
1010
- Android System 4.2+
11-
- DJI Android SDK 4.9
11+
- DJI Android SDK 4.10
1212

1313
## IMPORTANT: Install `git lfs`
1414

android-videostreamdecodingsample/app/build.gradle

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,20 +45,25 @@ android {
4545
doNotStrip "*/*/libFRCorkscrew.so"
4646
doNotStrip "*/*/libUpgradeVerify.so"
4747
doNotStrip "*/*/libFR.so"
48+
doNotStrip "*/*/libDJIFlySafeCore.so"
49+
doNotStrip "*/*/libdjifs_jni.so"
50+
doNotStrip "*/*/libsfjni.so"
4851
exclude 'META-INF/rxjava.properties'
4952
}
5053
}
5154
dependencies {
5255
implementation 'com.android.support:multidex:1.0.2'
53-
implementation('com.dji:dji-sdk:4.9', {
56+
implementation('com.dji:dji-sdk:4.10', {
5457
//if your app needn't support Mavic 2 Pro and Mavic 2 Zoom, pls exclude the library-anti-distortion module
5558
//like following
5659
//exclude module: 'library-anti-distortion'
60+
61+
//Uncomment the following line if your APP does not need network RTK.
62+
//For Phantom 4 RTK and Matrice 210 RTK V2. Network RTK can be used as a virtual reference station to provide
63+
//cm level accurate position.
64+
//exclude module: 'library-anti-distortion'
5765
})
58-
compileOnly 'com.dji:dji-sdk-provided:4.9'
59-
}
66+
compileOnly 'com.dji:dji-sdk-provided:4.10'
6067

68+
}
6169

62-
repositories {
63-
google()
64-
}
-46.6 MB
Binary file not shown.

android-videostreamdecodingsample/app/src/main/java/com/dji/videostreamdecodingsample/ConnectionActivity.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import android.widget.TextView;
2020
import android.widget.Toast;
2121

22+
import dji.sdk.sdkmanager.DJISDKInitEvent;
2223
import java.util.ArrayList;
2324
import java.util.List;
2425
import java.util.concurrent.atomic.AtomicBoolean;
@@ -153,6 +154,11 @@ public void onConnectivityChange(boolean b) {
153154
}
154155
notifyStatusChange();
155156
}
157+
158+
@Override
159+
public void onInitProcess(DJISDKInitEvent djisdkInitEvent, int i) {
160+
//notify the init progress
161+
}
156162
});
157163
}
158164
});
@@ -245,6 +251,7 @@ private void initUI() {
245251
mBtnOpen.setOnClickListener(this);
246252
mBtnOpen.setEnabled(false);
247253
((TextView)findViewById(R.id.textView2)).setText(getResources().getString(R.string.sdk_version, DJISDKManager.getInstance().getSDKVersion()));
254+
248255
}
249256

250257
private void updateTitleBar() {

android-videostreamdecodingsample/app/src/main/java/com/dji/videostreamdecodingsample/MainActivity.java

Lines changed: 34 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import android.graphics.Rect;
66
import android.graphics.SurfaceTexture;
77
import android.graphics.YuvImage;
8+
import android.os.Build;
89
import android.os.Bundle;
910
import android.os.Environment;
1011
import android.os.Handler;
@@ -20,25 +21,24 @@
2021
import android.widget.Toast;
2122

2223
import com.dji.videostreamdecodingsample.media.DJIVideoStreamDecoder;
23-
2424
import com.dji.videostreamdecodingsample.media.NativeHelper;
25-
import dji.common.camera.SettingsDefinitions;
26-
import dji.common.error.DJIError;
27-
import dji.common.util.CommonCallbacks;
28-
import dji.log.DJILog;
29-
import dji.thirdparty.afinal.core.AsyncTask;
25+
3026
import java.io.File;
3127
import java.io.FileNotFoundException;
3228
import java.io.FileOutputStream;
3329
import java.io.IOException;
3430
import java.io.OutputStream;
31+
import java.nio.ByteBuffer;
3532

33+
import dji.common.camera.SettingsDefinitions;
34+
import dji.common.error.DJIError;
3635
import dji.common.product.Model;
36+
import dji.common.util.CommonCallbacks;
3737
import dji.sdk.base.BaseProduct;
3838
import dji.sdk.camera.Camera;
3939
import dji.sdk.camera.VideoFeeder;
4040
import dji.sdk.codec.DJICodecManager;
41-
import java.nio.ByteBuffer;
41+
import dji.thirdparty.afinal.core.AsyncTask;
4242

4343
public class MainActivity extends Activity implements DJICodecManager.YuvDataCallback {
4444
private static final String TAG = MainActivity.class.getSimpleName();
@@ -391,13 +391,18 @@ public void onYuvDataReceived(final ByteBuffer yuvFrame, int dataSize, final int
391391
AsyncTask.execute(new Runnable() {
392392
@Override
393393
public void run() {
394-
saveYuvDataToJPEG(bytes, width, height);
394+
if (Build.VERSION.SDK_INT <= 23){
395+
oldSaveYuvDataToJPEG(bytes, width, height);
396+
}else {
397+
newSaveYuvDataToJPEG(bytes, width, height);
398+
}
395399
}
396400
});
397401
}
398402
}
399403

400-
private void saveYuvDataToJPEG(byte[] yuvFrame, int width, int height){
404+
// For android API <= 23
405+
private void oldSaveYuvDataToJPEG(byte[] yuvFrame, int width, int height){
401406
if (yuvFrame.length < width * height) {
402407
//DJILog.d(TAG, "yuvFrame size is too small " + yuvFrame.length);
403408
return;
@@ -447,6 +452,26 @@ private void saveYuvDataToJPEG(byte[] yuvFrame, int width, int height){
447452
screenShot(bytes,Environment.getExternalStorageDirectory() + "/DJI_ScreenShot", width, height);
448453
}
449454

455+
private void newSaveYuvDataToJPEG(byte[] yuvFrame, int width, int height){
456+
if (yuvFrame.length < width * height) {
457+
//DJILog.d(TAG, "yuvFrame size is too small " + yuvFrame.length);
458+
return;
459+
}
460+
int length = width * height;
461+
462+
byte[] u = new byte[width * height / 4];
463+
byte[] v = new byte[width * height / 4];
464+
for (int i = 0; i < u.length; i++) {
465+
v[i] = yuvFrame[length + 2 * i];
466+
u[i] = yuvFrame[length + 2 * i + 1];
467+
}
468+
for (int i = 0; i < u.length; i++) {
469+
yuvFrame[length + 2 * i] = u[i];
470+
yuvFrame[length + 2 * i + 1] = v[i];
471+
}
472+
screenShot(yuvFrame,Environment.getExternalStorageDirectory() + "/DJI_ScreenShot", width, height);
473+
}
474+
450475
/**
451476
* Save the buffered data into a JPG image file
452477
*/

0 commit comments

Comments
 (0)