blob: 9481f688915808894a71bb7a8e21f8a93a39819f [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 */
72int segment_update_pts(Segment_Handle_t handle, uint64_t pts, off_t offset);
73
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
Pengfei Liuc181a982020-01-07 19:27:13 +080077 * \return The segment current read position on success
Pengfei Liub4734232020-01-17 18:25:10 +080078 * \return error code on failure
Pengfei Liuc181a982020-01-07 19:27:13 +080079 */
80off_t segment_seek(Segment_Handle_t handle, uint64_t time);
81
82/**\brief Tell the position for the giving segment
Pengfei Liub4734232020-01-17 18:25:10 +080083 * \param[in] handle, Segment handle
Pengfei Liuc181a982020-01-07 19:27:13 +080084 * \return The segment current read position on success
Pengfei Liub4734232020-01-17 18:25:10 +080085 * \return error code on failure
Pengfei Liuc181a982020-01-07 19:27:13 +080086 */
87off_t segment_tell(Segment_Handle_t handle);
88
Pengfei Liub4734232020-01-17 18:25:10 +080089/**\brief Store the segment information to a file
90 * \param[in] handle, The segment handle
91 * \param[in] p_info, The segment information pointer
92 * \return DVR_SUCCESS On success
93 * \return Error code On failure
94 */
95int segment_store_info(Segment_Handle_t handle, Segment_StoreInfo_t *p_info);
96
97/**\brief Load the segment information from a file
98 * \param[in] handle, The segment handle
99 * \param[out] p_info, The segment information pointer
100 * \return DVR_SUCCESS On success
101 * \return Error code On failure
102 */
103int segment_load_info(Segment_Handle_t handle, Segment_StoreInfo_t *p_info);
104
105/**\brief Delete the segment information file
106 * \param[in] location, The record file's location
107 * \param[in] segment_id, The segment's index
108 * \return DVR_SUCCESS On success
109 * \return Error code On failure
110 */
111int segment_delete(const char *location, uint64_t segment_id);
112
Pengfei Liuc181a982020-01-07 19:27:13 +0800113#ifdef __cplusplus
114}
115#endif
116
117#endif /*END _SEGMENT_H_H_*/