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