fei.deng | f7a0cd3 | 2023-08-29 09:36:37 +0000 | [diff] [blame] | 1 | /* |
| 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 | */ |
fei.deng | dd910ef | 2024-06-07 10:25:30 +0800 | [diff] [blame] | 16 | #include <fcntl.h> |
| 17 | #include <string.h> |
fei.deng | f7a0cd3 | 2023-08-29 09:36:37 +0000 | [diff] [blame] | 18 | #include "wayland_plugin.h" |
| 19 | #include "wayland_display.h" |
| 20 | #include "Logger.h" |
| 21 | #include "Times.h" |
fei.deng | b9a1a57 | 2023-09-13 01:33:57 +0000 | [diff] [blame] | 22 | #include "ErrorCode.h" |
fei.deng | f7a0cd3 | 2023-08-29 09:36:37 +0000 | [diff] [blame] | 23 | |
| 24 | #define TAG "rlib:wayland_plugin" |
| 25 | |
fei.deng | b9a1a57 | 2023-09-13 01:33:57 +0000 | [diff] [blame] | 26 | WaylandPlugin::WaylandPlugin(int logCatgory) |
| 27 | : mRenderLock("renderlock"), |
| 28 | mLogCategory(logCatgory) |
fei.deng | f7a0cd3 | 2023-08-29 09:36:37 +0000 | [diff] [blame] | 29 | { |
fei.deng | b9a1a57 | 2023-09-13 01:33:57 +0000 | [diff] [blame] | 30 | mDisplay = new WaylandDisplay(this, logCatgory); |
fei.deng | f7a0cd3 | 2023-08-29 09:36:37 +0000 | [diff] [blame] | 31 | mQueue = new Tls::Queue(); |
| 32 | mPaused = false; |
| 33 | mImmediatelyOutput = false; |
| 34 | } |
| 35 | |
| 36 | WaylandPlugin::~WaylandPlugin() |
| 37 | { |
| 38 | if (mDisplay) { |
| 39 | delete mDisplay; |
| 40 | } |
| 41 | if (mQueue) { |
| 42 | mQueue->flush(); |
| 43 | delete mQueue; |
| 44 | mQueue = NULL; |
| 45 | } |
fei.deng | b9a1a57 | 2023-09-13 01:33:57 +0000 | [diff] [blame] | 46 | TRACE(mLogCategory,"desconstruct"); |
fei.deng | f7a0cd3 | 2023-08-29 09:36:37 +0000 | [diff] [blame] | 47 | } |
| 48 | |
| 49 | void WaylandPlugin::init() |
| 50 | { |
fei.deng | b9a1a57 | 2023-09-13 01:33:57 +0000 | [diff] [blame] | 51 | INFO(mLogCategory,"\n--------------------------------\n" |
fei.deng | f7a0cd3 | 2023-08-29 09:36:37 +0000 | [diff] [blame] | 52 | "plugin : weston\n" |
| 53 | "ARCH : %s\n" |
| 54 | "branch name : %s\n" |
| 55 | "git version : %s\n" |
| 56 | "change id : %s \n" |
| 57 | "ID : %s \n" |
| 58 | "last changed: %s\n" |
| 59 | "build-time : %s\n" |
| 60 | "build-name : %s\n" |
| 61 | "--------------------------------\n", |
| 62 | #if defined(__aarch64__) |
| 63 | "arm64", |
| 64 | #else |
| 65 | "arm", |
| 66 | #endif |
| 67 | BRANCH_NAME, |
| 68 | GIT_VERSION, |
| 69 | COMMIT_CHANGEID, |
| 70 | COMMIT_PD, |
| 71 | LAST_CHANGED, |
| 72 | BUILD_TIME, |
| 73 | BUILD_NAME |
| 74 | ); |
| 75 | } |
| 76 | |
| 77 | void WaylandPlugin::release() |
| 78 | { |
| 79 | } |
| 80 | |
| 81 | void WaylandPlugin::setCallback(void *userData, PluginCallback *callback) |
| 82 | { |
| 83 | mUserData = userData; |
| 84 | mCallback = callback; |
| 85 | } |
| 86 | |
| 87 | int WaylandPlugin::openDisplay() |
| 88 | { |
| 89 | int ret; |
| 90 | |
fei.deng | b9a1a57 | 2023-09-13 01:33:57 +0000 | [diff] [blame] | 91 | Tls::Mutex::Autolock _l(mRenderLock); |
| 92 | DEBUG(mLogCategory,"openDisplay"); |
fei.deng | f7a0cd3 | 2023-08-29 09:36:37 +0000 | [diff] [blame] | 93 | ret = mDisplay->openDisplay(); |
fei.deng | b9a1a57 | 2023-09-13 01:33:57 +0000 | [diff] [blame] | 94 | if (ret != NO_ERROR) { |
| 95 | ERROR(mLogCategory,"Error open display"); |
| 96 | return ret; |
fei.deng | f7a0cd3 | 2023-08-29 09:36:37 +0000 | [diff] [blame] | 97 | } |
fei.deng | b9a1a57 | 2023-09-13 01:33:57 +0000 | [diff] [blame] | 98 | DEBUG(mLogCategory,"openDisplay end"); |
| 99 | return ret; |
fei.deng | f7a0cd3 | 2023-08-29 09:36:37 +0000 | [diff] [blame] | 100 | } |
| 101 | |
| 102 | int WaylandPlugin::openWindow() |
| 103 | { |
fei.deng | b9a1a57 | 2023-09-13 01:33:57 +0000 | [diff] [blame] | 104 | Tls::Mutex::Autolock _l(mRenderLock); |
fei.deng | f7a0cd3 | 2023-08-29 09:36:37 +0000 | [diff] [blame] | 105 | /* if weston can't support pts feature, |
| 106 | * we should create a post buffer thread to |
| 107 | * send buffer by mono time |
| 108 | */ |
fei.deng | 640c3c9 | 2024-04-12 08:31:19 +0000 | [diff] [blame] | 109 | WaylandDisplay::AmlConfigAPIList *amlconfig = mDisplay->getAmlConfigAPIList(); |
| 110 | if (!amlconfig->enableSetPts) { |
fei.deng | dd910ef | 2024-06-07 10:25:30 +0800 | [diff] [blame] | 111 | DEBUG(mLogCategory,"run frame post thread"); |
fei.deng | f7a0cd3 | 2023-08-29 09:36:37 +0000 | [diff] [blame] | 112 | setThreadPriority(50); |
| 113 | run("waylandPostThread"); |
| 114 | } |
fei.deng | b9a1a57 | 2023-09-13 01:33:57 +0000 | [diff] [blame] | 115 | return NO_ERROR; |
fei.deng | f7a0cd3 | 2023-08-29 09:36:37 +0000 | [diff] [blame] | 116 | } |
| 117 | |
| 118 | int WaylandPlugin::prepareFrame(RenderBuffer *buffer) |
| 119 | { |
| 120 | mDisplay->prepareFrameBuffer(buffer); |
fei.deng | b9a1a57 | 2023-09-13 01:33:57 +0000 | [diff] [blame] | 121 | return NO_ERROR; |
fei.deng | f7a0cd3 | 2023-08-29 09:36:37 +0000 | [diff] [blame] | 122 | } |
| 123 | |
| 124 | int WaylandPlugin::displayFrame(RenderBuffer *buffer, int64_t displayTime) |
| 125 | { |
| 126 | /* if weston can't support pts feature, |
| 127 | * push buffer to queue, the buffer will send to |
| 128 | * weston in post thread |
| 129 | */ |
fei.deng | 640c3c9 | 2024-04-12 08:31:19 +0000 | [diff] [blame] | 130 | WaylandDisplay::AmlConfigAPIList *amlconfig = mDisplay->getAmlConfigAPIList(); |
| 131 | if (!amlconfig->enableSetPts) { |
fei.deng | f7a0cd3 | 2023-08-29 09:36:37 +0000 | [diff] [blame] | 132 | buffer->time = displayTime; |
| 133 | mQueue->push(buffer); |
fei.deng | dd910ef | 2024-06-07 10:25:30 +0800 | [diff] [blame] | 134 | DEBUG(mLogCategory,"queue size:%d,pts:%lld us",mQueue->getCnt(),buffer->pts/1000); |
fei.deng | f7a0cd3 | 2023-08-29 09:36:37 +0000 | [diff] [blame] | 135 | } else { |
fei.deng | ae8c90a | 2024-06-27 13:39:53 +0800 | [diff] [blame] | 136 | buffer->time = displayTime; |
fei.deng | f7a0cd3 | 2023-08-29 09:36:37 +0000 | [diff] [blame] | 137 | mDisplay->displayFrameBuffer(buffer, displayTime); |
| 138 | } |
fei.deng | b9a1a57 | 2023-09-13 01:33:57 +0000 | [diff] [blame] | 139 | return NO_ERROR; |
fei.deng | f7a0cd3 | 2023-08-29 09:36:37 +0000 | [diff] [blame] | 140 | } |
| 141 | |
| 142 | void WaylandPlugin::queueFlushCallback(void *userdata,void *data) |
| 143 | { |
| 144 | WaylandPlugin* plugin = static_cast<WaylandPlugin *>(userdata); |
| 145 | plugin->handleFrameDropped((RenderBuffer *)data); |
| 146 | plugin->handleBufferRelease((RenderBuffer *)data); |
| 147 | } |
| 148 | |
| 149 | int WaylandPlugin::flush() |
| 150 | { |
| 151 | RenderBuffer *entity; |
| 152 | mQueue->flushAndCallback(this, WaylandPlugin::queueFlushCallback); |
| 153 | mDisplay->flushBuffers(); |
fei.deng | b9a1a57 | 2023-09-13 01:33:57 +0000 | [diff] [blame] | 154 | return NO_ERROR; |
fei.deng | f7a0cd3 | 2023-08-29 09:36:37 +0000 | [diff] [blame] | 155 | } |
| 156 | |
| 157 | int WaylandPlugin::pause() |
| 158 | { |
fei.deng | 19b4869 | 2024-08-13 14:17:55 +0800 | [diff] [blame^] | 159 | /*pause and resume can cause frame dropped. |
| 160 | those frames ready to send to weston in queue will drop |
| 161 | when resume*/ |
| 162 | //mPaused = true; |
fei.deng | b9a1a57 | 2023-09-13 01:33:57 +0000 | [diff] [blame] | 163 | return NO_ERROR; |
fei.deng | f7a0cd3 | 2023-08-29 09:36:37 +0000 | [diff] [blame] | 164 | } |
| 165 | int WaylandPlugin::resume() |
| 166 | { |
fei.deng | 19b4869 | 2024-08-13 14:17:55 +0800 | [diff] [blame^] | 167 | //mPaused = false; |
fei.deng | b9a1a57 | 2023-09-13 01:33:57 +0000 | [diff] [blame] | 168 | return NO_ERROR; |
fei.deng | f7a0cd3 | 2023-08-29 09:36:37 +0000 | [diff] [blame] | 169 | } |
| 170 | |
| 171 | int WaylandPlugin::closeDisplay() |
| 172 | { |
| 173 | RenderBuffer *entity; |
fei.deng | b9a1a57 | 2023-09-13 01:33:57 +0000 | [diff] [blame] | 174 | Tls::Mutex::Autolock _l(mRenderLock); |
fei.deng | f7a0cd3 | 2023-08-29 09:36:37 +0000 | [diff] [blame] | 175 | mDisplay->closeDisplay(); |
fei.deng | f7a0cd3 | 2023-08-29 09:36:37 +0000 | [diff] [blame] | 176 | |
fei.deng | b9a1a57 | 2023-09-13 01:33:57 +0000 | [diff] [blame] | 177 | return NO_ERROR; |
fei.deng | f7a0cd3 | 2023-08-29 09:36:37 +0000 | [diff] [blame] | 178 | } |
| 179 | |
| 180 | int WaylandPlugin::closeWindow() |
| 181 | { |
fei.deng | b9a1a57 | 2023-09-13 01:33:57 +0000 | [diff] [blame] | 182 | Tls::Mutex::Autolock _l(mRenderLock); |
fei.deng | f7a0cd3 | 2023-08-29 09:36:37 +0000 | [diff] [blame] | 183 | if (isRunning()) { |
fei.deng | b9a1a57 | 2023-09-13 01:33:57 +0000 | [diff] [blame] | 184 | DEBUG(mLogCategory,"stop frame post thread"); |
fei.deng | f7a0cd3 | 2023-08-29 09:36:37 +0000 | [diff] [blame] | 185 | requestExitAndWait(); |
| 186 | } |
fei.deng | dd910ef | 2024-06-07 10:25:30 +0800 | [diff] [blame] | 187 | mQueue->flushAndCallback(this, WaylandPlugin::queueFlushCallback); |
fei.deng | b9a1a57 | 2023-09-13 01:33:57 +0000 | [diff] [blame] | 188 | return NO_ERROR; |
fei.deng | f7a0cd3 | 2023-08-29 09:36:37 +0000 | [diff] [blame] | 189 | } |
| 190 | |
| 191 | |
| 192 | int WaylandPlugin::getValue(PluginKey key, void *value) |
| 193 | { |
| 194 | switch (key) { |
| 195 | case PLUGIN_KEY_SELECT_DISPLAY_OUTPUT: { |
| 196 | *(int *)(value) = mDisplay->getDisplayOutput(); |
fei.deng | b9a1a57 | 2023-09-13 01:33:57 +0000 | [diff] [blame] | 197 | TRACE(mLogCategory,"get select display output:%d",*(int *)value); |
fei.deng | f7a0cd3 | 2023-08-29 09:36:37 +0000 | [diff] [blame] | 198 | } break; |
fei.deng | f1f5fc3 | 2023-12-06 06:22:20 +0000 | [diff] [blame] | 199 | case PLUGIN_KEY_CURRENT_OUTPUT: { |
| 200 | *(int *)(value) = mDisplay->getCurrentOutputCrtcIndex(); |
| 201 | //DEBUG(mLogCategory,"get current crtc output index:%d",*(int *)value); |
| 202 | } break; |
fei.deng | f7a0cd3 | 2023-08-29 09:36:37 +0000 | [diff] [blame] | 203 | } |
fei.deng | b9a1a57 | 2023-09-13 01:33:57 +0000 | [diff] [blame] | 204 | return NO_ERROR; |
fei.deng | f7a0cd3 | 2023-08-29 09:36:37 +0000 | [diff] [blame] | 205 | } |
| 206 | |
| 207 | int WaylandPlugin::setValue(PluginKey key, void *value) |
| 208 | { |
| 209 | switch (key) { |
| 210 | case PLUGIN_KEY_WINDOW_SIZE: { |
| 211 | RenderRect* rect = static_cast<RenderRect*>(value); |
| 212 | if (mDisplay) { |
| 213 | mDisplay->setWindowSize(rect->x, rect->y, rect->w, rect->h); |
| 214 | } |
| 215 | } break; |
| 216 | case PLUGIN_KEY_FRAME_SIZE: { |
| 217 | RenderFrameSize * frameSize = static_cast<RenderFrameSize * >(value); |
| 218 | if (mDisplay) { |
| 219 | mDisplay->setFrameSize(frameSize->width, frameSize->height); |
| 220 | } |
| 221 | } break; |
| 222 | case PLUGIN_KEY_VIDEO_FORMAT: { |
| 223 | int videoFormat = *(int *)(value); |
fei.deng | b9a1a57 | 2023-09-13 01:33:57 +0000 | [diff] [blame] | 224 | DEBUG(mLogCategory,"Set video format :%d",videoFormat); |
fei.deng | f7a0cd3 | 2023-08-29 09:36:37 +0000 | [diff] [blame] | 225 | mDisplay->setVideoBufferFormat((RenderVideoFormat)videoFormat); |
| 226 | } break; |
| 227 | case PLUGIN_KEY_SELECT_DISPLAY_OUTPUT: { |
| 228 | int outputIndex = *(int *)(value); |
fei.deng | b9a1a57 | 2023-09-13 01:33:57 +0000 | [diff] [blame] | 229 | DEBUG(mLogCategory,"Set select display output :%d",outputIndex); |
fei.deng | f7a0cd3 | 2023-08-29 09:36:37 +0000 | [diff] [blame] | 230 | mDisplay->setDisplayOutput(outputIndex); |
| 231 | } break; |
| 232 | case PLUGIN_KEY_VIDEO_PIP: { |
| 233 | int pip = *(int *) (value); |
| 234 | pip = pip > 0? 1: 0; |
| 235 | mDisplay->setPip(pip); |
| 236 | } break; |
| 237 | case PLUGIN_KEY_IMMEDIATELY_OUTPUT: { |
| 238 | bool mImmediatelyOutput = (*(int *)(value)) > 0? true: false; |
fei.deng | b9a1a57 | 2023-09-13 01:33:57 +0000 | [diff] [blame] | 239 | DEBUG(mLogCategory, "Set immediately output:%d",mImmediatelyOutput); |
fei.deng | f7a0cd3 | 2023-08-29 09:36:37 +0000 | [diff] [blame] | 240 | } break; |
fei.deng | 640c3c9 | 2024-04-12 08:31:19 +0000 | [diff] [blame] | 241 | case PLUGIN_KEY_KEEP_LAST_FRAME: { |
| 242 | int keep = *(int *) (value); |
| 243 | DEBUG(mLogCategory, "Set keep last frame:%d",keep); |
| 244 | mDisplay->setKeepLastFrame(keep); |
| 245 | } break; |
fei.deng | a4abbd5 | 2024-07-11 19:17:50 +0800 | [diff] [blame] | 246 | case PLUGIN_KEY_FORCE_ASPECT_RATIO: { |
| 247 | int forceAspectRatio = *(int *)(value); |
| 248 | DEBUG(mLogCategory, "force aspect ratio:%d, TODO ",forceAspectRatio); |
| 249 | } break; |
| 250 | case PLUGIN_KEY_PIXEL_ASPECT_RATIO: { |
| 251 | double ratio = *(double *)(value); |
| 252 | INFO(mLogCategory,"pixel aspect ratio :%f",ratio); |
| 253 | mDisplay->setPixelAspectRatio((double)ratio); |
| 254 | } break; |
fei.deng | 6c42523 | 2024-07-19 16:15:31 +0800 | [diff] [blame] | 255 | case PLUGIN_KEY_VIDEO_FRAME_RATE: { |
| 256 | RenderFraction * fraction = static_cast<RenderFraction*>(value); |
| 257 | INFO(mLogCategory,"frame rate,num:%d,denom:%d",fraction->num,fraction->denom); |
| 258 | mDisplay->setFrameRate(fraction->num, fraction->denom); |
| 259 | } break; |
fei.deng | f7a0cd3 | 2023-08-29 09:36:37 +0000 | [diff] [blame] | 260 | } |
| 261 | return 0; |
| 262 | } |
| 263 | |
| 264 | void WaylandPlugin::handleBufferRelease(RenderBuffer *buffer) |
| 265 | { |
| 266 | if (mCallback) { |
| 267 | mCallback->doBufferReleaseCallback(mUserData, (void *)buffer); |
| 268 | } |
| 269 | } |
| 270 | |
| 271 | void WaylandPlugin::handleFrameDisplayed(RenderBuffer *buffer) |
| 272 | { |
| 273 | if (mCallback) { |
| 274 | mCallback->doBufferDisplayedCallback(mUserData, (void *)buffer); |
| 275 | } |
| 276 | } |
| 277 | |
| 278 | void WaylandPlugin::handleFrameDropped(RenderBuffer *buffer) |
| 279 | { |
| 280 | if (mCallback) { |
| 281 | mCallback->doBufferDropedCallback(mUserData, (void *)buffer); |
| 282 | } |
| 283 | } |
| 284 | |
fei.deng | 3287c08 | 2024-04-23 09:29:22 +0000 | [diff] [blame] | 285 | void WaylandPlugin::handleMsgNotify(int type, void *detail) |
| 286 | { |
| 287 | if (mCallback) { |
| 288 | mCallback->doMsgCallback(mUserData, type, detail); |
| 289 | } |
| 290 | } |
| 291 | |
fei.deng | f7a0cd3 | 2023-08-29 09:36:37 +0000 | [diff] [blame] | 292 | void WaylandPlugin::readyToRun() |
| 293 | { |
| 294 | } |
| 295 | |
| 296 | bool WaylandPlugin::threadLoop() |
| 297 | { |
| 298 | RenderBuffer *curFrameEntity = NULL; |
| 299 | RenderBuffer *expiredFrameEntity = NULL; |
| 300 | int64_t nowMonotime = Tls::Times::getSystemTimeUs(); |
| 301 | |
| 302 | //if queue is empty or paused, loop next |
| 303 | if (mQueue->isEmpty() || mPaused) { |
| 304 | goto tag_next; |
| 305 | } |
| 306 | |
| 307 | //if weston obtains a buffer rendering,we can't send buffer to weston |
| 308 | if (mDisplay->isRedrawingPending()) { |
| 309 | goto tag_next; |
| 310 | } |
| 311 | |
| 312 | //we output video frame asap |
| 313 | if (mImmediatelyOutput) { |
| 314 | //pop the peeked frame |
| 315 | mQueue->pop((void **)&expiredFrameEntity); |
| 316 | goto tag_post; |
| 317 | } |
| 318 | |
| 319 | while (mQueue->peek((void **)&curFrameEntity, 0) == Q_OK) |
| 320 | { |
| 321 | //no frame expired,loop next |
| 322 | if (nowMonotime < curFrameEntity->time) { |
| 323 | break; |
| 324 | } |
| 325 | |
| 326 | //pop the peeked frame |
| 327 | mQueue->pop((void **)&curFrameEntity); |
| 328 | |
| 329 | //drop last expired frame,got a new expired frame |
| 330 | if (expiredFrameEntity) { |
fei.deng | b9a1a57 | 2023-09-13 01:33:57 +0000 | [diff] [blame] | 331 | WARNING(mLogCategory,"drop,now:%lld,display:%lld(pts:%lld ms),n-d:%lld ms", |
fei.deng | f7a0cd3 | 2023-08-29 09:36:37 +0000 | [diff] [blame] | 332 | nowMonotime,expiredFrameEntity->time,expiredFrameEntity->pts/1000000, |
| 333 | (nowMonotime - expiredFrameEntity->time)/1000); |
| 334 | handleFrameDropped(expiredFrameEntity); |
| 335 | handleBufferRelease(expiredFrameEntity); |
| 336 | expiredFrameEntity = NULL; |
| 337 | } |
| 338 | |
| 339 | expiredFrameEntity = curFrameEntity; |
| 340 | } |
| 341 | |
| 342 | tag_post: |
| 343 | if (!expiredFrameEntity) { |
| 344 | //TRACE(mLogCategory,"no frame expire"); |
| 345 | goto tag_next; |
| 346 | } |
| 347 | |
| 348 | if (mDisplay) { |
fei.deng | dd910ef | 2024-06-07 10:25:30 +0800 | [diff] [blame] | 349 | TRACE(mLogCategory,"post,now:%lld,display:%lld(pts:%lld ms),n-d::%lld ms, size:%d", |
fei.deng | f7a0cd3 | 2023-08-29 09:36:37 +0000 | [diff] [blame] | 350 | nowMonotime,expiredFrameEntity->time,expiredFrameEntity->pts/1000000, |
fei.deng | dd910ef | 2024-06-07 10:25:30 +0800 | [diff] [blame] | 351 | (nowMonotime - expiredFrameEntity->time)/1000,mQueue->getCnt()); |
fei.deng | f7a0cd3 | 2023-08-29 09:36:37 +0000 | [diff] [blame] | 352 | mDisplay->displayFrameBuffer(expiredFrameEntity, expiredFrameEntity->time); |
| 353 | } |
| 354 | |
| 355 | tag_next: |
| 356 | usleep(4*1000); |
| 357 | return true; |
| 358 | } |
| 359 | |
| 360 | void *makePluginInstance(int id) |
| 361 | { |
fei.deng | dd910ef | 2024-06-07 10:25:30 +0800 | [diff] [blame] | 362 | int fd= -1; |
| 363 | const char *levelPath = "/run/rlib_plugin_level"; |
| 364 | |
fei.deng | b9a1a57 | 2023-09-13 01:33:57 +0000 | [diff] [blame] | 365 | int category =Logger_init(id); |
fei.deng | c467785 | 2023-10-09 07:21:04 +0000 | [diff] [blame] | 366 | char *env = getenv("VIDEO_RENDER_PLUGIN_LOG_LEVEL"); |
fei.deng | f7a0cd3 | 2023-08-29 09:36:37 +0000 | [diff] [blame] | 367 | if (env) { |
| 368 | int level = atoi(env); |
| 369 | Logger_set_level(level); |
fei.deng | dd910ef | 2024-06-07 10:25:30 +0800 | [diff] [blame] | 370 | INFO(category,"env set VIDEO_RENDER_PLUGIN_LOG_LEVEL=%d",level); |
fei.deng | f7a0cd3 | 2023-08-29 09:36:37 +0000 | [diff] [blame] | 371 | } |
fei.deng | dd910ef | 2024-06-07 10:25:30 +0800 | [diff] [blame] | 372 | |
| 373 | //get log level from /run/rlib_plugin_level |
| 374 | fd= open(levelPath, O_RDONLY|O_CLOEXEC); |
| 375 | if ( fd >= 0 ) |
| 376 | { |
| 377 | char valstr[64]; |
| 378 | uint32_t val= 0; |
| 379 | int nRead; |
| 380 | |
| 381 | memset(valstr, 0, sizeof(valstr)); |
| 382 | nRead = read(fd, valstr, sizeof(valstr) - 1); |
| 383 | valstr[strlen(valstr)] = '\0'; |
| 384 | if (sscanf(valstr, "%u", &val) > 0) |
| 385 | { |
| 386 | Logger_set_level(val); |
| 387 | INFO(category,"set VIDEO_RENDER_LOG_LEVEL=%d",val); |
| 388 | } |
| 389 | close(fd); |
| 390 | fd = -1; |
| 391 | } |
fei.deng | dd910ef | 2024-06-07 10:25:30 +0800 | [diff] [blame] | 392 | |
fei.deng | b9a1a57 | 2023-09-13 01:33:57 +0000 | [diff] [blame] | 393 | WaylandPlugin *pluginInstance = new WaylandPlugin(category); |
fei.deng | f7a0cd3 | 2023-08-29 09:36:37 +0000 | [diff] [blame] | 394 | return static_cast<void *>(pluginInstance); |
| 395 | } |
| 396 | |
| 397 | void destroyPluginInstance(void * plugin) |
| 398 | { |
fei.deng | b9a1a57 | 2023-09-13 01:33:57 +0000 | [diff] [blame] | 399 | int category; |
| 400 | |
fei.deng | f7a0cd3 | 2023-08-29 09:36:37 +0000 | [diff] [blame] | 401 | WaylandPlugin *pluginInstance = static_cast<WaylandPlugin *>(plugin); |
fei.deng | b9a1a57 | 2023-09-13 01:33:57 +0000 | [diff] [blame] | 402 | category = pluginInstance->getLogCategory(); |
fei.deng | f7a0cd3 | 2023-08-29 09:36:37 +0000 | [diff] [blame] | 403 | delete pluginInstance; |
fei.deng | b9a1a57 | 2023-09-13 01:33:57 +0000 | [diff] [blame] | 404 | Logger_exit(category); |
fei.deng | f7a0cd3 | 2023-08-29 09:36:37 +0000 | [diff] [blame] | 405 | } |