summaryrefslogtreecommitdiffstats
path: root/remoting/base/decoder.h
diff options
context:
space:
mode:
authorhclam@chromium.org <hclam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-07-23 00:54:47 +0000
committerhclam@chromium.org <hclam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-07-23 00:54:47 +0000
commitbe2da4de5227f4f1cbb8455a58045c5e51076474 (patch)
treed69b7cb3b045d01adb953b007086fbe9c864af40 /remoting/base/decoder.h
parent452390cc7dc08a33a2c9b5729372b830f6966095 (diff)
downloadchromium_src-be2da4de5227f4f1cbb8455a58045c5e51076474.zip
chromium_src-be2da4de5227f4f1cbb8455a58045c5e51076474.tar.gz
chromium_src-be2da4de5227f4f1cbb8455a58045c5e51076474.tar.bz2
Moving Encoder and Decoder to remoting/base
Putting Encder and Decoder together so we can have test that tests both of them. TEST=remoting_unittests Review URL: http://codereview.chromium.org/2840036 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@53427 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'remoting/base/decoder.h')
-rw-r--r--remoting/base/decoder.h114
1 files changed, 114 insertions, 0 deletions
diff --git a/remoting/base/decoder.h b/remoting/base/decoder.h
new file mode 100644
index 0000000..1df477d
--- /dev/null
+++ b/remoting/base/decoder.h
@@ -0,0 +1,114 @@
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef REMOTING_BASE_DECODER_H_
+#define REMOTING_BASE_DECODER_H_
+
+#include <vector>
+
+#include "base/task.h"
+#include "base/scoped_ptr.h"
+#include "gfx/rect.h"
+#include "media/base/video_frame.h"
+#include "remoting/base/protocol/chromotocol.pb.h"
+
+namespace remoting {
+
+// TODO(hclam): Merge this with the one in remoting/host/encoder.h.
+typedef std::vector<gfx::Rect> UpdatedRects;
+
+// Defines the behavior of a decoder for decoding images received from the
+// host.
+//
+// Sequence of actions with a decoder is as follows:
+//
+// 1. BeginDecode(PartialDecodeDone, DecodeDone, VideoFrame)
+// 2. PartialDecode(HostMessage)
+// ...
+// 3. EndDecode()
+//
+// The decoder will reply with:
+// 1. PartialDecodeDone(VideoFrame, UpdatedRects)
+// ...
+// 2. DecodeDone(VideoFrame)
+//
+// The format of VideoFrame is a contract between the object that creates the
+// decoder (most likely the renderer) and the decoder.
+class Decoder {
+ public:
+
+ virtual ~Decoder() {
+ }
+
+ // Tell the decoder to use |frame| as a target to write the decoded image
+ // for the coming update stream.
+ // If decode is partially done and |frame| can be read, |partial_decode_done|
+ // is called and |update_rects| contains the updated regions.
+ // If decode is completed |decode_done| is called.
+ // Return true if the decoder can writes output to |frame| and accept
+ // the codec format.
+ // TODO(hclam): Provide more information when calling this function.
+ virtual bool BeginDecode(scoped_refptr<media::VideoFrame> frame,
+ UpdatedRects* updated_rects,
+ Task* partial_decode_done,
+ Task* decode_done) = 0;
+
+ // Give a HostMessage that contains the update stream packet that contains
+ // the encoded data to the decoder.
+ // The decoder will own |message| and is responsible for deleting it.
+ //
+ // If the decoder has written something into |frame|,
+ // |partial_decode_done_| is called with |frame| and updated regions.
+ // Return true if the decoder can accept |message| and decode it.
+ //
+ // HostMessage returned by this method will contain a
+ // UpdateStreamPacketMessage.
+ // This message will contain either:
+ // 1. UpdateStreamBeginRect
+ // 2. UpdateStreamRectData
+ // 3. UpdateStreamEndRect
+ //
+ // See remoting/base/protocol/chromotocol.proto for more information about
+ // these messages.
+ virtual bool PartialDecode(HostMessage* message) = 0;
+
+ // Notify the decoder that we have received the last update stream packet.
+ // If the decoding of the update stream has completed |decode_done_| is
+ // called with |frame|.
+ // If the update stream is not received fully and this method is called the
+ // decoder should also call |decode_done_| as soon as possible.
+ virtual void EndDecode() = 0;
+
+ protected:
+ // Every decoder will have two internal states because there are three
+ // kinds of messages send to PartialDecode().
+ //
+ // Here's a state diagram:
+ //
+ // UpdateStreamBeginRect UpdateStreamRectData
+ // .............. ............
+ // . . . .
+ // . v . .
+ // kWaitingForBeginRect kWaitingForRectData .
+ // ^ . ^ .
+ // . . . .
+ // .............. ............
+ // UpdateStreaEndRect
+ enum State {
+ // In this state the decoder is waiting for UpdateStreamBeginRect.
+ // After receiving UpdateStreaBeginRect, the encoder will transit to
+ // to kWaitingForRectData state.
+ kWaitingForBeginRect,
+
+ // In this state the decoder is waiting for UpdateStreamRectData.
+ // The decode remains in this state if UpdateStreamRectData is received.
+ // The decoder will transit to kWaitingForBeginRect if UpdateStreamEndRect
+ // is received.
+ kWaitingForRectData,
+ };
+};
+
+} // namespace remoting
+
+#endif // REMOTING_BASE_DECODER_H_