2021-05-31 05:42:20 +00:00
|
|
|
//
|
2021-07-08 06:30:47 +00:00
|
|
|
// Copyright (c) 2013-2021 The SRS Authors
|
2021-05-31 05:42:20 +00:00
|
|
|
//
|
|
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
//
|
2017-01-30 11:35:04 +00:00
|
|
|
|
|
|
|
#ifndef SRS_KERNEL_IO_HPP
|
|
|
|
#define SRS_KERNEL_IO_HPP
|
|
|
|
|
|
|
|
#include <srs_core.hpp>
|
|
|
|
|
|
|
|
// for srs-librtmp, @see https://github.com/ossrs/srs/issues/213
|
|
|
|
#ifndef _WIN32
|
|
|
|
#include <sys/uio.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/**
|
2017-01-30 11:59:59 +00:00
|
|
|
* The reader to read data from channel.
|
2017-01-30 11:35:04 +00:00
|
|
|
*/
|
2017-01-30 11:59:59 +00:00
|
|
|
class ISrsReader
|
2017-01-30 11:35:04 +00:00
|
|
|
{
|
|
|
|
public:
|
2017-01-30 11:59:59 +00:00
|
|
|
ISrsReader();
|
|
|
|
virtual ~ISrsReader();
|
2017-01-30 11:35:04 +00:00
|
|
|
public:
|
2017-02-01 13:57:32 +00:00
|
|
|
/**
|
|
|
|
* Read bytes from reader.
|
|
|
|
* @param nread How many bytes read from channel. NULL to ignore.
|
|
|
|
*/
|
2017-12-31 04:11:48 +00:00
|
|
|
virtual srs_error_t read(void* buf, size_t size, ssize_t* nread) = 0;
|
2017-01-30 11:35:04 +00:00
|
|
|
};
|
|
|
|
|
2017-02-03 14:49:19 +00:00
|
|
|
/**
|
|
|
|
* The seeker to seek with a device.
|
|
|
|
*/
|
|
|
|
class ISrsSeeker
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
ISrsSeeker();
|
|
|
|
virtual ~ISrsSeeker();
|
|
|
|
public:
|
|
|
|
/**
|
2017-03-25 09:21:39 +00:00
|
|
|
* The lseek() function repositions the offset of the file descriptor fildes to the argument offset, according to the
|
2017-02-03 14:49:19 +00:00
|
|
|
* directive whence. lseek() repositions the file pointer fildes as follows:
|
|
|
|
* If whence is SEEK_SET, the offset is set to offset bytes.
|
|
|
|
* If whence is SEEK_CUR, the offset is set to its current location plus offset bytes.
|
|
|
|
* If whence is SEEK_END, the offset is set to the size of the file plus offset bytes.
|
|
|
|
* @param seeked Upon successful completion, lseek() returns the resulting offset location as measured in bytes from
|
|
|
|
* the beginning of the file. NULL to ignore.
|
|
|
|
*/
|
2017-12-31 04:11:48 +00:00
|
|
|
virtual srs_error_t lseek(off_t offset, int whence, off_t* seeked) = 0;
|
2017-02-03 14:49:19 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The reader and seeker.
|
|
|
|
*/
|
2021-05-14 10:17:42 +00:00
|
|
|
class ISrsReadSeeker : public ISrsReader, public ISrsSeeker
|
2017-02-03 14:49:19 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
ISrsReadSeeker();
|
|
|
|
virtual ~ISrsReadSeeker();
|
|
|
|
};
|
|
|
|
|
2017-01-30 11:35:04 +00:00
|
|
|
/**
|
2017-01-30 11:59:59 +00:00
|
|
|
* The writer to write stream data to channel.
|
2017-01-30 11:35:04 +00:00
|
|
|
*/
|
2017-01-30 11:59:59 +00:00
|
|
|
class ISrsStreamWriter
|
2017-01-30 11:35:04 +00:00
|
|
|
{
|
|
|
|
public:
|
2017-01-30 11:59:59 +00:00
|
|
|
ISrsStreamWriter();
|
|
|
|
virtual ~ISrsStreamWriter();
|
2017-01-30 11:35:04 +00:00
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* write bytes over writer.
|
|
|
|
* @nwrite the actual written bytes. NULL to ignore.
|
|
|
|
*/
|
2017-12-31 04:11:48 +00:00
|
|
|
virtual srs_error_t write(void* buf, size_t size, ssize_t* nwrite) = 0;
|
2017-01-30 11:59:59 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The vector writer to write vector(iovc) to channel.
|
|
|
|
*/
|
|
|
|
class ISrsVectorWriter
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
ISrsVectorWriter();
|
|
|
|
virtual ~ISrsVectorWriter();
|
|
|
|
public:
|
2017-01-30 11:35:04 +00:00
|
|
|
/**
|
|
|
|
* write iov over writer.
|
|
|
|
* @nwrite the actual written bytes. NULL to ignore.
|
2017-02-03 14:49:19 +00:00
|
|
|
* @remark for the HTTP FLV, to writev to improve performance.
|
|
|
|
* @see https://github.com/ossrs/srs/issues/405
|
2017-01-30 11:35:04 +00:00
|
|
|
*/
|
2017-12-31 04:11:48 +00:00
|
|
|
virtual srs_error_t writev(const iovec *iov, int iov_size, ssize_t* nwrite) = 0;
|
2017-01-30 11:35:04 +00:00
|
|
|
};
|
|
|
|
|
2017-01-30 11:59:59 +00:00
|
|
|
/**
|
|
|
|
* The generally writer, stream and vector writer.
|
|
|
|
*/
|
2021-05-14 10:17:42 +00:00
|
|
|
class ISrsWriter : public ISrsStreamWriter, public ISrsVectorWriter
|
2017-01-30 11:59:59 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
ISrsWriter();
|
|
|
|
virtual ~ISrsWriter();
|
|
|
|
};
|
|
|
|
|
2017-02-03 14:49:19 +00:00
|
|
|
/**
|
|
|
|
* The writer and seeker.
|
|
|
|
*/
|
2021-05-14 10:17:42 +00:00
|
|
|
class ISrsWriteSeeker : public ISrsWriter, public ISrsSeeker
|
2017-02-03 14:49:19 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
ISrsWriteSeeker();
|
|
|
|
virtual ~ISrsWriteSeeker();
|
|
|
|
};
|
|
|
|
|
2017-01-30 11:35:04 +00:00
|
|
|
#endif
|
|
|
|
|