mirror of
https://github.com/ossrs/srs.git
synced 2025-03-09 15:49:59 +00:00
finish kernel utest. to 0.9.149
This commit is contained in:
parent
ad920915a2
commit
5a41b1b538
9 changed files with 686 additions and 116 deletions
|
@ -87,7 +87,6 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|||
// aggregate message parse failed.
|
||||
#define ERROR_RTMP_AGGREGATE 324
|
||||
|
||||
#define ERROR_SYSTEM_STREAM_INIT 400
|
||||
#define ERROR_SYSTEM_PACKET_INVALID 401
|
||||
#define ERROR_SYSTEM_CLIENT_INVALID 402
|
||||
#define ERROR_SYSTEM_ASSERT_FAILED 403
|
||||
|
@ -190,6 +189,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|||
|
||||
#define ERROR_KERNEL_FLV_HEADER 900
|
||||
#define ERROR_KERNEL_FLV_STREAM_CLOSED 901
|
||||
#define ERROR_KERNEL_STREAM_INIT 902
|
||||
|
||||
// system control message,
|
||||
// not an error, but special control logic.
|
||||
|
|
|
@ -31,8 +31,8 @@ using namespace std;
|
|||
|
||||
SrsStream::SrsStream()
|
||||
{
|
||||
p = bytes = NULL;
|
||||
size = 0;
|
||||
p = _bytes = NULL;
|
||||
_size = 0;
|
||||
|
||||
// TODO: support both little and big endian.
|
||||
srs_assert(srs_is_little_endian());
|
||||
|
@ -42,61 +42,61 @@ SrsStream::~SrsStream()
|
|||
{
|
||||
}
|
||||
|
||||
int SrsStream::initialize(char* _bytes, int _size)
|
||||
int SrsStream::initialize(char* bytes, int size)
|
||||
{
|
||||
int ret = ERROR_SUCCESS;
|
||||
|
||||
if (!_bytes) {
|
||||
ret = ERROR_SYSTEM_STREAM_INIT;
|
||||
if (!bytes) {
|
||||
ret = ERROR_KERNEL_STREAM_INIT;
|
||||
srs_error("stream param bytes must not be NULL. ret=%d", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
if (_size <= 0) {
|
||||
ret = ERROR_SYSTEM_STREAM_INIT;
|
||||
if (size <= 0) {
|
||||
ret = ERROR_KERNEL_STREAM_INIT;
|
||||
srs_error("stream param size must be positive. ret=%d", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
size = _size;
|
||||
p = bytes = _bytes;
|
||||
_size = size;
|
||||
p = _bytes = bytes;
|
||||
srs_info("init stream ok, size=%d", size);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
void SrsStream::reset()
|
||||
char* SrsStream::data()
|
||||
{
|
||||
p = bytes;
|
||||
return _bytes;
|
||||
}
|
||||
|
||||
bool SrsStream::empty()
|
||||
int SrsStream::size()
|
||||
{
|
||||
return !p || !bytes || (p >= bytes + size);
|
||||
}
|
||||
|
||||
bool SrsStream::require(int required_size)
|
||||
{
|
||||
return !empty() && (required_size <= bytes + size - p);
|
||||
}
|
||||
|
||||
void SrsStream::skip(int size)
|
||||
{
|
||||
p += size;
|
||||
return _size;
|
||||
}
|
||||
|
||||
int SrsStream::pos()
|
||||
{
|
||||
return p - bytes;
|
||||
return p - _bytes;
|
||||
}
|
||||
|
||||
int SrsStream::left()
|
||||
bool SrsStream::empty()
|
||||
{
|
||||
return size - pos();
|
||||
return !_bytes || (p >= _bytes + _size);
|
||||
}
|
||||
|
||||
char* SrsStream::current()
|
||||
bool SrsStream::require(int required_size)
|
||||
{
|
||||
return p;
|
||||
srs_assert(required_size > 0);
|
||||
|
||||
return required_size <= _size - (p - _bytes);
|
||||
}
|
||||
|
||||
void SrsStream::skip(int size)
|
||||
{
|
||||
srs_assert(p);
|
||||
|
||||
p += size;
|
||||
}
|
||||
|
||||
int8_t SrsStream::read_1bytes()
|
||||
|
|
|
@ -33,52 +33,67 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|||
#include <sys/types.h>
|
||||
#include <string>
|
||||
|
||||
/**
|
||||
* bytes utility, used to:
|
||||
* convert basic types to bytes,
|
||||
* build basic types from bytes.
|
||||
*/
|
||||
class SrsStream
|
||||
{
|
||||
private:
|
||||
char* p;
|
||||
char* pp;
|
||||
char* bytes;
|
||||
int size;
|
||||
char* _bytes;
|
||||
int _size;
|
||||
public:
|
||||
SrsStream();
|
||||
virtual ~SrsStream();
|
||||
public:
|
||||
/**
|
||||
* initialize the stream from bytes.
|
||||
* @_bytes, must not be NULL, or return error.
|
||||
* @_size, must be positive, or return error.
|
||||
* @remark, stream never free the _bytes, user must free it.
|
||||
* @bytes, the bytes to convert from/to basic types.
|
||||
* @size, the size of bytes.
|
||||
* @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* bytes, int size);
|
||||
// get the status of stream
|
||||
public:
|
||||
/**
|
||||
* reset the position to beginning.
|
||||
* get data of stream, set by initialize.
|
||||
* current bytes = data() + pos()
|
||||
*/
|
||||
virtual void reset();
|
||||
virtual char* data();
|
||||
/**
|
||||
* whether stream is empty.
|
||||
* if empty, never read or write.
|
||||
* the total stream size, set by initialize.
|
||||
* left bytes = size() - pos().
|
||||
*/
|
||||
virtual bool empty();
|
||||
/**
|
||||
* whether required size is ok.
|
||||
* @return true if stream can read/write specified required_size bytes.
|
||||
*/
|
||||
virtual bool require(int required_size);
|
||||
/**
|
||||
* to skip some size.
|
||||
* @size can be any value. positive to forward; nagetive to backward.
|
||||
*/
|
||||
virtual void skip(int size);
|
||||
virtual int size();
|
||||
/**
|
||||
* tell the current pos.
|
||||
*/
|
||||
virtual int pos();
|
||||
/**
|
||||
* left size of bytes.
|
||||
* whether stream is empty.
|
||||
* if empty, user should never read or write.
|
||||
*/
|
||||
virtual int left();
|
||||
virtual char* current();
|
||||
virtual bool empty();
|
||||
/**
|
||||
* whether required size is ok.
|
||||
* @return true if stream can read/write specified required_size bytes.
|
||||
* @remark assert required_size positive.
|
||||
*/
|
||||
virtual bool require(int required_size);
|
||||
// to change stream.
|
||||
public:
|
||||
/**
|
||||
* to skip some size.
|
||||
* @param size can be any value. positive to forward; nagetive to backward.
|
||||
* @remark to skip(pos()) to reset stream.
|
||||
* @remark assert initialized, the data() not NULL.
|
||||
*/
|
||||
virtual void skip(int size);
|
||||
public:
|
||||
/**
|
||||
* get 1bytes char from stream.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue