1/*
2Copyright (c) 2012, Broadcom Europe Ltd
3All rights reserved.
4
5Redistribution and use in source and binary forms, with or without
6modification, are permitted provided that the following conditions are met:
7 * Redistributions of source code must retain the above copyright
8 notice, this list of conditions and the following disclaimer.
9 * Redistributions in binary form must reproduce the above copyright
10 notice, this list of conditions and the following disclaimer in the
11 documentation and/or other materials provided with the distribution.
12 * Neither the name of the copyright holder nor the
13 names of its contributors may be used to endorse or promote products
14 derived from this software without specific prior written permission.
15
16THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
20DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26*/
27#ifndef VC_CONTAINERS_INDEX_H
28#define VC_CONTAINERS_INDEX_H
29
30/** \file containers_index.h
31 * Definition of index utilitie for containers. Creates and maintains an
32 * index of file offsets and times, and is able to suggest a file position
33 * to seek to achieve a given time target. Useful for container formats
34 * that don't include an index.
35 */
36
37#include "containers/containers.h"
38
39struct VC_CONTAINER_INDEX_T;
40typedef struct VC_CONTAINER_INDEX_T VC_CONTAINER_INDEX_T;
41
42/**
43 * Creates an index with a suggested number of entries.
44 * @param index Pointer to created index will be filled here on success.
45 * @param length Suggested length of index.
46 * @return Status code
47 */
48VC_CONTAINER_STATUS_T vc_container_index_create( VC_CONTAINER_INDEX_T **index, int length );
49
50
51/**
52 * Frees an index.
53 * @param index Pointer to valid index.
54 * @return Status code.
55 */
56VC_CONTAINER_STATUS_T vc_container_index_free( VC_CONTAINER_INDEX_T *index );
57
58
59/**
60 * Adds an entry to the index. If the index is full then some stored records will be
61 * discarded.
62 * @param index Pointer to a valid index.
63 * @param time Timestamp of new index entry.
64 * @param file_offset File offset for new index entry.
65 * @return Status code
66 */
67VC_CONTAINER_STATUS_T vc_container_index_add( VC_CONTAINER_INDEX_T *index, int64_t time, int64_t file_offset );
68
69
70/**
71 * Retrieves the best entry for the supplied time offset.
72 * @param index Pointer to valid index.
73 * @param later If true, the selected entry is the earliest retained entry with a greater or equal timestamp.
74 * If false, the selected entry is the latest retained entry with an earlier or equal timestamp.
75 * @param time The requested time. On success, this is filled in with the time of the selected entry.
76 * @param file_offset On success, this is filled in with the file offset of the selected entry.
77 * @param past Set if the requested time is after the last entry in the index.
78 * @return Status code.
79 */
80VC_CONTAINER_STATUS_T vc_container_index_get( VC_CONTAINER_INDEX_T *index, int later, int64_t *time, int64_t *file_offset, int *past );
81
82#endif /* VC_CONTAINERS_WRITER_UTILS_H */
83