blob: fa0ee89de15df22421d0064f1920fee9a502e904 [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"
7#include "playback_device.h"
8#ifdef __cplusplus
9extern "C" {
10#endif
11/**\brief dvr play chunk flag */
12typedef enum
13{
14 DVR_PLAY_ENCRYPTED = (1 << 0), /**< encrypted stream */
15 DVR_PLAY_DISPLAYABLE = (1 << 1), /**< displayable stream */
16 DVR_PLAY_CONTINUOUS = (1 << 2) /**< continuous stream with pre one */
17} DVR_Play_Chunk_Flag_t;
18
19/**\brief dvr pid type*/
20typedef struct
21{
22 int pid; /**< stream pid */
23 int fmt; /**< stream fmt */
24} DVR_PID_t;
25
26/**\brief dvr pid type*/
27typedef enum
28{
29 DVR_PLAY_SYNC, /**< sync play mode */
30 DVR_PLAY_ASYNC /**< out of sync play mode */
31} DVR_PlayBack_Sync_Mode;
32
33
34/**\brief dvr play pids */
35typedef struct
36{
37 DVR_PID_t vpid; /**< video pid */
38 DVR_PID_t apid; /**< audio pid */
39 DVR_PID_t pcrpid; /**< pcr pid */
40 DVR_PID_t sub_apid; /**< sub audio pid */
41} DVR_Play_Pids_t;
42
43/**\brief dvr chunk info */
44typedef struct
45{
46 struct list_head head;
47 int chunk_id; /**< chunk id */
48 uint8_t location[DVR_MAX_LOCATION_SIZE]; /**< chunk location */
49 DVR_Play_Pids_t pids; /**< chunk cons pids */
50 DVR_Play_Chunk_Flag_t flags; /**< chunk flag */
51 int key_data_id; /**< ??? */
52} DVR_Play_Chunk_Info_t;
53
54/**\brief play flag, if set this flag, player need pause when decode first frame */
55typedef enum
56{
57 DVR_PLAY_STARTED_PAUSEDLIVE = (1 << 0)
58} DVR_Play_Flag_t;
59
60typedef enum
61{
62 DVR_PLAY_FAST_FORWARD = 0,
63 DVR_PLAY_FAST_BACKWARD = 1,
64} DVR_Play_SpeedMode_t;
65
66
67/**\brief playback play status*/
68typedef struct
69{
70 Playback_Speed speed; /**< playback speed */
71 DVR_Play_SpeedMode_t mode; /**< playback 0: fast forword or 1: fast backword*/
72} DVR_Playback_Speed;
73
74#define DVR_MAX_SUPPORTED_SPEEDS 32
75/**\brief playback capability*/
76typedef struct
77{
78 int nb_supported_speeds; /**< support playback speed count*/
79 int supported_speeds[DVR_MAX_SUPPORTED_SPEEDS]; /**< support playback speed*/
80} DVR_Play_Capability_t;
81
82typedef void* DVR_Playback_Handle_t;
83
84/**\brief playback play state*/
85typedef enum
86{
87 DVR_PlayBack_State_Unint, /**< uninit state */
88 DVR_PlayBack_State_Init, /**< init state, open device */
89 DVR_PlayBack_State_Start, /**< start play */
90 DVR_PlayBack_State_Stop, /**< stop */
91 DVR_PlayBack_State_Pause, /**< pause */
92 DVR_PlayBack_State_FF, /**< fast forward */
93 DVR_PlayBack_State_FB, /**< fast backword */
94} DVR_PlayBack_Play_State_t;
95
96/**\brief playback play status*/
97typedef struct
98{
99 DVR_PlayBack_Play_State_t state; /**< playback play state */
100 int chunk_id; /**< playback ongoing chunkid */
101 int time_cur; /**< playback cur time,0 <--> time_end Ms*/
102 int time_end; /**< playback ongoing chunk dur,Ms */
103 DVR_Play_Pids_t pids; /**< playback played pids */
104 int speed; /**< playback played speed */
105 DVR_Play_Chunk_Flag_t flags; /**< playback played chunk flag */
106} DVR_Play_Status_t;
107
108/**\brief playback play params*/
109typedef struct
110{
111 int vpid; /**< video pid*/
112 int vfmt; /**< video fmt*/
113 int apid; /**< audio pid*/
114 int afmt; /**< audio fmt*/
115 int sub_apid; /**< sub audio pid*/
116 int sub_afmt; /**< sub audio fmt*/
117 int pcr_pid; /**< pcr pid*/
118} DVR_PlayBack_playParams;
119
120/**\brief playback open params*/
121typedef struct
122{
123 int dmx; /**< playback used dmx device index*/
124 int blocksize; /**< playback inject block size*/
125} DVR_PlayBack_openParams;
126
127/**\brief playback play state*/
128typedef enum
129{
130 DVR_PlayBack_Cmd_Start, /**< start av */
131 DVR_PlayBack_Cmd_Stop, /**< stop av */
132 DVR_PlayBack_Cmd_VStart, /**< v start */
133 DVR_PlayBack_Cmd_AStart, /**< a start */
134 DVR_PlayBack_Cmd_VStop, /**< v stop */
135 DVR_PlayBack_Cmd_AStop, /**< a stop */
136 DVR_PlayBack_Cmd_VReStart, /**<v restart */
137 DVR_PlayBack_Cmd_AReStart, /**< a restart */
138 DVR_PlayBack_Cmd_VStopAStart, /**< v stop a start*/
139 DVR_PlayBack_Cmd_AStopVStart, /**< a stop vstart */
140 DVR_PlayBack_Cmd_VStopAReStart, /**<v stop a restart*/
141 DVR_PlayBack_Cmd_AStopVReStart, /**<a stop v restart*/
142 DVR_PlayBack_Cmd_Pause, /**< pause */
143 DVR_PlayBack_Cmd_Resume, /**< resume */
144 DVR_PlayBack_Cmd_Seek, /**< seek */
145 DVR_PlayBack_Cmd_FF, /**< fast forward */
146 DVR_PlayBack_Cmd_FB, /**< fast backword */
147} DVR_Play_Cmd_t;
148
149
150/**\brief playback struct*/
151typedef struct
152{
153 Playback_Speed speed;
154 DVR_PlayBack_Play_State_t state;
155 DVR_Play_Cmd_t cur_cmd;
156 DVR_Play_Cmd_t last_cmd;
157 int pos;
158} Dvr_PlayBack_Cmd_t;
159
160
161/**\brief playback struct*/
162typedef struct
163{
164 Playback_DeviceHandle handle;
165 int cur_chunkid; /**< Current filename*/
166 DVR_Play_Chunk_Info_t cur_chunk; /**< chunk info list*/
167 struct list_head chunk_list;
168 pthread_t playback_thread;
169 pthread_mutex_t lock;
170 pthread_cond_t cond;
171 void *user_data;
172 DVR_PlayBack_playParams params;
173 Playback_Speed speed;
174 DVR_PlayBack_Play_State_t state;
175 DVR_Play_Flag_t play_flag;
176 int is_running;
177 Dvr_PlayBack_Cmd_t cmd;
178 int offset;/**< chunk read offset*/
179} Dvr_PlayBack_t;
180
181/**\brief Open an dvr palyback
182 * \param[out] p_handle dvr playback addr
183 * \param[in] params dvr playback open parameters
184 * \retval DVR_SUCCESS On success
185 * \return Error code
186 */
187int dvr_playback_open(DVR_Playback_Handle_t *p_handle, DVR_PlayBack_openParams *params);
188
189/**\brief Close an dvr palyback
190 * \param[in] handle playback handle
191 * \retval DVR_SUCCESS On success
192 * \return Error code
193 */
194int dvr_playback_close(DVR_Playback_Handle_t handle);
195
196
197/**\brief Start play audio and video, used start auido api and start video api
198 * \param[in] handle playback handle
199 * \param[in] params audio playback params,contains fmt and pid...
200 * \retval DVR_SUCCESS On success
201 * \return Error code
202 */
203int dvr_playback_start(DVR_Playback_Handle_t handle, DVR_Play_Flag_t flag);
204
205/**\brief dvr play back add chunk info to chunk list
206 * \param[in] handle playback handle
207 * \param[in] info added chunk info,con vpid fmt apid fmt.....
208 * \retval DVR_SUCCESS On success
209 * \return Error code
210 */
211int dvr_playback_add_chunk(DVR_Playback_Handle_t handle, DVR_Play_Chunk_Info_t *info);
212
213/**\brief dvr play back remove chunk info by chunkid
214 * \param[in] handle playback handle
215 * \param[in] chunkid need removed chunk id
216 * \retval DVR_SUCCESS On success
217 * \return Error code
218 */
219int dvr_playback_remove_chunk(DVR_Playback_Handle_t handle, int chunkid);
220
221/**\brief dvr play back add chunk info
222 * \param[in] handle playback handle
223 * \param[in] info added chunk info,con vpid fmt apid fmt.....
224 * \retval DVR_SUCCESS On success
225 * \return Error code
226 */
227int dvr_playback_Update_Chunk_Flags(DVR_Playback_Handle_t handle,
228 int chunk_id,
229 DVR_Play_Chunk_Flag_t flags);
230/**\brief dvr play back update chunk pids
231 * if updated chunk is ongoing chunk, we need start new
232 * add pid stream and stop remove pid stream.
233 * \param[in] handle playback handle
234 * \param[in] chunk_id need updated pids chunk id
235 * \retval DVR_SUCCESS On success
236 * \return Error code
237 */
238int dvr_playback_Update_Chunk_Pids(DVR_Playback_Handle_t handle, int chunkid,
239DVR_Play_Pids_t *p_pids);
240
241/**\brief Stop play, will stop video and audio
242 * \param[in] handle playback handle
243 * \param[in] clear is clear last frame
244 * \retval DVR_SUCCESS On success
245 * \return Error code
246 */
247int dvr_playback_stop(DVR_Playback_Handle_t handle, DVR_Bool_t clear);
248
249/**\brief Start play audio
250 * \param[in] handle playback handle
251 * \param[in] params audio playback params,contains fmt and pid...
252 * \retval DVR_SUCCESS On success
253 * \return Error code
254 */
255int dvr_playback_audio_start(DVR_Playback_Handle_t handle, Playback_AudioParams *param);
256
257/**\brief Stop play audio
258 * \param[in] handle playback handle
259 * \retval DVR_SUCCESS On success
260 * \return Error code
261 */
262int dvr_playback_audio_stop(DVR_Playback_Handle_t handle);
263
264/**\brief Start play video
265 * \param[in] handle playback handle
266 * \param[in] params video playback params,contains fmt and pid...
267 * \retval DVR_SUCCESS On success
268 * \return Error code
269 */
270int dvr_playback_video_start(DVR_Playback_Handle_t handle, Playback_VideoParams *param);
271
272/**\brief Stop play video
273 * \param[in] handle playback handle
274 * \retval DVR_SUCCESS On success
275 * \return Error code
276 */
277int dvr_playback_video_stop(DVR_Playback_Handle_t handle);
278
279/**\brief Pause play
280 * \param[in] handle playback handle
281 * \param[in] flush whether its internal buffers should be flushed
282 * \retval DVR_SUCCESS On success
283 * \return Error code
284 */
285int dvr_playback_pause(DVR_Playback_Handle_t handle, DVR_Bool_t flush);
286
287
288/**\brief seek
289 * \param[in] handle playback handle
290 * \param[in] time_offset time offset base cur chunk
291 * \retval DVR_SUCCESS On success
292 * \return Error code
293 */
294int dvr_playback_seek(DVR_Playback_Handle_t handle, int chunk_id, int time_offset);
295
296/**\brief Set play speed
297 * \param[in] handle playback handle
298 * \param[in] speed playback speed
299 * \retval DVR_SUCCESS On success
300 * \return Error code
301 */
302int dvr_playback_set_speed(DVR_Playback_Handle_t handle, Playback_Speed speed);
303
304/**\brief Get playback status
305 * \param[in] handle playback handle
306 * \param[out] p_status playback status
307 * \retval DVR_SUCCESS On success
308 * \return Error code
309 */
310int dvr_playback_get_status(DVR_Playback_Handle_t handle, DVR_Play_Status_t *p_status);
311
312/**\brief Get playback capabilities
313 * \param[out] p_capability playback capability
314 * \retval DVR_SUCCESS On success
315 * \return Error code
316 */
317int dvr_playback_get_capabilities(DVR_Play_Capability_t *p_capability);
318
319/**\brief dump chunkinfo throw print log
320 * \param[int] handle playback
321 * \param[int] chunk_id if chunk_id > 0, only dump this log. else dump all chunk info
322 * \retval DVR_SUCCESS On success
323 * \return Error code
324 */
325int dvr_dump_chunkinfo(DVR_Playback_Handle_t handle, int chunk_id);
326
327#ifdef __cplusplus
328}
329#endif
330
331#endif /*END DVR_PLAYBACK_H_*/