~ubuntu-branches/ubuntu/precise/me-tv/precise-proposed

« back to all changes in this revision

Viewing changes to src/libucsi/dvb/vbi_data_descriptor.h

  • Committer: Bazaar Package Importer
  • Author(s): Philipp Kern
  • Date: 2008-07-23 14:03:56 UTC
  • mfrom: (1.1.3 upstream) (3.1.1 lenny)
  • Revision ID: james.westby@ubuntu.com-20080723140356-m6ze7fbkydes42c7
Tags: 0.5.33-3
Fix xine-lib ffmpeg dependency.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * section and descriptor parser
3
 
 *
4
 
 * Copyright (C) 2005 Kenneth Aafloy (kenneth@linuxtv.org)
5
 
 * Copyright (C) 2005 Andrew de Quincey (adq_dvb@lidskialf.net)
6
 
 *
7
 
 * This library is free software; you can redistribute it and/or
8
 
 * modify it under the terms of the GNU Lesser General Public
9
 
 * License as published by the Free Software Foundation; either
10
 
 * version 2.1 of the License, or (at your option) any later version.
11
 
 *
12
 
 * This library is distributed in the hope that it will be useful,
13
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15
 
 * Lesser General Public License for more details.
16
 
 *
17
 
 * You should have received a copy of the GNU Lesser General Public
18
 
 * License along with this library; if not, write to the Free Software
19
 
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
20
 
 */
21
 
 
22
 
#ifndef _UCSI_DVB_VBI_DATA_DESCRIPTOR
23
 
#define _UCSI_DVB_VBI_DATA_DESCRIPTOR 1
24
 
 
25
 
#ifdef __cplusplus
26
 
extern "C"
27
 
