#!/usr/bin/python3 import sys import selectors import pykms import argparse import time iw = 640 ih = 480 ifmt = pykms.PixelFormat.XRGB8888 ow = 640 oh = 480 ofmt = pykms.PixelFormat.XRGB8888 card = pykms.Card() res = pykms.ResourceManager(card) conn = res.reserve_connector() crtc = res.reserve_crtc(conn) plane1 = res.reserve_overlay_plane(crtc, ifmt) plane2 = res.reserve_overlay_plane(crtc, ofmt) print("{}, {}".format(plane1.id, plane2.id)) mode = conn.get_default_mode() modeb = mode.to_blob(card) card.disable_planes() req = pykms.AtomicReq(card) req.add(conn, "CRTC_ID", crtc.id) req.add(crtc, {"ACTIVE": 1, "MODE_ID": modeb.id}) req.commit_sync(allow_modeset = True) NUM_BUFS = 4 src_fbs = [] dst_fbs = [] for i in range(NUM_BUFS): fb = pykms.DumbFramebuffer(card, iw, ih, ifmt) pykms.draw_test_pattern(fb); pykms.draw_text(fb, iw // 2, 2, str(i), pykms.white); src_fbs.append(fb) fb = pykms.DumbFramebuffer(card, ow, oh, ofmt) dst_fbs.append(fb) # put the planes on the screen, so that WB doesn't take them req = pykms.AtomicReq(card) req.add_plane(plane1, src_fbs[0], crtc, dst=(0, 0, 400, 480)) req.add_plane(plane2, dst_fbs[1], crtc, dst=(400, 0, 400, 480)) r = req.commit_sync(allow_modeset = True) assert r == 0 vid = pykms.VideoDevice("/dev/video10") src_streamer = vid.output_streamer dst_streamer = vid.capture_streamer src_streamer.set_format(ifmt, iw, ih) (left, top, width, height) = src_streamer.get_selection() print("get: crop -> {},{}-{}x{}".format(left, top, width, height)) (left, top, width, height) = src_streamer.set_selection(160, 0, 320, 240) print("set: crop -> {},{}-{}x{}".format(left, top, width, height)) dst_streamer.set_format(ofmt, ow, oh) src_streamer.set_queue_size(NUM_BUFS) dst_streamer.set_queue_size(NUM_BUFS) for fb in src_fbs: src_streamer.queue(fb) for fb in dst_fbs: dst_streamer.queue(fb) input("press enter\n") src_streamer.stream_on() dst_streamer.stream_on() loop_count = 0 def readvid(conn, mask): global loop_count print("VID EVENT"); ifb = src_streamer.dequeue() ofb = dst_streamer.dequeue() req = pykms.AtomicReq(card) req.add_plane(plane1, ifb, crtc, dst=(0, 0, 400, 480)) req.add_plane(plane2, ofb, crtc, dst=(400, 0, 400, 480)) req.commit_sync(allow_modeset = True) time.sleep(1) loop_count += 1 if loop_count >= 10: exit(0) print("loop #", loop_count) src_streamer.queue(ifb) dst_streamer.queue(ofb) def readkey(conn, mask): print("KEY EVENT"); sys.stdin.readline() exit(0) sel = selectors.PollSelector() sel.register(vid.fd, selectors.EVENT_READ, readvid) sel.register(sys.stdin, selectors.EVENT_READ, readkey) while True: events = sel.select() for key, mask in events: callback = key.data callback(key.fileobj, mask) print("done"); exit(0) >drm_scatter.c
blob: dfae4b84886e7e13a090d200369067fc893bcd28 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
/**
 * \file drm_scatter.c
 * IOCTLs to manage scatter/gather memory
 *
 * \author Gareth Hughes <gareth@valinux.com>
 */

/*
 * Created: Mon Dec 18 23:20:54 2000 by gareth@valinux.com
 *
 * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
 * All Rights Reserved.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, including without limitation