Alexandre Lision | a8b7872 | 2013-12-13 10:18:33 -0500 | [diff] [blame] | 1 | /* |
Alexandre Lision | c1024c0 | 2014-01-06 11:12:53 -0500 | [diff] [blame] | 2 | * Copyright (C) 2004-2014 Savoir-Faire Linux Inc. |
Alexandre Lision | a8b7872 | 2013-12-13 10:18:33 -0500 | [diff] [blame] | 3 | * |
| 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 Lision | 933ef0a | 2013-10-15 17:28:40 -0400 | [diff] [blame] | 32 | package org.sflphone.model; |
| 33 | |
Alexandre Lision | 933ef0a | 2013-10-15 17:28:40 -0400 | [diff] [blame] | 34 | import org.sflphone.service.StringVect; |
| 35 | |
| 36 | import android.os.Parcel; |
| 37 | import android.os.Parcelable; |
| 38 | |
| 39 | public class Codec implements Parcelable { |
| 40 | int payload; |
| 41 | String name; |
| 42 | String sampleRate; |
| 43 | String bitRate; |
| 44 | String channels; |
Alexandre Lision | 4df961d | 2013-10-16 13:44:49 -0400 | [diff] [blame] | 45 | boolean enabled; |
Alexandre Lision | 933ef0a | 2013-10-15 17:28:40 -0400 | [diff] [blame] | 46 | |
Alexandre Lision | 4df961d | 2013-10-16 13:44:49 -0400 | [diff] [blame] | 47 | public Codec(int i, StringVect audioCodecDetails, boolean b) { |
Alexandre Lision | 933ef0a | 2013-10-15 17:28:40 -0400 | [diff] [blame] | 48 | payload = i; |
| 49 | name = audioCodecDetails.get(0); |
| 50 | sampleRate = audioCodecDetails.get(1); |
| 51 | bitRate = audioCodecDetails.get(2); |
| 52 | channels = audioCodecDetails.get(3); |
Alexandre Lision | 4df961d | 2013-10-16 13:44:49 -0400 | [diff] [blame] | 53 | enabled = b; |
Alexandre Lision | 933ef0a | 2013-10-15 17:28:40 -0400 | [diff] [blame] | 54 | } |
| 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 Lision | 4df961d | 2013-10-16 13:44:49 -0400 | [diff] [blame] | 68 | out.writeByte((byte) (enabled ? 1 : 0)); |
Alexandre Lision | 933ef0a | 2013-10-15 17:28:40 -0400 | [diff] [blame] | 69 | } |
| 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 Lision | 4df961d | 2013-10-16 13:44:49 -0400 | [diff] [blame] | 87 | enabled = in.readByte() == 1 ? true : false; |
Alexandre Lision | 933ef0a | 2013-10-15 17:28:40 -0400 | [diff] [blame] | 88 | } |
| 89 | |
Alexandre Lision | 4b4233a | 2013-10-16 17:24:17 -0400 | [diff] [blame] | 90 | 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 Lision | 933ef0a | 2013-10-15 17:28:40 -0400 | [diff] [blame] | 99 | @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 Lision | 4df961d | 2013-10-16 13:44:49 -0400 | [diff] [blame] | 126 | public boolean isEnabled() { |
| 127 | return enabled; |
| 128 | } |
| 129 | |
| 130 | public void setEnabled(boolean b) { |
| 131 | enabled = b; |
| 132 | } |
| 133 | |
Alexandre Lision | 4b4233a | 2013-10-16 17:24:17 -0400 | [diff] [blame] | 134 | 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 Lision | 423aa13 | 2013-12-10 17:31:10 -0500 | [diff] [blame] | 144 | } |
| 145 | |
| 146 | public boolean isSpeex() { |
| 147 | return name.contentEquals("speex"); |
Alexandre Lision | 4b4233a | 2013-10-16 17:24:17 -0400 | [diff] [blame] | 148 | } |
| 149 | |
Alexandre Lision | 933ef0a | 2013-10-15 17:28:40 -0400 | [diff] [blame] | 150 | } |