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

Commit 3579b9d3 authored by Shalaj Jain's avatar Shalaj Jain Committed by Steve Kondik
Browse files

libstagefright: Add custom IOCTL for prefetching CMA data for wv playback

trigger allocation of cma pool at start of drm playback

Change-Id: I6c15b31ff3147739f9d837a2a2b6e135cc918e99

libstagefright: Prefetch CMA data for secure playback via MediaCodec

Trigger allocation of cma pool at start of drm playback in mediacodec mode.

Change-Id: I1ce09f3c9013cb815f1ab0e729a099c7aae79ec5
parent ecdf6678
Loading
Loading
Loading
Loading
+33 −11
Original line number Diff line number Diff line
#
# This file was modified by Dolby Laboratories, Inc. The portions of the
# code that are surrounded by "DOLBY..." are copyrighted and
# licensed separately, as follows:
#
#  (C) 2012-2013 Dolby Laboratories, Inc.
#
# 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.
#
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)

@@ -152,6 +171,8 @@ LOCAL_SRC_FILES += ExtendedCodec.cpp ExtendedExtractor.cpp ExtendedUtils.cpp
ifeq ($(TARGET_ENABLE_QC_AV_ENHANCEMENTS),true)
    LOCAL_CFLAGS     += -DENABLE_AV_ENHANCEMENTS
    LOCAL_SRC_FILES  += ExtendedMediaDefs.cpp ExtendedWriter.cpp
    LOCAL_C_INCLUDES += $(TARGET_OUT_INTERMEDIATES)/KERNEL_OBJ/usr/include
    LOCAL_ADDITIONAL_DEPENDENCIES := $(TARGET_OUT_INTERMEDIATES)/KERNEL_OBJ/usr

    ifneq ($(TARGET_QCOM_MEDIA_VARIANT),)
        LOCAL_C_INCLUDES += \
@@ -179,13 +200,13 @@ LOCAL_CFLAGS += -Wno-multichar

ifeq ($(BOARD_USE_SAMSUNG_COLORFORMAT), true)
LOCAL_CFLAGS += -DUSE_SAMSUNG_COLORFORMAT
endif

# Include native color format header path
LOCAL_C_INCLUDES += \
	$(TOP)/hardware/samsung/exynos4/hal/include \
	$(TOP)/hardware/samsung/exynos4/include

endif

ifeq ($(BOARD_USE_TI_DUCATI_H264_PROFILE), true)
LOCAL_CFLAGS += -DUSE_TI_DUCATI_H264_PROFILE
@@ -197,6 +218,7 @@ endif #DOLBY_UDC
ifdef DOLBY_UDC_MULTICHANNEL
  LOCAL_CFLAGS += -DDOLBY_UDC_MULTICHANNEL
endif #DOLBY_UDC_MULTICHANNEL

LOCAL_MODULE:= libstagefright

LOCAL_MODULE_TAGS := optional
+12 −1
Original line number Diff line number Diff line
@@ -290,6 +290,9 @@ AwesomePlayer::~AwesomePlayer() {
    mIsTunnelAudio = false;
#endif
    mClient.disconnect();
#ifdef ENABLE_AV_ENHANCEMENTS
    ExtendedUtils::drainSecurePool();
#endif
}

