blob: 36ee6d92beaadd99e77025f31600b1e0ff1d3c9a [file] [log] [blame]
niklase@google.com470e71d2011-07-07 08:21:25 +00001/*
2 * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.
3 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
niklase@google.com470e71d2011-07-07 08:21:25 +000011#include <stdlib.h>
12#include <string.h>
Mirko Bonadeibc3b7822018-02-01 14:30:53 +010013
Mirko Bonadeibc3b7822018-02-01 14:30:53 +010014#include "modules/audio_coding/codecs/g722/g722_interface.h"
Artem Titov52b90002018-07-25 13:13:44 +020015#include "modules/third_party/g722/g722_enc_dec.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000016
pbos@webrtc.org0946a562013-04-09 00:28:06 +000017int16_t WebRtcG722_CreateEncoder(G722EncInst **G722enc_inst)
niklase@google.com470e71d2011-07-07 08:21:25 +000018{
pbos@webrtc.orgeb544462014-12-17 15:23:29 +000019 *G722enc_inst=(G722EncInst*)malloc(sizeof(G722EncoderState));
niklase@google.com470e71d2011-07-07 08:21:25 +000020 if (*G722enc_inst!=NULL) {
21 return(0);
22 } else {
23 return(-1);
24 }
25}
26
pbos@webrtc.org0946a562013-04-09 00:28:06 +000027int16_t WebRtcG722_EncoderInit(G722EncInst *G722enc_inst)
niklase@google.com470e71d2011-07-07 08:21:25 +000028{
29 // Create and/or reset the G.722 encoder
30 // Bitrate 64 kbps and wideband mode (2)
pwestin@webrtc.orgebcb6422011-12-22 12:20:06 +000031 G722enc_inst = (G722EncInst *) WebRtc_g722_encode_init(
pbos@webrtc.orgeb544462014-12-17 15:23:29 +000032 (G722EncoderState*) G722enc_inst, 64000, 2);
niklase@google.com470e71d2011-07-07 08:21:25 +000033 if (G722enc_inst == NULL) {
34 return -1;
35 } else {
36 return 0;
37 }
38}
39
Peter Kastingbba78072015-06-11 19:02:46 -070040int WebRtcG722_FreeEncoder(G722EncInst *G722enc_inst)
niklase@google.com470e71d2011-07-07 08:21:25 +000041{
42 // Free encoder memory
pbos@webrtc.orgeb544462014-12-17 15:23:29 +000043 return WebRtc_g722_encode_release((G722EncoderState*) G722enc_inst);
niklase@google.com470e71d2011-07-07 08:21:25 +000044}
45
Peter Kastingdce40cf2015-08-24 14:52:23 -070046size_t WebRtcG722_Encode(G722EncInst *G722enc_inst,
47 const int16_t* speechIn,
48 size_t len,
49 uint8_t* encoded)
niklase@google.com470e71d2011-07-07 08:21:25 +000050{
51 unsigned char *codechar = (unsigned char*) encoded;
52 // Encode the input speech vector
Peter Kasting728d9032015-06-11 14:31:38 -070053 return WebRtc_g722_encode((G722EncoderState*) G722enc_inst, codechar,
54 speechIn, len);
niklase@google.com470e71d2011-07-07 08:21:25 +000055}
56
pbos@webrtc.org0946a562013-04-09 00:28:06 +000057int16_t WebRtcG722_CreateDecoder(G722DecInst **G722dec_inst)
niklase@google.com470e71d2011-07-07 08:21:25 +000058{
pbos@webrtc.orgeb544462014-12-17 15:23:29 +000059 *G722dec_inst=(G722DecInst*)malloc(sizeof(G722DecoderState));
niklase@google.com470e71d2011-07-07 08:21:25 +000060 if (*G722dec_inst!=NULL) {
61 return(0);
62 } else {
63 return(-1);
64 }
65}
66
Karl Wiberg43766482015-08-27 15:22:11 +020067void WebRtcG722_DecoderInit(G722DecInst* inst) {
68 // Create and/or reset the G.722 decoder
69 // Bitrate 64 kbps and wideband mode (2)
70 WebRtc_g722_decode_init((G722DecoderState*)inst, 64000, 2);
niklase@google.com470e71d2011-07-07 08:21:25 +000071}
72
Peter Kastingbba78072015-06-11 19:02:46 -070073int WebRtcG722_FreeDecoder(G722DecInst *G722dec_inst)
niklase@google.com470e71d2011-07-07 08:21:25 +000074{
75 // Free encoder memory
pbos@webrtc.orgeb544462014-12-17 15:23:29 +000076 return WebRtc_g722_decode_release((G722DecoderState*) G722dec_inst);
niklase@google.com470e71d2011-07-07 08:21:25 +000077}
78
Peter Kastingdce40cf2015-08-24 14:52:23 -070079size_t WebRtcG722_Decode(G722DecInst *G722dec_inst,
80 const uint8_t *encoded,
81 size_t len,
82 int16_t *decoded,
83 int16_t *speechType)
niklase@google.com470e71d2011-07-07 08:21:25 +000084{
85 // Decode the G.722 encoder stream
86 *speechType=G722_WEBRTC_SPEECH;
Peter Kasting728d9032015-06-11 14:31:38 -070087 return WebRtc_g722_decode((G722DecoderState*) G722dec_inst, decoded,
88 encoded, len);
niklase@google.com470e71d2011-07-07 08:21:25 +000089}
90
pbos@webrtc.org0946a562013-04-09 00:28:06 +000091int16_t WebRtcG722_Version(char *versionStr, short len)
niklase@google.com470e71d2011-07-07 08:21:25 +000092{
93 // Get version string
94 char version[30] = "2.0.0\n";
95 if (strlen(version) < (unsigned int)len)
96 {
97 strcpy(versionStr, version);
98 return 0;
99 }
100 else
101 {
102 return -1;
103 }
104}