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_AUDIO_MEDIA_CODEC_DECODER_H_ | |
6 #define MEDIA_BASE_ANDROID_AUDIO_MEDIA_CODEC_DECODER_H_ | |
7 | |
8 #include <stddef.h> | |
9 #include <stdint.h> | |
10 #include <memory> | |
11 | |
12 #include "base/macros.h" | |
13 #include "media/base/android/media_codec_decoder.h" | |
14 | |
15 namespace media { | |
16 | |
17 class AudioTimestampHelper; | |
18 | |
19 // Audio decoder for MediaCodecPlayer | |
20 class AudioMediaCodecDecoder : public MediaCodecDecoder { | |
21 public: | |
22 // For parameters see media_codec_decoder.h | |
23 // update_current_time_cb: callback that reports current playback time. | |
24 // Called for each rendered frame. | |
25 AudioMediaCodecDecoder( | |
26 const scoped_refptr<base::SingleThreadTaskRunner>& media_runner, | |
27 FrameStatistics* frame_statistics, | |
28 const base::Closure& request_data_cb, | |
29 const base::Closure& starvation_cb, | |
30 const base::Closure& decoder_drained_cb, | |
31 const base::Closure& stop_done_cb, | |
32 const base::Closure& waiting_for_decryption_key_cb, | |
33 const base::Closure& error_cb, | |
34 const SetTimeCallback& update_current_time_cb); | |
35 ~AudioMediaCodecDecoder() override; | |
36 | |
37 const char* class_name() const override; | |
38 | |
39 bool HasStream() const override; | |
40 void SetDemuxerConfigs(const DemuxerConfigs& configs) override; | |
41 bool IsContentEncrypted() const override; | |
42 void ReleaseDecoderResources() override; | |
43 void Flush() override; | |
44 | |
45 // Sets the volume of the audio output. | |
46 void SetVolume(double volume); | |
47 | |
48 // Sets the base timestamp for |audio_timestamp_helper_|. | |
49 void SetBaseTimestamp(base::TimeDelta base_timestamp); | |
50 | |
51 protected: | |
52 bool IsCodecReconfigureNeeded(const DemuxerConfigs& next) const override; | |
53 ConfigStatus ConfigureInternal(jobject media_crypto) override; | |
54 bool OnOutputFormatChanged() override; | |
55 bool Render(int buffer_index, | |
56 size_t offset, | |
57 size_t size, | |
58 RenderMode render_mode, | |
59 base::TimeDelta pts, | |
60 bool eos_encountered) override; | |
61 | |
62 private: | |
63 // A helper method to set the volume. | |
64 void SetVolumeInternal(); | |
65 | |
66 // Recreates |audio_timestamp_helper_|, called when sampling rate is changed. | |
67 void ResetTimestampHelper(); | |
68 | |
69 // Data. | |
70 | |
71 // Configuration received from demuxer | |
72 DemuxerConfigs configs_; | |
73 | |
74 // Requested volume | |
75 double volume_; | |
76 | |
77 // The sampling rate received from decoder. | |
78 int output_sampling_rate_; | |
79 | |
80 // The number of audio channels received from decoder. | |
81 int output_num_channels_; | |
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 std::unique_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(AudioMediaCodecDecoder); | |
99 }; | |
100 | |
101 } // namespace media | |
102 | |
103 #endif // MEDIA_BASE_ANDROID_AUDIO_MEDIA_CODEC_DECODER_H_ | |
OLD | NEW |