mirror of
https://github.com/ossrs/srs.git
synced 2025-03-09 15:49:59 +00:00
fix #179: dvr support custom filepath by variables. 2.0.87
This commit is contained in:
parent
f89941254a
commit
f881bc43b5
10 changed files with 215 additions and 27 deletions
|
@ -93,6 +93,9 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|||
#define ERROR_SYSTEM_SECURITY 1052
|
||||
#define ERROR_SYSTEM_SECURITY_DENY 1053
|
||||
#define ERROR_SYSTEM_SECURITY_ALLOW 1054
|
||||
#define ERROR_SYSTEM_TIME 1055
|
||||
#define ERROR_SYSTEM_DIR_EXISTS 1056
|
||||
#define ERROR_SYSTEM_CREATE_DIR 1057
|
||||
|
||||
///////////////////////////////////////////////////////
|
||||
// RTMP protocol error.
|
||||
|
@ -152,7 +155,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|||
///////////////////////////////////////////////////////
|
||||
#define ERROR_HLS_METADATA 3000
|
||||
#define ERROR_HLS_DECODE_ERROR 3001
|
||||
#define ERROR_HLS_CREATE_DIR 3002
|
||||
//#define ERROR_HLS_CREATE_DIR 3002
|
||||
#define ERROR_HLS_OPEN_FAILED 3003
|
||||
#define ERROR_HLS_WRITE_FAILED 3004
|
||||
#define ERROR_HLS_AAC_FRAME_LENGTH 3005
|
||||
|
|
|
@ -32,10 +32,13 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|||
#endif
|
||||
|
||||
#include <string.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
#include <srs_kernel_log.hpp>
|
||||
#include <srs_kernel_error.hpp>
|
||||
|
||||
// this value must:
|
||||
// equals to (SRS_SYS_CYCLE_INTERVAL*SRS_SYS_TIME_RESOLUTION_MS_TIMES)*1000
|
||||
|
@ -222,3 +225,56 @@ bool srs_string_ends_with(string str, string flag)
|
|||
return str.rfind(flag) == str.length() - flag.length();
|
||||
}
|
||||
|
||||
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) {
|
||||
return ERROR_SYSTEM_DIR_EXISTS;
|
||||
}
|
||||
|
||||
// create parent first.
|
||||
size_t pos;
|
||||
if ((pos = dir.rfind("/")) != std::string::npos) {
|
||||
std::string parent = dir.substr(0, pos);
|
||||
ret = __srs_create_dir_recursively(parent);
|
||||
// return for error.
|
||||
if (ret != ERROR_SUCCESS && ret != ERROR_SYSTEM_DIR_EXISTS) {
|
||||
return ret;
|
||||
}
|
||||
// parent exists, set to ok.
|
||||
ret = ERROR_SUCCESS;
|
||||
}
|
||||
|
||||
// create curren dir.
|
||||
mode_t mode = S_IRUSR|S_IWUSR|S_IXUSR|S_IRGRP|S_IWGRP|S_IXGRP|S_IROTH|S_IXOTH;
|
||||
if (::mkdir(dir.c_str(), mode) < 0) {
|
||||
if (errno == EEXIST) {
|
||||
return ERROR_SYSTEM_DIR_EXISTS;
|
||||
}
|
||||
|
||||
ret = ERROR_SYSTEM_CREATE_DIR;
|
||||
srs_error("create dir %s failed. ret=%d", dir.c_str(), ret);
|
||||
return ret;
|
||||
}
|
||||
srs_info("create dir %s success.", dir.c_str());
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int srs_create_dir_recursively(string dir)
|
||||
{
|
||||
int ret = ERROR_SUCCESS;
|
||||
|
||||
ret = __srs_create_dir_recursively(dir);
|
||||
|
||||
if (ret == ERROR_SYSTEM_DIR_EXISTS) {
|
||||
return ERROR_SUCCESS;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
|
|
@ -59,5 +59,8 @@ extern std::string srs_string_remove(std::string str, std::string remove_chars);
|
|||
// whether string end with
|
||||
extern bool srs_string_ends_with(std::string str, std::string flag);
|
||||
|
||||
// create dir recursively
|
||||
extern int srs_create_dir_recursively(std::string dir);
|
||||
|
||||
#endif
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue