summaryrefslogtreecommitdiffstats
path: root/chrome/gpu/gpu_video_decoder.h
blob: caed871da430961c0255d51c492346e2b205ce34 (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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
// 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 CHROME_GPU_GPU_VIDEO_DECODER_H_
#define CHROME_GPU_GPU_VIDEO_DECODER_H_

#include "base/basictypes.h"
#include "base/callback.h"
#include "base/ref_counted.h"
#include "base/scoped_ptr.h"
#include "chrome/common/gpu_video_common.h"
#include "media/filters/video_decode_engine.h"
#include "ipc/ipc_channel.h"

class GpuChannel;

using media::VideoCodecConfig;
using media::VideoCodecInfo;
using media::VideoStreamInfo;
using media::VideoFrame;
using media::Buffer;

class GpuVideoDecoder
    : public IPC::Channel::Listener,
      public base::RefCountedThreadSafe<GpuVideoDecoder>,
      public media::VideoDecodeEngine::EventHandler {

 public:
  // IPC::Channel::Listener.
  virtual void OnChannelConnected(int32 peer_pid);
  virtual void OnChannelError();
  virtual void OnMessageReceived(const IPC::Message& message);

  // VideoDecodeEngine::EventHandler.
  virtual void OnInitializeComplete(const VideoCodecInfo& info);
  virtual void OnUninitializeComplete();
  virtual void OnFlushComplete();
  virtual void OnSeekComplete();
  virtual void OnError();
  virtual void OnFormatChange(VideoStreamInfo stream_info);
  virtual void OnEmptyBufferCallback(scoped_refptr<Buffer> buffer);
  virtual void OnFillBufferCallback(scoped_refptr<VideoFrame> frame);

  GpuVideoDecoder(const GpuVideoDecoderInfoParam* param,
                  GpuChannel* channel_,
                  base::ProcessHandle handle);
  virtual ~GpuVideoDecoder() {}

 private:
  int32 route_id() { return decoder_host_route_id_; }

  bool CreateInputTransferBuffer(uint32 size,
                                 base::SharedMemoryHandle* handle);
  bool CreateOutputTransferBuffer(uint32 size,
                                  base::SharedMemoryHandle* handle);
  void CreateVideoFrameOnTransferBuffer();

  int32 decoder_host_route_id_;

  // Used only in system memory path. i.e. Remove this later.
  scoped_refptr<VideoFrame> frame_;
  bool output_transfer_buffer_busy_;
  int32 pending_output_requests_;

  GpuChannel* channel_;
  base::ProcessHandle renderer_handle_;

  scoped_ptr<base::SharedMemory> input_transfer_buffer_;
  scoped_ptr<base::SharedMemory> output_transfer_buffer_;

  scoped_ptr<media::VideoDecodeEngine> decode_engine_;
  media::VideoCodecConfig config_;
  media::VideoCodecInfo info_;

  // Input message handler.
  void OnInitialize(const GpuVideoDecoderInitParam& param);
  void OnUninitialize();
  void OnFlush();
  void OnEmptyThisBuffer(const GpuVideoDecoderInputBufferParam& buffer);
  void OnFillThisBuffer(const GpuVideoDecoderOutputBufferParam& frame);
  void OnFillThisBufferDoneACK();

  // Output message helper.
  void SendInitializeDone(const GpuVideoDecoderInitDoneParam& param);
  void SendUninitializeDone();
  void SendFlushDone();
  void SendEmptyBufferDone();
  void SendEmptyBufferACK();
  void SendFillBufferDone(const GpuVideoDecoderOutputBufferParam& frame);

  DISALLOW_COPY_AND_ASSIGN(GpuVideoDecoder);
};

#endif  // CHROME_GPU_GPU_VIDEO_DECODER_H_