audiocodec.cpp 3.26 KB
Newer Older
1
/*
2
 * Copyright (C) 2004, 2005, 2006, 2008, 2009, 2010 Savoir-Faire Linux Inc.
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
 * Author:  Alexandre Savard <alexandre.savard@savoirfairelinux.com>
 *
 * Mostly borrowed from asterisk's sources (Steve Underwood <steveu@coppice.org>)
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program 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 General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 *
 *  Additional permission under GNU GPL version 3 section 7:
 *
 *  If you modify this program, or any covered work, by linking or
 *  combining it with the OpenSSL project's OpenSSL library (or a
 *  modified version of that library), containing parts covered by the
 *  terms of the OpenSSL or SSLeay licenses, Savoir-Faire Linux Inc.
 *  grants you additional permission to convey the resulting work.
 *  Corresponding Source for a non-source form of such a combination
 *  shall include the source code for the parts of OpenSSL used as well
 *  as that of the covered work.
 */

#include "audiocodec.h"
34
35
using std::ptrdiff_t;
#include <ccrtp/rtp.h>
36

37
38
namespace sfl {

39
AudioCodec::AudioCodec(uint8 payload, const std::string &codecName) :
40
41
42
    codecName_(codecName), clockRate_(8000), channel_(1), frameSize_(0),
    bitrate_(0.0), bandwidth_(0.0), hasDynamicPayload_(false),
    payload_(payload), payloadFormat_(0)
43
{
44
    init(payload, clockRate_);
45
46
}

47
48
49
50
51
AudioCodec::AudioCodec(const AudioCodec& c) :
    codecName_(c.codecName_), clockRate_(c.clockRate_), channel_(c.channel_),
    frameSize_(c.frameSize_), bitrate_(c.bitrate_), bandwidth_(c.bandwidth_),
    hasDynamicPayload_(c.hasDynamicPayload_), payload_(c.payload_),
    payloadFormat_(c.payloadFormat_)
52
{
53
    init(c.payload_, c.clockRate_);
54
55
}

56
void AudioCodec::init(uint8 payloadType, uint32 clockRate)
57
{
58
    payloadFormat_ = new ost::DynamicPayloadFormat(payloadType, clockRate);
59
60
61

    // If g722 (payload 9), we need to init libccrtp symetric sessions with using
    // dynamic payload format. This way we get control on rtp clockrate.
62
    hasDynamicPayload_ = ((payload_ >= 96 and payload_ <= 127) or payload_ == 9);
63
64
65
66
67
68
69
70
71
}

std::string AudioCodec::getMimeType() const
{
    return "audio";
}

std::string AudioCodec::getMimeSubtype() const
{
72
    return codecName_;
73
74
75
76
}

const ost::PayloadFormat& AudioCodec::getPayloadFormat()
{
77
    return *payloadFormat_;
78
79
}

80
uint8 AudioCodec::getPayloadType() const
81
{
82
    return payload_;
83
84
}

85
bool AudioCodec::hasDynamicPayload() const
86
{
87
    return hasDynamicPayload_;
88
89
}

90
uint32 AudioCodec::getClockRate() const
91
{
92
    return clockRate_;
93
94
}

95
unsigned AudioCodec::getFrameSize() const
96
{
97
    return frameSize_;
98
99
}

100
uint8 AudioCodec::getChannel() const
101
{
102
    return channel_;
103
104
}

105
double AudioCodec::getBitRate() const
106
{
107
    return bitrate_;
108
109
}

110
111
AudioCodec::~AudioCodec()
{
112
    delete payloadFormat_;
113
114
}

115
} // end namespace sfl