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 "base/time/time.h" 10#include "remoting/codec/scoped_vpx_codec.h" 11#include "remoting/codec/video_encoder.h" 12#include "remoting/codec/video_encoder_helper.h" 13 14typedef struct vpx_image vpx_image_t; 15 16namespace webrtc { 17class DesktopRegion; 18class DesktopSize; 19} // namespace webrtc 20 21namespace remoting { 22 23class VideoEncoderVpx : public VideoEncoder { 24 public: 25 // Create encoder for the specified protocol. 26 static scoped_ptr<VideoEncoderVpx> CreateForVP8(); 27 static scoped_ptr<VideoEncoderVpx> CreateForVP9(); 28 29 virtual ~VideoEncoderVpx(); 30 31 // VideoEncoder interface. 32 virtual void SetLosslessEncode(bool want_lossless) OVERRIDE; 33 virtual void SetLosslessColor(bool want_lossless) OVERRIDE; 34 virtual scoped_ptr<VideoPacket> Encode( 35 const webrtc::DesktopFrame& frame) OVERRIDE; 36 37 private: 38 explicit VideoEncoderVpx(bool use_vp9); 39 40 // Initializes the codec for frames of |size|. Returns true if successful. 41 bool Initialize(const webrtc::DesktopSize& size); 42 43 // Prepares |image_| for encoding. Writes updated rectangles into 44 // |updated_region|. 45 void PrepareImage(const webrtc::DesktopFrame& frame, 46 webrtc::DesktopRegion* updated_region); 47 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); 51 52 // True if the encoder should generate VP9, false for VP8. 53 bool use_vp9_; 54 55 // Options controlling VP9 encode quantization and color space. 56 // These are always off (false) for VP8. 57 bool lossless_encode_; 58 bool lossless_color_; 59 60 ScopedVpxCodec codec_; 61 base::TimeTicks timestamp_base_; 62 63 // VPX image and buffer to hold the actual YUV planes. 64 scoped_ptr<vpx_image_t> image_; 65 scoped_ptr<uint8[]> image_buffer_; 66 67 // Active map used to optimize out processing of un-changed macroblocks. 68 scoped_ptr<uint8[]> active_map_; 69 int active_map_width_; 70 int active_map_height_; 71 72 // Used to help initialize VideoPackets from DesktopFrames. 73 VideoEncoderHelper helper_; 74 75 DISALLOW_COPY_AND_ASSIGN(VideoEncoderVpx); 76}; 77 78} // namespace remoting 79 80#endif // REMOTING_CODEC_VIDEO_ENCODER_VP8_H_ 81