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

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

Issue 1651673002: Add MediaCodecAudioDecoder implementation (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Removed CDM stuff, fixed Opus 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/android_audio_decoder.h
diff --git a/media/filters/android/android_audio_decoder.h b/media/filters/android/android_audio_decoder.h
new file mode 100644
index 0000000000000000000000000000000000000000..4e40054482bae6d0db633f1f8a8bfa5278f4a2ee
--- /dev/null
+++ b/media/filters/android/android_audio_decoder.h
@@ -0,0 +1,164 @@
+// Copyright 2016 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_FILTERS_ANDROID_ANDROID_AUDIO_DECODER_H_
+#define MEDIA_FILTERS_ANDROID_ANDROID_AUDIO_DECODER_H_
Tima Vaisburd 2016/02/04 22:59:12 Moved the file into media/filters/android. The AND
xhwang 2016/02/05 21:37:37 *_audio_decoder.h is more media-ish and *_android.
Tima Vaisburd 2016/02/06 03:54:12 Just to clarify: "Android" in the name of the clas
xhwang 2016/02/08 20:03:34 MediaCodecAudioDecoder does sound a better name. T
+
+#include <deque>
xhwang 2016/02/05 21:37:37 add an empty line here
Tima Vaisburd 2016/02/06 03:54:12 Done.
+#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/android/media_drm_bridge.h"
+#include "media/base/audio_decoder.h"
+#include "media/base/audio_decoder_config.h"
+#include "media/base/cdm_context.h"
+#include "media/base/media_export.h"
+#include "media/base/media_keys.h"
+
+namespace base {
+class SingleThreadTaskRunner;
+}
+
+namespace media {
+
+// AudioDecoder based on Android's MediaCodec API.
+//
+// It is intended for EME encrypted audio streams wich on Android require
+// the MediaCodec API for the playback and coordination with MediaDRM API.
+// Therefore, this decoder is a decrypting decoder: it is able to accept an
+// encrypted stream and produce the decrypted and decoded output.
xhwang 2016/02/05 21:37:37 When encrypted audio streams work, I suppose clear
Tima Vaisburd 2016/02/06 03:54:12 I did not mean to limit, rather I wanted to say th
xhwang 2016/02/08 20:03:33 I guess "this decoder is a decrypting decoder" is
+//
+// In order to use MediaCodec and MediaDRM API we plan to use it in the GPU
+// process through Mojo IPC. See https://docs.google.com/a/google.com/document/
+// d/1YwMZdC-eWe6EkAshSqy8P1b7h2XU469RvbyGPW6EpZs
Tima Vaisburd 2016/02/04 22:59:12 This link points to the Google restricted doc, is
xhwang 2016/02/05 21:37:37 We'd like to avoid it. Actually, you don't really
xhwang 2016/02/05 21:37:37 nit: A link that across two lines with "//" and a
Tima Vaisburd 2016/02/06 03:54:11 Removed
Tima Vaisburd 2016/02/06 03:54:12 Acknowledged.
+
+class MEDIA_EXPORT AndroidAudioDecoder : public AudioDecoder {
+ public:
+ AndroidAudioDecoder(scoped_refptr<base::SingleThreadTaskRunner> task_runner);
xhwang 2016/02/05 21:37:37 explicit
xhwang 2016/02/05 21:37:37 in media/ we like to pass scoped_refptr by const-r
Tima Vaisburd 2016/02/06 03:54:12 Done.
Tima Vaisburd 2016/02/06 03:54:12 Done.
+ ~AndroidAudioDecoder() override;
+
+ // AudioDecoder implementation.
+ std::string GetDisplayName() const override;
+ void Initialize(const AudioDecoderConfig& config,
+ const SetCdmReadyCB& set_cdm_ready_cb,
+ const InitCB& init_cb,
+ const OutputCB& output_cb) override;
+ void Decode(const scoped_refptr<DecoderBuffer>& buffer,
+ const DecodeCB& decode_cb) override;
+ void Reset(const base::Closure& closure) override;
+
+ private:
+ // Possible states.
+ enum State {
xhwang 2016/02/05 21:37:37 Can we have comments/doc about how these states wo
xhwang 2016/02/08 20:03:34 This is not done :) I'll continue to review the im
+ kStateUninitialized,
+ kStateReady,
+ kStateWaitingForKey,
+ kStateDraining,
+ kStateDrained,
+ kStateError,
xhwang 2016/02/05 21:37:37 Use MACRO_STYLE for enums: https://www.chromium.o
Tima Vaisburd 2016/02/06 03:54:11 This rationale argues for deviation from the Googl
xhwang 2016/02/08 20:03:33 Once upon a time kCamelCase was acceptable for enu
+ };
+
+ // Information about the MediaCodec's output buffer.
+ struct OutputBufferInfo {
+ int buf_index;
+ size_t offset;
+ size_t size;
+ base::TimeDelta pts;
+ bool is_eos;
+ bool is_key_frame;
+ };
+
+ // Callback called when a new key is available after the codec received
+ // the status MEDIA_CODEC_NO_KEY.
+ void OnKeyAdded();
+
+ // Does the MediaCodec processing cycle: enqueues an input buffer, then
+ // dequeues output buffers.
+ void DoIOTask();
+
+ // Enqueue one pending input buffer into MediaCodec if MediaCodec has a room.
xhwang 2016/02/05 21:37:37 nit: here and below, Enqueue_s_
Tima Vaisburd 2016/02/06 03:54:12 Done.
+ // Returns true if any input was processed.
+ bool QueueInput();
+
+ // Dequeue all output buffers from MediaCodec that are immediately available.
xhwang 2016/02/05 21:37:37 what's the return value?
Tima Vaisburd 2016/02/06 03:54:11 Done.
+ bool DequeueOutput();
+
+ // Start or stop our work-polling timer based on whether we did any work, and
+ // how long it has been since we've done work. Calling this with true will
+ // start the timer. Calling it with false may stop the timer.
+ void ManageTimer(bool did_work);
xhwang 2016/02/05 21:37:37 This seems complicated: "will start the timer" and
Tima Vaisburd 2016/02/06 03:54:11 Rewrote the explanation.
+
+ // 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 decoder which would be based on MediaCodec.
+ // TODO(timav): refactor the common part out and use it here and in AVDA
+ // (http://crbug.com/583082).
+
+ // Configures |media_codec_| with the given codec parameters from the client.
xhwang 2016/02/05 21:37:37 Can we s/given codec parameters from the client/|c
Tima Vaisburd 2016/02/06 03:54:12 Done.
+ bool ConfigureMediaCodec();
+
+ // Processes the output buffer after it comes from MediaCodec.
+ void OnDecodedFrame(const OutputBufferInfo* out);
xhwang 2016/02/05 21:37:37 We don't typically use const-pointer. Can we use c
Tima Vaisburd 2016/02/06 03:54:12 Done.
+
+ // Processed the output format change.
+ void OnOutputFormatChanged();
+
+ // A helper function for logging.
+ static const char* AsString(State state);
xhwang 2016/02/05 21:37:37 Can you make this a file-scope function in the .cc
Tima Vaisburd 2016/02/06 03:54:12 Wouldn't it require making the State public?
+
+ scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
xhwang 2016/02/05 21:37:37 Is this class single threaded? Will everything run
+
+ // The current state of the object.
+ State state_;
+
+ // The queue of encoded (and maybe encrypted) buffers.
+ using BufferCBPair = std::pair<scoped_refptr<DecoderBuffer>, DecodeCB>;
xhwang 2016/02/05 21:37:37 Add include for std::pair: <utility>
Tima Vaisburd 2016/02/06 03:54:12 Done.
+ using InputQueue = std::deque<BufferCBPair>;
+ InputQueue input_queue_;
xhwang 2016/02/05 21:37:37 Can you comment on why we need to put input buffer
Tima Vaisburd 2016/02/06 03:54:12 Done.
+
+ // Decoder configuration cache.
+ AudioDecoderConfig config_;
+
+ // Frequently used constants derived from |config_|.
+ int channel_count_;
+ int bytes_per_frame_;
+
+ // Callback that reports the end of initialization and its status.
+ InitCB init_cb_;
+
+ // Callback that delivers output frames.
+ OutputCB output_cb_;
+
+ // DecodeCB that should be fired after the decoder has been flashed in case
+ // of EOS.
+ DecodeCB eos_decode_cb_;
+
+ // The bridge to Android's MediaCodec API.
+ scoped_ptr<MediaCodecBridge> media_codec_;
+
+ // Repeating timer that kicks MediaCodec operation.
+ base::RepeatingTimer io_timer_;
+
+ // Time at which we last did useful work on |io_timer_|.
+ base::TimeTicks most_recent_work_;
xhwang 2016/02/05 21:37:37 nit: |most_recent_work_| doesn't sounds like a tim
Tima Vaisburd 2016/02/06 03:54:12 s/most_recent_work_/idle_time_begin_/
+
+ // Index of the dequeued and filled buffer that we keep trying to enqueue.
+ // Such buffer appears in MEDIA_CODEC_NO_KEY processing.
+ int pending_input_buf_index_;
+
+ // Weak pointer factory must be the last member variable.
+ base::WeakPtrFactory<AndroidAudioDecoder> weak_factory_;
+
+ DISALLOW_COPY_AND_ASSIGN(AndroidAudioDecoder);
+};
+
+} // namespace media
+
+#endif // MEDIA_FILTERS_ANDROID_ANDROID_AUDIO_DECODER_H_

Powered by Google App Engine
This is Rietveld 408576698