blob: 19f0d60ee92ccab187db42a5cf04bab0586819ff [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*/
Pengfei Liuc181a982020-01-07 19:27:13 +080030} Segment_OpenParams_t;
31
32/**\brief Open a segment for a target giving some open parameters
Pengfei Liub4734232020-01-17 18:25:10 +080033 * \param[out] p_handle, Return the handle of the newly created segment
34 * \param[in] params, Segment open parameters
Pengfei Liuc181a982020-01-07 19:27:13 +080035 * \return DVR_SUCCESS on success
Pengfei Liub4734232020-01-17 18:25:10 +080036 * \return error code on failure
Pengfei Liuc181a982020-01-07 19:27:13 +080037 */
38int segment_open(Segment_OpenParams_t *params, Segment_Handle_t *p_handle);
39
40/**\brief Close a segment
Pengfei Liub4734232020-01-17 18:25:10 +080041 * \param[in] handle, Segment handle
Pengfei Liuc181a982020-01-07 19:27:13 +080042 * \return DVR_SUCCESS on success
Pengfei Liub4734232020-01-17 18:25:10 +080043 * \return error code on failure
Pengfei Liuc181a982020-01-07 19:27:13 +080044 */
45int segment_close(Segment_Handle_t handle);
46
47/**\brief Read data from the giving segment
Pengfei Liub4734232020-01-17 18:25:10 +080048 * \param[out] buf, The buffer of data
49 * \param[in] handle, Segment handle
50 * \param[in] count, The data count
Pengfei Liuc181a982020-01-07 19:27:13 +080051 * \return The number of bytes read on success
Pengfei Liub4734232020-01-17 18:25:10 +080052 * \return error code on failure
Pengfei Liuc181a982020-01-07 19:27:13 +080053 */
54ssize_t segment_read(Segment_Handle_t handle, void *buf, size_t count);
55
56/**\brief Write data from the giving segment
Pengfei Liub4734232020-01-17 18:25:10 +080057 * \param[in] buf, The buffer of data
58 * \param[in] handle, Segment handle
59 * \param[in] count, The data count
Pengfei Liuc181a982020-01-07 19:27:13 +080060 * \return The number of bytes write on success
Pengfei Liub4734232020-01-17 18:25:10 +080061 * \return error code on failure
Pengfei Liuc181a982020-01-07 19:27:13 +080062 */
63ssize_t segment_write(Segment_Handle_t handle, void *buf, size_t count);
64
hualing chen2932d372020-04-29 13:44:00 +080065/**\brief force Update the pts and offset when record
66 * \param[in] handle, Segment handle
67 * \param[in] pts, Current pts
68 * \param[in] offset, Current segment offset
69 * \return DVR_SUCCESS on success
70 * \return error code on failure
71 */
72int segment_update_pts_force(Segment_Handle_t handle, uint64_t pts, loff_t offset);
73
74
Pengfei Liuc181a982020-01-07 19:27:13 +080075/**\brief Update the pts and offset when record
Pengfei Liub4734232020-01-17 18:25:10 +080076 * \param[in] handle, Segment handle
77 * \param[in] pts, Current pts
78 * \param[in] offset, Current segment offset
Pengfei Liuc181a982020-01-07 19:27:13 +080079 * \return DVR_SUCCESS 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 +080082int segment_update_pts(Segment_Handle_t handle, uint64_t pts, loff_t offset);
Pengfei Liuc181a982020-01-07 19:27:13 +080083
84/**\brief Seek the segment to the correct position which match the giving time
Pengfei Liub4734232020-01-17 18:25:10 +080085 * \param[in] handle, Segment handle
86 * \param[in] time, The time offset
hualing chen266b9502020-04-04 17:39:39 +080087 * \param[in] block_size, if block_size is > 0, we need aligned to block_size-byte boundary
Pengfei Liuc181a982020-01-07 19:27:13 +080088 * \return The segment current read position on success
Pengfei Liub4734232020-01-17 18:25:10 +080089 * \return error code on failure
Pengfei Liuc181a982020-01-07 19:27:13 +080090 */
hualing chen266b9502020-04-04 17:39:39 +080091loff_t segment_seek(Segment_Handle_t handle, uint64_t time, int block_size);
Pengfei Liuc181a982020-01-07 19:27:13 +080092
Pengfei Liu3b1a8202020-02-12 23:04:21 +080093/**\brief Tell the current position for the giving segment
Pengfei Liub4734232020-01-17 18:25:10 +080094 * \param[in] handle, Segment handle
Pengfei Liuc181a982020-01-07 19:27:13 +080095 * \return The segment current read position on success
Pengfei Liub4734232020-01-17 18:25:10 +080096 * \return error code on failure
Pengfei Liuc181a982020-01-07 19:27:13 +080097 */
Pengfei Liu3b1a8202020-02-12 23:04:21 +080098loff_t segment_tell_position(Segment_Handle_t handle);
99
pengfei.liu8b563292020-02-26 15:49:02 +0800100/**\brief Tell the current time for the giving segment, used for playback
Pengfei Liu3b1a8202020-02-12 23:04:21 +0800101 * \param[in] handle, Segment handle
102 * \return The segment current time on success
103 * \return error code on failure
104 */
pengfei.liu8b563292020-02-26 15:49:02 +0800105uint64_t segment_tell_current_time(Segment_Handle_t handle);
106
107/**\brief Tell the total time for the giving segment
108 * \param[in] handle, Segment handle
109 * \return The segment total time on success
110 * \return error code on failure
111 */
112uint64_t segment_tell_total_time(Segment_Handle_t handle);
Pengfei Liuc181a982020-01-07 19:27:13 +0800113
Pengfei Liub4734232020-01-17 18:25:10 +0800114/**\brief Store the segment information to a file
115 * \param[in] handle, The segment handle
116 * \param[in] p_info, The segment information pointer
117 * \return DVR_SUCCESS On success
118 * \return Error code On failure
119 */
120int segment_store_info(Segment_Handle_t handle, Segment_StoreInfo_t *p_info);
121
122/**\brief Load the segment information from a file
123 * \param[in] handle, The segment handle
124 * \param[out] p_info, The segment information pointer
125 * \return DVR_SUCCESS On success
126 * \return Error code On failure
127 */
128int segment_load_info(Segment_Handle_t handle, Segment_StoreInfo_t *p_info);
129
130/**\brief Delete the segment information file
131 * \param[in] location, The record file's location
132 * \param[in] segment_id, The segment's index
133 * \return DVR_SUCCESS On success
134 * \return Error code On failure
135 */
136int segment_delete(const char *location, uint64_t segment_id);
137
hualing chen87072a82020-03-12 16:20:12 +0800138/**\brief check the segment is ongoing file
139 * \param[in] handle, The segment handle
140 * \return DVR_SUCCESS On success
141 * \return Error code not ongoing
142 */
143int segment_ongoing(Segment_Handle_t handle);
144
145
Pengfei Liuc181a982020-01-07 19:27:13 +0800146#ifdef __cplusplus
147}
148#endif
149
150#endif /*END _SEGMENT_H_H_*/