summaryrefslogtreecommitdiffstats
path: root/content/renderer/gpu/gpu_video_service_host.h
blob: 83028c112348565ec07755cbc830e375ce83dafd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// Copyright (c) 2011 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 CONTENT_RENDERER_GPU_GPU_VIDEO_SERVICE_HOST_H_
#define CONTENT_RENDERER_GPU_GPU_VIDEO_SERVICE_HOST_H_

#include "base/memory/singleton.h"
#include "content/renderer/gpu/gpu_channel_host.h"
#include "ipc/ipc_channel.h"
#include "media/base/buffers.h"
#include "media/base/video_frame.h"
#include "media/video/video_decode_accelerator.h"

class GpuVideoDecodeAcceleratorHost;

// GpuVideoServiceHost lives on IO thread and is used to dispatch IPC messages
// to GpuVideoDecoderHost objects.
class GpuVideoServiceHost : public IPC::ChannelProxy::MessageFilter {
 public:
  GpuVideoServiceHost();
  virtual ~GpuVideoServiceHost();

  // IPC::ChannelProxy::MessageFilter implementations, called on IO thread.
  virtual bool OnMessageReceived(const IPC::Message& message);
  virtual void OnFilterAdded(IPC::Channel* channel);
  virtual void OnFilterRemoved();
  virtual void OnChannelClosing();

  // Register a callback to be notified when |*this| can be used to
  // CreateVideo{Decoder,Accelerator} below.  Called on RenderThread.
  // |on_initialized| will get invoked in-line in this function if |*this| is
  // already ready for use, and asynchronously after this function returns
  // otherwise.
  void SetOnInitialized(const base::Closure& on_initialized);

  // Called on RenderThread to create a hardware accelerated video decoder
  // in the GPU process.
  GpuVideoDecodeAcceleratorHost* CreateVideoAccelerator(
      media::VideoDecodeAccelerator::Client* client,
      int command_buffer_route_id);

 private:
  // Guards all members other than |router_|.
  base::Lock lock_;

  // Reference to the channel that the service listens to.
  IPC::Channel* channel_;

  // Router to send messages to a GpuVideoDecoderHost.
  MessageRouter router_;

  // ID for the next GpuVideoDecoderHost.
  int32 next_decoder_host_id_;

  // Callback to invoke when initialized.
  base::Closure on_initialized_;

  DISALLOW_COPY_AND_ASSIGN(GpuVideoServiceHost);
};

#endif  // CONTENT_RENDERER_GPU_GPU_VIDEO_SERVICE_HOST_H_