1
0
Fork 0
mirror of https://github.com/ossrs/srs.git synced 2025-03-09 15:49:59 +00:00

refine dvr, append file when dvr file exists. 2.0.122.

This commit is contained in:
winlin 2015-02-19 19:50:10 +08:00
parent 1102c7a58f
commit a984eeecab
10 changed files with 79 additions and 17 deletions

View file

@ -69,6 +69,30 @@ int SrsFileWriter::open(string file)
return ret;
}
int SrsFileWriter::open_append(string file)
{
int ret = ERROR_SUCCESS;
if (fd > 0) {
ret = ERROR_SYSTEM_FILE_ALREADY_OPENED;
srs_error("file %s already opened. ret=%d", _file.c_str(), ret);
return ret;
}
int flags = O_APPEND|O_WRONLY;
mode_t mode = S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH;
if ((fd = ::open(file.c_str(), flags, mode)) < 0) {
ret = ERROR_SYSTEM_FILE_OPENE;
srs_error("open file %s failed. ret=%d", file.c_str(), ret);
return ret;
}
_file = file;
return ret;
}
void SrsFileWriter::close()
{
int ret = ERROR_SUCCESS;

View file

@ -47,6 +47,10 @@ public:
* open file writer, can open then close then open...
*/
virtual int open(std::string file);
/**
* open file writer in append mode.
*/
virtual int open_append(std::string file);
virtual void close();
public:
virtual bool is_open();

View file

@ -230,10 +230,8 @@ int __srs_create_dir_recursively(string dir)
{
int ret = ERROR_SUCCESS;
struct stat st;
// stat current dir, if exists, return error.
if (stat(dir.c_str(), &st) == 0) {
if (srs_path_exists(dir)) {
return ERROR_SYSTEM_DIR_EXISTS;
}
@ -279,6 +277,18 @@ int srs_create_dir_recursively(string dir)
return ret;
}
bool srs_path_exists(std::string path)
{
struct stat st;
// stat current dir, if exists, return error.
if (stat(path.c_str(), &st) == 0) {
return true;
}
return false;
}
bool srs_avc_startswith_annexb(SrsStream* stream, int* pnb_start_code)
{
char* bytes = stream->data() + stream->pos();

View file

@ -64,6 +64,9 @@ extern bool srs_string_ends_with(std::string str, std::string flag);
// create dir recursively
extern int srs_create_dir_recursively(std::string dir);
// whether path exists.
extern bool srs_path_exists(std::string path);
/**
* whether stream starts with the avc NALU in "AnnexB"
* from H.264-AVC-ISO_IEC_14496-10.pdf, page 211.