Cast: Stop logging kVideoFrameSentToEncoder and rename a couple events.
[chromium-blink-merge.git] / media / cast / video_sender / video_encoder_impl.h
blob4bc0a835d11f0688a095c53341f884a97a162b43
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_VIDEO_SENDER_VIDEO_ENCODER_IMPL_H_
6 #define MEDIA_CAST_VIDEO_SENDER_VIDEO_ENCODER_IMPL_H_
8 #include "base/memory/scoped_ptr.h"
9 #include "media/cast/cast_config.h"
10 #include "media/cast/cast_environment.h"
11 #include "media/cast/video_sender/software_video_encoder.h"
12 #include "media/cast/video_sender/video_encoder.h"
14 namespace media {
15 class VideoFrame;
17 namespace cast {
19 // This object is called external from the main cast thread and internally from
20 // the video encoder thread.
21 class VideoEncoderImpl : public VideoEncoder {
22 public:
23 struct CodecDynamicConfig {
24 bool key_frame_requested;
25 uint32 latest_frame_id_to_reference;
26 int bit_rate;
29 typedef base::Callback<void(scoped_ptr<transport::EncodedVideoFrame>,
30 const base::TimeTicks&)> FrameEncodedCallback;
32 VideoEncoderImpl(scoped_refptr<CastEnvironment> cast_environment,
33 const VideoSenderConfig& video_config,
34 uint8 max_unacked_frames);
36 virtual ~VideoEncoderImpl();
38 // Called from the main cast thread. This function post the encode task to the
39 // video encoder thread;
40 // The video_frame must be valid until the closure callback is called.
41 // The closure callback is called from the video encoder thread as soon as
42 // the encoder is done with the frame; it does not mean that the encoded frame
43 // has been sent out.
44 // Once the encoded frame is ready the frame_encoded_callback is called.
45 virtual bool EncodeVideoFrame(
46 const scoped_refptr<media::VideoFrame>& video_frame,
47 const base::TimeTicks& capture_time,
48 const FrameEncodedCallback& frame_encoded_callback) OVERRIDE;
50 // The following functions are called from the main cast thread.
51 virtual void SetBitRate(int new_bit_rate) OVERRIDE;
52 virtual void SkipNextFrame(bool skip_next_frame) OVERRIDE;
53 virtual void GenerateKeyFrame() OVERRIDE;
54 virtual void LatestFrameIdToReference(uint32 frame_id) OVERRIDE;
55 virtual int NumberOfSkippedFrames() const OVERRIDE;
57 private:
58 const VideoSenderConfig video_config_;
59 scoped_refptr<CastEnvironment> cast_environment_;
60 CodecDynamicConfig dynamic_config_;
61 bool skip_next_frame_;
62 int skip_count_;
64 // This member belongs to the video encoder thread. It must not be
65 // dereferenced on the main thread. We manage the lifetime of this member
66 // manually because it needs to be initialize, used and destroyed on the
67 // video encoder thread and video encoder thread can out-live the main thread.
68 scoped_ptr<SoftwareVideoEncoder> encoder_;
70 DISALLOW_COPY_AND_ASSIGN(VideoEncoderImpl);
73 } // namespace cast
74 } // namespace media
76 #endif // MEDIA_CAST_VIDEO_SENDER_VIDEO_ENCODER_IMPL_H_