Apollo  6.0
Open source self driving car software
socket_input.h
Go to the documentation of this file.
1 /******************************************************************************
2  * Copyright 2019 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 #pragma once
18 
19 #include <unistd.h>
20 
21 #include <cstdio>
22 #include <map>
23 #include <memory>
24 #include <string>
25 
26 #include "cyber/cyber.h"
27 #include "modules/drivers/proto/sensor_image.pb.h"
28 
29 namespace apollo {
30 namespace drivers {
31 namespace video {
32 
33 static const int SOCKET_TIMEOUT = -2;
34 static const int RECEIVE_FAIL = -3;
35 static const int POLL_TIMEOUT = 1000; // one second (in msec)
36 static const size_t H265_FRAME_PACKAGE_SIZE = 4 * 1024 * 1024;
37 static const size_t H265_PDU_SIZE = 1500;
38 
40 class SocketInput {
41  public:
42  SocketInput();
43  virtual ~SocketInput();
44  void Init(uint32_t port);
45  int GetFramePacket(std::shared_ptr<CompressedImage> h265);
46 
47  private:
48  int sockfd_;
49  int port_;
50  uint8_t *buf_ = nullptr;
51  uint8_t *pdu_ = nullptr;
52  int pkg_num_;
53  int bytes_num_;
54  uint32_t frame_id_;
55  bool InputAvailable(int timeout);
56 };
57 
58 } // namespace video
59 } // namespace drivers
60 } // namespace apollo
Live Velodyne input from socket.
Definition: socket_input.h:40
PlanningContext is the runtime context in planning. It is persistent across multiple frames...
Definition: atomic_hash_map.h:25
int GetFramePacket(std::shared_ptr< CompressedImage > h265)