Skip to content
This repository was archived by the owner on May 30, 2023. It is now read-only.

Commit c7b2495

Browse files
n8fr8eighthave
authored andcommitted
new android java library project
1 parent ae87b9a commit c7b2495

8 files changed

+680
-0
lines changed

.classpath

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<classpath>
3+
<classpathentry kind="src" path="src"/>
4+
<classpathentry kind="src" path="gen"/>
5+
<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
6+
<classpathentry kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
7+
<classpathentry kind="output" path="bin/classes"/>
8+
</classpath>

.project

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<projectDescription>
3+
<name>android-ffmpeg-library</name>
4+
<comment></comment>
5+
<projects>
6+
</projects>
7+
<buildSpec>
8+
<buildCommand>
9+
<name>com.android.ide.eclipse.adt.ResourceManagerBuilder</name>
10+
<arguments>
11+
</arguments>
12+
</buildCommand>
13+
<buildCommand>
14+
<name>com.android.ide.eclipse.adt.PreCompilerBuilder</name>
15+
<arguments>
16+
</arguments>
17+
</buildCommand>
18+
<buildCommand>
19+
<name>org.eclipse.jdt.core.javabuilder</name>
20+
<arguments>
21+
</arguments>
22+
</buildCommand>
23+
<buildCommand>
24+
<name>com.android.ide.eclipse.adt.ApkBuilder</name>
25+
<arguments>
26+
</arguments>
27+
</buildCommand>
28+
</buildSpec>
29+
<natures>
30+
<nature>com.android.ide.eclipse.adt.AndroidNature</nature>
31+
<nature>org.eclipse.jdt.core.javanature</nature>
32+
</natures>
33+
</projectDescription>

AndroidManifest.xml

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
2+
package="org.ffmpeg.android"
3+
android:versionCode="1"
4+
android:versionName="1.0">
5+
6+
<uses-sdk android:minSdkVersion="8" android:targetSdkVersion="15" />
7+
8+
<application android:label="@string/app_name"
9+
android:icon="@drawable/ic_launcher"
10+
android:theme="@style/AppTheme">
11+
12+
</application>
13+
14+
</manifest>

libs/android-support-v4.jar

265 KB
Binary file not shown.

