1 /*
2  * Copyright 2016, 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 SECURE_BUFFER_H_
18 
19 #define SECURE_BUFFER_H_
20 
21 #include <mediadrm/ICrypto.h>
22 #include <media/MediaCodecBuffer.h>
23 
24 namespace android {
25 
26 class NativeHandle;
27 
28 /**
29  * Secure MediaCodecBuffer implementation.
30  *
31  * For classes outside of MediaCodec, this buffer is an opaque buffer only with
32  * the size information. For decryption, it exposes underlying handle/pointer
33  * and its type, which can be fed to ICrypto::decrypt().
34  */
35 class SecureBuffer : public MediaCodecBuffer {
36 public:
37     SecureBuffer(const sp<AMessage> &format, const void *ptr, size_t size);
38     SecureBuffer(const sp<AMessage> &format, const sp<NativeHandle> &handle, size_t size);
39 
40     virtual ~SecureBuffer() = default;
41 
42     void *getDestinationPointer();
43     ICrypto::DestinationType getDestinationType();
44 
45 private:
46     SecureBuffer() = delete;
47 
48     const void *mPointer;
49     const sp<NativeHandle> mHandle;
50 };
51 
52 }  // namespace android
53 
54 #endif  // SECURE_BUFFER_H_
55