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