Re-subimission of https://codereview.chromium.org/1041213003/
[chromium-blink-merge.git] / media / base / android / audio_decoder_job.h
blob0a7523fa7786f5715225cb43db98538ccc194436
1 // Copyright 2013 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_AUDIO_DECODER_JOB_H_
6 #define MEDIA_BASE_ANDROID_AUDIO_DECODER_JOB_H_
8 #include <jni.h>
9 #include <vector>
11 #include "base/callback.h"
12 #include "media/base/android/media_decoder_job.h"
14 namespace media {
16 class AudioCodecBridge;
17 class AudioTimestampHelper;
19 // Class for managing audio decoding jobs.
20 class AudioDecoderJob : public MediaDecoderJob {
21 public:
22 // Creates a new AudioDecoderJob instance for decoding audio.
23 // |request_data_cb| - Callback used to request more data for the decoder.
24 // |on_demuxer_config_changed_cb| - Callback used to inform the caller that
25 // demuxer config has changed.
26 AudioDecoderJob(const base::Closure& request_data_cb,
27 const base::Closure& on_demuxer_config_changed_cb);
28 ~AudioDecoderJob() override;
30 // MediaDecoderJob implementation.
31 bool HasStream() const override;
32 void Flush() override;
33 void SetDemuxerConfigs(const DemuxerConfigs& configs) override;
35 // Sets the volume of the audio output.
36 void SetVolume(double volume);
37 double volume() const { return volume_; }
39 // Sets the base timestamp for |audio_timestamp_helper_|.
40 void SetBaseTimestamp(base::TimeDelta base_timestamp);
42 private:
43 // MediaDecoderJob implementation.
44 void ReleaseOutputBuffer(
45 int output_buffer_index,
46 size_t size,
47 bool render_output,
48 base::TimeDelta current_presentation_timestamp,
49 const ReleaseOutputCompletionCallback& callback) override;
50 bool ComputeTimeToRender() const override;
51 bool AreDemuxerConfigsChanged(const DemuxerConfigs& configs) const override;
52 MediaDecoderJobStatus CreateMediaCodecBridgeInternal() override;
53 void OnOutputFormatChanged() override;
55 // Helper method to set the audio output volume.
56 void SetVolumeInternal();
58 void ResetTimestampHelper();
60 // Audio configs from the demuxer.
61 AudioCodec audio_codec_;
62 int num_channels_;
63 int config_sampling_rate_;
64 std::vector<uint8> audio_extra_data_;
65 int64 audio_codec_delay_ns_;
66 int64 audio_seek_preroll_ns_;
67 double volume_;
68 int bytes_per_frame_;
70 // Audio output sample rate
71 int output_sampling_rate_;
73 // Frame count to sync with audio codec output
74 int64 frame_count_;
76 // Base timestamp for the |audio_timestamp_helper_|.
77 base::TimeDelta base_timestamp_;
79 // Object to calculate the current audio timestamp for A/V sync.
80 scoped_ptr<AudioTimestampHelper> audio_timestamp_helper_;
82 DISALLOW_COPY_AND_ASSIGN(AudioDecoderJob);
85 } // namespace media
87 #endif // MEDIA_BASE_ANDROID_AUDIO_DECODER_JOB_H_