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_VIDEO_FRAME_DELIVERER_H_ | 5 #ifndef CONTENT_RENDERER_MEDIA_VIDEO_FRAME_DELIVERER_H_ |
6 #define CONTENT_RENDERER_MEDIA_VIDEO_FRAME_DELIVERER_H_ | 6 #define CONTENT_RENDERER_MEDIA_VIDEO_FRAME_DELIVERER_H_ |
7 | 7 |
8 #include <utility> | 8 #include <utility> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 12 matching lines...) Expand all Loading... |
23 // Its used by MediaStreamVideoTrack and MediaStreamVideoSource. | 23 // Its used by MediaStreamVideoTrack and MediaStreamVideoSource. |
24 class VideoFrameDeliverer | 24 class VideoFrameDeliverer |
25 : public base::RefCountedThreadSafe<VideoFrameDeliverer> { | 25 : public base::RefCountedThreadSafe<VideoFrameDeliverer> { |
26 public: | 26 public: |
27 explicit VideoFrameDeliverer( | 27 explicit VideoFrameDeliverer( |
28 const scoped_refptr<base::MessageLoopProxy>& io_message_loop); | 28 const scoped_refptr<base::MessageLoopProxy>& io_message_loop); |
29 | 29 |
30 // Add |callback| to receive video frames on the IO-thread. | 30 // Add |callback| to receive video frames on the IO-thread. |
31 // Must be called on the main render thread. | 31 // Must be called on the main render thread. |
32 void AddCallback(void* id, const VideoCaptureDeliverFrameCB& callback); | 32 void AddCallback(void* id, const VideoCaptureDeliverFrameCB& callback); |
| 33 |
33 // Removes |callback| associated with |id| from receiving video frames if |id| | 34 // Removes |callback| associated with |id| from receiving video frames if |id| |
34 // has been added. It is ok to call RemoveCallback even if the |id| has not | 35 // has been added. It is ok to call RemoveCallback even if the |id| has not |
35 // been added. | 36 // been added. Note that the added callback will be reset on the main thread. |
36 // Must be called on the main render thread. | 37 // Must be called on the main render thread. |
37 void RemoveCallback(void* id); | 38 void RemoveCallback(void* id); |
38 | 39 |
39 // Triggers all registered callbacks with |frame| and |format| as parameters. | 40 // Triggers all registered callbacks with |frame| and |format| as parameters. |
40 // Must be called on the IO-thread. | 41 // Must be called on the IO-thread. |
41 virtual void DeliverFrameOnIO( | 42 virtual void DeliverFrameOnIO( |
42 const scoped_refptr<media::VideoFrame>& frame, | 43 const scoped_refptr<media::VideoFrame>& frame, |
43 const media::VideoCaptureFormat& format); | 44 const media::VideoCaptureFormat& format); |
44 | 45 |
45 const scoped_refptr<base::MessageLoopProxy>& io_message_loop() const { | 46 const scoped_refptr<base::MessageLoopProxy>& io_message_loop() const { |
46 return io_message_loop_; | 47 return io_message_loop_; |
47 } | 48 } |
48 | 49 |
49 protected: | 50 protected: |
50 void AddCallbackOnIO(void* id, const VideoCaptureDeliverFrameCB& callback); | 51 void AddCallbackOnIO(void* id, const VideoCaptureDeliverFrameCB& callback); |
| 52 |
| 53 // Callback will be removed and then reset on the designated message loop. |
51 // It is ok to call RemoveCallback even if |id| has not been added. | 54 // It is ok to call RemoveCallback even if |id| has not been added. |
52 void RemoveCallbackOnIO(void* id); | 55 void RemoveCallbackOnIO( |
| 56 void* id, const scoped_refptr<base::MessageLoopProxy>& message_loop); |
53 | 57 |
54 protected: | 58 protected: |
55 virtual ~VideoFrameDeliverer(); | 59 virtual ~VideoFrameDeliverer(); |
56 const base::ThreadChecker& thread_checker() const { | 60 const base::ThreadChecker& thread_checker() const { |
57 return thread_checker_; | 61 return thread_checker_; |
58 } | 62 } |
59 | 63 |
60 private: | 64 private: |
61 friend class base::RefCountedThreadSafe<VideoFrameDeliverer>; | 65 friend class base::RefCountedThreadSafe<VideoFrameDeliverer>; |
62 | 66 |
63 // Used to DCHECK that AddCallback and RemoveCallback are called on the main | 67 // Used to DCHECK that AddCallback and RemoveCallback are called on the main |
64 // render thread. | 68 // render thread. |
65 base::ThreadChecker thread_checker_; | 69 base::ThreadChecker thread_checker_; |
66 scoped_refptr<base::MessageLoopProxy> io_message_loop_; | 70 scoped_refptr<base::MessageLoopProxy> io_message_loop_; |
67 | 71 |
68 typedef std::pair<void*, VideoCaptureDeliverFrameCB> VideoIdCallbackPair; | 72 typedef std::pair<void*, VideoCaptureDeliverFrameCB> VideoIdCallbackPair; |
69 std::vector<VideoIdCallbackPair> callbacks_; | 73 std::vector<VideoIdCallbackPair> callbacks_; |
70 | 74 |
71 DISALLOW_COPY_AND_ASSIGN(VideoFrameDeliverer); | 75 DISALLOW_COPY_AND_ASSIGN(VideoFrameDeliverer); |
72 }; | 76 }; |
73 | 77 |
74 } // namespace content | 78 } // namespace content |
75 | 79 |
76 #endif // CONTENT_RENDERER_MEDIA_VIDEO_FRAME_DELIVERER_H_ | 80 #endif // CONTENT_RENDERER_MEDIA_VIDEO_FRAME_DELIVERER_H_ |
OLD | NEW |