summaryrefslogtreecommitdiffstats
path: root/cmds
diff options
context:
space:
mode:
Diffstat (limited to 'cmds')
-rw-r--r--cmds/am/src/com/android/commands/am/Am.java566
-rw-r--r--cmds/app_process/app_main.cpp4
-rw-r--r--cmds/bootanimation/Android.mk5
-rw-r--r--cmds/bootanimation/BootAnimation.cpp25
-rw-r--r--cmds/bootanimation/BootAnimation.h3
-rw-r--r--cmds/bootanimation/bootanimation_main.cpp6
-rw-r--r--cmds/dumpsys/Android.mk4
-rw-r--r--cmds/dumpsys/dumpsys.cpp6
-rw-r--r--cmds/runtime/Android.mk1
-rw-r--r--cmds/runtime/ServiceManager.cpp4
-rw-r--r--cmds/runtime/ServiceManager.h2
-rw-r--r--cmds/runtime/main_runtime.cpp8
-rw-r--r--cmds/service/Android.mk3
-rw-r--r--cmds/service/service.cpp6
-rw-r--r--cmds/servicemanager/service_manager.c1
-rw-r--r--cmds/stagefright/Android.mk66
-rw-r--r--cmds/stagefright/WaveWriter.h71
-rw-r--r--cmds/stagefright/play.cpp295
-rw-r--r--cmds/stagefright/record.cpp181
-rw-r--r--cmds/stagefright/stagefright.cpp200
-rw-r--r--cmds/surfaceflinger/Android.mk1
-rw-r--r--cmds/surfaceflinger/main_surfaceflinger.cpp6
-rw-r--r--cmds/system_server/Android.mk1
-rw-r--r--cmds/system_server/library/Android.mk1
-rw-r--r--cmds/system_server/library/system_init.cpp10
-rw-r--r--cmds/system_server/system_main.cpp2
26 files changed, 1129 insertions, 349 deletions
diff --git a/cmds/am/src/com/android/commands/am/Am.java b/cmds/am/src/com/android/commands/am/Am.java
index 3782136..0b4f25e 100644
--- a/cmds/am/src/com/android/commands/am/Am.java
+++ b/cmds/am/src/com/android/commands/am/Am.java
@@ -23,16 +23,19 @@ import android.app.IActivityManager;
import android.app.IInstrumentationWatcher;
import android.app.Instrumentation;
import android.content.ComponentName;
+import android.content.IIntentReceiver;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.os.ParcelFileDescriptor;
import android.os.RemoteException;
import android.os.ServiceManager;
+import android.util.AndroidException;
import android.view.IWindowManager;
import java.io.File;
import java.io.FileNotFoundException;
+import java.net.URISyntaxException;
import java.util.Iterator;
import java.util.Set;
@@ -45,16 +48,29 @@ public class Am {
private boolean mDebugOption = false;
+ // These are magic strings understood by the Eclipse plugin.
+ private static final String FATAL_ERROR_CODE = "Error type 1";
+ private static final String NO_SYSTEM_ERROR_CODE = "Error type 2";
+ private static final String NO_CLASS_ERROR_CODE = "Error type 3";
+
/**
* Command-line entry point.
*
* @param args The command-line arguments
*/
public static void main(String[] args) {
- (new Am()).run(args);
+ try {
+ (new Am()).run(args);
+ } catch (IllegalArgumentException e) {
+ showUsage();
+ System.err.println("Error: " + e.getMessage());
+ } catch (Exception e) {
+ System.err.println(e.toString());
+ System.exit(1);
+ }
}
- private void run(String[] args) {
+ private void run(String[] args) throws Exception {
if (args.length < 1) {
showUsage();
return;
@@ -62,16 +78,14 @@ public class Am {
mAm = ActivityManagerNative.getDefault();
if (mAm == null) {
- System.err.println("Error type 2");
- System.err.println("Error: Unable to connect to activity manager; is the system running?");
- showUsage();
- return;
+ System.err.println(NO_SYSTEM_ERROR_CODE);
+ throw new AndroidException("Can't connect to activity manager; is the system running?");
}
mArgs = args;
-
String op = args[0];
mNextArg = 1;
+
if (op.equals("start")) {
runStart();
} else if (op.equals("instrument")) {
@@ -81,13 +95,11 @@ public class Am {
} else if (op.equals("profile")) {
runProfile();
} else {
- System.err.println("Error: Unknown command: " + op);
- showUsage();
- return;
+ throw new IllegalArgumentException("Unknown command: " + op);
}
}
- private Intent makeIntent() {
+ private Intent makeIntent() throws URISyntaxException {
Intent intent = new Intent();
boolean hasIntentInfo = false;
@@ -95,186 +107,146 @@ public class Am {
Uri data = null;
String type = null;
- try {
- String opt;
- while ((opt=nextOption()) != null) {
- if (opt.equals("-a")) {
- intent.setAction(nextOptionData());
- hasIntentInfo = true;
- } else if (opt.equals("-d")) {
- data = Uri.parse(nextOptionData());
- hasIntentInfo = true;
- } else if (opt.equals("-t")) {
- type = nextOptionData();
- hasIntentInfo = true;
- } else if (opt.equals("-c")) {
- intent.addCategory(nextOptionData());
- hasIntentInfo = true;
- } else if (opt.equals("-e") || opt.equals("--es")) {
- String key = nextOptionData();
- String value = nextOptionData();
- intent.putExtra(key, value);
- hasIntentInfo = true;
- } else if (opt.equals("--ei")) {
- String key = nextOptionData();
- String value = nextOptionData();
- intent.putExtra(key, Integer.valueOf(value));
- hasIntentInfo = true;
- } else if (opt.equals("--ez")) {
- String key = nextOptionData();
- String value = nextOptionData();
- intent.putExtra(key, Boolean.valueOf(value));
- hasIntentInfo = true;
- } else if (opt.equals("-n")) {
- String str = nextOptionData();
- ComponentName cn = ComponentName.unflattenFromString(str);
- if (cn == null) {
- System.err.println("Error: Bad component name: " + str);
- showUsage();
- return null;
- }
- intent.setComponent(cn);
- hasIntentInfo = true;
- } else if (opt.equals("-f")) {
- String str = nextOptionData();
- intent.setFlags(Integer.decode(str).intValue());
- } else if (opt.equals("-D")) {
- mDebugOption = true;
- } else {
- System.err.println("Error: Unknown option: " + opt);
- showUsage();
- return null;
- }
+ String opt;
+ while ((opt=nextOption()) != null) {
+ if (opt.equals("-a")) {
+ intent.setAction(nextArgRequired());
+ hasIntentInfo = true;
+ } else if (opt.equals("-d")) {
+ data = Uri.parse(nextArgRequired());
+ hasIntentInfo = true;
+ } else if (opt.equals("-t")) {
+ type = nextArgRequired();
+ hasIntentInfo = true;
+ } else if (opt.equals("-c")) {
+ intent.addCategory(nextArgRequired());
+ hasIntentInfo = true;
+ } else if (opt.equals("-e") || opt.equals("--es")) {
+ String key = nextArgRequired();
+ String value = nextArgRequired();
+ intent.putExtra(key, value);
+ hasIntentInfo = true;
+ } else if (opt.equals("--ei")) {
+ String key = nextArgRequired();
+ String value = nextArgRequired();
+ intent.putExtra(key, Integer.valueOf(value));
+ hasIntentInfo = true;
+ } else if (opt.equals("--ez")) {
+ String key = nextArgRequired();
+ String value = nextArgRequired();
+ intent.putExtra(key, Boolean.valueOf(value));
+ hasIntentInfo = true;
+ } else if (opt.equals("-n")) {
+ String str = nextArgRequired();
+ ComponentName cn = ComponentName.unflattenFromString(str);
+ if (cn == null) throw new IllegalArgumentException("Bad component name: " + str);
+ intent.setComponent(cn);
+ hasIntentInfo = true;
+ } else if (opt.equals("-f")) {
+ String str = nextArgRequired();
+ intent.setFlags(Integer.decode(str).intValue());
+ } else if (opt.equals("-D")) {
+ mDebugOption = true;
+ } else {
+ System.err.println("Error: Unknown option: " + opt);
+ showUsage();
+ return null;
}
- } catch (RuntimeException ex) {
- System.err.println("Error: " + ex.toString());
- showUsage();
- return null;
}
intent.setDataAndType(data, type);
String uri = nextArg();
if (uri != null) {
- try {
- Intent oldIntent = intent;
- try {
- intent = Intent.getIntent(uri);
- } catch (java.net.URISyntaxException ex) {
- System.err.println("Bad URI: " + uri);
- showUsage();
- return null;
- }
- if (oldIntent.getAction() != null) {
- intent.setAction(oldIntent.getAction());
- }
- if (oldIntent.getData() != null || oldIntent.getType() != null) {
- intent.setDataAndType(oldIntent.getData(), oldIntent.getType());
- }
- Set cats = oldIntent.getCategories();
- if (cats != null) {
- Iterator it = cats.iterator();
- while (it.hasNext()) {
- intent.addCategory((String)it.next());
- }
+ Intent oldIntent = intent;
+ intent = Intent.getIntent(uri);
+ if (oldIntent.getAction() != null) {
+ intent.setAction(oldIntent.getAction());
+ }
+ if (oldIntent.getData() != null || oldIntent.getType() != null) {
+ intent.setDataAndType(oldIntent.getData(), oldIntent.getType());
+ }
+ Set cats = oldIntent.getCategories();
+ if (cats != null) {
+ Iterator it = cats.iterator();
+ while (it.hasNext()) {
+ intent.addCategory((String)it.next());
}
- } catch (RuntimeException ex) {
- System.err.println("Error creating from URI: " + ex.toString());
- showUsage();
- return null;
}
- } else if (!hasIntentInfo) {
- System.err.println("Error: No intent supplied");
- showUsage();
- return null;
+ hasIntentInfo = true;
}
+ if (!hasIntentInfo) throw new IllegalArgumentException("No intent supplied");
return intent;
}
- private void runStart() {
+ private void runStart() throws Exception {
Intent intent = makeIntent();
-
- if (intent != null) {
- System.out.println("Starting: " + intent);
- try {
- intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
- // XXX should do something to determine the MIME type.
- int res = mAm.startActivity(null, intent, intent.getType(),
- null, 0, null, null, 0, false, mDebugOption);
- switch (res) {
- case IActivityManager.START_SUCCESS:
- break;
- case IActivityManager.START_SWITCHES_CANCELED:
- System.err.println(
- "Warning: Activity not started because the "
- + " current activity is being kept for the user.");
- break;
- case IActivityManager.START_DELIVERED_TO_TOP:
- System.err.println(
- "Warning: Activity not started, intent has "
- + "been delivered to currently running "
- + "top-most instance.");
- break;
- case IActivityManager.START_RETURN_INTENT_TO_CALLER:
- System.err.println(
- "Warning: Activity not started because intent "
- + "should be handled by the caller");
- break;
- case IActivityManager.START_TASK_TO_FRONT:
- System.err.println(
- "Warning: Activity not started, its current "
- + "task has been brought to the front");
- break;
- case IActivityManager.START_INTENT_NOT_RESOLVED:
- System.err.println(
- "Error: Activity not started, unable to "
- + "resolve " + intent.toString());
- break;
- case IActivityManager.START_CLASS_NOT_FOUND:
- System.err.println("Error type 3");
- System.err.println("Error: Activity class " +
- intent.getComponent().toShortString()
- + " does not exist.");
- break;
- case IActivityManager.START_FORWARD_AND_REQUEST_CONFLICT:
- System.err.println(
- "Error: Activity not started, you requested to "
- + "both forward and receive its result");
- break;
- case IActivityManager.START_PERMISSION_DENIED:
- System.err.println(
- "Error: Activity not started, you do not "
- + "have permission to access it.");
- break;
- default:
- System.err.println(
- "Error: Activity not started, unknown error "
- + "code " + res);
- break;
- }
- } catch (RemoteException e) {
- System.err.println("Error type 1");
+ System.out.println("Starting: " + intent);
+ intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+ // XXX should do something to determine the MIME type.
+ int res = mAm.startActivity(null, intent, intent.getType(),
+ null, 0, null, null, 0, false, mDebugOption);
+ switch (res) {
+ case IActivityManager.START_SUCCESS:
+ break;
+ case IActivityManager.START_SWITCHES_CANCELED:
+ System.err.println(
+ "Warning: Activity not started because the "
+ + " current activity is being kept for the user.");
+ break;
+ case IActivityManager.START_DELIVERED_TO_TOP:
+ System.err.println(
+ "Warning: Activity not started, intent has "
+ + "been delivered to currently running "
+ + "top-most instance.");
+ break;
+ case IActivityManager.START_RETURN_INTENT_TO_CALLER:
+ System.err.println(
+ "Warning: Activity not started because intent "
+ + "should be handled by the caller");
+ break;
+ case IActivityManager.START_TASK_TO_FRONT:
+ System.err.println(
+ "Warning: Activity not started, its current "
+ + "task has been brought to the front");
+ break;
+ case IActivityManager.START_INTENT_NOT_RESOLVED:
System.err.println(
"Error: Activity not started, unable to "
- + "call on to activity manager service");
- }
+ + "resolve " + intent.toString());
+ break;
+ case IActivityManager.START_CLASS_NOT_FOUND:
+ System.err.println(NO_CLASS_ERROR_CODE);
+ System.err.println("Error: Activity class " +
+ intent.getComponent().toShortString()
+ + " does not exist.");
+ break;
+ case IActivityManager.START_FORWARD_AND_REQUEST_CONFLICT:
+ System.err.println(
+ "Error: Activity not started, you requested to "
+ + "both forward and receive its result");
+ break;
+ case IActivityManager.START_PERMISSION_DENIED:
+ System.err.println(
+ "Error: Activity not started, you do not "
+ + "have permission to access it.");
+ break;
+ default:
+ System.err.println(
+ "Error: Activity not started, unknown error code " + res);
+ break;
}
}
- private void sendBroadcast() {
+ private void sendBroadcast() throws Exception {
Intent intent = makeIntent();
-
- if (intent != null) {
- System.out.println("Broadcasting: " + intent);
- try {
- mAm.broadcastIntent(null, intent, null, null, 0, null, null,
- null, true, false);
- } catch (RemoteException e) {
- }
- }
+ IntentReceiver receiver = new IntentReceiver();
+ System.out.println("Broadcasting: " + intent);
+ mAm.broadcastIntent(null, intent, null, receiver, 0, null, null, null, true, false);
+ receiver.waitForFinish();
}
- private void runInstrument() {
+ private void runInstrument() throws Exception {
String profileFile = null;
boolean wait = false;
boolean rawMode = false;
@@ -283,46 +255,30 @@ public class Am {
String argKey = null, argValue = null;
IWindowManager wm = IWindowManager.Stub.asInterface(ServiceManager.getService("window"));
- try {
- String opt;
- while ((opt=nextOption()) != null) {
- if (opt.equals("-p")) {
- profileFile = nextOptionData();
- } else if (opt.equals("-w")) {
- wait = true;
- } else if (opt.equals("-r")) {
- rawMode = true;
- } else if (opt.equals("-e")) {
- argKey = nextOptionData();
- argValue = nextOptionData();
- args.putString(argKey, argValue);
- } else if (opt.equals("--no_window_animation")) {
- no_window_animation = true;
- } else {
- System.err.println("Error: Unknown option: " + opt);
- showUsage();
- return;
- }
+ String opt;
+ while ((opt=nextOption()) != null) {
+ if (opt.equals("-p")) {
+ profileFile = nextArgRequired();
+ } else if (opt.equals("-w")) {
+ wait = true;
+ } else if (opt.equals("-r")) {
+ rawMode = true;
+ } else if (opt.equals("-e")) {
+ argKey = nextArgRequired();
+ argValue = nextArgRequired();
+ args.putString(argKey, argValue);
+ } else if (opt.equals("--no_window_animation")) {
+ no_window_animation = true;
+ } else {
+ System.err.println("Error: Unknown option: " + opt);
+ showUsage();
+ return;
}
- } catch (RuntimeException ex) {
- System.err.println("Error: " + ex.toString());
- showUsage();
- return;
}
- String cnArg = nextArg();
- if (cnArg == null) {
- System.err.println("Error: No instrumentation component supplied");
- showUsage();
- return;
- }
-
+ String cnArg = nextArgRequired();
ComponentName cn = ComponentName.unflattenFromString(cnArg);
- if (cn == null) {
- System.err.println("Error: Bad component name: " + cnArg);
- showUsage();
- return;
- }
+ if (cn == null) throw new IllegalArgumentException("Bad component name: " + cnArg);
InstrumentationWatcher watcher = null;
if (wait) {
@@ -331,22 +287,13 @@ public class Am {
}
float[] oldAnims = null;
if (no_window_animation) {
- try {
- oldAnims = wm.getAnimationScales();
- wm.setAnimationScale(0, 0.0f);
- wm.setAnimationScale(1, 0.0f);
- } catch (RemoteException e) {
- }
+ oldAnims = wm.getAnimationScales();
+ wm.setAnimationScale(0, 0.0f);
+ wm.setAnimationScale(1, 0.0f);
}
- try {
- if (!mAm.startInstrumentation(cn, profileFile, 0, args, watcher)) {
- System.out.println("INSTRUMENTATION_FAILED: " +
- cn.flattenToString());
- showUsage();
- return;
- }
- } catch (RemoteException e) {
+ if (!mAm.startInstrumentation(cn, profileFile, 0, args, watcher)) {
+ throw new AndroidException("INSTRUMENTATION_FAILED: " + cn.flattenToString());
}
if (watcher != null) {
@@ -356,9 +303,57 @@ public class Am {
}
if (oldAnims != null) {
+ wm.setAnimationScales(oldAnims);
+ }
+ }
+
+ private void runProfile() throws Exception {
+ String profileFile = null;
+ boolean start = false;
+ String process = nextArgRequired();
+ ParcelFileDescriptor fd = null;
+
+ String cmd = nextArgRequired();
+ if ("start".equals(cmd)) {
+ start = true;
+ profileFile = nextArgRequired();
+ try {
+ fd = ParcelFileDescriptor.open(
+ new File(profileFile),
+ ParcelFileDescriptor.MODE_CREATE |
+ ParcelFileDescriptor.MODE_TRUNCATE |
+ ParcelFileDescriptor.MODE_READ_WRITE);
+ } catch (FileNotFoundException e) {
+ System.err.println("Error: Unable to open file: " + profileFile);
+ return;
+ }
+ } else if (!"stop".equals(cmd)) {
+ throw new IllegalArgumentException("Profile command " + cmd + " not valid");
+ }
+
+ if (!mAm.profileControl(process, start, profileFile, fd)) {
+ throw new AndroidException("PROFILE FAILED on process " + process);
+ }
+ }
+
+ private class IntentReceiver extends IIntentReceiver.Stub {
+ private boolean mFinished = false;
+
+ public synchronized void performReceive(
+ Intent intent, int rc, String data, Bundle ext, boolean ord) {
+ String line = "Broadcast completed: result=" + rc;
+ if (data != null) line = line + ", data=\"" + data + "\"";
+ if (ext != null) line = line + ", extras: " + ext;
+ System.out.println(line);
+ mFinished = true;
+ notifyAll();
+ }
+
+ public synchronized void waitForFinish() {
try {
- wm.setAnimationScales(oldAnims);
- } catch (RemoteException e) {
+ while (!mFinished) wait();
+ } catch (InterruptedException e) {
+ throw new IllegalStateException(e);
}
}
}
@@ -366,7 +361,7 @@ public class Am {
private class InstrumentationWatcher extends IInstrumentationWatcher.Stub {
private boolean mFinished = false;
private boolean mRawMode = false;
-
+
/**
* Set or reset "raw mode". In "raw mode", all bundles are dumped. In "pretty mode",
* if a bundle includes Instrumentation.REPORT_KEY_STREAMRESULT, just print that.
@@ -375,7 +370,7 @@ public class Am {
public void setRawOutput(boolean rawMode) {
mRawMode = rawMode;
}
-
+
public void instrumentationStatus(ComponentName name, int resultCode, Bundle results) {
synchronized (this) {
// pretty printer mode?
@@ -431,6 +426,7 @@ public class Am {
}
wait(1000);
} catch (InterruptedException e) {
+ throw new IllegalStateException(e);
}
}
}
@@ -438,62 +434,11 @@ public class Am {
}
}
- private void runProfile() {
- String profileFile = null;
- boolean start = false;
-
- String process = nextArg();
- if (process == null) {
- System.err.println("Error: No profile process supplied");
- showUsage();
- return;
- }
-
- ParcelFileDescriptor fd = null;
-
- String cmd = nextArg();
- if ("start".equals(cmd)) {
- start = true;
- profileFile = nextArg();
- if (profileFile == null) {
- System.err.println("Error: No profile file path supplied");
- showUsage();
- return;
- }
- try {
- fd = ParcelFileDescriptor.open(
- new File(profileFile),
- ParcelFileDescriptor.MODE_CREATE |
- ParcelFileDescriptor.MODE_TRUNCATE |
- ParcelFileDescriptor.MODE_READ_WRITE);
- } catch (FileNotFoundException e) {
- System.err.println("Error: Unable to open file: " + profileFile);
- return;
- }
- } else if (!"stop".equals(cmd)) {
- System.err.println("Error: Profile command " + cmd + " not valid");
- showUsage();
- return;
- }
-
- try {
- if (!mAm.profileControl(process, start, profileFile, fd)) {
- System.err.println("PROFILE FAILED on process " + process);
- return;
- }
- } catch (IllegalArgumentException e) {
- System.out.println("PROFILE FAILED: " + e.getMessage());
- return;
- } catch (IllegalStateException e) {
- System.out.println("PROFILE FAILED: " + e.getMessage());
- return;
- } catch (RemoteException e) {
- System.out.println("PROFILE FAILED: activity manager gone");
- return;
- }
- }
-
private String nextOption() {
+ if (mCurArgData != null) {
+ String prev = mArgs[mNextArg - 1];
+ throw new IllegalArgumentException("No argument expected after \"" + prev + "\"");
+ }
if (mNextArg >= mArgs.length) {
return null;
}
@@ -518,41 +463,52 @@ public class Am {
return arg;
}
- private String nextOptionData() {
+ private String nextArg() {
if (mCurArgData != null) {
- return mCurArgData;
- }
- if (mNextArg >= mArgs.length) {
+ String arg = mCurArgData;
+ mCurArgData = null;
+ return arg;
+ } else if (mNextArg < mArgs.length) {
+ return mArgs[mNextArg++];
+ } else {
return null;
}
- String data = mArgs[mNextArg];
- mNextArg++;
- return data;
}
- private String nextArg() {
- if (mNextArg >= mArgs.length) {
- return null;
+ private String nextArgRequired() {
+ String arg = nextArg();
+ if (arg == null) {
+ String prev = mArgs[mNextArg - 1];
+ throw new IllegalArgumentException("Argument expected after \"" + prev + "\"");
}
- String arg = mArgs[mNextArg];
- mNextArg++;
return arg;
}
- private void showUsage() {
- System.err.println("usage: am [start|broadcast|instrument|profile]");
- System.err.println(" am start [-D] INTENT");
- System.err.println(" am broadcast INTENT");
- System.err.println(" am instrument [-r] [-e <ARG_NAME> <ARG_VALUE>] [-p <PROF_FILE>]");
- System.err.println(" [-w] <COMPONENT> ");
- System.err.println(" am profile <PROCESS> [start <PROF_FILE>|stop]");
- System.err.println("");
- System.err.println(" INTENT is described with:");
- System.err.println(" [-a <ACTION>] [-d <DATA_URI>] [-t <MIME_TYPE>]");
- System.err.println(" [-c <CATEGORY> [-c <CATEGORY>] ...]");
- System.err.println(" [-e|--es <EXTRA_KEY> <EXTRA_STRING_VALUE> ...]");
- System.err.println(" [--ez <EXTRA_KEY> <EXTRA_BOOLEAN_VALUE> ...]");
- System.err.println(" [-e|--ei <EXTRA_KEY> <EXTRA_INT_VALUE> ...]");
- System.err.println(" [-n <COMPONENT>] [-f <FLAGS>] [<URI>]");
+ private static void showUsage() {
+ System.err.println(
+ "usage: am [subcommand] [options]\n" +
+ "\n" +
+ " start an Activity: am start [-D] <INTENT>\n" +
+ " -D: enable debugging\n" +
+ "\n" +
+ " send a broadcast Intent: am broadcast <INTENT>\n" +
+ "\n" +
+ " start an Instrumentation: am instrument [flags] <COMPONENT>\n" +
+ " -r: print raw results (otherwise decode REPORT_KEY_STREAMRESULT)\n" +
+ " -e <NAME> <VALUE>: set argument <NAME> to <VALUE>\n" +
+ " -p <FILE>: write profiling data to <FILE>\n" +
+ " -w: wait for instrumentation to finish before returning\n" +
+ "\n" +
+ " start profiling: am profile <PROCESS> start <FILE>\n" +
+ " stop profiling: am profile <PROCESS> stop\n" +
+ "\n" +
+ " <INTENT> specifications include these flags:\n" +
+ " [-a <ACTION>] [-d <DATA_URI>] [-t <MIME_TYPE>]\n" +
+ " [-c <CATEGORY> [-c <CATEGORY>] ...]\n" +
+ " [-e|--es <EXTRA_KEY> <EXTRA_STRING_VALUE> ...]\n" +
+ " [--ez <EXTRA_KEY> <EXTRA_BOOLEAN_VALUE> ...]\n" +
+ " [-e|--ei <EXTRA_KEY> <EXTRA_INT_VALUE> ...]\n" +
+ " [-n <COMPONENT>] [-f <FLAGS>] [<URI>]\n"
+ );
}
}
diff --git a/cmds/app_process/app_main.cpp b/cmds/app_process/app_main.cpp
index d825d5a..7decf9a 100644
--- a/cmds/app_process/app_main.cpp
+++ b/cmds/app_process/app_main.cpp
@@ -7,8 +7,8 @@
#define LOG_TAG "appproc"
-#include <utils/IPCThreadState.h>
-#include <utils/ProcessState.h>
+#include <binder/IPCThreadState.h>
+#include <binder/ProcessState.h>
#include <utils/Log.h>
#include <cutils/process_name.h>
#include <cutils/memory.h>
diff --git a/cmds/bootanimation/Android.mk b/cmds/bootanimation/Android.mk
index 9c94c2e..3449de1 100644
--- a/cmds/bootanimation/Android.mk
+++ b/cmds/bootanimation/Android.mk
@@ -12,12 +12,13 @@ ifeq ($(TARGET_SIMULATOR),true)
endif
endif
+LOCAL_CFLAGS += -DGL_GLEXT_PROTOTYPES -DEGL_EGLEXT_PROTOTYPES
+
LOCAL_SHARED_LIBRARIES := \
libcutils \
libutils \
libui \
- libcorecg \
- libsgl \
+ libskia \
libEGL \
libGLESv1_CM
diff --git a/cmds/bootanimation/BootAnimation.cpp b/cmds/bootanimation/BootAnimation.cpp
index 3b9db8d..e2d01de 100644
--- a/cmds/bootanimation/BootAnimation.cpp
+++ b/cmds/bootanimation/BootAnimation.cpp
@@ -14,15 +14,13 @@
* limitations under the License.
*/
-#define LOG_TAG "BootAnimation"
-
#include <stdint.h>
#include <sys/types.h>
#include <math.h>
#include <fcntl.h>
#include <utils/misc.h>
-#include <utils/IPCThreadState.h>
+#include <binder/IPCThreadState.h>
#include <utils/threads.h>
#include <utils/Atomic.h>
#include <utils/Errors.h>
@@ -35,7 +33,7 @@
#include <ui/DisplayInfo.h>
#include <ui/ISurfaceComposer.h>
#include <ui/ISurfaceFlingerClient.h>
-#include <ui/EGLNativeWindowSurface.h>
+#include <ui/FramebufferNativeWindow.h>
#include <core/SkBitmap.h>
#include <images/SkImageDecoder.h>
@@ -130,12 +128,15 @@ status_t BootAnimation::readyToRun() {
return -1;
// create the native surface
- sp<Surface> s = session()->createSurface(getpid(), 0, dinfo.w, dinfo.h,
- PIXEL_FORMAT_RGB_565, ISurfaceComposer::eGPU);
+ sp<SurfaceControl> control = session()->createSurface(
+ getpid(), 0, dinfo.w, dinfo.h, PIXEL_FORMAT_RGB_565,
+ ISurfaceComposer::eGPU);
session()->openTransaction();
- s->setLayer(0x40000000);
+ control->setLayer(0x40000000);
session()->closeTransaction();
+ sp<Surface> s = control->getSurface();
+
// initialize opengl and egl
const EGLint attribs[] = { EGL_RED_SIZE, 5, EGL_GREEN_SIZE, 6,
EGL_BLUE_SIZE, 5, EGL_DEPTH_SIZE, 0, EGL_NONE };
@@ -150,9 +151,7 @@ status_t BootAnimation::readyToRun() {
eglInitialize(display, 0, 0);
eglChooseConfig(display, attribs, &config, 1, &numConfigs);
- mNativeWindowSurface = new EGLNativeWindowSurface(s);
- surface = eglCreateWindowSurface(display, config,
- mNativeWindowSurface.get(), NULL);
+ surface = eglCreateWindowSurface(display, config, s.get(), NULL);
context = eglCreateContext(display, config, NULL, NULL);
eglQuerySurface(display, surface, EGL_WIDTH, &w);
@@ -163,6 +162,7 @@ status_t BootAnimation::readyToRun() {
mSurface = surface;
mWidth = w;
mHeight = h;
+ mFlingerSurfaceControl = control;
mFlingerSurface = s;
// initialize GL
@@ -178,8 +178,8 @@ bool BootAnimation::threadLoop() {
eglMakeCurrent(mDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
eglDestroyContext(mDisplay, mContext);
eglDestroySurface(mDisplay, mSurface);
- mNativeWindowSurface.clear();
mFlingerSurface.clear();
+ mFlingerSurfaceControl.clear();
eglTerminate(mDisplay);
IPCThreadState::self()->stopProcess();
return r;
@@ -200,8 +200,7 @@ bool BootAnimation::android() {
const Rect updateRect(xc, yc, xc + mAndroid[0].w, yc + mAndroid[0].h);
// draw and update only what we need
- mNativeWindowSurface->setSwapRectangle(updateRect.left,
- updateRect.top, updateRect.width(), updateRect.height());
+ mFlingerSurface->setSwapRectangle(updateRect);
glEnable(GL_SCISSOR_TEST);
glScissor(updateRect.left, mHeight - updateRect.bottom, updateRect.width(),
diff --git a/cmds/bootanimation/BootAnimation.h b/cmds/bootanimation/BootAnimation.h
index 42e9eed..796077d 100644
--- a/cmds/bootanimation/BootAnimation.h
+++ b/cmds/bootanimation/BootAnimation.h
@@ -34,7 +34,6 @@ class SkBitmap;
namespace android {
class AssetManager;
-class EGLNativeWindowSurface;
// ---------------------------------------------------------------------------
@@ -68,8 +67,8 @@ private:
EGLDisplay mDisplay;
EGLDisplay mContext;
EGLDisplay mSurface;
+ sp<SurfaceControl> mFlingerSurfaceControl;
sp<Surface> mFlingerSurface;
- sp<EGLNativeWindowSurface> mNativeWindowSurface;
};
// ---------------------------------------------------------------------------
diff --git a/cmds/bootanimation/bootanimation_main.cpp b/cmds/bootanimation/bootanimation_main.cpp
index 675ea81..346f156 100644
--- a/cmds/bootanimation/bootanimation_main.cpp
+++ b/cmds/bootanimation/bootanimation_main.cpp
@@ -16,9 +16,9 @@
#define LOG_TAG "BootAnimation"
-#include <utils/IPCThreadState.h>
-#include <utils/ProcessState.h>
-#include <utils/IServiceManager.h>
+#include <binder/IPCThreadState.h>
+#include <binder/ProcessState.h>
+#include <binder/IServiceManager.h>
#include <utils/Log.h>
#include <utils/threads.h>
diff --git a/cmds/dumpsys/Android.mk b/cmds/dumpsys/Android.mk
index 0c623cc..42b1b73 100644
--- a/cmds/dumpsys/Android.mk
+++ b/cmds/dumpsys/Android.mk
@@ -5,7 +5,9 @@ LOCAL_SRC_FILES:= \
dumpsys.cpp
LOCAL_SHARED_LIBRARIES := \
- libutils
+ libutils \
+ libbinder
+
ifeq ($(TARGET_OS),linux)
LOCAL_CFLAGS += -DXP_UNIX
diff --git a/cmds/dumpsys/dumpsys.cpp b/cmds/dumpsys/dumpsys.cpp
index a62fe55..945a690 100644
--- a/cmds/dumpsys/dumpsys.cpp
+++ b/cmds/dumpsys/dumpsys.cpp
@@ -6,9 +6,9 @@
#define LOG_TAG "dumpsys"
#include <utils/Log.h>
-#include <utils/Parcel.h>
-#include <utils/ProcessState.h>
-#include <utils/IServiceManager.h>
+#include <binder/Parcel.h>
+#include <binder/ProcessState.h>
+#include <binder/IServiceManager.h>
#include <utils/TextOutput.h>
#include <utils/Vector.h>
diff --git a/cmds/runtime/Android.mk b/cmds/runtime/Android.mk
index 521eb2b..6a72d10 100644
--- a/cmds/runtime/Android.mk
+++ b/cmds/runtime/Android.mk
@@ -10,6 +10,7 @@ LOCAL_SRC_FILES:= \
LOCAL_SHARED_LIBRARIES := \
libutils \
+ libbinder \
libandroid_runtime \
libcutils \
libui \
diff --git a/cmds/runtime/ServiceManager.cpp b/cmds/runtime/ServiceManager.cpp
index 758a95c..b2bef07 100644
--- a/cmds/runtime/ServiceManager.cpp
+++ b/cmds/runtime/ServiceManager.cpp
@@ -9,9 +9,9 @@
#include <utils/Debug.h>
#include <utils/Log.h>
-#include <utils/Parcel.h>
+#include <binder/Parcel.h>
#include <utils/String8.h>
-#include <utils/ProcessState.h>
+#include <binder/ProcessState.h>
#include <private/utils/Static.h>
diff --git a/cmds/runtime/ServiceManager.h b/cmds/runtime/ServiceManager.h
index d09cec8..090ca6d 100644
--- a/cmds/runtime/ServiceManager.h
+++ b/cmds/runtime/ServiceManager.h
@@ -4,7 +4,7 @@
#ifndef ANDROID_SERVICE_MANAGER_H
#define ANDROID_SERVICE_MANAGER_H
-#include <utils/IServiceManager.h>
+#include <binder/IServiceManager.h>
#include <utils/KeyedVector.h>
#include <utils/threads.h>
diff --git a/cmds/runtime/main_runtime.cpp b/cmds/runtime/main_runtime.cpp
index 476f38a..21e0e4d 100644
--- a/cmds/runtime/main_runtime.cpp
+++ b/cmds/runtime/main_runtime.cpp
@@ -7,9 +7,11 @@
#include "ServiceManager.h"
#include "SignalHandler.h"
-#include <utils.h>
-#include <utils/IPCThreadState.h>
-#include <utils/ProcessState.h>
+#include <utils/threads.h>
+#include <utils/Errors.h>
+
+#include <binder/IPCThreadState.h>
+#include <binder/ProcessState.h>
#include <utils/Log.h>
#include <cutils/zygote.h>
diff --git a/cmds/service/Android.mk b/cmds/service/Android.mk
index 8c5005c..275bbb2 100644
--- a/cmds/service/Android.mk
+++ b/cmds/service/Android.mk
@@ -4,8 +4,7 @@ include $(CLEAR_VARS)
LOCAL_SRC_FILES:= \
service.cpp
-LOCAL_SHARED_LIBRARIES := \
- libutils
+LOCAL_SHARED_LIBRARIES := libutils libbinder
ifeq ($(TARGET_OS),linux)
LOCAL_CFLAGS += -DXP_UNIX
diff --git a/cmds/service/service.cpp b/cmds/service/service.cpp
index 859a9bf..32db83b 100644
--- a/cmds/service/service.cpp
+++ b/cmds/service/service.cpp
@@ -3,9 +3,9 @@
*
*/
-#include <utils/Parcel.h>
-#include <utils/ProcessState.h>
-#include <utils/IServiceManager.h>
+#include <binder/Parcel.h>
+#include <binder/ProcessState.h>
+#include <binder/IServiceManager.h>
#include <utils/TextOutput.h>
#include <getopt.h>
diff --git a/cmds/servicemanager/service_manager.c b/cmds/servicemanager/service_manager.c
index e4aa8b5..f3a4713 100644
--- a/cmds/servicemanager/service_manager.c
+++ b/cmds/servicemanager/service_manager.c
@@ -30,6 +30,7 @@ static struct {
{ AID_MEDIA, "media.audio_flinger" },
{ AID_MEDIA, "media.player" },
{ AID_MEDIA, "media.camera" },
+ { AID_MEDIA, "media.audio_policy" },
{ AID_RADIO, "radio.phone" },
{ AID_RADIO, "radio.sms" },
{ AID_RADIO, "radio.phonesubinfo" },
diff --git a/cmds/stagefright/Android.mk b/cmds/stagefright/Android.mk
new file mode 100644
index 0000000..fd681a2
--- /dev/null
+++ b/cmds/stagefright/Android.mk
@@ -0,0 +1,66 @@
+ifeq ($(BUILD_WITH_STAGEFRIGHT),true)
+
+LOCAL_PATH:= $(call my-dir)
+
+include $(CLEAR_VARS)
+
+LOCAL_SRC_FILES:= \
+ stagefright.cpp
+
+LOCAL_SHARED_LIBRARIES := \
+ libstagefright
+
+LOCAL_C_INCLUDES:= \
+ frameworks/base/media/libstagefright \
+ $(TOP)/external/opencore/extern_libs_v2/khronos/openmax/include \
+ $(TOP)/external/opencore/android
+
+LOCAL_CFLAGS += -Wno-multichar
+
+LOCAL_MODULE:= stagefright
+
+include $(BUILD_EXECUTABLE)
+
+################################################################################
+
+include $(CLEAR_VARS)
+
+LOCAL_SRC_FILES:= \
+ record.cpp
+
+LOCAL_SHARED_LIBRARIES := \
+ libstagefright
+
+LOCAL_C_INCLUDES:= \
+ frameworks/base/media/libstagefright \
+ $(TOP)/external/opencore/extern_libs_v2/khronos/openmax/include \
+ $(TOP)/external/opencore/android
+
+LOCAL_CFLAGS += -Wno-multichar
+
+LOCAL_MODULE:= record
+
+include $(BUILD_EXECUTABLE)
+
+################################################################################
+
+# include $(CLEAR_VARS)
+#
+# LOCAL_SRC_FILES:= \
+# play.cpp
+#
+# LOCAL_SHARED_LIBRARIES := \
+# libstagefright
+#
+# LOCAL_C_INCLUDES:= \
+# frameworks/base/media/libstagefright \
+# $(TOP)/external/opencore/extern_libs_v2/khronos/openmax/include \
+# $(TOP)/external/opencore/android
+#
+# LOCAL_CFLAGS += -Wno-multichar
+#
+# LOCAL_MODULE:= play
+#
+# include $(BUILD_EXECUTABLE)
+
+endif
diff --git a/cmds/stagefright/WaveWriter.h b/cmds/stagefright/WaveWriter.h
new file mode 100644
index 0000000..a0eb66e
--- /dev/null
+++ b/cmds/stagefright/WaveWriter.h
@@ -0,0 +1,71 @@
+/*
+ * Copyright (C) 2009 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef ANDROID_WAVEWRITER_H_
+
+#define ANDROID_WAVEWRITER_H_
+
+namespace android {
+
+class WaveWriter {
+public:
+ WaveWriter(const char *filename,
+ uint16_t num_channels, uint32_t sampling_rate)
+ : mFile(fopen(filename, "wb")),
+ mTotalBytes(0) {
+ fwrite("RIFFxxxxWAVEfmt \x10\x00\x00\x00\x01\x00", 1, 22, mFile);
+ write_u16(num_channels);
+ write_u32(sampling_rate);
+ write_u32(sampling_rate * num_channels * 2);
+ write_u16(num_channels * 2);
+ write_u16(16);
+ fwrite("dataxxxx", 1, 8, mFile);
+ }
+
+ ~WaveWriter() {
+ fseek(mFile, 40, SEEK_SET);
+ write_u32(mTotalBytes);
+
+ fseek(mFile, 4, SEEK_SET);
+ write_u32(36 + mTotalBytes);
+
+ fclose(mFile);
+ mFile = NULL;
+ }
+
+ void Append(const void *data, size_t size) {
+ fwrite(data, 1, size, mFile);
+ mTotalBytes += size;
+ }
+
+private:
+ void write_u16(uint16_t x) {
+ fputc(x & 0xff, mFile);
+ fputc(x >> 8, mFile);
+ }
+
+ void write_u32(uint32_t x) {
+ write_u16(x & 0xffff);
+ write_u16(x >> 16);
+ }
+
+ FILE *mFile;
+ size_t mTotalBytes;
+};
+
+} // namespace android
+
+#endif // ANDROID_WAVEWRITER_H_
diff --git a/cmds/stagefright/play.cpp b/cmds/stagefright/play.cpp
new file mode 100644
index 0000000..c6e778e
--- /dev/null
+++ b/cmds/stagefright/play.cpp
@@ -0,0 +1,295 @@
+/*
+ * Copyright (C) 2009 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <binder/ProcessState.h>
+#include <media/stagefright/OMXClient.h>
+#include <media/stagefright/TimedEventQueue.h>
+#include <media/stagefright/MPEG4Extractor.h>
+#include <media/stagefright/MediaSource.h>
+#include <media/stagefright/MetaData.h>
+#include <media/stagefright/MmapSource.h>
+#include <media/stagefright/OMXDecoder.h>
+
+using namespace android;
+
+struct NewPlayer {
+ NewPlayer();
+ ~NewPlayer();
+
+ void setSource(const char *uri);
+ void start();
+ void pause();
+ void stop();
+
+private:
+ struct PlayerEvent : public TimedEventQueue::Event {
+ PlayerEvent(NewPlayer *player,
+ void (NewPlayer::*method)(int64_t realtime_us))
+ : mPlayer(player),
+ mMethod(method) {
+ }
+
+ virtual void fire(TimedEventQueue *queue, int64_t realtime_us) {
+ (mPlayer->*mMethod)(realtime_us);
+ }
+
+ private:
+ NewPlayer *mPlayer;
+ void (NewPlayer::*mMethod)(int64_t realtime_us);
+
+ PlayerEvent(const PlayerEvent &);
+ PlayerEvent &operator=(const PlayerEvent &);
+ };
+
+ struct PlayVideoFrameEvent : public TimedEventQueue::Event {
+ PlayVideoFrameEvent(NewPlayer *player, MediaBuffer *buffer)
+ : mPlayer(player),
+ mBuffer(buffer) {
+ }
+
+ virtual ~PlayVideoFrameEvent() {
+ if (mBuffer != NULL) {
+ mBuffer->release();
+ mBuffer = NULL;
+ }
+ }
+
+ virtual void fire(TimedEventQueue *queue, int64_t realtime_us) {
+ mPlayer->onPlayVideoFrame(realtime_us, mBuffer);
+ mBuffer = NULL;
+ }
+
+ private:
+ NewPlayer *mPlayer;
+ MediaBuffer *mBuffer;
+
+ PlayVideoFrameEvent(const PlayVideoFrameEvent &);
+ PlayVideoFrameEvent &operator=(const PlayVideoFrameEvent &);
+ };
+
+ OMXClient mClient;
+
+ MPEG4Extractor *mExtractor;
+ MediaSource *mAudioSource;
+ OMXDecoder *mAudioDecoder;
+ MediaSource *mVideoSource;
+ OMXDecoder *mVideoDecoder;
+
+ int32_t mVideoWidth, mVideoHeight;
+
+ TimedEventQueue mQueue;
+ wp<TimedEventQueue::Event> mPlayVideoFrameEvent;
+
+ int64_t mMediaTimeUsStart;
+ int64_t mRealTimeUsStart;
+
+ void setAudioSource(MediaSource *source);
+ void setVideoSource(MediaSource *source);
+
+ int64_t approxRealTime(int64_t mediatime_us) const;
+
+ void onStart(int64_t realtime_us);
+ void onPause(int64_t realtime_us);
+ void onFetchVideoFrame(int64_t realtime_us);
+ void onPlayVideoFrame(int64_t realtime_us, MediaBuffer *buffer);
+
+ static int64_t getMediaBufferTimeUs(MediaBuffer *buffer);
+
+ NewPlayer(const NewPlayer &);
+ NewPlayer &operator=(const NewPlayer &);
+};
+
+NewPlayer::NewPlayer()
+ : mExtractor(NULL),
+ mAudioSource(NULL),
+ mAudioDecoder(NULL),
+ mVideoSource(NULL),
+ mVideoDecoder(NULL),
+ mVideoWidth(0),
+ mVideoHeight(0) {
+ status_t err = mClient.connect();
+ assert(err == OK);
+}
+
+NewPlayer::~NewPlayer() {
+ stop();
+
+ mClient.disconnect();
+}
+
+void NewPlayer::setSource(const char *uri) {
+ stop();
+
+ mExtractor = new MPEG4Extractor(new MmapSource(uri));
+
+ int num_tracks;
+ status_t err = mExtractor->countTracks(&num_tracks);
+ assert(err == OK);
+
+ for (int i = 0; i < num_tracks; ++i) {
+ const sp<MetaData> meta = mExtractor->getTrackMetaData(i);
+ assert(meta != NULL);
+
+ const char *mime;
+ if (!meta->findCString(kKeyMIMEType, &mime)) {
+ continue;
+ }
+
+ bool is_audio = false;
+ bool is_acceptable = false;
+ if (!strncasecmp(mime, "audio/", 6)) {
+ is_audio = true;
+ is_acceptable = (mAudioSource == NULL);
+ } else if (!strncasecmp(mime, "video/", 6)) {
+ is_acceptable = (mVideoSource == NULL);
+ }
+
+ if (!is_acceptable) {
+ continue;
+ }
+
+ MediaSource *source;
+ if (mExtractor->getTrack(i, &source) != OK) {
+ continue;
+ }
+
+ if (is_audio) {
+ setAudioSource(source);
+ } else {
+ setVideoSource(source);
+ }
+ }
+}
+
+void NewPlayer::setAudioSource(MediaSource *source) {
+ mAudioSource = source;
+
+ sp<MetaData> meta = source->getFormat();
+
+ mAudioDecoder = OMXDecoder::Create(&mClient, meta);
+ mAudioDecoder->setSource(source);
+}
+
+void NewPlayer::setVideoSource(MediaSource *source) {
+ mVideoSource = source;
+
+ sp<MetaData> meta = source->getFormat();
+
+ bool success = meta->findInt32(kKeyWidth, &mVideoWidth);
+ assert(success);
+
+ success = meta->findInt32(kKeyHeight, &mVideoHeight);
+ assert(success);
+
+ mVideoDecoder = OMXDecoder::Create(&mClient, meta);
+ mVideoDecoder->setSource(source);
+}
+
+void NewPlayer::start() {
+ mQueue.start();
+ mQueue.postEvent(new PlayerEvent(this, &NewPlayer::onStart));
+}
+
+void NewPlayer::pause() {
+ mQueue.postEvent(new PlayerEvent(this, &NewPlayer::onPause));
+}
+
+void NewPlayer::stop() {
+ mQueue.stop();
+
+ delete mVideoDecoder;
+ mVideoDecoder = NULL;
+ delete mVideoSource;
+ mVideoSource = NULL;
+ mVideoWidth = mVideoHeight = 0;
+
+ delete mAudioDecoder;
+ mAudioDecoder = NULL;
+ delete mAudioSource;
+ mAudioSource = NULL;
+
+ delete mExtractor;
+ mExtractor = NULL;
+}
+
+int64_t NewPlayer::approxRealTime(int64_t mediatime_us) const {
+ return mRealTimeUsStart + (mediatime_us - mMediaTimeUsStart);
+}
+
+void NewPlayer::onStart(int64_t realtime_us) {
+ mRealTimeUsStart = TimedEventQueue::getRealTimeUs();
+
+ if (mVideoDecoder != NULL) {
+ mQueue.postEvent(new PlayerEvent(this, &NewPlayer::onFetchVideoFrame));
+ }
+}
+
+void NewPlayer::onFetchVideoFrame(int64_t realtime_us) {
+ MediaBuffer *buffer;
+ status_t err = mVideoDecoder->read(&buffer);
+ assert(err == OK);
+
+ int64_t mediatime_us = getMediaBufferTimeUs(buffer);
+
+ sp<TimedEventQueue::Event> event = new PlayVideoFrameEvent(this, buffer);
+ mPlayVideoFrameEvent = event;
+
+ mQueue.postTimedEvent(event, approxRealTime(mediatime_us));
+}
+
+// static
+int64_t NewPlayer::getMediaBufferTimeUs(MediaBuffer *buffer) {
+ int32_t units, scale;
+ bool success =
+ buffer->meta_data()->findInt32(kKeyTimeUnits, &units);
+ assert(success);
+ success =
+ buffer->meta_data()->findInt32(kKeyTimeScale, &scale);
+ assert(success);
+
+ return (int64_t)units * 1000000 / scale;
+}
+
+void NewPlayer::onPlayVideoFrame(int64_t realtime_us, MediaBuffer *buffer) {
+ LOGI("playing video frame (mediatime: %.2f sec)\n",
+ getMediaBufferTimeUs(buffer) / 1E6);
+ fflush(stdout);
+
+ buffer->release();
+ buffer = NULL;
+
+ mQueue.postEvent(new PlayerEvent(this, &NewPlayer::onFetchVideoFrame));
+}
+
+void NewPlayer::onPause(int64_t realtime_us) {
+}
+
+int main(int argc, char **argv) {
+ android::ProcessState::self()->startThreadPool();
+
+ if (argc != 2) {
+ fprintf(stderr, "usage: %s filename\n", argv[0]);
+ return 1;
+ }
+
+ NewPlayer player;
+ player.setSource(argv[1]);
+ player.start();
+ sleep(10);
+ player.stop();
+
+ return 0;
+}
diff --git a/cmds/stagefright/record.cpp b/cmds/stagefright/record.cpp
new file mode 100644
index 0000000..12bdead
--- /dev/null
+++ b/cmds/stagefright/record.cpp
@@ -0,0 +1,181 @@
+/*
+ * Copyright (C) 2009 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#undef NDEBUG
+#include <assert.h>
+
+#include <binder/ProcessState.h>
+#include <media/stagefright/CameraSource.h>
+#include <media/stagefright/MediaBufferGroup.h>
+#include <media/stagefright/MetaData.h>
+#include <media/stagefright/MPEG4Extractor.h>
+#include <media/stagefright/MPEG4Writer.h>
+#include <media/stagefright/MmapSource.h>
+#include <media/stagefright/OMXClient.h>
+#include <media/stagefright/OMXDecoder.h>
+
+using namespace android;
+
+class DummySource : public MediaSource {
+public:
+ DummySource(int width, int height)
+ : mSize((width * height * 3) / 2) {
+ mGroup.add_buffer(new MediaBuffer(mSize));
+ }
+
+ virtual ::status_t getMaxSampleSize(size_t *max_size) {
+ *max_size = mSize;
+ return ::OK;
+ }
+
+ virtual ::status_t read(MediaBuffer **buffer) {
+ ::status_t err = mGroup.acquire_buffer(buffer);
+ if (err != ::OK) {
+ return err;
+ }
+
+ char x = (char)((double)rand() / RAND_MAX * 255);
+ memset((*buffer)->data(), x, mSize);
+ (*buffer)->set_range(0, mSize);
+
+ return ::OK;
+ }
+
+private:
+ MediaBufferGroup mGroup;
+ size_t mSize;
+
+ DummySource(const DummySource &);
+ DummySource &operator=(const DummySource &);
+};
+
+int main(int argc, char **argv) {
+ android::ProcessState::self()->startThreadPool();
+
+#if 1
+ if (argc != 2) {
+ fprintf(stderr, "usage: %s filename\n", argv[0]);
+ return 1;
+ }
+
+ MPEG4Extractor extractor(new MmapSource(argv[1]));
+ int num_tracks;
+ assert(extractor.countTracks(&num_tracks) == ::OK);
+
+ MediaSource *source = NULL;
+ sp<MetaData> meta;
+ for (int i = 0; i < num_tracks; ++i) {
+ meta = extractor.getTrackMetaData(i);
+ assert(meta.get() != NULL);
+
+ const char *mime;
+ if (!meta->findCString(kKeyMIMEType, &mime)) {
+ continue;
+ }
+
+ if (strncasecmp(mime, "video/", 6)) {
+ continue;
+ }
+
+ if (extractor.getTrack(i, &source) != ::OK) {
+ source = NULL;
+ continue;
+ }
+ break;
+ }
+
+ if (source == NULL) {
+ fprintf(stderr, "Unable to find a suitable video track.\n");
+ return 1;
+ }
+
+ OMXClient client;
+ assert(client.connect() == android::OK);
+
+ OMXDecoder *decoder = OMXDecoder::Create(&client, meta);
+ decoder->setSource(source);
+
+ int width, height;
+ bool success = meta->findInt32(kKeyWidth, &width);
+ success = success && meta->findInt32(kKeyHeight, &height);
+ assert(success);
+
+ sp<MetaData> enc_meta = new MetaData;
+ // enc_meta->setCString(kKeyMIMEType, "video/3gpp");
+ enc_meta->setCString(kKeyMIMEType, "video/mp4v-es");
+ enc_meta->setInt32(kKeyWidth, width);
+ enc_meta->setInt32(kKeyHeight, height);
+
+ OMXDecoder *encoder = OMXDecoder::CreateEncoder(&client, enc_meta);
+
+ encoder->setSource(decoder);
+ // encoder->setSource(meta, new DummySource(width, height));
+
+#if 1
+ MPEG4Writer writer("/sdcard/output.mp4");
+ writer.addSource(enc_meta, encoder);
+ writer.start();
+ sleep(120);
+ writer.stop();
+#else
+ encoder->start();
+
+ MediaBuffer *buffer;
+ while (encoder->read(&buffer) == ::OK) {
+ printf("got an output frame of size %d\n", buffer->range_length());
+
+ buffer->release();
+ buffer = NULL;
+ }
+
+ encoder->stop();
+#endif
+
+ delete encoder;
+ encoder = NULL;
+
+ delete decoder;
+ decoder = NULL;
+
+ client.disconnect();
+
+ delete source;
+ source = NULL;
+#endif
+
+#if 0
+ CameraSource *source = CameraSource::Create();
+ printf("source = %p\n", source);
+
+ for (int i = 0; i < 100; ++i) {
+ MediaBuffer *buffer;
+ status_t err = source->read(&buffer);
+ assert(err == OK);
+
+ printf("got a frame, data=%p, size=%d\n",
+ buffer->data(), buffer->range_length());
+
+ buffer->release();
+ buffer = NULL;
+ }
+
+ delete source;
+ source = NULL;
+#endif
+
+ return 0;
+}
+
diff --git a/cmds/stagefright/stagefright.cpp b/cmds/stagefright/stagefright.cpp
new file mode 100644
index 0000000..961942a
--- /dev/null
+++ b/cmds/stagefright/stagefright.cpp
@@ -0,0 +1,200 @@
+/*
+ * Copyright (C) 2009 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <sys/time.h>
+
+#undef NDEBUG
+#include <assert.h>
+
+#include <pthread.h>
+#include <stdlib.h>
+
+#include <binder/IServiceManager.h>
+#include <binder/ProcessState.h>
+#include <media/IMediaPlayerService.h>
+#include <media/stagefright/AudioPlayer.h>
+#include <media/stagefright/CachingDataSource.h>
+#include <media/stagefright/ESDS.h>
+#include <media/stagefright/FileSource.h>
+#include <media/stagefright/MediaBuffer.h>
+#include <media/stagefright/MediaPlayerImpl.h>
+#include <media/stagefright/MediaExtractor.h>
+#include <media/stagefright/MediaSource.h>
+#include <media/stagefright/MetaData.h>
+#include <media/stagefright/MmapSource.h>
+#include <media/stagefright/OMXClient.h>
+#include <media/stagefright/OMXDecoder.h>
+
+#include "WaveWriter.h"
+
+using namespace android;
+
+////////////////////////////////////////////////////////////////////////////////
+
+static bool convertToWav(
+ OMXClient *client, const sp<MetaData> &meta, MediaSource *source) {
+ printf("convertToWav\n");
+
+ OMXDecoder *decoder = OMXDecoder::Create(client, meta);
+
+ int32_t sampleRate;
+ bool success = meta->findInt32(kKeySampleRate, &sampleRate);
+ assert(success);
+
+ int32_t numChannels;
+ success = meta->findInt32(kKeyChannelCount, &numChannels);
+ assert(success);
+
+ const char *mime;
+ success = meta->findCString(kKeyMIMEType, &mime);
+ assert(success);
+
+ if (!strcasecmp("audio/3gpp", mime)) {
+ numChannels = 1; // XXX
+ }
+
+ WaveWriter writer("/sdcard/Music/shoutcast.wav", numChannels, sampleRate);
+
+ decoder->setSource(source);
+ for (int i = 0; i < 100; ++i) {
+ MediaBuffer *buffer;
+
+ ::status_t err = decoder->read(&buffer);
+ if (err != ::OK) {
+ break;
+ }
+
+ writer.Append((const char *)buffer->data() + buffer->range_offset(),
+ buffer->range_length());
+
+ buffer->release();
+ buffer = NULL;
+ }
+
+ delete decoder;
+ decoder = NULL;
+
+ return true;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+
+static int64_t getNowUs() {
+ struct timeval tv;
+ gettimeofday(&tv, NULL);
+
+ return (int64_t)tv.tv_usec + tv.tv_sec * 1000000;
+}
+
+int main(int argc, char **argv) {
+ android::ProcessState::self()->startThreadPool();
+
+ if (argc > 1 && !strcmp(argv[1], "--list")) {
+ sp<IServiceManager> sm = defaultServiceManager();
+ sp<IBinder> binder = sm->getService(String16("media.player"));
+ sp<IMediaPlayerService> service = interface_cast<IMediaPlayerService>(binder);
+
+ assert(service.get() != NULL);
+
+ sp<IOMX> omx = service->createOMX();
+ assert(omx.get() != NULL);
+
+ List<String8> list;
+ omx->list_nodes(&list);
+
+ for (List<String8>::iterator it = list.begin();
+ it != list.end(); ++it) {
+ printf("%s\n", (*it).string());
+ }
+
+ return 0;
+ }
+
+#if 0
+ MediaPlayerImpl player(argv[1]);
+ player.play();
+
+ sleep(10000);
+#else
+ DataSource::RegisterDefaultSniffers();
+
+ OMXClient client;
+ status_t err = client.connect();
+
+ MmapSource *dataSource = new MmapSource(argv[1]);
+ MediaExtractor *extractor = MediaExtractor::Create(dataSource);
+ dataSource = NULL;
+
+ int numTracks;
+ err = extractor->countTracks(&numTracks);
+
+ sp<MetaData> meta;
+ int i;
+ for (i = 0; i < numTracks; ++i) {
+ meta = extractor->getTrackMetaData(i);
+
+ const char *mime;
+ meta->findCString(kKeyMIMEType, &mime);
+
+ if (!strncasecmp(mime, "video/", 6)) {
+ break;
+ }
+ }
+
+ OMXDecoder *decoder = OMXDecoder::Create(&client, meta);
+
+ if (decoder != NULL) {
+ MediaSource *source;
+ err = extractor->getTrack(i, &source);
+
+ decoder->setSource(source);
+
+ decoder->start();
+
+ int64_t startTime = getNowUs();
+
+ int n = 0;
+ MediaBuffer *buffer;
+ while ((err = decoder->read(&buffer)) == OK) {
+ if ((++n % 16) == 0) {
+ printf(".");
+ fflush(stdout);
+ }
+
+ buffer->release();
+ buffer = NULL;
+ }
+ decoder->stop();
+ printf("\n");
+
+ int64_t delay = getNowUs() - startTime;
+ printf("avg. %.2f fps\n", n * 1E6 / delay);
+
+ delete decoder;
+ decoder = NULL;
+
+ delete source;
+ source = NULL;
+ }
+
+ delete extractor;
+ extractor = NULL;
+
+ client.disconnect();
+#endif
+
+ return 0;
+}
diff --git a/cmds/surfaceflinger/Android.mk b/cmds/surfaceflinger/Android.mk
index 37c3d94..bfa58a1 100644
--- a/cmds/surfaceflinger/Android.mk
+++ b/cmds/surfaceflinger/Android.mk
@@ -6,6 +6,7 @@ LOCAL_SRC_FILES:= \
LOCAL_SHARED_LIBRARIES := \
libsurfaceflinger \
+ libbinder \
libutils
LOCAL_C_INCLUDES := \
diff --git a/cmds/surfaceflinger/main_surfaceflinger.cpp b/cmds/surfaceflinger/main_surfaceflinger.cpp
index 7c89578..d650721 100644
--- a/cmds/surfaceflinger/main_surfaceflinger.cpp
+++ b/cmds/surfaceflinger/main_surfaceflinger.cpp
@@ -1,6 +1,6 @@
-#include <utils/IPCThreadState.h>
-#include <utils/ProcessState.h>
-#include <utils/IServiceManager.h>
+#include <binder/IPCThreadState.h>
+#include <binder/ProcessState.h>
+#include <binder/IServiceManager.h>
#include <utils/Log.h>
#include <SurfaceFlinger.h>
diff --git a/cmds/system_server/Android.mk b/cmds/system_server/Android.mk
index 0a684e8..ad537977 100644
--- a/cmds/system_server/Android.mk
+++ b/cmds/system_server/Android.mk
@@ -6,6 +6,7 @@ LOCAL_SRC_FILES:= \
LOCAL_SHARED_LIBRARIES := \
libutils \
+ libbinder \
libsystem_server
LOCAL_C_INCLUDES := \
diff --git a/cmds/system_server/library/Android.mk b/cmds/system_server/library/Android.mk
index 580331a..1813d3e 100644
--- a/cmds/system_server/library/Android.mk
+++ b/cmds/system_server/library/Android.mk
@@ -20,6 +20,7 @@ LOCAL_SHARED_LIBRARIES := \
libcameraservice \
libmediaplayerservice \
libutils \
+ libbinder \
libcutils
LOCAL_MODULE:= libsystem_server
diff --git a/cmds/system_server/library/system_init.cpp b/cmds/system_server/library/system_init.cpp
index 73b23e2..1d57fdc 100644
--- a/cmds/system_server/library/system_init.cpp
+++ b/cmds/system_server/library/system_init.cpp
@@ -8,15 +8,16 @@
#define LOG_TAG "sysproc"
-#include <utils/IPCThreadState.h>
-#include <utils/ProcessState.h>
-#include <utils/IServiceManager.h>
+#include <binder/IPCThreadState.h>
+#include <binder/ProcessState.h>
+#include <binder/IServiceManager.h>
#include <utils/TextOutput.h>
#include <utils/Log.h>
#include <SurfaceFlinger.h>
#include <AudioFlinger.h>
#include <CameraService.h>
+#include <AudioPolicyService.h>
#include <MediaPlayerService.h>
#include <android_runtime/AndroidRuntime.h>
@@ -80,6 +81,9 @@ extern "C" status_t system_init()
// Start the camera service
CameraService::instantiate();
+
+ // Start the audio policy service
+ AudioPolicyService::instantiate();
}
// And now start the Android runtime. We have to do this bit
diff --git a/cmds/system_server/system_main.cpp b/cmds/system_server/system_main.cpp
index ca16e57..543f650 100644
--- a/cmds/system_server/system_main.cpp
+++ b/cmds/system_server/system_main.cpp
@@ -9,7 +9,7 @@
#define LOG_TAG "sysproc"
-#include <utils/IPCThreadState.h>
+#include <binder/IPCThreadState.h>
#include <utils/Log.h>
#include <private/android_filesystem_config.h>