audio_decoder.h revision 5d1f7b1de12d16ceb2c938c56701a3e8bfa558f7
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/channel_layout.h" 11#include "media/base/pipeline_status.h" 12#include "media/base/media_export.h" 13 14namespace media { 15 16class AudioBuffer; 17class DemuxerStream; 18 19class MEDIA_EXPORT AudioDecoder { 20 public: 21 // Status codes for read operations. 22 enum Status { 23 kOk, 24 kAborted, 25 kDecodeError, 26 }; 27 28 AudioDecoder(); 29 virtual ~AudioDecoder(); 30 31 // Initializes an AudioDecoder with the given DemuxerStream, executing the 32 // callback upon completion. 33 // statistics_cb is used to update global pipeline statistics. 34 virtual void Initialize(DemuxerStream* stream, 35 const PipelineStatusCB& status_cb, 36 const StatisticsCB& statistics_cb) = 0; 37 38 // Requests samples to be decoded and returned via the provided callback. 39 // Only one read may be in flight at any given time. 40 // 41 // Implementations guarantee that the callback will not be called from within 42 // this method. 43 // 44 // Non-NULL sample buffer pointers will contain decoded audio data or may 45 // indicate the end of the stream. A NULL buffer pointer indicates an aborted 46 // Read(). This can happen if the DemuxerStream gets flushed and doesn't have 47 // any more data to return. 48 typedef base::Callback<void(Status, const scoped_refptr<AudioBuffer>&)> 49 ReadCB; 50 virtual void Read(const ReadCB& read_cb) = 0; 51 52 // Resets decoder state, dropping any queued encoded data. 53 virtual void Reset(const base::Closure& closure) = 0; 54 55 // Stops decoder, fires any pending callbacks and sets the decoder to an 56 // uninitialized state. An AudioDecoder cannot be re-initialized after it has 57 // been stopped. 58 // Note that if Initialize() has been called, Stop() must be called and 59 // complete before deleting the decoder. 60 virtual void Stop(const base::Closure& closure) = 0; 61 62 // Returns various information about the decoded audio format. 63 virtual int bits_per_channel() = 0; 64 virtual ChannelLayout channel_layout() = 0; 65 virtual int samples_per_second() = 0; 66 67 private: 68 DISALLOW_COPY_AND_ASSIGN(AudioDecoder); 69}; 70 71} // namespace media 72 73#endif // MEDIA_BASE_AUDIO_DECODER_H_ 74