Valkka  1.6.1
OpenSource Video Management
fileframefilter.h
1 #ifndef fileframefilter_HEADER_GUARD
2 #define fileframefilter_HEADER_GUARD
3 
4 /*
5  * fileframefilter.h : File input to matroska files
6  *
7  * (c) Copyright 2017-2024 Sampsa Riikonen
8  *
9  * Authors: Sampsa Riikonen <sampsa.riikonen@iki.fi>
10  *
11  * This file is part of the Valkka library.
12  *
13  * Valkka is free software: you can redistribute it and/or modify
14  * it under the terms of the GNU Lesser General Public License as
15  * published by the Free Software Foundation, either version 3 of the
16  * License, or (at your option) any later version.
17  *
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21  * GNU Lesser General Public License for more details.
22  *
23  * You should have received a copy of the GNU Lesser General Public License
24  * along with this program. If not, see <https://www.gnu.org/licenses/>
25  *
26  */
27 
38 /*
39 
40 Some ideas:
41 
42  * SetupStorageFrameFilter (stores any setup frames it observes)
43 
44 Writing streams:
45 
46  * By a FrameFilter
47  * By a Thread that uses that FrameFilter .. a service, similar to LiveThread or OpenGLThread
48 
49 Reading streams:
50 
51  * A service thread, similar to LiveThread ..?
52  * .. could do both writing and reading
53 
54 Extend LiveThread into sending frames over rtsp (or sdp)
55 
56 
57 */
58 
59 #include "constant.h"
60 #include "framefilter.h"
61 
62 
70 class InitStreamFrameFilter : public FrameFilter { // <pyapi>
71 
72 public: // <pyapi>
73  InitStreamFrameFilter(const char* name, FrameFilter *next = NULL); // <pyapi>
74  ~InitStreamFrameFilter(); // <pyapi>
75 
76 protected:
77  std::vector<SetupFrame> setupframes;
78 
79 protected:
80  void go(Frame* frame);
81  void run(Frame* frame);
82 }; // <pyapi>
83 
84 
85 
124 class FileFrameFilter : public FrameFilter { // <pyapi>
125 
126 public: // <pyapi>
132  FileFrameFilter(const char *name, FrameFilter *next=NULL); // <pyapi>
134  ~FileFrameFilter(); // <pyapi>
135 
136 protected:
137  bool active;
138  bool ready;
139  bool initialized;
140  long int mstimestamp0;
141  long int zerotime;
142  bool zerotimeset;
143  std::string filename;
144 
145 protected: //libav stuff
146  AVRational timebase;
147  std::vector<AVCodecContext*> codec_contexes;
148  std::vector<AVStream*> streams;
149  AVFormatContext *av_format_context;
150  AVPacket *avpkt;
151 
152 protected: //mutex stuff
153  std::mutex mutex;
154  std::condition_variable condition;
155 
156 protected: //frames
157  std::vector<SetupFrame> setupframes;
159 
160 protected:
161  void go(Frame* frame);
162  void initFile();
163  void closeFile();
164  void deActivate_();
165  void writeHeader();
166 
167 public: // API calls // <pyapi>
168  // setFileName(const char* fname); ///< Sets the output filename // <pyapi>
169  void activate(const char* fname, long int zerotime=0);
170  void deActivate();
171 }; // <pyapi>
172 
173 
174 #endif
Custom payload Frame.
Definition: frame.h:166
Pipe stream into a matroska (mkv) file.
Definition: fileframefilter.h:124
long int zerotime
Start time set explicitly by the user.
Definition: fileframefilter.h:141
bool active
Writing to file has been requested (but not necessarily achieved..)
Definition: fileframefilter.h:137
void initFile()
Open file, reserve codec_contexes, streams, write preamble, set initialized=true if success.
Definition: fileframefilter.cpp:185
bool ready
Got enough setup frames.
Definition: fileframefilter.h:138
void deActivate()
Stop streaming to disk // <pyapi>
Definition: fileframefilter.cpp:374
long int mstimestamp0
Time of activation (i.e. when the recording started)
Definition: fileframefilter.h:140
bool initialized
File was opened ok : codec_contexes, streams and av_format_context reserved (should be freed at some ...
Definition: fileframefilter.h:139
std::condition_variable condition
Condition variable for the mutex.
Definition: fileframefilter.h:154
std::mutex mutex
Mutex protecting the "active" boolean.
Definition: fileframefilter.h:153
void activate(const char *fname, long int zerotime=0)
Request streaming to disk asap (when config frames have arrived) // <pyapi>
Definition: fileframefilter.cpp:361
void go(Frame *frame)
Does the actual filtering/modification to the Frame. Define in subclass.
Definition: fileframefilter.cpp:126
std::vector< SetupFrame > setupframes
deep copies of the arrived setup frames
Definition: fileframefilter.h:157
~FileFrameFilter()
Default destructor.
Definition: fileframefilter.cpp:110
void closeFile()
Close file, dealloc codec_contexes, streams.
Definition: fileframefilter.cpp:300
FileFrameFilter(const char *name, FrameFilter *next=NULL)
Default constructor.
Definition: fileframefilter.cpp:97
BasicFrame internal_frame
copy of the arrived frame and payload
Definition: fileframefilter.h:158
The mother class of all frame filters! FrameFilters are used to create "filter chains".
Definition: framefilter.h:44
FrameFilter * next
The next frame filter in the chain to be applied.
Definition: framefilter.h:60
Frame: An abstract queueable class.
Definition: frame.h:112
Add state information to stream.
Definition: fileframefilter.h:70
std::vector< SetupFrame > setupframes
cached setupframes
Definition: fileframefilter.h:77
void run(Frame *frame)
Calls this->go(Frame* frame) and then calls the this->next->run(Frame* frame) (if this->next !...
Definition: fileframefilter.cpp:51
void go(Frame *frame)
Does the actual filtering/modification to the Frame. Define in subclass.
Definition: fileframefilter.cpp:47
Constant/default values, version numbers.
Definition of FrameFilter and derived classes for various purposes.