am 3a0b37a0: Merge "Remove the lock/unlock workaround from CameraService" into kraken
This commit is contained in:
@@ -371,10 +371,7 @@ CameraService::Client::~Client() {
|
|||||||
status_t CameraService::Client::checkPid() const {
|
status_t CameraService::Client::checkPid() const {
|
||||||
int callingPid = getCallingPid();
|
int callingPid = getCallingPid();
|
||||||
if (callingPid == mClientPid) return NO_ERROR;
|
if (callingPid == mClientPid) return NO_ERROR;
|
||||||
if (callingPid == getpid()) {
|
|
||||||
LOGW("FIXME: use camera from mediaserver without permission.");
|
|
||||||
return NO_ERROR;
|
|
||||||
}
|
|
||||||
LOGW("attempt to use a locked camera from a different process"
|
LOGW("attempt to use a locked camera from a different process"
|
||||||
" (old pid %d, new pid %d)", mClientPid, callingPid);
|
" (old pid %d, new pid %d)", mClientPid, callingPid);
|
||||||
return EBUSY;
|
return EBUSY;
|
||||||
|
|||||||
@@ -114,25 +114,27 @@ status_t StagefrightRecorder::setVideoFrameRate(int frames_per_second) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
status_t StagefrightRecorder::setCamera(const sp<ICamera> &camera) {
|
status_t StagefrightRecorder::setCamera(const sp<ICamera> &camera) {
|
||||||
LOGV("setCamera: pid %d pid %d", IPCThreadState::self()->getCallingPid(), getpid());
|
LOGV("setCamera");
|
||||||
if (camera == 0) {
|
if (camera == 0) {
|
||||||
LOGE("camera is NULL");
|
LOGE("camera is NULL");
|
||||||
return UNKNOWN_ERROR;
|
return UNKNOWN_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
mFlags &= ~ FLAGS_SET_CAMERA | FLAGS_HOT_CAMERA;
|
int64_t token = IPCThreadState::self()->clearCallingIdentity();
|
||||||
|
mFlags &= ~FLAGS_HOT_CAMERA;
|
||||||
mCamera = Camera::create(camera);
|
mCamera = Camera::create(camera);
|
||||||
if (mCamera == 0) {
|
if (mCamera == 0) {
|
||||||
LOGE("Unable to connect to camera");
|
LOGE("Unable to connect to camera");
|
||||||
|
IPCThreadState::self()->restoreCallingIdentity(token);
|
||||||
return UNKNOWN_ERROR;
|
return UNKNOWN_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
LOGV("Connected to camera");
|
LOGV("Connected to camera");
|
||||||
mFlags |= FLAGS_SET_CAMERA;
|
|
||||||
if (mCamera->previewEnabled()) {
|
if (mCamera->previewEnabled()) {
|
||||||
LOGV("camera is hot");
|
LOGV("camera is hot");
|
||||||
mFlags |= FLAGS_HOT_CAMERA;
|
mFlags |= FLAGS_HOT_CAMERA;
|
||||||
}
|
}
|
||||||
|
IPCThreadState::self()->restoreCallingIdentity(token);
|
||||||
|
|
||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
@@ -584,7 +586,12 @@ status_t StagefrightRecorder::startMPEG4Recording() {
|
|||||||
}
|
}
|
||||||
if (mVideoSource == VIDEO_SOURCE_DEFAULT
|
if (mVideoSource == VIDEO_SOURCE_DEFAULT
|
||||||
|| mVideoSource == VIDEO_SOURCE_CAMERA) {
|
|| mVideoSource == VIDEO_SOURCE_CAMERA) {
|
||||||
CHECK(mCamera != NULL);
|
|
||||||
|
int64_t token = IPCThreadState::self()->clearCallingIdentity();
|
||||||
|
if (mCamera == 0) {
|
||||||
|
mCamera = Camera::connect(0);
|
||||||
|
mCamera->lock();
|
||||||
|
}
|
||||||
|
|
||||||
// Set the actual video recording frame size
|
// Set the actual video recording frame size
|
||||||
CameraParameters params(mCamera->getParameters());
|
CameraParameters params(mCamera->getParameters());
|
||||||
@@ -601,6 +608,7 @@ status_t StagefrightRecorder::startMPEG4Recording() {
|
|||||||
frameHeight < 0 || frameHeight != mVideoHeight) {
|
frameHeight < 0 || frameHeight != mVideoHeight) {
|
||||||
LOGE("Failed to set the video frame size to %dx%d",
|
LOGE("Failed to set the video frame size to %dx%d",
|
||||||
mVideoWidth, mVideoHeight);
|
mVideoWidth, mVideoHeight);
|
||||||
|
IPCThreadState::self()->restoreCallingIdentity(token);
|
||||||
return UNKNOWN_ERROR;
|
return UNKNOWN_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -612,6 +620,7 @@ status_t StagefrightRecorder::startMPEG4Recording() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
CHECK_EQ(OK, mCamera->setPreviewDisplay(mPreviewSurface));
|
CHECK_EQ(OK, mCamera->setPreviewDisplay(mPreviewSurface));
|
||||||
|
IPCThreadState::self()->restoreCallingIdentity(token);
|
||||||
|
|
||||||
sp<CameraSource> cameraSource =
|
sp<CameraSource> cameraSource =
|
||||||
CameraSource::CreateFromCamera(mCamera);
|
CameraSource::CreateFromCamera(mCamera);
|
||||||
@@ -698,14 +707,14 @@ status_t StagefrightRecorder::close() {
|
|||||||
stop();
|
stop();
|
||||||
|
|
||||||
if (mCamera != 0) {
|
if (mCamera != 0) {
|
||||||
|
int64_t token = IPCThreadState::self()->clearCallingIdentity();
|
||||||
if ((mFlags & FLAGS_HOT_CAMERA) == 0) {
|
if ((mFlags & FLAGS_HOT_CAMERA) == 0) {
|
||||||
LOGV("Camera was cold when we started, stopping preview");
|
LOGV("Camera was cold when we started, stopping preview");
|
||||||
mCamera->stopPreview();
|
mCamera->stopPreview();
|
||||||
}
|
}
|
||||||
if (mFlags & FLAGS_SET_CAMERA) {
|
mCamera->unlock();
|
||||||
LOGV("Unlocking camera");
|
mCamera = NULL;
|
||||||
mCamera->unlock();
|
IPCThreadState::self()->restoreCallingIdentity(token);
|
||||||
}
|
|
||||||
mFlags = 0;
|
mFlags = 0;
|
||||||
}
|
}
|
||||||
return OK;
|
return OK;
|
||||||
|
|||||||
@@ -19,7 +19,7 @@
|
|||||||
#include <utils/Log.h>
|
#include <utils/Log.h>
|
||||||
|
|
||||||
#include <OMX_Component.h>
|
#include <OMX_Component.h>
|
||||||
|
#include <binder/IPCThreadState.h>
|
||||||
#include <media/stagefright/CameraSource.h>
|
#include <media/stagefright/CameraSource.h>
|
||||||
#include <media/stagefright/MediaDebug.h>
|
#include <media/stagefright/MediaDebug.h>
|
||||||
#include <media/stagefright/MediaDefs.h>
|
#include <media/stagefright/MediaDefs.h>
|
||||||
@@ -125,7 +125,11 @@ CameraSource::CameraSource(const sp<Camera> &camera)
|
|||||||
mNumFramesDropped(0),
|
mNumFramesDropped(0),
|
||||||
mCollectStats(false),
|
mCollectStats(false),
|
||||||
mStarted(false) {
|
mStarted(false) {
|
||||||
|
|
||||||
|
int64_t token = IPCThreadState::self()->clearCallingIdentity();
|
||||||
String8 s = mCamera->getParameters();
|
String8 s = mCamera->getParameters();
|
||||||
|
IPCThreadState::self()->restoreCallingIdentity(token);
|
||||||
|
|
||||||
printf("params: \"%s\"\n", s.string());
|
printf("params: \"%s\"\n", s.string());
|
||||||
|
|
||||||
int32_t width, height, stride, sliceHeight;
|
int32_t width, height, stride, sliceHeight;
|
||||||
@@ -166,8 +170,11 @@ status_t CameraSource::start(MetaData *) {
|
|||||||
&& (!strcmp(value, "1") || !strcasecmp(value, "true"))) {
|
&& (!strcmp(value, "1") || !strcasecmp(value, "true"))) {
|
||||||
mCollectStats = true;
|
mCollectStats = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int64_t token = IPCThreadState::self()->clearCallingIdentity();
|
||||||
mCamera->setListener(new CameraSourceListener(this));
|
mCamera->setListener(new CameraSourceListener(this));
|
||||||
CHECK_EQ(OK, mCamera->startRecording());
|
CHECK_EQ(OK, mCamera->startRecording());
|
||||||
|
IPCThreadState::self()->restoreCallingIdentity(token);
|
||||||
|
|
||||||
mStarted = true;
|
mStarted = true;
|
||||||
return OK;
|
return OK;
|
||||||
@@ -179,16 +186,17 @@ status_t CameraSource::stop() {
|
|||||||
mStarted = false;
|
mStarted = false;
|
||||||
mFrameAvailableCondition.signal();
|
mFrameAvailableCondition.signal();
|
||||||
|
|
||||||
|
int64_t token = IPCThreadState::self()->clearCallingIdentity();
|
||||||
mCamera->setListener(NULL);
|
mCamera->setListener(NULL);
|
||||||
mCamera->stopRecording();
|
mCamera->stopRecording();
|
||||||
|
|
||||||
releaseQueuedFrames();
|
releaseQueuedFrames();
|
||||||
|
|
||||||
while (!mFramesBeingEncoded.empty()) {
|
while (!mFramesBeingEncoded.empty()) {
|
||||||
LOGI("Waiting for outstanding frames being encoded: %d",
|
LOGI("Waiting for outstanding frames being encoded: %d",
|
||||||
mFramesBeingEncoded.size());
|
mFramesBeingEncoded.size());
|
||||||
mFrameCompleteCondition.wait(mLock);
|
mFrameCompleteCondition.wait(mLock);
|
||||||
}
|
}
|
||||||
|
mCamera = NULL;
|
||||||
|
IPCThreadState::self()->restoreCallingIdentity(token);
|
||||||
|
|
||||||
if (mCollectStats) {
|
if (mCollectStats) {
|
||||||
LOGI("Frames received/encoded/dropped: %d/%d/%d in %lld us",
|
LOGI("Frames received/encoded/dropped: %d/%d/%d in %lld us",
|
||||||
@@ -219,7 +227,11 @@ void CameraSource::signalBufferReturned(MediaBuffer *buffer) {
|
|||||||
for (List<sp<IMemory> >::iterator it = mFramesBeingEncoded.begin();
|
for (List<sp<IMemory> >::iterator it = mFramesBeingEncoded.begin();
|
||||||
it != mFramesBeingEncoded.end(); ++it) {
|
it != mFramesBeingEncoded.end(); ++it) {
|
||||||
if ((*it)->pointer() == buffer->data()) {
|
if ((*it)->pointer() == buffer->data()) {
|
||||||
|
|
||||||
|
int64_t token = IPCThreadState::self()->clearCallingIdentity();
|
||||||
mCamera->releaseRecordingFrame((*it));
|
mCamera->releaseRecordingFrame((*it));
|
||||||
|
IPCThreadState::self()->restoreCallingIdentity(token);
|
||||||
|
|
||||||
mFramesBeingEncoded.erase(it);
|
mFramesBeingEncoded.erase(it);
|
||||||
++mNumFramesEncoded;
|
++mNumFramesEncoded;
|
||||||
buffer->setObserver(0);
|
buffer->setObserver(0);
|
||||||
@@ -273,7 +285,9 @@ void CameraSource::dataCallbackTimestamp(int64_t timestampUs,
|
|||||||
LOGV("dataCallbackTimestamp: timestamp %lld us", timestampUs);
|
LOGV("dataCallbackTimestamp: timestamp %lld us", timestampUs);
|
||||||
Mutex::Autolock autoLock(mLock);
|
Mutex::Autolock autoLock(mLock);
|
||||||
if (!mStarted) {
|
if (!mStarted) {
|
||||||
|
int64_t token = IPCThreadState::self()->clearCallingIdentity();
|
||||||
mCamera->releaseRecordingFrame(data);
|
mCamera->releaseRecordingFrame(data);
|
||||||
|
IPCThreadState::self()->restoreCallingIdentity(token);
|
||||||
++mNumFramesReceived;
|
++mNumFramesReceived;
|
||||||
++mNumFramesDropped;
|
++mNumFramesDropped;
|
||||||
return;
|
return;
|
||||||
|
|||||||
Reference in New Issue
Block a user