1/*
2 * Copyright (C) 2017 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef KEY_FETCHER_H_
18#define KEY_FETCHER_H_
19
20#include <vector>
21
22#include <media/stagefright/foundation/ABuffer.h>
23#include <utils/Errors.h>
24
25using namespace std;
26
27namespace android {
28namespace clearkeycas {
29
30// Interface for classes which extract the content key from an Ecm.
31class KeyFetcher {
32public:
33    struct KeyInfo {
34        sp<ABuffer> key_bytes;
35        int key_id;
36    };
37
38    KeyFetcher() {}
39    virtual ~KeyFetcher() {}
40
41    // Initializes resources set in subclass-specific calls. This must be called
42    // before threads are started.
43    virtual status_t Init() = 0;
44
45    // Obtains content key(s) based on contents of |ecm|. |asset_id| is the
46    // internal id of the asset, |keys| is a vector containing instances of a
47    // class containing a content key and an id. |asset_id| and |keys| are
48    // owned by the caller and must be non-null.
49    virtual status_t ObtainKey(const sp<ABuffer>& ecm,
50            uint64_t* asset_id, vector<KeyInfo>* keys) = 0;
51};
52
53}  // namespace clearkeycas
54}  // namespace android
55
56#endif  // KEY_FETCHER_H_
57