| 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 <memory> | 8 #include <memory> |
| 9 | 9 |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 | 21 |
| 22 // VideoTrackRecorder is a MediaStreamVideoSink that encodes the video frames | 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 | 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 | 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 | 25 // with its own threading subtleties, see the implementation file. This mirrors |
| 26 // the other MediaStreamVideo* classes that are constructed/configured on Main | 26 // the other MediaStreamVideo* classes that are constructed/configured on Main |
| 27 // Render thread but that pass frames on Render IO thread. | 27 // Render thread but that pass frames on Render IO thread. |
| 28 class CONTENT_EXPORT VideoTrackRecorder | 28 class CONTENT_EXPORT VideoTrackRecorder |
| 29 : NON_EXPORTED_BASE(public MediaStreamVideoSink) { | 29 : NON_EXPORTED_BASE(public MediaStreamVideoSink) { |
| 30 public: | 30 public: |
| 31 enum class CodecId { |
| 32 VP8, |
| 33 VP9, |
| 34 }; |
| 35 |
| 31 using OnEncodedVideoCB = | 36 using OnEncodedVideoCB = |
| 32 base::Callback<void(const scoped_refptr<media::VideoFrame>& video_frame, | 37 base::Callback<void(const scoped_refptr<media::VideoFrame>& video_frame, |
| 33 std::unique_ptr<std::string> encoded_data, | 38 std::unique_ptr<std::string> encoded_data, |
| 34 base::TimeTicks capture_timestamp, | 39 base::TimeTicks capture_timestamp, |
| 35 bool is_key_frame)>; | 40 bool is_key_frame)>; |
| 36 | 41 |
| 37 // |use_vp9| forces using VP9, otherwise VP8 will be used by default. | 42 VideoTrackRecorder(CodecId codec, |
| 38 VideoTrackRecorder(bool use_vp9, | |
| 39 const blink::WebMediaStreamTrack& track, | 43 const blink::WebMediaStreamTrack& track, |
| 40 const OnEncodedVideoCB& on_encoded_video_cb, | 44 const OnEncodedVideoCB& on_encoded_video_cb, |
| 41 int32_t bits_per_second); | 45 int32_t bits_per_second); |
| 42 ~VideoTrackRecorder() override; | 46 ~VideoTrackRecorder() override; |
| 43 | 47 |
| 44 void Pause(); | 48 void Pause(); |
| 45 void Resume(); | 49 void Resume(); |
| 46 | 50 |
| 47 void OnVideoFrameForTesting(const scoped_refptr<media::VideoFrame>& frame, | 51 void OnVideoFrameForTesting(const scoped_refptr<media::VideoFrame>& frame, |
| 48 base::TimeTicks capture_time); | 52 base::TimeTicks capture_time); |
| 49 private: | 53 private: |
| 50 friend class VideoTrackRecorderTest; | 54 friend class VideoTrackRecorderTest; |
| 51 | 55 |
| 52 // Used to check that we are destroyed on the same thread we were created. | 56 // Used to check that we are destroyed on the same thread we were created. |
| 53 base::ThreadChecker main_render_thread_checker_; | 57 base::ThreadChecker main_render_thread_checker_; |
| 54 | 58 |
| 55 // We need to hold on to the Blink track to remove ourselves on dtor. | 59 // We need to hold on to the Blink track to remove ourselves on dtor. |
| 56 blink::WebMediaStreamTrack track_; | 60 blink::WebMediaStreamTrack track_; |
| 57 | 61 |
| 58 // Forward declaration and member of an inner class to encode using VPx. | 62 // Inner class to encode using whichever codec is configured. |
| 59 class VpxEncoder; | 63 class VpxEncoder; |
| 60 const scoped_refptr<VpxEncoder> encoder_; | 64 const scoped_refptr<VpxEncoder> encoder_; |
| 61 | 65 |
| 62 DISALLOW_COPY_AND_ASSIGN(VideoTrackRecorder); | 66 DISALLOW_COPY_AND_ASSIGN(VideoTrackRecorder); |
| 63 }; | 67 }; |
| 64 | 68 |
| 65 } // namespace content | 69 } // namespace content |
| 66 #endif // CONTENT_RENDERER_MEDIA_VIDEO_TRACK_RECORDER_H_ | 70 #endif // CONTENT_RENDERER_MEDIA_VIDEO_TRACK_RECORDER_H_ |
| OLD | NEW |