summaryrefslogtreecommitdiffstats
path: root/kopete/libkopete/avdevice/kxv.h
blob: 97552071fa5c2152ba249246b2846a38cf49d20c (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
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
/* 
 *   KDE Xv interface
 *
 *   Copyright (C) 2001 George Staikos (staikos@kde.org)
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public License
 * along with this library; see the file COPYING.LIB.  If not, write to
 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301, USA.
 */

#ifndef __KXV_H
#define __KXV_H

#include <X11/X.h>
#include <X11/Xlib.h>
#include <tqstring.h>
#include <tqstringlist.h>
#include <tqptrlist.h>

class TQWidget;
class TQImage;

class KXvPrivate;
class KXvDevice;
class KXvDevicePrivate;

typedef TQPtrList<KXvDevice> KXvDeviceList;


class KXv
{
public:
    ~KXv();
    
    /*
     *   To get access to the Xv extension, you call this method.  It will return
     *   a KXv* object on success, or NULL if it can't connect.
     *
     *   d is typically the Window ID
     */
    static KXv *connect(Drawable d);
    
    /*
     *   True if we can connect to the Xv extension.
     */
    static bool haveXv();
    
    /*
     *   Return the list of Xv devices
     */
    KXvDeviceList& devices();
    
protected:
    KXv();
    bool init(Drawable d);
    
    /***   XV info   ***/
    unsigned int xv_version, xv_release, xv_request, xv_event, xv_error;
    unsigned int xv_adaptors;
    void *xv_adaptor_info;
    
    KXvDeviceList _devs;
    
private:
    KXvPrivate *d;
};



class KXvDeviceAttribute
{
public:
    TQString name;
    int min;
    int max;
    int flags;
    
    Atom atom();
};

typedef TQPtrList<KXvDeviceAttribute> KXvDeviceAttributes;


class KXvDevice
{
    friend class KXv;
public:

    KXvDevice();
    ~KXvDevice();
    
    /*
     *   return the list of known attributes
     */
    const KXvDeviceAttributes& attributes();
    
    /*
     *   return the range for a given attribute
     */
    bool getAttributeRange(const TQString& attribute, int *min, int *max);
    
    /*
     *   get the current value of a given attribute
     */
    bool getAttribute(const TQString& attribute, int *val);
    
    /*
     *   set the current value of a given attribute
     */
    bool setAttribute(const TQString& attribute, int val);
    
    bool grabStill(TQImage *pix, int dw, int dh);
    
    /*
     *   True if this device can operate on the given widget
     */
    bool supportsWidget(TQWidget *w);
    
    /*
     *   Display the given image with Xv.
     */
    int displayImage(TQWidget *widget, const unsigned char *const data, int w, int h, int dw, int dh);
    int displayImage(Window win, const unsigned char *const data, int w, int h, int dw, int dh);

    /*
     *   Display a portion of the given image with Xv.
     */
    int displayImage(TQWidget *widget, const unsigned char *const data, int w, int h, int x, int y, int sw, int sh, int dw, int dh);
    int displayImage(Window win, const unsigned char *const data, int w, int h, int x, int y, int sw, int sh, int dw, int dh);
    
    /*
     *   Start a video stream in widget w, width dw, height dh
     */
    bool startVideo(TQWidget *w, int dw, int dh);
    bool startVideo(Window w, int dw, int dh);
    
    /*
     *   Is the video playing
     */
    bool videoPlaying() const;
    
    /*
     *   Stop video stream
     */
    bool stopVideo();
    
    /*
     *   True if this is an image output backend (video card)
     */
    bool isImageBackend();
    
    /*
     *   True if this is a video source
     */
    bool isVideoSource();
    
    /*
     *   Name of the device
     */
    const TQString& name() const;
    
    /*
     *   The Xv port for this device
     */
    int port() const;
    
    /*
     *   The list of encodings/norms available
     */
    const TQStringList& encodings() const;
    
    /*
     *   get encoding
     */
    bool encoding(TQString& encoding);
    
    /*
     *   Set the encoding to the given one.  This should be taken from the list.
     */
    bool setEncoding(const TQString& e);
    
    /*
     *   Set the image format. (ex YUV)
     */
    int setImageFormat(int format);
    
    /*
     *   Get the current image format
     */
    int imageFormat() const;
    
    /*
     *   Use SHM for PutImage if available
     */
    bool useShm(bool on);
    
    /*
     *   Is SHM being used?
     */
    bool usingShm() const;

    
protected:
    bool init();
    
    bool _shm;
    KXvDeviceAttributes _attrs;
    
    int xv_type, xv_adaptor;
    TQString xv_name;
    int xv_port;
    unsigned int xv_encodings;
    int xv_encoding;
    void *xv_encoding_info;
    int xv_encoding_attributes;
    void *xv_attr;
    GC xv_gc;
    Window xv_last_win;
    
    TQStringList _encodingList;
    
    int xv_formats;
    void *xv_formatvalues;
    
    int xv_nvisualformats;
    void *xv_visualformats;  // XvFormat*
    
    bool videoStarted;
    Window videoWindow;
    
    long xv_imageformat;
    
    void *xv_shminfo;
    void *xv_image;
    int xv_image_w;
    int xv_image_h;
    bool _haveShm;

    
private:
    KXvDevicePrivate *d;
    
    void rebuildImage(int w, int h, bool shm);
    void destroyImage();
};


#endif