Valkka  1.6.1
OpenSource Video Management
muxshmem.h
Go to the documentation of this file.
1 #ifndef muxshmem_HEADER_GUARD
2 #define muxshmem_HEADER_GUARD
3 /*
4  * muxshmem.h :
5  *
6  * (c) Copyright 2017-2024 Sampsa Riikonen
7  *
8  * Authors: Sampsa Riikonen <sampsa.riikonen@iki.fi>
9  *
10  * This file is part of the Valkka library.
11  *
12  * Valkka is free software: you can redistribute it and/or modify
13  * it under the terms of the GNU Lesser General Public License as
14  * published by the Free Software Foundation, either version 3 of the
15  * License, or (at your option) any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20  * GNU Lesser General Public License for more details.
21  *
22  * You should have received a copy of the GNU Lesser General Public License
23  * along with this program. If not, see <https://www.gnu.org/licenses/>
24  *
25  */
26 
36 #include "sharedmem.h"
37 
38 
40 
41 public:
42  FragMP4SharedMemSegment(const char* name, std::size_t n_bytes, bool is_server=false);
43  virtual ~FragMP4SharedMemSegment();
44 
45 protected:
46  virtual void serverInit();
47  virtual bool clientInit();
48  virtual void serverClose();
49  virtual void clientClose();
50 
51 public:
52  virtual std::size_t getSize();
53  virtual void put(std::vector<uint8_t> &inp_payload, void* meta_);
54  virtual void put(uint8_t* buf_, void* meta_);
55  virtual void copyMetaFrom(void *meta_);
56  virtual void copyMetaTo(void *meta_);
57 
58 public:
59  void putMuxFrame(MuxFrame *f);
60 
61 public:
62  FragMP4Meta *meta;
63 };
64 
65 
67 
68 public: // <pyapi>
69  FragMP4SharedMemRingBuffer(const char* name, int n_cells, std::size_t n_size, // <pyapi>
70  int mstimeout=0, bool is_server=false); // <pyapi>
71  virtual ~FragMP4SharedMemRingBuffer(); // <pyapi>
72 
73 public:
74  void serverPushMuxFrame(MuxFrame *f);
75  // ..takes meta_blob
76 
77 public: // <pyapi>
78 // TODO
79  PyObject* clientPullPy(); // <pyapi>
80  // bool serverPushPyMux(PyObject *po, SlotNumber slot, long int mstimestamp); // <pyapi>
81 }; // <pyapi>
82 
83 
84 
85 class FragMP4ShmemFrameFilter : public FrameFilter { // <pyapi>
86 
87 public: // <pyapi>
88  FragMP4ShmemFrameFilter(const char* name, int n_cells, std::size_t n_size, int mstimeout=0); // <pyapi>
89  // ~FragMP4ShmemFrameFilter(); // <pyapi>
90 
91 protected: // initialized at constructor
93 
94 protected:
95  virtual void go(Frame* frame);
96 
97 public: // <pyapi>
98  void useFd(EventFd &event_fd); // <pyapi>
99 }; // <pyapi>
100 
101 
102 #endif
A file descriptor for running select and poll with shmem ring buffers.
Definition: sharedmem.h:56
Definition: muxshmem.h:66
Definition: muxshmem.h:39
virtual std::size_t getSize()
Client: return metadata = the size of the payload (not the maximum size). Uses SharedMemSegment::getM...
Definition: muxshmem.cpp:50
virtual void put(std::vector< uint8_t > &inp_payload, void *meta_)
typecast void to std::size_t
Definition: muxshmem.cpp:54
virtual void copyMetaTo(void *meta_)
Dereference metadata pointer correctly and copy the contents from this memory segment's metadata.
virtual void serverInit()
Uses shmem_open with write rights. used by the constructor if is_server=true. Init with correct metad...
virtual void copyMetaFrom(void *meta_)
Dereference metadata pointer correctly and copy the contents into this memory segment's metadata.
virtual bool clientInit()
Uses shmem_open with read-only rights. Init with correct metadata serialization.
virtual void serverClose()
Erases the shmem segment. used by the constructor if is_server=true.
Definition: muxshmem.h:85
virtual void go(Frame *frame)
Does the actual filtering/modification to the Frame. Define in subclass.
Definition: muxshmem.cpp:214
The mother class of all frame filters! FrameFilters are used to create "filter chains".
Definition: framefilter.h:44
Frame: An abstract queueable class.
Definition: frame.h:112
A muxed packet (in some container format)
Definition: frame.h:220
Interprocess shared memory ring buffer synchronized with posix semaphores.
Definition: sharedmem.h:226
int mstimeout
Semaphore timeout in milliseconds.
Definition: sharedmem.h:247
bool is_server
Are we on the server side or not?
Definition: sharedmem.h:248
Handles a shared memory segment with metadata (the segment size)
Definition: sharedmem.h:85
std::string name
Name to identify the posix objects.
Definition: sharedmem.h:115
std::size_t n_bytes
Maximum size of the payload (this much is reserved)
Definition: sharedmem.h:125
bool is_server
Client or server process?
Definition: sharedmem.h:118
Posix shared memory segment server/client management, shared memory ring buffer synchronized using po...
Definition: metadata.h:53