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

Unified Diff: media/filters/android/media_codec_audio_decoder.h

Issue 1651673002: Add MediaCodecAudioDecoder implementation (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed comments Created 4 years, 10 months 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/filters/android/media_codec_audio_decoder.h
diff --git a/media/filters/android/media_codec_audio_decoder.h b/media/filters/android/media_codec_audio_decoder.h
index 1e307893a1534a617afb8b6a1489aa27795cc823..3c3f2d56017e982f49f4db980939a3ddcdb79d68 100644
--- a/media/filters/android/media_codec_audio_decoder.h
+++ b/media/filters/android/media_codec_audio_decoder.h
@@ -10,13 +10,11 @@
#include "base/macros.h"
#include "base/memory/scoped_ptr.h"
-#include "base/memory/weak_ptr.h"
#include "base/time/time.h"
#include "base/timer/timer.h"
#include "media/base/android/media_codec_bridge.h"
#include "media/base/audio_decoder.h"
#include "media/base/audio_decoder_config.h"
-#include "media/base/media_export.h"
namespace base {
class SingleThreadTaskRunner;
@@ -53,10 +51,15 @@ namespace media {
// Because both dequeuing and enqueuing of an input buffer can fail, the
// implementation puts the input |DecoderBuffer|s and the corresponding decode
// callbacks into an input queue. The decoder has a timer that periodically
-// tries to send the front buffer from the input queue to the MediaCodec. In
-// the case of success the element is removed from the queue, the decode
-// callback is fired and the decoding process advances. The same timer tries to
-// dequeue an output buffer.
+// fires the decoding cycle that has two steps. The first step tries to send the
+// front buffer from the input queue to the MediaCodec. In the case of success
+// the element is removed from the queue, the decode callback is fired and the
+// decoding process advances. The second step tries to dequeue an output buffer,
+// and uses it in the case of success.
+//
+// The failures in both steps are normal and they happen periodically since
+// both input and output buffers become available at unpredictable moments. The
+// timer is here to repeat the dequeueing attempts.
//
// Although one can specify a delay in the MediaCodec's dequeue operations,
// this implementation follows the simple logic which is similar to
@@ -94,7 +97,7 @@ namespace media {
// | | |
// [Error] [Ready] [Error]
-class MEDIA_EXPORT MediaCodecAudioDecoder : public AudioDecoder {
+class MediaCodecAudioDecoder : public AudioDecoder {
public:
explicit MediaCodecAudioDecoder(
const scoped_refptr<base::SingleThreadTaskRunner>& task_runner);
@@ -143,6 +146,21 @@ class MEDIA_EXPORT MediaCodecAudioDecoder : public AudioDecoder {
// Returns true if any input was processed.
bool QueueInput();
+ // A helper method for QueueInput(). Dequeues an empty input buffer from the
+ // codec and returns its index or -1 if the codec is busy or an error occurs.
+ // In the case of an error sets STATE_ERROR.
+ int DequeueInputBuffer();
+
+ // A helper method for QueueInput(). Fills an input buffer referred to by
+ // |input_buf_index| with data and enqueues it to the codec. Returns true
+ // if succeeded or false if an error occurs or there is no good CDM key.
+ // May set STATE_DRAINING, STATE_WAITING_FOR_KEY or STATE_ERROR.
+ bool EnqueueInputBuffer(int input_buf_index);
+
+ // Calls DecodeCB with |frame_decode_status| for every frame in |input_queue|
+ // and then clears it.
+ void ClearInputQueue(Status frame_decode_status);
+
// Dequeues all output buffers from MediaCodec that are immediately available.
// Returns true if any output buffer was received from MediaCodec.
bool DequeueOutput();
@@ -154,17 +172,15 @@ class MEDIA_EXPORT MediaCodecAudioDecoder : public AudioDecoder {
// Helper method to change the state.
void SetState(State new_state);
- // The following helper methods ConfigureMediaCodec(), OnDecodedFrame(),
- // OnOutputFormatChanged() are specific to the stream (audio/video), but
- // others seem to apply to any MediaCodec decoder.
+ // Helper method for DequeueOutput(), processes end of stream.
+ void OnDecodedEos(const OutputBufferInfo& out);
+
+ // The following helper methods OnDecodedFrame() and OnOutputFormatChanged()
+ // are specific to the stream (audio/video), but others seem to apply to any
+ // MediaCodec decoder.
// TODO(timav): refactor the common part out and use it here and in AVDA
// (http://crbug.com/583082).
- // Configures MediaCodec with |config|. Returns valid MediaCodec pointer if
- // succeeded or null if configuration failed.
- scoped_ptr<MediaCodecBridge> ConfigureMediaCodec(
- const AudioDecoderConfig& config);
-
// Processes the output buffer after it comes from MediaCodec.
void OnDecodedFrame(const OutputBufferInfo& out);
@@ -206,9 +222,6 @@ class MEDIA_EXPORT MediaCodecAudioDecoder : public AudioDecoder {
// there is no such buffer.
int pending_input_buf_index_;
- // Weak pointer factory must be the last member variable.
- base::WeakPtrFactory<MediaCodecAudioDecoder> weak_factory_;
-
DISALLOW_COPY_AND_ASSIGN(MediaCodecAudioDecoder);
};

Powered by Google App Engine
This is Rietveld 408576698