• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright (C) 2019 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 #include <fcntl.h>
18 #include <unistd.h>
19 #include <sys/types.h>
20 #include <sys/stat.h>
21 #include <binder/IServiceManager.h>
22 #include <media/IMediaPlayerService.h>
23 #include <media/IOMX.h>
24 #include <media/OMXBuffer.h>
25 #include <ui/GraphicBuffer.h>
26 #include <android/hardware/media/omx/1.0/IOmx.h>
27 #include <android/hardware/media/omx/1.0/IOmxNode.h>
28 #include <android/hardware/media/omx/1.0/IOmxObserver.h>
29 #include <android/hardware/media/omx/1.0/types.h>
30 #include <android/hidl/allocator/1.0/IAllocator.h>
31 #include <android/hidl/memory/1.0/IMapper.h>
32 #include <android/hidl/memory/1.0/IMemory.h>
33 #include <android/hardware/media/omx/1.0/IGraphicBufferSource.h>
34 #include <android/IOMXBufferSource.h>
35 #include <media/omx/1.0/WOmx.h>
36 #include <binder/MemoryDealer.h>
37 #include "media/hardware/HardwareAPI.h"
38 #include "OMX_Component.h"
39 #include <binder/ProcessState.h>
40 #include <media/stagefright/foundation/ALooper.h>
41 #include <utils/List.h>
42 #include <utils/Vector.h>
43 #include <utils/threads.h>
44 #include <inttypes.h>
45 #include <utils/Log.h>
46 #include <media/stagefright/OMXClient.h>
47 
48 #define DEFAULT_TIMEOUT   5000000
49 #define OMX_UTILS_IP_PORT 0
50 #define OMX_UTILS_OP_PORT 1
51 
52 using namespace android;
53 typedef hidl::allocator::V1_0::IAllocator IAllocator;
54 
55 template<class T>
InitOMXParams(T * params)56 static void InitOMXParams(T *params) {
57     params->nSize = sizeof(T);
58     params->nVersion.s.nVersionMajor = 1;
59     params->nVersion.s.nVersionMinor = 0;
60     params->nVersion.s.nRevision = 0;
61     params->nVersion.s.nStep = 0;
62 }
63 struct Buffer {
64     IOMX::buffer_id mID;
65     sp<IMemory> mMemory;
66     hidl_memory mHidlMemory;
67     uint32_t mFlags;
68 };
69 
70 status_t omxUtilsInit(char *codecName);
71 status_t omxUtilsGetParameter(int portIndex,
72                               OMX_PARAM_PORTDEFINITIONTYPE *params);
73 status_t omxUtilsSetParameter(int portIndex,
74                               OMX_PARAM_PORTDEFINITIONTYPE *params);
75 status_t omxUtilsSetPortMode(OMX_U32 port_index, IOMX::PortMode mode);
76 status_t omxUtilsUseBuffer(OMX_U32 portIndex, const OMXBuffer &omxBuf,
77                            android::IOMX::buffer_id *buffer);
78 status_t omxUtilsSendCommand(OMX_COMMANDTYPE cmd, OMX_S32 param);
79 status_t omxUtilsEmptyBuffer(android::IOMX::buffer_id buffer,
80                              const OMXBuffer &omxBuf, OMX_U32 flags,
81                              OMX_TICKS timestamp, int fenceFd);
82 status_t omxUtilsFillBuffer(android::IOMX::buffer_id buffer,
83                             const OMXBuffer &omxBuf, int fenceFd);
84 status_t omxUtilsFreeBuffer(OMX_U32 portIndex,
85                             android::IOMX::buffer_id buffer);
86 status_t omxUtilsFreeNode();
87 status_t dequeueMessageForNode(omx_message *msg, int64_t timeoutUs);
88 void omxExitOnError(status_t ret);
89