annotate seek.c @ 6455:3f50c7effad1 libavformat

rtsp: 10l, try to update the correct rtp stream This fixes a bug from rev 22917. Now RTSP streams where the individual RTCP sender reports aren't sent at the same time actually are synced properly.
author mstorsjo
date Fri, 03 Sep 2010 07:10:21 +0000
parents 11bb10c37225
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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"
5764
99068df75916 Add internal.h include for av_read_frame_flush prototype
conrad
parents: 5761
diff changeset
25 #include "internal.h"
5139
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
26
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
27 // 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
28 // separated.
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 /**
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
51 * Compute a distance between timestamps.
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
52 *
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
53 * 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
54 * distances.
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
55 *
5158
26ba0ebacbb2 cosmetic changes (indentation, doxygen comments, braces, put structures for API to header, ...)
schreter
parents: 5139
diff changeset
56 * @param ts_hi high timestamp
26ba0ebacbb2 cosmetic changes (indentation, doxygen comments, braces, put structures for API to header, ...)
schreter
parents: 5139
diff changeset
57 * @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
58 * @param ts_lo low timestamp
26ba0ebacbb2 cosmetic changes (indentation, doxygen comments, braces, put structures for API to header, ...)
schreter
parents: 5139
diff changeset
59 * @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
60 * @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
61 */
5158
26ba0ebacbb2 cosmetic changes (indentation, doxygen comments, braces, put structures for API to header, ...)
schreter
parents: 5139
diff changeset
62 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
63 AVRational tb_hi,
26ba0ebacbb2 cosmetic changes (indentation, doxygen comments, braces, put structures for API to header, ...)
schreter
parents: 5139
diff changeset
64 int64_t ts_lo,
26ba0ebacbb2 cosmetic changes (indentation, doxygen comments, braces, put structures for API to header, ...)
schreter
parents: 5139
diff changeset
65 AVRational tb_lo)
5139
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
66 {
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
67 int64_t hi, lo;
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
68
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
69 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
70 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
71
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
72 return hi - lo;
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
73 }
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 /**
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
76 * Partial search for keyframes in multiple streams.
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
77 *
5158
26ba0ebacbb2 cosmetic changes (indentation, doxygen comments, braces, put structures for API to header, ...)
schreter
parents: 5139
diff changeset
78 * 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
79 * 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
80 * 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
81 * 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
82 *
5158
26ba0ebacbb2 cosmetic changes (indentation, doxygen comments, braces, put structures for API to header, ...)
schreter
parents: 5139
diff changeset
83 * 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
84 * timestamp.
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
85 *
5158
26ba0ebacbb2 cosmetic changes (indentation, doxygen comments, braces, put structures for API to header, ...)
schreter
parents: 5139
diff changeset
86 * @param s format context
26ba0ebacbb2 cosmetic changes (indentation, doxygen comments, braces, put structures for API to header, ...)
schreter
parents: 5139
diff changeset
87 * @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
88 * @param timebase time base for timestamps
26ba0ebacbb2 cosmetic changes (indentation, doxygen comments, braces, put structures for API to header, ...)
schreter
parents: 5139
diff changeset
89 * @param flags seeking flags
26ba0ebacbb2 cosmetic changes (indentation, doxygen comments, braces, put structures for API to header, ...)
schreter
parents: 5139
diff changeset
90 * @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
91 * @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
92 * @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
93 * @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
94 * @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
95 */
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
96 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
97 int64_t timestamp,
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
98 AVRational timebase,
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
99 int flags,
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
100 AVSyncPoint *sync,
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
101 int keyframes_to_find,
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
102 int *found_lo,
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
103 int *found_hi,
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
104 int first_iter)
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 AVPacket pkt;
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
107 AVSyncPoint *sp;
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
108 AVStream *st;
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
109 int idx;
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
110 int flg;
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
111 int terminated_count = 0;
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
112 int64_t pos;
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
113 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
114 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
115 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
116
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
117 for (;;) {
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
118 if (av_read_frame(s, &pkt) < 0) {
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
119 // 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
120 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
121 if (s->streams[idx]->discard < AVDISCARD_ALL) {
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
122 sp = &sync[idx];
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
123 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
124 // 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
125 (*found_hi)++;
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
126 sp->ts_hi = INT64_MAX;
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
127 sp->pos_hi = INT64_MAX - 1;
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
128 }
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
129 }
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
130 }
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
131 break;
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
132 }
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
133
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
134 idx = pkt.stream_index;
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
135 st = s->streams[idx];
5158
26ba0ebacbb2 cosmetic changes (indentation, doxygen comments, braces, put structures for API to header, ...)
schreter
parents: 5139
diff changeset
136 if (st->discard >= AVDISCARD_ALL)
26ba0ebacbb2 cosmetic changes (indentation, doxygen comments, braces, put structures for API to header, ...)
schreter
parents: 5139
diff changeset
137 // 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
138 continue;
5158
26ba0ebacbb2 cosmetic changes (indentation, doxygen comments, braces, put structures for API to header, ...)
schreter
parents: 5139
diff changeset
139
5139
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
140 sp = &sync[idx];
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
141
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
142 flg = pkt.flags;
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
143 pos = pkt.pos;
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
144 pts = pkt.pts;
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
145 dts = pkt.dts;
5158
26ba0ebacbb2 cosmetic changes (indentation, doxygen comments, braces, put structures for API to header, ...)
schreter
parents: 5139
diff changeset
146 if (pts == AV_NOPTS_VALUE)
26ba0ebacbb2 cosmetic changes (indentation, doxygen comments, braces, put structures for API to header, ...)
schreter
parents: 5139
diff changeset
147 // 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
148 pts = dts;
5158
26ba0ebacbb2 cosmetic changes (indentation, doxygen comments, braces, put structures for API to header, ...)
schreter
parents: 5139
diff changeset
149
5139
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
150 av_free_packet(&pkt);
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
151
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
152 // 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
153 // 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
154 // 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
155 // 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
156 // 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
157 // 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
158 if (pos < 0)
5139
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
159 pos = sp->last_pos;
5158
26ba0ebacbb2 cosmetic changes (indentation, doxygen comments, braces, put structures for API to header, ...)
schreter
parents: 5139
diff changeset
160 else
5139
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
161 sp->last_pos = pos;
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 // 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
164 if (pts != AV_NOPTS_VALUE &&
5913
11bb10c37225 Replace all occurences of PKT_FLAG_KEY with AV_PKT_FLAG_KEY.
cehoyos
parents: 5853
diff changeset
165 ((flg & AV_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
166 if (flags & AVSEEK_FLAG_BYTE) {
5158
26ba0ebacbb2 cosmetic changes (indentation, doxygen comments, braces, put structures for API to header, ...)
schreter
parents: 5139
diff changeset
167 // 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
168 ts = pos;
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
169 ts_tb.num = 1;
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
170 ts_tb.den = 1;
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
171 } else {
5158
26ba0ebacbb2 cosmetic changes (indentation, doxygen comments, braces, put structures for API to header, ...)
schreter
parents: 5139
diff changeset
172 // otherwise, get stream time_base
5139
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
173 ts = pts;
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
174 ts_tb = st->time_base;
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
175 }
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
176
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
177 if (sp->first_ts == AV_NOPTS_VALUE) {
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
178 // 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
179 // 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
180 // 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
181 // are already evaluated).
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
182 sp->first_ts = ts;
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
183 sp->first_ts_tb = ts_tb;
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
184 }
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
185
5158
26ba0ebacbb2 cosmetic changes (indentation, doxygen comments, braces, put structures for API to header, ...)
schreter
parents: 5139
diff changeset
186 if (sp->term_ts != AV_NOPTS_VALUE &&
5647
6f5cdb0fb3c2 Use av_compare_ts from libavutil instead of the locale compare_ts, the
reimar
parents: 5171
diff changeset
187 av_compare_ts(ts, ts_tb, sp->term_ts, sp->term_ts_tb) > 0) {
5158
26ba0ebacbb2 cosmetic changes (indentation, doxygen comments, braces, put structures for API to header, ...)
schreter
parents: 5139
diff changeset
188 // 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
189 if (!sp->terminated) {
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
190 sp->terminated = 1;
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
191 ++terminated_count;
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
192 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
193 // 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
194 (*found_hi)++;
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
195 sp->ts_hi = INT64_MAX;
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
196 sp->pos_hi = INT64_MAX - 1;
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
197 }
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
198 if (terminated_count == keyframes_to_find)
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
199 break; // all terminated, iteration done
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
200 }
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
201 continue;
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
202 }
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
203
5647
6f5cdb0fb3c2 Use av_compare_ts from libavutil instead of the locale compare_ts, the
reimar
parents: 5171
diff changeset
204 if (av_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
205 // keyframe found before target timestamp
5139
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
206 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
207 // 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
208 (*found_lo)++;
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
209 sp->ts_lo = ts;
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
210 sp->pos_lo = pos;
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
211 } 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
212 // 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
213 sp->ts_lo = ts;
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
214 sp->pos_lo = pos;
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
215 }
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
216 }
5647
6f5cdb0fb3c2 Use av_compare_ts from libavutil instead of the locale compare_ts, the
reimar
parents: 5171
diff changeset
217 if (av_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
218 // keyframe found after target timestamp
5139
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
219 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
220 // 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
221 (*found_hi)++;
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
222 sp->ts_hi = ts;
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
223 sp->pos_hi = pos;
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
224 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
225 // 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
226 // 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
227 // 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
228 break;
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 } 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
231 // 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
232 sp->ts_hi = ts;
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
233 sp->pos_hi = pos;
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 }
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
237 }
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
238
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
239 // Clean up the parser.
5853
cf00e196666a rename av_read_frame_flush to ff_read_frame_flush
aurel
parents: 5764
diff changeset
240 ff_read_frame_flush(s);
5139
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
241 }
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
242
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
243 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
244 int stream_index,
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
245 int64_t pos,
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
246 int64_t ts_min,
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
247 int64_t ts,
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
248 int64_t ts_max,
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
249 int flags)
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
250 {
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
251 AVSyncPoint *sync, *sp;
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
252 AVStream *st;
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
253 int i;
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
254 int keyframes_to_find = 0;
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
255 int64_t curpos;
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
256 int64_t step;
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
257 int found_lo = 0, found_hi = 0;
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
258 int64_t min_distance, distance;
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
259 int64_t min_pos = 0;
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
260 int first_iter = 1;
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
261 AVRational time_base;
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
262
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
263 if (flags & AVSEEK_FLAG_BYTE) {
5158
26ba0ebacbb2 cosmetic changes (indentation, doxygen comments, braces, put structures for API to header, ...)
schreter
parents: 5139
diff changeset
264 // 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
265 time_base.num = 1;
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
266 time_base.den = 1;
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
267 } else {
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
268 if (stream_index >= 0) {
5158
26ba0ebacbb2 cosmetic changes (indentation, doxygen comments, braces, put structures for API to header, ...)
schreter
parents: 5139
diff changeset
269 // 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
270 st = s->streams[stream_index];
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
271 time_base = st->time_base;
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
272 } else {
5158
26ba0ebacbb2 cosmetic changes (indentation, doxygen comments, braces, put structures for API to header, ...)
schreter
parents: 5139
diff changeset
273 // 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
274 time_base.num = 1;
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
275 time_base.den = AV_TIME_BASE;
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
276 }
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
277 }
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
278
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
279 // 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
280 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
281 if (!sync)
5139
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
282 // cannot allocate helper structure
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
283 return -1;
5158
26ba0ebacbb2 cosmetic changes (indentation, doxygen comments, braces, put structures for API to header, ...)
schreter
parents: 5139
diff changeset
284
5139
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
285 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
286 st = s->streams[i];
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
287 sp = &sync[i];
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
288
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
289 sp->pos_lo = INT64_MAX;
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
290 sp->ts_lo = INT64_MAX;
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
291 sp->pos_hi = INT64_MAX;
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
292 sp->ts_hi = INT64_MAX;
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
293 sp->terminated = 0;
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
294 sp->first_ts = AV_NOPTS_VALUE;
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
295 sp->term_ts = ts_max;
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
296 sp->term_ts_tb = time_base;
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
297 sp->last_pos = pos;
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
298
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
299 st->cur_dts = AV_NOPTS_VALUE;
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
300
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
301 if (st->discard < AVDISCARD_ALL)
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
302 ++keyframes_to_find;
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
303 }
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
304
5158
26ba0ebacbb2 cosmetic changes (indentation, doxygen comments, braces, put structures for API to header, ...)
schreter
parents: 5139
diff changeset
305 if (!keyframes_to_find) {
26ba0ebacbb2 cosmetic changes (indentation, doxygen comments, braces, put structures for API to header, ...)
schreter
parents: 5139
diff changeset
306 // no stream active, error
5139
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
307 av_free(sync);
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
308 return -1;
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 // 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
312 // 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
313 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
314 curpos = FFMAX(pos - step / 2, 0);
5139
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
315 for (;;) {
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
316 url_fseek(s->pb, curpos, SEEK_SET);
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
317 search_hi_lo_keyframes(s,
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
318 ts, time_base,
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
319 flags,
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
320 sync,
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
321 keyframes_to_find,
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
322 &found_lo, &found_hi,
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
323 first_iter);
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
324 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
325 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
326 if (!curpos)
5139
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
327 break; // cannot go back anymore
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
328
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
329 curpos = pos - step;
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
330 if (curpos < 0)
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
331 curpos = 0;
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
332 step *= 2;
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
333
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
334 // switch termination positions
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
335 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
336 st = s->streams[i];
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
337 st->cur_dts = AV_NOPTS_VALUE;
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
338
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
339 sp = &sync[i];
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
340 if (sp->first_ts != AV_NOPTS_VALUE) {
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
341 sp->term_ts = sp->first_ts;
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
342 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
343 sp->first_ts = AV_NOPTS_VALUE;
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
344 }
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
345 sp->terminated = 0;
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
346 sp->last_pos = curpos;
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
347 }
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
348 first_iter = 0;
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
349 }
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
350
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
351 // 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
352 // 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
353 pos = INT64_MAX;
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
354
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
355 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
356 st = s->streams[i];
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
357 if (st->discard < AVDISCARD_ALL) {
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
358 sp = &sync[i];
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
359 min_distance = INT64_MAX;
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
360 // 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
361 if (sp->pos_lo != INT64_MAX
5647
6f5cdb0fb3c2 Use av_compare_ts from libavutil instead of the locale compare_ts, the
reimar
parents: 5171
diff changeset
362 && av_compare_ts(ts_min, time_base, sp->ts_lo, st->time_base) <= 0
6f5cdb0fb3c2 Use av_compare_ts from libavutil instead of the locale compare_ts, the
reimar
parents: 5171
diff changeset
363 && av_compare_ts(sp->ts_lo, st->time_base, ts_max, time_base) <= 0) {
5139
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
364 // low timestamp is in range
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
365 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
366 min_pos = sp->pos_lo;
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
367 }
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
368 if (sp->pos_hi != INT64_MAX
5647
6f5cdb0fb3c2 Use av_compare_ts from libavutil instead of the locale compare_ts, the
reimar
parents: 5171
diff changeset
369 && av_compare_ts(ts_min, time_base, sp->ts_hi, st->time_base) <= 0
6f5cdb0fb3c2 Use av_compare_ts from libavutil instead of the locale compare_ts, the
reimar
parents: 5171
diff changeset
370 && av_compare_ts(sp->ts_hi, st->time_base, ts_max, time_base) <= 0) {
5139
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
371 // high timestamp is in range, check distance
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
372 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
373 if (distance < min_distance) {
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
374 min_distance = distance;
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
375 min_pos = sp->pos_hi;
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 }
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
378 if (min_distance == INT64_MAX) {
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
379 // no timestamp is in range, cannot seek
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
380 av_free(sync);
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
381 return -1;
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 if (min_pos < pos)
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
384 pos = min_pos;
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
385 }
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
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
388 url_fseek(s->pb, pos, SEEK_SET);
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
389 av_free(sync);
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
390 return pos;
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
391 }
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
392
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
393 AVParserState *ff_store_parser_state(AVFormatContext *s)
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
394 {
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
395 int i;
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
396 AVStream *st;
5158
26ba0ebacbb2 cosmetic changes (indentation, doxygen comments, braces, put structures for API to header, ...)
schreter
parents: 5139
diff changeset
397 AVParserStreamState *ss;
26ba0ebacbb2 cosmetic changes (indentation, doxygen comments, braces, put structures for API to header, ...)
schreter
parents: 5139
diff changeset
398 AVParserState *state = av_malloc(sizeof(AVParserState));
5139
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
399 if (!state)
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
400 return NULL;
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
401
5158
26ba0ebacbb2 cosmetic changes (indentation, doxygen comments, braces, put structures for API to header, ...)
schreter
parents: 5139
diff changeset
402 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
403 if (!state->stream_states) {
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
404 av_free(state);
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
405 return NULL;
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
406 }
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
407
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
408 state->fpos = url_ftell(s->pb);
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 // copy context structures
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
411 state->cur_st = s->cur_st;
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
412 state->packet_buffer = s->packet_buffer;
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
413 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
414 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
415
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
416 s->cur_st = NULL;
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
417 s->packet_buffer = NULL;
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
418 s->raw_packet_buffer = NULL;
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
419 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
420
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
421 // copy stream structures
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
422 state->nb_streams = s->nb_streams;
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
423 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
424 st = s->streams[i];
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
425 ss = &state->stream_states[i];
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 ss->parser = st->parser;
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
428 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
429 ss->cur_dts = st->cur_dts;
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
430 ss->reference_dts = st->reference_dts;
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
431 ss->cur_ptr = st->cur_ptr;
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
432 ss->cur_len = st->cur_len;
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
433 ss->probe_packets = st->probe_packets;
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
434 ss->cur_pkt = st->cur_pkt;
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
435
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
436 st->parser = NULL;
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
437 st->last_IP_pts = AV_NOPTS_VALUE;
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
438 st->cur_dts = AV_NOPTS_VALUE;
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
439 st->reference_dts = AV_NOPTS_VALUE;
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
440 st->cur_ptr = NULL;
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
441 st->cur_len = 0;
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
442 st->probe_packets = MAX_PROBE_PACKETS;
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
443 av_init_packet(&st->cur_pkt);
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
444 }
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
445
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
446 return state;
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
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
449 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
450 {
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
451 int i;
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
452 AVStream *st;
5158
26ba0ebacbb2 cosmetic changes (indentation, doxygen comments, braces, put structures for API to header, ...)
schreter
parents: 5139
diff changeset
453 AVParserStreamState *ss;
5853
cf00e196666a rename av_read_frame_flush to ff_read_frame_flush
aurel
parents: 5764
diff changeset
454 ff_read_frame_flush(s);
5139
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
455
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
456 if (!state)
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
457 return;
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 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
460
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
461 // copy context structures
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
462 s->cur_st = state->cur_st;
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
463 s->packet_buffer = state->packet_buffer;
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
464 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
465 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
466
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
467 // copy stream structures
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
468 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
469 st = s->streams[i];
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
470 ss = &state->stream_states[i];
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
471
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
472 st->parser = ss->parser;
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
473 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
474 st->cur_dts = ss->cur_dts;
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
475 st->reference_dts = ss->reference_dts;
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
476 st->cur_ptr = ss->cur_ptr;
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
477 st->cur_len = ss->cur_len;
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
478 st->probe_packets = ss->probe_packets;
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
479 st->cur_pkt = ss->cur_pkt;
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
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
482 av_free(state->stream_states);
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
483 av_free(state);
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
484 }
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
485
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
486 static void free_packet_list(AVPacketList *pktl)
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 AVPacketList *cur;
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
489 while (pktl) {
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
490 cur = pktl;
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
491 pktl = cur->next;
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
492 av_free_packet(&cur->pkt);
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
493 av_free(cur);
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
494 }
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
495 }
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
496
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
497 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
498 {
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
499 int i;
5158
26ba0ebacbb2 cosmetic changes (indentation, doxygen comments, braces, put structures for API to header, ...)
schreter
parents: 5139
diff changeset
500 AVParserStreamState *ss;
5139
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
501
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
502 if (!state)
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
503 return;
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
504
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
505 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
506 ss = &state->stream_states[i];
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
507 if (ss->parser)
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
508 av_parser_close(ss->parser);
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
509 av_free_packet(&ss->cur_pkt);
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
510 }
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
511
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
512 free_packet_list(state->packet_buffer);
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
513 free_packet_list(state->raw_packet_buffer);
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
514
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
515 av_free(state->stream_states);
9b2d2f4aa042 Support for generic multi-stream key frame finding for new seek API.
schreter
parents:
diff changeset
516 av_free(state);
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