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> |
Wentao MA | 361eaac | 2023-03-21 13:12:28 +0800 | [diff] [blame] | 8 | #include <sys/prctl.h> |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 9 | #include <fcntl.h> |
| 10 | #include <unistd.h> |
| 11 | #include <poll.h> |
| 12 | #include <errno.h> |
| 13 | #include <signal.h> |
| 14 | #include <pthread.h> |
hualing chen | b5cd42e | 2020-04-15 17:03:34 +0800 | [diff] [blame] | 15 | #include <errno.h> |
hualing chen | 03fd494 | 2021-07-15 15:56:41 +0800 | [diff] [blame] | 16 | #include "dvr_utils.h" |
| 17 | #include "dvr_types.h" |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 18 | #include "dvr_playback.h" |
Yahui Han | 1fbf329 | 2021-11-08 18:17:19 +0800 | [diff] [blame] | 19 | #include "am_crypt.h" |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 20 | |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 21 | #define PB_LOG_TAG "libdvr-playback" |
| 22 | #define DVR_PB_DEBUG(...) DVR_LOG_PRINT(LOG_LV_DEBUG, PB_LOG_TAG, __VA_ARGS__) |
| 23 | #define DVR_PB_INFO(...) DVR_LOG_PRINT(LOG_LV_INFO, PB_LOG_TAG, __VA_ARGS__) |
| 24 | #define DVR_PB_WARN(...) DVR_LOG_PRINT(LOG_LV_WARN, PB_LOG_TAG, __VA_ARGS__) |
| 25 | #define DVR_PB_ERROR(...) DVR_LOG_PRINT(LOG_LV_ERROR, PB_LOG_TAG, __VA_ARGS__) |
| 26 | #define DVR_PB_FATAL(...) DVR_LOG_PRINT(LOG_LV_FATAL, PB_LOG_TAG, __VA_ARGS__) |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 27 | |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 28 | #define VALID_PID(_pid_) ((_pid_)>0 && (_pid_)<0x1fff) |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 29 | |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 30 | #define FF_SPEED (2.0f) |
| 31 | #define FB_SPEED (-1.0f) |
| 32 | #define IS_FFFB(_SPEED_) ((_SPEED_) > FF_SPEED && (_SPEED_) < FB_SPEED) |
hualing chen | e41f437 | 2020-06-06 16:29:17 +0800 | [diff] [blame] | 33 | #define IS_FB(_SPEED_) ((_SPEED_) <= FB_SPEED) |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 34 | |
| 35 | #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)) |
| 36 | #define IS_FAST_SPEED(_SPEED_) (((_SPEED_) == PLAYBACK_SPEED_X2) || ((_SPEED_) == PLAYBACK_SPEED_S2) || ((_SPEED_) == PLAYBACK_SPEED_S4) || ((_SPEED_) == PLAYBACK_SPEED_S8)) |
| 37 | |
Wentao MA | 907b643 | 2022-08-01 06:23:08 +0000 | [diff] [blame] | 38 | #define DVR_PLAYER_CHANGE_STATE(player,newstate)\ |
| 39 | DVR_PB_INFO("%s:%d player %p changes state from %s to %s",__func__,__LINE__,\ |
| 40 | player,_dvr_playback_state_toString(player->state),_dvr_playback_state_toString(newstate));\ |
| 41 | player->state=newstate; |
| 42 | |
Wentao MA | 75775d2 | 2023-09-25 16:53:24 +0800 | [diff] [blame^] | 43 | //#define FOR_SKYWORTH_FETCH_RDK |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 44 | |
hualing chen | b5cd42e | 2020-04-15 17:03:34 +0800 | [diff] [blame] | 45 | #define FFFB_SLEEP_TIME (1000)//500ms |
hualing chen | e41f437 | 2020-06-06 16:29:17 +0800 | [diff] [blame] | 46 | #define FB_DEFAULT_LEFT_TIME (3000) |
hualing chen | 3114087 | 2020-03-25 12:29:26 +0800 | [diff] [blame] | 47 | //if tsplayer delay time < 200 and no data can read, we will pause |
| 48 | #define MIN_TSPLAYER_DELAY_TIME (200) |
| 49 | |
hualing chen | 041c409 | 2020-04-05 15:11:50 +0800 | [diff] [blame] | 50 | #define MAX_CACHE_TIME (30000) |
hualing chen | 43a89bc | 2022-01-19 14:31:20 +0800 | [diff] [blame] | 51 | //used pcr to control avsync,default not used |
| 52 | //#define AVSYNC_USED_PCR 1 |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 53 | static int write_success = 0; |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 54 | // |
| 55 | static int _dvr_playback_fffb(DVR_PlaybackHandle_t handle); |
Wentao MA | 6dcdc34 | 2023-01-30 17:03:19 +0800 | [diff] [blame] | 56 | static int _do_handle_pid_update(DVR_PlaybackHandle_t handle, DVR_PlaybackPids_t now_pids, DVR_PlaybackPids_t pids, int type); |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame] | 57 | static int _dvr_get_cur_time(DVR_PlaybackHandle_t handle); |
| 58 | static int _dvr_get_end_time(DVR_PlaybackHandle_t handle); |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 59 | static int _dvr_playback_calculate_seekpos(DVR_PlaybackHandle_t handle); |
hualing chen | 87072a8 | 2020-03-12 16:20:12 +0800 | [diff] [blame] | 60 | static int _dvr_playback_replay(DVR_PlaybackHandle_t handle, DVR_Bool_t trick) ; |
hualing chen | 2932d37 | 2020-04-29 13:44:00 +0800 | [diff] [blame] | 61 | static int _dvr_playback_get_status(DVR_PlaybackHandle_t handle, |
| 62 | DVR_PlaybackStatus_t *p_status, DVR_Bool_t is_lock); |
hualing chen | e41f437 | 2020-06-06 16:29:17 +0800 | [diff] [blame] | 63 | static int _dvr_playback_sent_transition_ok(DVR_PlaybackHandle_t handle, DVR_Bool_t is_lock); |
hualing chen | 7ea70a7 | 2021-09-09 11:25:13 +0800 | [diff] [blame] | 64 | static uint32_t dvr_playback_calculate_last_valid_segment( |
| 65 | DVR_PlaybackHandle_t handle, uint64_t *segmentid, uint32_t *pos); |
Wentao MA | 804bab1 | 2022-11-29 10:01:26 +0800 | [diff] [blame] | 66 | static int get_effective_tsplayer_delay_time(DVR_Playback_t* playback, int *time); |
Wentao MA | 92a1489 | 2023-09-12 18:54:47 +0800 | [diff] [blame] | 67 | static int _dvr_get_play_cur_time(DVR_PlaybackHandle_t handle, uint64_t *id); |
hualing chen | 87072a8 | 2020-03-12 16:20:12 +0800 | [diff] [blame] | 68 | |
hualing chen | bcada02 | 2020-04-22 14:27:01 +0800 | [diff] [blame] | 69 | |
hualing chen | a5f0322 | 2021-12-02 11:22:35 +0800 | [diff] [blame] | 70 | |
hualing chen | bcada02 | 2020-04-22 14:27:01 +0800 | [diff] [blame] | 71 | static char* _cmd_toString(int cmd) |
| 72 | { |
| 73 | |
| 74 | char *string[DVR_PLAYBACK_CMD_NONE+1]={ |
| 75 | "start", |
| 76 | "stop", |
Wentao MA | 270dc0f | 2022-08-23 13:17:26 +0800 | [diff] [blame] | 77 | "v_start", |
| 78 | "a_start", |
| 79 | "v_stop", |
| 80 | "a_stop", |
| 81 | "v_restart", |
| 82 | "a_restart", |
| 83 | "av_restart", |
| 84 | "v_stop_a_start", |
| 85 | "a_stop_v_start", |
| 86 | "v_stop_a_restart", |
| 87 | "a_stop_v_restart", |
| 88 | "v_start_a_restart", |
| 89 | "a_start_v_restart", |
hualing chen | bcada02 | 2020-04-22 14:27:01 +0800 | [diff] [blame] | 90 | "pause", |
| 91 | "resume", |
| 92 | "seek", |
| 93 | "ff", |
| 94 | "fb", |
| 95 | "NONE" |
| 96 | }; |
| 97 | |
| 98 | if (cmd > DVR_PLAYBACK_CMD_NONE) { |
Wentao MA | 270dc0f | 2022-08-23 13:17:26 +0800 | [diff] [blame] | 99 | return "unknown"; |
hualing chen | bcada02 | 2020-04-22 14:27:01 +0800 | [diff] [blame] | 100 | } else { |
| 101 | return string[cmd]; |
| 102 | } |
| 103 | } |
| 104 | |
| 105 | |
Wentao MA | 907b643 | 2022-08-01 06:23:08 +0000 | [diff] [blame] | 106 | static char* _dvr_playback_state_toString(int state) |
hualing chen | 6d24aa9 | 2020-03-23 18:43:47 +0800 | [diff] [blame] | 107 | { |
Wentao MA | 907b643 | 2022-08-01 06:23:08 +0000 | [diff] [blame] | 108 | char *strings[5]={ |
| 109 | "START", |
| 110 | "STOP", |
| 111 | "PAUSE", |
| 112 | "FF", |
| 113 | "FB", |
hualing chen | 6d24aa9 | 2020-03-23 18:43:47 +0800 | [diff] [blame] | 114 | }; |
| 115 | |
Wentao MA | 907b643 | 2022-08-01 06:23:08 +0000 | [diff] [blame] | 116 | if (state >= 5 || state < 0) { |
| 117 | return "UNKNOWN"; |
hualing chen | 6d24aa9 | 2020-03-23 18:43:47 +0800 | [diff] [blame] | 118 | } |
Wentao MA | 907b643 | 2022-08-01 06:23:08 +0000 | [diff] [blame] | 119 | return strings[state]; |
hualing chen | 6d24aa9 | 2020-03-23 18:43:47 +0800 | [diff] [blame] | 120 | } |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 121 | |
| 122 | static DVR_Bool_t _dvr_support_speed(int speed) { |
| 123 | |
| 124 | DVR_Bool_t ret = DVR_FALSE; |
| 125 | |
| 126 | switch (speed) { |
hualing chen | e41f437 | 2020-06-06 16:29:17 +0800 | [diff] [blame] | 127 | case PLAYBACK_SPEED_FBX1: |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 128 | case PLAYBACK_SPEED_FBX2: |
| 129 | case PLAYBACK_SPEED_FBX4: |
| 130 | case PLAYBACK_SPEED_FBX8: |
hualing chen | 041c409 | 2020-04-05 15:11:50 +0800 | [diff] [blame] | 131 | case PLAYBACK_SPEED_FBX16: |
| 132 | case PLAYBACK_SPEED_FBX12: |
| 133 | case PLAYBACK_SPEED_FBX32: |
| 134 | case PLAYBACK_SPEED_FBX48: |
| 135 | case PLAYBACK_SPEED_FBX64: |
| 136 | case PLAYBACK_SPEED_FBX128: |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 137 | case PLAYBACK_SPEED_S2: |
| 138 | case PLAYBACK_SPEED_S4: |
| 139 | case PLAYBACK_SPEED_S8: |
| 140 | case PLAYBACK_SPEED_X1: |
| 141 | case PLAYBACK_SPEED_X2: |
| 142 | case PLAYBACK_SPEED_X4: |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 143 | case PLAYBACK_SPEED_X3: |
| 144 | case PLAYBACK_SPEED_X5: |
| 145 | case PLAYBACK_SPEED_X6: |
| 146 | case PLAYBACK_SPEED_X7: |
hualing chen | 041c409 | 2020-04-05 15:11:50 +0800 | [diff] [blame] | 147 | case PLAYBACK_SPEED_X8: |
| 148 | case PLAYBACK_SPEED_X12: |
| 149 | case PLAYBACK_SPEED_X16: |
| 150 | case PLAYBACK_SPEED_X32: |
| 151 | case PLAYBACK_SPEED_X48: |
| 152 | case PLAYBACK_SPEED_X64: |
| 153 | case PLAYBACK_SPEED_X128: |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 154 | ret = DVR_TRUE; |
| 155 | break; |
| 156 | default: |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 157 | DVR_PB_INFO("not support speed is set [%d]", speed); |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 158 | break; |
| 159 | } |
| 160 | return ret; |
| 161 | } |
Wentao MA | 907b643 | 2022-08-01 06:23:08 +0000 | [diff] [blame] | 162 | |
hualing chen | 6e4bfa5 | 2020-03-13 14:37:11 +0800 | [diff] [blame] | 163 | void _dvr_tsplayer_callback_test(void *user_data, am_tsplayer_event *event) |
| 164 | { |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 165 | DVR_PB_INFO("in callback test "); |
hualing chen | 6e4bfa5 | 2020-03-13 14:37:11 +0800 | [diff] [blame] | 166 | DVR_Playback_t *player = NULL; |
| 167 | if (user_data != NULL) { |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 168 | player = (DVR_Playback_t *) user_data; |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 169 | DVR_PB_INFO("play speed [%f] in callback test ", player->speed); |
hualing chen | 6e4bfa5 | 2020-03-13 14:37:11 +0800 | [diff] [blame] | 170 | } |
| 171 | switch (event->type) { |
| 172 | case AM_TSPLAYER_EVENT_TYPE_VIDEO_CHANGED: |
| 173 | { |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 174 | DVR_PB_INFO("[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] | 175 | event->event.video_format.frame_width, |
| 176 | event->event.video_format.frame_height, |
| 177 | event->event.video_format.frame_rate); |
| 178 | break; |
| 179 | } |
hualing chen | 6e4bfa5 | 2020-03-13 14:37:11 +0800 | [diff] [blame] | 180 | case AM_TSPLAYER_EVENT_TYPE_FIRST_FRAME: |
| 181 | { |
Wentao MA | 16f870e | 2022-09-09 11:00:22 +0800 | [diff] [blame] | 182 | if (player == NULL) { |
| 183 | DVR_PB_WARN("player is null at line %d",__LINE__); |
| 184 | break; |
| 185 | } |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 186 | DVR_PB_INFO("[evt] test AM_TSPLAYER_EVENT_TYPE_FIRST_FRAME\n"); |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 187 | player->first_frame = 1; |
hualing chen | 6e4bfa5 | 2020-03-13 14:37:11 +0800 | [diff] [blame] | 188 | break; |
| 189 | } |
| 190 | default: |
| 191 | break; |
| 192 | } |
| 193 | } |
Wentao MA | 804bab1 | 2022-11-29 10:01:26 +0800 | [diff] [blame] | 194 | |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 195 | void _dvr_tsplayer_callback(void *user_data, am_tsplayer_event *event) |
| 196 | { |
Wentao MA | 804bab1 | 2022-11-29 10:01:26 +0800 | [diff] [blame] | 197 | DVR_Playback_t *play = (DVR_Playback_t*)user_data; |
| 198 | if (play == NULL) { |
| 199 | DVR_PB_WARN("play is invalid in %s",__func__); |
| 200 | return; |
hualing chen | 6e4bfa5 | 2020-03-13 14:37:11 +0800 | [diff] [blame] | 201 | } |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 202 | switch (event->type) { |
hualing chen | 6e4bfa5 | 2020-03-13 14:37:11 +0800 | [diff] [blame] | 203 | case AM_TSPLAYER_EVENT_TYPE_FIRST_FRAME: |
Wentao MA | 804bab1 | 2022-11-29 10:01:26 +0800 | [diff] [blame] | 204 | DVR_PB_INFO("Received AM_TSPLAYER_EVENT_TYPE_FIRST_FRAME"); |
| 205 | if (play->first_trans_ok == DVR_FALSE) { |
| 206 | play->first_trans_ok = DVR_TRUE; |
| 207 | _dvr_playback_sent_transition_ok((DVR_PlaybackHandle_t)play, DVR_FALSE); |
| 208 | } |
| 209 | play->first_frame = 1; |
| 210 | play->seek_pause = DVR_FALSE; |
| 211 | break; |
hualing chen | 487ae6d | 2020-07-22 10:34:11 +0800 | [diff] [blame] | 212 | case AM_TSPLAYER_EVENT_TYPE_DECODE_FIRST_FRAME_AUDIO: |
Wentao MA | 804bab1 | 2022-11-29 10:01:26 +0800 | [diff] [blame] | 213 | DVR_PB_INFO("Received AM_TSPLAYER_EVENT_TYPE_DECODE_FIRST_FRAME_AUDIO"); |
| 214 | if (play->first_trans_ok == DVR_FALSE && play->has_video == DVR_FALSE) { |
| 215 | play->first_trans_ok = DVR_TRUE; |
| 216 | _dvr_playback_sent_transition_ok((DVR_PlaybackHandle_t)play, DVR_FALSE); |
| 217 | } |
| 218 | if (play->has_video == DVR_FALSE) { |
| 219 | play->first_frame = 1; |
| 220 | play->seek_pause = DVR_FALSE; |
| 221 | } |
hualing chen | 487ae6d | 2020-07-22 10:34:11 +0800 | [diff] [blame] | 222 | break; |
hualing chen | 6e4bfa5 | 2020-03-13 14:37:11 +0800 | [diff] [blame] | 223 | default: |
| 224 | break; |
| 225 | } |
Wentao MA | 804bab1 | 2022-11-29 10:01:26 +0800 | [diff] [blame] | 226 | if (play->player_callback_func == NULL) { |
| 227 | DVR_PB_WARN("play callback function %p is invalid",play->player_callback_func); |
| 228 | return; |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 229 | } |
Wentao MA | 804bab1 | 2022-11-29 10:01:26 +0800 | [diff] [blame] | 230 | play->player_callback_func(play->player_callback_userdata, event); |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 231 | } |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame] | 232 | |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 233 | //convert video and audio fmt |
| 234 | static int _dvr_convert_stream_fmt(int fmt, DVR_Bool_t is_audio) { |
| 235 | int format = 0; |
| 236 | if (is_audio == DVR_FALSE) { |
| 237 | //for video fmt |
| 238 | switch (fmt) |
| 239 | { |
| 240 | case DVR_VIDEO_FORMAT_MPEG1: |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 241 | format = AV_VIDEO_CODEC_MPEG1; |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 242 | break; |
| 243 | case DVR_VIDEO_FORMAT_MPEG2: |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 244 | format = AV_VIDEO_CODEC_MPEG2; |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 245 | break; |
| 246 | case DVR_VIDEO_FORMAT_HEVC: |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 247 | format = AV_VIDEO_CODEC_H265; |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 248 | break; |
| 249 | case DVR_VIDEO_FORMAT_H264: |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 250 | format = AV_VIDEO_CODEC_H264; |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 251 | break; |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 252 | case DVR_VIDEO_FORMAT_VP9: |
| 253 | format = AV_VIDEO_CODEC_VP9; |
| 254 | break; |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 255 | } |
| 256 | } else { |
| 257 | //for audio fmt |
| 258 | switch (fmt) |
| 259 | { |
| 260 | case DVR_AUDIO_FORMAT_MPEG: |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 261 | format = AV_AUDIO_CODEC_MP2; |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 262 | break; |
| 263 | case DVR_AUDIO_FORMAT_AC3: |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 264 | format = AV_AUDIO_CODEC_AC3; |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 265 | break; |
| 266 | case DVR_AUDIO_FORMAT_EAC3: |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 267 | format = AV_AUDIO_CODEC_EAC3; |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 268 | break; |
| 269 | case DVR_AUDIO_FORMAT_DTS: |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 270 | format = AV_AUDIO_CODEC_DTS; |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 271 | break; |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 272 | case DVR_AUDIO_FORMAT_AAC: |
| 273 | format = AV_AUDIO_CODEC_AAC; |
| 274 | break; |
| 275 | case DVR_AUDIO_FORMAT_LATM: |
| 276 | format = AV_AUDIO_CODEC_LATM; |
| 277 | break; |
| 278 | case DVR_AUDIO_FORMAT_PCM: |
| 279 | format = AV_AUDIO_CODEC_PCM; |
| 280 | break; |
hualing chen | ee0e52b | 2021-04-09 16:58:44 +0800 | [diff] [blame] | 281 | case DVR_AUDIO_FORMAT_AC4: |
| 282 | format = AV_AUDIO_CODEC_AC4; |
| 283 | break; |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 284 | } |
| 285 | } |
| 286 | return format; |
| 287 | } |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 288 | static int _dvr_playback_get_trick_stat(DVR_PlaybackHandle_t handle) |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 289 | { |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 290 | DVR_Playback_t *player = (DVR_Playback_t *) handle; |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 291 | |
Gong Ke | 2a0ebbe | 2021-05-25 15:22:50 +0800 | [diff] [blame] | 292 | if (player == NULL || player->handle == (am_tsplayer_handle)NULL) |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 293 | return -1; |
| 294 | |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 295 | return player->first_frame; |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 296 | } |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 297 | |
hualing chen | 7ea70a7 | 2021-09-09 11:25:13 +0800 | [diff] [blame] | 298 | |
| 299 | //get sys time sec |
| 300 | static uint32_t _dvr_getClock_sec(void) |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 301 | { |
| 302 | struct timespec ts; |
hualing chen | 7ea70a7 | 2021-09-09 11:25:13 +0800 | [diff] [blame] | 303 | uint32_t s; |
hualing chen | 03fd494 | 2021-07-15 15:56:41 +0800 | [diff] [blame] | 304 | clock_gettime(CLOCK_REALTIME, &ts); |
hualing chen | 7ea70a7 | 2021-09-09 11:25:13 +0800 | [diff] [blame] | 305 | s = (uint32_t)(ts.tv_sec); |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 306 | DVR_PB_INFO("n:%u", s); |
hualing chen | 7ea70a7 | 2021-09-09 11:25:13 +0800 | [diff] [blame] | 307 | return s; |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 308 | } |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 309 | |
hualing chen | 7ea70a7 | 2021-09-09 11:25:13 +0800 | [diff] [blame] | 310 | //get sys time ms |
| 311 | static uint32_t _dvr_time_getClock(void) |
| 312 | { |
| 313 | struct timespec ts; |
| 314 | uint32_t ms; |
Zhiqiang Han | 7170365 | 2023-09-18 11:05:34 +0800 | [diff] [blame] | 315 | clock_gettime(CLOCK_MONOTONIC, &ts); |
hualing chen | 7ea70a7 | 2021-09-09 11:25:13 +0800 | [diff] [blame] | 316 | ms = (uint32_t)(ts.tv_sec*1000+ts.tv_nsec/1000000); |
| 317 | return ms; |
| 318 | } |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 319 | |
Wentao MA | 270dc0f | 2022-08-23 13:17:26 +0800 | [diff] [blame] | 320 | //timeout wait signal |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 321 | static int _dvr_playback_timeoutwait(DVR_PlaybackHandle_t handle , int ms) |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 322 | { |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 323 | DVR_Playback_t *player = (DVR_Playback_t *) handle; |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 324 | |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 325 | |
| 326 | if (player == NULL) { |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 327 | DVR_PB_INFO("player is NULL"); |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 328 | return DVR_FAILURE; |
| 329 | } |
| 330 | |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 331 | struct timespec ts; |
| 332 | clock_gettime(CLOCK_MONOTONIC, &ts); |
| 333 | //ms为毫秒,换算成秒 |
| 334 | ts.tv_sec += ms/1000; |
| 335 | //在outtime的基础上,增加ms毫秒 |
| 336 | //outtime.tv_nsec为纳秒,1微秒=1000纳秒 |
| 337 | //tv_nsec此值再加上剩余的毫秒数 ms%1000,有可能超过1秒。需要特殊处理 |
| 338 | uint64_t us = ts.tv_nsec/1000 + 1000 * (ms % 1000); //微秒 |
| 339 | //us的值有可能超过1秒, |
| 340 | ts.tv_sec += us / 1000000; |
| 341 | us = us % 1000000; |
| 342 | ts.tv_nsec = us * 1000;//换算成纳秒 |
Zhiqiang Han | f9c0e27 | 2022-06-14 13:54:03 +0800 | [diff] [blame] | 343 | |
| 344 | int val = dvr_mutex_save(&player->lock); |
| 345 | pthread_cond_timedwait(&player->cond, &player->lock.lock, &ts); |
| 346 | dvr_mutex_restore(&player->lock, val); |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 347 | return 0; |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 348 | } |
Wentao MA | 804bab1 | 2022-11-29 10:01:26 +0800 | [diff] [blame] | 349 | |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 350 | //send signal |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 351 | static int _dvr_playback_sendSignal(DVR_PlaybackHandle_t handle) |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 352 | { |
hualing chen | 87072a8 | 2020-03-12 16:20:12 +0800 | [diff] [blame] | 353 | DVR_Playback_t *player = (DVR_Playback_t *) handle;\ |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 354 | |
| 355 | if (player == NULL) { |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 356 | DVR_PB_INFO("player is NULL"); |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 357 | return DVR_FAILURE; |
| 358 | } |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 359 | DVR_PB_DEBUG("lock---"); |
Zhiqiang Han | f9c0e27 | 2022-06-14 13:54:03 +0800 | [diff] [blame] | 360 | dvr_mutex_lock(&player->lock); |
hualing chen | 87072a8 | 2020-03-12 16:20:12 +0800 | [diff] [blame] | 361 | pthread_cond_signal(&player->cond); |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 362 | DVR_PB_DEBUG("unlock---"); |
Zhiqiang Han | f9c0e27 | 2022-06-14 13:54:03 +0800 | [diff] [blame] | 363 | dvr_mutex_unlock(&player->lock); |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 364 | return 0; |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 365 | } |
| 366 | |
hualing chen | 2932d37 | 2020-04-29 13:44:00 +0800 | [diff] [blame] | 367 | //send playback event, need check is need lock first |
| 368 | static int _dvr_playback_sent_event(DVR_PlaybackHandle_t handle, DVR_PlaybackEvent_t evt, DVR_Play_Notify_t *notify, DVR_Bool_t is_lock) { |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame] | 369 | |
| 370 | DVR_Playback_t *player = (DVR_Playback_t *) handle; |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 371 | |
| 372 | if (player == NULL) { |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 373 | DVR_PB_INFO("player is NULL"); |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 374 | return DVR_FAILURE; |
| 375 | } |
| 376 | |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame] | 377 | switch (evt) { |
| 378 | case DVR_PLAYBACK_EVENT_ERROR: |
hualing chen | 2932d37 | 2020-04-29 13:44:00 +0800 | [diff] [blame] | 379 | _dvr_playback_get_status(handle, &(notify->play_status), is_lock); |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame] | 380 | break; |
| 381 | case DVR_PLAYBACK_EVENT_TRANSITION_OK: |
| 382 | //GET STATE |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 383 | DVR_PB_INFO("trans ok EVENT"); |
hualing chen | 2932d37 | 2020-04-29 13:44:00 +0800 | [diff] [blame] | 384 | _dvr_playback_get_status(handle, &(notify->play_status), is_lock); |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame] | 385 | break; |
| 386 | case DVR_PLAYBACK_EVENT_TRANSITION_FAILED: |
| 387 | break; |
| 388 | case DVR_PLAYBACK_EVENT_KEY_FAILURE: |
| 389 | break; |
| 390 | case DVR_PLAYBACK_EVENT_NO_KEY: |
| 391 | break; |
| 392 | case DVR_PLAYBACK_EVENT_REACHED_BEGIN: |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 393 | //GET STATE |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 394 | DVR_PB_INFO("reached begin EVENT"); |
hualing chen | 2932d37 | 2020-04-29 13:44:00 +0800 | [diff] [blame] | 395 | _dvr_playback_get_status(handle, &(notify->play_status), is_lock); |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame] | 396 | break; |
| 397 | case DVR_PLAYBACK_EVENT_REACHED_END: |
| 398 | //GET STATE |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 399 | DVR_PB_INFO("reached end EVENT"); |
hualing chen | 2932d37 | 2020-04-29 13:44:00 +0800 | [diff] [blame] | 400 | _dvr_playback_get_status(handle, &(notify->play_status), is_lock); |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame] | 401 | break; |
hualing chen | 6e4bfa5 | 2020-03-13 14:37:11 +0800 | [diff] [blame] | 402 | case DVR_PLAYBACK_EVENT_NOTIFY_PLAYTIME: |
hualing chen | 2932d37 | 2020-04-29 13:44:00 +0800 | [diff] [blame] | 403 | _dvr_playback_get_status(handle, &(notify->play_status), is_lock); |
hualing chen | 6e4bfa5 | 2020-03-13 14:37:11 +0800 | [diff] [blame] | 404 | break; |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame] | 405 | default: |
| 406 | break; |
| 407 | } |
| 408 | if (player->openParams.event_fn != NULL) |
| 409 | player->openParams.event_fn(evt, (void*)notify, player->openParams.event_userdata); |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame] | 410 | return DVR_SUCCESS; |
| 411 | } |
hualing chen | 2932d37 | 2020-04-29 13:44:00 +0800 | [diff] [blame] | 412 | static int _dvr_playback_sent_transition_ok(DVR_PlaybackHandle_t handle, DVR_Bool_t is_lock) |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame] | 413 | { |
| 414 | DVR_Play_Notify_t notify; |
| 415 | memset(¬ify, 0 , sizeof(DVR_Play_Notify_t)); |
| 416 | notify.event = DVR_PLAYBACK_EVENT_TRANSITION_OK; |
| 417 | //get play statue not here |
hualing chen | 2932d37 | 2020-04-29 13:44:00 +0800 | [diff] [blame] | 418 | _dvr_playback_sent_event(handle, DVR_PLAYBACK_EVENT_TRANSITION_OK, ¬ify, is_lock); |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame] | 419 | return DVR_SUCCESS; |
| 420 | } |
| 421 | |
hualing chen | 2932d37 | 2020-04-29 13:44:00 +0800 | [diff] [blame] | 422 | static int _dvr_playback_sent_playtime(DVR_PlaybackHandle_t handle, DVR_Bool_t is_lock) |
hualing chen | 6e4bfa5 | 2020-03-13 14:37:11 +0800 | [diff] [blame] | 423 | { |
| 424 | DVR_Playback_t *player = (DVR_Playback_t *) handle; |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 425 | |
Wentao MA | 16f870e | 2022-09-09 11:00:22 +0800 | [diff] [blame] | 426 | if (player == NULL) { |
| 427 | DVR_PB_ERROR("player is NULL"); |
| 428 | return DVR_FAILURE; |
| 429 | } |
hualing chen | e3797f0 | 2021-01-13 14:53:28 +0800 | [diff] [blame] | 430 | if (player->openParams.is_notify_time == DVR_FALSE) { |
shenghui.geng | bec6a46 | 2023-01-12 15:21:02 +0800 | [diff] [blame] | 431 | if (player->control_speed_enable == 0) |
hualing chen | d241c7a | 2021-06-22 13:34:27 +0800 | [diff] [blame] | 432 | return DVR_SUCCESS; |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 433 | } |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 434 | |
hualing chen | 03fd494 | 2021-07-15 15:56:41 +0800 | [diff] [blame] | 435 | if (player->send_time == 0) { |
shenghui.geng | bec6a46 | 2023-01-12 15:21:02 +0800 | [diff] [blame] | 436 | if (player->control_speed_enable == 0) |
hualing chen | d241c7a | 2021-06-22 13:34:27 +0800 | [diff] [blame] | 437 | player->send_time = _dvr_time_getClock() + 500; |
| 438 | else |
| 439 | player->send_time = _dvr_time_getClock() + 20; |
hualing chen | 0888c03 | 2020-12-18 17:54:57 +0800 | [diff] [blame] | 440 | } else if (player->send_time >= _dvr_time_getClock()) { |
hualing chen | 56c0a16 | 2022-01-27 17:01:50 +0800 | [diff] [blame] | 441 | if ((player->send_time - _dvr_time_getClock()) > 1000) { |
| 442 | player->send_time = _dvr_time_getClock() + 500; |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 443 | DVR_PB_INFO("player send time occur system time changed!!!!!"); |
hualing chen | 56c0a16 | 2022-01-27 17:01:50 +0800 | [diff] [blame] | 444 | } else { |
| 445 | return DVR_SUCCESS; |
| 446 | } |
hualing chen | 6e4bfa5 | 2020-03-13 14:37:11 +0800 | [diff] [blame] | 447 | } |
shenghui.geng | bec6a46 | 2023-01-12 15:21:02 +0800 | [diff] [blame] | 448 | if (player->control_speed_enable == 0) |
hualing chen | d241c7a | 2021-06-22 13:34:27 +0800 | [diff] [blame] | 449 | player->send_time = _dvr_time_getClock() + 500; |
| 450 | else |
| 451 | player->send_time = _dvr_time_getClock() + 20; |
| 452 | |
hualing chen | 6e4bfa5 | 2020-03-13 14:37:11 +0800 | [diff] [blame] | 453 | DVR_Play_Notify_t notify; |
| 454 | memset(¬ify, 0 , sizeof(DVR_Play_Notify_t)); |
| 455 | notify.event = DVR_PLAYBACK_EVENT_NOTIFY_PLAYTIME; |
| 456 | //get play statue not here |
hualing chen | 2932d37 | 2020-04-29 13:44:00 +0800 | [diff] [blame] | 457 | _dvr_playback_sent_event(handle, DVR_PLAYBACK_EVENT_NOTIFY_PLAYTIME, ¬ify, is_lock); |
hualing chen | 6e4bfa5 | 2020-03-13 14:37:11 +0800 | [diff] [blame] | 458 | return DVR_SUCCESS; |
| 459 | } |
| 460 | |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 461 | static int _dvr_init_fffb_t(DVR_PlaybackHandle_t handle) { |
| 462 | DVR_Playback_t *player = (DVR_Playback_t *) handle; |
| 463 | player->fffb_start = _dvr_time_getClock(); |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 464 | DVR_PB_INFO(" player->fffb_start:%u", player->fffb_start); |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 465 | player->fffb_current = player->fffb_start; |
| 466 | //get segment current time pos |
| 467 | player->fffb_start_pcr = _dvr_get_cur_time(handle); |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 468 | player->next_fffb_time = _dvr_time_getClock(); |
| 469 | |
| 470 | return DVR_SUCCESS; |
| 471 | } |
| 472 | |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 473 | static int _dvr_init_fffb_time(DVR_PlaybackHandle_t handle) { |
| 474 | DVR_Playback_t *player = (DVR_Playback_t *) handle; |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 475 | player->fffb_start = _dvr_time_getClock(); |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 476 | DVR_PB_INFO(" player->fffb_start:%u", player->fffb_start); |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 477 | player->fffb_current = player->fffb_start; |
| 478 | //get segment current time pos |
| 479 | player->fffb_start_pcr = _dvr_get_cur_time(handle); |
hualing chen | 03fd494 | 2021-07-15 15:56:41 +0800 | [diff] [blame] | 480 | |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 481 | player->next_fffb_time = _dvr_time_getClock(); |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 482 | player->last_send_time_id = UINT64_MAX; |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 483 | return DVR_SUCCESS; |
| 484 | } |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame] | 485 | //get next segment id |
hualing chen | 87072a8 | 2020-03-12 16:20:12 +0800 | [diff] [blame] | 486 | static int _dvr_has_next_segmentId(DVR_PlaybackHandle_t handle, int segmentid) { |
| 487 | |
| 488 | DVR_Playback_t *player = (DVR_Playback_t *) handle; |
| 489 | DVR_PlaybackSegmentInfo_t *segment; |
| 490 | DVR_PlaybackSegmentInfo_t *pre_segment = NULL; |
| 491 | |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 492 | if (player == NULL) { |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 493 | DVR_PB_INFO(" player is NULL"); |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 494 | return DVR_FAILURE; |
| 495 | } |
| 496 | |
hualing chen | 87072a8 | 2020-03-12 16:20:12 +0800 | [diff] [blame] | 497 | int found = 0; |
| 498 | int found_eq_id = 0; |
wentao.ma | fd5283f | 2022-10-14 09:51:13 +0800 | [diff] [blame] | 499 | // This error is suppressed as the macro code is picked from kernel. |
wentao.ma | a22bc85 | 2022-10-13 12:18:06 +0800 | [diff] [blame] | 500 | // prefetch() here incurring self_assign is used to avoid some compiling |
| 501 | // warnings. |
| 502 | // coverity[self_assign] |
hualing chen | 87072a8 | 2020-03-12 16:20:12 +0800 | [diff] [blame] | 503 | list_for_each_entry(segment, &player->segment_list, head) |
| 504 | { |
| 505 | if (player->segment_is_open == DVR_FALSE) { |
| 506 | //get first segment from list, case segment is not open |
| 507 | if (!IS_FB(player->speed)) |
| 508 | found = 1; |
| 509 | } else if (segment->segment_id == segmentid) { |
| 510 | //find cur segment, we need get next one |
| 511 | found_eq_id = 1; |
| 512 | if (!IS_FB(player->speed)) { |
| 513 | found = 1; |
| 514 | continue; |
| 515 | } else { |
| 516 | //if is fb mode.we need used pre segment |
| 517 | if (pre_segment != NULL) { |
| 518 | found = 1; |
| 519 | } else { |
| 520 | //not find next id. |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 521 | DVR_PB_INFO("not has find next segment on fb mode"); |
hualing chen | 87072a8 | 2020-03-12 16:20:12 +0800 | [diff] [blame] | 522 | return DVR_FAILURE; |
| 523 | } |
| 524 | } |
| 525 | } |
| 526 | if (found == 1) { |
| 527 | found = 2; |
| 528 | break; |
| 529 | } |
hualing chen | c7aa4c8 | 2021-02-03 15:41:37 +0800 | [diff] [blame] | 530 | pre_segment = segment; |
hualing chen | 87072a8 | 2020-03-12 16:20:12 +0800 | [diff] [blame] | 531 | } |
| 532 | if (found != 2) { |
| 533 | //list is null or reache list end |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 534 | DVR_PB_INFO("not found next segment return failure"); |
hualing chen | 87072a8 | 2020-03-12 16:20:12 +0800 | [diff] [blame] | 535 | return DVR_FAILURE; |
| 536 | } |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 537 | DVR_PB_INFO("found next segment return success"); |
hualing chen | 87072a8 | 2020-03-12 16:20:12 +0800 | [diff] [blame] | 538 | return DVR_SUCCESS; |
| 539 | } |
| 540 | |
| 541 | //get next segment id |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 542 | static int _dvr_get_next_segmentId(DVR_PlaybackHandle_t handle) { |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 543 | |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 544 | DVR_Playback_t *player = (DVR_Playback_t *) handle; |
| 545 | DVR_PlaybackSegmentInfo_t *segment; |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 546 | DVR_PlaybackSegmentInfo_t *pre_segment = NULL; |
hualing chen | 03fd494 | 2021-07-15 15:56:41 +0800 | [diff] [blame] | 547 | uint64_t segmentid; |
hualing chen | 7ea70a7 | 2021-09-09 11:25:13 +0800 | [diff] [blame] | 548 | uint32_t pos; |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 549 | if (player == NULL) { |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 550 | DVR_PB_INFO("player is NULL"); |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 551 | return DVR_FAILURE; |
| 552 | } |
| 553 | |
hualing chen | 03fd494 | 2021-07-15 15:56:41 +0800 | [diff] [blame] | 554 | if (IS_FB(player->speed) |
| 555 | && dvr_playback_check_limit(handle)) { |
| 556 | dvr_playback_calculate_last_valid_segment(handle, &segmentid, &pos); |
| 557 | //case cur id < segment id |
| 558 | if (player->cur_segment_id <= segmentid) { |
| 559 | //expired ts data is player,return error |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 560 | DVR_PB_INFO("reach start segment ,return error"); |
hualing chen | 03fd494 | 2021-07-15 15:56:41 +0800 | [diff] [blame] | 561 | return DVR_FAILURE; |
| 562 | } |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 563 | DVR_PB_INFO("has segment to fb play [%lld][%u]", segmentid, pos); |
hualing chen | 03fd494 | 2021-07-15 15:56:41 +0800 | [diff] [blame] | 564 | } |
| 565 | |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 566 | int found = 0; |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 567 | int found_eq_id = 0; |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 568 | |
wentao.ma | fd5283f | 2022-10-14 09:51:13 +0800 | [diff] [blame] | 569 | // This error is suppressed as the macro code is picked from kernel. |
wentao.ma | a22bc85 | 2022-10-13 12:18:06 +0800 | [diff] [blame] | 570 | // prefetch() here incurring self_assign is used to avoid some compiling |
| 571 | // warnings. |
| 572 | // coverity[self_assign] |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 573 | list_for_each_entry(segment, &player->segment_list, head) |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 574 | { |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame] | 575 | if (player->segment_is_open == DVR_FALSE) { |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 576 | //get first segment from list, case segment is not open |
| 577 | if (!IS_FB(player->speed)) |
| 578 | found = 1; |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 579 | } else if (segment->segment_id == player->cur_segment_id) { |
| 580 | //find cur segment, we need get next one |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 581 | found_eq_id = 1; |
| 582 | if (!IS_FB(player->speed)) { |
| 583 | found = 1; |
| 584 | continue; |
| 585 | } else { |
| 586 | //if is fb mode.we need used pre segment |
| 587 | if (pre_segment != NULL) { |
| 588 | found = 1; |
| 589 | } else { |
| 590 | //not find next id. |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 591 | DVR_PB_INFO("not find next segment on fb mode"); |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 592 | return DVR_FAILURE; |
| 593 | } |
| 594 | } |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 595 | } |
| 596 | if (found == 1) { |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 597 | if (IS_FB(player->speed)) { |
| 598 | //used pre segment |
| 599 | segment = pre_segment; |
| 600 | } |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame] | 601 | //save segment info |
| 602 | player->last_segment_id = player->cur_segment_id; |
Wentao MA | f35c388 | 2023-04-17 12:36:19 +0800 | [diff] [blame] | 603 | if (player->segment_handle) { |
| 604 | player->last_segment_total = segment_tell_total_time(player->segment_handle); |
| 605 | } |
hualing chen | 87072a8 | 2020-03-12 16:20:12 +0800 | [diff] [blame] | 606 | player->last_segment.segment_id = player->cur_segment.segment_id; |
| 607 | player->last_segment.flags = player->cur_segment.flags; |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame] | 608 | memcpy(player->last_segment.location, player->cur_segment.location, DVR_MAX_LOCATION_SIZE); |
| 609 | //pids |
| 610 | memcpy(&player->last_segment.pids, &player->cur_segment.pids, sizeof(DVR_PlaybackPids_t)); |
| 611 | |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 612 | //get segment info |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame] | 613 | player->segment_is_open = DVR_TRUE; |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 614 | player->cur_segment_id = segment->segment_id; |
| 615 | player->cur_segment.segment_id = segment->segment_id; |
| 616 | player->cur_segment.flags = segment->flags; |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 617 | DVR_PB_INFO("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] | 618 | memcpy(player->cur_segment.location, segment->location, DVR_MAX_LOCATION_SIZE); |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 619 | //pids |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 620 | memcpy(&player->cur_segment.pids, &segment->pids, sizeof(DVR_PlaybackPids_t)); |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 621 | found = 2; |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 622 | break; |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 623 | } |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 624 | pre_segment = segment; |
| 625 | } |
| 626 | if (player->segment_is_open == DVR_FALSE && IS_FB(player->speed)) { |
| 627 | //used the last one segment to open |
| 628 | //get segment info |
| 629 | player->segment_is_open = DVR_TRUE; |
| 630 | player->cur_segment_id = pre_segment->segment_id; |
| 631 | player->cur_segment.segment_id = pre_segment->segment_id; |
| 632 | player->cur_segment.flags = pre_segment->flags; |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 633 | DVR_PB_INFO("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] | 634 | memcpy(player->cur_segment.location, pre_segment->location, DVR_MAX_LOCATION_SIZE); |
| 635 | //pids |
| 636 | memcpy(&player->cur_segment.pids, &pre_segment->pids, sizeof(DVR_PlaybackPids_t)); |
| 637 | return DVR_SUCCESS; |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 638 | } |
| 639 | if (found != 2) { |
| 640 | //list is null or reache list end |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 641 | return DVR_FAILURE; |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 642 | } |
| 643 | return DVR_SUCCESS; |
| 644 | } |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 645 | //open next segment to play,if reach list end return errro. |
| 646 | static int _change_to_next_segment(DVR_PlaybackHandle_t handle) |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 647 | { |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 648 | DVR_Playback_t *player = (DVR_Playback_t *) handle; |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 649 | Segment_OpenParams_t params; |
| 650 | int ret = DVR_SUCCESS; |
| 651 | |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 652 | if (player == NULL) { |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 653 | DVR_PB_INFO("player is NULL"); |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 654 | return DVR_FAILURE; |
| 655 | } |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 656 | pthread_mutex_lock(&player->segment_lock); |
hualing chen | 926a8ec | 2021-12-20 20:38:24 +0800 | [diff] [blame] | 657 | retry: |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 658 | ret = _dvr_get_next_segmentId(handle); |
| 659 | if (ret == DVR_FAILURE) { |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 660 | DVR_PB_INFO("not found segment info"); |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 661 | pthread_mutex_unlock(&player->segment_lock); |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 662 | return DVR_FAILURE; |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 663 | } |
| 664 | |
Wentao MA | f35c388 | 2023-04-17 12:36:19 +0800 | [diff] [blame] | 665 | if (player->segment_handle != NULL) { |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 666 | DVR_PB_INFO("close segment"); |
Wentao MA | f35c388 | 2023-04-17 12:36:19 +0800 | [diff] [blame] | 667 | segment_close(player->segment_handle); |
| 668 | player->segment_handle = NULL; |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 669 | } |
| 670 | |
Wentao MA | 4d85ff3 | 2022-09-23 11:36:18 +0800 | [diff] [blame] | 671 | memset((void*)¶ms,0,sizeof(params)); |
Wentao MA | 270dc0f | 2022-08-23 13:17:26 +0800 | [diff] [blame] | 672 | //cp current segment path to location |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 673 | memcpy(params.location, player->cur_segment.location, DVR_MAX_LOCATION_SIZE); |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 674 | params.segment_id = (uint64_t)player->cur_segment.segment_id; |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 675 | params.mode = SEGMENT_MODE_READ; |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 676 | DVR_PB_INFO("open segment location[%s]id[%lld]flag[0x%x]", params.location, params.segment_id, player->cur_segment.flags); |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 677 | |
Wentao MA | f35c388 | 2023-04-17 12:36:19 +0800 | [diff] [blame] | 678 | ret = segment_open(¶ms, &(player->segment_handle)); |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 679 | if (ret == DVR_FAILURE) { |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 680 | DVR_PB_INFO("open segment error"); |
hualing chen | 926a8ec | 2021-12-20 20:38:24 +0800 | [diff] [blame] | 681 | goto retry; |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 682 | } |
Wentao MA | 01de0e6 | 2022-01-10 18:48:23 +0800 | [diff] [blame] | 683 | // Keep the start segment_id when the first segment_open is called during a playback |
| 684 | if (player->first_start_id == UINT64_MAX) { |
| 685 | player->first_start_id = player->cur_segment.segment_id; |
| 686 | } |
hualing chen | 87072a8 | 2020-03-12 16:20:12 +0800 | [diff] [blame] | 687 | pthread_mutex_unlock(&player->segment_lock); |
| 688 | int total = _dvr_get_end_time( handle); |
| 689 | pthread_mutex_lock(&player->segment_lock); |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 690 | if (IS_FB(player->speed)) { |
| 691 | //seek end pos -FB_DEFAULT_LEFT_TIME |
hualing chen | 5605eed | 2020-05-26 18:18:06 +0800 | [diff] [blame] | 692 | player->ts_cache_len = 0; |
Wentao MA | f35c388 | 2023-04-17 12:36:19 +0800 | [diff] [blame] | 693 | segment_seek(player->segment_handle, total - FB_DEFAULT_LEFT_TIME, player->openParams.block_size); |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 694 | DVR_PB_INFO("seek pos [%d]", total - FB_DEFAULT_LEFT_TIME); |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 695 | } |
hualing chen | 87072a8 | 2020-03-12 16:20:12 +0800 | [diff] [blame] | 696 | player->dur = total; |
wentao.ma | fdba9a0 | 2023-01-17 16:43:26 +0800 | [diff] [blame] | 697 | player->con_spe.ply_dur = 0; |
| 698 | player->con_spe.ply_sta = 0; |
| 699 | player->con_spe.sys_dur = 0; |
| 700 | player->con_spe.sys_sta = 0; |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 701 | pthread_mutex_unlock(&player->segment_lock); |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 702 | DVR_PB_INFO("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] | 703 | return ret; |
| 704 | } |
| 705 | |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 706 | //open next segment to play,if reach list end return errro. |
| 707 | static int _dvr_open_segment(DVR_PlaybackHandle_t handle, uint64_t segment_id) |
| 708 | { |
| 709 | DVR_Playback_t *player = (DVR_Playback_t *) handle; |
| 710 | Segment_OpenParams_t params; |
| 711 | int ret = DVR_SUCCESS; |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 712 | if (player == NULL) { |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 713 | DVR_PB_INFO("player is NULL"); |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 714 | return DVR_FAILURE; |
| 715 | } |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame] | 716 | 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] | 717 | return DVR_SUCCESS; |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 718 | } |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame] | 719 | uint64_t id = segment_id; |
Wentao MA | 07d3d74 | 2022-09-06 09:58:05 +0800 | [diff] [blame] | 720 | DVR_PB_INFO("start finding segment[%lld] info", id); |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 721 | pthread_mutex_lock(&player->segment_lock); |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 722 | |
| 723 | DVR_PlaybackSegmentInfo_t *segment; |
| 724 | |
| 725 | int found = 0; |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame] | 726 | |
wentao.ma | fd5283f | 2022-10-14 09:51:13 +0800 | [diff] [blame] | 727 | // This error is suppressed as the macro code is picked from kernel. |
wentao.ma | a22bc85 | 2022-10-13 12:18:06 +0800 | [diff] [blame] | 728 | // prefetch() here incurring self_assign is used to avoid some compiling |
| 729 | // warnings. |
| 730 | // coverity[self_assign] |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 731 | list_for_each_entry(segment, &player->segment_list, head) |
| 732 | { |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 733 | DVR_PB_INFO("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] | 734 | if (segment->segment_id == segment_id) { |
| 735 | found = 1; |
| 736 | } |
| 737 | if (found == 1) { |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 738 | DVR_PB_INFO("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] | 739 | //get segment info |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame] | 740 | player->segment_is_open = DVR_TRUE; |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 741 | player->cur_segment_id = segment->segment_id; |
| 742 | player->cur_segment.segment_id = segment->segment_id; |
| 743 | player->cur_segment.flags = segment->flags; |
Wentao MA | e88ad70 | 2022-09-02 10:35:00 +0800 | [diff] [blame] | 744 | const int len = strlen(segment->location); |
| 745 | if (len >= DVR_MAX_LOCATION_SIZE || len <= 0) { |
| 746 | DVR_PB_ERROR("Invalid segment.location length %d",len); |
| 747 | pthread_mutex_unlock(&player->segment_lock); |
| 748 | return DVR_FAILURE; |
| 749 | } |
| 750 | strncpy(player->cur_segment.location, segment->location, len+1); |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 751 | //pids |
| 752 | memcpy(&player->cur_segment.pids, &segment->pids, sizeof(DVR_PlaybackPids_t)); |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 753 | DVR_PB_INFO("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] | 754 | break; |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 755 | } |
| 756 | } |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame] | 757 | if (found == 0) { |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 758 | DVR_PB_INFO("not found segment info.error.."); |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 759 | pthread_mutex_unlock(&player->segment_lock); |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame] | 760 | return DVR_FAILURE; |
| 761 | } |
Wentao MA | 4d85ff3 | 2022-09-23 11:36:18 +0800 | [diff] [blame] | 762 | memset((void*)¶ms,0,sizeof(params)); |
Wentao MA | e88ad70 | 2022-09-02 10:35:00 +0800 | [diff] [blame] | 763 | |
| 764 | const int len2 = strlen(player->cur_segment.location); |
| 765 | if (len2 >= DVR_MAX_LOCATION_SIZE || len2 <= 0) { |
| 766 | DVR_PB_ERROR("Invalid cur_segment.location length %d",len2); |
| 767 | pthread_mutex_unlock(&player->segment_lock); |
| 768 | return DVR_FAILURE; |
| 769 | } |
| 770 | strncpy(params.location, player->cur_segment.location, len2+1); |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 771 | params.segment_id = (uint64_t)player->cur_segment.segment_id; |
| 772 | params.mode = SEGMENT_MODE_READ; |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 773 | DVR_PB_INFO("open segment location[%s][%lld]cur flag[0x%x]", params.location, params.segment_id, player->cur_segment.flags); |
Wentao MA | f35c388 | 2023-04-17 12:36:19 +0800 | [diff] [blame] | 774 | if (player->segment_handle != NULL) { |
| 775 | segment_close(player->segment_handle); |
| 776 | player->segment_handle = NULL; |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 777 | } |
Wentao MA | f35c388 | 2023-04-17 12:36:19 +0800 | [diff] [blame] | 778 | ret = segment_open(¶ms, &(player->segment_handle)); |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 779 | if (ret == DVR_FAILURE) { |
Wentao MA | 270dc0f | 2022-08-23 13:17:26 +0800 | [diff] [blame] | 780 | DVR_PB_INFO("segment open error"); |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 781 | } |
Wentao MA | 01de0e6 | 2022-01-10 18:48:23 +0800 | [diff] [blame] | 782 | // Keep the start segment_id when the first segment_open is called during a playback |
| 783 | if (player->first_start_id == UINT64_MAX) { |
| 784 | player->first_start_id = player->cur_segment.segment_id; |
| 785 | } |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 786 | pthread_mutex_unlock(&player->segment_lock); |
hualing chen | 87072a8 | 2020-03-12 16:20:12 +0800 | [diff] [blame] | 787 | player->dur = _dvr_get_end_time(handle); |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame] | 788 | |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 789 | DVR_PB_INFO("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] | 790 | return ret; |
| 791 | } |
| 792 | |
| 793 | |
| 794 | //get play info by segment id |
| 795 | static int _dvr_playback_get_playinfo(DVR_PlaybackHandle_t handle, |
| 796 | uint64_t segment_id, |
Wentao MA | 270dc0f | 2022-08-23 13:17:26 +0800 | [diff] [blame] | 797 | am_tsplayer_video_params *video_param, |
| 798 | am_tsplayer_audio_params *audio_param, am_tsplayer_audio_params *ad_param) { |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 799 | |
| 800 | DVR_Playback_t *player = (DVR_Playback_t *) handle; |
| 801 | DVR_PlaybackSegmentInfo_t *segment; |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 802 | if (player == NULL) { |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 803 | DVR_PB_INFO("player is NULL"); |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 804 | return DVR_FAILURE; |
| 805 | } |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 806 | |
| 807 | int found = 0; |
| 808 | |
wentao.ma | fd5283f | 2022-10-14 09:51:13 +0800 | [diff] [blame] | 809 | // This error is suppressed as the macro code is picked from kernel. |
wentao.ma | a22bc85 | 2022-10-13 12:18:06 +0800 | [diff] [blame] | 810 | // prefetch() here incurring self_assign is used to avoid some compiling |
| 811 | // warnings. |
| 812 | // coverity[self_assign] |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 813 | list_for_each_entry(segment, &player->segment_list, head) |
| 814 | { |
hualing chen | 87072a8 | 2020-03-12 16:20:12 +0800 | [diff] [blame] | 815 | if (segment_id == UINT64_MAX) { |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 816 | //get first segment from list |
| 817 | found = 1; |
| 818 | } |
| 819 | if (segment->segment_id == segment_id) { |
| 820 | found = 1; |
| 821 | } |
| 822 | if (found == 1) { |
| 823 | //get segment info |
hualing chen | 87072a8 | 2020-03-12 16:20:12 +0800 | [diff] [blame] | 824 | if (player->cur_segment_id != UINT64_MAX) |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 825 | player->cur_segment_id = segment->segment_id; |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 826 | player->cur_segment.segment_id = segment->segment_id; |
| 827 | player->cur_segment.flags = segment->flags; |
| 828 | //pids |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 829 | player->cur_segment.pids.video.pid = segment->pids.video.pid; |
| 830 | player->cur_segment.pids.video.format = segment->pids.video.format; |
| 831 | player->cur_segment.pids.video.type = segment->pids.video.type; |
| 832 | player->cur_segment.pids.audio.pid = segment->pids.audio.pid; |
| 833 | player->cur_segment.pids.audio.format = segment->pids.audio.format; |
| 834 | player->cur_segment.pids.audio.type = segment->pids.audio.type; |
| 835 | player->cur_segment.pids.ad.pid = segment->pids.ad.pid; |
| 836 | player->cur_segment.pids.ad.format = segment->pids.ad.format; |
| 837 | player->cur_segment.pids.ad.type = segment->pids.ad.type; |
| 838 | player->cur_segment.pids.pcr.pid = segment->pids.pcr.pid; |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 839 | // |
Wentao MA | 270dc0f | 2022-08-23 13:17:26 +0800 | [diff] [blame] | 840 | video_param->codectype = _dvr_convert_stream_fmt(segment->pids.video.format, DVR_FALSE); |
| 841 | video_param->pid = segment->pids.video.pid; |
| 842 | audio_param->codectype = _dvr_convert_stream_fmt(segment->pids.audio.format, DVR_TRUE); |
| 843 | audio_param->pid = segment->pids.audio.pid; |
| 844 | ad_param->codectype =_dvr_convert_stream_fmt(segment->pids.ad.format, DVR_TRUE); |
| 845 | ad_param->pid =segment->pids.ad.pid; |
Wentao MA | 804bab1 | 2022-11-29 10:01:26 +0800 | [diff] [blame] | 846 | DVR_PB_DEBUG("get_playinfo, segment_id:%lld, vpid[0x%x], apid[0x%x], vfmt[%d], afmt[%d]", |
| 847 | player->cur_segment_id, video_param->pid, audio_param->pid, |
| 848 | video_param->codectype, audio_param->codectype); |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 849 | found = 2; |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame] | 850 | break; |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 851 | } |
| 852 | } |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame] | 853 | if (found != 2) { |
| 854 | //list is null or reache list end |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 855 | DVR_PB_INFO("get play info fail"); |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame] | 856 | return DVR_FAILURE; |
| 857 | } |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 858 | |
| 859 | return DVR_SUCCESS; |
| 860 | } |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame] | 861 | static int _dvr_replay_changed_pid(DVR_PlaybackHandle_t handle) { |
| 862 | DVR_Playback_t *player = (DVR_Playback_t *) handle; |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 863 | if (player == NULL) { |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 864 | DVR_PB_INFO("player is NULL"); |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 865 | return DVR_FAILURE; |
| 866 | } |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 867 | |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame] | 868 | //compare cur segment |
| 869 | //if (player->cmd.state == DVR_PLAYBACK_STATE_START) |
| 870 | { |
| 871 | //check video pids, stop or restart |
Wentao MA | 6dcdc34 | 2023-01-30 17:03:19 +0800 | [diff] [blame] | 872 | _do_handle_pid_update(handle, player->last_segment.pids, player->cur_segment.pids, 0); |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame] | 873 | //check sub audio pids stop or restart |
Wentao MA | 6dcdc34 | 2023-01-30 17:03:19 +0800 | [diff] [blame] | 874 | _do_handle_pid_update(handle, player->last_segment.pids, player->cur_segment.pids, 2); |
hualing chen | 969fe7b | 2021-05-26 15:13:17 +0800 | [diff] [blame] | 875 | //check audio pids stop or restart |
Wentao MA | 6dcdc34 | 2023-01-30 17:03:19 +0800 | [diff] [blame] | 876 | _do_handle_pid_update(handle, player->last_segment.pids, player->cur_segment.pids, 1); |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 877 | DVR_PB_INFO(":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] | 878 | //check pcr pids stop or restart |
Wentao MA | 6dcdc34 | 2023-01-30 17:03:19 +0800 | [diff] [blame] | 879 | _do_handle_pid_update(handle, player->last_segment.pids, player->cur_segment.pids, 3); |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame] | 880 | } |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 881 | return DVR_SUCCESS; |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame] | 882 | } |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 883 | |
hualing chen | d241c7a | 2021-06-22 13:34:27 +0800 | [diff] [blame] | 884 | static int _dvr_check_speed_con(DVR_PlaybackHandle_t handle) |
| 885 | { |
| 886 | DVR_Playback_t *player = (DVR_Playback_t *) handle; |
| 887 | if (player == NULL) { |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 888 | DVR_PB_INFO("player is NULL"); |
hualing chen | d241c7a | 2021-06-22 13:34:27 +0800 | [diff] [blame] | 889 | return DVR_TRUE; |
| 890 | } |
hualing chen | d241c7a | 2021-06-22 13:34:27 +0800 | [diff] [blame] | 891 | |
wentao.ma | fdba9a0 | 2023-01-17 16:43:26 +0800 | [diff] [blame] | 892 | DVR_PB_INFO(":play speed: %f ply dur: %d sys_dur: %u", |
hualing chen | 03fd494 | 2021-07-15 15:56:41 +0800 | [diff] [blame] | 893 | player->speed, |
| 894 | player->con_spe.ply_dur, |
| 895 | player->con_spe.sys_dur); |
hualing chen | d241c7a | 2021-06-22 13:34:27 +0800 | [diff] [blame] | 896 | |
| 897 | if (player->speed != 1.0f) |
| 898 | return DVR_TRUE; |
| 899 | |
| 900 | if (player->con_spe.ply_dur > 0 |
hualing chen | 03fd494 | 2021-07-15 15:56:41 +0800 | [diff] [blame] | 901 | && 2 * player->con_spe.ply_dur > 3 * player->con_spe.sys_dur) |
hualing chen | d241c7a | 2021-06-22 13:34:27 +0800 | [diff] [blame] | 902 | return DVR_FALSE; |
| 903 | |
| 904 | return DVR_TRUE; |
| 905 | } |
| 906 | |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame] | 907 | static int _dvr_check_cur_segment_flag(DVR_PlaybackHandle_t handle) |
| 908 | { |
| 909 | DVR_Playback_t *player = (DVR_Playback_t *) handle; |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 910 | if (player == NULL) { |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 911 | DVR_PB_INFO("player is NULL"); |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 912 | return DVR_FAILURE; |
| 913 | } |
Wentao MA | 292380e | 2022-12-14 14:46:19 +0800 | [diff] [blame] | 914 | if (player->vendor != DVR_PLAYBACK_VENDOR_DEF) { |
| 915 | DVR_PB_INFO("In case of vendor Amlogic/Amazon, do not control AV display"); |
hualing chen | f43b8ba | 2020-07-28 13:11:42 +0800 | [diff] [blame] | 916 | return DVR_SUCCESS; |
| 917 | } |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 918 | DVR_PB_INFO("flag[0x%x]id[%lld]last[0x%x][%llu]", |
hualing chen | 03fd494 | 2021-07-15 15:56:41 +0800 | [diff] [blame] | 919 | player->cur_segment.flags, |
| 920 | player->cur_segment.segment_id, |
| 921 | player->last_segment.flags, |
| 922 | player->last_segment.segment_id); |
hualing chen | 87072a8 | 2020-03-12 16:20:12 +0800 | [diff] [blame] | 923 | if ((player->cur_segment.flags & DVR_PLAYBACK_SEGMENT_DISPLAYABLE) == DVR_PLAYBACK_SEGMENT_DISPLAYABLE && |
| 924 | (player->last_segment.flags & DVR_PLAYBACK_SEGMENT_DISPLAYABLE) == 0) { |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame] | 925 | //enable display |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 926 | DVR_PB_INFO("unmute"); |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 927 | AmTsPlayer_showVideo(player->handle); |
| 928 | AmTsPlayer_setAudioMute(player->handle, 0, 0); |
hualing chen | 87072a8 | 2020-03-12 16:20:12 +0800 | [diff] [blame] | 929 | } else if ((player->cur_segment.flags & DVR_PLAYBACK_SEGMENT_DISPLAYABLE) == 0 && |
| 930 | (player->last_segment.flags & DVR_PLAYBACK_SEGMENT_DISPLAYABLE) == DVR_PLAYBACK_SEGMENT_DISPLAYABLE) { |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 931 | //disable display |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 932 | DVR_PB_INFO("mute"); |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 933 | AmTsPlayer_hideVideo(player->handle); |
| 934 | AmTsPlayer_setAudioMute(player->handle, 1, 1); |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame] | 935 | } |
| 936 | return DVR_SUCCESS; |
| 937 | } |
hualing chen | e3797f0 | 2021-01-13 14:53:28 +0800 | [diff] [blame] | 938 | /* |
Wentao MA | 270dc0f | 2022-08-23 13:17:26 +0800 | [diff] [blame] | 939 | if decode success first time. |
| 940 | success: return true |
hualing chen | e3797f0 | 2021-01-13 14:53:28 +0800 | [diff] [blame] | 941 | fail: return false |
| 942 | */ |
Wentao MA | 270dc0f | 2022-08-23 13:17:26 +0800 | [diff] [blame] | 943 | static DVR_Bool_t _dvr_pauselive_decode_success(DVR_PlaybackHandle_t handle) { |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 944 | DVR_Playback_t *player = (DVR_Playback_t *) handle; |
| 945 | if (player == NULL) { |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 946 | DVR_PB_INFO("player is NULL"); |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 947 | return DVR_TRUE; |
| 948 | } |
hualing chen | e3797f0 | 2021-01-13 14:53:28 +0800 | [diff] [blame] | 949 | if (player->first_frame == 1) { |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 950 | return DVR_TRUE; |
hualing chen | e3797f0 | 2021-01-13 14:53:28 +0800 | [diff] [blame] | 951 | } else { |
| 952 | return DVR_FALSE; |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 953 | } |
| 954 | } |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 955 | static void* _dvr_playback_thread(void *arg) |
| 956 | { |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 957 | DVR_Playback_t *player = (DVR_Playback_t *) arg; |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame] | 958 | //int need_open_segment = 1; |
Wentao MA | 270dc0f | 2022-08-23 13:17:26 +0800 | [diff] [blame] | 959 | am_tsplayer_input_buffer input_buffer; |
pengfei.liu | 07ddc8a | 2020-03-24 23:36:53 +0800 | [diff] [blame] | 960 | am_tsplayer_input_buffer dec_bufs; |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 961 | int ret = DVR_SUCCESS; |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 962 | |
hualing chen | 3962821 | 2020-05-14 10:35:13 +0800 | [diff] [blame] | 963 | #define MAX_REACHEND_TIMEOUT (3000) |
| 964 | int reach_end_timeout = 0;//ms |
| 965 | int cache_time = 0; |
hualing chen | 40dd546 | 2021-11-26 19:56:20 +0800 | [diff] [blame] | 966 | int check_no_data_time = 4; |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 967 | 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] | 968 | DVR_Bool_t b_writed_whole_block = player->openParams.block_size > 0 ? DVR_TRUE:DVR_FALSE; |
hualing chen | 40dd546 | 2021-11-26 19:56:20 +0800 | [diff] [blame] | 969 | int first_write = 0; |
pengfei.liu | 07ddc8a | 2020-03-24 23:36:53 +0800 | [diff] [blame] | 970 | int dec_buf_size = buf_len + 188; |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 971 | int real_read = 0; |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 972 | DVR_Bool_t goto_rewrite = DVR_FALSE; |
wentao ma | 7d64278 | 2022-10-23 18:26:16 -0700 | [diff] [blame] | 973 | int read = 0; |
yinming ding | 0ce9492 | 2021-09-08 15:09:15 +0800 | [diff] [blame] | 974 | |
Wentao MA | 361eaac | 2023-03-21 13:12:28 +0800 | [diff] [blame] | 975 | prctl(PR_SET_NAME,"DvrPlayback"); |
| 976 | |
wentao ma | 7d64278 | 2022-10-23 18:26:16 -0700 | [diff] [blame] | 977 | const uint64_t write_timeout_ms = (uint64_t)dvr_prop_read_int("vendor.tv.libdvr.writetm",50); |
| 978 | const int timeout = dvr_prop_read_int("vendor.tv.libdvr.waittm",200); |
hualing chen | 56c0a16 | 2022-01-27 17:01:50 +0800 | [diff] [blame] | 979 | |
pengfei.liu | 07ddc8a | 2020-03-24 23:36:53 +0800 | [diff] [blame] | 980 | if (player->is_secure_mode) { |
| 981 | if (dec_buf_size > player->secure_buffer_size) { |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 982 | DVR_PB_INFO("playback blocksize too large"); |
pengfei.liu | 07ddc8a | 2020-03-24 23:36:53 +0800 | [diff] [blame] | 983 | return NULL; |
| 984 | } |
| 985 | } |
wentao.ma | a210e5e | 2022-10-12 16:10:03 +0800 | [diff] [blame] | 986 | |
| 987 | uint8_t *buf = malloc(buf_len); |
pengfei.liu | 07ddc8a | 2020-03-24 23:36:53 +0800 | [diff] [blame] | 988 | if (!buf) { |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 989 | DVR_PB_INFO("Malloc buffer failed"); |
pengfei.liu | 07ddc8a | 2020-03-24 23:36:53 +0800 | [diff] [blame] | 990 | return NULL; |
| 991 | } |
Wentao MA | 270dc0f | 2022-08-23 13:17:26 +0800 | [diff] [blame] | 992 | input_buffer.buf_type = TS_INPUT_BUFFER_TYPE_NORMAL; |
| 993 | input_buffer.buf_size = 0; |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame] | 994 | |
pengfei.liu | 07ddc8a | 2020-03-24 23:36:53 +0800 | [diff] [blame] | 995 | dec_bufs.buf_data = malloc(dec_buf_size); |
| 996 | if (!dec_bufs.buf_data) { |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 997 | DVR_PB_INFO("Malloc dec buffer failed"); |
Pengfei Liu | faf38e4 | 2020-05-22 00:28:02 +0800 | [diff] [blame] | 998 | free(buf); |
pengfei.liu | 07ddc8a | 2020-03-24 23:36:53 +0800 | [diff] [blame] | 999 | return NULL; |
| 1000 | } |
| 1001 | dec_bufs.buf_type = TS_INPUT_BUFFER_TYPE_NORMAL; |
| 1002 | dec_bufs.buf_size = dec_buf_size; |
| 1003 | |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame] | 1004 | if (player->segment_is_open == DVR_FALSE) { |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 1005 | ret = _change_to_next_segment((DVR_PlaybackHandle_t)player); |
| 1006 | } |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1007 | |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1008 | if (ret != DVR_SUCCESS) { |
| 1009 | if (buf != NULL) { |
| 1010 | free(buf); |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1011 | } |
pengfei.liu | 07ddc8a | 2020-03-24 23:36:53 +0800 | [diff] [blame] | 1012 | free(dec_bufs.buf_data); |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 1013 | DVR_PB_INFO("get segment error"); |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 1014 | return NULL; |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1015 | } |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 1016 | DVR_PB_INFO("--player->vendor %d,player->has_video[%d] bufsize[0x%x]whole block[%d]", |
hualing chen | 03fd494 | 2021-07-15 15:56:41 +0800 | [diff] [blame] | 1017 | player->vendor, player->has_video, buf_len, b_writed_whole_block); |
hualing chen | fbf8e02 | 2020-06-15 13:43:11 +0800 | [diff] [blame] | 1018 | //get play statue not here,send ok event when vendor is aml or only audio channel if not send ok event |
| 1019 | if (((player->first_trans_ok == DVR_FALSE) && (player->vendor == DVR_PLAYBACK_VENDOR_AML) ) || |
| 1020 | (player->first_trans_ok == DVR_FALSE && player->has_video == DVR_FALSE)) { |
| 1021 | player->first_trans_ok = DVR_TRUE; |
| 1022 | _dvr_playback_sent_transition_ok((DVR_PlaybackHandle_t)player, DVR_TRUE); |
| 1023 | } |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame] | 1024 | _dvr_check_cur_segment_flag((DVR_PlaybackHandle_t)player); |
hualing chen | 6d24aa9 | 2020-03-23 18:43:47 +0800 | [diff] [blame] | 1025 | //set video show |
| 1026 | AmTsPlayer_showVideo(player->handle); |
hualing chen | 40dd546 | 2021-11-26 19:56:20 +0800 | [diff] [blame] | 1027 | if (player->vendor == DVR_PLAYBACK_VENDOR_AMAZON) |
| 1028 | check_no_data_time = 8; |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1029 | int trick_stat = 0; |
| 1030 | while (player->is_running/* || player->cmd.last_cmd != player->cmd.cur_cmd*/) { |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 1031 | |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1032 | //check trick stat |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 1033 | //DVR_PB_INFO("lock check_no_data_time:%d", check_no_data_time); |
Zhiqiang Han | f9c0e27 | 2022-06-14 13:54:03 +0800 | [diff] [blame] | 1034 | dvr_mutex_lock(&player->lock); |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 1035 | |
Wentao MA | 907b643 | 2022-08-01 06:23:08 +0000 | [diff] [blame] | 1036 | { |
Wentao MA | 9a16400 | 2022-08-29 11:20:24 +0800 | [diff] [blame] | 1037 | static struct timespec _prev_ts={0,0}; |
Wentao MA | 907b643 | 2022-08-01 06:23:08 +0000 | [diff] [blame] | 1038 | struct timespec _nowts,_diffts; |
| 1039 | clock_gettime(CLOCK_MONOTONIC, &_nowts); |
Wentao MA | 9a16400 | 2022-08-29 11:20:24 +0800 | [diff] [blame] | 1040 | clock_timespec_subtract(&_nowts,&_prev_ts,&_diffts); |
Wentao MA | 907b643 | 2022-08-01 06:23:08 +0000 | [diff] [blame] | 1041 | if (_diffts.tv_sec>0) { |
| 1042 | char _logbuf[512]={0}; |
| 1043 | char* _pbuf=_logbuf; |
| 1044 | int _nchar=0; |
| 1045 | DVR_PlaybackSegmentInfo_t* _segment; |
wentao.ma | fd5283f | 2022-10-14 09:51:13 +0800 | [diff] [blame] | 1046 | // This error is suppressed as the macro code is picked from kernel. |
wentao.ma | a22bc85 | 2022-10-13 12:18:06 +0800 | [diff] [blame] | 1047 | // prefetch() here incurring self_assign is used to avoid some compiling |
| 1048 | // warnings. |
| 1049 | // coverity[self_assign] |
Wentao MA | 907b643 | 2022-08-01 06:23:08 +0000 | [diff] [blame] | 1050 | list_for_each_entry(_segment, &player->segment_list, head) { |
| 1051 | if (player->cur_segment_id == _segment->segment_id) { |
Wentao MA | f35c388 | 2023-04-17 12:36:19 +0800 | [diff] [blame] | 1052 | int seg_size = segment_get_cur_segment_size(player->segment_handle); |
| 1053 | int read_ptr = segment_tell_position(player->segment_handle); |
Wentao MA | 907b643 | 2022-08-01 06:23:08 +0000 | [diff] [blame] | 1054 | float progress = -1.0f; |
Wentao MA | 9a16400 | 2022-08-29 11:20:24 +0800 | [diff] [blame] | 1055 | if (seg_size>0) { |
| 1056 | progress = (float)read_ptr*100/seg_size; |
Wentao MA | 907b643 | 2022-08-01 06:23:08 +0000 | [diff] [blame] | 1057 | } |
Wentao MA | 4d85ff3 | 2022-09-23 11:36:18 +0800 | [diff] [blame] | 1058 | _nchar=sprintf(_pbuf,"%lld(%.1f%%), ",_segment->segment_id,progress); |
Wentao MA | 907b643 | 2022-08-01 06:23:08 +0000 | [diff] [blame] | 1059 | } else { |
| 1060 | _nchar=sprintf(_pbuf,"%lld, ",_segment->segment_id); |
| 1061 | } |
| 1062 | if (_nchar<0) { |
| 1063 | break; |
| 1064 | } |
| 1065 | _pbuf+=_nchar; |
| 1066 | if (_pbuf-_logbuf+10 >= sizeof(_logbuf)) { |
| 1067 | sprintf(_pbuf,"..."); |
| 1068 | break; |
| 1069 | } |
| 1070 | } |
Wentao MA | 9a16400 | 2022-08-29 11:20:24 +0800 | [diff] [blame] | 1071 | DVR_PB_INFO("clk: %08u, seg_list: %s",_nowts.tv_sec,_logbuf); |
| 1072 | _prev_ts=_nowts; |
Wentao MA | 907b643 | 2022-08-01 06:23:08 +0000 | [diff] [blame] | 1073 | } |
| 1074 | } |
| 1075 | |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 1076 | if (player->cmd.cur_cmd == DVR_PLAYBACK_CMD_SEEK || |
| 1077 | player->cmd.cur_cmd == DVR_PLAYBACK_CMD_FF || |
hualing chen | 3114087 | 2020-03-25 12:29:26 +0800 | [diff] [blame] | 1078 | player->cmd.cur_cmd == DVR_PLAYBACK_CMD_FB || |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 1079 | player->speed > FF_SPEED ||player->speed <= FB_SPEED || |
hualing chen | 3962821 | 2020-05-14 10:35:13 +0800 | [diff] [blame] | 1080 | (player->state == DVR_PLAYBACK_STATE_PAUSE) || |
hualing chen | 3114087 | 2020-03-25 12:29:26 +0800 | [diff] [blame] | 1081 | (player->play_flag&DVR_PLAYBACK_STARTED_PAUSEDLIVE) == DVR_PLAYBACK_STARTED_PAUSEDLIVE) |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1082 | { |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 1083 | trick_stat = _dvr_playback_get_trick_stat((DVR_PlaybackHandle_t)player); |
| 1084 | if (trick_stat > 0) { |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 1085 | DVR_PB_INFO("trick stat[%d] is > 0 cur cmd[%d]last cmd[%d]flag[0x%x]", |
hualing chen | 03fd494 | 2021-07-15 15:56:41 +0800 | [diff] [blame] | 1086 | trick_stat, player->cmd.cur_cmd, player->cmd.last_cmd, player->play_flag); |
hualing chen | 87072a8 | 2020-03-12 16:20:12 +0800 | [diff] [blame] | 1087 | 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] | 1088 | //check last cmd |
hualing chen | bcada02 | 2020-04-22 14:27:01 +0800 | [diff] [blame] | 1089 | if (player->cmd.last_cmd == DVR_PLAYBACK_CMD_PAUSE |
hualing chen | 3114087 | 2020-03-25 12:29:26 +0800 | [diff] [blame] | 1090 | || ((player->play_flag&DVR_PLAYBACK_STARTED_PAUSEDLIVE) == DVR_PLAYBACK_STARTED_PAUSEDLIVE |
hualing chen | 87072a8 | 2020-03-12 16:20:12 +0800 | [diff] [blame] | 1091 | && ( player->cmd.cur_cmd == DVR_PLAYBACK_CMD_START |
Wentao MA | 270dc0f | 2022-08-23 13:17:26 +0800 | [diff] [blame] | 1092 | ||player->cmd.last_cmd == DVR_PLAYBACK_CMD_V_START |
| 1093 | || player->cmd.last_cmd == DVR_PLAYBACK_CMD_A_START |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 1094 | || player->cmd.last_cmd == DVR_PLAYBACK_CMD_START))) { |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 1095 | DVR_PB_INFO("pause play-------cur cmd[%d]last cmd[%d]flag[0x%x]", |
hualing chen | 03fd494 | 2021-07-15 15:56:41 +0800 | [diff] [blame] | 1096 | player->cmd.cur_cmd, player->cmd.last_cmd, player->play_flag); |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 1097 | //need change to pause state |
| 1098 | player->cmd.cur_cmd = DVR_PLAYBACK_CMD_PAUSE; |
| 1099 | player->cmd.state = DVR_PLAYBACK_STATE_PAUSE; |
Wentao MA | 907b643 | 2022-08-01 06:23:08 +0000 | [diff] [blame] | 1100 | DVR_PLAYER_CHANGE_STATE(player,DVR_PLAYBACK_STATE_PAUSE); |
hualing chen | 87072a8 | 2020-03-12 16:20:12 +0800 | [diff] [blame] | 1101 | //clear flag |
hualing chen | 3114087 | 2020-03-25 12:29:26 +0800 | [diff] [blame] | 1102 | player->play_flag = player->play_flag & (~DVR_PLAYBACK_STARTED_PAUSEDLIVE); |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 1103 | player->first_frame = 0; |
hualing chen | 10cdb16 | 2021-02-05 10:44:41 +0800 | [diff] [blame] | 1104 | AmTsPlayer_setTrickMode(player->handle, AV_VIDEO_TRICK_MODE_NONE); |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 1105 | AmTsPlayer_pauseVideoDecoding(player->handle); |
| 1106 | AmTsPlayer_pauseAudioDecoding(player->handle); |
Wentao MA | 6dcdc34 | 2023-01-30 17:03:19 +0800 | [diff] [blame] | 1107 | |
| 1108 | // Audio is unmuted here, for it was muted before receiving first frame event. |
| 1109 | if (player->cur_segment.flags & DVR_PLAYBACK_SEGMENT_DISPLAYABLE) { |
| 1110 | AmTsPlayer_setAudioMute(player->handle,0,0); |
| 1111 | } |
hualing chen | 2bd8a7a | 2020-04-02 11:31:03 +0800 | [diff] [blame] | 1112 | } else { |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 1113 | DVR_PB_INFO("clear first frame value-------"); |
hualing chen | 2bd8a7a | 2020-04-02 11:31:03 +0800 | [diff] [blame] | 1114 | player->first_frame = 0; |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 1115 | } |
| 1116 | } else if (player->cmd.cur_cmd == DVR_PLAYBACK_CMD_FF |
| 1117 | || player->cmd.cur_cmd == DVR_PLAYBACK_CMD_FB |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 1118 | ||player->speed > FF_SPEED ||player->speed < FB_SPEED) { |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 1119 | //restart play stream if speed > 2 |
hualing chen | b5cd42e | 2020-04-15 17:03:34 +0800 | [diff] [blame] | 1120 | if (player->state == DVR_PLAYBACK_STATE_PAUSE) { |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 1121 | DVR_PB_INFO("fffb pause state----speed[%f] fffb cur[%u] cur sys[%u] [%s] [%u]", |
hualing chen | 03fd494 | 2021-07-15 15:56:41 +0800 | [diff] [blame] | 1122 | player->speed, |
| 1123 | player->fffb_current, |
| 1124 | _dvr_time_getClock(), |
| 1125 | _dvr_playback_state_toString(player->state), |
| 1126 | player->next_fffb_time); |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 1127 | //used timeout wait need lock first,so we unlock and lock |
Zhiqiang Han | f9c0e27 | 2022-06-14 13:54:03 +0800 | [diff] [blame] | 1128 | //dvr_mutex_unlock(&player->lock); |
| 1129 | //dvr_mutex_lock(&player->lock); |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 1130 | _dvr_playback_timeoutwait((DVR_PlaybackHandle_t)player, timeout); |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 1131 | DVR_PB_DEBUG("unlock---"); |
Zhiqiang Han | f9c0e27 | 2022-06-14 13:54:03 +0800 | [diff] [blame] | 1132 | dvr_mutex_unlock(&player->lock); |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 1133 | continue; |
hualing chen | b5cd42e | 2020-04-15 17:03:34 +0800 | [diff] [blame] | 1134 | } else if (_dvr_time_getClock() < player->next_fffb_time) { |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 1135 | DVR_PB_INFO("fffb timeout-to pause video---speed[%f] fffb cur[%u] cur sys[%u] [%s] [%u]", |
hualing chen | 03fd494 | 2021-07-15 15:56:41 +0800 | [diff] [blame] | 1136 | player->speed, |
| 1137 | player->fffb_current, |
| 1138 | _dvr_time_getClock(), |
| 1139 | _dvr_playback_state_toString(player->state), |
| 1140 | player->next_fffb_time); |
hualing chen | b5cd42e | 2020-04-15 17:03:34 +0800 | [diff] [blame] | 1141 | //used timeout wait need lock first,so we unlock and lock |
Zhiqiang Han | f9c0e27 | 2022-06-14 13:54:03 +0800 | [diff] [blame] | 1142 | //dvr_mutex_unlock(&player->lock); |
| 1143 | //dvr_mutex_lock(&player->lock); |
hualing chen | b5cd42e | 2020-04-15 17:03:34 +0800 | [diff] [blame] | 1144 | AmTsPlayer_pauseVideoDecoding(player->handle); |
| 1145 | _dvr_playback_timeoutwait((DVR_PlaybackHandle_t)player, timeout); |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 1146 | DVR_PB_DEBUG("unlock---"); |
Zhiqiang Han | f9c0e27 | 2022-06-14 13:54:03 +0800 | [diff] [blame] | 1147 | dvr_mutex_unlock(&player->lock); |
hualing chen | b5cd42e | 2020-04-15 17:03:34 +0800 | [diff] [blame] | 1148 | continue; |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 1149 | } |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 1150 | DVR_PB_INFO("fffb play-------speed[%f][%d][%d][%s][%d]", |
hualing chen | 03fd494 | 2021-07-15 15:56:41 +0800 | [diff] [blame] | 1151 | player->speed, |
| 1152 | goto_rewrite, |
| 1153 | real_read, |
| 1154 | _dvr_playback_state_toString(player->state), |
| 1155 | player->cmd.cur_cmd); |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 1156 | goto_rewrite = DVR_FALSE; |
hualing chen | 87072a8 | 2020-03-12 16:20:12 +0800 | [diff] [blame] | 1157 | real_read = 0; |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 1158 | player->play_flag = player->play_flag & (~DVR_PLAYBACK_STARTED_PAUSEDLIVE); |
| 1159 | player->first_frame = 0; |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 1160 | DVR_PB_INFO("unlock---"); |
Zhiqiang Han | f9c0e27 | 2022-06-14 13:54:03 +0800 | [diff] [blame] | 1161 | dvr_mutex_unlock(&player->lock); |
| 1162 | |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 1163 | _dvr_playback_fffb((DVR_PlaybackHandle_t)player); |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 1164 | DVR_PB_DEBUG("lock---"); |
Zhiqiang Han | f9c0e27 | 2022-06-14 13:54:03 +0800 | [diff] [blame] | 1165 | dvr_mutex_lock(&player->lock); |
Zhiqiang Han | f9c0e27 | 2022-06-14 13:54:03 +0800 | [diff] [blame] | 1166 | player->fffb_play = DVR_FALSE; |
hualing chen | 1ffd85b | 2021-08-16 15:18:43 +0800 | [diff] [blame] | 1167 | } else if(player->state == DVR_PLAYBACK_STATE_PAUSE) { |
| 1168 | //on pause state,user seek to new pos,we need pause and wait |
| 1169 | //user to resume |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 1170 | DVR_PB_INFO("pause, when got first frame event when user seek end"); |
hualing chen | 1ffd85b | 2021-08-16 15:18:43 +0800 | [diff] [blame] | 1171 | player->first_frame = 0; |
| 1172 | AmTsPlayer_setTrickMode(player->handle, AV_VIDEO_TRICK_MODE_NONE); |
| 1173 | AmTsPlayer_pauseVideoDecoding(player->handle); |
| 1174 | AmTsPlayer_pauseAudioDecoding(player->handle); |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1175 | } |
hualing chen | 1ffd85b | 2021-08-16 15:18:43 +0800 | [diff] [blame] | 1176 | } else if (player->fffb_play == DVR_TRUE){ |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 1177 | //for first into fffb when reset speed |
| 1178 | if (player->state == DVR_PLAYBACK_STATE_PAUSE || |
| 1179 | _dvr_time_getClock() < player->next_fffb_time) { |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 1180 | DVR_PB_INFO("fffb timeout-fffb play---speed[%f] fffb cur[%u] cur sys[%u] [%s] [%u]", |
hualing chen | 03fd494 | 2021-07-15 15:56:41 +0800 | [diff] [blame] | 1181 | player->speed, |
| 1182 | player->fffb_current, |
| 1183 | _dvr_time_getClock(), |
| 1184 | _dvr_playback_state_toString(player->state), |
| 1185 | player->next_fffb_time); |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 1186 | //used timeout wait need lock first,so we unlock and lock |
Zhiqiang Han | f9c0e27 | 2022-06-14 13:54:03 +0800 | [diff] [blame] | 1187 | //dvr_mutex_unlock(&player->lock); |
| 1188 | //dvr_mutex_lock(&player->lock); |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 1189 | _dvr_playback_timeoutwait((DVR_PlaybackHandle_t)player, timeout); |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 1190 | DVR_PB_DEBUG("unlock---"); |
Zhiqiang Han | f9c0e27 | 2022-06-14 13:54:03 +0800 | [diff] [blame] | 1191 | dvr_mutex_unlock(&player->lock); |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 1192 | continue; |
| 1193 | } |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 1194 | DVR_PB_INFO("fffb replay-------speed[%f][%d][%d][%s][%d]player->fffb_play[%d]", |
hualing chen | 03fd494 | 2021-07-15 15:56:41 +0800 | [diff] [blame] | 1195 | player->speed, |
| 1196 | goto_rewrite, |
| 1197 | real_read, |
| 1198 | _dvr_playback_state_toString(player->state), |
| 1199 | player->cmd.cur_cmd, |
| 1200 | player->fffb_play); |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 1201 | DVR_PB_DEBUG("unlock---"); |
Zhiqiang Han | f9c0e27 | 2022-06-14 13:54:03 +0800 | [diff] [blame] | 1202 | dvr_mutex_unlock(&player->lock); |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 1203 | goto_rewrite = DVR_FALSE; |
| 1204 | real_read = 0; |
Wentao MA | 63c6cba | 2022-09-20 10:14:29 +0800 | [diff] [blame] | 1205 | pthread_mutex_lock(&player->segment_lock); |
hualing chen | 5605eed | 2020-05-26 18:18:06 +0800 | [diff] [blame] | 1206 | player->ts_cache_len = 0; |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 1207 | player->play_flag = player->play_flag & (~DVR_PLAYBACK_STARTED_PAUSEDLIVE); |
| 1208 | player->first_frame = 0; |
Wentao MA | 63c6cba | 2022-09-20 10:14:29 +0800 | [diff] [blame] | 1209 | pthread_mutex_unlock(&player->segment_lock); |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 1210 | _dvr_playback_fffb((DVR_PlaybackHandle_t)player); |
Zhiqiang Han | f9c0e27 | 2022-06-14 13:54:03 +0800 | [diff] [blame] | 1211 | dvr_mutex_lock(&player->lock); |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 1212 | player->fffb_play = DVR_FALSE; |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 1213 | } |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 1214 | } |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1215 | |
hualing chen | 3042386 | 2021-04-16 14:39:12 +0800 | [diff] [blame] | 1216 | if (player->state == DVR_PLAYBACK_STATE_PAUSE |
| 1217 | && player->seek_pause == DVR_FALSE) { |
hualing chen | 6e4bfa5 | 2020-03-13 14:37:11 +0800 | [diff] [blame] | 1218 | //check is need send time send end |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 1219 | DVR_PB_INFO("pause, continue"); |
| 1220 | DVR_PB_DEBUG("unlock---"); |
Zhiqiang Han | f9c0e27 | 2022-06-14 13:54:03 +0800 | [diff] [blame] | 1221 | dvr_mutex_unlock(&player->lock); |
hualing chen | 2932d37 | 2020-04-29 13:44:00 +0800 | [diff] [blame] | 1222 | _dvr_playback_sent_playtime((DVR_PlaybackHandle_t)player, DVR_FALSE); |
Zhiqiang Han | f9c0e27 | 2022-06-14 13:54:03 +0800 | [diff] [blame] | 1223 | dvr_mutex_lock(&player->lock); |
hualing chen | 87072a8 | 2020-03-12 16:20:12 +0800 | [diff] [blame] | 1224 | _dvr_playback_timeoutwait((DVR_PlaybackHandle_t)player, timeout); |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 1225 | DVR_PB_DEBUG("unlock---"); |
Zhiqiang Han | f9c0e27 | 2022-06-14 13:54:03 +0800 | [diff] [blame] | 1226 | dvr_mutex_unlock(&player->lock); |
hualing chen | 87072a8 | 2020-03-12 16:20:12 +0800 | [diff] [blame] | 1227 | continue; |
| 1228 | } |
hualing chen | 266b950 | 2020-04-04 17:39:39 +0800 | [diff] [blame] | 1229 | //when seek action is done. we need drop write timeout data. |
| 1230 | if (player->drop_ts == DVR_TRUE) { |
| 1231 | goto_rewrite = DVR_FALSE; |
| 1232 | real_read = 0; |
| 1233 | player->drop_ts = DVR_FALSE; |
| 1234 | } |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 1235 | if (goto_rewrite == DVR_TRUE) { |
| 1236 | goto_rewrite = DVR_FALSE; |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 1237 | //DVR_PB_DEBUG("unlock---"); |
Zhiqiang Han | f9c0e27 | 2022-06-14 13:54:03 +0800 | [diff] [blame] | 1238 | dvr_mutex_unlock(&player->lock); |
hualing chen | 3bcf3be | 2021-12-22 20:15:01 +0800 | [diff] [blame] | 1239 | _dvr_playback_sent_playtime((DVR_PlaybackHandle_t)player, DVR_FALSE); |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 1240 | //DVR_PB_INFO("rewrite-player->speed[%f]", player->speed); |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 1241 | goto rewrite; |
| 1242 | } |
hualing chen | 6e4bfa5 | 2020-03-13 14:37:11 +0800 | [diff] [blame] | 1243 | //.check is need send time send end |
Zhiqiang Han | f9c0e27 | 2022-06-14 13:54:03 +0800 | [diff] [blame] | 1244 | dvr_mutex_unlock(&player->lock); |
hualing chen | 2932d37 | 2020-04-29 13:44:00 +0800 | [diff] [blame] | 1245 | _dvr_playback_sent_playtime((DVR_PlaybackHandle_t)player, DVR_FALSE); |
Zhiqiang Han | f9c0e27 | 2022-06-14 13:54:03 +0800 | [diff] [blame] | 1246 | dvr_mutex_lock(&player->lock); |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 1247 | pthread_mutex_lock(&player->segment_lock); |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 1248 | //DVR_PB_INFO("start read"); |
Wentao MA | f35c388 | 2023-04-17 12:36:19 +0800 | [diff] [blame] | 1249 | read = segment_read(player->segment_handle, buf + real_read, buf_len - real_read); |
hualing chen | 21a4037 | 2021-10-29 11:07:26 +0800 | [diff] [blame] | 1250 | real_read = real_read + read; |
| 1251 | player->ts_cache_len = real_read; |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 1252 | //DVR_PB_INFO("start read end [%d]", read); |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 1253 | pthread_mutex_unlock(&player->segment_lock); |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 1254 | //DVR_PB_DEBUG("unlock---"); |
Zhiqiang Han | f9c0e27 | 2022-06-14 13:54:03 +0800 | [diff] [blame] | 1255 | dvr_mutex_unlock(&player->lock); |
hualing chen | b5cd42e | 2020-04-15 17:03:34 +0800 | [diff] [blame] | 1256 | if (read < 0 && errno == EIO) { |
| 1257 | //EIO ERROR, EXIT THRAD |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 1258 | DVR_PB_INFO("read error.EIO error, exit thread"); |
hualing chen | b5cd42e | 2020-04-15 17:03:34 +0800 | [diff] [blame] | 1259 | DVR_Play_Notify_t notify; |
| 1260 | memset(¬ify, 0 , sizeof(DVR_Play_Notify_t)); |
| 1261 | notify.event = DVR_PLAYBACK_EVENT_ERROR; |
hualing chen | 9b434f0 | 2020-06-10 15:06:54 +0800 | [diff] [blame] | 1262 | notify.info.error_reason = DVR_ERROR_REASON_READ; |
hualing chen | 2932d37 | 2020-04-29 13:44:00 +0800 | [diff] [blame] | 1263 | _dvr_playback_sent_event((DVR_PlaybackHandle_t)player,DVR_PLAYBACK_EVENT_ERROR, ¬ify, DVR_TRUE); |
hualing chen | b5cd42e | 2020-04-15 17:03:34 +0800 | [diff] [blame] | 1264 | goto end; |
| 1265 | } else if (read < 0) { |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 1266 | DVR_PB_INFO("read error.:%d EIO:%d", errno, EIO); |
hualing chen | b5cd42e | 2020-04-15 17:03:34 +0800 | [diff] [blame] | 1267 | } |
hualing chen | 87072a8 | 2020-03-12 16:20:12 +0800 | [diff] [blame] | 1268 | //if on fb mode and read file end , we need calculate pos to retry read. |
| 1269 | if (read == 0 && IS_FB(player->speed) && real_read == 0) { |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 1270 | DVR_PB_INFO("recalculate read [%d] readed [%d]buf_len[%d]speed[%f]id=[%llu]", |
hualing chen | 03fd494 | 2021-07-15 15:56:41 +0800 | [diff] [blame] | 1271 | read, |
| 1272 | real_read, |
| 1273 | buf_len, |
| 1274 | player->speed, |
| 1275 | player->cur_segment_id); |
hualing chen | 87072a8 | 2020-03-12 16:20:12 +0800 | [diff] [blame] | 1276 | _dvr_playback_calculate_seekpos((DVR_PlaybackHandle_t)player); |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 1277 | DVR_PB_DEBUG("lock---"); |
Zhiqiang Han | f9c0e27 | 2022-06-14 13:54:03 +0800 | [diff] [blame] | 1278 | dvr_mutex_lock(&player->lock); |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 1279 | _dvr_playback_timeoutwait((DVR_PlaybackHandle_t)player, timeout); |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 1280 | DVR_PB_DEBUG("unlock---"); |
Zhiqiang Han | f9c0e27 | 2022-06-14 13:54:03 +0800 | [diff] [blame] | 1281 | dvr_mutex_unlock(&player->lock); |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 1282 | continue; |
| 1283 | } |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 1284 | //DVR_PB_INFO("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] | 1285 | if (read == 0) { |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 1286 | //file end.need to play next segment |
hualing chen | e41f437 | 2020-06-06 16:29:17 +0800 | [diff] [blame] | 1287 | #define MIN_CACHE_TIME (3000) |
Wentao MA | 804bab1 | 2022-11-29 10:01:26 +0800 | [diff] [blame] | 1288 | int delay = 0; |
| 1289 | get_effective_tsplayer_delay_time(player,&delay); |
hualing chen | e3797f0 | 2021-01-13 14:53:28 +0800 | [diff] [blame] | 1290 | /*if cache time is > min cache time ,not read next segment,wait cache data to play*/ |
Wentao MA | 804bab1 | 2022-11-29 10:01:26 +0800 | [diff] [blame] | 1291 | if (delay > MIN_CACHE_TIME) { |
Zhiqiang Han | f9c0e27 | 2022-06-14 13:54:03 +0800 | [diff] [blame] | 1292 | //dvr_mutex_lock(&player->lock); |
hualing chen | e3797f0 | 2021-01-13 14:53:28 +0800 | [diff] [blame] | 1293 | /*if cache time > 20s , we think get time is error,*/ |
Wentao MA | 804bab1 | 2022-11-29 10:01:26 +0800 | [diff] [blame] | 1294 | if (delay - MIN_CACHE_TIME > 20 * 1000) { |
| 1295 | DVR_PB_WARN("read end but cache time is %d > 20s, this is an error at media_hal", delay); |
hualing chen | e3797f0 | 2021-01-13 14:53:28 +0800 | [diff] [blame] | 1296 | } |
hualing chen | e41f437 | 2020-06-06 16:29:17 +0800 | [diff] [blame] | 1297 | } |
hualing chen | 969fe7b | 2021-05-26 15:13:17 +0800 | [diff] [blame] | 1298 | |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 1299 | int ret = _change_to_next_segment((DVR_PlaybackHandle_t)player); |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 1300 | //init fffb time if change segment |
hualing chen | 041c409 | 2020-04-05 15:11:50 +0800 | [diff] [blame] | 1301 | _dvr_init_fffb_time((DVR_PlaybackHandle_t)player); |
hualing chen | 3114087 | 2020-03-25 12:29:26 +0800 | [diff] [blame] | 1302 | |
Wentao MA | 804bab1 | 2022-11-29 10:01:26 +0800 | [diff] [blame] | 1303 | get_effective_tsplayer_delay_time(player,&delay); |
hualing chen | 1679f81 | 2021-11-08 15:17:46 +0800 | [diff] [blame] | 1304 | if (ret != DVR_SUCCESS && delay < MIN_TSPLAYER_DELAY_TIME) { |
| 1305 | player->noData++; |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 1306 | DVR_PB_INFO("playback nodata[%d]", player->noData); |
hualing chen | 40dd546 | 2021-11-26 19:56:20 +0800 | [diff] [blame] | 1307 | if (player->noData == check_no_data_time) { |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 1308 | DVR_PB_INFO("playback send nodata event nodata[%d]", player->noData); |
hualing chen | e3797f0 | 2021-01-13 14:53:28 +0800 | [diff] [blame] | 1309 | //send event here and pause |
| 1310 | DVR_Play_Notify_t notify; |
| 1311 | memset(¬ify, 0 , sizeof(DVR_Play_Notify_t)); |
| 1312 | notify.event = DVR_PLAYBACK_EVENT_NODATA; |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 1313 | DVR_PB_INFO("send event DVR_PLAYBACK_EVENT_NODATA--"); |
hualing chen | e3797f0 | 2021-01-13 14:53:28 +0800 | [diff] [blame] | 1314 | //get play statue not here |
| 1315 | _dvr_playback_sent_event((DVR_PlaybackHandle_t)player, DVR_PLAYBACK_EVENT_NODATA, ¬ify, DVR_FALSE); |
| 1316 | } |
| 1317 | } |
Wentao MA | a0b9c00 | 2022-11-10 17:47:27 +0800 | [diff] [blame] | 1318 | |
| 1319 | DVR_Bool_t cond1 = (ret != DVR_SUCCESS); |
| 1320 | DVR_Bool_t cond2 = (player->vendor != DVR_PLAYBACK_VENDOR_AMAZON); |
| 1321 | DVR_Bool_t cond3 = (delay <= MIN_TSPLAYER_DELAY_TIME); |
| 1322 | DVR_Bool_t cond4 = (player->cmd.cur_cmd == DVR_PLAYBACK_CMD_FF); |
| 1323 | DVR_Bool_t cond5 = (player->delay_is_effective == DVR_TRUE); |
| 1324 | DVR_Bool_t cond6 = (reach_end_timeout >= MAX_REACHEND_TIMEOUT); |
| 1325 | if ((cond1 && cond2 && (cond3 || cond4) && cond5) || cond6) { |
| 1326 | DVR_PB_INFO("REACHED_END conditions: cond1:%d, cond2:%d, (cond3:%d, cond4:%d)," |
| 1327 | " cond5:%d, cond6:%d. delay:%d, reach_end_timeout:%d", |
| 1328 | (int)cond1,(int)cond2,(int)cond3,(int)cond4,(int)cond5,(int)cond6, |
| 1329 | delay,reach_end_timeout); |
Wentao MA | 804bab1 | 2022-11-29 10:01:26 +0800 | [diff] [blame] | 1330 | DVR_Play_Notify_t notify; |
| 1331 | memset(¬ify, 0 , sizeof(DVR_Play_Notify_t)); |
| 1332 | notify.event = DVR_PLAYBACK_EVENT_REACHED_END; |
| 1333 | dvr_playback_pause((DVR_PlaybackHandle_t)player, DVR_FALSE); |
| 1334 | _dvr_playback_sent_event((DVR_PlaybackHandle_t)player, DVR_PLAYBACK_EVENT_REACHED_END, ¬ify, DVR_TRUE); |
| 1335 | dvr_mutex_lock(&player->lock); |
| 1336 | _dvr_playback_timeoutwait((DVR_PlaybackHandle_t)player, timeout); |
| 1337 | dvr_mutex_unlock(&player->lock); |
| 1338 | continue; |
| 1339 | } else if (ret != DVR_SUCCESS) { |
| 1340 | DVR_PB_INFO("delay:%d pauselive:%d", delay, _dvr_pauselive_decode_success((DVR_PlaybackHandle_t)player)); |
| 1341 | dvr_mutex_lock(&player->lock); |
| 1342 | _dvr_playback_timeoutwait((DVR_PlaybackHandle_t)player, timeout); |
| 1343 | dvr_mutex_unlock(&player->lock); |
| 1344 | |
| 1345 | get_effective_tsplayer_delay_time(player,&delay); |
| 1346 | //not send event and pause,sleep and go to next time to recheck |
| 1347 | if (delay < cache_time) { |
| 1348 | //delay time is changed and then has data to play, so not start timeout |
| 1349 | reach_end_timeout = 0; |
| 1350 | } else { |
| 1351 | reach_end_timeout = reach_end_timeout + timeout; |
| 1352 | } |
| 1353 | cache_time = delay; |
| 1354 | continue; |
| 1355 | } |
hualing chen | 3962821 | 2020-05-14 10:35:13 +0800 | [diff] [blame] | 1356 | reach_end_timeout = 0; |
| 1357 | cache_time = 0; |
hualing chen | 2932d37 | 2020-04-29 13:44:00 +0800 | [diff] [blame] | 1358 | //change next segment success case |
| 1359 | _dvr_playback_sent_transition_ok((DVR_PlaybackHandle_t)player, DVR_FALSE); |
Zhiqiang Han | f9c0e27 | 2022-06-14 13:54:03 +0800 | [diff] [blame] | 1360 | dvr_mutex_lock(&player->lock); |
hualing chen | 40dd546 | 2021-11-26 19:56:20 +0800 | [diff] [blame] | 1361 | player->noData = 0; |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 1362 | DVR_PB_INFO("_dvr_replay_changed_pid:start"); |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame] | 1363 | _dvr_replay_changed_pid((DVR_PlaybackHandle_t)player); |
| 1364 | _dvr_check_cur_segment_flag((DVR_PlaybackHandle_t)player); |
hualing chen | 21a4037 | 2021-10-29 11:07:26 +0800 | [diff] [blame] | 1365 | pthread_mutex_lock(&player->segment_lock); |
Wentao MA | f35c388 | 2023-04-17 12:36:19 +0800 | [diff] [blame] | 1366 | read = segment_read(player->segment_handle, buf + real_read, buf_len - real_read); |
hualing chen | 21a4037 | 2021-10-29 11:07:26 +0800 | [diff] [blame] | 1367 | real_read = real_read + read; |
| 1368 | player->ts_cache_len = real_read; |
| 1369 | pthread_mutex_unlock(&player->segment_lock); |
| 1370 | |
Zhiqiang Han | f9c0e27 | 2022-06-14 13:54:03 +0800 | [diff] [blame] | 1371 | dvr_mutex_unlock(&player->lock); |
hualing chen | e3797f0 | 2021-01-13 14:53:28 +0800 | [diff] [blame] | 1372 | }//read len 0 check end |
Wentao MA | 92a1489 | 2023-09-12 18:54:47 +0800 | [diff] [blame] | 1373 | |
| 1374 | #ifdef FOR_SKYWORTH_FETCH_RDK |
| 1375 | if (player->openParams.is_timeshift == DVR_TRUE && player->speed >= FF_SPEED) |
| 1376 | { |
| 1377 | DVR_PlaybackSegmentInfo_t *newest_segment |
| 1378 | = list_last_entry(&player->segment_list, DVR_PlaybackSegmentInfo_t, head); |
| 1379 | DVR_Bool_t cond1 = (player->cur_segment_id == newest_segment->segment_id); |
| 1380 | int32_t time_end = _dvr_get_end_time((DVR_PlaybackHandle_t)player); |
| 1381 | uint64_t cur_seg_id = 0; |
| 1382 | int32_t time_cur = _dvr_get_play_cur_time((DVR_PlaybackHandle_t)player, &cur_seg_id); |
| 1383 | DVR_Bool_t cond2 = (cur_seg_id == player->cur_segment_id && time_end - time_cur < 1000); |
| 1384 | if (cond1 && cond2) |
| 1385 | { |
| 1386 | DVR_PlaybackSpeed_t normal_speed = {PLAYBACK_SPEED_X1,0}; |
| 1387 | DVR_PB_INFO("Change to normal speed due to FF reaching end"); |
| 1388 | dvr_playback_set_speed((DVR_PlaybackHandle_t)player,normal_speed); |
| 1389 | } |
| 1390 | } |
| 1391 | #endif |
| 1392 | |
hualing chen | 40dd546 | 2021-11-26 19:56:20 +0800 | [diff] [blame] | 1393 | if (player->noData >= check_no_data_time) { |
hualing chen | e3797f0 | 2021-01-13 14:53:28 +0800 | [diff] [blame] | 1394 | player->noData = 0; |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 1395 | DVR_PB_INFO("playback send data event resume[%d]", player->noData); |
hualing chen | e3797f0 | 2021-01-13 14:53:28 +0800 | [diff] [blame] | 1396 | //send event here and pause |
| 1397 | DVR_Play_Notify_t notify; |
| 1398 | memset(¬ify, 0 , sizeof(DVR_Play_Notify_t)); |
| 1399 | notify.event = DVR_PLAYBACK_EVENT_DATARESUME; |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 1400 | DVR_PB_INFO("----send event DVR_PLAYBACK_EVENT_DATARESUME"); |
hualing chen | e3797f0 | 2021-01-13 14:53:28 +0800 | [diff] [blame] | 1401 | //get play statue not here |
| 1402 | _dvr_playback_sent_event((DVR_PlaybackHandle_t)player, DVR_PLAYBACK_EVENT_DATARESUME, ¬ify, DVR_FALSE); |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1403 | } |
hualing chen | 3962821 | 2020-05-14 10:35:13 +0800 | [diff] [blame] | 1404 | reach_end_timeout = 0; |
hualing chen | 21a4037 | 2021-10-29 11:07:26 +0800 | [diff] [blame] | 1405 | //real_read = real_read + read; |
Wentao MA | 270dc0f | 2022-08-23 13:17:26 +0800 | [diff] [blame] | 1406 | input_buffer.buf_size = real_read; |
| 1407 | input_buffer.buf_data = buf; |
hualing chen | 5605eed | 2020-05-26 18:18:06 +0800 | [diff] [blame] | 1408 | |
Wentao MA | 270dc0f | 2022-08-23 13:17:26 +0800 | [diff] [blame] | 1409 | //check read data len,if len < 0, we need continue |
| 1410 | if (input_buffer.buf_size <= 0 || input_buffer.buf_data == NULL) { |
| 1411 | DVR_PB_INFO("error occur read_read [%d],buf=[%p]",input_buffer.buf_size, input_buffer.buf_data); |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 1412 | real_read = 0; |
Wentao MA | 63c6cba | 2022-09-20 10:14:29 +0800 | [diff] [blame] | 1413 | pthread_mutex_lock(&player->segment_lock); |
hualing chen | 5605eed | 2020-05-26 18:18:06 +0800 | [diff] [blame] | 1414 | player->ts_cache_len = 0; |
Wentao MA | 63c6cba | 2022-09-20 10:14:29 +0800 | [diff] [blame] | 1415 | pthread_mutex_unlock(&player->segment_lock); |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 1416 | continue; |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 1417 | } |
hualing chen | 266b950 | 2020-04-04 17:39:39 +0800 | [diff] [blame] | 1418 | //if need write whole block size, we need check read buf len is eq block size. |
Wentao MA | a0b9c00 | 2022-11-10 17:47:27 +0800 | [diff] [blame] | 1419 | if (b_writed_whole_block == DVR_TRUE |
| 1420 | && (player->has_video || player->dec_func || player->cryptor)) { |
hualing chen | 266b950 | 2020-04-04 17:39:39 +0800 | [diff] [blame] | 1421 | //buf_len is block size value. |
| 1422 | if (real_read < buf_len) { |
Wentao MA | 270dc0f | 2022-08-23 13:17:26 +0800 | [diff] [blame] | 1423 | //continue to read data from file |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 1424 | DVR_PB_INFO("read buf len[%d] is < block size [%d]", real_read, buf_len); |
Zhiqiang Han | f9c0e27 | 2022-06-14 13:54:03 +0800 | [diff] [blame] | 1425 | dvr_mutex_lock(&player->lock); |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 1426 | _dvr_playback_timeoutwait((DVR_PlaybackHandle_t)player, timeout); |
| 1427 | dvr_mutex_unlock(&player->lock); |
| 1428 | DVR_PB_INFO("read buf len[%d] is < block size [%d] continue", real_read, buf_len); |
hualing chen | 266b950 | 2020-04-04 17:39:39 +0800 | [diff] [blame] | 1429 | continue; |
| 1430 | } else if (real_read > buf_len) { |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 1431 | DVR_PB_INFO("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] | 1432 | } |
| 1433 | } |
| 1434 | |
weishi.zhang | 0a6d5c8 | 2021-12-13 14:05:31 +0800 | [diff] [blame] | 1435 | if (player->dec_func) { |
pengfei.liu | 27cc4ec | 2020-04-03 16:28:16 +0800 | [diff] [blame] | 1436 | DVR_CryptoParams_t crypto_params; |
| 1437 | |
| 1438 | memset(&crypto_params, 0, sizeof(crypto_params)); |
| 1439 | crypto_params.type = DVR_CRYPTO_TYPE_DECRYPT; |
| 1440 | memcpy(crypto_params.location, player->cur_segment.location, strlen(player->cur_segment.location)); |
| 1441 | crypto_params.segment_id = player->cur_segment.segment_id; |
Wentao MA | f35c388 | 2023-04-17 12:36:19 +0800 | [diff] [blame] | 1442 | crypto_params.offset = segment_tell_position(player->segment_handle) - input_buffer.buf_size; |
hualing chen | bafc62d | 2020-11-02 15:44:05 +0800 | [diff] [blame] | 1443 | if ((crypto_params.offset % (player->openParams.block_size)) != 0) |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 1444 | DVR_PB_INFO("offset is not block_size %d", player->openParams.block_size); |
pengfei.liu | 27cc4ec | 2020-04-03 16:28:16 +0800 | [diff] [blame] | 1445 | crypto_params.input_buffer.type = DVR_BUFFER_TYPE_NORMAL; |
| 1446 | crypto_params.input_buffer.addr = (size_t)buf; |
| 1447 | crypto_params.input_buffer.size = real_read; |
| 1448 | |
weishi.zhang | 0a6d5c8 | 2021-12-13 14:05:31 +0800 | [diff] [blame] | 1449 | if (player->is_secure_mode) { |
| 1450 | crypto_params.output_buffer.type = DVR_BUFFER_TYPE_SECURE; |
| 1451 | crypto_params.output_buffer.addr = (size_t)player->secure_buffer; |
| 1452 | crypto_params.output_buffer.size = dec_buf_size; |
| 1453 | ret = player->dec_func(&crypto_params, player->dec_userdata); |
Wentao MA | 270dc0f | 2022-08-23 13:17:26 +0800 | [diff] [blame] | 1454 | input_buffer.buf_data = player->secure_buffer; |
| 1455 | input_buffer.buf_type = TS_INPUT_BUFFER_TYPE_SECURE; |
weishi.zhang | 0a6d5c8 | 2021-12-13 14:05:31 +0800 | [diff] [blame] | 1456 | if (ret != DVR_SUCCESS) { |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 1457 | DVR_PB_INFO("decrypt failed"); |
weishi.zhang | 0a6d5c8 | 2021-12-13 14:05:31 +0800 | [diff] [blame] | 1458 | } |
Wentao MA | 270dc0f | 2022-08-23 13:17:26 +0800 | [diff] [blame] | 1459 | input_buffer.buf_size = crypto_params.output_size; |
weishi.zhang | 0a6d5c8 | 2021-12-13 14:05:31 +0800 | [diff] [blame] | 1460 | } else { // only for NAGRA |
| 1461 | crypto_params.output_buffer.type = crypto_params.input_buffer.type; |
| 1462 | crypto_params.output_buffer.addr = (size_t)dec_bufs.buf_data; |
| 1463 | crypto_params.output_buffer.size = crypto_params.input_buffer.size; |
| 1464 | ret = player->dec_func(&crypto_params, player->dec_userdata); |
Wentao MA | 270dc0f | 2022-08-23 13:17:26 +0800 | [diff] [blame] | 1465 | input_buffer.buf_data = (uint8_t*)crypto_params.output_buffer.addr; |
| 1466 | input_buffer.buf_type = TS_INPUT_BUFFER_TYPE_NORMAL; |
weishi.zhang | 0a6d5c8 | 2021-12-13 14:05:31 +0800 | [diff] [blame] | 1467 | if (ret != DVR_SUCCESS) { |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 1468 | DVR_PB_INFO("decrypt failed"); |
weishi.zhang | 0a6d5c8 | 2021-12-13 14:05:31 +0800 | [diff] [blame] | 1469 | } |
Wentao MA | 270dc0f | 2022-08-23 13:17:26 +0800 | [diff] [blame] | 1470 | input_buffer.buf_size = crypto_params.output_buffer.size; |
pengfei.liu | 27cc4ec | 2020-04-03 16:28:16 +0800 | [diff] [blame] | 1471 | } |
Yahui Han | 1fbf329 | 2021-11-08 18:17:19 +0800 | [diff] [blame] | 1472 | } else if (player->cryptor) { |
Yahui Han | 63b23b4 | 2021-12-07 15:37:46 +0800 | [diff] [blame] | 1473 | int len = real_read; |
Yahui Han | 1fbf329 | 2021-11-08 18:17:19 +0800 | [diff] [blame] | 1474 | am_crypt_des_crypt(player->cryptor, dec_bufs.buf_data, buf, &len, 1); |
Wentao MA | 270dc0f | 2022-08-23 13:17:26 +0800 | [diff] [blame] | 1475 | input_buffer.buf_data = dec_bufs.buf_data; |
| 1476 | input_buffer.buf_type = TS_INPUT_BUFFER_TYPE_NORMAL; |
| 1477 | input_buffer.buf_size = len; |
pengfei.liu | 27cc4ec | 2020-04-03 16:28:16 +0800 | [diff] [blame] | 1478 | } |
pengfei.liu | 07ddc8a | 2020-03-24 23:36:53 +0800 | [diff] [blame] | 1479 | rewrite: |
hualing chen | bcada02 | 2020-04-22 14:27:01 +0800 | [diff] [blame] | 1480 | if (player->drop_ts == DVR_TRUE) { |
| 1481 | //need drop ts data when seek occur.we need read next loop,drop this ts data |
| 1482 | goto_rewrite = DVR_FALSE; |
| 1483 | real_read = 0; |
Wentao MA | 63c6cba | 2022-09-20 10:14:29 +0800 | [diff] [blame] | 1484 | pthread_mutex_lock(&player->segment_lock); |
hualing chen | 5605eed | 2020-05-26 18:18:06 +0800 | [diff] [blame] | 1485 | player->ts_cache_len = 0; |
hualing chen | bcada02 | 2020-04-22 14:27:01 +0800 | [diff] [blame] | 1486 | player->drop_ts = DVR_FALSE; |
Wentao MA | 63c6cba | 2022-09-20 10:14:29 +0800 | [diff] [blame] | 1487 | pthread_mutex_unlock(&player->segment_lock); |
| 1488 | DVR_PB_INFO("----drop ts"); |
hualing chen | bcada02 | 2020-04-22 14:27:01 +0800 | [diff] [blame] | 1489 | continue; |
| 1490 | } |
hualing chen | 21a4037 | 2021-10-29 11:07:26 +0800 | [diff] [blame] | 1491 | |
| 1492 | pthread_mutex_lock(&player->segment_lock); |
hualing chen | 5605eed | 2020-05-26 18:18:06 +0800 | [diff] [blame] | 1493 | player->ts_cache_len = real_read; |
hualing chen | b9a0292 | 2021-12-14 11:29:47 +0800 | [diff] [blame] | 1494 | //used for printf first write data time. |
| 1495 | //to check change channel kpi. |
| 1496 | if (first_write == 0) { |
| 1497 | first_write++; |
Wentao MA | 270dc0f | 2022-08-23 13:17:26 +0800 | [diff] [blame] | 1498 | DVR_PB_INFO("----first write ts data"); |
hualing chen | b9a0292 | 2021-12-14 11:29:47 +0800 | [diff] [blame] | 1499 | } |
| 1500 | |
Wentao MA | 270dc0f | 2022-08-23 13:17:26 +0800 | [diff] [blame] | 1501 | ret = AmTsPlayer_writeData(player->handle, &input_buffer, write_timeout_ms); |
pengfei.liu | 07ddc8a | 2020-03-24 23:36:53 +0800 | [diff] [blame] | 1502 | if (ret == AM_TSPLAYER_OK) { |
hualing chen | 5605eed | 2020-05-26 18:18:06 +0800 | [diff] [blame] | 1503 | player->ts_cache_len = 0; |
hualing chen | 21a4037 | 2021-10-29 11:07:26 +0800 | [diff] [blame] | 1504 | pthread_mutex_unlock(&player->segment_lock); |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 1505 | real_read = 0; |
| 1506 | write_success++; |
shenghui.geng | bec6a46 | 2023-01-12 15:21:02 +0800 | [diff] [blame] | 1507 | if (player->control_speed_enable == 1) { |
hualing chen | d241c7a | 2021-06-22 13:34:27 +0800 | [diff] [blame] | 1508 | check0: |
Yahui Han | c7ab63d | 2022-08-29 15:59:08 +0800 | [diff] [blame] | 1509 | if (!player->is_running) { |
Yahui Han | 28c66ed | 2022-09-08 10:32:33 +0800 | [diff] [blame] | 1510 | //DVR_PB_DEBUG(1, "playback thread exit"); |
Yahui Han | c7ab63d | 2022-08-29 15:59:08 +0800 | [diff] [blame] | 1511 | break; |
| 1512 | } |
hualing chen | d241c7a | 2021-06-22 13:34:27 +0800 | [diff] [blame] | 1513 | if (_dvr_check_speed_con((DVR_PlaybackHandle_t)player) == DVR_FALSE){ |
Zhiqiang Han | f9c0e27 | 2022-06-14 13:54:03 +0800 | [diff] [blame] | 1514 | dvr_mutex_lock(&player->lock); |
hualing chen | d241c7a | 2021-06-22 13:34:27 +0800 | [diff] [blame] | 1515 | _dvr_playback_timeoutwait((DVR_PlaybackHandle_t)player, 50); |
Zhiqiang Han | f9c0e27 | 2022-06-14 13:54:03 +0800 | [diff] [blame] | 1516 | dvr_mutex_unlock(&player->lock); |
hualing chen | d241c7a | 2021-06-22 13:34:27 +0800 | [diff] [blame] | 1517 | _dvr_playback_sent_playtime((DVR_PlaybackHandle_t)player, DVR_FALSE); |
| 1518 | goto check0; |
| 1519 | } |
| 1520 | } |
Wentao MA | 270dc0f | 2022-08-23 13:17:26 +0800 | [diff] [blame] | 1521 | //DVR_PB_INFO("write write_success:%d input_buffer.buf_size:%d", write_success, input_buffer.buf_size); |
hualing chen | 87072a8 | 2020-03-12 16:20:12 +0800 | [diff] [blame] | 1522 | } else { |
Wentao MA | 804bab1 | 2022-11-29 10:01:26 +0800 | [diff] [blame] | 1523 | pthread_mutex_unlock(&player->segment_lock); |
wentao.ma | 4ee4302 | 2022-12-14 13:22:57 +0800 | [diff] [blame] | 1524 | DVR_PB_DEBUG("write time out write_success:%d buf_size:%d systime:%u", |
| 1525 | write_success, input_buffer.buf_size, _dvr_time_getClock()); |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 1526 | write_success = 0; |
shenghui.geng | bec6a46 | 2023-01-12 15:21:02 +0800 | [diff] [blame] | 1527 | if (player->control_speed_enable == 1) { |
hualing chen | d241c7a | 2021-06-22 13:34:27 +0800 | [diff] [blame] | 1528 | check1: |
Yahui Han | c7ab63d | 2022-08-29 15:59:08 +0800 | [diff] [blame] | 1529 | if (!player->is_running) { |
Yahui Han | 28c66ed | 2022-09-08 10:32:33 +0800 | [diff] [blame] | 1530 | //DVR_PB_DEBUG(1, "playback thread exit"); |
Yahui Han | c7ab63d | 2022-08-29 15:59:08 +0800 | [diff] [blame] | 1531 | break; |
| 1532 | } |
hualing chen | d241c7a | 2021-06-22 13:34:27 +0800 | [diff] [blame] | 1533 | if (_dvr_check_speed_con((DVR_PlaybackHandle_t)player) == DVR_FALSE){ |
Zhiqiang Han | f9c0e27 | 2022-06-14 13:54:03 +0800 | [diff] [blame] | 1534 | dvr_mutex_lock(&player->lock); |
hualing chen | d241c7a | 2021-06-22 13:34:27 +0800 | [diff] [blame] | 1535 | _dvr_playback_timeoutwait((DVR_PlaybackHandle_t)player, 50); |
Zhiqiang Han | f9c0e27 | 2022-06-14 13:54:03 +0800 | [diff] [blame] | 1536 | dvr_mutex_unlock(&player->lock); |
hualing chen | d241c7a | 2021-06-22 13:34:27 +0800 | [diff] [blame] | 1537 | _dvr_playback_sent_playtime((DVR_PlaybackHandle_t)player, DVR_FALSE); |
| 1538 | goto check1; |
| 1539 | } |
| 1540 | } |
Zhiqiang Han | f9c0e27 | 2022-06-14 13:54:03 +0800 | [diff] [blame] | 1541 | dvr_mutex_lock(&player->lock); |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 1542 | _dvr_playback_timeoutwait((DVR_PlaybackHandle_t)player, timeout); |
Zhiqiang Han | f9c0e27 | 2022-06-14 13:54:03 +0800 | [diff] [blame] | 1543 | dvr_mutex_unlock(&player->lock); |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1544 | if (!player->is_running) { |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 1545 | DVR_PB_INFO("playback thread exit"); |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1546 | break; |
| 1547 | } |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 1548 | goto_rewrite = DVR_TRUE; |
| 1549 | //goto rewrite; |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1550 | } |
| 1551 | } |
hualing chen | b5cd42e | 2020-04-15 17:03:34 +0800 | [diff] [blame] | 1552 | end: |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 1553 | DVR_PB_INFO("playback thread is end"); |
pengfei.liu | 07ddc8a | 2020-03-24 23:36:53 +0800 | [diff] [blame] | 1554 | free(buf); |
| 1555 | free(dec_bufs.buf_data); |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1556 | return NULL; |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 1557 | } |
| 1558 | |
| 1559 | |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 1560 | static int _start_playback_thread(DVR_PlaybackHandle_t handle) |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 1561 | { |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 1562 | DVR_Playback_t *player = (DVR_Playback_t *) handle; |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 1563 | |
| 1564 | if (player == NULL) { |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 1565 | DVR_PB_INFO("player is NULL"); |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 1566 | return DVR_FAILURE; |
| 1567 | } |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 1568 | DVR_PB_INFO("start thread is_running:[%d]", player->is_running); |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame] | 1569 | if (player->is_running == DVR_TRUE) { |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 1570 | return 0; |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1571 | } |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 1572 | player->is_running = DVR_TRUE; |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1573 | 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] | 1574 | if (rc < 0) |
| 1575 | player->is_running = DVR_FALSE; |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1576 | return 0; |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 1577 | } |
| 1578 | |
| 1579 | |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 1580 | static int _stop_playback_thread(DVR_PlaybackHandle_t handle) |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1581 | { |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 1582 | DVR_Playback_t *player = (DVR_Playback_t *) handle; |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 1583 | |
| 1584 | if (player == NULL) { |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 1585 | DVR_PB_INFO("player is NULL"); |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 1586 | return DVR_FAILURE; |
| 1587 | } |
| 1588 | |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 1589 | DVR_PB_INFO("stopthread------[%d]", player->is_running); |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame] | 1590 | if (player->is_running == DVR_TRUE) |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1591 | { |
| 1592 | player->is_running = DVR_FALSE; |
hualing chen | 87072a8 | 2020-03-12 16:20:12 +0800 | [diff] [blame] | 1593 | _dvr_playback_sendSignal(handle); |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1594 | pthread_join(player->playback_thread, NULL); |
| 1595 | } |
Wentao MA | f35c388 | 2023-04-17 12:36:19 +0800 | [diff] [blame] | 1596 | if (player->segment_handle) { |
| 1597 | segment_close(player->segment_handle); |
| 1598 | player->segment_handle = NULL; |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1599 | } |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 1600 | DVR_PB_INFO(":end"); |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1601 | return 0; |
| 1602 | } |
| 1603 | |
hualing chen | 1679f81 | 2021-11-08 15:17:46 +0800 | [diff] [blame] | 1604 | static int getFakePid() |
| 1605 | { |
wentao ma | 7d64278 | 2022-10-23 18:26:16 -0700 | [diff] [blame] | 1606 | return dvr_prop_read_int("vendor.tv.dtv.fake_pid",0xffff); |
hualing chen | 1679f81 | 2021-11-08 15:17:46 +0800 | [diff] [blame] | 1607 | } |
| 1608 | |
| 1609 | void dvr_playback_change_seek_state(DVR_PlaybackHandle_t handle,int pid) { |
| 1610 | |
| 1611 | DVR_ASSERT(handle); |
| 1612 | DVR_Playback_t *player = (DVR_Playback_t *) handle; |
| 1613 | if (player == NULL) { |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 1614 | DVR_PB_INFO("player is NULL"); |
hualing chen | 1679f81 | 2021-11-08 15:17:46 +0800 | [diff] [blame] | 1615 | return ; |
| 1616 | } |
| 1617 | if (player->need_seek_start == DVR_FALSE) { |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 1618 | DVR_PB_INFO("player need_seek_start is false"); |
hualing chen | 1679f81 | 2021-11-08 15:17:46 +0800 | [diff] [blame] | 1619 | return ; |
| 1620 | } |
| 1621 | |
hualing chen | a5f0322 | 2021-12-02 11:22:35 +0800 | [diff] [blame] | 1622 | if (pid != player->fake_pid) { |
hualing chen | 1679f81 | 2021-11-08 15:17:46 +0800 | [diff] [blame] | 1623 | player->need_seek_start = DVR_FALSE; |
| 1624 | } |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 1625 | DVR_PB_INFO("player player->need_seek_start=%d", player->need_seek_start); |
hualing chen | 1679f81 | 2021-11-08 15:17:46 +0800 | [diff] [blame] | 1626 | } |
| 1627 | |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 1628 | /**\brief Open an dvr palyback |
| 1629 | * \param[out] p_handle dvr playback addr |
| 1630 | * \param[in] params dvr playback open parameters |
| 1631 | * \retval DVR_SUCCESS On success |
| 1632 | * \return Error code |
| 1633 | */ |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 1634 | 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] | 1635 | |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 1636 | DVR_Playback_t *player; |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1637 | pthread_condattr_t cattr; |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 1638 | |
Zhiqiang Han | 2d8cd82 | 2020-03-16 13:58:10 +0800 | [diff] [blame] | 1639 | player = (DVR_Playback_t*)calloc(1, sizeof(DVR_Playback_t)); |
wentao.ma | a22bc85 | 2022-10-13 12:18:06 +0800 | [diff] [blame] | 1640 | DVR_RETURN_IF_FALSE(player); |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 1641 | |
Zhiqiang Han | f9c0e27 | 2022-06-14 13:54:03 +0800 | [diff] [blame] | 1642 | dvr_mutex_init(&player->lock); |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 1643 | pthread_mutex_init(&player->segment_lock, NULL); |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1644 | pthread_condattr_init(&cattr); |
| 1645 | pthread_condattr_setclock(&cattr, CLOCK_MONOTONIC); |
| 1646 | pthread_cond_init(&player->cond, &cattr); |
| 1647 | pthread_condattr_destroy(&cattr); |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 1648 | |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 1649 | //init segment list head |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 1650 | INIT_LIST_HEAD(&player->segment_list); |
| 1651 | player->cmd.last_cmd = DVR_PLAYBACK_CMD_STOP; |
| 1652 | player->cmd.cur_cmd = DVR_PLAYBACK_CMD_STOP; |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 1653 | player->cmd.speed.speed.speed = PLAYBACK_SPEED_X1; |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 1654 | player->cmd.state = DVR_PLAYBACK_STATE_STOP; |
Wentao MA | 907b643 | 2022-08-01 06:23:08 +0000 | [diff] [blame] | 1655 | DVR_PLAYER_CHANGE_STATE(player,DVR_PLAYBACK_STATE_STOP); |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1656 | player->cmd.pos = 0; |
hualing chen | 3114087 | 2020-03-25 12:29:26 +0800 | [diff] [blame] | 1657 | player->speed = 1.0f; |
hualing chen | e41f437 | 2020-06-06 16:29:17 +0800 | [diff] [blame] | 1658 | player->first_trans_ok = DVR_FALSE; |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 1659 | |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1660 | //store open params |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 1661 | player->openParams.dmx_dev_id = params->dmx_dev_id; |
| 1662 | player->openParams.block_size = params->block_size; |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 1663 | DVR_PB_INFO("playback open block_size:[%d]",params->block_size); |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1664 | player->openParams.is_timeshift = params->is_timeshift; |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame] | 1665 | player->openParams.event_fn = params->event_fn; |
| 1666 | player->openParams.event_userdata = params->event_userdata; |
hualing chen | e3797f0 | 2021-01-13 14:53:28 +0800 | [diff] [blame] | 1667 | player->openParams.is_notify_time = params->is_notify_time; |
hualing chen | fbf8e02 | 2020-06-15 13:43:11 +0800 | [diff] [blame] | 1668 | player->vendor = params->vendor; |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame] | 1669 | |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 1670 | player->has_pids = params->has_pids; |
| 1671 | |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 1672 | player->handle = params->player_handle ; |
shenghui.geng | bec6a46 | 2023-01-12 15:21:02 +0800 | [diff] [blame] | 1673 | player->control_speed_enable = params->control_speed_enable; |
hualing chen | 6e4bfa5 | 2020-03-13 14:37:11 +0800 | [diff] [blame] | 1674 | |
| 1675 | AmTsPlayer_getCb(player->handle, &player->player_callback_func, &player->player_callback_userdata); |
| 1676 | //for test get callback |
| 1677 | if (0 && player->player_callback_func == NULL) { |
| 1678 | AmTsPlayer_registerCb(player->handle, _dvr_tsplayer_callback_test, player); |
| 1679 | AmTsPlayer_getCb(player->handle, &player->player_callback_func, &player->player_callback_userdata); |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 1680 | DVR_PB_INFO("playback open get callback[%p][%p][%p][%p]", |
hualing chen | 03fd494 | 2021-07-15 15:56:41 +0800 | [diff] [blame] | 1681 | player->player_callback_func, |
| 1682 | player->player_callback_userdata, |
| 1683 | _dvr_tsplayer_callback_test, |
| 1684 | player); |
hualing chen | 6e4bfa5 | 2020-03-13 14:37:11 +0800 | [diff] [blame] | 1685 | } |
| 1686 | AmTsPlayer_registerCb(player->handle, _dvr_tsplayer_callback, player); |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 1687 | |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1688 | //init has audio and video |
| 1689 | player->has_video = DVR_FALSE; |
| 1690 | player->has_audio = DVR_FALSE; |
hualing chen | 87072a8 | 2020-03-12 16:20:12 +0800 | [diff] [blame] | 1691 | player->cur_segment_id = UINT64_MAX; |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame] | 1692 | player->last_segment_id = 0LL; |
| 1693 | player->segment_is_open = DVR_FALSE; |
Wentao MA | 5629ad8 | 2022-08-24 10:03:02 +0800 | [diff] [blame] | 1694 | player->audio_presentation_id = -1; |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 1695 | |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 1696 | //init ff fb time |
hualing chen | 7ea70a7 | 2021-09-09 11:25:13 +0800 | [diff] [blame] | 1697 | player->fffb_current = 0; |
| 1698 | player->fffb_start = 0; |
hualing chen | 03fd494 | 2021-07-15 15:56:41 +0800 | [diff] [blame] | 1699 | player->fffb_start_pcr = 0; |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 1700 | //seek time |
| 1701 | player->seek_time = 0; |
hualing chen | 6e4bfa5 | 2020-03-13 14:37:11 +0800 | [diff] [blame] | 1702 | player->send_time = 0; |
pengfei.liu | 07ddc8a | 2020-03-24 23:36:53 +0800 | [diff] [blame] | 1703 | |
Yahui Han | 1fbf329 | 2021-11-08 18:17:19 +0800 | [diff] [blame] | 1704 | //allocate cryptor if have clearkey |
| 1705 | if (params->keylen > 0) { |
| 1706 | player->cryptor = am_crypt_des_open((uint8_t *)params->clearkey, |
hualing chen | 002e5b9 | 2022-02-23 17:51:21 +0800 | [diff] [blame] | 1707 | (uint8_t *)params->cleariv, |
| 1708 | params->keylen * 8); |
Yahui Han | 1fbf329 | 2021-11-08 18:17:19 +0800 | [diff] [blame] | 1709 | if (!player->cryptor) { |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 1710 | DVR_INFO("%s , open des cryptor failed!!!\n", __func__); |
Yahui Han | 1fbf329 | 2021-11-08 18:17:19 +0800 | [diff] [blame] | 1711 | } |
| 1712 | } else { |
| 1713 | player->cryptor = NULL; |
| 1714 | } |
| 1715 | |
pengfei.liu | 07ddc8a | 2020-03-24 23:36:53 +0800 | [diff] [blame] | 1716 | //init secure stuff |
| 1717 | player->dec_func = NULL; |
| 1718 | player->dec_userdata = NULL; |
| 1719 | player->is_secure_mode = 0; |
| 1720 | player->secure_buffer = NULL; |
| 1721 | player->secure_buffer_size = 0; |
hualing chen | 266b950 | 2020-04-04 17:39:39 +0800 | [diff] [blame] | 1722 | player->drop_ts = DVR_FALSE; |
pengfei.liu | 07ddc8a | 2020-03-24 23:36:53 +0800 | [diff] [blame] | 1723 | |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 1724 | player->fffb_play = DVR_FALSE; |
| 1725 | |
| 1726 | player->last_send_time_id = UINT64_MAX; |
| 1727 | player->last_cur_time = 0; |
hualing chen | 3042386 | 2021-04-16 14:39:12 +0800 | [diff] [blame] | 1728 | player->seek_pause = DVR_FALSE; |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 1729 | |
hualing chen | d241c7a | 2021-06-22 13:34:27 +0800 | [diff] [blame] | 1730 | //speed con init |
shenghui.geng | bec6a46 | 2023-01-12 15:21:02 +0800 | [diff] [blame] | 1731 | if (player->control_speed_enable == 1) { |
hualing chen | d241c7a | 2021-06-22 13:34:27 +0800 | [diff] [blame] | 1732 | player->con_spe.ply_dur = 0; |
hualing chen | 7ea70a7 | 2021-09-09 11:25:13 +0800 | [diff] [blame] | 1733 | player->con_spe.ply_sta = 0; |
hualing chen | d241c7a | 2021-06-22 13:34:27 +0800 | [diff] [blame] | 1734 | player->con_spe.sys_dur = 0; |
| 1735 | player->con_spe.sys_sta = 0; |
| 1736 | } |
| 1737 | |
hualing chen | 03fd494 | 2021-07-15 15:56:41 +0800 | [diff] [blame] | 1738 | //limit info |
| 1739 | player->rec_start = 0; |
hualing chen | 7ea70a7 | 2021-09-09 11:25:13 +0800 | [diff] [blame] | 1740 | player->limit = 0; |
hualing chen | 8a657f3 | 2021-08-30 13:12:49 +0800 | [diff] [blame] | 1741 | //need seek to start pos |
| 1742 | player->first_start_time = 0; |
Wentao MA | 01de0e6 | 2022-01-10 18:48:23 +0800 | [diff] [blame] | 1743 | player->first_start_id = UINT64_MAX; |
Wentao MA | a0b9c00 | 2022-11-10 17:47:27 +0800 | [diff] [blame] | 1744 | player->delay_is_effective = DVR_FALSE; |
hualing chen | 8a657f3 | 2021-08-30 13:12:49 +0800 | [diff] [blame] | 1745 | player->need_seek_start = DVR_TRUE; |
hualing chen | a5f0322 | 2021-12-02 11:22:35 +0800 | [diff] [blame] | 1746 | //fake_pid init |
| 1747 | player->fake_pid = getFakePid(); |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1748 | *p_handle = player; |
| 1749 | return DVR_SUCCESS; |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 1750 | } |
| 1751 | |
| 1752 | /**\brief Close an dvr palyback |
| 1753 | * \param[in] handle playback handle |
| 1754 | * \retval DVR_SUCCESS On success |
| 1755 | * \return Error code |
| 1756 | */ |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 1757 | int dvr_playback_close(DVR_PlaybackHandle_t handle) { |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 1758 | |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1759 | DVR_ASSERT(handle); |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 1760 | DVR_PB_INFO(":into"); |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 1761 | DVR_Playback_t *player = (DVR_Playback_t *) handle; |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 1762 | if (player == NULL) { |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 1763 | DVR_PB_INFO("player is NULL"); |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 1764 | return DVR_FAILURE; |
| 1765 | } |
| 1766 | |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame] | 1767 | if (player->state != DVR_PLAYBACK_STATE_STOP) |
| 1768 | { |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 1769 | DVR_PB_INFO("player->state %s", _dvr_playback_state_toString(player->state)); |
Yahui Han | 1fbf329 | 2021-11-08 18:17:19 +0800 | [diff] [blame] | 1770 | if (player->cryptor) { |
| 1771 | am_crypt_des_close(player->cryptor); |
| 1772 | player->cryptor = NULL; |
| 1773 | } |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame] | 1774 | dvr_playback_stop(handle, DVR_TRUE); |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 1775 | DVR_PB_INFO("player->state %s", _dvr_playback_state_toString(player->state)); |
hualing chen | b96aa2c | 2020-04-15 14:13:53 +0800 | [diff] [blame] | 1776 | } else { |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 1777 | DVR_PB_INFO(":is stoped state"); |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame] | 1778 | } |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 1779 | DVR_PB_INFO(":into"); |
Zhiqiang Han | f9c0e27 | 2022-06-14 13:54:03 +0800 | [diff] [blame] | 1780 | dvr_mutex_destroy(&player->lock); |
Zhiqiang Han | c951346 | 2022-06-21 09:55:23 +0800 | [diff] [blame] | 1781 | pthread_mutex_destroy(&player->segment_lock); |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1782 | pthread_cond_destroy(&player->cond); |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 1783 | |
| 1784 | if (player) { |
| 1785 | free(player); |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 1786 | } |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 1787 | DVR_PB_INFO(":end"); |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1788 | return DVR_SUCCESS; |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 1789 | } |
| 1790 | |
Wentao MA | 270dc0f | 2022-08-23 13:17:26 +0800 | [diff] [blame] | 1791 | /**\brief Start play audio and video, used start audio api and start video api |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 1792 | * \param[in] handle playback handle |
| 1793 | * \param[in] params audio playback params,contains fmt and pid... |
| 1794 | * \retval DVR_SUCCESS On success |
| 1795 | * \return Error code |
| 1796 | */ |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 1797 | int dvr_playback_start(DVR_PlaybackHandle_t handle, DVR_PlaybackFlag_t flag) { |
| 1798 | DVR_Playback_t *player = (DVR_Playback_t *) handle; |
Wentao MA | 270dc0f | 2022-08-23 13:17:26 +0800 | [diff] [blame] | 1799 | am_tsplayer_video_params video_params; |
| 1800 | am_tsplayer_audio_params audio_params; |
| 1801 | am_tsplayer_audio_params ad_params; |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 1802 | |
Wentao MA | 270dc0f | 2022-08-23 13:17:26 +0800 | [diff] [blame] | 1803 | memset(&video_params, 0, sizeof(video_params)); |
| 1804 | memset(&audio_params, 0, sizeof(audio_params)); |
jiangfei.han | b8fbad4 | 2021-07-29 15:04:48 +0800 | [diff] [blame] | 1805 | |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 1806 | if (player == NULL) { |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 1807 | DVR_PB_INFO("player is NULL"); |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 1808 | return DVR_FAILURE; |
| 1809 | } |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame] | 1810 | uint64_t segment_id = player->cur_segment_id; |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 1811 | DVR_PB_INFO("[%p]segment_id:[%lld]", handle, segment_id); |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 1812 | |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 1813 | player->first_frame = 0; |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame] | 1814 | //can used start api to resume playback |
| 1815 | if (player->cmd.state == DVR_PLAYBACK_STATE_PAUSE) { |
| 1816 | return dvr_playback_resume(handle); |
| 1817 | } |
hualing chen | 87072a8 | 2020-03-12 16:20:12 +0800 | [diff] [blame] | 1818 | if (player->cmd.state == DVR_PLAYBACK_STATE_START) { |
Wentao MA | 270dc0f | 2022-08-23 13:17:26 +0800 | [diff] [blame] | 1819 | //if flag is paused and not decode first frame. if user resume, we need |
hualing chen | 9b434f0 | 2020-06-10 15:06:54 +0800 | [diff] [blame] | 1820 | //clear flag and set trickmode none |
| 1821 | if ((player->play_flag&DVR_PLAYBACK_STARTED_PAUSEDLIVE) == DVR_PLAYBACK_STARTED_PAUSEDLIVE) { |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 1822 | DVR_PB_INFO("[%p]clear pause live flag and clear trick mode", handle); |
hualing chen | 9b434f0 | 2020-06-10 15:06:54 +0800 | [diff] [blame] | 1823 | player->play_flag = player->play_flag & (~DVR_PLAYBACK_STARTED_PAUSEDLIVE); |
| 1824 | AmTsPlayer_setTrickMode(player->handle, AV_VIDEO_TRICK_MODE_NONE); |
| 1825 | } |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 1826 | DVR_PB_INFO("stat is start, not need into start play"); |
hualing chen | 87072a8 | 2020-03-12 16:20:12 +0800 | [diff] [blame] | 1827 | return DVR_SUCCESS; |
| 1828 | } |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1829 | player->play_flag = flag; |
hualing chen | e41f437 | 2020-06-06 16:29:17 +0800 | [diff] [blame] | 1830 | player->first_trans_ok = DVR_FALSE; |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 1831 | //get segment info and audio video pid fmt ; |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 1832 | DVR_PB_INFO("lock flag:0x%x", flag); |
Zhiqiang Han | f9c0e27 | 2022-06-14 13:54:03 +0800 | [diff] [blame] | 1833 | dvr_mutex_lock(&player->lock); |
Wentao MA | 270dc0f | 2022-08-23 13:17:26 +0800 | [diff] [blame] | 1834 | _dvr_playback_get_playinfo(handle, segment_id, &video_params, &audio_params, &ad_params); |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1835 | //start audio and video |
Wentao MA | 270dc0f | 2022-08-23 13:17:26 +0800 | [diff] [blame] | 1836 | if (video_params.pid != player->fake_pid && !VALID_PID(video_params.pid) && !VALID_PID(audio_params.pid)) { |
| 1837 | //audio and video pids are all invalid, return error. |
| 1838 | DVR_PB_ERROR("unlock dvr play back start error, not found audio and video info [0x%x]", video_params.pid); |
Zhiqiang Han | f9c0e27 | 2022-06-14 13:54:03 +0800 | [diff] [blame] | 1839 | dvr_mutex_unlock(&player->lock); |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame] | 1840 | DVR_Play_Notify_t notify; |
| 1841 | memset(¬ify, 0 , sizeof(DVR_Play_Notify_t)); |
| 1842 | notify.event = DVR_PLAYBACK_EVENT_TRANSITION_FAILED; |
| 1843 | notify.info.error_reason = DVR_PLAYBACK_PID_ERROR; |
| 1844 | notify.info.transition_failed_data.segment_id = segment_id; |
| 1845 | //get play statue not here |
hualing chen | 2932d37 | 2020-04-29 13:44:00 +0800 | [diff] [blame] | 1846 | _dvr_playback_sent_event(handle, DVR_PLAYBACK_EVENT_TRANSITION_FAILED, ¬ify, DVR_TRUE); |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1847 | return -1; |
| 1848 | } |
hualing chen | 3114087 | 2020-03-25 12:29:26 +0800 | [diff] [blame] | 1849 | |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame] | 1850 | { |
Wentao MA | 270dc0f | 2022-08-23 13:17:26 +0800 | [diff] [blame] | 1851 | if (VALID_PID(video_params.pid)) { |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1852 | player->has_video = DVR_TRUE; |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1853 | //if set flag is pause live, we need set trick mode |
hualing chen | 3114087 | 2020-03-25 12:29:26 +0800 | [diff] [blame] | 1854 | if ((player->play_flag&DVR_PLAYBACK_STARTED_PAUSEDLIVE) == DVR_PLAYBACK_STARTED_PAUSEDLIVE) { |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 1855 | DVR_PB_INFO("set trick mode -pauselive flag--"); |
hualing chen | 3114087 | 2020-03-25 12:29:26 +0800 | [diff] [blame] | 1856 | AmTsPlayer_setTrickMode(player->handle, AV_VIDEO_TRICK_MODE_PAUSE_NEXT); |
| 1857 | } else if (player->cmd.cur_cmd == DVR_PLAYBACK_CMD_FB |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 1858 | || player->cmd.cur_cmd == DVR_PLAYBACK_CMD_FF) { |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 1859 | DVR_PB_INFO("set trick mode -fffb--at pause live"); |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 1860 | AmTsPlayer_setTrickMode(player->handle, AV_VIDEO_TRICK_MODE_PAUSE_NEXT); |
hualing chen | 87072a8 | 2020-03-12 16:20:12 +0800 | [diff] [blame] | 1861 | } else { |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 1862 | DVR_PB_INFO("set trick mode ---none"); |
hualing chen | 87072a8 | 2020-03-12 16:20:12 +0800 | [diff] [blame] | 1863 | AmTsPlayer_setTrickMode(player->handle, AV_VIDEO_TRICK_MODE_NONE); |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 1864 | } |
hualing chen | a93bbbc | 2020-12-22 17:23:42 +0800 | [diff] [blame] | 1865 | AmTsPlayer_showVideo(player->handle); |
Wentao MA | 270dc0f | 2022-08-23 13:17:26 +0800 | [diff] [blame] | 1866 | AmTsPlayer_setVideoParams(player->handle, &video_params); |
hualing chen | 21a4037 | 2021-10-29 11:07:26 +0800 | [diff] [blame] | 1867 | AmTsPlayer_setVideoBlackOut(player->handle, 1); |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 1868 | AmTsPlayer_startVideoDecoding(player->handle); |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 1869 | } |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 1870 | |
Wentao MA | 270dc0f | 2022-08-23 13:17:26 +0800 | [diff] [blame] | 1871 | DVR_PB_INFO("player->cmd.cur_cmd:%d vpid[0x%x]apis[0x%x]", player->cmd.cur_cmd, video_params.pid, audio_params.pid); |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 1872 | player->last_send_time_id = UINT64_MAX; |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame] | 1873 | if (player->cmd.cur_cmd == DVR_PLAYBACK_CMD_FB |
| 1874 | || player->cmd.cur_cmd == DVR_PLAYBACK_CMD_FF) { |
| 1875 | player->cmd.state = DVR_PLAYBACK_STATE_START; |
Wentao MA | 907b643 | 2022-08-01 06:23:08 +0000 | [diff] [blame] | 1876 | DVR_PLAYER_CHANGE_STATE(player,DVR_PLAYBACK_STATE_START); |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame] | 1877 | } else { |
| 1878 | player->cmd.last_cmd = player->cmd.cur_cmd; |
| 1879 | player->cmd.cur_cmd = DVR_PLAYBACK_CMD_START; |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 1880 | if (IS_FAST_SPEED(player->cmd.speed.speed.speed)) { |
hualing chen | 3114087 | 2020-03-25 12:29:26 +0800 | [diff] [blame] | 1881 | //set fast play |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 1882 | DVR_PB_INFO("start fast"); |
hualing chen | 3114087 | 2020-03-25 12:29:26 +0800 | [diff] [blame] | 1883 | AmTsPlayer_startFast(player->handle, (float)player->cmd.speed.speed.speed/100.0f); |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 1884 | } else { |
Wentao MA | 270dc0f | 2022-08-23 13:17:26 +0800 | [diff] [blame] | 1885 | if (VALID_PID(ad_params.pid)) { |
hualing chen | df118dd | 2020-05-21 15:49:11 +0800 | [diff] [blame] | 1886 | player->has_ad_audio = DVR_TRUE; |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 1887 | DVR_PB_INFO("start ad audio"); |
Wentao MA | 270dc0f | 2022-08-23 13:17:26 +0800 | [diff] [blame] | 1888 | dvr_playback_change_seek_state(handle, ad_params.pid); |
| 1889 | AmTsPlayer_setADParams(player->handle, &ad_params); |
hualing chen | df118dd | 2020-05-21 15:49:11 +0800 | [diff] [blame] | 1890 | AmTsPlayer_enableADMix(player->handle); |
| 1891 | } |
Wentao MA | 270dc0f | 2022-08-23 13:17:26 +0800 | [diff] [blame] | 1892 | if (VALID_PID(audio_params.pid)) { |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 1893 | DVR_PB_INFO("start audio"); |
hualing chen | 969fe7b | 2021-05-26 15:13:17 +0800 | [diff] [blame] | 1894 | player->has_audio = DVR_TRUE; |
Wentao MA | 270dc0f | 2022-08-23 13:17:26 +0800 | [diff] [blame] | 1895 | dvr_playback_change_seek_state(handle, audio_params.pid); |
| 1896 | AmTsPlayer_setAudioParams(player->handle, &audio_params); |
Wentao MA | 5629ad8 | 2022-08-24 10:03:02 +0800 | [diff] [blame] | 1897 | if (player->audio_presentation_id > -1) { |
| 1898 | AmTsPlayer_setParams(player->handle, AM_TSPLAYER_KEY_AUDIO_PRESENTATION_ID, &player->audio_presentation_id); |
| 1899 | } |
hualing chen | 969fe7b | 2021-05-26 15:13:17 +0800 | [diff] [blame] | 1900 | AmTsPlayer_startAudioDecoding(player->handle); |
| 1901 | } |
hualing chen | 3114087 | 2020-03-25 12:29:26 +0800 | [diff] [blame] | 1902 | } |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame] | 1903 | player->cmd.state = DVR_PLAYBACK_STATE_START; |
Wentao MA | 907b643 | 2022-08-01 06:23:08 +0000 | [diff] [blame] | 1904 | DVR_PLAYER_CHANGE_STATE(player,DVR_PLAYBACK_STATE_START); |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame] | 1905 | } |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1906 | } |
hualing chen | 43a89bc | 2022-01-19 14:31:20 +0800 | [diff] [blame] | 1907 | #ifdef AVSYNC_USED_PCR |
| 1908 | if (player && VALID_PID(player->cur_segment.pids.pcr.pid)) { |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 1909 | DVR_PB_INFO("start set pcr [%d]", player->cur_segment.pids.pcr.pid); |
hualing chen | 43a89bc | 2022-01-19 14:31:20 +0800 | [diff] [blame] | 1910 | AmTsPlayer_setPcrPid(player->handle, player->cur_segment.pids.pcr.pid); |
| 1911 | } |
| 1912 | #endif |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 1913 | DVR_PB_DEBUG("unlock"); |
Zhiqiang Han | f9c0e27 | 2022-06-14 13:54:03 +0800 | [diff] [blame] | 1914 | dvr_mutex_unlock(&player->lock); |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 1915 | _start_playback_thread(handle); |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1916 | return DVR_SUCCESS; |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 1917 | } |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 1918 | /**\brief dvr play back add segment info to segment list |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 1919 | * \param[in] handle playback handle |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 1920 | * \param[in] info added segment info,con vpid fmt apid fmt..... |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 1921 | * \retval DVR_SUCCESS On success |
| 1922 | * \return Error code |
| 1923 | */ |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 1924 | int dvr_playback_add_segment(DVR_PlaybackHandle_t handle, DVR_PlaybackSegmentInfo_t *info) { |
| 1925 | DVR_Playback_t *player = (DVR_Playback_t *) handle; |
wentao.ma | a22bc85 | 2022-10-13 12:18:06 +0800 | [diff] [blame] | 1926 | DVR_RETURN_IF_FALSE(player); |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 1927 | |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 1928 | DVR_PB_INFO("add segment id: %lld %p", info->segment_id, handle); |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 1929 | DVR_PlaybackSegmentInfo_t *segment; |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 1930 | |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 1931 | segment = malloc(sizeof(DVR_PlaybackSegmentInfo_t)); |
wentao.ma | a22bc85 | 2022-10-13 12:18:06 +0800 | [diff] [blame] | 1932 | DVR_RETURN_IF_FALSE(segment); |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 1933 | memset(segment, 0, sizeof(DVR_PlaybackSegmentInfo_t)); |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 1934 | |
Wentao MA | 270dc0f | 2022-08-23 13:17:26 +0800 | [diff] [blame] | 1935 | //not memcpy chunk info. |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 1936 | segment->segment_id = info->segment_id; |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1937 | //cp location |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 1938 | memcpy(segment->location, info->location, DVR_MAX_LOCATION_SIZE); |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame] | 1939 | |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 1940 | DVR_PB_INFO("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] | 1941 | segment->flags = info->flags; |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 1942 | |
| 1943 | //pids |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame] | 1944 | segment->pids.video.pid = info->pids.video.pid; |
| 1945 | segment->pids.video.format = info->pids.video.format; |
| 1946 | segment->pids.video.type = info->pids.video.type; |
| 1947 | |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 1948 | segment->pids.audio.pid = info->pids.audio.pid; |
| 1949 | segment->pids.audio.format = info->pids.audio.format; |
| 1950 | segment->pids.audio.type = info->pids.audio.type; |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame] | 1951 | |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 1952 | segment->pids.ad.pid = info->pids.ad.pid; |
| 1953 | segment->pids.ad.format = info->pids.ad.format; |
| 1954 | segment->pids.ad.type = info->pids.ad.type; |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame] | 1955 | |
| 1956 | segment->pids.pcr.pid = info->pids.pcr.pid; |
| 1957 | |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 1958 | DVR_PB_INFO("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); |
Zhiqiang Han | f9c0e27 | 2022-06-14 13:54:03 +0800 | [diff] [blame] | 1959 | dvr_mutex_lock(&player->lock); |
wentao.ma | a22bc85 | 2022-10-13 12:18:06 +0800 | [diff] [blame] | 1960 | list_add_tail(segment, &player->segment_list); |
Zhiqiang Han | f9c0e27 | 2022-06-14 13:54:03 +0800 | [diff] [blame] | 1961 | dvr_mutex_unlock(&player->lock); |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 1962 | DVR_PB_DEBUG("unlock"); |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 1963 | |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 1964 | return DVR_SUCCESS; |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 1965 | } |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 1966 | /**\brief dvr play back remove segment info by segment_id |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 1967 | * \param[in] handle playback handle |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 1968 | * \param[in] segment_id need removed segment id |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 1969 | * \retval DVR_SUCCESS On success |
| 1970 | * \return Error code |
| 1971 | */ |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 1972 | 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] | 1973 | DVR_Playback_t *player = (DVR_Playback_t *) handle; |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 1974 | DVR_PB_INFO("remove segment id: %lld", segment_id); |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 1975 | if (player == NULL) { |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 1976 | DVR_PB_INFO("player is NULL"); |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 1977 | return DVR_FAILURE; |
| 1978 | } |
| 1979 | |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame] | 1980 | if (segment_id == player->cur_segment_id) { |
Wentao MA | 9a16400 | 2022-08-29 11:20:24 +0800 | [diff] [blame] | 1981 | DVR_PB_INFO("not support remove current segment id: %lld", segment_id); |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame] | 1982 | return DVR_FAILURE; |
| 1983 | } |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 1984 | DVR_PB_DEBUG("lock"); |
Zhiqiang Han | f9c0e27 | 2022-06-14 13:54:03 +0800 | [diff] [blame] | 1985 | dvr_mutex_lock(&player->lock); |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 1986 | DVR_PlaybackSegmentInfo_t *segment = NULL; |
| 1987 | DVR_PlaybackSegmentInfo_t *segment_tmp = NULL; |
| 1988 | list_for_each_entry_safe(segment, segment_tmp, &player->segment_list, head) |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1989 | { |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 1990 | if (segment->segment_id == segment_id) { |
| 1991 | list_del(&segment->head); |
| 1992 | free(segment); |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1993 | break; |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 1994 | } |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1995 | } |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 1996 | DVR_PB_DEBUG("unlock"); |
Zhiqiang Han | f9c0e27 | 2022-06-14 13:54:03 +0800 | [diff] [blame] | 1997 | dvr_mutex_unlock(&player->lock); |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1998 | |
| 1999 | return DVR_SUCCESS; |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 2000 | } |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 2001 | /**\brief dvr play back add segment info |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 2002 | * \param[in] handle playback handle |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 2003 | * \param[in] info added segment info,con vpid fmt apid fmt..... |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 2004 | * \retval DVR_SUCCESS On success |
| 2005 | * \return Error code |
| 2006 | */ |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 2007 | int dvr_playback_update_segment_flags(DVR_PlaybackHandle_t handle, |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 2008 | uint64_t segment_id, DVR_PlaybackSegmentFlag_t flags) { |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 2009 | DVR_Playback_t *player = (DVR_Playback_t *) handle; |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 2010 | DVR_PB_INFO("update segment id: %lld flag:%d", segment_id, flags); |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 2011 | if (player == NULL) { |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 2012 | DVR_PB_INFO("player is NULL"); |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 2013 | return DVR_FAILURE; |
| 2014 | } |
Wentao MA | 292380e | 2022-12-14 14:46:19 +0800 | [diff] [blame] | 2015 | if (player->vendor != DVR_PLAYBACK_VENDOR_DEF) { |
| 2016 | DVR_PB_INFO("In case of vendor Amlogic/Amazon, do not control AV display"); |
hualing chen | f43b8ba | 2020-07-28 13:11:42 +0800 | [diff] [blame] | 2017 | return DVR_SUCCESS; |
| 2018 | } |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 2019 | |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 2020 | DVR_PlaybackSegmentInfo_t *segment; |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 2021 | DVR_PB_DEBUG("lock"); |
Zhiqiang Han | f9c0e27 | 2022-06-14 13:54:03 +0800 | [diff] [blame] | 2022 | dvr_mutex_lock(&player->lock); |
wentao.ma | fd5283f | 2022-10-14 09:51:13 +0800 | [diff] [blame] | 2023 | // This error is suppressed as the macro code is picked from kernel. |
wentao.ma | a22bc85 | 2022-10-13 12:18:06 +0800 | [diff] [blame] | 2024 | // prefetch() here incurring self_assign is used to avoid some compiling |
| 2025 | // warnings. |
| 2026 | // coverity[self_assign] |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 2027 | list_for_each_entry(segment, &player->segment_list, head) |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 2028 | { |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 2029 | if (segment->segment_id != segment_id) { |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 2030 | continue; |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 2031 | } |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 2032 | // if encramble to free, only set flag and return; |
| 2033 | |
| 2034 | //if displayable to none, we need mute audio and video |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 2035 | if (segment_id == player->cur_segment_id) { |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 2036 | if ((segment->flags & DVR_PLAYBACK_SEGMENT_DISPLAYABLE) == DVR_PLAYBACK_SEGMENT_DISPLAYABLE |
| 2037 | && (flags & DVR_PLAYBACK_SEGMENT_DISPLAYABLE) == 0) { |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame] | 2038 | //disable display, mute |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 2039 | DVR_PB_INFO("mute av"); |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 2040 | AmTsPlayer_hideVideo(player->handle); |
| 2041 | AmTsPlayer_setAudioMute(player->handle, 1, 1); |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 2042 | } else if ((segment->flags & DVR_PLAYBACK_SEGMENT_DISPLAYABLE) == 0 && |
| 2043 | (flags & DVR_PLAYBACK_SEGMENT_DISPLAYABLE) == DVR_PLAYBACK_SEGMENT_DISPLAYABLE) { |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame] | 2044 | //enable display, unmute |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 2045 | DVR_PB_INFO("unmute av"); |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 2046 | AmTsPlayer_showVideo(player->handle); |
| 2047 | AmTsPlayer_setAudioMute(player->handle, 0, 0); |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 2048 | } else { |
| 2049 | //do nothing |
| 2050 | } |
| 2051 | } else { |
| 2052 | //do nothing |
| 2053 | } |
| 2054 | //continue , only set flag |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 2055 | segment->flags = flags; |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 2056 | } |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 2057 | DVR_PB_DEBUG("unlock"); |
Zhiqiang Han | f9c0e27 | 2022-06-14 13:54:03 +0800 | [diff] [blame] | 2058 | dvr_mutex_unlock(&player->lock); |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 2059 | return DVR_SUCCESS; |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 2060 | } |
| 2061 | |
| 2062 | |
Wentao MA | 6dcdc34 | 2023-01-30 17:03:19 +0800 | [diff] [blame] | 2063 | static int _do_handle_pid_update(DVR_PlaybackHandle_t handle, DVR_PlaybackPids_t now_pids, DVR_PlaybackPids_t set_pids, int type) { |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 2064 | DVR_Playback_t *player = (DVR_Playback_t *) handle; |
hualing chen | 275379e | 2021-06-15 17:57:21 +0800 | [diff] [blame] | 2065 | DVR_StreamInfo_t set_pid; |
hualing chen | 9950864 | 2021-10-18 15:41:17 +0800 | [diff] [blame] | 2066 | DVR_StreamInfo_t now_pid; |
hualing chen | 275379e | 2021-06-15 17:57:21 +0800 | [diff] [blame] | 2067 | |
Wentao MA | 6dcdc34 | 2023-01-30 17:03:19 +0800 | [diff] [blame] | 2068 | if (player == NULL) { |
| 2069 | DVR_PB_INFO("player is NULL"); |
| 2070 | return DVR_FAILURE; |
| 2071 | } |
| 2072 | |
hualing chen | 275379e | 2021-06-15 17:57:21 +0800 | [diff] [blame] | 2073 | if (type == 0) { |
| 2074 | set_pid = set_pids.video; |
hualing chen | 9950864 | 2021-10-18 15:41:17 +0800 | [diff] [blame] | 2075 | now_pid = now_pids.video; |
hualing chen | 275379e | 2021-06-15 17:57:21 +0800 | [diff] [blame] | 2076 | } else if (type == 1) { |
| 2077 | set_pid = set_pids.audio; |
hualing chen | 9950864 | 2021-10-18 15:41:17 +0800 | [diff] [blame] | 2078 | now_pid = now_pids.audio; |
hualing chen | 275379e | 2021-06-15 17:57:21 +0800 | [diff] [blame] | 2079 | } else if (type == 2) { |
| 2080 | set_pid = set_pids.ad; |
hualing chen | 9950864 | 2021-10-18 15:41:17 +0800 | [diff] [blame] | 2081 | now_pid = now_pids.ad; |
hualing chen | 275379e | 2021-06-15 17:57:21 +0800 | [diff] [blame] | 2082 | } else { |
| 2083 | set_pid = set_pids.pcr; |
hualing chen | 9950864 | 2021-10-18 15:41:17 +0800 | [diff] [blame] | 2084 | now_pid = now_pids.pcr; |
hualing chen | 275379e | 2021-06-15 17:57:21 +0800 | [diff] [blame] | 2085 | } |
| 2086 | |
Wentao MA | 6dcdc34 | 2023-01-30 17:03:19 +0800 | [diff] [blame] | 2087 | if (type == 1 && VALID_PID(set_pid.pid) && player->cmd.state == DVR_PLAYBACK_STATE_START |
| 2088 | && player->play_flag&DVR_PLAYBACK_STARTED_PAUSEDLIVE) { |
| 2089 | // Here we mute audio no matter it is displayable or not in starting phase of a playback. |
| 2090 | // Audio will be unmuted shortly on receiving first frame event. |
| 2091 | AmTsPlayer_setAudioMute(player->handle,1,1); |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 2092 | } |
Wentao MA | 6dcdc34 | 2023-01-30 17:03:19 +0800 | [diff] [blame] | 2093 | |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 2094 | if (now_pid.pid == set_pid.pid) { |
| 2095 | //do nothing |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 2096 | return 0; |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 2097 | } else if (player->cmd.state == DVR_PLAYBACK_STATE_START) { |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 2098 | if (VALID_PID(now_pid.pid)) { |
| 2099 | //stop now stream |
| 2100 | if (type == 0) { |
Wentao MA | 270dc0f | 2022-08-23 13:17:26 +0800 | [diff] [blame] | 2101 | //stop video |
hualing chen | c70a8df | 2020-05-12 19:23:11 +0800 | [diff] [blame] | 2102 | if (player->has_video == DVR_TRUE) { |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 2103 | DVR_PB_INFO("stop video"); |
hualing chen | c70a8df | 2020-05-12 19:23:11 +0800 | [diff] [blame] | 2104 | AmTsPlayer_stopVideoDecoding(player->handle); |
| 2105 | player->has_video = DVR_FALSE; |
| 2106 | } |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 2107 | } else if (type == 1) { |
| 2108 | //stop audio |
hualing chen | c70a8df | 2020-05-12 19:23:11 +0800 | [diff] [blame] | 2109 | if (player->has_audio == DVR_TRUE) { |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 2110 | DVR_PB_INFO("stop audio"); |
hualing chen | c70a8df | 2020-05-12 19:23:11 +0800 | [diff] [blame] | 2111 | AmTsPlayer_stopAudioDecoding(player->handle); |
| 2112 | player->has_audio = DVR_FALSE; |
| 2113 | } |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 2114 | } else if (type == 2) { |
| 2115 | //stop sub audio |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 2116 | DVR_PB_INFO("stop ad"); |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 2117 | AmTsPlayer_disableADMix(player->handle); |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 2118 | } else if (type == 3) { |
| 2119 | //pcr |
| 2120 | } |
| 2121 | } |
| 2122 | if (VALID_PID(set_pid.pid)) { |
| 2123 | //start |
| 2124 | if (type == 0) { |
Wentao MA | 270dc0f | 2022-08-23 13:17:26 +0800 | [diff] [blame] | 2125 | //start video |
| 2126 | am_tsplayer_video_params video_params; |
| 2127 | video_params.pid = set_pid.pid; |
| 2128 | video_params.codectype = _dvr_convert_stream_fmt(set_pid.format, DVR_FALSE); |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 2129 | player->has_video = DVR_TRUE; |
Wentao MA | 270dc0f | 2022-08-23 13:17:26 +0800 | [diff] [blame] | 2130 | DVR_PB_INFO("start video pid[%d]fmt[%d]",video_params.pid, video_params.codectype); |
| 2131 | AmTsPlayer_setVideoParams(player->handle, &video_params); |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 2132 | AmTsPlayer_startVideoDecoding(player->handle); |
Wentao MA | 270dc0f | 2022-08-23 13:17:26 +0800 | [diff] [blame] | 2133 | //playback_device_video_start(player->handle,&video_params); |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 2134 | } else if (type == 1) { |
| 2135 | //start audio |
Gong Ke | 2a0ebbe | 2021-05-25 15:22:50 +0800 | [diff] [blame] | 2136 | if (player->cmd.speed.speed.speed == PLAYBACK_SPEED_X1) { |
hualing chen | 275379e | 2021-06-15 17:57:21 +0800 | [diff] [blame] | 2137 | if (VALID_PID(set_pids.ad.pid)) { |
Wentao MA | 270dc0f | 2022-08-23 13:17:26 +0800 | [diff] [blame] | 2138 | am_tsplayer_audio_params ad_params; |
| 2139 | ad_params.pid = set_pids.ad.pid; |
| 2140 | ad_params.codectype= _dvr_convert_stream_fmt(set_pids.ad.format, DVR_TRUE); |
| 2141 | DVR_PB_INFO("start ad audio pid[%d]fmt[%d]",ad_params.pid, ad_params.codectype); |
| 2142 | AmTsPlayer_setADParams(player->handle, &ad_params); |
hualing chen | 275379e | 2021-06-15 17:57:21 +0800 | [diff] [blame] | 2143 | AmTsPlayer_enableADMix(player->handle); |
| 2144 | } |
| 2145 | |
Wentao MA | 270dc0f | 2022-08-23 13:17:26 +0800 | [diff] [blame] | 2146 | am_tsplayer_audio_params audio_params; |
jiangfei.han | b8fbad4 | 2021-07-29 15:04:48 +0800 | [diff] [blame] | 2147 | |
Wentao MA | 270dc0f | 2022-08-23 13:17:26 +0800 | [diff] [blame] | 2148 | memset(&audio_params, 0, sizeof(audio_params)); |
jiangfei.han | b8fbad4 | 2021-07-29 15:04:48 +0800 | [diff] [blame] | 2149 | |
Wentao MA | 270dc0f | 2022-08-23 13:17:26 +0800 | [diff] [blame] | 2150 | audio_params.pid = set_pid.pid; |
| 2151 | audio_params.codectype= _dvr_convert_stream_fmt(set_pid.format, DVR_TRUE); |
hualing chen | c70a8df | 2020-05-12 19:23:11 +0800 | [diff] [blame] | 2152 | player->has_audio = DVR_TRUE; |
Wentao MA | 270dc0f | 2022-08-23 13:17:26 +0800 | [diff] [blame] | 2153 | DVR_PB_INFO("start audio pid[%d]fmt[%d]",audio_params.pid, audio_params.codectype); |
| 2154 | AmTsPlayer_setAudioParams(player->handle, &audio_params); |
Wentao MA | 5629ad8 | 2022-08-24 10:03:02 +0800 | [diff] [blame] | 2155 | if (player->audio_presentation_id > -1) { |
| 2156 | AmTsPlayer_setParams(player->handle, AM_TSPLAYER_KEY_AUDIO_PRESENTATION_ID, &player->audio_presentation_id); |
| 2157 | } |
Wentao MA | 6dcdc34 | 2023-01-30 17:03:19 +0800 | [diff] [blame] | 2158 | |
hualing chen | c70a8df | 2020-05-12 19:23:11 +0800 | [diff] [blame] | 2159 | AmTsPlayer_startAudioDecoding(player->handle); |
Wentao MA | 270dc0f | 2022-08-23 13:17:26 +0800 | [diff] [blame] | 2160 | //playback_device_audio_start(player->handle,&audio_params); |
hualing chen | c70a8df | 2020-05-12 19:23:11 +0800 | [diff] [blame] | 2161 | } |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 2162 | } else if (type == 2) { |
Gong Ke | 2a0ebbe | 2021-05-25 15:22:50 +0800 | [diff] [blame] | 2163 | if (player->cmd.speed.speed.speed == PLAYBACK_SPEED_X1) { |
hualing chen | 9950864 | 2021-10-18 15:41:17 +0800 | [diff] [blame] | 2164 | if (set_pids.audio.pid == now_pids.audio.pid) { |
| 2165 | //stop audio if audio pid not change |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 2166 | DVR_PB_INFO("stop audio when start ad"); |
hualing chen | 9950864 | 2021-10-18 15:41:17 +0800 | [diff] [blame] | 2167 | AmTsPlayer_stopAudioDecoding(player->handle); |
| 2168 | } |
Wentao MA | 270dc0f | 2022-08-23 13:17:26 +0800 | [diff] [blame] | 2169 | am_tsplayer_audio_params audio_params; |
jiangfei.han | b8fbad4 | 2021-07-29 15:04:48 +0800 | [diff] [blame] | 2170 | |
Wentao MA | 270dc0f | 2022-08-23 13:17:26 +0800 | [diff] [blame] | 2171 | memset(&audio_params, 0, sizeof(audio_params)); |
| 2172 | audio_params.pid = set_pid.pid; |
| 2173 | audio_params.codectype= _dvr_convert_stream_fmt(set_pid.format, DVR_TRUE); |
hualing chen | c70a8df | 2020-05-12 19:23:11 +0800 | [diff] [blame] | 2174 | player->has_audio = DVR_TRUE; |
Wentao MA | 270dc0f | 2022-08-23 13:17:26 +0800 | [diff] [blame] | 2175 | DVR_PB_INFO("start ad audio pid[%d]fmt[%d]",audio_params.pid, audio_params.codectype); |
| 2176 | AmTsPlayer_setADParams(player->handle, &audio_params); |
hualing chen | c70a8df | 2020-05-12 19:23:11 +0800 | [diff] [blame] | 2177 | AmTsPlayer_enableADMix(player->handle); |
hualing chen | 9950864 | 2021-10-18 15:41:17 +0800 | [diff] [blame] | 2178 | |
| 2179 | if (set_pids.audio.pid == now_pids.audio.pid) { |
Wentao MA | 270dc0f | 2022-08-23 13:17:26 +0800 | [diff] [blame] | 2180 | am_tsplayer_audio_params audio_params; |
hualing chen | 9950864 | 2021-10-18 15:41:17 +0800 | [diff] [blame] | 2181 | |
Wentao MA | 270dc0f | 2022-08-23 13:17:26 +0800 | [diff] [blame] | 2182 | memset(&audio_params, 0, sizeof(audio_params)); |
hualing chen | 9950864 | 2021-10-18 15:41:17 +0800 | [diff] [blame] | 2183 | |
Wentao MA | 270dc0f | 2022-08-23 13:17:26 +0800 | [diff] [blame] | 2184 | audio_params.pid = set_pids.audio.pid; |
| 2185 | audio_params.codectype= _dvr_convert_stream_fmt(set_pids.audio.format, DVR_TRUE); |
hualing chen | 9950864 | 2021-10-18 15:41:17 +0800 | [diff] [blame] | 2186 | player->has_audio = DVR_TRUE; |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 2187 | DVR_PB_INFO("restart audio when start ad"); |
Wentao MA | 270dc0f | 2022-08-23 13:17:26 +0800 | [diff] [blame] | 2188 | AmTsPlayer_setAudioParams(player->handle, &audio_params); |
Wentao MA | 5629ad8 | 2022-08-24 10:03:02 +0800 | [diff] [blame] | 2189 | if (player->audio_presentation_id > -1) { |
| 2190 | AmTsPlayer_setParams(player->handle, AM_TSPLAYER_KEY_AUDIO_PRESENTATION_ID, &player->audio_presentation_id); |
| 2191 | } |
hualing chen | 9950864 | 2021-10-18 15:41:17 +0800 | [diff] [blame] | 2192 | AmTsPlayer_startAudioDecoding(player->handle); |
| 2193 | } |
hualing chen | c70a8df | 2020-05-12 19:23:11 +0800 | [diff] [blame] | 2194 | } |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 2195 | } else if (type == 3) { |
| 2196 | //pcr |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 2197 | DVR_PB_INFO("start set pcr [%d]", set_pid.pid); |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 2198 | AmTsPlayer_setPcrPid(player->handle, set_pid.pid); |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 2199 | } |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 2200 | //audio and video all close |
| 2201 | if (!player->has_audio && !player->has_video) { |
Wentao MA | 907b643 | 2022-08-01 06:23:08 +0000 | [diff] [blame] | 2202 | DVR_PLAYER_CHANGE_STATE(player,DVR_PLAYBACK_STATE_STOP); |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 2203 | } |
hualing chen | 43a89bc | 2022-01-19 14:31:20 +0800 | [diff] [blame] | 2204 | } else if (type == 2) { |
| 2205 | //case disable ad |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 2206 | DVR_PB_INFO("restart audio when stop ad"); |
hualing chen | 43a89bc | 2022-01-19 14:31:20 +0800 | [diff] [blame] | 2207 | if (player->cmd.speed.speed.speed == PLAYBACK_SPEED_X1) { |
Wentao MA | 6d045b3 | 2022-02-18 18:47:25 +0800 | [diff] [blame] | 2208 | if (VALID_PID(now_pids.audio.pid)) { |
| 2209 | //stop audio if audio pid not change |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 2210 | DVR_PB_INFO("stop audio when stop ad pid [0x%x]", now_pids.audio.pid); |
Wentao MA | 6d045b3 | 2022-02-18 18:47:25 +0800 | [diff] [blame] | 2211 | AmTsPlayer_stopAudioDecoding(player->handle); |
Wentao MA | 270dc0f | 2022-08-23 13:17:26 +0800 | [diff] [blame] | 2212 | am_tsplayer_audio_params audio_params; |
hualing chen | 43a89bc | 2022-01-19 14:31:20 +0800 | [diff] [blame] | 2213 | |
Wentao MA | 270dc0f | 2022-08-23 13:17:26 +0800 | [diff] [blame] | 2214 | memset(&audio_params, 0, sizeof(audio_params)); |
hualing chen | 43a89bc | 2022-01-19 14:31:20 +0800 | [diff] [blame] | 2215 | |
Wentao MA | 270dc0f | 2022-08-23 13:17:26 +0800 | [diff] [blame] | 2216 | audio_params.pid = now_pids.audio.pid; |
| 2217 | audio_params.codectype= _dvr_convert_stream_fmt(now_pids.audio.format, DVR_TRUE); |
Wentao MA | 6d045b3 | 2022-02-18 18:47:25 +0800 | [diff] [blame] | 2218 | player->has_audio = DVR_TRUE; |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 2219 | DVR_PB_INFO("restart audio when stop ad"); |
Wentao MA | 270dc0f | 2022-08-23 13:17:26 +0800 | [diff] [blame] | 2220 | AmTsPlayer_setAudioParams(player->handle, &audio_params); |
Wentao MA | 5629ad8 | 2022-08-24 10:03:02 +0800 | [diff] [blame] | 2221 | if (player->audio_presentation_id > -1) { |
| 2222 | AmTsPlayer_setParams(player->handle, AM_TSPLAYER_KEY_AUDIO_PRESENTATION_ID, &player->audio_presentation_id); |
| 2223 | } |
Wentao MA | 6d045b3 | 2022-02-18 18:47:25 +0800 | [diff] [blame] | 2224 | AmTsPlayer_startAudioDecoding(player->handle); |
hualing chen | 43a89bc | 2022-01-19 14:31:20 +0800 | [diff] [blame] | 2225 | } |
Wentao MA | 6d045b3 | 2022-02-18 18:47:25 +0800 | [diff] [blame] | 2226 | } |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 2227 | } |
| 2228 | } |
| 2229 | return 0; |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 2230 | } |
hualing chen | a5f0322 | 2021-12-02 11:22:35 +0800 | [diff] [blame] | 2231 | /**\brief dvr play back only update segment pids info |
| 2232 | * only update pid info not to start stop codec. |
| 2233 | * \param[in] handle playback handle |
| 2234 | * \param[in] segment_id need updated pids segment id |
| 2235 | * \param[in] p_pids need updated pids |
| 2236 | * \retval DVR_SUCCESS On success |
| 2237 | * \return Error code |
| 2238 | */ |
| 2239 | int dvr_playback_only_update_segment_pids(DVR_PlaybackHandle_t handle, uint64_t segment_id, DVR_PlaybackPids_t *p_pids) { |
| 2240 | DVR_Playback_t *player = (DVR_Playback_t *) handle; |
| 2241 | if (player == NULL) { |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 2242 | DVR_PB_INFO("player is NULL"); |
hualing chen | a5f0322 | 2021-12-02 11:22:35 +0800 | [diff] [blame] | 2243 | return DVR_FAILURE; |
| 2244 | } |
| 2245 | |
| 2246 | DVR_PlaybackSegmentInfo_t *segment; |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 2247 | DVR_PB_DEBUG("lock"); |
Zhiqiang Han | f9c0e27 | 2022-06-14 13:54:03 +0800 | [diff] [blame] | 2248 | dvr_mutex_lock(&player->lock); |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 2249 | DVR_PB_INFO("get lock update segment id: %lld cur id %lld", segment_id, player->cur_segment_id); |
wentao.ma | fd5283f | 2022-10-14 09:51:13 +0800 | [diff] [blame] | 2250 | // This error is suppressed as the macro code is picked from kernel. |
wentao.ma | a22bc85 | 2022-10-13 12:18:06 +0800 | [diff] [blame] | 2251 | // prefetch() here incurring self_assign is used to avoid some compiling |
| 2252 | // warnings. |
| 2253 | // coverity[self_assign] |
hualing chen | a5f0322 | 2021-12-02 11:22:35 +0800 | [diff] [blame] | 2254 | list_for_each_entry(segment, &player->segment_list, head) |
| 2255 | { |
| 2256 | if (segment->segment_id == segment_id) { |
| 2257 | if (player->cur_segment_id == segment_id) { |
| 2258 | if (player->cmd.state == DVR_PLAYBACK_STATE_FF |
Wentao MA | 16f870e | 2022-09-09 11:00:22 +0800 | [diff] [blame] | 2259 | || player->cmd.state == DVR_PLAYBACK_STATE_FB) { |
hualing chen | a5f0322 | 2021-12-02 11:22:35 +0800 | [diff] [blame] | 2260 | //do nothing when ff fb |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 2261 | DVR_PB_INFO("unlock now is ff fb, not to update cur segment info\r\n"); |
Zhiqiang Han | f9c0e27 | 2022-06-14 13:54:03 +0800 | [diff] [blame] | 2262 | dvr_mutex_unlock(&player->lock); |
hualing chen | a5f0322 | 2021-12-02 11:22:35 +0800 | [diff] [blame] | 2263 | return 0; |
| 2264 | } |
| 2265 | memcpy(&player->cur_segment.pids, p_pids, sizeof(DVR_PlaybackPids_t)); |
| 2266 | } |
| 2267 | //save pids info |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 2268 | DVR_PB_INFO(":apid :%d %d", segment->pids.audio.pid, p_pids->audio.pid); |
hualing chen | a5f0322 | 2021-12-02 11:22:35 +0800 | [diff] [blame] | 2269 | memcpy(&segment->pids, p_pids, sizeof(DVR_PlaybackPids_t)); |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 2270 | DVR_PB_INFO(":cp apid :%d %d", segment->pids.audio.pid, p_pids->audio.pid); |
hualing chen | a5f0322 | 2021-12-02 11:22:35 +0800 | [diff] [blame] | 2271 | break; |
| 2272 | } |
| 2273 | } |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 2274 | DVR_PB_DEBUG("unlock"); |
Zhiqiang Han | f9c0e27 | 2022-06-14 13:54:03 +0800 | [diff] [blame] | 2275 | dvr_mutex_unlock(&player->lock); |
hualing chen | a5f0322 | 2021-12-02 11:22:35 +0800 | [diff] [blame] | 2276 | return DVR_SUCCESS; |
| 2277 | } |
| 2278 | |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 2279 | /**\brief dvr play back update segment pids |
| 2280 | * if updated segment is ongoing segment, we need start new |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 2281 | * add pid stream and stop remove pid stream. |
| 2282 | * \param[in] handle playback handle |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 2283 | * \param[in] segment_id need updated pids segment id |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 2284 | * \retval DVR_SUCCESS On success |
| 2285 | * \return Error code |
| 2286 | */ |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 2287 | 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] | 2288 | DVR_Playback_t *player = (DVR_Playback_t *) handle; |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 2289 | if (player == NULL) { |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 2290 | DVR_PB_INFO("player is NULL"); |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 2291 | return DVR_FAILURE; |
| 2292 | } |
| 2293 | |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 2294 | DVR_PlaybackSegmentInfo_t *segment; |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 2295 | DVR_PB_DEBUG("lock"); |
Zhiqiang Han | f9c0e27 | 2022-06-14 13:54:03 +0800 | [diff] [blame] | 2296 | dvr_mutex_lock(&player->lock); |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 2297 | DVR_PB_INFO("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] | 2298 | |
wentao.ma | fd5283f | 2022-10-14 09:51:13 +0800 | [diff] [blame] | 2299 | // This error is suppressed as the macro code is picked from kernel. |
wentao.ma | a22bc85 | 2022-10-13 12:18:06 +0800 | [diff] [blame] | 2300 | // prefetch() here incurring self_assign is used to avoid some compiling |
| 2301 | // warnings. |
| 2302 | // coverity[self_assign] |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 2303 | list_for_each_entry(segment, &player->segment_list, head) |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 2304 | { |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 2305 | if (segment->segment_id == segment_id) { |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 2306 | |
| 2307 | if (player->cur_segment_id == segment_id) { |
| 2308 | if (player->cmd.state == DVR_PLAYBACK_STATE_FF |
Wentao MA | 16f870e | 2022-09-09 11:00:22 +0800 | [diff] [blame] | 2309 | || player->cmd.state == DVR_PLAYBACK_STATE_FB) { |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 2310 | //do nothing when ff fb |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 2311 | DVR_PB_INFO("unlock now is ff fb, not to update cur segment info\r\n"); |
Zhiqiang Han | f9c0e27 | 2022-06-14 13:54:03 +0800 | [diff] [blame] | 2312 | dvr_mutex_unlock(&player->lock); |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 2313 | return 0; |
| 2314 | } |
| 2315 | |
| 2316 | //if segment is on going segment,we need stop start stream |
| 2317 | if (player->cmd.state == DVR_PLAYBACK_STATE_START) { |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 2318 | DVR_PB_DEBUG("unlock ---\r\n"); |
Zhiqiang Han | f9c0e27 | 2022-06-14 13:54:03 +0800 | [diff] [blame] | 2319 | dvr_mutex_unlock(&player->lock); |
hualing chen | 8a657f3 | 2021-08-30 13:12:49 +0800 | [diff] [blame] | 2320 | if (segment->pids.audio.pid != p_pids->audio.pid && |
| 2321 | segment->pids.audio.pid == 0x1fff) { |
hualing chen | a5f0322 | 2021-12-02 11:22:35 +0800 | [diff] [blame] | 2322 | //not used this to seek to start pos.we will |
Wentao MA | 9a16400 | 2022-08-29 11:20:24 +0800 | [diff] [blame] | 2323 | //add update only api. if need seek to start |
hualing chen | a5f0322 | 2021-12-02 11:22:35 +0800 | [diff] [blame] | 2324 | //pos, we will call only update api and used seek api |
| 2325 | //to start and stop av codec |
| 2326 | if (0 && player->need_seek_start == DVR_TRUE) { |
hualing chen | 8a657f3 | 2021-08-30 13:12:49 +0800 | [diff] [blame] | 2327 | player->need_seek_start = DVR_FALSE; |
| 2328 | pthread_mutex_lock(&player->segment_lock); |
| 2329 | player->drop_ts = DVR_TRUE; |
| 2330 | player->ts_cache_len = 0; |
| 2331 | if (player->first_start_time > 0) |
| 2332 | player->first_start_time = player->first_start_time - 1; |
Wentao MA | f35c388 | 2023-04-17 12:36:19 +0800 | [diff] [blame] | 2333 | segment_seek(player->segment_handle, (uint64_t)(player->first_start_time), player->openParams.block_size); |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 2334 | DVR_PB_ERROR("unlock segment update need seek time_offset %llu [0x%x][0x%x]", player->first_start_time, segment->pids.audio.pid, segment->pids.ad.pid); |
hualing chen | 8a657f3 | 2021-08-30 13:12:49 +0800 | [diff] [blame] | 2335 | pthread_mutex_unlock(&player->segment_lock); |
| 2336 | } |
| 2337 | } |
hualing chen | 1679f81 | 2021-11-08 15:17:46 +0800 | [diff] [blame] | 2338 | //check video pids, stop or restart |
Wentao MA | 6dcdc34 | 2023-01-30 17:03:19 +0800 | [diff] [blame] | 2339 | _do_handle_pid_update((DVR_PlaybackHandle_t)player, segment->pids, *p_pids, 0); |
hualing chen | 1679f81 | 2021-11-08 15:17:46 +0800 | [diff] [blame] | 2340 | //check sub audio pids stop or restart |
Wentao MA | 6dcdc34 | 2023-01-30 17:03:19 +0800 | [diff] [blame] | 2341 | _do_handle_pid_update((DVR_PlaybackHandle_t)player, segment->pids, *p_pids, 2); |
hualing chen | 1679f81 | 2021-11-08 15:17:46 +0800 | [diff] [blame] | 2342 | //check audio pids stop or restart |
Wentao MA | 6dcdc34 | 2023-01-30 17:03:19 +0800 | [diff] [blame] | 2343 | _do_handle_pid_update((DVR_PlaybackHandle_t)player, segment->pids, *p_pids, 1); |
hualing chen | 1679f81 | 2021-11-08 15:17:46 +0800 | [diff] [blame] | 2344 | //check pcr pids stop or restart |
Wentao MA | 6dcdc34 | 2023-01-30 17:03:19 +0800 | [diff] [blame] | 2345 | _do_handle_pid_update((DVR_PlaybackHandle_t)player, segment->pids, *p_pids, 3); |
hualing chen | 1679f81 | 2021-11-08 15:17:46 +0800 | [diff] [blame] | 2346 | |
Zhiqiang Han | f9c0e27 | 2022-06-14 13:54:03 +0800 | [diff] [blame] | 2347 | dvr_mutex_lock(&player->lock); |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 2348 | } else if (player->cmd.state == DVR_PLAYBACK_STATE_PAUSE) { |
| 2349 | //if state is pause, we need process at resume api. we only record change info |
| 2350 | int v_cmd = DVR_PLAYBACK_CMD_NONE; |
| 2351 | int a_cmd = DVR_PLAYBACK_CMD_NONE; |
| 2352 | if (VALID_PID(segment->pids.video.pid) |
| 2353 | && VALID_PID(p_pids->video.pid) |
| 2354 | && segment->pids.video.pid != p_pids->video.pid) { |
| 2355 | //restart video |
Wentao MA | 270dc0f | 2022-08-23 13:17:26 +0800 | [diff] [blame] | 2356 | v_cmd = DVR_PLAYBACK_CMD_V_RESTART; |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 2357 | } |
| 2358 | if (!VALID_PID(segment->pids.video.pid) |
| 2359 | && VALID_PID(p_pids->video.pid) |
| 2360 | && segment->pids.video.pid != p_pids->video.pid) { |
| 2361 | //start video |
Wentao MA | 270dc0f | 2022-08-23 13:17:26 +0800 | [diff] [blame] | 2362 | v_cmd = DVR_PLAYBACK_CMD_V_START; |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 2363 | } |
| 2364 | if (VALID_PID(segment->pids.video.pid) |
| 2365 | && !VALID_PID(p_pids->video.pid) |
| 2366 | && segment->pids.video.pid != p_pids->video.pid) { |
| 2367 | //stop video |
Wentao MA | 270dc0f | 2022-08-23 13:17:26 +0800 | [diff] [blame] | 2368 | v_cmd = DVR_PLAYBACK_CMD_V_STOP; |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 2369 | } |
| 2370 | if (VALID_PID(segment->pids.audio.pid) |
| 2371 | && VALID_PID(p_pids->audio.pid) |
| 2372 | && segment->pids.audio.pid != p_pids->audio.pid) { |
| 2373 | //restart audio |
Wentao MA | 270dc0f | 2022-08-23 13:17:26 +0800 | [diff] [blame] | 2374 | a_cmd = DVR_PLAYBACK_CMD_A_RESTART; |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 2375 | } |
| 2376 | if (!VALID_PID(segment->pids.audio.pid) |
| 2377 | && VALID_PID(p_pids->audio.pid) |
| 2378 | && segment->pids.audio.pid != p_pids->audio.pid) { |
| 2379 | //start audio |
Wentao MA | 270dc0f | 2022-08-23 13:17:26 +0800 | [diff] [blame] | 2380 | a_cmd = DVR_PLAYBACK_CMD_A_START; |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 2381 | } |
| 2382 | if (VALID_PID(segment->pids.audio.pid) |
| 2383 | && !VALID_PID(p_pids->audio.pid) |
| 2384 | && segment->pids.audio.pid != p_pids->audio.pid) { |
| 2385 | //stop audio |
Wentao MA | 270dc0f | 2022-08-23 13:17:26 +0800 | [diff] [blame] | 2386 | a_cmd = DVR_PLAYBACK_CMD_A_STOP; |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 2387 | } |
| 2388 | if (a_cmd == DVR_PLAYBACK_CMD_NONE |
| 2389 | && v_cmd == DVR_PLAYBACK_CMD_NONE) { |
| 2390 | //do nothing |
| 2391 | } else if (a_cmd == DVR_PLAYBACK_CMD_NONE |
| 2392 | || v_cmd == DVR_PLAYBACK_CMD_NONE) { |
| 2393 | player->cmd.last_cmd =DVR_PLAYBACK_CMD_PAUSE; |
| 2394 | player->cmd.cur_cmd = a_cmd != DVR_PLAYBACK_CMD_NONE ? a_cmd : v_cmd; |
| 2395 | } else if (a_cmd != DVR_PLAYBACK_CMD_NONE |
| 2396 | && v_cmd != DVR_PLAYBACK_CMD_NONE) { |
Wentao MA | 270dc0f | 2022-08-23 13:17:26 +0800 | [diff] [blame] | 2397 | if (v_cmd == DVR_PLAYBACK_CMD_V_RESTART |
| 2398 | && (a_cmd == DVR_PLAYBACK_CMD_A_RESTART)) { |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 2399 | player->cmd.last_cmd =DVR_PLAYBACK_CMD_PAUSE; |
Wentao MA | 270dc0f | 2022-08-23 13:17:26 +0800 | [diff] [blame] | 2400 | player->cmd.cur_cmd = DVR_PLAYBACK_CMD_AV_RESTART; |
| 2401 | }else if (v_cmd == DVR_PLAYBACK_CMD_V_RESTART |
| 2402 | && a_cmd == DVR_PLAYBACK_CMD_A_START) { |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 2403 | player->cmd.last_cmd =DVR_PLAYBACK_CMD_PAUSE; |
Wentao MA | 270dc0f | 2022-08-23 13:17:26 +0800 | [diff] [blame] | 2404 | player->cmd.cur_cmd = DVR_PLAYBACK_CMD_A_START_V_RESTART; |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 2405 | } else { |
| 2406 | player->cmd.last_cmd =DVR_PLAYBACK_CMD_PAUSE; |
Wentao MA | 270dc0f | 2022-08-23 13:17:26 +0800 | [diff] [blame] | 2407 | player->cmd.cur_cmd = DVR_PLAYBACK_CMD_A_STOP_V_RESTART; |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 2408 | } |
| 2409 | |
Wentao MA | 270dc0f | 2022-08-23 13:17:26 +0800 | [diff] [blame] | 2410 | if (v_cmd == DVR_PLAYBACK_CMD_V_START |
| 2411 | && (a_cmd == DVR_PLAYBACK_CMD_A_RESTART)) { |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 2412 | player->cmd.last_cmd =DVR_PLAYBACK_CMD_PAUSE; |
Wentao MA | 270dc0f | 2022-08-23 13:17:26 +0800 | [diff] [blame] | 2413 | player->cmd.cur_cmd = DVR_PLAYBACK_CMD_V_START_A_RESTART; |
| 2414 | } else if (v_cmd == DVR_PLAYBACK_CMD_V_START |
| 2415 | && a_cmd == DVR_PLAYBACK_CMD_A_START) { |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 2416 | //not occur this case |
| 2417 | player->cmd.last_cmd =DVR_PLAYBACK_CMD_PAUSE; |
| 2418 | player->cmd.cur_cmd = DVR_PLAYBACK_CMD_START; |
| 2419 | } else { |
| 2420 | player->cmd.last_cmd =DVR_PLAYBACK_CMD_PAUSE; |
Wentao MA | 270dc0f | 2022-08-23 13:17:26 +0800 | [diff] [blame] | 2421 | player->cmd.cur_cmd = DVR_PLAYBACK_CMD_A_STOP_V_START; |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 2422 | } |
| 2423 | |
Wentao MA | 270dc0f | 2022-08-23 13:17:26 +0800 | [diff] [blame] | 2424 | if (v_cmd == DVR_PLAYBACK_CMD_V_STOP |
| 2425 | && a_cmd == DVR_PLAYBACK_CMD_A_START) { |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 2426 | player->cmd.last_cmd =DVR_PLAYBACK_CMD_PAUSE; |
Wentao MA | 270dc0f | 2022-08-23 13:17:26 +0800 | [diff] [blame] | 2427 | player->cmd.cur_cmd = DVR_PLAYBACK_CMD_V_STOP_A_START; |
| 2428 | } else if (v_cmd == DVR_PLAYBACK_CMD_V_STOP |
| 2429 | && a_cmd == DVR_PLAYBACK_CMD_A_RESTART) { |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 2430 | player->cmd.last_cmd =DVR_PLAYBACK_CMD_PAUSE; |
Wentao MA | 270dc0f | 2022-08-23 13:17:26 +0800 | [diff] [blame] | 2431 | player->cmd.cur_cmd = DVR_PLAYBACK_CMD_V_STOP_A_RESTART; |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 2432 | } else { |
| 2433 | //not occur this case |
| 2434 | player->cmd.last_cmd =DVR_PLAYBACK_CMD_PAUSE; |
| 2435 | player->cmd.cur_cmd = DVR_PLAYBACK_CMD_STOP; |
| 2436 | } |
| 2437 | } |
| 2438 | } |
hualing chen | e10666f | 2020-04-14 13:58:37 +0800 | [diff] [blame] | 2439 | memcpy(&player->cur_segment.pids, p_pids, sizeof(DVR_PlaybackPids_t)); |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 2440 | } |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 2441 | //save pids info |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 2442 | DVR_PB_INFO(":apid :%d %d", segment->pids.audio.pid, p_pids->audio.pid); |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 2443 | memcpy(&segment->pids, p_pids, sizeof(DVR_PlaybackPids_t)); |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 2444 | DVR_PB_INFO(":cp apid :%d %d", segment->pids.audio.pid, p_pids->audio.pid); |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 2445 | break; |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 2446 | } |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 2447 | } |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 2448 | DVR_PB_DEBUG("unlock"); |
Zhiqiang Han | f9c0e27 | 2022-06-14 13:54:03 +0800 | [diff] [blame] | 2449 | dvr_mutex_unlock(&player->lock); |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 2450 | return DVR_SUCCESS; |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 2451 | } |
| 2452 | /**\brief Stop play, will stop video and audio |
| 2453 | * \param[in] handle playback handle |
| 2454 | * \param[in] clear is clear last frame |
| 2455 | * \retval DVR_SUCCESS On success |
| 2456 | * \return Error code |
| 2457 | */ |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 2458 | int dvr_playback_stop(DVR_PlaybackHandle_t handle, DVR_Bool_t clear) { |
| 2459 | DVR_Playback_t *player = (DVR_Playback_t *) handle; |
Wentao MA | e8ba517 | 2022-08-09 11:18:17 +0800 | [diff] [blame] | 2460 | DVR_UNUSED(clear); |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 2461 | if (player == NULL) { |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 2462 | DVR_PB_INFO("player is NULL"); |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 2463 | return DVR_FAILURE; |
| 2464 | } |
hualing chen | b96aa2c | 2020-04-15 14:13:53 +0800 | [diff] [blame] | 2465 | if (player->state == DVR_PLAYBACK_STATE_STOP) { |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 2466 | DVR_PB_INFO(":playback is stoped"); |
hualing chen | b96aa2c | 2020-04-15 14:13:53 +0800 | [diff] [blame] | 2467 | return DVR_SUCCESS; |
| 2468 | } |
Ke Gong | 3c0caba | 2020-04-21 22:58:18 -0700 | [diff] [blame] | 2469 | if (player->state == DVR_PLAYBACK_STATE_STOP) { |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 2470 | DVR_PB_INFO(":playback is stoped"); |
Ke Gong | 3c0caba | 2020-04-21 22:58:18 -0700 | [diff] [blame] | 2471 | return DVR_SUCCESS; |
| 2472 | } |
hualing chen | 87072a8 | 2020-03-12 16:20:12 +0800 | [diff] [blame] | 2473 | _stop_playback_thread(handle); |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 2474 | DVR_PB_DEBUG("lock"); |
Zhiqiang Han | f9c0e27 | 2022-06-14 13:54:03 +0800 | [diff] [blame] | 2475 | dvr_mutex_lock(&player->lock); |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 2476 | DVR_PB_INFO(":get lock into stop fast"); |
hualing chen | 3114087 | 2020-03-25 12:29:26 +0800 | [diff] [blame] | 2477 | AmTsPlayer_stopFast(player->handle); |
hualing chen | 266b950 | 2020-04-04 17:39:39 +0800 | [diff] [blame] | 2478 | if (player->has_video) { |
| 2479 | AmTsPlayer_resumeVideoDecoding(player->handle); |
| 2480 | } |
| 2481 | if (player->has_audio) { |
| 2482 | AmTsPlayer_resumeAudioDecoding(player->handle); |
| 2483 | } |
| 2484 | if (player->has_video) { |
| 2485 | player->has_video = DVR_FALSE; |
hualing chen | 10cdb16 | 2021-02-05 10:44:41 +0800 | [diff] [blame] | 2486 | AmTsPlayer_hideVideo(player->handle); |
hualing chen | 266b950 | 2020-04-04 17:39:39 +0800 | [diff] [blame] | 2487 | AmTsPlayer_stopVideoDecoding(player->handle); |
| 2488 | } |
| 2489 | if (player->has_audio) { |
| 2490 | player->has_audio = DVR_FALSE; |
| 2491 | AmTsPlayer_stopAudioDecoding(player->handle); |
| 2492 | } |
hualing chen | df118dd | 2020-05-21 15:49:11 +0800 | [diff] [blame] | 2493 | if (player->has_ad_audio) { |
| 2494 | player->has_ad_audio =DVR_FALSE; |
| 2495 | AmTsPlayer_disableADMix(player->handle); |
| 2496 | } |
hualing chen | 266b950 | 2020-04-04 17:39:39 +0800 | [diff] [blame] | 2497 | |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 2498 | player->cmd.last_cmd = player->cmd.cur_cmd; |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 2499 | player->cmd.cur_cmd = DVR_PLAYBACK_CMD_STOP; |
| 2500 | player->cmd.state = DVR_PLAYBACK_STATE_STOP; |
Wentao MA | 907b643 | 2022-08-01 06:23:08 +0000 | [diff] [blame] | 2501 | DVR_PLAYER_CHANGE_STATE(player,DVR_PLAYBACK_STATE_STOP); |
hualing chen | 87072a8 | 2020-03-12 16:20:12 +0800 | [diff] [blame] | 2502 | player->cur_segment_id = UINT64_MAX; |
| 2503 | player->segment_is_open = DVR_FALSE; |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 2504 | DVR_PB_DEBUG("unlock"); |
| 2505 | DVR_PB_INFO("player->state %s", _dvr_playback_state_toString(player->state)); |
Zhiqiang Han | f9c0e27 | 2022-06-14 13:54:03 +0800 | [diff] [blame] | 2506 | dvr_mutex_unlock(&player->lock); |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 2507 | return DVR_SUCCESS; |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 2508 | } |
| 2509 | /**\brief Start play audio |
| 2510 | * \param[in] handle playback handle |
| 2511 | * \param[in] params audio playback params,contains fmt and pid... |
| 2512 | * \retval DVR_SUCCESS On success |
| 2513 | * \return Error code |
| 2514 | */ |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 2515 | |
Wentao MA | 270dc0f | 2022-08-23 13:17:26 +0800 | [diff] [blame] | 2516 | int dvr_playback_audio_start(DVR_PlaybackHandle_t handle, am_tsplayer_audio_params *param, am_tsplayer_audio_params *ad_param) { |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 2517 | DVR_Playback_t *player = (DVR_Playback_t *) handle; |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 2518 | |
| 2519 | if (player == NULL) { |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 2520 | DVR_PB_INFO("player is NULL"); |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 2521 | return DVR_FAILURE; |
| 2522 | } |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 2523 | _start_playback_thread(handle); |
| 2524 | //start audio and video |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 2525 | DVR_PB_DEBUG("lock"); |
Zhiqiang Han | f9c0e27 | 2022-06-14 13:54:03 +0800 | [diff] [blame] | 2526 | dvr_mutex_lock(&player->lock); |
hualing chen | df118dd | 2020-05-21 15:49:11 +0800 | [diff] [blame] | 2527 | |
Wentao MA | 270dc0f | 2022-08-23 13:17:26 +0800 | [diff] [blame] | 2528 | if (VALID_PID(ad_param->pid)) { |
hualing chen | df118dd | 2020-05-21 15:49:11 +0800 | [diff] [blame] | 2529 | player->has_ad_audio = DVR_TRUE; |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 2530 | DVR_PB_INFO("start ad audio"); |
Wentao MA | 270dc0f | 2022-08-23 13:17:26 +0800 | [diff] [blame] | 2531 | AmTsPlayer_setADParams(player->handle, ad_param); |
hualing chen | df118dd | 2020-05-21 15:49:11 +0800 | [diff] [blame] | 2532 | AmTsPlayer_enableADMix(player->handle); |
| 2533 | } |
hualing chen | 969fe7b | 2021-05-26 15:13:17 +0800 | [diff] [blame] | 2534 | if (VALID_PID(param->pid)) { |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 2535 | DVR_PB_INFO("start audio"); |
hualing chen | 969fe7b | 2021-05-26 15:13:17 +0800 | [diff] [blame] | 2536 | player->has_audio = DVR_TRUE; |
| 2537 | AmTsPlayer_setAudioParams(player->handle, param); |
Wentao MA | 5629ad8 | 2022-08-24 10:03:02 +0800 | [diff] [blame] | 2538 | if (player->audio_presentation_id > -1) { |
| 2539 | AmTsPlayer_setParams(player->handle, AM_TSPLAYER_KEY_AUDIO_PRESENTATION_ID, &player->audio_presentation_id); |
| 2540 | } |
hualing chen | 969fe7b | 2021-05-26 15:13:17 +0800 | [diff] [blame] | 2541 | AmTsPlayer_startAudioDecoding(player->handle); |
| 2542 | } |
hualing chen | df118dd | 2020-05-21 15:49:11 +0800 | [diff] [blame] | 2543 | |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 2544 | player->cmd.last_cmd = player->cmd.cur_cmd; |
Wentao MA | 270dc0f | 2022-08-23 13:17:26 +0800 | [diff] [blame] | 2545 | player->cmd.cur_cmd = DVR_PLAYBACK_CMD_A_START; |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 2546 | player->cmd.state = DVR_PLAYBACK_STATE_START; |
Wentao MA | 907b643 | 2022-08-01 06:23:08 +0000 | [diff] [blame] | 2547 | DVR_PLAYER_CHANGE_STATE(player,DVR_PLAYBACK_STATE_START); |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 2548 | DVR_PB_DEBUG("unlock"); |
Zhiqiang Han | f9c0e27 | 2022-06-14 13:54:03 +0800 | [diff] [blame] | 2549 | dvr_mutex_unlock(&player->lock); |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 2550 | return DVR_SUCCESS; |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 2551 | } |
| 2552 | /**\brief Stop play audio |
| 2553 | * \param[in] handle playback handle |
| 2554 | * \retval DVR_SUCCESS On success |
| 2555 | * \return Error code |
| 2556 | */ |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 2557 | int dvr_playback_audio_stop(DVR_PlaybackHandle_t handle) { |
| 2558 | DVR_Playback_t *player = (DVR_Playback_t *) handle; |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 2559 | |
| 2560 | if (player == NULL) { |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 2561 | DVR_PB_INFO("player is NULL"); |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 2562 | return DVR_FAILURE; |
| 2563 | } |
| 2564 | |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 2565 | //playback_device_audio_stop(player->handle); |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 2566 | if (player->has_video == DVR_FALSE) { |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 2567 | player->cmd.state = DVR_PLAYBACK_STATE_STOP; |
Wentao MA | 907b643 | 2022-08-01 06:23:08 +0000 | [diff] [blame] | 2568 | DVR_PLAYER_CHANGE_STATE(player,DVR_PLAYBACK_STATE_STOP); |
Wentao MA | 9a16400 | 2022-08-29 11:20:24 +0800 | [diff] [blame] | 2569 | //destroy thread |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 2570 | _stop_playback_thread(handle); |
| 2571 | } else { |
| 2572 | //do nothing.video is playing |
| 2573 | } |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 2574 | DVR_PB_DEBUG("lock"); |
Zhiqiang Han | f9c0e27 | 2022-06-14 13:54:03 +0800 | [diff] [blame] | 2575 | dvr_mutex_lock(&player->lock); |
hualing chen | 7a56cba | 2020-04-14 14:09:27 +0800 | [diff] [blame] | 2576 | |
hualing chen | f00cdc8 | 2020-06-10 14:23:35 +0800 | [diff] [blame] | 2577 | if (player->has_audio) { |
hualing chen | df118dd | 2020-05-21 15:49:11 +0800 | [diff] [blame] | 2578 | player->has_audio = DVR_FALSE; |
| 2579 | AmTsPlayer_stopAudioDecoding(player->handle); |
| 2580 | } |
hualing chen | 87072a8 | 2020-03-12 16:20:12 +0800 | [diff] [blame] | 2581 | |
hualing chen | df118dd | 2020-05-21 15:49:11 +0800 | [diff] [blame] | 2582 | if (player->has_ad_audio) { |
| 2583 | player->has_ad_audio =DVR_FALSE; |
| 2584 | AmTsPlayer_disableADMix(player->handle); |
| 2585 | } |
| 2586 | |
hualing chen | 87072a8 | 2020-03-12 16:20:12 +0800 | [diff] [blame] | 2587 | player->cmd.last_cmd = player->cmd.cur_cmd; |
Wentao MA | 270dc0f | 2022-08-23 13:17:26 +0800 | [diff] [blame] | 2588 | player->cmd.cur_cmd = DVR_PLAYBACK_CMD_A_STOP; |
hualing chen | 87072a8 | 2020-03-12 16:20:12 +0800 | [diff] [blame] | 2589 | |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 2590 | DVR_PB_DEBUG("unlock"); |
Zhiqiang Han | f9c0e27 | 2022-06-14 13:54:03 +0800 | [diff] [blame] | 2591 | dvr_mutex_unlock(&player->lock); |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 2592 | return DVR_SUCCESS; |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 2593 | } |
| 2594 | /**\brief Start play video |
| 2595 | * \param[in] handle playback handle |
| 2596 | * \param[in] params video playback params,contains fmt and pid... |
| 2597 | * \retval DVR_SUCCESS On success |
| 2598 | * \return Error code |
| 2599 | */ |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 2600 | 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] | 2601 | DVR_Playback_t *player = (DVR_Playback_t *) handle; |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 2602 | |
| 2603 | if (player == NULL) { |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 2604 | DVR_PB_INFO("player is NULL"); |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 2605 | return DVR_FAILURE; |
| 2606 | } |
| 2607 | |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 2608 | _start_playback_thread(handle); |
| 2609 | //start audio and video |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 2610 | DVR_PB_DEBUG("lock"); |
Zhiqiang Han | f9c0e27 | 2022-06-14 13:54:03 +0800 | [diff] [blame] | 2611 | dvr_mutex_lock(&player->lock); |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 2612 | player->has_video = DVR_TRUE; |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 2613 | AmTsPlayer_setVideoParams(player->handle, param); |
hualing chen | 21a4037 | 2021-10-29 11:07:26 +0800 | [diff] [blame] | 2614 | AmTsPlayer_setVideoBlackOut(player->handle, 1); |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 2615 | AmTsPlayer_startVideoDecoding(player->handle); |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 2616 | |
| 2617 | //playback_device_video_start(player->handle , param); |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 2618 | //if set flag is pause live, we need set trick mode |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 2619 | if ((player->play_flag&DVR_PLAYBACK_STARTED_PAUSEDLIVE) == DVR_PLAYBACK_STARTED_PAUSEDLIVE) { |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 2620 | DVR_PB_INFO("settrick mode at video start"); |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 2621 | AmTsPlayer_setTrickMode(player->handle, AV_VIDEO_TRICK_MODE_PAUSE_NEXT); |
| 2622 | //playback_device_trick_mode(player->handle, 1); |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 2623 | } |
| 2624 | player->cmd.last_cmd = player->cmd.cur_cmd; |
Wentao MA | 270dc0f | 2022-08-23 13:17:26 +0800 | [diff] [blame] | 2625 | player->cmd.cur_cmd = DVR_PLAYBACK_CMD_V_START; |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 2626 | player->cmd.state = DVR_PLAYBACK_STATE_START; |
Wentao MA | 907b643 | 2022-08-01 06:23:08 +0000 | [diff] [blame] | 2627 | DVR_PLAYER_CHANGE_STATE(player,DVR_PLAYBACK_STATE_START); |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 2628 | DVR_PB_DEBUG("unlock"); |
Zhiqiang Han | f9c0e27 | 2022-06-14 13:54:03 +0800 | [diff] [blame] | 2629 | dvr_mutex_unlock(&player->lock); |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 2630 | return DVR_SUCCESS; |
| 2631 | } |
| 2632 | /**\brief Stop play video |
| 2633 | * \param[in] handle playback handle |
| 2634 | * \retval DVR_SUCCESS On success |
| 2635 | * \return Error code |
| 2636 | */ |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 2637 | int dvr_playback_video_stop(DVR_PlaybackHandle_t handle) { |
| 2638 | DVR_Playback_t *player = (DVR_Playback_t *) handle; |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 2639 | |
| 2640 | if (player == NULL) { |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 2641 | DVR_PB_INFO("player is NULL"); |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 2642 | return DVR_FAILURE; |
| 2643 | } |
| 2644 | |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 2645 | if (player->has_audio == DVR_FALSE) { |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 2646 | player->cmd.state = DVR_PLAYBACK_STATE_STOP; |
Wentao MA | 907b643 | 2022-08-01 06:23:08 +0000 | [diff] [blame] | 2647 | DVR_PLAYER_CHANGE_STATE(player,DVR_PLAYBACK_STATE_STOP); |
Wentao MA | 9a16400 | 2022-08-29 11:20:24 +0800 | [diff] [blame] | 2648 | //destroy thread |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 2649 | _stop_playback_thread(handle); |
| 2650 | } else { |
| 2651 | //do nothing.audio is playing |
| 2652 | } |
hualing chen | 7a56cba | 2020-04-14 14:09:27 +0800 | [diff] [blame] | 2653 | |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 2654 | DVR_PB_DEBUG("lock"); |
Zhiqiang Han | f9c0e27 | 2022-06-14 13:54:03 +0800 | [diff] [blame] | 2655 | dvr_mutex_lock(&player->lock); |
hualing chen | 7a56cba | 2020-04-14 14:09:27 +0800 | [diff] [blame] | 2656 | |
hualing chen | 87072a8 | 2020-03-12 16:20:12 +0800 | [diff] [blame] | 2657 | player->has_video = DVR_FALSE; |
| 2658 | |
| 2659 | AmTsPlayer_stopVideoDecoding(player->handle); |
| 2660 | //playback_device_video_stop(player->handle); |
| 2661 | |
| 2662 | player->cmd.last_cmd = player->cmd.cur_cmd; |
Wentao MA | 270dc0f | 2022-08-23 13:17:26 +0800 | [diff] [blame] | 2663 | player->cmd.cur_cmd = DVR_PLAYBACK_CMD_V_STOP; |
hualing chen | 87072a8 | 2020-03-12 16:20:12 +0800 | [diff] [blame] | 2664 | |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 2665 | DVR_PB_DEBUG("unlock"); |
Zhiqiang Han | f9c0e27 | 2022-06-14 13:54:03 +0800 | [diff] [blame] | 2666 | dvr_mutex_unlock(&player->lock); |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 2667 | return DVR_SUCCESS; |
| 2668 | } |
| 2669 | /**\brief Pause play |
| 2670 | * \param[in] handle playback handle |
| 2671 | * \param[in] flush whether its internal buffers should be flushed |
| 2672 | * \retval DVR_SUCCESS On success |
| 2673 | * \return Error code |
| 2674 | */ |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 2675 | int dvr_playback_pause(DVR_PlaybackHandle_t handle, DVR_Bool_t flush) { |
| 2676 | DVR_Playback_t *player = (DVR_Playback_t *) handle; |
Wentao MA | e8ba517 | 2022-08-09 11:18:17 +0800 | [diff] [blame] | 2677 | DVR_UNUSED(flush); |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 2678 | if (player == NULL) { |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 2679 | DVR_PB_INFO("player is NULL"); |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 2680 | return DVR_FAILURE; |
| 2681 | } |
hualing chen | f00cdc8 | 2020-06-10 14:23:35 +0800 | [diff] [blame] | 2682 | if (player->state == DVR_PLAYBACK_STATE_PAUSE ||player->state == DVR_PLAYBACK_STATE_STOP ) { |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 2683 | DVR_PB_INFO("player state is [%d] pause or stop", player->state); |
hualing chen | bd977fd | 2020-06-29 19:14:18 +0800 | [diff] [blame] | 2684 | return DVR_SUCCESS; |
hualing chen | f00cdc8 | 2020-06-10 14:23:35 +0800 | [diff] [blame] | 2685 | } |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 2686 | DVR_PB_DEBUG("lock"); |
Zhiqiang Han | f9c0e27 | 2022-06-14 13:54:03 +0800 | [diff] [blame] | 2687 | dvr_mutex_lock(&player->lock); |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 2688 | DVR_PB_DEBUG("get lock"); |
hualing chen | 266b950 | 2020-04-04 17:39:39 +0800 | [diff] [blame] | 2689 | if (player->has_video) |
| 2690 | AmTsPlayer_pauseVideoDecoding(player->handle); |
hualing chen | e41f437 | 2020-06-06 16:29:17 +0800 | [diff] [blame] | 2691 | if (player->has_audio) |
hualing chen | 266b950 | 2020-04-04 17:39:39 +0800 | [diff] [blame] | 2692 | AmTsPlayer_pauseAudioDecoding(player->handle); |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 2693 | |
| 2694 | //playback_device_pause(player->handle); |
hualing chen | 87072a8 | 2020-03-12 16:20:12 +0800 | [diff] [blame] | 2695 | if (player->cmd.cur_cmd == DVR_PLAYBACK_CMD_FF || |
| 2696 | player->cmd.cur_cmd == DVR_PLAYBACK_CMD_FB) { |
| 2697 | player->cmd.state = DVR_PLAYBACK_STATE_PAUSE; |
Wentao MA | 907b643 | 2022-08-01 06:23:08 +0000 | [diff] [blame] | 2698 | DVR_PLAYER_CHANGE_STATE(player,DVR_PLAYBACK_STATE_PAUSE); |
hualing chen | 87072a8 | 2020-03-12 16:20:12 +0800 | [diff] [blame] | 2699 | } else { |
| 2700 | player->cmd.last_cmd = player->cmd.cur_cmd; |
| 2701 | player->cmd.cur_cmd = DVR_PLAYBACK_CMD_PAUSE; |
| 2702 | player->cmd.state = DVR_PLAYBACK_STATE_PAUSE; |
Wentao MA | 907b643 | 2022-08-01 06:23:08 +0000 | [diff] [blame] | 2703 | DVR_PLAYER_CHANGE_STATE(player,DVR_PLAYBACK_STATE_PAUSE); |
hualing chen | 87072a8 | 2020-03-12 16:20:12 +0800 | [diff] [blame] | 2704 | } |
Zhiqiang Han | f9c0e27 | 2022-06-14 13:54:03 +0800 | [diff] [blame] | 2705 | dvr_mutex_unlock(&player->lock); |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 2706 | DVR_PB_DEBUG("unlock"); |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 2707 | |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 2708 | return DVR_SUCCESS; |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 2709 | } |
| 2710 | |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 2711 | //not add lock |
| 2712 | static int _dvr_cmd(DVR_PlaybackHandle_t handle, int cmd) |
| 2713 | { |
| 2714 | DVR_Playback_t *player = (DVR_Playback_t *) handle; |
| 2715 | |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 2716 | if (player == NULL) { |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 2717 | DVR_PB_INFO("player is NULL"); |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 2718 | return DVR_FAILURE; |
| 2719 | } |
| 2720 | |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 2721 | //get video params and audio params |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 2722 | DVR_PB_DEBUG("lock"); |
Zhiqiang Han | f9c0e27 | 2022-06-14 13:54:03 +0800 | [diff] [blame] | 2723 | dvr_mutex_lock(&player->lock); |
Wentao MA | 270dc0f | 2022-08-23 13:17:26 +0800 | [diff] [blame] | 2724 | am_tsplayer_video_params video_params; |
| 2725 | am_tsplayer_audio_params audio_params; |
| 2726 | am_tsplayer_audio_params ad_params; |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame] | 2727 | uint64_t segmentid = player->cur_segment_id; |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 2728 | |
Wentao MA | 270dc0f | 2022-08-23 13:17:26 +0800 | [diff] [blame] | 2729 | memset(&video_params, 0, sizeof(video_params)); |
| 2730 | memset(&audio_params, 0, sizeof(audio_params)); |
jiangfei.han | b8fbad4 | 2021-07-29 15:04:48 +0800 | [diff] [blame] | 2731 | |
Wentao MA | 270dc0f | 2022-08-23 13:17:26 +0800 | [diff] [blame] | 2732 | _dvr_playback_get_playinfo(handle, segmentid, &video_params, &audio_params, &ad_params); |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 2733 | DVR_PB_INFO("unlock cmd: %d", cmd); |
Zhiqiang Han | f9c0e27 | 2022-06-14 13:54:03 +0800 | [diff] [blame] | 2734 | dvr_mutex_unlock(&player->lock); |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 2735 | |
| 2736 | switch (cmd) { |
Wentao MA | 270dc0f | 2022-08-23 13:17:26 +0800 | [diff] [blame] | 2737 | case DVR_PLAYBACK_CMD_AV_RESTART: |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 2738 | //av restart |
Wentao MA | 270dc0f | 2022-08-23 13:17:26 +0800 | [diff] [blame] | 2739 | DVR_PB_INFO("do_cmd av_restart"); |
hualing chen | 87072a8 | 2020-03-12 16:20:12 +0800 | [diff] [blame] | 2740 | _dvr_playback_replay((DVR_PlaybackHandle_t)player, DVR_FALSE); |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 2741 | break; |
Wentao MA | 270dc0f | 2022-08-23 13:17:26 +0800 | [diff] [blame] | 2742 | case DVR_PLAYBACK_CMD_V_RESTART: |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 2743 | dvr_playback_video_stop((DVR_PlaybackHandle_t)player); |
Wentao MA | 270dc0f | 2022-08-23 13:17:26 +0800 | [diff] [blame] | 2744 | dvr_playback_video_start((DVR_PlaybackHandle_t)player, &video_params); |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 2745 | break; |
Wentao MA | 270dc0f | 2022-08-23 13:17:26 +0800 | [diff] [blame] | 2746 | case DVR_PLAYBACK_CMD_V_START: |
| 2747 | dvr_playback_video_start((DVR_PlaybackHandle_t)player, &video_params); |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 2748 | break; |
Wentao MA | 270dc0f | 2022-08-23 13:17:26 +0800 | [diff] [blame] | 2749 | case DVR_PLAYBACK_CMD_V_STOP: |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 2750 | dvr_playback_video_stop((DVR_PlaybackHandle_t)player); |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 2751 | break; |
Wentao MA | 270dc0f | 2022-08-23 13:17:26 +0800 | [diff] [blame] | 2752 | case DVR_PLAYBACK_CMD_A_RESTART: |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 2753 | //a restart |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 2754 | dvr_playback_audio_stop((DVR_PlaybackHandle_t)player); |
Wentao MA | 270dc0f | 2022-08-23 13:17:26 +0800 | [diff] [blame] | 2755 | dvr_playback_audio_start((DVR_PlaybackHandle_t)player, &audio_params, &ad_params); |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 2756 | break; |
Wentao MA | 270dc0f | 2022-08-23 13:17:26 +0800 | [diff] [blame] | 2757 | case DVR_PLAYBACK_CMD_A_START: |
| 2758 | dvr_playback_audio_start((DVR_PlaybackHandle_t)player, &audio_params, &ad_params); |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 2759 | break; |
Wentao MA | 270dc0f | 2022-08-23 13:17:26 +0800 | [diff] [blame] | 2760 | case DVR_PLAYBACK_CMD_A_STOP: |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 2761 | dvr_playback_audio_stop((DVR_PlaybackHandle_t)player); |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 2762 | break; |
Wentao MA | 270dc0f | 2022-08-23 13:17:26 +0800 | [diff] [blame] | 2763 | case DVR_PLAYBACK_CMD_A_STOP_V_RESTART: |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 2764 | dvr_playback_audio_stop((DVR_PlaybackHandle_t)player); |
| 2765 | dvr_playback_video_stop((DVR_PlaybackHandle_t)player); |
Wentao MA | 270dc0f | 2022-08-23 13:17:26 +0800 | [diff] [blame] | 2766 | dvr_playback_video_start((DVR_PlaybackHandle_t)player, &video_params); |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 2767 | break; |
Wentao MA | 270dc0f | 2022-08-23 13:17:26 +0800 | [diff] [blame] | 2768 | case DVR_PLAYBACK_CMD_A_STOP_V_START: |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 2769 | dvr_playback_audio_stop((DVR_PlaybackHandle_t)player); |
Wentao MA | 270dc0f | 2022-08-23 13:17:26 +0800 | [diff] [blame] | 2770 | dvr_playback_video_start((DVR_PlaybackHandle_t)player, &video_params); |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 2771 | break; |
Wentao MA | 270dc0f | 2022-08-23 13:17:26 +0800 | [diff] [blame] | 2772 | case DVR_PLAYBACK_CMD_V_STOP_A_RESTART: |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 2773 | dvr_playback_video_stop((DVR_PlaybackHandle_t)player); |
| 2774 | dvr_playback_audio_stop((DVR_PlaybackHandle_t)player); |
Wentao MA | 270dc0f | 2022-08-23 13:17:26 +0800 | [diff] [blame] | 2775 | dvr_playback_audio_start((DVR_PlaybackHandle_t)player, &audio_params, &ad_params); |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 2776 | break; |
| 2777 | case DVR_PLAYBACK_CMD_STOP: |
| 2778 | break; |
| 2779 | case DVR_PLAYBACK_CMD_START: |
| 2780 | break; |
Wentao MA | 270dc0f | 2022-08-23 13:17:26 +0800 | [diff] [blame] | 2781 | case DVR_PLAYBACK_CMD_A_START_V_RESTART: |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 2782 | dvr_playback_video_stop((DVR_PlaybackHandle_t)player); |
Wentao MA | 270dc0f | 2022-08-23 13:17:26 +0800 | [diff] [blame] | 2783 | dvr_playback_video_start((DVR_PlaybackHandle_t)player, &video_params); |
| 2784 | dvr_playback_audio_start((DVR_PlaybackHandle_t)player, &audio_params, &ad_params); |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 2785 | break; |
Wentao MA | 270dc0f | 2022-08-23 13:17:26 +0800 | [diff] [blame] | 2786 | case DVR_PLAYBACK_CMD_V_START_A_RESTART: |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 2787 | dvr_playback_audio_stop((DVR_PlaybackHandle_t)player); |
Wentao MA | 270dc0f | 2022-08-23 13:17:26 +0800 | [diff] [blame] | 2788 | dvr_playback_video_start((DVR_PlaybackHandle_t)player, &video_params); |
| 2789 | dvr_playback_audio_start((DVR_PlaybackHandle_t)player, &audio_params, &ad_params); |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 2790 | break; |
| 2791 | case DVR_PLAYBACK_CMD_FF: |
| 2792 | case DVR_PLAYBACK_CMD_FB: |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 2793 | _dvr_playback_fffb((DVR_PlaybackHandle_t)player); |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 2794 | break; |
| 2795 | default: |
| 2796 | break; |
| 2797 | } |
| 2798 | return DVR_SUCCESS; |
| 2799 | } |
| 2800 | |
| 2801 | /**\brief Resume play |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 2802 | * \param[in] handle playback handle |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 2803 | * \retval DVR_SUCCESS On success |
| 2804 | * \return Error code |
| 2805 | */ |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 2806 | int dvr_playback_resume(DVR_PlaybackHandle_t handle) { |
| 2807 | DVR_Playback_t *player = (DVR_Playback_t *) handle; |
hualing chen | 7ea70a7 | 2021-09-09 11:25:13 +0800 | [diff] [blame] | 2808 | uint32_t pos = 0; |
hualing chen | 03fd494 | 2021-07-15 15:56:41 +0800 | [diff] [blame] | 2809 | uint64_t segmentid = 0; |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 2810 | if (player == NULL) { |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 2811 | DVR_PB_INFO("player is NULL"); |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 2812 | return DVR_FAILURE; |
| 2813 | } |
| 2814 | |
hualing chen | a991aa8 | 2021-08-16 10:21:15 +0800 | [diff] [blame] | 2815 | if (dvr_playback_check_limit(handle)) { |
| 2816 | //get id and pos to check if we can seek to this pos |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 2817 | DVR_PB_INFO("player start calculate time"); |
hualing chen | a991aa8 | 2021-08-16 10:21:15 +0800 | [diff] [blame] | 2818 | dvr_playback_calculate_last_valid_segment(handle, &segmentid, &pos); |
| 2819 | if (segmentid != player->cur_segment_id || |
| 2820 | (segmentid == player->cur_segment_id && |
| 2821 | pos > _dvr_get_cur_time(handle))) { |
| 2822 | //first to seek new pos and to resume |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 2823 | DVR_PB_INFO("seek new pos and to resume"); |
hualing chen | a991aa8 | 2021-08-16 10:21:15 +0800 | [diff] [blame] | 2824 | dvr_playback_seek(handle, segmentid, pos); |
| 2825 | } |
hualing chen | 7ea70a7 | 2021-09-09 11:25:13 +0800 | [diff] [blame] | 2826 | } else { |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 2827 | DVR_PB_INFO("player is not set limit"); |
hualing chen | 03fd494 | 2021-07-15 15:56:41 +0800 | [diff] [blame] | 2828 | } |
hualing chen | a991aa8 | 2021-08-16 10:21:15 +0800 | [diff] [blame] | 2829 | |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 2830 | if (player->cmd.cur_cmd == DVR_PLAYBACK_CMD_PAUSE) { |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 2831 | DVR_PB_DEBUG("lock"); |
Zhiqiang Han | f9c0e27 | 2022-06-14 13:54:03 +0800 | [diff] [blame] | 2832 | dvr_mutex_lock(&player->lock); |
hualing chen | 1ffd85b | 2021-08-16 15:18:43 +0800 | [diff] [blame] | 2833 | player->first_frame = 0; |
| 2834 | if (player->has_video) |
| 2835 | AmTsPlayer_pauseVideoDecoding(player->handle); |
| 2836 | if (player->has_audio) |
| 2837 | AmTsPlayer_pauseAudioDecoding(player->handle); |
| 2838 | |
hualing chen | 266b950 | 2020-04-04 17:39:39 +0800 | [diff] [blame] | 2839 | if (player->has_video) { |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 2840 | DVR_PB_INFO("dvr_playback_resume set trick mode none"); |
hualing chen | 266b950 | 2020-04-04 17:39:39 +0800 | [diff] [blame] | 2841 | AmTsPlayer_setTrickMode(player->handle, AV_VIDEO_TRICK_MODE_NONE); |
| 2842 | AmTsPlayer_resumeVideoDecoding(player->handle); |
| 2843 | } |
| 2844 | if (player->has_audio) { |
| 2845 | AmTsPlayer_resumeAudioDecoding(player->handle); |
| 2846 | } |
| 2847 | //check is has audio param,if has audio .we need start audio, |
| 2848 | //we will stop audio when ff fb, if reach end, we will pause.so we need |
| 2849 | //start audio when resume play |
| 2850 | |
Wentao MA | 270dc0f | 2022-08-23 13:17:26 +0800 | [diff] [blame] | 2851 | am_tsplayer_video_params video_params; |
| 2852 | am_tsplayer_audio_params audio_params; |
| 2853 | am_tsplayer_audio_params ad_params; |
hualing chen | 266b950 | 2020-04-04 17:39:39 +0800 | [diff] [blame] | 2854 | uint64_t segmentid = player->cur_segment_id; |
jiangfei.han | b8fbad4 | 2021-07-29 15:04:48 +0800 | [diff] [blame] | 2855 | |
Wentao MA | 270dc0f | 2022-08-23 13:17:26 +0800 | [diff] [blame] | 2856 | memset(&video_params, 0, sizeof(video_params)); |
| 2857 | memset(&audio_params, 0, sizeof(audio_params)); |
| 2858 | _dvr_playback_get_playinfo(handle, segmentid, &video_params, &audio_params, &ad_params); |
hualing chen | 266b950 | 2020-04-04 17:39:39 +0800 | [diff] [blame] | 2859 | //valid audio pid, start audio |
Wentao MA | 270dc0f | 2022-08-23 13:17:26 +0800 | [diff] [blame] | 2860 | if (player->has_ad_audio == DVR_FALSE && VALID_PID(ad_params.pid) && (player->cmd.speed.speed.speed == PLAYBACK_SPEED_X1)) { |
hualing chen | 969fe7b | 2021-05-26 15:13:17 +0800 | [diff] [blame] | 2861 | player->has_ad_audio = DVR_TRUE; |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 2862 | DVR_PB_INFO("start ad audio"); |
Wentao MA | 270dc0f | 2022-08-23 13:17:26 +0800 | [diff] [blame] | 2863 | dvr_playback_change_seek_state(handle, ad_params.pid); |
| 2864 | AmTsPlayer_setADParams(player->handle, &ad_params); |
hualing chen | 969fe7b | 2021-05-26 15:13:17 +0800 | [diff] [blame] | 2865 | AmTsPlayer_enableADMix(player->handle); |
| 2866 | } |
| 2867 | |
Wentao MA | 270dc0f | 2022-08-23 13:17:26 +0800 | [diff] [blame] | 2868 | if (player->has_audio == DVR_FALSE && VALID_PID(audio_params.pid) && (player->cmd.speed.speed.speed == PLAYBACK_SPEED_X1)) { |
hualing chen | 266b950 | 2020-04-04 17:39:39 +0800 | [diff] [blame] | 2869 | player->has_audio = DVR_TRUE; |
Wentao MA | 270dc0f | 2022-08-23 13:17:26 +0800 | [diff] [blame] | 2870 | dvr_playback_change_seek_state(handle, audio_params.pid); |
| 2871 | AmTsPlayer_setAudioParams(player->handle, &audio_params); |
Wentao MA | 5629ad8 | 2022-08-24 10:03:02 +0800 | [diff] [blame] | 2872 | if (player->audio_presentation_id > -1) { |
| 2873 | AmTsPlayer_setParams(player->handle, AM_TSPLAYER_KEY_AUDIO_PRESENTATION_ID, &player->audio_presentation_id); |
| 2874 | } |
hualing chen | 266b950 | 2020-04-04 17:39:39 +0800 | [diff] [blame] | 2875 | AmTsPlayer_startAudioDecoding(player->handle); |
| 2876 | } else { |
Wentao MA | 270dc0f | 2022-08-23 13:17:26 +0800 | [diff] [blame] | 2877 | DVR_PB_INFO("audio_params.pid:%d player->has_audio:%d speed:%d", audio_params.pid, player->has_audio, player->cmd.speed.speed.speed); |
hualing chen | 266b950 | 2020-04-04 17:39:39 +0800 | [diff] [blame] | 2878 | } |
hualing chen | df118dd | 2020-05-21 15:49:11 +0800 | [diff] [blame] | 2879 | |
hualing chen | 87072a8 | 2020-03-12 16:20:12 +0800 | [diff] [blame] | 2880 | if (player->cmd.cur_cmd == DVR_PLAYBACK_CMD_FF || |
| 2881 | player->cmd.cur_cmd == DVR_PLAYBACK_CMD_FB) { |
| 2882 | player->cmd.state = DVR_PLAYBACK_STATE_START; |
Wentao MA | 907b643 | 2022-08-01 06:23:08 +0000 | [diff] [blame] | 2883 | DVR_PLAYER_CHANGE_STATE(player,DVR_PLAYBACK_STATE_START); |
hualing chen | 87072a8 | 2020-03-12 16:20:12 +0800 | [diff] [blame] | 2884 | } else { |
| 2885 | player->cmd.last_cmd = player->cmd.cur_cmd; |
| 2886 | player->cmd.cur_cmd = DVR_PLAYBACK_CMD_RESUME; |
| 2887 | player->cmd.state = DVR_PLAYBACK_STATE_START; |
Wentao MA | 907b643 | 2022-08-01 06:23:08 +0000 | [diff] [blame] | 2888 | DVR_PLAYER_CHANGE_STATE(player,DVR_PLAYBACK_STATE_START); |
hualing chen | 87072a8 | 2020-03-12 16:20:12 +0800 | [diff] [blame] | 2889 | } |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 2890 | DVR_PB_DEBUG("unlock"); |
Zhiqiang Han | f9c0e27 | 2022-06-14 13:54:03 +0800 | [diff] [blame] | 2891 | dvr_mutex_unlock(&player->lock); |
hualing chen | 041c409 | 2020-04-05 15:11:50 +0800 | [diff] [blame] | 2892 | } else if (player->state == DVR_PLAYBACK_STATE_PAUSE){ |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 2893 | DVR_PB_INFO("lock"); |
Zhiqiang Han | f9c0e27 | 2022-06-14 13:54:03 +0800 | [diff] [blame] | 2894 | dvr_mutex_lock(&player->lock); |
hualing chen | 1ffd85b | 2021-08-16 15:18:43 +0800 | [diff] [blame] | 2895 | player->first_frame = 0; |
| 2896 | if (player->has_video) |
| 2897 | AmTsPlayer_pauseVideoDecoding(player->handle); |
| 2898 | if (player->has_audio) |
| 2899 | AmTsPlayer_pauseAudioDecoding(player->handle); |
| 2900 | |
hualing chen | e41f437 | 2020-06-06 16:29:17 +0800 | [diff] [blame] | 2901 | if (player->has_video) { |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 2902 | DVR_PB_INFO("dvr_playback_resume set trick mode none 1"); |
hualing chen | e41f437 | 2020-06-06 16:29:17 +0800 | [diff] [blame] | 2903 | AmTsPlayer_setTrickMode(player->handle, AV_VIDEO_TRICK_MODE_NONE); |
hualing chen | 041c409 | 2020-04-05 15:11:50 +0800 | [diff] [blame] | 2904 | AmTsPlayer_resumeVideoDecoding(player->handle); |
hualing chen | e41f437 | 2020-06-06 16:29:17 +0800 | [diff] [blame] | 2905 | } |
hualing chen | 041c409 | 2020-04-05 15:11:50 +0800 | [diff] [blame] | 2906 | if (player->has_audio) |
| 2907 | AmTsPlayer_resumeAudioDecoding(player->handle); |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 2908 | DVR_PB_INFO("set start state cur cmd[%d]", player->cmd.cur_cmd); |
hualing chen | 9811b21 | 2020-10-29 11:21:44 +0800 | [diff] [blame] | 2909 | if (player->cmd.speed.speed.speed == PLAYBACK_SPEED_X1) |
| 2910 | _dvr_cmd(handle, player->cmd.cur_cmd); |
hualing chen | d1686e5 | 2022-01-05 17:10:42 +0800 | [diff] [blame] | 2911 | player->cmd.state = DVR_PLAYBACK_STATE_START; |
Wentao MA | 907b643 | 2022-08-01 06:23:08 +0000 | [diff] [blame] | 2912 | DVR_PLAYER_CHANGE_STATE(player,DVR_PLAYBACK_STATE_START); |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 2913 | DVR_PB_INFO("unlock"); |
Zhiqiang Han | f9c0e27 | 2022-06-14 13:54:03 +0800 | [diff] [blame] | 2914 | dvr_mutex_unlock(&player->lock); |
hualing chen | 041c409 | 2020-04-05 15:11:50 +0800 | [diff] [blame] | 2915 | } else { |
| 2916 | if ((player->play_flag&DVR_PLAYBACK_STARTED_PAUSEDLIVE) == DVR_PLAYBACK_STARTED_PAUSEDLIVE) |
| 2917 | { |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 2918 | DVR_PB_DEBUG("lock ---\r\n"); |
Zhiqiang Han | f9c0e27 | 2022-06-14 13:54:03 +0800 | [diff] [blame] | 2919 | dvr_mutex_lock(&player->lock); |
hualing chen | 1ffd85b | 2021-08-16 15:18:43 +0800 | [diff] [blame] | 2920 | player->first_frame = 0; |
| 2921 | if (player->has_video) |
| 2922 | AmTsPlayer_pauseVideoDecoding(player->handle); |
| 2923 | if (player->has_audio) |
| 2924 | AmTsPlayer_pauseAudioDecoding(player->handle); |
hualing chen | 041c409 | 2020-04-05 15:11:50 +0800 | [diff] [blame] | 2925 | //clear flag |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 2926 | DVR_PB_INFO("clear pause live flag cur cmd[%d]", player->cmd.cur_cmd); |
hualing chen | 041c409 | 2020-04-05 15:11:50 +0800 | [diff] [blame] | 2927 | player->play_flag = player->play_flag & (~DVR_PLAYBACK_STARTED_PAUSEDLIVE); |
| 2928 | AmTsPlayer_setTrickMode(player->handle, AV_VIDEO_TRICK_MODE_NONE); |
hualing chen | 05d0943 | 2021-01-25 15:26:55 +0800 | [diff] [blame] | 2929 | if (player->has_video) { |
| 2930 | AmTsPlayer_resumeVideoDecoding(player->handle); |
| 2931 | } |
| 2932 | if (player->has_audio) |
| 2933 | AmTsPlayer_resumeAudioDecoding(player->handle); |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 2934 | DVR_PB_DEBUG("unlock ---\r\n"); |
Zhiqiang Han | f9c0e27 | 2022-06-14 13:54:03 +0800 | [diff] [blame] | 2935 | dvr_mutex_unlock(&player->lock); |
hualing chen | 041c409 | 2020-04-05 15:11:50 +0800 | [diff] [blame] | 2936 | } |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 2937 | } |
| 2938 | return DVR_SUCCESS; |
| 2939 | } |
| 2940 | |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 2941 | static DVR_Bool_t _dvr_check_playinfo_changed(DVR_PlaybackHandle_t handle, int segment_id, int set_seg_id){ |
| 2942 | |
| 2943 | DVR_Playback_t *player = (DVR_Playback_t *) handle; |
| 2944 | DVR_PlaybackSegmentInfo_t *segment = NULL; |
| 2945 | DVR_PlaybackSegmentInfo_t *cur_segment = NULL; |
| 2946 | DVR_PlaybackSegmentInfo_t *set_segment = NULL; |
| 2947 | |
wentao.ma | fd5283f | 2022-10-14 09:51:13 +0800 | [diff] [blame] | 2948 | // This error is suppressed as the macro code is picked from kernel. |
wentao.ma | a22bc85 | 2022-10-13 12:18:06 +0800 | [diff] [blame] | 2949 | // prefetch() here incurring self_assign is used to avoid some compiling |
| 2950 | // warnings. |
| 2951 | // coverity[self_assign] |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 2952 | list_for_each_entry(segment, &player->segment_list, head) |
| 2953 | { |
| 2954 | if (segment->segment_id == segment_id) { |
| 2955 | cur_segment = segment; |
| 2956 | } |
| 2957 | if (segment->segment_id == set_seg_id) { |
| 2958 | set_segment = segment; |
| 2959 | } |
| 2960 | if (cur_segment != NULL && set_segment != NULL) { |
| 2961 | break; |
| 2962 | } |
| 2963 | } |
| 2964 | if (cur_segment == NULL || set_segment == NULL) { |
Wentao MA | 270dc0f | 2022-08-23 13:17:26 +0800 | [diff] [blame] | 2965 | DVR_PB_INFO("set segment or cur segment is null"); |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 2966 | return DVR_TRUE; |
| 2967 | } |
| 2968 | if (cur_segment->pids.video.format != set_segment->pids.video.format || |
| 2969 | cur_segment->pids.video.pid != set_segment->pids.video.pid || |
| 2970 | cur_segment->pids.audio.format != set_segment->pids.audio.format || |
| 2971 | cur_segment->pids.audio.pid != set_segment->pids.audio.pid) { |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 2972 | DVR_PB_INFO("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] | 2973 | return DVR_TRUE; |
| 2974 | } |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 2975 | DVR_PB_INFO("play info not change"); |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 2976 | return DVR_FALSE; |
| 2977 | } |
| 2978 | |
hualing chen | 03fd494 | 2021-07-15 15:56:41 +0800 | [diff] [blame] | 2979 | /**\brief set limit |
| 2980 | * \param[in] handle playback handle |
| 2981 | * \param[in] rec start time ms |
| 2982 | * \param[in] rec limit time ms |
| 2983 | * \retval DVR_SUCCESS On success |
| 2984 | * \return Error code |
| 2985 | */ |
hualing chen | 7ea70a7 | 2021-09-09 11:25:13 +0800 | [diff] [blame] | 2986 | int dvr_playback_setlimit(DVR_PlaybackHandle_t handle, uint32_t time, uint32_t limit) |
hualing chen | 03fd494 | 2021-07-15 15:56:41 +0800 | [diff] [blame] | 2987 | { DVR_Playback_t *player = (DVR_Playback_t *) handle; |
| 2988 | |
| 2989 | if (player == NULL) { |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 2990 | DVR_PB_INFO("player is NULL"); |
hualing chen | 03fd494 | 2021-07-15 15:56:41 +0800 | [diff] [blame] | 2991 | return DVR_FAILURE; |
| 2992 | } |
hualing chen | 7ea70a7 | 2021-09-09 11:25:13 +0800 | [diff] [blame] | 2993 | _dvr_getClock_sec(); |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 2994 | DVR_PB_INFO("lock time %lu limit: %u player->state:%d", time, limit, player->state); |
Zhiqiang Han | f9c0e27 | 2022-06-14 13:54:03 +0800 | [diff] [blame] | 2995 | dvr_mutex_lock(&player->lock); |
hualing chen | 03fd494 | 2021-07-15 15:56:41 +0800 | [diff] [blame] | 2996 | player->rec_start = time; |
| 2997 | player->limit = limit; |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 2998 | DVR_PB_DEBUG("unlock ---\r\n"); |
Zhiqiang Han | f9c0e27 | 2022-06-14 13:54:03 +0800 | [diff] [blame] | 2999 | dvr_mutex_unlock(&player->lock); |
hualing chen | 03fd494 | 2021-07-15 15:56:41 +0800 | [diff] [blame] | 3000 | return DVR_SUCCESS; |
| 3001 | } |
| 3002 | |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 3003 | /**\brief seek |
| 3004 | * \param[in] handle playback handle |
| 3005 | * \param[in] time_offset time offset base cur segment |
| 3006 | * \retval DVR_SUCCESS On success |
| 3007 | * \return Error code |
| 3008 | */ |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame] | 3009 | 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] | 3010 | DVR_Playback_t *player = (DVR_Playback_t *) handle; |
hualing chen | 03fd494 | 2021-07-15 15:56:41 +0800 | [diff] [blame] | 3011 | int ret = DVR_SUCCESS; |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 3012 | if (player == NULL) { |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 3013 | DVR_PB_INFO("player is NULL"); |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 3014 | return DVR_FAILURE; |
| 3015 | } |
| 3016 | |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 3017 | DVR_PB_INFO("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); |
Zhiqiang Han | f9c0e27 | 2022-06-14 13:54:03 +0800 | [diff] [blame] | 3018 | dvr_mutex_lock(&player->lock); |
hualing chen | 87072a8 | 2020-03-12 16:20:12 +0800 | [diff] [blame] | 3019 | |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 3020 | DVR_Bool_t replay = _dvr_check_playinfo_changed(handle, player->cur_segment_id, segment_id); |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 3021 | DVR_PB_INFO("player->state[%d]-replay[%d]--get lock-", player->state, replay); |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 3022 | |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 3023 | //open segment if id is not current segment |
hualing chen | 03fd494 | 2021-07-15 15:56:41 +0800 | [diff] [blame] | 3024 | ret = _dvr_open_segment(handle, segment_id); |
hualing chen | 87072a8 | 2020-03-12 16:20:12 +0800 | [diff] [blame] | 3025 | if (ret ==DVR_FAILURE) { |
wentao.ma | a210e5e | 2022-10-12 16:10:03 +0800 | [diff] [blame] | 3026 | DVR_PB_ERROR("unlock seek error at open segment"); |
Zhiqiang Han | f9c0e27 | 2022-06-14 13:54:03 +0800 | [diff] [blame] | 3027 | dvr_mutex_unlock(&player->lock); |
hualing chen | 87072a8 | 2020-03-12 16:20:12 +0800 | [diff] [blame] | 3028 | return DVR_FAILURE; |
| 3029 | } |
| 3030 | if (time_offset >_dvr_get_end_time(handle) &&_dvr_has_next_segmentId(handle, segment_id) == DVR_FAILURE) { |
Wentao MA | f35c388 | 2023-04-17 12:36:19 +0800 | [diff] [blame] | 3031 | if (segment_ongoing(player->segment_handle) == DVR_SUCCESS) { |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 3032 | DVR_PB_INFO("is ongoing segment when seek end, need return success"); |
hualing chen | 87072a8 | 2020-03-12 16:20:12 +0800 | [diff] [blame] | 3033 | time_offset = _dvr_get_end_time(handle); |
| 3034 | } else { |
wentao.ma | a210e5e | 2022-10-12 16:10:03 +0800 | [diff] [blame] | 3035 | DVR_PB_ERROR("is not ongoing segment when seek end, return failure"); |
Zhiqiang Han | 447cff0 | 2022-12-15 11:13:41 +0800 | [diff] [blame] | 3036 | dvr_mutex_unlock(&player->lock); |
wentao.ma | a210e5e | 2022-10-12 16:10:03 +0800 | [diff] [blame] | 3037 | return DVR_FAILURE; |
hualing chen | 87072a8 | 2020-03-12 16:20:12 +0800 | [diff] [blame] | 3038 | } |
| 3039 | } |
| 3040 | |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 3041 | DVR_PB_INFO("seek open id[%lld]flag[0x%x] time_offset %u", |
hualing chen | 03fd494 | 2021-07-15 15:56:41 +0800 | [diff] [blame] | 3042 | player->cur_segment.segment_id, |
| 3043 | player->cur_segment.flags, |
| 3044 | time_offset); |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 3045 | //get file offset by time |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 3046 | if (player->cmd.cur_cmd == DVR_PLAYBACK_CMD_FB) { |
| 3047 | //forward playback.not seek end of file |
| 3048 | if (time_offset != 0 && time_offset > FB_DEFAULT_LEFT_TIME) { |
| 3049 | //default -2000ms |
| 3050 | time_offset = time_offset -FB_DEFAULT_LEFT_TIME; |
| 3051 | } |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 3052 | } |
Wentao MA | 01de0e6 | 2022-01-10 18:48:23 +0800 | [diff] [blame] | 3053 | // Seek can be regarded as a new playback, so keep the start segment_id for it also |
hualing chen | 8a657f3 | 2021-08-30 13:12:49 +0800 | [diff] [blame] | 3054 | if (player->need_seek_start == DVR_TRUE) { |
| 3055 | player->first_start_time = (uint64_t)time_offset + 1;//set first start time not eq 0 |
Wentao MA | 01de0e6 | 2022-01-10 18:48:23 +0800 | [diff] [blame] | 3056 | player->first_start_id = player->cur_segment.segment_id; |
hualing chen | 8a657f3 | 2021-08-30 13:12:49 +0800 | [diff] [blame] | 3057 | } |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 3058 | pthread_mutex_lock(&player->segment_lock); |
hualing chen | 266b950 | 2020-04-04 17:39:39 +0800 | [diff] [blame] | 3059 | player->drop_ts = DVR_TRUE; |
hualing chen | 5605eed | 2020-05-26 18:18:06 +0800 | [diff] [blame] | 3060 | player->ts_cache_len = 0; |
Wentao MA | f35c388 | 2023-04-17 12:36:19 +0800 | [diff] [blame] | 3061 | int offset = segment_seek(player->segment_handle, (uint64_t)time_offset, player->openParams.block_size); |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 3062 | DVR_PB_ERROR("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] | 3063 | pthread_mutex_unlock(&player->segment_lock); |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 3064 | player->offset = offset; |
hualing chen | 87072a8 | 2020-03-12 16:20:12 +0800 | [diff] [blame] | 3065 | |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 3066 | _dvr_get_end_time(handle); |
Zhiqiang Han | 8e4e6db | 2020-05-15 10:52:20 +0800 | [diff] [blame] | 3067 | |
| 3068 | player->last_send_time_id = UINT64_MAX; |
Wentao MA | 270dc0f | 2022-08-23 13:17:26 +0800 | [diff] [blame] | 3069 | player->last_segment_total = 0LL; |
hualing chen | 03fd494 | 2021-07-15 15:56:41 +0800 | [diff] [blame] | 3070 | player->last_segment_id = 0LL; |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 3071 | //init fffb time |
hualing chen | 87072a8 | 2020-03-12 16:20:12 +0800 | [diff] [blame] | 3072 | player->fffb_current = _dvr_time_getClock(); |
| 3073 | player->fffb_start = player->fffb_current; |
| 3074 | player->fffb_start_pcr = _dvr_get_cur_time(handle); |
| 3075 | player->next_fffb_time = player->fffb_current; |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 3076 | //pause state if need to replayer false |
hualing chen | 3962821 | 2020-05-14 10:35:13 +0800 | [diff] [blame] | 3077 | if (player->state == DVR_PLAYBACK_STATE_STOP) { |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 3078 | //only seek file,not start |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 3079 | DVR_PB_DEBUG("unlock"); |
Zhiqiang Han | f9c0e27 | 2022-06-14 13:54:03 +0800 | [diff] [blame] | 3080 | dvr_mutex_unlock(&player->lock); |
hualing chen | 87072a8 | 2020-03-12 16:20:12 +0800 | [diff] [blame] | 3081 | return DVR_SUCCESS; |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 3082 | } |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 3083 | //stop play |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 3084 | DVR_PB_ERROR("seek stop play, not inject data has video[%d]audio[%d]", |
hualing chen | 03fd494 | 2021-07-15 15:56:41 +0800 | [diff] [blame] | 3085 | player->has_video, player->has_audio); |
hualing chen | 1ffd85b | 2021-08-16 15:18:43 +0800 | [diff] [blame] | 3086 | |
hualing chen | 266b950 | 2020-04-04 17:39:39 +0800 | [diff] [blame] | 3087 | if (player->has_video) { |
hualing chen | 7e14e53 | 2021-09-23 11:23:28 +0800 | [diff] [blame] | 3088 | //player->has_video = DVR_FALSE; |
hualing chen | 21a4037 | 2021-10-29 11:07:26 +0800 | [diff] [blame] | 3089 | AmTsPlayer_setVideoBlackOut(player->handle, 0); |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 3090 | AmTsPlayer_stopVideoDecoding(player->handle); |
hualing chen | 266b950 | 2020-04-04 17:39:39 +0800 | [diff] [blame] | 3091 | } |
| 3092 | |
hualing chen | 40dd546 | 2021-11-26 19:56:20 +0800 | [diff] [blame] | 3093 | |
hualing chen | 266b950 | 2020-04-04 17:39:39 +0800 | [diff] [blame] | 3094 | if (player->has_audio) { |
| 3095 | player->has_audio =DVR_FALSE; |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 3096 | AmTsPlayer_stopAudioDecoding(player->handle); |
hualing chen | 266b950 | 2020-04-04 17:39:39 +0800 | [diff] [blame] | 3097 | } |
hualing chen | df118dd | 2020-05-21 15:49:11 +0800 | [diff] [blame] | 3098 | if (player->has_ad_audio) { |
| 3099 | player->has_ad_audio =DVR_FALSE; |
| 3100 | AmTsPlayer_disableADMix(player->handle); |
| 3101 | } |
| 3102 | |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 3103 | //start play |
Wentao MA | 270dc0f | 2022-08-23 13:17:26 +0800 | [diff] [blame] | 3104 | am_tsplayer_video_params video_params; |
| 3105 | am_tsplayer_audio_params audio_params; |
| 3106 | am_tsplayer_audio_params ad_params; |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 3107 | |
Wentao MA | 270dc0f | 2022-08-23 13:17:26 +0800 | [diff] [blame] | 3108 | memset(&video_params, 0, sizeof(video_params)); |
| 3109 | memset(&audio_params, 0, sizeof(audio_params)); |
jiangfei.han | b8fbad4 | 2021-07-29 15:04:48 +0800 | [diff] [blame] | 3110 | |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 3111 | player->cur_segment_id = segment_id; |
| 3112 | |
| 3113 | int sync = DVR_PLAYBACK_SYNC; |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 3114 | //get segment info and audio video pid fmt ; |
Wentao MA | 270dc0f | 2022-08-23 13:17:26 +0800 | [diff] [blame] | 3115 | _dvr_playback_get_playinfo(handle, segment_id, &video_params, &audio_params, &ad_params); |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 3116 | //start audio and video |
Wentao MA | 270dc0f | 2022-08-23 13:17:26 +0800 | [diff] [blame] | 3117 | if (video_params.pid != player->fake_pid && !VALID_PID(video_params.pid) && !VALID_PID(audio_params.pid)) { |
hualing chen | a5f0322 | 2021-12-02 11:22:35 +0800 | [diff] [blame] | 3118 | //audio and video pid is all invalid, return error. |
Wentao MA | 270dc0f | 2022-08-23 13:17:26 +0800 | [diff] [blame] | 3119 | DVR_PB_ERROR("unlock seek start dvr play back start error, not found audio and video info [0x%x]", video_params.pid); |
Zhiqiang Han | f9c0e27 | 2022-06-14 13:54:03 +0800 | [diff] [blame] | 3120 | dvr_mutex_unlock(&player->lock); |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 3121 | return -1; |
| 3122 | } |
Wentao MA | 270dc0f | 2022-08-23 13:17:26 +0800 | [diff] [blame] | 3123 | DVR_PB_ERROR("seek start[0x%x]", video_params.pid); |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 3124 | //add |
Zhiqiang Han | d48afcd | 2023-04-03 18:26:27 +0800 | [diff] [blame] | 3125 | int v_restarted = 0; |
| 3126 | int a_restarted = 0; |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 3127 | if (sync == DVR_PLAYBACK_SYNC) { |
Wentao MA | 270dc0f | 2022-08-23 13:17:26 +0800 | [diff] [blame] | 3128 | if (VALID_PID(video_params.pid)) { |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 3129 | //player->has_video; |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 3130 | if (player->cmd.cur_cmd == DVR_PLAYBACK_CMD_PAUSE || |
hualing chen | e41f437 | 2020-06-06 16:29:17 +0800 | [diff] [blame] | 3131 | player->state == DVR_PLAYBACK_STATE_PAUSE || |
hualing chen | df118dd | 2020-05-21 15:49:11 +0800 | [diff] [blame] | 3132 | player->speed > 2.0f|| |
hualing chen | 3114087 | 2020-03-25 12:29:26 +0800 | [diff] [blame] | 3133 | player->speed <= -1.0f) { |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 3134 | //if is pause state. we need set trick mode. |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 3135 | DVR_PB_INFO("seek set trick mode player->speed [%f]", player->speed); |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 3136 | AmTsPlayer_setTrickMode(player->handle, AV_VIDEO_TRICK_MODE_PAUSE_NEXT); |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 3137 | } |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 3138 | DVR_PB_INFO("start video"); |
Wentao MA | 270dc0f | 2022-08-23 13:17:26 +0800 | [diff] [blame] | 3139 | AmTsPlayer_setVideoParams(player->handle, &video_params); |
hualing chen | 21a4037 | 2021-10-29 11:07:26 +0800 | [diff] [blame] | 3140 | AmTsPlayer_setVideoBlackOut(player->handle, 1); |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 3141 | AmTsPlayer_startVideoDecoding(player->handle); |
Zhiqiang Han | d48afcd | 2023-04-03 18:26:27 +0800 | [diff] [blame] | 3142 | v_restarted = 1; |
hualing chen | e41f437 | 2020-06-06 16:29:17 +0800 | [diff] [blame] | 3143 | if (IS_KERNEL_SPEED(player->cmd.speed.speed.speed) && |
| 3144 | player->cmd.speed.speed.speed != PLAYBACK_SPEED_X1) { |
| 3145 | AmTsPlayer_startFast(player->handle, (float)player->cmd.speed.speed.speed/(float)100); |
| 3146 | } else if (player->cmd.speed.speed.speed == PLAYBACK_SPEED_X1) { |
| 3147 | AmTsPlayer_stopFast(player->handle); |
| 3148 | } |
hualing chen | 266b950 | 2020-04-04 17:39:39 +0800 | [diff] [blame] | 3149 | player->has_video = DVR_TRUE; |
hualing chen | 7e14e53 | 2021-09-23 11:23:28 +0800 | [diff] [blame] | 3150 | } else { |
| 3151 | player->has_video = DVR_FALSE; |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 3152 | } |
Wentao MA | 270dc0f | 2022-08-23 13:17:26 +0800 | [diff] [blame] | 3153 | if (VALID_PID(ad_params.pid) && player->speed == 1.0) { |
hualing chen | df118dd | 2020-05-21 15:49:11 +0800 | [diff] [blame] | 3154 | player->has_ad_audio = DVR_TRUE; |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 3155 | DVR_PB_INFO("start ad audio"); |
Wentao MA | 270dc0f | 2022-08-23 13:17:26 +0800 | [diff] [blame] | 3156 | dvr_playback_change_seek_state(handle, ad_params.pid); |
| 3157 | AmTsPlayer_setADParams(player->handle, &ad_params); |
hualing chen | df118dd | 2020-05-21 15:49:11 +0800 | [diff] [blame] | 3158 | AmTsPlayer_enableADMix(player->handle); |
| 3159 | } |
Wentao MA | 270dc0f | 2022-08-23 13:17:26 +0800 | [diff] [blame] | 3160 | if (VALID_PID(audio_params.pid) && player->speed == 1.0) { |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 3161 | DVR_PB_INFO("start audio seek"); |
Wentao MA | 270dc0f | 2022-08-23 13:17:26 +0800 | [diff] [blame] | 3162 | dvr_playback_change_seek_state(handle, audio_params.pid); |
| 3163 | AmTsPlayer_setAudioParams(player->handle, &audio_params); |
Wentao MA | 5629ad8 | 2022-08-24 10:03:02 +0800 | [diff] [blame] | 3164 | if (player->audio_presentation_id > -1) { |
| 3165 | AmTsPlayer_setParams(player->handle, AM_TSPLAYER_KEY_AUDIO_PRESENTATION_ID, &player->audio_presentation_id); |
| 3166 | } |
hualing chen | 969fe7b | 2021-05-26 15:13:17 +0800 | [diff] [blame] | 3167 | AmTsPlayer_startAudioDecoding(player->handle); |
Zhiqiang Han | d48afcd | 2023-04-03 18:26:27 +0800 | [diff] [blame] | 3168 | a_restarted = 1; |
hualing chen | 969fe7b | 2021-05-26 15:13:17 +0800 | [diff] [blame] | 3169 | player->has_audio = DVR_TRUE; |
| 3170 | } |
hualing chen | 43a89bc | 2022-01-19 14:31:20 +0800 | [diff] [blame] | 3171 | #ifdef AVSYNC_USED_PCR |
| 3172 | if (player && VALID_PID(player->cur_segment.pids.pcr.pid)) { |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 3173 | DVR_PB_INFO("start set pcr [%d]", player->cur_segment.pids.pcr.pid); |
hualing chen | 43a89bc | 2022-01-19 14:31:20 +0800 | [diff] [blame] | 3174 | AmTsPlayer_setPcrPid(player->handle, player->cur_segment.pids.pcr.pid); |
| 3175 | } |
| 3176 | #endif |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 3177 | } |
hualing chen | 1ffd85b | 2021-08-16 15:18:43 +0800 | [diff] [blame] | 3178 | if (player->state == DVR_PLAYBACK_STATE_PAUSE) { |
Zhiqiang Han | d48afcd | 2023-04-03 18:26:27 +0800 | [diff] [blame] | 3179 | if (v_restarted) { |
| 3180 | switch (player->cmd.cur_cmd) { |
| 3181 | case DVR_PLAYBACK_CMD_V_RESTART: |
| 3182 | player->cmd.cur_cmd = DVR_PLAYBACK_CMD_NONE; |
| 3183 | break; |
| 3184 | case DVR_PLAYBACK_CMD_A_STOP_V_RESTART: |
| 3185 | player->cmd.cur_cmd = DVR_PLAYBACK_CMD_A_STOP; |
| 3186 | break; |
| 3187 | case DVR_PLAYBACK_CMD_A_START_V_RESTART: |
| 3188 | player->cmd.cur_cmd = DVR_PLAYBACK_CMD_A_START; |
| 3189 | break; |
| 3190 | case DVR_PLAYBACK_CMD_AV_RESTART: |
| 3191 | player->cmd.cur_cmd = DVR_PLAYBACK_CMD_A_RESTART; |
| 3192 | break; |
| 3193 | default: |
| 3194 | break; |
| 3195 | } |
| 3196 | } |
| 3197 | if (a_restarted) { |
| 3198 | switch (player->cmd.cur_cmd) { |
| 3199 | case DVR_PLAYBACK_CMD_A_RESTART: |
| 3200 | player->cmd.cur_cmd = DVR_PLAYBACK_CMD_NONE; |
| 3201 | break; |
| 3202 | case DVR_PLAYBACK_CMD_V_STOP_A_RESTART: |
| 3203 | player->cmd.cur_cmd = DVR_PLAYBACK_CMD_V_STOP; |
| 3204 | break; |
| 3205 | case DVR_PLAYBACK_CMD_V_START_A_RESTART: |
| 3206 | player->cmd.cur_cmd = DVR_PLAYBACK_CMD_V_START; |
| 3207 | break; |
| 3208 | case DVR_PLAYBACK_CMD_AV_RESTART: |
| 3209 | player->cmd.cur_cmd = DVR_PLAYBACK_CMD_V_RESTART; |
| 3210 | break; |
| 3211 | default: |
| 3212 | break; |
| 3213 | } |
| 3214 | } |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 3215 | player->cmd.state = DVR_PLAYBACK_STATE_PAUSE; |
Wentao MA | 907b643 | 2022-08-01 06:23:08 +0000 | [diff] [blame] | 3216 | DVR_PLAYER_CHANGE_STATE(player,DVR_PLAYBACK_STATE_PAUSE); |
Wentao MA | 270dc0f | 2022-08-23 13:17:26 +0800 | [diff] [blame] | 3217 | if (VALID_PID(audio_params.pid) || VALID_PID(video_params.pid)) |
hualing chen | a5f0322 | 2021-12-02 11:22:35 +0800 | [diff] [blame] | 3218 | player->seek_pause = DVR_TRUE; |
Wentao MA | 270dc0f | 2022-08-23 13:17:26 +0800 | [diff] [blame] | 3219 | DVR_PB_INFO("set state pause in seek vpid[0x%x]apid[0x%x]",video_params.pid, audio_params.pid); |
hualing chen | 87072a8 | 2020-03-12 16:20:12 +0800 | [diff] [blame] | 3220 | } else if (player->cmd.cur_cmd == DVR_PLAYBACK_CMD_FF || |
Wentao MA | 16f870e | 2022-09-09 11:00:22 +0800 | [diff] [blame] | 3221 | player->cmd.cur_cmd == DVR_PLAYBACK_CMD_FB || |
hualing chen | 3114087 | 2020-03-25 12:29:26 +0800 | [diff] [blame] | 3222 | player->speed > 1.0f|| |
| 3223 | player->speed <= -1.0f) { |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 3224 | DVR_PB_INFO("not set cmd to seek"); |
hualing chen | 87072a8 | 2020-03-12 16:20:12 +0800 | [diff] [blame] | 3225 | //not pause state, we need not set cur cmd |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 3226 | } else { |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 3227 | DVR_PB_INFO("set cmd to seek"); |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 3228 | player->cmd.last_cmd = player->cmd.cur_cmd; |
| 3229 | player->cmd.cur_cmd = DVR_PLAYBACK_CMD_SEEK; |
| 3230 | player->cmd.state = DVR_PLAYBACK_STATE_START; |
Wentao MA | 907b643 | 2022-08-01 06:23:08 +0000 | [diff] [blame] | 3231 | DVR_PLAYER_CHANGE_STATE(player,DVR_PLAYBACK_STATE_START); |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 3232 | } |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 3233 | player->last_send_time_id = UINT64_MAX; |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 3234 | DVR_PB_DEBUG("unlock"); |
Zhiqiang Han | f9c0e27 | 2022-06-14 13:54:03 +0800 | [diff] [blame] | 3235 | dvr_mutex_unlock(&player->lock); |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 3236 | |
| 3237 | return DVR_SUCCESS; |
| 3238 | } |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 3239 | |
Wentao MA | ac5ea06 | 2022-08-11 11:44:27 +0800 | [diff] [blame] | 3240 | // Get current playback time position of the ongoing segment. |
| 3241 | // Notice the return value may be negative. This is because previous segment's |
| 3242 | // data cached in demux buffer need to be considered. |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 3243 | static int _dvr_get_cur_time(DVR_PlaybackHandle_t handle) { |
| 3244 | //get cur time of segment |
| 3245 | DVR_Playback_t *player = (DVR_Playback_t *) handle; |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 3246 | |
Gong Ke | 2a0ebbe | 2021-05-25 15:22:50 +0800 | [diff] [blame] | 3247 | if (player == NULL || player->handle == (am_tsplayer_handle)NULL) { |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 3248 | DVR_PB_INFO("player is NULL"); |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 3249 | return DVR_FAILURE; |
| 3250 | } |
| 3251 | |
Wentao MA | 270dc0f | 2022-08-23 13:17:26 +0800 | [diff] [blame] | 3252 | int64_t cache = 0;//default es buf cache 500ms |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 3253 | pthread_mutex_lock(&player->segment_lock); |
Wentao MA | f35c388 | 2023-04-17 12:36:19 +0800 | [diff] [blame] | 3254 | loff_t pos = segment_tell_position(player->segment_handle) -player->ts_cache_len; |
hualing chen | a5f0322 | 2021-12-02 11:22:35 +0800 | [diff] [blame] | 3255 | uint64_t cur = 0; |
| 3256 | if (player->ts_cache_len > 0 && pos < 0) { |
| 3257 | //this case is open new segment end,but cache data is last segment. |
| 3258 | //we need used last segment len to send play time. |
| 3259 | cur = 0; |
| 3260 | } else { |
Wentao MA | f35c388 | 2023-04-17 12:36:19 +0800 | [diff] [blame] | 3261 | cur = segment_tell_position_time(player->segment_handle, pos); |
hualing chen | a5f0322 | 2021-12-02 11:22:35 +0800 | [diff] [blame] | 3262 | } |
hualing chen | 21a4037 | 2021-10-29 11:07:26 +0800 | [diff] [blame] | 3263 | AmTsPlayer_getDelayTime(player->handle, &cache); |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 3264 | pthread_mutex_unlock(&player->segment_lock); |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 3265 | DVR_PB_INFO("get cur time [%lld] cache:%lld cur id [%lld]last id [%lld] pb cache len [%d] [%lld]", cur, cache, player->cur_segment_id,player->last_send_time_id, player->ts_cache_len, pos); |
hualing chen | 87072a8 | 2020-03-12 16:20:12 +0800 | [diff] [blame] | 3266 | if (player->state == DVR_PLAYBACK_STATE_STOP) { |
| 3267 | cache = 0; |
| 3268 | } |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 3269 | int cur_time = (int)(cur > cache ? cur - cache : 0); |
| 3270 | return cur_time; |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame] | 3271 | } |
| 3272 | |
Wentao MA | ac5ea06 | 2022-08-11 11:44:27 +0800 | [diff] [blame] | 3273 | // Get current playback time position of the ongoing segment. |
| 3274 | // Notice the return value may be negative. This is because previous segment's |
| 3275 | // data cached in demux buffer need to be considered. |
hualing chen | 969fe7b | 2021-05-26 15:13:17 +0800 | [diff] [blame] | 3276 | static int _dvr_get_play_cur_time(DVR_PlaybackHandle_t handle, uint64_t *id) { |
| 3277 | //get cur time of segment |
| 3278 | DVR_Playback_t *player = (DVR_Playback_t *) handle; |
Wentao MA | 804bab1 | 2022-11-29 10:01:26 +0800 | [diff] [blame] | 3279 | DVR_RETURN_IF_FALSE(player != NULL); |
Wentao MA | f35c388 | 2023-04-17 12:36:19 +0800 | [diff] [blame] | 3280 | DVR_RETURN_IF_FALSE(player->segment_handle != NULL); |
hualing chen | 969fe7b | 2021-05-26 15:13:17 +0800 | [diff] [blame] | 3281 | |
hualing chen | 969fe7b | 2021-05-26 15:13:17 +0800 | [diff] [blame] | 3282 | pthread_mutex_lock(&player->segment_lock); |
Wentao MA | f35c388 | 2023-04-17 12:36:19 +0800 | [diff] [blame] | 3283 | const loff_t pos = segment_tell_position(player->segment_handle); |
| 3284 | const uint64_t cur = segment_tell_position_time(player->segment_handle, pos); |
hualing chen | 969fe7b | 2021-05-26 15:13:17 +0800 | [diff] [blame] | 3285 | pthread_mutex_unlock(&player->segment_lock); |
Wentao MA | 01de0e6 | 2022-01-10 18:48:23 +0800 | [diff] [blame] | 3286 | |
Wentao MA | 804bab1 | 2022-11-29 10:01:26 +0800 | [diff] [blame] | 3287 | int cache = 0; |
| 3288 | get_effective_tsplayer_delay_time(player, &cache); |
Wentao MA | 01de0e6 | 2022-01-10 18:48:23 +0800 | [diff] [blame] | 3289 | |
hualing chen | 969fe7b | 2021-05-26 15:13:17 +0800 | [diff] [blame] | 3290 | if (player->state == DVR_PLAYBACK_STATE_STOP) { |
| 3291 | cache = 0; |
| 3292 | } |
Wentao MA | 804bab1 | 2022-11-29 10:01:26 +0800 | [diff] [blame] | 3293 | |
Wentao MA | 3e2dc45 | 2022-12-20 11:17:16 +0800 | [diff] [blame] | 3294 | int cur_time = (int)(cur - cache); |
Wentao MA | 804bab1 | 2022-11-29 10:01:26 +0800 | [diff] [blame] | 3295 | *id = player->cur_segment_id; |
hualing chen | 8a657f3 | 2021-08-30 13:12:49 +0800 | [diff] [blame] | 3296 | |
Wentao MA | 3e2dc45 | 2022-12-20 11:17:16 +0800 | [diff] [blame] | 3297 | if (*id == 0 && cur_time<0) { |
| 3298 | cur_time = 0; |
| 3299 | } |
| 3300 | |
Wentao MA | 8017951 | 2022-11-03 12:20:03 +0800 | [diff] [blame] | 3301 | DVR_PB_INFO("***get playback slider position within segment. segment_id [%lld]," |
wentao.ma | 4ee4302 | 2022-12-14 13:22:57 +0800 | [diff] [blame] | 3302 | " segment_slider_pos[%7d ms] = segment_read_pos[%7lld ms] - tsplayer_cache_len[%5ld ms]," |
Wentao MA | 8017951 | 2022-11-03 12:20:03 +0800 | [diff] [blame] | 3303 | " last id [%lld] pos [%lld]", |
| 3304 | player->cur_segment_id,cur_time,cur,cache,player->last_send_time_id,pos); |
Wentao MA | 804bab1 | 2022-11-29 10:01:26 +0800 | [diff] [blame] | 3305 | |
hualing chen | 969fe7b | 2021-05-26 15:13:17 +0800 | [diff] [blame] | 3306 | return cur_time; |
| 3307 | } |
| 3308 | |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame] | 3309 | //get current segment current pcr time of read pos |
| 3310 | static int _dvr_get_end_time(DVR_PlaybackHandle_t handle) { |
| 3311 | //get cur time of segment |
| 3312 | DVR_Playback_t *player = (DVR_Playback_t *) handle; |
Wentao MA | f35c388 | 2023-04-17 12:36:19 +0800 | [diff] [blame] | 3313 | DVR_RETURN_IF_FALSE(player != NULL); |
| 3314 | DVR_RETURN_IF_FALSE(player->segment_handle != NULL); |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 3315 | |
| 3316 | if (player == NULL) { |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 3317 | DVR_PB_INFO("player is NULL"); |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 3318 | return DVR_FAILURE; |
| 3319 | } |
| 3320 | |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 3321 | pthread_mutex_lock(&player->segment_lock); |
Wentao MA | f35c388 | 2023-04-17 12:36:19 +0800 | [diff] [blame] | 3322 | uint64_t end = segment_tell_total_time(player->segment_handle); |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 3323 | pthread_mutex_unlock(&player->segment_lock); |
| 3324 | return (int)end; |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 3325 | } |
| 3326 | |
hualing chen | 03fd494 | 2021-07-15 15:56:41 +0800 | [diff] [blame] | 3327 | DVR_Bool_t dvr_playback_check_limit(DVR_PlaybackHandle_t handle) |
| 3328 | { |
| 3329 | //check is set limit info |
| 3330 | DVR_Playback_t *player = (DVR_Playback_t *) handle; |
| 3331 | |
| 3332 | if (player == NULL) { |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 3333 | DVR_PB_INFO("player is NULL"); |
hualing chen | 03fd494 | 2021-07-15 15:56:41 +0800 | [diff] [blame] | 3334 | return DVR_FALSE; |
| 3335 | } |
| 3336 | if (player->rec_start > 0 || player->limit > 0) { |
| 3337 | return DVR_TRUE; |
| 3338 | } |
| 3339 | return DVR_FALSE; |
| 3340 | } |
| 3341 | |
| 3342 | /**\brief set DVR playback calculate expired time len |
| 3343 | * \param[in] handle, DVR playback session handle |
| 3344 | * \return DVR_SUCCESS on success |
| 3345 | * \return error code on failure |
| 3346 | */ |
hualing chen | 7ea70a7 | 2021-09-09 11:25:13 +0800 | [diff] [blame] | 3347 | uint32_t dvr_playback_calculate_expiredlen(DVR_PlaybackHandle_t handle) |
hualing chen | 03fd494 | 2021-07-15 15:56:41 +0800 | [diff] [blame] | 3348 | { |
| 3349 | //calculate expired time to play |
| 3350 | DVR_Playback_t *player = (DVR_Playback_t *) handle; |
hualing chen | 7ea70a7 | 2021-09-09 11:25:13 +0800 | [diff] [blame] | 3351 | uint32_t cur_time; |
| 3352 | uint32_t tmp_time; |
| 3353 | uint32_t expired = 0; |
hualing chen | 03fd494 | 2021-07-15 15:56:41 +0800 | [diff] [blame] | 3354 | if (player == NULL) { |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 3355 | DVR_PB_INFO("player is NULL"); |
hualing chen | 03fd494 | 2021-07-15 15:56:41 +0800 | [diff] [blame] | 3356 | return expired; |
| 3357 | } |
hualing chen | 7ea70a7 | 2021-09-09 11:25:13 +0800 | [diff] [blame] | 3358 | if (player->rec_start == 0 || player->limit == 0) { |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 3359 | DVR_PB_INFO("rec limit 0"); |
hualing chen | 03fd494 | 2021-07-15 15:56:41 +0800 | [diff] [blame] | 3360 | return expired; |
| 3361 | } |
| 3362 | //get system time |
hualing chen | 7ea70a7 | 2021-09-09 11:25:13 +0800 | [diff] [blame] | 3363 | cur_time = _dvr_getClock_sec(); |
| 3364 | if ((cur_time - player->rec_start) > player->limit) { |
| 3365 | tmp_time = (uint32_t)((cur_time - player->rec_start) - player->limit) * 1000U; |
| 3366 | expired = *(int*)&tmp_time; |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 3367 | DVR_PB_INFO("cur_time:%u, rec start:%u limit:%d c_r_diff:%u expired:%u tmp_time:%u", |
hualing chen | 03fd494 | 2021-07-15 15:56:41 +0800 | [diff] [blame] | 3368 | cur_time, |
| 3369 | player->rec_start, |
| 3370 | player->limit, |
hualing chen | 7ea70a7 | 2021-09-09 11:25:13 +0800 | [diff] [blame] | 3371 | (uint32_t)(cur_time - player->rec_start - player->limit), expired, tmp_time); |
| 3372 | } |
hualing chen | 03fd494 | 2021-07-15 15:56:41 +0800 | [diff] [blame] | 3373 | return expired; |
| 3374 | } |
| 3375 | |
| 3376 | /**\brief set DVR playback obsolete time |
| 3377 | * \param[in] handle, DVR playback session handle |
| 3378 | * \param[in] obsolete, obsolete len |
| 3379 | * \return DVR_SUCCESS on success |
| 3380 | * \return error code on failure |
| 3381 | */ |
| 3382 | int dvr_playback_set_obsolete(DVR_PlaybackHandle_t handle, int obsolete) |
| 3383 | { |
| 3384 | int expired = 0; |
| 3385 | //calculate expired time to play |
| 3386 | DVR_Playback_t *player = (DVR_Playback_t *) handle; |
| 3387 | |
| 3388 | if (player == NULL) { |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 3389 | DVR_PB_INFO("player is NULL"); |
hualing chen | 03fd494 | 2021-07-15 15:56:41 +0800 | [diff] [blame] | 3390 | return DVR_FALSE; |
| 3391 | } |
| 3392 | //get system time |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 3393 | DVR_PB_DEBUG("lock ---\r\n"); |
Zhiqiang Han | f9c0e27 | 2022-06-14 13:54:03 +0800 | [diff] [blame] | 3394 | dvr_mutex_lock(&player->lock); |
hualing chen | 03fd494 | 2021-07-15 15:56:41 +0800 | [diff] [blame] | 3395 | player->obsolete = obsolete; |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 3396 | DVR_PB_DEBUG("unlock ---\r\n"); |
Zhiqiang Han | f9c0e27 | 2022-06-14 13:54:03 +0800 | [diff] [blame] | 3397 | dvr_mutex_unlock(&player->lock); |
hualing chen | 03fd494 | 2021-07-15 15:56:41 +0800 | [diff] [blame] | 3398 | return expired; |
| 3399 | } |
| 3400 | |
| 3401 | /**\brief update DVR playback newest segment duration |
| 3402 | * \param[in] handle, DVR playback session handle |
| 3403 | * \param[in] segmentid, newest segment id |
| 3404 | * \param[in] dur dur time ms |
| 3405 | * \return DVR_SUCCESS on success |
| 3406 | * \return error code on failure |
| 3407 | */ |
| 3408 | int dvr_playback_update_duration(DVR_PlaybackHandle_t handle, |
| 3409 | uint64_t segmentid, int dur) |
| 3410 | { |
| 3411 | DVR_Playback_t *player = (DVR_Playback_t *) handle; |
| 3412 | DVR_PlaybackSegmentInfo_t *segment; |
| 3413 | DVR_PlaybackSegmentInfo_t *pre_segment = NULL; |
| 3414 | |
| 3415 | if (player == NULL) { |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 3416 | DVR_PB_INFO(" player is NULL"); |
hualing chen | 03fd494 | 2021-07-15 15:56:41 +0800 | [diff] [blame] | 3417 | return DVR_FAILURE; |
| 3418 | } |
| 3419 | //update the newest segment duration on timeshift mode |
wentao.ma | fd5283f | 2022-10-14 09:51:13 +0800 | [diff] [blame] | 3420 | // This error is suppressed as the macro code is picked from kernel. |
wentao.ma | a22bc85 | 2022-10-13 12:18:06 +0800 | [diff] [blame] | 3421 | // prefetch() here incurring self_assign is used to avoid some compiling |
| 3422 | // warnings. |
| 3423 | // coverity[self_assign] |
hualing chen | 03fd494 | 2021-07-15 15:56:41 +0800 | [diff] [blame] | 3424 | list_for_each_entry(segment, &player->segment_list, head) |
| 3425 | { |
| 3426 | if (segment->segment_id == segmentid) { |
| 3427 | segment->duration = dur; |
| 3428 | break; |
| 3429 | } |
| 3430 | pre_segment = segment; |
| 3431 | } |
| 3432 | |
| 3433 | return DVR_SUCCESS; |
| 3434 | } |
| 3435 | |
hualing chen | 7ea70a7 | 2021-09-09 11:25:13 +0800 | [diff] [blame] | 3436 | static uint32_t dvr_playback_calculate_last_valid_segment( |
| 3437 | DVR_PlaybackHandle_t handle, uint64_t *segmentid, uint32_t *pos) |
hualing chen | 03fd494 | 2021-07-15 15:56:41 +0800 | [diff] [blame] | 3438 | { |
hualing chen | 7ea70a7 | 2021-09-09 11:25:13 +0800 | [diff] [blame] | 3439 | uint32_t off = 0; |
hualing chen | 03fd494 | 2021-07-15 15:56:41 +0800 | [diff] [blame] | 3440 | uint64_t segment_id = 0; |
hualing chen | 7ea70a7 | 2021-09-09 11:25:13 +0800 | [diff] [blame] | 3441 | uint32_t pre_off = 0; |
hualing chen | 03fd494 | 2021-07-15 15:56:41 +0800 | [diff] [blame] | 3442 | uint64_t last_segment_id = 0; |
hualing chen | 7ea70a7 | 2021-09-09 11:25:13 +0800 | [diff] [blame] | 3443 | uint32_t expired = 0; |
hualing chen | 03fd494 | 2021-07-15 15:56:41 +0800 | [diff] [blame] | 3444 | DVR_Playback_t *player = (DVR_Playback_t *) handle; |
| 3445 | |
| 3446 | if (player == NULL) { |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 3447 | DVR_PB_INFO("player is NULL"); |
hualing chen | 03fd494 | 2021-07-15 15:56:41 +0800 | [diff] [blame] | 3448 | return DVR_FAILURE; |
| 3449 | } |
| 3450 | expired = dvr_playback_calculate_expiredlen(handle); |
hualing chen | 7e14e53 | 2021-09-23 11:23:28 +0800 | [diff] [blame] | 3451 | if (expired == 0) { |
| 3452 | *segmentid = player->cur_segment_id; |
| 3453 | *pos = 0; |
| 3454 | return DVR_SUCCESS; |
| 3455 | } |
Wentao MA | 270dc0f | 2022-08-23 13:17:26 +0800 | [diff] [blame] | 3456 | DVR_PlaybackSegmentInfo_t *p_seg; |
wentao.ma | fd5283f | 2022-10-14 09:51:13 +0800 | [diff] [blame] | 3457 | // This error is suppressed as the macro code is picked from kernel. |
wentao.ma | a22bc85 | 2022-10-13 12:18:06 +0800 | [diff] [blame] | 3458 | // prefetch() here incurring self_assign is used to avoid some compiling |
| 3459 | // warnings. |
| 3460 | // coverity[self_assign] |
Wentao MA | 270dc0f | 2022-08-23 13:17:26 +0800 | [diff] [blame] | 3461 | list_for_each_entry_reverse(p_seg, &player->segment_list, head) { |
| 3462 | segment_id = p_seg->segment_id; |
hualing chen | 03fd494 | 2021-07-15 15:56:41 +0800 | [diff] [blame] | 3463 | |
Wentao MA | 270dc0f | 2022-08-23 13:17:26 +0800 | [diff] [blame] | 3464 | if ((player->obsolete + pre_off + p_seg->duration) > expired) |
hualing chen | 03fd494 | 2021-07-15 15:56:41 +0800 | [diff] [blame] | 3465 | break; |
| 3466 | |
Wentao MA | 270dc0f | 2022-08-23 13:17:26 +0800 | [diff] [blame] | 3467 | last_segment_id = p_seg->segment_id; |
| 3468 | pre_off += p_seg->duration; |
hualing chen | 03fd494 | 2021-07-15 15:56:41 +0800 | [diff] [blame] | 3469 | } |
| 3470 | |
| 3471 | if (last_segment_id == segment_id) { |
| 3472 | /*1.only one seg with id:0, 2.offset exceeds the total duration*/ |
| 3473 | off = expired; |
| 3474 | } else if (player->obsolete >= expired) { |
| 3475 | off = 0; |
| 3476 | } else { |
| 3477 | off = expired - pre_off - player->obsolete; |
| 3478 | } |
| 3479 | *segmentid = segment_id; |
| 3480 | *pos = off; |
| 3481 | return DVR_SUCCESS; |
| 3482 | } |
| 3483 | |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 3484 | #define FB_MIX_SEEK_TIME 2000 |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 3485 | //start replay |
| 3486 | static int _dvr_playback_calculate_seekpos(DVR_PlaybackHandle_t handle) { |
| 3487 | |
| 3488 | DVR_Playback_t *player = (DVR_Playback_t *) handle; |
| 3489 | //calculate pcr seek time |
| 3490 | int t_diff = 0; |
| 3491 | int seek_time = 0; |
hualing chen | 03fd494 | 2021-07-15 15:56:41 +0800 | [diff] [blame] | 3492 | uint64_t segmentid = 0; |
| 3493 | int pos = 0; |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 3494 | if (player == NULL) { |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 3495 | DVR_PB_INFO("player is NULL"); |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 3496 | return DVR_FAILURE; |
| 3497 | } |
| 3498 | |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 3499 | if (player->fffb_start == -1) { |
| 3500 | //set fffb start time ms |
| 3501 | player->fffb_start = _dvr_time_getClock(); |
| 3502 | player->fffb_current = player->fffb_start; |
| 3503 | //get segment current time pos |
| 3504 | player->fffb_start_pcr = _dvr_get_cur_time(handle); |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 3505 | DVR_PB_INFO("calculate seek pos player->fffb_start_pcr[%d]ms, speed[%f]", |
hualing chen | 03fd494 | 2021-07-15 15:56:41 +0800 | [diff] [blame] | 3506 | player->fffb_start_pcr, player->speed); |
hualing chen | e41f437 | 2020-06-06 16:29:17 +0800 | [diff] [blame] | 3507 | //default first time 2s seek |
hualing chen | 87072a8 | 2020-03-12 16:20:12 +0800 | [diff] [blame] | 3508 | seek_time = FB_MIX_SEEK_TIME; |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 3509 | } else { |
| 3510 | player->fffb_current = _dvr_time_getClock(); |
| 3511 | t_diff = player->fffb_current - player->fffb_start; |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 3512 | //if speed is < 0, cmd is fb. |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 3513 | seek_time = player->fffb_start_pcr + t_diff *player->speed; |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 3514 | if (seek_time <= 0) { |
| 3515 | //need seek to pre one segment |
| 3516 | seek_time = 0; |
| 3517 | } |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 3518 | //seek segment pos |
Wentao MA | f35c388 | 2023-04-17 12:36:19 +0800 | [diff] [blame] | 3519 | if (player->segment_handle) { |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 3520 | pthread_mutex_lock(&player->segment_lock); |
hualing chen | 5605eed | 2020-05-26 18:18:06 +0800 | [diff] [blame] | 3521 | player->ts_cache_len = 0; |
hualing chen | e41f437 | 2020-06-06 16:29:17 +0800 | [diff] [blame] | 3522 | if (seek_time < FB_MIX_SEEK_TIME && IS_FB(player->speed)) { |
| 3523 | //set seek time to 0; |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 3524 | DVR_PB_INFO("segment seek to 0 at fb mode [%d]id[%lld]", |
hualing chen | 03fd494 | 2021-07-15 15:56:41 +0800 | [diff] [blame] | 3525 | seek_time, |
| 3526 | player->cur_segment_id); |
hualing chen | e41f437 | 2020-06-06 16:29:17 +0800 | [diff] [blame] | 3527 | seek_time = 0; |
| 3528 | } |
hualing chen | 03fd494 | 2021-07-15 15:56:41 +0800 | [diff] [blame] | 3529 | if (IS_FB(player->speed) |
| 3530 | && dvr_playback_check_limit(handle)) { |
| 3531 | //fb case.check expired time |
| 3532 | //get id and pos to check if we can seek to this pos |
| 3533 | dvr_playback_calculate_last_valid_segment(handle, &segmentid, &pos); |
| 3534 | //case cur id < segment id |
| 3535 | if (player->cur_segment_id < segmentid) { |
| 3536 | //expired ts data is player,return error |
| 3537 | // |
| 3538 | pthread_mutex_unlock(&player->segment_lock); |
| 3539 | return 0; |
| 3540 | } else if (player->cur_segment_id == segmentid) { |
| 3541 | //id is same,compare seek pos |
| 3542 | if (seek_time < pos) { |
| 3543 | //expired ts data is player,return error |
| 3544 | // |
| 3545 | pthread_mutex_unlock(&player->segment_lock); |
| 3546 | return 0; |
| 3547 | } |
| 3548 | } |
| 3549 | //case can play |
| 3550 | } |
Wentao MA | f35c388 | 2023-04-17 12:36:19 +0800 | [diff] [blame] | 3551 | if (segment_seek(player->segment_handle, seek_time, player->openParams.block_size) == DVR_FAILURE) { |
hualing chen | 041c409 | 2020-04-05 15:11:50 +0800 | [diff] [blame] | 3552 | seek_time = 0; |
| 3553 | } |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 3554 | pthread_mutex_unlock(&player->segment_lock); |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 3555 | } else { |
| 3556 | // |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 3557 | DVR_PB_INFO("segment not open,can not seek"); |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 3558 | } |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 3559 | DVR_PB_INFO("calculate seek pos seek_time[%d]ms, speed[%f]id[%lld]cur [%d]", |
hualing chen | 03fd494 | 2021-07-15 15:56:41 +0800 | [diff] [blame] | 3560 | seek_time, |
| 3561 | player->speed, |
| 3562 | player->cur_segment_id, |
| 3563 | _dvr_get_cur_time(handle)); |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 3564 | } |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 3565 | return seek_time; |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 3566 | } |
| 3567 | |
| 3568 | |
| 3569 | //start replay |
| 3570 | static int _dvr_playback_fffb_replay(DVR_PlaybackHandle_t handle) { |
| 3571 | // |
| 3572 | DVR_Playback_t *player = (DVR_Playback_t *) handle; |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 3573 | |
| 3574 | if (player == NULL) { |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 3575 | DVR_PB_INFO("player is NULL"); |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 3576 | return DVR_FAILURE; |
| 3577 | } |
| 3578 | |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 3579 | //stop |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 3580 | if (player->has_video) { |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 3581 | DVR_PB_INFO("fffb stop video"); |
hualing chen | 21a4037 | 2021-10-29 11:07:26 +0800 | [diff] [blame] | 3582 | AmTsPlayer_setVideoBlackOut(player->handle, 0); |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 3583 | AmTsPlayer_stopVideoDecoding(player->handle); |
| 3584 | } |
| 3585 | if (player->has_audio) { |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 3586 | DVR_PB_INFO("fffb stop audio"); |
hualing chen | 266b950 | 2020-04-04 17:39:39 +0800 | [diff] [blame] | 3587 | player->has_audio =DVR_FALSE; |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 3588 | AmTsPlayer_stopAudioDecoding(player->handle); |
| 3589 | } |
hualing chen | df118dd | 2020-05-21 15:49:11 +0800 | [diff] [blame] | 3590 | if (player->has_ad_audio) { |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 3591 | DVR_PB_INFO("fffb stop audio"); |
hualing chen | df118dd | 2020-05-21 15:49:11 +0800 | [diff] [blame] | 3592 | player->has_ad_audio =DVR_FALSE; |
| 3593 | AmTsPlayer_disableADMix(player->handle); |
| 3594 | } |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 3595 | |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 3596 | //start video and audio |
| 3597 | |
Wentao MA | 270dc0f | 2022-08-23 13:17:26 +0800 | [diff] [blame] | 3598 | am_tsplayer_video_params video_params; |
| 3599 | am_tsplayer_audio_params audio_params; |
| 3600 | am_tsplayer_audio_params ad_params; |
jiangfei.han | b8fbad4 | 2021-07-29 15:04:48 +0800 | [diff] [blame] | 3601 | |
Wentao MA | 270dc0f | 2022-08-23 13:17:26 +0800 | [diff] [blame] | 3602 | memset(&video_params, 0, sizeof(video_params)); |
| 3603 | memset(&audio_params, 0, sizeof(audio_params)); |
jiangfei.han | b8fbad4 | 2021-07-29 15:04:48 +0800 | [diff] [blame] | 3604 | |
hualing chen | 87072a8 | 2020-03-12 16:20:12 +0800 | [diff] [blame] | 3605 | uint64_t segment_id = player->cur_segment_id; |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 3606 | |
| 3607 | //get segment info and audio video pid fmt ; |
Zhiqiang Han | f9c0e27 | 2022-06-14 13:54:03 +0800 | [diff] [blame] | 3608 | //dvr_mutex_lock(&player->lock); |
Wentao MA | 270dc0f | 2022-08-23 13:17:26 +0800 | [diff] [blame] | 3609 | _dvr_playback_get_playinfo(handle, segment_id, &video_params, &audio_params, &ad_params); |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 3610 | //start audio and video |
Wentao MA | 270dc0f | 2022-08-23 13:17:26 +0800 | [diff] [blame] | 3611 | if (!VALID_PID(video_params.pid) && !VALID_PID(audio_params.pid)) { |
| 3612 | //audio and video pids are all invalid, return error. |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 3613 | DVR_PB_ERROR("dvr play back restart error, not found audio and video info"); |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 3614 | return -1; |
| 3615 | } |
| 3616 | |
Wentao MA | 270dc0f | 2022-08-23 13:17:26 +0800 | [diff] [blame] | 3617 | if (VALID_PID(video_params.pid)) { |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 3618 | player->has_video = DVR_TRUE; |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 3619 | DVR_PB_INFO("fffb start video"); |
| 3620 | //DVR_PB_INFO("fffb start video and save last frame"); |
hualing chen | 0888c03 | 2020-12-18 17:54:57 +0800 | [diff] [blame] | 3621 | //AmTsPlayer_setVideoBlackOut(player->handle, 0); |
hualing chen | 3114087 | 2020-03-25 12:29:26 +0800 | [diff] [blame] | 3622 | AmTsPlayer_setTrickMode(player->handle, AV_VIDEO_TRICK_MODE_NONE); |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 3623 | AmTsPlayer_setTrickMode(player->handle, AV_VIDEO_TRICK_MODE_PAUSE_NEXT); |
Wentao MA | 270dc0f | 2022-08-23 13:17:26 +0800 | [diff] [blame] | 3624 | AmTsPlayer_setVideoParams(player->handle, &video_params); |
hualing chen | 21a4037 | 2021-10-29 11:07:26 +0800 | [diff] [blame] | 3625 | AmTsPlayer_setVideoBlackOut(player->handle, 1); |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 3626 | AmTsPlayer_startVideoDecoding(player->handle); |
Wentao MA | 270dc0f | 2022-08-23 13:17:26 +0800 | [diff] [blame] | 3627 | //playback_device_video_start(player->handle , &video_params); |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 3628 | //if set flag is pause live, we need set trick mode |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 3629 | //playback_device_trick_mode(player->handle, 1); |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 3630 | } |
hualing chen | 3114087 | 2020-03-25 12:29:26 +0800 | [diff] [blame] | 3631 | //fffb mode need stop fast; |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 3632 | DVR_PB_INFO("stop fast"); |
hualing chen | 3114087 | 2020-03-25 12:29:26 +0800 | [diff] [blame] | 3633 | AmTsPlayer_stopFast(player->handle); |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 3634 | return 0; |
| 3635 | } |
| 3636 | |
| 3637 | static int _dvr_playback_fffb(DVR_PlaybackHandle_t handle) { |
| 3638 | DVR_Playback_t *player = (DVR_Playback_t *) handle; |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 3639 | if (player == NULL) { |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 3640 | DVR_PB_INFO("player is NULL"); |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 3641 | return DVR_FAILURE; |
| 3642 | } |
| 3643 | |
| 3644 | player->first_frame = 0; |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 3645 | DVR_PB_INFO("lock speed [%f]", player->speed); |
Zhiqiang Han | f9c0e27 | 2022-06-14 13:54:03 +0800 | [diff] [blame] | 3646 | dvr_mutex_lock(&player->lock); |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 3647 | |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 3648 | int seek_time = _dvr_playback_calculate_seekpos(handle); |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 3649 | DVR_PB_INFO("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] | 3650 | |
hualing chen | 87072a8 | 2020-03-12 16:20:12 +0800 | [diff] [blame] | 3651 | if (_dvr_has_next_segmentId(handle, player->cur_segment_id) == DVR_FAILURE && seek_time < FB_MIX_SEEK_TIME && IS_FB(player->speed)) { |
| 3652 | //seek time set 0 |
| 3653 | seek_time = 0; |
| 3654 | } |
hualing chen | 041c409 | 2020-04-05 15:11:50 +0800 | [diff] [blame] | 3655 | if (seek_time == 0) { |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 3656 | //for fb cmd, we need open pre segment.if reach first one segment, send begin event |
| 3657 | int ret = _change_to_next_segment((DVR_PlaybackHandle_t)player); |
hualing chen | 041c409 | 2020-04-05 15:11:50 +0800 | [diff] [blame] | 3658 | if (ret != DVR_SUCCESS && IS_FB(player->speed)) { |
wentao.ma | 4ee4302 | 2022-12-14 13:22:57 +0800 | [diff] [blame] | 3659 | |
| 3660 | // An fffb_replay is required here to help finish the last FB play |
| 3661 | // at beginning position of a recording. In addition to function |
| 3662 | // correctness, another benefit is that after play, demux buffer |
| 3663 | // is cleared due to stopVideoDecoding invocation in the process. |
| 3664 | // The following resume operation will not be affected by the invalid |
| 3665 | // cache length. |
| 3666 | player->next_fffb_time =_dvr_time_getClock() + FFFB_SLEEP_TIME; |
| 3667 | _dvr_playback_fffb_replay(handle); |
| 3668 | |
Zhiqiang Han | f9c0e27 | 2022-06-14 13:54:03 +0800 | [diff] [blame] | 3669 | dvr_mutex_unlock(&player->lock); |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 3670 | DVR_PB_DEBUG("unlock"); |
Wentao MA | 75775d2 | 2023-09-25 16:53:24 +0800 | [diff] [blame^] | 3671 | #ifdef FOR_SKYWORTH_FETCH_RDK |
| 3672 | DVR_PlaybackSpeed_t normal_speed = {PLAYBACK_SPEED_X1,0}; |
| 3673 | DVR_PB_INFO("Change to normal speed due to FB reaching beginning"); |
| 3674 | dvr_playback_set_speed((DVR_PlaybackHandle_t)player,normal_speed); |
| 3675 | #else |
hualing chen | 87072a8 | 2020-03-12 16:20:12 +0800 | [diff] [blame] | 3676 | dvr_playback_pause(handle, DVR_FALSE); |
Wentao MA | 75775d2 | 2023-09-25 16:53:24 +0800 | [diff] [blame^] | 3677 | #endif |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 3678 | //send event here and pause |
| 3679 | DVR_Play_Notify_t notify; |
| 3680 | memset(¬ify, 0 , sizeof(DVR_Play_Notify_t)); |
hualing chen | 87072a8 | 2020-03-12 16:20:12 +0800 | [diff] [blame] | 3681 | notify.event = DVR_PLAYBACK_EVENT_REACHED_BEGIN; |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 3682 | //get play statue not here |
hualing chen | 2932d37 | 2020-04-29 13:44:00 +0800 | [diff] [blame] | 3683 | _dvr_playback_sent_event(handle, DVR_PLAYBACK_EVENT_REACHED_BEGIN, ¬ify, DVR_TRUE); |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 3684 | DVR_PB_INFO("*******************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] | 3685 | //change to pause |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 3686 | return DVR_SUCCESS; |
| 3687 | } |
hualing chen | 2932d37 | 2020-04-29 13:44:00 +0800 | [diff] [blame] | 3688 | _dvr_playback_sent_transition_ok(handle, DVR_FALSE); |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 3689 | _dvr_init_fffb_time(handle); |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 3690 | DVR_PB_INFO("*******************send trans ok event speed [%f]", player->speed); |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 3691 | } |
| 3692 | player->next_fffb_time =_dvr_time_getClock() + FFFB_SLEEP_TIME; |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 3693 | _dvr_playback_fffb_replay(handle); |
| 3694 | |
Zhiqiang Han | f9c0e27 | 2022-06-14 13:54:03 +0800 | [diff] [blame] | 3695 | dvr_mutex_unlock(&player->lock); |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 3696 | DVR_PB_DEBUG("unlock"); |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 3697 | |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 3698 | return DVR_SUCCESS; |
| 3699 | } |
| 3700 | |
hualing chen | 87072a8 | 2020-03-12 16:20:12 +0800 | [diff] [blame] | 3701 | //start replay, need get lock at extern |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 3702 | 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] | 3703 | // |
| 3704 | DVR_Playback_t *player = (DVR_Playback_t *) handle; |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 3705 | |
| 3706 | if (player == NULL) { |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 3707 | DVR_PB_INFO("player is NULL"); |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 3708 | return DVR_FAILURE; |
| 3709 | } |
| 3710 | |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 3711 | //stop |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 3712 | if (player->has_video) { |
hualing chen | 266b950 | 2020-04-04 17:39:39 +0800 | [diff] [blame] | 3713 | player->has_video = DVR_FALSE; |
hualing chen | 21a4037 | 2021-10-29 11:07:26 +0800 | [diff] [blame] | 3714 | AmTsPlayer_setVideoBlackOut(player->handle, 0); |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 3715 | AmTsPlayer_stopVideoDecoding(player->handle); |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 3716 | } |
| 3717 | |
| 3718 | if (player->has_audio) { |
hualing chen | 266b950 | 2020-04-04 17:39:39 +0800 | [diff] [blame] | 3719 | player->has_audio = DVR_FALSE; |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 3720 | AmTsPlayer_stopAudioDecoding(player->handle); |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 3721 | } |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 3722 | //start video and audio |
| 3723 | |
Wentao MA | 270dc0f | 2022-08-23 13:17:26 +0800 | [diff] [blame] | 3724 | am_tsplayer_video_params video_params; |
| 3725 | am_tsplayer_audio_params audio_params; |
| 3726 | am_tsplayer_audio_params ad_params; |
hualing chen | 87072a8 | 2020-03-12 16:20:12 +0800 | [diff] [blame] | 3727 | uint64_t segment_id = player->cur_segment_id; |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 3728 | |
Wentao MA | 270dc0f | 2022-08-23 13:17:26 +0800 | [diff] [blame] | 3729 | memset(&video_params, 0, sizeof(video_params)); |
| 3730 | memset(&audio_params, 0, sizeof(audio_params)); |
jiangfei.han | b8fbad4 | 2021-07-29 15:04:48 +0800 | [diff] [blame] | 3731 | |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 3732 | //get segment info and audio video pid fmt ; |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 3733 | DVR_PB_INFO("into"); |
Wentao MA | 270dc0f | 2022-08-23 13:17:26 +0800 | [diff] [blame] | 3734 | _dvr_playback_get_playinfo(handle, segment_id, &video_params, &audio_params, &ad_params); |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 3735 | //start audio and video |
Wentao MA | 270dc0f | 2022-08-23 13:17:26 +0800 | [diff] [blame] | 3736 | if (!VALID_PID(video_params.pid) && !VALID_PID(audio_params.pid)) { |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 3737 | //audio and video pis is all invalid, return error. |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 3738 | DVR_PB_ERROR("dvr play back restart error, not found audio and video info"); |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 3739 | return -1; |
| 3740 | } |
| 3741 | |
Wentao MA | 270dc0f | 2022-08-23 13:17:26 +0800 | [diff] [blame] | 3742 | if (VALID_PID(video_params.pid)) { |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 3743 | player->has_video = DVR_TRUE; |
hualing chen | 87072a8 | 2020-03-12 16:20:12 +0800 | [diff] [blame] | 3744 | if (trick == DVR_TRUE) { |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 3745 | DVR_PB_INFO("settrick mode at replay"); |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 3746 | AmTsPlayer_setTrickMode(player->handle, AV_VIDEO_TRICK_MODE_PAUSE_NEXT); |
hualing chen | 87072a8 | 2020-03-12 16:20:12 +0800 | [diff] [blame] | 3747 | } |
hualing chen | 266b950 | 2020-04-04 17:39:39 +0800 | [diff] [blame] | 3748 | else { |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 3749 | AmTsPlayer_setTrickMode(player->handle, AV_VIDEO_TRICK_MODE_NONE); |
hualing chen | 266b950 | 2020-04-04 17:39:39 +0800 | [diff] [blame] | 3750 | } |
Wentao MA | 270dc0f | 2022-08-23 13:17:26 +0800 | [diff] [blame] | 3751 | AmTsPlayer_setVideoParams(player->handle, &video_params); |
hualing chen | 21a4037 | 2021-10-29 11:07:26 +0800 | [diff] [blame] | 3752 | AmTsPlayer_setVideoBlackOut(player->handle, 1); |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 3753 | AmTsPlayer_startVideoDecoding(player->handle); |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 3754 | } |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 3755 | |
| 3756 | if (IS_FAST_SPEED(player->cmd.speed.speed.speed)) { |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 3757 | DVR_PB_INFO("start fast"); |
hualing chen | 3114087 | 2020-03-25 12:29:26 +0800 | [diff] [blame] | 3758 | AmTsPlayer_startFast(player->handle, (float)player->cmd.speed.speed.speed/(float)100); |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 3759 | player->speed = (float)player->cmd.speed.speed.speed/100.0f; |
hualing chen | 3114087 | 2020-03-25 12:29:26 +0800 | [diff] [blame] | 3760 | } else { |
Wentao MA | 270dc0f | 2022-08-23 13:17:26 +0800 | [diff] [blame] | 3761 | if (VALID_PID(ad_params.pid)) { |
hualing chen | df118dd | 2020-05-21 15:49:11 +0800 | [diff] [blame] | 3762 | player->has_ad_audio = DVR_TRUE; |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 3763 | DVR_PB_INFO("start ad audio"); |
Wentao MA | 270dc0f | 2022-08-23 13:17:26 +0800 | [diff] [blame] | 3764 | AmTsPlayer_setADParams(player->handle, &ad_params); |
hualing chen | df118dd | 2020-05-21 15:49:11 +0800 | [diff] [blame] | 3765 | AmTsPlayer_enableADMix(player->handle); |
| 3766 | } |
Wentao MA | 270dc0f | 2022-08-23 13:17:26 +0800 | [diff] [blame] | 3767 | if (VALID_PID(audio_params.pid)) { |
hualing chen | 969fe7b | 2021-05-26 15:13:17 +0800 | [diff] [blame] | 3768 | player->has_audio = DVR_TRUE; |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 3769 | DVR_PB_INFO("start audio"); |
Wentao MA | 270dc0f | 2022-08-23 13:17:26 +0800 | [diff] [blame] | 3770 | AmTsPlayer_setAudioParams(player->handle, &audio_params); |
Wentao MA | 5629ad8 | 2022-08-24 10:03:02 +0800 | [diff] [blame] | 3771 | if (player->audio_presentation_id > -1) { |
| 3772 | AmTsPlayer_setParams(player->handle, AM_TSPLAYER_KEY_AUDIO_PRESENTATION_ID, &player->audio_presentation_id); |
| 3773 | } |
hualing chen | 969fe7b | 2021-05-26 15:13:17 +0800 | [diff] [blame] | 3774 | AmTsPlayer_startAudioDecoding(player->handle); |
| 3775 | } |
hualing chen | df118dd | 2020-05-21 15:49:11 +0800 | [diff] [blame] | 3776 | |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 3777 | DVR_PB_INFO("stop fast"); |
hualing chen | 3114087 | 2020-03-25 12:29:26 +0800 | [diff] [blame] | 3778 | AmTsPlayer_stopFast(player->handle); |
| 3779 | player->cmd.speed.speed.speed = PLAYBACK_SPEED_X1; |
| 3780 | player->speed = (float)PLAYBACK_SPEED_X1/100.0f; |
| 3781 | } |
hualing chen | 43a89bc | 2022-01-19 14:31:20 +0800 | [diff] [blame] | 3782 | #ifdef AVSYNC_USED_PCR |
| 3783 | if (player && VALID_PID(player->cur_segment.pids.pcr.pid)) { |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 3784 | DVR_PB_INFO("start set pcr [%d]", player->cur_segment.pids.pcr.pid); |
hualing chen | 43a89bc | 2022-01-19 14:31:20 +0800 | [diff] [blame] | 3785 | AmTsPlayer_setPcrPid(player->handle, player->cur_segment.pids.pcr.pid); |
| 3786 | } |
| 3787 | #endif |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 3788 | player->cmd.last_cmd = player->cmd.cur_cmd; |
| 3789 | player->cmd.cur_cmd = DVR_PLAYBACK_CMD_START; |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 3790 | player->cmd.state = DVR_PLAYBACK_STATE_START; |
Wentao MA | 907b643 | 2022-08-01 06:23:08 +0000 | [diff] [blame] | 3791 | DVR_PLAYER_CHANGE_STATE(player,DVR_PLAYBACK_STATE_START); |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 3792 | return 0; |
| 3793 | } |
| 3794 | |
| 3795 | |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 3796 | /**\brief Set play speed |
| 3797 | * \param[in] handle playback handle |
| 3798 | * \param[in] speed playback speed |
| 3799 | * \retval DVR_SUCCESS On success |
| 3800 | * \return Error code |
| 3801 | */ |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 3802 | int dvr_playback_set_speed(DVR_PlaybackHandle_t handle, DVR_PlaybackSpeed_t speed) { |
| 3803 | |
| 3804 | DVR_Playback_t *player = (DVR_Playback_t *) handle; |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 3805 | |
| 3806 | if (player == NULL) { |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 3807 | DVR_PB_INFO("player is NULL"); |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 3808 | return DVR_FAILURE; |
| 3809 | } |
| 3810 | |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 3811 | if (_dvr_support_speed(speed.speed.speed) == DVR_FALSE) { |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 3812 | DVR_PB_INFO(" func: not support speed [%d]", speed.speed.speed); |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 3813 | return DVR_FAILURE; |
| 3814 | } |
hualing chen | f00cdc8 | 2020-06-10 14:23:35 +0800 | [diff] [blame] | 3815 | if (speed.speed.speed == player->cmd.speed.speed.speed) { |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 3816 | DVR_PB_INFO(" func: eq speed [%d]", speed.speed.speed); |
hualing chen | f00cdc8 | 2020-06-10 14:23:35 +0800 | [diff] [blame] | 3817 | return DVR_SUCCESS; |
| 3818 | } |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 3819 | DVR_PB_INFO("lock func: speed [%d]", speed.speed.speed); |
hualing chen | 1679f81 | 2021-11-08 15:17:46 +0800 | [diff] [blame] | 3820 | |
Zhiqiang Han | f9c0e27 | 2022-06-14 13:54:03 +0800 | [diff] [blame] | 3821 | dvr_mutex_lock(&player->lock); |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 3822 | if (player->cmd.cur_cmd != DVR_PLAYBACK_CMD_FF |
| 3823 | && player->cmd.cur_cmd != DVR_PLAYBACK_CMD_FB) { |
| 3824 | player->cmd.last_cmd = player->cmd.cur_cmd; |
| 3825 | } |
hualing chen | e41f437 | 2020-06-06 16:29:17 +0800 | [diff] [blame] | 3826 | |
hualing chen | 3114087 | 2020-03-25 12:29:26 +0800 | [diff] [blame] | 3827 | if (player->state != DVR_PLAYBACK_STATE_PAUSE && |
hualing chen | f00cdc8 | 2020-06-10 14:23:35 +0800 | [diff] [blame] | 3828 | IS_KERNEL_SPEED(speed.speed.speed) ) { |
| 3829 | //case 1. not start play.only set speed |
| 3830 | if (player->state == DVR_PLAYBACK_STATE_STOP) { |
| 3831 | //only set speed.and return; |
| 3832 | player->cmd.speed.mode = DVR_PLAYBACK_KERNEL_SUPPORT; |
| 3833 | player->cmd.speed.speed = speed.speed; |
| 3834 | player->speed = (float)speed.speed.speed/(float)100; |
| 3835 | player->fffb_play = DVR_FALSE; |
Zhiqiang Han | f9c0e27 | 2022-06-14 13:54:03 +0800 | [diff] [blame] | 3836 | dvr_mutex_unlock(&player->lock); |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 3837 | DVR_PB_DEBUG("unlock"); |
hualing chen | f00cdc8 | 2020-06-10 14:23:35 +0800 | [diff] [blame] | 3838 | return DVR_SUCCESS; |
| 3839 | } |
| 3840 | //case 2. cur speed is 100,set 200 50 25 12 . |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 3841 | //we think x1 and x2 s1/2 s 1/4 s 1/8 is normal speed. is not ff fb. |
| 3842 | if (IS_KERNEL_SPEED(player->cmd.speed.speed.speed)) { |
hualing chen | 87072a8 | 2020-03-12 16:20:12 +0800 | [diff] [blame] | 3843 | //if last speed is x2 or s2, we need stop fast |
hualing chen | 2bd8a7a | 2020-04-02 11:31:03 +0800 | [diff] [blame] | 3844 | if (speed.speed.speed == PLAYBACK_SPEED_X1) { |
| 3845 | // resume audio and stop fast play |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 3846 | DVR_PB_INFO("stop fast"); |
hualing chen | 2bd8a7a | 2020-04-02 11:31:03 +0800 | [diff] [blame] | 3847 | AmTsPlayer_stopFast(player->handle); |
Zhiqiang Han | f9c0e27 | 2022-06-14 13:54:03 +0800 | [diff] [blame] | 3848 | dvr_mutex_unlock(&player->lock); |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 3849 | DVR_PB_DEBUG("unlock ---\r\n"); |
Wentao MA | 270dc0f | 2022-08-23 13:17:26 +0800 | [diff] [blame] | 3850 | _dvr_cmd(handle, DVR_PLAYBACK_CMD_A_START); |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 3851 | DVR_PB_DEBUG("lock ---\r\n"); |
Zhiqiang Han | f9c0e27 | 2022-06-14 13:54:03 +0800 | [diff] [blame] | 3852 | dvr_mutex_lock(&player->lock); |
hualing chen | 2bd8a7a | 2020-04-02 11:31:03 +0800 | [diff] [blame] | 3853 | } else { |
| 3854 | //set play speed and if audio is start, stop audio. |
| 3855 | if (player->has_audio) { |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 3856 | DVR_PB_INFO("fast play stop audio"); |
hualing chen | 2bd8a7a | 2020-04-02 11:31:03 +0800 | [diff] [blame] | 3857 | AmTsPlayer_stopAudioDecoding(player->handle); |
| 3858 | player->has_audio = DVR_FALSE; |
| 3859 | } |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 3860 | DVR_PB_INFO("start fast"); |
hualing chen | 2bd8a7a | 2020-04-02 11:31:03 +0800 | [diff] [blame] | 3861 | AmTsPlayer_startFast(player->handle, (float)speed.speed.speed/(float)100); |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 3862 | } |
hualing chen | bcada02 | 2020-04-22 14:27:01 +0800 | [diff] [blame] | 3863 | player->fffb_play = DVR_FALSE; |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 3864 | player->cmd.speed.mode = DVR_PLAYBACK_KERNEL_SUPPORT; |
hualing chen | 3114087 | 2020-03-25 12:29:26 +0800 | [diff] [blame] | 3865 | player->cmd.speed.speed = speed.speed; |
| 3866 | player->speed = (float)speed.speed.speed/(float)100; |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 3867 | DVR_PB_DEBUG("unlock ---\r\n"); |
Zhiqiang Han | f9c0e27 | 2022-06-14 13:54:03 +0800 | [diff] [blame] | 3868 | dvr_mutex_unlock(&player->lock); |
hualing chen | 3114087 | 2020-03-25 12:29:26 +0800 | [diff] [blame] | 3869 | return DVR_SUCCESS; |
| 3870 | } |
hualing chen | 3114087 | 2020-03-25 12:29:26 +0800 | [diff] [blame] | 3871 | //case 3 fffb mode |
| 3872 | if (player->cmd.cur_cmd == DVR_PLAYBACK_CMD_FF || |
| 3873 | player->cmd.cur_cmd == DVR_PLAYBACK_CMD_FB) { |
| 3874 | //restart play at normal speed exit ff fb |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 3875 | DVR_PB_INFO("set speed normal and replay playback"); |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 3876 | player->cmd.speed.mode = DVR_PLAYBACK_KERNEL_SUPPORT; |
hualing chen | 3114087 | 2020-03-25 12:29:26 +0800 | [diff] [blame] | 3877 | player->cmd.speed.speed = speed.speed; |
| 3878 | player->speed = (float)speed.speed.speed/(float)100; |
| 3879 | _dvr_playback_replay(handle, DVR_FALSE); |
hualing chen | bcada02 | 2020-04-22 14:27:01 +0800 | [diff] [blame] | 3880 | player->fffb_play = DVR_FALSE; |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 3881 | DVR_PB_DEBUG("unlock ---\r\n"); |
Zhiqiang Han | f9c0e27 | 2022-06-14 13:54:03 +0800 | [diff] [blame] | 3882 | dvr_mutex_unlock(&player->lock); |
hualing chen | 3114087 | 2020-03-25 12:29:26 +0800 | [diff] [blame] | 3883 | return DVR_SUCCESS; |
| 3884 | } |
| 3885 | } |
| 3886 | else if (player->state == DVR_PLAYBACK_STATE_PAUSE && |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 3887 | IS_KERNEL_SPEED(speed.speed.speed)) { |
| 3888 | //case 1. cur speed is kernel support speed,set kernel speed. |
| 3889 | if (IS_KERNEL_SPEED(player->cmd.speed.speed.speed)) { |
hualing chen | 3114087 | 2020-03-25 12:29:26 +0800 | [diff] [blame] | 3890 | //if last speed is x2 or s2, we need stop fast |
hualing chen | 2bd8a7a | 2020-04-02 11:31:03 +0800 | [diff] [blame] | 3891 | if (speed.speed.speed == PLAYBACK_SPEED_X1) { |
| 3892 | // resume audio and stop fast play |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 3893 | DVR_PB_INFO("stop fast"); |
hualing chen | 2bd8a7a | 2020-04-02 11:31:03 +0800 | [diff] [blame] | 3894 | AmTsPlayer_stopFast(player->handle); |
Wentao MA | 270dc0f | 2022-08-23 13:17:26 +0800 | [diff] [blame] | 3895 | player->cmd.cur_cmd = DVR_PLAYBACK_CMD_A_START; |
hualing chen | 2bd8a7a | 2020-04-02 11:31:03 +0800 | [diff] [blame] | 3896 | } else { |
| 3897 | //set play speed and if audio is start, stop audio. |
| 3898 | if (player->has_audio) { |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 3899 | DVR_PB_INFO("fast play stop audio at pause"); |
hualing chen | 2bd8a7a | 2020-04-02 11:31:03 +0800 | [diff] [blame] | 3900 | AmTsPlayer_stopAudioDecoding(player->handle); |
| 3901 | player->has_audio = DVR_FALSE; |
| 3902 | } |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 3903 | DVR_PB_INFO("start fast"); |
hualing chen | f00cdc8 | 2020-06-10 14:23:35 +0800 | [diff] [blame] | 3904 | AmTsPlayer_startFast(player->handle, (float)speed.speed.speed/(float)100); |
hualing chen | 2bd8a7a | 2020-04-02 11:31:03 +0800 | [diff] [blame] | 3905 | } |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 3906 | player->cmd.speed.mode = DVR_PLAYBACK_KERNEL_SUPPORT; |
hualing chen | 3114087 | 2020-03-25 12:29:26 +0800 | [diff] [blame] | 3907 | player->cmd.speed.speed = speed.speed; |
| 3908 | player->speed = (float)speed.speed.speed/(float)100; |
hualing chen | bcada02 | 2020-04-22 14:27:01 +0800 | [diff] [blame] | 3909 | player->fffb_play = DVR_FALSE; |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 3910 | DVR_PB_DEBUG("unlock ---\r\n"); |
Zhiqiang Han | f9c0e27 | 2022-06-14 13:54:03 +0800 | [diff] [blame] | 3911 | dvr_mutex_unlock(&player->lock); |
hualing chen | 3114087 | 2020-03-25 12:29:26 +0800 | [diff] [blame] | 3912 | return DVR_SUCCESS; |
| 3913 | } |
| 3914 | //case 2 fffb mode |
| 3915 | if (player->cmd.cur_cmd == DVR_PLAYBACK_CMD_FF || |
| 3916 | player->cmd.cur_cmd == DVR_PLAYBACK_CMD_FB) { |
| 3917 | //restart play at normal speed exit ff fb |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 3918 | DVR_PB_INFO("set speed x1 s2 and replay playback"); |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 3919 | player->cmd.speed.mode = DVR_PLAYBACK_KERNEL_SUPPORT; |
hualing chen | 3114087 | 2020-03-25 12:29:26 +0800 | [diff] [blame] | 3920 | player->cmd.speed.speed = speed.speed; |
| 3921 | player->speed = (float)speed.speed.speed/(float)100; |
Wentao MA | 270dc0f | 2022-08-23 13:17:26 +0800 | [diff] [blame] | 3922 | player->cmd.cur_cmd = DVR_PLAYBACK_CMD_AV_RESTART; |
hualing chen | bcada02 | 2020-04-22 14:27:01 +0800 | [diff] [blame] | 3923 | player->fffb_play = DVR_FALSE; |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 3924 | DVR_PB_DEBUG("unlock ---\r\n"); |
Zhiqiang Han | f9c0e27 | 2022-06-14 13:54:03 +0800 | [diff] [blame] | 3925 | dvr_mutex_unlock(&player->lock); |
hualing chen | 3114087 | 2020-03-25 12:29:26 +0800 | [diff] [blame] | 3926 | return DVR_SUCCESS; |
| 3927 | } |
hualing chen | 3114087 | 2020-03-25 12:29:26 +0800 | [diff] [blame] | 3928 | } |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 3929 | if (IS_KERNEL_SPEED(speed.speed.speed)) { |
| 3930 | //we think x1 and s2 s4 s8 x2is normal speed. is not ff fb. |
hualing chen | bcada02 | 2020-04-22 14:27:01 +0800 | [diff] [blame] | 3931 | player->fffb_play = DVR_FALSE; |
hualing chen | 87072a8 | 2020-03-12 16:20:12 +0800 | [diff] [blame] | 3932 | } else { |
hualing chen | 3114087 | 2020-03-25 12:29:26 +0800 | [diff] [blame] | 3933 | if ((float)speed.speed.speed > 1.0f) |
hualing chen | 87072a8 | 2020-03-12 16:20:12 +0800 | [diff] [blame] | 3934 | player->cmd.cur_cmd = DVR_PLAYBACK_CMD_FF; |
| 3935 | else |
| 3936 | player->cmd.cur_cmd = DVR_PLAYBACK_CMD_FB; |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 3937 | player->fffb_play = DVR_TRUE; |
| 3938 | } |
| 3939 | DVR_Bool_t init_last_time = DVR_FALSE; |
| 3940 | if (player->speed > 0.0f && speed.speed.speed < 0) { |
| 3941 | init_last_time = DVR_TRUE; |
| 3942 | } else if (player->speed < 0.0f && speed.speed.speed > 0) { |
| 3943 | init_last_time = DVR_TRUE; |
hualing chen | 87072a8 | 2020-03-12 16:20:12 +0800 | [diff] [blame] | 3944 | } |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 3945 | player->cmd.speed.mode = speed.mode; |
| 3946 | player->cmd.speed.speed = speed.speed; |
hualing chen | 3114087 | 2020-03-25 12:29:26 +0800 | [diff] [blame] | 3947 | player->speed = (float)speed.speed.speed/(float)100; |
| 3948 | //reset fffb time, if change speed value |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 3949 | _dvr_init_fffb_t(handle); |
| 3950 | if (init_last_time == DVR_TRUE) |
| 3951 | player->last_send_time_id = UINT64_MAX; |
| 3952 | |
hualing chen | 87072a8 | 2020-03-12 16:20:12 +0800 | [diff] [blame] | 3953 | if (speed.speed.speed == PLAYBACK_SPEED_X1 && |
hualing chen | 6d24aa9 | 2020-03-23 18:43:47 +0800 | [diff] [blame] | 3954 | (player->cmd.cur_cmd == DVR_PLAYBACK_CMD_FF || |
| 3955 | player->cmd.cur_cmd == DVR_PLAYBACK_CMD_FB)) { |
hualing chen | 87072a8 | 2020-03-12 16:20:12 +0800 | [diff] [blame] | 3956 | //restart play at normal speed exit ff fb |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 3957 | DVR_PB_INFO("set speed normal and replay playback"); |
hualing chen | 87072a8 | 2020-03-12 16:20:12 +0800 | [diff] [blame] | 3958 | _dvr_playback_replay(handle, DVR_FALSE); |
| 3959 | } else if (speed.speed.speed == PLAYBACK_SPEED_X1 && |
| 3960 | (player->state == DVR_PLAYBACK_STATE_PAUSE)) { |
Wentao MA | 270dc0f | 2022-08-23 13:17:26 +0800 | [diff] [blame] | 3961 | player->cmd.cur_cmd = DVR_PLAYBACK_CMD_AV_RESTART; |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 3962 | DVR_PB_INFO("set speed normal at pause state ,set cur cmd"); |
hualing chen | 87072a8 | 2020-03-12 16:20:12 +0800 | [diff] [blame] | 3963 | } |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 3964 | DVR_PB_INFO("unlock speed[%f]cmd[%d]", player->speed, player->cmd.cur_cmd); |
Zhiqiang Han | f9c0e27 | 2022-06-14 13:54:03 +0800 | [diff] [blame] | 3965 | dvr_mutex_unlock(&player->lock); |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 3966 | return DVR_SUCCESS; |
| 3967 | } |
hualing chen | 2932d37 | 2020-04-29 13:44:00 +0800 | [diff] [blame] | 3968 | |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 3969 | /**\brief Get playback status |
| 3970 | * \param[in] handle playback handle |
| 3971 | * \param[out] p_status playback status |
| 3972 | * \retval DVR_SUCCESS On success |
| 3973 | * \return Error code |
| 3974 | */ |
hualing chen | 2932d37 | 2020-04-29 13:44:00 +0800 | [diff] [blame] | 3975 | static int _dvr_playback_get_status(DVR_PlaybackHandle_t handle, |
| 3976 | DVR_PlaybackStatus_t *p_status, DVR_Bool_t is_lock) { |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 3977 | // |
| 3978 | DVR_Playback_t *player = (DVR_Playback_t *) handle; |
hualing chen | 969fe7b | 2021-05-26 15:13:17 +0800 | [diff] [blame] | 3979 | uint64_t segment_id = 0LL; |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 3980 | if (player == NULL) { |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 3981 | DVR_PB_INFO("player is NULL"); |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 3982 | return DVR_FAILURE; |
| 3983 | } |
hualing chen | 1679f81 | 2021-11-08 15:17:46 +0800 | [diff] [blame] | 3984 | if (is_lock ==DVR_TRUE) { |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 3985 | DVR_PB_DEBUG("lock"); |
Zhiqiang Han | f9c0e27 | 2022-06-14 13:54:03 +0800 | [diff] [blame] | 3986 | dvr_mutex_lock(&player->lock); |
hualing chen | 1679f81 | 2021-11-08 15:17:46 +0800 | [diff] [blame] | 3987 | } |
| 3988 | |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 3989 | p_status->state = player->state; |
hualing chen | 3114087 | 2020-03-25 12:29:26 +0800 | [diff] [blame] | 3990 | //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] | 3991 | if ((player->play_flag&DVR_PLAYBACK_STARTED_PAUSEDLIVE) == DVR_PLAYBACK_STARTED_PAUSEDLIVE && |
| 3992 | player->state == DVR_PLAYBACK_STATE_START) { |
| 3993 | p_status->state = DVR_PLAYBACK_STATE_PAUSE; |
| 3994 | } |
hualing chen | 041c409 | 2020-04-05 15:11:50 +0800 | [diff] [blame] | 3995 | |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame] | 3996 | p_status->time_end = _dvr_get_end_time(handle); |
hualing chen | 969fe7b | 2021-05-26 15:13:17 +0800 | [diff] [blame] | 3997 | p_status->time_cur = _dvr_get_play_cur_time(handle, &segment_id); |
hualing chen | d241c7a | 2021-06-22 13:34:27 +0800 | [diff] [blame] | 3998 | |
shenghui.geng | bec6a46 | 2023-01-12 15:21:02 +0800 | [diff] [blame] | 3999 | if (player->control_speed_enable == 1) { |
hualing chen | 7ea70a7 | 2021-09-09 11:25:13 +0800 | [diff] [blame] | 4000 | if (player->con_spe.ply_sta == 0) { |
wentao.ma | fdba9a0 | 2023-01-17 16:43:26 +0800 | [diff] [blame] | 4001 | DVR_PB_INFO("player dur[%d] sta[%d] cur[%d] -----reinit", |
hualing chen | 03fd494 | 2021-07-15 15:56:41 +0800 | [diff] [blame] | 4002 | player->con_spe.ply_dur, |
| 4003 | player->con_spe.ply_sta, |
| 4004 | p_status->time_cur); |
hualing chen | d241c7a | 2021-06-22 13:34:27 +0800 | [diff] [blame] | 4005 | player->con_spe.ply_sta = p_status->time_cur; |
| 4006 | } else if (player->speed == 1.0f && player->con_spe.ply_sta < p_status->time_cur) { |
| 4007 | player->con_spe.ply_dur += (p_status->time_cur - player->con_spe.ply_sta); |
wentao.ma | fdba9a0 | 2023-01-17 16:43:26 +0800 | [diff] [blame] | 4008 | DVR_PB_INFO("player dur[%d] sta[%d] cur[%d]", |
hualing chen | 03fd494 | 2021-07-15 15:56:41 +0800 | [diff] [blame] | 4009 | player->con_spe.ply_dur, |
| 4010 | player->con_spe.ply_sta, |
| 4011 | p_status->time_cur); |
hualing chen | d241c7a | 2021-06-22 13:34:27 +0800 | [diff] [blame] | 4012 | player->con_spe.ply_sta = p_status->time_cur; |
| 4013 | } |
| 4014 | |
| 4015 | if (player->con_spe.sys_sta == 0) { |
| 4016 | player->con_spe.sys_sta = _dvr_time_getClock(); |
| 4017 | } else if (player->speed == 1.0f && player->con_spe.sys_sta > 0) { |
| 4018 | player->con_spe.sys_dur += (_dvr_time_getClock() - player->con_spe.sys_sta); |
| 4019 | player->con_spe.sys_sta = _dvr_time_getClock(); |
| 4020 | } |
| 4021 | } |
| 4022 | |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 4023 | if (player->last_send_time_id == UINT64_MAX) { |
| 4024 | player->last_send_time_id = player->cur_segment_id; |
| 4025 | player->last_cur_time = p_status->time_cur; |
| 4026 | } |
| 4027 | if (player->last_send_time_id == player->cur_segment_id) { |
Wentao MA | 8017951 | 2022-11-03 12:20:03 +0800 | [diff] [blame] | 4028 | if (player->speed > 1.0f ) { |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 4029 | //ff |
| 4030 | if (p_status->time_cur < player->last_cur_time ) { |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 4031 | DVR_PB_INFO("get ff time error last[%d]cur[%d]diff[%d]", |
hualing chen | 03fd494 | 2021-07-15 15:56:41 +0800 | [diff] [blame] | 4032 | player->last_cur_time, |
| 4033 | p_status->time_cur, |
| 4034 | player->last_cur_time - p_status->time_cur); |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 4035 | p_status->time_cur = player->last_cur_time; |
| 4036 | } else { |
| 4037 | player->last_cur_time = p_status->time_cur; |
| 4038 | } |
hualing chen | e41f437 | 2020-06-06 16:29:17 +0800 | [diff] [blame] | 4039 | } else if (player->speed <= -1.0f){ |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 4040 | //fb |
| 4041 | if (p_status->time_cur > player->last_cur_time ) { |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 4042 | DVR_PB_INFO("get fb time error last[%d]cur[%d]diff[%d]", |
hualing chen | 03fd494 | 2021-07-15 15:56:41 +0800 | [diff] [blame] | 4043 | player->last_cur_time, |
| 4044 | p_status->time_cur, |
| 4045 | p_status->time_cur - player->last_cur_time ); |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 4046 | p_status->time_cur = player->last_cur_time; |
| 4047 | } else { |
| 4048 | player->last_cur_time = p_status->time_cur; |
| 4049 | } |
| 4050 | } |
hualing chen | d241c7a | 2021-06-22 13:34:27 +0800 | [diff] [blame] | 4051 | } else { |
hualing chen | 4b7c15d | 2020-04-07 16:13:48 +0800 | [diff] [blame] | 4052 | player->last_cur_time = p_status->time_cur; |
| 4053 | } |
hualing chen | 969fe7b | 2021-05-26 15:13:17 +0800 | [diff] [blame] | 4054 | player->last_send_time_id = segment_id; |
| 4055 | p_status->segment_id = segment_id; |
hualing chen | 2aba402 | 2020-03-02 13:49:55 +0800 | [diff] [blame] | 4056 | |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 4057 | memcpy(&p_status->pids, &player->cur_segment.pids, sizeof(DVR_PlaybackPids_t)); |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame] | 4058 | p_status->speed = player->cmd.speed.speed.speed; |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 4059 | p_status->flags = player->cur_segment.flags; |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 4060 | DVR_PB_INFO("player real state[%s]state[%s]cur[%d]end[%d] id[%lld]playflag[%d]speed[%f]is_lock[%d]", |
hualing chen | 03fd494 | 2021-07-15 15:56:41 +0800 | [diff] [blame] | 4061 | _dvr_playback_state_toString(player->state), |
| 4062 | _dvr_playback_state_toString(p_status->state), |
| 4063 | p_status->time_cur, p_status->time_end, |
| 4064 | p_status->segment_id,player->play_flag, |
| 4065 | player->speed, |
| 4066 | is_lock); |
hualing chen | 1679f81 | 2021-11-08 15:17:46 +0800 | [diff] [blame] | 4067 | if (is_lock ==DVR_TRUE) { |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 4068 | DVR_PB_DEBUG("unlock ---\r\n"); |
Zhiqiang Han | f9c0e27 | 2022-06-14 13:54:03 +0800 | [diff] [blame] | 4069 | dvr_mutex_unlock(&player->lock); |
hualing chen | 1679f81 | 2021-11-08 15:17:46 +0800 | [diff] [blame] | 4070 | } |
hualing chen | 2932d37 | 2020-04-29 13:44:00 +0800 | [diff] [blame] | 4071 | return DVR_SUCCESS; |
| 4072 | } |
| 4073 | |
| 4074 | |
| 4075 | /**\brief Get playback status |
| 4076 | * \param[in] handle playback handle |
| 4077 | * \param[out] p_status playback status |
| 4078 | * \retval DVR_SUCCESS On success |
| 4079 | * \return Error code |
| 4080 | */ |
| 4081 | int dvr_playback_get_status(DVR_PlaybackHandle_t handle, |
| 4082 | DVR_PlaybackStatus_t *p_status) { |
| 4083 | // |
| 4084 | DVR_Playback_t *player = (DVR_Playback_t *) handle; |
| 4085 | |
Zhiqiang Han | 9adc972 | 2020-11-11 18:38:10 +0800 | [diff] [blame] | 4086 | _dvr_playback_get_status(handle, p_status, DVR_TRUE); |
| 4087 | |
hualing chen | 2932d37 | 2020-04-29 13:44:00 +0800 | [diff] [blame] | 4088 | if (player == NULL) { |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 4089 | DVR_PB_INFO("player is NULL"); |
hualing chen | 2932d37 | 2020-04-29 13:44:00 +0800 | [diff] [blame] | 4090 | return DVR_FAILURE; |
| 4091 | } |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 4092 | DVR_PB_DEBUG("lock---"); |
Zhiqiang Han | f9c0e27 | 2022-06-14 13:54:03 +0800 | [diff] [blame] | 4093 | dvr_mutex_lock(&player->lock); |
Zhiqiang Han | 9adc972 | 2020-11-11 18:38:10 +0800 | [diff] [blame] | 4094 | if (!player->has_video && !player->has_audio) |
| 4095 | p_status->time_cur = 0; |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 4096 | DVR_PB_DEBUG("unlock---"); |
Zhiqiang Han | f9c0e27 | 2022-06-14 13:54:03 +0800 | [diff] [blame] | 4097 | dvr_mutex_unlock(&player->lock); |
hualing chen | 2932d37 | 2020-04-29 13:44:00 +0800 | [diff] [blame] | 4098 | |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 4099 | return DVR_SUCCESS; |
| 4100 | } |
| 4101 | |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 4102 | void _dvr_dump_segment(DVR_PlaybackSegmentInfo_t *segment) { |
| 4103 | if (segment != NULL) { |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 4104 | DVR_PB_INFO("segment id: %lld", segment->segment_id); |
| 4105 | DVR_PB_INFO("segment flag: %d", segment->flags); |
| 4106 | DVR_PB_INFO("segment location: [%s]", segment->location); |
| 4107 | DVR_PB_INFO("segment vpid: 0x%x vfmt:0x%x", segment->pids.video.pid,segment->pids.video.format); |
| 4108 | DVR_PB_INFO("segment apid: 0x%x afmt:0x%x", segment->pids.audio.pid,segment->pids.audio.format); |
| 4109 | DVR_PB_INFO("segment pcr pid: 0x%x pcr fmt:0x%x", segment->pids.pcr.pid,segment->pids.pcr.format); |
| 4110 | DVR_PB_INFO("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] | 4111 | } |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 4112 | } |
| 4113 | |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 4114 | int dvr_dump_segmentinfo(DVR_PlaybackHandle_t handle, uint64_t segment_id) { |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 4115 | DVR_Playback_t *player = (DVR_Playback_t *) handle; |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 4116 | |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 4117 | if (player == NULL) { |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 4118 | DVR_PB_INFO("player is NULL"); |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 4119 | return DVR_FAILURE; |
| 4120 | } |
| 4121 | |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 4122 | DVR_PlaybackSegmentInfo_t *segment; |
wentao.ma | fd5283f | 2022-10-14 09:51:13 +0800 | [diff] [blame] | 4123 | // This error is suppressed as the macro code is picked from kernel. |
wentao.ma | a22bc85 | 2022-10-13 12:18:06 +0800 | [diff] [blame] | 4124 | // prefetch() here incurring self_assign is used to avoid some compiling |
| 4125 | // warnings. |
| 4126 | // coverity[self_assign] |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 4127 | list_for_each_entry(segment, &player->segment_list, head) |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 4128 | { |
Wentao MA | 07d3d74 | 2022-09-06 09:58:05 +0800 | [diff] [blame] | 4129 | if (segment->segment_id == segment_id) { |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 4130 | _dvr_dump_segment(segment); |
Wentao MA | 07d3d74 | 2022-09-06 09:58:05 +0800 | [diff] [blame] | 4131 | break; |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 4132 | } |
| 4133 | } |
| 4134 | return 0; |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 4135 | } |
pengfei.liu | 07ddc8a | 2020-03-24 23:36:53 +0800 | [diff] [blame] | 4136 | |
pengfei.liu | 27cc4ec | 2020-04-03 16:28:16 +0800 | [diff] [blame] | 4137 | 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] | 4138 | { |
| 4139 | DVR_Playback_t *player = (DVR_Playback_t *) handle; |
| 4140 | DVR_RETURN_IF_FALSE(player); |
| 4141 | DVR_RETURN_IF_FALSE(func); |
| 4142 | |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 4143 | DVR_PB_INFO("in "); |
Zhiqiang Han | f9c0e27 | 2022-06-14 13:54:03 +0800 | [diff] [blame] | 4144 | dvr_mutex_lock(&player->lock); |
pengfei.liu | 07ddc8a | 2020-03-24 23:36:53 +0800 | [diff] [blame] | 4145 | |
| 4146 | player->dec_func = func; |
| 4147 | player->dec_userdata = userdata; |
| 4148 | |
Zhiqiang Han | f9c0e27 | 2022-06-14 13:54:03 +0800 | [diff] [blame] | 4149 | dvr_mutex_unlock(&player->lock); |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 4150 | DVR_PB_INFO("out "); |
pengfei.liu | 07ddc8a | 2020-03-24 23:36:53 +0800 | [diff] [blame] | 4151 | return DVR_SUCCESS; |
| 4152 | } |
| 4153 | |
| 4154 | int dvr_playback_set_secure_buffer(DVR_PlaybackHandle_t handle, uint8_t *p_secure_buf, uint32_t len) |
| 4155 | { |
| 4156 | DVR_Playback_t *player = (DVR_Playback_t *) handle; |
| 4157 | DVR_RETURN_IF_FALSE(player); |
| 4158 | DVR_RETURN_IF_FALSE(p_secure_buf); |
| 4159 | DVR_RETURN_IF_FALSE(len); |
| 4160 | |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 4161 | DVR_PB_INFO("in "); |
Zhiqiang Han | f9c0e27 | 2022-06-14 13:54:03 +0800 | [diff] [blame] | 4162 | dvr_mutex_lock(&player->lock); |
pengfei.liu | 07ddc8a | 2020-03-24 23:36:53 +0800 | [diff] [blame] | 4163 | |
| 4164 | player->is_secure_mode = 1; |
| 4165 | player->secure_buffer = p_secure_buf; |
| 4166 | player->secure_buffer_size = len; |
| 4167 | |
Zhiqiang Han | f9c0e27 | 2022-06-14 13:54:03 +0800 | [diff] [blame] | 4168 | dvr_mutex_unlock(&player->lock); |
Wentao MA | 96f6896 | 2022-06-15 19:45:35 +0800 | [diff] [blame] | 4169 | DVR_PB_INFO("out"); |
pengfei.liu | 07ddc8a | 2020-03-24 23:36:53 +0800 | [diff] [blame] | 4170 | return DVR_SUCCESS; |
| 4171 | } |
Wentao MA | 5629ad8 | 2022-08-24 10:03:02 +0800 | [diff] [blame] | 4172 | |
| 4173 | int dvr_playback_set_ac4_preselection_id(DVR_PlaybackHandle_t handle, int presel_id) |
| 4174 | { |
| 4175 | DVR_Playback_t *player = (DVR_Playback_t *) handle; |
wentao.ma | a210e5e | 2022-10-12 16:10:03 +0800 | [diff] [blame] | 4176 | DVR_RETURN_IF_FALSE(player != NULL); |
Wentao MA | 5629ad8 | 2022-08-24 10:03:02 +0800 | [diff] [blame] | 4177 | |
| 4178 | player->audio_presentation_id = presel_id; |
| 4179 | am_tsplayer_result ret = AmTsPlayer_setParams(player->handle, |
| 4180 | AM_TSPLAYER_KEY_AUDIO_PRESENTATION_ID, &presel_id); |
| 4181 | DVR_RETURN_IF_FALSE(ret == AM_TSPLAYER_OK); |
| 4182 | |
| 4183 | return DVR_SUCCESS; |
| 4184 | } |
Wentao MA | a0b9c00 | 2022-11-10 17:47:27 +0800 | [diff] [blame] | 4185 | |
| 4186 | // This function ensures a valid TsPlayer delay time is provided or else it |
| 4187 | // returns DVR_FAILURE. It is designed to workaround a weakness of |
| 4188 | // AmTsPlayer_getDelayTime at starting phase of a playback in a short period |
| 4189 | // of 20ms or less. During the said period, getDelayTime does NOT work as |
| 4190 | // expect to return real delay length because demux isn't actually running |
| 4191 | // to provide valid pts to TsPlayer. |
Wentao MA | 804bab1 | 2022-11-29 10:01:26 +0800 | [diff] [blame] | 4192 | static int get_effective_tsplayer_delay_time(DVR_Playback_t* play, int *time) |
Wentao MA | a0b9c00 | 2022-11-10 17:47:27 +0800 | [diff] [blame] | 4193 | { |
| 4194 | int64_t delay=0; |
| 4195 | uint64_t pts_a=0; |
| 4196 | uint64_t pts_v=0; |
| 4197 | |
Wentao MA | 804bab1 | 2022-11-29 10:01:26 +0800 | [diff] [blame] | 4198 | DVR_RETURN_IF_FALSE(play != NULL); |
| 4199 | DVR_RETURN_IF_FALSE(play->handle != NULL); |
Wentao MA | a0b9c00 | 2022-11-10 17:47:27 +0800 | [diff] [blame] | 4200 | |
Wentao MA | 804bab1 | 2022-11-29 10:01:26 +0800 | [diff] [blame] | 4201 | AmTsPlayer_getDelayTime(play->handle, &delay); |
| 4202 | // In scambled stream situation, the returned TsPlayer delay time is |
| 4203 | // invalid and dirty. An additional time check agaginst 15 minutes (900s) |
| 4204 | // is introduced to insure such error condition is handled properly. |
| 4205 | DVR_RETURN_IF_FALSE((delay >= 0) && (delay <= 900*1000)); |
Wentao MA | a0b9c00 | 2022-11-10 17:47:27 +0800 | [diff] [blame] | 4206 | |
Wentao MA | 804bab1 | 2022-11-29 10:01:26 +0800 | [diff] [blame] | 4207 | if (play->delay_is_effective) { |
| 4208 | *time = (int)delay; |
Wentao MA | a0b9c00 | 2022-11-10 17:47:27 +0800 | [diff] [blame] | 4209 | return DVR_SUCCESS; |
| 4210 | } else if (delay > 0) { |
Wentao MA | 804bab1 | 2022-11-29 10:01:26 +0800 | [diff] [blame] | 4211 | *time = (int)delay; |
| 4212 | play->delay_is_effective=DVR_TRUE; |
Wentao MA | a0b9c00 | 2022-11-10 17:47:27 +0800 | [diff] [blame] | 4213 | return DVR_SUCCESS; |
| 4214 | } |
| 4215 | |
Wentao MA | 804bab1 | 2022-11-29 10:01:26 +0800 | [diff] [blame] | 4216 | AmTsPlayer_getPts(play->handle, TS_STREAM_AUDIO, &pts_a); |
| 4217 | AmTsPlayer_getPts(play->handle, TS_STREAM_VIDEO, &pts_v); |
Wentao MA | a0b9c00 | 2022-11-10 17:47:27 +0800 | [diff] [blame] | 4218 | if ((int64_t)pts_a > 0 || (int64_t)pts_v > 0) { |
Wentao MA | 804bab1 | 2022-11-29 10:01:26 +0800 | [diff] [blame] | 4219 | *time = (int)delay; |
| 4220 | play->delay_is_effective=DVR_TRUE; |
Wentao MA | a0b9c00 | 2022-11-10 17:47:27 +0800 | [diff] [blame] | 4221 | return DVR_SUCCESS; |
| 4222 | } |
| 4223 | |
| 4224 | return DVR_FAILURE; |
| 4225 | } |
| 4226 | |