winlin

add utest for kernel codec

@@ -517,7 +517,7 @@ fi @@ -517,7 +517,7 @@ fi
517 # 517 #
518 # utest, the unit-test cases of srs, base on gtest1.6 518 # utest, the unit-test cases of srs, base on gtest1.6
519 MODULE_FILES=("srs_utest" "srs_utest_amf0" "srs_utest_handshake" 519 MODULE_FILES=("srs_utest" "srs_utest_amf0" "srs_utest_handshake"
520 - "srs_utest_buffer" "srs_utest_protocol") 520 + "srs_utest_buffer" "srs_utest_protocol" "srs_utest_kernel")
521 ModuleLibIncs=(${SRS_OBJS} ${LibSTRoot}) 521 ModuleLibIncs=(${SRS_OBJS} ${LibSTRoot})
522 ModuleLibFiles=(${LibSTfile} ${LibHttpParserfile} ${LibSSLfile}) 522 ModuleLibFiles=(${LibSTfile} ${LibHttpParserfile} ${LibSSLfile})
523 MODULE_DEPENDS=("CORE" "KERNEL" "RTMP" "APP") 523 MODULE_DEPENDS=("CORE" "KERNEL" "RTMP" "APP")
@@ -160,7 +160,6 @@ public: @@ -160,7 +160,6 @@ public:
160 * check codec h264. 160 * check codec h264.
161 */ 161 */
162 static bool video_is_h264(int8_t* data, int size); 162 static bool video_is_h264(int8_t* data, int size);
163 -private:  
164 /** 163 /**
165 * check codec aac. 164 * check codec aac.
166 */ 165 */
@@ -116,6 +116,8 @@ file @@ -116,6 +116,8 @@ file
116 ..\utest\srs_utest_buffer.cpp, 116 ..\utest\srs_utest_buffer.cpp,
117 ..\utest\srs_utest_handshake.hpp, 117 ..\utest\srs_utest_handshake.hpp,
118 ..\utest\srs_utest_handshake.cpp, 118 ..\utest\srs_utest_handshake.cpp,
  119 + ..\utest\srs_utest_kernel.hpp,
  120 + ..\utest\srs_utest_kernel.cpp,
