Home | History | Annotate | Download | only in filters
      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_FILTERS_OPUS_AUDIO_DECODER_H_
      6 #define MEDIA_FILTERS_OPUS_AUDIO_DECODER_H_
      7 
      8 #include "base/callback.h"
      9 #include "base/memory/weak_ptr.h"
     10 #include "base/time/time.h"
     11 #include "media/base/audio_decoder.h"
     12 #include "media/base/demuxer_stream.h"
     13 
     14 struct OpusMSDecoder;
     15 
     16 namespace base {
     17 class MessageLoopProxy;
     18 }
     19 
     20 namespace media {
     21 
     22 class AudioBuffer;
     23 class AudioTimestampHelper;
     24 class DecoderBuffer;
     25 struct QueuedAudioBuffer;
     26 
     27 class MEDIA_EXPORT OpusAudioDecoder : public AudioDecoder {
     28  public:
     29   explicit OpusAudioDecoder(
     30       const scoped_refptr<base::MessageLoopProxy>& message_loop);
     31   virtual ~OpusAudioDecoder();
     32 
     33   // AudioDecoder implementation.
     34   virtual void Initialize(DemuxerStream* stream,
     35                           const PipelineStatusCB& status_cb,
     36                           const StatisticsCB& statistics_cb) OVERRIDE;
     37   virtual void Read(const ReadCB& read_cb) OVERRIDE;
     38   virtual int bits_per_channel() OVERRIDE;
     39   virtual ChannelLayout channel_layout() OVERRIDE;
     40   virtual int samples_per_second() OVERRIDE;
     41   virtual void Reset(const base::Closure& closure) OVERRIDE;
     42 
     43  private:
     44   // Reads from the demuxer stream with corresponding callback method.
     45   void ReadFromDemuxerStream();
     46   void BufferReady(DemuxerStream::Status status,
     47                    const scoped_refptr<DecoderBuffer>& input);
     48 
     49 
     50   bool ConfigureDecoder();
     51   void CloseDecoder();
     52   void ResetTimestampState();
     53   bool Decode(const scoped_refptr<DecoderBuffer>& input,
     54               scoped_refptr<AudioBuffer>* output_buffer);
     55 
     56   scoped_refptr<base::MessageLoopProxy> message_loop_;
     57   base::WeakPtrFactory<OpusAudioDecoder> weak_factory_;
     58   base::WeakPtr<OpusAudioDecoder> weak_this_;
     59 
     60   DemuxerStream* demuxer_stream_;
     61   StatisticsCB statistics_cb_;
     62   OpusMSDecoder* opus_decoder_;
     63 
     64   // Decoded audio format.
     65   int bits_per_channel_;
     66   ChannelLayout channel_layout_;
     67   int samples_per_second_;
     68 
     69   // Used for computing output timestamps.
     70   scoped_ptr<AudioTimestampHelper> output_timestamp_helper_;
     71   base::TimeDelta last_input_timestamp_;
     72 
     73   // Number of output sample bytes to drop before generating
     74   // output buffers.
     75   int output_bytes_to_drop_;
     76 
     77   ReadCB read_cb_;
     78 
     79   int skip_samples_;
     80 
     81   // Buffer for output from libopus.
     82   scoped_ptr<int16[]> output_buffer_;
     83 
     84   DISALLOW_IMPLICIT_CONSTRUCTORS(OpusAudioDecoder);
     85 };
     86 
     87 }  // namespace media
     88 
     89 #endif  // MEDIA_FILTERS_OPUS_AUDIO_DECODER_H_
     90