2013-07-10 00:45:36 +00:00
|
|
|
/*
|
2016-02-10 07:54:43 -08:00
|
|
|
* Copyright 2012 The WebRTC project authors. All Rights Reserved.
|
2013-07-10 00:45:36 +00:00
|
|
|
*
|
2016-02-10 07:54:43 -08:00
|
|
|
* Use of this source code is governed by a BSD-style license
|
|
|
|
|
* that can be found in the LICENSE file in the root of the source
|
|
|
|
|
* tree. An additional intellectual property rights grant can be found
|
|
|
|
|
* in the file PATENTS. All contributing project authors may
|
|
|
|
|
* be found in the AUTHORS file in the root of the source tree.
|
2013-07-10 00:45:36 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
// This file contains interfaces for MediaStream, MediaTrack and MediaSource.
|
|
|
|
|
// These interfaces are used for implementing MediaStream and MediaTrack as
|
|
|
|
|
// defined in http://dev.w3.org/2011/webrtc/editor/webrtc.html#stream-api. These
|
|
|
|
|
// interfaces must be used only with PeerConnection. PeerConnectionManager
|
|
|
|
|
// interface provides the factory methods to create MediaStream and MediaTracks.
|
|
|
|
|
|
2016-02-10 10:53:12 +01:00
|
|
|
#ifndef WEBRTC_API_MEDIASTREAMINTERFACE_H_
|
|
|
|
|
#define WEBRTC_API_MEDIASTREAMINTERFACE_H_
|
2013-07-10 00:45:36 +00:00
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
|
#include <vector>
|
|
|
|
|
|
2014-07-29 17:36:52 +00:00
|
|
|
#include "webrtc/base/basictypes.h"
|
|
|
|
|
#include "webrtc/base/refcount.h"
|
|
|
|
|
#include "webrtc/base/scoped_ref_ptr.h"
|
2016-01-28 04:47:08 -08:00
|
|
|
#include "webrtc/media/base/videosinkinterface.h"
|
2013-07-10 00:45:36 +00:00
|
|
|
|
|
|
|
|
namespace cricket {
|
|
|
|
|
|
|
|
|
|
class AudioRenderer;
|
|
|
|
|
class VideoCapturer;
|
|
|
|
|
class VideoRenderer;
|
|
|
|
|
class VideoFrame;
|
|
|
|
|
|
|
|
|
|
} // namespace cricket
|
|
|
|
|
|
|
|
|
|
namespace webrtc {
|
|
|
|
|
|
|
|
|
|
// Generic observer interface.
|
|
|
|
|
class ObserverInterface {
|
|
|
|
|
public:
|
|
|
|
|
virtual void OnChanged() = 0;
|
|
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
virtual ~ObserverInterface() {}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class NotifierInterface {
|
|
|
|
|
public:
|
|
|
|
|
virtual void RegisterObserver(ObserverInterface* observer) = 0;
|
|
|
|
|
virtual void UnregisterObserver(ObserverInterface* observer) = 0;
|
|
|
|
|
|
|
|
|
|
virtual ~NotifierInterface() {}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// Base class for sources. A MediaStreamTrack have an underlying source that
|
|
|
|
|
// provide media. A source can be shared with multiple tracks.
|
2014-07-29 17:36:52 +00:00
|
|
|
class MediaSourceInterface : public rtc::RefCountInterface,
|
2013-07-10 00:45:36 +00:00
|
|
|
public NotifierInterface {
|
|
|
|
|
public:
|
|
|
|
|
enum SourceState {
|
|
|
|
|
kInitializing,
|
|
|
|
|
kLive,
|
|
|
|
|
kEnded,
|
|
|
|
|
kMuted
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
virtual SourceState state() const = 0;
|
|
|
|
|
|
2015-12-15 04:27:11 -08:00
|
|
|
virtual bool remote() const = 0;
|
|
|
|
|
|
2013-07-10 00:45:36 +00:00
|
|
|
protected:
|
|
|
|
|
virtual ~MediaSourceInterface() {}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// Information about a track.
|
2014-07-29 17:36:52 +00:00
|
|
|
class MediaStreamTrackInterface : public rtc::RefCountInterface,
|
2013-07-10 00:45:36 +00:00
|
|
|
public NotifierInterface {
|
|
|
|
|
public:
|
|
|
|
|
enum TrackState {
|
|
|
|
|
kInitializing, // Track is beeing negotiated.
|
|
|
|
|
kLive = 1, // Track alive
|
|
|
|
|
kEnded = 2, // Track have ended
|
|
|
|
|
kFailed = 3, // Track negotiation failed.
|
|
|
|
|
};
|
|
|
|
|
|
2015-11-25 11:26:01 -08:00
|
|
|
static const char kAudioKind[];
|
|
|
|
|
static const char kVideoKind[];
|
|
|
|
|
|
2013-07-10 00:45:36 +00:00
|
|
|
virtual std::string kind() const = 0;
|
|
|
|
|
virtual std::string id() const = 0;
|
|
|
|
|
virtual bool enabled() const = 0;
|
|
|
|
|
virtual TrackState state() const = 0;
|
|
|
|
|
virtual bool set_enabled(bool enable) = 0;
|
|
|
|
|
// These methods should be called by implementation only.
|
|
|
|
|
virtual bool set_state(TrackState new_state) = 0;
|
2013-08-12 23:26:21 +00:00
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
virtual ~MediaStreamTrackInterface() {}
|
2013-07-10 00:45:36 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// Interface for rendering VideoFrames from a VideoTrack
|
2016-01-28 04:47:08 -08:00
|
|
|
class VideoRendererInterface
|
|
|
|
|
: public rtc::VideoSinkInterface<cricket::VideoFrame> {
|
2013-07-10 00:45:36 +00:00
|
|
|
public:
|
2015-03-12 21:37:26 +00:00
|
|
|
// |frame| may have pending rotation. For clients which can't apply rotation,
|
|
|
|
|
// |frame|->GetCopyWithRotationApplied() will return a frame that has the
|
|
|
|
|
// rotation applied.
|
2013-07-10 00:45:36 +00:00
|
|
|
virtual void RenderFrame(const cricket::VideoFrame* frame) = 0;
|
2016-01-28 04:47:08 -08:00
|
|
|
// Intended to replace RenderFrame.
|
|
|
|
|
void OnFrame(const cricket::VideoFrame& frame) override {
|
|
|
|
|
RenderFrame(&frame);
|
|
|
|
|
}
|
2013-07-10 00:45:36 +00:00
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
// The destructor is protected to prevent deletion via the interface.
|
|
|
|
|
// This is so that we allow reference counted classes, where the destructor
|
|
|
|
|
// should never be public, to implement the interface.
|
|
|
|
|
virtual ~VideoRendererInterface() {}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class VideoSourceInterface;
|
|
|
|
|
|
|
|
|
|
class VideoTrackInterface : public MediaStreamTrackInterface {
|
|
|
|
|
public:
|
|
|
|
|
// Register a renderer that will render all frames received on this track.
|
|
|
|
|
virtual void AddRenderer(VideoRendererInterface* renderer) = 0;
|
|
|
|
|
// Deregister a renderer.
|
|
|
|
|
virtual void RemoveRenderer(VideoRendererInterface* renderer) = 0;
|
|
|
|
|
|
|
|
|
|
virtual VideoSourceInterface* GetSource() const = 0;
|
|
|
|
|
|
2016-02-05 01:52:15 -08:00
|
|
|
// Return the track input sink. I.e., frames sent to this sink are
|
|
|
|
|
// propagated to all renderers registered with the track. The
|
|
|
|
|
// returned sink must not change between calls. Currently, this
|
|
|
|
|
// method is used for remote tracks (VideoRtpReceiver); further
|
|
|
|
|
// refactoring is planned for this path, it's unclear if this method
|
|
|
|
|
// belongs here long term.
|
|
|
|
|
|
|
|
|
|
// We do this instead of simply implementing the
|
|
|
|
|
// VideoSourceInterface directly, because if we did the latter, we'd
|
|
|
|
|
// need an OnFrame method in VideoTrackProxy, with a thread jump on
|
|
|
|
|
// each call.
|
|
|
|
|
|
|
|
|
|
// TODO(nisse): It has a default implementation so that mock
|
|
|
|
|
// objects, in particular, chrome's MockWebRtcVideoTrack, doesn't
|
|
|
|
|
// need to know about it. Consider removing the implementation (or
|
|
|
|
|
// this comment) after refactoring dust settles.
|
|
|
|
|
virtual rtc::VideoSinkInterface<cricket::VideoFrame>* GetSink() {
|
|
|
|
|
return nullptr;
|
|
|
|
|
};
|
|
|
|
|
|
2013-07-10 00:45:36 +00:00
|
|
|
protected:
|
|
|
|
|
virtual ~VideoTrackInterface() {}
|
|
|
|
|
};
|
|
|
|
|
|
2015-12-15 04:27:11 -08:00
|
|
|
// Interface for receiving audio data from a AudioTrack.
|
|
|
|
|
class AudioTrackSinkInterface {
|
|
|
|
|
public:
|
|
|
|
|
virtual void OnData(const void* audio_data,
|
|
|
|
|
int bits_per_sample,
|
|
|
|
|
int sample_rate,
|
Convert channel counts to size_t.
IIRC, this was originally requested by ajm during review of the other size_t conversions I did over the past year, and I agreed it made sense, but wanted to do it separately since those changes were already gargantuan.
BUG=chromium:81439
TEST=none
R=henrik.lundin@webrtc.org, henrika@webrtc.org, kjellander@webrtc.org, minyue@webrtc.org, perkj@webrtc.org, solenberg@webrtc.org, stefan@webrtc.org, tina.legrand@webrtc.org
Review URL: https://codereview.webrtc.org/1316523002 .
Cr-Commit-Position: refs/heads/master@{#11229}
2016-01-12 16:26:35 -08:00
|
|
|
size_t number_of_channels,
|
2015-12-15 04:27:11 -08:00
|
|
|
size_t number_of_frames) = 0;
|
|
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
virtual ~AudioTrackSinkInterface() {}
|
|
|
|
|
};
|
|
|
|
|
|
2013-07-10 00:45:36 +00:00
|
|
|
// AudioSourceInterface is a reference counted source used for AudioTracks.
|
|
|
|
|
// The same source can be used in multiple AudioTracks.
|
|
|
|
|
class AudioSourceInterface : public MediaSourceInterface {
|
2014-02-13 23:18:49 +00:00
|
|
|
public:
|
|
|
|
|
class AudioObserver {
|
|
|
|
|
public:
|
|
|
|
|
virtual void OnSetVolume(double volume) = 0;
|
|
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
virtual ~AudioObserver() {}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// TODO(xians): Makes all the interface pure virtual after Chrome has their
|
|
|
|
|
// implementations.
|
|
|
|
|
// Sets the volume to the source. |volume| is in the range of [0, 10].
|
2015-12-12 01:37:01 +01:00
|
|
|
// TODO(tommi): This method should be on the track and ideally volume should
|
|
|
|
|
// be applied in the track in a way that does not affect clones of the track.
|
2014-02-13 23:18:49 +00:00
|
|
|
virtual void SetVolume(double volume) {}
|
|
|
|
|
|
|
|
|
|
// Registers/unregisters observer to the audio source.
|
|
|
|
|
virtual void RegisterAudioObserver(AudioObserver* observer) {}
|
|
|
|
|
virtual void UnregisterAudioObserver(AudioObserver* observer) {}
|
2013-07-10 00:45:36 +00:00
|
|
|
|
2015-12-15 04:27:11 -08:00
|
|
|
// TODO(tommi): Make pure virtual.
|
|
|
|
|
virtual void AddSink(AudioTrackSinkInterface* sink) {}
|
|
|
|
|
virtual void RemoveSink(AudioTrackSinkInterface* sink) {}
|
2014-02-03 16:57:16 +00:00
|
|
|
};
|
|
|
|
|
|
2014-03-03 18:30:11 +00:00
|
|
|
// Interface of the audio processor used by the audio track to collect
|
|
|
|
|
// statistics.
|
2014-07-29 17:36:52 +00:00
|
|
|
class AudioProcessorInterface : public rtc::RefCountInterface {
|
2014-03-03 18:30:11 +00:00
|
|
|
public:
|
|
|
|
|
struct AudioProcessorStats {
|
|
|
|
|
AudioProcessorStats() : typing_noise_detected(false),
|
|
|
|
|
echo_return_loss(0),
|
|
|
|
|
echo_return_loss_enhancement(0),
|
|
|
|
|
echo_delay_median_ms(0),
|
|
|
|
|
aec_quality_min(0.0),
|
|
|
|
|
echo_delay_std_ms(0) {}
|
|
|
|
|
~AudioProcessorStats() {}
|
|
|
|
|
|
|
|
|
|
bool typing_noise_detected;
|
|
|
|
|
int echo_return_loss;
|
|
|
|
|
int echo_return_loss_enhancement;
|
|
|
|
|
int echo_delay_median_ms;
|
|
|
|
|
float aec_quality_min;
|
|
|
|
|
int echo_delay_std_ms;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// Get audio processor statistics.
|
|
|
|
|
virtual void GetStats(AudioProcessorStats* stats) = 0;
|
|
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
virtual ~AudioProcessorInterface() {}
|
|
|
|
|
};
|
|
|
|
|
|
2013-07-10 00:45:36 +00:00
|
|
|
class AudioTrackInterface : public MediaStreamTrackInterface {
|
|
|
|
|
public:
|
|
|
|
|
// TODO(xians): Figure out if the following interface should be const or not.
|
|
|
|
|
virtual AudioSourceInterface* GetSource() const = 0;
|
|
|
|
|
|
2014-03-03 18:30:11 +00:00
|
|
|
// Add/Remove a sink that will receive the audio data from the track.
|
|
|
|
|
virtual void AddSink(AudioTrackSinkInterface* sink) = 0;
|
|
|
|
|
virtual void RemoveSink(AudioTrackSinkInterface* sink) = 0;
|
|
|
|
|
|
|
|
|
|
// Get the signal level from the audio track.
|
|
|
|
|
// Return true on success, otherwise false.
|
|
|
|
|
// TODO(xians): Change the interface to int GetSignalLevel() and pure virtual
|
|
|
|
|
// after Chrome has the correct implementation of the interface.
|
|
|
|
|
virtual bool GetSignalLevel(int* level) { return false; }
|
|
|
|
|
|
|
|
|
|
// Get the audio processor used by the audio track. Return NULL if the track
|
|
|
|
|
// does not have any processor.
|
|
|
|
|
// TODO(xians): Make the interface pure virtual.
|
2014-07-29 17:36:52 +00:00
|
|
|
virtual rtc::scoped_refptr<AudioProcessorInterface>
|
2014-03-04 19:54:57 +00:00
|
|
|
GetAudioProcessor() { return NULL; }
|
2014-02-03 16:57:16 +00:00
|
|
|
|
2013-07-10 00:45:36 +00:00
|
|
|
protected:
|
|
|
|
|
virtual ~AudioTrackInterface() {}
|
|
|
|
|
};
|
|
|
|
|
|
2014-07-29 17:36:52 +00:00
|
|
|
typedef std::vector<rtc::scoped_refptr<AudioTrackInterface> >
|
2013-07-10 00:45:36 +00:00
|
|
|
AudioTrackVector;
|
2014-07-29 17:36:52 +00:00
|
|
|
typedef std::vector<rtc::scoped_refptr<VideoTrackInterface> >
|
2013-07-10 00:45:36 +00:00
|
|
|
VideoTrackVector;
|
|
|
|
|
|
2014-07-29 17:36:52 +00:00
|
|
|
class MediaStreamInterface : public rtc::RefCountInterface,
|
2013-07-10 00:45:36 +00:00
|
|
|
public NotifierInterface {
|
|
|
|
|
public:
|
|
|
|
|
virtual std::string label() const = 0;
|
|
|
|
|
|
|
|
|
|
virtual AudioTrackVector GetAudioTracks() = 0;
|
|
|
|
|
virtual VideoTrackVector GetVideoTracks() = 0;
|
2014-07-29 17:36:52 +00:00
|
|
|
virtual rtc::scoped_refptr<AudioTrackInterface>
|
2013-07-10 00:45:36 +00:00
|
|
|
FindAudioTrack(const std::string& track_id) = 0;
|
2014-07-29 17:36:52 +00:00
|
|
|
virtual rtc::scoped_refptr<VideoTrackInterface>
|
2013-07-10 00:45:36 +00:00
|
|
|
FindVideoTrack(const std::string& track_id) = 0;
|
|
|
|
|
|
|
|
|
|
virtual bool AddTrack(AudioTrackInterface* track) = 0;
|
|
|
|
|
virtual bool AddTrack(VideoTrackInterface* track) = 0;
|
|
|
|
|
virtual bool RemoveTrack(AudioTrackInterface* track) = 0;
|
|
|
|
|
virtual bool RemoveTrack(VideoTrackInterface* track) = 0;
|
|
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
virtual ~MediaStreamInterface() {}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // namespace webrtc
|
|
|
|
|
|
2016-02-10 10:53:12 +01:00
|
|
|
#endif // WEBRTC_API_MEDIASTREAMINTERFACE_H_
|