Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / content / renderer / media / video_track_to_pepper_adapter.h
blob424c9011e1be528eedb1fc0b5879031f35086afa
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/memory/ref_counted.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "base/threading/thread_checker.h"
14 #include "content/common/content_export.h"
15 #include "media/base/video_frame.h"
16 #include "third_party/WebKit/public/platform/WebMediaStreamTrack.h"
18 namespace content {
20 class MediaStreamRegistryInterface;
21 class PpFrameReceiver;
23 // Interface used by a Pepper plugin to get captured frames from a video track.
24 class CONTENT_EXPORT FrameReaderInterface {
25 public:
26 // Got a new captured frame.
27 virtual void GotFrame(const scoped_refptr<media::VideoFrame>& frame) = 0;
29 protected:
30 virtual ~FrameReaderInterface() {}
33 // VideoTrackToPepperAdapter is a glue class between MediaStreamVideoTrack and a
34 // Pepper plugin host.
35 class CONTENT_EXPORT VideoTrackToPepperAdapter {
36 public:
37 // |registry| is used to look up the media stream by url. If a NULL |registry|
38 // is given, the global blink::WebMediaStreamRegistry will be used.
39 explicit VideoTrackToPepperAdapter(MediaStreamRegistryInterface* registry);
40 virtual ~VideoTrackToPepperAdapter();
41 // Connects to the first video track in the MediaStream specified by |url| and
42 // the received frames will be delivered via |reader|.
43 // Returns true on success and false on failure.
44 bool Open(const std::string& url, FrameReaderInterface* reader);
45 // Closes |reader|'s connection with the video track, i.e. stops receiving
46 // frames from the video track.
47 // Returns true on success and false on failure.
48 bool Close(FrameReaderInterface* reader);
50 private:
51 friend class VideoTrackToPepperAdapterTest;
53 struct SourceInfo {
54 SourceInfo(const blink::WebMediaStreamTrack& blink_track,
55 FrameReaderInterface* reader);
56 ~SourceInfo();
58 scoped_ptr<PpFrameReceiver> receiver_;
61 typedef std::map<FrameReaderInterface*, SourceInfo*> SourceInfoMap;
63 blink::WebMediaStreamTrack GetFirstVideoTrack(const std::string& url);
65 // Deliver VideoFrame to the MediaStreamVideoSink associated with
66 // |reader|. For testing only.
67 void DeliverFrameForTesting(FrameReaderInterface* reader,
68 const scoped_refptr<media::VideoFrame>& frame);
70 MediaStreamRegistryInterface* const registry_;
71 SourceInfoMap reader_to_receiver_;
73 base::ThreadChecker thread_checker_;
75 DISALLOW_COPY_AND_ASSIGN(VideoTrackToPepperAdapter);
78 } // namespace content
80 #endif // CONTENT_RENDERER_MEDIA_VIDEO_SOURCE_HANDLER_H_