OLD | NEW |
| (Empty) |
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. | |
4 | |
5 #ifndef MEDIA_BASE_ANDROID_MEDIA_CODEC_AUDIO_DECODER_H_ | |
6 #define MEDIA_BASE_ANDROID_MEDIA_CODEC_AUDIO_DECODER_H_ | |
7 | |
8 #include <stddef.h> | |
9 #include <stdint.h> | |
10 | |
11 #include "base/macros.h" | |
12 #include "media/base/android/media_codec_decoder.h" | |
13 | |
14 namespace media { | |
15 | |
16 class AudioTimestampHelper; | |
17 | |
18 // Audio decoder for MediaCodecPlayer | |
19 class MediaCodecAudioDecoder : public MediaCodecDecoder { | |
20 public: | |
21 // For parameters see media_codec_decoder.h | |
22 // update_current_time_cb: callback that reports current playback time. | |
23 // Called for each rendered frame. | |
24 MediaCodecAudioDecoder( | |
25 const scoped_refptr<base::SingleThreadTaskRunner>& media_runner, | |
26 FrameStatistics* frame_statistics, | |
27 const base::Closure& request_data_cb, | |
28 const base::Closure& starvation_cb, | |
29 const base::Closure& decoder_drained_cb, | |
30 const base::Closure& stop_done_cb, | |
31 const base::Closure& waiting_for_decryption_key_cb, | |
32 const base::Closure& error_cb, | |
33 const SetTimeCallback& update_current_time_cb); | |
34 ~MediaCodecAudioDecoder() override; | |
35 | |
36 const char* class_name() const override; | |
37 | |
38 bool HasStream() const override; | |
39 void SetDemuxerConfigs(const DemuxerConfigs& configs) override; | |
40 bool IsContentEncrypted() const override; | |
41 void ReleaseDecoderResources() override; | |
42 void Flush() override; | |
43 | |
44 // Sets the volume of the audio output. | |
45 void SetVolume(double volume); | |
46 | |
47 // Sets the base timestamp for |audio_timestamp_helper_|. | |
48 void SetBaseTimestamp(base::TimeDelta base_timestamp); | |
49 | |
50 protected: | |
51 bool IsCodecReconfigureNeeded(const DemuxerConfigs& next) const override; | |
52 ConfigStatus ConfigureInternal(jobject media_crypto) override; | |
53 void OnOutputFormatChanged() override; | |
54 void Render(int buffer_index, | |
55 size_t offset, | |
56 size_t size, | |
57 RenderMode render_mode, | |
58 base::TimeDelta pts, | |
59 bool eos_encountered) override; | |
60 | |
61 private: | |
62 // A helper method to set the volume. | |
63 void SetVolumeInternal(); | |
64 | |
65 // Recreates |audio_timestamp_helper_|, called when sampling rate is changed. | |
66 void ResetTimestampHelper(); | |
67 | |
68 // Data. | |
69 | |
70 // Configuration received from demuxer | |
71 DemuxerConfigs configs_; | |
72 | |
73 // Requested volume | |
74 double volume_; | |
75 | |
76 // Number of bytes per audio frame. Depends on the output format and the | |
77 // number of channels. | |
78 int bytes_per_frame_; | |
79 | |
80 // The sampling rate received from decoder. | |
81 int output_sampling_rate_; | |
82 | |
83 // Frame count to sync with audio codec output. | |
84 int64_t frame_count_; | |
85 | |
86 // Base timestamp for the |audio_timestamp_helper_|. | |
87 base::TimeDelta base_timestamp_; | |
88 | |
89 // Object to calculate the current audio timestamp for A/V sync. | |
90 scoped_ptr<AudioTimestampHelper> audio_timestamp_helper_; | |
91 | |
92 // Reports current playback time to the callee. | |
93 SetTimeCallback update_current_time_cb_; | |
94 | |
95 // The time limit for the next frame to avoid underrun. | |
96 base::TimeTicks next_frame_time_limit_; | |
97 | |
98 DISALLOW_COPY_AND_ASSIGN(MediaCodecAudioDecoder); | |
99 }; | |
100 | |
101 } // namespace media | |
102 | |
103 #endif // MEDIA_BASE_ANDROID_MEDIA_CODEC_DECODER_H_ | |
OLD | NEW |