OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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_VIDEO_TRACK_H_ | 5 #ifndef CONTENT_RENDERER_MEDIA_MEDIA_STREAM_VIDEO_TRACK_H_ |
6 #define CONTENT_RENDERER_MEDIA_MEDIA_STREAM_VIDEO_TRACK_H_ | 6 #define CONTENT_RENDERER_MEDIA_MEDIA_STREAM_VIDEO_TRACK_H_ |
7 | 7 |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
| 11 #include "base/gtest_prod_util.h" |
11 #include "base/memory/scoped_vector.h" | 12 #include "base/memory/scoped_vector.h" |
12 #include "base/threading/thread_checker.h" | 13 #include "base/threading/thread_checker.h" |
13 #include "content/common/content_export.h" | 14 #include "content/common/content_export.h" |
14 #include "content/public/renderer/media_stream_video_sink.h" | 15 #include "content/public/renderer/media_stream_video_sink.h" |
15 #include "content/renderer/media/media_stream_track.h" | 16 #include "content/renderer/media/media_stream_track.h" |
16 #include "content/renderer/media/media_stream_video_source.h" | 17 #include "content/renderer/media/media_stream_video_source.h" |
17 | 18 |
18 namespace content { | 19 namespace content { |
19 | 20 |
20 // MediaStreamVideoTrack is a video specific representation of a | 21 // MediaStreamVideoTrack is a video specific representation of a |
(...skipping 20 matching lines...) Expand all Loading... |
41 const blink::WebMediaStreamTrack& track); | 42 const blink::WebMediaStreamTrack& track); |
42 | 43 |
43 // Constructor for local video tracks. | 44 // Constructor for local video tracks. |
44 MediaStreamVideoTrack( | 45 MediaStreamVideoTrack( |
45 MediaStreamVideoSource* source, | 46 MediaStreamVideoSource* source, |
46 const blink::WebMediaConstraints& constraints, | 47 const blink::WebMediaConstraints& constraints, |
47 const MediaStreamVideoSource::ConstraintsCallback& callback, | 48 const MediaStreamVideoSource::ConstraintsCallback& callback, |
48 bool enabled); | 49 bool enabled); |
49 virtual ~MediaStreamVideoTrack(); | 50 virtual ~MediaStreamVideoTrack(); |
50 | 51 |
51 // Add |sink| to receive state changes and video frames on the main render | |
52 // thread. | |
53 virtual void AddSink(MediaStreamVideoSink* sink); | |
54 virtual void RemoveSink(MediaStreamVideoSink* sink); | |
55 | |
56 // Add |sink| to receive state changes on the main render thread and video | |
57 // frames in the |callback| method on the IO-thread. | |
58 virtual void AddSink(MediaStreamSink* sink, | |
59 const VideoCaptureDeliverFrameCB& callback); | |
60 virtual void RemoveSink(MediaStreamSink* sink); | |
61 | |
62 virtual void SetEnabled(bool enabled) OVERRIDE; | 52 virtual void SetEnabled(bool enabled) OVERRIDE; |
63 virtual void Stop() OVERRIDE; | 53 virtual void Stop() OVERRIDE; |
64 | 54 |
65 void OnReadyStateChanged(blink::WebMediaStreamSource::ReadyState state); | 55 void OnReadyStateChanged(blink::WebMediaStreamSource::ReadyState state); |
66 | 56 |
67 const blink::WebMediaConstraints& constraints() const { | 57 const blink::WebMediaConstraints& constraints() const { |
68 return constraints_; | 58 return constraints_; |
69 } | 59 } |
70 | 60 |
71 protected: | 61 protected: |
72 // Used to DCHECK that we are called on the correct thread. | 62 // Used to DCHECK that we are called on the correct thread. |
73 base::ThreadChecker thread_checker_; | 63 base::ThreadChecker thread_checker_; |
74 | 64 |
75 private: | 65 private: |
| 66 // MediaStreamVideoSink is a friend to allow it to call AddSink() and |
| 67 // RemoveSink(). |
| 68 friend class MediaStreamVideoSink; |
| 69 FRIEND_TEST_ALL_PREFIXES(MediaStreamRemoteVideoSourceTest, StartTrack); |
| 70 FRIEND_TEST_ALL_PREFIXES(MediaStreamRemoteVideoSourceTest, RemoteTrackStop); |
| 71 FRIEND_TEST_ALL_PREFIXES(VideoDestinationHandlerTest, PutFrame); |
| 72 |
| 73 // Add |sink| to receive state changes on the main render thread and video |
| 74 // frames in the |callback| method on the IO-thread. |
| 75 // |callback| will be reset on the render thread. |
| 76 // These two methods are private such that no subclass can intercept and |
| 77 // store the callback. This is important to ensure that we can release |
| 78 // the callback on render thread without reference to it on the IO-thread. |
| 79 void AddSink(MediaStreamVideoSink* sink, |
| 80 const VideoCaptureDeliverFrameCB& callback); |
| 81 void RemoveSink(MediaStreamVideoSink* sink); |
| 82 |
76 // |FrameDeliverer| is an internal helper object used for delivering video | 83 // |FrameDeliverer| is an internal helper object used for delivering video |
77 // frames on the IO-thread using callbacks to all registered tracks. | 84 // frames on the IO-thread using callbacks to all registered tracks. |
78 class FrameDeliverer; | 85 class FrameDeliverer; |
79 scoped_refptr<FrameDeliverer> frame_deliverer_; | 86 scoped_refptr<FrameDeliverer> frame_deliverer_; |
80 | 87 |
81 blink::WebMediaConstraints constraints_; | 88 blink::WebMediaConstraints constraints_; |
82 | 89 |
83 // Weak ref to the source this tracks is connected to. |source_| is owned | 90 // Weak ref to the source this tracks is connected to. |source_| is owned |
84 // by the blink::WebMediaStreamSource and is guaranteed to outlive the | 91 // by the blink::WebMediaStreamSource and is guaranteed to outlive the |
85 // track. | 92 // track. |
86 MediaStreamVideoSource* source_; | 93 MediaStreamVideoSource* source_; |
87 | 94 |
88 DISALLOW_COPY_AND_ASSIGN(MediaStreamVideoTrack); | 95 DISALLOW_COPY_AND_ASSIGN(MediaStreamVideoTrack); |
89 }; | 96 }; |
90 | 97 |
91 } // namespace content | 98 } // namespace content |
92 | 99 |
93 #endif // CONTENT_RENDERER_MEDIA_MEDIA_STREAM_VIDEO_TRACK_H_ | 100 #endif // CONTENT_RENDERER_MEDIA_MEDIA_STREAM_VIDEO_TRACK_H_ |
OLD | NEW |