Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit dd2eb288 authored by Marco Nelissen's avatar Marco Nelissen Committed by android-build-merger
Browse files

Merge \"screenrecord: fix race condition\" into nyc-mr1-dev

am: a6c2f960

Change-Id: I2dc9541d7f2122a5b5aac15de4680b2dea865b0c
parents afaf9cd1 a6c2f960
Loading
Loading
Loading
Loading
+7 −5
Original line number Diff line number Diff line
@@ -80,7 +80,7 @@ static uint32_t gBitRate = 4000000; // 4Mbps
static uint32_t gTimeLimitSec = kMaxTimeLimitSec;

// Set by signal handler to stop recording.
static volatile bool gStopRequested;
static volatile bool gStopRequested = false;

// Previous signal handler state, restored after first hit.
static struct sigaction gOrigSigactionINT;
@@ -334,9 +334,6 @@ static status_t runEncoder(const sp<MediaCodec>& encoder,
        return err;
    }

    // This is set by the signal handler.
    gStopRequested = false;

    // Run until we're signaled.
    while (!gStopRequested) {
        size_t bufIndex, offset, size;
@@ -640,6 +637,11 @@ static status_t recordScreen(const char* fileName) {
        case FORMAT_MP4: {
            // Configure muxer.  We have to wait for the CSD blob from the encoder
            // before we can start it.
            err = unlink(fileName);
            if (err != 0 && errno != ENOENT) {
                fprintf(stderr, "ERROR: couldn't remove existing file\n");
                abort();
            }
            int fd = open(fileName, O_CREAT | O_LARGEFILE | O_TRUNC | O_RDWR, S_IRUSR | S_IWUSR);
            if (fd < 0) {
                fprintf(stderr, "ERROR: couldn't open file\n");
@@ -718,7 +720,7 @@ static status_t recordScreen(const char* fileName) {
    if (muxer != NULL) {
        // If we don't stop muxer explicitly, i.e. let the destructor run,
        // it may hang (b/11050628).
        muxer->stop();
        err = muxer->stop();
    } else if (rawFp != stdout) {
        fclose(rawFp);
    }