1 diff --git a/src/streamproxy.c b/src/streamproxy.c
2 index 3f82412..321d9c9 100644
3 --- a/src/streamproxy.c
4 +++ b/src/streamproxy.c
5 @@ -42,6 +42,25 @@ char *reason = "";
7 int active_pids[MAX_PIDS];
21 +struct proc_dmx_pid proc_dmx_setup[] = {
22 + {"/proc/stb/encoder/0/video_pid", "video", 0},
23 + {"/proc/stb/encoder/0/audio_pid", "audio", 0},
24 + {"/proc/stb/encoder/0/pcr_pid", "pcr", 0},
25 + {"/proc/stb/encoder/0/pmt_pid", "pmt", 0},
28 int handle_upstream(void);
29 int handle_upstream_line(void);
31 @@ -81,6 +100,7 @@ int main(int argc, char **argv)
33 for (i=0; i<MAX_PIDS; ++i)
39 @@ -113,6 +133,8 @@ int main(int argc, char **argv)
43 + memset(upstream_request, 0, 256);
45 snprintf(upstream_request, sizeof(upstream_request), "GET /web/stream?StreamService=%s HTTP/1.0\r\n%s%s\r\n", service_ref, xff_header, authorization);
47 if (write(upstream, upstream_request, strlen(upstream_request)) != strlen(upstream_request))
48 @@ -168,6 +190,7 @@ bad_gateway:
49 int handle_upstream(void)
51 char buffer[MAX_LINE_LENGTH];
52 + memset(buffer, 0, MAX_LINE_LENGTH);
53 int n = read(upstream, buffer, MAX_LINE_LENGTH);
56 @@ -180,6 +203,7 @@ int handle_upstream(void)
64 @@ -218,6 +242,9 @@ int handle_upstream(void)
66 int handle_upstream_line(void)
71 switch (upstream_state)
74 @@ -244,104 +271,137 @@ int handle_upstream_line(void)
75 if (response_line[0] == '+') {
76 /* parse (and possibly open) demux */
77 int demux = atoi(response_line + 1);
80 + FILE *f = fopen("/proc/stb/encoder/0/demux", "w");
83 + fprintf(f, "%d\n", demux);
88 - /* parse new pids */
89 - const char *p = strchr(response_line, ':');
90 - int old_active_pids[MAX_PIDS];
92 - memcpy(old_active_pids, active_pids, sizeof(active_pids));
94 - int nr_pids = 0, i, j;
96 + for(i = 0 ; i < sizeof(proc_dmx_setup)/sizeof(proc_dmx_setup[0]) ; i++)
99 - int pid = strtoul(p, 0, 0x10);
100 - p = strchr(p, ',');
101 + str = strstr(response_line, proc_dmx_setup[i].str_match);
104 + while(*str != ',') str--;
105 + proc_dmx_setup[i].pid = strtoul(str+1, 0, 0x10);
106 + FILE *f = fopen(proc_dmx_setup[i].proc_path, "w");
109 + fprintf(f, "%d\n", proc_dmx_setup[i].pid);
114 - /* do not add pids twice */
115 - for (i = 0; i < nr_pids; ++i)
116 - if (active_pids[i] == pid)
123 - active_pids[nr_pids++] = pid;
124 + if(proc_dmx_setup[3].pid && ( (g_video_pid != proc_dmx_setup[0].pid) || (g_audio_pid != proc_dmx_setup[1].pid) || (g_pcr_pid != proc_dmx_setup[2].pid)) )
126 + g_video_pid = proc_dmx_setup[0].pid;
127 + g_audio_pid = proc_dmx_setup[1].pid;
128 + g_pcr_pid = proc_dmx_setup[2].pid;
131 + /* parse new pids */
132 + const char *p = strchr(response_line, ':');
133 + int old_active_pids[MAX_PIDS];
135 - if (nr_pids == MAX_PIDS)
139 - for (i = nr_pids; i < MAX_PIDS; ++i)
140 - active_pids[i] = -1;
141 + memcpy(old_active_pids, active_pids, sizeof(active_pids));
143 - /* check for added pids */
144 - for (i = 0; i < nr_pids; ++i)
146 - for (j = 0; j < MAX_PIDS; ++j)
147 - if (active_pids[i] == old_active_pids[j])
148 + int nr_pids = 0, i, j;
152 + int pid = strtoul(p, 0, 0x10);
153 + p = strchr(p, ',');
155 + /* do not add pids twice */
156 + for (i = 0; i < nr_pids; ++i)
157 + if (active_pids[i] == pid)
163 + active_pids[nr_pids++] = pid;
165 + if (nr_pids == MAX_PIDS)
167 - if (j == MAX_PIDS) {
168 - if (demux_fd < 0) {
169 - struct dmx_pes_filter_params flt;
171 - sprintf(demuxfn, "/dev/dvb/adapter0/demux%d", demux);
172 - demux_fd = open(demuxfn, O_RDWR | O_NONBLOCK);
175 + for (i = nr_pids; i < MAX_PIDS; ++i)
176 + active_pids[i] = -1;
178 + /* check for added pids */
179 + for (i = 0; i < nr_pids; ++i)
181 + for (j = 0; j < MAX_PIDS; ++j)
182 + if (active_pids[i] == old_active_pids[j])
184 + if (j == MAX_PIDS) {
186 - reason = "DEMUX OPEN FAILED";
189 + struct dmx_pes_filter_params flt;
191 + sprintf(demuxfn, "/dev/dvb/adapter0/demux%d", demux);
192 + demux_fd = open(demuxfn, O_RDWR | O_NONBLOCK);
193 + if (demux_fd < 0) {
194 + reason = "DEMUX OPEN FAILED";
198 - ioctl(demux_fd, DMX_SET_BUFFER_SIZE, 1024*1024);
199 + ioctl(demux_fd, DMX_SET_BUFFER_SIZE, 1024*1024);
201 - flt.pid = active_pids[i];
202 - flt.input = DMX_IN_FRONTEND;
203 + flt.pid = active_pids[i];
204 + flt.input = DMX_IN_FRONTEND;
205 #if DVB_API_VERSION > 3
206 - flt.output = DMX_OUT_TSDEMUX_TAP;
207 - flt.pes_type = DMX_PES_OTHER;
208 + flt.output = DMX_OUT_TSDEMUX_TAP;
209 + flt.pes_type = DMX_PES_OTHER;
211 - flt.output = DMX_OUT_TAP;
212 - flt.pes_type = DMX_TAP_TS;
213 + flt.output = DMX_OUT_TAP;
214 + flt.pes_type = DMX_TAP_TS;
216 - flt.flags = DMX_IMMEDIATE_START;
217 + flt.flags = DMX_IMMEDIATE_START;
219 - if (ioctl(demux_fd, DMX_SET_PES_FILTER, &flt) < 0) {
220 - reason = "DEMUX PES FILTER SET FAILED";
222 + if (ioctl(demux_fd, DMX_SET_PES_FILTER, &flt) < 0) {
223 + reason = "DEMUX PES FILTER SET FAILED";
229 - uint16_t pid = active_pids[i];
232 + uint16_t pid = active_pids[i];
234 #if DVB_API_VERSION > 3
235 - ret = ioctl(demux_fd, DMX_ADD_PID, &pid);
236 + ret = ioctl(demux_fd, DMX_ADD_PID, &pid);
238 - ret = ioctl(demux_fd, DMX_ADD_PID, pid);
239 + ret = ioctl(demux_fd, DMX_ADD_PID, pid);
242 - reason = "DMX_ADD_PID FAILED";
245 + reason = "DMX_ADD_PID FAILED";
253 - /* check for removed pids */
254 - for (i = 0; i < MAX_PIDS; ++i)
256 - if (old_active_pids[i] == -1)
258 - for (j = 0; j < nr_pids; ++j)
259 - if (old_active_pids[i] == active_pids[j])
261 - if (j == nr_pids) {
263 + /* check for removed pids */
264 + for (i = 0; i < MAX_PIDS; ++i)
266 + if (old_active_pids[i] == -1)
268 + for (j = 0; j < nr_pids; ++j)
269 + if (old_active_pids[i] == active_pids[j])
271 + if (j == nr_pids) {
272 #if DVB_API_VERSION > 3
273 - uint16_t pid = old_active_pids[i];
274 - ioctl(demux_fd, DMX_REMOVE_PID, &pid);
275 + uint16_t pid = old_active_pids[i];
276 + ioctl(demux_fd, DMX_REMOVE_PID, &pid);
278 - ioctl(demux_fd, DMX_REMOVE_PID, old_active_pids[i]);
279 + ioctl(demux_fd, DMX_REMOVE_PID, old_active_pids[i]);
284 if (upstream_state == 2) {