void AwesomePlayer::printStats() {
@@ -379,6 +382,10 @@ status_t AwesomePlayer::setDataSource_l(

    mUri = uri;

#ifdef ENABLE_AV_ENHANCEMENTS
    ExtendedUtils::prefetchSecurePool(uri);
#endif

    if (headers) {
        mUriHeaders = *headers;

@@ -427,8 +434,12 @@ status_t AwesomePlayer::setDataSource(
    ALOGD("Before reset_l");
    reset_l();

    if(fd)
    if (fd) {
        printFileName(fd);
#ifdef ENABLE_AV_ENHANCEMENTS
        ExtendedUtils::prefetchSecurePool(fd);
#endif
    }

    sp<DataSource> dataSource = new FileSource(fd, offset, length);

+101 −2
Original line number Diff line number Diff line
/*Copyright (c) 2013, The Linux Foundation. All rights reserved.
/*Copyright (c) 2013-2014, The Linux Foundation. All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are
@@ -54,6 +54,10 @@ static const int64_t kMaxAVSyncLateMargin = 250000;

#include "include/ExtendedExtractor.h"
#include "include/avc_utils.h"
#include <fcntl.h>
#include <linux/msm_ion.h>
#define MEM_DEVICE "/dev/ion"
#define MEM_HEAP_ID ION_CP_MM_HEAP_ID

namespace android {

@@ -527,6 +531,91 @@ bool ExtendedUtils::checkIsThumbNailMode(const uint32_t flags, char* componentNa
    return isInThumbnailMode;
}

void ExtendedUtils::prefetchSecurePool(const char *uri)
{
    if (!strncasecmp("widevine://", uri, 11)) {
        ALOGV("Widevine streaming content\n");
        createSecurePool();
    }
}

void ExtendedUtils::prefetchSecurePool(int fd)
{
    char symName[40] = {0};
    char fileName[256] = {0};
    char* kSuffix;
    size_t kSuffixLength = 0;
    size_t fileNameLength;

    snprintf(symName, sizeof(symName), "/proc/%d/fd/%d", getpid(), fd);

    if (readlink( symName, fileName, (sizeof(fileName) - 1)) != -1 ) {
        kSuffix = (char *)".wvm";
        kSuffixLength = strlen(kSuffix);
        fileNameLength = strlen(fileName);

        if (!strcmp(&fileName[fileNameLength - kSuffixLength], kSuffix)) {
            ALOGV("Widevine local content\n");
            createSecurePool();
        }
    }
}

void ExtendedUtils::prefetchSecurePool()
{
    createSecurePool();
}

void ExtendedUtils::createSecurePool()
{
#ifdef ION_IOC_PREFETCH
    struct ion_prefetch_data prefetch_data;
    struct ion_custom_data d;
    int ion_dev_flag = O_RDONLY;
    int rc = 0;
    int fd = open (MEM_DEVICE, ion_dev_flag);

    if (fd < 0) {
        ALOGE("opening ion device failed with fd = %d", fd);
    } else {
        prefetch_data.heap_id = ION_HEAP(MEM_HEAP_ID);
        prefetch_data.len = 0x0;
        d.cmd = ION_IOC_PREFETCH;
        d.arg = (unsigned long int)&prefetch_data;
        rc = ioctl(fd, ION_IOC_CUSTOM, &d);
        if (rc != 0) {
            ALOGE("creating secure pool failed, rc is %d, errno is %d", rc, errno);
        }
        close(fd);
    }
#endif
}

void ExtendedUtils::drainSecurePool()
{
#ifdef ION_IOC_DRAIN
    struct ion_prefetch_data prefetch_data;
    struct ion_custom_data d;
    int ion_dev_flag = O_RDONLY;
    int rc = 0;
    int fd = open (MEM_DEVICE, ion_dev_flag);

    if (fd < 0) {
        ALOGE("opening ion device failed with fd = %d", fd);
    } else {
        prefetch_data.heap_id = ION_HEAP(MEM_HEAP_ID);
        prefetch_data.len = 0x0;
        d.cmd = ION_IOC_DRAIN;
        d.arg = (unsigned long int)&prefetch_data;
        rc = ioctl(fd, ION_IOC_CUSTOM, &d);
        if (rc != 0) {
            ALOGE("draining secure pool failed rc is %d, errno is %d", rc, errno);
        }
        close(fd);
    }
#endif
}

}
#else //ENABLE_AV_ENHANCEMENTS

@@ -618,5 +707,15 @@ bool ExtendedUtils::checkIsThumbNailMode(const uint32_t flags, char* componentNa
    return false;
}

void ExtendedUtils::prefetchSecurePool(int fd) {}

void ExtendedUtils::prefetchSecurePool(const char *uri) {}

void ExtendedUtils::prefetchSecurePool() {}

void ExtendedUtils::createSecurePool() {}

void ExtendedUtils::drainSecurePool() {}

}
#endif //ENABLE_AV_ENHANCEMENTS
+7 −0
Original line number Diff line number Diff line
@@ -37,6 +37,7 @@
#include <media/stagefright/MetaData.h>
#ifdef QCOM_HARDWARE
#include <media/stagefright/ExtendedCodec.h>
#include "include/ExtendedUtils.h"
#endif
#include <media/stagefright/NativeWindowWrapper.h>

@@ -82,6 +83,9 @@ MediaCodec::MediaCodec(const sp<ALooper> &looper)

MediaCodec::~MediaCodec() {
    CHECK_EQ(mState, UNINITIALIZED);
#ifdef ENABLE_AV_ENHANCEMENTS
    ExtendedUtils::drainSecurePool();
#endif
}

// static
@@ -111,6 +115,9 @@ status_t MediaCodec::init(const char *name, bool nameIsType, bool encoder) {
    } else {
        AString tmp = name;
        if (tmp.endsWith(".secure")) {
#ifdef ENABLE_AV_ENHANCEMENTS
            ExtendedUtils::prefetchSecurePool();
#endif
            tmp.erase(tmp.size() - 7, 7);
        }
        const MediaCodecList *mcl = MediaCodecList::getInstance();
+10 −1
Original line number Diff line number Diff line
/*Copyright (c) 2013, The Linux Foundation. All rights reserved.
/*Copyright (c) 2013-2014, The Linux Foundation. All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are
@@ -141,6 +141,15 @@ struct ExtendedUtils {

    static bool checkIsThumbNailMode(const uint32_t flags, char* componentName);

    static void prefetchSecurePool(int fd);

    static void prefetchSecurePool(const char *uri);

    static void prefetchSecurePool();

    static void createSecurePool();

    static void drainSecurePool();
};

}