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