00001 #ifndef _OPENGL_VIDEO_H__
00002 #define _OPENGL_VIDEO_H__
00003
00004 #include <vector>
00005 #include <map>
00006 using namespace std;
00007
00008 #include <qrect.h>
00009 #include <qmap.h>
00010
00011 #include "videooutbase.h"
00012
00013 enum OpenGLFilterType
00014 {
00015 kGLFilterNone = 0,
00016
00017
00018 kGLFilterYUV2RGB,
00019 kGLFilterYUV2RGBA,
00020
00021
00022 kGLFilterLinearBlendDeint,
00023 kGLFilterKernelDeint,
00024 kGLFilterOneFieldDeint,
00025
00026
00027 kGLFilterBobDeintDFR,
00028 kGLFilterLinearBlendDeintDFR,
00029 kGLFilterKernelDeintDFR,
00030 kGLFilterFieldOrderDFR,
00031 kGLFilterOneFieldDeintDFR,
00032
00033
00034 kGLFilterResize,
00035 };
00036
00037 enum DisplayBuffer
00038 {
00039 kNoBuffer = 0,
00040 kDefaultBuffer,
00041 kFrameBufferObject
00042 };
00043
00044 class OpenGLContext;
00045
00046 class OpenGLFilter;
00047 typedef map<OpenGLFilterType,OpenGLFilter*> glfilt_map_t;
00048
00049 #ifdef USING_OPENGL_VIDEO
00050
00051 class OpenGLVideo
00052 {
00053 public:
00054 OpenGLVideo();
00055 ~OpenGLVideo();
00056
00057 bool Init(OpenGLContext *glcontext, bool colour_control, bool onscreen,
00058 QSize video_size, QRect visible_rect,
00059 QRect video_rect, QRect frame_rect,
00060 bool viewport_control, bool osd = FALSE);
00061 bool ReInit(OpenGLContext *gl, bool colour_control, bool onscreen,
00062 QSize video_size, QRect visible_rect,
00063 QRect video_rect, QRect frame_rect,
00064 bool viewport_control, bool osd = FALSE);
00065
00066 void UpdateInputFrame(const VideoFrame *frame);
00067 void UpdateInput(const unsigned char *buf, const int *offsets,
00068 uint texture_index, int format, QSize size);
00069
00070 bool AddFilter(const QString &filter)
00071 { return AddFilter(StringToFilter(filter)); }
00072 bool RemoveFilter(const QString &filter)
00073 { return RemoveFilter(StringToFilter(filter)); }
00074
00075 bool AddDeinterlacer(const QString &filter);
00076 void SetDeinterlacing(bool deinterlacing);
00077 QString GetDeinterlacer(void) const
00078 { return FilterToString(GetDeintFilter()); };
00079 void SetSoftwareDeinterlacer(const QString &filter)
00080 { softwareDeinterlacer = QDeepCopy<QString>(filter); };
00081
00082 void PrepareFrame(FrameScanType scan, bool softwareDeinterlacing,
00083 long long frame);
00084
00085 void SetMasterViewport(QSize size) { masterViewportSize = size; }
00086 QSize GetViewPort(void) const { return viewportSize; }
00087 void SetVideoRect(const QRect &vidrect, const QRect &framerect)
00088 { videoRect = vidrect; frameRect = framerect;}
00089 QSize GetVideoSize(void) const { return videoSize; }
00090 void SetVideoResize(const QRect &rect);
00091 void DisableVideoResize(void);
00092 int SetPictureAttribute(PictureAttribute attributeType, int newValue);
00093 PictureAttributeSupported GetSupportedPictureAttributes(void) const;
00094
00095 private:
00096 void Teardown(void);
00097 void SetViewPort(const QSize &new_viewport_size);
00098 void SetViewPortPrivate(const QSize &new_viewport_size);
00099 bool AddFilter(OpenGLFilterType filter);
00100 bool RemoveFilter(OpenGLFilterType filter);
00101 bool OptimiseFilters(void);
00102 OpenGLFilterType GetDeintFilter(void) const;
00103 bool AddFrameBuffer(uint &framebuffer, uint &texture, QSize size);
00104 uint AddFragmentProgram(OpenGLFilterType name);
00105 uint CreateVideoTexture(QSize size, QSize &tex_size);
00106 QString GetProgramString(OpenGLFilterType filter);
00107 void CalculateResize(float &left, float &top,
00108 float &right, float &bottom);
00109 static QString FilterToString(OpenGLFilterType filter);
00110 static OpenGLFilterType StringToFilter(const QString &filter);
00111 void ShutDownYUV2RGB(void);
00112 void SetViewPort(bool last_stage);
00113 void InitOpenGL(void);
00114 QSize GetTextureSize(const QSize &size);
00115 void SetFiltering(void);
00116
00117 void Rotate(vector<uint> *target);
00118 void SetTextureFilters(vector<uint> *textures, int filt);
00119
00120 OpenGLContext *gl_context;
00121 QSize videoSize;
00122 QSize viewportSize;
00123 QSize masterViewportSize;
00124 QRect visibleRect;
00125 QRect videoRect;
00126 QRect frameRect;
00127 QRect frameBufferRect;
00128 bool invertVideo;
00129 QString softwareDeinterlacer;
00130 bool hardwareDeinterlacing;
00131 bool useColourControl;
00132 bool viewportControl;
00133 uint frameBuffer;
00134 uint frameBufferTexture;
00135 vector<uint> inputTextures;
00136 QSize inputTextureSize;
00137 glfilt_map_t filters;
00138 long long currentFrameNum;
00139 bool inputUpdated;
00140
00141 QSize convertSize;
00142 unsigned char *convertBuf;
00143
00144 bool videoResize;
00145 QRect videoResizeRect;
00146
00147 float pictureAttribs[kPictureAttribute_MAX];
00148 };
00149
00150 #else // if !USING_OPENGL_VIDEO
00151
00152 class OpenGLVideo
00153 {
00154 public:
00155 OpenGLVideo() { }
00156 ~OpenGLVideo() { }
00157
00158 bool Init(OpenGLContext*, bool, bool, QSize, QRect,
00159 QRect, QRect, bool, bool osd = false)
00160 { (void) osd; return false; }
00161
00162 bool ReInit(OpenGLContext*, bool, bool, QSize, QRect,
00163 QRect, QRect, bool, bool osd = false)
00164 { (void) osd; return false; }
00165
00166 void UpdateInputFrame(const VideoFrame*) { }
00167 void UpdateInput(const unsigned char*, const int*, uint, int, QSize) { }
00168
00169 bool AddFilter(const QString&) { return false; }
00170 bool RemoveFilter(const QString&) { return false; }
00171
00172 bool AddDeinterlacer(const QString&) { return false; }
00173 void SetDeinterlacing(bool) { }
00174 QString GetDeinterlacer(void) const { return QString::null; }
00175 void SetSoftwareDeinterlacer(const QString&) { }
00176
00177 void PrepareFrame(FrameScanType, bool, long long) { }
00178
00179 void SetMasterViewport(QSize) { }
00180 QSize GetViewPort(void) const { return QSize(0,0); }
00181 void SetVideoRect(const QRect&, const QRect&) { }
00182 QSize GetVideoSize(void) const { return QSize(0,0); }
00183 void SetVideoResize(const QRect&) { }
00184 void DisableVideoResize(void) { }
00185 int SetPictureAttribute(PictureAttribute, int) { return -1; }
00186 PictureAttributeSupported GetSupportedPictureAttributes(void) const
00187 { return kPictureAttributeSupported_None; }
00188 };
00189
00190 #endif // !USING_OPENGL_VIDEO
00191
00192 #endif // _OPENGL_VIDEO_H__