diff options
Diffstat (limited to 'chromium/media/base/audio_encoder.h')
-rw-r--r-- | chromium/media/base/audio_encoder.h | 104 |
1 files changed, 53 insertions, 51 deletions
diff --git a/chromium/media/base/audio_encoder.h b/chromium/media/base/audio_encoder.h index c25218c9ee8..2d3362bebca 100644 --- a/chromium/media/base/audio_encoder.h +++ b/chromium/media/base/audio_encoder.h @@ -6,6 +6,7 @@ #define MEDIA_BASE_AUDIO_ENCODER_H_ #include <memory> +#include <vector> #include "base/callback.h" #include "base/sequence_checker.h" @@ -46,71 +47,72 @@ struct MEDIA_EXPORT EncodedAudioBuffer { const base::TimeTicks timestamp; }; -// Defines an interface for audio encoders. Concrete encoders must implement the -// EncodeAudioImpl() function. +// Defines an interface for audio encoders. class MEDIA_EXPORT AudioEncoder { public: + struct MEDIA_EXPORT Options { + Options(); + Options(const Options&); + ~Options(); + + base::Optional<int> bitrate; + + int channels; + + int sample_rate; + }; + + // A sequence of codec specific bytes, commonly known as extradata. + using CodecDescription = std::vector<uint8_t>; + // Signature of the callback invoked to provide the encoded audio data. It is - // invoked on the same sequence on which EncodeAudio() is called. The utility - // media::BindToCurrentLoop() can be used to create a callback that will be - // invoked on the same sequence it is constructed on. - using EncodeCB = base::RepeatingCallback<void(EncodedAudioBuffer output)>; + // invoked on the same sequence on which EncodeAudio() is called. + using OutputCB = + base::RepeatingCallback<void(EncodedAudioBuffer output, + base::Optional<CodecDescription>)>; // Signature of the callback to report errors. - using StatusCB = base::RepeatingCallback<void(Status error)>; - - // Constructs the encoder given the audio parameters of the input to this - // encoder, and a callback to trigger to provide the encoded audio data. - // |input_params| must be valid, and |encode_callback| and |status_callback| - // must not be null callbacks. All calls to EncodeAudio() must happen on the - // same sequence (usually an encoder blocking pool sequence), but the encoder - // itself can be constructed on any sequence. - AudioEncoder(const AudioParameters& input_params, - EncodeCB encode_callback, - StatusCB status_callback); + using StatusCB = base::OnceCallback<void(Status error)>; + + AudioEncoder(); AudioEncoder(const AudioEncoder&) = delete; AudioEncoder& operator=(const AudioEncoder&) = delete; virtual ~AudioEncoder(); - const AudioParameters& audio_input_params() const { - return audio_input_params_; - } - - // Performs various checks before calling EncodeAudioImpl() which does the - // actual encoding. - void EncodeAudio(const AudioBus& audio_bus, base::TimeTicks capture_time); + // Initializes an AudioEncoder with the given input option, executing + // the |done_cb| upon completion. |output_cb| is called for each encoded audio + // chunk. + // + // No AudioEncoder calls should be made before |done_cb| is executed. + virtual void Initialize(const Options& options, + OutputCB output_cb, + StatusCB done_cb) = 0; + + // Requests contents of |audio_bus| to be encoded. + // |capture_time| is a media time at the end of the audio piece in the + // |audio_bus|. + // + // |done_cb| is called upon encode completion and can possible convey an + // encoding error. It doesn't depend on future call to encoder's methods. + // |done_cb| will not be called from within this method. + // + // After the input, or several inputs, are encoded the encoder calls + // |output_cb|. + // |output_cb| may be called before or after |done_cb|, + // including before Encode() returns. + virtual void Encode(std::unique_ptr<AudioBus> audio_bus, + base::TimeTicks capture_time, + StatusCB done_cb) = 0; // Some encoders may choose to buffer audio frames before they encode them. - // This function provides a mechanism to drain and encode any buffered frames - // (if any). Must be called on the encoder sequence. - void Flush(); + // Requests all outputs for already encoded frames to be + // produced via |output_cb| and calls |done_cb| after that. + virtual void Flush(StatusCB done_cb) = 0; protected: - const EncodeCB& encode_callback() const { return encode_callback_; } - const StatusCB& status_callback() const { return status_callback_; } - base::TimeTicks last_capture_time() const { return last_capture_time_; } - - virtual void EncodeAudioImpl(const AudioBus& audio_bus, - base::TimeTicks capture_time) = 0; - - virtual void FlushImpl() = 0; - - // Computes the timestamp of an AudioBus which has |num_frames| and was - // captured at |capture_time|. This timestamp is the capture time of the first - // sample in that AudioBus. - base::TimeTicks ComputeTimestamp(int num_frames, - base::TimeTicks capture_time) const; - - private: - const AudioParameters audio_input_params_; - - const EncodeCB encode_callback_; - - const StatusCB status_callback_; + Options options_; - // The capture time of the most recent |audio_bus| delivered to - // EncodeAudio(). - base::TimeTicks last_capture_time_; + OutputCB output_cb_; SEQUENCE_CHECKER(sequence_checker_); }; |