ipp_codecs.c 56 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683
  1. /*
  2. * Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com)
  3. * Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  18. */
  19. #include <pjmedia-codec/ipp_codecs.h>
  20. #include <pjmedia-codec/amr_sdp_match.h>
  21. #include <pjmedia-codec/g7221_sdp_match.h>
  22. #include <pjmedia/codec.h>
  23. #include <pjmedia/errno.h>
  24. #include <pjmedia/endpoint.h>
  25. #include <pjmedia/plc.h>
  26. #include <pjmedia/port.h>
  27. #include <pjmedia/silencedet.h>
  28. #include <pj/assert.h>
  29. #include <pj/log.h>
  30. #include <pj/math.h>
  31. #include <pj/pool.h>
  32. #include <pj/string.h>
  33. #include <pj/os.h>
  34. /*
  35. * Only build this file if PJMEDIA_HAS_INTEL_IPP != 0
  36. */
  37. #if defined(PJMEDIA_HAS_INTEL_IPP) && PJMEDIA_HAS_INTEL_IPP != 0
  38. #include <usc.h>
  39. #include <ippversion.h>
  40. #define THIS_FILE "ipp_codecs.c"
  41. /* Prototypes for IPP codecs factory */
  42. static pj_status_t ipp_test_alloc( pjmedia_codec_factory *factory,
  43. const pjmedia_codec_info *id );
  44. static pj_status_t ipp_default_attr( pjmedia_codec_factory *factory,
  45. const pjmedia_codec_info *id,
  46. pjmedia_codec_param *attr );
  47. static pj_status_t ipp_enum_codecs( pjmedia_codec_factory *factory,
  48. unsigned *count,
  49. pjmedia_codec_info codecs[]);
  50. static pj_status_t ipp_alloc_codec( pjmedia_codec_factory *factory,
  51. const pjmedia_codec_info *id,
  52. pjmedia_codec **p_codec);
  53. static pj_status_t ipp_dealloc_codec( pjmedia_codec_factory *factory,
  54. pjmedia_codec *codec );
  55. /* Prototypes for IPP codecs implementation. */
  56. static pj_status_t ipp_codec_init( pjmedia_codec *codec,
  57. pj_pool_t *pool );
  58. static pj_status_t ipp_codec_open( pjmedia_codec *codec,
  59. pjmedia_codec_param *attr );
  60. static pj_status_t ipp_codec_close( pjmedia_codec *codec );
  61. static pj_status_t ipp_codec_modify(pjmedia_codec *codec,
  62. const pjmedia_codec_param *attr );
  63. static pj_status_t ipp_codec_parse( pjmedia_codec *codec,
  64. void *pkt,
  65. pj_size_t pkt_size,
  66. const pj_timestamp *ts,
  67. unsigned *frame_cnt,
  68. pjmedia_frame frames[]);
  69. static pj_status_t ipp_codec_encode( pjmedia_codec *codec,
  70. const struct pjmedia_frame *input,
  71. unsigned output_buf_len,
  72. struct pjmedia_frame *output);
  73. static pj_status_t ipp_codec_decode( pjmedia_codec *codec,
  74. const struct pjmedia_frame *input,
  75. unsigned output_buf_len,
  76. struct pjmedia_frame *output);
  77. static pj_status_t ipp_codec_recover(pjmedia_codec *codec,
  78. unsigned output_buf_len,
  79. struct pjmedia_frame *output);
  80. /* Definition for IPP codecs operations. */
  81. static pjmedia_codec_op ipp_op =
  82. {
  83. &ipp_codec_init,
  84. &ipp_codec_open,
  85. &ipp_codec_close,
  86. &ipp_codec_modify,
  87. &ipp_codec_parse,
  88. &ipp_codec_encode,
  89. &ipp_codec_decode,
  90. &ipp_codec_recover
  91. };
  92. /* Definition for IPP codecs factory operations. */
  93. static pjmedia_codec_factory_op ipp_factory_op =
  94. {
  95. &ipp_test_alloc,
  96. &ipp_default_attr,
  97. &ipp_enum_codecs,
  98. &ipp_alloc_codec,
  99. &ipp_dealloc_codec,
  100. &pjmedia_codec_ipp_deinit
  101. };
  102. /* IPP codecs factory */
  103. static struct ipp_factory {
  104. pjmedia_codec_factory base;
  105. pjmedia_endpt *endpt;
  106. pj_pool_t *pool;
  107. pj_mutex_t *mutex;
  108. unsigned g7221_pcm_shift;
  109. } ipp_factory;
  110. /* IPP codecs private data. */
  111. typedef struct ipp_private {
  112. int codec_idx; /**< Codec index. */
  113. void *codec_setting; /**< Specific codec setting. */
  114. pj_pool_t *pool; /**< Pool for each instance. */
  115. USC_Handle enc; /**< Encoder state. */
  116. USC_Handle dec; /**< Decoder state. */
  117. USC_CodecInfo *info; /**< Native codec info. */
  118. pj_uint16_t frame_size; /**< Bitstream frame size. */
  119. pj_bool_t plc_enabled; /**< PLC enabled flag. */
  120. pjmedia_plc *plc; /**< PJMEDIA PLC engine, NULL if
  121. codec has internal PLC. */
  122. pj_bool_t vad_enabled; /**< VAD enabled flag. */
  123. pjmedia_silence_det *vad; /**< PJMEDIA VAD engine, NULL if
  124. codec has internal VAD. */
  125. pj_timestamp last_tx; /**< Timestamp of last transmit.*/
  126. unsigned g7221_pcm_shift; /**< G722.1 PCM level adjustment*/
  127. } ipp_private_t;
  128. /* USC codec implementations. */
  129. extern USC_Fxns USC_G729AFP_Fxns;
  130. extern USC_Fxns USC_G729I_Fxns;
  131. extern USC_Fxns USC_G723_Fxns;
  132. extern USC_Fxns USC_G726_Fxns;
  133. extern USC_Fxns USC_G728_Fxns;
  134. extern USC_Fxns USC_G722_Fxns;
  135. extern USC_Fxns USC_GSMAMR_Fxns;
  136. extern USC_Fxns USC_AMRWB_Fxns;
  137. extern USC_Fxns USC_AMRWBE_Fxns;
  138. /* CUSTOM CALLBACKS */
  139. /* This callback is useful for translating RTP frame into USC frame, e.g:
  140. * reassigning frame attributes, reorder bitstream. Default behaviour of
  141. * the translation is just setting the USC frame buffer & its size as
  142. * specified in RTP frame, setting USC frame frametype to 0, setting bitrate
  143. * of USC frame to bitrate info of codec_data. Implement this callback when
  144. * the default behaviour is unapplicable.
  145. */
  146. typedef void (*predecode_cb)(ipp_private_t *codec_data,
  147. const pjmedia_frame *rtp_frame,
  148. USC_Bitstream *usc_frame);
  149. /* Parse frames from a packet. Default behaviour of frame parsing is
  150. * just separating frames based on calculating frame length derived
  151. * from bitrate. Implement this callback when the default behaviour is
  152. * unapplicable.
  153. */
  154. typedef pj_status_t (*parse_cb)(ipp_private_t *codec_data, void *pkt,
  155. pj_size_t pkt_size, const pj_timestamp *ts,
  156. unsigned *frame_cnt, pjmedia_frame frames[]);
  157. /* Pack frames into a packet. Default behaviour of packing frames is
  158. * just stacking the frames with octet aligned without adding any
  159. * payload header. Implement this callback when the default behaviour is
  160. * unapplicable.
  161. */
  162. typedef pj_status_t (*pack_cb)(ipp_private_t *codec_data, void *pkt,
  163. pj_size_t *pkt_size, pj_size_t max_pkt_size);
  164. /* Custom callback implementations. */
  165. static void predecode_g723( ipp_private_t *codec_data,
  166. const pjmedia_frame *rtp_frame,
  167. USC_Bitstream *usc_frame);
  168. static pj_status_t parse_g723( ipp_private_t *codec_data, void *pkt,
  169. pj_size_t pkt_size, const pj_timestamp *ts,
  170. unsigned *frame_cnt, pjmedia_frame frames[]);
  171. static void predecode_g729( ipp_private_t *codec_data,
  172. const pjmedia_frame *rtp_frame,
  173. USC_Bitstream *usc_frame);
  174. static void predecode_amr( ipp_private_t *codec_data,
  175. const pjmedia_frame *rtp_frame,
  176. USC_Bitstream *usc_frame);
  177. static pj_status_t parse_amr( ipp_private_t *codec_data, void *pkt,
  178. pj_size_t pkt_size, const pj_timestamp *ts,
  179. unsigned *frame_cnt, pjmedia_frame frames[]);
  180. static pj_status_t pack_amr( ipp_private_t *codec_data, void *pkt,
  181. pj_size_t *pkt_size, pj_size_t max_pkt_size);
  182. static void predecode_g7221( ipp_private_t *codec_data,
  183. const pjmedia_frame *rtp_frame,
  184. USC_Bitstream *usc_frame);
  185. static pj_status_t pack_g7221( ipp_private_t *codec_data, void *pkt,
  186. pj_size_t *pkt_size, pj_size_t max_pkt_size);
  187. /* IPP codec implementation descriptions. */
  188. static struct ipp_codec {
  189. int enabled; /* Is this codec enabled? */
  190. const char *name; /* Codec name. */
  191. pj_uint8_t pt; /* Payload type. */
  192. USC_Fxns *fxns; /* USC callback functions. */
  193. unsigned clock_rate; /* Codec's clock rate. */
  194. unsigned channel_count; /* Codec's channel count. */
  195. unsigned samples_per_frame; /* Codec's samples count. */
  196. unsigned def_bitrate; /* Default bitrate of this codec. */
  197. unsigned max_bitrate; /* Maximum bitrate of this codec. */
  198. pj_uint8_t frm_per_pkt; /* Default num of frames per packet.*/
  199. int has_native_vad; /* Codec has internal VAD? */
  200. int has_native_plc; /* Codec has internal PLC? */
  201. predecode_cb predecode; /* Callback to translate RTP frame
  202. into USC frame. */
  203. parse_cb parse; /* Callback to parse bitstream. */
  204. pack_cb pack; /* Callback to pack bitstream. */
  205. pjmedia_codec_fmtp dec_fmtp; /* Decoder's fmtp params. */
  206. }
  207. ipp_codec[] =
  208. {
  209. # if PJMEDIA_HAS_INTEL_IPP_CODEC_AMR
  210. {1, "AMR", PJMEDIA_RTP_PT_AMR, &USC_GSMAMR_Fxns, 8000, 1, 160,
  211. 7400, 12200, 2, 1, 1,
  212. &predecode_amr, &parse_amr, &pack_amr,
  213. {1, {{{"octet-align", 11}, {"1", 1}}} }
  214. },
  215. # endif
  216. # if PJMEDIA_HAS_INTEL_IPP_CODEC_AMRWB
  217. {1, "AMR-WB", PJMEDIA_RTP_PT_AMRWB, &USC_AMRWB_Fxns, 16000, 1, 320,
  218. 15850, 23850, 2, 1, 1,
  219. &predecode_amr, &parse_amr, &pack_amr,
  220. {1, {{{"octet-align", 11}, {"1", 1}}} }
  221. },
  222. # endif
  223. # if PJMEDIA_HAS_INTEL_IPP_CODEC_G729
  224. # if defined(PJ_HAS_FLOATING_POINT) && (PJ_HAS_FLOATING_POINT != 0)
  225. {1, "G729", PJMEDIA_RTP_PT_G729, &USC_G729AFP_Fxns, 8000, 1, 80,
  226. 8000, 11800, 2, 1, 1,
  227. &predecode_g729, NULL, NULL
  228. },
  229. # else
  230. {1, "G729", PJMEDIA_RTP_PT_G729, &USC_G729I_Fxns, 8000, 1, 80,
  231. 8000, 11800, 2, 1, 1,
  232. &predecode_g729, NULL, NULL
  233. },
  234. # endif
  235. # endif
  236. # if PJMEDIA_HAS_INTEL_IPP_CODEC_G723_1
  237. /* This is actually G.723.1 */
  238. {1, "G723", PJMEDIA_RTP_PT_G723, &USC_G723_Fxns, 8000, 1, 240,
  239. 6300, 6300, 1, 1, 1,
  240. &predecode_g723, &parse_g723, NULL
  241. },
  242. # endif
  243. # if PJMEDIA_HAS_INTEL_IPP_CODEC_G726
  244. {0, "G726-16", PJMEDIA_RTP_PT_G726_16, &USC_G726_Fxns, 8000, 1, 80,
  245. 16000, 16000, 2, 0, 0,
  246. NULL, NULL, NULL
  247. },
  248. {0, "G726-24", PJMEDIA_RTP_PT_G726_24, &USC_G726_Fxns, 8000, 1, 80,
  249. 24000, 24000, 2, 0, 0,
  250. NULL, NULL, NULL
  251. },
  252. {1, "G726-32", PJMEDIA_RTP_PT_G726_32, &USC_G726_Fxns, 8000, 1, 80,
  253. 32000, 32000, 2, 0, 0,
  254. NULL, NULL, NULL
  255. },
  256. {0, "G726-40", PJMEDIA_RTP_PT_G726_40, &USC_G726_Fxns, 8000, 1, 80,
  257. 40000, 40000, 2, 0, 0,
  258. NULL, NULL, NULL
  259. },
  260. /* Old definition of G726-32 */
  261. {1, "G721", PJMEDIA_RTP_PT_G721, &USC_G726_Fxns, 8000, 1, 80,
  262. 32000, 32000, 2, 0, 0,
  263. NULL, NULL, NULL
  264. },
  265. # endif
  266. # if PJMEDIA_HAS_INTEL_IPP_CODEC_G728
  267. {1, "G728", PJMEDIA_RTP_PT_G728, &USC_G728_Fxns, 8000, 1, 80,
  268. 16000, 16000, 2, 0, 1,
  269. NULL, NULL, NULL
  270. },
  271. # endif
  272. # if PJMEDIA_HAS_INTEL_IPP_CODEC_G722_1
  273. {0, "G7221", PJMEDIA_RTP_PT_G722_1_16, &USC_G722_Fxns, 16000, 1, 320,
  274. 16000, 16000, 1, 0, 1,
  275. predecode_g7221, NULL, pack_g7221,
  276. {1, {{{"bitrate", 7}, {"16000", 5}}} }
  277. },
  278. {1, "G7221", PJMEDIA_RTP_PT_G722_1_24, &USC_G722_Fxns, 16000, 1, 320,
  279. 24000, 24000, 1, 0, 1,
  280. predecode_g7221, NULL, pack_g7221,
  281. {1, {{{"bitrate", 7}, {"24000", 5}}} }
  282. },
  283. {1, "G7221", PJMEDIA_RTP_PT_G722_1_32, &USC_G722_Fxns, 16000, 1, 320,
  284. 32000, 32000, 1, 0, 1,
  285. predecode_g7221, NULL, pack_g7221,
  286. {1, {{{"bitrate", 7}, {"32000", 5}}} }
  287. },
  288. # endif
  289. };
  290. #if PJMEDIA_HAS_INTEL_IPP_CODEC_G729
  291. static void predecode_g729( ipp_private_t *codec_data,
  292. const pjmedia_frame *rtp_frame,
  293. USC_Bitstream *usc_frame)
  294. {
  295. switch (rtp_frame->size) {
  296. case 2:
  297. /* SID */
  298. usc_frame->frametype = 1;
  299. usc_frame->bitrate = codec_data->info->params.modes.bitrate;
  300. break;
  301. case 8:
  302. /* G729D */
  303. usc_frame->frametype = 2;
  304. usc_frame->bitrate = 6400;
  305. break;
  306. case 10:
  307. /* G729 */
  308. usc_frame->frametype = 3;
  309. usc_frame->bitrate = 8000;
  310. break;
  311. case 15:
  312. /* G729E */
  313. usc_frame->frametype = 4;
  314. usc_frame->bitrate = 11800;
  315. break;
  316. default:
  317. usc_frame->frametype = 0;
  318. usc_frame->bitrate = 0;
  319. break;
  320. }
  321. usc_frame->pBuffer = rtp_frame->buf;
  322. usc_frame->nbytes = rtp_frame->size;
  323. }
  324. #endif /* PJMEDIA_HAS_INTEL_IPP_CODEC_G729 */
  325. #if PJMEDIA_HAS_INTEL_IPP_CODEC_G723_1
  326. static void predecode_g723( ipp_private_t *codec_data,
  327. const pjmedia_frame *rtp_frame,
  328. USC_Bitstream *usc_frame)
  329. {
  330. int i, HDR = 0;
  331. pj_uint8_t *f = (pj_uint8_t*)rtp_frame->buf;
  332. PJ_UNUSED_ARG(codec_data);
  333. for (i = 0; i < 2; ++i){
  334. int tmp;
  335. tmp = (f[0] >> (i & 0x7)) & 1;
  336. HDR += tmp << i ;
  337. }
  338. usc_frame->pBuffer = rtp_frame->buf;
  339. usc_frame->nbytes = rtp_frame->size;
  340. usc_frame->bitrate = HDR == 0? 6300 : 5300;
  341. usc_frame->frametype = 0;
  342. }
  343. static pj_status_t parse_g723(ipp_private_t *codec_data, void *pkt,
  344. pj_size_t pkt_size, const pj_timestamp *ts,
  345. unsigned *frame_cnt, pjmedia_frame frames[])
  346. {
  347. unsigned count = 0;
  348. pj_uint8_t *f = (pj_uint8_t*)pkt;
  349. while (pkt_size && count < *frame_cnt) {
  350. int framesize, i, j;
  351. int HDR = 0;
  352. for (i = 0; i < 2; ++i){
  353. j = (f[0] >> (i & 0x7)) & 1;
  354. HDR += j << i ;
  355. }
  356. if (HDR == 0)
  357. framesize = 24;
  358. else if (HDR == 1)
  359. framesize = 20;
  360. else if (HDR == 2)
  361. framesize = 4;
  362. else if (HDR == 3)
  363. framesize = 1;
  364. else {
  365. pj_assert(!"Unknown G723.1 frametype, packet may be corrupted!");
  366. return PJMEDIA_CODEC_EINMODE;
  367. }
  368. frames[count].type = PJMEDIA_FRAME_TYPE_AUDIO;
  369. frames[count].buf = f;
  370. frames[count].size = framesize;
  371. frames[count].timestamp.u64 = ts->u64 + count *
  372. ipp_codec[codec_data->codec_idx].samples_per_frame;
  373. f += framesize;
  374. pkt_size -= framesize;
  375. ++count;
  376. }
  377. *frame_cnt = count;
  378. return PJ_SUCCESS;
  379. }
  380. #endif /* PJMEDIA_HAS_INTEL_IPP_CODEC_G723_1 */
  381. #if PJMEDIA_HAS_INTEL_IPP_CODEC_AMR || PJMEDIA_HAS_INTEL_IPP_CODEC_AMRWB
  382. #include <pjmedia-codec/amr_helper.h>
  383. typedef struct amr_settings_t {
  384. pjmedia_codec_amr_pack_setting enc_setting;
  385. pjmedia_codec_amr_pack_setting dec_setting;
  386. pj_int8_t enc_mode;
  387. } amr_settings_t;
  388. /* Rearrange AMR bitstream and convert RTP frame into USC frame:
  389. * - make the start_bit to be 0
  390. * - if it is speech frame, reorder bitstream from sensitivity bits order
  391. * to encoder bits order.
  392. * - set the appropriate value of usc_frame.
  393. */
  394. static void predecode_amr( ipp_private_t *codec_data,
  395. const pjmedia_frame *rtp_frame,
  396. USC_Bitstream *usc_frame)
  397. {
  398. pjmedia_frame frame;
  399. pjmedia_codec_amr_bit_info *info;
  400. pjmedia_codec_amr_pack_setting *setting;
  401. setting = &((amr_settings_t*)codec_data->codec_setting)->dec_setting;
  402. frame = *rtp_frame;
  403. pjmedia_codec_amr_predecode(rtp_frame, setting, &frame);
  404. info = (pjmedia_codec_amr_bit_info*) &frame.bit_info;
  405. usc_frame->pBuffer = frame.buf;
  406. usc_frame->nbytes = frame.size;
  407. if (info->mode != -1) {
  408. usc_frame->bitrate = setting->amr_nb?
  409. pjmedia_codec_amrnb_bitrates[info->mode]:
  410. pjmedia_codec_amrwb_bitrates[info->mode];
  411. } else {
  412. usc_frame->bitrate = 0;
  413. }
  414. if (frame.size > 5) {
  415. /* Speech */
  416. if (info->good_quality)
  417. usc_frame->frametype = 0;
  418. else
  419. usc_frame->frametype = setting->amr_nb ? 5 : 6;
  420. } else if (frame.size == 5) {
  421. /* SID */
  422. if (info->good_quality) {
  423. usc_frame->frametype = info->STI? 2 : 1;
  424. } else {
  425. usc_frame->frametype = setting->amr_nb ? 6 : 7;
  426. }
  427. } else {
  428. /* no data */
  429. usc_frame->frametype = 3;
  430. }
  431. }
  432. /* Pack AMR payload */
  433. static pj_status_t pack_amr(ipp_private_t *codec_data, void *pkt,
  434. pj_size_t *pkt_size, pj_size_t max_pkt_size)
  435. {
  436. enum {MAX_FRAMES_PER_PACKET = PJMEDIA_MAX_FRAME_DURATION_MS / 20};
  437. pjmedia_frame frames[MAX_FRAMES_PER_PACKET];
  438. unsigned nframes = 0;
  439. pjmedia_codec_amr_bit_info *info;
  440. pj_uint8_t *r; /* Read cursor */
  441. pj_uint8_t SID_FT;
  442. pjmedia_codec_amr_pack_setting *setting;
  443. const pj_uint8_t *framelen_tbl;
  444. setting = &((amr_settings_t*)codec_data->codec_setting)->enc_setting;
  445. framelen_tbl = setting->amr_nb? pjmedia_codec_amrnb_framelen:
  446. pjmedia_codec_amrwb_framelen;
  447. SID_FT = (pj_uint8_t)(setting->amr_nb? 8 : 9);
  448. /* Align pkt buf right */
  449. r = (pj_uint8_t*)pkt + max_pkt_size - *pkt_size;
  450. pj_memmove(r, pkt, *pkt_size);
  451. /* Get frames */
  452. for (;;) {
  453. pj_bool_t eof;
  454. pj_uint16_t info_;
  455. info_ = *((pj_uint16_t*)r);
  456. eof = ((info_ & 0x40) != 0);
  457. info = (pjmedia_codec_amr_bit_info*) &frames[nframes].bit_info;
  458. pj_bzero(info, sizeof(*info));
  459. info->frame_type = (pj_uint8_t)(info_ & 0x0F);
  460. info->good_quality = (pj_uint8_t)((info_ & 0x80) == 0);
  461. info->mode = (pj_int8_t) ((info_ >> 8) & 0x0F);
  462. info->STI = (pj_uint8_t)((info_ >> 5) & 1);
  463. frames[nframes].buf = r + 2;
  464. frames[nframes].size = info->frame_type <= SID_FT ?
  465. framelen_tbl[info->frame_type] : 0;
  466. r += frames[nframes].size + 2;
  467. /* Last frame */
  468. if (++nframes >= MAX_FRAMES_PER_PACKET || eof)
  469. break;
  470. }
  471. /* Pack */
  472. *pkt_size = max_pkt_size;
  473. return pjmedia_codec_amr_pack(frames, nframes, setting, pkt, pkt_size);
  474. }
  475. /* Parse AMR payload into frames. */
  476. static pj_status_t parse_amr(ipp_private_t *codec_data, void *pkt,
  477. pj_size_t pkt_size, const pj_timestamp *ts,
  478. unsigned *frame_cnt, pjmedia_frame frames[])
  479. {
  480. amr_settings_t* s = (amr_settings_t*)codec_data->codec_setting;
  481. pjmedia_codec_amr_pack_setting *setting;
  482. pj_status_t status;
  483. pj_uint8_t cmr;
  484. setting = &s->dec_setting;
  485. status = pjmedia_codec_amr_parse(pkt, pkt_size, ts, setting, frames,
  486. frame_cnt, &cmr);
  487. if (status != PJ_SUCCESS)
  488. return status;
  489. /* Check Change Mode Request. */
  490. if (((setting->amr_nb && cmr <= 7) || (!setting->amr_nb && cmr <= 8)) &&
  491. s->enc_mode != cmr)
  492. {
  493. struct ipp_codec *ippc = &ipp_codec[codec_data->codec_idx];
  494. s->enc_mode = cmr;
  495. codec_data->info->params.modes.bitrate = s->enc_setting.amr_nb?
  496. pjmedia_codec_amrnb_bitrates[s->enc_mode] :
  497. pjmedia_codec_amrwb_bitrates[s->enc_mode];
  498. ippc->fxns->std.Control(&codec_data->info->params.modes,
  499. codec_data->enc);
  500. PJ_LOG(4,(THIS_FILE, "AMR%s switched encoding mode to: %d (%dbps)",
  501. (s->enc_setting.amr_nb?"":"-WB"),
  502. s->enc_mode,
  503. codec_data->info->params.modes.bitrate));
  504. }
  505. return PJ_SUCCESS;
  506. }
  507. #endif /* PJMEDIA_HAS_INTEL_IPP_CODEC_AMR */
  508. #if PJMEDIA_HAS_INTEL_IPP_CODEC_G722_1
  509. static void predecode_g7221( ipp_private_t *codec_data,
  510. const pjmedia_frame *rtp_frame,
  511. USC_Bitstream *usc_frame)
  512. {
  513. usc_frame->pBuffer = (char*)rtp_frame->buf;
  514. usc_frame->nbytes = rtp_frame->size;
  515. usc_frame->frametype = 0;
  516. usc_frame->bitrate = codec_data->info->params.modes.bitrate;
  517. #if defined(PJ_IS_LITTLE_ENDIAN) && PJ_IS_LITTLE_ENDIAN!=0
  518. {
  519. pj_uint16_t *p, *p_end;
  520. p = (pj_uint16_t*)rtp_frame->buf;
  521. p_end = p + rtp_frame->size/2;
  522. while (p < p_end) {
  523. *p = pj_ntohs(*p);
  524. ++p;
  525. }
  526. }
  527. #endif
  528. }
  529. static pj_status_t pack_g7221( ipp_private_t *codec_data, void *pkt,
  530. pj_size_t *pkt_size, pj_size_t max_pkt_size)
  531. {
  532. PJ_UNUSED_ARG(codec_data);
  533. PJ_UNUSED_ARG(max_pkt_size);
  534. #if defined(PJ_IS_LITTLE_ENDIAN) && PJ_IS_LITTLE_ENDIAN!=0
  535. {
  536. pj_uint16_t *p, *p_end;
  537. p = (pj_uint16_t*)pkt;
  538. p_end = p + *pkt_size/2;
  539. while (p < p_end) {
  540. *p = pj_htons(*p);
  541. ++p;
  542. }
  543. }
  544. #else
  545. PJ_UNUSED_ARG(pkt);
  546. PJ_UNUSED_ARG(pkt_size);
  547. #endif
  548. return PJ_SUCCESS;
  549. }
  550. #include <pjmedia-codec/g7221.h>
  551. PJ_DEF(pj_status_t) pjmedia_codec_g7221_set_pcm_shift(int val)
  552. {
  553. PJ_ASSERT_RETURN(val >= 0, PJ_EINVAL);
  554. ipp_factory.g7221_pcm_shift = val;
  555. return PJ_SUCCESS;
  556. }
  557. #endif /* PJMEDIA_HAS_INTEL_IPP_CODEC_G722_1 */
  558. /*
  559. * Initialize and register IPP codec factory to pjmedia endpoint.
  560. */
  561. PJ_DEF(pj_status_t) pjmedia_codec_ipp_init( pjmedia_endpt *endpt )
  562. {
  563. pjmedia_codec_mgr *codec_mgr;
  564. pj_str_t codec_name;
  565. pj_status_t status;
  566. if (ipp_factory.pool != NULL) {
  567. /* Already initialized. */
  568. return PJ_SUCCESS;
  569. }
  570. /* Create IPP codec factory. */
  571. ipp_factory.base.op = &ipp_factory_op;
  572. ipp_factory.base.factory_data = NULL;
  573. ipp_factory.endpt = endpt;
  574. ipp_factory.g7221_pcm_shift = PJMEDIA_G7221_DEFAULT_PCM_SHIFT;
  575. ipp_factory.pool = pjmedia_endpt_create_pool(endpt, "IPP codecs", 4000, 4000);
  576. if (!ipp_factory.pool)
  577. return PJ_ENOMEM;
  578. /* Create mutex. */
  579. status = pj_mutex_create_simple(ipp_factory.pool, "IPP codecs",
  580. &ipp_factory.mutex);
  581. if (status != PJ_SUCCESS)
  582. goto on_error;
  583. /* Get the codec manager. */
  584. codec_mgr = pjmedia_endpt_get_codec_mgr(endpt);
  585. if (!codec_mgr) {
  586. status = PJ_EINVALIDOP;
  587. goto on_error;
  588. }
  589. /* Register format match callback. */
  590. #if PJMEDIA_HAS_INTEL_IPP_CODEC_G722_1
  591. pj_cstr(&codec_name, "G7221");
  592. status = pjmedia_sdp_neg_register_fmt_match_cb(
  593. &codec_name,
  594. &pjmedia_codec_g7221_match_sdp);
  595. if (status != PJ_SUCCESS)
  596. goto on_error;
  597. #endif
  598. #if PJMEDIA_HAS_INTEL_IPP_CODEC_AMR
  599. pj_cstr(&codec_name, "AMR");
  600. status = pjmedia_sdp_neg_register_fmt_match_cb(
  601. &codec_name,
  602. &pjmedia_codec_amr_match_sdp);
  603. if (status != PJ_SUCCESS)
  604. goto on_error;
  605. #endif
  606. #if PJMEDIA_HAS_INTEL_IPP_CODEC_AMRWB
  607. pj_cstr(&codec_name, "AMR-WB");
  608. status = pjmedia_sdp_neg_register_fmt_match_cb(
  609. &codec_name,
  610. &pjmedia_codec_amr_match_sdp);
  611. if (status != PJ_SUCCESS)
  612. goto on_error;
  613. #endif
  614. /* Suppress compile warning */
  615. PJ_UNUSED_ARG(codec_name);
  616. /* Register codec factory to endpoint. */
  617. status = pjmedia_codec_mgr_register_factory(codec_mgr,
  618. &ipp_factory.base);
  619. if (status != PJ_SUCCESS)
  620. goto on_error;
  621. /* Done. */
  622. return PJ_SUCCESS;
  623. on_error:
  624. pj_pool_release(ipp_factory.pool);
  625. ipp_factory.pool = NULL;
  626. return status;
  627. }
  628. /*
  629. * Unregister IPP codecs factory from pjmedia endpoint.
  630. */
  631. PJ_DEF(pj_status_t) pjmedia_codec_ipp_deinit(void)
  632. {
  633. pjmedia_codec_mgr *codec_mgr;
  634. pj_status_t status;
  635. if (ipp_factory.pool == NULL) {
  636. /* Already deinitialized */
  637. return PJ_SUCCESS;
  638. }
  639. pj_mutex_lock(ipp_factory.mutex);
  640. /* Get the codec manager. */
  641. codec_mgr = pjmedia_endpt_get_codec_mgr(ipp_factory.endpt);
  642. if (!codec_mgr) {
  643. pj_pool_release(ipp_factory.pool);
  644. ipp_factory.pool = NULL;
  645. pj_mutex_unlock(ipp_factory.mutex);
  646. return PJ_EINVALIDOP;
  647. }
  648. /* Unregister IPP codecs factory. */
  649. status = pjmedia_codec_mgr_unregister_factory(codec_mgr,
  650. &ipp_factory.base);
  651. /* Destroy mutex. */
  652. pj_mutex_unlock(ipp_factory.mutex);
  653. pj_mutex_destroy(ipp_factory.mutex);
  654. ipp_factory.mutex = NULL;
  655. /* Destroy pool. */
  656. pj_pool_release(ipp_factory.pool);
  657. ipp_factory.pool = NULL;
  658. return status;
  659. }
  660. /*
  661. * Check if factory can allocate the specified codec.
  662. */
  663. static pj_status_t ipp_test_alloc( pjmedia_codec_factory *factory,
  664. const pjmedia_codec_info *info )
  665. {
  666. unsigned i;
  667. PJ_UNUSED_ARG(factory);
  668. /* Type MUST be audio. */
  669. if (info->type != PJMEDIA_TYPE_AUDIO)
  670. return PJMEDIA_CODEC_EUNSUP;
  671. for (i = 0; i < PJ_ARRAY_SIZE(ipp_codec); ++i) {
  672. pj_str_t name = pj_str((char*)ipp_codec[i].name);
  673. if ((pj_stricmp(&info->encoding_name, &name) == 0) &&
  674. (info->clock_rate == (unsigned)ipp_codec[i].clock_rate) &&
  675. (info->channel_cnt == (unsigned)ipp_codec[i].channel_count) &&
  676. (ipp_codec[i].enabled))
  677. {
  678. return PJ_SUCCESS;
  679. }
  680. }
  681. /* Unsupported, or mode is disabled. */
  682. return PJMEDIA_CODEC_EUNSUP;
  683. }
  684. /*
  685. * Generate default attribute.
  686. */
  687. static pj_status_t ipp_default_attr (pjmedia_codec_factory *factory,
  688. const pjmedia_codec_info *id,
  689. pjmedia_codec_param *attr )
  690. {
  691. unsigned i;
  692. PJ_ASSERT_RETURN(factory==&ipp_factory.base, PJ_EINVAL);
  693. pj_bzero(attr, sizeof(pjmedia_codec_param));
  694. for (i = 0; i < PJ_ARRAY_SIZE(ipp_codec); ++i) {
  695. pj_str_t name = pj_str((char*)ipp_codec[i].name);
  696. if ((pj_stricmp(&id->encoding_name, &name) == 0) &&
  697. (id->clock_rate == (unsigned)ipp_codec[i].clock_rate) &&
  698. (id->channel_cnt == (unsigned)ipp_codec[i].channel_count) &&
  699. (id->pt == (unsigned)ipp_codec[i].pt))
  700. {
  701. attr->info.pt = (pj_uint8_t)id->pt;
  702. attr->info.channel_cnt = ipp_codec[i].channel_count;
  703. attr->info.clock_rate = ipp_codec[i].clock_rate;
  704. attr->info.avg_bps = ipp_codec[i].def_bitrate;
  705. attr->info.max_bps = ipp_codec[i].max_bitrate;
  706. attr->info.pcm_bits_per_sample = 16;
  707. attr->info.frm_ptime = (pj_uint16_t)
  708. (ipp_codec[i].samples_per_frame * 1000 /
  709. ipp_codec[i].channel_count /
  710. ipp_codec[i].clock_rate);
  711. attr->setting.frm_per_pkt = ipp_codec[i].frm_per_pkt;
  712. /* Default flags. */
  713. attr->setting.plc = 1;
  714. attr->setting.penh= 0;
  715. attr->setting.vad = 1;
  716. attr->setting.cng = attr->setting.vad;
  717. attr->setting.dec_fmtp = ipp_codec[i].dec_fmtp;
  718. if (attr->setting.vad == 0) {
  719. #if PJMEDIA_HAS_INTEL_IPP_CODEC_G729
  720. if (id->pt == PJMEDIA_RTP_PT_G729) {
  721. /* Signal G729 Annex B is being disabled */
  722. attr->setting.dec_fmtp.cnt = 1;
  723. pj_strset2(&attr->setting.dec_fmtp.param[0].name, "annexb");
  724. pj_strset2(&attr->setting.dec_fmtp.param[0].val, "no");
  725. }
  726. #endif
  727. }
  728. return PJ_SUCCESS;
  729. }
  730. }
  731. return PJMEDIA_CODEC_EUNSUP;
  732. }
  733. /*
  734. * Enum codecs supported by this factory.
  735. */
  736. static pj_status_t ipp_enum_codecs(pjmedia_codec_factory *factory,
  737. unsigned *count,
  738. pjmedia_codec_info codecs[])
  739. {
  740. unsigned max;
  741. unsigned i;
  742. PJ_UNUSED_ARG(factory);
  743. PJ_ASSERT_RETURN(codecs && *count > 0, PJ_EINVAL);
  744. max = *count;
  745. for (i = 0, *count = 0; i < PJ_ARRAY_SIZE(ipp_codec) && *count < max; ++i)
  746. {
  747. if (!ipp_codec[i].enabled)
  748. continue;
  749. pj_bzero(&codecs[*count], sizeof(pjmedia_codec_info));
  750. codecs[*count].encoding_name = pj_str((char*)ipp_codec[i].name);
  751. codecs[*count].pt = ipp_codec[i].pt;
  752. codecs[*count].type = PJMEDIA_TYPE_AUDIO;
  753. codecs[*count].clock_rate = ipp_codec[i].clock_rate;
  754. codecs[*count].channel_cnt = ipp_codec[i].channel_count;
  755. ++*count;
  756. }
  757. return PJ_SUCCESS;
  758. }
  759. /*
  760. * Allocate a new codec instance.
  761. */
  762. static pj_status_t ipp_alloc_codec( pjmedia_codec_factory *factory,
  763. const pjmedia_codec_info *id,
  764. pjmedia_codec **p_codec)
  765. {
  766. ipp_private_t *codec_data;
  767. pjmedia_codec *codec;
  768. int idx;
  769. pj_pool_t *pool;
  770. unsigned i;
  771. PJ_ASSERT_RETURN(factory && id && p_codec, PJ_EINVAL);
  772. PJ_ASSERT_RETURN(factory == &ipp_factory.base, PJ_EINVAL);
  773. pj_mutex_lock(ipp_factory.mutex);
  774. /* Find codec's index */
  775. idx = -1;
  776. for (i = 0; i < PJ_ARRAY_SIZE(ipp_codec); ++i) {
  777. pj_str_t name = pj_str((char*)ipp_codec[i].name);
  778. if ((pj_stricmp(&id->encoding_name, &name) == 0) &&
  779. (id->clock_rate == (unsigned)ipp_codec[i].clock_rate) &&
  780. (id->channel_cnt == (unsigned)ipp_codec[i].channel_count) &&
  781. (ipp_codec[i].enabled))
  782. {
  783. idx = i;
  784. break;
  785. }
  786. }
  787. if (idx == -1) {
  788. *p_codec = NULL;
  789. pj_mutex_unlock(ipp_factory.mutex);
  790. return PJMEDIA_CODEC_EFAILED;
  791. }
  792. /* Create pool for codec instance */
  793. pool = pjmedia_endpt_create_pool(ipp_factory.endpt, "IPPcodec", 512, 512);
  794. codec = PJ_POOL_ZALLOC_T(pool, pjmedia_codec);
  795. PJ_ASSERT_RETURN(codec != NULL, PJ_ENOMEM);
  796. codec->op = &ipp_op;
  797. codec->factory = factory;
  798. codec->codec_data = PJ_POOL_ZALLOC_T(pool, ipp_private_t);
  799. codec_data = (ipp_private_t*) codec->codec_data;
  800. /* Create PLC if codec has no internal PLC */
  801. if (!ipp_codec[idx].has_native_plc) {
  802. pj_status_t status;
  803. status = pjmedia_plc_create(pool, ipp_codec[idx].clock_rate,
  804. ipp_codec[idx].samples_per_frame, 0,
  805. &codec_data->plc);
  806. if (status != PJ_SUCCESS) {
  807. pj_pool_release(pool);
  808. pj_mutex_unlock(ipp_factory.mutex);
  809. return status;
  810. }
  811. }
  812. /* Create silence detector if codec has no internal VAD */
  813. if (!ipp_codec[idx].has_native_vad) {
  814. pj_status_t status;
  815. status = pjmedia_silence_det_create(pool,
  816. ipp_codec[idx].clock_rate,
  817. ipp_codec[idx].samples_per_frame,
  818. &codec_data->vad);
  819. if (status != PJ_SUCCESS) {
  820. pj_pool_release(pool);
  821. pj_mutex_unlock(ipp_factory.mutex);
  822. return status;
  823. }
  824. }
  825. codec_data->pool = pool;
  826. codec_data->codec_idx = idx;
  827. pj_mutex_unlock(ipp_factory.mutex);
  828. *p_codec = codec;
  829. return PJ_SUCCESS;
  830. }
  831. /*
  832. * Free codec.
  833. */
  834. static pj_status_t ipp_dealloc_codec( pjmedia_codec_factory *factory,
  835. pjmedia_codec *codec )
  836. {
  837. ipp_private_t *codec_data;
  838. PJ_ASSERT_RETURN(factory && codec, PJ_EINVAL);
  839. PJ_ASSERT_RETURN(factory == &ipp_factory.base, PJ_EINVAL);
  840. /* Close codec, if it's not closed. */
  841. codec_data = (ipp_private_t*) codec->codec_data;
  842. if (codec_data->enc != NULL || codec_data->dec != NULL) {
  843. ipp_codec_close(codec);
  844. }
  845. pj_pool_release(codec_data->pool);
  846. return PJ_SUCCESS;
  847. }
  848. /*
  849. * Init codec.
  850. */
  851. static pj_status_t ipp_codec_init( pjmedia_codec *codec,
  852. pj_pool_t *pool )
  853. {
  854. PJ_UNUSED_ARG(codec);
  855. PJ_UNUSED_ARG(pool);
  856. return PJ_SUCCESS;
  857. }
  858. /*
  859. * Open codec.
  860. */
  861. static pj_status_t ipp_codec_open( pjmedia_codec *codec,
  862. pjmedia_codec_param *attr )
  863. {
  864. ipp_private_t *codec_data = (ipp_private_t*) codec->codec_data;
  865. struct ipp_codec *ippc = &ipp_codec[codec_data->codec_idx];
  866. int info_size;
  867. pj_pool_t *pool;
  868. int i, j;
  869. USC_MemBank *membanks;
  870. int nb_membanks;
  871. pool = codec_data->pool;
  872. /* Get the codec info size */
  873. if (USC_NoError != ippc->fxns->std.GetInfoSize(&info_size)) {
  874. PJ_LOG(1,(THIS_FILE, "Error getting codec info size"));
  875. goto on_error;
  876. }
  877. /* Get the codec info */
  878. codec_data->info = pj_pool_zalloc(pool, info_size);
  879. if (USC_NoError != ippc->fxns->std.GetInfo((USC_Handle)NULL,
  880. codec_data->info))
  881. {
  882. PJ_LOG(1,(THIS_FILE, "Error getting codec info"));
  883. goto on_error;
  884. }
  885. /* PREPARING THE ENCODER */
  886. /* Setting the encoder params */
  887. codec_data->info->params.direction = USC_ENCODE;
  888. codec_data->info->params.modes.vad = attr->setting.vad &&
  889. ippc->has_native_vad;
  890. codec_data->info->params.modes.bitrate = attr->info.avg_bps;
  891. codec_data->info->params.law = 0; /* Linear PCM input */
  892. #if PJMEDIA_HAS_INTEL_IPP_CODEC_G729
  893. if (ippc->pt == PJMEDIA_RTP_PT_G729) {
  894. /* Check if G729 Annex B is signaled to be disabled */
  895. for (i = 0; i < attr->setting.enc_fmtp.cnt; ++i) {
  896. if (pj_stricmp2(&attr->setting.enc_fmtp.param[i].name, "annexb")==0)
  897. {
  898. if (pj_stricmp2(&attr->setting.enc_fmtp.param[i].val, "no")==0)
  899. {
  900. attr->setting.vad = 0;
  901. codec_data->info->params.modes.vad = 0;
  902. }
  903. break;
  904. }
  905. }
  906. }
  907. #endif
  908. /* Get number of memory blocks needed by the encoder */
  909. if (USC_NoError != ippc->fxns->std.NumAlloc(&codec_data->info->params,
  910. &nb_membanks))
  911. {
  912. PJ_LOG(1,(THIS_FILE, "Error getting no of memory blocks of encoder"));
  913. goto on_error;
  914. }
  915. /* Allocate memory blocks table */
  916. membanks = (USC_MemBank*) pj_pool_zalloc(pool,
  917. sizeof(USC_MemBank) * nb_membanks);
  918. /* Get size of each memory block */
  919. if (USC_NoError != ippc->fxns->std.MemAlloc(&codec_data->info->params,
  920. membanks))
  921. {
  922. PJ_LOG(1,(THIS_FILE, "Error getting memory blocks size of encoder"));
  923. goto on_error;
  924. }
  925. /* Allocate memory for each block */
  926. for (i = 0; i < nb_membanks; i++) {
  927. membanks[i].pMem = (char*) pj_pool_zalloc(pool, membanks[i].nbytes);
  928. }
  929. /* Create encoder instance */
  930. if (USC_NoError != ippc->fxns->std.Init(&codec_data->info->params,
  931. membanks,
  932. &codec_data->enc))
  933. {
  934. PJ_LOG(1,(THIS_FILE, "Error initializing encoder"));
  935. goto on_error;
  936. }
  937. /* PREPARING THE DECODER */
  938. /* Setting the decoder params */
  939. codec_data->info->params.direction = USC_DECODE;
  940. /* Not sure if VAD affects decoder, just try to be safe */
  941. //codec_data->info->params.modes.vad = ippc->has_native_vad;
  942. /* Get number of memory blocks needed by the decoder */
  943. if (USC_NoError != ippc->fxns->std.NumAlloc(&codec_data->info->params,
  944. &nb_membanks))
  945. {
  946. PJ_LOG(1,(THIS_FILE, "Error getting no of memory blocks of decoder"));
  947. goto on_error;
  948. }
  949. /* Allocate memory blocks table */
  950. membanks = (USC_MemBank*) pj_pool_zalloc(pool,
  951. sizeof(USC_MemBank) * nb_membanks);
  952. /* Get size of each memory block */
  953. if (USC_NoError != ippc->fxns->std.MemAlloc(&codec_data->info->params,
  954. membanks))
  955. {
  956. PJ_LOG(1,(THIS_FILE, "Error getting memory blocks size of decoder"));
  957. goto on_error;
  958. }
  959. /* Allocate memory for each block */
  960. for (i = 0; i < nb_membanks; i++) {
  961. membanks[i].pMem = (char*) pj_pool_zalloc(pool, membanks[i].nbytes);
  962. }
  963. /* Create decoder instance */
  964. if (USC_NoError != ippc->fxns->std.Init(&codec_data->info->params,
  965. membanks, &codec_data->dec))
  966. {
  967. PJ_LOG(1,(THIS_FILE, "Error initializing decoder"));
  968. goto on_error;
  969. }
  970. /* Update codec info */
  971. ippc->fxns->std.GetInfo((USC_Handle)codec_data->enc, codec_data->info);
  972. /* Get bitstream size */
  973. i = codec_data->info->params.modes.bitrate * ippc->samples_per_frame;
  974. j = ippc->clock_rate << 3;
  975. codec_data->frame_size = (pj_uint16_t)(i / j);
  976. if (i % j) ++codec_data->frame_size;
  977. codec_data->vad_enabled = (attr->setting.vad != 0);
  978. codec_data->plc_enabled = (attr->setting.plc != 0);
  979. #if PJMEDIA_HAS_INTEL_IPP_CODEC_AMR
  980. /* Init AMR settings */
  981. if (ippc->pt == PJMEDIA_RTP_PT_AMR || ippc->pt == PJMEDIA_RTP_PT_AMRWB) {
  982. amr_settings_t *s;
  983. pj_uint8_t octet_align = 0;
  984. pj_int8_t enc_mode;
  985. enc_mode = pjmedia_codec_amr_get_mode(
  986. codec_data->info->params.modes.bitrate);
  987. pj_assert(enc_mode >= 0 && enc_mode <= 8);
  988. /* Check AMR specific attributes */
  989. for (i = 0; i < attr->setting.dec_fmtp.cnt; ++i) {
  990. /* octet-align, one of the parameters that must have same value
  991. * in offer & answer (RFC 4867 Section 8.3.1). Just check fmtp
  992. * in the decoder side, since it's value is guaranteed to fulfil
  993. * above requirement (by SDP negotiator).
  994. */
  995. const pj_str_t STR_FMTP_OCTET_ALIGN = {"octet-align", 11};
  996. if (pj_stricmp(&attr->setting.dec_fmtp.param[i].name,
  997. &STR_FMTP_OCTET_ALIGN) == 0)
  998. {
  999. octet_align=(pj_uint8_t)
  1000. pj_strtoul(&attr->setting.dec_fmtp.param[i].val);
  1001. break;
  1002. }
  1003. }
  1004. for (i = 0; i < attr->setting.enc_fmtp.cnt; ++i) {
  1005. /* mode-set, encoding mode is chosen based on local default mode
  1006. * setting:
  1007. * - if local default mode is included in the mode-set, use it
  1008. * - otherwise, find the closest mode to local default mode;
  1009. * if there are two closest modes, prefer to use the higher
  1010. * one, e.g: local default mode is 4, the mode-set param
  1011. * contains '2,3,5,6', then 5 will be chosen.
  1012. */
  1013. const pj_str_t STR_FMTP_MODE_SET = {"mode-set", 8};
  1014. if (pj_stricmp(&attr->setting.enc_fmtp.param[i].name,
  1015. &STR_FMTP_MODE_SET) == 0)
  1016. {
  1017. const char *p;
  1018. pj_size_t l;
  1019. pj_int8_t diff = 99;
  1020. p = pj_strbuf(&attr->setting.enc_fmtp.param[i].val);
  1021. l = pj_strlen(&attr->setting.enc_fmtp.param[i].val);
  1022. while (l--) {
  1023. if ((ippc->pt==PJMEDIA_RTP_PT_AMR && *p>='0' && *p<='7') ||
  1024. (ippc->pt==PJMEDIA_RTP_PT_AMRWB && *p>='0' && *p<='8'))
  1025. {
  1026. pj_int8_t tmp = (pj_int8_t)(*p - '0' - enc_mode);
  1027. if (PJ_ABS(diff) > PJ_ABS(tmp) ||
  1028. (PJ_ABS(diff) == PJ_ABS(tmp) && tmp > diff))
  1029. {
  1030. diff = tmp;
  1031. if (diff == 0) break;
  1032. }
  1033. }
  1034. ++p;
  1035. }
  1036. if (diff == 99)
  1037. goto on_error;
  1038. enc_mode = (pj_int8_t)(enc_mode + diff);
  1039. break;
  1040. }
  1041. }
  1042. /* Initialize AMR specific settings */
  1043. s = PJ_POOL_ZALLOC_T(pool, amr_settings_t);
  1044. codec_data->codec_setting = s;
  1045. s->enc_setting.amr_nb = (pj_uint8_t)(ippc->pt == PJMEDIA_RTP_PT_AMR);
  1046. s->enc_setting.octet_aligned = octet_align;
  1047. s->enc_setting.reorder = PJ_TRUE;
  1048. s->enc_setting.cmr = 15;
  1049. s->dec_setting.amr_nb = (pj_uint8_t)(ippc->pt == PJMEDIA_RTP_PT_AMR);
  1050. s->dec_setting.octet_aligned = octet_align;
  1051. s->dec_setting.reorder = PJ_TRUE;
  1052. /* Apply encoder mode/bitrate */
  1053. s->enc_mode = enc_mode;
  1054. codec_data->info->params.modes.bitrate = s->enc_setting.amr_nb?
  1055. pjmedia_codec_amrnb_bitrates[s->enc_mode]:
  1056. pjmedia_codec_amrwb_bitrates[s->enc_mode];
  1057. ippc->fxns->std.Control(&codec_data->info->params.modes,
  1058. codec_data->enc);
  1059. PJ_LOG(4,(THIS_FILE, "AMR%s encoding mode: %d (%dbps)",
  1060. (s->enc_setting.amr_nb?"":"-WB"),
  1061. s->enc_mode,
  1062. codec_data->info->params.modes.bitrate));
  1063. /* Return back bitrate info to application */
  1064. attr->info.avg_bps = codec_data->info->params.modes.bitrate;
  1065. }
  1066. #endif
  1067. #if PJMEDIA_HAS_INTEL_IPP_CODEC_G722_1
  1068. if (ippc->pt >= PJMEDIA_RTP_PT_G722_1_16 &&
  1069. ippc->pt <= PJMEDIA_RTP_PT_G7221_RSV2)
  1070. {
  1071. codec_data->g7221_pcm_shift = ipp_factory.g7221_pcm_shift;
  1072. }
  1073. #endif
  1074. return PJ_SUCCESS;
  1075. on_error:
  1076. return PJMEDIA_CODEC_EFAILED;
  1077. }
  1078. /*
  1079. * Close codec.
  1080. */
  1081. static pj_status_t ipp_codec_close( pjmedia_codec *codec )
  1082. {
  1083. PJ_UNUSED_ARG(codec);
  1084. return PJ_SUCCESS;
  1085. }
  1086. /*
  1087. * Modify codec settings.
  1088. */
  1089. static pj_status_t ipp_codec_modify(pjmedia_codec *codec,
  1090. const pjmedia_codec_param *attr )
  1091. {
  1092. ipp_private_t *codec_data = (ipp_private_t*) codec->codec_data;
  1093. struct ipp_codec *ippc = &ipp_codec[codec_data->codec_idx];
  1094. codec_data->vad_enabled = (attr->setting.vad != 0);
  1095. codec_data->plc_enabled = (attr->setting.plc != 0);
  1096. if (ippc->has_native_vad) {
  1097. USC_Modes modes;
  1098. modes = codec_data->info->params.modes;
  1099. modes.vad = codec_data->vad_enabled;
  1100. ippc->fxns->std.Control(&modes, codec_data->enc);
  1101. }
  1102. return PJ_SUCCESS;
  1103. }
  1104. /*
  1105. * Get frames in the packet.
  1106. */
  1107. static pj_status_t ipp_codec_parse( pjmedia_codec *codec,
  1108. void *pkt,
  1109. pj_size_t pkt_size,
  1110. const pj_timestamp *ts,
  1111. unsigned *frame_cnt,
  1112. pjmedia_frame frames[])
  1113. {
  1114. ipp_private_t *codec_data = (ipp_private_t*) codec->codec_data;
  1115. struct ipp_codec *ippc = &ipp_codec[codec_data->codec_idx];
  1116. unsigned count = 0;
  1117. PJ_ASSERT_RETURN(frame_cnt, PJ_EINVAL);
  1118. if (ippc->parse != NULL) {
  1119. return ippc->parse(codec_data, pkt, pkt_size, ts, frame_cnt, frames);
  1120. }
  1121. while (pkt_size >= codec_data->frame_size && count < *frame_cnt) {
  1122. frames[count].type = PJMEDIA_FRAME_TYPE_AUDIO;
  1123. frames[count].buf = pkt;
  1124. frames[count].size = codec_data->frame_size;
  1125. frames[count].timestamp.u64 = ts->u64 + count*ippc->samples_per_frame;
  1126. pkt = ((char*)pkt) + codec_data->frame_size;
  1127. pkt_size -= codec_data->frame_size;
  1128. ++count;
  1129. }
  1130. if (pkt_size && count < *frame_cnt) {
  1131. frames[count].type = PJMEDIA_FRAME_TYPE_AUDIO;
  1132. frames[count].buf = pkt;
  1133. frames[count].size = pkt_size;
  1134. frames[count].timestamp.u64 = ts->u64 + count*ippc->samples_per_frame;
  1135. ++count;
  1136. }
  1137. *frame_cnt = count;
  1138. return PJ_SUCCESS;
  1139. }
  1140. /*
  1141. * Encode frames.
  1142. */
  1143. static pj_status_t ipp_codec_encode( pjmedia_codec *codec,
  1144. const struct pjmedia_frame *input,
  1145. unsigned output_buf_len,
  1146. struct pjmedia_frame *output)
  1147. {
  1148. ipp_private_t *codec_data = (ipp_private_t*) codec->codec_data;
  1149. struct ipp_codec *ippc = &ipp_codec[codec_data->codec_idx];
  1150. unsigned samples_per_frame;
  1151. unsigned nsamples;
  1152. pj_size_t tx = 0;
  1153. pj_int16_t *pcm_in = (pj_int16_t*)input->buf;
  1154. pj_uint8_t *bits_out = (pj_uint8_t*) output->buf;
  1155. pj_uint8_t pt;
  1156. /* Invoke external VAD if codec has no internal VAD */
  1157. if (codec_data->vad && codec_data->vad_enabled) {
  1158. pj_bool_t is_silence;
  1159. pj_int32_t silence_duration;
  1160. silence_duration = pj_timestamp_diff32(&codec_data->last_tx,
  1161. &input->timestamp);
  1162. is_silence = pjmedia_silence_det_detect(codec_data->vad,
  1163. (const pj_int16_t*) input->buf,
  1164. (input->size >> 1),
  1165. NULL);
  1166. if (is_silence &&
  1167. (PJMEDIA_CODEC_MAX_SILENCE_PERIOD == -1 ||
  1168. silence_duration < (PJMEDIA_CODEC_MAX_SILENCE_PERIOD *
  1169. (int)ippc->clock_rate / 1000)))
  1170. {
  1171. output->type = PJMEDIA_FRAME_TYPE_NONE;
  1172. output->buf = NULL;
  1173. output->size = 0;
  1174. output->timestamp = input->timestamp;
  1175. return PJ_SUCCESS;
  1176. } else {
  1177. codec_data->last_tx = input->timestamp;
  1178. }
  1179. }
  1180. nsamples = input->size >> 1;
  1181. samples_per_frame = ippc->samples_per_frame;
  1182. pt = ippc->pt;
  1183. PJ_ASSERT_RETURN(nsamples % samples_per_frame == 0,
  1184. PJMEDIA_CODEC_EPCMFRMINLEN);
  1185. /* Encode the frames */
  1186. while (nsamples >= samples_per_frame) {
  1187. USC_PCMStream in;
  1188. USC_Bitstream out;
  1189. in.bitrate = codec_data->info->params.modes.bitrate;
  1190. in.nbytes = samples_per_frame << 1;
  1191. in.pBuffer = (char*)pcm_in;
  1192. in.pcmType.bitPerSample = codec_data->info->params.pcmType.bitPerSample;
  1193. in.pcmType.nChannels = codec_data->info->params.pcmType.nChannels;
  1194. in.pcmType.sample_frequency = codec_data->info->params.pcmType.sample_frequency;
  1195. out.pBuffer = (char*)bits_out;
  1196. #if PJMEDIA_HAS_INTEL_IPP_CODEC_AMR
  1197. /* For AMR: reserve two octets for AMR frame info */
  1198. if (pt == PJMEDIA_RTP_PT_AMR || pt == PJMEDIA_RTP_PT_AMRWB) {
  1199. out.pBuffer += 2;
  1200. }
  1201. #endif
  1202. #if PJMEDIA_HAS_INTEL_IPP_CODEC_G722_1
  1203. /* For G722.1: adjust the encoder input signal level */
  1204. if (pt >= PJMEDIA_RTP_PT_G722_1_16 &&
  1205. pt <= PJMEDIA_RTP_PT_G7221_RSV2 &&
  1206. codec_data->g7221_pcm_shift)
  1207. {
  1208. unsigned i;
  1209. for (i = 0; i < samples_per_frame; ++i)
  1210. pcm_in[i] >>= codec_data->g7221_pcm_shift;
  1211. }
  1212. #endif
  1213. if (USC_NoError != ippc->fxns->Encode(codec_data->enc, &in, &out)) {
  1214. break;
  1215. }
  1216. #if PJMEDIA_HAS_INTEL_IPP_CODEC_AMR
  1217. /* For AMR: put info (frametype, degraded, last frame, mode) in the
  1218. * first two octets for payload packing.
  1219. */
  1220. if (pt == PJMEDIA_RTP_PT_AMR || pt == PJMEDIA_RTP_PT_AMRWB) {
  1221. pj_uint16_t *info = (pj_uint16_t*)bits_out;
  1222. /* Two octets for AMR frame info, 0=LSB:
  1223. * bit 0-3 : frame type
  1224. * bit 5 : STI flag
  1225. * bit 6 : last frame flag
  1226. * bit 7 : quality flag
  1227. * bit 8-11 : mode
  1228. */
  1229. out.nbytes += 2;
  1230. if (out.frametype == 0 || out.frametype == 4 ||
  1231. (pt == PJMEDIA_RTP_PT_AMR && out.frametype == 5) ||
  1232. (pt == PJMEDIA_RTP_PT_AMRWB && out.frametype == 6))
  1233. {
  1234. /* Speech frame type */
  1235. *info = (char)pjmedia_codec_amr_get_mode(out.bitrate);
  1236. /* Quality */
  1237. if (out.frametype == 5 || out.frametype == 6)
  1238. *info |= 0x80;
  1239. } else if (out.frametype == 1 || out.frametype == 2 ||
  1240. (pt == PJMEDIA_RTP_PT_AMR && out.frametype == 6) ||
  1241. (pt == PJMEDIA_RTP_PT_AMRWB && out.frametype == 7))
  1242. {
  1243. /* SID frame type */
  1244. *info = (pj_uint8_t)(pt == PJMEDIA_RTP_PT_AMRWB? 9 : 8);
  1245. /* Quality */
  1246. if (out.frametype == 6 || out.frametype == 7)
  1247. *info |= 0x80;
  1248. /* STI */
  1249. if (out.frametype != 1)
  1250. *info |= 0x20;
  1251. } else {
  1252. /* Untransmited */
  1253. *info = 15;
  1254. out.nbytes = 2;
  1255. }
  1256. /* Mode */
  1257. *info |= (char)pjmedia_codec_amr_get_mode(out.bitrate) << 8;
  1258. /* Last frame flag */
  1259. if (nsamples == samples_per_frame)
  1260. *info |= 0x40;
  1261. }
  1262. #endif
  1263. pcm_in += samples_per_frame;
  1264. nsamples -= samples_per_frame;
  1265. tx += out.nbytes;
  1266. bits_out += out.nbytes;
  1267. #if PJMEDIA_HAS_INTEL_IPP_CODEC_G729
  1268. if (pt == PJMEDIA_RTP_PT_G729) {
  1269. if (out.frametype == 1) {
  1270. /* SID */
  1271. break;
  1272. } else if (out.frametype == 0) {
  1273. /* Untransmitted */
  1274. tx -= out.nbytes;
  1275. break;
  1276. }
  1277. }
  1278. #endif
  1279. }
  1280. if (ippc->pack != NULL) {
  1281. ippc->pack(codec_data, output->buf, &tx, output_buf_len);
  1282. }
  1283. /* Check if we don't need to transmit the frame (DTX) */
  1284. if (tx == 0) {
  1285. output->buf = NULL;
  1286. output->size = 0;
  1287. output->timestamp.u64 = input->timestamp.u64;
  1288. output->type = PJMEDIA_FRAME_TYPE_NONE;
  1289. return PJ_SUCCESS;
  1290. }
  1291. output->size = tx;
  1292. output->type = PJMEDIA_FRAME_TYPE_AUDIO;
  1293. output->timestamp = input->timestamp;
  1294. return PJ_SUCCESS;
  1295. }
  1296. /*
  1297. * Decode frame.
  1298. */
  1299. static pj_status_t ipp_codec_decode( pjmedia_codec *codec,
  1300. const struct pjmedia_frame *input,
  1301. unsigned output_buf_len,
  1302. struct pjmedia_frame *output)
  1303. {
  1304. ipp_private_t *codec_data = (ipp_private_t*) codec->codec_data;
  1305. struct ipp_codec *ippc = &ipp_codec[codec_data->codec_idx];
  1306. unsigned samples_per_frame;
  1307. USC_PCMStream out;
  1308. USC_Bitstream in;
  1309. pj_uint8_t pt;
  1310. pt = ippc->pt;
  1311. samples_per_frame = ippc->samples_per_frame;
  1312. PJ_ASSERT_RETURN(output_buf_len >= samples_per_frame << 1,
  1313. PJMEDIA_CODEC_EPCMTOOSHORT);
  1314. if (input->type == PJMEDIA_FRAME_TYPE_AUDIO) {
  1315. if (ippc->predecode) {
  1316. ippc->predecode(codec_data, input, &in);
  1317. } else {
  1318. /* Most IPP codecs have frametype==0 for speech frame */
  1319. in.pBuffer = (char*)input->buf;
  1320. in.nbytes = input->size;
  1321. in.frametype = 0;
  1322. in.bitrate = codec_data->info->params.modes.bitrate;
  1323. }
  1324. out.pBuffer = output->buf;
  1325. }
  1326. if (input->type != PJMEDIA_FRAME_TYPE_AUDIO ||
  1327. USC_NoError != ippc->fxns->Decode(codec_data->dec, &in, &out))
  1328. {
  1329. pjmedia_zero_samples((pj_int16_t*)output->buf, samples_per_frame);
  1330. output->size = samples_per_frame << 1;
  1331. output->timestamp.u64 = input->timestamp.u64;
  1332. output->type = PJMEDIA_FRAME_TYPE_AUDIO;
  1333. return PJ_SUCCESS;
  1334. }
  1335. #if PJMEDIA_HAS_INTEL_IPP_CODEC_G726
  1336. /* For G.726: amplify decoding result (USC G.726 encoder deamplified it) */
  1337. if (pt == PJMEDIA_RTP_PT_G726_16 || pt == PJMEDIA_RTP_PT_G726_24 ||
  1338. pt == PJMEDIA_RTP_PT_G726_32 || pt == PJMEDIA_RTP_PT_G726_40 ||
  1339. pt == PJMEDIA_RTP_PT_G721)
  1340. {
  1341. unsigned i;
  1342. pj_int16_t *s = (pj_int16_t*)output->buf;
  1343. for (i = 0; i < samples_per_frame; ++i)
  1344. s[i] <<= 2;
  1345. }
  1346. #endif
  1347. #if PJMEDIA_HAS_INTEL_IPP_CODEC_G722_1
  1348. /* For G722.1: adjust the decoder output signal level */
  1349. if (pt >= PJMEDIA_RTP_PT_G722_1_16 &&
  1350. pt <= PJMEDIA_RTP_PT_G7221_RSV2 &&
  1351. codec_data->g7221_pcm_shift)
  1352. {
  1353. unsigned i;
  1354. pj_int16_t *s = (pj_int16_t*)output->buf;
  1355. for (i = 0; i < samples_per_frame; ++i)
  1356. s[i] <<= codec_data->g7221_pcm_shift;
  1357. }
  1358. #endif
  1359. output->type = PJMEDIA_FRAME_TYPE_AUDIO;
  1360. output->size = samples_per_frame << 1;
  1361. output->timestamp.u64 = input->timestamp.u64;
  1362. /* Invoke external PLC if codec has no internal PLC */
  1363. if (codec_data->plc && codec_data->plc_enabled)
  1364. pjmedia_plc_save(codec_data->plc, (pj_int16_t*)output->buf);
  1365. return PJ_SUCCESS;
  1366. }
  1367. /*
  1368. * Recover lost frame.
  1369. */
  1370. static pj_status_t ipp_codec_recover(pjmedia_codec *codec,
  1371. unsigned output_buf_len,
  1372. struct pjmedia_frame *output)
  1373. {
  1374. ipp_private_t *codec_data = (ipp_private_t*) codec->codec_data;
  1375. struct ipp_codec *ippc = &ipp_codec[codec_data->codec_idx];
  1376. unsigned samples_per_frame;
  1377. PJ_UNUSED_ARG(output_buf_len);
  1378. samples_per_frame = ippc->samples_per_frame;
  1379. output->type = PJMEDIA_FRAME_TYPE_AUDIO;
  1380. output->size = samples_per_frame << 1;
  1381. if (codec_data->plc_enabled) {
  1382. if (codec_data->plc) {
  1383. pjmedia_plc_generate(codec_data->plc, (pj_int16_t*)output->buf);
  1384. } else {
  1385. USC_PCMStream out;
  1386. out.pBuffer = output->buf;
  1387. ippc->fxns->Decode(codec_data->dec, NULL, &out);
  1388. }
  1389. } else {
  1390. pjmedia_zero_samples((pj_int16_t*)output->buf, samples_per_frame);
  1391. }
  1392. return PJ_SUCCESS;
  1393. }
  1394. #if defined(_MSC_VER) && PJMEDIA_AUTO_LINK_IPP_LIBS
  1395. # pragma comment( lib, "ippcore.lib")
  1396. # pragma comment( lib, "ipps.lib")
  1397. # pragma comment( lib, "ippsc.lib")
  1398. # if defined(IPP_VERSION_MAJOR) && IPP_VERSION_MAJOR<=6
  1399. # pragma comment( lib, "ippsr.lib")
  1400. # endif
  1401. //# pragma comment( lib, "ippcorel.lib")
  1402. //# pragma comment( lib, "ippsemerged.lib")
  1403. //# pragma comment( lib, "ippsmerged.lib")
  1404. //# pragma comment( lib, "ippscemerged.lib")
  1405. //# pragma comment( lib, "ippscmerged.lib")
  1406. //# pragma comment( lib, "ippsremerged.lib")
  1407. //# pragma comment( lib, "ippsrmerged.lib")
  1408. # if defined(IPP_VERSION_MAJOR) && IPP_VERSION_MAJOR>=6
  1409. # pragma comment( lib, "speech.lib")
  1410. # else
  1411. # pragma comment( lib, "usc.lib")
  1412. # endif
  1413. #endif
  1414. #endif /* PJMEDIA_HAS_INTEL_IPP */