/** * Wait until a new set of frames becomes available. * The frames set includes time-synchronized frames of each enabled stream in the pipeline. * In case of different frame rates of the streams, the frames set include a matching frame of the slow stream, * which may have been included in previous frames set. * The method blocks the calling thread, and fetches the latest unread frames set. * Device frames, which were produced while the function wasn't called, are dropped. To avoid frame drops, this method * should be called as fast as the device frame rate. * The application can maintain the frames handles to defer processing. However, if the application maintains too long * history, the device may lack memory resources to produce new frames, and the following call to this method shall fail * to retrieve new frames, until resources are retained. * * \param[in] timeout_ms Max time in milliseconds to wait until an exception will be thrown * \return Set of time synchronized frames, one from each active stream */ frameset wait_for_frames(unsigned int timeout_ms = 5000) const { rs2_error* e = nullptr; frame f(rs2_pipeline_wait_for_frames(_pipeline.get(), timeout_ms, &e)); error::handle(e); return frameset(f); }
bool try_wait_for_frames(frameset* f, unsigned int timeout_ms = 5000) const { if (!f) { throw std::invalid_argument("null frameset"); } rs2_error* e = nullptr; rs2_frame* frame_ref = nullptr; auto res = rs2_pipeline_try_wait_for_frames(_pipeline.get(), &frame_ref, timeout_ms, &e); error::handle(e); if (res) *f = frameset(frame(frame_ref)); return res > 0; }
/** * Check if a new set of frames is available and retrieve the latest undelivered set. * The frames set includes time-synchronized frames of each enabled stream in the pipeline. * The method returns without blocking the calling thread, with status of new frames available or not. * If available, it fetches the latest frames set. * Device frames, which were produced while the function wasn't called, are dropped. * To avoid frame drops, this method should be called as fast as the device frame rate. * The application can maintain the frames handles to defer processing. However, if the application maintains too long * history, the device may lack memory resources to produce new frames, and the following calls to this method shall * return no new frames, until resources are retained. * * \param[out] f Frames set handle * \return True if new set of time synchronized frames was stored to f, false if no new frames set is available */ bool poll_for_frames(frameset* f) const { if (!f) { throw std::invalid_argument("null frameset"); } rs2_error* e = nullptr; rs2_frame* frame_ref = nullptr; auto res = rs2_pipeline_poll_for_frames(_pipeline.get(), &frame_ref, &e); error::handle(e); if (res) *f = frameset(frame(frame_ref)); return res > 0; }
int print_report(FILE *fp, __u64 begin, __u64 end, __u32 interval, char *filename, __u64 topline, list<MsgTypes> *filter_types, DeviceFilter &dev_filter, Collapser &col, Printer &printer) { int frames_printed = 0; bool first_time = true; time_t t; int rc = 0; Frameset frameset(&col); Framer framer(begin, end, interval, filter_types, &dev_filter, filename, &rc); if (rc) return -1; if (topline && printer.print_csv()) { fprintf(stderr, "%s: Warning: Cannot use '-t' with CSV mode," " ignoring\n", toolname); topline = 0; } verbose_msg("print report for:\n"); t = (time_t)begin; verbose_msg(" begin : %s", ctime(&t)); t = (time_t)end; verbose_msg(" end : %s", (end == UINT64_MAX ? "-\n" : ctime(&t))); verbose_msg(" interval : %lu\n", (long unsigned int)interval); verbose_msg(" topline : %llu\n", (long long unsigned int)topline); verbose_msg(" csv mode : %d\n", printer.print_csv()); while ( (rc = framer.get_next_frameset(frameset, true)) == 0 ) { vverbose_msg("printing frameset %d\n", frames_printed); if (first_time || (topline && frames_printed % topline == 0)) { first_time = false; printer.print_topline(fp); } if (printer.print_frame(fp, frameset, dev_filter) < 0) return -1; ++frames_printed; } if (rc > 0) return frames_printed; return rc; }
/** * Read all essential data from the files, * including the headers, timestamp of first message * and a DeviceFilter for all available devices. * Note that 'agg' is NULL if not available and must * be free()'d otherwise. */ static int get_initial_data(const char *filename, struct file_header *f_hdr, struct aggr_data **agg, DeviceFilter &dev_filt, ConfigReader &cfg) { FILE *fp; int rc = 0; __u64 begin; if (open_data_files(&fp, filename, f_hdr, agg)) return -1; close_data_files(fp); /* * Retrieve first real frame */ MsgTypeFilter msgtype_filter; NoopCollapser nop_col; Frameset frameset(&nop_col); list<MsgTypes> type_flt; type_flt.push_back(ioerr); // we retrieve the first interval only, and eventually the .agg data // as well if (*agg) begin = (*agg)->end_time; else begin = f_hdr->begin_time; Framer framer(begin, begin + f_hdr->interval_length, f_hdr->interval_length, &type_flt, (DeviceFilter*)NULL, filename, &rc); vector <struct ioerr_cnt*> ioerrs; do { if ( framer.get_next_frameset(frameset) != 0 ) { fprintf(stderr, "%s: Could not read" " any frames in %s%s\n", toolname, filename, DACC_FILE_EXT_LOG); return -2; } /* * Construct a DeviceFilter with all devices. * NOTE: The very first ioerr msg might already have been moved to the .agg * file - hence we have to consider the .agg data as well! */ ioerrs = frameset.get_ioerr_stats(); rc = 0; for (vector<struct ioerr_cnt*>::const_iterator i = ioerrs.begin(); i != ioerrs.end(); ++i) { vverbose_msg(" add device: hctl=[%d:%d:%d:%d], mm=%d\n", (*i)->identifier.host, (*i)->identifier.channel, (*i)->identifier.target, (*i)->identifier.lun, cfg.get_mm_by_ident(&(*i)->identifier, &rc)); dev_filt.add_device(cfg.get_mm_by_ident(&(*i)->identifier, &rc), &(*i)->identifier); if (rc) return -1; } } while ( frameset.is_aggregated() && !ioerrs.size()); if (dev_filt.get_host_id_list().size() == 0 || dev_filt.get_mm_list().size() == 0) { fprintf(stderr, "%s: Could not retrieve initial data" " - data files corrupted or broken, or the .agg file is missing.\n", toolname); return -1; } verbose_msg("retrieve initial data FINISHED\n"); return 0; }