Merge pull request #222 from paxc/master

[mod_openh264] Fix stap-a size issue and add unit test.
This commit is contained in:
Andrey Volk 2020-05-15 21:04:25 +04:00 committed by GitHub
commit 55ddecd750
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 280 additions and 5 deletions

View File

@ -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)

View File

@ -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;
}

View File

@ -0,0 +1,38 @@
<?xml version="1.0"?>
<document type="freeswitch/xml">
<section name="configuration" description="Various Configuration">
<configuration name="modules.conf" description="Modules">
<modules>
<load module="mod_console"/>
</modules>
</configuration>
<configuration name="console.conf" description="Console Logger">
<mappings>
<map name="all" value="console,debug,info,notice,warning,err,crit,alert"/>
</mappings>
<settings>
<param name="colorize" value="true"/>
<param name="loglevel" value="debug"/>
</settings>
</configuration>
<configuration name="timezones.conf" description="Timezones">
<timezones>
<zone name="GMT" value="GMT0" />
</timezones>
</configuration>
</section>
<section name="dialplan" description="Regex/XML Dialplan">
<context name="default">
<extension name="sample">
<condition>
<action application="info"/>
</condition>
</extension>
</context>
</section>
</document>

View File

@ -0,0 +1 @@
'B<> <0B>X<><58><EFBFBD>0<>{<7B>

View File

@ -0,0 +1 @@
(<28> <09>

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1 @@
'B<> <0B>X<><58><EFBFBD>0<>{<7B>

View File

@ -0,0 +1 @@
(<28> <09>

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,220 @@
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
* Copyright (C) 2005-2018, Anthony Minessale II <anthm@freeswitch.org>
*
* 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 <dujinfang@gmail.com>
* Portions created by the Initial Developer are Copyright (C)
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Pax Cao <yiping.cao@msn.com>
*
* mod_openh264_test -- mod_openh264 tests
*
*/
#include <test/switch_test.h>
#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()