timeshift: Split timeshift_index_t in two separate datatypes.
This commit is contained in:
parent
869f95ee0f
commit
a300377036
4 changed files with 41 additions and 32 deletions
|
@ -24,36 +24,45 @@
|
|||
/**
|
||||
* Indexes of import data in the stream
|
||||
*/
|
||||
typedef struct timeshift_index
|
||||
typedef struct timeshift_index_iframe
|
||||
{
|
||||
off_t pos; ///< Position in the file
|
||||
union {
|
||||
int64_t time; ///< Packet time
|
||||
void *data; ///< Associated data
|
||||
};
|
||||
TAILQ_ENTRY(timeshift_index) link; ///< List entry
|
||||
} timeshift_index_t;
|
||||
off_t pos; ///< Position in the file
|
||||
int64_t time; ///< Packet time
|
||||
TAILQ_ENTRY(timeshift_index_iframe) link; ///< List entry
|
||||
} timeshift_index_iframe_t;
|
||||
|
||||
typedef TAILQ_HEAD(timeshift_index_list,timeshift_index) timeshift_index_list_t;
|
||||
typedef TAILQ_HEAD(timeshift_index_iframe_list,timeshift_index_iframe) timeshift_index_iframe_list_t;
|
||||
|
||||
/**
|
||||
* Indexes of import data in the stream
|
||||
*/
|
||||
typedef struct timeshift_index_data
|
||||
{
|
||||
off_t pos; ///< Position in the file
|
||||
void *data; ///< Associated data
|
||||
TAILQ_ENTRY(timeshift_index_data) link; ///< List entry
|
||||
} timeshift_index_data_t;
|
||||
|
||||
typedef TAILQ_HEAD(timeshift_index_data_list,timeshift_index_data) timeshift_index_data_list_t;
|
||||
|
||||
/**
|
||||
* Timeshift file
|
||||
*/
|
||||
typedef struct timeshift_file
|
||||
{
|
||||
int fd; ///< Write descriptor
|
||||
char *path; ///< Full path to file
|
||||
int fd; ///< Write descriptor
|
||||
char *path; ///< Full path to file
|
||||
|
||||
time_t time; ///< Files coarse timestamp
|
||||
size_t size; ///< Current file size;
|
||||
int64_t last; ///< Latest timestamp
|
||||
time_t time; ///< Files coarse timestamp
|
||||
size_t size; ///< Current file size;
|
||||
int64_t last; ///< Latest timestamp
|
||||
|
||||
uint8_t bad; ///< File is broken
|
||||
uint8_t bad; ///< File is broken
|
||||
|
||||
int refcount; ///< Reader ref count
|
||||
int refcount; ///< Reader ref count
|
||||
|
||||
timeshift_index_list_t iframes; ///< I-frame indexing
|
||||
timeshift_index_list_t sstart; ///< Stream start messages
|
||||
timeshift_index_iframe_list_t iframes; ///< I-frame indexing
|
||||
timeshift_index_data_list_t sstart; ///< Stream start messages
|
||||
|
||||
TAILQ_ENTRY(timeshift_file) link; ///< List entry
|
||||
} timeshift_file_t;
|
||||
|
|
|
@ -46,7 +46,8 @@ static void* timeshift_reaper_callback ( void *p )
|
|||
{
|
||||
char *dpath;
|
||||
timeshift_file_t *tsf;
|
||||
timeshift_index_t *ti;
|
||||
timeshift_index_iframe_t *ti;
|
||||
timeshift_index_data_t *tid;
|
||||
streaming_message_t *sm;
|
||||
pthread_mutex_lock(×hift_reaper_lock);
|
||||
while (timeshift_reaper_run) {
|
||||
|
@ -77,11 +78,11 @@ static void* timeshift_reaper_callback ( void *p )
|
|||
TAILQ_REMOVE(&tsf->iframes, ti, link);
|
||||
free(ti);
|
||||
}
|
||||
while ((ti = TAILQ_FIRST(&tsf->sstart))) {
|
||||
TAILQ_REMOVE(&tsf->sstart, ti, link);
|
||||
sm = ti->data;
|
||||
while ((tid = TAILQ_FIRST(&tsf->sstart))) {
|
||||
TAILQ_REMOVE(&tsf->sstart, tid, link);
|
||||
sm = tid->data;
|
||||
streaming_msg_free(sm);
|
||||
free(ti);
|
||||
free(tid);
|
||||
}
|
||||
free(tsf->path);
|
||||
free(tsf);
|
||||
|
@ -161,7 +162,7 @@ timeshift_file_t *timeshift_filemgr_get ( timeshift_t *ts, int create )
|
|||
int fd;
|
||||
struct timespec tp;
|
||||
timeshift_file_t *tsf_tl, *tsf_hd, *tsf_tmp;
|
||||
timeshift_index_t *ti;
|
||||
timeshift_index_data_t *ti;
|
||||
char path[512];
|
||||
|
||||
/* Return last file */
|
||||
|
@ -218,13 +219,12 @@ timeshift_file_t *timeshift_filemgr_get ( timeshift_t *ts, int create )
|
|||
TAILQ_INSERT_TAIL(&ts->files, tsf_tmp, link);
|
||||
|
||||
/* Copy across last start message */
|
||||
if (tsf_tl && (ti = TAILQ_LAST(&tsf_tl->sstart, timeshift_index_list))) {
|
||||
if (tsf_tl && (ti = TAILQ_LAST(&tsf_tl->sstart, timeshift_index_data_list))) {
|
||||
#ifdef TSHFT_TRACE
|
||||
tvhlog(LOG_DEBUG, "timeshift", "ts %d copy smt_start to new file",
|
||||
ts->id);
|
||||
#endif
|
||||
timeshift_index_t *ti2 = calloc(1, sizeof(timeshift_index_t));
|
||||
ti2->pos = ti->pos;
|
||||
timeshift_index_data_t *ti2 = calloc(1, sizeof(timeshift_index_data_t));
|
||||
ti2->data = streaming_msg_clone(ti->data);
|
||||
TAILQ_INSERT_TAIL(&tsf_tmp->sstart, ti2, link);
|
||||
}
|
||||
|
|
|
@ -180,7 +180,7 @@ void *timeshift_reader ( void *p )
|
|||
int64_t now, deliver;
|
||||
streaming_message_t *sm = NULL, *ctrl;
|
||||
timeshift_file_t *cur_file = NULL, *tsi_file = NULL;
|
||||
timeshift_index_t *tsi = NULL;
|
||||
timeshift_index_iframe_t *tsi = NULL;
|
||||
|
||||
/* Poll */
|
||||
struct epoll_event ev;
|
||||
|
@ -311,7 +311,7 @@ void *timeshift_reader ( void *p )
|
|||
if (cur_speed < 0) {
|
||||
if (!tsi) {
|
||||
TAILQ_FOREACH_REVERSE(tsi, &tsi_file->iframes,
|
||||
timeshift_index_list, link) {
|
||||
timeshift_index_iframe_list, link) {
|
||||
if (tsi->time < last_time) break;
|
||||
}
|
||||
}
|
||||
|
@ -378,7 +378,7 @@ void *timeshift_reader ( void *p )
|
|||
|
||||
/* Next index */
|
||||
if (cur_speed < 0)
|
||||
tsi = TAILQ_PREV(tsi, timeshift_index_list, link);
|
||||
tsi = TAILQ_PREV(tsi, timeshift_index_iframe_list, link);
|
||||
else
|
||||
tsi = TAILQ_NEXT(tsi, link);
|
||||
|
||||
|
|
|
@ -188,7 +188,7 @@ static inline ssize_t _process_msg0
|
|||
streaming_message_t *sm = *smp;
|
||||
if (sm->sm_type == SMT_START) {
|
||||
err = 0;
|
||||
timeshift_index_t *ti = calloc(1, sizeof(timeshift_index_t));
|
||||
timeshift_index_data_t *ti = calloc(1, sizeof(timeshift_index_data_t));
|
||||
ti->pos = tsf->size;
|
||||
ti->data = sm;
|
||||
*smp = NULL;
|
||||
|
@ -209,7 +209,7 @@ static inline ssize_t _process_msg0
|
|||
/* Index video iframes */
|
||||
if (pkt->pkt_componentindex == ts->vididx &&
|
||||
pkt->pkt_frametype == PKT_I_FRAME) {
|
||||
timeshift_index_t *ti = calloc(1, sizeof(timeshift_index_t));
|
||||
timeshift_index_iframe_t *ti = calloc(1, sizeof(timeshift_index_iframe_t));
|
||||
ti->pos = tsf->size;
|
||||
ti->time = sm->sm_time;
|
||||
TAILQ_INSERT_TAIL(&tsf->iframes, ti, link);
|
||||
|
|
Loading…
Add table
Reference in a new issue