Scanner C++ API
video_encoder.h
1 /* Copyright 2016 Carnegie Mellon University
2  *
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #pragma once
17 
18 #include "scanner/api/kernel.h"
19 #include "scanner/engine/metadata.h"
20 #include "scanner/util/common.h"
21 #include "scanner/util/profiler.h"
22 
23 #include <vector>
24 
25 namespace scanner {
26 namespace internal {
27 
28 enum class VideoEncoderType {
29  NVIDIA,
30  INTEL,
31  SOFTWARE,
32 };
33 
34 struct EncodeOptions {
35  i32 quality = -1;
36  i64 bitrate = -1;
37  i64 keyframe_distance = -1;
38 };
39 
42 class VideoEncoder {
43  public:
44  static std::vector<VideoEncoderType> get_supported_encoder_types();
45 
46  static bool has_encoder_type(VideoEncoderType type);
47 
48  static VideoEncoder* make_from_config(DeviceHandle device_handle,
49  i32 num_devices, VideoEncoderType type);
50 
51  virtual ~VideoEncoder(){};
52 
53  virtual void configure(const FrameInfo& metadata,
54  const EncodeOptions& opts) = 0;
55 
56  virtual bool feed(const u8* frame_buffer, size_t frame_size) = 0;
57 
58  virtual bool flush() = 0;
59 
60  virtual bool get_packet(u8* decoded_buffer, size_t decoded_size,
61  size_t& actual_packet_size) = 0;
62 
63  virtual int decoded_packets_buffered() = 0;
64 
65  virtual void wait_until_packets_copied() = 0;
66 
67  void set_profiler(Profiler* profiler);
68 
69  protected:
70  Profiler* profiler_ = nullptr;
71 };
72 }
73 }
Definition: video_encoder.h:34
Definition: profiler.h:40
Definition: common.h:53
Definition: database.cpp:36
VideoEncoder.
Definition: video_encoder.h:42
FrameInfo.
Definition: frame.h:34