1 /*
2 * Copyright (c) 2009-2011 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 #ifndef _INTEL_METADATA_BUFFER_H_
18 #define _INTEL_METADATA_BUFFER_H_
19 
20 #include <stdint.h>
21 
22 //#define INTEL_VIDEO_XPROC_SHARING
23 
24 #ifdef INTEL_VIDEO_XPROC_SHARING
25 #include <binder/MemoryBase.h>
26 #include <ui/GraphicBuffer.h>
27 
28 using namespace android;
29 #endif
30 #define STRING_TO_FOURCC(format) ((uint32_t)(((format)[0])|((format)[1]<<8)|((format)[2]<<16)|((format)[3]<<24)))
31 
32 typedef enum {
33     IMB_SUCCESS = 0,
34     IMB_INVAL_PARAM = 1,
35     IMB_INVAL_BUFFER = 2,
36 #ifdef INTEL_VIDEO_XPROC_SHARING
37     IMB_NO_SERVICE = 3,
38     IMB_SERVICE_FAIL = 4,
39 #endif
40 }IMB_Result;
41 
42 typedef enum {
43     MEM_MODE_MALLOC = 1,
44     MEM_MODE_CI = 2,
45     MEM_MODE_V4L2 = 4,
46     MEM_MODE_SURFACE = 8,
47     MEM_MODE_USRPTR = 16,
48     MEM_MODE_GFXHANDLE = 32,
49     MEM_MODE_KBUFHANDLE = 64,
50     MEM_MODE_ION = 128,
51     MEM_MODE_NONECACHE_USRPTR = 256,
52 }MemMode;
53 
54 typedef struct {
55         MemMode mode; 			//memory type, vasurface/malloc/gfx/ion/v4l2/ci etc
56         intptr_t handle;		//handle
57         uint32_t size;      		//memory size
58         uint32_t width;			//picture width
59         uint32_t height;		//picture height
60         uint32_t lumaStride;		//picture luma stride
61         uint32_t chromStride;		//picture chrom stride
62         uint32_t format;		//color format
63         uint32_t s3dformat;		//S3D format
64 #ifdef INTEL_VIDEO_XPROC_SHARING
65         uint32_t sessionFlag;     //for buffer sharing session
66 #endif
67 }ValueInfo;
68 
69 typedef enum {
70     IntelMetadataBufferTypeCameraSource = 0,   //same with kMetadataBufferTypeCameraSource in framework
71     IntelMetadataBufferTypeGrallocSource = 1,  //same with kMetadataBufferTypeGrallocSource in framework
72 
73     IntelMetadataBufferTypeExtension = 0xFF,   //intel extended type
74     IntelMetadataBufferTypeEncoder = IntelMetadataBufferTypeExtension,        //for WiDi clone mode
75     IntelMetadataBufferTypeUser = IntelMetadataBufferTypeExtension + 1,       //for WiDi user mode
76     IntelMetadataBufferTypeLast = IntelMetadataBufferTypeExtension + 2,       //type number
77 }IntelMetadataBufferType;
78 
79 class IntelMetadataBuffer {
80 public:
81     IntelMetadataBuffer();                                          //for generator
82     IntelMetadataBuffer(IntelMetadataBufferType type, intptr_t value);    //for quick generator
83     ~IntelMetadataBuffer();
84 
85     IntelMetadataBuffer(const IntelMetadataBuffer& imb);
86     const IntelMetadataBuffer& operator=(const IntelMetadataBuffer& imb);
87 
88     IMB_Result GetType(IntelMetadataBufferType &type);
89     IMB_Result SetType(IntelMetadataBufferType type);
90     IMB_Result GetValue(intptr_t &value);
91     IMB_Result SetValue(intptr_t value);
92     IMB_Result GetValueInfo(ValueInfo* &info);
93     IMB_Result SetValueInfo(ValueInfo *info);
94     IMB_Result GetExtraValues(intptr_t* &values, uint32_t &num);
95     IMB_Result SetExtraValues(intptr_t *values, uint32_t num);
96 
97     //New API for bytes input/ouput, UnSerialize=SetBytes, Serialize=GetBytes
98     IMB_Result UnSerialize(uint8_t* data, uint32_t size);
99     IMB_Result Serialize(uint8_t* &data, uint32_t& size);
100 
101     //Static, for get max IntelMetadataBuffer size
102     static uint32_t GetMaxBufferSize();
103 
104 private:
105     IntelMetadataBufferType mType;
106     intptr_t mValue;
107     ValueInfo* mInfo;
108 
109     intptr_t* mExtraValues;
110     uint32_t mExtraValues_Count;
111 
112     uint8_t* mBytes;
113     uint32_t mSize;
114 
115 #ifdef INTEL_VIDEO_XPROC_SHARING
116 public:
117     IMB_Result ShareValue(sp<MemoryBase> mem);
118     IMB_Result ShareValue(sp<GraphicBuffer> gbuffer);
119 
120     IMB_Result GetSessionFlag(uint32_t &sessionflag);
121     IMB_Result SetSessionFlag(uint32_t sessionflag);
122 
123     //Static, for clear context
124     static IMB_Result ClearContext(uint32_t sessionflag, bool isProvider = true);
125 
126     static const uint16_t CAMERA_BASE =    0x0000;
127     static const uint16_t WIDI_BASE =      0x1000;
128     static const uint16_t WEBRTC_BASE =    0x2000;
129     static const uint16_t VIDEOEDIT_BASE = 0x3000;
130 
131    static uint32_t MakeSessionFlag(bool romoteProvider, bool remoteConsumer, uint16_t sindex);
132 
133 private:
134     uint32_t mSessionFlag;
135 #endif
136 
137 };
138 
139 #ifdef INTEL_VIDEO_XPROC_SHARING
140 
141 class IntelBufferSharingService : public BBinder
142 {
143 private:
144     static IntelBufferSharingService *gBufferService;
145 
146 public:
147     static status_t instantiate();
148 
IntelBufferSharingService()149     IntelBufferSharingService(){
150         ALOGI("IntelBufferSharingService instance is created");
151     }
152 
~IntelBufferSharingService()153     ~IntelBufferSharingService(){
154         ALOGI("IntelBufferSharingService instance is destroyed");
155     }
156 
157     status_t onTransact(uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags);
158 };
159 #endif
160 
161 #endif
162 
163