• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2018 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 CLEARKEY_ANDROID_HARDWARE_DRM_V1_1_TYPECONVERT
18 #define CLEARKEY_ANDROID_HARDWARE_DRM_V1_1_TYPECONVERT
19 
20 #include <vector>
21 
22 #include <android/hardware/drm/1.0/types.h>
23 
24 namespace android {
25 namespace hardware {
26 namespace drm {
27 namespace V1_1 {
28 namespace clearkey {
29 
30 using ::android::hardware::hidl_array;
31 using ::android::hardware::hidl_vec;
32 
toHidlVec(const std::vector<T> & vec)33 template<typename T> const hidl_vec<T> toHidlVec(const std::vector<T> &vec) {
34     hidl_vec<T> hVec;
35     hVec.setToExternal(const_cast<T *>(vec.data()), vec.size());
36     return hVec;
37 }
38 
toHidlVec(std::vector<T> & vec)39 template<typename T> hidl_vec<T> toHidlVec(std::vector<T> &vec) {
40     hidl_vec<T> hVec;
41     hVec.setToExternal(vec.data(), vec.size());
42     return hVec;
43 }
44 
toVector(const hidl_vec<T> & hVec)45 template<typename T> const std::vector<T> toVector(const hidl_vec<T> &hVec) {
46     std::vector<T> vec;
47     vec.assign(hVec.data(), hVec.data() + hVec.size());
48     return *const_cast<const std::vector<T> *>(&vec);
49 }
50 
toVector(hidl_vec<T> & hVec)51 template<typename T> std::vector<T> toVector(hidl_vec<T> &hVec) {
52     std::vector<T> vec;
53     vec.assign(hVec.data(), hVec.data() + hVec.size());
54     return vec;
55 }
56 
toVector(const hidl_array<T,SIZE> & hArray)57 template<typename T, size_t SIZE> const std::vector<T> toVector(
58         const hidl_array<T, SIZE> &hArray) {
59     std::vector<T> vec;
60     vec.assign(hArray.data(), hArray.data() + hArray.size());
61     return vec;
62 }
63 
toVector(hidl_array<T,SIZE> & hArray)64 template<typename T, size_t SIZE> std::vector<T> toVector(
65         hidl_array<T, SIZE> &hArray) {
66     std::vector<T> vec;
67     vec.assign(hArray.data(), hArray.data() + hArray.size());
68     return vec;
69 }
70 
71 }  // namespace clearkey
72 }  // namespace V1_1
73 }  // namespace drm
74 }  // namespace hardware
75 }  // namespace android
76 
77 #endif // CLEARKEY_ANDROID_HARDWARE_DRM_V1_1_TYPECONVERT
78