00001 #ifndef VIDEOOUT_XV_H_
00002 #define VIDEOOUT_XV_H_
00003
00004 #include <set>
00005 #include <qwindowdefs.h>
00006
00007 #include "DisplayRes.h"
00008 #include "videooutbase.h"
00009
00010 #include "util-x11.h"
00011 #include <X11/Xatom.h>
00012 #include <X11/Xutil.h>
00013 #include <X11/extensions/Xvlib.h>
00014 #include <X11/extensions/XShm.h>
00015 #include <X11/extensions/Xv.h>
00016
00017 #undef HAVE_AV_CONFIG_H
00018 extern "C" {
00019 #include "../libavcodec/avcodec.h"
00020 }
00021
00022 class NuppelVideoPlayer;
00023 class ChromaKeyOSD;
00024
00025 class OpenGLContext;
00026 class OpenGLVideo;
00027
00028 class XvMCBufferSettings;
00029 class XvMCSurfaceTypes;
00030 class XvMCTextures;
00031 class XvMCOSD;
00032
00033 #ifdef USING_XVMC
00034 # include "XvMCSurfaceTypes.h"
00035 # include "../libavcodec/xvmc_render.h"
00036 typedef struct
00037 {
00038 XvMCSurface surface;
00039 XvMCBlockArray blocks;
00040 XvMCMacroBlockArray macro_blocks;
00041 } xvmc_vo_surf_t;
00042 #else // if !USING_XVMC
00043 typedef int xvmc_vo_surf_t;
00044 typedef int XvMCSurfaceInfo;
00045 struct XvMCContext;
00046 #endif // !USING_XVMC
00047
00048 typedef enum VideoOutputSubType
00049 {
00050 XVUnknown = 0, Xlib, XShm, OpenGL, XVideo, XVideoMC, XVideoIDCT, XVideoVLD,
00051 } VOSType;
00052
00053 class VideoOutputXv : public VideoOutput
00054 {
00055 friend class ChromaKeyOSD;
00056 friend class OpenGLVideoSync;
00057 friend class XvMCOSD;
00058 public:
00059 VideoOutputXv(MythCodecID av_codec_id);
00060 ~VideoOutputXv();
00061
00062 bool Init(int width, int height, float aspect, WId winid,
00063 int winx, int winy, int winw, int winh, WId embedid = 0);
00064
00065 bool SetDeinterlacingEnabled(bool);
00066 bool SetupDeinterlace(bool interlaced, const QString& ovrf="");
00067 bool ApproveDeintFilter(const QString& filtername) const;
00068
00069 void ProcessFrame(VideoFrame *frame, OSD *osd,
00070 FilterChain *filterList,
00071 NuppelVideoPlayer *pipPlayer);
00072 void PrepareFrame(VideoFrame*, FrameScanType);
00073 void DrawSlice(VideoFrame*, int x, int y, int w, int h);
00074 void Show(FrameScanType);
00075
00076 void ClearAfterSeek(void);
00077
00078 void MoveResize(void);
00079 bool InputChanged(const QSize &input_size,
00080 float aspect,
00081 MythCodecID av_codec_id,
00082 void *codec_private);
00083 void Zoom(ZoomDirection direction);
00084 void VideoAspectRatioChanged(float aspect);
00085 void EmbedInWidget(WId wid, int x, int y, int w, int h);
00086 void StopEmbedding(void);
00087 void ResizeForGui(void);
00088 void ResizeForVideo(void);
00089 void DrawUnusedRects(bool sync = true);
00090 void UpdatePauseFrame(void);
00091 int SetPictureAttribute(PictureAttribute attribute, int newValue);
00092 void InitPictureAttributes(void);
00093
00095 int GetRefreshRate(void);
00096
00097 virtual bool hasMCAcceleration(void) const
00098 { return XVideoMC <= VideoOutputSubType(); }
00099 virtual bool hasIDCTAcceleration(void) const
00100 { return XVideoIDCT <= VideoOutputSubType(); }
00101 virtual bool hasVLDAcceleration(void) const
00102 { return XVideoVLD == VideoOutputSubType(); }
00103
00104 void CheckFrameStates(void);
00105 QRect GetPIPRect(int location, NuppelVideoPlayer *pipplayer = NULL);
00106
00107 virtual void ShutdownVideoResize(void);
00108
00109 static MythCodecID GetBestSupportedCodec(uint width, uint height,
00110 uint osd_width, uint osd_height,
00111 uint stream_type, int xvmc_chroma,
00112 bool test_surface, bool force_xv);
00113
00114 static int GrabSuitableXvPort(Display* disp, Window root,
00115 MythCodecID type,
00116 uint width, uint height,
00117 int xvmc_chroma = 0,
00118 XvMCSurfaceInfo* si = NULL,
00119 QString *adaptor_name = NULL);
00120
00121 static XvMCContext* CreateXvMCContext(Display* disp, int port,
00122 int surf_type,
00123 int width, int height);
00124 static void DeleteXvMCContext(Display* disp, XvMCContext*& ctx);
00125
00126
00127 static QStringList GetAllowedRenderers(MythCodecID myth_codec_id,
00128 const QSize &video_dim);
00129
00130 private:
00131 VOSType VideoOutputSubType() const { return video_output_subtype; }
00132 virtual QRect GetVisibleOSDBounds(float&, float&, float) const;
00133 virtual QRect GetTotalOSDBounds(void) const;
00134
00135 VideoFrame *GetNextFreeFrame(bool allow_unsafe);
00136 void DiscardFrame(VideoFrame*);
00137 void DiscardFrames(bool next_frame_keyframe);
00138 void DoneDisplayingFrame(void);
00139
00140 void ProcessFrameXvMC(VideoFrame *frame, OSD *osd);
00141 void ProcessFrameOpenGL(VideoFrame *frame, OSD *osd,
00142 FilterChain *filterList,
00143 NuppelVideoPlayer *pipPlayer);
00144 void ProcessFrameMem(VideoFrame *frame, OSD *osd,
00145 FilterChain *filterList,
00146 NuppelVideoPlayer *pipPlayer);
00147
00148 void PrepareFrameXvMC(VideoFrame *, FrameScanType);
00149 void PrepareFrameXv(VideoFrame *);
00150 void PrepareFrameOpenGL(VideoFrame *, FrameScanType);
00151 void PrepareFrameMem(VideoFrame *, FrameScanType);
00152
00153 void ShowXvMC(FrameScanType scan);
00154 void ShowXVideo(FrameScanType scan);
00155
00156 void ShowPip(VideoFrame *frame, NuppelVideoPlayer *pipplayer);
00157 virtual int DisplayOSD(VideoFrame *frame, OSD *osd,
00158 int stride = -1, int revision = -1);
00159
00160 void ResizeForVideo(uint width, uint height);
00161 void InitDisplayMeasurements(uint width, uint height);
00162 void InitColorKey(bool turnoffautopaint);
00163
00164 bool InitVideoBuffers(MythCodecID, bool use_xv,
00165 bool use_shm, bool use_opengl);
00166
00167 bool InitXvMC(MythCodecID);
00168 bool InitXVideo(void);
00169 bool InitOpenGL(void);
00170 bool InitXShm(void);
00171 bool InitXlib(void);
00172 bool InitOSD(const QString&);
00173 bool CheckOSDInit(void);
00174
00175 bool CreateXvMCBuffers(void);
00176 bool CreateBuffers(VOSType subtype);
00177 vector<void*> CreateXvMCSurfaces(uint num, bool surface_has_vld);
00178 vector<unsigned char*> CreateShmImages(uint num, bool use_xv);
00179 void CreatePauseFrame(VOSType subtype);
00180 void CopyFrame(VideoFrame *to, const VideoFrame *from);
00181
00182 void DeleteBuffers(VOSType subtype, bool delete_pause_frame);
00183
00184 bool InitSetupBuffers(void);
00185
00186
00187 static bool IsDisplaying(VideoFrame* frame);
00188 static bool IsRendering(VideoFrame* frame);
00189 static void SyncSurface(VideoFrame* frame, int past_future = 0);
00190 static void FlushSurface(VideoFrame* frame);
00191
00192 #ifdef USING_XVMC
00193 XvMCOSD* GetAvailableOSD();
00194 void ReturnAvailableOSD(XvMCOSD*);
00195 #endif // USING_XVMC
00196
00197
00198 bool SetDeinterlacingEnabledOpenGL(bool enable);
00199 bool SetupDeinterlaceOpenGL(
00200 bool interlaced, const QString &overridefilter);
00201
00202
00203
00204 MythCodecID myth_codec_id;
00205 VOSType video_output_subtype;
00206 DisplayRes *display_res;
00207 QMutex global_lock;
00208
00209
00210 Window XJ_root;
00211 Window XJ_win;
00212 Window XJ_curwin;
00213 GC XJ_gc;
00214 Screen *XJ_screen;
00215 Display *XJ_disp;
00216 int XJ_screen_num;
00217 unsigned long XJ_white;
00218 unsigned long XJ_black;
00219 unsigned long XJ_letterbox_colour;
00220 int XJ_depth;
00221 int XJ_screenx;
00222 int XJ_screeny;
00223 int XJ_screenwidth;
00224 int XJ_screenheight;
00225 bool XJ_started;
00226
00227
00228 VideoFrame av_pause_frame;
00229 vector<XShmSegmentInfo*> XJ_shm_infos;
00230 vector<YUVInfo> XJ_yuv_infos;
00231
00232
00233 XImage *XJ_non_xv_image;
00234 long long non_xv_frames_shown;
00235 int non_xv_show_frame;
00236 int non_xv_fps;
00237 int non_xv_av_format;
00238 time_t non_xv_stop_time;
00239
00240
00241 XvMCBufferSettings *xvmc_buf_attr;
00242 int xvmc_chroma;
00243 XvMCContext *xvmc_ctx;
00244 vector<void*> xvmc_surfs;
00245 QMutex xvmc_osd_lock;
00246 MythDeque<XvMCOSD*> xvmc_osd_available;
00247 #ifdef USING_XVMC
00248 XvMCSurfaceInfo xvmc_surf_info;
00249 #endif // USING_XVMC
00250
00251
00252 XvMCTextures *xvmc_tex;
00253
00254
00255 int xv_port;
00256 int xv_hue_base;
00257 int xv_colorkey;
00258 bool xv_draw_colorkey;
00259 int xv_chroma;
00260 buffer_map_t xv_buffers;
00261 bool xv_need_bobdeint_repaint;
00262 QMap<PictureAttribute,int> xv_attribute_min;
00263 QMap<PictureAttribute,int> xv_attribute_max;
00264
00265
00266 QMutex gl_context_lock;
00267 OpenGLContext *gl_context;
00268 OpenGLVideo *gl_videochain;
00269 OpenGLVideo *gl_pipchain;
00270 OpenGLVideo *gl_osdchain;
00271 bool gl_use_osd_opengl2;
00272 bool gl_pip_ready;
00273 bool gl_osd_ready;
00274
00275
00276 ChromaKeyOSD *chroma_osd;
00277 };
00278
00279 #endif // VIDEOOUT_XV_H_