1 /*
2  * Copyright (c) 2014 Intel Corporation.  All rights reserved.
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_TAG "drm_vendor_api"
18 
19 #include <log/log.h>
20 #include <dlfcn.h>
21 #include <string.h>
22 
23 #include "drm_vendor_api.h"
24 
25 #define LIB_DRM_VENDOR "libsepdrm_cc54.so"
26 
drm_vendor_api_init(struct drm_vendor_api * api)27 uint32_t drm_vendor_api_init(struct drm_vendor_api *api)
28 {
29     uint32_t got_error = 0;
30 
31     if (api == NULL) {
32         ALOGE("%s: NULL parameter provided", __func__);
33         return 1;
34     }
35 
36     api->handle = dlopen(LIB_DRM_VENDOR, RTLD_NOW);
37     if (api->handle == NULL) {
38         ALOGE("%s: couldn't dlopen %s : %s", __func__, LIB_DRM_VENDOR, dlerror());
39         drm_vendor_api_deinit(api);
40         return 1;
41     } else {
42         api->drm_keep_alive = (drm_keep_alive_t) dlsym(api->handle, "drm_keep_alive");
43         if (api->drm_keep_alive == NULL) {
44             ALOGE("%s: couldn't dlsym drm_keep_alive in %s : %s",
45                     __func__, LIB_DRM_VENDOR, dlerror());
46             got_error = 1;
47         }
48         api->drm_start_playback = (drm_start_playback_t) dlsym(api->handle, "drm_start_playback");
49         if (api->drm_start_playback == NULL) {
50             ALOGE("%s: couldn't dlsym drm_start_playback in %s : %s",
51                     __func__, LIB_DRM_VENDOR, dlerror());
52             got_error = 1;
53         }
54         api->drm_stop_playback = (drm_stop_playback_t) dlsym(api->handle, "drm_stop_playback");
55         if (api->drm_stop_playback == NULL) {
56             ALOGE("%s: couldn't dlsym drm_stop_playback in %s : %s",
57                     __func__, LIB_DRM_VENDOR, dlerror());
58             got_error = 1;
59         }
60         api->drm_pr_return_naluheaders = (drm_pr_return_naluheaders_t) dlsym(api->handle,
61                 "drm_pr_return_naluheaders");
62         if (api->drm_pr_return_naluheaders == NULL) {
63             ALOGE("%s: couldn't dlsym drm_pr_return_naluheaders in %s : %s",
64                     __func__, LIB_DRM_VENDOR, dlerror());
65             got_error = 1;
66         }
67         api->drm_wv_return_naluheaders =
68                 (drm_wv_return_naluheaders_t) dlsym(api->handle, "drm_wv_return_naluheaders");
69         if (api->drm_wv_return_naluheaders == NULL) {
70             ALOGE("%s: couldn't dlsym drm_wv_return_naluheaders in %s : %s",
71                     __func__, LIB_DRM_VENDOR, dlerror());
72             got_error = 1;
73         }
74         if (got_error) {
75             drm_vendor_api_deinit(api);
76             return 1;
77         }
78     }
79     return 0;
80 }
81 
drm_vendor_api_deinit(struct drm_vendor_api * api)82 uint32_t drm_vendor_api_deinit(struct drm_vendor_api *api)
83 {
84     if (api == NULL) {
85         ALOGE("%s: NULL parameter provided", __func__);
86         return 1;
87     }
88     if(api->handle) {
89         if (dlclose(api->handle)) {
90             ALOGE("%s: couldn't dlcose %s : %s", __func__, LIB_DRM_VENDOR, dlerror());
91             return 1;
92         }
93     }
94     memset(api, 0, sizeof(struct drm_vendor_api));
95     return 0;
96 }
97