media_source_video_renderer.h revision 010d83a9304c5a91596085d917d248abff47903a
1// Copyright 2014 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_CLIENT_PLUGIN_MEDIA_SOURCE_VIDEO_RENDERER_H_
6#define REMOTING_CLIENT_PLUGIN_MEDIA_SOURCE_VIDEO_RENDERER_H_
7
8#include <string>
9
10#include "base/basictypes.h"
11#include "base/callback.h"
12#include "base/memory/scoped_ptr.h"
13#include "remoting/client/chromoting_stats.h"
14#include "remoting/client/video_renderer.h"
15#include "third_party/webrtc/modules/desktop_capture/desktop_geometry.h"
16#include "third_party/webrtc/modules/desktop_capture/desktop_region.h"
17
18namespace remoting {
19
20// VideoRenderer implementation that packs data into a WebM stream that can be
21// passed to <video> tag using MediaSource API.
22class MediaSourceVideoRenderer : public VideoRenderer {
23 public:
24  class Delegate {
25   public:
26    Delegate() {}
27    virtual ~Delegate() {}
28
29    // Called when stream size changes.
30    virtual void OnMediaSourceSize(const webrtc::DesktopSize& size,
31                                   const webrtc::DesktopVector& dpi) = 0;
32
33    // Called when desktop shape changes.
34    virtual void OnMediaSourceShape(const webrtc::DesktopRegion& shape) = 0;
35
36    // Called when the MediaSource needs to be reset (e.g. because screen size
37    // has changed).
38    virtual void OnMediaSourceReset(const std::string& format) = 0;
39
40    // Called when new data becomes available.
41    virtual void OnMediaSourceData(uint8_t* buffer, size_t buffer_size) = 0;
42  };
43
44  explicit MediaSourceVideoRenderer(Delegate* data_forwarder);
45  virtual ~MediaSourceVideoRenderer();
46
47  // VideoRenderer interface.
48  virtual void Initialize(const protocol::SessionConfig& config) OVERRIDE;
49  virtual ChromotingStats* GetStats() OVERRIDE;
50  virtual void ProcessVideoPacket(scoped_ptr<VideoPacket> packet,
51                                  const base::Closure& done) OVERRIDE;
52
53 private:
54  // Helper class used to generate WebM stream.
55  class VideoWriter;
56
57  Delegate* delegate_;
58  scoped_ptr<VideoWriter> writer_;
59  webrtc::DesktopVector frame_dpi_;
60  webrtc::DesktopRegion desktop_shape_;
61
62  ChromotingStats stats_;
63  int64 latest_sequence_number_;
64
65  DISALLOW_COPY_AND_ASSIGN(MediaSourceVideoRenderer);
66};
67
68}  // namespace remoting
69
70#endif  // REMOTING_CLIENT_PLUGIN_MEDIA_SOURCE_VIDEO_RENDERER_H_
71