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