119 ..\utest\srs_utest_protocol.hpp, 121 ..\utest\srs_utest_protocol.hpp,
120 ..\utest\srs_utest_protocol.cpp, 122 ..\utest\srs_utest_protocol.cpp,
121 research readonly separator, 123 research readonly separator,
  1 +/*
  2 +The MIT License (MIT)
  3 +
  4 +Copyright (c) 2013-2014 winlin
  5 +
  6 +Permission is hereby granted, free of charge, to any person obtaining a copy of
  7 +this software and associated documentation files (the "Software"), to deal in
  8 +the Software without restriction, including without limitation the rights to
  9 +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
  10 +the Software, and to permit persons to whom the Software is furnished to do so,
  11 +subject to the following conditions:
  12 +
  13 +The above copyright notice and this permission notice shall be included in all
  14 +copies or substantial portions of the Software.
  15 +
  16 +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17 +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
  18 +FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
  19 +COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
  20 +IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  21 +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  22 +*/
  23 +#include <srs_utest_kernel.hpp>
  24 +
  25 +using namespace std;
  26 +
  27 +#include <srs_kernel_error.hpp>
  28 +
  29 +VOID TEST(KernelCodecTest, IsKeyFrame)
  30 +{
  31 + int8_t data;
  32 +
  33 + data = 0x10;
  34 + EXPECT_TRUE(SrsFlvCodec::video_is_keyframe(&data, 1));
  35 + EXPECT_FALSE(SrsFlvCodec::video_is_keyframe(&data, 0));
  36 +
  37 + data = 0x20;
  38 + EXPECT_FALSE(SrsFlvCodec::video_is_keyframe(&data, 1));
  39 +}
  40 +
  41 +VOID TEST(KernelCodecTest, IsH264)
  42 +{
  43 + int8_t data;
  44 +
  45 + EXPECT_FALSE(SrsFlvCodec::video_is_h264(&data, 0));
  46 +
  47 + data = 0x17;
  48 + EXPECT_TRUE(SrsFlvCodec::video_is_h264(&data, 1));
  49 +
  50 + data = 0x07;
  51 + EXPECT_TRUE(SrsFlvCodec::video_is_h264(&data, 1));
  52 +
  53 + data = 0x08;
  54 + EXPECT_FALSE(SrsFlvCodec::video_is_h264(&data, 1));
  55 +}
  56 +
  57 +VOID TEST(KernelCodecTest, IsSequenceHeader)
  58 +{
  59 + int16_t data;
  60 + char* pp = (char*)&data;
  61 +
  62 + EXPECT_FALSE(SrsFlvCodec::video_is_sequence_header((int8_t*)pp, 0));
  63 + EXPECT_FALSE(SrsFlvCodec::video_is_sequence_header((int8_t*)pp, 1));
  64 +
  65 + pp[0] = 0x17;
  66 + pp[1] = 0x00;
  67 + EXPECT_TRUE(SrsFlvCodec::video_is_sequence_header((int8_t*)pp, 2));
  68 + pp[0] = 0x18;
  69 + EXPECT_FALSE(SrsFlvCodec::video_is_sequence_header((int8_t*)pp, 2));
  70 + pp[0] = 0x27;
  71 + EXPECT_FALSE(SrsFlvCodec::video_is_sequence_header((int8_t*)pp, 2));
  72 + pp[0] = 0x17;
  73 + pp[1] = 0x01;
  74 + EXPECT_FALSE(SrsFlvCodec::video_is_sequence_header((int8_t*)pp, 2));
  75 +}
  76 +
  77 +VOID TEST(KernelCodecTest, IsAAC)
  78 +{
  79 + int8_t data;
  80 +
  81 + EXPECT_FALSE(SrsFlvCodec::audio_is_aac(&data, 0));
  82 +
  83 + data = 0xa0;
  84 + EXPECT_TRUE(SrsFlvCodec::audio_is_aac(&data, 1));
  85 +
  86 + data = 0xa7;
  87 + EXPECT_TRUE(SrsFlvCodec::audio_is_aac(&data, 1));
  88 +
  89 + data = 0x00;
  90 + EXPECT_FALSE(SrsFlvCodec::audio_is_aac(&data, 1));
  91 +}
  92 +
  93 +VOID TEST(KernelCodecTest, IsAudioSequenceHeader)
  94 +{
  95 + int16_t data;
  96 + char* pp = (char*)&data;
  97 +
  98 + EXPECT_FALSE(SrsFlvCodec::audio_is_sequence_header((int8_t*)pp, 0));
  99 + EXPECT_FALSE(SrsFlvCodec::audio_is_sequence_header((int8_t*)pp, 1));
  100 +
  101 + pp[0] = 0xa0;
  102 + pp[1] = 0x00;
  103 + EXPECT_TRUE(SrsFlvCodec::audio_is_sequence_header((int8_t*)pp, 2));
  104 + pp[0] = 0x00;
  105 + EXPECT_FALSE(SrsFlvCodec::video_is_sequence_header((int8_t*)pp, 2));
  106 + pp[0] = 0xa0;
  107 + pp[1] = 0x01;
  108 + EXPECT_FALSE(SrsFlvCodec::video_is_sequence_header((int8_t*)pp, 2));
  109 +}
  1 +/*
  2 +The MIT License (MIT)
  3 +
  4 +Copyright (c) 2013-2014 winlin
  5 +
  6 +Permission is hereby granted, free of charge, to any person obtaining a copy of
  7 +this software and associated documentation files (the "Software"), to deal in
  8 +the Software without restriction, including without limitation the rights to
  9 +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
  10 +the Software, and to permit persons to whom the Software is furnished to do so,
  11 +subject to the following conditions:
  12 +
  13 +The above copyright notice and this permission notice shall be included in all
  14 +copies or substantial portions of the Software.
  15 +
  16 +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17 +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
  18 +FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
  19 +COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
  20 +IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  21 +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  22 +*/
  23 +
  24 +#ifndef SRS_UTEST_KERNEL_HPP
  25 +#define SRS_UTEST_KERNEL_HPP
  26 +
  27 +/*
  28 +#include <srs_utest_kernel.hpp>
  29 +*/
  30 +#include <srs_utest.hpp>
  31 +
  32 +#include <string>
  33 +#include <srs_kernel_codec.hpp>
  34 +
  35 +#endif