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_DESTINATION_HANDLER_H_ 6 #define CONTENT_RENDERER_MEDIA_VIDEO_DESTINATION_HANDLER_H_ 7 8 #include <string> 9 #include <vector> 10 11 #include "base/compiler_specific.h" 12 #include "base/synchronization/lock.h" 13 #include "content/common/content_export.h" 14 #include "third_party/libjingle/source/talk/media/base/videocapturer.h" 15 16 namespace content { 17 18 class MediaStreamDependencyFactory; 19 class MediaStreamRegistryInterface; 20 class PPB_ImageData_Impl; 21 22 // Interface used by the effects pepper plugin to output the processed frame 23 // to the video track. 24 class CONTENT_EXPORT FrameWriterInterface { 25 public: 26 // The ownership of the |image_data| deosn't transfer. So the implementation 27 // of this interface should make a copy of the |image_data| before return. 28 virtual void PutFrame(PPB_ImageData_Impl* image_data, 29 int64 time_stamp_ns) = 0; 30 virtual ~FrameWriterInterface() {} 31 }; 32 33 // PpFrameWriter implements cricket::VideoCapturer so that it can be used in 34 // the native video track's video source. It also implements 35 // FrameWriterInterface, which will be used by the effects pepper plugin to 36 // inject the processed frame. 37 class CONTENT_EXPORT PpFrameWriter 38 : public NON_EXPORTED_BASE(cricket::VideoCapturer), 39 public FrameWriterInterface { 40 public: 41 PpFrameWriter(); 42 virtual ~PpFrameWriter(); 43 44 // cricket::VideoCapturer implementation. 45 // These methods are accessed from a libJingle worker thread. 46 virtual cricket::CaptureState Start( 47 const cricket::VideoFormat& capture_format) OVERRIDE; 48 virtual void Stop() OVERRIDE; 49 virtual bool IsRunning() OVERRIDE; 50 virtual bool GetPreferredFourccs(std::vector<uint32>* fourccs) OVERRIDE; 51 virtual bool GetBestCaptureFormat(const cricket::VideoFormat& desired, 52 cricket::VideoFormat* best_format) OVERRIDE; 53 virtual bool IsScreencast() const OVERRIDE; 54 55 // FrameWriterInterface implementation. 56 // This method will be called by the Pepper host from render thread. 57 virtual void PutFrame(PPB_ImageData_Impl* image_data, 58 int64 time_stamp_ns) OVERRIDE; 59 60 private: 61 bool started_; 62 // |lock_| is used to protect |started_| which will be accessed from different 63 // threads - libjingle worker thread and render thread. 64 base::Lock lock_; 65 66 DISALLOW_COPY_AND_ASSIGN(PpFrameWriter); 67 }; 68 69 // VideoDestinationHandler is a glue class between the webrtc MediaStream and 70 // the effects pepper plugin host. 71 class CONTENT_EXPORT VideoDestinationHandler { 72 public: 73 // Instantiates and adds a new video track to the MediaStream specified by 74 // |url|. Returns a handler for delivering frames to the new video track as 75 // |frame_writer|. 76 // If |factory| is NULL the MediaStreamDependencyFactory owned by 77 // RenderThreadImpl::current() will be used. 78 // If |registry| is NULL the global blink::WebMediaStreamRegistry will be 79 // used to look up the media stream. 80 // The caller of the function takes the ownership of |frame_writer|. 81 // Returns true on success and false on failure. 82 static bool Open(MediaStreamDependencyFactory* factory, 83 MediaStreamRegistryInterface* registry, 84 const std::string& url, 85 FrameWriterInterface** frame_writer); 86 87 private: 88 DISALLOW_COPY_AND_ASSIGN(VideoDestinationHandler); 89 }; 90 91 } // namespace content 92 93 #endif // CONTENT_RENDERER_MEDIA_VIDEO_DESTINATION_HANDLER_H_ 94 95