1import xcffib
2import struct
3import six
4MAJOR_VERSION = 1
5MINOR_VERSION = 1
6key = xcffib.ExtensionKey("XVideo-MotionCompensation")
7_events = {}
8_errors = {}
9from . import xv
10class SurfaceInfo(xcffib.Struct):
11    def __init__(self, unpacker):
12        if isinstance(unpacker, xcffib.Protobj):
13            unpacker = xcffib.MemoryUnpacker(unpacker.pack())
14        xcffib.Struct.__init__(self, unpacker)
15        base = unpacker.offset
16        self.id, self.chroma_format, self.pad0, self.max_width, self.max_height, self.subpicture_max_width, self.subpicture_max_height, self.mc_type, self.flags = unpacker.unpack("IHHHHHHII")
17        self.bufsize = unpacker.offset - base
18    def pack(self):
19        buf = six.BytesIO()
20        buf.write(struct.pack("=IHHHHHHII", self.id, self.chroma_format, self.pad0, self.max_width, self.max_height, self.subpicture_max_width, self.subpicture_max_height, self.mc_type, self.flags))
21        return buf.getvalue()
22    fixed_size = 24
23    @classmethod
24    def synthetic(cls, id, chroma_format, pad0, max_width, max_height, subpicture_max_width, subpicture_max_height, mc_type, flags):
25        self = cls.__new__(cls)
26        self.id = id
27        self.chroma_format = chroma_format
28        self.pad0 = pad0
29        self.max_width = max_width
30        self.max_height = max_height
31        self.subpicture_max_width = subpicture_max_width
32        self.subpicture_max_height = subpicture_max_height
33        self.mc_type = mc_type
34        self.flags = flags
35        return self
36class QueryVersionReply(xcffib.Reply):
37    def __init__(self, unpacker):
38        if isinstance(unpacker, xcffib.Protobj):
39            unpacker = xcffib.MemoryUnpacker(unpacker.pack())
40        xcffib.Reply.__init__(self, unpacker)
41        base = unpacker.offset
42        self.major, self.minor = unpacker.unpack("xx2x4xII")
43        self.bufsize = unpacker.offset - base
44class QueryVersionCookie(xcffib.Cookie):
45    reply_type = QueryVersionReply
46class ListSurfaceTypesReply(xcffib.Reply):
47    def __init__(self, unpacker):
48        if isinstance(unpacker, xcffib.Protobj):
49            unpacker = xcffib.MemoryUnpacker(unpacker.pack())
50        xcffib.Reply.__init__(self, unpacker)
51        base = unpacker.offset
52        self.num, = unpacker.unpack("xx2x4xI20x")
53        self.surfaces = xcffib.List(unpacker, SurfaceInfo, self.num)
54        self.bufsize = unpacker.offset - base
55class ListSurfaceTypesCookie(xcffib.Cookie):
56    reply_type = ListSurfaceTypesReply
57class CreateContextReply(xcffib.Reply):
58    def __init__(self, unpacker):
59        if isinstance(unpacker, xcffib.Protobj):
60            unpacker = xcffib.MemoryUnpacker(unpacker.pack())
61        xcffib.Reply.__init__(self, unpacker)
62        base = unpacker.offset
63        self.width_actual, self.height_actual, self.flags_return = unpacker.unpack("xx2x4xHHI20x")
64        self.priv_data = xcffib.List(unpacker, "I", self.length)
65        self.bufsize = unpacker.offset - base
66class CreateContextCookie(xcffib.Cookie):
67    reply_type = CreateContextReply
68class CreateSurfaceReply(xcffib.Reply):
69    def __init__(self, unpacker):
70        if isinstance(unpacker, xcffib.Protobj):
71            unpacker = xcffib.MemoryUnpacker(unpacker.pack())
72        xcffib.Reply.__init__(self, unpacker)
73        base = unpacker.offset
74        unpacker.unpack("xx2x4x24x")
75        self.priv_data = xcffib.List(unpacker, "I", self.length)
76        self.bufsize = unpacker.offset - base
77class CreateSurfaceCookie(xcffib.Cookie):
78    reply_type = CreateSurfaceReply
79class CreateSubpictureReply(xcffib.Reply):
80    def __init__(self, unpacker):
81        if isinstance(unpacker, xcffib.Protobj):
82            unpacker = xcffib.MemoryUnpacker(unpacker.pack())
83        xcffib.Reply.__init__(self, unpacker)
84        base = unpacker.offset
85        self.width_actual, self.height_actual, self.num_palette_entries, self.entry_bytes = unpacker.unpack("xx2x4xHHHH")
86        self.component_order = xcffib.List(unpacker, "B", 4)
87        unpacker.unpack("12x")
88        unpacker.pad("I")
89        self.priv_data = xcffib.List(unpacker, "I", self.length)
90        self.bufsize = unpacker.offset - base
91class CreateSubpictureCookie(xcffib.Cookie):
92    reply_type = CreateSubpictureReply
93class ListSubpictureTypesReply(xcffib.Reply):
94    def __init__(self, unpacker):
95        if isinstance(unpacker, xcffib.Protobj):
96            unpacker = xcffib.MemoryUnpacker(unpacker.pack())
97        xcffib.Reply.__init__(self, unpacker)
98        base = unpacker.offset
99        self.num, = unpacker.unpack("xx2x4xI20x")
100        self.types = xcffib.List(unpacker, xv.ImageFormatInfo, self.num)
101        self.bufsize = unpacker.offset - base
102class ListSubpictureTypesCookie(xcffib.Cookie):
103    reply_type = ListSubpictureTypesReply
104class xvmcExtension(xcffib.Extension):
105    def QueryVersion(self, is_checked=True):
106        buf = six.BytesIO()
107        buf.write(struct.pack("=xx2x"))
108        return self.send_request(0, buf, QueryVersionCookie, is_checked=is_checked)
109    def ListSurfaceTypes(self, port_id, is_checked=True):
110        buf = six.BytesIO()
111        buf.write(struct.pack("=xx2xI", port_id))
112        return self.send_request(1, buf, ListSurfaceTypesCookie, is_checked=is_checked)
113    def CreateContext(self, context_id, port_id, surface_id, width, height, flags, is_checked=True):
114        buf = six.BytesIO()
115        buf.write(struct.pack("=xx2xIIIHHI", context_id, port_id, surface_id, width, height, flags))
116        return self.send_request(2, buf, CreateContextCookie, is_checked=is_checked)
117    def DestroyContext(self, context_id, is_checked=False):
118        buf = six.BytesIO()
119        buf.write(struct.pack("=xx2xI", context_id))
120        return self.send_request(3, buf, is_checked=is_checked)
121    def CreateSurface(self, surface_id, context_id, is_checked=True):
122        buf = six.BytesIO()
123        buf.write(struct.pack("=xx2xII", surface_id, context_id))
124        return self.send_request(4, buf, CreateSurfaceCookie, is_checked=is_checked)
125    def DestroySurface(self, surface_id, is_checked=False):
126        buf = six.BytesIO()
127        buf.write(struct.pack("=xx2xI", surface_id))
128        return self.send_request(5, buf, is_checked=is_checked)
129    def CreateSubpicture(self, subpicture_id, context, xvimage_id, width, height, is_checked=True):
130        buf = six.BytesIO()
131        buf.write(struct.pack("=xx2xIIIHH", subpicture_id, context, xvimage_id, width, height))
132        return self.send_request(6, buf, CreateSubpictureCookie, is_checked=is_checked)
133    def DestroySubpicture(self, subpicture_id, is_checked=False):
134        buf = six.BytesIO()
135        buf.write(struct.pack("=xx2xI", subpicture_id))
136        return self.send_request(7, buf, is_checked=is_checked)
137    def ListSubpictureTypes(self, port_id, surface_id, is_checked=True):
138        buf = six.BytesIO()
139        buf.write(struct.pack("=xx2xII", port_id, surface_id))
140        return self.send_request(8, buf, ListSubpictureTypesCookie, is_checked=is_checked)
141xcffib._add_ext(key, xvmcExtension, _events, _errors)
142