2
en50221 encoder An implementation for libdvb
3
an implementation for the en50221 transport layer
5
Copyright (C) 2004, 2005 Manu Abraham <abraham.manu@gmail.com>
6
Copyright (C) 2005 Julian Scheel (julian at jusst dot de)
7
Copyright (C) 2006 Andrew de Quincey (adq_dvb@lidskialf.net)
9
This library is free software; you can redistribute it and/or modify
10
it under the terms of the GNU Lesser General Public License as
11
published by the Free Software Foundation; either version 2.1 of
12
the License, or (at your option) any later version.
14
This program is distributed in the hope that it will be useful,
15
but WITHOUT ANY WARRANTY; without even the implied warranty of
16
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
GNU Lesser General Public License for more details.
19
You should have received a copy of the GNU Lesser General Public
20
License along with this library; if not, write to the Free Software
21
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25
#include <libdvbmisc/dvbmisc.h>
27
#include "en50221_app_teletext.h"
28
#include "en50221_app_tags.h"
31
struct en50221_app_teletext {
32
struct en50221_app_send_functions *funcs;
34
en50221_app_teletext_callback callback;
40
static int en50221_app_teletext_parse_ebu(struct en50221_app_teletext *teletext,
42
uint16_t session_number,
44
uint32_t data_length);
48
struct en50221_app_teletext *
49
en50221_app_teletext_create(struct en50221_app_send_functions *funcs)
51
struct en50221_app_teletext *teletext = NULL;
53
// create structure and set it up
54
teletext = malloc(sizeof(struct en50221_app_teletext));
55
if (teletext == NULL) {
58
teletext->funcs = funcs;
59
teletext->callback = NULL;
61
pthread_mutex_init(&teletext->lock, NULL);
67
void en50221_app_teletext_destroy(struct en50221_app_teletext *teletext)
69
pthread_mutex_destroy(&teletext->lock);
73
void en50221_app_teletext_register_callback(struct en50221_app_teletext *teletext,
74
en50221_app_teletext_callback callback, void *arg)
76
pthread_mutex_lock(&teletext->lock);
77
teletext->callback = callback;
78
teletext->callback_arg = arg;
79
pthread_mutex_unlock(&teletext->lock);
82
int en50221_app_teletext_message(struct en50221_app_teletext *teletext,
84
uint16_t session_number,
86
uint8_t * data, uint32_t data_length)
91
if (data_length < 3) {
92
print(LOG_LEVEL, ERROR, 1, "Received short data\n");
95
uint32_t tag = (data[0] << 16) | (data[1] << 8) | data[2];
98
case TAG_TELETEXT_EBU:
99
return en50221_app_teletext_parse_ebu(teletext, slot_id,
105
print(LOG_LEVEL, ERROR, 1, "Received unexpected tag %x\n", tag);
110
static int en50221_app_teletext_parse_ebu(struct en50221_app_teletext *teletext,
112
uint16_t session_number,
114
uint32_t data_length)
116
// first of all, decode the length field
117
uint16_t asn_data_length;
118
int length_field_len;
119
if ((length_field_len = asn_1_decode(&asn_data_length, data, data_length)) < 0) {
120
print(LOG_LEVEL, ERROR, 1, "ASN.1 decode error\n");
125
if (asn_data_length > (data_length - length_field_len)) {
126
print(LOG_LEVEL, ERROR, 1, "Received short data\n");
129
uint8_t *teletext_data = data + length_field_len;
132
pthread_mutex_lock(&teletext->lock);
133
en50221_app_teletext_callback cb = teletext->callback;
134
void *cb_arg = teletext->callback_arg;
135
pthread_mutex_unlock(&teletext->lock);
137
return cb(cb_arg, slot_id, session_number, teletext_data,