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

Commit f5e1faf1 authored by Nipun Kwatra's avatar Nipun Kwatra Committed by Android (Google) Code Review
Browse files

Merge changes I71f5b0fc,I92c7accb

* changes:
  Moving decision to use still camera to CameraSourceTimeLapse
  pass auxiliary video parameters.
parents 7e955e7c 4a857e62
Loading
Loading
Loading
Loading
+6 −3
Original line number Diff line number Diff line
@@ -31,13 +31,12 @@ class Camera;

class CameraSourceTimeLapse : public CameraSource {
public:
    static CameraSourceTimeLapse *Create(bool useStillCameraForTimeLapse,
    static CameraSourceTimeLapse *Create(
        int64_t timeBetweenTimeLapseFrameCaptureUs,
        int32_t width, int32_t height,
        int32_t videoFrameRate);

    static CameraSourceTimeLapse *CreateFromCamera(const sp<Camera> &camera,
        bool useStillCameraForTimeLapse,
        int64_t timeBetweenTimeLapseFrameCaptureUs,
        int32_t width, int32_t height,
        int32_t videoFrameRate);
@@ -87,7 +86,6 @@ private:
    bool mCameraIdle;

    CameraSourceTimeLapse(const sp<Camera> &camera,
        bool useStillCameraForTimeLapse,
        int64_t timeBetweenTimeLapseFrameCaptureUs,
        int32_t width, int32_t height,
        int32_t videoFrameRate);
@@ -124,6 +122,11 @@ private:
    virtual void dataCallbackTimestamp(int64_t timestampUs, int32_t msgType,
            const sp<IMemory> &data);

    // If the passed in size (width x height) is a supported preview size,
    // the function sets the camera's preview size to it and returns true.
    // Otherwise returns false.
    bool trySettingPreviewSize(int32_t width, int32_t height);

    // The still camera may not support the demanded video width and height.
    // We look for the supported picture sizes from the still camera and
    // choose the smallest one with either dimensions higher than the corresponding
+51 −6
Original line number Diff line number Diff line
@@ -299,13 +299,60 @@ public class MediaRecorder
            int timeBetweenTimeLapseFrameCaptureMs, int encoderLevel) {
        setParameter(String.format("time-lapse-enable=%d",
                    (enableTimeLapse) ? 1 : 0));
        setParameter(String.format("use-still-camera-for-time-lapse=%d",
                    (useStillCameraForTimeLapse) ? 1 : 0));
        setParameter(String.format("time-between-time-lapse-frame-capture=%d",
                    timeBetweenTimeLapseFrameCaptureMs));
        setVideoEncoderLevel(encoderLevel);
    }

    /**
     * Enables time lapse capture and sets its parameters. This method should
     * be called after setProfile().
     *
     * @param timeBetweenTimeLapseFrameCaptureMs time between two captures of time lapse frames.
     * @hide
     */
    public void enableTimeLapse(int timeBetweenTimeLapseFrameCaptureMs) {
        setParameter(String.format("time-lapse-enable=1"));
        setParameter(String.format("time-between-time-lapse-frame-capture=%d",
                    timeBetweenTimeLapseFrameCaptureMs));
    }

    /**
     * Sets filename and parameters for auxiliary time lapse video.
     *
     * @param fd an open file descriptor to be written into.
     * @param videoFrameWidth width of the auxiliary video.
     * @param videoFrameHeight height of the auxiliary video.
     * @param videoBitRate bit rate of the auxiliary video
     * @hide
     * */
    public void setAuxVideoParameters(FileDescriptor fd,
            int videoFrameWidth, int videoFrameHeight,
            int videoBitRate) {
        setAuxiliaryOutputFile(fd);
        setParameter(String.format("video-aux-param-width=%d", videoFrameWidth));
        setParameter(String.format("video-aux-param-height=%d", videoFrameHeight));
        setParameter(String.format("video-aux-param-encoding-bitrate=%d", videoBitRate));
    }

    /**
     * Sets filename and parameters for auxiliary time lapse video.
     *
     * @param path The pathname to use for the auxiliary video.
     * @param videoFrameWidth width of the auxiliary video.
     * @param videoFrameHeight height of the auxiliary video.
     * @param videoBitRate bit rate of the auxiliary video
     * @hide
     * */
    public void setAuxVideoParameters(String path,
            int videoFrameWidth, int videoFrameHeight,
            int videoBitRate) {
        setAuxiliaryOutputFile(path);
        setParameter(String.format("video-aux-param-width=%d", videoFrameWidth));
        setParameter(String.format("video-aux-param-height=%d", videoFrameHeight));
        setParameter(String.format("video-aux-param-encoding-bitrate=%d", videoBitRate));
    }

