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

Commit 8c953e45 authored by Dan Stoza's avatar Dan Stoza
Browse files

libstagefright: Remove direct access to gralloc

Switches from loading the gralloc module directly to using
GraphicBufferMapper.

Change-Id: Ib4f6e0d5b3fd1cb1747a1a78959e9fa8f3c6864a
parent df9e6aaf
Loading
Loading
Loading
Loading
+9 −16
Original line number Diff line number Diff line
@@ -23,7 +23,6 @@

#include "include/SoftVideoEncoderOMXComponent.h"

#include <hardware/gralloc.h>
#include <media/hardware/HardwareAPI.h>
#include <media/stagefright/foundation/ADebug.h>
#include <media/stagefright/foundation/ALooper.h>
@@ -71,7 +70,6 @@ SoftVideoEncoderOMXComponent::SoftVideoEncoderOMXComponent(
      mBitrate(192000),
      mFramerate(30 << 16), // Q16 format
      mColorFormat(OMX_COLOR_FormatYUV420Planar),
      mGrallocModule(NULL),
      mMinOutputBufferSize(384), // arbitrary, using one uncompressed macroblock
      mMinCompressionRatio(1),   // max output size is normally the input size
      mComponentRole(componentRole),
@@ -500,13 +498,6 @@ const uint8_t *SoftVideoEncoderOMXComponent::extractGraphicBuffer(
        return NULL;
    }

    if (mGrallocModule == NULL) {
        CHECK_EQ(0, hw_get_module(GRALLOC_HARDWARE_MODULE_ID, &mGrallocModule));
    }

    const gralloc_module_t *grmodule =
        (const gralloc_module_t *)mGrallocModule;

    buffer_handle_t handle;
    int format;
    size_t srcStride;
@@ -564,19 +555,21 @@ const uint8_t *SoftVideoEncoderOMXComponent::extractGraphicBuffer(
        return NULL;
    }

    auto& mapper = GraphicBufferMapper::get();

    void *bits = NULL;
    struct android_ycbcr ycbcr;
    status_t res;
    if (format == HAL_PIXEL_FORMAT_YCbCr_420_888) {
        res = grmodule->lock_ycbcr(
                 grmodule, handle,
        res = mapper.lockYCbCr(
                 handle,
                 GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_NEVER,
                 0, 0, width, height, &ycbcr);
                 Rect(width, height), &ycbcr);
    } else {
        res = grmodule->lock(
                 grmodule, handle,
        res = mapper.lock(
                 handle,
                 GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_NEVER,
                 0, 0, width, height, &bits);
                 Rect(width, height), &bits);
    }
    if (res != OK) {
        ALOGE("Unable to lock image buffer %p for access", handle);
@@ -620,7 +613,7 @@ const uint8_t *SoftVideoEncoderOMXComponent::extractGraphicBuffer(
            break;
    }

    if (grmodule->unlock(grmodule, handle) != OK) {
    if (mapper.unlock(handle) != OK) {
        ALOGE("Unable to unlock image buffer %p for access", handle);
    }