test_oss_live.c 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674
  1. #include "CuTest.h"
  2. #include "aos_log.h"
  3. #include "aos_util.h"
  4. #include "aos_string.h"
  5. #include "aos_status.h"
  6. #include "aos_transport.h"
  7. #include "aos_http_io.h"
  8. #include "oss_auth.h"
  9. #include "oss_util.h"
  10. #include "oss_xml.h"
  11. #include "oss_api.h"
  12. #include "oss_config.h"
  13. #include "oss_test_util.h"
  14. #include "apr_time.h"
  15. void test_live_setup(CuTest *tc)
  16. {
  17. aos_pool_t *p = NULL;
  18. int is_cname = 0;
  19. aos_status_t *s = NULL;
  20. oss_request_options_t *options = NULL;
  21. oss_acl_e oss_acl = OSS_ACL_PRIVATE;
  22. //create test bucket
  23. aos_pool_create(&p, NULL);
  24. options = oss_request_options_create(p);
  25. init_test_request_options(options, is_cname);
  26. s = create_test_bucket(options, TEST_BUCKET_NAME, oss_acl);
  27. CuAssertIntEquals(tc, 200, s->code);
  28. aos_pool_destroy(p);
  29. }
  30. void test_live_cleanup(CuTest *tc)
  31. {
  32. aos_pool_t *p = NULL;
  33. int is_cname = 0;
  34. aos_string_t bucket;
  35. oss_request_options_t *options = NULL;
  36. aos_table_t *resp_headers = NULL;
  37. aos_pool_create(&p, NULL);
  38. options = oss_request_options_create(p);
  39. init_test_request_options(options, is_cname);
  40. //delete test bucket
  41. aos_str_set(&bucket, TEST_BUCKET_NAME);
  42. oss_delete_bucket(options, &bucket, &resp_headers);
  43. apr_sleep(apr_time_from_sec(3));
  44. aos_pool_destroy(p);
  45. }
  46. void test_create_live_channel_default(CuTest *tc)
  47. {
  48. aos_pool_t *p = NULL;
  49. oss_request_options_t *options = NULL;
  50. aos_status_t *s = NULL;
  51. aos_list_t publish_url_list;
  52. aos_list_t play_url_list;
  53. oss_live_channel_configuration_t *config = NULL;
  54. oss_live_channel_configuration_t info;
  55. char *live_channel_name = "test_live_channel_create_def";
  56. char *live_channel_desc = "my test live channel";
  57. aos_string_t bucket;
  58. aos_string_t channel_name;
  59. oss_live_channel_publish_url_t *publish_url;
  60. oss_live_channel_play_url_t *play_url;
  61. char *content = NULL;
  62. aos_pool_create(&p, NULL);
  63. options = oss_request_options_create(p);
  64. init_test_request_options(options, 0);
  65. aos_str_set(&bucket, TEST_BUCKET_NAME);
  66. aos_str_set(&channel_name, live_channel_name);
  67. config = oss_create_live_channel_configuration_content(options->pool);
  68. aos_str_set(&config->name, live_channel_name);
  69. aos_str_set(&config->description, live_channel_desc);
  70. // create
  71. aos_list_init(&publish_url_list);
  72. aos_list_init(&play_url_list);
  73. s = oss_create_live_channel(options, &bucket, config, &publish_url_list,
  74. &play_url_list, NULL);
  75. CuAssertIntEquals(tc, 200, s->code);
  76. aos_list_for_each_entry(oss_live_channel_publish_url_t, publish_url, &publish_url_list, node) {
  77. content = apr_psprintf(p, "%.*s", publish_url->publish_url.len,
  78. publish_url->publish_url.data);
  79. CuAssertStrnEquals(tc, AOS_RTMP_PREFIX, strlen(AOS_RTMP_PREFIX), content);
  80. CuAssertIntEquals(tc, 1, aos_ends_with(&publish_url->publish_url, &channel_name));
  81. }
  82. aos_list_for_each_entry(oss_live_channel_play_url_t, play_url, &play_url_list, node) {
  83. content = apr_psprintf(p, "%.*s", play_url->play_url.len,
  84. play_url->play_url.data);
  85. CuAssertStrnEquals(tc, AOS_HTTP_PREFIX, strlen(AOS_HTTP_PREFIX), content);
  86. CuAssertIntEquals(tc, 1, aos_ends_with(&play_url->play_url, &config->target.play_list_name));
  87. }
  88. // get info
  89. s = oss_get_live_channel_info(options, &bucket, &channel_name, &info, NULL);
  90. CuAssertIntEquals(tc, 200, s->code);
  91. content = apr_psprintf(p, "%.*s", info.name.len, info.name.data);
  92. CuAssertStrEquals(tc, live_channel_name, content);
  93. content = apr_psprintf(p, "%.*s", info.description.len, info.description.data);
  94. CuAssertStrEquals(tc, live_channel_desc, content);
  95. content = apr_psprintf(p, "%.*s", info.status.len, info.status.data);
  96. CuAssertStrEquals(tc, LIVE_CHANNEL_STATUS_ENABLED, content);
  97. content = apr_psprintf(p, "%.*s", info.target.type.len, info.target.type.data);
  98. CuAssertStrEquals(tc, LIVE_CHANNEL_DEFAULT_TYPE, content);
  99. content = apr_psprintf(p, "%.*s", info.target.play_list_name.len, info.target.play_list_name.data);
  100. CuAssertStrEquals(tc, LIVE_CHANNEL_DEFAULT_PLAYLIST, content);
  101. CuAssertIntEquals(tc, LIVE_CHANNEL_DEFAULT_FRAG_DURATION, info.target.frag_duration);
  102. CuAssertIntEquals(tc, LIVE_CHANNEL_DEFAULT_FRAG_COUNT, info.target.frag_count);
  103. // delete
  104. s = oss_delete_live_channel(options, &bucket, &channel_name, NULL);
  105. CuAssertIntEquals(tc, 204, s->code);
  106. aos_pool_destroy(p);
  107. printf("test_create_live_channel_default ok\n");
  108. }
  109. void test_create_live_channel(CuTest *tc)
  110. {
  111. aos_pool_t *p = NULL;
  112. oss_request_options_t *options = NULL;
  113. aos_status_t *s = NULL;
  114. aos_list_t publish_url_list;
  115. aos_list_t play_url_list;
  116. oss_live_channel_configuration_t *config = NULL;
  117. oss_live_channel_configuration_t info;
  118. char *live_channel_name = "test_live_channel_create";
  119. char *live_channel_desc = "my test live channel,<>{}=?//&";
  120. aos_string_t bucket;
  121. aos_string_t channel_name;
  122. oss_live_channel_publish_url_t *publish_url;
  123. oss_live_channel_play_url_t *play_url;
  124. aos_table_t *resp_headers = NULL;
  125. char *content = NULL;
  126. aos_pool_create(&p, NULL);
  127. options = oss_request_options_create(p);
  128. init_test_request_options(options, 0);
  129. aos_str_set(&bucket, TEST_BUCKET_NAME);
  130. aos_str_set(&channel_name, live_channel_name);
  131. config = oss_create_live_channel_configuration_content(options->pool);
  132. aos_str_set(&config->name, live_channel_name);
  133. aos_str_set(&config->description, live_channel_desc);
  134. aos_str_set(&config->status, LIVE_CHANNEL_STATUS_DISABLED);
  135. aos_str_set(&config->target.type, "HLS");
  136. aos_str_set(&config->target.play_list_name, "myplay.m3u8");
  137. config->target.frag_duration = 100;
  138. config->target.frag_count = 99;
  139. // create
  140. aos_list_init(&publish_url_list);
  141. aos_list_init(&play_url_list);
  142. s = oss_create_live_channel(options, &bucket, config, &publish_url_list,
  143. &play_url_list, &resp_headers);
  144. CuAssertIntEquals(tc, 200, s->code);
  145. CuAssertPtrNotNull(tc, resp_headers);
  146. aos_list_for_each_entry(oss_live_channel_publish_url_t, publish_url, &publish_url_list, node) {
  147. content = apr_psprintf(p, "%.*s", publish_url->publish_url.len,
  148. publish_url->publish_url.data);
  149. CuAssertStrnEquals(tc, AOS_RTMP_PREFIX, strlen(AOS_RTMP_PREFIX), content);
  150. CuAssertIntEquals(tc, 1, aos_ends_with(&publish_url->publish_url, &channel_name));
  151. }
  152. aos_list_for_each_entry(oss_live_channel_play_url_t, play_url, &play_url_list, node) {
  153. content = apr_psprintf(p, "%.*s", play_url->play_url.len,
  154. play_url->play_url.data);
  155. CuAssertStrnEquals(tc, AOS_HTTP_PREFIX, strlen(AOS_HTTP_PREFIX), content);
  156. CuAssertIntEquals(tc, 1, aos_ends_with(&play_url->play_url, &config->target.play_list_name));
  157. }
  158. // get info
  159. s = oss_get_live_channel_info(options, &bucket, &channel_name, &info, NULL);
  160. CuAssertIntEquals(tc, 200, s->code);
  161. content = apr_psprintf(p, "%.*s", info.name.len, info.name.data);
  162. CuAssertStrEquals(tc, live_channel_name, content);
  163. content = apr_psprintf(p, "%.*s", info.description.len, info.description.data);
  164. CuAssertStrEquals(tc, live_channel_desc, content);
  165. content = apr_psprintf(p, "%.*s", info.status.len, info.status.data);
  166. CuAssertStrEquals(tc, LIVE_CHANNEL_STATUS_DISABLED, content);
  167. content = apr_psprintf(p, "%.*s", info.target.type.len, info.target.type.data);
  168. CuAssertStrEquals(tc, "HLS", content);
  169. content = apr_psprintf(p, "%.*s", info.target.play_list_name.len, info.target.play_list_name.data);
  170. CuAssertStrEquals(tc, "myplay.m3u8", content);
  171. CuAssertIntEquals(tc, 100, info.target.frag_duration);
  172. CuAssertIntEquals(tc, 99, info.target.frag_count);
  173. // delete
  174. s = oss_delete_live_channel(options, &bucket, &channel_name, NULL);
  175. CuAssertIntEquals(tc, 204, s->code);
  176. aos_pool_destroy(p);
  177. printf("test_create_live_channel ok\n");
  178. }
  179. void test_get_live_channel_stat(CuTest *tc)
  180. {
  181. aos_pool_t *p = NULL;
  182. oss_request_options_t *options = NULL;
  183. aos_status_t *s = NULL;
  184. aos_list_t publish_url_list;
  185. aos_list_t play_url_list;
  186. oss_live_channel_configuration_t *config = NULL;
  187. oss_live_channel_stat_t live_stat;
  188. char *live_channel_name = "test_live_channel_stat";
  189. char *live_channel_desc = "my test live channel";
  190. aos_string_t bucket;
  191. aos_string_t channel_name;
  192. char *content = NULL;
  193. aos_pool_create(&p, NULL);
  194. options = oss_request_options_create(p);
  195. init_test_request_options(options, 0);
  196. aos_str_set(&bucket, TEST_BUCKET_NAME);
  197. aos_str_set(&channel_name, live_channel_name);
  198. config = oss_create_live_channel_configuration_content(options->pool);
  199. aos_str_set(&config->name, live_channel_name);
  200. aos_str_set(&config->description, live_channel_desc);
  201. // create
  202. aos_list_init(&publish_url_list);
  203. aos_list_init(&play_url_list);
  204. s = oss_create_live_channel(options, &bucket, config, &publish_url_list,
  205. &play_url_list, NULL);
  206. CuAssertIntEquals(tc, 200, s->code);
  207. // get stat
  208. s = oss_get_live_channel_stat(options, &bucket, &channel_name, &live_stat, NULL);
  209. CuAssertIntEquals(tc, 200, s->code);
  210. content = apr_psprintf(p, "%.*s", live_stat.pushflow_status.len, live_stat.pushflow_status.data);
  211. CuAssertStrEquals(tc, "Idle", content);
  212. s = oss_delete_live_channel(options, &bucket, &channel_name, NULL);
  213. CuAssertIntEquals(tc, 204, s->code);
  214. aos_pool_destroy(p);
  215. printf("test_get_live_channel_stat ok\n");
  216. }
  217. void test_put_live_channel_status(CuTest *tc)
  218. {
  219. aos_pool_t *p = NULL;
  220. oss_request_options_t *options = NULL;
  221. aos_status_t *s = NULL;
  222. char *live_channel_name = "test_live_channel_status";
  223. aos_string_t bucket;
  224. aos_string_t channel_name;
  225. aos_string_t channel_stutus;
  226. oss_live_channel_configuration_t info;
  227. char *content = NULL;
  228. aos_pool_create(&p, NULL);
  229. options = oss_request_options_create(p);
  230. init_test_request_options(options, 0);
  231. aos_str_set(&bucket, TEST_BUCKET_NAME);
  232. aos_str_set(&channel_name, live_channel_name);
  233. // create
  234. s = create_test_live_channel(options, TEST_BUCKET_NAME, live_channel_name);
  235. CuAssertIntEquals(tc, 200, s->code);
  236. // put status
  237. aos_str_set(&channel_stutus, LIVE_CHANNEL_STATUS_DISABLED);
  238. s= oss_put_live_channel_status(options, &bucket, &channel_name, &channel_stutus, NULL);
  239. CuAssertIntEquals(tc, 200, s->code);
  240. // check by get info
  241. s = oss_get_live_channel_info(options, &bucket, &channel_name, &info, NULL);
  242. CuAssertIntEquals(tc, 200, s->code);
  243. content = apr_psprintf(p, "%.*s", info.name.len, info.name.data);
  244. CuAssertStrEquals(tc, live_channel_name, content);
  245. content = apr_psprintf(p, "%.*s", info.status.len, info.status.data);
  246. CuAssertStrEquals(tc, LIVE_CHANNEL_STATUS_DISABLED, content);
  247. // put status
  248. aos_str_set(&channel_stutus, LIVE_CHANNEL_STATUS_ENABLED);
  249. s= oss_put_live_channel_status(options, &bucket, &channel_name, &channel_stutus, NULL);
  250. CuAssertIntEquals(tc, 200, s->code);
  251. // check by get info
  252. s = oss_get_live_channel_info(options, &bucket, &channel_name, &info, NULL);
  253. CuAssertIntEquals(tc, 200, s->code);
  254. content = apr_psprintf(p, "%.*s", info.name.len, info.name.data);
  255. CuAssertStrEquals(tc, live_channel_name, content);
  256. content = apr_psprintf(p, "%.*s", info.status.len, info.status.data);
  257. CuAssertStrEquals(tc, LIVE_CHANNEL_STATUS_ENABLED, content);
  258. // delete
  259. s = oss_delete_live_channel(options, &bucket, &channel_name, NULL);
  260. CuAssertIntEquals(tc, 204, s->code);
  261. aos_pool_destroy(p);
  262. printf("test_put_live_channel_status ok\n");
  263. }
  264. void test_delete_live_channel(CuTest *tc)
  265. {
  266. aos_pool_t *p = NULL;
  267. oss_request_options_t *options = NULL;
  268. aos_status_t *s = NULL;
  269. aos_list_t publish_url_list;
  270. aos_list_t play_url_list;
  271. oss_live_channel_configuration_t *config = NULL;
  272. oss_live_channel_stat_t live_stat;
  273. char *live_channel_name = "test_live_channel_del";
  274. char *live_channel_desc = "my test live channel";
  275. aos_string_t bucket;
  276. aos_string_t channel_name;
  277. aos_pool_create(&p, NULL);
  278. options = oss_request_options_create(p);
  279. init_test_request_options(options, 0);
  280. aos_str_set(&bucket, TEST_BUCKET_NAME);
  281. aos_str_set(&channel_name, live_channel_name);
  282. config = oss_create_live_channel_configuration_content(options->pool);
  283. aos_str_set(&config->name, live_channel_name);
  284. aos_str_set(&config->description, live_channel_desc);
  285. // create
  286. aos_list_init(&publish_url_list);
  287. aos_list_init(&play_url_list);
  288. s = oss_create_live_channel(options, &bucket, config, &publish_url_list,
  289. &play_url_list, NULL);
  290. CuAssertIntEquals(tc, 200, s->code);
  291. // get stat
  292. s = oss_get_live_channel_stat(options, &bucket, &channel_name, &live_stat, NULL);
  293. CuAssertIntEquals(tc, 200, s->code);
  294. // delete
  295. s = oss_delete_live_channel(options, &bucket, &channel_name, NULL);
  296. CuAssertIntEquals(tc, 204, s->code);
  297. // get stat
  298. s = oss_get_live_channel_stat(options, &bucket, &channel_name, &live_stat, NULL);
  299. CuAssertIntEquals(tc, 404, s->code);
  300. CuAssertStrEquals(tc, "NoSuchLiveChannel", s->error_code);
  301. aos_pool_destroy(p);
  302. printf("test_delete_live_channel ok\n");
  303. }
  304. void test_list_live_channel(CuTest *tc)
  305. {
  306. aos_pool_t *p = NULL;
  307. oss_request_options_t *options = NULL;
  308. aos_status_t *s = NULL;
  309. aos_string_t bucket;
  310. oss_list_live_channel_params_t *params = NULL;
  311. oss_live_channel_content_t *live_chan;
  312. char *content = NULL;
  313. oss_live_channel_publish_url_t *publish_url;
  314. oss_live_channel_play_url_t *play_url;
  315. int channel_count = 0;
  316. aos_pool_create(&p, NULL);
  317. options = oss_request_options_create(p);
  318. init_test_request_options(options, 0);
  319. aos_str_set(&bucket, TEST_BUCKET_NAME);
  320. // create
  321. s = create_test_live_channel(options, TEST_BUCKET_NAME, "test_live_channel_list1");
  322. CuAssertIntEquals(tc, 200, s->code);
  323. s = create_test_live_channel(options, TEST_BUCKET_NAME, "test_live_channel_list2");
  324. CuAssertIntEquals(tc, 200, s->code);
  325. s = create_test_live_channel(options, TEST_BUCKET_NAME, "test_live_channel_list3");
  326. CuAssertIntEquals(tc, 200, s->code);
  327. s = create_test_live_channel(options, TEST_BUCKET_NAME, "test_live_channel_list4");
  328. CuAssertIntEquals(tc, 200, s->code);
  329. s = create_test_live_channel(options, TEST_BUCKET_NAME, "test_live_channel_list5");
  330. CuAssertIntEquals(tc, 200, s->code);
  331. // list
  332. params = oss_create_list_live_channel_params(options->pool);
  333. aos_str_set(&params->prefix, "test_live_channel_list");
  334. s = oss_list_live_channel(options, &bucket, params, NULL);
  335. CuAssertIntEquals(tc, 200, s->code);
  336. channel_count = 0;
  337. aos_list_for_each_entry(oss_live_channel_content_t, live_chan, &params->live_channel_list, node) {
  338. channel_count++;
  339. content = apr_psprintf(p, "%.*s", live_chan->name.len, live_chan->name.data);
  340. CuAssertStrEquals(tc, apr_psprintf(p, "test_live_channel_list%d", channel_count), content);
  341. content = apr_psprintf(p, "%.*s", live_chan->description.len, live_chan->description.data);
  342. CuAssertStrEquals(tc, "live channel description", content);
  343. content = apr_psprintf(p, "%.*s", live_chan->status.len, live_chan->status.data);
  344. CuAssertStrEquals(tc, LIVE_CHANNEL_STATUS_ENABLED, content);
  345. content = apr_psprintf(p, "%.*s", live_chan->last_modified.len, live_chan->last_modified.data);
  346. CuAssertStrnEquals(tc, "201", strlen("201"), content);
  347. aos_list_for_each_entry(oss_live_channel_publish_url_t, publish_url, &live_chan->publish_url_list, node) {
  348. content = apr_psprintf(p, "%.*s", publish_url->publish_url.len, publish_url->publish_url.data);
  349. CuAssertStrnEquals(tc, AOS_RTMP_PREFIX, strlen(AOS_RTMP_PREFIX), content);
  350. }
  351. aos_list_for_each_entry(oss_live_channel_play_url_t, play_url, &live_chan->play_url_list, node) {
  352. content = apr_psprintf(p, "%.*s", play_url->play_url.len, play_url->play_url.data);
  353. CuAssertStrnEquals(tc, AOS_HTTP_PREFIX, strlen(AOS_HTTP_PREFIX), content);
  354. }
  355. }
  356. CuAssertIntEquals(tc, 5, channel_count);
  357. // list by prefix
  358. params = oss_create_list_live_channel_params(options->pool);
  359. aos_str_set(&params->prefix, "test_live_channel_list2");
  360. s = oss_list_live_channel(options, &bucket, params, NULL);
  361. CuAssertIntEquals(tc, 200, s->code);
  362. channel_count = 0;
  363. aos_list_for_each_entry(oss_live_channel_content_t, live_chan, &params->live_channel_list, node) {
  364. channel_count++;
  365. content = apr_psprintf(p, "%.*s", live_chan->name.len, live_chan->name.data);
  366. CuAssertStrEquals(tc, "test_live_channel_list2", content);
  367. content = apr_psprintf(p, "%.*s", live_chan->description.len, live_chan->description.data);
  368. CuAssertStrEquals(tc, "live channel description", content);
  369. content = apr_psprintf(p, "%.*s", live_chan->status.len, live_chan->status.data);
  370. CuAssertStrEquals(tc, LIVE_CHANNEL_STATUS_ENABLED, content);
  371. content = apr_psprintf(p, "%.*s", live_chan->last_modified.len, live_chan->last_modified.data);
  372. CuAssertStrnEquals(tc, "201", strlen("201"), content);
  373. aos_list_for_each_entry(oss_live_channel_publish_url_t, publish_url, &live_chan->publish_url_list, node) {
  374. content = apr_psprintf(p, "%.*s", publish_url->publish_url.len, publish_url->publish_url.data);
  375. CuAssertStrnEquals(tc, AOS_RTMP_PREFIX, strlen(AOS_RTMP_PREFIX), content);
  376. }
  377. aos_list_for_each_entry(oss_live_channel_play_url_t, play_url, &live_chan->play_url_list, node) {
  378. content = apr_psprintf(p, "%.*s", play_url->play_url.len, play_url->play_url.data);
  379. CuAssertStrnEquals(tc, AOS_HTTP_PREFIX, strlen(AOS_HTTP_PREFIX), content);
  380. }
  381. }
  382. CuAssertIntEquals(tc, 1, channel_count);
  383. // list by mark
  384. params = oss_create_list_live_channel_params(options->pool);
  385. aos_str_set(&params->prefix, "test_live_channel_list");
  386. aos_str_set(&params->marker, "test_live_channel_list2");
  387. s = oss_list_live_channel(options, &bucket, params, NULL);
  388. CuAssertIntEquals(tc, 200, s->code);
  389. channel_count = 0;
  390. aos_list_for_each_entry(oss_live_channel_content_t, live_chan, &params->live_channel_list, node) {
  391. channel_count++;
  392. content = apr_psprintf(p, "%.*s", live_chan->name.len, live_chan->name.data);
  393. CuAssertStrEquals(tc, apr_psprintf(p, "test_live_channel_list%d", channel_count + 2), content);
  394. content = apr_psprintf(p, "%.*s", live_chan->description.len, live_chan->description.data);
  395. CuAssertStrEquals(tc, "live channel description", content);
  396. content = apr_psprintf(p, "%.*s", live_chan->status.len, live_chan->status.data);
  397. CuAssertStrEquals(tc, LIVE_CHANNEL_STATUS_ENABLED, content);
  398. content = apr_psprintf(p, "%.*s", live_chan->last_modified.len, live_chan->last_modified.data);
  399. CuAssertStrnEquals(tc, "201", strlen("201"), content);
  400. aos_list_for_each_entry(oss_live_channel_publish_url_t, publish_url, &live_chan->publish_url_list, node) {
  401. content = apr_psprintf(p, "%.*s", publish_url->publish_url.len,
  402. publish_url->publish_url.data);
  403. CuAssertStrnEquals(tc, AOS_RTMP_PREFIX, strlen(AOS_RTMP_PREFIX), content);
  404. }
  405. aos_list_for_each_entry(oss_live_channel_play_url_t, play_url, &live_chan->play_url_list, node) {
  406. content = apr_psprintf(p, "%.*s", play_url->play_url.len, play_url->play_url.data);
  407. CuAssertStrnEquals(tc, AOS_HTTP_PREFIX, strlen(AOS_HTTP_PREFIX), content);
  408. }
  409. }
  410. CuAssertIntEquals(tc, 3, channel_count);
  411. // list by max keys
  412. params = oss_create_list_live_channel_params(options->pool);
  413. aos_str_set(&params->prefix, "test_live_channel_list");
  414. params->max_keys = 3;
  415. s = oss_list_live_channel(options, &bucket, params, NULL);
  416. CuAssertIntEquals(tc, 200, s->code);
  417. channel_count = 0;
  418. aos_list_for_each_entry(oss_live_channel_content_t, live_chan, &params->live_channel_list, node) {
  419. channel_count++;
  420. content = apr_psprintf(p, "%.*s", live_chan->name.len, live_chan->name.data);
  421. CuAssertStrEquals(tc, apr_psprintf(p, "test_live_channel_list%d", channel_count), content);
  422. content = apr_psprintf(p, "%.*s", live_chan->description.len, live_chan->description.data);
  423. CuAssertStrEquals(tc, "live channel description", content);
  424. content = apr_psprintf(p, "%.*s", live_chan->status.len, live_chan->status.data);
  425. CuAssertStrEquals(tc, LIVE_CHANNEL_STATUS_ENABLED, content);
  426. content = apr_psprintf(p, "%.*s", live_chan->last_modified.len, live_chan->last_modified.data);
  427. CuAssertStrnEquals(tc, "201", strlen("201"), content);
  428. aos_list_for_each_entry(oss_live_channel_publish_url_t, publish_url, &live_chan->publish_url_list, node) {
  429. content = apr_psprintf(p, "%.*s", publish_url->publish_url.len, publish_url->publish_url.data);
  430. CuAssertStrnEquals(tc, AOS_RTMP_PREFIX, strlen(AOS_RTMP_PREFIX), content);
  431. }
  432. aos_list_for_each_entry(oss_live_channel_play_url_t, play_url, &live_chan->play_url_list, node) {
  433. content = apr_psprintf(p, "%.*s", play_url->play_url.len, play_url->play_url.data);
  434. CuAssertStrnEquals(tc, AOS_HTTP_PREFIX, strlen(AOS_HTTP_PREFIX), content);
  435. }
  436. }
  437. CuAssertIntEquals(tc, 3, channel_count);
  438. s = delete_test_live_channel(options, TEST_BUCKET_NAME, "test_live_channel_list1");
  439. CuAssertIntEquals(tc, 204, s->code);
  440. s = delete_test_live_channel(options, TEST_BUCKET_NAME, "test_live_channel_list2");
  441. CuAssertIntEquals(tc, 204, s->code);
  442. s = delete_test_live_channel(options, TEST_BUCKET_NAME, "test_live_channel_list3");
  443. CuAssertIntEquals(tc, 204, s->code);
  444. s = delete_test_live_channel(options, TEST_BUCKET_NAME, "test_live_channel_list4");
  445. CuAssertIntEquals(tc, 204, s->code);
  446. s = delete_test_live_channel(options, TEST_BUCKET_NAME, "test_live_channel_list5");
  447. CuAssertIntEquals(tc, 204, s->code);
  448. aos_pool_destroy(p);
  449. printf("test_list_live_channel ok\n");
  450. }
  451. void test_get_live_channel_history(CuTest *tc)
  452. {
  453. aos_pool_t *p = NULL;
  454. oss_request_options_t *options = NULL;
  455. aos_status_t *s = NULL;
  456. aos_list_t live_record_list;
  457. oss_live_record_content_t *live_record;
  458. char *live_channel_name = "test_live_channel_hist";
  459. aos_string_t bucket;
  460. aos_string_t channel_name;
  461. aos_string_t content;
  462. aos_pool_create(&p, NULL);
  463. options = oss_request_options_create(p);
  464. init_test_request_options(options, 0);
  465. aos_str_set(&bucket, TEST_BUCKET_NAME);
  466. aos_str_set(&channel_name, live_channel_name);
  467. // create
  468. s = create_test_live_channel(options, TEST_BUCKET_NAME, live_channel_name);
  469. CuAssertIntEquals(tc, 200, s->code);
  470. // get history
  471. aos_list_init(&live_record_list);
  472. s = oss_get_live_channel_history(options, &bucket, &channel_name, &live_record_list, NULL);
  473. CuAssertIntEquals(tc, 200, s->code);
  474. aos_list_for_each_entry(oss_live_record_content_t, live_record, &live_record_list, node) {
  475. aos_str_set(&content, ".000Z");
  476. CuAssertIntEquals(tc, 1, aos_ends_with(&live_record->start_time, &content));
  477. CuAssertIntEquals(tc, 1, aos_ends_with(&live_record->end_time, &content));
  478. CuAssertTrue(tc, live_record->remote_addr.len >= (int)strlen("0.0.0.0:0"));
  479. }
  480. // delete
  481. s = oss_delete_live_channel(options, &bucket, &channel_name, NULL);
  482. CuAssertIntEquals(tc, 204, s->code);
  483. aos_pool_destroy(p);
  484. printf("test_get_live_channel_history ok\n");
  485. }
  486. /**
  487. * Note: the case need put rtmp stream, use command:
  488. * ffmpeg \-re \-i allstar.flv \-c copy \-f flv "rtmp://oss-live-channel.demo-oss-cn-shenzhen.aliyuncs.com/live/test_live_channel_vod?playlistName=play.m3u8"
  489. */
  490. void test_gen_vod_play_list(CuTest *tc)
  491. {
  492. aos_pool_t *p = NULL;
  493. oss_request_options_t *options = NULL;
  494. aos_status_t *s = NULL;
  495. char *live_channel_name = "test_live_channel_vod";
  496. aos_string_t bucket;
  497. aos_string_t channel_name;
  498. aos_string_t play_list_name;
  499. int64_t start_time = 0;
  500. int64_t end_time = 0;
  501. oss_acl_e oss_acl;
  502. aos_table_t *resp_headers = NULL;
  503. aos_pool_create(&p, NULL);
  504. options = oss_request_options_create(p);
  505. init_test_request_options(options, 0);
  506. aos_str_set(&bucket, TEST_BUCKET_NAME);
  507. aos_str_set(&channel_name, live_channel_name);
  508. oss_acl = OSS_ACL_PUBLIC_READ_WRITE;
  509. s = oss_put_bucket_acl(options, &bucket, oss_acl, &resp_headers);
  510. // create
  511. s = create_test_live_channel(options, TEST_BUCKET_NAME, live_channel_name);
  512. CuAssertIntEquals(tc, 200, s->code);
  513. // post vod
  514. aos_str_set(&play_list_name, "play.m3u8");
  515. start_time = apr_time_now() / 1000000 - 3600;
  516. end_time = apr_time_now() / 1000000 + 3600;
  517. s = oss_gen_vod_play_list(options, &bucket, &channel_name, &play_list_name,
  518. start_time, end_time, NULL);
  519. CuAssertIntEquals(tc, 400, s->code);
  520. // delete
  521. s = oss_delete_live_channel(options, &bucket, &channel_name, NULL);
  522. CuAssertIntEquals(tc, 204, s->code);
  523. aos_pool_destroy(p);
  524. printf("test_post_vod_play_list ok\n");
  525. }
  526. void test_gen_rtmp_signed_url(CuTest *tc)
  527. {
  528. aos_pool_t *p = NULL;
  529. oss_request_options_t *options = NULL;
  530. aos_status_t *s = NULL;
  531. char *live_channel_name = "test_live_channel_url";
  532. aos_string_t bucket;
  533. aos_string_t channel_name;
  534. aos_string_t play_list_name;
  535. oss_acl_e oss_acl;
  536. aos_table_t *resp_headers = NULL;
  537. char *rtmp_url = NULL;
  538. int64_t expires = 0;
  539. aos_pool_create(&p, NULL);
  540. options = oss_request_options_create(p);
  541. init_test_request_options(options, 0);
  542. aos_str_set(&bucket, TEST_BUCKET_NAME);
  543. aos_str_set(&channel_name, live_channel_name);
  544. oss_acl = OSS_ACL_PRIVATE;
  545. s = oss_put_bucket_acl(options, &bucket, oss_acl, &resp_headers);
  546. // create
  547. s = create_test_live_channel(options, TEST_BUCKET_NAME, live_channel_name);
  548. CuAssertIntEquals(tc, 200, s->code);
  549. // gen url
  550. aos_str_set(&play_list_name, "play.m3u8");
  551. expires = apr_time_now() / 1000000 + 60 * 30;
  552. rtmp_url = oss_gen_rtmp_signed_url(options, &bucket, &channel_name,
  553. &play_list_name, expires);
  554. // manual check passed
  555. CuAssertStrnEquals(tc, AOS_RTMP_PREFIX, strlen(AOS_RTMP_PREFIX), rtmp_url);
  556. // delete
  557. s = oss_delete_live_channel(options, &bucket, &channel_name, NULL);
  558. CuAssertIntEquals(tc, 204, s->code);
  559. aos_pool_destroy(p);
  560. printf("test_gen_rtmp_signed_url ok\n");
  561. }
  562. CuSuite *test_oss_live()
  563. {
  564. CuSuite* suite = CuSuiteNew();
  565. SUITE_ADD_TEST(suite, test_live_setup);
  566. SUITE_ADD_TEST(suite, test_create_live_channel_default);
  567. SUITE_ADD_TEST(suite, test_create_live_channel);
  568. SUITE_ADD_TEST(suite, test_put_live_channel_status);
  569. SUITE_ADD_TEST(suite, test_get_live_channel_stat);
  570. SUITE_ADD_TEST(suite, test_delete_live_channel);
  571. SUITE_ADD_TEST(suite, test_list_live_channel);
  572. SUITE_ADD_TEST(suite, test_get_live_channel_history);
  573. SUITE_ADD_TEST(suite, test_gen_vod_play_list);
  574. SUITE_ADD_TEST(suite, test_gen_rtmp_signed_url);
  575. SUITE_ADD_TEST(suite, test_live_cleanup);
  576. return suite;
  577. }