Apollo 10.0
自动驾驶开放平台
play_task_producer.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_PLAY_TASK_PRODUCER_H_
18#define CYBER_TOOLS_CYBER_RECORDER_PLAYER_PLAY_TASK_PRODUCER_H_
19
20#include <atomic>
21#include <cstdint>
22#include <map>
23#include <memory>
24#include <mutex>
25#include <string>
26#include <thread>
27#include <unordered_map>
28#include <vector>
29
31#include "cyber/node/node.h"
32#include "cyber/node/writer.h"
36#include "cyber/proto/record.pb.h"
38
39namespace apollo {
40namespace cyber {
41namespace record {
42
43using ::apollo::cyber::proto::RecordInfo;
44
46 public:
47 using NodePtr = std::shared_ptr<Node>;
48 using ThreadPtr = std::unique_ptr<std::thread>;
49 using TaskBufferPtr = std::shared_ptr<PlayTaskBuffer>;
50 using RecordReaderPtr = std::shared_ptr<RecordReader>;
51 using WriterPtr = std::shared_ptr<Writer<message::RawMessage>>;
52 using WriterMap = std::unordered_map<std::string, WriterPtr>;
53 using MessageTypeMap = std::unordered_map<std::string, std::string>;
54 using RecordViewerPtr = std::shared_ptr<RecordViewer>;
55
56 PlayTaskProducer(const TaskBufferPtr& task_buffer,
57 const PlayParam& play_param,
58 const NodePtr& node = nullptr,
59 const bool preload_fill_buffer_mode = false);
60 virtual ~PlayTaskProducer();
61
62 bool Init();
63 void Start();
64 void Stop();
65
66 const PlayParam& play_param() const { return play_param_; }
67 bool is_stopped() const { return is_stopped_.load(); }
68 bool is_initialized() const { return is_initialized_.load(); }
69 void set_stopped() { is_stopped_.exchange(true); }
70 void WriteRecordProgress(const double& curr_time_s,
71 const double& total_time_s);
76 void FillPlayTaskBuffer();
81 void Reset(const double& progress_time_s);
82
83 private:
84 bool ReadRecordInfo();
85 bool UpdatePlayParam();
86 bool CreateWriters();
87 bool CreatePlayTaskWriter(const std::string& channel_name,
88 const std::string& msg_type);
89 void ThreadFunc();
90 void ThreadFuncUnderPreloadMode();
91
92 PlayParam play_param_;
93 TaskBufferPtr task_buffer_;
94 ThreadPtr produce_th_;
95
96 std::atomic<bool> is_initialized_;
97 std::atomic<bool> is_stopped_;
98
99 NodePtr node_;
100 WriterMap writers_;
101 MessageTypeMap msg_types_;
102 std::vector<RecordReaderPtr> record_readers_;
103 RecordViewerPtr record_viewer_ptr_;
104
105 uint64_t earliest_begin_time_;
106 uint64_t latest_end_time_;
107 uint64_t total_msg_num_;
108
109 // This parameter indicates whether the producer needs to preload the buffer
110 // When this value is true, it means that we preload the buffer before playing
111 // we use it when dv play record under nohup process,all record player related
112 // to the same node,so when this value is true,we pass parameter node to
113 // assign value to node_
114 bool preload_fill_buffer_mode_;
115
116 static const uint32_t kMinTaskBufferSize;
117 static const uint32_t kPreloadTimeSec;
118 static const uint64_t kSleepIntervalNanoSec;
119};
120
121} // namespace record
122} // namespace cyber
123} // namespace apollo
124
125#endif // CYBER_TOOLS_CYBER_RECORDER_PLAYER_PLAY_TASK_PRODUCER_H_
std::unordered_map< std::string, WriterPtr > WriterMap
std::shared_ptr< RecordReader > RecordReaderPtr
void WriteRecordProgress(const double &curr_time_s, const double &total_time_s)
std::shared_ptr< PlayTaskBuffer > TaskBufferPtr
std::shared_ptr< RecordViewer > RecordViewerPtr
std::unique_ptr< std::thread > ThreadPtr
std::shared_ptr< Writer< message::RawMessage > > WriterPtr
void FillPlayTaskBuffer()
Preload the player,producer fill play_task_buffer before playing.
void Reset(const double &progress_time_s)
Reset player producer for dv will repeatedly use it.
std::unordered_map< std::string, std::string > MessageTypeMap
class register implement
Definition arena_queue.h:37