audio_decoder.h revision a1401311d1ab56c4ed0a474bd38c108f75cb0cd9
1// Copyright (c) 2012 The Chromium Authors. All rights reserved. 2// Use of this source code is governed by a BSD-style license that can be 3// found in the LICENSE file. 4 5#ifndef MEDIA_BASE_AUDIO_DECODER_H_ 6#define MEDIA_BASE_AUDIO_DECODER_H_ 7 8#include "base/callback.h" 9#include "base/memory/ref_counted.h" 10#include "media/base/audio_decoder_config.h" 11#include "media/base/channel_layout.h" 12#include "media/base/decoder_buffer.h" 13#include "media/base/media_export.h" 14#include "media/base/pipeline_status.h" 15 16namespace media { 17 18class AudioBuffer; 19class DemuxerStream; 20 21class MEDIA_EXPORT AudioDecoder { 22 public: 23 // Status codes for decode operations. 24 // TODO(rileya): Now that both AudioDecoder and VideoDecoder Status enums 25 // match, break them into a decoder_status.h. 26 enum Status { 27 kOk, // We're all good. 28 kAborted, // We aborted as a result of Stop() or Reset(). 29 kNotEnoughData, // Not enough data to produce a video frame. 30 kDecodeError, // A decoding error occurred. 31 kDecryptError // Decrypting error happened. 32 }; 33 34 AudioDecoder(); 35 virtual ~AudioDecoder(); 36 37 // Initializes an AudioDecoder with the given DemuxerStream, executing the 38 // callback upon completion. 39 // statistics_cb is used to update global pipeline statistics. 40 virtual void Initialize(const AudioDecoderConfig& config, 41 const PipelineStatusCB& status_cb) = 0; 42 43 // Requests samples to be decoded and returned via the provided callback. 44 // Only one decode may be in flight at any given time. 45 // 46 // Implementations guarantee that the callback will not be called from within 47 // this method. 48 // 49 // Non-NULL sample buffer pointers will contain decoded audio data or may 50 // indicate the end of the stream. A NULL buffer pointer indicates an aborted 51 // Decode(). 52 typedef base::Callback<void(Status, const scoped_refptr<AudioBuffer>&)> 53 DecodeCB; 54 virtual void Decode(const scoped_refptr<DecoderBuffer>& buffer, 55 const DecodeCB& decode_cb) = 0; 56 57 // Some AudioDecoders will queue up multiple AudioBuffers from a single 58 // DecoderBuffer, if we have any such queued buffers this will return the next 59 // one. Otherwise we return a NULL AudioBuffer. 60 virtual scoped_refptr<AudioBuffer> GetDecodeOutput(); 61 62 // Resets decoder state, dropping any queued encoded data. 63 virtual void Reset(const base::Closure& closure) = 0; 64 65 // Stops decoder, fires any pending callbacks and sets the decoder to an 66 // uninitialized state. An AudioDecoder cannot be re-initialized after it has 67 // been stopped. 68 // Note that if Initialize() has been called, Stop() must be called and 69 // complete before deleting the decoder. 70 virtual void Stop(const base::Closure& closure) = 0; 71 72 // Returns various information about the decoded audio format. 73 virtual int bits_per_channel() = 0; 74 virtual ChannelLayout channel_layout() = 0; 75 virtual int samples_per_second() = 0; 76 77 private: 78 DISALLOW_COPY_AND_ASSIGN(AudioDecoder); 79}; 80 81} // namespace media 82 83#endif // MEDIA_BASE_AUDIO_DECODER_H_ 84