Pengfei Liu | b473423 | 2020-01-17 18:25:10 +0800 | [diff] [blame] | 1 | /* |
| 2 | * \file |
| 3 | * Segment module |
| 4 | */ |
| 5 | |
Pengfei Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 6 | #ifndef _SEGMENT_H_H_ |
| 7 | #define _SEGMENT_H_H_ |
| 8 | |
| 9 | #ifdef __cplusplus |
| 10 | extern "C" { |
| 11 | #endif |
| 12 | |
Pengfei Liu | 47ed6c9 | 2020-01-17 11:23:41 +0800 | [diff] [blame] | 13 | #include "dvr_types.h" |
Pengfei Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 14 | |
Pengfei Liu | b473423 | 2020-01-17 18:25:10 +0800 | [diff] [blame] | 15 | /**\brief Segment handle*/ |
Pengfei Liu | b038b6a | 2020-01-14 15:57:01 +0800 | [diff] [blame] | 16 | typedef void* Segment_Handle_t; |
Pengfei Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 17 | |
Pengfei Liu | b473423 | 2020-01-17 18:25:10 +0800 | [diff] [blame] | 18 | /**\brief Segment open mode*/ |
Pengfei Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 19 | typedef enum { |
Pengfei Liu | b473423 | 2020-01-17 18:25:10 +0800 | [diff] [blame] | 20 | SEGMENT_MODE_READ, /**< Segment open read mode*/ |
| 21 | SEGMENT_MODE_WRITE, /**< Segment open write mode*/ |
| 22 | SEGMENT_MODE_MAX /**< Segment invalid open mode*/ |
Pengfei Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 23 | } Segment_OpenMode_t; |
| 24 | |
Pengfei Liu | b473423 | 2020-01-17 18:25:10 +0800 | [diff] [blame] | 25 | /**\brief Segment open parameters*/ |
Pengfei Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 26 | typedef struct Segment_OpenParams_s { |
Pengfei Liu | b473423 | 2020-01-17 18:25:10 +0800 | [diff] [blame] | 27 | char location[DVR_MAX_LOCATION_SIZE]; /**< Segment file location*/ |
| 28 | uint64_t segment_id; /**< Segment index*/ |
| 29 | Segment_OpenMode_t mode; /**< Segment open mode*/ |
Pengfei Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 30 | } Segment_OpenParams_t; |
| 31 | |
| 32 | /**\brief Open a segment for a target giving some open parameters |
Pengfei Liu | b473423 | 2020-01-17 18:25:10 +0800 | [diff] [blame] | 33 | * \param[out] p_handle, Return the handle of the newly created segment |
| 34 | * \param[in] params, Segment open parameters |
Pengfei Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 35 | * \return DVR_SUCCESS on success |
Pengfei Liu | b473423 | 2020-01-17 18:25:10 +0800 | [diff] [blame] | 36 | * \return error code on failure |
Pengfei Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 37 | */ |
| 38 | int segment_open(Segment_OpenParams_t *params, Segment_Handle_t *p_handle); |
| 39 | |
| 40 | /**\brief Close a segment |
Pengfei Liu | b473423 | 2020-01-17 18:25:10 +0800 | [diff] [blame] | 41 | * \param[in] handle, Segment handle |
Pengfei Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 42 | * \return DVR_SUCCESS on success |
Pengfei Liu | b473423 | 2020-01-17 18:25:10 +0800 | [diff] [blame] | 43 | * \return error code on failure |
Pengfei Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 44 | */ |
| 45 | int segment_close(Segment_Handle_t handle); |
| 46 | |
| 47 | /**\brief Read data from the giving segment |
Pengfei Liu | b473423 | 2020-01-17 18:25:10 +0800 | [diff] [blame] | 48 | * \param[out] buf, The buffer of data |
| 49 | * \param[in] handle, Segment handle |
| 50 | * \param[in] count, The data count |
Pengfei Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 51 | * \return The number of bytes read on success |
Pengfei Liu | b473423 | 2020-01-17 18:25:10 +0800 | [diff] [blame] | 52 | * \return error code on failure |
Pengfei Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 53 | */ |
| 54 | ssize_t segment_read(Segment_Handle_t handle, void *buf, size_t count); |
| 55 | |
| 56 | /**\brief Write data from the giving segment |
Pengfei Liu | b473423 | 2020-01-17 18:25:10 +0800 | [diff] [blame] | 57 | * \param[in] buf, The buffer of data |
| 58 | * \param[in] handle, Segment handle |
| 59 | * \param[in] count, The data count |
Pengfei Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 60 | * \return The number of bytes write on success |
Pengfei Liu | b473423 | 2020-01-17 18:25:10 +0800 | [diff] [blame] | 61 | * \return error code on failure |
Pengfei Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 62 | */ |
| 63 | ssize_t segment_write(Segment_Handle_t handle, void *buf, size_t count); |
| 64 | |
hualing chen | 2932d37 | 2020-04-29 13:44:00 +0800 | [diff] [blame^] | 65 | /**\brief force Update the pts and offset when record |
| 66 | * \param[in] handle, Segment handle |
| 67 | * \param[in] pts, Current pts |
| 68 | * \param[in] offset, Current segment offset |
| 69 | * \return DVR_SUCCESS on success |
| 70 | * \return error code on failure |
| 71 | */ |
| 72 | int segment_update_pts_force(Segment_Handle_t handle, uint64_t pts, loff_t offset); |
| 73 | |
| 74 | |
Pengfei Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 75 | /**\brief Update the pts and offset when record |
Pengfei Liu | b473423 | 2020-01-17 18:25:10 +0800 | [diff] [blame] | 76 | * \param[in] handle, Segment handle |
| 77 | * \param[in] pts, Current pts |
| 78 | * \param[in] offset, Current segment offset |
Pengfei Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 79 | * \return DVR_SUCCESS on success |
Pengfei Liu | b473423 | 2020-01-17 18:25:10 +0800 | [diff] [blame] | 80 | * \return error code on failure |
Pengfei Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 81 | */ |
Pengfei Liu | 3b1a820 | 2020-02-12 23:04:21 +0800 | [diff] [blame] | 82 | int segment_update_pts(Segment_Handle_t handle, uint64_t pts, loff_t offset); |
Pengfei Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 83 | |
| 84 | /**\brief Seek the segment to the correct position which match the giving time |
Pengfei Liu | b473423 | 2020-01-17 18:25:10 +0800 | [diff] [blame] | 85 | * \param[in] handle, Segment handle |
| 86 | * \param[in] time, The time offset |
hualing chen | 266b950 | 2020-04-04 17:39:39 +0800 | [diff] [blame] | 87 | * \param[in] block_size, if block_size is > 0, we need aligned to block_size-byte boundary |
Pengfei Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 88 | * \return The segment current read position on success |
Pengfei Liu | b473423 | 2020-01-17 18:25:10 +0800 | [diff] [blame] | 89 | * \return error code on failure |
Pengfei Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 90 | */ |
hualing chen | 266b950 | 2020-04-04 17:39:39 +0800 | [diff] [blame] | 91 | loff_t segment_seek(Segment_Handle_t handle, uint64_t time, int block_size); |
Pengfei Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 92 | |
Pengfei Liu | 3b1a820 | 2020-02-12 23:04:21 +0800 | [diff] [blame] | 93 | /**\brief Tell the current position for the giving segment |
Pengfei Liu | b473423 | 2020-01-17 18:25:10 +0800 | [diff] [blame] | 94 | * \param[in] handle, Segment handle |
Pengfei Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 95 | * \return The segment current read position on success |
Pengfei Liu | b473423 | 2020-01-17 18:25:10 +0800 | [diff] [blame] | 96 | * \return error code on failure |
Pengfei Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 97 | */ |
Pengfei Liu | 3b1a820 | 2020-02-12 23:04:21 +0800 | [diff] [blame] | 98 | loff_t segment_tell_position(Segment_Handle_t handle); |
| 99 | |
pengfei.liu | 8b56329 | 2020-02-26 15:49:02 +0800 | [diff] [blame] | 100 | /**\brief Tell the current time for the giving segment, used for playback |
Pengfei Liu | 3b1a820 | 2020-02-12 23:04:21 +0800 | [diff] [blame] | 101 | * \param[in] handle, Segment handle |
| 102 | * \return The segment current time on success |
| 103 | * \return error code on failure |
| 104 | */ |
pengfei.liu | 8b56329 | 2020-02-26 15:49:02 +0800 | [diff] [blame] | 105 | uint64_t segment_tell_current_time(Segment_Handle_t handle); |
| 106 | |
| 107 | /**\brief Tell the total time for the giving segment |
| 108 | * \param[in] handle, Segment handle |
| 109 | * \return The segment total time on success |
| 110 | * \return error code on failure |
| 111 | */ |
| 112 | uint64_t segment_tell_total_time(Segment_Handle_t handle); |
Pengfei Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 113 | |
Pengfei Liu | b473423 | 2020-01-17 18:25:10 +0800 | [diff] [blame] | 114 | /**\brief Store the segment information to a file |
| 115 | * \param[in] handle, The segment handle |
| 116 | * \param[in] p_info, The segment information pointer |
| 117 | * \return DVR_SUCCESS On success |
| 118 | * \return Error code On failure |
| 119 | */ |
| 120 | int segment_store_info(Segment_Handle_t handle, Segment_StoreInfo_t *p_info); |
| 121 | |
| 122 | /**\brief Load the segment information from a file |
| 123 | * \param[in] handle, The segment handle |
| 124 | * \param[out] p_info, The segment information pointer |
| 125 | * \return DVR_SUCCESS On success |
| 126 | * \return Error code On failure |
| 127 | */ |
| 128 | int segment_load_info(Segment_Handle_t handle, Segment_StoreInfo_t *p_info); |
| 129 | |
| 130 | /**\brief Delete the segment information file |
| 131 | * \param[in] location, The record file's location |
| 132 | * \param[in] segment_id, The segment's index |
| 133 | * \return DVR_SUCCESS On success |
| 134 | * \return Error code On failure |
| 135 | */ |
| 136 | int segment_delete(const char *location, uint64_t segment_id); |
| 137 | |
hualing chen | 87072a8 | 2020-03-12 16:20:12 +0800 | [diff] [blame] | 138 | /**\brief check the segment is ongoing file |
| 139 | * \param[in] handle, The segment handle |
| 140 | * \return DVR_SUCCESS On success |
| 141 | * \return Error code not ongoing |
| 142 | */ |
| 143 | int segment_ongoing(Segment_Handle_t handle); |
| 144 | |
| 145 | |
Pengfei Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 146 | #ifdef __cplusplus |
| 147 | } |
| 148 | #endif |
| 149 | |
| 150 | #endif /*END _SEGMENT_H_H_*/ |