1
/* $Id: plc_common.c 3553 2011-05-05 06:14:19Z nanang $ */
3
* Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com)
4
* Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; either version 2 of the License, or
9
* (at your option) any later version.
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20
#include <pjmedia/plc.h>
21
#include <pjmedia/errno.h>
22
#include <pjmedia/wsola.h>
23
#include <pj/assert.h>
25
#include <pj/string.h>
28
static void* plc_wsola_create(pj_pool_t*, unsigned c, unsigned f);
29
static void plc_wsola_save(void*, pj_int16_t*);
30
static void plc_wsola_generate(void*, pj_int16_t*);
33
* This struct is used internally to represent a PLC backend.
37
void* (*plc_create)(pj_pool_t*, unsigned c, unsigned f);
38
void (*plc_save)(void*, pj_int16_t*);
39
void (*plc_generate)(void*, pj_int16_t*);
43
static struct plc_alg plc_wsola =
59
* Create PLC session. This function will select the PLC algorithm to
60
* use based on the arguments.
62
PJ_DEF(pj_status_t) pjmedia_plc_create( pj_pool_t *pool,
64
unsigned samples_per_frame,
70
PJ_ASSERT_RETURN(pool && clock_rate && samples_per_frame && p_plc,
72
PJ_ASSERT_RETURN(options == 0, PJ_EINVAL);
74
PJ_UNUSED_ARG(options);
76
plc = PJ_POOL_ZALLOC_T(pool, pjmedia_plc);
79
plc->obj = plc->op->plc_create(pool, clock_rate, samples_per_frame);
88
* Save a good frame to PLC.
90
PJ_DEF(pj_status_t) pjmedia_plc_save( pjmedia_plc *plc,
93
PJ_ASSERT_RETURN(plc && frame, PJ_EINVAL);
95
plc->op->plc_save(plc->obj, frame);
101
* Generate a replacement for lost frame.
103
PJ_DEF(pj_status_t) pjmedia_plc_generate( pjmedia_plc *plc,
106
PJ_ASSERT_RETURN(plc && frame, PJ_EINVAL);
108
plc->op->plc_generate(plc->obj, frame);
113
//////////////////////////////////////////////////////////////////////////////
115
* Packet loss concealment based on WSOLA
119
pjmedia_wsola *wsola;
124
static void* plc_wsola_create(pj_pool_t *pool, unsigned clock_rate,
125
unsigned samples_per_frame)
131
PJ_UNUSED_ARG(clock_rate);
133
o = PJ_POOL_ZALLOC_T(pool, struct wsola_plc);
134
o->prev_lost = PJ_FALSE;
136
flag = PJMEDIA_WSOLA_NO_DISCARD;
137
if (PJMEDIA_WSOLA_PLC_NO_FADING)
138
flag |= PJMEDIA_WSOLA_NO_FADING;
140
status = pjmedia_wsola_create(pool, clock_rate, samples_per_frame, 1,
142
if (status != PJ_SUCCESS)
148
static void plc_wsola_save(void *plc, pj_int16_t *frame)
150
struct wsola_plc *o = (struct wsola_plc*) plc;
152
pjmedia_wsola_save(o->wsola, frame, o->prev_lost);
153
o->prev_lost = PJ_FALSE;
156
static void plc_wsola_generate(void *plc, pj_int16_t *frame)
158
struct wsola_plc *o = (struct wsola_plc*) plc;
160
pjmedia_wsola_generate(o->wsola, frame);
161
o->prev_lost = PJ_TRUE;