1 #include "decoder.h"
2 
Decoder(QObject * parent)3 Decoder::Decoder(QObject *parent) :
4     QObject(parent)
5 {
6     channel = NULL;
7 }
8 
9 /*
10  * inititialize the decoder
11  *
12  * @return 0 on success, -1 on failure
13  *****************************************************************************/
init(QString filename)14 int Decoder::init(QString filename)
15 {
16     printf("Decoder::init\n");
17     if (channel)
18         return -1;
19 
20     /* open a virtual channel and connect to remote client */
21     channel = WTSVirtualChannelOpenEx(WTS_CURRENT_SESSION, "xrdpvr", 0);
22     if (channel == NULL)
23     {
24         qDebug() << "WTSVirtualChannelOpenEx() failed\n";
25         return -1;
26     }
27 
28     /* initialize the player */
29     if (xrdpvr_init_player(channel, 101, filename.toAscii().data()))
30     {
31         fprintf(stderr, "failed to initialize the player\n");
32         return -1;
33     }
34 
35 #if 1
36     sleep(1);
37     qDebug() << "sleeping 1";
38     xrdpvr_set_geometry(channel, 101, mainWindowGeometry.x(),
39                         mainWindowGeometry.y(), mainWindowGeometry.width(),
40                         mainWindowGeometry.height());
41     qDebug() << "set geometry to:" << mainWindowGeometry.x() <<
42                 "" << mainWindowGeometry.y() <<
43                 "" << mainWindowGeometry.width() <<
44                 "" << mainWindowGeometry.height();
45 #endif
46 
47     /* send compressed media data to client; client will decompress */
48     /* the media and play it locally                                */
49     xrdpvr_play_media(channel, 101, filename.toAscii().data());
50 
51     /* perform clean up */
52     xrdpvr_deinit_player(channel, 101);
53 
54     WTSVirtualChannelClose(channel);
55 
56     return 0;
57 }
58 
onGeometryChanged(QRect * g)59 void Decoder::onGeometryChanged(QRect *g)
60 {
61 #if 1
62     mainWindowGeometry.setX(g->x());
63     mainWindowGeometry.setY(g->y());
64     mainWindowGeometry.setWidth(g->width());
65     mainWindowGeometry.setHeight(g->height());
66 #else
67     if (!channel)
68         return;
69 
70     xrdpvr_set_geometry(channel, 101, g->x(), g->y(), g->width(), g->height());
71     qDebug() << "sent geometry";
72 #endif
73 }
74