1 // Copyright 2020 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 ANDROID_V4L2_CODEC2_COMPONENTS_VIDEO_DECODER_H
6 #define ANDROID_V4L2_CODEC2_COMPONENTS_VIDEO_DECODER_H
7 
8 #include <stdint.h>
9 #include <memory>
10 
11 #include <base/callback.h>
12 
13 #include <v4l2_codec2/common/VideoTypes.h>
14 #include <v4l2_codec2/components/BitstreamBuffer.h>
15 #include <v4l2_codec2/components/VideoFrame.h>
16 #include <v4l2_codec2/components/VideoFramePool.h>
17 
18 namespace android {
19 
20 class VideoDecoder {
21 public:
22     enum class DecodeStatus {
23         kOk = 0,   // Everything went as planned.
24         kAborted,  // Read aborted due to Flush() during pending read.
25         kError,    // Decoder returned decode error.
26     };
27     static const char* DecodeStatusToString(DecodeStatus status);
28 
29     using GetPoolCB = base::RepeatingCallback<std::unique_ptr<VideoFramePool>(
30             const ui::Size& size, HalPixelFormat pixelFormat, size_t numOutputBuffers)>;
31     using DecodeCB = base::OnceCallback<void(DecodeStatus)>;
32     using OutputCB = base::RepeatingCallback<void(std::unique_ptr<VideoFrame>)>;
33     using ErrorCB = base::RepeatingCallback<void()>;
34 
35     virtual ~VideoDecoder();
36 
37     virtual void decode(std::unique_ptr<BitstreamBuffer> buffer, DecodeCB decodeCb) = 0;
38     virtual void drain(DecodeCB drainCb) = 0;
39     virtual void flush() = 0;
40 };
41 
42 }  // namespace android
43 
44 #endif  // ANDROID_V4L2_CODEC2_COMPONENTS_VIDEO_DECODER_H
45