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