You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

290 lines
10 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. /*
  2. * libjingle
  3. * Copyright 2012, Google Inc.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions are met:
  7. *
  8. * 1. Redistributions of source code must retain the above copyright notice,
  9. * this list of conditions and the following disclaimer.
  10. * 2. Redistributions in binary form must reproduce the above copyright notice,
  11. * this list of conditions and the following disclaimer in the documentation
  12. * and/or other materials provided with the distribution.
  13. * 3. The name of the author may not be used to endorse or promote products
  14. * derived from this software without specific prior written permission.
  15. *
  16. * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
  17. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  18. * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
  19. * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  20. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  21. * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
  22. * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  23. * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
  24. * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
  25. * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26. */
  27. // This file contains interfaces for MediaStream, MediaTrack and MediaSource.
  28. // These interfaces are used for implementing MediaStream and MediaTrack as
  29. // defined in http://dev.w3.org/2011/webrtc/editor/webrtc.html#stream-api. These
  30. // interfaces must be used only with PeerConnection. PeerConnectionManager
  31. // interface provides the factory methods to create MediaStream and MediaTracks.
  32. #ifndef TALK_APP_WEBRTC_MEDIASTREAMINTERFACE_H_
  33. #define TALK_APP_WEBRTC_MEDIASTREAMINTERFACE_H_
  34. #include <string>
  35. #include <vector>
  36. #include "talk/base/basictypes.h"
  37. #include "talk/base/refcount.h"
  38. #include "talk/base/scoped_ref_ptr.h"
  39. namespace cricket {
  40. class VideoCapturer;
  41. class VideoRenderer;
  42. class VideoFrame;
  43. } // namespace cricket
  44. namespace webrtc {
  45. // Generic observer interface.
  46. class ObserverInterface {
  47. public:
  48. virtual void OnChanged() = 0;
  49. protected:
  50. virtual ~ObserverInterface() {}
  51. };
  52. class NotifierInterface {
  53. public:
  54. virtual void RegisterObserver(ObserverInterface* observer) = 0;
  55. virtual void UnregisterObserver(ObserverInterface* observer) = 0;
  56. virtual ~NotifierInterface() {}
  57. };
  58. // Base class for sources. A MediaStreamTrack have an underlying source that
  59. // provide media. A source can be shared with multiple tracks.
  60. // TODO(perkj): Implement sources for local and remote audio tracks and
  61. // remote video tracks.
  62. class MediaSourceInterface : public talk_base::RefCountInterface,
  63. public NotifierInterface {
  64. public:
  65. enum SourceState {
  66. kInitializing,
  67. kLive,
  68. kEnded,
  69. kMuted
  70. };
  71. virtual SourceState state() const = 0;
  72. protected:
  73. virtual ~MediaSourceInterface() {}
  74. };
  75. // Information about a track.
  76. class MediaStreamTrackInterface : public talk_base::RefCountInterface,
  77. public NotifierInterface {
  78. public:
  79. enum TrackState {
  80. kInitializing, // Track is beeing negotiated.
  81. kLive = 1, // Track alive
  82. kEnded = 2, // Track have ended
  83. kFailed = 3, // Track negotiation failed.
  84. };
  85. virtual std::string kind() const = 0;
  86. virtual std::string id() const = 0;
  87. virtual bool enabled() const = 0;
  88. virtual TrackState state() const = 0;
  89. virtual bool set_enabled(bool enable) = 0;
  90. // These methods should be called by implementation only.
  91. virtual bool set_state(TrackState new_state) = 0;
  92. };
  93. // Interface for rendering VideoFrames from a VideoTrack
  94. class VideoRendererInterface {
  95. public:
  96. virtual void SetSize(int width, int height) = 0;
  97. virtual void RenderFrame(const cricket::VideoFrame* frame) = 0;
  98. protected:
  99. // The destructor is protected to prevent deletion via the interface.
  100. // This is so that we allow reference counted classes, where the destructor
  101. // should never be public, to implement the interface.
  102. virtual ~VideoRendererInterface() {}
  103. };
  104. class VideoSourceInterface;
  105. class VideoTrackInterface : public MediaStreamTrackInterface {
  106. public:
  107. // Register a renderer that will render all frames received on this track.
  108. virtual void AddRenderer(VideoRendererInterface* renderer) = 0;
  109. // Deregister a renderer.
  110. virtual void RemoveRenderer(VideoRendererInterface* renderer) = 0;
  111. // Gets a pointer to the frame input of this VideoTrack.
  112. // The pointer is valid for the lifetime of this VideoTrack.
  113. // VideoFrames rendered to the cricket::VideoRenderer will be rendered on all
  114. // registered renderers.
  115. virtual cricket::VideoRenderer* FrameInput() = 0;
  116. virtual VideoSourceInterface* GetSource() const = 0;
  117. protected:
  118. virtual ~VideoTrackInterface() {}
  119. };
  120. // TODO(perkj): Deprecate and remove LocalAudioTrackInterface when no clients
  121. // use it.
  122. typedef VideoTrackInterface LocalVideoTrackInterface;
  123. // AudioSourceInterface is a reference counted source used for AudioTracks.
  124. // The same source can be used in multiple AudioTracks.
  125. // TODO(perkj): Extend this class with necessary methods to allow separate
  126. // sources for each audio track.
  127. class AudioSourceInterface : public MediaSourceInterface {
  128. };
  129. class AudioTrackInterface : public MediaStreamTrackInterface {
  130. public:
  131. virtual AudioSourceInterface* GetSource() const = 0;
  132. protected:
  133. virtual ~AudioTrackInterface() {}
  134. };
  135. // TODO(perkj): Deprecate and remove LocalAudioTrackInterface when no clients
  136. // use it.
  137. typedef AudioTrackInterface LocalAudioTrackInterface;
  138. // List of of tracks.
  139. // Deprecated: Please use TrackVectors.
  140. template <class TrackType>
  141. class MediaStreamTrackListInterface : public talk_base::RefCountInterface {
  142. public:
  143. virtual size_t count() const = 0;
  144. virtual TrackType* at(size_t index) = 0;
  145. virtual TrackType* Find(const std::string& id) = 0;
  146. protected:
  147. virtual ~MediaStreamTrackListInterface() {}
  148. };
  149. typedef std::vector<talk_base::scoped_refptr<AudioTrackInterface> >
  150. AudioTrackVector;
  151. typedef std::vector<talk_base::scoped_refptr<VideoTrackInterface> >
  152. VideoTrackVector;
  153. // Deprecated: Please use AudioTrackVector.
  154. typedef MediaStreamTrackListInterface<AudioTrackInterface> AudioTracks;
  155. // Deprecated: Please use VideoTrackVector.
  156. typedef MediaStreamTrackListInterface<VideoTrackInterface> VideoTracks;
  157. class MediaStreamInterface : public talk_base::RefCountInterface,
  158. public NotifierInterface {
  159. public:
  160. virtual std::string label() const = 0;
  161. virtual AudioTrackVector GetAudioTracks() = 0;
  162. virtual VideoTrackVector GetVideoTracks() = 0;
  163. virtual talk_base::scoped_refptr<AudioTrackInterface>
  164. FindAudioTrack(const std::string& track_id) = 0;
  165. virtual talk_base::scoped_refptr<VideoTrackInterface>
  166. FindVideoTrack(const std::string& track_id) = 0;
  167. virtual bool AddTrack(AudioTrackInterface* track) = 0;
  168. virtual bool AddTrack(VideoTrackInterface* track) = 0;
  169. virtual bool RemoveTrack(AudioTrackInterface* track) = 0;
  170. virtual bool RemoveTrack(VideoTrackInterface* track) = 0;
  171. // Deprecated: Please use GetAudioTracks.
  172. virtual AudioTracks* audio_tracks() = 0;
  173. // Deprecated: Please use GetVideoTracks.
  174. virtual VideoTracks* video_tracks() = 0;
  175. protected:
  176. virtual ~MediaStreamInterface() {}
  177. };
  178. // Currently there is no difference between LocalMediaStreams and MediaStreams
  179. // but the class is kept since Chrome use this type to distinguish between
  180. // local and remote streams.
  181. // TODO(perkj): Decide if LocalMediaStreamInterface is needed or not once Chrome
  182. // don't care about the type.
  183. class LocalMediaStreamInterface : public MediaStreamInterface {
  184. public:
  185. };
  186. // MediaConstraintsInterface
  187. // Interface used for passing arguments about media constraints
  188. // to the MediaStream and PeerConnection implementation.
  189. class MediaConstraintsInterface {
  190. public:
  191. struct Constraint {
  192. Constraint() {}
  193. Constraint(const std::string& key, const std::string value)
  194. : key(key), value(value) {
  195. }
  196. std::string key;
  197. std::string value;
  198. };
  199. typedef std::vector<Constraint> Constraints;
  200. virtual const Constraints& GetMandatory() const = 0;
  201. virtual const Constraints& GetOptional() const = 0;
  202. // Constraint keys used by a local video source.
  203. // Specified by draft-alvestrand-constraints-resolution-00b
  204. static const char kMinAspectRatio[]; // minAspectRatio
  205. static const char kMaxAspectRatio[]; // maxAspectRatio
  206. static const char kMaxWidth[]; // maxWidth
  207. static const char kMinWidth[]; // minWidth
  208. static const char kMaxHeight[]; // maxHeight
  209. static const char kMinHeight[]; // minHeight
  210. static const char kMaxFrameRate[]; // maxFrameRate
  211. static const char kMinFrameRate[]; // minFrameRate
  212. // Constraint keys used by a local audio source.
  213. // These keys are google specific.
  214. static const char kEchoCancellation[]; // googEchoCancellation
  215. static const char kAutoGainControl[]; // googAutoGainControl
  216. static const char kNoiseSuppression[]; // googNoiseSuppression
  217. static const char kHighpassFilter[]; // googHighpassFilter
  218. // Google-specific constraint keys for a local video source
  219. static const char kNoiseReduction[]; // googNoiseReduction
  220. static const char kLeakyBucket[]; // googLeakyBucket
  221. // Constraint keys for CreateOffer / CreateAnswer
  222. // Specified by the W3C PeerConnection spec
  223. static const char kOfferToReceiveVideo[]; // OfferToReceiveVideo
  224. static const char kOfferToReceiveAudio[]; // OfferToReceiveAudio
  225. static const char kIceRestart[]; // IceRestart
  226. // These keys are google specific.
  227. static const char kUseRtpMux[]; // googUseRtpMUX
  228. // Constraints values.
  229. static const char kValueTrue[]; // true
  230. static const char kValueFalse[]; // false
  231. // Temporary pseudo-constraints used to enable DTLS-SRTP
  232. static const char kEnableDtlsSrtp[]; // Enable DTLS-SRTP
  233. // Temporary pseudo-constraints used to enable DataChannels
  234. static const char kEnableRtpDataChannels[]; // Enable DataChannels
  235. protected:
  236. // Dtor protected as objects shouldn't be deleted via this interface
  237. virtual ~MediaConstraintsInterface() {}
  238. };
  239. } // namespace webrtc
  240. #endif // TALK_APP_WEBRTC_MEDIASTREAMINTERFACE_H_