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 CONTENT_RENDERER_MEDIA_WEBRTC_PEER_CONNECTION_REMOTE_AUDIO_SOURCE_H_ |
| 6 #define CONTENT_RENDERER_MEDIA_WEBRTC_PEER_CONNECTION_REMOTE_AUDIO_SOURCE_H_ |
| 7 |
| 8 #include "base/memory/ref_counted.h" |
| 9 #include "content/renderer/media/media_stream_audio_track.h" |
| 10 #include "content/renderer/media/media_stream_audio_source.h" |
| 11 #include "third_party/webrtc/api/mediastreaminterface.h" |
| 12 |
| 13 namespace content { |
| 14 |
| 15 // PeerConnectionRemoteAudioTrack is a WebRTC specific implementation of an |
| 16 // audio track whose data is sourced from a PeerConnection. |
| 17 class PeerConnectionRemoteAudioTrack : public MediaStreamAudioTrack { |
| 18 public: |
| 19 explicit PeerConnectionRemoteAudioTrack( |
| 20 const scoped_refptr<webrtc::AudioTrackInterface>& track_interface); |
| 21 ~PeerConnectionRemoteAudioTrack() final; |
| 22 |
| 23 // If |track| is an instance of PeerConnectionRemoteAudioTrack, return a |
| 24 // type-casted pointer to it. Otherwise, return null. |
| 25 static PeerConnectionRemoteAudioTrack* From(MediaStreamAudioTrack* track); |
| 26 |
| 27 webrtc::AudioTrackInterface* track_interface() const { |
| 28 return track_interface_.get(); |
| 29 } |
| 30 |
| 31 // MediaStreamAudioTrack override. |
| 32 void SetEnabled(bool enabled) final; |
| 33 void* GetClassIdentifier() const final; |
| 34 |
| 35 private: |
| 36 const scoped_refptr<webrtc::AudioTrackInterface> track_interface_; |
| 37 }; |
| 38 |
| 39 // Represents the audio provided by the receiving end of a PeerConnection. |
| 40 class PeerConnectionRemoteAudioSource |
| 41 : NON_EXPORTED_BASE(public MediaStreamAudioSource), |
| 42 NON_EXPORTED_BASE(protected webrtc::AudioTrackSinkInterface) { |
| 43 public: |
| 44 explicit PeerConnectionRemoteAudioSource( |
| 45 const scoped_refptr<webrtc::AudioTrackInterface>& track_interface); |
| 46 ~PeerConnectionRemoteAudioSource() final; |
| 47 |
| 48 protected: |
| 49 // MediaStreamAudioSource overrides. |
| 50 scoped_ptr<MediaStreamAudioTrack> CreateMediaStreamAudioTrack( |
| 51 const std::string& id) final; |
| 52 void DoStopSource() final; |
| 53 bool EnsureSourceIsStarted() final; |
| 54 |
| 55 // webrtc::AudioTrackSinkInterface implementation. |
| 56 void OnData(const void* audio_data, int bits_per_sample, int sample_rate, |
| 57 size_t number_of_channels, size_t number_of_frames) final; |
| 58 |
| 59 private: |
| 60 // Interface to the implementation that calls OnData(). |
| 61 const scoped_refptr<webrtc::AudioTrackInterface> track_interface_; |
| 62 |
| 63 // True if |this| has been registered as a sink via |track_interface_|. |
| 64 bool is_started_; |
| 65 |
| 66 // Buffer for converting from interleaved int16 PCM samples to the planar |
| 67 // float format. Only used on the thread that calls OnData(). |
| 68 scoped_ptr<media::AudioBus> audio_bus_; |
| 69 }; |
| 70 |
| 71 } // namespace content |
| 72 |
| 73 #endif // CONTENT_RENDERER_MEDIA_WEBRTC_PEER_CONNECTION_REMOTE_AUDIO_SOURCE_H_ |
OLD | NEW |