    /**
     * Sets the format of the output file produced during recording. Call this
     * after setAudioSource()/setVideoSource() but before prepare().
@@ -489,9 +536,8 @@ public class MediaRecorder
     * @param fd an open file descriptor to be written into.
     * @throws IllegalStateException if it is called before
     * setOutputFormat() or after prepare()
     * @hide
     */
    public void setAuxiliaryOutputFile(FileDescriptor fd) throws IllegalStateException
    private void setAuxiliaryOutputFile(FileDescriptor fd) throws IllegalStateException
    {
        mPrepareAuxiliaryFile = true;
        mPathAux = null;
@@ -505,9 +551,8 @@ public class MediaRecorder
     * @param path The pathname to use.
     * @throws IllegalStateException if it is called before
     * setOutputFormat() or after prepare()
     * @hide
     */
    public void setAuxiliaryOutputFile(String path) throws IllegalStateException
    private void setAuxiliaryOutputFile(String path) throws IllegalStateException
    {
        mPrepareAuxiliaryFile = true;
        mFdAux = null;
+4 −23
Original line number Diff line number Diff line
@@ -507,19 +507,6 @@ status_t StagefrightRecorder::setParamTimeLapseEnable(int32_t timeLapseEnable) {
    return OK;
}

status_t StagefrightRecorder::setParamUseStillCameraForTimeLapse(int32_t useStillCamera) {
    LOGV("setParamUseStillCameraForTimeLapse: %d", useStillCamera);

    if(useStillCamera == 0) {
        mUseStillCameraForTimeLapse= false;
    } else if (useStillCamera == 1) {
        mUseStillCameraForTimeLapse= true;
    } else {
        return BAD_VALUE;
    }
    return OK;
}

status_t StagefrightRecorder::setParamTimeBetweenTimeLapseFrameCapture(int64_t timeUs) {
    LOGV("setParamTimeBetweenTimeLapseFrameCapture: %lld us", timeUs);

@@ -657,11 +644,6 @@ status_t StagefrightRecorder::setParameter(
        if (safe_strtoi32(value.string(), &timeLapseEnable)) {
            return setParamTimeLapseEnable(timeLapseEnable);
        }
    } else if (key == "use-still-camera-for-time-lapse") {
        int32_t useStillCamera;
        if (safe_strtoi32(value.string(), &useStillCamera)) {
            return setParamUseStillCameraForTimeLapse(useStillCamera);
        }
    } else if (key == "time-between-time-lapse-frame-capture") {
        int64_t timeBetweenTimeLapseFrameCaptureMs;
        if (safe_strtoi64(value.string(), &timeBetweenTimeLapseFrameCaptureMs)) {
@@ -1008,10 +990,10 @@ status_t StagefrightRecorder::setupCamera() {
    // Set the actual video recording frame size
    CameraParameters params(mCamera->getParameters());

    // dont change the preview size when using still camera for time lapse
    // dont change the preview size because time lapse may be using still camera
    // as mVideoWidth, mVideoHeight may correspond to HD resolution not
    // supported by the video camera.
    if (!(mCaptureTimeLapse && mUseStillCameraForTimeLapse)) {
    if (!mCaptureTimeLapse) {
        params.setPreviewSize(mVideoWidth, mVideoHeight);
    }

@@ -1027,7 +1009,7 @@ status_t StagefrightRecorder::setupCamera() {
    // Check on video frame size
    int frameWidth = 0, frameHeight = 0;
    newCameraParams.getPreviewSize(&frameWidth, &frameHeight);
    if (!(mCaptureTimeLapse && mUseStillCameraForTimeLapse) &&
    if (!mCaptureTimeLapse &&
        (frameWidth  < 0 || frameWidth  != mVideoWidth ||
        frameHeight < 0 || frameHeight != mVideoHeight)) {
        LOGE("Failed to set the video frame size to %dx%d",
@@ -1072,7 +1054,7 @@ status_t StagefrightRecorder::setupCameraSource(sp<CameraSource> *cameraSource)
    if (err != OK) return err;

    *cameraSource = (mCaptureTimeLapse) ?
        CameraSourceTimeLapse::CreateFromCamera(mCamera, mUseStillCameraForTimeLapse,
        CameraSourceTimeLapse::CreateFromCamera(mCamera,
                mTimeBetweenTimeLapseFrameCaptureUs, mVideoWidth, mVideoHeight, mFrameRate):
        CameraSource::CreateFromCamera(mCamera);
    CHECK(*cameraSource != NULL);
@@ -1418,7 +1400,6 @@ status_t StagefrightRecorder::reset() {
    mMaxFileSizeBytes = 0;
    mTrackEveryTimeDurationUs = 0;
    mCaptureTimeLapse = false;
    mUseStillCameraForTimeLapse = true;
    mTimeBetweenTimeLapseFrameCaptureUs = -1;
    mCaptureAuxVideo = false;
    mCameraSourceSplitter = NULL;
+0 −2
Original line number Diff line number Diff line
@@ -98,7 +98,6 @@ private:
    int64_t mTrackEveryTimeDurationUs;

    bool mCaptureTimeLapse;
    bool mUseStillCameraForTimeLapse;
    int64_t mTimeBetweenTimeLapseFrameCaptureUs;
    bool mCaptureAuxVideo;
    sp<MediaSourceSplitter> mCameraSourceSplitter;
@@ -138,7 +137,6 @@ private:
    status_t setParamAudioSamplingRate(int32_t sampleRate);
    status_t setParamAudioTimeScale(int32_t timeScale);
    status_t setParamTimeLapseEnable(int32_t timeLapseEnable);
    status_t setParamUseStillCameraForTimeLapse(int32_t useStillCamera);
    status_t setParamTimeBetweenTimeLapseFrameCapture(int64_t timeUs);
    status_t setParamAuxVideoHeight(int32_t height);
    status_t setParamAuxVideoWidth(int32_t width);
+41 −9
Original line number Diff line number Diff line
@@ -37,7 +37,7 @@
namespace android {

// static
CameraSourceTimeLapse *CameraSourceTimeLapse::Create(bool useStillCameraForTimeLapse,
CameraSourceTimeLapse *CameraSourceTimeLapse::Create(
        int64_t timeBetweenTimeLapseFrameCaptureUs,
        int32_t width, int32_t height,
        int32_t videoFrameRate) {
@@ -47,13 +47,12 @@ CameraSourceTimeLapse *CameraSourceTimeLapse::Create(bool useStillCameraForTimeL
        return NULL;
    }

    return new CameraSourceTimeLapse(camera, useStillCameraForTimeLapse,
            timeBetweenTimeLapseFrameCaptureUs, width, height, videoFrameRate);
    return new CameraSourceTimeLapse(camera, timeBetweenTimeLapseFrameCaptureUs,
            width, height, videoFrameRate);
}

// static
CameraSourceTimeLapse *CameraSourceTimeLapse::CreateFromCamera(const sp<Camera> &camera,
        bool useStillCameraForTimeLapse,
        int64_t timeBetweenTimeLapseFrameCaptureUs,
        int32_t width, int32_t height,
        int32_t videoFrameRate) {
@@ -61,17 +60,15 @@ CameraSourceTimeLapse *CameraSourceTimeLapse::CreateFromCamera(const sp<Camera>
        return NULL;
    }

    return new CameraSourceTimeLapse(camera, useStillCameraForTimeLapse,
            timeBetweenTimeLapseFrameCaptureUs, width, height, videoFrameRate);
    return new CameraSourceTimeLapse(camera, timeBetweenTimeLapseFrameCaptureUs,
            width, height, videoFrameRate);
}

CameraSourceTimeLapse::CameraSourceTimeLapse(const sp<Camera> &camera,
        bool useStillCameraForTimeLapse,
        int64_t timeBetweenTimeLapseFrameCaptureUs,
        int32_t width, int32_t height,
        int32_t videoFrameRate)
    : CameraSource(camera),
      mUseStillCameraForTimeLapse(useStillCameraForTimeLapse),
      mTimeBetweenTimeLapseFrameCaptureUs(timeBetweenTimeLapseFrameCaptureUs),
      mTimeBetweenTimeLapseVideoFramesUs(1E6/videoFrameRate),
      mLastTimeLapseFrameRealTimestampUs(0),
@@ -80,7 +77,13 @@ CameraSourceTimeLapse::CameraSourceTimeLapse(const sp<Camera> &camera,
    LOGV("starting time lapse mode");
    mVideoWidth = width;
    mVideoHeight = height;
    if (mUseStillCameraForTimeLapse) {

    if (trySettingPreviewSize(width, height)) {
        mUseStillCameraForTimeLapse = false;
    } else {
        // TODO: Add a check to see that mTimeBetweenTimeLapseFrameCaptureUs is greater
        // than the fastest rate at which the still camera can take pictures.
        mUseStillCameraForTimeLapse = true;
        CHECK(setPictureSizeToClosestSupported(width, height));
        mNeedCropping = computeCropRectangleOffset();
        mMeta->setInt32(kKeyWidth, width);
@@ -91,6 +94,35 @@ CameraSourceTimeLapse::CameraSourceTimeLapse(const sp<Camera> &camera,
CameraSourceTimeLapse::~CameraSourceTimeLapse() {
}

bool CameraSourceTimeLapse::trySettingPreviewSize(int32_t width, int32_t height) {
    int64_t token = IPCThreadState::self()->clearCallingIdentity();
    String8 s = mCamera->getParameters();
    IPCThreadState::self()->restoreCallingIdentity(token);

    CameraParameters params(s);
    Vector<Size> supportedSizes;
    params.getSupportedPreviewSizes(supportedSizes);

    bool previewSizeSupported = false;
    for (uint32_t i = 0; i < supportedSizes.size(); ++i) {
        int32_t pictureWidth = supportedSizes[i].width;
        int32_t pictureHeight = supportedSizes[i].height;

        if ((pictureWidth == width) && (pictureHeight == height)) {
            previewSizeSupported = true;
        }
    }

    if (previewSizeSupported) {
        LOGV("Video size (%d, %d) is a supported preview size", width, height);
        params.setPreviewSize(width, height);
        CHECK(mCamera->setParameters(params.flatten()));
        return true;
    }

    return false;
}

bool CameraSourceTimeLapse::setPictureSizeToClosestSupported(int32_t width, int32_t height) {
    int64_t token = IPCThreadState::self()->clearCallingIdentity();
    String8 s = mCamera->getParameters();