commit
08c3c988ee
@ -0,0 +1,185 @@
|
||||
/*
|
||||
* Copyright 2019 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifdef __LP64__
|
||||
#define OMX_ANDROID_COMPILE_AS_32BIT_ON_64BIT_PLATFORMS
|
||||
#endif
|
||||
|
||||
//#define LOG_NDEBUG 0
|
||||
#define LOG_TAG "Omx2IGraphicBufferSource"
|
||||
#include <android-base/logging.h>
|
||||
|
||||
#include "Omx2IGraphicBufferSource.h"
|
||||
|
||||
#include <android/BnOMXBufferSource.h>
|
||||
#include <media/OMXBuffer.h>
|
||||
#include <media/stagefright/omx/OMXUtils.h>
|
||||
|
||||
#include <OMX_Component.h>
|
||||
#include <OMX_Index.h>
|
||||
#include <OMX_IndexExt.h>
|
||||
|
||||
namespace android {
|
||||
|
||||
namespace /* unnamed */ {
|
||||
|
||||
// OmxGraphicBufferSource -> IOMXBufferSource
|
||||
|
||||
struct OmxGbs2IOmxBs : public BnOMXBufferSource {
|
||||
sp<OmxGraphicBufferSource> mBase;
|
||||
OmxGbs2IOmxBs(sp<OmxGraphicBufferSource> const& base) : mBase{base} {}
|
||||
BnStatus onOmxExecuting() override {
|
||||
return mBase->onOmxExecuting();
|
||||
}
|
||||
BnStatus onOmxIdle() override {
|
||||
return mBase->onOmxIdle();
|
||||
}
|
||||
BnStatus onOmxLoaded() override {
|
||||
return mBase->onOmxLoaded();
|
||||
}
|
||||
BnStatus onInputBufferAdded(int32_t bufferId) override {
|
||||
return mBase->onInputBufferAdded(bufferId);
|
||||
}
|
||||
BnStatus onInputBufferEmptied(
|
||||
int32_t bufferId,
|
||||
OMXFenceParcelable const& fenceParcel) override {
|
||||
return mBase->onInputBufferEmptied(bufferId, fenceParcel.get());
|
||||
}
|
||||
};
|
||||
|
||||
struct OmxNodeWrapper : public IOmxNodeWrapper {
|
||||
sp<IOMXNode> mBase;
|
||||
OmxNodeWrapper(sp<IOMXNode> const& base) : mBase{base} {}
|
||||
status_t emptyBuffer(
|
||||
int32_t bufferId, uint32_t flags,
|
||||
const sp<GraphicBuffer> &buffer,
|
||||
int64_t timestamp, int fenceFd) override {
|
||||
return mBase->emptyBuffer(bufferId, buffer, flags, timestamp, fenceFd);
|
||||
}
|
||||
void dispatchDataSpaceChanged(
|
||||
int32_t dataSpace, int32_t aspects, int32_t pixelFormat) override {
|
||||
omx_message msg{};
|
||||
msg.type = omx_message::EVENT;
|
||||
msg.fenceFd = -1;
|
||||
msg.u.event_data.event = OMX_EventDataSpaceChanged;
|
||||
msg.u.event_data.data1 = dataSpace;
|
||||
msg.u.event_data.data2 = aspects;
|
||||
msg.u.event_data.data3 = pixelFormat;
|
||||
mBase->dispatchMessage(msg);
|
||||
}
|
||||
};
|
||||
|
||||
} // unnamed namespace
|
||||
|
||||
// Omx2IGraphicBufferSource
|
||||
Omx2IGraphicBufferSource::Omx2IGraphicBufferSource(
|
||||
sp<OmxGraphicBufferSource> const& base)
|
||||
: mBase{base},
|
||||
mOMXBufferSource{new OmxGbs2IOmxBs(base)} {
|
||||
}
|
||||
|
||||
BnStatus Omx2IGraphicBufferSource::setSuspend(
|
||||
bool suspend, int64_t timeUs) {
|
||||
return BnStatus::fromStatusT(mBase->setSuspend(suspend, timeUs));
|
||||
}
|
||||
|
||||
BnStatus Omx2IGraphicBufferSource::setRepeatPreviousFrameDelayUs(
|
||||
int64_t repeatAfterUs) {
|
||||
return BnStatus::fromStatusT(mBase->setRepeatPreviousFrameDelayUs(repeatAfterUs));
|
||||
}
|
||||
|
||||
BnStatus Omx2IGraphicBufferSource::setMaxFps(float maxFps) {
|
||||
return BnStatus::fromStatusT(mBase->setMaxFps(maxFps));
|
||||
}
|
||||
|
||||
BnStatus Omx2IGraphicBufferSource::setTimeLapseConfig(
|
||||
double fps, double captureFps) {
|
||||
return BnStatus::fromStatusT(mBase->setTimeLapseConfig(fps, captureFps));
|
||||
}
|
||||
|
||||
BnStatus Omx2IGraphicBufferSource::setStartTimeUs(
|
||||
int64_t startTimeUs) {
|
||||
return BnStatus::fromStatusT(mBase->setStartTimeUs(startTimeUs));
|
||||
}
|
||||
|
||||
BnStatus Omx2IGraphicBufferSource::setStopTimeUs(
|
||||
int64_t stopTimeUs) {
|
||||
return BnStatus::fromStatusT(mBase->setStopTimeUs(stopTimeUs));
|
||||
}
|
||||
|
||||
BnStatus Omx2IGraphicBufferSource::getStopTimeOffsetUs(
|
||||
int64_t *stopTimeOffsetUs) {
|
||||
return BnStatus::fromStatusT(mBase->getStopTimeOffsetUs(stopTimeOffsetUs));
|
||||
}
|
||||
|
||||
BnStatus Omx2IGraphicBufferSource::setColorAspects(
|
||||
int32_t aspects) {
|
||||
return BnStatus::fromStatusT(mBase->setColorAspects(aspects));
|
||||
}
|
||||
|
||||
BnStatus Omx2IGraphicBufferSource::setTimeOffsetUs(
|
||||
int64_t timeOffsetsUs) {
|
||||
return BnStatus::fromStatusT(mBase->setTimeOffsetUs(timeOffsetsUs));
|
||||
}
|
||||
|
||||
BnStatus Omx2IGraphicBufferSource::signalEndOfInputStream() {
|
||||
return BnStatus::fromStatusT(mBase->signalEndOfInputStream());
|
||||
}
|
||||
|
||||
BnStatus Omx2IGraphicBufferSource::configure(
|
||||
const sp<IOMXNode>& omxNode, int32_t dataSpace) {
|
||||
if (omxNode == NULL) {
|
||||
return BnStatus::fromServiceSpecificError(BAD_VALUE);
|
||||
}
|
||||
|
||||
// Do setInputSurface() first, the node will try to enable metadata
|
||||
// mode on input, and does necessary error checking. If this fails,
|
||||
// we can't use this input surface on the node.
|
||||
status_t err = omxNode->setInputSurface(mOMXBufferSource);
|
||||
if (err != NO_ERROR) {
|
||||
ALOGE("Unable to set input surface: %d", err);
|
||||
return BnStatus::fromServiceSpecificError(err);
|
||||
}
|
||||
|
||||
uint32_t consumerUsage;
|
||||
if (omxNode->getParameter(
|
||||
(OMX_INDEXTYPE)OMX_IndexParamConsumerUsageBits,
|
||||
&consumerUsage, sizeof(consumerUsage)) != OK) {
|
||||
consumerUsage = 0;
|
||||
}
|
||||
|
||||
OMX_PARAM_PORTDEFINITIONTYPE def;
|
||||
InitOMXParams(&def);
|
||||
def.nPortIndex = 0; // kPortIndexInput
|
||||
|
||||
err = omxNode->getParameter(
|
||||
OMX_IndexParamPortDefinition, &def, sizeof(def));
|
||||
if (err != NO_ERROR) {
|
||||
ALOGE("Failed to get port definition: %d", err);
|
||||
return BnStatus::fromServiceSpecificError(UNKNOWN_ERROR);
|
||||
}
|
||||
|
||||
return BnStatus::fromStatusT(mBase->configure(
|
||||
new OmxNodeWrapper(omxNode),
|
||||
dataSpace,
|
||||
def.nBufferCountActual,
|
||||
def.format.video.nFrameWidth,
|
||||
def.format.video.nFrameHeight,
|
||||
consumerUsage));
|
||||
}
|
||||
|
||||
} // namespace android
|
||||
|
@ -0,0 +1,47 @@
|
||||
/*
|
||||
* Copyright 2019 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef OMX_2_IGRAPHICBUFFERSOURCE_H_
|
||||
#define OMX_2_IGRAPHICBUFFERSOURCE_H_
|
||||
|
||||
#include <android/BnGraphicBufferSource.h>
|
||||
#include <media/stagefright/omx/OmxGraphicBufferSource.h>
|
||||
|
||||
namespace android {
|
||||
|
||||
using BnStatus = ::android::binder::Status;
|
||||
|
||||
struct Omx2IGraphicBufferSource : public BnGraphicBufferSource {
|
||||
sp<OmxGraphicBufferSource> mBase;
|
||||
sp<IOMXBufferSource> mOMXBufferSource;
|
||||
Omx2IGraphicBufferSource(sp<OmxGraphicBufferSource> const& base);
|
||||
BnStatus configure(const sp<IOMXNode>& omxNode, int32_t dataSpace) override;
|
||||
BnStatus setSuspend(bool suspend, int64_t timeUs) override;
|
||||
BnStatus setRepeatPreviousFrameDelayUs(int64_t repeatAfterUs) override;
|
||||
BnStatus setMaxFps(float maxFps) override;
|
||||
BnStatus setTimeLapseConfig(double fps, double captureFps) override;
|
||||
BnStatus setStartTimeUs(int64_t startTimeUs) override;
|
||||
BnStatus setStopTimeUs(int64_t stopTimeUs) override;
|
||||
BnStatus getStopTimeOffsetUs(int64_t *stopTimeOffsetUs) override;
|
||||
BnStatus setColorAspects(int32_t aspects) override;
|
||||
BnStatus setTimeOffsetUs(int64_t timeOffsetsUs) override;
|
||||
BnStatus signalEndOfInputStream() override;
|
||||
};
|
||||
|
||||
} // namespace android
|
||||
|
||||
#endif // OMX_2_IGRAPHICBUFFERSOURCE_H_
|
||||
|
@ -0,0 +1,38 @@
|
||||
/*
|
||||
* Copyright (C) 2016 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package android;
|
||||
|
||||
import android.IOMXNode;
|
||||
|
||||
/**
|
||||
* Binder interface for controlling a graphic buffer source.
|
||||
*
|
||||
* @hide
|
||||
*/
|
||||
interface IGraphicBufferSource {
|
||||
void configure(IOMXNode omxNode, int dataSpace);
|
||||
void setSuspend(boolean suspend, long suspendTimeUs);
|
||||
void setRepeatPreviousFrameDelayUs(long repeatAfterUs);
|
||||
void setMaxFps(float maxFps);
|
||||
void setTimeLapseConfig(double fps, double captureFps);
|
||||
void setStartTimeUs(long startTimeUs);
|
||||
void setStopTimeUs(long stopTimeUs);
|
||||
long getStopTimeOffsetUs();
|
||||
void setColorAspects(int aspects);
|
||||
void setTimeOffsetUs(long timeOffsetsUs);
|
||||
void signalEndOfInputStream();
|
||||
}
|
@ -0,0 +1,90 @@
|
||||
/*
|
||||
* Copyright 2016, The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef ANDROID_HARDWARE_MEDIA_OMX_V1_0_WGRAPHICBUFFERSOURCE_H
|
||||
#define ANDROID_HARDWARE_MEDIA_OMX_V1_0_WGRAPHICBUFFERSOURCE_H
|
||||
|
||||
#include <hidl/MQDescriptor.h>
|
||||
#include <hidl/Status.h>
|
||||
|
||||
#include <binder/Binder.h>
|
||||
#include <media/IOMX.h>
|
||||
|
||||
#include <android/hardware/graphics/common/1.0/types.h>
|
||||
#include <android/hardware/media/omx/1.0/IOmxNode.h>
|
||||
#include <android/hardware/media/omx/1.0/IGraphicBufferSource.h>
|
||||
|
||||
#include <android/BnGraphicBufferSource.h>
|
||||
|
||||
namespace android {
|
||||
namespace hardware {
|
||||
namespace media {
|
||||
namespace omx {
|
||||
namespace V1_0 {
|
||||
namespace utils {
|
||||
|
||||
using ::android::hardware::graphics::common::V1_0::Dataspace;
|
||||
using ::android::hardware::media::omx::V1_0::ColorAspects;
|
||||
using ::android::hardware::media::omx::V1_0::IGraphicBufferSource;
|
||||
using ::android::hardware::media::omx::V1_0::IOmxNode;
|
||||
using ::android::hidl::base::V1_0::IBase;
|
||||
using ::android::hardware::hidl_array;
|
||||
using ::android::hardware::hidl_memory;
|
||||
using ::android::hardware::hidl_string;
|
||||
using ::android::hardware::hidl_vec;
|
||||
using ::android::hardware::Return;
|
||||
using ::android::hardware::Void;
|
||||
using ::android::sp;
|
||||
using ::android::IOMXNode;
|
||||
|
||||
/**
|
||||
* Wrapper classes for conversion
|
||||
* ==============================
|
||||
*
|
||||
* Naming convention:
|
||||
* - LW = Legacy Wrapper --- It wraps a Treble object inside a legacy object.
|
||||
* - TW = Treble Wrapper --- It wraps a legacy object inside a Treble object.
|
||||
*/
|
||||
|
||||
typedef ::android::binder::Status BnStatus;
|
||||
typedef ::android::BnGraphicBufferSource BnGraphicBufferSource;
|
||||
typedef ::android::hardware::media::omx::V1_0::IGraphicBufferSource
|
||||
TGraphicBufferSource;
|
||||
|
||||
struct LWGraphicBufferSource : public BnGraphicBufferSource {
|
||||
sp<TGraphicBufferSource> mBase;
|
||||
LWGraphicBufferSource(sp<TGraphicBufferSource> const& base);
|
||||
BnStatus configure(const sp<IOMXNode>& omxNode, int32_t dataSpace) override;
|
||||
BnStatus setSuspend(bool suspend, int64_t timeUs) override;
|
||||
BnStatus setRepeatPreviousFrameDelayUs(int64_t repeatAfterUs) override;
|
||||
BnStatus setMaxFps(float maxFps) override;
|
||||
BnStatus setTimeLapseConfig(double fps, double captureFps) override;
|
||||
BnStatus setStartTimeUs(int64_t startTimeUs) override;
|
||||
BnStatus setStopTimeUs(int64_t stopTimeUs) override;
|
||||
BnStatus getStopTimeOffsetUs(int64_t *stopTimeOffsetUs) override;
|
||||
BnStatus setColorAspects(int32_t aspects) override;
|
||||
BnStatus setTimeOffsetUs(int64_t timeOffsetsUs) override;
|
||||
BnStatus signalEndOfInputStream() override;
|
||||
};
|
||||
|
||||
} // namespace utils
|
||||
} // namespace V1_0
|
||||
} // namespace omx
|
||||
} // namespace media
|
||||
} // namespace hardware
|
||||
} // namespace android
|
||||
|
||||
#endif // ANDROID_HARDWARE_MEDIA_OMX_V1_0_WGRAPHICBUFFERSOURCE_H
|
@ -0,0 +1,98 @@
|
||||
/*
|
||||
* Copyright 2016, The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include <media/omx/1.0/WGraphicBufferSource.h>
|
||||
#include <media/omx/1.0/WOmxNode.h>
|
||||
#include <media/omx/1.0/Conversion.h>
|
||||
|
||||
namespace android {
|
||||
namespace hardware {
|
||||
namespace media {
|
||||
namespace omx {
|
||||
namespace V1_0 {
|
||||
namespace utils {
|
||||
|
||||
// LWGraphicBufferSource
|
||||
LWGraphicBufferSource::LWGraphicBufferSource(
|
||||
sp<TGraphicBufferSource> const& base) : mBase(base) {
|
||||
}
|
||||
|
||||
BnStatus LWGraphicBufferSource::configure(
|
||||
const sp<IOMXNode>& omxNode, int32_t dataSpace) {
|
||||
sp<IOmxNode> hOmxNode = omxNode->getHalInterface<IOmxNode>();
|
||||
return toBinderStatus(mBase->configure(
|
||||
hOmxNode == nullptr ? new TWOmxNode(omxNode) : hOmxNode,
|
||||
toHardwareDataspace(dataSpace)));
|
||||
}
|
||||
|
||||
BnStatus LWGraphicBufferSource::setSuspend(
|
||||
bool suspend, int64_t timeUs) {
|
||||
return toBinderStatus(mBase->setSuspend(suspend, timeUs));
|
||||
}
|
||||
|
||||
BnStatus LWGraphicBufferSource::setRepeatPreviousFrameDelayUs(
|
||||
int64_t repeatAfterUs) {
|
||||
return toBinderStatus(mBase->setRepeatPreviousFrameDelayUs(repeatAfterUs));
|
||||
}
|
||||
|
||||
BnStatus LWGraphicBufferSource::setMaxFps(float maxFps) {
|
||||
return toBinderStatus(mBase->setMaxFps(maxFps));
|
||||
}
|
||||
|
||||
BnStatus LWGraphicBufferSource::setTimeLapseConfig(
|
||||
double fps, double captureFps) {
|
||||
return toBinderStatus(mBase->setTimeLapseConfig(fps, captureFps));
|
||||
}
|
||||
|
||||
BnStatus LWGraphicBufferSource::setStartTimeUs(
|
||||
int64_t startTimeUs) {
|
||||
return toBinderStatus(mBase->setStartTimeUs(startTimeUs));
|
||||
}
|
||||
|
||||
BnStatus LWGraphicBufferSource::setStopTimeUs(
|
||||
int64_t stopTimeUs) {
|
||||
return toBinderStatus(mBase->setStopTimeUs(stopTimeUs));
|
||||
}
|
||||
|
||||
BnStatus LWGraphicBufferSource::getStopTimeOffsetUs(
|
||||
int64_t *stopTimeOffsetUs) {
|
||||
return toBinderStatus(mBase->getStopTimeOffsetUs(
|
||||
[stopTimeOffsetUs](auto, auto offsetUs) {
|
||||
*stopTimeOffsetUs = offsetUs;
|
||||
}));
|
||||
}
|
||||
|
||||
BnStatus LWGraphicBufferSource::setColorAspects(
|
||||
int32_t aspects) {
|
||||
return toBinderStatus(mBase->setColorAspects(
|
||||
toHardwareColorAspects(aspects)));
|
||||
}
|
||||
|
||||
BnStatus LWGraphicBufferSource::setTimeOffsetUs(
|
||||
int64_t timeOffsetsUs) {
|
||||
return toBinderStatus(mBase->setTimeOffsetUs(timeOffsetsUs));
|
||||
}
|
||||
|
||||
BnStatus LWGraphicBufferSource::signalEndOfInputStream() {
|
||||
return toBinderStatus(mBase->signalEndOfInputStream());
|
||||
}
|
||||
|
||||
} // namespace utils
|
||||
} // namespace V1_0
|
||||
} // namespace omx
|
||||
} // namespace media
|
||||
} // namespace hardware
|
||||
} // namespace android
|
Loading…
Reference in new issue