Newer
Older
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
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
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
ast_test_validate_cleanup(test, !change_res, res, done);
ast_test_validate_cleanup(test, pvt->indicated_changed, res, done);
done:
ast_hangup(mock_channel);
return res;
}
AST_TEST_DEFINE(stream_topology_change_request_from_channel)
{
struct ast_channel_tech tech = {
.read_stream = mock_channel_read,
.write_stream = mock_channel_write_stream,
.indicate = mock_channel_indicate,
.hangup = mock_channel_hangup,
};
struct ast_channel *mock_channel;
struct mock_channel_pvt *pvt;
enum ast_test_result_state res = AST_TEST_PASS;
RAII_VAR(struct ast_stream_topology *, topology, NULL, ast_stream_topology_free);
struct ast_frame request_change = {
.frametype = AST_FRAME_CONTROL,
.subclass.integer = AST_CONTROL_STREAM_TOPOLOGY_REQUEST_CHANGE,
};
struct ast_frame *fr = NULL;
switch (cmd) {
case TEST_INIT:
info->name = "stream_topology_change_request_from_channel";
info->category = "/main/stream/";
info->summary = "channel requesting stream topology change to multistream application test";
info->description =
"Test that a channel requesting a stream topology change from a multistream application works";
return AST_TEST_NOT_RUN;
case TEST_EXECUTE:
break;
}
mock_channel = make_channel(test, 1, &tech);
ast_test_validate_cleanup(test, mock_channel, res, done);
pvt = ast_channel_tech_pvt(mock_channel);
pvt->indicated_changed = 0;
topology = ast_stream_topology_alloc();
ast_test_validate_cleanup(test, topology, res, done);
request_change.data.ptr = topology;
ast_queue_frame(mock_channel, &request_change);
fr = ast_read_stream(mock_channel);
ast_test_validate_cleanup(test, fr, res, done);
ast_test_validate_cleanup(test, fr->frametype == AST_FRAME_CONTROL, res, done);
ast_test_validate_cleanup(test, fr->subclass.integer == AST_CONTROL_STREAM_TOPOLOGY_REQUEST_CHANGE, res, done);
ast_test_validate_cleanup(test, !pvt->indicated_changed, res, done);
done:
if (fr) {
ast_frfree(fr);
}
ast_hangup(mock_channel);
return res;
}
AST_TEST_DEFINE(format_cap_from_stream_topology)
{
RAII_VAR(struct ast_format_cap *, caps, NULL, ao2_cleanup);
RAII_VAR(struct ast_format_cap *, stream_caps, NULL, ao2_cleanup);
struct ast_stream_topology *topology;
struct ast_stream *stream;
struct ast_format_cap *new_cap;
switch (cmd) {
case TEST_INIT:
info->name = "format_cap_from_stream_topology";
info->category = "/main/stream/";
info->summary = "stream topology to format capabilities conversion test";
info->description =
"Test that converting a stream topology to format capabilities results in expected formats";
return AST_TEST_NOT_RUN;
case TEST_EXECUTE:
break;
}
caps = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT);
if (!caps) {
ast_test_status_update(test, "Could not allocate an empty format capabilities structure\n");
return AST_TEST_FAIL;
}
if (ast_format_cap_append(caps, ast_format_ulaw, 0)) {
ast_test_status_update(test, "Failed to append ulaw format to capabilities\n");
return AST_TEST_FAIL;
}
if (ast_format_cap_append(caps, ast_format_h264, 0)) {
ast_test_status_update(test, "Failed to append h264 format to capabilities\n");
return AST_TEST_FAIL;
}
topology = ast_stream_topology_create_from_format_cap(caps);
if (!topology) {
ast_test_status_update(test, "Failed to create a stream topology from format capabilities of ulaw and h264\n");
return AST_TEST_FAIL;
}
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
/*
* Append declined stream with formats that should not be included
* in combined topology caps.
*/
stream = ast_stream_alloc("audio", AST_MEDIA_TYPE_AUDIO);
if (!stream) {
ast_test_status_update(test, "Failed to create an audio stream for testing stream topology\n");
ast_stream_topology_free(topology);
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_stream_topology_get_formats(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;
}
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
#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_metadata);
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_metadata);
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");