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
3 // found in the LICENSE file.
5 #ifndef MEDIA_CAST_VIDEO_SENDER_CODECS_VP8_VP8_ENCODER_H_
6 #define MEDIA_CAST_VIDEO_SENDER_CODECS_VP8_VP8_ENCODER_H_
8 #include "base/basictypes.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "media/cast/cast_config.h"
11 #include "third_party/libvpx/source/libvpx/vpx/vpx_encoder.h"
13 // VPX forward declaration.
14 typedef struct vpx_codec_ctx vpx_enc_ctx_t;
19 const int kNumberOfVp8VideoBuffers = 3;
23 Vp8Encoder(const VideoSenderConfig& video_config,
24 uint8 max_unacked_frames);
28 // Encode a raw image (as a part of a video stream).
29 bool Encode(const I420VideoFrame& input_image,
30 EncodedVideoFrame* encoded_image);
32 // Update the encoder with a new target bit rate.
33 void UpdateRates(uint32 new_bitrate);
35 // Set the next frame to be a key frame.
36 void GenerateKeyFrame();
38 void LatestFrameIdToReference(uint8 frame_id);
45 kNoBuffer = 3 // Note: must be last.
48 void InitEncode(int number_of_cores);
50 // Calculate the max target in % for a keyframe.
51 uint32 MaxIntraTarget(uint32 optimal_buffer_size) const;
53 // Calculate which next Vp8 buffers to update with the next frame.
54 Vp8Buffers GetNextBufferToUpdate();
56 // Calculate which previous frame to reference.
57 uint8 GetLatestFrameIdToReference();
59 // Get encoder flags for our referenced encoder buffers.
60 void GetCodecReferenceFlags(vpx_codec_flags_t* flags);
62 // Get encoder flags for our encoder buffers to update with next frame.
63 void GetCodecUpdateFlags(Vp8Buffers buffer_to_update,
64 vpx_codec_flags_t* flags);
66 const VideoSenderConfig cast_config_;
67 const bool use_multiple_video_buffers_;
68 const int max_number_of_repeated_buffers_in_a_row_;
70 // VP8 internal objects.
71 scoped_ptr<vpx_codec_enc_cfg_t> config_;
72 vpx_enc_ctx_t* encoder_;
73 vpx_image_t* raw_image_;
75 bool key_frame_requested_;
77 uint8 last_encoded_frame_id_;
78 uint8 used_buffers_frame_id_[kNumberOfVp8VideoBuffers];
79 bool acked_frame_buffers_[kNumberOfVp8VideoBuffers];
80 Vp8Buffers last_used_vp8_buffer_;
81 int number_of_repeated_buffers_;
87 #endif // MEDIA_CAST_VIDEO_SENDER_CODECS_VP8_VP8_ENCODER_H_