Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(174)

Side by Side Diff: content/renderer/media/webrtc/video_destination_handler.h

Issue 212973002: Refactor VideoDestinationHandler to implement MediaStreamVideoSource. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CONTENT_RENDERER_MEDIA_VIDEO_DESTINATION_HANDLER_H_ 5 #ifndef CONTENT_RENDERER_MEDIA_WEBRTC_VIDEO_DESTINATION_HANDLER_H_
6 #define CONTENT_RENDERER_MEDIA_VIDEO_DESTINATION_HANDLER_H_ 6 #define CONTENT_RENDERER_MEDIA_WEBRTC_VIDEO_DESTINATION_HANDLER_H_
7 7
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/compiler_specific.h" 11 #include "base/compiler_specific.h"
12 #include "base/synchronization/lock.h" 12 #include "base/memory/weak_ptr.h"
13 #include "content/common/content_export.h" 13 #include "content/common/content_export.h"
14 #include "third_party/libjingle/source/talk/media/base/videocapturer.h" 14 #include "content/renderer/media/media_stream_video_source.h"
15 #include "media/base/video_frame_pool.h"
15 16
16 namespace content { 17 namespace content {
17 18
18 class MediaStreamDependencyFactory; 19 class MediaStreamDependencyFactory;
19 class MediaStreamRegistryInterface; 20 class MediaStreamRegistryInterface;
20 class PPB_ImageData_Impl; 21 class PPB_ImageData_Impl;
21 22
22 // Interface used by the effects pepper plugin to output the processed frame 23 // Interface used by the effects pepper plugin to output the processed frame
23 // to the video track. 24 // to the video track.
24 class CONTENT_EXPORT FrameWriterInterface { 25 class CONTENT_EXPORT FrameWriterInterface {
25 public: 26 public:
26 // The ownership of the |image_data| deosn't transfer. So the implementation 27 // 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 // of this interface should make a copy of the |image_data| before return.
28 virtual void PutFrame(PPB_ImageData_Impl* image_data, 29 virtual void PutFrame(PPB_ImageData_Impl* image_data,
29 int64 time_stamp_ns) = 0; 30 int64 time_stamp_ns) = 0;
30 virtual ~FrameWriterInterface() {} 31 virtual ~FrameWriterInterface() {}
31 }; 32 };
32 33
33 // PpFrameWriter implements cricket::VideoCapturer so that it can be used in 34 // PpFrameWriter implements MediaStreamVideoSource and can therefore provide
34 // the native video track's video source. It also implements 35 // video frames to MediaStreamVideoTracks. It also implements
35 // FrameWriterInterface, which will be used by the effects pepper plugin to 36 // FrameWriterInterface, which will be used by the effects pepper plugin to
36 // inject the processed frame. 37 // inject the processed frame.
37 class CONTENT_EXPORT PpFrameWriter 38 class CONTENT_EXPORT PpFrameWriter
38 : public NON_EXPORTED_BASE(cricket::VideoCapturer), 39 : NON_EXPORTED_BASE(public MediaStreamVideoSource),
39 public FrameWriterInterface { 40 public FrameWriterInterface,
41 NON_EXPORTED_BASE(public base::SupportsWeakPtr<PpFrameWriter>) {
40 public: 42 public:
41 PpFrameWriter(); 43 explicit PpFrameWriter(MediaStreamDependencyFactory* factory);
42 virtual ~PpFrameWriter(); 44 virtual ~PpFrameWriter();
43 45
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. 46 // FrameWriterInterface implementation.
56 // This method will be called by the Pepper host from render thread. 47 // This method will be called by the Pepper host from render thread.
57 virtual void PutFrame(PPB_ImageData_Impl* image_data, 48 virtual void PutFrame(PPB_ImageData_Impl* image_data,
58 int64 time_stamp_ns) OVERRIDE; 49 int64 time_stamp_ns) OVERRIDE;
50 protected:
51 // MediaStreamVideoSource implementation.
52 virtual void GetCurrentSupportedFormats(int max_requested_width,
53 int max_requested_height) OVERRIDE;
54 virtual void StartSourceImpl(
55 const media::VideoCaptureParams& params) OVERRIDE;
56 virtual void StopSourceImpl() OVERRIDE;
59 57
60 private: 58 private:
61 bool started_; 59 // |format_| is the format currently received by this source.
62 // |lock_| is used to protect |started_| which will be accessed from different 60 media::VideoCaptureFormat format_;
63 // threads - libjingle worker thread and render thread. 61 bool first_frame_received_;
64 base::Lock lock_; 62 media::VideoFramePool frame_pool_;
65 63
66 DISALLOW_COPY_AND_ASSIGN(PpFrameWriter); 64 DISALLOW_COPY_AND_ASSIGN(PpFrameWriter);
67 }; 65 };
68 66
69 // VideoDestinationHandler is a glue class between the webrtc MediaStream and 67 // VideoDestinationHandler is a glue class between the content MediaStream and
70 // the effects pepper plugin host. 68 // the effects pepper plugin host.
71 class CONTENT_EXPORT VideoDestinationHandler { 69 class CONTENT_EXPORT VideoDestinationHandler {
72 public: 70 public:
73 // Instantiates and adds a new video track to the MediaStream specified by 71 // 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 72 // |url|. Returns a handler for delivering frames to the new video track as
75 // |frame_writer|. 73 // |frame_writer|.
76 // If |factory| is NULL the MediaStreamDependencyFactory owned by 74 // If |factory| is NULL the MediaStreamDependencyFactory owned by
77 // RenderThreadImpl::current() will be used. 75 // RenderThreadImpl::current() will be used.
78 // If |registry| is NULL the global blink::WebMediaStreamRegistry will be 76 // If |registry| is NULL the global blink::WebMediaStreamRegistry will be
79 // used to look up the media stream. 77 // used to look up the media stream.
80 // The caller of the function takes the ownership of |frame_writer|. 78 // The caller of the function takes the ownership of |frame_writer|.
81 // Returns true on success and false on failure. 79 // Returns true on success and false on failure.
82 static bool Open(MediaStreamDependencyFactory* factory, 80 static bool Open(MediaStreamDependencyFactory* factory,
83 MediaStreamRegistryInterface* registry, 81 MediaStreamRegistryInterface* registry,
84 const std::string& url, 82 const std::string& url,
85 FrameWriterInterface** frame_writer); 83 FrameWriterInterface** frame_writer);
86 84
87 private: 85 private:
88 DISALLOW_COPY_AND_ASSIGN(VideoDestinationHandler); 86 DISALLOW_COPY_AND_ASSIGN(VideoDestinationHandler);
89 }; 87 };
90 88
91 } // namespace content 89 } // namespace content
92 90
93 #endif // CONTENT_RENDERER_MEDIA_VIDEO_DESTINATION_HANDLER_H_ 91 #endif // CONTENT_RENDERER_MEDIA_VIDEO_DESTINATION_HANDLER_H_
94 92
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698