41static const char * STREAM_TAB =
"Streaming";
94 return d->getDeviceName();
116 StreamTimeNP[0].fill(
"STREAM_DELAY_TIME",
"Delay (s)",
"%.3f", 0, 60, 0.001, 0);
126 FpsNP[
FPS_INSTANT].fill(
"EST_FPS",
"Instant.",
"%.2f", 0.0, 999.0, 0.0, 30);
127 FpsNP[
FPS_AVERAGE].fill(
"AVG_FPS",
"Average (1 sec.)",
"%.2f", 0.0, 999.0, 0.0, 30);
133 std::string defaultDirectory = std::string(getenv(
"HOME")) + std::string(
"/Videos/indi__D_");
134 RecordFileTP[0].fill(
"RECORD_FILE_DIR",
"Dir.", defaultDirectory.data());
135 RecordFileTP[1].fill(
"RECORD_FILE_NAME",
"Name",
"indi_record__T_");
141 RecordOptionsNP[0].fill(
"RECORD_DURATION",
"Duration (sec)",
"%.3f", 0.001, 999999.0, 0.0, 1.0);
142 RecordOptionsNP[1].fill(
"RECORD_FRAME_TOTAL",
"Frames",
"%.f", 1.0, 999999999.0, 1.0, 30.0);
161 StreamFrameNP[3].fill(
"HEIGHT",
"Height",
"%.f", 0, 0, 0, 0);
228 return d->initProperties();
263 d->ISGetProperties(dev);
333 return d->updateProperties();
381 size_t allocatedSize = nbytes *
framesIncoming.size() / 1024 / 1024;
384 LOG_WARN(
"Frame buffer is full, skipping frame...");
388 std::vector<uint8_t> copyBuffer(buffer, buffer + nbytes);
403 LOG_INFO(
"Waiting for all buffered frames to be recorded");
408 "Ending record after %g millisecs and %d frames",
426 d->newFrame(buffer, nbytes, timestamp);
435 uint8_t bytesPerComponent = (
PixelDepth + 7) / 8;
437 dstFrameInfo.bytesPerColor = components * bytesPerComponent;
443 components * bytesPerComponent
450 components * bytesPerComponent
469 const uint8_t *srcBuffer,
476 uint32_t srcStride = srcFrameInfo.
lineSize();
479 srcBuffer += srcOffset;
484 memcpy(dstBuffer, srcBuffer, dstStride);
485 dstBuffer += dstStride;
486 srcBuffer += srcStride;
493 sourceTimeFrame.
time = 0;
495 std::vector<uint8_t> subframeBuffer;
496 std::vector<uint8_t> downscaleBuffer;
508 std::vector<uint8_t> *sourceBuffer = &sourceTimeFrame.
frame;
515 LOGF_ERROR(
"Source buffer size %d is less than frame size %d, skipping frame...", sourceBuffer->size(),
521 bool isSubframed =
false;
531 sourceBuffer = &subframeBuffer;
570 reinterpret_cast<const uint16_t*
>(sourceBuffer->data()),
571 downscaleBuffer.size(),
572 downscaleBuffer.data()
575 sourceBuffer = &downscaleBuffer;
579 previewThreadPool.
start(std::bind([
this, &previewElapsed](
const std::atomic_bool & isAboutToQuit,
580 std::vector<uint8_t> frame)
583 previewElapsed.
start();
588 }, std::placeholders::_1, std::move(*sourceBuffer)));
598 LOG_WARN(
"Cannot subframe JPEG streams.");
634 std::lock_guard<std::mutex> lock(d->recordMutex);
635 return d->recorder->close();
643 bool recorderOK =
recorder->setPixelFormat(pixelFormat, pixelDepth);
644 if (recorderOK ==
false)
646 LOGF_ERROR(
"Pixel format %d is not supported by %s recorder.", pixelFormat,
recorder->getName());
650 LOGF_DEBUG(
"Pixel format %d is supported by %s recorder.", pixelFormat,
recorder->getName());
652 bool encoderOK =
encoder->setPixelFormat(pixelFormat, pixelDepth);
653 if (encoderOK ==
false)
655 LOGF_ERROR(
"Pixel format %d is not supported by %s encoder.", pixelFormat,
encoder->getName());
659 LOGF_DEBUG(
"Pixel format %d is supported by %s encoder.", pixelFormat,
encoder->getName());
670 return d->setPixelFormat(pixelFormat, pixelDepth);
677 d->setSize(width, height);
686 return recorder->writeFrame(buffer, nbytes, timestamp);
691 std::string result = fname;
693 std::time_t t = std::time(
nullptr);
694 std::tm tm = *std::gmtime(&t);
696 auto extendedPatterns = patterns;
697 extendedPatterns[
"_D_"] =
format_time(tm,
"%Y-%m-%d");
698 extendedPatterns[
"_H_"] =
format_time(tm,
"%H-%M-%S");
699 extendedPatterns[
"_T_"] =
format_time(tm,
"%Y-%m-%d" "@" "%H-%M-%S");
701 for(
const auto &pattern : extendedPatterns)
703 replace_all(result, pattern.first, pattern.second);
707 std::replace(result.begin(), result.end(),
':',
'-');
715 std::string filename, expfilename, expfiledir;
716 std::string filtername;
717 std::map<std::string, std::string> patterns;
730 patterns[
"_F_"] = filtername;
731 LOGF_DEBUG(
"Adding filter pattern %s", filtername.c_str());
740 if (
const char * home = getenv(
"HOME"))
741 patterns[
"_HOME_"] = home;
746 if (expfiledir.at(expfiledir.size() - 1) !=
'/')
750 if (expfilename.size() < 4 || expfilename.substr(expfilename.size() - 4, 4) !=
recorder->getExtension())
751 expfilename +=
recorder->getExtension();
753 filename = expfiledir + expfilename;
756 LOGF_INFO(
"Record file is %s", filename.c_str());
758 if (
mkpath(expfiledir, 0755))
760 LOGF_WARN(
"Can not create record directory %s: %s", expfiledir.c_str(),
764 if (!
recorder->open(filename.c_str(), errmsg))
768 LOGF_WARN(
"Can not open record file: %s", errmsg);
777 LOG_INFO(
"Using direct recording (no software cropping).");
854 "Record Duration: %g millisec / %d frames",
871 for (
int i = 0; i <
n; i++)
873 if (!strcmp(names[i],
"STREAM_ON") && states[i] ==
ISS_ON)
878 else if (!strcmp(names[i],
"STREAM_OFF") && states[i] ==
ISS_ON)
898 LOG_WARN(
"Recording device is busy.");
934 LOG_INFO(
"Recording stream has been disabled. Closing the stream...");
949 const char * selectedEncoder =
EncoderSP.findOnSwitch()->getName();
953 if (!strcmp(selectedEncoder, oneEncoder->getName()))
974 const char * selectedRecorder =
RecorderSP.findOnSwitch()->getName();
978 if (!strcmp(selectedRecorder, oneRecorder->getName()))
1019 return d->ISNewSwitch(dev, name, states, names,
n);
1030 auto tp =
RecordFileTP.findWidgetByName(
"RECORD_FILE_NAME");
1031 if (strchr(tp->getText(),
'/'))
1033 LOG_WARN(
"Dir. separator (/) not allowed in filename.");
1049 return d->ISNewText(dev, name, texts, names,
n);
1084 LOG_WARN(
"Recording device is busy");
1099 LOG_WARN(
"Recording device is busy");
1135 LOG_WARN(
"Turn tracking on before setting the lock point.");
1169 return d->ISNewNumber(dev, name, values, names,
n);
1180 if (StreamOptionsN[OPTION_RATE_DIVISOR].value > 0)
1182 "Starting the video stream with target FPS %.f and rate divisor of %.f",
1183 StreamOptionsN[OPTION_TARGET_FPS].value, StreamOptionsN[OPTION_RATE_DIVISOR].value);
1185 LOGF_INFO(
"Starting the video stream with target FPS %.f", StreamOptionsN[OPTION_TARGET_FPS].value);
1187 LOGF_INFO(
"Starting the video stream with target exposure %.6f s (Max theoretical FPS %.f)",
1203 LOG_ERROR(
"Failed to start streaming.");
1215 LOG_ERROR(
"Failed to start streaming.");
1279 return d->setStream(enable);
1285 d->EncoderSP.save(fp);
1286 d->RecordFileTP.save(fp);
1287 d->RecordOptionsNP.save(fp);
1288 d->RecorderSP.save(fp);
1289 d->LimitsNP.save(fp);
1290 d->FullDepthSP.save(fp);
1292 d->TrackingSettingsNP.save(fp);
1315 LOG_INFO(
"Tracking enabled. The target position is measured while streaming or recording.");
1340 image.
data = buffer;
1341 image.
width = width;
1360 LOG_ERROR(
"Tracking is not supported for compressed (JPEG) streams.");
1370 measurement.
x += originX;
1371 measurement.
y += originY;
1374 const double now = std::chrono::duration<double>(std::chrono::system_clock::now().time_since_epoch()).count();
1432 d->getStreamFrame(x, y, w, h);
1440 imageBP[0].setBlob(
const_cast<uint8_t *
>(buffer));
1441 imageBP[0].setBlobLen(nbytes);
1443 imageBP[0].setFormat(
".stream_jpg");
1493 return d->direct_record;
1499 return d->isStreaming;
1505 return d->isRecording && !d->isRecordingAboutToClose;
1511 return (d->isStreaming || d->isRecording);
1517 return 1.0 / d->StreamExposureNP[0].getValue();
1522 return d->StreamExposureNP[0].getValue();
1528 d->hasStreamingExposure = enable;
bool isCompressed() const
isCompressed
Class to provide general functionality of CCD cameras with a single CCD sensor, or a primary CCD sens...
Class to provide extended functionality for devices in addition to the functionality provided by INDI...
The ElapsedTimer class provides a fast way to calculate elapsed times.
int64_t nsecsElapsed() const
Returns the number of nanoseconds since this ElapsedTimer was last started.
void start()
Starts this timer. Once started, a timer value can be checked with elapsed().
The EncoderInterface class is the base class for video streaming encoders.
static Measurement measure(const Image &image, double referenceArea=0)
measure Find the target in a single frame.
The RecorderInterface class is the base class for recorders.
The SensorDevice class provides functionality of a Sensor Device within a Sensor.
void start(const std::function< void(const std::atomic_bool &isAboutToClose)> &functionToRun)
Reserves a thread and uses it to run functionToRun. A running function can check the 'isAboutToClose'...
bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n)
std::atomic< bool > isRecording
bool setPixelFormat(INDI_PIXEL_FORMAT pixelFormat, uint8_t pixelDepth)
INDI::PropertyNumber TrackingSettingsNP
INDI::PropertySwitch RecordStreamSP
bool hasStreamingExposure
static std::string expand(const std::string &fname, const std::map< std::string, std::string > &patterns)
void setStreamFrame(uint16_t x, uint16_t y, uint16_t w, uint16_t h)
bool trackingFormatWarned
INDI::PropertySwitch EncoderSP
std::atomic< bool > isStreaming
std::atomic< bool > isTracking
INDI::PropertySwitch StreamSP
static void subframe(const uint8_t *srcBuffer, const FrameInfo &srcFrameInfo, uint8_t *dstBuffer, const FrameInfo &dstFrameInfo)
void newFrame(const uint8_t *buffer, uint32_t nbytes, uint64_t timestamp)
std::atomic< bool > isRecordingAboutToClose
bool stopRecording(bool force=false)
UniqueQueue< TimeFrame > framesIncoming
virtual ~StreamManagerPrivate()
INDI::PropertySwitch FullDepthSP
void processTracking(const uint8_t *buffer, size_t width, size_t height, size_t originX, size_t originY)
processTracking Measure the target in a frame and publish the averaged offset.
INDI::PropertyBlob imageBP
std::atomic< bool > framesThreadTerminate
INDI::PropertyNumber RecordOptionsNP
EncoderInterface * encoder
const char * getDeviceName() const
std::string recordfiledir
INDI::PropertyNumber TrackingOffsetNP
uint32_t frameCountDivider
void setTracking(bool enable)
INDI::PropertyNumber StreamTimeNP
INDI::PropertyNumber FpsNP
void setSize(uint16_t width, uint16_t height)
EncoderManager encoderManager
bool ISNewText(const char *dev, const char *name, char *texts[], char *names[], int n)
INDI::PropertyNumber TrackingLockNP
std::string recordfilename
bool uploadStream(const uint8_t *buffer, uint32_t nbytes)
uploadStream Upload frame to client using the selected encoder
INDI_PIXEL_FORMAT PixelFormat
RecorderManager recorderManager
INDI::PropertySwitch TrackingSP
bool recordStream(const uint8_t *buffer, uint32_t nbytes, double deltams, uint64_t timestamp)
recordStream Calls the backend recorder to record a single frame.
uint32_t trackingSequence
FrameTracker frameTracker
RecorderInterface * recorder
INDI::PropertyText RecordFileTP
INDI::PropertyNumber StreamFrameNP
bool setStream(bool enable)
DefaultDevice * currentDevice
INDI::PropertyNumber LimitsNP
StreamManagerPrivate(DefaultDevice *defaultDevice)
void getStreamFrame(uint16_t *x, uint16_t *y, uint16_t *w, uint16_t *h) const
void asyncStreamThread()
Thread processing frames and forwarding to recording and preview.
void ISGetProperties(const char *dev)
FrameInfo updateSourceFrameInfo()
bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n)
INDI::PropertyNumber StreamExposureNP
INDI::PropertySwitch RecorderSP
void setSize(uint16_t width, uint16_t height=1)
bool isDirectRecording() const
void getStreamFrame(uint16_t *x, uint16_t *y, uint16_t *w, uint16_t *h) const
void newFrame(const uint8_t *buffer, uint32_t nbytes, uint64_t timestamp=0)
newFrame CCD drivers call this function when a new frame is received. It is then streamed,...
void setStreamingExposureEnabled(bool enable)
setStreamingExposureEnabled Can stream exposure time be changed?
std::shared_ptr< StreamManagerPrivate > d_ptr
bool setPixelFormat(INDI_PIXEL_FORMAT pixelFormat, uint8_t pixelDepth=8)
double getTargetExposure() const
bool setStream(bool enable)
setStream Enables (starts) or disables (stops) streaming.
double getTargetFPS() const
virtual bool ISNewText(const char *dev, const char *name, char *texts[], char *names[], int n)
virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n)
virtual void ISGetProperties(const char *dev)
virtual bool initProperties()
StreamManager(DefaultDevice *currentDevice)
virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n)
virtual bool saveConfigItems(FILE *fp)
RecorderInterface * getRecorder() const
virtual bool updateProperties()
const char * getDeviceName() const
*brief user defined string literal for JSON values *sa std::size_t n
#define LOGF_INFO(fmt,...)
#define LOGF_WARN(fmt,...)
#define LOGF_DEBUG(fmt,...)
#define LOG_ERROR(txt)
Shorter logging macros. In order to use these macros, the function (or method) "getDeviceName()" must...
#define LOGF_ERROR(fmt,...)
#define DEBUGF(priority, msg,...)
Namespace to encapsulate INDI client, drivers, and mediator classes.
std::string format_time(const std::tm &tm, const char *format)
void replace_all(std::string &subject, const std::string &search, const std::string &replace)
int mkpath(std::string s, mode_t mode)
bool bayer
Raw Bayer mosaic: binning is kept even so each bin averages whole CFA cells.
size_t bytesPerComponent
1 for 8-bit, 2 for 16-bit (native endian) samples
size_t components
1 for mono or Bayer, 3 for interleaved RGB
double x
Centroid in frame pixels.
double offsetX
Averaged centroid minus lock point.
double quality
Mean quality of the valid samples, scaled by the fraction of samples that were valid.
double windowStart
Time of the first sample in the window.
bool valid
False if no sample in the window was valid (target lost).
double x
Averaged centroid in frame pixels.
std::vector< uint8_t > frame