{
28
 
#endif
29
 
 
30
 
#include <libucsi/descriptor.h>
31
 
#include <libucsi/endianops.h>
32
 
 
33
 
/**
34
 
 * Possible values for the data_service_id field.
35
 
 */
36
 
enum {
37
 
        DVB_VBI_DATA_SERVICE_ID_EBU             = 0x01,
38
 
        DVB_VBI_DATA_SERVICE_ID_INVERTED        = 0x02,
39
 
        DVB_VBI_DATA_SERVICE_ID_VPS             = 0x04,
40
 
        DVB_VBI_DATA_SERVICE_ID_WSS             = 0x05,
41
 
        DVB_VBI_DATA_SERVICE_ID_CC              = 0x06,
42
 
        DVB_VBI_DATA_SERVICE_ID_MONO_422        = 0x07,
43
 
};
44
 
 
45
 
/**
46
 
 * dvb_vbi_data_descriptor structure
47
 
 */
48
 
struct dvb_vbi_data_descriptor {
49
 
        struct descriptor d;
50
 
 
51
 
        /* struct dvb_vbi_data_entry entries[] */
52
 
} __ucsi_packed;
53
 
 
54
 
/**
55
 
 * An entry in the dvb_vbi_data_descriptor entries field.
56
 
 */
57
 
struct dvb_vbi_data_entry {
58
 
        uint8_t data_service_id;
59
 
        uint8_t data_length;
60
 
        /* uint8_t data[] */
61
 
} __ucsi_packed;
62
 
 
63
 
/**
64
 
 * Format of the dvb_vbi_data_entry data field, if data_service_id == 1,2,4,5,6,7.
65
 
 */
66
 
struct dvb_vbi_data_x {
67
 
  EBIT3(uint8_t reserved        : 2; ,
68
 
        uint8_t field_parity    : 1; ,
69
 
        uint8_t line_offset     : 5; );
70
 
} __ucsi_packed;
71
 
 
72
 
/**
73
 
 * Process a dvb_vbi_data_descriptor.
74
 
 *
75
 
 * @param d Generic descriptor structure.
76
 
 * @return dvb_vbi_data_descriptor pointer, or NULL on error.
77
 
 */
78
 
static inline struct dvb_vbi_data_descriptor*
79
 
        dvb_vbi_data_descriptor_codec(struct descriptor* d)
80
 
{
81
 
        uint8_t* p = (uint8_t*) d + 2;
82
 
        uint32_t pos = 0;
83
 
        uint32_t len = d->len;
84
 
 
85
 
        while(pos < len) {
86
 
                struct dvb_vbi_data_entry *e =
87
 
                        (struct dvb_vbi_data_entry*) (p+pos);
88
 
 
89
 
                pos += sizeof(struct dvb_vbi_data_entry);
90
 
 
91
 
                if (pos > len)
92
 
                        return NULL;
93
 
 
94
 
                pos += e->data_length;
95
 
 
96
 
                if (pos > len)
97
 
                        return NULL;
98
 
        }
99
 
 
100
 
        return (struct dvb_vbi_data_descriptor*) d;
101
 
}
102
 
 
103
 
/**
104
 
 * Iterator for entries field in a dvb_vbi_data_descriptor structure.
105
 
 *
106
 
 * @param d Pointer to dvb_vbi_data_descriptor structure.
107
 
 * @param pos Variable holding pointer to the current dvb_vbi_data_entry structure.
108
 
 */
109
 
#define dvb_vbi_data_descriptor_entries_for_each(d, pos) \
110
 
        for ((pos) = dvb_vbi_data_descriptor_entries_first(d); \
111
 
             (pos); \
112
 
             (pos) = dvb_vbi_data_descriptor_entries_next(d, pos))
113
 
 
114
 
/**
115
 
 * Get a pointer to the data field of a dvb_vbi_data_entry.
116
 
 *
117
 
 * @param d dvb_vbi_data_entry structure.
118
 
 * @return Pointer to the data field.
119
 
 */
120
 
static inline uint8_t *
121
 
        dvb_vbi_data_entry_data(struct dvb_vbi_data_entry *d)
122
 
{
123
 
        return (uint8_t *) d + sizeof(struct dvb_vbi_data_entry);
124
 
}
125
 
 
126
 
/**
127
 
 * Get a pointer to the data field of a dvb_vbi_data_x for id 1,2,4,5,6,7.
128
 
 *
129
 
 * @param d dvb_vbi_data_entry structure.
130
 
 * @return Pointer to the data field, or NULL if invalid
131
 
 */
132
 
static inline struct dvb_vbi_data_x*
133
 
        dvb_vbi_data_entry_data_x(struct dvb_vbi_data_entry *d)
134
 
{
135
 
        switch(d->data_service_id) {
136
 
        case 1:
137
 
        case 2:
138
 
        case 4:
139
 
        case 5:
140
 
        case 6:
141
 
        case 7:
142
 
                return (struct dvb_vbi_data_x*) ((uint8_t *) d + sizeof(struct dvb_vbi_data_entry));
143
 
        }
144
 
 
145
 
        return NULL;
146
 
}
147
 
 
148
 
 
149
 
 
150
 
 
151
 
 
152
 
 
153
 
 
154
 
 
155
 
 
156
 
 
157
 
/******************************** PRIVATE CODE ********************************/
158
 
static inline struct dvb_vbi_data_entry*
159
 
        dvb_vbi_data_descriptor_entries_first(struct dvb_vbi_data_descriptor *d)
160
 
{
161
 
        if (d->d.len == 0)
162
 
                return NULL;
163
 
 
164
 
        return (struct dvb_vbi_data_entry *)
165
 
                ((uint8_t*) d + sizeof(struct dvb_vbi_data_descriptor));
166
 
}
167
 
 
168
 
static inline struct dvb_vbi_data_entry*
169
 
        dvb_vbi_data_descriptor_entries_next(struct dvb_vbi_data_descriptor *d,
170
 
                                             struct dvb_vbi_data_entry *pos)
171
 
{
172
 
        uint8_t *end = (uint8_t*) d + 2 + d->d.len;
173
 
        uint8_t *next = (uint8_t *) pos + sizeof(struct dvb_vbi_data_entry) +
174
 
                        pos->data_length;
175
 
 
176
 
        if (next >= end)
177
 
                return NULL;
178
 
 
179
 
        return (struct dvb_vbi_data_entry *) next;
180
 
}
181
 
 
182
 
#ifdef __cplusplus
183
 
}
184
 
#endif
185
 
 
186
 
#endif