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 REMOTING_CODEC_VIDEO_ENCODER_VPX_H_
6 #define REMOTING_CODEC_VIDEO_ENCODER_VPX_H_
8 #include "base/callback.h"
9 #include "base/time/time.h"
10 #include "remoting/codec/scoped_vpx_codec.h"
11 #include "remoting/codec/video_encoder.h"
13 typedef struct vpx_image vpx_image_t;
22 class VideoEncoderVpx : public VideoEncoder {
24 // Create encoder for the specified protocol.
25 static scoped_ptr<VideoEncoderVpx> CreateForVP8();
26 static scoped_ptr<VideoEncoderVpx> CreateForVP9();
28 virtual ~VideoEncoderVpx();
30 // VideoEncoder interface.
31 virtual scoped_ptr<VideoPacket> Encode(
32 const webrtc::DesktopFrame& frame) OVERRIDE;
35 typedef base::Callback<ScopedVpxCodec(const webrtc::DesktopSize&)>
36 InitializeCodecCallback;
38 VideoEncoderVpx(const InitializeCodecCallback& init_codec);
40 // Initializes the codec for frames of |size|. Returns true if successful.
41 bool Initialize(const webrtc::DesktopSize& size);
43 // Prepares |image_| for encoding. Writes updated rectangles into
45 void PrepareImage(const webrtc::DesktopFrame& frame,
46 webrtc::DesktopRegion* updated_region);
48 // Updates the active map according to |updated_region|. Active map is then
49 // given to the encoder to speed up encoding.
50 void PrepareActiveMap(const webrtc::DesktopRegion& updated_region);
52 InitializeCodecCallback init_codec_;
54 ScopedVpxCodec codec_;
55 scoped_ptr<vpx_image_t> image_;
56 scoped_ptr<uint8[]> active_map_;
57 int active_map_width_;
58 int active_map_height_;
59 base::TimeTicks timestamp_base_;
61 // Buffer for storing the yuv image.
62 scoped_ptr<uint8[]> yuv_image_;
64 DISALLOW_COPY_AND_ASSIGN(VideoEncoderVpx);
67 } // namespace remoting
69 #endif // REMOTING_CODEC_VIDEO_ENCODER_VP8_H_