project.properties

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# This file is automatically generated by Android Tools.
2+
# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
3+
#
4+
# This file must be checked in Version Control Systems.
5+
#
6+
# To customize properties used by the Ant build system edit
7+
# "ant.properties", and override values to adapt the script to your
8+
# project structure.
9+
#
10+
# To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home):
11+
#proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
12+
13+
# Project target.
14+
target=android-15
15+
android.library=true
+208
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,208 @@
1+
package org.ffmpeg.android;
2+
/* Copyright (c) 2009, Nathan Freitas, Orbot / The Guardian Project - http://openideals.com/guardian */
3+
/* See LICENSE for licensing information */
4+
5+
import java.io.BufferedReader;
6+
import java.io.DataInputStream;
7+
import java.io.DataOutputStream;
8+
import java.io.File;
9+
import java.io.FileNotFoundException;
10+
import java.io.FileOutputStream;
11+
import java.io.FileReader;
12+
import java.io.IOException;
13+
import java.io.InputStream;
14+
import java.io.OutputStream;
15+
import java.util.zip.GZIPInputStream;
16+
import java.util.zip.ZipEntry;
17+
import java.util.zip.ZipInputStream;
18+
19+
20+
import android.content.Context;
21+
import android.util.Log;
22+
23+
public class BinaryInstaller {
24+
25+
26+
File installFolder;
27+
Context context;
28+
29+
private static int isARMv6 = -1;
30+
private static String CHMOD_EXEC = "700";
31+
32+
private final static int FILE_WRITE_BUFFER_SIZE = 32256;
33+
34+
public BinaryInstaller (Context context, File installFolder)
35+
{
36+
this.installFolder = installFolder;
37+
38+
this.context = context;
39+
}
40+
41+
//
42+
/*
43+
* Extract the Tor binary from the APK file using ZIP
44+
*/
45+
public boolean installFromRaw () throws IOException, FileNotFoundException
46+
{
47+
48+
InputStream is;
49+
File outFile;
50+
51+
is = context.getResources().openRawResource(R.raw.ffmpeg);
52+
outFile = new File(installFolder, "ffmpeg");
53+
streamToFile(is, outFile, false, false, "700");
54+
55+
56+
return true;
57+
}
58+
59+
60+
private static void copyAssetFile(Context ctx, String asset, File file) throws IOException, InterruptedException
61+
{
62+
63+
DataOutputStream out = new DataOutputStream(new FileOutputStream(file));
64+
InputStream is = new GZIPInputStream(ctx.getAssets().open(asset));
65+
66+
byte buf[] = new byte[8172];
67+
int len;
68+
while ((len = is.read(buf)) > 0) {
69+
out.write(buf, 0, len);
70+
}
71+
out.close();
72+
is.close();
73+
}
74+
/*
75+
* Write the inputstream contents to the file
76+
*/
77+
private static boolean streamToFile(InputStream stm, File outFile, boolean append, boolean zip, String mode) throws IOException
78+
79+
{
80+
byte[] buffer = new byte[FILE_WRITE_BUFFER_SIZE];
81+
82+
int bytecount;
83+
84+
85+
OutputStream stmOut = new FileOutputStream(outFile, append);
86+
87+
if (zip)
88+
{
89+
ZipInputStream zis = new ZipInputStream(stm);
90+
ZipEntry ze = zis.getNextEntry();
91+
stm = zis;
92+
93+
}
94+
95+
while ((bytecount = stm.read(buffer)) > 0)
96+
{
97+
98+
stmOut.write(buffer, 0, bytecount);
99+
100+
}
101+
102+
stmOut.close();
103+
stm.close();
104+
105+
Runtime.getRuntime().exec("chmod "+mode+" "+outFile.getAbsolutePath());
106+
107+
108+
return true;
109+
110+
}
111+
112+
//copy the file from inputstream to File output - alternative impl
113+
public void copyFile (InputStream is, File outputFile)
114+
{
115+
116+
try {
117+
outputFile.createNewFile();
118+
DataOutputStream out = new DataOutputStream(new FileOutputStream(outputFile));
119+
DataInputStream in = new DataInputStream(is);
120+
121+
int b = -1;
122+
byte[] data = new byte[1024];
123+
124+
while ((b = in.read(data)) != -1) {
125+
out.write(data);
126+
}
127+
128+
if (b == -1); //rejoice
129+
130+
//
131+
out.flush();
132+
out.close();
133+
in.close();
134+
// chmod?
135+
136+
137+
138+
} catch (IOException ex) {
139+
Log.e("ffmpeg", "error copying binary", ex);
140+
}
141+
142+
}
143+
144+
145+
146+
/**
147+
* Check if this is an ARMv6 device
148+
* @return true if this is ARMv6
149+
*/
150+
private static boolean isARMv6() {
151+
if (isARMv6 == -1) {
152+
BufferedReader r = null;
153+
try {
154+
isARMv6 = 0;
155+
r = new BufferedReader(new FileReader("/proc/cpuinfo"));
156+
for (String line = r.readLine(); line != null; line = r.readLine()) {
157+
if (line.startsWith("Processor") && line.contains("ARMv6")) {
158+
isARMv6 = 1;
159+
break;
160+
} else if (line.startsWith("CPU architecture") && (line.contains("6TE") || line.contains("5TE"))) {
161+
isARMv6 = 1;
162+
break;
163+
}
164+
}
165+
} catch (Exception ex) {
166+
} finally {
167+
if (r != null) try {r.close();} catch (Exception ex) {}
168+
}
169+
}
170+
return (isARMv6 == 1);
171+
}
172+
173+
/**
174+
* Copies a raw resource file, given its ID to the given location
175+
* @param ctx context
176+
* @param resid resource id
177+
* @param file destination file
178+
* @param mode file permissions (E.g.: "755")
179+
* @throws IOException on error
180+
* @throws InterruptedException when interrupted
181+
*/
182+
private static void copyRawFile(Context ctx, int resid, File file, String mode, boolean isZipd) throws IOException, InterruptedException
183+
{
184+
final String abspath = file.getAbsolutePath();
185+
// Write the iptables binary
186+
final FileOutputStream out = new FileOutputStream(file);
187+
InputStream is = ctx.getResources().openRawResource(resid);
188+
189+
if (isZipd)
190+
{
191+
ZipInputStream zis = new ZipInputStream(is);
192+
ZipEntry ze = zis.getNextEntry();
193+
is = zis;
194+
}
195+
196+
byte buf[] = new byte[1024];
197+
int len;
198+
while ((len = is.read(buf)) > 0) {
199+
out.write(buf, 0, len);
200+
}
201+
out.close();
202+
is.close();
203+
// Change the permissions
204+
Runtime.getRuntime().exec("chmod "+mode+" "+abspath).waitFor();
205+
}
206+
207+
208+
}

0 commit comments

Comments
 (0)