| Index: media/base/android/media_codec_bridge.h
|
| diff --git a/media/base/android/media_codec_bridge.h b/media/base/android/media_codec_bridge.h
|
| index 73f070d81de9cb44542d0d050c6f0d71c6c46e0d..fd7fd35efb512d0cc7866f626cf91fd245ca52fc 100644
|
| --- a/media/base/android/media_codec_bridge.h
|
| +++ b/media/base/android/media_codec_bridge.h
|
| @@ -8,12 +8,12 @@
|
| #include <jni.h>
|
| #include <set>
|
| #include <string>
|
| +#include <vector>
|
|
|
| -#include "base/android/scoped_java_ref.h"
|
| +#include "base/compiler_specific.h"
|
| #include "base/time/time.h"
|
| -#include "media/base/audio_decoder_config.h"
|
| -#include "media/base/video_decoder_config.h"
|
| -#include "ui/gfx/geometry/size.h"
|
| +#include "media/base/android/media_codec_util.h"
|
| +#include "media/base/media_export.h"
|
|
|
| namespace media {
|
|
|
| @@ -34,59 +34,12 @@ enum MediaCodecStatus {
|
| MEDIA_CODEC_ERROR
|
| };
|
|
|
| -// Codec direction. Keep this in sync with MediaCodecBridge.java.
|
| -enum MediaCodecDirection {
|
| - MEDIA_CODEC_DECODER,
|
| - MEDIA_CODEC_ENCODER,
|
| -};
|
| -
|
| -// This class serves as a bridge for native code to call java functions inside
|
| -// Android MediaCodec class. For more information on Android MediaCodec, check
|
| +// Interface for wrapping different Android MediaCodec implementations. For
|
| +// more information on Android MediaCodec, check
|
| // http://developer.android.com/reference/android/media/MediaCodec.html
|
| // Note: MediaCodec is only available on JB and greater.
|
| -// Use AudioCodecBridge or VideoCodecBridge to create an instance of this
|
| -// object.
|
| -//
|
| -// TODO(fischman,xhwang): replace this (and the enums that go with it) with
|
| -// chromium's JNI auto-generation hotness.
|
| class MEDIA_EXPORT MediaCodecBridge {
|
| public:
|
| - // Returns true if MediaCodec is available on the device.
|
| - // All other static methods check IsAvailable() internally. There's no need
|
| - // to check IsAvailable() explicitly before calling them.
|
| - static bool IsAvailable();
|
| -
|
| - // Returns true if MediaCodec.setParameters() is available on the device.
|
| - static bool SupportsSetParameters();
|
| -
|
| - // Returns true if MediaCodec.getName() is available on the device.
|
| - static bool SupportsGetName();
|
| -
|
| - // Returns whether MediaCodecBridge has a decoder that |is_secure| and can
|
| - // decode |codec| type.
|
| - static bool CanDecode(const std::string& codec, bool is_secure);
|
| -
|
| - // Represents supported codecs on android.
|
| - // TODO(qinmin): Currently the codecs string only contains one codec. Do we
|
| - // need to support codecs separated by comma. (e.g. "vp8" -> "vp8, vp8.0")?
|
| - struct CodecsInfo {
|
| - std::string codecs; // E.g. "vp8" or "avc1".
|
| - std::string name; // E.g. "OMX.google.vp8.decoder".
|
| - MediaCodecDirection direction;
|
| - };
|
| -
|
| - // Get a list of supported codecs.
|
| - static std::vector<CodecsInfo> GetCodecsInfo();
|
| -
|
| - // Get default codec name for |mime_type|.
|
| - static std::string GetDefaultCodecName(const std::string& mime_type,
|
| - MediaCodecDirection direction);
|
| -
|
| - // Get a list of encoder supported color formats for |mime_type|.
|
| - // The mapping of color format name and its value refers to
|
| - // MediaCodecInfo.CodecCapabilities.
|
| - static std::set<int> GetEncoderColorFormats(const std::string& mime_type);
|
| -
|
| virtual ~MediaCodecBridge();
|
|
|
| // Resets both input and output, all indices previously returned in calls to
|
| @@ -95,31 +48,36 @@ class MEDIA_EXPORT MediaCodecBridge {
|
| // words, there will be no outputs until new input is provided.
|
| // Returns MEDIA_CODEC_ERROR if an unexpected error happens, or Media_CODEC_OK
|
| // otherwise.
|
| - MediaCodecStatus Reset();
|
| + virtual MediaCodecStatus Reset() = 0;
|
| +
|
| + // Calls start() against the media codec instance. Returns whether media
|
| + // codec was successfully started.
|
| + virtual bool Start() WARN_UNUSED_RESULT = 0;
|
|
|
| // Finishes the decode/encode session. The instance remains active
|
| // and ready to be StartAudio/Video()ed again. HOWEVER, due to the buggy
|
| // vendor's implementation , b/8125974, Stop() -> StartAudio/Video() may not
|
| // work on some devices. For reliability, Stop() -> delete and recreate new
|
| // instance -> StartAudio/Video() is recommended.
|
| - void Stop();
|
| + virtual void Stop() = 0;
|
|
|
| // Used for getting output format. This is valid after DequeueInputBuffer()
|
| // returns a format change by returning INFO_OUTPUT_FORMAT_CHANGED
|
| - void GetOutputFormat(int* width, int* height);
|
| + virtual void GetOutputFormat(int* width, int* height) = 0;
|
|
|
| // Used for checking for new sampling rate after DequeueInputBuffer() returns
|
| // INFO_OUTPUT_FORMAT_CHANGED
|
| - int GetOutputSamplingRate();
|
| + virtual int GetOutputSamplingRate() = 0;
|
|
|
| // Submits a byte array to the given input buffer. Call this after getting an
|
| - // available buffer from DequeueInputBuffer(). If |data| is NULL, assume the
|
| + // available buffer from DequeueInputBuffer(). If |data| is NULL, assume the
|
| // input buffer has already been populated (but still obey |size|).
|
| // |data_size| must be less than kint32max (because Java).
|
| - MediaCodecStatus QueueInputBuffer(int index,
|
| - const uint8* data,
|
| - size_t data_size,
|
| - const base::TimeDelta& presentation_time);
|
| + virtual MediaCodecStatus QueueInputBuffer(
|
| + int index,
|
| + const uint8* data,
|
| + size_t data_size,
|
| + const base::TimeDelta& presentation_time) = 0;
|
|
|
| // Similar to the above call, but submits a buffer that is encrypted. Note:
|
| // NULL |subsamples| indicates the whole buffer is encrypted. If |data| is
|
| @@ -138,7 +96,7 @@ class MEDIA_EXPORT MediaCodecBridge {
|
| // and MediaCodecPlayer.
|
| // TODO(timav): remove this method and keep only the one above after we
|
| // switch to the Spitzer pipeline.
|
| - MediaCodecStatus QueueSecureInputBuffer(
|
| + virtual MediaCodecStatus QueueSecureInputBuffer(
|
| int index,
|
| const uint8* data,
|
| size_t data_size,
|
| @@ -148,10 +106,10 @@ class MEDIA_EXPORT MediaCodecBridge {
|
| int iv_size,
|
| const SubsampleEntry* subsamples,
|
| int subsamples_size,
|
| - const base::TimeDelta& presentation_time);
|
| + const base::TimeDelta& presentation_time) = 0;
|
|
|
| // Submits an empty buffer with a EOS (END OF STREAM) flag.
|
| - void QueueEOS(int input_buffer_index);
|
| + virtual void QueueEOS(int input_buffer_index) = 0;
|
|
|
| // Returns:
|
| // MEDIA_CODEC_OK if an input buffer is ready to be filled with valid data,
|
| @@ -159,8 +117,8 @@ class MEDIA_EXPORT MediaCodecBridge {
|
| // MEDIA_CODEC_ERROR if unexpected error happens.
|
| // Note: Never use infinite timeout as this would block the decoder thread and
|
| // prevent the decoder job from being released.
|
| - MediaCodecStatus DequeueInputBuffer(const base::TimeDelta& timeout,
|
| - int* index);
|
| + virtual MediaCodecStatus DequeueInputBuffer(const base::TimeDelta& timeout,
|
| + int* index) = 0;
|
|
|
| // Dequeues an output buffer, block at most timeout_us microseconds.
|
| // Returns the status of this operation. If OK is returned, the output
|
| @@ -171,159 +129,56 @@ class MEDIA_EXPORT MediaCodecBridge {
|
| // prevent the decoder job from being released.
|
| // TODO(xhwang): Can we drop |end_of_stream| and return
|
| // MEDIA_CODEC_OUTPUT_END_OF_STREAM?
|
| - MediaCodecStatus DequeueOutputBuffer(const base::TimeDelta& timeout,
|
| - int* index,
|
| - size_t* offset,
|
| - size_t* size,
|
| - base::TimeDelta* presentation_time,
|
| - bool* end_of_stream,
|
| - bool* key_frame);
|
| + virtual MediaCodecStatus DequeueOutputBuffer(
|
| + const base::TimeDelta& timeout,
|
| + int* index,
|
| + size_t* offset,
|
| + size_t* size,
|
| + base::TimeDelta* presentation_time,
|
| + bool* end_of_stream,
|
| + bool* key_frame) = 0;
|
|
|
| // Returns the buffer to the codec. If you previously specified a surface when
|
| // configuring this video decoder you can optionally render the buffer.
|
| - void ReleaseOutputBuffer(int index, bool render);
|
| + virtual void ReleaseOutputBuffer(int index, bool render) = 0;
|
|
|
| // Returns the number of output buffers used by the codec.
|
| // TODO(qinmin): this call is deprecated in Lollipop.
|
| - int GetOutputBuffersCount();
|
| + virtual int GetOutputBuffersCount();
|
|
|
| // Returns the capacity of each output buffer used by the codec.
|
| // TODO(qinmin): this call is deprecated in Lollipop.
|
| - size_t GetOutputBuffersCapacity();
|
| + virtual size_t GetOutputBuffersCapacity();
|
|
|
| // Returns an input buffer's base pointer and capacity.
|
| - void GetInputBuffer(int input_buffer_index, uint8** data, size_t* capacity);
|
| + virtual void GetInputBuffer(int input_buffer_index,
|
| + uint8** data,
|
| + size_t* capacity) = 0;
|
|
|
| // Copy |dst_size| bytes from output buffer |index|'s |offset| onwards into
|
| // |*dst|.
|
| - bool CopyFromOutputBuffer(int index, size_t offset, void* dst, int dst_size);
|
| -
|
| - static bool RegisterMediaCodecBridge(JNIEnv* env);
|
| + virtual bool CopyFromOutputBuffer(int index,
|
| + size_t offset,
|
| + void* dst,
|
| + int dst_size) = 0;
|
|
|
| protected:
|
| + MediaCodecBridge();
|
| +
|
| // Returns true if |mime_type| is known to be unaccelerated (i.e. backed by a
|
| // software codec instead of a hardware one).
|
| static bool IsKnownUnaccelerated(const std::string& mime_type,
|
| MediaCodecDirection direction);
|
|
|
| - MediaCodecBridge(const std::string& mime,
|
| - bool is_secure,
|
| - MediaCodecDirection direction);
|
| -
|
| - // Calls start() against the media codec instance. Used in StartXXX() after
|
| - // configuring media codec. Returns whether media codec was successfully
|
| - // started.
|
| - bool StartInternal() WARN_UNUSED_RESULT;
|
| -
|
| - // Called to get the buffer address given the output buffer index and offset.
|
| - // This function returns the size of the output and |addr| is the pointer to
|
| - // the address to read.
|
| - int GetOutputBufferAddress(int index, size_t offset, void** addr);
|
| -
|
| - jobject media_codec() { return j_media_codec_.obj(); }
|
| - MediaCodecDirection direction_;
|
| -
|
| - private:
|
| // Fills a particular input buffer; returns false if |data_size| exceeds the
|
| // input buffer's capacity (and doesn't touch the input buffer in that case).
|
| bool FillInputBuffer(int index,
|
| const uint8* data,
|
| size_t data_size) WARN_UNUSED_RESULT;
|
|
|
| - // Java MediaCodec instance.
|
| - base::android::ScopedJavaGlobalRef<jobject> j_media_codec_;
|
| -
|
| DISALLOW_COPY_AND_ASSIGN(MediaCodecBridge);
|
| };
|
|
|
| -class AudioCodecBridge : public MediaCodecBridge {
|
| - public:
|
| - // Returns an AudioCodecBridge instance if |codec| is supported, or a NULL
|
| - // pointer otherwise.
|
| - static AudioCodecBridge* Create(const AudioCodec& codec);
|
| -
|
| - // See MediaCodecBridge::IsKnownUnaccelerated().
|
| - static bool IsKnownUnaccelerated(const AudioCodec& codec);
|
| -
|
| - // Start the audio codec bridge.
|
| - bool Start(const AudioCodec& codec, int sample_rate, int channel_count,
|
| - const uint8* extra_data, size_t extra_data_size,
|
| - int64 codec_delay_ns, int64 seek_preroll_ns,
|
| - bool play_audio, jobject media_crypto) WARN_UNUSED_RESULT;
|
| -
|
| - // Plays the output buffer right away or save for later playback if |postpone|
|
| - // is set to true. This call must be called after DequeueOutputBuffer() and
|
| - // before ReleaseOutputBuffer. The data is extracted from the output buffers
|
| - // using |index|, |size| and |offset|. Returns the playback head position
|
| - // expressed in frames.
|
| - // When |postpone| is set to true, the next PlayOutputBuffer() should have
|
| - // postpone == false, and it will play two buffers: the postponed one and
|
| - // the one identified by |index|.
|
| - int64 PlayOutputBuffer(int index,
|
| - size_t size,
|
| - size_t offset,
|
| - bool postpone = false);
|
| -
|
| - // Set the volume of the audio output.
|
| - void SetVolume(double volume);
|
| -
|
| - private:
|
| - explicit AudioCodecBridge(const std::string& mime);
|
| -
|
| - // Configure the java MediaFormat object with the extra codec data passed in.
|
| - bool ConfigureMediaFormat(jobject j_format, const AudioCodec& codec,
|
| - const uint8* extra_data, size_t extra_data_size,
|
| - int64 codec_delay_ns, int64 seek_preroll_ns);
|
| -};
|
| -
|
| -class MEDIA_EXPORT VideoCodecBridge : public MediaCodecBridge {
|
| - public:
|
| - // See MediaCodecBridge::IsKnownUnaccelerated().
|
| - static bool IsKnownUnaccelerated(const VideoCodec& codec,
|
| - MediaCodecDirection direction);
|
| -
|
| - // Create, start, and return a VideoCodecBridge decoder or NULL on failure.
|
| - static VideoCodecBridge* CreateDecoder(
|
| - const VideoCodec& codec, // e.g. media::kCodecVP8
|
| - bool is_secure,
|
| - const gfx::Size& size, // Output frame size.
|
| - jobject surface, // Output surface, optional.
|
| - jobject media_crypto); // MediaCrypto object, optional.
|
| -
|
| - // Create, start, and return a VideoCodecBridge encoder or NULL on failure.
|
| - static VideoCodecBridge* CreateEncoder(
|
| - const VideoCodec& codec, // e.g. media::kCodecVP8
|
| - const gfx::Size& size, // input frame size
|
| - int bit_rate, // bits/second
|
| - int frame_rate, // frames/second
|
| - int i_frame_interval, // count
|
| - int color_format); // MediaCodecInfo.CodecCapabilities.
|
| -
|
| - void SetVideoBitrate(int bps);
|
| - void RequestKeyFrameSoon();
|
| -
|
| - // Returns whether adaptive playback is supported for this object given
|
| - // the new size.
|
| - bool IsAdaptivePlaybackSupported(int width, int height);
|
| -
|
| - // Test-only method to set the return value of IsAdaptivePlaybackSupported().
|
| - // Without this function, the return value of that function will be device
|
| - // dependent. If |adaptive_playback_supported| is equal to 0, the return value
|
| - // will be false. If |adaptive_playback_supported| is larger than 0, the
|
| - // return value will be true.
|
| - void set_adaptive_playback_supported_for_testing(
|
| - int adaptive_playback_supported) {
|
| - adaptive_playback_supported_for_testing_ = adaptive_playback_supported;
|
| - }
|
| -
|
| - private:
|
| - VideoCodecBridge(const std::string& mime,
|
| - bool is_secure,
|
| - MediaCodecDirection direction);
|
| -
|
| - int adaptive_playback_supported_for_testing_;
|
| -};
|
| -
|
| } // namespace media
|
|
|
| #endif // MEDIA_BASE_ANDROID_MEDIA_CODEC_BRIDGE_H_
|
|
|