summaryrefslogtreecommitdiffstats
path: root/content/common/gpu/media/fake_video_decode_accelerator.h
blob: 10d47822b45faac4a0d1bcc3c5041138751903cc (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
// Copyright 2014 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_COMMON_GPU_MEDIA_FAKE_VIDEO_DECODE_ACCELERATOR_H_
#define CONTENT_COMMON_GPU_MEDIA_FAKE_VIDEO_DECODE_ACCELERATOR_H_

#include <stdint.h>

#include <queue>
#include <vector>

#include "base/macros.h"
#include "base/memory/weak_ptr.h"
#include "content/common/content_export.h"
#include "content/common/gpu/media/gpu_video_decode_accelerator_helpers.h"
#include "media/video/video_decode_accelerator.h"
#include "ui/gfx/geometry/size_f.h"
#include "ui/gl/gl_context.h"

namespace content {

class CONTENT_EXPORT FakeVideoDecodeAccelerator
    : public media::VideoDecodeAccelerator {
 public:
  FakeVideoDecodeAccelerator(
      const gfx::Size& size,
      const MakeGLContextCurrentCallback& make_context_current_cb);
  ~FakeVideoDecodeAccelerator() override;

  bool Initialize(const Config& config, Client* client) override;
  void Decode(const media::BitstreamBuffer& bitstream_buffer) override;
  void AssignPictureBuffers(
      const std::vector<media::PictureBuffer>& buffers) override;
  void ReusePictureBuffer(int32_t picture_buffer_id) override;
  void Flush() override;
  void Reset() override;
  void Destroy() override;
  bool TryToSetupDecodeOnSeparateThread(
      const base::WeakPtr<Client>& decode_client,
      const scoped_refptr<base::SingleThreadTaskRunner>& decode_task_runner)
      override;

 private:
  void DoPictureReady();

  // The message loop that created the class. Used for all callbacks. This
  // class expects all calls to this class to be on this message loop (not
  // checked).
  const scoped_refptr<base::SingleThreadTaskRunner> child_task_runner_;

  Client* client_;

  // Make our context current before running any GL entry points.
  MakeGLContextCurrentCallback make_context_current_cb_;

  // Output picture size.
  gfx::Size frame_buffer_size_;

  // Picture buffer ids that are available for putting fake frames in.
  std::queue<int> free_output_buffers_;
  // BitstreamBuffer ids for buffers that contain new data to decode.
  std::queue<int> queued_bitstream_ids_;

  bool flushing_;

  // The WeakPtrFactory for |weak_this_|.
  base::WeakPtrFactory<FakeVideoDecodeAccelerator> weak_this_factory_;

  DISALLOW_COPY_AND_ASSIGN(FakeVideoDecodeAccelerator);
};

}  // namespace content

#endif  // CONTENT_COMMON_GPU_MEDIA_FAKE_VIDEO_DECODE_ACCELERATOR_H_