@Override public boolean onContextItemSelected(MenuItem item) { int posn = (int) ((AdapterContextMenuInfo) item.getMenuInfo()).position; Codec c = codecs.elementAt(posn); if (item.getItemId() == MENU_UP) { if (posn == 0) return super.onContextItemSelected(item); Codec tmp = codecs.elementAt(posn - 1); codecs.set(posn - 1, c); codecs.set(posn, tmp); } else if (item.getItemId() == MENU_DOWN) { if (posn == codecs.size() - 1) return super.onContextItemSelected(item); Codec tmp = codecs.elementAt(posn + 1); codecs.set(posn + 1, c); codecs.set(posn, tmp); } PreferenceScreen ps = getPreferenceScreen(); SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(Receiver.mContext); String v = ""; SharedPreferences.Editor e = sp.edit(); for (Codec d : codecs) v = v + d.number() + " "; e.putString(Settings.PREF_CODECS, v); e.commit(); ps.removeAll(); addPreferences(ps); return super.onContextItemSelected(item); }
private static void saveCodecPrefs(SharedPreferences sp) { String v = ""; for (Codec c : codecs) v = v + c.number() + " "; SharedPreferences.Editor e = sp.edit(); e.putString(Settings.PREF_CODECS, v); e.commit(); }
public static int[] getCodecs() { Vector<Integer> v = new Vector<Integer>(codecs.size()); for (Codec c : codecs) { if (!c.isValid()) continue; v.add(c.number()); } int i[] = new int[v.size()]; for (int j = 0; j < i.length; j++) i[j] = v.elementAt(j); return i; }
static { final int size = codecs.size(); codecsNumbers = new HashMap<Integer, Codec>(size); codecsNames = new HashMap<String, Codec>(size); for (Codec c : codecs) { codecsNames.put(c.name(), c); codecsNumbers.put(c.number(), c); } SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(Receiver.mContext); String prefs = sp.getString(Settings.PREF_CODECS, Settings.DEFAULT_CODECS); if (prefs == null) { saveCodecPrefs(sp); } else { String[] vals = prefs.split(" "); Vector<Codec> orderedCodecs = new Vector<Codec>(); for (String v : vals) { try { int i = Integer.parseInt(v); Codec c = codecsNumbers.get(i); /* moves the configured codecs to the beginning of the list, * and any new codecs will automatically go at the end */ if (c != null) { codecs.remove(c); orderedCodecs.add(c); } } catch (Exception e) { // do nothing (expecting // NumberFormatException and // indexnot found } } orderedCodecs.addAll(codecs); codecs.clear(); for (Codec c : orderedCodecs) { if (c.isLicensed()) codecs.add(c); } saveCodecPrefs(sp); } }
public static Map getCodec(SessionDescriptor offers) { Logger logger = Logger.getLogger(Codecs.class.getCanonicalName()); if (offers == null) { logger.warning("offers == null"); return null; } MediaDescriptor mAudio = offers.getMediaDescriptor("audio"); if (mAudio == null) { logger.warning("offer doesn't contain m=audio"); logger.info(offers.toString()); return null; } MediaField m = mAudio.getMedia(); if (m == null) { logger.warning("media field invalid"); return null; } String proto = m.getTransport(); // see http://tools.ietf.org/html/rfc4566#page-22, paragraph 5.14, <fmt> description if (proto.equals("RTP/AVP") || proto.equals("RTP/SAVP") || proto.equals("RTP/SAVPF")) { Vector<String> formats = m.getFormatList(); Vector<String> names = new Vector<String>(formats.size()); Vector<Integer> numbers = new Vector<Integer>(formats.size()); Vector<Codec> codecmap = new Vector<Codec>(formats.size()); // add all avail formats with empty names for (String fmt : formats) { try { int number = Integer.parseInt(fmt); numbers.add(number); names.add(""); codecmap.add(null); } catch (NumberFormatException e) { // continue ... remote sent bogus rtp setting } } ; logger.info("got " + numbers.size() + " format numbers"); // if we have attrs for format -> set name Vector<AttributeField> attrs = offers.getMediaDescriptor("audio").getAttributes("rtpmap"); logger.info("got " + attrs.size() + " rtpmap attributes"); for (AttributeField a : attrs) { String s = a.getValue(); // skip over "rtpmap:" s = s.substring(7, s.indexOf("/")); int i = s.indexOf(" "); try { String name = s.substring(i + 1); int number = Integer.parseInt(s.substring(0, i)); int index = numbers.indexOf(number); logger.info("format offered " + index + ", " + name); if (index >= 0) names.set(index, name.toLowerCase()); } catch (NumberFormatException e) { // continue ... remote sent bogus rtp setting } } Codec codec = null; int index = formats.size() + 1; logger.info("number of local codecs = " + codecs.size()); for (Codec c : codecs) { logger.info("checking " + c.userName() + ", valid = " + c.isValid()); if (!c.isValid()) continue; // search current codec in offers by name int i = names.indexOf(c.userName().toLowerCase()); if (i >= 0) { logger.info("adding codec " + c.userName() + " by name"); codecmap.set(i, c); if ((codec == null) || (i < index)) { codec = c; index = i; continue; } } // search current codec in offers by number i = numbers.indexOf(c.number()); if (i >= 0) { if (names.elementAt(i).equals("")) { logger.info("adding codec " + c.userName() + " by number"); codecmap.set(i, c); if ((codec == null) || (i < index)) { // fmt number has no attr with name codec = c; index = i; continue; } } } } if (codec != null) return new Map(numbers.elementAt(index), codec, numbers, codecmap); else { // no codec found ... we can't talk logger.warning("didn't find any recognised codec"); return null; } } else { /*formats of other protocols not supported yet*/ logger.warning("can't handle protocol: " + proto); return null; } }