Skip to content

Commit ab9e8c3

Browse files
Updated ffmpeg binaries + updated tests script + using sha1sum to check if device ffmpeg binary is different
1 parent b7d1c4c commit ab9e8c3

File tree

13 files changed

+86
-38
lines changed

13 files changed

+86
-38
lines changed
696 KB
Binary file not shown.
696 KB
Binary file not shown.

FFmpegAndroid/assets/x86/ffmpeg

-176 KB
Binary file not shown.

FFmpegAndroid/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ android {
88
applicationId "com.github.hiteshsondhi88.libffmpeg"
99
minSdkVersion 16
1010
targetSdkVersion 16
11-
versionCode 22
12-
versionName "0.2.2"
11+
versionCode 23
12+
versionName "0.2.3"
1313
}
1414

1515
sourceSets.main {

FFmpegAndroid/src/androidTest/java/com/github/hiteshsondhi88/libffmpeg/ShellCommandTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public void run() {
4444

4545
public void testRunWaitFor() throws Exception {
4646
ShellCommand shellCommand = new ShellCommand();
47-
CommandResult commandResult = shellCommand.runWaitFor("ls /sdcard/");
47+
CommandResult commandResult = shellCommand.runWaitFor("ls");
4848
assertNotNull(commandResult);
4949
assertEquals(true, commandResult.success);
5050
assertThat(commandResult.output).isNotEmpty();
Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,27 @@
11
package com.github.hiteshsondhi88.libffmpeg;
22

3+
import android.text.TextUtils;
4+
35
enum CpuArch {
4-
x86, ARMv7, ARMv7_NEON, NONE
6+
x86("64978fa085af04a2d08907a3a853a6ed8f2f25b6"),
7+
ARMv7("b924a0ee8650f18da292a7e2ad398d2791d2966c"),
8+
ARMv7_NEON("7eb42611f316de0349edbd244440484f3b0f29bd"),
9+
NONE(null);
10+
11+
private String sha1;
12+
13+
CpuArch(String sha1) {
14+
this.sha1 = sha1;
15+
}
16+
17+
static CpuArch fromString(String sha1) {
18+
if (!TextUtils.isEmpty(sha1)) {
19+
for (CpuArch cpuArch : CpuArch.values()) {
20+
if (sha1.equalsIgnoreCase(cpuArch.sha1)) {
21+
return cpuArch;
22+
}
23+
}
24+
}
25+
return NONE;
26+
}
527
}

FFmpegAndroid/src/main/java/com/github/hiteshsondhi88/libffmpeg/FFmpeg.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public void loadBinary(FFmpegLoadBinaryResponseHandler ffmpegLoadBinaryResponseH
5353
}
5454

5555
if (!TextUtils.isEmpty(cpuArchNameFromAssets)) {
56-
ffmpegLoadLibraryAsyncTask = new FFmpegLoadLibraryAsyncTask(context, cpuArchNameFromAssets, ffmpegLoadBinaryResponseHandler, this);
56+
ffmpegLoadLibraryAsyncTask = new FFmpegLoadLibraryAsyncTask(context, cpuArchNameFromAssets, ffmpegLoadBinaryResponseHandler);
5757
ffmpegLoadLibraryAsyncTask.execute();
5858
} else {
5959
throw new FFmpegNotSupportedException("Device not supported");

FFmpegAndroid/src/main/java/com/github/hiteshsondhi88/libffmpeg/FFmpegLoadLibraryAsyncTask.java

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,19 @@
22

33
import android.content.Context;
44
import android.os.AsyncTask;
5-
import android.text.TextUtils;
65

76
import java.io.File;
87

9-
import com.github.hiteshsondhi88.libffmpeg.exceptions.FFmpegCommandAlreadyRunningException;
10-
118
class FFmpegLoadLibraryAsyncTask extends AsyncTask<Void, Void, Boolean> {
129

1310
private final String cpuArchNameFromAssets;
1411
private final FFmpegLoadBinaryResponseHandler ffmpegLoadBinaryResponseHandler;
1512
private final Context context;
16-
private final FFmpeg ffmpeg;
1713

18-
FFmpegLoadLibraryAsyncTask(Context context, String cpuArchNameFromAssets, FFmpegLoadBinaryResponseHandler ffmpegLoadBinaryResponseHandler, FFmpeg ffmpeg) {
14+
FFmpegLoadLibraryAsyncTask(Context context, String cpuArchNameFromAssets, FFmpegLoadBinaryResponseHandler ffmpegLoadBinaryResponseHandler) {
1915
this.context = context;
2016
this.cpuArchNameFromAssets = cpuArchNameFromAssets;
2117
this.ffmpegLoadBinaryResponseHandler = ffmpegLoadBinaryResponseHandler;
22-
this.ffmpeg = ffmpeg;
2318
}
2419

2520
@Override
@@ -63,14 +58,6 @@ protected void onPostExecute(Boolean isSuccess) {
6358
}
6459

6560
private boolean isDeviceFFmpegVersionOld() {
66-
String ffmpegDeviceVersion;
67-
try {
68-
ffmpegDeviceVersion = ffmpeg.getDeviceFFmpegVersion();
69-
} catch (FFmpegCommandAlreadyRunningException e) {
70-
Log.e("FFmpeg already running", e);
71-
// return false, ffmpeg is already running so we cannot replace the existing binary file
72-
return false;
73-
}
74-
return !TextUtils.isEmpty(ffmpegDeviceVersion) && !ffmpegDeviceVersion.equals(ffmpeg.getLibraryFFmpegVersion());
61+
return CpuArch.fromString(FileUtils.SHA1(FileUtils.getFFmpeg(context))).equals(CpuArch.NONE);
7562
}
7663
}

FFmpegAndroid/src/main/java/com/github/hiteshsondhi88/libffmpeg/FileUtils.java

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,21 @@
11
package com.github.hiteshsondhi88.libffmpeg;
22

33
import android.content.Context;
4-
import android.util.Log;
54

5+
import java.io.BufferedInputStream;
66
import java.io.File;
7+
import java.io.FileInputStream;
78
import java.io.FileOutputStream;
89
import java.io.IOException;
910
import java.io.InputStream;
11+
import java.security.MessageDigest;
12+
import java.security.NoSuchAlgorithmException;
13+
import java.util.Formatter;
1014
import java.util.Map;
1115

1216
class FileUtils {
1317

14-
private static final String TAG = FileUtils.class.getSimpleName();
15-
16-
static final String ffmpegFileName = "ffmpeg";
18+
static final String ffmpegFileName = "ffmpeg";
1719
private static final int DEFAULT_BUFFER_SIZE = 1024 * 4;
1820
private static final int EOF = -1;
1921

@@ -39,7 +41,7 @@ static boolean copyBinaryFromAssetsToData(Context context, String fileNameFromAs
3941

4042
return true;
4143
} catch (IOException e) {
42-
Log.e(TAG, "issue in coping binary from assets to data. ", e);
44+
Log.e("issue in coping binary from assets to data. ", e);
4345
}
4446
return false;
4547
}
@@ -63,4 +65,30 @@ static String getFFmpeg(Context context, Map<String,String> environmentVars) {
6365
ffmpegCommand += getFFmpeg(context);
6466
return ffmpegCommand;
6567
}
68+
69+
static String SHA1(String file) {
70+
InputStream is = null;
71+
try {
72+
MessageDigest messageDigest = MessageDigest.getInstance("SHA1");
73+
is = new BufferedInputStream(new FileInputStream(file));
74+
final byte[] buffer = new byte[DEFAULT_BUFFER_SIZE];
75+
for (int read; (read = is.read(buffer)) != -1; ) {
76+
messageDigest.update(buffer, 0, read);
77+
}
78+
79+
Formatter formatter = new Formatter();
80+
// Convert the byte to hex format
81+
for (final byte b : messageDigest.digest()) {
82+
formatter.format("%02x", b);
83+
}
84+
return formatter.toString();
85+
} catch (NoSuchAlgorithmException e) {
86+
Log.e(e);
87+
} catch (IOException e) {
88+
Log.e(e);
89+
} finally {
90+
Util.close(is);
91+
}
92+
return null;
93+
}
6694
}

app/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ android {
88
applicationId "com.github.hiteshsondhi88.sampleffmpeg"
99
minSdkVersion 16
1010
targetSdkVersion 20
11-
versionCode 22
12-
versionName "0.2.2"
11+
versionCode 23
12+
versionName "0.2.3"
1313
}
1414

1515
sourceSets.main {

0 commit comments

Comments
 (0)