aw: Ensure fallback tick unsets |block_invalidates_|
[chromium-blink-merge.git] / content / renderer / media / video_source_handler.h
blobead167a0a5b6e7100740487a202ccac63c3e9f07
1 // Copyright (c) 2013 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.
5 #ifndef CONTENT_RENDERER_MEDIA_VIDEO_SOURCE_HANDLER_H_
6 #define CONTENT_RENDERER_MEDIA_VIDEO_SOURCE_HANDLER_H_
8 #include <map>
9 #include <string>
11 #include "base/compiler_specific.h"
12 #include "base/gtest_prod_util.h"
13 #include "base/memory/ref_counted.h"
14 #include "base/memory/scoped_ptr.h"
15 #include "base/threading/thread_checker.h"
16 #include "content/common/content_export.h"
17 #include "media/base/video_frame.h"
18 #include "third_party/WebKit/public/platform/WebMediaStreamTrack.h"
20 namespace content {
22 class MediaStreamRegistryInterface;
23 class MediaStreamVideoSink;
24 class PpFrameReceiver;
26 // Interface used by the effects pepper plugin to get captured frame
27 // from the video track.
28 class CONTENT_EXPORT FrameReaderInterface {
29 public:
30 // Got a new captured frame.
31 virtual bool GotFrame(const scoped_refptr<media::VideoFrame>& frame) = 0;
33 protected:
34 virtual ~FrameReaderInterface() {}
37 // VideoSourceHandler is a glue class between MediaStreamVideoTrack and
38 // the effects pepper plugin host.
39 class CONTENT_EXPORT VideoSourceHandler {
40 public:
41 // |registry| is used to look up the media stream by url. If a NULL |registry|
42 // is given, the global blink::WebMediaStreamRegistry will be used.
43 explicit VideoSourceHandler(MediaStreamRegistryInterface* registry);
44 virtual ~VideoSourceHandler();
45 // Connects to the first video track in the MediaStream specified by |url| and
46 // the received frames will be delivered via |reader|.
47 // Returns true on success and false on failure.
48 bool Open(const std::string& url, FrameReaderInterface* reader);
49 // Closes |reader|'s connection with the video track, i.e. stops receiving
50 // frames from the video track.
51 // Returns true on success and false on failure.
52 bool Close(FrameReaderInterface* reader);
54 private:
55 FRIEND_TEST_ALL_PREFIXES(VideoSourceHandlerTest, OpenClose);
57 struct SourceInfo {
58 SourceInfo(const blink::WebMediaStreamTrack& blink_track,
59 FrameReaderInterface* reader);
60 ~SourceInfo();
62 scoped_ptr<PpFrameReceiver> receiver_;
65 typedef std::map<FrameReaderInterface*, SourceInfo*> SourceInfoMap;
67 // Deliver VideoFrame to the MediaStreamVideoSink associated with
68 // |reader|. For testing only.
69 void DeliverFrameForTesting(FrameReaderInterface* reader,
70 const scoped_refptr<media::VideoFrame>& frame);
72 blink::WebMediaStreamTrack GetFirstVideoTrack(const std::string& url);
74 MediaStreamRegistryInterface* registry_;
75 SourceInfoMap reader_to_receiver_;
77 base::ThreadChecker thread_checker_;
79 DISALLOW_COPY_AND_ASSIGN(VideoSourceHandler);
82 } // namespace content
84 #endif // CONTENT_RENDERER_MEDIA_VIDEO_SOURCE_HANDLER_H_