frame_handler_impl.h
Go to the documentation of this file.
1 /*
2  * BSD 3-Clause License
3  *
4  * Copyright (c) 2019, Analog Devices, Inc.
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions are met:
9  *
10  * 1. Redistributions of source code must retain the above copyright notice, this
11  * list of conditions and the following disclaimer.
12  *
13  * 2. Redistributions in binary form must reproduce the above copyright notice,
14  * this list of conditions and the following disclaimer in the documentation
15  * and/or other materials provided with the distribution.
16  *
17  * 3. Neither the name of the copyright holder nor the names of its
18  * contributors may be used to endorse or promote products derived from
19  * this software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
25  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */
32 #ifndef FRAME_HANDLER
33 #define FRAME_HANDLER
34 
35 #include <aditof/camera.h>
36 #include <aditof/frame.h>
37 #include <aditof/frame_handler.h>
39 
40 #include <chrono>
41 #include <fstream>
42 #include <functional>
43 #include <iostream>
44 #include <mutex>
45 #include <queue>
46 #include <string>
47 #include <thread>
48 
49 #define METADATA_SIZE 128
50 
52  public:
55 
56  //Open existing file/create new file to store data
58  aditof::Status setInputFileName(const std::string &fullFileName);
59 
60  //the api should only use frame objects when saving/reading data from file
61  //the conversion between formats should happen inside the functions
62 
63  //store frame to file
65  const std::string &fileName = "");
66 
67  //TO DO: write function to save frames on different thread
68  //aditof::Status enqueueFrameToSaveToFile(aditof::Frame frame);
70  const std::string &filename = "");
71 
72  //read new frame from file and process metadata to get new frame
73  //charateristics if we have different frame types in the same file
75  const std::string &fullFileName = "");
76 
77  //We could offer support for a couple of standart formats (avi/mp4/..)
78  //and let the users decide between them
80 
81  //aditof::Status splitFrames(bool enable);
83  //aditof::Status storeSingleFrameToFile(bool enable);
84  //aditof::Status storeToSingleFile(bool enable);
85 
86  //we should be able to give the users the ability to choose which data
87  //type they want to store (depth/ab/conf/metadata/full-data) or any combinations
88  //between this 2
89  //NOTE: metadata should be always enabled for a better data processing
90  aditof::Status setFrameContent(const std::string &frameContent);
91 
92  private:
94 
95  aditof::Status createFile(const std::string &fileName);
96  void threadWritter();
97  //aditof::Status writtingThread(std::string fileName = "");
98  //We should be able do decide if we want to store frames in the same file
99  //or store them in different files
101 
102  //Let the users decide if they want to use multithreading or not
104 
105  //we should offer a standart format that would be compatible with our examples
106  //(viewer/data-collect/python bindings/etc)
107  //it would be nice if we could give the users the posibility to store data in other
108  //formats (mp4, avi, etc)
111 
112  //relevant data extracted from metadata that can help us compute frame size
119 
123 
124  //variables used for file handling
131  std::fstream m_file;
132  size_t m_pos;
133  int m_frameCount = 0;
134 
135  //multithread variables
136  std::mutex m_mutex;
137  std::thread m_threadWorker;
138  std::queue<aditof::Frame> m_frameQueue;
139  std::queue<std::string> m_frameNameQueue;
140  volatile bool m_threadRunning;
141 };
142 
143 #endif // FRAME_HANDLER
FrameHandlerImpl::m_endOfFile
bool m_endOfFile
Definition: frame_handler_impl.h:130
FrameHandlerImpl::m_file
std::fstream m_file
Definition: frame_handler_impl.h:131
FrameHandlerImpl::m_frameNameQueue
std::queue< std::string > m_frameNameQueue
Definition: frame_handler_impl.h:139
frame_handler.h
FrameHandlerImpl::getOutputFileFullPath
std::string getOutputFileFullPath(const std::string &fileName)
Definition: frame_handler_impl.cpp:360
FrameHandlerImpl::m_bitsInDepth
int m_bitsInDepth
Definition: frame_handler_impl.h:113
FrameHandlerImpl::m_mutex
std::mutex m_mutex
Definition: frame_handler_impl.h:136
FrameHandlerImpl::m_frameWidth
int m_frameWidth
Definition: frame_handler_impl.h:116
FrameHandlerImpl::m_bitsInConf
int m_bitsInConf
Definition: frame_handler_impl.h:115
FrameHandlerImpl::m_threadRunning
volatile bool m_threadRunning
Definition: frame_handler_impl.h:140
string
GLsizei const GLchar *const * string
Definition: glcorearb.h:3083
FrameHandlerImpl::saveFrameToFileMultithread
aditof::Status saveFrameToFileMultithread(aditof::Frame &frame, const std::string &filename="")
Definition: frame_handler_impl.cpp:146
FrameHandlerImpl::m_frDetails
aditof::FrameDetails m_frDetails
Definition: frame_handler_impl.h:121
FrameHandlerImpl::m_frameQueue
std::queue< aditof::Frame > m_frameQueue
Definition: frame_handler_impl.h:138
FrameHandlerImpl::setFrameContent
aditof::Status setFrameContent(const std::string &frameContent)
Definition: frame_handler_impl.cpp:323
aditof::FrameDetails
Describes the properties of a frame.
Definition: frame_definitions.h:93
aditof::Metadata
Contains all of the metadata components.
Definition: frame_definitions.h:147
FrameHandlerImpl::setInputFileName
aditof::Status setInputFileName(const std::string &fullFileName)
Definition: frame_handler_impl.cpp:63
FrameHandlerImpl::threadWritter
void threadWritter()
Definition: frame_handler_impl.cpp:171
FrameHandlerImpl::setOutputFilePath
aditof::Status setOutputFilePath(const std::string &filePath)
Definition: frame_handler_impl.cpp:56
format
GLint GLint GLsizei GLint GLenum format
Definition: glcorearb.h:2773
FrameHandlerImpl::m_bitsInAB
int m_bitsInAB
Definition: frame_handler_impl.h:114
FrameHandlerImpl::storeFramesToSingleFile
aditof::Status storeFramesToSingleFile(bool enable)
Definition: frame_handler_impl.cpp:316
FrameHandlerImpl::setCustomFormat
aditof::Status setCustomFormat(const std::string &format)
Definition: frame_handler_impl.cpp:312
FrameHandlerImpl::m_frameHeight
int m_frameHeight
Definition: frame_handler_impl.h:117
frame.h
FrameHandlerImpl::createFile
aditof::Status createFile(const std::string &fileName)
Definition: frame_handler_impl.cpp:327
aditof::Status
Status
Status of any operation that the TOF sdk performs.
Definition: status_definitions.h:48
FrameHandlerImpl::m_threadWorker
std::thread m_threadWorker
Definition: frame_handler_impl.h:137
camera.h
FrameHandlerImpl::m_fullInputFileName
std::string m_fullInputFileName
Definition: frame_handler_impl.h:127
FrameHandlerImpl::m_metadataStruct
aditof::Metadata m_metadataStruct
Definition: frame_handler_impl.h:122
FrameHandlerImpl::~FrameHandlerImpl
~FrameHandlerImpl()
Definition: frame_handler_impl.cpp:50
FrameHandlerImpl::m_customFormatType
std::string m_customFormatType
Definition: frame_handler_impl.h:110
FrameHandlerImpl::FrameHandlerImpl
FrameHandlerImpl()
Definition: frame_handler_impl.cpp:44
FrameHandlerImpl::m_swapFrame
aditof::Frame m_swapFrame
Definition: frame_handler_impl.h:120
FrameHandlerImpl
Definition: frame_handler_impl.h:51
aditof::Frame
Frame of a camera.
Definition: frame.h:50
status_definitions.h
FrameHandlerImpl::m_concatFrames
bool m_concatFrames
Definition: frame_handler_impl.h:100
FrameHandlerImpl::m_inputFileName
std::string m_inputFileName
Definition: frame_handler_impl.h:128
FrameHandlerImpl::m_outputFileName
std::string m_outputFileName
Definition: frame_handler_impl.h:126
FrameHandlerImpl::saveFrameToFile
aditof::Status saveFrameToFile(aditof::Frame &frame, const std::string &fileName="")
Definition: frame_handler_impl.cpp:70
FrameHandlerImpl::m_customFormat
bool m_customFormat
Definition: frame_handler_impl.h:109
FrameHandlerImpl::m_enableMultithreading
bool m_enableMultithreading
Definition: frame_handler_impl.h:103
FrameHandlerImpl::m_fileCreated
bool m_fileCreated
Definition: frame_handler_impl.h:129
FrameHandlerImpl::readNextFrame
aditof::Status readNextFrame(aditof::Frame &frame, const std::string &fullFileName="")
Definition: frame_handler_impl.cpp:186
FrameHandlerImpl::m_pos
size_t m_pos
Definition: frame_handler_impl.h:132
FrameHandlerImpl::m_dir
std::string m_dir
Definition: frame_handler_impl.h:125
FrameHandlerImpl::m_frameCount
int m_frameCount
Definition: frame_handler_impl.h:133
FrameHandlerImpl::m_frameIndex
int m_frameIndex
Definition: frame_handler_impl.h:118


libaditof
Author(s):
autogenerated on Wed May 21 2025 02:06:51