Scanner C++ API
decoder_automata.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/video/video_decoder.h"
19 
20 #include <condition_variable>
21 #include <memory>
22 #include <mutex>
23 #include <thread>
24 
25 namespace scanner {
26 namespace internal {
27 
29  DecoderAutomata() = delete;
30  DecoderAutomata(const DecoderAutomata&) = delete;
31  DecoderAutomata(const DecoderAutomata&& other) = delete;
32  DecoderAutomata(DeviceHandle device_handle, i32 num_devices,
33  VideoDecoderType decoder_type, VideoDecoder* decoder);
34 
35  public:
36  static DecoderAutomata* make_instance(DeviceHandle device_handle, i32 num_devices,
37  VideoDecoderType decoder_type);
38  ~DecoderAutomata();
39 
40  void initialize(const std::vector<proto::DecodeArgs>& encoded_data);
41 
42  void get_frames(u8* buffer, i32 num_frames);
43 
44  void set_profiler(Profiler* profiler);
45 
46  private:
47  void feeder();
48 
49  void set_feeder_idx(i32 data_idx);
50 
51  const i32 MAX_BUFFERED_FRAMES = 8;
52 
53  Profiler* profiler_ = nullptr;
54 
55  DeviceHandle device_handle_;
56  i32 num_devices_;
57  VideoDecoderType decoder_type_;
58  std::unique_ptr<VideoDecoder> decoder_;
59  std::atomic<bool> feeder_waiting_;
60  std::thread feeder_thread_;
61  std::atomic<bool> not_done_;
62 
63  FrameInfo info_{};
64  size_t frame_size_;
65  i32 current_frame_;
66  std::atomic<i32> reset_current_frame_;
67  std::vector<proto::DecodeArgs> encoded_data_;
68 
69  std::atomic<i64> next_frame_;
70  std::atomic<i64> frames_retrieved_;
71  std::atomic<i64> frames_to_get_;
72 
73  std::atomic<i32> retriever_data_idx_;
74  std::atomic<i32> retriever_valid_idx_;
75 
76  std::atomic<bool> skip_frames_;
77  std::atomic<bool> seeking_;
78  std::atomic<i32> feeder_data_idx_;
79  std::atomic<i64> feeder_valid_idx_;
80  std::atomic<i64> feeder_current_frame_;
81  std::atomic<i64> feeder_next_frame_;
82 
83  std::atomic<size_t> feeder_buffer_offset_;
84  std::atomic<i64> feeder_next_keyframe_;
85  std::mutex feeder_mutex_;
86  std::condition_variable wake_feeder_;
87 };
88 }
89 }
Definition: profiler.h:40
VideoDecoder.
Definition: video_decoder.h:38
Definition: common.h:53
Definition: database.cpp:36
FrameInfo.
Definition: frame.h:34
Definition: decoder_automata.h:28