1 /*
2  * Copyright (C) 2014 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 //#define LOG_NDEBUG 0
18 #define LOG_TAG "ClearKeyCryptoPlugin"
19 #include <utils/Log.h>
20 
21 #include <utils/Errors.h>
22 
23 #include "DrmFactory.h"
24 
25 #include "DrmPlugin.h"
26 #include "ClearKeyUUID.h"
27 #include "SessionLibrary.h"
28 
29 namespace clearkeydrm {
30 
isCryptoSchemeSupported(const uint8_t uuid[16])31 bool DrmFactory::isCryptoSchemeSupported(const uint8_t uuid[16]) {
32     return isClearKeyUUID(uuid);
33 }
34 
isContentTypeSupported(const android::String8 & initDataType)35 bool DrmFactory::isContentTypeSupported(const android::String8 &initDataType) {
36     // This should match the types handed by InitDataParser.
37     return initDataType == "cenc" ||
38            initDataType == "webm";
39 }
40 
createDrmPlugin(const uint8_t uuid[16],android::DrmPlugin ** plugin)41 android::status_t DrmFactory::createDrmPlugin(
42         const uint8_t uuid[16], android::DrmPlugin** plugin) {
43     if (!isCryptoSchemeSupported(uuid)) {
44         *plugin = NULL;
45         return android::BAD_VALUE;
46     }
47 
48     *plugin = new DrmPlugin(SessionLibrary::get());
49     return android::OK;
50 }
51 
52 } // namespace clearkeydrm
53