2
0

switch_vpx.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /*
  2. * Copyright (C) 2018, Signalwire, Inc. ALL RIGHTS RESERVED
  3. *
  4. * switch_vpx.c -- Tests vpx functions
  5. */
  6. #include <test/switch_test.h>
  7. FST_CORE_BEGIN("./conf")
  8. {
  9. FST_SUITE_BEGIN()
  10. {
  11. FST_SETUP_BEGIN()
  12. {
  13. switch_stream_handle_t stream = { 0 };
  14. SWITCH_STANDARD_STREAM(stream);
  15. switch_api_execute("vpx", "debug on", NULL, &stream);
  16. switch_safe_free(stream.data);
  17. }
  18. FST_SETUP_END()
  19. FST_TEST_BEGIN(vp8_test)
  20. {
  21. switch_status_t status;
  22. switch_codec_t codec = { 0 };
  23. switch_codec_settings_t codec_settings = {{ 0 }};
  24. // switch_set_string(codec_settings.video.config_profile_name, "conference");
  25. codec_settings.video.width = 1280;
  26. codec_settings.video.height = 720;
  27. status = switch_core_codec_init(&codec,
  28. "VP8",
  29. NULL,
  30. NULL,
  31. 0,
  32. 0,
  33. 1, SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE,
  34. &codec_settings, fst_pool);
  35. fst_check(status == SWITCH_STATUS_SUCCESS);
  36. switch_image_t *img = switch_img_alloc(NULL, SWITCH_IMG_FMT_I420, 1280, 720, 1);
  37. fst_requires(img);
  38. uint8_t buf[SWITCH_DEFAULT_VIDEO_SIZE + 12];
  39. switch_frame_t frame = { 0 };
  40. frame.packet = buf;
  41. frame.packetlen = SWITCH_DEFAULT_VIDEO_SIZE + 12;
  42. frame.data = buf + 12;
  43. frame.datalen = SWITCH_DEFAULT_VIDEO_SIZE;
  44. frame.payload = 96;
  45. frame.m = 0;
  46. frame.seq = 0;
  47. frame.timestamp = 0;
  48. frame.img = img;
  49. int packets = 0;
  50. switch_status_t encode_status;
  51. do {
  52. frame.datalen = SWITCH_DEFAULT_VIDEO_SIZE;
  53. encode_status = switch_core_codec_encode_video(&codec, &frame);
  54. if (encode_status == SWITCH_STATUS_SUCCESS || encode_status == SWITCH_STATUS_MORE_DATA) {
  55. switch_assert((encode_status == SWITCH_STATUS_SUCCESS && frame.m) || !frame.m);
  56. if (frame.flags & SFF_PICTURE_RESET) {
  57. frame.flags &= ~SFF_PICTURE_RESET;
  58. // fst_check(0);
  59. }
  60. if (frame.datalen == 0) break;
  61. switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "%02x %02x | m=%d | %d\n", buf[12], buf[13], frame.m, frame.datalen);
  62. packets++;
  63. }
  64. } while(encode_status == SWITCH_STATUS_MORE_DATA);
  65. fst_check(frame.m == 1);
  66. fst_check(packets > 0);
  67. switch_img_free(&img);
  68. switch_core_codec_destroy(&codec);
  69. }
  70. FST_TEST_END()
  71. FST_TEARDOWN_BEGIN()
  72. {
  73. switch_sleep(1000000);
  74. // switch_core_destroy();
  75. }
  76. FST_TEARDOWN_END()
  77. }
  78. FST_SUITE_END()
  79. }
  80. FST_CORE_END()