| 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" |
| 11 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
| 12 #include "base/memory/weak_ptr.h" |
| 13 #include "base/single_thread_task_runner.h" |
| 12 #include "base/threading/thread_checker.h" | 14 #include "base/threading/thread_checker.h" |
| 13 #include "content/public/common/features.h" | 15 #include "content/public/common/features.h" |
| 14 #include "content/public/renderer/media_stream_video_sink.h" | 16 #include "content/public/renderer/media_stream_video_sink.h" |
| 15 #include "third_party/WebKit/public/platform/WebMediaStreamTrack.h" | 17 #include "third_party/WebKit/public/platform/WebMediaStreamTrack.h" |
| 16 | 18 |
| 19 namespace base { |
| 20 class WaitableEvent; |
| 21 } // namespace base |
| 22 |
| 17 namespace media { | 23 namespace media { |
| 18 class VideoFrame; | 24 class VideoFrame; |
| 19 } // namespace media | 25 } // namespace media |
| 20 | 26 |
| 21 namespace content { | 27 namespace content { |
| 22 | 28 |
| 23 // VideoTrackRecorder is a MediaStreamVideoSink that encodes the video frames | 29 // VideoTrackRecorder is a MediaStreamVideoSink that encodes the video frames |
| 24 // received from a Stream Video Track. This class is constructed and used on a | 30 // received from a Stream Video Track. This class is constructed and used on a |
| 25 // single thread, namely the main Render thread. This mirrors the other | 31 // single thread, namely the main Render thread. This mirrors the other |
| 26 // MediaStreamVideo* classes that are constructed/configured on Main Render | 32 // MediaStreamVideo* classes that are constructed/configured on Main Render |
| (...skipping 22 matching lines...) Expand all Loading... |
| 49 ~VideoTrackRecorder() override; | 55 ~VideoTrackRecorder() override; |
| 50 | 56 |
| 51 void Pause(); | 57 void Pause(); |
| 52 void Resume(); | 58 void Resume(); |
| 53 | 59 |
| 54 void OnVideoFrameForTesting(const scoped_refptr<media::VideoFrame>& frame, | 60 void OnVideoFrameForTesting(const scoped_refptr<media::VideoFrame>& frame, |
| 55 base::TimeTicks capture_time); | 61 base::TimeTicks capture_time); |
| 56 private: | 62 private: |
| 57 friend class VideoTrackRecorderTest; | 63 friend class VideoTrackRecorderTest; |
| 58 | 64 |
| 65 void ReceiveFirstFrameOnIOThread( |
| 66 const scoped_refptr<media::VideoFrame>& frame, |
| 67 base::TimeTicks capture_time); |
| 68 void InitializeEncoderOnMainThread( |
| 69 const scoped_refptr<media::VideoFrame>& frame, |
| 70 base::TimeTicks capture_time, |
| 71 base::WaitableEvent* async_waiter); |
| 72 |
| 59 // Used to check that we are destroyed on the same thread we were created. | 73 // Used to check that we are destroyed on the same thread we were created. |
| 60 base::ThreadChecker main_render_thread_checker_; | 74 base::ThreadChecker main_render_thread_checker_; |
| 61 | 75 |
| 76 // Used to post initialization on the same thread we were created. |
| 77 const scoped_refptr<base::SingleThreadTaskRunner> main_task_runner_; |
| 78 |
| 79 // Task runner where frame encode callbacks must happen. |
| 80 scoped_refptr<base::SingleThreadTaskRunner> origin_task_runner_; |
| 81 |
| 62 // We need to hold on to the Blink track to remove ourselves on dtor. | 82 // We need to hold on to the Blink track to remove ourselves on dtor. |
| 63 blink::WebMediaStreamTrack track_; | 83 blink::WebMediaStreamTrack track_; |
| 64 | 84 |
| 65 // Inner class to encode using whichever codec is configured. | 85 // Inner class to encode using whichever codec is configured. |
| 66 scoped_refptr<Encoder> encoder_; | 86 scoped_refptr<Encoder> encoder_; |
| 67 | 87 |
| 88 // Parameters that would be passed to the underlying |encoder_|. |
| 89 const CodecId codec_; |
| 90 const OnEncodedVideoCB on_encoded_video_callback_; |
| 91 const int32_t bits_per_second_; |
| 92 |
| 93 // Used to track the paused state during the initialization process. |
| 94 bool paused_before_init_; |
| 95 |
| 96 base::WeakPtrFactory<VideoTrackRecorder> weak_ptr_factory_; |
| 97 |
| 68 DISALLOW_COPY_AND_ASSIGN(VideoTrackRecorder); | 98 DISALLOW_COPY_AND_ASSIGN(VideoTrackRecorder); |
| 69 }; | 99 }; |
| 70 | 100 |
| 71 } // namespace content | 101 } // namespace content |
| 72 #endif // CONTENT_RENDERER_MEDIA_VIDEO_TRACK_RECORDER_H_ | 102 #endif // CONTENT_RENDERER_MEDIA_VIDEO_TRACK_RECORDER_H_ |
| OLD | NEW |