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 SERVICES_MEDIA_AUDIO_AUDIO_SERVER_IMPL_H_ |
| 6 #define SERVICES_MEDIA_AUDIO_AUDIO_SERVER_IMPL_H_ |
| 7 |
| 8 #include <list> |
| 9 #include <set> |
| 10 |
| 11 #include "base/callback.h" |
| 12 #include "base/synchronization/lock.h" |
| 13 #include "base/task_runner.h" |
| 14 #include "mojo/services/media/audio/interfaces/audio_server.mojom.h" |
| 15 #include "mojo/services/media/audio/interfaces/audio_track.mojom.h" |
| 16 #include "services/media/audio/audio_output_manager.h" |
| 17 #include "services/media/audio/fwd_decls.h" |
| 18 #include "services/media/common/media_pipe_base.h" |
| 19 |
| 20 namespace mojo { |
| 21 namespace media { |
| 22 namespace audio { |
| 23 |
| 24 class AudioServerImpl : public AudioServer { |
| 25 public: |
| 26 AudioServerImpl(); |
| 27 ~AudioServerImpl() override; |
| 28 |
| 29 void Initialize(); |
| 30 |
| 31 // AudioServer |
| 32 void CreateTrack(mojo::InterfaceRequest<AudioTrack> track) override; |
| 33 |
| 34 // Called (indirectly) by AudioOutputs to schedule the callback for a |
| 35 // MediaPacked which was queued to an AudioTrack via. a media pipe. |
| 36 // |
| 37 // TODO(johngro): This bouncing through thread contexts is inefficient and |
| 38 // will increase the latency requirements for clients (its going to take them |
| 39 // some extra time to discover that their media has been completely consumed). |
| 40 // When mojo exposes a way to safely invoke interface method callbacks from |
| 41 // threads other than the thread which executed the method itself, we will |
| 42 // want to switch to creating the callback message directly, instead of |
| 43 // indirecting through the server. |
| 44 void SchedulePacketCleanup(MediaPipeBase::MediaPacketStatePtr state); |
| 45 |
| 46 // Schedule a closure to run on the server's main message loop. |
| 47 void ScheduleMessageLoopTask(const tracked_objects::Location& from_here, |
| 48 const base::Closure& task) { |
| 49 DCHECK(task_runner_); |
| 50 bool success = task_runner_->PostTask(from_here, task); |
| 51 DCHECK(success); |
| 52 } |
| 53 |
| 54 |
| 55 // Accessor for our encapsulated output manager. |
| 56 AudioOutputManager& GetOutputManager() { return output_manager_; } |
| 57 |
| 58 private: |
| 59 using CleanupQueue = std::list<MediaPipeBase::MediaPacketStatePtr>; |
| 60 |
| 61 void Shutdown(); |
| 62 void DoPacketCleanup(); |
| 63 |
| 64 // A reference to our message loop's task runner. Allows us to post events to |
| 65 // be handled by our main application thread from things like the output |
| 66 // manager's thread pool. |
| 67 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; |
| 68 |
| 69 // State for dealing with outputs. |
| 70 AudioOutputManager output_manager_; |
| 71 |
| 72 // State for dealing with tracks. |
| 73 base::Lock track_lock_; |
| 74 std::set<AudioTrackImplPtr> tracks_; |
| 75 |
| 76 // State for dealing with cleanup tasks. |
| 77 base::Lock cleanup_queue_lock_; |
| 78 std::unique_ptr<CleanupQueue> cleanup_queue_; |
| 79 bool cleanup_scheduled_ = false; |
| 80 bool shutting_down_ = false; |
| 81 base::Closure cleanup_closure_; |
| 82 }; |
| 83 |
| 84 } // namespace audio |
| 85 } // namespace media |
| 86 } // namespace mojo |
| 87 |
| 88 #endif // SERVICES_MEDIA_AUDIO_AUDIO_SERVER_IMPL_H_ |
OLD | NEW |