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

Commit b00e2466 authored by James Dong's avatar James Dong
Browse files

Use timestamp from camera driver for CameraSource

Change-Id: I09ddec69997c43b8f17fdd21304c76cb4c5ab8cf
parent 55fb51aa
Loading
Loading
Loading
Loading
+2 −1
Original line number Original line Diff line number Diff line
@@ -16,6 +16,7 @@
** limitations under the License.
** limitations under the License.
*/
*/


//#define LOG_NDEBUG 0
#define LOG_TAG "CameraService"
#define LOG_TAG "CameraService"
#include <utils/Log.h>
#include <utils/Log.h>


@@ -247,7 +248,7 @@ CameraService::Client::Client(const sp<CameraService>& cameraService,
status_t CameraService::Client::checkPid()
status_t CameraService::Client::checkPid()
{
{
    int callingPid = getCallingPid();
    int callingPid = getCallingPid();
    if (mClientPid == callingPid) return NO_ERROR;
    if (mClientPid == callingPid || callingPid == getpid()) return NO_ERROR;
    LOGW("Attempt to use locked camera (client %p) from different process "
    LOGW("Attempt to use locked camera (client %p) from different process "
        " (old pid %d, new pid %d)",
        " (old pid %d, new pid %d)",
        getCameraClient()->asBinder().get(), mClientPid, callingPid);
        getCameraClient()->asBinder().get(), mClientPid, callingPid);
+7 −2
Original line number Original line Diff line number Diff line
@@ -34,7 +34,7 @@ class Camera;
class CameraSource : public MediaSource {
class CameraSource : public MediaSource {
public:
public:
    static CameraSource *Create();
    static CameraSource *Create();
    static CameraSource *CreateFromICamera(const sp<ICamera> &icamera);
    static CameraSource *CreateFromCamera(const sp<Camera> &camera);


    virtual ~CameraSource();
    virtual ~CameraSource();


@@ -61,12 +61,17 @@ private:


    int mWidth, mHeight;
    int mWidth, mHeight;
    int64_t mFirstFrameTimeUs;
    int64_t mFirstFrameTimeUs;
    int64_t mLastFrameTimestampUs;
    int32_t mNumFrames;
    int32_t mNumFrames;
    int32_t mNumFramesReleased;
    bool mStarted;
    bool mStarted;


    CameraSource(const sp<Camera> &camera);
    CameraSource(const sp<Camera> &camera);


    void dataCallback(int32_t msgType, const sp<IMemory> &data);
    void dataCallbackTimestamp(
            int64_t timestampUs, int32_t msgType, const sp<IMemory> &data);

    void releaseQueuedFrames();


    CameraSource(const CameraSource &);
    CameraSource(const CameraSource &);
    CameraSource &operator=(const CameraSource &);
    CameraSource &operator=(const CameraSource &);
+1 −0
Original line number Original line Diff line number Diff line
@@ -37,6 +37,7 @@ LOCAL_SHARED_LIBRARIES := \
	libvorbisidec         			\
	libvorbisidec         			\
	libsonivox            			\
	libsonivox            			\
	libmedia              			\
	libmedia              			\
	libcamera_client      			\
	libandroid_runtime    			\
	libandroid_runtime    			\
	libstagefright        			\
	libstagefright        			\
	libstagefright_omx    			\
	libstagefright_omx    			\
+36 −2
Original line number Original line Diff line number Diff line
@@ -20,6 +20,7 @@


#include "StagefrightRecorder.h"
#include "StagefrightRecorder.h"


#include <binder/IPCThreadState.h>
#include <media/stagefright/AudioSource.h>
#include <media/stagefright/AudioSource.h>
#include <media/stagefright/AMRWriter.h>
#include <media/stagefright/AMRWriter.h>
#include <media/stagefright/CameraSource.h>
#include <media/stagefright/CameraSource.h>
@@ -30,8 +31,11 @@
#include <media/stagefright/OMXClient.h>
#include <media/stagefright/OMXClient.h>
#include <media/stagefright/OMXCodec.h>
#include <media/stagefright/OMXCodec.h>
#include <camera/ICamera.h>
#include <camera/ICamera.h>
#include <camera/Camera.h>
#include <surfaceflinger/ISurface.h>
#include <surfaceflinger/ISurface.h>
#include <utils/Errors.h>
#include <utils/Errors.h>
#include <sys/types.h>
#include <unistd.h>


namespace android {
namespace android {


@@ -96,7 +100,25 @@ status_t StagefrightRecorder::setVideoFrameRate(int frames_per_second) {
}
}


status_t StagefrightRecorder::setCamera(const sp<ICamera> &camera) {
status_t StagefrightRecorder::setCamera(const sp<ICamera> &camera) {
    mCamera = camera;
    LOGV("setCamera: pid %d pid %d", IPCThreadState::self()->getCallingPid(), getpid());
    if (camera == 0) {
        LOGE("camera is NULL");
        return UNKNOWN_ERROR;
    }

    mFlags &= ~ FLAGS_SET_CAMERA | FLAGS_HOT_CAMERA;
    mCamera = Camera::create(camera);
    if (mCamera == 0) {
        LOGE("Unable to connect to camera");
        return UNKNOWN_ERROR;
    }

    LOGV("Connected to camera");
    mFlags |= FLAGS_SET_CAMERA;
    if (mCamera->previewEnabled()) {
        LOGV("camera is hot");
        mFlags |= FLAGS_HOT_CAMERA;
    }


    return OK;
    return OK;
}
}
@@ -240,7 +262,7 @@ status_t StagefrightRecorder::startMPEG4Recording() {
        CHECK(mCamera != NULL);
        CHECK(mCamera != NULL);


        sp<CameraSource> cameraSource =
        sp<CameraSource> cameraSource =
            CameraSource::CreateFromICamera(mCamera);
            CameraSource::CreateFromCamera(mCamera);


        CHECK(cameraSource != NULL);
        CHECK(cameraSource != NULL);


@@ -314,6 +336,17 @@ status_t StagefrightRecorder::stop() {
status_t StagefrightRecorder::close() {
status_t StagefrightRecorder::close() {
    stop();
    stop();


    if (mCamera != 0) {
        if ((mFlags & FLAGS_HOT_CAMERA) == 0) {
            LOGV("Camera was cold when we started, stopping preview");
            mCamera->stopPreview();
        }
        if (mFlags & FLAGS_SET_CAMERA) {
            LOGV("Unlocking camera");
            mCamera->unlock();
        }
        mFlags = 0;
    }
    return OK;
    return OK;
}
}


@@ -329,6 +362,7 @@ status_t StagefrightRecorder::reset() {
    mVideoHeight = -1;
    mVideoHeight = -1;
    mFrameRate = -1;
    mFrameRate = -1;
    mOutputFd = -1;
    mOutputFd = -1;
    mFlags = 0;


    return OK;
    return OK;
}
}
+8 −1
Original line number Original line Diff line number Diff line
@@ -23,6 +23,7 @@


namespace android {
namespace android {


class Camera;
struct MediaSource;
struct MediaSource;
struct MediaWriter;
struct MediaWriter;


@@ -52,7 +53,12 @@ struct StagefrightRecorder : public MediaRecorderBase {
    virtual status_t getMaxAmplitude(int *max);
    virtual status_t getMaxAmplitude(int *max);


private:
private:
    sp<ICamera> mCamera;
    enum CameraFlags {
        FLAGS_SET_CAMERA = 1L << 0,
        FLAGS_HOT_CAMERA = 1L << 1,
    };

    sp<Camera> mCamera;
    sp<ISurface> mPreviewSurface;
    sp<ISurface> mPreviewSurface;
    sp<IMediaPlayerClient> mListener;
    sp<IMediaPlayerClient> mListener;
    sp<MediaWriter> mWriter;
    sp<MediaWriter> mWriter;
@@ -66,6 +72,7 @@ private:
    int mFrameRate;
    int mFrameRate;
    String8 mParams;
    String8 mParams;
    int mOutputFd;
    int mOutputFd;
    int32_t mFlags;


    status_t startMPEG4Recording();
    status_t startMPEG4Recording();
    status_t startAMRRecording();
    status_t startAMRRecording();
Loading