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