Instrument Neutral Distributed Interface INDI 2.2.5
theorarecorder.h
Go to the documentation of this file.
1/*
2 Copyright (C) 2017 by Jasem Mutlaq <[email protected]>
3
4 Theora 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 <ogg/ogg.h>
27#include <theora/theoraenc.h>
28
29#include <cstdint>
30#include <stdio.h>
31
32namespace INDI
33{
34
39{
40 public:
42 virtual ~TheoraRecorder();
43
44 virtual const char *getExtension()
45 {
46 return ".ogv";
47 }
48 virtual bool setPixelFormat(INDI_PIXEL_FORMAT pixelFormat, uint8_t pixelDepth);
49 virtual bool setSize(uint16_t width, uint16_t height);
50 virtual bool open(const char *filename, char *errmsg);
51 virtual bool close();
52 virtual bool writeFrame(const uint8_t *frame, uint32_t nbytes, uint64_t timestamp);
53 virtual void setStreamEnabled(bool enable)
54 {
55 isStreamingActive = enable;
56 }
57
58 protected:
59 bool isRecordingActive = false, isStreamingActive = false;
61 uint16_t rawWidth = 0, rawHeight = 0;
62 std::vector<uint64_t> frameStamps;
64 uint8_t m_PixelDepth = 8;
65
66 private:
67 bool allocateBuffers();
68 //int theora_write_frame(th_ycbcr_buffer ycbcr, int last);
69 int theora_write_frame(int last);
70 bool frac(double fps, uint32_t &num, uint32_t &den);
71
72 th_ycbcr_buffer ycbcr;
73 ogg_uint32_t video_fps_numerator = 24;
74 ogg_uint32_t video_fps_denominator = 1;
75 ogg_uint32_t video_aspect_numerator = 0;
76 ogg_uint32_t video_aspect_denominator = 0;
77 int video_rate = -1;
78 int video_quality = -1;
79 int soft_target = 0;
80 ogg_uint32_t keyframe_frequency = 0;
81 int buf_delay = -1;
82 int vp3_compatible = 0;
83 int chroma_format = TH_PF_420;
84
85 FILE *twopass_file = nullptr;
86 int twopass = 0;
87 int passno = 0;
88
89 FILE *ogg_fp = nullptr;
90 ogg_stream_state ogg_os;
91 ogg_packet op;
92 ogg_page og;
93
94 th_enc_ctx *td = nullptr;
95 th_info ti;
96 th_comment tc;
97};
98}
The RecorderInterface class is the base class for recorders.
The TheoraRecorder class implemented recording of video streaming data in a libtheora OGV file.
virtual bool setPixelFormat(INDI_PIXEL_FORMAT pixelFormat, uint8_t pixelDepth)
std::vector< uint64_t > frameStamps
virtual bool writeFrame(const uint8_t *frame, uint32_t nbytes, uint64_t timestamp)
virtual bool open(const char *filename, char *errmsg)
virtual void setStreamEnabled(bool enable)
virtual const char * getExtension()
INDI_PIXEL_FORMAT m_PixelFormat
virtual bool setSize(uint16_t width, uint16_t height)
INDI_PIXEL_FORMAT
Namespace to encapsulate INDI client, drivers, and mediator classes.