Home | History | Annotate | Download | only in webrtc
      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_WEBRTC_VIDEO_DESTINATION_HANDLER_H_
      6 #define CONTENT_RENDERER_MEDIA_WEBRTC_VIDEO_DESTINATION_HANDLER_H_
      7 
      8 #include <string>
      9 #include <vector>
     10 
     11 #include "base/compiler_specific.h"
     12 #include "base/memory/weak_ptr.h"
     13 #include "content/common/content_export.h"
     14 #include "content/renderer/media/media_stream_video_source.h"
     15 #include "media/base/video_frame_pool.h"
     16 
     17 namespace content {
     18 
     19 class PeerConnectionDependencyFactory;
     20 class MediaStreamRegistryInterface;
     21 class PPB_ImageData_Impl;
     22 
     23 // Interface used by the effects pepper plugin to output the processed frame
     24 // to the video track.
     25 class CONTENT_EXPORT FrameWriterInterface {
     26  public:
     27   // The ownership of the |image_data| deosn't transfer. So the implementation
     28   // of this interface should make a copy of the |image_data| before return.
     29   virtual void PutFrame(PPB_ImageData_Impl* image_data,
     30                         int64 time_stamp_ns) = 0;
     31   virtual ~FrameWriterInterface() {}
     32 };
     33 
     34 // PpFrameWriter implements MediaStreamVideoSource and can therefore provide
     35 // video frames to MediaStreamVideoTracks. It also implements
     36 // FrameWriterInterface, which will be used by the effects pepper plugin to
     37 // inject the processed frame.
     38 class CONTENT_EXPORT PpFrameWriter
     39     : NON_EXPORTED_BASE(public MediaStreamVideoSource),
     40       public FrameWriterInterface,
     41       NON_EXPORTED_BASE(public base::SupportsWeakPtr<PpFrameWriter>) {
     42  public:
     43   PpFrameWriter();
     44   virtual ~PpFrameWriter();
     45 
     46   // FrameWriterInterface implementation.
     47   // This method will be called by the Pepper host from render thread.
     48   virtual void PutFrame(PPB_ImageData_Impl* image_data,
     49                         int64 time_stamp_ns) OVERRIDE;
     50  protected:
     51   // MediaStreamVideoSource implementation.
     52   virtual void GetCurrentSupportedFormats(
     53       int max_requested_width,
     54       int max_requested_height,
     55       const VideoCaptureDeviceFormatsCB& callback) OVERRIDE;
     56   virtual void StartSourceImpl(
     57       const media::VideoCaptureParams& params,
     58       const VideoCaptureDeliverFrameCB& frame_callback) OVERRIDE;
     59   virtual void StopSourceImpl() OVERRIDE;
     60 
     61  private:
     62   media::VideoFramePool frame_pool_;
     63 
     64   class FrameWriterDelegate;
     65   scoped_refptr<FrameWriterDelegate> delegate_;
     66 
     67   DISALLOW_COPY_AND_ASSIGN(PpFrameWriter);
     68 };
     69 
     70 // VideoDestinationHandler is a glue class between the content MediaStream and
     71 // the effects pepper plugin host.
     72 class CONTENT_EXPORT VideoDestinationHandler {
     73  public:
     74   // Instantiates and adds a new video track to the MediaStream specified by
     75   // |url|. Returns a handler for delivering frames to the new video track as
     76   // |frame_writer|.
     77   // If |registry| is NULL the global blink::WebMediaStreamRegistry will be
     78   // used to look up the media stream.
     79   // The caller of the function takes the ownership of |frame_writer|.
     80   // Returns true on success and false on failure.
     81   static bool Open(MediaStreamRegistryInterface* registry,
     82                    const std::string& url,
     83                    FrameWriterInterface** frame_writer);
     84 
     85  private:
     86   DISALLOW_COPY_AND_ASSIGN(VideoDestinationHandler);
     87 };
     88 
     89 }  // namespace content
     90 
     91 #endif  // CONTENT_RENDERER_MEDIA_VIDEO_DESTINATION_HANDLER_H_
     92 
     93