blob: 22e38a5c1455f3699af8971b17297410f4e700bc [file] [log] [blame]
fei.dengf7a0cd32023-08-29 09:36:37 +00001/*
2 * Copyright (C) 2021 Amlogic Corporation.
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#include "drm_plugin.h"
17#include "Logger.h"
18#include "drm_display.h"
19
20#define TAG "rlib:drm_plugin"
21
22DrmPlugin::DrmPlugin()
23{
24 mVideoFormat = VIDEO_FORMAT_UNKNOWN;
25 mIsPip = false;
26 mDrmDisplay = new DrmDisplay(this);
27}
28
29DrmPlugin::~DrmPlugin()
30{
31 if (mDrmDisplay) {
32 delete mDrmDisplay;
33 mDrmDisplay = NULL;
34 }
35}
36
37void DrmPlugin::init()
38{
39 INFO("\n--------------------------------\n"
40 "plugin : drmmeson\n"
41 "ARCH : %s\n"
42 "branch name : %s\n"
43 "git version : %s\n"
44 "change id : %s \n"
45 "ID : %s \n"
46 "last changed: %s\n"
47 "build-time : %s\n"
48 "build-name : %s\n"
49 "--------------------------------\n",
50#if defined(__aarch64__)
51 "arm64",
52#else
53 "arm",
54#endif
55 BRANCH_NAME,
56 GIT_VERSION,
57 COMMIT_CHANGEID,
58 COMMIT_PD,
59 LAST_CHANGED,
60 BUILD_TIME,
61 BUILD_NAME
62 );
63}
64
65void DrmPlugin::release()
66{
67}
68
69void DrmPlugin::setCallback(void *userData, PluginCallback *callback)
70{
71 mUserData = userData;
72 mCallback = callback;
73}
74
75int DrmPlugin::openDisplay()
76{
77 int ret;
78
79 DEBUG("openDisplay");
80
81 return ret;
82}
83
84int DrmPlugin::openWindow()
85{
86 int ret = 0;
87
88 DEBUG("openWindow");
89
90 bool rc = mDrmDisplay->start(mIsPip);
91 if (!rc) {
92 ERROR("drm window open failed");
93 return -1;
94 }
95
96 DEBUG("openWindow,end");
97 return ret;
98}
99
100int DrmPlugin::prepareFrame(RenderBuffer *buffer)
101{
102
103}
104
105int DrmPlugin::displayFrame(RenderBuffer *buffer, int64_t displayTime)
106{
107 mDrmDisplay->displayFrame(buffer, displayTime);
108 return 0;
109}
110
111int DrmPlugin::flush()
112{
113 mDrmDisplay->flush();
114 return 0;
115}
116
117int DrmPlugin::pause()
118{
119 mDrmDisplay->pause();
120 return 0;
121}
122int DrmPlugin::resume()
123{
124 mDrmDisplay->resume();
125 return 0;
126}
127
128int DrmPlugin::closeDisplay()
129{
130 return 0;
131}
132
133int DrmPlugin::closeWindow()
134{
135 int ret;
136 mDrmDisplay->stop();
137 return 0;
138}
139
140
141int DrmPlugin::getValue(PluginKey key, void *value)
142{
143 switch (key) {
144 case PLUGIN_KEY_VIDEO_FORMAT: {
145 *(int *)value = mVideoFormat;
146 TRACE("get video format:%d",*(int *)value);
147 } break;
148 case PLUGIN_KEY_VIDEO_PIP: {
149 *(int *)value = (mIsPip == true) ? 1 : 0;
150 };
151 case PLUGIN_KEY_HIDE_VIDEO: {
152 bool isHide = false;
153 if (mDrmDisplay) {
154 isHide = mDrmDisplay->isHideVideo();
155 }
156 *(int *)value = isHide == true? 1: 0;
157 TRACE("get hide video:%d",*(int *)value);
158 } break;
159 }
160
161 return 0;
162}
163
164int DrmPlugin::setValue(PluginKey key, void *value)
165{
166 switch (key) {
167 case PLUGIN_KEY_WINDOW_SIZE: {
168 RenderRect* rect = static_cast<RenderRect*>(value);
169 if (mDrmDisplay) {
170 mDrmDisplay->setWindowSize(rect->x, rect->y, rect->w, rect->h);
171 }
172 } break;
173 case PLUGIN_KEY_FRAME_SIZE: {
174 RenderFrameSize * frameSize = static_cast<RenderFrameSize * >(value);
175 if (mDrmDisplay) {
176 mDrmDisplay->setFrameSize(frameSize->width, frameSize->height);
177 }
178 } break;
179 case PLUGIN_KEY_VIDEO_FORMAT: {
180 int format = *(int *)(value);
181 mVideoFormat = (RenderVideoFormat) format;
182 DEBUG("Set video format :%d",mVideoFormat);
183 if (mDrmDisplay) {
184 mDrmDisplay->setVideoFormat(mVideoFormat);
185 }
186 } break;
187 case PLUGIN_KEY_VIDEO_PIP: {
188 int pip = *(int *) (value);
189 mIsPip = pip > 0? true:false;
190 };
191 case PLUGIN_KEY_IMMEDIATELY_OUTPUT: {
192 bool immediately = (*(int *)(value)) > 0? true: false;
193 DEBUG( "Set immediately output:%d",immediately);
194 if (mDrmDisplay) {
195 mDrmDisplay->setImmediatelyOutout(immediately);
196 }
197 } break;
198 case PLUGIN_KEY_HIDE_VIDEO: {
199 int hide = *(int *)(value);
200 if (mDrmDisplay) {
201 mDrmDisplay->setHideVideo(hide > 0? true:false);
202 }
203 } break;
204 case PLUGIN_KEY_KEEP_LAST_FRAME: {
205 int keep = *(int *) (value);
206 bool keepLastFrame = keep > 0? true:false;
207 DEBUG("Set keep last frame :%d",keepLastFrame);
208 if (mDrmDisplay) {
209 mDrmDisplay->setKeepLastFrame(keepLastFrame);
210 }
211 } break;
212 }
213 return 0;
214}
215
216void DrmPlugin::handleBufferRelease(RenderBuffer *buffer)
217{
218 if (mCallback) {
219 mCallback->doBufferReleaseCallback(mUserData, (void *)buffer);
220 }
221}
222
223void DrmPlugin::handleFrameDisplayed(RenderBuffer *buffer)
224{
225 if (mCallback) {
226 mCallback->doBufferDisplayedCallback(mUserData, (void *)buffer);
227 }
228}
229
230void DrmPlugin::handleFrameDropped(RenderBuffer *buffer)
231{
232 if (mCallback) {
233 mCallback->doBufferDropedCallback(mUserData, (void *)buffer);
234 }
235}
236
237void DrmPlugin::handleMsgNotify(int type, void *detail)
238{
239 if (mCallback) {
240 mCallback->doMsgCallback(mUserData, type, detail);
241 }
242}
243
244void *makePluginInstance(int id)
245{
246 char *env = getenv("VIDEO_RENDER_LOG_LEVEL");
247 if (env) {
248 int level = atoi(env);
249 Logger_set_level(level);
250 INFO("VIDEO_RENDER_LOG_LEVEL=%d",level);
251 }
252 DrmPlugin *drmPlugin = new DrmPlugin();
253 return static_cast<void *>(drmPlugin);
254}
255
256void destroyPluginInstance(void * plugin)
257{
258 DrmPlugin *pluginInstance = static_cast<DrmPlugin *>(plugin);
259 delete pluginInstance;
260}