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.
5 #ifndef MEDIA_CAST_SENDER_EXTERNAL_VIDEO_ENCODER_H_
6 #define MEDIA_CAST_SENDER_EXTERNAL_VIDEO_ENCODER_H_
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/sender/video_encoder.h"
13 #include "media/video/video_encode_accelerator.h"
22 class LocalVideoEncodeAcceleratorClient;
24 // This object is called external from the main cast thread and internally from
25 // the video encoder thread.
26 class ExternalVideoEncoder : public VideoEncoder {
29 scoped_refptr<CastEnvironment> cast_environment,
30 const VideoSenderConfig& video_config,
31 const CastInitializationCallback& initialization_cb,
32 const CreateVideoEncodeAcceleratorCallback& create_vea_cb,
33 const CreateVideoEncodeMemoryCallback& create_video_encode_mem_cb);
35 ~ExternalVideoEncoder() override;
37 // VideoEncoder implementation.
38 bool EncodeVideoFrame(
39 const scoped_refptr<media::VideoFrame>& video_frame,
40 const base::TimeTicks& reference_time,
41 const FrameEncodedCallback& frame_encoded_callback) override;
42 void SetBitRate(int new_bit_rate) override;
43 void GenerateKeyFrame() override;
44 void LatestFrameIdToReference(uint32 frame_id) override;
46 // Called when video_accelerator_client_ has finished creating the VEA and
48 void OnCreateVideoEncodeAccelerator(
49 scoped_refptr<base::SingleThreadTaskRunner> encoder_task_runner);
52 // If |success| is true then encoder is initialized successfully.
53 // Otherwise encoder initialization failed.
54 void EncoderInitialized(bool success);
58 friend class LocalVideoEncodeAcceleratorClient;
60 VideoSenderConfig video_config_;
61 scoped_refptr<CastEnvironment> cast_environment_;
64 bool key_frame_requested_;
66 scoped_refptr<LocalVideoEncodeAcceleratorClient> video_accelerator_client_;
67 scoped_refptr<base::SingleThreadTaskRunner> encoder_task_runner_;
69 CastInitializationCallback initialization_cb_;
71 // Weak pointer factory for posting back LocalVideoEncodeAcceleratorClient
72 // notifications to ExternalVideoEncoder.
73 // NOTE: Weak pointers must be invalidated before all other member variables.
74 base::WeakPtrFactory<ExternalVideoEncoder> weak_factory_;
76 DISALLOW_COPY_AND_ASSIGN(ExternalVideoEncoder);
82 #endif // MEDIA_CAST_SENDER_EXTERNAL_VIDEO_ENCODER_H_