refine code naming or comments.

pull/499/head
winlin 10 years ago
parent 3d5fbc7a61
commit 8d86eb6516

@ -51,8 +51,8 @@ public:
/**
* auto delete the ptr.
*/
impl__SrsAutoFree(T** _ptr) {
ptr = _ptr;
impl__SrsAutoFree(T** p) {
ptr = p;
}
virtual ~impl__SrsAutoFree() {

@ -46,50 +46,50 @@ SrsFileWriter::~SrsFileWriter()
close();
}
int SrsFileWriter::open(string file)
int SrsFileWriter::open(string p)
{
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);
srs_error("file %s already opened. ret=%d", path.c_str(), ret);
return ret;
}
int flags = O_CREAT|O_WRONLY|O_TRUNC;
mode_t mode = S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH;
if ((fd = ::open(file.c_str(), flags, mode)) < 0) {
if ((fd = ::open(p.c_str(), flags, mode)) < 0) {
ret = ERROR_SYSTEM_FILE_OPENE;
srs_error("open file %s failed. ret=%d", file.c_str(), ret);
srs_error("open file %s failed. ret=%d", p.c_str(), ret);
return ret;
}
_file = file;
path = p;
return ret;
}
int SrsFileWriter::open_append(string file)
int SrsFileWriter::open_append(string p)
{
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);
srs_error("file %s already opened. ret=%d", path.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) {
if ((fd = ::open(p.c_str(), flags, mode)) < 0) {
ret = ERROR_SYSTEM_FILE_OPENE;
srs_error("open file %s failed. ret=%d", file.c_str(), ret);
srs_error("open file %s failed. ret=%d", p.c_str(), ret);
return ret;
}
_file = file;
path = p;
return ret;
}
@ -104,7 +104,7 @@ void SrsFileWriter::close()
if (::close(fd) < 0) {
ret = ERROR_SYSTEM_FILE_CLOSE;
srs_error("close file %s failed. ret=%d", _file.c_str(), ret);
srs_error("close file %s failed. ret=%d", path.c_str(), ret);
return;
}
fd = -1;
@ -135,7 +135,7 @@ int SrsFileWriter::write(void* buf, size_t count, ssize_t* pnwrite)
// TODO: FIXME: use st_write.
if ((nwrite = ::write(fd, buf, count)) < 0) {
ret = ERROR_SYSTEM_FILE_WRITE;
srs_error("write to file %s failed. ret=%d", _file.c_str(), ret);
srs_error("write to file %s failed. ret=%d", path.c_str(), ret);
return ret;
}
@ -177,23 +177,23 @@ SrsFileReader::~SrsFileReader()
close();
}
int SrsFileReader::open(string file)
int SrsFileReader::open(string p)
{
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);
srs_error("file %s already opened. ret=%d", path.c_str(), ret);
return ret;
}
if ((fd = ::open(file.c_str(), O_RDONLY)) < 0) {
if ((fd = ::open(p.c_str(), O_RDONLY)) < 0) {
ret = ERROR_SYSTEM_FILE_OPENE;
srs_error("open file %s failed. ret=%d", file.c_str(), ret);
srs_error("open file %s failed. ret=%d", p.c_str(), ret);
return ret;
}
_file = file;
path = p;
return ret;
}
@ -208,7 +208,7 @@ void SrsFileReader::close()
if (::close(fd) < 0) {
ret = ERROR_SYSTEM_FILE_CLOSE;
srs_error("close file %s failed. ret=%d", _file.c_str(), ret);
srs_error("close file %s failed. ret=%d", path.c_str(), ret);
return;
}
fd = -1;

