Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(135)

Side by Side Diff: chrome/gpu/arc_gpu_video_decode_accelerator.h

Issue 1549473002: Add ArcGpuVideoDecodeAccelerator. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: address posciak's comments Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2016 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 CHROME_GPU_ARC_GPU_VIDEO_DECODE_ACCELERATOR_H_
6 #define CHROME_GPU_ARC_GPU_VIDEO_DECODE_ACCELERATOR_H_
7
8 #include <list>
9 #include <queue>
10 #include <vector>
11
12 #include "base/callback.h"
13 #include "base/memory/scoped_ptr.h"
14 #include "base/threading/thread_checker.h"
15 #include "chrome/gpu/arc_video_accelerator.h"
16 #include "media/video/video_decode_accelerator.h"
17
18 namespace chromeos {
19 namespace arc {
20
21 // This class is executed in Chromium's GPU process. It takes decoding requests
22 // from ARC via IPC channels and translates and send those requests to an
23 // implementation of the VideoDecodeAccelerator interface on Chromium. It also
24 // returns the decoded frames back to the ARC side.
25 class ArcGpuVideoDecodeAccelerator
26 : public ArcVideoAccelerator,
27 public media::VideoDecodeAccelerator::Client,
28 public base::SupportsWeakPtr<ArcGpuVideoDecodeAccelerator> {
29 public:
30 ArcGpuVideoDecodeAccelerator(
31 const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner);
32 ~ArcGpuVideoDecodeAccelerator() override;
33
34 // Implementation of the ArcVideoAccelerator interface.
35 bool Initialize(const Config& config,
36 ArcVideoAccelerator::Client* client) override;
37 void SetNumberOfOutputBuffers(size_t number) override;
38 void BindSharedMemory(PortType port,
39 uint32_t index,
40 int ashmem_fd,
41 off_t offset,
42 size_t length) override;
43 void BindDmabuf(PortType port, uint32_t index, int dmabuf_fd) override;
44 void UseBuffer(PortType port,
45 uint32_t index,
46 const BufferMetadata& metadata) override;
47 void Reset() override;
48
49 // Implementation of the VideoDecodeAccelerator::Client interface.
50 void ProvidePictureBuffers(uint32_t requested_num_of_buffers,
51 const gfx::Size& dimensions,
52 uint32_t texture_target) override;
53 void DismissPictureBuffer(int32_t picture_buffer) override;
54 void PictureReady(const media::Picture& picture) override;
55 void NotifyEndOfBitstreamBuffer(int32_t bitstream_buffer_id) override;
56 void NotifyFlushDone() override;
57 void NotifyResetDone() override;
58 void NotifyError(media::VideoDecodeAccelerator::Error error) override;
59
60 private:
61 struct InputRecord {
62 int32_t bitstream_buffer_id;
63 uint32_t buffer_index;
64 int64_t timestamp;
65
66 InputRecord(int32_t bitstream_buffer_id,
67 uint32_t buffer_index,
68 int64_t timestamp);
69 };
70
71 struct InputBufferInfo {
72 // The file handle to access the buffer. It is owned by this class and
73 // should be closed after use.
74 base::ScopedFD handle;
75 off_t offset;
76 size_t length;
77
78 InputBufferInfo();
79 InputBufferInfo(InputBufferInfo&&);
80 ~InputBufferInfo();
81 };
82
83 // Helper function to Send the end-of-stream output buffer if
84 // |pending_eos_output_buffer_| is true, or reuse the picture in ArcVDA.
85 void SendEosIfNeededOrReusePicture(uint32_t index);
86
87 // Helper function to validate |port| and |index|.
88 bool ValidatePortAndIndex(PortType port, uint32_t index);
89
90 // Sets InputRecord for the given |bitstream_buffer_id|. The |buffer_index|
91 // is the index of the associated input buffer. The |timestamp| is the
92 // time the video frame should be displayed.
93 void SetInputRecord(int32_t bitstream_buffer_id,
94 uint32_t buffer_index,
95 int64_t timestamp);
96
97 // Finds the InputRecord which matches to given |bitstream_buffer_id|.
98 // Returns |nullptr| if it cannot be found.
99 InputRecord* FindInputRecord(int32_t bitstream_buffer_id);
100
101 // When true, an EOS output buffer need to be sent to |arc_client_| once an
102 // output buffer is available.
103 bool pending_eos_output_buffer_;
104 scoped_ptr<media::VideoDecodeAccelerator> vda_;
105
106 // It's safe to use the pointer here, the life cycle of the |arc_client_|
107 // is longer than this ArcGpuVideoDecodeAccelerator.
108 ArcVideoAccelerator::Client* arc_client_;
109
110 // The callback called when reset completes.
111 base::Closure reset_done_callback_;
112
113 // The next ID for the bitstream buffer, started from 0.
114 int32_t next_bitstream_buffer_id_;
115
116 gfx::Size coded_size_;
117
118 // The |picture_buffer_id|s for Picutres that were returned to us from VDA
119 // via PictureReady() while flushing. We keep them until NotifyFlushDone();
120 // once it's called, we send one of the pending buffers from this queue (if
121 // not empty), marked with an EOS flag, to arc_client_, and return the rest
kcwu 2016/03/09 07:58:21 |arc_client_|
Owen Lin 2016/03/14 08:46:59 Done.
122 // to VDA for reuse.
123 std::queue<uint32_t> buffers_pending_eos_;
kcwu 2016/03/09 07:58:21 bitstream buffer id is int32_t
Owen Lin 2016/03/14 08:46:59 Done.
124 std::list<InputRecord> input_records_;
125 std::vector<InputBufferInfo> input_buffer_info_;
126
127 // To keep those output buffers which have been bound by bindDmabuf() but not
128 // be used yet. Will call VDA::ImportBufferForPicture() when those buffer are
129 // used for the first time.
130 std::vector<base::ScopedFD> pending_import_buffer_;
131 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_;
132 base::ThreadChecker thread_checker_;
133 size_t output_buffer_size_;
134
135 DISALLOW_IMPLICIT_CONSTRUCTORS(ArcGpuVideoDecodeAccelerator);
136 };
137
138 } // namespace arc
139 } // namespace chromeos
140
141 #endif // CHROME_GPU_ARC_GPU_VIDEO_DECODE_ACCELERATOR_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698