xs/DVBT-ad-tie-c.c

filter: Statementstmt 78.7% 163 / 207 Branchbran 38.8% 49 / 126 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 63.6% 212 / 333 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« xs/DVBT-advert.c ↑ Summary xs/DVBT-advert-c.c »
1 // VERSION = "1.003"
2 //
3 // There are 2 types of tied arrays supported: ADATA and FILTERED
4 //
5 // ADATA is basically a link to the results list after running detection. It manages the user_data
6 // structure and frees it up when finished. This must be available for the lifetime of the analysis.
7 //
8 // FILTERED is a filtered view of all the results - i.e. is those entries where a particular parameter
9 // is >= a threshold. This list contains just the frame number to point at the results list (in ADATA)
10 // along with some extra info like frame_end and gap. These arrays are created and destroyed at will
11 //
12 //
13
14
15 // Standard C code loaded outside XS space. Implements tied HASH connected to advert detect data
16 #include "ts_advert.h"
17 #include "ts_cut.h"
18 #include "ts_split.h"
19
20
21 //========================================================================================================
22 // CONSTANTS
23 //========================================================================================================
24
25 #define XSCLASS "Linux::DVB::DVBT::Advert"
26 #define MAXKEY 256
27
28 //#define DBG_ADAV
29 //#define DBG_ADAV_DEV stdout
30 #define DBG_ADAV_DEV stderr
31
32 //========================================================================================================
33 // TYPES
34 //========================================================================================================
35
36 //---------------------------------------------------------------------------------------------------------
37 enum Adav_type {ADAV_NULL=0, ADAV_ADATA, ADAV_FILTERED, ADAV_LOGO, ADAV_CSV} ;
38 enum Adav_sig {
39 ADA_SIGNATURE = 0x41444824,
40 ADA_FREE_SIGNATURE = 0xDEADC0DE
41 } ;
42
43 static char *adav_types[8] = {
44 [0 ... 7] = "UNKNOWN",
45 [ADAV_NULL] = "ADAV_NULL",
46 [ADAV_ADATA] = "ADAV_ADATA",
47 [ADAV_FILTERED] = "ADAV_FILTERED",
48 [ADAV_LOGO] = "ADAV_LOGO",
49 [ADAV_CSV] = "ADAV_CSV",
50 } ;
51
52 //---------------------------------------------------------------------------------------------------------
53 struct adav_element {
54 unsigned frame ;
55 unsigned frame_end ;
56 int gap ;
57
58 } ;
59
60 //---------------------------------------------------------------------------------------------------------
61 struct adav_logo_element {
62 unsigned frame ;
63 unsigned frame_end ;
64 int gap ;
65
66 // these values over ride the real results
67 unsigned match_percent ;
68 unsigned ave_percent ;
69 } ;
70
71 //---------------------------------------------------------------------------------------------------------
72 struct adav_csv_element {
73 unsigned frame ;
74 // unsigned frame_end ;
75 HV *hv ;
76 } ;
77
78
79 //---------------------------------------------------------------------------------------------------------
80 struct adav_filter {
81 char key[MAXKEY] ;
82 struct adav_element *data ;
83 unsigned num_elems ;
84 } ;
85
86 //---------------------------------------------------------------------------------------------------------
87 struct adav_logo {
88 struct adav_logo_element *data ;
89 unsigned num_elems ;
90 unsigned num_alloc ;
91 } ;
92
93 //---------------------------------------------------------------------------------------------------------
94 struct adav_csv {
95 struct adav_csv_element *data ;
96 unsigned num_elems ;
97 } ;
98
99
100 //---------------------------------------------------------------------------------------------------------
101 typedef struct {
102 // Advert detect user_data
103 Adata *user_data;
104
105 enum Adav_sig signature;
106 enum Adav_type type ;
107
108 union {
109 struct adav_filter filter_data ;
110 struct adav_logo logo_data ;
111 struct adav_csv csv_data ;
112 } ;
113
114 } ADAV;
115
116
117 //========================================================================================================
118 // MACROS
119 //========================================================================================================
120
121 //---------------------------------------------------------------------------------------------------------
122 #define ADA_METHOD( name ) const char * const method = #name
123
124 #define ADA_CHECK_OBJECT(OBJ) \
125 do { \
126 if (OBJ == NULL ) \
127 Perl_croak(aTHX_ "NULL OBJECT IN " XSCLASS "::%s", method); \
128 if (OBJ->signature != ADA_SIGNATURE) \
129 { \
130 if (OBJ->signature == ADA_FREE_SIGNATURE) \
131 Perl_croak(aTHX_ "DEAD OBJECT IN " XSCLASS "::%s", method); \
132 Perl_croak(aTHX_ "INVALID OBJECT IN " XSCLASS "::%s", method); \
133 } \
134 if (OBJ->user_data == NULL || OBJ->type == ADAV_NULL) \
135 Perl_croak(aTHX_ "OBJECT INCONSITENCY IN " XSCLASS "::%s", method);\
136 } while (0)
137
138 #define ADA_CHECK_THIS ADA_CHECK_OBJECT(THIS) ; ada_dbg_printf("== ADAV::%s [%p] type=%s ==\n", method, THIS, adav_types[THIS->type])
139 #define ADA_END_THIS ada_dbg_printf("== ADAV::%s [%p] - END ==\n", method, THIS)
140 #define ADA_CHECK_THIS_NODBG ADA_CHECK_OBJECT(THIS)
141 #define ADA_FREE(PTR) ada_dbg_printf("ADAV free [%p]\n", PTR) ; free(PTR)
142
143 #define ADA_UNEXPECTED_CALL die("Unexpected call to ADAV::%s!", method)
144
145 #ifdef DBG_ADAV
146 static void ada_dbg_printf(char *f, ...)
147 {
148 va_list l;
149 va_start(l, f);
150 vfprintf(DBG_ADAV_DEV, f, l);
151 va_end(l);
152 }
153 #else
154 766 static void ada_dbg_printf(char *f, ...) {}
155 #endif
156
157 //---------------------------------------------------------------------------------------------------------
158
159 #define _GET_OFFSET(KEY, NAME) \
160 else if (strcmp(key, #KEY) == 0) \
161 { \
162 offset = (void *)&results->NAME ; \
163 key_offset = (int)(offset - base) ; \
164 }
165
166
167 #define GET_OFFSET(NAME) _GET_OFFSET(NAME, NAME)
168 #define GET_FRAME_OFFSET(NAME) _GET_OFFSET(NAME, frame_results.NAME)
169 #define GET_LOGO_OFFSET(NAME) _GET_OFFSET(NAME, logo_results.NAME)
170 #define GET_AUDIO_OFFSET(NAME) _GET_OFFSET(NAME, audio_results.NAME)
171
172
173 /*
174
175 #-----------------------------------------------------------------------------
176 # Set the gap counts - the distance each frame is from it's previous frame
177 #
178 # numframes=n' numframes=n
179 # |------------>| |----------->|
180 # |<--------------------|
181 # _............ gap _...........
182 # | | : | | :
183 # ___________| |___________:_____________________| |__________:____
184 # ^ ^ ^
185 # frame=f' frame_end=e' frame=f
186 #
187 #
188 # | f' ..... e' | e'+1 ......... f-1 |
189 # |------------>|
190 # n'=e'-f'+1 |
191 # |<--------------------|
192 # gap = (f-1) - (e'+1) + 1
193 #
194 #
195 #
196 # For frame f:
197 #
198 # gap = f - e' - 1
199 #
200
201 */
202
203 #define CALC_GAP(FRAME, PREV) (FRAME - PREV -1)
204
205 //========================================================================================================
206 // COMMON FUNCTIONS
207 //========================================================================================================
208
209 //---------------------------------------------------------------------------------------------------------
210 11 static void clear_adav(ADAV *this)
211 {
212 11 this->user_data = 0 ;
213 11 this->signature = ADA_FREE_SIGNATURE ;
214 11 this->type = ADAV_NULL ;
215 11 }
216
217
218
219 //========================================================================================================
220 // FILTERED FUNCTIONS
221 //========================================================================================================
222
223 //---------------------------------------------------------------------------------------------------------
224 2 static int get_key_offset(Adata *user_data, char *key)
225 {
226 2 int key_offset = -1 ;
227 2 struct Ad_results *results = user_data->results_list[0].results ;
228 2 int *base = (int *)results ;
229 int *offset ;
230
231 2 ▶ if (!key || (strlen(key)==0) )
Branch: 2 branches
BranchTrueFalseTotal
if (!key || (strlen(key)==0) ) 2 0 2
if (!key || (strlen(key)==0) ) 2 0 2
232 {
233 2 return key_offset ;
234 }
235 0 ▶ GET_FRAME_OFFSET(black_frame)
Branch: 1 branch
BranchTrueFalseTotal
GET_FRAME_OFFSET(black_frame) 0 0 0
236 0 ▶ GET_FRAME_OFFSET(scene_frame)
Branch: 1 branch
BranchTrueFalseTotal
GET_FRAME_OFFSET(scene_frame) 0 0 0
237 0 ▶ GET_FRAME_OFFSET(size_change)
Branch: 1 branch
BranchTrueFalseTotal
GET_FRAME_OFFSET(size_change) 0 0 0
238 0 ▶ GET_FRAME_OFFSET(screen_width)
Branch: 1 branch
BranchTrueFalseTotal
GET_FRAME_OFFSET(screen_width) 0 0 0
239 0 ▶ GET_FRAME_OFFSET(screen_height)
Branch: 1 branch
BranchTrueFalseTotal
GET_FRAME_OFFSET(screen_height) 0 0 0
240 0 ▶ GET_FRAME_OFFSET(brightness)
Branch: 1 branch
BranchTrueFalseTotal
GET_FRAME_OFFSET(brightness) 0 0 0
241 0 ▶ GET_FRAME_OFFSET(uniform)
Branch: 1 branch
BranchTrueFalseTotal
GET_FRAME_OFFSET(uniform) 0 0 0
242 0 ▶ GET_FRAME_OFFSET(dimCount)
Branch: 1 branch
BranchTrueFalseTotal
GET_FRAME_OFFSET(dimCount) 0 0 0
243 0 ▶ GET_FRAME_OFFSET(sceneChangePercent)
Branch: 1 branch
BranchTrueFalseTotal
GET_FRAME_OFFSET(sceneChangePercent) 0 0 0
244
245 0 ▶ GET_LOGO_OFFSET(logo_frame)
Branch: 1 branch
BranchTrueFalseTotal
GET_LOGO_OFFSET(logo_frame) 0 0 0
246 0 ▶ GET_LOGO_OFFSET(match_percent)
Branch: 1 branch
BranchTrueFalseTotal
GET_LOGO_OFFSET(match_percent) 0 0 0
247 0 ▶ GET_LOGO_OFFSET(ave_percent)
Branch: 1 branch
BranchTrueFalseTotal
GET_LOGO_OFFSET(ave_percent) 0 0 0
248
249 0 ▶ GET_AUDIO_OFFSET(audio_framenum)
Branch: 1 branch
BranchTrueFalseTotal
GET_AUDIO_OFFSET(audio_framenum) 0 0 0
250 0 ▶ GET_AUDIO_OFFSET(volume)
Branch: 1 branch
BranchTrueFalseTotal
GET_AUDIO_OFFSET(volume) 0 0 0
251 0 ▶ GET_AUDIO_OFFSET(max_volume)
Branch: 1 branch
BranchTrueFalseTotal
GET_AUDIO_OFFSET(max_volume) 0 0 0
252 0 ▶ GET_AUDIO_OFFSET(sample_rate)
Branch: 1 branch
BranchTrueFalseTotal
GET_AUDIO_OFFSET(sample_rate) 0 0 0
253 0 ▶ GET_AUDIO_OFFSET(channels)
Branch: 1 branch
BranchTrueFalseTotal
GET_AUDIO_OFFSET(channels) 0 0 0
254 0 ▶ GET_AUDIO_OFFSET(samples_per_frame)
Branch: 1 branch
BranchTrueFalseTotal
GET_AUDIO_OFFSET(samples_per_frame) 0 0 0
255 0 ▶ GET_AUDIO_OFFSET(samples)
Branch: 1 branch
BranchTrueFalseTotal
GET_AUDIO_OFFSET(samples) 0 0 0
256 0 ▶ GET_AUDIO_OFFSET(framesize)
Branch: 1 branch
BranchTrueFalseTotal
GET_AUDIO_OFFSET(framesize) 0 0 0
257 0 ▶ GET_AUDIO_OFFSET(volume_dB)
Branch: 1 branch
BranchTrueFalseTotal
GET_AUDIO_OFFSET(volume_dB) 0 0 0
258 0 ▶ GET_AUDIO_OFFSET(silent_frame)
Branch: 1 branch
BranchTrueFalseTotal
GET_AUDIO_OFFSET(silent_frame) 0 0 0
259
260 0 ada_dbg_printf("get_key_offset() + key offset : %d\n", key_offset) ;
261
262 0 return key_offset ;
263 }
264
265 //---------------------------------------------------------------------------------------------------------
266 2 static void create_adav_filter(ADAV *this, Adata *user_data, char *key, int threshold)
267 {
268 unsigned i, j ;
269 int key_offset ;
270 unsigned ok ;
271
272 2 ada_dbg_printf("create_adav_filter(%s) - START\n", key) ;
273
274 2 strncpy(this->filter_data.key, key, MAXKEY) ;
275 2 key_offset = get_key_offset(user_data, key) ;
276
277 // Get number of elements
278 2 this->filter_data.num_elems = 0 ;
279 202 ▶ for (i=0; i < user_data->results_list_size; i++)
Branch: 1 branch
BranchTrueFalseTotal
for (i=0; i < user_data->results_list_size; i++) 200 2 202
280 {
281 200 ok = 0 ;
282 200 ▶ if (key_offset < 0)
Branch: 1 branch
BranchTrueFalseTotal
if (key_offset < 0) 200 0 200
283 {
284 200 ok = 1 ;
285 }
286 else
287 {
288 0 struct Ad_results *results = user_data->results_list[i].results ;
289 0 int *base = (int *)results ;
290 0 int val = *(base + key_offset) ;
291 0 ▶ if (val >= threshold)
Branch: 1 branch
BranchTrueFalseTotal
if (val >= threshold) 0 0 0
292 {
293 0 ok=1 ;
294 }
295 }
296
297 200 ▶ if (ok)
Branch: 1 branch
BranchTrueFalseTotal
if (ok) 200 0 200
298 {
299 200 ++this->filter_data.num_elems ;
300 }
301 }
302
303 2 ada_dbg_printf("create_adav_filter(%s) - array size = %d\n", key, this->filter_data.num_elems) ;
304
305 // Create data
306 2 this->filter_data.data = (struct adav_element *)malloc(this->filter_data.num_elems * sizeof(struct adav_element)) ;
307 2 memset(this->filter_data.data, 0, this->filter_data.num_elems * sizeof(struct adav_element)) ;
308
309 2 ada_dbg_printf("create_adav_filter(%s) - data [%p]\n", key, this->filter_data.data) ;
310
311 // Fill data
312 202 ▶ for (i=0, j=0; i < user_data->results_list_size; i++)
Branch: 1 branch
BranchTrueFalseTotal
for (i=0, j=0; i < user_data->results_list_size; i++) 200 2 202
313 {
314 200 struct Ad_results *results = user_data->results_list[i].results ;
315 200 ok = 0 ;
316
317 200 ▶ if (key_offset < 0)
Branch: 1 branch
BranchTrueFalseTotal
if (key_offset < 0) 200 0 200
318 {
319 200 ok = 1 ;
320 }
321 else
322 {
323 0 int *base = (int *)results ;
324 0 int val = *(base + key_offset) ;
325 0 ▶ if (val >= threshold)
Branch: 1 branch
BranchTrueFalseTotal
if (val >= threshold) 0 0 0
326 {
327 0 ok=1 ;
328 }
329 }
330
331 200 ▶ if (ok)
Branch: 1 branch
BranchTrueFalseTotal
if (ok) 200 0 200
332 {
333 200 this->filter_data.data[j].frame = results->video_framenum ;
334 200 this->filter_data.data[j].frame_end = results->video_framenum ;
335 200 this->filter_data.data[j].gap = 0 ;
336 200 j++ ;
337 }
338 }
339 2 ada_dbg_printf("create_adav_filter(%s) - END (j=%d)\n", key, j) ;
340
341 2 }
342
343
344 //---------------------------------------------------------------------------------------------------------
345 2 static void free_adav_filter(ADAV *this)
346 {
347 2 ada_dbg_printf("free_adav_filter - START\n") ;
348 2 ▶ if (this->filter_data.data)
Branch: 1 branch
BranchTrueFalseTotal
if (this->filter_data.data) 2 0 2
349 {
350 2 ada_dbg_printf("free_adav_filter(%s)\n", this->filter_data.key) ;
351 2 ADA_FREE(this->filter_data.data) ;
352 2 this->filter_data.data = 0 ;
353 2 this->filter_data.num_elems = 0 ;
354 }
355 2 ada_dbg_printf("free_adav_filter - clear adav\n") ;
356 2 clear_adav(this) ;
357 2 ada_dbg_printf("free_adav_filter - END\n") ;
358 2 }
359
360 //---------------------------------------------------------------------------------------------------------
361 // set the gap value based on frame & frame_end
362 2 static void filtered_update_gaps(ADAV *this)
363 {
364 unsigned i ;
365 2 int prev_frame_end = -1 ;
366
367 202 ▶ for (i=0; i < this->filter_data.num_elems; i++)
Branch: 1 branch
BranchTrueFalseTotal
for (i=0; i < this->filter_data.num_elems; i++) 200 2 202
368 {
369 200 this->filter_data.data[i].gap = CALC_GAP(this->filter_data.data[i].frame, prev_frame_end) ;
370 200 prev_frame_end = this->filter_data.data[i].frame_end ;
371 }
372 2 }
373
374
375
376 //========================================================================================================
377 // LOGO FUNCTIONS
378 //========================================================================================================
379
380 //---------------------------------------------------------------------------------------------------------
381 1 static void create_adav_logo(ADAV *this, Adata *user_data)
382 {
383 // Initialise
384 1 this->logo_data.data = 0 ;
385 1 this->logo_data.num_elems = 0 ;
386 1 }
387
388
389 //---------------------------------------------------------------------------------------------------------
390 1 static void free_adav_logo(ADAV *this)
391 {
392 1 ▶ if (this->logo_data.data)
Branch: 1 branch
BranchTrueFalseTotal
if (this->logo_data.data) 1 0 1
393 {
394 1 ADA_FREE(this->logo_data.data) ;
395 1 this->logo_data.data = 0 ;
396 1 this->logo_data.num_elems = 0 ;
397 1 this->logo_data.num_alloc = 0 ;
398 }
399 1 clear_adav(this) ;
400 1 }
401
402
403
404 //---------------------------------------------------------------------------------------------------------
405 // set the gap value based on frame & frame_end
406 0 static void logo_update_gaps(ADAV *this)
407 {
408 unsigned i ;
409 0 int prev_frame_end = -1 ;
410
411 0 ▶ for (i=0; i < this->logo_data.num_elems; i++)
Branch: 1 branch
BranchTrueFalseTotal
for (i=0; i < this->logo_data.num_elems; i++) 0 0 0
412 {
413 0 this->logo_data.data[i].gap = CALC_GAP(this->logo_data.data[i].frame, prev_frame_end) ;
414 0 prev_frame_end = this->logo_data.data[i].frame_end ;
415 }
416 0 }
417
418 //---------------------------------------------------------------------------------------------------------
419 // check gaps
420 #ifdef DBG_ADAV
421 static void logo_frames_sanity(ADAV *this, int frame)
422 {
423 unsigned i ;
424
425 for (i=0; i < this->logo_data.num_elems; i++)
426 {
427 if (this->logo_data.data[i].gap < 0)
428 {
429 ada_dbg_printf("<check sanity at frame %d> ??? BAD ??? bad frame=%d\n", frame, i) ;
430 }
431 }
432 }
433 #else
434 #define logo_frames_sanity(this, frame)
435 #endif
436
437
438
439 // Set to 30 minutes (+margin)
440 #define RESULTS_BLOCKSIZE (32 * 60 * FPS)
441 #define STORE_LOGO(IDX, NAME) HVF_IV(hv, NAME, this->logo_data.data[IDX].NAME)
442
443 //---------------------------------------------------------------------------------------------------------
444 44 static HV *store_logo(ADAV *this, int idx, HV *hv)
445 {
446 SV **val;
447
448 44 ada_dbg_printf(" + store_logo[%d] - curr size=%d (alloc=%d)\n", idx, this->logo_data.num_elems, this->logo_data.num_alloc) ;
449
450 44 ▶ if (idx < 0)
Branch: 1 branch
BranchTrueFalseTotal
if (idx < 0) 0 44 44
451 0 return hv ;
452
453 // check allocated space - only ever increases
454 44 ▶ if ((idx >= this->logo_data.num_alloc) || (!this->logo_data.data))
Branch: 2 branches
BranchTrueFalseTotal
if ((idx >= this->logo_data.num_alloc) || (!this->logo_data.data)) 43 1 44
if ((idx >= this->logo_data.num_alloc) || (!this->logo_data.data)) 0 43 43
455 {
456 // increase size
457 1 this->logo_data.num_alloc += RESULTS_BLOCKSIZE ;
458 1 this->logo_data.data = (struct adav_logo_element *)realloc(this->logo_data.data, this->logo_data.num_alloc * sizeof(struct adav_logo_element)) ;
459 1 memset(&this->logo_data.data[this->logo_data.num_alloc - RESULTS_BLOCKSIZE], 0, RESULTS_BLOCKSIZE * sizeof(struct adav_logo_element)) ;
460
461 1 ada_dbg_printf(" + + store[%d] inc size - curr size=%d (alloc=%d)\n", idx, this->logo_data.num_elems, this->logo_data.num_alloc) ;
462
463 }
464
465 // set the item
466 44 ▶ STORE_LOGO(idx, frame) ;
Branch: 2 branches
BranchTrueFalseTotal
STORE_LOGO(idx, frame) ; 44 0 44
STORE_LOGO(idx, frame) ; 44 0 44
467 44 ▶ STORE_LOGO(idx, frame_end) ;
Branch: 2 branches
BranchTrueFalseTotal
STORE_LOGO(idx, frame_end) ; 1 43 44
STORE_LOGO(idx, frame_end) ; 1 0 1
468 44 ▶ STORE_LOGO(idx, match_percent) ;
Branch: 2 branches
BranchTrueFalseTotal
STORE_LOGO(idx, match_percent) ; 44 0 44
STORE_LOGO(idx, match_percent) ; 44 0 44
469 44 ▶ STORE_LOGO(idx, ave_percent) ;
Branch: 2 branches
BranchTrueFalseTotal
STORE_LOGO(idx, ave_percent) ; 44 0 44
STORE_LOGO(idx, ave_percent) ; 44 0 44
470 44 this->logo_data.data[idx].gap = 0 ;
471
472 44 ada_dbg_printf(" + logo_frame[%d] frame=%d frame_end=%d match=%d ave=%d - curr size=%d\n",
473 idx,
474 44 this->logo_data.data[idx].frame,
475 44 this->logo_data.data[idx].frame_end,
476 44 this->logo_data.data[idx].match_percent,
477 44 this->logo_data.data[idx].ave_percent,
478 this->logo_data.num_elems) ;
479
480
481 // update number of elements
482 44 ▶ if (idx >= this->logo_data.num_elems)
Branch: 1 branch
BranchTrueFalseTotal
if (idx >= this->logo_data.num_elems) 40 4 44
483 {
484 40 this->logo_data.num_elems = idx+1;
485 40 ada_dbg_printf(" + + [%d] news size=%d (alloc=%d)\n", idx, this->logo_data.num_elems, this->logo_data.num_alloc) ;
486 }
487
488 44 return hv ;
489 }
490
491
492 //---------------------------------------------------------------------------------------------------------
493 // Shift all array contents down by 'count' ready for an "unshift" command
494 3 static void unshift_logo(ADAV *this, int count)
495 {
496 int num_blocks ;
497 struct adav_logo_element *new_data ;
498
499 3 ada_dbg_printf(" + unshift_logo(count=%d) - curr size=%d (alloc=%d)\n", count, this->logo_data.num_elems, this->logo_data.num_alloc) ;
500
501 3 ▶ if (count + this->logo_data.num_elems >= this->logo_data.num_alloc)
Branch: 1 branch
BranchTrueFalseTotal
if (count + this->logo_data.num_elems >= this->logo_data.num_alloc) 0 3 3
502 {
503 // increase size
504 0 num_blocks = (count / RESULTS_BLOCKSIZE) + 1 ;
505 0 this->logo_data.num_alloc += num_blocks * RESULTS_BLOCKSIZE ;
506 }
507
508 3 new_data = (struct adav_logo_element *)malloc(this->logo_data.num_alloc * sizeof(struct adav_logo_element)) ;
509 3 memset(new_data, 0, this->logo_data.num_alloc * sizeof(struct adav_logo_element)) ;
510
511 3 memcpy(&new_data[count], this->logo_data.data, this->logo_data.num_elems * sizeof(struct adav_logo_element)) ;
512
513 3 ADA_FREE(this->logo_data.data) ;
514 3 this->logo_data.data = new_data ;
515 3 this->logo_data.num_elems += count ;
516
517 3 ada_dbg_printf(" + unshift_logo(count=%d) - END : curr size=%d (alloc=%d)\n", count, this->logo_data.num_elems, this->logo_data.num_alloc) ;
518 3 }
519
520
521 //========================================================================================================
522 // CSV FUNCTIONS
523 //========================================================================================================
524
525 //---------------------------------------------------------------------------------------------------------
526 3 static void create_adav_csv(ADAV *this, Adata *user_data)
527 {
528 unsigned i ;
529
530 3 ada_dbg_printf("create_adav_csv() - START\n") ;
531
532 // Get number of elements
533 3 this->csv_data.num_elems = user_data->results_list_size ;
534
535 3 ada_dbg_printf("create_adav_csv() - array size = %d (%d bytes)\n", this->csv_data.num_elems, (this->csv_data.num_elems * sizeof(struct adav_csv_element)) ) ;
536
537 // Create data
538 3 this->csv_data.data = (struct adav_csv_element *)malloc(this->csv_data.num_elems * sizeof(struct adav_csv_element)) ;
539
540 3 ada_dbg_printf("create_adav_csv() - [%p]\n", this->csv_data.data ) ;
541
542 3 memset(this->csv_data.data, 0, this->csv_data.num_elems * sizeof(struct adav_csv_element)) ;
543
544 // Fill data
545 303 ▶ for (i=0; i < user_data->results_list_size; i++)
Branch: 1 branch
BranchTrueFalseTotal
for (i=0; i < user_data->results_list_size; i++) 300 3 303
546 {
547 300 struct Ad_results *results = user_data->results_list[i].results ;
548 300 this->csv_data.data[i].frame = results->video_framenum ;
549
550 300 this->csv_data.data[i].hv = newHV();
551 }
552
553 3 }
554
555
556 //---------------------------------------------------------------------------------------------------------
557 3 static void free_adav_csv(ADAV *this)
558 {
559 int i ;
560
561 3 ada_dbg_printf("free_adav_csv() - %p\n", this) ;
562
563 3 ▶ if (this->csv_data.data)
Branch: 1 branch
BranchTrueFalseTotal
if (this->csv_data.data) 3 0 3
564 {
565 303 ▶ for (i=0; i < this->csv_data.num_elems; i++)
Branch: 1 branch
BranchTrueFalseTotal
for (i=0; i < this->csv_data.num_elems; i++) 300 3 303
566 {
567 300 SvREFCNT_dec(this->csv_data.data[i].hv) ;
568 }
569 3 ADA_FREE(this->csv_data.data) ;
570 3 this->csv_data.data = 0 ;
571 3 this->csv_data.num_elems = 0 ;
572 }
573 3 clear_adav(this) ;
574
575 3 ada_dbg_printf("free_adav_csv() - %p - END\n", this) ;
576 3 }
577
578 //---------------------------------------------------------------------------------------------------------
579 // ASUMPTION: All values are integers (any non-integers are ignored)
580 1 static HV *store_csv(ADAV *this, int idx, HV *hv)
581 {
582 SV *value;
583 SV *newval;
584 char *key;
585 I32 len;
586 HV *csv_hv ;
587 int ival ;
588
589 1 ada_dbg_printf(" + store_csv[%d] - curr size=%d\n", idx, this->csv_data.num_elems) ;
590
591 1 ▶ if ((idx < 0) || (idx >= this->csv_data.num_elems))
Branch: 2 branches
BranchTrueFalseTotal
if ((idx < 0) || (idx >= this->csv_data.num_elems)) 1 0 1
if ((idx < 0) || (idx >= this->csv_data.num_elems)) 0 1 1
592 0 return hv ;
593
594 1 csv_hv = this->csv_data.data[idx].hv ;
595 1 hv_iterinit( hv );
596 1 value = hv_iternextsv( hv, &key, &len );
597 2 ▶ while ( value != NULL )
Branch: 1 branch
BranchTrueFalseTotal
while ( value != NULL ) 1 1 2
598 {
599 1 ada_dbg_printf(" + + store_csv[%d] - %s ok? %d\n", idx, key, SvIOK(value)) ;
600 1 ▶ if ( SvIOK(value) )
Branch: 1 branch
BranchTrueFalseTotal
if ( SvIOK(value) ) 1 0 1
601 {
602 // store/update the value stored in the CSV data for this key
603 1 ival = SvIV(value) ;
604 1 newval = newSViv(ival) ;
605 1 hv_store(csv_hv, key, len, newval, 0);
606 1 ada_dbg_printf(" + + store_csv[%d] - %s = %d\n", idx, key, ival) ;
607 }
608
609 1 value = hv_iternextsv( hv, &key, &len );
610 }
611
612 1 ada_dbg_printf(" + store_csv[%d] - DONE\n", idx) ;
613
614 1 return csv_hv ;
615 }
616
617
618 //---------------------------------------------------------------------------------------------------------
619 // ASUMPTION: All values are integers (any non-integers are ignored)
620 3 static HV *fetch_csv(ADAV *this, int idx, HV *results)
621 {
622 HV *hv ;
623 SV *value;
624 SV *newval;
625 char *key;
626 I32 len;
627 int ival ;
628
629 3 ada_dbg_printf(" + fetch_csv[%d] - curr size=%d\n", idx, this->csv_data.num_elems) ;
630
631 3 ▶ if ((idx < 0) || (idx >= this->csv_data.num_elems))
Branch: 2 branches
BranchTrueFalseTotal
if ((idx < 0) || (idx >= this->csv_data.num_elems)) 3 0 3
if ((idx < 0) || (idx >= this->csv_data.num_elems)) 0 3 3
632 0 return hv ;
633
634 // update with the csv list stuff
635 3 hv = this->csv_data.data[idx].hv ;
636 3 hv_iterinit( hv );
637 3 value = hv_iternextsv( hv, &key, &len );
638 5 ▶ while ( value != NULL )
Branch: 1 branch
BranchTrueFalseTotal
while ( value != NULL ) 2 3 5
639 {
640 // only process if value is a valid integer AND key is not one of the "special" keys
641 2 ▶ if ( SvIOK(value) && !(strcmp(key, "frame")==0) )
Branch: 2 branches
BranchTrueFalseTotal
if ( SvIOK(value) && !(strcmp(key, "frame")==0) ) 2 0 2
if ( SvIOK(value) && !(strcmp(key, "frame")==0) ) 2 0 2
642 {
643 // store/update the value returned for this key
644 2 ival = SvIV(value) ;
645 2 newval = newSViv(ival) ;
646 2 hv_store(results, key, len, newval, 0);
647 2 ada_dbg_printf(" + + fetch_csv[%d] - %s = %d\n", idx, key, ival) ;
648 }
649
650 2 value = hv_iternextsv( hv, &key, &len );
651 }
652
653 3 ada_dbg_printf(" + fetch_csv[%d] - DONE\n", idx) ;
654 3 return hv ;
655 }
656
657
658 //---------------------------------------------------------------------------------------------------------
659 // Creates the new key for all HASH entries and sets the value to 0
660 1 static void csv_add_key(ADAV *this, SV *key)
661 {
662 int idx ;
663 HV *hv ;
664 SV *value;
665 SV *newval;
666 I32 len;
667
668 1 ada_dbg_printf(" + csv_add_key[%s]\n", SvPV_nolen(key)) ;
669
670 // Fill data
671 101 ▶ for (idx=0; idx < this->csv_data.num_elems; idx++)
Branch: 1 branch
BranchTrueFalseTotal
for (idx=0; idx < this->csv_data.num_elems; idx++) 100 1 101
672 {
673 // update with the csv list stuff
674 100 hv = this->csv_data.data[idx].hv ;
675 100 ▶ if (!hv_exists_ent(hv, key, 0))
Branch: 1 branch
BranchTrueFalseTotal
if (!hv_exists_ent(hv, key, 0)) 100 0 100
676 {
677 100 newval = newSViv(0) ;
678 100 hv_store_ent(hv, key, newval, 0);
679 }
680 }
681 1 }
682
683
« xs/DVBT-advert.c ↑ Summary xs/DVBT-advert-c.c »