From f5f54e60082f6c1728a3d7a5a1873d08df04a634 Mon Sep 17 00:00:00 2001 From: winlin Date: Sun, 29 Jun 2014 15:43:32 +0800 Subject: [PATCH] add utest for kernel codec --- trunk/configure | 2 +- trunk/src/kernel/srs_kernel_codec.hpp | 1 - trunk/src/srs/srs.upp | 2 + trunk/src/utest/srs_utest_kernel.cpp | 109 ++++++++++++++++++++++++++ trunk/src/utest/srs_utest_kernel.hpp | 35 +++++++++ 5 files changed, 147 insertions(+), 2 deletions(-) create mode 100644 trunk/src/utest/srs_utest_kernel.cpp create mode 100644 trunk/src/utest/srs_utest_kernel.hpp diff --git a/trunk/configure b/trunk/configure index 069fe97fe..8f83049de 100755 --- a/trunk/configure +++ b/trunk/configure @@ -517,7 +517,7 @@ fi # # utest, the unit-test cases of srs, base on gtest1.6 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}) ModuleLibFiles=(${LibSTfile} ${LibHttpParserfile} ${LibSSLfile}) MODULE_DEPENDS=("CORE" "KERNEL" "RTMP" "APP") diff --git a/trunk/src/kernel/srs_kernel_codec.hpp b/trunk/src/kernel/srs_kernel_codec.hpp index c0a4f4c3e..570133644 100644 --- a/trunk/src/kernel/srs_kernel_codec.hpp +++ b/trunk/src/kernel/srs_kernel_codec.hpp @@ -160,7 +160,6 @@ public: * check codec h264. */ static bool video_is_h264(int8_t* data, int size); -private: /** * check codec aac. */ diff --git a/trunk/src/srs/srs.upp b/trunk/src/srs/srs.upp index ebc1795a4..b8f98d0c1 100755 --- a/trunk/src/srs/srs.upp +++ b/trunk/src/srs/srs.upp @@ -116,6 +116,8 @@ file ..\utest\srs_utest_buffer.cpp, ..\utest\srs_utest_handshake.hpp, ..\utest\srs_utest_handshake.cpp, + ..\utest\srs_utest_kernel.hpp, + ..\utest\srs_utest_kernel.cpp, ..\utest\srs_utest_protocol.hpp, ..\utest\srs_utest_protocol.cpp, research readonly separator, diff --git a/trunk/src/utest/srs_utest_kernel.cpp b/trunk/src/utest/srs_utest_kernel.cpp new file mode 100644 index 000000000..ff46b1d80 --- /dev/null +++ b/trunk/src/utest/srs_utest_kernel.cpp @@ -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 + +using namespace std; + +#include + +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)); +} diff --git a/trunk/src/utest/srs_utest_kernel.hpp b/trunk/src/utest/srs_utest_kernel.hpp new file mode 100644 index 000000000..3e1120472 --- /dev/null +++ b/trunk/src/utest/srs_utest_kernel.hpp @@ -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 +*/ +#include + +#include +#include + +#endif