clib/dvb_ts_lib/ts_cut.c

filter: Statementstmt 0.0% 0 / 52 Branchbran 0.0% 0 / 32 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 0.0% 0 / 84 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« clib/dvb_ts_lib/ts_bits.c ↑ Summary clib/dvb_ts_lib/ts_parse.c »
1 // VERSION = "1.000"
2 //
3 // Standard C code loaded outside XS space. Contains useful routines used by ts TS parsing functions
4  
5 // VERSION 1.01
6  
7 #include "ts_split.h"
8  
9 //========================================================================================================
10 // CUT
11 //========================================================================================================
12  
13  
14 //---------------------------------------------------------------------------------------------------------
15 // void (*tsparse_ts_hook)(unsigned long, unsigned, const uint8_t *, unsigned, unsigned, unsigned) ;
16 0 void ts_cut_hook(struct TS_pidinfo *pidinfo, uint8_t *packet, unsigned packet_len, void *user_data)
17 {
18 0 struct TS_cut_data *hook_data = (struct TS_cut_data *)user_data ;
19 static unsigned prev_ok=1;
20  
21 0 ▶ if (hook_data->ofile)
Branch: 1 branch
BranchTrueFalseTotal
if (hook_data->ofile) 0 0 0
22 {
23 0 unsigned ok = 1 ;
24  
25 0 ▶ if (hook_data->debug >= 10)
Branch: 1 branch
BranchTrueFalseTotal
if (hook_data->debug >= 10) 0 0 0
26 {
27 0 printf("-> TS PID 0x%x (%u) [%u] :: start=%d err=%d\n",
28 pidinfo->pid, pidinfo->pid,
29 pidinfo->pktnum,
30 0 pidinfo->pes_start ? 1 : 0,
31 0 pidinfo->pid_error ? 1 : 0) ;
32 }
33  
34 // check cut
35 0 ▶ if (hook_data->current_cut == UNSET_CUT_LIST)
Branch: 1 branch
BranchTrueFalseTotal
if (hook_data->current_cut == UNSET_CUT_LIST) 0 0 0
36 {
37 struct list_head *item;
38  
39 0 ▶ list_for_each(item, hook_data->cut_list)
Branch: 1 branch
BranchTrueFalseTotal
list_for_each(item, hook_data->cut_list) 0 0 0
40 {
41 0 hook_data->current_cut = list_entry(item, struct TS_cut, next);
42 0 break;
43 }
44 }
45  
46 0 ▶ if (hook_data->current_cut != END_CUT_LIST)
Branch: 1 branch
BranchTrueFalseTotal
if (hook_data->current_cut != END_CUT_LIST) 0 0 0
47 {
48 // check current
49 0 ▶ if (pidinfo->pktnum < hook_data->current_cut->start)
Branch: 1 branch
BranchTrueFalseTotal
if (pidinfo->pktnum < hook_data->current_cut->start) 0 0 0
50 {
51 // ok, not in this cut band
52 }
53 else
54 {
55  
56 0 ▶ if (pidinfo->pktnum <= hook_data->current_cut->end)
Branch: 1 branch
BranchTrueFalseTotal
if (pidinfo->pktnum <= hook_data->current_cut->end) 0 0 0
57 {
58 // cut, in this cut band
59 0 ok = 0 ;
60  
61 0 ▶ if (prev_ok)
Branch: 1 branch
BranchTrueFalseTotal
if (prev_ok) 0 0 0
62 {
63 0 ▶ if (hook_data->debug) printf("Skipping %u .. %u\n", hook_data->current_cut->start, hook_data->current_cut->end) ;
Branch: 1 branch
BranchTrueFalseTotal
if (hook_data->debug) printf("Skipping %u .. %u\n", hook_data->current_cut->start, hook_data->current_cut->end) ; 0 0 0
64 }
65  
66 0 prev_ok = ok ;
67  
68 }
69 else
70 {
71 struct list_head *item;
72  
73 // ok, beyond this cut band - find next cut region
74 do
75 {
76 0 ▶ list_next_each(hook_data->current_cut, END_CUT_LIST, item, hook_data->cut_list)
Branch: 1 branch
BranchTrueFalseTotal
list_next_each(hook_data->current_cut, END_CUT_LIST, item, hook_data->cut_list) 0 0 0
77 {
78 0 hook_data->current_cut = list_entry(item, struct TS_cut, next);
79 0 break;
80 }
81 0 ▶ } while ( (hook_data->current_cut != END_CUT_LIST) && (pidinfo->pktnum > hook_data->current_cut->start) ) ;
Branch: 2 branches
BranchTrueFalseTotal
} while ( (hook_data->current_cut != END_CUT_LIST) && (pidinfo->pktnum > hook_data->current_cut->start) ) ; 0 0 0
} while ( (hook_data->current_cut != END_CUT_LIST) && (pidinfo->pktnum > hook_data->current_cut->start) ) ; 0 0 0
82  
83 0 prev_ok=1;
84  
85 }
86 }
87 }
88  
89 0 ▶ if (hook_data->debug >= 10)
Branch: 1 branch
BranchTrueFalseTotal
if (hook_data->debug >= 10) 0 0 0
90 {
91 0 printf("-> TS PID 0x%x (%u) [%u] :: ok=%d\n",
92 pidinfo->pid, pidinfo->pid,
93 pidinfo->pktnum,
94 ok) ;
95 }
96  
97  
98 // write if allowed to
99 0 ▶ if (ok)
Branch: 1 branch
BranchTrueFalseTotal
if (ok) 0 0 0
100 {
101 // no error
102 0 write(hook_data->ofile, packet, packet_len);
103 }
104 }
105 0 }
106  
107  
108  
109 //---------------------------------------------------------------------------------------------------------
110 0 int ts_cut(char *filename, char *ofilename, struct list_head *cuts_array, unsigned debug)
111 {
112 int file;
113 struct TS_cut_data hook_data ;
114 struct TS_reader *tsreader ;
115  
116 0 hook_data.cut_list = cuts_array ;
117  
118 0 hook_data.current_cut = UNSET_CUT_LIST ;
119 0 hook_data.debug = debug ;
120 0 hook_data.ofile = 0 ;
121 0 hook_data.split_count = 0 ;
122 0 hook_data.cut_file = 0 ;
123  
124 0 hook_data.ofile = open(ofilename, O_CREAT | O_TRUNC | O_WRONLY | O_LARGEFILE, 0666);
125 0 ▶ if (-1 == hook_data.ofile) {
Branch: 1 branch
BranchTrueFalseTotal
if (-1 == hook_data.ofile) { 0 0 0
126 0 RETURN_DVB_ERROR(ERR_FILE);
127 }
128  
129 0 tsreader = tsreader_new(filename) ;
130 0 ▶ if (!tsreader)
Branch: 1 branch
BranchTrueFalseTotal
if (!tsreader) 0 0 0
131 {
132 0 return(dvb_error_code);
133 }
134 0 tsreader->ts_hook = ts_cut_hook ;
135 0 tsreader->user_data = &hook_data ;
136 0 tsreader->debug = debug ;
137  
138 0 remove_ext(filename, hook_data.fname) ;
139 0 remove_ext(ofilename, hook_data.ofname) ;
140  
141 // parse data
142 0 ts_parse(tsreader) ;
143  
144 0 close(hook_data.ofile) ;
145  
146 0 tsreader_free(tsreader) ;
147 0 free_cut_list(hook_data.cut_list) ;
148  
149 0 return(dvb_error_code) ;
150 }
151  
152  
« clib/dvb_ts_lib/ts_bits.c ↑ Summary clib/dvb_ts_lib/ts_parse.c »