Package 

Class DeviceEncoders


  • 
    public class DeviceEncoders
    
                        

    Checks the capabilities of device encoders and adjust parameters to ensure that they'll be supported by the final encoder. Methods in this class might throw either a VideoException or a AudioException. Throwing this exception means that the given parameters will not be supported by the encoder for that type, and cannot be tweaked to be. When this happens, users should retry with a new DeviceEncoders instance, but with the audio or video encoder offset incremented. This offset is the position in the encoder list from which we'll choose the potential encoder. This class will inspect the encoders list in two ways, based on the mode flag: 1. MODE_RESPECT_ORDER Chooses the encoder as the first one that matches the given mime type. This is what createEncoderByType does, and what android.media.MediaRecorder also does when recording. The list is ordered based on the encoder definitions in system/etc/media_codecs.xml, as explained here: https://source.android.com/devices/media , for example. So taking the first means respecting the vendor priorities and should generally be a good idea. About android.media.MediaRecorder, we know it uses this option from here: https://stackoverflow.com/q/57479564/4288782 where all links to source code are shown. - StagefrightRecorder (https://android.googlesource.com/platform/frameworks/av/+/master/media/libmediaplayerservice/StagefrightRecorder.cpp#1782) - MediaCodecSource (https://android.googlesource.com/platform/frameworks/av/+/master/media/libstagefright/MediaCodecSource.cpp#515) - MediaCodecList (https://android.googlesource.com/platform/frameworks/av/+/master/media/libstagefright/MediaCodecList.cpp#322) To be fair, what android.media.MediaRecorder does is actually choose the first one that configures itself without errors. We offer this option through tryConfigureVideo and tryConfigureAudio. 2. MODE_PREFER_HARDWARE This takes the list - as ordered by the vendor - and just sorts it so that hardware encoders are preferred over software ones. It's questionable whether this is good or not. Some vendors might forget to put hardware encoders first in the list, some others might put poor hardware encoders on the bottom of the list on purpose.

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      public class DeviceEncoders.VideoException

      Exception thrown when trying to find appropriate valuesfor a video encoder.

      public class DeviceEncoders.AudioException

      Exception thrown when trying to find appropriate valuesfor an audio encoder. Currently never thrown.

    • Constructor Summary

      Constructors 
      Constructor Description
      DeviceEncoders(int mode, String videoType, String audioType, int videoOffset, int audioOffset)
    • Method Summary

      Modifier and Type Method Description
      Size getSupportedVideoSize(@NonNull() Size size) Returns a video size supported by the device encoders.Throws if input width or height are out of the supported boundaries.
      int getSupportedVideoBitRate(int bitRate) Returns a video bit rate supported by the device encoders.This means adjusting the input bit rate if needed, to match encoder constraints.
      int getSupportedVideoFrameRate(@NonNull() Size size, int frameRate) Returns a video frame rate supported by the device encoders.This means adjusting the input frame rate if needed, to match encoder constraints.
      int getSupportedAudioBitRate(int bitRate) Returns an audio bit rate supported by the device encoders.This means adjusting the input bit rate if needed, to match encoder constraints.
      String getVideoEncoder() Returns the name of the video encoder if we were able to determine one.
      String getAudioEncoder() Returns the name of the audio encoder if we were able to determine one.
      void tryConfigureVideo(@NonNull() String mimeType, @NonNull() Size size, int frameRate, int bitRate)
      void tryConfigureAudio(@NonNull() String mimeType, int bitRate, int sampleRate, int channels)
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • DeviceEncoders

        DeviceEncoders(int mode, String videoType, String audioType, int videoOffset, int audioOffset)
    • Method Detail

      • getSupportedVideoSize

        @NonNull() Size getSupportedVideoSize(@NonNull() Size size)

        Returns a video size supported by the device encoders.Throws if input width or height are out of the supported boundaries.

        Parameters:
        size - input size
      • getSupportedVideoBitRate

         int getSupportedVideoBitRate(int bitRate)

        Returns a video bit rate supported by the device encoders.This means adjusting the input bit rate if needed, to match encoder constraints.

        Parameters:
        bitRate - input rate
      • getSupportedVideoFrameRate

         int getSupportedVideoFrameRate(@NonNull() Size size, int frameRate)

        Returns a video frame rate supported by the device encoders.This means adjusting the input frame rate if needed, to match encoder constraints.

        Parameters:
        frameRate - input rate
      • getSupportedAudioBitRate

         int getSupportedAudioBitRate(int bitRate)

        Returns an audio bit rate supported by the device encoders.This means adjusting the input bit rate if needed, to match encoder constraints.

        Parameters:
        bitRate - input rate