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

Commit cd58933b authored by Dongwon Kang's avatar Dongwon Kang Committed by Ayushi Khopkar
Browse files

Remove libcrypto dependency when building com.android.media

A base class with default implementation, SampleDecryptor, is added to
be used in com.android.media without requiring libcrypto.

Test: build
Bug: 141646183

Change-Id: Ied8b33ca3dfc993f14389601c4b897c2205ba685
Merged-In: Idbd6b4bc3a9f7edc63bf5b450d02182032be37b2
parent 84b71232
Loading
Loading
Loading
Loading
+0 −1
Original line number Diff line number Diff line
@@ -12,7 +12,6 @@ cc_library {
    shared_libs: [
        "libcgrouprc#29",
        "libvndksupport#29",
        "libcrypto",
    ],

    header_libs: [
+11 −1
Original line number Diff line number Diff line
@@ -36,6 +36,10 @@
#include <inttypes.h>
#include <netinet/in.h>

#ifndef __ANDROID_APEX__
#include "HlsSampleDecryptor.h"
#endif

namespace android {

ElementaryStreamQueue::ElementaryStreamQueue(Mode mode, uint32_t flags)
@@ -50,7 +54,13 @@ ElementaryStreamQueue::ElementaryStreamQueue(Mode mode, uint32_t flags)

    // Create the decryptor anyway since we don't know the use-case unless key is provided
    // Won't decrypt if key info not available (e.g., scanner/extractor just parsing ts files)
    mSampleDecryptor = isSampleEncrypted() ? new HlsSampleDecryptor : NULL;
    mSampleDecryptor = isSampleEncrypted() ?
#ifdef __ANDROID_APEX__
        new SampleDecryptor
#else
        new HlsSampleDecryptor
#endif
        : NULL;
}

sp<MetaData> ElementaryStreamQueue::getFormat() {
+2 −2
Original line number Diff line number Diff line
@@ -25,7 +25,7 @@
#include <utils/RefBase.h>
#include <vector>

#include "HlsSampleDecryptor.h"
#include "SampleDecryptor.h"

namespace android {

@@ -109,7 +109,7 @@ private:

    sp<MetaData> mFormat;

    sp<HlsSampleDecryptor> mSampleDecryptor;
    sp<SampleDecryptor> mSampleDecryptor;
    int mAUIndex;

    bool isSampleEncrypted() const {
+10 −8
Original line number Diff line number Diff line
@@ -14,9 +14,9 @@
 * limitations under the License.
 */

#ifndef SAMPLE_AES_PROCESSOR_H_
#ifndef HLS_SAMPLE_AES_PROCESSOR_H_

#define SAMPLE_AES_PROCESSOR_H_
#define HLS_SAMPLE_AES_PROCESSOR_H_

#include <media/stagefright/foundation/AMessage.h>
#include <media/stagefright/foundation/AString.h>
@@ -28,18 +28,20 @@
#include <utils/RefBase.h>
#include <utils/Vector.h>

#include "SampleDecryptor.h"

namespace android {

struct HlsSampleDecryptor : RefBase {
struct HlsSampleDecryptor : SampleDecryptor {

    HlsSampleDecryptor();
    explicit HlsSampleDecryptor(const sp<AMessage> &sampleAesKeyItem);

    void signalNewSampleAesKey(const sp<AMessage> &sampleAesKeyItem);
    virtual void signalNewSampleAesKey(const sp<AMessage> &sampleAesKeyItem);

    size_t processNal(uint8_t *nalData, size_t nalSize);
    void processAAC(size_t adtsHdrSize, uint8_t *data, size_t size);
    void processAC3(uint8_t *data, size_t size);
    virtual size_t processNal(uint8_t *nalData, size_t nalSize);
    virtual void processAAC(size_t adtsHdrSize, uint8_t *data, size_t size);
    virtual void processAC3(uint8_t *data, size_t size);

    static AString aesBlockToStr(uint8_t block[AES_BLOCK_SIZE]);

@@ -60,4 +62,4 @@ private:

}  // namespace android

#endif // SAMPLE_AES_PROCESSOR_H_
#endif // HLS_SAMPLE_AES_PROCESSOR_H_
+44 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 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 SAMPLE_AES_PROCESSOR_H_

#define SAMPLE_AES_PROCESSOR_H_

#include <media/stagefright/foundation/AMessage.h>

#include <utils/RefBase.h>

namespace android {

// Base class of HlsSampleDecryptor which has dummy default implementation.
struct SampleDecryptor : RefBase {

    SampleDecryptor() { };

    virtual void signalNewSampleAesKey(const sp<AMessage> &) { };

    virtual size_t processNal(uint8_t *, size_t) { return -1; };
    virtual void processAAC(size_t, uint8_t *, size_t) { };
    virtual void processAC3(uint8_t *, size_t) { };

private:
    DISALLOW_EVIL_CONSTRUCTORS(SampleDecryptor);
};

}  // namespace android

#endif // SAMPLE_AES_PROCESSOR_H_