Mercurial > libavformat.hg
annotate seek.h @ 5571:3fd13093ca7c libavformat
Change on rtsp_send_cmd() to the _async() version since we don't use the
response anyway.
author | rbultje |
---|---|
date | Thu, 21 Jan 2010 20:01:11 +0000 |
parents | 26ba0ebacbb2 |
children |
rev | line source |
---|---|
5139
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
1 /* |
5158
26ba0ebacbb2
cosmetic changes (indentation, doxygen comments, braces, put structures for API to header, ...)
schreter
parents:
5139
diff
changeset
|
2 * seek utility functions for use within format handlers |
5139
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
3 * |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
4 * Copyright (c) 2009 Ivan Schreter |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
5 * |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
6 * This file is part of FFmpeg. |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
7 * |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
8 * FFmpeg is free software; you can redistribute it and/or |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
9 * modify it under the terms of the GNU Lesser General Public |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
10 * License as published by the Free Software Foundation; either |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
11 * version 2.1 of the License, or (at your option) any later version. |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
12 * |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
13 * FFmpeg is distributed in the hope that it will be useful, |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
16 * Lesser General Public License for more details. |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
17 * |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
18 * You should have received a copy of the GNU Lesser General Public |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
19 * License along with FFmpeg; if not, write to the Free Software |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
21 */ |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
22 |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
23 #ifndef AVFORMAT_SEEK_H |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
24 #define AVFORMAT_SEEK_H |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
25 |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
26 #include "avformat.h" |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
27 |
5158
26ba0ebacbb2
cosmetic changes (indentation, doxygen comments, braces, put structures for API to header, ...)
schreter
parents:
5139
diff
changeset
|
28 /** |
26ba0ebacbb2
cosmetic changes (indentation, doxygen comments, braces, put structures for API to header, ...)
schreter
parents:
5139
diff
changeset
|
29 * structure to store parser state of one AVStream |
26ba0ebacbb2
cosmetic changes (indentation, doxygen comments, braces, put structures for API to header, ...)
schreter
parents:
5139
diff
changeset
|
30 */ |
26ba0ebacbb2
cosmetic changes (indentation, doxygen comments, braces, put structures for API to header, ...)
schreter
parents:
5139
diff
changeset
|
31 typedef struct AVParserStreamState { |
26ba0ebacbb2
cosmetic changes (indentation, doxygen comments, braces, put structures for API to header, ...)
schreter
parents:
5139
diff
changeset
|
32 // saved members of AVStream |
26ba0ebacbb2
cosmetic changes (indentation, doxygen comments, braces, put structures for API to header, ...)
schreter
parents:
5139
diff
changeset
|
33 AVCodecParserContext *parser; |
26ba0ebacbb2
cosmetic changes (indentation, doxygen comments, braces, put structures for API to header, ...)
schreter
parents:
5139
diff
changeset
|
34 AVPacket cur_pkt; |
26ba0ebacbb2
cosmetic changes (indentation, doxygen comments, braces, put structures for API to header, ...)
schreter
parents:
5139
diff
changeset
|
35 int64_t last_IP_pts; |
26ba0ebacbb2
cosmetic changes (indentation, doxygen comments, braces, put structures for API to header, ...)
schreter
parents:
5139
diff
changeset
|
36 int64_t cur_dts; |
26ba0ebacbb2
cosmetic changes (indentation, doxygen comments, braces, put structures for API to header, ...)
schreter
parents:
5139
diff
changeset
|
37 int64_t reference_dts; |
26ba0ebacbb2
cosmetic changes (indentation, doxygen comments, braces, put structures for API to header, ...)
schreter
parents:
5139
diff
changeset
|
38 const uint8_t *cur_ptr; |
26ba0ebacbb2
cosmetic changes (indentation, doxygen comments, braces, put structures for API to header, ...)
schreter
parents:
5139
diff
changeset
|
39 int cur_len; |
26ba0ebacbb2
cosmetic changes (indentation, doxygen comments, braces, put structures for API to header, ...)
schreter
parents:
5139
diff
changeset
|
40 int probe_packets; |
26ba0ebacbb2
cosmetic changes (indentation, doxygen comments, braces, put structures for API to header, ...)
schreter
parents:
5139
diff
changeset
|
41 } AVParserStreamState; |
5139
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
42 |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
43 /** |
5158
26ba0ebacbb2
cosmetic changes (indentation, doxygen comments, braces, put structures for API to header, ...)
schreter
parents:
5139
diff
changeset
|
44 * structure to store parser state of AVFormat |
26ba0ebacbb2
cosmetic changes (indentation, doxygen comments, braces, put structures for API to header, ...)
schreter
parents:
5139
diff
changeset
|
45 */ |
26ba0ebacbb2
cosmetic changes (indentation, doxygen comments, braces, put structures for API to header, ...)
schreter
parents:
5139
diff
changeset
|
46 typedef struct AVParserState { |
26ba0ebacbb2
cosmetic changes (indentation, doxygen comments, braces, put structures for API to header, ...)
schreter
parents:
5139
diff
changeset
|
47 int64_t fpos; ///< file position at the time of call |
26ba0ebacbb2
cosmetic changes (indentation, doxygen comments, braces, put structures for API to header, ...)
schreter
parents:
5139
diff
changeset
|
48 |
26ba0ebacbb2
cosmetic changes (indentation, doxygen comments, braces, put structures for API to header, ...)
schreter
parents:
5139
diff
changeset
|
49 // saved members of AVFormatContext |
26ba0ebacbb2
cosmetic changes (indentation, doxygen comments, braces, put structures for API to header, ...)
schreter
parents:
5139
diff
changeset
|
50 AVStream *cur_st; ///< current stream. |
26ba0ebacbb2
cosmetic changes (indentation, doxygen comments, braces, put structures for API to header, ...)
schreter
parents:
5139
diff
changeset
|
51 AVPacketList *packet_buffer; ///< packet buffer of original state |
26ba0ebacbb2
cosmetic changes (indentation, doxygen comments, braces, put structures for API to header, ...)
schreter
parents:
5139
diff
changeset
|
52 AVPacketList *raw_packet_buffer; ///< raw packet buffer of original state |
26ba0ebacbb2
cosmetic changes (indentation, doxygen comments, braces, put structures for API to header, ...)
schreter
parents:
5139
diff
changeset
|
53 int raw_packet_buffer_remaining_size; ///< remaining space in raw_packet_buffer |
26ba0ebacbb2
cosmetic changes (indentation, doxygen comments, braces, put structures for API to header, ...)
schreter
parents:
5139
diff
changeset
|
54 |
26ba0ebacbb2
cosmetic changes (indentation, doxygen comments, braces, put structures for API to header, ...)
schreter
parents:
5139
diff
changeset
|
55 // saved info for streams |
26ba0ebacbb2
cosmetic changes (indentation, doxygen comments, braces, put structures for API to header, ...)
schreter
parents:
5139
diff
changeset
|
56 int nb_streams; ///< number of streams with stored state |
26ba0ebacbb2
cosmetic changes (indentation, doxygen comments, braces, put structures for API to header, ...)
schreter
parents:
5139
diff
changeset
|
57 AVParserStreamState *stream_states; ///< states of individual streams (array) |
26ba0ebacbb2
cosmetic changes (indentation, doxygen comments, braces, put structures for API to header, ...)
schreter
parents:
5139
diff
changeset
|
58 } AVParserState; |
26ba0ebacbb2
cosmetic changes (indentation, doxygen comments, braces, put structures for API to header, ...)
schreter
parents:
5139
diff
changeset
|
59 |
26ba0ebacbb2
cosmetic changes (indentation, doxygen comments, braces, put structures for API to header, ...)
schreter
parents:
5139
diff
changeset
|
60 /** |
26ba0ebacbb2
cosmetic changes (indentation, doxygen comments, braces, put structures for API to header, ...)
schreter
parents:
5139
diff
changeset
|
61 * Search for the sync point of all active streams. |
5139
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
62 * |
5158
26ba0ebacbb2
cosmetic changes (indentation, doxygen comments, braces, put structures for API to header, ...)
schreter
parents:
5139
diff
changeset
|
63 * This routine is not supposed to be called directly by a user application, |
5139
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
64 * but by demuxers. |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
65 * |
5158
26ba0ebacbb2
cosmetic changes (indentation, doxygen comments, braces, put structures for API to header, ...)
schreter
parents:
5139
diff
changeset
|
66 * A sync point is defined as a point in stream, such that, when decoding start |
26ba0ebacbb2
cosmetic changes (indentation, doxygen comments, braces, put structures for API to header, ...)
schreter
parents:
5139
diff
changeset
|
67 * from this point, the decoded output of all streams synchronizes closest |
26ba0ebacbb2
cosmetic changes (indentation, doxygen comments, braces, put structures for API to header, ...)
schreter
parents:
5139
diff
changeset
|
68 * to the given timestamp ts. This routine also takes timestamp limits into account. |
26ba0ebacbb2
cosmetic changes (indentation, doxygen comments, braces, put structures for API to header, ...)
schreter
parents:
5139
diff
changeset
|
69 * Thus, the output will synchronize no sooner than ts_min and no later than ts_max. |
5139
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
70 * |
5158
26ba0ebacbb2
cosmetic changes (indentation, doxygen comments, braces, put structures for API to header, ...)
schreter
parents:
5139
diff
changeset
|
71 * @param stream_index stream index for time base reference of timestamps |
26ba0ebacbb2
cosmetic changes (indentation, doxygen comments, braces, put structures for API to header, ...)
schreter
parents:
5139
diff
changeset
|
72 * @param pos approximate position where to start searching for key frames |
26ba0ebacbb2
cosmetic changes (indentation, doxygen comments, braces, put structures for API to header, ...)
schreter
parents:
5139
diff
changeset
|
73 * @param min_ts minimum allowed timestamp (position, if AVSEEK_FLAG_BYTE set) |
26ba0ebacbb2
cosmetic changes (indentation, doxygen comments, braces, put structures for API to header, ...)
schreter
parents:
5139
diff
changeset
|
74 * @param ts target timestamp (or position, if AVSEEK_FLAG_BYTE set in flags) |
26ba0ebacbb2
cosmetic changes (indentation, doxygen comments, braces, put structures for API to header, ...)
schreter
parents:
5139
diff
changeset
|
75 * @param max_ts maximum allowed timestamp (position, if AVSEEK_FLAG_BYTE set) |
26ba0ebacbb2
cosmetic changes (indentation, doxygen comments, braces, put structures for API to header, ...)
schreter
parents:
5139
diff
changeset
|
76 * @param flags if AVSEEK_FLAG_ANY is set, seek to any frame, otherwise only |
26ba0ebacbb2
cosmetic changes (indentation, doxygen comments, braces, put structures for API to header, ...)
schreter
parents:
5139
diff
changeset
|
77 * to a keyframe. If AVSEEK_FLAG_BYTE is set, search by |
26ba0ebacbb2
cosmetic changes (indentation, doxygen comments, braces, put structures for API to header, ...)
schreter
parents:
5139
diff
changeset
|
78 * position, not by timestamp. |
26ba0ebacbb2
cosmetic changes (indentation, doxygen comments, braces, put structures for API to header, ...)
schreter
parents:
5139
diff
changeset
|
79 * @return -1 if no such sync point could be found, otherwise stream position |
26ba0ebacbb2
cosmetic changes (indentation, doxygen comments, braces, put structures for API to header, ...)
schreter
parents:
5139
diff
changeset
|
80 * (stream is repositioned to this position) |
5139
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
81 */ |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
82 int64_t ff_gen_syncpoint_search(AVFormatContext *s, |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
83 int stream_index, |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
84 int64_t pos, |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
85 int64_t min_ts, |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
86 int64_t ts, |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
87 int64_t max_ts, |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
88 int flags); |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
89 |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
90 /** |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
91 * Store current parser state and file position. |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
92 * |
5158
26ba0ebacbb2
cosmetic changes (indentation, doxygen comments, braces, put structures for API to header, ...)
schreter
parents:
5139
diff
changeset
|
93 * This function can be used by demuxers before a destructive seeking algorithm |
26ba0ebacbb2
cosmetic changes (indentation, doxygen comments, braces, put structures for API to header, ...)
schreter
parents:
5139
diff
changeset
|
94 * to store the parser state. Depending on the outcome of the seek, either the original |
26ba0ebacbb2
cosmetic changes (indentation, doxygen comments, braces, put structures for API to header, ...)
schreter
parents:
5139
diff
changeset
|
95 * state can be restored or the new state kept and the original state freed. |
5139
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
96 * |
5158
26ba0ebacbb2
cosmetic changes (indentation, doxygen comments, braces, put structures for API to header, ...)
schreter
parents:
5139
diff
changeset
|
97 * @note As a side effect, the original parser state is reset, since structures |
26ba0ebacbb2
cosmetic changes (indentation, doxygen comments, braces, put structures for API to header, ...)
schreter
parents:
5139
diff
changeset
|
98 * are relinked to the stored state instead of being deeply-copied (for |
26ba0ebacbb2
cosmetic changes (indentation, doxygen comments, braces, put structures for API to header, ...)
schreter
parents:
5139
diff
changeset
|
99 * performance reasons and to keep the code simple). |
5139
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
100 * |
5158
26ba0ebacbb2
cosmetic changes (indentation, doxygen comments, braces, put structures for API to header, ...)
schreter
parents:
5139
diff
changeset
|
101 * @param s context from which to save state |
26ba0ebacbb2
cosmetic changes (indentation, doxygen comments, braces, put structures for API to header, ...)
schreter
parents:
5139
diff
changeset
|
102 * @return parser state object or NULL if memory could not be allocated |
5139
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
103 */ |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
104 AVParserState *ff_store_parser_state(AVFormatContext *s); |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
105 |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
106 /** |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
107 * Restore previously saved parser state and file position. |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
108 * |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
109 * Saved state will be invalidated and freed by this call, since internal |
5158
26ba0ebacbb2
cosmetic changes (indentation, doxygen comments, braces, put structures for API to header, ...)
schreter
parents:
5139
diff
changeset
|
110 * structures will be relinked back to the stored state instead of being |
5139
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
111 * deeply-copied. |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
112 * |
5158
26ba0ebacbb2
cosmetic changes (indentation, doxygen comments, braces, put structures for API to header, ...)
schreter
parents:
5139
diff
changeset
|
113 * @param s context to which to restore state (same as used for storing state) |
26ba0ebacbb2
cosmetic changes (indentation, doxygen comments, braces, put structures for API to header, ...)
schreter
parents:
5139
diff
changeset
|
114 * @param state state to restore |
5139
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
115 */ |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
116 void ff_restore_parser_state(AVFormatContext *s, AVParserState *state); |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
117 |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
118 /** |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
119 * Free previously saved parser state. |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
120 * |
5158
26ba0ebacbb2
cosmetic changes (indentation, doxygen comments, braces, put structures for API to header, ...)
schreter
parents:
5139
diff
changeset
|
121 * @param s context to which the state belongs (same as used for storing state) |
26ba0ebacbb2
cosmetic changes (indentation, doxygen comments, braces, put structures for API to header, ...)
schreter
parents:
5139
diff
changeset
|
122 * @param state state to free |
5139
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
123 */ |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
124 void ff_free_parser_state(AVFormatContext *s, AVParserState *state); |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
125 |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
126 #endif /* AVFORMAT_SEEK_H */ |