Apollo 10.0
自动驾驶开放平台
player.h
浏览该文件的文档.
1/******************************************************************************
2 * Copyright 2018 The Apollo Authors. All Rights Reserved.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *****************************************************************************/
16
17#ifndef CYBER_TOOLS_CYBER_RECORDER_PLAYER_PLAYER_H_
18#define CYBER_TOOLS_CYBER_RECORDER_PLAYER_PLAYER_H_
19
20#include <atomic>
21#include <memory>
22#include <thread>
23
28#include "cyber/node/node.h"
29
30namespace apollo {
31namespace cyber {
32namespace record {
33
34class Player {
35 public:
36 using ConsumerPtr = std::unique_ptr<PlayTaskConsumer>;
37 using ProducerPtr = std::unique_ptr<PlayTaskProducer>;
38 using TaskBufferPtr = std::shared_ptr<PlayTaskBuffer>;
39 using NodePtr = std::shared_ptr<apollo::cyber::Node>;
40
41 Player(const PlayParam& play_param, const NodePtr& node = nullptr,
42 const bool preload_fill_buffer_mode = false);
43 virtual ~Player();
44
45 bool Init();
46 bool Start();
47 bool Stop();
52 bool Reset();
60 bool PreloadPlayRecord(const double& progress_s = 0,
61 bool paused_status = false);
65 void NohupPlayRecord();
70
71 private:
72 void ThreadFunc_Term();
77 bool ThreadFunc_Play_Nohup();
78
79 private:
80 std::atomic<bool> is_initialized_ = {false};
81 std::atomic<bool> is_stopped_ = {false};
82 std::atomic<bool> is_paused_ = {false};
83 std::atomic<bool> is_playonce_ = {false};
84 // is_preloaded_ is only used under nohup play mode to
85 // mark whether the task_buffer_ is preloaded.
86 std::atomic<bool> is_preloaded_ = {false};
87 ConsumerPtr consumer_;
88 ProducerPtr producer_;
89 TaskBufferPtr task_buffer_;
90 std::shared_ptr<std::thread> term_thread_ = nullptr;
91 // add nohup_play_th_ to allow background play record
92 std::shared_ptr<std::thread> nohup_play_th_ = nullptr;
93 static const uint64_t kSleepIntervalMiliSec;
94};
95
96} // namespace record
97} // namespace cyber
98} // namespace apollo
99
100#endif // CYBER_TOOLS_CYBER_RECORDER_PLAYER_PLAYER_H_
std::unique_ptr< PlayTaskConsumer > ConsumerPtr
Definition player.h:36
void HandleNohupThreadStatus()
Pause or continue to play record by change the nohup process status.
Definition player.cc:130
bool Reset()
Reset player for dv will repeatedly use
Definition player.cc:273
std::shared_ptr< PlayTaskBuffer > TaskBufferPtr
Definition player.h:38
void NohupPlayRecord()
set nohup process to play record.
Definition player.cc:148
std::unique_ptr< PlayTaskProducer > ProducerPtr
Definition player.h:37
bool PreloadPlayRecord(const double &progress_s=0, bool paused_status=false)
Preload the player,fill play_task_buffer ahead ofr time to ensure fast playback and avoid consumer wa...
Definition player.cc:152
std::shared_ptr< apollo::cyber::Node > NodePtr
Definition player.h:39
class register implement
Definition arena_queue.h:37