49 info->name =
"stream_create";
50 info->category =
"/main/stream/";
51 info->summary =
"stream create unit test";
53 "Test that creating a stream results in a stream with the expected values";
54 return AST_TEST_NOT_RUN;
61 ast_test_status_update(
test,
"Failed to create media stream given proper arguments\n");
66 ast_test_status_update(
test,
"Newly created stream does not have expected inactive stream state\n");
71 ast_test_status_update(
test,
"Newly created stream does not have expected audio media type\n");
76 ast_test_status_update(
test,
"Newly created stream does not have expected name of test\n");
89 info->name =
"stream_create_no_name";
90 info->category =
"/main/stream/";
91 info->summary =
"stream create (without a name) unit test";
93 "Test that creating a stream with no name works";
94 return AST_TEST_NOT_RUN;
101 ast_test_status_update(
test,
"Failed to create media stream given proper arguments\n");
102 return AST_TEST_FAIL;
105 return AST_TEST_PASS;
114 info->name =
"stream_set_type";
115 info->category =
"/main/stream/";
116 info->summary =
"stream type setting unit test";
118 "Test that changing the type of a stream works";
119 return AST_TEST_NOT_RUN;
126 ast_test_status_update(
test,
"Failed to create media stream given proper arguments\n");
127 return AST_TEST_FAIL;
131 ast_test_status_update(
test,
"Newly created stream does not have expected audio media type\n");
132 return AST_TEST_FAIL;
138 ast_test_status_update(
test,
"Changed stream does not have expected video media type\n");
139 return AST_TEST_FAIL;
142 return AST_TEST_PASS;
152 info->name =
"stream_set_formats";
153 info->category =
"/main/stream/";
154 info->summary =
"stream formats setting unit test";
156 "Test that changing the formats of a stream works";
157 return AST_TEST_NOT_RUN;
164 ast_test_status_update(
test,
"Failed to create a format capabilities structure for testing\n");
165 return AST_TEST_FAIL;
170 ast_test_status_update(
test,
"Failed to create media stream given proper arguments\n");
171 return AST_TEST_FAIL;
177 ast_test_status_update(
test,
"Changed stream does not have expected formats\n");
178 return AST_TEST_FAIL;
184 ast_test_status_update(
test,
"Retrieved formats from stream despite removing them\n");
185 return AST_TEST_FAIL;
188 return AST_TEST_PASS;
197 info->name =
"stream_set_state";
198 info->category =
"/main/stream/";
199 info->summary =
"stream state setting unit test";
201 "Test that changing the state of a stream works";
202 return AST_TEST_NOT_RUN;
209 ast_test_status_update(
test,
"Failed to create media stream given proper arguments\n");
210 return AST_TEST_FAIL;
214 ast_test_status_update(
test,
"Newly created stream does not have expected inactive stream state\n");
215 return AST_TEST_FAIL;
221 ast_test_status_update(
test,
"Changed stream does not have expected sendrecv state\n");
222 return AST_TEST_FAIL;
225 return AST_TEST_PASS;
231 char track_label[AST_UUID_STR_LEN + 1];
232 const char *stream_track_label;
237 info->name =
"stream_metadata";
238 info->category =
"/main/stream/";
239 info->summary =
"stream metadata unit test";
241 "Test that metadata operations on a stream works";
242 return AST_TEST_NOT_RUN;
249 ast_test_status_update(
test,
"Failed to create media stream given proper arguments\n");
250 return AST_TEST_FAIL;
254 if (stream_track_label) {
255 ast_test_status_update(
test,
"New stream HAD a track label\n");
256 return AST_TEST_FAIL;
262 ast_test_status_update(
test,
"Failed to add track label\n");
263 return AST_TEST_FAIL;
267 if (!stream_track_label) {
268 ast_test_status_update(
test,
"Changed stream does not have a track label\n");
269 return AST_TEST_FAIL;
272 if (strcmp(stream_track_label, track_label) != 0) {
273 ast_test_status_update(
test,
"Changed stream did not return same track label\n");
274 return AST_TEST_FAIL;
279 ast_test_status_update(
test,
"Failed to remove track label\n");
280 return AST_TEST_FAIL;
284 if (stream_track_label) {
285 ast_test_status_update(
test,
"Changed stream still had a track label after we removed it\n");
286 return AST_TEST_FAIL;
289 return AST_TEST_PASS;
298 info->name =
"stream_topology_create";
299 info->category =
"/main/stream/";
300 info->summary =
"stream topology creation unit test";
302 "Test that creating a stream topology works";
303 return AST_TEST_NOT_RUN;
310 ast_test_status_update(
test,
"Failed to create media stream topology\n");
311 return AST_TEST_FAIL;
314 return AST_TEST_PASS;
321 struct ast_stream *audio_stream, *video_stream;
322 char audio_track_label[AST_UUID_STR_LEN + 1];
323 char video_track_label[AST_UUID_STR_LEN + 1];
324 const char *original_track_label;
325 const char *cloned_track_label;
330 info->name =
"stream_topology_clone";
331 info->category =
"/main/stream/";
332 info->summary =
"stream topology cloning unit test";
334 "Test that cloning a stream topology results in a clone with the same contents";
335 return AST_TEST_NOT_RUN;
342 ast_test_status_update(
test,
"Failed to create media stream topology\n");
343 return AST_TEST_FAIL;
348 ast_test_status_update(
test,
"Failed to create an audio stream for testing stream topology\n");
349 return AST_TEST_FAIL;
355 ast_test_status_update(
test,
"Failed to add track label\n");
356 return AST_TEST_FAIL;
360 ast_test_status_update(
test,
"Failed to append valid audio stream to stream topology\n");
362 return AST_TEST_FAIL;
367 ast_test_status_update(
test,
"Failed to create a video stream for testing stream topology\n");
368 return AST_TEST_FAIL;
374 ast_test_status_update(
test,
"Failed to add track label\n");
375 return AST_TEST_FAIL;
379 ast_test_status_update(
test,
"Failed to append valid video stream to stream topology\n");
381 return AST_TEST_FAIL;
386 ast_test_status_update(
test,
"Failed to clone a perfectly good stream topology\n");
387 return AST_TEST_FAIL;
391 ast_test_status_update(
test,
"Cloned stream topology does not contain same number of streams as original\n");
392 return AST_TEST_FAIL;
396 ast_test_status_update(
test,
"Cloned audio stream does not contain same type as original\n");
397 return AST_TEST_FAIL;
401 "AST_STREAM_METADATA_TRACK_LABEL");
402 if (!original_track_label) {
403 ast_test_status_update(
test,
"Original topology stream 0 does not contain metadata\n");
404 return AST_TEST_FAIL;
407 "AST_STREAM_METADATA_TRACK_LABEL");
408 if (!cloned_track_label) {
409 ast_test_status_update(
test,
"Cloned topology stream 0 does not contain metadata\n");
410 return AST_TEST_FAIL;
412 if (strcmp(original_track_label, cloned_track_label) != 0) {
413 ast_test_status_update(
test,
"Cloned topology stream 0 track label was not the same as the original\n");
414 return AST_TEST_FAIL;
418 ast_test_status_update(
test,
"Cloned video stream does not contain same type as original\n");
419 return AST_TEST_FAIL;
423 "AST_STREAM_METADATA_TRACK_LABEL");
424 if (!original_track_label) {
425 ast_test_status_update(
test,
"Original topology stream 1 does not contain metadata\n");
426 return AST_TEST_FAIL;
429 "AST_STREAM_METADATA_TRACK_LABEL");
430 if (!cloned_track_label) {
431 ast_test_status_update(
test,
"Cloned topology stream 1 does not contain metadata\n");
432 return AST_TEST_FAIL;
434 if (strcmp(original_track_label, cloned_track_label) != 0) {
435 ast_test_status_update(
test,
"Cloned topology stream 1 track label was not the same as the original\n");
436 return AST_TEST_FAIL;
439 return AST_TEST_PASS;
445 struct ast_stream *audio_stream, *video_stream;
450 info->name =
"stream_topology_append_stream";
451 info->category =
"/main/stream/";
452 info->summary =
"stream topology stream appending unit test";
454 "Test that appending streams to a stream topology works";
455 return AST_TEST_NOT_RUN;
462 ast_test_status_update(
test,
"Failed to create media stream topology\n");
463 return AST_TEST_FAIL;
468 ast_test_status_update(
test,
"Failed to create an audio stream for testing stream topology\n");
469 return AST_TEST_FAIL;
473 if (position == -1) {
474 ast_test_status_update(
test,
"Failed to append valid audio stream to stream topology\n");
476 return AST_TEST_FAIL;
477 }
else if (position != 0) {
478 ast_test_status_update(
test,
"Appended audio stream to stream topology but position is '%d' instead of 0\n",
480 return AST_TEST_FAIL;
484 ast_test_status_update(
test,
"Appended an audio stream to the stream topology but stream count is '%d' on it, not 1\n",
486 return AST_TEST_FAIL;
490 ast_test_status_update(
test,
"Appended an audio stream to the stream topology but returned stream doesn't match\n");
491 return AST_TEST_FAIL;
495 ast_test_status_update(
test,
"Appended audio stream says it is at position '%d' instead of 0\n",
497 return AST_TEST_FAIL;
502 ast_test_status_update(
test,
"Failed to create a video stream for testing stream topology\n");
503 return AST_TEST_FAIL;
507 if (position == -1) {
508 ast_test_status_update(
test,
"Failed to append valid video stream to stream topology\n");
510 return AST_TEST_FAIL;
511 }
else if (position != 1) {
512 ast_test_status_update(
test,
"Appended video stream to stream topology but position is '%d' instead of 1\n",
514 return AST_TEST_FAIL;
518 ast_test_status_update(
test,
"Appended a video stream to the stream topology but stream count is '%d' on it, not 2\n",
520 return AST_TEST_FAIL;
524 ast_test_status_update(
test,
"Appended a video stream to the stream topology but returned stream doesn't match\n");
525 return AST_TEST_FAIL;
529 ast_test_status_update(
test,
"Appended video stream says it is at position '%d' instead of 1\n",
531 return AST_TEST_FAIL;
534 return AST_TEST_PASS;
540 struct ast_stream *audio_stream, *video_stream;
544 info->name =
"stream_topology_set_stream";
545 info->category =
"/main/stream/";
546 info->summary =
"stream topology stream setting unit test";
548 "Test that setting streams at a specific position in a topology works";
549 return AST_TEST_NOT_RUN;
556 ast_test_status_update(
test,
"Failed to create media stream topology\n");
557 return AST_TEST_FAIL;
562 ast_test_status_update(
test,
"Failed to create an audio stream for testing stream topology\n");
563 return AST_TEST_FAIL;
567 ast_test_status_update(
test,
"Failed to set an audio stream to a position where it is permitted\n");
569 return AST_TEST_FAIL;
573 ast_test_status_update(
test,
"Set an audio stream on the stream topology but stream count is '%d' on it, not 1\n",
575 return AST_TEST_FAIL;
579 ast_test_status_update(
test,
"Set an audio stream on the stream topology but returned stream doesn't match\n");
580 return AST_TEST_FAIL;
584 ast_test_status_update(
test,
"Set audio stream says it is at position '%d' instead of 0\n",
586 return AST_TEST_FAIL;
591 ast_test_status_update(
test,
"Failed to create a video stream for testing stream topology\n");
592 return AST_TEST_FAIL;
596 ast_test_status_update(
test,
"Failed to set a video stream to a position where it is permitted\n");
598 return AST_TEST_FAIL;
602 ast_test_status_update(
test,
"Set a video stream on the stream topology but stream count is '%d' on it, not 1\n",
604 return AST_TEST_FAIL;
608 ast_test_status_update(
test,
"Set a video stream on the stream topology but returned stream doesn't match\n");
609 return AST_TEST_FAIL;
613 ast_test_status_update(
test,
"Set video stream says it is at position '%d' instead of 0\n",
615 return AST_TEST_FAIL;
620 ast_test_status_update(
test,
"Failed to create an audio stream for testing stream topology\n");
621 return AST_TEST_FAIL;
625 ast_test_status_update(
test,
"Failed to set an audio stream to a position where it is permitted\n");
627 return AST_TEST_FAIL;
631 ast_test_status_update(
test,
"Set an audio stream on the stream topology but stream count is '%d' on it, not 2\n",
633 return AST_TEST_FAIL;
637 ast_test_status_update(
test,
"Set an audio stream on the stream topology but returned stream doesn't match\n");
638 return AST_TEST_FAIL;
642 ast_test_status_update(
test,
"Set audio stream says it is at position '%d' instead of 1\n",
644 return AST_TEST_FAIL;
647 return AST_TEST_PASS;
662 ast_test_status_update(test,
"Failed: '%s' stream says it is at position %d instead of %d\n",
679 info->name =
"stream_topology_del_stream";
680 info->category =
"/main/stream/";
681 info->summary =
"stream topology stream delete unit test";
683 "Test that deleting streams at a specific position in a topology works";
684 return AST_TEST_NOT_RUN;
691 ast_test_status_update(test,
"Failed to create media stream topology\n");
692 return AST_TEST_FAIL;
696 for (type = AST_MEDIA_TYPE_UNKNOWN; type < AST_MEDIA_TYPE_END; ++
type) {
699 ast_test_status_update(test,
"Failed to create '%s' stream for testing stream topology\n",
701 return AST_TEST_FAIL;
704 ast_test_status_update(test,
"Failed to append '%s' stream to topology\n",
707 return AST_TEST_FAIL;
712 type = AST_MEDIA_TYPE_UNKNOWN;
716 ast_test_status_update(test,
"Initial topology types failed: Expected:%s Got:%s\n",
719 return AST_TEST_FAIL;
722 if (check_stream_positions(test, topology)) {
723 ast_test_status_update(test,
"Initial topology positions failed.\n");
724 return AST_TEST_FAIL;
729 ast_test_status_update(test,
"Deleting stream outside of topology succeeded!\n");
730 return AST_TEST_FAIL;
735 ast_test_status_update(test,
"Failed deleting last stream of topology.\n");
736 return AST_TEST_FAIL;
738 if (check_stream_positions(test, topology)) {
739 ast_test_status_update(test,
"Last stream delete topology positions failed.\n");
740 return AST_TEST_FAIL;
744 if (type != AST_MEDIA_TYPE_END - 2) {
745 ast_test_status_update(test,
"Last stream delete types failed: Expected:%s Got:%s\n",
748 return AST_TEST_FAIL;
753 ast_test_status_update(test,
"Failed deleting second stream in topology.\n");
754 return AST_TEST_FAIL;
756 if (check_stream_positions(test, topology)) {
757 ast_test_status_update(test,
"Second stream delete topology positions failed.\n");
758 return AST_TEST_FAIL;
762 if (type != AST_MEDIA_TYPE_UNKNOWN + 2) {
763 ast_test_status_update(test,
"Second stream delete types failed: Expected:%s Got:%s\n",
766 return AST_TEST_FAIL;
771 ast_test_status_update(test,
"Failed deleting first stream in topology.\n");
772 return AST_TEST_FAIL;
774 if (check_stream_positions(test, topology)) {
775 ast_test_status_update(test,
"First stream delete topology positions failed.\n");
776 return AST_TEST_FAIL;
780 if (type != AST_MEDIA_TYPE_UNKNOWN + 2) {
781 ast_test_status_update(test,
"First stream delete types failed: Expected:%s Got:%s\n",
784 return AST_TEST_FAIL;
787 return AST_TEST_PASS;
797 info->name =
"stream_topology_create_from_format_cap";
798 info->category =
"/main/stream/";
799 info->summary =
"stream topology creation from format capabilities unit test";
801 "Test that creating a stream topology from format capabilities results in the expected streams";
802 return AST_TEST_NOT_RUN;
809 ast_test_status_update(test,
"Could not allocate an empty format capabilities structure\n");
810 return AST_TEST_FAIL;
814 ast_test_status_update(test,
"Failed to append a ulaw format to capabilities for stream topology creation\n");
815 return AST_TEST_FAIL;
819 ast_test_status_update(test,
"Failed to append an alaw format to capabilities for stream topology creation\n");
820 return AST_TEST_FAIL;
825 ast_test_status_update(test,
"Failed to create a stream topology using a perfectly good format capabilities\n");
826 return AST_TEST_FAIL;
830 ast_test_status_update(test,
"Expected a stream topology with 1 stream but it has %d streams\n",
832 return AST_TEST_FAIL;
836 ast_test_status_update(test,
"Produced stream topology has a single stream of type %s instead of audio\n",
838 return AST_TEST_FAIL;
848 ast_test_status_update(test,
"Failed to create a stream topology using a perfectly good format capabilities\n");
849 return AST_TEST_FAIL;
853 ast_test_status_update(test,
"Expected a stream topology with 2 streams but it has %d streams\n",
855 return AST_TEST_FAIL;
859 ast_test_status_update(test,
"Produced stream topology has a first stream of type %s instead of audio\n",
861 return AST_TEST_FAIL;
865 ast_test_status_update(test,
"Produced stream topology has a second stream of type %s instead of video\n",
867 return AST_TEST_FAIL;
870 return AST_TEST_PASS;
885 info->name =
"stream_topology_get_first_stream_by_type";
886 info->category =
"/main/stream/";
887 info->summary =
"stream topology getting first stream by type unit test";
889 "Test that getting the first stream by type from a topology actually returns the first stream";
890 return AST_TEST_NOT_RUN;
897 ast_test_status_update(test,
"Failed to create media stream topology\n");
898 return AST_TEST_FAIL;
903 ast_test_status_update(test,
"Failed to create an audio stream for testing stream topology\n");
904 return AST_TEST_FAIL;
909 ast_test_status_update(test,
"Failed to append a perfectly good stream to a topology\n");
911 return AST_TEST_FAIL;
915 if (!second_stream) {
916 ast_test_status_update(test,
"Failed to create a second audio stream for testing stream topology\n");
917 return AST_TEST_FAIL;
921 ast_test_status_update(test,
"Failed to append a perfectly good stream to a topology\n");
923 return AST_TEST_FAIL;
928 ast_test_status_update(test,
"Failed to create a third audio stream for testing stream topology\n");
929 return AST_TEST_FAIL;
933 ast_test_status_update(test,
"Failed to append a perfectly good stream to a topology\n");
935 return AST_TEST_FAIL;
939 if (!fourth_stream) {
940 ast_test_status_update(test,
"Failed to create a video stream for testing stream topology\n");
941 return AST_TEST_FAIL;
946 ast_test_status_update(test,
"Failed to append a perfectly good stream to a topology\n");
948 return AST_TEST_FAIL;
953 ast_test_status_update(test,
"Failed to create a second video stream for testing stream topology\n");
954 return AST_TEST_FAIL;
958 ast_test_status_update(test,
"Failed to append a perfectly good stream to a topology\n");
960 return AST_TEST_FAIL;
965 ast_test_status_update(test,
"Failed to create a third video stream for testing stream topology\n");
966 return AST_TEST_FAIL;
970 ast_test_status_update(test,
"Failed to append a perfectly good stream to a topology\n");
972 return AST_TEST_FAIL;
976 ast_test_status_update(test,
"Retrieved first audio stream from topology but it is not the correct one\n");
977 return AST_TEST_FAIL;
981 ast_test_status_update(test,
"Retrieved first video stream from topology but it is not the correct one\n");
982 return AST_TEST_FAIL;
985 return AST_TEST_PASS;
996 enum ast_test_result_state res = AST_TEST_FAIL;
1002 info->name =
"stream_topology_create_from_channel_nativeformats";
1003 info->category =
"/main/stream/";
1004 info->summary =
"stream topology creation from channel native formats unit test";
1006 "Test that creating a stream topology from the setting of channel nativeformats results in the expected streams";
1007 return AST_TEST_NOT_RUN;
1014 ast_test_status_update(test,
"Could not allocate an empty format capabilities structure\n");
1015 return AST_TEST_FAIL;
1019 ast_test_status_update(test,
"Failed to append a ulaw format to capabilities for channel nativeformats\n");
1020 return AST_TEST_FAIL;
1024 ast_test_status_update(test,
"Failed to append an alaw format to capabilities for channel nativeformats\n");
1025 return AST_TEST_FAIL;
1029 ast_test_status_update(test,
"Failed to append an h264 format to capabilities for channel nativeformats\n");
1030 return AST_TEST_FAIL;
1033 mock_channel =
ast_channel_alloc(0,
AST_STATE_DOWN, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0,
"TestChannel");
1034 if (!mock_channel) {
1035 ast_test_status_update(test,
"Failed to create a mock channel for testing\n");
1036 return AST_TEST_FAIL;
1039 ast_channel_tech_set(mock_channel, &mock_channel_tech);
1040 ast_channel_nativeformats_set(mock_channel, caps);
1043 ast_test_status_update(test,
"Set nativeformats with ulaw, alaw, and h264 on channel but it did not create a topology\n");
1048 ast_test_status_update(test,
"Set nativeformats on a channel to ulaw, alaw, and h264 and received '%d' streams instead of expected 2\n",
1054 ast_test_status_update(test,
"First stream on channel is of %s when it should be audio\n",
1061 ast_test_status_update(test,
"Formats on audio stream of channel are '%s' when they should be '%s'\n",
1068 ast_test_status_update(test,
"Second stream on channel is of type %s when it should be video\n",
1076 ast_test_status_update(test,
"Failed to append h264 video codec to capabilities for capabilities comparison\n");
1081 ast_test_status_update(test,
"Formats on video stream of channel are '%s' when they should be '%s'\n",
1087 res = AST_TEST_PASS;
1090 ast_channel_unlock(mock_channel);
1099 unsigned int wrote_stream;
1104 int frames_per_read;
1105 unsigned int indicated_change_request;
1106 unsigned int indicated_changed;
1117 if (pvt->frames_per_read == 0) {
1118 pvt->frames_per_read = 1;
1120 for (i = 0; i < pvt->frames_per_read && pvt->frame_count < pvt->frame_limit; i++) {
1123 if (pvt->frame_count % 2 == 0) {
1130 f.
seqno = pvt->frame_count;
1131 f.
stream_num = pvt->frame_count % pvt->streams;
1154 static int mock_channel_indicate(
struct ast_channel *chan,
int condition,
const void *data,
size_t datalen)
1159 pvt->indicated_change_request = 1;
1161 pvt->indicated_changed = 1;
1167 static int mock_channel_write_stream(
struct ast_channel *chan,
int stream_num,
struct ast_frame *fr)
1171 pvt->wrote_stream = 1;
1172 pvt->stream_num = stream_num;
1179 .write_stream = mock_channel_write_stream,
1186 enum ast_test_result_state res = AST_TEST_PASS;
1190 info->name =
"stream_topology_channel_set";
1191 info->category =
"/main/stream/";
1192 info->summary =
"stream topology setting on a channel unit test";
1194 "Test that setting a stream topology on a channel works";
1195 return AST_TEST_NOT_RUN;
1202 ast_test_status_update(test,
"Failed to create media stream topology\n");
1203 return AST_TEST_FAIL;
1206 mock_channel =
ast_channel_alloc(0,
AST_STATE_DOWN, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0,
"TestChannel");
1207 if (!mock_channel) {
1208 ast_test_status_update(test,
"Failed to create a mock channel for testing\n");
1209 return AST_TEST_FAIL;
1212 ast_channel_tech_set(mock_channel, &mock_stream_channel_tech);
1216 ast_test_status_update(test,
"Set an explicit stream topology on a channel but the returned one did not match it\n");
1217 res = AST_TEST_FAIL;
1221 ast_channel_unlock(mock_channel);
1227 static int mock_channel_hangup(
struct ast_channel *chan)
1235 ast_channel_tech_pvt_set(chan, NULL);
1240 .
write = mock_channel_write,
1241 .write_video = mock_channel_write,
1242 .hangup = mock_channel_hangup,
1250 enum ast_test_result_state res = AST_TEST_FAIL;
1255 info->name =
"stream_write_non_multistream";
1256 info->category =
"/main/stream/";
1257 info->summary =
"stream writing to non-multistream capable channel test";
1259 "Test that writing frames to a non-multistream channel works as expected";
1260 return AST_TEST_NOT_RUN;
1267 ast_test_status_update(test,
"Could not allocate an empty format capabilities structure\n");
1268 return AST_TEST_FAIL;
1272 ast_test_status_update(test,
"Failed to append a ulaw format to capabilities for channel nativeformats\n");
1273 return AST_TEST_FAIL;
1277 ast_test_status_update(test,
"Failed to append an h264 format to capabilities for channel nativeformats\n");
1278 return AST_TEST_FAIL;
1281 mock_channel =
ast_channel_alloc(0,
AST_STATE_DOWN, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0,
"TestChannel");
1282 if (!mock_channel) {
1283 ast_test_status_update(test,
"Failed to create a mock channel for testing\n");
1284 return AST_TEST_FAIL;
1287 ast_channel_tech_set(mock_channel, &mock_channel_old_write_tech);
1288 ast_channel_nativeformats_set(mock_channel, caps);
1291 ast_channel_tech_pvt_set(mock_channel, &pvt);
1292 ast_channel_unlock(mock_channel);
1298 ast_test_status_update(test,
"Failed to write a ulaw frame to the mock channel when it should be fine\n");
1303 ast_test_status_update(test,
"Successfully wrote a frame of ulaw but it never reached the channel driver\n");
1310 ast_test_status_update(test,
"Successfully wrote a frame of ulaw to a non-existent stream\n");
1318 ast_test_status_update(test,
"Failed to write an h264 frame to the mock channel when it should be fine\n");
1323 ast_test_status_update(test,
"Successfully wrote a frame of h264 but it never reached the channel driver\n");
1327 res = AST_TEST_PASS;
1336 .
write = mock_channel_write,
1337 .write_video = mock_channel_write,
1338 .write_stream = mock_channel_write_stream,
1339 .read_stream = mock_channel_read,
1340 .hangup = mock_channel_hangup,
1350 enum ast_test_result_state res = AST_TEST_FAIL;
1355 info->name =
"stream_write_multistream";
1356 info->category =
"/main/stream/";
1357 info->summary =
"stream writing to multistream capable channel test";
1359 "Test that writing frames to a multistream channel works as expected";
1360 return AST_TEST_NOT_RUN;
1367 ast_test_status_update(test,
"Failed to create media stream topology\n");
1368 return AST_TEST_FAIL;
1373 ast_test_status_update(test,
"Failed to create an audio stream for testing multistream writing\n");
1374 return AST_TEST_FAIL;
1378 ast_test_status_update(test,
"Failed to append a perfectly good stream to a topology\n");
1380 return AST_TEST_FAIL;
1385 ast_test_status_update(test,
"Failed to create an audio stream for testing multistream writing\n");
1386 return AST_TEST_FAIL;
1390 ast_test_status_update(test,
"Failed to append a perfectly good stream to a topology\n");
1392 return AST_TEST_FAIL;
1397 ast_test_status_update(test,
"Failed to create a video stream for testing multistream writing\n");
1398 return AST_TEST_FAIL;
1402 ast_test_status_update(test,
"Failed to append a perfectly good stream to a topology\n");
1404 return AST_TEST_FAIL;
1409 ast_test_status_update(test,
"Failed to create a video stream for testing multistream writing\n");
1410 return AST_TEST_FAIL;
1414 ast_test_status_update(test,
"Failed to append a perfectly good stream to a topology\n");
1416 return AST_TEST_FAIL;
1421 ast_test_status_update(test,
"Could not allocate an empty format capabilities structure\n");
1422 return AST_TEST_FAIL;
1426 ast_test_status_update(test,
"Failed to append a ulaw format to capabilities for channel nativeformats\n");
1427 return AST_TEST_FAIL;
1431 ast_test_status_update(test,
"Failed to append an h264 format to capabilities for channel nativeformats\n");
1432 return AST_TEST_FAIL;
1435 mock_channel =
ast_channel_alloc(0,
AST_STATE_DOWN, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0,
"TestChannel");
1436 if (!mock_channel) {
1437 ast_test_status_update(test,
"Failed to create a mock channel for testing\n");
1438 return AST_TEST_FAIL;
1441 ast_channel_tech_set(mock_channel, &mock_channel_write_stream_tech);
1443 ast_channel_nativeformats_set(mock_channel, caps);
1446 ast_channel_tech_pvt_set(mock_channel, &pvt);
1447 ast_channel_unlock(mock_channel);
1451 pvt.stream_num = -1;
1454 ast_test_status_update(test,
"Failed to write a ulaw frame to the mock channel when it should be fine\n");
1459 ast_test_status_update(test,
"Successfully wrote a frame of ulaw but it ended up on the old write callback instead of write_stream\n");
1463 if (!pvt.wrote_stream) {
1464 ast_test_status_update(test,
"Successfully wrote a frame of ulaw but it never reached the channel driver\n");
1468 if (pvt.stream_num != 0) {
1469 ast_test_status_update(test,
"Successfully wrote a frame of ulaw to the default stream but it ended up on stream %d and not 0\n",
1474 pvt.wrote_stream = 0;
1475 pvt.stream_num = -1;
1478 ast_test_status_update(test,
"Failed to write a ulaw frame to the first audio stream\n");
1483 ast_test_status_update(test,
"Successfully wrote a frame of ulaw to the first audio stream but it ended up on the old write callback instead of write_stream\n");
1487 if (!pvt.wrote_stream) {
1488 ast_test_status_update(test,
"Successfully wrote a frame of ulaw to the first audio stream but it never reached the channel driver\n");
1492 if (pvt.stream_num != 0) {
1493 ast_test_status_update(test,
"Successfully wrote a frame of ulaw to the first audio stream but it ended up on stream %d and not 0\n",
1498 pvt.wrote_stream = 0;
1499 pvt.stream_num = -1;
1502 ast_test_status_update(test,
"Failed to write a ulaw frame to the second audio stream\n");
1507 ast_test_status_update(test,
"Successfully wrote a frame of ulaw to the second audio stream but it ended up on the old write callback instead of write_stream\n");
1511 if (!pvt.wrote_stream) {
1512 ast_test_status_update(test,
"Successfully wrote a frame of ulaw to the second audio stream but it never reached the channel driver\n");
1516 if (pvt.stream_num != 1) {
1517 ast_test_status_update(test,
"Successfully wrote a frame of ulaw to the second audio stream but it ended up on stream %d and not 1\n",
1522 pvt.wrote_stream = 0;
1523 pvt.stream_num = -1;
1529 ast_test_status_update(test,
"Failed to write an h264 frame to the mock channel when it should be fine\n");
1534 ast_test_status_update(test,
"Successfully wrote a frame of h264 but it ended up on the old write callback instead of write_stream\n");
1538 if (!pvt.wrote_stream) {
1539 ast_test_status_update(test,
"Successfully wrote a frame of h264 but it never reached the channel driver\n");
1543 if (pvt.stream_num != 2) {
1544 ast_test_status_update(test,
"Successfully wrote a frame of h264 to the default stream but it ended up on stream %d and not 2\n",
1549 pvt.wrote_stream = 0;
1550 pvt.stream_num = -1;
1553 ast_test_status_update(test,
"Failed to write an h264 frame to the first video stream\n");
1558 ast_test_status_update(test,
"Successfully wrote a frame of h264 to the first video stream but it ended up on the old write callback instead of write_stream\n");
1562 if (!pvt.wrote_stream) {
1563 ast_test_status_update(test,
"Successfully wrote a frame of h264 to the first video stream but it never reached the channel driver\n");
1567 if (pvt.stream_num != 2) {
1568 ast_test_status_update(test,
"Successfully wrote a frame of h264 to the first video stream but it ended up on stream %d and not 2\n",
1573 pvt.wrote_stream = 0;
1574 pvt.stream_num = -1;
1577 ast_test_status_update(test,
"Failed to write an h264 frame to the second video stream\n");
1582 ast_test_status_update(test,
"Successfully wrote a frame of h264 to the second video stream but it ended up on the old write callback instead of write_stream\n");
1586 if (!pvt.wrote_stream) {
1587 ast_test_status_update(test,
"Successfully wrote a frame of h264 to the second video stream but it never reached the channel driver\n");
1591 if (pvt.stream_num != 3) {
1592 ast_test_status_update(test,
"Successfully wrote a frame of h264 to the second video stream but it ended up on stream %d and not 3\n",
1597 pvt.wrote_stream = 0;
1598 pvt.stream_num = -1;
1601 ast_test_status_update(test,
"Successfully wrote a frame of h264 to a non-existent stream\n");
1606 ast_test_status_update(test,
"Successfully wrote a frame of h264 to a non-existent stream and it ended up on the old write callback\n");
1610 if (pvt.wrote_stream) {
1611 ast_test_status_update(test,
"Successfully wrote a frame of h264 to a non-existent stream and it ended up on the write_stream callback\n");
1615 res = AST_TEST_PASS;
1623 static int load_stream_readqueue(
struct ast_channel *chan,
int frames)
1633 for (i = 0; i < frames; i++) {
1634 if (pvt->frame_count % 2 == 0) {
1641 f.
stream_num = pvt->frame_count % pvt->streams;
1642 f.
seqno = pvt->frame_count;
1650 static struct ast_channel *make_channel(
struct ast_test *test,
int streams,
1658 enum ast_test_result_state res = AST_TEST_PASS;
1661 mock_channel =
ast_channel_alloc(0,
AST_STATE_DOWN, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0,
"TestChannel");
1662 ast_test_validate_cleanup(test, mock_channel, res, done);
1663 ast_channel_tech_set(mock_channel, tech);
1667 ast_test_validate_cleanup(test, topology, res, done);
1669 for (i = 0; i < streams; i++) {
1670 stream =
ast_stream_alloc((i % 2 ?
"video":
"audio"), (i % 2 ? AST_MEDIA_TYPE_VIDEO : AST_MEDIA_TYPE_AUDIO));
1671 ast_test_validate_cleanup(test, stream, res, done);
1679 ast_test_validate_cleanup(test, caps, res, done);
1683 ast_channel_nativeformats_set(mock_channel, caps);
1687 ast_test_validate_cleanup(test, pvt, res, done);
1689 ast_channel_tech_pvt_set(mock_channel, pvt);
1691 ast_channel_unlock(mock_channel);
1695 if (res == AST_TEST_FAIL && mock_channel) {
1699 return mock_channel;
1702 enum CHANNEL_READ_TYPE {
1709 if (rt == CHANNEL_READ_STREAM) {
1716 static enum ast_test_result_state read_test(
struct ast_test *test,
struct ast_channel_tech *tech,
1717 enum CHANNEL_READ_TYPE rt,
int streams,
int frames,
int frames_per_read,
int expected_nulls)
1722 enum ast_test_result_state res = AST_TEST_PASS;
1724 int null_frames = 0;
1726 ast_test_status_update(test,
"ChanType: %s ReadType: %s Streams: %d Frames: %d Frames per read: %d Expected Nulls: %d\n",
1728 rt == CHANNEL_READ_STREAM ?
"STREAM" :
"NON-STREAM",
1729 streams, frames, frames_per_read, expected_nulls);
1730 mock_channel = make_channel(test, 4, tech);
1731 ast_test_validate_cleanup(test, mock_channel, res, done);
1733 pvt = ast_channel_tech_pvt(mock_channel);
1734 pvt->frame_count = 0;
1735 pvt->frame_limit = frames;
1736 pvt->streams = streams;
1737 pvt->frames_per_read = frames_per_read;
1739 load_stream_readqueue(mock_channel, frames / 2);
1740 ast_channel_fdno_set(mock_channel, 0);
1742 while ((fr = read_from_chan(rt, mock_channel))) {
1743 ast_channel_fdno_set(mock_channel, 0);
1745 ast_test_validate_cleanup(test, i == fr->
seqno, res, done);
1747 ast_test_validate_cleanup(test, fr->
stream_num == ( i % streams ), res, done);
1755 ast_test_validate_cleanup(test, i == frames, res, done);
1756 ast_test_validate_cleanup(test, null_frames == expected_nulls, res, done);
1759 ast_test_status_update(test,
" Frames read: %d NULL frames: %d\n", i, null_frames);
1768 .
read = mock_channel_read,
1769 .hangup = mock_channel_hangup,
1772 enum ast_test_result_state res = AST_TEST_PASS;
1776 info->name =
"stream_read_non_multistream";
1777 info->category =
"/main/stream/";
1778 info->summary =
"stream reading from non-multistream capable channel test";
1780 "Test that reading frames from a non-multistream channel works as expected";
1781 return AST_TEST_NOT_RUN;
1786 res = read_test(test, &tech, CHANNEL_READ, 2, 16, 1, 0);
1787 ast_test_validate(test, res == AST_TEST_PASS,
"non multi, non read stream, 2 stream");
1789 res = read_test(test, &tech, CHANNEL_READ_STREAM, 2, 16, 1, 0);
1790 ast_test_validate(test, res == AST_TEST_PASS,
"non multi, read stream, 2 stream");
1792 res = read_test(test, &tech, CHANNEL_READ, 2, 16, 3, 0);
1793 ast_test_validate(test, res == AST_TEST_PASS,
"non multi, non read stream, 2 stream, 3 frames per read");
1795 res = read_test(test, &tech, CHANNEL_READ_STREAM, 2, 16, 3, 0);
1796 ast_test_validate(test, res == AST_TEST_PASS,
"non multi, read stream, 2 stream, 3 frames per read");
1805 .write_stream = mock_channel_write_stream,
1806 .hangup = mock_channel_hangup,
1808 enum ast_test_result_state res = AST_TEST_PASS;
1812 info->name =
"stream_read_multistream";
1813 info->category =
"/main/stream/";
1814 info->summary =
"stream reading from multistream capable channel test";
1816 "Test that reading frames from a multistream channel works as expected";
1817 return AST_TEST_NOT_RUN;
1822 res = read_test(test, &tech, CHANNEL_READ, 2, 16, 1, 0);
1823 ast_test_validate(test, res == AST_TEST_PASS,
"multi, non read stream, 2 stream");
1825 res = read_test(test, &tech, CHANNEL_READ_STREAM, 2, 16, 1, 0);
1826 ast_test_validate(test, res == AST_TEST_PASS,
"multi, read stream, 2 stream");
1828 res = read_test(test, &tech, CHANNEL_READ, 4, 16, 1, 8);
1829 ast_test_validate(test, res == AST_TEST_PASS,
"multi, non read stream, 4 stream");
1831 res = read_test(test, &tech, CHANNEL_READ_STREAM, 4, 16, 1, 0);
1832 ast_test_validate(test, res == AST_TEST_PASS,
"multi, read stream, 4 stream");
1834 res = read_test(test, &tech, CHANNEL_READ, 2, 16, 3, 0);
1835 ast_test_validate(test, res == AST_TEST_PASS,
"multi, non read stream, 2 stream, 3 frames per read");
1837 res = read_test(test, &tech, CHANNEL_READ_STREAM, 2, 16, 3, 0);
1838 ast_test_validate(test, res == AST_TEST_PASS,
"multi, read stream, 2 stream, 3 frames per read");
1840 res = read_test(test, &tech, CHANNEL_READ, 4, 16, 3, 8);
1841 ast_test_validate(test, res == AST_TEST_PASS,
"multi, non read stream, 4 stream, 3 frames per read");
1843 res = read_test(test, &tech, CHANNEL_READ_STREAM, 4, 16, 3, 0);
1844 ast_test_validate(test, res == AST_TEST_PASS,
"multi, read stream, 4 stream, 3 frames per read");
1849 AST_TEST_DEFINE(stream_topology_change_request_from_application_non_multistream)
1852 .
read = mock_channel_read,
1853 .indicate = mock_channel_indicate,
1854 .hangup = mock_channel_hangup,
1858 enum ast_test_result_state res = AST_TEST_PASS;
1864 info->name =
"stream_topology_change_request_from_application_non_multistream";
1865 info->category =
"/main/stream/";
1866 info->summary =
"stream topology changing on non-multistream channel test";
1868 "Test that an application trying to change the stream topology of a non-multistream channel gets a failure";
1869 return AST_TEST_NOT_RUN;
1874 mock_channel = make_channel(test, 1, &tech);
1875 ast_test_validate_cleanup(test, mock_channel, res, done);
1877 pvt = ast_channel_tech_pvt(mock_channel);
1878 pvt->indicated_change_request = 0;
1879 pvt->indicated_changed = 0;
1882 ast_test_validate_cleanup(test, topology, res, done);
1886 ast_test_validate_cleanup(test, change_res == -1, res, done);
1887 ast_test_validate_cleanup(test, !pvt->indicated_change_request, res, done);
1889 ast_channel_lock(mock_channel);
1891 ast_channel_unlock(mock_channel);
1893 ast_test_validate_cleanup(test, change_res == -1, res, done);
1894 ast_test_validate_cleanup(test, !pvt->indicated_changed, res, done);
1902 AST_TEST_DEFINE(stream_topology_change_request_from_channel_non_multistream)
1906 .write_stream = mock_channel_write_stream,
1907 .indicate = mock_channel_indicate,
1908 .hangup = mock_channel_hangup,
1912 enum ast_test_result_state res = AST_TEST_PASS;
1922 info->name =
"stream_topology_change_request_from_channel_non_multistream";
1923 info->category =
"/main/stream/";
1924 info->summary =
"channel requesting stream topology change to non-multistream application test";
1926 "Test that a channel requesting a stream topology change from a non-multistream application does not work";
1927 return AST_TEST_NOT_RUN;
1932 mock_channel = make_channel(test, 1, &tech);
1933 ast_test_validate_cleanup(test, mock_channel, res, done);
1935 pvt = ast_channel_tech_pvt(mock_channel);
1936 pvt->indicated_changed = 0;
1939 ast_test_validate_cleanup(test, topology, res, done);
1941 request_change.
data.ptr = topology;
1945 ast_test_validate_cleanup(test, fr, res, done);
1946 ast_test_validate_cleanup(test, fr == &
ast_null_frame, res, done);
1947 ast_test_validate_cleanup(test, pvt->indicated_changed, res, done);
1962 .write_stream = mock_channel_write_stream,
1963 .indicate = mock_channel_indicate,
1964 .hangup = mock_channel_hangup,
1968 enum ast_test_result_state res = AST_TEST_PASS;
1974 info->name =
"stream_topology_change_request_from_application";
1975 info->category =
"/main/stream/";
1976 info->summary =
"stream topology change request from application test";
1978 "Test that an application changing the stream topology of a multistream capable channel receives success";
1979 return AST_TEST_NOT_RUN;
1984 mock_channel = make_channel(test, 1, &tech);
1985 ast_test_validate_cleanup(test, mock_channel, res, done);
1987 pvt = ast_channel_tech_pvt(mock_channel);
1988 pvt->indicated_change_request = 0;
1989 pvt->indicated_changed = 0;
1992 ast_test_validate_cleanup(test, topology, res, done);
1996 ast_test_validate_cleanup(test, !change_res, res, done);
1997 ast_test_validate_cleanup(test, pvt->indicated_change_request, res, done);
1999 ast_channel_lock(mock_channel);
2001 ast_channel_unlock(mock_channel);
2003 ast_test_validate_cleanup(test, !change_res, res, done);
2004 ast_test_validate_cleanup(test, pvt->indicated_changed, res, done);
2016 .write_stream = mock_channel_write_stream,
2017 .indicate = mock_channel_indicate,
2018 .hangup = mock_channel_hangup,
2022 enum ast_test_result_state res = AST_TEST_PASS;
2032 info->name =
"stream_topology_change_request_from_channel";
2033 info->category =
"/main/stream/";
2034 info->summary =
"channel requesting stream topology change to multistream application test";
2036 "Test that a channel requesting a stream topology change from a multistream application works";
2037 return AST_TEST_NOT_RUN;
2042 mock_channel = make_channel(test, 1, &tech);
2043 ast_test_validate_cleanup(test, mock_channel, res, done);
2045 pvt = ast_channel_tech_pvt(mock_channel);
2046 pvt->indicated_changed = 0;
2049 ast_test_validate_cleanup(test, topology, res, done);
2051 request_change.
data.ptr = topology;
2055 ast_test_validate_cleanup(test, fr, res, done);
2058 ast_test_validate_cleanup(test, !pvt->indicated_changed, res, done);
2079 info->name =
"format_cap_from_stream_topology";
2080 info->category =
"/main/stream/";
2081 info->summary =
"stream topology to format capabilities conversion test";
2083 "Test that converting a stream topology to format capabilities results in expected formats";
2084 return AST_TEST_NOT_RUN;
2091 ast_test_status_update(test,
"Could not allocate an empty format capabilities structure\n");
2092 return AST_TEST_FAIL;
2096 ast_test_status_update(test,
"Failed to append ulaw format to capabilities\n");
2097 return AST_TEST_FAIL;
2101 ast_test_status_update(test,
"Failed to append h264 format to capabilities\n");
2102 return AST_TEST_FAIL;
2107 ast_test_status_update(test,
"Failed to create a stream topology from format capabilities of ulaw and h264\n");
2108 return AST_TEST_FAIL;
2117 ast_test_status_update(test,
"Failed to create an audio stream for testing stream topology\n");
2119 return AST_TEST_FAIL;
2124 ast_test_status_update(test,
"Could not allocate an empty format capabilities structure\n");
2127 return AST_TEST_FAIL;
2130 ast_test_status_update(test,
"Failed to append alaw format to capabilities\n");
2131 ao2_cleanup(new_cap);
2134 return AST_TEST_FAIL;
2137 ao2_cleanup(new_cap);
2139 ast_test_status_update(test,
"Failed to append a perfectly good stream to a topology\n");
2142 return AST_TEST_FAIL;
2147 ast_test_status_update(test,
"Failed to create a format capabilities from a stream topology\n");
2149 return AST_TEST_FAIL;
2155 ast_test_status_update(test,
"Converting format capabilities into topology and back resulted in different formats\n");
2156 return AST_TEST_FAIL;
2159 return AST_TEST_PASS;
2162 #define topology_append_stream(topology, name, type, res, label) \
2164 struct ast_stream *__stream = ast_stream_alloc((name), (type)); \
2165 ast_test_validate_cleanup(test, __stream, res, label); \
2166 if (ast_stream_topology_append_stream((topology), __stream) < 0) { \
2167 ast_stream_free(__stream); \
2168 res = AST_TEST_FAIL; \
2181 enum ast_test_result_state res = AST_TEST_PASS;
2185 info->name =
"stream_topology_map_create";
2186 info->category =
"/main/stream/";
2187 info->summary =
"stream topology map creation unit test";
2189 "Test that creating a stream topology map works";
2190 return AST_TEST_NOT_RUN;
2199 topology_append_stream(t0,
"audio", AST_MEDIA_TYPE_AUDIO, res, done);
2200 topology_append_stream(t0,
"video", AST_MEDIA_TYPE_VIDEO, res, done);
2203 ast_test_validate_cleanup(test,
AST_VECTOR_SIZE(&types) == 2, res, done);
2204 ast_test_validate_cleanup(test,
AST_VECTOR_GET(&types, 0) == AST_MEDIA_TYPE_AUDIO, res, done);
2205 ast_test_validate_cleanup(test,
AST_VECTOR_GET(&types, 1) == AST_MEDIA_TYPE_VIDEO, res, done);
2206 ast_test_validate_cleanup(test,
AST_VECTOR_GET(&v0, 0) == 0, res, done);
2207 ast_test_validate_cleanup(test,
AST_VECTOR_GET(&v0, 1) == 1, res, done);
2208 ast_test_validate_cleanup(test,
AST_VECTOR_GET(&v1, 0) == 0, res, done);
2209 ast_test_validate_cleanup(test,
AST_VECTOR_GET(&v1, 1) == 1, res, done);
2214 topology_append_stream(t0,
"video", AST_MEDIA_TYPE_VIDEO, res, done);
2215 topology_append_stream(t0,
"audio", AST_MEDIA_TYPE_AUDIO, res, done);
2218 ast_test_validate_cleanup(test,
AST_VECTOR_SIZE(&types) == 2, res, done);
2219 ast_test_validate_cleanup(test,
AST_VECTOR_GET(&types, 0) == AST_MEDIA_TYPE_AUDIO, res, done);
2220 ast_test_validate_cleanup(test,
AST_VECTOR_GET(&types, 1) == AST_MEDIA_TYPE_VIDEO, res, done);
2221 ast_test_validate_cleanup(test,
AST_VECTOR_GET(&v0, 0) == 1, res, done);
2222 ast_test_validate_cleanup(test,
AST_VECTOR_GET(&v0, 1) == 0, res, done);
2223 ast_test_validate_cleanup(test,
AST_VECTOR_GET(&v1, 0) == 1, res, done);
2224 ast_test_validate_cleanup(test,
AST_VECTOR_GET(&v1, 1) == 0, res, done);
2229 topology_append_stream(t0,
"video", AST_MEDIA_TYPE_VIDEO, res, done);
2230 topology_append_stream(t0,
"audio", AST_MEDIA_TYPE_AUDIO, res, done);
2231 topology_append_stream(t0,
"audio", AST_MEDIA_TYPE_AUDIO, res, done);
2234 ast_test_validate_cleanup(test,
AST_VECTOR_SIZE(&types) == 3, res, done);
2235 ast_test_validate_cleanup(test,
AST_VECTOR_GET(&types, 0) == AST_MEDIA_TYPE_AUDIO, res, done);
2236 ast_test_validate_cleanup(test,
AST_VECTOR_GET(&types, 1) == AST_MEDIA_TYPE_VIDEO, res, done);
2237 ast_test_validate_cleanup(test,
AST_VECTOR_GET(&types, 2) == AST_MEDIA_TYPE_AUDIO, res, done);
2238 ast_test_validate_cleanup(test,
AST_VECTOR_GET(&v0, 0) == 1, res, done);
2239 ast_test_validate_cleanup(test,
AST_VECTOR_GET(&v0, 1) == 0, res, done);
2240 ast_test_validate_cleanup(test,
AST_VECTOR_GET(&v0, 2) == 2, res, done);
2241 ast_test_validate_cleanup(test,
AST_VECTOR_GET(&v1, 0) == 1, res, done);
2242 ast_test_validate_cleanup(test,
AST_VECTOR_GET(&v1, 1) == 0, res, done);
2243 ast_test_validate_cleanup(test,
AST_VECTOR_GET(&v1, 2) == 2, res, done);
2253 static int unload_module(
void)
2255 AST_TEST_UNREGISTER(stream_create);
2256 AST_TEST_UNREGISTER(stream_create_no_name);
2257 AST_TEST_UNREGISTER(stream_set_type);
2258 AST_TEST_UNREGISTER(stream_set_formats);
2259 AST_TEST_UNREGISTER(stream_set_state);
2260 AST_TEST_UNREGISTER(stream_metadata);
2261 AST_TEST_UNREGISTER(stream_topology_create);
2262 AST_TEST_UNREGISTER(stream_topology_clone);
2263 AST_TEST_UNREGISTER(stream_topology_clone);
2264 AST_TEST_UNREGISTER(stream_topology_append_stream);
2265 AST_TEST_UNREGISTER(stream_topology_set_stream);
2266 AST_TEST_UNREGISTER(stream_topology_del_stream);
2267 AST_TEST_UNREGISTER(stream_topology_create_from_format_cap);
2268 AST_TEST_UNREGISTER(stream_topology_get_first_stream_by_type);
2269 AST_TEST_UNREGISTER(stream_topology_create_from_channel_nativeformats);
2270 AST_TEST_UNREGISTER(stream_topology_channel_set);
2271 AST_TEST_UNREGISTER(stream_write_non_multistream);
2272 AST_TEST_UNREGISTER(stream_write_multistream);
2273 AST_TEST_UNREGISTER(stream_read_non_multistream);
2274 AST_TEST_UNREGISTER(stream_read_multistream);
2275 AST_TEST_UNREGISTER(stream_topology_change_request_from_application_non_multistream);
2276 AST_TEST_UNREGISTER(stream_topology_change_request_from_channel_non_multistream);
2277 AST_TEST_UNREGISTER(stream_topology_change_request_from_application);
2278 AST_TEST_UNREGISTER(stream_topology_change_request_from_channel);
2279 AST_TEST_UNREGISTER(format_cap_from_stream_topology);
2280 AST_TEST_UNREGISTER(stream_topology_map_create);
2284 static int load_module(
void)
2286 AST_TEST_REGISTER(stream_create);
2287 AST_TEST_REGISTER(stream_create_no_name);
2288 AST_TEST_REGISTER(stream_set_type);
2289 AST_TEST_REGISTER(stream_set_formats);
2290 AST_TEST_REGISTER(stream_set_state);
2291 AST_TEST_REGISTER(stream_metadata);
2292 AST_TEST_REGISTER(stream_topology_create);
2293 AST_TEST_REGISTER(stream_topology_clone);
2294 AST_TEST_REGISTER(stream_topology_append_stream);
2295 AST_TEST_REGISTER(stream_topology_set_stream);
2296 AST_TEST_REGISTER(stream_topology_del_stream);
2297 AST_TEST_REGISTER(stream_topology_create_from_format_cap);
2298 AST_TEST_REGISTER(stream_topology_get_first_stream_by_type);
2299 AST_TEST_REGISTER(stream_topology_create_from_channel_nativeformats);
2300 AST_TEST_REGISTER(stream_topology_channel_set);
2301 AST_TEST_REGISTER(stream_write_non_multistream);
2302 AST_TEST_REGISTER(stream_write_multistream);
2303 AST_TEST_REGISTER(stream_read_non_multistream);
2304 AST_TEST_REGISTER(stream_read_multistream);
2305 AST_TEST_REGISTER(stream_topology_change_request_from_application_non_multistream);
2306 AST_TEST_REGISTER(stream_topology_change_request_from_channel_non_multistream);
2307 AST_TEST_REGISTER(stream_topology_change_request_from_application);
2308 AST_TEST_REGISTER(stream_topology_change_request_from_channel);
2309 AST_TEST_REGISTER(format_cap_from_stream_topology);
2310 AST_TEST_REGISTER(stream_topology_map_create);
2314 AST_MODULE_INFO_STANDARD(
ASTERISK_GPL_KEY,
"Media Stream API test module");
#define AST_VECTOR_FREE(vec)
Deallocates this vector.
Main Channel structure associated with a channel.
#define ast_frdup(fr)
Copies a frame.
Asterisk main include file. File version handling, generic pbx functions.
struct ast_stream_topology * ast_channel_get_stream_topology(const struct ast_channel *chan)
Retrieve the topology of streams on a channel.
struct ast_format_cap * ast_stream_topology_get_formats(struct ast_stream_topology *topology)
Create a format capabilities structure representing the topology.
int(*const write)(struct ast_channel *chan, struct ast_frame *frame)
Write a frame, in standard format (see frame.h)
enum ast_media_type ast_stream_get_type(const struct ast_stream *stream)
Get the media type of a stream.
const char * ast_codec_media_type2str(enum ast_media_type type)
Conversion function to take a media type and turn it into a string.
struct ast_frame *(*const read_stream)(struct ast_channel *chan)
Read a frame (or chain of frames from the same stream), in standard format (see frame.h), with stream num.
Universally unique identifier support.
struct ast_frame::@225 frame_list
Set when the stream has been removed/declined.
struct ast_frame * ast_read(struct ast_channel *chan)
Reads a frame.
struct ast_frame * ast_read_stream(struct ast_channel *chan)
Reads a frame, but does not filter to just the default streams.
struct ast_stream_topology * ast_stream_topology_create_from_format_cap(struct ast_format_cap *cap)
A helper function that, given a format capabilities structure, creates a topology and separates the m...
Set when the stream is not sending OR receiving media.
int ast_channel_request_stream_topology_change(struct ast_channel *chan, struct ast_stream_topology *topology, void *change_source)
Request that the stream topology of a channel change.
struct ast_stream * ast_stream_topology_get_stream(const struct ast_stream_topology *topology, unsigned int position)
Get a specific stream from the topology.
int ast_stream_topology_append_stream(struct ast_stream_topology *topology, struct ast_stream *stream)
Append a stream to the topology.
void ast_stream_set_formats(struct ast_stream *stream, struct ast_format_cap *caps)
Set the current negotiated formats of a stream.
int ast_stream_topology_set_stream(struct ast_stream_topology *topology, unsigned int position, struct ast_stream *stream)
Set a specific position in a topology.
int ast_write_stream(struct ast_channel *chan, int stream_num, struct ast_frame *frame)
Write a frame to a stream This function writes the given frame to the indicated stream on the channel...
struct ast_frame_subclass subclass
const struct ast_channel_tech * tech
#define AST_VECTOR_INIT(vec, size)
Initialize a vector.
struct ast_stream * ast_stream_topology_get_first_stream_by_type(const struct ast_stream_topology *topology, enum ast_media_type type)
Gets the first active stream of a specific type from the topology.
General Asterisk PBX channel definitions.
enum ast_media_type type
The type of media the stream is handling.
#define AST_LIST_REMOVE_HEAD(head, field)
Removes and returns the head entry from a list.
const struct ast_format_cap * ast_stream_get_formats(const struct ast_stream *stream)
Get the current negotiated formats of a stream.
Structure to describe a channel "technology", ie a channel driver See for examples: ...
int ast_queue_frame(struct ast_channel *chan, struct ast_frame *f)
Queue one or more frames to a channel's frame queue.
Set when the stream is sending and receiving media.
int ast_channel_stream_topology_changed(struct ast_channel *chan, struct ast_stream_topology *topology)
Provide notice to a channel that the stream topology has changed.
struct ast_stream_topology * ast_channel_set_stream_topology(struct ast_channel *chan, struct ast_stream_topology *topology)
Set the topology of streams on a channel.
void ast_stream_set_type(struct ast_stream *stream, enum ast_media_type type)
Change the media type of a stream.
Support for dynamic strings.
struct ast_stream_topology * ast_stream_topology_alloc(void)
Create a stream topology.
union ast_frame::@224 data
#define ast_calloc(num, len)
A wrapper for calloc()
void ast_hangup(struct ast_channel *chan)
Hang up a channel.
void ast_stream_set_state(struct ast_stream *stream, enum ast_stream_state state)
Set the state of a stream.
char * ast_uuid_generate_str(char *buf, size_t size)
Generate a UUID string.
int ast_write(struct ast_channel *chan, struct ast_frame *frame)
Write a frame to a channel This function writes the given frame to the indicated channel.
int ast_stream_topology_get_count(const struct ast_stream_topology *topology)
Get the number of streams in a topology.
struct ast_frame *(*const read)(struct ast_channel *chan)
Read a frame (or chain of frames from the same stream), in standard format (see frame.h)
struct ast_stream_topology * ast_stream_topology_clone(const struct ast_stream_topology *topology)
Create a deep clone of an existing stream topology.
struct ast_frame ast_null_frame
void ast_stream_free(struct ast_stream *stream)
Destroy a media stream representation.
#define AST_VECTOR_GET(vec, idx)
Get an element from a vector.
struct ast_stream * ast_stream_alloc(const char *name, enum ast_media_type type)
Create a new media stream representation.
int ast_stream_set_metadata(struct ast_stream *stream, const char *m_key, const char *value)
Set a stream metadata value.
const char * ast_stream_get_metadata(const struct ast_stream *stream, const char *m_key)
Get a stream metadata value.
Data structure associated with a single frame of data.
#define AST_TEST_DEFINE(hdr)
ast_media_type
Types of media.
void ast_stream_topology_map(const struct ast_stream_topology *topology, struct ast_vector_int *types, struct ast_vector_int *v0, struct ast_vector_int *v1)
Map a given topology's streams to the given types.
enum ast_frame_type frametype
struct ast_format * format
void ast_stream_topology_free(struct ast_stream_topology *topology)
Unreference and destroy a stream topology.
int ast_stream_get_position(const struct ast_stream *stream)
Get the position of the stream in the topology.
const char * ast_stream_get_name(const struct ast_stream *stream)
Get the name of a stream.
#define ASTERISK_GPL_KEY
The text the key() function should return.
#define ast_channel_alloc(needqueue, state, cid_num, cid_name, acctcode, exten, context, assignedids, requestor, amaflag,...)
Create a channel structure.
Asterisk module definitions.
#define RAII_VAR(vartype, varname, initval, dtor)
Declare a variable that will call a destructor function when it goes out of scope.
Integer vector definition.
int ast_stream_topology_del_stream(struct ast_stream_topology *topology, unsigned int position)
Delete a specified stream from the given topology.
enum ast_stream_state ast_stream_get_state(const struct ast_stream *stream)
Get the current state of a stream.
#define AST_VECTOR_SIZE(vec)
Get the number of elements in a vector.
unsigned int position
The position of the stream in the topology.