blob: b79846ca3e548b1340b149f5124fee55385378f8 [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"
Mirko Bonadei71207422017-09-15 13:58:09 +020016#include "typedefs.h" // NOLINT(build/include)
niklase@google.com470e71d2011-07-07 08:21:25 +000017
pbos@webrtc.org0946a562013-04-09 00:28:06 +000018int16_t WebRtcG722_CreateEncoder(G722EncInst **G722enc_inst)
niklase@google.com470e71d2011-07-07 08:21:25 +000019{
pbos@webrtc.orgeb544462014-12-17 15:23:29 +000020 *G722enc_inst=(G722EncInst*)malloc(sizeof(G722EncoderState));
niklase@google.com470e71d2011-07-07 08:21:25 +000021 if (*G722enc_inst!=NULL) {
22 return(0);
23 } else {
24 return(-1);
25 }
26}
27
pbos@webrtc.org0946a562013-04-09 00:28:06 +000028int16_t WebRtcG722_EncoderInit(G722EncInst *G722enc_inst)
niklase@google.com470e71d2011-07-07 08:21:25 +000029{
30 // Create and/or reset the G.722 encoder
31 // Bitrate 64 kbps and wideband mode (2)
pwestin@webrtc.orgebcb6422011-12-22 12:20:06 +000032 G722enc_inst = (G722EncInst *) WebRtc_g722_encode_init(
pbos@webrtc.orgeb544462014-12-17 15:23:29 +000033 (G722EncoderState*) G722enc_inst, 64000, 2);
niklase@google.com470e71d2011-07-07 08:21:25 +000034 if (G722enc_inst == NULL) {
35 return -1;
36 } else {
37 return 0;
38 }
39}
40
Peter Kastingbba78072015-06-11 19:02:46 -070041int WebRtcG722_FreeEncoder(G722EncInst *G722enc_inst)
niklase@google.com470e71d2011-07-07 08:21:25 +000042{
43 // Free encoder memory
pbos@webrtc.orgeb544462014-12-17 15:23:29 +000044 return WebRtc_g722_encode_release((G722EncoderState*) G722enc_inst);
niklase@google.com470e71d2011-07-07 08:21:25 +000045}
46
Peter Kastingdce40cf2015-08-24 14:52:23 -070047size_t WebRtcG722_Encode(G722EncInst *G722enc_inst,
48 const int16_t* speechIn,
49 size_t len,
50 uint8_t* encoded)
niklase@google.com470e71d2011-07-07 08:21:25 +000051{
52 unsigned char *codechar = (unsigned char*) encoded;
53 // Encode the input speech vector
Peter Kasting728d9032015-06-11 14:31:38 -070054 return WebRtc_g722_encode((G722EncoderState*) G722enc_inst, codechar,
55 speechIn, len);
niklase@google.com470e71d2011-07-07 08:21:25 +000056}
57
pbos@webrtc.org0946a562013-04-09 00:28:06 +000058int16_t WebRtcG722_CreateDecoder(G722DecInst **G722dec_inst)
niklase@google.com470e71d2011-07-07 08:21:25 +000059{
pbos@webrtc.orgeb544462014-12-17 15:23:29 +000060 *G722dec_inst=(G722DecInst*)malloc(sizeof(G722DecoderState));
niklase@google.com470e71d2011-07-07 08:21:25 +000061 if (*G722dec_inst!=NULL) {
62 return(0);
63 } else {
64 return(-1);
65 }
66}
67
Karl Wiberg43766482015-08-27 15:22:11 +020068void WebRtcG722_DecoderInit(G722DecInst* inst) {
69 // Create and/or reset the G.722 decoder
70 // Bitrate 64 kbps and wideband mode (2)
71 WebRtc_g722_decode_init((G722DecoderState*)inst, 64000, 2);
niklase@google.com470e71d2011-07-07 08:21:25 +000072}
73
Peter Kastingbba78072015-06-11 19:02:46 -070074int WebRtcG722_FreeDecoder(G722DecInst *G722dec_inst)
niklase@google.com470e71d2011-07-07 08:21:25 +000075{
76 // Free encoder memory
pbos@webrtc.orgeb544462014-12-17 15:23:29 +000077 return WebRtc_g722_decode_release((G722DecoderState*) G722dec_inst);
niklase@google.com470e71d2011-07-07 08:21:25 +000078}
79
Peter Kastingdce40cf2015-08-24 14:52:23 -070080size_t WebRtcG722_Decode(G722DecInst *G722dec_inst,
81 const uint8_t *encoded,
82 size_t len,
83 int16_t *decoded,
84 int16_t *speechType)
niklase@google.com470e71d2011-07-07 08:21:25 +000085{
86 // Decode the G.722 encoder stream
87 *speechType=G722_WEBRTC_SPEECH;
Peter Kasting728d9032015-06-11 14:31:38 -070088 return WebRtc_g722_decode((G722DecoderState*) G722dec_inst, decoded,
89 encoded, len);
niklase@google.com470e71d2011-07-07 08:21:25 +000090}
91
pbos@webrtc.org0946a562013-04-09 00:28:06 +000092int16_t WebRtcG722_Version(char *versionStr, short len)
niklase@google.com470e71d2011-07-07 08:21:25 +000093{
94 // Get version string
95 char version[30] = "2.0.0\n";
96 if (strlen(version) < (unsigned int)len)
97 {
98 strcpy(versionStr, version);
99 return 0;
100 }
101 else
102 {
103 return -1;
104 }
105}