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

Commit 3c4de3af authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge "media.c2 aidl: Add decoder output allocator interface"

parents b8863f6a a2600cab
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -15,7 +15,7 @@ aidl_interface {
    double_loadable: true,
    srcs: ["android/hardware/media/c2/*.aidl"],
    include_dirs: [
        "frameworks/native/aidl/gui",
        "frameworks/base/core/java",
    ],
    imports: [
        "android.hardware.common-V2",
+1 −1
Original line number Diff line number Diff line
@@ -43,7 +43,7 @@ interface IComponent {
  void queue(in android.hardware.media.c2.WorkBundle workBundle);
  void release();
  void reset();
  void setOutputSurface(in long blockPoolId, in android.view.Surface surface, in android.hardware.media.c2.SurfaceSyncObj syncObject);
  void setDecoderOutputAllocator(in android.hardware.media.c2.IGraphicBufferAllocator allocator);
  void start();
  void stop();
  parcelable BlockPool {
+19 −6
Original line number Diff line number Diff line
/*
 * Copyright (C) 2022 The Android Open Source Project
 * Copyright (C) 2023 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.
@@ -33,9 +33,22 @@

package android.hardware.media.c2;
@VintfStability
parcelable SurfaceSyncObj {
  android.hardware.common.NativeHandle syncMemory;
  long bqId;
  int generationId;
  long consumerUsage;
interface IGraphicBufferAllocator {
  android.hardware.media.c2.IGraphicBufferAllocator.Allocation allocate(in android.hardware.media.c2.IGraphicBufferAllocator.Description desc);
  boolean deallocate(in long id);
  android.hardware.media.c2.IGraphicBufferAllocator.WaitableFds getWaitableFds();
  parcelable Allocation {
    android.hardware.HardwareBuffer buffer;
    ParcelFileDescriptor fence;
  }
  parcelable Description {
    int width;
    int height;
    int format;
    long usage;
  }
  parcelable WaitableFds {
    ParcelFileDescriptor allocEvent;
    ParcelFileDescriptor statusEvent;
  }
}
+7 −17
Original line number Diff line number Diff line
@@ -17,12 +17,10 @@
package android.hardware.media.c2;

import android.hardware.common.NativeHandle;
import android.view.Surface;

import android.hardware.media.c2.IComponentInterface;
import android.hardware.media.c2.IConfigurable;
import android.hardware.media.c2.IGraphicBufferAllocator;
import android.hardware.media.c2.WorkBundle;
import android.hardware.media.c2.SurfaceSyncObj;

/**
 * Interface for an AIDL Codec2 component.
@@ -234,23 +232,15 @@ interface IComponent {
    void reset();

    /**
     * Starts using a surface for output with a synchronization object
     *
     * This method must not block.
     * Specify an allocator for decoder output buffer from HAL.
     *
     * @param blockPoolId Id of the `C2BlockPool` to be associated with the
     *     output surface.
     * @param surface Output surface.
     * @param syncObject synchronization object for buffer allocation between
     *     Framework and Component.
     * @throws ServiceSpecificException with one of the following values:
     *   - `Status::CANNOT_DO` - The component does not support an output surface.
     *   - `Status::REFUSED`   - The output surface cannot be accessed.
     *   - `Status::TIMED_OUT` - The operation cannot be finished in a timely manner.
     * The method will be used once during the life-cycle of a codec instance.
     * @param allocator Decoder output buffer allocator from the client
     * @throws ServiceSpecificException with one of the following values
     *   - `Status::CANNOT_DO` - The component does not support allocating from the client.
     *   - `Status::CORRUPTED` - Some unknown error occurred.
     */
    void setOutputSurface(in long blockPoolId, in Surface surface,
        in SurfaceSyncObj syncObject);
    void setDecoderOutputAllocator(in IGraphicBufferAllocator allocator);

    /**
     * Starts the component.
+114 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2023 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.hardware.media.c2;

import android.hardware.HardwareBuffer;
import android.os.ParcelFileDescriptor;

/**
 * Interface for decoder output buffer allocator for HAL process
 *
 * A graphic buffer for decoder output is allocated by the interface.
 */
@VintfStability
interface IGraphicBufferAllocator {
    /**
     * A graphic buffer allocation.
     *
     * buffer is in android.hardware.HardwareBuffer.
     * fence is provided in order to signal readiness of the buffer I/O inside
     * underlying Graphics subsystem. This is called a sync fence throughout Android framework.
     */
    parcelable Allocation {
        HardwareBuffer buffer;
        ParcelFileDescriptor fence;
    }

    /**
     * Parameters for a graphic buffer allocation.
     *
     * Refer to AHardwareBuffer_Desc(libnativewindow) for details.
     */
    parcelable Description {
        int width;
        int height;
        int format;
        long usage;
    }

    /**
     * Allocate a graphic buffer.
     *
     * @param desc Allocation parameters.
     * @return an android.hardware.HardwareBuffer which is basically same to
     *     AHardwareBuffer. If underlying grpahics system is blocked, c2::Status::Blocked
     *     will be returned. In this case getWaitableFds() will return file descriptors which
     *     can be used to construct a waitable object. The waitable object will be notified
     *     when underlying graphics system is unblocked
     * @throws ServiceSpecificException with one of the following values:
     *   - `c2::Status::BAD_STATE` - The client is not in running states.
     *   - `c2::Status::BLOCKED`   - Underlying graphics system is blocked.
     *   - `c2::Status::CORRUPTED` - Some unknown error occurred.
     */
    Allocation allocate(in Description desc);

    /**
     * De-allocate a graphic buffer by graphic buffer's unique id.
     *
     * @param id graphic buffer's unique id. See also AHardwareBuffer_getId().
     * @return {@code true} when de-allocate happened, {@code false} otherwise.
     */
    boolean deallocate(in long id);

    /**
     * Fds for waitable object events.
     *
     * Fds are created by eventfd() with semaphore mode.
     * For allocEvent, An integer counter regarding dequeuable buffer count is maintained
     * by client using read()/write() to the fd. The fd can be checked whether it is
     * readable via poll(). When in readable status, the specified counter is positive
     * so allocate/dequeue can happen.
     *
     * For statusEvent, the client can notify further allocation is not feasible.
     * e.g.) life-cycle of the underlying allocator is ended.
     *
     * C2Fence object should be implemented based on this Fds. Thus, C2Fence can return
     * either by allocation being ready or allocation being infeasible by the client status
     * change.
     */
    parcelable WaitableFds {
        ParcelFileDescriptor allocEvent;
        ParcelFileDescriptor statusEvent;
    }

    /**
     * Gets waiable file descriptors.
     *
     * Use this method once and cache it in order not to create unnecessary duplicated fds.
     * The returned array will have two fds.
     *
     * If many waitable objects based on the same fd are competing, all watiable objects will be
     * notified. After being notified, they should invoke allocate(). At least one of them can
     * successfully allocate. Others not having an Allocation will have c2::Status::BLOCKED
     * as return value. They should wait again via waitable objects based on the fds which are
     * already returned from this interface.
     *
     * @return an fd array which will be wrapped to C2Fence and will be waited for
     *     until allocating is unblocked.
     */
    WaitableFds getWaitableFds();
}
Loading