summaryrefslogtreecommitdiffstats
path: root/cmds
diff options
context:
space:
mode:
authorMarco Nelissen <marcone@google.com>2013-12-05 12:26:30 -0800
committerMarco Nelissen <marcone@google.com>2013-12-05 12:38:15 -0800
commita2354479716db40d865c597dc572ea83573caac2 (patch)
tree01f3d515ffee05e9f352a11d8e6e2de6cf302b4f /cmds
parent84acd489b93e04bea7aab06d8abb024eef2576fd (diff)
downloadframeworks_av-a2354479716db40d865c597dc572ea83573caac2.zip
frameworks_av-a2354479716db40d865c597dc572ea83573caac2.tar.gz
frameworks_av-a2354479716db40d865c597dc572ea83573caac2.tar.bz2
Print statistics after ctrl-C
And exit cleanly when no audio or video track is found. Change-Id: I3e030d60c774ad3ede839cba999ab32dd86bab5a
Diffstat (limited to 'cmds')
-rw-r--r--cmds/stagefright/sf2.cpp59
1 files changed, 43 insertions, 16 deletions
diff --git a/cmds/stagefright/sf2.cpp b/cmds/stagefright/sf2.cpp
index c817443..439b6e4 100644
--- a/cmds/stagefright/sf2.cpp
+++ b/cmds/stagefright/sf2.cpp
@@ -18,6 +18,8 @@
#define LOG_TAG "sf2"
#include <utils/Log.h>
+#include <signal.h>
+
#include <binder/ProcessState.h>
#include <media/stagefright/foundation/hexdump.h>
@@ -42,6 +44,18 @@
using namespace android;
+volatile static bool ctrlc = false;
+
+static sighandler_t oldhandler = NULL;
+
+static void mysighandler(int signum) {
+ if (signum == SIGINT) {
+ ctrlc = true;
+ return;
+ }
+ oldhandler(signum);
+}
+
struct Controller : public AHandler {
Controller(const char *uri, bool decodeAudio,
const sp<Surface> &surface, bool renderToSurface)
@@ -62,7 +76,29 @@ protected:
virtual ~Controller() {
}
+ virtual void printStatistics() {
+ int64_t delayUs = ALooper::GetNowUs() - mStartTimeUs;
+ if (mDecodeAudio) {
+ printf("%lld bytes received. %.2f KB/sec\n",
+ mTotalBytesReceived,
+ mTotalBytesReceived * 1E6 / 1024 / delayUs);
+ } else {
+ printf("%d frames decoded, %.2f fps. %lld bytes "
+ "received. %.2f KB/sec\n",
+ mNumOutputBuffersReceived,
+ mNumOutputBuffersReceived * 1E6 / delayUs,
+ mTotalBytesReceived,
+ mTotalBytesReceived * 1E6 / 1024 / delayUs);
+ }
+ }
+
virtual void onMessageReceived(const sp<AMessage> &msg) {
+ if (ctrlc) {
+ printf("\n");
+ printStatistics();
+ (new AMessage(kWhatStop, id()))->post();
+ ctrlc = false;
+ }
switch (msg->what()) {
case kWhatStart:
{
@@ -98,7 +134,10 @@ protected:
break;
}
}
- CHECK(mSource != NULL);
+ if (mSource == NULL) {
+ printf("no %s track found\n", mDecodeAudio ? "audio" : "video");
+ exit (1);
+ }
CHECK_EQ(mSource->start(), (status_t)OK);
@@ -180,21 +219,7 @@ protected:
|| what == ACodec::kWhatError) {
printf((what == ACodec::kWhatEOS) ? "$\n" : "E\n");
- int64_t delayUs = ALooper::GetNowUs() - mStartTimeUs;
-
- if (mDecodeAudio) {
- printf("%lld bytes received. %.2f KB/sec\n",
- mTotalBytesReceived,
- mTotalBytesReceived * 1E6 / 1024 / delayUs);
- } else {
- printf("%d frames decoded, %.2f fps. %lld bytes "
- "received. %.2f KB/sec\n",
- mNumOutputBuffersReceived,
- mNumOutputBuffersReceived * 1E6 / delayUs,
- mTotalBytesReceived,
- mTotalBytesReceived * 1E6 / 1024 / delayUs);
- }
-
+ printStatistics();
(new AMessage(kWhatStop, id()))->post();
} else if (what == ACodec::kWhatFlushCompleted) {
mSeekState = SEEK_FLUSH_COMPLETED;
@@ -638,6 +663,8 @@ int main(int argc, char **argv) {
looper->registerHandler(controller);
+ signal(SIGINT, mysighandler);
+
controller->startAsync();
CHECK_EQ(looper->start(true /* runOnCallingThread */), (status_t)OK);