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

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

Issue 1424933002: Add an initial revision of an audio server. (Closed) Base URL: https://github.com/domokit/mojo.git@change4
Patch Set: fix issues discovered with initial preflight Created 5 years, 1 month 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
(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 SERVICES_MEDIA_AUDIO_PLATFORM_GENERIC_STANDARD_OUTPUT_BASE_H_
6 #define SERVICES_MEDIA_AUDIO_PLATFORM_GENERIC_STANDARD_OUTPUT_BASE_H_
7
8 #include "base/callback.h"
9 #include "mojo/services/media/common/cpp/linear_transform.h"
10 #include "mojo/services/media/common/cpp/local_time.h"
11 #include "mojo/services/media/common/interfaces/media_common.mojom.h"
12 #include "mojo/services/media/common/interfaces/media_types.mojom.h"
13 #include "services/media/audio/audio_output.h"
14 #include "services/media/audio/audio_track_to_output_link.h"
15 #include "services/media/audio/platform/generic/mixer.h"
16
17 namespace mojo {
18 namespace media {
19 namespace audio {
20
21 class StandardOutputBase : public AudioOutput {
22 public:
23 ~StandardOutputBase() override;
24
25 protected:
26 struct MixJob {
27 static constexpr uint32_t INVALID_GENERATION = 0;
28
29 // State for the job set up once by the output implementation and then used
30 // by all tracks.
31 void* buf;
32 uint32_t buf_frames;
33 int64_t start_pts_of; // start PTS, expressed in output frames.
34 uint32_t local_to_output_gen;
35 bool accumulate;
36 const LinearTransform* local_to_output;
37
38 // State for the job which is set up for each track during SetupMix
39 uint32_t frames_produced;
40 };
41
42 struct TrackBookkeeping : public AudioTrackToOutputLink::Bookkeeping {
43 TrackBookkeeping();
44 ~TrackBookkeeping() override;
45
46 LinearTransform lt_to_track_frames;
47 LinearTransform out_frames_to_track_frames;
48 uint32_t lt_to_track_frames_gen = 0;
49 uint32_t out_frames_to_track_frames_gen = MixJob::INVALID_GENERATION;
50 uint32_t step_size;
51 MixerPtr mixer;
52
53 void UpdateTrackTrans(const AudioTrackImplPtr& track);
54 void UpdateOutputTrans(const MixJob& job);
55 };
56
57 explicit StandardOutputBase(AudioOutputManager* manager);
58
59 void Process() final;
60 MediaResult InitializeLink(const AudioTrackToOutputLinkPtr& link) final;
61
62 void SetNextSchedTime(const LocalTime& next_sched_time) {
63 next_sched_time_ = next_sched_time;
64 next_sched_time_known_ = true;
65 }
66
67 void SetNextSchedDelay(const LocalDuration& next_sched_delay) {
68 SetNextSchedTime(LocalClock::now() + next_sched_delay);
69 }
70
71 virtual bool StartMixJob(MixJob* job, const LocalTime& process_start) = 0;
72 virtual bool FinishMixJob(const MixJob& job) = 0;
73 virtual TrackBookkeeping* AllocBookkeeping();
74
75 LpcmMediaTypeDetailsPtr output_format_;
76 uint32_t output_bytes_per_frame_;
77
78 private:
79 using TrackSetupTask = std::function<bool(const AudioTrackImplPtr& track,
80 TrackBookkeeping* info)>;
81 using TrackProcessTask =
82 std::function<bool(const AudioTrackImplPtr& track,
83 TrackBookkeeping* info,
84 const AudioPipe::AudioPacketRefPtr& pkt_ref)>;
85
86 void ForeachTrack(const TrackSetupTask& setup,
87 const TrackProcessTask& process);
88
89 bool SetupMix(const AudioTrackImplPtr& track, TrackBookkeeping* info);
90 bool ProcessMix(const AudioTrackImplPtr& track,
91 TrackBookkeeping* info,
92 const AudioPipe::AudioPacketRefPtr& pkt_ref);
93
94 bool SetupTrim(const AudioTrackImplPtr& track, TrackBookkeeping* info);
95 bool ProcessTrim(const AudioTrackImplPtr& track,
96 TrackBookkeeping* info,
97 const AudioPipe::AudioPacketRefPtr& pkt_ref);
98
99 LocalTime next_sched_time_;
100 bool next_sched_time_known_;
101
102 // State used by the mix task.
103 TrackSetupTask setup_mix_;
104 TrackProcessTask process_mix_;
105 MixJob cur_mix_job_;
106
107 // State used by the trim task.
108 TrackSetupTask setup_trim_;
109 TrackProcessTask process_trim_;
110 int64_t trim_threshold_;
111 };
112
113 } // namespace audio
114 } // namespace media
115 } // namespace mojo
116
117 #endif // SERVICES_MEDIA_AUDIO_PLATFORM_GENERIC_STANDARD_OUTPUT_BASE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698