hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 1 | #include <stdio.h> |
| 2 | #include <stdlib.h> |
| 3 | |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 4 | #include <string.h> |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 5 | #include <sys/types.h> |
| 6 | #include <sys/stat.h> |
| 7 | #include <sys/ioctl.h> |
| 8 | #include <fcntl.h> |
| 9 | #include <unistd.h> |
| 10 | #include <poll.h> |
| 11 | #include <errno.h> |
| 12 | #include <signal.h> |
| 13 | #include <pthread.h> |
hualing chen | b5cd42e | 2020-04-15 17:03:34 +0800 | [diff] [blame] | 14 | #include <errno.h> |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 15 | |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 16 | #include "dvr_playback.h" |
| 17 | |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 18 | #define DVR_PB_DG(_level, _fmt, ...) \ |
| 19 | DVR_DEBUG(_level, "playback %-30.30s:%d " _fmt, __FUNCTION__, __LINE__, ##__VA_ARGS__) |
| 20 | |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 21 | |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 22 | #define VALID_PID(_pid_) ((_pid_)>0 && (_pid_)<0x1fff) |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 23 | |
| 24 | |
| 25 | #define FF_SPEED (2.0f) |
| 26 | #define FB_SPEED (-1.0f) |
| 27 | #define IS_FFFB(_SPEED_) ((_SPEED_) > FF_SPEED && (_SPEED_) < FB_SPEED) |
hualing chen | e41f437 | 2020-06-06 16:29:17 +0800 | [diff] [blame] | 28 | #define IS_FB(_SPEED_) ((_SPEED_) <= FB_SPEED) |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 29 | |
| 30 | #define IS_KERNEL_SPEED(_SPEED_) (((_SPEED_) == PLAYBACK_SPEED_X2) || ((_SPEED_) == PLAYBACK_SPEED_X1) || ((_SPEED_) == PLAYBACK_SPEED_S2) || ((_SPEED_) == PLAYBACK_SPEED_S4) || ((_SPEED_) == PLAYBACK_SPEED_S8)) |
| 31 | #define IS_FAST_SPEED(_SPEED_) (((_SPEED_) == PLAYBACK_SPEED_X2) || ((_SPEED_) == PLAYBACK_SPEED_S2) || ((_SPEED_) == PLAYBACK_SPEED_S4) || ((_SPEED_) == PLAYBACK_SPEED_S8)) |
| 32 | |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 33 | |
hualing chen | b5cd42e | 2020-04-15 17:03:34 +0800 | [diff] [blame] | 34 | #define FFFB_SLEEP_TIME (1000)//500ms |
hualing chen | e41f437 | 2020-06-06 16:29:17 +0800 | [diff] [blame] | 35 | #define FB_DEFAULT_LEFT_TIME (3000) |
hualing chen | 3114087 | 2020-03-25 12:29:26 +0800 | [diff] [blame] | 36 | //if tsplayer delay time < 200 and no data can read, we will pause |
| 37 | #define MIN_TSPLAYER_DELAY_TIME (200) |
| 38 | |
hualing chen | 041c409 | 2020-04-05 15:11:50 +0800 | [diff] [blame] | 39 | #define MAX_CACHE_TIME (30000) |
| 40 | |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 41 | static int write_success = 0; |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 42 | // |
| 43 | static int _dvr_playback_fffb(DVR_PlaybackHandle_t handle); |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame] | 44 | static int _do_check_pid_info(DVR_PlaybackHandle_t handle, DVR_StreamInfo_t now_pid, DVR_StreamInfo_t set_pid, int type); |
| 45 | static int _dvr_get_cur_time(DVR_PlaybackHandle_t handle); |
| 46 | static int _dvr_get_end_time(DVR_PlaybackHandle_t handle); |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 47 | static int _dvr_playback_calculate_seekpos(DVR_PlaybackHandle_t handle); |
hualing chen | 87072a8 | 2020-03-12 16:20:12 +0800 | [diff] [blame] | 48 | static int _dvr_playback_replay(DVR_PlaybackHandle_t handle, DVR_Bool_t trick) ; |
hualing chen | 2932d37 | 2020-04-29 13:44:00 +0800 | [diff] [blame] | 49 | static int _dvr_playback_get_status(DVR_PlaybackHandle_t handle, |
| 50 | DVR_PlaybackStatus_t *p_status, DVR_Bool_t is_lock); |
hualing chen | e41f437 | 2020-06-06 16:29:17 +0800 | [diff] [blame] | 51 | static int _dvr_playback_sent_transition_ok(DVR_PlaybackHandle_t handle, DVR_Bool_t is_lock); |
hualing chen | 87072a8 | 2020-03-12 16:20:12 +0800 | [diff] [blame] | 52 | |
hualing chen | bcada02 | 2020-04-22 14:27:01 +0800 | [diff] [blame] | 53 | |
| 54 | static char* _cmd_toString(int cmd) |
| 55 | { |
| 56 | |
| 57 | char *string[DVR_PLAYBACK_CMD_NONE+1]={ |
| 58 | "start", |
| 59 | "stop", |
| 60 | "vstart", |
| 61 | "astart", |
| 62 | "vstop", |
| 63 | "astop", |
| 64 | "vrestart", |
| 65 | "arestart", |
| 66 | "avrestart", |
| 67 | "vstopastart", |
| 68 | "astopvstart", |
| 69 | "vstoparestart", |
| 70 | "astopvrestart", |
| 71 | "vstartarestart", |
| 72 | "astartvrestart", |
| 73 | "pause", |
| 74 | "resume", |
| 75 | "seek", |
| 76 | "ff", |
| 77 | "fb", |
| 78 | "NONE" |
| 79 | }; |
| 80 | |
| 81 | if (cmd > DVR_PLAYBACK_CMD_NONE) { |
| 82 | return "unkown"; |
| 83 | } else { |
| 84 | return string[cmd]; |
| 85 | } |
| 86 | } |
| 87 | |
| 88 | |
hualing chen | 6d24aa9 | 2020-03-23 18:43:47 +0800 | [diff] [blame] | 89 | static char* _dvr_playback_state_toString(int stat) |
| 90 | { |
| 91 | char *string[DVR_PLAYBACK_STATE_FB+1]={ |
| 92 | "start", |
hualing chen | 6d24aa9 | 2020-03-23 18:43:47 +0800 | [diff] [blame] | 93 | "stop", |
hualing chen | 3114087 | 2020-03-25 12:29:26 +0800 | [diff] [blame] | 94 | "pause", |
hualing chen | 6d24aa9 | 2020-03-23 18:43:47 +0800 | [diff] [blame] | 95 | "ff", |
| 96 | "fb" |
| 97 | }; |
| 98 | |
| 99 | if (stat > DVR_PLAYBACK_STATE_FB) { |
| 100 | return "unkown"; |
| 101 | } else { |
| 102 | return string[stat]; |
| 103 | } |
| 104 | } |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 105 | |
| 106 | static DVR_Bool_t _dvr_support_speed(int speed) { |
| 107 | |
| 108 | DVR_Bool_t ret = DVR_FALSE; |
| 109 | |
| 110 | switch (speed) { |
hualing chen | e41f437 | 2020-06-06 16:29:17 +0800 | [diff] [blame] | 111 | case PLAYBACK_SPEED_FBX1: |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 112 | case PLAYBACK_SPEED_FBX2: |
| 113 | case PLAYBACK_SPEED_FBX4: |
| 114 | case PLAYBACK_SPEED_FBX8: |
hualing chen | 041c409 | 2020-04-05 15:11:50 +0800 | [diff] [blame] | 115 | case PLAYBACK_SPEED_FBX16: |
| 116 | case PLAYBACK_SPEED_FBX12: |
| 117 | case PLAYBACK_SPEED_FBX32: |
| 118 | case PLAYBACK_SPEED_FBX48: |
| 119 | case PLAYBACK_SPEED_FBX64: |
| 120 | case PLAYBACK_SPEED_FBX128: |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 121 | case PLAYBACK_SPEED_S2: |
| 122 | case PLAYBACK_SPEED_S4: |
| 123 | case PLAYBACK_SPEED_S8: |
| 124 | case PLAYBACK_SPEED_X1: |
| 125 | case PLAYBACK_SPEED_X2: |
| 126 | case PLAYBACK_SPEED_X4: |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 127 | case PLAYBACK_SPEED_X3: |
| 128 | case PLAYBACK_SPEED_X5: |
| 129 | case PLAYBACK_SPEED_X6: |
| 130 | case PLAYBACK_SPEED_X7: |
hualing chen | 041c409 | 2020-04-05 15:11:50 +0800 | [diff] [blame] | 131 | case PLAYBACK_SPEED_X8: |
| 132 | case PLAYBACK_SPEED_X12: |
| 133 | case PLAYBACK_SPEED_X16: |
| 134 | case PLAYBACK_SPEED_X32: |
| 135 | case PLAYBACK_SPEED_X48: |
| 136 | case PLAYBACK_SPEED_X64: |
| 137 | case PLAYBACK_SPEED_X128: |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 138 | ret = DVR_TRUE; |
| 139 | break; |
| 140 | default: |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 141 | DVR_PB_DG(1, "not support speed is set [%d]", speed); |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 142 | break; |
| 143 | } |
| 144 | return ret; |
| 145 | } |
hualing chen | 6e4bfa5 | 2020-03-13 14:37:11 +0800 | [diff] [blame] | 146 | void _dvr_tsplayer_callback_test(void *user_data, am_tsplayer_event *event) |
| 147 | { |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 148 | DVR_PB_DG(1, "in callback test "); |
hualing chen | 6e4bfa5 | 2020-03-13 14:37:11 +0800 | [diff] [blame] | 149 | DVR_Playback_t *player = NULL; |
| 150 | if (user_data != NULL) { |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 151 | player = (DVR_Playback_t *) user_data; |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 152 | DVR_PB_DG(1, "play speed [%f] in callback test ", player->speed); |
hualing chen | 6e4bfa5 | 2020-03-13 14:37:11 +0800 | [diff] [blame] | 153 | } |
| 154 | switch (event->type) { |
| 155 | case AM_TSPLAYER_EVENT_TYPE_VIDEO_CHANGED: |
| 156 | { |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 157 | DVR_PB_DG(1,"[evt] test AM_TSPLAYER_EVENT_TYPE_VIDEO_CHANGED: %d x %d @%d\n", |
hualing chen | 6e4bfa5 | 2020-03-13 14:37:11 +0800 | [diff] [blame] | 158 | event->event.video_format.frame_width, |
| 159 | event->event.video_format.frame_height, |
| 160 | event->event.video_format.frame_rate); |
| 161 | break; |
| 162 | } |
hualing chen | 6e4bfa5 | 2020-03-13 14:37:11 +0800 | [diff] [blame] | 163 | case AM_TSPLAYER_EVENT_TYPE_FIRST_FRAME: |
| 164 | { |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 165 | DVR_PB_DG(1, "[evt] test AM_TSPLAYER_EVENT_TYPE_FIRST_FRAME\n"); |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 166 | player->first_frame = 1; |
hualing chen | 6e4bfa5 | 2020-03-13 14:37:11 +0800 | [diff] [blame] | 167 | break; |
| 168 | } |
| 169 | default: |
| 170 | break; |
| 171 | } |
| 172 | } |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 173 | void _dvr_tsplayer_callback(void *user_data, am_tsplayer_event *event) |
| 174 | { |
hualing chen | 6e4bfa5 | 2020-03-13 14:37:11 +0800 | [diff] [blame] | 175 | DVR_Playback_t *player = NULL; |
| 176 | if (user_data != NULL) { |
| 177 | player = (DVR_Playback_t *) user_data; |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 178 | DVR_PB_DG(1, "play speed [%f] in-- callback", player->speed); |
hualing chen | 6e4bfa5 | 2020-03-13 14:37:11 +0800 | [diff] [blame] | 179 | } |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 180 | switch (event->type) { |
hualing chen | 6e4bfa5 | 2020-03-13 14:37:11 +0800 | [diff] [blame] | 181 | case AM_TSPLAYER_EVENT_TYPE_VIDEO_CHANGED: |
| 182 | { |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 183 | DVR_PB_DG(1,"[evt] AM_TSPLAYER_EVENT_TYPE_VIDEO_CHANGED: %d x %d @%d\n", |
hualing chen | 6e4bfa5 | 2020-03-13 14:37:11 +0800 | [diff] [blame] | 184 | event->event.video_format.frame_width, |
| 185 | event->event.video_format.frame_height, |
| 186 | event->event.video_format.frame_rate); |
| 187 | break; |
| 188 | } |
hualing chen | 6e4bfa5 | 2020-03-13 14:37:11 +0800 | [diff] [blame] | 189 | case AM_TSPLAYER_EVENT_TYPE_FIRST_FRAME: |
| 190 | { |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 191 | DVR_PB_DG(1, "[evt] AM_TSPLAYER_EVENT_TYPE_FIRST_FRAME\n"); |
hualing chen | e41f437 | 2020-06-06 16:29:17 +0800 | [diff] [blame] | 192 | if (player->first_trans_ok == DVR_FALSE) { |
| 193 | player->first_trans_ok = DVR_TRUE; |
| 194 | _dvr_playback_sent_transition_ok((DVR_PlaybackHandle_t)player, DVR_FALSE); |
| 195 | } |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 196 | if (player != NULL) |
| 197 | player->first_frame = 1; |
hualing chen | 6e4bfa5 | 2020-03-13 14:37:11 +0800 | [diff] [blame] | 198 | break; |
| 199 | } |
hualing chen | 487ae6d | 2020-07-22 10:34:11 +0800 | [diff] [blame] | 200 | case AM_TSPLAYER_EVENT_TYPE_DECODE_FIRST_FRAME_AUDIO: |
| 201 | if (player->first_trans_ok == DVR_FALSE && player->has_video == DVR_FALSE) { |
| 202 | player->first_trans_ok = DVR_TRUE; |
| 203 | _dvr_playback_sent_transition_ok((DVR_PlaybackHandle_t)player, DVR_FALSE); |
| 204 | } |
| 205 | if (player != NULL && player->has_video == DVR_FALSE) { |
| 206 | DVR_PB_DG(1, "[evt]AM_TSPLAYER_EVENT_TYPE_DECODE_FIRST_FRAME_AUDIO [%d]\n", event->type); |
| 207 | player->first_frame = 1; |
| 208 | } |
| 209 | break; |
hualing chen | 6e4bfa5 | 2020-03-13 14:37:11 +0800 | [diff] [blame] | 210 | default: |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 211 | DVR_PB_DG(1, "[evt]unkown event [%d]\n", event->type); |
hualing chen | 6e4bfa5 | 2020-03-13 14:37:11 +0800 | [diff] [blame] | 212 | break; |
| 213 | } |
| 214 | if (player&&player->player_callback_func) { |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 215 | DVR_PB_DG(1, "player is nonull, --call callback\n"); |
hualing chen | 6e4bfa5 | 2020-03-13 14:37:11 +0800 | [diff] [blame] | 216 | player->player_callback_func(player->player_callback_userdata, event); |
| 217 | } else if (player == NULL){ |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 218 | DVR_PB_DG(1, "player is null, get userdata error\n"); |
hualing chen | 6e4bfa5 | 2020-03-13 14:37:11 +0800 | [diff] [blame] | 219 | } else { |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 220 | DVR_PB_DG(1, "player callback is null, get callback error\n"); |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 221 | } |
| 222 | } |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame] | 223 | |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 224 | //convert video and audio fmt |
| 225 | static int _dvr_convert_stream_fmt(int fmt, DVR_Bool_t is_audio) { |
| 226 | int format = 0; |
| 227 | if (is_audio == DVR_FALSE) { |
| 228 | //for video fmt |
| 229 | switch (fmt) |
| 230 | { |
| 231 | case DVR_VIDEO_FORMAT_MPEG1: |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 232 | format = AV_VIDEO_CODEC_MPEG1; |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 233 | break; |
| 234 | case DVR_VIDEO_FORMAT_MPEG2: |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 235 | format = AV_VIDEO_CODEC_MPEG2; |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 236 | break; |
| 237 | case DVR_VIDEO_FORMAT_HEVC: |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 238 | format = AV_VIDEO_CODEC_H265; |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 239 | break; |
| 240 | case DVR_VIDEO_FORMAT_H264: |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 241 | format = AV_VIDEO_CODEC_H264; |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 242 | break; |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 243 | case DVR_VIDEO_FORMAT_VP9: |
| 244 | format = AV_VIDEO_CODEC_VP9; |
| 245 | break; |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 246 | } |
| 247 | } else { |
| 248 | //for audio fmt |
| 249 | switch (fmt) |
| 250 | { |
| 251 | case DVR_AUDIO_FORMAT_MPEG: |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 252 | format = AV_AUDIO_CODEC_MP2; |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 253 | break; |
| 254 | case DVR_AUDIO_FORMAT_AC3: |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 255 | format = AV_AUDIO_CODEC_AC3; |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 256 | break; |
| 257 | case DVR_AUDIO_FORMAT_EAC3: |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 258 | format = AV_AUDIO_CODEC_EAC3; |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 259 | break; |
| 260 | case DVR_AUDIO_FORMAT_DTS: |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 261 | format = AV_AUDIO_CODEC_DTS; |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 262 | break; |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 263 | case DVR_AUDIO_FORMAT_AAC: |
| 264 | format = AV_AUDIO_CODEC_AAC; |
| 265 | break; |
| 266 | case DVR_AUDIO_FORMAT_LATM: |
| 267 | format = AV_AUDIO_CODEC_LATM; |
| 268 | break; |
| 269 | case DVR_AUDIO_FORMAT_PCM: |
| 270 | format = AV_AUDIO_CODEC_PCM; |
| 271 | break; |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 272 | } |
| 273 | } |
| 274 | return format; |
| 275 | } |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 276 | static int _dvr_playback_get_trick_stat(DVR_PlaybackHandle_t handle) |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 277 | { |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 278 | DVR_Playback_t *player = (DVR_Playback_t *) handle; |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 279 | |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 280 | if (player == NULL || player->handle == NULL) |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 281 | return -1; |
| 282 | |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 283 | return player->first_frame; |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 284 | } |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 285 | |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 286 | //get sys time ms |
| 287 | static int _dvr_time_getClock(void) |
| 288 | { |
| 289 | struct timespec ts; |
| 290 | int ms; |
| 291 | |
| 292 | clock_gettime(CLOCK_MONOTONIC, &ts); |
| 293 | ms = ts.tv_sec*1000+ts.tv_nsec/1000000; |
| 294 | |
| 295 | return ms; |
| 296 | } |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 297 | |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 298 | |
| 299 | //timeout wait sibnal |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 300 | static int _dvr_playback_timeoutwait(DVR_PlaybackHandle_t handle , int ms) |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 301 | { |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 302 | DVR_Playback_t *player = (DVR_Playback_t *) handle; |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 303 | |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 304 | |
| 305 | if (player == NULL) { |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 306 | DVR_PB_DG(1, "player is NULL"); |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 307 | return DVR_FAILURE; |
| 308 | } |
| 309 | |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 310 | struct timespec ts; |
| 311 | clock_gettime(CLOCK_MONOTONIC, &ts); |
| 312 | //ms为毫秒,换算成秒 |
| 313 | ts.tv_sec += ms/1000; |
| 314 | //在outtime的基础上,增加ms毫秒 |
| 315 | //outtime.tv_nsec为纳秒,1微秒=1000纳秒 |
| 316 | //tv_nsec此值再加上剩余的毫秒数 ms%1000,有可能超过1秒。需要特殊处理 |
| 317 | uint64_t us = ts.tv_nsec/1000 + 1000 * (ms % 1000); //微秒 |
| 318 | //us的值有可能超过1秒, |
| 319 | ts.tv_sec += us / 1000000; |
| 320 | us = us % 1000000; |
| 321 | ts.tv_nsec = us * 1000;//换算成纳秒 |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 322 | pthread_cond_timedwait(&player->cond, &player->lock, &ts); |
| 323 | return 0; |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 324 | } |
hualing chen | 3114087 | 2020-03-25 12:29:26 +0800 | [diff] [blame] | 325 | //get tsplay delay time ms |
| 326 | static int _dvr_playback_get_delaytime(DVR_PlaybackHandle_t handle ) { |
| 327 | DVR_Playback_t *player = (DVR_Playback_t *) handle; |
| 328 | int64_t cache = 0; |
| 329 | if (player == NULL || player->handle == NULL) { |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 330 | DVR_PB_DG(1, "tsplayer delay time error, handle is NULL"); |
hualing chen | 3114087 | 2020-03-25 12:29:26 +0800 | [diff] [blame] | 331 | return 0; |
| 332 | } |
| 333 | AmTsPlayer_getDelayTime(player->handle, &cache); |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 334 | DVR_PB_DG(1, "tsplayer cache time [%lld]ms", cache); |
hualing chen | 3114087 | 2020-03-25 12:29:26 +0800 | [diff] [blame] | 335 | return cache; |
| 336 | } |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 337 | //send signal |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 338 | static int _dvr_playback_sendSignal(DVR_PlaybackHandle_t handle) |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 339 | { |
hualing chen | 87072a8 | 2020-03-12 16:20:12 +0800 | [diff] [blame] | 340 | DVR_Playback_t *player = (DVR_Playback_t *) handle;\ |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 341 | |
| 342 | if (player == NULL) { |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 343 | DVR_PB_DG(1, "player is NULL"); |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 344 | return DVR_FAILURE; |
| 345 | } |
| 346 | |
hualing chen | 87072a8 | 2020-03-12 16:20:12 +0800 | [diff] [blame] | 347 | pthread_mutex_lock(&player->lock); |
hualing chen | 87072a8 | 2020-03-12 16:20:12 +0800 | [diff] [blame] | 348 | pthread_cond_signal(&player->cond); |
hualing chen | 87072a8 | 2020-03-12 16:20:12 +0800 | [diff] [blame] | 349 | pthread_mutex_unlock(&player->lock); |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 350 | return 0; |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 351 | } |
| 352 | |
hualing chen | 2932d37 | 2020-04-29 13:44:00 +0800 | [diff] [blame] | 353 | //send playback event, need check is need lock first |
| 354 | static int _dvr_playback_sent_event(DVR_PlaybackHandle_t handle, DVR_PlaybackEvent_t evt, DVR_Play_Notify_t *notify, DVR_Bool_t is_lock) { |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame] | 355 | |
| 356 | DVR_Playback_t *player = (DVR_Playback_t *) handle; |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 357 | |
| 358 | if (player == NULL) { |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 359 | DVR_PB_DG(1, "player is NULL"); |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 360 | return DVR_FAILURE; |
| 361 | } |
| 362 | |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame] | 363 | switch (evt) { |
| 364 | case DVR_PLAYBACK_EVENT_ERROR: |
hualing chen | 2932d37 | 2020-04-29 13:44:00 +0800 | [diff] [blame] | 365 | _dvr_playback_get_status(handle, &(notify->play_status), is_lock); |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame] | 366 | break; |
| 367 | case DVR_PLAYBACK_EVENT_TRANSITION_OK: |
| 368 | //GET STATE |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 369 | DVR_PB_DG(1, "trans ok EVENT"); |
hualing chen | 2932d37 | 2020-04-29 13:44:00 +0800 | [diff] [blame] | 370 | _dvr_playback_get_status(handle, &(notify->play_status), is_lock); |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame] | 371 | break; |
| 372 | case DVR_PLAYBACK_EVENT_TRANSITION_FAILED: |
| 373 | break; |
| 374 | case DVR_PLAYBACK_EVENT_KEY_FAILURE: |
| 375 | break; |
| 376 | case DVR_PLAYBACK_EVENT_NO_KEY: |
| 377 | break; |
| 378 | case DVR_PLAYBACK_EVENT_REACHED_BEGIN: |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 379 | //GET STATE |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 380 | DVR_PB_DG(1, "reached begin EVENT"); |
hualing chen | 2932d37 | 2020-04-29 13:44:00 +0800 | [diff] [blame] | 381 | _dvr_playback_get_status(handle, &(notify->play_status), is_lock); |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame] | 382 | break; |
| 383 | case DVR_PLAYBACK_EVENT_REACHED_END: |
| 384 | //GET STATE |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 385 | DVR_PB_DG(1, "reached end EVENT"); |
hualing chen | 2932d37 | 2020-04-29 13:44:00 +0800 | [diff] [blame] | 386 | _dvr_playback_get_status(handle, &(notify->play_status), is_lock); |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame] | 387 | break; |
hualing chen | 6e4bfa5 | 2020-03-13 14:37:11 +0800 | [diff] [blame] | 388 | case DVR_PLAYBACK_EVENT_NOTIFY_PLAYTIME: |
hualing chen | 2932d37 | 2020-04-29 13:44:00 +0800 | [diff] [blame] | 389 | _dvr_playback_get_status(handle, &(notify->play_status), is_lock); |
hualing chen | 6e4bfa5 | 2020-03-13 14:37:11 +0800 | [diff] [blame] | 390 | break; |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame] | 391 | default: |
| 392 | break; |
| 393 | } |
| 394 | if (player->openParams.event_fn != NULL) |
| 395 | player->openParams.event_fn(evt, (void*)notify, player->openParams.event_userdata); |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame] | 396 | return DVR_SUCCESS; |
| 397 | } |
hualing chen | 2932d37 | 2020-04-29 13:44:00 +0800 | [diff] [blame] | 398 | static int _dvr_playback_sent_transition_ok(DVR_PlaybackHandle_t handle, DVR_Bool_t is_lock) |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame] | 399 | { |
| 400 | DVR_Play_Notify_t notify; |
| 401 | memset(¬ify, 0 , sizeof(DVR_Play_Notify_t)); |
| 402 | notify.event = DVR_PLAYBACK_EVENT_TRANSITION_OK; |
| 403 | //get play statue not here |
hualing chen | 2932d37 | 2020-04-29 13:44:00 +0800 | [diff] [blame] | 404 | _dvr_playback_sent_event(handle, DVR_PLAYBACK_EVENT_TRANSITION_OK, ¬ify, is_lock); |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame] | 405 | return DVR_SUCCESS; |
| 406 | } |
| 407 | |
hualing chen | 2932d37 | 2020-04-29 13:44:00 +0800 | [diff] [blame] | 408 | static int _dvr_playback_sent_playtime(DVR_PlaybackHandle_t handle, DVR_Bool_t is_lock) |
hualing chen | 6e4bfa5 | 2020-03-13 14:37:11 +0800 | [diff] [blame] | 409 | { |
| 410 | DVR_Playback_t *player = (DVR_Playback_t *) handle; |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 411 | |
hualing chen | e3797f0 | 2021-01-13 14:53:28 +0800 | [diff] [blame] | 412 | if (player->openParams.is_notify_time == DVR_FALSE) { |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 413 | return DVR_SUCCESS; |
| 414 | } |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 415 | if (player == NULL) { |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 416 | DVR_PB_DG(1, "player is NULL"); |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 417 | return DVR_FAILURE; |
| 418 | } |
| 419 | |
hualing chen | 6e4bfa5 | 2020-03-13 14:37:11 +0800 | [diff] [blame] | 420 | if (player->send_time ==0) { |
hualing chen | 0888c03 | 2020-12-18 17:54:57 +0800 | [diff] [blame] | 421 | player->send_time = _dvr_time_getClock() + 500; |
| 422 | } else if (player->send_time >= _dvr_time_getClock()) { |
hualing chen | 6e4bfa5 | 2020-03-13 14:37:11 +0800 | [diff] [blame] | 423 | return DVR_SUCCESS; |
| 424 | } |
hualing chen | 0888c03 | 2020-12-18 17:54:57 +0800 | [diff] [blame] | 425 | player->send_time = _dvr_time_getClock() + 500; |
hualing chen | 6e4bfa5 | 2020-03-13 14:37:11 +0800 | [diff] [blame] | 426 | DVR_Play_Notify_t notify; |
| 427 | memset(¬ify, 0 , sizeof(DVR_Play_Notify_t)); |
| 428 | notify.event = DVR_PLAYBACK_EVENT_NOTIFY_PLAYTIME; |
| 429 | //get play statue not here |
hualing chen | 2932d37 | 2020-04-29 13:44:00 +0800 | [diff] [blame] | 430 | _dvr_playback_sent_event(handle, DVR_PLAYBACK_EVENT_NOTIFY_PLAYTIME, ¬ify, is_lock); |
hualing chen | 6e4bfa5 | 2020-03-13 14:37:11 +0800 | [diff] [blame] | 431 | return DVR_SUCCESS; |
| 432 | } |
| 433 | |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame] | 434 | //check is ongoing segment |
| 435 | static int _dvr_check_segment_ongoing(DVR_PlaybackHandle_t handle) { |
| 436 | |
| 437 | DVR_Playback_t *player = (DVR_Playback_t *) handle; |
hualing chen | 87072a8 | 2020-03-12 16:20:12 +0800 | [diff] [blame] | 438 | int ret = DVR_FAILURE; |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 439 | |
| 440 | if (player == NULL) { |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 441 | DVR_PB_DG(1, "player is NULL"); |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 442 | return DVR_FAILURE; |
| 443 | } |
hualing chen | 87072a8 | 2020-03-12 16:20:12 +0800 | [diff] [blame] | 444 | ret = segment_ongoing(player->r_handle); |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame] | 445 | if (ret != DVR_SUCCESS) { |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame] | 446 | return DVR_FALSE; |
| 447 | } |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame] | 448 | return DVR_TRUE; |
| 449 | } |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 450 | |
| 451 | |
| 452 | static int _dvr_init_fffb_t(DVR_PlaybackHandle_t handle) { |
| 453 | DVR_Playback_t *player = (DVR_Playback_t *) handle; |
| 454 | player->fffb_start = _dvr_time_getClock(); |
| 455 | DVR_PB_DG(1, " player->fffb_start:%d", player->fffb_start); |
| 456 | player->fffb_current = player->fffb_start; |
| 457 | //get segment current time pos |
| 458 | player->fffb_start_pcr = _dvr_get_cur_time(handle); |
| 459 | //player->fffb_current = -1; |
| 460 | //player->fffb_start = -1; |
| 461 | //player->fffb_start_pcr = -1; |
| 462 | player->next_fffb_time = _dvr_time_getClock(); |
| 463 | |
| 464 | return DVR_SUCCESS; |
| 465 | } |
| 466 | |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 467 | static int _dvr_init_fffb_time(DVR_PlaybackHandle_t handle) { |
| 468 | DVR_Playback_t *player = (DVR_Playback_t *) handle; |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 469 | player->fffb_start = _dvr_time_getClock(); |
| 470 | DVR_PB_DG(1, " player->fffb_start:%d", player->fffb_start); |
| 471 | player->fffb_current = player->fffb_start; |
| 472 | //get segment current time pos |
| 473 | player->fffb_start_pcr = _dvr_get_cur_time(handle); |
| 474 | //player->fffb_current = -1; |
| 475 | //player->fffb_start = -1; |
| 476 | //player->fffb_start_pcr = -1; |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 477 | player->next_fffb_time = _dvr_time_getClock(); |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 478 | player->last_send_time_id = UINT64_MAX; |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 479 | return DVR_SUCCESS; |
| 480 | } |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame] | 481 | //get next segment id |
hualing chen | 87072a8 | 2020-03-12 16:20:12 +0800 | [diff] [blame] | 482 | static int _dvr_has_next_segmentId(DVR_PlaybackHandle_t handle, int segmentid) { |
| 483 | |
| 484 | DVR_Playback_t *player = (DVR_Playback_t *) handle; |
| 485 | DVR_PlaybackSegmentInfo_t *segment; |
| 486 | DVR_PlaybackSegmentInfo_t *pre_segment = NULL; |
| 487 | |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 488 | if (player == NULL) { |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 489 | DVR_PB_DG(1, " player is NULL"); |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 490 | return DVR_FAILURE; |
| 491 | } |
| 492 | |
hualing chen | 87072a8 | 2020-03-12 16:20:12 +0800 | [diff] [blame] | 493 | int found = 0; |
| 494 | int found_eq_id = 0; |
| 495 | list_for_each_entry(segment, &player->segment_list, head) |
| 496 | { |
| 497 | if (player->segment_is_open == DVR_FALSE) { |
| 498 | //get first segment from list, case segment is not open |
| 499 | if (!IS_FB(player->speed)) |
| 500 | found = 1; |
| 501 | } else if (segment->segment_id == segmentid) { |
| 502 | //find cur segment, we need get next one |
| 503 | found_eq_id = 1; |
| 504 | if (!IS_FB(player->speed)) { |
| 505 | found = 1; |
| 506 | continue; |
| 507 | } else { |
| 508 | //if is fb mode.we need used pre segment |
| 509 | if (pre_segment != NULL) { |
| 510 | found = 1; |
| 511 | } else { |
| 512 | //not find next id. |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 513 | DVR_PB_DG(1, "not has find next segment on fb mode"); |
hualing chen | 87072a8 | 2020-03-12 16:20:12 +0800 | [diff] [blame] | 514 | return DVR_FAILURE; |
| 515 | } |
| 516 | } |
| 517 | } |
| 518 | if (found == 1) { |
| 519 | found = 2; |
| 520 | break; |
| 521 | } |
hualing chen | c7aa4c8 | 2021-02-03 15:41:37 +0800 | [diff] [blame] | 522 | pre_segment = segment; |
hualing chen | 87072a8 | 2020-03-12 16:20:12 +0800 | [diff] [blame] | 523 | } |
| 524 | if (found != 2) { |
| 525 | //list is null or reache list end |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 526 | DVR_PB_DG(1, "not found next segment return failure"); |
hualing chen | 87072a8 | 2020-03-12 16:20:12 +0800 | [diff] [blame] | 527 | return DVR_FAILURE; |
| 528 | } |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 529 | DVR_PB_DG(1, "found next segment return success"); |
hualing chen | 87072a8 | 2020-03-12 16:20:12 +0800 | [diff] [blame] | 530 | return DVR_SUCCESS; |
| 531 | } |
| 532 | |
| 533 | //get next segment id |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 534 | static int _dvr_get_next_segmentId(DVR_PlaybackHandle_t handle) { |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 535 | |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 536 | DVR_Playback_t *player = (DVR_Playback_t *) handle; |
| 537 | DVR_PlaybackSegmentInfo_t *segment; |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 538 | DVR_PlaybackSegmentInfo_t *pre_segment = NULL; |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 539 | |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 540 | if (player == NULL) { |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 541 | DVR_PB_DG(1, "player is NULL"); |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 542 | return DVR_FAILURE; |
| 543 | } |
| 544 | |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 545 | int found = 0; |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 546 | int found_eq_id = 0; |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 547 | |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 548 | list_for_each_entry(segment, &player->segment_list, head) |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 549 | { |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame] | 550 | if (player->segment_is_open == DVR_FALSE) { |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 551 | //get first segment from list, case segment is not open |
| 552 | if (!IS_FB(player->speed)) |
| 553 | found = 1; |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 554 | } else if (segment->segment_id == player->cur_segment_id) { |
| 555 | //find cur segment, we need get next one |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 556 | found_eq_id = 1; |
| 557 | if (!IS_FB(player->speed)) { |
| 558 | found = 1; |
| 559 | continue; |
| 560 | } else { |
| 561 | //if is fb mode.we need used pre segment |
| 562 | if (pre_segment != NULL) { |
| 563 | found = 1; |
| 564 | } else { |
| 565 | //not find next id. |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 566 | DVR_PB_DG(1, "not find next segment on fb mode"); |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 567 | return DVR_FAILURE; |
| 568 | } |
| 569 | } |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 570 | } |
| 571 | if (found == 1) { |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 572 | if (IS_FB(player->speed)) { |
| 573 | //used pre segment |
| 574 | segment = pre_segment; |
| 575 | } |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame] | 576 | //save segment info |
| 577 | player->last_segment_id = player->cur_segment_id; |
hualing chen | 87072a8 | 2020-03-12 16:20:12 +0800 | [diff] [blame] | 578 | player->last_segment.segment_id = player->cur_segment.segment_id; |
| 579 | player->last_segment.flags = player->cur_segment.flags; |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame] | 580 | memcpy(player->last_segment.location, player->cur_segment.location, DVR_MAX_LOCATION_SIZE); |
| 581 | //pids |
| 582 | memcpy(&player->last_segment.pids, &player->cur_segment.pids, sizeof(DVR_PlaybackPids_t)); |
| 583 | |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 584 | //get segment info |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame] | 585 | player->segment_is_open = DVR_TRUE; |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 586 | player->cur_segment_id = segment->segment_id; |
| 587 | player->cur_segment.segment_id = segment->segment_id; |
| 588 | player->cur_segment.flags = segment->flags; |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 589 | DVR_PB_DG(1, "set cur id cur flag[0x%x]segment->flags flag[0x%x] id [%lld]", player->cur_segment.flags, segment->flags, segment->segment_id); |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 590 | memcpy(player->cur_segment.location, segment->location, DVR_MAX_LOCATION_SIZE); |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 591 | //pids |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 592 | memcpy(&player->cur_segment.pids, &segment->pids, sizeof(DVR_PlaybackPids_t)); |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 593 | found = 2; |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 594 | break; |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 595 | } |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 596 | pre_segment = segment; |
| 597 | } |
| 598 | if (player->segment_is_open == DVR_FALSE && IS_FB(player->speed)) { |
| 599 | //used the last one segment to open |
| 600 | //get segment info |
| 601 | player->segment_is_open = DVR_TRUE; |
| 602 | player->cur_segment_id = pre_segment->segment_id; |
| 603 | player->cur_segment.segment_id = pre_segment->segment_id; |
| 604 | player->cur_segment.flags = pre_segment->flags; |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 605 | DVR_PB_DG(1, "set cur id fb last one cur flag[0x%x]segment->flags flag[0x%x] id [%lld]", player->cur_segment.flags, pre_segment->flags, pre_segment->segment_id); |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 606 | memcpy(player->cur_segment.location, pre_segment->location, DVR_MAX_LOCATION_SIZE); |
| 607 | //pids |
| 608 | memcpy(&player->cur_segment.pids, &pre_segment->pids, sizeof(DVR_PlaybackPids_t)); |
| 609 | return DVR_SUCCESS; |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 610 | } |
| 611 | if (found != 2) { |
| 612 | //list is null or reache list end |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 613 | return DVR_FAILURE; |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 614 | } |
| 615 | return DVR_SUCCESS; |
| 616 | } |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 617 | //open next segment to play,if reach list end return errro. |
| 618 | static int _change_to_next_segment(DVR_PlaybackHandle_t handle) |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 619 | { |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 620 | DVR_Playback_t *player = (DVR_Playback_t *) handle; |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 621 | Segment_OpenParams_t params; |
| 622 | int ret = DVR_SUCCESS; |
| 623 | |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 624 | if (player == NULL) { |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 625 | DVR_PB_DG(1, "player is NULL"); |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 626 | return DVR_FAILURE; |
| 627 | } |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 628 | pthread_mutex_lock(&player->segment_lock); |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 629 | |
| 630 | ret = _dvr_get_next_segmentId(handle); |
| 631 | if (ret == DVR_FAILURE) { |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 632 | DVR_PB_DG(1, "not found segment info"); |
| 633 | pthread_mutex_unlock(&player->segment_lock); |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 634 | return DVR_FAILURE; |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 635 | } |
| 636 | |
| 637 | if (player->r_handle != NULL) { |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 638 | DVR_PB_DG(1, "close segment"); |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 639 | segment_close(player->r_handle); |
| 640 | player->r_handle = NULL; |
| 641 | } |
| 642 | |
| 643 | memset(params.location, 0, DVR_MAX_LOCATION_SIZE); |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 644 | //cp chur segment path to location |
| 645 | memcpy(params.location, player->cur_segment.location, DVR_MAX_LOCATION_SIZE); |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 646 | params.segment_id = (uint64_t)player->cur_segment.segment_id; |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 647 | params.mode = SEGMENT_MODE_READ; |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 648 | DVR_PB_DG(1, "open segment location[%s]id[%lld]flag[0x%x]", params.location, params.segment_id, player->cur_segment.flags); |
| 649 | |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 650 | ret = segment_open(¶ms, &(player->r_handle)); |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 651 | if (ret == DVR_FAILURE) { |
| 652 | DVR_PB_DG(1, "open segment error"); |
| 653 | } |
hualing chen | 87072a8 | 2020-03-12 16:20:12 +0800 | [diff] [blame] | 654 | pthread_mutex_unlock(&player->segment_lock); |
| 655 | int total = _dvr_get_end_time( handle); |
| 656 | pthread_mutex_lock(&player->segment_lock); |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 657 | if (IS_FB(player->speed)) { |
| 658 | //seek end pos -FB_DEFAULT_LEFT_TIME |
hualing chen | 5605eed | 2020-05-26 18:18:06 +0800 | [diff] [blame] | 659 | player->ts_cache_len = 0; |
hualing chen | 266b950 | 2020-04-04 17:39:39 +0800 | [diff] [blame] | 660 | segment_seek(player->r_handle, total - FB_DEFAULT_LEFT_TIME, player->openParams.block_size); |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 661 | DVR_PB_DG(1, "seek pos [%d]", total - FB_DEFAULT_LEFT_TIME); |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 662 | } |
hualing chen | 87072a8 | 2020-03-12 16:20:12 +0800 | [diff] [blame] | 663 | player->dur = total; |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 664 | pthread_mutex_unlock(&player->segment_lock); |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 665 | DVR_PB_DG(1, "next segment dur [%d] flag [0x%x]", player->dur, player->cur_segment.flags); |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 666 | return ret; |
| 667 | } |
| 668 | |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 669 | //open next segment to play,if reach list end return errro. |
| 670 | static int _dvr_open_segment(DVR_PlaybackHandle_t handle, uint64_t segment_id) |
| 671 | { |
| 672 | DVR_Playback_t *player = (DVR_Playback_t *) handle; |
| 673 | Segment_OpenParams_t params; |
| 674 | int ret = DVR_SUCCESS; |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 675 | if (player == NULL) { |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 676 | DVR_PB_DG(1, "player is NULL"); |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 677 | return DVR_FAILURE; |
| 678 | } |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame] | 679 | if (segment_id == player->cur_segment_id && player->segment_is_open == DVR_TRUE) { |
hualing chen | 87072a8 | 2020-03-12 16:20:12 +0800 | [diff] [blame] | 680 | return DVR_SUCCESS; |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 681 | } |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame] | 682 | uint64_t id = segment_id; |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 683 | if (id < 0) { |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 684 | DVR_PB_DG(1, "not found segment info"); |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 685 | return DVR_FAILURE; |
| 686 | } |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 687 | DVR_PB_DG(1, "start found segment[%lld]info", id); |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 688 | pthread_mutex_lock(&player->segment_lock); |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 689 | |
| 690 | DVR_PlaybackSegmentInfo_t *segment; |
| 691 | |
| 692 | int found = 0; |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame] | 693 | |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 694 | list_for_each_entry(segment, &player->segment_list, head) |
| 695 | { |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 696 | DVR_PB_DG(1, "see 1 location [%s]id[%lld]flag[%x]segment_id[%lld]", segment->location, segment->segment_id, segment->flags, segment_id); |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 697 | if (segment->segment_id == segment_id) { |
| 698 | found = 1; |
| 699 | } |
| 700 | if (found == 1) { |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 701 | DVR_PB_DG(1, "found [%s]id[%lld]flag[%x]segment_id[%lld]", segment->location, segment->segment_id, segment->flags, segment_id); |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 702 | //get segment info |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame] | 703 | player->segment_is_open = DVR_TRUE; |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 704 | player->cur_segment_id = segment->segment_id; |
| 705 | player->cur_segment.segment_id = segment->segment_id; |
| 706 | player->cur_segment.flags = segment->flags; |
hualing chen | 3114087 | 2020-03-25 12:29:26 +0800 | [diff] [blame] | 707 | strncpy(player->cur_segment.location, segment->location, sizeof(segment->location));//DVR_MAX_LOCATION_SIZE |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 708 | //pids |
| 709 | memcpy(&player->cur_segment.pids, &segment->pids, sizeof(DVR_PlaybackPids_t)); |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 710 | DVR_PB_DG(1, "cur found location [%s]id[%lld]flag[%x]", player->cur_segment.location, player->cur_segment.segment_id,player->cur_segment.flags); |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame] | 711 | break; |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 712 | } |
| 713 | } |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame] | 714 | if (found == 0) { |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 715 | DVR_PB_DG(1, "not found segment info.error.."); |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 716 | pthread_mutex_unlock(&player->segment_lock); |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame] | 717 | return DVR_FAILURE; |
| 718 | } |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 719 | memset(params.location, 0, DVR_MAX_LOCATION_SIZE); |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame] | 720 | //cp cur segment path to location |
hualing chen | 3114087 | 2020-03-25 12:29:26 +0800 | [diff] [blame] | 721 | strncpy(params.location, player->cur_segment.location, sizeof(player->cur_segment.location)); |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 722 | params.segment_id = (uint64_t)player->cur_segment.segment_id; |
| 723 | params.mode = SEGMENT_MODE_READ; |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 724 | DVR_PB_DG(1, "open segment location[%s][%lld]cur flag[0x%x]", params.location, params.segment_id, player->cur_segment.flags); |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 725 | if (player->r_handle != NULL) { |
| 726 | segment_close(player->r_handle); |
| 727 | player->r_handle = NULL; |
| 728 | } |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 729 | ret = segment_open(¶ms, &(player->r_handle)); |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 730 | if (ret == DVR_FAILURE) { |
| 731 | DVR_PB_DG(1, "segment opne error"); |
| 732 | } |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 733 | pthread_mutex_unlock(&player->segment_lock); |
hualing chen | 87072a8 | 2020-03-12 16:20:12 +0800 | [diff] [blame] | 734 | player->dur = _dvr_get_end_time(handle); |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame] | 735 | |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 736 | DVR_PB_DG(1, "player->dur [%d]cur id [%lld]cur flag [0x%x]\r\n", player->dur,player->cur_segment.segment_id, player->cur_segment.flags); |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 737 | return ret; |
| 738 | } |
| 739 | |
| 740 | |
| 741 | //get play info by segment id |
| 742 | static int _dvr_playback_get_playinfo(DVR_PlaybackHandle_t handle, |
| 743 | uint64_t segment_id, |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 744 | am_tsplayer_video_params *vparam, |
hualing chen | df118dd | 2020-05-21 15:49:11 +0800 | [diff] [blame] | 745 | am_tsplayer_audio_params *aparam, am_tsplayer_audio_params *adparam) { |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 746 | |
| 747 | DVR_Playback_t *player = (DVR_Playback_t *) handle; |
| 748 | DVR_PlaybackSegmentInfo_t *segment; |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 749 | if (player == NULL) { |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 750 | DVR_PB_DG(1, "player is NULL"); |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 751 | return DVR_FAILURE; |
| 752 | } |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 753 | |
| 754 | int found = 0; |
| 755 | |
| 756 | list_for_each_entry(segment, &player->segment_list, head) |
| 757 | { |
hualing chen | 87072a8 | 2020-03-12 16:20:12 +0800 | [diff] [blame] | 758 | if (segment_id == UINT64_MAX) { |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 759 | //get first segment from list |
| 760 | found = 1; |
| 761 | } |
| 762 | if (segment->segment_id == segment_id) { |
| 763 | found = 1; |
| 764 | } |
| 765 | if (found == 1) { |
| 766 | //get segment info |
hualing chen | 87072a8 | 2020-03-12 16:20:12 +0800 | [diff] [blame] | 767 | if (player->cur_segment_id != UINT64_MAX) |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 768 | player->cur_segment_id = segment->segment_id; |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 769 | DVR_PB_DG(1, "get play info id [%lld]", player->cur_segment_id); |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 770 | player->cur_segment.segment_id = segment->segment_id; |
| 771 | player->cur_segment.flags = segment->flags; |
| 772 | //pids |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 773 | player->cur_segment.pids.video.pid = segment->pids.video.pid; |
| 774 | player->cur_segment.pids.video.format = segment->pids.video.format; |
| 775 | player->cur_segment.pids.video.type = segment->pids.video.type; |
| 776 | player->cur_segment.pids.audio.pid = segment->pids.audio.pid; |
| 777 | player->cur_segment.pids.audio.format = segment->pids.audio.format; |
| 778 | player->cur_segment.pids.audio.type = segment->pids.audio.type; |
| 779 | player->cur_segment.pids.ad.pid = segment->pids.ad.pid; |
| 780 | player->cur_segment.pids.ad.format = segment->pids.ad.format; |
| 781 | player->cur_segment.pids.ad.type = segment->pids.ad.type; |
| 782 | player->cur_segment.pids.pcr.pid = segment->pids.pcr.pid; |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 783 | // |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 784 | vparam->codectype = _dvr_convert_stream_fmt(segment->pids.video.format, DVR_FALSE); |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 785 | vparam->pid = segment->pids.video.pid; |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 786 | aparam->codectype = _dvr_convert_stream_fmt(segment->pids.audio.format, DVR_TRUE); |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 787 | aparam->pid = segment->pids.audio.pid; |
hualing chen | df118dd | 2020-05-21 15:49:11 +0800 | [diff] [blame] | 788 | adparam->codectype =_dvr_convert_stream_fmt(segment->pids.ad.format, DVR_TRUE); |
| 789 | adparam->pid =segment->pids.ad.pid; |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 790 | DVR_PB_DG(1, "get play info sucess[0x%x]apid[0x%x]vfmt[%d]afmt[%d]", vparam->pid, aparam->pid, vparam->codectype, aparam->codectype); |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 791 | found = 2; |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame] | 792 | break; |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 793 | } |
| 794 | } |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame] | 795 | if (found != 2) { |
| 796 | //list is null or reache list end |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 797 | DVR_PB_DG(1, "get play info fail"); |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame] | 798 | return DVR_FAILURE; |
| 799 | } |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 800 | |
| 801 | return DVR_SUCCESS; |
| 802 | } |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame] | 803 | static int _dvr_replay_changed_pid(DVR_PlaybackHandle_t handle) { |
| 804 | DVR_Playback_t *player = (DVR_Playback_t *) handle; |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 805 | if (player == NULL) { |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 806 | DVR_PB_DG(1, "player is NULL"); |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 807 | return DVR_FAILURE; |
| 808 | } |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 809 | |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame] | 810 | //compare cur segment |
| 811 | //if (player->cmd.state == DVR_PLAYBACK_STATE_START) |
| 812 | { |
| 813 | //check video pids, stop or restart |
| 814 | _do_check_pid_info(handle, player->last_segment.pids.video, player->cur_segment.pids.video, 0); |
| 815 | //check audio pids stop or restart |
| 816 | _do_check_pid_info(handle, player->last_segment.pids.audio, player->cur_segment.pids.audio, 1); |
| 817 | //check sub audio pids stop or restart |
| 818 | _do_check_pid_info(handle, player->last_segment.pids.ad, player->cur_segment.pids.ad, 2); |
hualing chen | e3797f0 | 2021-01-13 14:53:28 +0800 | [diff] [blame] | 819 | DVR_PB_DG(1, ":last apid: %d set apid: %d", player->last_segment.pids.audio.pid,player->cur_segment.pids.audio.pid); |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame] | 820 | //check pcr pids stop or restart |
| 821 | _do_check_pid_info(handle, player->last_segment.pids.pcr, player->cur_segment.pids.pcr, 3); |
| 822 | } |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 823 | return DVR_SUCCESS; |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame] | 824 | } |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 825 | |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame] | 826 | static int _dvr_check_cur_segment_flag(DVR_PlaybackHandle_t handle) |
| 827 | { |
| 828 | DVR_Playback_t *player = (DVR_Playback_t *) handle; |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 829 | if (player == NULL) { |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 830 | DVR_PB_DG(1, "player is NULL"); |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 831 | return DVR_FAILURE; |
| 832 | } |
hualing chen | f43b8ba | 2020-07-28 13:11:42 +0800 | [diff] [blame] | 833 | if (player->vendor == DVR_PLAYBACK_VENDOR_AML) { |
| 834 | DVR_PB_DG(1, "vendor is amlogic. no used segment flag to hide or show av"); |
| 835 | return DVR_SUCCESS; |
| 836 | } |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 837 | DVR_PB_DG(1, "flag[0x%x]id[%lld]last[0x%x][%llu]", player->cur_segment.flags, player->cur_segment.segment_id, player->last_segment.flags, player->last_segment.segment_id); |
hualing chen | 87072a8 | 2020-03-12 16:20:12 +0800 | [diff] [blame] | 838 | if ((player->cur_segment.flags & DVR_PLAYBACK_SEGMENT_DISPLAYABLE) == DVR_PLAYBACK_SEGMENT_DISPLAYABLE && |
| 839 | (player->last_segment.flags & DVR_PLAYBACK_SEGMENT_DISPLAYABLE) == 0) { |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame] | 840 | //enable display |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 841 | DVR_PB_DG(1, "unmute"); |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 842 | AmTsPlayer_showVideo(player->handle); |
| 843 | AmTsPlayer_setAudioMute(player->handle, 0, 0); |
hualing chen | 87072a8 | 2020-03-12 16:20:12 +0800 | [diff] [blame] | 844 | } else if ((player->cur_segment.flags & DVR_PLAYBACK_SEGMENT_DISPLAYABLE) == 0 && |
| 845 | (player->last_segment.flags & DVR_PLAYBACK_SEGMENT_DISPLAYABLE) == DVR_PLAYBACK_SEGMENT_DISPLAYABLE) { |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 846 | //disable display |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 847 | DVR_PB_DG(1, "mute"); |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 848 | AmTsPlayer_hideVideo(player->handle); |
| 849 | AmTsPlayer_setAudioMute(player->handle, 1, 1); |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame] | 850 | } |
| 851 | return DVR_SUCCESS; |
| 852 | } |
hualing chen | e3797f0 | 2021-01-13 14:53:28 +0800 | [diff] [blame] | 853 | /* |
| 854 | if decodec sucess first time. |
| 855 | sucess: return true |
| 856 | fail: return false |
| 857 | */ |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 858 | static DVR_Bool_t _dvr_pauselive_decode_sucess(DVR_PlaybackHandle_t handle) { |
| 859 | DVR_Playback_t *player = (DVR_Playback_t *) handle; |
| 860 | if (player == NULL) { |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 861 | DVR_PB_DG(1, "player is NULL"); |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 862 | return DVR_TRUE; |
| 863 | } |
hualing chen | e3797f0 | 2021-01-13 14:53:28 +0800 | [diff] [blame] | 864 | if (player->first_frame == 1) { |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 865 | return DVR_TRUE; |
hualing chen | e3797f0 | 2021-01-13 14:53:28 +0800 | [diff] [blame] | 866 | } else { |
| 867 | return DVR_FALSE; |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 868 | } |
| 869 | } |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 870 | static void* _dvr_playback_thread(void *arg) |
| 871 | { |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 872 | DVR_Playback_t *player = (DVR_Playback_t *) arg; |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame] | 873 | //int need_open_segment = 1; |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 874 | am_tsplayer_input_buffer wbufs; |
pengfei.liu | 07ddc8a | 2020-03-24 23:36:53 +0800 | [diff] [blame] | 875 | am_tsplayer_input_buffer dec_bufs; |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 876 | int ret = DVR_SUCCESS; |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 877 | |
hualing chen | 3962821 | 2020-05-14 10:35:13 +0800 | [diff] [blame] | 878 | #define MAX_REACHEND_TIMEOUT (3000) |
| 879 | int reach_end_timeout = 0;//ms |
| 880 | int cache_time = 0; |
hualing chen | 6d24aa9 | 2020-03-23 18:43:47 +0800 | [diff] [blame] | 881 | int timeout = 300;//ms |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 882 | uint64_t write_timeout_ms = 50; |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 883 | uint8_t *buf = NULL; |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 884 | int buf_len = player->openParams.block_size > 0 ? player->openParams.block_size : (256 * 1024); |
hualing chen | 266b950 | 2020-04-04 17:39:39 +0800 | [diff] [blame] | 885 | DVR_Bool_t b_writed_whole_block = player->openParams.block_size > 0 ? DVR_TRUE:DVR_FALSE; |
| 886 | |
pengfei.liu | 07ddc8a | 2020-03-24 23:36:53 +0800 | [diff] [blame] | 887 | int dec_buf_size = buf_len + 188; |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 888 | int real_read = 0; |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 889 | DVR_Bool_t goto_rewrite = DVR_FALSE; |
hualing chen | e41f437 | 2020-06-06 16:29:17 +0800 | [diff] [blame] | 890 | int retry_open_seg = 0; |
pengfei.liu | 07ddc8a | 2020-03-24 23:36:53 +0800 | [diff] [blame] | 891 | if (player->is_secure_mode) { |
| 892 | if (dec_buf_size > player->secure_buffer_size) { |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 893 | DVR_PB_DG(1, "playback blocksize too large"); |
pengfei.liu | 07ddc8a | 2020-03-24 23:36:53 +0800 | [diff] [blame] | 894 | return NULL; |
| 895 | } |
| 896 | } |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 897 | buf = malloc(buf_len); |
pengfei.liu | 07ddc8a | 2020-03-24 23:36:53 +0800 | [diff] [blame] | 898 | if (!buf) { |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 899 | DVR_PB_DG(1, "Malloc buffer failed"); |
pengfei.liu | 07ddc8a | 2020-03-24 23:36:53 +0800 | [diff] [blame] | 900 | return NULL; |
| 901 | } |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 902 | wbufs.buf_type = TS_INPUT_BUFFER_TYPE_NORMAL; |
| 903 | wbufs.buf_size = 0; |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame] | 904 | |
pengfei.liu | 07ddc8a | 2020-03-24 23:36:53 +0800 | [diff] [blame] | 905 | dec_bufs.buf_data = malloc(dec_buf_size); |
| 906 | if (!dec_bufs.buf_data) { |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 907 | DVR_PB_DG(1, "Malloc dec buffer failed"); |
Pengfei Liu | faf38e4 | 2020-05-22 00:28:02 +0800 | [diff] [blame] | 908 | free(buf); |
pengfei.liu | 07ddc8a | 2020-03-24 23:36:53 +0800 | [diff] [blame] | 909 | return NULL; |
| 910 | } |
| 911 | dec_bufs.buf_type = TS_INPUT_BUFFER_TYPE_NORMAL; |
| 912 | dec_bufs.buf_size = dec_buf_size; |
| 913 | |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame] | 914 | if (player->segment_is_open == DVR_FALSE) { |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 915 | ret = _change_to_next_segment((DVR_PlaybackHandle_t)player); |
| 916 | } |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 917 | |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 918 | if (ret != DVR_SUCCESS) { |
| 919 | if (buf != NULL) { |
| 920 | free(buf); |
| 921 | buf = NULL; |
| 922 | } |
pengfei.liu | 07ddc8a | 2020-03-24 23:36:53 +0800 | [diff] [blame] | 923 | free(dec_bufs.buf_data); |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 924 | DVR_PB_DG(1, "get segment error"); |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 925 | return NULL; |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 926 | } |
hualing chen | 4fe3bee | 2020-10-23 13:58:52 +0800 | [diff] [blame] | 927 | DVR_PB_DG(1, "player->vendor %d,player->has_video[%d] bufsize[0x%x]whole block[%d]", |
| 928 | player->vendor, player->has_video, buf_len, b_writed_whole_block); |
hualing chen | fbf8e02 | 2020-06-15 13:43:11 +0800 | [diff] [blame] | 929 | //get play statue not here,send ok event when vendor is aml or only audio channel if not send ok event |
| 930 | if (((player->first_trans_ok == DVR_FALSE) && (player->vendor == DVR_PLAYBACK_VENDOR_AML) ) || |
| 931 | (player->first_trans_ok == DVR_FALSE && player->has_video == DVR_FALSE)) { |
| 932 | player->first_trans_ok = DVR_TRUE; |
| 933 | _dvr_playback_sent_transition_ok((DVR_PlaybackHandle_t)player, DVR_TRUE); |
| 934 | } |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame] | 935 | _dvr_check_cur_segment_flag((DVR_PlaybackHandle_t)player); |
hualing chen | 6d24aa9 | 2020-03-23 18:43:47 +0800 | [diff] [blame] | 936 | //set video show |
| 937 | AmTsPlayer_showVideo(player->handle); |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 938 | |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 939 | int trick_stat = 0; |
| 940 | while (player->is_running/* || player->cmd.last_cmd != player->cmd.cur_cmd*/) { |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 941 | |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 942 | //check trick stat |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame] | 943 | pthread_mutex_lock(&player->lock); |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 944 | |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 945 | if (player->cmd.cur_cmd == DVR_PLAYBACK_CMD_SEEK || |
| 946 | player->cmd.cur_cmd == DVR_PLAYBACK_CMD_FF || |
hualing chen | 3114087 | 2020-03-25 12:29:26 +0800 | [diff] [blame] | 947 | player->cmd.cur_cmd == DVR_PLAYBACK_CMD_FB || |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 948 | player->speed > FF_SPEED ||player->speed <= FB_SPEED || |
hualing chen | 3962821 | 2020-05-14 10:35:13 +0800 | [diff] [blame] | 949 | (player->state == DVR_PLAYBACK_STATE_PAUSE) || |
hualing chen | 3114087 | 2020-03-25 12:29:26 +0800 | [diff] [blame] | 950 | (player->play_flag&DVR_PLAYBACK_STARTED_PAUSEDLIVE) == DVR_PLAYBACK_STARTED_PAUSEDLIVE) |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 951 | { |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 952 | trick_stat = _dvr_playback_get_trick_stat((DVR_PlaybackHandle_t)player); |
| 953 | if (trick_stat > 0) { |
hualing chen | bcada02 | 2020-04-22 14:27:01 +0800 | [diff] [blame] | 954 | DVR_PB_DG(1, "trick stat[%d] is > 0 cur cmd[%d]last cmd[%d]flag[0x%x]", player->cmd.cur_cmd, player->cmd.last_cmd, player->play_flag); |
hualing chen | 87072a8 | 2020-03-12 16:20:12 +0800 | [diff] [blame] | 955 | if (player->cmd.cur_cmd == DVR_PLAYBACK_CMD_SEEK || (player->play_flag&DVR_PLAYBACK_STARTED_PAUSEDLIVE) == DVR_PLAYBACK_STARTED_PAUSEDLIVE) { |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 956 | //check last cmd |
hualing chen | bcada02 | 2020-04-22 14:27:01 +0800 | [diff] [blame] | 957 | if (player->cmd.last_cmd == DVR_PLAYBACK_CMD_PAUSE |
hualing chen | 3114087 | 2020-03-25 12:29:26 +0800 | [diff] [blame] | 958 | || ((player->play_flag&DVR_PLAYBACK_STARTED_PAUSEDLIVE) == DVR_PLAYBACK_STARTED_PAUSEDLIVE |
hualing chen | 87072a8 | 2020-03-12 16:20:12 +0800 | [diff] [blame] | 959 | && ( player->cmd.cur_cmd == DVR_PLAYBACK_CMD_START |
| 960 | ||player->cmd.last_cmd == DVR_PLAYBACK_CMD_VSTART |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 961 | || player->cmd.last_cmd == DVR_PLAYBACK_CMD_ASTART |
| 962 | || player->cmd.last_cmd == DVR_PLAYBACK_CMD_START))) { |
hualing chen | bcada02 | 2020-04-22 14:27:01 +0800 | [diff] [blame] | 963 | DVR_PB_DG(1, "pause play-------cur cmd[%d]last cmd[%d]flag[0x%x]", player->cmd.cur_cmd, player->cmd.last_cmd, player->play_flag); |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 964 | //need change to pause state |
| 965 | player->cmd.cur_cmd = DVR_PLAYBACK_CMD_PAUSE; |
| 966 | player->cmd.state = DVR_PLAYBACK_STATE_PAUSE; |
hualing chen | 3114087 | 2020-03-25 12:29:26 +0800 | [diff] [blame] | 967 | player->state = DVR_PLAYBACK_STATE_PAUSE; |
hualing chen | 87072a8 | 2020-03-12 16:20:12 +0800 | [diff] [blame] | 968 | //clear flag |
hualing chen | 3114087 | 2020-03-25 12:29:26 +0800 | [diff] [blame] | 969 | player->play_flag = player->play_flag & (~DVR_PLAYBACK_STARTED_PAUSEDLIVE); |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 970 | player->first_frame = 0; |
hualing chen | 10cdb16 | 2021-02-05 10:44:41 +0800 | [diff] [blame^] | 971 | AmTsPlayer_setTrickMode(player->handle, AV_VIDEO_TRICK_MODE_NONE); |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 972 | AmTsPlayer_pauseVideoDecoding(player->handle); |
| 973 | AmTsPlayer_pauseAudioDecoding(player->handle); |
hualing chen | 2bd8a7a | 2020-04-02 11:31:03 +0800 | [diff] [blame] | 974 | } else { |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 975 | DVR_PB_DG(1, "clear first frame value-------"); |
hualing chen | 2bd8a7a | 2020-04-02 11:31:03 +0800 | [diff] [blame] | 976 | player->first_frame = 0; |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 977 | } |
| 978 | } else if (player->cmd.cur_cmd == DVR_PLAYBACK_CMD_FF |
| 979 | || player->cmd.cur_cmd == DVR_PLAYBACK_CMD_FB |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 980 | ||player->speed > FF_SPEED ||player->speed < FB_SPEED) { |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 981 | //restart play stream if speed > 2 |
hualing chen | b5cd42e | 2020-04-15 17:03:34 +0800 | [diff] [blame] | 982 | if (player->state == DVR_PLAYBACK_STATE_PAUSE) { |
| 983 | DVR_PB_DG(1, "fffb pause state----speed[%f] fffb cur[%d] cur sys[%d] [%s] [%d]", player->speed, player->fffb_current,_dvr_time_getClock(),_dvr_playback_state_toString(player->state), player->next_fffb_time); |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 984 | //used timeout wait need lock first,so we unlock and lock |
| 985 | //pthread_mutex_unlock(&player->lock); |
| 986 | //pthread_mutex_lock(&player->lock); |
| 987 | _dvr_playback_timeoutwait((DVR_PlaybackHandle_t)player, timeout); |
| 988 | pthread_mutex_unlock(&player->lock); |
| 989 | continue; |
hualing chen | b5cd42e | 2020-04-15 17:03:34 +0800 | [diff] [blame] | 990 | } else if (_dvr_time_getClock() < player->next_fffb_time) { |
| 991 | DVR_PB_DG(1, "fffb timeout-to pause video---speed[%f] fffb cur[%d] cur sys[%d] [%s] [%d]", player->speed, player->fffb_current,_dvr_time_getClock(),_dvr_playback_state_toString(player->state), player->next_fffb_time); |
| 992 | //used timeout wait need lock first,so we unlock and lock |
| 993 | //pthread_mutex_unlock(&player->lock); |
| 994 | //pthread_mutex_lock(&player->lock); |
| 995 | AmTsPlayer_pauseVideoDecoding(player->handle); |
| 996 | _dvr_playback_timeoutwait((DVR_PlaybackHandle_t)player, timeout); |
| 997 | pthread_mutex_unlock(&player->lock); |
| 998 | continue; |
| 999 | |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 1000 | } |
hualing chen | 2932d37 | 2020-04-29 13:44:00 +0800 | [diff] [blame] | 1001 | DVR_PB_DG(1, "fffb play-------speed[%f][%d][%d][%s][%d]", player->speed, goto_rewrite, real_read, _dvr_playback_state_toString(player->state), player->cmd); |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 1002 | pthread_mutex_unlock(&player->lock); |
| 1003 | goto_rewrite = DVR_FALSE; |
hualing chen | 87072a8 | 2020-03-12 16:20:12 +0800 | [diff] [blame] | 1004 | real_read = 0; |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 1005 | player->play_flag = player->play_flag & (~DVR_PLAYBACK_STARTED_PAUSEDLIVE); |
| 1006 | player->first_frame = 0; |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 1007 | _dvr_playback_fffb((DVR_PlaybackHandle_t)player); |
hualing chen | bcada02 | 2020-04-22 14:27:01 +0800 | [diff] [blame] | 1008 | player->fffb_play = DVR_FALSE; |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 1009 | pthread_mutex_lock(&player->lock); |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1010 | } |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 1011 | }else if (player->fffb_play == DVR_TRUE){ |
| 1012 | //for first into fffb when reset speed |
| 1013 | if (player->state == DVR_PLAYBACK_STATE_PAUSE || |
| 1014 | _dvr_time_getClock() < player->next_fffb_time) { |
| 1015 | DVR_PB_DG(1, "fffb timeout-fffb play---speed[%f] fffb cur[%d] cur sys[%d] [%s] [%d]", player->speed, player->fffb_current,_dvr_time_getClock(),_dvr_playback_state_toString(player->state), player->next_fffb_time); |
| 1016 | //used timeout wait need lock first,so we unlock and lock |
| 1017 | //pthread_mutex_unlock(&player->lock); |
| 1018 | //pthread_mutex_lock(&player->lock); |
| 1019 | _dvr_playback_timeoutwait((DVR_PlaybackHandle_t)player, timeout); |
| 1020 | pthread_mutex_unlock(&player->lock); |
| 1021 | continue; |
| 1022 | } |
hualing chen | 2932d37 | 2020-04-29 13:44:00 +0800 | [diff] [blame] | 1023 | DVR_PB_DG(1, "fffb replay-------speed[%f][%d][%d][%s][%d]player->fffb_play[%d]", player->speed, goto_rewrite, real_read, _dvr_playback_state_toString(player->state), player->cmd, player->fffb_play); |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 1024 | pthread_mutex_unlock(&player->lock); |
| 1025 | goto_rewrite = DVR_FALSE; |
| 1026 | real_read = 0; |
hualing chen | 5605eed | 2020-05-26 18:18:06 +0800 | [diff] [blame] | 1027 | player->ts_cache_len = 0; |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 1028 | player->play_flag = player->play_flag & (~DVR_PLAYBACK_STARTED_PAUSEDLIVE); |
| 1029 | player->first_frame = 0; |
| 1030 | _dvr_playback_fffb((DVR_PlaybackHandle_t)player); |
| 1031 | pthread_mutex_lock(&player->lock); |
| 1032 | player->fffb_play = DVR_FALSE; |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 1033 | } |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 1034 | } |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1035 | |
hualing chen | 87072a8 | 2020-03-12 16:20:12 +0800 | [diff] [blame] | 1036 | if (player->state == DVR_PLAYBACK_STATE_PAUSE) { |
hualing chen | 6e4bfa5 | 2020-03-13 14:37:11 +0800 | [diff] [blame] | 1037 | //check is need send time send end |
hualing chen | c70a8df | 2020-05-12 19:23:11 +0800 | [diff] [blame] | 1038 | DVR_PB_DG(1, "pause, continue"); |
hualing chen | 2932d37 | 2020-04-29 13:44:00 +0800 | [diff] [blame] | 1039 | _dvr_playback_sent_playtime((DVR_PlaybackHandle_t)player, DVR_FALSE); |
hualing chen | 87072a8 | 2020-03-12 16:20:12 +0800 | [diff] [blame] | 1040 | _dvr_playback_timeoutwait((DVR_PlaybackHandle_t)player, timeout); |
| 1041 | pthread_mutex_unlock(&player->lock); |
| 1042 | continue; |
| 1043 | } |
hualing chen | 266b950 | 2020-04-04 17:39:39 +0800 | [diff] [blame] | 1044 | //when seek action is done. we need drop write timeout data. |
| 1045 | if (player->drop_ts == DVR_TRUE) { |
| 1046 | goto_rewrite = DVR_FALSE; |
| 1047 | real_read = 0; |
| 1048 | player->drop_ts = DVR_FALSE; |
| 1049 | } |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 1050 | if (goto_rewrite == DVR_TRUE) { |
| 1051 | goto_rewrite = DVR_FALSE; |
| 1052 | pthread_mutex_unlock(&player->lock); |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 1053 | //DVR_PB_DG(1, "rewrite-player->speed[%f]", player->speed); |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 1054 | goto rewrite; |
| 1055 | } |
hualing chen | 6e4bfa5 | 2020-03-13 14:37:11 +0800 | [diff] [blame] | 1056 | //.check is need send time send end |
hualing chen | 2932d37 | 2020-04-29 13:44:00 +0800 | [diff] [blame] | 1057 | _dvr_playback_sent_playtime((DVR_PlaybackHandle_t)player, DVR_FALSE); |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 1058 | pthread_mutex_lock(&player->segment_lock); |
hualing chen | e41f437 | 2020-06-06 16:29:17 +0800 | [diff] [blame] | 1059 | //DVR_PB_DG(1, "start read"); |
hualing chen | 87072a8 | 2020-03-12 16:20:12 +0800 | [diff] [blame] | 1060 | int read = segment_read(player->r_handle, buf + real_read, buf_len - real_read); |
hualing chen | fbf8e02 | 2020-06-15 13:43:11 +0800 | [diff] [blame] | 1061 | //DVR_PB_DG(1, "start read end [%d]", read); |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 1062 | pthread_mutex_unlock(&player->segment_lock); |
hualing chen | 87072a8 | 2020-03-12 16:20:12 +0800 | [diff] [blame] | 1063 | pthread_mutex_unlock(&player->lock); |
hualing chen | b5cd42e | 2020-04-15 17:03:34 +0800 | [diff] [blame] | 1064 | if (read < 0 && errno == EIO) { |
| 1065 | //EIO ERROR, EXIT THRAD |
| 1066 | DVR_PB_DG(1, "read error.EIO error, exit thread"); |
| 1067 | DVR_Play_Notify_t notify; |
| 1068 | memset(¬ify, 0 , sizeof(DVR_Play_Notify_t)); |
| 1069 | notify.event = DVR_PLAYBACK_EVENT_ERROR; |
hualing chen | 9b434f0 | 2020-06-10 15:06:54 +0800 | [diff] [blame] | 1070 | notify.info.error_reason = DVR_ERROR_REASON_READ; |
hualing chen | 2932d37 | 2020-04-29 13:44:00 +0800 | [diff] [blame] | 1071 | _dvr_playback_sent_event((DVR_PlaybackHandle_t)player,DVR_PLAYBACK_EVENT_ERROR, ¬ify, DVR_TRUE); |
hualing chen | b5cd42e | 2020-04-15 17:03:34 +0800 | [diff] [blame] | 1072 | goto end; |
| 1073 | } else if (read < 0) { |
| 1074 | DVR_PB_DG(1, "read error.:%d EIO:%d", errno, EIO); |
| 1075 | } |
hualing chen | 87072a8 | 2020-03-12 16:20:12 +0800 | [diff] [blame] | 1076 | //if on fb mode and read file end , we need calculate pos to retry read. |
| 1077 | if (read == 0 && IS_FB(player->speed) && real_read == 0) { |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 1078 | DVR_PB_DG(1, "recalculate read [%d] readed [%d]buf_len[%d]speed[%f]id=[%llu]", read,real_read, buf_len, player->speed,player->cur_segment_id); |
hualing chen | 87072a8 | 2020-03-12 16:20:12 +0800 | [diff] [blame] | 1079 | _dvr_playback_calculate_seekpos((DVR_PlaybackHandle_t)player); |
| 1080 | pthread_mutex_lock(&player->lock); |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 1081 | _dvr_playback_timeoutwait((DVR_PlaybackHandle_t)player, timeout); |
| 1082 | pthread_mutex_unlock(&player->lock); |
| 1083 | continue; |
| 1084 | } |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 1085 | //DVR_PB_DG(1, "read ts [%d]buf_len[%d]speed[%f]real_read:%d", read, buf_len, player->speed, real_read); |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1086 | if (read == 0) { |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 1087 | //file end.need to play next segment |
hualing chen | e41f437 | 2020-06-06 16:29:17 +0800 | [diff] [blame] | 1088 | #define MIN_CACHE_TIME (3000) |
| 1089 | int _cache_time = _dvr_playback_get_delaytime((DVR_PlaybackHandle_t)player) ; |
hualing chen | e3797f0 | 2021-01-13 14:53:28 +0800 | [diff] [blame] | 1090 | /*if cache time is > min cache time ,not read next segment,wait cache data to play*/ |
hualing chen | e41f437 | 2020-06-06 16:29:17 +0800 | [diff] [blame] | 1091 | if (_cache_time > MIN_CACHE_TIME) { |
hualing chen | e41f437 | 2020-06-06 16:29:17 +0800 | [diff] [blame] | 1092 | pthread_mutex_lock(&player->lock); |
hualing chen | e3797f0 | 2021-01-13 14:53:28 +0800 | [diff] [blame] | 1093 | /*if cache time > 20s , we think get time is error,*/ |
| 1094 | if (_cache_time - MIN_CACHE_TIME > 20 * 1000) { |
| 1095 | DVR_PB_DG(1, "read end but cache time is %d > 20s, this is an error at media_hal", _cache_time); |
| 1096 | DVR_PB_DG(1, "read end but cache time is %d > 20s, this is an error at media_hal", _cache_time); |
| 1097 | DVR_PB_DG(1, "read end but cache time is %d > 20s, this is an error at media_hal", _cache_time); |
| 1098 | } |
| 1099 | _dvr_playback_timeoutwait((DVR_PlaybackHandle_t)player, ((_cache_time - MIN_CACHE_TIME) > MIN_CACHE_TIME ? MIN_CACHE_TIME : (_cache_time - MIN_CACHE_TIME))); |
hualing chen | e41f437 | 2020-06-06 16:29:17 +0800 | [diff] [blame] | 1100 | pthread_mutex_unlock(&player->lock); |
hualing chen | e3797f0 | 2021-01-13 14:53:28 +0800 | [diff] [blame] | 1101 | DVR_PB_DG(1, "read end but cache time is %d > %d, to sleep end and continue", _cache_time, MIN_CACHE_TIME); |
hualing chen | e41f437 | 2020-06-06 16:29:17 +0800 | [diff] [blame] | 1102 | //continue; |
| 1103 | } |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 1104 | int ret = _change_to_next_segment((DVR_PlaybackHandle_t)player); |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 1105 | //init fffb time if change segment |
hualing chen | 041c409 | 2020-04-05 15:11:50 +0800 | [diff] [blame] | 1106 | _dvr_init_fffb_time((DVR_PlaybackHandle_t)player); |
hualing chen | 3114087 | 2020-03-25 12:29:26 +0800 | [diff] [blame] | 1107 | |
| 1108 | int delay = _dvr_playback_get_delaytime((DVR_PlaybackHandle_t)player); |
hualing chen | e3797f0 | 2021-01-13 14:53:28 +0800 | [diff] [blame] | 1109 | if (ret != DVR_SUCCESS) { |
| 1110 | player->noData++; |
| 1111 | DVR_PB_DG(1, "playback is sleep:[%d]ms nodata[%d]", timeout, player->noData); |
| 1112 | if (player->noData == 4) { |
| 1113 | DVR_PB_DG(1, "playback send nodata event nodata[%d]", player->noData); |
| 1114 | //send event here and pause |
| 1115 | DVR_Play_Notify_t notify; |
| 1116 | memset(¬ify, 0 , sizeof(DVR_Play_Notify_t)); |
| 1117 | notify.event = DVR_PLAYBACK_EVENT_NODATA; |
| 1118 | DVR_PB_DG(1, "send event DVR_PLAYBACK_EVENT_NODATA"); |
| 1119 | //get play statue not here |
| 1120 | _dvr_playback_sent_event((DVR_PlaybackHandle_t)player, DVR_PLAYBACK_EVENT_NODATA, ¬ify, DVR_FALSE); |
| 1121 | } |
| 1122 | } |
| 1123 | //send reached event |
hualing chen | 3962821 | 2020-05-14 10:35:13 +0800 | [diff] [blame] | 1124 | if ((ret != DVR_SUCCESS && |
hualing chen | 041c409 | 2020-04-05 15:11:50 +0800 | [diff] [blame] | 1125 | (delay <= MIN_TSPLAYER_DELAY_TIME || |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 1126 | player->cmd.cur_cmd == DVR_PLAYBACK_CMD_FF) && |
hualing chen | 3962821 | 2020-05-14 10:35:13 +0800 | [diff] [blame] | 1127 | _dvr_pauselive_decode_sucess((DVR_PlaybackHandle_t)player)) || |
| 1128 | (reach_end_timeout >= MAX_REACHEND_TIMEOUT )) { |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 1129 | //send end event to hal |
hualing chen | 3114087 | 2020-03-25 12:29:26 +0800 | [diff] [blame] | 1130 | DVR_Play_Notify_t notify; |
| 1131 | memset(¬ify, 0 , sizeof(DVR_Play_Notify_t)); |
| 1132 | notify.event = DVR_PLAYBACK_EVENT_REACHED_END; |
| 1133 | //get play statue not here |
| 1134 | dvr_playback_pause((DVR_PlaybackHandle_t)player, DVR_FALSE); |
hualing chen | 2932d37 | 2020-04-29 13:44:00 +0800 | [diff] [blame] | 1135 | _dvr_playback_sent_event((DVR_PlaybackHandle_t)player, DVR_PLAYBACK_EVENT_REACHED_END, ¬ify, DVR_TRUE); |
hualing chen | 3114087 | 2020-03-25 12:29:26 +0800 | [diff] [blame] | 1136 | //continue,timeshift mode, when read end,need wait cur recording segment |
hualing chen | 3962821 | 2020-05-14 10:35:13 +0800 | [diff] [blame] | 1137 | DVR_PB_DG(1, "playback is send end delay:[%d]reach_end_timeout[%d]ms", delay, reach_end_timeout); |
hualing chen | 3114087 | 2020-03-25 12:29:26 +0800 | [diff] [blame] | 1138 | pthread_mutex_lock(&player->lock); |
| 1139 | _dvr_playback_timeoutwait((DVR_PlaybackHandle_t)player, timeout); |
| 1140 | pthread_mutex_unlock(&player->lock); |
| 1141 | continue; |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 1142 | } else if (ret != DVR_SUCCESS) { |
| 1143 | //not send event and pause,sleep and go to next time to recheck |
hualing chen | 3962821 | 2020-05-14 10:35:13 +0800 | [diff] [blame] | 1144 | if (delay < cache_time) { |
| 1145 | //delay time is changed and then has data to play, so not start timeout |
| 1146 | } else { |
| 1147 | reach_end_timeout = reach_end_timeout + timeout; |
| 1148 | } |
| 1149 | cache_time = delay; |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 1150 | DVR_PB_DG(1, "delay:%d pauselive:%d", delay, _dvr_pauselive_decode_sucess((DVR_PlaybackHandle_t)player)); |
hualing chen | 3114087 | 2020-03-25 12:29:26 +0800 | [diff] [blame] | 1151 | pthread_mutex_lock(&player->lock); |
| 1152 | _dvr_playback_timeoutwait((DVR_PlaybackHandle_t)player, timeout); |
| 1153 | pthread_mutex_unlock(&player->lock); |
| 1154 | continue; |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1155 | } |
hualing chen | 3962821 | 2020-05-14 10:35:13 +0800 | [diff] [blame] | 1156 | reach_end_timeout = 0; |
| 1157 | cache_time = 0; |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame] | 1158 | pthread_mutex_lock(&player->lock); |
hualing chen | 2932d37 | 2020-04-29 13:44:00 +0800 | [diff] [blame] | 1159 | //change next segment success case |
| 1160 | _dvr_playback_sent_transition_ok((DVR_PlaybackHandle_t)player, DVR_FALSE); |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 1161 | DVR_PB_DG(1, "_dvr_replay_changed_pid:start"); |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame] | 1162 | _dvr_replay_changed_pid((DVR_PlaybackHandle_t)player); |
| 1163 | _dvr_check_cur_segment_flag((DVR_PlaybackHandle_t)player); |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1164 | read = segment_read(player->r_handle, buf + real_read, buf_len - real_read); |
hualing chen | 87072a8 | 2020-03-12 16:20:12 +0800 | [diff] [blame] | 1165 | pthread_mutex_unlock(&player->lock); |
hualing chen | e3797f0 | 2021-01-13 14:53:28 +0800 | [diff] [blame] | 1166 | }//read len 0 check end |
| 1167 | if (player->noData > 0) { |
| 1168 | player->noData = 0; |
| 1169 | DVR_PB_DG(1, "playback send data event resume[%d]", player->noData); |
| 1170 | //send event here and pause |
| 1171 | DVR_Play_Notify_t notify; |
| 1172 | memset(¬ify, 0 , sizeof(DVR_Play_Notify_t)); |
| 1173 | notify.event = DVR_PLAYBACK_EVENT_DATARESUME; |
| 1174 | DVR_PB_DG(1, "send event DVR_PLAYBACK_EVENT_DATARESUME"); |
| 1175 | //get play statue not here |
| 1176 | _dvr_playback_sent_event((DVR_PlaybackHandle_t)player, DVR_PLAYBACK_EVENT_DATARESUME, ¬ify, DVR_FALSE); |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1177 | } |
hualing chen | 3962821 | 2020-05-14 10:35:13 +0800 | [diff] [blame] | 1178 | reach_end_timeout = 0; |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1179 | real_read = real_read + read; |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 1180 | wbufs.buf_size = real_read; |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 1181 | wbufs.buf_data = buf; |
hualing chen | 5605eed | 2020-05-26 18:18:06 +0800 | [diff] [blame] | 1182 | |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 1183 | //check read data len,iflen < 0, we need continue |
hualing chen | 7a56cba | 2020-04-14 14:09:27 +0800 | [diff] [blame] | 1184 | if (wbufs.buf_size <= 0 || wbufs.buf_data == NULL) { |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 1185 | DVR_PB_DG(1, "error occur read_read [%d],buf=[%p]",wbufs.buf_size, wbufs.buf_data); |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 1186 | real_read = 0; |
hualing chen | 5605eed | 2020-05-26 18:18:06 +0800 | [diff] [blame] | 1187 | player->ts_cache_len = 0; |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 1188 | continue; |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 1189 | } |
hualing chen | 266b950 | 2020-04-04 17:39:39 +0800 | [diff] [blame] | 1190 | //if need write whole block size, we need check read buf len is eq block size. |
| 1191 | if (b_writed_whole_block == DVR_TRUE) { |
| 1192 | //buf_len is block size value. |
| 1193 | if (real_read < buf_len) { |
| 1194 | //coontinue to read data from file |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 1195 | DVR_PB_DG(1, "read buf len[%d] is < block size [%d]", real_read, buf_len); |
hualing chen | 266b950 | 2020-04-04 17:39:39 +0800 | [diff] [blame] | 1196 | pthread_mutex_lock(&player->lock); |
| 1197 | _dvr_playback_timeoutwait((DVR_PlaybackHandle_t)player, timeout); |
| 1198 | pthread_mutex_unlock(&player->lock); |
hualing chen | c70a8df | 2020-05-12 19:23:11 +0800 | [diff] [blame] | 1199 | DVR_PB_DG(1, "read buf len[%d] is < block size [%d] continue", real_read, buf_len); |
hualing chen | 266b950 | 2020-04-04 17:39:39 +0800 | [diff] [blame] | 1200 | continue; |
| 1201 | } else if (real_read > buf_len) { |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 1202 | DVR_PB_DG(1, "read buf len[%d] is > block size [%d],this error occur", real_read, buf_len); |
hualing chen | 266b950 | 2020-04-04 17:39:39 +0800 | [diff] [blame] | 1203 | } |
| 1204 | } |
| 1205 | |
pengfei.liu | 27cc4ec | 2020-04-03 16:28:16 +0800 | [diff] [blame] | 1206 | if (player->dec_func) { |
| 1207 | DVR_CryptoParams_t crypto_params; |
| 1208 | |
| 1209 | memset(&crypto_params, 0, sizeof(crypto_params)); |
| 1210 | crypto_params.type = DVR_CRYPTO_TYPE_DECRYPT; |
| 1211 | memcpy(crypto_params.location, player->cur_segment.location, strlen(player->cur_segment.location)); |
| 1212 | crypto_params.segment_id = player->cur_segment.segment_id; |
hualing chen | 1f26ffa | 2020-11-03 10:39:20 +0800 | [diff] [blame] | 1213 | crypto_params.offset = segment_tell_position(player->r_handle) - wbufs.buf_size; |
hualing chen | bafc62d | 2020-11-02 15:44:05 +0800 | [diff] [blame] | 1214 | if ((crypto_params.offset % (player->openParams.block_size)) != 0) |
| 1215 | DVR_PB_DG(1, "offset is not block_size %d", player->openParams.block_size); |
pengfei.liu | 27cc4ec | 2020-04-03 16:28:16 +0800 | [diff] [blame] | 1216 | crypto_params.input_buffer.type = DVR_BUFFER_TYPE_NORMAL; |
| 1217 | crypto_params.input_buffer.addr = (size_t)buf; |
| 1218 | crypto_params.input_buffer.size = real_read; |
| 1219 | |
| 1220 | if (player->is_secure_mode) { |
| 1221 | crypto_params.output_buffer.type = DVR_BUFFER_TYPE_SECURE; |
| 1222 | crypto_params.output_buffer.addr = (size_t)player->secure_buffer; |
| 1223 | crypto_params.output_buffer.size = dec_buf_size; |
| 1224 | ret = player->dec_func(&crypto_params, player->dec_userdata); |
| 1225 | wbufs.buf_data = player->secure_buffer; |
pengfei.liu | fda2a97 | 2020-04-09 14:47:15 +0800 | [diff] [blame] | 1226 | wbufs.buf_type = TS_INPUT_BUFFER_TYPE_SECURE; |
pengfei.liu | 27cc4ec | 2020-04-03 16:28:16 +0800 | [diff] [blame] | 1227 | } else { |
| 1228 | crypto_params.output_buffer.type = DVR_BUFFER_TYPE_NORMAL; |
| 1229 | crypto_params.output_buffer.addr = (size_t)dec_bufs.buf_data; |
| 1230 | crypto_params.output_buffer.size = dec_buf_size; |
| 1231 | ret = player->dec_func(&crypto_params, player->dec_userdata); |
| 1232 | wbufs.buf_data = dec_bufs.buf_data; |
pengfei.liu | fda2a97 | 2020-04-09 14:47:15 +0800 | [diff] [blame] | 1233 | wbufs.buf_type = TS_INPUT_BUFFER_TYPE_NORMAL; |
pengfei.liu | 27cc4ec | 2020-04-03 16:28:16 +0800 | [diff] [blame] | 1234 | } |
| 1235 | if (ret != DVR_SUCCESS) { |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 1236 | DVR_PB_DG(1, "decrypt failed"); |
pengfei.liu | 27cc4ec | 2020-04-03 16:28:16 +0800 | [diff] [blame] | 1237 | } |
pengfei.liu | fda2a97 | 2020-04-09 14:47:15 +0800 | [diff] [blame] | 1238 | wbufs.buf_size = crypto_params.output_size; |
pengfei.liu | 27cc4ec | 2020-04-03 16:28:16 +0800 | [diff] [blame] | 1239 | } |
pengfei.liu | 07ddc8a | 2020-03-24 23:36:53 +0800 | [diff] [blame] | 1240 | rewrite: |
hualing chen | bcada02 | 2020-04-22 14:27:01 +0800 | [diff] [blame] | 1241 | if (player->drop_ts == DVR_TRUE) { |
| 1242 | //need drop ts data when seek occur.we need read next loop,drop this ts data |
| 1243 | goto_rewrite = DVR_FALSE; |
| 1244 | real_read = 0; |
hualing chen | 5605eed | 2020-05-26 18:18:06 +0800 | [diff] [blame] | 1245 | player->ts_cache_len = 0; |
hualing chen | bcada02 | 2020-04-22 14:27:01 +0800 | [diff] [blame] | 1246 | player->drop_ts = DVR_FALSE; |
| 1247 | continue; |
| 1248 | } |
hualing chen | 5605eed | 2020-05-26 18:18:06 +0800 | [diff] [blame] | 1249 | player->ts_cache_len = real_read; |
pengfei.liu | 07ddc8a | 2020-03-24 23:36:53 +0800 | [diff] [blame] | 1250 | ret = AmTsPlayer_writeData(player->handle, &wbufs, write_timeout_ms); |
| 1251 | if (ret == AM_TSPLAYER_OK) { |
hualing chen | 5605eed | 2020-05-26 18:18:06 +0800 | [diff] [blame] | 1252 | player->ts_cache_len = 0; |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 1253 | real_read = 0; |
| 1254 | write_success++; |
hualing chen | 5605eed | 2020-05-26 18:18:06 +0800 | [diff] [blame] | 1255 | //DVR_PB_DG(1, "write write_success:%d wbufs.buf_size:%d", write_success, wbufs.buf_size); |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 1256 | continue; |
hualing chen | 87072a8 | 2020-03-12 16:20:12 +0800 | [diff] [blame] | 1257 | } else { |
hualing chen | 2932d37 | 2020-04-29 13:44:00 +0800 | [diff] [blame] | 1258 | DVR_PB_DG(1, "write time out write_success:%d wbufs.buf_size:%d", write_success, wbufs.buf_size); |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 1259 | write_success = 0; |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame] | 1260 | pthread_mutex_lock(&player->lock); |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 1261 | _dvr_playback_timeoutwait((DVR_PlaybackHandle_t)player, timeout); |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame] | 1262 | pthread_mutex_unlock(&player->lock); |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1263 | if (!player->is_running) { |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 1264 | DVR_PB_DG(1, "playback thread exit"); |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1265 | break; |
| 1266 | } |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 1267 | goto_rewrite = DVR_TRUE; |
| 1268 | //goto rewrite; |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1269 | } |
| 1270 | } |
hualing chen | b5cd42e | 2020-04-15 17:03:34 +0800 | [diff] [blame] | 1271 | end: |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 1272 | DVR_PB_DG(1, "playback thread is end"); |
pengfei.liu | 07ddc8a | 2020-03-24 23:36:53 +0800 | [diff] [blame] | 1273 | free(buf); |
| 1274 | free(dec_bufs.buf_data); |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1275 | return NULL; |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 1276 | } |
| 1277 | |
| 1278 | |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 1279 | static int _start_playback_thread(DVR_PlaybackHandle_t handle) |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 1280 | { |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 1281 | DVR_Playback_t *player = (DVR_Playback_t *) handle; |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 1282 | |
| 1283 | if (player == NULL) { |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 1284 | DVR_PB_DG(1, "player is NULL"); |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 1285 | return DVR_FAILURE; |
| 1286 | } |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 1287 | DVR_PB_DG(1, "start thread is_running:[%d]", player->is_running); |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame] | 1288 | if (player->is_running == DVR_TRUE) { |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 1289 | return 0; |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1290 | } |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 1291 | player->is_running = DVR_TRUE; |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1292 | int rc = pthread_create(&player->playback_thread, NULL, _dvr_playback_thread, (void*)player); |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 1293 | if (rc < 0) |
| 1294 | player->is_running = DVR_FALSE; |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1295 | return 0; |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 1296 | } |
| 1297 | |
| 1298 | |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 1299 | static int _stop_playback_thread(DVR_PlaybackHandle_t handle) |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1300 | { |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 1301 | DVR_Playback_t *player = (DVR_Playback_t *) handle; |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 1302 | |
| 1303 | if (player == NULL) { |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 1304 | DVR_PB_DG(1, "player is NULL"); |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 1305 | return DVR_FAILURE; |
| 1306 | } |
| 1307 | |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 1308 | DVR_PB_DG(1, "stopthread------[%d]", player->is_running); |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame] | 1309 | if (player->is_running == DVR_TRUE) |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1310 | { |
| 1311 | player->is_running = DVR_FALSE; |
hualing chen | 87072a8 | 2020-03-12 16:20:12 +0800 | [diff] [blame] | 1312 | _dvr_playback_sendSignal(handle); |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1313 | pthread_join(player->playback_thread, NULL); |
| 1314 | } |
| 1315 | if (player->r_handle) { |
| 1316 | segment_close(player->r_handle); |
| 1317 | player->r_handle = NULL; |
| 1318 | } |
hualing chen | 7a56cba | 2020-04-14 14:09:27 +0800 | [diff] [blame] | 1319 | DVR_PB_DG(1, ":end"); |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1320 | return 0; |
| 1321 | } |
| 1322 | |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 1323 | /**\brief Open an dvr palyback |
| 1324 | * \param[out] p_handle dvr playback addr |
| 1325 | * \param[in] params dvr playback open parameters |
| 1326 | * \retval DVR_SUCCESS On success |
| 1327 | * \return Error code |
| 1328 | */ |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 1329 | int dvr_playback_open(DVR_PlaybackHandle_t *p_handle, DVR_PlaybackOpenParams_t *params) { |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 1330 | |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 1331 | DVR_Playback_t *player; |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1332 | pthread_condattr_t cattr; |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 1333 | |
Zhiqiang Han | 2d8cd82 | 2020-03-16 13:58:10 +0800 | [diff] [blame] | 1334 | player = (DVR_Playback_t*)calloc(1, sizeof(DVR_Playback_t)); |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 1335 | |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1336 | pthread_mutex_init(&player->lock, NULL); |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 1337 | pthread_mutex_init(&player->segment_lock, NULL); |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1338 | pthread_condattr_init(&cattr); |
| 1339 | pthread_condattr_setclock(&cattr, CLOCK_MONOTONIC); |
| 1340 | pthread_cond_init(&player->cond, &cattr); |
| 1341 | pthread_condattr_destroy(&cattr); |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 1342 | |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 1343 | //init segment list head |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 1344 | INIT_LIST_HEAD(&player->segment_list); |
| 1345 | player->cmd.last_cmd = DVR_PLAYBACK_CMD_STOP; |
| 1346 | player->cmd.cur_cmd = DVR_PLAYBACK_CMD_STOP; |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 1347 | player->cmd.speed.speed.speed = PLAYBACK_SPEED_X1; |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 1348 | player->cmd.state = DVR_PLAYBACK_STATE_STOP; |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 1349 | player->state = DVR_PLAYBACK_STATE_STOP; |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1350 | player->cmd.pos = 0; |
hualing chen | 3114087 | 2020-03-25 12:29:26 +0800 | [diff] [blame] | 1351 | player->speed = 1.0f; |
hualing chen | e41f437 | 2020-06-06 16:29:17 +0800 | [diff] [blame] | 1352 | player->first_trans_ok = DVR_FALSE; |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 1353 | |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1354 | //store open params |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 1355 | player->openParams.dmx_dev_id = params->dmx_dev_id; |
| 1356 | player->openParams.block_size = params->block_size; |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1357 | player->openParams.is_timeshift = params->is_timeshift; |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame] | 1358 | player->openParams.event_fn = params->event_fn; |
| 1359 | player->openParams.event_userdata = params->event_userdata; |
hualing chen | e3797f0 | 2021-01-13 14:53:28 +0800 | [diff] [blame] | 1360 | player->openParams.is_notify_time = params->is_notify_time; |
hualing chen | fbf8e02 | 2020-06-15 13:43:11 +0800 | [diff] [blame] | 1361 | player->vendor = params->vendor; |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame] | 1362 | |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 1363 | player->has_pids = params->has_pids; |
| 1364 | |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 1365 | player->handle = params->player_handle ; |
hualing chen | 6e4bfa5 | 2020-03-13 14:37:11 +0800 | [diff] [blame] | 1366 | |
| 1367 | AmTsPlayer_getCb(player->handle, &player->player_callback_func, &player->player_callback_userdata); |
| 1368 | //for test get callback |
| 1369 | if (0 && player->player_callback_func == NULL) { |
| 1370 | AmTsPlayer_registerCb(player->handle, _dvr_tsplayer_callback_test, player); |
| 1371 | AmTsPlayer_getCb(player->handle, &player->player_callback_func, &player->player_callback_userdata); |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 1372 | DVR_PB_DG(1, "playback open get callback[%p][%p][%p][%p]",player->player_callback_func, player->player_callback_userdata, _dvr_tsplayer_callback_test,player); |
hualing chen | 6e4bfa5 | 2020-03-13 14:37:11 +0800 | [diff] [blame] | 1373 | } |
| 1374 | AmTsPlayer_registerCb(player->handle, _dvr_tsplayer_callback, player); |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 1375 | |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1376 | //init has audio and video |
| 1377 | player->has_video = DVR_FALSE; |
| 1378 | player->has_audio = DVR_FALSE; |
hualing chen | 87072a8 | 2020-03-12 16:20:12 +0800 | [diff] [blame] | 1379 | player->cur_segment_id = UINT64_MAX; |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame] | 1380 | player->last_segment_id = 0LL; |
| 1381 | player->segment_is_open = DVR_FALSE; |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 1382 | |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 1383 | //init ff fb time |
| 1384 | player->fffb_current = -1; |
| 1385 | player->fffb_start =-1; |
| 1386 | player->fffb_start_pcr = -1; |
| 1387 | //seek time |
| 1388 | player->seek_time = 0; |
hualing chen | 6e4bfa5 | 2020-03-13 14:37:11 +0800 | [diff] [blame] | 1389 | player->send_time = 0; |
pengfei.liu | 07ddc8a | 2020-03-24 23:36:53 +0800 | [diff] [blame] | 1390 | |
| 1391 | //init secure stuff |
| 1392 | player->dec_func = NULL; |
| 1393 | player->dec_userdata = NULL; |
| 1394 | player->is_secure_mode = 0; |
| 1395 | player->secure_buffer = NULL; |
| 1396 | player->secure_buffer_size = 0; |
hualing chen | 266b950 | 2020-04-04 17:39:39 +0800 | [diff] [blame] | 1397 | player->drop_ts = DVR_FALSE; |
pengfei.liu | 07ddc8a | 2020-03-24 23:36:53 +0800 | [diff] [blame] | 1398 | |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 1399 | player->fffb_play = DVR_FALSE; |
| 1400 | |
| 1401 | player->last_send_time_id = UINT64_MAX; |
| 1402 | player->last_cur_time = 0; |
| 1403 | |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1404 | *p_handle = player; |
| 1405 | return DVR_SUCCESS; |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 1406 | } |
| 1407 | |
| 1408 | /**\brief Close an dvr palyback |
| 1409 | * \param[in] handle playback handle |
| 1410 | * \retval DVR_SUCCESS On success |
| 1411 | * \return Error code |
| 1412 | */ |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 1413 | int dvr_playback_close(DVR_PlaybackHandle_t handle) { |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 1414 | |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1415 | DVR_ASSERT(handle); |
hualing chen | 7a56cba | 2020-04-14 14:09:27 +0800 | [diff] [blame] | 1416 | DVR_PB_DG(1, ":into"); |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 1417 | DVR_Playback_t *player = (DVR_Playback_t *) handle; |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 1418 | if (player == NULL) { |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 1419 | DVR_PB_DG(1, "player is NULL"); |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 1420 | return DVR_FAILURE; |
| 1421 | } |
| 1422 | |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame] | 1423 | if (player->state != DVR_PLAYBACK_STATE_STOP) |
| 1424 | { |
hualing chen | b96aa2c | 2020-04-15 14:13:53 +0800 | [diff] [blame] | 1425 | DVR_PB_DG(1, "player->state %s", _dvr_playback_state_toString(player->state)); |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame] | 1426 | dvr_playback_stop(handle, DVR_TRUE); |
hualing chen | b96aa2c | 2020-04-15 14:13:53 +0800 | [diff] [blame] | 1427 | DVR_PB_DG(1, "player->state %s", _dvr_playback_state_toString(player->state)); |
| 1428 | } else { |
| 1429 | DVR_PB_DG(1, ":is stoped state"); |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame] | 1430 | } |
hualing chen | 7a56cba | 2020-04-14 14:09:27 +0800 | [diff] [blame] | 1431 | DVR_PB_DG(1, ":into"); |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1432 | pthread_mutex_destroy(&player->lock); |
| 1433 | pthread_cond_destroy(&player->cond); |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 1434 | |
| 1435 | if (player) { |
| 1436 | free(player); |
| 1437 | player = NULL; |
| 1438 | } |
hualing chen | 7a56cba | 2020-04-14 14:09:27 +0800 | [diff] [blame] | 1439 | DVR_PB_DG(1, ":end"); |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1440 | return DVR_SUCCESS; |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 1441 | } |
| 1442 | |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 1443 | /**\brief Start play audio and video, used start auido api and start video api |
| 1444 | * \param[in] handle playback handle |
| 1445 | * \param[in] params audio playback params,contains fmt and pid... |
| 1446 | * \retval DVR_SUCCESS On success |
| 1447 | * \return Error code |
| 1448 | */ |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 1449 | int dvr_playback_start(DVR_PlaybackHandle_t handle, DVR_PlaybackFlag_t flag) { |
| 1450 | DVR_Playback_t *player = (DVR_Playback_t *) handle; |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 1451 | am_tsplayer_video_params vparams; |
| 1452 | am_tsplayer_audio_params aparams; |
hualing chen | df118dd | 2020-05-21 15:49:11 +0800 | [diff] [blame] | 1453 | am_tsplayer_audio_params adparams; |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 1454 | |
| 1455 | if (player == NULL) { |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 1456 | DVR_PB_DG(1, "player is NULL"); |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 1457 | return DVR_FAILURE; |
| 1458 | } |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame] | 1459 | uint64_t segment_id = player->cur_segment_id; |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 1460 | DVR_PB_DG(1, "[%p]segment_id:[%lld]", handle, segment_id); |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 1461 | |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 1462 | player->first_frame = 0; |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame] | 1463 | //can used start api to resume playback |
| 1464 | if (player->cmd.state == DVR_PLAYBACK_STATE_PAUSE) { |
| 1465 | return dvr_playback_resume(handle); |
| 1466 | } |
hualing chen | 87072a8 | 2020-03-12 16:20:12 +0800 | [diff] [blame] | 1467 | if (player->cmd.state == DVR_PLAYBACK_STATE_START) { |
hualing chen | 9b434f0 | 2020-06-10 15:06:54 +0800 | [diff] [blame] | 1468 | //if flag is puased and not decodec first frame. if user resume, we need |
| 1469 | //clear flag and set trickmode none |
| 1470 | if ((player->play_flag&DVR_PLAYBACK_STARTED_PAUSEDLIVE) == DVR_PLAYBACK_STARTED_PAUSEDLIVE) { |
| 1471 | DVR_PB_DG(1, "[%p]clear pause live flag and clear trick mode", handle); |
| 1472 | player->play_flag = player->play_flag & (~DVR_PLAYBACK_STARTED_PAUSEDLIVE); |
| 1473 | AmTsPlayer_setTrickMode(player->handle, AV_VIDEO_TRICK_MODE_NONE); |
| 1474 | } |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 1475 | DVR_PB_DG(1, "stat is start, not need into start play"); |
hualing chen | 87072a8 | 2020-03-12 16:20:12 +0800 | [diff] [blame] | 1476 | return DVR_SUCCESS; |
| 1477 | } |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1478 | player->play_flag = flag; |
hualing chen | e41f437 | 2020-06-06 16:29:17 +0800 | [diff] [blame] | 1479 | player->first_trans_ok = DVR_FALSE; |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 1480 | //get segment info and audio video pid fmt ; |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 1481 | DVR_PB_DG(1, "lock flag:0x%x", flag); |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1482 | pthread_mutex_lock(&player->lock); |
hualing chen | df118dd | 2020-05-21 15:49:11 +0800 | [diff] [blame] | 1483 | _dvr_playback_get_playinfo(handle, segment_id, &vparams, &aparams, &adparams); |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1484 | //start audio and video |
Zhiqiang Han | a9d261b | 2020-11-11 18:38:10 +0800 | [diff] [blame] | 1485 | if (vparams.pid != 0x2fff && !VALID_PID(vparams.pid) && !VALID_PID(aparams.pid)) { |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1486 | //audio abnd video pis is all invalid, return error. |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 1487 | DVR_PB_DG(0, "unlock dvr play back start error, not found audio and video info"); |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame] | 1488 | pthread_mutex_unlock(&player->lock); |
| 1489 | DVR_Play_Notify_t notify; |
| 1490 | memset(¬ify, 0 , sizeof(DVR_Play_Notify_t)); |
| 1491 | notify.event = DVR_PLAYBACK_EVENT_TRANSITION_FAILED; |
| 1492 | notify.info.error_reason = DVR_PLAYBACK_PID_ERROR; |
| 1493 | notify.info.transition_failed_data.segment_id = segment_id; |
| 1494 | //get play statue not here |
hualing chen | 2932d37 | 2020-04-29 13:44:00 +0800 | [diff] [blame] | 1495 | _dvr_playback_sent_event(handle, DVR_PLAYBACK_EVENT_TRANSITION_FAILED, ¬ify, DVR_TRUE); |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1496 | return -1; |
| 1497 | } |
hualing chen | 3114087 | 2020-03-25 12:29:26 +0800 | [diff] [blame] | 1498 | |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame] | 1499 | { |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1500 | if (VALID_PID(vparams.pid)) { |
| 1501 | player->has_video = DVR_TRUE; |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1502 | //if set flag is pause live, we need set trick mode |
hualing chen | 3114087 | 2020-03-25 12:29:26 +0800 | [diff] [blame] | 1503 | if ((player->play_flag&DVR_PLAYBACK_STARTED_PAUSEDLIVE) == DVR_PLAYBACK_STARTED_PAUSEDLIVE) { |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 1504 | DVR_PB_DG(1, "set trick mode -pauselive flag--"); |
hualing chen | 3114087 | 2020-03-25 12:29:26 +0800 | [diff] [blame] | 1505 | AmTsPlayer_setTrickMode(player->handle, AV_VIDEO_TRICK_MODE_PAUSE_NEXT); |
| 1506 | } else if (player->cmd.cur_cmd == DVR_PLAYBACK_CMD_FB |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 1507 | || player->cmd.cur_cmd == DVR_PLAYBACK_CMD_FF) { |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 1508 | DVR_PB_DG(1, "set trick mode -fffb--at pause live"); |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 1509 | AmTsPlayer_setTrickMode(player->handle, AV_VIDEO_TRICK_MODE_PAUSE_NEXT); |
hualing chen | 87072a8 | 2020-03-12 16:20:12 +0800 | [diff] [blame] | 1510 | } else { |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 1511 | DVR_PB_DG(1, "set trick mode ---none"); |
hualing chen | 87072a8 | 2020-03-12 16:20:12 +0800 | [diff] [blame] | 1512 | AmTsPlayer_setTrickMode(player->handle, AV_VIDEO_TRICK_MODE_NONE); |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 1513 | } |
hualing chen | a93bbbc | 2020-12-22 17:23:42 +0800 | [diff] [blame] | 1514 | AmTsPlayer_showVideo(player->handle); |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 1515 | AmTsPlayer_setVideoParams(player->handle, &vparams); |
| 1516 | AmTsPlayer_startVideoDecoding(player->handle); |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 1517 | } |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 1518 | |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 1519 | DVR_PB_DG(1, "player->cmd.cur_cmd:%d vpid[0x%x]apis[0x%x]", player->cmd.cur_cmd, vparams.pid, aparams.pid); |
| 1520 | player->last_send_time_id = UINT64_MAX; |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame] | 1521 | if (player->cmd.cur_cmd == DVR_PLAYBACK_CMD_FB |
| 1522 | || player->cmd.cur_cmd == DVR_PLAYBACK_CMD_FF) { |
| 1523 | player->cmd.state = DVR_PLAYBACK_STATE_START; |
| 1524 | player->state = DVR_PLAYBACK_STATE_START; |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame] | 1525 | } else { |
| 1526 | player->cmd.last_cmd = player->cmd.cur_cmd; |
| 1527 | player->cmd.cur_cmd = DVR_PLAYBACK_CMD_START; |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 1528 | if (IS_FAST_SPEED(player->cmd.speed.speed.speed)) { |
hualing chen | 3114087 | 2020-03-25 12:29:26 +0800 | [diff] [blame] | 1529 | //set fast play |
hualing chen | b96aa2c | 2020-04-15 14:13:53 +0800 | [diff] [blame] | 1530 | DVR_PB_DG(1, "start fast"); |
hualing chen | 3114087 | 2020-03-25 12:29:26 +0800 | [diff] [blame] | 1531 | AmTsPlayer_startFast(player->handle, (float)player->cmd.speed.speed.speed/100.0f); |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 1532 | } else { |
| 1533 | if (VALID_PID(aparams.pid)) { |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 1534 | DVR_PB_DG(1, "start audio"); |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 1535 | player->has_audio = DVR_TRUE; |
| 1536 | AmTsPlayer_setAudioParams(player->handle, &aparams); |
| 1537 | AmTsPlayer_startAudioDecoding(player->handle); |
| 1538 | } |
hualing chen | df118dd | 2020-05-21 15:49:11 +0800 | [diff] [blame] | 1539 | if (VALID_PID(adparams.pid)) { |
| 1540 | player->has_ad_audio = DVR_TRUE; |
| 1541 | DVR_PB_DG(1, "start ad audio"); |
| 1542 | AmTsPlayer_setADParams(player->handle, &adparams); |
| 1543 | AmTsPlayer_enableADMix(player->handle); |
| 1544 | } |
hualing chen | 3114087 | 2020-03-25 12:29:26 +0800 | [diff] [blame] | 1545 | } |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame] | 1546 | player->cmd.state = DVR_PLAYBACK_STATE_START; |
| 1547 | player->state = DVR_PLAYBACK_STATE_START; |
| 1548 | } |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1549 | } |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 1550 | DVR_PB_DG(1, "unlock"); |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1551 | pthread_mutex_unlock(&player->lock); |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 1552 | _start_playback_thread(handle); |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1553 | return DVR_SUCCESS; |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 1554 | } |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 1555 | /**\brief dvr play back add segment info to segment list |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 1556 | * \param[in] handle playback handle |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 1557 | * \param[in] info added segment info,con vpid fmt apid fmt..... |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 1558 | * \retval DVR_SUCCESS On success |
| 1559 | * \return Error code |
| 1560 | */ |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 1561 | int dvr_playback_add_segment(DVR_PlaybackHandle_t handle, DVR_PlaybackSegmentInfo_t *info) { |
| 1562 | DVR_Playback_t *player = (DVR_Playback_t *) handle; |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 1563 | |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 1564 | if (player == NULL) { |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 1565 | DVR_PB_DG(1, "player is NULL"); |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 1566 | return DVR_FAILURE; |
| 1567 | } |
| 1568 | |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 1569 | DVR_PB_DG(1, "add segment id: %lld %p", info->segment_id, handle); |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 1570 | DVR_PlaybackSegmentInfo_t *segment; |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 1571 | |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 1572 | segment = malloc(sizeof(DVR_PlaybackSegmentInfo_t)); |
| 1573 | memset(segment, 0, sizeof(DVR_PlaybackSegmentInfo_t)); |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 1574 | |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1575 | //not memcpy chun info. |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 1576 | segment->segment_id = info->segment_id; |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1577 | //cp location |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 1578 | memcpy(segment->location, info->location, DVR_MAX_LOCATION_SIZE); |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame] | 1579 | |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 1580 | DVR_PB_DG(1, "add location [%s]id[%lld]flag[%x]", segment->location, segment->segment_id, info->flags); |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 1581 | segment->flags = info->flags; |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 1582 | |
| 1583 | //pids |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame] | 1584 | segment->pids.video.pid = info->pids.video.pid; |
| 1585 | segment->pids.video.format = info->pids.video.format; |
| 1586 | segment->pids.video.type = info->pids.video.type; |
| 1587 | |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 1588 | segment->pids.audio.pid = info->pids.audio.pid; |
| 1589 | segment->pids.audio.format = info->pids.audio.format; |
| 1590 | segment->pids.audio.type = info->pids.audio.type; |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame] | 1591 | |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 1592 | segment->pids.ad.pid = info->pids.ad.pid; |
| 1593 | segment->pids.ad.format = info->pids.ad.format; |
| 1594 | segment->pids.ad.type = info->pids.ad.type; |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame] | 1595 | |
| 1596 | segment->pids.pcr.pid = info->pids.pcr.pid; |
| 1597 | |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 1598 | DVR_PB_DG(1, "lock pid [0x%x][0x%x][0x%x][0x%x]", segment->pids.video.pid,segment->pids.audio.pid, info->pids.video.pid,info->pids.audio.pid); |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1599 | pthread_mutex_lock(&player->lock); |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 1600 | list_add_tail(&segment->head, &player->segment_list); |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1601 | pthread_mutex_unlock(&player->lock); |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 1602 | DVR_PB_DG(1, "unlock"); |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 1603 | |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 1604 | return DVR_SUCCESS; |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 1605 | } |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 1606 | /**\brief dvr play back remove segment info by segment_id |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 1607 | * \param[in] handle playback handle |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 1608 | * \param[in] segment_id need removed segment id |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 1609 | * \retval DVR_SUCCESS On success |
| 1610 | * \return Error code |
| 1611 | */ |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 1612 | int dvr_playback_remove_segment(DVR_PlaybackHandle_t handle, uint64_t segment_id) { |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 1613 | DVR_Playback_t *player = (DVR_Playback_t *) handle; |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 1614 | DVR_PB_DG(1, "remove segment id: %lld", segment_id); |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 1615 | if (player == NULL) { |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 1616 | DVR_PB_DG(1, "player is NULL"); |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 1617 | return DVR_FAILURE; |
| 1618 | } |
| 1619 | |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame] | 1620 | if (segment_id == player->cur_segment_id) { |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 1621 | DVR_PB_DG(1, "not suport remove curren segment id: %lld", segment_id); |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame] | 1622 | return DVR_FAILURE; |
| 1623 | } |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 1624 | DVR_PB_DG(1, "lock"); |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1625 | pthread_mutex_lock(&player->lock); |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 1626 | DVR_PlaybackSegmentInfo_t *segment = NULL; |
| 1627 | DVR_PlaybackSegmentInfo_t *segment_tmp = NULL; |
| 1628 | list_for_each_entry_safe(segment, segment_tmp, &player->segment_list, head) |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1629 | { |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 1630 | if (segment->segment_id == segment_id) { |
| 1631 | list_del(&segment->head); |
| 1632 | free(segment); |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1633 | break; |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 1634 | } |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1635 | } |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 1636 | DVR_PB_DG(1, "unlock"); |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1637 | pthread_mutex_unlock(&player->lock); |
| 1638 | |
| 1639 | return DVR_SUCCESS; |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 1640 | } |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 1641 | /**\brief dvr play back add segment info |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 1642 | * \param[in] handle playback handle |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 1643 | * \param[in] info added segment info,con vpid fmt apid fmt..... |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 1644 | * \retval DVR_SUCCESS On success |
| 1645 | * \return Error code |
| 1646 | */ |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 1647 | int dvr_playback_update_segment_flags(DVR_PlaybackHandle_t handle, |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 1648 | uint64_t segment_id, DVR_PlaybackSegmentFlag_t flags) { |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 1649 | DVR_Playback_t *player = (DVR_Playback_t *) handle; |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 1650 | DVR_PB_DG(1, "update segment id: %lld flag:%d", segment_id, flags); |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 1651 | if (player == NULL) { |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 1652 | DVR_PB_DG(1, "player is NULL"); |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 1653 | return DVR_FAILURE; |
| 1654 | } |
hualing chen | f43b8ba | 2020-07-28 13:11:42 +0800 | [diff] [blame] | 1655 | if (player->vendor == DVR_PLAYBACK_VENDOR_AML) { |
| 1656 | DVR_PB_DG(1, "vendor is amlogic. not hide or show av and update segment"); |
| 1657 | return DVR_SUCCESS; |
| 1658 | } |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 1659 | |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 1660 | DVR_PlaybackSegmentInfo_t *segment; |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 1661 | DVR_PB_DG(1, "lock"); |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1662 | pthread_mutex_lock(&player->lock); |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 1663 | list_for_each_entry(segment, &player->segment_list, head) |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1664 | { |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 1665 | if (segment->segment_id != segment_id) { |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1666 | continue; |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 1667 | } |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1668 | // if encramble to free, only set flag and return; |
| 1669 | |
| 1670 | //if displayable to none, we need mute audio and video |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 1671 | if (segment_id == player->cur_segment_id) { |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 1672 | if ((segment->flags & DVR_PLAYBACK_SEGMENT_DISPLAYABLE) == DVR_PLAYBACK_SEGMENT_DISPLAYABLE |
| 1673 | && (flags & DVR_PLAYBACK_SEGMENT_DISPLAYABLE) == 0) { |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame] | 1674 | //disable display, mute |
hualing chen | 703f357 | 2021-01-06 12:51:34 +0800 | [diff] [blame] | 1675 | DVR_PB_DG(1, "mute av"); |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 1676 | AmTsPlayer_hideVideo(player->handle); |
| 1677 | AmTsPlayer_setAudioMute(player->handle, 1, 1); |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 1678 | } else if ((segment->flags & DVR_PLAYBACK_SEGMENT_DISPLAYABLE) == 0 && |
| 1679 | (flags & DVR_PLAYBACK_SEGMENT_DISPLAYABLE) == DVR_PLAYBACK_SEGMENT_DISPLAYABLE) { |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame] | 1680 | //enable display, unmute |
hualing chen | 703f357 | 2021-01-06 12:51:34 +0800 | [diff] [blame] | 1681 | DVR_PB_DG(1, "unmute av"); |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 1682 | AmTsPlayer_showVideo(player->handle); |
| 1683 | AmTsPlayer_setAudioMute(player->handle, 0, 0); |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1684 | } else { |
| 1685 | //do nothing |
| 1686 | } |
| 1687 | } else { |
| 1688 | //do nothing |
| 1689 | } |
| 1690 | //continue , only set flag |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 1691 | segment->flags = flags; |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1692 | } |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 1693 | DVR_PB_DG(1, "unlock"); |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1694 | pthread_mutex_unlock(&player->lock); |
| 1695 | return DVR_SUCCESS; |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 1696 | } |
| 1697 | |
| 1698 | |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 1699 | static int _do_check_pid_info(DVR_PlaybackHandle_t handle, DVR_StreamInfo_t now_pid, DVR_StreamInfo_t set_pid, int type) { |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 1700 | DVR_Playback_t *player = (DVR_Playback_t *) handle; |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 1701 | if (player == NULL) { |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 1702 | DVR_PB_DG(1, "player is NULL"); |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 1703 | return DVR_FAILURE; |
| 1704 | } |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 1705 | DVR_PB_DG(1, " do check"); |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1706 | if (now_pid.pid == set_pid.pid) { |
| 1707 | //do nothing |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 1708 | return 0; |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 1709 | } else if (player->cmd.state == DVR_PLAYBACK_STATE_START) { |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1710 | if (VALID_PID(now_pid.pid)) { |
| 1711 | //stop now stream |
| 1712 | if (type == 0) { |
| 1713 | //stop vieo |
hualing chen | c70a8df | 2020-05-12 19:23:11 +0800 | [diff] [blame] | 1714 | if (player->has_video == DVR_TRUE) { |
| 1715 | DVR_PB_DG(1, "stop video"); |
| 1716 | AmTsPlayer_stopVideoDecoding(player->handle); |
| 1717 | player->has_video = DVR_FALSE; |
| 1718 | } |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1719 | } else if (type == 1) { |
| 1720 | //stop audio |
hualing chen | c70a8df | 2020-05-12 19:23:11 +0800 | [diff] [blame] | 1721 | if (player->has_audio == DVR_TRUE) { |
| 1722 | DVR_PB_DG(1, "stop audio"); |
| 1723 | AmTsPlayer_stopAudioDecoding(player->handle); |
| 1724 | player->has_audio = DVR_FALSE; |
| 1725 | } |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1726 | } else if (type == 2) { |
| 1727 | //stop sub audio |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 1728 | DVR_PB_DG(1, "stop ad"); |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 1729 | AmTsPlayer_disableADMix(player->handle); |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1730 | } else if (type == 3) { |
| 1731 | //pcr |
| 1732 | } |
| 1733 | } |
| 1734 | if (VALID_PID(set_pid.pid)) { |
| 1735 | //start |
| 1736 | if (type == 0) { |
| 1737 | //start vieo |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 1738 | am_tsplayer_video_params vparams; |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1739 | vparams.pid = set_pid.pid; |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 1740 | vparams.codectype = _dvr_convert_stream_fmt(set_pid.format, DVR_FALSE); |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 1741 | player->has_video = DVR_TRUE; |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 1742 | DVR_PB_DG(1, "start video pid[%d]fmt[%d]",vparams.pid, vparams.codectype); |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 1743 | AmTsPlayer_setVideoParams(player->handle, &vparams); |
| 1744 | AmTsPlayer_startVideoDecoding(player->handle); |
| 1745 | //playback_device_video_start(player->handle,&vparams); |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1746 | } else if (type == 1) { |
| 1747 | //start audio |
hualing chen | c70a8df | 2020-05-12 19:23:11 +0800 | [diff] [blame] | 1748 | if ((player->cmd.speed.speed.speed == PLAYBACK_SPEED_X1)) { |
| 1749 | am_tsplayer_audio_params aparams; |
| 1750 | aparams.pid = set_pid.pid; |
| 1751 | aparams.codectype= _dvr_convert_stream_fmt(set_pid.format, DVR_TRUE); |
| 1752 | player->has_audio = DVR_TRUE; |
| 1753 | DVR_PB_DG(1, "start audio pid[%d]fmt[%d]",aparams.pid, aparams.codectype); |
| 1754 | AmTsPlayer_setAudioParams(player->handle, &aparams); |
| 1755 | AmTsPlayer_startAudioDecoding(player->handle); |
| 1756 | //playback_device_audio_start(player->handle,&aparams); |
| 1757 | } |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1758 | } else if (type == 2) { |
hualing chen | 3962821 | 2020-05-14 10:35:13 +0800 | [diff] [blame] | 1759 | if ((player->cmd.speed.speed.speed == PLAYBACK_SPEED_X1)) { |
hualing chen | c70a8df | 2020-05-12 19:23:11 +0800 | [diff] [blame] | 1760 | am_tsplayer_audio_params aparams; |
| 1761 | aparams.pid = set_pid.pid; |
| 1762 | aparams.codectype= _dvr_convert_stream_fmt(set_pid.format, DVR_TRUE); |
| 1763 | player->has_audio = DVR_TRUE; |
| 1764 | DVR_PB_DG(1, "start ad audio pid[%d]fmt[%d]",aparams.pid, aparams.codectype); |
| 1765 | AmTsPlayer_setADParams(player->handle, &aparams); |
| 1766 | AmTsPlayer_enableADMix(player->handle); |
| 1767 | //playback_device_audio_start(player->handle,&aparams); |
| 1768 | } |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1769 | } else if (type == 3) { |
| 1770 | //pcr |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 1771 | DVR_PB_DG(1, "start set pcr [%d]", set_pid.pid); |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 1772 | AmTsPlayer_setPcrPid(player->handle, set_pid.pid); |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1773 | } |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 1774 | //audio and video all close |
| 1775 | if (!player->has_audio && !player->has_video) { |
| 1776 | player->state = DVR_PLAYBACK_STATE_STOP; |
| 1777 | } |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1778 | } |
| 1779 | } |
| 1780 | return 0; |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 1781 | } |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 1782 | /**\brief dvr play back update segment pids |
| 1783 | * if updated segment is ongoing segment, we need start new |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 1784 | * add pid stream and stop remove pid stream. |
| 1785 | * \param[in] handle playback handle |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 1786 | * \param[in] segment_id need updated pids segment id |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 1787 | * \retval DVR_SUCCESS On success |
| 1788 | * \return Error code |
| 1789 | */ |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 1790 | int dvr_playback_update_segment_pids(DVR_PlaybackHandle_t handle, uint64_t segment_id, DVR_PlaybackPids_t *p_pids) { |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 1791 | DVR_Playback_t *player = (DVR_Playback_t *) handle; |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 1792 | if (player == NULL) { |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 1793 | DVR_PB_DG(1, "player is NULL"); |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 1794 | return DVR_FAILURE; |
| 1795 | } |
| 1796 | |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 1797 | DVR_PlaybackSegmentInfo_t *segment; |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 1798 | DVR_PB_DG(1, "lock"); |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1799 | pthread_mutex_lock(&player->lock); |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 1800 | DVR_PB_DG(1, "get lock update segment id: %lld cur id %lld", segment_id, player->cur_segment_id); |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame] | 1801 | |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 1802 | list_for_each_entry(segment, &player->segment_list, head) |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1803 | { |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 1804 | if (segment->segment_id == segment_id) { |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 1805 | |
| 1806 | if (player->cur_segment_id == segment_id) { |
| 1807 | if (player->cmd.state == DVR_PLAYBACK_STATE_FF |
| 1808 | || player->cmd.state == DVR_PLAYBACK_STATE_FF) { |
| 1809 | //do nothing when ff fb |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 1810 | DVR_PB_DG(1, "unlock now is ff fb, not to update cur segment info\r\n"); |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame] | 1811 | pthread_mutex_unlock(&player->lock); |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 1812 | return 0; |
| 1813 | } |
| 1814 | |
| 1815 | //if segment is on going segment,we need stop start stream |
| 1816 | if (player->cmd.state == DVR_PLAYBACK_STATE_START) { |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame] | 1817 | pthread_mutex_unlock(&player->lock); |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 1818 | //check video pids, stop or restart |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame] | 1819 | _do_check_pid_info((DVR_PlaybackHandle_t)player, segment->pids.video, p_pids->video, 0); |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 1820 | //check audio pids stop or restart |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame] | 1821 | _do_check_pid_info((DVR_PlaybackHandle_t)player, segment->pids.audio, p_pids->audio, 1); |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 1822 | //check sub audio pids stop or restart |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame] | 1823 | _do_check_pid_info((DVR_PlaybackHandle_t)player, segment->pids.ad, p_pids->ad, 2); |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 1824 | //check pcr pids stop or restart |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame] | 1825 | _do_check_pid_info((DVR_PlaybackHandle_t)player, segment->pids.pcr, p_pids->pcr, 3); |
| 1826 | pthread_mutex_lock(&player->lock); |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 1827 | } else if (player->cmd.state == DVR_PLAYBACK_STATE_PAUSE) { |
| 1828 | //if state is pause, we need process at resume api. we only record change info |
| 1829 | int v_cmd = DVR_PLAYBACK_CMD_NONE; |
| 1830 | int a_cmd = DVR_PLAYBACK_CMD_NONE; |
| 1831 | if (VALID_PID(segment->pids.video.pid) |
| 1832 | && VALID_PID(p_pids->video.pid) |
| 1833 | && segment->pids.video.pid != p_pids->video.pid) { |
| 1834 | //restart video |
| 1835 | v_cmd = DVR_PLAYBACK_CMD_VRESTART; |
| 1836 | } |
| 1837 | if (!VALID_PID(segment->pids.video.pid) |
| 1838 | && VALID_PID(p_pids->video.pid) |
| 1839 | && segment->pids.video.pid != p_pids->video.pid) { |
| 1840 | //start video |
| 1841 | v_cmd = DVR_PLAYBACK_CMD_VSTART; |
| 1842 | } |
| 1843 | if (VALID_PID(segment->pids.video.pid) |
| 1844 | && !VALID_PID(p_pids->video.pid) |
| 1845 | && segment->pids.video.pid != p_pids->video.pid) { |
| 1846 | //stop video |
| 1847 | v_cmd = DVR_PLAYBACK_CMD_VSTOP; |
| 1848 | } |
| 1849 | if (VALID_PID(segment->pids.audio.pid) |
| 1850 | && VALID_PID(p_pids->audio.pid) |
| 1851 | && segment->pids.audio.pid != p_pids->audio.pid) { |
| 1852 | //restart audio |
| 1853 | a_cmd = DVR_PLAYBACK_CMD_ARESTART; |
| 1854 | } |
| 1855 | if (!VALID_PID(segment->pids.audio.pid) |
| 1856 | && VALID_PID(p_pids->audio.pid) |
| 1857 | && segment->pids.audio.pid != p_pids->audio.pid) { |
| 1858 | //start audio |
| 1859 | a_cmd = DVR_PLAYBACK_CMD_ASTART; |
| 1860 | } |
| 1861 | if (VALID_PID(segment->pids.audio.pid) |
| 1862 | && !VALID_PID(p_pids->audio.pid) |
| 1863 | && segment->pids.audio.pid != p_pids->audio.pid) { |
| 1864 | //stop audio |
| 1865 | a_cmd = DVR_PLAYBACK_CMD_ASTOP; |
| 1866 | } |
| 1867 | if (a_cmd == DVR_PLAYBACK_CMD_NONE |
| 1868 | && v_cmd == DVR_PLAYBACK_CMD_NONE) { |
| 1869 | //do nothing |
| 1870 | } else if (a_cmd == DVR_PLAYBACK_CMD_NONE |
| 1871 | || v_cmd == DVR_PLAYBACK_CMD_NONE) { |
| 1872 | player->cmd.last_cmd =DVR_PLAYBACK_CMD_PAUSE; |
| 1873 | player->cmd.cur_cmd = a_cmd != DVR_PLAYBACK_CMD_NONE ? a_cmd : v_cmd; |
| 1874 | } else if (a_cmd != DVR_PLAYBACK_CMD_NONE |
| 1875 | && v_cmd != DVR_PLAYBACK_CMD_NONE) { |
| 1876 | if (v_cmd == DVR_PLAYBACK_CMD_VRESTART |
| 1877 | && (a_cmd == DVR_PLAYBACK_CMD_ARESTART)) { |
| 1878 | player->cmd.last_cmd =DVR_PLAYBACK_CMD_PAUSE; |
| 1879 | player->cmd.cur_cmd = DVR_PLAYBACK_CMD_AVRESTART; |
| 1880 | }else if (v_cmd == DVR_PLAYBACK_CMD_VRESTART |
| 1881 | && a_cmd == DVR_PLAYBACK_CMD_ASTART) { |
| 1882 | player->cmd.last_cmd =DVR_PLAYBACK_CMD_PAUSE; |
| 1883 | player->cmd.cur_cmd = DVR_PLAYBACK_CMD_ASTARTVRESTART; |
| 1884 | } else { |
| 1885 | player->cmd.last_cmd =DVR_PLAYBACK_CMD_PAUSE; |
| 1886 | player->cmd.cur_cmd = DVR_PLAYBACK_CMD_ASTOPVRESTART; |
| 1887 | } |
| 1888 | |
| 1889 | if (v_cmd == DVR_PLAYBACK_CMD_VSTART |
| 1890 | && (a_cmd == DVR_PLAYBACK_CMD_ARESTART)) { |
| 1891 | player->cmd.last_cmd =DVR_PLAYBACK_CMD_PAUSE; |
| 1892 | player->cmd.cur_cmd = DVR_PLAYBACK_CMD_VSTARTARESTART; |
| 1893 | } else if (v_cmd == DVR_PLAYBACK_CMD_VSTART |
| 1894 | && a_cmd == DVR_PLAYBACK_CMD_ASTART) { |
| 1895 | //not occur this case |
| 1896 | player->cmd.last_cmd =DVR_PLAYBACK_CMD_PAUSE; |
| 1897 | player->cmd.cur_cmd = DVR_PLAYBACK_CMD_START; |
| 1898 | } else { |
| 1899 | player->cmd.last_cmd =DVR_PLAYBACK_CMD_PAUSE; |
| 1900 | player->cmd.cur_cmd = DVR_PLAYBACK_CMD_ASTOPVSTART; |
| 1901 | } |
| 1902 | |
| 1903 | if (v_cmd == DVR_PLAYBACK_CMD_VSTOP |
| 1904 | && a_cmd == DVR_PLAYBACK_CMD_ASTART) { |
| 1905 | player->cmd.last_cmd =DVR_PLAYBACK_CMD_PAUSE; |
| 1906 | player->cmd.cur_cmd = DVR_PLAYBACK_CMD_VSTOPASTART; |
| 1907 | } else if (v_cmd == DVR_PLAYBACK_CMD_VSTOP |
| 1908 | && a_cmd == DVR_PLAYBACK_CMD_ARESTART) { |
| 1909 | player->cmd.last_cmd =DVR_PLAYBACK_CMD_PAUSE; |
| 1910 | player->cmd.cur_cmd = DVR_PLAYBACK_CMD_VSTOPARESTART; |
| 1911 | } else { |
| 1912 | //not occur this case |
| 1913 | player->cmd.last_cmd =DVR_PLAYBACK_CMD_PAUSE; |
| 1914 | player->cmd.cur_cmd = DVR_PLAYBACK_CMD_STOP; |
| 1915 | } |
| 1916 | } |
| 1917 | } |
hualing chen | e10666f | 2020-04-14 13:58:37 +0800 | [diff] [blame] | 1918 | memcpy(&player->cur_segment.pids, p_pids, sizeof(DVR_PlaybackPids_t)); |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 1919 | } |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1920 | //save pids info |
hualing chen | b5cd42e | 2020-04-15 17:03:34 +0800 | [diff] [blame] | 1921 | DVR_PB_DG(1, ":apid :%d %d", segment->pids.audio.pid, p_pids->audio.pid); |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 1922 | memcpy(&segment->pids, p_pids, sizeof(DVR_PlaybackPids_t)); |
hualing chen | b5cd42e | 2020-04-15 17:03:34 +0800 | [diff] [blame] | 1923 | DVR_PB_DG(1, ":cp apid :%d %d", segment->pids.audio.pid, p_pids->audio.pid); |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1924 | break; |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 1925 | } |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1926 | } |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 1927 | DVR_PB_DG(1, "unlock"); |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1928 | pthread_mutex_unlock(&player->lock); |
| 1929 | return DVR_SUCCESS; |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 1930 | } |
| 1931 | /**\brief Stop play, will stop video and audio |
| 1932 | * \param[in] handle playback handle |
| 1933 | * \param[in] clear is clear last frame |
| 1934 | * \retval DVR_SUCCESS On success |
| 1935 | * \return Error code |
| 1936 | */ |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 1937 | int dvr_playback_stop(DVR_PlaybackHandle_t handle, DVR_Bool_t clear) { |
| 1938 | DVR_Playback_t *player = (DVR_Playback_t *) handle; |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 1939 | |
| 1940 | if (player == NULL) { |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 1941 | DVR_PB_DG(1, "player is NULL"); |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 1942 | return DVR_FAILURE; |
| 1943 | } |
hualing chen | b96aa2c | 2020-04-15 14:13:53 +0800 | [diff] [blame] | 1944 | if (player->state == DVR_PLAYBACK_STATE_STOP) { |
| 1945 | DVR_PB_DG(1, ":playback is stoped"); |
| 1946 | return DVR_SUCCESS; |
| 1947 | } |
Ke Gong | 3c0caba | 2020-04-21 22:58:18 -0700 | [diff] [blame] | 1948 | if (player->state == DVR_PLAYBACK_STATE_STOP) { |
| 1949 | DVR_PB_DG(1, ":playback is stoped"); |
| 1950 | return DVR_SUCCESS; |
| 1951 | } |
hualing chen | 87072a8 | 2020-03-12 16:20:12 +0800 | [diff] [blame] | 1952 | _stop_playback_thread(handle); |
hualing chen | 7a56cba | 2020-04-14 14:09:27 +0800 | [diff] [blame] | 1953 | DVR_PB_DG(1, "lock"); |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1954 | pthread_mutex_lock(&player->lock); |
hualing chen | 7a56cba | 2020-04-14 14:09:27 +0800 | [diff] [blame] | 1955 | DVR_PB_DG(1, ":get lock into stop fast"); |
hualing chen | 3114087 | 2020-03-25 12:29:26 +0800 | [diff] [blame] | 1956 | AmTsPlayer_stopFast(player->handle); |
hualing chen | 266b950 | 2020-04-04 17:39:39 +0800 | [diff] [blame] | 1957 | if (player->has_video) { |
| 1958 | AmTsPlayer_resumeVideoDecoding(player->handle); |
| 1959 | } |
| 1960 | if (player->has_audio) { |
| 1961 | AmTsPlayer_resumeAudioDecoding(player->handle); |
| 1962 | } |
| 1963 | if (player->has_video) { |
| 1964 | player->has_video = DVR_FALSE; |
hualing chen | 10cdb16 | 2021-02-05 10:44:41 +0800 | [diff] [blame^] | 1965 | AmTsPlayer_hideVideo(player->handle); |
hualing chen | 266b950 | 2020-04-04 17:39:39 +0800 | [diff] [blame] | 1966 | AmTsPlayer_stopVideoDecoding(player->handle); |
| 1967 | } |
| 1968 | if (player->has_audio) { |
| 1969 | player->has_audio = DVR_FALSE; |
| 1970 | AmTsPlayer_stopAudioDecoding(player->handle); |
| 1971 | } |
hualing chen | df118dd | 2020-05-21 15:49:11 +0800 | [diff] [blame] | 1972 | if (player->has_ad_audio) { |
| 1973 | player->has_ad_audio =DVR_FALSE; |
| 1974 | AmTsPlayer_disableADMix(player->handle); |
| 1975 | } |
hualing chen | 266b950 | 2020-04-04 17:39:39 +0800 | [diff] [blame] | 1976 | |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1977 | player->cmd.last_cmd = player->cmd.cur_cmd; |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 1978 | player->cmd.cur_cmd = DVR_PLAYBACK_CMD_STOP; |
| 1979 | player->cmd.state = DVR_PLAYBACK_STATE_STOP; |
| 1980 | player->state = DVR_PLAYBACK_STATE_STOP; |
hualing chen | 87072a8 | 2020-03-12 16:20:12 +0800 | [diff] [blame] | 1981 | player->cur_segment_id = UINT64_MAX; |
| 1982 | player->segment_is_open = DVR_FALSE; |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 1983 | DVR_PB_DG(1, "unlock"); |
hualing chen | b96aa2c | 2020-04-15 14:13:53 +0800 | [diff] [blame] | 1984 | DVR_PB_DG(1, "player->state %s", _dvr_playback_state_toString(player->state)); |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1985 | pthread_mutex_unlock(&player->lock); |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1986 | return DVR_SUCCESS; |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 1987 | } |
| 1988 | /**\brief Start play audio |
| 1989 | * \param[in] handle playback handle |
| 1990 | * \param[in] params audio playback params,contains fmt and pid... |
| 1991 | * \retval DVR_SUCCESS On success |
| 1992 | * \return Error code |
| 1993 | */ |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 1994 | |
hualing chen | df118dd | 2020-05-21 15:49:11 +0800 | [diff] [blame] | 1995 | int dvr_playback_audio_start(DVR_PlaybackHandle_t handle, am_tsplayer_audio_params *param, am_tsplayer_audio_params *adparam) { |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 1996 | DVR_Playback_t *player = (DVR_Playback_t *) handle; |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 1997 | |
| 1998 | if (player == NULL) { |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 1999 | DVR_PB_DG(1, "player is NULL"); |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 2000 | return DVR_FAILURE; |
| 2001 | } |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 2002 | _start_playback_thread(handle); |
| 2003 | //start audio and video |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 2004 | DVR_PB_DG(1, "lock"); |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 2005 | pthread_mutex_lock(&player->lock); |
hualing chen | df118dd | 2020-05-21 15:49:11 +0800 | [diff] [blame] | 2006 | |
| 2007 | if (VALID_PID(param->pid)) { |
| 2008 | DVR_PB_DG(1, "start audio"); |
| 2009 | player->has_audio = DVR_TRUE; |
| 2010 | AmTsPlayer_setAudioParams(player->handle, param); |
| 2011 | AmTsPlayer_startAudioDecoding(player->handle); |
| 2012 | } |
| 2013 | if (VALID_PID(adparam->pid)) { |
| 2014 | player->has_ad_audio = DVR_TRUE; |
| 2015 | DVR_PB_DG(1, "start ad audio"); |
| 2016 | AmTsPlayer_setADParams(player->handle, adparam); |
| 2017 | AmTsPlayer_enableADMix(player->handle); |
| 2018 | } |
| 2019 | |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 2020 | player->cmd.last_cmd = player->cmd.cur_cmd; |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 2021 | player->cmd.cur_cmd = DVR_PLAYBACK_CMD_ASTART; |
| 2022 | player->cmd.state = DVR_PLAYBACK_STATE_START; |
| 2023 | player->state = DVR_PLAYBACK_STATE_START; |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 2024 | DVR_PB_DG(1, "unlock"); |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 2025 | pthread_mutex_unlock(&player->lock); |
| 2026 | return DVR_SUCCESS; |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 2027 | } |
| 2028 | /**\brief Stop play audio |
| 2029 | * \param[in] handle playback handle |
| 2030 | * \retval DVR_SUCCESS On success |
| 2031 | * \return Error code |
| 2032 | */ |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 2033 | int dvr_playback_audio_stop(DVR_PlaybackHandle_t handle) { |
| 2034 | DVR_Playback_t *player = (DVR_Playback_t *) handle; |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 2035 | |
| 2036 | if (player == NULL) { |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 2037 | DVR_PB_DG(1, "player is NULL"); |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 2038 | return DVR_FAILURE; |
| 2039 | } |
| 2040 | |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 2041 | //playback_device_audio_stop(player->handle); |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 2042 | if (player->has_video == DVR_FALSE) { |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 2043 | player->cmd.state = DVR_PLAYBACK_STATE_STOP; |
| 2044 | player->state = DVR_PLAYBACK_STATE_STOP; |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 2045 | //destory thread |
| 2046 | _stop_playback_thread(handle); |
| 2047 | } else { |
| 2048 | //do nothing.video is playing |
| 2049 | } |
hualing chen | 7a56cba | 2020-04-14 14:09:27 +0800 | [diff] [blame] | 2050 | DVR_PB_DG(1, "lock"); |
| 2051 | pthread_mutex_lock(&player->lock); |
| 2052 | |
hualing chen | f00cdc8 | 2020-06-10 14:23:35 +0800 | [diff] [blame] | 2053 | if (player->has_audio) { |
hualing chen | df118dd | 2020-05-21 15:49:11 +0800 | [diff] [blame] | 2054 | player->has_audio = DVR_FALSE; |
| 2055 | AmTsPlayer_stopAudioDecoding(player->handle); |
| 2056 | } |
hualing chen | 87072a8 | 2020-03-12 16:20:12 +0800 | [diff] [blame] | 2057 | |
hualing chen | df118dd | 2020-05-21 15:49:11 +0800 | [diff] [blame] | 2058 | if (player->has_ad_audio) { |
| 2059 | player->has_ad_audio =DVR_FALSE; |
| 2060 | AmTsPlayer_disableADMix(player->handle); |
| 2061 | } |
| 2062 | |
hualing chen | 87072a8 | 2020-03-12 16:20:12 +0800 | [diff] [blame] | 2063 | player->cmd.last_cmd = player->cmd.cur_cmd; |
| 2064 | player->cmd.cur_cmd = DVR_PLAYBACK_CMD_ASTOP; |
| 2065 | |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 2066 | DVR_PB_DG(1, "unlock"); |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 2067 | pthread_mutex_unlock(&player->lock); |
| 2068 | return DVR_SUCCESS; |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 2069 | } |
| 2070 | /**\brief Start play video |
| 2071 | * \param[in] handle playback handle |
| 2072 | * \param[in] params video playback params,contains fmt and pid... |
| 2073 | * \retval DVR_SUCCESS On success |
| 2074 | * \return Error code |
| 2075 | */ |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 2076 | int dvr_playback_video_start(DVR_PlaybackHandle_t handle, am_tsplayer_video_params *param) { |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 2077 | DVR_Playback_t *player = (DVR_Playback_t *) handle; |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 2078 | |
| 2079 | if (player == NULL) { |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 2080 | DVR_PB_DG(1, "player is NULL"); |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 2081 | return DVR_FAILURE; |
| 2082 | } |
| 2083 | |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 2084 | _start_playback_thread(handle); |
| 2085 | //start audio and video |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 2086 | DVR_PB_DG(1, "lock"); |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 2087 | pthread_mutex_lock(&player->lock); |
| 2088 | player->has_video = DVR_TRUE; |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 2089 | AmTsPlayer_setVideoParams(player->handle, param); |
| 2090 | AmTsPlayer_startVideoDecoding(player->handle); |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 2091 | |
| 2092 | //playback_device_video_start(player->handle , param); |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 2093 | //if set flag is pause live, we need set trick mode |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 2094 | if ((player->play_flag&DVR_PLAYBACK_STARTED_PAUSEDLIVE) == DVR_PLAYBACK_STARTED_PAUSEDLIVE) { |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 2095 | DVR_PB_DG(1, "settrick mode at video start"); |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 2096 | AmTsPlayer_setTrickMode(player->handle, AV_VIDEO_TRICK_MODE_PAUSE_NEXT); |
| 2097 | //playback_device_trick_mode(player->handle, 1); |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 2098 | } |
| 2099 | player->cmd.last_cmd = player->cmd.cur_cmd; |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 2100 | player->cmd.cur_cmd = DVR_PLAYBACK_CMD_VSTART; |
| 2101 | player->cmd.state = DVR_PLAYBACK_STATE_START; |
| 2102 | player->state = DVR_PLAYBACK_STATE_START; |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 2103 | DVR_PB_DG(1, "unlock"); |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 2104 | pthread_mutex_unlock(&player->lock); |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 2105 | return DVR_SUCCESS; |
| 2106 | } |
| 2107 | /**\brief Stop play video |
| 2108 | * \param[in] handle playback handle |
| 2109 | * \retval DVR_SUCCESS On success |
| 2110 | * \return Error code |
| 2111 | */ |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 2112 | int dvr_playback_video_stop(DVR_PlaybackHandle_t handle) { |
| 2113 | DVR_Playback_t *player = (DVR_Playback_t *) handle; |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 2114 | |
| 2115 | if (player == NULL) { |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 2116 | DVR_PB_DG(1, "player is NULL"); |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 2117 | return DVR_FAILURE; |
| 2118 | } |
| 2119 | |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 2120 | if (player->has_audio == DVR_FALSE) { |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 2121 | player->cmd.state = DVR_PLAYBACK_STATE_STOP; |
| 2122 | player->state = DVR_PLAYBACK_STATE_STOP; |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 2123 | //destory thread |
| 2124 | _stop_playback_thread(handle); |
| 2125 | } else { |
| 2126 | //do nothing.audio is playing |
| 2127 | } |
hualing chen | 7a56cba | 2020-04-14 14:09:27 +0800 | [diff] [blame] | 2128 | |
| 2129 | DVR_PB_DG(1, "lock"); |
| 2130 | pthread_mutex_lock(&player->lock); |
| 2131 | |
hualing chen | 87072a8 | 2020-03-12 16:20:12 +0800 | [diff] [blame] | 2132 | player->has_video = DVR_FALSE; |
| 2133 | |
| 2134 | AmTsPlayer_stopVideoDecoding(player->handle); |
| 2135 | //playback_device_video_stop(player->handle); |
| 2136 | |
| 2137 | player->cmd.last_cmd = player->cmd.cur_cmd; |
| 2138 | player->cmd.cur_cmd = DVR_PLAYBACK_CMD_VSTOP; |
| 2139 | |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 2140 | DVR_PB_DG(1, "unlock"); |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 2141 | pthread_mutex_unlock(&player->lock); |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 2142 | return DVR_SUCCESS; |
| 2143 | } |
| 2144 | /**\brief Pause play |
| 2145 | * \param[in] handle playback handle |
| 2146 | * \param[in] flush whether its internal buffers should be flushed |
| 2147 | * \retval DVR_SUCCESS On success |
| 2148 | * \return Error code |
| 2149 | */ |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 2150 | int dvr_playback_pause(DVR_PlaybackHandle_t handle, DVR_Bool_t flush) { |
| 2151 | DVR_Playback_t *player = (DVR_Playback_t *) handle; |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 2152 | |
| 2153 | if (player == NULL) { |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 2154 | DVR_PB_DG(1, "player is NULL"); |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 2155 | return DVR_FAILURE; |
| 2156 | } |
hualing chen | f00cdc8 | 2020-06-10 14:23:35 +0800 | [diff] [blame] | 2157 | if (player->state == DVR_PLAYBACK_STATE_PAUSE ||player->state == DVR_PLAYBACK_STATE_STOP ) { |
| 2158 | DVR_PB_DG(1, "player state is [%d] pause or stop", player->state); |
hualing chen | bd977fd | 2020-06-29 19:14:18 +0800 | [diff] [blame] | 2159 | return DVR_SUCCESS; |
hualing chen | f00cdc8 | 2020-06-10 14:23:35 +0800 | [diff] [blame] | 2160 | } |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 2161 | DVR_PB_DG(1, "lock"); |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 2162 | pthread_mutex_lock(&player->lock); |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 2163 | DVR_PB_DG(1, "get lock"); |
hualing chen | 266b950 | 2020-04-04 17:39:39 +0800 | [diff] [blame] | 2164 | if (player->has_video) |
| 2165 | AmTsPlayer_pauseVideoDecoding(player->handle); |
hualing chen | e41f437 | 2020-06-06 16:29:17 +0800 | [diff] [blame] | 2166 | if (player->has_audio) |
hualing chen | 266b950 | 2020-04-04 17:39:39 +0800 | [diff] [blame] | 2167 | AmTsPlayer_pauseAudioDecoding(player->handle); |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 2168 | |
| 2169 | //playback_device_pause(player->handle); |
hualing chen | 87072a8 | 2020-03-12 16:20:12 +0800 | [diff] [blame] | 2170 | if (player->cmd.cur_cmd == DVR_PLAYBACK_CMD_FF || |
| 2171 | player->cmd.cur_cmd == DVR_PLAYBACK_CMD_FB) { |
| 2172 | player->cmd.state = DVR_PLAYBACK_STATE_PAUSE; |
| 2173 | player->state = DVR_PLAYBACK_STATE_PAUSE; |
hualing chen | 87072a8 | 2020-03-12 16:20:12 +0800 | [diff] [blame] | 2174 | } else { |
| 2175 | player->cmd.last_cmd = player->cmd.cur_cmd; |
| 2176 | player->cmd.cur_cmd = DVR_PLAYBACK_CMD_PAUSE; |
| 2177 | player->cmd.state = DVR_PLAYBACK_STATE_PAUSE; |
| 2178 | player->state = DVR_PLAYBACK_STATE_PAUSE; |
hualing chen | 87072a8 | 2020-03-12 16:20:12 +0800 | [diff] [blame] | 2179 | } |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 2180 | pthread_mutex_unlock(&player->lock); |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 2181 | DVR_PB_DG(1, "unlock"); |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 2182 | |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 2183 | return DVR_SUCCESS; |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 2184 | } |
| 2185 | |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 2186 | //not add lock |
| 2187 | static int _dvr_cmd(DVR_PlaybackHandle_t handle, int cmd) |
| 2188 | { |
| 2189 | DVR_Playback_t *player = (DVR_Playback_t *) handle; |
| 2190 | |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 2191 | if (player == NULL) { |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 2192 | DVR_PB_DG(1, "player is NULL"); |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 2193 | return DVR_FAILURE; |
| 2194 | } |
| 2195 | |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 2196 | //get video params and audio params |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 2197 | DVR_PB_DG(1, "lock"); |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 2198 | pthread_mutex_lock(&player->lock); |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 2199 | am_tsplayer_video_params vparams; |
| 2200 | am_tsplayer_audio_params aparams; |
hualing chen | df118dd | 2020-05-21 15:49:11 +0800 | [diff] [blame] | 2201 | am_tsplayer_audio_params adparams; |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame] | 2202 | uint64_t segmentid = player->cur_segment_id; |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 2203 | |
hualing chen | df118dd | 2020-05-21 15:49:11 +0800 | [diff] [blame] | 2204 | _dvr_playback_get_playinfo(handle, segmentid, &vparams, &aparams, &adparams); |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 2205 | DVR_PB_DG(1, "unlock cmd: %d", cmd); |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 2206 | pthread_mutex_unlock(&player->lock); |
| 2207 | |
| 2208 | switch (cmd) { |
| 2209 | case DVR_PLAYBACK_CMD_AVRESTART: |
| 2210 | //av restart |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 2211 | DVR_PB_DG(1, "do_cmd avrestart"); |
hualing chen | 87072a8 | 2020-03-12 16:20:12 +0800 | [diff] [blame] | 2212 | _dvr_playback_replay((DVR_PlaybackHandle_t)player, DVR_FALSE); |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 2213 | break; |
| 2214 | case DVR_PLAYBACK_CMD_VRESTART: |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 2215 | dvr_playback_video_stop((DVR_PlaybackHandle_t)player); |
| 2216 | dvr_playback_video_start((DVR_PlaybackHandle_t)player, &vparams); |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 2217 | break; |
| 2218 | case DVR_PLAYBACK_CMD_VSTART: |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 2219 | dvr_playback_video_start((DVR_PlaybackHandle_t)player, &vparams); |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 2220 | break; |
| 2221 | case DVR_PLAYBACK_CMD_VSTOP: |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 2222 | dvr_playback_video_stop((DVR_PlaybackHandle_t)player); |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 2223 | break; |
| 2224 | case DVR_PLAYBACK_CMD_ARESTART: |
| 2225 | //a restart |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 2226 | dvr_playback_audio_stop((DVR_PlaybackHandle_t)player); |
hualing chen | df118dd | 2020-05-21 15:49:11 +0800 | [diff] [blame] | 2227 | dvr_playback_audio_start((DVR_PlaybackHandle_t)player, &aparams, &adparams); |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 2228 | break; |
| 2229 | case DVR_PLAYBACK_CMD_ASTART: |
hualing chen | df118dd | 2020-05-21 15:49:11 +0800 | [diff] [blame] | 2230 | dvr_playback_audio_start((DVR_PlaybackHandle_t)player, &aparams, &adparams); |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 2231 | break; |
| 2232 | case DVR_PLAYBACK_CMD_ASTOP: |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 2233 | dvr_playback_audio_stop((DVR_PlaybackHandle_t)player); |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 2234 | break; |
| 2235 | case DVR_PLAYBACK_CMD_ASTOPVRESTART: |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 2236 | dvr_playback_audio_stop((DVR_PlaybackHandle_t)player); |
| 2237 | dvr_playback_video_stop((DVR_PlaybackHandle_t)player); |
| 2238 | dvr_playback_video_start((DVR_PlaybackHandle_t)player, &vparams); |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 2239 | break; |
| 2240 | case DVR_PLAYBACK_CMD_ASTOPVSTART: |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 2241 | dvr_playback_audio_stop((DVR_PlaybackHandle_t)player); |
| 2242 | dvr_playback_video_start((DVR_PlaybackHandle_t)player, &vparams); |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 2243 | break; |
| 2244 | case DVR_PLAYBACK_CMD_VSTOPARESTART: |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 2245 | dvr_playback_video_stop((DVR_PlaybackHandle_t)player); |
| 2246 | dvr_playback_audio_stop((DVR_PlaybackHandle_t)player); |
hualing chen | df118dd | 2020-05-21 15:49:11 +0800 | [diff] [blame] | 2247 | dvr_playback_audio_start((DVR_PlaybackHandle_t)player, &aparams, &adparams); |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 2248 | break; |
| 2249 | case DVR_PLAYBACK_CMD_STOP: |
| 2250 | break; |
| 2251 | case DVR_PLAYBACK_CMD_START: |
| 2252 | break; |
| 2253 | case DVR_PLAYBACK_CMD_ASTARTVRESTART: |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 2254 | dvr_playback_video_stop((DVR_PlaybackHandle_t)player); |
| 2255 | dvr_playback_video_start((DVR_PlaybackHandle_t)player, &vparams); |
hualing chen | df118dd | 2020-05-21 15:49:11 +0800 | [diff] [blame] | 2256 | dvr_playback_audio_start((DVR_PlaybackHandle_t)player, &aparams, &adparams); |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 2257 | break; |
| 2258 | case DVR_PLAYBACK_CMD_VSTARTARESTART: |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 2259 | dvr_playback_audio_stop((DVR_PlaybackHandle_t)player); |
| 2260 | dvr_playback_video_start((DVR_PlaybackHandle_t)player, &vparams); |
hualing chen | df118dd | 2020-05-21 15:49:11 +0800 | [diff] [blame] | 2261 | dvr_playback_audio_start((DVR_PlaybackHandle_t)player, &aparams, &adparams); |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 2262 | break; |
| 2263 | case DVR_PLAYBACK_CMD_FF: |
| 2264 | case DVR_PLAYBACK_CMD_FB: |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 2265 | _dvr_playback_fffb((DVR_PlaybackHandle_t)player); |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 2266 | break; |
| 2267 | default: |
| 2268 | break; |
| 2269 | } |
| 2270 | return DVR_SUCCESS; |
| 2271 | } |
| 2272 | |
| 2273 | /**\brief Resume play |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 2274 | * \param[in] handle playback handle |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 2275 | * \retval DVR_SUCCESS On success |
| 2276 | * \return Error code |
| 2277 | */ |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 2278 | int dvr_playback_resume(DVR_PlaybackHandle_t handle) { |
| 2279 | DVR_Playback_t *player = (DVR_Playback_t *) handle; |
| 2280 | |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 2281 | if (player == NULL) { |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 2282 | DVR_PB_DG(1, "player is NULL"); |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 2283 | return DVR_FAILURE; |
| 2284 | } |
| 2285 | |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 2286 | if (player->cmd.cur_cmd == DVR_PLAYBACK_CMD_PAUSE) { |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 2287 | DVR_PB_DG(1, "lock"); |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 2288 | pthread_mutex_lock(&player->lock); |
hualing chen | 266b950 | 2020-04-04 17:39:39 +0800 | [diff] [blame] | 2289 | if (player->has_video) { |
hualing chen | f00cdc8 | 2020-06-10 14:23:35 +0800 | [diff] [blame] | 2290 | DVR_PB_DG(1, "dvr_playback_resume set trick mode none"); |
hualing chen | 266b950 | 2020-04-04 17:39:39 +0800 | [diff] [blame] | 2291 | AmTsPlayer_setTrickMode(player->handle, AV_VIDEO_TRICK_MODE_NONE); |
| 2292 | AmTsPlayer_resumeVideoDecoding(player->handle); |
| 2293 | } |
| 2294 | if (player->has_audio) { |
| 2295 | AmTsPlayer_resumeAudioDecoding(player->handle); |
| 2296 | } |
| 2297 | //check is has audio param,if has audio .we need start audio, |
| 2298 | //we will stop audio when ff fb, if reach end, we will pause.so we need |
| 2299 | //start audio when resume play |
| 2300 | |
| 2301 | am_tsplayer_video_params vparams; |
| 2302 | am_tsplayer_audio_params aparams; |
hualing chen | df118dd | 2020-05-21 15:49:11 +0800 | [diff] [blame] | 2303 | am_tsplayer_audio_params adparams; |
hualing chen | 266b950 | 2020-04-04 17:39:39 +0800 | [diff] [blame] | 2304 | uint64_t segmentid = player->cur_segment_id; |
hualing chen | df118dd | 2020-05-21 15:49:11 +0800 | [diff] [blame] | 2305 | _dvr_playback_get_playinfo(handle, segmentid, &vparams, &aparams, &adparams); |
hualing chen | 266b950 | 2020-04-04 17:39:39 +0800 | [diff] [blame] | 2306 | //valid audio pid, start audio |
hualing chen | c70a8df | 2020-05-12 19:23:11 +0800 | [diff] [blame] | 2307 | if (player->has_audio == DVR_FALSE && VALID_PID(aparams.pid) && (player->cmd.speed.speed.speed == PLAYBACK_SPEED_X1)) { |
hualing chen | 266b950 | 2020-04-04 17:39:39 +0800 | [diff] [blame] | 2308 | player->has_audio = DVR_TRUE; |
| 2309 | AmTsPlayer_setAudioParams(player->handle, &aparams); |
| 2310 | AmTsPlayer_startAudioDecoding(player->handle); |
| 2311 | } else { |
hualing chen | c70a8df | 2020-05-12 19:23:11 +0800 | [diff] [blame] | 2312 | DVR_PB_DG(1, "aparams.pid:%d player->has_audio:%d speed:%d", aparams.pid, player->has_audio, player->cmd.speed.speed.speed); |
hualing chen | 266b950 | 2020-04-04 17:39:39 +0800 | [diff] [blame] | 2313 | } |
hualing chen | df118dd | 2020-05-21 15:49:11 +0800 | [diff] [blame] | 2314 | |
| 2315 | if (player->has_ad_audio == DVR_FALSE && VALID_PID(adparams.pid) && (player->cmd.speed.speed.speed == PLAYBACK_SPEED_X1)) { |
| 2316 | player->has_ad_audio = DVR_TRUE; |
| 2317 | DVR_PB_DG(1, "start ad audio"); |
| 2318 | AmTsPlayer_setADParams(player->handle, &adparams); |
| 2319 | AmTsPlayer_enableADMix(player->handle); |
| 2320 | } |
| 2321 | |
hualing chen | 87072a8 | 2020-03-12 16:20:12 +0800 | [diff] [blame] | 2322 | if (player->cmd.cur_cmd == DVR_PLAYBACK_CMD_FF || |
| 2323 | player->cmd.cur_cmd == DVR_PLAYBACK_CMD_FB) { |
| 2324 | player->cmd.state = DVR_PLAYBACK_STATE_START; |
| 2325 | player->state = DVR_PLAYBACK_STATE_START; |
| 2326 | } else { |
| 2327 | player->cmd.last_cmd = player->cmd.cur_cmd; |
| 2328 | player->cmd.cur_cmd = DVR_PLAYBACK_CMD_RESUME; |
| 2329 | player->cmd.state = DVR_PLAYBACK_STATE_START; |
| 2330 | player->state = DVR_PLAYBACK_STATE_START; |
| 2331 | } |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 2332 | DVR_PB_DG(1, "unlock"); |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 2333 | pthread_mutex_unlock(&player->lock); |
hualing chen | 041c409 | 2020-04-05 15:11:50 +0800 | [diff] [blame] | 2334 | } else if (player->state == DVR_PLAYBACK_STATE_PAUSE){ |
hualing chen | e41f437 | 2020-06-06 16:29:17 +0800 | [diff] [blame] | 2335 | if (player->has_video) { |
hualing chen | f00cdc8 | 2020-06-10 14:23:35 +0800 | [diff] [blame] | 2336 | DVR_PB_DG(1, "dvr_playback_resume set trick mode none 1"); |
hualing chen | e41f437 | 2020-06-06 16:29:17 +0800 | [diff] [blame] | 2337 | AmTsPlayer_setTrickMode(player->handle, AV_VIDEO_TRICK_MODE_NONE); |
hualing chen | 041c409 | 2020-04-05 15:11:50 +0800 | [diff] [blame] | 2338 | AmTsPlayer_resumeVideoDecoding(player->handle); |
hualing chen | e41f437 | 2020-06-06 16:29:17 +0800 | [diff] [blame] | 2339 | } |
hualing chen | 041c409 | 2020-04-05 15:11:50 +0800 | [diff] [blame] | 2340 | if (player->has_audio) |
| 2341 | AmTsPlayer_resumeAudioDecoding(player->handle); |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 2342 | DVR_PB_DG(1, "set start state cur cmd[%d]", player->cmd.cur_cmd); |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 2343 | player->cmd.state = DVR_PLAYBACK_STATE_START; |
| 2344 | player->state = DVR_PLAYBACK_STATE_START; |
hualing chen | 9811b21 | 2020-10-29 11:21:44 +0800 | [diff] [blame] | 2345 | if (player->cmd.speed.speed.speed == PLAYBACK_SPEED_X1) |
| 2346 | _dvr_cmd(handle, player->cmd.cur_cmd); |
hualing chen | 041c409 | 2020-04-05 15:11:50 +0800 | [diff] [blame] | 2347 | } else { |
| 2348 | if ((player->play_flag&DVR_PLAYBACK_STARTED_PAUSEDLIVE) == DVR_PLAYBACK_STARTED_PAUSEDLIVE) |
| 2349 | { |
| 2350 | pthread_mutex_lock(&player->lock); |
| 2351 | //clear flag |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 2352 | DVR_PB_DG(1, "clear pause live flag cur cmd[%d]", player->cmd.cur_cmd); |
hualing chen | 041c409 | 2020-04-05 15:11:50 +0800 | [diff] [blame] | 2353 | player->play_flag = player->play_flag & (~DVR_PLAYBACK_STARTED_PAUSEDLIVE); |
| 2354 | AmTsPlayer_setTrickMode(player->handle, AV_VIDEO_TRICK_MODE_NONE); |
hualing chen | 05d0943 | 2021-01-25 15:26:55 +0800 | [diff] [blame] | 2355 | if (player->has_video) { |
| 2356 | AmTsPlayer_resumeVideoDecoding(player->handle); |
| 2357 | } |
| 2358 | if (player->has_audio) |
| 2359 | AmTsPlayer_resumeAudioDecoding(player->handle); |
| 2360 | |
hualing chen | 041c409 | 2020-04-05 15:11:50 +0800 | [diff] [blame] | 2361 | pthread_mutex_unlock(&player->lock); |
| 2362 | } |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 2363 | } |
| 2364 | return DVR_SUCCESS; |
| 2365 | } |
| 2366 | |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 2367 | static DVR_Bool_t _dvr_check_playinfo_changed(DVR_PlaybackHandle_t handle, int segment_id, int set_seg_id){ |
| 2368 | |
| 2369 | DVR_Playback_t *player = (DVR_Playback_t *) handle; |
| 2370 | DVR_PlaybackSegmentInfo_t *segment = NULL; |
| 2371 | DVR_PlaybackSegmentInfo_t *cur_segment = NULL; |
| 2372 | DVR_PlaybackSegmentInfo_t *set_segment = NULL; |
| 2373 | |
| 2374 | list_for_each_entry(segment, &player->segment_list, head) |
| 2375 | { |
| 2376 | if (segment->segment_id == segment_id) { |
| 2377 | cur_segment = segment; |
| 2378 | } |
| 2379 | if (segment->segment_id == set_seg_id) { |
| 2380 | set_segment = segment; |
| 2381 | } |
| 2382 | if (cur_segment != NULL && set_segment != NULL) { |
| 2383 | break; |
| 2384 | } |
| 2385 | } |
| 2386 | if (cur_segment == NULL || set_segment == NULL) { |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 2387 | DVR_PB_DG(1, "set segmen or cur segment is null"); |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 2388 | return DVR_TRUE; |
| 2389 | } |
| 2390 | if (cur_segment->pids.video.format != set_segment->pids.video.format || |
| 2391 | cur_segment->pids.video.pid != set_segment->pids.video.pid || |
| 2392 | cur_segment->pids.audio.format != set_segment->pids.audio.format || |
| 2393 | cur_segment->pids.audio.pid != set_segment->pids.audio.pid) { |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 2394 | DVR_PB_DG(1, "cur v[%d]a[%d] set v[%d]a[%d]",cur_segment->pids.video.pid,cur_segment->pids.audio.pid,set_segment->pids.video.pid,set_segment->pids.audio.pid); |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 2395 | return DVR_TRUE; |
| 2396 | } |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 2397 | DVR_PB_DG(1, "play info not change"); |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 2398 | return DVR_FALSE; |
| 2399 | } |
| 2400 | |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 2401 | /**\brief seek |
| 2402 | * \param[in] handle playback handle |
| 2403 | * \param[in] time_offset time offset base cur segment |
| 2404 | * \retval DVR_SUCCESS On success |
| 2405 | * \return Error code |
| 2406 | */ |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame] | 2407 | int dvr_playback_seek(DVR_PlaybackHandle_t handle, uint64_t segment_id, uint32_t time_offset) { |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 2408 | DVR_Playback_t *player = (DVR_Playback_t *) handle; |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 2409 | |
| 2410 | if (player == NULL) { |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 2411 | DVR_PB_DG(1, "player is NULL"); |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 2412 | return DVR_FAILURE; |
| 2413 | } |
| 2414 | |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 2415 | DVR_PB_DG(1, "lock segment_id %llu cur id %llu time_offset %u cur end: %d player->state:%d", segment_id,player->cur_segment_id, (uint32_t)time_offset, _dvr_get_end_time(handle), player->state); |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 2416 | pthread_mutex_lock(&player->lock); |
hualing chen | 87072a8 | 2020-03-12 16:20:12 +0800 | [diff] [blame] | 2417 | |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 2418 | int offset = -1; |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 2419 | DVR_Bool_t replay = _dvr_check_playinfo_changed(handle, player->cur_segment_id, segment_id); |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 2420 | DVR_PB_DG(1, "player->state[%d]-replay[%d]--get lock-", player->state, replay); |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 2421 | |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 2422 | //open segment if id is not current segment |
hualing chen | 87072a8 | 2020-03-12 16:20:12 +0800 | [diff] [blame] | 2423 | int ret = _dvr_open_segment(handle, segment_id); |
| 2424 | if (ret ==DVR_FAILURE) { |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 2425 | DVR_PB_DG(1, "seek error at open segment"); |
hualing chen | 87072a8 | 2020-03-12 16:20:12 +0800 | [diff] [blame] | 2426 | pthread_mutex_unlock(&player->lock); |
| 2427 | return DVR_FAILURE; |
| 2428 | } |
| 2429 | if (time_offset >_dvr_get_end_time(handle) &&_dvr_has_next_segmentId(handle, segment_id) == DVR_FAILURE) { |
| 2430 | if (segment_ongoing(player->r_handle) == DVR_SUCCESS) { |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 2431 | DVR_PB_DG(1, "is ongoing segment when seek end, need return success"); |
hualing chen | 87072a8 | 2020-03-12 16:20:12 +0800 | [diff] [blame] | 2432 | //pthread_mutex_unlock(&player->lock); |
| 2433 | //return DVR_SUCCESS; |
| 2434 | time_offset = _dvr_get_end_time(handle); |
| 2435 | } else { |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 2436 | DVR_PB_DG(1, "is not ongoing segment when seek end, return failure"); |
hualing chen | e41f437 | 2020-06-06 16:29:17 +0800 | [diff] [blame] | 2437 | time_offset = _dvr_get_end_time(handle); |
hualing chen | 87072a8 | 2020-03-12 16:20:12 +0800 | [diff] [blame] | 2438 | pthread_mutex_unlock(&player->lock); |
| 2439 | return DVR_FAILURE; |
| 2440 | } |
| 2441 | } |
| 2442 | |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 2443 | DVR_PB_DG(1, "seek open id[%lld]flag[0x%x] time_offset %u", player->cur_segment.segment_id, player->cur_segment.flags, time_offset); |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 2444 | //get file offset by time |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 2445 | if (player->cmd.cur_cmd == DVR_PLAYBACK_CMD_FB) { |
| 2446 | //forward playback.not seek end of file |
| 2447 | if (time_offset != 0 && time_offset > FB_DEFAULT_LEFT_TIME) { |
| 2448 | //default -2000ms |
| 2449 | time_offset = time_offset -FB_DEFAULT_LEFT_TIME; |
| 2450 | } |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 2451 | } |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 2452 | pthread_mutex_lock(&player->segment_lock); |
hualing chen | 266b950 | 2020-04-04 17:39:39 +0800 | [diff] [blame] | 2453 | player->drop_ts = DVR_TRUE; |
hualing chen | 5605eed | 2020-05-26 18:18:06 +0800 | [diff] [blame] | 2454 | player->ts_cache_len = 0; |
hualing chen | 266b950 | 2020-04-04 17:39:39 +0800 | [diff] [blame] | 2455 | offset = segment_seek(player->r_handle, (uint64_t)time_offset, player->openParams.block_size); |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 2456 | DVR_PB_DG(0, "seek get offset by time offset, offset=%d time_offset %u",offset, time_offset); |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 2457 | pthread_mutex_unlock(&player->segment_lock); |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 2458 | player->offset = offset; |
hualing chen | 87072a8 | 2020-03-12 16:20:12 +0800 | [diff] [blame] | 2459 | |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 2460 | _dvr_get_end_time(handle); |
Zhiqiang Han | 8e4e6db | 2020-05-15 10:52:20 +0800 | [diff] [blame] | 2461 | |
| 2462 | player->last_send_time_id = UINT64_MAX; |
| 2463 | |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 2464 | //init fffb time |
hualing chen | 87072a8 | 2020-03-12 16:20:12 +0800 | [diff] [blame] | 2465 | player->fffb_current = _dvr_time_getClock(); |
| 2466 | player->fffb_start = player->fffb_current; |
| 2467 | player->fffb_start_pcr = _dvr_get_cur_time(handle); |
| 2468 | player->next_fffb_time = player->fffb_current; |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 2469 | //pause state if need to replayer false |
hualing chen | 3962821 | 2020-05-14 10:35:13 +0800 | [diff] [blame] | 2470 | if (player->state == DVR_PLAYBACK_STATE_STOP) { |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 2471 | //only seek file,not start |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 2472 | DVR_PB_DG(1, "unlock"); |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame] | 2473 | pthread_mutex_unlock(&player->lock); |
hualing chen | 87072a8 | 2020-03-12 16:20:12 +0800 | [diff] [blame] | 2474 | return DVR_SUCCESS; |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 2475 | } |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 2476 | //stop play |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 2477 | DVR_PB_DG(0, "seek stop play, not inject data has video[%d]audio[%d]", player->has_video, player->has_audio); |
hualing chen | 266b950 | 2020-04-04 17:39:39 +0800 | [diff] [blame] | 2478 | if (player->has_video) { |
| 2479 | player->has_video = DVR_FALSE; |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 2480 | AmTsPlayer_stopVideoDecoding(player->handle); |
hualing chen | 266b950 | 2020-04-04 17:39:39 +0800 | [diff] [blame] | 2481 | } |
| 2482 | |
| 2483 | if (player->has_audio) { |
| 2484 | player->has_audio =DVR_FALSE; |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 2485 | AmTsPlayer_stopAudioDecoding(player->handle); |
hualing chen | 266b950 | 2020-04-04 17:39:39 +0800 | [diff] [blame] | 2486 | } |
hualing chen | df118dd | 2020-05-21 15:49:11 +0800 | [diff] [blame] | 2487 | if (player->has_ad_audio) { |
| 2488 | player->has_ad_audio =DVR_FALSE; |
| 2489 | AmTsPlayer_disableADMix(player->handle); |
| 2490 | } |
| 2491 | |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 2492 | //start play |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 2493 | am_tsplayer_video_params vparams; |
| 2494 | am_tsplayer_audio_params aparams; |
hualing chen | df118dd | 2020-05-21 15:49:11 +0800 | [diff] [blame] | 2495 | am_tsplayer_audio_params adparams; |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 2496 | |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 2497 | player->cur_segment_id = segment_id; |
| 2498 | |
| 2499 | int sync = DVR_PLAYBACK_SYNC; |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 2500 | //get segment info and audio video pid fmt ; |
hualing chen | df118dd | 2020-05-21 15:49:11 +0800 | [diff] [blame] | 2501 | _dvr_playback_get_playinfo(handle, segment_id, &vparams, &aparams, &adparams); |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 2502 | //start audio and video |
Zhiqiang Han | 9adc972 | 2020-11-11 18:38:10 +0800 | [diff] [blame] | 2503 | if (vparams.pid != 0x2fff && !VALID_PID(vparams.pid) && !VALID_PID(aparams.pid)) { |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 2504 | //audio abnd video pis is all invalid, return error. |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 2505 | DVR_PB_DG(0, "unlock seek start dvr play back start error, not found audio and video info"); |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 2506 | pthread_mutex_unlock(&player->lock); |
| 2507 | return -1; |
| 2508 | } |
| 2509 | //add |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 2510 | if (sync == DVR_PLAYBACK_SYNC) { |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 2511 | if (VALID_PID(vparams.pid)) { |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 2512 | //player->has_video; |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 2513 | if (player->cmd.cur_cmd == DVR_PLAYBACK_CMD_PAUSE || |
hualing chen | e41f437 | 2020-06-06 16:29:17 +0800 | [diff] [blame] | 2514 | player->state == DVR_PLAYBACK_STATE_PAUSE || |
hualing chen | df118dd | 2020-05-21 15:49:11 +0800 | [diff] [blame] | 2515 | player->speed > 2.0f|| |
hualing chen | 3114087 | 2020-03-25 12:29:26 +0800 | [diff] [blame] | 2516 | player->speed <= -1.0f) { |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 2517 | //if is pause state. we need set trick mode. |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 2518 | DVR_PB_DG(1, "seek set trick mode player->speed [%f]", player->speed); |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 2519 | AmTsPlayer_setTrickMode(player->handle, AV_VIDEO_TRICK_MODE_PAUSE_NEXT); |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 2520 | } |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 2521 | AmTsPlayer_setVideoParams(player->handle, &vparams); |
| 2522 | AmTsPlayer_startVideoDecoding(player->handle); |
hualing chen | e41f437 | 2020-06-06 16:29:17 +0800 | [diff] [blame] | 2523 | if (IS_KERNEL_SPEED(player->cmd.speed.speed.speed) && |
| 2524 | player->cmd.speed.speed.speed != PLAYBACK_SPEED_X1) { |
| 2525 | AmTsPlayer_startFast(player->handle, (float)player->cmd.speed.speed.speed/(float)100); |
| 2526 | } else if (player->cmd.speed.speed.speed == PLAYBACK_SPEED_X1) { |
| 2527 | AmTsPlayer_stopFast(player->handle); |
| 2528 | } |
hualing chen | 266b950 | 2020-04-04 17:39:39 +0800 | [diff] [blame] | 2529 | player->has_video = DVR_TRUE; |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 2530 | } |
hualing chen | e41f437 | 2020-06-06 16:29:17 +0800 | [diff] [blame] | 2531 | if (VALID_PID(aparams.pid) && player->speed == 1.0) { |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 2532 | DVR_PB_DG(1, "start audio seek"); |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 2533 | AmTsPlayer_setAudioParams(player->handle, &aparams); |
| 2534 | AmTsPlayer_startAudioDecoding(player->handle); |
hualing chen | 266b950 | 2020-04-04 17:39:39 +0800 | [diff] [blame] | 2535 | player->has_audio = DVR_TRUE; |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 2536 | } |
hualing chen | e41f437 | 2020-06-06 16:29:17 +0800 | [diff] [blame] | 2537 | if (VALID_PID(adparams.pid) && player->speed == 1.0) { |
hualing chen | df118dd | 2020-05-21 15:49:11 +0800 | [diff] [blame] | 2538 | player->has_ad_audio = DVR_TRUE; |
| 2539 | DVR_PB_DG(1, "start ad audio"); |
| 2540 | AmTsPlayer_setADParams(player->handle, &adparams); |
| 2541 | AmTsPlayer_enableADMix(player->handle); |
| 2542 | } |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 2543 | } |
hualing chen | e41f437 | 2020-06-06 16:29:17 +0800 | [diff] [blame] | 2544 | if (player->state == DVR_PLAYBACK_STATE_PAUSE /*&& |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 2545 | ((player->cmd.cur_cmd == DVR_PLAYBACK_CMD_FF || |
| 2546 | player->cmd.cur_cmd == DVR_PLAYBACK_CMD_FB) || |
| 2547 | (player->cmd.last_cmd == DVR_PLAYBACK_CMD_FF || |
hualing chen | e41f437 | 2020-06-06 16:29:17 +0800 | [diff] [blame] | 2548 | player->cmd.last_cmd == DVR_PLAYBACK_CMD_FB))*/) { |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 2549 | player->cmd.state = DVR_PLAYBACK_STATE_PAUSE; |
| 2550 | player->state = DVR_PLAYBACK_STATE_PAUSE; |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 2551 | DVR_PB_DG(1, "set state pause in seek"); |
hualing chen | 87072a8 | 2020-03-12 16:20:12 +0800 | [diff] [blame] | 2552 | } else if (player->cmd.cur_cmd == DVR_PLAYBACK_CMD_FF || |
| 2553 | player->cmd.cur_cmd == DVR_PLAYBACK_CMD_FF || |
hualing chen | 3114087 | 2020-03-25 12:29:26 +0800 | [diff] [blame] | 2554 | player->speed > 1.0f|| |
| 2555 | player->speed <= -1.0f) { |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 2556 | DVR_PB_DG(1, "not set cmd to seek"); |
hualing chen | 87072a8 | 2020-03-12 16:20:12 +0800 | [diff] [blame] | 2557 | //not pause state, we need not set cur cmd |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 2558 | } else { |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 2559 | DVR_PB_DG(1, "set cmd to seek"); |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 2560 | player->cmd.last_cmd = player->cmd.cur_cmd; |
| 2561 | player->cmd.cur_cmd = DVR_PLAYBACK_CMD_SEEK; |
| 2562 | player->cmd.state = DVR_PLAYBACK_STATE_START; |
| 2563 | player->state = DVR_PLAYBACK_STATE_START; |
| 2564 | } |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 2565 | player->last_send_time_id = UINT64_MAX; |
| 2566 | DVR_PB_DG(1, "unlock"); |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 2567 | pthread_mutex_unlock(&player->lock); |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 2568 | |
| 2569 | return DVR_SUCCESS; |
| 2570 | } |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 2571 | |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 2572 | static int _dvr_get_cur_time(DVR_PlaybackHandle_t handle) { |
| 2573 | //get cur time of segment |
| 2574 | DVR_Playback_t *player = (DVR_Playback_t *) handle; |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 2575 | |
| 2576 | if (player == NULL || player->handle == NULL) { |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 2577 | DVR_PB_DG(1, "player is NULL"); |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 2578 | return DVR_FAILURE; |
| 2579 | } |
| 2580 | |
hualing chen | 3114087 | 2020-03-25 12:29:26 +0800 | [diff] [blame] | 2581 | int64_t cache = 0;//defalut es buf cache 500ms |
| 2582 | AmTsPlayer_getDelayTime(player->handle, &cache); |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 2583 | pthread_mutex_lock(&player->segment_lock); |
hualing chen | 5605eed | 2020-05-26 18:18:06 +0800 | [diff] [blame] | 2584 | loff_t pos = segment_tell_position(player->r_handle) -player->ts_cache_len; |
| 2585 | uint64_t cur = segment_tell_position_time(player->r_handle, pos); |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 2586 | pthread_mutex_unlock(&player->segment_lock); |
hualing chen | fbf8e02 | 2020-06-15 13:43:11 +0800 | [diff] [blame] | 2587 | DVR_PB_DG(1, "get cur time [%lld] cache:%lld cur id [%lld]last id [%lld] pb cache len [%d] [%lld]", cur, cache, player->cur_segment_id,player->last_send_time_id, player->ts_cache_len, pos); |
hualing chen | 87072a8 | 2020-03-12 16:20:12 +0800 | [diff] [blame] | 2588 | if (player->state == DVR_PLAYBACK_STATE_STOP) { |
| 2589 | cache = 0; |
| 2590 | } |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 2591 | int cur_time = (int)(cur > cache ? cur - cache : 0); |
| 2592 | return cur_time; |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame] | 2593 | } |
| 2594 | |
| 2595 | //get current segment current pcr time of read pos |
| 2596 | static int _dvr_get_end_time(DVR_PlaybackHandle_t handle) { |
| 2597 | //get cur time of segment |
| 2598 | DVR_Playback_t *player = (DVR_Playback_t *) handle; |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 2599 | |
| 2600 | if (player == NULL) { |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 2601 | DVR_PB_DG(1, "player is NULL"); |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 2602 | return DVR_FAILURE; |
| 2603 | } |
| 2604 | |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 2605 | pthread_mutex_lock(&player->segment_lock); |
| 2606 | uint64_t end = segment_tell_total_time(player->r_handle); |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 2607 | DVR_PB_DG(1, "get tatal time [%lld]", end); |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 2608 | pthread_mutex_unlock(&player->segment_lock); |
| 2609 | return (int)end; |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 2610 | } |
| 2611 | |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 2612 | #define FB_MIX_SEEK_TIME 2000 |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 2613 | //start replay |
| 2614 | static int _dvr_playback_calculate_seekpos(DVR_PlaybackHandle_t handle) { |
| 2615 | |
| 2616 | DVR_Playback_t *player = (DVR_Playback_t *) handle; |
| 2617 | //calculate pcr seek time |
| 2618 | int t_diff = 0; |
| 2619 | int seek_time = 0; |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 2620 | |
| 2621 | if (player == NULL) { |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 2622 | DVR_PB_DG(1, "player is NULL"); |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 2623 | return DVR_FAILURE; |
| 2624 | } |
| 2625 | |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 2626 | if (player->fffb_start == -1) { |
| 2627 | //set fffb start time ms |
| 2628 | player->fffb_start = _dvr_time_getClock(); |
| 2629 | player->fffb_current = player->fffb_start; |
| 2630 | //get segment current time pos |
| 2631 | player->fffb_start_pcr = _dvr_get_cur_time(handle); |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 2632 | DVR_PB_DG(1, "calculate seek pos player->fffb_start_pcr[%d]ms, speed[%f]", player->fffb_start_pcr, player->speed); |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 2633 | t_diff = 0; |
hualing chen | e41f437 | 2020-06-06 16:29:17 +0800 | [diff] [blame] | 2634 | //default first time 2s seek |
hualing chen | 87072a8 | 2020-03-12 16:20:12 +0800 | [diff] [blame] | 2635 | seek_time = FB_MIX_SEEK_TIME; |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 2636 | } else { |
| 2637 | player->fffb_current = _dvr_time_getClock(); |
| 2638 | t_diff = player->fffb_current - player->fffb_start; |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 2639 | //if speed is < 0, cmd is fb. |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 2640 | seek_time = player->fffb_start_pcr + t_diff *player->speed; |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 2641 | if (seek_time <= 0) { |
| 2642 | //need seek to pre one segment |
| 2643 | seek_time = 0; |
| 2644 | } |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 2645 | //seek segment pos |
| 2646 | if (player->r_handle) { |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 2647 | pthread_mutex_lock(&player->segment_lock); |
hualing chen | 5605eed | 2020-05-26 18:18:06 +0800 | [diff] [blame] | 2648 | player->ts_cache_len = 0; |
hualing chen | e41f437 | 2020-06-06 16:29:17 +0800 | [diff] [blame] | 2649 | if (seek_time < FB_MIX_SEEK_TIME && IS_FB(player->speed)) { |
| 2650 | //set seek time to 0; |
| 2651 | DVR_PB_DG(1, "segment seek to 0 at fb mode [%d]id[%lld]", seek_time, player->cur_segment_id); |
| 2652 | seek_time = 0; |
| 2653 | } |
hualing chen | 041c409 | 2020-04-05 15:11:50 +0800 | [diff] [blame] | 2654 | if (segment_seek(player->r_handle, seek_time, player->openParams.block_size) == DVR_FAILURE) { |
| 2655 | seek_time = 0; |
| 2656 | } |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 2657 | pthread_mutex_unlock(&player->segment_lock); |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 2658 | } else { |
| 2659 | // |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 2660 | DVR_PB_DG(1, "segment not open,can not seek"); |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 2661 | } |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 2662 | DVR_PB_DG(1, "calculate seek pos seek_time[%d]ms, speed[%f]id[%lld]cur [%d]", seek_time, player->speed,player->cur_segment_id, _dvr_get_cur_time(handle)); |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 2663 | } |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 2664 | return seek_time; |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 2665 | } |
| 2666 | |
| 2667 | |
| 2668 | //start replay |
| 2669 | static int _dvr_playback_fffb_replay(DVR_PlaybackHandle_t handle) { |
| 2670 | // |
| 2671 | DVR_Playback_t *player = (DVR_Playback_t *) handle; |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 2672 | |
| 2673 | if (player == NULL) { |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 2674 | DVR_PB_DG(1, "player is NULL"); |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 2675 | return DVR_FAILURE; |
| 2676 | } |
| 2677 | |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 2678 | //stop |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 2679 | if (player->has_video) { |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 2680 | DVR_PB_DG(1, "fffb stop video"); |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 2681 | AmTsPlayer_stopVideoDecoding(player->handle); |
| 2682 | } |
| 2683 | if (player->has_audio) { |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 2684 | DVR_PB_DG(1, "fffb stop audio"); |
hualing chen | 266b950 | 2020-04-04 17:39:39 +0800 | [diff] [blame] | 2685 | player->has_audio =DVR_FALSE; |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 2686 | AmTsPlayer_stopAudioDecoding(player->handle); |
| 2687 | } |
hualing chen | df118dd | 2020-05-21 15:49:11 +0800 | [diff] [blame] | 2688 | if (player->has_ad_audio) { |
| 2689 | DVR_PB_DG(1, "fffb stop audio"); |
| 2690 | player->has_ad_audio =DVR_FALSE; |
| 2691 | AmTsPlayer_disableADMix(player->handle); |
| 2692 | } |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 2693 | |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 2694 | //start video and audio |
| 2695 | |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 2696 | am_tsplayer_video_params vparams; |
| 2697 | am_tsplayer_audio_params aparams; |
hualing chen | df118dd | 2020-05-21 15:49:11 +0800 | [diff] [blame] | 2698 | am_tsplayer_audio_params adparams; |
hualing chen | 87072a8 | 2020-03-12 16:20:12 +0800 | [diff] [blame] | 2699 | uint64_t segment_id = player->cur_segment_id; |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 2700 | |
| 2701 | //get segment info and audio video pid fmt ; |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame] | 2702 | //pthread_mutex_lock(&player->lock); |
hualing chen | df118dd | 2020-05-21 15:49:11 +0800 | [diff] [blame] | 2703 | _dvr_playback_get_playinfo(handle, segment_id, &vparams, &aparams, &adparams); |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 2704 | //start audio and video |
| 2705 | if (!VALID_PID(vparams.pid) && !VALID_PID(aparams.pid)) { |
| 2706 | //audio abnd video pis is all invalid, return error. |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 2707 | DVR_PB_DG(0, "dvr play back restart error, not found audio and video info"); |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame] | 2708 | //pthread_mutex_unlock(&player->lock); |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 2709 | return -1; |
| 2710 | } |
| 2711 | |
| 2712 | if (VALID_PID(vparams.pid)) { |
| 2713 | player->has_video = DVR_TRUE; |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 2714 | DVR_PB_DG(1, "fffb start video"); |
hualing chen | 0888c03 | 2020-12-18 17:54:57 +0800 | [diff] [blame] | 2715 | //DVR_PB_DG(1, "fffb start video and save last frame"); |
| 2716 | //AmTsPlayer_setVideoBlackOut(player->handle, 0); |
hualing chen | 3114087 | 2020-03-25 12:29:26 +0800 | [diff] [blame] | 2717 | AmTsPlayer_setTrickMode(player->handle, AV_VIDEO_TRICK_MODE_NONE); |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 2718 | AmTsPlayer_setTrickMode(player->handle, AV_VIDEO_TRICK_MODE_PAUSE_NEXT); |
| 2719 | AmTsPlayer_setVideoParams(player->handle, &vparams); |
| 2720 | AmTsPlayer_startVideoDecoding(player->handle); |
| 2721 | //playback_device_video_start(player->handle , &vparams); |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 2722 | //if set flag is pause live, we need set trick mode |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 2723 | //playback_device_trick_mode(player->handle, 1); |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 2724 | } |
hualing chen | 3114087 | 2020-03-25 12:29:26 +0800 | [diff] [blame] | 2725 | //fffb mode need stop fast; |
hualing chen | 7a56cba | 2020-04-14 14:09:27 +0800 | [diff] [blame] | 2726 | DVR_PB_DG(1, "stop fast"); |
hualing chen | 3114087 | 2020-03-25 12:29:26 +0800 | [diff] [blame] | 2727 | AmTsPlayer_stopFast(player->handle); |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame] | 2728 | //pthread_mutex_unlock(&player->lock); |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 2729 | return 0; |
| 2730 | } |
| 2731 | |
| 2732 | static int _dvr_playback_fffb(DVR_PlaybackHandle_t handle) { |
| 2733 | DVR_Playback_t *player = (DVR_Playback_t *) handle; |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 2734 | if (player == NULL) { |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 2735 | DVR_PB_DG(1, "player is NULL"); |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 2736 | return DVR_FAILURE; |
| 2737 | } |
| 2738 | |
| 2739 | player->first_frame = 0; |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 2740 | DVR_PB_DG(1, "lock speed [%f]", player->speed); |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 2741 | pthread_mutex_lock(&player->lock); |
| 2742 | |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 2743 | int seek_time = _dvr_playback_calculate_seekpos(handle); |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 2744 | DVR_PB_DG(1, "get lock speed [%f]id [%lld]seek_time[%d]", player->speed, player->cur_segment_id, seek_time); |
hualing chen | 041c409 | 2020-04-05 15:11:50 +0800 | [diff] [blame] | 2745 | |
hualing chen | 87072a8 | 2020-03-12 16:20:12 +0800 | [diff] [blame] | 2746 | if (_dvr_has_next_segmentId(handle, player->cur_segment_id) == DVR_FAILURE && seek_time < FB_MIX_SEEK_TIME && IS_FB(player->speed)) { |
| 2747 | //seek time set 0 |
| 2748 | seek_time = 0; |
| 2749 | } |
hualing chen | 041c409 | 2020-04-05 15:11:50 +0800 | [diff] [blame] | 2750 | if (seek_time == 0) { |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 2751 | //for fb cmd, we need open pre segment.if reach first one segment, send begin event |
| 2752 | int ret = _change_to_next_segment((DVR_PlaybackHandle_t)player); |
hualing chen | 041c409 | 2020-04-05 15:11:50 +0800 | [diff] [blame] | 2753 | if (ret != DVR_SUCCESS && IS_FB(player->speed)) { |
hualing chen | 87072a8 | 2020-03-12 16:20:12 +0800 | [diff] [blame] | 2754 | pthread_mutex_unlock(&player->lock); |
| 2755 | dvr_playback_pause(handle, DVR_FALSE); |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 2756 | //send event here and pause |
| 2757 | DVR_Play_Notify_t notify; |
| 2758 | memset(¬ify, 0 , sizeof(DVR_Play_Notify_t)); |
hualing chen | 87072a8 | 2020-03-12 16:20:12 +0800 | [diff] [blame] | 2759 | notify.event = DVR_PLAYBACK_EVENT_REACHED_BEGIN; |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 2760 | //get play statue not here |
hualing chen | 2932d37 | 2020-04-29 13:44:00 +0800 | [diff] [blame] | 2761 | _dvr_playback_sent_event(handle, DVR_PLAYBACK_EVENT_REACHED_BEGIN, ¬ify, DVR_TRUE); |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 2762 | DVR_PB_DG(1, "*******************send begin event speed [%f] cur [%d]", player->speed, _dvr_get_cur_time(handle)); |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 2763 | //change to pause |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 2764 | return DVR_SUCCESS; |
| 2765 | } |
hualing chen | 2932d37 | 2020-04-29 13:44:00 +0800 | [diff] [blame] | 2766 | _dvr_playback_sent_transition_ok(handle, DVR_FALSE); |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 2767 | _dvr_init_fffb_time(handle); |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 2768 | DVR_PB_DG(1, "*******************send trans ok event speed [%f]", player->speed); |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 2769 | } |
| 2770 | player->next_fffb_time =_dvr_time_getClock() + FFFB_SLEEP_TIME; |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 2771 | _dvr_playback_fffb_replay(handle); |
| 2772 | |
| 2773 | pthread_mutex_unlock(&player->lock); |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 2774 | DVR_PB_DG(1, "unlock"); |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 2775 | |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 2776 | return DVR_SUCCESS; |
| 2777 | } |
| 2778 | |
hualing chen | 87072a8 | 2020-03-12 16:20:12 +0800 | [diff] [blame] | 2779 | //start replay, need get lock at extern |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 2780 | static int _dvr_playback_replay(DVR_PlaybackHandle_t handle, DVR_Bool_t trick) { |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 2781 | // |
| 2782 | DVR_Playback_t *player = (DVR_Playback_t *) handle; |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 2783 | |
| 2784 | if (player == NULL) { |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 2785 | DVR_PB_DG(1, "player is NULL"); |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 2786 | return DVR_FAILURE; |
| 2787 | } |
| 2788 | |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 2789 | //stop |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 2790 | if (player->has_video) { |
hualing chen | 266b950 | 2020-04-04 17:39:39 +0800 | [diff] [blame] | 2791 | player->has_video = DVR_FALSE; |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 2792 | AmTsPlayer_stopVideoDecoding(player->handle); |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 2793 | } |
| 2794 | |
| 2795 | if (player->has_audio) { |
hualing chen | 266b950 | 2020-04-04 17:39:39 +0800 | [diff] [blame] | 2796 | player->has_audio = DVR_FALSE; |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 2797 | AmTsPlayer_stopAudioDecoding(player->handle); |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 2798 | } |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 2799 | //start video and audio |
| 2800 | |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 2801 | am_tsplayer_video_params vparams; |
| 2802 | am_tsplayer_audio_params aparams; |
hualing chen | df118dd | 2020-05-21 15:49:11 +0800 | [diff] [blame] | 2803 | am_tsplayer_audio_params adparams; |
hualing chen | 87072a8 | 2020-03-12 16:20:12 +0800 | [diff] [blame] | 2804 | uint64_t segment_id = player->cur_segment_id; |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 2805 | |
| 2806 | //get segment info and audio video pid fmt ; |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 2807 | DVR_PB_DG(1, "into"); |
hualing chen | df118dd | 2020-05-21 15:49:11 +0800 | [diff] [blame] | 2808 | _dvr_playback_get_playinfo(handle, segment_id, &vparams, &aparams, &adparams); |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 2809 | //start audio and video |
| 2810 | if (!VALID_PID(vparams.pid) && !VALID_PID(aparams.pid)) { |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 2811 | //audio and video pis is all invalid, return error. |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 2812 | DVR_PB_DG(0, "dvr play back restart error, not found audio and video info"); |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 2813 | return -1; |
| 2814 | } |
| 2815 | |
| 2816 | if (VALID_PID(vparams.pid)) { |
| 2817 | player->has_video = DVR_TRUE; |
hualing chen | 87072a8 | 2020-03-12 16:20:12 +0800 | [diff] [blame] | 2818 | if (trick == DVR_TRUE) { |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 2819 | DVR_PB_DG(1, "settrick mode at replay"); |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 2820 | AmTsPlayer_setTrickMode(player->handle, AV_VIDEO_TRICK_MODE_PAUSE_NEXT); |
hualing chen | 87072a8 | 2020-03-12 16:20:12 +0800 | [diff] [blame] | 2821 | } |
hualing chen | 266b950 | 2020-04-04 17:39:39 +0800 | [diff] [blame] | 2822 | else { |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 2823 | AmTsPlayer_setTrickMode(player->handle, AV_VIDEO_TRICK_MODE_NONE); |
hualing chen | 266b950 | 2020-04-04 17:39:39 +0800 | [diff] [blame] | 2824 | } |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 2825 | AmTsPlayer_setVideoParams(player->handle, &vparams); |
| 2826 | AmTsPlayer_startVideoDecoding(player->handle); |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 2827 | } |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 2828 | |
| 2829 | if (IS_FAST_SPEED(player->cmd.speed.speed.speed)) { |
hualing chen | 7a56cba | 2020-04-14 14:09:27 +0800 | [diff] [blame] | 2830 | DVR_PB_DG(1, "start fast"); |
hualing chen | 3114087 | 2020-03-25 12:29:26 +0800 | [diff] [blame] | 2831 | AmTsPlayer_startFast(player->handle, (float)player->cmd.speed.speed.speed/(float)100); |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 2832 | player->speed = (float)player->cmd.speed.speed.speed/100.0f; |
hualing chen | 3114087 | 2020-03-25 12:29:26 +0800 | [diff] [blame] | 2833 | } else { |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 2834 | if (VALID_PID(aparams.pid)) { |
| 2835 | player->has_audio = DVR_TRUE; |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 2836 | DVR_PB_DG(1, "start audio"); |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 2837 | AmTsPlayer_setAudioParams(player->handle, &aparams); |
Zhiqiang Han | e013e3e | 2020-12-03 13:34:56 +0800 | [diff] [blame] | 2838 | AmTsPlayer_startAudioDecoding(player->handle); |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 2839 | } |
hualing chen | df118dd | 2020-05-21 15:49:11 +0800 | [diff] [blame] | 2840 | if (VALID_PID(adparams.pid)) { |
| 2841 | player->has_ad_audio = DVR_TRUE; |
| 2842 | DVR_PB_DG(1, "start ad audio"); |
| 2843 | AmTsPlayer_setADParams(player->handle, &adparams); |
| 2844 | AmTsPlayer_enableADMix(player->handle); |
| 2845 | } |
| 2846 | |
hualing chen | 7a56cba | 2020-04-14 14:09:27 +0800 | [diff] [blame] | 2847 | DVR_PB_DG(1, "stop fast"); |
hualing chen | 3114087 | 2020-03-25 12:29:26 +0800 | [diff] [blame] | 2848 | AmTsPlayer_stopFast(player->handle); |
| 2849 | player->cmd.speed.speed.speed = PLAYBACK_SPEED_X1; |
| 2850 | player->speed = (float)PLAYBACK_SPEED_X1/100.0f; |
| 2851 | } |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 2852 | player->cmd.last_cmd = player->cmd.cur_cmd; |
| 2853 | player->cmd.cur_cmd = DVR_PLAYBACK_CMD_START; |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 2854 | player->cmd.state = DVR_PLAYBACK_STATE_START; |
| 2855 | player->state = DVR_PLAYBACK_STATE_START; |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 2856 | return 0; |
| 2857 | } |
| 2858 | |
| 2859 | |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 2860 | /**\brief Set play speed |
| 2861 | * \param[in] handle playback handle |
| 2862 | * \param[in] speed playback speed |
| 2863 | * \retval DVR_SUCCESS On success |
| 2864 | * \return Error code |
| 2865 | */ |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 2866 | int dvr_playback_set_speed(DVR_PlaybackHandle_t handle, DVR_PlaybackSpeed_t speed) { |
| 2867 | |
| 2868 | DVR_Playback_t *player = (DVR_Playback_t *) handle; |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 2869 | |
| 2870 | if (player == NULL) { |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 2871 | DVR_PB_DG(1, "player is NULL"); |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 2872 | return DVR_FAILURE; |
| 2873 | } |
| 2874 | |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 2875 | DVR_PB_DG(1, "lock func: speed [%d]", speed.speed.speed); |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 2876 | if (_dvr_support_speed(speed.speed.speed) == DVR_FALSE) { |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 2877 | DVR_PB_DG(1, " func: not support speed [%d]", speed.speed.speed); |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 2878 | return DVR_FAILURE; |
| 2879 | } |
hualing chen | f00cdc8 | 2020-06-10 14:23:35 +0800 | [diff] [blame] | 2880 | if (speed.speed.speed == player->cmd.speed.speed.speed) { |
| 2881 | DVR_PB_DG(1, " func: eq speed [%d]", speed.speed.speed); |
| 2882 | return DVR_SUCCESS; |
| 2883 | } |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 2884 | pthread_mutex_lock(&player->lock); |
| 2885 | if (player->cmd.cur_cmd != DVR_PLAYBACK_CMD_FF |
| 2886 | && player->cmd.cur_cmd != DVR_PLAYBACK_CMD_FB) { |
| 2887 | player->cmd.last_cmd = player->cmd.cur_cmd; |
| 2888 | } |
hualing chen | e41f437 | 2020-06-06 16:29:17 +0800 | [diff] [blame] | 2889 | |
hualing chen | 3114087 | 2020-03-25 12:29:26 +0800 | [diff] [blame] | 2890 | if (player->state != DVR_PLAYBACK_STATE_PAUSE && |
hualing chen | f00cdc8 | 2020-06-10 14:23:35 +0800 | [diff] [blame] | 2891 | IS_KERNEL_SPEED(speed.speed.speed) ) { |
| 2892 | //case 1. not start play.only set speed |
| 2893 | if (player->state == DVR_PLAYBACK_STATE_STOP) { |
| 2894 | //only set speed.and return; |
| 2895 | player->cmd.speed.mode = DVR_PLAYBACK_KERNEL_SUPPORT; |
| 2896 | player->cmd.speed.speed = speed.speed; |
| 2897 | player->speed = (float)speed.speed.speed/(float)100; |
| 2898 | player->fffb_play = DVR_FALSE; |
| 2899 | pthread_mutex_unlock(&player->lock); |
| 2900 | return DVR_SUCCESS; |
| 2901 | } |
| 2902 | //case 2. cur speed is 100,set 200 50 25 12 . |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 2903 | //we think x1 and x2 s1/2 s 1/4 s 1/8 is normal speed. is not ff fb. |
| 2904 | if (IS_KERNEL_SPEED(player->cmd.speed.speed.speed)) { |
hualing chen | 87072a8 | 2020-03-12 16:20:12 +0800 | [diff] [blame] | 2905 | //if last speed is x2 or s2, we need stop fast |
hualing chen | 2bd8a7a | 2020-04-02 11:31:03 +0800 | [diff] [blame] | 2906 | if (speed.speed.speed == PLAYBACK_SPEED_X1) { |
| 2907 | // resume audio and stop fast play |
hualing chen | 7a56cba | 2020-04-14 14:09:27 +0800 | [diff] [blame] | 2908 | DVR_PB_DG(1, "stop fast"); |
hualing chen | 2bd8a7a | 2020-04-02 11:31:03 +0800 | [diff] [blame] | 2909 | AmTsPlayer_stopFast(player->handle); |
| 2910 | pthread_mutex_unlock(&player->lock); |
| 2911 | _dvr_cmd(handle, DVR_PLAYBACK_CMD_ASTART); |
| 2912 | pthread_mutex_lock(&player->lock); |
| 2913 | } else { |
| 2914 | //set play speed and if audio is start, stop audio. |
| 2915 | if (player->has_audio) { |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 2916 | DVR_PB_DG(1, "fast play stop audio"); |
hualing chen | 2bd8a7a | 2020-04-02 11:31:03 +0800 | [diff] [blame] | 2917 | AmTsPlayer_stopAudioDecoding(player->handle); |
| 2918 | player->has_audio = DVR_FALSE; |
| 2919 | } |
hualing chen | b96aa2c | 2020-04-15 14:13:53 +0800 | [diff] [blame] | 2920 | DVR_PB_DG(1, "start fast"); |
hualing chen | 2bd8a7a | 2020-04-02 11:31:03 +0800 | [diff] [blame] | 2921 | AmTsPlayer_startFast(player->handle, (float)speed.speed.speed/(float)100); |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 2922 | } |
hualing chen | bcada02 | 2020-04-22 14:27:01 +0800 | [diff] [blame] | 2923 | player->fffb_play = DVR_FALSE; |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 2924 | player->cmd.speed.mode = DVR_PLAYBACK_KERNEL_SUPPORT; |
hualing chen | 3114087 | 2020-03-25 12:29:26 +0800 | [diff] [blame] | 2925 | player->cmd.speed.speed = speed.speed; |
| 2926 | player->speed = (float)speed.speed.speed/(float)100; |
| 2927 | pthread_mutex_unlock(&player->lock); |
| 2928 | return DVR_SUCCESS; |
| 2929 | } |
hualing chen | 3114087 | 2020-03-25 12:29:26 +0800 | [diff] [blame] | 2930 | //case 3 fffb mode |
| 2931 | if (player->cmd.cur_cmd == DVR_PLAYBACK_CMD_FF || |
| 2932 | player->cmd.cur_cmd == DVR_PLAYBACK_CMD_FB) { |
| 2933 | //restart play at normal speed exit ff fb |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 2934 | DVR_PB_DG(1, "set speed normal and replay playback"); |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 2935 | player->cmd.speed.mode = DVR_PLAYBACK_KERNEL_SUPPORT; |
hualing chen | 3114087 | 2020-03-25 12:29:26 +0800 | [diff] [blame] | 2936 | player->cmd.speed.speed = speed.speed; |
| 2937 | player->speed = (float)speed.speed.speed/(float)100; |
| 2938 | _dvr_playback_replay(handle, DVR_FALSE); |
hualing chen | bcada02 | 2020-04-22 14:27:01 +0800 | [diff] [blame] | 2939 | player->fffb_play = DVR_FALSE; |
hualing chen | 3114087 | 2020-03-25 12:29:26 +0800 | [diff] [blame] | 2940 | pthread_mutex_unlock(&player->lock); |
| 2941 | return DVR_SUCCESS; |
| 2942 | } |
| 2943 | } |
| 2944 | else if (player->state == DVR_PLAYBACK_STATE_PAUSE && |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 2945 | IS_KERNEL_SPEED(speed.speed.speed)) { |
| 2946 | //case 1. cur speed is kernel support speed,set kernel speed. |
| 2947 | if (IS_KERNEL_SPEED(player->cmd.speed.speed.speed)) { |
hualing chen | 3114087 | 2020-03-25 12:29:26 +0800 | [diff] [blame] | 2948 | //if last speed is x2 or s2, we need stop fast |
hualing chen | 2bd8a7a | 2020-04-02 11:31:03 +0800 | [diff] [blame] | 2949 | if (speed.speed.speed == PLAYBACK_SPEED_X1) { |
| 2950 | // resume audio and stop fast play |
hualing chen | 7a56cba | 2020-04-14 14:09:27 +0800 | [diff] [blame] | 2951 | DVR_PB_DG(1, "stop fast"); |
hualing chen | 2bd8a7a | 2020-04-02 11:31:03 +0800 | [diff] [blame] | 2952 | AmTsPlayer_stopFast(player->handle); |
hualing chen | f00cdc8 | 2020-06-10 14:23:35 +0800 | [diff] [blame] | 2953 | player->cmd.cur_cmd = DVR_PLAYBACK_CMD_ASTART; |
hualing chen | 2bd8a7a | 2020-04-02 11:31:03 +0800 | [diff] [blame] | 2954 | } else { |
| 2955 | //set play speed and if audio is start, stop audio. |
| 2956 | if (player->has_audio) { |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 2957 | DVR_PB_DG(1, "fast play stop audio at pause"); |
hualing chen | 2bd8a7a | 2020-04-02 11:31:03 +0800 | [diff] [blame] | 2958 | AmTsPlayer_stopAudioDecoding(player->handle); |
| 2959 | player->has_audio = DVR_FALSE; |
| 2960 | } |
hualing chen | f00cdc8 | 2020-06-10 14:23:35 +0800 | [diff] [blame] | 2961 | DVR_PB_DG(1, "start fast"); |
| 2962 | AmTsPlayer_startFast(player->handle, (float)speed.speed.speed/(float)100); |
hualing chen | 2bd8a7a | 2020-04-02 11:31:03 +0800 | [diff] [blame] | 2963 | } |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 2964 | player->cmd.speed.mode = DVR_PLAYBACK_KERNEL_SUPPORT; |
hualing chen | 3114087 | 2020-03-25 12:29:26 +0800 | [diff] [blame] | 2965 | player->cmd.speed.speed = speed.speed; |
| 2966 | player->speed = (float)speed.speed.speed/(float)100; |
hualing chen | bcada02 | 2020-04-22 14:27:01 +0800 | [diff] [blame] | 2967 | player->fffb_play = DVR_FALSE; |
hualing chen | 3114087 | 2020-03-25 12:29:26 +0800 | [diff] [blame] | 2968 | pthread_mutex_unlock(&player->lock); |
| 2969 | return DVR_SUCCESS; |
| 2970 | } |
| 2971 | //case 2 fffb mode |
| 2972 | if (player->cmd.cur_cmd == DVR_PLAYBACK_CMD_FF || |
| 2973 | player->cmd.cur_cmd == DVR_PLAYBACK_CMD_FB) { |
| 2974 | //restart play at normal speed exit ff fb |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 2975 | DVR_PB_DG(1, "set speed x1 s2 and replay playback"); |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 2976 | player->cmd.speed.mode = DVR_PLAYBACK_KERNEL_SUPPORT; |
hualing chen | 3114087 | 2020-03-25 12:29:26 +0800 | [diff] [blame] | 2977 | player->cmd.speed.speed = speed.speed; |
| 2978 | player->speed = (float)speed.speed.speed/(float)100; |
| 2979 | player->cmd.cur_cmd = DVR_PLAYBACK_CMD_AVRESTART; |
hualing chen | bcada02 | 2020-04-22 14:27:01 +0800 | [diff] [blame] | 2980 | player->fffb_play = DVR_FALSE; |
hualing chen | 3114087 | 2020-03-25 12:29:26 +0800 | [diff] [blame] | 2981 | pthread_mutex_unlock(&player->lock); |
| 2982 | return DVR_SUCCESS; |
| 2983 | } |
hualing chen | 3114087 | 2020-03-25 12:29:26 +0800 | [diff] [blame] | 2984 | } |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 2985 | if (IS_KERNEL_SPEED(speed.speed.speed)) { |
| 2986 | //we think x1 and s2 s4 s8 x2is normal speed. is not ff fb. |
hualing chen | bcada02 | 2020-04-22 14:27:01 +0800 | [diff] [blame] | 2987 | player->fffb_play = DVR_FALSE; |
hualing chen | 87072a8 | 2020-03-12 16:20:12 +0800 | [diff] [blame] | 2988 | } else { |
hualing chen | 3114087 | 2020-03-25 12:29:26 +0800 | [diff] [blame] | 2989 | if ((float)speed.speed.speed > 1.0f) |
hualing chen | 87072a8 | 2020-03-12 16:20:12 +0800 | [diff] [blame] | 2990 | player->cmd.cur_cmd = DVR_PLAYBACK_CMD_FF; |
| 2991 | else |
| 2992 | player->cmd.cur_cmd = DVR_PLAYBACK_CMD_FB; |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 2993 | player->fffb_play = DVR_TRUE; |
| 2994 | } |
| 2995 | DVR_Bool_t init_last_time = DVR_FALSE; |
| 2996 | if (player->speed > 0.0f && speed.speed.speed < 0) { |
| 2997 | init_last_time = DVR_TRUE; |
| 2998 | } else if (player->speed < 0.0f && speed.speed.speed > 0) { |
| 2999 | init_last_time = DVR_TRUE; |
hualing chen | 87072a8 | 2020-03-12 16:20:12 +0800 | [diff] [blame] | 3000 | } |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 3001 | player->cmd.speed.mode = speed.mode; |
| 3002 | player->cmd.speed.speed = speed.speed; |
hualing chen | 3114087 | 2020-03-25 12:29:26 +0800 | [diff] [blame] | 3003 | player->speed = (float)speed.speed.speed/(float)100; |
| 3004 | //reset fffb time, if change speed value |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 3005 | _dvr_init_fffb_t(handle); |
| 3006 | if (init_last_time == DVR_TRUE) |
| 3007 | player->last_send_time_id = UINT64_MAX; |
| 3008 | |
hualing chen | 87072a8 | 2020-03-12 16:20:12 +0800 | [diff] [blame] | 3009 | if (speed.speed.speed == PLAYBACK_SPEED_X1 && |
hualing chen | 6d24aa9 | 2020-03-23 18:43:47 +0800 | [diff] [blame] | 3010 | (player->cmd.cur_cmd == DVR_PLAYBACK_CMD_FF || |
| 3011 | player->cmd.cur_cmd == DVR_PLAYBACK_CMD_FB)) { |
hualing chen | 87072a8 | 2020-03-12 16:20:12 +0800 | [diff] [blame] | 3012 | //restart play at normal speed exit ff fb |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 3013 | DVR_PB_DG(1, "set speed normal and replay playback"); |
hualing chen | 87072a8 | 2020-03-12 16:20:12 +0800 | [diff] [blame] | 3014 | _dvr_playback_replay(handle, DVR_FALSE); |
| 3015 | } else if (speed.speed.speed == PLAYBACK_SPEED_X1 && |
| 3016 | (player->state == DVR_PLAYBACK_STATE_PAUSE)) { |
| 3017 | player->cmd.cur_cmd = DVR_PLAYBACK_CMD_AVRESTART; |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 3018 | DVR_PB_DG(1, "set speed normal at pause state ,set cur cmd"); |
hualing chen | 87072a8 | 2020-03-12 16:20:12 +0800 | [diff] [blame] | 3019 | } |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 3020 | DVR_PB_DG(1, "unlock speed[%f]cmd[%d]", player->speed, player->cmd.cur_cmd); |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 3021 | pthread_mutex_unlock(&player->lock); |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 3022 | return DVR_SUCCESS; |
| 3023 | } |
hualing chen | 2932d37 | 2020-04-29 13:44:00 +0800 | [diff] [blame] | 3024 | |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 3025 | /**\brief Get playback status |
| 3026 | * \param[in] handle playback handle |
| 3027 | * \param[out] p_status playback status |
| 3028 | * \retval DVR_SUCCESS On success |
| 3029 | * \return Error code |
| 3030 | */ |
hualing chen | 2932d37 | 2020-04-29 13:44:00 +0800 | [diff] [blame] | 3031 | static int _dvr_playback_get_status(DVR_PlaybackHandle_t handle, |
| 3032 | DVR_PlaybackStatus_t *p_status, DVR_Bool_t is_lock) { |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 3033 | // |
| 3034 | DVR_Playback_t *player = (DVR_Playback_t *) handle; |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 3035 | |
| 3036 | if (player == NULL) { |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 3037 | DVR_PB_DG(1, "player is NULL"); |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 3038 | return DVR_FAILURE; |
| 3039 | } |
hualing chen | 2932d37 | 2020-04-29 13:44:00 +0800 | [diff] [blame] | 3040 | if (is_lock ==DVR_TRUE) |
| 3041 | pthread_mutex_lock(&player->lock); |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 3042 | p_status->state = player->state; |
hualing chen | 3114087 | 2020-03-25 12:29:26 +0800 | [diff] [blame] | 3043 | //when got first frame we will change to pause state.this only from start play to got first frame |
hualing chen | 87072a8 | 2020-03-12 16:20:12 +0800 | [diff] [blame] | 3044 | if ((player->play_flag&DVR_PLAYBACK_STARTED_PAUSEDLIVE) == DVR_PLAYBACK_STARTED_PAUSEDLIVE && |
| 3045 | player->state == DVR_PLAYBACK_STATE_START) { |
| 3046 | p_status->state = DVR_PLAYBACK_STATE_PAUSE; |
| 3047 | } |
hualing chen | 041c409 | 2020-04-05 15:11:50 +0800 | [diff] [blame] | 3048 | |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame] | 3049 | p_status->time_end = _dvr_get_end_time(handle); |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 3050 | p_status->time_cur = _dvr_get_cur_time(handle); |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 3051 | if (player->last_send_time_id == UINT64_MAX) { |
| 3052 | player->last_send_time_id = player->cur_segment_id; |
| 3053 | player->last_cur_time = p_status->time_cur; |
| 3054 | } |
| 3055 | if (player->last_send_time_id == player->cur_segment_id) { |
| 3056 | if (player->speed > 0.0f ) { |
| 3057 | //ff |
| 3058 | if (p_status->time_cur < player->last_cur_time ) { |
| 3059 | DVR_PB_DG(1, "get ff time error last[%d]cur[%d]diff[%d]", player->last_cur_time, p_status->time_cur, player->last_cur_time - p_status->time_cur); |
| 3060 | p_status->time_cur = player->last_cur_time; |
| 3061 | } else { |
| 3062 | player->last_cur_time = p_status->time_cur; |
| 3063 | } |
hualing chen | e41f437 | 2020-06-06 16:29:17 +0800 | [diff] [blame] | 3064 | } else if (player->speed <= -1.0f){ |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 3065 | //fb |
| 3066 | if (p_status->time_cur > player->last_cur_time ) { |
| 3067 | DVR_PB_DG(1, "get fb time error last[%d]cur[%d]diff[%d]", player->last_cur_time, p_status->time_cur, p_status->time_cur - player->last_cur_time ); |
| 3068 | p_status->time_cur = player->last_cur_time; |
| 3069 | } else { |
| 3070 | player->last_cur_time = p_status->time_cur; |
| 3071 | } |
| 3072 | } |
| 3073 | } else { |
| 3074 | player->last_cur_time = p_status->time_cur; |
| 3075 | } |
| 3076 | player->last_send_time_id = player->cur_segment_id; |
hualing chen | 041c409 | 2020-04-05 15:11:50 +0800 | [diff] [blame] | 3077 | p_status->segment_id = player->cur_segment_id; |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 3078 | |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 3079 | memcpy(&p_status->pids, &player->cur_segment.pids, sizeof(DVR_PlaybackPids_t)); |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame] | 3080 | p_status->speed = player->cmd.speed.speed.speed; |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 3081 | p_status->flags = player->cur_segment.flags; |
hualing chen | 2932d37 | 2020-04-29 13:44:00 +0800 | [diff] [blame] | 3082 | DVR_PB_DG(1, "player real state[%s]state[%s]cur[%d]end[%d] id[%lld]playflag[%d]speed[%f]is_lock[%d]", |
hualing chen | 6d24aa9 | 2020-03-23 18:43:47 +0800 | [diff] [blame] | 3083 | _dvr_playback_state_toString(player->state), |
| 3084 | _dvr_playback_state_toString(p_status->state), |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 3085 | p_status->time_cur, p_status->time_end, |
| 3086 | p_status->segment_id,player->play_flag, |
hualing chen | 2932d37 | 2020-04-29 13:44:00 +0800 | [diff] [blame] | 3087 | player->speed, |
| 3088 | is_lock); |
| 3089 | if (is_lock ==DVR_TRUE) |
| 3090 | pthread_mutex_unlock(&player->lock); |
| 3091 | return DVR_SUCCESS; |
| 3092 | } |
| 3093 | |
| 3094 | |
| 3095 | /**\brief Get playback status |
| 3096 | * \param[in] handle playback handle |
| 3097 | * \param[out] p_status playback status |
| 3098 | * \retval DVR_SUCCESS On success |
| 3099 | * \return Error code |
| 3100 | */ |
| 3101 | int dvr_playback_get_status(DVR_PlaybackHandle_t handle, |
| 3102 | DVR_PlaybackStatus_t *p_status) { |
| 3103 | // |
| 3104 | DVR_Playback_t *player = (DVR_Playback_t *) handle; |
| 3105 | |
Zhiqiang Han | 9adc972 | 2020-11-11 18:38:10 +0800 | [diff] [blame] | 3106 | _dvr_playback_get_status(handle, p_status, DVR_TRUE); |
| 3107 | |
hualing chen | 2932d37 | 2020-04-29 13:44:00 +0800 | [diff] [blame] | 3108 | if (player == NULL) { |
| 3109 | DVR_PB_DG(1, "player is NULL"); |
| 3110 | return DVR_FAILURE; |
| 3111 | } |
Zhiqiang Han | 9adc972 | 2020-11-11 18:38:10 +0800 | [diff] [blame] | 3112 | pthread_mutex_lock(&player->lock); |
| 3113 | if (!player->has_video && !player->has_audio) |
| 3114 | p_status->time_cur = 0; |
| 3115 | pthread_mutex_unlock(&player->lock); |
hualing chen | 2932d37 | 2020-04-29 13:44:00 +0800 | [diff] [blame] | 3116 | |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 3117 | return DVR_SUCCESS; |
| 3118 | } |
| 3119 | |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 3120 | void _dvr_dump_segment(DVR_PlaybackSegmentInfo_t *segment) { |
| 3121 | if (segment != NULL) { |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 3122 | DVR_PB_DG(1, "segment id: %lld", segment->segment_id); |
| 3123 | DVR_PB_DG(1, "segment flag: %d", segment->flags); |
| 3124 | DVR_PB_DG(1, "segment location: [%s]", segment->location); |
| 3125 | DVR_PB_DG(1, "segment vpid: 0x%x vfmt:0x%x", segment->pids.video.pid,segment->pids.video.format); |
| 3126 | DVR_PB_DG(1, "segment apid: 0x%x afmt:0x%x", segment->pids.audio.pid,segment->pids.audio.format); |
| 3127 | DVR_PB_DG(1, "segment pcr pid: 0x%x pcr fmt:0x%x", segment->pids.pcr.pid,segment->pids.pcr.format); |
| 3128 | DVR_PB_DG(1, "segment sub apid: 0x%x sub afmt:0x%x", segment->pids.ad.pid,segment->pids.ad.format); |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 3129 | } |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 3130 | } |
| 3131 | |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 3132 | int dvr_dump_segmentinfo(DVR_PlaybackHandle_t handle, uint64_t segment_id) { |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 3133 | DVR_Playback_t *player = (DVR_Playback_t *) handle; |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 3134 | |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 3135 | if (player == NULL) { |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 3136 | DVR_PB_DG(1, "player is NULL"); |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 3137 | return DVR_FAILURE; |
| 3138 | } |
| 3139 | |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 3140 | DVR_PlaybackSegmentInfo_t *segment; |
| 3141 | list_for_each_entry(segment, &player->segment_list, head) |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 3142 | { |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 3143 | if (segment_id >= 0) { |
| 3144 | if (segment->segment_id == segment_id) { |
| 3145 | _dvr_dump_segment(segment); |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 3146 | break; |
| 3147 | } |
| 3148 | } else { |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 3149 | //printf segment info |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 3150 | _dvr_dump_segment(segment); |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 3151 | } |
| 3152 | } |
| 3153 | return 0; |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 3154 | } |
pengfei.liu | 07ddc8a | 2020-03-24 23:36:53 +0800 | [diff] [blame] | 3155 | |
pengfei.liu | 27cc4ec | 2020-04-03 16:28:16 +0800 | [diff] [blame] | 3156 | int dvr_playback_set_decrypt_callback(DVR_PlaybackHandle_t handle, DVR_CryptoFunction_t func, void *userdata) |
pengfei.liu | 07ddc8a | 2020-03-24 23:36:53 +0800 | [diff] [blame] | 3157 | { |
| 3158 | DVR_Playback_t *player = (DVR_Playback_t *) handle; |
| 3159 | DVR_RETURN_IF_FALSE(player); |
| 3160 | DVR_RETURN_IF_FALSE(func); |
| 3161 | |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 3162 | DVR_PB_DG(1, "in "); |
pengfei.liu | 07ddc8a | 2020-03-24 23:36:53 +0800 | [diff] [blame] | 3163 | pthread_mutex_lock(&player->lock); |
| 3164 | |
| 3165 | player->dec_func = func; |
| 3166 | player->dec_userdata = userdata; |
| 3167 | |
| 3168 | pthread_mutex_unlock(&player->lock); |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 3169 | DVR_PB_DG(1, "out "); |
pengfei.liu | 07ddc8a | 2020-03-24 23:36:53 +0800 | [diff] [blame] | 3170 | return DVR_SUCCESS; |
| 3171 | } |
| 3172 | |
| 3173 | int dvr_playback_set_secure_buffer(DVR_PlaybackHandle_t handle, uint8_t *p_secure_buf, uint32_t len) |
| 3174 | { |
| 3175 | DVR_Playback_t *player = (DVR_Playback_t *) handle; |
| 3176 | DVR_RETURN_IF_FALSE(player); |
| 3177 | DVR_RETURN_IF_FALSE(p_secure_buf); |
| 3178 | DVR_RETURN_IF_FALSE(len); |
| 3179 | |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 3180 | DVR_PB_DG(1, "in "); |
pengfei.liu | 07ddc8a | 2020-03-24 23:36:53 +0800 | [diff] [blame] | 3181 | pthread_mutex_lock(&player->lock); |
| 3182 | |
| 3183 | player->is_secure_mode = 1; |
| 3184 | player->secure_buffer = p_secure_buf; |
| 3185 | player->secure_buffer_size = len; |
| 3186 | |
| 3187 | pthread_mutex_unlock(&player->lock); |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 3188 | DVR_PB_DG(1, "out"); |
pengfei.liu | 07ddc8a | 2020-03-24 23:36:53 +0800 | [diff] [blame] | 3189 | return DVR_SUCCESS; |
| 3190 | } |