Merging gst-plugins-bad
[platform/upstream/gstreamer.git] / subprojects / gst-plugins-bad / sys / dvb / camtransport.h
1 /*
2  * camtransport.h - GStreamer CAM (EN50221) transport layer
3  * Copyright (C) 2007 Alessandro Decina
4  *
5  * Authors:
6  *   Alessandro Decina <alessandro.d@gmail.com>
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Library General Public
10  * License as published by the Free Software Foundation; either
11  * version 2 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * Library General Public License for more details.
17  *
18  * You should have received a copy of the GNU Library General Public
19  * License along with this library; if not, write to the
20  * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
21  * Boston, MA 02110-1301, USA.
22  */
23
24 #ifndef CAM_TRANSPORT_H
25 #define CAM_TRANSPORT_H
26
27 #include <gst/gst.h>
28 #include "cam.h"
29 #include "camutils.h"
30
31 #define HOST_BUFFER_SIZE 1024
32
33 #define CAM_TL(obj) ((CamTL *) obj)
34 #define CAM_TL_CONNECTION(obj) ((CamTLConnection *) obj)
35
36 typedef struct _CamTL CamTL;
37 typedef struct _CamTLPrivate CamTLPrivate;
38
39 typedef struct _CamTLConnection CamTLConnection;
40 typedef struct _CamTLConnectionPrivate CamTLConnectionPrivate;
41
42 typedef enum
43 {
44   CAM_TL_CONNECTION_STATE_CLOSED,
45   CAM_TL_CONNECTION_STATE_IN_CREATION,
46   CAM_TL_CONNECTION_STATE_OPEN,
47   CAM_TL_CONNECTION_STATE_IN_DELETION
48 } CamTLConnectionState;
49
50 struct _CamTL
51 {
52   int fd;
53   guint connection_ids;
54
55   GHashTable *connections;
56
57   guint expected_tpdus;
58
59   /* buffer containing module data */
60   guint8 buffer [HOST_BUFFER_SIZE];
61   /* number of bytes written in the buffer */
62   guint buffer_size;
63   /* index pointing to the first byte of a TPDU's body */
64   guint8 *body;
65   /* length of the body part */
66   guint body_length;
67
68   /* callbacks */
69   void (*request_connection) (CamTL *tl, CamTLConnection *connection);
70   void (*connection_created) (CamTL *tl, CamTLConnection *connection);
71   void (*connection_deleted) (CamTL *tl, CamTLConnection *connection);
72   CamReturn (*connection_data) (CamTL *tl, CamTLConnection *connection,
73     guint8 *data, guint length);
74
75   /* used by the upper layer to extend this layer */
76   gpointer user_data;
77 };
78
79 struct _CamTLConnection
80 {
81   CamTL *tl;
82
83   guint8 slot;
84   guint id;
85   CamTLConnectionState state;
86   /* TRUE if the last status byte was 0x80, FALSE otherwise */
87   gboolean has_data;
88   /* NCAS 1.0 sometimes reports that it has data even if it doesn't. After
89    * MAX_EMPTY_DATA times that we don't get any data we assume that there's
90    * actually no data.
91    */
92   guint empty_data;
93   /* timer restarted every time the connection is polled */
94   GTimer *last_poll;
95
96   gpointer user_data;
97 };
98
99 CamTL *cam_tl_new (int cam_device_fd);
100 void cam_tl_destroy (CamTL *tl);
101
102 CamReturn cam_tl_create_connection (CamTL *tl,
103   guint8 slot, CamTLConnection **connnection);
104 CamReturn cam_tl_connection_delete (CamTLConnection *connection);
105
106 void cam_tl_calc_buffer_size (CamTL *tl,
107   guint body_length, guint *buffer_size, guint *offset);
108
109 CamReturn cam_tl_connection_write (CamTLConnection *connection,
110   guint8 *data, guint buffer_size, guint body_length);
111
112 CamReturn cam_tl_connection_poll (CamTLConnection *connection, gboolean force);
113 CamReturn cam_tl_read_all (CamTL *tl, gboolean poll);
114
115 #endif /* CAM_TRANSPORT_H */