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_SOURCE_H_ | 5 #ifndef CONTENT_RENDERER_MEDIA_MEDIA_STREAM_SOURCE_H_ |
6 #define CONTENT_RENDERER_MEDIA_MEDIA_STREAM_SOURCE_H_ | 6 #define CONTENT_RENDERER_MEDIA_MEDIA_STREAM_SOURCE_H_ |
7 | 7 |
8 #include "base/callback.h" | 8 #include "base/callback.h" |
9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
11 #include "base/macros.h" | 11 #include "base/macros.h" |
12 #include "base/threading/thread_checker.h" | |
13 #include "content/common/content_export.h" | 12 #include "content/common/content_export.h" |
14 #include "content/common/media/media_stream_options.h" | 13 #include "content/common/media/media_stream_options.h" |
15 #include "third_party/WebKit/public/platform/WebMediaStreamSource.h" | 14 #include "third_party/WebKit/public/platform/WebMediaStreamSource.h" |
16 | 15 |
17 namespace blink { | 16 namespace blink { |
18 class WebMediaStreamTrack; | 17 class WebMediaStreamTrack; |
19 } // namespace blink | 18 } // namespace blink |
20 | 19 |
21 namespace content { | 20 namespace content { |
22 | 21 |
(...skipping 14 matching lines...) Expand all Loading... |
37 | 36 |
38 MediaStreamSource(); | 37 MediaStreamSource(); |
39 ~MediaStreamSource() override; | 38 ~MediaStreamSource() override; |
40 | 39 |
41 // Returns device information about a source that has been created by a | 40 // Returns device information about a source that has been created by a |
42 // JavaScript call to GetUserMedia, e.g., a camera or microphone. | 41 // JavaScript call to GetUserMedia, e.g., a camera or microphone. |
43 const StreamDeviceInfo& device_info() const { | 42 const StreamDeviceInfo& device_info() const { |
44 return device_info_; | 43 return device_info_; |
45 } | 44 } |
46 | 45 |
47 // Stops the source (by calling DoStopSource()). This runs the | 46 // Stops the source (by calling DoStopSource()). This sets the |
48 // |stop_callback_| (if set), and then sets the | 47 // WebMediaStreamSource::readyState to ended, triggers the |stop_callback_| |
49 // WebMediaStreamSource::readyState to ended. | 48 // if set. All pointers to this object are invalid after calling this. |
50 void StopSource(); | 49 void StopSource(); |
51 | 50 |
| 51 void ResetSourceStoppedCallback() { |
| 52 DCHECK(!stop_callback_.is_null()); |
| 53 stop_callback_.Reset(); |
| 54 } |
| 55 |
| 56 protected: |
| 57 // Called when StopSource is called. It allows derived classes to implement |
| 58 // its own Stop method. |
| 59 virtual void DoStopSource() = 0; |
| 60 |
52 // Sets device information about a source that has been created by a | 61 // Sets device information about a source that has been created by a |
53 // JavaScript call to GetUserMedia. F.E a camera or microphone. | 62 // JavaScript call to GetUserMedia. F.E a camera or microphone. |
54 void SetDeviceInfo(const StreamDeviceInfo& device_info); | 63 void SetDeviceInfo(const StreamDeviceInfo& device_info) { |
| 64 device_info_ = device_info; |
| 65 } |
55 | 66 |
56 // Sets a callback that will be triggered when StopSource is called. | 67 // Sets a callback that will be triggered when StopSource is called. |
57 void SetStopCallback(const SourceStoppedCallback& stop_callback); | 68 void SetStopCallback(const SourceStoppedCallback& stop_callback) { |
58 | 69 DCHECK(stop_callback_.is_null()); |
59 // Clears the previously-set SourceStoppedCallback so that it will not be run | 70 stop_callback_ = stop_callback; |
60 // in the future. | 71 } |
61 void ResetSourceStoppedCallback(); | |
62 | |
63 protected: | |
64 // Called when StopSource is called. It allows derived classes to implement | |
65 // its own Stop method. | |
66 virtual void DoStopSource() = 0; | |
67 | 72 |
68 private: | 73 private: |
69 // Called by both StopSource() and the destructor to ensure the | |
70 // |stop_callback_| has been run and the blink::WebMediaStreamSource's ready | |
71 // state has been set to "ended." | |
72 void RunStopCallbackAndEndStream(); | |
73 | |
74 StreamDeviceInfo device_info_; | 74 StreamDeviceInfo device_info_; |
75 SourceStoppedCallback stop_callback_; | 75 SourceStoppedCallback stop_callback_; |
76 | 76 |
77 // In debug builds, check that all methods are being called on the main | |
78 // thread. | |
79 base::ThreadChecker thread_checker_; | |
80 | |
81 DISALLOW_COPY_AND_ASSIGN(MediaStreamSource); | 77 DISALLOW_COPY_AND_ASSIGN(MediaStreamSource); |
82 }; | 78 }; |
83 | 79 |
84 } // namespace content | 80 } // namespace content |
85 | 81 |
86 #endif // CONTENT_RENDERER_MEDIA_MEDIA_STREAM_SOURCE_H_ | 82 #endif // CONTENT_RENDERER_MEDIA_MEDIA_STREAM_SOURCE_H_ |
OLD | NEW |