1 // Copyright 2014 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.
5 #ifndef CONTENT_RENDERER_PEPPER_PEPPER_MEDIA_STREAM_VIDEO_TRACK_HOST_H_
6 #define CONTENT_RENDERER_PEPPER_PEPPER_MEDIA_STREAM_VIDEO_TRACK_HOST_H_
8 #include "base/compiler_specific.h"
9 #include "base/memory/weak_ptr.h"
10 #include "content/public/renderer/media_stream_video_sink.h"
11 #include "content/renderer/media/media_stream_video_source.h"
12 #include "content/renderer/pepper/pepper_media_stream_track_host_base.h"
13 #include "media/base/video_frame.h"
14 #include "ppapi/c/ppb_video_frame.h"
15 #include "ppapi/shared_impl/media_stream_video_track_shared.h"
16 #include "third_party/WebKit/public/platform/WebMediaStreamTrack.h"
17 #include "ui/gfx/geometry/size.h"
21 class PepperMediaStreamVideoTrackHost
: public PepperMediaStreamTrackHostBase
,
22 public MediaStreamVideoSink
,
23 public MediaStreamVideoSource
{
25 // Input mode constructor.
26 // In input mode, this class passes video frames from |track| to the
27 // associated pepper plugin.
28 PepperMediaStreamVideoTrackHost(RendererPpapiHost
* host
,
31 const blink::WebMediaStreamTrack
& track
);
33 // Output mode constructor.
34 // In output mode, this class passes video frames from the associated
35 // pepper plugin to a newly created blink::WebMediaStreamTrack.
36 PepperMediaStreamVideoTrackHost(RendererPpapiHost
* host
,
38 PP_Resource resource
);
40 bool IsMediaStreamVideoTrackHost() override
;
42 blink::WebMediaStreamTrack
track() { return track_
; }
46 virtual ~PepperMediaStreamVideoTrackHost();
50 // PepperMediaStreamTrackHostBase overrides:
51 void OnClose() override
;
52 int32_t OnHostMsgEnqueueBuffer(ppapi::host::HostMessageContext
* context
,
53 int32_t index
) override
;
55 // Sends frame with |index| to |track_|.
56 int32_t SendFrameToTrack(int32_t index
);
58 void OnVideoFrame(const scoped_refptr
<media::VideoFrame
>& frame
,
59 const base::TimeTicks
& estimated_capture_time
);
61 // MediaStreamVideoSource overrides:
62 void GetCurrentSupportedFormats(
63 int max_requested_width
,
64 int max_requested_height
,
65 double max_requested_frame_rate
,
66 const VideoCaptureDeviceFormatsCB
& callback
) override
;
69 const media::VideoCaptureFormat
& format
,
70 const VideoCaptureDeliverFrameCB
& frame_callback
) override
;
72 void StopSourceImpl() override
;
74 // ResourceHost overrides:
75 void DidConnectPendingHostToResource() override
;
77 // ResourceMessageHandler overrides:
78 int32_t OnResourceMessageReceived(
79 const IPC::Message
& msg
,
80 ppapi::host::HostMessageContext
* context
) override
;
83 int32_t OnHostMsgConfigure(
84 ppapi::host::HostMessageContext
* context
,
85 const ppapi::MediaStreamVideoTrackShared::Attributes
& attributes
);
87 void InitBlinkTrack();
88 void OnTrackStarted(MediaStreamSource
* source
,
89 MediaStreamRequestResult result
,
90 const blink::WebString
& result_name
);
92 blink::WebMediaStreamTrack track_
;
94 // True if it has been added to |blink::WebMediaStreamTrack| as a sink.
98 int32_t number_of_buffers_
;
100 // Size of frames which are received from MediaStreamVideoSink.
101 gfx::Size source_frame_size_
;
103 // Plugin specified frame size.
104 gfx::Size plugin_frame_size_
;
106 // Format of frames which are received from MediaStreamVideoSink.
107 PP_VideoFrame_Format source_frame_format_
;
109 // Plugin specified frame format.
110 PP_VideoFrame_Format plugin_frame_format_
;
112 // The size of frame pixels in bytes.
113 uint32_t frame_data_size_
;
115 // TODO(ronghuawu): Remove |type_| and split PepperMediaStreamVideoTrackHost
116 // into 2 classes for read and write.
118 bool output_started_
;
120 // Internal class used for delivering video frames on the IO-thread to
121 // the MediaStreamVideoSource implementation.
122 class FrameDeliverer
;
123 scoped_refptr
<FrameDeliverer
> frame_deliverer_
;
125 base::WeakPtrFactory
<PepperMediaStreamVideoTrackHost
> weak_factory_
;
127 DISALLOW_COPY_AND_ASSIGN(PepperMediaStreamVideoTrackHost
);
130 } // namespace content
132 #endif // CONTENT_RENDERER_PEPPER_PEPPER_MEDIA_STREAM_VIDEO_TRACK_HOST_H_