Disable view source for Developer Tools.
[chromium-blink-merge.git] / media / filters / opus_audio_decoder.h
blobd5eb595cd1045c6558831ebc84674ca147f1a2f1
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.
5 #ifndef MEDIA_FILTERS_OPUS_AUDIO_DECODER_H_
6 #define MEDIA_FILTERS_OPUS_AUDIO_DECODER_H_
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 #include "media/base/sample_format.h"
15 struct OpusMSDecoder;
17 namespace base {
18 class SingleThreadTaskRunner;
21 namespace media {
23 class AudioBuffer;
24 class AudioTimestampHelper;
25 class DecoderBuffer;
26 struct QueuedAudioBuffer;
28 class MEDIA_EXPORT OpusAudioDecoder : public AudioDecoder {
29 public:
30 explicit OpusAudioDecoder(
31 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner);
32 virtual ~OpusAudioDecoder();
34 // AudioDecoder implementation.
35 virtual void Initialize(DemuxerStream* stream,
36 const PipelineStatusCB& status_cb,
37 const StatisticsCB& statistics_cb) OVERRIDE;
38 virtual void Read(const ReadCB& read_cb) OVERRIDE;
39 virtual int bits_per_channel() OVERRIDE;
40 virtual ChannelLayout channel_layout() OVERRIDE;
41 virtual int samples_per_second() OVERRIDE;
42 virtual void Reset(const base::Closure& closure) OVERRIDE;
44 private:
45 // Reads from the demuxer stream with corresponding callback method.
46 void ReadFromDemuxerStream();
47 void BufferReady(DemuxerStream::Status status,
48 const scoped_refptr<DecoderBuffer>& input);
51 bool ConfigureDecoder();
52 void CloseDecoder();
53 void ResetTimestampState();
54 bool Decode(const scoped_refptr<DecoderBuffer>& input,
55 scoped_refptr<AudioBuffer>* output_buffer);
57 scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
58 base::WeakPtrFactory<OpusAudioDecoder> weak_factory_;
59 base::WeakPtr<OpusAudioDecoder> weak_this_;
61 DemuxerStream* demuxer_stream_;
62 StatisticsCB statistics_cb_;
63 OpusMSDecoder* opus_decoder_;
65 // Decoded audio format.
66 ChannelLayout channel_layout_;
67 int samples_per_second_;
68 const SampleFormat sample_format_;
69 const int bits_per_channel_;
71 // Used for computing output timestamps.
72 scoped_ptr<AudioTimestampHelper> output_timestamp_helper_;
73 base::TimeDelta last_input_timestamp_;
75 ReadCB read_cb_;
77 // Number of frames to be discarded from the start of the packet. This value
78 // is respected for all packets except for the first one in the stream. For
79 // the first packet in the stream, |frame_delay_at_start_| is used. This is
80 // usually set to the SeekPreRoll value from the container whenever a seek
81 // happens.
82 int frames_to_discard_;
84 // Number of frames to be discarded at the start of the stream. This value
85 // is typically the CodecDelay value from the container. This value should
86 // only be applied when input timestamp is |start_input_timestamp_|.
87 int frame_delay_at_start_;
88 base::TimeDelta start_input_timestamp_;
90 // Timestamp to be subtracted from all the frames. This is typically computed
91 // from the CodecDelay value in the container.
92 base::TimeDelta timestamp_offset_;
94 DISALLOW_IMPLICIT_CONSTRUCTORS(OpusAudioDecoder);
97 } // namespace media
99 #endif // MEDIA_FILTERS_OPUS_AUDIO_DECODER_H_