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