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> |
| 14 | |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 15 | #include <amports/amstream.h> |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 16 | |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 17 | #include "dvr_playback.h" |
| 18 | |
| 19 | #define VALID_PID(_pid_) ((_pid_)>0 && (_pid_)<0x1fff) |
| 20 | |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 21 | #define FFFB_SLEEP_TIME 400 |
| 22 | |
| 23 | // |
| 24 | static int _dvr_playback_fffb(DVR_PlaybackHandle_t handle); |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame^] | 25 | static int _do_check_pid_info(DVR_PlaybackHandle_t handle, DVR_StreamInfo_t now_pid, DVR_StreamInfo_t set_pid, int type); |
| 26 | static int _dvr_get_cur_time(DVR_PlaybackHandle_t handle); |
| 27 | static int _dvr_get_end_time(DVR_PlaybackHandle_t handle); |
| 28 | |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 29 | //convert video and audio fmt |
| 30 | static int _dvr_convert_stream_fmt(int fmt, DVR_Bool_t is_audio) { |
| 31 | int format = 0; |
| 32 | if (is_audio == DVR_FALSE) { |
| 33 | //for video fmt |
| 34 | switch (fmt) |
| 35 | { |
| 36 | case DVR_VIDEO_FORMAT_MPEG1: |
| 37 | format = VFORMAT_MPEG12; |
| 38 | break; |
| 39 | case DVR_VIDEO_FORMAT_MPEG2: |
| 40 | format = VFORMAT_MPEG12; |
| 41 | break; |
| 42 | case DVR_VIDEO_FORMAT_HEVC: |
| 43 | format = VFORMAT_HEVC; |
| 44 | break; |
| 45 | case DVR_VIDEO_FORMAT_H264: |
| 46 | format = VFORMAT_H264; |
| 47 | break; |
| 48 | } |
| 49 | } else { |
| 50 | //for audio fmt |
| 51 | switch (fmt) |
| 52 | { |
| 53 | case DVR_AUDIO_FORMAT_MPEG: |
| 54 | format = AFORMAT_MPEG; |
| 55 | break; |
| 56 | case DVR_AUDIO_FORMAT_AC3: |
| 57 | format = AFORMAT_AC3; |
| 58 | break; |
| 59 | case DVR_AUDIO_FORMAT_EAC3: |
| 60 | format = AFORMAT_EAC3; |
| 61 | break; |
| 62 | case DVR_AUDIO_FORMAT_DTS: |
| 63 | format = AFORMAT_DTS; |
| 64 | break; |
| 65 | } |
| 66 | } |
| 67 | return format; |
| 68 | } |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 69 | static int _dvr_playback_get_trick_stat(DVR_PlaybackHandle_t handle) |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 70 | { |
| 71 | int state; |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 72 | DVR_Playback_t *player = (DVR_Playback_t *) handle; |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 73 | |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 74 | if (player->handle == NULL) |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 75 | return -1; |
| 76 | |
| 77 | state = playback_device_get_trick_stat(handle); |
| 78 | |
| 79 | return state; |
| 80 | } |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 81 | //get sys time ms |
| 82 | static int _dvr_time_getClock(void) |
| 83 | { |
| 84 | struct timespec ts; |
| 85 | int ms; |
| 86 | |
| 87 | clock_gettime(CLOCK_MONOTONIC, &ts); |
| 88 | ms = ts.tv_sec*1000+ts.tv_nsec/1000000; |
| 89 | |
| 90 | return ms; |
| 91 | } |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 92 | |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 93 | |
| 94 | //timeout wait sibnal |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 95 | static int _dvr_playback_timeoutwait(DVR_PlaybackHandle_t handle , int ms) |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 96 | { |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 97 | DVR_Playback_t *player = (DVR_Playback_t *) handle; |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 98 | |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 99 | struct timespec ts; |
| 100 | clock_gettime(CLOCK_MONOTONIC, &ts); |
| 101 | //ms为毫秒,换算成秒 |
| 102 | ts.tv_sec += ms/1000; |
| 103 | //在outtime的基础上,增加ms毫秒 |
| 104 | //outtime.tv_nsec为纳秒,1微秒=1000纳秒 |
| 105 | //tv_nsec此值再加上剩余的毫秒数 ms%1000,有可能超过1秒。需要特殊处理 |
| 106 | uint64_t us = ts.tv_nsec/1000 + 1000 * (ms % 1000); //微秒 |
| 107 | //us的值有可能超过1秒, |
| 108 | ts.tv_sec += us / 1000000; |
| 109 | us = us % 1000000; |
| 110 | ts.tv_nsec = us * 1000;//换算成纳秒 |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 111 | pthread_cond_timedwait(&player->cond, &player->lock, &ts); |
| 112 | return 0; |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 113 | } |
| 114 | |
| 115 | //send signal |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 116 | static int _dvr_playback_sendSignal(DVR_PlaybackHandle_t handle) |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 117 | { |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 118 | DVR_Playback_t *player = (DVR_Playback_t *) handle; |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame^] | 119 | //pthread_cond_signal(&player->cond); |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 120 | return 0; |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 121 | } |
| 122 | |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame^] | 123 | //send playback event |
| 124 | static int _dvr_playback_sent_event(DVR_PlaybackHandle_t handle, DVR_PlaybackEvent_t evt, DVR_Play_Notify_t *notify) { |
| 125 | |
| 126 | DVR_Playback_t *player = (DVR_Playback_t *) handle; |
| 127 | DVR_DEBUG(1, "into send event -----"); |
| 128 | switch (evt) { |
| 129 | case DVR_PLAYBACK_EVENT_ERROR: |
| 130 | break; |
| 131 | case DVR_PLAYBACK_EVENT_TRANSITION_OK: |
| 132 | //GET STATE |
| 133 | DVR_DEBUG(1, "trans ok----"); |
| 134 | dvr_playback_get_status(handle, &(notify->play_status)); |
| 135 | break; |
| 136 | case DVR_PLAYBACK_EVENT_TRANSITION_FAILED: |
| 137 | break; |
| 138 | case DVR_PLAYBACK_EVENT_KEY_FAILURE: |
| 139 | break; |
| 140 | case DVR_PLAYBACK_EVENT_NO_KEY: |
| 141 | break; |
| 142 | case DVR_PLAYBACK_EVENT_REACHED_BEGIN: |
| 143 | break; |
| 144 | case DVR_PLAYBACK_EVENT_REACHED_END: |
| 145 | //GET STATE |
| 146 | DVR_DEBUG(1, "reached end---"); |
| 147 | dvr_playback_get_status(handle, &(notify->play_status)); |
| 148 | break; |
| 149 | default: |
| 150 | break; |
| 151 | } |
| 152 | if (player->openParams.event_fn != NULL) |
| 153 | player->openParams.event_fn(evt, (void*)notify, player->openParams.event_userdata); |
| 154 | DVR_DEBUG(1, "into send event --end---"); |
| 155 | return DVR_SUCCESS; |
| 156 | } |
| 157 | static int _dvr_playback_sent_transition_ok(DVR_PlaybackHandle_t handle) |
| 158 | { |
| 159 | DVR_Play_Notify_t notify; |
| 160 | memset(¬ify, 0 , sizeof(DVR_Play_Notify_t)); |
| 161 | notify.event = DVR_PLAYBACK_EVENT_TRANSITION_OK; |
| 162 | //get play statue not here |
| 163 | _dvr_playback_sent_event(handle, DVR_PLAYBACK_EVENT_TRANSITION_OK, ¬ify); |
| 164 | return DVR_SUCCESS; |
| 165 | } |
| 166 | |
| 167 | //check is ongoing segment |
| 168 | static int _dvr_check_segment_ongoing(DVR_PlaybackHandle_t handle) { |
| 169 | |
| 170 | DVR_Playback_t *player = (DVR_Playback_t *) handle; |
| 171 | Segment_StoreInfo_t info; |
| 172 | int ret = DVR_FALSE; |
| 173 | DVR_DEBUG(1, "into check ongoing---"); |
| 174 | if (player->r_handle != NULL) |
| 175 | ret = segment_load_info(player->r_handle, &info); |
| 176 | |
| 177 | if (ret != DVR_SUCCESS) { |
| 178 | DVR_DEBUG(1, "is not ongoing chunk--end---"); |
| 179 | return DVR_FALSE; |
| 180 | } |
| 181 | DVR_DEBUG(1, "is ongoing chunk--end---"); |
| 182 | return DVR_TRUE; |
| 183 | } |
| 184 | //get next segment id |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 185 | static int _dvr_get_next_segmentId(DVR_PlaybackHandle_t handle) { |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 186 | |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 187 | DVR_Playback_t *player = (DVR_Playback_t *) handle; |
| 188 | DVR_PlaybackSegmentInfo_t *segment; |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 189 | |
| 190 | int found = 0; |
| 191 | |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 192 | list_for_each_entry(segment, &player->segment_list, head) |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 193 | { |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame^] | 194 | if (player->segment_is_open == DVR_FALSE) { |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 195 | //get first segment from list |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 196 | found = 1; |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 197 | } else if (segment->segment_id == player->cur_segment_id) { |
| 198 | //find cur segment, we need get next one |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 199 | found = 1; |
| 200 | continue; |
| 201 | } |
| 202 | if (found == 1) { |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame^] | 203 | //save segment info |
| 204 | player->last_segment_id = player->cur_segment_id; |
| 205 | player->last_segment.segment_id = player->cur_segment.flags; |
| 206 | player->last_segment.flags = segment->flags; |
| 207 | memcpy(player->last_segment.location, player->cur_segment.location, DVR_MAX_LOCATION_SIZE); |
| 208 | //pids |
| 209 | memcpy(&player->last_segment.pids, &player->cur_segment.pids, sizeof(DVR_PlaybackPids_t)); |
| 210 | |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 211 | //get segment info |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame^] | 212 | player->segment_is_open = DVR_TRUE; |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 213 | player->cur_segment_id = segment->segment_id; |
| 214 | player->cur_segment.segment_id = segment->segment_id; |
| 215 | player->cur_segment.flags = segment->flags; |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame^] | 216 | DVR_DEBUG(1, "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] | 217 | memcpy(player->cur_segment.location, segment->location, DVR_MAX_LOCATION_SIZE); |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 218 | //pids |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 219 | memcpy(&player->cur_segment.pids, &segment->pids, sizeof(DVR_PlaybackPids_t)); |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 220 | found = 2; |
| 221 | } |
| 222 | } |
| 223 | if (found != 2) { |
| 224 | //list is null or reache list end |
| 225 | return -1; |
| 226 | } |
| 227 | return DVR_SUCCESS; |
| 228 | } |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 229 | //open next segment to play,if reach list end return errro. |
| 230 | static int _change_to_next_segment(DVR_PlaybackHandle_t handle) |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 231 | { |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 232 | DVR_Playback_t *player = (DVR_Playback_t *) handle; |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 233 | Segment_OpenParams_t params; |
| 234 | int ret = DVR_SUCCESS; |
| 235 | |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 236 | int id = _dvr_get_next_segmentId(handle); |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 237 | if (id < 0) { |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 238 | DVR_DEBUG(1, "not found segment info"); |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 239 | return DVR_FAILURE; |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 240 | } |
| 241 | |
| 242 | if (player->r_handle != NULL) { |
| 243 | segment_close(player->r_handle); |
| 244 | player->r_handle = NULL; |
| 245 | } |
| 246 | |
| 247 | memset(params.location, 0, DVR_MAX_LOCATION_SIZE); |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 248 | //cp chur segment path to location |
| 249 | memcpy(params.location, player->cur_segment.location, DVR_MAX_LOCATION_SIZE); |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 250 | params.segment_id = (uint64_t)player->cur_segment.segment_id; |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 251 | params.mode = SEGMENT_MODE_READ; |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame^] | 252 | DVR_DEBUG(1, "open segment info[%s][%lld]flag[0x%x]", params.location, params.segment_id, player->cur_segment.flags); |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 253 | ret = segment_open(¶ms, &(player->r_handle)); |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame^] | 254 | Segment_StoreInfo_t info; |
| 255 | if (segment_load_info(player->r_handle, &info) == DVR_SUCCESS) { |
| 256 | player->openParams.is_timeshift = DVR_FALSE; |
| 257 | } else { |
| 258 | player->openParams.is_timeshift = DVR_TRUE; |
| 259 | } |
| 260 | player->dur = info.duration; |
| 261 | DVR_DEBUG(1, "next player->dur [%d] flag [0x%x]", player->dur, player->cur_segment.flags); |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 262 | return ret; |
| 263 | } |
| 264 | |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 265 | //open next segment to play,if reach list end return errro. |
| 266 | static int _dvr_open_segment(DVR_PlaybackHandle_t handle, uint64_t segment_id) |
| 267 | { |
| 268 | DVR_Playback_t *player = (DVR_Playback_t *) handle; |
| 269 | Segment_OpenParams_t params; |
| 270 | int ret = DVR_SUCCESS; |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame^] | 271 | if (segment_id == player->cur_segment_id && player->segment_is_open == DVR_TRUE) { |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 272 | return 0; |
| 273 | } |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame^] | 274 | uint64_t id = segment_id; |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 275 | if (id < 0) { |
| 276 | DVR_DEBUG(1, "not found segment info"); |
| 277 | return DVR_FAILURE; |
| 278 | } |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame^] | 279 | DVR_DEBUG(1, "start found segment[%lld][%lld] info", id,segment_id); |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 280 | |
| 281 | if (player->r_handle != NULL) { |
| 282 | segment_close(player->r_handle); |
| 283 | player->r_handle = NULL; |
| 284 | } |
| 285 | |
| 286 | DVR_PlaybackSegmentInfo_t *segment; |
| 287 | |
| 288 | int found = 0; |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame^] | 289 | |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 290 | list_for_each_entry(segment, &player->segment_list, head) |
| 291 | { |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame^] | 292 | DVR_DEBUG(1, "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] | 293 | if (segment->segment_id == segment_id) { |
| 294 | found = 1; |
| 295 | } |
| 296 | if (found == 1) { |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame^] | 297 | DVR_DEBUG(1, "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] | 298 | //get segment info |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame^] | 299 | player->segment_is_open = DVR_TRUE; |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 300 | player->cur_segment_id = segment->segment_id; |
| 301 | player->cur_segment.segment_id = segment->segment_id; |
| 302 | player->cur_segment.flags = segment->flags; |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame^] | 303 | strncpy(player->cur_segment.location, segment->location, strlen(segment->location));//DVR_MAX_LOCATION_SIZE |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 304 | //pids |
| 305 | memcpy(&player->cur_segment.pids, &segment->pids, sizeof(DVR_PlaybackPids_t)); |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame^] | 306 | DVR_DEBUG(1, "cur found location [%s]id[%lld]flag[%x]", player->cur_segment.location, player->cur_segment.segment_id,player->cur_segment.flags); |
| 307 | break; |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 308 | } |
| 309 | } |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame^] | 310 | if (found == 0) { |
| 311 | DVR_DEBUG(1, "not found segment info.error.."); |
| 312 | return DVR_FAILURE; |
| 313 | } |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 314 | memset(params.location, 0, DVR_MAX_LOCATION_SIZE); |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame^] | 315 | //cp cur segment path to location |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 316 | strncpy(params.location, player->cur_segment.location, strlen(player->cur_segment.location)); |
| 317 | params.segment_id = (uint64_t)player->cur_segment.segment_id; |
| 318 | params.mode = SEGMENT_MODE_READ; |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame^] | 319 | DVR_DEBUG(1, "open segment location[%s][%lld]cur flag[0x%x]", params.location, params.segment_id, player->cur_segment.flags); |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 320 | ret = segment_open(¶ms, &(player->r_handle)); |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame^] | 321 | Segment_StoreInfo_t info; |
| 322 | if (segment_load_info(player->r_handle, &info) == DVR_SUCCESS) { |
| 323 | player->openParams.is_timeshift = DVR_FALSE; |
| 324 | } else { |
| 325 | player->openParams.is_timeshift = DVR_TRUE; |
| 326 | } |
| 327 | player->dur = info.duration; |
| 328 | |
| 329 | DVR_DEBUG(1, "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] | 330 | return ret; |
| 331 | } |
| 332 | |
| 333 | |
| 334 | //get play info by segment id |
| 335 | static int _dvr_playback_get_playinfo(DVR_PlaybackHandle_t handle, |
| 336 | uint64_t segment_id, |
| 337 | Playback_DeviceVideoParams_t *vparam, |
| 338 | Playback_DeviceAudioParams_t *aparam) { |
| 339 | |
| 340 | DVR_Playback_t *player = (DVR_Playback_t *) handle; |
| 341 | DVR_PlaybackSegmentInfo_t *segment; |
| 342 | |
| 343 | int found = 0; |
| 344 | |
| 345 | list_for_each_entry(segment, &player->segment_list, head) |
| 346 | { |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame^] | 347 | if (segment_id == 0LL) { |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 348 | //get first segment from list |
| 349 | found = 1; |
| 350 | } |
| 351 | if (segment->segment_id == segment_id) { |
| 352 | found = 1; |
| 353 | } |
| 354 | if (found == 1) { |
| 355 | //get segment info |
| 356 | if (player->cur_segment_id > 0) |
| 357 | player->cur_segment_id = segment->segment_id; |
| 358 | DVR_DEBUG(1, "get play info id [%lld]", player->cur_segment_id); |
| 359 | player->cur_segment.segment_id = segment->segment_id; |
| 360 | player->cur_segment.flags = segment->flags; |
| 361 | //pids |
| 362 | memcpy(&player->cur_segment.pids, &segment->pids, sizeof(DVR_PlaybackPids_t)); |
| 363 | // |
| 364 | vparam->fmt = _dvr_convert_stream_fmt(segment->pids.video.format, DVR_FALSE); |
| 365 | vparam->pid = segment->pids.video.pid; |
| 366 | aparam->fmt = _dvr_convert_stream_fmt(segment->pids.audio.format, DVR_TRUE); |
| 367 | aparam->pid = segment->pids.audio.pid; |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame^] | 368 | DVR_DEBUG(1, "get play info sucess[0x%x]apid[0x%x]", vparam->pid, aparam->pid); |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 369 | found = 2; |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame^] | 370 | break; |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 371 | } |
| 372 | } |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame^] | 373 | if (found != 2) { |
| 374 | //list is null or reache list end |
| 375 | DVR_DEBUG(1, "get play info fail"); |
| 376 | return DVR_FAILURE; |
| 377 | } |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 378 | |
| 379 | return DVR_SUCCESS; |
| 380 | } |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame^] | 381 | static int _dvr_replay_changed_pid(DVR_PlaybackHandle_t handle) { |
| 382 | DVR_Playback_t *player = (DVR_Playback_t *) handle; |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 383 | |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame^] | 384 | //compare cur segment |
| 385 | //if (player->cmd.state == DVR_PLAYBACK_STATE_START) |
| 386 | { |
| 387 | //check video pids, stop or restart |
| 388 | _do_check_pid_info(handle, player->last_segment.pids.video, player->cur_segment.pids.video, 0); |
| 389 | //check audio pids stop or restart |
| 390 | _do_check_pid_info(handle, player->last_segment.pids.audio, player->cur_segment.pids.audio, 1); |
| 391 | //check sub audio pids stop or restart |
| 392 | _do_check_pid_info(handle, player->last_segment.pids.ad, player->cur_segment.pids.ad, 2); |
| 393 | //check pcr pids stop or restart |
| 394 | _do_check_pid_info(handle, player->last_segment.pids.pcr, player->cur_segment.pids.pcr, 3); |
| 395 | } |
| 396 | return 0; |
| 397 | } |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 398 | |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame^] | 399 | static int _dvr_check_cur_segment_flag(DVR_PlaybackHandle_t handle) |
| 400 | { |
| 401 | DVR_Playback_t *player = (DVR_Playback_t *) handle; |
| 402 | DVR_DEBUG(1, "call %s flag[0x%x]id[%lld]", __func__, player->cur_segment.flags, player->cur_segment.segment_id); |
| 403 | if ((player->cur_segment.flags & DVR_PLAYBACK_SEGMENT_DISPLAYABLE) == DVR_PLAYBACK_SEGMENT_DISPLAYABLE) { |
| 404 | //disable display |
| 405 | DVR_DEBUG(1, "call %s unmute", __func__); |
| 406 | playback_device_mute_audio(player->handle, 0); |
| 407 | playback_device_mute_video(player->handle, 0); |
| 408 | } else if ((player->cur_segment.flags & DVR_PLAYBACK_SEGMENT_DISPLAYABLE) == 0) { |
| 409 | //enable display |
| 410 | DVR_DEBUG(1, "call %s mute", __func__); |
| 411 | playback_device_mute_audio(player->handle, 1); |
| 412 | playback_device_mute_video(player->handle, 1); |
| 413 | } |
| 414 | return DVR_SUCCESS; |
| 415 | } |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 416 | static void* _dvr_playback_thread(void *arg) |
| 417 | { |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 418 | DVR_Playback_t *player = (DVR_Playback_t *) arg; |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame^] | 419 | //int need_open_segment = 1; |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 420 | Playback_DeviceWBufs_t wbufs; |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 421 | int ret = DVR_SUCCESS; |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 422 | |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame^] | 423 | int timeout = 50;//ms |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 424 | uint8_t *buf = NULL; |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 425 | int buf_len = player->openParams.block_size > 0 ? player->openParams.block_size : (256 * 1024); |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 426 | int real_read = 0; |
| 427 | int real_write = 0; |
| 428 | |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 429 | buf = malloc(buf_len); |
| 430 | wbufs.flag = 0; |
| 431 | wbufs.timeout = 10; |
| 432 | wbufs.len = 0; |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame^] | 433 | |
| 434 | if (player->segment_is_open == DVR_FALSE) { |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 435 | ret = _change_to_next_segment((DVR_PlaybackHandle_t)player); |
| 436 | } |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 437 | |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 438 | if (ret != DVR_SUCCESS) { |
| 439 | if (buf != NULL) { |
| 440 | free(buf); |
| 441 | buf = NULL; |
| 442 | } |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 443 | DVR_DEBUG(1, "get segment error"); |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 444 | return NULL; |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 445 | } |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame^] | 446 | //get play statue not here |
| 447 | _dvr_playback_sent_transition_ok((DVR_PlaybackHandle_t)player); |
| 448 | _dvr_check_cur_segment_flag((DVR_PlaybackHandle_t)player); |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 449 | |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 450 | int trick_stat = 0; |
| 451 | while (player->is_running/* || player->cmd.last_cmd != player->cmd.cur_cmd*/) { |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 452 | |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 453 | //check trick stat |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame^] | 454 | pthread_mutex_lock(&player->lock); |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 455 | trick_stat = _dvr_playback_get_trick_stat((DVR_PlaybackHandle_t)player); |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 456 | |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 457 | if (trick_stat > 0) |
| 458 | { |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 459 | if (player->cmd.cur_cmd == DVR_PLAYBACK_CMD_SEEK) { |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 460 | //check last cmd |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 461 | if(player->cmd.last_cmd == DVR_PLAYBACK_CMD_PAUSE |
| 462 | || (player->play_flag == DVR_PLAYBACK_STARTED_PAUSEDLIVE |
| 463 | && (player->cmd.last_cmd == DVR_PLAYBACK_CMD_VSTART |
| 464 | || player->cmd.last_cmd == DVR_PLAYBACK_CMD_ASTART |
| 465 | || player->cmd.last_cmd == DVR_PLAYBACK_CMD_START))) { |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 466 | |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 467 | //need change to pause state |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 468 | player->cmd.cur_cmd = DVR_PLAYBACK_CMD_PAUSE; |
| 469 | player->cmd.state = DVR_PLAYBACK_STATE_PAUSE; |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 470 | playback_device_pause(player->handle); |
| 471 | } |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 472 | } else if (player->cmd.cur_cmd == DVR_PLAYBACK_CMD_FF |
| 473 | || player->cmd.cur_cmd == DVR_PLAYBACK_CMD_FB) { |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 474 | //restart play stream if speed > 2 |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame^] | 475 | pthread_mutex_unlock(&player->lock); |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 476 | _dvr_playback_fffb((DVR_PlaybackHandle_t)player); |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame^] | 477 | pthread_mutex_lock(&player->lock); |
| 478 | } |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 479 | } |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 480 | |
| 481 | int write = 0; |
| 482 | int read = segment_read(player->r_handle, buf + real_read, buf_len - real_read); |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame^] | 483 | pthread_mutex_unlock(&player->lock); |
| 484 | |
| 485 | //DVR_DEBUG(1, "read ts [%d]buf_len[%d]", read, buf_len); |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 486 | if (read == 0) { |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame^] | 487 | //file end.need to play next segment |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 488 | int ret = _change_to_next_segment((DVR_PlaybackHandle_t)player); |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 489 | if (ret != DVR_SUCCESS) { |
| 490 | if (player->openParams.is_timeshift) { |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame^] | 491 | //send end event to hal |
| 492 | DVR_Play_Notify_t notify; |
| 493 | memset(¬ify, 0 , sizeof(DVR_Play_Notify_t)); |
| 494 | notify.event = DVR_PLAYBACK_EVENT_REACHED_END; |
| 495 | //get play statue not here |
| 496 | _dvr_playback_sent_event((DVR_PlaybackHandle_t)player, DVR_PLAYBACK_EVENT_REACHED_END, ¬ify); |
| 497 | |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 498 | //continue,timeshift mode, when read end,need wait cur recording segment |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame^] | 499 | DVR_DEBUG(1, "playback is timeshift"); |
| 500 | pthread_mutex_lock(&player->lock); |
| 501 | _dvr_playback_timeoutwait((DVR_PlaybackHandle_t)player, timeout); |
| 502 | pthread_mutex_unlock(&player->lock); |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 503 | continue; |
| 504 | } else { |
| 505 | //play end |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame^] | 506 | if (read == 0) { |
| 507 | DVR_DEBUG(1, "playback reach end segment, exit playbackplayer->cur_segment_id [%lld] [%p]", player->cur_segment_id, (DVR_PlaybackHandle_t)player); |
| 508 | //send reach end |
| 509 | DVR_Play_Notify_t notify; |
| 510 | memset(¬ify, 0 , sizeof(DVR_Play_Notify_t)); |
| 511 | notify.event = DVR_PLAYBACK_EVENT_REACHED_END; |
| 512 | //get play statue not here |
| 513 | _dvr_playback_sent_event((DVR_PlaybackHandle_t)player, DVR_PLAYBACK_EVENT_REACHED_END, ¬ify); |
| 514 | DVR_DEBUG(1, "playback reach end segment, send event end"); |
| 515 | continue; |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 516 | } else { |
| 517 | //has data not inject to dev |
| 518 | goto inject; |
| 519 | } |
| 520 | } |
| 521 | } |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame^] | 522 | _dvr_playback_sent_transition_ok((DVR_PlaybackHandle_t)player); |
| 523 | pthread_mutex_lock(&player->lock); |
| 524 | _dvr_replay_changed_pid((DVR_PlaybackHandle_t)player); |
| 525 | _dvr_check_cur_segment_flag((DVR_PlaybackHandle_t)player); |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 526 | read = segment_read(player->r_handle, buf + real_read, buf_len - real_read); |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame^] | 527 | pthread_mutex_lock(&player->lock); |
| 528 | |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 529 | } |
| 530 | real_read = real_read + read; |
| 531 | if (real_read < buf_len ) { |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame^] | 532 | if (player->openParams.is_timeshift) { |
| 533 | //send end event to hal |
| 534 | DVR_Play_Notify_t notify; |
| 535 | memset(¬ify, 0 , sizeof(DVR_Play_Notify_t)); |
| 536 | notify.event = DVR_PLAYBACK_EVENT_REACHED_END; |
| 537 | //get play statue not here |
| 538 | _dvr_playback_sent_event((DVR_PlaybackHandle_t)player, DVR_PLAYBACK_EVENT_REACHED_END, ¬ify); |
| 539 | |
| 540 | //continue,timeshift mode, when read end,need wait cur recording segment |
| 541 | DVR_DEBUG(1, "playback is timeshift---"); |
| 542 | pthread_mutex_lock(&player->lock); |
| 543 | _dvr_playback_timeoutwait((DVR_PlaybackHandle_t)player, timeout); |
| 544 | pthread_mutex_unlock(&player->lock); |
| 545 | continue; |
| 546 | } |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 547 | //continue to read |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame^] | 548 | pthread_mutex_lock(&player->lock); |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 549 | _dvr_playback_timeoutwait((DVR_PlaybackHandle_t)player, timeout); |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame^] | 550 | pthread_mutex_unlock(&player->lock); |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 551 | if (!player->is_running) { |
| 552 | break; |
| 553 | } |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 554 | DVR_DEBUG(1, "playback continue read"); |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 555 | continue; |
| 556 | } |
| 557 | inject: |
| 558 | wbufs.len = real_read; |
| 559 | real_write = 0; |
| 560 | rewrite: |
| 561 | wbufs.buf = buf + real_write; |
| 562 | //read data |
| 563 | //descramble data |
| 564 | //read data to inject |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame^] | 565 | //DVR_DEBUG(1, "playback dev write---"); |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 566 | write = playback_device_write(player->handle, &wbufs); |
| 567 | real_write = real_write + write; |
| 568 | wbufs.len = real_read - real_write; |
| 569 | //check if left data |
| 570 | if (real_write == real_read) { |
| 571 | //this block write end |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 572 | real_read = 0; |
| 573 | real_write = 0; |
| 574 | continue; |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 575 | } else { |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame^] | 576 | pthread_mutex_lock(&player->lock); |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 577 | _dvr_playback_timeoutwait((DVR_PlaybackHandle_t)player, timeout); |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame^] | 578 | pthread_mutex_unlock(&player->lock); |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 579 | if (!player->is_running) { |
| 580 | break; |
| 581 | } |
| 582 | goto rewrite; |
| 583 | } |
| 584 | } |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 585 | DVR_DEBUG(1, "playback thread is end"); |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 586 | return NULL; |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 587 | } |
| 588 | |
| 589 | |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 590 | static int _start_playback_thread(DVR_PlaybackHandle_t handle) |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 591 | { |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 592 | DVR_Playback_t *player = (DVR_Playback_t *) handle; |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame^] | 593 | DVR_DEBUG(1, "start thread------[%d]", player->is_running); |
| 594 | if (player->is_running == DVR_TRUE) { |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 595 | return 0; |
| 596 | } |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 597 | player->is_running = DVR_TRUE; |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 598 | 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] | 599 | if (rc < 0) |
| 600 | player->is_running = DVR_FALSE; |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame^] | 601 | DVR_DEBUG(1, "start thread------[%d] end", player->is_running); |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 602 | return 0; |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 603 | } |
| 604 | |
| 605 | |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 606 | static int _stop_playback_thread(DVR_PlaybackHandle_t handle) |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 607 | { |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 608 | DVR_Playback_t *player = (DVR_Playback_t *) handle; |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame^] | 609 | DVR_DEBUG(1, "stopthread------[%d]", player->is_running); |
| 610 | if (player->is_running == DVR_TRUE) |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 611 | { |
| 612 | player->is_running = DVR_FALSE; |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame^] | 613 | //pthread_cond_signal(&player->cond); |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 614 | pthread_join(player->playback_thread, NULL); |
| 615 | } |
| 616 | if (player->r_handle) { |
| 617 | segment_close(player->r_handle); |
| 618 | player->r_handle = NULL; |
| 619 | } |
| 620 | return 0; |
| 621 | } |
| 622 | |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 623 | /**\brief Open an dvr palyback |
| 624 | * \param[out] p_handle dvr playback addr |
| 625 | * \param[in] params dvr playback open parameters |
| 626 | * \retval DVR_SUCCESS On success |
| 627 | * \return Error code |
| 628 | */ |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 629 | 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] | 630 | |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 631 | DVR_Playback_t *player; |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 632 | pthread_condattr_t cattr; |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 633 | |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 634 | player = (DVR_Playback_t*)malloc(sizeof(DVR_Playback_t)); |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 635 | |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 636 | pthread_mutex_init(&player->lock, NULL); |
| 637 | pthread_condattr_init(&cattr); |
| 638 | pthread_condattr_setclock(&cattr, CLOCK_MONOTONIC); |
| 639 | pthread_cond_init(&player->cond, &cattr); |
| 640 | pthread_condattr_destroy(&cattr); |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 641 | |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 642 | //init segment list head |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 643 | INIT_LIST_HEAD(&player->segment_list); |
| 644 | player->cmd.last_cmd = DVR_PLAYBACK_CMD_STOP; |
| 645 | player->cmd.cur_cmd = DVR_PLAYBACK_CMD_STOP; |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 646 | player->cmd.speed.speed.speed = PLAYBACK_SPEED_X1; |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 647 | player->cmd.state = DVR_PLAYBACK_STATE_STOP; |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 648 | player->cmd.pos = 0; |
| 649 | //store open params |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 650 | player->openParams.dmx_dev_id = params->dmx_dev_id; |
| 651 | player->openParams.block_size = params->block_size; |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 652 | player->openParams.is_timeshift = params->is_timeshift; |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame^] | 653 | player->openParams.event_fn = params->event_fn; |
| 654 | player->openParams.event_userdata = params->event_userdata; |
| 655 | |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 656 | player->has_pids = params->has_pids; |
| 657 | |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 658 | player->handle = params->playback_handle; |
| 659 | |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 660 | //init has audio and video |
| 661 | player->has_video = DVR_FALSE; |
| 662 | player->has_audio = DVR_FALSE; |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame^] | 663 | player->cur_segment_id = 0LL; |
| 664 | player->last_segment_id = 0LL; |
| 665 | player->segment_is_open = DVR_FALSE; |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 666 | |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 667 | //init ff fb time |
| 668 | player->fffb_current = -1; |
| 669 | player->fffb_start =-1; |
| 670 | player->fffb_start_pcr = -1; |
| 671 | //seek time |
| 672 | player->seek_time = 0; |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 673 | *p_handle = player; |
| 674 | return DVR_SUCCESS; |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 675 | } |
| 676 | |
| 677 | /**\brief Close an dvr palyback |
| 678 | * \param[in] handle playback handle |
| 679 | * \retval DVR_SUCCESS On success |
| 680 | * \return Error code |
| 681 | */ |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 682 | int dvr_playback_close(DVR_PlaybackHandle_t handle) { |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 683 | |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 684 | DVR_ASSERT(handle); |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 685 | |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 686 | DVR_Playback_t *player = (DVR_Playback_t *) handle; |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame^] | 687 | DVR_DEBUG(1, "func: %s", __func__); |
| 688 | if (player->state != DVR_PLAYBACK_STATE_STOP) |
| 689 | { |
| 690 | dvr_playback_stop(handle, DVR_TRUE); |
| 691 | } |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 692 | playback_device_close(player->handle); |
| 693 | //device close |
| 694 | pthread_mutex_destroy(&player->lock); |
| 695 | pthread_cond_destroy(&player->cond); |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 696 | |
| 697 | if (player) { |
| 698 | free(player); |
| 699 | player = NULL; |
| 700 | } |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 701 | return DVR_SUCCESS; |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 702 | } |
| 703 | |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 704 | /**\brief Start play audio and video, used start auido api and start video api |
| 705 | * \param[in] handle playback handle |
| 706 | * \param[in] params audio playback params,contains fmt and pid... |
| 707 | * \retval DVR_SUCCESS On success |
| 708 | * \return Error code |
| 709 | */ |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 710 | int dvr_playback_start(DVR_PlaybackHandle_t handle, DVR_PlaybackFlag_t flag) { |
| 711 | DVR_Playback_t *player = (DVR_Playback_t *) handle; |
| 712 | Playback_DeviceVideoParams_t vparams; |
| 713 | Playback_DeviceAudioParams_t aparams; |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame^] | 714 | uint64_t segment_id = player->cur_segment_id; |
| 715 | DVR_DEBUG(1, "[%s][%p]segment_id:[%lld]",__func__, handle, segment_id); |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 716 | |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 717 | int sync = DVR_PLAYBACK_SYNC; |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame^] | 718 | //can used start api to resume playback |
| 719 | if (player->cmd.state == DVR_PLAYBACK_STATE_PAUSE) { |
| 720 | return dvr_playback_resume(handle); |
| 721 | } |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 722 | player->play_flag = flag; |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 723 | //get segment info and audio video pid fmt ; |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame^] | 724 | DVR_DEBUG(1, "lock func: %s %p", __func__, handle); |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 725 | pthread_mutex_lock(&player->lock); |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 726 | _dvr_playback_get_playinfo(handle, segment_id, &vparams, &aparams); |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 727 | //start audio and video |
| 728 | if (!VALID_PID(vparams.pid) && !VALID_PID(aparams.pid)) { |
| 729 | //audio abnd video pis is all invalid, return error. |
| 730 | DVR_DEBUG(0, "dvr play back start error, not found audio and video info"); |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame^] | 731 | DVR_DEBUG(1, "unlock func: %s", __func__); |
| 732 | pthread_mutex_unlock(&player->lock); |
| 733 | DVR_Play_Notify_t notify; |
| 734 | memset(¬ify, 0 , sizeof(DVR_Play_Notify_t)); |
| 735 | notify.event = DVR_PLAYBACK_EVENT_TRANSITION_FAILED; |
| 736 | notify.info.error_reason = DVR_PLAYBACK_PID_ERROR; |
| 737 | notify.info.transition_failed_data.segment_id = segment_id; |
| 738 | //get play statue not here |
| 739 | _dvr_playback_sent_event(handle, DVR_PLAYBACK_EVENT_TRANSITION_FAILED, ¬ify); |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 740 | return -1; |
| 741 | } |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 742 | |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame^] | 743 | { |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 744 | if (VALID_PID(vparams.pid)) { |
| 745 | player->has_video = DVR_TRUE; |
| 746 | playback_device_video_start(player->handle , &vparams); |
| 747 | //if set flag is pause live, we need set trick mode |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 748 | if ((player->play_flag&DVR_PLAYBACK_STARTED_PAUSEDLIVE) == DVR_PLAYBACK_STARTED_PAUSEDLIVE) { |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 749 | playback_device_trick_mode(player->handle, 1); |
| 750 | } |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 751 | } |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 752 | if (VALID_PID(aparams.pid)) { |
| 753 | player->has_audio = DVR_TRUE; |
| 754 | playback_device_audio_start(player->handle , &aparams); |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 755 | } |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame^] | 756 | DVR_DEBUG(1, "player->cmd.cur_cmd:%d", player->cmd.cur_cmd); |
| 757 | if (player->cmd.cur_cmd == DVR_PLAYBACK_CMD_FB |
| 758 | || player->cmd.cur_cmd == DVR_PLAYBACK_CMD_FF) { |
| 759 | player->cmd.state = DVR_PLAYBACK_STATE_START; |
| 760 | player->state = DVR_PLAYBACK_STATE_START; |
| 761 | if (player->has_video == DVR_TRUE) |
| 762 | playback_device_trick_mode(player->handle, 1); |
| 763 | DVR_DEBUG(1, "set trick mode ---at start"); |
| 764 | } else { |
| 765 | player->cmd.last_cmd = player->cmd.cur_cmd; |
| 766 | player->cmd.cur_cmd = DVR_PLAYBACK_CMD_START; |
| 767 | player->cmd.speed.speed.speed = PLAYBACK_SPEED_X1; |
| 768 | player->cmd.state = DVR_PLAYBACK_STATE_START; |
| 769 | player->state = DVR_PLAYBACK_STATE_START; |
| 770 | } |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 771 | } |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame^] | 772 | DVR_DEBUG(1, "unlock func: %s", __func__); |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 773 | pthread_mutex_unlock(&player->lock); |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 774 | _start_playback_thread(handle); |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 775 | return DVR_SUCCESS; |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 776 | } |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 777 | /**\brief dvr play back add segment info to segment list |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 778 | * \param[in] handle playback handle |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 779 | * \param[in] info added segment info,con vpid fmt apid fmt..... |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 780 | * \retval DVR_SUCCESS On success |
| 781 | * \return Error code |
| 782 | */ |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 783 | int dvr_playback_add_segment(DVR_PlaybackHandle_t handle, DVR_PlaybackSegmentInfo_t *info) { |
| 784 | DVR_Playback_t *player = (DVR_Playback_t *) handle; |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame^] | 785 | DVR_DEBUG(1, "[%s][%p]",__func__, handle); |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 786 | |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame^] | 787 | DVR_DEBUG(1, "add segment id: %lld %p", info->segment_id, handle); |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 788 | DVR_PlaybackSegmentInfo_t *segment; |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 789 | |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 790 | segment = malloc(sizeof(DVR_PlaybackSegmentInfo_t)); |
| 791 | memset(segment, 0, sizeof(DVR_PlaybackSegmentInfo_t)); |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 792 | |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 793 | //not memcpy chun info. |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 794 | segment->segment_id = info->segment_id; |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 795 | //cp location |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 796 | memcpy(segment->location, info->location, DVR_MAX_LOCATION_SIZE); |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame^] | 797 | |
| 798 | DVR_DEBUG(1, "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] | 799 | segment->flags = info->flags; |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 800 | |
| 801 | //pids |
| 802 | if (player->has_pids == DVR_TRUE) |
| 803 | memcpy(&segment->pids, &info->pids, sizeof(DVR_PlaybackPids_t)); |
| 804 | |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame^] | 805 | segment->pids.video.pid = info->pids.video.pid; |
| 806 | segment->pids.video.format = info->pids.video.format; |
| 807 | segment->pids.video.type = info->pids.video.type; |
| 808 | |
| 809 | segment->pids.audio.pid = info->pids.video.pid; |
| 810 | segment->pids.audio.format = info->pids.video.format; |
| 811 | segment->pids.audio.type = info->pids.video.type; |
| 812 | |
| 813 | segment->pids.ad.pid = info->pids.video.pid; |
| 814 | segment->pids.ad.format = info->pids.video.format; |
| 815 | segment->pids.ad.type = info->pids.video.type; |
| 816 | |
| 817 | segment->pids.pcr.pid = info->pids.pcr.pid; |
| 818 | |
| 819 | DVR_DEBUG(1, "lock func: %s pid [0x%x][0x%x][0x%x][0x%x]", __func__,segment->pids.video.pid,segment->pids.audio.pid, info->pids.video.pid,info->pids.audio.pid); |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 820 | pthread_mutex_lock(&player->lock); |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 821 | list_add_tail(&segment->head, &player->segment_list); |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 822 | pthread_mutex_unlock(&player->lock); |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame^] | 823 | DVR_DEBUG(1, "unlock func: %s", __func__); |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 824 | |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 825 | return DVR_SUCCESS; |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 826 | } |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 827 | /**\brief dvr play back remove segment info by segment_id |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 828 | * \param[in] handle playback handle |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 829 | * \param[in] segment_id need removed segment id |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 830 | * \retval DVR_SUCCESS On success |
| 831 | * \return Error code |
| 832 | */ |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 833 | 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] | 834 | DVR_Playback_t *player = (DVR_Playback_t *) handle; |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 835 | DVR_DEBUG(1, "remove segment id: %lld", segment_id); |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame^] | 836 | if (segment_id == player->cur_segment_id) { |
| 837 | DVR_DEBUG(1, "not suport remove curren segment id: %lld", segment_id); |
| 838 | return DVR_FAILURE; |
| 839 | } |
| 840 | DVR_DEBUG(1, "lock func: %s", __func__); |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 841 | pthread_mutex_lock(&player->lock); |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 842 | DVR_PlaybackSegmentInfo_t *segment; |
| 843 | list_for_each_entry(segment, &player->segment_list, head) |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 844 | { |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 845 | if (segment->segment_id == segment_id) { |
| 846 | list_del(&segment->head); |
| 847 | free(segment); |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 848 | break; |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 849 | } |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 850 | } |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame^] | 851 | DVR_DEBUG(1, "unlock func: %s", __func__); |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 852 | pthread_mutex_unlock(&player->lock); |
| 853 | |
| 854 | return DVR_SUCCESS; |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 855 | } |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 856 | /**\brief dvr play back add segment info |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 857 | * \param[in] handle playback handle |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 858 | * \param[in] info added segment info,con vpid fmt apid fmt..... |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 859 | * \retval DVR_SUCCESS On success |
| 860 | * \return Error code |
| 861 | */ |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 862 | int dvr_playback_update_segment_flags(DVR_PlaybackHandle_t handle, |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 863 | uint64_t segment_id, DVR_PlaybackSegmentFlag_t flags) { |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 864 | DVR_Playback_t *player = (DVR_Playback_t *) handle; |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 865 | DVR_DEBUG(1, "update segment id: %lld flag:%d", segment_id, flags); |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 866 | |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 867 | DVR_PlaybackSegmentInfo_t *segment; |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame^] | 868 | DVR_DEBUG(1, "lock func: %s", __func__); |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 869 | pthread_mutex_lock(&player->lock); |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 870 | list_for_each_entry(segment, &player->segment_list, head) |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 871 | { |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 872 | if (segment->segment_id != segment_id) { |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 873 | continue; |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 874 | } |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 875 | // if encramble to free, only set flag and return; |
| 876 | |
| 877 | //if displayable to none, we need mute audio and video |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 878 | if (segment_id == player->cur_segment_id) { |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 879 | if ((segment->flags & DVR_PLAYBACK_SEGMENT_DISPLAYABLE) == DVR_PLAYBACK_SEGMENT_DISPLAYABLE |
| 880 | && (flags & DVR_PLAYBACK_SEGMENT_DISPLAYABLE) == 0) { |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame^] | 881 | //disable display, mute |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 882 | playback_device_mute_audio(player->handle, 1); |
| 883 | playback_device_mute_video(player->handle, 1); |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 884 | } else if ((segment->flags & DVR_PLAYBACK_SEGMENT_DISPLAYABLE) == 0 && |
| 885 | (flags & DVR_PLAYBACK_SEGMENT_DISPLAYABLE) == DVR_PLAYBACK_SEGMENT_DISPLAYABLE) { |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame^] | 886 | //enable display, unmute |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 887 | playback_device_mute_audio(player->handle, 0); |
| 888 | playback_device_mute_video(player->handle, 0); |
| 889 | } else { |
| 890 | //do nothing |
| 891 | } |
| 892 | } else { |
| 893 | //do nothing |
| 894 | } |
| 895 | //continue , only set flag |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 896 | segment->flags = flags; |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 897 | } |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame^] | 898 | DVR_DEBUG(1, "unlock func: %s", __func__); |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 899 | pthread_mutex_unlock(&player->lock); |
| 900 | return DVR_SUCCESS; |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 901 | } |
| 902 | |
| 903 | |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 904 | static int _do_check_pid_info(DVR_PlaybackHandle_t handle, DVR_StreamInfo_t now_pid, DVR_StreamInfo_t set_pid, int type) { |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 905 | DVR_Playback_t *player = (DVR_Playback_t *) handle; |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame^] | 906 | DVR_DEBUG(1, "do check pid %p", handle); |
| 907 | DVR_DEBUG(1, "[%s][%p]",__func__, handle); |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 908 | |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 909 | if (now_pid.pid == set_pid.pid) { |
| 910 | //do nothing |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 911 | return 0; |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 912 | } else if (player->cmd.state == DVR_PLAYBACK_STATE_START) { |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 913 | if (VALID_PID(now_pid.pid)) { |
| 914 | //stop now stream |
| 915 | if (type == 0) { |
| 916 | //stop vieo |
| 917 | playback_device_video_stop(player->handle); |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 918 | player->has_video = DVR_FALSE; |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 919 | } else if (type == 1) { |
| 920 | //stop audio |
| 921 | playback_device_audio_stop(player->handle); |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 922 | player->has_audio = DVR_FALSE; |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 923 | } else if (type == 2) { |
| 924 | //stop sub audio |
| 925 | playback_device_audio_stop(player->handle); |
| 926 | } else if (type == 3) { |
| 927 | //pcr |
| 928 | } |
| 929 | } |
| 930 | if (VALID_PID(set_pid.pid)) { |
| 931 | //start |
| 932 | if (type == 0) { |
| 933 | //start vieo |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 934 | Playback_DeviceVideoParams_t vparams; |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 935 | vparams.pid = set_pid.pid; |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 936 | vparams.fmt = _dvr_convert_stream_fmt(set_pid.format, DVR_FALSE); |
| 937 | player->has_video = DVR_TRUE; |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame^] | 938 | playback_device_video_start(player->handle,&vparams); |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 939 | } else if (type == 1) { |
| 940 | //start audio |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 941 | Playback_DeviceAudioParams_t aparams; |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 942 | aparams.pid = set_pid.pid; |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 943 | aparams.fmt = _dvr_convert_stream_fmt(set_pid.format, DVR_TRUE); |
| 944 | player->has_audio = DVR_TRUE; |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame^] | 945 | playback_device_audio_start(player->handle,&aparams); |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 946 | } else if (type == 2) { |
| 947 | //start sub audio |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 948 | Playback_DeviceAudioParams_t aparams; |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 949 | aparams.pid = set_pid.pid; |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 950 | aparams.fmt = _dvr_convert_stream_fmt(set_pid.format, DVR_TRUE); |
| 951 | player->has_audio = DVR_TRUE; |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame^] | 952 | playback_device_audio_start(player->handle, &aparams); |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 953 | } else if (type == 3) { |
| 954 | //pcr |
| 955 | } |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 956 | //audio and video all close |
| 957 | if (!player->has_audio && !player->has_video) { |
| 958 | player->state = DVR_PLAYBACK_STATE_STOP; |
| 959 | } |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 960 | } |
| 961 | } |
| 962 | return 0; |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 963 | } |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 964 | /**\brief dvr play back update segment pids |
| 965 | * if updated segment is ongoing segment, we need start new |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 966 | * add pid stream and stop remove pid stream. |
| 967 | * \param[in] handle playback handle |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 968 | * \param[in] segment_id need updated pids segment id |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 969 | * \retval DVR_SUCCESS On success |
| 970 | * \return Error code |
| 971 | */ |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 972 | 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] | 973 | DVR_Playback_t *player = (DVR_Playback_t *) handle; |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame^] | 974 | DVR_DEBUG(1, "update segment id: %lld", segment_id); |
| 975 | DVR_DEBUG(1, "[%s][%p]",__func__, handle); |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 976 | |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 977 | DVR_PlaybackSegmentInfo_t *segment; |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame^] | 978 | DVR_DEBUG(1, "lock func: %s", __func__); |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 979 | pthread_mutex_lock(&player->lock); |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame^] | 980 | DVR_DEBUG(1, "get lock [%p] update segment id: %lld cur id %lld",handle, segment_id, player->cur_segment_id); |
| 981 | |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 982 | list_for_each_entry(segment, &player->segment_list, head) |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 983 | { |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 984 | if (segment->segment_id == segment_id) { |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 985 | |
| 986 | if (player->cur_segment_id == segment_id) { |
| 987 | if (player->cmd.state == DVR_PLAYBACK_STATE_FF |
| 988 | || player->cmd.state == DVR_PLAYBACK_STATE_FF) { |
| 989 | //do nothing when ff fb |
| 990 | DVR_DEBUG(1, "now is ff fb, not to update cur segment info\r\n"); |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame^] | 991 | DVR_DEBUG(1, "unlock func: %s", __func__); |
| 992 | pthread_mutex_unlock(&player->lock); |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 993 | return 0; |
| 994 | } |
| 995 | |
| 996 | //if segment is on going segment,we need stop start stream |
| 997 | if (player->cmd.state == DVR_PLAYBACK_STATE_START) { |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame^] | 998 | pthread_mutex_unlock(&player->lock); |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 999 | //check video pids, stop or restart |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame^] | 1000 | _do_check_pid_info((DVR_PlaybackHandle_t)player, segment->pids.video, p_pids->video, 0); |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 1001 | //check audio pids stop or restart |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame^] | 1002 | _do_check_pid_info((DVR_PlaybackHandle_t)player, segment->pids.audio, p_pids->audio, 1); |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 1003 | //check sub audio pids stop or restart |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame^] | 1004 | _do_check_pid_info((DVR_PlaybackHandle_t)player, segment->pids.ad, p_pids->ad, 2); |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 1005 | //check pcr pids stop or restart |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame^] | 1006 | _do_check_pid_info((DVR_PlaybackHandle_t)player, segment->pids.pcr, p_pids->pcr, 3); |
| 1007 | pthread_mutex_lock(&player->lock); |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 1008 | } else if (player->cmd.state == DVR_PLAYBACK_STATE_PAUSE) { |
| 1009 | //if state is pause, we need process at resume api. we only record change info |
| 1010 | int v_cmd = DVR_PLAYBACK_CMD_NONE; |
| 1011 | int a_cmd = DVR_PLAYBACK_CMD_NONE; |
| 1012 | if (VALID_PID(segment->pids.video.pid) |
| 1013 | && VALID_PID(p_pids->video.pid) |
| 1014 | && segment->pids.video.pid != p_pids->video.pid) { |
| 1015 | //restart video |
| 1016 | v_cmd = DVR_PLAYBACK_CMD_VRESTART; |
| 1017 | } |
| 1018 | if (!VALID_PID(segment->pids.video.pid) |
| 1019 | && VALID_PID(p_pids->video.pid) |
| 1020 | && segment->pids.video.pid != p_pids->video.pid) { |
| 1021 | //start video |
| 1022 | v_cmd = DVR_PLAYBACK_CMD_VSTART; |
| 1023 | } |
| 1024 | if (VALID_PID(segment->pids.video.pid) |
| 1025 | && !VALID_PID(p_pids->video.pid) |
| 1026 | && segment->pids.video.pid != p_pids->video.pid) { |
| 1027 | //stop video |
| 1028 | v_cmd = DVR_PLAYBACK_CMD_VSTOP; |
| 1029 | } |
| 1030 | if (VALID_PID(segment->pids.audio.pid) |
| 1031 | && VALID_PID(p_pids->audio.pid) |
| 1032 | && segment->pids.audio.pid != p_pids->audio.pid) { |
| 1033 | //restart audio |
| 1034 | a_cmd = DVR_PLAYBACK_CMD_ARESTART; |
| 1035 | } |
| 1036 | if (!VALID_PID(segment->pids.audio.pid) |
| 1037 | && VALID_PID(p_pids->audio.pid) |
| 1038 | && segment->pids.audio.pid != p_pids->audio.pid) { |
| 1039 | //start audio |
| 1040 | a_cmd = DVR_PLAYBACK_CMD_ASTART; |
| 1041 | } |
| 1042 | if (VALID_PID(segment->pids.audio.pid) |
| 1043 | && !VALID_PID(p_pids->audio.pid) |
| 1044 | && segment->pids.audio.pid != p_pids->audio.pid) { |
| 1045 | //stop audio |
| 1046 | a_cmd = DVR_PLAYBACK_CMD_ASTOP; |
| 1047 | } |
| 1048 | if (a_cmd == DVR_PLAYBACK_CMD_NONE |
| 1049 | && v_cmd == DVR_PLAYBACK_CMD_NONE) { |
| 1050 | //do nothing |
| 1051 | } else if (a_cmd == DVR_PLAYBACK_CMD_NONE |
| 1052 | || v_cmd == DVR_PLAYBACK_CMD_NONE) { |
| 1053 | player->cmd.last_cmd =DVR_PLAYBACK_CMD_PAUSE; |
| 1054 | player->cmd.cur_cmd = a_cmd != DVR_PLAYBACK_CMD_NONE ? a_cmd : v_cmd; |
| 1055 | } else if (a_cmd != DVR_PLAYBACK_CMD_NONE |
| 1056 | && v_cmd != DVR_PLAYBACK_CMD_NONE) { |
| 1057 | if (v_cmd == DVR_PLAYBACK_CMD_VRESTART |
| 1058 | && (a_cmd == DVR_PLAYBACK_CMD_ARESTART)) { |
| 1059 | player->cmd.last_cmd =DVR_PLAYBACK_CMD_PAUSE; |
| 1060 | player->cmd.cur_cmd = DVR_PLAYBACK_CMD_AVRESTART; |
| 1061 | }else if (v_cmd == DVR_PLAYBACK_CMD_VRESTART |
| 1062 | && a_cmd == DVR_PLAYBACK_CMD_ASTART) { |
| 1063 | player->cmd.last_cmd =DVR_PLAYBACK_CMD_PAUSE; |
| 1064 | player->cmd.cur_cmd = DVR_PLAYBACK_CMD_ASTARTVRESTART; |
| 1065 | } else { |
| 1066 | player->cmd.last_cmd =DVR_PLAYBACK_CMD_PAUSE; |
| 1067 | player->cmd.cur_cmd = DVR_PLAYBACK_CMD_ASTOPVRESTART; |
| 1068 | } |
| 1069 | |
| 1070 | if (v_cmd == DVR_PLAYBACK_CMD_VSTART |
| 1071 | && (a_cmd == DVR_PLAYBACK_CMD_ARESTART)) { |
| 1072 | player->cmd.last_cmd =DVR_PLAYBACK_CMD_PAUSE; |
| 1073 | player->cmd.cur_cmd = DVR_PLAYBACK_CMD_VSTARTARESTART; |
| 1074 | } else if (v_cmd == DVR_PLAYBACK_CMD_VSTART |
| 1075 | && a_cmd == DVR_PLAYBACK_CMD_ASTART) { |
| 1076 | //not occur this case |
| 1077 | player->cmd.last_cmd =DVR_PLAYBACK_CMD_PAUSE; |
| 1078 | player->cmd.cur_cmd = DVR_PLAYBACK_CMD_START; |
| 1079 | } else { |
| 1080 | player->cmd.last_cmd =DVR_PLAYBACK_CMD_PAUSE; |
| 1081 | player->cmd.cur_cmd = DVR_PLAYBACK_CMD_ASTOPVSTART; |
| 1082 | } |
| 1083 | |
| 1084 | if (v_cmd == DVR_PLAYBACK_CMD_VSTOP |
| 1085 | && a_cmd == DVR_PLAYBACK_CMD_ASTART) { |
| 1086 | player->cmd.last_cmd =DVR_PLAYBACK_CMD_PAUSE; |
| 1087 | player->cmd.cur_cmd = DVR_PLAYBACK_CMD_VSTOPASTART; |
| 1088 | } else if (v_cmd == DVR_PLAYBACK_CMD_VSTOP |
| 1089 | && a_cmd == DVR_PLAYBACK_CMD_ARESTART) { |
| 1090 | player->cmd.last_cmd =DVR_PLAYBACK_CMD_PAUSE; |
| 1091 | player->cmd.cur_cmd = DVR_PLAYBACK_CMD_VSTOPARESTART; |
| 1092 | } else { |
| 1093 | //not occur this case |
| 1094 | player->cmd.last_cmd =DVR_PLAYBACK_CMD_PAUSE; |
| 1095 | player->cmd.cur_cmd = DVR_PLAYBACK_CMD_STOP; |
| 1096 | } |
| 1097 | } |
| 1098 | } |
| 1099 | } |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1100 | //save pids info |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 1101 | memcpy(&segment->pids, p_pids, sizeof(DVR_PlaybackPids_t)); |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1102 | break; |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 1103 | } |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1104 | } |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame^] | 1105 | DVR_DEBUG(1, "unlock func: %s", __func__); |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1106 | pthread_mutex_unlock(&player->lock); |
| 1107 | return DVR_SUCCESS; |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 1108 | } |
| 1109 | /**\brief Stop play, will stop video and audio |
| 1110 | * \param[in] handle playback handle |
| 1111 | * \param[in] clear is clear last frame |
| 1112 | * \retval DVR_SUCCESS On success |
| 1113 | * \return Error code |
| 1114 | */ |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 1115 | int dvr_playback_stop(DVR_PlaybackHandle_t handle, DVR_Bool_t clear) { |
| 1116 | DVR_Playback_t *player = (DVR_Playback_t *) handle; |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame^] | 1117 | DVR_DEBUG(1, "---into-stop-----"); |
| 1118 | DVR_DEBUG(1, "lock func: %s", __func__); |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1119 | pthread_mutex_lock(&player->lock); |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame^] | 1120 | DVR_DEBUG(1, "---into-stop---1--"); |
| 1121 | |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1122 | playback_device_video_stop(player->handle); |
| 1123 | playback_device_audio_stop(player->handle); |
| 1124 | player->cmd.last_cmd = player->cmd.cur_cmd; |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 1125 | player->cmd.cur_cmd = DVR_PLAYBACK_CMD_STOP; |
| 1126 | player->cmd.state = DVR_PLAYBACK_STATE_STOP; |
| 1127 | player->state = DVR_PLAYBACK_STATE_STOP; |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame^] | 1128 | DVR_DEBUG(1, "unlock func: %s", __func__); |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1129 | pthread_mutex_unlock(&player->lock); |
| 1130 | //destory thread |
| 1131 | _stop_playback_thread(handle); |
| 1132 | return DVR_SUCCESS; |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 1133 | } |
| 1134 | /**\brief Start play audio |
| 1135 | * \param[in] handle playback handle |
| 1136 | * \param[in] params audio playback params,contains fmt and pid... |
| 1137 | * \retval DVR_SUCCESS On success |
| 1138 | * \return Error code |
| 1139 | */ |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 1140 | int dvr_playback_audio_start(DVR_PlaybackHandle_t handle, Playback_DeviceAudioParams_t *param) { |
| 1141 | DVR_Playback_t *player = (DVR_Playback_t *) handle; |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame^] | 1142 | DVR_DEBUG(1, "into func: %s", __func__); |
| 1143 | DVR_DEBUG(1, "[%s][%p]",__func__, handle); |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1144 | _start_playback_thread(handle); |
| 1145 | //start audio and video |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame^] | 1146 | DVR_DEBUG(1, "lock func: %s", __func__); |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1147 | pthread_mutex_lock(&player->lock); |
| 1148 | player->has_audio = DVR_TRUE; |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 1149 | playback_device_audio_start(player->handle , param); |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1150 | player->cmd.last_cmd = player->cmd.cur_cmd; |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 1151 | player->cmd.cur_cmd = DVR_PLAYBACK_CMD_ASTART; |
| 1152 | player->cmd.state = DVR_PLAYBACK_STATE_START; |
| 1153 | player->state = DVR_PLAYBACK_STATE_START; |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame^] | 1154 | DVR_DEBUG(1, "unlock func: %s", __func__); |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1155 | pthread_mutex_unlock(&player->lock); |
| 1156 | return DVR_SUCCESS; |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 1157 | } |
| 1158 | /**\brief Stop play audio |
| 1159 | * \param[in] handle playback handle |
| 1160 | * \retval DVR_SUCCESS On success |
| 1161 | * \return Error code |
| 1162 | */ |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 1163 | int dvr_playback_audio_stop(DVR_PlaybackHandle_t handle) { |
| 1164 | DVR_Playback_t *player = (DVR_Playback_t *) handle; |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame^] | 1165 | DVR_DEBUG(1, "lock func: %s", __func__); |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1166 | pthread_mutex_lock(&player->lock); |
| 1167 | player->has_audio = DVR_FALSE; |
| 1168 | playback_device_audio_stop(player->handle); |
| 1169 | |
| 1170 | player->cmd.last_cmd = player->cmd.cur_cmd; |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 1171 | player->cmd.cur_cmd = DVR_PLAYBACK_CMD_ASTOP; |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1172 | |
| 1173 | if (player->has_video == DVR_FALSE) { |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 1174 | player->cmd.state = DVR_PLAYBACK_STATE_STOP; |
| 1175 | player->state = DVR_PLAYBACK_STATE_STOP; |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1176 | //destory thread |
| 1177 | _stop_playback_thread(handle); |
| 1178 | } else { |
| 1179 | //do nothing.video is playing |
| 1180 | } |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame^] | 1181 | DVR_DEBUG(1, "unlock func: %s", __func__); |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1182 | pthread_mutex_unlock(&player->lock); |
| 1183 | return DVR_SUCCESS; |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 1184 | } |
| 1185 | /**\brief Start play video |
| 1186 | * \param[in] handle playback handle |
| 1187 | * \param[in] params video playback params,contains fmt and pid... |
| 1188 | * \retval DVR_SUCCESS On success |
| 1189 | * \return Error code |
| 1190 | */ |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 1191 | int dvr_playback_video_start(DVR_PlaybackHandle_t handle, Playback_DeviceVideoParams_t *param) { |
| 1192 | DVR_Playback_t *player = (DVR_Playback_t *) handle; |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1193 | _start_playback_thread(handle); |
| 1194 | //start audio and video |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame^] | 1195 | DVR_DEBUG(1, "lock func: %s", __func__); |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1196 | pthread_mutex_lock(&player->lock); |
| 1197 | player->has_video = DVR_TRUE; |
| 1198 | playback_device_video_start(player->handle , param); |
| 1199 | //if set flag is pause live, we need set trick mode |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 1200 | if ((player->play_flag&DVR_PLAYBACK_STARTED_PAUSEDLIVE) == DVR_PLAYBACK_STARTED_PAUSEDLIVE) { |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1201 | playback_device_trick_mode(player->handle, 1); |
| 1202 | } |
| 1203 | player->cmd.last_cmd = player->cmd.cur_cmd; |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 1204 | player->cmd.cur_cmd = DVR_PLAYBACK_CMD_VSTART; |
| 1205 | player->cmd.state = DVR_PLAYBACK_STATE_START; |
| 1206 | player->state = DVR_PLAYBACK_STATE_START; |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame^] | 1207 | DVR_DEBUG(1, "unlock func: %s", __func__); |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1208 | pthread_mutex_unlock(&player->lock); |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 1209 | return DVR_SUCCESS; |
| 1210 | } |
| 1211 | /**\brief Stop play video |
| 1212 | * \param[in] handle playback handle |
| 1213 | * \retval DVR_SUCCESS On success |
| 1214 | * \return Error code |
| 1215 | */ |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 1216 | int dvr_playback_video_stop(DVR_PlaybackHandle_t handle) { |
| 1217 | DVR_Playback_t *player = (DVR_Playback_t *) handle; |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame^] | 1218 | DVR_DEBUG(1, "lock func: %s", __func__); |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1219 | pthread_mutex_lock(&player->lock); |
| 1220 | player->has_video = DVR_FALSE; |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 1221 | playback_device_video_stop(player->handle); |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1222 | |
| 1223 | player->cmd.last_cmd = player->cmd.cur_cmd; |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 1224 | player->cmd.cur_cmd = DVR_PLAYBACK_CMD_VSTOP; |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1225 | |
| 1226 | if (player->has_audio == DVR_FALSE) { |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 1227 | player->cmd.state = DVR_PLAYBACK_STATE_STOP; |
| 1228 | player->state = DVR_PLAYBACK_STATE_STOP; |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1229 | //destory thread |
| 1230 | _stop_playback_thread(handle); |
| 1231 | } else { |
| 1232 | //do nothing.audio is playing |
| 1233 | } |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame^] | 1234 | DVR_DEBUG(1, "unlock func: %s", __func__); |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1235 | pthread_mutex_unlock(&player->lock); |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 1236 | return DVR_SUCCESS; |
| 1237 | } |
| 1238 | /**\brief Pause play |
| 1239 | * \param[in] handle playback handle |
| 1240 | * \param[in] flush whether its internal buffers should be flushed |
| 1241 | * \retval DVR_SUCCESS On success |
| 1242 | * \return Error code |
| 1243 | */ |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 1244 | int dvr_playback_pause(DVR_PlaybackHandle_t handle, DVR_Bool_t flush) { |
| 1245 | DVR_Playback_t *player = (DVR_Playback_t *) handle; |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame^] | 1246 | DVR_DEBUG(1, "lock func: %s", __func__); |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1247 | pthread_mutex_lock(&player->lock); |
| 1248 | playback_device_pause(player->handle); |
| 1249 | player->cmd.last_cmd = player->cmd.cur_cmd; |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 1250 | player->cmd.cur_cmd = DVR_PLAYBACK_CMD_PAUSE; |
| 1251 | player->cmd.state = DVR_PLAYBACK_STATE_PAUSE; |
| 1252 | player->state = DVR_PLAYBACK_STATE_PAUSE; |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame^] | 1253 | DVR_DEBUG(1, "unlock func: %s", __func__); |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1254 | pthread_mutex_unlock(&player->lock); |
| 1255 | return DVR_SUCCESS; |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 1256 | } |
| 1257 | |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 1258 | //not add lock |
| 1259 | static int _dvr_cmd(DVR_PlaybackHandle_t handle, int cmd) |
| 1260 | { |
| 1261 | DVR_Playback_t *player = (DVR_Playback_t *) handle; |
| 1262 | |
| 1263 | //get video params and audio params |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame^] | 1264 | DVR_DEBUG(1, "lock func: %s", __func__); |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 1265 | pthread_mutex_lock(&player->lock); |
| 1266 | Playback_DeviceVideoParams_t vparams; |
| 1267 | Playback_DeviceAudioParams_t aparams; |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame^] | 1268 | uint64_t segmentid = player->cur_segment_id; |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 1269 | |
| 1270 | _dvr_playback_get_playinfo(handle, segmentid, &vparams, &aparams); |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame^] | 1271 | DVR_DEBUG(1, "unlock func: %s", __func__); |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 1272 | pthread_mutex_unlock(&player->lock); |
| 1273 | |
| 1274 | switch (cmd) { |
| 1275 | case DVR_PLAYBACK_CMD_AVRESTART: |
| 1276 | //av restart |
| 1277 | dvr_playback_video_stop(player->handle); |
| 1278 | dvr_playback_audio_stop(player->handle); |
| 1279 | dvr_playback_video_start(player->handle, &vparams); |
| 1280 | dvr_playback_audio_start(player->handle, &aparams); |
| 1281 | break; |
| 1282 | case DVR_PLAYBACK_CMD_VRESTART: |
| 1283 | dvr_playback_video_stop(player->handle); |
| 1284 | dvr_playback_video_start(player->handle, &vparams); |
| 1285 | break; |
| 1286 | case DVR_PLAYBACK_CMD_VSTART: |
| 1287 | dvr_playback_video_start(player->handle, &vparams); |
| 1288 | break; |
| 1289 | case DVR_PLAYBACK_CMD_VSTOP: |
| 1290 | dvr_playback_video_stop(player->handle); |
| 1291 | break; |
| 1292 | case DVR_PLAYBACK_CMD_ARESTART: |
| 1293 | //a restart |
| 1294 | dvr_playback_audio_stop(player->handle); |
| 1295 | dvr_playback_audio_start(player->handle, &aparams); |
| 1296 | break; |
| 1297 | case DVR_PLAYBACK_CMD_ASTART: |
| 1298 | dvr_playback_audio_start(player->handle, &aparams); |
| 1299 | break; |
| 1300 | case DVR_PLAYBACK_CMD_ASTOP: |
| 1301 | dvr_playback_audio_stop(player->handle); |
| 1302 | break; |
| 1303 | case DVR_PLAYBACK_CMD_ASTOPVRESTART: |
| 1304 | dvr_playback_audio_stop(player->handle); |
| 1305 | dvr_playback_video_stop(player->handle); |
| 1306 | dvr_playback_video_start(player->handle, &vparams); |
| 1307 | break; |
| 1308 | case DVR_PLAYBACK_CMD_ASTOPVSTART: |
| 1309 | dvr_playback_audio_stop(player->handle); |
| 1310 | dvr_playback_video_start(player->handle, &vparams); |
| 1311 | break; |
| 1312 | case DVR_PLAYBACK_CMD_VSTOPARESTART: |
| 1313 | dvr_playback_video_stop(player->handle); |
| 1314 | dvr_playback_audio_stop(player->handle); |
| 1315 | dvr_playback_audio_start(player->handle, &aparams); |
| 1316 | break; |
| 1317 | case DVR_PLAYBACK_CMD_STOP: |
| 1318 | break; |
| 1319 | case DVR_PLAYBACK_CMD_START: |
| 1320 | break; |
| 1321 | case DVR_PLAYBACK_CMD_ASTARTVRESTART: |
| 1322 | dvr_playback_video_stop(player->handle); |
| 1323 | dvr_playback_video_start(player->handle, &vparams); |
| 1324 | dvr_playback_audio_start(player->handle, &aparams); |
| 1325 | break; |
| 1326 | case DVR_PLAYBACK_CMD_VSTARTARESTART: |
| 1327 | dvr_playback_audio_stop(player->handle); |
| 1328 | dvr_playback_video_start(player->handle, &vparams); |
| 1329 | dvr_playback_audio_start(player->handle, &aparams); |
| 1330 | break; |
| 1331 | case DVR_PLAYBACK_CMD_FF: |
| 1332 | case DVR_PLAYBACK_CMD_FB: |
| 1333 | _dvr_playback_fffb(player->handle); |
| 1334 | break; |
| 1335 | default: |
| 1336 | break; |
| 1337 | } |
| 1338 | return DVR_SUCCESS; |
| 1339 | } |
| 1340 | |
| 1341 | /**\brief Resume play |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 1342 | * \param[in] handle playback handle |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 1343 | * \retval DVR_SUCCESS On success |
| 1344 | * \return Error code |
| 1345 | */ |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 1346 | int dvr_playback_resume(DVR_PlaybackHandle_t handle) { |
| 1347 | DVR_Playback_t *player = (DVR_Playback_t *) handle; |
| 1348 | |
| 1349 | if (player->cmd.cur_cmd == DVR_PLAYBACK_CMD_PAUSE) { |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame^] | 1350 | DVR_DEBUG(1, "lock func: %s", __func__); |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 1351 | pthread_mutex_lock(&player->lock); |
| 1352 | playback_device_resume(player->handle); |
| 1353 | player->cmd.last_cmd = player->cmd.cur_cmd; |
| 1354 | player->cmd.cur_cmd = DVR_PLAYBACK_CMD_RESUME; |
| 1355 | player->cmd.state = DVR_PLAYBACK_STATE_START; |
| 1356 | player->state = DVR_PLAYBACK_STATE_START; |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame^] | 1357 | DVR_DEBUG(1, "unlock func: %s", __func__); |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 1358 | pthread_mutex_unlock(&player->lock); |
| 1359 | } else { |
| 1360 | //player->cmd.last_cmd = DVR_PLAYBACK_CMD_RESUME; |
| 1361 | _dvr_cmd(handle, player->cmd.cur_cmd); |
| 1362 | } |
| 1363 | return DVR_SUCCESS; |
| 1364 | } |
| 1365 | |
| 1366 | |
| 1367 | /**\brief seek |
| 1368 | * \param[in] handle playback handle |
| 1369 | * \param[in] time_offset time offset base cur segment |
| 1370 | * \retval DVR_SUCCESS On success |
| 1371 | * \return Error code |
| 1372 | */ |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame^] | 1373 | 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] | 1374 | DVR_Playback_t *player = (DVR_Playback_t *) handle; |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame^] | 1375 | DVR_DEBUG(1, "lock func: %s segment_id %llu time_offset %u", __func__, segment_id, (uint32_t)time_offset); |
| 1376 | DVR_DEBUG(1, "[%s][%p]---player->state[%d]----",__func__, handle, player->state); |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1377 | pthread_mutex_lock(&player->lock); |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame^] | 1378 | _dvr_get_cur_time(handle); |
| 1379 | _dvr_get_end_time(handle); |
| 1380 | |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1381 | int offset = -1; |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 1382 | //open segment if id is not current segment |
| 1383 | _dvr_open_segment(handle, segment_id); |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame^] | 1384 | DVR_DEBUG(1, "seek open id[%lld]flag[0x%x] time_offset %u", player->cur_segment.segment_id, player->cur_segment.flags, time_offset); |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1385 | //get file offset by time |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame^] | 1386 | offset = segment_seek(player->r_handle, (uint64_t)time_offset); |
| 1387 | DVR_DEBUG(0, "seek get offset by time offset, offset=%d time_offset %u",offset, time_offset); |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1388 | //seek file |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1389 | if (offset == -1) { |
| 1390 | //seek 2M data once for test |
| 1391 | //seek error |
| 1392 | offset = player->offset + (2*1014*1024); |
| 1393 | } |
| 1394 | player->offset = offset; |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame^] | 1395 | |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 1396 | if (player->state == DVR_PLAYBACK_STATE_STOP) { |
| 1397 | //only seek file,not start |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame^] | 1398 | DVR_DEBUG(1, "unlock func: %s", __func__); |
| 1399 | pthread_mutex_unlock(&player->lock); |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 1400 | return 0; |
| 1401 | } |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1402 | //stop play |
| 1403 | DVR_DEBUG(0, "seek stop play, not inject data"); |
| 1404 | if (player->has_video) |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 1405 | playback_device_video_stop(player->handle); |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame^] | 1406 | if (player->has_audio) |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 1407 | playback_device_audio_stop(player->handle); |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1408 | //start play |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 1409 | Playback_DeviceVideoParams_t vparams; |
| 1410 | Playback_DeviceAudioParams_t aparams; |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 1411 | |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 1412 | player->cur_segment_id = segment_id; |
| 1413 | |
| 1414 | int sync = DVR_PLAYBACK_SYNC; |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 1415 | //get segment info and audio video pid fmt ; |
| 1416 | _dvr_playback_get_playinfo(handle, segment_id, &vparams, &aparams); |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1417 | //start audio and video |
| 1418 | if (!VALID_PID(vparams.pid) && !VALID_PID(aparams.pid)) { |
| 1419 | //audio abnd video pis is all invalid, return error. |
| 1420 | DVR_DEBUG(0, "seek start dvr play back start error, not found audio and video info"); |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame^] | 1421 | DVR_DEBUG(1, "unlock func: %s", __func__); |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1422 | pthread_mutex_unlock(&player->lock); |
| 1423 | return -1; |
| 1424 | } |
| 1425 | //add |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 1426 | if (sync == DVR_PLAYBACK_SYNC) { |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1427 | if (VALID_PID(vparams.pid)) { |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 1428 | //player->has_video; |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1429 | playback_device_video_start(player->handle , &vparams); |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 1430 | if (player->cmd.cur_cmd == DVR_PLAYBACK_CMD_PAUSE) { |
| 1431 | //if is pause state. we need set trick mode. |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame^] | 1432 | DVR_DEBUG(1, "seek set trick mode", __func__); |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 1433 | playback_device_trick_mode(player->handle, 1); |
| 1434 | } |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 1435 | } |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1436 | if (VALID_PID(aparams.pid)) { |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 1437 | //player->has_video; |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1438 | playback_device_audio_start(player->handle , &aparams); |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 1439 | } |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1440 | } |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 1441 | |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1442 | player->cmd.last_cmd = player->cmd.cur_cmd; |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 1443 | player->cmd.cur_cmd = DVR_PLAYBACK_CMD_SEEK; |
| 1444 | player->cmd.state = DVR_PLAYBACK_STATE_START; |
| 1445 | player->state = DVR_PLAYBACK_STATE_START; |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame^] | 1446 | DVR_DEBUG(1, "unlock func: %s ---", __func__); |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1447 | pthread_mutex_unlock(&player->lock); |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 1448 | |
| 1449 | return DVR_SUCCESS; |
| 1450 | } |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 1451 | |
| 1452 | //get current segment current pcr time of read pos |
| 1453 | static int _dvr_get_cur_time(DVR_PlaybackHandle_t handle) { |
| 1454 | //get cur time of segment |
| 1455 | DVR_Playback_t *player = (DVR_Playback_t *) handle; |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame^] | 1456 | int cache = 500;//defalut es buf cache 500ms |
| 1457 | uint32_t cur = segment_tell_current_time(player->r_handle); |
| 1458 | return cur > cache ? cur - cache : cur; |
| 1459 | } |
| 1460 | |
| 1461 | //get current segment current pcr time of read pos |
| 1462 | static int _dvr_get_end_time(DVR_PlaybackHandle_t handle) { |
| 1463 | //get cur time of segment |
| 1464 | DVR_Playback_t *player = (DVR_Playback_t *) handle; |
| 1465 | //if (player->openParams.is_timeshift == DVR_TRUE) { |
| 1466 | //get dur real time |
| 1467 | return segment_tell_total_time(player->r_handle); |
| 1468 | //} |
| 1469 | //return player->dur; |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 1470 | } |
| 1471 | |
| 1472 | //start replay |
| 1473 | static int _dvr_playback_calculate_seekpos(DVR_PlaybackHandle_t handle) { |
| 1474 | |
| 1475 | DVR_Playback_t *player = (DVR_Playback_t *) handle; |
| 1476 | //calculate pcr seek time |
| 1477 | int t_diff = 0; |
| 1478 | int seek_time = 0; |
| 1479 | if (player->fffb_start == -1) { |
| 1480 | //set fffb start time ms |
| 1481 | player->fffb_start = _dvr_time_getClock(); |
| 1482 | player->fffb_current = player->fffb_start; |
| 1483 | //get segment current time pos |
| 1484 | player->fffb_start_pcr = _dvr_get_cur_time(handle); |
| 1485 | t_diff = 0; |
| 1486 | } else { |
| 1487 | player->fffb_current = _dvr_time_getClock(); |
| 1488 | t_diff = player->fffb_current - player->fffb_start; |
| 1489 | seek_time = player->fffb_start_pcr + t_diff *player->speed; |
| 1490 | //seek segment pos |
| 1491 | if (player->r_handle) { |
| 1492 | segment_seek(player->r_handle, seek_time); |
| 1493 | } else { |
| 1494 | // |
| 1495 | DVR_DEBUG(1, "segment not open,can not seek"); |
| 1496 | } |
| 1497 | } |
| 1498 | return 0; |
| 1499 | } |
| 1500 | |
| 1501 | |
| 1502 | //start replay |
| 1503 | static int _dvr_playback_fffb_replay(DVR_PlaybackHandle_t handle) { |
| 1504 | // |
| 1505 | DVR_Playback_t *player = (DVR_Playback_t *) handle; |
| 1506 | //stop |
| 1507 | if (player->has_video) |
| 1508 | playback_device_video_stop(player->handle); |
| 1509 | if (player->has_audio) |
| 1510 | playback_device_audio_stop(player->handle); |
| 1511 | //start video and audio |
| 1512 | |
| 1513 | Playback_DeviceVideoParams_t vparams; |
| 1514 | Playback_DeviceAudioParams_t aparams; |
| 1515 | uint64_t segment_id = 0; |
| 1516 | |
| 1517 | //get segment info and audio video pid fmt ; |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame^] | 1518 | //pthread_mutex_lock(&player->lock); |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 1519 | _dvr_playback_get_playinfo(handle, segment_id, &vparams, &aparams); |
| 1520 | //start audio and video |
| 1521 | if (!VALID_PID(vparams.pid) && !VALID_PID(aparams.pid)) { |
| 1522 | //audio abnd video pis is all invalid, return error. |
| 1523 | DVR_DEBUG(0, "dvr play back restart error, not found audio and video info"); |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame^] | 1524 | //pthread_mutex_unlock(&player->lock); |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 1525 | return -1; |
| 1526 | } |
| 1527 | |
| 1528 | if (VALID_PID(vparams.pid)) { |
| 1529 | player->has_video = DVR_TRUE; |
| 1530 | playback_device_video_start(player->handle , &vparams); |
| 1531 | //if set flag is pause live, we need set trick mode |
| 1532 | playback_device_trick_mode(player->handle, 1); |
| 1533 | } |
| 1534 | if (VALID_PID(aparams.pid)) { |
| 1535 | player->has_audio = DVR_TRUE; |
| 1536 | playback_device_audio_start(player->handle , &aparams); |
| 1537 | } |
| 1538 | |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame^] | 1539 | //pthread_mutex_unlock(&player->lock); |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 1540 | return 0; |
| 1541 | } |
| 1542 | |
| 1543 | static int _dvr_playback_fffb(DVR_PlaybackHandle_t handle) { |
| 1544 | DVR_Playback_t *player = (DVR_Playback_t *) handle; |
| 1545 | if (_dvr_time_getClock() < player->fffb_current + FFFB_SLEEP_TIME) |
| 1546 | return 0; |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame^] | 1547 | DVR_DEBUG(1, "lock func: %s", __func__); |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 1548 | pthread_mutex_lock(&player->lock); |
| 1549 | |
| 1550 | _dvr_playback_calculate_seekpos(handle); |
| 1551 | _dvr_playback_fffb_replay(handle); |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame^] | 1552 | DVR_DEBUG(1, "unlock func: %s", __func__); |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 1553 | |
| 1554 | pthread_mutex_unlock(&player->lock); |
| 1555 | return DVR_SUCCESS; |
| 1556 | } |
| 1557 | |
| 1558 | //start replay |
| 1559 | static int _dvr_playback_replay(DVR_PlaybackHandle_t handle) { |
| 1560 | // |
| 1561 | DVR_Playback_t *player = (DVR_Playback_t *) handle; |
| 1562 | //stop |
| 1563 | if (player->has_video) |
| 1564 | playback_device_video_stop(player->handle); |
| 1565 | if (player->has_audio) |
| 1566 | playback_device_audio_stop(player->handle); |
| 1567 | //start video and audio |
| 1568 | |
| 1569 | Playback_DeviceVideoParams_t vparams; |
| 1570 | Playback_DeviceAudioParams_t aparams; |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame^] | 1571 | uint64_t segment_id = 0LL; |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 1572 | |
| 1573 | //get segment info and audio video pid fmt ; |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame^] | 1574 | DVR_DEBUG(1, "lock func: %s", __func__); |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 1575 | pthread_mutex_lock(&player->lock); |
| 1576 | _dvr_playback_get_playinfo(handle, segment_id, &vparams, &aparams); |
| 1577 | //start audio and video |
| 1578 | if (!VALID_PID(vparams.pid) && !VALID_PID(aparams.pid)) { |
| 1579 | //audio abnd video pis is all invalid, return error. |
| 1580 | DVR_DEBUG(0, "dvr play back restart error, not found audio and video info"); |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame^] | 1581 | DVR_DEBUG(1, "unlock func: %s", __func__); |
| 1582 | pthread_mutex_unlock(&player->lock); |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 1583 | return -1; |
| 1584 | } |
| 1585 | |
| 1586 | if (VALID_PID(vparams.pid)) { |
| 1587 | player->has_video = DVR_TRUE; |
| 1588 | playback_device_video_start(player->handle , &vparams); |
| 1589 | //if set flag is pause live, we need set trick mode |
| 1590 | playback_device_trick_mode(player->handle, 1); |
| 1591 | } |
| 1592 | if (VALID_PID(aparams.pid)) { |
| 1593 | player->has_audio = DVR_TRUE; |
| 1594 | playback_device_audio_start(player->handle , &aparams); |
| 1595 | } |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame^] | 1596 | DVR_DEBUG(1, "unlock func: %s", __func__); |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 1597 | |
| 1598 | pthread_mutex_unlock(&player->lock); |
| 1599 | return 0; |
| 1600 | } |
| 1601 | |
| 1602 | |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 1603 | /**\brief Set play speed |
| 1604 | * \param[in] handle playback handle |
| 1605 | * \param[in] speed playback speed |
| 1606 | * \retval DVR_SUCCESS On success |
| 1607 | * \return Error code |
| 1608 | */ |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 1609 | int dvr_playback_set_speed(DVR_PlaybackHandle_t handle, DVR_PlaybackSpeed_t speed) { |
| 1610 | |
| 1611 | DVR_Playback_t *player = (DVR_Playback_t *) handle; |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame^] | 1612 | DVR_DEBUG(1, "lock func: %s", __func__); |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 1613 | pthread_mutex_lock(&player->lock); |
| 1614 | if (player->cmd.cur_cmd != DVR_PLAYBACK_CMD_FF |
| 1615 | && player->cmd.cur_cmd != DVR_PLAYBACK_CMD_FB) { |
| 1616 | player->cmd.last_cmd = player->cmd.cur_cmd; |
| 1617 | } |
| 1618 | //only set mode and speed info, we will deal ff fb at playback thread. |
| 1619 | player->cmd.speed.mode = speed.mode; |
| 1620 | player->cmd.speed.speed = speed.speed; |
| 1621 | if (speed.mode == DVR_PLAYBACK_FAST_FORWARD) |
| 1622 | player->speed = speed.speed.speed/100; |
| 1623 | else |
| 1624 | player->speed = -speed.speed.speed/100; |
| 1625 | |
| 1626 | if (speed.mode == DVR_PLAYBACK_FAST_FORWARD) |
| 1627 | player->cmd.cur_cmd = DVR_PLAYBACK_CMD_FF; |
| 1628 | else |
| 1629 | player->cmd.cur_cmd = DVR_PLAYBACK_CMD_FB; |
| 1630 | //need exit ff fb |
| 1631 | if (speed.speed.speed == PLAYBACK_SPEED_X1) { |
| 1632 | player->cmd.cur_cmd = DVR_PLAYBACK_CMD_AVRESTART; |
| 1633 | } |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame^] | 1634 | DVR_DEBUG(1, "unlock func: %s", __func__); |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 1635 | pthread_mutex_unlock(&player->lock); |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 1636 | |
| 1637 | return DVR_SUCCESS; |
| 1638 | } |
| 1639 | /**\brief Get playback status |
| 1640 | * \param[in] handle playback handle |
| 1641 | * \param[out] p_status playback status |
| 1642 | * \retval DVR_SUCCESS On success |
| 1643 | * \return Error code |
| 1644 | */ |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 1645 | int dvr_playback_get_status(DVR_PlaybackHandle_t handle, |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 1646 | DVR_PlaybackStatus_t *p_status) { |
| 1647 | // |
| 1648 | DVR_Playback_t *player = (DVR_Playback_t *) handle; |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame^] | 1649 | DVR_DEBUG(1, "get stat start [%p]", handle); |
| 1650 | //pthread_mutex_lock(&player->lock); |
| 1651 | //DVR_DEBUG(1, "lock func: %s", __func__); |
| 1652 | DVR_DEBUG(1, "get stat start id[%lld]", player->cur_segment_id); |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 1653 | |
| 1654 | p_status->state = player->state; |
| 1655 | p_status->segment_id = player->cur_segment_id; |
| 1656 | p_status->time_cur = _dvr_get_cur_time(handle); |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame^] | 1657 | p_status->time_end = _dvr_get_end_time(handle); |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 1658 | memcpy(&p_status->pids, &player->cur_segment.pids, sizeof(DVR_PlaybackPids_t)); |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame^] | 1659 | p_status->speed = player->cmd.speed.speed.speed; |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 1660 | p_status->flags = player->cur_segment.flags; |
hualing chen | cc91e1c | 2020-02-28 13:26:17 +0800 | [diff] [blame^] | 1661 | //pthread_mutex_unlock(&player->lock); |
| 1662 | //DVR_DEBUG(1, "unlock func: %s", __func__); |
| 1663 | DVR_DEBUG(1, "get stat start end [%d][%d] id[%lld]", p_status->time_cur, p_status->time_end, p_status->segment_id); |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 1664 | return DVR_SUCCESS; |
| 1665 | } |
| 1666 | |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 1667 | void _dvr_dump_segment(DVR_PlaybackSegmentInfo_t *segment) { |
| 1668 | if (segment != NULL) { |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 1669 | DVR_DEBUG(1, "segment id: %lld", segment->segment_id); |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 1670 | DVR_DEBUG(1, "segment flag: %d", segment->flags); |
| 1671 | DVR_DEBUG(1, "segment location: [%s]", segment->location); |
| 1672 | DVR_DEBUG(1, "segment vpid: 0x%x vfmt:0x%x", segment->pids.video.pid,segment->pids.video.format); |
| 1673 | DVR_DEBUG(1, "segment apid: 0x%x afmt:0x%x", segment->pids.audio.pid,segment->pids.audio.format); |
| 1674 | DVR_DEBUG(1, "segment pcr pid: 0x%x pcr fmt:0x%x", segment->pids.pcr.pid,segment->pids.pcr.format); |
| 1675 | DVR_DEBUG(1, "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] | 1676 | } |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 1677 | } |
| 1678 | |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 1679 | int dvr_dump_segmentinfo(DVR_PlaybackHandle_t handle, uint64_t segment_id) { |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 1680 | DVR_Playback_t *player = (DVR_Playback_t *) handle; |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 1681 | |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 1682 | DVR_PlaybackSegmentInfo_t *segment; |
| 1683 | list_for_each_entry(segment, &player->segment_list, head) |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1684 | { |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 1685 | if (segment_id >= 0) { |
| 1686 | if (segment->segment_id == segment_id) { |
| 1687 | _dvr_dump_segment(segment); |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1688 | break; |
| 1689 | } |
| 1690 | } else { |
hualing chen | 5cbe1a6 | 2020-02-10 16:36:36 +0800 | [diff] [blame] | 1691 | //printf segment info |
hualing chen | 040df22 | 2020-01-17 13:35:02 +0800 | [diff] [blame] | 1692 | _dvr_dump_segment(segment); |
hualing chen | 86e7d48 | 2020-01-16 15:13:33 +0800 | [diff] [blame] | 1693 | } |
| 1694 | } |
| 1695 | return 0; |
hualing chen | b31a6c6 | 2020-01-13 17:27:00 +0800 | [diff] [blame] | 1696 | } |