Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(195)

Unified Diff: media/base/android/sdk_media_codec_bridge.h

Issue 1472943002: Refactor MediaCodecBridge to add support for NDK APIs (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: add media_codec_util.cc(h) Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: media/base/android/sdk_media_codec_bridge.h
diff --git a/media/base/android/sdk_media_codec_bridge.h b/media/base/android/sdk_media_codec_bridge.h
new file mode 100644
index 0000000000000000000000000000000000000000..6c882f33c5cd8f8c524e98f825fe18c688d2a9e8
--- /dev/null
+++ b/media/base/android/sdk_media_codec_bridge.h
@@ -0,0 +1,198 @@
+// Copyright (c) 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef MEDIA_BASE_ANDROID_SDK_MEDIA_CODEC_BRIDGE_H_
+#define MEDIA_BASE_ANDROID_SDK_MEDIA_CODEC_BRIDGE_H_
+
+#include <jni.h>
+#include <set>
+#include <string>
+
+#include "base/android/scoped_java_ref.h"
+#include "base/macros.h"
+#include "base/time/time.h"
+#include "media/base/android/media_codec_bridge.h"
+#include "media/base/audio_decoder_config.h"
+#include "media/base/media_export.h"
+#include "media/base/video_decoder_config.h"
+#include "ui/gfx/geometry/size.h"
+
+namespace media {
+
+// This class implements MediaCodecBridge using android MediaCodec SDK APIs.
+class MEDIA_EXPORT SdkMediaCodecBridge : public MediaCodecBridge {
+ public:
+ ~SdkMediaCodecBridge() override;
+
+ // MediaCodecBridge implementations.
+ MediaCodecStatus Reset() override;
+ bool Start() override;
+ void Stop() override;
+ void GetOutputFormat(int* width, int* height) override;
+ int GetOutputSamplingRate() override;
+ MediaCodecStatus QueueInputBuffer(
+ int index,
+ const uint8* data,
+ size_t data_size,
+ const base::TimeDelta& presentation_time) override;
+ using MediaCodecBridge::QueueSecureInputBuffer;
+ MediaCodecStatus QueueSecureInputBuffer(
+ int index,
+ const uint8* data,
+ size_t data_size,
+ const uint8* key_id,
+ int key_id_size,
+ const uint8* iv,
+ int iv_size,
+ const SubsampleEntry* subsamples,
+ int subsamples_size,
+ const base::TimeDelta& presentation_time) override;
+ void QueueEOS(int input_buffer_index) override;
+ MediaCodecStatus DequeueInputBuffer(const base::TimeDelta& timeout,
+ int* index) override;
+ 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) override;
+ void ReleaseOutputBuffer(int index, bool render) override;
+ int GetOutputBuffersCount() override;
+ size_t GetOutputBuffersCapacity() override;
+ void GetInputBuffer(int input_buffer_index,
+ uint8** data,
+ size_t* capacity) override;
+ bool CopyFromOutputBuffer(int index,
+ size_t offset,
+ void* dst,
+ int dst_size) override;
+
+ static bool RegisterSdkMediaCodecBridge(JNIEnv* env);
+
+ protected:
+ SdkMediaCodecBridge(const std::string& mime,
+ bool is_secure,
+ MediaCodecDirection direction);
+
+ // 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:
+ // Java MediaCodec instance.
+ base::android::ScopedJavaGlobalRef<jobject> j_media_codec_;
+
+ DISALLOW_COPY_AND_ASSIGN(SdkMediaCodecBridge);
+};
+
+// Class for handling audio decoding using android MediaCodec APIs.
+// TODO(qinmin): implement the logic to switch between NDK and SDK
+// MediaCodecBridge.
+class MEDIA_EXPORT AudioCodecBridge : public SdkMediaCodecBridge {
+ 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 ConfigureAndStart(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 for handling video encoding/decoding using android MediaCodec APIs.
+// TODO(qinmin): implement the logic to switch between NDK and SDK
+// MediaCodecBridge.
+class MEDIA_EXPORT VideoCodecBridge : public SdkMediaCodecBridge {
+ 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_SDK_MEDIA_CODEC_BRIDGE_H_

Powered by Google App Engine
This is Rietveld 408576698