| OLD | NEW | 
|---|
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be | 
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. | 
| 4 | 4 | 
| 5 #ifndef REMOTING_CLIENT_DECODER_H_ | 5 #ifndef REMOTING_CLIENT_DECODER_H_ | 
| 6 #define REMOTING_CLIENT_DECODER_H_ | 6 #define REMOTING_CLIENT_DECODER_H_ | 
| 7 | 7 | 
| 8 #include <vector> | 8 #include <vector> | 
| 9 | 9 | 
| 10 #include "base/callback.h" | 10 #include "base/task.h" | 
| 11 #include "base/scoped_ptr.h" | 11 #include "base/scoped_ptr.h" | 
| 12 #include "gfx/rect.h" | 12 #include "gfx/rect.h" | 
| 13 #include "media/base/video_frame.h" | 13 #include "media/base/video_frame.h" | 
| 14 #include "remoting/base/protocol/chromotocol.pb.h" | 14 #include "remoting/base/protocol/chromotocol.pb.h" | 
| 15 | 15 | 
| 16 namespace remoting { | 16 namespace remoting { | 
| 17 | 17 | 
|  | 18 // TODO(hclam): Merge this with the one in remoting/host/encoder.h. | 
|  | 19 typedef std::vector<gfx::Rect> UpdatedRects; | 
|  | 20 | 
| 18 // Defines the behavior of a decoder for decoding images received from the | 21 // Defines the behavior of a decoder for decoding images received from the | 
| 19 // host. | 22 // host. | 
| 20 // | 23 // | 
| 21 // Sequence of actions with a decoder is as follows: | 24 // Sequence of actions with a decoder is as follows: | 
| 22 // | 25 // | 
| 23 // 1. BeginDecode(VideoFrame) | 26 // 1. BeginDecode(PartialDecodeDone, DecodeDone, VideoFrame) | 
| 24 // 2. PartialDecode(HostMessage) | 27 // 2. PartialDecode(HostMessage) | 
| 25 //    ... | 28 //    ... | 
| 26 // 3. EndDecode() | 29 // 3. EndDecode() | 
| 27 // | 30 // | 
| 28 // The decoder will reply with: | 31 // The decoder will reply with: | 
| 29 // 1. PartialDecodeDone(VideoFrame, UpdatedRects) | 32 // 1. PartialDecodeDone(VideoFrame, UpdatedRects) | 
| 30 //    ... | 33 //    ... | 
| 31 // 2. DecodeDone(VideoFrame) | 34 // 2. DecodeDone(VideoFrame) | 
| 32 // | 35 // | 
| 33 // The format of VideoFrame is a contract between the object that creates the | 36 // The format of VideoFrame is a contract between the object that creates the | 
| 34 // decoder (most likely the renderer) and the decoder. | 37 // decoder (most likely the renderer) and the decoder. | 
| 35 class Decoder { | 38 class Decoder { | 
| 36  public: | 39  public: | 
| 37   typedef std::vector<gfx::Rect> UpdatedRects; |  | 
| 38   typedef Callback2<scoped_refptr<media::VideoFrame>, UpdatedRects>::Type |  | 
| 39       PartialDecodeDoneCallback; |  | 
| 40   typedef Callback1<scoped_refptr<media::VideoFrame> >::Type |  | 
| 41       DecodeDoneCallback; |  | 
| 42 |  | 
| 43   Decoder(PartialDecodeDoneCallback* partial_decode_done_callback, |  | 
| 44           DecodeDoneCallback* decode_done_callback) |  | 
| 45       : partial_decode_done_(partial_decode_done_callback), |  | 
| 46         decode_done_(decode_done_callback) { |  | 
| 47   } |  | 
| 48 | 40 | 
| 49   virtual ~Decoder() { | 41   virtual ~Decoder() { | 
| 50   } | 42   } | 
| 51 | 43 | 
| 52   // Tell the decoder to use |frame| as a target to write the decoded image | 44   // Tell the decoder to use |frame| as a target to write the decoded image | 
| 53   // for the coming update stream. | 45   // for the coming update stream. | 
|  | 46   // If decode is partially done and |frame| can be read, |partial_decode_done| | 
|  | 47   // is called and |update_rects| contains the updated regions. | 
|  | 48   // If decode is completed |decode_done| is called. | 
| 54   // Return true if the decoder can writes output to |frame| and accept | 49   // Return true if the decoder can writes output to |frame| and accept | 
| 55   // the codec format. | 50   // the codec format. | 
| 56   // TODO(hclam): Provide more information when calling this function. | 51   // TODO(hclam): Provide more information when calling this function. | 
| 57   virtual bool BeginDecode(scoped_refptr<media::VideoFrame> frame) = 0; | 52   virtual bool BeginDecode(scoped_refptr<media::VideoFrame> frame, | 
|  | 53                            UpdatedRects* updated_rects, | 
|  | 54                            Task* partial_decode_done, | 
|  | 55                            Task* decode_done) = 0; | 
| 58 | 56 | 
| 59   // Give a HostMessage that contains the update stream packet that contains | 57   // Give a HostMessage that contains the update stream packet that contains | 
| 60   // the encoded data to the decoder. | 58   // the encoded data to the decoder. | 
| 61   // The decoder will own |message| and is responsible for deleting it. | 59   // The decoder will own |message| and is responsible for deleting it. | 
| 62   // If the decoder has written something into |frame|, | 60   // If the decoder has written something into |frame|, | 
| 63   // |partial_decode_done_| is called with |frame| and updated regions. | 61   // |partial_decode_done_| is called with |frame| and updated regions. | 
| 64   // Return true if the decoder can accept |message| and decode it. | 62   // Return true if the decoder can accept |message| and decode it. | 
| 65   virtual bool PartialDecode(chromotocol_pb::HostMessage* message) = 0; | 63   virtual bool PartialDecode(HostMessage* message) = 0; | 
| 66 | 64 | 
| 67   // Notify the decoder that we have received the last update stream packet. | 65   // Notify the decoder that we have received the last update stream packet. | 
| 68   // If the decoding of the update stream has completed |decode_done_| is | 66   // If the decoding of the update stream has completed |decode_done_| is | 
| 69   // called with |frame|. | 67   // called with |frame|. | 
| 70   // If the update stream is not received fully and this method is called the | 68   // If the update stream is not received fully and this method is called the | 
| 71   // decoder should also call |decode_done_| as soon as possible. | 69   // decoder should also call |decode_done_| as soon as possible. | 
| 72   virtual void EndDecode() = 0; | 70   virtual void EndDecode() = 0; | 
| 73 |  | 
| 74  protected: |  | 
| 75   PartialDecodeDoneCallback* partial_decode_done() { |  | 
| 76     return partial_decode_done_.get(); |  | 
| 77   } |  | 
| 78 |  | 
| 79   DecodeDoneCallback* decode_done() { |  | 
| 80     return decode_done_.get(); |  | 
| 81   } |  | 
| 82 |  | 
| 83  private: |  | 
| 84   scoped_ptr<PartialDecodeDoneCallback> partial_decode_done_; |  | 
| 85   scoped_ptr<DecodeDoneCallback> decode_done_; |  | 
| 86 |  | 
| 87   DISALLOW_COPY_AND_ASSIGN(Decoder); |  | 
| 88 }; | 71 }; | 
| 89 | 72 | 
| 90 }  // namespace remoting | 73 }  // namespace remoting | 
| 91 | 74 | 
| 92 #endif  // REMOTING_CLIENT_DECODER_H_ | 75 #endif  // REMOTING_CLIENT_DECODER_H_ | 
| OLD | NEW | 
|---|