blob: 94a564a6874b3e28ceee41a67aefa09185b05782 [file] [log] [blame]
Gong Ke3489c0f2020-01-16 18:11:44 +08001/**
2 * \file
Gong Ke497c4c22020-03-20 10:15:42 +08003 * \brief Playback module.
Gong Ke3489c0f2020-01-16 18:11:44 +08004 */
5
hualing chenb31a6c62020-01-13 17:27:00 +08006#ifndef DVR_PLAYBACK_H_
7#define DVR_PLAYBACK_H_
hualing chenb31a6c62020-01-13 17:27:00 +08008#include "list.h"
Gong Ke3489c0f2020-01-16 18:11:44 +08009#include "dvr_types.h"
hualing chen86e7d482020-01-16 15:13:33 +080010#include "segment.h"
hualing chen2aba4022020-03-02 13:49:55 +080011#include "AmTsPlayer.h"
hualing chen040df222020-01-17 13:35:02 +080012#include "dvr_types.h"
13#include "dvr_crypto.h"
Zhiqiang Hanf9c0e272022-06-14 13:54:03 +080014#include "dvr_mutex.h"
hualing chen040df222020-01-17 13:35:02 +080015
hualing chenb31a6c62020-01-13 17:27:00 +080016#ifdef __cplusplus
17extern "C" {
18#endif
Gong Ke3489c0f2020-01-16 18:11:44 +080019
hualing chen040df222020-01-17 13:35:02 +080020/**\brief dvr play segment flag */
hualing chenb31a6c62020-01-13 17:27:00 +080021typedef enum
22{
Gong Ke3489c0f2020-01-16 18:11:44 +080023 DVR_PLAYBACK_SEGMENT_ENCRYPTED = (1 << 0), /**< encrypted stream */
24 DVR_PLAYBACK_SEGMENT_DISPLAYABLE = (1 << 1), /**< displayable stream */
Gong Ke497c4c22020-03-20 10:15:42 +080025 DVR_PLAYBACK_SEGMENT_CONTINUOUS = (1 << 2) /**< continuous stream with pre one */
Gong Ke3489c0f2020-01-16 18:11:44 +080026} DVR_PlaybackSegmentFlag_t;
hualing chenb31a6c62020-01-13 17:27:00 +080027
28/**\brief dvr pid type*/
29typedef enum
30{
Gong Ke3489c0f2020-01-16 18:11:44 +080031 DVR_PLAYBACK_SYNC, /**< sync play mode */
32 DVR_PLAYBACK_ASYNC /**< out of sync play mode */
33} DVR_PlaybackSyncMode_t;
hualing chenb31a6c62020-01-13 17:27:00 +080034
35
36/**\brief dvr play pids */
37typedef struct
38{
Gong Ke3489c0f2020-01-16 18:11:44 +080039 DVR_StreamInfo_t video; /**< Video.*/
40 DVR_StreamInfo_t audio; /**< Audio.*/
41 DVR_StreamInfo_t ad; /**< AD.*/
42 DVR_StreamInfo_t subtitle; /**< Subtitle.*/
43 DVR_StreamInfo_t pcr; /**< PCR.*/
44} DVR_PlaybackPids_t;
hualing chenb31a6c62020-01-13 17:27:00 +080045
hualing chen1679f812021-11-08 15:17:46 +080046/**\brief dvr play pids */
47typedef struct
48{
49 DVR_PlaybackPids_t pids; /**< Video.*/
50 int av_scale;
51} DVR_Playback_info_t;
52
Gong Ke3489c0f2020-01-16 18:11:44 +080053/**\brief dvr segments info */
hualing chenb31a6c62020-01-13 17:27:00 +080054typedef struct
55{
Gong Ke3489c0f2020-01-16 18:11:44 +080056 struct list_head head; /**< Segment node.*/
hualing chen5cbe1a62020-02-10 16:36:36 +080057 uint64_t segment_id; /**< Segment's index.*/
58 char location[DVR_MAX_LOCATION_SIZE]; /**< chunk location */
Gong Ke3489c0f2020-01-16 18:11:44 +080059 DVR_PlaybackPids_t pids; /**< Streams' PIDs.*/
hualing chen040df222020-01-17 13:35:02 +080060 DVR_PlaybackSegmentFlag_t flags; /**< Segment's flag */
Gong Ke3489c0f2020-01-16 18:11:44 +080061 int key_data_id; /**< ??? */
hualing chen03fd4942021-07-15 15:56:41 +080062 int duration; /**< Segment dur time ms*/
Gong Ke3489c0f2020-01-16 18:11:44 +080063} DVR_PlaybackSegmentInfo_t;
hualing chenb31a6c62020-01-13 17:27:00 +080064
65/**\brief play flag, if set this flag, player need pause when decode first frame */
66typedef enum
67{
Gong Ke3489c0f2020-01-16 18:11:44 +080068 DVR_PLAYBACK_STARTED_PAUSEDLIVE = (1 << 0) /**< dvr play stat,need change to pause state if set */
69} DVR_PlaybackFlag_t;
hualing chen86e7d482020-01-16 15:13:33 +080070
71/**\brief playback speed mode*/
hualing chenb31a6c62020-01-13 17:27:00 +080072typedef enum
73{
Gong Ke3489c0f2020-01-16 18:11:44 +080074 DVR_PLAYBACK_FAST_FORWARD = 0, /**< fast forward */
75 DVR_PLAYBACK_FAST_BACKWARD = 1, /**< fast backward */
hualing chen31140872020-03-25 12:29:26 +080076 DVR_PLAYBACK_KERNEL_SUPPORT = 2, /**< kernel support mode */
Gong Ke3489c0f2020-01-16 18:11:44 +080077} DVR_PlaybackSpeedMode_t;
hualing chenb31a6c62020-01-13 17:27:00 +080078
hualing chen2aba4022020-03-02 13:49:55 +080079/**\brief playback speed*/
80typedef enum
81{
hualing chene41f4372020-06-06 16:29:17 +080082 PLAYBACK_SPEED_FBX1 = -100, /**<FB X 1 speed*/
hualing chena540a7e2020-03-27 16:44:05 +080083 PLAYBACK_SPEED_FBX2 = -200, /**<FB X 2 speed*/
84 PLAYBACK_SPEED_FBX4 = -400, /**<FB X 4 speed*/
85 PLAYBACK_SPEED_FBX8 = -800, /**<FB X 8 speed*/
hualing chen041c4092020-04-05 15:11:50 +080086 PLAYBACK_SPEED_FBX12 = -1200, /**< FB 12 speed*/
87 PLAYBACK_SPEED_FBX16 = -1600, /**<FB X 16 speed*/
88 PLAYBACK_SPEED_FBX32 = -3200, /**<FB X 32 speed*/
89 PLAYBACK_SPEED_FBX48 = -4800, /**<FB X 48 speed*/
90 PLAYBACK_SPEED_FBX64 = -6400, /**<FB X 64 speed*/
91 PLAYBACK_SPEED_FBX128 = -12800, /**<FB X 128 speed*/
hualing chena540a7e2020-03-27 16:44:05 +080092 PLAYBACK_SPEED_S8 = 12, /**<slow 1/8 speed*/
93 PLAYBACK_SPEED_S4 = 25, /**<slow 1/4 speed*/
hualing chen2aba4022020-03-02 13:49:55 +080094 PLAYBACK_SPEED_S2 = 50, /**<slow 1/2 speed*/
95 PLAYBACK_SPEED_X1 = 100, /**< X 1 normal speed*/
96 PLAYBACK_SPEED_X2 = 200, /**< X 2 speed*/
hualing chena540a7e2020-03-27 16:44:05 +080097 PLAYBACK_SPEED_X3 = 300, /**< X 3 speed*/
hualing chen2aba4022020-03-02 13:49:55 +080098 PLAYBACK_SPEED_X4 = 400, /**< X 4 speed*/
hualing chena540a7e2020-03-27 16:44:05 +080099 PLAYBACK_SPEED_X5 = 500, /**< X 5 speed*/
100 PLAYBACK_SPEED_X6 = 600, /**< X 6 speed*/
101 PLAYBACK_SPEED_X7 = 700, /**< X 7 speed*/
hualing chen2aba4022020-03-02 13:49:55 +0800102 PLAYBACK_SPEED_X8 = 800, /**< X 8 speed*/
hualing chen041c4092020-04-05 15:11:50 +0800103 PLAYBACK_SPEED_X12 = 1200, /**< X 12 speed*/
104 PLAYBACK_SPEED_X16 = 1600, /**< X 16 speed*/
105 PLAYBACK_SPEED_X32 = 3200, /**< X 32 speed*/
106 PLAYBACK_SPEED_X48 = 4800, /**< X 48 speed*/
107 PLAYBACK_SPEED_X64 = 6400, /**< X 64 speed*/
108 PLAYBACK_SPEED_X128 = 12800, /**< X 128 speed*/
hualing chen2aba4022020-03-02 13:49:55 +0800109 PlayBack_Speed_MAX,
110} Playback_SpeedValue_t;
111
Gong Ke497c4c22020-03-20 10:15:42 +0800112/**\brief playback speed*/
hualing chen2aba4022020-03-02 13:49:55 +0800113typedef struct Playback_Speeds_s {
Gong Ke497c4c22020-03-20 10:15:42 +0800114 int speed; /**< playback speed value*/
hualing chen2aba4022020-03-02 13:49:55 +0800115} Playback_Speeds_t;
hualing chenb31a6c62020-01-13 17:27:00 +0800116
Gong Ke3489c0f2020-01-16 18:11:44 +0800117/**\brief playback play speed*/
hualing chenb31a6c62020-01-13 17:27:00 +0800118typedef struct
119{
hualing chen2aba4022020-03-02 13:49:55 +0800120 Playback_Speeds_t speed; /**< playback speed */
Gong Ke3489c0f2020-01-16 18:11:44 +0800121 DVR_PlaybackSpeedMode_t mode; /**< playback 0: fast forword or 1: fast backword*/
122} DVR_PlaybackSpeed_t;
hualing chenb31a6c62020-01-13 17:27:00 +0800123
hualing chen2aba4022020-03-02 13:49:55 +0800124
Gong Ke3489c0f2020-01-16 18:11:44 +0800125/**Maximum supported speed modes.*/
hualing chenb31a6c62020-01-13 17:27:00 +0800126#define DVR_MAX_SUPPORTED_SPEEDS 32
Gong Ke3489c0f2020-01-16 18:11:44 +0800127
hualing chenb31a6c62020-01-13 17:27:00 +0800128/**\brief playback capability*/
129typedef struct
130{
hualing chen86e7d482020-01-16 15:13:33 +0800131 int nb_supported_speeds; /**< support playback speed count*/
132 int supported_speeds[DVR_MAX_SUPPORTED_SPEEDS]; /**< support playback speed*/
Gong Ke3489c0f2020-01-16 18:11:44 +0800133} DVR_PlaybackCapability_t;
hualing chenb31a6c62020-01-13 17:27:00 +0800134
Gong Ke3489c0f2020-01-16 18:11:44 +0800135/**Playback handle.*/
136typedef void* DVR_PlaybackHandle_t;
hualing chenb31a6c62020-01-13 17:27:00 +0800137
hualing chencc91e1c2020-02-28 13:26:17 +0800138
139/**\brief playback error reason*/
140typedef enum
141{
142 DVR_PLAYBACK_PID_ERROR, /**< uninit state */
Wentao MA9a164002022-08-29 11:20:24 +0800143 DVR_PLAYBACK_FMT_ERROR /**< fmt not support backword */
hualing chencc91e1c2020-02-28 13:26:17 +0800144} DVR_PlaybackError_t;
145
146
hualing chenb31a6c62020-01-13 17:27:00 +0800147/**\brief playback play state*/
148typedef enum
149{
Gong Ke3489c0f2020-01-16 18:11:44 +0800150 DVR_PLAYBACK_STATE_START, /**< start play */
151 DVR_PLAYBACK_STATE_STOP, /**< stop */
152 DVR_PLAYBACK_STATE_PAUSE, /**< pause */
153 DVR_PLAYBACK_STATE_FF, /**< fast forward */
154 DVR_PLAYBACK_STATE_FB /**< fast backword */
155} DVR_PlaybackPlayState_t;
hualing chenb31a6c62020-01-13 17:27:00 +0800156
157/**\brief playback play status*/
158typedef struct
159{
Gong Ke3489c0f2020-01-16 18:11:44 +0800160 DVR_PlaybackPlayState_t state; /**< playback play state */
hualing chen5cbe1a62020-02-10 16:36:36 +0800161 uint64_t segment_id; /**< playback ongoing segment index */
Wentao MAac5ea062022-08-11 11:44:27 +0800162 int32_t time_cur; /**< current playback time position in ms of a segment.
163 It can be a negative value to refer to relative time
164 position of previous segment*/
165 int32_t time_end; /**< end time position of a segment in ms */
Gong Ke3489c0f2020-01-16 18:11:44 +0800166 DVR_PlaybackPids_t pids; /**< playback played pids */
hualing chen5cbe1a62020-02-10 16:36:36 +0800167 int speed; /**< playback speed */
168 DVR_PlaybackSegmentFlag_t flags; /**< playback played segment flag */
Gong Ke3489c0f2020-01-16 18:11:44 +0800169} DVR_PlaybackStatus_t;
hualing chenb31a6c62020-01-13 17:27:00 +0800170
hualing chenfbf8e022020-06-15 13:43:11 +0800171/**\brief DVR playback vendor*/
172typedef enum {
Wentao MA292380e2022-12-14 14:46:19 +0800173 DVR_PLAYBACK_VENDOR_DEF, /**< default, for Irdeto*/
hualing chen90b3ae62021-03-30 10:49:28 +0800174 DVR_PLAYBACK_VENDOR_AML, /**< aml*/
175 DVR_PLAYBACK_VENDOR_AMAZON /**< amazon*/
hualing chenfbf8e022020-06-15 13:43:11 +0800176} DVR_PlaybackVendor_t;
177
178
hualing chencc91e1c2020-02-28 13:26:17 +0800179/**\brief DVR playback event*/
180typedef enum {
181 DVR_PLAYBACK_EVENT_ERROR = 0x1000, /**< Signal a critical playback error*/
182 DVR_PLAYBACK_EVENT_TRANSITION_OK , /**< transition ok*/
183 DVR_PLAYBACK_EVENT_TRANSITION_FAILED, /**< transition failed*/
184 DVR_PLAYBACK_EVENT_KEY_FAILURE, /**< key failure*/
185 DVR_PLAYBACK_EVENT_NO_KEY, /**< no key*/
186 DVR_PLAYBACK_EVENT_REACHED_BEGIN , /**< reached begin*/
hualing chen2aba4022020-03-02 13:49:55 +0800187 DVR_PLAYBACK_EVENT_REACHED_END, /**< reached end*/
Wentao MA270dc0f2022-08-23 13:17:26 +0800188 DVR_PLAYBACK_EVENT_NOTIFY_PLAYTIME, /**< notify play cur segment time ms*/
hualing chene3797f02021-01-13 14:53:28 +0800189 DVR_PLAYBACK_EVENT_FIRST_FRAME, /**< first frame*/
190 DVR_PLAYBACK_EVENT_NODATA, /**< no data*/
Wentao MA9e31f692023-09-26 17:42:18 +0800191 DVR_PLAYBACK_EVENT_DATARESUME, /**< data resume*/
192 DVR_PLAYBACK_EVENT_TIMESHIFT_FR_REACHED_BEGIN,
193 DVR_PLAYBACK_EVENT_TIMESHIFT_FF_REACHED_END,
hualing chencc91e1c2020-02-28 13:26:17 +0800194} DVR_PlaybackEvent_t;
195
196/**\brief DVR playback event notify function*/
197typedef struct
198{
Gong Ke497c4c22020-03-20 10:15:42 +0800199 DVR_PlaybackEvent_t event; /**< event type*/
200 DVR_PlaybackStatus_t play_status; /**< play status*/
hualing chencc91e1c2020-02-28 13:26:17 +0800201 union
202 {
Gong Ke497c4c22020-03-20 10:15:42 +0800203 uint8_t unused;
204 uint8_t error_reason;/**< error reason*/
hualing chencc91e1c2020-02-28 13:26:17 +0800205 struct
206 {
Gong Ke497c4c22020-03-20 10:15:42 +0800207 uint64_t segment_id; /**< error segment id*/
208 uint32_t key_data_id; /**< key data id*/
209 uint8_t error; /**< error*/
hualing chencc91e1c2020-02-28 13:26:17 +0800210 } transition_failed_data;
Gong Ke497c4c22020-03-20 10:15:42 +0800211 } info; /**< information*/
hualing chencc91e1c2020-02-28 13:26:17 +0800212} DVR_Play_Notify_t;
213
214/**\brief DVR playback event notify function*/
215typedef DVR_Result_t (*DVR_PlaybackEventFunction_t) (DVR_PlaybackEvent_t event, void *params, void *userdata);
216
217
hualing chenb31a6c62020-01-13 17:27:00 +0800218/**\brief playback open params*/
219typedef struct
220{
Gong Ke3489c0f2020-01-16 18:11:44 +0800221 int dmx_dev_id; /**< playback used dmx device index*/
222 int block_size; /**< playback inject block size*/
223 DVR_Bool_t is_timeshift; /**< 0:playback mode, 1 : is timeshift mode*/
hualing chen2aba4022020-03-02 13:49:55 +0800224 am_tsplayer_handle player_handle; /**< am tsplayer handle.*/
Gong Ke3489c0f2020-01-16 18:11:44 +0800225 DVR_CryptoFunction_t crypto_fn; /**< Crypto function.*/
Yahui Han1fbf3292021-11-08 18:17:19 +0800226 void *crypto_data; /**< Crypto function's user data.*/
227 uint8_t *clearkey; /**< key for encrypted PVR on FTA.*/
Wentao MAe8ba5172022-08-09 11:18:17 +0800228 uint8_t *cleariv; /**< iv for encrypted PVR on FTA.*/
Yahui Han1fbf3292021-11-08 18:17:19 +0800229 uint32_t keylen; /**< key/iv length.*/
hualing chen5cbe1a62020-02-10 16:36:36 +0800230 DVR_Bool_t has_pids; /**< has video audo pid fmt info*/
hualing chencc91e1c2020-02-28 13:26:17 +0800231 DVR_PlaybackEventFunction_t event_fn; /**< playback event callback function*/
232 void *event_userdata; /**< event userdata*/
hualing chenfbf8e022020-06-15 13:43:11 +0800233 DVR_PlaybackVendor_t vendor; /**< vendor type,default is 0*/
hualing chene3797f02021-01-13 14:53:28 +0800234 DVR_Bool_t is_notify_time; /**< notify play time info true or not*/
shenghui.gengbec6a462023-01-12 15:21:02 +0800235 DVR_Bool_t control_speed_enable; /**< 1: system clock, 0: libdvr can determine index time source based on actual situation*/
Gong Ke3489c0f2020-01-16 18:11:44 +0800236} DVR_PlaybackOpenParams_t;
hualing chenb31a6c62020-01-13 17:27:00 +0800237
238/**\brief playback play state*/
239typedef enum
240{
hualing chen040df222020-01-17 13:35:02 +0800241 DVR_PLAYBACK_CMD_START, /**< start av */
242 DVR_PLAYBACK_CMD_STOP, /**< stop av */
Wentao MA270dc0f2022-08-23 13:17:26 +0800243 DVR_PLAYBACK_CMD_V_START, /**< v start */
244 DVR_PLAYBACK_CMD_A_START , /**< a start */
245 DVR_PLAYBACK_CMD_V_STOP , /**< v stop */
246 DVR_PLAYBACK_CMD_A_STOP, /**< a stop */
247 DVR_PLAYBACK_CMD_V_RESTART, /**< v restart */
248 DVR_PLAYBACK_CMD_A_RESTART, /**< a restart */
249 DVR_PLAYBACK_CMD_AV_RESTART, /**< av restart */
250 DVR_PLAYBACK_CMD_V_STOP_A_START, /**< v stop a start*/
251 DVR_PLAYBACK_CMD_A_STOP_V_START, /**< a stop v_start */
252 DVR_PLAYBACK_CMD_V_STOP_A_RESTART, /**<v stop a restart*/
253 DVR_PLAYBACK_CMD_A_STOP_V_RESTART, /**<a stop v restart*/
254 DVR_PLAYBACK_CMD_V_START_A_RESTART, /**<v start a restart*/
255 DVR_PLAYBACK_CMD_A_START_V_RESTART, /**<a start v restart*/
hualing chen040df222020-01-17 13:35:02 +0800256 DVR_PLAYBACK_CMD_PAUSE, /**< pause */
257 DVR_PLAYBACK_CMD_RESUME, /**< resume */
258 DVR_PLAYBACK_CMD_SEEK, /**< seek */
259 DVR_PLAYBACK_CMD_FF, /**< fast forward */
260 DVR_PLAYBACK_CMD_FB, /**< fast backword */
hualing chen5cbe1a62020-02-10 16:36:36 +0800261 DVR_PLAYBACK_CMD_NONE, /**< none */
hualing chen040df222020-01-17 13:35:02 +0800262} DVR_PlaybackCmd_t;
hualing chenb31a6c62020-01-13 17:27:00 +0800263
264
265/**\brief playback struct*/
266typedef struct
267{
hualing chen5cbe1a62020-02-10 16:36:36 +0800268 DVR_PlaybackSpeed_t speed; /**< play speed */
269 DVR_PlaybackPlayState_t state; /**< play state */
hualing chen040df222020-01-17 13:35:02 +0800270 DVR_PlaybackCmd_t cur_cmd; /**< cur send cmd */
271 DVR_PlaybackCmd_t last_cmd; /**< last cmd */
272 int pos; /**< seek pos at cur segment*/
273} DVR_PlaybackCmdInfo_t;
hualing chenb31a6c62020-01-13 17:27:00 +0800274
hualing chend241c7a2021-06-22 13:34:27 +0800275/**\brief playback struct*/
276typedef struct
277{
hualing chen7ea70a72021-09-09 11:25:13 +0800278 uint32_t sys_dur; /**< system duration */
279 uint32_t sys_sta; /**< system start time */
wentao.mafdba9a02023-01-17 16:43:26 +0800280 int32_t ply_dur; /**< play duration */
281 int32_t ply_sta; /**< play start time */
hualing chend241c7a2021-06-22 13:34:27 +0800282} DVR_PlaybackConSpe_t;
283
284
pengfei.liu07ddc8a2020-03-24 23:36:53 +0800285/**\brief DVR playback decrypt function*/
286typedef DVR_Result_t (*DVR_PlaybackDecryptFunction_t) (uint8_t *p_in,
287 uint32_t in_len,
288 uint8_t *p_out,
289 uint32_t *p_out_len,
290 void *userdata);
hualing chenb31a6c62020-01-13 17:27:00 +0800291
Gong Ke497c4c22020-03-20 10:15:42 +0800292/**\cond */
hualing chenb31a6c62020-01-13 17:27:00 +0800293/**\brief playback struct*/
294typedef struct
295{
hualing chen2aba4022020-03-02 13:49:55 +0800296 am_tsplayer_handle handle; /**< tsplayer handle */
hualing chencc91e1c2020-02-28 13:26:17 +0800297 DVR_Bool_t segment_is_open; /**<segment is opend*/
hualing chen5cbe1a62020-02-10 16:36:36 +0800298 uint64_t cur_segment_id; /**< Current segment id*/
hualing chen040df222020-01-17 13:35:02 +0800299 DVR_PlaybackSegmentInfo_t cur_segment; /**< Current playing segment*/
hualing chencc91e1c2020-02-28 13:26:17 +0800300 uint64_t last_segment_id; /**< last segment id*/
301 DVR_PlaybackSegmentInfo_t last_segment; /**< last playing segment*/
hualing chen040df222020-01-17 13:35:02 +0800302 struct list_head segment_list; /**< segment list head*/
303 pthread_t playback_thread; /**< playback thread*/
Zhiqiang Hanf9c0e272022-06-14 13:54:03 +0800304 dvr_mutex_t lock; /**< playback lock*/
hualing chen2aba4022020-03-02 13:49:55 +0800305 pthread_mutex_t segment_lock; /**< playback segment lock*/
hualing chen040df222020-01-17 13:35:02 +0800306 pthread_cond_t cond; /**< playback cond*/
307 void *user_data; /**< playback userdata, used to send event*/
hualing chen6d24aa92020-03-23 18:43:47 +0800308 float speed; /**< playback speed*/
hualing chen040df222020-01-17 13:35:02 +0800309 DVR_PlaybackPlayState_t state; /**< playback state*/
310 DVR_PlaybackFlag_t play_flag; /**< playback play flag*/
hualing chen86e7d482020-01-16 15:13:33 +0800311 int is_running; /**< playback htread is runing*/
hualing chen040df222020-01-17 13:35:02 +0800312 DVR_PlaybackCmdInfo_t cmd; /**< playback cmd*/
313 int offset; /**< segment read offset*/
hualing chencc91e1c2020-02-28 13:26:17 +0800314 uint32_t dur; /**< segment dur*/
Wentao MAf35c3882023-04-17 12:36:19 +0800315 Segment_Handle_t segment_handle; /**< playback current segment handle*/
hualing chen040df222020-01-17 13:35:02 +0800316 DVR_PlaybackOpenParams_t openParams; /**< playback openParams*/
hualing chen86e7d482020-01-16 15:13:33 +0800317 DVR_Bool_t has_video; /**< has video playing*/
318 DVR_Bool_t has_audio; /**< has audio playing*/
hualing chendf118dd2020-05-21 15:49:11 +0800319 DVR_Bool_t has_ad_audio; /**< has ad audio playing*/
hualing chen5cbe1a62020-02-10 16:36:36 +0800320 DVR_Bool_t has_pids; /**< has video audo pid fmt info*/
hualing chen7ea70a72021-09-09 11:25:13 +0800321 uint32_t fffb_start; /**< fffb start time ms*/
322 uint32_t fffb_current; /**< fffb current time*/
hualing chen5cbe1a62020-02-10 16:36:36 +0800323 int fffb_start_pcr; /**< fffb start pcr time*/
hualing chen7ea70a72021-09-09 11:25:13 +0800324 uint32_t next_fffb_time;/**< fffb start pcr time*/
hualing chena540a7e2020-03-27 16:44:05 +0800325 int seek_time;/**< fffb start pcr time*/
326 event_callback player_callback_func;/**< tsplayer cb*/
327 void *player_callback_userdata;/**< tsplayer cb data*/
hualing chen7ea70a72021-09-09 11:25:13 +0800328 uint32_t send_time;/**< send event time*/
pengfei.liu27cc4ec2020-04-03 16:28:16 +0800329 int first_frame;/**< show first frame*/
330 DVR_CryptoFunction_t dec_func; /**< Decrypt function*/
331 void *dec_userdata; /**< Decrypt userdata*/
Yahui Han1fbf3292021-11-08 18:17:19 +0800332 void *cryptor; /**< Cryptor for encrypted PVR on FTA.*/
pengfei.liu27cc4ec2020-04-03 16:28:16 +0800333 int is_secure_mode; /**< Playback session run in secure pipeline */
334 uint8_t *secure_buffer; /* Playback session secure buffer */
335 uint32_t secure_buffer_size; /* Playback session secure buffer size */
hualing chen266b9502020-04-04 17:39:39 +0800336 DVR_Bool_t drop_ts;
hualing chen4b7c15d2020-04-07 16:13:48 +0800337 DVR_Bool_t fffb_play;
338 int32_t last_cur_time;
339 uint64_t last_send_time_id;
hualing chen5605eed2020-05-26 18:18:06 +0800340 int ts_cache_len;
hualing chene41f4372020-06-06 16:29:17 +0800341 DVR_Bool_t first_trans_ok;
hualing chenfbf8e022020-06-15 13:43:11 +0800342 DVR_PlaybackVendor_t vendor;
hualing chene3797f02021-01-13 14:53:28 +0800343 int noData;
hualing chena5f03222021-12-02 11:22:35 +0800344 DVR_Bool_t seek_pause; /**<set true when user call seek at pause state,we will start inject data, if first frame is got,set false and stop inject data*/
Wentao MA270dc0f2022-08-23 13:17:26 +0800345 int last_segment_total; /**< last segment total time*/
hualing chen969fe7b2021-05-26 15:13:17 +0800346
hualing chen03fd4942021-07-15 15:56:41 +0800347 DVR_PlaybackConSpe_t con_spe; /**< inject data speed info*/
348
349 //limit info
350 int obsolete; /**< rec obsolete time in ms*/
hualing chen7ea70a72021-09-09 11:25:13 +0800351 uint32_t rec_start; /**< rec start time in ms*/
352 uint32_t limit; /**< rec data limit time in ms*/
hualing chen8a657f32021-08-30 13:12:49 +0800353 //first play need seek to start time
hualing chen7ea70a72021-09-09 11:25:13 +0800354 uint32_t first_start_time;
Wentao MA01de0e62022-01-10 18:48:23 +0800355 //The segment id where a playback is initially started
356 uint64_t first_start_id;
Wentao MAa0b9c002022-11-10 17:47:27 +0800357
358 // Tells whether the delay from AmTsPlayer_getDelayTime is valid.
359 // Notice it can be invalid in a short period at starting phase of a playback.
360 DVR_Bool_t delay_is_effective;
361
hualing chen8a657f32021-08-30 13:12:49 +0800362 DVR_Bool_t need_seek_start;
hualing chena5f03222021-12-02 11:22:35 +0800363 //init fake pid
364 int fake_pid;
Wentao MA5629ad82022-08-24 10:03:02 +0800365 //Audio presentation id, used for dolby AC4 audio
366 int32_t audio_presentation_id;
shenghui.gengbec6a462023-01-12 15:21:02 +0800367
368 /**< 1: system clock, 0: libdvr can determine index time source based on actual situation*/
369 DVR_Bool_t control_speed_enable;
hualing chen040df222020-01-17 13:35:02 +0800370} DVR_Playback_t;
Gong Ke497c4c22020-03-20 10:15:42 +0800371/**\endcond*/
hualing chenb31a6c62020-01-13 17:27:00 +0800372
373/**\brief Open an dvr palyback
374 * \param[out] p_handle dvr playback addr
375 * \param[in] params dvr playback open parameters
376 * \retval DVR_SUCCESS On success
377 * \return Error code
378 */
Gong Ke3489c0f2020-01-16 18:11:44 +0800379int dvr_playback_open(DVR_PlaybackHandle_t *p_handle, DVR_PlaybackOpenParams_t *params);
hualing chenb31a6c62020-01-13 17:27:00 +0800380
381/**\brief Close an dvr palyback
382 * \param[in] handle playback handle
383 * \retval DVR_SUCCESS On success
384 * \return Error code
385 */
Gong Ke3489c0f2020-01-16 18:11:44 +0800386int dvr_playback_close(DVR_PlaybackHandle_t handle);
hualing chenb31a6c62020-01-13 17:27:00 +0800387
388
Wentao MA270dc0f2022-08-23 13:17:26 +0800389/**\brief Start play audio and video, used start audio api and start video api
hualing chenb31a6c62020-01-13 17:27:00 +0800390 * \param[in] handle playback handle
Gong Ke497c4c22020-03-20 10:15:42 +0800391 * \param[in] flag playback flag
hualing chenb31a6c62020-01-13 17:27:00 +0800392 * \retval DVR_SUCCESS On success
393 * \return Error code
394 */
Gong Ke3489c0f2020-01-16 18:11:44 +0800395int dvr_playback_start(DVR_PlaybackHandle_t handle, DVR_PlaybackFlag_t flag);
hualing chenb31a6c62020-01-13 17:27:00 +0800396
hualing chen040df222020-01-17 13:35:02 +0800397/**\brief dvr play back add segment info to segment list
hualing chenb31a6c62020-01-13 17:27:00 +0800398 * \param[in] handle playback handle
hualing chen040df222020-01-17 13:35:02 +0800399 * \param[in] info added segment info,con vpid fmt apid fmt.....
hualing chenb31a6c62020-01-13 17:27:00 +0800400 * \retval DVR_SUCCESS On success
401 * \return Error code
402 */
hualing chen040df222020-01-17 13:35:02 +0800403int dvr_playback_add_segment(DVR_PlaybackHandle_t handle, DVR_PlaybackSegmentInfo_t *info);
hualing chenb31a6c62020-01-13 17:27:00 +0800404
hualing chen040df222020-01-17 13:35:02 +0800405/**\brief dvr play back remove segment info by segmentkid
hualing chenb31a6c62020-01-13 17:27:00 +0800406 * \param[in] handle playback handle
hualing chen040df222020-01-17 13:35:02 +0800407 * \param[in] segmentid need removed segment id
hualing chenb31a6c62020-01-13 17:27:00 +0800408 * \retval DVR_SUCCESS On success
409 * \return Error code
410 */
hualing chen5cbe1a62020-02-10 16:36:36 +0800411int dvr_playback_remove_segment(DVR_PlaybackHandle_t handle, uint64_t segmentid);
hualing chenb31a6c62020-01-13 17:27:00 +0800412
hualing chen040df222020-01-17 13:35:02 +0800413/**\brief dvr play back add segment info
hualing chenb31a6c62020-01-13 17:27:00 +0800414 * \param[in] handle playback handle
Gong Ke497c4c22020-03-20 10:15:42 +0800415 * \param[in] segment_id the segment's index
416 * \param[in] flags the segment's flags
hualing chenb31a6c62020-01-13 17:27:00 +0800417 * \retval DVR_SUCCESS On success
418 * \return Error code
419 */
hualing chen040df222020-01-17 13:35:02 +0800420int dvr_playback_update_segment_flags(DVR_PlaybackHandle_t handle,
hualing chen5cbe1a62020-02-10 16:36:36 +0800421 uint64_t segment_id,
hualing chen040df222020-01-17 13:35:02 +0800422 DVR_PlaybackSegmentFlag_t flags);
Gong Ke497c4c22020-03-20 10:15:42 +0800423
hualing chen040df222020-01-17 13:35:02 +0800424/**\brief dvr play back up1date segment pids
425 * if updated segment is ongoing segment, we need start new
hualing chenb31a6c62020-01-13 17:27:00 +0800426 * add pid stream and stop remove pid stream.
427 * \param[in] handle playback handle
hualing chen040df222020-01-17 13:35:02 +0800428 * \param[in] segment_id need updated pids segment id
Gong Ke497c4c22020-03-20 10:15:42 +0800429 * \param[in] p_pids the new PIDs
hualing chenb31a6c62020-01-13 17:27:00 +0800430 * \retval DVR_SUCCESS On success
431 * \return Error code
432 */
Gong Ke497c4c22020-03-20 10:15:42 +0800433int dvr_playback_update_segment_pids(DVR_PlaybackHandle_t handle, uint64_t segment_id,
hualing chen040df222020-01-17 13:35:02 +0800434DVR_PlaybackPids_t *p_pids);
hualing chenb31a6c62020-01-13 17:27:00 +0800435
hualing chena5f03222021-12-02 11:22:35 +0800436/**\brief dvr play back only up1date segment pids
437 * only update segment info, not stop start codec.
438 * \param[in] handle playback handle
439 * \param[in] segment_id need updated pids segment id
440 * \param[in] p_pids the new PIDs
441 * \retval DVR_SUCCESS On success
442 * \return Error code
443 */
444int dvr_playback_only_update_segment_pids(DVR_PlaybackHandle_t handle, uint64_t segment_id, DVR_PlaybackPids_t *p_pids);
445
Gong Ke497c4c22020-03-20 10:15:42 +0800446/**\brief Stop playing, will stop video and audio
hualing chenb31a6c62020-01-13 17:27:00 +0800447 * \param[in] handle playback handle
448 * \param[in] clear is clear last frame
449 * \retval DVR_SUCCESS On success
450 * \return Error code
451 */
hualing chen040df222020-01-17 13:35:02 +0800452int dvr_playback_stop(DVR_PlaybackHandle_t handle, DVR_Bool_t clear);
hualing chenb31a6c62020-01-13 17:27:00 +0800453
Gong Ke497c4c22020-03-20 10:15:42 +0800454/**\brief Start audio playing
hualing chenb31a6c62020-01-13 17:27:00 +0800455 * \param[in] handle playback handle
456 * \param[in] params audio playback params,contains fmt and pid...
Wentao MA270dc0f2022-08-23 13:17:26 +0800457 * \param[in] ad_params ad audio playback params,contains fmt and pid...
hualing chenb31a6c62020-01-13 17:27:00 +0800458 * \retval DVR_SUCCESS On success
459 * \return Error code
460 */
Wentao MA270dc0f2022-08-23 13:17:26 +0800461int dvr_playback_audio_start(DVR_PlaybackHandle_t handle, am_tsplayer_audio_params *param, am_tsplayer_audio_params *ad_param);
hualing chendf118dd2020-05-21 15:49:11 +0800462
hualing chenb31a6c62020-01-13 17:27:00 +0800463
Gong Ke497c4c22020-03-20 10:15:42 +0800464/**\brief Stop audio playing
hualing chenb31a6c62020-01-13 17:27:00 +0800465 * \param[in] handle playback handle
466 * \retval DVR_SUCCESS On success
467 * \return Error code
468 */
hualing chen040df222020-01-17 13:35:02 +0800469int dvr_playback_audio_stop(DVR_PlaybackHandle_t handle);
hualing chenb31a6c62020-01-13 17:27:00 +0800470
Gong Ke497c4c22020-03-20 10:15:42 +0800471/**\brief Start video playing
hualing chenb31a6c62020-01-13 17:27:00 +0800472 * \param[in] handle playback handle
473 * \param[in] params video playback params,contains fmt and pid...
474 * \retval DVR_SUCCESS On success
475 * \return Error code
476 */
Gong Ke497c4c22020-03-20 10:15:42 +0800477int dvr_playback_video_start(DVR_PlaybackHandle_t handle, am_tsplayer_video_params *params);
hualing chenb31a6c62020-01-13 17:27:00 +0800478
479/**\brief Stop play video
480 * \param[in] handle playback handle
481 * \retval DVR_SUCCESS On success
482 * \return Error code
483 */
hualing chen040df222020-01-17 13:35:02 +0800484int dvr_playback_video_stop(DVR_PlaybackHandle_t handle);
hualing chenb31a6c62020-01-13 17:27:00 +0800485
486/**\brief Pause play
487 * \param[in] handle playback handle
488 * \param[in] flush whether its internal buffers should be flushed
489 * \retval DVR_SUCCESS On success
490 * \return Error code
491 */
hualing chen040df222020-01-17 13:35:02 +0800492int dvr_playback_pause(DVR_PlaybackHandle_t handle, DVR_Bool_t flush);
hualing chenb31a6c62020-01-13 17:27:00 +0800493
hualing chen31140872020-03-25 12:29:26 +0800494/**\brief resume play
495 * \param[in] handle playback handle
496 * \retval DVR_SUCCESS On success
497 * \return Error code
498 */
499int dvr_playback_resume(DVR_PlaybackHandle_t handle);
hualing chenb31a6c62020-01-13 17:27:00 +0800500
hualing chen03fd4942021-07-15 15:56:41 +0800501/**\brief set limit
502 * \param[in] handle playback handle
503 * \param[in] rec start time ms
504 * \param[in] rec limit time ms
505 * \retval DVR_SUCCESS On success
506 * \return Error code
507 */
hualing chen7ea70a72021-09-09 11:25:13 +0800508int dvr_playback_setlimit(DVR_PlaybackHandle_t handle, uint32_t time, uint32_t limit);
hualing chen03fd4942021-07-15 15:56:41 +0800509
Gong Ke497c4c22020-03-20 10:15:42 +0800510/**\brief Seek the playing position
hualing chenb31a6c62020-01-13 17:27:00 +0800511 * \param[in] handle playback handle
Gong Ke497c4c22020-03-20 10:15:42 +0800512 * \param[in] segment_id the segment's index
hualing chen040df222020-01-17 13:35:02 +0800513 * \param[in] time_offset time offset base cur segment
hualing chenb31a6c62020-01-13 17:27:00 +0800514 * \retval DVR_SUCCESS On success
515 * \return Error code
516 */
hualing chencc91e1c2020-02-28 13:26:17 +0800517int dvr_playback_seek(DVR_PlaybackHandle_t handle, uint64_t segment_id, uint32_t time_offset);
hualing chenb31a6c62020-01-13 17:27:00 +0800518
519/**\brief Set play speed
520 * \param[in] handle playback handle
521 * \param[in] speed playback speed
522 * \retval DVR_SUCCESS On success
523 * \return Error code
524 */
hualing chen5cbe1a62020-02-10 16:36:36 +0800525int dvr_playback_set_speed(DVR_PlaybackHandle_t handle, DVR_PlaybackSpeed_t speed);
hualing chenb31a6c62020-01-13 17:27:00 +0800526
527/**\brief Get playback status
528 * \param[in] handle playback handle
529 * \param[out] p_status playback status
530 * \retval DVR_SUCCESS On success
531 * \return Error code
532 */
hualing chen040df222020-01-17 13:35:02 +0800533int dvr_playback_get_status(DVR_PlaybackHandle_t handle, DVR_PlaybackStatus_t *p_status);
hualing chenb31a6c62020-01-13 17:27:00 +0800534
535/**\brief Get playback capabilities
536 * \param[out] p_capability playback capability
537 * \retval DVR_SUCCESS On success
538 * \return Error code
539 */
hualing chen040df222020-01-17 13:35:02 +0800540int dvr_playback_get_capabilities(DVR_PlaybackCapability_t *p_capability);
hualing chenb31a6c62020-01-13 17:27:00 +0800541
hualing chen040df222020-01-17 13:35:02 +0800542/**\brief dump segmentinfo throw print log
Gong Ke497c4c22020-03-20 10:15:42 +0800543 * \param[in] handle playback
544 * \param[in] segment_id if segment_id > 0, only dump this log. else dump all segment info
hualing chenb31a6c62020-01-13 17:27:00 +0800545 * \retval DVR_SUCCESS On success
546 * \return Error code
547 */
hualing chen5cbe1a62020-02-10 16:36:36 +0800548int dvr_dump_segmentinfo(DVR_PlaybackHandle_t handle, uint64_t segment_id);
hualing chenb31a6c62020-01-13 17:27:00 +0800549
pengfei.liu07ddc8a2020-03-24 23:36:53 +0800550/**\brief Set DVR playback decrypt function
551 * \param[in] handle, DVR playback session handle
552 * \param[in] func, DVR playback encrypt function
553 * \param[in] userdata, DVR playback userdata from the caller
554 * \return DVR_SUCCESS on success
555 * \return error code on failure
556 */
pengfei.liu27cc4ec2020-04-03 16:28:16 +0800557int dvr_playback_set_decrypt_callback(DVR_PlaybackHandle_t handle, DVR_CryptoFunction_t func, void *userdata);
pengfei.liu07ddc8a2020-03-24 23:36:53 +0800558
559/**\brief Set DVR playback secure buffer used for protect the secure content
560 * \param[in] handle, DVR playback session handle
561 * \param[in] p_secure_buf, Secure buffer address which can NOT access by ACPU
562 * \param[in] len, Secure buffer length
563 * \return DVR_SUCCESS on success
564 * \return error code on failure
565 */
566int dvr_playback_set_secure_buffer(DVR_PlaybackHandle_t handle, uint8_t *p_secure_buf, uint32_t len);
567
hualing chen03fd4942021-07-15 15:56:41 +0800568/**\brief set DVR playback calculate expired time len
569 * \param[in] handle, DVR playback session handle
570 * \return DVR_SUCCESS on success
571 * \return error code on failure
572 */
hualing chen7ea70a72021-09-09 11:25:13 +0800573uint32_t dvr_playback_calculate_expiredlen(DVR_PlaybackHandle_t handle);
hualing chen03fd4942021-07-15 15:56:41 +0800574
575/**\brief set DVR playback obsolete time
576 * \param[in] handle, DVR playback session handle
577 * \param[in] obsolete, obsolete len
578 * \return DVR_SUCCESS on success
579 * \return error code on failure
580 */
581int dvr_playback_set_obsolete(DVR_PlaybackHandle_t handle, int obsolete);
582
583/**\brief update DVR playback newest segment duration
584 * \param[in] handle, DVR playback session handle
585 * \param[in] segmentid, newest segment id
586 * \param[in] dur dur time ms
587 * \return DVR_SUCCESS on success
588 * \return error code on failure
589 */
590int dvr_playback_update_duration(DVR_PlaybackHandle_t handle,
591uint64_t segmentid, int dur);
592
593/**\brief check DVR playback is set limit info
594 * \param[in] handle, DVR playback session handle
595 * \return DVR_FALSE or DVR_TRUE
596 */
597DVR_Bool_t dvr_playback_check_limit(DVR_PlaybackHandle_t handle);
598
Wentao MA5629ad82022-08-24 10:03:02 +0800599/**\brief set ac4 audio preselection id for playback
600 * \param[in] handle, DVR playback session handle
601 * \param[in] presel_id, ac4 preselection id
602 * \return DVR_SUCCESS on success
603 * \return error code on failure
604 */
605int dvr_playback_set_ac4_preselection_id(DVR_PlaybackHandle_t handle, int presel_id);
606
hualing chenb31a6c62020-01-13 17:27:00 +0800607#ifdef __cplusplus
608}
609#endif
610
611#endif /*END DVR_PLAYBACK_H_*/