blob: 9db394fe5bf8039f2800378e3eea7c0fafb05db3 [file] [log] [blame]
Pengfei Liuc181a982020-01-07 19:27:13 +08001#ifndef _SEGMENT_H_H_
2#define _SEGMENT_H_H_
3
4#ifdef __cplusplus
5extern "C" {
6#endif
7
8#include "dvr_common.h"
9
Pengfei Liub038b6a2020-01-14 15:57:01 +080010typedef void* Segment_Handle_t;
Pengfei Liuc181a982020-01-07 19:27:13 +080011
12typedef enum {
13 SEGMENT_MODE_READ,
14 SEGMENT_MODE_WRITE,
15 SEGMENT_MODE_MAX
16} Segment_OpenMode_t;
17
18typedef struct Segment_OpenParams_s {
19 char location[DVR_MAX_LOCATION_SIZE];
20 uint64_t segment_id;
21 Segment_OpenMode_t mode;
22} Segment_OpenParams_t;
23
24/**\brief Open a segment for a target giving some open parameters
25 * \param[out] p_handle Return the handle of the newly created segment
26 * \param[in] params Segment open parameters
27 * \return DVR_SUCCESS on success
28 * \return error code
29 */
30int segment_open(Segment_OpenParams_t *params, Segment_Handle_t *p_handle);
31
32/**\brief Close a segment
33 * \param[in] handle Segment handle
34 * \return DVR_SUCCESS on success
35 * \return error code
36 */
37int segment_close(Segment_Handle_t handle);
38
39/**\brief Read data from the giving segment
40 * \param[out] buf The buffer of data
41 * \param[in] handle Segment handle
42 * \param[in] count The data count
43 * \return The number of bytes read on success
44 * \return error code
45 */
46ssize_t segment_read(Segment_Handle_t handle, void *buf, size_t count);
47
48/**\brief Write data from the giving segment
49 * \param[in] buf The buffer of data
50 * \param[in] handle Segment handle
51 * \param[in] count The data count
52 * \return The number of bytes write on success
53 * \return error code
54 */
55ssize_t segment_write(Segment_Handle_t handle, void *buf, size_t count);
56
57/**\brief Update the pts and offset when record
58 * \param[in] handle Segment handle
59 * \param[in] pts Current pts
60 * \param[in] offset Current segment offset
61 * \return DVR_SUCCESS on success
62 * \return error code
63 */
64int segment_update_pts(Segment_Handle_t handle, uint64_t pts, off_t offset);
65
66/**\brief Seek the segment to the correct position which match the giving time
67 * \param[in] handle Segment handle
68 * \param[in] time The time offset
69 * \return The segment current read position on success
70 * \return error code
71 */
72off_t segment_seek(Segment_Handle_t handle, uint64_t time);
73
74/**\brief Tell the position for the giving segment
75 * \param[in] handle Segment handle
76 * \return The segment current read position on success
77 * \return error code
78 */
79off_t segment_tell(Segment_Handle_t handle);
80
81#ifdef __cplusplus
82}
83#endif
84
85#endif /*END _SEGMENT_H_H_*/