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