From 9bec823f22dad07e2ba13543947807a7ed9bb8a8 Mon Sep 17 00:00:00 2001 From: paxc Date: Sun, 12 Jan 2020 13:44:48 +0400 Subject: [PATCH] [mod_openh264] Fix stap-a size issue and add unit test. --- src/mod/codecs/mod_openh264/Makefile.am | 13 ++ src/mod/codecs/mod_openh264/mod_openh264.cpp | 10 +- .../mod_openh264/test/conf/freeswitch.xml | 38 +++ .../mod_openh264/test/data/case1.packet1.264 | 1 + .../mod_openh264/test/data/case1.packet2.264 | 1 + .../mod_openh264/test/data/case1.packet3.264 | Bin 0 -> 1826 bytes .../mod_openh264/test/data/case1.packet4.264 | Bin 0 -> 2323 bytes .../mod_openh264/test/data/case1.packet5.264 | Bin 0 -> 89 bytes .../mod_openh264/test/data/case2.packet1.264 | 1 + .../mod_openh264/test/data/case2.packet2.264 | 1 + .../mod_openh264/test/data/case2.packet3.264 | Bin 0 -> 4156 bytes .../mod_openh264/test/data/case2.packet4.264 | Bin 0 -> 89 bytes .../mod_openh264/test/test_mod_openh264.cpp | 220 ++++++++++++++++++ 13 files changed, 280 insertions(+), 5 deletions(-) create mode 100644 src/mod/codecs/mod_openh264/test/conf/freeswitch.xml create mode 100755 src/mod/codecs/mod_openh264/test/data/case1.packet1.264 create mode 100755 src/mod/codecs/mod_openh264/test/data/case1.packet2.264 create mode 100755 src/mod/codecs/mod_openh264/test/data/case1.packet3.264 create mode 100755 src/mod/codecs/mod_openh264/test/data/case1.packet4.264 create mode 100755 src/mod/codecs/mod_openh264/test/data/case1.packet5.264 create mode 100755 src/mod/codecs/mod_openh264/test/data/case2.packet1.264 create mode 100755 src/mod/codecs/mod_openh264/test/data/case2.packet2.264 create mode 100755 src/mod/codecs/mod_openh264/test/data/case2.packet3.264 create mode 100755 src/mod/codecs/mod_openh264/test/data/case2.packet4.264 create mode 100644 src/mod/codecs/mod_openh264/test/test_mod_openh264.cpp diff --git a/src/mod/codecs/mod_openh264/Makefile.am b/src/mod/codecs/mod_openh264/Makefile.am index c541e9563f..c9f6c743d7 100644 --- a/src/mod/codecs/mod_openh264/Makefile.am +++ b/src/mod/codecs/mod_openh264/Makefile.am @@ -8,3 +8,16 @@ mod_openh264_la_SOURCES = mod_openh264.cpp mod_openh264_la_CXXFLAGS = $(AM_CXXFLAGS) -I$(OPENH264_DIR)/include/wels mod_openh264_la_LIBADD = $(switch_builddir)/libfreeswitch.la mod_openh264_la_LDFLAGS = -L$(OPENH264_DIR)/lib/ -lopenh264 -avoid-version -module -no-undefined -shared + +noinst_LTLIBRARIES = libmodopenh264.la + +libmodopenh264_la_SOURCES = $(mod_openh264_la_SOURCES) +libmodopenh264_la_CXXFLAGS = $(AM_CXXFLAGS) -I$(OPENH264_DIR)/include/wels + +noinst_PROGRAMS = test/test_mod_openh264 +test_test_mod_openh264_SOURCES = test/test_mod_openh264.cpp +test_test_mod_openh264_CXXFLAGS = $(AM_CXXFLAGS) -I. +test_test_mod_openh264_LDFLAGS = -L$(OPENH264_DIR)/lib/ -lopenh264 -avoid-version -module +test_test_mod_openh264_LDADD = libmodopenh264.la $(switch_builddir)/libfreeswitch.la + +TESTS = $(noinst_PROGRAMS) diff --git a/src/mod/codecs/mod_openh264/mod_openh264.cpp b/src/mod/codecs/mod_openh264/mod_openh264.cpp index 841e9efcd7..8770a71818 100644 --- a/src/mod/codecs/mod_openh264/mod_openh264.cpp +++ b/src/mod/codecs/mod_openh264/mod_openh264.cpp @@ -243,8 +243,8 @@ static switch_size_t buffer_h264_nalu(h264_codec_context_t *context, switch_fram if (start) { //uint8_t nalu_idc = (nalu_hdr & 0x60) >> 5; nalu_type |= (nalu_idc << 5); - size = switch_buffer_write(buffer, sync_bytes, sizeof(sync_bytes)); - size = switch_buffer_write(buffer, &nalu_type, 1); + switch_buffer_write(buffer, sync_bytes, sizeof(sync_bytes)); + switch_buffer_write(buffer, &nalu_type, 1); context->nalu_28_start = 1; } @@ -273,14 +273,14 @@ static switch_size_t buffer_h264_nalu(h264_codec_context_t *context, switch_fram if (context->got_sps <= 0 && nalu_type == 7) context->got_sps = 1; - size += switch_buffer_write(buffer, sync_bytes, sizeof(sync_bytes)); - size += switch_buffer_write(buffer, (void *)data, nalu_size); + switch_buffer_write(buffer, sync_bytes, sizeof(sync_bytes)); + size = switch_buffer_write(buffer, (void *)data, nalu_size); data += nalu_size; left -= nalu_size; goto again; } } else { - size = switch_buffer_write(buffer, sync_bytes, sizeof(sync_bytes)); + switch_buffer_write(buffer, sync_bytes, sizeof(sync_bytes)); size = switch_buffer_write(buffer, frame->data, frame->datalen); context->nalu_28_start = 0; } diff --git a/src/mod/codecs/mod_openh264/test/conf/freeswitch.xml b/src/mod/codecs/mod_openh264/test/conf/freeswitch.xml new file mode 100644 index 0000000000..b0ba4da969 --- /dev/null +++ b/src/mod/codecs/mod_openh264/test/conf/freeswitch.xml @@ -0,0 +1,38 @@ + + + +
+ + + + + + + + + + + + + + + + + + + + + + +
+ +
+ + + + + + + +
+
diff --git a/src/mod/codecs/mod_openh264/test/data/case1.packet1.264 b/src/mod/codecs/mod_openh264/test/data/case1.packet1.264 new file mode 100755 index 0000000000..4e076d8d91 --- /dev/null +++ b/src/mod/codecs/mod_openh264/test/data/case1.packet1.264 @@ -0,0 +1 @@ +'B X0{ \ No newline at end of file diff --git a/src/mod/codecs/mod_openh264/test/data/case1.packet2.264 b/src/mod/codecs/mod_openh264/test/data/case1.packet2.264 new file mode 100755 index 0000000000..d244d3b546 --- /dev/null +++ b/src/mod/codecs/mod_openh264/test/data/case1.packet2.264 @@ -0,0 +1 @@ +( \ No newline at end of file diff --git a/src/mod/codecs/mod_openh264/test/data/case1.packet3.264 b/src/mod/codecs/mod_openh264/test/data/case1.packet3.264 new file mode 100755 index 0000000000000000000000000000000000000000..b17dd27676c96dd72344c46e3736f67a43c50ed7 GIT binary patch literal 1826 zcmV+-2i^E3xF8_>N!`V+Lhk+qi+}(@WIY(4Ocdl}KnX4en@KjCh?uhLCFE()#yac3 z2fX&?kl+IoFy|*1{v&Y`8-!$gfWc+Os_$e$VC)}u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^K8)Xdcuv&3_PE_bg2o7%qi+L zp|drGH>1w=84d)QH6j%C%p(4QBXq(3m4<-3P+d#d1LYxx{CJ(0&qmWS1Y5~98R?;d z2c)?JaghMl&l3|GnJi<|VI$UL|4yn z!ozYm1_+R44MK=ZF0Ga!U>+eFcbe4)h6ah@M*K+I_P%Lao>TUcQNsNoX_A5&cJgo= z(|`N%0_(-(=d|U?G$Yu!YV$&>y8nO3qwLF?Q)qtGxp)bT_F|8tqjU&SBrmapFBv^J zn|Qc*Kw#?N$oj<;q$^k-QAhlFVIE#V3{-eWWYq9cxxXFXVJCHf_7E9x3+%(mfv9>) zE0=&NGeYRB*9<;B@=*2ky0(HilOQkI1Rx0vs2H|UK?rg;_!ImR=mu!SbwNge2CSVa za#9^+K+wF^U97Vbh?5~G+x3~EX?$hTfB>)BAOZ^<00aS{EfPI_50{^tMb_*WYI(F# Q`Grs)sgTB3V1{;GAQDbx>Hq)$ literal 0 HcmV?d00001 diff --git a/src/mod/codecs/mod_openh264/test/data/case1.packet4.264 b/src/mod/codecs/mod_openh264/test/data/case1.packet4.264 new file mode 100755 index 0000000000000000000000000000000000000000..1b9c51c18507e1ae66ee129b699ea72cc33e74c7 GIT binary patch literal 2323 zcmV+u3GDVI22KbF5yo)|2M>Y31Sn6CgDe83ph21eeGHxG{`@+eA>iQs@Yy5Cp~3^~ ziPK<@;LASdKn|Ia%;zxGT(j`fM6Ujc>owGE<0t8Ym6ZEp5P0{Td*yy!G+Lg zG3-s&&k<;ft1Sr=fdH{E2M14p z00%eC|3lw4^efANVim8yls3-^(Kyio#>6m%o2S7w$ zAbboz_thrN_{Bj39WF+bPz zbgU?-VH1jL6v~W7HIbLZqBT zH)J^Z_uxg3WyxC3(O8CrAaKK}?_u?#LuthJzGIir4rF8G#5U?V&LY zCK%HdL*3<{6n2O?>5h7Czkp0)#t_L!1EWhl1}?vT=G1x^GOu0;!1)4KCTiMf0eB7o ziok#>Vy*)wG1Ef|3$|U?Y9X+@prYhOD-fQtQ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rdp(O_1@!>Xc<_KvBpxhe(x3vq@kl|83vby+$L3b5*ouY0IRzpR~?*X+O_^{!%`Id)f8+g`rS;@v`K<8rZZ-8AsxK1?G$bAa&QIr;zq literal 0 HcmV?d00001 diff --git a/src/mod/codecs/mod_openh264/test/data/case1.packet5.264 b/src/mod/codecs/mod_openh264/test/data/case1.packet5.264 new file mode 100755 index 0000000000000000000000000000000000000000..27264044f63ead3710e5438dd74a37f4027b68fe GIT binary patch literal 89 zcmV-f0H*&T;ROR^{~UZzP01a(`uF~em;XfeKVD9fbo|8rEl_OJer|gHd%u4Df78M; v_kI!mzyJUM0U-uhK|uBI|M&0z|5;Q{{d)hB9m(tcd;j2u?|wHYUaqwyg99cJs6)%6y#$-2`&bkNj95^n6m37>>qYJXEzi4N&zFdmvq9Jej34jcpA0KhcwapyW>puAu zMa*GjNA;iK_32xX3f^c$alm_u*P!Zg@fWRc;s7RrAOM;c98VZRWO&ig;f$Zw8u%nY z7$>Qthe~-(UbjiGSzxD1h_zLpq-hAJ^ zxY2c`1Y0U0f?pMz7yiq|)D(V>jTlw16?O3um0$f+`$BjTZ$_K6`e*;|`3B*J$QV(r zU?CkWX)3}YU@LIpk@p+u6EgwW&K#Pu4eG##@R(krLB$2xm5_B4YX&GA-AsKrV8{X3 zz|Q>a>5p8sXOQ#y?g2HxD;YAb(m^K0(s}-5QL_R}xLydeXCa-qgZMZb<3kP@OQ;9` z)ay->9t1#Y=E8C8y@Hp_<|+6Qv3S3o#Z}xD<|h@JrOo+p7`N}g=ZR$~8eODws)V|4;vK)~k%q zic?~f>AR(`z@^{|2WHHGP)!1G@CN6n7;29>g$KwY7Ze1%df4TGY4!kW`d&wX1`v^i z1b`+j0oLyXJlIQ6C>8Y$K5Zii0zw=CZHNvb9i@)2Mlb-JCU{jSu*7c|0!**4z3RHA zzf6#J(nH9>3lMD&0>mb0as0x7J_Xaja3%mzfUu}6LuWt%i9i{{CY&YVk_FVB3j6fH z-^UmLaWD(56Digo{KCK`+yt>W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(e9J48psCmkD$lfqjmz4xsewN&2fn)N?@%UZG)_ zqo7*tnq;#F7?3sWjC>}cko^v`eg5YbGeJK=?t^>BwmV~`Q>yE7M8`20;(@I)CMJYq zl*4$JDj6}428oZ8@`wSZTBLII-s6&J8CZ|8#!|I@?-mNAp`&OS2A750CRKM58pBzB z!*c$ + * + * Version: MPL 1.1 + * + * The contents of this file are subject to the Mozilla Public License Version + * 1.1 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Original Code is FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application + * + * The Initial Developer of the Original Code is + * Seven Du + * Portions created by the Initial Developer are Copyright (C) + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Pax Cao + * + * mod_openh264_test -- mod_openh264 tests + * + */ + +#include + +#define TEST_SIMU_RTP_MAX_LEN 4200 + +/* Add our command line options. */ +static fctcl_init_t my_cl_options[] = { + {"--disable-hw", /* long_opt */ + NULL, /* short_opt (optional) */ + FCTCL_STORE_TRUE , /* action */ + "disable hardware encoder" /* help */ + }, + + FCTCL_INIT_NULL /* Sentinel */ +}; + +FST_CORE_BEGIN("conf") +{ + fctcl_install(my_cl_options); + + FST_MODULE_BEGIN(mod_openh264, mod_openh264_test) + { + FST_SETUP_BEGIN() + { + fst_requires_module("mod_openh264"); + } + FST_SETUP_END() + + FST_TEST_BEGIN(decoder_testcase) + { + switch_status_t status; + switch_codec_t codec = { 0 }; + switch_codec_settings_t codec_settings = {{ 0 }}; + switch_image_t *img; + uint8_t buf[TEST_SIMU_RTP_MAX_LEN + 12] = {0}; + switch_frame_t frame = { 0 }; + int packets = 0; + switch_status_t decode_status; + FILE *fp = NULL; + long file_size = 0; + switch_bool_t fh_status = SWITCH_FALSE; + int file_count = 1; + switch_set_string(codec_settings.video.config_profile_name, "test-decoder-1"); + + if (!fctcl_is("--disable-hw")) { + codec_settings.video.try_hardware_encoder = 1; + } + + status = switch_core_codec_init(&codec, + "H264", + NULL, + NULL, + 0, + 0, + 1, SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE, + &codec_settings, fst_pool); + fst_check(status == SWITCH_STATUS_SUCCESS); + + frame.packet = buf; + frame.packetlen = TEST_SIMU_RTP_MAX_LEN + 12; + frame.data = buf + 12; + frame.datalen = TEST_SIMU_RTP_MAX_LEN; + frame.payload = 96; + frame.m = SWITCH_FALSE; + frame.seq = 0; + frame.timestamp = 375233; + frame.img = (switch_image_t*)NULL; + do { + switch_size_t len = TEST_SIMU_RTP_MAX_LEN; + char file_name[128] = { 0 }; + frame.seq++; + switch_snprintf(file_name, 128, "./data/case1.packet%d.264", file_count); + + fp = fopen(file_name, "rb"); + if (!fp) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, + "read video file %s failed \n", file_name); + break; + } + fseek(fp, 0, SEEK_END); + file_size = ftell(fp); + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, + "file %s length: %ld \n", file_name, file_size); + fseek(fp, 0, SEEK_SET); + + frame.datalen = fread(frame.data, sizeof(char), file_size, fp); + fst_check(frame.datalen == file_size); + + if (4 == file_count ) { + frame.m = SWITCH_TRUE; + } + if (5 == file_count) { + frame.m = SWITCH_TRUE; + frame.timestamp = 380633; + } + decode_status = switch_core_codec_decode_video(&codec, &frame); + fst_check(decode_status == SWITCH_STATUS_SUCCESS || decode_status == SWITCH_STATUS_MORE_DATA); + + if (frame.img != NULL) { + // write down the decoded + status = switch_img_write_png(frame.img, (char *)"case1.output.qcif.png"); + fst_check(status == SWITCH_STATUS_SUCCESS); + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, + "write output file done! \n"); + + } + fclose(fp); + file_count++; + } while (decode_status == SWITCH_STATUS_MORE_DATA && file_count < 6); + + switch_core_codec_destroy(&codec); + + file_count = 1; + status = switch_core_codec_init(&codec, + "H264", + NULL, + NULL, + 0, + 0, + 1, SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE, + &codec_settings, fst_pool); + fst_check(status == SWITCH_STATUS_SUCCESS); + + frame.packet = buf; + frame.packetlen = TEST_SIMU_RTP_MAX_LEN + 12; + frame.data = buf + 12; + frame.datalen = TEST_SIMU_RTP_MAX_LEN; + frame.payload = 96; + frame.m = SWITCH_FALSE; + frame.seq = 0; + frame.timestamp = 375233; + frame.img = (switch_image_t*)NULL; + do { + switch_size_t len = TEST_SIMU_RTP_MAX_LEN; + char file_name[128] = { 0 }; + frame.seq++; + switch_snprintf(file_name, 128, "./data/case2.packet%d.264", file_count); + + fp = fopen(file_name, "rb"); + if (!fp) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, + "read video file %s failed \n", file_name); + break; + } + fseek(fp, 0, SEEK_END); + file_size = ftell(fp); + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, + "file %s length: %ld \n", file_name, file_size); + fseek(fp, 0, SEEK_SET); + + frame.datalen = fread(frame.data, sizeof(char), file_size, fp); + fst_check(frame.datalen == file_size); + + if (3 == file_count) { + frame.m = SWITCH_TRUE; + } + if (4 == file_count) { + frame.m = SWITCH_TRUE; + frame.timestamp = 380633; + } + decode_status = switch_core_codec_decode_video(&codec, &frame); + fst_check(decode_status == SWITCH_STATUS_SUCCESS || decode_status == SWITCH_STATUS_MORE_DATA); + if (frame.img != NULL) { + // write down the decoded + status = switch_img_write_png(frame.img, (char *)"case2.output.qcif.png"); + fst_check(status == SWITCH_STATUS_SUCCESS); + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, + "write output file done! \n"); + + } + fclose(fp); + file_count++; + } while (decode_status == SWITCH_STATUS_MORE_DATA && file_count < 5); + + switch_core_codec_destroy(&codec); + + } + FST_TEST_END() + + + FST_TEARDOWN_BEGIN() + { + const char *err = NULL; + switch_sleep(1000000); + fst_check(switch_loadable_module_unload_module(SWITCH_GLOBAL_dirs.mod_dir, (char *)"mod_openh264", SWITCH_TRUE, &err) == SWITCH_STATUS_SUCCESS); + } + FST_TEARDOWN_END() + } + FST_MODULE_END() +} +FST_CORE_END()