switch_vpx.c 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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_image_t *img;
  22. uint8_t buf[SWITCH_DEFAULT_VIDEO_SIZE + 12];
  23. switch_status_t status;
  24. switch_codec_t codec = { 0 };
  25. switch_frame_t frame = { 0 };
  26. switch_codec_settings_t codec_settings = {{ 0 }};
  27. int packets = 0;
  28. switch_status_t encode_status;
  29. // switch_set_string(codec_settings.video.config_profile_name, "conference");
  30. codec_settings.video.width = 1280;
  31. codec_settings.video.height = 720;
  32. status = switch_core_codec_init(&codec,
  33. "VP8",
  34. NULL,
  35. NULL,
  36. 0,
  37. 0,
  38. 1, SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE,
  39. &codec_settings, fst_pool);
  40. fst_check(status == SWITCH_STATUS_SUCCESS);
  41. img = switch_img_alloc(NULL, SWITCH_IMG_FMT_I420, 1280, 720, 1);
  42. fst_requires(img);
  43. frame.packet = buf;
  44. frame.packetlen = SWITCH_DEFAULT_VIDEO_SIZE + 12;
  45. frame.data = buf + 12;
  46. frame.datalen = SWITCH_DEFAULT_VIDEO_SIZE;
  47. frame.payload = 96;
  48. frame.m = 0;
  49. frame.seq = 0;
  50. frame.timestamp = 0;
  51. frame.img = img;
  52. do {
  53. frame.datalen = SWITCH_DEFAULT_VIDEO_SIZE;
  54. encode_status = switch_core_codec_encode_video(&codec, &frame);
  55. if (encode_status == SWITCH_STATUS_SUCCESS || encode_status == SWITCH_STATUS_MORE_DATA) {
  56. switch_assert((encode_status == SWITCH_STATUS_SUCCESS && frame.m) || !frame.m);
  57. if (frame.flags & SFF_PICTURE_RESET) {
  58. frame.flags &= ~SFF_PICTURE_RESET;
  59. // fst_check(0);
  60. }
  61. if (frame.datalen == 0) break;
  62. switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "%02x %02x | m=%d | %d\n", buf[12], buf[13], frame.m, frame.datalen);
  63. packets++;
  64. }
  65. } while(encode_status == SWITCH_STATUS_MORE_DATA);
  66. fst_check(frame.m == 1);
  67. fst_check(packets > 0);
  68. switch_img_free(&img);
  69. switch_core_codec_destroy(&codec);
  70. }
  71. FST_TEST_END()
  72. FST_TEARDOWN_BEGIN()
  73. {
  74. switch_sleep(1000000);
  75. // switch_core_destroy();
  76. }
  77. FST_TEARDOWN_END()
  78. }
  79. FST_SUITE_END()
  80. }
  81. FST_CORE_END()