| 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 |
| 30 // Called from the main cast thread. This function post the encode task to the | 32 // Called from the main cast thread. This function post the encode task to the |
| 31 // video encoder thread; | 33 // video encoder thread; |
| 32 // The video_frame must be valid until the closure callback is called. | 34 // The video_frame must be valid until the closure callback is called. |
| 33 // The closure callback is called from the video encoder thread as soon as | 35 // The closure callback is called from the video encoder thread as soon as |
| 34 // the encoder is done with the frame; it does not mean that the encoded frame | 36 // the encoder is done with the frame; it does not mean that the encoded frame |
| 35 // has been sent out. | 37 // has been sent out. |
| 36 // Once the encoded frame is ready the frame_encoded_callback is called. | 38 // Once the encoded frame is ready the frame_encoded_callback is called. |
| 37 bool EncodeVideoFrame(const I420VideoFrame* video_frame, | 39 bool EncodeVideoFrame(const I420VideoFrame* video_frame, |
| 38 const base::TimeTicks& capture_time, | 40 const base::TimeTicks& capture_time, |
| 39 const FrameEncodedCallback& frame_encoded_callback, | 41 const FrameEncodedCallback& frame_encoded_callback, |
| 40 const base::Closure frame_release_callback); | 42 const base::Closure frame_release_callback); |
| 41 | 43 |
| 42 protected: | 44 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 | |
| 69 const VideoSenderConfig video_config_; | 67 const VideoSenderConfig video_config_; |
| 70 scoped_refptr<CastThread> cast_thread_; | 68 scoped_refptr<CastThread> cast_thread_; |
| 71 scoped_ptr<Vp8Encoder> vp8_encoder_; | 69 scoped_ptr<Vp8Encoder> vp8_encoder_; |
| 72 CodecDynamicConfig dynamic_config_; | 70 CodecDynamicConfig dynamic_config_; |
| 73 bool skip_next_frame_; | 71 bool skip_next_frame_; |
| 74 int skip_count_; | 72 int skip_count_; |
| 75 | 73 |
| 76 DISALLOW_COPY_AND_ASSIGN(VideoEncoder); | 74 DISALLOW_COPY_AND_ASSIGN(VideoEncoder); |
| 77 }; | 75 }; |
| 78 | 76 |
| 79 } // namespace cast | 77 } // namespace cast |
| 80 } // namespace media | 78 } // namespace media |
| 81 | 79 |
| 82 #endif // MEDIA_CAST_VIDEO_SENDER_VIDEO_ENCODER_H_ | 80 #endif // MEDIA_CAST_VIDEO_SENDER_VIDEO_ENCODER_H_ |
| OLD | NEW |