switch_core_codec.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. /*
  2. * FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
  3. * Copyright (C) 2005-2018, Anthony Minessale II <anthm@freeswitch.org>
  4. *
  5. * Version: MPL 1.1
  6. *
  7. * The contents of this file are subject to the Mozilla Public License Version
  8. * 1.1 (the "License"); you may not use this file except in compliance with
  9. * the License. You may obtain a copy of the License at
  10. * http://www.mozilla.org/MPL/
  11. *
  12. * Software distributed under the License is distributed on an "AS IS" basis,
  13. * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  14. * for the specific language governing rights and limitations under the
  15. * License.
  16. *
  17. * The Original Code is FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
  18. *
  19. * The Initial Developer of the Original Code is
  20. * Anthony Minessale II <anthm@freeswitch.org>
  21. * Portions created by the Initial Developer are Copyright (C)
  22. * the Initial Developer. All Rights Reserved.
  23. *
  24. * Contributor(s):
  25. * Chris Rienzo <chris@signalwire.com>
  26. * Seven Du <dujinfang@gmail.com>
  27. * Dragos Oancea <dragos@signalwire.com>
  28. *
  29. * switch_core_codec.c -- tests codec core functions
  30. *
  31. */
  32. #include <switch.h>
  33. #include <stdlib.h>
  34. #include <test/switch_test.h>
  35. FST_CORE_BEGIN("./conf")
  36. {
  37. FST_SUITE_BEGIN(switch_core_codec)
  38. {
  39. FST_SETUP_BEGIN()
  40. {
  41. }
  42. FST_SETUP_END()
  43. FST_TEARDOWN_BEGIN()
  44. {
  45. }
  46. FST_TEARDOWN_END()
  47. FST_SETUP_BEGIN()
  48. {
  49. fst_requires_module("mod_opus");
  50. fst_requires_module("mod_spandsp");
  51. }
  52. FST_SETUP_END()
  53. FST_TEST_BEGIN(test_switch_core_codec_copy)
  54. {
  55. switch_codec_t orig_codec = { 0 };
  56. switch_codec_t new_codec = { 0 };
  57. switch_status_t status;
  58. switch_codec_settings_t codec_settings = {{ 0 }};
  59. status = switch_core_codec_init(&orig_codec,
  60. "OPUS",
  61. "mod_opus",
  62. NULL,
  63. 48000,
  64. 20,
  65. 1, SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE,
  66. &codec_settings, fst_pool);
  67. fst_check(status == SWITCH_STATUS_SUCCESS);
  68. switch_core_codec_copy(&orig_codec, &new_codec, NULL, NULL);
  69. fst_check(orig_codec.implementation->samples_per_second == new_codec.implementation->samples_per_second);
  70. fst_check(orig_codec.implementation->actual_samples_per_second == new_codec.implementation->actual_samples_per_second);
  71. switch_core_codec_destroy(&orig_codec);
  72. switch_core_codec_destroy(&new_codec);
  73. status = switch_core_codec_init(&orig_codec,
  74. "OPUS",
  75. "mod_opus",
  76. NULL,
  77. 16000,
  78. 20,
  79. 1, SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE,
  80. &codec_settings, fst_pool);
  81. fst_check(status == SWITCH_STATUS_SUCCESS);
  82. switch_core_codec_copy(&orig_codec, &new_codec, NULL, NULL);
  83. fst_check(orig_codec.implementation->samples_per_second == new_codec.implementation->samples_per_second);
  84. fst_check(orig_codec.implementation->actual_samples_per_second == new_codec.implementation->actual_samples_per_second);
  85. switch_core_codec_destroy(&orig_codec);
  86. switch_core_codec_destroy(&new_codec);
  87. status = switch_core_codec_init(&orig_codec,
  88. "OPUS",
  89. "mod_opus",
  90. NULL,
  91. 8000,
  92. 20,
  93. 1, SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE,
  94. &codec_settings, fst_pool);
  95. fst_check(status == SWITCH_STATUS_SUCCESS);
  96. switch_core_codec_copy(&orig_codec, &new_codec, NULL, NULL);
  97. fst_check(orig_codec.implementation->samples_per_second == new_codec.implementation->samples_per_second);
  98. fst_check(orig_codec.implementation->actual_samples_per_second == new_codec.implementation->actual_samples_per_second);
  99. switch_core_codec_destroy(&orig_codec);
  100. switch_core_codec_destroy(&new_codec);
  101. status = switch_core_codec_init(&orig_codec,
  102. "G722",
  103. "mod_spandsp",
  104. NULL,
  105. 8000,
  106. 20,
  107. 1, SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE,
  108. &codec_settings, fst_pool);
  109. fst_check(status == SWITCH_STATUS_SUCCESS);
  110. switch_core_codec_copy(&orig_codec, &new_codec, NULL, NULL);
  111. fst_check(orig_codec.implementation->samples_per_second == new_codec.implementation->samples_per_second);
  112. fst_check(orig_codec.implementation->actual_samples_per_second == new_codec.implementation->actual_samples_per_second);
  113. switch_core_codec_destroy(&orig_codec);
  114. switch_core_codec_destroy(&new_codec);
  115. }
  116. FST_TEST_END()
  117. }
  118. FST_SUITE_END()
  119. }
  120. FST_CORE_END()