Skip to content

Commit

Permalink
Merge changes from topic "reland-64bit-omx" into main
Browse files Browse the repository at this point in the history
* changes:
  GraphicBufferSource: add configure() with 32bit consumerUsage flag
  RELAND "OMX: Add high bit of usage flag during conversion"
  RELAND "GraphicBufferSource: Use 64bit consumer usage"
  • Loading branch information
Sungtak Lee authored and Gerrit Code Review committed Aug 23, 2023
2 parents 00f1963 + 635cfc6 commit f67a94c
Show file tree
Hide file tree
Showing 11 changed files with 130 additions and 23 deletions.
7 changes: 3 additions & 4 deletions media/codec2/hal/client/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1850,8 +1850,8 @@ c2_status_t Codec2Client::Component::setOutputSurface(
uint64_t consumerUsage = kDefaultConsumerUsage;
{
if (surface) {
int usage = 0;
status_t err = surface->query(NATIVE_WINDOW_CONSUMER_USAGE_BITS, &usage);
uint64_t usage = 0;
status_t err = surface->getConsumerUsage(&usage);
if (err != NO_ERROR) {
ALOGD("setOutputSurface -- failed to get consumer usage bits (%d/%s). ignoring",
err, asString(err));
Expand All @@ -1864,8 +1864,7 @@ c2_status_t Codec2Client::Component::setOutputSurface(
// they do not exist inside of C2 scope. Any buffer usage shall be communicated
// through the sideband channel.

// do an unsigned conversion as bit-31 may be 1
consumerUsage = (uint32_t)usage | kDefaultConsumerUsage;
consumerUsage = usage | kDefaultConsumerUsage;
}
}

Expand Down
2 changes: 1 addition & 1 deletion media/codec2/hal/hidl/1.0/utils/InputSurfaceConnection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ struct InputSurfaceConnection::Impl : public ComponentWrapper {
// C2AndroidMemoryUsage(C2MemoryUsage(usage.value)).
// asGrallocUsage();

uint32_t grallocUsage =
uint64_t grallocUsage =
mSinkName.compare(0, 11, "c2.android.") == 0 ?
GRALLOC_USAGE_SW_READ_OFTEN :
GRALLOC_USAGE_HW_VIDEO_ENCODER;
Expand Down
13 changes: 13 additions & 0 deletions media/codec2/sfplugin/C2OMXNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,12 @@ status_t C2OMXNode::getParameter(OMX_INDEXTYPE index, void *params, size_t size)
err = OK;
break;
}
case OMX_IndexParamConsumerUsageBits64: {
OMX_U64 *usage = (OMX_U64 *)params;
*usage = mUsage;
err = OK;
break;
}
case OMX_IndexParamPortDefinition: {
if (size < sizeof(OMX_PARAM_PORTDEFINITIONTYPE)) {
return BAD_VALUE;
Expand Down Expand Up @@ -293,6 +299,13 @@ status_t C2OMXNode::setParameter(OMX_INDEXTYPE index, const void *params, size_t
}
mUsage = *((OMX_U32 *)params);
return OK;

case OMX_IndexParamConsumerUsageBits64:
if (size != sizeof(OMX_U64)) {
return BAD_VALUE;
}
mUsage = *((OMX_U64 *)params);
return OK;
}
return ERROR_UNSUPPORTED;
}
Expand Down
17 changes: 12 additions & 5 deletions media/codec2/sfplugin/CCodec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -206,12 +206,19 @@ class GraphicBufferSourceWrapper : public InputSurfaceWrapper {
mNode = new C2OMXNode(comp);
mOmxNode = new hardware::media::omx::V1_0::utils::TWOmxNode(mNode);
mNode->setFrameSize(mWidth, mHeight);

// Usage is queried during configure(), so setting it beforehand.
OMX_U32 usage = mConfig.mUsage & 0xFFFFFFFF;
(void)mNode->setParameter(
(OMX_INDEXTYPE)OMX_IndexParamConsumerUsageBits,
&usage, sizeof(usage));
// 64 bit set parameter is existing only in C2OMXNode.
OMX_U64 usage64 = mConfig.mUsage;
status_t res = mNode->setParameter(
(OMX_INDEXTYPE)OMX_IndexParamConsumerUsageBits64,
&usage64, sizeof(usage64));

if (res != OK) {
OMX_U32 usage = mConfig.mUsage & 0xFFFFFFFF;
(void)mNode->setParameter(
(OMX_INDEXTYPE)OMX_IndexParamConsumerUsageBits,
&usage, sizeof(usage));
}

return GetStatus(mSource->configure(
mOmxNode, static_cast<hardware::graphics::common::V1_0::Dataspace>(mDataSpace)));
Expand Down
27 changes: 21 additions & 6 deletions media/libmedia/include/media/omx/1.0/Conversion.h
Original file line number Diff line number Diff line change
Expand Up @@ -606,8 +606,16 @@ inline void wrapAs(AnwBuffer* t, GraphicBuffer const& l) {
t->attr.height = l.getHeight();
t->attr.stride = l.getStride();
t->attr.format = static_cast<PixelFormat>(l.getPixelFormat());
t->attr.layerCount = l.getLayerCount();
t->attr.usage = l.getUsage();
// HACK
// anwBuffer.layerCount 8 bytes : GraphicBuffer::layerCount 4 bytes
// anwBuffer.usage 4 bytes : GraphicBuffer::usage 8 bytes
// We would like to retain high part of usage with high part of layerCount
uint64_t usage = l.getUsage();
uint32_t usageHigh = (usage >> 32);
uint32_t usageLow = (0xFFFFFFFF & usage);
uint32_t layerLow = l.getLayerCount();
t->attr.layerCount = ((uint64_t(usageHigh) << 32) | layerLow);
t->attr.usage = usageLow;
t->attr.id = l.getId();
t->attr.generationNumber = l.getGenerationNumber();
t->nativeHandle = hidl_handle(l.handle);
Expand Down Expand Up @@ -637,30 +645,37 @@ inline bool convertTo(GraphicBuffer* l, AnwBuffer const& t) {
}
}

size_t const numInts = 12 + (handle ? handle->numInts : 0);
size_t const numInts = 13 + (handle ? handle->numInts : 0);
int32_t* ints = new int32_t[numInts];

size_t numFds = static_cast<size_t>(handle ? handle->numFds : 0);
int* fds = new int[numFds];

ints[0] = 'GBFR';
ints[0] = 'GB01';
ints[1] = static_cast<int32_t>(t.attr.width);
ints[2] = static_cast<int32_t>(t.attr.height);
ints[3] = static_cast<int32_t>(t.attr.stride);
ints[4] = static_cast<int32_t>(t.attr.format);
ints[5] = static_cast<int32_t>(t.attr.layerCount);
// HACK
// anwBuffer.layerCount 8 bytes : GraphicBuffer::layerCount 4 bytes
// anwBuffer.usage 4 bytes : GraphicBuffer::usage 8 bytes
// We would like to retain high part of usage with high part of layerCount
uint32_t layer = (0xFFFFFFFF & t.attr.layerCount);
uint32_t usageHigh = (t.attr.layerCount >> 32);
ints[5] = layer;
ints[6] = static_cast<int32_t>(t.attr.usage);
ints[7] = static_cast<int32_t>(t.attr.id >> 32);
ints[8] = static_cast<int32_t>(t.attr.id & 0xFFFFFFFF);
ints[9] = static_cast<int32_t>(t.attr.generationNumber);
ints[10] = 0;
ints[11] = 0;
ints[12] = usageHigh;
if (handle) {
ints[10] = static_cast<int32_t>(handle->numFds);
ints[11] = static_cast<int32_t>(handle->numInts);
int* intsStart = handle->data + handle->numFds;
std::copy(handle->data, intsStart, fds);
std::copy(intsStart, intsStart + handle->numInts, &ints[12]);
std::copy(intsStart, intsStart + handle->numInts, &ints[13]);
}

void const* constBuffer = static_cast<void const*>(ints);
Expand Down
23 changes: 20 additions & 3 deletions media/libstagefright/omx/1.0/WGraphicBufferSource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ Return<Status> TWGraphicBufferSource::configure(

// use consumer usage bits queried from encoder, but always add
// HW_VIDEO_ENCODER for backward compatibility.
uint32_t consumerUsage;
uint64_t consumerUsage;
void *_params = &consumerUsage;
uint8_t *params = static_cast<uint8_t*>(_params);
fnStatus = UNKNOWN_ERROR;
Expand All @@ -155,15 +155,32 @@ Return<Status> TWGraphicBufferSource::configure(
outParams.data() + outParams.size(),
params);
});

// try 64 bit consumer usage first
auto transStatus = omxNode->getParameter(
static_cast<uint32_t>(OMX_IndexParamConsumerUsageBits),
static_cast<uint32_t>(OMX_IndexParamConsumerUsageBits64),
inHidlBytes(&consumerUsage, sizeof(consumerUsage)),
_hidl_cb);
if (!transStatus.isOk()) {
return toStatus(FAILED_TRANSACTION);
}
if (fnStatus != OK) {
consumerUsage = 0;
// try 32 bit consumer usage upon failure
uint32_t usage;
_params = &usage;
params = static_cast<uint8_t*>(_params);
transStatus = omxNode->getParameter(
static_cast<uint32_t>(OMX_IndexParamConsumerUsageBits),
inHidlBytes(&usage, sizeof(usage)),
_hidl_cb);
if (!transStatus.isOk()) {
return toStatus(FAILED_TRANSACTION);
}
if (fnStatus != OK) {
consumerUsage = 0;
} else {
consumerUsage = usage;
}
}

OMX_PARAM_PORTDEFINITIONTYPE def;
Expand Down
12 changes: 12 additions & 0 deletions media/libstagefright/omx/OmxGraphicBufferSource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,18 @@ status_t OmxGraphicBufferSource::configure(
uint32_t frameWidth,
uint32_t frameHeight,
uint32_t consumerUsage) {
uint64_t consumerUsage64 = static_cast<uint64_t>(consumerUsage);
return configure(omxNode, dataSpace, bufferCount,
frameWidth, frameHeight, consumerUsage64);
}

status_t OmxGraphicBufferSource::configure(
const sp<IOmxNodeWrapper>& omxNode,
int32_t dataSpace,
int32_t bufferCount,
uint32_t frameWidth,
uint32_t frameHeight,
uint64_t consumerUsage) {
if (omxNode == NULL) {
return BAD_VALUE;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -425,8 +425,16 @@ inline CodecBuffer *wrapAs(CodecBuffer *t, sp<GraphicBuffer> const& graphicBuffe
t->attr.anwBuffer.stride = graphicBuffer->getStride();
t->attr.anwBuffer.format = static_cast<PixelFormat>(
graphicBuffer->getPixelFormat());
t->attr.anwBuffer.layerCount = graphicBuffer->getLayerCount();
t->attr.anwBuffer.usage = graphicBuffer->getUsage();
// HACK
// anwBuffer.layerCount 8 bytes : GraphicBuffer::layerCount 4 bytes
// anwBuffer.usage 4 bytes : GraphicBuffer::usage 8 bytes
// We would like to retain high part of usage with high part of layerCount
uint64_t usage = graphicBuffer->getUsage();
uint32_t usageHigh = (usage >> 32);
uint32_t usageLow = (0xFFFFFFFF & usage);
uint32_t layerLow = graphicBuffer->getLayerCount();
t->attr.anwBuffer.layerCount = ((uint64_t(usageHigh) << 32) | layerLow);
t->attr.anwBuffer.usage = usageLow;
t->nativeHandle = graphicBuffer->handle;
return t;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,9 @@ class OmxGraphicBufferSource : public GraphicBufferSource {
// ------------------------------

// Configure the buffer source to be used with an OMX node with the default
// data space.
// data space.(32-bit consumerUsage flag, for vendor partition
// compatibility)
[[deprecated("use configure() with a 64-bit consumerUsage flag instead")]]
status_t configure(
const sp<IOmxNodeWrapper> &omxNode,
int32_t dataSpace,
Expand All @@ -72,6 +74,16 @@ class OmxGraphicBufferSource : public GraphicBufferSource {
uint32_t frameHeight,
uint32_t consumerUsage);

// Configure the buffer source to be used with an OMX node with the default
// data space. (64-bit consumerUsage flag)
status_t configure(
const sp<IOmxNodeWrapper> &omxNode,
int32_t dataSpace,
int32_t bufferCount,
uint32_t frameWidth,
uint32_t frameHeight,
uint64_t consumerUsage);

// Rest of the interface in GraphicBufferSource.

private:
Expand Down
12 changes: 12 additions & 0 deletions media/module/bqhelper/GraphicBufferSource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1151,6 +1151,18 @@ status_t GraphicBufferSource::configure(
uint32_t frameWidth,
uint32_t frameHeight,
uint32_t consumerUsage) {
uint64_t consumerUsage64 = static_cast<uint64_t>(consumerUsage);
return configure(component, dataSpace, bufferCount,
frameWidth, frameHeight, consumerUsage64);
}

status_t GraphicBufferSource::configure(
const sp<ComponentWrapper>& component,
int32_t dataSpace,
int32_t bufferCount,
uint32_t frameWidth,
uint32_t frameHeight,
uint64_t consumerUsage) {
if (component == NULL) {
return BAD_VALUE;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,9 @@ class GraphicBufferSource : public RefBase {
// ------------------------------

// Configure the buffer source to be used with a component with the default
// data space.
// data space. (32-bit consumerUsage flag, for vendor partition
// compatibility)
[[deprecated("use configure() with a 64-bit consumerUsage flag instead")]]
status_t configure(
const sp<ComponentWrapper> &component,
int32_t dataSpace,
Expand All @@ -131,6 +133,16 @@ class GraphicBufferSource : public RefBase {
uint32_t frameHeight,
uint32_t consumerUsage);

// Configure the buffer source to be used with a component with the default
// data space. (64-bit consumerUsage flag)
status_t configure(
const sp<ComponentWrapper> &component,
int32_t dataSpace,
int32_t bufferCount,
uint32_t frameWidth,
uint32_t frameHeight,
uint64_t consumerUsage);

// This is called after the last input frame has been submitted or buffer
// timestamp is greater or equal than stopTimeUs. We need to submit an empty
// buffer with the EOS flag set. If we don't have a codec buffer ready,
Expand Down

0 comments on commit f67a94c

Please sign in to comment.