Menu

[cc842c]: / vdr-dsmcc / dsmcc-decoder.c  Maximize  Restore  History

Download this file

141 lines (110 with data), 3.5 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#include <stdlib.h>
#include <zlib.h>
#include <vdr/receiver.h>
#include "dsmcc-decoder.h"
#include "libdsmcc.h"
// #include <mpatrol.h>
cDsmccReceiver::cDsmccReceiver(const char *channel) : cReceiver(0, -1, 0) {
if(channel != '\0') {
name = (char*)malloc(strlen(channel)+1);
strcpy(name, channel);
} else {
name = (char*)malloc(7+1);
strcpy(name, "Unknown");
}
status = dsmcc_open(channel, NULL); /* XXX pass log_fd */
scanning = 1; /* Set to 1 to scan thorugh all channels for carousel
Set to 0 to disable
*/
}
cDsmccReceiver::~cDsmccReceiver() {
/* Free any carousel data and cached data.
* TODO - actually cache on disk the cache data
* TODO - more terrible memory madness, this all needs improving
*/
/* Free any unattached streams */
if(name)
free(name);
// if(debug_fd != NULL) fclose(debug_fd);
// if(test_fd != NULL) fclose(test_fd);
Detach(); /* TODO ??? */
}
bool cDsmccReceiver::Active() {
return active;
}
void cDsmccReceiver::Activate(bool On) {
;
}
void cDsmccReceiver::AddStream(struct dsmcc_status *status, int pid) {
struct pid_buffer *buf, *lbuf;
for(lbuf=status->buffers;lbuf!=NULL;lbuf=lbuf->next) {
if(lbuf->pid == pid) { return; }
}
// esyslog("Created buffer for pid %d\n", pid);
buf = (struct pid_buffer *)malloc(sizeof(struct pid_buffer));
buf->pid = pid;
buf->pointer_field = 0;
buf->in_section = 0;
buf->cont = -1;
buf->next = NULL;
if(status->buffers == NULL) {
status->buffers = buf;
} else {
for(lbuf=status->buffers;lbuf->next!=NULL;lbuf=lbuf->next) { ; }
lbuf->next = buf;
}
AddPid(pid);
if(!Active()) {
Start();
active = true;
}
}
/* Start of new logging stuff */
#define ilog(a...)
#define dlog(a...)
#define elog(a...)
void cDsmccReceiver::Receive(uchar *Data, int Length) {
int full_cache = 0;
int i;
dsmcc_receive(status, Data, Length);
for(i=0;i<MAXCAROUSELS;i++) {
if(status->carousels[i].streams != NULL) {
if((status->carousels[i].filecache->total_files > 0) && ((status->carousels[i].filecache->num_files <= 0) && (status->carousels[i].filecache->num_dirs <= 0))) {
full_cache = 1;
esyslog("Finished receiving cache for carousel %d", i);
} else {
full_cache = 0;
}
}
}
if(full_cache & scanning) {
// esyslog("Detaching receiver");
Detach();
active = false;
/*
cDevice *dev;
// esyslog("Switching channel after full cache");
dev = cDevice::PrimaryDevice();
result = dev->SwitchChannel(1);
if(result == false) {
Gone through all channels
// esyslog("Finished switching channels for cache");
scanning = 0;
}
*/
}
if(status->newstreams) {
struct stream *s;
for(s=status->newstreams;s!=NULL;s=s->next) {
AddStream(status, s->pid);
}
if(status->streams == NULL) {
status->streams = status->newstreams;
} else {
struct stream *str;
for(str=status->streams;str!=NULL;str=str->next){;}
str->next = status->newstreams;
}
status->newstreams = NULL;
}
}