blob: 70babc107ae20b5761a7c2115ce7900ca0cdd013 [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
65/**\brief Update the pts and offset when record
Pengfei Liub4734232020-01-17 18:25:10 +080066 * \param[in] handle, Segment handle
67 * \param[in] pts, Current pts
68 * \param[in] offset, Current segment offset
Pengfei Liuc181a982020-01-07 19:27:13 +080069 * \return DVR_SUCCESS on success
Pengfei Liub4734232020-01-17 18:25:10 +080070 * \return error code on failure
Pengfei Liuc181a982020-01-07 19:27:13 +080071 */
Pengfei Liu3b1a8202020-02-12 23:04:21 +080072int segment_update_pts(Segment_Handle_t handle, uint64_t pts, loff_t offset);
Pengfei Liuc181a982020-01-07 19:27:13 +080073
74/**\brief Seek the segment to the correct position which match the giving time
Pengfei Liub4734232020-01-17 18:25:10 +080075 * \param[in] handle, Segment handle
76 * \param[in] time, The time offset
hualing chen266b9502020-04-04 17:39:39 +080077 * \param[in] block_size, if block_size is > 0, we need aligned to block_size-byte boundary
Pengfei Liuc181a982020-01-07 19:27:13 +080078 * \return The segment current read position on success
Pengfei Liub4734232020-01-17 18:25:10 +080079 * \return error code on failure
Pengfei Liuc181a982020-01-07 19:27:13 +080080 */
hualing chen266b9502020-04-04 17:39:39 +080081loff_t segment_seek(Segment_Handle_t handle, uint64_t time, int block_size);
Pengfei Liuc181a982020-01-07 19:27:13 +080082
Pengfei Liu3b1a8202020-02-12 23:04:21 +080083/**\brief Tell the current position for the giving segment
Pengfei Liub4734232020-01-17 18:25:10 +080084 * \param[in] handle, Segment handle
Pengfei Liuc181a982020-01-07 19:27:13 +080085 * \return The segment current read position on success
Pengfei Liub4734232020-01-17 18:25:10 +080086 * \return error code on failure
Pengfei Liuc181a982020-01-07 19:27:13 +080087 */
Pengfei Liu3b1a8202020-02-12 23:04:21 +080088loff_t segment_tell_position(Segment_Handle_t handle);
89
pengfei.liu8b563292020-02-26 15:49:02 +080090/**\brief Tell the current time for the giving segment, used for playback
Pengfei Liu3b1a8202020-02-12 23:04:21 +080091 * \param[in] handle, Segment handle
92 * \return The segment current time on success
93 * \return error code on failure
94 */
pengfei.liu8b563292020-02-26 15:49:02 +080095uint64_t segment_tell_current_time(Segment_Handle_t handle);
96
97/**\brief Tell the total time for the giving segment
98 * \param[in] handle, Segment handle
99 * \return The segment total time on success
100 * \return error code on failure
101 */
102uint64_t segment_tell_total_time(Segment_Handle_t handle);
Pengfei Liuc181a982020-01-07 19:27:13 +0800103
Pengfei Liub4734232020-01-17 18:25:10 +0800104/**\brief Store the segment information to a file
105 * \param[in] handle, The segment handle
106 * \param[in] p_info, The segment information pointer
107 * \return DVR_SUCCESS On success
108 * \return Error code On failure
109 */
110int segment_store_info(Segment_Handle_t handle, Segment_StoreInfo_t *p_info);
111
112/**\brief Load the segment information from a file
113 * \param[in] handle, The segment handle
114 * \param[out] p_info, The segment information pointer
115 * \return DVR_SUCCESS On success
116 * \return Error code On failure
117 */
118int segment_load_info(Segment_Handle_t handle, Segment_StoreInfo_t *p_info);
119
120/**\brief Delete the segment information file
121 * \param[in] location, The record file's location
122 * \param[in] segment_id, The segment's index
123 * \return DVR_SUCCESS On success
124 * \return Error code On failure
125 */
126int segment_delete(const char *location, uint64_t segment_id);
127
hualing chen87072a82020-03-12 16:20:12 +0800128/**\brief check the segment is ongoing file
129 * \param[in] handle, The segment handle
130 * \return DVR_SUCCESS On success
131 * \return Error code not ongoing
132 */
133int segment_ongoing(Segment_Handle_t handle);
134
135
Pengfei Liuc181a982020-01-07 19:27:13 +0800136#ifdef __cplusplus
137}
138#endif
139
140#endif /*END _SEGMENT_H_H_*/