blob: 8c101724aee0e496b76b3785c43a9dd928f125a1 [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#ifndef __WST_CLIENT_PLUGIN_H__
17#define __WST_CLIENT_PLUGIN_H__
18#include <unordered_map>
19#include "render_plugin.h"
20#include "wstclient_wayland.h"
21#include "wstclient_socket.h"
22#include "wst_essos.h"
23#include <mutex>
24
25class WstClientPlugin : public RenderPlugin
26{
27 public:
fei.dengb9a1a572023-09-13 01:33:57 +000028 WstClientPlugin(int logCategory);
fei.dengf7a0cd32023-08-29 09:36:37 +000029 virtual ~WstClientPlugin();
30 virtual void init();
31 virtual void release();
32 void setCallback(void *userData, PluginCallback *callback);
33 virtual int openDisplay();
34 virtual int openWindow();
35 virtual int prepareFrame(RenderBuffer *buffer);
36 virtual int displayFrame(RenderBuffer *buffer, int64_t displayTime);
37 virtual int flush();
38 virtual int pause();
39 virtual int resume();
40 virtual int closeDisplay();
41 virtual int closeWindow();
42 virtual int getValue(PluginKey key, void *value);
43 virtual int setValue(PluginKey key, void *value);
44 //buffer release callback
45 void handleBufferRelease(RenderBuffer *buffer);
46 //buffer had displayed ,but not release
47 void handleFrameDisplayed(RenderBuffer *buffer);
48 //buffer droped callback
49 void handleFrameDropped(RenderBuffer *buffer);
50 //plugin msg callback
51 void handleMsgNotify(int type, void *detail);
52
53 void onWstSocketEvent(WstEvent *event);
54
55 void setVideoRect(int videoX, int videoY, int videoWidth, int videoHeight);
fei.dengb9a1a572023-09-13 01:33:57 +000056 int getLogCategory() {
57 return mLogCategory;
58 };
fei.dengf7a0cd32023-08-29 09:36:37 +000059 private:
60 typedef struct {
61 bool isSet;
62 bool value;
63 } ConfigValue;
64 /**
65 * @brief Get the Display Frame Buffer Id object
66 *
67 * @param displayTime
68 * @return int > 0 if success, -1 if not found
69 */
70 int getDisplayFrameBufferId(int64_t displayTime);
71 /**
72 * @brief send crop frame rect to server if needed
73 * @return true send ok, false if failed
74 */
75 bool setCropFrameRect();
76 PluginCallback *mCallback;
77 WstClientWayland *mWayland;
78 WstClientSocket *mWstClientSocket;
79 RenderRect mWinRect;
80 bool mSetCropFrameRect;
81 RenderRect mCropFrameRect; //set frame crop size
fei.dengb9a1a572023-09-13 01:33:57 +000082 int mLogCategory;
fei.dengf7a0cd32023-08-29 09:36:37 +000083
84 ConfigValue mKeepLastFrame;
le.hanbf4baf32024-02-28 03:28:11 +000085 ConfigValue mKeepLastFrameOnFlush;
fei.dengf7a0cd32023-08-29 09:36:37 +000086 ConfigValue mHideVideo;
87
88 std::mutex mRenderLock;
89 bool mFullscreen; //default true value to full screen show video
90
91 int mNumDroppedFrames; //the count of dropped frames
92 int mCommitFrameCnt; //the count frames of committing to server
93 int mReadyDisplayFrameCnt; //the count frames of ready to display
94 int64_t mFirstFramePts; //the first display frame pts
95
96 RenderVideoFormat mBufferFormat;
97 std::unordered_map<int, RenderBuffer *> mRenderBuffersMap;
98 /*key is buffer id, value is display time*/
99 std::unordered_map<int, int64_t> mDisplayedFrameMap;
100
101 bool mIsVideoPip;
fei.dengb9a1a572023-09-13 01:33:57 +0000102 mutable Tls::Mutex mMutex;
fei.dengf7a0cd32023-08-29 09:36:37 +0000103 void *mUserData;
104
105 /*immediately output video frame to display*/
106 bool mImmediatelyOutput;
107
108 //essos resource manager
109 WstEssRMgrOps *mWstEssRMgrOps;
fei.deng7ac1aeb2023-12-05 01:38:57 +0000110
111 int mFrameRateFractionNum;
112 int mFrameRateFractionDenom;
113 bool mFrameRateChanged;
fei.dengf7a0cd32023-08-29 09:36:37 +0000114};
115
116
117#endif /*__WST_CLIENT_PLUGIN_H__*/