Mercurial > libavformat.hg
annotate seek.c @ 5400:c7d1e90d4935 libavformat
Read and write extended timestamps for RTMP packets.
Extracted from patch by Sergiy in thread "[PATCH] rtmp-output"
author | kostya |
---|---|
date | Tue, 01 Dec 2009 15:07:32 +0000 |
parents | 44e53fe2e9ca |
children | 6f5cdb0fb3c2 |
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 #include "seek.h" |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
24 #include "libavutil/mem.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 // NOTE: implementation should be moved here in another patch, to keep patches |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
27 // separated. |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
28 extern void av_read_frame_flush(AVFormatContext *s); |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
29 |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
30 /** |
5158
26ba0ebacbb2
cosmetic changes (indentation, doxygen comments, braces, put structures for API to header, ...)
schreter
parents:
5139
diff
changeset
|
31 * helper structure describing keyframe search state of one stream |
5139
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
32 */ |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
33 typedef struct { |
5158
26ba0ebacbb2
cosmetic changes (indentation, doxygen comments, braces, put structures for API to header, ...)
schreter
parents:
5139
diff
changeset
|
34 int64_t pos_lo; ///< position of the frame with low timestamp in file or INT64_MAX if not found (yet) |
26ba0ebacbb2
cosmetic changes (indentation, doxygen comments, braces, put structures for API to header, ...)
schreter
parents:
5139
diff
changeset
|
35 int64_t ts_lo; ///< frame presentation timestamp or same as pos_lo for byte seeking |
5139
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
36 |
5158
26ba0ebacbb2
cosmetic changes (indentation, doxygen comments, braces, put structures for API to header, ...)
schreter
parents:
5139
diff
changeset
|
37 int64_t pos_hi; ///< position of the frame with high timestamp in file or INT64_MAX if not found (yet) |
26ba0ebacbb2
cosmetic changes (indentation, doxygen comments, braces, put structures for API to header, ...)
schreter
parents:
5139
diff
changeset
|
38 int64_t ts_hi; ///< frame presentation timestamp or same as pos_hi for byte seeking |
5139
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
39 |
5158
26ba0ebacbb2
cosmetic changes (indentation, doxygen comments, braces, put structures for API to header, ...)
schreter
parents:
5139
diff
changeset
|
40 int64_t last_pos; ///< last known position of a frame, for multi-frame packets |
5139
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
41 |
5158
26ba0ebacbb2
cosmetic changes (indentation, doxygen comments, braces, put structures for API to header, ...)
schreter
parents:
5139
diff
changeset
|
42 int64_t term_ts; ///< termination timestamp (which TS we already read) |
26ba0ebacbb2
cosmetic changes (indentation, doxygen comments, braces, put structures for API to header, ...)
schreter
parents:
5139
diff
changeset
|
43 AVRational term_ts_tb; ///< timebase for term_ts |
26ba0ebacbb2
cosmetic changes (indentation, doxygen comments, braces, put structures for API to header, ...)
schreter
parents:
5139
diff
changeset
|
44 int64_t first_ts; ///< first packet timestamp in this iteration (to fill term_ts later) |
26ba0ebacbb2
cosmetic changes (indentation, doxygen comments, braces, put structures for API to header, ...)
schreter
parents:
5139
diff
changeset
|
45 AVRational first_ts_tb; ///< timebase for first_ts |
5139
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
46 |
5158
26ba0ebacbb2
cosmetic changes (indentation, doxygen comments, braces, put structures for API to header, ...)
schreter
parents:
5139
diff
changeset
|
47 int terminated; ///< termination flag for the current iteration |
5139
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
48 } AVSyncPoint; |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
49 |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
50 /** |
5158
26ba0ebacbb2
cosmetic changes (indentation, doxygen comments, braces, put structures for API to header, ...)
schreter
parents:
5139
diff
changeset
|
51 * Compare two timestamps exactly, taking their respective time bases into account. |
5139
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
52 * |
5158
26ba0ebacbb2
cosmetic changes (indentation, doxygen comments, braces, put structures for API to header, ...)
schreter
parents:
5139
diff
changeset
|
53 * @param ts_a timestamp A |
26ba0ebacbb2
cosmetic changes (indentation, doxygen comments, braces, put structures for API to header, ...)
schreter
parents:
5139
diff
changeset
|
54 * @param tb_a time base for timestamp A |
26ba0ebacbb2
cosmetic changes (indentation, doxygen comments, braces, put structures for API to header, ...)
schreter
parents:
5139
diff
changeset
|
55 * @param ts_b timestamp B |
26ba0ebacbb2
cosmetic changes (indentation, doxygen comments, braces, put structures for API to header, ...)
schreter
parents:
5139
diff
changeset
|
56 * @param tb_b time base for timestamp A |
26ba0ebacbb2
cosmetic changes (indentation, doxygen comments, braces, put structures for API to header, ...)
schreter
parents:
5139
diff
changeset
|
57 * @return -1, 0 or 1 if timestamp A is less than, equal or greater than timestamp B |
5139
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
58 */ |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
59 static int compare_ts(int64_t ts_a, AVRational tb_a, int64_t ts_b, AVRational tb_b) |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
60 { |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
61 int64_t a, b, res; |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
62 |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
63 if (ts_a == INT64_MIN) |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
64 return ts_a < ts_b ? -1 : 0; |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
65 if (ts_a == INT64_MAX) |
5158
26ba0ebacbb2
cosmetic changes (indentation, doxygen comments, braces, put structures for API to header, ...)
schreter
parents:
5139
diff
changeset
|
66 return ts_a > ts_b ? 1 : 0; |
5139
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
67 if (ts_b == INT64_MIN) |
5158
26ba0ebacbb2
cosmetic changes (indentation, doxygen comments, braces, put structures for API to header, ...)
schreter
parents:
5139
diff
changeset
|
68 return ts_a > ts_b ? 1 : 0; |
5139
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
69 if (ts_b == INT64_MAX) |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
70 return ts_a < ts_b ? -1 : 0; |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
71 |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
72 a = ts_a * tb_a.num * tb_b.den; |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
73 b = ts_b * tb_b.num * tb_a.den; |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
74 |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
75 res = a - b; |
5158
26ba0ebacbb2
cosmetic changes (indentation, doxygen comments, braces, put structures for API to header, ...)
schreter
parents:
5139
diff
changeset
|
76 if (!res) |
5139
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
77 return 0; |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
78 else |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
79 return (res >> 63) | 1; |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
80 } |
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 /** |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
83 * Compute a distance between timestamps. |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
84 * |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
85 * Distances are only comparable, if same time bases are used for computing |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
86 * distances. |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
87 * |
5158
26ba0ebacbb2
cosmetic changes (indentation, doxygen comments, braces, put structures for API to header, ...)
schreter
parents:
5139
diff
changeset
|
88 * @param ts_hi high timestamp |
26ba0ebacbb2
cosmetic changes (indentation, doxygen comments, braces, put structures for API to header, ...)
schreter
parents:
5139
diff
changeset
|
89 * @param tb_hi high timestamp time base |
26ba0ebacbb2
cosmetic changes (indentation, doxygen comments, braces, put structures for API to header, ...)
schreter
parents:
5139
diff
changeset
|
90 * @param ts_lo low timestamp |
26ba0ebacbb2
cosmetic changes (indentation, doxygen comments, braces, put structures for API to header, ...)
schreter
parents:
5139
diff
changeset
|
91 * @param tb_lo low timestamp time base |
26ba0ebacbb2
cosmetic changes (indentation, doxygen comments, braces, put structures for API to header, ...)
schreter
parents:
5139
diff
changeset
|
92 * @return representation of distance between high and low timestamps |
5139
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
93 */ |
5158
26ba0ebacbb2
cosmetic changes (indentation, doxygen comments, braces, put structures for API to header, ...)
schreter
parents:
5139
diff
changeset
|
94 static int64_t ts_distance(int64_t ts_hi, |
26ba0ebacbb2
cosmetic changes (indentation, doxygen comments, braces, put structures for API to header, ...)
schreter
parents:
5139
diff
changeset
|
95 AVRational tb_hi, |
26ba0ebacbb2
cosmetic changes (indentation, doxygen comments, braces, put structures for API to header, ...)
schreter
parents:
5139
diff
changeset
|
96 int64_t ts_lo, |
26ba0ebacbb2
cosmetic changes (indentation, doxygen comments, braces, put structures for API to header, ...)
schreter
parents:
5139
diff
changeset
|
97 AVRational tb_lo) |
5139
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
98 { |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
99 int64_t hi, lo; |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
100 |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
101 hi = ts_hi * tb_hi.num * tb_lo.den; |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
102 lo = ts_lo * tb_lo.num * tb_hi.den; |
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 return hi - lo; |
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 /** |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
108 * Partial search for keyframes in multiple streams. |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
109 * |
5158
26ba0ebacbb2
cosmetic changes (indentation, doxygen comments, braces, put structures for API to header, ...)
schreter
parents:
5139
diff
changeset
|
110 * This routine searches in each stream for the next lower and the next higher |
26ba0ebacbb2
cosmetic changes (indentation, doxygen comments, braces, put structures for API to header, ...)
schreter
parents:
5139
diff
changeset
|
111 * timestamp compared to the given target timestamp. The search starts at the current |
26ba0ebacbb2
cosmetic changes (indentation, doxygen comments, braces, put structures for API to header, ...)
schreter
parents:
5139
diff
changeset
|
112 * file position and ends at the file position, where all streams have already been |
26ba0ebacbb2
cosmetic changes (indentation, doxygen comments, braces, put structures for API to header, ...)
schreter
parents:
5139
diff
changeset
|
113 * examined (or when all higher key frames are found in the first iteration). |
5139
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
114 * |
5158
26ba0ebacbb2
cosmetic changes (indentation, doxygen comments, braces, put structures for API to header, ...)
schreter
parents:
5139
diff
changeset
|
115 * This routine is called iteratively with an exponential backoff to find the lower |
5139
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
116 * timestamp. |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
117 * |
5158
26ba0ebacbb2
cosmetic changes (indentation, doxygen comments, braces, put structures for API to header, ...)
schreter
parents:
5139
diff
changeset
|
118 * @param s format context |
26ba0ebacbb2
cosmetic changes (indentation, doxygen comments, braces, put structures for API to header, ...)
schreter
parents:
5139
diff
changeset
|
119 * @param timestamp target timestamp (or position, if AVSEEK_FLAG_BYTE) |
26ba0ebacbb2
cosmetic changes (indentation, doxygen comments, braces, put structures for API to header, ...)
schreter
parents:
5139
diff
changeset
|
120 * @param timebase time base for timestamps |
26ba0ebacbb2
cosmetic changes (indentation, doxygen comments, braces, put structures for API to header, ...)
schreter
parents:
5139
diff
changeset
|
121 * @param flags seeking flags |
26ba0ebacbb2
cosmetic changes (indentation, doxygen comments, braces, put structures for API to header, ...)
schreter
parents:
5139
diff
changeset
|
122 * @param sync array with information per stream |
26ba0ebacbb2
cosmetic changes (indentation, doxygen comments, braces, put structures for API to header, ...)
schreter
parents:
5139
diff
changeset
|
123 * @param keyframes_to_find count of keyframes to find in total |
26ba0ebacbb2
cosmetic changes (indentation, doxygen comments, braces, put structures for API to header, ...)
schreter
parents:
5139
diff
changeset
|
124 * @param found_lo ptr to the count of already found low timestamp keyframes |
26ba0ebacbb2
cosmetic changes (indentation, doxygen comments, braces, put structures for API to header, ...)
schreter
parents:
5139
diff
changeset
|
125 * @param found_hi ptr to the count of already found high timestamp keyframes |
26ba0ebacbb2
cosmetic changes (indentation, doxygen comments, braces, put structures for API to header, ...)
schreter
parents:
5139
diff
changeset
|
126 * @param first_iter flag for first iteration |
5139
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
127 */ |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
128 static void search_hi_lo_keyframes(AVFormatContext *s, |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
129 int64_t timestamp, |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
130 AVRational timebase, |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
131 int flags, |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
132 AVSyncPoint *sync, |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
133 int keyframes_to_find, |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
134 int *found_lo, |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
135 int *found_hi, |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
136 int first_iter) |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
137 { |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
138 AVPacket pkt; |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
139 AVSyncPoint *sp; |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
140 AVStream *st; |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
141 int idx; |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
142 int flg; |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
143 int terminated_count = 0; |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
144 int64_t pos; |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
145 int64_t pts, dts; // PTS/DTS from stream |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
146 int64_t ts; // PTS in stream-local time base or position for byte seeking |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
147 AVRational ts_tb; // Time base of the stream or 1:1 for byte seeking |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
148 |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
149 for (;;) { |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
150 if (av_read_frame(s, &pkt) < 0) { |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
151 // EOF or error, make sure high flags are set |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
152 for (idx = 0; idx < s->nb_streams; ++idx) { |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
153 if (s->streams[idx]->discard < AVDISCARD_ALL) { |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
154 sp = &sync[idx]; |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
155 if (sp->pos_hi == INT64_MAX) { |
5158
26ba0ebacbb2
cosmetic changes (indentation, doxygen comments, braces, put structures for API to header, ...)
schreter
parents:
5139
diff
changeset
|
156 // no high frame exists for this stream |
5139
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
157 (*found_hi)++; |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
158 sp->ts_hi = INT64_MAX; |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
159 sp->pos_hi = INT64_MAX - 1; |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
160 } |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
161 } |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
162 } |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
163 break; |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
164 } |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
165 |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
166 idx = pkt.stream_index; |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
167 st = s->streams[idx]; |
5158
26ba0ebacbb2
cosmetic changes (indentation, doxygen comments, braces, put structures for API to header, ...)
schreter
parents:
5139
diff
changeset
|
168 if (st->discard >= AVDISCARD_ALL) |
26ba0ebacbb2
cosmetic changes (indentation, doxygen comments, braces, put structures for API to header, ...)
schreter
parents:
5139
diff
changeset
|
169 // this stream is not active, skip packet |
5139
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
170 continue; |
5158
26ba0ebacbb2
cosmetic changes (indentation, doxygen comments, braces, put structures for API to header, ...)
schreter
parents:
5139
diff
changeset
|
171 |
5139
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
172 sp = &sync[idx]; |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
173 |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
174 flg = pkt.flags; |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
175 pos = pkt.pos; |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
176 pts = pkt.pts; |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
177 dts = pkt.dts; |
5158
26ba0ebacbb2
cosmetic changes (indentation, doxygen comments, braces, put structures for API to header, ...)
schreter
parents:
5139
diff
changeset
|
178 if (pts == AV_NOPTS_VALUE) |
26ba0ebacbb2
cosmetic changes (indentation, doxygen comments, braces, put structures for API to header, ...)
schreter
parents:
5139
diff
changeset
|
179 // some formats don't provide PTS, only DTS |
5139
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
180 pts = dts; |
5158
26ba0ebacbb2
cosmetic changes (indentation, doxygen comments, braces, put structures for API to header, ...)
schreter
parents:
5139
diff
changeset
|
181 |
5139
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
182 av_free_packet(&pkt); |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
183 |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
184 // Multi-frame packets only return position for the very first frame. |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
185 // Other frames are read with position == -1. Therefore, we note down |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
186 // last known position of a frame and use it if a frame without |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
187 // position arrives. In this way, it's possible to seek to proper |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
188 // position. Additionally, for parsers not providing position at all, |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
189 // an approximation will be used (starting position of this iteration). |
5158
26ba0ebacbb2
cosmetic changes (indentation, doxygen comments, braces, put structures for API to header, ...)
schreter
parents:
5139
diff
changeset
|
190 if (pos < 0) |
5139
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
191 pos = sp->last_pos; |
5158
26ba0ebacbb2
cosmetic changes (indentation, doxygen comments, braces, put structures for API to header, ...)
schreter
parents:
5139
diff
changeset
|
192 else |
5139
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
193 sp->last_pos = pos; |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
194 |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
195 // Evaluate key frames with known TS (or any frames, if AVSEEK_FLAG_ANY set). |
5158
26ba0ebacbb2
cosmetic changes (indentation, doxygen comments, braces, put structures for API to header, ...)
schreter
parents:
5139
diff
changeset
|
196 if (pts != AV_NOPTS_VALUE && |
26ba0ebacbb2
cosmetic changes (indentation, doxygen comments, braces, put structures for API to header, ...)
schreter
parents:
5139
diff
changeset
|
197 ((flg & PKT_FLAG_KEY) || (flags & AVSEEK_FLAG_ANY))) { |
5139
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
198 if (flags & AVSEEK_FLAG_BYTE) { |
5158
26ba0ebacbb2
cosmetic changes (indentation, doxygen comments, braces, put structures for API to header, ...)
schreter
parents:
5139
diff
changeset
|
199 // for byte seeking, use position as timestamp |
5139
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
200 ts = pos; |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
201 ts_tb.num = 1; |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
202 ts_tb.den = 1; |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
203 } else { |
5158
26ba0ebacbb2
cosmetic changes (indentation, doxygen comments, braces, put structures for API to header, ...)
schreter
parents:
5139
diff
changeset
|
204 // otherwise, get stream time_base |
5139
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
205 ts = pts; |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
206 ts_tb = st->time_base; |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
207 } |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
208 |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
209 if (sp->first_ts == AV_NOPTS_VALUE) { |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
210 // Note down termination timestamp for the next iteration - when |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
211 // we encounter a packet with the same timestamp, we will ignore |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
212 // any further packets for this stream in next iteration (as they |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
213 // are already evaluated). |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
214 sp->first_ts = ts; |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
215 sp->first_ts_tb = ts_tb; |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
216 } |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
217 |
5158
26ba0ebacbb2
cosmetic changes (indentation, doxygen comments, braces, put structures for API to header, ...)
schreter
parents:
5139
diff
changeset
|
218 if (sp->term_ts != AV_NOPTS_VALUE && |
26ba0ebacbb2
cosmetic changes (indentation, doxygen comments, braces, put structures for API to header, ...)
schreter
parents:
5139
diff
changeset
|
219 compare_ts(ts, ts_tb, sp->term_ts, sp->term_ts_tb) > 0) { |
26ba0ebacbb2
cosmetic changes (indentation, doxygen comments, braces, put structures for API to header, ...)
schreter
parents:
5139
diff
changeset
|
220 // past the end position from last iteration, ignore packet |
5139
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
221 if (!sp->terminated) { |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
222 sp->terminated = 1; |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
223 ++terminated_count; |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
224 if (sp->pos_hi == INT64_MAX) { |
5158
26ba0ebacbb2
cosmetic changes (indentation, doxygen comments, braces, put structures for API to header, ...)
schreter
parents:
5139
diff
changeset
|
225 // no high frame exists for this stream |
5139
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
226 (*found_hi)++; |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
227 sp->ts_hi = INT64_MAX; |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
228 sp->pos_hi = INT64_MAX - 1; |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
229 } |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
230 if (terminated_count == keyframes_to_find) |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
231 break; // all terminated, iteration done |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
232 } |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
233 continue; |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
234 } |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
235 |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
236 if (compare_ts(ts, ts_tb, timestamp, timebase) <= 0) { |
5158
26ba0ebacbb2
cosmetic changes (indentation, doxygen comments, braces, put structures for API to header, ...)
schreter
parents:
5139
diff
changeset
|
237 // keyframe found before target timestamp |
5139
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
238 if (sp->pos_lo == INT64_MAX) { |
5158
26ba0ebacbb2
cosmetic changes (indentation, doxygen comments, braces, put structures for API to header, ...)
schreter
parents:
5139
diff
changeset
|
239 // found first keyframe lower than target timestamp |
5139
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
240 (*found_lo)++; |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
241 sp->ts_lo = ts; |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
242 sp->pos_lo = pos; |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
243 } else if (sp->ts_lo < ts) { |
5158
26ba0ebacbb2
cosmetic changes (indentation, doxygen comments, braces, put structures for API to header, ...)
schreter
parents:
5139
diff
changeset
|
244 // found a better match (closer to target timestamp) |
5139
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
245 sp->ts_lo = ts; |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
246 sp->pos_lo = pos; |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
247 } |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
248 } |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
249 if (compare_ts(ts, ts_tb, timestamp, timebase) >= 0) { |
5158
26ba0ebacbb2
cosmetic changes (indentation, doxygen comments, braces, put structures for API to header, ...)
schreter
parents:
5139
diff
changeset
|
250 // keyframe found after target timestamp |
5139
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
251 if (sp->pos_hi == INT64_MAX) { |
5158
26ba0ebacbb2
cosmetic changes (indentation, doxygen comments, braces, put structures for API to header, ...)
schreter
parents:
5139
diff
changeset
|
252 // found first keyframe higher than target timestamp |
5139
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
253 (*found_hi)++; |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
254 sp->ts_hi = ts; |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
255 sp->pos_hi = pos; |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
256 if (*found_hi >= keyframes_to_find && first_iter) { |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
257 // We found high frame for all. They may get updated |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
258 // to TS closer to target TS in later iterations (which |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
259 // will stop at start position of previous iteration). |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
260 break; |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
261 } |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
262 } else if (sp->ts_hi > ts) { |
5158
26ba0ebacbb2
cosmetic changes (indentation, doxygen comments, braces, put structures for API to header, ...)
schreter
parents:
5139
diff
changeset
|
263 // found a better match (actually, shouldn't happen) |
5139
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
264 sp->ts_hi = ts; |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
265 sp->pos_hi = pos; |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
266 } |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
267 } |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
268 } |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
269 } |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
270 |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
271 // Clean up the parser. |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
272 av_read_frame_flush(s); |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
273 } |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
274 |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
275 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
|
276 int stream_index, |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
277 int64_t pos, |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
278 int64_t ts_min, |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
279 int64_t ts, |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
280 int64_t ts_max, |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
281 int flags) |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
282 { |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
283 AVSyncPoint *sync, *sp; |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
284 AVStream *st; |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
285 int i; |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
286 int keyframes_to_find = 0; |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
287 int64_t curpos; |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
288 int64_t step; |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
289 int found_lo = 0, found_hi = 0; |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
290 int64_t min_distance, distance; |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
291 int64_t min_pos = 0; |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
292 int first_iter = 1; |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
293 AVRational time_base; |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
294 |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
295 if (flags & AVSEEK_FLAG_BYTE) { |
5158
26ba0ebacbb2
cosmetic changes (indentation, doxygen comments, braces, put structures for API to header, ...)
schreter
parents:
5139
diff
changeset
|
296 // for byte seeking, we have exact 1:1 "timestamps" - positions |
5139
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
297 time_base.num = 1; |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
298 time_base.den = 1; |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
299 } else { |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
300 if (stream_index >= 0) { |
5158
26ba0ebacbb2
cosmetic changes (indentation, doxygen comments, braces, put structures for API to header, ...)
schreter
parents:
5139
diff
changeset
|
301 // we have a reference stream, which time base we use |
5139
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
302 st = s->streams[stream_index]; |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
303 time_base = st->time_base; |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
304 } else { |
5158
26ba0ebacbb2
cosmetic changes (indentation, doxygen comments, braces, put structures for API to header, ...)
schreter
parents:
5139
diff
changeset
|
305 // no reference stream, use AV_TIME_BASE as reference time base |
5139
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
306 time_base.num = 1; |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
307 time_base.den = AV_TIME_BASE; |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
308 } |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
309 } |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
310 |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
311 // Initialize syncpoint structures for each stream. |
5158
26ba0ebacbb2
cosmetic changes (indentation, doxygen comments, braces, put structures for API to header, ...)
schreter
parents:
5139
diff
changeset
|
312 sync = av_malloc(s->nb_streams * sizeof(AVSyncPoint)); |
26ba0ebacbb2
cosmetic changes (indentation, doxygen comments, braces, put structures for API to header, ...)
schreter
parents:
5139
diff
changeset
|
313 if (!sync) |
5139
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
314 // cannot allocate helper structure |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
315 return -1; |
5158
26ba0ebacbb2
cosmetic changes (indentation, doxygen comments, braces, put structures for API to header, ...)
schreter
parents:
5139
diff
changeset
|
316 |
5139
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
317 for (i = 0; i < s->nb_streams; ++i) { |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
318 st = s->streams[i]; |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
319 sp = &sync[i]; |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
320 |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
321 sp->pos_lo = INT64_MAX; |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
322 sp->ts_lo = INT64_MAX; |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
323 sp->pos_hi = INT64_MAX; |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
324 sp->ts_hi = INT64_MAX; |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
325 sp->terminated = 0; |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
326 sp->first_ts = AV_NOPTS_VALUE; |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
327 sp->term_ts = ts_max; |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
328 sp->term_ts_tb = time_base; |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
329 sp->last_pos = pos; |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
330 |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
331 st->cur_dts = AV_NOPTS_VALUE; |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
332 |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
333 if (st->discard < AVDISCARD_ALL) |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
334 ++keyframes_to_find; |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
335 } |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
336 |
5158
26ba0ebacbb2
cosmetic changes (indentation, doxygen comments, braces, put structures for API to header, ...)
schreter
parents:
5139
diff
changeset
|
337 if (!keyframes_to_find) { |
26ba0ebacbb2
cosmetic changes (indentation, doxygen comments, braces, put structures for API to header, ...)
schreter
parents:
5139
diff
changeset
|
338 // no stream active, error |
5139
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
339 av_free(sync); |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
340 return -1; |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
341 } |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
342 |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
343 // Find keyframes in all active streams with timestamp/position just before |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
344 // and just after requested timestamp/position. |
5171
44e53fe2e9ca
Use I/O buffer size as initial value for backoff for seeking sync point search.
schreter
parents:
5158
diff
changeset
|
345 step = s->pb->buffer_size; |
44e53fe2e9ca
Use I/O buffer size as initial value for backoff for seeking sync point search.
schreter
parents:
5158
diff
changeset
|
346 curpos = FFMAX(pos - step / 2, 0); |
5139
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
347 for (;;) { |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
348 url_fseek(s->pb, curpos, SEEK_SET); |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
349 search_hi_lo_keyframes(s, |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
350 ts, time_base, |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
351 flags, |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
352 sync, |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
353 keyframes_to_find, |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
354 &found_lo, &found_hi, |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
355 first_iter); |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
356 if (found_lo == keyframes_to_find && found_hi == keyframes_to_find) |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
357 break; // have all keyframes we wanted |
5158
26ba0ebacbb2
cosmetic changes (indentation, doxygen comments, braces, put structures for API to header, ...)
schreter
parents:
5139
diff
changeset
|
358 if (!curpos) |
5139
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
359 break; // cannot go back anymore |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
360 |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
361 curpos = pos - step; |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
362 if (curpos < 0) |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
363 curpos = 0; |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
364 step *= 2; |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
365 |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
366 // switch termination positions |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
367 for (i = 0; i < s->nb_streams; ++i) { |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
368 st = s->streams[i]; |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
369 st->cur_dts = AV_NOPTS_VALUE; |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
370 |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
371 sp = &sync[i]; |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
372 if (sp->first_ts != AV_NOPTS_VALUE) { |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
373 sp->term_ts = sp->first_ts; |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
374 sp->term_ts_tb = sp->first_ts_tb; |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
375 sp->first_ts = AV_NOPTS_VALUE; |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
376 } |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
377 sp->terminated = 0; |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
378 sp->last_pos = curpos; |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
379 } |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
380 first_iter = 0; |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
381 } |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
382 |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
383 // Find actual position to start decoding so that decoder synchronizes |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
384 // closest to ts and between ts_min and ts_max. |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
385 pos = INT64_MAX; |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
386 |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
387 for (i = 0; i < s->nb_streams; ++i) { |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
388 st = s->streams[i]; |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
389 if (st->discard < AVDISCARD_ALL) { |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
390 sp = &sync[i]; |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
391 min_distance = INT64_MAX; |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
392 // Find timestamp closest to requested timestamp within min/max limits. |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
393 if (sp->pos_lo != INT64_MAX |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
394 && compare_ts(ts_min, time_base, sp->ts_lo, st->time_base) <= 0 |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
395 && compare_ts(sp->ts_lo, st->time_base, ts_max, time_base) <= 0) { |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
396 // low timestamp is in range |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
397 min_distance = ts_distance(ts, time_base, sp->ts_lo, st->time_base); |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
398 min_pos = sp->pos_lo; |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
399 } |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
400 if (sp->pos_hi != INT64_MAX |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
401 && compare_ts(ts_min, time_base, sp->ts_hi, st->time_base) <= 0 |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
402 && compare_ts(sp->ts_hi, st->time_base, ts_max, time_base) <= 0) { |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
403 // high timestamp is in range, check distance |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
404 distance = ts_distance(sp->ts_hi, st->time_base, ts, time_base); |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
405 if (distance < min_distance) { |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
406 min_distance = distance; |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
407 min_pos = sp->pos_hi; |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
408 } |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
409 } |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
410 if (min_distance == INT64_MAX) { |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
411 // no timestamp is in range, cannot seek |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
412 av_free(sync); |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
413 return -1; |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
414 } |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
415 if (min_pos < pos) |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
416 pos = min_pos; |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
417 } |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
418 } |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
419 |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
420 url_fseek(s->pb, pos, SEEK_SET); |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
421 av_free(sync); |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
422 return pos; |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
423 } |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
424 |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
425 AVParserState *ff_store_parser_state(AVFormatContext *s) |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
426 { |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
427 int i; |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
428 AVStream *st; |
5158
26ba0ebacbb2
cosmetic changes (indentation, doxygen comments, braces, put structures for API to header, ...)
schreter
parents:
5139
diff
changeset
|
429 AVParserStreamState *ss; |
26ba0ebacbb2
cosmetic changes (indentation, doxygen comments, braces, put structures for API to header, ...)
schreter
parents:
5139
diff
changeset
|
430 AVParserState *state = av_malloc(sizeof(AVParserState)); |
5139
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
431 if (!state) |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
432 return NULL; |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
433 |
5158
26ba0ebacbb2
cosmetic changes (indentation, doxygen comments, braces, put structures for API to header, ...)
schreter
parents:
5139
diff
changeset
|
434 state->stream_states = av_malloc(sizeof(AVParserStreamState) * s->nb_streams); |
5139
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
435 if (!state->stream_states) { |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
436 av_free(state); |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
437 return NULL; |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
438 } |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
439 |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
440 state->fpos = url_ftell(s->pb); |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
441 |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
442 // copy context structures |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
443 state->cur_st = s->cur_st; |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
444 state->packet_buffer = s->packet_buffer; |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
445 state->raw_packet_buffer = s->raw_packet_buffer; |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
446 state->raw_packet_buffer_remaining_size = s->raw_packet_buffer_remaining_size; |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
447 |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
448 s->cur_st = NULL; |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
449 s->packet_buffer = NULL; |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
450 s->raw_packet_buffer = NULL; |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
451 s->raw_packet_buffer_remaining_size = RAW_PACKET_BUFFER_SIZE; |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
452 |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
453 // copy stream structures |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
454 state->nb_streams = s->nb_streams; |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
455 for (i = 0; i < s->nb_streams; i++) { |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
456 st = s->streams[i]; |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
457 ss = &state->stream_states[i]; |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
458 |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
459 ss->parser = st->parser; |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
460 ss->last_IP_pts = st->last_IP_pts; |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
461 ss->cur_dts = st->cur_dts; |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
462 ss->reference_dts = st->reference_dts; |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
463 ss->cur_ptr = st->cur_ptr; |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
464 ss->cur_len = st->cur_len; |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
465 ss->probe_packets = st->probe_packets; |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
466 ss->cur_pkt = st->cur_pkt; |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
467 |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
468 st->parser = NULL; |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
469 st->last_IP_pts = AV_NOPTS_VALUE; |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
470 st->cur_dts = AV_NOPTS_VALUE; |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
471 st->reference_dts = AV_NOPTS_VALUE; |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
472 st->cur_ptr = NULL; |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
473 st->cur_len = 0; |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
474 st->probe_packets = MAX_PROBE_PACKETS; |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
475 av_init_packet(&st->cur_pkt); |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
476 } |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
477 |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
478 return state; |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
479 } |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
480 |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
481 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
|
482 { |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
483 int i; |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
484 AVStream *st; |
5158
26ba0ebacbb2
cosmetic changes (indentation, doxygen comments, braces, put structures for API to header, ...)
schreter
parents:
5139
diff
changeset
|
485 AVParserStreamState *ss; |
5139
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
486 av_read_frame_flush(s); |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
487 |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
488 if (!state) |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
489 return; |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
490 |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
491 url_fseek(s->pb, state->fpos, SEEK_SET); |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
492 |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
493 // copy context structures |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
494 s->cur_st = state->cur_st; |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
495 s->packet_buffer = state->packet_buffer; |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
496 s->raw_packet_buffer = state->raw_packet_buffer; |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
497 s->raw_packet_buffer_remaining_size = state->raw_packet_buffer_remaining_size; |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
498 |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
499 // copy stream structures |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
500 for (i = 0; i < state->nb_streams; i++) { |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
501 st = s->streams[i]; |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
502 ss = &state->stream_states[i]; |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
503 |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
504 st->parser = ss->parser; |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
505 st->last_IP_pts = ss->last_IP_pts; |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
506 st->cur_dts = ss->cur_dts; |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
507 st->reference_dts = ss->reference_dts; |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
508 st->cur_ptr = ss->cur_ptr; |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
509 st->cur_len = ss->cur_len; |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
510 st->probe_packets = ss->probe_packets; |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
511 st->cur_pkt = ss->cur_pkt; |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
512 } |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
513 |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
514 av_free(state->stream_states); |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
515 av_free(state); |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
516 } |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
517 |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
518 static void free_packet_list(AVPacketList *pktl) |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
519 { |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
520 AVPacketList *cur; |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
521 while (pktl) { |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
522 cur = pktl; |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
523 pktl = cur->next; |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
524 av_free_packet(&cur->pkt); |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
525 av_free(cur); |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
526 } |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
527 } |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
528 |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
529 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
|
530 { |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
531 int i; |
5158
26ba0ebacbb2
cosmetic changes (indentation, doxygen comments, braces, put structures for API to header, ...)
schreter
parents:
5139
diff
changeset
|
532 AVParserStreamState *ss; |
5139
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
533 |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
534 if (!state) |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
535 return; |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
536 |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
537 for (i = 0; i < state->nb_streams; i++) { |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
538 ss = &state->stream_states[i]; |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
539 if (ss->parser) |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
540 av_parser_close(ss->parser); |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
541 av_free_packet(&ss->cur_pkt); |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
542 } |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
543 |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
544 free_packet_list(state->packet_buffer); |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
545 free_packet_list(state->raw_packet_buffer); |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
546 |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
547 av_free(state->stream_states); |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
548 av_free(state); |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
549 } |
9b2d2f4aa042
Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff
changeset
|
550 |