blob: bcc2709904bd4814b1500bea7388c154179ffa36 [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
Wentao MAa3388532022-08-18 15:07:07 +0800101/**\brief Tell position time of the given segment's postion. Function is used for playback.
hualing chen5605eed2020-05-26 18:18:06 +0800102 * \param[in] handle, Segment handle
Wentao MAa3388532022-08-18 15:07:07 +0800103 * \param[in] position, Segment's file position
104 * \return position time in ms on success, or -1 on failure
hualing chen5605eed2020-05-26 18:18:06 +0800105 */
Wentao MAa3388532022-08-18 15:07:07 +0800106loff_t segment_tell_position_time(Segment_Handle_t handle, loff_t position);
hualing chen5605eed2020-05-26 18:18:06 +0800107
Wentao MAa3388532022-08-18 15:07:07 +0800108/**\brief Tell current playback time of the given segment. Function is used for playback.
Pengfei Liu3b1a8202020-02-12 23:04:21 +0800109 * \param[in] handle, Segment handle
Wentao MAa3388532022-08-18 15:07:07 +0800110 * \return segment's current playback time in ms on success, or -1 on failure
Pengfei Liu3b1a8202020-02-12 23:04:21 +0800111 */
Wentao MAa3388532022-08-18 15:07:07 +0800112loff_t segment_tell_current_time(Segment_Handle_t handle);
pengfei.liu8b563292020-02-26 15:49:02 +0800113
Wentao MAa3388532022-08-18 15:07:07 +0800114/**\brief Tell total time of the given segment.
pengfei.liu8b563292020-02-26 15:49:02 +0800115 * \param[in] handle, Segment handle
Wentao MAa3388532022-08-18 15:07:07 +0800116 * \return The segment's total time in ms on success, or -1 on failure
pengfei.liu8b563292020-02-26 15:49:02 +0800117 */
Wentao MAa3388532022-08-18 15:07:07 +0800118loff_t segment_tell_total_time(Segment_Handle_t handle);
Pengfei Liuc181a982020-01-07 19:27:13 +0800119
Pengfei Liub4734232020-01-17 18:25:10 +0800120/**\brief Store the segment information to a file
121 * \param[in] handle, The segment handle
122 * \param[in] p_info, The segment information pointer
123 * \return DVR_SUCCESS On success
124 * \return Error code On failure
125 */
126int segment_store_info(Segment_Handle_t handle, Segment_StoreInfo_t *p_info);
127
hualing chenb9a02922021-12-14 11:29:47 +0800128/**\brief Store the segment all information to a file
129 * \param[in] handle, The segment handle
130 * \param[in] p_info, The segment information pointer
131 * \return DVR_SUCCESS On success
132 * \return Error code On failure
133 */
134int segment_store_allInfo(Segment_Handle_t handle, Segment_StoreInfo_t *p_info);
135
Pengfei Liub4734232020-01-17 18:25:10 +0800136/**\brief Load the segment information from a file
137 * \param[in] handle, The segment handle
138 * \param[out] p_info, The segment information pointer
139 * \return DVR_SUCCESS On success
140 * \return Error code On failure
141 */
142int segment_load_info(Segment_Handle_t handle, Segment_StoreInfo_t *p_info);
143
hualing chenb9a02922021-12-14 11:29:47 +0800144/**\brief Load the segment information from a file
145 * \param[in] handle, The segment handle
146 * \param[out] p_info, The segment information pointer
147 * \return DVR_SUCCESS On success
148 * \return Error code On failure
149 */
150int segment_load_allInfo(Segment_Handle_t handle, struct list_head *list);
151
152
Pengfei Liub4734232020-01-17 18:25:10 +0800153/**\brief Delete the segment information file
154 * \param[in] location, The record file's location
155 * \param[in] segment_id, The segment's index
156 * \return DVR_SUCCESS On success
157 * \return Error code On failure
158 */
159int segment_delete(const char *location, uint64_t segment_id);
160
hualing chen87072a82020-03-12 16:20:12 +0800161/**\brief check the segment is ongoing file
162 * \param[in] handle, The segment handle
163 * \return DVR_SUCCESS On success
164 * \return Error code not ongoing
165 */
166int segment_ongoing(Segment_Handle_t handle);
167
Wentao MA907b6432022-08-01 06:23:08 +0000168/**\brief get current ongoing segment size
169 * \param[in] handle, The segment handle
170 * \return segment size
171 */
172off_t segment_get_cur_segment_size(Segment_Handle_t handle);
173
174/**\brief get current ongoing segment id
175 * \param[in] handle, The segment handle
176 * \return segment id
177 */
178uint64_t segment_get_cur_segment_id(Segment_Handle_t handle);
179
hualing chen87072a82020-03-12 16:20:12 +0800180
Pengfei Liuc181a982020-01-07 19:27:13 +0800181#ifdef __cplusplus
182}
183#endif
184
185#endif /*END _SEGMENT_H_H_*/