blob: 6e60507b366723d44d48293fd157c23af9cae555 [file] [log] [blame]
Pengfei Liub4734232020-01-17 18:25:10 +08001/*
2 * \file
3 * Segment module
4 */
5
Pengfei Liuc181a982020-01-07 19:27:13 +08006#ifndef _SEGMENT_H_H_
7#define _SEGMENT_H_H_
8
9#ifdef __cplusplus
10extern "C" {
11#endif
12
Pengfei Liu47ed6c92020-01-17 11:23:41 +080013#include "dvr_types.h"
Zhiqiang Han2f019af2023-08-31 11:12:02 +080014#include "segment_ops.h"
Pengfei Liuc181a982020-01-07 19:27:13 +080015
16/**\brief Open a segment for a target giving some open parameters
Pengfei Liub4734232020-01-17 18:25:10 +080017 * \param[out] p_handle, Return the handle of the newly created segment
18 * \param[in] params, Segment open parameters
Pengfei Liuc181a982020-01-07 19:27:13 +080019 * \return DVR_SUCCESS on success
Pengfei Liub4734232020-01-17 18:25:10 +080020 * \return error code on failure
Pengfei Liuc181a982020-01-07 19:27:13 +080021 */
22int segment_open(Segment_OpenParams_t *params, Segment_Handle_t *p_handle);
23
24/**\brief Close a segment
Pengfei Liub4734232020-01-17 18:25:10 +080025 * \param[in] handle, Segment handle
Pengfei Liuc181a982020-01-07 19:27:13 +080026 * \return DVR_SUCCESS on success
Pengfei Liub4734232020-01-17 18:25:10 +080027 * \return error code on failure
Pengfei Liuc181a982020-01-07 19:27:13 +080028 */
29int segment_close(Segment_Handle_t handle);
30
31/**\brief Read data from the giving segment
Pengfei Liub4734232020-01-17 18:25:10 +080032 * \param[out] buf, The buffer of data
33 * \param[in] handle, Segment handle
34 * \param[in] count, The data count
Pengfei Liuc181a982020-01-07 19:27:13 +080035 * \return The number of bytes read on success
Pengfei Liub4734232020-01-17 18:25:10 +080036 * \return error code on failure
Pengfei Liuc181a982020-01-07 19:27:13 +080037 */
38ssize_t segment_read(Segment_Handle_t handle, void *buf, size_t count);
39
40/**\brief Write data from the giving segment
Pengfei Liub4734232020-01-17 18:25:10 +080041 * \param[in] buf, The buffer of data
42 * \param[in] handle, Segment handle
43 * \param[in] count, The data count
Pengfei Liuc181a982020-01-07 19:27:13 +080044 * \return The number of bytes write on success
Pengfei Liub4734232020-01-17 18:25:10 +080045 * \return error code on failure
Pengfei Liuc181a982020-01-07 19:27:13 +080046 */
47ssize_t segment_write(Segment_Handle_t handle, void *buf, size_t count);
48
hualing chen2932d372020-04-29 13:44:00 +080049/**\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 */
56int segment_update_pts_force(Segment_Handle_t handle, uint64_t pts, loff_t offset);
57
58
Pengfei Liuc181a982020-01-07 19:27:13 +080059/**\brief Update the pts and offset when record
Pengfei Liub4734232020-01-17 18:25:10 +080060 * \param[in] handle, Segment handle
61 * \param[in] pts, Current pts
62 * \param[in] offset, Current segment offset
Pengfei Liuc181a982020-01-07 19:27:13 +080063 * \return DVR_SUCCESS on success
Pengfei Liub4734232020-01-17 18:25:10 +080064 * \return error code on failure
Pengfei Liuc181a982020-01-07 19:27:13 +080065 */
Pengfei Liu3b1a8202020-02-12 23:04:21 +080066int segment_update_pts(Segment_Handle_t handle, uint64_t pts, loff_t offset);
Pengfei Liuc181a982020-01-07 19:27:13 +080067
68/**\brief Seek the segment to the correct position which match the giving time
Pengfei Liub4734232020-01-17 18:25:10 +080069 * \param[in] handle, Segment handle
70 * \param[in] time, The time offset
hualing chen266b9502020-04-04 17:39:39 +080071 * \param[in] block_size, if block_size is > 0, we need aligned to block_size-byte boundary
Pengfei Liuc181a982020-01-07 19:27:13 +080072 * \return The segment current read position on success
Pengfei Liub4734232020-01-17 18:25:10 +080073 * \return error code on failure
Pengfei Liuc181a982020-01-07 19:27:13 +080074 */
hualing chen266b9502020-04-04 17:39:39 +080075loff_t segment_seek(Segment_Handle_t handle, uint64_t time, int block_size);
Pengfei Liuc181a982020-01-07 19:27:13 +080076
Pengfei Liu3b1a8202020-02-12 23:04:21 +080077/**\brief Tell the current position for the giving segment
Pengfei Liub4734232020-01-17 18:25:10 +080078 * \param[in] handle, Segment handle
Pengfei Liuc181a982020-01-07 19:27:13 +080079 * \return The segment current read position on success
Pengfei Liub4734232020-01-17 18:25:10 +080080 * \return error code on failure
Pengfei Liuc181a982020-01-07 19:27:13 +080081 */
Pengfei Liu3b1a8202020-02-12 23:04:21 +080082loff_t segment_tell_position(Segment_Handle_t handle);
83
Wentao MAa3388532022-08-18 15:07:07 +080084/**\brief Tell position time of the given segment's postion. Function is used for playback.
hualing chen5605eed2020-05-26 18:18:06 +080085 * \param[in] handle, Segment handle
Wentao MAa3388532022-08-18 15:07:07 +080086 * \param[in] position, Segment's file position
87 * \return position time in ms on success, or -1 on failure
hualing chen5605eed2020-05-26 18:18:06 +080088 */
Wentao MAa3388532022-08-18 15:07:07 +080089loff_t segment_tell_position_time(Segment_Handle_t handle, loff_t position);
hualing chen5605eed2020-05-26 18:18:06 +080090
Wentao MAa3388532022-08-18 15:07:07 +080091/**\brief Tell current playback time of the given segment. Function is used for playback.
Pengfei Liu3b1a8202020-02-12 23:04:21 +080092 * \param[in] handle, Segment handle
Wentao MAa3388532022-08-18 15:07:07 +080093 * \return segment's current playback time in ms on success, or -1 on failure
Pengfei Liu3b1a8202020-02-12 23:04:21 +080094 */
Wentao MAa3388532022-08-18 15:07:07 +080095loff_t segment_tell_current_time(Segment_Handle_t handle);
pengfei.liu8b563292020-02-26 15:49:02 +080096
Wentao MAa3388532022-08-18 15:07:07 +080097/**\brief Tell total time of the given segment.
pengfei.liu8b563292020-02-26 15:49:02 +080098 * \param[in] handle, Segment handle
Wentao MAa3388532022-08-18 15:07:07 +080099 * \return The segment's total time in ms on success, or -1 on failure
pengfei.liu8b563292020-02-26 15:49:02 +0800100 */
Wentao MAa3388532022-08-18 15:07:07 +0800101loff_t segment_tell_total_time(Segment_Handle_t handle);
Pengfei Liuc181a982020-01-07 19:27:13 +0800102
Pengfei Liub4734232020-01-17 18:25:10 +0800103/**\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 */
109int segment_store_info(Segment_Handle_t handle, Segment_StoreInfo_t *p_info);
110
hualing chenb9a02922021-12-14 11:29:47 +0800111/**\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 */
117int segment_store_allInfo(Segment_Handle_t handle, Segment_StoreInfo_t *p_info);
118
Pengfei Liub4734232020-01-17 18:25:10 +0800119/**\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 */
125int segment_load_info(Segment_Handle_t handle, Segment_StoreInfo_t *p_info);
126
hualing chenb9a02922021-12-14 11:29:47 +0800127/**\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 */
133int segment_load_allInfo(Segment_Handle_t handle, struct list_head *list);
134
135
Pengfei Liub4734232020-01-17 18:25:10 +0800136/**\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 */
142int segment_delete(const char *location, uint64_t segment_id);
143
hualing chen87072a82020-03-12 16:20:12 +0800144/**\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 */
149int segment_ongoing(Segment_Handle_t handle);
150
Wentao MA907b6432022-08-01 06:23:08 +0000151/**\brief get current ongoing segment size
152 * \param[in] handle, The segment handle
153 * \return segment size
154 */
155off_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 */
161uint64_t segment_get_cur_segment_id(Segment_Handle_t handle);
162
hualing chen87072a82020-03-12 16:20:12 +0800163
Pengfei Liuc181a982020-01-07 19:27:13 +0800164#ifdef __cplusplus
165}
166#endif
167
168#endif /*END _SEGMENT_H_H_*/