video_decoder.h revision d0247b1b59f9c528cb6df88b4f2b9afaf80d181e
1// Copyright (c) 2012 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_DECODER_H_ 6#define REMOTING_CODEC_VIDEO_DECODER_H_ 7 8#include "base/basictypes.h" 9#include "remoting/proto/video.pb.h" 10 11namespace webrtc { 12class DesktopRect; 13class DesktopRegion; 14class DesktopSize; 15} // namespace webrtc 16 17namespace remoting { 18 19// Interface for a decoder that takes a stream of bytes from the network and 20// outputs frames of data. 21class VideoDecoder { 22 public: 23 // DecodeResult is returned from DecodePacket() and indicates current state 24 // of the decoder. DECODE_DONE means that last packet for the frame was 25 // processed, and the frame can be displayed now. DECODE_ERROR is returned if 26 // there was an error in the stream. 27 enum DecodeResult { 28 DECODE_ERROR, 29 DECODE_DONE, 30 }; 31 32 VideoDecoder() {} 33 virtual ~VideoDecoder() {} 34 35 // Initializes the decoder and sets the output dimensions. 36 // |screen size| must not be empty. 37 virtual void Initialize(const webrtc::DesktopSize& screen_size) = 0; 38 39 // Feeds more data into the decoder. 40 virtual DecodeResult DecodePacket(const VideoPacket* packet) = 0; 41 42 // Returns true if decoder is ready to accept data via DecodePacket. 43 virtual bool IsReadyForData() = 0; 44 45 virtual VideoPacketFormat::Encoding Encoding() = 0; 46 47 // Marks the specified |region| of the view for update the next time 48 // RenderFrame() is called. |region| is expressed in |view_size| coordinates. 49 // |view_size| must not be empty. 50 virtual void Invalidate(const webrtc::DesktopSize& view_size, 51 const webrtc::DesktopRegion& region) = 0; 52 53 // Copies invalidated pixels within |clip_area| to |image_buffer|. Pixels are 54 // invalidated either by new data received in DecodePacket(), or by explicit 55 // calls to Invalidate(). |clip_area| is specified in |view_size| coordinates. 56 // If |view_size| differs from the source size then the copied pixels will be 57 // scaled accordingly. |view_size| cannot be empty. 58 // 59 // |image_buffer|'s origin must correspond to the top-left of |clip_area|, 60 // and the buffer must be large enough to hold |clip_area| RGBA32 pixels. 61 // |image_stride| gives the output buffer's stride in pixels. 62 // 63 // On return, |output_region| contains the updated area, in |view_size| 64 // coordinates. 65 virtual void RenderFrame(const webrtc::DesktopSize& view_size, 66 const webrtc::DesktopRect& clip_area, 67 uint8* image_buffer, 68 int image_stride, 69 webrtc::DesktopRegion* output_region) = 0; 70 71 // Returns the "shape", if any, of the most recently rendered frame. 72 // The shape is returned in source dimensions. 73 virtual const webrtc::DesktopRegion* GetImageShape() = 0; 74}; 75 76} // namespace remoting 77 78#endif // REMOTING_CODEC_VIDEO_DECODER_H_ 79