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 #include "base/bind.h" |
| 6 #include "base/callback.h" |
| 7 #include "base/location.h" |
| 8 #include "base/logging.h" |
| 9 #include "base/time/time.h" |
| 10 #include "mojo/services/media/common/cpp/local_time.h" |
| 11 #include "services/media/audio/audio_output_manager.h" |
| 12 #include "services/media/audio/platform/generic/throttle_output.h" |
| 13 |
| 14 namespace mojo { |
| 15 namespace media { |
| 16 namespace audio { |
| 17 |
| 18 static constexpr LocalDuration TRIM_PERIOD = local_time::from_msec(10); |
| 19 |
| 20 ThrottleOutput::ThrottleOutput(AudioOutputManager* manager) |
| 21 : StandardOutputBase(manager) {} |
| 22 |
| 23 ThrottleOutput::~ThrottleOutput() {} |
| 24 |
| 25 AudioOutputPtr ThrottleOutput::New(AudioOutputManager* manager) { |
| 26 return AudioOutputPtr(new ThrottleOutput(manager)); |
| 27 } |
| 28 |
| 29 MediaResult ThrottleOutput::Init() { |
| 30 last_sched_time_ = LocalClock::now(); |
| 31 return MediaResult::OK; |
| 32 } |
| 33 |
| 34 bool ThrottleOutput::StartMixJob(MixJob* job, |
| 35 const LocalTime& process_start) { |
| 36 // Compute our next callback time, and check to see if we are falling behind |
| 37 // in the process. |
| 38 last_sched_time_ += TRIM_PERIOD; |
| 39 if (process_start > last_sched_time_) { |
| 40 // TODO(johngro): We are falling behind on our trimming. We should |
| 41 // probably tell someone. |
| 42 last_sched_time_ = process_start + TRIM_PERIOD;; |
| 43 } |
| 44 |
| 45 // TODO(johngro): We could optimize this trim operation by scheduling our |
| 46 // callback to the time at which the first pending packet in our queue will |
| 47 // end, instead of using this polling style. This would have the addition |
| 48 // benefit of tighten the timing on returning packets (currently, we could |
| 49 // hold a packet for up to TRIM_PERIOD - episilon past its end pts before |
| 50 // releasing it) |
| 51 // |
| 52 // In order to do this, however, we would to wake up and recompute whenever |
| 53 // the rate transformations for one of our client tracks changes. For now, we |
| 54 // just poll because its simpler. |
| 55 SetNextSchedTime(last_sched_time_); |
| 56 |
| 57 // The throttle output never actually mixes anything, it just provides |
| 58 // backpressure to the pipeline by holding references to AudioPackets until |
| 59 // after their presentation should be finished. All we need to do here is |
| 60 // schedule our next callback to keep things running, and let the base class |
| 61 // implementation handle trimming the output. |
| 62 return false; |
| 63 } |
| 64 |
| 65 bool ThrottleOutput::FinishMixJob(const MixJob& job) { |
| 66 // Since we never start any jobs, this should never be called. |
| 67 DCHECK(false); |
| 68 return false; |
| 69 } |
| 70 |
| 71 } // namespace audio |
| 72 } // namespace media |
| 73 } // namespace mojo |
| 74 |
OLD | NEW |