| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef MEDIA_CAST_VIDEO_SENDER_EXTERNAL_VIDEO_ENCODER_H_ | |
| 6 #define MEDIA_CAST_VIDEO_SENDER_EXTERNAL_VIDEO_ENCODER_H_ | |
| 7 | |
| 8 #include "base/memory/scoped_ptr.h" | |
| 9 #include "base/memory/weak_ptr.h" | |
| 10 #include "media/cast/cast_config.h" | |
| 11 #include "media/cast/cast_environment.h" | |
| 12 #include "media/cast/video_sender/video_encoder.h" | |
| 13 #include "media/video/video_encode_accelerator.h" | |
| 14 | |
| 15 namespace media { | |
| 16 class VideoFrame; | |
| 17 } | |
| 18 | |
| 19 namespace media { | |
| 20 namespace cast { | |
| 21 | |
| 22 class LocalVideoEncodeAcceleratorClient; | |
| 23 | |
| 24 // This object is called external from the main cast thread and internally from | |
| 25 // the video encoder thread. | |
| 26 class ExternalVideoEncoder : public VideoEncoder { | |
| 27 public: | |
| 28 ExternalVideoEncoder( | |
| 29 scoped_refptr<CastEnvironment> cast_environment, | |
| 30 const VideoSenderConfig& video_config, | |
| 31 const CreateVideoEncodeAcceleratorCallback& create_vea_cb, | |
| 32 const CreateVideoEncodeMemoryCallback& create_video_encode_mem_cb); | |
| 33 | |
| 34 virtual ~ExternalVideoEncoder(); | |
| 35 | |
| 36 // Called from the main cast thread. This function post the encode task to the | |
| 37 // video encoder thread; | |
| 38 // 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 encoder is done with the frame; it does not mean that the encoded frame | |
| 41 // has been sent out. | |
| 42 // Once the encoded frame is ready the frame_encoded_callback is called. | |
| 43 virtual bool EncodeVideoFrame( | |
| 44 const scoped_refptr<media::VideoFrame>& video_frame, | |
| 45 const base::TimeTicks& capture_time, | |
| 46 const FrameEncodedCallback& frame_encoded_callback) OVERRIDE; | |
| 47 | |
| 48 // The following functions are called from the main cast thread. | |
| 49 virtual void SetBitRate(int new_bit_rate) OVERRIDE; | |
| 50 virtual void GenerateKeyFrame() OVERRIDE; | |
| 51 virtual void LatestFrameIdToReference(uint32 frame_id) OVERRIDE; | |
| 52 | |
| 53 // Called when a VEA is created. | |
| 54 void OnCreateVideoEncodeAccelerator( | |
| 55 const CreateVideoEncodeMemoryCallback& create_video_encode_mem_cb, | |
| 56 scoped_refptr<base::SingleThreadTaskRunner> encoder_task_runner, | |
| 57 scoped_ptr<media::VideoEncodeAccelerator> vea); | |
| 58 | |
| 59 protected: | |
| 60 void EncoderInitialized(); | |
| 61 void EncoderError(); | |
| 62 | |
| 63 private: | |
| 64 friend class LocalVideoEncodeAcceleratorClient; | |
| 65 | |
| 66 VideoSenderConfig video_config_; | |
| 67 scoped_refptr<CastEnvironment> cast_environment_; | |
| 68 | |
| 69 bool encoder_active_; | |
| 70 bool key_frame_requested_; | |
| 71 | |
| 72 scoped_refptr<LocalVideoEncodeAcceleratorClient> video_accelerator_client_; | |
| 73 scoped_refptr<base::SingleThreadTaskRunner> encoder_task_runner_; | |
| 74 | |
| 75 // Weak pointer factory for posting back LocalVideoEncodeAcceleratorClient | |
| 76 // notifications to ExternalVideoEncoder. | |
| 77 // NOTE: Weak pointers must be invalidated before all other member variables. | |
| 78 base::WeakPtrFactory<ExternalVideoEncoder> weak_factory_; | |
| 79 | |
| 80 DISALLOW_COPY_AND_ASSIGN(ExternalVideoEncoder); | |
| 81 }; | |
| 82 | |
| 83 } // namespace cast | |
| 84 } // namespace media | |
| 85 | |
| 86 #endif // MEDIA_CAST_VIDEO_SENDER_EXTERNAL_VIDEO_ENCODER_H_ | |
| OLD | NEW |