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