/*
 * Kurento Android Media: Android Media Library based on FFmpeg.
 * Copyright (C) 2011  Tikal Technologies
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 3
 * as published by the Free Software Foundation.
 *
 * 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, see <http://www.gnu.org/licenses/>.
 */

package com.kurento.kas.media.codecs;

import java.util.ArrayList;

import com.kurento.kas.media.exception.CodecNotSupportedException;

/**
 * 
 * @author mparis
 * 
 */
public enum AudioCodecType {
	AMR(0, 8000, 12200, new String[]{ "AMR", "AMR-NB" }),
	MP2(1, 44100, 64000, new String[]{ "MP2", "MPA" }),
	AAC(2, 44100, 64000, new String[]{ "AAC" });
	
	private int codecID;
	private int supportedSampleRate;
	private int supportedBitRate;
	private ArrayList<String> arrayCodecStrings;

	private AudioCodecType(int codecID, int supportedSampleRate, int supportedBitRate, String[] codecStrings) {
		this.codecID = codecID;
		this.supportedSampleRate = supportedSampleRate;
		this.supportedBitRate = supportedBitRate;
		arrayCodecStrings = new ArrayList<String>();
		for (String s : codecStrings)
			arrayCodecStrings.add(s);
	}

	public int getCodecID() {
		return codecID;
	}

	public int getSupportedSampleRate() {
		return supportedSampleRate;
	}

	public int getSupportedBitRate() {
		return supportedBitRate;
	}

	public ArrayList<String> getArrayCodecStrings() {
		return arrayCodecStrings;
	}
	
	public static int getCodecIdFromName(String codecName) throws CodecNotSupportedException {
		if (AMR.arrayCodecStrings.contains(codecName))
			return AMR.codecID;
		else if (MP2.arrayCodecStrings.contains(codecName))
			return MP2.codecID;
		else if (AAC.arrayCodecStrings.contains(codecName))
			return AAC.codecID;

		throw new CodecNotSupportedException("Codec not supported");
	}
	
	public static AudioCodecType getCodecTypeFromName(String codecName) throws CodecNotSupportedException {
		if (AMR.arrayCodecStrings.contains(codecName))
			return AMR;
		else if (MP2.arrayCodecStrings.contains(codecName))
			return MP2;
		else if (AAC.arrayCodecStrings.contains(codecName))
			return AAC;

		throw new CodecNotSupportedException("Codec not supported");
	}
	
}

@@ -758,16 +758,45 @@
 rayList;
+%0Aimport java.util.Collection;
 %0A%0Aimport
@@ -1176,31 +1176,37 @@
 ate 
-ArrayList%3CString%3E array
+Collection%3CString%3E collection
 Code
@@ -1447,21 +1447,26 @@
 Rate;%0A%09%09
-array
+collection
 CodecStr
@@ -1532,21 +1532,26 @@
 ngs)%0A%09%09%09
-array
+collection
 CodecStr
@@ -1764,25 +1764,26 @@
 %09public 
-ArrayList
+Collection
 %3CString%3E
@@ -1786,21 +1786,26 @@
 ing%3E get
-Array
+Collection
 CodecStr
@@ -1822,21 +1822,26 @@
 %09return 
-array
+collection
 CodecStr
@@ -1945,37 +1945,42 @@
 ion %7B%0A%09%09if (AMR.
-array
+collection
 CodecStrings.con
@@ -1986,32 +1986,46 @@
 ntains(codecName
+.toUpperCase()
 ))%0A%09%09%09return AMR
@@ -2041,37 +2041,42 @@
 %0A%09%09else if (MP2.
-array
+collection
 CodecStrings.con
@@ -2082,32 +2082,46 @@
 ntains(codecName
+.toUpperCase()
 ))%0A%09%09%09return MP2
@@ -2137,37 +2137,42 @@
 %0A%09%09else if (AAC.
-array
+collection
 CodecStrings.con
@@ -2178,32 +2178,46 @@
 ntains(codecName
+.toUpperCase()
 ))%0A%09%09%09return AAC
@@ -2410,21 +2410,26 @@
 if (AMR.
-array
+collection
 CodecStr
@@ -2443,32 +2443,46 @@
 ntains(codecName
+.toUpperCase()
 ))%0A%09%09%09return AMR
@@ -2498,21 +2498,26 @@
 if (MP2.
-array
+collection
 CodecStr
@@ -2531,32 +2531,46 @@
 ntains(codecName
+.toUpperCase()
 ))%0A%09%09%09return MP2
@@ -2590,13 +2590,18 @@
 AAC.
-array
+collection
 Code
@@ -2627,16 +2627,30 @@
 odecName
+.toUpperCase()
 ))%0A%09%09%09re

Improve AudioCodecType management.