@ -42,20 +42,26 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
class SrsFileWriter
{
private:
std::string _file;
std::string path;
int fd;
public:
SrsFileWriter();
virtual ~SrsFileWriter();
public:
/**
* open file writer, can open then close then open...
*/
virtual int open(std::string file);
* open file writer, in truncate mode.
* @param p a string indicates the path of file to open.
*/
virtual int open(std::string p);
/**
* open file writer in append mode.
*/
virtual int open_append(std::string file);
* 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.
*/
virtual void close();
public:
virtual bool is_open();
@ -80,16 +86,21 @@ public:
class SrsFileReader
{
private:
std::string _file;
std::string path;
int fd;
public:
SrsFileReader();
virtual ~SrsFileReader();
public:
/**
* open file reader, can open then close then open...
*/
virtual int open(std::string file);
* 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.
*/
virtual void close();
public:
// TODO: FIXME: extract interface.

@ -332,7 +332,7 @@ SrsSharedPtrMessage* SrsSharedPtrMessage::copy()
SrsFlvEncoder::SrsFlvEncoder()
{
_fs = NULL;
reader = NULL;
tag_stream = new SrsStream();
#ifdef SRS_PERF_FAST_FLV_ENCODER
@ -356,19 +356,19 @@ SrsFlvEncoder::~SrsFlvEncoder()
#endif
}
int SrsFlvEncoder::initialize(SrsFileWriter* fs)
int SrsFlvEncoder::initialize(SrsFileWriter* fr)
{
int ret = ERROR_SUCCESS;
srs_assert(fs);
srs_assert(fr);
if (!fs->is_open()) {
if (!fr->is_open()) {
ret = ERROR_KERNEL_FLV_STREAM_CLOSED;
srs_warn("stream is not open for encoder. ret=%d", ret);
return ret;
}
_fs = fs;
reader = fr;
return ret;
}
@ -402,14 +402,14 @@ int SrsFlvEncoder::write_header(char flv_header[9])
int ret = ERROR_SUCCESS;
// write data.
if ((ret = _fs->write(flv_header, 9, NULL)) != ERROR_SUCCESS) {
if ((ret = reader->write(flv_header, 9, NULL)) != ERROR_SUCCESS) {
srs_error("write flv header failed. ret=%d", ret);
return ret;
}
// previous tag size.
char pts[] = { (char)0x00, (char)0x00, (char)0x00, (char)0x00 };
if ((ret = _fs->write(pts, 4, NULL)) != ERROR_SUCCESS) {
if ((ret = reader->write(pts, 4, NULL)) != ERROR_SUCCESS) {
return ret;
}
@ -552,7 +552,7 @@ int SrsFlvEncoder::write_tags(SrsSharedPtrMessage** msgs, int count)
iovs += 3;
}
if ((ret = _fs->writev(iovss, nb_iovss, NULL)) != ERROR_SUCCESS) {
if ((ret = reader->writev(iovss, nb_iovss, NULL)) != ERROR_SUCCESS) {
if (!srs_is_client_gracefully_close(ret)) {
srs_error("write flv tags failed. ret=%d", ret);
}
@ -683,7 +683,7 @@ int SrsFlvEncoder::write_tag(char* header, int header_size, char* tag, int tag_s
iovs[2].iov_base = pre_size;
iovs[2].iov_len = SRS_FLV_PREVIOUS_TAG_SIZE;
if ((ret = _fs->writev(iovs, 3, NULL)) != ERROR_SUCCESS) {
if ((ret = reader->writev(iovs, 3, NULL)) != ERROR_SUCCESS) {
if (!srs_is_client_gracefully_close(ret)) {
srs_error("write flv tag failed. ret=%d", ret);
}
@ -695,7 +695,7 @@ int SrsFlvEncoder::write_tag(char* header, int header_size, char* tag, int tag_s
SrsFlvDecoder::SrsFlvDecoder()
{
_fs = NULL;
reader = NULL;
tag_stream = new SrsStream();
}
@ -704,19 +704,19 @@ SrsFlvDecoder::~SrsFlvDecoder()
srs_freep(tag_stream);
}
int SrsFlvDecoder::initialize(SrsFileReader* fs)
int SrsFlvDecoder::initialize(SrsFileReader* fr)
{
int ret = ERROR_SUCCESS;
srs_assert(fs);
srs_assert(fr);
if (!fs->is_open()) {
if (!fr->is_open()) {
ret = ERROR_KERNEL_FLV_STREAM_CLOSED;
srs_warn("stream is not open for decoder. ret=%d", ret);
return ret;
}
_fs = fs;
reader = fr;
return ret;
}
@ -727,7 +727,7 @@ int SrsFlvDecoder::read_header(char header[9])
srs_assert(header);
if ((ret = _fs->read(header, 9, NULL)) != ERROR_SUCCESS) {
if ((ret = reader->read(header, 9, NULL)) != ERROR_SUCCESS) {
return ret;
}
@ -752,7 +752,7 @@ int SrsFlvDecoder::read_tag_header(char* ptype, int32_t* pdata_size, u_int32_t*
char th[11]; // tag header
// read tag header
if ((ret = _fs->read(th, 11, NULL)) != ERROR_SUCCESS) {
if ((ret = reader->read(th, 11, NULL)) != ERROR_SUCCESS) {
if (ret != ERROR_SYSTEM_FILE_EOF) {
srs_error("read flv tag header failed. ret=%d", ret);
}
@ -789,7 +789,7 @@ int SrsFlvDecoder::read_tag_data(char* data, int32_t size)
srs_assert(data);
if ((ret = _fs->read(data, size, NULL)) != ERROR_SUCCESS) {
if ((ret = reader->read(data, size, NULL)) != ERROR_SUCCESS) {
if (ret != ERROR_SYSTEM_FILE_EOF) {
srs_error("read flv tag header failed. ret=%d", ret);
}
@ -807,7 +807,7 @@ int SrsFlvDecoder::read_previous_tag_size(char previous_tag_size[4])
srs_assert(previous_tag_size);
// ignore 4bytes tag size.
if ((ret = _fs->read(previous_tag_size, 4, NULL)) != ERROR_SUCCESS) {
if ((ret = reader->read(previous_tag_size, 4, NULL)) != ERROR_SUCCESS) {
if (ret != ERROR_SYSTEM_FILE_EOF) {
srs_error("read flv previous tag size failed. ret=%d", ret);
}
@ -819,7 +819,7 @@ int SrsFlvDecoder::read_previous_tag_size(char previous_tag_size[4])
SrsFlvVodStreamDecoder::SrsFlvVodStreamDecoder()
{
_fs = NULL;
reader = NULL;
tag_stream = new SrsStream();
}
@ -828,19 +828,19 @@ SrsFlvVodStreamDecoder::~SrsFlvVodStreamDecoder()
srs_freep(tag_stream);
}
int SrsFlvVodStreamDecoder::initialize(SrsFileReader* fs)
int SrsFlvVodStreamDecoder::initialize(SrsFileReader* fr)
{
int ret = ERROR_SUCCESS;
srs_assert(fs);
srs_assert(fr);
if (!fs->is_open()) {
if (!fr->is_open()) {
ret = ERROR_KERNEL_FLV_STREAM_CLOSED;
srs_warn("stream is not open for decoder. ret=%d", ret);
return ret;
}
_fs = fs;
reader = fr;
return ret;
}
@ -857,7 +857,7 @@ int SrsFlvVodStreamDecoder::read_header_ext(char header[13])
// 9bytes header and 4bytes first previous-tag-size
int size = 13;
if ((ret = _fs->read(header, size, NULL)) != ERROR_SUCCESS) {
if ((ret = reader->read(header, size, NULL)) != ERROR_SUCCESS) {
return ret;
}
@ -891,7 +891,7 @@ int SrsFlvVodStreamDecoder::read_sequence_header_summary(int64_t* pstart, int* p
int64_t av_sequence_offset_start = -1;
int64_t av_sequence_offset_end = -1;
for (;;) {
if ((ret = _fs->read(tag_header, SRS_FLV_TAG_HEADER_SIZE, NULL)) != ERROR_SUCCESS) {
if ((ret = reader->read(tag_header, SRS_FLV_TAG_HEADER_SIZE, NULL)) != ERROR_SUCCESS) {
return ret;
}
@ -907,7 +907,7 @@ int SrsFlvVodStreamDecoder::read_sequence_header_summary(int64_t* pstart, int* p
bool is_not_av = !is_video && !is_audio;
if (is_not_av) {
// skip body and tag size.
_fs->skip(data_size + SRS_FLV_PREVIOUS_TAG_SIZE);
reader->skip(data_size + SRS_FLV_PREVIOUS_TAG_SIZE);
continue;
}
@ -926,10 +926,10 @@ int SrsFlvVodStreamDecoder::read_sequence_header_summary(int64_t* pstart, int* p
got_video = true;
if (av_sequence_offset_start < 0) {
av_sequence_offset_start = _fs->tellg() - SRS_FLV_TAG_HEADER_SIZE;
av_sequence_offset_start = reader->tellg() - SRS_FLV_TAG_HEADER_SIZE;
}
av_sequence_offset_end = _fs->tellg() + data_size + SRS_FLV_PREVIOUS_TAG_SIZE;
_fs->skip(data_size + SRS_FLV_PREVIOUS_TAG_SIZE);
av_sequence_offset_end = reader->tellg() + data_size + SRS_FLV_PREVIOUS_TAG_SIZE;
reader->skip(data_size + SRS_FLV_PREVIOUS_TAG_SIZE);
}
// audio
@ -938,16 +938,16 @@ int SrsFlvVodStreamDecoder::read_sequence_header_summary(int64_t* pstart, int* p
got_audio = true;
if (av_sequence_offset_start < 0) {
av_sequence_offset_start = _fs->tellg() - SRS_FLV_TAG_HEADER_SIZE;
av_sequence_offset_start = reader->tellg() - SRS_FLV_TAG_HEADER_SIZE;
}
av_sequence_offset_end = _fs->tellg() + data_size + SRS_FLV_PREVIOUS_TAG_SIZE;
_fs->skip(data_size + SRS_FLV_PREVIOUS_TAG_SIZE);
av_sequence_offset_end = reader->tellg() + data_size + SRS_FLV_PREVIOUS_TAG_SIZE;
reader->skip(data_size + SRS_FLV_PREVIOUS_TAG_SIZE);
}
}
// seek to the sequence header start offset.
if (av_sequence_offset_start > 0) {
_fs->lseek(av_sequence_offset_start);
reader->lseek(av_sequence_offset_start);
*pstart = av_sequence_offset_start;
*psize = (int)(av_sequence_offset_end - av_sequence_offset_start);
}
@ -959,19 +959,19 @@ int SrsFlvVodStreamDecoder::lseek(int64_t offset)
{
int ret = ERROR_SUCCESS;
if (offset >= _fs->filesize()) {
if (offset >= reader->filesize()) {
ret = ERROR_SYSTEM_FILE_EOF;
srs_warn("flv fast decoder seek overflow file, "
"size=%"PRId64", offset=%"PRId64", ret=%d",
_fs->filesize(), offset, ret);
reader->filesize(), offset, ret);
return ret;
}
if (_fs->lseek(offset) < 0) {
if (reader->lseek(offset) < 0) {
ret = ERROR_SYSTEM_FILE_SEEK;
srs_warn("flv fast decoder seek error, "
"size=%"PRId64", offset=%"PRId64", ret=%d",
_fs->filesize(), offset, ret);
reader->filesize(), offset, ret);
return ret;
}

@ -434,7 +434,7 @@ public:
class SrsFlvEncoder
{
private:
SrsFileWriter* _fs;
SrsFileWriter* reader;
private:
SrsStream* tag_stream;
char tag_header[SRS_FLV_TAG_HEADER_SIZE];
@ -445,9 +445,9 @@ public:
/**
* initialize the underlayer file stream.
* @remark user can initialize multiple times to encode multiple flv files.
* @remark, user must free the fs, flv encoder never close/free it.
* @remark, user must free the @param fr, flv encoder never close/free it.
*/
virtual int initialize(SrsFileWriter* fs);
virtual int initialize(SrsFileWriter* fr);
public:
/**
* write flv header.
@ -512,7 +512,7 @@ private:
class SrsFlvDecoder
{
private:
SrsFileReader* _fs;
SrsFileReader* reader;
private:
SrsStream* tag_stream;
public:
@ -522,9 +522,9 @@ public:
/**
* initialize the underlayer file stream
* @remark user can initialize multiple times to decode multiple flv files.
* @remark, user must free the fs, flv decoder never close/free it.
* @remark user must free the @param fr, flv decoder never close/free it.
*/
virtual int initialize(SrsFileReader* fs);
virtual int initialize(SrsFileReader* fr);
public:
/**
* read the flv header, donot including the 4bytes previous tag size.
@ -556,7 +556,7 @@ public:
class SrsFlvVodStreamDecoder
{
private:
SrsFileReader* _fs;
SrsFileReader* reader;
private:
SrsStream* tag_stream;
public:
@ -566,9 +566,9 @@ public:
/**
* initialize the underlayer file stream
* @remark user can initialize multiple times to decode multiple flv files.
* @remark, user must free the fs, flv decoder never close/free it.
* @remark user must free the @param fr, flv decoder never close/free it.
*/
virtual int initialize(SrsFileReader* fs);
virtual int initialize(SrsFileReader* fr);
public:
/**
* read the flv header and its size.

Loading…
Cancel
Save