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"
18 class SingleThreadTaskRunner
;
24 class AudioTimestampHelper
;
26 struct QueuedAudioBuffer
;
28 class MEDIA_EXPORT OpusAudioDecoder
: public AudioDecoder
{
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
;
43 virtual void Stop(const base::Closure
& closure
) OVERRIDE
;
49 // Reads from the demuxer stream with corresponding callback method.
50 void ReadFromDemuxerStream();
51 void BufferReady(DemuxerStream::Status status
,
52 const scoped_refptr
<DecoderBuffer
>& input
);
54 bool ConfigureDecoder();
56 void ResetTimestampState();
57 bool Decode(const scoped_refptr
<DecoderBuffer
>& input
,
58 scoped_refptr
<AudioBuffer
>* output_buffer
);
60 scoped_refptr
<base::SingleThreadTaskRunner
> task_runner_
;
61 base::WeakPtrFactory
<OpusAudioDecoder
> weak_factory_
;
62 base::WeakPtr
<OpusAudioDecoder
> weak_this_
;
64 DemuxerStream
* demuxer_stream_
;
65 StatisticsCB statistics_cb_
;
66 OpusMSDecoder
* opus_decoder_
;
68 // Decoded audio format.
69 ChannelLayout channel_layout_
;
70 int samples_per_second_
;
71 const SampleFormat sample_format_
;
72 const int bits_per_channel_
;
74 // Used for computing output timestamps.
75 scoped_ptr
<AudioTimestampHelper
> output_timestamp_helper_
;
76 base::TimeDelta last_input_timestamp_
;
79 base::Closure reset_cb_
;
80 base::Closure stop_cb_
;
82 // Number of frames to be discarded from the start of the packet. This value
83 // is respected for all packets except for the first one in the stream. For
84 // the first packet in the stream, |frame_delay_at_start_| is used. This is
85 // usually set to the SeekPreRoll value from the container whenever a seek
87 int frames_to_discard_
;
89 // Number of frames to be discarded at the start of the stream. This value
90 // is typically the CodecDelay value from the container. This value should
91 // only be applied when input timestamp is |start_input_timestamp_|.
92 int frame_delay_at_start_
;
93 base::TimeDelta start_input_timestamp_
;
95 // Timestamp to be subtracted from all the frames. This is typically computed
96 // from the CodecDelay value in the container.
97 base::TimeDelta timestamp_offset_
;
99 DISALLOW_IMPLICIT_CONSTRUCTORS(OpusAudioDecoder
);
104 #endif // MEDIA_FILTERS_OPUS_AUDIO_DECODER_H_