| 1 | #ifndef VIDEOOUT_OPENGL_H_
|
|---|
| 2 | #define VIDEOOUT_OPENGL_H_
|
|---|
| 3 |
|
|---|
| 4 | #include <DisplayRes.h>
|
|---|
| 5 | #include "videooutbase.h"
|
|---|
| 6 | #include "NuppelVideoPlayer.h"
|
|---|
| 7 | #include "util-opengl.h"
|
|---|
| 8 |
|
|---|
| 9 | #define GL_GLEXT_PROTOTYPES
|
|---|
| 10 | #define GLX_GLXEXT_PROTOTYPES
|
|---|
| 11 | #define XMD_H 1
|
|---|
| 12 | #include <GL/glx.h>
|
|---|
| 13 |
|
|---|
| 14 | #include <GL/gl.h>
|
|---|
| 15 | #undef GLX_ARB_get_proc_address
|
|---|
| 16 | #include <GL/glxext.h>
|
|---|
| 17 | #include <GL/glext.h>
|
|---|
| 18 |
|
|---|
| 19 | class VideoOutputOpengl : public VideoOutput
|
|---|
| 20 | {
|
|---|
| 21 | public:
|
|---|
| 22 | VideoOutputOpengl();
|
|---|
| 23 | ~VideoOutputOpengl();
|
|---|
| 24 | bool Init(int width, int height, float aspect, WId winid,
|
|---|
| 25 | int winx, int winy, int winw, int winh, WId embedid = 0);
|
|---|
| 26 | void SetOffscreen(void) { render_onscreen = false; };
|
|---|
| 27 | void GetOSDBounds(QRect &visible, QRect &total,
|
|---|
| 28 | float &pixelAspect, float &fontScale) const;
|
|---|
| 29 | void PrepareFrame(VideoFrame *buffer, FrameScanType);
|
|---|
| 30 | void ShowPip(VideoFrame *frame, NuppelVideoPlayer *pipplayer);
|
|---|
| 31 | QRect GetPIPRect(int location, NuppelVideoPlayer *pipplayer);
|
|---|
| 32 | int DisplayOSD(VideoFrame *frame, OSD *osd,
|
|---|
| 33 | int stride = -1, int revision = -1);
|
|---|
| 34 | void Show(FrameScanType );
|
|---|
| 35 | void MoveResize();
|
|---|
| 36 | void InputChanged(int width, int height,
|
|---|
| 37 | float aspect, MythCodecID codec_id);
|
|---|
| 38 | void Zoom(int direction);
|
|---|
| 39 | void AspectChanged(float aspect);
|
|---|
| 40 | void EmbedInWidget(WId wid, int x, int y, int w, int h);
|
|---|
| 41 | void StopEmbedding(void);
|
|---|
| 42 | void ResizeForGui(void);
|
|---|
| 43 | void ResizeForVideo(uint width, uint height);
|
|---|
| 44 | void ResizeForVideo(void);
|
|---|
| 45 | int GetRefreshRate(void);
|
|---|
| 46 | void DrawUnusedRects(bool sync = true);
|
|---|
| 47 | float GetDisplayAspect(void);
|
|---|
| 48 | void UpdatePauseFrame(void);
|
|---|
| 49 | void ProcessFrame(VideoFrame *frame, OSD *osd,
|
|---|
| 50 | FilterChain *filterList,
|
|---|
| 51 | NuppelVideoPlayer *pipPlayer);
|
|---|
| 52 | int SetPictureAttribute(int attributeType, int newValue);
|
|---|
| 53 | bool hasOpenGLAcceleration(void) const { return true; }
|
|---|
| 54 | unsigned char* GetARGBFrame(QSize &size);
|
|---|
| 55 | void ShutdownVideoResize(void);
|
|---|
| 56 |
|
|---|
| 57 | bool SetDeinterlacingEnabled(bool);
|
|---|
| 58 | bool SetupDeinterlace(bool i, const QString& ovrf="");
|
|---|
| 59 |
|
|---|
| 60 | private:
|
|---|
| 61 | void InitDisplayMeasurements(uint width, uint height);
|
|---|
| 62 | bool InitSetupBuffers(void);
|
|---|
| 63 | void CreateBuffers(void);
|
|---|
| 64 | void CreatePauseFrame(void);
|
|---|
| 65 | void DeleteBuffers(bool delete_pause_frame);
|
|---|
| 66 |
|
|---|
| 67 | // Misc.
|
|---|
| 68 | DisplayRes *display_res;
|
|---|
| 69 | QMutex global_lock;
|
|---|
| 70 |
|
|---|
| 71 | // Opengl
|
|---|
| 72 | OpenglContext *gl;
|
|---|
| 73 | OpenglVideo *videochain;
|
|---|
| 74 | OpenglVideo *pipchain;
|
|---|
| 75 | OpenglVideo *osdchain;
|
|---|
| 76 |
|
|---|
| 77 | // General
|
|---|
| 78 | bool render_onscreen;
|
|---|
| 79 | bool use_colourcontrols;
|
|---|
| 80 | bool gl_osd;
|
|---|
| 81 | VideoFrame av_pause_frame;
|
|---|
| 82 | bool actually_draw_pip;
|
|---|
| 83 | bool actually_draw_osd;
|
|---|
| 84 | unsigned char *argb_frame;
|
|---|
| 85 |
|
|---|
| 86 | };
|
|---|
| 87 |
|
|---|
| 88 | enum OpenglFilter
|
|---|
| 89 | {
|
|---|
| 90 | kNOFILT = 0,
|
|---|
| 91 | kYUV2RGB,
|
|---|
| 92 | kYUV2RGBA,
|
|---|
| 93 | kLINBLEND,
|
|---|
| 94 | kKDEINT,
|
|---|
| 95 | kONEFIELD,
|
|---|
| 96 | kBOBDEINT,
|
|---|
| 97 | kPROGLINBLEND,
|
|---|
| 98 | kPROGKDEINT,
|
|---|
| 99 | kPROGONEFIELD,
|
|---|
| 100 | kRESIZE
|
|---|
| 101 | };
|
|---|
| 102 |
|
|---|
| 103 | enum DisplayBuffer
|
|---|
| 104 | {
|
|---|
| 105 | kNoBuffer = 0, // disable filter
|
|---|
| 106 | kDefaultBuffer,
|
|---|
| 107 | kFrameBufferObject
|
|---|
| 108 | };
|
|---|
| 109 |
|
|---|
| 110 | typedef struct Filter
|
|---|
| 111 | {
|
|---|
| 112 | GLuint fragmentProgram;
|
|---|
| 113 | uint numInputs;
|
|---|
| 114 | bool rotateFrameBuffers;
|
|---|
| 115 | vector<GLuint> frameBuffers;
|
|---|
| 116 | vector<GLuint> frameBufferTextures;
|
|---|
| 117 | DisplayBuffer outputBuffer;
|
|---|
| 118 | };
|
|---|
| 119 |
|
|---|
| 120 | class OpenglVideo
|
|---|
| 121 | {
|
|---|
| 122 | public:
|
|---|
| 123 | OpenglVideo();
|
|---|
| 124 | ~OpenglVideo();
|
|---|
| 125 | bool Init(OpenglContext *glcontext, bool colour_control, bool onscreen,
|
|---|
| 126 | QSize video_size, QRect visible_rect,
|
|---|
| 127 | QRect video_rect, bool viewport_control, bool osd = FALSE);
|
|---|
| 128 | bool ReInit(OpenglContext *gl, bool colour_control, bool onscreen,
|
|---|
| 129 | QSize video_size, QRect visible_rect,
|
|---|
| 130 | QRect video_rect, bool viewport_control, bool osd = FALSE);
|
|---|
| 131 | void UpdateInputFrame(VideoFrame *frame);
|
|---|
| 132 | void UpdateInput(unsigned char *buf, uint texture_num,
|
|---|
| 133 | int format, QSize size);
|
|---|
| 134 | bool AddFilter(QString filter)
|
|---|
| 135 | { return AddFilter(StringToFilter(filter)); };
|
|---|
| 136 | bool RemoveFilter(QString filter)
|
|---|
| 137 | { return RemoveFilter(StringToFilter(filter)); };
|
|---|
| 138 | bool AddDeinterlacer(QString filter);
|
|---|
| 139 | void SetDeinterlacing(bool deinterlacing);
|
|---|
| 140 | QString GetDeinterlacer(void)
|
|---|
| 141 | { return FilterToString(GetDeintFilter()); };
|
|---|
| 142 | void Show(FrameScanType scan, bool softwareDeinterlacing, long long frame);
|
|---|
| 143 | void SetSoftwareDeinterlacer(QString filter)
|
|---|
| 144 | { softwareDeinterlacer = filter; };
|
|---|
| 145 | void SetMasterViewport(QSize size)
|
|---|
| 146 | { masterViewportSize = size; };
|
|---|
| 147 | QSize GetViewPort(void) { return viewportSize; };
|
|---|
| 148 | void SetVideoRect(QRect rect) { videoRect = rect; };
|
|---|
| 149 | QSize GetVideoSize(void) { return videoSize; };
|
|---|
| 150 | void SetVideoResize(QRect *size);
|
|---|
| 151 | void SetPictureAttribute(int attributeType, int newValue);
|
|---|
| 152 |
|
|---|
| 153 | private:
|
|---|
| 154 | void Cleanup(void);
|
|---|
| 155 | void SetViewPort(uint width, uint height);
|
|---|
| 156 | void ViewPort(uint width, uint height);
|
|---|
| 157 | bool AddFilter(OpenglFilter filter);
|
|---|
| 158 | bool RemoveFilter(OpenglFilter filter);
|
|---|
| 159 | bool OptimiseFilters(void);
|
|---|
| 160 | OpenglFilter GetDeintFilter(void);
|
|---|
| 161 | bool AddFrameBuffer(GLuint *framebuffer, GLuint *texture, QSize size);
|
|---|
| 162 | GLuint AddFragmentProgram(OpenglFilter name);
|
|---|
| 163 | GLuint CreateVideoTexture(QSize size, QSize *tex_size, bool YUV12);
|
|---|
| 164 | QString GetProgramString(OpenglFilter filter);
|
|---|
| 165 | void CalculateResize(float *left, float *top,
|
|---|
| 166 | float *right, float *bottom);
|
|---|
| 167 | void Rotate(vector<GLuint> *target);
|
|---|
| 168 | QString FilterToString(OpenglFilter filter);
|
|---|
| 169 | OpenglFilter StringToFilter(QString filter);
|
|---|
| 170 | void ShutDownYUV2RGB(void);
|
|---|
| 171 | void SetViewPort(bool last_stage);
|
|---|
| 172 | void InitOpengl(void);
|
|---|
| 173 | void GetTextureSize(QSize *temp, QSize size);
|
|---|
| 174 | void SetFiltering(void);
|
|---|
| 175 | void SetTextureFilters(vector<GLuint> *textures, int filt);
|
|---|
| 176 |
|
|---|
| 177 | OpenglContext *gl;
|
|---|
| 178 | QSize videoSize;
|
|---|
| 179 | QSize viewportSize;
|
|---|
| 180 | QSize masterViewportSize;
|
|---|
| 181 | QRect visibleRect;
|
|---|
| 182 | QRect videoRect;
|
|---|
| 183 | QRect frameBufferRect;
|
|---|
| 184 | bool invertVideo;
|
|---|
| 185 | QString softwareDeinterlacer;
|
|---|
| 186 | bool hardwareDeinterlacing;
|
|---|
| 187 | bool useColourControl;
|
|---|
| 188 | bool viewportControl;
|
|---|
| 189 | GLuint frameBuffer;
|
|---|
| 190 | GLuint frameBufferTexture;
|
|---|
| 191 | vector<GLuint> inputTextures;
|
|---|
| 192 | QSize inputTextureSize;
|
|---|
| 193 | map<OpenglFilter,Filter> filters;
|
|---|
| 194 | long long currentFrameNum;
|
|---|
| 195 | bool inputUpdated;
|
|---|
| 196 |
|
|---|
| 197 | QSize convertSize;
|
|---|
| 198 | unsigned char *convertBuf;
|
|---|
| 199 |
|
|---|
| 200 | bool videoResize;
|
|---|
| 201 | QRect videoResizeRect;
|
|---|
| 202 |
|
|---|
| 203 | static QMap<int,float> pictureAttribs;
|
|---|
| 204 | };
|
|---|
| 205 |
|
|---|
| 206 | #endif
|
|---|
| 207 |
|
|---|