#include <media/stagefright/MediaMuxer.h>
#include <media/ICrypto.h>
+#include <stdlib.h>
+#include <string.h>
#include <stdio.h>
#include <fcntl.h>
#include <signal.h>
format->setFloat("frame-rate", displayFps);
format->setInt32("i-frame-interval", 10);
- /// MediaCodec
+ // MediaCodec
sp<ALooper> looper = new ALooper;
looper->setName("screenrecord_looper");
looper->start();
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;
}
}
}
/*
+ * 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.
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;
}