clib/dvb_ts_lib/ts_split.c

filter: Statementstmt 0.0% 0 / 62 Branchbran 0.0% 0 / 40 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 0.0% 0 / 102 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« clib/dvb_ts_lib/ts_skip.c ↑ Summary clib/libmpeg2_stubs/mpeg2_stubs.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 // SPLIT
11 //========================================================================================================
12  
13 //---------------------------------------------------------------------------------------------------------
14 //
15 0 static void next_split_file(struct TS_cut_data *hook_data, unsigned pktnum)
16 {
17 // close currently open
18 0 ▶ if (hook_data->cut_file)
Branch: 1 branch
BranchTrueFalseTotal
if (hook_data->cut_file) 0 0 0
19 {
20 0 ▶ if (pktnum > hook_data->split_pkt)
Branch: 1 branch
BranchTrueFalseTotal
if (pktnum > hook_data->split_pkt) 0 0 0
21 {
22 0 close(hook_data->cut_file) ;
23 0 hook_data->cut_file = 0 ;
24 }
25 }
26  
27 // open next
28 0 ▶ if (!hook_data->cut_file)
Branch: 1 branch
BranchTrueFalseTotal
if (!hook_data->cut_file) 0 0 0
29 {
30 char cutname[256] ;
31  
32 0 hook_data->split_pkt = pktnum ;
33  
34 0 sprintf(cutname, "%s-%04u.ts",
35 0 hook_data->ofname, ++hook_data->split_count) ;
36  
37 0 ▶ if (hook_data->debug) printf("New split file %s at pkt %d\n", cutname, pktnum) ;
Branch: 1 branch
BranchTrueFalseTotal
if (hook_data->debug) printf("New split file %s at pkt %d\n", cutname, pktnum) ; 0 0 0
38  
39  
40 0 hook_data->cut_file = open(cutname, O_CREAT | O_TRUNC | O_WRONLY | O_LARGEFILE, 0666);
41  
42 0 ▶ if (hook_data->debug >= 10) printf("-> save cut sequence: %s [%d]\n", cutname, hook_data->cut_file) ;
Branch: 1 branch
BranchTrueFalseTotal
if (hook_data->debug >= 10) printf("-> save cut sequence: %s [%d]\n", cutname, hook_data->cut_file) ; 0 0 0
43 }
44  
45 0 }
46  
47 //---------------------------------------------------------------------------------------------------------
48 // void (*tsparse_ts_hook)(unsigned long, unsigned, const uint8_t *, unsigned, unsigned, unsigned) ;
49 0 static void ts_split_hook(struct TS_pidinfo *pidinfo, uint8_t *packet, unsigned packet_len, void *user_data)
50 {
51 0 struct TS_cut_data *hook_data = (struct TS_cut_data *)user_data ;
52 //static unsigned prev_ok=1;
53 //unsigned ok = 1 ;
54  
55 0 ▶ if (hook_data->debug >= 10)
Branch: 1 branch
BranchTrueFalseTotal
if (hook_data->debug >= 10) 0 0 0
56 {
57 0 printf("-> TS PID 0x%x (%u) [%u] :: start=%d err=%d\n",
58 pidinfo->pid, pidinfo->pid,
59 pidinfo->pktnum,
60 0 pidinfo->pes_start ? 1 : 0,
61 0 pidinfo->pid_error ? 1 : 0) ;
62 }
63  
64 // check cut
65 0 ▶ if (hook_data->current_cut == UNSET_CUT_LIST)
Branch: 1 branch
BranchTrueFalseTotal
if (hook_data->current_cut == UNSET_CUT_LIST) 0 0 0
66 {
67 struct list_head *item;
68  
69 0 ▶ list_for_each(item, hook_data->cut_list)
Branch: 1 branch
BranchTrueFalseTotal
list_for_each(item, hook_data->cut_list) 0 0 0
70 {
71 0 hook_data->current_cut = list_entry(item, struct TS_cut, next);
72 // next_split_file(hook_data) ;
73 // if (hook_data->debug) printf("New split file %04d at pkt %d\n", hook_data->split_count, pidinfo->pktnum) ;
74 0 break;
75 }
76 }
77  
78 0 ▶ if (hook_data->current_cut != END_CUT_LIST)
Branch: 1 branch
BranchTrueFalseTotal
if (hook_data->current_cut != END_CUT_LIST) 0 0 0
79 {
80 // check current
81 0 ▶ if (pidinfo->pktnum < hook_data->current_cut->start)
Branch: 1 branch
BranchTrueFalseTotal
if (pidinfo->pktnum < hook_data->current_cut->start) 0 0 0
82 {
83 // still before start of next band
84 }
85 else
86 {
87 // Now >= start
88  
89 // New file at start of region
90 0 ▶ if ( pidinfo->pktnum == hook_data->current_cut->start )
Branch: 1 branch
BranchTrueFalseTotal
if ( pidinfo->pktnum == hook_data->current_cut->start ) 0 0 0
91 {
92 // save next band into new file
93 0 next_split_file(hook_data, pidinfo->pktnum) ;
94 }
95  
96 // writing : start -> end
97 0 ▶ else if (pidinfo->pktnum < hook_data->current_cut->end)
Branch: 1 branch
BranchTrueFalseTotal
else if (pidinfo->pktnum < hook_data->current_cut->end) 0 0 0
98 {
99 }
100  
101 // writing : end
102 0 ▶ else if (pidinfo->pktnum == hook_data->current_cut->end)
Branch: 1 branch
BranchTrueFalseTotal
else if (pidinfo->pktnum == hook_data->current_cut->end) 0 0 0
103 {
104 // // save next band into new file
105 // next_split_file(hook_data, pidinfo->pktnum) ;
106 }
107  
108 // beyond end
109 else
110 {
111 struct list_head *item;
112  
113 // ok, beyond this cut band - find next cut region
114 do
115 {
116 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
117 {
118 0 hook_data->current_cut = list_entry(item, struct TS_cut, next);
119 0 break;
120 }
121 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
122  
123 // prev_ok=1;
124  
125 // // save next band into new file
126 0 next_split_file(hook_data, pidinfo->pktnum) ;
127 // if (hook_data->debug) printf("New split file %04d at pkt %d\n", hook_data->split_count, pidinfo->pktnum) ;
128 }
129 }
130 }
131  
132 0 ▶ if (hook_data->debug >= 10)
Branch: 1 branch
BranchTrueFalseTotal
if (hook_data->debug >= 10) 0 0 0
133 {
134 0 printf("-> TS PID 0x%x (%u) [%u]\n",
135 pidinfo->pid, pidinfo->pid,
136 pidinfo->pktnum) ;
137 }
138  
139 // write if allowed to
140 0 ▶ if (hook_data->cut_file)
Branch: 1 branch
BranchTrueFalseTotal
if (hook_data->cut_file) 0 0 0
141 {
142 0 write(hook_data->cut_file, packet, packet_len);
143 }
144 0 }
145  
146  
147  
148 //---------------------------------------------------------------------------------------------------------
149 0 int ts_split(char *filename, char *ofilename, struct list_head *cuts_array, unsigned debug)
150 {
151 int file;
152 struct TS_cut_data hook_data ;
153 struct TS_reader *tsreader ;
154  
155 0 hook_data.cut_list = cuts_array ;
156  
157 0 hook_data.current_cut = UNSET_CUT_LIST ;
158 0 hook_data.debug = debug ;
159 0 hook_data.ofile = 0 ;
160 0 hook_data.split_count = 0 ;
161 0 hook_data.cut_file = 0 ;
162 0 hook_data.ofile = 0 ;
163  
164 0 tsreader = tsreader_new(filename) ;
165 0 ▶ if (!tsreader)
Branch: 1 branch
BranchTrueFalseTotal
if (!tsreader) 0 0 0
166 {
167 0 return(dvb_error_code);
168 }
169 0 tsreader->ts_hook = ts_split_hook ;
170 0 tsreader->user_data = &hook_data ;
171 0 tsreader->debug = debug ;
172  
173 0 remove_ext(filename, hook_data.fname) ;
174 0 remove_ext(ofilename, hook_data.ofname) ;
175  
176 // start first file
177 0 next_split_file(&hook_data, 0) ;
178  
179 // parse data
180 0 ts_parse(tsreader) ;
181  
182 0 ▶ if (hook_data.cut_file)
Branch: 1 branch
BranchTrueFalseTotal
if (hook_data.cut_file) 0 0 0
183 0 close(hook_data.cut_file) ;
184  
185 0 tsreader_free(tsreader) ;
186 0 free_cut_list(hook_data.cut_list) ;
187  
188 0 return(dvb_error_code) ;
189 }
190  
191  
« clib/dvb_ts_lib/ts_skip.c ↑ Summary clib/libmpeg2_stubs/mpeg2_stubs.c »