Home | History | Annotate | Download | only in media
      1 // Copyright (c) 2012 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_BROWSER_RENDERER_HOST_MEDIA_WEB_CONTENTS_VIDEO_CAPTURE_DEVICE_H_
      6 #define CONTENT_BROWSER_RENDERER_HOST_MEDIA_WEB_CONTENTS_VIDEO_CAPTURE_DEVICE_H_
      7 
      8 #include <string>
      9 
     10 #include "base/memory/scoped_ptr.h"
     11 #include "content/common/content_export.h"
     12 #include "media/video/capture/video_capture_device.h"
     13 
     14 namespace content {
     15 
     16 class RenderWidgetHost;
     17 
     18 // A virtualized VideoCaptureDevice that mirrors the displayed contents of a
     19 // tab (accessed via its associated WebContents instance), producing a stream of
     20 // video frames.
     21 //
     22 // An instance is created by providing a device_id.  The device_id contains the
     23 // routing ID for a RenderViewHost, and from the RenderViewHost instance, a
     24 // reference to its associated WebContents instance is acquired.  From then on,
     25 // WebContentsVideoCaptureDevice will capture from whatever render view is
     26 // currently associated with that WebContents instance.  This allows the
     27 // underlying render view to be swapped out (e.g., due to navigation or
     28 // crashes/reloads), without any interruption in capturing.
     29 class CONTENT_EXPORT WebContentsVideoCaptureDevice
     30     : public media::VideoCaptureDevice {
     31  public:
     32   // Construct from a |device_id| string of the form:
     33   //   "virtual-media-stream://render_process_id:render_view_id", where
     34   // |render_process_id| and |render_view_id| are decimal integers.
     35   // |destroy_cb| is invoked on an outside thread once all outstanding objects
     36   // are completely destroyed -- this will be some time after the
     37   // WebContentsVideoCaptureDevice is itself deleted.
     38   // TODO(miu): Passing a destroy callback suggests needing to revisit the
     39   // design philosophy of an asynchronous DeAllocate().  http://crbug.com/158641
     40   static media::VideoCaptureDevice* Create(const std::string& device_id);
     41 
     42   virtual ~WebContentsVideoCaptureDevice();
     43 
     44   // VideoCaptureDevice implementation.
     45   virtual void Allocate(const media::VideoCaptureCapability& capture_format,
     46                         VideoCaptureDevice::EventHandler* observer) OVERRIDE;
     47   virtual void Start() OVERRIDE;
     48   virtual void Stop() OVERRIDE;
     49   virtual void DeAllocate() OVERRIDE;
     50 
     51   // Note: The following is just a pass-through of the device_id provided to the
     52   // constructor.  It does not change when the content of the page changes
     53   // (e.g., due to navigation), or when the underlying RenderView is
     54   // swapped-out.
     55   virtual const Name& device_name() OVERRIDE;
     56 
     57  private:
     58   class Impl;
     59 
     60   WebContentsVideoCaptureDevice(const Name& name,
     61                                 int render_process_id,
     62                                 int render_view_id);
     63 
     64   Name device_name_;
     65   const scoped_ptr<Impl> impl_;
     66 
     67   DISALLOW_COPY_AND_ASSIGN(WebContentsVideoCaptureDevice);
     68 };
     69 
     70 
     71 }  // namespace content
     72 
     73 #endif  // CONTENT_BROWSER_RENDERER_HOST_MEDIA_WEB_CONTENTS_VIDEO_CAPTURE_DEVICE_H_
     74