Newer
Older
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
return AST_TEST_FAIL;
}
ast_stream_set_state(stream, AST_STREAM_STATE_REMOVED);
new_cap = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT);
if (!new_cap) {
ast_test_status_update(test, "Could not allocate an empty format capabilities structure\n");
ast_stream_free(stream);
ast_stream_topology_free(topology);
return AST_TEST_FAIL;
}
if (ast_format_cap_append(new_cap, ast_format_alaw, 0)) {
ast_test_status_update(test, "Failed to append alaw format to capabilities\n");
ao2_cleanup(new_cap);
ast_stream_free(stream);
ast_stream_topology_free(topology);
return AST_TEST_FAIL;
}
ast_stream_set_formats(stream, new_cap);
ao2_cleanup(new_cap);
if (ast_stream_topology_append_stream(topology, stream) == -1) {
ast_test_status_update(test, "Failed to append a perfectly good stream to a topology\n");
ast_stream_free(stream);
ast_stream_topology_free(topology);
return AST_TEST_FAIL;
}
stream_caps = ast_format_cap_from_stream_topology(topology);
if (!stream_caps) {
ast_test_status_update(test, "Failed to create a format capabilities from a stream topology\n");
ast_stream_topology_free(topology);
return AST_TEST_FAIL;
}
ast_stream_topology_free(topology);
if (!ast_format_cap_identical(caps, stream_caps)) {
ast_test_status_update(test, "Converting format capabilities into topology and back resulted in different formats\n");
return AST_TEST_FAIL;
}
return AST_TEST_PASS;
}
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
#define topology_append_stream(topology, name, type, res, label) \
do { \
struct ast_stream *__stream = ast_stream_alloc((name), (type)); \
ast_test_validate_cleanup(test, __stream, res, label); \
if (ast_stream_topology_append_stream((topology), __stream) < 0) { \
ast_stream_free(__stream); \
res = AST_TEST_FAIL; \
goto label; \
} \
} while(0)
AST_TEST_DEFINE(stream_topology_map_create)
{
RAII_VAR(struct ast_stream_topology *, t0, NULL, ast_stream_topology_free);
struct ast_vector_int types = { NULL };
struct ast_vector_int v0 = { NULL };
struct ast_vector_int v1 = { NULL };
enum ast_test_result_state res = AST_TEST_PASS;
switch (cmd) {
case TEST_INIT:
info->name = "stream_topology_map_create";
info->category = "/main/stream/";
info->summary = "stream topology map creation unit test";
info->description =
"Test that creating a stream topology map works";
return AST_TEST_NOT_RUN;
case TEST_EXECUTE:
break;
}
ast_test_validate(test, AST_VECTOR_INIT(&types, 5) == 0);
/* Map a first topology and check that it mapped one to one */
ast_test_validate_cleanup(test, (t0 = ast_stream_topology_alloc()), res, done);
topology_append_stream(t0, "audio", AST_MEDIA_TYPE_AUDIO, res, done);
topology_append_stream(t0, "video", AST_MEDIA_TYPE_VIDEO, res, done);
ast_stream_topology_map(t0, &types, &v0, &v1);
ast_test_validate_cleanup(test, AST_VECTOR_SIZE(&types) == 2, res, done);
ast_test_validate_cleanup(test, AST_VECTOR_GET(&types, 0) == AST_MEDIA_TYPE_AUDIO, res, done);
ast_test_validate_cleanup(test, AST_VECTOR_GET(&types, 1) == AST_MEDIA_TYPE_VIDEO, res, done);
ast_test_validate_cleanup(test, AST_VECTOR_GET(&v0, 0) == 0, res, done);
ast_test_validate_cleanup(test, AST_VECTOR_GET(&v0, 1) == 1, res, done);
ast_test_validate_cleanup(test, AST_VECTOR_GET(&v1, 0) == 0, res, done);
ast_test_validate_cleanup(test, AST_VECTOR_GET(&v1, 1) == 1, res, done);
/* Map a second topology and check that it merged */
ast_stream_topology_free(t0);
ast_test_validate_cleanup(test, (t0 = ast_stream_topology_alloc()), res, done);
topology_append_stream(t0, "video", AST_MEDIA_TYPE_VIDEO, res, done);
topology_append_stream(t0, "audio", AST_MEDIA_TYPE_AUDIO, res, done);
ast_stream_topology_map(t0, &types, &v0, &v1);
ast_test_validate_cleanup(test, AST_VECTOR_SIZE(&types) == 2, res, done);
ast_test_validate_cleanup(test, AST_VECTOR_GET(&types, 0) == AST_MEDIA_TYPE_AUDIO, res, done);
ast_test_validate_cleanup(test, AST_VECTOR_GET(&types, 1) == AST_MEDIA_TYPE_VIDEO, res, done);
ast_test_validate_cleanup(test, AST_VECTOR_GET(&v0, 0) == 1, res, done);
ast_test_validate_cleanup(test, AST_VECTOR_GET(&v0, 1) == 0, res, done);
ast_test_validate_cleanup(test, AST_VECTOR_GET(&v1, 0) == 1, res, done);
ast_test_validate_cleanup(test, AST_VECTOR_GET(&v1, 1) == 0, res, done);
/* Map a third topology with more streams and check that it merged */
ast_stream_topology_free(t0);
ast_test_validate_cleanup(test, (t0 = ast_stream_topology_alloc()), res, done);
topology_append_stream(t0, "video", AST_MEDIA_TYPE_VIDEO, res, done);
topology_append_stream(t0, "audio", AST_MEDIA_TYPE_AUDIO, res, done);
topology_append_stream(t0, "audio", AST_MEDIA_TYPE_AUDIO, res, done);
ast_stream_topology_map(t0, &types, &v0, &v1);
ast_test_validate_cleanup(test, AST_VECTOR_SIZE(&types) == 3, res, done);
ast_test_validate_cleanup(test, AST_VECTOR_GET(&types, 0) == AST_MEDIA_TYPE_AUDIO, res, done);
ast_test_validate_cleanup(test, AST_VECTOR_GET(&types, 1) == AST_MEDIA_TYPE_VIDEO, res, done);
ast_test_validate_cleanup(test, AST_VECTOR_GET(&types, 2) == AST_MEDIA_TYPE_AUDIO, res, done);
ast_test_validate_cleanup(test, AST_VECTOR_GET(&v0, 0) == 1, res, done);
ast_test_validate_cleanup(test, AST_VECTOR_GET(&v0, 1) == 0, res, done);
ast_test_validate_cleanup(test, AST_VECTOR_GET(&v0, 2) == 2, res, done);
ast_test_validate_cleanup(test, AST_VECTOR_GET(&v1, 0) == 1, res, done);
ast_test_validate_cleanup(test, AST_VECTOR_GET(&v1, 1) == 0, res, done);
ast_test_validate_cleanup(test, AST_VECTOR_GET(&v1, 2) == 2, res, done);
done:
AST_VECTOR_FREE(&v1);
AST_VECTOR_FREE(&v0);
AST_VECTOR_FREE(&types);
return res;
}
static int unload_module(void)
{
AST_TEST_UNREGISTER(stream_create);
AST_TEST_UNREGISTER(stream_create_no_name);
AST_TEST_UNREGISTER(stream_set_type);
AST_TEST_UNREGISTER(stream_set_formats);
AST_TEST_UNREGISTER(stream_set_state);
AST_TEST_UNREGISTER(stream_topology_create);
AST_TEST_UNREGISTER(stream_topology_clone);
AST_TEST_UNREGISTER(stream_topology_clone);
AST_TEST_UNREGISTER(stream_topology_append_stream);
AST_TEST_UNREGISTER(stream_topology_set_stream);
AST_TEST_UNREGISTER(stream_topology_del_stream);
AST_TEST_UNREGISTER(stream_topology_create_from_format_cap);
AST_TEST_UNREGISTER(stream_topology_get_first_stream_by_type);
AST_TEST_UNREGISTER(stream_topology_create_from_channel_nativeformats);
AST_TEST_UNREGISTER(stream_topology_channel_set);
AST_TEST_UNREGISTER(stream_write_non_multistream);
AST_TEST_UNREGISTER(stream_write_multistream);
AST_TEST_UNREGISTER(stream_read_non_multistream);
AST_TEST_UNREGISTER(stream_read_multistream);
AST_TEST_UNREGISTER(stream_topology_change_request_from_application_non_multistream);
AST_TEST_UNREGISTER(stream_topology_change_request_from_channel_non_multistream);
AST_TEST_UNREGISTER(stream_topology_change_request_from_application);
AST_TEST_UNREGISTER(stream_topology_change_request_from_channel);
AST_TEST_UNREGISTER(format_cap_from_stream_topology);
AST_TEST_UNREGISTER(stream_topology_map_create);
return 0;
}
static int load_module(void)
{
AST_TEST_REGISTER(stream_create);
AST_TEST_REGISTER(stream_create_no_name);
AST_TEST_REGISTER(stream_set_type);
AST_TEST_REGISTER(stream_set_formats);
AST_TEST_REGISTER(stream_set_state);
AST_TEST_REGISTER(stream_topology_create);
AST_TEST_REGISTER(stream_topology_clone);
AST_TEST_REGISTER(stream_topology_append_stream);
AST_TEST_REGISTER(stream_topology_set_stream);
AST_TEST_REGISTER(stream_topology_del_stream);
AST_TEST_REGISTER(stream_topology_create_from_format_cap);
AST_TEST_REGISTER(stream_topology_get_first_stream_by_type);
AST_TEST_REGISTER(stream_topology_create_from_channel_nativeformats);
AST_TEST_REGISTER(stream_topology_channel_set);
AST_TEST_REGISTER(stream_write_non_multistream);
AST_TEST_REGISTER(stream_write_multistream);
AST_TEST_REGISTER(stream_read_non_multistream);
AST_TEST_REGISTER(stream_read_multistream);
AST_TEST_REGISTER(stream_topology_change_request_from_application_non_multistream);
AST_TEST_REGISTER(stream_topology_change_request_from_channel_non_multistream);
AST_TEST_REGISTER(stream_topology_change_request_from_application);
AST_TEST_REGISTER(stream_topology_change_request_from_channel);
AST_TEST_REGISTER(format_cap_from_stream_topology);
AST_TEST_REGISTER(stream_topology_map_create);
return AST_MODULE_LOAD_SUCCESS;
}
AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Media Stream API test module");