Home | History | Annotate | Download | only in media
      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.
      4 
      5 #ifndef CONTENT_RENDERER_MEDIA_VIDEO_SOURCE_HANDLER_H_
      6 #define CONTENT_RENDERER_MEDIA_VIDEO_SOURCE_HANDLER_H_
      7 
      8 #include <map>
      9 #include <string>
     10 
     11 #include "base/compiler_specific.h"
     12 #include "base/memory/ref_counted.h"
     13 #include "content/common/content_export.h"
     14 #include "third_party/libjingle/source/talk/app/webrtc/videosourceinterface.h"
     15 
     16 namespace cricket {
     17 class VideoFrame;
     18 }
     19 
     20 namespace content {
     21 
     22 class MediaStreamDependencyFactory;
     23 class MediaStreamRegistryInterface;
     24 
     25 // Interface used by the effects pepper plugin to get captured frame
     26 // from the video track.
     27 class CONTENT_EXPORT FrameReaderInterface {
     28  public:
     29   // Got a new captured frame.
     30   // The ownership of the |frame| is transfered to the caller. So the caller
     31   // must delete |frame| when done with it.
     32   virtual bool GotFrame(cricket::VideoFrame* frame) = 0;
     33 
     34  protected:
     35   virtual ~FrameReaderInterface() {}
     36 };
     37 
     38 // VideoSourceHandler is a glue class between the webrtc MediaStream and
     39 // the effects pepper plugin host.
     40 class CONTENT_EXPORT VideoSourceHandler {
     41  public:
     42   // |registry| is used to look up the media stream by url. If a NULL |registry|
     43   // is given, the global WebKit::WebMediaStreamRegistry will be used.
     44   explicit VideoSourceHandler(MediaStreamRegistryInterface* registry);
     45   virtual ~VideoSourceHandler();
     46   // Connects to the first video track in the MediaStream specified by |url| and
     47   // the received frames will be delivered via |reader|.
     48   // Returns true on success and false on failure.
     49   bool Open(const std::string& url, FrameReaderInterface* reader);
     50   // Closes |reader|'s connection with the first video track in
     51   // the MediaStream specified by |url|, i.e. stops receiving frames from the
     52   // video track.
     53   // Returns true on success and false on failure.
     54   bool Close(const std::string& url, FrameReaderInterface* reader);
     55 
     56   // Gets the VideoRenderer associated with |reader|.
     57   // Made it public only for testing purpose.
     58   cricket::VideoRenderer* GetReceiver(FrameReaderInterface* reader);
     59 
     60  private:
     61   scoped_refptr<webrtc::VideoSourceInterface> GetFirstVideoSource(
     62       const std::string& url);
     63 
     64   MediaStreamRegistryInterface* registry_;
     65   std::map<FrameReaderInterface*, cricket::VideoRenderer*> reader_to_receiver_;
     66 
     67   DISALLOW_COPY_AND_ASSIGN(VideoSourceHandler);
     68 };
     69 
     70 }  // namespace content
     71 
     72 #endif  // CONTENT_RENDERER_MEDIA_VIDEO_SOURCE_HANDLER_H_
     73 
     74