1 /* -*- Mode: C; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2 /*
3    Copyright (C) 2017 Red Hat, Inc.
4 
5    This library is free software; you can redistribute it and/or
6    modify it under the terms of the GNU Lesser General Public
7    License as published by the Free Software Foundation; either
8    version 2.1 of the License, or (at your option) any later version.
9 
10    This library is distributed in the hope that it will be useful,
11    but WITHOUT ANY WARRANTY; without even the implied warranty of
12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13    Lesser General Public License for more details.
14 
15    You should have received a copy of the GNU Lesser General Public
16    License along with this library; if not, see <http://www.gnu.org/licenses/>.
17 */
18 
19 #ifndef STREAM_CHANNEL_H_
20 #define STREAM_CHANNEL_H_
21 
22 #include <spice/stream-device.h>
23 
24 #include "red-channel.h"
25 
26 #include "push-visibility.h"
27 
28 /**
29  * This type it's a RedChannel class which implement display
30  * channel with input only by stream.
31  * A pointer to StreamChannel can be converted to a RedChannel.
32  */
33 struct StreamChannel;
34 
35 /**
36  * Create StreamChannel.
37  */
38 red::shared_ptr<StreamChannel> stream_channel_new(RedsState *server, uint32_t id);
39 
40 struct StreamMsgStartStop;
41 
42 typedef void (*stream_channel_start_proc)(void *opaque, struct StreamMsgStartStop *start,
43                                           StreamChannel *channel);
44 
45 struct StreamQueueStat {
46     uint32_t num_items;
47     uint32_t size;
48 };
49 
50 typedef void (*stream_channel_queue_stat_proc)(void *opaque, const StreamQueueStat *stats,
51                                                StreamChannel *channel);
52 
53 struct StreamDataItem;
54 struct StreamChannelClient;
55 struct StreamChannel final: public RedChannel
56 {
57     friend struct StreamChannelClient;
58     friend struct StreamDataItem;
59     StreamChannel(RedsState *reds, uint32_t id);
60 
61     /**
62      * Reset channel at initial state
63      */
64     void reset();
65 
66     void change_format(const struct StreamMsgFormat *fmt);
67     void send_data(const void *data, size_t size, uint32_t mm_time);
68 
69     void register_start_cb(stream_channel_start_proc cb, void *opaque);
70     void register_queue_stat_cb(stream_channel_queue_stat_proc cb, void *opaque);
71 
72 private:
73     void on_connect(RedClient *red_client, RedStream *stream,
74                     int migration, RedChannelCapabilities *caps) override;
75 
76     inline void update_queue_stat(int32_t num_diff, int32_t size_diff);
77     void request_new_stream(StreamMsgStartStop *start);
78 
79     /* current video stream id, <0 if not initialized or
80      * we are not sending a stream */
81     int stream_id = -1;
82     /* size of the current video stream */
83     unsigned width = 0, height = 0;
84 
85     StreamQueueStat queue_stat;
86 
87     /* callback to notify when a stream should be started or stopped */
88     stream_channel_start_proc start_cb;
89     void *start_opaque;
90 
91     /* callback to notify when queue statistics changes */
92     stream_channel_queue_stat_proc queue_cb;
93     void *queue_opaque;
94 };
95 
96 #include "pop-visibility.h"
97 
98 #endif /* STREAM_CHANNEL_H_ */
99