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