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