Skip to content

Commit

Permalink
Updated ffmpeg binaries + updated tests script + using sha1sum to che…
Browse files Browse the repository at this point in the history
…ck if device ffmpeg binary is different
  • Loading branch information
hiteshsondhi88 committed Sep 18, 2014
1 parent b7d1c4c commit ab9e8c3
Show file tree
Hide file tree
Showing 13 changed files with 86 additions and 38 deletions.
Binary file modified FFmpegAndroid/assets/armeabi-v7a-neon/ffmpeg
Binary file not shown.
Binary file modified FFmpegAndroid/assets/armeabi-v7a/ffmpeg
Binary file not shown.
Binary file modified FFmpegAndroid/assets/x86/ffmpeg
Binary file not shown.
4 changes: 2 additions & 2 deletions FFmpegAndroid/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ android {
applicationId "com.github.hiteshsondhi88.libffmpeg"
minSdkVersion 16
targetSdkVersion 16
versionCode 22
versionName "0.2.2"
versionCode 23
versionName "0.2.3"
}

sourceSets.main {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public void run() {

public void testRunWaitFor() throws Exception {
ShellCommand shellCommand = new ShellCommand();
CommandResult commandResult = shellCommand.runWaitFor("ls /sdcard/");
CommandResult commandResult = shellCommand.runWaitFor("ls");
assertNotNull(commandResult);
assertEquals(true, commandResult.success);
assertThat(commandResult.output).isNotEmpty();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,27 @@
package com.github.hiteshsondhi88.libffmpeg;

import android.text.TextUtils;

enum CpuArch {
x86, ARMv7, ARMv7_NEON, NONE
x86("64978fa085af04a2d08907a3a853a6ed8f2f25b6"),
ARMv7("b924a0ee8650f18da292a7e2ad398d2791d2966c"),
ARMv7_NEON("7eb42611f316de0349edbd244440484f3b0f29bd"),
NONE(null);

private String sha1;

CpuArch(String sha1) {
this.sha1 = sha1;
}

static CpuArch fromString(String sha1) {
if (!TextUtils.isEmpty(sha1)) {
for (CpuArch cpuArch : CpuArch.values()) {
if (sha1.equalsIgnoreCase(cpuArch.sha1)) {
return cpuArch;
}
}
}
return NONE;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public void loadBinary(FFmpegLoadBinaryResponseHandler ffmpegLoadBinaryResponseH
}

if (!TextUtils.isEmpty(cpuArchNameFromAssets)) {
ffmpegLoadLibraryAsyncTask = new FFmpegLoadLibraryAsyncTask(context, cpuArchNameFromAssets, ffmpegLoadBinaryResponseHandler, this);
ffmpegLoadLibraryAsyncTask = new FFmpegLoadLibraryAsyncTask(context, cpuArchNameFromAssets, ffmpegLoadBinaryResponseHandler);
ffmpegLoadLibraryAsyncTask.execute();
} else {
throw new FFmpegNotSupportedException("Device not supported");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,19 @@

import android.content.Context;
import android.os.AsyncTask;
import android.text.TextUtils;

import java.io.File;

import com.github.hiteshsondhi88.libffmpeg.exceptions.FFmpegCommandAlreadyRunningException;

class FFmpegLoadLibraryAsyncTask extends AsyncTask<Void, Void, Boolean> {

private final String cpuArchNameFromAssets;
private final FFmpegLoadBinaryResponseHandler ffmpegLoadBinaryResponseHandler;
private final Context context;
private final FFmpeg ffmpeg;

FFmpegLoadLibraryAsyncTask(Context context, String cpuArchNameFromAssets, FFmpegLoadBinaryResponseHandler ffmpegLoadBinaryResponseHandler, FFmpeg ffmpeg) {
FFmpegLoadLibraryAsyncTask(Context context, String cpuArchNameFromAssets, FFmpegLoadBinaryResponseHandler ffmpegLoadBinaryResponseHandler) {
this.context = context;
this.cpuArchNameFromAssets = cpuArchNameFromAssets;
this.ffmpegLoadBinaryResponseHandler = ffmpegLoadBinaryResponseHandler;
this.ffmpeg = ffmpeg;
}

@Override
Expand Down Expand Up @@ -63,14 +58,6 @@ protected void onPostExecute(Boolean isSuccess) {
}

private boolean isDeviceFFmpegVersionOld() {
String ffmpegDeviceVersion;
try {
ffmpegDeviceVersion = ffmpeg.getDeviceFFmpegVersion();
} catch (FFmpegCommandAlreadyRunningException e) {
Log.e("FFmpeg already running", e);
// return false, ffmpeg is already running so we cannot replace the existing binary file
return false;
}
return !TextUtils.isEmpty(ffmpegDeviceVersion) && !ffmpegDeviceVersion.equals(ffmpeg.getLibraryFFmpegVersion());
return CpuArch.fromString(FileUtils.SHA1(FileUtils.getFFmpeg(context))).equals(CpuArch.NONE);
}
}
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
package com.github.hiteshsondhi88.libffmpeg;

import android.content.Context;
import android.util.Log;

import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Formatter;
import java.util.Map;

class FileUtils {

private static final String TAG = FileUtils.class.getSimpleName();

static final String ffmpegFileName = "ffmpeg";
static final String ffmpegFileName = "ffmpeg";
private static final int DEFAULT_BUFFER_SIZE = 1024 * 4;
private static final int EOF = -1;

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

return true;
} catch (IOException e) {
Log.e(TAG, "issue in coping binary from assets to data. ", e);
Log.e("issue in coping binary from assets to data. ", e);
}
return false;
}
Expand All @@ -63,4 +65,30 @@ static String getFFmpeg(Context context, Map<String,String> environmentVars) {
ffmpegCommand += getFFmpeg(context);
return ffmpegCommand;
}

static String SHA1(String file) {
InputStream is = null;
try {
MessageDigest messageDigest = MessageDigest.getInstance("SHA1");
is = new BufferedInputStream(new FileInputStream(file));
final byte[] buffer = new byte[DEFAULT_BUFFER_SIZE];
for (int read; (read = is.read(buffer)) != -1; ) {
messageDigest.update(buffer, 0, read);
}

Formatter formatter = new Formatter();
// Convert the byte to hex format
for (final byte b : messageDigest.digest()) {
formatter.format("%02x", b);
}
return formatter.toString();
} catch (NoSuchAlgorithmException e) {
Log.e(e);
} catch (IOException e) {
Log.e(e);
} finally {
Util.close(is);
}
return null;
}
}
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ android {
applicationId "com.github.hiteshsondhi88.sampleffmpeg"
minSdkVersion 16
targetSdkVersion 20
versionCode 22
versionName "0.2.2"
versionCode 23
versionName "0.2.3"
}

sourceSets.main {
Expand Down
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
VERSION_NAME=0.2.2
VERSION_CODE=22
VERSION_NAME=0.2.3
VERSION_CODE=23
GROUP=com.github.hiteshsondhi88.libffmpeg

POM_DESCRIPTION=Java implementation of ffmpeg for Android
Expand Down
21 changes: 14 additions & 7 deletions runTests.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
#!/bin/bash

# x86 emulator
echo no | android create avd -c 50M --force -n testx86 -t android-16 --abi x86
emulator -avd testx86 -no-skin -no-audio -no-window &
EMULATOR_PID=$!
adb wait-for-device
./wait_for_emulator
adb shell input keyevent 82 &
./gradlew --info build connectedAndroidTest
kill -9 $EMULATOR_PID && sleep 10
emulator -ports 5554,5555 -partition-size 256 -avd testx86 -no-skin -no-boot-anim -no-audio -no-window &
PID_EMU1=$!
./wait_for_emulator emulator-5554

# armeabi-v7a emulator
echo no | android create avd -c 50M --force -n testarm -t android-16 --abi armeabi-v7a
emulator -ports 5556,5557 -partition-size 256 -avd testarm -no-skin -no-boot-anim -no-audio -no-window &
PID_EMU2=$!
./wait_for_emulator emulator-5556

# Running Tests
./gradlew --info build connectedCheck
kill -9 $PID_EMU1 $PID_EMU2
8 changes: 6 additions & 2 deletions wait_for_emulator
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
#!/bin/bash

# Originally written by Ralf Kistner <[email protected]>, but placed in the public domain

EMU_SERIAL=$1
ADB_CMD='adb'
if [ -n "$EMU_SERIAL" ]; then
ADB_CMD="adb -s $EMU_SERIAL"
fi
set +e

bootanim=""
failcounter=0
until [[ "$bootanim" =~ "stopped" ]]; do
bootanim=`adb -e shell getprop init.svc.bootanim 2>&1`
bootanim=`$ADB_CMD -e shell getprop init.svc.bootanim 2>&1`
echo "$bootanim"
if [[ "$bootanim" =~ "not found" ]]; then
let "failcounter += 1"
Expand Down

0 comments on commit ab9e8c3

Please sign in to comment.