2014-07-04 23:33:18 +00:00
|
|
|
/*
|
|
|
|
The MIT License (MIT)
|
|
|
|
|
2016-12-16 03:57:25 +00:00
|
|
|
Copyright (c) 2013-2017 SRS(ossrs)
|
2014-07-04 23:33:18 +00:00
|
|
|
|
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
|
|
this software and associated documentation files (the "Software"), to deal in
|
|
|
|
the Software without restriction, including without limitation the rights to
|
|
|
|
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
|
|
|
the Software, and to permit persons to whom the Software is furnished to do so,
|
|
|
|
subject to the following conditions:
|
|
|
|
|
|
|
|
The above copyright notice and this permission notice shall be included in all
|
|
|
|
copies or substantial portions of the Software.
|
|
|
|
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
|
|
|
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
|
|
|
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
|
|
|
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
|
|
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef SRS_KERNEL_FILE_HPP
|
|
|
|
#define SRS_KERNEL_FILE_HPP
|
|
|
|
|
|
|
|
/*
|
|
|
|
#include <srs_kernel_file.hpp>
|
|
|
|
*/
|
|
|
|
#include <srs_core.hpp>
|
|
|
|
|
2017-01-30 11:35:04 +00:00
|
|
|
#include <srs_kernel_io.hpp>
|
|
|
|
|
2014-07-04 23:33:18 +00:00
|
|
|
#include <string>
|
|
|
|
|
2015-11-11 02:37:50 +00:00
|
|
|
// for srs-librtmp, @see https://github.com/ossrs/srs/issues/213
|
2015-05-24 14:43:02 +00:00
|
|
|
#ifndef _WIN32
|
|
|
|
#include <sys/uio.h>
|
|
|
|
#endif
|
|
|
|
|
2014-07-04 23:33:18 +00:00
|
|
|
/**
|
|
|
|
* file writer, to write to file.
|
|
|
|
*/
|
2017-01-30 11:59:59 +00:00
|
|
|
class SrsFileWriter : public ISrsWriter
|
2014-07-04 23:33:18 +00:00
|
|
|
{
|
|
|
|
private:
|
2015-07-28 09:56:50 +00:00
|
|
|
std::string path;
|
2014-07-04 23:33:18 +00:00
|
|
|
int fd;
|
|
|
|
public:
|
|
|
|
SrsFileWriter();
|
|
|
|
virtual ~SrsFileWriter();
|
|
|
|
public:
|
|
|
|
/**
|
2015-07-28 09:56:50 +00:00
|
|
|
* open file writer, in truncate mode.
|
|
|
|
* @param p a string indicates the path of file to open.
|
|
|
|
*/
|
|
|
|
virtual int open(std::string p);
|
2015-02-19 11:50:10 +00:00
|
|
|
/**
|
2015-07-28 09:56:50 +00:00
|
|
|
* open file writer, in append mode.
|
|
|
|
* @param p a string indicates the path of file to open.
|
|
|
|
*/
|
|
|
|
virtual int open_append(std::string p);
|
|
|
|
/**
|
|
|
|
* close current writer.
|
|
|
|
* @remark user can reopen again.
|
|
|
|
*/
|
2014-07-04 23:33:18 +00:00
|
|
|
virtual void close();
|
|
|
|
public:
|
|
|
|
virtual bool is_open();
|
2015-02-21 11:14:05 +00:00
|
|
|
virtual void lseek(int64_t offset);
|
2014-07-04 23:33:18 +00:00
|
|
|
virtual int64_t tellg();
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* write to file.
|
|
|
|
* @param pnwrite the output nb_write, NULL to ignore.
|
|
|
|
*/
|
|
|
|
virtual int write(void* buf, size_t count, ssize_t* pnwrite);
|
2015-05-24 14:43:02 +00:00
|
|
|
/**
|
|
|
|
* for the HTTP FLV, to writev to improve performance.
|
2015-11-11 02:37:50 +00:00
|
|
|
* @see https://github.com/ossrs/srs/issues/405
|
2015-05-24 14:43:02 +00:00
|
|
|
*/
|
2017-01-30 11:35:04 +00:00
|
|
|
virtual int writev(const iovec* iov, int iovcnt, ssize_t* pnwrite);
|
2014-07-04 23:33:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* file reader, to read from file.
|
|
|
|
*/
|
2017-01-30 11:59:59 +00:00
|
|
|
class SrsFileReader : public ISrsReader
|
2014-07-04 23:33:18 +00:00
|
|
|
{
|
|
|
|
private:
|
2015-07-28 09:56:50 +00:00
|
|
|
std::string path;
|
2014-07-04 23:33:18 +00:00
|
|
|
int fd;
|
|
|
|
public:
|
|
|
|
SrsFileReader();
|
|
|
|
virtual ~SrsFileReader();
|
|
|
|
public:
|
|
|
|
/**
|
2015-07-28 09:56:50 +00:00
|
|
|
* open file reader.
|
|
|
|
* @param p a string indicates the path of file to open.
|
|
|
|
*/
|
|
|
|
virtual int open(std::string p);
|
|
|
|
/**
|
|
|
|
* close current reader.
|
|
|
|
* @remark user can reopen again.
|
|
|
|
*/
|
2014-07-04 23:33:18 +00:00
|
|
|
virtual void close();
|
|
|
|
public:
|
2015-03-10 10:07:43 +00:00
|
|
|
// TODO: FIXME: extract interface.
|
2014-07-04 23:33:18 +00:00
|
|
|
virtual bool is_open();
|
|
|
|
virtual int64_t tellg();
|
|
|
|
virtual void skip(int64_t size);
|
|
|
|
virtual int64_t lseek(int64_t offset);
|
|
|
|
virtual int64_t filesize();
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* read from file.
|
|
|
|
* @param pnread the output nb_read, NULL to ignore.
|
|
|
|
*/
|
|
|
|
virtual int read(void* buf, size_t count, ssize_t* pnread);
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|
2014-08-02 14:18:39 +00:00
|
|
|
|