Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CameraClient: MTK Support & libstagefright: mtk: Use vendor extensions #1

Open
wants to merge 25 commits into
base: 8.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
47ff086
merge in oc-r6-release history after reset to oc-release
Aug 17, 2017
d320496
merge in oc-r6-release history after reset to oc-release
Aug 17, 2017
51344d2
release-request-2c066723-15d1-45c9-8fff-fdeca41661a9-for-git_oc-r6-re…
Aug 25, 2017
44c414f
release-request-2c066723-15d1-45c9-8fff-fdeca41661a9-for-git_oc-r6-re…
Aug 25, 2017
bc44aff
audiopolicy: make audio policy extensible
Jul 24, 2015
375747a
camera: Allow devices to load custom CameraParameter code
intervigilium Oct 28, 2015
0e41363
stagefright: Fix SurfaceMediaSource buffer search condition when buff…
billchen1977 Apr 1, 2017
3049374
stagefright: omx: Don't signal dataspace change on legacy QCOM
arco Oct 9, 2016
df54f6a
libstagefright: Add support for NV21 color format
cryptomilk Aug 17, 2015
3253801
Revert "libstagefright: Add support for NV21 color format"
Martinusbe Sep 12, 2017
2f44742
libcameraservice: Don't pass NULL args on setCallbacks call
irii Sep 11, 2016
8ac0db3
camera/media: Support for legacy camera HALv1
fourkbomb Oct 6, 2016
6147530
libstagefright: Support for legacy camera/encoder buffers
raymanfx Oct 18, 2016
e927fff
OMXNodeInstance: Fix legacy HAL1 after merge of android-7.1.0_r7
luk1337 Nov 11, 2016
26ec628
soundtrigger: fill in default extras from dsp
romanbb May 3, 2016
9bd20df
soundtrigger: fix memory corruption
sam3000 Dec 9, 2016
78056e7
frameworks/av : Add diag permissions
Apr 14, 2016
07d5acb
Use AID OEM DIAG instead of qcom_diag
Jul 21, 2017
5490e5f
Camera: CameraHardwareInterface changes to support Extended FD
May 11, 2017
bf9a71e
Revert "update stune group for cameraserver to top-app"
Feb 9, 2017
14a1ef0
Merge tag 'android-8.0.0_r11' into HEAD
Martinusbe Sep 14, 2017
8ffb906
Revert "Camera: CameraHardwareInterface changes to support Extended FD"
Martinusbe Sep 14, 2017
70386b6
camera: include: Don't override possible overlayed header
bgcngm Sep 23, 2017
ed12b77
CameraClient: MTK Support
rmcc Aug 14, 2017
787dff4
libstagefright: mtk: Use vendor extensions to check if we should fixu…
defer Aug 14, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion camera/Android.mk
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ LOCAL_SRC_FILES := \
LOCAL_SRC_FILES += \
Camera.cpp \
CameraMetadata.cpp \
CameraParameters.cpp \
CaptureResult.cpp \
CameraParameters2.cpp \
ICamera.cpp \
Expand Down Expand Up @@ -73,6 +72,21 @@ LOCAL_EXPORT_C_INCLUDE_DIRS := \

LOCAL_CFLAGS += -Werror -Wall -Wextra

ifneq ($(TARGET_SPECIFIC_CAMERA_PARAMETER_LIBRARY),)
LOCAL_WHOLE_STATIC_LIBRARIES += $(TARGET_SPECIFIC_CAMERA_PARAMETER_LIBRARY)
else
LOCAL_WHOLE_STATIC_LIBRARIES += libcamera_parameters
endif

LOCAL_MODULE:= libcamera_client

include $(BUILD_SHARED_LIBRARY)

include $(CLEAR_VARS)

LOCAL_SRC_FILES := \
CameraParameters.cpp

LOCAL_MODULE := libcamera_parameters

include $(BUILD_STATIC_LIBRARY)
4 changes: 4 additions & 0 deletions camera/cameraserver/Android.mk
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@

LOCAL_PATH:= $(call my-dir)

ifeq ($(TARGET_HAS_LEGACY_CAMERA_HAL1),true)
$(warning Target has integrated cameraserver into mediaserver. This is weakening security measures introduced in 7.0)
else
include $(CLEAR_VARS)

