1 // Copyright 2015 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_MEDIA_VIDEO_TRACK_RECORDER_H_
6 #define CONTENT_RENDERER_MEDIA_VIDEO_TRACK_RECORDER_H_
8 #include "base/macros.h"
9 #include "base/memory/ref_counted.h"
10 #include "base/strings/string_piece.h"
11 #include "base/threading/thread_checker.h"
12 #include "content/public/renderer/media_stream_video_sink.h"
13 #include "third_party/WebKit/public/platform/WebMediaStreamTrack.h"
14 #include "ui/gfx/geometry/size.h"
22 // VideoTrackRecorder is a MediaStreamVideoSink that encodes the video frames
23 // received from a Stream Video Track. The class is constructed and used on a
24 // single thread, namely the main Render thread. It has an internal VpxEncoder
25 // with its own threading subtleties, see the implementation file. This mirrors
26 // the other MediaStreamVideo* classes that are constructed/configured on Main
27 // Render thread but that pass frames on Render IO thread.
28 class CONTENT_EXPORT VideoTrackRecorder
29 : NON_EXPORTED_BASE(public MediaStreamVideoSink
) {
31 using OnEncodedVideoCB
=
32 base::Callback
<void(const scoped_refptr
<media::VideoFrame
>& video_frame
,
33 const base::StringPiece
& encoded_data
,
34 base::TimeTicks capture_timestamp
,
37 VideoTrackRecorder(const blink::WebMediaStreamTrack
& track
,
38 const OnEncodedVideoCB
& on_encoded_video_cb
);
39 ~VideoTrackRecorder() override
;
41 void OnVideoFrameForTesting(const scoped_refptr
<media::VideoFrame
>& frame
,
42 base::TimeTicks capture_time
);
45 friend class VideoTrackRecorderTest
;
47 // Used to check that we are destroyed on the same thread we were created.
48 base::ThreadChecker main_render_thread_checker_
;
50 // We need to hold on to the Blink track to remove ourselves on dtor.
51 blink::WebMediaStreamTrack track_
;
53 // Forward declaration and member of an inner class to encode using VPx.
55 const scoped_refptr
<VpxEncoder
> encoder_
;
57 DISALLOW_COPY_AND_ASSIGN(VideoTrackRecorder
);
60 } // namespace content
61 #endif // CONTENT_RENDERER_MEDIA_VIDEO_TRACK_RECORDER_H_