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 __VIDEO_ENCODER_UTILS_H__
18 #define __VIDEO_ENCODER_UTILS_H__
19 #include <va/va.h>
20 #include <va/va_tpi.h>
21 #include "VideoEncoderDef.h"
22 #include "IntelMetadataBuffer.h"
23 #ifdef IMG_GFX
24 #include <hardware/gralloc.h>
25 #endif
26 
27 #define MAP_ACTION_COPY         0x00000001  //mem copy
28 #define MAP_ACTION_ALIGN64      0x00000002  //align 64
29 #define MAP_ACTION_COLORCONVERT 0x00000004  //color convert
30 #define MAP_ACTION_RESIZE       0x00000008  //resize
31 
32 class VASurfaceMap {
33 public:
34     VASurfaceMap(VADisplay display, int hwcap);
35     ~VASurfaceMap();
36 
37     Encode_Status doMapping();
getVASurface()38     VASurfaceID getVASurface() {return mVASurface;}
getValue()39     intptr_t getValue() {return mValue;}
getValueInfo()40     ValueInfo* getValueInfo() {return &mVinfo;}
41 
setVASurface(VASurfaceID surface)42     void setVASurface(VASurfaceID surface) {mVASurface = surface;}
setValue(intptr_t value)43     void setValue(intptr_t value) {mValue = value;}
setValueInfo(ValueInfo & vinfo)44     void setValueInfo(ValueInfo& vinfo) {memcpy(&mVinfo, &vinfo, sizeof(ValueInfo));}
setTracked()45     void setTracked() {mTracked = true;}
setAction(int32_t action)46     void setAction(int32_t action) {mAction = action;}
47 
48 private:
49     Encode_Status doActionCopy();
50     Encode_Status doActionColConv();
51     Encode_Status MappingToVASurface();
52     Encode_Status MappingSurfaceID(intptr_t value);
53     Encode_Status MappingGfxHandle(intptr_t value);
54     Encode_Status MappingKbufHandle(intptr_t value);
55     Encode_Status MappingMallocPTR(intptr_t value);
56     VASurfaceID CreateSurfaceFromExternalBuf(intptr_t value, ValueInfo& vinfo);
57 
58     VADisplay mVADisplay;
59 
60     intptr_t mValue;
61 
62     VASurfaceID mVASurface;
63     int32_t mVASurfaceWidth;
64     int32_t mVASurfaceHeight;
65     int32_t mVASurfaceStride;
66 
67 //    MetadataBufferType mType;
68 
69     ValueInfo mVinfo;
70     bool mTracked;
71 
72     int32_t mAction;
73 
74     int32_t mSupportedSurfaceMemType;
75 
76 #ifdef IMG_GFX
77     //special for gfx color format converter
78     buffer_handle_t mGfxHandle;
79 #endif
80 };
81 
82 VASurfaceID CreateNewVASurface(VADisplay display, int32_t width, int32_t height);
83 
84 #endif
85 
86