blob: e5982dbbed1a1f0fb41df48e9b7e97c234c606a7 [file] [log] [blame]
Alexandre Lisiona8b78722013-12-13 10:18:33 -05001/*
Alexandre Lisionc1024c02014-01-06 11:12:53 -05002 * Copyright (C) 2004-2014 Savoir-Faire Linux Inc.
Alexandre Lisiona8b78722013-12-13 10:18:33 -05003 *
4 * Author: Alexandre Lision <alexandre.lision@savoirfairelinux.com>
5 *
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 3 of the License, or
9 * (at your option) any later version.
10 *
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.
15 *
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., 675 Mass Ave, Cambridge, MA 02139, USA.
19 *
20 * Additional permission under GNU GPL version 3 section 7:
21 *
22 * If you modify this program, or any covered work, by linking or
23 * combining it with the OpenSSL project's OpenSSL library (or a
24 * modified version of that library), containing parts covered by the
25 * terms of the OpenSSL or SSLeay licenses, Savoir-Faire Linux Inc.
26 * grants you additional permission to convey the resulting work.
27 * Corresponding Source for a non-source form of such a combination
28 * shall include the source code for the parts of OpenSSL used as well
29 * as that of the covered work.
30 */
31
Alexandre Lision933ef0a2013-10-15 17:28:40 -040032package org.sflphone.model;
33
Alexandre Lision933ef0a2013-10-15 17:28:40 -040034import org.sflphone.service.StringVect;
35
36import android.os.Parcel;
37import android.os.Parcelable;
38
39public class Codec implements Parcelable {
40 int payload;
41 String name;
42 String sampleRate;
43 String bitRate;
44 String channels;
Alexandre Lision4df961d2013-10-16 13:44:49 -040045 boolean enabled;
Alexandre Lision933ef0a2013-10-15 17:28:40 -040046
Alexandre Lision4df961d2013-10-16 13:44:49 -040047 public Codec(int i, StringVect audioCodecDetails, boolean b) {
Alexandre Lision933ef0a2013-10-15 17:28:40 -040048 payload = i;
49 name = audioCodecDetails.get(0);
50 sampleRate = audioCodecDetails.get(1);
51 bitRate = audioCodecDetails.get(2);
52 channels = audioCodecDetails.get(3);
Alexandre Lision4df961d2013-10-16 13:44:49 -040053 enabled = b;
Alexandre Lision933ef0a2013-10-15 17:28:40 -040054 }
55
56 @Override
57 public int describeContents() {
58 return 0;
59 }
60
61 @Override
62 public void writeToParcel(Parcel out, int flags) {
63 out.writeInt(payload);
64 out.writeString(name);
65 out.writeString(sampleRate);
66 out.writeString(bitRate);
67 out.writeString(channels);
Alexandre Lision4df961d2013-10-16 13:44:49 -040068 out.writeByte((byte) (enabled ? 1 : 0));
Alexandre Lision933ef0a2013-10-15 17:28:40 -040069 }
70
71 public static final Parcelable.Creator<Codec> CREATOR = new Parcelable.Creator<Codec>() {
72 public Codec createFromParcel(Parcel in) {
73 return new Codec(in);
74 }
75
76 public Codec[] newArray(int size) {
77 return new Codec[size];
78 }
79 };
80
81 private Codec(Parcel in) {
82 payload = in.readInt();
83 name = in.readString();
84 sampleRate = in.readString();
85 bitRate = in.readString();
86 channels = in.readString();
Alexandre Lision4df961d2013-10-16 13:44:49 -040087 enabled = in.readByte() == 1 ? true : false;
Alexandre Lision933ef0a2013-10-15 17:28:40 -040088 }
89
Alexandre Lision4b4233a2013-10-16 17:24:17 -040090 public Codec(Codec c) {
91 payload = c.payload;
92 name = c.name;
93 sampleRate = c.sampleRate;
94 bitRate = c.bitRate;
95 channels = c.channels;
96 enabled = c.enabled;
97 }
98
Alexandre Lision933ef0a2013-10-15 17:28:40 -040099 @Override
100 public String toString() {
101 String str = "Codec: " + name + "\n" + "Payload: " + payload + "\n" + "Sample Rate: " + sampleRate + "\n" + "Bit Rate: " + bitRate + "\n"
102 + "Channels: " + channels;
103 return str;
104 }
105
106 public CharSequence getPayload() {
107 return Integer.toString(payload);
108 }
109
110 public CharSequence getName() {
111 return name;
112 }
113
114 public String getSampleRate() {
115 return sampleRate;
116 }
117
118 public String getBitRate() {
119 return bitRate;
120 }
121
122 public String getChannels() {
123 return channels;
124 }
125
Alexandre Lision4df961d2013-10-16 13:44:49 -0400126 public boolean isEnabled() {
127 return enabled;
128 }
129
130 public void setEnabled(boolean b) {
131 enabled = b;
132 }
133
Alexandre Lision4b4233a2013-10-16 17:24:17 -0400134 public void toggleState() {
135 enabled = !enabled;
136
137 }
138
139 @Override
140 public boolean equals(Object o){
141 if(o instanceof Codec && ((Codec) o).payload == payload)
142 return true;
143 return false;
Alexandre Lision423aa132013-12-10 17:31:10 -0500144 }
145
146 public boolean isSpeex() {
147 return name.contentEquals("speex");
Alexandre Lision4b4233a2013-10-16 17:24:17 -0400148 }
149
Alexandre Lision933ef0a2013-10-15 17:28:40 -0400150}