| OLD | NEW | 
|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 CONTENT_RENDERER_MEDIA_MEDIA_STREAM_H_ | 5 #ifndef CONTENT_RENDERER_MEDIA_MEDIA_STREAM_H_ | 
| 6 #define CONTENT_RENDERER_MEDIA_MEDIA_STREAM_H_ | 6 #define CONTENT_RENDERER_MEDIA_MEDIA_STREAM_H_ | 
| 7 | 7 | 
| 8 #include <string> | 8 #include <string> | 
| 9 | 9 | 
| 10 #include "base/callback.h" | 10 #include "base/callback.h" | 
| 11 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" | 
| 12 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" | 
| 13 #include "content/common/content_export.h" | 13 #include "content/common/content_export.h" | 
| 14 #include "third_party/WebKit/public/platform/WebMediaStream.h" | 14 #include "third_party/WebKit/public/platform/WebMediaStream.h" | 
| 15 | 15 | 
| 16 namespace webrtc { | 16 namespace webrtc { | 
| 17 class MediaStreamInterface; | 17 class MediaStreamInterface; | 
| 18 }  // namespace webrtc | 18 }  // namespace webrtc | 
| 19 | 19 | 
| 20 namespace content { | 20 namespace content { | 
| 21 | 21 | 
| 22 class MediaStreamDependencyFactory; | 22 class MediaStreamDependencyFactory; | 
| 23 | 23 | 
| 24 // MediaStream is the Chrome representation of blink::WebMediaStream. | 24 // MediaStream is the Chrome representation of blink::WebMediaStream. | 
| 25 // It is owned by blink::WebMediaStream as blink::WebMediaStream::ExtraData. | 25 // It is owned by blink::WebMediaStream as blink::WebMediaStream::ExtraData. | 
| 26 class CONTENT_EXPORT MediaStream | 26 class CONTENT_EXPORT MediaStream | 
| 27     : NON_EXPORTED_BASE(public blink::WebMediaStream::ExtraData) { | 27     : NON_EXPORTED_BASE(public blink::WebMediaStream::ExtraData) { | 
| 28  public: | 28  public: | 
| 29   typedef base::Callback<void(const std::string& label)> StreamStopCallback; |  | 
| 30 |  | 
| 31   // Constructor for local MediaStreams. | 29   // Constructor for local MediaStreams. | 
| 32   MediaStream(MediaStreamDependencyFactory* factory, | 30   MediaStream(MediaStreamDependencyFactory* factory, | 
| 33               StreamStopCallback stream_stop, |  | 
| 34               const blink::WebMediaStream& stream); | 31               const blink::WebMediaStream& stream); | 
| 35   // Constructor for remote MediaStreams. | 32   // Constructor for remote MediaStreams. | 
| 36   explicit MediaStream(webrtc::MediaStreamInterface* stream); | 33   explicit MediaStream(webrtc::MediaStreamInterface* stream); | 
| 37 | 34 | 
| 38   virtual ~MediaStream(); | 35   virtual ~MediaStream(); | 
| 39 | 36 | 
| 40   // Returns an instance of MediaStream. This method will never return NULL. | 37   // Returns an instance of MediaStream. This method will never return NULL. | 
| 41   static MediaStream* GetMediaStream( | 38   static MediaStream* GetMediaStream( | 
| 42       const blink::WebMediaStream& stream); | 39       const blink::WebMediaStream& stream); | 
| 43 | 40 | 
| 44   // Returns a libjingle representation of a MediaStream. If a representation | 41   // Returns a libjingle representation of a MediaStream. If a representation | 
| 45   // does not exist- the libjingle stream is created. This method will never | 42   // does not exist- the libjingle stream is created. This method will never | 
| 46   // return NULL. | 43   // return NULL. | 
| 47   static webrtc::MediaStreamInterface* GetAdapter( | 44   static webrtc::MediaStreamInterface* GetAdapter( | 
| 48       const blink::WebMediaStream& stream); | 45       const blink::WebMediaStream& stream); | 
| 49 | 46 | 
| 50   // TODO(xians): Remove |is_local| once AudioTracks can be rendered the same | 47   // TODO(xians): Remove |is_local| once AudioTracks can be rendered the same | 
| 51   // way regardless if they are local or remote. | 48   // way regardless if they are local or remote. | 
| 52   bool is_local() const { return is_local_; } | 49   bool is_local() const { return is_local_; } | 
| 53 | 50 | 
| 54   // Called by MediaStreamCenter when a stream has been stopped |  | 
| 55   // from JavaScript. Triggers |stream_stop_callback_|. |  | 
| 56   void OnStreamStopped(); |  | 
| 57 |  | 
| 58   // Called by MediaStreamCenter when a track has been added to a stream stream. | 51   // Called by MediaStreamCenter when a track has been added to a stream stream. | 
| 59   // If a libjingle representation of |stream| exist, the track is added to | 52   // If a libjingle representation of |stream| exist, the track is added to | 
| 60   // the libjingle MediaStream. | 53   // the libjingle MediaStream. | 
| 61   bool AddTrack(const blink::WebMediaStream& stream, | 54   bool AddTrack(const blink::WebMediaStream& stream, | 
| 62                 const blink::WebMediaStreamTrack& track); | 55                 const blink::WebMediaStreamTrack& track); | 
| 63 | 56 | 
| 64   // Called by MediaStreamCenter when a track has been removed from |stream| | 57   // Called by MediaStreamCenter when a track has been removed from |stream| | 
| 65   // If a libjingle representation or |stream| exist, the track is removed | 58   // If a libjingle representation or |stream| exist, the track is removed | 
| 66   // from the libjingle MediaStream. | 59   // from the libjingle MediaStream. | 
| 67   bool RemoveTrack(const blink::WebMediaStream& stream, | 60   bool RemoveTrack(const blink::WebMediaStream& stream, | 
| 68                    const blink::WebMediaStreamTrack& track); | 61                    const blink::WebMediaStreamTrack& track); | 
| 69 | 62 | 
| 70  protected: | 63  protected: | 
| 71   virtual webrtc::MediaStreamInterface* GetWebRtcAdapter( | 64   virtual webrtc::MediaStreamInterface* GetWebRtcAdapter( | 
| 72       const blink::WebMediaStream& stream); | 65       const blink::WebMediaStream& stream); | 
| 73 | 66 | 
| 74  private: | 67  private: | 
| 75   StreamStopCallback stream_stop_callback_; |  | 
| 76   scoped_refptr<webrtc::MediaStreamInterface> stream_adapter_; | 68   scoped_refptr<webrtc::MediaStreamInterface> stream_adapter_; | 
| 77   const bool is_local_; | 69   const bool is_local_; | 
| 78   const std::string label_; | 70   const std::string label_; | 
| 79 | 71 | 
| 80   // Weak ref to a MediaStreamDependencyFactory, owned by the RenderThread. | 72   // Weak ref to a MediaStreamDependencyFactory, owned by the RenderThread. | 
| 81   // It's valid for the lifetime of RenderThread. | 73   // It's valid for the lifetime of RenderThread. | 
| 82   MediaStreamDependencyFactory* factory_; | 74   MediaStreamDependencyFactory* factory_; | 
| 83 | 75 | 
| 84   DISALLOW_COPY_AND_ASSIGN(MediaStream); | 76   DISALLOW_COPY_AND_ASSIGN(MediaStream); | 
| 85 }; | 77 }; | 
| 86 | 78 | 
| 87 }  // namespace content | 79 }  // namespace content | 
| 88 | 80 | 
| 89 #endif  // CONTENT_RENDERER_MEDIA_MEDIA_STREAM_H_ | 81 #endif  // CONTENT_RENDERER_MEDIA_MEDIA_STREAM_H_ | 
| OLD | NEW | 
|---|