Instrument Neutral Distributed Interface INDI 2.2.5
serrecorder.h
Go to the documentation of this file.
1/*
2 Copyright (C) 2014 by geehalel <[email protected]>
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
29typedef 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;
45
60
61#define SER_BIG_ENDIAN 0
62#define SER_LITTLE_ENDIAN 1
63
64namespace INDI
65{
66
71{
72 public:
74 virtual ~SER_Recorder();
75
76 virtual const char *getExtension()
77 {
78 return ".ser";
79 }
80 virtual bool setPixelFormat(INDI_PIXEL_FORMAT pixelFormat, uint8_t pixelDepth);
81 virtual bool setSize(uint16_t width, uint16_t height);
82 virtual bool open(const char *filename, char *errmsg);
83 virtual bool close();
85 virtual bool writeFrame(const uint8_t *frame, uint32_t nbytes, uint64_t timestamp);
86 virtual void setStreamEnabled(bool enable)
87 {
88 isStreamingActive = enable;
89 }
90
91 // Public constants
92 static const uint64_t C_SEPASECONDS_PER_SECOND = 10000000;
93
94 protected:
95 uint64_t utcTo64BitTS();
96 bool is_little_endian();
97 void write_int_le(uint32_t *i);
98 void write_long_int_le(uint64_t *i);
99 void write_header(ser_header *s);
102 FILE *f;
103 uint32_t frame_size;
105 uint16_t rawWidth = 0, rawHeight = 0;
106 std::vector<uint64_t> frameStamps;
107
108 private:
109 // From pipp_timestamp.h
110 // Copyright (C) 2015 Chris Garry
111
112 // Date to MS 64bit timestamp format for SER header
113 void dateTo64BitTS(int32_t year, int32_t month, int32_t day, int32_t hour, int32_t minute, int32_t second,
114 int32_t microsec, uint64_t *p_ts);
115
116 uint64_t getUTCTimeStamp();
117 uint64_t getLocalTimeStamp();
118
119 // Calculate if a year is a leap yer
121 static bool is_leap_year(uint32_t year);
122
123 // Constants
124 static const uint64_t m_sepaseconds_per_microsecond = 10;
125 static const uint64_t m_septaseconds_per_part_minute = C_SEPASECONDS_PER_SECOND * 6;
126 static const uint64_t m_septaseconds_per_minute = C_SEPASECONDS_PER_SECOND * 60;
127 static const uint64_t m_septaseconds_per_hour = C_SEPASECONDS_PER_SECOND * 60 * 60;
128 static const uint64_t m_septaseconds_per_day = m_septaseconds_per_hour * 24;
129 static const uint32_t m_days_in_400_years = 303 * 365 + 97 * 366;
130 static const uint64_t m_septaseconds_per_400_years = m_days_in_400_years * m_septaseconds_per_day;
131
132 uint8_t *jpegBuffer = nullptr;
133 INDI_PIXEL_FORMAT m_PixelFormat;
134};
135}
The RecorderInterface class is the base class for recorders.
The SER_Recorder class implements recording of video streams in SER format.
Definition serrecorder.h:71
void write_long_int_le(uint64_t *i)
virtual bool writeFrame(const uint8_t *frame, uint32_t nbytes, uint64_t timestamp)
virtual ~SER_Recorder()
uint64_t utcTo64BitTS()
virtual bool close()
virtual bool open(const char *filename, char *errmsg)
virtual bool setSize(uint16_t width, uint16_t height)
void write_header(ser_header *s)
void write_int_le(uint32_t *i)
virtual bool setPixelFormat(INDI_PIXEL_FORMAT pixelFormat, uint8_t pixelDepth)
std::vector< uint64_t > frameStamps
virtual void setStreamEnabled(bool enable)
Definition serrecorder.h:86
static const uint64_t C_SEPASECONDS_PER_SECOND
Definition serrecorder.h:92
uint32_t number_of_planes
virtual const char * getExtension()
Definition serrecorder.h:76
Class to provide general functionality of a telescope device.
INDI_PIXEL_FORMAT
Namespace to encapsulate INDI client, drivers, and mediator classes.
ser_color_id
Definition serrecorder.h:47
@ SER_BGR
Definition serrecorder.h:58
@ SER_BAYER_GRBG
Definition serrecorder.h:50
@ SER_RGB
Definition serrecorder.h:57
@ SER_BAYER_YCMY
Definition serrecorder.h:54
@ SER_BAYER_CYYM
Definition serrecorder.h:53
@ SER_BAYER_GBRG
Definition serrecorder.h:51
@ SER_MONO
Definition serrecorder.h:48
@ SER_BAYER_BGGR
Definition serrecorder.h:52
@ SER_BAYER_YMCY
Definition serrecorder.h:55
@ SER_BAYER_MYYC
Definition serrecorder.h:56
@ SER_BAYER_RGGB
Definition serrecorder.h:49
uint64_t DateTime
Definition serrecorder.h:42
char FileID[14]
Definition serrecorder.h:31
uint64_t DateTime_UTC
Definition serrecorder.h:43
char Observer[40]
Definition serrecorder.h:39
uint32_t PixelDepth
Definition serrecorder.h:37
uint32_t LittleEndian
Definition serrecorder.h:34
char Instrume[40]
Definition serrecorder.h:40
uint32_t LuID
Definition serrecorder.h:32
uint32_t ColorID
Definition serrecorder.h:33
uint32_t ImageWidth
Definition serrecorder.h:35
uint32_t FrameCount
Definition serrecorder.h:38
uint32_t ImageHeight
Definition serrecorder.h:36