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 |
hualing chen | 7a56cba | 2020-04-14 14:09:27 +0800 | [diff] [blame^] | 756 | DVR_PB_DG(1, ":last apid: %d set apid: %d", player->last_segment.pids.audio.pid,player->cur_segment.pids.audio.pid); |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame] | 757 | _do_check_pid_info(handle, player->last_segment.pids.audio, player->cur_segment.pids.audio, 1); |
| 758 | //check sub audio pids stop or restart |
| 759 | _do_check_pid_info(handle, player->last_segment.pids.ad, player->cur_segment.pids.ad, 2); |
| 760 | //check pcr pids stop or restart |
| 761 | _do_check_pid_info(handle, player->last_segment.pids.pcr, player->cur_segment.pids.pcr, 3); |
| 762 | } |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 763 | return DVR_SUCCESS; |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame] | 764 | } |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 765 | |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame] | 766 | static int _dvr_check_cur_segment_flag(DVR_PlaybackHandle_t handle) |
| 767 | { |
| 768 | DVR_Playback_t *player = (DVR_Playback_t *) handle; |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 769 | if (player == NULL) { |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 770 | DVR_PB_DG(1, "player is NULL"); |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 771 | return DVR_FAILURE; |
| 772 | } |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 773 | 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] | 774 | if ((player->cur_segment.flags & DVR_PLAYBACK_SEGMENT_DISPLAYABLE) == DVR_PLAYBACK_SEGMENT_DISPLAYABLE && |
| 775 | (player->last_segment.flags & DVR_PLAYBACK_SEGMENT_DISPLAYABLE) == 0) { |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame] | 776 | //enable display |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 777 | DVR_PB_DG(1, "unmute"); |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 778 | AmTsPlayer_showVideo(player->handle); |
| 779 | AmTsPlayer_setAudioMute(player->handle, 0, 0); |
hualing chen | 87072a8 | 2020-03-12 16:20:12 +0800 | [diff] [blame] | 780 | } else if ((player->cur_segment.flags & DVR_PLAYBACK_SEGMENT_DISPLAYABLE) == 0 && |
| 781 | (player->last_segment.flags & DVR_PLAYBACK_SEGMENT_DISPLAYABLE) == DVR_PLAYBACK_SEGMENT_DISPLAYABLE) { |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 782 | //disable display |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 783 | DVR_PB_DG(1, "mute"); |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 784 | AmTsPlayer_hideVideo(player->handle); |
| 785 | AmTsPlayer_setAudioMute(player->handle, 1, 1); |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame] | 786 | } |
| 787 | return DVR_SUCCESS; |
| 788 | } |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 789 | static DVR_Bool_t _dvr_pauselive_decode_sucess(DVR_PlaybackHandle_t handle) { |
| 790 | DVR_Playback_t *player = (DVR_Playback_t *) handle; |
| 791 | if (player == NULL) { |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 792 | DVR_PB_DG(1, "player is NULL"); |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 793 | return DVR_TRUE; |
| 794 | } |
hualing chen | 266b950 | 2020-04-04 17:39:39 +0800 | [diff] [blame] | 795 | if ((player->play_flag&DVR_PLAYBACK_STARTED_PAUSEDLIVE) == DVR_PLAYBACK_STARTED_PAUSEDLIVE) { |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 796 | if (player->first_frame == 1) { |
| 797 | return DVR_TRUE; |
| 798 | } else { |
| 799 | return DVR_FALSE; |
| 800 | } |
| 801 | } else { |
| 802 | return DVR_TRUE; |
| 803 | } |
| 804 | } |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 805 | static void* _dvr_playback_thread(void *arg) |
| 806 | { |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 807 | DVR_Playback_t *player = (DVR_Playback_t *) arg; |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame] | 808 | //int need_open_segment = 1; |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 809 | am_tsplayer_input_buffer wbufs; |
pengfei.liu | 07ddc8a | 2020-03-24 23:36:53 +0800 | [diff] [blame] | 810 | am_tsplayer_input_buffer dec_bufs; |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 811 | int ret = DVR_SUCCESS; |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 812 | |
hualing chen | 6d24aa9 | 2020-03-23 18:43:47 +0800 | [diff] [blame] | 813 | int timeout = 300;//ms |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 814 | uint64_t write_timeout_ms = 50; |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 815 | uint8_t *buf = NULL; |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 816 | 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] | 817 | DVR_Bool_t b_writed_whole_block = player->openParams.block_size > 0 ? DVR_TRUE:DVR_FALSE; |
| 818 | |
pengfei.liu | 07ddc8a | 2020-03-24 23:36:53 +0800 | [diff] [blame] | 819 | int dec_buf_size = buf_len + 188; |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 820 | int real_read = 0; |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 821 | DVR_Bool_t goto_rewrite = DVR_FALSE; |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 822 | |
pengfei.liu | 07ddc8a | 2020-03-24 23:36:53 +0800 | [diff] [blame] | 823 | if (player->is_secure_mode) { |
| 824 | if (dec_buf_size > player->secure_buffer_size) { |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 825 | DVR_PB_DG(1, "playback blocksize too large"); |
pengfei.liu | 07ddc8a | 2020-03-24 23:36:53 +0800 | [diff] [blame] | 826 | return NULL; |
| 827 | } |
| 828 | } |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 829 | buf = malloc(buf_len); |
pengfei.liu | 07ddc8a | 2020-03-24 23:36:53 +0800 | [diff] [blame] | 830 | if (!buf) { |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 831 | DVR_PB_DG(1, "Malloc buffer failed"); |
pengfei.liu | 07ddc8a | 2020-03-24 23:36:53 +0800 | [diff] [blame] | 832 | return NULL; |
| 833 | } |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 834 | wbufs.buf_type = TS_INPUT_BUFFER_TYPE_NORMAL; |
| 835 | wbufs.buf_size = 0; |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame] | 836 | |
pengfei.liu | 07ddc8a | 2020-03-24 23:36:53 +0800 | [diff] [blame] | 837 | dec_bufs.buf_data = malloc(dec_buf_size); |
| 838 | if (!dec_bufs.buf_data) { |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 839 | DVR_PB_DG(1, "Malloc dec buffer failed"); |
pengfei.liu | 07ddc8a | 2020-03-24 23:36:53 +0800 | [diff] [blame] | 840 | return NULL; |
| 841 | } |
| 842 | dec_bufs.buf_type = TS_INPUT_BUFFER_TYPE_NORMAL; |
| 843 | dec_bufs.buf_size = dec_buf_size; |
| 844 | |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame] | 845 | if (player->segment_is_open == DVR_FALSE) { |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 846 | ret = _change_to_next_segment((DVR_PlaybackHandle_t)player); |
| 847 | } |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 848 | |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 849 | if (ret != DVR_SUCCESS) { |
| 850 | if (buf != NULL) { |
| 851 | free(buf); |
| 852 | buf = NULL; |
| 853 | } |
pengfei.liu | 07ddc8a | 2020-03-24 23:36:53 +0800 | [diff] [blame] | 854 | free(dec_bufs.buf_data); |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 855 | DVR_PB_DG(1, "get segment error"); |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 856 | return NULL; |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 857 | } |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame] | 858 | //get play statue not here |
| 859 | _dvr_playback_sent_transition_ok((DVR_PlaybackHandle_t)player); |
| 860 | _dvr_check_cur_segment_flag((DVR_PlaybackHandle_t)player); |
hualing chen | 6d24aa9 | 2020-03-23 18:43:47 +0800 | [diff] [blame] | 861 | //set video show |
| 862 | AmTsPlayer_showVideo(player->handle); |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 863 | |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 864 | int trick_stat = 0; |
| 865 | while (player->is_running/* || player->cmd.last_cmd != player->cmd.cur_cmd*/) { |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 866 | |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 867 | //check trick stat |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame] | 868 | pthread_mutex_lock(&player->lock); |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 869 | |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 870 | if (player->cmd.cur_cmd == DVR_PLAYBACK_CMD_SEEK || |
| 871 | player->cmd.cur_cmd == DVR_PLAYBACK_CMD_FF || |
hualing chen | 3114087 | 2020-03-25 12:29:26 +0800 | [diff] [blame] | 872 | player->cmd.cur_cmd == DVR_PLAYBACK_CMD_FB || |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 873 | player->speed > FF_SPEED ||player->speed <= FB_SPEED || |
hualing chen | 3114087 | 2020-03-25 12:29:26 +0800 | [diff] [blame] | 874 | (player->play_flag&DVR_PLAYBACK_STARTED_PAUSEDLIVE) == DVR_PLAYBACK_STARTED_PAUSEDLIVE) |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 875 | { |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 876 | trick_stat = _dvr_playback_get_trick_stat((DVR_PlaybackHandle_t)player); |
| 877 | if (trick_stat > 0) { |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 878 | DVR_PB_DG(1, "trick stat[%d] is > 0", trick_stat); |
hualing chen | 87072a8 | 2020-03-12 16:20:12 +0800 | [diff] [blame] | 879 | 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] | 880 | //check last cmd |
| 881 | if(player->cmd.last_cmd == DVR_PLAYBACK_CMD_PAUSE |
hualing chen | 3114087 | 2020-03-25 12:29:26 +0800 | [diff] [blame] | 882 | || ((player->play_flag&DVR_PLAYBACK_STARTED_PAUSEDLIVE) == DVR_PLAYBACK_STARTED_PAUSEDLIVE |
hualing chen | 87072a8 | 2020-03-12 16:20:12 +0800 | [diff] [blame] | 883 | && ( player->cmd.cur_cmd == DVR_PLAYBACK_CMD_START |
| 884 | ||player->cmd.last_cmd == DVR_PLAYBACK_CMD_VSTART |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 885 | || player->cmd.last_cmd == DVR_PLAYBACK_CMD_ASTART |
| 886 | || player->cmd.last_cmd == DVR_PLAYBACK_CMD_START))) { |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 887 | DVR_PB_DG(1, "pause play-------"); |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 888 | //need change to pause state |
| 889 | player->cmd.cur_cmd = DVR_PLAYBACK_CMD_PAUSE; |
| 890 | player->cmd.state = DVR_PLAYBACK_STATE_PAUSE; |
hualing chen | 3114087 | 2020-03-25 12:29:26 +0800 | [diff] [blame] | 891 | player->state = DVR_PLAYBACK_STATE_PAUSE; |
hualing chen | 87072a8 | 2020-03-12 16:20:12 +0800 | [diff] [blame] | 892 | //clear flag |
hualing chen | 3114087 | 2020-03-25 12:29:26 +0800 | [diff] [blame] | 893 | player->play_flag = player->play_flag & (~DVR_PLAYBACK_STARTED_PAUSEDLIVE); |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 894 | player->first_frame = 0; |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 895 | AmTsPlayer_pauseVideoDecoding(player->handle); |
| 896 | AmTsPlayer_pauseAudioDecoding(player->handle); |
hualing chen | 2bd8a7a | 2020-04-02 11:31:03 +0800 | [diff] [blame] | 897 | } else { |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 898 | DVR_PB_DG(1, "clear first frame value-------"); |
hualing chen | 2bd8a7a | 2020-04-02 11:31:03 +0800 | [diff] [blame] | 899 | player->first_frame = 0; |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 900 | } |
| 901 | } else if (player->cmd.cur_cmd == DVR_PLAYBACK_CMD_FF |
| 902 | || player->cmd.cur_cmd == DVR_PLAYBACK_CMD_FB |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 903 | ||player->speed > FF_SPEED ||player->speed < FB_SPEED) { |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 904 | //restart play stream if speed > 2 |
| 905 | if (player->state == DVR_PLAYBACK_STATE_PAUSE || |
| 906 | _dvr_time_getClock() < player->next_fffb_time) { |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 907 | 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] | 908 | //used timeout wait need lock first,so we unlock and lock |
| 909 | //pthread_mutex_unlock(&player->lock); |
| 910 | //pthread_mutex_lock(&player->lock); |
| 911 | _dvr_playback_timeoutwait((DVR_PlaybackHandle_t)player, timeout); |
| 912 | pthread_mutex_unlock(&player->lock); |
| 913 | continue; |
| 914 | } |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 915 | 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] | 916 | pthread_mutex_unlock(&player->lock); |
| 917 | goto_rewrite = DVR_FALSE; |
hualing chen | 87072a8 | 2020-03-12 16:20:12 +0800 | [diff] [blame] | 918 | real_read = 0; |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 919 | player->play_flag = player->play_flag & (~DVR_PLAYBACK_STARTED_PAUSEDLIVE); |
| 920 | player->first_frame = 0; |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 921 | _dvr_playback_fffb((DVR_PlaybackHandle_t)player); |
| 922 | pthread_mutex_lock(&player->lock); |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 923 | } |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 924 | }else if (player->fffb_play == DVR_TRUE){ |
| 925 | //for first into fffb when reset speed |
| 926 | if (player->state == DVR_PLAYBACK_STATE_PAUSE || |
| 927 | _dvr_time_getClock() < player->next_fffb_time) { |
| 928 | 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); |
| 929 | //used timeout wait need lock first,so we unlock and lock |
| 930 | //pthread_mutex_unlock(&player->lock); |
| 931 | //pthread_mutex_lock(&player->lock); |
| 932 | _dvr_playback_timeoutwait((DVR_PlaybackHandle_t)player, timeout); |
| 933 | pthread_mutex_unlock(&player->lock); |
| 934 | continue; |
| 935 | } |
| 936 | DVR_PB_DG(1, "fffb replay-------speed[%f][%d][%d]", player->speed, goto_rewrite, real_read); |
| 937 | pthread_mutex_unlock(&player->lock); |
| 938 | goto_rewrite = DVR_FALSE; |
| 939 | real_read = 0; |
| 940 | player->play_flag = player->play_flag & (~DVR_PLAYBACK_STARTED_PAUSEDLIVE); |
| 941 | player->first_frame = 0; |
| 942 | _dvr_playback_fffb((DVR_PlaybackHandle_t)player); |
| 943 | pthread_mutex_lock(&player->lock); |
| 944 | player->fffb_play = DVR_FALSE; |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 945 | } |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 946 | } |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 947 | |
hualing chen | 87072a8 | 2020-03-12 16:20:12 +0800 | [diff] [blame] | 948 | if (player->state == DVR_PLAYBACK_STATE_PAUSE) { |
hualing chen | 6e4bfa5 | 2020-03-13 14:37:11 +0800 | [diff] [blame] | 949 | //check is need send time send end |
| 950 | _dvr_playback_sent_playtime((DVR_PlaybackHandle_t)player); |
hualing chen | 87072a8 | 2020-03-12 16:20:12 +0800 | [diff] [blame] | 951 | _dvr_playback_timeoutwait((DVR_PlaybackHandle_t)player, timeout); |
| 952 | pthread_mutex_unlock(&player->lock); |
| 953 | continue; |
| 954 | } |
hualing chen | 266b950 | 2020-04-04 17:39:39 +0800 | [diff] [blame] | 955 | //when seek action is done. we need drop write timeout data. |
| 956 | if (player->drop_ts == DVR_TRUE) { |
| 957 | goto_rewrite = DVR_FALSE; |
| 958 | real_read = 0; |
| 959 | player->drop_ts = DVR_FALSE; |
| 960 | } |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 961 | if (goto_rewrite == DVR_TRUE) { |
| 962 | goto_rewrite = DVR_FALSE; |
| 963 | pthread_mutex_unlock(&player->lock); |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 964 | //DVR_PB_DG(1, "rewrite-player->speed[%f]", player->speed); |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 965 | goto rewrite; |
| 966 | } |
hualing chen | 6e4bfa5 | 2020-03-13 14:37:11 +0800 | [diff] [blame] | 967 | //.check is need send time send end |
| 968 | _dvr_playback_sent_playtime((DVR_PlaybackHandle_t)player); |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 969 | pthread_mutex_lock(&player->segment_lock); |
hualing chen | 87072a8 | 2020-03-12 16:20:12 +0800 | [diff] [blame] | 970 | 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] | 971 | pthread_mutex_unlock(&player->segment_lock); |
hualing chen | 87072a8 | 2020-03-12 16:20:12 +0800 | [diff] [blame] | 972 | pthread_mutex_unlock(&player->lock); |
| 973 | //if on fb mode and read file end , we need calculate pos to retry read. |
| 974 | if (read == 0 && IS_FB(player->speed) && real_read == 0) { |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 975 | 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] | 976 | _dvr_playback_calculate_seekpos((DVR_PlaybackHandle_t)player); |
| 977 | pthread_mutex_lock(&player->lock); |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 978 | _dvr_playback_timeoutwait((DVR_PlaybackHandle_t)player, timeout); |
| 979 | pthread_mutex_unlock(&player->lock); |
| 980 | continue; |
| 981 | } |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 982 | //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] | 983 | if (read == 0) { |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 984 | //file end.need to play next segment |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 985 | int ret = _change_to_next_segment((DVR_PlaybackHandle_t)player); |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 986 | //init fffb time if change segment |
hualing chen | 041c409 | 2020-04-05 15:11:50 +0800 | [diff] [blame] | 987 | _dvr_init_fffb_time((DVR_PlaybackHandle_t)player); |
hualing chen | 3114087 | 2020-03-25 12:29:26 +0800 | [diff] [blame] | 988 | |
| 989 | int delay = _dvr_playback_get_delaytime((DVR_PlaybackHandle_t)player); |
hualing chen | 041c409 | 2020-04-05 15:11:50 +0800 | [diff] [blame] | 990 | if (ret != DVR_SUCCESS && |
| 991 | (delay <= MIN_TSPLAYER_DELAY_TIME || |
| 992 | delay > MAX_CACHE_TIME || |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 993 | player->cmd.cur_cmd == DVR_PLAYBACK_CMD_FF) && |
hualing chen | 041c409 | 2020-04-05 15:11:50 +0800 | [diff] [blame] | 994 | _dvr_pauselive_decode_sucess((DVR_PlaybackHandle_t)player)) { |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 995 | //send end event to hal |
hualing chen | 3114087 | 2020-03-25 12:29:26 +0800 | [diff] [blame] | 996 | DVR_Play_Notify_t notify; |
| 997 | memset(¬ify, 0 , sizeof(DVR_Play_Notify_t)); |
| 998 | notify.event = DVR_PLAYBACK_EVENT_REACHED_END; |
| 999 | //get play statue not here |
| 1000 | dvr_playback_pause((DVR_PlaybackHandle_t)player, DVR_FALSE); |
hualing chen | 3114087 | 2020-03-25 12:29:26 +0800 | [diff] [blame] | 1001 | _dvr_playback_sent_event((DVR_PlaybackHandle_t)player, DVR_PLAYBACK_EVENT_REACHED_END, ¬ify); |
| 1002 | //continue,timeshift mode, when read end,need wait cur recording segment |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 1003 | DVR_PB_DG(1, "playback is send end delay:[%d]", delay); |
hualing chen | 3114087 | 2020-03-25 12:29:26 +0800 | [diff] [blame] | 1004 | pthread_mutex_lock(&player->lock); |
| 1005 | _dvr_playback_timeoutwait((DVR_PlaybackHandle_t)player, timeout); |
| 1006 | pthread_mutex_unlock(&player->lock); |
| 1007 | continue; |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 1008 | } else if (ret != DVR_SUCCESS) { |
| 1009 | //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] | 1010 | 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] | 1011 | pthread_mutex_lock(&player->lock); |
| 1012 | _dvr_playback_timeoutwait((DVR_PlaybackHandle_t)player, timeout); |
| 1013 | pthread_mutex_unlock(&player->lock); |
| 1014 | continue; |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1015 | } |
hualing chen | 3114087 | 2020-03-25 12:29:26 +0800 | [diff] [blame] | 1016 | //change next segment success case |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame] | 1017 | _dvr_playback_sent_transition_ok((DVR_PlaybackHandle_t)player); |
| 1018 | pthread_mutex_lock(&player->lock); |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 1019 | DVR_PB_DG(1, "_dvr_replay_changed_pid:start"); |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame] | 1020 | _dvr_replay_changed_pid((DVR_PlaybackHandle_t)player); |
| 1021 | _dvr_check_cur_segment_flag((DVR_PlaybackHandle_t)player); |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1022 | 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] | 1023 | pthread_mutex_unlock(&player->lock); |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1024 | } |
| 1025 | real_read = real_read + read; |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 1026 | wbufs.buf_size = real_read; |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 1027 | wbufs.buf_data = buf; |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 1028 | //check read data len,iflen < 0, we need continue |
hualing chen | 7a56cba | 2020-04-14 14:09:27 +0800 | [diff] [blame^] | 1029 | if (wbufs.buf_size <= 0 || wbufs.buf_data == NULL) { |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 1030 | 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] | 1031 | real_read = 0; |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 1032 | continue; |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 1033 | } |
hualing chen | 266b950 | 2020-04-04 17:39:39 +0800 | [diff] [blame] | 1034 | //if need write whole block size, we need check read buf len is eq block size. |
| 1035 | if (b_writed_whole_block == DVR_TRUE) { |
| 1036 | //buf_len is block size value. |
| 1037 | if (real_read < buf_len) { |
| 1038 | //coontinue to read data from file |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 1039 | 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] | 1040 | pthread_mutex_lock(&player->lock); |
| 1041 | _dvr_playback_timeoutwait((DVR_PlaybackHandle_t)player, timeout); |
| 1042 | pthread_mutex_unlock(&player->lock); |
| 1043 | continue; |
| 1044 | } else if (real_read > buf_len) { |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 1045 | 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] | 1046 | } |
| 1047 | } |
| 1048 | |
pengfei.liu | 27cc4ec | 2020-04-03 16:28:16 +0800 | [diff] [blame] | 1049 | if (player->dec_func) { |
| 1050 | DVR_CryptoParams_t crypto_params; |
| 1051 | |
| 1052 | memset(&crypto_params, 0, sizeof(crypto_params)); |
| 1053 | crypto_params.type = DVR_CRYPTO_TYPE_DECRYPT; |
| 1054 | memcpy(crypto_params.location, player->cur_segment.location, strlen(player->cur_segment.location)); |
| 1055 | crypto_params.segment_id = player->cur_segment.segment_id; |
| 1056 | crypto_params.offset = segment_tell_position(player->r_handle); |
| 1057 | |
| 1058 | crypto_params.input_buffer.type = DVR_BUFFER_TYPE_NORMAL; |
| 1059 | crypto_params.input_buffer.addr = (size_t)buf; |
| 1060 | crypto_params.input_buffer.size = real_read; |
| 1061 | |
| 1062 | if (player->is_secure_mode) { |
| 1063 | crypto_params.output_buffer.type = DVR_BUFFER_TYPE_SECURE; |
| 1064 | crypto_params.output_buffer.addr = (size_t)player->secure_buffer; |
| 1065 | crypto_params.output_buffer.size = dec_buf_size; |
| 1066 | ret = player->dec_func(&crypto_params, player->dec_userdata); |
| 1067 | wbufs.buf_data = player->secure_buffer; |
pengfei.liu | fda2a97 | 2020-04-09 14:47:15 +0800 | [diff] [blame] | 1068 | wbufs.buf_type = TS_INPUT_BUFFER_TYPE_SECURE; |
pengfei.liu | 27cc4ec | 2020-04-03 16:28:16 +0800 | [diff] [blame] | 1069 | } else { |
| 1070 | crypto_params.output_buffer.type = DVR_BUFFER_TYPE_NORMAL; |
| 1071 | crypto_params.output_buffer.addr = (size_t)dec_bufs.buf_data; |
| 1072 | crypto_params.output_buffer.size = dec_buf_size; |
| 1073 | ret = player->dec_func(&crypto_params, player->dec_userdata); |
| 1074 | wbufs.buf_data = dec_bufs.buf_data; |
pengfei.liu | fda2a97 | 2020-04-09 14:47:15 +0800 | [diff] [blame] | 1075 | wbufs.buf_type = TS_INPUT_BUFFER_TYPE_NORMAL; |
pengfei.liu | 27cc4ec | 2020-04-03 16:28:16 +0800 | [diff] [blame] | 1076 | } |
| 1077 | if (ret != DVR_SUCCESS) { |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 1078 | DVR_PB_DG(1, "decrypt failed"); |
pengfei.liu | 27cc4ec | 2020-04-03 16:28:16 +0800 | [diff] [blame] | 1079 | } |
pengfei.liu | fda2a97 | 2020-04-09 14:47:15 +0800 | [diff] [blame] | 1080 | wbufs.buf_size = crypto_params.output_size; |
pengfei.liu | 27cc4ec | 2020-04-03 16:28:16 +0800 | [diff] [blame] | 1081 | } |
pengfei.liu | 07ddc8a | 2020-03-24 23:36:53 +0800 | [diff] [blame] | 1082 | rewrite: |
hualing chen | 041c409 | 2020-04-05 15:11:50 +0800 | [diff] [blame] | 1083 | |
pengfei.liu | 07ddc8a | 2020-03-24 23:36:53 +0800 | [diff] [blame] | 1084 | ret = AmTsPlayer_writeData(player->handle, &wbufs, write_timeout_ms); |
| 1085 | if (ret == AM_TSPLAYER_OK) { |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 1086 | real_read = 0; |
| 1087 | write_success++; |
| 1088 | continue; |
hualing chen | 87072a8 | 2020-03-12 16:20:12 +0800 | [diff] [blame] | 1089 | } else { |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 1090 | DVR_PB_DG(1, "write time out write_success:%d", write_success); |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 1091 | write_success = 0; |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame] | 1092 | pthread_mutex_lock(&player->lock); |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 1093 | _dvr_playback_timeoutwait((DVR_PlaybackHandle_t)player, timeout); |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame] | 1094 | pthread_mutex_unlock(&player->lock); |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1095 | if (!player->is_running) { |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 1096 | DVR_PB_DG(1, "playback thread exit"); |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1097 | break; |
| 1098 | } |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 1099 | goto_rewrite = DVR_TRUE; |
| 1100 | //goto rewrite; |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1101 | } |
| 1102 | } |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 1103 | DVR_PB_DG(1, "playback thread is end"); |
pengfei.liu | 07ddc8a | 2020-03-24 23:36:53 +0800 | [diff] [blame] | 1104 | free(buf); |
| 1105 | free(dec_bufs.buf_data); |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1106 | return NULL; |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 1107 | } |
| 1108 | |
| 1109 | |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 1110 | static int _start_playback_thread(DVR_PlaybackHandle_t handle) |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 1111 | { |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 1112 | DVR_Playback_t *player = (DVR_Playback_t *) handle; |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 1113 | |
| 1114 | if (player == NULL) { |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 1115 | DVR_PB_DG(1, "player is NULL"); |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 1116 | return DVR_FAILURE; |
| 1117 | } |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 1118 | DVR_PB_DG(1, "start thread is_running:[%d]", player->is_running); |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame] | 1119 | if (player->is_running == DVR_TRUE) { |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 1120 | return 0; |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1121 | } |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 1122 | player->is_running = DVR_TRUE; |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1123 | 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] | 1124 | if (rc < 0) |
| 1125 | player->is_running = DVR_FALSE; |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1126 | return 0; |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 1127 | } |
| 1128 | |
| 1129 | |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 1130 | static int _stop_playback_thread(DVR_PlaybackHandle_t handle) |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1131 | { |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 1132 | DVR_Playback_t *player = (DVR_Playback_t *) handle; |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 1133 | |
| 1134 | if (player == NULL) { |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 1135 | DVR_PB_DG(1, "player is NULL"); |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 1136 | return DVR_FAILURE; |
| 1137 | } |
| 1138 | |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 1139 | DVR_PB_DG(1, "stopthread------[%d]", player->is_running); |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame] | 1140 | if (player->is_running == DVR_TRUE) |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1141 | { |
| 1142 | player->is_running = DVR_FALSE; |
hualing chen | 87072a8 | 2020-03-12 16:20:12 +0800 | [diff] [blame] | 1143 | _dvr_playback_sendSignal(handle); |
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 | } |
hualing chen | 7a56cba | 2020-04-14 14:09:27 +0800 | [diff] [blame^] | 1150 | DVR_PB_DG(1, ":end"); |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1151 | return 0; |
| 1152 | } |
| 1153 | |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 1154 | /**\brief Open an dvr palyback |
| 1155 | * \param[out] p_handle dvr playback addr |
| 1156 | * \param[in] params dvr playback open parameters |
| 1157 | * \retval DVR_SUCCESS On success |
| 1158 | * \return Error code |
| 1159 | */ |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 1160 | 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] | 1161 | |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 1162 | DVR_Playback_t *player; |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1163 | pthread_condattr_t cattr; |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 1164 | |
Zhiqiang Han | 2d8cd82 | 2020-03-16 13:58:10 +0800 | [diff] [blame] | 1165 | player = (DVR_Playback_t*)calloc(1, sizeof(DVR_Playback_t)); |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 1166 | |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1167 | pthread_mutex_init(&player->lock, NULL); |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 1168 | pthread_mutex_init(&player->segment_lock, NULL); |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1169 | pthread_condattr_init(&cattr); |
| 1170 | pthread_condattr_setclock(&cattr, CLOCK_MONOTONIC); |
| 1171 | pthread_cond_init(&player->cond, &cattr); |
| 1172 | pthread_condattr_destroy(&cattr); |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 1173 | |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 1174 | //init segment list head |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 1175 | INIT_LIST_HEAD(&player->segment_list); |
| 1176 | player->cmd.last_cmd = DVR_PLAYBACK_CMD_STOP; |
| 1177 | player->cmd.cur_cmd = DVR_PLAYBACK_CMD_STOP; |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 1178 | player->cmd.speed.speed.speed = PLAYBACK_SPEED_X1; |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 1179 | player->cmd.state = DVR_PLAYBACK_STATE_STOP; |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 1180 | player->state = DVR_PLAYBACK_STATE_STOP; |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1181 | player->cmd.pos = 0; |
hualing chen | 3114087 | 2020-03-25 12:29:26 +0800 | [diff] [blame] | 1182 | player->speed = 1.0f; |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 1183 | |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1184 | //store open params |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 1185 | player->openParams.dmx_dev_id = params->dmx_dev_id; |
| 1186 | player->openParams.block_size = params->block_size; |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1187 | player->openParams.is_timeshift = params->is_timeshift; |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame] | 1188 | player->openParams.event_fn = params->event_fn; |
| 1189 | player->openParams.event_userdata = params->event_userdata; |
| 1190 | |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 1191 | player->has_pids = params->has_pids; |
| 1192 | |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 1193 | player->handle = params->player_handle ; |
hualing chen | 6e4bfa5 | 2020-03-13 14:37:11 +0800 | [diff] [blame] | 1194 | |
| 1195 | AmTsPlayer_getCb(player->handle, &player->player_callback_func, &player->player_callback_userdata); |
| 1196 | //for test get callback |
| 1197 | if (0 && player->player_callback_func == NULL) { |
| 1198 | AmTsPlayer_registerCb(player->handle, _dvr_tsplayer_callback_test, player); |
| 1199 | AmTsPlayer_getCb(player->handle, &player->player_callback_func, &player->player_callback_userdata); |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 1200 | 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] | 1201 | } |
| 1202 | AmTsPlayer_registerCb(player->handle, _dvr_tsplayer_callback, player); |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 1203 | |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1204 | //init has audio and video |
| 1205 | player->has_video = DVR_FALSE; |
| 1206 | player->has_audio = DVR_FALSE; |
hualing chen | 87072a8 | 2020-03-12 16:20:12 +0800 | [diff] [blame] | 1207 | player->cur_segment_id = UINT64_MAX; |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame] | 1208 | player->last_segment_id = 0LL; |
| 1209 | player->segment_is_open = DVR_FALSE; |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 1210 | |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 1211 | //init ff fb time |
| 1212 | player->fffb_current = -1; |
| 1213 | player->fffb_start =-1; |
| 1214 | player->fffb_start_pcr = -1; |
| 1215 | //seek time |
| 1216 | player->seek_time = 0; |
hualing chen | 6e4bfa5 | 2020-03-13 14:37:11 +0800 | [diff] [blame] | 1217 | player->send_time = 0; |
pengfei.liu | 07ddc8a | 2020-03-24 23:36:53 +0800 | [diff] [blame] | 1218 | |
| 1219 | //init secure stuff |
| 1220 | player->dec_func = NULL; |
| 1221 | player->dec_userdata = NULL; |
| 1222 | player->is_secure_mode = 0; |
| 1223 | player->secure_buffer = NULL; |
| 1224 | player->secure_buffer_size = 0; |
hualing chen | 266b950 | 2020-04-04 17:39:39 +0800 | [diff] [blame] | 1225 | player->drop_ts = DVR_FALSE; |
pengfei.liu | 07ddc8a | 2020-03-24 23:36:53 +0800 | [diff] [blame] | 1226 | |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 1227 | player->fffb_play = DVR_FALSE; |
| 1228 | |
| 1229 | player->last_send_time_id = UINT64_MAX; |
| 1230 | player->last_cur_time = 0; |
| 1231 | |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1232 | *p_handle = player; |
| 1233 | return DVR_SUCCESS; |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 1234 | } |
| 1235 | |
| 1236 | /**\brief Close an dvr palyback |
| 1237 | * \param[in] handle playback handle |
| 1238 | * \retval DVR_SUCCESS On success |
| 1239 | * \return Error code |
| 1240 | */ |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 1241 | int dvr_playback_close(DVR_PlaybackHandle_t handle) { |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 1242 | |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1243 | DVR_ASSERT(handle); |
hualing chen | 7a56cba | 2020-04-14 14:09:27 +0800 | [diff] [blame^] | 1244 | DVR_PB_DG(1, ":into"); |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 1245 | DVR_Playback_t *player = (DVR_Playback_t *) handle; |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 1246 | if (player == NULL) { |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 1247 | DVR_PB_DG(1, "player is NULL"); |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 1248 | return DVR_FAILURE; |
| 1249 | } |
| 1250 | |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame] | 1251 | if (player->state != DVR_PLAYBACK_STATE_STOP) |
| 1252 | { |
| 1253 | dvr_playback_stop(handle, DVR_TRUE); |
| 1254 | } |
hualing chen | 7a56cba | 2020-04-14 14:09:27 +0800 | [diff] [blame^] | 1255 | DVR_PB_DG(1, ":into"); |
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 | 7a56cba | 2020-04-14 14:09:27 +0800 | [diff] [blame^] | 1263 | DVR_PB_DG(1, ":end"); |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1264 | return DVR_SUCCESS; |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 1265 | } |
| 1266 | |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 1267 | /**\brief Start play audio and video, used start auido api and start video api |
| 1268 | * \param[in] handle playback handle |
| 1269 | * \param[in] params audio playback params,contains fmt and pid... |
| 1270 | * \retval DVR_SUCCESS On success |
| 1271 | * \return Error code |
| 1272 | */ |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 1273 | int dvr_playback_start(DVR_PlaybackHandle_t handle, DVR_PlaybackFlag_t flag) { |
| 1274 | DVR_Playback_t *player = (DVR_Playback_t *) handle; |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 1275 | am_tsplayer_video_params vparams; |
| 1276 | am_tsplayer_audio_params aparams; |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 1277 | |
| 1278 | if (player == NULL) { |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 1279 | DVR_PB_DG(1, "player is NULL"); |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 1280 | return DVR_FAILURE; |
| 1281 | } |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame] | 1282 | uint64_t segment_id = player->cur_segment_id; |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 1283 | DVR_PB_DG(1, "[%p]segment_id:[%lld]", handle, segment_id); |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 1284 | |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 1285 | player->first_frame = 0; |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame] | 1286 | //can used start api to resume playback |
| 1287 | if (player->cmd.state == DVR_PLAYBACK_STATE_PAUSE) { |
| 1288 | return dvr_playback_resume(handle); |
| 1289 | } |
hualing chen | 87072a8 | 2020-03-12 16:20:12 +0800 | [diff] [blame] | 1290 | if (player->cmd.state == DVR_PLAYBACK_STATE_START) { |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 1291 | DVR_PB_DG(1, "stat is start, not need into start play"); |
hualing chen | 87072a8 | 2020-03-12 16:20:12 +0800 | [diff] [blame] | 1292 | return DVR_SUCCESS; |
| 1293 | } |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1294 | player->play_flag = flag; |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 1295 | //get segment info and audio video pid fmt ; |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 1296 | DVR_PB_DG(1, "lock flag:0x%x", flag); |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1297 | pthread_mutex_lock(&player->lock); |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 1298 | _dvr_playback_get_playinfo(handle, segment_id, &vparams, &aparams); |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1299 | //start audio and video |
| 1300 | if (!VALID_PID(vparams.pid) && !VALID_PID(aparams.pid)) { |
| 1301 | //audio abnd video pis is all invalid, return error. |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 1302 | 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] | 1303 | pthread_mutex_unlock(&player->lock); |
| 1304 | DVR_Play_Notify_t notify; |
| 1305 | memset(¬ify, 0 , sizeof(DVR_Play_Notify_t)); |
| 1306 | notify.event = DVR_PLAYBACK_EVENT_TRANSITION_FAILED; |
| 1307 | notify.info.error_reason = DVR_PLAYBACK_PID_ERROR; |
| 1308 | notify.info.transition_failed_data.segment_id = segment_id; |
| 1309 | //get play statue not here |
| 1310 | _dvr_playback_sent_event(handle, DVR_PLAYBACK_EVENT_TRANSITION_FAILED, ¬ify); |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1311 | return -1; |
| 1312 | } |
hualing chen | 3114087 | 2020-03-25 12:29:26 +0800 | [diff] [blame] | 1313 | |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame] | 1314 | { |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1315 | if (VALID_PID(vparams.pid)) { |
| 1316 | player->has_video = DVR_TRUE; |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1317 | //if set flag is pause live, we need set trick mode |
hualing chen | 3114087 | 2020-03-25 12:29:26 +0800 | [diff] [blame] | 1318 | if ((player->play_flag&DVR_PLAYBACK_STARTED_PAUSEDLIVE) == DVR_PLAYBACK_STARTED_PAUSEDLIVE) { |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 1319 | DVR_PB_DG(1, "set trick mode -pauselive flag--"); |
hualing chen | 3114087 | 2020-03-25 12:29:26 +0800 | [diff] [blame] | 1320 | AmTsPlayer_setTrickMode(player->handle, AV_VIDEO_TRICK_MODE_PAUSE_NEXT); |
| 1321 | } else if (player->cmd.cur_cmd == DVR_PLAYBACK_CMD_FB |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 1322 | || player->cmd.cur_cmd == DVR_PLAYBACK_CMD_FF) { |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 1323 | DVR_PB_DG(1, "set trick mode -fffb--at pause live"); |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 1324 | AmTsPlayer_setTrickMode(player->handle, AV_VIDEO_TRICK_MODE_PAUSE_NEXT); |
hualing chen | 87072a8 | 2020-03-12 16:20:12 +0800 | [diff] [blame] | 1325 | } else { |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 1326 | DVR_PB_DG(1, "set trick mode ---none"); |
hualing chen | 87072a8 | 2020-03-12 16:20:12 +0800 | [diff] [blame] | 1327 | AmTsPlayer_setTrickMode(player->handle, AV_VIDEO_TRICK_MODE_NONE); |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 1328 | } |
| 1329 | AmTsPlayer_setVideoParams(player->handle, &vparams); |
| 1330 | AmTsPlayer_startVideoDecoding(player->handle); |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 1331 | } |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 1332 | |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 1333 | DVR_PB_DG(1, "player->cmd.cur_cmd:%d vpid[0x%x]apis[0x%x]", player->cmd.cur_cmd, vparams.pid, aparams.pid); |
| 1334 | player->last_send_time_id = UINT64_MAX; |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame] | 1335 | if (player->cmd.cur_cmd == DVR_PLAYBACK_CMD_FB |
| 1336 | || player->cmd.cur_cmd == DVR_PLAYBACK_CMD_FF) { |
| 1337 | player->cmd.state = DVR_PLAYBACK_STATE_START; |
| 1338 | player->state = DVR_PLAYBACK_STATE_START; |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame] | 1339 | } else { |
| 1340 | player->cmd.last_cmd = player->cmd.cur_cmd; |
| 1341 | player->cmd.cur_cmd = DVR_PLAYBACK_CMD_START; |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 1342 | if (IS_FAST_SPEED(player->cmd.speed.speed.speed)) { |
hualing chen | 3114087 | 2020-03-25 12:29:26 +0800 | [diff] [blame] | 1343 | //set fast play |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 1344 | DVR_PB_DG(1, "dvr start fast mode"); |
hualing chen | 3114087 | 2020-03-25 12:29:26 +0800 | [diff] [blame] | 1345 | AmTsPlayer_startFast(player->handle, (float)player->cmd.speed.speed.speed/100.0f); |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 1346 | } else { |
| 1347 | if (VALID_PID(aparams.pid)) { |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 1348 | DVR_PB_DG(1, "start audio"); |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 1349 | player->has_audio = DVR_TRUE; |
| 1350 | AmTsPlayer_setAudioParams(player->handle, &aparams); |
| 1351 | AmTsPlayer_startAudioDecoding(player->handle); |
| 1352 | } |
hualing chen | 3114087 | 2020-03-25 12:29:26 +0800 | [diff] [blame] | 1353 | } |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame] | 1354 | player->cmd.state = DVR_PLAYBACK_STATE_START; |
| 1355 | player->state = DVR_PLAYBACK_STATE_START; |
| 1356 | } |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1357 | } |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 1358 | DVR_PB_DG(1, "unlock"); |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1359 | pthread_mutex_unlock(&player->lock); |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 1360 | _start_playback_thread(handle); |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1361 | return DVR_SUCCESS; |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 1362 | } |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 1363 | /**\brief dvr play back add segment info to segment list |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 1364 | * \param[in] handle playback handle |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 1365 | * \param[in] info added segment info,con vpid fmt apid fmt..... |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 1366 | * \retval DVR_SUCCESS On success |
| 1367 | * \return Error code |
| 1368 | */ |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 1369 | int dvr_playback_add_segment(DVR_PlaybackHandle_t handle, DVR_PlaybackSegmentInfo_t *info) { |
| 1370 | DVR_Playback_t *player = (DVR_Playback_t *) handle; |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 1371 | |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 1372 | if (player == NULL) { |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 1373 | DVR_PB_DG(1, "player is NULL"); |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 1374 | return DVR_FAILURE; |
| 1375 | } |
| 1376 | |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 1377 | 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] | 1378 | DVR_PlaybackSegmentInfo_t *segment; |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 1379 | |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 1380 | segment = malloc(sizeof(DVR_PlaybackSegmentInfo_t)); |
| 1381 | memset(segment, 0, sizeof(DVR_PlaybackSegmentInfo_t)); |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 1382 | |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1383 | //not memcpy chun info. |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 1384 | segment->segment_id = info->segment_id; |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1385 | //cp location |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 1386 | memcpy(segment->location, info->location, DVR_MAX_LOCATION_SIZE); |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame] | 1387 | |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 1388 | 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] | 1389 | segment->flags = info->flags; |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 1390 | |
| 1391 | //pids |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame] | 1392 | segment->pids.video.pid = info->pids.video.pid; |
| 1393 | segment->pids.video.format = info->pids.video.format; |
| 1394 | segment->pids.video.type = info->pids.video.type; |
| 1395 | |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 1396 | segment->pids.audio.pid = info->pids.audio.pid; |
| 1397 | segment->pids.audio.format = info->pids.audio.format; |
| 1398 | segment->pids.audio.type = info->pids.audio.type; |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame] | 1399 | |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 1400 | segment->pids.ad.pid = info->pids.ad.pid; |
| 1401 | segment->pids.ad.format = info->pids.ad.format; |
| 1402 | segment->pids.ad.type = info->pids.ad.type; |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame] | 1403 | |
| 1404 | segment->pids.pcr.pid = info->pids.pcr.pid; |
| 1405 | |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 1406 | 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] | 1407 | pthread_mutex_lock(&player->lock); |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 1408 | list_add_tail(&segment->head, &player->segment_list); |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1409 | pthread_mutex_unlock(&player->lock); |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 1410 | DVR_PB_DG(1, "unlock"); |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 1411 | |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 1412 | return DVR_SUCCESS; |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 1413 | } |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 1414 | /**\brief dvr play back remove segment info by segment_id |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 1415 | * \param[in] handle playback handle |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 1416 | * \param[in] segment_id need removed segment id |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 1417 | * \retval DVR_SUCCESS On success |
| 1418 | * \return Error code |
| 1419 | */ |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 1420 | 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] | 1421 | DVR_Playback_t *player = (DVR_Playback_t *) handle; |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 1422 | DVR_PB_DG(1, "remove segment id: %lld", segment_id); |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 1423 | if (player == NULL) { |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 1424 | DVR_PB_DG(1, "player is NULL"); |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 1425 | return DVR_FAILURE; |
| 1426 | } |
| 1427 | |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame] | 1428 | if (segment_id == player->cur_segment_id) { |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 1429 | 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] | 1430 | return DVR_FAILURE; |
| 1431 | } |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 1432 | DVR_PB_DG(1, "lock"); |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1433 | pthread_mutex_lock(&player->lock); |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 1434 | DVR_PlaybackSegmentInfo_t *segment = NULL; |
| 1435 | DVR_PlaybackSegmentInfo_t *segment_tmp = NULL; |
| 1436 | list_for_each_entry_safe(segment, segment_tmp, &player->segment_list, head) |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1437 | { |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 1438 | if (segment->segment_id == segment_id) { |
| 1439 | list_del(&segment->head); |
| 1440 | free(segment); |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1441 | break; |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 1442 | } |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1443 | } |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 1444 | DVR_PB_DG(1, "unlock"); |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1445 | pthread_mutex_unlock(&player->lock); |
| 1446 | |
| 1447 | return DVR_SUCCESS; |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 1448 | } |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 1449 | /**\brief dvr play back add segment info |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 1450 | * \param[in] handle playback handle |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 1451 | * \param[in] info added segment info,con vpid fmt apid fmt..... |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 1452 | * \retval DVR_SUCCESS On success |
| 1453 | * \return Error code |
| 1454 | */ |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 1455 | int dvr_playback_update_segment_flags(DVR_PlaybackHandle_t handle, |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 1456 | uint64_t segment_id, DVR_PlaybackSegmentFlag_t flags) { |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 1457 | DVR_Playback_t *player = (DVR_Playback_t *) handle; |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 1458 | 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] | 1459 | if (player == NULL) { |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 1460 | DVR_PB_DG(1, "player is NULL"); |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 1461 | return DVR_FAILURE; |
| 1462 | } |
| 1463 | |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 1464 | DVR_PlaybackSegmentInfo_t *segment; |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 1465 | DVR_PB_DG(1, "lock"); |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1466 | pthread_mutex_lock(&player->lock); |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 1467 | list_for_each_entry(segment, &player->segment_list, head) |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1468 | { |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 1469 | if (segment->segment_id != segment_id) { |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1470 | continue; |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 1471 | } |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1472 | // if encramble to free, only set flag and return; |
| 1473 | |
| 1474 | //if displayable to none, we need mute audio and video |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 1475 | if (segment_id == player->cur_segment_id) { |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 1476 | if ((segment->flags & DVR_PLAYBACK_SEGMENT_DISPLAYABLE) == DVR_PLAYBACK_SEGMENT_DISPLAYABLE |
| 1477 | && (flags & DVR_PLAYBACK_SEGMENT_DISPLAYABLE) == 0) { |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame] | 1478 | //disable display, mute |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 1479 | AmTsPlayer_hideVideo(player->handle); |
| 1480 | AmTsPlayer_setAudioMute(player->handle, 1, 1); |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 1481 | } else if ((segment->flags & DVR_PLAYBACK_SEGMENT_DISPLAYABLE) == 0 && |
| 1482 | (flags & DVR_PLAYBACK_SEGMENT_DISPLAYABLE) == DVR_PLAYBACK_SEGMENT_DISPLAYABLE) { |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame] | 1483 | //enable display, unmute |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 1484 | AmTsPlayer_showVideo(player->handle); |
| 1485 | AmTsPlayer_setAudioMute(player->handle, 0, 0); |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1486 | } else { |
| 1487 | //do nothing |
| 1488 | } |
| 1489 | } else { |
| 1490 | //do nothing |
| 1491 | } |
| 1492 | //continue , only set flag |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 1493 | segment->flags = flags; |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1494 | } |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 1495 | DVR_PB_DG(1, "unlock"); |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1496 | pthread_mutex_unlock(&player->lock); |
| 1497 | return DVR_SUCCESS; |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 1498 | } |
| 1499 | |
| 1500 | |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 1501 | 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] | 1502 | DVR_Playback_t *player = (DVR_Playback_t *) handle; |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 1503 | if (player == NULL) { |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 1504 | DVR_PB_DG(1, "player is NULL"); |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 1505 | return DVR_FAILURE; |
| 1506 | } |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 1507 | DVR_PB_DG(1, " do check"); |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1508 | if (now_pid.pid == set_pid.pid) { |
| 1509 | //do nothing |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 1510 | return 0; |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 1511 | } else if (player->cmd.state == DVR_PLAYBACK_STATE_START) { |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1512 | if (VALID_PID(now_pid.pid)) { |
| 1513 | //stop now stream |
| 1514 | if (type == 0) { |
| 1515 | //stop vieo |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 1516 | DVR_PB_DG(1, "stop video"); |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 1517 | AmTsPlayer_stopVideoDecoding(player->handle); |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 1518 | player->has_video = DVR_FALSE; |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1519 | } else if (type == 1) { |
| 1520 | //stop audio |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 1521 | DVR_PB_DG(1, "stop audio"); |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 1522 | AmTsPlayer_stopAudioDecoding(player->handle); |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 1523 | player->has_audio = DVR_FALSE; |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1524 | } else if (type == 2) { |
| 1525 | //stop sub audio |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 1526 | DVR_PB_DG(1, "stop ad"); |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 1527 | AmTsPlayer_disableADMix(player->handle); |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1528 | } else if (type == 3) { |
| 1529 | //pcr |
| 1530 | } |
| 1531 | } |
| 1532 | if (VALID_PID(set_pid.pid)) { |
| 1533 | //start |
| 1534 | if (type == 0) { |
| 1535 | //start vieo |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 1536 | am_tsplayer_video_params vparams; |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1537 | vparams.pid = set_pid.pid; |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 1538 | vparams.codectype = _dvr_convert_stream_fmt(set_pid.format, DVR_FALSE); |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 1539 | player->has_video = DVR_TRUE; |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 1540 | 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] | 1541 | AmTsPlayer_setVideoParams(player->handle, &vparams); |
| 1542 | AmTsPlayer_startVideoDecoding(player->handle); |
| 1543 | //playback_device_video_start(player->handle,&vparams); |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1544 | } else if (type == 1) { |
| 1545 | //start audio |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 1546 | am_tsplayer_audio_params aparams; |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1547 | aparams.pid = set_pid.pid; |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 1548 | aparams.codectype= _dvr_convert_stream_fmt(set_pid.format, DVR_TRUE); |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 1549 | player->has_audio = DVR_TRUE; |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 1550 | 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] | 1551 | AmTsPlayer_setAudioParams(player->handle, &aparams); |
| 1552 | AmTsPlayer_startAudioDecoding(player->handle); |
| 1553 | //playback_device_audio_start(player->handle,&aparams); |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1554 | } else if (type == 2) { |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 1555 | am_tsplayer_audio_params aparams; |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1556 | aparams.pid = set_pid.pid; |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 1557 | aparams.codectype= _dvr_convert_stream_fmt(set_pid.format, DVR_TRUE); |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 1558 | player->has_audio = DVR_TRUE; |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 1559 | 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] | 1560 | AmTsPlayer_setADParams(player->handle, &aparams); |
| 1561 | AmTsPlayer_enableADMix(player->handle); |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 1562 | //playback_device_audio_start(player->handle,&aparams); |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1563 | } else if (type == 3) { |
| 1564 | //pcr |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 1565 | DVR_PB_DG(1, "start set pcr [%d]", set_pid.pid); |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 1566 | AmTsPlayer_setPcrPid(player->handle, set_pid.pid); |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1567 | } |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 1568 | //audio and video all close |
| 1569 | if (!player->has_audio && !player->has_video) { |
| 1570 | player->state = DVR_PLAYBACK_STATE_STOP; |
| 1571 | } |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1572 | } |
| 1573 | } |
| 1574 | return 0; |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 1575 | } |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 1576 | /**\brief dvr play back update segment pids |
| 1577 | * if updated segment is ongoing segment, we need start new |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 1578 | * add pid stream and stop remove pid stream. |
| 1579 | * \param[in] handle playback handle |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 1580 | * \param[in] segment_id need updated pids segment id |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 1581 | * \retval DVR_SUCCESS On success |
| 1582 | * \return Error code |
| 1583 | */ |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 1584 | 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] | 1585 | DVR_Playback_t *player = (DVR_Playback_t *) handle; |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 1586 | if (player == NULL) { |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 1587 | DVR_PB_DG(1, "player is NULL"); |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 1588 | return DVR_FAILURE; |
| 1589 | } |
| 1590 | |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 1591 | DVR_PlaybackSegmentInfo_t *segment; |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 1592 | DVR_PB_DG(1, "lock"); |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1593 | pthread_mutex_lock(&player->lock); |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 1594 | 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] | 1595 | |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 1596 | list_for_each_entry(segment, &player->segment_list, head) |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1597 | { |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 1598 | if (segment->segment_id == segment_id) { |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 1599 | |
| 1600 | if (player->cur_segment_id == segment_id) { |
| 1601 | if (player->cmd.state == DVR_PLAYBACK_STATE_FF |
| 1602 | || player->cmd.state == DVR_PLAYBACK_STATE_FF) { |
| 1603 | //do nothing when ff fb |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 1604 | 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] | 1605 | pthread_mutex_unlock(&player->lock); |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 1606 | return 0; |
| 1607 | } |
| 1608 | |
| 1609 | //if segment is on going segment,we need stop start stream |
| 1610 | if (player->cmd.state == DVR_PLAYBACK_STATE_START) { |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame] | 1611 | pthread_mutex_unlock(&player->lock); |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 1612 | //check video pids, stop or restart |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame] | 1613 | _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] | 1614 | //check audio pids stop or restart |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame] | 1615 | _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] | 1616 | //check sub audio pids stop or restart |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame] | 1617 | _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] | 1618 | //check pcr pids stop or restart |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame] | 1619 | _do_check_pid_info((DVR_PlaybackHandle_t)player, segment->pids.pcr, p_pids->pcr, 3); |
| 1620 | pthread_mutex_lock(&player->lock); |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 1621 | } else if (player->cmd.state == DVR_PLAYBACK_STATE_PAUSE) { |
| 1622 | //if state is pause, we need process at resume api. we only record change info |
| 1623 | int v_cmd = DVR_PLAYBACK_CMD_NONE; |
| 1624 | int a_cmd = DVR_PLAYBACK_CMD_NONE; |
| 1625 | if (VALID_PID(segment->pids.video.pid) |
| 1626 | && VALID_PID(p_pids->video.pid) |
| 1627 | && segment->pids.video.pid != p_pids->video.pid) { |
| 1628 | //restart video |
| 1629 | v_cmd = DVR_PLAYBACK_CMD_VRESTART; |
| 1630 | } |
| 1631 | if (!VALID_PID(segment->pids.video.pid) |
| 1632 | && VALID_PID(p_pids->video.pid) |
| 1633 | && segment->pids.video.pid != p_pids->video.pid) { |
| 1634 | //start video |
| 1635 | v_cmd = DVR_PLAYBACK_CMD_VSTART; |
| 1636 | } |
| 1637 | if (VALID_PID(segment->pids.video.pid) |
| 1638 | && !VALID_PID(p_pids->video.pid) |
| 1639 | && segment->pids.video.pid != p_pids->video.pid) { |
| 1640 | //stop video |
| 1641 | v_cmd = DVR_PLAYBACK_CMD_VSTOP; |
| 1642 | } |
| 1643 | if (VALID_PID(segment->pids.audio.pid) |
| 1644 | && VALID_PID(p_pids->audio.pid) |
| 1645 | && segment->pids.audio.pid != p_pids->audio.pid) { |
| 1646 | //restart audio |
| 1647 | a_cmd = DVR_PLAYBACK_CMD_ARESTART; |
| 1648 | } |
| 1649 | if (!VALID_PID(segment->pids.audio.pid) |
| 1650 | && VALID_PID(p_pids->audio.pid) |
| 1651 | && segment->pids.audio.pid != p_pids->audio.pid) { |
| 1652 | //start audio |
| 1653 | a_cmd = DVR_PLAYBACK_CMD_ASTART; |
| 1654 | } |
| 1655 | if (VALID_PID(segment->pids.audio.pid) |
| 1656 | && !VALID_PID(p_pids->audio.pid) |
| 1657 | && segment->pids.audio.pid != p_pids->audio.pid) { |
| 1658 | //stop audio |
| 1659 | a_cmd = DVR_PLAYBACK_CMD_ASTOP; |
| 1660 | } |
| 1661 | if (a_cmd == DVR_PLAYBACK_CMD_NONE |
| 1662 | && v_cmd == DVR_PLAYBACK_CMD_NONE) { |
| 1663 | //do nothing |
| 1664 | } else if (a_cmd == DVR_PLAYBACK_CMD_NONE |
| 1665 | || v_cmd == DVR_PLAYBACK_CMD_NONE) { |
| 1666 | player->cmd.last_cmd =DVR_PLAYBACK_CMD_PAUSE; |
| 1667 | player->cmd.cur_cmd = a_cmd != DVR_PLAYBACK_CMD_NONE ? a_cmd : v_cmd; |
| 1668 | } else if (a_cmd != DVR_PLAYBACK_CMD_NONE |
| 1669 | && v_cmd != DVR_PLAYBACK_CMD_NONE) { |
| 1670 | if (v_cmd == DVR_PLAYBACK_CMD_VRESTART |
| 1671 | && (a_cmd == DVR_PLAYBACK_CMD_ARESTART)) { |
| 1672 | player->cmd.last_cmd =DVR_PLAYBACK_CMD_PAUSE; |
| 1673 | player->cmd.cur_cmd = DVR_PLAYBACK_CMD_AVRESTART; |
| 1674 | }else if (v_cmd == DVR_PLAYBACK_CMD_VRESTART |
| 1675 | && a_cmd == DVR_PLAYBACK_CMD_ASTART) { |
| 1676 | player->cmd.last_cmd =DVR_PLAYBACK_CMD_PAUSE; |
| 1677 | player->cmd.cur_cmd = DVR_PLAYBACK_CMD_ASTARTVRESTART; |
| 1678 | } else { |
| 1679 | player->cmd.last_cmd =DVR_PLAYBACK_CMD_PAUSE; |
| 1680 | player->cmd.cur_cmd = DVR_PLAYBACK_CMD_ASTOPVRESTART; |
| 1681 | } |
| 1682 | |
| 1683 | if (v_cmd == DVR_PLAYBACK_CMD_VSTART |
| 1684 | && (a_cmd == DVR_PLAYBACK_CMD_ARESTART)) { |
| 1685 | player->cmd.last_cmd =DVR_PLAYBACK_CMD_PAUSE; |
| 1686 | player->cmd.cur_cmd = DVR_PLAYBACK_CMD_VSTARTARESTART; |
| 1687 | } else if (v_cmd == DVR_PLAYBACK_CMD_VSTART |
| 1688 | && a_cmd == DVR_PLAYBACK_CMD_ASTART) { |
| 1689 | //not occur this case |
| 1690 | player->cmd.last_cmd =DVR_PLAYBACK_CMD_PAUSE; |
| 1691 | player->cmd.cur_cmd = DVR_PLAYBACK_CMD_START; |
| 1692 | } else { |
| 1693 | player->cmd.last_cmd =DVR_PLAYBACK_CMD_PAUSE; |
| 1694 | player->cmd.cur_cmd = DVR_PLAYBACK_CMD_ASTOPVSTART; |
| 1695 | } |
| 1696 | |
| 1697 | if (v_cmd == DVR_PLAYBACK_CMD_VSTOP |
| 1698 | && a_cmd == DVR_PLAYBACK_CMD_ASTART) { |
| 1699 | player->cmd.last_cmd =DVR_PLAYBACK_CMD_PAUSE; |
| 1700 | player->cmd.cur_cmd = DVR_PLAYBACK_CMD_VSTOPASTART; |
| 1701 | } else if (v_cmd == DVR_PLAYBACK_CMD_VSTOP |
| 1702 | && a_cmd == DVR_PLAYBACK_CMD_ARESTART) { |
| 1703 | player->cmd.last_cmd =DVR_PLAYBACK_CMD_PAUSE; |
| 1704 | player->cmd.cur_cmd = DVR_PLAYBACK_CMD_VSTOPARESTART; |
| 1705 | } else { |
| 1706 | //not occur this case |
| 1707 | player->cmd.last_cmd =DVR_PLAYBACK_CMD_PAUSE; |
| 1708 | player->cmd.cur_cmd = DVR_PLAYBACK_CMD_STOP; |
| 1709 | } |
| 1710 | } |
| 1711 | } |
| 1712 | } |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1713 | //save pids info |
hualing chen | 7a56cba | 2020-04-14 14:09:27 +0800 | [diff] [blame^] | 1714 | DVR_PB_DG(1, ":apid :%d", segment->pids.audio.pid, p_pids->audio.pid); |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 1715 | memcpy(&segment->pids, p_pids, sizeof(DVR_PlaybackPids_t)); |
hualing chen | 7a56cba | 2020-04-14 14:09:27 +0800 | [diff] [blame^] | 1716 | DVR_PB_DG(1, ":cp apid :%d", segment->pids.audio.pid, p_pids->audio.pid); |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1717 | break; |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 1718 | } |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1719 | } |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 1720 | DVR_PB_DG(1, "unlock"); |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1721 | pthread_mutex_unlock(&player->lock); |
| 1722 | return DVR_SUCCESS; |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 1723 | } |
| 1724 | /**\brief Stop play, will stop video and audio |
| 1725 | * \param[in] handle playback handle |
| 1726 | * \param[in] clear is clear last frame |
| 1727 | * \retval DVR_SUCCESS On success |
| 1728 | * \return Error code |
| 1729 | */ |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 1730 | int dvr_playback_stop(DVR_PlaybackHandle_t handle, DVR_Bool_t clear) { |
| 1731 | DVR_Playback_t *player = (DVR_Playback_t *) handle; |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 1732 | |
| 1733 | if (player == NULL) { |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 1734 | DVR_PB_DG(1, "player is NULL"); |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 1735 | return DVR_FAILURE; |
| 1736 | } |
hualing chen | 7a56cba | 2020-04-14 14:09:27 +0800 | [diff] [blame^] | 1737 | DVR_PB_DG(1, ":into"); |
hualing chen | 87072a8 | 2020-03-12 16:20:12 +0800 | [diff] [blame] | 1738 | _stop_playback_thread(handle); |
hualing chen | 7a56cba | 2020-04-14 14:09:27 +0800 | [diff] [blame^] | 1739 | DVR_PB_DG(1, "lock"); |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1740 | pthread_mutex_lock(&player->lock); |
hualing chen | 7a56cba | 2020-04-14 14:09:27 +0800 | [diff] [blame^] | 1741 | DVR_PB_DG(1, ":get lock into stop fast"); |
hualing chen | 3114087 | 2020-03-25 12:29:26 +0800 | [diff] [blame] | 1742 | AmTsPlayer_stopFast(player->handle); |
hualing chen | 266b950 | 2020-04-04 17:39:39 +0800 | [diff] [blame] | 1743 | if (player->has_video) { |
| 1744 | AmTsPlayer_resumeVideoDecoding(player->handle); |
| 1745 | } |
| 1746 | if (player->has_audio) { |
| 1747 | AmTsPlayer_resumeAudioDecoding(player->handle); |
| 1748 | } |
hualing chen | 7a56cba | 2020-04-14 14:09:27 +0800 | [diff] [blame^] | 1749 | DVR_PB_DG(1, ":into"); |
hualing chen | 266b950 | 2020-04-04 17:39:39 +0800 | [diff] [blame] | 1750 | if (player->has_video) { |
| 1751 | player->has_video = DVR_FALSE; |
| 1752 | AmTsPlayer_showVideo(player->handle); |
| 1753 | AmTsPlayer_stopVideoDecoding(player->handle); |
| 1754 | } |
hualing chen | 7a56cba | 2020-04-14 14:09:27 +0800 | [diff] [blame^] | 1755 | DVR_PB_DG(1, ":into"); |
hualing chen | 266b950 | 2020-04-04 17:39:39 +0800 | [diff] [blame] | 1756 | if (player->has_audio) { |
| 1757 | player->has_audio = DVR_FALSE; |
| 1758 | AmTsPlayer_stopAudioDecoding(player->handle); |
| 1759 | } |
hualing chen | 7a56cba | 2020-04-14 14:09:27 +0800 | [diff] [blame^] | 1760 | DVR_PB_DG(1, ":into"); |
hualing chen | 266b950 | 2020-04-04 17:39:39 +0800 | [diff] [blame] | 1761 | |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1762 | player->cmd.last_cmd = player->cmd.cur_cmd; |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 1763 | player->cmd.cur_cmd = DVR_PLAYBACK_CMD_STOP; |
| 1764 | player->cmd.state = DVR_PLAYBACK_STATE_STOP; |
| 1765 | player->state = DVR_PLAYBACK_STATE_STOP; |
hualing chen | 87072a8 | 2020-03-12 16:20:12 +0800 | [diff] [blame] | 1766 | player->cur_segment_id = UINT64_MAX; |
| 1767 | player->segment_is_open = DVR_FALSE; |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 1768 | DVR_PB_DG(1, "unlock"); |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1769 | pthread_mutex_unlock(&player->lock); |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1770 | return DVR_SUCCESS; |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 1771 | } |
| 1772 | /**\brief Start play audio |
| 1773 | * \param[in] handle playback handle |
| 1774 | * \param[in] params audio playback params,contains fmt and pid... |
| 1775 | * \retval DVR_SUCCESS On success |
| 1776 | * \return Error code |
| 1777 | */ |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 1778 | |
| 1779 | 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] | 1780 | DVR_Playback_t *player = (DVR_Playback_t *) handle; |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 1781 | |
| 1782 | if (player == NULL) { |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 1783 | DVR_PB_DG(1, "player is NULL"); |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 1784 | return DVR_FAILURE; |
| 1785 | } |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1786 | _start_playback_thread(handle); |
| 1787 | //start audio and video |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 1788 | DVR_PB_DG(1, "lock"); |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1789 | pthread_mutex_lock(&player->lock); |
| 1790 | player->has_audio = DVR_TRUE; |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 1791 | AmTsPlayer_setAudioParams(player->handle, param); |
| 1792 | AmTsPlayer_startAudioDecoding(player->handle); |
| 1793 | //playback_device_audio_start(player->handle , param); |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1794 | player->cmd.last_cmd = player->cmd.cur_cmd; |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 1795 | player->cmd.cur_cmd = DVR_PLAYBACK_CMD_ASTART; |
| 1796 | player->cmd.state = DVR_PLAYBACK_STATE_START; |
| 1797 | player->state = DVR_PLAYBACK_STATE_START; |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 1798 | DVR_PB_DG(1, "unlock"); |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1799 | pthread_mutex_unlock(&player->lock); |
| 1800 | return DVR_SUCCESS; |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 1801 | } |
| 1802 | /**\brief Stop play audio |
| 1803 | * \param[in] handle playback handle |
| 1804 | * \retval DVR_SUCCESS On success |
| 1805 | * \return Error code |
| 1806 | */ |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 1807 | int dvr_playback_audio_stop(DVR_PlaybackHandle_t handle) { |
| 1808 | DVR_Playback_t *player = (DVR_Playback_t *) handle; |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 1809 | |
| 1810 | if (player == NULL) { |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 1811 | DVR_PB_DG(1, "player is NULL"); |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 1812 | return DVR_FAILURE; |
| 1813 | } |
| 1814 | |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 1815 | //playback_device_audio_stop(player->handle); |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1816 | if (player->has_video == DVR_FALSE) { |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 1817 | player->cmd.state = DVR_PLAYBACK_STATE_STOP; |
| 1818 | player->state = DVR_PLAYBACK_STATE_STOP; |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1819 | //destory thread |
| 1820 | _stop_playback_thread(handle); |
| 1821 | } else { |
| 1822 | //do nothing.video is playing |
| 1823 | } |
hualing chen | 7a56cba | 2020-04-14 14:09:27 +0800 | [diff] [blame^] | 1824 | DVR_PB_DG(1, "lock"); |
| 1825 | pthread_mutex_lock(&player->lock); |
| 1826 | |
hualing chen | 87072a8 | 2020-03-12 16:20:12 +0800 | [diff] [blame] | 1827 | player->has_audio = DVR_FALSE; |
| 1828 | |
| 1829 | AmTsPlayer_stopAudioDecoding(player->handle); |
| 1830 | player->cmd.last_cmd = player->cmd.cur_cmd; |
| 1831 | player->cmd.cur_cmd = DVR_PLAYBACK_CMD_ASTOP; |
| 1832 | |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 1833 | DVR_PB_DG(1, "unlock"); |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1834 | pthread_mutex_unlock(&player->lock); |
| 1835 | return DVR_SUCCESS; |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 1836 | } |
| 1837 | /**\brief Start play video |
| 1838 | * \param[in] handle playback handle |
| 1839 | * \param[in] params video playback params,contains fmt and pid... |
| 1840 | * \retval DVR_SUCCESS On success |
| 1841 | * \return Error code |
| 1842 | */ |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 1843 | 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] | 1844 | DVR_Playback_t *player = (DVR_Playback_t *) handle; |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 1845 | |
| 1846 | if (player == NULL) { |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 1847 | DVR_PB_DG(1, "player is NULL"); |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 1848 | return DVR_FAILURE; |
| 1849 | } |
| 1850 | |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1851 | _start_playback_thread(handle); |
| 1852 | //start audio and video |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 1853 | DVR_PB_DG(1, "lock"); |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1854 | pthread_mutex_lock(&player->lock); |
| 1855 | player->has_video = DVR_TRUE; |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 1856 | AmTsPlayer_setVideoParams(player->handle, param); |
| 1857 | AmTsPlayer_startVideoDecoding(player->handle); |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 1858 | |
| 1859 | //playback_device_video_start(player->handle , param); |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1860 | //if set flag is pause live, we need set trick mode |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 1861 | if ((player->play_flag&DVR_PLAYBACK_STARTED_PAUSEDLIVE) == DVR_PLAYBACK_STARTED_PAUSEDLIVE) { |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 1862 | DVR_PB_DG(1, "settrick mode at video start"); |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 1863 | AmTsPlayer_setTrickMode(player->handle, AV_VIDEO_TRICK_MODE_PAUSE_NEXT); |
| 1864 | //playback_device_trick_mode(player->handle, 1); |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1865 | } |
| 1866 | player->cmd.last_cmd = player->cmd.cur_cmd; |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 1867 | player->cmd.cur_cmd = DVR_PLAYBACK_CMD_VSTART; |
| 1868 | player->cmd.state = DVR_PLAYBACK_STATE_START; |
| 1869 | player->state = DVR_PLAYBACK_STATE_START; |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 1870 | DVR_PB_DG(1, "unlock"); |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1871 | pthread_mutex_unlock(&player->lock); |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 1872 | return DVR_SUCCESS; |
| 1873 | } |
| 1874 | /**\brief Stop play video |
| 1875 | * \param[in] handle playback handle |
| 1876 | * \retval DVR_SUCCESS On success |
| 1877 | * \return Error code |
| 1878 | */ |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 1879 | int dvr_playback_video_stop(DVR_PlaybackHandle_t handle) { |
| 1880 | DVR_Playback_t *player = (DVR_Playback_t *) handle; |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 1881 | |
| 1882 | if (player == NULL) { |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 1883 | DVR_PB_DG(1, "player is NULL"); |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 1884 | return DVR_FAILURE; |
| 1885 | } |
| 1886 | |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1887 | if (player->has_audio == DVR_FALSE) { |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 1888 | player->cmd.state = DVR_PLAYBACK_STATE_STOP; |
| 1889 | player->state = DVR_PLAYBACK_STATE_STOP; |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1890 | //destory thread |
| 1891 | _stop_playback_thread(handle); |
| 1892 | } else { |
| 1893 | //do nothing.audio is playing |
| 1894 | } |
hualing chen | 7a56cba | 2020-04-14 14:09:27 +0800 | [diff] [blame^] | 1895 | |
| 1896 | DVR_PB_DG(1, "lock"); |
| 1897 | pthread_mutex_lock(&player->lock); |
| 1898 | |
hualing chen | 87072a8 | 2020-03-12 16:20:12 +0800 | [diff] [blame] | 1899 | player->has_video = DVR_FALSE; |
| 1900 | |
| 1901 | AmTsPlayer_stopVideoDecoding(player->handle); |
| 1902 | //playback_device_video_stop(player->handle); |
| 1903 | |
| 1904 | player->cmd.last_cmd = player->cmd.cur_cmd; |
| 1905 | player->cmd.cur_cmd = DVR_PLAYBACK_CMD_VSTOP; |
| 1906 | |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 1907 | DVR_PB_DG(1, "unlock"); |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1908 | pthread_mutex_unlock(&player->lock); |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 1909 | return DVR_SUCCESS; |
| 1910 | } |
| 1911 | /**\brief Pause play |
| 1912 | * \param[in] handle playback handle |
| 1913 | * \param[in] flush whether its internal buffers should be flushed |
| 1914 | * \retval DVR_SUCCESS On success |
| 1915 | * \return Error code |
| 1916 | */ |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 1917 | int dvr_playback_pause(DVR_PlaybackHandle_t handle, DVR_Bool_t flush) { |
| 1918 | DVR_Playback_t *player = (DVR_Playback_t *) handle; |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 1919 | |
| 1920 | if (player == NULL) { |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 1921 | DVR_PB_DG(1, "player is NULL"); |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 1922 | return DVR_FAILURE; |
| 1923 | } |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 1924 | DVR_PB_DG(1, "lock"); |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1925 | pthread_mutex_lock(&player->lock); |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 1926 | DVR_PB_DG(1, "get lock"); |
hualing chen | 266b950 | 2020-04-04 17:39:39 +0800 | [diff] [blame] | 1927 | if (player->has_video) |
| 1928 | AmTsPlayer_pauseVideoDecoding(player->handle); |
| 1929 | if (player->has_video) |
| 1930 | AmTsPlayer_pauseAudioDecoding(player->handle); |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 1931 | |
| 1932 | //playback_device_pause(player->handle); |
hualing chen | 87072a8 | 2020-03-12 16:20:12 +0800 | [diff] [blame] | 1933 | if (player->cmd.cur_cmd == DVR_PLAYBACK_CMD_FF || |
| 1934 | player->cmd.cur_cmd == DVR_PLAYBACK_CMD_FB) { |
| 1935 | player->cmd.state = DVR_PLAYBACK_STATE_PAUSE; |
| 1936 | player->state = DVR_PLAYBACK_STATE_PAUSE; |
hualing chen | 87072a8 | 2020-03-12 16:20:12 +0800 | [diff] [blame] | 1937 | } else { |
| 1938 | player->cmd.last_cmd = player->cmd.cur_cmd; |
| 1939 | player->cmd.cur_cmd = DVR_PLAYBACK_CMD_PAUSE; |
| 1940 | player->cmd.state = DVR_PLAYBACK_STATE_PAUSE; |
| 1941 | player->state = DVR_PLAYBACK_STATE_PAUSE; |
hualing chen | 87072a8 | 2020-03-12 16:20:12 +0800 | [diff] [blame] | 1942 | } |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1943 | pthread_mutex_unlock(&player->lock); |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 1944 | DVR_PB_DG(1, "unlock"); |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 1945 | |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1946 | return DVR_SUCCESS; |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 1947 | } |
| 1948 | |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 1949 | //not add lock |
| 1950 | static int _dvr_cmd(DVR_PlaybackHandle_t handle, int cmd) |
| 1951 | { |
| 1952 | DVR_Playback_t *player = (DVR_Playback_t *) handle; |
| 1953 | |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 1954 | if (player == NULL) { |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 1955 | DVR_PB_DG(1, "player is NULL"); |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 1956 | return DVR_FAILURE; |
| 1957 | } |
| 1958 | |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 1959 | //get video params and audio params |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 1960 | DVR_PB_DG(1, "lock"); |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 1961 | pthread_mutex_lock(&player->lock); |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 1962 | am_tsplayer_video_params vparams; |
| 1963 | am_tsplayer_audio_params aparams; |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame] | 1964 | uint64_t segmentid = player->cur_segment_id; |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 1965 | |
| 1966 | _dvr_playback_get_playinfo(handle, segmentid, &vparams, &aparams); |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 1967 | DVR_PB_DG(1, "unlock cmd: %d", cmd); |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 1968 | pthread_mutex_unlock(&player->lock); |
| 1969 | |
| 1970 | switch (cmd) { |
| 1971 | case DVR_PLAYBACK_CMD_AVRESTART: |
| 1972 | //av restart |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 1973 | DVR_PB_DG(1, "do_cmd avrestart"); |
hualing chen | 87072a8 | 2020-03-12 16:20:12 +0800 | [diff] [blame] | 1974 | _dvr_playback_replay((DVR_PlaybackHandle_t)player, DVR_FALSE); |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 1975 | break; |
| 1976 | case DVR_PLAYBACK_CMD_VRESTART: |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 1977 | dvr_playback_video_stop((DVR_PlaybackHandle_t)player); |
| 1978 | dvr_playback_video_start((DVR_PlaybackHandle_t)player, &vparams); |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 1979 | break; |
| 1980 | case DVR_PLAYBACK_CMD_VSTART: |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 1981 | dvr_playback_video_start((DVR_PlaybackHandle_t)player, &vparams); |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 1982 | break; |
| 1983 | case DVR_PLAYBACK_CMD_VSTOP: |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 1984 | dvr_playback_video_stop((DVR_PlaybackHandle_t)player); |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 1985 | break; |
| 1986 | case DVR_PLAYBACK_CMD_ARESTART: |
| 1987 | //a restart |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 1988 | dvr_playback_audio_stop((DVR_PlaybackHandle_t)player); |
| 1989 | dvr_playback_audio_start((DVR_PlaybackHandle_t)player, &aparams); |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 1990 | break; |
| 1991 | case DVR_PLAYBACK_CMD_ASTART: |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 1992 | dvr_playback_audio_start((DVR_PlaybackHandle_t)player, &aparams); |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 1993 | break; |
| 1994 | case DVR_PLAYBACK_CMD_ASTOP: |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 1995 | dvr_playback_audio_stop((DVR_PlaybackHandle_t)player); |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 1996 | break; |
| 1997 | case DVR_PLAYBACK_CMD_ASTOPVRESTART: |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 1998 | dvr_playback_audio_stop((DVR_PlaybackHandle_t)player); |
| 1999 | dvr_playback_video_stop((DVR_PlaybackHandle_t)player); |
| 2000 | dvr_playback_video_start((DVR_PlaybackHandle_t)player, &vparams); |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 2001 | break; |
| 2002 | case DVR_PLAYBACK_CMD_ASTOPVSTART: |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 2003 | dvr_playback_audio_stop((DVR_PlaybackHandle_t)player); |
| 2004 | dvr_playback_video_start((DVR_PlaybackHandle_t)player, &vparams); |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 2005 | break; |
| 2006 | case DVR_PLAYBACK_CMD_VSTOPARESTART: |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 2007 | dvr_playback_video_stop((DVR_PlaybackHandle_t)player); |
| 2008 | dvr_playback_audio_stop((DVR_PlaybackHandle_t)player); |
| 2009 | dvr_playback_audio_start((DVR_PlaybackHandle_t)player, &aparams); |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 2010 | break; |
| 2011 | case DVR_PLAYBACK_CMD_STOP: |
| 2012 | break; |
| 2013 | case DVR_PLAYBACK_CMD_START: |
| 2014 | break; |
| 2015 | case DVR_PLAYBACK_CMD_ASTARTVRESTART: |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 2016 | dvr_playback_video_stop((DVR_PlaybackHandle_t)player); |
| 2017 | dvr_playback_video_start((DVR_PlaybackHandle_t)player, &vparams); |
| 2018 | dvr_playback_audio_start((DVR_PlaybackHandle_t)player, &aparams); |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 2019 | break; |
| 2020 | case DVR_PLAYBACK_CMD_VSTARTARESTART: |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 2021 | dvr_playback_audio_stop((DVR_PlaybackHandle_t)player); |
| 2022 | dvr_playback_video_start((DVR_PlaybackHandle_t)player, &vparams); |
| 2023 | dvr_playback_audio_start((DVR_PlaybackHandle_t)player, &aparams); |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 2024 | break; |
| 2025 | case DVR_PLAYBACK_CMD_FF: |
| 2026 | case DVR_PLAYBACK_CMD_FB: |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 2027 | _dvr_playback_fffb((DVR_PlaybackHandle_t)player); |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 2028 | break; |
| 2029 | default: |
| 2030 | break; |
| 2031 | } |
| 2032 | return DVR_SUCCESS; |
| 2033 | } |
| 2034 | |
| 2035 | /**\brief Resume play |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 2036 | * \param[in] handle playback handle |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 2037 | * \retval DVR_SUCCESS On success |
| 2038 | * \return Error code |
| 2039 | */ |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 2040 | int dvr_playback_resume(DVR_PlaybackHandle_t handle) { |
| 2041 | DVR_Playback_t *player = (DVR_Playback_t *) handle; |
| 2042 | |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 2043 | if (player == NULL) { |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 2044 | DVR_PB_DG(1, "player is NULL"); |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 2045 | return DVR_FAILURE; |
| 2046 | } |
| 2047 | |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 2048 | if (player->cmd.cur_cmd == DVR_PLAYBACK_CMD_PAUSE) { |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 2049 | DVR_PB_DG(1, "lock"); |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 2050 | pthread_mutex_lock(&player->lock); |
hualing chen | 266b950 | 2020-04-04 17:39:39 +0800 | [diff] [blame] | 2051 | if (player->has_video) { |
| 2052 | AmTsPlayer_setTrickMode(player->handle, AV_VIDEO_TRICK_MODE_NONE); |
| 2053 | AmTsPlayer_resumeVideoDecoding(player->handle); |
| 2054 | } |
| 2055 | if (player->has_audio) { |
| 2056 | AmTsPlayer_resumeAudioDecoding(player->handle); |
| 2057 | } |
| 2058 | //check is has audio param,if has audio .we need start audio, |
| 2059 | //we will stop audio when ff fb, if reach end, we will pause.so we need |
| 2060 | //start audio when resume play |
| 2061 | |
| 2062 | am_tsplayer_video_params vparams; |
| 2063 | am_tsplayer_audio_params aparams; |
| 2064 | uint64_t segmentid = player->cur_segment_id; |
| 2065 | _dvr_playback_get_playinfo(handle, segmentid, &vparams, &aparams); |
| 2066 | //valid audio pid, start audio |
| 2067 | if (player->has_audio == DVR_FALSE && VALID_PID(aparams.pid)) { |
| 2068 | player->has_audio = DVR_TRUE; |
| 2069 | AmTsPlayer_setAudioParams(player->handle, &aparams); |
| 2070 | AmTsPlayer_startAudioDecoding(player->handle); |
| 2071 | } else { |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 2072 | 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] | 2073 | } |
hualing chen | 87072a8 | 2020-03-12 16:20:12 +0800 | [diff] [blame] | 2074 | if (player->cmd.cur_cmd == DVR_PLAYBACK_CMD_FF || |
| 2075 | player->cmd.cur_cmd == DVR_PLAYBACK_CMD_FB) { |
| 2076 | player->cmd.state = DVR_PLAYBACK_STATE_START; |
| 2077 | player->state = DVR_PLAYBACK_STATE_START; |
| 2078 | } else { |
| 2079 | player->cmd.last_cmd = player->cmd.cur_cmd; |
| 2080 | player->cmd.cur_cmd = DVR_PLAYBACK_CMD_RESUME; |
| 2081 | player->cmd.state = DVR_PLAYBACK_STATE_START; |
| 2082 | player->state = DVR_PLAYBACK_STATE_START; |
| 2083 | } |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 2084 | DVR_PB_DG(1, "unlock"); |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 2085 | pthread_mutex_unlock(&player->lock); |
hualing chen | 041c409 | 2020-04-05 15:11:50 +0800 | [diff] [blame] | 2086 | } else if (player->state == DVR_PLAYBACK_STATE_PAUSE){ |
| 2087 | if (player->has_video) |
| 2088 | AmTsPlayer_resumeVideoDecoding(player->handle); |
| 2089 | if (player->has_audio) |
| 2090 | AmTsPlayer_resumeAudioDecoding(player->handle); |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 2091 | 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] | 2092 | player->cmd.state = DVR_PLAYBACK_STATE_START; |
| 2093 | player->state = DVR_PLAYBACK_STATE_START; |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 2094 | _dvr_cmd(handle, player->cmd.cur_cmd); |
hualing chen | 041c409 | 2020-04-05 15:11:50 +0800 | [diff] [blame] | 2095 | } else { |
| 2096 | if ((player->play_flag&DVR_PLAYBACK_STARTED_PAUSEDLIVE) == DVR_PLAYBACK_STARTED_PAUSEDLIVE) |
| 2097 | { |
| 2098 | pthread_mutex_lock(&player->lock); |
| 2099 | //clear flag |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 2100 | 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] | 2101 | player->play_flag = player->play_flag & (~DVR_PLAYBACK_STARTED_PAUSEDLIVE); |
| 2102 | AmTsPlayer_setTrickMode(player->handle, AV_VIDEO_TRICK_MODE_NONE); |
| 2103 | pthread_mutex_unlock(&player->lock); |
| 2104 | } |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 2105 | } |
| 2106 | return DVR_SUCCESS; |
| 2107 | } |
| 2108 | |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 2109 | static DVR_Bool_t _dvr_check_playinfo_changed(DVR_PlaybackHandle_t handle, int segment_id, int set_seg_id){ |
| 2110 | |
| 2111 | DVR_Playback_t *player = (DVR_Playback_t *) handle; |
| 2112 | DVR_PlaybackSegmentInfo_t *segment = NULL; |
| 2113 | DVR_PlaybackSegmentInfo_t *cur_segment = NULL; |
| 2114 | DVR_PlaybackSegmentInfo_t *set_segment = NULL; |
| 2115 | |
| 2116 | list_for_each_entry(segment, &player->segment_list, head) |
| 2117 | { |
| 2118 | if (segment->segment_id == segment_id) { |
| 2119 | cur_segment = segment; |
| 2120 | } |
| 2121 | if (segment->segment_id == set_seg_id) { |
| 2122 | set_segment = segment; |
| 2123 | } |
| 2124 | if (cur_segment != NULL && set_segment != NULL) { |
| 2125 | break; |
| 2126 | } |
| 2127 | } |
| 2128 | if (cur_segment == NULL || set_segment == NULL) { |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 2129 | DVR_PB_DG(1, "set segmen or cur segment is null"); |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 2130 | return DVR_TRUE; |
| 2131 | } |
| 2132 | if (cur_segment->pids.video.format != set_segment->pids.video.format || |
| 2133 | cur_segment->pids.video.pid != set_segment->pids.video.pid || |
| 2134 | cur_segment->pids.audio.format != set_segment->pids.audio.format || |
| 2135 | cur_segment->pids.audio.pid != set_segment->pids.audio.pid) { |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 2136 | 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] | 2137 | return DVR_TRUE; |
| 2138 | } |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 2139 | DVR_PB_DG(1, "play info not change"); |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 2140 | return DVR_FALSE; |
| 2141 | } |
| 2142 | |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 2143 | /**\brief seek |
| 2144 | * \param[in] handle playback handle |
| 2145 | * \param[in] time_offset time offset base cur segment |
| 2146 | * \retval DVR_SUCCESS On success |
| 2147 | * \return Error code |
| 2148 | */ |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame] | 2149 | 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] | 2150 | DVR_Playback_t *player = (DVR_Playback_t *) handle; |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 2151 | |
| 2152 | if (player == NULL) { |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 2153 | DVR_PB_DG(1, "player is NULL"); |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 2154 | return DVR_FAILURE; |
| 2155 | } |
| 2156 | |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 2157 | 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] | 2158 | pthread_mutex_lock(&player->lock); |
hualing chen | 87072a8 | 2020-03-12 16:20:12 +0800 | [diff] [blame] | 2159 | |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 2160 | int offset = -1; |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 2161 | 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] | 2162 | 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] | 2163 | |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 2164 | //open segment if id is not current segment |
hualing chen | 87072a8 | 2020-03-12 16:20:12 +0800 | [diff] [blame] | 2165 | int ret = _dvr_open_segment(handle, segment_id); |
| 2166 | if (ret ==DVR_FAILURE) { |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 2167 | DVR_PB_DG(1, "seek error at open segment"); |
hualing chen | 87072a8 | 2020-03-12 16:20:12 +0800 | [diff] [blame] | 2168 | pthread_mutex_unlock(&player->lock); |
| 2169 | return DVR_FAILURE; |
| 2170 | } |
| 2171 | if (time_offset >_dvr_get_end_time(handle) &&_dvr_has_next_segmentId(handle, segment_id) == DVR_FAILURE) { |
| 2172 | if (segment_ongoing(player->r_handle) == DVR_SUCCESS) { |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 2173 | 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] | 2174 | //pthread_mutex_unlock(&player->lock); |
| 2175 | //return DVR_SUCCESS; |
| 2176 | time_offset = _dvr_get_end_time(handle); |
| 2177 | } else { |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 2178 | 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] | 2179 | pthread_mutex_unlock(&player->lock); |
| 2180 | return DVR_FAILURE; |
| 2181 | } |
| 2182 | } |
| 2183 | |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 2184 | 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] | 2185 | //get file offset by time |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 2186 | if (player->cmd.cur_cmd == DVR_PLAYBACK_CMD_FB) { |
| 2187 | //forward playback.not seek end of file |
| 2188 | if (time_offset != 0 && time_offset > FB_DEFAULT_LEFT_TIME) { |
| 2189 | //default -2000ms |
| 2190 | time_offset = time_offset -FB_DEFAULT_LEFT_TIME; |
| 2191 | } |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 2192 | } |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 2193 | pthread_mutex_lock(&player->segment_lock); |
hualing chen | 266b950 | 2020-04-04 17:39:39 +0800 | [diff] [blame] | 2194 | player->drop_ts = DVR_TRUE; |
| 2195 | 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] | 2196 | 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] | 2197 | pthread_mutex_unlock(&player->segment_lock); |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 2198 | player->offset = offset; |
hualing chen | 87072a8 | 2020-03-12 16:20:12 +0800 | [diff] [blame] | 2199 | |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 2200 | _dvr_get_end_time(handle); |
| 2201 | //init fffb time |
hualing chen | 87072a8 | 2020-03-12 16:20:12 +0800 | [diff] [blame] | 2202 | player->fffb_current = _dvr_time_getClock(); |
| 2203 | player->fffb_start = player->fffb_current; |
| 2204 | player->fffb_start_pcr = _dvr_get_cur_time(handle); |
| 2205 | player->next_fffb_time = player->fffb_current; |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 2206 | //pause state if need to replayer false |
| 2207 | if (player->state == DVR_PLAYBACK_STATE_STOP || |
| 2208 | (player->state == DVR_PLAYBACK_STATE_PAUSE)) { |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 2209 | //only seek file,not start |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 2210 | DVR_PB_DG(1, "unlock"); |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame] | 2211 | pthread_mutex_unlock(&player->lock); |
hualing chen | 87072a8 | 2020-03-12 16:20:12 +0800 | [diff] [blame] | 2212 | return DVR_SUCCESS; |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 2213 | } |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 2214 | //stop play |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 2215 | 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] | 2216 | if (player->has_video) { |
| 2217 | player->has_video = DVR_FALSE; |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 2218 | AmTsPlayer_stopVideoDecoding(player->handle); |
hualing chen | 266b950 | 2020-04-04 17:39:39 +0800 | [diff] [blame] | 2219 | } |
| 2220 | |
| 2221 | if (player->has_audio) { |
| 2222 | player->has_audio =DVR_FALSE; |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 2223 | AmTsPlayer_stopAudioDecoding(player->handle); |
hualing chen | 266b950 | 2020-04-04 17:39:39 +0800 | [diff] [blame] | 2224 | } |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 2225 | //start play |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 2226 | am_tsplayer_video_params vparams; |
| 2227 | am_tsplayer_audio_params aparams; |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 2228 | |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 2229 | player->cur_segment_id = segment_id; |
| 2230 | |
| 2231 | int sync = DVR_PLAYBACK_SYNC; |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 2232 | //get segment info and audio video pid fmt ; |
| 2233 | _dvr_playback_get_playinfo(handle, segment_id, &vparams, &aparams); |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 2234 | //start audio and video |
| 2235 | if (!VALID_PID(vparams.pid) && !VALID_PID(aparams.pid)) { |
| 2236 | //audio abnd video pis is all invalid, return error. |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 2237 | 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] | 2238 | pthread_mutex_unlock(&player->lock); |
| 2239 | return -1; |
| 2240 | } |
| 2241 | //add |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 2242 | if (sync == DVR_PLAYBACK_SYNC) { |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 2243 | if (VALID_PID(vparams.pid)) { |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 2244 | //player->has_video; |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 2245 | if (player->cmd.cur_cmd == DVR_PLAYBACK_CMD_PAUSE || |
hualing chen | 3114087 | 2020-03-25 12:29:26 +0800 | [diff] [blame] | 2246 | player->speed > 1.0f|| |
| 2247 | player->speed <= -1.0f) { |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 2248 | //if is pause state. we need set trick mode. |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 2249 | 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] | 2250 | AmTsPlayer_setTrickMode(player->handle, AV_VIDEO_TRICK_MODE_PAUSE_NEXT); |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 2251 | } |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 2252 | AmTsPlayer_setVideoParams(player->handle, &vparams); |
| 2253 | AmTsPlayer_startVideoDecoding(player->handle); |
hualing chen | 266b950 | 2020-04-04 17:39:39 +0800 | [diff] [blame] | 2254 | player->has_video = DVR_TRUE; |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 2255 | } |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 2256 | if (VALID_PID(aparams.pid)) { |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 2257 | DVR_PB_DG(1, "start audio seek"); |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 2258 | AmTsPlayer_setAudioParams(player->handle, &aparams); |
| 2259 | AmTsPlayer_startAudioDecoding(player->handle); |
hualing chen | 266b950 | 2020-04-04 17:39:39 +0800 | [diff] [blame] | 2260 | player->has_audio = DVR_TRUE; |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 2261 | } |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 2262 | } |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 2263 | if (player->state == DVR_PLAYBACK_STATE_PAUSE && |
| 2264 | ((player->cmd.cur_cmd == DVR_PLAYBACK_CMD_FF || |
| 2265 | player->cmd.cur_cmd == DVR_PLAYBACK_CMD_FB) || |
| 2266 | (player->cmd.last_cmd == DVR_PLAYBACK_CMD_FF || |
| 2267 | player->cmd.last_cmd == DVR_PLAYBACK_CMD_FB))) { |
| 2268 | player->cmd.state = DVR_PLAYBACK_STATE_PAUSE; |
| 2269 | player->state = DVR_PLAYBACK_STATE_PAUSE; |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 2270 | DVR_PB_DG(1, "set state pause in seek"); |
hualing chen | 87072a8 | 2020-03-12 16:20:12 +0800 | [diff] [blame] | 2271 | } else if (player->cmd.cur_cmd == DVR_PLAYBACK_CMD_FF || |
| 2272 | player->cmd.cur_cmd == DVR_PLAYBACK_CMD_FF || |
hualing chen | 3114087 | 2020-03-25 12:29:26 +0800 | [diff] [blame] | 2273 | player->speed > 1.0f|| |
| 2274 | player->speed <= -1.0f) { |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 2275 | DVR_PB_DG(1, "not set cmd to seek"); |
hualing chen | 87072a8 | 2020-03-12 16:20:12 +0800 | [diff] [blame] | 2276 | //not pause state, we need not set cur cmd |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 2277 | } else { |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 2278 | DVR_PB_DG(1, "set cmd to seek"); |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 2279 | player->cmd.last_cmd = player->cmd.cur_cmd; |
| 2280 | player->cmd.cur_cmd = DVR_PLAYBACK_CMD_SEEK; |
| 2281 | player->cmd.state = DVR_PLAYBACK_STATE_START; |
| 2282 | player->state = DVR_PLAYBACK_STATE_START; |
| 2283 | } |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 2284 | player->last_send_time_id = UINT64_MAX; |
| 2285 | DVR_PB_DG(1, "unlock"); |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 2286 | pthread_mutex_unlock(&player->lock); |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 2287 | |
| 2288 | return DVR_SUCCESS; |
| 2289 | } |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 2290 | |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 2291 | static int _dvr_get_cur_time(DVR_PlaybackHandle_t handle) { |
| 2292 | //get cur time of segment |
| 2293 | DVR_Playback_t *player = (DVR_Playback_t *) handle; |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 2294 | |
| 2295 | if (player == NULL || player->handle == NULL) { |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 2296 | DVR_PB_DG(1, "player is NULL"); |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 2297 | return DVR_FAILURE; |
| 2298 | } |
| 2299 | |
hualing chen | 3114087 | 2020-03-25 12:29:26 +0800 | [diff] [blame] | 2300 | int64_t cache = 0;//defalut es buf cache 500ms |
| 2301 | AmTsPlayer_getDelayTime(player->handle, &cache); |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 2302 | pthread_mutex_lock(&player->segment_lock); |
| 2303 | uint64_t cur = segment_tell_current_time(player->r_handle); |
| 2304 | pthread_mutex_unlock(&player->segment_lock); |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 2305 | 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] | 2306 | if (player->state == DVR_PLAYBACK_STATE_STOP) { |
| 2307 | cache = 0; |
| 2308 | } |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 2309 | int cur_time = (int)(cur > cache ? cur - cache : 0); |
| 2310 | return cur_time; |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame] | 2311 | } |
| 2312 | |
| 2313 | //get current segment current pcr time of read pos |
| 2314 | static int _dvr_get_end_time(DVR_PlaybackHandle_t handle) { |
| 2315 | //get cur time of segment |
| 2316 | DVR_Playback_t *player = (DVR_Playback_t *) handle; |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 2317 | |
| 2318 | if (player == NULL) { |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 2319 | DVR_PB_DG(1, "player is NULL"); |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 2320 | return DVR_FAILURE; |
| 2321 | } |
| 2322 | |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 2323 | pthread_mutex_lock(&player->segment_lock); |
| 2324 | uint64_t end = segment_tell_total_time(player->r_handle); |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 2325 | DVR_PB_DG(1, "get tatal time [%lld]", end); |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 2326 | pthread_mutex_unlock(&player->segment_lock); |
| 2327 | return (int)end; |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 2328 | } |
| 2329 | |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 2330 | #define FB_MIX_SEEK_TIME 2000 |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 2331 | //start replay |
| 2332 | static int _dvr_playback_calculate_seekpos(DVR_PlaybackHandle_t handle) { |
| 2333 | |
| 2334 | DVR_Playback_t *player = (DVR_Playback_t *) handle; |
| 2335 | //calculate pcr seek time |
| 2336 | int t_diff = 0; |
| 2337 | int seek_time = 0; |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 2338 | |
| 2339 | if (player == NULL) { |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 2340 | DVR_PB_DG(1, "player is NULL"); |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 2341 | return DVR_FAILURE; |
| 2342 | } |
| 2343 | |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 2344 | if (player->fffb_start == -1) { |
| 2345 | //set fffb start time ms |
| 2346 | player->fffb_start = _dvr_time_getClock(); |
| 2347 | player->fffb_current = player->fffb_start; |
| 2348 | //get segment current time pos |
| 2349 | player->fffb_start_pcr = _dvr_get_cur_time(handle); |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 2350 | 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] | 2351 | t_diff = 0; |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 2352 | //default first time 1ms seek |
hualing chen | 87072a8 | 2020-03-12 16:20:12 +0800 | [diff] [blame] | 2353 | seek_time = FB_MIX_SEEK_TIME; |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 2354 | } else { |
| 2355 | player->fffb_current = _dvr_time_getClock(); |
| 2356 | t_diff = player->fffb_current - player->fffb_start; |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 2357 | //if speed is < 0, cmd is fb. |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 2358 | seek_time = player->fffb_start_pcr + t_diff *player->speed; |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 2359 | if (seek_time <= 0) { |
| 2360 | //need seek to pre one segment |
| 2361 | seek_time = 0; |
| 2362 | } |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 2363 | //seek segment pos |
| 2364 | if (player->r_handle) { |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 2365 | pthread_mutex_lock(&player->segment_lock); |
hualing chen | 041c409 | 2020-04-05 15:11:50 +0800 | [diff] [blame] | 2366 | if (segment_seek(player->r_handle, seek_time, player->openParams.block_size) == DVR_FAILURE) { |
| 2367 | seek_time = 0; |
| 2368 | } |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 2369 | pthread_mutex_unlock(&player->segment_lock); |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 2370 | } else { |
| 2371 | // |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 2372 | DVR_PB_DG(1, "segment not open,can not seek"); |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 2373 | } |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 2374 | 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] | 2375 | } |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 2376 | return seek_time; |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 2377 | } |
| 2378 | |
| 2379 | |
| 2380 | //start replay |
| 2381 | static int _dvr_playback_fffb_replay(DVR_PlaybackHandle_t handle) { |
| 2382 | // |
| 2383 | DVR_Playback_t *player = (DVR_Playback_t *) handle; |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 2384 | |
| 2385 | if (player == NULL) { |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 2386 | DVR_PB_DG(1, "player is NULL"); |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 2387 | return DVR_FAILURE; |
| 2388 | } |
| 2389 | |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 2390 | //stop |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 2391 | if (player->has_video) { |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 2392 | DVR_PB_DG(1, "fffb stop video"); |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 2393 | AmTsPlayer_stopVideoDecoding(player->handle); |
| 2394 | } |
| 2395 | if (player->has_audio) { |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 2396 | DVR_PB_DG(1, "fffb stop audio"); |
hualing chen | 266b950 | 2020-04-04 17:39:39 +0800 | [diff] [blame] | 2397 | player->has_audio =DVR_FALSE; |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 2398 | AmTsPlayer_stopAudioDecoding(player->handle); |
| 2399 | } |
| 2400 | |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 2401 | //start video and audio |
| 2402 | |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 2403 | am_tsplayer_video_params vparams; |
| 2404 | am_tsplayer_audio_params aparams; |
hualing chen | 87072a8 | 2020-03-12 16:20:12 +0800 | [diff] [blame] | 2405 | uint64_t segment_id = player->cur_segment_id; |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 2406 | |
| 2407 | //get segment info and audio video pid fmt ; |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame] | 2408 | //pthread_mutex_lock(&player->lock); |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 2409 | _dvr_playback_get_playinfo(handle, segment_id, &vparams, &aparams); |
| 2410 | //start audio and video |
| 2411 | if (!VALID_PID(vparams.pid) && !VALID_PID(aparams.pid)) { |
| 2412 | //audio abnd video pis is all invalid, return error. |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 2413 | 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] | 2414 | //pthread_mutex_unlock(&player->lock); |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 2415 | return -1; |
| 2416 | } |
| 2417 | |
| 2418 | if (VALID_PID(vparams.pid)) { |
| 2419 | player->has_video = DVR_TRUE; |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 2420 | DVR_PB_DG(1, "fffb start video"); |
hualing chen | 3114087 | 2020-03-25 12:29:26 +0800 | [diff] [blame] | 2421 | AmTsPlayer_setTrickMode(player->handle, AV_VIDEO_TRICK_MODE_NONE); |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 2422 | AmTsPlayer_setTrickMode(player->handle, AV_VIDEO_TRICK_MODE_PAUSE_NEXT); |
| 2423 | AmTsPlayer_setVideoParams(player->handle, &vparams); |
| 2424 | AmTsPlayer_startVideoDecoding(player->handle); |
| 2425 | //playback_device_video_start(player->handle , &vparams); |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 2426 | //if set flag is pause live, we need set trick mode |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 2427 | //playback_device_trick_mode(player->handle, 1); |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 2428 | } |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 2429 | if (0 && VALID_PID(aparams.pid)) { |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 2430 | player->has_audio = DVR_TRUE; |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 2431 | DVR_PB_DG(1, "fffb start audio"); |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 2432 | AmTsPlayer_setAudioParams(player->handle, &aparams); |
| 2433 | AmTsPlayer_startAudioDecoding(player->handle); |
| 2434 | //playback_device_audio_start(player->handle , &aparams); |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 2435 | } |
hualing chen | 3114087 | 2020-03-25 12:29:26 +0800 | [diff] [blame] | 2436 | //fffb mode need stop fast; |
hualing chen | 7a56cba | 2020-04-14 14:09:27 +0800 | [diff] [blame^] | 2437 | DVR_PB_DG(1, "stop fast"); |
hualing chen | 3114087 | 2020-03-25 12:29:26 +0800 | [diff] [blame] | 2438 | AmTsPlayer_stopFast(player->handle); |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame] | 2439 | //pthread_mutex_unlock(&player->lock); |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 2440 | return 0; |
| 2441 | } |
| 2442 | |
| 2443 | static int _dvr_playback_fffb(DVR_PlaybackHandle_t handle) { |
| 2444 | DVR_Playback_t *player = (DVR_Playback_t *) handle; |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 2445 | |
| 2446 | if (player == NULL) { |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 2447 | DVR_PB_DG(1, "player is NULL"); |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 2448 | return DVR_FAILURE; |
| 2449 | } |
| 2450 | |
| 2451 | player->first_frame = 0; |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 2452 | DVR_PB_DG(1, "lock speed [%f]", player->speed); |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 2453 | pthread_mutex_lock(&player->lock); |
| 2454 | |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 2455 | int seek_time = _dvr_playback_calculate_seekpos(handle); |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 2456 | 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] | 2457 | |
hualing chen | 87072a8 | 2020-03-12 16:20:12 +0800 | [diff] [blame] | 2458 | if (_dvr_has_next_segmentId(handle, player->cur_segment_id) == DVR_FAILURE && seek_time < FB_MIX_SEEK_TIME && IS_FB(player->speed)) { |
| 2459 | //seek time set 0 |
| 2460 | seek_time = 0; |
| 2461 | } |
hualing chen | 041c409 | 2020-04-05 15:11:50 +0800 | [diff] [blame] | 2462 | if (seek_time == 0) { |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 2463 | //for fb cmd, we need open pre segment.if reach first one segment, send begin event |
| 2464 | int ret = _change_to_next_segment((DVR_PlaybackHandle_t)player); |
hualing chen | 041c409 | 2020-04-05 15:11:50 +0800 | [diff] [blame] | 2465 | if (ret != DVR_SUCCESS && IS_FB(player->speed)) { |
hualing chen | 87072a8 | 2020-03-12 16:20:12 +0800 | [diff] [blame] | 2466 | pthread_mutex_unlock(&player->lock); |
| 2467 | dvr_playback_pause(handle, DVR_FALSE); |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 2468 | //send event here and pause |
| 2469 | DVR_Play_Notify_t notify; |
| 2470 | memset(¬ify, 0 , sizeof(DVR_Play_Notify_t)); |
hualing chen | 87072a8 | 2020-03-12 16:20:12 +0800 | [diff] [blame] | 2471 | notify.event = DVR_PLAYBACK_EVENT_REACHED_BEGIN; |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 2472 | //get play statue not here |
| 2473 | _dvr_playback_sent_event(handle, DVR_PLAYBACK_EVENT_REACHED_BEGIN, ¬ify); |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 2474 | 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] | 2475 | //change to pause |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 2476 | return DVR_SUCCESS; |
| 2477 | } |
hualing chen | 87072a8 | 2020-03-12 16:20:12 +0800 | [diff] [blame] | 2478 | _dvr_playback_sent_transition_ok(handle); |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 2479 | _dvr_init_fffb_time(handle); |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 2480 | DVR_PB_DG(1, "*******************send trans ok event speed [%f]", player->speed); |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 2481 | } |
| 2482 | player->next_fffb_time =_dvr_time_getClock() + FFFB_SLEEP_TIME; |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 2483 | _dvr_playback_fffb_replay(handle); |
| 2484 | |
| 2485 | pthread_mutex_unlock(&player->lock); |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 2486 | DVR_PB_DG(1, "unlock"); |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 2487 | |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 2488 | return DVR_SUCCESS; |
| 2489 | } |
| 2490 | |
hualing chen | 87072a8 | 2020-03-12 16:20:12 +0800 | [diff] [blame] | 2491 | //start replay, need get lock at extern |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 2492 | 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] | 2493 | // |
| 2494 | DVR_Playback_t *player = (DVR_Playback_t *) handle; |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 2495 | |
| 2496 | if (player == NULL) { |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 2497 | DVR_PB_DG(1, "player is NULL"); |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 2498 | return DVR_FAILURE; |
| 2499 | } |
| 2500 | |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 2501 | //stop |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 2502 | if (player->has_video) { |
hualing chen | 266b950 | 2020-04-04 17:39:39 +0800 | [diff] [blame] | 2503 | player->has_video = DVR_FALSE; |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 2504 | AmTsPlayer_stopVideoDecoding(player->handle); |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 2505 | } |
| 2506 | |
| 2507 | if (player->has_audio) { |
hualing chen | 266b950 | 2020-04-04 17:39:39 +0800 | [diff] [blame] | 2508 | player->has_audio = DVR_FALSE; |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 2509 | AmTsPlayer_stopAudioDecoding(player->handle); |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 2510 | } |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 2511 | //start video and audio |
| 2512 | |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 2513 | am_tsplayer_video_params vparams; |
| 2514 | am_tsplayer_audio_params aparams; |
hualing chen | 87072a8 | 2020-03-12 16:20:12 +0800 | [diff] [blame] | 2515 | uint64_t segment_id = player->cur_segment_id; |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 2516 | |
| 2517 | //get segment info and audio video pid fmt ; |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 2518 | DVR_PB_DG(1, "into"); |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 2519 | _dvr_playback_get_playinfo(handle, segment_id, &vparams, &aparams); |
| 2520 | //start audio and video |
| 2521 | if (!VALID_PID(vparams.pid) && !VALID_PID(aparams.pid)) { |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 2522 | //audio and video pis is all invalid, return error. |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 2523 | 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] | 2524 | return -1; |
| 2525 | } |
| 2526 | |
| 2527 | if (VALID_PID(vparams.pid)) { |
| 2528 | player->has_video = DVR_TRUE; |
hualing chen | 87072a8 | 2020-03-12 16:20:12 +0800 | [diff] [blame] | 2529 | if (trick == DVR_TRUE) { |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 2530 | DVR_PB_DG(1, "settrick mode at replay"); |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 2531 | AmTsPlayer_setTrickMode(player->handle, AV_VIDEO_TRICK_MODE_PAUSE_NEXT); |
hualing chen | 87072a8 | 2020-03-12 16:20:12 +0800 | [diff] [blame] | 2532 | } |
hualing chen | 266b950 | 2020-04-04 17:39:39 +0800 | [diff] [blame] | 2533 | else { |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 2534 | AmTsPlayer_setTrickMode(player->handle, AV_VIDEO_TRICK_MODE_NONE); |
hualing chen | 266b950 | 2020-04-04 17:39:39 +0800 | [diff] [blame] | 2535 | } |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 2536 | AmTsPlayer_setVideoParams(player->handle, &vparams); |
| 2537 | AmTsPlayer_startVideoDecoding(player->handle); |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 2538 | } |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 2539 | |
| 2540 | if (IS_FAST_SPEED(player->cmd.speed.speed.speed)) { |
hualing chen | 7a56cba | 2020-04-14 14:09:27 +0800 | [diff] [blame^] | 2541 | DVR_PB_DG(1, "start fast"); |
hualing chen | 3114087 | 2020-03-25 12:29:26 +0800 | [diff] [blame] | 2542 | AmTsPlayer_startFast(player->handle, (float)player->cmd.speed.speed.speed/(float)100); |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 2543 | player->speed = (float)player->cmd.speed.speed.speed/100.0f; |
hualing chen | 3114087 | 2020-03-25 12:29:26 +0800 | [diff] [blame] | 2544 | } else { |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 2545 | if (VALID_PID(aparams.pid)) { |
| 2546 | player->has_audio = DVR_TRUE; |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 2547 | DVR_PB_DG(1, "start audio"); |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 2548 | AmTsPlayer_startAudioDecoding(player->handle); |
| 2549 | AmTsPlayer_setAudioParams(player->handle, &aparams); |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 2550 | } |
hualing chen | 7a56cba | 2020-04-14 14:09:27 +0800 | [diff] [blame^] | 2551 | DVR_PB_DG(1, "stop fast"); |
hualing chen | 3114087 | 2020-03-25 12:29:26 +0800 | [diff] [blame] | 2552 | AmTsPlayer_stopFast(player->handle); |
| 2553 | player->cmd.speed.speed.speed = PLAYBACK_SPEED_X1; |
| 2554 | player->speed = (float)PLAYBACK_SPEED_X1/100.0f; |
| 2555 | } |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 2556 | player->cmd.last_cmd = player->cmd.cur_cmd; |
| 2557 | player->cmd.cur_cmd = DVR_PLAYBACK_CMD_START; |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 2558 | player->cmd.state = DVR_PLAYBACK_STATE_START; |
| 2559 | player->state = DVR_PLAYBACK_STATE_START; |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 2560 | return 0; |
| 2561 | } |
| 2562 | |
| 2563 | |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 2564 | /**\brief Set play speed |
| 2565 | * \param[in] handle playback handle |
| 2566 | * \param[in] speed playback speed |
| 2567 | * \retval DVR_SUCCESS On success |
| 2568 | * \return Error code |
| 2569 | */ |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 2570 | int dvr_playback_set_speed(DVR_PlaybackHandle_t handle, DVR_PlaybackSpeed_t speed) { |
| 2571 | |
| 2572 | DVR_Playback_t *player = (DVR_Playback_t *) handle; |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 2573 | |
| 2574 | if (player == NULL) { |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 2575 | DVR_PB_DG(1, "player is NULL"); |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 2576 | return DVR_FAILURE; |
| 2577 | } |
| 2578 | |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 2579 | DVR_PB_DG(1, "lock func: speed [%d]", speed.speed.speed); |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 2580 | if (_dvr_support_speed(speed.speed.speed) == DVR_FALSE) { |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 2581 | DVR_PB_DG(1, " func: not support speed [%d]", speed.speed.speed); |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 2582 | return DVR_FAILURE; |
| 2583 | } |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 2584 | pthread_mutex_lock(&player->lock); |
| 2585 | if (player->cmd.cur_cmd != DVR_PLAYBACK_CMD_FF |
| 2586 | && player->cmd.cur_cmd != DVR_PLAYBACK_CMD_FB) { |
| 2587 | player->cmd.last_cmd = player->cmd.cur_cmd; |
| 2588 | } |
hualing chen | 3114087 | 2020-03-25 12:29:26 +0800 | [diff] [blame] | 2589 | if (player->state != DVR_PLAYBACK_STATE_PAUSE && |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 2590 | IS_KERNEL_SPEED(speed.speed.speed)) { |
| 2591 | //case 1. cur speed is 100,set 200 50 25 12 . |
| 2592 | //we think x1 and x2 s1/2 s 1/4 s 1/8 is normal speed. is not ff fb. |
| 2593 | if (IS_KERNEL_SPEED(player->cmd.speed.speed.speed)) { |
hualing chen | 87072a8 | 2020-03-12 16:20:12 +0800 | [diff] [blame] | 2594 | //if last speed is x2 or s2, we need stop fast |
hualing chen | 2bd8a7a | 2020-04-02 11:31:03 +0800 | [diff] [blame] | 2595 | if (speed.speed.speed == PLAYBACK_SPEED_X1) { |
| 2596 | // resume audio and stop fast play |
hualing chen | 7a56cba | 2020-04-14 14:09:27 +0800 | [diff] [blame^] | 2597 | DVR_PB_DG(1, "stop fast"); |
hualing chen | 2bd8a7a | 2020-04-02 11:31:03 +0800 | [diff] [blame] | 2598 | AmTsPlayer_stopFast(player->handle); |
| 2599 | pthread_mutex_unlock(&player->lock); |
| 2600 | _dvr_cmd(handle, DVR_PLAYBACK_CMD_ASTART); |
| 2601 | pthread_mutex_lock(&player->lock); |
| 2602 | } else { |
| 2603 | //set play speed and if audio is start, stop audio. |
| 2604 | if (player->has_audio) { |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 2605 | DVR_PB_DG(1, "fast play stop audio"); |
hualing chen | 2bd8a7a | 2020-04-02 11:31:03 +0800 | [diff] [blame] | 2606 | AmTsPlayer_stopAudioDecoding(player->handle); |
| 2607 | player->has_audio = DVR_FALSE; |
| 2608 | } |
| 2609 | AmTsPlayer_startFast(player->handle, (float)speed.speed.speed/(float)100); |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 2610 | } |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 2611 | player->cmd.speed.mode = DVR_PLAYBACK_KERNEL_SUPPORT; |
hualing chen | 3114087 | 2020-03-25 12:29:26 +0800 | [diff] [blame] | 2612 | player->cmd.speed.speed = speed.speed; |
| 2613 | player->speed = (float)speed.speed.speed/(float)100; |
| 2614 | pthread_mutex_unlock(&player->lock); |
| 2615 | return DVR_SUCCESS; |
| 2616 | } |
| 2617 | //case 2. not start play |
| 2618 | if (player->state == DVR_PLAYBACK_STATE_STOP) { |
| 2619 | //only set speed.and return; |
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 | pthread_mutex_unlock(&player->lock); |
| 2624 | return DVR_SUCCESS; |
hualing chen | 87072a8 | 2020-03-12 16:20:12 +0800 | [diff] [blame] | 2625 | } |
hualing chen | 3114087 | 2020-03-25 12:29:26 +0800 | [diff] [blame] | 2626 | //case 3 fffb mode |
| 2627 | if (player->cmd.cur_cmd == DVR_PLAYBACK_CMD_FF || |
| 2628 | player->cmd.cur_cmd == DVR_PLAYBACK_CMD_FB) { |
| 2629 | //restart play at normal speed exit ff fb |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 2630 | DVR_PB_DG(1, "set speed normal and replay playback"); |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 2631 | player->cmd.speed.mode = DVR_PLAYBACK_KERNEL_SUPPORT; |
hualing chen | 3114087 | 2020-03-25 12:29:26 +0800 | [diff] [blame] | 2632 | player->cmd.speed.speed = speed.speed; |
| 2633 | player->speed = (float)speed.speed.speed/(float)100; |
| 2634 | _dvr_playback_replay(handle, DVR_FALSE); |
| 2635 | pthread_mutex_unlock(&player->lock); |
| 2636 | return DVR_SUCCESS; |
| 2637 | } |
| 2638 | } |
| 2639 | else if (player->state == DVR_PLAYBACK_STATE_PAUSE && |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 2640 | IS_KERNEL_SPEED(speed.speed.speed)) { |
| 2641 | //case 1. cur speed is kernel support speed,set kernel speed. |
| 2642 | if (IS_KERNEL_SPEED(player->cmd.speed.speed.speed)) { |
hualing chen | 3114087 | 2020-03-25 12:29:26 +0800 | [diff] [blame] | 2643 | //if last speed is x2 or s2, we need stop fast |
hualing chen | 2bd8a7a | 2020-04-02 11:31:03 +0800 | [diff] [blame] | 2644 | if (speed.speed.speed == PLAYBACK_SPEED_X1) { |
| 2645 | // resume audio and stop fast play |
hualing chen | 7a56cba | 2020-04-14 14:09:27 +0800 | [diff] [blame^] | 2646 | DVR_PB_DG(1, "stop fast"); |
hualing chen | 2bd8a7a | 2020-04-02 11:31:03 +0800 | [diff] [blame] | 2647 | AmTsPlayer_stopFast(player->handle); |
| 2648 | pthread_mutex_unlock(&player->lock); |
| 2649 | _dvr_cmd(handle, DVR_PLAYBACK_CMD_ASTART); |
| 2650 | pthread_mutex_lock(&player->lock); |
| 2651 | } else { |
| 2652 | //set play speed and if audio is start, stop audio. |
| 2653 | if (player->has_audio) { |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 2654 | DVR_PB_DG(1, "fast play stop audio at pause"); |
hualing chen | 2bd8a7a | 2020-04-02 11:31:03 +0800 | [diff] [blame] | 2655 | AmTsPlayer_stopAudioDecoding(player->handle); |
| 2656 | player->has_audio = DVR_FALSE; |
| 2657 | } |
| 2658 | AmTsPlayer_startFast(player->handle, (float)speed.speed.speed/(float)100); |
| 2659 | } |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 2660 | player->cmd.speed.mode = DVR_PLAYBACK_KERNEL_SUPPORT; |
hualing chen | 3114087 | 2020-03-25 12:29:26 +0800 | [diff] [blame] | 2661 | player->cmd.speed.speed = speed.speed; |
| 2662 | player->speed = (float)speed.speed.speed/(float)100; |
| 2663 | pthread_mutex_unlock(&player->lock); |
| 2664 | return DVR_SUCCESS; |
| 2665 | } |
| 2666 | //case 2 fffb mode |
| 2667 | if (player->cmd.cur_cmd == DVR_PLAYBACK_CMD_FF || |
| 2668 | player->cmd.cur_cmd == DVR_PLAYBACK_CMD_FB) { |
| 2669 | //restart play at normal speed exit ff fb |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 2670 | DVR_PB_DG(1, "set speed x1 s2 and replay playback"); |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 2671 | player->cmd.speed.mode = DVR_PLAYBACK_KERNEL_SUPPORT; |
hualing chen | 3114087 | 2020-03-25 12:29:26 +0800 | [diff] [blame] | 2672 | player->cmd.speed.speed = speed.speed; |
| 2673 | player->speed = (float)speed.speed.speed/(float)100; |
| 2674 | player->cmd.cur_cmd = DVR_PLAYBACK_CMD_AVRESTART; |
| 2675 | pthread_mutex_unlock(&player->lock); |
| 2676 | return DVR_SUCCESS; |
| 2677 | } |
hualing chen | 3114087 | 2020-03-25 12:29:26 +0800 | [diff] [blame] | 2678 | } |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 2679 | if (IS_KERNEL_SPEED(speed.speed.speed)) { |
| 2680 | //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] | 2681 | } else { |
hualing chen | 3114087 | 2020-03-25 12:29:26 +0800 | [diff] [blame] | 2682 | if ((float)speed.speed.speed > 1.0f) |
hualing chen | 87072a8 | 2020-03-12 16:20:12 +0800 | [diff] [blame] | 2683 | player->cmd.cur_cmd = DVR_PLAYBACK_CMD_FF; |
| 2684 | else |
| 2685 | player->cmd.cur_cmd = DVR_PLAYBACK_CMD_FB; |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 2686 | player->fffb_play = DVR_TRUE; |
| 2687 | } |
| 2688 | DVR_Bool_t init_last_time = DVR_FALSE; |
| 2689 | if (player->speed > 0.0f && speed.speed.speed < 0) { |
| 2690 | init_last_time = DVR_TRUE; |
| 2691 | } else if (player->speed < 0.0f && speed.speed.speed > 0) { |
| 2692 | init_last_time = DVR_TRUE; |
hualing chen | 87072a8 | 2020-03-12 16:20:12 +0800 | [diff] [blame] | 2693 | } |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 2694 | player->cmd.speed.mode = speed.mode; |
| 2695 | player->cmd.speed.speed = speed.speed; |
hualing chen | 3114087 | 2020-03-25 12:29:26 +0800 | [diff] [blame] | 2696 | player->speed = (float)speed.speed.speed/(float)100; |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 2697 | #if 0 |
| 2698 | if (abs((int)(player->speed)) > 1) { |
| 2699 | //seek speed*1000 ms at fb mode |
| 2700 | pthread_mutex_lock(&player->segment_lock); |
| 2701 | uint64_t cur = segment_tell_current_time(player->r_handle); |
| 2702 | int diff = abs((int)(player->speed * 1000)); |
| 2703 | DVR_PB_DG(1, " cur:%ull diff:%d", cur, diff); |
| 2704 | if (cur > diff) |
| 2705 | cur = cur - diff; |
| 2706 | else |
| 2707 | cur = 0; |
| 2708 | segment_seek(player->r_handle, cur, player->openParams.block_size); |
| 2709 | pthread_mutex_unlock(&player->segment_lock); |
| 2710 | } |
| 2711 | #endif |
hualing chen | 3114087 | 2020-03-25 12:29:26 +0800 | [diff] [blame] | 2712 | //reset fffb time, if change speed value |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 2713 | _dvr_init_fffb_t(handle); |
| 2714 | if (init_last_time == DVR_TRUE) |
| 2715 | player->last_send_time_id = UINT64_MAX; |
| 2716 | |
hualing chen | 87072a8 | 2020-03-12 16:20:12 +0800 | [diff] [blame] | 2717 | if (speed.speed.speed == PLAYBACK_SPEED_X1 && |
hualing chen | 6d24aa9 | 2020-03-23 18:43:47 +0800 | [diff] [blame] | 2718 | (player->cmd.cur_cmd == DVR_PLAYBACK_CMD_FF || |
| 2719 | player->cmd.cur_cmd == DVR_PLAYBACK_CMD_FB)) { |
hualing chen | 87072a8 | 2020-03-12 16:20:12 +0800 | [diff] [blame] | 2720 | //restart play at normal speed exit ff fb |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 2721 | DVR_PB_DG(1, "set speed normal and replay playback"); |
hualing chen | 87072a8 | 2020-03-12 16:20:12 +0800 | [diff] [blame] | 2722 | _dvr_playback_replay(handle, DVR_FALSE); |
| 2723 | } else if (speed.speed.speed == PLAYBACK_SPEED_X1 && |
| 2724 | (player->state == DVR_PLAYBACK_STATE_PAUSE)) { |
| 2725 | player->cmd.cur_cmd = DVR_PLAYBACK_CMD_AVRESTART; |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 2726 | 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] | 2727 | } |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 2728 | //need exit ff fb |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 2729 | 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] | 2730 | pthread_mutex_unlock(&player->lock); |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 2731 | return DVR_SUCCESS; |
| 2732 | } |
| 2733 | /**\brief Get playback status |
| 2734 | * \param[in] handle playback handle |
| 2735 | * \param[out] p_status playback status |
| 2736 | * \retval DVR_SUCCESS On success |
| 2737 | * \return Error code |
| 2738 | */ |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 2739 | int dvr_playback_get_status(DVR_PlaybackHandle_t handle, |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 2740 | DVR_PlaybackStatus_t *p_status) { |
| 2741 | // |
| 2742 | DVR_Playback_t *player = (DVR_Playback_t *) handle; |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 2743 | |
| 2744 | if (player == NULL) { |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 2745 | DVR_PB_DG(1, "player is NULL"); |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 2746 | return DVR_FAILURE; |
| 2747 | } |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 2748 | |
| 2749 | p_status->state = player->state; |
hualing chen | 3114087 | 2020-03-25 12:29:26 +0800 | [diff] [blame] | 2750 | //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] | 2751 | if ((player->play_flag&DVR_PLAYBACK_STARTED_PAUSEDLIVE) == DVR_PLAYBACK_STARTED_PAUSEDLIVE && |
| 2752 | player->state == DVR_PLAYBACK_STATE_START) { |
| 2753 | p_status->state = DVR_PLAYBACK_STATE_PAUSE; |
| 2754 | } |
hualing chen | 041c409 | 2020-04-05 15:11:50 +0800 | [diff] [blame] | 2755 | |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame] | 2756 | p_status->time_end = _dvr_get_end_time(handle); |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 2757 | p_status->time_cur = _dvr_get_cur_time(handle); |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 2758 | if (player->last_send_time_id == UINT64_MAX) { |
| 2759 | player->last_send_time_id = player->cur_segment_id; |
| 2760 | player->last_cur_time = p_status->time_cur; |
| 2761 | } |
| 2762 | if (player->last_send_time_id == player->cur_segment_id) { |
| 2763 | if (player->speed > 0.0f ) { |
| 2764 | //ff |
| 2765 | if (p_status->time_cur < player->last_cur_time ) { |
| 2766 | 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); |
| 2767 | p_status->time_cur = player->last_cur_time; |
| 2768 | } else { |
| 2769 | player->last_cur_time = p_status->time_cur; |
| 2770 | } |
| 2771 | } else if (player->speed < -1.0f){ |
| 2772 | //fb |
| 2773 | if (p_status->time_cur > player->last_cur_time ) { |
| 2774 | 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 ); |
| 2775 | p_status->time_cur = player->last_cur_time; |
| 2776 | } else { |
| 2777 | player->last_cur_time = p_status->time_cur; |
| 2778 | } |
| 2779 | } |
| 2780 | } else { |
| 2781 | player->last_cur_time = p_status->time_cur; |
| 2782 | } |
| 2783 | player->last_send_time_id = player->cur_segment_id; |
hualing chen | 041c409 | 2020-04-05 15:11:50 +0800 | [diff] [blame] | 2784 | p_status->segment_id = player->cur_segment_id; |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 2785 | |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 2786 | memcpy(&p_status->pids, &player->cur_segment.pids, sizeof(DVR_PlaybackPids_t)); |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame] | 2787 | p_status->speed = player->cmd.speed.speed.speed; |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 2788 | p_status->flags = player->cur_segment.flags; |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 2789 | 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] | 2790 | _dvr_playback_state_toString(player->state), |
| 2791 | _dvr_playback_state_toString(p_status->state), |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 2792 | p_status->time_cur, p_status->time_end, |
| 2793 | p_status->segment_id,player->play_flag, |
| 2794 | player->speed); |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 2795 | return DVR_SUCCESS; |
| 2796 | } |
| 2797 | |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 2798 | void _dvr_dump_segment(DVR_PlaybackSegmentInfo_t *segment) { |
| 2799 | if (segment != NULL) { |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 2800 | DVR_PB_DG(1, "segment id: %lld", segment->segment_id); |
| 2801 | DVR_PB_DG(1, "segment flag: %d", segment->flags); |
| 2802 | DVR_PB_DG(1, "segment location: [%s]", segment->location); |
| 2803 | DVR_PB_DG(1, "segment vpid: 0x%x vfmt:0x%x", segment->pids.video.pid,segment->pids.video.format); |
| 2804 | DVR_PB_DG(1, "segment apid: 0x%x afmt:0x%x", segment->pids.audio.pid,segment->pids.audio.format); |
| 2805 | DVR_PB_DG(1, "segment pcr pid: 0x%x pcr fmt:0x%x", segment->pids.pcr.pid,segment->pids.pcr.format); |
| 2806 | 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] | 2807 | } |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 2808 | } |
| 2809 | |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 2810 | int dvr_dump_segmentinfo(DVR_PlaybackHandle_t handle, uint64_t segment_id) { |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 2811 | DVR_Playback_t *player = (DVR_Playback_t *) handle; |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 2812 | |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 2813 | if (player == NULL) { |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 2814 | DVR_PB_DG(1, "player is NULL"); |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 2815 | return DVR_FAILURE; |
| 2816 | } |
| 2817 | |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 2818 | DVR_PlaybackSegmentInfo_t *segment; |
| 2819 | list_for_each_entry(segment, &player->segment_list, head) |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 2820 | { |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 2821 | if (segment_id >= 0) { |
| 2822 | if (segment->segment_id == segment_id) { |
| 2823 | _dvr_dump_segment(segment); |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 2824 | break; |
| 2825 | } |
| 2826 | } else { |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 2827 | //printf segment info |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 2828 | _dvr_dump_segment(segment); |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 2829 | } |
| 2830 | } |
| 2831 | return 0; |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 2832 | } |
pengfei.liu | 07ddc8a | 2020-03-24 23:36:53 +0800 | [diff] [blame] | 2833 | |
pengfei.liu | 27cc4ec | 2020-04-03 16:28:16 +0800 | [diff] [blame] | 2834 | 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] | 2835 | { |
| 2836 | DVR_Playback_t *player = (DVR_Playback_t *) handle; |
| 2837 | DVR_RETURN_IF_FALSE(player); |
| 2838 | DVR_RETURN_IF_FALSE(func); |
| 2839 | |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 2840 | DVR_PB_DG(1, "in "); |
pengfei.liu | 07ddc8a | 2020-03-24 23:36:53 +0800 | [diff] [blame] | 2841 | pthread_mutex_lock(&player->lock); |
| 2842 | |
| 2843 | player->dec_func = func; |
| 2844 | player->dec_userdata = userdata; |
| 2845 | |
| 2846 | pthread_mutex_unlock(&player->lock); |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 2847 | DVR_PB_DG(1, "out "); |
pengfei.liu | 07ddc8a | 2020-03-24 23:36:53 +0800 | [diff] [blame] | 2848 | return DVR_SUCCESS; |
| 2849 | } |
| 2850 | |
| 2851 | int dvr_playback_set_secure_buffer(DVR_PlaybackHandle_t handle, uint8_t *p_secure_buf, uint32_t len) |
| 2852 | { |
| 2853 | DVR_Playback_t *player = (DVR_Playback_t *) handle; |
| 2854 | DVR_RETURN_IF_FALSE(player); |
| 2855 | DVR_RETURN_IF_FALSE(p_secure_buf); |
| 2856 | DVR_RETURN_IF_FALSE(len); |
| 2857 | |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 2858 | DVR_PB_DG(1, "in "); |
pengfei.liu | 07ddc8a | 2020-03-24 23:36:53 +0800 | [diff] [blame] | 2859 | pthread_mutex_lock(&player->lock); |
| 2860 | |
| 2861 | player->is_secure_mode = 1; |
| 2862 | player->secure_buffer = p_secure_buf; |
| 2863 | player->secure_buffer_size = len; |
| 2864 | |
| 2865 | pthread_mutex_unlock(&player->lock); |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 2866 | DVR_PB_DG(1, "out"); |
pengfei.liu | 07ddc8a | 2020-03-24 23:36:53 +0800 | [diff] [blame] | 2867 | return DVR_SUCCESS; |
| 2868 | } |