blob: 5c6ed6f22664b60d2de8f300c92cf2cfa1d4b33d [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{
Zhiqiang Han83923642023-11-03 12:06:48 +0800241 /*Bit order to check:
242 stop > start,
243 */
244 DVR_PLAYBACK_CMD_V_START = 0x0001, /**< v start */
245 DVR_PLAYBACK_CMD_V_STOP = 0x0002, /**< v stop */
246 DVR_PLAYBACK_CMD_A_START = 0x0100, /**< a start */
247 DVR_PLAYBACK_CMD_A_STOP = 0x0200, /**< a stop */
248 DVR_PLAYBACK_CMD_V_RESTART = (DVR_PLAYBACK_CMD_V_STOP | DVR_PLAYBACK_CMD_V_START ), /**< v restart */
249 DVR_PLAYBACK_CMD_A_RESTART = (DVR_PLAYBACK_CMD_A_STOP | DVR_PLAYBACK_CMD_A_START ), /**< a restart */
250 DVR_PLAYBACK_CMD_V_STOP_A_START = (DVR_PLAYBACK_CMD_V_STOP | DVR_PLAYBACK_CMD_A_START ), /**< v stop a start*/
251 DVR_PLAYBACK_CMD_A_STOP_V_START = (DVR_PLAYBACK_CMD_A_STOP | DVR_PLAYBACK_CMD_V_START ), /**< a stop v_start */
252 DVR_PLAYBACK_CMD_V_STOP_A_RESTART = (DVR_PLAYBACK_CMD_V_STOP | DVR_PLAYBACK_CMD_A_RESTART), /**<v stop a restart*/
253 DVR_PLAYBACK_CMD_A_STOP_V_RESTART = (DVR_PLAYBACK_CMD_A_STOP | DVR_PLAYBACK_CMD_V_RESTART), /**<a stop v restart*/
254 DVR_PLAYBACK_CMD_V_START_A_RESTART = (DVR_PLAYBACK_CMD_V_START | DVR_PLAYBACK_CMD_A_RESTART), /**<v start a restart*/
255 DVR_PLAYBACK_CMD_A_START_V_RESTART = (DVR_PLAYBACK_CMD_A_START | DVR_PLAYBACK_CMD_V_RESTART), /**<a start v restart*/
256 DVR_PLAYBACK_CMD_AV_RESTART = (DVR_PLAYBACK_CMD_A_RESTART | DVR_PLAYBACK_CMD_V_RESTART), /**< av restart */
257 DVR_PLAYBACK_CMD_START = (DVR_PLAYBACK_CMD_V_START | DVR_PLAYBACK_CMD_A_START ), /**< start av */
258 DVR_PLAYBACK_CMD_STOP = (DVR_PLAYBACK_CMD_V_STOP | DVR_PLAYBACK_CMD_A_STOP ), /**< stop av */
259
260 #define DVR_PLAYBACK_CMD_RESET_V(_c) ((_c) & (~0xFF))
261 #define DVR_PLAYBACK_CMD_RESET_A(_c) ((_c) & (~0xFF00))
262
263 #define DVR_PLAYBACK_CMD_IS_RESTART(_c) ((_c) == 0x03)
264 #define DVR_PLAYBACK_CMD_IS_STOP(_c) ((_c) & 0x02)
265 #define DVR_PLAYBACK_CMD_IS_START(_c) ((_c) & 0x01)
266
267 #define DVR_PLAYBACK_CMD_GET_V_CMD(_c) ((_c) & 0xFF)
268 #define DVR_PLAYBACK_CMD_GET_A_CMD(_c) (((_c) & 0xFF00) >> 8)
269
270 #define DVR_PLAYBACK_CMD_IS_V_RESTART(_c) DVR_PLAYBACK_CMD_IS_RESTART(DVR_PLAYBACK_CMD_GET_V_CMD(_c))
271 #define DVR_PLAYBACK_CMD_IS_A_RESTART(_c) DVR_PLAYBACK_CMD_IS_RESTART(DVR_PLAYBACK_CMD_GET_A_CMD(_c))
272
273 #define DVR_PLAYBACK_CMD_IS_V_STOP(_c) DVR_PLAYBACK_CMD_IS_STOP(DVR_PLAYBACK_CMD_GET_V_CMD(_c))
274 #define DVR_PLAYBACK_CMD_IS_A_STOP(_c) DVR_PLAYBACK_CMD_IS_STOP(DVR_PLAYBACK_CMD_GET_A_CMD(_c))
275
276 #define DVR_PLAYBACK_CMD_IS_V_START(_c) DVR_PLAYBACK_CMD_IS_START(DVR_PLAYBACK_CMD_GET_V_CMD(_c))
277 #define DVR_PLAYBACK_CMD_IS_A_START(_c) DVR_PLAYBACK_CMD_IS_START(DVR_PLAYBACK_CMD_GET_A_CMD(_c))
278
279 DVR_PLAYBACK_CMD_PAUSE = 0x10000, /**< pause */
280 DVR_PLAYBACK_CMD_RESUME = 0x20000, /**< resume */
281 DVR_PLAYBACK_CMD_SEEK = 0x40000, /**< seek */
282 DVR_PLAYBACK_CMD_FF = 0x100000, /**< fast forward */
283 DVR_PLAYBACK_CMD_FB = 0x200000, /**< fast backword */
284 DVR_PLAYBACK_CMD_NONE = 0, /**< none */
hualing chen040df222020-01-17 13:35:02 +0800285} DVR_PlaybackCmd_t;
hualing chenb31a6c62020-01-13 17:27:00 +0800286
287
288/**\brief playback struct*/
289typedef struct
290{
hualing chen5cbe1a62020-02-10 16:36:36 +0800291 DVR_PlaybackSpeed_t speed; /**< play speed */
292 DVR_PlaybackPlayState_t state; /**< play state */
hualing chen040df222020-01-17 13:35:02 +0800293 DVR_PlaybackCmd_t cur_cmd; /**< cur send cmd */
294 DVR_PlaybackCmd_t last_cmd; /**< last cmd */
295 int pos; /**< seek pos at cur segment*/
296} DVR_PlaybackCmdInfo_t;
hualing chenb31a6c62020-01-13 17:27:00 +0800297
hualing chend241c7a2021-06-22 13:34:27 +0800298/**\brief playback struct*/
299typedef struct
300{
hualing chen7ea70a72021-09-09 11:25:13 +0800301 uint32_t sys_dur; /**< system duration */
302 uint32_t sys_sta; /**< system start time */
wentao.mafdba9a02023-01-17 16:43:26 +0800303 int32_t ply_dur; /**< play duration */
304 int32_t ply_sta; /**< play start time */
hualing chend241c7a2021-06-22 13:34:27 +0800305} DVR_PlaybackConSpe_t;
306
307
pengfei.liu07ddc8a2020-03-24 23:36:53 +0800308/**\brief DVR playback decrypt function*/
309typedef DVR_Result_t (*DVR_PlaybackDecryptFunction_t) (uint8_t *p_in,
310 uint32_t in_len,
311 uint8_t *p_out,
312 uint32_t *p_out_len,
313 void *userdata);
hualing chenb31a6c62020-01-13 17:27:00 +0800314
Gong Ke497c4c22020-03-20 10:15:42 +0800315/**\cond */
hualing chenb31a6c62020-01-13 17:27:00 +0800316/**\brief playback struct*/
317typedef struct
318{
hualing chen2aba4022020-03-02 13:49:55 +0800319 am_tsplayer_handle handle; /**< tsplayer handle */
hualing chencc91e1c2020-02-28 13:26:17 +0800320 DVR_Bool_t segment_is_open; /**<segment is opend*/
hualing chen5cbe1a62020-02-10 16:36:36 +0800321 uint64_t cur_segment_id; /**< Current segment id*/
hualing chen040df222020-01-17 13:35:02 +0800322 DVR_PlaybackSegmentInfo_t cur_segment; /**< Current playing segment*/
hualing chencc91e1c2020-02-28 13:26:17 +0800323 uint64_t last_segment_id; /**< last segment id*/
324 DVR_PlaybackSegmentInfo_t last_segment; /**< last playing segment*/
hualing chen040df222020-01-17 13:35:02 +0800325 struct list_head segment_list; /**< segment list head*/
326 pthread_t playback_thread; /**< playback thread*/
Zhiqiang Hanf9c0e272022-06-14 13:54:03 +0800327 dvr_mutex_t lock; /**< playback lock*/
hualing chen2aba4022020-03-02 13:49:55 +0800328 pthread_mutex_t segment_lock; /**< playback segment lock*/
hualing chen040df222020-01-17 13:35:02 +0800329 pthread_cond_t cond; /**< playback cond*/
330 void *user_data; /**< playback userdata, used to send event*/
hualing chen6d24aa92020-03-23 18:43:47 +0800331 float speed; /**< playback speed*/
hualing chen040df222020-01-17 13:35:02 +0800332 DVR_PlaybackPlayState_t state; /**< playback state*/
333 DVR_PlaybackFlag_t play_flag; /**< playback play flag*/
hualing chen86e7d482020-01-16 15:13:33 +0800334 int is_running; /**< playback htread is runing*/
hualing chen040df222020-01-17 13:35:02 +0800335 DVR_PlaybackCmdInfo_t cmd; /**< playback cmd*/
336 int offset; /**< segment read offset*/
hualing chencc91e1c2020-02-28 13:26:17 +0800337 uint32_t dur; /**< segment dur*/
Wentao MAf35c3882023-04-17 12:36:19 +0800338 Segment_Handle_t segment_handle; /**< playback current segment handle*/
hualing chen040df222020-01-17 13:35:02 +0800339 DVR_PlaybackOpenParams_t openParams; /**< playback openParams*/
hualing chen86e7d482020-01-16 15:13:33 +0800340 DVR_Bool_t has_video; /**< has video playing*/
341 DVR_Bool_t has_audio; /**< has audio playing*/
hualing chendf118dd2020-05-21 15:49:11 +0800342 DVR_Bool_t has_ad_audio; /**< has ad audio playing*/
hualing chen5cbe1a62020-02-10 16:36:36 +0800343 DVR_Bool_t has_pids; /**< has video audo pid fmt info*/
hualing chen7ea70a72021-09-09 11:25:13 +0800344 uint32_t fffb_start; /**< fffb start time ms*/
345 uint32_t fffb_current; /**< fffb current time*/
hualing chen5cbe1a62020-02-10 16:36:36 +0800346 int fffb_start_pcr; /**< fffb start pcr time*/
hualing chen7ea70a72021-09-09 11:25:13 +0800347 uint32_t next_fffb_time;/**< fffb start pcr time*/
hualing chena540a7e2020-03-27 16:44:05 +0800348 int seek_time;/**< fffb start pcr time*/
349 event_callback player_callback_func;/**< tsplayer cb*/
350 void *player_callback_userdata;/**< tsplayer cb data*/
hualing chen7ea70a72021-09-09 11:25:13 +0800351 uint32_t send_time;/**< send event time*/
pengfei.liu27cc4ec2020-04-03 16:28:16 +0800352 int first_frame;/**< show first frame*/
353 DVR_CryptoFunction_t dec_func; /**< Decrypt function*/
354 void *dec_userdata; /**< Decrypt userdata*/
Yahui Han1fbf3292021-11-08 18:17:19 +0800355 void *cryptor; /**< Cryptor for encrypted PVR on FTA.*/
pengfei.liu27cc4ec2020-04-03 16:28:16 +0800356 int is_secure_mode; /**< Playback session run in secure pipeline */
357 uint8_t *secure_buffer; /* Playback session secure buffer */
358 uint32_t secure_buffer_size; /* Playback session secure buffer size */
hualing chen266b9502020-04-04 17:39:39 +0800359 DVR_Bool_t drop_ts;
hualing chen4b7c15d2020-04-07 16:13:48 +0800360 DVR_Bool_t fffb_play;
361 int32_t last_cur_time;
362 uint64_t last_send_time_id;
hualing chen5605eed2020-05-26 18:18:06 +0800363 int ts_cache_len;
hualing chene41f4372020-06-06 16:29:17 +0800364 DVR_Bool_t first_trans_ok;
hualing chenfbf8e022020-06-15 13:43:11 +0800365 DVR_PlaybackVendor_t vendor;
hualing chene3797f02021-01-13 14:53:28 +0800366 int noData;
hualing chena5f03222021-12-02 11:22:35 +0800367 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 +0800368 int last_segment_total; /**< last segment total time*/
hualing chen969fe7b2021-05-26 15:13:17 +0800369
hualing chen03fd4942021-07-15 15:56:41 +0800370 DVR_PlaybackConSpe_t con_spe; /**< inject data speed info*/
371
372 //limit info
373 int obsolete; /**< rec obsolete time in ms*/
hualing chen7ea70a72021-09-09 11:25:13 +0800374 uint32_t rec_start; /**< rec start time in ms*/
375 uint32_t limit; /**< rec data limit time in ms*/
hualing chen8a657f32021-08-30 13:12:49 +0800376 //first play need seek to start time
hualing chen7ea70a72021-09-09 11:25:13 +0800377 uint32_t first_start_time;
Wentao MA01de0e62022-01-10 18:48:23 +0800378 //The segment id where a playback is initially started
379 uint64_t first_start_id;
Wentao MAa0b9c002022-11-10 17:47:27 +0800380
381 // Tells whether the delay from AmTsPlayer_getDelayTime is valid.
382 // Notice it can be invalid in a short period at starting phase of a playback.
383 DVR_Bool_t delay_is_effective;
384
hualing chen8a657f32021-08-30 13:12:49 +0800385 DVR_Bool_t need_seek_start;
hualing chena5f03222021-12-02 11:22:35 +0800386 //init fake pid
387 int fake_pid;
Wentao MA5629ad82022-08-24 10:03:02 +0800388 //Audio presentation id, used for dolby AC4 audio
389 int32_t audio_presentation_id;
shenghui.gengbec6a462023-01-12 15:21:02 +0800390
391 /**< 1: system clock, 0: libdvr can determine index time source based on actual situation*/
392 DVR_Bool_t control_speed_enable;
Zhiqiang Hand5c1c042024-09-14 14:32:28 +0800393 DVR_Bool_t control_speed_enable_user;
394 DVR_Bool_t control_speed_enable_last;
395
396 int fake_mode;
hualing chen040df222020-01-17 13:35:02 +0800397} DVR_Playback_t;
Gong Ke497c4c22020-03-20 10:15:42 +0800398/**\endcond*/
hualing chenb31a6c62020-01-13 17:27:00 +0800399
400/**\brief Open an dvr palyback
401 * \param[out] p_handle dvr playback addr
402 * \param[in] params dvr playback open parameters
403 * \retval DVR_SUCCESS On success
404 * \return Error code
405 */
Gong Ke3489c0f2020-01-16 18:11:44 +0800406int dvr_playback_open(DVR_PlaybackHandle_t *p_handle, DVR_PlaybackOpenParams_t *params);
hualing chenb31a6c62020-01-13 17:27:00 +0800407
408/**\brief Close an dvr palyback
409 * \param[in] handle playback handle
410 * \retval DVR_SUCCESS On success
411 * \return Error code
412 */
Gong Ke3489c0f2020-01-16 18:11:44 +0800413int dvr_playback_close(DVR_PlaybackHandle_t handle);
hualing chenb31a6c62020-01-13 17:27:00 +0800414
415
Wentao MA270dc0f2022-08-23 13:17:26 +0800416/**\brief Start play audio and video, used start audio api and start video api
hualing chenb31a6c62020-01-13 17:27:00 +0800417 * \param[in] handle playback handle
Gong Ke497c4c22020-03-20 10:15:42 +0800418 * \param[in] flag playback flag
hualing chenb31a6c62020-01-13 17:27:00 +0800419 * \retval DVR_SUCCESS On success
420 * \return Error code
421 */
Gong Ke3489c0f2020-01-16 18:11:44 +0800422int dvr_playback_start(DVR_PlaybackHandle_t handle, DVR_PlaybackFlag_t flag);
hualing chenb31a6c62020-01-13 17:27:00 +0800423
hualing chen040df222020-01-17 13:35:02 +0800424/**\brief dvr play back add segment info to segment list
hualing chenb31a6c62020-01-13 17:27:00 +0800425 * \param[in] handle playback handle
hualing chen040df222020-01-17 13:35:02 +0800426 * \param[in] info added segment info,con vpid fmt apid fmt.....
hualing chenb31a6c62020-01-13 17:27:00 +0800427 * \retval DVR_SUCCESS On success
428 * \return Error code
429 */
hualing chen040df222020-01-17 13:35:02 +0800430int dvr_playback_add_segment(DVR_PlaybackHandle_t handle, DVR_PlaybackSegmentInfo_t *info);
hualing chenb31a6c62020-01-13 17:27:00 +0800431
hualing chen040df222020-01-17 13:35:02 +0800432/**\brief dvr play back remove segment info by segmentkid
hualing chenb31a6c62020-01-13 17:27:00 +0800433 * \param[in] handle playback handle
hualing chen040df222020-01-17 13:35:02 +0800434 * \param[in] segmentid need removed segment id
hualing chenb31a6c62020-01-13 17:27:00 +0800435 * \retval DVR_SUCCESS On success
436 * \return Error code
437 */
hualing chen5cbe1a62020-02-10 16:36:36 +0800438int dvr_playback_remove_segment(DVR_PlaybackHandle_t handle, uint64_t segmentid);
hualing chenb31a6c62020-01-13 17:27:00 +0800439
hualing chen040df222020-01-17 13:35:02 +0800440/**\brief dvr play back add segment info
hualing chenb31a6c62020-01-13 17:27:00 +0800441 * \param[in] handle playback handle
Gong Ke497c4c22020-03-20 10:15:42 +0800442 * \param[in] segment_id the segment's index
443 * \param[in] flags the segment's flags
hualing chenb31a6c62020-01-13 17:27:00 +0800444 * \retval DVR_SUCCESS On success
445 * \return Error code
446 */
hualing chen040df222020-01-17 13:35:02 +0800447int dvr_playback_update_segment_flags(DVR_PlaybackHandle_t handle,
hualing chen5cbe1a62020-02-10 16:36:36 +0800448 uint64_t segment_id,
hualing chen040df222020-01-17 13:35:02 +0800449 DVR_PlaybackSegmentFlag_t flags);
Gong Ke497c4c22020-03-20 10:15:42 +0800450
hualing chen040df222020-01-17 13:35:02 +0800451/**\brief dvr play back up1date segment pids
452 * if updated segment is ongoing segment, we need start new
hualing chenb31a6c62020-01-13 17:27:00 +0800453 * add pid stream and stop remove pid stream.
454 * \param[in] handle playback handle
hualing chen040df222020-01-17 13:35:02 +0800455 * \param[in] segment_id need updated pids segment id
Gong Ke497c4c22020-03-20 10:15:42 +0800456 * \param[in] p_pids the new PIDs
hualing chenb31a6c62020-01-13 17:27:00 +0800457 * \retval DVR_SUCCESS On success
458 * \return Error code
459 */
Gong Ke497c4c22020-03-20 10:15:42 +0800460int dvr_playback_update_segment_pids(DVR_PlaybackHandle_t handle, uint64_t segment_id,
hualing chen040df222020-01-17 13:35:02 +0800461DVR_PlaybackPids_t *p_pids);
hualing chenb31a6c62020-01-13 17:27:00 +0800462
hualing chena5f03222021-12-02 11:22:35 +0800463/**\brief dvr play back only up1date segment pids
464 * only update segment info, not stop start codec.
465 * \param[in] handle playback handle
466 * \param[in] segment_id need updated pids segment id
467 * \param[in] p_pids the new PIDs
468 * \retval DVR_SUCCESS On success
469 * \return Error code
470 */
471int dvr_playback_only_update_segment_pids(DVR_PlaybackHandle_t handle, uint64_t segment_id, DVR_PlaybackPids_t *p_pids);
472
Gong Ke497c4c22020-03-20 10:15:42 +0800473/**\brief Stop playing, will stop video and audio
hualing chenb31a6c62020-01-13 17:27:00 +0800474 * \param[in] handle playback handle
475 * \param[in] clear is clear last frame
476 * \retval DVR_SUCCESS On success
477 * \return Error code
478 */
hualing chen040df222020-01-17 13:35:02 +0800479int dvr_playback_stop(DVR_PlaybackHandle_t handle, DVR_Bool_t clear);
hualing chenb31a6c62020-01-13 17:27:00 +0800480
Gong Ke497c4c22020-03-20 10:15:42 +0800481/**\brief Start audio playing
hualing chenb31a6c62020-01-13 17:27:00 +0800482 * \param[in] handle playback handle
483 * \param[in] params audio playback params,contains fmt and pid...
Wentao MA270dc0f2022-08-23 13:17:26 +0800484 * \param[in] ad_params ad audio playback params,contains fmt and pid...
hualing chenb31a6c62020-01-13 17:27:00 +0800485 * \retval DVR_SUCCESS On success
486 * \return Error code
487 */
Wentao MA270dc0f2022-08-23 13:17:26 +0800488int 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 +0800489
hualing chenb31a6c62020-01-13 17:27:00 +0800490
Gong Ke497c4c22020-03-20 10:15:42 +0800491/**\brief Stop audio playing
hualing chenb31a6c62020-01-13 17:27:00 +0800492 * \param[in] handle playback handle
493 * \retval DVR_SUCCESS On success
494 * \return Error code
495 */
hualing chen040df222020-01-17 13:35:02 +0800496int dvr_playback_audio_stop(DVR_PlaybackHandle_t handle);
hualing chenb31a6c62020-01-13 17:27:00 +0800497
Gong Ke497c4c22020-03-20 10:15:42 +0800498/**\brief Start video playing
hualing chenb31a6c62020-01-13 17:27:00 +0800499 * \param[in] handle playback handle
500 * \param[in] params video playback params,contains fmt and pid...
501 * \retval DVR_SUCCESS On success
502 * \return Error code
503 */
Gong Ke497c4c22020-03-20 10:15:42 +0800504int dvr_playback_video_start(DVR_PlaybackHandle_t handle, am_tsplayer_video_params *params);
hualing chenb31a6c62020-01-13 17:27:00 +0800505
506/**\brief Stop play video
507 * \param[in] handle playback handle
508 * \retval DVR_SUCCESS On success
509 * \return Error code
510 */
hualing chen040df222020-01-17 13:35:02 +0800511int dvr_playback_video_stop(DVR_PlaybackHandle_t handle);
hualing chenb31a6c62020-01-13 17:27:00 +0800512
513/**\brief Pause play
514 * \param[in] handle playback handle
515 * \param[in] flush whether its internal buffers should be flushed
516 * \retval DVR_SUCCESS On success
517 * \return Error code
518 */
hualing chen040df222020-01-17 13:35:02 +0800519int dvr_playback_pause(DVR_PlaybackHandle_t handle, DVR_Bool_t flush);
hualing chenb31a6c62020-01-13 17:27:00 +0800520
hualing chen31140872020-03-25 12:29:26 +0800521/**\brief resume play
522 * \param[in] handle playback handle
523 * \retval DVR_SUCCESS On success
524 * \return Error code
525 */
526int dvr_playback_resume(DVR_PlaybackHandle_t handle);
hualing chenb31a6c62020-01-13 17:27:00 +0800527
hualing chen03fd4942021-07-15 15:56:41 +0800528/**\brief set limit
529 * \param[in] handle playback handle
530 * \param[in] rec start time ms
531 * \param[in] rec limit time ms
532 * \retval DVR_SUCCESS On success
533 * \return Error code
534 */
hualing chen7ea70a72021-09-09 11:25:13 +0800535int dvr_playback_setlimit(DVR_PlaybackHandle_t handle, uint32_t time, uint32_t limit);
hualing chen03fd4942021-07-15 15:56:41 +0800536
Gong Ke497c4c22020-03-20 10:15:42 +0800537/**\brief Seek the playing position
hualing chenb31a6c62020-01-13 17:27:00 +0800538 * \param[in] handle playback handle
Gong Ke497c4c22020-03-20 10:15:42 +0800539 * \param[in] segment_id the segment's index
hualing chen040df222020-01-17 13:35:02 +0800540 * \param[in] time_offset time offset base cur segment
hualing chenb31a6c62020-01-13 17:27:00 +0800541 * \retval DVR_SUCCESS On success
542 * \return Error code
543 */
hualing chencc91e1c2020-02-28 13:26:17 +0800544int dvr_playback_seek(DVR_PlaybackHandle_t handle, uint64_t segment_id, uint32_t time_offset);
hualing chenb31a6c62020-01-13 17:27:00 +0800545
546/**\brief Set play speed
547 * \param[in] handle playback handle
548 * \param[in] speed playback speed
549 * \retval DVR_SUCCESS On success
550 * \return Error code
551 */
hualing chen5cbe1a62020-02-10 16:36:36 +0800552int dvr_playback_set_speed(DVR_PlaybackHandle_t handle, DVR_PlaybackSpeed_t speed);
hualing chenb31a6c62020-01-13 17:27:00 +0800553
554/**\brief Get playback status
555 * \param[in] handle playback handle
556 * \param[out] p_status playback status
557 * \retval DVR_SUCCESS On success
558 * \return Error code
559 */
hualing chen040df222020-01-17 13:35:02 +0800560int dvr_playback_get_status(DVR_PlaybackHandle_t handle, DVR_PlaybackStatus_t *p_status);
hualing chenb31a6c62020-01-13 17:27:00 +0800561
562/**\brief Get playback capabilities
563 * \param[out] p_capability playback capability
564 * \retval DVR_SUCCESS On success
565 * \return Error code
566 */
hualing chen040df222020-01-17 13:35:02 +0800567int dvr_playback_get_capabilities(DVR_PlaybackCapability_t *p_capability);
hualing chenb31a6c62020-01-13 17:27:00 +0800568
hualing chen040df222020-01-17 13:35:02 +0800569/**\brief dump segmentinfo throw print log
Gong Ke497c4c22020-03-20 10:15:42 +0800570 * \param[in] handle playback
571 * \param[in] segment_id if segment_id > 0, only dump this log. else dump all segment info
hualing chenb31a6c62020-01-13 17:27:00 +0800572 * \retval DVR_SUCCESS On success
573 * \return Error code
574 */
hualing chen5cbe1a62020-02-10 16:36:36 +0800575int dvr_dump_segmentinfo(DVR_PlaybackHandle_t handle, uint64_t segment_id);
hualing chenb31a6c62020-01-13 17:27:00 +0800576
pengfei.liu07ddc8a2020-03-24 23:36:53 +0800577/**\brief Set DVR playback decrypt function
578 * \param[in] handle, DVR playback session handle
579 * \param[in] func, DVR playback encrypt function
580 * \param[in] userdata, DVR playback userdata from the caller
581 * \return DVR_SUCCESS on success
582 * \return error code on failure
583 */
pengfei.liu27cc4ec2020-04-03 16:28:16 +0800584int dvr_playback_set_decrypt_callback(DVR_PlaybackHandle_t handle, DVR_CryptoFunction_t func, void *userdata);
pengfei.liu07ddc8a2020-03-24 23:36:53 +0800585
586/**\brief Set DVR playback secure buffer used for protect the secure content
587 * \param[in] handle, DVR playback session handle
588 * \param[in] p_secure_buf, Secure buffer address which can NOT access by ACPU
589 * \param[in] len, Secure buffer length
590 * \return DVR_SUCCESS on success
591 * \return error code on failure
592 */
593int dvr_playback_set_secure_buffer(DVR_PlaybackHandle_t handle, uint8_t *p_secure_buf, uint32_t len);
594
hualing chen03fd4942021-07-15 15:56:41 +0800595/**\brief set DVR playback calculate expired time len
596 * \param[in] handle, DVR playback session handle
597 * \return DVR_SUCCESS on success
598 * \return error code on failure
599 */
hualing chen7ea70a72021-09-09 11:25:13 +0800600uint32_t dvr_playback_calculate_expiredlen(DVR_PlaybackHandle_t handle);
hualing chen03fd4942021-07-15 15:56:41 +0800601
602/**\brief set DVR playback obsolete time
603 * \param[in] handle, DVR playback session handle
604 * \param[in] obsolete, obsolete len
605 * \return DVR_SUCCESS on success
606 * \return error code on failure
607 */
608int dvr_playback_set_obsolete(DVR_PlaybackHandle_t handle, int obsolete);
609
610/**\brief update DVR playback newest segment duration
611 * \param[in] handle, DVR playback session handle
612 * \param[in] segmentid, newest segment id
613 * \param[in] dur dur time ms
614 * \return DVR_SUCCESS on success
615 * \return error code on failure
616 */
617int dvr_playback_update_duration(DVR_PlaybackHandle_t handle,
618uint64_t segmentid, int dur);
619
620/**\brief check DVR playback is set limit info
621 * \param[in] handle, DVR playback session handle
622 * \return DVR_FALSE or DVR_TRUE
623 */
624DVR_Bool_t dvr_playback_check_limit(DVR_PlaybackHandle_t handle);
625
Wentao MA5629ad82022-08-24 10:03:02 +0800626/**\brief set ac4 audio preselection id for playback
627 * \param[in] handle, DVR playback session handle
628 * \param[in] presel_id, ac4 preselection id
629 * \return DVR_SUCCESS on success
630 * \return error code on failure
631 */
632int dvr_playback_set_ac4_preselection_id(DVR_PlaybackHandle_t handle, int presel_id);
633
hualing chenb31a6c62020-01-13 17:27:00 +0800634#ifdef __cplusplus
635}
636#endif
637
638#endif /*END DVR_PLAYBACK_H_*/