00001 #ifndef MYTHRENDER_VDPAU_H_
00002 #define MYTHRENDER_VDPAU_H_
00003
00004 #include <QMutex>
00005 #include <QRect>
00006 #include <QHash>
00007
00008 #include "mythuiexp.h"
00009 #include "mythimage.h"
00010 #include "mythxdisplay.h"
00011 #include "mythrender_base.h"
00012
00013 extern "C" {
00014 #include "libavcodec/vdpau.h"
00015 }
00016
00017 #define MIN_OUTPUT_SURFACES 2 // UI
00018 #define MAX_OUTPUT_SURFACES 4 // Video
00019 #define NUM_REFERENCE_FRAMES 3
00020 #define VDPAU_COLORKEY 0x020202
00021
00022 typedef enum
00023 {
00024 kVDPAttribNone = 0x000,
00025 kVDPAttribBackground = 0x001,
00026 kVDPAttribSkipChroma = 0x002,
00027 kVDPAttribCSCEnd = kVDPAttribSkipChroma,
00028 kVDPAttribFiltersStart = 0x100,
00029 kVDPAttribNoiseReduction = kVDPAttribFiltersStart,
00030 kVDPAttribSharpness = 0x200,
00031 } VDPAUAttributes;
00032
00033 typedef enum
00034 {
00035 kVDPFeatNone = 0x00,
00036 kVDPFeatTemporal = 0x01,
00037 kVDPFeatSpatial = 0x02,
00038 kVDPFeatIVTC = 0x04,
00039 kVDPFeatDenoise = 0x08,
00040 kVDPFeatSharpness = 0x10,
00041 kVDPFeatHQScaling = 0x20,
00042 } VDPAUFeatures;
00043
00044 typedef enum
00045 {
00046 kVDPBlendNormal = 0,
00047 kVDPBlendPiP = 1,
00048 kVDPBlendNull = 2,
00049 } VDPBlendType;
00050
00051 class VDPAUOutputSurface;
00052 class VDPAUVideoSurface;
00053 class VDPAUBitmapSurface;
00054 class VDPAUDecoder;
00055 class VDPAUVideoMixer;
00056 class VDPAULayer;
00057
00058 class MUI_PUBLIC MythRenderVDPAU : public MythRender
00059 {
00060 public:
00061 static bool gVDPAUSupportChecked;
00062 static uint gVDPAUBestScaling;
00063 static bool gVDPAUMPEG4Accel;
00064 static bool IsMPEG4Available(void);
00065 static bool H264DecoderSizeSupported(uint width, uint height);
00066 bool CreateDummy(void);
00067
00068 MythRenderVDPAU();
00069 ~MythRenderVDPAU();
00070
00071 uint GetColorKey(void) { return m_colorKey; }
00072 void SetPreempted(void) { m_preempted = true; }
00073
00074 bool Create(const QSize &size, WId window, uint colorkey = VDPAU_COLORKEY);
00075 bool CreateDecodeOnly(void);
00076 bool WasPreempted(void);
00077 bool SetColorKey(uint color);
00078 void WaitForFlip(void);
00079 void Flip(void);
00080 void SyncDisplay(void);
00081 void DrawDisplayRect(const QRect &rect, bool use_colorkey = false);
00082 void MoveResizeWin(QRect &rect);
00083 void CheckOutputSurfaces(void);
00084 bool GetScreenShot(int width = 0, int height = 0, QString filename = "");
00085
00086 uint CreateOutputSurface(const QSize &size,
00087 VdpRGBAFormat fmt = VDP_RGBA_FORMAT_B8G8R8A8,
00088 uint existing = 0);
00089 uint CreateVideoSurface(const QSize &size,
00090 VdpChromaType type = VDP_CHROMA_TYPE_420,
00091 uint existing = 0);
00092 uint CreateBitmapSurface(const QSize &size,
00093 VdpRGBAFormat fmt = VDP_RGBA_FORMAT_B8G8R8A8,
00094 uint existing = 0);
00095 uint CreateDecoder(const QSize &size, VdpDecoderProfile profile,
00096 uint references, uint existing = 0);
00097 uint CreateVideoMixer(const QSize &size, uint layers,
00098 uint features,
00099 VdpChromaType type = VDP_CHROMA_TYPE_420,
00100 uint existing = 0);
00101 uint CreateLayer(uint surface, const QRect *src = NULL,
00102 const QRect *dst = NULL);
00103
00104 void DestroyOutputSurface(uint id);
00105 void DestroyVideoSurface(uint id);
00106 void DestroyBitmapSurface(uint id);
00107 void DestroyDecoder(uint id);
00108 void DestroyVideoMixer(uint id);
00109 void DestroyLayer(uint id);
00110
00111 bool MixAndRend(uint id, VdpVideoMixerPictureStructure field,
00112 uint vid_surface, uint out_surface,
00113 const QVector<uint>* refs, bool top, QRect src,
00114 const QRect &dst, QRect dst_vid,
00115 uint layer1 = 0, uint layer2 = 0);
00116 bool SetDeinterlacing(uint id, uint deinterlacers = kVDPFeatNone);
00117 bool ChangeVideoMixerFeatures(uint id, uint features);
00118 int SetMixerAttribute(uint id, uint attrib, int value);
00119 bool SetMixerAttribute(uint id, uint attrib, float value);
00120 void SetCSCMatrix(uint id, void* vals);
00121
00122 bool UploadBitmap(uint id, void* const plane[1], uint32_t pitch[1]);
00123 bool UploadMythImage(uint id, MythImage *image);
00124 bool UploadYUVFrame(uint id, void* const planes[3], uint32_t pitches[3]);
00125 bool DownloadYUVFrame(uint id, void* const planes[3], uint32_t pitches[3]);
00126 bool DrawBitmap(uint id, uint target, const QRect *src,
00127 const QRect *dst, VDPBlendType blendi = kVDPBlendNormal,
00128 int alpha = 0, int red = 0, int blue = 0, int green = 0);
00129 bool DrawLayer(uint id, uint target);
00130
00131 int GetBitmapSize(uint id);
00132 void* GetRender(uint id);
00133 uint GetSurfaceOwner(VdpVideoSurface surface);
00134 QSize GetSurfaceSize(uint id);
00135 void ClearVideoSurface(uint id);
00136 void ChangeVideoSurfaceOwner(uint id);
00137
00138 void Decode(uint id, struct vdpau_render_state *render);
00139
00140 private:
00141 bool CreateDevice(void);
00142 bool GetProcs(void);
00143 bool CreatePresentationQueue(void);
00144 bool CreatePresentationSurfaces(void);
00145 bool RegisterCallback(bool enable = true);
00146 bool CheckHardwareSupport(void);
00147 bool IsFeatureAvailable(uint feature);
00148
00149 void Destroy(void);
00150 void DestroyDevice(void);
00151 void ResetProcs(void);
00152 void DestroyPresentationQueue(void);
00153 void DestroyPresentationSurfaces(void);
00154 void DestroyOutputSurfaces(void);
00155 void DestroyVideoSurfaces(void);
00156 void DestroyBitmapSurfaces(void);
00157 void DestroyDecoders(void);
00158 void DestroyVideoMixers(void);
00159 void DestroyLayers(void);
00160
00161 bool SetMixerAttribute(uint id, VdpVideoMixerAttribute attribute[1],
00162 void const *value[1]);
00163
00164 void Preempted(void);
00165 void ResetVideoSurfaces(void);
00166
00167 private:
00168 VdpRect m_rect;
00169 bool m_preempted;
00170 bool m_recreating;
00171 bool m_recreated;
00172 bool m_reset_video_surfaces;
00173 QMutex m_render_lock;
00174 QMutex m_decode_lock;
00175 MythXDisplay *m_display;
00176 WId m_window;
00177 VdpDevice m_device;
00178 uint m_surface;
00179 VdpPresentationQueue m_flipQueue;
00180 VdpPresentationQueueTarget m_flipTarget;
00181 bool m_flipReady;
00182 uint m_colorKey;
00183
00184 QVector<uint> m_surfaces;
00185 QHash<uint, VDPAUOutputSurface> m_outputSurfaces;
00186 QHash<uint, VDPAUBitmapSurface> m_bitmapSurfaces;
00187 QHash<uint, VDPAUDecoder> m_decoders;
00188 QHash<uint, VDPAUVideoMixer> m_videoMixers;
00189 QHash<uint, VDPAUVideoSurface> m_videoSurfaces;
00190 QHash<VdpVideoSurface, uint> m_videoSurfaceHash;
00191 QHash<uint, VDPAULayer> m_layers;
00192
00193 VdpGetProcAddress *vdp_get_proc_address;
00194 VdpGetErrorString *vdp_get_error_string;
00195 VdpDeviceDestroy *vdp_device_destroy;
00196 VdpGetApiVersion *vdp_get_api_version;
00197 VdpGetInformationString *vdp_get_information_string;
00198 VdpVideoSurfaceCreate *vdp_video_surface_create;
00199 VdpVideoSurfaceDestroy *vdp_video_surface_destroy;
00200 VdpVideoSurfaceGetBitsYCbCr *vdp_video_surface_put_bits_y_cb_cr;
00201 VdpVideoSurfaceGetParameters *vdp_video_surface_get_parameters;
00202 VdpVideoSurfacePutBitsYCbCr *vdp_video_surface_get_bits_y_cb_cr;
00203 VdpOutputSurfacePutBitsNative *vdp_output_surface_put_bits_native;
00204 VdpOutputSurfaceCreate *vdp_output_surface_create;
00205 VdpOutputSurfaceDestroy *vdp_output_surface_destroy;
00206 VdpOutputSurfaceRenderBitmapSurface *vdp_output_surface_render_bitmap_surface;
00207 VdpOutputSurfaceGetParameters *vdp_output_surface_get_parameters;
00208 VdpOutputSurfaceGetBitsNative *vdp_output_surface_get_bits_native;
00209 VdpOutputSurfaceRenderOutputSurface *vdp_output_surface_render_output_surface;
00210 VdpVideoMixerCreate *vdp_video_mixer_create;
00211 VdpVideoMixerSetFeatureEnables *vdp_video_mixer_set_feature_enables;
00212 VdpVideoMixerDestroy *vdp_video_mixer_destroy;
00213 VdpVideoMixerRender *vdp_video_mixer_render;
00214 VdpVideoMixerSetAttributeValues *vdp_video_mixer_set_attribute_values;
00215 VdpGenerateCSCMatrix *vdp_generate_csc_matrix;
00216 VdpVideoMixerQueryFeatureSupport *vdp_video_mixer_query_feature_support;
00217 VdpPresentationQueueTargetDestroy *vdp_presentation_queue_target_destroy;
00218 VdpPresentationQueueCreate *vdp_presentation_queue_create;
00219 VdpPresentationQueueDestroy *vdp_presentation_queue_destroy;
00220 VdpPresentationQueueDisplay *vdp_presentation_queue_display;
00221 VdpPresentationQueueBlockUntilSurfaceIdle
00222 *vdp_presentation_queue_block_until_surface_idle;
00223 VdpPresentationQueueTargetCreateX11
00224 *vdp_presentation_queue_target_create_x11;
00225 VdpPresentationQueueGetTime *vdp_presentation_queue_get_time;
00226 VdpPresentationQueueSetBackgroundColor
00227 *vdp_presentation_queue_set_background_color;
00228 VdpDecoderCreate *vdp_decoder_create;
00229 VdpDecoderDestroy *vdp_decoder_destroy;
00230 VdpDecoderRender *vdp_decoder_render;
00231 VdpDecoderQueryCapabilities *vdp_decoder_query_capabilities;
00232 VdpBitmapSurfaceCreate *vdp_bitmap_surface_create;
00233 VdpBitmapSurfaceDestroy *vdp_bitmap_surface_destroy;
00234 VdpBitmapSurfacePutBitsNative *vdp_bitmap_surface_put_bits_native;
00235 VdpPreemptionCallbackRegister *vdp_preemption_callback_register;
00236 };
00237
00238 #endif