blob: c571e9e2f84acca1980bfbb1c8e0c8f815eaabdb [file] [log] [blame]
hualing chenb31a6c62020-01-13 17:27:00 +08001#ifndef DVR_PLAYBACK_H_
2#define DVR_PLAYBACK_H_
3#include <amports/aformat.h>
4#include <amports/vformat.h>
5#include "list.h"
6#include "dvr_common.h"
hualing chen86e7d482020-01-16 15:13:33 +08007#include "segment.h"
hualing chenb31a6c62020-01-13 17:27:00 +08008#include "playback_device.h"
9#ifdef __cplusplus
10extern "C" {
11#endif
12/**\brief dvr play chunk flag */
13typedef enum
14{
hualing chen86e7d482020-01-16 15:13:33 +080015 DVR_PLAY_ENCRYPTED = (1 << 0), /**< encrypted stream */
16 DVR_PLAY_DISPLAYABLE = (1 << 1), /**< displayable stream */
17 DVR_PLAY_CONTINUOUS = (1 << 2) /**< continuous stream with pre one */
18} DVR_Playback_Chunk_Flag_t;
hualing chenb31a6c62020-01-13 17:27:00 +080019
20/**\brief dvr pid type*/
21typedef struct
22{
hualing chen86e7d482020-01-16 15:13:33 +080023 int pid; /**< stream pid */
24 int fmt; /**< stream fmt */
25} DVR_Playback_StreamParams_t;
hualing chenb31a6c62020-01-13 17:27:00 +080026
27/**\brief dvr pid type*/
28typedef enum
29{
hualing chen86e7d482020-01-16 15:13:33 +080030 DVR_PLAY_SYNC, /**< sync play mode */
31 DVR_PLAY_ASYNC /**< out of sync play mode */
32} DVR_PlayBack_Sync_Mode_t;
hualing chenb31a6c62020-01-13 17:27:00 +080033
34
35/**\brief dvr play pids */
36typedef struct
37{
hualing chen86e7d482020-01-16 15:13:33 +080038 DVR_Playback_StreamParams_t vpid; /**< video pid */
39 DVR_Playback_StreamParams_t apid; /**< audio pid */
40 DVR_Playback_StreamParams_t pcrpid; /**< pcr pid */
41 DVR_Playback_StreamParams_t sub_apid; /**< sub audio pid */
42} DVR_Playback_Pids_t;
hualing chenb31a6c62020-01-13 17:27:00 +080043
44/**\brief dvr chunk info */
45typedef struct
46{
hualing chen86e7d482020-01-16 15:13:33 +080047 struct list_head head; /**< chunk list head */
48 int chunk_id; /**< chunk id */
49 uint8_t location[DVR_MAX_LOCATION_SIZE]; /**< chunk location */
50 DVR_Playback_Pids_t pids; /**< chunk cons pids */
51 DVR_Playback_Chunk_Flag_t flags; /**< chunk flag */
52 int key_data_id; /**< ??? */
53} DVR_Playback_Chunk_Info_t;
hualing chenb31a6c62020-01-13 17:27:00 +080054
55/**\brief play flag, if set this flag, player need pause when decode first frame */
56typedef enum
57{
hualing chen86e7d482020-01-16 15:13:33 +080058 DVR_PLAY_STARTED_PAUSEDLIVE = (1 << 0) /**< dvr play stat,need change to pause state if set */
59} DVR_Playback_Flag_t;
hualing chenb31a6c62020-01-13 17:27:00 +080060
hualing chen86e7d482020-01-16 15:13:33 +080061
62/**\brief playback speed mode*/
hualing chenb31a6c62020-01-13 17:27:00 +080063typedef enum
64{
hualing chen86e7d482020-01-16 15:13:33 +080065 DVR_PLAY_FAST_FORWARD = 0, /**< fast forward */
66 DVR_PLAY_FAST_BACKWARD = 1, /**< fast backward */
67} DVR_Playback_SpeedMode_t;
hualing chenb31a6c62020-01-13 17:27:00 +080068
69
70/**\brief playback play status*/
71typedef struct
72{
hualing chen86e7d482020-01-16 15:13:33 +080073 Playback_Device_Speeds_t speed; /**< playback speed */
74 DVR_Playback_SpeedMode_t mode; /**< playback 0: fast forword or 1: fast backword*/
75} DVR_Playback_Speed_t;
hualing chenb31a6c62020-01-13 17:27:00 +080076
77#define DVR_MAX_SUPPORTED_SPEEDS 32
78/**\brief playback capability*/
79typedef struct
80{
hualing chen86e7d482020-01-16 15:13:33 +080081 int nb_supported_speeds; /**< support playback speed count*/
82 int supported_speeds[DVR_MAX_SUPPORTED_SPEEDS]; /**< support playback speed*/
83} DVR_Playback_Capability_t;
hualing chenb31a6c62020-01-13 17:27:00 +080084
85typedef void* DVR_Playback_Handle_t;
86
87/**\brief playback play state*/
88typedef enum
89{
hualing chen86e7d482020-01-16 15:13:33 +080090 DVR_PlayBack_State_Unint, /**< uninit state */
91 DVR_PlayBack_State_Init, /**< init state, open device */
92 DVR_PlayBack_State_Start, /**< start play */
93 DVR_PlayBack_State_Stop, /**< stop */
94 DVR_PlayBack_State_Pause, /**< pause */
95 DVR_PlayBack_State_FF, /**< fast forward */
96 DVR_PlayBack_State_FB, /**< fast backword */
hualing chenb31a6c62020-01-13 17:27:00 +080097} DVR_PlayBack_Play_State_t;
98
99/**\brief playback play status*/
100typedef struct
101{
hualing chen86e7d482020-01-16 15:13:33 +0800102 DVR_PlayBack_Play_State_t state; /**< playback play state */
103 int chunk_id; /**< playback ongoing chunkid */
104 int time_cur; /**< playback cur time,0 <--> time_end Ms*/
105 int time_end; /**< playback ongoing chunk dur,Ms */
106 DVR_Playback_Pids_t pids; /**< playback played pids */
107 int speed; /**< playback played speed */
108 DVR_Playback_Chunk_Flag_t flags; /**< playback played chunk flag */
109} DVR_Playback_Status_t;
hualing chenb31a6c62020-01-13 17:27:00 +0800110
111/**\brief playback play params*/
112typedef struct
113{
hualing chen86e7d482020-01-16 15:13:33 +0800114 int vpid; /**< video pid*/
115 int vfmt; /**< video fmt*/
116 int apid; /**< audio pid*/
117 int afmt; /**< audio fmt*/
118 int sub_apid; /**< sub audio pid*/
119 int sub_afmt; /**< sub audio fmt*/
120 int pcr_pid; /**< pcr pid*/
121} DVR_PlayBack_PlayParams_t;
hualing chenb31a6c62020-01-13 17:27:00 +0800122
123/**\brief playback open params*/
124typedef struct
125{
hualing chen86e7d482020-01-16 15:13:33 +0800126 int dmx; /**< playback used dmx device index*/
127 int blocksize; /**< playback inject block size*/
128 int is_timeshift;/**< 0:playback mode, 1 : is timeshift mode*/
129} DVR_PlayBack_OpenParams_t;
hualing chenb31a6c62020-01-13 17:27:00 +0800130
131/**\brief playback play state*/
132typedef enum
133{
hualing chen86e7d482020-01-16 15:13:33 +0800134 DVR_PlayBack_Cmd_Start, /**< start av */
135 DVR_PlayBack_Cmd_Stop, /**< stop av */
136 DVR_PlayBack_Cmd_VStart, /**< v start */
137 DVR_PlayBack_Cmd_AStart, /**< a start */
138 DVR_PlayBack_Cmd_VStop, /**< v stop */
139 DVR_PlayBack_Cmd_AStop, /**< a stop */
140 DVR_PlayBack_Cmd_VReStart, /**<v restart */
141 DVR_PlayBack_Cmd_AReStart, /**< a restart */
142 DVR_PlayBack_Cmd_VStopAStart, /**< v stop a start*/
143 DVR_PlayBack_Cmd_AStopVStart, /**< a stop vstart */
144 DVR_PlayBack_Cmd_VStopAReStart, /**<v stop a restart*/
145 DVR_PlayBack_Cmd_AStopVReStart, /**<a stop v restart*/
146 DVR_PlayBack_Cmd_Pause, /**< pause */
147 DVR_PlayBack_Cmd_Resume, /**< resume */
148 DVR_PlayBack_Cmd_Seek, /**< seek */
149 DVR_PlayBack_Cmd_FF, /**< fast forward */
150 DVR_PlayBack_Cmd_FB, /**< fast backword */
151} DVR_Playback_Cmd_t;
hualing chenb31a6c62020-01-13 17:27:00 +0800152
153
154/**\brief playback struct*/
155typedef struct
156{
hualing chen86e7d482020-01-16 15:13:33 +0800157 Playback_Device_Speeds_t speed; /**< play speed */
158 DVR_PlayBack_Play_State_t state; /**< plat state */
159 DVR_Playback_Cmd_t cur_cmd; /**< cur send cmd */
160 DVR_Playback_Cmd_t last_cmd; /**< last cmd */
161 int pos; /**< seek pos at cur chunk*/
162} DVR_PlayBack_CmdInfo_t;
hualing chenb31a6c62020-01-13 17:27:00 +0800163
164
165/**\brief playback struct*/
166typedef struct
167{
hualing chen86e7d482020-01-16 15:13:33 +0800168 Playback_DeviceHandle handle; /**< device handle */
169 int cur_chunkid; /**< Current chunk id*/
170 DVR_Playback_Chunk_Info_t cur_chunk; /**< Current playing chunk*/
171 struct list_head chunk_list; /**< chunk list head*/
172 pthread_t playback_thread; /**< playback thread*/
173 pthread_mutex_t lock; /**< playback lock*/
174 pthread_cond_t cond; /**< playback cond*/
175 void *user_data; /**< playback userdata, used to send event*/
176 DVR_PlayBack_PlayParams_t params; /**< playback playparams,cont vpid vfm apid afmt...*/
177 Playback_Device_Speeds_t speed; /**< playback speed*/
178 DVR_PlayBack_Play_State_t state; /**< playback state*/
179 DVR_Playback_Flag_t play_flag; /**< playback play flag*/
180 int is_running; /**< playback htread is runing*/
181 DVR_PlayBack_CmdInfo_t cmd; /**< playback cmd*/
182 int offset; /**< chunk read offset*/
183 Segment_Handle_t r_handle; /**< playback current segment handle*/
184 DVR_PlayBack_OpenParams_t openParams; /**< playback openParams*/
185 DVR_Bool_t has_video; /**< has video playing*/
186 DVR_Bool_t has_audio; /**< has audio playing*/
hualing chenb31a6c62020-01-13 17:27:00 +0800187} Dvr_PlayBack_t;
188
189/**\brief Open an dvr palyback
190 * \param[out] p_handle dvr playback addr
191 * \param[in] params dvr playback open parameters
192 * \retval DVR_SUCCESS On success
193 * \return Error code
194 */
hualing chen86e7d482020-01-16 15:13:33 +0800195int dvr_playback_open(DVR_Playback_Handle_t *p_handle, DVR_PlayBack_OpenParams_t *params);
hualing chenb31a6c62020-01-13 17:27:00 +0800196
197/**\brief Close an dvr palyback
198 * \param[in] handle playback handle
199 * \retval DVR_SUCCESS On success
200 * \return Error code
201 */
202int dvr_playback_close(DVR_Playback_Handle_t handle);
203
204
205/**\brief Start play audio and video, used start auido api and start video api
206 * \param[in] handle playback handle
207 * \param[in] params audio playback params,contains fmt and pid...
208 * \retval DVR_SUCCESS On success
209 * \return Error code
210 */
hualing chen86e7d482020-01-16 15:13:33 +0800211int dvr_playback_start(DVR_Playback_Handle_t handle, DVR_Playback_Flag_t flag);
hualing chenb31a6c62020-01-13 17:27:00 +0800212
213/**\brief dvr play back add chunk info to chunk list
214 * \param[in] handle playback handle
215 * \param[in] info added chunk info,con vpid fmt apid fmt.....
216 * \retval DVR_SUCCESS On success
217 * \return Error code
218 */
hualing chen86e7d482020-01-16 15:13:33 +0800219int dvr_playback_add_chunk(DVR_Playback_Handle_t handle, DVR_Playback_Chunk_Info_t *info);
hualing chenb31a6c62020-01-13 17:27:00 +0800220
221/**\brief dvr play back remove chunk info by chunkid
222 * \param[in] handle playback handle
223 * \param[in] chunkid need removed chunk id
224 * \retval DVR_SUCCESS On success
225 * \return Error code
226 */
227int dvr_playback_remove_chunk(DVR_Playback_Handle_t handle, int chunkid);
228
229/**\brief dvr play back add chunk info
230 * \param[in] handle playback handle
231 * \param[in] info added chunk info,con vpid fmt apid fmt.....
232 * \retval DVR_SUCCESS On success
233 * \return Error code
234 */
235int dvr_playback_Update_Chunk_Flags(DVR_Playback_Handle_t handle,
236 int chunk_id,
hualing chen86e7d482020-01-16 15:13:33 +0800237 DVR_Playback_Chunk_Flag_t flags);
hualing chenb31a6c62020-01-13 17:27:00 +0800238/**\brief dvr play back update chunk pids
239 * if updated chunk is ongoing chunk, we need start new
240 * add pid stream and stop remove pid stream.
241 * \param[in] handle playback handle
242 * \param[in] chunk_id need updated pids chunk id
243 * \retval DVR_SUCCESS On success
244 * \return Error code
245 */
246int dvr_playback_Update_Chunk_Pids(DVR_Playback_Handle_t handle, int chunkid,
hualing chen86e7d482020-01-16 15:13:33 +0800247DVR_Playback_Pids_t *p_pids);
hualing chenb31a6c62020-01-13 17:27:00 +0800248
249/**\brief Stop play, will stop video and audio
250 * \param[in] handle playback handle
251 * \param[in] clear is clear last frame
252 * \retval DVR_SUCCESS On success
253 * \return Error code
254 */
255int dvr_playback_stop(DVR_Playback_Handle_t handle, DVR_Bool_t clear);
256
257/**\brief Start play audio
258 * \param[in] handle playback handle
259 * \param[in] params audio playback params,contains fmt and pid...
260 * \retval DVR_SUCCESS On success
261 * \return Error code
262 */
hualing chen86e7d482020-01-16 15:13:33 +0800263int dvr_playback_audio_start(DVR_Playback_Handle_t handle, Playback_Device_AudioParams_t *param);
hualing chenb31a6c62020-01-13 17:27:00 +0800264
265/**\brief Stop play audio
266 * \param[in] handle playback handle
267 * \retval DVR_SUCCESS On success
268 * \return Error code
269 */
270int dvr_playback_audio_stop(DVR_Playback_Handle_t handle);
271
272/**\brief Start play video
273 * \param[in] handle playback handle
274 * \param[in] params video playback params,contains fmt and pid...
275 * \retval DVR_SUCCESS On success
276 * \return Error code
277 */
hualing chen86e7d482020-01-16 15:13:33 +0800278int dvr_playback_video_start(DVR_Playback_Handle_t handle, Playback_Device_VideoParams_t *param);
hualing chenb31a6c62020-01-13 17:27:00 +0800279
280/**\brief Stop play video
281 * \param[in] handle playback handle
282 * \retval DVR_SUCCESS On success
283 * \return Error code
284 */
285int dvr_playback_video_stop(DVR_Playback_Handle_t handle);
286
287/**\brief Pause play
288 * \param[in] handle playback handle
289 * \param[in] flush whether its internal buffers should be flushed
290 * \retval DVR_SUCCESS On success
291 * \return Error code
292 */
293int dvr_playback_pause(DVR_Playback_Handle_t handle, DVR_Bool_t flush);
294
295
296/**\brief seek
297 * \param[in] handle playback handle
298 * \param[in] time_offset time offset base cur chunk
299 * \retval DVR_SUCCESS On success
300 * \return Error code
301 */
302int dvr_playback_seek(DVR_Playback_Handle_t handle, int chunk_id, int time_offset);
303
304/**\brief Set play speed
305 * \param[in] handle playback handle
306 * \param[in] speed playback speed
307 * \retval DVR_SUCCESS On success
308 * \return Error code
309 */
hualing chen86e7d482020-01-16 15:13:33 +0800310int dvr_playback_set_speed(DVR_Playback_Handle_t handle, Playback_Device_Speeds_t speed);
hualing chenb31a6c62020-01-13 17:27:00 +0800311
312/**\brief Get playback status
313 * \param[in] handle playback handle
314 * \param[out] p_status playback status
315 * \retval DVR_SUCCESS On success
316 * \return Error code
317 */
hualing chen86e7d482020-01-16 15:13:33 +0800318int dvr_playback_get_status(DVR_Playback_Handle_t handle, DVR_Playback_Status_t *p_status);
hualing chenb31a6c62020-01-13 17:27:00 +0800319
320/**\brief Get playback capabilities
321 * \param[out] p_capability playback capability
322 * \retval DVR_SUCCESS On success
323 * \return Error code
324 */
hualing chen86e7d482020-01-16 15:13:33 +0800325int dvr_playback_get_capabilities(DVR_Playback_Capability_t *p_capability);
hualing chenb31a6c62020-01-13 17:27:00 +0800326
327/**\brief dump chunkinfo throw print log
328 * \param[int] handle playback
329 * \param[int] chunk_id if chunk_id > 0, only dump this log. else dump all chunk info
330 * \retval DVR_SUCCESS On success
331 * \return Error code
332 */
333int dvr_dump_chunkinfo(DVR_Playback_Handle_t handle, int chunk_id);
334
335#ifdef __cplusplus
336}
337#endif
338
339#endif /*END DVR_PLAYBACK_H_*/