Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(212)

Side by Side Diff: services/media/audio/platform/generic/standard_output_base.h

Issue 1471813002: Mix to an intermediate buffer. (Closed) Base URL: https://github.com/domokit/mojo.git@change7
Patch Set: Final rebase before landing Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef SERVICES_MEDIA_AUDIO_PLATFORM_GENERIC_STANDARD_OUTPUT_BASE_H_ 5 #ifndef SERVICES_MEDIA_AUDIO_PLATFORM_GENERIC_STANDARD_OUTPUT_BASE_H_
6 #define SERVICES_MEDIA_AUDIO_PLATFORM_GENERIC_STANDARD_OUTPUT_BASE_H_ 6 #define SERVICES_MEDIA_AUDIO_PLATFORM_GENERIC_STANDARD_OUTPUT_BASE_H_
7 7
8 #include "base/callback.h" 8 #include "base/callback.h"
9 #include "mojo/services/media/common/cpp/linear_transform.h" 9 #include "mojo/services/media/common/cpp/linear_transform.h"
10 #include "mojo/services/media/common/cpp/local_time.h" 10 #include "mojo/services/media/common/cpp/local_time.h"
11 #include "mojo/services/media/common/interfaces/media_common.mojom.h" 11 #include "mojo/services/media/common/interfaces/media_common.mojom.h"
12 #include "mojo/services/media/common/interfaces/media_types.mojom.h" 12 #include "mojo/services/media/common/interfaces/media_types.mojom.h"
13 #include "services/media/audio/audio_output.h" 13 #include "services/media/audio/audio_output.h"
14 #include "services/media/audio/audio_track_to_output_link.h" 14 #include "services/media/audio/audio_track_to_output_link.h"
15 #include "services/media/audio/platform/generic/mixer.h" 15 #include "services/media/audio/platform/generic/mixer.h"
16 #include "services/media/audio/platform/generic/output_formatter.h"
16 17
17 namespace mojo { 18 namespace mojo {
18 namespace media { 19 namespace media {
19 namespace audio { 20 namespace audio {
20 21
21 class StandardOutputBase : public AudioOutput { 22 class StandardOutputBase : public AudioOutput {
22 public: 23 public:
23 ~StandardOutputBase() override; 24 ~StandardOutputBase() override;
24 25
25 protected: 26 protected:
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 next_sched_time_known_ = true; 65 next_sched_time_known_ = true;
65 } 66 }
66 67
67 void SetNextSchedDelay(const LocalDuration& next_sched_delay) { 68 void SetNextSchedDelay(const LocalDuration& next_sched_delay) {
68 SetNextSchedTime(LocalClock::now() + next_sched_delay); 69 SetNextSchedTime(LocalClock::now() + next_sched_delay);
69 } 70 }
70 71
71 virtual bool StartMixJob(MixJob* job, const LocalTime& process_start) = 0; 72 virtual bool StartMixJob(MixJob* job, const LocalTime& process_start) = 0;
72 virtual bool FinishMixJob(const MixJob& job) = 0; 73 virtual bool FinishMixJob(const MixJob& job) = 0;
73 virtual TrackBookkeeping* AllocBookkeeping(); 74 virtual TrackBookkeeping* AllocBookkeeping();
75 void SetupMixBuffer(uint32_t max_mix_frames);
74 76
75 LpcmMediaTypeDetailsPtr output_format_; 77 // Details about the final output format
76 uint32_t output_bytes_per_frame_; 78 OutputFormatterPtr output_formatter_;
77 79
78 private: 80 private:
79 using TrackSetupTask = std::function<bool(const AudioTrackImplPtr& track, 81 using TrackSetupTask = std::function<bool(const AudioTrackImplPtr& track,
80 TrackBookkeeping* info)>; 82 TrackBookkeeping* info)>;
81 using TrackProcessTask = 83 using TrackProcessTask =
82 std::function<bool(const AudioTrackImplPtr& track, 84 std::function<bool(const AudioTrackImplPtr& track,
83 TrackBookkeeping* info, 85 TrackBookkeeping* info,
84 const AudioPipe::AudioPacketRefPtr& pkt_ref)>; 86 const AudioPipe::AudioPacketRefPtr& pkt_ref)>;
85 87
86 void ForeachTrack(const TrackSetupTask& setup, 88 void ForeachTrack(const TrackSetupTask& setup,
87 const TrackProcessTask& process); 89 const TrackProcessTask& process);
88 90
89 bool SetupMix(const AudioTrackImplPtr& track, TrackBookkeeping* info); 91 bool SetupMix(const AudioTrackImplPtr& track, TrackBookkeeping* info);
90 bool ProcessMix(const AudioTrackImplPtr& track, 92 bool ProcessMix(const AudioTrackImplPtr& track,
91 TrackBookkeeping* info, 93 TrackBookkeeping* info,
92 const AudioPipe::AudioPacketRefPtr& pkt_ref); 94 const AudioPipe::AudioPacketRefPtr& pkt_ref);
93 95
94 bool SetupTrim(const AudioTrackImplPtr& track, TrackBookkeeping* info); 96 bool SetupTrim(const AudioTrackImplPtr& track, TrackBookkeeping* info);
95 bool ProcessTrim(const AudioTrackImplPtr& track, 97 bool ProcessTrim(const AudioTrackImplPtr& track,
96 TrackBookkeeping* info, 98 TrackBookkeeping* info,
97 const AudioPipe::AudioPacketRefPtr& pkt_ref); 99 const AudioPipe::AudioPacketRefPtr& pkt_ref);
98 100
99 LocalTime next_sched_time_; 101 LocalTime next_sched_time_;
100 bool next_sched_time_known_; 102 bool next_sched_time_known_;
101 103
104 // State for the internal buffer which holds intermediate mix results.
105 //
106 // TODO(johngro): Right now, the cannonical intermediate format is signed 32
107 // bit ints. As time goes on, we may need to reconsider this. This will
108 // become more important when...
109 //
110 // 1) We support 24 bit audio. Right now, with a 16 bit max, we can
111 // accumulate for up to a maximum of 2^16-1 tracks without needing to do
112 // anything special about about clipping. With 24 bit audio, this number
113 // will drop to only 255 simultanious tracks. It is unclear if this is a
114 // reasonable system-wide limitation or not.
115 // 2) We support floating point audio.
116 std::unique_ptr<int32_t> mix_buf_;
117 uint32_t mix_buf_frames_ = 0;
118
102 // State used by the mix task. 119 // State used by the mix task.
103 TrackSetupTask setup_mix_; 120 TrackSetupTask setup_mix_;
104 TrackProcessTask process_mix_; 121 TrackProcessTask process_mix_;
105 MixJob cur_mix_job_; 122 MixJob cur_mix_job_;
106 123
107 // State used by the trim task. 124 // State used by the trim task.
108 TrackSetupTask setup_trim_; 125 TrackSetupTask setup_trim_;
109 TrackProcessTask process_trim_; 126 TrackProcessTask process_trim_;
110 int64_t trim_threshold_; 127 int64_t trim_threshold_;
111 }; 128 };
112 129
113 } // namespace audio 130 } // namespace audio
114 } // namespace media 131 } // namespace media
115 } // namespace mojo 132 } // namespace mojo
116 133
117 #endif // SERVICES_MEDIA_AUDIO_PLATFORM_GENERIC_STANDARD_OUTPUT_BASE_H_ 134 #endif // SERVICES_MEDIA_AUDIO_PLATFORM_GENERIC_STANDARD_OUTPUT_BASE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698