blob: 6e5fa1016e22c9d5721facd176cc1d9e4678d1b4 [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"
Pengfei Liuc181a982020-01-07 19:27:13 +080014
Pengfei Liub4734232020-01-17 18:25:10 +080015/**\brief Segment handle*/
Pengfei Liub038b6a2020-01-14 15:57:01 +080016typedef void* Segment_Handle_t;
Pengfei Liuc181a982020-01-07 19:27:13 +080017
Pengfei Liub4734232020-01-17 18:25:10 +080018/**\brief Segment open mode*/
Pengfei Liuc181a982020-01-07 19:27:13 +080019typedef enum {
Pengfei Liub4734232020-01-17 18:25:10 +080020 SEGMENT_MODE_READ, /**< Segment open read mode*/
21 SEGMENT_MODE_WRITE, /**< Segment open write mode*/
22 SEGMENT_MODE_MAX /**< Segment invalid open mode*/
Pengfei Liuc181a982020-01-07 19:27:13 +080023} Segment_OpenMode_t;
24
Pengfei Liub4734232020-01-17 18:25:10 +080025/**\brief Segment open parameters*/
Pengfei Liuc181a982020-01-07 19:27:13 +080026typedef struct Segment_OpenParams_s {
Pengfei Liub4734232020-01-17 18:25:10 +080027 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.ma35a69d42022-03-10 18:08:40 +080030 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 Liuc181a982020-01-07 19:27:13 +080031} Segment_OpenParams_t;
32
33/**\brief Open a segment for a target giving some open parameters
Pengfei Liub4734232020-01-17 18:25:10 +080034 * \param[out] p_handle, Return the handle of the newly created segment
35 * \param[in] params, Segment open parameters
Pengfei Liuc181a982020-01-07 19:27:13 +080036 * \return DVR_SUCCESS on success
Pengfei Liub4734232020-01-17 18:25:10 +080037 * \return error code on failure
Pengfei Liuc181a982020-01-07 19:27:13 +080038 */
39int segment_open(Segment_OpenParams_t *params, Segment_Handle_t *p_handle);
40
41/**\brief Close a segment
Pengfei Liub4734232020-01-17 18:25:10 +080042 * \param[in] handle, Segment handle
Pengfei Liuc181a982020-01-07 19:27:13 +080043 * \return DVR_SUCCESS on success
Pengfei Liub4734232020-01-17 18:25:10 +080044 * \return error code on failure
Pengfei Liuc181a982020-01-07 19:27:13 +080045 */
46int segment_close(Segment_Handle_t handle);
47
48/**\brief Read data from the giving segment
Pengfei Liub4734232020-01-17 18:25:10 +080049 * \param[out] buf, The buffer of data
50 * \param[in] handle, Segment handle
51 * \param[in] count, The data count
Pengfei Liuc181a982020-01-07 19:27:13 +080052 * \return The number of bytes read on success
Pengfei Liub4734232020-01-17 18:25:10 +080053 * \return error code on failure
Pengfei Liuc181a982020-01-07 19:27:13 +080054 */
55ssize_t segment_read(Segment_Handle_t handle, void *buf, size_t count);
56
57/**\brief Write data from the giving segment
Pengfei Liub4734232020-01-17 18:25:10 +080058 * \param[in] buf, The buffer of data
59 * \param[in] handle, Segment handle
60 * \param[in] count, The data count
Pengfei Liuc181a982020-01-07 19:27:13 +080061 * \return The number of bytes write on success
Pengfei Liub4734232020-01-17 18:25:10 +080062 * \return error code on failure
Pengfei Liuc181a982020-01-07 19:27:13 +080063 */
64ssize_t segment_write(Segment_Handle_t handle, void *buf, size_t count);
65
hualing chen2932d372020-04-29 13:44:00 +080066/**\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 */
73int segment_update_pts_force(Segment_Handle_t handle, uint64_t pts, loff_t offset);
74
75
Pengfei Liuc181a982020-01-07 19:27:13 +080076/**\brief Update the pts and offset when record
Pengfei Liub4734232020-01-17 18:25:10 +080077 * \param[in] handle, Segment handle
78 * \param[in] pts, Current pts
79 * \param[in] offset, Current segment offset
Pengfei Liuc181a982020-01-07 19:27:13 +080080 * \return DVR_SUCCESS on success
Pengfei Liub4734232020-01-17 18:25:10 +080081 * \return error code on failure
Pengfei Liuc181a982020-01-07 19:27:13 +080082 */
Pengfei Liu3b1a8202020-02-12 23:04:21 +080083int segment_update_pts(Segment_Handle_t handle, uint64_t pts, loff_t offset);
Pengfei Liuc181a982020-01-07 19:27:13 +080084
85/**\brief Seek the segment to the correct position which match the giving time
Pengfei Liub4734232020-01-17 18:25:10 +080086 * \param[in] handle, Segment handle
87 * \param[in] time, The time offset
hualing chen266b9502020-04-04 17:39:39 +080088 * \param[in] block_size, if block_size is > 0, we need aligned to block_size-byte boundary
Pengfei Liuc181a982020-01-07 19:27:13 +080089 * \return The segment current read position on success
Pengfei Liub4734232020-01-17 18:25:10 +080090 * \return error code on failure
Pengfei Liuc181a982020-01-07 19:27:13 +080091 */
hualing chen266b9502020-04-04 17:39:39 +080092loff_t segment_seek(Segment_Handle_t handle, uint64_t time, int block_size);
Pengfei Liuc181a982020-01-07 19:27:13 +080093
Pengfei Liu3b1a8202020-02-12 23:04:21 +080094/**\brief Tell the current position for the giving segment
Pengfei Liub4734232020-01-17 18:25:10 +080095 * \param[in] handle, Segment handle
Pengfei Liuc181a982020-01-07 19:27:13 +080096 * \return The segment current read position on success
Pengfei Liub4734232020-01-17 18:25:10 +080097 * \return error code on failure
Pengfei Liuc181a982020-01-07 19:27:13 +080098 */
Pengfei Liu3b1a8202020-02-12 23:04:21 +080099loff_t segment_tell_position(Segment_Handle_t handle);
100
hualing chen5605eed2020-05-26 18:18:06 +0800101/**\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 */
106uint64_t segment_tell_position_time(Segment_Handle_t handle, loff_t position);
107
pengfei.liu8b563292020-02-26 15:49:02 +0800108/**\brief Tell the current time for the giving segment, used for playback
Pengfei Liu3b1a8202020-02-12 23:04:21 +0800109 * \param[in] handle, Segment handle
110 * \return The segment current time on success
111 * \return error code on failure
112 */
pengfei.liu8b563292020-02-26 15:49:02 +0800113uint64_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 */
120uint64_t segment_tell_total_time(Segment_Handle_t handle);
Pengfei Liuc181a982020-01-07 19:27:13 +0800121
Pengfei Liub4734232020-01-17 18:25:10 +0800122/**\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 */
128int segment_store_info(Segment_Handle_t handle, Segment_StoreInfo_t *p_info);
129
hualing chenb9a02922021-12-14 11:29:47 +0800130/**\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 */
136int segment_store_allInfo(Segment_Handle_t handle, Segment_StoreInfo_t *p_info);
137
Pengfei Liub4734232020-01-17 18:25:10 +0800138/**\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 */
144int segment_load_info(Segment_Handle_t handle, Segment_StoreInfo_t *p_info);
145
hualing chenb9a02922021-12-14 11:29:47 +0800146/**\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 */
152int segment_load_allInfo(Segment_Handle_t handle, struct list_head *list);
153
154
Pengfei Liub4734232020-01-17 18:25:10 +0800155/**\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 */
161int segment_delete(const char *location, uint64_t segment_id);
162
hualing chen87072a82020-03-12 16:20:12 +0800163/**\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 */
168int segment_ongoing(Segment_Handle_t handle);
169
Wentao MA907b6432022-08-01 06:23:08 +0000170/**\brief get current ongoing segment size
171 * \param[in] handle, The segment handle
172 * \return segment size
173 */
174off_t segment_get_cur_segment_size(Segment_Handle_t handle);
175
176/**\brief get current ongoing segment id
177 * \param[in] handle, The segment handle
178 * \return segment id
179 */
180uint64_t segment_get_cur_segment_id(Segment_Handle_t handle);
181
hualing chen87072a82020-03-12 16:20:12 +0800182
Pengfei Liuc181a982020-01-07 19:27:13 +0800183#ifdef __cplusplus
184}
185#endif
186
187#endif /*END _SEGMENT_H_H_*/