| OLD | NEW |
| (Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef CONTENT_RENDERER_MEDIA_MEDIA_STREAM_SOURCE_H_ |
| 6 #define CONTENT_RENDERER_MEDIA_MEDIA_STREAM_SOURCE_H_ |
| 7 |
| 8 #include "base/callback.h" |
| 9 #include "base/compiler_specific.h" |
| 10 #include "base/logging.h" |
| 11 #include "content/common/content_export.h" |
| 12 #include "content/common/media/media_stream_options.h" |
| 13 #include "third_party/WebKit/public/platform/WebMediaStreamSource.h" |
| 14 |
| 15 namespace blink { |
| 16 class WebMediaStreamTrack; |
| 17 } // namespace blink |
| 18 |
| 19 namespace content { |
| 20 |
| 21 class CONTENT_EXPORT MediaStreamSource |
| 22 : NON_EXPORTED_BASE(public blink::WebMediaStreamSource::ExtraData) { |
| 23 public: |
| 24 typedef base::Callback<void(const blink::WebMediaStreamSource& source)> |
| 25 SourceStoppedCallback; |
| 26 |
| 27 typedef base::Callback<void(MediaStreamSource* source, |
| 28 bool success)> ConstraintsCallback; |
| 29 |
| 30 MediaStreamSource(); |
| 31 virtual ~MediaStreamSource(); |
| 32 |
| 33 virtual void AddTrack(const blink::WebMediaStreamTrack& track, |
| 34 const blink::WebMediaConstraints& constraints, |
| 35 const ConstraintsCallback& callback) = 0; |
| 36 virtual void RemoveTrack(const blink::WebMediaStreamTrack& track) = 0; |
| 37 |
| 38 // Returns device information about a source that has been created by a |
| 39 // JavaScript call to GetUserMedia, e.g., a camera or microphone. |
| 40 const StreamDeviceInfo& device_info() const { |
| 41 return device_info_; |
| 42 } |
| 43 |
| 44 // Stops the source (by calling DoStopSource()). This sets the |
| 45 // WebMediaStreamSource::readyState to ended, triggers the |stop_callback_| |
| 46 // if set. All pointers to this object are invalid after calling this. |
| 47 void StopSource(); |
| 48 |
| 49 void ResetSourceStoppedCallback() { |
| 50 DCHECK(!stop_callback_.is_null()); |
| 51 stop_callback_.Reset(); |
| 52 } |
| 53 |
| 54 protected: |
| 55 // Called when StopSource is called. It allows derived classes to implement |
| 56 // its own Stop method. |
| 57 virtual void DoStopSource() = 0; |
| 58 |
| 59 // Sets device information about a source that has been created by a |
| 60 // JavaScript call to GetUserMedia. F.E a camera or microphone. |
| 61 void SetDeviceInfo(const StreamDeviceInfo& device_info) { |
| 62 device_info_ = device_info; |
| 63 } |
| 64 |
| 65 // Sets a callback that will be triggered when StopSource is called. |
| 66 void SetStopCallback(const SourceStoppedCallback& stop_callback) { |
| 67 DCHECK(stop_callback_.is_null()); |
| 68 stop_callback_ = stop_callback; |
| 69 } |
| 70 |
| 71 private: |
| 72 StreamDeviceInfo device_info_; |
| 73 SourceStoppedCallback stop_callback_; |
| 74 |
| 75 DISALLOW_COPY_AND_ASSIGN(MediaStreamSource); |
| 76 }; |
| 77 |
| 78 } // namespace content |
| 79 |
| 80 #endif // CONTENT_RENDERER_MEDIA_MEDIA_STREAM_SOURCE_H_ |
| OLD | NEW |