Instrument Neutral Distributed Interface INDI  1.9.5
serrecorder.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2014 by geehalel <geehalel@gmail.com>
3 
4  SER Recorder
5 
6  This library is free software; you can redistribute it and/or
7  modify it under the terms of the GNU Lesser General Public
8  License as published by the Free Software Foundation; either
9  version 2.1 of the License, or (at your option) any later version.
10 
11  This library is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  Lesser General Public License for more details.
15 
16  You should have received a copy of the GNU Lesser General Public
17  License along with this library; if not, write to the Free Software
18  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 
20 */
21 
22 #pragma once
23 
24 #include "recorderinterface.h"
25 
26 #include <cstdint>
27 #include <stdio.h>
28 
29 typedef struct ser_header
30 {
31  char FileID[14];
32  uint32_t LuID;
33  uint32_t ColorID;
34  uint32_t LittleEndian;
35  uint32_t ImageWidth;
36  uint32_t ImageHeight;
37  uint32_t PixelDepth;
38  uint32_t FrameCount;
39  char Observer[40];
40  char Instrume[40];
41  char Telescope[40];
42  uint64_t DateTime;
43  uint64_t DateTime_UTC;
44 } ser_header;
45 
47 {
48  SER_MONO = 0,
57  SER_RGB = 100,
58  SER_BGR = 101
59 };
60 
61 #define SER_BIG_ENDIAN 0
62 #define SER_LITTLE_ENDIAN 1
63 
64 namespace INDI
65 {
66 
71 {
72  public:
73  SER_Recorder();
74  virtual ~SER_Recorder();
75 
76  virtual const char *getExtension() { return ".ser"; }
77  virtual bool setPixelFormat(INDI_PIXEL_FORMAT pixelFormat, uint8_t pixelDepth);
78  virtual bool setSize(uint16_t width, uint16_t height);
79  virtual bool open(const char *filename, char *errmsg);
80  virtual bool close();
81  virtual bool writeFrame(const uint8_t *frame, uint32_t nbytes);
82  virtual void setStreamEnabled(bool enable) { isStreamingActive = enable; }
83 
84  // Public constants
85  static const uint64_t C_SEPASECONDS_PER_SECOND = 10000000;
86 
87  protected:
88  uint64_t utcTo64BitTS();
89  bool is_little_endian();
90  void write_int_le(uint32_t *i);
91  void write_long_int_le(uint64_t *i);
92  void write_header(ser_header *s);
94  bool isRecordingActive = false, isStreamingActive = false;
95  FILE *f;
96  uint32_t frame_size;
97  uint32_t number_of_planes;
98  uint16_t rawWidth = 0, rawHeight = 0;
99  std::vector<uint64_t> frameStamps;
100 
101  private:
102  // From pipp_timestamp.h
103  // Copyright (C) 2015 Chris Garry
104 
105  // Date to MS 64bit timestamp format for SER header
106  void dateTo64BitTS(int32_t year, int32_t month, int32_t day, int32_t hour, int32_t minute, int32_t second,
107  int32_t microsec, uint64_t *p_ts);
108 
109  uint64_t getUTCTimeStamp();
110  uint64_t getLocalTimeStamp();
111 
112  // Calculate if a year is a leap yer
114  static bool is_leap_year(uint32_t year);
115 
116  // Constants
117  static const uint64_t m_sepaseconds_per_microsecond = 10;
118  static const uint64_t m_septaseconds_per_part_minute = C_SEPASECONDS_PER_SECOND * 6;
119  static const uint64_t m_septaseconds_per_minute = C_SEPASECONDS_PER_SECOND * 60;
120  static const uint64_t m_septaseconds_per_hour = C_SEPASECONDS_PER_SECOND * 60 * 60;
121  static const uint64_t m_septaseconds_per_day = m_septaseconds_per_hour * 24;
122  static const uint32_t m_days_in_400_years = 303 * 365 + 97 * 366;
123  static const uint64_t m_septaseconds_per_400_years = m_days_in_400_years * m_septaseconds_per_day;
124 
125  uint8_t *jpegBuffer=nullptr;
126  INDI_PIXEL_FORMAT m_PixelFormat;
127 };
128 }
SER_BAYER_GBRG
@ SER_BAYER_GBRG
Definition: serrecorder.h:51
ser_header::ImageHeight
uint32_t ImageHeight
Definition: serrecorder.h:36
ser_header::DateTime_UTC
uint64_t DateTime_UTC
Definition: serrecorder.h:43
ser_header::PixelDepth
uint32_t PixelDepth
Definition: serrecorder.h:37
INDI::SER_Recorder::frameStamps
std::vector< uint64_t > frameStamps
Definition: serrecorder.h:99
SER_BGR
@ SER_BGR
Definition: serrecorder.h:58
INDI::SER_Recorder::C_SEPASECONDS_PER_SECOND
static const uint64_t C_SEPASECONDS_PER_SECOND
Definition: serrecorder.h:85
INDI::SER_Recorder::frame_size
uint32_t frame_size
Definition: serrecorder.h:96
INDI::SER_Recorder::setStreamEnabled
virtual void setStreamEnabled(bool enable)
Definition: serrecorder.h:82
INDI::SER_Recorder::SER_Recorder
SER_Recorder()
Definition: serrecorder.cpp:42
INDI::SER_Recorder::writeFrame
virtual bool writeFrame(const uint8_t *frame, uint32_t nbytes)
Definition: serrecorder.cpp:215
INDI::SER_Recorder::isRecordingActive
bool isRecordingActive
Definition: serrecorder.h:94
ser_header::Observer
char Observer[40]
Definition: serrecorder.h:39
SER_BAYER_YCMY
@ SER_BAYER_YCMY
Definition: serrecorder.h:54
INDI::SER_Recorder::isStreamingActive
bool isStreamingActive
Definition: serrecorder.h:94
INDI::SER_Recorder
The SER_Recorder class implements recording of video streams in SER format.
Definition: serrecorder.h:70
SER_BAYER_MYYC
@ SER_BAYER_MYYC
Definition: serrecorder.h:56
ser_header::DateTime
uint64_t DateTime
Definition: serrecorder.h:42
Telescope
Class to provide general functionality of a telescope device.
INDI::SER_Recorder::f
FILE * f
Definition: serrecorder.h:95
SER_BAYER_CYYM
@ SER_BAYER_CYYM
Definition: serrecorder.h:53
INDI::SER_Recorder::close
virtual bool close()
Definition: serrecorder.cpp:195
INDI::SER_Recorder::write_header
void write_header(ser_header *s)
Definition: serrecorder.cpp:101
INDI::SER_Recorder::utcTo64BitTS
uint64_t utcTo64BitTS()
ser_header::FileID
char FileID[14]
Definition: serrecorder.h:31
INDI::SER_Recorder::setSize
virtual bool setSize(uint16_t width, uint16_t height)
Definition: serrecorder.cpp:160
ser_header::ColorID
uint32_t ColorID
Definition: serrecorder.h:33
ser_header
struct ser_header ser_header
INDI::SER_Recorder::getExtension
virtual const char * getExtension()
Definition: serrecorder.h:76
SER_RGB
@ SER_RGB
Definition: serrecorder.h:57
INDI::SER_Recorder::write_int_le
void write_int_le(uint32_t *i)
Definition: serrecorder.cpp:73
SER_MONO
@ SER_MONO
Definition: serrecorder.h:48
INDI::SER_Recorder::~SER_Recorder
virtual ~SER_Recorder()
Definition: serrecorder.cpp:61
ser_header::FrameCount
uint32_t FrameCount
Definition: serrecorder.h:38
INDI::SER_Recorder::is_little_endian
bool is_little_endian()
Definition: serrecorder.cpp:66
ser_header::LittleEndian
uint32_t LittleEndian
Definition: serrecorder.h:34
INDI
Namespace to encapsulate INDI client, drivers, and mediator classes.
Definition: AlignmentSubsystemForClients.cpp:11
ser_header
Definition: serrecorder.h:29
INDI::SER_Recorder::serh
ser_header serh
Definition: serrecorder.h:93
INDI::SER_Recorder::setPixelFormat
virtual bool setPixelFormat(INDI_PIXEL_FORMAT pixelFormat, uint8_t pixelDepth)
Definition: serrecorder.cpp:118
INDI::SER_Recorder::rawWidth
uint16_t rawWidth
Definition: serrecorder.h:98
ser_header::LuID
uint32_t LuID
Definition: serrecorder.h:32
INDI::RecorderInterface
The RecorderInterface class is the base class for recorders.
Definition: recorderinterface.h:56
INDI::SER_Recorder::write_long_int_le
void write_long_int_le(uint64_t *i)
Definition: serrecorder.cpp:87
recorderinterface.h
SER_BAYER_RGGB
@ SER_BAYER_RGGB
Definition: serrecorder.h:49
ser_header::ImageWidth
uint32_t ImageWidth
Definition: serrecorder.h:35
SER_BAYER_GRBG
@ SER_BAYER_GRBG
Definition: serrecorder.h:50
INDI::SER_Recorder::number_of_planes
uint32_t number_of_planes
Definition: serrecorder.h:97
SER_BAYER_YMCY
@ SER_BAYER_YMCY
Definition: serrecorder.h:55
ser_color_id
ser_color_id
Definition: serrecorder.h:46
INDI::SER_Recorder::rawHeight
uint16_t rawHeight
Definition: serrecorder.h:98
SER_BAYER_BGGR
@ SER_BAYER_BGGR
Definition: serrecorder.h:52
INDI::SER_Recorder::open
virtual bool open(const char *filename, char *errmsg)
Definition: serrecorder.cpp:173
ser_header::Instrume
char Instrume[40]
Definition: serrecorder.h:40
INDI_PIXEL_FORMAT
INDI_PIXEL_FORMAT
Definition: indibasetypes.h:63