| 1 |
|
| |
| 2 |
|
| # /*---------------------------------------------------------------------------------------------------*/ |
| 3 |
|
| # /* Remove the demux filter (specified via the file handle) */ |
| 4 |
|
| int |
| 5 |
|
| dvb_del_demux (DVB *dvb, int fd) |
| 6 |
|
| |
| 7 |
|
| CODE: |
| 8 |
0 |
▶ | if (fd > 0) |
Branch: 1 branch
| Branch | True | False | Total |
| if (fd > 0) |
0 |
0 |
0 |
|
| 9 |
|
| { |
| 10 |
|
| // delete demux filter |
| 11 |
0 |
| RETVAL = dvb_demux_remove_filter(dvb, fd) ; |
| 12 |
|
| } |
| 13 |
|
| else |
| 14 |
|
| { |
| 15 |
0 |
| RETVAL = -1 ; |
| 16 |
|
| } |
| 17 |
|
| |
| 18 |
|
| OUTPUT: |
| 19 |
|
| RETVAL |
| 20 |
|
| |
| 21 |
|
| |
| 22 |
|
| |
| 23 |
|
| # /*---------------------------------------------------------------------------------------------------*/ |
| 24 |
|
| # /* Set the DEMUX to add a new stream specified by it's pid. Returns file handle or negative if fail */ |
| 25 |
|
| int |
| 26 |
|
| dvb_add_demux (DVB *dvb, unsigned int pid) |
| 27 |
|
| |
| 28 |
|
| CODE: |
| 29 |
|
| // set demux |
| 30 |
0 |
| RETVAL = dvb_demux_add_filter(dvb, pid) ; |
| 31 |
|
| |
| 32 |
|
| OUTPUT: |
| 33 |
|
| RETVAL |
| 34 |
|
| |
| 35 |
|
| |
| 36 |
|
| |
| 37 |
|
| # /*---------------------------------------------------------------------------------------------------*/ |
| 38 |
|
| # /* Stream the raw TS data to a file (assumes frontend & demux are already set up */ |
| 39 |
|
| int |
| 40 |
|
| dvb_record (DVB *dvb, char *filename, int sec) |
| 41 |
|
| CODE: |
| 42 |
0 |
▶ | if (sec <= 0) |
Branch: 1 branch
| Branch | True | False | Total |
| if (sec <= 0) |
0 |
0 |
0 |
|
| 43 |
0 |
| croak ("Linux::DVB::DVBT::dvb_record requires a valid record length in seconds"); |
| 44 |
|
| |
| 45 |
|
| |
| 46 |
|
| // open dvr first |
| 47 |
0 |
| RETVAL = dvb_dvr_open(dvb) ; |
| 48 |
|
| |
| 49 |
|
| // save stream |
| 50 |
0 |
▶ | if (RETVAL == 0) |
Branch: 1 branch
| Branch | True | False | Total |
| if (RETVAL == 0) |
0 |
0 |
0 |
|
| 51 |
|
| { |
| 52 |
0 |
| RETVAL = write_stream(dvb, filename, sec) ; |
| 53 |
|
| |
| 54 |
|
| // close dvr |
| 55 |
0 |
| dvb_dvr_release(dvb) ; |
| 56 |
|
| } |
| 57 |
|
| |
| 58 |
|
| |
| 59 |
|
| OUTPUT: |
| 60 |
|
| RETVAL |
| 61 |
|
| |
| 62 |
|
| |
| 63 |
|
| # /*---------------------------------------------------------------------------------------------------*/ |
| 64 |
|
| # /* Record a multiplex */ |
| 65 |
|
| # |
| 66 |
|
| # struct multiplex_file_struct { |
| 67 |
|
| # int file; |
| 68 |
|
| # time_t start; |
| 69 |
|
| # time_t end; |
| 70 |
|
| # unsigned int done; |
| 71 |
|
| # uint64_t errors; |
| 72 |
|
| # uint64_t pkts; |
| 73 |
|
| # } ; |
| 74 |
|
| # |
| 75 |
|
| # struct multiplex_pid_struct { |
| 76 |
|
| # struct multiplex_file_struct *file_info ; |
| 77 |
|
| # unsigned int pid; |
| 78 |
|
| # } ; |
| 79 |
|
| # |
| 80 |
|
| |
| 81 |
|
| int |
| 82 |
|
| dvb_record_demux (DVB *dvb, AV *multiplex_aref, HV *options_href=NULL) |
| 83 |
|
| |
| 84 |
|
| INIT: |
| 85 |
|
| unsigned num_entries ; |
| 86 |
|
| int i ; |
| 87 |
|
| SV **item ; |
| 88 |
|
| SV **val; |
| 89 |
|
| HV *href ; |
| 90 |
|
| HV *errors_href ; |
| 91 |
|
| HV *overflows_href ; |
| 92 |
|
| HV *pkts_href ; |
| 93 |
|
| HV *timeslip_href ; |
| 94 |
|
| char *str ; |
| 95 |
|
| char key[256] ; |
| 96 |
|
| char string[256] ; |
| 97 |
|
| |
| 98 |
|
| AV *pid_array; |
| 99 |
|
| unsigned num_pids ; |
| 100 |
|
| int j ; |
| 101 |
|
| SV **piditem ; |
| 102 |
|
| |
| 103 |
|
| struct multiplex_file_struct *file_info ; |
| 104 |
|
| struct multiplex_pid_struct *pid_list ; |
| 105 |
|
| unsigned pid_list_length ; |
| 106 |
|
| unsigned pid_index; |
| 107 |
|
| |
| 108 |
|
| time_t now, start, end; |
| 109 |
|
| int file ; |
| 110 |
|
| int rc ; |
| 111 |
|
| |
| 112 |
0 |
| unsigned use_demux2 = 0 ; |
| 113 |
0 |
| unsigned pnr = 0 ; |
| 114 |
0 |
| int event_id = -1 ; |
| 115 |
0 |
| unsigned timeslip_start = 0 ; |
| 116 |
0 |
| unsigned timeslip_end = 0 ; |
| 117 |
0 |
| unsigned max_timeslip = 0 ; |
| 118 |
|
| |
| 119 |
|
| CODE: |
| 120 |
|
| |
| 121 |
0 |
▶ | if (options_href) |
Branch: 1 branch
| Branch | True | False | Total |
| if (options_href) |
0 |
0 |
0 |
|
| 122 |
|
| { |
| 123 |
0 |
▶ | HVF_IV(options_href, use_demux2, use_demux2) ; |
Branch: 2 branches
| Branch | True | False | Total |
| HVF_IV(options_href, use_demux2, use_demux2) ; |
0 |
0 |
0 |
| HVF_IV(options_href, use_demux2, use_demux2) ; |
0 |
0 |
0 |
|
| 124 |
|
| } |
| 125 |
|
| |
| 126 |
|
| |
| 127 |
|
| // av_len returns -1 for empty. Returns maximum index number otherwise |
| 128 |
|
| //num_entries = av_len( (AV *)SvRV(multiplex_aref) ) + 1 ; |
| 129 |
0 |
| num_entries = av_len( multiplex_aref ) + 1 ; |
| 130 |
0 |
▶ | if (num_entries <= 0) |
Branch: 1 branch
| Branch | True | False | Total |
| if (num_entries <= 0) |
0 |
0 |
0 |
|
| 131 |
|
| { |
| 132 |
0 |
| croak("Linux::DVB::DVBT::dvb_record_demux requires a list of multiplex hashes") ; |
| 133 |
|
| } |
| 134 |
|
| |
| 135 |
|
| // count number of entries (and check structure) |
| 136 |
0 |
| pid_list_length = 0 ; |
| 137 |
|
| |
| 138 |
0 |
▶ | for (i=0; i <= num_entries ; i++) |
Branch: 1 branch
| Branch | True | False | Total |
| for (i=0; i <= num_entries ; i++) |
0 |
0 |
0 |
|
| 139 |
|
| { |
| 140 |
0 |
▶ | if ((item = av_fetch(multiplex_aref, i, 0)) && SvOK (*item)) |
Branch: 2 branches
| Branch | True | False | Total |
| if ((item = av_fetch(multiplex_aref, i, 0)) && SvOK (*item)) |
0 |
0 |
0 |
| if ((item = av_fetch(multiplex_aref, i, 0)) && SvOK (*item)) |
0 |
0 |
0 |
|
| 141 |
|
| { |
| 142 |
0 |
▶ | if ( SvTYPE(SvRV(*item)) != SVt_PVHV ) |
Branch: 1 branch
| Branch | True | False | Total |
| if ( SvTYPE(SvRV(*item)) != SVt_PVHV ) |
0 |
0 |
0 |
|
| 143 |
|
| { |
| 144 |
0 |
| croak("Linux::DVB::DVBT::dvb_record_demux requires a list of multiplex hashes") ; |
| 145 |
|
| } |
| 146 |
0 |
| href = (HV *)SvRV(*item) ; |
| 147 |
|
| |
| 148 |
|
| // get pids |
| 149 |
0 |
| val = HVF(href, pids) ; |
| 150 |
0 |
| pid_array = (AV *) SvRV (*val); |
| 151 |
0 |
| num_pids = av_len(pid_array) + 1 ; |
| 152 |
|
| |
| 153 |
0 |
| pid_list_length += num_pids ; |
| 154 |
|
| } |
| 155 |
|
| } |
| 156 |
|
| |
| 157 |
|
| // create arrays |
| 158 |
0 |
| now = time(NULL); |
| 159 |
0 |
| pid_list = (struct multiplex_pid_struct *)safemalloc( sizeof(struct multiplex_pid_struct) * pid_list_length); |
| 160 |
0 |
| file_info = (struct multiplex_file_struct *)safemalloc( sizeof(struct multiplex_file_struct) * num_entries ); |
| 161 |
|
| |
| 162 |
0 |
▶ | for (i=0, pid_index=0; i <= num_entries ; i++) |
Branch: 1 branch
| Branch | True | False | Total |
| for (i=0, pid_index=0; i <= num_entries ; i++) |
0 |
0 |
0 |
|
| 163 |
|
| { |
| 164 |
0 |
▶ | if ((item = av_fetch(multiplex_aref, i, 0)) && SvOK (*item)) |
Branch: 2 branches
| Branch | True | False | Total |
| if ((item = av_fetch(multiplex_aref, i, 0)) && SvOK (*item)) |
0 |
0 |
0 |
| if ((item = av_fetch(multiplex_aref, i, 0)) && SvOK (*item)) |
0 |
0 |
0 |
|
| 165 |
|
| { |
| 166 |
0 |
| href = (HV *)SvRV(*item) ; |
| 167 |
|
| |
| 168 |
0 |
| val = HVF(href, destfile) ; |
| 169 |
0 |
| str = (char *)SvPV(*val, SvLEN(*val)) ; |
| 170 |
0 |
| file = open(str, O_WRONLY | O_TRUNC | O_CREAT | O_LARGEFILE, 0666); |
| 171 |
0 |
▶ | if (-1 == file) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (-1 == file) { |
0 |
0 |
0 |
|
| 172 |
|
| |
| 173 |
0 |
| fprintf(stderr,"open %s: %s\n",str,strerror(errno)); |
| 174 |
0 |
| croak("Linux::DVB::DVBT::dvb_record_demux failed to write to file") ; |
| 175 |
|
| } |
| 176 |
|
| |
| 177 |
|
| // create file info struct |
| 178 |
0 |
| file_info[i].file = file ; |
| 179 |
|
| |
| 180 |
0 |
| val = HVF(href, offset) ; |
| 181 |
0 |
| file_info[i].start = now + SvIV (*val) ; |
| 182 |
|
| |
| 183 |
0 |
| val = HVF(href, duration) ; |
| 184 |
0 |
| file_info[i].duration = SvIV (*val) ; |
| 185 |
0 |
| file_info[i].end = file_info[i].start + SvIV (*val) ; |
| 186 |
|
| |
| 187 |
|
| |
| 188 |
0 |
| pnr = 0 ; |
| 189 |
0 |
| event_id = -1 ; |
| 190 |
0 |
| timeslip_start = 0 ; |
| 191 |
0 |
| timeslip_end = 0 ; |
| 192 |
0 |
| max_timeslip = 0 ; |
| 193 |
|
| |
| 194 |
0 |
▶ | HVF_IV(href, pnr, pnr) ; |
Branch: 2 branches
| Branch | True | False | Total |
| HVF_IV(href, pnr, pnr) ; |
0 |
0 |
0 |
| HVF_IV(href, pnr, pnr) ; |
0 |
0 |
0 |
|
| 195 |
0 |
▶ | HVF_IV(href, event_id, event_id) ; |
Branch: 2 branches
| Branch | True | False | Total |
| HVF_IV(href, event_id, event_id) ; |
0 |
0 |
0 |
| HVF_IV(href, event_id, event_id) ; |
0 |
0 |
0 |
|
| 196 |
0 |
▶ | HVF_IV(href, timeslip_start, timeslip_start) ; |
Branch: 2 branches
| Branch | True | False | Total |
| HVF_IV(href, timeslip_start, timeslip_start) ; |
0 |
0 |
0 |
| HVF_IV(href, timeslip_start, timeslip_start) ; |
0 |
0 |
0 |
|
| 197 |
0 |
▶ | HVF_IV(href, timeslip_end, timeslip_end) ; |
Branch: 2 branches
| Branch | True | False | Total |
| HVF_IV(href, timeslip_end, timeslip_end) ; |
0 |
0 |
0 |
| HVF_IV(href, timeslip_end, timeslip_end) ; |
0 |
0 |
0 |
|
| 198 |
0 |
▶ | HVF_IV(href, max_timeslip, max_timeslip) ; |
Branch: 2 branches
| Branch | True | False | Total |
| HVF_IV(href, max_timeslip, max_timeslip) ; |
0 |
0 |
0 |
| HVF_IV(href, max_timeslip, max_timeslip) ; |
0 |
0 |
0 |
|
| 199 |
|
| |
| 200 |
|
| // get pids |
| 201 |
0 |
| val = HVF(href, pids) ; |
| 202 |
0 |
| pid_array = (AV *) SvRV (*val); |
| 203 |
0 |
| num_pids = av_len(pid_array) + 1 ; |
| 204 |
|
| |
| 205 |
0 |
▶ | for (j=0; j < num_pids ; j++, ++pid_index) |
Branch: 1 branch
| Branch | True | False | Total |
| for (j=0; j < num_pids ; j++, ++pid_index) |
0 |
0 |
0 |
|
| 206 |
|
| { |
| 207 |
0 |
▶ | if ((piditem = av_fetch(pid_array, j, 0)) && SvOK (*piditem)) |
Branch: 2 branches
| Branch | True | False | Total |
| if ((piditem = av_fetch(pid_array, j, 0)) && SvOK (*piditem)) |
0 |
0 |
0 |
| if ((piditem = av_fetch(pid_array, j, 0)) && SvOK (*piditem)) |
0 |
0 |
0 |
|
| 208 |
|
| { |
| 209 |
0 |
| pid_list[pid_index].file_info = &file_info[i] ; |
| 210 |
0 |
| pid_list[pid_index].pid = SvIV (*piditem) ; |
| 211 |
0 |
| pid_list[pid_index].started = 0 ; |
| 212 |
0 |
| pid_list[pid_index].done = 0 ; |
| 213 |
|
| |
| 214 |
|
| // Statistics |
| 215 |
0 |
| pid_list[pid_index].errors = 0 ; |
| 216 |
0 |
| pid_list[pid_index].overflows = 0 ; |
| 217 |
0 |
| pid_list[pid_index].pkts = 0 ; |
| 218 |
0 |
| pid_list[pid_index].timeslip_start_secs = 0 ; |
| 219 |
0 |
| pid_list[pid_index].timeslip_end_secs = 0 ; |
| 220 |
|
| |
| 221 |
|
| // Timeslipping |
| 222 |
0 |
| pid_list[pid_index].pnr = pnr ; |
| 223 |
0 |
| pid_list[pid_index].event_id = event_id ; |
| 224 |
0 |
| pid_list[pid_index].running_status = RUNNING_STATUS_UNDEF ; |
| 225 |
0 |
| pid_list[pid_index].max_timeslip = max_timeslip ; |
| 226 |
|
| |
| 227 |
|
| // Flags - set to timeslip start and/or end of prog |
| 228 |
0 |
| pid_list[pid_index].timeslip_start = timeslip_start ; |
| 229 |
0 |
| pid_list[pid_index].timeslip_end = timeslip_end ; |
| 230 |
|
| |
| 231 |
|
| |
| 232 |
|
| // internal |
| 233 |
0 |
| pid_list[pid_index].running_event_id = EVENT_ID_UNDEF ; |
| 234 |
0 |
| pid_list[pid_index].pending_event_id = EVENT_ID_UNDEF ; |
| 235 |
0 |
| pid_list[pid_index].got_eit = 0 ; |
| 236 |
0 |
| pid_list[pid_index].ref = (void *)item ; |
| 237 |
|
| } |
| 238 |
|
| } |
| 239 |
|
| |
| 240 |
|
| } |
| 241 |
|
| } |
| 242 |
|
| |
| 243 |
|
| // open dvr first |
| 244 |
0 |
| RETVAL = dvb_dvr_open(dvb) ; |
| 245 |
|
| |
| 246 |
|
| // save stream |
| 247 |
0 |
▶ | if (RETVAL == 0) |
Branch: 1 branch
| Branch | True | False | Total |
| if (RETVAL == 0) |
0 |
0 |
0 |
|
| 248 |
|
| { |
| 249 |
0 |
| RETVAL = write_stream_demux(dvb, pid_list, pid_index) ; |
| 250 |
|
| |
| 251 |
|
| // close dvr |
| 252 |
0 |
| dvb_dvr_release(dvb) ; |
| 253 |
|
| } |
| 254 |
|
| |
| 255 |
|
| // Copy error/packet counts |
| 256 |
0 |
▶ | for (i=0; i < pid_index; ++i) |
Branch: 1 branch
| Branch | True | False | Total |
| for (i=0; i < pid_index; ++i) |
0 |
0 |
0 |
|
| 257 |
|
| { |
| 258 |
0 |
| item = (SV **)pid_list[i].ref ; |
| 259 |
0 |
| href = (HV *)SvRV(*item) ; |
| 260 |
|
| |
| 261 |
0 |
| sprintf(key, "%d", pid_list[i].pid) ; |
| 262 |
|
| |
| 263 |
|
| // set errors (save 64 bit value as a string) |
| 264 |
0 |
| val = HVF(href, errors) ; |
| 265 |
0 |
| errors_href = (HV *) SvRV (*val); |
| 266 |
0 |
| sprintf(string, "%"PRIu64, pid_list[i].errors) ; |
| 267 |
0 |
| hv_store(errors_href, key, strlen(key), newSVpv(string, 0), 0); |
| 268 |
|
| |
| 269 |
|
| // set overflows (save 64 bit value as a string) |
| 270 |
0 |
| val = HVF(href, overflows) ; |
| 271 |
0 |
| overflows_href = (HV *) SvRV (*val); |
| 272 |
0 |
| sprintf(string, "%"PRIu64, pid_list[i].overflows) ; |
| 273 |
0 |
| hv_store(overflows_href, key, strlen(key), newSVpv(string, 0), 0); |
| 274 |
|
| |
| 275 |
|
| // set packets (save 64 bit value as a string) |
| 276 |
0 |
| val = HVF(href, pkts) ; |
| 277 |
0 |
| pkts_href = (HV *) SvRV (*val); |
| 278 |
0 |
| sprintf(string, "%"PRIu64, pid_list[i].pkts) ; |
| 279 |
0 |
| hv_store(pkts_href, key, strlen(key), newSVpv(string, 0), 0); |
| 280 |
|
| |
| 281 |
|
| // set timeslip statistics |
| 282 |
0 |
| val = HVF(href, timeslip_start_secs) ; |
| 283 |
0 |
| timeslip_href = (HV *) SvRV (*val); |
| 284 |
0 |
| sprintf(string, "%u", pid_list[i].timeslip_start_secs) ; |
| 285 |
0 |
| hv_store(timeslip_href, key, strlen(key), newSVpv(string, 0), 0); |
| 286 |
0 |
| val = HVF(href, timeslip_end_secs) ; |
| 287 |
0 |
| timeslip_href = (HV *) SvRV (*val); |
| 288 |
0 |
| sprintf(string, "%u", pid_list[i].timeslip_end_secs) ; |
| 289 |
0 |
| hv_store(timeslip_href, key, strlen(key), newSVpv(string, 0), 0); |
| 290 |
|
| |
| 291 |
|
| |
| 292 |
|
| } |
| 293 |
|
| |
| 294 |
|
| // free up |
| 295 |
0 |
▶ | for (i=0; i < num_entries ; i++) |
Branch: 1 branch
| Branch | True | False | Total |
| for (i=0; i < num_entries ; i++) |
0 |
0 |
0 |
|
| 296 |
|
| { |
| 297 |
0 |
▶ | if (file_info[i].file > 0) |
Branch: 1 branch
| Branch | True | False | Total |
| if (file_info[i].file > 0) |
0 |
0 |
0 |
|
| 298 |
|
| { |
| 299 |
0 |
| close(file_info[i].file) ; |
| 300 |
|
| } |
| 301 |
|
| } |
| 302 |
0 |
| safefree(pid_list) ; |
| 303 |
0 |
| safefree(file_info) ; |
| 304 |
|
| |
| 305 |
|
| |
| 306 |
|
| OUTPUT: |
| 307 |
|
| RETVAL |
| 308 |
|
| |
| 309 |
|
| |