summaryrefslogtreecommitdiffstats
path: root/cmds
diff options
context:
space:
mode:
authorAndy McFadden <fadden@android.com>2013-08-23 13:49:38 -0700
committerAndy McFadden <fadden@android.com>2013-08-28 07:38:28 -0700
commit48326940f48390e79476e5ce7c2a18b8201cdafc (patch)
tree56ba061a0ef635c2242dca1f5972246edc9a736b /cmds
parente07f53720bcf543bcfe90c228a49c2a85a3fdb4c (diff)
downloadframeworks_av-48326940f48390e79476e5ce7c2a18b8201cdafc.zip
frameworks_av-48326940f48390e79476e5ce7c2a18b8201cdafc.tar.gz
frameworks_av-48326940f48390e79476e5ce7c2a18b8201cdafc.tar.bz2
Notify the media scanner
Use an "am broadcast" command to notify the media scanner that a new video file is available. Bug 10096103 Change-Id: I8261d81d96832969ebb9031a9766c1b1f2a569ed
Diffstat (limited to 'cmds')
-rw-r--r--cmds/screenrecord/screenrecord.cpp38
1 files changed, 36 insertions, 2 deletions
diff --git a/cmds/screenrecord/screenrecord.cpp b/cmds/screenrecord/screenrecord.cpp
index 3f8567c..ceda908 100644
--- a/cmds/screenrecord/screenrecord.cpp
+++ b/cmds/screenrecord/screenrecord.cpp
@@ -35,6 +35,8 @@
#include <media/stagefright/MediaMuxer.h>
#include <media/ICrypto.h>
+#include <stdlib.h>
+#include <string.h>
#include <stdio.h>
#include <fcntl.h>
#include <signal.h>
@@ -138,7 +140,7 @@ static status_t prepareEncoder(float displayFps, sp<MediaCodec>* pCodec,
format->setFloat("frame-rate", displayFps);
format->setInt32("i-frame-interval", 10);
- /// MediaCodec
+ // MediaCodec
sp<ALooper> looper = new ALooper;
looper->setName("screenrecord_looper");
looper->start();
@@ -370,10 +372,15 @@ static status_t runEncoder(const sp<MediaCodec>& encoder,
if (err != NO_ERROR) {
fprintf(stderr,
"Unable to get new output buffers (err=%d)\n", err);
+ return err;
}
break;
+ case INVALID_OPERATION:
+ fprintf(stderr, "Request for encoder buffer failed\n");
+ return err;
default:
- ALOGW("Got weird result %d from dequeueOutputBuffer", err);
+ fprintf(stderr,
+ "Got weird result %d from dequeueOutputBuffer\n", err);
return err;
}
}
@@ -477,6 +484,29 @@ static status_t recordScreen(const char* fileName) {
}
/*
+ * Sends a broadcast to the media scanner to tell it about the new video.
+ */
+static status_t notifyMediaScanner(const char* fileName) {
+ String8 command("am broadcast -a android.intent.action.MEDIA_SCANNER_SCAN_FILE -d file://");
+ command.append(fileName);
+ if (gVerbose) {
+ printf("Shell: %s\n", command.string());
+ }
+
+ // TODO: for non-verbose mode we should suppress stdout
+ int status = system(command.string());
+ if (status < 0) {
+ fprintf(stderr, "Unable to fork shell for media scanner broadcast\n");
+ return UNKNOWN_ERROR;
+ } else if (status != 0) {
+ fprintf(stderr, "am command failed (status=%d): '%s'\n",
+ status, command.string());
+ return UNKNOWN_ERROR;
+ }
+ return NO_ERROR;
+}
+
+/*
* Parses a string of the form "1280x720".
*
* Returns true on success.
@@ -609,6 +639,10 @@ int main(int argc, char* const argv[]) {
close(fd);
status_t err = recordScreen(fileName);
+ if (err == NO_ERROR) {
+ // Try to notify the media scanner. Not fatal if this fails.
+ notifyMediaScanner(fileName);
+ }
ALOGD(err == NO_ERROR ? "success" : "failed");
return (int) err;
}