summaryrefslogtreecommitdiff
path: root/pjmedia/src/pjmedia/mediamgr.c
blob: b87d65086d1be4f0d45a5babecd779344dac93ab (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
/* $Id$
 *
 */
/* 
 * PJMEDIA - Multimedia over IP Stack 
 * (C)2003-2005 Benny Prijono <bennylp@bulukucing.org>
 *
 * Author:
 *  Benny Prijono <bennylp@bulukucing.org>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 * 
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */
#include <pjmedia/mediamgr.h>
#include <pj/sock.h>
#include <pj/pool.h>
#include <pj/string.h>

PJ_DECL(pj_status_t) g711_init_factory (pj_codec_factory *factory, pj_pool_t *pool);
PJ_DECL(pj_status_t) g711_deinit_factory (pj_codec_factory *factory);

/** Concrete declaration of media manager. */
struct pj_med_mgr_t
{
    /** Pool. */
    pj_pool_t		 *pool;

    /** Pool factory. */
    pj_pool_factory	 *pf;

    /** Codec manager. */
    pj_codec_mgr	  codec_mgr;
};

/**
 * Initialize and get the instance of media manager.
 */
PJ_DEF(pj_med_mgr_t*) pj_med_mgr_create ( pj_pool_factory *pf)
{
    pj_pool_t *pool;
    pj_med_mgr_t *mm;
    pj_codec_factory *cf;
    pj_status_t status;

    pool = pj_pool_create(pf, "mediamgr", 512, 512, NULL);
    if (!pool)
	return NULL;

    mm = pj_pool_calloc(pool, 1, sizeof(struct pj_med_mgr_t));
    mm->pool = pool;
    mm->pf = pf;

    /* Sound */
    pj_snd_init(pf);

    /* Init codec manager. */
    status = pj_codec_mgr_init(&mm->codec_mgr);
    if (status != 0) {
	pj_snd_deinit();
	goto on_error;
    }

    /* Init and register G.711 codec. */
    cf = pj_pool_alloc (mm->pool, sizeof(pj_codec_factory));

    status = g711_init_factory (cf, mm->pool);
    if (status != 0) {
	pj_snd_deinit();
	return NULL;
    }

    status = pj_codec_mgr_register_factory (&mm->codec_mgr, cf);
    if (status != 0) 
	return NULL;

    return mm;

on_error:
    pj_pool_release(pool);
    return NULL;
}

/**
 * Get the codec manager instance.
 */
PJ_DEF(pj_codec_mgr*) pj_med_mgr_get_codec_mgr (pj_med_mgr_t *mgr)
{
    return &mgr->codec_mgr;
}

/**
 * Deinitialize media manager.
 */
PJ_DEF(pj_status_t) pj_med_mgr_destroy (pj_med_mgr_t *mgr)
{
    pj_snd_deinit();
    pj_pool_release (mgr->pool);
    return 0;
}

/**
 * Get pool factory.
 */
PJ_DEF(pj_pool_factory*) pj_med_mgr_get_pool_factory (pj_med_mgr_t *mgr)
{
    return mgr->pf;
}