mirror of
https://github.com/ossrs/srs.git
synced 2025-02-13 03:41:55 +00:00
add utest for kernel codec
This commit is contained in:
parent
492665e166
commit
f5f54e6008
5 changed files with 147 additions and 2 deletions
2
trunk/configure
vendored
2
trunk/configure
vendored
|
@ -517,7 +517,7 @@ fi
|
||||||
#
|
#
|
||||||
# utest, the unit-test cases of srs, base on gtest1.6
|
# utest, the unit-test cases of srs, base on gtest1.6
|
||||||
MODULE_FILES=("srs_utest" "srs_utest_amf0" "srs_utest_handshake"
|
MODULE_FILES=("srs_utest" "srs_utest_amf0" "srs_utest_handshake"
|
||||||
"srs_utest_buffer" "srs_utest_protocol")
|
"srs_utest_buffer" "srs_utest_protocol" "srs_utest_kernel")
|
||||||
ModuleLibIncs=(${SRS_OBJS} ${LibSTRoot})
|
ModuleLibIncs=(${SRS_OBJS} ${LibSTRoot})
|
||||||
ModuleLibFiles=(${LibSTfile} ${LibHttpParserfile} ${LibSSLfile})
|
ModuleLibFiles=(${LibSTfile} ${LibHttpParserfile} ${LibSSLfile})
|
||||||
MODULE_DEPENDS=("CORE" "KERNEL" "RTMP" "APP")
|
MODULE_DEPENDS=("CORE" "KERNEL" "RTMP" "APP")
|
||||||
|
|
|
@ -160,7 +160,6 @@ public:
|
||||||
* check codec h264.
|
* check codec h264.
|
||||||
*/
|
*/
|
||||||
static bool video_is_h264(int8_t* data, int size);
|
static bool video_is_h264(int8_t* data, int size);
|
||||||
private:
|
|
||||||
/**
|
/**
|
||||||
* check codec aac.
|
* check codec aac.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -116,6 +116,8 @@ file
|
||||||
..\utest\srs_utest_buffer.cpp,
|
..\utest\srs_utest_buffer.cpp,
|
||||||
..\utest\srs_utest_handshake.hpp,
|
..\utest\srs_utest_handshake.hpp,
|
||||||
..\utest\srs_utest_handshake.cpp,
|
..\utest\srs_utest_handshake.cpp,
|
||||||
|
..\utest\srs_utest_kernel.hpp,
|
||||||
|
..\utest\srs_utest_kernel.cpp,
|
||||||
..\utest\srs_utest_protocol.hpp,
|
..\utest\srs_utest_protocol.hpp,
|
||||||
..\utest\srs_utest_protocol.cpp,
|
..\utest\srs_utest_protocol.cpp,
|
||||||
research readonly separator,
|
research readonly separator,
|
||||||
|
|
109
trunk/src/utest/srs_utest_kernel.cpp
Normal file
109
trunk/src/utest/srs_utest_kernel.cpp
Normal file
|
@ -0,0 +1,109 @@
|
||||||
|
/*
|
||||||
|
The MIT License (MIT)
|
||||||
|
|
||||||
|
Copyright (c) 2013-2014 winlin
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||||
|
this software and associated documentation files (the "Software"), to deal in
|
||||||
|
the Software without restriction, including without limitation the rights to
|
||||||
|
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||||
|
the Software, and to permit persons to whom the Software is furnished to do so,
|
||||||
|
subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||||
|
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||||
|
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||||
|
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||||
|
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
#include <srs_utest_kernel.hpp>
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
#include <srs_kernel_error.hpp>
|
||||||
|
|
||||||
|
VOID TEST(KernelCodecTest, IsKeyFrame)
|
||||||
|
{
|
||||||
|
int8_t data;
|
||||||
|
|
||||||
|
data = 0x10;
|
||||||
|
EXPECT_TRUE(SrsFlvCodec::video_is_keyframe(&data, 1));
|
||||||
|
EXPECT_FALSE(SrsFlvCodec::video_is_keyframe(&data, 0));
|
||||||
|
|
||||||
|
data = 0x20;
|
||||||
|
EXPECT_FALSE(SrsFlvCodec::video_is_keyframe(&data, 1));
|
||||||
|
}
|
||||||
|
|
||||||
|
VOID TEST(KernelCodecTest, IsH264)
|
||||||
|
{
|
||||||
|
int8_t data;
|
||||||
|
|
||||||
|
EXPECT_FALSE(SrsFlvCodec::video_is_h264(&data, 0));
|
||||||
|
|
||||||
|
data = 0x17;
|
||||||
|
EXPECT_TRUE(SrsFlvCodec::video_is_h264(&data, 1));
|
||||||
|
|
||||||
|
data = 0x07;
|
||||||
|
EXPECT_TRUE(SrsFlvCodec::video_is_h264(&data, 1));
|
||||||
|
|
||||||
|
data = 0x08;
|
||||||
|
EXPECT_FALSE(SrsFlvCodec::video_is_h264(&data, 1));
|
||||||
|
}
|
||||||
|
|
||||||
|
VOID TEST(KernelCodecTest, IsSequenceHeader)
|
||||||
|
{
|
||||||
|
int16_t data;
|
||||||
|
char* pp = (char*)&data;
|
||||||
|
|
||||||
|
EXPECT_FALSE(SrsFlvCodec::video_is_sequence_header((int8_t*)pp, 0));
|
||||||
|
EXPECT_FALSE(SrsFlvCodec::video_is_sequence_header((int8_t*)pp, 1));
|
||||||
|
|
||||||
|
pp[0] = 0x17;
|
||||||
|
pp[1] = 0x00;
|
||||||
|
EXPECT_TRUE(SrsFlvCodec::video_is_sequence_header((int8_t*)pp, 2));
|
||||||
|
pp[0] = 0x18;
|
||||||
|
EXPECT_FALSE(SrsFlvCodec::video_is_sequence_header((int8_t*)pp, 2));
|
||||||
|
pp[0] = 0x27;
|
||||||
|
EXPECT_FALSE(SrsFlvCodec::video_is_sequence_header((int8_t*)pp, 2));
|
||||||
|
pp[0] = 0x17;
|
||||||
|
pp[1] = 0x01;
|
||||||
|
EXPECT_FALSE(SrsFlvCodec::video_is_sequence_header((int8_t*)pp, 2));
|
||||||
|
}
|
||||||
|
|
||||||
|
VOID TEST(KernelCodecTest, IsAAC)
|
||||||
|
{
|
||||||
|
int8_t data;
|
||||||
|
|
||||||
|
EXPECT_FALSE(SrsFlvCodec::audio_is_aac(&data, 0));
|
||||||
|
|
||||||
|
data = 0xa0;
|
||||||
|
EXPECT_TRUE(SrsFlvCodec::audio_is_aac(&data, 1));
|
||||||
|
|
||||||
|
data = 0xa7;
|
||||||
|
EXPECT_TRUE(SrsFlvCodec::audio_is_aac(&data, 1));
|
||||||
|
|
||||||
|
data = 0x00;
|
||||||
|
EXPECT_FALSE(SrsFlvCodec::audio_is_aac(&data, 1));
|
||||||
|
}
|
||||||
|
|
||||||
|
VOID TEST(KernelCodecTest, IsAudioSequenceHeader)
|
||||||
|
{
|
||||||
|
int16_t data;
|
||||||
|
char* pp = (char*)&data;
|
||||||
|
|
||||||
|
EXPECT_FALSE(SrsFlvCodec::audio_is_sequence_header((int8_t*)pp, 0));
|
||||||
|
EXPECT_FALSE(SrsFlvCodec::audio_is_sequence_header((int8_t*)pp, 1));
|
||||||
|
|
||||||
|
pp[0] = 0xa0;
|
||||||
|
pp[1] = 0x00;
|
||||||
|
EXPECT_TRUE(SrsFlvCodec::audio_is_sequence_header((int8_t*)pp, 2));
|
||||||
|
pp[0] = 0x00;
|
||||||
|
EXPECT_FALSE(SrsFlvCodec::video_is_sequence_header((int8_t*)pp, 2));
|
||||||
|
pp[0] = 0xa0;
|
||||||
|
pp[1] = 0x01;
|
||||||
|
EXPECT_FALSE(SrsFlvCodec::video_is_sequence_header((int8_t*)pp, 2));
|
||||||
|
}
|
35
trunk/src/utest/srs_utest_kernel.hpp
Normal file
35
trunk/src/utest/srs_utest_kernel.hpp
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
/*
|
||||||
|
The MIT License (MIT)
|
||||||
|
|
||||||
|
Copyright (c) 2013-2014 winlin
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||||
|
this software and associated documentation files (the "Software"), to deal in
|
||||||
|
the Software without restriction, including without limitation the rights to
|
||||||
|
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||||
|
the Software, and to permit persons to whom the Software is furnished to do so,
|
||||||
|
subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||||
|
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||||
|
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||||
|
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||||
|
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef SRS_UTEST_KERNEL_HPP
|
||||||
|
#define SRS_UTEST_KERNEL_HPP
|
||||||
|
|
||||||
|
/*
|
||||||
|
#include <srs_utest_kernel.hpp>
|
||||||
|
*/
|
||||||
|
#include <srs_utest.hpp>
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
#include <srs_kernel_codec.hpp>
|
||||||
|
|
||||||
|
#endif
|
Loading…
Reference in a new issue