@Override public Dimension[] getResolutions() { if (dimensions == null) { dimensions = new ArrayList<Dimension>(); Format[] formats = cdi.getFormats(); for (Format format : formats) { if ("RGB".equalsIgnoreCase(format.getEncoding())) { dimensions.add(((VideoFormat) format).getSize()); } } Collections.sort(dimensions, new Comparator<Dimension>() { @Override public int compare(Dimension a, Dimension b) { int apx = a.width * a.height; int bpx = b.width * b.height; if (apx > bpx) { return 1; } else if (apx < bpx) { return -1; } else { return 0; } } }); } return dimensions.toArray(new Dimension[dimensions.size()]); }
/** * Get video format for size. * * @param device device to get format from * @param size specific size to search * @return VideoFormat */ private VideoFormat getSizedVideoFormat(Dimension size) { Format[] formats = device.getFormats(); VideoFormat format = null; for (Format f : formats) { if (!"RGB".equalsIgnoreCase(f.getEncoding()) || !(f instanceof VideoFormat)) { continue; } Dimension d = ((VideoFormat) f).getSize(); if (d.width == size.width && d.height == size.height) { format = (VideoFormat) f; break; } } return format; }
/** * Get suitable video format to use (the largest one by default, but this * can be easily changed). * * @param device device to get video format for * @return Suitable video format */ private VideoFormat getLargestVideoFormat() { Format[] formats = device.getFormats(); VideoFormat format = null; int area = 0; // find the largest picture format for (Format f : formats) { if (!(f instanceof VideoFormat) || !"RGB".equalsIgnoreCase(f.getEncoding())) { continue; } VideoFormat vf = (VideoFormat) f; Dimension dim = vf.getSize(); int a = dim.width * dim.height; if (a > area) { area = a; format = vf; } } return format; }
/** * Provides the default implementation of * <tt>AbstractBufferCaptureDevice</tt> for * {@link #getSupportedFormats(int)}. * * @param streamIndex the zero-based index of the * <tt>AbstractBufferStream</tt> for which the specified * <tt>FormatControl</tt> is to report the list of supported * <tt>Format</tt>s * @return an array of <tt>Format</tt>s to be reported by a * <tt>FormatControl</tt> as the supported formats for the * <tt>AbstractBufferStream</tt> at the specified <tt>streamIndex</tt> in * the list of streams of this <tt>AbstractBufferCaptureDevice</tt> */ final Format[] defaultGetSupportedFormats(int streamIndex) { CaptureDeviceInfo captureDeviceInfo = getCaptureDeviceInfo(); return (captureDeviceInfo == null) ? new Format[0] : captureDeviceInfo.getFormats(); }
captureDeviceInfo.getName(), captureDeviceInfo.getLocator(), captureDeviceInfo.getFormats(), uid, transportType,