xs/DVBT-scan.c

filter: Statementstmt 0.0% 0 / 115 Branchbran 0.0% 0 / 90 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 0.0% 0 / 205 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« xs/DVBT-record.c ↑ Summary xs/shared/DVBT-common.h »
1 # VERSION = "1.001"
2  
3 # /*---------------------------------------------------------------------------------------------------*/
4 # /* Set up for scanning */
5  
6 void
7 dvb_scan_new(DVB *dvb, int verbose)
8 CODE:
9 // init the freq list
10 0 clear_freqlist() ;
11  
12 # /*---------------------------------------------------------------------------------------------------*/
13 # /* Set up for scanning */
14  
15 void
16 dvb_scan_init(DVB *dvb, int verbose)
17 CODE:
18 0 dvb_scan_init(dvb, verbose) ;
19  
20 # /*---------------------------------------------------------------------------------------------------*/
21 # /* Clear up after scanning */
22  
23 void
24 dvb_scan_end(DVB *dvb, int verbose)
25 CODE:
26 /* Free up results */
27 0 dvb_scan_end(dvb, verbose) ;
28  
29 # /*---------------------------------------------------------------------------------------------------*/
30 # /* Scan all frequencies starting from whatever the current tuning is */
31 SV *
32 dvb_scan(DVB *dvb, int verbose)
33  
34 INIT:
35 HV * results;
36  
37 AV * streams ;
38 HV * freqs ;
39 AV * programs ;
40  
41 char key[256] ;
42 char key2[256] ;
43  
44 struct dvbmon *dm ;
45 struct list_head *item, *safe, *pitem, *fitem ;
46 struct psi_program *program ;
47 struct psi_stream *stream;
48 struct prog_info *pinfo ;
49 struct freqitem *freqi;
50 struct freq_info *finfo;
51  
52 0 results = (HV *)sv_2mortal((SV *)newHV());
53  
54 0 streams = (AV *)sv_2mortal((SV *)newAV());
55 0 programs = (AV *)sv_2mortal((SV *)newAV());
56 0 freqs = (HV *)sv_2mortal((SV *)newHV());
57  
58 CODE:
59 /* get info */
60 0 dm = dvb_scan_freqs(dvb, verbose) ;
61  
62 /** Create Perl data **/
63 0 HVS(results, ts, newRV((SV *)streams)) ;
64 0 HVS(results, pr, newRV((SV *)programs)) ;
65 0 HVS(results, freqs, newRV((SV *)freqs)) ;
66  
67 0 ▶ if (DVBT_DEBUG >= 10)
Branch: 1 branch
BranchTrueFalseTotal
if (DVBT_DEBUG >= 10) 0 0 0
68 {
69 0 fprintf(stderr, "\n\n == DVBT.xs::dvb_scan() ================\n") ;
70  
71 }
72  
73 /* Store frequency info */
74 0 ▶ list_for_each(item,&freq_list)
Branch: 1 branch
BranchTrueFalseTotal
list_for_each(item,&freq_list) 0 0 0
75 {
76 HV * fh;
77  
78 0 freqi = list_entry(item, struct freqitem, next);
79  
80 // Only consider valid frequencies
81 0 ▶ if (VALID_FREQ(freqi->frequency))
Branch: 1 branch
BranchTrueFalseTotal
if (VALID_FREQ(freqi->frequency)) 0 0 0
82 {
83  
84 0 ▶ if (DVBT_DEBUG >= 10)
Branch: 1 branch
BranchTrueFalseTotal
if (DVBT_DEBUG >= 10) 0 0 0
85 {
86 0 fprintf(stderr, "#@f FREQ: %d Hz seen=%d tuned=%d (Strength=%d) [",
87 freqi->frequency,
88 0 freqi->flags.seen,
89 0 freqi->flags.tuned,
90 freqi->strength
91 ) ;
92 0 fprintf(stderr, "inv=%d bw=%d crh=%d crl=%d con=%d tr=%d g=%d hi=%d",
93 0 freqi->params.inversion,
94 0 freqi->params.u.ofdm.bandwidth,
95 0 freqi->params.u.ofdm.code_rate_HP,
96 0 freqi->params.u.ofdm.code_rate_LP,
97 0 freqi->params.u.ofdm.constellation,
98 0 freqi->params.u.ofdm.transmission_mode,
99 0 freqi->params.u.ofdm.guard_interval,
100 0 freqi->params.u.ofdm.hierarchy_information
101 ) ;
102 0 fprintf(stderr, "]\n") ;
103 0 fprintf(stderr, "#@f Mod=%d\n", co_t[ freqi->params.u.ofdm.constellation ] );
104 }
105  
106 /* Convert structure fields into hash elements */
107 0 fh = (HV *)sv_2mortal((SV *)newHV());
108  
109 0 HVS_I(fh, freqi, strength) ;
110 0 HVS_I(fh, freqi, ber) ;
111 0 HVS_I(fh, freqi, snr) ;
112 0 HVS(fh, seen, newSViv(freqi->flags.seen)) ;
113 0 HVS(fh, tuned, newSViv(freqi->flags.tuned)) ;
114  
115 // Convert frontend params into VDR values
116 0 HVS_INT(fh, inversion, freqi->params.inversion) ;
117 0 HVS_INT(fh, bandwidth, bw[ freqi->params.u.ofdm.bandwidth ] );
118 0 HVS_INT(fh, code_rate_high, ra_t[ freqi->params.u.ofdm.code_rate_HP ] );
119 0 HVS_INT(fh, code_rate_low, ra_t[ freqi->params.u.ofdm.code_rate_LP ] );
120 0 HVS_INT(fh, modulation, co_t[ freqi->params.u.ofdm.constellation ] );
121 0 HVS_INT(fh, transmission, tr[ freqi->params.u.ofdm.transmission_mode ] );
122 0 HVS_INT(fh, guard_interval, gu[ freqi->params.u.ofdm.guard_interval ] );
123 0 HVS_INT(fh, hierarchy, hi[ freqi->params.u.ofdm.hierarchy_information ] );
124  
125 0 sprintf(key, "%d", freqi->frequency) ;
126 0 hv_store(freqs, key, strlen(key), newRV((SV *)fh), 0) ;
127  
128 } // freq valid
129 } // foreach freq
130  
131  
132  
133 /* Store stream info */
134 0 ▶ list_for_each(item,&dm->info->streams)
Branch: 1 branch
BranchTrueFalseTotal
list_for_each(item,&dm->info->streams) 0 0 0
135 {
136 HV * rh;
137 HV * tsidh;
138 int frequency ;
139  
140 0 stream = list_entry(item, struct psi_stream, next);
141  
142 // round up frequency to nearest kHz
143 // HVS_I(rh, stream, frequency) ;
144 0 frequency = ROUND_FREQUENCY(stream->frequency) ;
145  
146 0 ▶ if (DVBT_DEBUG >= 10)
Branch: 1 branch
BranchTrueFalseTotal
if (DVBT_DEBUG >= 10) 0 0 0
147 {
148 0 fprintf(stderr, "#@f stream: TSID %d freq = %d Hz [%d Hz] : tuned=%d updated=%d\n",
149 stream->tsid,
150 stream->frequency,
151 frequency,
152 stream->tuned,
153 stream->updated
154 ) ;
155 }
156  
157  
158 /*
159 // int tsid;
160 //
161 // // network //
162 // int netid;
163 // char net[PSI_STR_MAX];
164 //
165 // int frequency;
166 // int symbol_rate;
167 // char *bandwidth;
168 // char *constellation;
169 // char *hierarchy;
170 // char *code_rate_hp;
171 // char *code_rate_lp;
172 // char *fec_inner;
173 // char *guard;
174 // char *transmission;
175 // char *polarization;
176 */
177  
178 /* Convert structure fields into hash elements */
179 0 rh = (HV *)sv_2mortal((SV *)newHV());
180 0 tsidh = (HV *)sv_2mortal((SV *)newHV());
181  
182 0 HVS_INT(rh, frequency, frequency) ;
183  
184 0 ▶ HVS_I(rh, stream, tsid) ;
Branch: 1 branch
BranchTrueFalseTotal
HVS_I(rh, stream, tsid) ; 0 0 0
185 0 ▶ HVS_I(rh, stream, netid) ;
Branch: 1 branch
BranchTrueFalseTotal
HVS_I(rh, stream, netid) ; 0 0 0
186 0 ▶ HVS_S(rh, stream, bandwidth) ;
Branch: 1 branch
BranchTrueFalseTotal
HVS_S(rh, stream, bandwidth) ; 0 0 0
187 0 ▶ HVSN_S(rh, stream, code_rate_hp, code_rate_high) ;
Branch: 1 branch
BranchTrueFalseTotal
HVSN_S(rh, stream, code_rate_hp, code_rate_high) ; 0 0 0
188 0 ▶ HVSN_S(rh, stream, code_rate_lp, code_rate_low) ;
Branch: 1 branch
BranchTrueFalseTotal
HVSN_S(rh, stream, code_rate_lp, code_rate_low) ; 0 0 0
189 0 ▶ HVSN_S(rh, stream, constellation, modulation) ;
Branch: 1 branch
BranchTrueFalseTotal
HVSN_S(rh, stream, constellation, modulation) ; 0 0 0
190 0 ▶ HVSN_S(rh, stream, guard, guard_interval) ;
Branch: 1 branch
BranchTrueFalseTotal
HVSN_S(rh, stream, guard, guard_interval) ; 0 0 0
191 0 ▶ HVS_S(rh, stream, hierarchy) ;
Branch: 1 branch
BranchTrueFalseTotal
HVS_S(rh, stream, hierarchy) ; 0 0 0
192 0 ▶ HVS_S(rh, stream, net) ;
Branch: 1 branch
BranchTrueFalseTotal
HVS_S(rh, stream, net) ; 0 0 0
193 0 ▶ HVS_S(rh, stream, transmission) ;
Branch: 1 branch
BranchTrueFalseTotal
HVS_S(rh, stream, transmission) ; 0 0 0
194  
195 /* Process the program lcns attached to this stream
196  
197 'lcn' => {
198  
199 $tsid => {
200  
201 $pnr => {
202 'service_type' => xx,
203 'visible' => yy,
204 'lcn' => zz,
205 }
206 }
207 }
208 */
209 0 ▶ list_for_each(pitem,&stream->prog_info_list)
Branch: 1 branch
BranchTrueFalseTotal
list_for_each(pitem,&stream->prog_info_list) 0 0 0
210 {
211 /* Convert structure fields into hash elements */
212 0 HV * pnrh = (HV *)sv_2mortal((SV *)newHV());
213  
214 0 pinfo = list_entry(pitem, struct prog_info, next);
215  
216 0 ▶ if (DVBT_DEBUG >= 10)
Branch: 1 branch
BranchTrueFalseTotal
if (DVBT_DEBUG >= 10) 0 0 0
217 {
218 0 fprintf(stderr, "#@p + LCN: %d (pnr %d) type=%d visible=%d\n",
219 pinfo->lcn,
220 pinfo->service_id,
221 pinfo->service_type,
222 pinfo->visible
223 ) ;
224 }
225  
226 0 ▶ if (pinfo->lcn > 0)
Branch: 1 branch
BranchTrueFalseTotal
if (pinfo->lcn > 0) 0 0 0
227 {
228 /*
229 int service_id ; # same as pnr
230 int service_type ;
231 int visible ;
232 int lcn ;
233 */
234 0 ▶ HVS_I(pnrh, pinfo, service_type) ;
Branch: 1 branch
BranchTrueFalseTotal
HVS_I(pnrh, pinfo, service_type) ; 0 0 0
235 0 ▶ HVS_I(pnrh, pinfo, visible) ;
Branch: 1 branch
BranchTrueFalseTotal
HVS_I(pnrh, pinfo, visible) ; 0 0 0
236 0 ▶ HVS_I(pnrh, pinfo, lcn) ;
Branch: 1 branch
BranchTrueFalseTotal
HVS_I(pnrh, pinfo, lcn) ; 0 0 0
237  
238 0 sprintf(key2, "%d", pinfo->service_id) ;
239 0 hv_store(tsidh, key2, strlen(key2), newRV((SV *)pnrh), 0) ;
240 }
241 }
242 0 HVS(rh, lcn, newRV((SV *)tsidh)) ;
243  
244 0 av_push(streams, newRV((SV *)rh));
245  
246 }
247  
248 /* store program info */
249 0 ▶ list_for_each(item,&dm->info->programs)
Branch: 1 branch
BranchTrueFalseTotal
list_for_each(item,&dm->info->programs) 0 0 0
250 {
251 0 program = list_entry(item, struct psi_program, next);
252  
253 0 ▶ if (DVBT_DEBUG >= 15)
Branch: 1 branch
BranchTrueFalseTotal
if (DVBT_DEBUG >= 15) 0 0 0
254 {
255 0 print_program(program) ;
256 }
257  
258 /*
259 // int tsid;
260 // int pnr;
261 // int version;
262 // int running;
263 // int ca;
264 //
265 // // program data //
266 // int type;
267 // int p_pid; // program
268 // int v_pid; // video
269 // int a_pid; // audio
270 // int t_pid; // teletext
271 // int s_pid; // subtitle //by rainbowcrypt
272 // char audio[PSI_STR_MAX];
273 // char subtitle[PSI_STR_MAX]; //by rainbowcrypt
274 // char net[PSI_STR_MAX];
275 // char name[PSI_STR_MAX];
276 //
277 // // status info //
278 // int updated;
279 // int seen;
280 */
281  
282 0 ▶ if (DVBT_DEBUG >= 10)
Branch: 1 branch
BranchTrueFalseTotal
if (DVBT_DEBUG >= 10) 0 0 0
283 {
284 0 fprintf(stderr, "#@p PROG %d-%d: %s\n",
285 program->tsid,
286 program->pnr,
287 0 program->name
288 ) ;
289 }
290  
291 /* Only bother saving this if the same is set AND type > 0*/
292 0 ▶ if ((strlen(program->name) > 0) && (program->type > 0))
Branch: 2 branches
BranchTrueFalseTotal
if ((strlen(program->name) > 0) && (program->type > 0)) 0 0 0
if ((strlen(program->name) > 0) && (program->type > 0)) 0 0 0
293 {
294 HV * rh;
295 AV * freq_array;
296 int frequency ;
297  
298 /* Convert structure fields into hash elements */
299 0 rh = (HV *)sv_2mortal((SV *)newHV());
300  
301 0 ▶ if (DVBT_DEBUG >= 10)
Branch: 1 branch
BranchTrueFalseTotal
if (DVBT_DEBUG >= 10) 0 0 0
302 {
303 0 fprintf(stderr, "#@p + PNR %d pmt=%d Video=%d Audio=%d Teletext=%d Subtitle=%d (type=%d)\n", /* by rainbowcrypt*/
304 program->pnr,
305 program->p_pid,
306 program->v_pid,
307 program->a_pid,
308 program->t_pid,
309 program->s_pid, /*by rainbowcrypt*/
310 program->type
311 ) ;
312 }
313  
314 0 ▶ HVS_I(rh, program, tsid) ;
Branch: 1 branch
BranchTrueFalseTotal
HVS_I(rh, program, tsid) ; 0 0 0
315 0 ▶ HVS_I(rh, program, pnr) ;
Branch: 1 branch
BranchTrueFalseTotal
HVS_I(rh, program, pnr) ; 0 0 0
316 0 ▶ HVS_I(rh, program, ca) ;
Branch: 1 branch
BranchTrueFalseTotal
HVS_I(rh, program, ca) ; 0 0 0
317 0 ▶ HVS_I(rh, program, type) ;
Branch: 1 branch
BranchTrueFalseTotal
HVS_I(rh, program, type) ; 0 0 0
318 0 ▶ HVSN_I(rh, program, p_pid, pmt) ;
Branch: 1 branch
BranchTrueFalseTotal
HVSN_I(rh, program, p_pid, pmt) ; 0 0 0
319 0 ▶ HVSN_I(rh, program, v_pid, video) ;
Branch: 1 branch
BranchTrueFalseTotal
HVSN_I(rh, program, v_pid, video) ; 0 0 0
320 0 ▶ HVSN_I(rh, program, a_pid, audio) ;
Branch: 1 branch
BranchTrueFalseTotal
HVSN_I(rh, program, a_pid, audio) ; 0 0 0
321 0 ▶ HVSN_I(rh, program, t_pid, teletext) ;
Branch: 1 branch
BranchTrueFalseTotal
HVSN_I(rh, program, t_pid, teletext) ; 0 0 0
322 0 ▶ HVSN_I(rh, program, s_pid, subtitle) ;
Branch: 1 branch
BranchTrueFalseTotal
HVSN_I(rh, program, s_pid, subtitle) ; 0 0 0
323 0 ▶ HVSN_I(rh, program, pcr_pid, pcr) ;
Branch: 1 branch
BranchTrueFalseTotal
HVSN_I(rh, program, pcr_pid, pcr) ; 0 0 0
324 0 ▶ HVSN_S(rh, program, audio, audio_details) ;
Branch: 1 branch
BranchTrueFalseTotal
HVSN_S(rh, program, audio, audio_details) ; 0 0 0
325 0 ▶ HVSN_S(rh, program, subtitle, subtitle_details) ; /*by rainbowcrypt*/
Branch: 1 branch
BranchTrueFalseTotal
HVSN_S(rh, program, subtitle, subtitle_details) ; /*by rainbowcrypt*/ 0 0 0
326 0 ▶ HVS_S(rh, program, net) ;
Branch: 1 branch
BranchTrueFalseTotal
HVS_S(rh, program, net) ; 0 0 0
327 0 ▶ HVS_S(rh, program, name) ;
Branch: 1 branch
BranchTrueFalseTotal
HVS_S(rh, program, name) ; 0 0 0
328  
329 // add frequencies
330 0 freq_array = (AV *)sv_2mortal((SV *)newAV());
331 0 ▶ list_for_each(fitem,&program->tuned_freq_list) {
Branch: 1 branch
BranchTrueFalseTotal
list_for_each(fitem,&program->tuned_freq_list) { 0 0 0
332 0 finfo = list_entry(fitem, struct freq_info, next);
333  
334 // round up frequency to nearest kHz
335 0 frequency = ROUND_FREQUENCY(finfo->frequency) ;
336  
337 0 ▶ if (DVBT_DEBUG >= 10)
Branch: 1 branch
BranchTrueFalseTotal
if (DVBT_DEBUG >= 10) 0 0 0
338 {
339 0 fprintf(stderr, "#@f + + freq = %d Hz [%d Hz]\n",
340 finfo->frequency, frequency
341 ) ;
342 }
343  
344 0 AVS_I(freq_array, frequency) ;
345 }
346 0 HVS(rh, freqs, newRV((SV *)freq_array)) ;
347  
348 // save entry in list
349 0 av_push(programs, newRV((SV *)rh));
350  
351 }
352 }
353  
354 0 ▶ if (DVBT_DEBUG >= 10)
Branch: 1 branch
BranchTrueFalseTotal
if (DVBT_DEBUG >= 10) 0 0 0
355 {
356 0 fprintf(stderr, "\n\n == DVBT.xs::dvb_scan() - END =============\n") ;
357 }
358  
359  
360 0 RETVAL = newRV((SV *)results);
361 OUTPUT:
362 RETVAL
363  
« xs/DVBT-record.c ↑ Summary xs/shared/DVBT-common.h »