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