Roll src/third_party/WebKit d10c917:a1123a1 (svn 198729:198730)
[chromium-blink-merge.git] / media / base / android / media_codec_audio_decoder.h
blob53bb664f6018b833e4fa5f571c12051c8ad727c9
1 // Copyright 2015 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_BASE_ANDROID_MEDIA_CODEC_AUDIO_DECODER_H_
6 #define MEDIA_BASE_ANDROID_MEDIA_CODEC_AUDIO_DECODER_H_
8 #include "media/base/android/media_codec_decoder.h"
10 namespace media {
12 class AudioTimestampHelper;
14 // Audio decoder for MediaCodecPlayer
15 class MediaCodecAudioDecoder : public MediaCodecDecoder {
16 public:
17 // For parameters see media_codec_decoder.h
18 // update_current_time_cb: callback that reports current playback time.
19 // Called for each rendered frame.
20 MediaCodecAudioDecoder(
21 const scoped_refptr<base::SingleThreadTaskRunner>& media_runner,
22 const base::Closure& request_data_cb,
23 const base::Closure& starvation_cb,
24 const base::Closure& stop_done_cb,
25 const base::Closure& error_cb,
26 const SetTimeCallback& update_current_time_cb);
27 ~MediaCodecAudioDecoder() override;
29 const char* class_name() const override;
31 bool HasStream() const override;
32 void SetDemuxerConfigs(const DemuxerConfigs& configs) override;
33 void Flush() override;
35 // Sets the volume of the audio output.
36 void SetVolume(double volume);
38 // Sets the base timestamp for |audio_timestamp_helper_|.
39 void SetBaseTimestamp(base::TimeDelta base_timestamp);
41 protected:
42 bool IsCodecReconfigureNeeded(const DemuxerConfigs& curr,
43 const DemuxerConfigs& next) const override;
44 ConfigStatus ConfigureInternal() override;
45 void OnOutputFormatChanged() override;
46 void Render(int buffer_index,
47 size_t size,
48 bool render_output,
49 base::TimeDelta pts,
50 bool eos_encountered) override;
52 private:
53 // A helper method to set the volume.
54 void SetVolumeInternal();
56 // Recreates |audio_timestamp_helper_|, called when sampling rate is changed.
57 void ResetTimestampHelper();
59 // Data.
61 // Configuration received from demuxer
62 DemuxerConfigs configs_;
64 // Requested volume
65 double volume_;
67 // Number of bytes per audio frame. Depends on the output format and the
68 // number of channels.
69 int bytes_per_frame_;
71 // The sampling rate received from decoder.
72 int output_sampling_rate_;
74 // Frame count to sync with audio codec output.
75 int64 frame_count_;
77 // Base timestamp for the |audio_timestamp_helper_|.
78 base::TimeDelta base_timestamp_;
80 // Object to calculate the current audio timestamp for A/V sync.
81 scoped_ptr<AudioTimestampHelper> audio_timestamp_helper_;
83 // Reports current playback time to the callee.
84 SetTimeCallback update_current_time_cb_;
86 DISALLOW_COPY_AND_ASSIGN(MediaCodecAudioDecoder);
89 } // namespace media
91 #endif // MEDIA_BASE_ANDROID_MEDIA_CODEC_DECODER_H_