OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_SENDER_EXTERNAL_VIDEO_ENCODER_H_ | 5 #ifndef MEDIA_CAST_SENDER_EXTERNAL_VIDEO_ENCODER_H_ |
6 #define MEDIA_CAST_SENDER_EXTERNAL_VIDEO_ENCODER_H_ | 6 #define MEDIA_CAST_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 "media/cast/cast_config.h" | 10 #include "media/cast/cast_config.h" |
(...skipping 10 matching lines...) Expand all Loading... |
21 | 21 |
22 class LocalVideoEncodeAcceleratorClient; | 22 class LocalVideoEncodeAcceleratorClient; |
23 | 23 |
24 // 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 |
25 // the video encoder thread. | 25 // the video encoder thread. |
26 class ExternalVideoEncoder : public VideoEncoder { | 26 class ExternalVideoEncoder : public VideoEncoder { |
27 public: | 27 public: |
28 ExternalVideoEncoder( | 28 ExternalVideoEncoder( |
29 scoped_refptr<CastEnvironment> cast_environment, | 29 scoped_refptr<CastEnvironment> cast_environment, |
30 const VideoSenderConfig& video_config, | 30 const VideoSenderConfig& video_config, |
| 31 const CastInitializationCallback& initialization_cb, |
31 const CreateVideoEncodeAcceleratorCallback& create_vea_cb, | 32 const CreateVideoEncodeAcceleratorCallback& create_vea_cb, |
32 const CreateVideoEncodeMemoryCallback& create_video_encode_mem_cb); | 33 const CreateVideoEncodeMemoryCallback& create_video_encode_mem_cb); |
33 | 34 |
34 virtual ~ExternalVideoEncoder(); | 35 virtual ~ExternalVideoEncoder(); |
35 | 36 |
36 // Called from the main cast thread. This function post the encode task to the | 37 // Called from the main cast thread. This function post the encode task to the |
37 // video encoder thread; | 38 // video encoder thread; |
38 // The video_frame must be valid until the closure callback is called. | 39 // The video_frame must be valid until the closure callback is called. |
39 // The closure callback is called from the video encoder thread as soon as | 40 // The closure callback is called from the video encoder thread as soon as |
40 // the encoder is done with the frame; it does not mean that the encoded frame | 41 // the encoder is done with the frame; it does not mean that the encoded frame |
41 // has been sent out. | 42 // has been sent out. |
42 // Once the encoded frame is ready the frame_encoded_callback is called. | 43 // Once the encoded frame is ready the frame_encoded_callback is called. |
43 virtual bool EncodeVideoFrame( | 44 virtual bool EncodeVideoFrame( |
44 const scoped_refptr<media::VideoFrame>& video_frame, | 45 const scoped_refptr<media::VideoFrame>& video_frame, |
45 const base::TimeTicks& capture_time, | 46 const base::TimeTicks& capture_time, |
46 const FrameEncodedCallback& frame_encoded_callback) OVERRIDE; | 47 const FrameEncodedCallback& frame_encoded_callback) OVERRIDE; |
47 | 48 |
48 // The following functions are called from the main cast thread. | 49 // The following functions are called from the main cast thread. |
49 virtual void SetBitRate(int new_bit_rate) OVERRIDE; | 50 virtual void SetBitRate(int new_bit_rate) OVERRIDE; |
50 virtual void GenerateKeyFrame() OVERRIDE; | 51 virtual void GenerateKeyFrame() OVERRIDE; |
51 virtual void LatestFrameIdToReference(uint32 frame_id) OVERRIDE; | 52 virtual void LatestFrameIdToReference(uint32 frame_id) OVERRIDE; |
52 | 53 |
53 // Called when video_accelerator_client_ has finished creating the VEA and | 54 // Called when video_accelerator_client_ has finished creating the VEA and |
54 // is ready for use. | 55 // is ready for use. |
55 void OnCreateVideoEncodeAccelerator( | 56 void OnCreateVideoEncodeAccelerator( |
56 scoped_refptr<base::SingleThreadTaskRunner> encoder_task_runner); | 57 scoped_refptr<base::SingleThreadTaskRunner> encoder_task_runner); |
57 | 58 |
58 protected: | 59 protected: |
59 void EncoderInitialized(); | 60 // If |success| is true then encoder is initialized successfully. |
| 61 // Otherwise encoder initialization failed. |
| 62 void EncoderInitialized(bool success); |
60 void EncoderError(); | 63 void EncoderError(); |
61 | 64 |
62 private: | 65 private: |
63 friend class LocalVideoEncodeAcceleratorClient; | 66 friend class LocalVideoEncodeAcceleratorClient; |
64 | 67 |
65 VideoSenderConfig video_config_; | 68 VideoSenderConfig video_config_; |
66 scoped_refptr<CastEnvironment> cast_environment_; | 69 scoped_refptr<CastEnvironment> cast_environment_; |
67 | 70 |
68 bool encoder_active_; | 71 bool encoder_active_; |
69 bool key_frame_requested_; | 72 bool key_frame_requested_; |
70 | 73 |
71 scoped_refptr<LocalVideoEncodeAcceleratorClient> video_accelerator_client_; | 74 scoped_refptr<LocalVideoEncodeAcceleratorClient> video_accelerator_client_; |
72 scoped_refptr<base::SingleThreadTaskRunner> encoder_task_runner_; | 75 scoped_refptr<base::SingleThreadTaskRunner> encoder_task_runner_; |
73 | 76 |
| 77 CastInitializationCallback initialization_cb_; |
| 78 |
74 // Weak pointer factory for posting back LocalVideoEncodeAcceleratorClient | 79 // Weak pointer factory for posting back LocalVideoEncodeAcceleratorClient |
75 // notifications to ExternalVideoEncoder. | 80 // notifications to ExternalVideoEncoder. |
76 // NOTE: Weak pointers must be invalidated before all other member variables. | 81 // NOTE: Weak pointers must be invalidated before all other member variables. |
77 base::WeakPtrFactory<ExternalVideoEncoder> weak_factory_; | 82 base::WeakPtrFactory<ExternalVideoEncoder> weak_factory_; |
78 | 83 |
79 DISALLOW_COPY_AND_ASSIGN(ExternalVideoEncoder); | 84 DISALLOW_COPY_AND_ASSIGN(ExternalVideoEncoder); |
80 }; | 85 }; |
81 | 86 |
82 } // namespace cast | 87 } // namespace cast |
83 } // namespace media | 88 } // namespace media |
84 | 89 |
85 #endif // MEDIA_CAST_SENDER_EXTERNAL_VIDEO_ENCODER_H_ | 90 #endif // MEDIA_CAST_SENDER_EXTERNAL_VIDEO_ENCODER_H_ |
OLD | NEW |