1e2b43843fd12783188edd2c54188ea8d26864788Vijay Venkatraman/*
2e2b43843fd12783188edd2c54188ea8d26864788Vijay Venkatraman * Copyright (C) 2012 The Android Open Source Project
3e2b43843fd12783188edd2c54188ea8d26864788Vijay Venkatraman *
4e2b43843fd12783188edd2c54188ea8d26864788Vijay Venkatraman * Licensed under the Apache License, Version 2.0 (the "License");
5e2b43843fd12783188edd2c54188ea8d26864788Vijay Venkatraman * you may not use this file except in compliance with the License.
6e2b43843fd12783188edd2c54188ea8d26864788Vijay Venkatraman * You may obtain a copy of the License at
7e2b43843fd12783188edd2c54188ea8d26864788Vijay Venkatraman *
8e2b43843fd12783188edd2c54188ea8d26864788Vijay Venkatraman *      http://www.apache.org/licenses/LICENSE-2.0
9e2b43843fd12783188edd2c54188ea8d26864788Vijay Venkatraman *
10e2b43843fd12783188edd2c54188ea8d26864788Vijay Venkatraman * Unless required by applicable law or agreed to in writing, software
11e2b43843fd12783188edd2c54188ea8d26864788Vijay Venkatraman * distributed under the License is distributed on an "AS IS" BASIS,
12e2b43843fd12783188edd2c54188ea8d26864788Vijay Venkatraman * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13e2b43843fd12783188edd2c54188ea8d26864788Vijay Venkatraman * See the License for the specific language governing permissions and
14e2b43843fd12783188edd2c54188ea8d26864788Vijay Venkatraman * limitations under the License.
15e2b43843fd12783188edd2c54188ea8d26864788Vijay Venkatraman */
16e2b43843fd12783188edd2c54188ea8d26864788Vijay Venkatraman
17e2b43843fd12783188edd2c54188ea8d26864788Vijay Venkatraman#ifndef CRYPTO_H_
18e2b43843fd12783188edd2c54188ea8d26864788Vijay Venkatraman
19e2b43843fd12783188edd2c54188ea8d26864788Vijay Venkatraman#define CRYPTO_H_
20e2b43843fd12783188edd2c54188ea8d26864788Vijay Venkatraman
21e2b43843fd12783188edd2c54188ea8d26864788Vijay Venkatraman#include <media/ICrypto.h>
22e2b43843fd12783188edd2c54188ea8d26864788Vijay Venkatraman#include <utils/threads.h>
23e2b43843fd12783188edd2c54188ea8d26864788Vijay Venkatraman#include <utils/KeyedVector.h>
24e2b43843fd12783188edd2c54188ea8d26864788Vijay Venkatraman
25e2b43843fd12783188edd2c54188ea8d26864788Vijay Venkatraman#include "SharedLibrary.h"
26e2b43843fd12783188edd2c54188ea8d26864788Vijay Venkatraman
27e2b43843fd12783188edd2c54188ea8d26864788Vijay Venkatramannamespace android {
28e2b43843fd12783188edd2c54188ea8d26864788Vijay Venkatraman
29e2b43843fd12783188edd2c54188ea8d26864788Vijay Venkatramanstruct CryptoFactory;
30e2b43843fd12783188edd2c54188ea8d26864788Vijay Venkatramanstruct CryptoPlugin;
31e2b43843fd12783188edd2c54188ea8d26864788Vijay Venkatraman
32e2b43843fd12783188edd2c54188ea8d26864788Vijay Venkatramanstruct Crypto : public BnCrypto {
33e2b43843fd12783188edd2c54188ea8d26864788Vijay Venkatraman    Crypto();
34e2b43843fd12783188edd2c54188ea8d26864788Vijay Venkatraman    virtual ~Crypto();
35e2b43843fd12783188edd2c54188ea8d26864788Vijay Venkatraman
36e2b43843fd12783188edd2c54188ea8d26864788Vijay Venkatraman    virtual status_t initCheck() const;
37e2b43843fd12783188edd2c54188ea8d26864788Vijay Venkatraman
38e2b43843fd12783188edd2c54188ea8d26864788Vijay Venkatraman    virtual bool isCryptoSchemeSupported(const uint8_t uuid[16]);
39e2b43843fd12783188edd2c54188ea8d26864788Vijay Venkatraman
40e2b43843fd12783188edd2c54188ea8d26864788Vijay Venkatraman    virtual status_t createPlugin(
41e2b43843fd12783188edd2c54188ea8d26864788Vijay Venkatraman            const uint8_t uuid[16], const void *data, size_t size);
42e2b43843fd12783188edd2c54188ea8d26864788Vijay Venkatraman
43e2b43843fd12783188edd2c54188ea8d26864788Vijay Venkatraman    virtual status_t destroyPlugin();
44e2b43843fd12783188edd2c54188ea8d26864788Vijay Venkatraman
45e2b43843fd12783188edd2c54188ea8d26864788Vijay Venkatraman    virtual bool requiresSecureDecoderComponent(
46e2b43843fd12783188edd2c54188ea8d26864788Vijay Venkatraman            const char *mime) const;
47e2b43843fd12783188edd2c54188ea8d26864788Vijay Venkatraman
48e2b43843fd12783188edd2c54188ea8d26864788Vijay Venkatraman    virtual void notifyResolution(uint32_t width, uint32_t height);
49e2b43843fd12783188edd2c54188ea8d26864788Vijay Venkatraman
50e2b43843fd12783188edd2c54188ea8d26864788Vijay Venkatraman    virtual status_t setMediaDrmSession(const Vector<uint8_t> &sessionId);
51e2b43843fd12783188edd2c54188ea8d26864788Vijay Venkatraman
52e2b43843fd12783188edd2c54188ea8d26864788Vijay Venkatraman    virtual ssize_t decrypt(const uint8_t key[16], const uint8_t iv[16],
53e2b43843fd12783188edd2c54188ea8d26864788Vijay Venkatraman            CryptoPlugin::Mode mode, const CryptoPlugin::Pattern &pattern,
54e2b43843fd12783188edd2c54188ea8d26864788Vijay Venkatraman            const sp<IMemory> &source, size_t offset,
55e2b43843fd12783188edd2c54188ea8d26864788Vijay Venkatraman            const CryptoPlugin::SubSample *subSamples, size_t numSubSamples,
56e2b43843fd12783188edd2c54188ea8d26864788Vijay Venkatraman            const DestinationBuffer &destination, AString *errorDetailMsg);
57e2b43843fd12783188edd2c54188ea8d26864788Vijay Venkatraman
58d07c92742fc5801cab8e99801f591365986acbe9Chong Zhang    virtual void setHeap(const sp<IMemoryHeap>&) {}
59d07c92742fc5801cab8e99801f591365986acbe9Chong Zhang    virtual void unsetHeap(const sp<IMemoryHeap>&) {}
60d07c92742fc5801cab8e99801f591365986acbe9Chong Zhang
61e2b43843fd12783188edd2c54188ea8d26864788Vijay Venkatramanprivate:
62e2b43843fd12783188edd2c54188ea8d26864788Vijay Venkatraman    mutable Mutex mLock;
63e2b43843fd12783188edd2c54188ea8d26864788Vijay Venkatraman
64e2b43843fd12783188edd2c54188ea8d26864788Vijay Venkatraman    status_t mInitCheck;
65e2b43843fd12783188edd2c54188ea8d26864788Vijay Venkatraman    sp<SharedLibrary> mLibrary;
66e2b43843fd12783188edd2c54188ea8d26864788Vijay Venkatraman    CryptoFactory *mFactory;
67e2b43843fd12783188edd2c54188ea8d26864788Vijay Venkatraman    CryptoPlugin *mPlugin;
68e2b43843fd12783188edd2c54188ea8d26864788Vijay Venkatraman
69e2b43843fd12783188edd2c54188ea8d26864788Vijay Venkatraman    static KeyedVector<Vector<uint8_t>, String8> mUUIDToLibraryPathMap;
70e2b43843fd12783188edd2c54188ea8d26864788Vijay Venkatraman    static KeyedVector<String8, wp<SharedLibrary> > mLibraryPathToOpenLibraryMap;
71e2b43843fd12783188edd2c54188ea8d26864788Vijay Venkatraman    static Mutex mMapLock;
72e2b43843fd12783188edd2c54188ea8d26864788Vijay Venkatraman
73e2b43843fd12783188edd2c54188ea8d26864788Vijay Venkatraman    void findFactoryForScheme(const uint8_t uuid[16]);
74e2b43843fd12783188edd2c54188ea8d26864788Vijay Venkatraman    bool loadLibraryForScheme(const String8 &path, const uint8_t uuid[16]);
75e2b43843fd12783188edd2c54188ea8d26864788Vijay Venkatraman    void closeFactory();
76e2b43843fd12783188edd2c54188ea8d26864788Vijay Venkatraman
77e2b43843fd12783188edd2c54188ea8d26864788Vijay Venkatraman    DISALLOW_EVIL_CONSTRUCTORS(Crypto);
78e2b43843fd12783188edd2c54188ea8d26864788Vijay Venkatraman};
79e2b43843fd12783188edd2c54188ea8d26864788Vijay Venkatraman
80e2b43843fd12783188edd2c54188ea8d26864788Vijay Venkatraman}  // namespace android
81e2b43843fd12783188edd2c54188ea8d26864788Vijay Venkatraman
82e2b43843fd12783188edd2c54188ea8d26864788Vijay Venkatraman#endif  // CRYPTO_H_
83