mMediaProjection = projection; mDensity = density; mFrameRate = options.getFrameRate(); mAvgColor = options.useAverageColor(); int blackThreshold = options.getBlackThreshold(); mBorderProcessor = new BorderProcessor(blackThreshold); int divisor = options.findDivisor(width, height);
/** * returns the divisor best suited to be used to meet the minimum image packet size * Since we only want to scale using whole numbers, we need to find what common divisors * are available for the given width & height. We will check those divisors to find the smallest * number (that we can divide our screen dimensions by) that would meet the minimum image * packet size required to match the count of the LEDs on the destination hyperion server. * @param width The original width of the device screen * @param height The original height of the device screen * @return int The divisor bes suited to scale the screen dimensions by **/ public int findDivisor(int width, int height) { List<Integer> divisors = getCommonDivisors(width, height); if (DEBUG) Log.d(TAG, "Available Divisors: " + divisors.toString()); ListIterator it = divisors.listIterator(divisors.size()); // iterate backwards since the divisors are listed largest to smallest while (it.hasPrevious()) { int i = (int) it.previous(); // check if the image packet size for this divisor is >= the minimum image packet size // like above we multiply the dimensions together and then by 3 for each byte in RGB if ((width / i) * (height / i) * 3 >= MINIMUM_IMAGE_PACKET_SIZE) return i; } return 1; }
@TargetApi(Build.VERSION_CODES.LOLLIPOP) private void startScreenRecord(final Intent intent) { if (DEBUG) Log.v(TAG, "Start screen recorder"); final int resultCode = intent.getIntExtra(EXTRA_RESULT_CODE, 0); // get MediaProjection final MediaProjection projection = mMediaProjectionManager.getMediaProjection(resultCode, intent); WindowManager window = (WindowManager) getSystemService(Context.WINDOW_SERVICE); if (projection != null && window != null) { _mediaProjection = projection; final DisplayMetrics metrics = new DisplayMetrics(); window.getDefaultDisplay().getRealMetrics(metrics); final int density = metrics.densityDpi; HyperionGrabberOptions options = new HyperionGrabberOptions(mHorizontalLEDCount, mVerticalLEDCount, mFrameRate, mSendAverageColor); if (DEBUG) Log.v(TAG, "Starting the recorder"); mHyperionEncoder = new HyperionScreenEncoder(mHyperionThread.getReceiver(), projection, metrics.widthPixels, metrics.heightPixels, density, options); mHyperionEncoder.sendStatus(); } }