2019-06-27 22:29:47 +08:00
|
|
|
//
|
2021-03-02 02:49:17 +08:00
|
|
|
// ZoneMinder Fifo
|
2019-06-27 22:29:47 +08:00
|
|
|
// Copyright (C) 2019 ZoneMinder LLC
|
|
|
|
//
|
|
|
|
// This program is free software; you can redistribute it and/or
|
|
|
|
// modify it under the terms of the GNU General Public License
|
|
|
|
// as published by the Free Software Foundation; either version 2
|
|
|
|
// of the License, or (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with this program; if not, write to the Free Software
|
|
|
|
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
//
|
2019-05-17 03:37:03 +08:00
|
|
|
#ifndef ZM_FIFO_H
|
|
|
|
#define ZM_FIFO_H
|
|
|
|
|
|
|
|
#include "zm_stream.h"
|
2021-02-28 01:27:10 +08:00
|
|
|
#include "zm_packet.h"
|
2019-05-17 03:37:03 +08:00
|
|
|
|
2021-02-04 11:47:28 +08:00
|
|
|
class Monitor;
|
|
|
|
|
2021-03-02 02:49:17 +08:00
|
|
|
class Fifo {
|
2019-06-27 22:29:47 +08:00
|
|
|
private:
|
2021-03-02 02:49:17 +08:00
|
|
|
std::string path;
|
|
|
|
int total_read;
|
|
|
|
int bytes_read;
|
|
|
|
bool on_blocking_abort;
|
|
|
|
FILE *outfile;
|
|
|
|
int raw_fd;
|
2019-05-17 03:37:03 +08:00
|
|
|
|
2019-06-27 22:29:47 +08:00
|
|
|
public:
|
2021-03-02 02:49:17 +08:00
|
|
|
static void file_create_if_missing(
|
|
|
|
const char * path,
|
|
|
|
bool is_fifo,
|
|
|
|
bool delete_fake_fifo = true
|
|
|
|
);
|
|
|
|
|
|
|
|
Fifo() :
|
|
|
|
total_read(0),
|
|
|
|
bytes_read(0),
|
|
|
|
on_blocking_abort(true),
|
|
|
|
outfile(nullptr),
|
|
|
|
raw_fd(-1)
|
|
|
|
{}
|
|
|
|
Fifo(const char *p_path, bool p_on_blocking_abort) :
|
|
|
|
path(p_path),
|
2020-11-02 05:11:19 +08:00
|
|
|
total_read(0),
|
|
|
|
bytes_read(0),
|
2021-03-02 02:49:17 +08:00
|
|
|
on_blocking_abort(p_on_blocking_abort),
|
|
|
|
outfile(nullptr),
|
|
|
|
raw_fd(-1)
|
2020-11-02 05:11:19 +08:00
|
|
|
{}
|
2021-03-02 02:49:17 +08:00
|
|
|
~Fifo();
|
|
|
|
|
2019-06-27 22:29:47 +08:00
|
|
|
static void fifo_create_if_missing(
|
|
|
|
const char * path,
|
|
|
|
bool delete_fake_fifo = true);
|
2021-03-02 02:49:17 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
2021-02-28 01:27:10 +08:00
|
|
|
static bool writePacket(std::string filename, ZMPacket &packet);
|
|
|
|
static bool write(std::string filename, uint8_t *data, size_t size);
|
2021-03-02 02:49:17 +08:00
|
|
|
|
|
|
|
bool open();
|
|
|
|
bool close();
|
|
|
|
|
|
|
|
bool writePacket(ZMPacket &packet);
|
|
|
|
bool write(uint8_t *data, size_t size, int64_t pts);
|
2019-05-17 03:37:03 +08:00
|
|
|
};
|
2019-06-27 22:29:47 +08:00
|
|
|
#endif // ZM_FIFO_H
|