blob: 79aacebc1244469e8a5b5cf40946c66e3f2ef5b4 [file] [log] [blame]
Zhiqiang Han2f019af2023-08-31 11:12:02 +08001/*
2 * \file
3 * Segment module
4 */
5
6#ifndef _SEGMENT_OPS_H_
7#define _SEGMENT_OPS_H_
8
9#ifdef __cplusplus
10extern "C" {
11#endif
12
13#include "dvr_types.h"
14
15/**\brief Segment handle*/
16typedef void* Segment_Handle_t;
17
18/**\brief Segment open mode*/
19typedef enum {
20 SEGMENT_MODE_READ, /**< Segment open read mode*/
21 SEGMENT_MODE_WRITE, /**< Segment open write mode*/
22 SEGMENT_MODE_MAX /**< Segment invalid open mode*/
23} Segment_OpenMode_t;
24
25/**\brief Segment open parameters*/
26typedef struct Segment_OpenParams_s {
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*/
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*/
31} Segment_OpenParams_t;
32
33typedef struct Segment_Ops_s {
34
35 /**\brief Open a segment for a target giving some open parameters
36 * \param[out] p_handle, Return the handle of the newly created segment
37 * \param[in] params, Segment open parameters
38 * \return DVR_SUCCESS on success
39 * \return error code on failure
40 */
41 int (*segment_open)(Segment_OpenParams_t *params, Segment_Handle_t *p_handle);
42
43 /**\brief Close a segment
44 * \param[in] handle, Segment handle
45 * \return DVR_SUCCESS on success
46 * \return error code on failure
47 */
48 int (*segment_close)(Segment_Handle_t handle);
49
50 /**\brief control the giving segment
51 * \param[in] handle, Segment handle
52 * \param[in] cmd, The control command
53 * \param[in] data, The control data
54 * \param[in] size, Size of the control data
55 * \return DVR_SUCCESS on success
56 * \return error code on failure
57 */
58 int (*segment_ioctl)(Segment_Handle_t handle, int cmd, void *data, size_t size);
59
60 /**\brief Read data from the giving segment
61 * \param[out] buf, The buffer of data
62 * \param[in] handle, Segment handle
63 * \param[in] count, The data count
64 * \return The number of bytes read on success
65 * \return error code on failure
66 */
67 ssize_t (*segment_read)(Segment_Handle_t handle, void *buf, size_t count);
68
69 /**\brief Write data from the giving segment
70 * \param[in] buf, The buffer of data
71 * \param[in] handle, Segment handle
72 * \param[in] count, The data count
73 * \return The number of bytes write on success
74 * \return error code on failure
75 */
76 ssize_t (*segment_write)(Segment_Handle_t handle, void *buf, size_t count);
77
78 /**\brief force Update the pts and offset when record
79 * \param[in] handle, Segment handle
80 * \param[in] pts, Current pts
81 * \param[in] offset, Current segment offset
82 * \return DVR_SUCCESS on success
83 * \return error code on failure
84 */
85 int (*segment_update_pts_force)(Segment_Handle_t handle, uint64_t pts, loff_t offset);
86
87
88 /**\brief Update the pts and offset when record
89 * \param[in] handle, Segment handle
90 * \param[in] pts, Current pts
91 * \param[in] offset, Current segment offset
92 * \return DVR_SUCCESS on success
93 * \return error code on failure
94 */
95 int (*segment_update_pts)(Segment_Handle_t handle, uint64_t pts, loff_t offset);
96
97 /**\brief Seek the segment to the correct position which match the giving time
98 * \param[in] handle, Segment handle
99 * \param[in] time, The time offset
100 * \param[in] block_size, if block_size is > 0, we need aligned to block_size-byte boundary
101 * \return The segment current read position on success
102 * \return error code on failure
103 */
104 loff_t (*segment_seek)(Segment_Handle_t handle, uint64_t time, int block_size);
105
106 /**\brief Tell the current position for the giving segment
107 * \param[in] handle, Segment handle
108 * \return The segment current read position on success
109 * \return error code on failure
110 */
111 loff_t (*segment_tell_position)(Segment_Handle_t handle);
112
113 /**\brief Tell position time of the given segment's postion. Function is used for playback.
114 * \param[in] handle, Segment handle
115 * \param[in] position, Segment's file position
116 * \return position time in ms on success, or -1 on failure
117 */
118 loff_t (*segment_tell_position_time)(Segment_Handle_t handle, loff_t position);
119
120 /**\brief Tell current playback time of the given segment. Function is used for playback.
121 * \param[in] handle, Segment handle
122 * \return segment's current playback time in ms on success, or -1 on failure
123 */
124 loff_t (*segment_tell_current_time)(Segment_Handle_t handle);
125
126 /**\brief Tell total time of the given segment.
127 * \param[in] handle, Segment handle
128 * \return The segment's total time in ms on success, or -1 on failure
129 */
130 loff_t (*segment_tell_total_time)(Segment_Handle_t handle);
131
132 /**\brief Store the segment information to a file
133 * \param[in] handle, The segment handle
134 * \param[in] p_info, The segment information pointer
135 * \return DVR_SUCCESS On success
136 * \return Error code On failure
137 */
138 int (*segment_store_info)(Segment_Handle_t handle, Segment_StoreInfo_t *p_info);
139
140 /**\brief Store the segment all information to a file
141 * \param[in] handle, The segment handle
142 * \param[in] p_info, The segment information pointer
143 * \return DVR_SUCCESS On success
144 * \return Error code On failure
145 */
146 int (*segment_store_allInfo)(Segment_Handle_t handle, Segment_StoreInfo_t *p_info);
147
148 /**\brief Load the segment information from a file
149 * \param[in] handle, The segment handle
150 * \param[out] p_info, The segment information pointer
151 * \return DVR_SUCCESS On success
152 * \return Error code On failure
153 */
154 int (*segment_load_info)(Segment_Handle_t handle, Segment_StoreInfo_t *p_info);
155
156 /**\brief Load the segment information from a file
157 * \param[in] handle, The segment handle
158 * \param[out] p_info, The segment information pointer
159 * \return DVR_SUCCESS On success
160 * \return Error code On failure
161 */
162 int (*segment_load_allInfo)(Segment_Handle_t handle, struct list_head *list);
163
164
165 /**\brief Delete the segment information file
166 * \param[in] location, The record file's location
167 * \param[in] segment_id, The segment's index
168 * \return DVR_SUCCESS On success
169 * \return Error code On failure
170 */
171 int (*segment_delete)(const char *location, uint64_t segment_id);
172
173 /**\brief check the segment is ongoing file
174 * \param[in] handle, The segment handle
175 * \return DVR_SUCCESS On success
176 * \return Error code not ongoing
177 */
178 int (*segment_ongoing)(Segment_Handle_t handle);
179
180 /**\brief get current ongoing segment size
181 * \param[in] handle, The segment handle
182 * \return segment size
183 */
184 off_t (*segment_get_cur_segment_size)(Segment_Handle_t handle);
185
186 /**\brief get current ongoing segment id
187 * \param[in] handle, The segment handle
188 * \return segment id
189 */
190 uint64_t (*segment_get_cur_segment_id)(Segment_Handle_t handle);
191} Segment_Ops_t;
192
193#ifdef __cplusplus
194}
195#endif
196
197#endif /*END _SEGMENT_H_H_*/