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