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