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*/ |
wentao.ma | 35a69d4 | 2022-03-10 18:08:40 +0800 | [diff] [blame] | 30 | DVR_Bool_t force_sysclock; /**< If ture, force to use system clock as PVR index time source. If false, libdvr can determine index time source based on actual situation*/ |
Pengfei Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 31 | } Segment_OpenParams_t; |
| 32 | |
| 33 | /**\brief Open a segment for a target giving some open parameters |
Pengfei Liu | b473423 | 2020-01-17 18:25:10 +0800 | [diff] [blame] | 34 | * \param[out] p_handle, Return the handle of the newly created segment |
| 35 | * \param[in] params, Segment open parameters |
Pengfei Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 36 | * \return DVR_SUCCESS on success |
Pengfei Liu | b473423 | 2020-01-17 18:25:10 +0800 | [diff] [blame] | 37 | * \return error code on failure |
Pengfei Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 38 | */ |
| 39 | int segment_open(Segment_OpenParams_t *params, Segment_Handle_t *p_handle); |
| 40 | |
| 41 | /**\brief Close a segment |
Pengfei Liu | b473423 | 2020-01-17 18:25:10 +0800 | [diff] [blame] | 42 | * \param[in] handle, Segment handle |
Pengfei Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 43 | * \return DVR_SUCCESS on success |
Pengfei Liu | b473423 | 2020-01-17 18:25:10 +0800 | [diff] [blame] | 44 | * \return error code on failure |
Pengfei Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 45 | */ |
| 46 | int segment_close(Segment_Handle_t handle); |
| 47 | |
| 48 | /**\brief Read data from the giving segment |
Pengfei Liu | b473423 | 2020-01-17 18:25:10 +0800 | [diff] [blame] | 49 | * \param[out] buf, The buffer of data |
| 50 | * \param[in] handle, Segment handle |
| 51 | * \param[in] count, The data count |
Pengfei Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 52 | * \return The number of bytes read on success |
Pengfei Liu | b473423 | 2020-01-17 18:25:10 +0800 | [diff] [blame] | 53 | * \return error code on failure |
Pengfei Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 54 | */ |
| 55 | ssize_t segment_read(Segment_Handle_t handle, void *buf, size_t count); |
| 56 | |
| 57 | /**\brief Write data from the giving segment |
Pengfei Liu | b473423 | 2020-01-17 18:25:10 +0800 | [diff] [blame] | 58 | * \param[in] buf, The buffer of data |
| 59 | * \param[in] handle, Segment handle |
| 60 | * \param[in] count, The data count |
Pengfei Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 61 | * \return The number of bytes write on success |
Pengfei Liu | b473423 | 2020-01-17 18:25:10 +0800 | [diff] [blame] | 62 | * \return error code on failure |
Pengfei Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 63 | */ |
| 64 | ssize_t segment_write(Segment_Handle_t handle, void *buf, size_t count); |
| 65 | |
hualing chen | 2932d37 | 2020-04-29 13:44:00 +0800 | [diff] [blame] | 66 | /**\brief force Update the pts and offset when record |
| 67 | * \param[in] handle, Segment handle |
| 68 | * \param[in] pts, Current pts |
| 69 | * \param[in] offset, Current segment offset |
| 70 | * \return DVR_SUCCESS on success |
| 71 | * \return error code on failure |
| 72 | */ |
| 73 | int segment_update_pts_force(Segment_Handle_t handle, uint64_t pts, loff_t offset); |
| 74 | |
| 75 | |
Pengfei Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 76 | /**\brief Update the pts and offset when record |
Pengfei Liu | b473423 | 2020-01-17 18:25:10 +0800 | [diff] [blame] | 77 | * \param[in] handle, Segment handle |
| 78 | * \param[in] pts, Current pts |
| 79 | * \param[in] offset, Current segment offset |
Pengfei Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 80 | * \return DVR_SUCCESS on success |
Pengfei Liu | b473423 | 2020-01-17 18:25:10 +0800 | [diff] [blame] | 81 | * \return error code on failure |
Pengfei Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 82 | */ |
Pengfei Liu | 3b1a820 | 2020-02-12 23:04:21 +0800 | [diff] [blame] | 83 | 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] | 84 | |
| 85 | /**\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] | 86 | * \param[in] handle, Segment handle |
| 87 | * \param[in] time, The time offset |
hualing chen | 266b950 | 2020-04-04 17:39:39 +0800 | [diff] [blame] | 88 | * \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] | 89 | * \return The segment current read position on success |
Pengfei Liu | b473423 | 2020-01-17 18:25:10 +0800 | [diff] [blame] | 90 | * \return error code on failure |
Pengfei Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 91 | */ |
hualing chen | 266b950 | 2020-04-04 17:39:39 +0800 | [diff] [blame] | 92 | 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] | 93 | |
Pengfei Liu | 3b1a820 | 2020-02-12 23:04:21 +0800 | [diff] [blame] | 94 | /**\brief Tell the current position for the giving segment |
Pengfei Liu | b473423 | 2020-01-17 18:25:10 +0800 | [diff] [blame] | 95 | * \param[in] handle, Segment handle |
Pengfei Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 96 | * \return The segment current read position on success |
Pengfei Liu | b473423 | 2020-01-17 18:25:10 +0800 | [diff] [blame] | 97 | * \return error code on failure |
Pengfei Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 98 | */ |
Pengfei Liu | 3b1a820 | 2020-02-12 23:04:21 +0800 | [diff] [blame] | 99 | loff_t segment_tell_position(Segment_Handle_t handle); |
| 100 | |
hualing chen | 5605eed | 2020-05-26 18:18:06 +0800 | [diff] [blame] | 101 | /**\brief Tell the giving position time for the giving segment, used for playback |
| 102 | * \param[in] handle, Segment handle |
| 103 | * \return The segment giving position time on success |
| 104 | * \return error code on failure |
| 105 | */ |
| 106 | uint64_t segment_tell_position_time(Segment_Handle_t handle, loff_t position); |
| 107 | |
pengfei.liu | 8b56329 | 2020-02-26 15:49:02 +0800 | [diff] [blame] | 108 | /**\brief Tell the current time for the giving segment, used for playback |
Pengfei Liu | 3b1a820 | 2020-02-12 23:04:21 +0800 | [diff] [blame] | 109 | * \param[in] handle, Segment handle |
| 110 | * \return The segment current time on success |
| 111 | * \return error code on failure |
| 112 | */ |
pengfei.liu | 8b56329 | 2020-02-26 15:49:02 +0800 | [diff] [blame] | 113 | uint64_t segment_tell_current_time(Segment_Handle_t handle); |
| 114 | |
| 115 | /**\brief Tell the total time for the giving segment |
| 116 | * \param[in] handle, Segment handle |
| 117 | * \return The segment total time on success |
| 118 | * \return error code on failure |
| 119 | */ |
| 120 | uint64_t segment_tell_total_time(Segment_Handle_t handle); |
Pengfei Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 121 | |
Pengfei Liu | b473423 | 2020-01-17 18:25:10 +0800 | [diff] [blame] | 122 | /**\brief Store the segment information to a file |
| 123 | * \param[in] handle, The segment handle |
| 124 | * \param[in] p_info, The segment information pointer |
| 125 | * \return DVR_SUCCESS On success |
| 126 | * \return Error code On failure |
| 127 | */ |
| 128 | int segment_store_info(Segment_Handle_t handle, Segment_StoreInfo_t *p_info); |
| 129 | |
hualing chen | b9a0292 | 2021-12-14 11:29:47 +0800 | [diff] [blame] | 130 | /**\brief Store the segment all information to a file |
| 131 | * \param[in] handle, The segment handle |
| 132 | * \param[in] p_info, The segment information pointer |
| 133 | * \return DVR_SUCCESS On success |
| 134 | * \return Error code On failure |
| 135 | */ |
| 136 | int segment_store_allInfo(Segment_Handle_t handle, Segment_StoreInfo_t *p_info); |
| 137 | |
Pengfei Liu | b473423 | 2020-01-17 18:25:10 +0800 | [diff] [blame] | 138 | /**\brief Load the segment information from a file |
| 139 | * \param[in] handle, The segment handle |
| 140 | * \param[out] p_info, The segment information pointer |
| 141 | * \return DVR_SUCCESS On success |
| 142 | * \return Error code On failure |
| 143 | */ |
| 144 | int segment_load_info(Segment_Handle_t handle, Segment_StoreInfo_t *p_info); |
| 145 | |
hualing chen | b9a0292 | 2021-12-14 11:29:47 +0800 | [diff] [blame] | 146 | /**\brief Load the segment information from a file |
| 147 | * \param[in] handle, The segment handle |
| 148 | * \param[out] p_info, The segment information pointer |
| 149 | * \return DVR_SUCCESS On success |
| 150 | * \return Error code On failure |
| 151 | */ |
| 152 | int segment_load_allInfo(Segment_Handle_t handle, struct list_head *list); |
| 153 | |
| 154 | |
Pengfei Liu | b473423 | 2020-01-17 18:25:10 +0800 | [diff] [blame] | 155 | /**\brief Delete the segment information file |
| 156 | * \param[in] location, The record file's location |
| 157 | * \param[in] segment_id, The segment's index |
| 158 | * \return DVR_SUCCESS On success |
| 159 | * \return Error code On failure |
| 160 | */ |
| 161 | int segment_delete(const char *location, uint64_t segment_id); |
| 162 | |
hualing chen | 87072a8 | 2020-03-12 16:20:12 +0800 | [diff] [blame] | 163 | /**\brief check the segment is ongoing file |
| 164 | * \param[in] handle, The segment handle |
| 165 | * \return DVR_SUCCESS On success |
| 166 | * \return Error code not ongoing |
| 167 | */ |
| 168 | int segment_ongoing(Segment_Handle_t handle); |
| 169 | |
| 170 | |
Pengfei Liu | c181a98 | 2020-01-07 19:27:13 +0800 | [diff] [blame] | 171 | #ifdef __cplusplus |
| 172 | } |
| 173 | #endif |
| 174 | |
| 175 | #endif /*END _SEGMENT_H_H_*/ |