LOCAL_SRC_FILES:= \
Expand Down Expand Up @@ -41,3 +44,4 @@ LOCAL_CFLAGS += -Wall -Wextra -Werror -Wno-unused-parameter
LOCAL_INIT_RC := cameraserver.rc

include $(BUILD_EXECUTABLE)
endif
2 changes: 1 addition & 1 deletion camera/cameraserver/cameraserver.rc
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ service cameraserver /system/bin/cameraserver
user cameraserver
group audio camera input drmrpc
ioprio rt 4
writepid /dev/cpuset/camera-daemon/tasks /dev/stune/top-app/tasks
writepid /dev/cpuset/camera-daemon/tasks /dev/stune/foreground/tasks
2 changes: 1 addition & 1 deletion camera/include/camera/CameraParameters2.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

#include <utils/Vector.h>
#include <utils/String8.h>
#include "CameraParameters.h"
#include <camera/CameraParameters.h>

namespace android {

Expand Down
2 changes: 1 addition & 1 deletion media/audioserver/audioserver.rc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ service audioserver /system/bin/audioserver
class main
user audioserver
# media gid needed for /dev/fm (radio) and for /data/misc/media (tee)
group audio camera drmrpc inet media mediadrm net_bt net_bt_admin net_bw_acct
group audio camera drmrpc inet media mediadrm net_bt net_bt_admin net_bw_acct oem_2901
ioprio rt 4
writepid /dev/cpuset/foreground/tasks /dev/stune/foreground/tasks
onrestart restart audio-hal-2-0
Expand Down
42 changes: 34 additions & 8 deletions media/libmediaplayerservice/MediaPlayerService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@
#include "HTTPBase.h"
#include "RemoteDisplay.h"

static const int kDumpLockRetries = 50;
static const int kDumpLockSleepUs = 20000;

namespace {
using android::media::Metadata;
using android::status_t;
Expand Down Expand Up @@ -392,12 +395,32 @@ status_t MediaPlayerService::Client::dump(int fd, const Vector<String16>& args)
snprintf(buffer, 255, " pid(%d), connId(%d), status(%d), looping(%s)\n",
mPid, mConnId, mStatus, mLoop?"true": "false");
result.append(buffer);

sp<MediaPlayerBase> p;
sp<AudioOutput> audioOutput;
bool locked = false;
for (int i = 0; i < kDumpLockRetries; ++i) {
if (mLock.tryLock() == NO_ERROR) {
locked = true;
break;
}
usleep(kDumpLockSleepUs);
}

if (locked) {
p = mPlayer;
audioOutput = mAudioOutput;
mLock.unlock();
} else {
result.append(" lock is taken, no dump from player and audio output\n");
}
write(fd, result.string(), result.size());
if (mPlayer != NULL) {
mPlayer->dump(fd, args);

if (p != NULL) {
p->dump(fd, args);
}
if (mAudioOutput != 0) {
mAudioOutput->dump(fd, args);
if (audioOutput != 0) {
audioOutput->dump(fd, args);
}
write(fd, "\n", 1);
return NO_ERROR;
Expand Down Expand Up @@ -577,7 +600,10 @@ MediaPlayerService::Client::Client(
MediaPlayerService::Client::~Client()
{
ALOGV("Client(%d) destructor pid = %d", mConnId, mPid);
mAudioOutput.clear();
{
Mutex::Autolock l(mLock);
mAudioOutput.clear();
}
wp<Client> client(this);
disconnect();
mService->removeClient(client);
Expand All @@ -597,10 +623,9 @@ void MediaPlayerService::Client::disconnect()
Mutex::Autolock l(mLock);
p = mPlayer;
mClient.clear();
mPlayer.clear();
}

mPlayer.clear();

// clear the notification to prevent callbacks to dead client
// and reset the player. We assume the player will serialize
// access to itself if necessary.
Expand All @@ -621,7 +646,7 @@ void MediaPlayerService::Client::disconnect()
sp<MediaPlayerBase> MediaPlayerService::Client::createPlayer(player_type playerType)
{
// determine if we have the right player type
sp<MediaPlayerBase> p = mPlayer;
sp<MediaPlayerBase> p = getPlayer();
if ((p != NULL) && (p->playerType() != playerType)) {
ALOGV("delete player");
p.clear();
Expand Down Expand Up @@ -772,6 +797,7 @@ void MediaPlayerService::Client::setDataSource_post(
}

if (mStatus == OK) {
Mutex::Autolock l(mLock);
mPlayer = p;
}
}
Expand Down
11 changes: 10 additions & 1 deletion media/libstagefright/ACodec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4833,7 +4833,16 @@ status_t ACodec::getPortFormat(OMX_U32 portIndex, sp<AMessage> &notify) {
rect.nWidth = videoDef->nFrameWidth;
rect.nHeight = videoDef->nFrameHeight;
}

#ifdef MTK_HARDWARE
if (!strncmp(mComponentName.c_str(), "OMX.MTK.", 8) && mOMX->getConfig(
mNode, (OMX_INDEXTYPE) 0x7f00001c /* OMX_IndexVendorMtkOmxVdecGetCropInfo */,
&rect, sizeof(rect)) != OK) {
rect.nLeft = 0;
rect.nTop = 0;
rect.nWidth = videoDef->nFrameWidth;
rect.nHeight = videoDef->nFrameHeight;
}
#endif
if (rect.nLeft < 0 ||
rect.nTop < 0 ||
rect.nLeft + rect.nWidth > videoDef->nFrameWidth ||
Expand Down
4 changes: 4 additions & 0 deletions media/libstagefright/Android.mk
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,10 @@ LOCAL_SHARED_LIBRARIES += \

LOCAL_EXPORT_SHARED_LIBRARY_HEADERS := libmedia

ifeq ($(TARGET_HAS_LEGACY_CAMERA_HAL1),true)
LOCAL_CFLAGS += -DCAMCORDER_GRALLOC_SOURCE
endif

LOCAL_CFLAGS += -Wno-multichar -Werror -Wno-error=deprecated-declarations -Wall

# enable experiments only in userdebug and eng builds
Expand Down
12 changes: 12 additions & 0 deletions media/libstagefright/CameraSource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -970,6 +970,14 @@ void CameraSource::releaseRecordingFrame(const sp<IMemory>& frame) {
}

if (handle != nullptr) {
ssize_t offset;
size_t size;
sp<IMemoryHeap> heap = frame->getMemory(&offset, &size);
if (heap->getHeapID() != mMemoryHeapBase->getHeapID()) {
ALOGE("%s: Mismatched heap ID, ignoring release (got %x, expected %x)",
__FUNCTION__, heap->getHeapID(), mMemoryHeapBase->getHeapID());
return;
}
uint32_t batchSize = 0;
{
Mutex::Autolock autoLock(mBatchLock);
Expand Down Expand Up @@ -1367,6 +1375,10 @@ void CameraSource::processBufferQueueFrame(BufferItem& buffer) {
MetadataBufferType CameraSource::metaDataStoredInVideoBuffers() const {
ALOGV("metaDataStoredInVideoBuffers");

#ifdef CAMCORDER_GRALLOC_SOURCE
return kMetadataBufferTypeGrallocSource;
#endif

// Output buffers will contain metadata if camera sends us buffer in metadata mode or via
// buffer queue.
switch (mVideoBufferMode) {
Expand Down
41 changes: 39 additions & 2 deletions media/libstagefright/SurfaceMediaSource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,11 @@ status_t SurfaceMediaSource::setFrameRate(int32_t fps)

MetadataBufferType SurfaceMediaSource::metaDataStoredInVideoBuffers() const {
ALOGV("isMetaDataStoredInVideoBuffers");
#ifdef CAMCORDER_GRALLOC_SOURCE
return kMetadataBufferTypeGrallocSource;
#else
return kMetadataBufferTypeANWBuffer;
#endif
}

int32_t SurfaceMediaSource::getFrameRate( ) const {
Expand Down Expand Up @@ -249,6 +253,35 @@ sp<MetaData> SurfaceMediaSource::getFormat()
return meta;
}

#ifdef CAMCORDER_GRALLOC_SOURCE
// Pass the data to the MediaBuffer. Pass in only the metadata
// The metadata passed consists of two parts:
// 1. First, there is an integer indicating that it is a GRAlloc
// source (kMetadataBufferTypeGrallocSource)
// 2. This is followed by the buffer_handle_t that is a handle to the
// GRalloc buffer. The encoder needs to interpret this GRalloc handle
// and encode the frames.
// --------------------------------------------------------------
// | kMetadataBufferTypeGrallocSource | sizeof(buffer_handle_t) |
// --------------------------------------------------------------
// Note: Call only when you have the lock
static void passMetadataBuffer(MediaBuffer **buffer,
buffer_handle_t bufferHandle) {
*buffer = new MediaBuffer(4 + sizeof(buffer_handle_t));
char *data = (char *)(*buffer)->data();
if (data == NULL) {
ALOGE("Cannot allocate memory for metadata buffer!");
return;
}
OMX_U32 type = kMetadataBufferTypeGrallocSource;
memcpy(data, &type, 4);
memcpy(data + 4, &bufferHandle, sizeof(buffer_handle_t));

ALOGV("handle = %p, , offset = %zu, length = %zu",
bufferHandle, (*buffer)->range_length(), (*buffer)->range_offset());
}
#endif

// Pass the data to the MediaBuffer. Pass in only the metadata
// Note: Call only when you have the lock
void SurfaceMediaSource::passMetadataBuffer_l(MediaBuffer **buffer,
Expand Down Expand Up @@ -351,7 +384,11 @@ status_t SurfaceMediaSource::read(
mNumFramesEncoded++;
// Pass the data to the MediaBuffer. Pass in only the metadata

#ifdef CAMCORDER_GRALLOC_SOURCE
passMetadataBuffer(buffer, mSlots[mCurrentSlot].mGraphicBuffer->handle);
#else
passMetadataBuffer_l(buffer, mSlots[mCurrentSlot].mGraphicBuffer->getNativeBuffer());
#endif

(*buffer)->setObserver(this);
(*buffer)->add_ref();
Expand Down Expand Up @@ -389,7 +426,7 @@ void SurfaceMediaSource::signalBufferReturned(MediaBuffer *buffer) {
buffer_handle_t bufferHandle = getMediaBufferHandle(buffer);

for (size_t i = 0; i < mCurrentBuffers.size(); i++) {
if (mCurrentBuffers[i]->handle == bufferHandle) {
if ((buffer_handle_t)mCurrentBuffers[i]->getNativeBuffer() == bufferHandle) {
mCurrentBuffers.removeAt(i);
foundBuffer = true;
break;
Expand All @@ -405,7 +442,7 @@ void SurfaceMediaSource::signalBufferReturned(MediaBuffer *buffer) {
continue;
}

if (bufferHandle == mSlots[id].mGraphicBuffer->handle) {
if (bufferHandle == (buffer_handle_t)mSlots[id].mGraphicBuffer->getNativeBuffer()) {
ALOGV("Slot %d returned, matches handle = %p", id,
mSlots[id].mGraphicBuffer->handle);

Expand Down
13 changes: 9 additions & 4 deletions media/libstagefright/codecs/mpeg2dec/SoftMPEG2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,10 @@ SoftMPEG2::~SoftMPEG2() {
}


static size_t getMinTimestampIdx(OMX_S64 *pNTimeStamp, bool *pIsTimeStampValid) {
static ssize_t getMinTimestampIdx(OMX_S64 *pNTimeStamp, bool *pIsTimeStampValid) {
OMX_S64 minTimeStamp = LLONG_MAX;
int idx = -1;
for (size_t i = 0; i < MAX_TIME_STAMPS; i++) {
ssize_t idx = -1;
for (ssize_t i = 0; i < MAX_TIME_STAMPS; i++) {
if (pIsTimeStampValid[i]) {
if (pNTimeStamp[i] < minTimeStamp) {
minTimeStamp = pNTimeStamp[i];
Expand Down Expand Up @@ -788,10 +788,15 @@ void SoftMPEG2::onQueueFilled(OMX_U32 portIndex) {
}

if (s_dec_op.u4_output_present) {
size_t timeStampIdx;
ssize_t timeStampIdx;
outHeader->nFilledLen = (mWidth * mHeight * 3) / 2;

timeStampIdx = getMinTimestampIdx(mTimeStamps, mTimeStampsValid);
if (timeStampIdx < 0) {
ALOGE("b/62872863, Invalid timestamp index!");
android_errorWriteLog(0x534e4554, "62872863");
return;
}
outHeader->nTimeStamp = mTimeStamps[timeStampIdx];
mTimeStampsValid[timeStampIdx] = false;

Expand Down
5 changes: 5 additions & 0 deletions media/libstagefright/mpeg2ts/ESQueue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -892,6 +892,11 @@ sp<ABuffer> ElementaryStreamQueue::dequeueAccessUnitAAC() {
bits.skipBits(2);

unsigned aac_frame_length = bits.getBits(13);
if (aac_frame_length == 0){
ALOGE("b/62673179, Invalid AAC frame length!");
android_errorWriteLog(0x534e4554, "62673179");
return NULL;
}

bits.skipBits(11); // adts_buffer_fullness

Expand Down
10 changes: 10 additions & 0 deletions media/libstagefright/omx/Android.mk
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,16 @@ LOCAL_EXPORT_C_INCLUDES := \
LOCAL_EXPORT_SHARED_LIBRARY_HEADERS := \
[email protected]

ifneq ($(filter msm7x27a msm7x30 msm8660 msm8960,$(TARGET_BOARD_PLATFORM)),)
LOCAL_CFLAGS += -DQCOM_BSP_LEGACY
endif

ifneq ($(TARGET_USES_MEDIA_EXTENSIONS),true)
ifeq ($(TARGET_HAS_LEGACY_CAMERA_HAL1),true)
LOCAL_CFLAGS += -DCAMCORDER_GRALLOC_SOURCE
endif
endif

LOCAL_MODULE:= libstagefright_omx
LOCAL_CFLAGS += -Werror -Wall -Wno-unused-parameter -Wno-documentation
LOCAL_SANITIZE := unsigned-integer-overflow signed-integer-overflow cfi
Expand Down
2 changes: 2 additions & 0 deletions media/libstagefright/omx/GraphicBufferSource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -774,11 +774,13 @@ status_t GraphicBufferSource::submitBuffer_l(const VideoBuffer &item) {
return UNKNOWN_ERROR;
}

#ifndef QCOM_BSP_LEGACY
if ((android_dataspace)item.mDataspace != mLastDataspace) {
onDataspaceChanged_l(
item.mDataspace,
(android_pixel_format)item.mBuffer->getGraphicBuffer()->format);
}
#endif

std::shared_ptr<AcquiredBuffer> buffer = item.mBuffer;
// use a GraphicBuffer for now as OMXNodeInstance is using GraphicBuffers to hold references
Expand Down
20 changes: 20 additions & 0 deletions media/libstagefright/omx/OMXNodeInstance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1632,10 +1632,30 @@ status_t OMXNodeInstance::emptyBuffer_l(
BufferMeta *buffer_meta =
static_cast<BufferMeta *>(header->pAppPrivate);

#ifndef CAMCORDER_GRALLOC_SOURCE
// set up proper filled length if component is configured for gralloc metadata mode
// ignore rangeOffset in this case (as client may be assuming ANW meta buffers).
if (mMetadataType[kPortIndexInput] == kMetadataBufferTypeGrallocSource) {
header->nFilledLen = rangeLength ? sizeof(VideoGrallocMetadata) : 0;
#else
sp<ABuffer> backup = buffer_meta->getBuffer(header, false /* limit */);
sp<ABuffer> codec = buffer_meta->getBuffer(header, false /* limit */);

// convert incoming ANW meta buffers if component is configured for gralloc metadata mode
// ignore rangeOffset in this case
if (mMetadataType[kPortIndexInput] == kMetadataBufferTypeGrallocSource
&& backup->capacity() >= sizeof(VideoNativeMetadata)
&& codec->capacity() >= sizeof(VideoGrallocMetadata)
&& ((VideoNativeMetadata *)backup->base())->eType
== kMetadataBufferTypeANWBuffer) {
VideoNativeMetadata &backupMeta = *(VideoNativeMetadata *)backup->base();
VideoGrallocMetadata &codecMeta = *(VideoGrallocMetadata *)codec->base();
CLOG_BUFFER(emptyBuffer, "converting ANWB %p to handle %p",
backupMeta.pBuffer, backupMeta.pBuffer->handle);
codecMeta.pHandle = backupMeta.pBuffer != NULL ? backupMeta.pBuffer->handle : NULL;
codecMeta.eType = kMetadataBufferTypeGrallocSource;
header->nFilledLen = rangeLength ? sizeof(codecMeta) : 0;
#endif
header->nOffset = 0;
} else {
// rangeLength and rangeOffset must be a subset of the allocated data in the buffer.
Expand Down
Loading