OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 MEDIA_CAST_VIDEO_SENDER_VIDEO_ENCODER_H_ | 5 #ifndef MEDIA_CAST_VIDEO_SENDER_VIDEO_ENCODER_H_ |
6 #define MEDIA_CAST_VIDEO_SENDER_VIDEO_ENCODER_H_ | 6 #define MEDIA_CAST_VIDEO_SENDER_VIDEO_ENCODER_H_ |
7 | 7 |
8 #include "base/memory/ref_counted.h" | 8 #include "base/memory/ref_counted.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
11 #include "media/cast/cast_config.h" | 11 #include "media/cast/cast_config.h" |
12 #include "media/cast/cast_thread.h" | 12 #include "media/cast/cast_thread.h" |
13 #include "media/cast/video_sender/codecs/vp8/vp8_encoder.h" | 13 #include "media/cast/video_sender/codecs/vp8/vp8_encoder.h" |
14 | 14 |
15 namespace media { | 15 namespace media { |
16 namespace cast { | 16 namespace cast { |
17 | 17 |
18 // This object is called external from the main cast thread and internally from | 18 // This object is called external from the main cast thread and internally from |
19 // the video encoder thread. | 19 // the video encoder thread. |
20 class VideoEncoder : public VideoEncoderController, | 20 class VideoEncoder : public VideoEncoderController, |
21 public base::RefCountedThreadSafe<VideoEncoder> { | 21 public base::RefCountedThreadSafe<VideoEncoder> { |
22 public: | 22 public: |
23 typedef base::Callback<void(scoped_ptr<EncodedVideoFrame>, | 23 typedef base::Callback<void(scoped_ptr<EncodedVideoFrame>, |
24 const base::TimeTicks&)> FrameEncodedCallback; | 24 const base::TimeTicks&)> FrameEncodedCallback; |
25 | 25 |
26 VideoEncoder(scoped_refptr<CastThread> cast_thread, | 26 VideoEncoder(scoped_refptr<CastThread> cast_thread, |
27 const VideoSenderConfig& video_config, | 27 const VideoSenderConfig& video_config, |
28 uint8 max_unacked_frames); | 28 uint8 max_unacked_frames); |
29 | 29 |
30 virtual ~VideoEncoder(); | |
31 | |
32 // Called from the main cast thread. This function post the encode task to the | 30 // Called from the main cast thread. This function post the encode task to the |
33 // video encoder thread; | 31 // video encoder thread; |
34 // The video_frame must be valid until the closure callback is called. | 32 // The video_frame must be valid until the closure callback is called. |
35 // The closure callback is called from the video encoder thread as soon as | 33 // The closure callback is called from the video encoder thread as soon as |
36 // the encoder is done with the frame; it does not mean that the encoded frame | 34 // the encoder is done with the frame; it does not mean that the encoded frame |
37 // has been sent out. | 35 // has been sent out. |
38 // Once the encoded frame is ready the frame_encoded_callback is called. | 36 // Once the encoded frame is ready the frame_encoded_callback is called. |
39 bool EncodeVideoFrame(const I420VideoFrame* video_frame, | 37 bool EncodeVideoFrame(const I420VideoFrame* video_frame, |
40 const base::TimeTicks& capture_time, | 38 const base::TimeTicks& capture_time, |
41 const FrameEncodedCallback& frame_encoded_callback, | 39 const FrameEncodedCallback& frame_encoded_callback, |
42 const base::Closure frame_release_callback); | 40 const base::Closure frame_release_callback); |
43 | 41 |
44 protected: | 42 protected: |
| 43 virtual ~VideoEncoder(); |
| 44 |
45 struct CodecDynamicConfig { | 45 struct CodecDynamicConfig { |
46 bool key_frame_requested; | 46 bool key_frame_requested; |
47 uint8 latest_frame_id_to_reference; | 47 uint8 latest_frame_id_to_reference; |
48 int bit_rate; | 48 int bit_rate; |
49 }; | 49 }; |
50 | 50 |
51 // The actual encode, called from the video encoder thread. | 51 // The actual encode, called from the video encoder thread. |
52 void EncodeVideoFrameEncoderThread( | 52 void EncodeVideoFrameEncoderThread( |
53 const I420VideoFrame* video_frame, | 53 const I420VideoFrame* video_frame, |
54 const base::TimeTicks& capture_time, | 54 const base::TimeTicks& capture_time, |
55 const CodecDynamicConfig& dynamic_config, | 55 const CodecDynamicConfig& dynamic_config, |
56 const FrameEncodedCallback& frame_encoded_callback, | 56 const FrameEncodedCallback& frame_encoded_callback, |
57 const base::Closure frame_release_callback); | 57 const base::Closure frame_release_callback); |
58 | 58 |
59 // The following functions are called from the main cast thread. | 59 // The following functions are called from the main cast thread. |
60 virtual void SetBitRate(int new_bit_rate) OVERRIDE; | 60 virtual void SetBitRate(int new_bit_rate) OVERRIDE; |
61 virtual void SkipNextFrame(bool skip_next_frame) OVERRIDE; | 61 virtual void SkipNextFrame(bool skip_next_frame) OVERRIDE; |
62 virtual void GenerateKeyFrame() OVERRIDE; | 62 virtual void GenerateKeyFrame() OVERRIDE; |
63 virtual void LatestFrameIdToReference(uint8 frame_id) OVERRIDE; | 63 virtual void LatestFrameIdToReference(uint8 frame_id) OVERRIDE; |
64 virtual int NumberOfSkippedFrames() const OVERRIDE; | 64 virtual int NumberOfSkippedFrames() const OVERRIDE; |
65 | 65 |
66 private: | 66 private: |
| 67 friend class base::RefCountedThreadSafe<VideoEncoder>; |
| 68 |
67 const VideoSenderConfig video_config_; | 69 const VideoSenderConfig video_config_; |
68 scoped_refptr<CastThread> cast_thread_; | 70 scoped_refptr<CastThread> cast_thread_; |
69 scoped_ptr<Vp8Encoder> vp8_encoder_; | 71 scoped_ptr<Vp8Encoder> vp8_encoder_; |
70 CodecDynamicConfig dynamic_config_; | 72 CodecDynamicConfig dynamic_config_; |
71 bool skip_next_frame_; | 73 bool skip_next_frame_; |
72 int skip_count_; | 74 int skip_count_; |
73 | 75 |
74 DISALLOW_COPY_AND_ASSIGN(VideoEncoder); | 76 DISALLOW_COPY_AND_ASSIGN(VideoEncoder); |
75 }; | 77 }; |
76 | 78 |
77 } // namespace cast | 79 } // namespace cast |
78 } // namespace media | 80 } // namespace media |
79 | 81 |
80 #endif // MEDIA_CAST_VIDEO_SENDER_VIDEO_ENCODER_H_ | 82 #endif // MEDIA_CAST_VIDEO_SENDER_VIDEO_ENCODER_H_ |
OLD | NEW |