blob: ee0011ca3aaa6808b5045a5fe670e5f73d23f6a1 [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
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 */
Pengfei Liu3b1a8202020-02-12 23:04:21 +080080loff_t segment_seek(Segment_Handle_t handle, uint64_t time);
Pengfei Liuc181a982020-01-07 19:27:13 +080081
Pengfei Liu3b1a8202020-02-12 23:04:21 +080082/**\brief Tell the current 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 */
Pengfei Liu3b1a8202020-02-12 23:04:21 +080087loff_t segment_tell_position(Segment_Handle_t handle);
88
pengfei.liu8b563292020-02-26 15:49:02 +080089/**\brief Tell the current time for the giving segment, used for playback
Pengfei Liu3b1a8202020-02-12 23:04:21 +080090 * \param[in] handle, Segment handle
91 * \return The segment current time on success
92 * \return error code on failure
93 */
pengfei.liu8b563292020-02-26 15:49:02 +080094uint64_t segment_tell_current_time(Segment_Handle_t handle);
95
96/**\brief Tell the total time for the giving segment
97 * \param[in] handle, Segment handle
98 * \return The segment total time on success
99 * \return error code on failure
100 */
101uint64_t segment_tell_total_time(Segment_Handle_t handle);
Pengfei Liuc181a982020-01-07 19:27:13 +0800102
Pengfei Liub4734232020-01-17 18:25:10 +0800103/**\brief Store the segment information to a file
104 * \param[in] handle, The segment handle
105 * \param[in] p_info, The segment information pointer
106 * \return DVR_SUCCESS On success
107 * \return Error code On failure
108 */
109int segment_store_info(Segment_Handle_t handle, Segment_StoreInfo_t *p_info);
110
111/**\brief Load the segment information from a file
112 * \param[in] handle, The segment handle
113 * \param[out] p_info, The segment information pointer
114 * \return DVR_SUCCESS On success
115 * \return Error code On failure
116 */
117int segment_load_info(Segment_Handle_t handle, Segment_StoreInfo_t *p_info);
118
119/**\brief Delete the segment information file
120 * \param[in] location, The record file's location
121 * \param[in] segment_id, The segment's index
122 * \return DVR_SUCCESS On success
123 * \return Error code On failure
124 */
125int segment_delete(const char *location, uint64_t segment_id);
126
Pengfei Liuc181a982020-01-07 19:27:13 +0800127#ifdef __cplusplus
128}
129#endif
130
131#endif /*END _SEGMENT_H_H_*/