| OLD | NEW |
| 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_AUDIO_TRACK_IMPL_H_ | 5 #ifndef SERVICES_MEDIA_AUDIO_AUDIO_TRACK_IMPL_H_ |
| 6 #define SERVICES_MEDIA_AUDIO_AUDIO_TRACK_IMPL_H_ | 6 #define SERVICES_MEDIA_AUDIO_AUDIO_TRACK_IMPL_H_ |
| 7 | 7 |
| 8 #include <deque> | 8 #include <deque> |
| 9 #include <set> | 9 #include <set> |
| 10 | 10 |
| 11 #include "base/synchronization/lock.h" | 11 #include "base/synchronization/lock.h" |
| 12 #include "mojo/public/cpp/bindings/binding.h" | 12 #include "mojo/public/cpp/bindings/binding.h" |
| 13 #include "mojo/public/cpp/bindings/callback.h" | 13 #include "mojo/public/cpp/bindings/callback.h" |
| 14 #include "mojo/services/media/audio/interfaces/audio_track.mojom.h" | 14 #include "mojo/services/media/audio/interfaces/audio_track.mojom.h" |
| 15 #include "mojo/services/media/common/cpp/linear_transform.h" | 15 #include "mojo/services/media/common/cpp/linear_transform.h" |
| 16 #include "mojo/services/media/core/interfaces/media_renderer.mojom.h" |
| 16 #include "services/media/audio/audio_pipe.h" | 17 #include "services/media/audio/audio_pipe.h" |
| 17 #include "services/media/audio/fwd_decls.h" | 18 #include "services/media/audio/fwd_decls.h" |
| 18 #include "services/media/common/timeline_control_site.h" | 19 #include "services/media/common/timeline_control_site.h" |
| 19 | 20 |
| 20 namespace mojo { | 21 namespace mojo { |
| 21 namespace media { | 22 namespace media { |
| 22 namespace audio { | 23 namespace audio { |
| 23 | 24 |
| 24 class AudioTrackImpl : public AudioTrack { | 25 class AudioTrackImpl : public AudioTrack, public MediaRenderer { |
| 25 public: | 26 public: |
| 26 // TODO(johngro): Find a better place for this constant. It affects the | 27 // TODO(johngro): Find a better place for this constant. It affects the |
| 27 // behavior of more than just the Audio Track implementation. | 28 // behavior of more than just the Audio Track implementation. |
| 28 static constexpr size_t PTS_FRACTIONAL_BITS = 12; | 29 static constexpr size_t PTS_FRACTIONAL_BITS = 12; |
| 29 | 30 |
| 30 ~AudioTrackImpl() override; | 31 ~AudioTrackImpl() override; |
| 31 static AudioTrackImplPtr Create(InterfaceRequest<AudioTrack> iface, | 32 static AudioTrackImplPtr Create( |
| 32 AudioServerImpl* owner); | 33 InterfaceRequest<AudioTrack> track_request, |
| 34 InterfaceRequest<MediaRenderer> renderer_request, |
| 35 AudioServerImpl* owner); |
| 33 | 36 |
| 34 // Shutdown the audio track, unlinking it from all outputs, closing | 37 // Shutdown the audio track, unlinking it from all outputs, closing |
| 35 // connections to all clients and removing it from its owner server's list. | 38 // connections to all clients and removing it from its owner server's list. |
| 36 void Shutdown(); | 39 void Shutdown(); |
| 37 | 40 |
| 38 // Methods used by the output manager to link this track to different outputs. | 41 // Methods used by the output manager to link this track to different outputs. |
| 39 void AddOutput(AudioTrackToOutputLinkPtr link); | 42 void AddOutput(AudioTrackToOutputLinkPtr link); |
| 40 void RemoveOutput(AudioTrackToOutputLinkPtr link); | 43 void RemoveOutput(AudioTrackToOutputLinkPtr link); |
| 41 | 44 |
| 42 // Accessors used by AudioOutputs during mixing to access parameters which are | 45 // Accessors used by AudioOutputs during mixing to access parameters which are |
| 43 // important for the mixing process. | 46 // important for the mixing process. |
| 44 void SnapshotRateTrans(LinearTransform* out, uint32_t* generation = nullptr); | 47 void SnapshotRateTrans(LinearTransform* out, uint32_t* generation = nullptr); |
| 45 | 48 |
| 46 const LinearTransform::Ratio& FractionalFrameToMediaTimeRatio() const { | 49 const LinearTransform::Ratio& FractionalFrameToMediaTimeRatio() const { |
| 47 return frame_to_media_ratio_; | 50 return frame_to_media_ratio_; |
| 48 } | 51 } |
| 49 | 52 |
| 50 uint32_t BytesPerFrame() const { return bytes_per_frame_; } | 53 uint32_t BytesPerFrame() const { return bytes_per_frame_; } |
| 51 const AudioMediaTypeDetailsPtr& Format() const { return format_; } | 54 const AudioMediaTypeDetailsPtr& Format() const { return format_; } |
| 52 float DbGain() const { return db_gain_; } | 55 float DbGain() const { return db_gain_; } |
| 53 | 56 |
| 54 private: | 57 private: |
| 55 friend class AudioPipe; | 58 friend class AudioPipe; |
| 56 | 59 |
| 57 AudioTrackImpl(InterfaceRequest<AudioTrack> track, | 60 AudioTrackImpl(InterfaceRequest<AudioTrack> track_request, |
| 61 InterfaceRequest<MediaRenderer> renderer_request, |
| 58 AudioServerImpl* owner); | 62 AudioServerImpl* owner); |
| 59 | 63 |
| 60 // Implementation of AudioTrack interface. | 64 // Implementation of AudioTrack interface. |
| 61 void Describe(const DescribeCallback& cbk) override; | |
| 62 void Configure(AudioTrackConfigurationPtr configuration, | |
| 63 InterfaceRequest<MediaConsumer> req) override; | |
| 64 void GetTimelineControlSite(InterfaceRequest<MediaTimelineControlSite> req) | |
| 65 override; | |
| 66 void SetGain(float db_gain) override; | 65 void SetGain(float db_gain) override; |
| 67 | 66 |
| 67 // MediaRenderer implementation. |
| 68 void GetSupportedMediaTypes( |
| 69 const GetSupportedMediaTypesCallback& callback) override; |
| 70 void SetMediaType(MediaTypePtr media_type) override; |
| 71 void GetConsumer(InterfaceRequest<MediaConsumer> consumer_request) override; |
| 72 void GetTimelineControlSite( |
| 73 InterfaceRequest<MediaTimelineControlSite> control_site_request) override; |
| 74 |
| 68 // Methods called by our AudioPipe. | 75 // Methods called by our AudioPipe. |
| 69 // | 76 // |
| 70 // TODO(johngro): MI is banned by style, but multiple interface inheritance | 77 // TODO(johngro): MI is banned by style, but multiple interface inheritance |
| 71 // (inheriting for one or more base classes consisting only of pure virtual | 78 // (inheriting for one or more base classes consisting only of pure virtual |
| 72 // methods) is allowed. Consider defining an interface for AudioPipe | 79 // methods) is allowed. Consider defining an interface for AudioPipe |
| 73 // encapsulation so that AudioPipe does not have to know that we are an | 80 // encapsulation so that AudioPipe does not have to know that we are an |
| 74 // AudioTrackImpl (just that we implement its interface). | 81 // AudioTrackImpl (just that we implement its interface). |
| 75 void OnPacketReceived(AudioPipe::AudioPacketRefPtr packet); | 82 void OnPacketReceived(AudioPipe::AudioPacketRefPtr packet); |
| 76 bool OnFlushRequested(const MediaConsumer::FlushCallback& cbk); | 83 bool OnFlushRequested(const MediaConsumer::FlushCallback& cbk); |
| 77 | 84 |
| 78 AudioTrackImplWeakPtr weak_this_; | 85 AudioTrackImplWeakPtr weak_this_; |
| 79 AudioServerImpl* owner_; | 86 AudioServerImpl* owner_; |
| 80 Binding<AudioTrack> binding_; | 87 Binding<AudioTrack> track_binding_; |
| 88 Binding<MediaRenderer> renderer_binding_; |
| 81 AudioPipe pipe_; | 89 AudioPipe pipe_; |
| 82 TimelineControlSite timeline_control_site_; | 90 TimelineControlSite timeline_control_site_; |
| 83 TimelineRate frames_per_ns_; | 91 TimelineRate frames_per_ns_; |
| 84 LinearTransform::Ratio frame_to_media_ratio_; | 92 LinearTransform::Ratio frame_to_media_ratio_; |
| 85 uint32_t bytes_per_frame_ = 1; | 93 uint32_t bytes_per_frame_ = 1; |
| 86 AudioMediaTypeDetailsPtr format_; | 94 AudioMediaTypeDetailsPtr format_; |
| 87 AudioTrackToOutputLinkSet outputs_; | 95 AudioTrackToOutputLinkSet outputs_; |
| 88 float db_gain_ = 0.0; | 96 float db_gain_ = 0.0; |
| 89 }; | 97 }; |
| 90 | 98 |
| 91 } // namespace audio | 99 } // namespace audio |
| 92 } // namespace media | 100 } // namespace media |
| 93 } // namespace mojo | 101 } // namespace mojo |
| 94 | 102 |
| 95 #endif // SERVICES_MEDIA_AUDIO_AUDIO_TRACK_IMPL_H_ | 103 #endif // SERVICES_MEDIA_AUDIO_AUDIO_TRACK_IMPL_H_ |
| OLD | NEW |