mirror of
https://github.com/ossrs/srs.git
synced 2025-02-13 03:41:55 +00:00
refine params nameing and SrsStream.
This commit is contained in:
parent
8d86eb6516
commit
bfe0f97edd
7 changed files with 57 additions and 54 deletions
|
@ -252,7 +252,7 @@ int SrsFileReader::read(void* buf, size_t count, ssize_t* pnread)
|
|||
// TODO: FIXME: use st_read.
|
||||
if ((nread = ::read(fd, buf, count)) < 0) {
|
||||
ret = ERROR_SYSTEM_FILE_READ;
|
||||
srs_error("read from file %s failed. ret=%d", _file.c_str(), ret);
|
||||
srs_error("read from file %s failed. ret=%d", path.c_str(), ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
|
|
@ -40,7 +40,7 @@ using namespace std;
|
|||
|
||||
SrsMp3Encoder::SrsMp3Encoder()
|
||||
{
|
||||
_fs = NULL;
|
||||
writer = NULL;
|
||||
tag_stream = new SrsStream();
|
||||
}
|
||||
|
||||
|
@ -49,19 +49,19 @@ SrsMp3Encoder::~SrsMp3Encoder()
|
|||
srs_freep(tag_stream);
|
||||
}
|
||||
|
||||
int SrsMp3Encoder::initialize(SrsFileWriter* fs)
|
||||
int SrsMp3Encoder::initialize(SrsFileWriter* fw)
|
||||
{
|
||||
int ret = ERROR_SUCCESS;
|
||||
|
||||
srs_assert(fs);
|
||||
srs_assert(fw);
|
||||
|
||||
if (!fs->is_open()) {
|
||||
if (!fw->is_open()) {
|
||||
ret = ERROR_KERNEL_MP3_STREAM_CLOSED;
|
||||
srs_warn("stream is not open for encoder. ret=%d", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
_fs = fs;
|
||||
writer = fw;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
@ -78,7 +78,7 @@ int SrsMp3Encoder::write_header()
|
|||
(char)0x00, (char)0x00, (char)0x00, (char)0x00, // FrameSize
|
||||
(char)0x00, (char)0x00 // Flags
|
||||
};
|
||||
return _fs->write(id3, sizeof(id3), NULL);
|
||||
return writer->write(id3, sizeof(id3), NULL);
|
||||
}
|
||||
|
||||
int SrsMp3Encoder::write_audio(int64_t timestamp, char* data, int size)
|
||||
|
@ -122,6 +122,6 @@ int SrsMp3Encoder::write_audio(int64_t timestamp, char* data, int size)
|
|||
return ret;
|
||||
}
|
||||
|
||||
return _fs->write(data + stream->pos(), size - stream->pos(), NULL);
|
||||
return writer->write(data + stream->pos(), size - stream->pos(), NULL);
|
||||
}
|
||||
|
||||
|
|
|
@ -33,7 +33,6 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|||
|
||||
class SrsStream;
|
||||
class SrsFileWriter;
|
||||
class SrsFileReader;
|
||||
|
||||
/**
|
||||
* encode data to aac file.
|
||||
|
@ -41,7 +40,7 @@ class SrsFileReader;
|
|||
class SrsMp3Encoder
|
||||
{
|
||||
private:
|
||||
SrsFileWriter* _fs;
|
||||
SrsFileWriter* writer;
|
||||
private:
|
||||
SrsStream* tag_stream;
|
||||
public:
|
||||
|
@ -51,9 +50,9 @@ public:
|
|||
/**
|
||||
* initialize the underlayer file stream.
|
||||
* @remark user can initialize multiple times to encode multiple mp3 files.
|
||||
* @remark, user must free the fs, mp3 encoder never close/free it.
|
||||
* @remark, user must free the @param fw, mp3 encoder never close/free it.
|
||||
*/
|
||||
virtual int initialize(SrsFileWriter* fs);
|
||||
virtual int initialize(SrsFileWriter* fw);
|
||||
public:
|
||||
/**
|
||||
* write mp3 id3 v2.3 header.
|
||||
|
|
|
@ -31,8 +31,8 @@ using namespace std;
|
|||
|
||||
SrsStream::SrsStream()
|
||||
{
|
||||
p = _bytes = NULL;
|
||||
_size = 0;
|
||||
p = bytes = NULL;
|
||||
nb_bytes = 0;
|
||||
|
||||
// TODO: support both little and big endian.
|
||||
srs_assert(srs_is_little_endian());
|
||||
|
@ -42,24 +42,24 @@ SrsStream::~SrsStream()
|
|||
{
|
||||
}
|
||||
|
||||
int SrsStream::initialize(char* bytes, int size)
|
||||
int SrsStream::initialize(char* b, int nb)
|
||||
{
|
||||
int ret = ERROR_SUCCESS;
|
||||
|
||||
if (!bytes) {
|
||||
if (!b) {
|
||||
ret = ERROR_KERNEL_STREAM_INIT;
|
||||
srs_error("stream param bytes must not be NULL. ret=%d", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
if (size <= 0) {
|
||||
if (nb <= 0) {
|
||||
ret = ERROR_KERNEL_STREAM_INIT;
|
||||
srs_error("stream param size must be positive. ret=%d", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
_size = size;
|
||||
p = _bytes = bytes;
|
||||
nb_bytes = nb;
|
||||
p = bytes = b;
|
||||
srs_info("init stream ok, size=%d", size);
|
||||
|
||||
return ret;
|
||||
|
@ -67,29 +67,29 @@ int SrsStream::initialize(char* bytes, int size)
|
|||
|
||||
char* SrsStream::data()
|
||||
{
|
||||
return _bytes;
|
||||
return bytes;
|
||||
}
|
||||
|
||||
int SrsStream::size()
|
||||
{
|
||||
return _size;
|
||||
return nb_bytes;
|
||||
}
|
||||
|
||||
int SrsStream::pos()
|
||||
{
|
||||
return p - _bytes;
|
||||
return (int)(p - bytes);
|
||||
}
|
||||
|
||||
bool SrsStream::empty()
|
||||
{
|
||||
return !_bytes || (p >= _bytes + _size);
|
||||
return !bytes || (p >= bytes + nb_bytes);
|
||||
}
|
||||
|
||||
bool SrsStream::require(int required_size)
|
||||
{
|
||||
srs_assert(required_size > 0);
|
||||
|
||||
return required_size <= _size - (p - _bytes);
|
||||
return required_size <= nb_bytes - (p - bytes);
|
||||
}
|
||||
|
||||
void SrsStream::skip(int size)
|
||||
|
@ -111,7 +111,7 @@ int16_t SrsStream::read_2bytes()
|
|||
srs_assert(require(2));
|
||||
|
||||
int16_t value;
|
||||
pp = (char*)&value;
|
||||
char* pp = (char*)&value;
|
||||
pp[1] = *p++;
|
||||
pp[0] = *p++;
|
||||
|
||||
|
@ -123,7 +123,7 @@ int32_t SrsStream::read_3bytes()
|
|||
srs_assert(require(3));
|
||||
|
||||
int32_t value = 0x00;
|
||||
pp = (char*)&value;
|
||||
char* pp = (char*)&value;
|
||||
pp[2] = *p++;
|
||||
pp[1] = *p++;
|
||||
pp[0] = *p++;
|
||||
|
@ -136,7 +136,7 @@ int32_t SrsStream::read_4bytes()
|
|||
srs_assert(require(4));
|
||||
|
||||
int32_t value;
|
||||
pp = (char*)&value;
|
||||
char* pp = (char*)&value;
|
||||
pp[3] = *p++;
|
||||
pp[2] = *p++;
|
||||
pp[1] = *p++;
|
||||
|
@ -150,7 +150,7 @@ int64_t SrsStream::read_8bytes()
|
|||
srs_assert(require(8));
|
||||
|
||||
int64_t value;
|
||||
pp = (char*)&value;
|
||||
char* pp = (char*)&value;
|
||||
pp[7] = *p++;
|
||||
pp[6] = *p++;
|
||||
pp[5] = *p++;
|
||||
|
@ -195,7 +195,7 @@ void SrsStream::write_2bytes(int16_t value)
|
|||
{
|
||||
srs_assert(require(2));
|
||||
|
||||
pp = (char*)&value;
|
||||
char* pp = (char*)&value;
|
||||
*p++ = pp[1];
|
||||
*p++ = pp[0];
|
||||
}
|
||||
|
@ -204,7 +204,7 @@ void SrsStream::write_4bytes(int32_t value)
|
|||
{
|
||||
srs_assert(require(4));
|
||||
|
||||
pp = (char*)&value;
|
||||
char* pp = (char*)&value;
|
||||
*p++ = pp[3];
|
||||
*p++ = pp[2];
|
||||
*p++ = pp[1];
|
||||
|
@ -215,7 +215,7 @@ void SrsStream::write_3bytes(int32_t value)
|
|||
{
|
||||
srs_assert(require(3));
|
||||
|
||||
pp = (char*)&value;
|
||||
char* pp = (char*)&value;
|
||||
*p++ = pp[2];
|
||||
*p++ = pp[1];
|
||||
*p++ = pp[0];
|
||||
|
@ -225,7 +225,7 @@ void SrsStream::write_8bytes(int64_t value)
|
|||
{
|
||||
srs_assert(require(8));
|
||||
|
||||
pp = (char*)&value;
|
||||
char* pp = (char*)&value;
|
||||
*p++ = pp[7];
|
||||
*p++ = pp[6];
|
||||
*p++ = pp[5];
|
||||
|
@ -238,7 +238,7 @@ void SrsStream::write_8bytes(int64_t value)
|
|||
|
||||
void SrsStream::write_string(string value)
|
||||
{
|
||||
srs_assert(require(value.length()));
|
||||
srs_assert(require((int)value.length()));
|
||||
|
||||
memcpy(p, value.data(), value.length());
|
||||
p += value.length();
|
||||
|
|
|
@ -41,23 +41,25 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|||
class SrsStream
|
||||
{
|
||||
private:
|
||||
// current position at bytes.
|
||||
char* p;
|
||||
char* pp;
|
||||
char* _bytes;
|
||||
int _size;
|
||||
// the bytes data for stream to read or write.
|
||||
char* bytes;
|
||||
// the total number of bytes.
|
||||
int nb_bytes;
|
||||
public:
|
||||
SrsStream();
|
||||
virtual ~SrsStream();
|
||||
public:
|
||||
/**
|
||||
* initialize the stream from bytes.
|
||||
* @bytes, the bytes to convert from/to basic types.
|
||||
* @size, the size of bytes.
|
||||
* @b, the bytes to convert from/to basic types.
|
||||
* @nb, the size of bytes, total number of bytes for stream.
|
||||
* @remark, stream never free the bytes, user must free it.
|
||||
* @remark, return error when bytes NULL.
|
||||
* @remark, return error when size is not positive.
|
||||
*/
|
||||
virtual int initialize(char* bytes, int size);
|
||||
virtual int initialize(char* b, int nb);
|
||||
// get the status of stream
|
||||
public:
|
||||
/**
|
||||
|
|
|
@ -2697,11 +2697,11 @@ SrsTSMuxer::~SrsTSMuxer()
|
|||
close();
|
||||
}
|
||||
|
||||
int SrsTSMuxer::open(string _path)
|
||||
int SrsTSMuxer::open(string p)
|
||||
{
|
||||
int ret = ERROR_SUCCESS;
|
||||
|
||||
path = _path;
|
||||
path = p;
|
||||
|
||||
close();
|
||||
|
||||
|
@ -3048,7 +3048,7 @@ int SrsTsCache::do_cache_avc(SrsAvcAacCodec* codec, SrsCodecSample* sample)
|
|||
|
||||
SrsTsEncoder::SrsTsEncoder()
|
||||
{
|
||||
_fs = NULL;
|
||||
writer = NULL;
|
||||
codec = new SrsAvcAacCodec();
|
||||
sample = new SrsCodecSample();
|
||||
cache = new SrsTsCache();
|
||||
|
@ -3065,22 +3065,22 @@ SrsTsEncoder::~SrsTsEncoder()
|
|||
srs_freep(context);
|
||||
}
|
||||
|
||||
int SrsTsEncoder::initialize(SrsFileWriter* fs)
|
||||
int SrsTsEncoder::initialize(SrsFileWriter* fw)
|
||||
{
|
||||
int ret = ERROR_SUCCESS;
|
||||
|
||||
srs_assert(fs);
|
||||
srs_assert(fw);
|
||||
|
||||
if (!fs->is_open()) {
|
||||
if (!fw->is_open()) {
|
||||
ret = ERROR_KERNEL_FLV_STREAM_CLOSED;
|
||||
srs_warn("stream is not open for encoder. ret=%d", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
_fs = fs;
|
||||
writer = fw;
|
||||
|
||||
srs_freep(muxer);
|
||||
muxer = new SrsTSMuxer(fs, context, SrsCodecAudioAAC, SrsCodecVideoAVC);
|
||||
muxer = new SrsTSMuxer(fw, context, SrsCodecAudioAAC, SrsCodecVideoAVC);
|
||||
|
||||
if ((ret = muxer->open("")) != ERROR_SUCCESS) {
|
||||
return ret;
|
||||
|
|
|
@ -1561,8 +1561,9 @@ public:
|
|||
public:
|
||||
/**
|
||||
* open the writer, donot write the PSI of ts.
|
||||
* @param p a string indicates the path of ts file to mux to.
|
||||
*/
|
||||
virtual int open(std::string _path);
|
||||
virtual int open(std::string p);
|
||||
/**
|
||||
* when open ts, we donot write the header(PSI),
|
||||
* for user may need to update the acodec to mp3 or others,
|
||||
|
@ -1625,7 +1626,7 @@ private:
|
|||
class SrsTsEncoder
|
||||
{
|
||||
private:
|
||||
SrsFileWriter* _fs;
|
||||
SrsFileWriter* writer;
|
||||
private:
|
||||
SrsAvcAacCodec* codec;
|
||||
SrsCodecSample* sample;
|
||||
|
@ -1638,8 +1639,9 @@ public:
|
|||
public:
|
||||
/**
|
||||
* initialize the underlayer file stream.
|
||||
* @param fw the writer to use for ts encoder, user must free it.
|
||||
*/
|
||||
virtual int initialize(SrsFileWriter* fs);
|
||||
virtual int initialize(SrsFileWriter* fw);
|
||||
public:
|
||||
/**
|
||||
* write audio/video packet.
|
||||
|
|
Loading…
Reference in a new issue